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
|
|
|
|
2014-02-24 17:57:15 +04:00
|
|
|
#include "DataStore.h"
|
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/DataStore.h"
|
|
|
|
#include "mozilla/dom/DataStoreBinding.h"
|
|
|
|
#include "mozilla/dom/Promise.h"
|
|
|
|
#include "mozilla/dom/PromiseWorkerProxy.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 "Navigator.h"
|
|
|
|
#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"
|
|
|
|
|
2013-07-24 11:38:23 +04:00
|
|
|
BEGIN_WORKERS_NAMESPACE
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-09-30 08:15:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WorkerNavigator)
|
|
|
|
|
|
|
|
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
|
|
|
{
|
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 WorkerNavigatorBinding_workers::Wrap(aCx, this, aGivenProto);
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2014-02-24 17:57:34 +04:00
|
|
|
// A WorkerMainThreadRunnable to synchronously add DataStoreChangeEventProxy on
|
|
|
|
// the main thread. We need this because we have to access |mBackingStore| on
|
|
|
|
// the main thread.
|
|
|
|
class DataStoreAddEventListenerRunnable : public WorkerMainThreadRunnable
|
|
|
|
{
|
|
|
|
nsMainThreadPtrHandle<DataStore> mBackingStore;
|
|
|
|
DataStoreChangeEventProxy* mEventProxy;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool
|
2015-03-21 19:28:04 +03:00
|
|
|
MainThreadRun() override
|
2014-02-24 17:57:34 +04:00
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
// Add |mEventProxy| as an event listner to DataStore.
|
|
|
|
if (NS_FAILED(mBackingStore->AddEventListener(NS_LITERAL_STRING("change"),
|
|
|
|
mEventProxy,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
2))) {
|
|
|
|
MOZ_ASSERT(false, "failed to add event listener!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
DataStoreAddEventListenerRunnable(
|
|
|
|
WorkerPrivate* aWorkerPrivate,
|
|
|
|
const nsMainThreadPtrHandle<DataStore>& aBackingStore,
|
|
|
|
DataStoreChangeEventProxy* aEventProxy)
|
|
|
|
: WorkerMainThreadRunnable(aWorkerPrivate)
|
|
|
|
, mBackingStore(aBackingStore)
|
|
|
|
, mEventProxy(aEventProxy)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aWorkerPrivate);
|
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-24 17:57:15 +04:00
|
|
|
#define WORKER_DATA_STORES_TAG JS_SCTAG_USER_MIN
|
|
|
|
|
|
|
|
static JSObject*
|
2015-09-05 12:22:13 +03:00
|
|
|
GetDataStoresProxyCloneCallbacksRead(JSContext* aCx,
|
|
|
|
JSStructuredCloneReader* aReader,
|
|
|
|
const PromiseWorkerProxy* aProxy,
|
|
|
|
uint32_t aTag,
|
|
|
|
uint32_t aData)
|
2014-02-24 17:57:15 +04:00
|
|
|
{
|
|
|
|
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
workerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
if (aTag != WORKER_DATA_STORES_TAG) {
|
|
|
|
MOZ_ASSERT(false, "aTag must be WORKER_DATA_STORES_TAG!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!aData, "aData should be empty");
|
|
|
|
|
|
|
|
// Read the holder from the buffer, which points to the data store.
|
|
|
|
nsMainThreadPtrHolder<DataStore>* dataStoreholder;
|
|
|
|
if (!JS_ReadBytes(aReader, &dataStoreholder, sizeof(dataStoreholder))) {
|
|
|
|
MOZ_ASSERT(false, "cannot read bytes for dataStoreholder!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-26 02:35:36 +04:00
|
|
|
// Protect workerStoreObj from moving GC during ~nsRefPtr.
|
|
|
|
JS::Rooted<JSObject*> workerStoreObj(aCx, nullptr);
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WorkerDataStore> workerStore =
|
2014-06-26 02:35:36 +04:00
|
|
|
new WorkerDataStore(workerPrivate->GlobalScope());
|
2014-07-30 04:43:56 +04:00
|
|
|
nsMainThreadPtrHandle<DataStore> backingStore(dataStoreholder);
|
2014-06-26 02:35:36 +04:00
|
|
|
|
|
|
|
// When we're on the worker thread, prepare a DataStoreChangeEventProxy.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DataStoreChangeEventProxy> eventProxy =
|
2014-06-26 02:35:36 +04:00
|
|
|
new DataStoreChangeEventProxy(workerPrivate, workerStore);
|
|
|
|
|
|
|
|
// Add the DataStoreChangeEventProxy as an event listener on the main thread.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DataStoreAddEventListenerRunnable> runnable =
|
2014-06-26 02:35:36 +04:00
|
|
|
new DataStoreAddEventListenerRunnable(workerPrivate,
|
|
|
|
backingStore,
|
|
|
|
eventProxy);
|
2015-11-24 08:04:21 +03:00
|
|
|
ErrorResult rv;
|
|
|
|
runnable->Dispatch(rv);
|
|
|
|
if (rv.MaybeSetPendingException(aCx)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-06-26 02:35:36 +04:00
|
|
|
|
|
|
|
// Point WorkerDataStore to DataStore.
|
|
|
|
workerStore->SetBackingDataStore(backingStore);
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
|
|
|
|
if (!global) {
|
|
|
|
MOZ_ASSERT(false, "cannot get global!");
|
|
|
|
} else {
|
2015-05-14 00:07:34 +03:00
|
|
|
workerStoreObj = workerStore->WrapObject(aCx, nullptr);
|
2014-06-26 02:35:36 +04:00
|
|
|
if (!JS_WrapObject(aCx, &workerStoreObj)) {
|
|
|
|
MOZ_ASSERT(false, "cannot wrap object for workerStoreObj!");
|
|
|
|
workerStoreObj = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2014-02-24 17:57:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return workerStoreObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2015-09-05 12:22:13 +03:00
|
|
|
GetDataStoresProxyCloneCallbacksWrite(JSContext* aCx,
|
|
|
|
JSStructuredCloneWriter* aWriter,
|
|
|
|
PromiseWorkerProxy* aProxy,
|
|
|
|
JS::Handle<JSObject*> aObj)
|
2014-02-24 17:57:15 +04:00
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
if (!JS_WriteUint32Pair(aWriter, WORKER_DATA_STORES_TAG, 0)) {
|
|
|
|
MOZ_ASSERT(false, "cannot write pair for WORKER_DATA_STORES_TAG!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> storeObj(aCx, aObj);
|
|
|
|
|
|
|
|
DataStore* store = nullptr;
|
|
|
|
nsresult rv = UNWRAP_OBJECT(DataStore, storeObj, store);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MOZ_ASSERT(false, "cannot unwrap the DataStore object!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We keep the data store alive here.
|
2015-09-05 12:22:13 +03:00
|
|
|
aProxy->StoreISupports(store);
|
2014-02-24 17:57:15 +04:00
|
|
|
|
|
|
|
// Construct the nsMainThreadPtrHolder pointing to the data store.
|
|
|
|
nsMainThreadPtrHolder<DataStore>* dataStoreholder =
|
|
|
|
new nsMainThreadPtrHolder<DataStore>(store);
|
|
|
|
|
|
|
|
// And write the dataStoreholder into the buffer.
|
|
|
|
if (!JS_WriteBytes(aWriter, &dataStoreholder, sizeof(dataStoreholder))) {
|
|
|
|
MOZ_ASSERT(false, "cannot write bytes for dataStoreholder!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-05 12:22:13 +03:00
|
|
|
static const PromiseWorkerProxy::PromiseWorkerProxyStructuredCloneCallbacks
|
|
|
|
kGetDataStoresCloneCallbacks= {
|
|
|
|
GetDataStoresProxyCloneCallbacksRead,
|
|
|
|
GetDataStoresProxyCloneCallbacksWrite
|
2014-02-24 17:57:15 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// A WorkerMainThreadRunnable to run WorkerNavigator::GetDataStores(...) on the
|
|
|
|
// main thread.
|
2015-03-21 19:28:04 +03:00
|
|
|
class NavigatorGetDataStoresRunnable final : public WorkerMainThreadRunnable
|
2014-02-24 17:57:15 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PromiseWorkerProxy> mPromiseWorkerProxy;
|
2014-02-24 17:57:15 +04:00
|
|
|
const nsString mName;
|
2014-07-17 07:53:23 +04:00
|
|
|
const nsString mOwner;
|
2014-02-24 17:57:15 +04:00
|
|
|
ErrorResult& mRv;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NavigatorGetDataStoresRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
|
Promise* aWorkerPromise,
|
|
|
|
const nsAString& aName,
|
2014-07-17 07:53:23 +04:00
|
|
|
const nsAString& aOwner,
|
2014-02-24 17:57:15 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
: WorkerMainThreadRunnable(aWorkerPrivate)
|
|
|
|
, mName(aName)
|
2014-07-17 07:53:23 +04:00
|
|
|
, mOwner(aOwner)
|
2014-02-24 17:57:15 +04:00
|
|
|
, mRv(aRv)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aWorkerPrivate);
|
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2014-12-17 17:49:36 +03:00
|
|
|
// this might return null if the worker has started the close handler.
|
2014-02-24 17:57:15 +04:00
|
|
|
mPromiseWorkerProxy =
|
2014-12-17 17:49:36 +03:00
|
|
|
PromiseWorkerProxy::Create(aWorkerPrivate,
|
|
|
|
aWorkerPromise,
|
2015-09-05 12:22:13 +03:00
|
|
|
&kGetDataStoresCloneCallbacks);
|
2014-02-24 17:57:15 +04:00
|
|
|
}
|
|
|
|
|
2015-11-24 08:04:21 +03:00
|
|
|
void Dispatch(ErrorResult& aRv)
|
2014-12-17 17:49:36 +03:00
|
|
|
{
|
|
|
|
if (mPromiseWorkerProxy) {
|
2015-11-24 08:04:21 +03:00
|
|
|
WorkerMainThreadRunnable::Dispatch(aRv);
|
2014-12-17 17:49:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the creation of mProxyWorkerProxy failed, the worker is terminating.
|
|
|
|
// In this case we don't want to dispatch the runnable and we should stop
|
|
|
|
// the promise chain here.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-24 17:57:15 +04:00
|
|
|
protected:
|
|
|
|
virtual bool
|
2015-03-21 19:28:04 +03:00
|
|
|
MainThreadRun() override
|
2014-02-24 17:57:15 +04:00
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
// Walk up to the containing window.
|
|
|
|
WorkerPrivate* wp = mWorkerPrivate;
|
|
|
|
while (wp->GetParent()) {
|
|
|
|
wp = wp->GetParent();
|
|
|
|
}
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* window = wp->GetWindow();
|
2014-02-24 17:57:15 +04:00
|
|
|
|
|
|
|
// TODO SharedWorker has null window. Don't need to worry about at this
|
|
|
|
// point, though.
|
|
|
|
if (!window) {
|
|
|
|
mRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> promise =
|
2014-07-17 07:53:23 +04:00
|
|
|
Navigator::GetDataStores(window, mName, mOwner, mRv);
|
2014-02-24 17:57:15 +04:00
|
|
|
promise->AppendNativeHandler(mPromiseWorkerProxy);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
WorkerNavigator::GetDataStores(JSContext* aCx,
|
|
|
|
const nsAString& aName,
|
2014-07-17 07:53:23 +04:00
|
|
|
const nsAString& aOwner,
|
2014-02-24 17:57:15 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
workerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> promise = Promise::Create(workerPrivate->GlobalScope(), aRv);
|
2014-07-19 05:31:11 +04:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-02-24 17:57:15 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<NavigatorGetDataStoresRunnable> runnable =
|
2014-07-17 07:53:23 +04:00
|
|
|
new NavigatorGetDataStoresRunnable(workerPrivate, promise, aName, aOwner, aRv);
|
2015-11-24 08:04:21 +03:00
|
|
|
runnable->Dispatch(aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-02-24 17:57:15 +04:00
|
|
|
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2014-09-05 18:26:34 +04:00
|
|
|
void
|
|
|
|
WorkerNavigator::SetLanguages(const nsTArray<nsString>& aLanguages)
|
|
|
|
{
|
|
|
|
WorkerNavigatorBinding_workers::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)
|
|
|
|
: WorkerMainThreadRunnable(aWorkerPrivate)
|
|
|
|
, 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
|
|
|
}
|
|
|
|
|
2011-07-17 23:09:13 +04:00
|
|
|
END_WORKERS_NAMESPACE
|