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-07-17 23:09:13 +04:00
|
|
|
|
2015-11-24 08:04:21 +03:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2018-05-31 15:32:51 +03:00
|
|
|
#include "mozilla/dom/MediaCapabilities.h"
|
2014-02-24 17:57:15 +04:00
|
|
|
#include "mozilla/dom/Promise.h"
|
|
|
|
#include "mozilla/dom/PromiseWorkerProxy.h"
|
2016-06-14 15:57:36 +03:00
|
|
|
#include "mozilla/dom/StorageManager.h"
|
2016-03-19 00:15:46 +03:00
|
|
|
#include "mozilla/dom/WorkerNavigator.h"
|
2013-09-30 08:15:37 +04:00
|
|
|
#include "mozilla/dom/WorkerNavigatorBinding.h"
|
2016-12-16 10:50:23 +03:00
|
|
|
#include "mozilla/dom/network/Connection.h"
|
2018-09-10 21:36:17 +03:00
|
|
|
#include "mozilla/StaticPrefs.h"
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2014-02-24 17:57:15 +04:00
|
|
|
#include "nsProxyRelease.h"
|
2017-06-01 09:54:59 +03:00
|
|
|
#include "nsRFPService.h"
|
2013-06-05 18:04:23 +04:00
|
|
|
#include "RuntimeService.h"
|
|
|
|
|
2014-09-24 20:09:50 +04:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
|
2014-02-24 17:57:15 +04:00
|
|
|
#include "WorkerPrivate.h"
|
|
|
|
#include "WorkerRunnable.h"
|
|
|
|
#include "WorkerScope.h"
|
|
|
|
|
2016-04-29 04:02:45 +03:00
|
|
|
#include "mozilla/dom/Navigator.h"
|
|
|
|
|
2016-03-19 00:15:46 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2018-02-08 10:26:05 +03:00
|
|
|
using namespace workerinternals;
|
|
|
|
|
2016-12-16 10:50:23 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WorkerNavigator, mStorageManager,
|
2018-05-31 15:32:51 +03:00
|
|
|
mConnection, mMediaCapabilities);
|
2016-12-16 10:50:23 +03:00
|
|
|
|
2013-09-30 08:15:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WorkerNavigator, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WorkerNavigator, Release)
|
|
|
|
|
2016-12-16 10:50:23 +03:00
|
|
|
WorkerNavigator::WorkerNavigator(const NavigatorProperties& aProperties,
|
|
|
|
bool aOnline)
|
|
|
|
: mProperties(aProperties)
|
|
|
|
, mOnline(aOnline)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkerNavigator::~WorkerNavigator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-24 11:38:23 +04:00
|
|
|
/* static */ already_AddRefed<WorkerNavigator>
|
2013-11-20 03:08:50 +04:00
|
|
|
WorkerNavigator::Create(bool aOnLine)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-07-24 11:38:23 +04:00
|
|
|
RuntimeService* rts = RuntimeService::GetService();
|
|
|
|
MOZ_ASSERT(rts);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-11-20 03:08:50 +04:00
|
|
|
const RuntimeService::NavigatorProperties& properties =
|
|
|
|
rts->GetNavigatorProperties();
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WorkerNavigator> navigator =
|
2014-09-23 23:11:18 +04:00
|
|
|
new WorkerNavigator(properties, aOnLine);
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-07-24 11:38:23 +04:00
|
|
|
return navigator.forget();
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-09-30 08:15:37 +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
|
|
|
WorkerNavigator::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2018-06-26 00:20:54 +03:00
|
|
|
return WorkerNavigator_Binding::Wrap(aCx, this, aGivenProto);
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2014-09-05 18:26:34 +04:00
|
|
|
void
|
|
|
|
WorkerNavigator::SetLanguages(const nsTArray<nsString>& aLanguages)
|
|
|
|
{
|
2018-06-26 00:20:54 +03:00
|
|
|
WorkerNavigator_Binding::ClearCachedLanguagesValue(this);
|
2014-09-23 23:11:18 +04:00
|
|
|
mProperties.mLanguages = aLanguages;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-11-16 01:44:43 +03:00
|
|
|
WorkerNavigator::GetAppName(nsString& aAppName, CallerType aCallerType) const
|
2014-09-23 23:11:18 +04:00
|
|
|
{
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
2017-06-01 09:54:59 +03:00
|
|
|
if ((!mProperties.mAppNameOverridden.IsEmpty() ||
|
2018-09-10 21:36:17 +03:00
|
|
|
StaticPrefs::privacy_resistFingerprinting()) &&
|
2014-09-23 23:11:18 +04:00
|
|
|
!workerPrivate->UsesSystemPrincipal()) {
|
2017-06-01 09:54:59 +03:00
|
|
|
// We will spoof this value when 'privacy.resistFingerprinting' is true.
|
|
|
|
// See nsRFPService.h for spoofed value.
|
2018-09-10 21:36:17 +03:00
|
|
|
aAppName = StaticPrefs::privacy_resistFingerprinting() ?
|
2017-06-01 09:54:59 +03:00
|
|
|
NS_LITERAL_STRING(SPOOFED_APPNAME) : mProperties.mAppNameOverridden;
|
2014-09-23 23:11:18 +04:00
|
|
|
} else {
|
|
|
|
aAppName = mProperties.mAppName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-11-16 01:44:43 +03:00
|
|
|
WorkerNavigator::GetAppVersion(nsString& aAppVersion, CallerType aCallerType,
|
|
|
|
ErrorResult& aRv) const
|
2014-09-23 23:11:18 +04:00
|
|
|
{
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
2017-06-01 09:54:59 +03:00
|
|
|
if ((!mProperties.mAppVersionOverridden.IsEmpty() ||
|
2018-09-10 21:36:17 +03:00
|
|
|
StaticPrefs::privacy_resistFingerprinting()) &&
|
2014-09-23 23:11:18 +04:00
|
|
|
!workerPrivate->UsesSystemPrincipal()) {
|
2017-06-01 09:54:59 +03:00
|
|
|
// We will spoof this value when 'privacy.resistFingerprinting' is true.
|
|
|
|
// See nsRFPService.h for spoofed value.
|
2018-09-10 21:36:17 +03:00
|
|
|
aAppVersion = StaticPrefs::privacy_resistFingerprinting() ?
|
2017-06-01 09:54:59 +03:00
|
|
|
NS_LITERAL_STRING(SPOOFED_APPVERSION) : mProperties.mAppVersionOverridden;
|
2014-09-23 23:11:18 +04:00
|
|
|
} else {
|
|
|
|
aAppVersion = mProperties.mAppVersion;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-11-16 01:44:43 +03:00
|
|
|
WorkerNavigator::GetPlatform(nsString& aPlatform, CallerType aCallerType,
|
|
|
|
ErrorResult& aRv) const
|
2014-09-23 23:11:18 +04:00
|
|
|
{
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
2017-06-01 09:54:59 +03:00
|
|
|
if ((!mProperties.mPlatformOverridden.IsEmpty() ||
|
2018-09-10 21:36:17 +03:00
|
|
|
StaticPrefs::privacy_resistFingerprinting()) &&
|
2014-09-23 23:11:18 +04:00
|
|
|
!workerPrivate->UsesSystemPrincipal()) {
|
2017-06-01 09:54:59 +03:00
|
|
|
// We will spoof this value when 'privacy.resistFingerprinting' is true.
|
|
|
|
// See nsRFPService.h for spoofed value.
|
2018-09-10 21:36:17 +03:00
|
|
|
aPlatform = StaticPrefs::privacy_resistFingerprinting() ?
|
2017-06-01 09:54:59 +03:00
|
|
|
NS_LITERAL_STRING(SPOOFED_PLATFORM) : mProperties.mPlatformOverridden;
|
2014-09-23 23:11:18 +04:00
|
|
|
} else {
|
|
|
|
aPlatform = mProperties.mPlatform;
|
|
|
|
}
|
2014-09-05 18:26:34 +04:00
|
|
|
}
|
|
|
|
|
2014-09-24 20:09:50 +04:00
|
|
|
namespace {
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class GetUserAgentRunnable final : public WorkerMainThreadRunnable
|
2014-09-24 20:09:50 +04:00
|
|
|
{
|
|
|
|
nsString& mUA;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GetUserAgentRunnable(WorkerPrivate* aWorkerPrivate, nsString& aUA)
|
2016-05-03 10:09:47 +03:00
|
|
|
: WorkerMainThreadRunnable(aWorkerPrivate,
|
|
|
|
NS_LITERAL_CSTRING("UserAgent getter"))
|
2014-09-24 20:09:50 +04:00
|
|
|
, mUA(aUA)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aWorkerPrivate);
|
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool MainThreadRun() override
|
2014-09-24 20:09:50 +04:00
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = mWorkerPrivate->GetWindow();
|
2014-09-24 20:09:50 +04:00
|
|
|
|
|
|
|
bool isCallerChrome = mWorkerPrivate->UsesSystemPrincipal();
|
2017-03-25 06:00:12 +03:00
|
|
|
nsresult rv = dom::Navigator::GetUserAgent(window, isCallerChrome, mUA);
|
2014-09-24 20:09:50 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to retrieve user-agent from the worker thread.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2014-09-24 20:09:50 +04:00
|
|
|
|
|
|
|
void
|
2016-11-16 01:44:43 +03:00
|
|
|
WorkerNavigator::GetUserAgent(nsString& aUserAgent, CallerType aCallerType,
|
|
|
|
ErrorResult& aRv) const
|
2014-09-24 20:09:50 +04:00
|
|
|
{
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GetUserAgentRunnable> runnable =
|
2014-09-24 20:09:50 +04:00
|
|
|
new GetUserAgentRunnable(workerPrivate, aUserAgent);
|
|
|
|
|
2018-07-12 20:33:41 +03:00
|
|
|
runnable->Dispatch(Canceling, aRv);
|
2014-09-24 20:09:50 +04:00
|
|
|
}
|
|
|
|
|
2016-03-16 22:41:38 +03:00
|
|
|
uint64_t
|
|
|
|
WorkerNavigator::HardwareConcurrency() const
|
|
|
|
{
|
|
|
|
RuntimeService* rts = RuntimeService::GetService();
|
|
|
|
MOZ_ASSERT(rts);
|
|
|
|
|
|
|
|
return rts->ClampedHardwareConcurrency();
|
|
|
|
}
|
|
|
|
|
2016-06-14 15:57:36 +03:00
|
|
|
StorageManager*
|
|
|
|
WorkerNavigator::Storage()
|
|
|
|
{
|
|
|
|
if (!mStorageManager) {
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
|
|
|
RefPtr<nsIGlobalObject> global = workerPrivate->GlobalScope();
|
|
|
|
MOZ_ASSERT(global);
|
|
|
|
|
|
|
|
mStorageManager = new StorageManager(global);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mStorageManager;
|
|
|
|
}
|
|
|
|
|
2016-12-16 10:50:23 +03:00
|
|
|
network::Connection*
|
|
|
|
WorkerNavigator::GetConnection(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mConnection) {
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
|
|
|
mConnection = network::Connection::CreateForWorker(workerPrivate, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mConnection;
|
|
|
|
}
|
|
|
|
|
2018-05-31 15:32:51 +03:00
|
|
|
dom::MediaCapabilities*
|
|
|
|
WorkerNavigator::MediaCapabilities()
|
|
|
|
{
|
|
|
|
if (!mMediaCapabilities) {
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
|
|
|
nsIGlobalObject* global = workerPrivate->GlobalScope();
|
|
|
|
MOZ_ASSERT(global);
|
|
|
|
|
|
|
|
mMediaCapabilities = new dom::MediaCapabilities(global);
|
|
|
|
}
|
|
|
|
return mMediaCapabilities;
|
|
|
|
}
|
2016-12-16 10:50:23 +03:00
|
|
|
|
2016-03-19 00:15:46 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|