2011-11-02 17:44:16 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=2 et tw=78: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
// Needs to be first.
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
|
|
|
#include "Navigator.h"
|
|
|
|
#include "nsIXULAppInfo.h"
|
|
|
|
#include "nsPluginArray.h"
|
|
|
|
#include "nsMimeTypeArray.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-04-10 18:20:43 +04:00
|
|
|
#include "mozilla/dom/DesktopNotification.h"
|
2014-10-08 20:15:23 +04:00
|
|
|
#include "mozilla/dom/File.h"
|
2011-11-02 17:44:16 +04:00
|
|
|
#include "nsGeolocation.h"
|
|
|
|
#include "nsIHttpProtocolHandler.h"
|
2014-03-06 19:51:23 +04:00
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsIContentSecurityPolicy.h"
|
|
|
|
#include "nsContentPolicyUtils.h"
|
|
|
|
#include "nsCrossSiteListenerProxy.h"
|
|
|
|
#include "nsISupportsPriority.h"
|
2011-11-02 17:44:16 +04:00
|
|
|
#include "nsICachingChannel.h"
|
|
|
|
#include "nsIWebContentHandlerRegistrar.h"
|
|
|
|
#include "nsICookiePermission.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/Telemetry.h"
|
2011-11-02 19:01:32 +04:00
|
|
|
#include "BatteryManager.h"
|
2013-09-11 18:35:04 +04:00
|
|
|
#include "mozilla/dom/PowerManager.h"
|
2014-01-07 16:16:07 +04:00
|
|
|
#include "mozilla/dom/WakeLock.h"
|
|
|
|
#include "mozilla/dom/power/PowerManagerService.h"
|
2014-08-25 13:24:03 +04:00
|
|
|
#include "mozilla/dom/CellBroadcast.h"
|
2013-03-09 11:21:47 +04:00
|
|
|
#include "mozilla/dom/MobileMessageManager.h"
|
2013-11-20 03:14:07 +04:00
|
|
|
#include "mozilla/dom/ServiceWorkerContainer.h"
|
2013-10-29 12:12:38 +04:00
|
|
|
#include "mozilla/dom/Telephony.h"
|
2014-09-26 09:00:23 +04:00
|
|
|
#include "mozilla/dom/Voicemail.h"
|
2011-11-11 01:26:36 +04:00
|
|
|
#include "mozilla/Hal.h"
|
2012-10-12 02:56:13 +04:00
|
|
|
#include "nsISiteSpecificUserAgent.h"
|
2011-11-11 01:26:36 +04:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2012-07-26 23:33:45 +04:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2012-01-16 16:23:44 +04:00
|
|
|
#include "Connection.h"
|
2014-03-05 04:37:43 +04:00
|
|
|
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
|
2013-06-25 00:07:03 +04:00
|
|
|
#include "nsGlobalWindow.h"
|
2014-06-07 21:30:18 +04:00
|
|
|
#ifdef MOZ_B2G
|
|
|
|
#include "nsIMobileIdentityService.h"
|
|
|
|
#endif
|
2012-08-27 21:34:10 +04:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-10-22 15:23:00 +04:00
|
|
|
#include "mozilla/dom/IccManager.h"
|
2014-01-02 07:06:17 +04:00
|
|
|
#include "mozilla/dom/MobileConnectionArray.h"
|
2012-08-27 21:34:10 +04:00
|
|
|
#endif
|
2012-06-29 12:32:21 +04:00
|
|
|
#include "nsIIdleObserver.h"
|
2012-08-17 04:42:26 +04:00
|
|
|
#include "nsIPermissionManager.h"
|
2014-03-06 19:51:23 +04:00
|
|
|
#include "nsMimeTypes.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsIHttpChannel.h"
|
2014-03-06 19:51:23 +04:00
|
|
|
#include "nsIHttpChannelInternal.h"
|
2012-09-11 10:05:00 +04:00
|
|
|
#include "TimeManager.h"
|
2013-08-15 22:17:48 +04:00
|
|
|
#include "DeviceStorage.h"
|
|
|
|
#include "nsIDOMNavigatorSystemMessages.h"
|
2014-03-06 19:51:23 +04:00
|
|
|
#include "nsStreamUtils.h"
|
2013-12-06 03:12:23 +04:00
|
|
|
#include "nsIAppsService.h"
|
|
|
|
#include "mozIApplication.h"
|
2014-01-28 20:09:34 +04:00
|
|
|
#include "WidgetUtils.h"
|
2014-03-06 19:51:23 +04:00
|
|
|
#include "mozIThirdPartyUtil.h"
|
2011-11-02 17:44:16 +04:00
|
|
|
|
2012-06-03 11:35:15 +04:00
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
2014-09-20 10:20:41 +04:00
|
|
|
#include "mozilla/dom/MediaDevices.h"
|
2012-06-03 11:35:15 +04:00
|
|
|
#include "MediaManager.h"
|
|
|
|
#endif
|
2012-02-20 19:15:19 +04:00
|
|
|
#ifdef MOZ_B2G_BT
|
2012-05-24 08:02:23 +04:00
|
|
|
#include "BluetoothManager.h"
|
2012-02-20 19:15:19 +04:00
|
|
|
#endif
|
2012-07-31 01:59:05 +04:00
|
|
|
#include "DOMCameraManager.h"
|
2012-01-10 02:28:47 +04:00
|
|
|
|
2012-11-30 02:52:03 +04:00
|
|
|
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
|
|
|
#include "AudioChannelManager.h"
|
|
|
|
#endif
|
|
|
|
|
2013-09-04 02:26:33 +04:00
|
|
|
#ifdef MOZ_B2G_FM
|
|
|
|
#include "mozilla/dom/FMRadio.h"
|
|
|
|
#endif
|
|
|
|
|
2012-07-03 04:16:55 +04:00
|
|
|
#include "nsIDOMGlobalPropertyInitializer.h"
|
2014-06-03 18:36:46 +04:00
|
|
|
#include "mozilla/dom/DataStoreService.h"
|
2013-07-12 18:35:35 +04:00
|
|
|
#include "nsJSUtils.h"
|
|
|
|
|
2013-07-12 18:37:23 +04:00
|
|
|
#include "nsScriptNameSpaceManager.h"
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
#include "mozilla/dom/NavigatorBinding.h"
|
2013-10-02 21:27:07 +04:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2013-09-11 19:45:51 +04:00
|
|
|
|
2014-03-06 19:51:23 +04:00
|
|
|
#include "nsIUploadChannel2.h"
|
|
|
|
#include "nsFormData.h"
|
2014-03-26 08:15:14 +04:00
|
|
|
#include "nsIPrivateBrowsingChannel.h"
|
|
|
|
#include "nsIDocShell.h"
|
2014-03-06 19:51:23 +04:00
|
|
|
|
2014-03-12 13:03:05 +04:00
|
|
|
#include "WorkerPrivate.h"
|
|
|
|
#include "WorkerRunnable.h"
|
|
|
|
|
2014-05-21 09:49:36 +04:00
|
|
|
#if defined(XP_LINUX)
|
|
|
|
#include "mozilla/Hal.h"
|
|
|
|
#endif
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
|
|
|
|
2014-07-15 03:08:45 +04:00
|
|
|
#include "mozilla/dom/FeatureList.h"
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2011-11-11 01:26:36 +04:00
|
|
|
static bool sDoNotTrackEnabled = false;
|
|
|
|
static bool sVibratorEnabled = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sMaxVibrateMS = 0;
|
|
|
|
static uint32_t sMaxVibrateListLen = 0;
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
Navigator::Init()
|
|
|
|
{
|
|
|
|
Preferences::AddBoolVarCache(&sDoNotTrackEnabled,
|
|
|
|
"privacy.donottrackheader.enabled",
|
|
|
|
false);
|
2011-11-11 01:26:36 +04:00
|
|
|
Preferences::AddBoolVarCache(&sVibratorEnabled,
|
|
|
|
"dom.vibrator.enabled", true);
|
|
|
|
Preferences::AddUintVarCache(&sMaxVibrateMS,
|
|
|
|
"dom.vibrator.max_vibrate_ms", 10000);
|
|
|
|
Preferences::AddUintVarCache(&sMaxVibrateListLen,
|
|
|
|
"dom.vibrator.max_vibrate_list_len", 128);
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2011-12-01 12:28:16 +04:00
|
|
|
Navigator::Navigator(nsPIDOMWindow* aWindow)
|
2013-06-20 22:34:38 +04:00
|
|
|
: mWindow(aWindow)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2013-11-28 18:07:55 +04:00
|
|
|
MOZ_ASSERT(aWindow->IsInnerWindow(), "Navigator must get an inner window!");
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Navigator::~Navigator()
|
|
|
|
{
|
2011-12-01 12:28:16 +04:00
|
|
|
Invalidate();
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Navigator)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2011-11-02 17:44:16 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNavigator)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigator)
|
2013-07-18 07:23:52 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMozNavigatorNetwork)
|
2011-11-02 17:44:16 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Navigator)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Navigator)
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Navigator)
|
|
|
|
|
2013-06-28 22:06:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Navigator)
|
|
|
|
tmp->Invalidate();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
|
2014-03-21 07:19:43 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCachedResolveResults)
|
2013-06-28 22:06:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
|
2013-07-09 17:58:21 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPlugins)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMimeTypes)
|
2013-06-28 22:06:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGeolocation)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNotification)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBatteryManager)
|
2013-07-18 20:07:28 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPowerManager)
|
2014-08-25 13:24:03 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCellBroadcast)
|
2013-06-28 22:06:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMobileMessageManager)
|
2013-10-29 12:12:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTelephony)
|
2014-09-26 09:00:23 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVoicemail)
|
2013-06-28 22:06:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConnection)
|
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-11-13 12:51:23 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMobileConnections)
|
2013-06-28 22:06:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(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-20 03:14:07 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mServiceWorkerContainer)
|
2013-06-28 22:06:39 +04:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
2014-03-21 07:19:43 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCachedResolveResults)
|
2013-06-28 22:06:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(Navigator)
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
void
|
2011-12-01 12:28:16 +04:00
|
|
|
Navigator::Invalidate()
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2013-06-20 22:34:38 +04:00
|
|
|
// Don't clear mWindow here so we know we've got a non-null mWindow
|
|
|
|
// until we're unlinked.
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
if (mPlugins) {
|
2011-12-01 12:28:16 +04:00
|
|
|
mPlugins->Invalidate();
|
2012-07-30 18:20:58 +04:00
|
|
|
mPlugins = nullptr;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:58:21 +04:00
|
|
|
mMimeTypes = nullptr;
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
// If there is a page transition, make sure delete the geolocation object.
|
|
|
|
if (mGeolocation) {
|
|
|
|
mGeolocation->Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
mGeolocation = nullptr;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mNotification) {
|
|
|
|
mNotification->Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
mNotification = nullptr;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
2011-11-02 19:27:06 +04:00
|
|
|
|
|
|
|
if (mBatteryManager) {
|
|
|
|
mBatteryManager->Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
mBatteryManager = nullptr;
|
2011-11-02 19:27:06 +04:00
|
|
|
}
|
2011-11-21 02:23:20 +04:00
|
|
|
|
2013-09-04 02:26:33 +04:00
|
|
|
#ifdef MOZ_B2G_FM
|
|
|
|
if (mFMRadio) {
|
|
|
|
mFMRadio->Shutdown();
|
|
|
|
mFMRadio = nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-03-07 15:03:25 +04:00
|
|
|
if (mPowerManager) {
|
|
|
|
mPowerManager->Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
mPowerManager = nullptr;
|
2012-03-07 15:03:25 +04:00
|
|
|
}
|
2012-01-20 07:24:00 +04:00
|
|
|
|
2014-08-25 13:24:03 +04:00
|
|
|
if (mCellBroadcast) {
|
|
|
|
mCellBroadcast = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-03-09 11:21:47 +04:00
|
|
|
if (mMobileMessageManager) {
|
|
|
|
mMobileMessageManager->Shutdown();
|
|
|
|
mMobileMessageManager = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-10-29 12:12:38 +04:00
|
|
|
if (mTelephony) {
|
|
|
|
mTelephony = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-09-26 09:00:23 +04:00
|
|
|
if (mVoicemail) {
|
2014-09-26 09:00:24 +04:00
|
|
|
mVoicemail->Shutdown();
|
2014-09-26 09:00:23 +04:00
|
|
|
mVoicemail = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-01-16 21:14:56 +04:00
|
|
|
if (mConnection) {
|
|
|
|
mConnection->Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
mConnection = nullptr;
|
2012-01-16 21:14:56 +04:00
|
|
|
}
|
2012-02-20 19:15:19 +04:00
|
|
|
|
2012-08-27 21:34:10 +04:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-11-13 12:51:23 +04:00
|
|
|
if (mMobileConnections) {
|
|
|
|
mMobileConnections = nullptr;
|
2012-04-20 01:33:25 +04:00
|
|
|
}
|
2012-12-04 06:38:25 +04:00
|
|
|
|
2013-04-08 14:34:10 +04:00
|
|
|
if (mIccManager) {
|
|
|
|
mIccManager->Shutdown();
|
|
|
|
mIccManager = nullptr;
|
|
|
|
}
|
2012-08-27 21:34:10 +04:00
|
|
|
#endif
|
2012-04-20 01:33:25 +04:00
|
|
|
|
2012-02-20 19:15:19 +04:00
|
|
|
#ifdef MOZ_B2G_BT
|
|
|
|
if (mBluetooth) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mBluetooth = nullptr;
|
2012-02-20 19:15:19 +04:00
|
|
|
}
|
|
|
|
#endif
|
2012-07-03 04:16:55 +04:00
|
|
|
|
2012-07-31 01:59:05 +04:00
|
|
|
mCameraManager = nullptr;
|
|
|
|
|
2012-07-03 04:16:55 +04:00
|
|
|
if (mMessagesManager) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mMessagesManager = nullptr;
|
2012-07-03 04:16:55 +04:00
|
|
|
}
|
|
|
|
|
2012-11-30 02:52:03 +04:00
|
|
|
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
|
|
|
if (mAudioChannelManager) {
|
|
|
|
mAudioChannelManager = nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = mDeviceStorageStores.Length();
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2012-08-02 10:29:34 +04:00
|
|
|
mDeviceStorageStores[i]->Shutdown();
|
|
|
|
}
|
|
|
|
mDeviceStorageStores.Clear();
|
|
|
|
|
2012-09-11 10:05:00 +04:00
|
|
|
if (mTimeManager) {
|
|
|
|
mTimeManager = nullptr;
|
|
|
|
}
|
2013-11-20 03:14:07 +04:00
|
|
|
|
|
|
|
mServiceWorkerContainer = nullptr;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigator
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetUserAgent(nsAString& aUserAgent)
|
|
|
|
{
|
2014-09-24 14:40:43 +04:00
|
|
|
nsCOMPtr<nsIURI> codebaseURI;
|
2014-09-24 20:09:50 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window;
|
2014-09-24 14:40:43 +04:00
|
|
|
|
2014-09-24 20:09:50 +04:00
|
|
|
if (mWindow && mWindow->GetDocShell()) {
|
|
|
|
window = mWindow;
|
|
|
|
nsIDocument* doc = mWindow->GetExtantDoc();
|
|
|
|
if (doc) {
|
|
|
|
doc->NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
|
|
|
|
}
|
|
|
|
}
|
2014-09-24 14:40:43 +04:00
|
|
|
|
2014-09-24 20:09:50 +04:00
|
|
|
return GetUserAgent(window, codebaseURI, nsContentUtils::IsCallerChrome(),
|
|
|
|
aUserAgent);
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetAppCodeName(nsAString& aAppCodeName)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString appName;
|
2011-11-02 17:44:16 +04:00
|
|
|
rv = service->GetAppName(appName);
|
|
|
|
CopyASCIItoUTF16(appName, aAppCodeName);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetAppVersion(nsAString& aAppVersion)
|
|
|
|
{
|
2014-09-23 23:11:18 +04:00
|
|
|
return GetAppVersion(aAppVersion, /* aUsePrefOverriddenValue */ true);
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetAppName(nsAString& aAppName)
|
|
|
|
{
|
2014-09-23 23:11:18 +04:00
|
|
|
AppName(aAppName, /* aUsePrefOverriddenValue */ true);
|
2013-07-12 18:35:35 +04:00
|
|
|
return NS_OK;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-12 15:48:15 +04: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 17:44:16 +04:00
|
|
|
*
|
2014-05-12 15:48:15 +04:00
|
|
|
* "en", "en-US" and "i-cherokee" and "" are valid languages tokens.
|
2011-11-02 17:44:16 +04:00
|
|
|
*
|
2014-05-12 15:48:15 +04:00
|
|
|
* An empty array will be returned if there is no valid languages.
|
2011-11-02 17:44:16 +04:00
|
|
|
*/
|
2014-09-05 18:26:34 +04:00
|
|
|
/* static */ void
|
2014-05-12 15:48:15 +04:00
|
|
|
Navigator::GetAcceptLanguages(nsTArray<nsString>& aLanguages)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2014-09-05 18:26:34 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2014-10-08 16:56:50 +04:00
|
|
|
aLanguages.Clear();
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
// E.g. "de-de, en-us,en".
|
|
|
|
const nsAdoptingString& acceptLang =
|
|
|
|
Preferences::GetLocalizedString("intl.accept_languages");
|
|
|
|
|
2014-05-12 15:48:15 +04:00
|
|
|
// Split values on commas.
|
2011-11-02 17:44:16 +04:00
|
|
|
nsCharSeparatedTokenizer langTokenizer(acceptLang, ',');
|
2014-05-12 15:48:15 +04:00
|
|
|
while (langTokenizer.hasMoreTokens()) {
|
|
|
|
nsDependentSubstring lang = langTokenizer.nextToken();
|
2011-11-02 17:44:16 +04:00
|
|
|
|
2014-05-12 15:48:15 +04: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 17:44:16 +04:00
|
|
|
|
2014-05-12 15:48:15 +04:00
|
|
|
// Use uppercase for country part, e.g. "en-US", not "en-us", see BCP47
|
|
|
|
// only uppercase 2-letter country codes, not "zh-Hant", "de-DE-x-goethe".
|
|
|
|
// 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 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2014-05-12 15:48:15 +04:00
|
|
|
aLanguages.AppendElement(lang);
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
2014-05-12 15:48:15 +04:00
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
|
2014-05-12 15:48:15 +04: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 18:26:34 +04:00
|
|
|
return NS_OK;
|
2014-05-12 15:48:15 +04: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 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetPlatform(nsAString& aPlatform)
|
|
|
|
{
|
2014-09-23 23:11:18 +04:00
|
|
|
return GetPlatform(aPlatform, /* aUsePrefOverriddenValue */ true);
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetOscpu(nsAString& aOSCPU)
|
|
|
|
{
|
2012-10-26 03:10:53 +04:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2011-11-02 17:44:16 +04:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
Preferences::GetString("general.oscpu.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aOSCPU = override;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString oscpu;
|
2011-11-02 17:44:16 +04:00
|
|
|
rv = service->GetOscpu(oscpu);
|
|
|
|
CopyASCIItoUTF16(oscpu, aOSCPU);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetVendor(nsAString& aVendor)
|
|
|
|
{
|
|
|
|
aVendor.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetVendorSub(nsAString& aVendorSub)
|
|
|
|
{
|
|
|
|
aVendorSub.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetProduct(nsAString& aProduct)
|
|
|
|
{
|
2012-07-27 16:09:59 +04:00
|
|
|
aProduct.AssignLiteral("Gecko");
|
|
|
|
return NS_OK;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetProductSub(nsAString& aProductSub)
|
|
|
|
{
|
2012-07-27 16:09:59 +04:00
|
|
|
// Legacy build ID hardcoded for backward compatibility (bug 776376)
|
|
|
|
aProductSub.AssignLiteral("20100101");
|
|
|
|
return NS_OK;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
nsMimeTypeArray*
|
|
|
|
Navigator::GetMimeTypes(ErrorResult& aRv)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
|
|
|
if (!mMimeTypes) {
|
2013-07-12 18:35:35 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-08-29 00:55:29 +04:00
|
|
|
mMimeTypes = new nsMimeTypeArray(mWindow);
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
return mMimeTypes;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
nsPluginArray*
|
|
|
|
Navigator::GetPlugins(ErrorResult& aRv)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
|
|
|
if (!mPlugins) {
|
2013-07-12 18:35:35 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-08-29 00:55:29 +04:00
|
|
|
mPlugins = new nsPluginArray(mWindow);
|
2013-04-11 00:59:45 +04:00
|
|
|
mPlugins->Init();
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
return mPlugins;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Values for the network.cookie.cookieBehavior pref are documented in
|
|
|
|
// nsCookieService.cpp.
|
|
|
|
#define COOKIE_BEHAVIOR_REJECT 2
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
bool
|
|
|
|
Navigator::CookieEnabled()
|
|
|
|
{
|
|
|
|
bool cookieEnabled =
|
2011-11-02 17:44:16 +04:00
|
|
|
(Preferences::GetInt("network.cookie.cookieBehavior",
|
|
|
|
COOKIE_BEHAVIOR_REJECT) != COOKIE_BEHAVIOR_REJECT);
|
|
|
|
|
|
|
|
// Check whether an exception overrides the global cookie behavior
|
|
|
|
// Note that the code for getting the URI here matches that in
|
|
|
|
// nsHTMLDocument::SetCookie.
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
2013-07-12 18:35:35 +04:00
|
|
|
return cookieEnabled;
|
2011-12-01 12:28:16 +04:00
|
|
|
}
|
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = mWindow->GetExtantDoc();
|
2011-11-02 17:44:16 +04:00
|
|
|
if (!doc) {
|
2013-07-12 18:35:35 +04:00
|
|
|
return cookieEnabled;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> codebaseURI;
|
|
|
|
doc->NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
|
|
|
|
|
|
|
|
if (!codebaseURI) {
|
|
|
|
// Not a codebase, so technically can't set cookies, but let's
|
|
|
|
// just return the default value.
|
2013-07-12 18:35:35 +04:00
|
|
|
return cookieEnabled;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsICookiePermission> permMgr =
|
|
|
|
do_GetService(NS_COOKIEPERMISSION_CONTRACTID);
|
2013-07-12 18:35:35 +04:00
|
|
|
NS_ENSURE_TRUE(permMgr, cookieEnabled);
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
// Pass null for the channel, just like the cookie service does.
|
|
|
|
nsCookieAccess access;
|
2012-07-30 18:20:58 +04:00
|
|
|
nsresult rv = permMgr->CanAccess(codebaseURI, nullptr, &access);
|
2013-07-12 18:35:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, cookieEnabled);
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
if (access != nsICookiePermission::ACCESS_DEFAULT) {
|
2013-07-12 18:35:35 +04:00
|
|
|
cookieEnabled = access != nsICookiePermission::ACCESS_DENY;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
return cookieEnabled;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
bool
|
|
|
|
Navigator::OnLine()
|
|
|
|
{
|
2014-08-23 07:06:56 +04:00
|
|
|
if (mWindow && mWindow->GetDoc()) {
|
2014-08-27 06:25:47 +04:00
|
|
|
return !NS_IsOffline() &&
|
|
|
|
!NS_IsAppOffline(mWindow->GetDoc()->NodePrincipal());
|
2014-08-23 07:06:56 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
return !NS_IsOffline();
|
|
|
|
}
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetBuildID(nsAString& aBuildID)
|
|
|
|
{
|
2012-10-26 03:10:53 +04:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2011-11-02 17:44:16 +04:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
Preferences::GetString("general.buildID.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aBuildID = override;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXULAppInfo> appInfo =
|
|
|
|
do_GetService("@mozilla.org/xre/app-info;1");
|
|
|
|
if (!appInfo) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString buildID;
|
2011-11-02 17:44:16 +04:00
|
|
|
nsresult rv = appInfo->GetAppBuildID(buildID);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
aBuildID.Truncate();
|
|
|
|
AppendASCIItoUTF16(buildID, aBuildID);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetDoNotTrack(nsAString &aResult)
|
|
|
|
{
|
|
|
|
if (sDoNotTrackEnabled) {
|
2014-01-28 21:26:16 +04:00
|
|
|
aResult.AssignLiteral("1");
|
2011-11-02 17:44:16 +04:00
|
|
|
} else {
|
|
|
|
aResult.AssignLiteral("unspecified");
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
bool
|
|
|
|
Navigator::JavaEnabled(ErrorResult& aRv)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
|
|
|
Telemetry::AutoTimer<Telemetry::CHECK_JAVA_ENABLED> telemetryTimer;
|
2014-02-11 03:50:53 +04:00
|
|
|
|
|
|
|
// Return true if we have a handler for the java mime
|
|
|
|
nsAdoptingString javaMIME = Preferences::GetString("plugin.java.mime");
|
|
|
|
NS_ENSURE_TRUE(!javaMIME.IsEmpty(), false);
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
if (!mMimeTypes) {
|
2013-07-12 18:35:35 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return false;
|
|
|
|
}
|
2013-08-29 00:55:29 +04:00
|
|
|
mMimeTypes = new nsMimeTypeArray(mWindow);
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
RefreshMIMEArray();
|
|
|
|
|
2014-02-11 03:50:53 +04:00
|
|
|
nsMimeType *mimeType = mMimeTypes->NamedItem(javaMIME);
|
2011-11-02 15:04:28 +04:00
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
return mimeType && mimeType->GetEnabledPlugin();
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Navigator::RefreshMIMEArray()
|
|
|
|
{
|
|
|
|
if (mMimeTypes) {
|
2011-12-01 12:28:16 +04:00
|
|
|
mMimeTypes->Refresh();
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-11 01:26:36 +04:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class VibrateWindowListener : public nsIDOMEventListener
|
|
|
|
{
|
|
|
|
public:
|
2013-04-24 08:22:37 +04:00
|
|
|
VibrateWindowListener(nsIDOMWindow* aWindow, nsIDocument* aDocument)
|
2011-11-11 01:26:36 +04:00
|
|
|
{
|
|
|
|
mWindow = do_GetWeakReference(aWindow);
|
|
|
|
mDocument = do_GetWeakReference(aDocument);
|
|
|
|
|
2012-11-17 02:22:56 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(visibilitychange, "visibilitychange");
|
2013-04-24 08:22:37 +04:00
|
|
|
aDocument->AddSystemEventListener(visibilitychange,
|
|
|
|
this, /* listener */
|
|
|
|
true, /* use capture */
|
|
|
|
false /* wants untrusted */);
|
2011-11-11 01:26:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveListener();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
|
|
|
|
|
|
|
private:
|
2014-06-23 23:56:07 +04:00
|
|
|
virtual ~VibrateWindowListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-11-11 01:26:36 +04:00
|
|
|
nsWeakPtr mWindow;
|
|
|
|
nsWeakPtr mDocument;
|
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(VibrateWindowListener, nsIDOMEventListener)
|
2011-11-11 01:26:36 +04:00
|
|
|
|
2012-07-26 23:33:45 +04:00
|
|
|
StaticRefPtr<VibrateWindowListener> gVibrateWindowListener;
|
2011-11-11 01:26:36 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
VibrateWindowListener::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
2013-04-20 02:18:32 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc =
|
|
|
|
do_QueryInterface(aEvent->InternalDOMEvent()->GetTarget());
|
2011-11-11 01:26:36 +04:00
|
|
|
|
2013-04-20 02:18:32 +04:00
|
|
|
if (!doc || doc->Hidden()) {
|
2011-11-11 01:26:36 +04:00
|
|
|
// It's important that we call CancelVibrate(), not Vibrate() with an
|
|
|
|
// empty list, because Vibrate() will fail if we're no longer focused, but
|
|
|
|
// CancelVibrate() will succeed, so long as nobody else has started a new
|
|
|
|
// vibration pattern.
|
|
|
|
nsCOMPtr<nsIDOMWindow> window = do_QueryReferent(mWindow);
|
|
|
|
hal::CancelVibrate(window);
|
|
|
|
RemoveListener();
|
2013-10-28 18:04:12 +04:00
|
|
|
gVibrateWindowListener = nullptr;
|
2011-11-11 01:26:36 +04:00
|
|
|
// Careful: The line above might have deleted |this|!
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VibrateWindowListener::RemoveListener()
|
|
|
|
{
|
2013-04-20 02:18:32 +04:00
|
|
|
nsCOMPtr<EventTarget> target = do_QueryReferent(mDocument);
|
2011-11-11 01:26:36 +04:00
|
|
|
if (!target) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-17 02:22:56 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(visibilitychange, "visibilitychange");
|
2011-11-11 01:26:36 +04:00
|
|
|
target->RemoveSystemEventListener(visibilitychange, this,
|
|
|
|
true /* use capture */);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
void
|
|
|
|
Navigator::AddIdleObserver(MozIdleObserver& aIdleObserver, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CallbackObjectHolder<MozIdleObserver, nsIIdleObserver> holder(&aIdleObserver);
|
|
|
|
nsCOMPtr<nsIIdleObserver> obs = holder.ToXPCOMCallback();
|
2013-07-18 07:23:52 +04:00
|
|
|
if (NS_FAILED(mWindow->RegisterIdleObserver(obs))) {
|
|
|
|
NS_WARNING("Failed to add idle observer.");
|
2013-07-12 18:35:35 +04:00
|
|
|
}
|
|
|
|
}
|
2011-11-11 01:26:36 +04:00
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
void
|
|
|
|
Navigator::RemoveIdleObserver(MozIdleObserver& aIdleObserver, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
2011-11-11 01:26:36 +04:00
|
|
|
}
|
2013-07-12 18:35:35 +04:00
|
|
|
CallbackObjectHolder<MozIdleObserver, nsIIdleObserver> holder(&aIdleObserver);
|
|
|
|
nsCOMPtr<nsIIdleObserver> obs = holder.ToXPCOMCallback();
|
2013-07-18 07:23:52 +04:00
|
|
|
if (NS_FAILED(mWindow->UnregisterIdleObserver(obs))) {
|
|
|
|
NS_WARNING("Failed to remove idle observer.");
|
2011-11-11 01:26:36 +04:00
|
|
|
}
|
2013-07-12 18:35:35 +04:00
|
|
|
}
|
|
|
|
|
2013-09-28 22:58:38 +04:00
|
|
|
bool
|
|
|
|
Navigator::Vibrate(uint32_t aDuration)
|
2013-07-12 18:35:35 +04:00
|
|
|
{
|
|
|
|
nsAutoTArray<uint32_t, 1> pattern;
|
|
|
|
pattern.AppendElement(aDuration);
|
2013-09-28 22:58:38 +04:00
|
|
|
return Vibrate(pattern);
|
2013-07-12 18:35:35 +04:00
|
|
|
}
|
|
|
|
|
2013-09-28 22:58:38 +04:00
|
|
|
bool
|
|
|
|
Navigator::Vibrate(const nsTArray<uint32_t>& aPattern)
|
2013-07-12 18:35:35 +04:00
|
|
|
{
|
|
|
|
if (!mWindow) {
|
2013-09-28 22:58:38 +04:00
|
|
|
return false;
|
2013-07-12 18:35:35 +04:00
|
|
|
}
|
2013-09-28 22:58:38 +04:00
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = mWindow->GetExtantDoc();
|
|
|
|
if (!doc) {
|
2013-09-28 22:58:38 +04:00
|
|
|
return false;
|
2013-07-12 18:35:35 +04:00
|
|
|
}
|
2013-09-28 22:58:38 +04:00
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
if (doc->Hidden()) {
|
|
|
|
// Hidden documents cannot start or stop a vibration.
|
2013-09-28 22:58:38 +04:00
|
|
|
return false;
|
2013-07-12 18:35:35 +04:00
|
|
|
}
|
|
|
|
|
2014-05-28 00:54:03 +04:00
|
|
|
nsTArray<uint32_t> pattern(aPattern);
|
|
|
|
|
|
|
|
if (pattern.Length() > sMaxVibrateListLen) {
|
2014-06-07 16:40:20 +04:00
|
|
|
pattern.SetLength(sMaxVibrateListLen);
|
2013-07-12 18:35:35 +04:00
|
|
|
}
|
|
|
|
|
2014-05-28 00:54:03 +04:00
|
|
|
for (size_t i = 0; i < pattern.Length(); ++i) {
|
|
|
|
if (pattern[i] > sMaxVibrateMS) {
|
|
|
|
pattern[i] = sMaxVibrateMS;
|
2013-07-12 18:35:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-11 01:26:36 +04:00
|
|
|
// The spec says we check sVibratorEnabled after we've done the sanity
|
|
|
|
// checking on the pattern.
|
2014-07-10 18:31:36 +04:00
|
|
|
if (!sVibratorEnabled) {
|
2013-09-28 22:58:38 +04:00
|
|
|
return true;
|
2011-11-11 01:26:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add a listener to cancel the vibration if the document becomes hidden,
|
2012-11-17 02:22:56 +04:00
|
|
|
// and remove the old visibility listener, if there was one.
|
2011-11-11 01:26:36 +04:00
|
|
|
|
|
|
|
if (!gVibrateWindowListener) {
|
|
|
|
// If gVibrateWindowListener is null, this is the first time we've vibrated,
|
|
|
|
// and we need to register a listener to clear gVibrateWindowListener on
|
|
|
|
// shutdown.
|
|
|
|
ClearOnShutdown(&gVibrateWindowListener);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gVibrateWindowListener->RemoveListener();
|
|
|
|
}
|
2013-06-20 22:34:38 +04:00
|
|
|
gVibrateWindowListener = new VibrateWindowListener(mWindow, doc);
|
2011-11-11 01:26:36 +04:00
|
|
|
|
2014-05-28 00:54:03 +04:00
|
|
|
hal::Vibrate(pattern, mWindow);
|
2013-09-28 22:58:38 +04:00
|
|
|
return true;
|
2011-11-11 01:26:36 +04:00
|
|
|
}
|
|
|
|
|
2014-01-28 20:09:34 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
// Pointer Events interface
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Navigator::MaxTouchPoints()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWidget> widget = widget::WidgetUtils::DOMWindowToWidget(mWindow);
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(widget, 0);
|
|
|
|
return widget->GetMaxTouchPoints();
|
|
|
|
}
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMClientInformation
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
void
|
2011-11-02 17:44:16 +04:00
|
|
|
Navigator::RegisterContentHandler(const nsAString& aMIMEType,
|
|
|
|
const nsAString& aURI,
|
2013-07-18 07:23:52 +04:00
|
|
|
const nsAString& aTitle,
|
|
|
|
ErrorResult& aRv)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
2013-07-18 07:23:52 +04:00
|
|
|
return;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebContentHandlerRegistrar> registrar =
|
|
|
|
do_GetService(NS_WEBCONTENTHANDLERREGISTRAR_CONTRACTID);
|
|
|
|
if (!registrar) {
|
2013-07-18 07:23:52 +04:00
|
|
|
return;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
aRv = registrar->RegisterContentHandler(aMIMEType, aURI, aTitle,
|
|
|
|
mWindow->GetOuterWindow());
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
void
|
2011-11-02 17:44:16 +04:00
|
|
|
Navigator::RegisterProtocolHandler(const nsAString& aProtocol,
|
|
|
|
const nsAString& aURI,
|
2013-07-18 07:23:52 +04:00
|
|
|
const nsAString& aTitle,
|
|
|
|
ErrorResult& aRv)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
2013-07-18 07:23:52 +04:00
|
|
|
return;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebContentHandlerRegistrar> registrar =
|
|
|
|
do_GetService(NS_WEBCONTENTHANDLERREGISTRAR_CONTRACTID);
|
|
|
|
if (!registrar) {
|
2013-07-18 07:23:52 +04:00
|
|
|
return;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
aRv = registrar->RegisterProtocolHandler(aProtocol, aURI, aTitle,
|
|
|
|
mWindow->GetOuterWindow());
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
nsDOMDeviceStorage*
|
|
|
|
Navigator::GetDeviceStorage(const nsAString& aType, ErrorResult& aRv)
|
|
|
|
{
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
2013-07-12 18:35:44 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2013-05-11 13:10:18 +04:00
|
|
|
}
|
2013-05-11 17:47:37 +04:00
|
|
|
|
2013-05-11 13:10:18 +04:00
|
|
|
nsRefPtr<nsDOMDeviceStorage> storage;
|
2013-06-20 22:34:38 +04:00
|
|
|
nsDOMDeviceStorage::CreateDeviceStorageFor(mWindow, aType,
|
|
|
|
getter_AddRefs(storage));
|
2013-05-11 17:47:37 +04:00
|
|
|
|
2013-05-11 13:10:18 +04:00
|
|
|
if (!storage) {
|
2013-07-12 18:35:44 +04:00
|
|
|
return nullptr;
|
2013-04-02 23:52:21 +04:00
|
|
|
}
|
|
|
|
|
2013-05-11 13:10:18 +04:00
|
|
|
mDeviceStorageStores.AppendElement(storage);
|
2013-07-12 18:35:44 +04:00
|
|
|
return storage;
|
2013-04-02 23:52:21 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
void
|
|
|
|
Navigator::GetDeviceStorages(const nsAString& aType,
|
|
|
|
nsTArray<nsRefPtr<nsDOMDeviceStorage> >& aStores,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-03 03:34:59 +04:00
|
|
|
nsDOMDeviceStorage::CreateDeviceStoragesFor(mWindow, aType, aStores);
|
2013-07-12 18:35:44 +04:00
|
|
|
|
|
|
|
mDeviceStorageStores.AppendElements(aStores);
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
Geolocation*
|
|
|
|
Navigator::GetGeolocation(ErrorResult& aRv)
|
|
|
|
{
|
2011-11-02 17:44:16 +04:00
|
|
|
if (mGeolocation) {
|
2013-07-12 18:35:35 +04:00
|
|
|
return mGeolocation;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
2013-07-12 18:35:35 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-04-12 22:47:47 +04:00
|
|
|
mGeolocation = new Geolocation();
|
2013-06-20 22:34:38 +04:00
|
|
|
if (NS_FAILED(mGeolocation->Init(mWindow->GetOuterWindow()))) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mGeolocation = nullptr;
|
2013-07-12 18:35:35 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
return mGeolocation;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2014-03-06 19:51:23 +04:00
|
|
|
class BeaconStreamListener MOZ_FINAL : public nsIStreamListener
|
|
|
|
{
|
2014-06-23 23:56:07 +04:00
|
|
|
~BeaconStreamListener() {}
|
|
|
|
|
2014-03-06 19:51:23 +04:00
|
|
|
public:
|
|
|
|
BeaconStreamListener() {}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(BeaconStreamListener,
|
|
|
|
nsIStreamListener,
|
|
|
|
nsIRequestObserver)
|
2014-03-06 19:51:23 +04: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 15:49:12 +04:00
|
|
|
doc,
|
|
|
|
nsILoadInfo::SEC_NORMAL,
|
2014-10-16 06:11:45 +04:00
|
|
|
nsIContentPolicy::TYPE_BEACON);
|
2014-09-22 15:49:12 +04:00
|
|
|
|
2014-03-06 19:51:23 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-26 08:15:14 +04: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 19:51:23 +04: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 11:30:26 +04:00
|
|
|
|
2014-03-06 19:51:23 +04: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 11:30:26 +04:00
|
|
|
|
2014-03-06 19:51:23 +04:00
|
|
|
} else if (aData.Value().IsArrayBufferView()) {
|
2014-04-16 11:30:26 +04:00
|
|
|
|
2014-03-06 19:51:23 +04:00
|
|
|
nsCOMPtr<nsIStringInputStream> strStream = do_CreateInstance(NS_STRINGINPUTSTREAM_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-16 11:30:26 +04:00
|
|
|
|
2014-06-24 00:03:57 +04: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-28 01:32:41 +04:00
|
|
|
view.ComputeLengthAndData();
|
|
|
|
rv = strStream->SetData(reinterpret_cast<char*>(view.Data()),
|
|
|
|
view.Length());
|
2014-04-16 11:30:26 +04:00
|
|
|
|
2014-03-06 19:51:23 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mimeType.AssignLiteral("application/octet-stream");
|
|
|
|
in = strStream;
|
2014-04-16 11:30:26 +04:00
|
|
|
|
2014-03-06 19:51:23 +04:00
|
|
|
} else if (aData.Value().IsBlob()) {
|
2014-10-08 20:15:23 +04:00
|
|
|
File& blob = aData.Value().GetAsBlob();
|
2014-10-08 20:15:22 +04:00
|
|
|
rv = blob.GetInternalStream(getter_AddRefs(in));
|
2014-03-06 19:51:23 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsAutoString type;
|
2014-10-08 20:15:22 +04:00
|
|
|
rv = blob.GetType(type);
|
2014-03-06 19:51:23 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mimeType = NS_ConvertUTF16toUTF8(type);
|
2014-04-16 11:30:26 +04:00
|
|
|
|
2014-03-06 19:51:23 +04: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 11:30:26 +04:00
|
|
|
|
2014-03-06 19:51:23 +04: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 11:30:26 +04:00
|
|
|
if (crossOrigin &&
|
2014-03-06 19:51:23 +04: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 11:35:15 +04:00
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
2014-09-20 10:20:41 +04:00
|
|
|
MediaDevices*
|
|
|
|
Navigator::GetMediaDevices(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mMediaDevices) {
|
|
|
|
if (!mWindow ||
|
|
|
|
!mWindow->GetOuterWindow() ||
|
|
|
|
mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
mMediaDevices = new MediaDevices(mWindow);
|
|
|
|
}
|
|
|
|
return mMediaDevices;
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:37:21 +04:00
|
|
|
void
|
2014-04-18 22:00:16 +04:00
|
|
|
Navigator::MozGetUserMedia(const MediaStreamConstraints& aConstraints,
|
2013-09-16 10:34:57 +04:00
|
|
|
NavigatorUserMediaSuccessCallback& aOnSuccess,
|
|
|
|
NavigatorUserMediaErrorCallback& aOnError,
|
2013-07-12 18:37:21 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2013-09-16 10:34:57 +04:00
|
|
|
CallbackObjectHolder<NavigatorUserMediaSuccessCallback,
|
|
|
|
nsIDOMGetUserMediaSuccessCallback> holder1(&aOnSuccess);
|
2013-07-18 07:23:52 +04:00
|
|
|
nsCOMPtr<nsIDOMGetUserMediaSuccessCallback> onsuccess =
|
2013-07-12 18:37:21 +04:00
|
|
|
holder1.ToXPCOMCallback();
|
|
|
|
|
2013-09-16 10:34:57 +04:00
|
|
|
CallbackObjectHolder<NavigatorUserMediaErrorCallback,
|
|
|
|
nsIDOMGetUserMediaErrorCallback> holder2(&aOnError);
|
2013-07-12 18:37:21 +04:00
|
|
|
nsCOMPtr<nsIDOMGetUserMediaErrorCallback> onerror = holder2.ToXPCOMCallback();
|
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() ||
|
|
|
|
mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) {
|
2013-07-12 18:37:21 +04:00
|
|
|
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return;
|
2012-09-20 23:54:00 +04:00
|
|
|
}
|
2012-06-03 11:35:15 +04:00
|
|
|
|
2012-09-20 23:54:00 +04:00
|
|
|
MediaManager* manager = MediaManager::Get();
|
2014-10-01 03:17:53 +04:00
|
|
|
aRv = manager->GetUserMedia(mWindow, aConstraints, onsuccess, onerror);
|
2013-07-12 18:37:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-18 22:00:16 +04:00
|
|
|
Navigator::MozGetUserMediaDevices(const MediaStreamConstraints& aConstraints,
|
2013-09-16 10:34:57 +04:00
|
|
|
MozGetUserMediaDevicesSuccessCallback& aOnSuccess,
|
|
|
|
NavigatorUserMediaErrorCallback& aOnError,
|
2014-02-14 23:32:58 +04:00
|
|
|
uint64_t aInnerWindowID,
|
2013-07-12 18:37:21 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
CallbackObjectHolder<MozGetUserMediaDevicesSuccessCallback,
|
2013-09-16 10:34:57 +04:00
|
|
|
nsIGetUserMediaDevicesSuccessCallback> holder1(&aOnSuccess);
|
2013-07-18 07:23:52 +04:00
|
|
|
nsCOMPtr<nsIGetUserMediaDevicesSuccessCallback> onsuccess =
|
2013-07-12 18:37:21 +04:00
|
|
|
holder1.ToXPCOMCallback();
|
|
|
|
|
2013-09-16 10:34:57 +04:00
|
|
|
CallbackObjectHolder<NavigatorUserMediaErrorCallback,
|
|
|
|
nsIDOMGetUserMediaErrorCallback> holder2(&aOnError);
|
2013-07-12 18:37:21 +04:00
|
|
|
nsCOMPtr<nsIDOMGetUserMediaErrorCallback> onerror = holder2.ToXPCOMCallback();
|
|
|
|
|
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() ||
|
|
|
|
mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-20 23:54:00 +04:00
|
|
|
MediaManager* manager = MediaManager::Get();
|
2014-02-14 23:32:58 +04:00
|
|
|
aRv = manager->GetUserMediaDevices(mWindow, aConstraints, onsuccess, onerror,
|
|
|
|
aInnerWindowID);
|
2012-06-03 11:35:15 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
DesktopNotificationCenter*
|
|
|
|
Navigator::GetMozNotification(ErrorResult& aRv)
|
|
|
|
{
|
2011-11-02 17:44:16 +04:00
|
|
|
if (mNotification) {
|
2013-07-12 18:35:44 +04:00
|
|
|
return mNotification;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
mNotification = new DesktopNotificationCenter(mWindow);
|
2013-07-12 18:35:44 +04:00
|
|
|
return mNotification;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-09-04 02:26:33 +04:00
|
|
|
#ifdef MOZ_B2G_FM
|
|
|
|
|
|
|
|
using mozilla::dom::FMRadio;
|
|
|
|
|
|
|
|
FMRadio*
|
|
|
|
Navigator::GetMozFMRadio(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mFMRadio) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
|
|
|
|
|
|
|
mFMRadio = new FMRadio();
|
|
|
|
mFMRadio->Init(mWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mFMRadio;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MOZ_B2G_FM
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsINavigatorBattery
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
battery::BatteryManager*
|
|
|
|
Navigator::GetBattery(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mBatteryManager) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
2011-11-19 14:37:21 +04:00
|
|
|
|
2014-01-07 06:53:23 +04:00
|
|
|
mBatteryManager = new battery::BatteryManager(mWindow);
|
|
|
|
mBatteryManager->Init();
|
2011-11-02 19:01:32 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
return mBatteryManager;
|
2011-11-02 16:04:39 +04:00
|
|
|
}
|
|
|
|
|
2014-02-24 17:57:15 +04:00
|
|
|
/* static */ already_AddRefed<Promise>
|
|
|
|
Navigator::GetDataStores(nsPIDOMWindow* aWindow,
|
|
|
|
const nsAString& aName,
|
2014-07-17 07:53:23 +04:00
|
|
|
const nsAString& aOwner,
|
2014-02-24 17:57:15 +04:00
|
|
|
ErrorResult& aRv)
|
2013-10-02 21:27:07 +04:00
|
|
|
{
|
2014-02-24 17:57:15 +04:00
|
|
|
if (!aWindow || !aWindow->GetDocShell()) {
|
2013-10-02 21:27:07 +04:00
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-03 18:36:46 +04:00
|
|
|
nsRefPtr<DataStoreService> service = DataStoreService::GetOrCreate();
|
2013-10-02 21:27:07 +04:00
|
|
|
if (!service) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> promise;
|
2014-07-17 07:53:23 +04:00
|
|
|
aRv = service->GetDataStores(aWindow, aName, aOwner, getter_AddRefs(promise));
|
2013-10-02 21:27:07 +04:00
|
|
|
|
|
|
|
nsRefPtr<Promise> p = static_cast<Promise*>(promise.get());
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
2014-02-24 17:57:15 +04:00
|
|
|
already_AddRefed<Promise>
|
2014-07-17 07:53:23 +04:00
|
|
|
Navigator::GetDataStores(const nsAString& aName,
|
|
|
|
const nsAString& aOwner,
|
|
|
|
ErrorResult& aRv)
|
2014-02-24 17:57:15 +04:00
|
|
|
{
|
2014-07-17 07:53:23 +04:00
|
|
|
return GetDataStores(mWindow, aName, aOwner, aRv);
|
2014-02-24 17:57:15 +04:00
|
|
|
}
|
|
|
|
|
2014-05-12 06:05:03 +04:00
|
|
|
already_AddRefed<Promise>
|
2014-07-19 05:31:11 +04:00
|
|
|
Navigator::GetFeature(const nsAString& aName, ErrorResult& aRv)
|
2014-05-12 06:05:03 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(mWindow);
|
2014-07-19 05:31:11 +04:00
|
|
|
nsRefPtr<Promise> p = Promise::Create(go, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-05-12 06:05:03 +04:00
|
|
|
|
|
|
|
#if defined(XP_LINUX)
|
|
|
|
if (aName.EqualsLiteral("hardware.memory")) {
|
2014-05-21 09:49:36 +04: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 19:38:38 +04:00
|
|
|
p->MaybeReject(NS_ERROR_NOT_AVAILABLE);
|
2014-05-12 06:05:03 +04:00
|
|
|
return p.forget();
|
|
|
|
}
|
2014-05-21 09:49:36 +04: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 06:05:03 +04:00
|
|
|
}
|
2014-05-21 09:49:36 +04:00
|
|
|
return p.forget();
|
2014-05-12 06:05:03 +04:00
|
|
|
} // hardware.memory
|
|
|
|
#endif
|
2014-07-10 01:05:29 +04: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 23:57:02 +04: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-15 03:08:45 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(apiWindowPrefix, "api.window.");
|
|
|
|
if (StringBeginsWith(aName, apiWindowPrefix)) {
|
2014-07-15 23:15:28 +04:00
|
|
|
const nsAString& featureName = Substring(aName, apiWindowPrefix.Length());
|
2014-07-24 23:57:02 +04: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 13:24:03 +04:00
|
|
|
#endif
|
2014-07-24 23:57:02 +04:00
|
|
|
|
|
|
|
if (featureName.EqualsLiteral("XMLHttpRequest.mozSystem")) {
|
|
|
|
p->MaybeResolve(true);
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
2014-07-15 03:08:45 +04:00
|
|
|
if (IsFeatureDetectible(featureName)) {
|
|
|
|
p->MaybeResolve(true);
|
|
|
|
} else {
|
|
|
|
p->MaybeResolve(JS::UndefinedHandleValue);
|
|
|
|
}
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
2014-05-21 09:49:36 +04:00
|
|
|
// resolve with <undefined> because the feature name is not supported
|
|
|
|
p->MaybeResolve(JS::UndefinedHandleValue);
|
2014-05-12 06:05:03 +04:00
|
|
|
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
2013-09-11 18:35:04 +04:00
|
|
|
PowerManager*
|
2013-07-12 18:35:35 +04:00
|
|
|
Navigator::GetMozPower(ErrorResult& aRv)
|
|
|
|
{
|
2012-01-20 07:24:00 +04:00
|
|
|
if (!mPowerManager) {
|
2013-07-12 18:35:35 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
mPowerManager = PowerManager::CreateInstance(mWindow);
|
|
|
|
if (!mPowerManager) {
|
|
|
|
// We failed to get the power manager service?
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
2012-01-20 07:24:00 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
return mPowerManager;
|
2012-01-20 07:24:00 +04:00
|
|
|
}
|
|
|
|
|
2014-01-07 16:16:07 +04:00
|
|
|
already_AddRefed<WakeLock>
|
2013-07-12 18:35:35 +04:00
|
|
|
Navigator::RequestWakeLock(const nsAString &aTopic, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-03-07 15:03:25 +04:00
|
|
|
|
2014-01-07 16:16:07 +04:00
|
|
|
nsRefPtr<power::PowerManagerService> pmService =
|
|
|
|
power::PowerManagerService::GetInstance();
|
2013-07-12 18:35:35 +04:00
|
|
|
// Maybe it went away for some reason... Or maybe we're just called
|
|
|
|
// from our XPCOM method.
|
2014-01-24 13:40:40 +04:00
|
|
|
if (!pmService) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-03-07 15:03:25 +04:00
|
|
|
|
2014-01-24 13:40:40 +04:00
|
|
|
return pmService->NewWakeLock(aTopic, mWindow, aRv);
|
2012-03-07 15:03:25 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
MobileMessageManager*
|
2013-07-12 18:35:44 +04:00
|
|
|
Navigator::GetMozMobileMessage()
|
|
|
|
{
|
2013-03-09 11:21:47 +04:00
|
|
|
if (!mMobileMessageManager) {
|
2013-07-12 18:35:44 +04:00
|
|
|
// Check that our window has not gone away
|
|
|
|
NS_ENSURE_TRUE(mWindow, nullptr);
|
|
|
|
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
2013-03-09 11:21:47 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
mMobileMessageManager = new MobileMessageManager(mWindow);
|
|
|
|
mMobileMessageManager->Init();
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
return mMobileMessageManager;
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2013-10-29 12:12:38 +04:00
|
|
|
Telephony*
|
|
|
|
Navigator::GetMozTelephony(ErrorResult& aRv)
|
2013-07-12 18:36:22 +04:00
|
|
|
{
|
2013-10-29 12:12:38 +04:00
|
|
|
if (!mTelephony) {
|
2013-07-12 18:36:22 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
2012-12-04 06:38:25 +04:00
|
|
|
}
|
2013-10-29 12:12:38 +04:00
|
|
|
mTelephony = Telephony::Create(mWindow, aRv);
|
2012-12-04 06:38:25 +04:00
|
|
|
}
|
|
|
|
|
2013-10-29 12:12:38 +04:00
|
|
|
return mTelephony;
|
2012-12-04 06:38:25 +04:00
|
|
|
}
|
|
|
|
|
2014-06-07 21:30:18 +04:00
|
|
|
#ifdef MOZ_B2G
|
|
|
|
already_AddRefed<Promise>
|
2014-06-27 03:18:21 +04:00
|
|
|
Navigator::GetMobileIdAssertion(const MobileIdOptions& aOptions,
|
|
|
|
ErrorResult& aRv)
|
2014-06-07 21:30:18 +04: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-27 03:18:21 +04: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 21:30:18 +04:00
|
|
|
nsCOMPtr<nsISupports> promise;
|
2014-06-27 03:18:21 +04:00
|
|
|
aRv = service->GetMobileIdAssertion(mWindow,
|
|
|
|
optionsValue,
|
|
|
|
getter_AddRefs(promise));
|
2014-06-07 21:30:18 +04:00
|
|
|
|
|
|
|
nsRefPtr<Promise> p = static_cast<Promise*>(promise.get());
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
#endif // MOZ_B2G
|
|
|
|
|
2013-10-29 12:12:38 +04:00
|
|
|
#ifdef MOZ_B2G_RIL
|
|
|
|
|
2014-01-02 07:06:17 +04:00
|
|
|
MobileConnectionArray*
|
2013-11-13 12:51:23 +04:00
|
|
|
Navigator::GetMozMobileConnections(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mMobileConnections) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-01-02 07:06:17 +04:00
|
|
|
mMobileConnections = new MobileConnectionArray(mWindow);
|
2013-11-13 12:51:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return mMobileConnections;
|
|
|
|
}
|
|
|
|
|
2014-08-25 13:24:03 +04:00
|
|
|
#endif // MOZ_B2G_RIL
|
|
|
|
|
2013-10-29 12:12:38 +04:00
|
|
|
CellBroadcast*
|
|
|
|
Navigator::GetMozCellBroadcast(ErrorResult& aRv)
|
2013-07-12 18:36:13 +04:00
|
|
|
{
|
2013-10-29 12:12:38 +04:00
|
|
|
if (!mCellBroadcast) {
|
2013-07-12 18:36:13 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-10-29 12:12:38 +04:00
|
|
|
mCellBroadcast = CellBroadcast::Create(mWindow, aRv);
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
2013-10-29 12:12:38 +04:00
|
|
|
return mCellBroadcast;
|
2012-01-10 02:28:47 +04:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:38:53 +04:00
|
|
|
Voicemail*
|
2013-07-12 18:36:22 +04:00
|
|
|
Navigator::GetMozVoicemail(ErrorResult& aRv)
|
|
|
|
{
|
2012-07-19 07:27:19 +04:00
|
|
|
if (!mVoicemail) {
|
2013-07-12 18:36:22 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
2012-07-19 07:27:19 +04:00
|
|
|
}
|
|
|
|
|
2014-09-26 09:00:24 +04:00
|
|
|
mVoicemail = Voicemail::Create(mWindow, aRv);
|
2012-07-19 07:27:19 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:36:22 +04:00
|
|
|
return mVoicemail;
|
2012-07-19 07:27:19 +04:00
|
|
|
}
|
|
|
|
|
2014-09-26 09:00:23 +04:00
|
|
|
#ifdef MOZ_B2G_RIL
|
|
|
|
|
2014-04-16 11:30:28 +04:00
|
|
|
IccManager*
|
2013-07-12 18:36:22 +04:00
|
|
|
Navigator::GetMozIccManager(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mIccManager) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
2013-04-08 14:34:10 +04:00
|
|
|
}
|
2013-07-12 18:36:22 +04:00
|
|
|
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
2013-04-08 14:34:10 +04:00
|
|
|
|
2013-10-09 13:40:12 +04:00
|
|
|
mIccManager = new IccManager(mWindow);
|
2013-04-08 14:34:10 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:36:22 +04:00
|
|
|
return mIccManager;
|
2013-04-08 14:34:10 +04:00
|
|
|
}
|
2012-01-10 02:28:47 +04:00
|
|
|
#endif // MOZ_B2G_RIL
|
|
|
|
|
2012-02-16 04:47:13 +04:00
|
|
|
#ifdef MOZ_GAMEPAD
|
2013-07-12 18:36:32 +04:00
|
|
|
void
|
|
|
|
Navigator::GetGamepads(nsTArray<nsRefPtr<Gamepad> >& aGamepads,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE_VOID(mWindow->GetDocShell());
|
|
|
|
nsGlobalWindow* win = static_cast<nsGlobalWindow*>(mWindow.get());
|
2013-12-06 15:52:06 +04:00
|
|
|
win->SetHasGamepadEventListener(true);
|
2013-07-12 18:36:32 +04:00
|
|
|
win->GetGamepads(aGamepads);
|
|
|
|
}
|
2012-02-16 04:47:13 +04:00
|
|
|
#endif
|
|
|
|
|
2012-01-16 16:23:28 +04:00
|
|
|
//*****************************************************************************
|
2013-07-18 07:23:52 +04:00
|
|
|
// Navigator::nsIMozNavigatorNetwork
|
2012-01-16 16:23:28 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-05 07:54:55 +04:00
|
|
|
Navigator::GetProperties(nsINetworkProperties** aProperties)
|
2012-01-16 16:23:28 +04:00
|
|
|
{
|
2014-03-05 07:54:55 +04:00
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aProperties = GetConnection(rv));
|
2013-07-12 18:35:44 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-01-16 21:14:56 +04:00
|
|
|
|
2014-01-16 14:53:48 +04:00
|
|
|
network::Connection*
|
2014-03-05 07:54:55 +04:00
|
|
|
Navigator::GetConnection(ErrorResult& aRv)
|
2013-07-12 18:35:44 +04:00
|
|
|
{
|
2012-01-16 16:23:44 +04:00
|
|
|
if (!mConnection) {
|
2014-03-05 07:54:55 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-10-07 13:44:48 +04:00
|
|
|
mConnection = new network::Connection(mWindow);
|
2012-01-16 16:23:44 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
return mConnection;
|
2012-01-16 16:23:28 +04:00
|
|
|
}
|
|
|
|
|
2012-02-20 19:15:19 +04:00
|
|
|
#ifdef MOZ_B2G_BT
|
2013-08-12 12:31:58 +04:00
|
|
|
bluetooth::BluetoothManager*
|
2013-07-12 18:36:32 +04:00
|
|
|
Navigator::GetMozBluetooth(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mBluetooth) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
mBluetooth = bluetooth::BluetoothManager::Create(mWindow);
|
2012-02-20 19:15:19 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:36:32 +04:00
|
|
|
return mBluetooth;
|
2012-02-20 19:15:19 +04:00
|
|
|
}
|
|
|
|
#endif //MOZ_B2G_BT
|
|
|
|
|
2012-07-23 10:53:08 +04:00
|
|
|
nsresult
|
2012-07-03 04:16:55 +04:00
|
|
|
Navigator::EnsureMessagesManager()
|
|
|
|
{
|
|
|
|
if (mMessagesManager) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
NS_ENSURE_STATE(mWindow);
|
2012-07-03 04:16:55 +04:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMNavigatorSystemMessages> messageManager =
|
|
|
|
do_CreateInstance("@mozilla.org/system-message-manager;1", &rv);
|
2013-08-12 12:31:58 +04:00
|
|
|
|
2012-07-03 04:16:55 +04:00
|
|
|
nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi =
|
|
|
|
do_QueryInterface(messageManager);
|
|
|
|
NS_ENSURE_TRUE(gpi, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// We don't do anything with the return value.
|
2013-05-30 00:16:04 +04:00
|
|
|
AutoJSContext cx;
|
|
|
|
JS::Rooted<JS::Value> prop_val(cx);
|
2014-01-09 21:39:36 +04:00
|
|
|
rv = gpi->Init(mWindow, &prop_val);
|
2012-07-03 04:16:55 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mMessagesManager = messageManager.forget();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
bool
|
|
|
|
Navigator::MozHasPendingMessage(const nsAString& aType, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// The WebIDL binding is responsible for the pref check here.
|
2012-07-03 04:16:55 +04:00
|
|
|
nsresult rv = EnsureMessagesManager();
|
2013-07-12 18:35:44 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-03 04:16:55 +04:00
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
bool result = false;
|
|
|
|
rv = mMessagesManager->MozHasPendingMessage(aType, &result);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return result;
|
2012-07-03 04:16:55 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
void
|
|
|
|
Navigator::MozSetMessageHandler(const nsAString& aType,
|
|
|
|
systemMessageCallback* aCallback,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// The WebIDL binding is responsible for the pref check here.
|
|
|
|
nsresult rv = EnsureMessagesManager();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CallbackObjectHolder<systemMessageCallback, nsIDOMSystemMessageCallback>
|
|
|
|
holder(aCallback);
|
|
|
|
nsCOMPtr<nsIDOMSystemMessageCallback> callback = holder.ToXPCOMCallback();
|
|
|
|
|
|
|
|
rv = mMessagesManager->MozSetMessageHandler(aType, callback);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-05 19:20:03 +04:00
|
|
|
#ifdef MOZ_TIME_MANAGER
|
2013-07-12 18:36:32 +04:00
|
|
|
time::TimeManager*
|
|
|
|
Navigator::GetMozTime(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-09-11 10:05:00 +04:00
|
|
|
if (!mTimeManager) {
|
2013-06-20 22:34:38 +04:00
|
|
|
mTimeManager = new time::TimeManager(mWindow);
|
2012-09-11 10:05:00 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:36:32 +04:00
|
|
|
return mTimeManager;
|
2012-09-11 10:05:00 +04:00
|
|
|
}
|
2012-11-05 19:20:03 +04:00
|
|
|
#endif
|
2012-09-11 10:05:00 +04:00
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
nsDOMCameraManager*
|
|
|
|
Navigator::GetMozCameras(ErrorResult& aRv)
|
|
|
|
{
|
2012-07-31 01:59:05 +04:00
|
|
|
if (!mCameraManager) {
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow ||
|
|
|
|
!mWindow->GetOuterWindow() ||
|
|
|
|
mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) {
|
2013-07-12 18:35:44 +04:00
|
|
|
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return nullptr;
|
2012-07-31 01:59:05 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
mCameraManager = nsDOMCameraManager::CreateInstance(mWindow);
|
2012-07-31 01:59:05 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
return mCameraManager;
|
2012-07-31 01:59:05 +04:00
|
|
|
}
|
|
|
|
|
2014-08-19 17:56:00 +04:00
|
|
|
already_AddRefed<ServiceWorkerContainer>
|
2013-11-20 03:14:07 +04:00
|
|
|
Navigator::ServiceWorker()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mWindow);
|
|
|
|
|
|
|
|
if (!mServiceWorkerContainer) {
|
2014-08-19 17:56:00 +04:00
|
|
|
mServiceWorkerContainer = new ServiceWorkerContainer(mWindow);
|
2013-11-20 03:14:07 +04:00
|
|
|
}
|
|
|
|
|
2014-08-19 17:56:00 +04:00
|
|
|
nsRefPtr<ServiceWorkerContainer> ref = mServiceWorkerContainer;
|
2013-11-20 03:14:07 +04:00
|
|
|
return ref.forget();
|
|
|
|
}
|
|
|
|
|
2012-02-02 01:58:01 +04:00
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
Navigator::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2012-02-02 01:58:01 +04:00
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
|
|
|
|
// TODO: add SizeOfIncludingThis() to nsMimeTypeArray, bug 674113.
|
|
|
|
// TODO: add SizeOfIncludingThis() to nsPluginArray, bug 674114.
|
2013-04-12 22:47:47 +04:00
|
|
|
// TODO: add SizeOfIncludingThis() to Geolocation, bug 674115.
|
2013-04-10 18:20:43 +04:00
|
|
|
// TODO: add SizeOfIncludingThis() to DesktopNotificationCenter, bug 674116.
|
2012-02-02 01:58:01 +04:00
|
|
|
|
|
|
|
return n;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2011-12-28 17:39:55 +04:00
|
|
|
void
|
|
|
|
Navigator::SetWindow(nsPIDOMWindow *aInnerWindow)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aInnerWindow->IsInnerWindow(),
|
|
|
|
"Navigator must get an inner window!");
|
2013-06-20 22:34:38 +04:00
|
|
|
mWindow = aInnerWindow;
|
2011-12-28 17:39:55 +04:00
|
|
|
}
|
|
|
|
|
2012-06-03 11:35:15 +04:00
|
|
|
void
|
|
|
|
Navigator::OnNavigation()
|
|
|
|
{
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow) {
|
2012-07-31 01:59:05 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-03 11:35:15 +04:00
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
2012-07-31 01:59:05 +04:00
|
|
|
// Inform MediaManager in case there are live streams or pending callbacks.
|
2012-06-03 11:35:15 +04:00
|
|
|
MediaManager *manager = MediaManager::Get();
|
2013-02-08 07:14:21 +04:00
|
|
|
if (manager) {
|
2013-06-20 22:34:38 +04:00
|
|
|
manager->OnNavigation(mWindow->WindowID());
|
2013-02-08 07:14:21 +04:00
|
|
|
}
|
2012-06-03 11:35:15 +04:00
|
|
|
#endif
|
2012-07-31 01:59:05 +04:00
|
|
|
if (mCameraManager) {
|
2013-06-20 22:34:38 +04:00
|
|
|
mCameraManager->OnNavigation(mWindow->WindowID());
|
2012-07-31 01:59:05 +04:00
|
|
|
}
|
2012-06-03 11:35:15 +04:00
|
|
|
}
|
|
|
|
|
2012-10-02 13:08:02 +04:00
|
|
|
bool
|
|
|
|
Navigator::CheckPermission(const char* type)
|
|
|
|
{
|
2013-07-12 18:35:35 +04:00
|
|
|
return CheckPermission(mWindow, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::CheckPermission(nsPIDOMWindow* aWindow, const char* aType)
|
|
|
|
{
|
|
|
|
if (!aWindow) {
|
2013-06-20 22:34:38 +04:00
|
|
|
return false;
|
|
|
|
}
|
2012-10-02 13:08:02 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr =
|
2014-04-29 21:27:26 +04:00
|
|
|
services::GetPermissionManager();
|
2012-10-02 13:08:02 +04:00
|
|
|
NS_ENSURE_TRUE(permMgr, false);
|
|
|
|
|
|
|
|
uint32_t permission = nsIPermissionManager::DENY_ACTION;
|
2013-07-12 18:35:35 +04:00
|
|
|
permMgr->TestPermissionFromWindow(aWindow, aType, &permission);
|
2012-10-02 13:08:02 +04:00
|
|
|
return permission == nsIPermissionManager::ALLOW_ACTION;
|
|
|
|
}
|
|
|
|
|
2012-11-30 02:52:03 +04:00
|
|
|
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
2013-07-12 18:36:32 +04:00
|
|
|
system::AudioChannelManager*
|
|
|
|
Navigator::GetMozAudioChannelManager(ErrorResult& aRv)
|
|
|
|
{
|
2012-11-30 02:52:03 +04:00
|
|
|
if (!mAudioChannelManager) {
|
2013-07-12 18:36:32 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-11-30 02:52:03 +04:00
|
|
|
mAudioChannelManager = new system::AudioChannelManager();
|
2013-06-20 22:34:38 +04:00
|
|
|
mAudioChannelManager->Init(mWindow);
|
2012-11-30 02:52:03 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:36:32 +04:00
|
|
|
return mAudioChannelManager;
|
2012-11-30 02:52:03 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-12 18:37:23 +04:00
|
|
|
bool
|
|
|
|
Navigator::DoNewResolve(JSContext* aCx, JS::Handle<JSObject*> aObject,
|
2013-07-16 09:31:03 +04:00
|
|
|
JS::Handle<jsid> aId,
|
2014-01-22 07:08:51 +04:00
|
|
|
JS::MutableHandle<JSPropertyDescriptor> aDesc)
|
2013-07-12 18:37:23 +04:00
|
|
|
{
|
|
|
|
if (!JSID_IS_STRING(aId)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-20 03:24:29 +04:00
|
|
|
nsScriptNameSpaceManager* nameSpaceManager = GetNameSpaceManager();
|
2013-07-12 18:37:23 +04:00
|
|
|
if (!nameSpaceManager) {
|
2013-09-09 07:29:21 +04:00
|
|
|
return Throw(aCx, NS_ERROR_NOT_INITIALIZED);
|
2013-07-12 18:37:23 +04:00
|
|
|
}
|
|
|
|
|
2014-07-05 19:30:54 +04:00
|
|
|
nsAutoJSString name;
|
|
|
|
if (!name.init(aCx, JSID_TO_STRING(aId))) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-12 18:37:23 +04:00
|
|
|
|
|
|
|
const nsGlobalNameStruct* name_struct =
|
|
|
|
nameSpaceManager->LookupNavigatorName(name);
|
|
|
|
if (!name_struct) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-21 11:25:21 +04:00
|
|
|
JS::Rooted<JSObject*> naviObj(aCx,
|
|
|
|
js::CheckedUnwrap(aObject,
|
|
|
|
/* stopAtOuter = */ false));
|
|
|
|
if (!naviObj) {
|
|
|
|
return Throw(aCx, NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:37:23 +04:00
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeNewDOMBinding) {
|
|
|
|
ConstructNavigatorProperty construct = name_struct->mConstructNavigatorProperty;
|
|
|
|
MOZ_ASSERT(construct);
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> domObject(aCx);
|
|
|
|
{
|
2014-03-21 11:25:21 +04: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 18:37:23 +04: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 17:59:13 +04:00
|
|
|
if (name.EqualsLiteral("mozSettings")) {
|
2014-08-28 08:01:29 +04:00
|
|
|
bool hasPermission = CheckPermission("settings-api-read") ||
|
|
|
|
CheckPermission("settings-api-write");
|
2013-08-06 17:59:13 +04:00
|
|
|
if (!hasPermission) {
|
2014-01-22 07:08:51 +04:00
|
|
|
FillPropertyDescriptor(aDesc, aObject, JS::NullValue(), false);
|
2013-08-06 17:59:13 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-28 11:18:12 +04:00
|
|
|
if (name.EqualsLiteral("mozDownloadManager")) {
|
|
|
|
if (!CheckPermission("downloads")) {
|
2014-01-22 07:08:51 +04:00
|
|
|
FillPropertyDescriptor(aDesc, aObject, JS::NullValue(), false);
|
2013-11-28 11:18:12 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-21 07:19:43 +04: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 08:58:43 +04:00
|
|
|
if (!dom::WrapObject(aCx, existingObject, &wrapped)) {
|
2014-03-21 07:19:43 +04: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 18:37:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-16 04:02:23 +04:00
|
|
|
if (!JS_WrapObject(aCx, &domObject)) {
|
2013-07-12 18:37:23 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-22 07:08:51 +04:00
|
|
|
FillPropertyDescriptor(aDesc, aObject, JS::ObjectValue(*domObject), false);
|
2013-07-12 18:37:23 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(name_struct->mType == nsGlobalNameStruct::eTypeNavigatorProperty,
|
|
|
|
"unexpected type");
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2014-03-21 07:19:43 +04: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 18:37:23 +04:00
|
|
|
|
2014-03-21 07:19:43 +04:00
|
|
|
nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi(do_QueryInterface(native));
|
2013-07-12 18:37:23 +04:00
|
|
|
|
2014-03-21 07:19:43 +04:00
|
|
|
if (gpi) {
|
|
|
|
if (!mWindow) {
|
|
|
|
return Throw(aCx, NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
2013-07-12 18:37:23 +04:00
|
|
|
|
2014-03-21 07:19:43 +04:00
|
|
|
rv = gpi->Init(mWindow, &prop_val);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return Throw(aCx, rv);
|
|
|
|
}
|
2013-07-12 18:37:23 +04:00
|
|
|
}
|
2014-03-21 07:19:43 +04:00
|
|
|
|
|
|
|
okToUseNative = !prop_val.isObjectOrNull();
|
2013-07-12 18:37:23 +04:00
|
|
|
}
|
|
|
|
|
2014-03-21 07:19:43 +04:00
|
|
|
if (okToUseNative) {
|
2014-03-21 11:25:21 +04: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 08:58:41 +04:00
|
|
|
rv = nsContentUtils::WrapNative(aCx, native, &prop_val);
|
2013-07-12 18:37:23 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-09-09 07:29:21 +04:00
|
|
|
return Throw(aCx, rv);
|
2013-07-12 18:37:23 +04:00
|
|
|
}
|
2014-03-21 07:19:43 +04: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 18:37:23 +04:00
|
|
|
}
|
|
|
|
|
2013-10-26 20:19:05 +04:00
|
|
|
if (!JS_WrapValue(aCx, &prop_val)) {
|
2013-09-09 07:29:21 +04:00
|
|
|
return Throw(aCx, NS_ERROR_UNEXPECTED);
|
2013-07-12 18:37:23 +04:00
|
|
|
}
|
|
|
|
|
2014-01-22 07:08:51 +04:00
|
|
|
FillPropertyDescriptor(aDesc, aObject, prop_val, false);
|
2013-07-16 09:31:03 +04:00
|
|
|
return true;
|
2013-07-12 18:37:23 +04:00
|
|
|
}
|
|
|
|
|
2014-02-16 01:12:34 +04: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 07:38:54 +04:00
|
|
|
static PLDHashOperator
|
2014-02-16 01:12:34 +04:00
|
|
|
SaveNavigatorName(const nsAString& aName,
|
|
|
|
const nsGlobalNameStruct& aNameStruct,
|
|
|
|
void* aClosure)
|
2013-08-04 07:38:54 +04:00
|
|
|
{
|
2014-02-16 01:12:34 +04:00
|
|
|
NavigatorNameEnumeratorClosure* closure =
|
|
|
|
static_cast<NavigatorNameEnumeratorClosure*>(aClosure);
|
|
|
|
if (!aNameStruct.mConstructorEnabled ||
|
|
|
|
aNameStruct.mConstructorEnabled(closure->mCx, closure->mWrapper)) {
|
|
|
|
closure->mNames.AppendElement(aName);
|
|
|
|
}
|
2013-08-04 07:38:54 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Navigator::GetOwnPropertyNames(JSContext* aCx, nsTArray<nsString>& aNames,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2013-08-20 03:24:29 +04:00
|
|
|
nsScriptNameSpaceManager *nameSpaceManager = GetNameSpaceManager();
|
2013-08-04 07:38:54 +04:00
|
|
|
if (!nameSpaceManager) {
|
|
|
|
NS_ERROR("Can't get namespace manager.");
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-16 01:12:34 +04:00
|
|
|
NavigatorNameEnumeratorClosure closure(aCx, GetWrapper(), aNames);
|
|
|
|
nameSpaceManager->EnumerateNavigatorNames(SaveNavigatorName, &closure);
|
2013-08-04 07:38:54 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:37:23 +04:00
|
|
|
JSObject*
|
2014-04-09 02:27:18 +04:00
|
|
|
Navigator::WrapObject(JSContext* cx)
|
2013-07-12 18:37:23 +04: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-09 02:27:17 +04:00
|
|
|
return NavigatorBinding::Wrap(cx, this);
|
2013-07-12 18:37:23 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04: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 12:12:38 +04:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasCameraSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && nsDOMCameraManager::CheckPermission(win);
|
|
|
|
}
|
|
|
|
|
2014-01-27 11:48:10 +04:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasWifiManagerSupport(JSContext* /* unused */,
|
|
|
|
JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
// On XBL scope, the global object is NOT |window|. So we have
|
|
|
|
// to use nsContentUtils::GetObjectPrincipal to get the principal
|
|
|
|
// and test directly with permission manager.
|
|
|
|
|
2014-05-13 13:58:00 +04:00
|
|
|
nsIPrincipal* principal = nsContentUtils::ObjectPrincipal(aGlobal);
|
2014-01-27 11:48:10 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr =
|
2014-04-29 21:27:26 +04:00
|
|
|
services::GetPermissionManager();
|
2014-01-27 11:48:10 +04: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 18:36:13 +04:00
|
|
|
|
2013-10-03 02:09:08 +04:00
|
|
|
#ifdef MOZ_NFC
|
|
|
|
/* static */
|
|
|
|
bool
|
2014-04-29 07:50:25 +04:00
|
|
|
Navigator::HasNFCSupport(JSContext* /* unused */, JSObject* aGlobal)
|
2013-10-03 02:09:08 +04:00
|
|
|
{
|
2014-07-18 20:37:42 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
|
2013-12-17 06:32:29 +04:00
|
|
|
// Do not support NFC if NFC content helper does not exist.
|
|
|
|
nsCOMPtr<nsISupports> contentHelper = do_GetService("@mozilla.org/nfc/content-helper;1");
|
2014-08-19 14:43:57 +04:00
|
|
|
return !!contentHelper;
|
2013-10-03 02:09:08 +04:00
|
|
|
}
|
2014-01-13 13:33:12 +04:00
|
|
|
#endif // MOZ_NFC
|
2013-10-03 02:09:08 +04:00
|
|
|
|
2013-07-12 18:37:21 +04:00
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
|
|
|
/* static */
|
2014-01-14 02:28:40 +04:00
|
|
|
bool
|
|
|
|
Navigator::HasUserMediaSupport(JSContext* /* unused */,
|
|
|
|
JSObject* /* unused */)
|
2013-07-12 18:37:21 +04:00
|
|
|
{
|
|
|
|
// Make enabling peerconnection enable getUserMedia() as well
|
|
|
|
return Preferences::GetBool("media.navigator.enabled", false) ||
|
|
|
|
Preferences::GetBool("media.peerconnection.enabled", false);
|
|
|
|
}
|
|
|
|
#endif // MOZ_MEDIA_NAVIGATOR
|
|
|
|
|
2013-09-26 11:10:56 +04:00
|
|
|
/* static */
|
2014-01-14 02:28:40 +04:00
|
|
|
bool
|
|
|
|
Navigator::HasInputMethodSupport(JSContext* /* unused */,
|
|
|
|
JSObject* aGlobal)
|
2013-09-26 11:10:56 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
2014-03-31 06:38:45 +04:00
|
|
|
if (!win || !Preferences::GetBool("dom.mozInputMethod.enabled", false)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-14 02:28:40 +04:00
|
|
|
if (Preferences::GetBool("dom.mozInputMethod.testing", false)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-31 06:38:45 +04:00
|
|
|
return CheckPermission(win, "input") ||
|
|
|
|
CheckPermission(win, "input-manage");
|
2013-09-26 11:10:56 +04:00
|
|
|
}
|
|
|
|
|
2013-12-06 03:12:23 +04:00
|
|
|
/* static */
|
|
|
|
bool
|
2014-03-12 13:03:05 +04:00
|
|
|
Navigator::HasDataStoreSupport(nsIPrincipal* aPrincipal)
|
2013-12-06 03:12:23 +04:00
|
|
|
{
|
2014-03-12 13:03:05 +04:00
|
|
|
workers::AssertIsOnMainThread();
|
2013-12-12 00:15:16 +04:00
|
|
|
|
2014-06-19 18:03:54 +04:00
|
|
|
return DataStoreService::CheckPermission(aPrincipal);
|
2014-03-12 13:03:05 +04: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 04:49:25 +04:00
|
|
|
explicit HasDataStoreSupportRunnable(workers::WorkerPrivate* aWorkerPrivate)
|
2014-03-12 13:03:05 +04: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-12 00:15:16 +04:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(global);
|
2013-12-06 03:12:23 +04:00
|
|
|
if (!win) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* doc = win->GetExtantDoc();
|
|
|
|
if (!doc || !doc->NodePrincipal()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-12 13:03:05 +04:00
|
|
|
return HasDataStoreSupport(doc->NodePrincipal());
|
2013-12-06 03:12:23 +04:00
|
|
|
}
|
|
|
|
|
2014-06-27 03:18:19 +04: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 23:57:02 +04:00
|
|
|
return permission == nsIPermissionManager::PROMPT_ACTION ||
|
|
|
|
permission == nsIPermissionManager::ALLOW_ACTION;
|
2014-06-27 03:18:19 +04:00
|
|
|
}
|
|
|
|
#endif
|
2014-05-12 06:05:03 +04:00
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<nsPIDOMWindow>
|
|
|
|
Navigator::GetWindowFromGlobal(JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win =
|
|
|
|
do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(aGlobal));
|
|
|
|
MOZ_ASSERT(!win || win->IsInnerWindow());
|
|
|
|
return win.forget();
|
|
|
|
}
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
nsresult
|
2014-09-23 23:11:18 +04:00
|
|
|
Navigator::GetPlatform(nsAString& aPlatform, bool aUsePrefOverriddenValue)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2014-09-23 23:11:18 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2011-11-02 17:44:16 +04:00
|
|
|
|
2014-09-23 23:11:18 +04:00
|
|
|
if (aUsePrefOverriddenValue && !nsContentUtils::IsCallerChrome()) {
|
2011-11-02 17:44:16 +04:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
mozilla::Preferences::GetString("general.platform.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aPlatform = override;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Sorry for the #if platform ugliness, but Communicator is likewise
|
|
|
|
// hardcoded and we are seeking backward compatibility here (bug 47080).
|
|
|
|
#if defined(_WIN64)
|
|
|
|
aPlatform.AssignLiteral("Win64");
|
|
|
|
#elif defined(WIN32)
|
|
|
|
aPlatform.AssignLiteral("Win32");
|
|
|
|
#elif defined(XP_MACOSX) && defined(__ppc__)
|
|
|
|
aPlatform.AssignLiteral("MacPPC");
|
|
|
|
#elif defined(XP_MACOSX) && defined(__i386__)
|
|
|
|
aPlatform.AssignLiteral("MacIntel");
|
|
|
|
#elif defined(XP_MACOSX) && defined(__x86_64__)
|
|
|
|
aPlatform.AssignLiteral("MacIntel");
|
|
|
|
#else
|
|
|
|
// XXX Communicator uses compiled-in build-time string defines
|
|
|
|
// to indicate the platform it was compiled *for*, not what it is
|
|
|
|
// currently running *on* which is what this does.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString plat;
|
2011-11-02 17:44:16 +04:00
|
|
|
rv = service->GetOscpu(plat);
|
|
|
|
CopyASCIItoUTF16(plat, aPlatform);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2014-09-23 23:11:18 +04:00
|
|
|
|
|
|
|
/* static */ nsresult
|
|
|
|
Navigator::GetAppVersion(nsAString& aAppVersion, bool aUsePrefOverriddenValue)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2014-09-24 20:09:50 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2014-09-23 23:11:18 +04:00
|
|
|
if (aUsePrefOverriddenValue && !nsContentUtils::IsCallerChrome()) {
|
2011-11-02 17:44:16 +04:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
mozilla::Preferences::GetString("general.appversion.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aAppVersion = override;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString str;
|
2011-11-02 17:44:16 +04:00
|
|
|
rv = service->GetAppVersion(str);
|
|
|
|
CopyASCIItoUTF16(str, aAppVersion);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
aAppVersion.AppendLiteral(" (");
|
|
|
|
|
|
|
|
rv = service->GetPlatform(str);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
AppendASCIItoUTF16(str, aAppVersion);
|
2014-01-04 19:02:17 +04:00
|
|
|
aAppVersion.Append(char16_t(')'));
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-09-23 23:11:18 +04:00
|
|
|
/* static */ void
|
|
|
|
Navigator::AppName(nsAString& aAppName, bool aUsePrefOverriddenValue)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2014-09-24 20:09:50 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2014-09-23 23:11:18 +04:00
|
|
|
if (aUsePrefOverriddenValue && !nsContentUtils::IsCallerChrome()) {
|
2011-11-02 17:44:16 +04:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
mozilla::Preferences::GetString("general.appname.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aAppName = override;
|
2013-11-18 03:10:15 +04:00
|
|
|
return;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aAppName.AssignLiteral("Netscape");
|
|
|
|
}
|
2014-09-23 23:11:18 +04:00
|
|
|
|
|
|
|
nsresult
|
2014-09-24 20:09:50 +04:00
|
|
|
Navigator::GetUserAgent(nsPIDOMWindow* aWindow, nsIURI* aURI,
|
|
|
|
bool aIsCallerChrome,
|
|
|
|
nsAString& aUserAgent)
|
2014-09-23 23:11:18 +04:00
|
|
|
{
|
2014-09-24 20:09:50 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-09-24 14:40:43 +04:00
|
|
|
|
2014-09-24 20:09:50 +04:00
|
|
|
if (!aIsCallerChrome) {
|
|
|
|
const nsAdoptingString& override =
|
|
|
|
mozilla::Preferences::GetString("general.useragent.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aUserAgent = override;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
2014-09-23 23:11:18 +04:00
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
2014-09-24 20:09:50 +04:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2014-09-23 23:11:18 +04:00
|
|
|
|
|
|
|
nsAutoCString ua;
|
|
|
|
rv = service->GetUserAgent(ua);
|
2014-09-24 20:09:50 +04:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-09-23 23:11:18 +04:00
|
|
|
CopyASCIItoUTF16(ua, aUserAgent);
|
|
|
|
|
2014-09-24 20:09:50 +04: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 23:11:18 +04:00
|
|
|
}
|
2014-09-24 20:09:50 +04:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|