2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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"
|
2014-12-06 22:26:50 +03:00
|
|
|
#include "nsIClassOfService.h"
|
2011-11-02 17:44:16 +04:00
|
|
|
#include "nsIHttpProtocolHandler.h"
|
2014-03-06 19:51:23 +04:00
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsIContentSecurityPolicy.h"
|
|
|
|
#include "nsContentPolicyUtils.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"
|
2015-05-04 09:11:00 +03:00
|
|
|
#include "mozilla/dom/DeviceStorageAreaListener.h"
|
2016-06-28 01:26:00 +03:00
|
|
|
#ifdef MOZ_GAMEPAD
|
|
|
|
#include "mozilla/dom/GamepadServiceTest.h"
|
|
|
|
#endif
|
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"
|
2016-06-07 12:46:03 +03:00
|
|
|
#include "mozilla/dom/FlyWebPublishedServer.h"
|
2016-06-02 09:47:00 +03:00
|
|
|
#include "mozilla/dom/FlyWebService.h"
|
2015-07-28 16:33:46 +03:00
|
|
|
#include "mozilla/dom/Permissions.h"
|
2015-03-19 10:48:28 +03:00
|
|
|
#include "mozilla/dom/Presentation.h"
|
2013-11-20 03:14:07 +04:00
|
|
|
#include "mozilla/dom/ServiceWorkerContainer.h"
|
2016-06-14 15:57:36 +03:00
|
|
|
#include "mozilla/dom/StorageManager.h"
|
2015-03-25 17:35:59 +03:00
|
|
|
#include "mozilla/dom/TCPSocket.h"
|
2016-04-13 03:39:28 +03:00
|
|
|
#include "mozilla/dom/VRDisplay.h"
|
2016-03-16 22:41:38 +03:00
|
|
|
#include "mozilla/dom/workers/RuntimeService.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"
|
2016-10-24 11:02:12 +03:00
|
|
|
#include "mozilla/SSE.h"
|
2012-07-26 23:33:45 +04:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2012-01-16 16:23:44 +04:00
|
|
|
#include "Connection.h"
|
2014-03-05 04:37:43 +04:00
|
|
|
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
|
2013-06-25 00:07:03 +04:00
|
|
|
#include "nsGlobalWindow.h"
|
2012-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"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsStringStream.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsIStringStream.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
#include "nsIHttpChannel.h"
|
2015-08-28 01:09:17 +03: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"
|
2014-03-06 19:51:23 +04:00
|
|
|
#include "nsStreamUtils.h"
|
2014-01-28 20:09:34 +04:00
|
|
|
#include "WidgetUtils.h"
|
2015-10-21 09:01:08 +03:00
|
|
|
#include "nsIPresentationService.h"
|
2011-11-02 17:44:16 +04:00
|
|
|
|
2014-09-20 10:20:41 +04:00
|
|
|
#include "mozilla/dom/MediaDevices.h"
|
2012-06-03 11:35:15 +04:00
|
|
|
#include "MediaManager.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
|
|
|
|
|
2012-07-03 04:16:55 +04:00
|
|
|
#include "nsIDOMGlobalPropertyInitializer.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"
|
2016-01-07 22:30:36 +03:00
|
|
|
#include "mozilla/dom/FormData.h"
|
2014-03-26 08:15:14 +04:00
|
|
|
#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"
|
|
|
|
|
2015-02-20 04:38:08 +03:00
|
|
|
#include "mozilla/EMEUtils.h"
|
2015-06-03 04:42:50 +03:00
|
|
|
#include "mozilla/DetailedPromise.h"
|
2015-02-20 04:38:08 +03:00
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2011-11-11 01:26:36 +04:00
|
|
|
static bool sVibratorEnabled = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t sMaxVibrateMS = 0;
|
|
|
|
static uint32_t sMaxVibrateListLen = 0;
|
2016-04-26 16:40:27 +03:00
|
|
|
static const char* kVibrationPermissionType = "vibration";
|
2011-11-02 17:44:16 +04:00
|
|
|
|
2016-04-26 16:38:18 +03:00
|
|
|
static void
|
|
|
|
AddPermission(nsIPrincipal* aPrincipal, const char* aType, uint32_t aPermission,
|
|
|
|
uint32_t aExpireType, int64_t aExpireTime)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aType);
|
|
|
|
MOZ_ASSERT(aPrincipal);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
|
|
|
|
if (!permMgr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
permMgr->AddFromPrincipal(aPrincipal, aType, aPermission, aExpireType,
|
|
|
|
aExpireTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
GetPermission(nsPIDOMWindowInner* aWindow, const char* aType)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aType);
|
|
|
|
|
|
|
|
uint32_t permission = nsIPermissionManager::UNKNOWN_ACTION;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
|
|
|
|
if (!permMgr) {
|
|
|
|
return permission;
|
|
|
|
}
|
|
|
|
permMgr->TestPermissionFromWindow(aWindow, aType, &permission);
|
|
|
|
return permission;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
GetPermission(nsIPrincipal* aPrincipal, const char* aType)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aType);
|
|
|
|
MOZ_ASSERT(aPrincipal);
|
|
|
|
|
|
|
|
uint32_t permission = nsIPermissionManager::UNKNOWN_ACTION;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
|
|
|
|
if (!permMgr) {
|
|
|
|
return permission;
|
|
|
|
}
|
|
|
|
permMgr->TestPermissionFromPrincipal(aPrincipal, aType, &permission);
|
|
|
|
return permission;
|
|
|
|
}
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
Navigator::Init()
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
Navigator::Navigator(nsPIDOMWindowInner* 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)
|
|
|
|
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(mMimeTypes)
|
2015-07-28 16:33:46 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPlugins)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPermissions)
|
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)
|
2015-08-21 13:29:25 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBatteryPromise)
|
2013-07-18 20:07:28 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPowerManager)
|
2013-06-28 22:06:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConnection)
|
2016-06-14 15:57:36 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStorageManager)
|
2013-06-28 22:06:39 +04:00
|
|
|
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAudioChannelManager)
|
|
|
|
#endif
|
2015-05-20 19:55:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaDevices)
|
2013-06-28 22:06:39 +04:00
|
|
|
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)
|
2015-03-31 10:50:01 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaKeySystemAccessManager)
|
2015-05-04 09:11:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDeviceStorageAreaListener)
|
2015-03-19 10:48:28 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPresentation)
|
2016-06-28 01:26:00 +03:00
|
|
|
#ifdef MOZ_GAMEPAD
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGamepadServiceTest)
|
|
|
|
#endif
|
2016-04-13 03:39:28 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVRGetDisplaysPromises)
|
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
|
|
|
|
2015-07-28 16:33:46 +03:00
|
|
|
mMimeTypes = nullptr;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-07-28 16:33:46 +03:00
|
|
|
mPermissions = nullptr;
|
2013-07-09 17:58:21 +04:00
|
|
|
|
2016-06-14 15:57:36 +03:00
|
|
|
mStorageManager = 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
|
|
|
|
2015-08-21 13:29:25 +03:00
|
|
|
mBatteryPromise = nullptr;
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2015-05-20 19:55:06 +03:00
|
|
|
mMediaDevices = nullptr;
|
2012-07-31 01:59:05 +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) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMDeviceStorage> ds = do_QueryReferent(mDeviceStorageStores[i]);
|
2015-08-18 14:42:14 +03:00
|
|
|
if (ds) {
|
|
|
|
ds->Shutdown();
|
|
|
|
}
|
2012-08-02 10:29:34 +04:00
|
|
|
}
|
|
|
|
mDeviceStorageStores.Clear();
|
|
|
|
|
2012-09-11 10:05:00 +04:00
|
|
|
if (mTimeManager) {
|
|
|
|
mTimeManager = nullptr;
|
|
|
|
}
|
2013-11-20 03:14:07 +04:00
|
|
|
|
2015-03-19 10:48:28 +03:00
|
|
|
if (mPresentation) {
|
|
|
|
mPresentation = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-11-20 03:14:07 +04:00
|
|
|
mServiceWorkerContainer = nullptr;
|
2015-03-31 10:50:01 +03:00
|
|
|
|
|
|
|
if (mMediaKeySystemAccessManager) {
|
|
|
|
mMediaKeySystemAccessManager->Shutdown();
|
|
|
|
mMediaKeySystemAccessManager = nullptr;
|
|
|
|
}
|
2015-05-04 09:11:00 +03:00
|
|
|
|
|
|
|
if (mDeviceStorageAreaListener) {
|
|
|
|
mDeviceStorageAreaListener = nullptr;
|
|
|
|
}
|
2015-09-18 00:23:13 +03:00
|
|
|
|
2016-06-28 01:26:00 +03:00
|
|
|
#ifdef MOZ_GAMEPAD
|
|
|
|
if (mGamepadServiceTest) {
|
|
|
|
mGamepadServiceTest->Shutdown();
|
|
|
|
mGamepadServiceTest = nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-04-13 03:39:28 +03:00
|
|
|
mVRGetDisplaysPromises.Clear();
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigator
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2016-11-16 01:44:43 +03:00
|
|
|
void
|
|
|
|
Navigator::GetUserAgent(nsAString& aUserAgent, CallerType aCallerType,
|
|
|
|
ErrorResult& aRv) const
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2014-09-24 14:40:43 +04:00
|
|
|
nsCOMPtr<nsIURI> codebaseURI;
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window;
|
2014-09-24 14:40:43 +04:00
|
|
|
|
2015-07-21 09:42:00 +03:00
|
|
|
if (mWindow) {
|
2014-09-24 20:09:50 +04:00
|
|
|
window = mWindow;
|
2015-07-21 09:42:00 +03:00
|
|
|
nsIDocShell* docshell = window->GetDocShell();
|
|
|
|
nsString customUserAgent;
|
|
|
|
if (docshell) {
|
|
|
|
docshell->GetCustomUserAgent(customUserAgent);
|
|
|
|
|
|
|
|
if (!customUserAgent.IsEmpty()) {
|
|
|
|
aUserAgent = customUserAgent;
|
2016-11-16 01:44:43 +03:00
|
|
|
return;
|
2015-07-21 09:42:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* doc = mWindow->GetExtantDoc();
|
|
|
|
if (doc) {
|
|
|
|
doc->NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
|
|
|
|
}
|
2014-09-24 20:09:50 +04:00
|
|
|
}
|
|
|
|
}
|
2014-09-24 14:40:43 +04:00
|
|
|
|
2016-11-16 01:44:43 +03:00
|
|
|
nsresult rv = GetUserAgent(window, codebaseURI,
|
|
|
|
aCallerType == CallerType::System,
|
|
|
|
aUserAgent);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2016-11-16 01:44:43 +03:00
|
|
|
void
|
|
|
|
Navigator::GetAppVersion(nsAString& aAppVersion, CallerType aCallerType,
|
|
|
|
ErrorResult& aRv) const
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2016-11-16 01:44:43 +03:00
|
|
|
nsresult rv = GetAppVersion(aAppVersion,
|
|
|
|
/* aUsePrefOverriddenValue = */ aCallerType != CallerType::System);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2016-11-16 01:44:43 +03:00
|
|
|
void
|
|
|
|
Navigator::GetAppName(nsAString& aAppName, CallerType aCallerType) const
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2016-11-16 01:44:43 +03:00
|
|
|
AppName(aAppName,
|
|
|
|
/* aUsePrefOverriddenValue = */ aCallerType != CallerType::System);
|
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
|
|
|
}
|
|
|
|
|
2016-11-16 01:44:43 +03:00
|
|
|
void
|
|
|
|
Navigator::GetPlatform(nsAString& aPlatform, CallerType aCallerType,
|
|
|
|
ErrorResult& aRv) const
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2016-11-16 01:44:43 +03:00
|
|
|
nsresult rv = GetPlatform(aPlatform,
|
|
|
|
/* aUsePrefOverriddenValue = */ aCallerType != CallerType::System);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2016-11-16 01:44:43 +03:00
|
|
|
void
|
|
|
|
Navigator::GetOscpu(nsAString& aOSCPU, CallerType aCallerType,
|
|
|
|
ErrorResult& aRv) const
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2016-11-16 01:44:43 +03:00
|
|
|
if (aCallerType != CallerType::System) {
|
2011-11-02 17:44:16 +04:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
Preferences::GetString("general.oscpu.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aOSCPU = override;
|
2016-11-16 01:44:43 +03:00
|
|
|
return;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
2016-11-16 01:44:43 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString oscpu;
|
2011-11-02 17:44:16 +04:00
|
|
|
rv = service->GetOscpu(oscpu);
|
2016-11-16 01:44:43 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
|
2016-11-16 01:44:43 +03:00
|
|
|
CopyASCIItoUTF16(oscpu, aOSCPU);
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-07-28 16:33:46 +03:00
|
|
|
Permissions*
|
|
|
|
Navigator::GetPermissions(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mPermissions) {
|
|
|
|
mPermissions = new Permissions(mWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mPermissions;
|
|
|
|
}
|
|
|
|
|
2016-06-14 15:57:36 +03:00
|
|
|
StorageManager*
|
|
|
|
Navigator::Storage()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mWindow);
|
|
|
|
|
|
|
|
if(!mStorageManager) {
|
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mWindow);
|
|
|
|
MOZ_ASSERT(global);
|
|
|
|
|
|
|
|
mStorageManager = new StorageManager(global);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mStorageManager;
|
|
|
|
}
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
// Values for the network.cookie.cookieBehavior pref are documented in
|
|
|
|
// nsCookieService.cpp.
|
|
|
|
#define COOKIE_BEHAVIOR_REJECT 2
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
bool
|
|
|
|
Navigator::CookieEnabled()
|
|
|
|
{
|
|
|
|
bool cookieEnabled =
|
2011-11-02 17:44:16 +04:00
|
|
|
(Preferences::GetInt("network.cookie.cookieBehavior",
|
|
|
|
COOKIE_BEHAVIOR_REJECT) != COOKIE_BEHAVIOR_REJECT);
|
|
|
|
|
|
|
|
// Check whether an exception overrides the global cookie behavior
|
|
|
|
// Note that the code for getting the URI here matches that in
|
|
|
|
// nsHTMLDocument::SetCookie.
|
2013-06-20 22:34:38 +04:00
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
2013-07-12 18:35:35 +04:00
|
|
|
return cookieEnabled;
|
2011-12-01 12:28:16 +04:00
|
|
|
}
|
|
|
|
|
2013-06-20 22:34:38 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = mWindow->GetExtantDoc();
|
2011-11-02 17:44:16 +04:00
|
|
|
if (!doc) {
|
2013-07-12 18:35:35 +04:00
|
|
|
return cookieEnabled;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> codebaseURI;
|
|
|
|
doc->NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
|
|
|
|
|
|
|
|
if (!codebaseURI) {
|
|
|
|
// Not a codebase, so technically can't set cookies, but let's
|
|
|
|
// just return the default value.
|
2013-07-12 18:35:35 +04:00
|
|
|
return cookieEnabled;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsICookiePermission> permMgr =
|
|
|
|
do_GetService(NS_COOKIEPERMISSION_CONTRACTID);
|
2013-07-12 18:35:35 +04:00
|
|
|
NS_ENSURE_TRUE(permMgr, cookieEnabled);
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
// Pass null for the channel, just like the cookie service does.
|
|
|
|
nsCookieAccess access;
|
2012-07-30 18:20:58 +04:00
|
|
|
nsresult rv = permMgr->CanAccess(codebaseURI, nullptr, &access);
|
2013-07-12 18:35:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, cookieEnabled);
|
2011-11-02 17:44:16 +04:00
|
|
|
|
|
|
|
if (access != nsICookiePermission::ACCESS_DEFAULT) {
|
2013-07-12 18:35:35 +04:00
|
|
|
cookieEnabled = access != nsICookiePermission::ACCESS_DENY;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
return cookieEnabled;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
bool
|
|
|
|
Navigator::OnLine()
|
|
|
|
{
|
|
|
|
return !NS_IsOffline();
|
|
|
|
}
|
|
|
|
|
2016-11-16 01:44:43 +03:00
|
|
|
void
|
|
|
|
Navigator::GetBuildID(nsAString& aBuildID, CallerType aCallerType,
|
|
|
|
ErrorResult& aRv) const
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
2016-11-16 01:44:43 +03:00
|
|
|
if (aCallerType != CallerType::System) {
|
2011-11-02 17:44:16 +04:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
Preferences::GetString("general.buildID.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aBuildID = override;
|
2016-11-16 01:44:43 +03:00
|
|
|
return;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXULAppInfo> appInfo =
|
|
|
|
do_GetService("@mozilla.org/xre/app-info;1");
|
|
|
|
if (!appInfo) {
|
2016-11-16 01:44:43 +03:00
|
|
|
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString buildID;
|
2011-11-02 17:44:16 +04:00
|
|
|
nsresult rv = appInfo->GetAppBuildID(buildID);
|
2016-11-16 01:44:43 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
aBuildID.Truncate();
|
|
|
|
AppendASCIItoUTF16(buildID, aBuildID);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetDoNotTrack(nsAString &aResult)
|
|
|
|
{
|
2016-06-02 05:22:18 +03:00
|
|
|
bool doNotTrack = nsContentUtils::DoNotTrackEnabled();
|
|
|
|
if (!doNotTrack) {
|
|
|
|
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(mWindow);
|
|
|
|
doNotTrack = loadContext && loadContext->UseTrackingProtection();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doNotTrack) {
|
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
|
|
|
}
|
|
|
|
|
2016-03-16 22:41:38 +03:00
|
|
|
uint64_t
|
|
|
|
Navigator::HardwareConcurrency()
|
|
|
|
{
|
|
|
|
workers::RuntimeService* rts = workers::RuntimeService::GetOrCreateService();
|
|
|
|
if (!rts) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rts->ClampedHardwareConcurrency();
|
|
|
|
}
|
|
|
|
|
2016-10-08 02:23:39 +03:00
|
|
|
bool
|
|
|
|
Navigator::CpuHasSSE2()
|
|
|
|
{
|
|
|
|
return mozilla::supports_sse2();
|
|
|
|
}
|
|
|
|
|
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:
|
2016-01-30 20:05:36 +03:00
|
|
|
VibrateWindowListener(nsPIDOMWindowInner* 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
|
|
|
|
2015-11-17 12:18:38 +03:00
|
|
|
static bool
|
|
|
|
MayVibrate(nsIDocument* doc) {
|
|
|
|
#if MOZ_WIDGET_GONK
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
return true; // The system app can always vibrate
|
|
|
|
}
|
|
|
|
#endif // MOZ_WIDGET_GONK
|
|
|
|
|
|
|
|
// Hidden documents cannot start or stop a vibration.
|
|
|
|
return (doc && !doc->Hidden());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-11-17 12:18:38 +03:00
|
|
|
if (!MayVibrate(doc)) {
|
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.
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryReferent(mWindow);
|
2011-11-11 01:26:36 +04:00
|
|
|
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 */);
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2011-11-11 01:26:36 +04:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-04-26 16:40:27 +03:00
|
|
|
void
|
|
|
|
Navigator::SetVibrationPermission(bool aPermitted, bool aPersistent)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsTArray<uint32_t> pattern;
|
|
|
|
pattern.SwapElements(mRequestedVibrationPattern);
|
|
|
|
|
|
|
|
if (!mWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = mWindow->GetExtantDoc();
|
|
|
|
|
|
|
|
if (!MayVibrate(doc)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aPermitted) {
|
|
|
|
// Add a listener to cancel the vibration if the document becomes hidden,
|
|
|
|
// and remove the old visibility listener, if there was one.
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
gVibrateWindowListener = new VibrateWindowListener(mWindow, doc);
|
|
|
|
hal::Vibrate(pattern, mWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aPersistent) {
|
|
|
|
AddPermission(doc->NodePrincipal(), kVibrationPermissionType,
|
|
|
|
aPermitted ? nsIPermissionManager::ALLOW_ACTION :
|
|
|
|
nsIPermissionManager::DENY_ACTION,
|
|
|
|
nsIPermissionManager::EXPIRE_SESSION, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-28 22:58:38 +04:00
|
|
|
bool
|
|
|
|
Navigator::Vibrate(uint32_t aDuration)
|
2013-07-12 18:35:35 +04:00
|
|
|
{
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<uint32_t, 1> pattern;
|
2013-07-12 18:35:35 +04:00
|
|
|
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
|
|
|
{
|
2016-04-26 16:40:27 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
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();
|
2013-09-28 22:58:38 +04:00
|
|
|
|
2015-11-17 12:18:38 +03:00
|
|
|
if (!MayVibrate(doc)) {
|
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) {
|
2016-04-26 16:40:27 +03:00
|
|
|
pattern[i] = std::min(sMaxVibrateMS, pattern[i]);
|
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
|
|
|
}
|
|
|
|
|
2016-04-26 16:40:27 +03:00
|
|
|
mRequestedVibrationPattern.SwapElements(pattern);
|
|
|
|
uint32_t permission = GetPermission(mWindow, kVibrationPermissionType);
|
2011-11-11 01:26:36 +04:00
|
|
|
|
2016-04-26 16:40:27 +03:00
|
|
|
if (permission == nsIPermissionManager::ALLOW_ACTION ||
|
|
|
|
mRequestedVibrationPattern.IsEmpty() ||
|
|
|
|
(mRequestedVibrationPattern.Length() == 1 &&
|
|
|
|
mRequestedVibrationPattern[0] == 0)) {
|
|
|
|
// Always allow cancelling vibration and respect session permissions.
|
|
|
|
SetVibrationPermission(true /* permitted */, false /* persistent */);
|
|
|
|
return true;
|
2011-11-11 01:26:36 +04:00
|
|
|
}
|
2016-04-26 16:40:27 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (!obs || permission == nsIPermissionManager::DENY_ACTION) {
|
|
|
|
// Abort without observer service or on denied session permission.
|
|
|
|
SetVibrationPermission(false /* permitted */, false /* persistent */);
|
|
|
|
return true;
|
2011-11-11 01:26:36 +04:00
|
|
|
}
|
|
|
|
|
2016-04-26 16:40:27 +03:00
|
|
|
// Request user permission.
|
|
|
|
obs->NotifyObservers(ToSupports(this), "Vibration:Request", nullptr);
|
|
|
|
|
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()
|
|
|
|
{
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsIWidget> widget = widget::WidgetUtils::DOMWindowToWidget(mWindow->GetOuterWindow());
|
2014-01-28 20:09:34 +04:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-05-04 09:11:00 +03:00
|
|
|
DeviceStorageAreaListener*
|
|
|
|
Navigator::GetDeviceStorageAreaListener(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mDeviceStorageAreaListener) {
|
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
mDeviceStorageAreaListener = new DeviceStorageAreaListener(mWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mDeviceStorageAreaListener;
|
|
|
|
}
|
|
|
|
|
2015-08-18 14:42:14 +03:00
|
|
|
already_AddRefed<nsDOMDeviceStorage>
|
|
|
|
Navigator::FindDeviceStorage(const nsAString& aName, const nsAString& aType)
|
|
|
|
{
|
|
|
|
auto i = mDeviceStorageStores.Length();
|
|
|
|
while (i > 0) {
|
|
|
|
--i;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMDeviceStorage> storage =
|
2015-08-18 14:42:14 +03:00
|
|
|
do_QueryReferent(mDeviceStorageStores[i]);
|
|
|
|
if (storage) {
|
|
|
|
if (storage->Equals(mWindow, aName, aType)) {
|
|
|
|
return storage.forget();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mDeviceStorageStores.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsDOMDeviceStorage>
|
2013-07-12 18:35:44 +04:00
|
|
|
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
|
|
|
|
2015-08-18 14:42:14 +03:00
|
|
|
nsString name;
|
|
|
|
nsDOMDeviceStorage::GetDefaultStorageName(aType, name);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMDeviceStorage> storage = FindDeviceStorage(name, aType);
|
2015-08-18 14:42:14 +03:00
|
|
|
if (storage) {
|
|
|
|
return storage.forget();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-08-18 14:42:14 +03:00
|
|
|
mDeviceStorageStores.AppendElement(
|
|
|
|
do_GetWeakReference(static_cast<DOMEventTargetHelper*>(storage)));
|
|
|
|
return storage.forget();
|
2013-04-02 23:52:21 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:44 +04:00
|
|
|
void
|
|
|
|
Navigator::GetDeviceStorages(const nsAString& aType,
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<nsDOMDeviceStorage> >& aStores,
|
2013-07-12 18:35:44 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-18 14:42:14 +03:00
|
|
|
nsDOMDeviceStorage::VolumeNameArray volumes;
|
|
|
|
nsDOMDeviceStorage::GetOrderedVolumeNames(aType, volumes);
|
|
|
|
if (volumes.IsEmpty()) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMDeviceStorage> storage = GetDeviceStorage(aType, aRv);
|
2015-08-18 14:42:14 +03:00
|
|
|
if (storage) {
|
|
|
|
aStores.AppendElement(storage.forget());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
uint32_t len = volumes.Length();
|
|
|
|
aStores.SetCapacity(len);
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMDeviceStorage> storage =
|
2015-08-18 14:42:14 +03:00
|
|
|
GetDeviceStorageByNameAndType(volumes[i], aType, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
break;
|
|
|
|
}
|
2013-07-12 18:35:44 +04:00
|
|
|
|
2015-08-18 14:42:14 +03:00
|
|
|
if (storage) {
|
|
|
|
aStores.AppendElement(storage.forget());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-12 18:35:44 +04:00
|
|
|
}
|
|
|
|
|
2015-08-18 14:42:14 +03:00
|
|
|
already_AddRefed<nsDOMDeviceStorage>
|
2015-05-04 09:11:00 +03:00
|
|
|
Navigator::GetDeviceStorageByNameAndType(const nsAString& aName,
|
|
|
|
const nsAString& aType,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDOMDeviceStorage> storage = FindDeviceStorage(aName, aType);
|
2015-08-18 14:42:14 +03:00
|
|
|
if (storage) {
|
|
|
|
return storage.forget();
|
|
|
|
}
|
2015-05-04 09:11:00 +03:00
|
|
|
nsDOMDeviceStorage::CreateDeviceStorageByNameAndType(mWindow, aName, aType,
|
|
|
|
getter_AddRefs(storage));
|
|
|
|
|
|
|
|
if (!storage) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-08-18 14:42:14 +03:00
|
|
|
mDeviceStorageStores.AppendElement(
|
|
|
|
do_GetWeakReference(static_cast<DOMEventTargetHelper*>(storage)));
|
|
|
|
return storage.forget();
|
2015-05-04 09:11:00 +03:00
|
|
|
}
|
|
|
|
|
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();
|
2016-01-30 20:05:36 +03:00
|
|
|
if (NS_FAILED(mGeolocation->Init(mWindow))) {
|
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
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class BeaconStreamListener final : public nsIStreamListener
|
2014-03-06 19:51:23 +04:00
|
|
|
{
|
2014-06-23 23:56:07 +04:00
|
|
|
~BeaconStreamListener() {}
|
|
|
|
|
2014-03-06 19:51:23 +04:00
|
|
|
public:
|
2015-07-28 06:39:17 +03:00
|
|
|
BeaconStreamListener() : mLoadGroup(nullptr) {}
|
|
|
|
|
|
|
|
void SetLoadGroup(nsILoadGroup* aLoadGroup) {
|
|
|
|
mLoadGroup = aLoadGroup;
|
|
|
|
}
|
2014-03-06 19:51:23 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
2015-07-28 06:39:17 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
|
|
|
|
2014-03-06 19:51:23 +04:00
|
|
|
};
|
|
|
|
|
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)
|
|
|
|
{
|
2015-07-28 06:39:17 +03:00
|
|
|
// release the loadgroup first
|
|
|
|
mLoadGroup = nullptr;
|
|
|
|
|
2014-03-06 19:51:23 +04:00
|
|
|
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)) {
|
2016-10-29 01:42:52 +03:00
|
|
|
aRv.ThrowTypeError<MSG_INVALID_URL>(aUrl);
|
2014-03-06 19:51:23 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-29 01:42:52 +03:00
|
|
|
// Spec disallows any schemes save for HTTP/HTTPs
|
|
|
|
bool isValidScheme;
|
|
|
|
if (!(NS_SUCCEEDED(uri->SchemeIs("http", &isValidScheme)) && isValidScheme) &&
|
|
|
|
!(NS_SUCCEEDED(uri->SchemeIs("https", &isValidScheme)) && isValidScheme)) {
|
|
|
|
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>( NS_LITERAL_STRING("Beacon"), aUrl);
|
2014-03-06 19:51:23 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-18 19:28:00 +03:00
|
|
|
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL |
|
|
|
|
nsIChannel::LOAD_CLASSIFY_URI;
|
|
|
|
|
2016-07-26 14:46:01 +03:00
|
|
|
// No need to use CORS for sendBeacon unless it's a BLOB
|
|
|
|
nsSecurityFlags securityFlags = (!aData.IsNull() && aData.Value().IsBlob())
|
|
|
|
? nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS
|
|
|
|
: nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS;
|
|
|
|
securityFlags |= nsILoadInfo::SEC_COOKIES_INCLUDE;
|
|
|
|
|
2014-03-06 19:51:23 +04:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
rv = NS_NewChannel(getter_AddRefs(channel),
|
|
|
|
uri,
|
2014-09-22 15:49:12 +04:00
|
|
|
doc,
|
2016-07-26 14:46:01 +03:00
|
|
|
securityFlags,
|
2015-12-18 19:28:00 +03:00
|
|
|
nsIContentPolicy::TYPE_BEACON,
|
|
|
|
nullptr, // aLoadGroup
|
|
|
|
nullptr, // aCallbacks
|
|
|
|
loadFlags);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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()) {
|
2015-05-12 15:09:51 +03:00
|
|
|
Blob& blob = aData.Value().GetAsBlob();
|
2015-05-19 17:36:37 +03:00
|
|
|
blob.GetInternalStream(getter_AddRefs(in), aRv);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
2014-03-06 19:51:23 +04:00
|
|
|
return false;
|
|
|
|
}
|
2015-05-19 17:36:37 +03:00
|
|
|
|
2014-03-06 19:51:23 +04:00
|
|
|
nsAutoString type;
|
2015-05-19 17:36:37 +03:00
|
|
|
blob.GetType(type);
|
2014-03-06 19:51:23 +04:00
|
|
|
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()) {
|
2016-01-07 22:30:36 +03:00
|
|
|
FormData& form = aData.Value().GetAsFormData();
|
2014-03-06 19:51:23 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-12-06 22:26:50 +03:00
|
|
|
nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(channel));
|
|
|
|
if (cos) {
|
|
|
|
cos->AddClassFlags(nsIClassOfService::Background);
|
|
|
|
}
|
|
|
|
|
2015-07-28 06:39:17 +03:00
|
|
|
// The channel needs to have a loadgroup associated with it, so that we can
|
|
|
|
// cancel the channel and any redirected channels it may create.
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup = do_CreateInstance(NS_LOADGROUP_CONTRACTID);
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> callbacks =
|
|
|
|
do_QueryInterface(mWindow->GetDocShell());
|
|
|
|
loadGroup->SetNotificationCallbacks(callbacks);
|
|
|
|
channel->SetLoadGroup(loadGroup);
|
2014-03-06 19:51:23 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<BeaconStreamListener> beaconListener = new BeaconStreamListener();
|
2015-08-28 01:09:17 +03:00
|
|
|
rv = channel->AsyncOpen2(beaconListener);
|
2016-07-12 08:26:11 +03:00
|
|
|
// do not throw if security checks fail within asyncOpen2
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
2015-07-28 06:39:17 +03:00
|
|
|
// make the beaconListener hold a strong reference to the loadgroup
|
|
|
|
// which is released in ::OnStartRequest
|
|
|
|
beaconListener->SetLoadGroup(loadGroup);
|
|
|
|
|
2014-03-06 19:51:23 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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,
|
2016-01-08 01:30:10 +03:00
|
|
|
const nsAString& aCallID,
|
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,
|
2016-01-08 01:30:10 +03:00
|
|
|
aInnerWindowID, aCallID);
|
2012-06-03 11:35:15 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsINavigatorBattery
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2015-08-21 13:29:25 +03:00
|
|
|
Promise*
|
2013-07-12 18:35:35 +04:00
|
|
|
Navigator::GetBattery(ErrorResult& aRv)
|
2015-08-21 13:29:25 +03:00
|
|
|
{
|
|
|
|
if (mBatteryPromise) {
|
|
|
|
return mBatteryPromise;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(mWindow);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> batteryPromise = Promise::Create(go, aRv);
|
2015-08-21 13:29:25 +03:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
mBatteryPromise = batteryPromise;
|
|
|
|
|
|
|
|
if (!mBatteryManager) {
|
|
|
|
mBatteryManager = new battery::BatteryManager(mWindow);
|
|
|
|
mBatteryManager->Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
mBatteryPromise->MaybeResolve(mBatteryManager);
|
|
|
|
|
|
|
|
return mBatteryPromise;
|
|
|
|
}
|
|
|
|
|
2016-06-02 09:47:00 +03:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
Navigator::PublishServer(const nsAString& aName,
|
|
|
|
const FlyWebPublishOptions& aOptions,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
RefPtr<FlyWebService> service = FlyWebService::GetOrCreate();
|
|
|
|
if (!service) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-06-07 12:46:03 +03:00
|
|
|
RefPtr<FlyWebPublishPromise> mozPromise =
|
|
|
|
service->PublishServer(aName, aOptions, mWindow);
|
|
|
|
MOZ_ASSERT(mozPromise);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mWindow);
|
|
|
|
ErrorResult result;
|
|
|
|
RefPtr<Promise> domPromise = Promise::Create(global, result);
|
|
|
|
if (result.Failed()) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mozPromise->Then(AbstractThread::MainThread(),
|
|
|
|
__func__,
|
|
|
|
[domPromise] (FlyWebPublishedServer* aServer) {
|
|
|
|
domPromise->MaybeResolve(aServer);
|
|
|
|
},
|
|
|
|
[domPromise] (nsresult aStatus) {
|
|
|
|
domPromise->MaybeReject(aStatus);
|
|
|
|
});
|
|
|
|
|
|
|
|
return domPromise.forget();
|
2016-06-02 09:47:00 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<power::PowerManagerService> pmService =
|
2014-01-07 16:16:07 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-03-25 17:35:59 +03:00
|
|
|
already_AddRefed<LegacyMozTCPSocket>
|
|
|
|
Navigator::MozTCPSocket()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<LegacyMozTCPSocket> socket = new LegacyMozTCPSocket(GetWindow());
|
2015-03-25 17:35:59 +03:00
|
|
|
return socket.forget();
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:47:13 +04:00
|
|
|
#ifdef MOZ_GAMEPAD
|
2013-07-12 18:36:32 +04:00
|
|
|
void
|
2015-10-18 08:24:48 +03:00
|
|
|
Navigator::GetGamepads(nsTArray<RefPtr<Gamepad> >& aGamepads,
|
2013-07-12 18:36:32 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE_VOID(mWindow->GetDocShell());
|
2016-01-30 20:05:36 +03:00
|
|
|
nsGlobalWindow* win = nsGlobalWindow::Cast(mWindow);
|
2013-12-06 15:52:06 +04:00
|
|
|
win->SetHasGamepadEventListener(true);
|
2013-07-12 18:36:32 +04:00
|
|
|
win->GetGamepads(aGamepads);
|
|
|
|
}
|
2016-06-28 01:26:00 +03:00
|
|
|
|
|
|
|
GamepadServiceTest*
|
|
|
|
Navigator::RequestGamepadServiceTest()
|
|
|
|
{
|
|
|
|
if (!mGamepadServiceTest) {
|
|
|
|
mGamepadServiceTest = GamepadServiceTest::CreateTestService(mWindow);
|
|
|
|
}
|
|
|
|
return mGamepadServiceTest;
|
|
|
|
}
|
2012-02-16 04:47:13 +04:00
|
|
|
#endif
|
|
|
|
|
2014-07-09 23:24:49 +04:00
|
|
|
already_AddRefed<Promise>
|
2016-04-13 03:39:28 +03:00
|
|
|
Navigator::GetVRDisplays(ErrorResult& aRv)
|
2014-07-09 23:24:49 +04:00
|
|
|
{
|
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-07-05 01:46:49 +03:00
|
|
|
nsGlobalWindow* win = nsGlobalWindow::Cast(mWindow);
|
|
|
|
win->NotifyVREventListenerAdded();
|
|
|
|
|
2014-07-09 23:24:49 +04:00
|
|
|
nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(mWindow);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> p = Promise::Create(go, aRv);
|
2014-07-09 23:24:49 +04:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-07-05 01:46:49 +03:00
|
|
|
// We pass ourself to RefreshVRDisplays, so NotifyVRDisplaysUpdated will
|
|
|
|
// be called asynchronously, resolving the promises in mVRGetDisplaysPromises.
|
2016-04-13 03:39:28 +03:00
|
|
|
if (!VRDisplay::RefreshVRDisplays(this)) {
|
2015-09-18 00:23:13 +03:00
|
|
|
p->MaybeReject(NS_ERROR_FAILURE);
|
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
2016-04-13 03:39:28 +03:00
|
|
|
mVRGetDisplaysPromises.AppendElement(p);
|
2015-09-18 00:23:13 +03:00
|
|
|
return p.forget();
|
|
|
|
}
|
|
|
|
|
2016-07-05 01:52:21 +03:00
|
|
|
void
|
|
|
|
Navigator::GetActiveVRDisplays(nsTArray<RefPtr<VRDisplay>>& aDisplays) const
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get only the active VR displays.
|
|
|
|
* Callers do not wish to VRDisplay::RefreshVRDisplays, as the enumeration may
|
|
|
|
* activate hardware that is not yet intended to be used.
|
|
|
|
*/
|
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsGlobalWindow* win = nsGlobalWindow::Cast(mWindow);
|
|
|
|
win->NotifyVREventListenerAdded();
|
|
|
|
nsTArray<RefPtr<VRDisplay>> displays;
|
|
|
|
if (win->UpdateVRDisplays(displays)) {
|
|
|
|
for (auto display : displays) {
|
|
|
|
if (display->IsPresenting()) {
|
|
|
|
aDisplays.AppendElement(display);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 00:23:13 +03:00
|
|
|
void
|
2016-04-13 03:39:28 +03:00
|
|
|
Navigator::NotifyVRDisplaysUpdated()
|
2015-09-18 00:23:13 +03:00
|
|
|
{
|
|
|
|
// Synchronize the VR devices and resolve the promises in
|
2016-04-13 03:39:28 +03:00
|
|
|
// mVRGetDisplaysPromises
|
2016-01-30 20:05:36 +03:00
|
|
|
nsGlobalWindow* win = nsGlobalWindow::Cast(mWindow);
|
2014-07-09 23:24:49 +04:00
|
|
|
|
2016-07-05 01:46:49 +03:00
|
|
|
nsTArray<RefPtr<VRDisplay>> vrDisplays;
|
|
|
|
if (win->UpdateVRDisplays(vrDisplays)) {
|
|
|
|
for (auto p : mVRGetDisplaysPromises) {
|
2016-04-13 03:39:28 +03:00
|
|
|
p->MaybeResolve(vrDisplays);
|
2015-09-18 00:23:13 +03:00
|
|
|
}
|
2014-07-09 23:24:49 +04:00
|
|
|
} else {
|
2016-04-13 03:39:28 +03:00
|
|
|
for (auto p : mVRGetDisplaysPromises) {
|
2015-09-18 00:23:13 +03:00
|
|
|
p->MaybeReject(NS_ERROR_FAILURE);
|
|
|
|
}
|
2014-07-09 23:24:49 +04:00
|
|
|
}
|
2016-04-13 03:39:28 +03:00
|
|
|
mVRGetDisplaysPromises.Clear();
|
2014-07-09 23:24:49 +04:00
|
|
|
}
|
|
|
|
|
2016-07-05 01:52:21 +03:00
|
|
|
void
|
|
|
|
Navigator::NotifyActiveVRDisplaysChanged()
|
|
|
|
{
|
|
|
|
NavigatorBinding::ClearCachedActiveVRDisplaysValue(this);
|
|
|
|
}
|
|
|
|
|
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-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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<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
|
2016-01-30 20:05:36 +03:00
|
|
|
Navigator::SetWindow(nsPIDOMWindowInner *aInnerWindow)
|
2011-12-28 17:39:55 +04:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-03-20 01:43:25 +03:00
|
|
|
// If MediaManager is open let it inform any live streams or pending callbacks
|
|
|
|
MediaManager *manager = MediaManager::GetIfExists();
|
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
|
|
|
}
|
|
|
|
|
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
|
2016-01-30 20:05:36 +03:00
|
|
|
Navigator::CheckPermission(nsPIDOMWindowInner* aWindow, const char* aType)
|
2013-07-12 18:35:35 +04:00
|
|
|
{
|
|
|
|
if (!aWindow) {
|
2013-06-20 22:34:38 +04:00
|
|
|
return false;
|
|
|
|
}
|
2012-10-02 13:08:02 +04:00
|
|
|
|
2016-04-26 16:38:18 +03:00
|
|
|
uint32_t permission = GetPermission(aWindow, aType);
|
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
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
Navigator::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
|
2013-07-12 18:37:23 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return NavigatorBinding::Wrap(cx, this, aGivenProto);
|
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 */
|
2014-01-27 11:48:10 +04:00
|
|
|
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);
|
2016-04-26 16:38:18 +03:00
|
|
|
uint32_t permission = GetPermission(principal, "wifi-manage");
|
2014-01-27 11:48:10 +04:00
|
|
|
|
2016-04-26 16:38:18 +03:00
|
|
|
return permission == nsIPermissionManager::ALLOW_ACTION;
|
2014-01-27 11:48:10 +04:00
|
|
|
}
|
2013-07-12 18:36:13 +04:00
|
|
|
|
2013-07-12 18:37:21 +04:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
2015-02-18 01:10:45 +03:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::IsE10sEnabled(JSContext* aCx, JSObject* aGlobal)
|
|
|
|
{
|
2015-07-04 04:29:00 +03:00
|
|
|
return XRE_IsContentProcess();
|
2015-02-18 01:10:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Navigator::MozE10sEnabled()
|
|
|
|
{
|
|
|
|
// This will only be called if IsE10sEnabled() is true.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
/* static */
|
2016-01-30 20:05:36 +03:00
|
|
|
already_AddRefed<nsPIDOMWindowInner>
|
2013-07-12 18:35:35 +04:00
|
|
|
Navigator::GetWindowFromGlobal(JSObject* aGlobal)
|
|
|
|
{
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> win =
|
2013-07-12 18:35:35 +04:00
|
|
|
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
|
|
|
|
2016-11-16 01:44:43 +03:00
|
|
|
if (aUsePrefOverriddenValue) {
|
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());
|
|
|
|
|
2016-11-16 01:44:43 +03:00
|
|
|
if (aUsePrefOverriddenValue) {
|
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());
|
|
|
|
|
2016-11-16 01:44:43 +03:00
|
|
|
if (aUsePrefOverriddenValue) {
|
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
|
|
|
|
2015-07-21 09:42:00 +03:00
|
|
|
void
|
|
|
|
Navigator::ClearUserAgentCache()
|
|
|
|
{
|
|
|
|
NavigatorBinding::ClearCachedUserAgentValue(this);
|
|
|
|
}
|
|
|
|
|
2014-09-23 23:11:18 +04:00
|
|
|
nsresult
|
2016-01-30 20:05:36 +03:00
|
|
|
Navigator::GetUserAgent(nsPIDOMWindowInner* aWindow, nsIURI* aURI,
|
2014-09-24 20:09:50 +04:00
|
|
|
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
|
|
|
|
2015-10-27 04:10:51 +03:00
|
|
|
static nsCString
|
|
|
|
ToCString(const nsString& aString)
|
2014-11-18 12:13:02 +03:00
|
|
|
{
|
2016-07-08 00:36:27 +03:00
|
|
|
nsCString str("'");
|
|
|
|
str.Append(NS_ConvertUTF16toUTF8(aString));
|
|
|
|
str.AppendLiteral("'");
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsCString
|
|
|
|
ToCString(const MediaKeysRequirement aValue)
|
|
|
|
{
|
|
|
|
nsCString str("'");
|
|
|
|
str.Append(nsDependentCString(MediaKeysRequirementValues::strings[static_cast<uint32_t>(aValue)].value));
|
|
|
|
str.AppendLiteral("'");
|
|
|
|
return str;
|
2015-10-27 04:10:51 +03:00
|
|
|
}
|
2015-07-27 02:52:19 +03:00
|
|
|
|
2015-10-27 04:10:51 +03:00
|
|
|
static nsCString
|
|
|
|
ToCString(const MediaKeySystemMediaCapability& aValue)
|
|
|
|
{
|
|
|
|
nsCString str;
|
2016-07-08 00:36:27 +03:00
|
|
|
str.AppendLiteral("{contentType=");
|
|
|
|
str.Append(ToCString(aValue.mContentType));
|
|
|
|
str.AppendLiteral(", robustness=");
|
|
|
|
str.Append(ToCString(aValue.mRobustness));
|
|
|
|
str.AppendLiteral("}");
|
2015-10-27 04:10:51 +03:00
|
|
|
return str;
|
|
|
|
}
|
2015-07-27 02:52:19 +03:00
|
|
|
|
2015-10-27 04:10:51 +03:00
|
|
|
template<class Type>
|
|
|
|
static nsCString
|
|
|
|
ToCString(const Sequence<Type>& aSequence)
|
|
|
|
{
|
2016-07-08 00:36:27 +03:00
|
|
|
nsCString str;
|
|
|
|
str.AppendLiteral("[");
|
2015-10-27 04:10:51 +03:00
|
|
|
for (size_t i = 0; i < aSequence.Length(); i++) {
|
|
|
|
if (i != 0) {
|
2016-07-08 00:36:27 +03:00
|
|
|
str.AppendLiteral(",");
|
2015-07-27 02:52:19 +03:00
|
|
|
}
|
2016-07-08 00:36:27 +03:00
|
|
|
str.Append(ToCString(aSequence[i]));
|
|
|
|
}
|
|
|
|
str.AppendLiteral("]");
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class Type>
|
|
|
|
static nsCString
|
|
|
|
ToCString(const Optional<Sequence<Type>>& aOptional)
|
|
|
|
{
|
|
|
|
nsCString str;
|
|
|
|
if (aOptional.WasPassed()) {
|
|
|
|
str.Append(ToCString(aOptional.Value()));
|
|
|
|
} else {
|
|
|
|
str.AppendLiteral("[]");
|
2015-07-27 02:52:19 +03:00
|
|
|
}
|
2016-07-08 00:36:27 +03:00
|
|
|
return str;
|
2015-10-27 04:10:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsCString
|
|
|
|
ToCString(const MediaKeySystemConfiguration& aConfig)
|
|
|
|
{
|
|
|
|
nsCString str;
|
2016-07-08 00:36:27 +03:00
|
|
|
str.AppendLiteral("{label=");
|
|
|
|
str.Append(ToCString(aConfig.mLabel));
|
2015-10-27 04:10:51 +03:00
|
|
|
|
2016-07-08 00:36:27 +03:00
|
|
|
str.AppendLiteral(", initDataTypes=");
|
|
|
|
str.Append(ToCString(aConfig.mInitDataTypes));
|
2015-10-27 04:10:51 +03:00
|
|
|
|
2016-07-08 00:36:27 +03:00
|
|
|
str.AppendLiteral(", audioCapabilities=");
|
|
|
|
str.Append(ToCString(aConfig.mAudioCapabilities));
|
|
|
|
|
|
|
|
str.AppendLiteral(", videoCapabilities=");
|
|
|
|
str.Append(ToCString(aConfig.mVideoCapabilities));
|
|
|
|
|
|
|
|
str.AppendLiteral(", distinctiveIdentifier=");
|
|
|
|
str.Append(ToCString(aConfig.mDistinctiveIdentifier));
|
|
|
|
|
|
|
|
str.AppendLiteral(", persistentState=");
|
|
|
|
str.Append(ToCString(aConfig.mPersistentState));
|
|
|
|
|
|
|
|
str.AppendLiteral(", sessionTypes=");
|
|
|
|
str.Append(ToCString(aConfig.mSessionTypes));
|
2015-10-27 04:10:51 +03:00
|
|
|
|
|
|
|
str.AppendLiteral("}");
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsCString
|
|
|
|
RequestKeySystemAccessLogString(const nsAString& aKeySystem,
|
|
|
|
const Sequence<MediaKeySystemConfiguration>& aConfigs)
|
|
|
|
{
|
|
|
|
nsCString str;
|
|
|
|
str.AppendPrintf("Navigator::RequestMediaKeySystemAccess(keySystem='%s' options=",
|
|
|
|
NS_ConvertUTF16toUTF8(aKeySystem).get());
|
|
|
|
str.Append(ToCString(aConfigs));
|
|
|
|
str.AppendLiteral(")");
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2014-11-18 12:13:02 +03:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
Navigator::RequestMediaKeySystemAccess(const nsAString& aKeySystem,
|
2015-10-27 04:10:51 +03:00
|
|
|
const Sequence<MediaKeySystemConfiguration>& aConfigs,
|
2014-11-18 12:13:02 +03:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2015-10-27 04:10:51 +03:00
|
|
|
EME_LOG("%s", RequestKeySystemAccessLogString(aKeySystem, aConfigs).get());
|
2015-07-27 02:52:19 +03:00
|
|
|
|
2014-11-18 12:13:02 +03:00
|
|
|
nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(mWindow);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DetailedPromise> promise =
|
2015-09-23 07:43:46 +03:00
|
|
|
DetailedPromise::Create(go, aRv,
|
|
|
|
NS_LITERAL_CSTRING("navigator.requestMediaKeySystemAccess"),
|
|
|
|
Telemetry::VIDEO_EME_REQUEST_SUCCESS_LATENCY_MS,
|
|
|
|
Telemetry::VIDEO_EME_REQUEST_FAILURE_LATENCY_MS);
|
2014-11-18 12:13:02 +03:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-03-31 10:50:01 +03:00
|
|
|
if (!mMediaKeySystemAccessManager) {
|
|
|
|
mMediaKeySystemAccessManager = new MediaKeySystemAccessManager(mWindow);
|
2014-11-18 12:13:02 +03:00
|
|
|
}
|
|
|
|
|
2015-10-27 04:10:51 +03:00
|
|
|
mMediaKeySystemAccessManager->Request(promise, aKeySystem, aConfigs);
|
2015-03-31 10:50:01 +03:00
|
|
|
return promise.forget();
|
2014-11-18 12:13:02 +03:00
|
|
|
}
|
|
|
|
|
2015-03-19 10:48:28 +03:00
|
|
|
Presentation*
|
|
|
|
Navigator::GetPresentation(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mPresentation) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
mPresentation = Presentation::Create(mWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mPresentation;
|
|
|
|
}
|
|
|
|
|
2014-09-24 20:09:50 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|