2011-11-02 13:44:16 +00: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 11:12:37 +00: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 13:44:16 +00:00
|
|
|
|
|
|
|
// Needs to be first.
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
|
|
|
#include "Navigator.h"
|
|
|
|
#include "nsIXULAppInfo.h"
|
|
|
|
#include "nsPluginArray.h"
|
|
|
|
#include "nsMimeTypeArray.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-04-10 14:20:43 +00:00
|
|
|
#include "mozilla/dom/DesktopNotification.h"
|
2014-10-08 16:15:23 +00:00
|
|
|
#include "mozilla/dom/File.h"
|
2011-11-02 13:44:16 +00:00
|
|
|
#include "nsGeolocation.h"
|
|
|
|
#include "nsIHttpProtocolHandler.h"
|
2014-03-06 15:51:23 +00:00
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsIContentSecurityPolicy.h"
|
|
|
|
#include "nsContentPolicyUtils.h"
|
|
|
|
#include "nsCrossSiteListenerProxy.h"
|
|
|
|
#include "nsISupportsPriority.h"
|
2011-11-02 13:44:16 +00: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 15:01:32 +00:00
|
|
|
#include "BatteryManager.h"
|
2013-09-11 14:35:04 +00:00
|
|
|
#include "mozilla/dom/PowerManager.h"
|
2014-01-07 12:16:07 +00:00
|
|
|
#include "mozilla/dom/WakeLock.h"
|
|
|
|
#include "mozilla/dom/power/PowerManagerService.h"
|
2014-08-25 09:24:03 +00:00
|
|
|
#include "mozilla/dom/CellBroadcast.h"
|
2013-03-09 07:21:47 +00:00
|
|
|
#include "mozilla/dom/MobileMessageManager.h"
|
2013-11-19 23:14:07 +00:00
|
|
|
#include "mozilla/dom/ServiceWorkerContainer.h"
|
2013-10-29 08:12:38 +00:00
|
|
|
#include "mozilla/dom/Telephony.h"
|
2014-09-26 05:00:23 +00:00
|
|
|
#include "mozilla/dom/Voicemail.h"
|
2011-11-10 21:26:36 +00:00
|
|
|
#include "mozilla/Hal.h"
|
2012-10-11 22:56:13 +00:00
|
|
|
#include "nsISiteSpecificUserAgent.h"
|
2011-11-10 21:26:36 +00:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2012-07-26 19:33:45 +00:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2012-01-16 12:23:44 +00:00
|
|
|
#include "Connection.h"
|
2014-03-05 00:37:43 +00:00
|
|
|
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
|
2013-06-24 20:07:03 +00:00
|
|
|
#include "nsGlobalWindow.h"
|
2014-06-07 17:30:18 +00:00
|
|
|
#ifdef MOZ_B2G
|
|
|
|
#include "nsIMobileIdentityService.h"
|
|
|
|
#endif
|
2012-08-27 17:34:10 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-10-22 11:23:00 +00:00
|
|
|
#include "mozilla/dom/IccManager.h"
|
2014-01-02 03:06:17 +00:00
|
|
|
#include "mozilla/dom/MobileConnectionArray.h"
|
2012-08-27 17:34:10 +00:00
|
|
|
#endif
|
2012-06-29 08:32:21 +00:00
|
|
|
#include "nsIIdleObserver.h"
|
2012-08-17 00:42:26 +00:00
|
|
|
#include "nsIPermissionManager.h"
|
2014-03-06 15:51:23 +00:00
|
|
|
#include "nsMimeTypes.h"
|
2012-08-23 19:33:46 +00:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsIHttpChannel.h"
|
2014-03-06 15:51:23 +00:00
|
|
|
#include "nsIHttpChannelInternal.h"
|
2012-09-11 06:05:00 +00:00
|
|
|
#include "TimeManager.h"
|
2013-08-15 18:17:48 +00:00
|
|
|
#include "DeviceStorage.h"
|
|
|
|
#include "nsIDOMNavigatorSystemMessages.h"
|
2014-03-06 15:51:23 +00:00
|
|
|
#include "nsStreamUtils.h"
|
2013-12-05 23:12:23 +00:00
|
|
|
#include "nsIAppsService.h"
|
|
|
|
#include "mozIApplication.h"
|
2014-01-28 16:09:34 +00:00
|
|
|
#include "WidgetUtils.h"
|
2014-03-06 15:51:23 +00:00
|
|
|
#include "mozIThirdPartyUtil.h"
|
2011-11-02 13:44:16 +00:00
|
|
|
|
2012-06-03 07:35:15 +00:00
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
|
|
|
#include "MediaManager.h"
|
|
|
|
#endif
|
2012-02-20 15:15:19 +00:00
|
|
|
#ifdef MOZ_B2G_BT
|
2012-05-24 04:02:23 +00:00
|
|
|
#include "BluetoothManager.h"
|
2012-02-20 15:15:19 +00:00
|
|
|
#endif
|
2012-07-30 21:59:05 +00:00
|
|
|
#include "DOMCameraManager.h"
|
2012-01-09 22:28:47 +00:00
|
|
|
|
2012-11-29 22:52:03 +00:00
|
|
|
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
|
|
|
#include "AudioChannelManager.h"
|
|
|
|
#endif
|
|
|
|
|
2013-09-03 22:26:33 +00:00
|
|
|
#ifdef MOZ_B2G_FM
|
|
|
|
#include "mozilla/dom/FMRadio.h"
|
|
|
|
#endif
|
|
|
|
|
2012-07-03 00:16:55 +00:00
|
|
|
#include "nsIDOMGlobalPropertyInitializer.h"
|
2014-06-03 14:36:46 +00:00
|
|
|
#include "mozilla/dom/DataStoreService.h"
|
2013-07-12 14:35:35 +00:00
|
|
|
#include "nsJSUtils.h"
|
|
|
|
|
2013-07-12 14:37:23 +00:00
|
|
|
#include "nsScriptNameSpaceManager.h"
|
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
#include "mozilla/dom/NavigatorBinding.h"
|
2013-10-02 17:27:07 +00:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2013-09-11 15:45:51 +00:00
|
|
|
|
2014-03-06 15:51:23 +00:00
|
|
|
#include "nsIUploadChannel2.h"
|
|
|
|
#include "nsFormData.h"
|
2014-03-26 04:15:14 +00:00
|
|
|
#include "nsIPrivateBrowsingChannel.h"
|
|
|
|
#include "nsIDocShell.h"
|
2014-03-06 15:51:23 +00:00
|
|
|
|
2014-03-12 09:03:05 +00:00
|
|
|
#include "WorkerPrivate.h"
|
|
|
|
#include "WorkerRunnable.h"
|
|
|
|
|
2014-05-21 05:49:36 +00:00
|
|
|
#if defined(XP_LINUX)
|
|
|
|
#include "mozilla/Hal.h"
|
|
|
|
#endif
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
|
|
|
|
2014-07-14 23:08:45 +00:00
|
|
|
#include "mozilla/dom/FeatureList.h"
|
|
|
|
|
2011-11-02 13:44:16 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2011-11-10 21:26:36 +00:00
|
|
|
static bool sDoNotTrackEnabled = false;
|
2014-10-22 06:11:11 +00:00
|
|
|
static uint32_t sDoNotTrackValue = 1;
|
2011-11-10 21:26:36 +00:00
|
|
|
static bool sVibratorEnabled = false;
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t sMaxVibrateMS = 0;
|
|
|
|
static uint32_t sMaxVibrateListLen = 0;
|
2011-11-02 13:44:16 +00:00
|
|
|
|
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
Navigator::Init()
|
|
|
|
{
|
|
|
|
Preferences::AddBoolVarCache(&sDoNotTrackEnabled,
|
|
|
|
"privacy.donottrackheader.enabled",
|
|
|
|
false);
|
2014-10-22 06:11:11 +00:00
|
|
|
Preferences::AddUintVarCache(&sDoNotTrackValue,
|
|
|
|
"privacy.donottrackheader.value",
|
|
|
|
1);
|
2011-11-10 21:26:36 +00: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 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2011-12-01 08:28:16 +00:00
|
|
|
Navigator::Navigator(nsPIDOMWindow* aWindow)
|
2013-06-20 18:34:38 +00:00
|
|
|
: mWindow(aWindow)
|
2011-11-02 13:44:16 +00:00
|
|
|
{
|
2013-11-28 14:07:55 +00:00
|
|
|
MOZ_ASSERT(aWindow->IsInnerWindow(), "Navigator must get an inner window!");
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Navigator::~Navigator()
|
|
|
|
{
|
2011-12-01 08:28:16 +00:00
|
|
|
Invalidate();
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 18:34:38 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Navigator)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2011-11-02 13:44:16 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNavigator)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigator)
|
2013-07-18 03:23:52 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMozNavigatorNetwork)
|
2011-11-02 13:44:16 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-06-20 18:34:38 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Navigator)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Navigator)
|
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Navigator)
|
|
|
|
|
2013-06-28 18:06:39 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Navigator)
|
|
|
|
tmp->Invalidate();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
|
2014-03-21 03:19:43 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCachedResolveResults)
|
2013-06-28 18:06:39 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
|
2013-07-09 13:58:21 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPlugins)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMimeTypes)
|
2013-06-28 18:06:39 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGeolocation)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNotification)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBatteryManager)
|
2013-07-18 16:07:28 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPowerManager)
|
2014-08-25 09:24:03 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCellBroadcast)
|
2013-06-28 18:06:39 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMobileMessageManager)
|
2013-10-29 08:12:38 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTelephony)
|
2014-09-26 05:00:23 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVoicemail)
|
2013-06-28 18:06:39 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConnection)
|
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-11-13 08:51:23 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMobileConnections)
|
2013-06-28 18:06:39 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIccManager)
|
|
|
|
#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)
|
2013-11-19 23:14:07 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mServiceWorkerContainer)
|
2013-06-28 18:06:39 +00:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
2014-03-21 03:19:43 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCachedResolveResults)
|
2013-06-28 18:06:39 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(Navigator)
|
2011-11-02 13:44:16 +00:00
|
|
|
|
|
|
|
void
|
2011-12-01 08:28:16 +00:00
|
|
|
Navigator::Invalidate()
|
2011-11-02 13:44:16 +00:00
|
|
|
{
|
2013-06-20 18:34:38 +00:00
|
|
|
// Don't clear mWindow here so we know we've got a non-null mWindow
|
|
|
|
// until we're unlinked.
|
2011-11-02 13:44:16 +00:00
|
|
|
|
|
|
|
if (mPlugins) {
|
2011-12-01 08:28:16 +00:00
|
|
|
mPlugins->Invalidate();
|
2012-07-30 14:20:58 +00:00
|
|
|
mPlugins = nullptr;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-09 13:58:21 +00:00
|
|
|
mMimeTypes = nullptr;
|
|
|
|
|
2011-11-02 13:44:16 +00:00
|
|
|
// If there is a page transition, make sure delete the geolocation object.
|
|
|
|
if (mGeolocation) {
|
|
|
|
mGeolocation->Shutdown();
|
2012-07-30 14:20:58 +00:00
|
|
|
mGeolocation = nullptr;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mNotification) {
|
|
|
|
mNotification->Shutdown();
|
2012-07-30 14:20:58 +00:00
|
|
|
mNotification = nullptr;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
2011-11-02 15:27:06 +00:00
|
|
|
|
|
|
|
if (mBatteryManager) {
|
|
|
|
mBatteryManager->Shutdown();
|
2012-07-30 14:20:58 +00:00
|
|
|
mBatteryManager = nullptr;
|
2011-11-02 15:27:06 +00:00
|
|
|
}
|
2011-11-20 22:23:20 +00:00
|
|
|
|
2013-09-03 22:26:33 +00:00
|
|
|
#ifdef MOZ_B2G_FM
|
|
|
|
if (mFMRadio) {
|
|
|
|
mFMRadio->Shutdown();
|
|
|
|
mFMRadio = nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-03-07 11:03:25 +00:00
|
|
|
if (mPowerManager) {
|
|
|
|
mPowerManager->Shutdown();
|
2012-07-30 14:20:58 +00:00
|
|
|
mPowerManager = nullptr;
|
2012-03-07 11:03:25 +00:00
|
|
|
}
|
2012-01-20 03:24:00 +00:00
|
|
|
|
2014-08-25 09:24:03 +00:00
|
|
|
if (mCellBroadcast) {
|
|
|
|
mCellBroadcast = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-03-09 07:21:47 +00:00
|
|
|
if (mMobileMessageManager) {
|
|
|
|
mMobileMessageManager->Shutdown();
|
|
|
|
mMobileMessageManager = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-10-29 08:12:38 +00:00
|
|
|
if (mTelephony) {
|
|
|
|
mTelephony = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-09-26 05:00:23 +00:00
|
|
|
if (mVoicemail) {
|
2014-09-26 05:00:24 +00:00
|
|
|
mVoicemail->Shutdown();
|
2014-09-26 05:00:23 +00:00
|
|
|
mVoicemail = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-01-16 17:14:56 +00:00
|
|
|
if (mConnection) {
|
|
|
|
mConnection->Shutdown();
|
2012-07-30 14:20:58 +00:00
|
|
|
mConnection = nullptr;
|
2012-01-16 17:14:56 +00:00
|
|
|
}
|
2012-02-20 15:15:19 +00:00
|
|
|
|
2012-08-27 17:34:10 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-11-13 08:51:23 +00:00
|
|
|
if (mMobileConnections) {
|
|
|
|
mMobileConnections = nullptr;
|
2012-04-19 21:33:25 +00:00
|
|
|
}
|
2012-12-04 02:38:25 +00:00
|
|
|
|
2013-04-08 10:34:10 +00:00
|
|
|
if (mIccManager) {
|
|
|
|
mIccManager->Shutdown();
|
|
|
|
mIccManager = nullptr;
|
|
|
|
}
|
2012-08-27 17:34:10 +00:00
|
|
|
#endif
|
2012-04-19 21:33:25 +00:00
|
|
|
|
2012-02-20 15:15:19 +00:00
|
|
|
#ifdef MOZ_B2G_BT
|
|
|
|
if (mBluetooth) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mBluetooth = nullptr;
|
2012-02-20 15:15:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
2012-07-03 00:16:55 +00:00
|
|
|
|
2012-07-30 21:59:05 +00:00
|
|
|
mCameraManager = nullptr;
|
|
|
|
|
2012-07-03 00:16:55 +00:00
|
|
|
if (mMessagesManager) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mMessagesManager = nullptr;
|
2012-07-03 00:16:55 +00:00
|
|
|
}
|
|
|
|
|
2012-11-29 22:52:03 +00:00
|
|
|
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
|
|
|
if (mAudioChannelManager) {
|
|
|
|
mAudioChannelManager = nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t len = mDeviceStorageStores.Length();
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2012-08-02 06:29:34 +00:00
|
|
|
mDeviceStorageStores[i]->Shutdown();
|
|
|
|
}
|
|
|
|
mDeviceStorageStores.Clear();
|
|
|
|
|
2012-09-11 06:05:00 +00:00
|
|
|
if (mTimeManager) {
|
|
|
|
mTimeManager = nullptr;
|
|
|
|
}
|
2013-11-19 23:14:07 +00:00
|
|
|
|
|
|
|
mServiceWorkerContainer = nullptr;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigator
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetUserAgent(nsAString& aUserAgent)
|
|
|
|
{
|
2014-09-24 10:40:43 +00:00
|
|
|
nsCOMPtr<nsIURI> codebaseURI;
|
2014-09-24 16:09:50 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window;
|
2014-09-24 10:40:43 +00:00
|
|
|
|
2014-09-24 16:09:50 +00:00
|
|
|
if (mWindow && mWindow->GetDocShell()) {
|
|
|
|
window = mWindow;
|
|
|
|
nsIDocument* doc = mWindow->GetExtantDoc();
|
|
|
|
if (doc) {
|
|
|
|
doc->NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
|
|
|
|
}
|
|
|
|
}
|
2014-09-24 10:40:43 +00:00
|
|
|
|
2014-09-24 16:09:50 +00:00
|
|
|
return GetUserAgent(window, codebaseURI, nsContentUtils::IsCallerChrome(),
|
|
|
|
aUserAgent);
|
2011-11-02 13:44:16 +00: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 02:35:17 +00:00
|
|
|
nsAutoCString appName;
|
2011-11-02 13:44:16 +00:00
|
|
|
rv = service->GetAppName(appName);
|
|
|
|
CopyASCIItoUTF16(appName, aAppCodeName);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetAppVersion(nsAString& aAppVersion)
|
|
|
|
{
|
2014-09-23 19:11:18 +00:00
|
|
|
return GetAppVersion(aAppVersion, /* aUsePrefOverriddenValue */ true);
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetAppName(nsAString& aAppName)
|
|
|
|
{
|
2014-09-23 19:11:18 +00:00
|
|
|
AppName(aAppName, /* aUsePrefOverriddenValue */ true);
|
2013-07-12 14:35:35 +00:00
|
|
|
return NS_OK;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-12 11:48:15 +00:00
|
|
|
* Returns the value of Accept-Languages (HTTP header) as a nsTArray of
|
|
|
|
* languages. The value is set in the preference by the user ("Content
|
|
|
|
* Languages").
|
2011-11-02 13:44:16 +00:00
|
|
|
*
|
2014-05-12 11:48:15 +00:00
|
|
|
* "en", "en-US" and "i-cherokee" and "" are valid languages tokens.
|
2011-11-02 13:44:16 +00:00
|
|
|
*
|
2014-05-12 11:48:15 +00:00
|
|
|
* An empty array will be returned if there is no valid languages.
|
2011-11-02 13:44:16 +00:00
|
|
|
*/
|
2014-09-05 14:26:34 +00:00
|
|
|
/* static */ void
|
2014-05-12 11:48:15 +00:00
|
|
|
Navigator::GetAcceptLanguages(nsTArray<nsString>& aLanguages)
|
2011-11-02 13:44:16 +00:00
|
|
|
{
|
2014-09-05 14:26:34 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2014-10-08 12:56:50 +00:00
|
|
|
aLanguages.Clear();
|
|
|
|
|
2011-11-02 13:44:16 +00:00
|
|
|
// E.g. "de-de, en-us,en".
|
|
|
|
const nsAdoptingString& acceptLang =
|
|
|
|
Preferences::GetLocalizedString("intl.accept_languages");
|
|
|
|
|
2014-05-12 11:48:15 +00:00
|
|
|
// Split values on commas.
|
2011-11-02 13:44:16 +00:00
|
|
|
nsCharSeparatedTokenizer langTokenizer(acceptLang, ',');
|
2014-05-12 11:48:15 +00:00
|
|
|
while (langTokenizer.hasMoreTokens()) {
|
|
|
|
nsDependentSubstring lang = langTokenizer.nextToken();
|
2011-11-02 13:44:16 +00:00
|
|
|
|
2014-05-12 11:48:15 +00:00
|
|
|
// Replace "_" with "-" to avoid POSIX/Windows "en_US" notation.
|
|
|
|
// NOTE: we should probably rely on the pref being set correctly.
|
|
|
|
if (lang.Length() > 2 && lang[2] == char16_t('_')) {
|
|
|
|
lang.Replace(2, 1, char16_t('-'));
|
|
|
|
}
|
2011-11-02 13:44:16 +00:00
|
|
|
|
2014-05-12 11:48:15 +00: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".
|
|
|
|
// NOTE: we should probably rely on the pref being set correctly.
|
|
|
|
if (lang.Length() > 2) {
|
|
|
|
nsCharSeparatedTokenizer localeTokenizer(lang, '-');
|
|
|
|
int32_t pos = 0;
|
|
|
|
bool first = true;
|
|
|
|
while (localeTokenizer.hasMoreTokens()) {
|
|
|
|
const nsSubstring& code = localeTokenizer.nextToken();
|
|
|
|
|
|
|
|
if (code.Length() == 2 && !first) {
|
|
|
|
nsAutoString upper(code);
|
|
|
|
ToUpperCase(upper);
|
|
|
|
lang.Replace(pos, code.Length(), upper);
|
|
|
|
}
|
|
|
|
|
|
|
|
pos += code.Length() + 1; // 1 is the separator
|
|
|
|
first = false;
|
|
|
|
}
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 11:48:15 +00:00
|
|
|
aLanguages.AppendElement(lang);
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
2014-05-12 11:48:15 +00:00
|
|
|
}
|
2011-11-02 13:44:16 +00:00
|
|
|
|
2014-05-12 11:48:15 +00:00
|
|
|
/**
|
|
|
|
* Do not use UI language (chosen app locale) here but the first value set in
|
|
|
|
* the Accept Languages header, see ::GetAcceptLanguages().
|
|
|
|
*
|
|
|
|
* See RFC 2616, Section 15.1.4 "Privacy Issues Connected to Accept Headers" for
|
|
|
|
* the reasons why.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetLanguage(nsAString& aLanguage)
|
|
|
|
{
|
|
|
|
nsTArray<nsString> languages;
|
|
|
|
GetLanguages(languages);
|
|
|
|
if (languages.Length() >= 1) {
|
|
|
|
aLanguage.Assign(languages[0]);
|
|
|
|
} else {
|
|
|
|
aLanguage.Truncate();
|
|
|
|
}
|
|
|
|
|
2014-09-05 14:26:34 +00:00
|
|
|
return NS_OK;
|
2014-05-12 11:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Navigator::GetLanguages(nsTArray<nsString>& aLanguages)
|
|
|
|
{
|
|
|
|
GetAcceptLanguages(aLanguages);
|
|
|
|
|
|
|
|
// The returned value is cached by the binding code. The window listen to the
|
|
|
|
// accept languages change and will clear the cache when needed. It has to
|
|
|
|
// take care of dispatching the DOM event already and the invalidation and the
|
|
|
|
// event has to be timed correctly.
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetPlatform(nsAString& aPlatform)
|
|
|
|
{
|
2014-09-23 19:11:18 +00:00
|
|
|
return GetPlatform(aPlatform, /* aUsePrefOverriddenValue */ true);
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetOscpu(nsAString& aOSCPU)
|
|
|
|
{
|
2012-10-25 23:10:53 +00:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2011-11-02 13:44:16 +00: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 02:35:17 +00:00
|
|
|
nsAutoCString oscpu;
|
2011-11-02 13:44:16 +00: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 12:09:59 +00:00
|
|
|
aProduct.AssignLiteral("Gecko");
|
|
|
|
return NS_OK;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetProductSub(nsAString& aProductSub)
|
|
|
|
{
|
2012-07-27 12:09:59 +00:00
|
|
|
// Legacy build ID hardcoded for backward compatibility (bug 776376)
|
|
|
|
aProductSub.AssignLiteral("20100101");
|
|
|
|
return NS_OK;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
nsMimeTypeArray*
|
|
|
|
Navigator::GetMimeTypes(ErrorResult& aRv)
|
2011-11-02 13:44:16 +00:00
|
|
|
{
|
|
|
|
if (!mMimeTypes) {
|
2013-07-12 14:35:35 +00:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-08-28 20:55:29 +00:00
|
|
|
mMimeTypes = new nsMimeTypeArray(mWindow);
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
return mMimeTypes;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
nsPluginArray*
|
|
|
|
Navigator::GetPlugins(ErrorResult& aRv)
|
2011-11-02 13:44:16 +00:00
|
|
|
{
|
|
|
|
if (!mPlugins) {
|
2013-07-12 14:35:35 +00:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-08-28 20:55:29 +00:00
|
|
|
mPlugins = new nsPluginArray(mWindow);
|
2013-04-10 20:59:45 +00:00
|
|
|
mPlugins->Init();
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
return mPlugins;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Values for the network.cookie.cookieBehavior pref are documented in
|
|
|
|
// nsCookieService.cpp.
|
|
|
|
#define COOKIE_BEHAVIOR_REJECT 2
|
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
bool
|
|
|
|
Navigator::CookieEnabled()
|
|
|
|
{
|
|
|
|
bool cookieEnabled =
|
2011-11-02 13:44:16 +00: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 18:34:38 +00:00
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
2013-07-12 14:35:35 +00:00
|
|
|
return cookieEnabled;
|
2011-12-01 08:28:16 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 18:34:38 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = mWindow->GetExtantDoc();
|
2011-11-02 13:44:16 +00:00
|
|
|
if (!doc) {
|
2013-07-12 14:35:35 +00:00
|
|
|
return cookieEnabled;
|
2011-11-02 13:44:16 +00: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 14:35:35 +00:00
|
|
|
return cookieEnabled;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsICookiePermission> permMgr =
|
|
|
|
do_GetService(NS_COOKIEPERMISSION_CONTRACTID);
|
2013-07-12 14:35:35 +00:00
|
|
|
NS_ENSURE_TRUE(permMgr, cookieEnabled);
|
2011-11-02 13:44:16 +00:00
|
|
|
|
|
|
|
// Pass null for the channel, just like the cookie service does.
|
|
|
|
nsCookieAccess access;
|
2012-07-30 14:20:58 +00:00
|
|
|
nsresult rv = permMgr->CanAccess(codebaseURI, nullptr, &access);
|
2013-07-12 14:35:35 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, cookieEnabled);
|
2011-11-02 13:44:16 +00:00
|
|
|
|
|
|
|
if (access != nsICookiePermission::ACCESS_DEFAULT) {
|
2013-07-12 14:35:35 +00:00
|
|
|
cookieEnabled = access != nsICookiePermission::ACCESS_DENY;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
return cookieEnabled;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
bool
|
|
|
|
Navigator::OnLine()
|
|
|
|
{
|
2014-08-23 03:06:56 +00:00
|
|
|
if (mWindow && mWindow->GetDoc()) {
|
2014-08-27 02:25:47 +00:00
|
|
|
return !NS_IsOffline() &&
|
|
|
|
!NS_IsAppOffline(mWindow->GetDoc()->NodePrincipal());
|
2014-08-23 03:06:56 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
return !NS_IsOffline();
|
|
|
|
}
|
|
|
|
|
2011-11-02 13:44:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetBuildID(nsAString& aBuildID)
|
|
|
|
{
|
2012-10-25 23:10:53 +00:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2011-11-02 13:44:16 +00: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 02:35:17 +00:00
|
|
|
nsAutoCString buildID;
|
2011-11-02 13:44:16 +00: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) {
|
2014-10-22 06:11:11 +00:00
|
|
|
if (sDoNotTrackValue == 0) {
|
|
|
|
aResult.AssignLiteral("0");
|
|
|
|
} else {
|
|
|
|
aResult.AssignLiteral("1");
|
|
|
|
}
|
2011-11-02 13:44:16 +00:00
|
|
|
} else {
|
|
|
|
aResult.AssignLiteral("unspecified");
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
bool
|
|
|
|
Navigator::JavaEnabled(ErrorResult& aRv)
|
2011-11-02 13:44:16 +00:00
|
|
|
{
|
|
|
|
Telemetry::AutoTimer<Telemetry::CHECK_JAVA_ENABLED> telemetryTimer;
|
2014-02-10 23:50:53 +00: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 13:44:16 +00:00
|
|
|
if (!mMimeTypes) {
|
2013-07-12 14:35:35 +00:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return false;
|
|
|
|
}
|
2013-08-28 20:55:29 +00:00
|
|
|
mMimeTypes = new nsMimeTypeArray(mWindow);
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RefreshMIMEArray();
|
|
|
|
|
2014-02-10 23:50:53 +00:00
|
|
|
nsMimeType *mimeType = mMimeTypes->NamedItem(javaMIME);
|
2011-11-02 11:04:28 +00:00
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
return mimeType && mimeType->GetEnabledPlugin();
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Navigator::RefreshMIMEArray()
|
|
|
|
{
|
|
|
|
if (mMimeTypes) {
|
2011-12-01 08:28:16 +00:00
|
|
|
mMimeTypes->Refresh();
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-10 21:26:36 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class VibrateWindowListener : public nsIDOMEventListener
|
|
|
|
{
|
|
|
|
public:
|
2013-04-24 04:22:37 +00:00
|
|
|
VibrateWindowListener(nsIDOMWindow* aWindow, nsIDocument* aDocument)
|
2011-11-10 21:26:36 +00:00
|
|
|
{
|
|
|
|
mWindow = do_GetWeakReference(aWindow);
|
|
|
|
mDocument = do_GetWeakReference(aDocument);
|
|
|
|
|
2012-11-16 22:22:56 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(visibilitychange, "visibilitychange");
|
2013-04-24 04:22:37 +00:00
|
|
|
aDocument->AddSystemEventListener(visibilitychange,
|
|
|
|
this, /* listener */
|
|
|
|
true, /* use capture */
|
|
|
|
false /* wants untrusted */);
|
2011-11-10 21:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveListener();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
|
|
|
|
|
|
|
private:
|
2014-06-23 19:56:07 +00:00
|
|
|
virtual ~VibrateWindowListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-11-10 21:26:36 +00:00
|
|
|
nsWeakPtr mWindow;
|
|
|
|
nsWeakPtr mDocument;
|
|
|
|
};
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(VibrateWindowListener, nsIDOMEventListener)
|
2011-11-10 21:26:36 +00:00
|
|
|
|
2012-07-26 19:33:45 +00:00
|
|
|
StaticRefPtr<VibrateWindowListener> gVibrateWindowListener;
|
2011-11-10 21:26:36 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
VibrateWindowListener::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
2013-04-19 22:18:32 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc =
|
|
|
|
do_QueryInterface(aEvent->InternalDOMEvent()->GetTarget());
|
2011-11-10 21:26:36 +00:00
|
|
|
|
2013-04-19 22:18:32 +00:00
|
|
|
if (!doc || doc->Hidden()) {
|
2011-11-10 21:26:36 +00: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 14:04:12 +00:00
|
|
|
gVibrateWindowListener = nullptr;
|
2011-11-10 21:26:36 +00:00
|
|
|
// Careful: The line above might have deleted |this|!
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VibrateWindowListener::RemoveListener()
|
|
|
|
{
|
2013-04-19 22:18:32 +00:00
|
|
|
nsCOMPtr<EventTarget> target = do_QueryReferent(mDocument);
|
2011-11-10 21:26:36 +00:00
|
|
|
if (!target) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-16 22:22:56 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(visibilitychange, "visibilitychange");
|
2011-11-10 21:26:36 +00:00
|
|
|
target->RemoveSystemEventListener(visibilitychange, this,
|
|
|
|
true /* use capture */);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2013-07-12 14:35:35 +00: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 03:23:52 +00:00
|
|
|
if (NS_FAILED(mWindow->RegisterIdleObserver(obs))) {
|
|
|
|
NS_WARNING("Failed to add idle observer.");
|
2013-07-12 14:35:35 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-10 21:26:36 +00:00
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
void
|
|
|
|
Navigator::RemoveIdleObserver(MozIdleObserver& aIdleObserver, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
2011-11-10 21:26:36 +00:00
|
|
|
}
|
2013-07-12 14:35:35 +00:00
|
|
|
CallbackObjectHolder<MozIdleObserver, nsIIdleObserver> holder(&aIdleObserver);
|
|
|
|
nsCOMPtr<nsIIdleObserver> obs = holder.ToXPCOMCallback();
|
2013-07-18 03:23:52 +00:00
|
|
|
if (NS_FAILED(mWindow->UnregisterIdleObserver(obs))) {
|
|
|
|
NS_WARNING("Failed to remove idle observer.");
|
2011-11-10 21:26:36 +00:00
|
|
|
}
|
2013-07-12 14:35:35 +00:00
|
|
|
}
|
|
|
|
|
2013-09-28 18:58:38 +00:00
|
|
|
bool
|
|
|
|
Navigator::Vibrate(uint32_t aDuration)
|
2013-07-12 14:35:35 +00:00
|
|
|
{
|
|
|
|
nsAutoTArray<uint32_t, 1> pattern;
|
|
|
|
pattern.AppendElement(aDuration);
|
2013-09-28 18:58:38 +00:00
|
|
|
return Vibrate(pattern);
|
2013-07-12 14:35:35 +00:00
|
|
|
}
|
|
|
|
|
2013-09-28 18:58:38 +00:00
|
|
|
bool
|
|
|
|
Navigator::Vibrate(const nsTArray<uint32_t>& aPattern)
|
2013-07-12 14:35:35 +00:00
|
|
|
{
|
|
|
|
if (!mWindow) {
|
2013-09-28 18:58:38 +00:00
|
|
|
return false;
|
2013-07-12 14:35:35 +00:00
|
|
|
}
|
2013-09-28 18:58:38 +00:00
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = mWindow->GetExtantDoc();
|
|
|
|
if (!doc) {
|
2013-09-28 18:58:38 +00:00
|
|
|
return false;
|
2013-07-12 14:35:35 +00:00
|
|
|
}
|
2013-09-28 18:58:38 +00:00
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
if (doc->Hidden()) {
|
|
|
|
// Hidden documents cannot start or stop a vibration.
|
2013-09-28 18:58:38 +00:00
|
|
|
return false;
|
2013-07-12 14:35:35 +00:00
|
|
|
}
|
|
|
|
|
2014-05-27 20:54:03 +00:00
|
|
|
nsTArray<uint32_t> pattern(aPattern);
|
|
|
|
|
|
|
|
if (pattern.Length() > sMaxVibrateListLen) {
|
2014-06-07 12:40:20 +00:00
|
|
|
pattern.SetLength(sMaxVibrateListLen);
|
2013-07-12 14:35:35 +00:00
|
|
|
}
|
|
|
|
|
2014-05-27 20:54:03 +00:00
|
|
|
for (size_t i = 0; i < pattern.Length(); ++i) {
|
|
|
|
if (pattern[i] > sMaxVibrateMS) {
|
|
|
|
pattern[i] = sMaxVibrateMS;
|
2013-07-12 14:35:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-10 21:26:36 +00:00
|
|
|
// The spec says we check sVibratorEnabled after we've done the sanity
|
|
|
|
// checking on the pattern.
|
2014-07-10 14:31:36 +00:00
|
|
|
if (!sVibratorEnabled) {
|
2013-09-28 18:58:38 +00:00
|
|
|
return true;
|
2011-11-10 21:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add a listener to cancel the vibration if the document becomes hidden,
|
2012-11-16 22:22:56 +00:00
|
|
|
// and remove the old visibility listener, if there was one.
|
2011-11-10 21:26:36 +00: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 18:34:38 +00:00
|
|
|
gVibrateWindowListener = new VibrateWindowListener(mWindow, doc);
|
2011-11-10 21:26:36 +00:00
|
|
|
|
2014-05-27 20:54:03 +00:00
|
|
|
hal::Vibrate(pattern, mWindow);
|
2013-09-28 18:58:38 +00:00
|
|
|
return true;
|
2011-11-10 21:26:36 +00:00
|
|
|
}
|
|
|
|
|
2014-01-28 16:09:34 +00: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 13:44:16 +00:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMClientInformation
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2013-07-18 03:23:52 +00:00
|
|
|
void
|
2011-11-02 13:44:16 +00:00
|
|
|
Navigator::RegisterContentHandler(const nsAString& aMIMEType,
|
|
|
|
const nsAString& aURI,
|
2013-07-18 03:23:52 +00:00
|
|
|
const nsAString& aTitle,
|
|
|
|
ErrorResult& aRv)
|
2011-11-02 13:44:16 +00:00
|
|
|
{
|
2013-06-20 18:34:38 +00:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
2013-07-18 03:23:52 +00:00
|
|
|
return;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebContentHandlerRegistrar> registrar =
|
|
|
|
do_GetService(NS_WEBCONTENTHANDLERREGISTRAR_CONTRACTID);
|
|
|
|
if (!registrar) {
|
2013-07-18 03:23:52 +00:00
|
|
|
return;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 03:23:52 +00:00
|
|
|
aRv = registrar->RegisterContentHandler(aMIMEType, aURI, aTitle,
|
|
|
|
mWindow->GetOuterWindow());
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 03:23:52 +00:00
|
|
|
void
|
2011-11-02 13:44:16 +00:00
|
|
|
Navigator::RegisterProtocolHandler(const nsAString& aProtocol,
|
|
|
|
const nsAString& aURI,
|
2013-07-18 03:23:52 +00:00
|
|
|
const nsAString& aTitle,
|
|
|
|
ErrorResult& aRv)
|
2011-11-02 13:44:16 +00:00
|
|
|
{
|
2013-06-20 18:34:38 +00:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
2013-07-18 03:23:52 +00:00
|
|
|
return;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebContentHandlerRegistrar> registrar =
|
|
|
|
do_GetService(NS_WEBCONTENTHANDLERREGISTRAR_CONTRACTID);
|
|
|
|
if (!registrar) {
|
2013-07-18 03:23:52 +00:00
|
|
|
return;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 03:23:52 +00:00
|
|
|
aRv = registrar->RegisterProtocolHandler(aProtocol, aURI, aTitle,
|
|
|
|
mWindow->GetOuterWindow());
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:44 +00:00
|
|
|
nsDOMDeviceStorage*
|
|
|
|
Navigator::GetDeviceStorage(const nsAString& aType, ErrorResult& aRv)
|
|
|
|
{
|
2013-06-20 18:34:38 +00:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
2013-07-12 14:35:44 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2013-05-11 09:10:18 +00:00
|
|
|
}
|
2013-05-11 13:47:37 +00:00
|
|
|
|
2013-05-11 09:10:18 +00:00
|
|
|
nsRefPtr<nsDOMDeviceStorage> storage;
|
2013-06-20 18:34:38 +00:00
|
|
|
nsDOMDeviceStorage::CreateDeviceStorageFor(mWindow, aType,
|
|
|
|
getter_AddRefs(storage));
|
2013-05-11 13:47:37 +00:00
|
|
|
|
2013-05-11 09:10:18 +00:00
|
|
|
if (!storage) {
|
2013-07-12 14:35:44 +00:00
|
|
|
return nullptr;
|
2013-04-02 19:52:21 +00:00
|
|
|
}
|
|
|
|
|
2013-05-11 09:10:18 +00:00
|
|
|
mDeviceStorageStores.AppendElement(storage);
|
2013-07-12 14:35:44 +00:00
|
|
|
return storage;
|
2013-04-02 19:52:21 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:44 +00: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-02 23:34:59 +00:00
|
|
|
nsDOMDeviceStorage::CreateDeviceStoragesFor(mWindow, aType, aStores);
|
2013-07-12 14:35:44 +00:00
|
|
|
|
|
|
|
mDeviceStorageStores.AppendElements(aStores);
|
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
Geolocation*
|
|
|
|
Navigator::GetGeolocation(ErrorResult& aRv)
|
|
|
|
{
|
2011-11-02 13:44:16 +00:00
|
|
|
if (mGeolocation) {
|
2013-07-12 14:35:35 +00:00
|
|
|
return mGeolocation;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 18:34:38 +00:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
2013-07-12 14:35:35 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-04-12 18:47:47 +00:00
|
|
|
mGeolocation = new Geolocation();
|
2013-06-20 18:34:38 +00:00
|
|
|
if (NS_FAILED(mGeolocation->Init(mWindow->GetOuterWindow()))) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mGeolocation = nullptr;
|
2013-07-12 14:35:35 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
return mGeolocation;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 15:51:23 +00:00
|
|
|
class BeaconStreamListener MOZ_FINAL : public nsIStreamListener
|
|
|
|
{
|
2014-06-23 19:56:07 +00:00
|
|
|
~BeaconStreamListener() {}
|
|
|
|
|
2014-03-06 15:51:23 +00:00
|
|
|
public:
|
|
|
|
BeaconStreamListener() {}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
};
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(BeaconStreamListener,
|
|
|
|
nsIStreamListener,
|
|
|
|
nsIRequestObserver)
|
2014-03-06 15:51:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
rv = NS_NewChannel(getter_AddRefs(channel),
|
|
|
|
uri,
|
2014-09-22 11:49:12 +00:00
|
|
|
doc,
|
|
|
|
nsILoadInfo::SEC_NORMAL,
|
2014-10-16 02:11:45 +00:00
|
|
|
nsIContentPolicy::TYPE_BEACON);
|
2014-09-22 11:49:12 +00:00
|
|
|
|
2014-03-06 15:51:23 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-26 04:15:14 +00:00
|
|
|
nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(channel);
|
|
|
|
if (pbChannel) {
|
|
|
|
nsIDocShell* docShell = mWindow->GetDocShell();
|
|
|
|
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(docShell);
|
|
|
|
if (loadContext) {
|
|
|
|
rv = pbChannel->SetPrivate(loadContext->UsePrivateBrowsing());
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Setting the privacy status on the beacon channel failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-06 15:51:23 +00:00
|
|
|
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;
|
2014-04-16 07:30:26 +00:00
|
|
|
|
2014-03-06 15:51:23 +00:00
|
|
|
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;
|
2014-04-16 07:30:26 +00:00
|
|
|
|
2014-03-06 15:51:23 +00:00
|
|
|
} else if (aData.Value().IsArrayBufferView()) {
|
2014-04-16 07:30:26 +00:00
|
|
|
|
2014-03-06 15:51:23 +00:00
|
|
|
nsCOMPtr<nsIStringInputStream> strStream = do_CreateInstance(NS_STRINGINPUTSTREAM_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-16 07:30:26 +00:00
|
|
|
|
2014-06-23 20:03:57 +00:00
|
|
|
const ArrayBufferView& view = aData.Value().GetAsArrayBufferView();
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-27 21:32:41 +00:00
|
|
|
view.ComputeLengthAndData();
|
|
|
|
rv = strStream->SetData(reinterpret_cast<char*>(view.Data()),
|
|
|
|
view.Length());
|
2014-04-16 07:30:26 +00:00
|
|
|
|
2014-03-06 15:51:23 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mimeType.AssignLiteral("application/octet-stream");
|
|
|
|
in = strStream;
|
2014-04-16 07:30:26 +00:00
|
|
|
|
2014-03-06 15:51:23 +00:00
|
|
|
} else if (aData.Value().IsBlob()) {
|
2014-10-08 16:15:23 +00:00
|
|
|
File& blob = aData.Value().GetAsBlob();
|
2014-10-08 16:15:22 +00:00
|
|
|
rv = blob.GetInternalStream(getter_AddRefs(in));
|
2014-03-06 15:51:23 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsAutoString type;
|
2014-10-08 16:15:22 +00:00
|
|
|
rv = blob.GetType(type);
|
2014-03-06 15:51:23 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mimeType = NS_ConvertUTF16toUTF8(type);
|
2014-04-16 07:30:26 +00:00
|
|
|
|
2014-03-06 15:51:23 +00:00
|
|
|
} 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;
|
|
|
|
}
|
2014-04-16 07:30:26 +00:00
|
|
|
|
2014-03-06 15:51:23 +00:00
|
|
|
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);
|
2014-04-16 07:30:26 +00:00
|
|
|
if (crossOrigin &&
|
2014-03-06 15:51:23 +00:00
|
|
|
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 07:35:15 +00:00
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
2013-07-12 14:37:21 +00:00
|
|
|
void
|
2014-04-18 18:00:16 +00:00
|
|
|
Navigator::MozGetUserMedia(const MediaStreamConstraints& aConstraints,
|
2013-09-16 06:34:57 +00:00
|
|
|
NavigatorUserMediaSuccessCallback& aOnSuccess,
|
|
|
|
NavigatorUserMediaErrorCallback& aOnError,
|
2013-07-12 14:37:21 +00:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2013-09-16 06:34:57 +00:00
|
|
|
CallbackObjectHolder<NavigatorUserMediaSuccessCallback,
|
|
|
|
nsIDOMGetUserMediaSuccessCallback> holder1(&aOnSuccess);
|
2013-07-18 03:23:52 +00:00
|
|
|
nsCOMPtr<nsIDOMGetUserMediaSuccessCallback> onsuccess =
|
2013-07-12 14:37:21 +00:00
|
|
|
holder1.ToXPCOMCallback();
|
|
|
|
|
2013-09-16 06:34:57 +00:00
|
|
|
CallbackObjectHolder<NavigatorUserMediaErrorCallback,
|
|
|
|
nsIDOMGetUserMediaErrorCallback> holder2(&aOnError);
|
2013-07-12 14:37:21 +00:00
|
|
|
nsCOMPtr<nsIDOMGetUserMediaErrorCallback> onerror = holder2.ToXPCOMCallback();
|
|
|
|
|
2013-06-20 18:34:38 +00:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() ||
|
|
|
|
mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) {
|
2013-07-12 14:37:21 +00:00
|
|
|
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return;
|
2012-09-20 19:54:00 +00:00
|
|
|
}
|
2012-06-03 07:35:15 +00:00
|
|
|
|
2012-09-20 19:54:00 +00:00
|
|
|
MediaManager* manager = MediaManager::Get();
|
2014-09-30 23:17:53 +00:00
|
|
|
aRv = manager->GetUserMedia(mWindow, aConstraints, onsuccess, onerror);
|
2013-07-12 14:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-18 18:00:16 +00:00
|
|
|
Navigator::MozGetUserMediaDevices(const MediaStreamConstraints& aConstraints,
|
2013-09-16 06:34:57 +00:00
|
|
|
MozGetUserMediaDevicesSuccessCallback& aOnSuccess,
|
|
|
|
NavigatorUserMediaErrorCallback& aOnError,
|
2014-02-14 19:32:58 +00:00
|
|
|
uint64_t aInnerWindowID,
|
2013-07-12 14:37:21 +00:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
CallbackObjectHolder<MozGetUserMediaDevicesSuccessCallback,
|
2013-09-16 06:34:57 +00:00
|
|
|
nsIGetUserMediaDevicesSuccessCallback> holder1(&aOnSuccess);
|
2013-07-18 03:23:52 +00:00
|
|
|
nsCOMPtr<nsIGetUserMediaDevicesSuccessCallback> onsuccess =
|
2013-07-12 14:37:21 +00:00
|
|
|
holder1.ToXPCOMCallback();
|
|
|
|
|
2013-09-16 06:34:57 +00:00
|
|
|
CallbackObjectHolder<NavigatorUserMediaErrorCallback,
|
|
|
|
nsIDOMGetUserMediaErrorCallback> holder2(&aOnError);
|
2013-07-12 14:37:21 +00:00
|
|
|
nsCOMPtr<nsIDOMGetUserMediaErrorCallback> onerror = holder2.ToXPCOMCallback();
|
|
|
|
|
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() ||
|
|
|
|
mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-20 19:54:00 +00:00
|
|
|
MediaManager* manager = MediaManager::Get();
|
2014-02-14 19:32:58 +00:00
|
|
|
aRv = manager->GetUserMediaDevices(mWindow, aConstraints, onsuccess, onerror,
|
|
|
|
aInnerWindowID);
|
2012-06-03 07:35:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-12 14:35:44 +00:00
|
|
|
DesktopNotificationCenter*
|
|
|
|
Navigator::GetMozNotification(ErrorResult& aRv)
|
|
|
|
{
|
2011-11-02 13:44:16 +00:00
|
|
|
if (mNotification) {
|
2013-07-12 14:35:44 +00:00
|
|
|
return mNotification;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:44 +00:00
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-11-02 13:44:16 +00:00
|
|
|
|
2013-06-20 18:34:38 +00:00
|
|
|
mNotification = new DesktopNotificationCenter(mWindow);
|
2013-07-12 14:35:44 +00:00
|
|
|
return mNotification;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-03 22:26:33 +00: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 14:35:35 +00: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 10:37:21 +00:00
|
|
|
|
2014-01-07 02:53:23 +00:00
|
|
|
mBatteryManager = new battery::BatteryManager(mWindow);
|
|
|
|
mBatteryManager->Init();
|
2011-11-02 15:01:32 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
return mBatteryManager;
|
2011-11-02 12:04:39 +00:00
|
|
|
}
|
|
|
|
|
2014-02-24 13:57:15 +00:00
|
|
|
/* static */ already_AddRefed<Promise>
|
|
|
|
Navigator::GetDataStores(nsPIDOMWindow* aWindow,
|
|
|
|
const nsAString& aName,
|
2014-07-17 03:53:23 +00:00
|
|
|
const nsAString& aOwner,
|
2014-02-24 13:57:15 +00:00
|
|
|
ErrorResult& aRv)
|
2013-10-02 17:27:07 +00:00
|
|
|
{
|
2014-02-24 13:57:15 +00:00
|
|
|
if (!aWindow || !aWindow->GetDocShell()) {
|
2013-10-02 17:27:07 +00:00
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-03 14:36:46 +00:00
|
|
|
nsRefPtr<DataStoreService> service = DataStoreService::GetOrCreate();
|
2013-10-02 17:27:07 +00:00
|
|
|
if (!service) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> promise;
|
2014-07-17 03:53:23 +00:00
|
|
|
aRv = service->GetDataStores(aWindow, aName, aOwner, getter_AddRefs(promise));
|
2013-10-02 17:27:07 +00:00
|
|
|
|
|
|
|
nsRefPtr<Promise> p = static_cast<Promise*>(promise.get());
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
2014-02-24 13:57:15 +00:00
|
|
|
already_AddRefed<Promise>
|
2014-07-17 03:53:23 +00:00
|
|
|
Navigator::GetDataStores(const nsAString& aName,
|
|
|
|
const nsAString& aOwner,
|
|
|
|
ErrorResult& aRv)
|
2014-02-24 13:57:15 +00:00
|
|
|
{
|
2014-07-17 03:53:23 +00:00
|
|
|
return GetDataStores(mWindow, aName, aOwner, aRv);
|
2014-02-24 13:57:15 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 02:05:03 +00:00
|
|
|
already_AddRefed<Promise>
|
2014-07-19 01:31:11 +00:00
|
|
|
Navigator::GetFeature(const nsAString& aName, ErrorResult& aRv)
|
2014-05-12 02:05:03 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(mWindow);
|
2014-07-19 01:31:11 +00:00
|
|
|
nsRefPtr<Promise> p = Promise::Create(go, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-05-12 02:05:03 +00:00
|
|
|
|
|
|
|
#if defined(XP_LINUX)
|
|
|
|
if (aName.EqualsLiteral("hardware.memory")) {
|
2014-05-21 05:49:36 +00:00
|
|
|
// with seccomp enabled, fopen() should be in a non-sandboxed process
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
|
|
|
uint32_t memLevel = mozilla::hal::GetTotalSystemMemoryLevel();
|
|
|
|
if (memLevel == 0) {
|
2014-06-03 15:38:38 +00:00
|
|
|
p->MaybeReject(NS_ERROR_NOT_AVAILABLE);
|
2014-05-12 02:05:03 +00:00
|
|
|
return p.forget();
|
|
|
|
}
|
2014-05-21 05:49:36 +00:00
|
|
|
p->MaybeResolve((int)memLevel);
|
|
|
|
} else {
|
|
|
|
mozilla::dom::ContentChild* cc =
|
|
|
|
mozilla::dom::ContentChild::GetSingleton();
|
|
|
|
nsRefPtr<Promise> ipcRef(p);
|
|
|
|
cc->SendGetSystemMemory(reinterpret_cast<uint64_t>(ipcRef.forget().take()));
|
2014-05-12 02:05:03 +00:00
|
|
|
}
|
2014-05-21 05:49:36 +00:00
|
|
|
return p.forget();
|
2014-05-12 02:05:03 +00:00
|
|
|
} // hardware.memory
|
|
|
|
#endif
|
2014-07-09 21:05:29 +00:00
|
|
|
|
|
|
|
// Hardcoded manifest features. Some are still b2g specific.
|
|
|
|
const char manifestFeatures[][64] = {
|
|
|
|
"manifest.origin"
|
|
|
|
, "manifest.redirects"
|
|
|
|
#ifdef MOZ_B2G
|
|
|
|
, "manifest.chrome.navigation"
|
|
|
|
, "manifest.precompile"
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
nsAutoCString feature = NS_ConvertUTF16toUTF8(aName);
|
|
|
|
for (uint32_t i = 0; i < MOZ_ARRAY_LENGTH(manifestFeatures); i++) {
|
|
|
|
if (feature.Equals(manifestFeatures[i])) {
|
|
|
|
p->MaybeResolve(true);
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-24 19:57:02 +00:00
|
|
|
p->MaybeResolve(JS::UndefinedHandleValue);
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
Navigator::HasFeature(const nsAString& aName, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(mWindow);
|
|
|
|
nsRefPtr<Promise> p = Promise::Create(go, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-14 23:08:45 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(apiWindowPrefix, "api.window.");
|
|
|
|
if (StringBeginsWith(aName, apiWindowPrefix)) {
|
2014-07-15 19:15:28 +00:00
|
|
|
const nsAString& featureName = Substring(aName, apiWindowPrefix.Length());
|
2014-07-24 19:57:02 +00:00
|
|
|
|
|
|
|
// Temporary hardcoded entry points due to technical constraints
|
|
|
|
if (featureName.EqualsLiteral("Navigator.mozTCPSocket")) {
|
|
|
|
p->MaybeResolve(Preferences::GetBool("dom.mozTCPSocket.enabled"));
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (featureName.EqualsLiteral("Navigator.mozMobileConnections") ||
|
|
|
|
featureName.EqualsLiteral("MozMobileNetworkInfo")) {
|
|
|
|
p->MaybeResolve(Preferences::GetBool("dom.mobileconnection.enabled"));
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (featureName.EqualsLiteral("Navigator.mozInputMethod")) {
|
|
|
|
p->MaybeResolve(Preferences::GetBool("dom.mozInputMethod.enabled"));
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (featureName.EqualsLiteral("Navigator.mozContacts")) {
|
|
|
|
p->MaybeResolve(true);
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (featureName.EqualsLiteral("Navigator.getDeviceStorage")) {
|
|
|
|
p->MaybeResolve(Preferences::GetBool("device.storage.enabled"));
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (featureName.EqualsLiteral("Navigator.mozNetworkStats")) {
|
|
|
|
p->MaybeResolve(Preferences::GetBool("dom.mozNetworkStats.enabled"));
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (featureName.EqualsLiteral("Navigator.push")) {
|
|
|
|
p->MaybeResolve(Preferences::GetBool("services.push.enabled"));
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (featureName.EqualsLiteral("Navigator.mozAlarms")) {
|
|
|
|
p->MaybeResolve(Preferences::GetBool("dom.mozAlarms.enabled"));
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (featureName.EqualsLiteral("Navigator.mozCameras")) {
|
|
|
|
p->MaybeResolve(true);
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_B2G
|
|
|
|
if (featureName.EqualsLiteral("Navigator.getMobileIdAssertion")) {
|
|
|
|
p->MaybeResolve(true);
|
|
|
|
return p.forget();
|
|
|
|
}
|
2014-08-25 09:24:03 +00:00
|
|
|
#endif
|
2014-07-24 19:57:02 +00:00
|
|
|
|
|
|
|
if (featureName.EqualsLiteral("XMLHttpRequest.mozSystem")) {
|
|
|
|
p->MaybeResolve(true);
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
2014-07-14 23:08:45 +00:00
|
|
|
if (IsFeatureDetectible(featureName)) {
|
|
|
|
p->MaybeResolve(true);
|
|
|
|
} else {
|
|
|
|
p->MaybeResolve(JS::UndefinedHandleValue);
|
|
|
|
}
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
2014-05-21 05:49:36 +00:00
|
|
|
// resolve with <undefined> because the feature name is not supported
|
|
|
|
p->MaybeResolve(JS::UndefinedHandleValue);
|
2014-05-12 02:05:03 +00:00
|
|
|
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
2013-09-11 14:35:04 +00:00
|
|
|
PowerManager*
|
2013-07-12 14:35:35 +00:00
|
|
|
Navigator::GetMozPower(ErrorResult& aRv)
|
|
|
|
{
|
2012-01-20 03:24:00 +00:00
|
|
|
if (!mPowerManager) {
|
2013-07-12 14:35:35 +00: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 03:24:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
return mPowerManager;
|
2012-01-20 03:24:00 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 12:16:07 +00:00
|
|
|
already_AddRefed<WakeLock>
|
2013-07-12 14:35:35 +00:00
|
|
|
Navigator::RequestWakeLock(const nsAString &aTopic, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-03-07 11:03:25 +00:00
|
|
|
|
2014-01-07 12:16:07 +00:00
|
|
|
nsRefPtr<power::PowerManagerService> pmService =
|
|
|
|
power::PowerManagerService::GetInstance();
|
2013-07-12 14:35:35 +00:00
|
|
|
// Maybe it went away for some reason... Or maybe we're just called
|
|
|
|
// from our XPCOM method.
|
2014-01-24 09:40:40 +00:00
|
|
|
if (!pmService) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-03-07 11:03:25 +00:00
|
|
|
|
2014-01-24 09:40:40 +00:00
|
|
|
return pmService->NewWakeLock(aTopic, mWindow, aRv);
|
2012-03-07 11:03:25 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 03:57:16 +00:00
|
|
|
MobileMessageManager*
|
2013-07-12 14:35:44 +00:00
|
|
|
Navigator::GetMozMobileMessage()
|
|
|
|
{
|
2013-03-09 07:21:47 +00:00
|
|
|
if (!mMobileMessageManager) {
|
2013-07-12 14:35:44 +00:00
|
|
|
// Check that our window has not gone away
|
|
|
|
NS_ENSURE_TRUE(mWindow, nullptr);
|
|
|
|
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
2013-03-09 07:21:47 +00:00
|
|
|
|
2014-06-25 03:57:16 +00:00
|
|
|
mMobileMessageManager = new MobileMessageManager(mWindow);
|
|
|
|
mMobileMessageManager->Init();
|
2013-03-09 07:21:47 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:44 +00:00
|
|
|
return mMobileMessageManager;
|
2013-03-09 07:21:47 +00:00
|
|
|
}
|
|
|
|
|
2013-10-29 08:12:38 +00:00
|
|
|
Telephony*
|
|
|
|
Navigator::GetMozTelephony(ErrorResult& aRv)
|
2013-07-12 14:36:22 +00:00
|
|
|
{
|
2013-10-29 08:12:38 +00:00
|
|
|
if (!mTelephony) {
|
2013-07-12 14:36:22 +00:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
2012-12-04 02:38:25 +00:00
|
|
|
}
|
2013-10-29 08:12:38 +00:00
|
|
|
mTelephony = Telephony::Create(mWindow, aRv);
|
2012-12-04 02:38:25 +00:00
|
|
|
}
|
|
|
|
|
2013-10-29 08:12:38 +00:00
|
|
|
return mTelephony;
|
2012-12-04 02:38:25 +00:00
|
|
|
}
|
|
|
|
|
2014-06-07 17:30:18 +00:00
|
|
|
#ifdef MOZ_B2G
|
|
|
|
already_AddRefed<Promise>
|
2014-06-26 23:18:21 +00:00
|
|
|
Navigator::GetMobileIdAssertion(const MobileIdOptions& aOptions,
|
|
|
|
ErrorResult& aRv)
|
2014-06-07 17:30:18 +00:00
|
|
|
{
|
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMobileIdentityService> service =
|
|
|
|
do_GetService("@mozilla.org/mobileidentity-service;1");
|
|
|
|
if (!service) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-26 23:18:21 +00:00
|
|
|
JSContext *cx = nsContentUtils::GetCurrentJSContext();
|
|
|
|
if (!cx) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> optionsValue(cx);
|
|
|
|
if (!ToJSValue(cx, aOptions, &optionsValue)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-07 17:30:18 +00:00
|
|
|
nsCOMPtr<nsISupports> promise;
|
2014-06-26 23:18:21 +00:00
|
|
|
aRv = service->GetMobileIdAssertion(mWindow,
|
|
|
|
optionsValue,
|
|
|
|
getter_AddRefs(promise));
|
2014-06-07 17:30:18 +00:00
|
|
|
|
|
|
|
nsRefPtr<Promise> p = static_cast<Promise*>(promise.get());
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
#endif // MOZ_B2G
|
|
|
|
|
2013-10-29 08:12:38 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
|
|
|
|
2014-01-02 03:06:17 +00:00
|
|
|
MobileConnectionArray*
|
2013-11-13 08:51:23 +00:00
|
|
|
Navigator::GetMozMobileConnections(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mMobileConnections) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-01-02 03:06:17 +00:00
|
|
|
mMobileConnections = new MobileConnectionArray(mWindow);
|
2013-11-13 08:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return mMobileConnections;
|
|
|
|
}
|
|
|
|
|
2014-08-25 09:24:03 +00:00
|
|
|
#endif // MOZ_B2G_RIL
|
|
|
|
|
2013-10-29 08:12:38 +00:00
|
|
|
CellBroadcast*
|
|
|
|
Navigator::GetMozCellBroadcast(ErrorResult& aRv)
|
2013-07-12 14:36:13 +00:00
|
|
|
{
|
2013-10-29 08:12:38 +00:00
|
|
|
if (!mCellBroadcast) {
|
2013-07-12 14:36:13 +00:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-10-29 08:12:38 +00:00
|
|
|
mCellBroadcast = CellBroadcast::Create(mWindow, aRv);
|
2012-01-09 22:28:47 +00:00
|
|
|
}
|
|
|
|
|
2013-10-29 08:12:38 +00:00
|
|
|
return mCellBroadcast;
|
2012-01-09 22:28:47 +00:00
|
|
|
}
|
|
|
|
|
2013-09-03 14:38:53 +00:00
|
|
|
Voicemail*
|
2013-07-12 14:36:22 +00:00
|
|
|
Navigator::GetMozVoicemail(ErrorResult& aRv)
|
|
|
|
{
|
2012-07-19 03:27:19 +00:00
|
|
|
if (!mVoicemail) {
|
2013-07-12 14:36:22 +00:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
2012-07-19 03:27:19 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 05:00:24 +00:00
|
|
|
mVoicemail = Voicemail::Create(mWindow, aRv);
|
2012-07-19 03:27:19 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:36:22 +00:00
|
|
|
return mVoicemail;
|
2012-07-19 03:27:19 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 05:00:23 +00:00
|
|
|
#ifdef MOZ_B2G_RIL
|
|
|
|
|
2014-04-16 07:30:28 +00:00
|
|
|
IccManager*
|
2013-07-12 14:36:22 +00:00
|
|
|
Navigator::GetMozIccManager(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mIccManager) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
2013-04-08 10:34:10 +00:00
|
|
|
}
|
2013-07-12 14:36:22 +00:00
|
|
|
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
2013-04-08 10:34:10 +00:00
|
|
|
|
2013-10-09 09:40:12 +00:00
|
|
|
mIccManager = new IccManager(mWindow);
|
2013-04-08 10:34:10 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:36:22 +00:00
|
|
|
return mIccManager;
|
2013-04-08 10:34:10 +00:00
|
|
|
}
|
2012-01-09 22:28:47 +00:00
|
|
|
#endif // MOZ_B2G_RIL
|
|
|
|
|
2012-02-16 00:47:13 +00:00
|
|
|
#ifdef MOZ_GAMEPAD
|
2013-07-12 14:36:32 +00: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 11:52:06 +00:00
|
|
|
win->SetHasGamepadEventListener(true);
|
2013-07-12 14:36:32 +00:00
|
|
|
win->GetGamepads(aGamepads);
|
|
|
|
}
|
2012-02-16 00:47:13 +00:00
|
|
|
#endif
|
|
|
|
|
2012-01-16 12:23:28 +00:00
|
|
|
//*****************************************************************************
|
2013-07-18 03:23:52 +00:00
|
|
|
// Navigator::nsIMozNavigatorNetwork
|
2012-01-16 12:23:28 +00:00
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-05 03:54:55 +00:00
|
|
|
Navigator::GetProperties(nsINetworkProperties** aProperties)
|
2012-01-16 12:23:28 +00:00
|
|
|
{
|
2014-03-05 03:54:55 +00:00
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aProperties = GetConnection(rv));
|
2013-07-12 14:35:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-01-16 17:14:56 +00:00
|
|
|
|
2014-01-16 10:53:48 +00:00
|
|
|
network::Connection*
|
2014-03-05 03:54:55 +00:00
|
|
|
Navigator::GetConnection(ErrorResult& aRv)
|
2013-07-12 14:35:44 +00:00
|
|
|
{
|
2012-01-16 12:23:44 +00:00
|
|
|
if (!mConnection) {
|
2014-03-05 03:54:55 +00:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-10-07 09:44:48 +00:00
|
|
|
mConnection = new network::Connection(mWindow);
|
2012-01-16 12:23:44 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:44 +00:00
|
|
|
return mConnection;
|
2012-01-16 12:23:28 +00:00
|
|
|
}
|
|
|
|
|
2012-02-20 15:15:19 +00:00
|
|
|
#ifdef MOZ_B2G_BT
|
2013-08-12 08:31:58 +00:00
|
|
|
bluetooth::BluetoothManager*
|
2013-07-12 14:36:32 +00:00
|
|
|
Navigator::GetMozBluetooth(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mBluetooth) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
mBluetooth = bluetooth::BluetoothManager::Create(mWindow);
|
2012-02-20 15:15:19 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:36:32 +00:00
|
|
|
return mBluetooth;
|
2012-02-20 15:15:19 +00:00
|
|
|
}
|
|
|
|
#endif //MOZ_B2G_BT
|
|
|
|
|
2012-07-23 06:53:08 +00:00
|
|
|
nsresult
|
2012-07-03 00:16:55 +00:00
|
|
|
Navigator::EnsureMessagesManager()
|
|
|
|
{
|
|
|
|
if (mMessagesManager) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-20 18:34:38 +00:00
|
|
|
NS_ENSURE_STATE(mWindow);
|
2012-07-03 00:16:55 +00:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMNavigatorSystemMessages> messageManager =
|
|
|
|
do_CreateInstance("@mozilla.org/system-message-manager;1", &rv);
|
2013-08-12 08:31:58 +00:00
|
|
|
|
2012-07-03 00:16:55 +00: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-29 20:16:04 +00:00
|
|
|
AutoJSContext cx;
|
|
|
|
JS::Rooted<JS::Value> prop_val(cx);
|
2014-01-09 17:39:36 +00:00
|
|
|
rv = gpi->Init(mWindow, &prop_val);
|
2012-07-03 00:16:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mMessagesManager = messageManager.forget();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:44 +00:00
|
|
|
bool
|
|
|
|
Navigator::MozHasPendingMessage(const nsAString& aType, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// The WebIDL binding is responsible for the pref check here.
|
2012-07-03 00:16:55 +00:00
|
|
|
nsresult rv = EnsureMessagesManager();
|
2013-07-12 14:35:44 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-03 00:16:55 +00:00
|
|
|
|
2013-07-12 14:35:44 +00:00
|
|
|
bool result = false;
|
|
|
|
rv = mMessagesManager->MozHasPendingMessage(aType, &result);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return result;
|
2012-07-03 00:16:55 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:44 +00: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 15:20:03 +00:00
|
|
|
#ifdef MOZ_TIME_MANAGER
|
2013-07-12 14:36:32 +00:00
|
|
|
time::TimeManager*
|
|
|
|
Navigator::GetMozTime(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-09-11 06:05:00 +00:00
|
|
|
if (!mTimeManager) {
|
2013-06-20 18:34:38 +00:00
|
|
|
mTimeManager = new time::TimeManager(mWindow);
|
2012-09-11 06:05:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:36:32 +00:00
|
|
|
return mTimeManager;
|
2012-09-11 06:05:00 +00:00
|
|
|
}
|
2012-11-05 15:20:03 +00:00
|
|
|
#endif
|
2012-09-11 06:05:00 +00:00
|
|
|
|
2013-07-12 14:35:44 +00:00
|
|
|
nsDOMCameraManager*
|
|
|
|
Navigator::GetMozCameras(ErrorResult& aRv)
|
|
|
|
{
|
2012-07-30 21:59:05 +00:00
|
|
|
if (!mCameraManager) {
|
2013-06-20 18:34:38 +00:00
|
|
|
if (!mWindow ||
|
|
|
|
!mWindow->GetOuterWindow() ||
|
|
|
|
mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) {
|
2013-07-12 14:35:44 +00:00
|
|
|
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return nullptr;
|
2012-07-30 21:59:05 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:44 +00:00
|
|
|
mCameraManager = nsDOMCameraManager::CreateInstance(mWindow);
|
2012-07-30 21:59:05 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:44 +00:00
|
|
|
return mCameraManager;
|
2012-07-30 21:59:05 +00:00
|
|
|
}
|
|
|
|
|
2014-08-19 13:56:00 +00:00
|
|
|
already_AddRefed<ServiceWorkerContainer>
|
2013-11-19 23:14:07 +00:00
|
|
|
Navigator::ServiceWorker()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mWindow);
|
|
|
|
|
|
|
|
if (!mServiceWorkerContainer) {
|
2014-08-19 13:56:00 +00:00
|
|
|
mServiceWorkerContainer = new ServiceWorkerContainer(mWindow);
|
2013-11-19 23:14:07 +00:00
|
|
|
}
|
|
|
|
|
2014-08-19 13:56:00 +00:00
|
|
|
nsRefPtr<ServiceWorkerContainer> ref = mServiceWorkerContainer;
|
2013-11-19 23:14:07 +00:00
|
|
|
return ref.forget();
|
|
|
|
}
|
|
|
|
|
2012-02-01 21:58:01 +00:00
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
Navigator::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2011-11-02 13:44:16 +00:00
|
|
|
{
|
2012-02-01 21:58:01 +00:00
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
|
|
|
|
// TODO: add SizeOfIncludingThis() to nsMimeTypeArray, bug 674113.
|
|
|
|
// TODO: add SizeOfIncludingThis() to nsPluginArray, bug 674114.
|
2013-04-12 18:47:47 +00:00
|
|
|
// TODO: add SizeOfIncludingThis() to Geolocation, bug 674115.
|
2013-04-10 14:20:43 +00:00
|
|
|
// TODO: add SizeOfIncludingThis() to DesktopNotificationCenter, bug 674116.
|
2012-02-01 21:58:01 +00:00
|
|
|
|
|
|
|
return n;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2011-12-28 13:39:55 +00:00
|
|
|
void
|
|
|
|
Navigator::SetWindow(nsPIDOMWindow *aInnerWindow)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aInnerWindow->IsInnerWindow(),
|
|
|
|
"Navigator must get an inner window!");
|
2013-06-20 18:34:38 +00:00
|
|
|
mWindow = aInnerWindow;
|
2011-12-28 13:39:55 +00:00
|
|
|
}
|
|
|
|
|
2012-06-03 07:35:15 +00:00
|
|
|
void
|
|
|
|
Navigator::OnNavigation()
|
|
|
|
{
|
2013-06-20 18:34:38 +00:00
|
|
|
if (!mWindow) {
|
2012-07-30 21:59:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-03 07:35:15 +00:00
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
2012-07-30 21:59:05 +00:00
|
|
|
// Inform MediaManager in case there are live streams or pending callbacks.
|
2012-06-03 07:35:15 +00:00
|
|
|
MediaManager *manager = MediaManager::Get();
|
2013-02-08 03:14:21 +00:00
|
|
|
if (manager) {
|
2013-06-20 18:34:38 +00:00
|
|
|
manager->OnNavigation(mWindow->WindowID());
|
2013-02-08 03:14:21 +00:00
|
|
|
}
|
2012-06-03 07:35:15 +00:00
|
|
|
#endif
|
2012-07-30 21:59:05 +00:00
|
|
|
if (mCameraManager) {
|
2013-06-20 18:34:38 +00:00
|
|
|
mCameraManager->OnNavigation(mWindow->WindowID());
|
2012-07-30 21:59:05 +00:00
|
|
|
}
|
2012-06-03 07:35:15 +00:00
|
|
|
}
|
|
|
|
|
2012-10-02 09:08:02 +00:00
|
|
|
bool
|
|
|
|
Navigator::CheckPermission(const char* type)
|
|
|
|
{
|
2013-07-12 14:35:35 +00:00
|
|
|
return CheckPermission(mWindow, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::CheckPermission(nsPIDOMWindow* aWindow, const char* aType)
|
|
|
|
{
|
|
|
|
if (!aWindow) {
|
2013-06-20 18:34:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-10-02 09:08:02 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr =
|
2014-04-29 17:27:26 +00:00
|
|
|
services::GetPermissionManager();
|
2012-10-02 09:08:02 +00:00
|
|
|
NS_ENSURE_TRUE(permMgr, false);
|
|
|
|
|
|
|
|
uint32_t permission = nsIPermissionManager::DENY_ACTION;
|
2013-07-12 14:35:35 +00:00
|
|
|
permMgr->TestPermissionFromWindow(aWindow, aType, &permission);
|
2012-10-02 09:08:02 +00:00
|
|
|
return permission == nsIPermissionManager::ALLOW_ACTION;
|
|
|
|
}
|
|
|
|
|
2012-11-29 22:52:03 +00:00
|
|
|
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
2013-07-12 14:36:32 +00:00
|
|
|
system::AudioChannelManager*
|
|
|
|
Navigator::GetMozAudioChannelManager(ErrorResult& aRv)
|
|
|
|
{
|
2012-11-29 22:52:03 +00:00
|
|
|
if (!mAudioChannelManager) {
|
2013-07-12 14:36:32 +00:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-11-29 22:52:03 +00:00
|
|
|
mAudioChannelManager = new system::AudioChannelManager();
|
2013-06-20 18:34:38 +00:00
|
|
|
mAudioChannelManager->Init(mWindow);
|
2012-11-29 22:52:03 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:36:32 +00:00
|
|
|
return mAudioChannelManager;
|
2012-11-29 22:52:03 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-12 14:37:23 +00:00
|
|
|
bool
|
|
|
|
Navigator::DoNewResolve(JSContext* aCx, JS::Handle<JSObject*> aObject,
|
2013-07-16 05:31:03 +00:00
|
|
|
JS::Handle<jsid> aId,
|
2014-01-22 03:08:51 +00:00
|
|
|
JS::MutableHandle<JSPropertyDescriptor> aDesc)
|
2013-07-12 14:37:23 +00:00
|
|
|
{
|
|
|
|
if (!JSID_IS_STRING(aId)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-19 23:24:29 +00:00
|
|
|
nsScriptNameSpaceManager* nameSpaceManager = GetNameSpaceManager();
|
2013-07-12 14:37:23 +00:00
|
|
|
if (!nameSpaceManager) {
|
2013-09-09 03:29:21 +00:00
|
|
|
return Throw(aCx, NS_ERROR_NOT_INITIALIZED);
|
2013-07-12 14:37:23 +00:00
|
|
|
}
|
|
|
|
|
2014-07-05 15:30:54 +00:00
|
|
|
nsAutoJSString name;
|
|
|
|
if (!name.init(aCx, JSID_TO_STRING(aId))) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-12 14:37:23 +00:00
|
|
|
|
|
|
|
const nsGlobalNameStruct* name_struct =
|
|
|
|
nameSpaceManager->LookupNavigatorName(name);
|
|
|
|
if (!name_struct) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-21 07:25:21 +00:00
|
|
|
JS::Rooted<JSObject*> naviObj(aCx,
|
|
|
|
js::CheckedUnwrap(aObject,
|
|
|
|
/* stopAtOuter = */ false));
|
|
|
|
if (!naviObj) {
|
|
|
|
return Throw(aCx, NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
}
|
|
|
|
|
2013-07-12 14:37:23 +00:00
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeNewDOMBinding) {
|
|
|
|
ConstructNavigatorProperty construct = name_struct->mConstructNavigatorProperty;
|
|
|
|
MOZ_ASSERT(construct);
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> domObject(aCx);
|
|
|
|
{
|
2014-03-21 07:25:21 +00:00
|
|
|
// Make sure to do the creation of our object in the compartment
|
|
|
|
// of naviObj, especially since we plan to cache that object.
|
2013-07-12 14:37:23 +00:00
|
|
|
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 13:59:13 +00:00
|
|
|
if (name.EqualsLiteral("mozSettings")) {
|
2014-08-28 04:01:29 +00:00
|
|
|
bool hasPermission = CheckPermission("settings-api-read") ||
|
|
|
|
CheckPermission("settings-api-write");
|
2013-08-06 13:59:13 +00:00
|
|
|
if (!hasPermission) {
|
2014-01-22 03:08:51 +00:00
|
|
|
FillPropertyDescriptor(aDesc, aObject, JS::NullValue(), false);
|
2013-08-06 13:59:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-28 07:18:12 +00:00
|
|
|
if (name.EqualsLiteral("mozDownloadManager")) {
|
|
|
|
if (!CheckPermission("downloads")) {
|
2014-01-22 03:08:51 +00:00
|
|
|
FillPropertyDescriptor(aDesc, aObject, JS::NullValue(), false);
|
2013-11-28 07:18:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-21 03:19:43 +00:00
|
|
|
nsISupports* existingObject = mCachedResolveResults.GetWeak(name);
|
|
|
|
if (existingObject) {
|
|
|
|
// We know all of our WebIDL objects here are wrappercached, so just go
|
|
|
|
// ahead and WrapObject() them. We can't use WrapNewBindingObject,
|
|
|
|
// because we don't have the concrete type.
|
|
|
|
JS::Rooted<JS::Value> wrapped(aCx);
|
2014-04-10 04:58:43 +00:00
|
|
|
if (!dom::WrapObject(aCx, existingObject, &wrapped)) {
|
2014-03-21 03:19:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
domObject = &wrapped.toObject();
|
|
|
|
} else {
|
|
|
|
domObject = construct(aCx, naviObj);
|
|
|
|
if (!domObject) {
|
|
|
|
return Throw(aCx, NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store the value in our cache
|
|
|
|
nsISupports* native = UnwrapDOMObjectToISupports(domObject);
|
|
|
|
MOZ_ASSERT(native);
|
|
|
|
mCachedResolveResults.Put(name, native);
|
2013-07-12 14:37:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-16 00:02:23 +00:00
|
|
|
if (!JS_WrapObject(aCx, &domObject)) {
|
2013-07-12 14:37:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-22 03:08:51 +00:00
|
|
|
FillPropertyDescriptor(aDesc, aObject, JS::ObjectValue(*domObject), false);
|
2013-07-12 14:37:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(name_struct->mType == nsGlobalNameStruct::eTypeNavigatorProperty,
|
|
|
|
"unexpected type");
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2014-03-21 03:19:43 +00:00
|
|
|
nsCOMPtr<nsISupports> native;
|
|
|
|
bool hadCachedNative = mCachedResolveResults.Get(name, getter_AddRefs(native));
|
|
|
|
bool okToUseNative;
|
|
|
|
JS::Rooted<JS::Value> prop_val(aCx);
|
|
|
|
if (hadCachedNative) {
|
|
|
|
okToUseNative = true;
|
|
|
|
} else {
|
|
|
|
native = do_CreateInstance(name_struct->mCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return Throw(aCx, rv);
|
|
|
|
}
|
2013-07-12 14:37:23 +00:00
|
|
|
|
2014-03-21 03:19:43 +00:00
|
|
|
nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi(do_QueryInterface(native));
|
2013-07-12 14:37:23 +00:00
|
|
|
|
2014-03-21 03:19:43 +00:00
|
|
|
if (gpi) {
|
|
|
|
if (!mWindow) {
|
|
|
|
return Throw(aCx, NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
2013-07-12 14:37:23 +00:00
|
|
|
|
2014-03-21 03:19:43 +00:00
|
|
|
rv = gpi->Init(mWindow, &prop_val);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return Throw(aCx, rv);
|
|
|
|
}
|
2013-07-12 14:37:23 +00:00
|
|
|
}
|
2014-03-21 03:19:43 +00:00
|
|
|
|
|
|
|
okToUseNative = !prop_val.isObjectOrNull();
|
2013-07-12 14:37:23 +00:00
|
|
|
}
|
|
|
|
|
2014-03-21 03:19:43 +00:00
|
|
|
if (okToUseNative) {
|
2014-03-21 07:25:21 +00:00
|
|
|
// Make sure to do the creation of our object in the compartment
|
|
|
|
// of naviObj, especially since we plan to cache that object.
|
|
|
|
JSAutoCompartment ac(aCx, naviObj);
|
|
|
|
|
2014-04-10 04:58:41 +00:00
|
|
|
rv = nsContentUtils::WrapNative(aCx, native, &prop_val);
|
2013-07-12 14:37:23 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-09-09 03:29:21 +00:00
|
|
|
return Throw(aCx, rv);
|
2013-07-12 14:37:23 +00:00
|
|
|
}
|
2014-03-21 03:19:43 +00:00
|
|
|
|
|
|
|
// Now that we know we managed to wrap this thing properly, go ahead and
|
|
|
|
// cache it as needed.
|
|
|
|
if (!hadCachedNative) {
|
|
|
|
mCachedResolveResults.Put(name, native);
|
|
|
|
}
|
2013-07-12 14:37:23 +00:00
|
|
|
}
|
|
|
|
|
2013-10-26 16:19:05 +00:00
|
|
|
if (!JS_WrapValue(aCx, &prop_val)) {
|
2013-09-09 03:29:21 +00:00
|
|
|
return Throw(aCx, NS_ERROR_UNEXPECTED);
|
2013-07-12 14:37:23 +00:00
|
|
|
}
|
|
|
|
|
2014-01-22 03:08:51 +00:00
|
|
|
FillPropertyDescriptor(aDesc, aObject, prop_val, false);
|
2013-07-16 05:31:03 +00:00
|
|
|
return true;
|
2013-07-12 14:37:23 +00:00
|
|
|
}
|
|
|
|
|
2014-02-15 21:12:34 +00:00
|
|
|
struct NavigatorNameEnumeratorClosure
|
|
|
|
{
|
|
|
|
NavigatorNameEnumeratorClosure(JSContext* aCx, JSObject* aWrapper,
|
|
|
|
nsTArray<nsString>& aNames)
|
|
|
|
: mCx(aCx),
|
|
|
|
mWrapper(aCx, aWrapper),
|
|
|
|
mNames(aNames)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext* mCx;
|
|
|
|
JS::Rooted<JSObject*> mWrapper;
|
|
|
|
nsTArray<nsString>& mNames;
|
|
|
|
};
|
|
|
|
|
2013-08-04 03:38:54 +00:00
|
|
|
static PLDHashOperator
|
2014-02-15 21:12:34 +00:00
|
|
|
SaveNavigatorName(const nsAString& aName,
|
|
|
|
const nsGlobalNameStruct& aNameStruct,
|
|
|
|
void* aClosure)
|
2013-08-04 03:38:54 +00:00
|
|
|
{
|
2014-02-15 21:12:34 +00:00
|
|
|
NavigatorNameEnumeratorClosure* closure =
|
|
|
|
static_cast<NavigatorNameEnumeratorClosure*>(aClosure);
|
|
|
|
if (!aNameStruct.mConstructorEnabled ||
|
|
|
|
aNameStruct.mConstructorEnabled(closure->mCx, closure->mWrapper)) {
|
|
|
|
closure->mNames.AppendElement(aName);
|
|
|
|
}
|
2013-08-04 03:38:54 +00:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Navigator::GetOwnPropertyNames(JSContext* aCx, nsTArray<nsString>& aNames,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2013-08-19 23:24:29 +00:00
|
|
|
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
|
2013-08-04 03:38:54 +00:00
|
|
|
if (!nameSpaceManager) {
|
|
|
|
NS_ERROR("Can't get namespace manager.");
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-15 21:12:34 +00:00
|
|
|
NavigatorNameEnumeratorClosure closure(aCx, GetWrapper(), aNames);
|
|
|
|
nameSpaceManager->EnumerateNavigatorNames(SaveNavigatorName, &closure);
|
2013-08-04 03:38:54 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:37:23 +00:00
|
|
|
JSObject*
|
2014-04-08 22:27:18 +00:00
|
|
|
Navigator::WrapObject(JSContext* cx)
|
2013-07-12 14:37:23 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return NavigatorBinding::Wrap(cx, this);
|
2013-07-12 14:37:23 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:35:35 +00:00
|
|
|
/* 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-10-29 08:12:38 +00:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasCameraSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && nsDOMCameraManager::CheckPermission(win);
|
|
|
|
}
|
|
|
|
|
2014-01-27 07:48:10 +00: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.
|
|
|
|
|
2014-05-13 09:58:00 +00:00
|
|
|
nsIPrincipal* principal = nsContentUtils::ObjectPrincipal(aGlobal);
|
2014-01-27 07:48:10 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr =
|
2014-04-29 17:27:26 +00:00
|
|
|
services::GetPermissionManager();
|
2014-01-27 07:48:10 +00:00
|
|
|
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 14:36:13 +00:00
|
|
|
|
2013-10-02 22:09:08 +00:00
|
|
|
#ifdef MOZ_NFC
|
|
|
|
/* static */
|
|
|
|
bool
|
2014-04-29 03:50:25 +00:00
|
|
|
Navigator::HasNFCSupport(JSContext* /* unused */, JSObject* aGlobal)
|
2013-10-02 22:09:08 +00:00
|
|
|
{
|
2014-07-18 16:37:42 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
|
2013-12-17 02:32:29 +00:00
|
|
|
// Do not support NFC if NFC content helper does not exist.
|
|
|
|
nsCOMPtr<nsISupports> contentHelper = do_GetService("@mozilla.org/nfc/content-helper;1");
|
2014-08-19 10:43:57 +00:00
|
|
|
return !!contentHelper;
|
2013-10-02 22:09:08 +00:00
|
|
|
}
|
2014-01-13 09:33:12 +00:00
|
|
|
#endif // MOZ_NFC
|
2013-10-02 22:09:08 +00:00
|
|
|
|
2013-07-12 14:37:21 +00:00
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
|
|
|
/* static */
|
2014-01-13 22:28:40 +00:00
|
|
|
bool
|
|
|
|
Navigator::HasUserMediaSupport(JSContext* /* unused */,
|
|
|
|
JSObject* /* unused */)
|
2013-07-12 14:37:21 +00: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-09-26 07:10:56 +00:00
|
|
|
/* static */
|
2014-01-13 22:28:40 +00:00
|
|
|
bool
|
|
|
|
Navigator::HasInputMethodSupport(JSContext* /* unused */,
|
|
|
|
JSObject* aGlobal)
|
2013-09-26 07:10:56 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
2014-03-31 02:38:45 +00:00
|
|
|
if (!win || !Preferences::GetBool("dom.mozInputMethod.enabled", false)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-13 22:28:40 +00:00
|
|
|
if (Preferences::GetBool("dom.mozInputMethod.testing", false)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-31 02:38:45 +00:00
|
|
|
return CheckPermission(win, "input") ||
|
|
|
|
CheckPermission(win, "input-manage");
|
2013-09-26 07:10:56 +00:00
|
|
|
}
|
|
|
|
|
2013-12-05 23:12:23 +00:00
|
|
|
/* static */
|
|
|
|
bool
|
2014-03-12 09:03:05 +00:00
|
|
|
Navigator::HasDataStoreSupport(nsIPrincipal* aPrincipal)
|
2013-12-05 23:12:23 +00:00
|
|
|
{
|
2014-03-12 09:03:05 +00:00
|
|
|
workers::AssertIsOnMainThread();
|
2013-12-11 20:15:16 +00:00
|
|
|
|
2014-06-19 14:03:54 +00:00
|
|
|
return DataStoreService::CheckPermission(aPrincipal);
|
2014-03-12 09:03:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// A WorkerMainThreadRunnable to synchronously dispatch the call of
|
|
|
|
// HasDataStoreSupport() from the worker thread to the main thread.
|
|
|
|
class HasDataStoreSupportRunnable MOZ_FINAL
|
|
|
|
: public workers::WorkerMainThreadRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool mResult;
|
|
|
|
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit HasDataStoreSupportRunnable(workers::WorkerPrivate* aWorkerPrivate)
|
2014-03-12 09:03:05 +00:00
|
|
|
: workers::WorkerMainThreadRunnable(aWorkerPrivate)
|
|
|
|
, mResult(false)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aWorkerPrivate);
|
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool
|
|
|
|
MainThreadRun() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
workers::AssertIsOnMainThread();
|
|
|
|
|
|
|
|
mResult = Navigator::HasDataStoreSupport(mWorkerPrivate->GetPrincipal());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasDataStoreSupport(JSContext* aCx, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
// If the caller is on the worker thread, dispatch this to the main thread.
|
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
workers::WorkerPrivate* workerPrivate =
|
|
|
|
workers::GetWorkerPrivateFromContext(aCx);
|
|
|
|
workerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
nsRefPtr<HasDataStoreSupportRunnable> runnable =
|
|
|
|
new HasDataStoreSupportRunnable(workerPrivate);
|
|
|
|
runnable->Dispatch(aCx);
|
|
|
|
|
|
|
|
return runnable->mResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
workers::AssertIsOnMainThread();
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> global(aCx, aGlobal);
|
|
|
|
|
2013-12-11 20:15:16 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(global);
|
2013-12-05 23:12:23 +00:00
|
|
|
if (!win) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* doc = win->GetExtantDoc();
|
|
|
|
if (!doc || !doc->NodePrincipal()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-12 09:03:05 +00:00
|
|
|
return HasDataStoreSupport(doc->NodePrincipal());
|
2013-12-05 23:12:23 +00:00
|
|
|
}
|
|
|
|
|
2014-06-26 23:18:19 +00:00
|
|
|
#ifdef MOZ_B2G
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasMobileIdSupport(JSContext* aCx, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
if (!win) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* doc = win->GetExtantDoc();
|
|
|
|
if (!doc) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPrincipal* principal = doc->NodePrincipal();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
|
|
|
|
NS_ENSURE_TRUE(permMgr, false);
|
|
|
|
|
|
|
|
uint32_t permission = nsIPermissionManager::UNKNOWN_ACTION;
|
|
|
|
permMgr->TestPermissionFromPrincipal(principal, "mobileid", &permission);
|
2014-07-24 19:57:02 +00:00
|
|
|
return permission == nsIPermissionManager::PROMPT_ACTION ||
|
|
|
|
permission == nsIPermissionManager::ALLOW_ACTION;
|
2014-06-26 23:18:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
2014-05-12 02:05:03 +00:00
|
|
|
|
2013-07-12 14:35:35 +00: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 13:44:16 +00:00
|
|
|
nsresult
|
2014-09-23 19:11:18 +00:00
|
|
|
Navigator::GetPlatform(nsAString& aPlatform, bool aUsePrefOverriddenValue)
|
2011-11-02 13:44:16 +00:00
|
|
|
{
|
2014-09-23 19:11:18 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2011-11-02 13:44:16 +00:00
|
|
|
|
2014-09-23 19:11:18 +00:00
|
|
|
if (aUsePrefOverriddenValue && !nsContentUtils::IsCallerChrome()) {
|
2011-11-02 13:44:16 +00: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 02:35:17 +00:00
|
|
|
nsAutoCString plat;
|
2011-11-02 13:44:16 +00:00
|
|
|
rv = service->GetOscpu(plat);
|
|
|
|
CopyASCIItoUTF16(plat, aPlatform);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2014-09-23 19:11:18 +00:00
|
|
|
|
|
|
|
/* static */ nsresult
|
|
|
|
Navigator::GetAppVersion(nsAString& aAppVersion, bool aUsePrefOverriddenValue)
|
2011-11-02 13:44:16 +00:00
|
|
|
{
|
2014-09-24 16:09:50 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2014-09-23 19:11:18 +00:00
|
|
|
if (aUsePrefOverriddenValue && !nsContentUtils::IsCallerChrome()) {
|
2011-11-02 13:44:16 +00: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 02:35:17 +00:00
|
|
|
nsAutoCString str;
|
2011-11-02 13:44:16 +00: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 15:02:17 +00:00
|
|
|
aAppVersion.Append(char16_t(')'));
|
2011-11-02 13:44:16 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-09-23 19:11:18 +00:00
|
|
|
/* static */ void
|
|
|
|
Navigator::AppName(nsAString& aAppName, bool aUsePrefOverriddenValue)
|
2011-11-02 13:44:16 +00:00
|
|
|
{
|
2014-09-24 16:09:50 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2014-09-23 19:11:18 +00:00
|
|
|
if (aUsePrefOverriddenValue && !nsContentUtils::IsCallerChrome()) {
|
2011-11-02 13:44:16 +00:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
mozilla::Preferences::GetString("general.appname.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aAppName = override;
|
2013-11-17 23:10:15 +00:00
|
|
|
return;
|
2011-11-02 13:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aAppName.AssignLiteral("Netscape");
|
|
|
|
}
|
2014-09-23 19:11:18 +00:00
|
|
|
|
|
|
|
nsresult
|
2014-09-24 16:09:50 +00:00
|
|
|
Navigator::GetUserAgent(nsPIDOMWindow* aWindow, nsIURI* aURI,
|
|
|
|
bool aIsCallerChrome,
|
|
|
|
nsAString& aUserAgent)
|
2014-09-23 19:11:18 +00:00
|
|
|
{
|
2014-09-24 16:09:50 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-09-24 10:40:43 +00:00
|
|
|
|
2014-09-24 16:09:50 +00:00
|
|
|
if (!aIsCallerChrome) {
|
|
|
|
const nsAdoptingString& override =
|
|
|
|
mozilla::Preferences::GetString("general.useragent.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aUserAgent = override;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
2014-09-23 19:11:18 +00:00
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
2014-09-24 16:09:50 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2014-09-23 19:11:18 +00:00
|
|
|
|
|
|
|
nsAutoCString ua;
|
|
|
|
rv = service->GetUserAgent(ua);
|
2014-09-24 16:09:50 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-09-23 19:11:18 +00:00
|
|
|
CopyASCIItoUTF16(ua, aUserAgent);
|
|
|
|
|
2014-09-24 16:09:50 +00:00
|
|
|
if (!aWindow || !aURI) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aWindow->GetDocShell());
|
|
|
|
|
|
|
|
nsCOMPtr<nsISiteSpecificUserAgent> siteSpecificUA =
|
|
|
|
do_GetService("@mozilla.org/dom/site-specific-user-agent;1");
|
|
|
|
if (!siteSpecificUA) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return siteSpecificUA->GetUserAgentForURIAndWindow(aURI, aWindow, aUserAgent);
|
2014-09-23 19:11:18 +00:00
|
|
|
}
|
2014-09-24 16:09:50 +00:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|