2011-11-02 17:44:16 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=2 et tw=78: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
// Needs to be first.
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
|
|
|
#include "Navigator.h"
|
|
|
|
#include "nsIXULAppInfo.h"
|
|
|
|
#include "nsPluginArray.h"
|
|
|
|
#include "nsMimeTypeArray.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-04-10 18:20:43 +04:00
|
|
|
#include "mozilla/dom/DesktopNotification.h"
|
2011-11-02 17:44:16 +04:00
|
|
|
#include "nsGeolocation.h"
|
|
|
|
#include "nsIHttpProtocolHandler.h"
|
2014-03-06 19:51:23 +04:00
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsIContentSecurityPolicy.h"
|
|
|
|
#include "nsContentPolicyUtils.h"
|
|
|
|
#include "nsCrossSiteListenerProxy.h"
|
|
|
|
#include "nsISupportsPriority.h"
|
2011-11-02 17:44:16 +04:00
|
|
|
#include "nsICachingChannel.h"
|
|
|
|
#include "nsIWebContentHandlerRegistrar.h"
|
|
|
|
#include "nsICookiePermission.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/Telemetry.h"
|
2011-11-02 19:01:32 +04:00
|
|
|
#include "BatteryManager.h"
|
2013-09-11 18:35:04 +04:00
|
|
|
#include "mozilla/dom/PowerManager.h"
|
2014-01-07 16:16:07 +04:00
|
|
|
#include "mozilla/dom/WakeLock.h"
|
|
|
|
#include "mozilla/dom/power/PowerManagerService.h"
|
2013-03-09 11:21:47 +04:00
|
|
|
#include "mozilla/dom/MobileMessageManager.h"
|
2013-10-29 12:12:38 +04:00
|
|
|
#include "mozilla/dom/Telephony.h"
|
2011-11-11 01:26:36 +04:00
|
|
|
#include "mozilla/Hal.h"
|
2012-10-12 02:56:13 +04:00
|
|
|
#include "nsISiteSpecificUserAgent.h"
|
2011-11-11 01:26:36 +04:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2012-07-26 23:33:45 +04:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2012-01-16 16:23:44 +04:00
|
|
|
#include "Connection.h"
|
2014-03-05 04:37:43 +04:00
|
|
|
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
|
2013-06-25 00:07:03 +04:00
|
|
|
#include "nsGlobalWindow.h"
|
2012-08-27 21:34:10 +04:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-10-22 15:23:00 +04:00
|
|
|
#include "mozilla/dom/IccManager.h"
|
2012-12-04 06:38:25 +04:00
|
|
|
#include "mozilla/dom/CellBroadcast.h"
|
2014-01-02 07:06:17 +04:00
|
|
|
#include "mozilla/dom/MobileConnectionArray.h"
|
2013-02-05 13:02:15 +04:00
|
|
|
#include "mozilla/dom/Voicemail.h"
|
2012-08-27 21:34:10 +04:00
|
|
|
#endif
|
2012-06-29 12:32:21 +04:00
|
|
|
#include "nsIIdleObserver.h"
|
2012-08-17 04:42:26 +04:00
|
|
|
#include "nsIPermissionManager.h"
|
2014-03-06 19:51:23 +04:00
|
|
|
#include "nsMimeTypes.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsIHttpChannel.h"
|
2014-03-06 19:51:23 +04:00
|
|
|
#include "nsIHttpChannelInternal.h"
|
2012-09-11 10:05:00 +04:00
|
|
|
#include "TimeManager.h"
|
2013-08-15 22:17:48 +04:00
|
|
|
#include "DeviceStorage.h"
|
|
|
|
#include "nsIDOMNavigatorSystemMessages.h"
|
2014-03-06 19:51:23 +04:00
|
|
|
#include "nsStreamUtils.h"
|
2013-12-06 03:12:23 +04:00
|
|
|
#include "nsIAppsService.h"
|
|
|
|
#include "mozIApplication.h"
|
2014-01-28 20:09:34 +04:00
|
|
|
#include "WidgetUtils.h"
|
2014-03-06 19:51:23 +04:00
|
|
|
#include "mozIThirdPartyUtil.h"
|
|
|
|
#include "nsChannelPolicy.h"
|
2011-11-02 17:44:16 +04:00
|
|
|
|
2012-06-03 11:35:15 +04:00
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
|
|
|
#include "MediaManager.h"
|
|
|
|
#endif
|
2012-02-20 19:15:19 +04:00
|
|
|
#ifdef MOZ_B2G_BT
|
2012-05-24 08:02:23 +04:00
|
|
|
#include "BluetoothManager.h"
|
2012-02-20 19:15:19 +04:00
|
|
|
#endif
|
2012-07-31 01:59:05 +04:00
|
|
|
#include "DOMCameraManager.h"
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2012-11-30 02:52:03 +04:00
|
|
|
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
|
|
|
#include "AudioChannelManager.h"
|
|
|
|
#endif
|
|
|
|
|
2013-09-04 02:26:33 +04:00
|
|
|
#ifdef MOZ_B2G_FM
|
|
|
|
#include "mozilla/dom/FMRadio.h"
|
|
|
|
#endif
|
|
|
|
|
2012-07-03 04:16:55 +04:00
|
|
|
#include "nsIDOMGlobalPropertyInitializer.h"
|
2013-10-02 21:27:07 +04:00
|
|
|
#include "nsIDataStoreService.h"
|
2013-07-12 18:35:35 +04:00
|
|
|
#include "nsJSUtils.h"
|
|
|
|
|
2013-07-12 18:37:23 +04:00
|
|
|
#include "nsScriptNameSpaceManager.h"
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
#include "mozilla/dom/NavigatorBinding.h"
|
2013-10-02 21:27:07 +04:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2013-09-11 19:45:51 +04:00
|
|
|
|
2014-03-06 19:51:23 +04:00
|
|
|
#include "nsIUploadChannel2.h"
|
|
|
|
#include "nsFormData.h"
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2011-11-11 01:26:36 +04:00
|
|
|
static bool sDoNotTrackEnabled = false;
|
|
|
|
static bool sVibratorEnabled = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sMaxVibrateMS = 0;
|
|
|
|
static uint32_t sMaxVibrateListLen = 0;
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
Navigator::Init()
|
|
|
|
{
|
|
|
|
Preferences::AddBoolVarCache(&sDoNotTrackEnabled,
|
|
|
|
"privacy.donottrackheader.enabled",
|
|
|
|
false);
|
2011-11-11 01:26:36 +04:00
|
|
|
Preferences::AddBoolVarCache(&sVibratorEnabled,
|
|
|
|
"dom.vibrator.enabled", true);
|
|
|
|
Preferences::AddUintVarCache(&sMaxVibrateMS,
|
|
|
|
"dom.vibrator.max_vibrate_ms", 10000);
|
|
|
|
Preferences::AddUintVarCache(&sMaxVibrateListLen,
|
|
|
|
"dom.vibrator.max_vibrate_list_len", 128);
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2011-12-01 12:28:16 +04:00
|
|
|
Navigator::Navigator(nsPIDOMWindow* aWindow)
|
2013-06-20 22:34:38 +04:00
|
|
|
: mWindow(aWindow)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2013-11-28 18:07:55 +04:00
|
|
|
MOZ_ASSERT(aWindow->IsInnerWindow(), "Navigator must get an inner window!");
|
2013-07-12 18:37:23 +04:00
|
|
|
SetIsDOMBinding();
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Navigator::~Navigator()
|
|
|
|
{
|
2011-12-01 12:28:16 +04:00
|
|
|
Invalidate();
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Navigator)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2011-11-02 17:44:16 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNavigator)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigator)
|
2013-07-18 07:23:52 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMozNavigatorNetwork)
|
2011-11-02 17:44:16 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Navigator)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Navigator)
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Navigator)
|
|
|
|
|
2013-06-28 22:06:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Navigator)
|
|
|
|
tmp->Invalidate();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
|
2013-07-09 17:58:21 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPlugins)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMimeTypes)
|
2013-06-28 22:06:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGeolocation)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNotification)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBatteryManager)
|
2013-07-18 20:07:28 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPowerManager)
|
2013-06-28 22:06:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMobileMessageManager)
|
2013-10-29 12:12:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTelephony)
|
2013-06-28 22:06:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConnection)
|
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-11-13 12:51:23 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMobileConnections)
|
2013-06-28 22:06:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCellBroadcast)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIccManager)
|
2013-10-22 15:23:04 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVoicemail)
|
2013-06-28 22:06:39 +04:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_B2G_BT
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBluetooth)
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAudioChannelManager)
|
|
|
|
#endif
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCameraManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMessagesManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDeviceStorageStores)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTimeManager)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(Navigator)
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
void
|
2011-12-01 12:28:16 +04:00
|
|
|
Navigator::Invalidate()
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2013-06-20 22:34:38 +04:00
|
|
|
// Don't clear mWindow here so we know we've got a non-null mWindow
|
|
|
|
// until we're unlinked.
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
if (mPlugins) {
|
2011-12-01 12:28:16 +04:00
|
|
|
mPlugins->Invalidate();
|
2012-07-30 18:20:58 +04:00
|
|
|
mPlugins = nullptr;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
mMimeTypes = nullptr;
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
// If there is a page transition, make sure delete the geolocation object.
|
|
|
|
if (mGeolocation) {
|
|
|
|
mGeolocation->Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
mGeolocation = nullptr;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mNotification) {
|
|
|
|
mNotification->Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
mNotification = nullptr;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
2011-11-02 19:27:06 +04:00
|
|
|
|
|
|
|
if (mBatteryManager) {
|
|
|
|
mBatteryManager->Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
mBatteryManager = nullptr;
|
2011-11-02 19:27:06 +04:00
|
|
|
}
|
2011-11-21 02:23:20 +04:00
|
|
|
|
2013-09-04 02:26:33 +04:00
|
|
|
#ifdef MOZ_B2G_FM
|
|
|
|
if (mFMRadio) {
|
|
|
|
mFMRadio->Shutdown();
|
|
|
|
mFMRadio = nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-03-07 15:03:25 +04:00
|
|
|
if (mPowerManager) {
|
|
|
|
mPowerManager->Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
mPowerManager = nullptr;
|
2012-03-07 15:03:25 +04:00
|
|
|
}
|
2012-01-20 07:24:00 +04:00
|
|
|
|
2013-03-09 11:21:47 +04:00
|
|
|
if (mMobileMessageManager) {
|
|
|
|
mMobileMessageManager->Shutdown();
|
|
|
|
mMobileMessageManager = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-10-29 12:12:38 +04:00
|
|
|
if (mTelephony) {
|
|
|
|
mTelephony = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-01-16 21:14:56 +04:00
|
|
|
if (mConnection) {
|
|
|
|
mConnection->Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
mConnection = nullptr;
|
2012-01-16 21:14:56 +04:00
|
|
|
}
|
2012-02-20 19:15:19 +04:00
|
|
|
|
2012-08-27 21:34:10 +04:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-11-13 12:51:23 +04:00
|
|
|
if (mMobileConnections) {
|
|
|
|
mMobileConnections = nullptr;
|
2012-04-20 01:33:25 +04:00
|
|
|
}
|
2012-12-04 06:38:25 +04:00
|
|
|
|
|
|
|
if (mCellBroadcast) {
|
|
|
|
mCellBroadcast = nullptr;
|
|
|
|
}
|
2013-04-08 14:34:10 +04:00
|
|
|
|
|
|
|
if (mIccManager) {
|
|
|
|
mIccManager->Shutdown();
|
|
|
|
mIccManager = nullptr;
|
|
|
|
}
|
2013-10-22 15:23:04 +04:00
|
|
|
|
|
|
|
if (mVoicemail) {
|
|
|
|
mVoicemail = nullptr;
|
|
|
|
}
|
2012-08-27 21:34:10 +04:00
|
|
|
#endif
|
2012-04-20 01:33:25 +04:00
|
|
|
|
2012-02-20 19:15:19 +04:00
|
|
|
#ifdef MOZ_B2G_BT
|
|
|
|
if (mBluetooth) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mBluetooth = nullptr;
|
2012-02-20 19:15:19 +04:00
|
|
|
}
|
|
|
|
#endif
|
2012-07-03 04:16:55 +04:00
|
|
|
|
2012-07-31 01:59:05 +04:00
|
|
|
mCameraManager = nullptr;
|
|
|
|
|
2012-07-03 04:16:55 +04:00
|
|
|
if (mMessagesManager) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mMessagesManager = nullptr;
|
2012-07-03 04:16:55 +04:00
|
|
|
}
|
|
|
|
|
2012-11-30 02:52:03 +04:00
|
|
|
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
|
|
|
if (mAudioChannelManager) {
|
|
|
|
mAudioChannelManager = nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = mDeviceStorageStores.Length();
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2012-08-02 10:29:34 +04:00
|
|
|
mDeviceStorageStores[i]->Shutdown();
|
|
|
|
}
|
|
|
|
mDeviceStorageStores.Clear();
|
|
|
|
|
2012-09-11 10:05:00 +04:00
|
|
|
if (mTimeManager) {
|
|
|
|
mTimeManager = nullptr;
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigator
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetUserAgent(nsAString& aUserAgent)
|
|
|
|
{
|
2012-10-12 02:56:13 +04:00
|
|
|
nsresult rv = NS_GetNavigatorUserAgent(aUserAgent);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
2012-10-12 02:56:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
nsIDocument* doc = mWindow->GetExtantDoc();
|
2012-10-12 02:56:13 +04:00
|
|
|
if (!doc) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> codebaseURI;
|
|
|
|
doc->NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
|
|
|
|
if (!codebaseURI) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISiteSpecificUserAgent> siteSpecificUA =
|
|
|
|
do_GetService("@mozilla.org/dom/site-specific-user-agent;1");
|
|
|
|
NS_ENSURE_TRUE(siteSpecificUA, NS_OK);
|
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
return siteSpecificUA->GetUserAgentForURIAndWindow(codebaseURI, mWindow,
|
|
|
|
aUserAgent);
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetAppCodeName(nsAString& aAppCodeName)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString appName;
|
2011-11-02 17:44:16 +04:00
|
|
|
rv = service->GetAppName(appName);
|
|
|
|
CopyASCIItoUTF16(appName, aAppCodeName);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetAppVersion(nsAString& aAppVersion)
|
|
|
|
{
|
|
|
|
return NS_GetNavigatorAppVersion(aAppVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetAppName(nsAString& aAppName)
|
|
|
|
{
|
2013-07-12 18:35:35 +04:00
|
|
|
NS_GetNavigatorAppName(aAppName);
|
|
|
|
return NS_OK;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* JS property navigator.language, exposed to web content.
|
|
|
|
* Take first value from Accept-Languages (HTTP header), which is
|
|
|
|
* the "content language" freely set by the user in the Pref window.
|
|
|
|
*
|
|
|
|
* Do not use UI language (chosen app locale) here.
|
|
|
|
* See RFC 2616, Section 15.1.4 "Privacy Issues Connected to Accept Headers"
|
|
|
|
*
|
|
|
|
* "en", "en-US" and "i-cherokee" and "" are valid.
|
|
|
|
* Fallback in case of invalid pref should be "" (empty string), to
|
|
|
|
* let site do fallback, e.g. to site's local language.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetLanguage(nsAString& aLanguage)
|
|
|
|
{
|
|
|
|
// E.g. "de-de, en-us,en".
|
|
|
|
const nsAdoptingString& acceptLang =
|
|
|
|
Preferences::GetLocalizedString("intl.accept_languages");
|
|
|
|
|
|
|
|
// Take everything before the first "," or ";", without trailing space.
|
|
|
|
nsCharSeparatedTokenizer langTokenizer(acceptLang, ',');
|
|
|
|
const nsSubstring &firstLangPart = langTokenizer.nextToken();
|
|
|
|
nsCharSeparatedTokenizer qTokenizer(firstLangPart, ';');
|
|
|
|
aLanguage.Assign(qTokenizer.nextToken());
|
|
|
|
|
|
|
|
// Checks and fixups:
|
|
|
|
// replace "_" with "-" to avoid POSIX/Windows "en_US" notation.
|
2014-01-04 19:02:17 +04:00
|
|
|
if (aLanguage.Length() > 2 && aLanguage[2] == char16_t('_')) {
|
|
|
|
aLanguage.Replace(2, 1, char16_t('-')); // TODO replace all
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Use uppercase for country part, e.g. "en-US", not "en-us", see BCP47
|
|
|
|
// only uppercase 2-letter country codes, not "zh-Hant", "de-DE-x-goethe".
|
|
|
|
if (aLanguage.Length() <= 2) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCharSeparatedTokenizer localeTokenizer(aLanguage, '-');
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t pos = 0;
|
2011-11-02 17:44:16 +04:00
|
|
|
bool first = true;
|
|
|
|
while (localeTokenizer.hasMoreTokens()) {
|
|
|
|
const nsSubstring& code = localeTokenizer.nextToken();
|
|
|
|
|
|
|
|
if (code.Length() == 2 && !first) {
|
|
|
|
nsAutoString upper(code);
|
|
|
|
ToUpperCase(upper);
|
|
|
|
aLanguage.Replace(pos, code.Length(), upper);
|
|
|
|
}
|
|
|
|
|
|
|
|
pos += code.Length() + 1; // 1 is the separator
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetPlatform(nsAString& aPlatform)
|
|
|
|
{
|
|
|
|
return NS_GetNavigatorPlatform(aPlatform);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetOscpu(nsAString& aOSCPU)
|
|
|
|
{
|
2012-10-26 03:10:53 +04:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2011-11-02 17:44:16 +04:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
Preferences::GetString("general.oscpu.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aOSCPU = override;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString oscpu;
|
2011-11-02 17:44:16 +04:00
|
|
|
rv = service->GetOscpu(oscpu);
|
|
|
|
CopyASCIItoUTF16(oscpu, aOSCPU);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetVendor(nsAString& aVendor)
|
|
|
|
{
|
|
|
|
aVendor.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetVendorSub(nsAString& aVendorSub)
|
|
|
|
{
|
|
|
|
aVendorSub.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetProduct(nsAString& aProduct)
|
|
|
|
{
|
2012-07-27 16:09:59 +04:00
|
|
|
aProduct.AssignLiteral("Gecko");
|
|
|
|
return NS_OK;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetProductSub(nsAString& aProductSub)
|
|
|
|
{
|
2012-07-27 16:09:59 +04:00
|
|
|
// Legacy build ID hardcoded for backward compatibility (bug 776376)
|
|
|
|
aProductSub.AssignLiteral("20100101");
|
|
|
|
return NS_OK;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
nsMimeTypeArray*
|
|
|
|
Navigator::GetMimeTypes(ErrorResult& aRv)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
|
|
|
if (!mMimeTypes) {
|
2013-07-12 18:35:35 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-08-29 00:55:29 +04:00
|
|
|
mMimeTypes = new nsMimeTypeArray(mWindow);
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
return mMimeTypes;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
nsPluginArray*
|
|
|
|
Navigator::GetPlugins(ErrorResult& aRv)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
|
|
|
if (!mPlugins) {
|
2013-07-12 18:35:35 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-08-29 00:55:29 +04:00
|
|
|
mPlugins = new nsPluginArray(mWindow);
|
2013-04-11 00:59:45 +04:00
|
|
|
mPlugins->Init();
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
return mPlugins;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Values for the network.cookie.cookieBehavior pref are documented in
|
|
|
|
// nsCookieService.cpp.
|
|
|
|
#define COOKIE_BEHAVIOR_REJECT 2
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
bool
|
|
|
|
Navigator::CookieEnabled()
|
|
|
|
{
|
|
|
|
bool cookieEnabled =
|
2011-11-02 17:44:16 +04:00
|
|
|
(Preferences::GetInt("network.cookie.cookieBehavior",
|
|
|
|
COOKIE_BEHAVIOR_REJECT) != COOKIE_BEHAVIOR_REJECT);
|
|
|
|
|
|
|
|
// Check whether an exception overrides the global cookie behavior
|
|
|
|
// Note that the code for getting the URI here matches that in
|
|
|
|
// nsHTMLDocument::SetCookie.
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
2013-07-12 18:35:35 +04:00
|
|
|
return cookieEnabled;
|
2011-12-01 12:28:16 +04:00
|
|
|
}
|
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = mWindow->GetExtantDoc();
|
2011-11-02 17:44:16 +04:00
|
|
|
if (!doc) {
|
2013-07-12 18:35:35 +04:00
|
|
|
return cookieEnabled;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> codebaseURI;
|
|
|
|
doc->NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
|
|
|
|
|
|
|
|
if (!codebaseURI) {
|
|
|
|
// Not a codebase, so technically can't set cookies, but let's
|
|
|
|
// just return the default value.
|
2013-07-12 18:35:35 +04:00
|
|
|
return cookieEnabled;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsICookiePermission> permMgr =
|
|
|
|
do_GetService(NS_COOKIEPERMISSION_CONTRACTID);
|
2013-07-12 18:35:35 +04:00
|
|
|
NS_ENSURE_TRUE(permMgr, cookieEnabled);
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
// Pass null for the channel, just like the cookie service does.
|
|
|
|
nsCookieAccess access;
|
2012-07-30 18:20:58 +04:00
|
|
|
nsresult rv = permMgr->CanAccess(codebaseURI, nullptr, &access);
|
2013-07-12 18:35:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, cookieEnabled);
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
if (access != nsICookiePermission::ACCESS_DEFAULT) {
|
2013-07-12 18:35:35 +04:00
|
|
|
cookieEnabled = access != nsICookiePermission::ACCESS_DENY;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
return cookieEnabled;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
bool
|
|
|
|
Navigator::OnLine()
|
|
|
|
{
|
|
|
|
return !NS_IsOffline();
|
|
|
|
}
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetBuildID(nsAString& aBuildID)
|
|
|
|
{
|
2012-10-26 03:10:53 +04:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2011-11-02 17:44:16 +04:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
Preferences::GetString("general.buildID.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aBuildID = override;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXULAppInfo> appInfo =
|
|
|
|
do_GetService("@mozilla.org/xre/app-info;1");
|
|
|
|
if (!appInfo) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString buildID;
|
2011-11-02 17:44:16 +04:00
|
|
|
nsresult rv = appInfo->GetAppBuildID(buildID);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
aBuildID.Truncate();
|
|
|
|
AppendASCIItoUTF16(buildID, aBuildID);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetDoNotTrack(nsAString &aResult)
|
|
|
|
{
|
|
|
|
if (sDoNotTrackEnabled) {
|
|
|
|
aResult.AssignLiteral("yes");
|
|
|
|
} else {
|
|
|
|
aResult.AssignLiteral("unspecified");
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
bool
|
|
|
|
Navigator::JavaEnabled(ErrorResult& aRv)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
|
|
|
Telemetry::AutoTimer<Telemetry::CHECK_JAVA_ENABLED> telemetryTimer;
|
2014-02-11 03:50:53 +04:00
|
|
|
|
|
|
|
// Return true if we have a handler for the java mime
|
|
|
|
nsAdoptingString javaMIME = Preferences::GetString("plugin.java.mime");
|
|
|
|
NS_ENSURE_TRUE(!javaMIME.IsEmpty(), false);
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
if (!mMimeTypes) {
|
2013-07-12 18:35:35 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return false;
|
|
|
|
}
|
2013-08-29 00:55:29 +04:00
|
|
|
mMimeTypes = new nsMimeTypeArray(mWindow);
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
RefreshMIMEArray();
|
|
|
|
|
2014-02-11 03:50:53 +04:00
|
|
|
nsMimeType *mimeType = mMimeTypes->NamedItem(javaMIME);
|
2011-11-02 15:04:28 +04:00
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
return mimeType && mimeType->GetEnabledPlugin();
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Navigator::RefreshMIMEArray()
|
|
|
|
{
|
|
|
|
if (mMimeTypes) {
|
2011-12-01 12:28:16 +04:00
|
|
|
mMimeTypes->Refresh();
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Navigator::HasDesktopNotificationSupport()
|
|
|
|
{
|
|
|
|
return Preferences::GetBool("notification.feature.enabled", false);
|
|
|
|
}
|
|
|
|
|
2011-11-11 01:26:36 +04:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class VibrateWindowListener : public nsIDOMEventListener
|
|
|
|
{
|
|
|
|
public:
|
2013-04-24 08:22:37 +04:00
|
|
|
VibrateWindowListener(nsIDOMWindow* aWindow, nsIDocument* aDocument)
|
2011-11-11 01:26:36 +04:00
|
|
|
{
|
|
|
|
mWindow = do_GetWeakReference(aWindow);
|
|
|
|
mDocument = do_GetWeakReference(aDocument);
|
|
|
|
|
2012-11-17 02:22:56 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(visibilitychange, "visibilitychange");
|
2013-04-24 08:22:37 +04:00
|
|
|
aDocument->AddSystemEventListener(visibilitychange,
|
|
|
|
this, /* listener */
|
|
|
|
true, /* use capture */
|
|
|
|
false /* wants untrusted */);
|
2011-11-11 01:26:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~VibrateWindowListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveListener();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsWeakPtr mWindow;
|
|
|
|
nsWeakPtr mDocument;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(VibrateWindowListener, nsIDOMEventListener)
|
|
|
|
|
2012-07-26 23:33:45 +04:00
|
|
|
StaticRefPtr<VibrateWindowListener> gVibrateWindowListener;
|
2011-11-11 01:26:36 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
VibrateWindowListener::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
2013-04-20 02:18:32 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc =
|
|
|
|
do_QueryInterface(aEvent->InternalDOMEvent()->GetTarget());
|
2011-11-11 01:26:36 +04:00
|
|
|
|
2013-04-20 02:18:32 +04:00
|
|
|
if (!doc || doc->Hidden()) {
|
2011-11-11 01:26:36 +04:00
|
|
|
// It's important that we call CancelVibrate(), not Vibrate() with an
|
|
|
|
// empty list, because Vibrate() will fail if we're no longer focused, but
|
|
|
|
// CancelVibrate() will succeed, so long as nobody else has started a new
|
|
|
|
// vibration pattern.
|
|
|
|
nsCOMPtr<nsIDOMWindow> window = do_QueryReferent(mWindow);
|
|
|
|
hal::CancelVibrate(window);
|
|
|
|
RemoveListener();
|
2013-10-28 18:04:12 +04:00
|
|
|
gVibrateWindowListener = nullptr;
|
2011-11-11 01:26:36 +04:00
|
|
|
// Careful: The line above might have deleted |this|!
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VibrateWindowListener::RemoveListener()
|
|
|
|
{
|
2013-04-20 02:18:32 +04:00
|
|
|
nsCOMPtr<EventTarget> target = do_QueryReferent(mDocument);
|
2011-11-11 01:26:36 +04:00
|
|
|
if (!target) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-17 02:22:56 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(visibilitychange, "visibilitychange");
|
2011-11-11 01:26:36 +04:00
|
|
|
target->RemoveSystemEventListener(visibilitychange, this,
|
|
|
|
true /* use capture */);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
void
|
|
|
|
Navigator::AddIdleObserver(MozIdleObserver& aIdleObserver, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CallbackObjectHolder<MozIdleObserver, nsIIdleObserver> holder(&aIdleObserver);
|
|
|
|
nsCOMPtr<nsIIdleObserver> obs = holder.ToXPCOMCallback();
|
2013-07-18 07:23:52 +04:00
|
|
|
if (NS_FAILED(mWindow->RegisterIdleObserver(obs))) {
|
|
|
|
NS_WARNING("Failed to add idle observer.");
|
2013-07-12 18:35:35 +04:00
|
|
|
}
|
|
|
|
}
|
2011-11-11 01:26:36 +04:00
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
void
|
|
|
|
Navigator::RemoveIdleObserver(MozIdleObserver& aIdleObserver, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
2011-11-11 01:26:36 +04:00
|
|
|
}
|
2013-07-12 18:35:35 +04:00
|
|
|
CallbackObjectHolder<MozIdleObserver, nsIIdleObserver> holder(&aIdleObserver);
|
|
|
|
nsCOMPtr<nsIIdleObserver> obs = holder.ToXPCOMCallback();
|
2013-07-18 07:23:52 +04:00
|
|
|
if (NS_FAILED(mWindow->UnregisterIdleObserver(obs))) {
|
|
|
|
NS_WARNING("Failed to remove idle observer.");
|
2011-11-11 01:26:36 +04:00
|
|
|
}
|
2013-07-12 18:35:35 +04:00
|
|
|
}
|
|
|
|
|
2013-09-28 22:58:38 +04:00
|
|
|
bool
|
|
|
|
Navigator::Vibrate(uint32_t aDuration)
|
2013-07-12 18:35:35 +04:00
|
|
|
{
|
|
|
|
nsAutoTArray<uint32_t, 1> pattern;
|
|
|
|
pattern.AppendElement(aDuration);
|
2013-09-28 22:58:38 +04:00
|
|
|
return Vibrate(pattern);
|
2013-07-12 18:35:35 +04:00
|
|
|
}
|
|
|
|
|
2013-09-28 22:58:38 +04:00
|
|
|
bool
|
|
|
|
Navigator::Vibrate(const nsTArray<uint32_t>& aPattern)
|
2013-07-12 18:35:35 +04:00
|
|
|
{
|
|
|
|
if (!mWindow) {
|
2013-09-28 22:58:38 +04:00
|
|
|
return false;
|
2013-07-12 18:35:35 +04:00
|
|
|
}
|
2013-09-28 22:58:38 +04:00
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = mWindow->GetExtantDoc();
|
|
|
|
if (!doc) {
|
2013-09-28 22:58:38 +04:00
|
|
|
return false;
|
2013-07-12 18:35:35 +04:00
|
|
|
}
|
2013-09-28 22:58:38 +04:00
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
if (doc->Hidden()) {
|
|
|
|
// Hidden documents cannot start or stop a vibration.
|
2013-09-28 22:58:38 +04:00
|
|
|
return false;
|
2013-07-12 18:35:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aPattern.Length() > sMaxVibrateListLen) {
|
2013-09-28 22:58:38 +04:00
|
|
|
return false;
|
2013-07-12 18:35:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < aPattern.Length(); ++i) {
|
|
|
|
if (aPattern[i] > sMaxVibrateMS) {
|
2013-09-28 22:58:38 +04:00
|
|
|
return false;
|
2013-07-12 18:35:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-11 01:26:36 +04:00
|
|
|
// The spec says we check sVibratorEnabled after we've done the sanity
|
|
|
|
// checking on the pattern.
|
2013-09-28 22:58:38 +04:00
|
|
|
if (aPattern.IsEmpty() || !sVibratorEnabled) {
|
|
|
|
return true;
|
2011-11-11 01:26:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add a listener to cancel the vibration if the document becomes hidden,
|
2012-11-17 02:22:56 +04:00
|
|
|
// and remove the old visibility listener, if there was one.
|
2011-11-11 01:26:36 +04:00
|
|
|
|
|
|
|
if (!gVibrateWindowListener) {
|
|
|
|
// If gVibrateWindowListener is null, this is the first time we've vibrated,
|
|
|
|
// and we need to register a listener to clear gVibrateWindowListener on
|
|
|
|
// shutdown.
|
|
|
|
ClearOnShutdown(&gVibrateWindowListener);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gVibrateWindowListener->RemoveListener();
|
|
|
|
}
|
2013-06-20 22:34:38 +04:00
|
|
|
gVibrateWindowListener = new VibrateWindowListener(mWindow, doc);
|
2011-11-11 01:26:36 +04:00
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
hal::Vibrate(aPattern, mWindow);
|
2013-09-28 22:58:38 +04:00
|
|
|
return true;
|
2011-11-11 01:26:36 +04:00
|
|
|
}
|
|
|
|
|
2014-01-28 20:09:34 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
// Pointer Events interface
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Navigator::MaxTouchPoints()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWidget> widget = widget::WidgetUtils::DOMWindowToWidget(mWindow);
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(widget, 0);
|
|
|
|
return widget->GetMaxTouchPoints();
|
|
|
|
}
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMClientInformation
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
void
|
2011-11-02 17:44:16 +04:00
|
|
|
Navigator::RegisterContentHandler(const nsAString& aMIMEType,
|
|
|
|
const nsAString& aURI,
|
2013-07-18 07:23:52 +04:00
|
|
|
const nsAString& aTitle,
|
|
|
|
ErrorResult& aRv)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
2013-07-18 07:23:52 +04:00
|
|
|
return;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebContentHandlerRegistrar> registrar =
|
|
|
|
do_GetService(NS_WEBCONTENTHANDLERREGISTRAR_CONTRACTID);
|
|
|
|
if (!registrar) {
|
2013-07-18 07:23:52 +04:00
|
|
|
return;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
aRv = registrar->RegisterContentHandler(aMIMEType, aURI, aTitle,
|
|
|
|
mWindow->GetOuterWindow());
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
void
|
2011-11-02 17:44:16 +04:00
|
|
|
Navigator::RegisterProtocolHandler(const nsAString& aProtocol,
|
|
|
|
const nsAString& aURI,
|
2013-07-18 07:23:52 +04:00
|
|
|
const nsAString& aTitle,
|
|
|
|
ErrorResult& aRv)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
2013-07-18 07:23:52 +04:00
|
|
|
return;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebContentHandlerRegistrar> registrar =
|
|
|
|
do_GetService(NS_WEBCONTENTHANDLERREGISTRAR_CONTRACTID);
|
|
|
|
if (!registrar) {
|
2013-07-18 07:23:52 +04:00
|
|
|
return;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
aRv = registrar->RegisterProtocolHandler(aProtocol, aURI, aTitle,
|
|
|
|
mWindow->GetOuterWindow());
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
bool
|
2011-11-02 17:44:16 +04:00
|
|
|
Navigator::MozIsLocallyAvailable(const nsAString &aURI,
|
|
|
|
bool aWhenOffline,
|
2013-07-18 07:23:52 +04:00
|
|
|
ErrorResult& aRv)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURI);
|
2013-07-18 07:23:52 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
// This method of checking the cache will only work for http/https urls.
|
|
|
|
bool match;
|
|
|
|
rv = uri->SchemeIs("http", &match);
|
2013-07-18 07:23:52 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
if (!match) {
|
|
|
|
rv = uri->SchemeIs("https", &match);
|
2013-07-18 07:23:52 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
if (!match) {
|
2013-07-18 07:23:52 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_BAD_URI);
|
|
|
|
return false;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same origin check.
|
2013-04-29 22:16:18 +04:00
|
|
|
JSContext *cx = nsContentUtils::GetCurrentJSContext();
|
2013-07-18 07:23:52 +04:00
|
|
|
if (!cx) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
rv = nsContentUtils::GetSecurityManager()->CheckSameOrigin(cx, uri);
|
2013-07-18 07:23:52 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
// These load flags cause an error to be thrown if there is no
|
|
|
|
// valid cache entry, and skip the load if there is.
|
|
|
|
// If the cache is busy, assume that it is not yet available rather
|
|
|
|
// than waiting for it to become available.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t loadFlags = nsIChannel::INHIBIT_CACHING |
|
2011-11-02 17:44:16 +04:00
|
|
|
nsICachingChannel::LOAD_NO_NETWORK_IO |
|
|
|
|
nsICachingChannel::LOAD_ONLY_IF_MODIFIED |
|
|
|
|
nsICachingChannel::LOAD_BYPASS_LOCAL_CACHE_IF_BUSY;
|
|
|
|
|
|
|
|
if (aWhenOffline) {
|
|
|
|
loadFlags |= nsICachingChannel::LOAD_CHECK_OFFLINE_CACHE |
|
|
|
|
nsICachingChannel::LOAD_ONLY_FROM_CACHE |
|
|
|
|
nsIRequest::LOAD_FROM_CACHE;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return false;
|
|
|
|
}
|
2013-06-20 22:34:38 +04:00
|
|
|
|
2012-09-17 19:24:38 +04:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
2013-06-20 22:34:38 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = mWindow->GetDoc();
|
2012-09-17 19:24:38 +04:00
|
|
|
if (doc) {
|
|
|
|
loadGroup = doc->GetDocumentLoadGroup();
|
|
|
|
}
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
rv = NS_NewChannel(getter_AddRefs(channel), uri,
|
2012-09-17 19:24:38 +04:00
|
|
|
nullptr, loadGroup, nullptr, loadFlags);
|
2013-07-18 07:23:52 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> stream;
|
|
|
|
rv = channel->Open(getter_AddRefs(stream));
|
2013-07-18 07:23:52 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
stream->Close();
|
|
|
|
|
|
|
|
nsresult status;
|
|
|
|
rv = channel->GetStatus(&status);
|
2013-07-18 07:23:52 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(status)) {
|
2013-07-18 07:23:52 +04:00
|
|
|
return false;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(channel);
|
2013-07-18 07:23:52 +04:00
|
|
|
bool isAvailable;
|
|
|
|
rv = httpChannel->GetRequestSucceeded(&isAvailable);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
2013-04-05 02:21:49 +04:00
|
|
|
}
|
2013-07-18 07:23:52 +04:00
|
|
|
return isAvailable;
|
2013-07-12 18:35:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMDeviceStorage*
|
|
|
|
Navigator::GetDeviceStorage(const nsAString& aType, ErrorResult& aRv)
|
|
|
|
{
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
2013-07-12 18:35:44 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2013-05-11 13:10:18 +04:00
|
|
|
}
|
2013-05-11 17:47:37 +04:00
|
|
|
|
2013-05-11 13:10:18 +04:00
|
|
|
nsRefPtr<nsDOMDeviceStorage> storage;
|
2013-06-20 22:34:38 +04:00
|
|
|
nsDOMDeviceStorage::CreateDeviceStorageFor(mWindow, aType,
|
|
|
|
getter_AddRefs(storage));
|
2013-05-11 17:47:37 +04:00
|
|
|
|
2013-05-11 13:10:18 +04:00
|
|
|
if (!storage) {
|
2013-07-12 18:35:44 +04:00
|
|
|
return nullptr;
|
2013-04-02 23:52:21 +04:00
|
|
|
}
|
|
|
|
|
2013-05-11 13:10:18 +04:00
|
|
|
mDeviceStorageStores.AppendElement(storage);
|
2013-07-12 18:35:44 +04:00
|
|
|
return storage;
|
2013-04-02 23:52:21 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
void
|
|
|
|
Navigator::GetDeviceStorages(const nsAString& aType,
|
|
|
|
nsTArray<nsRefPtr<nsDOMDeviceStorage> >& aStores,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-03 03:34:59 +04:00
|
|
|
nsDOMDeviceStorage::CreateDeviceStoragesFor(mWindow, aType, aStores);
|
2013-07-12 18:35:44 +04:00
|
|
|
|
|
|
|
mDeviceStorageStores.AppendElements(aStores);
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
Geolocation*
|
|
|
|
Navigator::GetGeolocation(ErrorResult& aRv)
|
|
|
|
{
|
2011-11-02 17:44:16 +04:00
|
|
|
if (mGeolocation) {
|
2013-07-12 18:35:35 +04:00
|
|
|
return mGeolocation;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
2013-07-12 18:35:35 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-04-12 22:47:47 +04:00
|
|
|
mGeolocation = new Geolocation();
|
2013-06-20 22:34:38 +04:00
|
|
|
if (NS_FAILED(mGeolocation->Init(mWindow->GetOuterWindow()))) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mGeolocation = nullptr;
|
2013-07-12 18:35:35 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
return mGeolocation;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2014-03-06 19:51:23 +04:00
|
|
|
class BeaconStreamListener MOZ_FINAL : public nsIStreamListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BeaconStreamListener() {}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS2(BeaconStreamListener,
|
|
|
|
nsIStreamListener,
|
|
|
|
nsIRequestObserver)
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BeaconStreamListener::OnStartRequest(nsIRequest *aRequest,
|
|
|
|
nsISupports *aContext)
|
|
|
|
{
|
|
|
|
aRequest->Cancel(NS_ERROR_NET_INTERRUPT);
|
|
|
|
return NS_BINDING_ABORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BeaconStreamListener::OnStopRequest(nsIRequest *aRequest,
|
|
|
|
nsISupports *aContext,
|
|
|
|
nsresult aStatus)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BeaconStreamListener::OnDataAvailable(nsIRequest *aRequest,
|
|
|
|
nsISupports *ctxt,
|
|
|
|
nsIInputStream *inStr,
|
|
|
|
uint64_t sourceOffset,
|
|
|
|
uint32_t count)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Navigator::SendBeacon(const nsAString& aUrl,
|
|
|
|
const Nullable<ArrayBufferViewOrBlobOrStringOrFormData>& aData,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = mWindow->GetDoc();
|
|
|
|
if (!doc) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIURI* documentURI = doc->GetDocumentURI();
|
|
|
|
if (!documentURI) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = nsContentUtils::NewURIWithDocumentCharset(
|
|
|
|
getter_AddRefs(uri),
|
|
|
|
aUrl,
|
|
|
|
doc,
|
|
|
|
doc->GetDocBaseURI());
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_URL_MISMATCH_ERR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether this is a sane URI to load
|
|
|
|
// Explicitly disallow things like chrome:, javascript:, and data: URIs
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = doc->NodePrincipal();
|
|
|
|
nsCOMPtr<nsIScriptSecurityManager> secMan = nsContentUtils::GetSecurityManager();
|
|
|
|
uint32_t flags = nsIScriptSecurityManager::DISALLOW_INHERIT_PRINCIPAL
|
|
|
|
& nsIScriptSecurityManager::DISALLOW_SCRIPT;
|
|
|
|
rv = secMan->CheckLoadURIWithPrincipal(principal,
|
|
|
|
uri,
|
|
|
|
flags);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Bad URI
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether the CSP allows us to load
|
|
|
|
int16_t shouldLoad = nsIContentPolicy::ACCEPT;
|
|
|
|
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_BEACON,
|
|
|
|
uri,
|
|
|
|
principal,
|
|
|
|
doc,
|
|
|
|
EmptyCString(), //mime guess
|
|
|
|
nullptr, //extra
|
|
|
|
&shouldLoad,
|
|
|
|
nsContentUtils::GetContentPolicy(),
|
|
|
|
nsContentUtils::GetSecurityManager());
|
|
|
|
if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) {
|
|
|
|
// Disallowed by content policy
|
|
|
|
aRv.Throw(NS_ERROR_CONTENT_BLOCKED);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
nsCOMPtr<nsIChannelPolicy> channelPolicy;
|
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> csp;
|
|
|
|
rv = principal->GetCsp(getter_AddRefs(csp));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (csp) {
|
|
|
|
channelPolicy = do_CreateInstance(NSCHANNELPOLICY_CONTRACTID);
|
|
|
|
channelPolicy->SetContentSecurityPolicy(csp);
|
|
|
|
channelPolicy->SetLoadType(nsIContentPolicy::TYPE_BEACON);
|
|
|
|
}
|
|
|
|
rv = NS_NewChannel(getter_AddRefs(channel),
|
|
|
|
uri,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nsIRequest::LOAD_NORMAL,
|
|
|
|
channelPolicy);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(channel);
|
|
|
|
if (!httpChannel) {
|
|
|
|
// Beacon spec only supports HTTP requests at this time
|
|
|
|
aRv.Throw(NS_ERROR_DOM_BAD_URI);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
httpChannel->SetReferrer(documentURI);
|
|
|
|
|
|
|
|
// Anything that will need to refer to the window during the request
|
|
|
|
// will need to be done now. For example, detection of whether any
|
|
|
|
// cookies set by this request are foreign. Note that ThirdPartyUtil
|
|
|
|
// (nsIThirdPartyUtil.isThirdPartyChannel) does a secondary check between
|
|
|
|
// the channel URI and the cookie URI even when forceAllowThirdPartyCookie
|
|
|
|
// is set, so this is safe with regard to redirects.
|
|
|
|
nsCOMPtr<nsIHttpChannelInternal> httpChannelInternal(do_QueryInterface(channel));
|
|
|
|
nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil = do_GetService(THIRDPARTYUTIL_CONTRACTID);
|
|
|
|
if (!httpChannelInternal) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_BAD_URI);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool isForeign = true;
|
|
|
|
thirdPartyUtil->IsThirdPartyWindow(mWindow, uri, &isForeign);
|
|
|
|
httpChannelInternal->SetForceAllowThirdPartyCookie(!isForeign);
|
|
|
|
|
|
|
|
nsCString mimeType;
|
|
|
|
if (!aData.IsNull()) {
|
|
|
|
nsCOMPtr<nsIInputStream> in;
|
|
|
|
|
|
|
|
if (aData.Value().IsString()) {
|
|
|
|
nsCString stringData = NS_ConvertUTF16toUTF8(aData.Value().GetAsString());
|
|
|
|
nsCOMPtr<nsIStringInputStream> strStream = do_CreateInstance(NS_STRINGINPUTSTREAM_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
rv = strStream->SetData(stringData.BeginReading(), stringData.Length());
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mimeType.AssignLiteral("text/plain;charset=UTF-8");
|
|
|
|
in = strStream;
|
|
|
|
|
|
|
|
} else if (aData.Value().IsArrayBufferView()) {
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStringInputStream> strStream = do_CreateInstance(NS_STRINGINPUTSTREAM_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = strStream->SetData(reinterpret_cast<char*>(aData.Value().GetAsArrayBufferView().Data()),
|
|
|
|
aData.Value().GetAsArrayBufferView().Length());
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mimeType.AssignLiteral("application/octet-stream");
|
|
|
|
in = strStream;
|
|
|
|
|
|
|
|
} else if (aData.Value().IsBlob()) {
|
|
|
|
nsCOMPtr<nsIDOMBlob> blob = aData.Value().GetAsBlob();
|
|
|
|
rv = blob->GetInternalStream(getter_AddRefs(in));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsAutoString type;
|
|
|
|
rv = blob->GetType(type);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mimeType = NS_ConvertUTF16toUTF8(type);
|
|
|
|
|
|
|
|
} else if (aData.Value().IsFormData()) {
|
|
|
|
nsFormData& form = aData.Value().GetAsFormData();
|
|
|
|
uint64_t len;
|
|
|
|
nsAutoCString charset;
|
|
|
|
form.GetSendInfo(getter_AddRefs(in),
|
|
|
|
&len,
|
|
|
|
mimeType,
|
|
|
|
charset);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(false, "switch statements not in sync");
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIUploadChannel2> uploadChannel = do_QueryInterface(channel);
|
|
|
|
if (!uploadChannel) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
uploadChannel->ExplicitSetUploadStream(in, mimeType, -1,
|
|
|
|
NS_LITERAL_CSTRING("POST"),
|
|
|
|
false);
|
|
|
|
} else {
|
|
|
|
httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("POST"));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(channel);
|
|
|
|
if (p) {
|
|
|
|
p->SetPriority(nsISupportsPriority::PRIORITY_LOWEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsCORSListenerProxy> cors = new nsCORSListenerProxy(new BeaconStreamListener(),
|
|
|
|
principal,
|
|
|
|
true);
|
|
|
|
|
|
|
|
// Start a preflight if cross-origin and content type is not whitelisted
|
|
|
|
rv = secMan->CheckSameOriginURI(documentURI, uri, false);
|
|
|
|
bool crossOrigin = NS_FAILED(rv);
|
|
|
|
nsAutoCString contentType, parsedCharset;
|
|
|
|
rv = NS_ParseContentType(mimeType, contentType, parsedCharset);
|
|
|
|
if (crossOrigin &&
|
|
|
|
contentType.Length() > 0 &&
|
|
|
|
!contentType.Equals(APPLICATION_WWW_FORM_URLENCODED) &&
|
|
|
|
!contentType.Equals(MULTIPART_FORM_DATA) &&
|
|
|
|
!contentType.Equals(TEXT_PLAIN)) {
|
|
|
|
nsCOMPtr<nsIChannel> preflightChannel;
|
|
|
|
nsTArray<nsCString> unsafeHeaders;
|
|
|
|
unsafeHeaders.AppendElement(NS_LITERAL_CSTRING("Content-Type"));
|
|
|
|
rv = NS_StartCORSPreflight(channel,
|
|
|
|
cors,
|
|
|
|
principal,
|
|
|
|
true,
|
|
|
|
unsafeHeaders,
|
|
|
|
getter_AddRefs(preflightChannel));
|
|
|
|
} else {
|
|
|
|
rv = channel->AsyncOpen(cors, nullptr);
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-03 11:35:15 +04:00
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
2013-07-12 18:37:21 +04:00
|
|
|
void
|
2013-09-16 10:34:57 +04:00
|
|
|
Navigator::MozGetUserMedia(JSContext* aCx,
|
|
|
|
const MediaStreamConstraints& aConstraints,
|
|
|
|
NavigatorUserMediaSuccessCallback& aOnSuccess,
|
|
|
|
NavigatorUserMediaErrorCallback& aOnError,
|
2013-07-12 18:37:21 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2013-09-16 10:34:57 +04:00
|
|
|
CallbackObjectHolder<NavigatorUserMediaSuccessCallback,
|
|
|
|
nsIDOMGetUserMediaSuccessCallback> holder1(&aOnSuccess);
|
2013-07-18 07:23:52 +04:00
|
|
|
nsCOMPtr<nsIDOMGetUserMediaSuccessCallback> onsuccess =
|
2013-07-12 18:37:21 +04:00
|
|
|
holder1.ToXPCOMCallback();
|
|
|
|
|
2013-09-16 10:34:57 +04:00
|
|
|
CallbackObjectHolder<NavigatorUserMediaErrorCallback,
|
|
|
|
nsIDOMGetUserMediaErrorCallback> holder2(&aOnError);
|
2013-07-12 18:37:21 +04:00
|
|
|
nsCOMPtr<nsIDOMGetUserMediaErrorCallback> onerror = holder2.ToXPCOMCallback();
|
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() ||
|
|
|
|
mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) {
|
2013-07-12 18:37:21 +04:00
|
|
|
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return;
|
2012-09-20 23:54:00 +04:00
|
|
|
}
|
2012-06-03 11:35:15 +04:00
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
bool privileged = nsContentUtils::IsChromeDoc(mWindow->GetExtantDoc());
|
2012-09-20 23:54:00 +04:00
|
|
|
|
|
|
|
MediaManager* manager = MediaManager::Get();
|
2013-09-16 10:34:57 +04:00
|
|
|
aRv = manager->GetUserMedia(aCx, privileged, mWindow, aConstraints,
|
|
|
|
onsuccess, onerror);
|
2013-07-12 18:37:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-16 10:34:57 +04:00
|
|
|
Navigator::MozGetUserMediaDevices(const MediaStreamConstraintsInternal& aConstraints,
|
|
|
|
MozGetUserMediaDevicesSuccessCallback& aOnSuccess,
|
|
|
|
NavigatorUserMediaErrorCallback& aOnError,
|
2014-02-14 23:32:58 +04:00
|
|
|
uint64_t aInnerWindowID,
|
2013-07-12 18:37:21 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
CallbackObjectHolder<MozGetUserMediaDevicesSuccessCallback,
|
2013-09-16 10:34:57 +04:00
|
|
|
nsIGetUserMediaDevicesSuccessCallback> holder1(&aOnSuccess);
|
2013-07-18 07:23:52 +04:00
|
|
|
nsCOMPtr<nsIGetUserMediaDevicesSuccessCallback> onsuccess =
|
2013-07-12 18:37:21 +04:00
|
|
|
holder1.ToXPCOMCallback();
|
|
|
|
|
2013-09-16 10:34:57 +04:00
|
|
|
CallbackObjectHolder<NavigatorUserMediaErrorCallback,
|
|
|
|
nsIDOMGetUserMediaErrorCallback> holder2(&aOnError);
|
2013-07-12 18:37:21 +04:00
|
|
|
nsCOMPtr<nsIDOMGetUserMediaErrorCallback> onerror = holder2.ToXPCOMCallback();
|
|
|
|
|
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() ||
|
|
|
|
mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-20 23:54:00 +04:00
|
|
|
MediaManager* manager = MediaManager::Get();
|
2014-02-14 23:32:58 +04:00
|
|
|
aRv = manager->GetUserMediaDevices(mWindow, aConstraints, onsuccess, onerror,
|
|
|
|
aInnerWindowID);
|
2012-06-03 11:35:15 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
DesktopNotificationCenter*
|
|
|
|
Navigator::GetMozNotification(ErrorResult& aRv)
|
|
|
|
{
|
2011-11-02 17:44:16 +04:00
|
|
|
if (mNotification) {
|
2013-07-12 18:35:44 +04:00
|
|
|
return mNotification;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
mNotification = new DesktopNotificationCenter(mWindow);
|
2013-07-12 18:35:44 +04:00
|
|
|
return mNotification;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-09-04 02:26:33 +04:00
|
|
|
#ifdef MOZ_B2G_FM
|
|
|
|
|
|
|
|
using mozilla::dom::FMRadio;
|
|
|
|
|
|
|
|
FMRadio*
|
|
|
|
Navigator::GetMozFMRadio(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mFMRadio) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
|
|
|
|
|
|
|
mFMRadio = new FMRadio();
|
|
|
|
mFMRadio->Init(mWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mFMRadio;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MOZ_B2G_FM
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsINavigatorBattery
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
battery::BatteryManager*
|
|
|
|
Navigator::GetBattery(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mBatteryManager) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
2011-11-19 14:37:21 +04:00
|
|
|
|
2014-01-07 06:53:23 +04:00
|
|
|
mBatteryManager = new battery::BatteryManager(mWindow);
|
|
|
|
mBatteryManager->Init();
|
2011-11-02 19:01:32 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
return mBatteryManager;
|
2011-11-02 16:04:39 +04:00
|
|
|
}
|
|
|
|
|
2013-10-02 21:27:07 +04:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
Navigator::GetDataStores(const nsAString& aName, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDataStoreService> service =
|
|
|
|
do_GetService("@mozilla.org/datastore-service;1");
|
|
|
|
if (!service) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> promise;
|
|
|
|
aRv = service->GetDataStores(mWindow, aName, getter_AddRefs(promise));
|
|
|
|
|
|
|
|
nsRefPtr<Promise> p = static_cast<Promise*>(promise.get());
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
2013-09-11 18:35:04 +04:00
|
|
|
PowerManager*
|
2013-07-12 18:35:35 +04:00
|
|
|
Navigator::GetMozPower(ErrorResult& aRv)
|
|
|
|
{
|
2012-01-20 07:24:00 +04:00
|
|
|
if (!mPowerManager) {
|
2013-07-12 18:35:35 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
mPowerManager = PowerManager::CreateInstance(mWindow);
|
|
|
|
if (!mPowerManager) {
|
|
|
|
// We failed to get the power manager service?
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
2012-01-20 07:24:00 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
return mPowerManager;
|
2012-01-20 07:24:00 +04:00
|
|
|
}
|
|
|
|
|
2014-01-07 16:16:07 +04:00
|
|
|
already_AddRefed<WakeLock>
|
2013-07-12 18:35:35 +04:00
|
|
|
Navigator::RequestWakeLock(const nsAString &aTopic, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-03-07 15:03:25 +04:00
|
|
|
|
2014-01-07 16:16:07 +04:00
|
|
|
nsRefPtr<power::PowerManagerService> pmService =
|
|
|
|
power::PowerManagerService::GetInstance();
|
2013-07-12 18:35:35 +04:00
|
|
|
// Maybe it went away for some reason... Or maybe we're just called
|
|
|
|
// from our XPCOM method.
|
2014-01-24 13:40:40 +04:00
|
|
|
if (!pmService) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-03-07 15:03:25 +04:00
|
|
|
|
2014-01-24 13:40:40 +04:00
|
|
|
return pmService->NewWakeLock(aTopic, mWindow, aRv);
|
2012-03-07 15:03:25 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
nsIDOMMozMobileMessageManager*
|
|
|
|
Navigator::GetMozMobileMessage()
|
|
|
|
{
|
2013-03-09 11:21:47 +04:00
|
|
|
if (!mMobileMessageManager) {
|
2013-07-12 18:35:44 +04:00
|
|
|
// Check that our window has not gone away
|
|
|
|
NS_ENSURE_TRUE(mWindow, nullptr);
|
|
|
|
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
2013-03-09 11:21:47 +04:00
|
|
|
|
|
|
|
mMobileMessageManager = new MobileMessageManager();
|
2013-06-20 22:34:38 +04:00
|
|
|
mMobileMessageManager->Init(mWindow);
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
return mMobileMessageManager;
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2013-10-29 12:12:38 +04:00
|
|
|
Telephony*
|
|
|
|
Navigator::GetMozTelephony(ErrorResult& aRv)
|
2013-07-12 18:36:22 +04:00
|
|
|
{
|
2013-10-29 12:12:38 +04:00
|
|
|
if (!mTelephony) {
|
2013-07-12 18:36:22 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
2012-12-04 06:38:25 +04:00
|
|
|
}
|
2013-10-29 12:12:38 +04:00
|
|
|
mTelephony = Telephony::Create(mWindow, aRv);
|
2012-12-04 06:38:25 +04:00
|
|
|
}
|
|
|
|
|
2013-10-29 12:12:38 +04:00
|
|
|
return mTelephony;
|
2012-12-04 06:38:25 +04:00
|
|
|
}
|
|
|
|
|
2013-10-29 12:12:38 +04:00
|
|
|
#ifdef MOZ_B2G_RIL
|
|
|
|
|
2014-01-02 07:06:17 +04:00
|
|
|
MobileConnectionArray*
|
2013-11-13 12:51:23 +04:00
|
|
|
Navigator::GetMozMobileConnections(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mMobileConnections) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-01-02 07:06:17 +04:00
|
|
|
mMobileConnections = new MobileConnectionArray(mWindow);
|
2013-11-13 12:51:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return mMobileConnections;
|
|
|
|
}
|
|
|
|
|
2013-10-29 12:12:38 +04:00
|
|
|
CellBroadcast*
|
|
|
|
Navigator::GetMozCellBroadcast(ErrorResult& aRv)
|
2013-07-12 18:36:13 +04:00
|
|
|
{
|
2013-10-29 12:12:38 +04:00
|
|
|
if (!mCellBroadcast) {
|
2013-07-12 18:36:13 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-10-29 12:12:38 +04:00
|
|
|
mCellBroadcast = CellBroadcast::Create(mWindow, aRv);
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
2013-10-29 12:12:38 +04:00
|
|
|
return mCellBroadcast;
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:38:53 +04:00
|
|
|
Voicemail*
|
2013-07-12 18:36:22 +04:00
|
|
|
Navigator::GetMozVoicemail(ErrorResult& aRv)
|
|
|
|
{
|
2012-07-19 07:27:19 +04:00
|
|
|
if (!mVoicemail) {
|
2013-07-12 18:36:22 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
2012-07-19 07:27:19 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:36:22 +04:00
|
|
|
aRv = NS_NewVoicemail(mWindow, getter_AddRefs(mVoicemail));
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-07-19 07:27:19 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:36:22 +04:00
|
|
|
return mVoicemail;
|
2012-07-19 07:27:19 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:36:22 +04:00
|
|
|
nsIDOMMozIccManager*
|
|
|
|
Navigator::GetMozIccManager(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mIccManager) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
2013-04-08 14:34:10 +04:00
|
|
|
}
|
2013-07-12 18:36:22 +04:00
|
|
|
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
2013-04-08 14:34:10 +04:00
|
|
|
|
2013-10-09 13:40:12 +04:00
|
|
|
mIccManager = new IccManager(mWindow);
|
2013-04-08 14:34:10 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:36:22 +04:00
|
|
|
return mIccManager;
|
2013-04-08 14:34:10 +04:00
|
|
|
}
|
|
|
|
|
2012-01-10 02:28:47 +04:00
|
|
|
#endif // MOZ_B2G_RIL
|
|
|
|
|
2012-02-16 04:47:13 +04:00
|
|
|
#ifdef MOZ_GAMEPAD
|
2013-07-12 18:36:32 +04:00
|
|
|
void
|
|
|
|
Navigator::GetGamepads(nsTArray<nsRefPtr<Gamepad> >& aGamepads,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE_VOID(mWindow->GetDocShell());
|
|
|
|
nsGlobalWindow* win = static_cast<nsGlobalWindow*>(mWindow.get());
|
2013-12-06 15:52:06 +04:00
|
|
|
win->SetHasGamepadEventListener(true);
|
2013-07-12 18:36:32 +04:00
|
|
|
win->GetGamepads(aGamepads);
|
|
|
|
}
|
2012-02-16 04:47:13 +04:00
|
|
|
#endif
|
|
|
|
|
2012-01-16 16:23:28 +04:00
|
|
|
//*****************************************************************************
|
2013-07-18 07:23:52 +04:00
|
|
|
// Navigator::nsIMozNavigatorNetwork
|
2012-01-16 16:23:28 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-16 14:53:48 +04:00
|
|
|
Navigator::GetMozConnection(nsISupports** aConnection)
|
2012-01-16 16:23:28 +04:00
|
|
|
{
|
2014-01-16 14:53:48 +04:00
|
|
|
nsCOMPtr<nsINetworkProperties> properties = GetMozConnection();
|
|
|
|
properties.forget(aConnection);
|
2013-07-12 18:35:44 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-01-16 21:14:56 +04:00
|
|
|
|
2014-01-16 14:53:48 +04:00
|
|
|
network::Connection*
|
2013-07-12 18:35:44 +04:00
|
|
|
Navigator::GetMozConnection()
|
|
|
|
{
|
2012-01-16 16:23:44 +04:00
|
|
|
if (!mConnection) {
|
2013-07-12 18:35:44 +04:00
|
|
|
NS_ENSURE_TRUE(mWindow, nullptr);
|
|
|
|
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
2012-01-16 21:14:56 +04:00
|
|
|
|
2012-01-16 16:23:44 +04:00
|
|
|
mConnection = new network::Connection();
|
2013-06-20 22:34:38 +04:00
|
|
|
mConnection->Init(mWindow);
|
2012-01-16 16:23:44 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
return mConnection;
|
2012-01-16 16:23:28 +04:00
|
|
|
}
|
|
|
|
|
2012-02-20 19:15:19 +04:00
|
|
|
#ifdef MOZ_B2G_BT
|
2013-08-12 12:31:58 +04:00
|
|
|
bluetooth::BluetoothManager*
|
2013-07-12 18:36:32 +04:00
|
|
|
Navigator::GetMozBluetooth(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mBluetooth) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
mBluetooth = bluetooth::BluetoothManager::Create(mWindow);
|
2012-02-20 19:15:19 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:36:32 +04:00
|
|
|
return mBluetooth;
|
2012-02-20 19:15:19 +04:00
|
|
|
}
|
|
|
|
#endif //MOZ_B2G_BT
|
|
|
|
|
2012-07-23 10:53:08 +04:00
|
|
|
nsresult
|
2012-07-03 04:16:55 +04:00
|
|
|
Navigator::EnsureMessagesManager()
|
|
|
|
{
|
|
|
|
if (mMessagesManager) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
NS_ENSURE_STATE(mWindow);
|
2012-07-03 04:16:55 +04:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMNavigatorSystemMessages> messageManager =
|
|
|
|
do_CreateInstance("@mozilla.org/system-message-manager;1", &rv);
|
2013-08-12 12:31:58 +04:00
|
|
|
|
2012-07-03 04:16:55 +04:00
|
|
|
nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi =
|
|
|
|
do_QueryInterface(messageManager);
|
|
|
|
NS_ENSURE_TRUE(gpi, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// We don't do anything with the return value.
|
2013-05-30 00:16:04 +04:00
|
|
|
AutoJSContext cx;
|
|
|
|
JS::Rooted<JS::Value> prop_val(cx);
|
2014-01-09 21:39:36 +04:00
|
|
|
rv = gpi->Init(mWindow, &prop_val);
|
2012-07-03 04:16:55 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mMessagesManager = messageManager.forget();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
bool
|
|
|
|
Navigator::MozHasPendingMessage(const nsAString& aType, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// The WebIDL binding is responsible for the pref check here.
|
2012-07-03 04:16:55 +04:00
|
|
|
nsresult rv = EnsureMessagesManager();
|
2013-07-12 18:35:44 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-03 04:16:55 +04:00
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
bool result = false;
|
|
|
|
rv = mMessagesManager->MozHasPendingMessage(aType, &result);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return result;
|
2012-07-03 04:16:55 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
void
|
|
|
|
Navigator::MozSetMessageHandler(const nsAString& aType,
|
|
|
|
systemMessageCallback* aCallback,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// The WebIDL binding is responsible for the pref check here.
|
|
|
|
nsresult rv = EnsureMessagesManager();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CallbackObjectHolder<systemMessageCallback, nsIDOMSystemMessageCallback>
|
|
|
|
holder(aCallback);
|
|
|
|
nsCOMPtr<nsIDOMSystemMessageCallback> callback = holder.ToXPCOMCallback();
|
|
|
|
|
|
|
|
rv = mMessagesManager->MozSetMessageHandler(aType, callback);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-05 19:20:03 +04:00
|
|
|
#ifdef MOZ_TIME_MANAGER
|
2013-07-12 18:36:32 +04:00
|
|
|
time::TimeManager*
|
|
|
|
Navigator::GetMozTime(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-09-11 10:05:00 +04:00
|
|
|
if (!mTimeManager) {
|
2013-06-20 22:34:38 +04:00
|
|
|
mTimeManager = new time::TimeManager(mWindow);
|
2012-09-11 10:05:00 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:36:32 +04:00
|
|
|
return mTimeManager;
|
2012-09-11 10:05:00 +04:00
|
|
|
}
|
2012-11-05 19:20:03 +04:00
|
|
|
#endif
|
2012-09-11 10:05:00 +04:00
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
nsDOMCameraManager*
|
|
|
|
Navigator::GetMozCameras(ErrorResult& aRv)
|
|
|
|
{
|
2012-07-31 01:59:05 +04:00
|
|
|
if (!mCameraManager) {
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow ||
|
|
|
|
!mWindow->GetOuterWindow() ||
|
|
|
|
mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) {
|
2013-07-12 18:35:44 +04:00
|
|
|
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return nullptr;
|
2012-07-31 01:59:05 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
mCameraManager = nsDOMCameraManager::CreateInstance(mWindow);
|
2012-07-31 01:59:05 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
return mCameraManager;
|
2012-07-31 01:59:05 +04:00
|
|
|
}
|
|
|
|
|
2012-02-02 01:58:01 +04:00
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
Navigator::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2012-02-02 01:58:01 +04:00
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
|
|
|
|
// TODO: add SizeOfIncludingThis() to nsMimeTypeArray, bug 674113.
|
|
|
|
// TODO: add SizeOfIncludingThis() to nsPluginArray, bug 674114.
|
2013-04-12 22:47:47 +04:00
|
|
|
// TODO: add SizeOfIncludingThis() to Geolocation, bug 674115.
|
2013-04-10 18:20:43 +04:00
|
|
|
// TODO: add SizeOfIncludingThis() to DesktopNotificationCenter, bug 674116.
|
2012-02-02 01:58:01 +04:00
|
|
|
|
|
|
|
return n;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2011-12-28 17:39:55 +04:00
|
|
|
void
|
|
|
|
Navigator::SetWindow(nsPIDOMWindow *aInnerWindow)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aInnerWindow->IsInnerWindow(),
|
|
|
|
"Navigator must get an inner window!");
|
2013-06-20 22:34:38 +04:00
|
|
|
mWindow = aInnerWindow;
|
2011-12-28 17:39:55 +04:00
|
|
|
}
|
|
|
|
|
2012-06-03 11:35:15 +04:00
|
|
|
void
|
|
|
|
Navigator::OnNavigation()
|
|
|
|
{
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow) {
|
2012-07-31 01:59:05 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-03 11:35:15 +04:00
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
2012-07-31 01:59:05 +04:00
|
|
|
// Inform MediaManager in case there are live streams or pending callbacks.
|
2012-06-03 11:35:15 +04:00
|
|
|
MediaManager *manager = MediaManager::Get();
|
2013-02-08 07:14:21 +04:00
|
|
|
if (manager) {
|
2013-06-20 22:34:38 +04:00
|
|
|
manager->OnNavigation(mWindow->WindowID());
|
2013-02-08 07:14:21 +04:00
|
|
|
}
|
2012-06-03 11:35:15 +04:00
|
|
|
#endif
|
2012-07-31 01:59:05 +04:00
|
|
|
if (mCameraManager) {
|
2013-06-20 22:34:38 +04:00
|
|
|
mCameraManager->OnNavigation(mWindow->WindowID());
|
2012-07-31 01:59:05 +04:00
|
|
|
}
|
2012-06-03 11:35:15 +04:00
|
|
|
}
|
|
|
|
|
2012-10-02 13:08:02 +04:00
|
|
|
bool
|
|
|
|
Navigator::CheckPermission(const char* type)
|
|
|
|
{
|
2013-07-12 18:35:35 +04:00
|
|
|
return CheckPermission(mWindow, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::CheckPermission(nsPIDOMWindow* aWindow, const char* aType)
|
|
|
|
{
|
|
|
|
if (!aWindow) {
|
2013-06-20 22:34:38 +04:00
|
|
|
return false;
|
|
|
|
}
|
2012-10-02 13:08:02 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr =
|
|
|
|
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(permMgr, false);
|
|
|
|
|
|
|
|
uint32_t permission = nsIPermissionManager::DENY_ACTION;
|
2013-07-12 18:35:35 +04:00
|
|
|
permMgr->TestPermissionFromWindow(aWindow, aType, &permission);
|
2012-10-02 13:08:02 +04:00
|
|
|
return permission == nsIPermissionManager::ALLOW_ACTION;
|
|
|
|
}
|
|
|
|
|
2012-11-30 02:52:03 +04:00
|
|
|
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
2013-07-12 18:36:32 +04:00
|
|
|
system::AudioChannelManager*
|
|
|
|
Navigator::GetMozAudioChannelManager(ErrorResult& aRv)
|
|
|
|
{
|
2012-11-30 02:52:03 +04:00
|
|
|
if (!mAudioChannelManager) {
|
2013-07-12 18:36:32 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-11-30 02:52:03 +04:00
|
|
|
mAudioChannelManager = new system::AudioChannelManager();
|
2013-06-20 22:34:38 +04:00
|
|
|
mAudioChannelManager->Init(mWindow);
|
2012-11-30 02:52:03 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:36:32 +04:00
|
|
|
return mAudioChannelManager;
|
2012-11-30 02:52:03 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-12 18:37:23 +04:00
|
|
|
bool
|
|
|
|
Navigator::DoNewResolve(JSContext* aCx, JS::Handle<JSObject*> aObject,
|
2013-07-16 09:31:03 +04:00
|
|
|
JS::Handle<jsid> aId,
|
2014-01-22 07:08:51 +04:00
|
|
|
JS::MutableHandle<JSPropertyDescriptor> aDesc)
|
2013-07-12 18:37:23 +04:00
|
|
|
{
|
|
|
|
if (!JSID_IS_STRING(aId)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-20 03:24:29 +04:00
|
|
|
nsScriptNameSpaceManager* nameSpaceManager = GetNameSpaceManager();
|
2013-07-12 18:37:23 +04:00
|
|
|
if (!nameSpaceManager) {
|
2013-09-09 07:29:21 +04:00
|
|
|
return Throw(aCx, NS_ERROR_NOT_INITIALIZED);
|
2013-07-12 18:37:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDependentJSString name(aId);
|
|
|
|
|
|
|
|
const nsGlobalNameStruct* name_struct =
|
|
|
|
nameSpaceManager->LookupNavigatorName(name);
|
|
|
|
if (!name_struct) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeNewDOMBinding) {
|
|
|
|
ConstructNavigatorProperty construct = name_struct->mConstructNavigatorProperty;
|
|
|
|
MOZ_ASSERT(construct);
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> naviObj(aCx,
|
|
|
|
js::CheckedUnwrap(aObject,
|
|
|
|
/* stopAtOuter = */ false));
|
|
|
|
if (!naviObj) {
|
2013-09-09 07:29:21 +04:00
|
|
|
return Throw(aCx, NS_ERROR_DOM_SECURITY_ERR);
|
2013-07-12 18:37:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> domObject(aCx);
|
|
|
|
{
|
|
|
|
JSAutoCompartment ac(aCx, naviObj);
|
|
|
|
|
|
|
|
// Check whether our constructor is enabled after we unwrap Xrays, since
|
|
|
|
// we don't want to define an interface on the Xray if it's disabled in
|
|
|
|
// the target global, even if it's enabled in the Xray's global.
|
|
|
|
if (name_struct->mConstructorEnabled &&
|
|
|
|
!(*name_struct->mConstructorEnabled)(aCx, naviObj)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-06 17:59:13 +04:00
|
|
|
if (name.EqualsLiteral("mozSettings")) {
|
|
|
|
bool hasPermission = CheckPermission("settings-read") ||
|
|
|
|
CheckPermission("settings-write");
|
|
|
|
if (!hasPermission) {
|
2014-01-22 07:08:51 +04:00
|
|
|
FillPropertyDescriptor(aDesc, aObject, JS::NullValue(), false);
|
2013-08-06 17:59:13 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-28 11:18:12 +04:00
|
|
|
if (name.EqualsLiteral("mozDownloadManager")) {
|
|
|
|
if (!CheckPermission("downloads")) {
|
2014-01-22 07:08:51 +04:00
|
|
|
FillPropertyDescriptor(aDesc, aObject, JS::NullValue(), false);
|
2013-11-28 11:18:12 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:37:23 +04:00
|
|
|
domObject = construct(aCx, naviObj);
|
|
|
|
if (!domObject) {
|
2013-09-09 07:29:21 +04:00
|
|
|
return Throw(aCx, NS_ERROR_FAILURE);
|
2013-07-12 18:37:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-16 04:02:23 +04:00
|
|
|
if (!JS_WrapObject(aCx, &domObject)) {
|
2013-07-12 18:37:23 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-22 07:08:51 +04:00
|
|
|
FillPropertyDescriptor(aDesc, aObject, JS::ObjectValue(*domObject), false);
|
2013-07-12 18:37:23 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(name_struct->mType == nsGlobalNameStruct::eTypeNavigatorProperty,
|
|
|
|
"unexpected type");
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> native(do_CreateInstance(name_struct->mCID, &rv));
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-09-09 07:29:21 +04:00
|
|
|
return Throw(aCx, rv);
|
2013-07-12 18:37:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> prop_val(aCx, JS::UndefinedValue()); // Property value.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi(do_QueryInterface(native));
|
|
|
|
|
|
|
|
if (gpi) {
|
|
|
|
if (!mWindow) {
|
2013-09-09 07:29:21 +04:00
|
|
|
return Throw(aCx, NS_ERROR_UNEXPECTED);
|
2013-07-12 18:37:23 +04:00
|
|
|
}
|
|
|
|
|
2014-01-09 21:39:36 +04:00
|
|
|
rv = gpi->Init(mWindow, &prop_val);
|
2013-07-12 18:37:23 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2013-09-09 07:29:21 +04:00
|
|
|
return Throw(aCx, rv);
|
2013-07-12 18:37:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (JSVAL_IS_PRIMITIVE(prop_val) && !JSVAL_IS_NULL(prop_val)) {
|
2014-02-13 03:19:32 +04:00
|
|
|
rv = nsContentUtils::WrapNative(aCx, aObject, native, &prop_val);
|
2013-07-12 18:37:23 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-09-09 07:29:21 +04:00
|
|
|
return Throw(aCx, rv);
|
2013-07-12 18:37:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-26 20:19:05 +04:00
|
|
|
if (!JS_WrapValue(aCx, &prop_val)) {
|
2013-09-09 07:29:21 +04:00
|
|
|
return Throw(aCx, NS_ERROR_UNEXPECTED);
|
2013-07-12 18:37:23 +04:00
|
|
|
}
|
|
|
|
|
2014-01-22 07:08:51 +04:00
|
|
|
FillPropertyDescriptor(aDesc, aObject, prop_val, false);
|
2013-07-16 09:31:03 +04:00
|
|
|
return true;
|
2013-07-12 18:37:23 +04:00
|
|
|
}
|
|
|
|
|
2013-08-04 07:38:54 +04:00
|
|
|
static PLDHashOperator
|
|
|
|
SaveNavigatorName(const nsAString& aName, void* aClosure)
|
|
|
|
{
|
|
|
|
nsTArray<nsString>* arr = static_cast<nsTArray<nsString>*>(aClosure);
|
|
|
|
arr->AppendElement(aName);
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Navigator::GetOwnPropertyNames(JSContext* aCx, nsTArray<nsString>& aNames,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2013-08-20 03:24:29 +04:00
|
|
|
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
|
2013-08-04 07:38:54 +04:00
|
|
|
if (!nameSpaceManager) {
|
|
|
|
NS_ERROR("Can't get namespace manager.");
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nameSpaceManager->EnumerateNavigatorNames(SaveNavigatorName, &aNames);
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:37:23 +04:00
|
|
|
JSObject*
|
|
|
|
Navigator::WrapObject(JSContext* cx, JS::Handle<JSObject*> scope)
|
|
|
|
{
|
|
|
|
return NavigatorBinding::Wrap(cx, scope, this);
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasBatterySupport(JSContext* /* unused*/, JSObject* /*unused */)
|
|
|
|
{
|
|
|
|
return battery::BatteryManager::HasSupport();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasPowerSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && PowerManager::CheckPermission(win);
|
|
|
|
}
|
|
|
|
|
2013-08-01 08:04:59 +04:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasPhoneNumberSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return CheckPermission(win, "phonenumberservice");
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasIdleSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsIdleObserverAPIEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return CheckPermission(win, "idle");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasWakeLockSupport(JSContext* /* unused*/, JSObject* /*unused */)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPowerManagerService> pmService =
|
|
|
|
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
|
|
|
|
// No service means no wake lock support
|
|
|
|
return !!pmService;
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasMobileMessageSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
|
|
|
|
#ifndef MOZ_WEBSMS_BACKEND
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// First of all, the general pref has to be turned on.
|
|
|
|
bool enabled = false;
|
|
|
|
Preferences::GetBool("dom.sms.enabled", &enabled);
|
2014-01-28 00:40:50 +04:00
|
|
|
if (!enabled) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-12 18:35:44 +04:00
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
NS_ENSURE_TRUE(win, false);
|
|
|
|
NS_ENSURE_TRUE(win->GetDocShell(), false);
|
2013-07-12 18:35:44 +04:00
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
if (!CheckPermission(win, "sms")) {
|
2013-07-12 18:35:44 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:36:13 +04:00
|
|
|
/* static */
|
|
|
|
bool
|
2013-12-12 00:15:16 +04:00
|
|
|
Navigator::HasTelephonySupport(JSContext* cx, JSObject* aGlobal)
|
2013-07-12 18:36:13 +04:00
|
|
|
{
|
2013-12-12 00:15:16 +04:00
|
|
|
JS::Rooted<JSObject*> global(cx, aGlobal);
|
|
|
|
|
2013-10-18 00:51:27 +04:00
|
|
|
// First of all, the general pref has to be turned on.
|
|
|
|
bool enabled = false;
|
|
|
|
Preferences::GetBool("dom.telephony.enabled", &enabled);
|
2014-01-28 00:40:50 +04:00
|
|
|
if (!enabled) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-18 00:51:27 +04:00
|
|
|
|
2013-12-12 00:15:16 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(global);
|
2013-10-18 00:51:27 +04:00
|
|
|
return win && CheckPermission(win, "telephony");
|
2013-07-12 18:36:13 +04:00
|
|
|
}
|
2013-07-12 18:36:22 +04:00
|
|
|
|
2013-10-29 12:12:38 +04:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasCameraSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && nsDOMCameraManager::CheckPermission(win);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-07-12 18:36:22 +04:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasMobileConnectionSupport(JSContext* /* unused */,
|
|
|
|
JSObject* aGlobal)
|
|
|
|
{
|
2013-10-18 00:51:27 +04:00
|
|
|
// First of all, the general pref has to be turned on.
|
|
|
|
bool enabled = false;
|
|
|
|
Preferences::GetBool("dom.mobileconnection.enabled", &enabled);
|
|
|
|
NS_ENSURE_TRUE(enabled, false);
|
|
|
|
|
2013-07-12 18:36:22 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && (CheckPermission(win, "mobileconnection") ||
|
|
|
|
CheckPermission(win, "mobilenetwork"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasCellBroadcastSupport(JSContext* /* unused */,
|
|
|
|
JSObject* aGlobal)
|
|
|
|
{
|
2013-10-18 00:51:27 +04:00
|
|
|
// First of all, the general pref has to be turned on.
|
|
|
|
bool enabled = false;
|
|
|
|
Preferences::GetBool("dom.cellbroadcast.enabled", &enabled);
|
|
|
|
NS_ENSURE_TRUE(enabled, false);
|
|
|
|
|
2013-07-12 18:36:22 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && CheckPermission(win, "cellbroadcast");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasVoicemailSupport(JSContext* /* unused */,
|
|
|
|
JSObject* aGlobal)
|
|
|
|
{
|
2013-10-18 00:51:27 +04:00
|
|
|
// First of all, the general pref has to be turned on.
|
|
|
|
bool enabled = false;
|
|
|
|
Preferences::GetBool("dom.voicemail.enabled", &enabled);
|
|
|
|
NS_ENSURE_TRUE(enabled, false);
|
|
|
|
|
2013-07-12 18:36:22 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && CheckPermission(win, "voicemail");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasIccManagerSupport(JSContext* /* unused */,
|
|
|
|
JSObject* aGlobal)
|
|
|
|
{
|
2013-10-18 00:51:27 +04:00
|
|
|
// First of all, the general pref has to be turned on.
|
|
|
|
bool enabled = false;
|
|
|
|
Preferences::GetBool("dom.icc.enabled", &enabled);
|
|
|
|
NS_ENSURE_TRUE(enabled, false);
|
|
|
|
|
2013-07-12 18:36:22 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && CheckPermission(win, "mobileconnection");
|
|
|
|
}
|
2014-02-05 13:52:25 +04:00
|
|
|
#endif // MOZ_B2G_RIL
|
2014-01-27 11:48:10 +04:00
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasWifiManagerSupport(JSContext* /* unused */,
|
|
|
|
JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
// On XBL scope, the global object is NOT |window|. So we have
|
|
|
|
// to use nsContentUtils::GetObjectPrincipal to get the principal
|
|
|
|
// and test directly with permission manager.
|
|
|
|
|
|
|
|
nsIPrincipal* principal = nsContentUtils::GetObjectPrincipal(aGlobal);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr =
|
|
|
|
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(permMgr, false);
|
|
|
|
|
|
|
|
uint32_t permission = nsIPermissionManager::DENY_ACTION;
|
|
|
|
permMgr->TestPermissionFromPrincipal(principal, "wifi-manage", &permission);
|
|
|
|
return nsIPermissionManager::ALLOW_ACTION == permission;
|
|
|
|
}
|
2013-07-12 18:36:13 +04:00
|
|
|
|
2013-07-12 18:36:32 +04:00
|
|
|
#ifdef MOZ_B2G_BT
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasBluetoothSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && bluetooth::BluetoothManager::CheckPermission(win);
|
|
|
|
}
|
|
|
|
#endif // MOZ_B2G_BT
|
|
|
|
|
2013-09-04 02:26:33 +04:00
|
|
|
#ifdef MOZ_B2G_FM
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasFMRadioSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && CheckPermission(win, "fmradio");
|
|
|
|
}
|
|
|
|
#endif // MOZ_B2G_FM
|
|
|
|
|
2013-10-03 02:09:08 +04:00
|
|
|
#ifdef MOZ_NFC
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasNfcSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
2013-12-17 06:32:29 +04:00
|
|
|
// Do not support NFC if NFC content helper does not exist.
|
|
|
|
nsCOMPtr<nsISupports> contentHelper = do_GetService("@mozilla.org/nfc/content-helper;1");
|
|
|
|
if (!contentHelper) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-03 02:09:08 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && (CheckPermission(win, "nfc-read") ||
|
|
|
|
CheckPermission(win, "nfc-write"));
|
|
|
|
}
|
|
|
|
|
2014-01-13 13:33:12 +04:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasNfcPeerSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && CheckPermission(win, "nfc-write");
|
|
|
|
}
|
2014-01-16 05:47:43 +04:00
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasNfcManagerSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && CheckPermission(win, "nfc-manager");
|
|
|
|
}
|
2014-01-13 13:33:12 +04:00
|
|
|
#endif // MOZ_NFC
|
2013-10-03 02:09:08 +04:00
|
|
|
|
2013-07-12 18:36:32 +04:00
|
|
|
#ifdef MOZ_TIME_MANAGER
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasTimeSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && CheckPermission(win, "time");
|
|
|
|
}
|
|
|
|
#endif // MOZ_TIME_MANAGER
|
|
|
|
|
2013-07-12 18:37:21 +04:00
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
|
|
|
/* static */
|
2014-01-14 02:28:40 +04:00
|
|
|
bool
|
|
|
|
Navigator::HasUserMediaSupport(JSContext* /* unused */,
|
|
|
|
JSObject* /* unused */)
|
2013-07-12 18:37:21 +04:00
|
|
|
{
|
|
|
|
// Make enabling peerconnection enable getUserMedia() as well
|
|
|
|
return Preferences::GetBool("media.navigator.enabled", false) ||
|
|
|
|
Preferences::GetBool("media.peerconnection.enabled", false);
|
|
|
|
}
|
|
|
|
#endif // MOZ_MEDIA_NAVIGATOR
|
|
|
|
|
2013-08-07 19:04:10 +04:00
|
|
|
/* static */
|
2014-01-14 02:28:40 +04:00
|
|
|
bool
|
|
|
|
Navigator::HasPushNotificationsSupport(JSContext* /* unused */,
|
|
|
|
JSObject* aGlobal)
|
2013-08-07 19:04:10 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
2014-01-14 02:28:40 +04:00
|
|
|
return Preferences::GetBool("services.push.enabled", false) &&
|
|
|
|
win && CheckPermission(win, "push");
|
2013-08-07 19:04:10 +04:00
|
|
|
}
|
|
|
|
|
2013-09-26 11:10:56 +04:00
|
|
|
/* static */
|
2014-01-14 02:28:40 +04:00
|
|
|
bool
|
|
|
|
Navigator::HasInputMethodSupport(JSContext* /* unused */,
|
|
|
|
JSObject* aGlobal)
|
2013-09-26 11:10:56 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
2014-01-14 02:28:40 +04:00
|
|
|
if (Preferences::GetBool("dom.mozInputMethod.testing", false)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Preferences::GetBool("dom.mozInputMethod.enabled", false) &&
|
|
|
|
win && CheckPermission(win, "input");
|
2013-09-26 11:10:56 +04:00
|
|
|
}
|
|
|
|
|
2013-12-06 03:12:23 +04:00
|
|
|
/* static */
|
|
|
|
bool
|
2013-12-12 00:15:16 +04:00
|
|
|
Navigator::HasDataStoreSupport(JSContext* cx, JSObject* aGlobal)
|
2013-12-06 03:12:23 +04:00
|
|
|
{
|
2013-12-12 00:15:16 +04:00
|
|
|
JS::Rooted<JSObject*> global(cx, aGlobal);
|
|
|
|
|
2013-12-06 03:12:23 +04:00
|
|
|
// First of all, the general pref has to be turned on.
|
|
|
|
bool enabled = false;
|
|
|
|
Preferences::GetBool("dom.datastore.enabled", &enabled);
|
2014-01-28 00:40:50 +04:00
|
|
|
if (!enabled) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-06 03:12:23 +04:00
|
|
|
|
|
|
|
// Just for testing, we can enable DataStore for any kind of app.
|
|
|
|
if (Preferences::GetBool("dom.testing.datastore_enabled_for_hosted_apps", false)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-12 00:15:16 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(global);
|
2013-12-06 03:12:23 +04:00
|
|
|
if (!win) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* doc = win->GetExtantDoc();
|
|
|
|
if (!doc || !doc->NodePrincipal()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t status;
|
|
|
|
if (NS_FAILED(doc->NodePrincipal()->GetAppStatus(&status))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status == nsIPrincipal::APP_STATUS_CERTIFIED;
|
|
|
|
}
|
|
|
|
|
2014-01-24 23:53:05 +04:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasDownloadsSupport(JSContext* aCx, JSObject* aGlobal)
|
|
|
|
{
|
2014-02-05 22:38:18 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
2014-01-24 23:53:05 +04:00
|
|
|
|
|
|
|
return win &&
|
|
|
|
CheckPermission(win, "downloads") &&
|
|
|
|
Preferences::GetBool("dom.mozDownloads.enabled");
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<nsPIDOMWindow>
|
|
|
|
Navigator::GetWindowFromGlobal(JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win =
|
|
|
|
do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(aGlobal));
|
|
|
|
MOZ_ASSERT(!win || win->IsInnerWindow());
|
|
|
|
return win.forget();
|
|
|
|
}
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_GetNavigatorUserAgent(nsAString& aUserAgent)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString ua;
|
2011-11-02 17:44:16 +04:00
|
|
|
rv = service->GetUserAgent(ua);
|
|
|
|
CopyASCIItoUTF16(ua, aUserAgent);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_GetNavigatorPlatform(nsAString& aPlatform)
|
|
|
|
{
|
2012-10-26 03:10:53 +04:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2011-11-02 17:44:16 +04:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
mozilla::Preferences::GetString("general.platform.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aPlatform = override;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Sorry for the #if platform ugliness, but Communicator is likewise
|
|
|
|
// hardcoded and we are seeking backward compatibility here (bug 47080).
|
|
|
|
#if defined(_WIN64)
|
|
|
|
aPlatform.AssignLiteral("Win64");
|
|
|
|
#elif defined(WIN32)
|
|
|
|
aPlatform.AssignLiteral("Win32");
|
|
|
|
#elif defined(XP_MACOSX) && defined(__ppc__)
|
|
|
|
aPlatform.AssignLiteral("MacPPC");
|
|
|
|
#elif defined(XP_MACOSX) && defined(__i386__)
|
|
|
|
aPlatform.AssignLiteral("MacIntel");
|
|
|
|
#elif defined(XP_MACOSX) && defined(__x86_64__)
|
|
|
|
aPlatform.AssignLiteral("MacIntel");
|
|
|
|
#else
|
|
|
|
// XXX Communicator uses compiled-in build-time string defines
|
|
|
|
// to indicate the platform it was compiled *for*, not what it is
|
|
|
|
// currently running *on* which is what this does.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString plat;
|
2011-11-02 17:44:16 +04:00
|
|
|
rv = service->GetOscpu(plat);
|
|
|
|
CopyASCIItoUTF16(plat, aPlatform);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
nsresult
|
|
|
|
NS_GetNavigatorAppVersion(nsAString& aAppVersion)
|
|
|
|
{
|
2012-10-26 03:10:53 +04:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2011-11-02 17:44:16 +04:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
mozilla::Preferences::GetString("general.appversion.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aAppVersion = override;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString str;
|
2011-11-02 17:44:16 +04:00
|
|
|
rv = service->GetAppVersion(str);
|
|
|
|
CopyASCIItoUTF16(str, aAppVersion);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
aAppVersion.AppendLiteral(" (");
|
|
|
|
|
|
|
|
rv = service->GetPlatform(str);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
AppendASCIItoUTF16(str, aAppVersion);
|
2014-01-04 19:02:17 +04:00
|
|
|
aAppVersion.Append(char16_t(')'));
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
void
|
2011-11-02 17:44:16 +04:00
|
|
|
NS_GetNavigatorAppName(nsAString& aAppName)
|
|
|
|
{
|
2012-10-26 03:10:53 +04:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2011-11-02 17:44:16 +04:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
mozilla::Preferences::GetString("general.appname.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aAppName = override;
|
2013-11-18 03:10:15 +04:00
|
|
|
return;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aAppName.AssignLiteral("Netscape");
|
|
|
|
}
|