|
@@ -0,0 +1,5579 @@
|
|
|
+# HG changeset patch
|
|
|
+# User Andrea Marchesini <amarchesini@mozilla.com>
|
|
|
+# Date 1517383448 -3600
|
|
|
+# Node ID 22ab83c80c5e38ab1b32b7e8186825ecd855ee1f
|
|
|
+# Parent 12db4ef527e6dd333a396a6c21f6e9c7b15dced5
|
|
|
+Bug 1432963 - Fixing workers headers - part 14 - WorkerPrivate without workers namespace, r=smaug
|
|
|
+
|
|
|
+diff --git a/dom/base/ImageEncoder.cpp b/dom/base/ImageEncoder.cpp
|
|
|
+--- a/dom/base/ImageEncoder.cpp
|
|
|
++++ b/dom/base/ImageEncoder.cpp
|
|
|
+@@ -84,17 +84,17 @@ public:
|
|
|
+ explicit EncodingCompleteEvent(EncodeCompleteCallback* aEncodeCompleteCallback)
|
|
|
+ : CancelableRunnable("EncodingCompleteEvent")
|
|
|
+ , mImgSize(0)
|
|
|
+ , mType()
|
|
|
+ , mImgData(nullptr)
|
|
|
+ , mEncodeCompleteCallback(aEncodeCompleteCallback)
|
|
|
+ , mFailed(false)
|
|
|
+ {
|
|
|
+- if (!NS_IsMainThread() && workers::GetCurrentThreadWorkerPrivate()) {
|
|
|
++ if (!NS_IsMainThread() && GetCurrentThreadWorkerPrivate()) {
|
|
|
+ mCreationEventTarget = GetCurrentThreadEventTarget();
|
|
|
+ } else {
|
|
|
+ mCreationEventTarget = GetMainThreadEventTarget();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ NS_IMETHOD Run() override
|
|
|
+ {
|
|
|
+diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp
|
|
|
+--- a/dom/base/nsContentUtils.cpp
|
|
|
++++ b/dom/base/nsContentUtils.cpp
|
|
|
+@@ -2512,17 +2512,17 @@ nsContentUtils::CalcRoundedWindowSizeFor
|
|
|
+ *aOutputHeight = resultHeight;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool
|
|
|
+ nsContentUtils::ThreadsafeIsCallerChrome()
|
|
|
+ {
|
|
|
+ return NS_IsMainThread() ?
|
|
|
+ IsCallerChrome() :
|
|
|
+- mozilla::dom::workers::IsCurrentThreadRunningChromeWorker();
|
|
|
++ mozilla::dom::IsCurrentThreadRunningChromeWorker();
|
|
|
+ }
|
|
|
+
|
|
|
+ bool
|
|
|
+ nsContentUtils::IsCallerContentXBL()
|
|
|
+ {
|
|
|
+ JSContext *cx = GetCurrentJSContext();
|
|
|
+ if (!cx)
|
|
|
+ return false;
|
|
|
+@@ -2551,17 +2551,17 @@ nsContentUtils::IsSystemCaller(JSContext
|
|
|
+
|
|
|
+ bool
|
|
|
+ nsContentUtils::ThreadsafeIsSystemCaller(JSContext* aCx)
|
|
|
+ {
|
|
|
+ if (NS_IsMainThread()) {
|
|
|
+ return IsSystemCaller(aCx);
|
|
|
+ }
|
|
|
+
|
|
|
+- return workers::GetWorkerPrivateFromContext(aCx)->UsesSystemPrincipal();
|
|
|
++ return GetWorkerPrivateFromContext(aCx)->UsesSystemPrincipal();
|
|
|
+ }
|
|
|
+
|
|
|
+ // static
|
|
|
+ bool
|
|
|
+ nsContentUtils::LookupBindingMember(JSContext* aCx, nsIContent *aContent,
|
|
|
+ JS::Handle<jsid> aId,
|
|
|
+ JS::MutableHandle<JS::PropertyDescriptor> aDesc)
|
|
|
+ {
|
|
|
+@@ -6208,17 +6208,17 @@ nsContentUtils::GetCurrentJSContext()
|
|
|
+ /* static */
|
|
|
+ JSContext *
|
|
|
+ nsContentUtils::GetCurrentJSContextForThread()
|
|
|
+ {
|
|
|
+ MOZ_ASSERT(IsInitialized());
|
|
|
+ if (MOZ_LIKELY(NS_IsMainThread())) {
|
|
|
+ return GetCurrentJSContext();
|
|
|
+ }
|
|
|
+- return workers::GetCurrentThreadJSContext();
|
|
|
++ return GetCurrentThreadJSContext();
|
|
|
+ }
|
|
|
+
|
|
|
+ template<typename StringType, typename CharType>
|
|
|
+ void
|
|
|
+ _ASCIIToLowerInSitu(StringType& aStr)
|
|
|
+ {
|
|
|
+ CharType* iter = aStr.BeginWriting();
|
|
|
+ CharType* end = aStr.EndWriting();
|
|
|
+diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf
|
|
|
+--- a/dom/bindings/Bindings.conf
|
|
|
++++ b/dom/bindings/Bindings.conf
|
|
|
+@@ -145,17 +145,17 @@ DOMInterfaces = {
|
|
|
+ },
|
|
|
+
|
|
|
+ 'ChromeWindow': {
|
|
|
+ 'concrete': False,
|
|
|
+ },
|
|
|
+
|
|
|
+ 'ChromeWorker': {
|
|
|
+ 'headerFile': 'mozilla/dom/WorkerPrivate.h',
|
|
|
+- 'nativeType': 'mozilla::dom::workers::ChromeWorkerPrivate',
|
|
|
++ 'nativeType': 'mozilla::dom::ChromeWorkerPrivate',
|
|
|
+ },
|
|
|
+
|
|
|
+ 'console': {
|
|
|
+ 'nativeType': 'mozilla::dom::Console',
|
|
|
+ },
|
|
|
+
|
|
|
+ 'ConsoleInstance': {
|
|
|
+ 'implicitJSContext': ['clear', 'count', 'groupEnd', 'time', 'timeEnd'],
|
|
|
+@@ -1357,17 +1357,17 @@ DOMInterfaces = {
|
|
|
+ },
|
|
|
+
|
|
|
+ 'WindowRoot': {
|
|
|
+ 'nativeType': 'nsWindowRoot'
|
|
|
+ },
|
|
|
+
|
|
|
+ 'Worker': {
|
|
|
+ 'headerFile': 'mozilla/dom/WorkerPrivate.h',
|
|
|
+- 'nativeType': 'mozilla::dom::workers::WorkerPrivate',
|
|
|
++ 'nativeType': 'mozilla::dom::WorkerPrivate',
|
|
|
+ },
|
|
|
+
|
|
|
+ 'WorkerDebuggerGlobalScope': {
|
|
|
+ 'headerFile': 'mozilla/dom/WorkerScope.h',
|
|
|
+ 'implicitJSContext': [
|
|
|
+ 'dump', 'global', 'reportError', 'setConsoleEventHandler',
|
|
|
+ ],
|
|
|
+ },
|
|
|
+diff --git a/dom/cache/Cache.cpp b/dom/cache/Cache.cpp
|
|
|
+--- a/dom/cache/Cache.cpp
|
|
|
++++ b/dom/cache/Cache.cpp
|
|
|
+@@ -22,18 +22,16 @@
|
|
|
+ #include "mozilla/Preferences.h"
|
|
|
+ #include "mozilla/Unused.h"
|
|
|
+ #include "nsIGlobalObject.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+ namespace cache {
|
|
|
+
|
|
|
+-using mozilla::dom::workers::GetCurrentThreadWorkerPrivate;
|
|
|
+-using mozilla::dom::workers::WorkerPrivate;
|
|
|
+ using mozilla::ipc::PBackgroundChild;
|
|
|
+
|
|
|
+ namespace {
|
|
|
+
|
|
|
+ enum class PutStatusPolicy {
|
|
|
+ Default,
|
|
|
+ RequireOK
|
|
|
+ };
|
|
|
+diff --git a/dom/cache/CacheStorage.cpp b/dom/cache/CacheStorage.cpp
|
|
|
+--- a/dom/cache/CacheStorage.cpp
|
|
|
++++ b/dom/cache/CacheStorage.cpp
|
|
|
+@@ -33,17 +33,16 @@
|
|
|
+ #include "WorkerPrivate.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+ namespace cache {
|
|
|
+
|
|
|
+ using mozilla::Unused;
|
|
|
+ using mozilla::ErrorResult;
|
|
|
+-using mozilla::dom::workers::WorkerPrivate;
|
|
|
+ using mozilla::ipc::BackgroundChild;
|
|
|
+ using mozilla::ipc::PBackgroundChild;
|
|
|
+ using mozilla::ipc::IProtocol;
|
|
|
+ using mozilla::ipc::PrincipalInfo;
|
|
|
+ using mozilla::ipc::PrincipalToPrincipalInfo;
|
|
|
+
|
|
|
+ NS_IMPL_CYCLE_COLLECTING_ADDREF(mozilla::dom::cache::CacheStorage);
|
|
|
+ NS_IMPL_CYCLE_COLLECTING_RELEASE(mozilla::dom::cache::CacheStorage);
|
|
|
+diff --git a/dom/cache/CacheStorage.h b/dom/cache/CacheStorage.h
|
|
|
+--- a/dom/cache/CacheStorage.h
|
|
|
++++ b/dom/cache/CacheStorage.h
|
|
|
+@@ -24,20 +24,17 @@ class ErrorResult;
|
|
|
+ namespace ipc {
|
|
|
+ class PrincipalInfo;
|
|
|
+ } // namespace ipc
|
|
|
+
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+ enum class CacheStorageNamespace : uint8_t;
|
|
|
+ class Promise;
|
|
|
+-
|
|
|
+-namespace workers {
|
|
|
+- class WorkerPrivate;
|
|
|
+-} // namespace workers
|
|
|
++class WorkerPrivate;
|
|
|
+
|
|
|
+ namespace cache {
|
|
|
+
|
|
|
+ class CacheStorageChild;
|
|
|
+ class CacheWorkerHolder;
|
|
|
+
|
|
|
+ class CacheStorage final : public nsISupports
|
|
|
+ , public nsWrapperCache
|
|
|
+@@ -48,17 +45,17 @@ class CacheStorage final : public nsISup
|
|
|
+ public:
|
|
|
+ static already_AddRefed<CacheStorage>
|
|
|
+ CreateOnMainThread(Namespace aNamespace, nsIGlobalObject* aGlobal,
|
|
|
+ nsIPrincipal* aPrincipal, bool aStorageDisabled,
|
|
|
+ bool aForceTrustedOrigin, ErrorResult& aRv);
|
|
|
+
|
|
|
+ static already_AddRefed<CacheStorage>
|
|
|
+ CreateOnWorker(Namespace aNamespace, nsIGlobalObject* aGlobal,
|
|
|
+- workers::WorkerPrivate* aWorkerPrivate, ErrorResult& aRv);
|
|
|
++ WorkerPrivate* aWorkerPrivate, ErrorResult& aRv);
|
|
|
+
|
|
|
+ static bool
|
|
|
+ DefineCaches(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
|
|
|
+
|
|
|
+ // webidl interface methods
|
|
|
+ already_AddRefed<Promise>
|
|
|
+ Match(JSContext* aCx, const RequestOrUSVString& aRequest,
|
|
|
+ const CacheQueryOptions& aOptions, ErrorResult& aRv);
|
|
|
+diff --git a/dom/cache/CacheWorkerHolder.cpp b/dom/cache/CacheWorkerHolder.cpp
|
|
|
+--- a/dom/cache/CacheWorkerHolder.cpp
|
|
|
++++ b/dom/cache/CacheWorkerHolder.cpp
|
|
|
+@@ -8,18 +8,16 @@
|
|
|
+
|
|
|
+ #include "mozilla/dom/cache/ActorChild.h"
|
|
|
+ #include "WorkerPrivate.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+ namespace cache {
|
|
|
+
|
|
|
+-using mozilla::dom::workers::WorkerPrivate;
|
|
|
+-
|
|
|
+ // static
|
|
|
+ already_AddRefed<CacheWorkerHolder>
|
|
|
+ CacheWorkerHolder::Create(WorkerPrivate* aWorkerPrivate, Behavior aBehavior)
|
|
|
+ {
|
|
|
+ MOZ_DIAGNOSTIC_ASSERT(aWorkerPrivate);
|
|
|
+
|
|
|
+ RefPtr<CacheWorkerHolder> workerHolder = new CacheWorkerHolder(aBehavior);
|
|
|
+ if (NS_WARN_IF(!workerHolder->HoldWorker(aWorkerPrivate, Terminating))) {
|
|
|
+diff --git a/dom/cache/CacheWorkerHolder.h b/dom/cache/CacheWorkerHolder.h
|
|
|
+--- a/dom/cache/CacheWorkerHolder.h
|
|
|
++++ b/dom/cache/CacheWorkerHolder.h
|
|
|
+@@ -8,30 +8,28 @@
|
|
|
+ #define mozilla_dom_cache_CacheWorkerHolder_h
|
|
|
+
|
|
|
+ #include "nsISupportsImpl.h"
|
|
|
+ #include "nsTArray.h"
|
|
|
+ #include "WorkerHolder.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-} // namespace workers
|
|
|
+
|
|
|
+ namespace dom {
|
|
|
+ namespace cache {
|
|
|
+
|
|
|
+ class ActorChild;
|
|
|
+
|
|
|
+ class CacheWorkerHolder final : public WorkerHolder
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ static already_AddRefed<CacheWorkerHolder>
|
|
|
+- Create(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ Create(WorkerPrivate* aWorkerPrivate,
|
|
|
+ Behavior aBehavior);
|
|
|
+
|
|
|
+ static already_AddRefed<CacheWorkerHolder>
|
|
|
+ PreferBehavior(CacheWorkerHolder* aCurrentHolder, Behavior aBehavior);
|
|
|
+
|
|
|
+ void AddActor(ActorChild* aActor);
|
|
|
+ void RemoveActor(ActorChild* aActor);
|
|
|
+
|
|
|
+diff --git a/dom/canvas/OffscreenCanvas.cpp b/dom/canvas/OffscreenCanvas.cpp
|
|
|
+--- a/dom/canvas/OffscreenCanvas.cpp
|
|
|
++++ b/dom/canvas/OffscreenCanvas.cpp
|
|
|
+@@ -298,18 +298,17 @@ OffscreenCanvas::GetSurfaceSnapshot(gfxA
|
|
|
+
|
|
|
+ nsCOMPtr<nsIGlobalObject>
|
|
|
+ OffscreenCanvas::GetGlobalObject()
|
|
|
+ {
|
|
|
+ if (NS_IsMainThread()) {
|
|
|
+ return GetParentObject();
|
|
|
+ }
|
|
|
+
|
|
|
+- dom::workers::WorkerPrivate* workerPrivate =
|
|
|
+- dom::workers::GetCurrentThreadWorkerPrivate();
|
|
|
++ dom::WorkerPrivate* workerPrivate = dom::GetCurrentThreadWorkerPrivate();
|
|
|
+ return workerPrivate->GlobalScope();
|
|
|
+ }
|
|
|
+
|
|
|
+ /* static */ already_AddRefed<OffscreenCanvas>
|
|
|
+ OffscreenCanvas::CreateFromCloneData(nsIGlobalObject* aGlobal, OffscreenCanvasCloneData* aData)
|
|
|
+ {
|
|
|
+ MOZ_ASSERT(aData);
|
|
|
+ RefPtr<OffscreenCanvas> wc =
|
|
|
+diff --git a/dom/clients/api/Client.cpp b/dom/clients/api/Client.cpp
|
|
|
+--- a/dom/clients/api/Client.cpp
|
|
|
++++ b/dom/clients/api/Client.cpp
|
|
|
+@@ -14,18 +14,16 @@
|
|
|
+ #include "mozilla/dom/Promise.h"
|
|
|
+ #include "mozilla/dom/WorkerPrivate.h"
|
|
|
+ #include "mozilla/dom/WorkerScope.h"
|
|
|
+ #include "nsIGlobalObject.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using mozilla::dom::workers::GetCurrentThreadWorkerPrivate;
|
|
|
+-using mozilla::dom::workers::WorkerPrivate;
|
|
|
+ using mozilla::dom::ipc::StructuredCloneData;
|
|
|
+
|
|
|
+ NS_IMPL_CYCLE_COLLECTING_ADDREF(mozilla::dom::Client);
|
|
|
+ NS_IMPL_CYCLE_COLLECTING_RELEASE(mozilla::dom::Client);
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(mozilla::dom::Client, mGlobal);
|
|
|
+
|
|
|
+ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(mozilla::dom::Client)
|
|
|
+ NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
+diff --git a/dom/clients/api/ClientDOMUtil.h b/dom/clients/api/ClientDOMUtil.h
|
|
|
+--- a/dom/clients/api/ClientDOMUtil.h
|
|
|
++++ b/dom/clients/api/ClientDOMUtil.h
|
|
|
+@@ -20,17 +20,16 @@ namespace dom {
|
|
|
+ // will properly hold a worker thread alive and avoid executing callbacks
|
|
|
+ // if the thread is shutting down.
|
|
|
+ template<typename Func, typename Arg, typename Resolve, typename Reject>
|
|
|
+ void
|
|
|
+ StartClientManagerOp(Func aFunc, const Arg& aArg, nsISerialEventTarget* aTarget,
|
|
|
+ Resolve aResolve, Reject aReject)
|
|
|
+ {
|
|
|
+ using mozilla::dom::WorkerStatus::Closing;
|
|
|
+- using mozilla::dom::workers::GetCurrentThreadWorkerPrivate;
|
|
|
+
|
|
|
+ RefPtr<WorkerHolderToken> token;
|
|
|
+ if (!NS_IsMainThread()) {
|
|
|
+ token = WorkerHolderToken::Create(GetCurrentThreadWorkerPrivate(), Closing);
|
|
|
+ }
|
|
|
+
|
|
|
+ RefPtr<ClientOpPromise> promise = aFunc(aArg, aTarget);
|
|
|
+ promise->Then(aTarget, __func__,
|
|
|
+diff --git a/dom/clients/api/Clients.cpp b/dom/clients/api/Clients.cpp
|
|
|
+--- a/dom/clients/api/Clients.cpp
|
|
|
++++ b/dom/clients/api/Clients.cpp
|
|
|
+@@ -16,18 +16,16 @@
|
|
|
+ #include "mozilla/dom/WorkerPrivate.h"
|
|
|
+ #include "mozilla/SystemGroup.h"
|
|
|
+ #include "nsIGlobalObject.h"
|
|
|
+ #include "nsString.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using mozilla::dom::workers::GetCurrentThreadWorkerPrivate;
|
|
|
+-using mozilla::dom::workers::WorkerPrivate;
|
|
|
+ using mozilla::ipc::PrincipalInfo;
|
|
|
+
|
|
|
+ NS_IMPL_CYCLE_COLLECTING_ADDREF(Clients);
|
|
|
+ NS_IMPL_CYCLE_COLLECTING_RELEASE(Clients);
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Clients, mGlobal);
|
|
|
+
|
|
|
+ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Clients)
|
|
|
+ NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
+diff --git a/dom/clients/manager/ClientManager.cpp b/dom/clients/manager/ClientManager.cpp
|
|
|
+--- a/dom/clients/manager/ClientManager.cpp
|
|
|
++++ b/dom/clients/manager/ClientManager.cpp
|
|
|
+@@ -19,18 +19,16 @@
|
|
|
+ #include "prthread.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+ using mozilla::ipc::BackgroundChild;
|
|
|
+ using mozilla::ipc::PBackgroundChild;
|
|
|
+ using mozilla::ipc::PrincipalInfo;
|
|
|
+-using mozilla::dom::workers::GetCurrentThreadWorkerPrivate;
|
|
|
+-using mozilla::dom::workers::WorkerPrivate;
|
|
|
+
|
|
|
+ namespace {
|
|
|
+
|
|
|
+ uint32_t kBadThreadLocalIndex = -1;
|
|
|
+ uint32_t sClientManagerThreadLocalIndex = kBadThreadLocalIndex;
|
|
|
+
|
|
|
+ } // anonymous namespace
|
|
|
+
|
|
|
+diff --git a/dom/clients/manager/ClientManager.h b/dom/clients/manager/ClientManager.h
|
|
|
+--- a/dom/clients/manager/ClientManager.h
|
|
|
++++ b/dom/clients/manager/ClientManager.h
|
|
|
+@@ -24,20 +24,17 @@ class ClientHandle;
|
|
|
+ class ClientInfo;
|
|
|
+ class ClientManagerChild;
|
|
|
+ class ClientMatchAllArgs;
|
|
|
+ class ClientNavigateArgs;
|
|
|
+ class ClientOpConstructorArgs;
|
|
|
+ class ClientOpenWindowArgs;
|
|
|
+ class ClientSource;
|
|
|
+ enum class ClientType : uint8_t;
|
|
|
+-
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-} // workers namespace
|
|
|
+
|
|
|
+ // The ClientManager provides a per-thread singleton interface workering
|
|
|
+ // with the client subsystem. It allows globals to create ClientSource
|
|
|
+ // objects. It allows other parts of the system to attach to this globals
|
|
|
+ // by creating ClientHandle objects. The ClientManager also provides
|
|
|
+ // methods for querying the list of clients active in the system.
|
|
|
+ class ClientManager final : public ClientThing<ClientManagerChild>
|
|
|
+ {
|
|
|
+@@ -71,17 +68,17 @@ class ClientManager final : public Clien
|
|
|
+
|
|
|
+ // Get or create the TLS singleton. Currently this is only used
|
|
|
+ // internally and external code indirectly calls it by invoking
|
|
|
+ // static methods.
|
|
|
+ static already_AddRefed<ClientManager>
|
|
|
+ GetOrCreateForCurrentThread();
|
|
|
+
|
|
|
+ // Private methods called by ClientSource
|
|
|
+- mozilla::dom::workers::WorkerPrivate*
|
|
|
++ mozilla::dom::WorkerPrivate*
|
|
|
+ GetWorkerPrivate() const;
|
|
|
+
|
|
|
+ public:
|
|
|
+ // Initialize the ClientManager at process start. This
|
|
|
+ // does book-keeping like creating a TLS identifier, etc.
|
|
|
+ // This should only be called by process startup code.
|
|
|
+ static void
|
|
|
+ Startup();
|
|
|
+diff --git a/dom/clients/manager/ClientManagerChild.cpp b/dom/clients/manager/ClientManagerChild.cpp
|
|
|
+--- a/dom/clients/manager/ClientManagerChild.cpp
|
|
|
++++ b/dom/clients/manager/ClientManagerChild.cpp
|
|
|
+@@ -9,18 +9,16 @@
|
|
|
+ #include "ClientHandleChild.h"
|
|
|
+ #include "ClientManagerOpChild.h"
|
|
|
+ #include "ClientNavigateOpChild.h"
|
|
|
+ #include "ClientSourceChild.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using mozilla::dom::workers::WorkerPrivate;
|
|
|
+-
|
|
|
+ void
|
|
|
+ ClientManagerChild::ActorDestroy(ActorDestroyReason aReason)
|
|
|
+ {
|
|
|
+ if (mWorkerHolderToken) {
|
|
|
+ mWorkerHolderToken->RemoveListener(this);
|
|
|
+ mWorkerHolderToken = nullptr;
|
|
|
+
|
|
|
+ }
|
|
|
+diff --git a/dom/clients/manager/ClientManagerChild.h b/dom/clients/manager/ClientManagerChild.h
|
|
|
+--- a/dom/clients/manager/ClientManagerChild.h
|
|
|
++++ b/dom/clients/manager/ClientManagerChild.h
|
|
|
+@@ -8,19 +8,17 @@
|
|
|
+
|
|
|
+ #include "ClientThing.h"
|
|
|
+ #include "mozilla/dom/PClientManagerChild.h"
|
|
|
+ #include "mozilla/dom/WorkerHolderToken.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-} // workers namespace
|
|
|
+
|
|
|
+ class ClientManagerChild final : public PClientManagerChild
|
|
|
+ , public WorkerHolderToken::Listener
|
|
|
+ {
|
|
|
+ ClientThing<ClientManagerChild>* mManager;
|
|
|
+
|
|
|
+ RefPtr<WorkerHolderToken> mWorkerHolderToken;
|
|
|
+ bool mTeardownStarted;
|
|
|
+@@ -68,16 +66,16 @@ public:
|
|
|
+ SetOwner(ClientThing<ClientManagerChild>* aThing);
|
|
|
+
|
|
|
+ void
|
|
|
+ RevokeOwner(ClientThing<ClientManagerChild>* aThing);
|
|
|
+
|
|
|
+ void
|
|
|
+ MaybeStartTeardown();
|
|
|
+
|
|
|
+- mozilla::dom::workers::WorkerPrivate*
|
|
|
++ mozilla::dom::WorkerPrivate*
|
|
|
+ GetWorkerPrivate() const;
|
|
|
+ };
|
|
|
+
|
|
|
+ } // namespace dom
|
|
|
+ } // namespace mozilla
|
|
|
+
|
|
|
+ #endif // _mozilla_dom_ClientManagerChild_h
|
|
|
+diff --git a/dom/clients/manager/ClientSource.cpp b/dom/clients/manager/ClientSource.cpp
|
|
|
+--- a/dom/clients/manager/ClientSource.cpp
|
|
|
++++ b/dom/clients/manager/ClientSource.cpp
|
|
|
+@@ -24,17 +24,16 @@
|
|
|
+ #include "nsContentUtils.h"
|
|
|
+ #include "nsIDocShell.h"
|
|
|
+ #include "nsPIDOMWindow.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+ using mozilla::dom::ipc::StructuredCloneData;
|
|
|
+-using mozilla::dom::workers::WorkerPrivate;
|
|
|
+ using mozilla::ipc::PrincipalInfo;
|
|
|
+ using mozilla::ipc::PrincipalInfoToPrincipal;
|
|
|
+
|
|
|
+ void
|
|
|
+ ClientSource::Shutdown()
|
|
|
+ {
|
|
|
+ NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
+ if (IsShutdown()) {
|
|
|
+diff --git a/dom/clients/manager/ClientSource.h b/dom/clients/manager/ClientSource.h
|
|
|
+--- a/dom/clients/manager/ClientSource.h
|
|
|
++++ b/dom/clients/manager/ClientSource.h
|
|
|
+@@ -30,20 +30,17 @@ class ClientGetInfoAndStateArgs;
|
|
|
+ class ClientManager;
|
|
|
+ class ClientPostMessageArgs;
|
|
|
+ class ClientSourceChild;
|
|
|
+ class ClientSourceConstructorArgs;
|
|
|
+ class ClientSourceExecutionReadyArgs;
|
|
|
+ class ClientState;
|
|
|
+ class ClientWindowState;
|
|
|
+ class PClientManagerChild;
|
|
|
+-
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-} // workers namespace
|
|
|
+
|
|
|
+ // ClientSource is an RAII style class that is designed to be held via
|
|
|
+ // a UniquePtr<>. When created ClientSource will register the existence
|
|
|
+ // of a client in the cross-process ClientManagerService. When the
|
|
|
+ // ClientSource is destroyed then client entry will be removed. Code
|
|
|
+ // that represents globals or browsing environments, such as nsGlobalWindow
|
|
|
+ // or WorkerPrivate, should use ClientManager to create a ClientSource.
|
|
|
+ class ClientSource final : public ClientThing<ClientSourceChild>
|
|
|
+@@ -53,34 +50,34 @@ class ClientSource final : public Client
|
|
|
+ NS_DECL_OWNINGTHREAD
|
|
|
+
|
|
|
+ RefPtr<ClientManager> mManager;
|
|
|
+ nsCOMPtr<nsISerialEventTarget> mEventTarget;
|
|
|
+
|
|
|
+ Variant<Nothing,
|
|
|
+ RefPtr<nsPIDOMWindowInner>,
|
|
|
+ nsCOMPtr<nsIDocShell>,
|
|
|
+- mozilla::dom::workers::WorkerPrivate*> mOwner;
|
|
|
++ WorkerPrivate*> mOwner;
|
|
|
+
|
|
|
+ ClientInfo mClientInfo;
|
|
|
+ Maybe<ServiceWorkerDescriptor> mController;
|
|
|
+
|
|
|
+ // Contained a de-duplicated list of ServiceWorker scope strings
|
|
|
+ // for which this client has called navigator.serviceWorker.register().
|
|
|
+ // Typically there will be either be zero or one scope strings, but
|
|
|
+ // there could be more. We keep this list until the client is closed.
|
|
|
+ AutoTArray<nsCString, 1> mRegisteringScopeList;
|
|
|
+
|
|
|
+ void
|
|
|
+ Shutdown();
|
|
|
+
|
|
|
+ void
|
|
|
+ ExecutionReady(const ClientSourceExecutionReadyArgs& aArgs);
|
|
|
+
|
|
|
+- mozilla::dom::workers::WorkerPrivate*
|
|
|
++ WorkerPrivate*
|
|
|
+ GetWorkerPrivate() const;
|
|
|
+
|
|
|
+ nsIDocShell*
|
|
|
+ GetDocShell() const;
|
|
|
+
|
|
|
+ void
|
|
|
+ MaybeCreateInitialDocument();
|
|
|
+
|
|
|
+@@ -97,17 +94,17 @@ class ClientSource final : public Client
|
|
|
+
|
|
|
+ public:
|
|
|
+ ~ClientSource();
|
|
|
+
|
|
|
+ nsPIDOMWindowInner*
|
|
|
+ GetInnerWindow() const;
|
|
|
+
|
|
|
+ void
|
|
|
+- WorkerExecutionReady(mozilla::dom::workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ WorkerExecutionReady(WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ nsresult
|
|
|
+ WindowExecutionReady(nsPIDOMWindowInner* aInnerWindow);
|
|
|
+
|
|
|
+ nsresult
|
|
|
+ DocShellExecutionReady(nsIDocShell* aDocShell);
|
|
|
+
|
|
|
+ void
|
|
|
+@@ -119,17 +116,17 @@ public:
|
|
|
+ const ClientInfo&
|
|
|
+ Info() const;
|
|
|
+
|
|
|
+ // Trigger a synchronous IPC ping to the parent process to confirm that
|
|
|
+ // the ClientSource actor has been created. This should only be used
|
|
|
+ // by the WorkerPrivate startup code to deal with a ClientHandle::Control()
|
|
|
+ // call racing on the main thread. Do not call this in other circumstances!
|
|
|
+ void
|
|
|
+- WorkerSyncPing(mozilla::dom::workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ WorkerSyncPing(WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ // Synchronously mark the ClientSource as controlled by the given service
|
|
|
+ // worker. This can happen as a result of a remote operation or directly
|
|
|
+ // by local code. For example, if a client's initial network load is
|
|
|
+ // intercepted by a controlling service worker then this should be called
|
|
|
+ // immediately.
|
|
|
+ //
|
|
|
+ // Note, there is no way to clear the controlling service worker because
|
|
|
+diff --git a/dom/crypto/WebCryptoTask.cpp b/dom/crypto/WebCryptoTask.cpp
|
|
|
+--- a/dom/crypto/WebCryptoTask.cpp
|
|
|
++++ b/dom/crypto/WebCryptoTask.cpp
|
|
|
+@@ -34,19 +34,16 @@ const SEC_ASN1Template SGN_DigestInfoTem
|
|
|
+ { SEC_ASN1_OCTET_STRING,
|
|
|
+ offsetof(SGNDigestInfo,digest) },
|
|
|
+ { 0, }
|
|
|
+ };
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using mozilla::dom::workers::GetCurrentThreadWorkerPrivate;
|
|
|
+-using mozilla::dom::workers::WorkerPrivate;
|
|
|
+-
|
|
|
+ // Pre-defined identifiers for telemetry histograms
|
|
|
+
|
|
|
+ enum TelemetryMethod {
|
|
|
+ TM_ENCRYPT = 0,
|
|
|
+ TM_DECRYPT = 1,
|
|
|
+ TM_SIGN = 2,
|
|
|
+ TM_VERIFY = 3,
|
|
|
+ TM_DIGEST = 4,
|
|
|
+diff --git a/dom/events/Event.cpp b/dom/events/Event.cpp
|
|
|
+--- a/dom/events/Event.cpp
|
|
|
++++ b/dom/events/Event.cpp
|
|
|
+@@ -329,17 +329,17 @@ Event::SetTrusted(bool aTrusted)
|
|
|
+ {
|
|
|
+ mEvent->mFlags.mIsTrusted = aTrusted;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool
|
|
|
+ Event::Init(mozilla::dom::EventTarget* aGlobal)
|
|
|
+ {
|
|
|
+ if (!mIsMainThreadEvent) {
|
|
|
+- return workers::IsCurrentThreadRunningChromeWorker();
|
|
|
++ return IsCurrentThreadRunningChromeWorker();
|
|
|
+ }
|
|
|
+ bool trusted = false;
|
|
|
+ nsCOMPtr<nsPIDOMWindowInner> w = do_QueryInterface(aGlobal);
|
|
|
+ if (w) {
|
|
|
+ nsCOMPtr<nsIDocument> d = w->GetExtantDoc();
|
|
|
+ if (d) {
|
|
|
+ trusted = nsContentUtils::IsChromeDoc(d);
|
|
|
+ nsIPresShell* s = d->GetShell();
|
|
|
+@@ -1113,18 +1113,17 @@ Event::TimeStampImpl() const
|
|
|
+ Performance* perf = win->GetPerformance();
|
|
|
+ if (NS_WARN_IF(!perf)) {
|
|
|
+ return 0.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ return perf->GetDOMTiming()->TimeStampToDOMHighRes(mEvent->mTimeStamp);
|
|
|
+ }
|
|
|
+
|
|
|
+- workers::WorkerPrivate* workerPrivate =
|
|
|
+- workers::GetCurrentThreadWorkerPrivate();
|
|
|
++ WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
+ MOZ_ASSERT(workerPrivate);
|
|
|
+
|
|
|
+ return workerPrivate->TimeStampToDOMHighRes(mEvent->mTimeStamp);
|
|
|
+ }
|
|
|
+
|
|
|
+ double
|
|
|
+ Event::TimeStamp() const
|
|
|
+ {
|
|
|
+diff --git a/dom/events/EventDispatcher.cpp b/dom/events/EventDispatcher.cpp
|
|
|
+--- a/dom/events/EventDispatcher.cpp
|
|
|
++++ b/dom/events/EventDispatcher.cpp
|
|
|
+@@ -920,17 +920,17 @@ EventDispatcher::DispatchDOMEvent(nsISup
|
|
|
+ innerEvent->mOriginalTarget = nullptr;
|
|
|
+ } else {
|
|
|
+ aDOMEvent->GetIsTrusted(&dontResetTrusted);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!dontResetTrusted) {
|
|
|
+ //Check security state to determine if dispatcher is trusted
|
|
|
+ bool trusted = NS_IsMainThread() ? nsContentUtils::LegacyIsCallerChromeOrNativeCode()
|
|
|
+- : mozilla::dom::workers::IsCurrentThreadRunningChromeWorker();
|
|
|
++ : mozilla::dom::IsCurrentThreadRunningChromeWorker();
|
|
|
+ aDOMEvent->SetTrusted(trusted);
|
|
|
+ }
|
|
|
+
|
|
|
+ return EventDispatcher::Dispatch(aTarget, aPresContext, innerEvent,
|
|
|
+ aDOMEvent, aEventStatus);
|
|
|
+ } else if (aEvent) {
|
|
|
+ return EventDispatcher::Dispatch(aTarget, aPresContext, aEvent,
|
|
|
+ aDOMEvent, aEventStatus);
|
|
|
+diff --git a/dom/events/JSEventHandler.cpp b/dom/events/JSEventHandler.cpp
|
|
|
+--- a/dom/events/JSEventHandler.cpp
|
|
|
++++ b/dom/events/JSEventHandler.cpp
|
|
|
+@@ -121,17 +121,17 @@ JSEventHandler::HandleEvent(nsIDOMEvent*
|
|
|
+
|
|
|
+ Event* event = aEvent->InternalDOMEvent();
|
|
|
+ bool isMainThread = event->IsMainThreadEvent();
|
|
|
+ bool isChromeHandler =
|
|
|
+ isMainThread ?
|
|
|
+ nsContentUtils::ObjectPrincipal(
|
|
|
+ GetTypedEventHandler().Ptr()->CallbackPreserveColor()) ==
|
|
|
+ nsContentUtils::GetSystemPrincipal() :
|
|
|
+- mozilla::dom::workers::IsCurrentThreadRunningChromeWorker();
|
|
|
++ mozilla::dom::IsCurrentThreadRunningChromeWorker();
|
|
|
+
|
|
|
+ if (mTypedHandler.Type() == TypedEventHandler::eOnError) {
|
|
|
+ MOZ_ASSERT_IF(mEventName, mEventName == nsGkAtoms::onerror);
|
|
|
+
|
|
|
+ nsString errorMsg, file;
|
|
|
+ EventOrString msgOrEvent;
|
|
|
+ Optional<nsAString> fileName;
|
|
|
+ Optional<uint32_t> lineNumber;
|
|
|
+diff --git a/dom/fetch/Fetch.cpp b/dom/fetch/Fetch.cpp
|
|
|
+--- a/dom/fetch/Fetch.cpp
|
|
|
++++ b/dom/fetch/Fetch.cpp
|
|
|
+@@ -184,17 +184,17 @@ class WorkerFetchResolver final : public
|
|
|
+
|
|
|
+ // Touched only on the worker thread.
|
|
|
+ RefPtr<FetchObserver> mFetchObserver;
|
|
|
+ UniquePtr<WorkerHolder> mWorkerHolder;
|
|
|
+
|
|
|
+ public:
|
|
|
+ // Returns null if worker is shutting down.
|
|
|
+ static already_AddRefed<WorkerFetchResolver>
|
|
|
+- Create(workers::WorkerPrivate* aWorkerPrivate, Promise* aPromise,
|
|
|
++ Create(WorkerPrivate* aWorkerPrivate, Promise* aPromise,
|
|
|
+ AbortSignal* aSignal, FetchObserver* aObserver)
|
|
|
+ {
|
|
|
+ MOZ_ASSERT(aWorkerPrivate);
|
|
|
+ aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
+ RefPtr<PromiseWorkerProxy> proxy =
|
|
|
+ PromiseWorkerProxy::Create(aWorkerPrivate, aPromise);
|
|
|
+ if (!proxy) {
|
|
|
+ return nullptr;
|
|
|
+@@ -861,17 +861,17 @@ WorkerFetchResolver::FlushConsoleReport(
|
|
|
+ {
|
|
|
+ AssertIsOnMainThread();
|
|
|
+ MOZ_ASSERT(mPromiseProxy);
|
|
|
+
|
|
|
+ if(!mReporter) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+- workers::WorkerPrivate* worker = mPromiseProxy->GetWorkerPrivate();
|
|
|
++ WorkerPrivate* worker = mPromiseProxy->GetWorkerPrivate();
|
|
|
+ if (!worker) {
|
|
|
+ mReporter->FlushReportsToConsole(0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (worker->IsServiceWorker()) {
|
|
|
+ // Flush to service worker
|
|
|
+ mReporter->FlushReportsToConsoleForServiceWorkerScope(worker->ServiceWorkerScope());
|
|
|
+diff --git a/dom/fetch/Fetch.h b/dom/fetch/Fetch.h
|
|
|
+--- a/dom/fetch/Fetch.h
|
|
|
++++ b/dom/fetch/Fetch.h
|
|
|
+@@ -30,21 +30,19 @@ namespace dom {
|
|
|
+
|
|
|
+ class BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString;
|
|
|
+ class BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString;
|
|
|
+ class BlobImpl;
|
|
|
+ class InternalRequest;
|
|
|
+ class OwningBlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString;
|
|
|
+ struct ReadableStream;
|
|
|
+ class RequestOrUSVString;
|
|
|
+-enum class CallerType : uint32_t;
|
|
|
++class WorkerPrivate;
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+-class WorkerPrivate;
|
|
|
+-} // namespace workers
|
|
|
++enum class CallerType : uint32_t;
|
|
|
+
|
|
|
+ already_AddRefed<Promise>
|
|
|
+ FetchRequest(nsIGlobalObject* aGlobal, const RequestOrUSVString& aInput,
|
|
|
+ const RequestInit& aInit, CallerType aCallerType,
|
|
|
+ ErrorResult& aRv);
|
|
|
+
|
|
|
+ nsresult
|
|
|
+ UpdateRequestReferrer(nsIGlobalObject* aGlobal, InternalRequest* aRequest);
|
|
|
+@@ -248,17 +246,17 @@ public:
|
|
|
+ // AbortFollower
|
|
|
+ void
|
|
|
+ Abort() override;
|
|
|
+
|
|
|
+ protected:
|
|
|
+ nsCOMPtr<nsIGlobalObject> mOwner;
|
|
|
+
|
|
|
+ // Always set whenever the FetchBody is created on the worker thread.
|
|
|
+- workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ WorkerPrivate* mWorkerPrivate;
|
|
|
+
|
|
|
+ // This is the ReadableStream exposed to content. It's underlying source is a
|
|
|
+ // FetchStream object.
|
|
|
+ JS::Heap<JSObject*> mReadableStreamBody;
|
|
|
+
|
|
|
+ // This is the Reader used to retrieve data from the body.
|
|
|
+ JS::Heap<JSObject*> mReadableStreamReader;
|
|
|
+ RefPtr<FetchStreamReader> mFetchStreamReader;
|
|
|
+diff --git a/dom/fetch/FetchConsumer.h b/dom/fetch/FetchConsumer.h
|
|
|
+--- a/dom/fetch/FetchConsumer.h
|
|
|
++++ b/dom/fetch/FetchConsumer.h
|
|
|
+@@ -15,20 +15,17 @@
|
|
|
+
|
|
|
+ class nsIThread;
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+ class Promise;
|
|
|
+ class WorkerHolder;
|
|
|
+-
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+
|
|
|
+ template <class Derived> class FetchBody;
|
|
|
+
|
|
|
+ // FetchBody is not thread-safe but we need to move it around threads.
|
|
|
+ // In order to keep it alive all the time, we use a WorkerHolder, if created on
|
|
|
+ // workers, plus a this consumer.
|
|
|
+ template <class Derived>
|
|
|
+ class FetchBodyConsumer final : public nsIObserver
|
|
|
+@@ -57,17 +54,17 @@ public:
|
|
|
+ ContinueConsumeBody(nsresult aStatus, uint32_t aLength, uint8_t* aResult);
|
|
|
+
|
|
|
+ void
|
|
|
+ ContinueConsumeBlobBody(BlobImpl* aBlobImpl);
|
|
|
+
|
|
|
+ void
|
|
|
+ ShutDownMainThreadConsuming();
|
|
|
+
|
|
|
+- workers::WorkerPrivate*
|
|
|
++ WorkerPrivate*
|
|
|
+ GetWorkerPrivate() const
|
|
|
+ {
|
|
|
+ return mWorkerPrivate;
|
|
|
+ }
|
|
|
+
|
|
|
+ void
|
|
|
+ NullifyConsumeBodyPump()
|
|
|
+ {
|
|
|
+@@ -76,17 +73,17 @@ public:
|
|
|
+ }
|
|
|
+
|
|
|
+ // AbortFollower
|
|
|
+ void Abort() override;
|
|
|
+
|
|
|
+ private:
|
|
|
+ FetchBodyConsumer(nsIEventTarget* aMainThreadEventTarget,
|
|
|
+ nsIGlobalObject* aGlobalObject,
|
|
|
+- workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ WorkerPrivate* aWorkerPrivate,
|
|
|
+ FetchBody<Derived>* aBody,
|
|
|
+ nsIInputStream* aBodyStream,
|
|
|
+ Promise* aPromise,
|
|
|
+ FetchConsumeType aType);
|
|
|
+
|
|
|
+ ~FetchBodyConsumer();
|
|
|
+
|
|
|
+ void
|
|
|
+@@ -112,17 +109,17 @@ private:
|
|
|
+ // Set when consuming the body is attempted on a worker.
|
|
|
+ // Unset when consumption is done/aborted.
|
|
|
+ // This WorkerHolder keeps alive the consumer via a cycle.
|
|
|
+ UniquePtr<WorkerHolder> mWorkerHolder;
|
|
|
+
|
|
|
+ nsCOMPtr<nsIGlobalObject> mGlobal;
|
|
|
+
|
|
|
+ // Always set whenever the FetchBodyConsumer is created on the worker thread.
|
|
|
+- workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ WorkerPrivate* mWorkerPrivate;
|
|
|
+
|
|
|
+ // Touched on the main-thread only.
|
|
|
+ nsCOMPtr<nsIInputStreamPump> mConsumeBodyPump;
|
|
|
+
|
|
|
+ // Only ever set once, always on target thread.
|
|
|
+ FetchConsumeType mConsumeType;
|
|
|
+ RefPtr<Promise> mConsumePromise;
|
|
|
+
|
|
|
+diff --git a/dom/fetch/FetchUtil.cpp b/dom/fetch/FetchUtil.cpp
|
|
|
+--- a/dom/fetch/FetchUtil.cpp
|
|
|
++++ b/dom/fetch/FetchUtil.cpp
|
|
|
+@@ -403,17 +403,17 @@ class JSStreamConsumer final : public ns
|
|
|
+ }
|
|
|
+
|
|
|
+ public:
|
|
|
+ NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
+
|
|
|
+ static bool Start(nsIInputStream* aStream,
|
|
|
+ JS::StreamConsumer* aConsumer,
|
|
|
+ nsIGlobalObject* aGlobal,
|
|
|
+- workers::WorkerPrivate* aMaybeWorker)
|
|
|
++ WorkerPrivate* aMaybeWorker)
|
|
|
+ {
|
|
|
+ nsresult rv;
|
|
|
+
|
|
|
+ bool nonBlocking = false;
|
|
|
+ rv = aStream->IsNonBlocking(&nonBlocking);
|
|
|
+ if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+@@ -526,17 +526,17 @@ ThrowException(JSContext* aCx, unsigned
|
|
|
+ }
|
|
|
+
|
|
|
+ // static
|
|
|
+ bool
|
|
|
+ FetchUtil::StreamResponseToJS(JSContext* aCx,
|
|
|
+ JS::HandleObject aObj,
|
|
|
+ JS::MimeType aMimeType,
|
|
|
+ JS::StreamConsumer* aConsumer,
|
|
|
+- workers::WorkerPrivate* aMaybeWorker)
|
|
|
++ WorkerPrivate* aMaybeWorker)
|
|
|
+ {
|
|
|
+ MOZ_ASSERT(!aMaybeWorker == NS_IsMainThread());
|
|
|
+
|
|
|
+ RefPtr<Response> response;
|
|
|
+ nsresult rv = UNWRAP_OBJECT(Response, aObj, response);
|
|
|
+ if (NS_FAILED(rv)) {
|
|
|
+ return ThrowException(aCx, JSMSG_BAD_RESPONSE_VALUE);
|
|
|
+ }
|
|
|
+diff --git a/dom/fetch/FetchUtil.h b/dom/fetch/FetchUtil.h
|
|
|
+--- a/dom/fetch/FetchUtil.h
|
|
|
++++ b/dom/fetch/FetchUtil.h
|
|
|
+@@ -17,20 +17,17 @@
|
|
|
+ class nsIPrincipal;
|
|
|
+ class nsIDocument;
|
|
|
+ class nsIHttpChannel;
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+ class InternalRequest;
|
|
|
+-
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+
|
|
|
+ class FetchUtil final
|
|
|
+ {
|
|
|
+ private:
|
|
|
+ FetchUtil() = delete;
|
|
|
+
|
|
|
+ public:
|
|
|
+ /**
|
|
|
+@@ -64,14 +61,14 @@ public:
|
|
|
+ * given JSContext before returning false. If executing in a worker, the
|
|
|
+ * WorkerPrivate must be given.
|
|
|
+ */
|
|
|
+ static bool
|
|
|
+ StreamResponseToJS(JSContext* aCx,
|
|
|
+ JS::HandleObject aObj,
|
|
|
+ JS::MimeType aMimeType,
|
|
|
+ JS::StreamConsumer* aConsumer,
|
|
|
+- workers::WorkerPrivate* aMaybeWorker);
|
|
|
++ WorkerPrivate* aMaybeWorker);
|
|
|
+ };
|
|
|
+
|
|
|
+ } // namespace dom
|
|
|
+ } // namespace mozilla
|
|
|
+ #endif
|
|
|
+diff --git a/dom/fetch/Request.cpp b/dom/fetch/Request.cpp
|
|
|
+--- a/dom/fetch/Request.cpp
|
|
|
++++ b/dom/fetch/Request.cpp
|
|
|
+@@ -185,17 +185,17 @@ GetRequestURLFromChrome(const nsAString&
|
|
|
+ if (NS_WARN_IF(aRv.Failed())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ already_AddRefed<URL>
|
|
|
+ ParseURLFromWorker(const GlobalObject& aGlobal, const nsAString& aInput,
|
|
|
+ ErrorResult& aRv)
|
|
|
+ {
|
|
|
+- workers::WorkerPrivate* worker = workers::GetCurrentThreadWorkerPrivate();
|
|
|
++ WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
|
|
|
+ MOZ_ASSERT(worker);
|
|
|
+ worker->AssertIsOnWorkerThread();
|
|
|
+
|
|
|
+ NS_ConvertUTF8toUTF16 baseURL(worker->GetLocationInfo().mHref);
|
|
|
+ RefPtr<URL> url = URL::WorkerConstructor(aGlobal, aInput, baseURL, aRv);
|
|
|
+ if (NS_WARN_IF(aRv.Failed())) {
|
|
|
+ aRv.ThrowTypeError<MSG_INVALID_URL>(aInput);
|
|
|
+ }
|
|
|
+@@ -246,17 +246,17 @@ GetRequestURLFromWorker(const GlobalObje
|
|
|
+ if (NS_WARN_IF(aRv.Failed())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ class ReferrerSameOriginChecker final : public WorkerMainThreadRunnable
|
|
|
+ {
|
|
|
+ public:
|
|
|
+- ReferrerSameOriginChecker(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ ReferrerSameOriginChecker(WorkerPrivate* aWorkerPrivate,
|
|
|
+ const nsAString& aReferrerURL,
|
|
|
+ nsresult& aResult)
|
|
|
+ : WorkerMainThreadRunnable(aWorkerPrivate,
|
|
|
+ NS_LITERAL_CSTRING("Fetch :: Referrer same origin check")),
|
|
|
+ mReferrerURL(aReferrerURL),
|
|
|
+ mResult(aResult)
|
|
|
+ {
|
|
|
+ mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
+@@ -402,17 +402,17 @@ Request::Constructor(const GlobalObject&
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+ url->Stringify(referrerURL, aRv);
|
|
|
+ if (NS_WARN_IF(aRv.Failed())) {
|
|
|
+ aRv.ThrowTypeError<MSG_INVALID_REFERRER_URL>(referrer);
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+ if (!referrerURL.EqualsLiteral(kFETCH_CLIENT_REFERRER_STR)) {
|
|
|
+- workers::WorkerPrivate* worker = workers::GetCurrentThreadWorkerPrivate();
|
|
|
++ WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
|
|
|
+ nsresult rv = NS_OK;
|
|
|
+ // ReferrerSameOriginChecker uses a sync loop to get the main thread
|
|
|
+ // to perform the same-origin check. Overall, on Workers this method
|
|
|
+ // can create 3 sync loops (two for constructing URLs and one here) so
|
|
|
+ // in the future we may want to optimize it all by off-loading all of
|
|
|
+ // this work in a single sync loop.
|
|
|
+ RefPtr<ReferrerSameOriginChecker> checker =
|
|
|
+ new ReferrerSameOriginChecker(worker, referrerURL, rv);
|
|
|
+@@ -440,17 +440,17 @@ Request::Constructor(const GlobalObject&
|
|
|
+ if (window) {
|
|
|
+ nsCOMPtr<nsIDocument> doc;
|
|
|
+ doc = window->GetExtantDoc();
|
|
|
+ if (doc) {
|
|
|
+ request->SetEnvironmentReferrerPolicy(doc->GetReferrerPolicy());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+- workers::WorkerPrivate* worker = workers::GetCurrentThreadWorkerPrivate();
|
|
|
++ WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
|
|
|
+ if (worker) {
|
|
|
+ worker->AssertIsOnWorkerThread();
|
|
|
+ request->SetEnvironmentReferrerPolicy(worker->GetReferrerPolicy());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mode != RequestMode::EndGuard_) {
|
|
|
+ request->SetMode(mode);
|
|
|
+diff --git a/dom/fetch/Response.cpp b/dom/fetch/Response.cpp
|
|
|
+--- a/dom/fetch/Response.cpp
|
|
|
++++ b/dom/fetch/Response.cpp
|
|
|
+@@ -114,17 +114,17 @@ Response::Redirect(const GlobalObject& a
|
|
|
+ nsAutoCString spec;
|
|
|
+ aRv = resolvedURI->GetSpec(spec);
|
|
|
+ if (NS_WARN_IF(aRv.Failed())) {
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+
|
|
|
+ CopyUTF8toUTF16(spec, parsedURL);
|
|
|
+ } else {
|
|
|
+- workers::WorkerPrivate* worker = workers::GetCurrentThreadWorkerPrivate();
|
|
|
++ WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
|
|
|
+ MOZ_ASSERT(worker);
|
|
|
+ worker->AssertIsOnWorkerThread();
|
|
|
+
|
|
|
+ NS_ConvertUTF8toUTF16 baseURL(worker->GetLocationInfo().mHref);
|
|
|
+ RefPtr<URL> url = URL::WorkerConstructor(aGlobal, aUrl, baseURL, aRv);
|
|
|
+ if (aRv.Failed()) {
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+@@ -199,17 +199,17 @@ Response::Constructor(const GlobalObject
|
|
|
+ nsIDocument* doc = window->GetExtantDoc();
|
|
|
+ MOZ_ASSERT(doc);
|
|
|
+ info.InitFromDocument(doc);
|
|
|
+ } else {
|
|
|
+ info.InitFromChromeGlobal(global);
|
|
|
+ }
|
|
|
+ internalResponse->InitChannelInfo(info);
|
|
|
+ } else {
|
|
|
+- workers::WorkerPrivate* worker = workers::GetCurrentThreadWorkerPrivate();
|
|
|
++ WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
|
|
|
+ MOZ_ASSERT(worker);
|
|
|
+ internalResponse->InitChannelInfo(worker->GetChannelInfo());
|
|
|
+ }
|
|
|
+
|
|
|
+ RefPtr<Response> r = new Response(global, internalResponse, nullptr);
|
|
|
+
|
|
|
+ if (aInit.mHeaders.WasPassed()) {
|
|
|
+ internalResponse->Headers()->Clear();
|
|
|
+diff --git a/dom/file/FileBlobImpl.cpp b/dom/file/FileBlobImpl.cpp
|
|
|
+--- a/dom/file/FileBlobImpl.cpp
|
|
|
++++ b/dom/file/FileBlobImpl.cpp
|
|
|
+@@ -13,18 +13,16 @@
|
|
|
+ #include "nsIFileStreams.h"
|
|
|
+ #include "nsIMIMEService.h"
|
|
|
+ #include "nsNetUtil.h"
|
|
|
+ #include "nsStreamUtils.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ NS_IMPL_ISUPPORTS_INHERITED0(FileBlobImpl, BlobImpl)
|
|
|
+
|
|
|
+ FileBlobImpl::FileBlobImpl(nsIFile* aFile)
|
|
|
+ : BaseBlobImpl(EmptyString(), EmptyString(), UINT64_MAX, INT64_MAX)
|
|
|
+ , mFile(aFile)
|
|
|
+ , mWholeFile(true)
|
|
|
+ , mFileId(-1)
|
|
|
+ {
|
|
|
+diff --git a/dom/file/FileReader.cpp b/dom/file/FileReader.cpp
|
|
|
+--- a/dom/file/FileReader.cpp
|
|
|
++++ b/dom/file/FileReader.cpp
|
|
|
+@@ -28,18 +28,16 @@
|
|
|
+ #include "xpcpublic.h"
|
|
|
+
|
|
|
+ #include "WorkerPrivate.h"
|
|
|
+ #include "WorkerScope.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ #define ABORT_STR "abort"
|
|
|
+ #define LOAD_STR "load"
|
|
|
+ #define LOADSTART_STR "loadstart"
|
|
|
+ #define LOADEND_STR "loadend"
|
|
|
+ #define ERROR_STR "error"
|
|
|
+ #define PROGRESS_STR "progress"
|
|
|
+
|
|
|
+ const uint64_t kUnknownSize = uint64_t(-1);
|
|
|
+diff --git a/dom/file/FileReader.h b/dom/file/FileReader.h
|
|
|
+--- a/dom/file/FileReader.h
|
|
|
++++ b/dom/file/FileReader.h
|
|
|
+@@ -23,20 +23,17 @@
|
|
|
+ class nsITimer;
|
|
|
+ class nsIEventTarget;
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+ class Blob;
|
|
|
+ class DOMException;
|
|
|
+-
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+
|
|
|
+ extern const uint64_t kUnknownSize;
|
|
|
+
|
|
|
+ class FileReaderDecreaseBusyCounter;
|
|
|
+
|
|
|
+ class FileReader final : public DOMEventTargetHelper,
|
|
|
+ public nsIInterfaceRequestor,
|
|
|
+ public nsSupportsWeakReference,
|
|
|
+@@ -44,17 +41,17 @@ class FileReader final : public DOMEvent
|
|
|
+ public nsITimerCallback,
|
|
|
+ public nsINamed,
|
|
|
+ public WorkerHolder
|
|
|
+ {
|
|
|
+ friend class FileReaderDecreaseBusyCounter;
|
|
|
+
|
|
|
+ public:
|
|
|
+ FileReader(nsIGlobalObject* aGlobal,
|
|
|
+- workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ NS_DECL_ISUPPORTS_INHERITED
|
|
|
+
|
|
|
+ NS_DECL_NSITIMERCALLBACK
|
|
|
+ NS_DECL_NSIINPUTSTREAMCALLBACK
|
|
|
+ NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
+ NS_DECL_NSINAMED
|
|
|
+
|
|
|
+@@ -196,15 +193,15 @@ private:
|
|
|
+ uint64_t mTotal;
|
|
|
+ uint64_t mTransferred;
|
|
|
+
|
|
|
+ nsCOMPtr<nsIEventTarget> mTarget;
|
|
|
+
|
|
|
+ uint64_t mBusyCount;
|
|
|
+
|
|
|
+ // Kept alive with a WorkerHolder.
|
|
|
+- workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ WorkerPrivate* mWorkerPrivate;
|
|
|
+ };
|
|
|
+
|
|
|
+ } // dom namespace
|
|
|
+ } // mozilla namespace
|
|
|
+
|
|
|
+ #endif // mozilla_dom_FileReader_h
|
|
|
+diff --git a/dom/file/FileReaderSync.cpp b/dom/file/FileReaderSync.cpp
|
|
|
+--- a/dom/file/FileReaderSync.cpp
|
|
|
++++ b/dom/file/FileReaderSync.cpp
|
|
|
+@@ -28,17 +28,16 @@
|
|
|
+ #include "nsIAsyncInputStream.h"
|
|
|
+ #include "WorkerPrivate.h"
|
|
|
+ #include "WorkerRunnable.h"
|
|
|
+
|
|
|
+ #include "RuntimeService.h"
|
|
|
+
|
|
|
+ using namespace mozilla;
|
|
|
+ using namespace mozilla::dom;
|
|
|
+-using namespace mozilla::dom::workers;
|
|
|
+ using mozilla::dom::Optional;
|
|
|
+ using mozilla::dom::GlobalObject;
|
|
|
+
|
|
|
+ // static
|
|
|
+ already_AddRefed<FileReaderSync>
|
|
|
+ FileReaderSync::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
|
|
|
+ {
|
|
|
+ RefPtr<FileReaderSync> frs = new FileReaderSync();
|
|
|
+diff --git a/dom/network/Connection.cpp b/dom/network/Connection.cpp
|
|
|
+--- a/dom/network/Connection.cpp
|
|
|
++++ b/dom/network/Connection.cpp
|
|
|
+@@ -15,18 +15,16 @@
|
|
|
+ * We have to use macros here because our leak analysis tool things we are
|
|
|
+ * leaking strings when we have |static const nsString|. Sad :(
|
|
|
+ */
|
|
|
+ #define CHANGE_EVENT_NAME NS_LITERAL_STRING("typechange")
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ namespace network {
|
|
|
+
|
|
|
+ NS_IMPL_QUERY_INTERFACE_INHERITED(Connection, DOMEventTargetHelper,
|
|
|
+ nsINetworkProperties)
|
|
|
+
|
|
|
+ // Don't use |Connection| alone, since that confuses nsTraceRefcnt since
|
|
|
+ // we're not the only class with that name.
|
|
|
+ NS_IMPL_ADDREF_INHERITED(dom::network::Connection, DOMEventTargetHelper)
|
|
|
+@@ -107,17 +105,17 @@ Connection::Update(ConnectionType aType,
|
|
|
+ /* static */ Connection*
|
|
|
+ Connection::CreateForWindow(nsPIDOMWindowInner* aWindow)
|
|
|
+ {
|
|
|
+ MOZ_ASSERT(aWindow);
|
|
|
+ return new ConnectionMainThread(aWindow);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* static */ already_AddRefed<Connection>
|
|
|
+-Connection::CreateForWorker(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++Connection::CreateForWorker(WorkerPrivate* aWorkerPrivate,
|
|
|
+ ErrorResult& aRv)
|
|
|
+ {
|
|
|
+ MOZ_ASSERT(aWorkerPrivate);
|
|
|
+ aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
+ return ConnectionWorker::Create(aWorkerPrivate, aRv);
|
|
|
+ }
|
|
|
+
|
|
|
+ } // namespace network
|
|
|
+diff --git a/dom/network/Connection.h b/dom/network/Connection.h
|
|
|
+--- a/dom/network/Connection.h
|
|
|
++++ b/dom/network/Connection.h
|
|
|
+@@ -16,19 +16,17 @@
|
|
|
+ namespace mozilla {
|
|
|
+
|
|
|
+ namespace hal {
|
|
|
+ class NetworkInformation;
|
|
|
+ } // namespace hal
|
|
|
+
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-} // namespace workers
|
|
|
+
|
|
|
+ namespace network {
|
|
|
+
|
|
|
+ class Connection : public DOMEventTargetHelper
|
|
|
+ , public nsINetworkProperties
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ NS_DECL_ISUPPORTS_INHERITED
|
|
|
+@@ -36,17 +34,17 @@ public:
|
|
|
+ NS_DECL_OWNINGTHREAD
|
|
|
+
|
|
|
+ NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
|
|
|
+
|
|
|
+ static Connection*
|
|
|
+ CreateForWindow(nsPIDOMWindowInner* aWindow);
|
|
|
+
|
|
|
+ static already_AddRefed<Connection>
|
|
|
+- CreateForWorker(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ CreateForWorker(WorkerPrivate* aWorkerPrivate,
|
|
|
+ ErrorResult& aRv);
|
|
|
+
|
|
|
+ void Shutdown();
|
|
|
+
|
|
|
+ // WebIDL
|
|
|
+
|
|
|
+ virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
+ JS::Handle<JSObject*> aGivenProto) override;
|
|
|
+diff --git a/dom/network/ConnectionWorker.h b/dom/network/ConnectionWorker.h
|
|
|
+--- a/dom/network/ConnectionWorker.h
|
|
|
++++ b/dom/network/ConnectionWorker.h
|
|
|
+@@ -18,25 +18,25 @@ namespace network {
|
|
|
+ class ConnectionProxy;
|
|
|
+
|
|
|
+ class ConnectionWorker final : public Connection
|
|
|
+ {
|
|
|
+ friend class ConnectionProxy;
|
|
|
+
|
|
|
+ public:
|
|
|
+ static already_AddRefed<ConnectionWorker>
|
|
|
+- Create(workers::WorkerPrivate* aWorkerPrivate, ErrorResult& aRv);
|
|
|
++ Create(WorkerPrivate* aWorkerPrivate, ErrorResult& aRv);
|
|
|
+
|
|
|
+ private:
|
|
|
+- explicit ConnectionWorker(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ explicit ConnectionWorker(WorkerPrivate* aWorkerPrivate);
|
|
|
+ ~ConnectionWorker();
|
|
|
+
|
|
|
+ virtual void ShutdownInternal() override;
|
|
|
+
|
|
|
+- workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ WorkerPrivate* mWorkerPrivate;
|
|
|
+ RefPtr<ConnectionProxy> mProxy;
|
|
|
+ };
|
|
|
+
|
|
|
+ } // namespace network
|
|
|
+ } // namespace dom
|
|
|
+ } // namespace mozilla
|
|
|
+
|
|
|
+ #endif // mozilla_dom_network_ConnectionWorker_h
|
|
|
+diff --git a/dom/notification/Notification.cpp b/dom/notification/Notification.cpp
|
|
|
+--- a/dom/notification/Notification.cpp
|
|
|
++++ b/dom/notification/Notification.cpp
|
|
|
+@@ -54,17 +54,17 @@
|
|
|
+ #include "nsXULAppAPI.h"
|
|
|
+ #include "WorkerPrivate.h"
|
|
|
+ #include "WorkerRunnable.h"
|
|
|
+ #include "WorkerScope.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
++using workers::AssertIsOnMainThread;
|
|
|
+
|
|
|
+ struct NotificationStrings
|
|
|
+ {
|
|
|
+ const nsString mID;
|
|
|
+ const nsString mTitle;
|
|
|
+ const nsString mDir;
|
|
|
+ const nsString mLang;
|
|
|
+ const nsString mBody;
|
|
|
+diff --git a/dom/notification/Notification.h b/dom/notification/Notification.h
|
|
|
+--- a/dom/notification/Notification.h
|
|
|
++++ b/dom/notification/Notification.h
|
|
|
+@@ -24,20 +24,17 @@ class nsIPrincipal;
|
|
|
+ class nsIVariant;
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+ class NotificationRef;
|
|
|
+ class WorkerNotificationObserver;
|
|
|
+ class Promise;
|
|
|
+-
|
|
|
+-namespace workers {
|
|
|
+- class WorkerPrivate;
|
|
|
+-} // namespace workers
|
|
|
++class WorkerPrivate;
|
|
|
+
|
|
|
+ class Notification;
|
|
|
+ class NotificationWorkerHolder final : public WorkerHolder
|
|
|
+ {
|
|
|
+ // Since the feature is strongly held by a Notification, it is ok to hold
|
|
|
+ // a raw pointer here.
|
|
|
+ Notification* mNotification;
|
|
|
+
|
|
|
+@@ -215,17 +212,17 @@ public:
|
|
|
+ const GetNotificationOptions& aFilter,
|
|
|
+ const nsAString& aScope,
|
|
|
+ ErrorResult& aRv);
|
|
|
+
|
|
|
+ static already_AddRefed<Promise> Get(const GlobalObject& aGlobal,
|
|
|
+ const GetNotificationOptions& aFilter,
|
|
|
+ ErrorResult& aRv);
|
|
|
+
|
|
|
+- static already_AddRefed<Promise> WorkerGet(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ static already_AddRefed<Promise> WorkerGet(WorkerPrivate* aWorkerPrivate,
|
|
|
+ const GetNotificationOptions& aFilter,
|
|
|
+ const nsAString& aScope,
|
|
|
+ ErrorResult& aRv);
|
|
|
+
|
|
|
+ // Notification implementation of
|
|
|
+ // ServiceWorkerRegistration.showNotification.
|
|
|
+ //
|
|
|
+ //
|
|
|
+@@ -258,17 +255,17 @@ public:
|
|
|
+
|
|
|
+ void AssertIsOnTargetThread() const
|
|
|
+ {
|
|
|
+ MOZ_ASSERT(IsTargetThread());
|
|
|
+ }
|
|
|
+
|
|
|
+ // Initialized on the worker thread, never unset, and always used in
|
|
|
+ // a read-only capacity. Used on any thread.
|
|
|
+- workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ WorkerPrivate* mWorkerPrivate;
|
|
|
+
|
|
|
+ // Main thread only.
|
|
|
+ WorkerNotificationObserver* mObserver;
|
|
|
+
|
|
|
+ // The NotificationTask calls ShowInternal()/CloseInternal() on the
|
|
|
+ // Notification. At this point the task has ownership of the Notification. It
|
|
|
+ // passes this on to the Notification itself via mTempRef so that
|
|
|
+ // ShowInternal()/CloseInternal() may pass it along appropriately (or release
|
|
|
+diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp
|
|
|
+--- a/dom/performance/Performance.cpp
|
|
|
++++ b/dom/performance/Performance.cpp
|
|
|
+@@ -19,30 +19,28 @@
|
|
|
+ #include "mozilla/ErrorResult.h"
|
|
|
+ #include "mozilla/dom/PerformanceBinding.h"
|
|
|
+ #include "mozilla/dom/PerformanceEntryEvent.h"
|
|
|
+ #include "mozilla/dom/PerformanceNavigationBinding.h"
|
|
|
+ #include "mozilla/dom/PerformanceObserverBinding.h"
|
|
|
+ #include "mozilla/dom/PerformanceNavigationTiming.h"
|
|
|
+ #include "mozilla/IntegerPrintfMacros.h"
|
|
|
+ #include "mozilla/Preferences.h"
|
|
|
+-#include "WorkerPrivate.h"
|
|
|
+-#include "WorkerRunnable.h"
|
|
|
++#include "mozilla/dom/WorkerPrivate.h"
|
|
|
++#include "mozilla/dom/WorkerRunnable.h"
|
|
|
+
|
|
|
+ #ifdef MOZ_GECKO_PROFILER
|
|
|
+ #include "ProfilerMarkerPayload.h"
|
|
|
+ #endif
|
|
|
+
|
|
|
+ #define PERFLOG(msg, ...) printf_stderr(msg, ##__VA_ARGS__)
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ namespace {
|
|
|
+
|
|
|
+ class PrefEnabledRunnable final
|
|
|
+ : public WorkerCheckAPIExposureOnMainThreadRunnable
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ PrefEnabledRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
+ const nsCString& aPrefName)
|
|
|
+@@ -89,17 +87,17 @@ Performance::CreateForMainThread(nsPIDOM
|
|
|
+ MOZ_ASSERT(NS_IsMainThread());
|
|
|
+
|
|
|
+ RefPtr<Performance> performance =
|
|
|
+ new PerformanceMainThread(aWindow, aDOMTiming, aChannel);
|
|
|
+ return performance.forget();
|
|
|
+ }
|
|
|
+
|
|
|
+ /* static */ already_AddRefed<Performance>
|
|
|
+-Performance::CreateForWorker(workers::WorkerPrivate* aWorkerPrivate)
|
|
|
++Performance::CreateForWorker(WorkerPrivate* aWorkerPrivate)
|
|
|
+ {
|
|
|
+ MOZ_ASSERT(aWorkerPrivate);
|
|
|
+ aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
+
|
|
|
+ RefPtr<Performance> performance = new PerformanceWorker(aWorkerPrivate);
|
|
|
+ return performance.forget();
|
|
|
+ }
|
|
|
+
|
|
|
+diff --git a/dom/performance/Performance.h b/dom/performance/Performance.h
|
|
|
+--- a/dom/performance/Performance.h
|
|
|
++++ b/dom/performance/Performance.h
|
|
|
+@@ -21,20 +21,17 @@ class ErrorResult;
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+ class PerformanceEntry;
|
|
|
+ class PerformanceNavigation;
|
|
|
+ class PerformanceObserver;
|
|
|
+ class PerformanceService;
|
|
|
+ class PerformanceStorage;
|
|
|
+ class PerformanceTiming;
|
|
|
+-
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+
|
|
|
+ // Base class for main-thread and worker Performance API
|
|
|
+ class Performance : public DOMEventTargetHelper
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ NS_DECL_ISUPPORTS_INHERITED
|
|
|
+ NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Performance,
|
|
|
+ DOMEventTargetHelper)
|
|
|
+@@ -42,17 +39,17 @@ public:
|
|
|
+ static bool IsObserverEnabled(JSContext* aCx, JSObject* aGlobal);
|
|
|
+
|
|
|
+ static already_AddRefed<Performance>
|
|
|
+ CreateForMainThread(nsPIDOMWindowInner* aWindow,
|
|
|
+ nsDOMNavigationTiming* aDOMTiming,
|
|
|
+ nsITimedChannel* aChannel);
|
|
|
+
|
|
|
+ static already_AddRefed<Performance>
|
|
|
+- CreateForWorker(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ CreateForWorker(WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ JSObject* WrapObject(JSContext *cx,
|
|
|
+ JS::Handle<JSObject*> aGivenProto) override;
|
|
|
+
|
|
|
+ virtual void GetEntries(nsTArray<RefPtr<PerformanceEntry>>& aRetval);
|
|
|
+
|
|
|
+ virtual void GetEntriesByType(const nsAString& aEntryType,
|
|
|
+ nsTArray<RefPtr<PerformanceEntry>>& aRetval);
|
|
|
+diff --git a/dom/performance/PerformanceObserver.cpp b/dom/performance/PerformanceObserver.cpp
|
|
|
+--- a/dom/performance/PerformanceObserver.cpp
|
|
|
++++ b/dom/performance/PerformanceObserver.cpp
|
|
|
+@@ -5,27 +5,26 @@
|
|
|
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
+
|
|
|
+ #include "PerformanceObserver.h"
|
|
|
+
|
|
|
+ #include "mozilla/dom/Performance.h"
|
|
|
+ #include "mozilla/dom/PerformanceBinding.h"
|
|
|
+ #include "mozilla/dom/PerformanceEntryBinding.h"
|
|
|
+ #include "mozilla/dom/PerformanceObserverBinding.h"
|
|
|
++#include "mozilla/dom/WorkerPrivate.h"
|
|
|
++#include "mozilla/dom/WorkerScope.h"
|
|
|
+ #include "nsPIDOMWindow.h"
|
|
|
+ #include "nsQueryObject.h"
|
|
|
+ #include "nsString.h"
|
|
|
+ #include "PerformanceEntry.h"
|
|
|
+ #include "PerformanceObserverEntryList.h"
|
|
|
+-#include "WorkerPrivate.h"
|
|
|
+-#include "WorkerScope.h"
|
|
|
+
|
|
|
+ using namespace mozilla;
|
|
|
+ using namespace mozilla::dom;
|
|
|
+-using namespace mozilla::dom::workers;
|
|
|
+
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_CLASS(PerformanceObserver)
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(PerformanceObserver)
|
|
|
+ tmp->Disconnect();
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_UNLINK(mCallback)
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_UNLINK(mPerformance)
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner)
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
+diff --git a/dom/performance/PerformanceObserver.h b/dom/performance/PerformanceObserver.h
|
|
|
+--- a/dom/performance/PerformanceObserver.h
|
|
|
++++ b/dom/performance/PerformanceObserver.h
|
|
|
+@@ -22,36 +22,34 @@ class ErrorResult;
|
|
|
+
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+ class GlobalObject;
|
|
|
+ class Performance;
|
|
|
+ class PerformanceEntry;
|
|
|
+ class PerformanceObserverCallback;
|
|
|
+ struct PerformanceObserverInit;
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-} // namespace workers
|
|
|
+
|
|
|
+ class PerformanceObserver final : public nsISupports,
|
|
|
+ public nsWrapperCache
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
+ NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PerformanceObserver)
|
|
|
+
|
|
|
+ static already_AddRefed<PerformanceObserver>
|
|
|
+ Constructor(const GlobalObject& aGlobal,
|
|
|
+ PerformanceObserverCallback& aCb,
|
|
|
+ ErrorResult& aRv);
|
|
|
+
|
|
|
+ PerformanceObserver(nsPIDOMWindowInner* aOwner,
|
|
|
+ PerformanceObserverCallback& aCb);
|
|
|
+
|
|
|
+- PerformanceObserver(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ PerformanceObserver(WorkerPrivate* aWorkerPrivate,
|
|
|
+ PerformanceObserverCallback& aCb);
|
|
|
+
|
|
|
+ virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
+ JS::Handle<JSObject*> aGivenProto) override;
|
|
|
+
|
|
|
+ nsISupports* GetParentObject() const { return mOwner; }
|
|
|
+
|
|
|
+ void Observe(const PerformanceObserverInit& aOptions,
|
|
|
+diff --git a/dom/performance/PerformanceStorageWorker.cpp b/dom/performance/PerformanceStorageWorker.cpp
|
|
|
+--- a/dom/performance/PerformanceStorageWorker.cpp
|
|
|
++++ b/dom/performance/PerformanceStorageWorker.cpp
|
|
|
+@@ -1,23 +1,21 @@
|
|
|
+ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
+ /* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
+ /* 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/. */
|
|
|
+
|
|
|
+ #include "PerformanceStorageWorker.h"
|
|
|
+-#include "WorkerPrivate.h"
|
|
|
+-#include "WorkerHolder.h"
|
|
|
++#include "mozilla/dom/WorkerHolder.h"
|
|
|
++#include "mozilla/dom/WorkerPrivate.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ class PerformanceProxyData
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ PerformanceProxyData(UniquePtr<PerformanceTimingData>&& aData,
|
|
|
+ const nsAString& aInitiatorType,
|
|
|
+ const nsAString& aEntryName)
|
|
|
+ : mData(Move(aData))
|
|
|
+ , mInitiatorType(aInitiatorType)
|
|
|
+diff --git a/dom/performance/PerformanceStorageWorker.h b/dom/performance/PerformanceStorageWorker.h
|
|
|
+--- a/dom/performance/PerformanceStorageWorker.h
|
|
|
++++ b/dom/performance/PerformanceStorageWorker.h
|
|
|
+@@ -8,50 +8,47 @@
|
|
|
+ #define mozilla_dom_PerformanceStorageWorker_h
|
|
|
+
|
|
|
+ #include "PerformanceStorage.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+ class WorkerHolder;
|
|
|
+-
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+
|
|
|
+ class PerformanceProxyData;
|
|
|
+
|
|
|
+ class PerformanceStorageWorker final : public PerformanceStorage
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PerformanceStorageWorker, override)
|
|
|
+
|
|
|
+ static already_AddRefed<PerformanceStorageWorker>
|
|
|
+- Create(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ Create(WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ void InitializeOnWorker();
|
|
|
+
|
|
|
+ void ShutdownOnWorker();
|
|
|
+
|
|
|
+ void AddEntry(nsIHttpChannel* aChannel,
|
|
|
+ nsITimedChannel* aTimedChannel) override;
|
|
|
+
|
|
|
+ void AddEntryOnWorker(UniquePtr<PerformanceProxyData>&& aData);
|
|
|
+
|
|
|
+ private:
|
|
|
+- explicit PerformanceStorageWorker(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ explicit PerformanceStorageWorker(WorkerPrivate* aWorkerPrivate);
|
|
|
+ ~PerformanceStorageWorker();
|
|
|
+
|
|
|
+ Mutex mMutex;
|
|
|
+
|
|
|
+ // Protected by mutex.
|
|
|
+ // This raw pointer is nullified when the WorkerHolder communicates the
|
|
|
+ // shutting down of the worker thread.
|
|
|
+- workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ WorkerPrivate* mWorkerPrivate;
|
|
|
+
|
|
|
+ // Protected by mutex.
|
|
|
+ enum {
|
|
|
+ eInitializing,
|
|
|
+ eReady,
|
|
|
+ eTerminated,
|
|
|
+ } mState;
|
|
|
+
|
|
|
+diff --git a/dom/performance/PerformanceWorker.cpp b/dom/performance/PerformanceWorker.cpp
|
|
|
+--- a/dom/performance/PerformanceWorker.cpp
|
|
|
++++ b/dom/performance/PerformanceWorker.cpp
|
|
|
+@@ -1,23 +1,21 @@
|
|
|
+ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
+ /* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
+ /* 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/. */
|
|
|
+
|
|
|
+ #include "PerformanceWorker.h"
|
|
|
+ #include "mozilla/dom/DOMPrefs.h"
|
|
|
+-#include "WorkerPrivate.h"
|
|
|
++#include "mozilla/dom/WorkerPrivate.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ PerformanceWorker::PerformanceWorker(WorkerPrivate* aWorkerPrivate)
|
|
|
+ : mWorkerPrivate(aWorkerPrivate)
|
|
|
+ {
|
|
|
+ mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
+ }
|
|
|
+
|
|
|
+ PerformanceWorker::~PerformanceWorker()
|
|
|
+ {
|
|
|
+diff --git a/dom/performance/PerformanceWorker.h b/dom/performance/PerformanceWorker.h
|
|
|
+--- a/dom/performance/PerformanceWorker.h
|
|
|
++++ b/dom/performance/PerformanceWorker.h
|
|
|
+@@ -7,24 +7,22 @@
|
|
|
+ #ifndef mozilla_dom_PerformanceWorker_h
|
|
|
+ #define mozilla_dom_PerformanceWorker_h
|
|
|
+
|
|
|
+ #include "Performance.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+
|
|
|
+ class PerformanceWorker final : public Performance
|
|
|
+ {
|
|
|
+ public:
|
|
|
+- explicit PerformanceWorker(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ explicit PerformanceWorker(WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ PerformanceStorage* AsPerformanceStorage() override
|
|
|
+ {
|
|
|
+ MOZ_CRASH("This should not be called on workers.");
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+
|
|
|
+ virtual PerformanceTiming* Timing() override
|
|
|
+@@ -67,15 +65,15 @@ protected:
|
|
|
+ void InsertUserEntry(PerformanceEntry* aEntry) override;
|
|
|
+
|
|
|
+ void DispatchBufferFullEvent() override
|
|
|
+ {
|
|
|
+ // Nothing to do here. See bug 1432758.
|
|
|
+ }
|
|
|
+
|
|
|
+ private:
|
|
|
+- workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ WorkerPrivate* mWorkerPrivate;
|
|
|
+ };
|
|
|
+
|
|
|
+ } // namespace dom
|
|
|
+ } // namespace mozilla
|
|
|
+
|
|
|
+ #endif // mozilla_dom_PerformanceWorker_h
|
|
|
+diff --git a/dom/performance/moz.build b/dom/performance/moz.build
|
|
|
+--- a/dom/performance/moz.build
|
|
|
++++ b/dom/performance/moz.build
|
|
|
+@@ -35,15 +35,11 @@ UNIFIED_SOURCES += [
|
|
|
+ 'PerformanceObserverEntryList.cpp',
|
|
|
+ 'PerformanceResourceTiming.cpp',
|
|
|
+ 'PerformanceService.cpp',
|
|
|
+ 'PerformanceStorageWorker.cpp',
|
|
|
+ 'PerformanceTiming.cpp',
|
|
|
+ 'PerformanceWorker.cpp',
|
|
|
+ ]
|
|
|
+
|
|
|
+-LOCAL_INCLUDES += [
|
|
|
+- '/dom/workers',
|
|
|
+-]
|
|
|
+-
|
|
|
+ MOCHITEST_MANIFESTS += [ 'tests/mochitest.ini' ]
|
|
|
+
|
|
|
+ FINAL_LIBRARY = 'xul'
|
|
|
+diff --git a/dom/promise/Promise.cpp b/dom/promise/Promise.cpp
|
|
|
+--- a/dom/promise/Promise.cpp
|
|
|
++++ b/dom/promise/Promise.cpp
|
|
|
+@@ -40,18 +40,16 @@
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+ namespace {
|
|
|
+ // Generator used by Promise::GetID.
|
|
|
+ Atomic<uintptr_t> gIDGenerator(0);
|
|
|
+ } // namespace
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ // Promise
|
|
|
+
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_CLASS(Promise)
|
|
|
+
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Promise)
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal)
|
|
|
+ tmp->mPromiseObj = nullptr;
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
+diff --git a/dom/promise/PromiseDebugging.h b/dom/promise/PromiseDebugging.h
|
|
|
+--- a/dom/promise/PromiseDebugging.h
|
|
|
++++ b/dom/promise/PromiseDebugging.h
|
|
|
+@@ -11,25 +11,22 @@
|
|
|
+ #include "nsTArray.h"
|
|
|
+ #include "mozilla/RefPtr.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+
|
|
|
+ class ErrorResult;
|
|
|
+
|
|
|
+ namespace dom {
|
|
|
+-namespace workers {
|
|
|
+-class WorkerPrivate;
|
|
|
+-} // namespace workers
|
|
|
+-
|
|
|
+ class Promise;
|
|
|
+ struct PromiseDebuggingStateHolder;
|
|
|
+ class GlobalObject;
|
|
|
+ class UncaughtRejectionObserver;
|
|
|
+ class FlushRejections;
|
|
|
++class WorkerPrivate;
|
|
|
+
|
|
|
+ void TriggerFlushRejections();
|
|
|
+
|
|
|
+ class PromiseDebugging
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ static void Init();
|
|
|
+ static void Shutdown();
|
|
|
+@@ -65,17 +62,17 @@ public:
|
|
|
+ static void AddConsumedRejection(JS::HandleObject);
|
|
|
+ // Propagate the informations from AddUncaughtRejection
|
|
|
+ // and AddConsumedRejection to observers.
|
|
|
+ static void FlushUncaughtRejections();
|
|
|
+
|
|
|
+ protected:
|
|
|
+ static void FlushUncaughtRejectionsInternal();
|
|
|
+ friend class FlushRejections;
|
|
|
+- friend class mozilla::dom::workers::WorkerPrivate;
|
|
|
++ friend class mozilla::dom::WorkerPrivate;
|
|
|
+ private:
|
|
|
+ // Identity of the process.
|
|
|
+ // This property is:
|
|
|
+ // - set during initialization of the layout module,
|
|
|
+ // prior to any Worker using it;
|
|
|
+ // - read by both the main thread and the Workers;
|
|
|
+ // - unset during shutdown of the layout module,
|
|
|
+ // after any Worker has been shutdown.
|
|
|
+diff --git a/dom/promise/PromiseWorkerProxy.h b/dom/promise/PromiseWorkerProxy.h
|
|
|
+--- a/dom/promise/PromiseWorkerProxy.h
|
|
|
++++ b/dom/promise/PromiseWorkerProxy.h
|
|
|
+@@ -15,20 +15,17 @@
|
|
|
+ #include "nsProxyRelease.h"
|
|
|
+
|
|
|
+ #include "WorkerRunnable.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+ class Promise;
|
|
|
+-
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-} // namespace workers
|
|
|
+
|
|
|
+ // A proxy to (eventually) mirror a resolved/rejected Promise's result from the
|
|
|
+ // main thread to a Promise on the worker thread.
|
|
|
+ //
|
|
|
+ // How to use:
|
|
|
+ //
|
|
|
+ // 1. Create a Promise on the worker thread and return it to the content
|
|
|
+ // script:
|
|
|
+@@ -129,24 +126,24 @@ public:
|
|
|
+
|
|
|
+ struct PromiseWorkerProxyStructuredCloneCallbacks
|
|
|
+ {
|
|
|
+ ReadCallbackOp Read;
|
|
|
+ WriteCallbackOp Write;
|
|
|
+ };
|
|
|
+
|
|
|
+ static already_AddRefed<PromiseWorkerProxy>
|
|
|
+- Create(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ Create(WorkerPrivate* aWorkerPrivate,
|
|
|
+ Promise* aWorkerPromise,
|
|
|
+ const PromiseWorkerProxyStructuredCloneCallbacks* aCallbacks = nullptr);
|
|
|
+
|
|
|
+ // Main thread callers must hold Lock() and check CleanUp() before calling this.
|
|
|
+ // Worker thread callers, this will assert that the proxy has not been cleaned
|
|
|
+ // up.
|
|
|
+- workers::WorkerPrivate* GetWorkerPrivate() const;
|
|
|
++ WorkerPrivate* GetWorkerPrivate() const;
|
|
|
+
|
|
|
+ // This should only be used within WorkerRunnable::WorkerRun() running on the
|
|
|
+ // worker thread! Do not call this after calling CleanUp().
|
|
|
+ Promise* WorkerPromise() const;
|
|
|
+
|
|
|
+ // Worker thread only. Calling this invalidates several assumptions, so be
|
|
|
+ // sure this is the last thing you do.
|
|
|
+ // 1. WorkerPrivate() will no longer return a valid worker.
|
|
|
+@@ -178,17 +175,17 @@ public:
|
|
|
+ protected:
|
|
|
+ virtual void ResolvedCallback(JSContext* aCx,
|
|
|
+ JS::Handle<JS::Value> aValue) override;
|
|
|
+
|
|
|
+ virtual void RejectedCallback(JSContext* aCx,
|
|
|
+ JS::Handle<JS::Value> aValue) override;
|
|
|
+
|
|
|
+ private:
|
|
|
+- PromiseWorkerProxy(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ PromiseWorkerProxy(WorkerPrivate* aWorkerPrivate,
|
|
|
+ Promise* aWorkerPromise,
|
|
|
+ const PromiseWorkerProxyStructuredCloneCallbacks* aCallbacks = nullptr);
|
|
|
+
|
|
|
+ virtual ~PromiseWorkerProxy();
|
|
|
+
|
|
|
+ bool AddRefObject();
|
|
|
+
|
|
|
+ // If not called from Create(), be sure to hold Lock().
|
|
|
+@@ -198,17 +195,17 @@ private:
|
|
|
+ typedef void (Promise::*RunCallbackFunc)(JSContext*,
|
|
|
+ JS::Handle<JS::Value>);
|
|
|
+
|
|
|
+ void RunCallback(JSContext* aCx,
|
|
|
+ JS::Handle<JS::Value> aValue,
|
|
|
+ RunCallbackFunc aFunc);
|
|
|
+
|
|
|
+ // Any thread with appropriate checks.
|
|
|
+- workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ WorkerPrivate* mWorkerPrivate;
|
|
|
+
|
|
|
+ // Worker thread only.
|
|
|
+ RefPtr<Promise> mWorkerPromise;
|
|
|
+
|
|
|
+ // Modified on the worker thread.
|
|
|
+ // It is ok to *read* this without a lock on the worker.
|
|
|
+ // Main thread must always acquire a lock.
|
|
|
+ bool mCleanedUp; // To specify if the cleanUp() has been done.
|
|
|
+diff --git a/dom/push/PushManager.cpp b/dom/push/PushManager.cpp
|
|
|
+--- a/dom/push/PushManager.cpp
|
|
|
++++ b/dom/push/PushManager.cpp
|
|
|
+@@ -28,17 +28,17 @@
|
|
|
+
|
|
|
+ #include "WorkerRunnable.h"
|
|
|
+ #include "WorkerPrivate.h"
|
|
|
+ #include "WorkerScope.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
++using workers::AssertIsOnMainThread;
|
|
|
+
|
|
|
+ namespace {
|
|
|
+
|
|
|
+ nsresult
|
|
|
+ GetPermissionState(nsIPrincipal* aPrincipal,
|
|
|
+ PushPermissionState& aState)
|
|
|
+ {
|
|
|
+ nsCOMPtr<nsIPermissionManager> permManager =
|
|
|
+diff --git a/dom/push/PushManager.h b/dom/push/PushManager.h
|
|
|
+--- a/dom/push/PushManager.h
|
|
|
++++ b/dom/push/PushManager.h
|
|
|
+@@ -38,24 +38,21 @@
|
|
|
+ #include "mozilla/RefPtr.h"
|
|
|
+
|
|
|
+ class nsIGlobalObject;
|
|
|
+ class nsIPrincipal;
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+-class WorkerPrivate;
|
|
|
+-}
|
|
|
+-
|
|
|
+ class OwningArrayBufferViewOrArrayBufferOrString;
|
|
|
+ class Promise;
|
|
|
+ class PushManagerImpl;
|
|
|
+ struct PushSubscriptionOptionsInit;
|
|
|
++class WorkerPrivate;
|
|
|
+
|
|
|
+ class PushManager final : public nsISupports
|
|
|
+ , public nsWrapperCache
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
+ NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PushManager)
|
|
|
+
|
|
|
+diff --git a/dom/push/PushSubscription.cpp b/dom/push/PushSubscription.cpp
|
|
|
+--- a/dom/push/PushSubscription.cpp
|
|
|
++++ b/dom/push/PushSubscription.cpp
|
|
|
+@@ -18,18 +18,16 @@
|
|
|
+ #include "mozilla/dom/PushUtil.h"
|
|
|
+ #include "mozilla/dom/WorkerPrivate.h"
|
|
|
+ #include "mozilla/dom/WorkerScope.h"
|
|
|
+ #include "mozilla/dom/workers/WorkerCommon.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ namespace {
|
|
|
+
|
|
|
+ class UnsubscribeResultCallback final : public nsIUnsubscribeResultCallback
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ NS_DECL_ISUPPORTS
|
|
|
+
|
|
|
+ explicit UnsubscribeResultCallback(Promise* aPromise)
|
|
|
+diff --git a/dom/push/PushSubscription.h b/dom/push/PushSubscription.h
|
|
|
+--- a/dom/push/PushSubscription.h
|
|
|
++++ b/dom/push/PushSubscription.h
|
|
|
+@@ -21,20 +21,16 @@
|
|
|
+ #include "mozilla/dom/PushSubscriptionOptionsBinding.h"
|
|
|
+ #include "mozilla/dom/TypedArray.h"
|
|
|
+
|
|
|
+ class nsIGlobalObject;
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+-class WorkerPrivate;
|
|
|
+-}
|
|
|
+-
|
|
|
+ class Promise;
|
|
|
+
|
|
|
+ class PushSubscription final : public nsISupports
|
|
|
+ , public nsWrapperCache
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
+ NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PushSubscription)
|
|
|
+diff --git a/dom/script/ScriptSettings.cpp b/dom/script/ScriptSettings.cpp
|
|
|
+--- a/dom/script/ScriptSettings.cpp
|
|
|
++++ b/dom/script/ScriptSettings.cpp
|
|
|
+@@ -539,17 +539,17 @@ WarningOnlyErrorReporter(JSContext* aCx,
|
|
|
+ if (!NS_IsMainThread()) {
|
|
|
+ // Reporting a warning on workers is a bit complicated because we have to
|
|
|
+ // climb our parent chain until we get to the main thread. So go ahead and
|
|
|
+ // just go through the worker ReportError codepath here.
|
|
|
+ //
|
|
|
+ // That said, it feels like we should be able to short-circuit things a bit
|
|
|
+ // here by posting an appropriate runnable to the main thread directly...
|
|
|
+ // Worth looking into sometime.
|
|
|
+- workers::WorkerPrivate* worker = workers::GetWorkerPrivateFromContext(aCx);
|
|
|
++ WorkerPrivate* worker = GetWorkerPrivateFromContext(aCx);
|
|
|
+ MOZ_ASSERT(worker);
|
|
|
+
|
|
|
+ worker->ReportError(aCx, JS::ConstUTF8CharsZ(), aRep);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ RefPtr<xpc::ErrorReport> xpcReport = new xpc::ErrorReport();
|
|
|
+ nsGlobalWindow* win = xpc::CurrentWindowOrNull(aCx);
|
|
|
+@@ -576,17 +576,17 @@ AutoJSAPI::ReportException()
|
|
|
+ // requires us to be in a compartment when we fetch the pending exception.
|
|
|
+ // In this case, we enter the privileged junk scope and don't dispatch any
|
|
|
+ // error events.
|
|
|
+ JS::Rooted<JSObject*> errorGlobal(cx(), JS::CurrentGlobalOrNull(cx()));
|
|
|
+ if (!errorGlobal) {
|
|
|
+ if (mIsMainThread) {
|
|
|
+ errorGlobal = xpc::PrivilegedJunkScope();
|
|
|
+ } else {
|
|
|
+- errorGlobal = workers::GetCurrentThreadWorkerGlobal();
|
|
|
++ errorGlobal = GetCurrentThreadWorkerGlobal();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSAutoCompartment ac(cx(), errorGlobal);
|
|
|
+ JS::Rooted<JS::Value> exn(cx());
|
|
|
+ js::ErrorReport jsReport(cx());
|
|
|
+ if (StealException(&exn) &&
|
|
|
+ jsReport.init(cx(), exn, js::ErrorReport::WithSideEffects)) {
|
|
|
+ if (mIsMainThread) {
|
|
|
+@@ -612,17 +612,17 @@ AutoJSAPI::ReportException()
|
|
|
+ xpc::FindExceptionStackForConsoleReport(inner, exn));
|
|
|
+ xpcReport->LogToConsoleWithStack(stack);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // On a worker, we just use the worker error reporting mechanism and don't
|
|
|
+ // bother with xpc::ErrorReport. This will ensure that all the right
|
|
|
+ // events (which are a lot more complicated than in the window case) get
|
|
|
+ // fired.
|
|
|
+- workers::WorkerPrivate* worker = workers::GetCurrentThreadWorkerPrivate();
|
|
|
++ WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
|
|
|
+ MOZ_ASSERT(worker);
|
|
|
+ MOZ_ASSERT(worker->GetJSContext() == cx());
|
|
|
+ // Before invoking ReportError, put the exception back on the context,
|
|
|
+ // because it may want to put it in its error events and has no other way
|
|
|
+ // to get hold of it. After we invoke ReportError, clear the exception on
|
|
|
+ // cx(), just in case ReportError didn't.
|
|
|
+ JS_SetPendingException(cx(), exn);
|
|
|
+ worker->ReportError(cx(), jsReport.toStringResult(), jsReport.report());
|
|
|
+diff --git a/dom/serviceworkers/ServiceWorkerPrivate.h b/dom/serviceworkers/ServiceWorkerPrivate.h
|
|
|
+--- a/dom/serviceworkers/ServiceWorkerPrivate.h
|
|
|
++++ b/dom/serviceworkers/ServiceWorkerPrivate.h
|
|
|
+@@ -206,17 +206,17 @@ private:
|
|
|
+ // The info object owns us. It is possible to outlive it for a brief period
|
|
|
+ // of time if there are pending waitUntil promises, in which case it
|
|
|
+ // will be null and |SpawnWorkerIfNeeded| will always fail.
|
|
|
+ ServiceWorkerInfo* MOZ_NON_OWNING_REF mInfo;
|
|
|
+
|
|
|
+ // The WorkerPrivate object can only be closed by this class or by the
|
|
|
+ // RuntimeService class if gecko is shutting down. Closing the worker
|
|
|
+ // multiple times is OK, since the second attempt will be a no-op.
|
|
|
+- RefPtr<workers::WorkerPrivate> mWorkerPrivate;
|
|
|
++ RefPtr<WorkerPrivate> mWorkerPrivate;
|
|
|
+
|
|
|
+ nsCOMPtr<nsITimer> mIdleWorkerTimer;
|
|
|
+
|
|
|
+ // We keep a token for |dom.serviceWorkers.idle_timeout| seconds to give the
|
|
|
+ // worker a grace period after each event.
|
|
|
+ RefPtr<KeepAliveToken> mIdleKeepAliveToken;
|
|
|
+
|
|
|
+ uint64_t mDebuggerCount;
|
|
|
+diff --git a/dom/serviceworkers/ServiceWorkerRegistration.h b/dom/serviceworkers/ServiceWorkerRegistration.h
|
|
|
+--- a/dom/serviceworkers/ServiceWorkerRegistration.h
|
|
|
++++ b/dom/serviceworkers/ServiceWorkerRegistration.h
|
|
|
+@@ -56,17 +56,17 @@ public:
|
|
|
+
|
|
|
+ IMPL_EVENT_HANDLER(updatefound)
|
|
|
+
|
|
|
+ static already_AddRefed<ServiceWorkerRegistration>
|
|
|
+ CreateForMainThread(nsPIDOMWindowInner* aWindow,
|
|
|
+ const nsAString& aScope);
|
|
|
+
|
|
|
+ static already_AddRefed<ServiceWorkerRegistration>
|
|
|
+- CreateForWorker(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ CreateForWorker(WorkerPrivate* aWorkerPrivate,
|
|
|
+ const nsAString& aScope);
|
|
|
+
|
|
|
+ JSObject*
|
|
|
+ WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
|
|
+
|
|
|
+ virtual already_AddRefed<ServiceWorker>
|
|
|
+ GetInstalling() = 0;
|
|
|
+
|
|
|
+diff --git a/dom/url/URLWorker.cpp b/dom/url/URLWorker.cpp
|
|
|
+--- a/dom/url/URLWorker.cpp
|
|
|
++++ b/dom/url/URLWorker.cpp
|
|
|
+@@ -15,17 +15,17 @@
|
|
|
+ #include "nsURLHelper.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+
|
|
|
+ using net::nsStandardURL;
|
|
|
+
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
++using workers::AssertIsOnMainThread;
|
|
|
+
|
|
|
+ // Proxy class to forward all the requests to a URLMainThread object.
|
|
|
+ class URLWorker::URLProxy final
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ NS_INLINE_DECL_THREADSAFE_REFCOUNTING(URLProxy)
|
|
|
+
|
|
|
+ explicit URLProxy(already_AddRefed<URLMainThread> aURL)
|
|
|
+diff --git a/dom/url/URLWorker.h b/dom/url/URLWorker.h
|
|
|
+--- a/dom/url/URLWorker.h
|
|
|
++++ b/dom/url/URLWorker.h
|
|
|
+@@ -13,19 +13,17 @@
|
|
|
+ namespace mozilla {
|
|
|
+
|
|
|
+ namespace net {
|
|
|
+ class nsStandardURL;
|
|
|
+ }
|
|
|
+
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+
|
|
|
+ // URLWorker implements the URL object in workers.
|
|
|
+ class URLWorker final : public URL
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ class URLProxy;
|
|
|
+
|
|
|
+ static already_AddRefed<URLWorker>
|
|
|
+@@ -43,17 +41,17 @@ public:
|
|
|
+ static void
|
|
|
+ RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aUrl,
|
|
|
+ ErrorResult& aRv);
|
|
|
+
|
|
|
+ static bool
|
|
|
+ IsValidURL(const GlobalObject& aGlobal, const nsAString& aUrl,
|
|
|
+ ErrorResult& aRv);
|
|
|
+
|
|
|
+- explicit URLWorker(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ explicit URLWorker(WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ void
|
|
|
+ Init(const nsAString& aURL, const Optional<nsAString>& aBase,
|
|
|
+ ErrorResult& aRv);
|
|
|
+
|
|
|
+ virtual void
|
|
|
+ GetHref(nsAString& aHref, ErrorResult& aRv) const override;
|
|
|
+
|
|
|
+@@ -117,17 +115,17 @@ public:
|
|
|
+ virtual void UpdateURLSearchParams() override;
|
|
|
+
|
|
|
+ virtual void
|
|
|
+ SetSearchInternal(const nsAString& aSearch, ErrorResult& aRv) override;
|
|
|
+
|
|
|
+ private:
|
|
|
+ ~URLWorker();
|
|
|
+
|
|
|
+- workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ WorkerPrivate* mWorkerPrivate;
|
|
|
+ RefPtr<URLProxy> mURLProxy;
|
|
|
+ RefPtr<net::nsStandardURL> mStdURL;
|
|
|
+ };
|
|
|
+
|
|
|
+ } // namespace dom
|
|
|
+ } // namespace mozilla
|
|
|
+
|
|
|
+ #endif // mozilla_dom_URLWorker_h
|
|
|
+diff --git a/dom/webidl/Worker.webidl b/dom/webidl/Worker.webidl
|
|
|
+--- a/dom/webidl/Worker.webidl
|
|
|
++++ b/dom/webidl/Worker.webidl
|
|
|
+@@ -8,17 +8,17 @@
|
|
|
+ *
|
|
|
+ * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and Opera
|
|
|
+ * Software ASA.
|
|
|
+ * You are granted a license to use, reproduce and create derivative works of
|
|
|
+ * this document.
|
|
|
+ */
|
|
|
+
|
|
|
+ [Constructor(USVString scriptURL, optional WorkerOptions options),
|
|
|
+- Func="mozilla::dom::workers::WorkerPrivate::WorkerAvailable",
|
|
|
++ Func="mozilla::dom::WorkerPrivate::WorkerAvailable",
|
|
|
+ Exposed=(Window,DedicatedWorker,SharedWorker,System)]
|
|
|
+ interface Worker : EventTarget {
|
|
|
+ void terminate();
|
|
|
+
|
|
|
+ [Throws]
|
|
|
+ void postMessage(any message, optional sequence<object> transfer = []);
|
|
|
+
|
|
|
+ attribute EventHandler onmessage;
|
|
|
+@@ -29,12 +29,12 @@ Worker implements AbstractWorker;
|
|
|
+
|
|
|
+ dictionary WorkerOptions {
|
|
|
+ // WorkerType type = "classic"; TODO: Bug 1247687
|
|
|
+ // RequestCredentials credentials = "omit"; // credentials is only used if type is "module" TODO: Bug 1247687
|
|
|
+ DOMString name = "";
|
|
|
+ };
|
|
|
+
|
|
|
+ [Constructor(USVString scriptURL),
|
|
|
+- Func="mozilla::dom::workers::ChromeWorkerPrivate::WorkerAvailable",
|
|
|
++ Func="mozilla::dom::ChromeWorkerPrivate::WorkerAvailable",
|
|
|
+ Exposed=(Window,DedicatedWorker,SharedWorker,System)]
|
|
|
+ interface ChromeWorker : Worker {
|
|
|
+ };
|
|
|
+diff --git a/dom/workers/MessageEventRunnable.cpp b/dom/workers/MessageEventRunnable.cpp
|
|
|
+--- a/dom/workers/MessageEventRunnable.cpp
|
|
|
++++ b/dom/workers/MessageEventRunnable.cpp
|
|
|
+@@ -12,18 +12,16 @@
|
|
|
+ #include "mozilla/WorkerTimelineMarker.h"
|
|
|
+ #include "nsQueryObject.h"
|
|
|
+ #include "WorkerPrivate.h"
|
|
|
+ #include "WorkerScope.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ MessageEventRunnable::MessageEventRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
+ TargetAndBusyBehavior aBehavior)
|
|
|
+ : WorkerRunnable(aWorkerPrivate, aBehavior)
|
|
|
+ , StructuredCloneHolder(CloningSupported, TransferringSupported,
|
|
|
+ StructuredCloneScope::SameProcessDifferentThread)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+diff --git a/dom/workers/MessageEventRunnable.h b/dom/workers/MessageEventRunnable.h
|
|
|
+--- a/dom/workers/MessageEventRunnable.h
|
|
|
++++ b/dom/workers/MessageEventRunnable.h
|
|
|
+@@ -16,26 +16,26 @@ namespace mozilla {
|
|
|
+ class DOMEventTargetHelper;
|
|
|
+
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+ class MessageEventRunnable final : public WorkerRunnable
|
|
|
+ , public StructuredCloneHolder
|
|
|
+ {
|
|
|
+ public:
|
|
|
+- MessageEventRunnable(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ MessageEventRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
+ TargetAndBusyBehavior aBehavior);
|
|
|
+
|
|
|
+ bool
|
|
|
+- DispatchDOMEvent(JSContext* aCx, workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ DispatchDOMEvent(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
|
|
|
+ DOMEventTargetHelper* aTarget, bool aIsMainThread);
|
|
|
+
|
|
|
+ private:
|
|
|
+ bool
|
|
|
+- WorkerRun(JSContext* aCx, workers::WorkerPrivate* aWorkerPrivate) override;
|
|
|
++ WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override;
|
|
|
+
|
|
|
+ void
|
|
|
+ DispatchError(JSContext* aCx, DOMEventTargetHelper* aTarget);
|
|
|
+ };
|
|
|
+
|
|
|
+ } // dom namespace
|
|
|
+ } // mozilla namespace
|
|
|
+
|
|
|
+diff --git a/dom/workers/Principal.cpp b/dom/workers/Principal.cpp
|
|
|
+--- a/dom/workers/Principal.cpp
|
|
|
++++ b/dom/workers/Principal.cpp
|
|
|
+@@ -31,17 +31,17 @@ GetWorkerPrincipal()
|
|
|
+ * the first time, decrement it again. This avoids the need for
|
|
|
+ * synchronization.
|
|
|
+ */
|
|
|
+ int32_t prevRefcount = sPrincipal.refcount++;
|
|
|
+ if (prevRefcount > 0) {
|
|
|
+ --sPrincipal.refcount;
|
|
|
+ } else {
|
|
|
+ #ifdef DEBUG
|
|
|
+- sPrincipal.debugToken = kJSPrincipalsDebugToken;
|
|
|
++ sPrincipal.debugToken = workers::kJSPrincipalsDebugToken;
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+
|
|
|
+ return &sPrincipal;
|
|
|
+ }
|
|
|
+
|
|
|
+ void
|
|
|
+ DestroyWorkerPrincipals(JSPrincipals* aPrincipals)
|
|
|
+diff --git a/dom/workers/Queue.h b/dom/workers/Queue.h
|
|
|
+--- a/dom/workers/Queue.h
|
|
|
++++ b/dom/workers/Queue.h
|
|
|
+@@ -2,17 +2,17 @@
|
|
|
+ /* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
+ /* 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/. */
|
|
|
+
|
|
|
+ #ifndef mozilla_dom_workers_queue_h__
|
|
|
+ #define mozilla_dom_workers_queue_h__
|
|
|
+
|
|
|
+-#include "WorkerCommon.h"
|
|
|
++#include "mozilla/dom/workers/WorkerCommon.h"
|
|
|
+
|
|
|
+ #include "mozilla/Mutex.h"
|
|
|
+ #include "nsTArray.h"
|
|
|
+
|
|
|
+ BEGIN_WORKERS_NAMESPACE
|
|
|
+
|
|
|
+ template <typename T, int TCount>
|
|
|
+ struct StorageWithTArray
|
|
|
+diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp
|
|
|
+--- a/dom/workers/RuntimeService.cpp
|
|
|
++++ b/dom/workers/RuntimeService.cpp
|
|
|
+@@ -1308,16 +1308,21 @@ ResumeWorkersForWindow(nsPIDOMWindowInne
|
|
|
+ {
|
|
|
+ AssertIsOnMainThread();
|
|
|
+ RuntimeService* runtime = RuntimeService::GetService();
|
|
|
+ if (runtime) {
|
|
|
+ runtime->ResumeWorkersForWindow(aWindow);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
++END_WORKERS_NAMESPACE
|
|
|
++
|
|
|
++namespace mozilla {
|
|
|
++namespace dom {
|
|
|
++
|
|
|
+ WorkerPrivate*
|
|
|
+ GetWorkerPrivateFromContext(JSContext* aCx)
|
|
|
+ {
|
|
|
+ MOZ_ASSERT(!NS_IsMainThread());
|
|
|
+ MOZ_ASSERT(aCx);
|
|
|
+
|
|
|
+ void* cxPrivate = JS_GetContextPrivate(aCx);
|
|
|
+ if (!cxPrivate) {
|
|
|
+@@ -1373,17 +1378,18 @@ GetCurrentThreadWorkerGlobal()
|
|
|
+ }
|
|
|
+ WorkerGlobalScope* scope = wp->GlobalScope();
|
|
|
+ if (!scope) {
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+ return scope->GetGlobalJSObject();
|
|
|
+ }
|
|
|
+
|
|
|
+-END_WORKERS_NAMESPACE
|
|
|
++} // dom namespace
|
|
|
++} // mozilla namespace
|
|
|
+
|
|
|
+ struct RuntimeService::IdleThreadInfo
|
|
|
+ {
|
|
|
+ RefPtr<WorkerThread> mThread;
|
|
|
+ mozilla::TimeStamp mExpirationTime;
|
|
|
+ };
|
|
|
+
|
|
|
+ // This is only touched on the main thread. Initialized in Init() below.
|
|
|
+diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp
|
|
|
+--- a/dom/workers/ScriptLoader.cpp
|
|
|
++++ b/dom/workers/ScriptLoader.cpp
|
|
|
+@@ -77,18 +77,16 @@ USING_WORKERS_NAMESPACE
|
|
|
+
|
|
|
+ using mozilla::dom::cache::Cache;
|
|
|
+ using mozilla::dom::cache::CacheStorage;
|
|
|
+ using mozilla::ipc::PrincipalInfo;
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ namespace {
|
|
|
+
|
|
|
+ nsIURI*
|
|
|
+ GetBaseURI(bool aIsMainScript, WorkerPrivate* aWorkerPrivate)
|
|
|
+ {
|
|
|
+ MOZ_ASSERT(aWorkerPrivate);
|
|
|
+ nsIURI* baseURI;
|
|
|
+ WorkerPrivate* parentWorker = aWorkerPrivate->GetParent();
|
|
|
+diff --git a/dom/workers/ScriptLoader.h b/dom/workers/ScriptLoader.h
|
|
|
+--- a/dom/workers/ScriptLoader.h
|
|
|
++++ b/dom/workers/ScriptLoader.h
|
|
|
+@@ -18,21 +18,18 @@ class nsILoadGroup;
|
|
|
+ class nsIChannel;
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+
|
|
|
+ class ErrorResult;
|
|
|
+
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
++struct WorkerLoadInfo;
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+-
|
|
|
+-struct WorkerLoadInfo;
|
|
|
+
|
|
|
+ enum WorkerScriptType {
|
|
|
+ WorkerScript,
|
|
|
+ DebuggerScript
|
|
|
+ };
|
|
|
+
|
|
|
+ namespace workerinternals {
|
|
|
+
|
|
|
+@@ -44,29 +41,29 @@ ChannelFromScriptURLMainThread(nsIPrinci
|
|
|
+ const nsAString& aScriptURL,
|
|
|
+ const Maybe<ClientInfo>& aClientInfo,
|
|
|
+ nsContentPolicyType aContentPolicyType,
|
|
|
+ bool aDefaultURIEncoding,
|
|
|
+ nsIChannel** aChannel);
|
|
|
+
|
|
|
+ nsresult
|
|
|
+ ChannelFromScriptURLWorkerThread(JSContext* aCx,
|
|
|
+- workers::WorkerPrivate* aParent,
|
|
|
++ WorkerPrivate* aParent,
|
|
|
+ const nsAString& aScriptURL,
|
|
|
+ WorkerLoadInfo& aLoadInfo);
|
|
|
+
|
|
|
+ void ReportLoadError(ErrorResult& aRv, nsresult aLoadResult,
|
|
|
+ const nsAString& aScriptURL);
|
|
|
+
|
|
|
+-void LoadMainScript(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++void LoadMainScript(WorkerPrivate* aWorkerPrivate,
|
|
|
+ const nsAString& aScriptURL,
|
|
|
+ WorkerScriptType aWorkerScriptType,
|
|
|
+ ErrorResult& aRv);
|
|
|
+
|
|
|
+-void Load(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++void Load(WorkerPrivate* aWorkerPrivate,
|
|
|
+ const nsTArray<nsString>& aScriptURLs,
|
|
|
+ WorkerScriptType aWorkerScriptType,
|
|
|
+ ErrorResult& aRv);
|
|
|
+
|
|
|
+ } // namespace workerinternals
|
|
|
+
|
|
|
+ } // dom namespace
|
|
|
+ } // namespace mozilla
|
|
|
+diff --git a/dom/workers/SharedWorker.cpp b/dom/workers/SharedWorker.cpp
|
|
|
+--- a/dom/workers/SharedWorker.cpp
|
|
|
++++ b/dom/workers/SharedWorker.cpp
|
|
|
+@@ -25,17 +25,16 @@
|
|
|
+ #undef PostMessage
|
|
|
+ #endif
|
|
|
+
|
|
|
+ using mozilla::dom::Optional;
|
|
|
+ using mozilla::dom::Sequence;
|
|
|
+ using mozilla::dom::MessagePort;
|
|
|
+ using namespace mozilla;
|
|
|
+ using namespace mozilla::dom;
|
|
|
+-using namespace mozilla::dom::workers;
|
|
|
+
|
|
|
+ SharedWorker::SharedWorker(nsPIDOMWindowInner* aWindow,
|
|
|
+ WorkerPrivate* aWorkerPrivate,
|
|
|
+ MessagePort* aMessagePort)
|
|
|
+ : DOMEventTargetHelper(aWindow)
|
|
|
+ , mWorkerPrivate(aWorkerPrivate)
|
|
|
+ , mMessagePort(aMessagePort)
|
|
|
+ , mFrozen(false)
|
|
|
+diff --git a/dom/workers/SharedWorker.h b/dom/workers/SharedWorker.h
|
|
|
+--- a/dom/workers/SharedWorker.h
|
|
|
++++ b/dom/workers/SharedWorker.h
|
|
|
+@@ -20,30 +20,30 @@ class nsIDOMEvent;
|
|
|
+ class nsPIDOMWindowInner;
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ class EventChainPreVisitor;
|
|
|
+
|
|
|
+ namespace dom {
|
|
|
+ class MessagePort;
|
|
|
+ class StringOrWorkerOptions;
|
|
|
++class WorkerPrivate;
|
|
|
+
|
|
|
+ namespace workers {
|
|
|
+ class RuntimeService;
|
|
|
+-class WorkerPrivate;
|
|
|
+ }
|
|
|
+
|
|
|
+ class SharedWorker final : public DOMEventTargetHelper
|
|
|
+ {
|
|
|
+ friend class workers::RuntimeService;
|
|
|
+
|
|
|
+ typedef mozilla::ErrorResult ErrorResult;
|
|
|
+ typedef mozilla::dom::GlobalObject GlobalObject;
|
|
|
+
|
|
|
+- RefPtr<workers::WorkerPrivate> mWorkerPrivate;
|
|
|
++ RefPtr<WorkerPrivate> mWorkerPrivate;
|
|
|
+ RefPtr<MessagePort> mMessagePort;
|
|
|
+ nsTArray<nsCOMPtr<nsIDOMEvent>> mFrozenEvents;
|
|
|
+ bool mFrozen;
|
|
|
+
|
|
|
+ public:
|
|
|
+ static already_AddRefed<SharedWorker>
|
|
|
+ Constructor(const GlobalObject& aGlobal, const nsAString& aScriptURL,
|
|
|
+ const StringOrWorkerOptions& aOptions, ErrorResult& aRv);
|
|
|
+@@ -75,26 +75,26 @@ public:
|
|
|
+ IMPL_EVENT_HANDLER(error)
|
|
|
+
|
|
|
+ virtual JSObject*
|
|
|
+ WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
|
|
+
|
|
|
+ virtual nsresult
|
|
|
+ GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
|
|
|
+
|
|
|
+- workers::WorkerPrivate*
|
|
|
++ WorkerPrivate*
|
|
|
+ GetWorkerPrivate() const
|
|
|
+ {
|
|
|
+ return mWorkerPrivate;
|
|
|
+ }
|
|
|
+
|
|
|
+ private:
|
|
|
+ // This class can only be created from the RuntimeService.
|
|
|
+ SharedWorker(nsPIDOMWindowInner* aWindow,
|
|
|
+- workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ WorkerPrivate* aWorkerPrivate,
|
|
|
+ MessagePort* aMessagePort);
|
|
|
+
|
|
|
+ // This class is reference-counted and will be destroyed from Release().
|
|
|
+ ~SharedWorker();
|
|
|
+
|
|
|
+ // Only called by MessagePort.
|
|
|
+ void
|
|
|
+ PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
|
|
|
+diff --git a/dom/workers/WorkerCommon.h b/dom/workers/WorkerCommon.h
|
|
|
+--- a/dom/workers/WorkerCommon.h
|
|
|
++++ b/dom/workers/WorkerCommon.h
|
|
|
+@@ -35,23 +35,23 @@ namespace dom {
|
|
|
+ // be updated too.
|
|
|
+ enum WorkerType
|
|
|
+ {
|
|
|
+ WorkerTypeDedicated,
|
|
|
+ WorkerTypeShared,
|
|
|
+ WorkerTypeService
|
|
|
+ };
|
|
|
+
|
|
|
++class WorkerPrivate;
|
|
|
++
|
|
|
+ } // namespace dom
|
|
|
+ } // namespace mozilla
|
|
|
+
|
|
|
+ BEGIN_WORKERS_NAMESPACE
|
|
|
+
|
|
|
+-class WorkerPrivate;
|
|
|
+-
|
|
|
+ struct PrivatizableBase
|
|
|
+ { };
|
|
|
+
|
|
|
+ #ifdef DEBUG
|
|
|
+ void
|
|
|
+ AssertIsOnMainThread();
|
|
|
+ #else
|
|
|
+ inline void
|
|
|
+diff --git a/dom/workers/WorkerDebugger.cpp b/dom/workers/WorkerDebugger.cpp
|
|
|
+--- a/dom/workers/WorkerDebugger.cpp
|
|
|
++++ b/dom/workers/WorkerDebugger.cpp
|
|
|
+@@ -16,18 +16,16 @@
|
|
|
+ #include "WorkerError.h"
|
|
|
+ #include "WorkerPrivate.h"
|
|
|
+ #include "WorkerRunnable.h"
|
|
|
+ #include "WorkerScope.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ namespace {
|
|
|
+
|
|
|
+ class DebuggerMessageEventRunnable : public WorkerDebuggerRunnable
|
|
|
+ {
|
|
|
+ nsString mMessage;
|
|
|
+
|
|
|
+ public:
|
|
|
+ DebuggerMessageEventRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
+diff --git a/dom/workers/WorkerDebugger.h b/dom/workers/WorkerDebugger.h
|
|
|
+--- a/dom/workers/WorkerDebugger.h
|
|
|
++++ b/dom/workers/WorkerDebugger.h
|
|
|
+@@ -8,31 +8,29 @@
|
|
|
+ #define mozilla_dom_workers_WorkerDebugger_h
|
|
|
+
|
|
|
+ #include "mozilla/dom/workers/WorkerCommon.h"
|
|
|
+ #include "nsIWorkerDebugger.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+
|
|
|
+ class WorkerDebugger : public nsIWorkerDebugger
|
|
|
+ {
|
|
|
+ class ReportDebuggerErrorRunnable;
|
|
|
+ class PostDebuggerMessageRunnable;
|
|
|
+
|
|
|
+- workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ WorkerPrivate* mWorkerPrivate;
|
|
|
+ bool mIsInitialized;
|
|
|
+ nsTArray<nsCOMPtr<nsIWorkerDebuggerListener>> mListeners;
|
|
|
+
|
|
|
+ public:
|
|
|
+- explicit WorkerDebugger(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ explicit WorkerDebugger(WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ NS_DECL_ISUPPORTS
|
|
|
+ NS_DECL_NSIWORKERDEBUGGER
|
|
|
+
|
|
|
+ void
|
|
|
+ AssertIsOnParentThread();
|
|
|
+
|
|
|
+ void
|
|
|
+diff --git a/dom/workers/WorkerDebuggerManager.cpp b/dom/workers/WorkerDebuggerManager.cpp
|
|
|
+--- a/dom/workers/WorkerDebuggerManager.cpp
|
|
|
++++ b/dom/workers/WorkerDebuggerManager.cpp
|
|
|
+@@ -12,18 +12,16 @@
|
|
|
+ #include "mozilla/StaticPtr.h"
|
|
|
+
|
|
|
+ #include "WorkerDebugger.h"
|
|
|
+ #include "WorkerPrivate.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ namespace {
|
|
|
+
|
|
|
+ class RegisterDebuggerMainThreadRunnable final : public mozilla::Runnable
|
|
|
+ {
|
|
|
+ WorkerPrivate* mWorkerPrivate;
|
|
|
+ bool mNotifyListeners;
|
|
|
+
|
|
|
+ public:
|
|
|
+diff --git a/dom/workers/WorkerDebuggerManager.h b/dom/workers/WorkerDebuggerManager.h
|
|
|
+--- a/dom/workers/WorkerDebuggerManager.h
|
|
|
++++ b/dom/workers/WorkerDebuggerManager.h
|
|
|
+@@ -20,21 +20,18 @@
|
|
|
+ { 0x62ec8731, 0x55ad, 0x4246, \
|
|
|
+ { 0xb2, 0xea, 0xf2, 0x6c, 0x1f, 0xe1, 0x9d, 0x2d } }
|
|
|
+ #define WORKERDEBUGGERMANAGER_CONTRACTID \
|
|
|
+ "@mozilla.org/dom/workers/workerdebuggermanager;1"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
++class WorkerDebugger;
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+-
|
|
|
+-class WorkerDebugger;
|
|
|
+
|
|
|
+ class WorkerDebuggerManager final : public nsIObserver,
|
|
|
+ public nsIWorkerDebuggerManager
|
|
|
+ {
|
|
|
+ Mutex mMutex;
|
|
|
+
|
|
|
+ // Protected by mMutex.
|
|
|
+ nsTArray<nsCOMPtr<nsIWorkerDebuggerManagerListener>> mListeners;
|
|
|
+@@ -60,34 +57,34 @@ public:
|
|
|
+
|
|
|
+ nsresult
|
|
|
+ Init();
|
|
|
+
|
|
|
+ void
|
|
|
+ Shutdown();
|
|
|
+
|
|
|
+ void
|
|
|
+- RegisterDebugger(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ RegisterDebugger(WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ void
|
|
|
+- RegisterDebuggerMainThread(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ RegisterDebuggerMainThread(WorkerPrivate* aWorkerPrivate,
|
|
|
+ bool aNotifyListeners);
|
|
|
+
|
|
|
+ void
|
|
|
+- UnregisterDebugger(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ UnregisterDebugger(WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ void
|
|
|
+- UnregisterDebuggerMainThread(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ UnregisterDebuggerMainThread(WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ private:
|
|
|
+ virtual ~WorkerDebuggerManager();
|
|
|
+ };
|
|
|
+
|
|
|
+ inline nsresult
|
|
|
+-RegisterWorkerDebugger(workers::WorkerPrivate* aWorkerPrivate)
|
|
|
++RegisterWorkerDebugger(WorkerPrivate* aWorkerPrivate)
|
|
|
+ {
|
|
|
+ WorkerDebuggerManager* manager;
|
|
|
+
|
|
|
+ if (NS_IsMainThread()) {
|
|
|
+ manager = WorkerDebuggerManager::GetOrCreate();
|
|
|
+ if (!manager) {
|
|
|
+ NS_WARNING("Failed to create worker debugger manager!");
|
|
|
+ return NS_ERROR_FAILURE;
|
|
|
+@@ -97,17 +94,17 @@ RegisterWorkerDebugger(workers::WorkerPr
|
|
|
+ manager = WorkerDebuggerManager::Get();
|
|
|
+ }
|
|
|
+
|
|
|
+ manager->RegisterDebugger(aWorkerPrivate);
|
|
|
+ return NS_OK;
|
|
|
+ }
|
|
|
+
|
|
|
+ inline nsresult
|
|
|
+-UnregisterWorkerDebugger(workers::WorkerPrivate* aWorkerPrivate)
|
|
|
++UnregisterWorkerDebugger(WorkerPrivate* aWorkerPrivate)
|
|
|
+ {
|
|
|
+ WorkerDebuggerManager* manager;
|
|
|
+
|
|
|
+ if (NS_IsMainThread()) {
|
|
|
+ manager = WorkerDebuggerManager::GetOrCreate();
|
|
|
+ if (!manager) {
|
|
|
+ NS_WARNING("Failed to create worker debugger manager!");
|
|
|
+ return NS_ERROR_FAILURE;
|
|
|
+diff --git a/dom/workers/WorkerError.cpp b/dom/workers/WorkerError.cpp
|
|
|
+--- a/dom/workers/WorkerError.cpp
|
|
|
++++ b/dom/workers/WorkerError.cpp
|
|
|
+@@ -18,18 +18,16 @@
|
|
|
+ #include "nsScriptError.h"
|
|
|
+ #include "WorkerRunnable.h"
|
|
|
+ #include "WorkerPrivate.h"
|
|
|
+ #include "WorkerScope.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ namespace {
|
|
|
+
|
|
|
+ class ReportErrorRunnable final : public WorkerRunnable
|
|
|
+ {
|
|
|
+ WorkerErrorReport mReport;
|
|
|
+
|
|
|
+ public:
|
|
|
+ // aWorkerPrivate is the worker thread we're on (or the main thread, if null)
|
|
|
+diff --git a/dom/workers/WorkerError.h b/dom/workers/WorkerError.h
|
|
|
+--- a/dom/workers/WorkerError.h
|
|
|
++++ b/dom/workers/WorkerError.h
|
|
|
+@@ -35,19 +35,17 @@ public:
|
|
|
+ };
|
|
|
+
|
|
|
+ class WorkerErrorNote : public WorkerErrorBase
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ void AssignErrorNote(JSErrorNotes::Note* aNote);
|
|
|
+ };
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+
|
|
|
+ class WorkerErrorReport : public WorkerErrorBase
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ nsString mLine;
|
|
|
+ uint32_t mFlags;
|
|
|
+ JSExnType mExnType;
|
|
|
+ bool mMutedError;
|
|
|
+@@ -60,17 +58,17 @@ public:
|
|
|
+ { }
|
|
|
+
|
|
|
+ void AssignErrorReport(JSErrorReport* aReport);
|
|
|
+
|
|
|
+ // aWorkerPrivate is the worker thread we're on (or the main thread, if null)
|
|
|
+ // aTarget is the worker object that we are going to fire an error at
|
|
|
+ // (if any).
|
|
|
+ static void
|
|
|
+- ReportError(JSContext* aCx, workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ ReportError(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
|
|
|
+ bool aFireAtScope, DOMEventTargetHelper* aTarget,
|
|
|
+ const WorkerErrorReport& aReport, uint64_t aInnerWindowId,
|
|
|
+ JS::Handle<JS::Value> aException = JS::NullHandleValue);
|
|
|
+
|
|
|
+ static void
|
|
|
+ LogErrorToConsole(const WorkerErrorReport& aReport, uint64_t aInnerWindowId);
|
|
|
+
|
|
|
+ };
|
|
|
+diff --git a/dom/workers/WorkerEventTarget.cpp b/dom/workers/WorkerEventTarget.cpp
|
|
|
+--- a/dom/workers/WorkerEventTarget.cpp
|
|
|
++++ b/dom/workers/WorkerEventTarget.cpp
|
|
|
+@@ -4,18 +4,16 @@
|
|
|
+ * 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/. */
|
|
|
+
|
|
|
+ #include "WorkerEventTarget.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ namespace {
|
|
|
+
|
|
|
+ class WrappedControlRunnable final : public WorkerControlRunnable
|
|
|
+ {
|
|
|
+ nsCOMPtr<nsIRunnable> mInner;
|
|
|
+
|
|
|
+ ~WrappedControlRunnable()
|
|
|
+ {
|
|
|
+diff --git a/dom/workers/WorkerEventTarget.h b/dom/workers/WorkerEventTarget.h
|
|
|
+--- a/dom/workers/WorkerEventTarget.h
|
|
|
++++ b/dom/workers/WorkerEventTarget.h
|
|
|
+@@ -8,19 +8,17 @@
|
|
|
+ #define mozilla_dom_WorkerEventTarget_h
|
|
|
+
|
|
|
+ #include "nsISerialEventTarget.h"
|
|
|
+ #include "mozilla/Mutex.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+
|
|
|
+ class WorkerEventTarget final : public nsISerialEventTarget
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ // The WorkerEventTarget supports different dispatch behaviors:
|
|
|
+ //
|
|
|
+ // * Hybrid targets will attempt to dispatch as a normal runnable,
|
|
|
+ // but fallback to a control runnable if that fails. This is
|
|
|
+@@ -31,27 +29,26 @@ public:
|
|
|
+ // * ControlOnly targets will simply dispatch a control runnable.
|
|
|
+ enum class Behavior : uint8_t {
|
|
|
+ Hybrid,
|
|
|
+ ControlOnly
|
|
|
+ };
|
|
|
+
|
|
|
+ private:
|
|
|
+ mozilla::Mutex mMutex;
|
|
|
+- workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ WorkerPrivate* mWorkerPrivate;
|
|
|
+ const Behavior mBehavior;
|
|
|
+
|
|
|
+ ~WorkerEventTarget() = default;
|
|
|
+
|
|
|
+ public:
|
|
|
+- WorkerEventTarget(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
+- Behavior aBehavior);
|
|
|
++ WorkerEventTarget(WorkerPrivate* aWorkerPrivate, Behavior aBehavior);
|
|
|
+
|
|
|
+ void
|
|
|
+- ForgetWorkerPrivate(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ ForgetWorkerPrivate(WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
+ NS_DECL_NSIEVENTTARGET
|
|
|
+ NS_DECL_NSISERIALEVENTTARGET
|
|
|
+ };
|
|
|
+
|
|
|
+ } // dom namespace
|
|
|
+ } // mozilla namespace
|
|
|
+diff --git a/dom/workers/WorkerHolder.h b/dom/workers/WorkerHolder.h
|
|
|
+--- a/dom/workers/WorkerHolder.h
|
|
|
++++ b/dom/workers/WorkerHolder.h
|
|
|
+@@ -7,19 +7,17 @@
|
|
|
+ #ifndef mozilla_dom_workers_WorkerHolder_h
|
|
|
+ #define mozilla_dom_workers_WorkerHolder_h
|
|
|
+
|
|
|
+ #include "mozilla/dom/workers/WorkerCommon.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Use this chart to help figure out behavior during each of the closing
|
|
|
+ * statuses. Details below.
|
|
|
+ *
|
|
|
+ * +==============================================================+
|
|
|
+ * | Closing Statuses |
|
|
|
+ * +=============+=============+=================+================+
|
|
|
+@@ -81,34 +79,33 @@ public:
|
|
|
+ AllowIdleShutdownStart,
|
|
|
+ PreventIdleShutdownStart,
|
|
|
+ };
|
|
|
+
|
|
|
+ explicit WorkerHolder(const char* aName,
|
|
|
+ Behavior aBehavior = PreventIdleShutdownStart);
|
|
|
+ virtual ~WorkerHolder();
|
|
|
+
|
|
|
+- bool HoldWorker(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
+- WorkerStatus aFailStatus);
|
|
|
++ bool HoldWorker(WorkerPrivate* aWorkerPrivate, WorkerStatus aFailStatus);
|
|
|
+ void ReleaseWorker();
|
|
|
+
|
|
|
+ virtual bool Notify(WorkerStatus aStatus) = 0;
|
|
|
+
|
|
|
+ Behavior GetBehavior() const;
|
|
|
+
|
|
|
+ const char*
|
|
|
+ Name() const
|
|
|
+ {
|
|
|
+ return mName;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected:
|
|
|
+ void ReleaseWorkerInternal();
|
|
|
+
|
|
|
+- workers::WorkerPrivate* MOZ_NON_OWNING_REF mWorkerPrivate;
|
|
|
++ WorkerPrivate* MOZ_NON_OWNING_REF mWorkerPrivate;
|
|
|
+
|
|
|
+ private:
|
|
|
+ void AssertIsOwningThread() const;
|
|
|
+
|
|
|
+ const Behavior mBehavior;
|
|
|
+
|
|
|
+ // For debugging only.
|
|
|
+ void* mThread;
|
|
|
+diff --git a/dom/workers/WorkerHolderToken.cpp b/dom/workers/WorkerHolderToken.cpp
|
|
|
+--- a/dom/workers/WorkerHolderToken.cpp
|
|
|
++++ b/dom/workers/WorkerHolderToken.cpp
|
|
|
+@@ -6,18 +6,16 @@
|
|
|
+
|
|
|
+ #include "WorkerHolderToken.h"
|
|
|
+
|
|
|
+ #include "WorkerPrivate.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ // static
|
|
|
+ already_AddRefed<WorkerHolderToken>
|
|
|
+ WorkerHolderToken::Create(WorkerPrivate* aWorkerPrivate,
|
|
|
+ WorkerStatus aShutdownStatus,
|
|
|
+ Behavior aBehavior)
|
|
|
+ {
|
|
|
+ MOZ_DIAGNOSTIC_ASSERT(aWorkerPrivate);
|
|
|
+ aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
+diff --git a/dom/workers/WorkerHolderToken.h b/dom/workers/WorkerHolderToken.h
|
|
|
+--- a/dom/workers/WorkerHolderToken.h
|
|
|
++++ b/dom/workers/WorkerHolderToken.h
|
|
|
+@@ -9,19 +9,17 @@
|
|
|
+
|
|
|
+ #include "nsISupportsImpl.h"
|
|
|
+ #include "nsTObserverArray.h"
|
|
|
+ #include "WorkerHolder.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+
|
|
|
+ // This is a ref-counted WorkerHolder implementation. If you wish
|
|
|
+ // to be notified of worker shutdown beginning, then you can implement
|
|
|
+ // the Listener interface and call AddListener().
|
|
|
+ //
|
|
|
+ // This is purely a convenience class to avoid requiring code to
|
|
|
+ // extend WorkerHolder all the time.
|
|
|
+ class WorkerHolderToken final : public WorkerHolder
|
|
|
+@@ -35,17 +33,17 @@ public:
|
|
|
+ virtual void
|
|
|
+ WorkerShuttingDown() = 0;
|
|
|
+ };
|
|
|
+
|
|
|
+ // Attempt to create a WorkerHolderToken(). If the shutdown has already
|
|
|
+ // passed the given shutdown phase or fails for another reason then
|
|
|
+ // nullptr is returned.
|
|
|
+ static already_AddRefed<WorkerHolderToken>
|
|
|
+- Create(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ Create(WorkerPrivate* aWorkerPrivate,
|
|
|
+ WorkerStatus aShutdownStatus,
|
|
|
+ Behavior aBehavior = PreventIdleShutdownStart);
|
|
|
+
|
|
|
+ // Add a listener to the token. Note, this does not hold a strong
|
|
|
+ // reference to the listener. You must call RemoveListener() before
|
|
|
+ // the listener is destroyed. This can only be called on the owning
|
|
|
+ // worker thread.
|
|
|
+ void
|
|
|
+@@ -54,17 +52,17 @@ public:
|
|
|
+ // Remove a previously added listener. This can only be called on the
|
|
|
+ // owning worker thread.
|
|
|
+ void
|
|
|
+ RemoveListener(Listener* aListener);
|
|
|
+
|
|
|
+ bool
|
|
|
+ IsShuttingDown() const;
|
|
|
+
|
|
|
+- workers::WorkerPrivate*
|
|
|
++ WorkerPrivate*
|
|
|
+ GetWorkerPrivate() const;
|
|
|
+
|
|
|
+ private:
|
|
|
+ WorkerHolderToken(WorkerStatus aShutdownStatus, Behavior aBehavior);
|
|
|
+
|
|
|
+ ~WorkerHolderToken();
|
|
|
+
|
|
|
+ // WorkerHolder methods
|
|
|
+diff --git a/dom/workers/WorkerLoadInfo.cpp b/dom/workers/WorkerLoadInfo.cpp
|
|
|
+--- a/dom/workers/WorkerLoadInfo.cpp
|
|
|
++++ b/dom/workers/WorkerLoadInfo.cpp
|
|
|
+@@ -19,18 +19,16 @@
|
|
|
+ #include "nsNetUtil.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+
|
|
|
+ using namespace ipc;
|
|
|
+
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ namespace {
|
|
|
+
|
|
|
+ class MainThreadReleaseRunnable final : public Runnable
|
|
|
+ {
|
|
|
+ nsTArray<nsCOMPtr<nsISupports>> mDoomed;
|
|
|
+ nsCOMPtr<nsILoadGroup> mLoadGroupToCancel;
|
|
|
+
|
|
|
+ public:
|
|
|
+diff --git a/dom/workers/WorkerLoadInfo.h b/dom/workers/WorkerLoadInfo.h
|
|
|
+--- a/dom/workers/WorkerLoadInfo.h
|
|
|
++++ b/dom/workers/WorkerLoadInfo.h
|
|
|
+@@ -29,19 +29,17 @@ class nsPIDOMWindowInner;
|
|
|
+ namespace mozilla {
|
|
|
+
|
|
|
+ namespace ipc {
|
|
|
+ class PrincipalInfo;
|
|
|
+ } // namespace ipc
|
|
|
+
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+
|
|
|
+ struct WorkerLoadInfo
|
|
|
+ {
|
|
|
+ // All of these should be released in WorkerPrivateParent::ForgetMainThreadObjects.
|
|
|
+ nsCOMPtr<nsIURI> mBaseURI;
|
|
|
+ nsCOMPtr<nsIURI> mResolvedScriptURI;
|
|
|
+
|
|
|
+ // This is the principal of the global (parent worker or a window) loading
|
|
|
+@@ -135,19 +133,19 @@ struct WorkerLoadInfo
|
|
|
+ bool
|
|
|
+ PrincipalIsValid() const;
|
|
|
+
|
|
|
+ bool
|
|
|
+ PrincipalURIMatchesScriptURL();
|
|
|
+ #endif
|
|
|
+
|
|
|
+ bool
|
|
|
+- ProxyReleaseMainThreadObjects(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ ProxyReleaseMainThreadObjects(WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ bool
|
|
|
+- ProxyReleaseMainThreadObjects(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ ProxyReleaseMainThreadObjects(WorkerPrivate* aWorkerPrivate,
|
|
|
+ nsCOMPtr<nsILoadGroup>& aLoadGroupToCancel);
|
|
|
+ };
|
|
|
+
|
|
|
+ } // dom namespace
|
|
|
+ } // mozilla namespace
|
|
|
+
|
|
|
+ #endif // mozilla_dom_workers_WorkerLoadInfo_h
|
|
|
+diff --git a/dom/workers/WorkerLocation.cpp b/dom/workers/WorkerLocation.cpp
|
|
|
+--- a/dom/workers/WorkerLocation.cpp
|
|
|
++++ b/dom/workers/WorkerLocation.cpp
|
|
|
+@@ -12,17 +12,17 @@ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WorkerLocation)
|
|
|
+
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WorkerLocation, AddRef)
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WorkerLocation, Release)
|
|
|
+
|
|
|
+ /* static */ already_AddRefed<WorkerLocation>
|
|
|
+-WorkerLocation::Create(workers::WorkerPrivate::LocationInfo& aInfo)
|
|
|
++WorkerLocation::Create(WorkerPrivate::LocationInfo& aInfo)
|
|
|
+ {
|
|
|
+ RefPtr<WorkerLocation> location =
|
|
|
+ new WorkerLocation(NS_ConvertUTF8toUTF16(aInfo.mHref),
|
|
|
+ NS_ConvertUTF8toUTF16(aInfo.mProtocol),
|
|
|
+ NS_ConvertUTF8toUTF16(aInfo.mHost),
|
|
|
+ NS_ConvertUTF8toUTF16(aInfo.mHostname),
|
|
|
+ NS_ConvertUTF8toUTF16(aInfo.mPort),
|
|
|
+ NS_ConvertUTF8toUTF16(aInfo.mPathname),
|
|
|
+diff --git a/dom/workers/WorkerLocation.h b/dom/workers/WorkerLocation.h
|
|
|
+--- a/dom/workers/WorkerLocation.h
|
|
|
++++ b/dom/workers/WorkerLocation.h
|
|
|
+@@ -54,17 +54,17 @@ class WorkerLocation final : public nsWr
|
|
|
+ }
|
|
|
+
|
|
|
+ public:
|
|
|
+
|
|
|
+ NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WorkerLocation)
|
|
|
+ NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WorkerLocation)
|
|
|
+
|
|
|
+ static already_AddRefed<WorkerLocation>
|
|
|
+- Create(workers::WorkerPrivate::LocationInfo& aInfo);
|
|
|
++ Create(WorkerPrivate::LocationInfo& aInfo);
|
|
|
+
|
|
|
+ virtual JSObject*
|
|
|
+ WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
|
|
+
|
|
|
+ nsISupports* GetParentObject() const {
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+
|
|
|
+diff --git a/dom/workers/WorkerNavigator.cpp b/dom/workers/WorkerNavigator.cpp
|
|
|
+--- a/dom/workers/WorkerNavigator.cpp
|
|
|
++++ b/dom/workers/WorkerNavigator.cpp
|
|
|
+@@ -23,18 +23,16 @@
|
|
|
+ #include "WorkerRunnable.h"
|
|
|
+ #include "WorkerScope.h"
|
|
|
+
|
|
|
+ #include "mozilla/dom/Navigator.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace mozilla::dom::workers;
|
|
|
+-
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WorkerNavigator, mStorageManager,
|
|
|
+ mConnection);
|
|
|
+
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WorkerNavigator, AddRef)
|
|
|
+ NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WorkerNavigator, Release)
|
|
|
+
|
|
|
+ WorkerNavigator::WorkerNavigator(const NavigatorProperties& aProperties,
|
|
|
+ bool aOnline)
|
|
|
+diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
|
|
|
+--- a/dom/workers/WorkerPrivate.cpp
|
|
|
++++ b/dom/workers/WorkerPrivate.cpp
|
|
|
+@@ -91,18 +91,16 @@ TimeoutsLog()
|
|
|
+ }
|
|
|
+
|
|
|
+ #define LOG(log, _args) MOZ_LOG(log, LogLevel::Debug, _args);
|
|
|
+
|
|
|
+ using namespace mozilla;
|
|
|
+ using namespace mozilla::dom;
|
|
|
+ using namespace mozilla::ipc;
|
|
|
+
|
|
|
+-USING_WORKERS_NAMESPACE
|
|
|
+-
|
|
|
+ MOZ_DEFINE_MALLOC_SIZE_OF(JsWorkerMallocSizeOf)
|
|
|
+
|
|
|
+ #ifdef DEBUG
|
|
|
+
|
|
|
+ BEGIN_WORKERS_NAMESPACE
|
|
|
+
|
|
|
+ void
|
|
|
+ AssertIsOnMainThread()
|
|
|
+@@ -251,17 +249,17 @@ private:
|
|
|
+
|
|
|
+ virtual bool
|
|
|
+ WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
|
|
|
+ {
|
|
|
+ if (!mFinishedWorker->ProxyReleaseMainThreadObjects()) {
|
|
|
+ NS_WARNING("Failed to dispatch, going to leak!");
|
|
|
+ }
|
|
|
+
|
|
|
+- RuntimeService* runtime = RuntimeService::GetService();
|
|
|
++ workers::RuntimeService* runtime = workers::RuntimeService::GetService();
|
|
|
+ NS_ASSERTION(runtime, "This should never be null!");
|
|
|
+
|
|
|
+ mFinishedWorker->DisableDebugger();
|
|
|
+
|
|
|
+ runtime->UnregisterWorker(mFinishedWorker);
|
|
|
+
|
|
|
+ mFinishedWorker->ClearSelfRef();
|
|
|
+ return true;
|
|
|
+@@ -283,19 +281,19 @@ public:
|
|
|
+ NS_DECL_ISUPPORTS_INHERITED
|
|
|
+
|
|
|
+ private:
|
|
|
+ ~TopLevelWorkerFinishedRunnable() {}
|
|
|
+
|
|
|
+ NS_IMETHOD
|
|
|
+ Run() override
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
+-
|
|
|
+- RuntimeService* runtime = RuntimeService::GetService();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
++
|
|
|
++ workers::RuntimeService* runtime = workers::RuntimeService::GetService();
|
|
|
+ MOZ_ASSERT(runtime);
|
|
|
+
|
|
|
+ mFinishedWorker->DisableDebugger();
|
|
|
+
|
|
|
+ runtime->UnregisterWorker(mFinishedWorker);
|
|
|
+
|
|
|
+ if (!mFinishedWorker->ProxyReleaseMainThreadObjects()) {
|
|
|
+ NS_WARNING("Failed to dispatch, going to leak!");
|
|
|
+@@ -565,17 +563,17 @@ class ReportErrorToConsoleRunnable final
|
|
|
+ public:
|
|
|
+ // aWorkerPrivate is the worker thread we're on (or the main thread, if null)
|
|
|
+ static void
|
|
|
+ Report(WorkerPrivate* aWorkerPrivate, const char* aMessage)
|
|
|
+ {
|
|
|
+ if (aWorkerPrivate) {
|
|
|
+ aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
+ } else {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Now fire a runnable to do the same on the parent's thread if we can.
|
|
|
+ if (aWorkerPrivate) {
|
|
|
+ RefPtr<ReportErrorToConsoleRunnable> runnable =
|
|
|
+ new ReportErrorToConsoleRunnable(aWorkerPrivate, aMessage);
|
|
|
+ runnable->Dispatch();
|
|
|
+ return;
|
|
|
+@@ -1032,22 +1030,22 @@ private:
|
|
|
+ { }
|
|
|
+ };
|
|
|
+
|
|
|
+ struct WorkerPrivate::TimeoutInfo
|
|
|
+ {
|
|
|
+ TimeoutInfo()
|
|
|
+ : mId(0), mIsInterval(false), mCanceled(false)
|
|
|
+ {
|
|
|
+- MOZ_COUNT_CTOR(mozilla::dom::workers::WorkerPrivate::TimeoutInfo);
|
|
|
++ MOZ_COUNT_CTOR(mozilla::dom::WorkerPrivate::TimeoutInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ ~TimeoutInfo()
|
|
|
+ {
|
|
|
+- MOZ_COUNT_DTOR(mozilla::dom::workers::WorkerPrivate::TimeoutInfo);
|
|
|
++ MOZ_COUNT_DTOR(mozilla::dom::WorkerPrivate::TimeoutInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ bool operator==(const TimeoutInfo& aOther)
|
|
|
+ {
|
|
|
+ return mTargetTime == aOther.mTargetTime;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool operator<(const TimeoutInfo& aOther)
|
|
|
+@@ -1223,17 +1221,17 @@ private:
|
|
|
+ {
|
|
|
+ mSuccess = success;
|
|
|
+ }
|
|
|
+
|
|
|
+ private:
|
|
|
+ ~FinishCollectRunnable()
|
|
|
+ {
|
|
|
+ // mHandleReport and mHandlerData are released on the main thread.
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ }
|
|
|
+
|
|
|
+ FinishCollectRunnable(const FinishCollectRunnable&) = delete;
|
|
|
+ FinishCollectRunnable& operator=(const FinishCollectRunnable&) = delete;
|
|
|
+ FinishCollectRunnable& operator=(const FinishCollectRunnable&&) = delete;
|
|
|
+ };
|
|
|
+
|
|
|
+ ~MemoryReporter()
|
|
|
+@@ -1257,17 +1255,17 @@ private:
|
|
|
+
|
|
|
+ NS_IMPL_ISUPPORTS(WorkerPrivate::MemoryReporter, nsIMemoryReporter)
|
|
|
+
|
|
|
+ NS_IMETHODIMP
|
|
|
+ WorkerPrivate::MemoryReporter::CollectReports(nsIHandleReportCallback* aHandleReport,
|
|
|
+ nsISupports* aData,
|
|
|
+ bool aAnonymize)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ RefPtr<CollectReportsRunnable> runnable;
|
|
|
+
|
|
|
+ {
|
|
|
+ MutexAutoLock lock(mMutex);
|
|
|
+
|
|
|
+ if (!mWorkerPrivate) {
|
|
|
+ // This will effectively report 0 memory.
|
|
|
+@@ -1309,17 +1307,17 @@ WorkerPrivate::MemoryReporter::CollectRe
|
|
|
+ }
|
|
|
+
|
|
|
+ return NS_OK;
|
|
|
+ }
|
|
|
+
|
|
|
+ void
|
|
|
+ WorkerPrivate::MemoryReporter::TryToMapAddon(nsACString &path)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ mMutex.AssertCurrentThreadOwns();
|
|
|
+
|
|
|
+ if (mAlreadyMappedToAddon || !mWorkerPrivate) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ nsCOMPtr<nsIURI> scriptURI;
|
|
|
+ if (NS_FAILED(NS_NewURI(getter_AddRefs(scriptURI),
|
|
|
+@@ -1385,31 +1383,30 @@ WorkerPrivate::MemoryReporter::CollectRe
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ WorkerPrivate::MemoryReporter::FinishCollectRunnable::FinishCollectRunnable(
|
|
|
+ nsIHandleReportCallback* aHandleReport,
|
|
|
+ nsISupports* aHandlerData,
|
|
|
+ bool aAnonymize,
|
|
|
+ const nsACString& aPath)
|
|
|
+- : mozilla::Runnable(
|
|
|
+- "dom::workers::WorkerPrivate::MemoryReporter::FinishCollectRunnable")
|
|
|
++ : mozilla::Runnable("dom::WorkerPrivate::MemoryReporter::FinishCollectRunnable")
|
|
|
+ , mHandleReport(aHandleReport)
|
|
|
+ , mHandlerData(aHandlerData)
|
|
|
+ , mPerformanceUserEntries(0)
|
|
|
+ , mPerformanceResourceEntries(0)
|
|
|
+ , mAnonymize(aAnonymize)
|
|
|
+ , mSuccess(false)
|
|
|
+ , mCxStats(aPath)
|
|
|
+ { }
|
|
|
+
|
|
|
+ NS_IMETHODIMP
|
|
|
+ WorkerPrivate::MemoryReporter::FinishCollectRunnable::Run()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ nsCOMPtr<nsIMemoryReporterManager> manager =
|
|
|
+ do_GetService("@mozilla.org/memory-reporter-manager;1");
|
|
|
+
|
|
|
+ if (!manager)
|
|
|
+ return NS_OK;
|
|
|
+
|
|
|
+ if (mSuccess) {
|
|
|
+@@ -1452,17 +1449,17 @@ WorkerPrivate::SyncLoopInfo::SyncLoopInf
|
|
|
+ #endif
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ template <class Derived>
|
|
|
+ nsIDocument*
|
|
|
+ WorkerPrivateParent<Derived>::GetDocument() const
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ if (mLoadInfo.mWindow) {
|
|
|
+ return mLoadInfo.mWindow->GetExtantDoc();
|
|
|
+ }
|
|
|
+ // if we don't have a document, we should query the document
|
|
|
+ // from the parent in case of a nested worker
|
|
|
+ WorkerPrivate* parent = mParent;
|
|
|
+ while (parent) {
|
|
|
+ if (parent->mLoadInfo.mWindow) {
|
|
|
+@@ -1473,31 +1470,31 @@ WorkerPrivateParent<Derived>::GetDocumen
|
|
|
+ // couldn't query a document, give up and return nullptr
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+
|
|
|
+ template <class Derived>
|
|
|
+ void
|
|
|
+ WorkerPrivateParent<Derived>::SetCSP(nsIContentSecurityPolicy* aCSP)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ if (!aCSP) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ WorkerPrivate* self = ParentAsWorkerPrivate();
|
|
|
+ aCSP->EnsureEventTarget(self->mMainThreadEventTarget);
|
|
|
+ mLoadInfo.mCSP = aCSP;
|
|
|
+ }
|
|
|
+
|
|
|
+ template <class Derived>
|
|
|
+ nsresult
|
|
|
+ WorkerPrivateParent<Derived>::SetCSPFromHeaderValues(const nsACString& aCSPHeaderValue,
|
|
|
+ const nsACString& aCSPReportOnlyHeaderValue)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ MOZ_DIAGNOSTIC_ASSERT(!mLoadInfo.mCSP);
|
|
|
+
|
|
|
+ NS_ConvertASCIItoUTF16 cspHeaderValue(aCSPHeaderValue);
|
|
|
+ NS_ConvertASCIItoUTF16 cspROHeaderValue(aCSPReportOnlyHeaderValue);
|
|
|
+
|
|
|
+ nsCOMPtr<nsIContentSecurityPolicy> csp;
|
|
|
+ nsresult rv = mLoadInfo.mPrincipal->EnsureCSP(nullptr, getter_AddRefs(csp));
|
|
|
+ if (!csp) {
|
|
|
+@@ -1587,17 +1584,17 @@ WorkerPrivateParent<Derived>::WorkerPriv
|
|
|
+ mIsChromeWorker(aIsChromeWorker), mMainThreadObjectsForgotten(false),
|
|
|
+ mIsSecureContext(false), mWorkerType(aWorkerType),
|
|
|
+ mCreationTimeStamp(TimeStamp::Now()),
|
|
|
+ mCreationTimeHighRes((double)PR_Now() / PR_USEC_PER_MSEC)
|
|
|
+ {
|
|
|
+ MOZ_ASSERT_IF(!IsDedicatedWorker(), NS_IsMainThread());
|
|
|
+
|
|
|
+ if (aLoadInfo.mWindow) {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ MOZ_ASSERT(aLoadInfo.mWindow->IsInnerWindow(),
|
|
|
+ "Should have inner window here!");
|
|
|
+ BindToOwner(aLoadInfo.mWindow);
|
|
|
+ }
|
|
|
+
|
|
|
+ mLoadInfo.StealFrom(aLoadInfo);
|
|
|
+
|
|
|
+ if (aParent) {
|
|
|
+@@ -1613,19 +1610,19 @@ WorkerPrivateParent<Derived>::WorkerPriv
|
|
|
+
|
|
|
+ MOZ_ASSERT(IsDedicatedWorker());
|
|
|
+
|
|
|
+ if (aParent->mParentFrozen) {
|
|
|
+ Freeze(nullptr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+- AssertIsOnMainThread();
|
|
|
+-
|
|
|
+- RuntimeService::GetDefaultJSSettings(mJSSettings);
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
++
|
|
|
++ workers::RuntimeService::GetDefaultJSSettings(mJSSettings);
|
|
|
+
|
|
|
+ // Our secure context state depends on the kind of worker we have.
|
|
|
+ if (UsesSystemPrincipal() || IsServiceWorker()) {
|
|
|
+ mIsSecureContext = true;
|
|
|
+ } else if (mLoadInfo.mWindow) {
|
|
|
+ // Shared and dedicated workers both inherit the loading window's secure
|
|
|
+ // context state. Shared workers then prevent windows with a different
|
|
|
+ // secure context state from attaching to them.
|
|
|
+@@ -1879,17 +1876,17 @@ WorkerPrivateParent<Derived>::NotifyPriv
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ pending = mParentStatus == Pending;
|
|
|
+ mParentStatus = aStatus;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (IsSharedWorker()) {
|
|
|
+- RuntimeService* runtime = RuntimeService::GetService();
|
|
|
++ workers::RuntimeService* runtime = workers::RuntimeService::GetService();
|
|
|
+ MOZ_ASSERT(runtime);
|
|
|
+
|
|
|
+ runtime->ForgetSharedWorker(ParentAsWorkerPrivate());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pending) {
|
|
|
+ WorkerPrivate* self = ParentAsWorkerPrivate();
|
|
|
+
|
|
|
+@@ -1927,17 +1924,17 @@ bool
|
|
|
+ WorkerPrivateParent<Derived>::Freeze(nsPIDOMWindowInner* aWindow)
|
|
|
+ {
|
|
|
+ AssertIsOnParentThread();
|
|
|
+
|
|
|
+ // Shared workers are only frozen if all of their owning documents are
|
|
|
+ // frozen. It can happen that mSharedWorkers is empty but this thread has
|
|
|
+ // not been unregistered yet.
|
|
|
+ if ((IsSharedWorker() || IsServiceWorker()) && !mSharedWorkers.IsEmpty()) {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ bool allFrozen = true;
|
|
|
+
|
|
|
+ for (uint32_t i = 0; i < mSharedWorkers.Length(); ++i) {
|
|
|
+ if (aWindow && mSharedWorkers[i]->GetOwner() == aWindow) {
|
|
|
+ // Calling Freeze() may change the refcount, ensure that the worker
|
|
|
+ // outlives this call.
|
|
|
+ RefPtr<SharedWorker> kungFuDeathGrip = mSharedWorkers[i];
|
|
|
+@@ -1986,17 +1983,17 @@ WorkerPrivateParent<Derived>::Thaw(nsPID
|
|
|
+ AssertIsOnParentThread();
|
|
|
+
|
|
|
+ MOZ_ASSERT(mParentFrozen);
|
|
|
+
|
|
|
+ // Shared workers are resumed if any of their owning documents are thawed.
|
|
|
+ // It can happen that mSharedWorkers is empty but this thread has not been
|
|
|
+ // unregistered yet.
|
|
|
+ if ((IsSharedWorker() || IsServiceWorker()) && !mSharedWorkers.IsEmpty()) {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ bool anyRunning = false;
|
|
|
+
|
|
|
+ for (uint32_t i = 0; i < mSharedWorkers.Length(); ++i) {
|
|
|
+ if (aWindow && mSharedWorkers[i]->GetOwner() == aWindow) {
|
|
|
+ // Calling Thaw() may change the refcount, ensure that the worker
|
|
|
+ // outlives this call.
|
|
|
+ RefPtr<SharedWorker> kungFuDeathGrip = mSharedWorkers[i];
|
|
|
+@@ -2053,26 +2050,26 @@ WorkerPrivateParent<Derived>::Thaw(nsPID
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ template <class Derived>
|
|
|
+ void
|
|
|
+ WorkerPrivateParent<Derived>::ParentWindowPaused()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ MOZ_ASSERT_IF(IsDedicatedWorker(), mParentWindowPausedDepth == 0);
|
|
|
+ mParentWindowPausedDepth += 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ template <class Derived>
|
|
|
+ void
|
|
|
+ WorkerPrivateParent<Derived>::ParentWindowResumed()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ MOZ_ASSERT(mParentWindowPausedDepth > 0);
|
|
|
+ MOZ_ASSERT_IF(IsDedicatedWorker(), mParentWindowPausedDepth == 1);
|
|
|
+ mParentWindowPausedDepth -= 1;
|
|
|
+ if (mParentWindowPausedDepth > 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+@@ -2398,17 +2395,17 @@ WorkerPrivateParent<Derived>::MemoryPres
|
|
|
+ Unused << NS_WARN_IF(!runnable->Dispatch());
|
|
|
+ }
|
|
|
+
|
|
|
+ template <class Derived>
|
|
|
+ bool
|
|
|
+ WorkerPrivateParent<Derived>::RegisterSharedWorker(SharedWorker* aSharedWorker,
|
|
|
+ MessagePort* aPort)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ MOZ_ASSERT(aSharedWorker);
|
|
|
+ MOZ_ASSERT(IsSharedWorker());
|
|
|
+ MOZ_ASSERT(!mSharedWorkers.Contains(aSharedWorker));
|
|
|
+
|
|
|
+ if (IsSharedWorker()) {
|
|
|
+ RefPtr<MessagePortRunnable> runnable =
|
|
|
+ new MessagePortRunnable(ParentAsWorkerPrivate(), aPort);
|
|
|
+ if (!runnable->Dispatch()) {
|
|
|
+@@ -2429,17 +2426,17 @@ WorkerPrivateParent<Derived>::RegisterSh
|
|
|
+
|
|
|
+ template <class Derived>
|
|
|
+ void
|
|
|
+ WorkerPrivateParent<Derived>::BroadcastErrorToSharedWorkers(
|
|
|
+ JSContext* aCx,
|
|
|
+ const WorkerErrorReport* aReport,
|
|
|
+ bool aIsErrorEvent)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ if (aIsErrorEvent && JSREPORT_IS_WARNING(aReport->mFlags)) {
|
|
|
+ // Don't fire any events anywhere. Just log to console.
|
|
|
+ // XXXbz should we log to all the consoles of all the relevant windows?
|
|
|
+ MOZ_ASSERT(aReport);
|
|
|
+ WorkerErrorReport::LogErrorToConsole(*aReport, 0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+@@ -2563,34 +2560,34 @@ WorkerPrivateParent<Derived>::BroadcastE
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ template <class Derived>
|
|
|
+ void
|
|
|
+ WorkerPrivateParent<Derived>::GetAllSharedWorkers(
|
|
|
+ nsTArray<RefPtr<SharedWorker>>& aSharedWorkers)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ MOZ_ASSERT(IsSharedWorker() || IsServiceWorker());
|
|
|
+
|
|
|
+ if (!aSharedWorkers.IsEmpty()) {
|
|
|
+ aSharedWorkers.Clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ for (uint32_t i = 0; i < mSharedWorkers.Length(); ++i) {
|
|
|
+ aSharedWorkers.AppendElement(mSharedWorkers[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ template <class Derived>
|
|
|
+ void
|
|
|
+ WorkerPrivateParent<Derived>::CloseSharedWorkersForWindow(
|
|
|
+ nsPIDOMWindowInner* aWindow)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ MOZ_ASSERT(IsSharedWorker() || IsServiceWorker());
|
|
|
+ MOZ_ASSERT(aWindow);
|
|
|
+
|
|
|
+ bool someRemoved = false;
|
|
|
+
|
|
|
+ for (uint32_t i = 0; i < mSharedWorkers.Length();) {
|
|
|
+ if (mSharedWorkers[i]->GetOwner() == aWindow) {
|
|
|
+ mSharedWorkers[i]->Close();
|
|
|
+@@ -2617,46 +2614,46 @@ WorkerPrivateParent<Derived>::CloseShare
|
|
|
+ Cancel();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ template <class Derived>
|
|
|
+ void
|
|
|
+ WorkerPrivateParent<Derived>::CloseAllSharedWorkers()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ MOZ_ASSERT(IsSharedWorker() || IsServiceWorker());
|
|
|
+
|
|
|
+ for (uint32_t i = 0; i < mSharedWorkers.Length(); ++i) {
|
|
|
+ mSharedWorkers[i]->Close();
|
|
|
+ }
|
|
|
+
|
|
|
+ mSharedWorkers.Clear();
|
|
|
+
|
|
|
+ Cancel();
|
|
|
+ }
|
|
|
+
|
|
|
+ template <class Derived>
|
|
|
+ void
|
|
|
+ WorkerPrivateParent<Derived>::WorkerScriptLoaded()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ if (IsSharedWorker() || IsServiceWorker()) {
|
|
|
+ // No longer need to hold references to the window or document we came from.
|
|
|
+ mLoadInfo.mWindow = nullptr;
|
|
|
+ mLoadInfo.mScriptContext = nullptr;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ template <class Derived>
|
|
|
+ void
|
|
|
+ WorkerPrivateParent<Derived>::SetBaseURI(nsIURI* aBaseURI)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ if (!mLoadInfo.mBaseURI) {
|
|
|
+ NS_ASSERTION(GetParent(), "Shouldn't happen without a parent!");
|
|
|
+ mLoadInfo.mResolvedScriptURI = aBaseURI;
|
|
|
+ }
|
|
|
+
|
|
|
+ mLoadInfo.mBaseURI = aBaseURI;
|
|
|
+
|
|
|
+@@ -2740,28 +2737,28 @@ WorkerPrivateParent<Derived>::PrincipalU
|
|
|
+ return mLoadInfo.PrincipalURIMatchesScriptURL();
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+
|
|
|
+ template <class Derived>
|
|
|
+ void
|
|
|
+ WorkerPrivateParent<Derived>::UpdateOverridenLoadGroup(nsILoadGroup* aBaseLoadGroup)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ // The load group should have been overriden at init time.
|
|
|
+ mLoadInfo.mInterfaceRequestor->MaybeAddTabChild(aBaseLoadGroup);
|
|
|
+ }
|
|
|
+
|
|
|
+ template <class Derived>
|
|
|
+ void
|
|
|
+ WorkerPrivateParent<Derived>::FlushReportsToSharedWorkers(
|
|
|
+ nsIConsoleReportCollector* aReporter)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ AutoTArray<RefPtr<SharedWorker>, 10> sharedWorkers;
|
|
|
+ AutoTArray<WindowAction, 10> windowActions;
|
|
|
+ GetAllSharedWorkers(sharedWorkers);
|
|
|
+
|
|
|
+ // First find out all the shared workers' window.
|
|
|
+ for (size_t index = 0; index < sharedWorkers.Length(); index++) {
|
|
|
+ RefPtr<SharedWorker>& sharedWorker = sharedWorkers[index];
|
|
|
+@@ -2844,32 +2841,32 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
+ template <class Derived>
|
|
|
+ void
|
|
|
+ WorkerPrivateParent<Derived>::AssertIsOnParentThread() const
|
|
|
+ {
|
|
|
+ if (GetParent()) {
|
|
|
+ GetParent()->AssertIsOnWorkerThread();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ template <class Derived>
|
|
|
+ void
|
|
|
+ WorkerPrivateParent<Derived>::AssertInnerWindowIsCorrect() const
|
|
|
+ {
|
|
|
+ AssertIsOnParentThread();
|
|
|
+
|
|
|
+ // Only care about top level workers from windows.
|
|
|
+ if (mParent || !mLoadInfo.mWindow) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ nsPIDOMWindowOuter* outer = mLoadInfo.mWindow->GetOuterWindow();
|
|
|
+ NS_ASSERTION(outer && outer->GetCurrentInnerWindow() == mLoadInfo.mWindow,
|
|
|
+ "Inner window no longer correct!");
|
|
|
+ }
|
|
|
+
|
|
|
+ #endif
|
|
|
+
|
|
|
+@@ -2917,17 +2914,17 @@ WorkerPrivate::WorkerPrivate(WorkerPriva
|
|
|
+ , mFetchHandlerWasAdded(false)
|
|
|
+ , mOnLine(false)
|
|
|
+ {
|
|
|
+ if (aParent) {
|
|
|
+ aParent->AssertIsOnWorkerThread();
|
|
|
+ mOnLine = aParent->OnLine();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ mOnLine = !NS_IsOffline();
|
|
|
+ }
|
|
|
+
|
|
|
+ nsCOMPtr<nsISerialEventTarget> target;
|
|
|
+
|
|
|
+ // A child worker just inherits the parent workers ThrottledEventQueue
|
|
|
+ // and main thread target for now. This is mainly due to the restriction
|
|
|
+ // that ThrottledEventQueue can only be created on the main thread at the
|
|
|
+@@ -3061,17 +3058,17 @@ WorkerPrivate::Constructor(JSContext* aC
|
|
|
+ parent->AssertIsOnWorkerThread();
|
|
|
+
|
|
|
+ holder.reset(new SimpleWorkerHolder());
|
|
|
+ if (!holder->HoldWorker(parent, Canceling)) {
|
|
|
+ aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ }
|
|
|
+
|
|
|
+ Maybe<WorkerLoadInfo> stackLoadInfo;
|
|
|
+ if (!aLoadInfo) {
|
|
|
+ stackLoadInfo.emplace();
|
|
|
+
|
|
|
+ nsresult rv = GetLoadInfo(aCx, nullptr, parent, aScriptURL,
|
|
|
+ aIsChromeWorker, InheritLoadGroup,
|
|
|
+@@ -3083,27 +3080,27 @@ WorkerPrivate::Constructor(JSContext* aC
|
|
|
+ }
|
|
|
+
|
|
|
+ aLoadInfo = stackLoadInfo.ptr();
|
|
|
+ }
|
|
|
+
|
|
|
+ // NB: This has to be done before creating the WorkerPrivate, because it will
|
|
|
+ // attempt to use static variables that are initialized in the RuntimeService
|
|
|
+ // constructor.
|
|
|
+- RuntimeService* runtimeService;
|
|
|
++ workers::RuntimeService* runtimeService;
|
|
|
+
|
|
|
+ if (!parent) {
|
|
|
+- runtimeService = RuntimeService::GetOrCreateService();
|
|
|
++ runtimeService = workers::RuntimeService::GetOrCreateService();
|
|
|
+ if (!runtimeService) {
|
|
|
+ aRv.Throw(NS_ERROR_FAILURE);
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+- runtimeService = RuntimeService::GetService();
|
|
|
++ runtimeService = workers::RuntimeService::GetService();
|
|
|
+ }
|
|
|
+
|
|
|
+ MOZ_ASSERT(runtimeService);
|
|
|
+
|
|
|
+ RefPtr<WorkerPrivate> worker =
|
|
|
+ new WorkerPrivate(parent, aScriptURL, aIsChromeWorker,
|
|
|
+ aWorkerType, aWorkerName, aServiceWorkerScope,
|
|
|
+ *aLoadInfo);
|
|
|
+@@ -3151,17 +3148,17 @@ WorkerPrivate::GetLoadInfo(JSContext* aC
|
|
|
+ WorkerLoadInfo* aLoadInfo)
|
|
|
+ {
|
|
|
+ using namespace mozilla::dom::workerinternals;
|
|
|
+
|
|
|
+ MOZ_ASSERT(aCx);
|
|
|
+ MOZ_ASSERT_IF(NS_IsMainThread(), aCx == nsContentUtils::GetCurrentJSContext());
|
|
|
+
|
|
|
+ if (aWindow) {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ }
|
|
|
+
|
|
|
+ WorkerLoadInfo loadInfo;
|
|
|
+ nsresult rv;
|
|
|
+
|
|
|
+ if (aParent) {
|
|
|
+ aParent->AssertIsOnWorkerThread();
|
|
|
+
|
|
|
+@@ -3201,17 +3198,17 @@ WorkerPrivate::GetLoadInfo(JSContext* aC
|
|
|
+ loadInfo.mFromWindow = aParent->IsFromWindow();
|
|
|
+ loadInfo.mWindowID = aParent->WindowID();
|
|
|
+ loadInfo.mStorageAllowed = aParent->IsStorageAllowed();
|
|
|
+ loadInfo.mOriginAttributes = aParent->GetOriginAttributes();
|
|
|
+ loadInfo.mServiceWorkersTestingInWindow =
|
|
|
+ aParent->ServiceWorkersTestingInWindow();
|
|
|
+ loadInfo.mParentController = aParent->GetController();
|
|
|
+ } else {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ // Make sure that the IndexedDatabaseManager is set up
|
|
|
+ Unused << NS_WARN_IF(!IndexedDatabaseManager::GetOrCreate());
|
|
|
+
|
|
|
+ nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
|
|
|
+ MOZ_ASSERT(ssm);
|
|
|
+
|
|
|
+ bool isChrome = nsContentUtils::IsSystemCaller(aCx);
|
|
|
+@@ -3838,23 +3835,23 @@ WorkerPrivate::SetGCTimerMode(GCTimerMod
|
|
|
+ int16_t type = nsITimer::TYPE_ONE_SHOT;
|
|
|
+ nsTimerCallbackFunc callback = nullptr;
|
|
|
+ const char* name = nullptr;
|
|
|
+
|
|
|
+ if (aMode == PeriodicTimer) {
|
|
|
+ delay = PERIODIC_GC_TIMER_DELAY_SEC * 1000;
|
|
|
+ type = nsITimer::TYPE_REPEATING_SLACK;
|
|
|
+ callback = PeriodicGCTimerCallback;
|
|
|
+- name = "dom::workers::PeriodicGCTimerCallback";
|
|
|
++ name = "dom::PeriodicGCTimerCallback";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ delay = IDLE_GC_TIMER_DELAY_SEC * 1000;
|
|
|
+ type = nsITimer::TYPE_ONE_SHOT;
|
|
|
+ callback = IdleGCTimerCallback;
|
|
|
+- name = "dom::workers::IdleGCTimerCallback";
|
|
|
++ name = "dom::IdleGCTimerCallback";
|
|
|
+ }
|
|
|
+
|
|
|
+ MOZ_ALWAYS_SUCCEEDS(mGCTimer->SetTarget(mWorkerControlEventTarget));
|
|
|
+ MOZ_ALWAYS_SUCCEEDS(
|
|
|
+ mGCTimer->InitWithNamedFuncCallback(callback, this, delay, type, name));
|
|
|
+
|
|
|
+ if (aMode == PeriodicTimer) {
|
|
|
+ LOG(WorkerLog(), ("Worker %p scheduled periodic GC timer\n", this));
|
|
|
+@@ -5548,17 +5545,17 @@ WorkerPrivate::DumpCrashInformation(nsAC
|
|
|
+ aString.Append("|");
|
|
|
+ aString.Append(holder->Name());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ PerformanceStorage*
|
|
|
+ WorkerPrivate::GetPerformanceStorage()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ if (!mPerformanceStorage) {
|
|
|
+ mPerformanceStorage = PerformanceStorageWorker::Create(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ return mPerformanceStorage;
|
|
|
+ }
|
|
|
+
|
|
|
+@@ -5671,14 +5668,10 @@ EventTarget::IsOnCurrentThreadInfallible
|
|
|
+ if (!mWorkerPrivate) {
|
|
|
+ NS_WARNING("A worker's event target was used after the worker has !");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return mWorkerPrivate->IsOnCurrentThread();
|
|
|
+ }
|
|
|
+
|
|
|
+-BEGIN_WORKERS_NAMESPACE
|
|
|
+-
|
|
|
+ // Force instantiation.
|
|
|
+ template class WorkerPrivateParent<WorkerPrivate>;
|
|
|
+-
|
|
|
+-END_WORKERS_NAMESPACE
|
|
|
+diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h
|
|
|
+--- a/dom/workers/WorkerPrivate.h
|
|
|
++++ b/dom/workers/WorkerPrivate.h
|
|
|
+@@ -2,28 +2,28 @@
|
|
|
+ /* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
+ /* 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/. */
|
|
|
+
|
|
|
+ #ifndef mozilla_dom_workers_workerprivate_h__
|
|
|
+ #define mozilla_dom_workers_workerprivate_h__
|
|
|
+
|
|
|
+-#include "WorkerCommon.h"
|
|
|
++#include "mozilla/dom/workers/WorkerCommon.h"
|
|
|
+ #include "mozilla/CondVar.h"
|
|
|
+ #include "mozilla/DOMEventTargetHelper.h"
|
|
|
+ #include "nsDOMNavigationTiming.h"
|
|
|
+ #include "nsIContentSecurityPolicy.h"
|
|
|
+ #include "nsIEventTarget.h"
|
|
|
+ #include "nsThreadUtils.h"
|
|
|
+ #include "nsTObserverArray.h"
|
|
|
+
|
|
|
+-#include "Queue.h"
|
|
|
+-#include "WorkerHolder.h"
|
|
|
+-#include "WorkerLoadInfo.h"
|
|
|
++#include "mozilla/dom/WorkerHolder.h"
|
|
|
++#include "mozilla/dom/WorkerLoadInfo.h"
|
|
|
++#include "mozilla/dom/workers/Queue.h"
|
|
|
+
|
|
|
+ #ifdef XP_WIN
|
|
|
+ #undef PostMessage
|
|
|
+ #endif
|
|
|
+
|
|
|
+ class nsIConsoleReportCollector;
|
|
|
+ class nsIThreadInternal;
|
|
|
+
|
|
|
+@@ -42,21 +42,16 @@ class WorkerDebugger;
|
|
|
+ class WorkerDebuggerGlobalScope;
|
|
|
+ class WorkerErrorReport;
|
|
|
+ class WorkerEventTarget;
|
|
|
+ class WorkerGlobalScope;
|
|
|
+ struct WorkerOptions;
|
|
|
+ class WorkerRunnable;
|
|
|
+ class WorkerThread;
|
|
|
+
|
|
|
+-} // dom namespace
|
|
|
+-} // mozilla namespace
|
|
|
+-
|
|
|
+-BEGIN_WORKERS_NAMESPACE
|
|
|
+-
|
|
|
+ // SharedMutex is a small wrapper around an (internal) reference-counted Mutex
|
|
|
+ // object. It exists to avoid changing a lot of code to use Mutex* instead of
|
|
|
+ // Mutex&.
|
|
|
+ class SharedMutex
|
|
|
+ {
|
|
|
+ typedef mozilla::Mutex Mutex;
|
|
|
+
|
|
|
+ class RefCountedMutex final : public Mutex
|
|
|
+@@ -144,17 +139,17 @@ private:
|
|
|
+ WorkerLoadInfo mLoadInfo;
|
|
|
+
|
|
|
+ Atomic<bool> mLoadingWorkerScript;
|
|
|
+
|
|
|
+ // Only used for top level workers.
|
|
|
+ nsTArray<nsCOMPtr<nsIRunnable>> mQueuedRunnables;
|
|
|
+
|
|
|
+ // Protected by mMutex.
|
|
|
+- JSSettings mJSSettings;
|
|
|
++ workers::JSSettings mJSSettings;
|
|
|
+
|
|
|
+ // Only touched on the parent thread (currently this is always the main
|
|
|
+ // thread as SharedWorkers are always top-level).
|
|
|
+ nsTArray<RefPtr<SharedWorker>> mSharedWorkers;
|
|
|
+
|
|
|
+ // This is touched on parent thread only, but it can be read on a different
|
|
|
+ // thread before crashing because hanging.
|
|
|
+ Atomic<uint64_t> mBusyCount;
|
|
|
+@@ -398,17 +393,17 @@ public:
|
|
|
+ {
|
|
|
+ mMutex.AssertCurrentThreadOwns();
|
|
|
+ return mParentStatus;
|
|
|
+ }
|
|
|
+
|
|
|
+ nsIScriptContext*
|
|
|
+ GetScriptContext() const
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ return mLoadInfo.mScriptContext;
|
|
|
+ }
|
|
|
+
|
|
|
+ const nsString&
|
|
|
+ ScriptURL() const
|
|
|
+ {
|
|
|
+ return mScriptURL;
|
|
|
+ }
|
|
|
+@@ -447,35 +442,35 @@ public:
|
|
|
+ ServiceWorkerScope() const
|
|
|
+ {
|
|
|
+ return GetServiceWorkerDescriptor().Scope();
|
|
|
+ }
|
|
|
+
|
|
|
+ nsIURI*
|
|
|
+ GetBaseURI() const
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ return mLoadInfo.mBaseURI;
|
|
|
+ }
|
|
|
+
|
|
|
+ void
|
|
|
+ SetBaseURI(nsIURI* aBaseURI);
|
|
|
+
|
|
|
+ nsIURI*
|
|
|
+ GetResolvedScriptURI() const
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ return mLoadInfo.mResolvedScriptURI;
|
|
|
+ }
|
|
|
+
|
|
|
+ const nsString&
|
|
|
+ ServiceWorkerCacheName() const
|
|
|
+ {
|
|
|
+ MOZ_DIAGNOSTIC_ASSERT(IsServiceWorker());
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ return mLoadInfo.mServiceWorkerCacheName;
|
|
|
+ }
|
|
|
+
|
|
|
+ const ServiceWorkerDescriptor&
|
|
|
+ GetServiceWorkerDescriptor() const
|
|
|
+ {
|
|
|
+ MOZ_DIAGNOSTIC_ASSERT(IsServiceWorker());
|
|
|
+ MOZ_DIAGNOSTIC_ASSERT(mLoadInfo.mServiceWorkerDescriptor.isSome());
|
|
|
+@@ -500,17 +495,17 @@ public:
|
|
|
+ GetChannelInfo() const
|
|
|
+ {
|
|
|
+ return mLoadInfo.mChannelInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ void
|
|
|
+ SetChannelInfo(const ChannelInfo& aChannelInfo)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ MOZ_ASSERT(!mLoadInfo.mChannelInfo.IsInitialized());
|
|
|
+ MOZ_ASSERT(aChannelInfo.IsInitialized());
|
|
|
+ mLoadInfo.mChannelInfo = aChannelInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ void
|
|
|
+ InitChannelInfo(nsIChannel* aChannel)
|
|
|
+ {
|
|
|
+@@ -561,36 +556,36 @@ public:
|
|
|
+ MOZ_ASSERT(!aTimeStamp.IsNull());
|
|
|
+ TimeDuration duration = aTimeStamp - mCreationTimeStamp;
|
|
|
+ return duration.ToMilliseconds();
|
|
|
+ }
|
|
|
+
|
|
|
+ nsIPrincipal*
|
|
|
+ GetPrincipal() const
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ return mLoadInfo.mPrincipal;
|
|
|
+ }
|
|
|
+
|
|
|
+ nsIPrincipal*
|
|
|
+ GetLoadingPrincipal() const
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ return mLoadInfo.mLoadingPrincipal;
|
|
|
+ }
|
|
|
+
|
|
|
+ const nsAString& Origin() const
|
|
|
+ {
|
|
|
+ return mLoadInfo.mOrigin;
|
|
|
+ }
|
|
|
+
|
|
|
+ nsILoadGroup*
|
|
|
+ GetLoadGroup() const
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ return mLoadInfo.mLoadGroup;
|
|
|
+ }
|
|
|
+
|
|
|
+ // This method allows the principal to be retrieved off the main thread.
|
|
|
+ // Principals are main-thread objects so the caller must ensure that all
|
|
|
+ // access occurs on the main thread.
|
|
|
+ nsIPrincipal*
|
|
|
+ GetPrincipalDontAssertMainThread() const
|
|
|
+@@ -622,33 +617,33 @@ public:
|
|
|
+ GetPrincipalInfo() const
|
|
|
+ {
|
|
|
+ return *mLoadInfo.mPrincipalInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ already_AddRefed<nsIChannel>
|
|
|
+ ForgetWorkerChannel()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ return mLoadInfo.mChannel.forget();
|
|
|
+ }
|
|
|
+
|
|
|
+ nsIDocument* GetDocument() const;
|
|
|
+
|
|
|
+ nsPIDOMWindowInner*
|
|
|
+ GetWindow()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ return mLoadInfo.mWindow;
|
|
|
+ }
|
|
|
+
|
|
|
+ nsIContentSecurityPolicy*
|
|
|
+ GetCSP() const
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ return mLoadInfo.mCSP;
|
|
|
+ }
|
|
|
+
|
|
|
+ void
|
|
|
+ SetCSP(nsIContentSecurityPolicy* aCSP);
|
|
|
+
|
|
|
+ nsresult
|
|
|
+ SetCSPFromHeaderValues(const nsACString& aCSPHeaderValue,
|
|
|
+@@ -707,17 +702,17 @@ public:
|
|
|
+
|
|
|
+ LocationInfo&
|
|
|
+ GetLocationInfo()
|
|
|
+ {
|
|
|
+ return mLocationInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ void
|
|
|
+- CopyJSSettings(JSSettings& aSettings)
|
|
|
++ CopyJSSettings(workers::JSSettings& aSettings)
|
|
|
+ {
|
|
|
+ mozilla::MutexAutoLock lock(mMutex);
|
|
|
+ aSettings = mJSSettings;
|
|
|
+ }
|
|
|
+
|
|
|
+ void
|
|
|
+ CopyJSCompartmentOptions(JS::CompartmentOptions& aOptions)
|
|
|
+ {
|
|
|
+@@ -889,18 +884,18 @@ class WorkerPrivate : public WorkerPriva
|
|
|
+ PeriodicTimer = 0,
|
|
|
+ IdleTimer,
|
|
|
+ NoTimer
|
|
|
+ };
|
|
|
+
|
|
|
+ bool mDebuggerRegistered;
|
|
|
+ WorkerDebugger* mDebugger;
|
|
|
+
|
|
|
+- Queue<WorkerControlRunnable*, 4> mControlQueue;
|
|
|
+- Queue<WorkerRunnable*, 4> mDebuggerQueue;
|
|
|
++ workers::Queue<WorkerControlRunnable*, 4> mControlQueue;
|
|
|
++ workers::Queue<WorkerRunnable*, 4> mDebuggerQueue;
|
|
|
+
|
|
|
+ // Touched on multiple threads, protected with mMutex.
|
|
|
+ JSContext* mJSContext;
|
|
|
+ RefPtr<WorkerThread> mThread;
|
|
|
+ PRThread* mPRThread;
|
|
|
+
|
|
|
+ // Things touched on worker thread only.
|
|
|
+ RefPtr<WorkerGlobalScope> mScope;
|
|
|
+@@ -1002,26 +997,26 @@ public:
|
|
|
+ // ServiceWorker and the loading principal for any other type.
|
|
|
+ static void
|
|
|
+ OverrideLoadInfoLoadGroup(WorkerLoadInfo& aLoadInfo,
|
|
|
+ nsIPrincipal* aPrincipal);
|
|
|
+
|
|
|
+ bool
|
|
|
+ IsDebuggerRegistered()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ // No need to lock here since this is only ever modified by the same thread.
|
|
|
+ return mDebuggerRegistered;
|
|
|
+ }
|
|
|
+
|
|
|
+ void
|
|
|
+ SetIsDebuggerRegistered(bool aDebuggerRegistered)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ MutexAutoLock lock(mMutex);
|
|
|
+
|
|
|
+ MOZ_ASSERT(mDebuggerRegistered != aDebuggerRegistered);
|
|
|
+ mDebuggerRegistered = aDebuggerRegistered;
|
|
|
+
|
|
|
+ mCondVar.Notify();
|
|
|
+ }
|
|
|
+@@ -1038,26 +1033,26 @@ public:
|
|
|
+ while (mDebuggerRegistered != aDebuggerRegistered) {
|
|
|
+ mCondVar.Wait();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ WorkerDebugger*
|
|
|
+ Debugger() const
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ MOZ_ASSERT(mDebugger);
|
|
|
+ return mDebugger;
|
|
|
+ }
|
|
|
+
|
|
|
+ void
|
|
|
+ SetDebugger(WorkerDebugger* aDebugger)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ MOZ_ASSERT(mDebugger != aDebugger);
|
|
|
+ mDebugger = aDebugger;
|
|
|
+ }
|
|
|
+
|
|
|
+ JS::UniqueChars
|
|
|
+ AdoptDefaultLocale()
|
|
|
+ {
|
|
|
+@@ -1565,11 +1560,12 @@ public:
|
|
|
+ nsIEventTarget*
|
|
|
+ GetEventTarget() const
|
|
|
+ {
|
|
|
+ // This can be null if CreateNewSyncLoop() fails.
|
|
|
+ return mTarget;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+-END_WORKERS_NAMESPACE
|
|
|
++} // dom namespace
|
|
|
++} // mozilla namespace
|
|
|
+
|
|
|
+ #endif /* mozilla_dom_workers_workerprivate_h__ */
|
|
|
+diff --git a/dom/workers/WorkerRunnable.cpp b/dom/workers/WorkerRunnable.cpp
|
|
|
+--- a/dom/workers/WorkerRunnable.cpp
|
|
|
++++ b/dom/workers/WorkerRunnable.cpp
|
|
|
+@@ -21,18 +21,16 @@
|
|
|
+ #include "js/Value.h"
|
|
|
+
|
|
|
+ #include "WorkerPrivate.h"
|
|
|
+ #include "WorkerScope.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ namespace {
|
|
|
+
|
|
|
+ const nsIID kWorkerRunnableIID = {
|
|
|
+ 0x320cc0b5, 0xef12, 0x4084, { 0x88, 0x6e, 0xca, 0x6a, 0x81, 0xe4, 0x1d, 0x68 }
|
|
|
+ };
|
|
|
+
|
|
|
+ } // namespace
|
|
|
+
|
|
|
+@@ -470,17 +468,17 @@ MainThreadWorkerSyncRunnable::PostDispat
|
|
|
+ }
|
|
|
+
|
|
|
+ MainThreadStopSyncLoopRunnable::MainThreadStopSyncLoopRunnable(
|
|
|
+ WorkerPrivate* aWorkerPrivate,
|
|
|
+ already_AddRefed<nsIEventTarget>&& aSyncLoopTarget,
|
|
|
+ bool aResult)
|
|
|
+ : WorkerSyncRunnable(aWorkerPrivate, Move(aSyncLoopTarget)), mResult(aResult)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ #ifdef DEBUG
|
|
|
+ mWorkerPrivate->AssertValidSyncLoop(mSyncLoopTarget);
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+
|
|
|
+ nsresult
|
|
|
+ MainThreadStopSyncLoopRunnable::Cancel()
|
|
|
+ {
|
|
|
+@@ -560,17 +558,17 @@ WorkerControlRunnable::DispatchInternal(
|
|
|
+ return NS_SUCCEEDED(mWorkerPrivate->DispatchToMainThread(runnable.forget()));
|
|
|
+ }
|
|
|
+
|
|
|
+ NS_IMPL_ISUPPORTS_INHERITED0(WorkerControlRunnable, WorkerRunnable)
|
|
|
+
|
|
|
+ WorkerMainThreadRunnable::WorkerMainThreadRunnable(
|
|
|
+ WorkerPrivate* aWorkerPrivate,
|
|
|
+ const nsACString& aTelemetryKey)
|
|
|
+- : mozilla::Runnable("dom::workers::WorkerMainThreadRunnable")
|
|
|
++ : mozilla::Runnable("dom::WorkerMainThreadRunnable")
|
|
|
+ , mWorkerPrivate(aWorkerPrivate)
|
|
|
+ , mTelemetryKey(aTelemetryKey)
|
|
|
+ {
|
|
|
+ mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
+ }
|
|
|
+
|
|
|
+ void
|
|
|
+ WorkerMainThreadRunnable::Dispatch(WorkerStatus aFailStatus,
|
|
|
+@@ -604,17 +602,17 @@ WorkerMainThreadRunnable::Dispatch(Worke
|
|
|
+ if (!success) {
|
|
|
+ aRv.ThrowUncatchableException();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ NS_IMETHODIMP
|
|
|
+ WorkerMainThreadRunnable::Run()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ bool runResult = MainThreadRun();
|
|
|
+
|
|
|
+ RefPtr<MainThreadStopSyncLoopRunnable> response =
|
|
|
+ new MainThreadStopSyncLoopRunnable(mWorkerPrivate,
|
|
|
+ mSyncLoopTarget.forget(),
|
|
|
+ runResult);
|
|
|
+
|
|
|
+@@ -664,17 +662,17 @@ WorkerSameThreadRunnable::PostDispatch(W
|
|
|
+ // Should never fail since if this thread is still running, so should the
|
|
|
+ // parent and it should be able to process a control runnable.
|
|
|
+ MOZ_ASSERT(willIncrement);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ WorkerProxyToMainThreadRunnable::WorkerProxyToMainThreadRunnable(
|
|
|
+ WorkerPrivate* aWorkerPrivate)
|
|
|
+- : mozilla::Runnable("dom::workers::WorkerProxyToMainThreadRunnable")
|
|
|
++ : mozilla::Runnable("dom::WorkerProxyToMainThreadRunnable")
|
|
|
+ , mWorkerPrivate(aWorkerPrivate)
|
|
|
+ {
|
|
|
+ MOZ_ASSERT(mWorkerPrivate);
|
|
|
+ mWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
+ }
|
|
|
+
|
|
|
+ WorkerProxyToMainThreadRunnable::~WorkerProxyToMainThreadRunnable()
|
|
|
+ {}
|
|
|
+@@ -696,17 +694,17 @@ WorkerProxyToMainThreadRunnable::Dispatc
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ NS_IMETHODIMP
|
|
|
+ WorkerProxyToMainThreadRunnable::Run()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ RunOnMainThread();
|
|
|
+ PostDispatchOnMainThread();
|
|
|
+ return NS_OK;
|
|
|
+ }
|
|
|
+
|
|
|
+ void
|
|
|
+ WorkerProxyToMainThreadRunnable::PostDispatchOnMainThread()
|
|
|
+ {
|
|
|
+@@ -728,17 +726,17 @@ WorkerProxyToMainThreadRunnable::PostDis
|
|
|
+ nsresult
|
|
|
+ Cancel() override
|
|
|
+ {
|
|
|
+ WorkerRun(nullptr, mWorkerPrivate);
|
|
|
+ return MainThreadWorkerControlRunnable::Cancel();
|
|
|
+ }
|
|
|
+
|
|
|
+ virtual bool
|
|
|
+- WorkerRun(JSContext* aCx, workers::WorkerPrivate* aWorkerPrivate) override
|
|
|
++ WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
|
|
|
+ {
|
|
|
+ MOZ_ASSERT(aWorkerPrivate);
|
|
|
+ aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
+
|
|
|
+ if (mRunnable) {
|
|
|
+ mRunnable->RunBackOnWorkerThreadForCleanup();
|
|
|
+
|
|
|
+ // Let's release the worker thread.
|
|
|
+diff --git a/dom/workers/WorkerRunnable.h b/dom/workers/WorkerRunnable.h
|
|
|
+--- a/dom/workers/WorkerRunnable.h
|
|
|
++++ b/dom/workers/WorkerRunnable.h
|
|
|
+@@ -2,37 +2,35 @@
|
|
|
+ /* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
+ /* 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/. */
|
|
|
+
|
|
|
+ #ifndef mozilla_dom_workers_workerrunnable_h__
|
|
|
+ #define mozilla_dom_workers_workerrunnable_h__
|
|
|
+
|
|
|
+-#include "WorkerCommon.h"
|
|
|
+-#include "WorkerHolder.h"
|
|
|
++#include "mozilla/dom/workers/WorkerCommon.h"
|
|
|
++#include "mozilla/dom/WorkerHolder.h"
|
|
|
+
|
|
|
+ #include "nsICancelableRunnable.h"
|
|
|
+
|
|
|
+ #include "mozilla/Atomics.h"
|
|
|
+ #include "nsISupportsImpl.h"
|
|
|
+ #include "nsThreadUtils.h" /* nsRunnable */
|
|
|
+
|
|
|
+ struct JSContext;
|
|
|
+ class nsIEventTarget;
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+
|
|
|
+ class ErrorResult;
|
|
|
+
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+
|
|
|
+ // Use this runnable to communicate from the worker to its parent or vice-versa.
|
|
|
+ // The busy count must be taken into consideration and declared at construction
|
|
|
+ // time.
|
|
|
+ class WorkerRunnable : public nsIRunnable,
|
|
|
+ public nsICancelableRunnable
|
|
|
+ {
|
|
|
+ public:
|
|
|
+@@ -49,17 +47,17 @@ public:
|
|
|
+ // Target the thread where the worker event loop runs. The busy count will
|
|
|
+ // not be modified in any way. Besides worker-internal runnables this is
|
|
|
+ // almost always the wrong choice.
|
|
|
+ WorkerThreadUnchangedBusyCount
|
|
|
+ };
|
|
|
+
|
|
|
+ protected:
|
|
|
+ // The WorkerPrivate that this runnable is associated with.
|
|
|
+- workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ WorkerPrivate* mWorkerPrivate;
|
|
|
+
|
|
|
+ // See above.
|
|
|
+ TargetAndBusyBehavior mBehavior;
|
|
|
+
|
|
|
+ // It's unclear whether or not Cancel() is supposed to work when called on any
|
|
|
+ // thread. To be safe we're using an atomic but it's likely overkill.
|
|
|
+ Atomic<uint32_t> mCanceled;
|
|
|
+
|
|
|
+@@ -89,17 +87,17 @@ public:
|
|
|
+ {
|
|
|
+ return mCanceled != 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ static WorkerRunnable*
|
|
|
+ FromRunnable(nsIRunnable* aRunnable);
|
|
|
+
|
|
|
+ protected:
|
|
|
+- WorkerRunnable(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ WorkerRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
+ TargetAndBusyBehavior aBehavior = WorkerThreadModifyBusyCount)
|
|
|
+ #ifdef DEBUG
|
|
|
+ ;
|
|
|
+ #else
|
|
|
+ : mWorkerPrivate(aWorkerPrivate), mBehavior(aBehavior), mCanceled(0),
|
|
|
+ mCallingCancelWithinRun(false)
|
|
|
+ { }
|
|
|
+ #endif
|
|
|
+@@ -116,32 +114,32 @@ protected:
|
|
|
+ nsIGlobalObject*
|
|
|
+ DefaultGlobalObject() const;
|
|
|
+
|
|
|
+ // By default asserts that Dispatch() is being called on the right thread
|
|
|
+ // (ParentThread if |mTarget| is WorkerThread, or WorkerThread otherwise).
|
|
|
+ // Also increments the busy count of |mWorkerPrivate| if targeting the
|
|
|
+ // WorkerThread.
|
|
|
+ virtual bool
|
|
|
+- PreDispatch(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ PreDispatch(WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ // By default asserts that Dispatch() is being called on the right thread
|
|
|
+ // (ParentThread if |mTarget| is WorkerThread, or WorkerThread otherwise).
|
|
|
+ virtual void
|
|
|
+- PostDispatch(workers::WorkerPrivate* aWorkerPrivate, bool aDispatchResult);
|
|
|
++ PostDispatch(WorkerPrivate* aWorkerPrivate, bool aDispatchResult);
|
|
|
+
|
|
|
+ // May be implemented by subclasses if desired if they need to do some sort of
|
|
|
+ // setup before we try to set up our JSContext and compartment for real.
|
|
|
+ // Typically the only thing that should go in here is creation of the worker's
|
|
|
+ // global.
|
|
|
+ //
|
|
|
+ // If false is returned, WorkerRun will not be called at all. PostRun will
|
|
|
+ // still be called, with false passed for aRunResult.
|
|
|
+ virtual bool
|
|
|
+- PreRun(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ PreRun(WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ // Must be implemented by subclasses. Called on the target thread. The return
|
|
|
+ // value will be passed to PostRun(). The JSContext passed in here comes from
|
|
|
+ // an AutoJSAPI (or AutoEntryScript) that we set up on the stack. If
|
|
|
+ // mBehavior is ParentThreadUnchangedBusyCount, it is in the compartment of
|
|
|
+ // mWorkerPrivate's reflector (i.e. the worker object in the parent thread),
|
|
|
+ // unless that reflector is null, in which case it's in the compartment of the
|
|
|
+ // parent global (which is the compartment reflector would have been in), or
|
|
|
+@@ -154,139 +152,139 @@ protected:
|
|
|
+ // sandbox compartment!). If aCx wasn't in a compartment to start with, aCx
|
|
|
+ // will be in either the debugger global's compartment or the worker's
|
|
|
+ // global's compartment depending on whether IsDebuggerRunnable() is true.
|
|
|
+ //
|
|
|
+ // Immediately after WorkerRun returns, the caller will assert that either it
|
|
|
+ // returns false or there is no exception pending on aCx. Then it will report
|
|
|
+ // any pending exceptions on aCx.
|
|
|
+ virtual bool
|
|
|
+- WorkerRun(JSContext* aCx, workers::WorkerPrivate* aWorkerPrivate) = 0;
|
|
|
++ WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) = 0;
|
|
|
+
|
|
|
+ // By default asserts that Run() (and WorkerRun()) were called on the correct
|
|
|
+ // thread. Also sends an asynchronous message to the ParentThread if the
|
|
|
+ // busy count was previously modified in PreDispatch().
|
|
|
+ //
|
|
|
+ // The aCx passed here is the same one as was passed to WorkerRun and is
|
|
|
+ // still in the same compartment. PostRun implementations must NOT leave an
|
|
|
+ // exception on the JSContext and must not run script, because the incoming
|
|
|
+ // JSContext may be in the null compartment.
|
|
|
+ virtual void
|
|
|
+- PostRun(JSContext* aCx, workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ PostRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
|
|
|
+ bool aRunResult);
|
|
|
+
|
|
|
+ virtual bool
|
|
|
+ DispatchInternal();
|
|
|
+
|
|
|
+ // Calling Run() directly is not supported. Just call Dispatch() and
|
|
|
+ // WorkerRun() will be called on the correct thread automatically.
|
|
|
+ NS_DECL_NSIRUNNABLE
|
|
|
+ };
|
|
|
+
|
|
|
+ // This runnable is used to send a message to a worker debugger.
|
|
|
+ class WorkerDebuggerRunnable : public WorkerRunnable
|
|
|
+ {
|
|
|
+ protected:
|
|
|
+- explicit WorkerDebuggerRunnable(workers::WorkerPrivate* aWorkerPrivate)
|
|
|
++ explicit WorkerDebuggerRunnable(WorkerPrivate* aWorkerPrivate)
|
|
|
+ : WorkerRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ virtual ~WorkerDebuggerRunnable()
|
|
|
+ { }
|
|
|
+
|
|
|
+ private:
|
|
|
+ virtual bool
|
|
|
+ IsDebuggerRunnable() const override
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ virtual bool
|
|
|
+- PreDispatch(workers::WorkerPrivate* aWorkerPrivate) override final
|
|
|
++ PreDispatch(WorkerPrivate* aWorkerPrivate) override final
|
|
|
+ {
|
|
|
+ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ virtual void
|
|
|
+- PostDispatch(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ PostDispatch(WorkerPrivate* aWorkerPrivate,
|
|
|
+ bool aDispatchResult) override;
|
|
|
+ };
|
|
|
+
|
|
|
+ // This runnable is used to send a message directly to a worker's sync loop.
|
|
|
+ class WorkerSyncRunnable : public WorkerRunnable
|
|
|
+ {
|
|
|
+ protected:
|
|
|
+ nsCOMPtr<nsIEventTarget> mSyncLoopTarget;
|
|
|
+
|
|
|
+ // Passing null for aSyncLoopTarget is allowed and will result in the behavior
|
|
|
+ // of a normal WorkerRunnable.
|
|
|
+- WorkerSyncRunnable(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ WorkerSyncRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
+ nsIEventTarget* aSyncLoopTarget);
|
|
|
+
|
|
|
+- WorkerSyncRunnable(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ WorkerSyncRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
+ already_AddRefed<nsIEventTarget>&& aSyncLoopTarget);
|
|
|
+
|
|
|
+ virtual ~WorkerSyncRunnable();
|
|
|
+
|
|
|
+ virtual bool
|
|
|
+ DispatchInternal() override;
|
|
|
+ };
|
|
|
+
|
|
|
+ // This runnable is identical to WorkerSyncRunnable except it is meant to be
|
|
|
+ // created on and dispatched from the main thread only. Its WorkerRun/PostRun
|
|
|
+ // will run on the worker thread.
|
|
|
+ class MainThreadWorkerSyncRunnable : public WorkerSyncRunnable
|
|
|
+ {
|
|
|
+ protected:
|
|
|
+ // Passing null for aSyncLoopTarget is allowed and will result in the behavior
|
|
|
+ // of a normal WorkerRunnable.
|
|
|
+- MainThreadWorkerSyncRunnable(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ MainThreadWorkerSyncRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
+ nsIEventTarget* aSyncLoopTarget)
|
|
|
+ : WorkerSyncRunnable(aWorkerPrivate, aSyncLoopTarget)
|
|
|
+ {
|
|
|
+ workers::AssertIsOnMainThread();
|
|
|
+ }
|
|
|
+
|
|
|
+- MainThreadWorkerSyncRunnable(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ MainThreadWorkerSyncRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
+ already_AddRefed<nsIEventTarget>&& aSyncLoopTarget)
|
|
|
+ : WorkerSyncRunnable(aWorkerPrivate, Move(aSyncLoopTarget))
|
|
|
+ {
|
|
|
+ workers::AssertIsOnMainThread();
|
|
|
+ }
|
|
|
+
|
|
|
+ virtual ~MainThreadWorkerSyncRunnable()
|
|
|
+ { }
|
|
|
+
|
|
|
+ private:
|
|
|
+ virtual bool
|
|
|
+- PreDispatch(workers::WorkerPrivate* aWorkerPrivate) override
|
|
|
++ PreDispatch(WorkerPrivate* aWorkerPrivate) override
|
|
|
+ {
|
|
|
+ workers::AssertIsOnMainThread();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ virtual void
|
|
|
+- PostDispatch(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ PostDispatch(WorkerPrivate* aWorkerPrivate,
|
|
|
+ bool aDispatchResult) override;
|
|
|
+ };
|
|
|
+
|
|
|
+ // This runnable is processed as soon as it is received by the worker,
|
|
|
+ // potentially running before previously queued runnables and perhaps even with
|
|
|
+ // other JS code executing on the stack. These runnables must not alter the
|
|
|
+ // state of the JS runtime and should only twiddle state values. The busy count
|
|
|
+ // is never modified.
|
|
|
+ class WorkerControlRunnable : public WorkerRunnable
|
|
|
+ {
|
|
|
+- friend class workers::WorkerPrivate;
|
|
|
++ friend class WorkerPrivate;
|
|
|
+
|
|
|
+ protected:
|
|
|
+- WorkerControlRunnable(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ WorkerControlRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
+ TargetAndBusyBehavior aBehavior = WorkerThreadModifyBusyCount)
|
|
|
+ #ifdef DEBUG
|
|
|
+ ;
|
|
|
+ #else
|
|
|
+ : WorkerRunnable(aWorkerPrivate, aBehavior)
|
|
|
+ { }
|
|
|
+ #endif
|
|
|
+
|
|
|
+@@ -298,115 +296,115 @@ protected:
|
|
|
+
|
|
|
+ public:
|
|
|
+ NS_DECL_ISUPPORTS_INHERITED
|
|
|
+
|
|
|
+ private:
|
|
|
+ virtual bool
|
|
|
+ DispatchInternal() override;
|
|
|
+
|
|
|
+- // Should only be called by workers::WorkerPrivate::DoRunLoop.
|
|
|
++ // Should only be called by WorkerPrivate::DoRunLoop.
|
|
|
+ using WorkerRunnable::Cancel;
|
|
|
+ };
|
|
|
+
|
|
|
+ // A convenience class for WorkerRunnables that are originated on the main
|
|
|
+ // thread.
|
|
|
+ class MainThreadWorkerRunnable : public WorkerRunnable
|
|
|
+ {
|
|
|
+ protected:
|
|
|
+- explicit MainThreadWorkerRunnable(workers::WorkerPrivate* aWorkerPrivate)
|
|
|
++ explicit MainThreadWorkerRunnable(WorkerPrivate* aWorkerPrivate)
|
|
|
+ : WorkerRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount)
|
|
|
+ {
|
|
|
+ workers::AssertIsOnMainThread();
|
|
|
+ }
|
|
|
+
|
|
|
+ virtual ~MainThreadWorkerRunnable()
|
|
|
+ {}
|
|
|
+
|
|
|
+ virtual bool
|
|
|
+- PreDispatch(workers::WorkerPrivate* aWorkerPrivate) override
|
|
|
++ PreDispatch(WorkerPrivate* aWorkerPrivate) override
|
|
|
+ {
|
|
|
+ workers::AssertIsOnMainThread();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ virtual void
|
|
|
+- PostDispatch(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ PostDispatch(WorkerPrivate* aWorkerPrivate,
|
|
|
+ bool aDispatchResult) override
|
|
|
+ {
|
|
|
+ workers::AssertIsOnMainThread();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // A convenience class for WorkerControlRunnables that originate on the main
|
|
|
+ // thread.
|
|
|
+ class MainThreadWorkerControlRunnable : public WorkerControlRunnable
|
|
|
+ {
|
|
|
+ protected:
|
|
|
+- explicit MainThreadWorkerControlRunnable(workers::WorkerPrivate* aWorkerPrivate)
|
|
|
++ explicit MainThreadWorkerControlRunnable(WorkerPrivate* aWorkerPrivate)
|
|
|
+ : WorkerControlRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount)
|
|
|
+ { }
|
|
|
+
|
|
|
+ virtual ~MainThreadWorkerControlRunnable()
|
|
|
+ { }
|
|
|
+
|
|
|
+ virtual bool
|
|
|
+- PreDispatch(workers::WorkerPrivate* aWorkerPrivate) override
|
|
|
++ PreDispatch(WorkerPrivate* aWorkerPrivate) override
|
|
|
+ {
|
|
|
+ workers::AssertIsOnMainThread();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ virtual void
|
|
|
+- PostDispatch(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ PostDispatch(WorkerPrivate* aWorkerPrivate,
|
|
|
+ bool aDispatchResult) override
|
|
|
+ {
|
|
|
+ workers::AssertIsOnMainThread();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // A WorkerRunnable that should be dispatched from the worker to itself for
|
|
|
+ // async tasks. This will increment the busy count PostDispatch() (only if
|
|
|
+ // dispatch was successful) and decrement it in PostRun().
|
|
|
+ //
|
|
|
+ // Async tasks will almost always want to use this since
|
|
|
+ // a WorkerSameThreadRunnable keeps the Worker from being GCed.
|
|
|
+ class WorkerSameThreadRunnable : public WorkerRunnable
|
|
|
+ {
|
|
|
+ protected:
|
|
|
+- explicit WorkerSameThreadRunnable(workers::WorkerPrivate* aWorkerPrivate)
|
|
|
++ explicit WorkerSameThreadRunnable(WorkerPrivate* aWorkerPrivate)
|
|
|
+ : WorkerRunnable(aWorkerPrivate, WorkerThreadModifyBusyCount)
|
|
|
+ { }
|
|
|
+
|
|
|
+ virtual ~WorkerSameThreadRunnable()
|
|
|
+ { }
|
|
|
+
|
|
|
+ virtual bool
|
|
|
+- PreDispatch(workers::WorkerPrivate* aWorkerPrivate) override;
|
|
|
++ PreDispatch(WorkerPrivate* aWorkerPrivate) override;
|
|
|
+
|
|
|
+ virtual void
|
|
|
+- PostDispatch(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ PostDispatch(WorkerPrivate* aWorkerPrivate,
|
|
|
+ bool aDispatchResult) override;
|
|
|
+
|
|
|
+ // We just delegate PostRun to WorkerRunnable, since it does exactly
|
|
|
+ // what we want.
|
|
|
+ };
|
|
|
+
|
|
|
+ // Base class for the runnable objects, which makes a synchronous call to
|
|
|
+ // dispatch the tasks from the worker thread to the main thread.
|
|
|
+ //
|
|
|
+ // Note that the derived class must override MainThreadRun.
|
|
|
+ class WorkerMainThreadRunnable : public Runnable
|
|
|
+ {
|
|
|
+ protected:
|
|
|
+- workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ WorkerPrivate* mWorkerPrivate;
|
|
|
+ nsCOMPtr<nsIEventTarget> mSyncLoopTarget;
|
|
|
+ const nsCString mTelemetryKey;
|
|
|
+
|
|
|
+- explicit WorkerMainThreadRunnable(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ explicit WorkerMainThreadRunnable(WorkerPrivate* aWorkerPrivate,
|
|
|
+ const nsACString& aTelemetryKey);
|
|
|
+ ~WorkerMainThreadRunnable() {}
|
|
|
+
|
|
|
+ virtual bool MainThreadRun() = 0;
|
|
|
+
|
|
|
+ public:
|
|
|
+ // Dispatch the runnable to the main thread. If dispatch to main thread
|
|
|
+ // fails, or if the worker is in a state equal or greater of aFailStatus, an
|
|
|
+@@ -427,17 +425,17 @@ private:
|
|
|
+ // says, only to release resources, no JS has to be executed, no timers, or
|
|
|
+ // other things. The reason of such limitations is that, in order to execute
|
|
|
+ // this method in any condition (also when the worker is shutting down), a
|
|
|
+ // Control Runnable is used, and, this could generate a reordering of existing
|
|
|
+ // runnables.
|
|
|
+ class WorkerProxyToMainThreadRunnable : public Runnable
|
|
|
+ {
|
|
|
+ protected:
|
|
|
+- explicit WorkerProxyToMainThreadRunnable(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ explicit WorkerProxyToMainThreadRunnable(WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ virtual ~WorkerProxyToMainThreadRunnable();
|
|
|
+
|
|
|
+ // First this method is called on the main-thread.
|
|
|
+ virtual void RunOnMainThread() = 0;
|
|
|
+
|
|
|
+ // After this second method is called on the worker-thread.
|
|
|
+ virtual void RunBackOnWorkerThreadForCleanup() = 0;
|
|
|
+@@ -449,33 +447,33 @@ private:
|
|
|
+ NS_IMETHOD Run() override;
|
|
|
+
|
|
|
+ void PostDispatchOnMainThread();
|
|
|
+
|
|
|
+ bool HoldWorker();
|
|
|
+ void ReleaseWorker();
|
|
|
+
|
|
|
+ protected:
|
|
|
+- workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ WorkerPrivate* mWorkerPrivate;
|
|
|
+ UniquePtr<WorkerHolder> mWorkerHolder;
|
|
|
+ };
|
|
|
+
|
|
|
+ // Class for checking API exposure. This totally violates the "MUST" in the
|
|
|
+ // comments on WorkerMainThreadRunnable::Dispatch, because API exposure checks
|
|
|
+ // can't throw. Maybe we should change it so they _could_ throw. But for now
|
|
|
+ // we are bad people and should be ashamed of ourselves. Let's hope none of
|
|
|
+ // them happen while a worker is shutting down.
|
|
|
+ //
|
|
|
+ // Do NOT copy what this class is doing elsewhere. Just don't.
|
|
|
+ class WorkerCheckAPIExposureOnMainThreadRunnable
|
|
|
+ : public WorkerMainThreadRunnable
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ explicit
|
|
|
+- WorkerCheckAPIExposureOnMainThreadRunnable(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ WorkerCheckAPIExposureOnMainThreadRunnable(WorkerPrivate* aWorkerPrivate);
|
|
|
+ virtual
|
|
|
+ ~WorkerCheckAPIExposureOnMainThreadRunnable();
|
|
|
+
|
|
|
+ // Returns whether the dispatch succeeded. If this returns false, the API
|
|
|
+ // should not be exposed.
|
|
|
+ bool Dispatch();
|
|
|
+ };
|
|
|
+
|
|
|
+@@ -485,43 +483,43 @@ public:
|
|
|
+ // in any way.
|
|
|
+ class MainThreadStopSyncLoopRunnable : public WorkerSyncRunnable
|
|
|
+ {
|
|
|
+ bool mResult;
|
|
|
+
|
|
|
+ public:
|
|
|
+ // Passing null for aSyncLoopTarget is not allowed.
|
|
|
+ MainThreadStopSyncLoopRunnable(
|
|
|
+- workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ WorkerPrivate* aWorkerPrivate,
|
|
|
+ already_AddRefed<nsIEventTarget>&& aSyncLoopTarget,
|
|
|
+ bool aResult);
|
|
|
+
|
|
|
+ // By default StopSyncLoopRunnables cannot be canceled since they could leave
|
|
|
+ // a sync loop spinning forever.
|
|
|
+ nsresult
|
|
|
+ Cancel() override;
|
|
|
+
|
|
|
+ protected:
|
|
|
+ virtual ~MainThreadStopSyncLoopRunnable()
|
|
|
+ { }
|
|
|
+
|
|
|
+ private:
|
|
|
+ virtual bool
|
|
|
+- PreDispatch(workers::WorkerPrivate* aWorkerPrivate) override final
|
|
|
++ PreDispatch(WorkerPrivate* aWorkerPrivate) override final
|
|
|
+ {
|
|
|
+ workers::AssertIsOnMainThread();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ virtual void
|
|
|
+- PostDispatch(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ PostDispatch(WorkerPrivate* aWorkerPrivate,
|
|
|
+ bool aDispatchResult) override;
|
|
|
+
|
|
|
+ virtual bool
|
|
|
+- WorkerRun(JSContext* aCx, workers::WorkerPrivate* aWorkerPrivate) override;
|
|
|
++ WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override;
|
|
|
+
|
|
|
+ virtual bool
|
|
|
+ DispatchInternal() override final;
|
|
|
+ };
|
|
|
+
|
|
|
+ } // dom namespace
|
|
|
+ } // mozilla namespace
|
|
|
+
|
|
|
+diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp
|
|
|
+--- a/dom/workers/WorkerScope.cpp
|
|
|
++++ b/dom/workers/WorkerScope.cpp
|
|
|
+@@ -52,24 +52,24 @@
|
|
|
+ #include "mozilla/dom/ServiceWorkerRegistration.h"
|
|
|
+
|
|
|
+ #ifdef XP_WIN
|
|
|
+ #undef PostMessage
|
|
|
+ #endif
|
|
|
+
|
|
|
+ extern already_AddRefed<nsIScriptTimeoutHandler>
|
|
|
+ NS_CreateJSTimeoutHandler(JSContext* aCx,
|
|
|
+- mozilla::dom::workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ mozilla::dom::WorkerPrivate* aWorkerPrivate,
|
|
|
+ mozilla::dom::Function& aFunction,
|
|
|
+ const mozilla::dom::Sequence<JS::Value>& aArguments,
|
|
|
+ mozilla::ErrorResult& aError);
|
|
|
+
|
|
|
+ extern already_AddRefed<nsIScriptTimeoutHandler>
|
|
|
+ NS_CreateJSTimeoutHandler(JSContext* aCx,
|
|
|
+- mozilla::dom::workers::WorkerPrivate* aWorkerPrivate,
|
|
|
++ mozilla::dom::WorkerPrivate* aWorkerPrivate,
|
|
|
+ const nsAString& aExpression);
|
|
|
+
|
|
|
+ using namespace mozilla;
|
|
|
+ using namespace mozilla::dom;
|
|
|
+ USING_WORKERS_NAMESPACE
|
|
|
+
|
|
|
+ using mozilla::dom::cache::CacheStorage;
|
|
|
+ using mozilla::ipc::PrincipalInfo;
|
|
|
+diff --git a/dom/workers/WorkerScope.h b/dom/workers/WorkerScope.h
|
|
|
+--- a/dom/workers/WorkerScope.h
|
|
|
++++ b/dom/workers/WorkerScope.h
|
|
|
+@@ -2,17 +2,17 @@
|
|
|
+ /* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
+ /* 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/. */
|
|
|
+
|
|
|
+ #ifndef mozilla_dom_workerscope_h__
|
|
|
+ #define mozilla_dom_workerscope_h__
|
|
|
+
|
|
|
+-#include "WorkerCommon.h"
|
|
|
++#include "mozilla/dom/workers/WorkerCommon.h"
|
|
|
+ #include "mozilla/DOMEventTargetHelper.h"
|
|
|
+ #include "mozilla/dom/Headers.h"
|
|
|
+ #include "mozilla/dom/RequestBinding.h"
|
|
|
+ #include "nsWeakReference.h"
|
|
|
+ #include "mozilla/dom/ImageBitmapSource.h"
|
|
|
+
|
|
|
+ #ifdef XP_WIN
|
|
|
+ #undef PostMessage
|
|
|
+@@ -32,30 +32,25 @@ class Function;
|
|
|
+ class IDBFactory;
|
|
|
+ enum class ImageBitmapFormat : uint8_t;
|
|
|
+ class Performance;
|
|
|
+ class Promise;
|
|
|
+ class RequestOrUSVString;
|
|
|
+ class ServiceWorkerRegistration;
|
|
|
+ class WorkerLocation;
|
|
|
+ class WorkerNavigator;
|
|
|
++class WorkerPrivate;
|
|
|
+ enum class CallerType : uint32_t;
|
|
|
+
|
|
|
+ namespace cache {
|
|
|
+
|
|
|
+ class CacheStorage;
|
|
|
+
|
|
|
+ } // namespace cache
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+-
|
|
|
+-class WorkerPrivate;
|
|
|
+-
|
|
|
+-} // namespace workers
|
|
|
+-
|
|
|
+ class WorkerGlobalScope : public DOMEventTargetHelper,
|
|
|
+ public nsIGlobalObject,
|
|
|
+ public nsSupportsWeakReference
|
|
|
+ {
|
|
|
+ typedef mozilla::dom::IDBFactory IDBFactory;
|
|
|
+
|
|
|
+ RefPtr<Console> mConsole;
|
|
|
+ RefPtr<Crypto> mCrypto;
|
|
|
+@@ -64,17 +59,16 @@ class WorkerGlobalScope : public DOMEven
|
|
|
+ RefPtr<Performance> mPerformance;
|
|
|
+ RefPtr<IDBFactory> mIndexedDB;
|
|
|
+ RefPtr<cache::CacheStorage> mCacheStorage;
|
|
|
+ nsCOMPtr<nsISerialEventTarget> mSerialEventTarget;
|
|
|
+
|
|
|
+ uint32_t mWindowInteractionsAllowed;
|
|
|
+
|
|
|
+ protected:
|
|
|
+- typedef mozilla::dom::workers::WorkerPrivate WorkerPrivate;
|
|
|
+ WorkerPrivate* mWorkerPrivate;
|
|
|
+
|
|
|
+ explicit WorkerGlobalScope(WorkerPrivate* aWorkerPrivate);
|
|
|
+ virtual ~WorkerGlobalScope();
|
|
|
+
|
|
|
+ public:
|
|
|
+ virtual JSObject*
|
|
|
+ WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
|
|
+@@ -350,18 +344,16 @@ public:
|
|
|
+ const dom::AddEventListenerOptionsOrBoolean& aOptions,
|
|
|
+ const dom::Nullable<bool>& aWantsUntrusted,
|
|
|
+ ErrorResult& aRv) override;
|
|
|
+ };
|
|
|
+
|
|
|
+ class WorkerDebuggerGlobalScope final : public DOMEventTargetHelper,
|
|
|
+ public nsIGlobalObject
|
|
|
+ {
|
|
|
+- typedef mozilla::dom::workers::WorkerPrivate WorkerPrivate;
|
|
|
+-
|
|
|
+ WorkerPrivate* mWorkerPrivate;
|
|
|
+ RefPtr<Console> mConsole;
|
|
|
+ nsCOMPtr<nsISerialEventTarget> mSerialEventTarget;
|
|
|
+
|
|
|
+ public:
|
|
|
+ explicit WorkerDebuggerGlobalScope(WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ NS_DECL_ISUPPORTS_INHERITED
|
|
|
+diff --git a/dom/workers/WorkerThread.cpp b/dom/workers/WorkerThread.cpp
|
|
|
+--- a/dom/workers/WorkerThread.cpp
|
|
|
++++ b/dom/workers/WorkerThread.cpp
|
|
|
+@@ -14,20 +14,20 @@
|
|
|
+ #include "WorkerPrivate.h"
|
|
|
+ #include "WorkerRunnable.h"
|
|
|
+
|
|
|
+ #ifdef DEBUG
|
|
|
+ #include "nsThreadManager.h"
|
|
|
+ #endif
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+-namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-using namespace mozilla::ipc;
|
|
|
++using namespace ipc;
|
|
|
++
|
|
|
++namespace dom {
|
|
|
+
|
|
|
+ namespace {
|
|
|
+
|
|
|
+ // The C stack size. We use the same stack size on all platforms for
|
|
|
+ // consistency.
|
|
|
+ const uint32_t kWorkerStackSize = 256 * sizeof(size_t) * 1024;
|
|
|
+
|
|
|
+ } // namespace
|
|
|
+diff --git a/dom/workers/WorkerThread.h b/dom/workers/WorkerThread.h
|
|
|
+--- a/dom/workers/WorkerThread.h
|
|
|
++++ b/dom/workers/WorkerThread.h
|
|
|
+@@ -15,46 +15,46 @@
|
|
|
+ #include "nsThread.h"
|
|
|
+
|
|
|
+ class nsIRunnable;
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+ class WorkerRunnable;
|
|
|
++class WorkerPrivate;
|
|
|
++template <class> class WorkerPrivateParent;
|
|
|
+
|
|
|
+ namespace workers {
|
|
|
+ class RuntimeService;
|
|
|
+-class WorkerPrivate;
|
|
|
+-template <class> class WorkerPrivateParent;
|
|
|
+ }
|
|
|
+
|
|
|
+ // This class lets us restrict the public methods that can be called on
|
|
|
+ // WorkerThread to RuntimeService and WorkerPrivate without letting them gain
|
|
|
+ // full access to private methods (as would happen if they were simply friends).
|
|
|
+ class WorkerThreadFriendKey
|
|
|
+ {
|
|
|
+ friend class workers::RuntimeService;
|
|
|
+- friend class workers::WorkerPrivate;
|
|
|
+- friend class workers::WorkerPrivateParent<workers::WorkerPrivate>;
|
|
|
++ friend class WorkerPrivate;
|
|
|
++ friend class WorkerPrivateParent<WorkerPrivate>;
|
|
|
+
|
|
|
+ WorkerThreadFriendKey();
|
|
|
+ ~WorkerThreadFriendKey();
|
|
|
+ };
|
|
|
+
|
|
|
+ class WorkerThread final
|
|
|
+ : public nsThread
|
|
|
+ {
|
|
|
+ class Observer;
|
|
|
+
|
|
|
+ Mutex mLock;
|
|
|
+ CondVar mWorkerPrivateCondVar;
|
|
|
+
|
|
|
+ // Protected by nsThread::mLock.
|
|
|
+- workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ WorkerPrivate* mWorkerPrivate;
|
|
|
+
|
|
|
+ // Only touched on the target thread.
|
|
|
+ RefPtr<Observer> mObserver;
|
|
|
+
|
|
|
+ // Protected by nsThread::mLock and waited on with mWorkerPrivateCondVar.
|
|
|
+ uint32_t mOtherThreadsDispatchingViaEventTarget;
|
|
|
+
|
|
|
+ #ifdef DEBUG
|
|
|
+@@ -63,17 +63,17 @@ class WorkerThread final
|
|
|
+ #endif
|
|
|
+
|
|
|
+ public:
|
|
|
+ static already_AddRefed<WorkerThread>
|
|
|
+ Create(const WorkerThreadFriendKey& aKey);
|
|
|
+
|
|
|
+ void
|
|
|
+ SetWorker(const WorkerThreadFriendKey& aKey,
|
|
|
+- workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ WorkerPrivate* aWorkerPrivate);
|
|
|
+
|
|
|
+ nsresult
|
|
|
+ DispatchPrimaryRunnable(const WorkerThreadFriendKey& aKey,
|
|
|
+ already_AddRefed<nsIRunnable> aRunnable);
|
|
|
+
|
|
|
+ nsresult
|
|
|
+ DispatchAnyThread(const WorkerThreadFriendKey& aKey,
|
|
|
+ already_AddRefed<WorkerRunnable> aWorkerRunnable);
|
|
|
+diff --git a/dom/workers/moz.build b/dom/workers/moz.build
|
|
|
+--- a/dom/workers/moz.build
|
|
|
++++ b/dom/workers/moz.build
|
|
|
+@@ -18,16 +18,17 @@ EXPORTS.mozilla.dom += [
|
|
|
+ 'WorkerLocation.h',
|
|
|
+ 'WorkerNavigator.h',
|
|
|
+ 'WorkerPrivate.h',
|
|
|
+ 'WorkerRunnable.h',
|
|
|
+ 'WorkerScope.h',
|
|
|
+ ]
|
|
|
+
|
|
|
+ EXPORTS.mozilla.dom.workers += [
|
|
|
++ 'Queue.h',
|
|
|
+ 'RuntimeService.h',
|
|
|
+ 'WorkerCommon.h',
|
|
|
+ ]
|
|
|
+
|
|
|
+ XPIDL_MODULE = 'dom_workers'
|
|
|
+
|
|
|
+ XPIDL_SOURCES += [
|
|
|
+ 'nsIWorkerDebugger.idl',
|
|
|
+diff --git a/dom/xhr/XMLHttpRequestWorker.cpp b/dom/xhr/XMLHttpRequestWorker.cpp
|
|
|
+--- a/dom/xhr/XMLHttpRequestWorker.cpp
|
|
|
++++ b/dom/xhr/XMLHttpRequestWorker.cpp
|
|
|
+@@ -35,18 +35,16 @@
|
|
|
+ #include "WorkerRunnable.h"
|
|
|
+ #include "XMLHttpRequestUpload.h"
|
|
|
+
|
|
|
+ #include "mozilla/UniquePtr.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+-using namespace workers;
|
|
|
+-
|
|
|
+ /* static */ void
|
|
|
+ XMLHttpRequestWorker::StateData::trace(JSTracer *aTrc)
|
|
|
+ {
|
|
|
+ JS::TraceEdge(aTrc, &mResponse, "XMLHttpRequestWorker::StateData::mResponse");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * XMLHttpRequest in workers
|
|
|
+@@ -159,27 +157,27 @@ public:
|
|
|
+ Teardown(bool aSendUnpin);
|
|
|
+
|
|
|
+ bool
|
|
|
+ AddRemoveEventListeners(bool aUpload, bool aAdd);
|
|
|
+
|
|
|
+ void
|
|
|
+ Reset()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ if (mUploadEventListenersAttached) {
|
|
|
+ AddRemoveEventListeners(true, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ already_AddRefed<nsIEventTarget>
|
|
|
+ GetEventTarget()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ nsCOMPtr<nsIEventTarget> target = mSyncEventResponseTarget ?
|
|
|
+ mSyncEventResponseTarget :
|
|
|
+ mSyncLoopTarget;
|
|
|
+ return target.forget();
|
|
|
+ }
|
|
|
+
|
|
|
+ private:
|
|
|
+@@ -370,17 +368,17 @@ public:
|
|
|
+
|
|
|
+ private:
|
|
|
+ ~AsyncTeardownRunnable()
|
|
|
+ { }
|
|
|
+
|
|
|
+ NS_IMETHOD
|
|
|
+ Run() override
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ // This means the XHR was GC'd, so we can't be pinned, and we don't need to
|
|
|
+ // try to unpin.
|
|
|
+ mProxy->Teardown(/* aSendUnpin */ false);
|
|
|
+ mProxy = nullptr;
|
|
|
+
|
|
|
+ return NS_OK;
|
|
|
+ }
|
|
|
+@@ -447,42 +445,42 @@ public:
|
|
|
+ : Runnable("dom::LoadStartDetectionRunnable")
|
|
|
+ , mWorkerPrivate(aProxy->mWorkerPrivate)
|
|
|
+ , mProxy(aProxy)
|
|
|
+ , mXHR(aProxy->mXHR)
|
|
|
+ , mXMLHttpRequestPrivate(aXHRPrivate)
|
|
|
+ , mChannelId(mProxy->mInnerChannelId)
|
|
|
+ , mReceivedLoadStart(false)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ CopyASCIItoUTF16(sEventStrings[STRING_loadstart], mEventType);
|
|
|
+ }
|
|
|
+
|
|
|
+ NS_DECL_ISUPPORTS_INHERITED
|
|
|
+ NS_DECL_NSIRUNNABLE
|
|
|
+ NS_DECL_NSIDOMEVENTLISTENER
|
|
|
+
|
|
|
+ bool
|
|
|
+ RegisterAndDispatch()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ if (NS_FAILED(mXHR->AddEventListener(mEventType, this, false, false, 2))) {
|
|
|
+ NS_WARNING("Failed to add event listener!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return NS_SUCCEEDED(mWorkerPrivate->DispatchToMainThread(this));
|
|
|
+ }
|
|
|
+
|
|
|
+ private:
|
|
|
+ ~LoadStartDetectionRunnable()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
+- }
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
++ }
|
|
|
+ };
|
|
|
+
|
|
|
+ class EventRunnable final : public MainThreadProxyRunnable
|
|
|
+ , public StructuredCloneHolder
|
|
|
+ {
|
|
|
+ nsString mType;
|
|
|
+ nsString mResponseType;
|
|
|
+ JS::Heap<JS::Value> mResponse;
|
|
|
+@@ -850,17 +848,17 @@ public:
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ } // namespace
|
|
|
+
|
|
|
+ bool
|
|
|
+ Proxy::Init()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+ MOZ_ASSERT(mWorkerPrivate);
|
|
|
+
|
|
|
+ if (mXHR) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ nsPIDOMWindowInner* ownerWindow = mWorkerPrivate->GetWindow();
|
|
|
+ if (ownerWindow && !ownerWindow->IsCurrentInnerWindow()) {
|
|
|
+@@ -893,17 +891,17 @@ Proxy::Init()
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ void
|
|
|
+ Proxy::Teardown(bool aSendUnpin)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ if (mXHR) {
|
|
|
+ Reset();
|
|
|
+
|
|
|
+ // NB: We are intentionally dropping events coming from xhr.abort on the
|
|
|
+ // floor.
|
|
|
+ AddRemoveEventListeners(false, false);
|
|
|
+
|
|
|
+@@ -943,17 +941,17 @@ Proxy::Teardown(bool aSendUnpin)
|
|
|
+
|
|
|
+ MOZ_ASSERT(!mWorkerPrivate);
|
|
|
+ MOZ_ASSERT(!mSyncLoopTarget);
|
|
|
+ }
|
|
|
+
|
|
|
+ bool
|
|
|
+ Proxy::AddRemoveEventListeners(bool aUpload, bool aAdd)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ NS_ASSERTION(!aUpload ||
|
|
|
+ (mUploadEventListenersAttached && !aAdd) ||
|
|
|
+ (!mUploadEventListenersAttached && aAdd),
|
|
|
+ "Messed up logic for upload listeners!");
|
|
|
+
|
|
|
+ nsCOMPtr<nsIDOMEventTarget> target =
|
|
|
+ aUpload ?
|
|
|
+@@ -983,17 +981,17 @@ Proxy::AddRemoveEventListeners(bool aUpl
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ NS_IMPL_ISUPPORTS(Proxy, nsIDOMEventListener)
|
|
|
+
|
|
|
+ NS_IMETHODIMP
|
|
|
+ Proxy::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ if (!mWorkerPrivate || !mXMLHttpRequestPrivate) {
|
|
|
+ NS_ERROR("Shouldn't get here!");
|
|
|
+ return NS_OK;
|
|
|
+ }
|
|
|
+
|
|
|
+ nsString type;
|
|
|
+ if (NS_FAILED(aEvent->GetType(type))) {
|
|
|
+@@ -1064,17 +1062,17 @@ Proxy::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
+ }
|
|
|
+
|
|
|
+ NS_IMPL_ISUPPORTS_INHERITED(LoadStartDetectionRunnable, Runnable,
|
|
|
+ nsIDOMEventListener)
|
|
|
+
|
|
|
+ NS_IMETHODIMP
|
|
|
+ LoadStartDetectionRunnable::Run()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ if (NS_FAILED(mXHR->RemoveEventListener(mEventType, this, false))) {
|
|
|
+ NS_WARNING("Failed to remove event listener!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!mReceivedLoadStart) {
|
|
|
+ if (mProxy->mOutstandingSendCount > 1) {
|
|
|
+ mProxy->mOutstandingSendCount--;
|
|
|
+@@ -1096,17 +1094,17 @@ LoadStartDetectionRunnable::Run()
|
|
|
+ mXHR = nullptr;
|
|
|
+ mXMLHttpRequestPrivate = nullptr;
|
|
|
+ return NS_OK;
|
|
|
+ }
|
|
|
+
|
|
|
+ NS_IMETHODIMP
|
|
|
+ LoadStartDetectionRunnable::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ #ifdef DEBUG
|
|
|
+ {
|
|
|
+ nsString type;
|
|
|
+ if (NS_SUCCEEDED(aEvent->GetType(type))) {
|
|
|
+ MOZ_ASSERT(type == mEventType);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+@@ -1117,17 +1115,17 @@ LoadStartDetectionRunnable::HandleEvent(
|
|
|
+
|
|
|
+ mReceivedLoadStart = true;
|
|
|
+ return NS_OK;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool
|
|
|
+ EventRunnable::PreDispatch(WorkerPrivate* /* unused */)
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ AutoJSAPI jsapi;
|
|
|
+ DebugOnly<bool> ok = jsapi.Init(xpc::NativeGlobal(mScopeObj));
|
|
|
+ MOZ_ASSERT(ok);
|
|
|
+ JSContext* cx = jsapi.cx();
|
|
|
+ // Now keep the mScopeObj alive for the duration
|
|
|
+ JS::Rooted<JSObject*> scopeObj(cx, mScopeObj);
|
|
|
+ // And reset mScopeObj now, before we have a chance to run its destructor on
|
|
|
+@@ -1372,17 +1370,17 @@ EventRunnable::WorkerRun(JSContext* aCx,
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool
|
|
|
+ WorkerThreadProxySyncRunnable::MainThreadRun()
|
|
|
+ {
|
|
|
+- AssertIsOnMainThread();
|
|
|
++ workers::AssertIsOnMainThread();
|
|
|
+
|
|
|
+ nsCOMPtr<nsIEventTarget> tempTarget = mSyncLoopTarget;
|
|
|
+
|
|
|
+ mProxy->mSyncEventResponseTarget.swap(tempTarget);
|
|
|
+
|
|
|
+ ErrorResult rv;
|
|
|
+ RunOnMainThread(rv);
|
|
|
+ mErrorCode = rv.StealNSResult();
|
|
|
+diff --git a/dom/xhr/XMLHttpRequestWorker.h b/dom/xhr/XMLHttpRequestWorker.h
|
|
|
+--- a/dom/xhr/XMLHttpRequestWorker.h
|
|
|
++++ b/dom/xhr/XMLHttpRequestWorker.h
|
|
|
+@@ -13,20 +13,17 @@
|
|
|
+ #include "mozilla/dom/TypedArray.h"
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace dom {
|
|
|
+
|
|
|
+ class Proxy;
|
|
|
+ class SendRunnable;
|
|
|
+ class DOMString;
|
|
|
+-
|
|
|
+-namespace workers {
|
|
|
+ class WorkerPrivate;
|
|
|
+-}
|
|
|
+
|
|
|
+ class XMLHttpRequestWorker final : public XMLHttpRequest,
|
|
|
+ public WorkerHolder
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ struct StateData
|
|
|
+ {
|
|
|
+ XMLHttpRequestStringSnapshot mResponseText;
|
|
|
+@@ -46,17 +43,17 @@ public:
|
|
|
+ mStatusResult(NS_OK), mResponseResult(NS_OK)
|
|
|
+ { }
|
|
|
+
|
|
|
+ void trace(JSTracer* trc);
|
|
|
+ };
|
|
|
+
|
|
|
+ private:
|
|
|
+ RefPtr<XMLHttpRequestUpload> mUpload;
|
|
|
+- workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ WorkerPrivate* mWorkerPrivate;
|
|
|
+ RefPtr<Proxy> mProxy;
|
|
|
+ XMLHttpRequestResponseType mResponseType;
|
|
|
+ StateData mStateData;
|
|
|
+
|
|
|
+ uint32_t mTimeout;
|
|
|
+
|
|
|
+ bool mRooted;
|
|
|
+ bool mBackgroundRequest;
|
|
|
+@@ -280,17 +277,17 @@ public:
|
|
|
+
|
|
|
+ bool
|
|
|
+ SendInProgress() const
|
|
|
+ {
|
|
|
+ return mRooted;
|
|
|
+ }
|
|
|
+
|
|
|
+ private:
|
|
|
+- explicit XMLHttpRequestWorker(workers::WorkerPrivate* aWorkerPrivate);
|
|
|
++ explicit XMLHttpRequestWorker(WorkerPrivate* aWorkerPrivate);
|
|
|
+ ~XMLHttpRequestWorker();
|
|
|
+
|
|
|
+ enum ReleaseType { Default, XHRIsGoingAway, WorkerIsGoingAway };
|
|
|
+
|
|
|
+ void
|
|
|
+ ReleaseProxy(ReleaseType aType = Default);
|
|
|
+
|
|
|
+ void
|
|
|
+diff --git a/gfx/thebes/gfxUtils.cpp b/gfx/thebes/gfxUtils.cpp
|
|
|
+--- a/gfx/thebes/gfxUtils.cpp
|
|
|
++++ b/gfx/thebes/gfxUtils.cpp
|
|
|
+@@ -1408,17 +1408,17 @@ gfxUtils::GetInputStream(gfx::DataSource
|
|
|
+ aSurface->GetSize().height,
|
|
|
+ imageBuffer.get(), format,
|
|
|
+ encoder, aEncoderOptions, outStream);
|
|
|
+ }
|
|
|
+
|
|
|
+ class GetFeatureStatusRunnable final : public dom::WorkerMainThreadRunnable
|
|
|
+ {
|
|
|
+ public:
|
|
|
+- GetFeatureStatusRunnable(dom::workers::WorkerPrivate* workerPrivate,
|
|
|
++ GetFeatureStatusRunnable(dom::WorkerPrivate* workerPrivate,
|
|
|
+ const nsCOMPtr<nsIGfxInfo>& gfxInfo,
|
|
|
+ int32_t feature,
|
|
|
+ nsACString& failureId,
|
|
|
+ int32_t* status)
|
|
|
+ : WorkerMainThreadRunnable(workerPrivate,
|
|
|
+ NS_LITERAL_CSTRING("GFX :: GetFeatureStatus"))
|
|
|
+ , mGfxInfo(gfxInfo)
|
|
|
+ , mFeature(feature)
|
|
|
+@@ -1453,18 +1453,17 @@ private:
|
|
|
+ };
|
|
|
+
|
|
|
+ /* static */ nsresult
|
|
|
+ gfxUtils::ThreadSafeGetFeatureStatus(const nsCOMPtr<nsIGfxInfo>& gfxInfo,
|
|
|
+ int32_t feature, nsACString& failureId,
|
|
|
+ int32_t* status)
|
|
|
+ {
|
|
|
+ if (!NS_IsMainThread()) {
|
|
|
+- dom::workers::WorkerPrivate* workerPrivate =
|
|
|
+- dom::workers::GetCurrentThreadWorkerPrivate();
|
|
|
++ dom::WorkerPrivate* workerPrivate = dom::GetCurrentThreadWorkerPrivate();
|
|
|
+
|
|
|
+ RefPtr<GetFeatureStatusRunnable> runnable =
|
|
|
+ new GetFeatureStatusRunnable(workerPrivate, gfxInfo, feature, failureId,
|
|
|
+ status);
|
|
|
+
|
|
|
+ ErrorResult rv;
|
|
|
+ runnable->Dispatch(dom::WorkerStatus::Terminating, rv);
|
|
|
+ if (rv.Failed()) {
|
|
|
+diff --git a/ipc/glue/IPCStreamSource.cpp b/ipc/glue/IPCStreamSource.cpp
|
|
|
+--- a/ipc/glue/IPCStreamSource.cpp
|
|
|
++++ b/ipc/glue/IPCStreamSource.cpp
|
|
|
+@@ -8,18 +8,18 @@
|
|
|
+ #include "mozilla/webrender/WebRenderTypes.h"
|
|
|
+ #include "nsIAsyncInputStream.h"
|
|
|
+ #include "nsICancelableRunnable.h"
|
|
|
+ #include "nsIRunnable.h"
|
|
|
+ #include "nsISerialEventTarget.h"
|
|
|
+ #include "nsStreamUtils.h"
|
|
|
+ #include "nsThreadUtils.h"
|
|
|
+
|
|
|
+-using mozilla::dom::workers::GetCurrentThreadWorkerPrivate;
|
|
|
+-using mozilla::dom::workers::WorkerPrivate;
|
|
|
++using mozilla::dom::GetCurrentThreadWorkerPrivate;
|
|
|
++using mozilla::dom::WorkerPrivate;
|
|
|
+ using mozilla::dom::WorkerStatus;
|
|
|
+ using mozilla::wr::ByteBuffer;
|
|
|
+
|
|
|
+ namespace mozilla {
|
|
|
+ namespace ipc {
|
|
|
+
|
|
|
+ class IPCStreamSource::Callback final : public nsIInputStreamCallback
|
|
|
+ , public nsIRunnable
|
|
|
+diff --git a/ipc/glue/IPCStreamSource.h b/ipc/glue/IPCStreamSource.h
|
|
|
+--- a/ipc/glue/IPCStreamSource.h
|
|
|
++++ b/ipc/glue/IPCStreamSource.h
|
|
|
+@@ -132,17 +132,17 @@ private:
|
|
|
+ void OnStreamReady(Callback* aCallback);
|
|
|
+
|
|
|
+ nsCOMPtr<nsIAsyncInputStream> mStream;
|
|
|
+ RefPtr<Callback> mCallback;
|
|
|
+
|
|
|
+ // Raw pointer because this IPCStreamSource keeps the worker alive using a
|
|
|
+ // WorkerHolder. The worker is kept alive when the actor is created and,
|
|
|
+ // released when the actor is destroyed.
|
|
|
+- dom::workers::WorkerPrivate* mWorkerPrivate;
|
|
|
++ dom::WorkerPrivate* mWorkerPrivate;
|
|
|
+
|
|
|
+ #ifdef DEBUG
|
|
|
+ protected:
|
|
|
+ #endif
|
|
|
+
|
|
|
+ enum {
|
|
|
+ ePending,
|
|
|
+ eActorConstructed,
|
|
|
+diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp
|
|
|
+--- a/js/xpconnect/src/nsXPConnect.cpp
|
|
|
++++ b/js/xpconnect/src/nsXPConnect.cpp
|
|
|
+@@ -1321,27 +1321,25 @@ IsChromeOrXBL(JSContext* cx, JSObject* /
|
|
|
+ // compat and not security for remote XUL, we just always claim to be XBL.
|
|
|
+ //
|
|
|
+ // Note that, for performance, we don't check AllowXULXBLForPrincipal here,
|
|
|
+ // and instead rely on the fact that AllowContentXBLScope() only returns false in
|
|
|
+ // remote XUL situations.
|
|
|
+ return AccessCheck::isChrome(c) || IsContentXBLCompartment(c) || !AllowContentXBLScope(realm);
|
|
|
+ }
|
|
|
+
|
|
|
+-namespace workers {
|
|
|
+ extern bool IsCurrentThreadRunningChromeWorker();
|
|
|
+-} // namespace workers
|
|
|
+
|
|
|
+ bool
|
|
|
+ ThreadSafeIsChromeOrXBL(JSContext* cx, JSObject* obj)
|
|
|
+ {
|
|
|
+ if (NS_IsMainThread()) {
|
|
|
+ return IsChromeOrXBL(cx, obj);
|
|
|
+ }
|
|
|
+- return workers::IsCurrentThreadRunningChromeWorker();
|
|
|
++ return IsCurrentThreadRunningChromeWorker();
|
|
|
+ }
|
|
|
+
|
|
|
+ } // namespace dom
|
|
|
+ } // namespace mozilla
|
|
|
+
|
|
|
+ void
|
|
|
+ xpc::CreateCooperativeContext()
|
|
|
+ {
|