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
|
|
|
|
|
|
|
#include "WorkerScope.h"
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
2018-03-01 22:24:20 +03:00
|
|
|
#include "jsfriendapi.h"
|
2014-03-17 10:56:53 +04:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2014-12-17 09:26:15 +03:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2017-12-12 23:44:47 +03:00
|
|
|
#include "mozilla/dom/Clients.h"
|
2018-01-30 12:12:04 +03:00
|
|
|
#include "mozilla/dom/ClientState.h"
|
2014-09-10 19:21:32 +04:00
|
|
|
#include "mozilla/dom/Console.h"
|
2013-11-05 18:16:26 +04:00
|
|
|
#include "mozilla/dom/DedicatedWorkerGlobalScopeBinding.h"
|
2018-01-08 16:05:03 +03:00
|
|
|
#include "mozilla/dom/DOMPrefs.h"
|
2014-10-06 22:01:20 +04:00
|
|
|
#include "mozilla/dom/Fetch.h"
|
2014-09-10 19:21:32 +04:00
|
|
|
#include "mozilla/dom/FunctionBinding.h"
|
2016-02-17 00:46:08 +03:00
|
|
|
#include "mozilla/dom/IDBFactory.h"
|
2015-07-30 21:47:00 +03:00
|
|
|
#include "mozilla/dom/ImageBitmap.h"
|
2015-11-18 11:57:38 +03:00
|
|
|
#include "mozilla/dom/ImageBitmapBinding.h"
|
2016-06-09 20:04:42 +03:00
|
|
|
#include "mozilla/dom/Performance.h"
|
2014-09-10 19:21:32 +04:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2015-07-02 15:54:00 +03:00
|
|
|
#include "mozilla/dom/PromiseWorkerProxy.h"
|
2014-05-14 01:28:01 +04:00
|
|
|
#include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h"
|
2013-11-05 18:16:26 +04:00
|
|
|
#include "mozilla/dom/SharedWorkerGlobalScopeBinding.h"
|
2016-04-04 19:29:16 +03:00
|
|
|
#include "mozilla/dom/SimpleGlobalObject.h"
|
2015-03-04 02:51:53 +03:00
|
|
|
#include "mozilla/dom/WorkerDebuggerGlobalScopeBinding.h"
|
|
|
|
#include "mozilla/dom/WorkerGlobalScopeBinding.h"
|
2016-03-16 21:51:11 +03:00
|
|
|
#include "mozilla/dom/WorkerLocation.h"
|
2016-03-19 00:15:46 +03:00
|
|
|
#include "mozilla/dom/WorkerNavigator.h"
|
2015-03-02 16:23:00 +03:00
|
|
|
#include "mozilla/dom/cache/CacheStorage.h"
|
2014-09-10 19:21:32 +04:00
|
|
|
#include "mozilla/Services.h"
|
2018-09-10 21:36:14 +03:00
|
|
|
#include "mozilla/StaticPrefs.h"
|
2014-09-10 19:21:32 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIServiceWorkerManager.h"
|
2018-01-30 12:12:04 +03:00
|
|
|
#include "nsIScriptError.h"
|
2016-08-16 09:10:30 +03:00
|
|
|
#include "nsIScriptTimeoutHandler.h"
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2014-02-12 01:01:29 +04:00
|
|
|
#ifdef ANDROID
|
|
|
|
#include <android/log.h>
|
|
|
|
#endif
|
|
|
|
|
2015-09-21 20:29:41 +03:00
|
|
|
#include "Crypto.h"
|
2013-12-10 15:43:16 +04:00
|
|
|
#include "Principal.h"
|
|
|
|
#include "RuntimeService.h"
|
|
|
|
#include "ScriptLoader.h"
|
|
|
|
#include "WorkerPrivate.h"
|
2014-09-10 19:21:32 +04:00
|
|
|
#include "WorkerRunnable.h"
|
2018-01-27 00:08:59 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerManager.h"
|
2018-01-27 00:08:58 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerRegistration.h"
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2015-07-02 15:54:00 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#undef PostMessage
|
|
|
|
#endif
|
|
|
|
|
2016-08-16 09:10:30 +03:00
|
|
|
extern already_AddRefed<nsIScriptTimeoutHandler>
|
|
|
|
NS_CreateJSTimeoutHandler(JSContext* aCx,
|
2018-01-31 10:24:08 +03:00
|
|
|
mozilla::dom::WorkerPrivate* aWorkerPrivate,
|
2016-08-16 09:10:30 +03:00
|
|
|
mozilla::dom::Function& aFunction,
|
|
|
|
const mozilla::dom::Sequence<JS::Value>& aArguments,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
|
|
|
|
extern already_AddRefed<nsIScriptTimeoutHandler>
|
|
|
|
NS_CreateJSTimeoutHandler(JSContext* aCx,
|
2018-01-31 10:24:08 +03:00
|
|
|
mozilla::dom::WorkerPrivate* aWorkerPrivate,
|
2018-09-17 18:53:10 +03:00
|
|
|
const nsAString& aExpression,
|
|
|
|
mozilla::ErrorResult& aRv);
|
2016-08-16 09:10:30 +03:00
|
|
|
|
2018-01-31 10:24:30 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2015-03-02 16:23:00 +03:00
|
|
|
using mozilla::dom::cache::CacheStorage;
|
2014-12-17 09:26:15 +03:00
|
|
|
using mozilla::ipc::PrincipalInfo;
|
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
WorkerGlobalScope::WorkerGlobalScope(WorkerPrivate* aWorkerPrivate)
|
2017-07-21 18:16:24 +03:00
|
|
|
: mSerialEventTarget(aWorkerPrivate->HybridEventTarget())
|
2017-06-29 21:28:56 +03:00
|
|
|
, mWindowInteractionsAllowed(0)
|
2015-07-23 18:30:27 +03:00
|
|
|
, mWorkerPrivate(aWorkerPrivate)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-11-05 18:16:26 +04:00
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2017-06-29 21:28:56 +03:00
|
|
|
|
|
|
|
// We should always have an event target when the global is created.
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mSerialEventTarget);
|
2013-11-05 18:16:26 +04:00
|
|
|
}
|
2013-09-09 07:28:48 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
WorkerGlobalScope::~WorkerGlobalScope()
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2014-02-26 23:00:40 +04:00
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2013-11-05 18:16:26 +04:00
|
|
|
}
|
2012-04-27 00:57:33 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(WorkerGlobalScope)
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(WorkerGlobalScope,
|
2014-04-01 10:13:50 +04:00
|
|
|
DOMEventTargetHelper)
|
2013-11-05 18:16:26 +04:00
|
|
|
tmp->mWorkerPrivate->AssertIsOnWorkerThread();
|
2014-08-08 16:34:30 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConsole)
|
2015-09-21 20:29:41 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCrypto)
|
2014-08-30 03:50:06 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPerformance)
|
2014-09-03 00:02:06 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLocation)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNavigator)
|
2014-12-17 09:26:15 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIndexedDB)
|
2015-03-02 16:23:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCacheStorage)
|
2015-05-07 10:05:43 +03:00
|
|
|
tmp->TraverseHostObjectURIs(cb);
|
2016-08-16 09:10:30 +03:00
|
|
|
tmp->mWorkerPrivate->TraverseTimeouts(cb);
|
2013-11-05 18:16:26 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(WorkerGlobalScope,
|
2014-04-01 10:13:50 +04:00
|
|
|
DOMEventTargetHelper)
|
2013-11-05 18:16:26 +04:00
|
|
|
tmp->mWorkerPrivate->AssertIsOnWorkerThread();
|
2014-08-08 16:34:30 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mConsole)
|
2015-09-21 20:29:41 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCrypto)
|
2014-08-30 03:50:06 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPerformance)
|
2014-09-03 00:02:06 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mLocation)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mNavigator)
|
2014-12-17 09:26:15 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIndexedDB)
|
2015-03-02 16:23:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCacheStorage)
|
2015-05-07 10:05:43 +03:00
|
|
|
tmp->UnlinkHostObjectURIs();
|
2016-08-16 09:10:30 +03:00
|
|
|
tmp->mWorkerPrivate->UnlinkTimeouts();
|
2013-11-05 18:16:26 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(WorkerGlobalScope,
|
2014-04-01 10:13:50 +04:00
|
|
|
DOMEventTargetHelper)
|
2013-11-05 18:16:26 +04:00
|
|
|
tmp->mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
2013-08-09 02:55:23 +04:00
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(WorkerGlobalScope, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(WorkerGlobalScope, DOMEventTargetHelper)
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WorkerGlobalScope)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
|
2015-01-18 06:17:06 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-11-05 18:16:26 +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
|
|
|
WorkerGlobalScope::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-06-05 18:04:23 +04:00
|
|
|
{
|
2013-11-05 18:16:26 +04:00
|
|
|
MOZ_CRASH("We should never get here!");
|
|
|
|
}
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2018-04-10 21:00:57 +03:00
|
|
|
void
|
|
|
|
WorkerGlobalScope::NoteTerminating()
|
|
|
|
{
|
|
|
|
DisconnectEventTargetObjects();
|
2018-07-30 20:35:42 +03:00
|
|
|
StartDying();
|
2018-04-10 21:00:57 +03:00
|
|
|
}
|
|
|
|
|
2017-12-20 16:35:34 +03:00
|
|
|
already_AddRefed<Console>
|
2016-03-24 00:55:07 +03:00
|
|
|
WorkerGlobalScope::GetConsole(ErrorResult& aRv)
|
2014-01-26 16:35:17 +04:00
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
if (!mConsole) {
|
2018-02-22 10:49:51 +03:00
|
|
|
mConsole = Console::Create(mWorkerPrivate->GetJSContext(),
|
|
|
|
nullptr, aRv);
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-01-26 16:35:17 +04:00
|
|
|
}
|
|
|
|
|
2017-12-20 16:35:34 +03:00
|
|
|
RefPtr<Console> console = mConsole;
|
|
|
|
return console.forget();
|
2014-01-26 16:35:17 +04:00
|
|
|
}
|
|
|
|
|
2015-09-21 20:29:41 +03:00
|
|
|
Crypto*
|
|
|
|
WorkerGlobalScope::GetCrypto(ErrorResult& aError)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
if (!mCrypto) {
|
2018-02-08 15:22:20 +03:00
|
|
|
mCrypto = new Crypto(this);
|
2015-09-21 20:29:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return mCrypto;
|
|
|
|
}
|
|
|
|
|
2015-03-02 16:23:00 +03:00
|
|
|
already_AddRefed<CacheStorage>
|
|
|
|
WorkerGlobalScope::GetCaches(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mCacheStorage) {
|
|
|
|
MOZ_ASSERT(mWorkerPrivate);
|
|
|
|
mCacheStorage = CacheStorage::CreateOnWorker(cache::DEFAULT_NAMESPACE, this,
|
|
|
|
mWorkerPrivate, aRv);
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CacheStorage> ref = mCacheStorage;
|
2015-03-02 16:23:00 +03:00
|
|
|
return ref.forget();
|
|
|
|
}
|
|
|
|
|
2016-10-10 22:09:00 +03:00
|
|
|
bool
|
|
|
|
WorkerGlobalScope::IsSecureContext() const
|
|
|
|
{
|
|
|
|
bool globalSecure =
|
2018-06-03 13:22:28 +03:00
|
|
|
JS::GetIsSecureContext(js::GetNonCCWObjectRealm(GetWrapperPreserveColor()));
|
2016-10-10 22:09:00 +03:00
|
|
|
MOZ_ASSERT(globalSecure == mWorkerPrivate->IsSecureContext());
|
|
|
|
return globalSecure;
|
|
|
|
}
|
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
already_AddRefed<WorkerLocation>
|
|
|
|
WorkerGlobalScope::Location()
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
if (!mLocation) {
|
|
|
|
WorkerPrivate::LocationInfo& info = mWorkerPrivate->GetLocationInfo();
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
mLocation = WorkerLocation::Create(info);
|
|
|
|
MOZ_ASSERT(mLocation);
|
2013-06-05 18:04:23 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WorkerLocation> location = mLocation;
|
2013-11-05 18:16:26 +04:00
|
|
|
return location.forget();
|
|
|
|
}
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
already_AddRefed<WorkerNavigator>
|
|
|
|
WorkerGlobalScope::Navigator()
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
if (!mNavigator) {
|
2013-11-20 03:08:50 +04:00
|
|
|
mNavigator = WorkerNavigator::Create(mWorkerPrivate->OnLine());
|
2013-11-05 18:16:26 +04:00
|
|
|
MOZ_ASSERT(mNavigator);
|
2013-06-05 18:04:23 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WorkerNavigator> navigator = mNavigator;
|
2013-11-05 18:16:26 +04:00
|
|
|
return navigator.forget();
|
|
|
|
}
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-20 03:08:50 +04:00
|
|
|
already_AddRefed<WorkerNavigator>
|
|
|
|
WorkerGlobalScope::GetExistingNavigator() const
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WorkerNavigator> navigator = mNavigator;
|
2013-11-20 03:08:50 +04:00
|
|
|
return navigator.forget();
|
|
|
|
}
|
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
OnErrorEventHandlerNonNull*
|
|
|
|
WorkerGlobalScope::GetOnerror()
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager* elm = GetExistingListenerManager();
|
2013-11-05 18:16:26 +04:00
|
|
|
return elm ? elm->GetOnErrorEventHandler() : nullptr;
|
|
|
|
}
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
void
|
|
|
|
WorkerGlobalScope::SetOnerror(OnErrorEventHandlerNonNull* aHandler)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager* elm = GetOrCreateListenerManager();
|
2013-11-05 18:16:26 +04:00
|
|
|
if (elm) {
|
|
|
|
elm->SetEventHandler(aHandler);
|
2013-06-05 18:04:23 +04:00
|
|
|
}
|
2013-11-05 18:16:26 +04:00
|
|
|
}
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
void
|
2016-02-29 22:52:42 +03:00
|
|
|
WorkerGlobalScope::ImportScripts(const Sequence<nsString>& aScriptURLs,
|
2013-11-05 18:16:26 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2018-01-31 10:22:03 +03:00
|
|
|
workerinternals::Load(mWorkerPrivate, aScriptURLs, WorkerScript, aRv);
|
2013-11-05 18:16:26 +04:00
|
|
|
}
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
int32_t
|
|
|
|
WorkerGlobalScope::SetTimeout(JSContext* aCx,
|
|
|
|
Function& aHandler,
|
|
|
|
const int32_t aTimeout,
|
|
|
|
const Sequence<JS::Value>& aArguments,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2016-08-16 09:10:30 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptTimeoutHandler> handler =
|
|
|
|
NS_CreateJSTimeoutHandler(aCx, mWorkerPrivate, aHandler, aArguments, aRv);
|
2018-09-17 18:53:10 +03:00
|
|
|
if (!handler) {
|
2016-08-16 09:10:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mWorkerPrivate->SetTimeout(aCx, handler, aTimeout, false, aRv);
|
2013-11-05 18:16:26 +04:00
|
|
|
}
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
int32_t
|
2016-04-07 00:20:30 +03:00
|
|
|
WorkerGlobalScope::SetTimeout(JSContext* aCx,
|
2014-02-19 19:13:38 +04:00
|
|
|
const nsAString& aHandler,
|
2013-11-05 18:16:26 +04:00
|
|
|
const int32_t aTimeout,
|
2014-02-19 19:13:38 +04:00
|
|
|
const Sequence<JS::Value>& /* unused */,
|
2013-11-05 18:16:26 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2016-08-16 09:10:30 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptTimeoutHandler> handler =
|
2018-09-17 18:53:10 +03:00
|
|
|
NS_CreateJSTimeoutHandler(aCx, mWorkerPrivate, aHandler, aRv);
|
|
|
|
if (!handler) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-16 09:10:30 +03:00
|
|
|
return mWorkerPrivate->SetTimeout(aCx, handler, aTimeout, false, aRv);
|
2013-11-05 18:16:26 +04:00
|
|
|
}
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
void
|
2016-03-10 12:50:56 +03:00
|
|
|
WorkerGlobalScope::ClearTimeout(int32_t aHandle)
|
2013-11-05 18:16:26 +04:00
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
mWorkerPrivate->ClearTimeout(aHandle);
|
|
|
|
}
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
int32_t
|
|
|
|
WorkerGlobalScope::SetInterval(JSContext* aCx,
|
|
|
|
Function& aHandler,
|
2018-05-03 06:20:00 +03:00
|
|
|
const int32_t aTimeout,
|
2013-11-05 18:16:26 +04:00
|
|
|
const Sequence<JS::Value>& aArguments,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2016-08-16 09:10:30 +03:00
|
|
|
nsCOMPtr<nsIScriptTimeoutHandler> handler =
|
|
|
|
NS_CreateJSTimeoutHandler(aCx, mWorkerPrivate, aHandler, aArguments, aRv);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-05-03 06:20:00 +03:00
|
|
|
return mWorkerPrivate->SetTimeout(aCx, handler, aTimeout, true, aRv);
|
2013-11-05 18:16:26 +04:00
|
|
|
}
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
int32_t
|
2016-04-07 00:57:44 +03:00
|
|
|
WorkerGlobalScope::SetInterval(JSContext* aCx,
|
2014-02-19 19:13:38 +04:00
|
|
|
const nsAString& aHandler,
|
2018-05-03 06:20:00 +03:00
|
|
|
const int32_t aTimeout,
|
2014-02-19 19:13:38 +04:00
|
|
|
const Sequence<JS::Value>& /* unused */,
|
2013-11-05 18:16:26 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
Sequence<JS::Value> dummy;
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2016-08-16 09:10:30 +03:00
|
|
|
nsCOMPtr<nsIScriptTimeoutHandler> handler =
|
2018-09-17 18:53:10 +03:00
|
|
|
NS_CreateJSTimeoutHandler(aCx, mWorkerPrivate, aHandler, aRv);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-05-03 06:20:00 +03:00
|
|
|
return mWorkerPrivate->SetTimeout(aCx, handler, aTimeout, true, aRv);
|
2013-11-05 18:16:26 +04:00
|
|
|
}
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
void
|
2016-03-10 12:50:56 +03:00
|
|
|
WorkerGlobalScope::ClearInterval(int32_t aHandle)
|
2013-11-05 18:16:26 +04:00
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
mWorkerPrivate->ClearTimeout(aHandle);
|
|
|
|
}
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2017-02-14 00:06:47 +03:00
|
|
|
void
|
|
|
|
WorkerGlobalScope::GetOrigin(nsAString& aOrigin) const
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
aOrigin = mWorkerPrivate->Origin();
|
|
|
|
}
|
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
void
|
|
|
|
WorkerGlobalScope::Atob(const nsAString& aAtob, nsAString& aOutput, ErrorResult& aRv) const
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
aRv = nsContentUtils::Atob(aAtob, aOutput);
|
|
|
|
}
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
void
|
|
|
|
WorkerGlobalScope::Btoa(const nsAString& aBtoa, nsAString& aOutput, ErrorResult& aRv) const
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
aRv = nsContentUtils::Btoa(aBtoa, aOutput);
|
|
|
|
}
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
void
|
|
|
|
WorkerGlobalScope::Dump(const Optional<nsAString>& aString) const
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
if (!aString.WasPassed()) {
|
|
|
|
return;
|
2013-06-05 18:04:23 +04:00
|
|
|
}
|
|
|
|
|
2015-10-24 19:06:57 +03:00
|
|
|
#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
|
2018-01-08 16:05:03 +03:00
|
|
|
if (!DOMPrefs::DumpEnabled()) {
|
2013-11-05 18:16:26 +04:00
|
|
|
return;
|
2013-06-05 18:04:23 +04:00
|
|
|
}
|
2015-10-24 19:06:57 +03:00
|
|
|
#endif
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2014-02-12 01:01:29 +04:00
|
|
|
NS_ConvertUTF16toUTF8 str(aString.Value());
|
|
|
|
|
2016-01-07 00:18:29 +03:00
|
|
|
MOZ_LOG(nsContentUtils::DOMDumpLog(), LogLevel::Debug, ("[Worker.Dump] %s", str.get()));
|
2014-02-12 01:01:29 +04:00
|
|
|
#ifdef ANDROID
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", str.get());
|
|
|
|
#endif
|
|
|
|
fputs(str.get(), stdout);
|
|
|
|
fflush(stdout);
|
2013-11-05 18:16:26 +04:00
|
|
|
}
|
2013-06-05 18:04:23 +04:00
|
|
|
|
2014-08-30 03:50:06 +04:00
|
|
|
Performance*
|
|
|
|
WorkerGlobalScope::GetPerformance()
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
if (!mPerformance) {
|
2016-06-09 20:04:42 +03:00
|
|
|
mPerformance = Performance::CreateForWorker(mWorkerPrivate);
|
2014-08-30 03:50:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return mPerformance;
|
|
|
|
}
|
|
|
|
|
2018-03-01 22:24:20 +03:00
|
|
|
bool
|
|
|
|
WorkerGlobalScope::IsInAutomation(JSContext* aCx, JSObject* /* unused */)
|
|
|
|
{
|
|
|
|
return GetWorkerPrivateFromContext(aCx)->IsInAutomation();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WorkerGlobalScope::GetJSTestingFunctions(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JSObject*> aFunctions,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
JSObject* obj = js::GetTestingFunctions(aCx);
|
|
|
|
if (!obj) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aFunctions.set(obj);
|
|
|
|
}
|
|
|
|
|
2014-07-25 05:30:07 +04:00
|
|
|
already_AddRefed<Promise>
|
2014-11-20 14:58:00 +03:00
|
|
|
WorkerGlobalScope::Fetch(const RequestOrUSVString& aInput,
|
2017-02-01 23:43:37 +03:00
|
|
|
const RequestInit& aInit,
|
|
|
|
CallerType aCallerType, ErrorResult& aRv)
|
2014-07-25 05:30:07 +04:00
|
|
|
{
|
2017-02-01 23:43:37 +03:00
|
|
|
return FetchRequest(this, aInput, aInit, aCallerType, aRv);
|
2014-07-25 05:30:07 +04:00
|
|
|
}
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
already_AddRefed<IDBFactory>
|
|
|
|
WorkerGlobalScope::GetIndexedDB(ErrorResult& aErrorResult)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBFactory> indexedDB = mIndexedDB;
|
2014-12-17 09:26:15 +03:00
|
|
|
|
|
|
|
if (!indexedDB) {
|
2015-07-16 00:01:02 +03:00
|
|
|
if (!mWorkerPrivate->IsStorageAllowed()) {
|
2014-12-17 09:26:15 +03:00
|
|
|
NS_WARNING("IndexedDB is not allowed in this worker!");
|
2015-07-16 00:01:02 +03:00
|
|
|
aErrorResult = NS_ERROR_DOM_SECURITY_ERR;
|
2014-12-17 09:26:15 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext* cx = mWorkerPrivate->GetJSContext();
|
|
|
|
MOZ_ASSERT(cx);
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> owningObject(cx, GetGlobalJSObject());
|
|
|
|
MOZ_ASSERT(owningObject);
|
|
|
|
|
|
|
|
const PrincipalInfo& principalInfo = mWorkerPrivate->GetPrincipalInfo();
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
IDBFactory::CreateForWorker(cx,
|
|
|
|
owningObject,
|
|
|
|
principalInfo,
|
|
|
|
mWorkerPrivate->WindowID(),
|
|
|
|
getter_AddRefs(indexedDB));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
aErrorResult = rv;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mIndexedDB = indexedDB;
|
|
|
|
}
|
|
|
|
|
|
|
|
return indexedDB.forget();
|
|
|
|
}
|
|
|
|
|
2015-07-30 21:47:00 +03:00
|
|
|
already_AddRefed<Promise>
|
2017-03-18 03:36:13 +03:00
|
|
|
WorkerGlobalScope::CreateImageBitmap(JSContext* aCx,
|
|
|
|
const ImageBitmapSource& aImage,
|
2015-07-30 21:47:00 +03:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
return ImageBitmap::Create(this, aImage, Nothing(), aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2017-03-18 03:36:13 +03:00
|
|
|
WorkerGlobalScope::CreateImageBitmap(JSContext* aCx,
|
|
|
|
const ImageBitmapSource& aImage,
|
2015-07-30 21:47:00 +03:00
|
|
|
int32_t aSx, int32_t aSy, int32_t aSw, int32_t aSh,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
return ImageBitmap::Create(this, aImage, Some(gfx::IntRect(aSx, aSy, aSw, aSh)), aRv);
|
|
|
|
}
|
|
|
|
|
2017-06-29 21:28:56 +03:00
|
|
|
nsresult
|
2017-07-26 11:13:35 +03:00
|
|
|
WorkerGlobalScope::Dispatch(TaskCategory aCategory,
|
2017-06-29 21:28:56 +03:00
|
|
|
already_AddRefed<nsIRunnable>&& aRunnable)
|
|
|
|
{
|
2018-05-30 22:15:35 +03:00
|
|
|
return EventTargetFor(aCategory)->Dispatch(std::move(aRunnable),
|
2017-06-29 21:28:56 +03:00
|
|
|
NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsISerialEventTarget*
|
|
|
|
WorkerGlobalScope::EventTargetFor(TaskCategory aCategory) const
|
|
|
|
{
|
|
|
|
return mSerialEventTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractThread*
|
|
|
|
WorkerGlobalScope::AbstractMainThreadFor(TaskCategory aCategory)
|
|
|
|
{
|
|
|
|
MOZ_CRASH("AbstractMainThreadFor not supported for workers.");
|
|
|
|
}
|
|
|
|
|
2018-01-12 04:46:08 +03:00
|
|
|
Maybe<ClientInfo>
|
|
|
|
WorkerGlobalScope::GetClientInfo() const
|
|
|
|
{
|
2018-05-02 16:29:26 +03:00
|
|
|
return mWorkerPrivate->GetClientInfo();
|
2018-01-12 04:46:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<ClientState>
|
|
|
|
WorkerGlobalScope::GetClientState() const
|
|
|
|
{
|
|
|
|
Maybe<ClientState> state;
|
|
|
|
state.emplace(mWorkerPrivate->GetClientState());
|
2018-06-01 18:59:07 +03:00
|
|
|
return state;
|
2018-01-12 04:46:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<ServiceWorkerDescriptor>
|
|
|
|
WorkerGlobalScope::GetController() const
|
|
|
|
{
|
|
|
|
return mWorkerPrivate->GetController();
|
|
|
|
}
|
|
|
|
|
2018-07-02 17:44:18 +03:00
|
|
|
RefPtr<mozilla::dom::ServiceWorkerRegistration>
|
|
|
|
WorkerGlobalScope::GetServiceWorkerRegistration(const ServiceWorkerRegistrationDescriptor& aDescriptor) const
|
2018-03-03 00:02:49 +03:00
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
RefPtr<ServiceWorkerRegistration> ref;
|
|
|
|
ForEachEventTargetObject([&] (DOMEventTargetHelper* aTarget, bool* aDoneOut) {
|
|
|
|
RefPtr<ServiceWorkerRegistration> swr = do_QueryObject(aTarget);
|
|
|
|
if (!swr || !swr->MatchesDescriptor(aDescriptor)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ref = swr.forget();
|
|
|
|
*aDoneOut = true;
|
|
|
|
});
|
2018-07-02 17:44:18 +03:00
|
|
|
return ref.forget();
|
|
|
|
}
|
2018-03-03 00:02:49 +03:00
|
|
|
|
2018-07-02 17:44:18 +03:00
|
|
|
RefPtr<ServiceWorkerRegistration>
|
|
|
|
WorkerGlobalScope::GetOrCreateServiceWorkerRegistration(const ServiceWorkerRegistrationDescriptor& aDescriptor)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
RefPtr<ServiceWorkerRegistration> ref = GetServiceWorkerRegistration(aDescriptor);
|
2018-03-03 00:02:49 +03:00
|
|
|
if (!ref) {
|
2018-03-03 00:02:50 +03:00
|
|
|
ref = ServiceWorkerRegistration::CreateForWorker(mWorkerPrivate, this,
|
|
|
|
aDescriptor);
|
2018-03-03 00:02:49 +03:00
|
|
|
}
|
|
|
|
return ref.forget();
|
|
|
|
}
|
|
|
|
|
2017-05-17 17:48:54 +03:00
|
|
|
DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
|
2017-05-17 17:49:34 +03:00
|
|
|
const nsString& aName)
|
2017-05-17 17:48:54 +03:00
|
|
|
: WorkerGlobalScope(aWorkerPrivate)
|
|
|
|
, mName(aName)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-09 00:56:42 +03:00
|
|
|
bool
|
|
|
|
DedicatedWorkerGlobalScope::WrapGlobalObject(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JSObject*> aReflector)
|
2011-07-17 23:09:13 +04:00
|
|
|
{
|
2013-11-05 18:16:26 +04:00
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
MOZ_ASSERT(!mWorkerPrivate->IsSharedWorker());
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2018-05-17 11:59:45 +03:00
|
|
|
JS::RealmOptions options;
|
|
|
|
mWorkerPrivate->CopyJSRealmOptions(options);
|
2013-12-10 15:43:16 +04:00
|
|
|
|
2015-06-11 00:12:55 +03:00
|
|
|
const bool usesSystemPrincipal = mWorkerPrivate->UsesSystemPrincipal();
|
|
|
|
|
|
|
|
// Note that xpc::ShouldDiscardSystemSource() and
|
|
|
|
// xpc::ExtraWarningsForSystemJS() read prefs that are cached on the main
|
|
|
|
// thread. This is benignly racey.
|
2016-04-21 16:48:59 +03:00
|
|
|
const bool discardSource = usesSystemPrincipal &&
|
2015-06-11 00:12:55 +03:00
|
|
|
xpc::ShouldDiscardSystemSource();
|
|
|
|
const bool extraWarnings = usesSystemPrincipal &&
|
|
|
|
xpc::ExtraWarningsForSystemJS();
|
|
|
|
|
2018-05-17 11:59:45 +03:00
|
|
|
JS::RealmBehaviors& behaviors = options.behaviors();
|
2015-12-29 01:15:52 +03:00
|
|
|
behaviors.setDiscardSource(discardSource)
|
|
|
|
.extraWarningsOverride().set(extraWarnings);
|
2015-06-11 00:12:55 +03:00
|
|
|
|
2018-09-25 17:11:13 +03:00
|
|
|
xpc::SetPrefableRealmOptions(options);
|
2016-01-06 18:31:38 +03:00
|
|
|
|
2018-06-26 00:20:54 +03:00
|
|
|
return DedicatedWorkerGlobalScope_Binding::Wrap(aCx, this, this,
|
2016-06-28 20:47:23 +03:00
|
|
|
options,
|
|
|
|
GetWorkerPrincipal(),
|
|
|
|
true, aReflector);
|
2013-11-05 18:16:26 +04:00
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
void
|
|
|
|
DedicatedWorkerGlobalScope::PostMessage(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aMessage,
|
2017-02-03 13:00:38 +03:00
|
|
|
const Sequence<JSObject*>& aTransferable,
|
2013-11-05 18:16:26 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
mWorkerPrivate->PostMessageToParent(aCx, aMessage, aTransferable, aRv);
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2018-10-29 18:26:30 +03:00
|
|
|
void
|
|
|
|
DedicatedWorkerGlobalScope::PostMessage(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aMessage,
|
|
|
|
const PostMessageOptions& aOptions,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
mWorkerPrivate->PostMessageToParent(aCx, aMessage, aOptions.mTransfer, aRv);
|
|
|
|
}
|
|
|
|
|
2017-02-03 10:35:19 +03:00
|
|
|
void
|
2018-03-13 17:25:50 +03:00
|
|
|
DedicatedWorkerGlobalScope::Close()
|
2017-02-03 10:35:19 +03:00
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2018-03-13 17:25:50 +03:00
|
|
|
mWorkerPrivate->CloseInternal();
|
2017-02-03 10:35:19 +03:00
|
|
|
}
|
|
|
|
|
2013-11-05 18:16:26 +04:00
|
|
|
SharedWorkerGlobalScope::SharedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
|
2017-05-17 17:49:34 +03:00
|
|
|
const nsString& aName)
|
2013-11-05 18:16:26 +04:00
|
|
|
: WorkerGlobalScope(aWorkerPrivate), mName(aName)
|
|
|
|
{
|
|
|
|
}
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2015-01-09 00:56:42 +03:00
|
|
|
bool
|
|
|
|
SharedWorkerGlobalScope::WrapGlobalObject(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JSObject*> aReflector)
|
2013-11-05 18:16:26 +04:00
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
MOZ_ASSERT(mWorkerPrivate->IsSharedWorker());
|
2011-07-17 23:09:13 +04:00
|
|
|
|
2018-05-17 11:59:45 +03:00
|
|
|
JS::RealmOptions options;
|
|
|
|
mWorkerPrivate->CopyJSRealmOptions(options);
|
2013-12-10 15:43:16 +04:00
|
|
|
|
2018-06-26 00:20:54 +03:00
|
|
|
return SharedWorkerGlobalScope_Binding::Wrap(aCx, this, this, options,
|
2016-06-28 20:47:23 +03:00
|
|
|
GetWorkerPrincipal(),
|
|
|
|
true, aReflector);
|
2011-07-17 23:09:13 +04:00
|
|
|
}
|
|
|
|
|
2017-02-03 10:35:19 +03:00
|
|
|
void
|
2018-03-13 17:25:50 +03:00
|
|
|
SharedWorkerGlobalScope::Close()
|
2017-02-03 10:35:19 +03:00
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2018-03-13 17:25:50 +03:00
|
|
|
mWorkerPrivate->CloseInternal();
|
2017-02-03 10:35:19 +03:00
|
|
|
}
|
|
|
|
|
2014-10-27 14:03:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(ServiceWorkerGlobalScope, WorkerGlobalScope,
|
2015-04-04 08:46:07 +03:00
|
|
|
mClients, mRegistration)
|
2017-08-30 02:02:48 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ServiceWorkerGlobalScope)
|
2014-10-27 14:03:00 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(WorkerGlobalScope)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(ServiceWorkerGlobalScope, WorkerGlobalScope)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(ServiceWorkerGlobalScope, WorkerGlobalScope)
|
|
|
|
|
2014-05-14 01:28:01 +04:00
|
|
|
ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
|
2018-02-14 22:23:15 +03:00
|
|
|
const ServiceWorkerRegistrationDescriptor& aRegistrationDescriptor)
|
|
|
|
: WorkerGlobalScope(aWorkerPrivate)
|
|
|
|
, mScope(NS_ConvertUTF8toUTF16(aRegistrationDescriptor.Scope()))
|
|
|
|
|
|
|
|
// Eagerly create the registration because we will need to receive updates
|
|
|
|
// about the state of the registration. We can't wait until first access
|
|
|
|
// to start receiving these.
|
2018-03-03 00:02:50 +03:00
|
|
|
, mRegistration(GetOrCreateServiceWorkerRegistration(aRegistrationDescriptor))
|
2014-05-14 01:28:01 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-10-27 14:03:00 +03:00
|
|
|
ServiceWorkerGlobalScope::~ServiceWorkerGlobalScope()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-09 00:56:42 +03:00
|
|
|
bool
|
|
|
|
ServiceWorkerGlobalScope::WrapGlobalObject(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JSObject*> aReflector)
|
2014-05-14 01:28:01 +04:00
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
MOZ_ASSERT(mWorkerPrivate->IsServiceWorker());
|
|
|
|
|
2018-05-17 11:59:45 +03:00
|
|
|
JS::RealmOptions options;
|
|
|
|
mWorkerPrivate->CopyJSRealmOptions(options);
|
2014-05-14 01:28:01 +04:00
|
|
|
|
2018-06-26 00:20:54 +03:00
|
|
|
return ServiceWorkerGlobalScope_Binding::Wrap(aCx, this, this, options,
|
2016-06-28 20:47:23 +03:00
|
|
|
GetWorkerPrincipal(),
|
|
|
|
true, aReflector);
|
2014-05-14 01:28:01 +04:00
|
|
|
}
|
|
|
|
|
2017-12-12 23:44:47 +03:00
|
|
|
already_AddRefed<Clients>
|
|
|
|
ServiceWorkerGlobalScope::GetClients()
|
2014-10-27 14:03:00 +03:00
|
|
|
{
|
|
|
|
if (!mClients) {
|
2017-12-12 23:44:47 +03:00
|
|
|
mClients = new Clients(this);
|
2014-10-27 14:03:00 +03:00
|
|
|
}
|
|
|
|
|
2017-12-12 23:44:47 +03:00
|
|
|
RefPtr<Clients> ref = mClients;
|
|
|
|
return ref.forget();
|
2014-10-27 14:03:00 +03:00
|
|
|
}
|
|
|
|
|
2016-06-12 17:26:51 +03:00
|
|
|
ServiceWorkerRegistration*
|
2015-04-04 08:46:07 +03:00
|
|
|
ServiceWorkerGlobalScope::Registration()
|
|
|
|
{
|
|
|
|
return mRegistration;
|
|
|
|
}
|
|
|
|
|
2016-12-19 05:38:53 +03:00
|
|
|
EventHandlerNonNull*
|
|
|
|
ServiceWorkerGlobalScope::GetOnfetch()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mWorkerPrivate);
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2018-07-25 01:15:19 +03:00
|
|
|
return GetEventHandler(nsGkAtoms::onfetch);
|
2016-12-19 05:38:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ReportFetchListenerWarningRunnable final : public Runnable
|
|
|
|
{
|
|
|
|
const nsCString mScope;
|
|
|
|
nsCString mSourceSpec;
|
|
|
|
uint32_t mLine;
|
|
|
|
uint32_t mColumn;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ReportFetchListenerWarningRunnable(const nsString& aScope)
|
2017-06-12 22:34:10 +03:00
|
|
|
: mozilla::Runnable("ReportFetchListenerWarningRunnable")
|
|
|
|
, mScope(NS_ConvertUTF16toUTF8(aScope))
|
2016-12-19 05:38:53 +03:00
|
|
|
{
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
JSContext* cx = workerPrivate->GetJSContext();
|
|
|
|
MOZ_ASSERT(cx);
|
|
|
|
|
|
|
|
nsJSUtils::GetCallingLocation(cx, mSourceSpec, &mLine, &mColumn);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
Run() override
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
ServiceWorkerManager::LocalizeAndReportToAllClients(mScope, "ServiceWorkerNoFetchHandler",
|
|
|
|
nsTArray<nsString>{}, nsIScriptError::warningFlag, NS_ConvertUTF8toUTF16(mSourceSpec),
|
|
|
|
EmptyString(), mLine, mColumn);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
void
|
|
|
|
ServiceWorkerGlobalScope::SetOnfetch(mozilla::dom::EventHandlerNonNull* aCallback)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mWorkerPrivate);
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
if (aCallback) {
|
|
|
|
if (mWorkerPrivate->WorkerScriptExecutedSuccessfully()) {
|
|
|
|
RefPtr<Runnable> r = new ReportFetchListenerWarningRunnable(mScope);
|
|
|
|
mWorkerPrivate->DispatchToMainThread(r.forget());
|
|
|
|
}
|
|
|
|
mWorkerPrivate->SetFetchHandlerWasAdded();
|
|
|
|
}
|
2018-07-25 01:15:19 +03:00
|
|
|
SetEventHandler(nsGkAtoms::onfetch, aCallback);
|
2016-12-19 05:38:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-07-25 01:15:19 +03:00
|
|
|
ServiceWorkerGlobalScope::EventListenerAdded(nsAtom* aType)
|
2016-12-19 05:38:53 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mWorkerPrivate);
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2018-07-25 01:15:19 +03:00
|
|
|
if (aType != nsGkAtoms::onfetch) {
|
2016-12-21 05:16:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-19 05:38:53 +03:00
|
|
|
if (mWorkerPrivate->WorkerScriptExecutedSuccessfully()) {
|
|
|
|
RefPtr<Runnable> r = new ReportFetchListenerWarningRunnable(mScope);
|
|
|
|
mWorkerPrivate->DispatchToMainThread(r.forget());
|
|
|
|
}
|
2016-12-21 05:16:00 +03:00
|
|
|
|
2018-04-05 20:42:42 +03:00
|
|
|
mWorkerPrivate->SetFetchHandlerWasAdded();
|
2016-12-19 05:38:53 +03:00
|
|
|
}
|
|
|
|
|
2015-06-02 14:12:00 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class SkipWaitingResultRunnable final : public WorkerRunnable
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PromiseWorkerProxy> mPromiseProxy;
|
2015-06-02 14:12:00 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
SkipWaitingResultRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
|
PromiseWorkerProxy* aPromiseProxy)
|
2016-06-28 20:28:13 +03:00
|
|
|
: WorkerRunnable(aWorkerPrivate)
|
2015-06-02 14:12:00 +03:00
|
|
|
, mPromiseProxy(aPromiseProxy)
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aWorkerPrivate);
|
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> promise = mPromiseProxy->WorkerPromise();
|
2016-08-09 12:15:13 +03:00
|
|
|
promise->MaybeResolveWithUndefined();
|
2015-06-02 14:12:00 +03:00
|
|
|
|
|
|
|
// Release the reference on the worker thread.
|
2016-02-29 22:52:42 +03:00
|
|
|
mPromiseProxy->CleanUp();
|
2015-06-02 14:12:00 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class WorkerScopeSkipWaitingRunnable final : public Runnable
|
2015-06-02 14:12:00 +03:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PromiseWorkerProxy> mPromiseProxy;
|
2015-06-02 14:12:00 +03:00
|
|
|
nsCString mScope;
|
|
|
|
|
|
|
|
public:
|
|
|
|
WorkerScopeSkipWaitingRunnable(PromiseWorkerProxy* aPromiseProxy,
|
|
|
|
const nsCString& aScope)
|
2017-06-12 22:34:10 +03:00
|
|
|
: mozilla::Runnable("WorkerScopeSkipWaitingRunnable")
|
|
|
|
, mPromiseProxy(aPromiseProxy)
|
2015-06-02 14:12:00 +03:00
|
|
|
, mScope(aScope)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aPromiseProxy);
|
|
|
|
}
|
|
|
|
|
2016-08-08 03:54:47 +03:00
|
|
|
NS_IMETHOD
|
2015-06-02 14:12:00 +03:00
|
|
|
Run() override
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
2015-09-02 20:07:26 +03:00
|
|
|
MutexAutoLock lock(mPromiseProxy->Lock());
|
|
|
|
if (mPromiseProxy->CleanedUp()) {
|
2015-06-02 14:12:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-02 20:07:26 +03:00
|
|
|
WorkerPrivate* workerPrivate = mPromiseProxy->GetWorkerPrivate();
|
2017-01-13 01:00:36 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(workerPrivate);
|
|
|
|
|
|
|
|
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
|
|
|
if (swm) {
|
|
|
|
swm->SetSkipWaitingFlag(workerPrivate->GetPrincipal(), mScope,
|
|
|
|
workerPrivate->ServiceWorkerID());
|
|
|
|
}
|
2015-06-02 14:12:00 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SkipWaitingResultRunnable> runnable =
|
2015-06-02 14:12:00 +03:00
|
|
|
new SkipWaitingResultRunnable(workerPrivate, mPromiseProxy);
|
|
|
|
|
2016-02-26 23:23:12 +03:00
|
|
|
if (!runnable->Dispatch()) {
|
2015-11-26 20:03:10 +03:00
|
|
|
NS_WARNING("Failed to dispatch SkipWaitingResultRunnable to the worker.");
|
|
|
|
}
|
2015-06-02 14:12:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2015-06-02 14:12:00 +03:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
ServiceWorkerGlobalScope::SkipWaiting(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
MOZ_ASSERT(mWorkerPrivate->IsServiceWorker());
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> promise = Promise::Create(this, aRv);
|
2015-06-02 14:12:00 +03:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PromiseWorkerProxy> promiseProxy =
|
2015-06-02 14:12:00 +03:00
|
|
|
PromiseWorkerProxy::Create(mWorkerPrivate, promise);
|
2015-09-02 20:07:26 +03:00
|
|
|
if (!promiseProxy) {
|
2016-08-09 12:15:13 +03:00
|
|
|
promise->MaybeResolveWithUndefined();
|
2015-06-02 14:12:00 +03:00
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WorkerScopeSkipWaitingRunnable> runnable =
|
2015-06-02 14:12:00 +03:00
|
|
|
new WorkerScopeSkipWaitingRunnable(promiseProxy,
|
|
|
|
NS_ConvertUTF16toUTF8(mScope));
|
|
|
|
|
2016-09-14 06:14:02 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(mWorkerPrivate->DispatchToMainThread(runnable.forget()));
|
2015-06-02 14:12:00 +03:00
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2015-03-04 02:51:53 +03:00
|
|
|
WorkerDebuggerGlobalScope::WorkerDebuggerGlobalScope(
|
|
|
|
WorkerPrivate* aWorkerPrivate)
|
|
|
|
: mWorkerPrivate(aWorkerPrivate)
|
2017-07-21 18:16:24 +03:00
|
|
|
, mSerialEventTarget(aWorkerPrivate->HybridEventTarget())
|
2015-03-04 02:51:53 +03:00
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
2017-06-29 21:28:56 +03:00
|
|
|
|
|
|
|
// We should always have an event target when the global is created.
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mSerialEventTarget);
|
2015-03-04 02:51:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
WorkerDebuggerGlobalScope::~WorkerDebuggerGlobalScope()
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
}
|
|
|
|
|
2016-02-11 20:41:17 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(WorkerDebuggerGlobalScope)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(WorkerDebuggerGlobalScope,
|
|
|
|
DOMEventTargetHelper)
|
|
|
|
tmp->mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConsole)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(WorkerDebuggerGlobalScope,
|
|
|
|
DOMEventTargetHelper)
|
|
|
|
tmp->mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mConsole)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(WorkerDebuggerGlobalScope,
|
|
|
|
DOMEventTargetHelper)
|
|
|
|
tmp->mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2015-03-04 02:51:53 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(WorkerDebuggerGlobalScope, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(WorkerDebuggerGlobalScope, DOMEventTargetHelper)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WorkerDebuggerGlobalScope)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
|
|
|
|
|
|
|
bool
|
|
|
|
WorkerDebuggerGlobalScope::WrapGlobalObject(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JSObject*> aReflector)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2018-05-17 11:59:45 +03:00
|
|
|
JS::RealmOptions options;
|
|
|
|
mWorkerPrivate->CopyJSRealmOptions(options);
|
2015-03-04 02:51:53 +03:00
|
|
|
|
2018-06-26 00:20:54 +03:00
|
|
|
return WorkerDebuggerGlobalScope_Binding::Wrap(aCx, this, this, options,
|
2015-03-04 02:51:53 +03:00
|
|
|
GetWorkerPrincipal(), true,
|
|
|
|
aReflector);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WorkerDebuggerGlobalScope::GetGlobal(JSContext* aCx,
|
2016-03-18 16:04:57 +03:00
|
|
|
JS::MutableHandle<JSObject*> aGlobal,
|
|
|
|
ErrorResult& aRv)
|
2015-03-04 02:51:53 +03:00
|
|
|
{
|
2016-03-18 16:04:57 +03:00
|
|
|
WorkerGlobalScope* scope = mWorkerPrivate->GetOrCreateGlobalScope(aCx);
|
|
|
|
if (!scope) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
2017-02-28 22:49:03 +03:00
|
|
|
return;
|
2016-03-18 16:04:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
aGlobal.set(scope->GetWrapper());
|
2015-03-04 02:51:53 +03:00
|
|
|
}
|
|
|
|
|
2015-03-31 13:22:40 +03:00
|
|
|
void
|
|
|
|
WorkerDebuggerGlobalScope::CreateSandbox(JSContext* aCx, const nsAString& aName,
|
|
|
|
JS::Handle<JSObject*> aPrototype,
|
2016-03-28 20:28:14 +03:00
|
|
|
JS::MutableHandle<JSObject*> aResult,
|
|
|
|
ErrorResult& aRv)
|
2015-03-31 13:22:40 +03:00
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2016-03-28 20:28:14 +03:00
|
|
|
aResult.set(nullptr);
|
|
|
|
|
2016-04-04 19:29:16 +03:00
|
|
|
JS::Rooted<JS::Value> protoVal(aCx);
|
|
|
|
protoVal.setObjectOrNull(aPrototype);
|
2015-03-31 13:22:40 +03:00
|
|
|
JS::Rooted<JSObject*> sandbox(aCx,
|
2016-04-04 19:29:16 +03:00
|
|
|
SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::WorkerDebuggerSandbox,
|
|
|
|
protoVal));
|
|
|
|
|
2015-03-31 13:22:40 +03:00
|
|
|
if (!sandbox) {
|
2016-04-04 19:29:16 +03:00
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
2015-03-31 13:22:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!JS_WrapObject(aCx, &sandbox)) {
|
2016-03-28 20:28:14 +03:00
|
|
|
aRv.NoteJSContextException(aCx);
|
2015-03-31 13:22:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult.set(sandbox);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WorkerDebuggerGlobalScope::LoadSubScript(JSContext* aCx,
|
|
|
|
const nsAString& aURL,
|
|
|
|
const Optional<JS::Handle<JSObject*>>& aSandbox,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2018-07-31 09:37:17 +03:00
|
|
|
Maybe<JSAutoRealm> ar;
|
2015-03-31 13:22:40 +03:00
|
|
|
if (aSandbox.WasPassed()) {
|
|
|
|
JS::Rooted<JSObject*> sandbox(aCx, js::CheckedUnwrap(aSandbox.Value()));
|
2018-02-05 21:55:07 +03:00
|
|
|
if (!IsWorkerDebuggerSandbox(sandbox)) {
|
2015-03-31 13:22:40 +03:00
|
|
|
aRv.Throw(NS_ERROR_INVALID_ARG);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-16 11:53:16 +03:00
|
|
|
ar.emplace(aCx, sandbox);
|
2015-03-31 13:22:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsString> urls;
|
|
|
|
urls.AppendElement(aURL);
|
2018-01-31 10:22:03 +03:00
|
|
|
workerinternals::Load(mWorkerPrivate, urls, DebuggerScript, aRv);
|
2015-03-31 13:22:40 +03:00
|
|
|
}
|
|
|
|
|
2015-03-27 09:17:16 +03:00
|
|
|
void
|
|
|
|
WorkerDebuggerGlobalScope::EnterEventLoop()
|
|
|
|
{
|
|
|
|
mWorkerPrivate->EnterDebuggerEventLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WorkerDebuggerGlobalScope::LeaveEventLoop()
|
|
|
|
{
|
|
|
|
mWorkerPrivate->LeaveDebuggerEventLoop();
|
|
|
|
}
|
|
|
|
|
2015-03-20 14:15:59 +03:00
|
|
|
void
|
|
|
|
WorkerDebuggerGlobalScope::PostMessage(const nsAString& aMessage)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->PostMessageToDebugger(aMessage);
|
|
|
|
}
|
|
|
|
|
2015-03-30 14:54:38 +03:00
|
|
|
void
|
2016-02-26 23:23:12 +03:00
|
|
|
WorkerDebuggerGlobalScope::SetImmediate(Function& aHandler, ErrorResult& aRv)
|
2015-03-30 14:54:38 +03:00
|
|
|
{
|
2016-02-26 23:23:12 +03:00
|
|
|
mWorkerPrivate->SetDebuggerImmediate(aHandler, aRv);
|
2015-03-30 14:54:38 +03:00
|
|
|
}
|
|
|
|
|
2015-03-26 22:09:45 +03:00
|
|
|
void
|
|
|
|
WorkerDebuggerGlobalScope::ReportError(JSContext* aCx,
|
|
|
|
const nsAString& aMessage)
|
|
|
|
{
|
2016-03-09 13:20:11 +03:00
|
|
|
JS::AutoFilename chars;
|
2015-03-26 22:09:45 +03:00
|
|
|
uint32_t lineno = 0;
|
2016-01-16 03:26:20 +03:00
|
|
|
JS::DescribeScriptedCaller(aCx, &chars, &lineno);
|
|
|
|
nsString filename(NS_ConvertUTF8toUTF16(chars.get()));
|
2015-03-26 22:09:45 +03:00
|
|
|
mWorkerPrivate->ReportErrorToDebugger(filename, lineno, aMessage);
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:55:07 +03:00
|
|
|
void
|
|
|
|
WorkerDebuggerGlobalScope::RetrieveConsoleEvents(JSContext* aCx,
|
|
|
|
nsTArray<JS::Value>& aEvents,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
WorkerGlobalScope* scope = mWorkerPrivate->GetOrCreateGlobalScope(aCx);
|
|
|
|
if (!scope) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Console> console = scope->GetConsole(aRv);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
console->RetrieveConsoleEvents(aCx, aEvents, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WorkerDebuggerGlobalScope::SetConsoleEventHandler(JSContext* aCx,
|
2016-03-29 17:56:10 +03:00
|
|
|
AnyCallback* aHandler,
|
2016-03-24 00:55:07 +03:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
WorkerGlobalScope* scope = mWorkerPrivate->GetOrCreateGlobalScope(aCx);
|
|
|
|
if (!scope) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Console> console = scope->GetConsole(aRv);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
console->SetConsoleEventHandler(aHandler);
|
|
|
|
}
|
|
|
|
|
2017-12-20 16:35:34 +03:00
|
|
|
already_AddRefed<Console>
|
2016-02-11 20:41:17 +03:00
|
|
|
WorkerDebuggerGlobalScope::GetConsole(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
|
|
|
// Debugger console has its own console object.
|
|
|
|
if (!mConsole) {
|
2018-02-22 10:49:51 +03:00
|
|
|
mConsole = Console::Create(mWorkerPrivate->GetJSContext(),
|
|
|
|
nullptr, aRv);
|
2016-03-24 00:55:07 +03:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-02-11 20:41:17 +03:00
|
|
|
}
|
|
|
|
|
2017-12-20 16:35:34 +03:00
|
|
|
RefPtr<Console> console = mConsole;
|
|
|
|
return console.forget();
|
2016-02-11 20:41:17 +03:00
|
|
|
}
|
|
|
|
|
2015-03-04 02:51:53 +03:00
|
|
|
void
|
|
|
|
WorkerDebuggerGlobalScope::Dump(JSContext* aCx,
|
|
|
|
const Optional<nsAString>& aString) const
|
|
|
|
{
|
2016-03-18 16:04:57 +03:00
|
|
|
WorkerGlobalScope* scope = mWorkerPrivate->GetOrCreateGlobalScope(aCx);
|
|
|
|
if (scope) {
|
|
|
|
scope->Dump(aString);
|
|
|
|
}
|
2015-03-04 02:51:53 +03:00
|
|
|
}
|
|
|
|
|
2017-06-29 21:28:56 +03:00
|
|
|
nsresult
|
2017-07-26 11:13:35 +03:00
|
|
|
WorkerDebuggerGlobalScope::Dispatch(TaskCategory aCategory,
|
2017-06-29 21:28:56 +03:00
|
|
|
already_AddRefed<nsIRunnable>&& aRunnable)
|
|
|
|
{
|
2018-05-30 22:15:35 +03:00
|
|
|
return EventTargetFor(aCategory)->Dispatch(std::move(aRunnable),
|
2017-06-29 21:28:56 +03:00
|
|
|
NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsISerialEventTarget*
|
|
|
|
WorkerDebuggerGlobalScope::EventTargetFor(TaskCategory aCategory) const
|
|
|
|
{
|
|
|
|
return mSerialEventTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractThread*
|
|
|
|
WorkerDebuggerGlobalScope::AbstractMainThreadFor(TaskCategory aCategory)
|
|
|
|
{
|
|
|
|
MOZ_CRASH("AbstractMainThreadFor not supported for workers.");
|
|
|
|
}
|
|
|
|
|
2015-03-04 02:51:53 +03:00
|
|
|
bool
|
|
|
|
IsWorkerGlobal(JSObject* object)
|
|
|
|
{
|
2017-07-10 23:05:24 +03:00
|
|
|
return IS_INSTANCE_OF(WorkerGlobalScope, object);
|
2015-03-04 02:51:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-02-05 21:55:07 +03:00
|
|
|
IsWorkerDebuggerGlobal(JSObject* object)
|
2015-03-04 02:51:53 +03:00
|
|
|
{
|
2017-07-10 23:05:24 +03:00
|
|
|
return IS_INSTANCE_OF(WorkerDebuggerGlobalScope, object);
|
2015-03-04 02:51:53 +03:00
|
|
|
}
|
|
|
|
|
2015-03-31 13:22:40 +03:00
|
|
|
bool
|
2018-02-05 21:55:07 +03:00
|
|
|
IsWorkerDebuggerSandbox(JSObject* object)
|
2015-03-31 13:22:40 +03:00
|
|
|
{
|
2016-04-04 19:29:16 +03:00
|
|
|
return SimpleGlobalObject::SimpleGlobalType(object) ==
|
|
|
|
SimpleGlobalObject::GlobalType::WorkerDebuggerSandbox;
|
2015-03-31 13:22:40 +03:00
|
|
|
}
|
|
|
|
|
2018-01-31 10:24:30 +03:00
|
|
|
} // dom namespace
|
|
|
|
} // mozilla namespace
|