diff --git a/dom/base/ChromeUtils.cpp b/dom/base/ChromeUtils.cpp index ac17626bb2a4..61fe3eb695fe 100644 --- a/dom/base/ChromeUtils.cpp +++ b/dom/base/ChromeUtils.cpp @@ -42,7 +42,7 @@ #include "mozilla/dom/UnionTypes.h" #include "mozilla/dom/WindowBinding.h" // For IdleRequestCallback/Options #include "mozilla/dom/WindowGlobalParent.h" -#include "mozilla/dom/WorkerScope.h" +#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/ipc/GeckoChildProcessHost.h" #include "mozilla/net/UrlClassifierFeatureFactory.h" #include "IOActivityMonitor.h" diff --git a/dom/broadcastchannel/BroadcastChannel.cpp b/dom/broadcastchannel/BroadcastChannel.cpp index 42b5a1d9e5d9..7d21664415e4 100644 --- a/dom/broadcastchannel/BroadcastChannel.cpp +++ b/dom/broadcastchannel/BroadcastChannel.cpp @@ -15,6 +15,7 @@ #include "mozilla/dom/ipc/StructuredCloneData.h" #include "mozilla/dom/RefMessageBodyService.h" #include "mozilla/dom/SharedMessageBody.h" +#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerScope.h" #include "mozilla/dom/WorkerRef.h" #include "mozilla/dom/WorkerRunnable.h" diff --git a/dom/clients/api/Client.cpp b/dom/clients/api/Client.cpp index 1b0b4a2a591e..b191c9aa1830 100644 --- a/dom/clients/api/Client.cpp +++ b/dom/clients/api/Client.cpp @@ -14,6 +14,7 @@ #include "mozilla/dom/DOMMozPromiseRequestHolder.h" #include "mozilla/dom/MessagePortBinding.h" #include "mozilla/dom/Promise.h" +#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerScope.h" #include "nsIDUtils.h" #include "nsIGlobalObject.h" diff --git a/dom/clients/api/Clients.cpp b/dom/clients/api/Clients.cpp index 6dd88953b3ab..79367af07f43 100644 --- a/dom/clients/api/Clients.cpp +++ b/dom/clients/api/Clients.cpp @@ -14,7 +14,7 @@ #include "mozilla/dom/Promise.h" #include "mozilla/dom/ServiceWorkerDescriptor.h" #include "mozilla/dom/ServiceWorkerManager.h" -#include "mozilla/dom/WorkerScope.h" +#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/ipc/BackgroundUtils.h" #include "mozilla/SchedulerGroup.h" #include "mozilla/StaticPrefs_privacy.h" diff --git a/dom/clients/manager/ClientSource.cpp b/dom/clients/manager/ClientSource.cpp index 2a1f3e1c48eb..6e404b9a1453 100644 --- a/dom/clients/manager/ClientSource.cpp +++ b/dom/clients/manager/ClientSource.cpp @@ -20,6 +20,7 @@ #include "mozilla/dom/MessageEvent.h" #include "mozilla/dom/MessageEventBinding.h" #include "mozilla/dom/Navigator.h" +#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerScope.h" #include "mozilla/dom/WorkerRef.h" #include "mozilla/dom/ServiceWorker.h" diff --git a/dom/console/Console.cpp b/dom/console/Console.cpp index 1184ccaa61fa..3003b5e120b5 100644 --- a/dom/console/Console.cpp +++ b/dom/console/Console.cpp @@ -22,6 +22,7 @@ #include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/StructuredCloneHolder.h" #include "mozilla/dom/ToJSValue.h" +#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerRunnable.h" #include "mozilla/dom/WorkerScope.h" #include "mozilla/dom/WorkletGlobalScope.h" diff --git a/dom/fetch/Fetch.cpp b/dom/fetch/Fetch.cpp index 432dc321648a..b8f909e6f04d 100644 --- a/dom/fetch/Fetch.cpp +++ b/dom/fetch/Fetch.cpp @@ -43,6 +43,7 @@ #include "InternalResponse.h" #include "mozilla/dom/WorkerCommon.h" +#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerRef.h" #include "mozilla/dom/WorkerRunnable.h" #include "mozilla/dom/WorkerScope.h" @@ -1088,15 +1089,16 @@ nsresult ExtractByteStreamFromBody(const fetch::ResponseBodyInit& aBodyInit, template FetchBody::FetchBody(nsIGlobalObject* aOwner) : mOwner(aOwner), + mWorkerPrivate(nullptr), mReadableStreamBody(nullptr), mReadableStreamReader(nullptr), mBodyUsed(false) { MOZ_ASSERT(aOwner); if (!NS_IsMainThread()) { - WorkerPrivate* wp = GetCurrentThreadWorkerPrivate(); - MOZ_ASSERT(wp); - mMainThreadEventTarget = wp->MainThreadEventTarget(); + mWorkerPrivate = GetCurrentThreadWorkerPrivate(); + MOZ_ASSERT(mWorkerPrivate); + mMainThreadEventTarget = mWorkerPrivate->MainThreadEventTarget(); } else { mMainThreadEventTarget = aOwner->EventTargetFor(TaskCategory::Other); } diff --git a/dom/fetch/Fetch.h b/dom/fetch/Fetch.h index faac1cd5d8bf..585be4df17d7 100644 --- a/dom/fetch/Fetch.h +++ b/dom/fetch/Fetch.h @@ -19,7 +19,6 @@ #include "mozilla/dom/Promise.h" #include "mozilla/dom/FetchStreamReader.h" #include "mozilla/dom/RequestBinding.h" -#include "mozilla/dom/workerinternals/RuntimeService.h" class nsIGlobalObject; class nsIEventTarget; @@ -231,6 +230,9 @@ class FetchBody : public BodyStreamHolder, public AbortFollower { protected: nsCOMPtr mOwner; + // Always set whenever the FetchBody is created on the worker thread. + WorkerPrivate* mWorkerPrivate; + // This is the ReadableStream exposed to content. It's underlying source is a // BodyStream object. JS::Heap mReadableStreamBody; @@ -252,9 +254,9 @@ class FetchBody : public BodyStreamHolder, public AbortFollower { void LockStream(JSContext* aCx, JS::HandleObject aStream, ErrorResult& aRv); - void AssertIsOnTargetThread() { - MOZ_ASSERT(NS_IsMainThread() == !GetCurrentThreadWorkerPrivate()); - } + bool IsOnTargetThread() { return NS_IsMainThread() == !mWorkerPrivate; } + + void AssertIsOnTargetThread() { MOZ_ASSERT(IsOnTargetThread()); } // Only ever set once, always on target thread. bool mBodyUsed; diff --git a/dom/indexedDB/IndexedDatabase.cpp b/dom/indexedDB/IndexedDatabase.cpp index a69ac0a3268b..df0eaa790f81 100644 --- a/dom/indexedDB/IndexedDatabase.cpp +++ b/dom/indexedDB/IndexedDatabase.cpp @@ -12,6 +12,7 @@ #include "mozilla/dom/FileBlobImpl.h" #include "mozilla/dom/StructuredCloneTags.h" +#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerScope.h" #include "MainThreadUtils.h" #include "jsapi.h" diff --git a/dom/indexedDB/IndexedDatabaseManager.cpp b/dom/indexedDB/IndexedDatabaseManager.cpp index 9356a770268e..a94b5f7f4e0d 100644 --- a/dom/indexedDB/IndexedDatabaseManager.cpp +++ b/dom/indexedDB/IndexedDatabaseManager.cpp @@ -22,6 +22,7 @@ #include "mozilla/dom/ErrorEvent.h" #include "mozilla/dom/ErrorEventBinding.h" #include "mozilla/dom/WorkerScope.h" +#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/intl/LocaleCanonicalizer.h" #include "mozilla/ipc/BackgroundChild.h" diff --git a/dom/notification/Notification.cpp b/dom/notification/Notification.cpp index 78f39b67cd59..2cd255d17205 100644 --- a/dom/notification/Notification.cpp +++ b/dom/notification/Notification.cpp @@ -31,6 +31,7 @@ #include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h" #include "mozilla/dom/ServiceWorkerManager.h" #include "mozilla/dom/ServiceWorkerUtils.h" +#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerRunnable.h" #include "mozilla/dom/WorkerScope.h" #include "Navigator.h" diff --git a/dom/notification/Notification.h b/dom/notification/Notification.h index 59becced729e..329cf83047f7 100644 --- a/dom/notification/Notification.h +++ b/dom/notification/Notification.h @@ -10,7 +10,6 @@ #include "mozilla/DOMEventTargetHelper.h" #include "mozilla/UniquePtr.h" #include "mozilla/dom/NotificationBinding.h" -#include "mozilla/dom/WorkerPrivate.h" #include "nsIObserver.h" #include "nsISupports.h" @@ -30,6 +29,7 @@ class NotificationRef; class WorkerNotificationObserver; class Promise; class StrongWorkerRef; +class WorkerPrivate; /* * Notifications on workers introduce some lifetime issues. The property we @@ -207,7 +207,7 @@ class Notification : public DOMEventTargetHelper, // Initialized on the worker thread, never unset, and always used in // a read-only capacity. Used on any thread. - CheckedUnsafePtr mWorkerPrivate; + WorkerPrivate* mWorkerPrivate; // Main thread only. WorkerNotificationObserver* mObserver; diff --git a/dom/performance/PerformanceObserver.cpp b/dom/performance/PerformanceObserver.cpp index 4f6516f350a2..a6164e401a15 100644 --- a/dom/performance/PerformanceObserver.cpp +++ b/dom/performance/PerformanceObserver.cpp @@ -10,6 +10,7 @@ #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 "mozilla/StaticPrefs_dom.h" #include "nsIScriptError.h" diff --git a/dom/performance/PerformanceStorageWorker.cpp b/dom/performance/PerformanceStorageWorker.cpp index 475b9da7e993..9799ee153d17 100644 --- a/dom/performance/PerformanceStorageWorker.cpp +++ b/dom/performance/PerformanceStorageWorker.cpp @@ -10,7 +10,7 @@ #include "PerformanceTiming.h" #include "mozilla/dom/WorkerRef.h" #include "mozilla/dom/WorkerRunnable.h" -#include "mozilla/dom/WorkerScope.h" +#include "mozilla/dom/WorkerPrivate.h" namespace mozilla::dom { diff --git a/dom/performance/PerformanceWorker.cpp b/dom/performance/PerformanceWorker.cpp index 4940a530ae4d..496fc3e49259 100644 --- a/dom/performance/PerformanceWorker.cpp +++ b/dom/performance/PerformanceWorker.cpp @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "PerformanceWorker.h" -#include "mozilla/dom/WorkerScope.h" +#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/StaticPrefs_dom.h" namespace mozilla::dom { diff --git a/dom/performance/PerformanceWorker.h b/dom/performance/PerformanceWorker.h index f11affd5dde4..dee46e439477 100644 --- a/dom/performance/PerformanceWorker.h +++ b/dom/performance/PerformanceWorker.h @@ -8,11 +8,12 @@ #define mozilla_dom_PerformanceWorker_h #include "Performance.h" -#include "mozilla/dom/WorkerPrivate.h" namespace mozilla { namespace dom { +class WorkerPrivate; + class PerformanceWorker final : public Performance { public: explicit PerformanceWorker(WorkerPrivate* aWorkerPrivate); @@ -93,7 +94,7 @@ class PerformanceWorker final : public Performance { } private: - CheckedUnsafePtr mWorkerPrivate; + WorkerPrivate* mWorkerPrivate; }; } // namespace dom diff --git a/dom/push/PushManager.cpp b/dom/push/PushManager.cpp index 1ab9931ae5b8..a23b0f840698 100644 --- a/dom/push/PushManager.cpp +++ b/dom/push/PushManager.cpp @@ -16,6 +16,7 @@ #include "mozilla/dom/PushSubscriptionOptionsBinding.h" #include "mozilla/dom/PushUtil.h" #include "mozilla/dom/WorkerRunnable.h" +#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerScope.h" #include "mozilla/dom/Promise.h" diff --git a/dom/serviceworkers/ServiceWorkerOp.cpp b/dom/serviceworkers/ServiceWorkerOp.cpp index 4664234ea221..c3e7cfc4b3fb 100644 --- a/dom/serviceworkers/ServiceWorkerOp.cpp +++ b/dom/serviceworkers/ServiceWorkerOp.cpp @@ -56,6 +56,7 @@ #include "mozilla/dom/SafeRefPtr.h" #include "mozilla/dom/ServiceWorkerBinding.h" #include "mozilla/dom/WorkerCommon.h" +#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerRef.h" #include "mozilla/dom/WorkerScope.h" #include "mozilla/ipc/IPCStreamUtils.h" diff --git a/dom/url/URLWorker.cpp b/dom/url/URLWorker.cpp index 8b0f48e9ff23..16889e966732 100644 --- a/dom/url/URLWorker.cpp +++ b/dom/url/URLWorker.cpp @@ -9,6 +9,7 @@ #include "mozilla/dom/Blob.h" #include "mozilla/dom/BlobImpl.h" #include "mozilla/dom/BlobURLProtocolHandler.h" +#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerRunnable.h" #include "mozilla/dom/WorkerScope.h" diff --git a/dom/workers/MessageEventRunnable.cpp b/dom/workers/MessageEventRunnable.cpp index e36578f6c3b7..07831604ac88 100644 --- a/dom/workers/MessageEventRunnable.cpp +++ b/dom/workers/MessageEventRunnable.cpp @@ -11,6 +11,7 @@ #include "mozilla/TimelineConsumers.h" #include "mozilla/WorkerTimelineMarker.h" #include "nsQueryObject.h" +#include "WorkerPrivate.h" #include "WorkerScope.h" namespace mozilla { diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index 00ed1ab06baf..4e419b68f655 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -76,6 +76,7 @@ #include "WorkerDebuggerManager.h" #include "WorkerError.h" #include "WorkerLoadInfo.h" +#include "WorkerPrivate.h" #include "WorkerRunnable.h" #include "WorkerScope.h" #include "WorkerThread.h" @@ -1184,7 +1185,7 @@ bool RuntimeService::RegisterWorker(WorkerPrivate& aWorkerPrivate) { // From here on out we must call UnregisterWorker if something fails! if (parent) { - if (!parent->AddChildWorker(aWorkerPrivate)) { + if (!parent->AddChildWorker(&aWorkerPrivate)) { UnregisterWorker(aWorkerPrivate); return false; } @@ -1304,7 +1305,7 @@ void RuntimeService::UnregisterWorker(WorkerPrivate& aWorkerPrivate) { // same time as us calling into the code here and would race with us. if (parent) { - parent->RemoveChildWorker(aWorkerPrivate); + parent->RemoveChildWorker(&aWorkerPrivate); } else if (aWorkerPrivate.IsSharedWorker()) { AssertIsOnMainThread(); diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index acb91f4fb0ae..d9f9181b6ede 100644 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -87,6 +87,7 @@ #include "mozilla/StaticPrefs_security.h" #include "mozilla/UniquePtr.h" #include "Principal.h" +#include "WorkerPrivate.h" #include "WorkerRunnable.h" #include "WorkerScope.h" diff --git a/dom/workers/WorkerCSPEventListener.cpp b/dom/workers/WorkerCSPEventListener.cpp index 40b23926dd37..819d0bf2df10 100644 --- a/dom/workers/WorkerCSPEventListener.cpp +++ b/dom/workers/WorkerCSPEventListener.cpp @@ -5,9 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "WorkerCSPEventListener.h" +#include "WorkerPrivate.h" #include "WorkerRef.h" #include "WorkerRunnable.h" -#include "WorkerScope.h" #include "mozilla/dom/SecurityPolicyViolationEvent.h" #include "mozilla/dom/SecurityPolicyViolationEventBinding.h" #include "mozilla/dom/WorkerRunnable.h" diff --git a/dom/workers/WorkerDebugger.cpp b/dom/workers/WorkerDebugger.cpp index cfb3256f761f..3fd164e4bebd 100644 --- a/dom/workers/WorkerDebugger.cpp +++ b/dom/workers/WorkerDebugger.cpp @@ -4,6 +4,8 @@ * 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 "WorkerDebugger.h" + #include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/MessageEvent.h" #include "mozilla/dom/MessageEventBinding.h" @@ -16,9 +18,9 @@ #include "ScriptLoader.h" #include "WorkerCommon.h" #include "WorkerError.h" +#include "WorkerPrivate.h" #include "WorkerRunnable.h" -#include "WorkerDebugger.h" - +#include "WorkerScope.h" #if defined(XP_WIN) # include // for GetCurrentProcessId() #else @@ -546,10 +548,8 @@ RefPtr WorkerDebugger::ReportPerformanceInfo() { } // We need to keep a ref on workerPrivate, passed to the promise, - // to make sure it's still aloive when collecting the info - // (and CheckedUnsafePtr does not convert directly to RefPtr). - WorkerPrivate* workerPtr = mWorkerPrivate; - RefPtr workerRef = workerPtr; + // to make sure it's still aloive when collecting the info. + RefPtr workerRef = mWorkerPrivate; RefPtr mainThread = AbstractThread::MainThread(); return CollectMemoryInfo(top, mainThread) diff --git a/dom/workers/WorkerDebugger.h b/dom/workers/WorkerDebugger.h index af55e6b5db84..e73641278c12 100644 --- a/dom/workers/WorkerDebugger.h +++ b/dom/workers/WorkerDebugger.h @@ -8,7 +8,6 @@ #define mozilla_dom_workers_WorkerDebugger_h #include "mozilla/PerformanceTypes.h" -#include "mozilla/dom/WorkerScope.h" #include "nsCOMPtr.h" #include "nsIWorkerDebugger.h" @@ -25,7 +24,7 @@ class WorkerDebugger : public nsIWorkerDebugger { class ReportDebuggerErrorRunnable; class PostDebuggerMessageRunnable; - CheckedUnsafePtr mWorkerPrivate; + WorkerPrivate* mWorkerPrivate; bool mIsInitialized; nsTArray> mListeners; diff --git a/dom/workers/WorkerEventTarget.h b/dom/workers/WorkerEventTarget.h index 7260fb8b0ca3..75af983df8e6 100644 --- a/dom/workers/WorkerEventTarget.h +++ b/dom/workers/WorkerEventTarget.h @@ -9,11 +9,12 @@ #include "nsISerialEventTarget.h" #include "mozilla/Mutex.h" -#include "mozilla/dom/WorkerPrivate.h" namespace mozilla { namespace dom { +class WorkerPrivate; + class WorkerEventTarget final : public nsISerialEventTarget { public: // The WorkerEventTarget supports different dispatch behaviors: @@ -29,7 +30,7 @@ class WorkerEventTarget final : public nsISerialEventTarget { private: mozilla::Mutex mMutex; - CheckedUnsafePtr mWorkerPrivate; + WorkerPrivate* mWorkerPrivate; const Behavior mBehavior; ~WorkerEventTarget() = default; diff --git a/dom/workers/WorkerNavigator.cpp b/dom/workers/WorkerNavigator.cpp index cb499d6bd7ae..fbbb32a92f88 100644 --- a/dom/workers/WorkerNavigator.cpp +++ b/dom/workers/WorkerNavigator.cpp @@ -11,6 +11,7 @@ #include "ErrorList.h" #include "MainThreadUtils.h" #include "RuntimeService.h" +#include "WorkerPrivate.h" #include "WorkerRunnable.h" #include "WorkerScope.h" #include "mozilla/dom/LockManager.h" diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 5af3130c4e33..050b67fc4f2d 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -51,7 +51,6 @@ #include "mozilla/dom/RemoteWorkerService.h" #include "mozilla/dom/TimeoutHandler.h" #include "mozilla/dom/WorkerBinding.h" -#include "mozilla/dom/WorkerScope.h" #include "mozilla/dom/JSExecutionManager.h" #include "mozilla/dom/WindowContext.h" #include "mozilla/extensions/ExtensionBrowser.h" // extensions::Create{AndDispatchInitWorkerContext,WorkerLoaded,WorkerDestroyed}Runnable @@ -3824,7 +3823,7 @@ bool WorkerPrivate::ModifyBusyCountFromWorker(bool aIncrease) { return runnable->Dispatch(); } -bool WorkerPrivate::AddChildWorker(WorkerPrivate& aChildWorker) { +bool WorkerPrivate::AddChildWorker(WorkerPrivate* aChildWorker) { auto data = mWorkerThreadAccessible.Access(); #ifdef DEBUG @@ -3839,20 +3838,20 @@ bool WorkerPrivate::AddChildWorker(WorkerPrivate& aChildWorker) { } #endif - NS_ASSERTION(!data->mChildWorkers.Contains(&aChildWorker), + NS_ASSERTION(!data->mChildWorkers.Contains(aChildWorker), "Already know about this one!"); - data->mChildWorkers.AppendElement(&aChildWorker); + data->mChildWorkers.AppendElement(aChildWorker); return data->mChildWorkers.Length() == 1 ? ModifyBusyCountFromWorker(true) : true; } -void WorkerPrivate::RemoveChildWorker(WorkerPrivate& aChildWorker) { +void WorkerPrivate::RemoveChildWorker(WorkerPrivate* aChildWorker) { auto data = mWorkerThreadAccessible.Access(); - NS_ASSERTION(data->mChildWorkers.Contains(&aChildWorker), + NS_ASSERTION(data->mChildWorkers.Contains(aChildWorker), "Didn't know about this one!"); - data->mChildWorkers.RemoveElement(&aChildWorker); + data->mChildWorkers.RemoveElement(aChildWorker); if (data->mChildWorkers.IsEmpty() && !ModifyBusyCountFromWorker(false)) { NS_WARNING("Failed to modify busy count!"); @@ -3922,7 +3921,7 @@ void WorkerPrivate::NotifyWorkerRefs(WorkerStatus aStatus) { workerRef->Notify(); } - AutoTArray, 10> children; + AutoTArray children; children.AppendElements(data->mChildWorkers); for (uint32_t index = 0; index < children.Length(); index++) { @@ -5245,14 +5244,15 @@ WorkerGlobalScope* WorkerPrivate::GetOrCreateGlobalScope(JSContext* aCx) { } if (IsSharedWorker()) { - data->mScope = - new SharedWorkerGlobalScope(this, CreateClientSource(), WorkerName()); + data->mScope = new SharedWorkerGlobalScope( + WrapNotNull(this), CreateClientSource(), WorkerName()); } else if (IsServiceWorker()) { - data->mScope = new ServiceWorkerGlobalScope( - this, CreateClientSource(), GetServiceWorkerRegistrationDescriptor()); + data->mScope = + new ServiceWorkerGlobalScope(WrapNotNull(this), CreateClientSource(), + GetServiceWorkerRegistrationDescriptor()); } else { - data->mScope = new DedicatedWorkerGlobalScope(this, CreateClientSource(), - WorkerName()); + data->mScope = new DedicatedWorkerGlobalScope( + WrapNotNull(this), CreateClientSource(), WorkerName()); } JS::Rooted global(aCx); @@ -5281,7 +5281,7 @@ WorkerDebuggerGlobalScope* WorkerPrivate::CreateDebuggerGlobalScope( GetClientType(), HybridEventTarget(), NullPrincipalInfo()); data->mDebuggerScope = - new WorkerDebuggerGlobalScope(this, std::move(clientSource)); + new WorkerDebuggerGlobalScope(WrapNotNull(this), std::move(clientSource)); JS::Rooted global(aCx); NS_ENSURE_TRUE(data->mDebuggerScope->WrapGlobalObject(aCx, &global), nullptr); diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index 5f75ffbb32e9..107e2d0511bc 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -28,10 +28,10 @@ #include "mozilla/dom/ClientSource.h" #include "mozilla/dom/FlippedOnce.h" #include "mozilla/dom/RemoteWorkerChild.h" -#include "mozilla/dom/quota/CheckedUnsafePtr.h" #include "mozilla/dom/Worker.h" #include "mozilla/dom/WorkerCommon.h" #include "mozilla/dom/WorkerLoadInfo.h" +#include "mozilla/dom/WorkerScope.h" #include "mozilla/dom/WorkerStatus.h" #include "mozilla/dom/workerinternals/JSSettings.h" #include "mozilla/dom/workerinternals/Queue.h" @@ -107,9 +107,7 @@ class SharedMutex { nsString ComputeWorkerPrivateId(); -class WorkerPrivate final - : public RelativeTimeline, - public SupportsCheckedUnsafePtr> { +class WorkerPrivate final : public RelativeTimeline { public: struct LocationInfo { nsCString mHref; @@ -263,9 +261,9 @@ class WorkerPrivate final bool ModifyBusyCountFromWorker(bool aIncrease); - bool AddChildWorker(WorkerPrivate& aChildWorker); + bool AddChildWorker(WorkerPrivate* aChildWorker); - void RemoveChildWorker(WorkerPrivate& aChildWorker); + void RemoveChildWorker(WorkerPrivate* aChildWorker); void PostMessageToParent(JSContext* aCx, JS::Handle aMessage, const Sequence& aTransferable, @@ -583,9 +581,6 @@ class WorkerPrivate final // worker [Dedicated|Shared|Service]. bool IsChromeWorker() const { return mIsChromeWorker; } - // TODO: Invariants require that the parent worker out-live any child - // worker, so WorkerPrivate* should be safe in the moment of calling. - // We would like to have stronger type-system annotated/enforced handling. WorkerPrivate* GetParent() const { return mParent; } bool IsFrozen() const { @@ -1157,9 +1152,7 @@ class WorkerPrivate final SharedMutex mMutex; mozilla::CondVar mCondVar; - // We cannot make this CheckedUnsafePtr as this would violate - // our static assert - MOZ_NON_OWNING_REF WorkerPrivate* const mParent; + WorkerPrivate* const mParent; const nsString mScriptURL; @@ -1279,8 +1272,6 @@ class WorkerPrivate final RefPtr mScope; RefPtr mDebuggerScope; - // We cannot make this CheckedUnsafePtr as this would violate - // our static assert nsTArray mChildWorkers; nsTObserverArray mWorkerRefs; nsTArray> mTimeouts; @@ -1351,9 +1342,7 @@ class WorkerPrivate final ~AutoPushEventLoopGlobal(); private: - // We cannot make this CheckedUnsafePtr as this would violate - // our static assert - MOZ_NON_OWNING_REF WorkerPrivate* mWorkerPrivate; + WorkerPrivate* mWorkerPrivate; nsCOMPtr mOldEventLoopGlobal; }; friend class AutoPushEventLoopGlobal; @@ -1437,7 +1426,7 @@ class WorkerPrivate final }; class AutoSyncLoopHolder { - CheckedUnsafePtr mWorkerPrivate; + WorkerPrivate* mWorkerPrivate; nsCOMPtr mTarget; uint32_t mIndex; @@ -1460,12 +1449,12 @@ class AutoSyncLoopHolder { } bool Run() { - CheckedUnsafePtr keepAliveWP = mWorkerPrivate; + WorkerPrivate* workerPrivate = mWorkerPrivate; mWorkerPrivate = nullptr; - keepAliveWP->AssertIsOnWorkerThread(); + workerPrivate->AssertIsOnWorkerThread(); - return keepAliveWP->RunCurrentSyncLoop(); + return workerPrivate->RunCurrentSyncLoop(); } nsIEventTarget* GetEventTarget() const { diff --git a/dom/workers/WorkerRunnable.cpp b/dom/workers/WorkerRunnable.cpp index df60298281fb..544568d4baad 100644 --- a/dom/workers/WorkerRunnable.cpp +++ b/dom/workers/WorkerRunnable.cpp @@ -6,6 +6,7 @@ #include "WorkerRunnable.h" +#include "WorkerPrivate.h" #include "WorkerScope.h" #include "js/RootingAPI.h" #include "jsapi.h" diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index b3f72dba97fd..516e75f2491f 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -217,7 +217,8 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WorkerGlobalScopeBase) NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper) WorkerGlobalScopeBase::WorkerGlobalScopeBase( - WorkerPrivate* aWorkerPrivate, UniquePtr aClientSource) + NotNull aWorkerPrivate, + UniquePtr aClientSource) : mWorkerPrivate(aWorkerPrivate), mClientSource(std::move(aClientSource)), mSerialEventTarget(aWorkerPrivate->HybridEventTarget()) { @@ -779,9 +780,9 @@ NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(DedicatedWorkerGlobalScope, WorkerGlobalScope) DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope( - WorkerPrivate* aWorkerPrivate, UniquePtr aClientSource, - const nsString& aName) - : WorkerGlobalScope(std::move(aWorkerPrivate), std::move(aClientSource)), + NotNull aWorkerPrivate, + UniquePtr aClientSource, const nsString& aName) + : WorkerGlobalScope(aWorkerPrivate, std::move(aClientSource)), NamedWorkerGlobalScopeMixin(aName) {} bool DedicatedWorkerGlobalScope::WrapGlobalObject( @@ -953,9 +954,9 @@ void DedicatedWorkerGlobalScope::OnVsync(const VsyncEvent& aVsync) { } SharedWorkerGlobalScope::SharedWorkerGlobalScope( - WorkerPrivate* aWorkerPrivate, UniquePtr aClientSource, - const nsString& aName) - : WorkerGlobalScope(std::move(aWorkerPrivate), std::move(aClientSource)), + NotNull aWorkerPrivate, + UniquePtr aClientSource, const nsString& aName) + : WorkerGlobalScope(aWorkerPrivate, std::move(aClientSource)), NamedWorkerGlobalScopeMixin(aName) {} bool SharedWorkerGlobalScope::WrapGlobalObject( @@ -987,9 +988,10 @@ NS_IMPL_ADDREF_INHERITED(ServiceWorkerGlobalScope, WorkerGlobalScope) NS_IMPL_RELEASE_INHERITED(ServiceWorkerGlobalScope, WorkerGlobalScope) ServiceWorkerGlobalScope::ServiceWorkerGlobalScope( - WorkerPrivate* aWorkerPrivate, UniquePtr aClientSource, + NotNull aWorkerPrivate, + UniquePtr aClientSource, const ServiceWorkerRegistrationDescriptor& aRegistrationDescriptor) - : WorkerGlobalScope(std::move(aWorkerPrivate), std::move(aClientSource)), + : WorkerGlobalScope(aWorkerPrivate, std::move(aClientSource)), mScope(NS_ConvertUTF8toUTF16(aRegistrationDescriptor.Scope())) // Eagerly create the registration because we will need to receive diff --git a/dom/workers/WorkerScope.h b/dom/workers/WorkerScope.h index 4c66cd2685a4..0575a0b4555b 100644 --- a/dom/workers/WorkerScope.h +++ b/dom/workers/WorkerScope.h @@ -20,7 +20,6 @@ #include "mozilla/dom/ImageBitmapBinding.h" #include "mozilla/dom/ImageBitmapSource.h" #include "mozilla/dom/SafeRefPtr.h" -#include "mozilla/dom/WorkerPrivate.h" #include "nsCOMPtr.h" #include "nsCycleCollectionParticipant.h" #include "nsIGlobalObject.h" @@ -94,7 +93,7 @@ class WorkerGlobalScopeBase : public DOMEventTargetHelper, NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WorkerGlobalScopeBase, DOMEventTargetHelper) - WorkerGlobalScopeBase(WorkerPrivate* aWorkerPrivate, + WorkerGlobalScopeBase(NotNull aWorkerPrivate, UniquePtr aClientSource); virtual bool WrapGlobalObject(JSContext* aCx, @@ -163,7 +162,7 @@ class WorkerGlobalScopeBase : public DOMEventTargetHelper, protected: ~WorkerGlobalScopeBase(); - CheckedUnsafePtr mWorkerPrivate; + const NotNull mWorkerPrivate; private: RefPtr mConsole; @@ -345,7 +344,7 @@ class DedicatedWorkerGlobalScope final NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED( DedicatedWorkerGlobalScope, WorkerGlobalScope) - DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate, + DedicatedWorkerGlobalScope(NotNull aWorkerPrivate, UniquePtr aClientSource, const nsString& aName); @@ -389,7 +388,7 @@ class SharedWorkerGlobalScope final : public WorkerGlobalScope, public workerinternals::NamedWorkerGlobalScopeMixin { public: - SharedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate, + SharedWorkerGlobalScope(NotNull aWorkerPrivate, UniquePtr aClientSource, const nsString& aName); @@ -411,7 +410,8 @@ class ServiceWorkerGlobalScope final : public WorkerGlobalScope { WorkerGlobalScope) ServiceWorkerGlobalScope( - WorkerPrivate* aWorkerPrivate, UniquePtr aClientSource, + NotNull aWorkerPrivate, + UniquePtr aClientSource, const ServiceWorkerRegistrationDescriptor& aRegistrationDescriptor); bool WrapGlobalObject(JSContext* aCx, diff --git a/dom/xhr/XMLHttpRequestWorker.cpp b/dom/xhr/XMLHttpRequestWorker.cpp index 90bcca0817c5..57fab8517d85 100644 --- a/dom/xhr/XMLHttpRequestWorker.cpp +++ b/dom/xhr/XMLHttpRequestWorker.cpp @@ -30,6 +30,7 @@ #include "mozilla/dom/UnionConversions.h" #include "mozilla/dom/URLSearchParams.h" #include "mozilla/dom/WorkerScope.h" +#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerRef.h" #include "mozilla/dom/WorkerRunnable.h" #include "mozilla/dom/XMLHttpRequestBinding.h" diff --git a/toolkit/components/extensions/webidl-api/ExtensionAPIRequestForwarder.cpp b/toolkit/components/extensions/webidl-api/ExtensionAPIRequestForwarder.cpp index 0edae10dfee6..99f012801c40 100644 --- a/toolkit/components/extensions/webidl-api/ExtensionAPIRequestForwarder.cpp +++ b/toolkit/components/extensions/webidl-api/ExtensionAPIRequestForwarder.cpp @@ -14,7 +14,7 @@ #include "mozilla/dom/ClonedErrorHolderBinding.h" #include "mozilla/dom/ExtensionBrowserBinding.h" #include "mozilla/dom/FunctionBinding.h" -#include "mozilla/dom/WorkerScope.h" +#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/SerializedStackHolder.h" #include "mozilla/dom/ServiceWorkerInfo.h" #include "mozilla/dom/ServiceWorkerManager.h" diff --git a/toolkit/components/extensions/webidl-api/ExtensionBrowser.cpp b/toolkit/components/extensions/webidl-api/ExtensionBrowser.cpp index 84ad46b7c131..a9dbf6bd84ad 100644 --- a/toolkit/components/extensions/webidl-api/ExtensionBrowser.cpp +++ b/toolkit/components/extensions/webidl-api/ExtensionBrowser.cpp @@ -8,7 +8,7 @@ #include "mozilla/dom/ExtensionBrowserBinding.h" #include "mozilla/dom/ExtensionPortBinding.h" // ExtensionPortDescriptor -#include "mozilla/dom/WorkerScope.h" // GetWorkerPrivateFromContext +#include "mozilla/dom/WorkerPrivate.h" // GetWorkerPrivateFromContext #include "mozilla/extensions/ExtensionAlarms.h" #include "mozilla/extensions/ExtensionMockAPI.h" #include "mozilla/extensions/ExtensionPort.h"