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"
|
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"
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2014-02-24 17:57:15 +04:00
|
|
|
#include "nsProxyRelease.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
|
|
|
|
2016-04-06 23:27:22 +03:00
|
|
|
using namespace mozilla::dom::workers;
|
|
|
|
|
2016-06-14 15:57:36 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WorkerNavigator, mStorageManager);
|
2013-09-30 08:15:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WorkerNavigator, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WorkerNavigator, Release)
|
|
|
|
|
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
|
|
|
{
|
2016-03-19 00:15:46 +03:00
|
|
|
return WorkerNavigatorBinding::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)
|
|
|
|
{
|
2016-03-19 00:15:46 +03:00
|
|
|
WorkerNavigatorBinding::ClearCachedLanguagesValue(this);
|
2014-09-23 23:11:18 +04:00
|
|
|
mProperties.mLanguages = aLanguages;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WorkerNavigator::GetAppName(nsString& aAppName) const
|
|
|
|
{
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
|
|
|
if (!mProperties.mAppNameOverridden.IsEmpty() &&
|
|
|
|
!workerPrivate->UsesSystemPrincipal()) {
|
|
|
|
aAppName = mProperties.mAppNameOverridden;
|
|
|
|
} else {
|
|
|
|
aAppName = mProperties.mAppName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WorkerNavigator::GetAppVersion(nsString& aAppVersion) const
|
|
|
|
{
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
|
|
|
if (!mProperties.mAppVersionOverridden.IsEmpty() &&
|
|
|
|
!workerPrivate->UsesSystemPrincipal()) {
|
|
|
|
aAppVersion = mProperties.mAppVersionOverridden;
|
|
|
|
} else {
|
|
|
|
aAppVersion = mProperties.mAppVersion;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WorkerNavigator::GetPlatform(nsString& aPlatform) const
|
|
|
|
{
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
|
|
|
if (!mProperties.mPlatformOverridden.IsEmpty() &&
|
|
|
|
!workerPrivate->UsesSystemPrincipal()) {
|
|
|
|
aPlatform = mProperties.mPlatformOverridden;
|
|
|
|
} 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
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
if (window && window->GetDocShell()) {
|
|
|
|
nsIDocument* doc = window->GetExtantDoc();
|
|
|
|
if (doc) {
|
|
|
|
doc->NodePrincipal()->GetURI(getter_AddRefs(uri));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isCallerChrome = mWorkerPrivate->UsesSystemPrincipal();
|
|
|
|
nsresult rv = dom::Navigator::GetUserAgent(window, uri,
|
|
|
|
isCallerChrome, mUA);
|
|
|
|
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
|
2015-11-24 08:04:21 +03:00
|
|
|
WorkerNavigator::GetUserAgent(nsString& aUserAgent, 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);
|
|
|
|
|
2015-11-24 08:04:21 +03:00
|
|
|
runnable->Dispatch(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-03-19 00:15:46 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|