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"
|
2017-01-24 14:13:31 +03:00
|
|
|
#include "mozilla/dom/BodyExtractor.h"
|
|
|
|
#include "mozilla/dom/FetchBinding.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"
|
2017-05-23 03:09:49 +03:00
|
|
|
#include "mozilla/dom/CredentialsContainer.h"
|
2016-06-28 01:26:00 +03:00
|
|
|
#include "mozilla/dom/GamepadServiceTest.h"
|
2014-01-07 16:16:07 +04:00
|
|
|
#include "mozilla/dom/WakeLock.h"
|
|
|
|
#include "mozilla/dom/power/PowerManagerService.h"
|
2017-11-15 22:18:58 +03:00
|
|
|
#include "mozilla/dom/MIDIAccessManager.h"
|
|
|
|
#include "mozilla/dom/MIDIOptionsBinding.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"
|
2017-01-24 14:14:00 +03:00
|
|
|
#include "mozilla/dom/URLSearchParams.h"
|
2016-04-13 03:39:28 +03:00
|
|
|
#include "mozilla/dom/VRDisplay.h"
|
2017-05-09 02:01:36 +03:00
|
|
|
#include "mozilla/dom/VRDisplayEvent.h"
|
2017-03-01 13:33:28 +03:00
|
|
|
#include "mozilla/dom/VRServiceTest.h"
|
2018-01-31 10:24:59 +03:00
|
|
|
#include "mozilla/dom/workerinternals/RuntimeService.h"
|
2011-11-11 01:26:36 +04:00
|
|
|
#include "mozilla/Hal.h"
|
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2012-07-26 23:33:45 +04:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2012-01-16 16:23:44 +04:00
|
|
|
#include "Connection.h"
|
2018-04-20 07:49:29 +03:00
|
|
|
#include "mozilla/dom/Event.h" // for Event
|
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"
|
2017-06-01 09:54:59 +03:00
|
|
|
#include "nsRFPService.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"
|
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"
|
2017-05-01 07:55:03 +03:00
|
|
|
#include "nsIScriptError.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-07-03 04:16:55 +04:00
|
|
|
#include "nsIDOMGlobalPropertyInitializer.h"
|
2013-07-12 18:35:35 +04:00
|
|
|
#include "nsJSUtils.h"
|
|
|
|
|
|
|
|
#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
|
|
|
|
2018-01-31 10:25:30 +03:00
|
|
|
#include "mozilla/dom/WorkerPrivate.h"
|
|
|
|
#include "mozilla/dom/WorkerRunnable.h"
|
2014-03-12 13:03:05 +04:00
|
|
|
|
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"
|
2017-05-01 07:55:03 +03:00
|
|
|
#include "mozilla/Unused.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
|
|
|
|
|
|
|
/* 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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2018-01-22 20:59:15 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
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(mBatteryManager)
|
2015-08-21 13:29:25 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBatteryPromise)
|
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)
|
2017-05-23 03:09:49 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCredentials)
|
2015-05-20 19:55:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaDevices)
|
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-03-19 10:48:28 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPresentation)
|
2016-06-28 01:26:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGamepadServiceTest)
|
2016-04-13 03:39:28 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVRGetDisplaysPromises)
|
2017-03-01 13:33:28 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVRServiceTest)
|
2013-06-28 22:06:39 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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-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
|
|
|
|
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
|
|
|
|
2016-06-28 01:26:00 +03:00
|
|
|
if (mGamepadServiceTest) {
|
|
|
|
mGamepadServiceTest->Shutdown();
|
|
|
|
mGamepadServiceTest = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-04-13 03:39:28 +03:00
|
|
|
mVRGetDisplaysPromises.Clear();
|
2017-03-01 13:33:28 +03:00
|
|
|
|
|
|
|
if (mVRServiceTest) {
|
|
|
|
mVRServiceTest->Shutdown();
|
|
|
|
mVRServiceTest = nullptr;
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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
|
|
|
}
|
2014-09-24 20:09:50 +04:00
|
|
|
}
|
|
|
|
}
|
2014-09-24 14:40:43 +04:00
|
|
|
|
2017-03-25 06:00:12 +03:00
|
|
|
nsresult rv = GetUserAgent(window,
|
2016-11-16 01:44:43 +03:00
|
|
|
aCallerType == CallerType::System,
|
|
|
|
aUserAgent);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2018-01-22 20:59:15 +03:00
|
|
|
void
|
|
|
|
Navigator::GetAppCodeName(nsAString& aAppCodeName, ErrorResult& aRv)
|
2011-11-02 17:44:16 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
2018-01-22 20:59:15 +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 appName;
|
2011-11-02 17:44:16 +04:00
|
|
|
rv = service->GetAppName(appName);
|
2018-01-22 20:59:15 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
2011-11-02 17:44:16 +04:00
|
|
|
|
2018-01-22 20:59:15 +03:00
|
|
|
CopyASCIItoUTF16(appName, aAppCodeName);
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
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".
|
2017-07-31 07:23:50 +03:00
|
|
|
nsAutoString acceptLang;
|
|
|
|
Preferences::GetLocalizedString("intl.accept_languages", acceptLang);
|
2011-11-02 17:44:16 +04:00
|
|
|
|
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()) {
|
2017-06-20 12:19:52 +03:00
|
|
|
const nsAString& code = localeTokenizer.nextToken();
|
2014-05-12 15:48:15 +04:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2018-01-22 20:59:15 +03:00
|
|
|
void
|
2014-05-12 15:48:15 +04:00
|
|
|
Navigator::GetLanguage(nsAString& aLanguage)
|
|
|
|
{
|
|
|
|
nsTArray<nsString> languages;
|
|
|
|
GetLanguages(languages);
|
|
|
|
if (languages.Length() >= 1) {
|
|
|
|
aLanguage.Assign(languages[0]);
|
|
|
|
} else {
|
|
|
|
aLanguage.Truncate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2017-06-01 09:54:59 +03:00
|
|
|
// If fingerprinting resistance is on, we will spoof this value. See nsRFPService.h
|
|
|
|
// for details about spoofed values.
|
|
|
|
if (nsContentUtils::ShouldResistFingerprinting()) {
|
|
|
|
aOSCPU.AssignLiteral(SPOOFED_OSCPU);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-31 07:23:50 +03:00
|
|
|
nsAutoString override;
|
|
|
|
nsresult rv = Preferences::GetString("general.oscpu.override", override);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-11-02 17:44:16 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-01-22 20:59:15 +03:00
|
|
|
void
|
2011-11-02 17:44:16 +04:00
|
|
|
Navigator::GetVendor(nsAString& aVendor)
|
|
|
|
{
|
|
|
|
aVendor.Truncate();
|
|
|
|
}
|
|
|
|
|
2018-01-22 20:59:15 +03:00
|
|
|
void
|
2011-11-02 17:44:16 +04:00
|
|
|
Navigator::GetVendorSub(nsAString& aVendorSub)
|
|
|
|
{
|
|
|
|
aVendorSub.Truncate();
|
|
|
|
}
|
|
|
|
|
2018-01-22 20:59:15 +03:00
|
|
|
void
|
2011-11-02 17:44:16 +04:00
|
|
|
Navigator::GetProduct(nsAString& aProduct)
|
|
|
|
{
|
2012-07-27 16:09:59 +04:00
|
|
|
aProduct.AssignLiteral("Gecko");
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2018-01-22 20:59:15 +03:00
|
|
|
void
|
2011-11-02 17:44:16 +04:00
|
|
|
Navigator::GetProductSub(nsAString& aProductSub)
|
|
|
|
{
|
2012-07-27 16:09:59 +04:00
|
|
|
// Legacy build ID hardcoded for backward compatibility (bug 776376)
|
2017-06-01 09:54:59 +03:00
|
|
|
aProductSub.AssignLiteral(LEGACY_BUILD_ID);
|
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) {
|
2018-02-23 01:28:39 +03:00
|
|
|
mStorageManager = new StorageManager(mWindow->AsGlobal());
|
2016-06-14 15:57:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2017-10-03 09:37:11 +03:00
|
|
|
nsresult rv = permMgr->CanAccess(doc->NodePrincipal(), &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) {
|
2017-06-01 09:54:59 +03:00
|
|
|
// If fingerprinting resistance is on, we will spoof this value. See nsRFPService.h
|
|
|
|
// for details about spoofed values.
|
|
|
|
if (nsContentUtils::ShouldResistFingerprinting()) {
|
|
|
|
aBuildID.AssignLiteral(LEGACY_BUILD_ID);
|
|
|
|
return;
|
|
|
|
}
|
2017-07-31 07:23:50 +03:00
|
|
|
nsAutoString override;
|
|
|
|
nsresult rv = Preferences::GetString("general.buildID.override", override);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-11-02 17:44:16 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-01-22 20:59:15 +03:00
|
|
|
void
|
2011-11-02 17:44:16 +04:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-12 18:35:35 +04:00
|
|
|
bool
|
2016-12-17 08:25:52 +03:00
|
|
|
Navigator::JavaEnabled(CallerType aCallerType, 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
|
2017-07-31 07:23:50 +03:00
|
|
|
nsAutoString javaMIME;
|
|
|
|
Preferences::GetString("plugin.java.mime", javaMIME);
|
2014-02-11 03:50:53 +04:00
|
|
|
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();
|
|
|
|
|
2016-12-17 08:25:52 +03:00
|
|
|
nsMimeType *mimeType = mMimeTypes->NamedItem(javaMIME, aCallerType);
|
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()
|
|
|
|
{
|
2018-01-31 10:24:59 +03:00
|
|
|
workerinternals::RuntimeService* rts =
|
|
|
|
workerinternals::RuntimeService::GetOrCreateService();
|
2016-03-16 22:41:38 +03:00
|
|
|
if (!rts) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rts->ClampedHardwareConcurrency();
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
// Hidden documents cannot start or stop a vibration.
|
|
|
|
return (doc && !doc->Hidden());
|
|
|
|
}
|
|
|
|
|
2011-11-11 01:26:36 +04:00
|
|
|
NS_IMETHODIMP
|
2018-04-20 07:49:29 +03:00
|
|
|
VibrateWindowListener::HandleEvent(Event* aEvent)
|
2011-11-11 01:26:36 +04:00
|
|
|
{
|
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) {
|
2018-04-10 05:20:36 +03:00
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
|
|
|
|
if (!permMgr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
permMgr->AddFromPrincipal(doc->NodePrincipal(), kVibrationPermissionType,
|
|
|
|
aPermitted ? nsIPermissionManager::ALLOW_ACTION :
|
|
|
|
nsIPermissionManager::DENY_ACTION,
|
|
|
|
nsIPermissionManager::EXPIRE_SESSION, 0);
|
2016-04-26 16:40:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2018-04-10 05:20:36 +03:00
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
|
|
|
|
if (!permMgr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t permission = nsIPermissionManager::UNKNOWN_ACTION;
|
|
|
|
|
|
|
|
permMgr->TestPermissionFromPrincipal(doc->NodePrincipal(), kVibrationPermissionType,
|
|
|
|
&permission);
|
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
|
|
|
}
|
|
|
|
|
2018-02-04 15:10:10 +03:00
|
|
|
if (!mWindow->IsSecureContext() && mWindow->GetDoc()) {
|
|
|
|
mWindow->GetDoc()->WarnOnceAbout(nsIDocument::eRegisterProtocolHandlerInsecure);
|
|
|
|
}
|
|
|
|
|
2011-11-02 17:44:16 +04:00
|
|
|
nsCOMPtr<nsIWebContentHandlerRegistrar> registrar =
|
|
|
|
do_GetService(NS_WEBCONTENTHANDLERREGISTRAR_CONTRACTID);
|
|
|
|
if (!registrar) {
|
2013-07-18 07:23:52 +04:00
|
|
|
return;
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
aRv = registrar->RegisterProtocolHandler(aProtocol, aURI, aTitle,
|
|
|
|
mWindow->GetOuterWindow());
|
2011-11-02 17:44:16 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 18:35: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,
|
2017-02-09 12:37:54 +03:00
|
|
|
const Nullable<fetch::BodyInit>& aData,
|
2014-03-06 19:51:23 +04:00
|
|
|
ErrorResult& aRv)
|
2017-01-24 14:13:31 +03:00
|
|
|
{
|
|
|
|
if (aData.IsNull()) {
|
2017-01-24 14:14:27 +03:00
|
|
|
return SendBeaconInternal(aUrl, nullptr, eBeaconTypeOther, aRv);
|
2017-01-24 14:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aData.Value().IsArrayBuffer()) {
|
|
|
|
BodyExtractor<const ArrayBuffer> body(&aData.Value().GetAsArrayBuffer());
|
2017-01-24 14:14:27 +03:00
|
|
|
return SendBeaconInternal(aUrl, &body, eBeaconTypeArrayBuffer, aRv);
|
2017-01-24 14:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aData.Value().IsArrayBufferView()) {
|
|
|
|
BodyExtractor<const ArrayBufferView> body(&aData.Value().GetAsArrayBufferView());
|
2017-01-24 14:14:27 +03:00
|
|
|
return SendBeaconInternal(aUrl, &body, eBeaconTypeArrayBuffer, aRv);
|
2017-01-24 14:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aData.Value().IsBlob()) {
|
2017-09-20 04:32:12 +03:00
|
|
|
BodyExtractor<const Blob> body(&aData.Value().GetAsBlob());
|
2017-01-24 14:14:27 +03:00
|
|
|
return SendBeaconInternal(aUrl, &body, eBeaconTypeBlob, aRv);
|
2017-01-24 14:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aData.Value().IsFormData()) {
|
2017-09-20 04:32:12 +03:00
|
|
|
BodyExtractor<const FormData> body(&aData.Value().GetAsFormData());
|
2017-01-24 14:14:27 +03:00
|
|
|
return SendBeaconInternal(aUrl, &body, eBeaconTypeOther, aRv);
|
2017-01-24 14:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aData.Value().IsUSVString()) {
|
|
|
|
BodyExtractor<const nsAString> body(&aData.Value().GetAsUSVString());
|
2017-01-24 14:14:27 +03:00
|
|
|
return SendBeaconInternal(aUrl, &body, eBeaconTypeOther, aRv);
|
2017-01-24 14:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aData.Value().IsURLSearchParams()) {
|
2017-09-20 04:32:12 +03:00
|
|
|
BodyExtractor<const URLSearchParams> body(&aData.Value().GetAsURLSearchParams());
|
2017-01-24 14:14:27 +03:00
|
|
|
return SendBeaconInternal(aUrl, &body, eBeaconTypeOther, aRv);
|
2017-01-24 14:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CRASH("Invalid data type.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Navigator::SendBeaconInternal(const nsAString& aUrl,
|
|
|
|
BodyExtractorBase* aBody,
|
2017-01-24 14:14:27 +03:00
|
|
|
BeaconType aType,
|
2017-01-24 14:13:31 +03:00
|
|
|
ErrorResult& aRv)
|
2014-03-06 19:51:23 +04:00
|
|
|
{
|
|
|
|
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
|
2017-01-24 14:14:27 +03:00
|
|
|
nsSecurityFlags securityFlags = aType == eBeaconTypeBlob
|
2017-01-24 14:13:31 +03:00
|
|
|
? nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS
|
|
|
|
: nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS;
|
2016-07-26 14:46:01 +03:00
|
|
|
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,
|
2018-01-24 19:17:31 +03:00
|
|
|
nullptr, // aPerformanceStorage
|
2015-12-18 19:28:00 +03:00
|
|
|
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;
|
|
|
|
}
|
2017-03-17 06:53:16 +03:00
|
|
|
mozilla::net::ReferrerPolicy referrerPolicy = doc->GetReferrerPolicy();
|
|
|
|
rv = httpChannel->SetReferrerWithPolicy(documentURI, referrerPolicy);
|
2016-12-20 06:49:32 +03:00
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
2014-03-06 19:51:23 +04:00
|
|
|
|
2017-01-24 14:13:31 +03:00
|
|
|
nsCOMPtr<nsIInputStream> in;
|
|
|
|
nsAutoCString contentTypeWithCharset;
|
|
|
|
nsAutoCString charset;
|
|
|
|
uint64_t length = 0;
|
2014-04-16 11:30:26 +04:00
|
|
|
|
2017-01-24 14:13:31 +03:00
|
|
|
if (aBody) {
|
|
|
|
aRv = aBody->GetAsStream(getter_AddRefs(in), &length,
|
|
|
|
contentTypeWithCharset, charset);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
2014-03-06 19:51:23 +04:00
|
|
|
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;
|
|
|
|
}
|
2017-01-24 14:13:31 +03:00
|
|
|
|
|
|
|
uploadChannel->ExplicitSetUploadStream(in, contentTypeWithCharset, length,
|
2014-03-06 19:51:23 +04:00
|
|
|
NS_LITERAL_CSTRING("POST"),
|
|
|
|
false);
|
|
|
|
} else {
|
2016-12-20 06:49:32 +03:00
|
|
|
rv = httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("POST"));
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
2014-03-06 19:51:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2017-02-01 23:43:38 +03:00
|
|
|
CallerType aCallerType,
|
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();
|
2017-02-01 23:43:38 +03:00
|
|
|
aRv = manager->GetUserMedia(mWindow, aConstraints, onsuccess, onerror,
|
|
|
|
aCallerType);
|
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-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;
|
|
|
|
}
|
|
|
|
|
2018-02-23 01:28:39 +03:00
|
|
|
RefPtr<Promise> batteryPromise = Promise::Create(mWindow->AsGlobal(), 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;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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());
|
2017-11-04 01:25:38 +03:00
|
|
|
nsGlobalWindowInner* win = nsGlobalWindowInner::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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-11-04 01:25:38 +03:00
|
|
|
nsGlobalWindowInner* win = nsGlobalWindowInner::Cast(mWindow);
|
2016-07-05 01:46:49 +03:00
|
|
|
win->NotifyVREventListenerAdded();
|
|
|
|
|
2018-02-23 01:28:39 +03:00
|
|
|
RefPtr<Promise> p = Promise::Create(mWindow->AsGlobal(), aRv);
|
2014-07-09 23:24:49 +04:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-11-24 22:50:43 +03:00
|
|
|
// We pass mWindow's id to RefreshVRDisplays, so NotifyVRDisplaysUpdated will
|
2016-07-05 01:46:49 +03:00
|
|
|
// be called asynchronously, resolving the promises in mVRGetDisplaysPromises.
|
2016-11-24 22:50:43 +03:00
|
|
|
if (!VRDisplay::RefreshVRDisplays(win->WindowID())) {
|
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.
|
2017-09-21 01:39:35 +03:00
|
|
|
* GetActiveVRDisplays should only enumerate displays that
|
|
|
|
* are already active without causing any other hardware to be
|
|
|
|
* activated.
|
|
|
|
* We must not call nsGlobalWindow::NotifyVREventListenerAdded here,
|
|
|
|
* as that would cause enumeration and activation of other VR hardware.
|
|
|
|
* Activating VR hardware is intrusive to the end user, as it may
|
|
|
|
* involve physically powering on devices that the user did not
|
|
|
|
* intend to use.
|
2016-07-05 01:52:21 +03:00
|
|
|
*/
|
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-11-04 01:25:38 +03:00
|
|
|
nsGlobalWindowInner* win = nsGlobalWindowInner::Cast(mWindow);
|
2016-07-05 01:52:21 +03:00
|
|
|
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
|
2017-11-04 01:25:38 +03:00
|
|
|
nsGlobalWindowInner* win = nsGlobalWindowInner::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);
|
|
|
|
}
|
|
|
|
|
2017-03-01 13:33:28 +03:00
|
|
|
VRServiceTest*
|
|
|
|
Navigator::RequestVRServiceTest()
|
|
|
|
{
|
2017-03-30 16:35:49 +03:00
|
|
|
// Ensure that the Mock VR devices are not released prematurely
|
2017-11-04 01:25:38 +03:00
|
|
|
nsGlobalWindowInner* win = nsGlobalWindowInner::Cast(mWindow);
|
2017-03-30 16:35:49 +03:00
|
|
|
win->NotifyVREventListenerAdded();
|
|
|
|
|
2017-03-01 13:33:28 +03:00
|
|
|
if (!mVRServiceTest) {
|
|
|
|
mVRServiceTest = VRServiceTest::CreateTestService(mWindow);
|
|
|
|
}
|
|
|
|
return mVRServiceTest;
|
|
|
|
}
|
|
|
|
|
2017-05-09 02:01:36 +03:00
|
|
|
bool
|
|
|
|
Navigator::IsWebVRContentDetected() const
|
|
|
|
{
|
2017-11-04 01:25:38 +03:00
|
|
|
nsGlobalWindowInner* win = nsGlobalWindowInner::Cast(mWindow);
|
2017-05-09 02:01:36 +03:00
|
|
|
return win->IsVRContentDetected();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Navigator::IsWebVRContentPresenting() const
|
|
|
|
{
|
2017-11-04 01:25:38 +03:00
|
|
|
nsGlobalWindowInner* win = nsGlobalWindowInner::Cast(mWindow);
|
2017-05-09 02:01:36 +03:00
|
|
|
return win->IsVRContentPresenting();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Navigator::RequestVRPresentation(VRDisplay& aDisplay)
|
|
|
|
{
|
2017-11-04 01:25:38 +03:00
|
|
|
nsGlobalWindowInner* win = nsGlobalWindowInner::Cast(mWindow);
|
2017-05-09 02:01:36 +03:00
|
|
|
win->DispatchVRDisplayActivate(aDisplay.DisplayId(), VRDisplayEventReason::Requested);
|
|
|
|
}
|
|
|
|
|
2017-11-15 22:18:58 +03:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
Navigator::RequestMIDIAccess(const MIDIOptions& aOptions,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
MIDIAccessManager* accessMgr = MIDIAccessManager::Get();
|
|
|
|
return accessMgr->RequestMIDIAccess(mWindow, aOptions, aRv);
|
|
|
|
}
|
|
|
|
|
2018-01-22 20:59:15 +03:00
|
|
|
nsINetworkProperties*
|
|
|
|
Navigator::GetNetworkProperties()
|
2012-01-16 16:23:28 +04:00
|
|
|
{
|
2018-02-01 22:21:14 +03:00
|
|
|
return GetConnection(IgnoreErrors());
|
2013-07-12 18:35:44 +04:00
|
|
|
}
|
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;
|
|
|
|
}
|
2016-12-16 10:50:23 +03:00
|
|
|
mConnection = network::Connection::CreateForWindow(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
|
|
|
}
|
|
|
|
|
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) {
|
2018-03-22 23:03:22 +03:00
|
|
|
mServiceWorkerContainer = ServiceWorkerContainer::Create(mWindow->AsGlobal());
|
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
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
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: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);
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
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) {
|
2017-06-01 09:54:59 +03:00
|
|
|
// If fingerprinting resistance is on, we will spoof this value. See nsRFPService.h
|
|
|
|
// for details about spoofed values.
|
|
|
|
if (nsContentUtils::ShouldResistFingerprinting()) {
|
|
|
|
aPlatform.AssignLiteral(SPOOFED_PLATFORM);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-07-31 07:23:50 +03:00
|
|
|
nsAutoString override;
|
|
|
|
nsresult rv =
|
|
|
|
mozilla::Preferences::GetString("general.platform.override", override);
|
2011-11-02 17:44:16 +04:00
|
|
|
|
2017-07-31 07:23:50 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-11-02 17:44:16 +04:00
|
|
|
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) {
|
2017-06-01 09:54:59 +03:00
|
|
|
// If fingerprinting resistance is on, we will spoof this value. See nsRFPService.h
|
|
|
|
// for details about spoofed values.
|
|
|
|
if (nsContentUtils::ShouldResistFingerprinting()) {
|
|
|
|
aAppVersion.AssignLiteral(SPOOFED_APPVERSION);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-07-31 07:23:50 +03:00
|
|
|
nsAutoString override;
|
|
|
|
nsresult rv =
|
|
|
|
mozilla::Preferences::GetString("general.appversion.override", override);
|
2011-11-02 17:44:16 +04:00
|
|
|
|
2017-07-31 07:23:50 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-11-02 17:44:16 +04:00
|
|
|
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) {
|
2017-06-01 09:54:59 +03:00
|
|
|
// If fingerprinting resistance is on, we will spoof this value. See nsRFPService.h
|
|
|
|
// for details about spoofed values.
|
|
|
|
if (nsContentUtils::ShouldResistFingerprinting()) {
|
|
|
|
aAppName.AssignLiteral(SPOOFED_APPNAME);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-31 07:23:50 +03:00
|
|
|
nsAutoString override;
|
|
|
|
nsresult rv =
|
|
|
|
mozilla::Preferences::GetString("general.appname.override", override);
|
2011-11-02 17:44:16 +04:00
|
|
|
|
2017-07-31 07:23:50 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-11-02 17:44:16 +04:00
|
|
|
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
|
2017-03-25 06:00:12 +03:00
|
|
|
Navigator::GetUserAgent(nsPIDOMWindowInner* aWindow,
|
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
|
|
|
|
2017-06-01 09:54:59 +03:00
|
|
|
// We will skip the override and pass to httpHandler to get spoofed userAgent
|
|
|
|
// when 'privacy.resistFingerprinting' is true.
|
|
|
|
if (!aIsCallerChrome &&
|
|
|
|
!nsContentUtils::ShouldResistFingerprinting()) {
|
2017-07-31 07:23:50 +03:00
|
|
|
nsAutoString override;
|
|
|
|
nsresult rv =
|
|
|
|
mozilla::Preferences::GetString("general.useragent.override", override);
|
2014-09-24 20:09:50 +04:00
|
|
|
|
2017-07-31 07:23:50 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2014-09-24 20:09:50 +04:00
|
|
|
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);
|
|
|
|
|
2017-06-01 09:54:59 +03:00
|
|
|
// When the caller is content, we will always return spoofed userAgent and
|
|
|
|
// ignore the User-Agent header from the document channel when
|
|
|
|
// 'privacy.resistFingerprinting' is true.
|
|
|
|
if (!aWindow ||
|
|
|
|
(nsContentUtils::ShouldResistFingerprinting() && !aIsCallerChrome)) {
|
2014-09-24 20:09:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-25 06:00:12 +03:00
|
|
|
// Copy the User-Agent header from the document channel which has already been
|
|
|
|
// subject to UA overrides.
|
|
|
|
nsCOMPtr<nsIDocument> doc = aWindow->GetExtantDoc();
|
|
|
|
if (!doc) {
|
2014-09-24 20:09:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-03-25 06:00:12 +03:00
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel =
|
|
|
|
do_QueryInterface(doc->GetChannel());
|
|
|
|
if (httpChannel) {
|
|
|
|
nsAutoCString userAgent;
|
|
|
|
rv = httpChannel->GetRequestHeader(NS_LITERAL_CSTRING("User-Agent"),
|
|
|
|
userAgent);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
CopyASCIItoUTF16(userAgent, aUserAgent);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
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
|
2017-04-28 08:46:30 +03:00
|
|
|
RequestKeySystemAccessLogString(
|
|
|
|
const nsAString& aKeySystem,
|
|
|
|
const Sequence<MediaKeySystemConfiguration>& aConfigs,
|
|
|
|
bool aIsSecureContext)
|
2015-10-27 04:10:51 +03:00
|
|
|
{
|
|
|
|
nsCString str;
|
|
|
|
str.AppendPrintf("Navigator::RequestMediaKeySystemAccess(keySystem='%s' options=",
|
|
|
|
NS_ConvertUTF16toUTF8(aKeySystem).get());
|
2017-05-29 01:34:38 +03:00
|
|
|
str.Append(MediaKeySystemAccess::ToCString(aConfigs));
|
2017-04-28 08:46:30 +03:00
|
|
|
str.AppendLiteral(") secureContext=");
|
|
|
|
str.AppendInt(aIsSecureContext);
|
2015-10-27 04:10:51 +03:00
|
|
|
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)
|
|
|
|
{
|
2017-04-28 08:46:30 +03:00
|
|
|
EME_LOG("%s",
|
|
|
|
RequestKeySystemAccessLogString(
|
|
|
|
aKeySystem, aConfigs, mWindow->IsSecureContext())
|
|
|
|
.get());
|
|
|
|
|
|
|
|
Telemetry::Accumulate(Telemetry::MEDIA_EME_SECURE_CONTEXT,
|
|
|
|
mWindow->IsSecureContext());
|
2015-07-27 02:52:19 +03:00
|
|
|
|
2017-05-01 07:55:03 +03:00
|
|
|
if (!mWindow->IsSecureContext()) {
|
|
|
|
nsIDocument* doc = mWindow->GetExtantDoc();
|
|
|
|
nsString uri;
|
|
|
|
if (doc) {
|
|
|
|
Unused << doc->GetDocumentURI(uri);
|
|
|
|
}
|
|
|
|
const char16_t* params[] = { uri.get() };
|
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
|
|
|
NS_LITERAL_CSTRING("Media"),
|
|
|
|
doc,
|
|
|
|
nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
"MediaEMEInsecureContextDeprecatedWarning",
|
|
|
|
params,
|
|
|
|
ArrayLength(params));
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DetailedPromise> promise =
|
2018-02-23 01:28:39 +03:00
|
|
|
DetailedPromise::Create(mWindow->AsGlobal(), aRv,
|
2015-09-23 07:43:46 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-05-23 03:09:49 +03:00
|
|
|
CredentialsContainer*
|
|
|
|
Navigator::Credentials()
|
|
|
|
{
|
|
|
|
if (!mCredentials) {
|
|
|
|
mCredentials = new CredentialsContainer(GetWindow());
|
|
|
|
}
|
|
|
|
return mCredentials;
|
|
|
|
}
|
|
|
|
|
2018-01-27 22:42:17 +03:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::Webdriver()
|
|
|
|
{
|
|
|
|
return Preferences::GetBool("marionette.enabled", false);
|
|
|
|
}
|
|
|
|
|
2014-09-24 20:09:50 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|