diff --git a/dom/abort/moz.build b/dom/abort/moz.build index 99e8f4b3bc7c..aea70cbc0c08 100644 --- a/dom/abort/moz.build +++ b/dom/abort/moz.build @@ -19,4 +19,6 @@ UNIFIED_SOURCES += [ 'AbortSignal.cpp', ] +include('/ipc/chromium/chromium-config.mozbuild') + FINAL_LIBRARY = 'xul' diff --git a/dom/console/moz.build b/dom/console/moz.build index f591dc76f9c2..93dd64e4bc82 100644 --- a/dom/console/moz.build +++ b/dom/console/moz.build @@ -52,4 +52,6 @@ MOCHITEST_MANIFESTS += [ 'tests/mochitest.ini' ] MOCHITEST_CHROME_MANIFESTS += [ 'tests/chrome.ini' ] XPCSHELL_TESTS_MANIFESTS += ['tests/xpcshell/xpcshell.ini'] +include('/ipc/chromium/chromium-config.mozbuild') + FINAL_LIBRARY = 'xul' diff --git a/dom/performance/moz.build b/dom/performance/moz.build index d588c26794aa..5e53327d684f 100644 --- a/dom/performance/moz.build +++ b/dom/performance/moz.build @@ -42,6 +42,8 @@ UNIFIED_SOURCES += [ 'PerformanceWorker.cpp', ] +include('/ipc/chromium/chromium-config.mozbuild') + MOCHITEST_MANIFESTS += [ 'tests/mochitest.ini' ] FINAL_LIBRARY = 'xul' diff --git a/dom/serviceworkers/ServiceWorkerPrivateImpl.cpp b/dom/serviceworkers/ServiceWorkerPrivateImpl.cpp index 006c4117c292..3d44882526a1 100644 --- a/dom/serviceworkers/ServiceWorkerPrivateImpl.cpp +++ b/dom/serviceworkers/ServiceWorkerPrivateImpl.cpp @@ -388,6 +388,34 @@ nsresult ServiceWorkerPrivateImpl::Initialize() { return NS_OK; } +RefPtr ServiceWorkerPrivateImpl::SetSkipWaitingFlag() { + AssertIsOnMainThread(); + MOZ_ASSERT(mOuter); + MOZ_ASSERT(mOuter->mInfo); + + RefPtr swm = ServiceWorkerManager::GetInstance(); + + if (!swm) { + return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__); + } + + RefPtr regInfo = + swm->GetRegistration(mOuter->mInfo->Principal(), mOuter->mInfo->Scope()); + + if (!regInfo) { + return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__); + } + + mOuter->mInfo->SetSkipWaitingFlag(); + + RefPtr promise = + new GenericPromise::Private(__func__); + + regInfo->TryToActivateAsync([promise] { promise->Resolve(true, __func__); }); + + return promise; +} + nsresult ServiceWorkerPrivateImpl::RefreshRemoteWorkerData( const RefPtr& aRegistration) { AssertIsOnMainThread(); diff --git a/dom/serviceworkers/ServiceWorkerPrivateImpl.h b/dom/serviceworkers/ServiceWorkerPrivateImpl.h index 4d50ade58c70..5f9792923812 100644 --- a/dom/serviceworkers/ServiceWorkerPrivateImpl.h +++ b/dom/serviceworkers/ServiceWorkerPrivateImpl.h @@ -52,6 +52,8 @@ class ServiceWorkerPrivateImpl final : public ServiceWorkerPrivate::Inner, nsresult Initialize(); + RefPtr SetSkipWaitingFlag(); + private: class RAIIActorPtrHolder; diff --git a/dom/serviceworkers/ServiceWorkerRegistrationInfo.cpp b/dom/serviceworkers/ServiceWorkerRegistrationInfo.cpp index ba031b46e5f4..55da923e81fb 100644 --- a/dom/serviceworkers/ServiceWorkerRegistrationInfo.cpp +++ b/dom/serviceworkers/ServiceWorkerRegistrationInfo.cpp @@ -294,16 +294,20 @@ ServiceWorkerRegistrationInfo::GetServiceWorkerInfoById(uint64_t aId) { return serviceWorker.forget(); } -void ServiceWorkerRegistrationInfo::TryToActivateAsync() { +void ServiceWorkerRegistrationInfo::TryToActivateAsync( + TryToActivateCallback&& aCallback) { MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread( - NewRunnableMethod("ServiceWorkerRegistrationInfo::TryToActivate", this, - &ServiceWorkerRegistrationInfo::TryToActivate))); + NewRunnableMethod>( + "ServiceWorkerRegistrationInfo::TryToActivate", this, + &ServiceWorkerRegistrationInfo::TryToActivate, + std::move(aCallback)))); } /* * TryToActivate should not be called directly, use TryToActivateAsync instead. */ -void ServiceWorkerRegistrationInfo::TryToActivate() { +void ServiceWorkerRegistrationInfo::TryToActivate( + TryToActivateCallback&& aCallback) { MOZ_ASSERT(NS_IsMainThread()); bool controlling = IsControllingClients(); bool skipWaiting = mWaitingWorker && mWaitingWorker->SkipWaitingFlag(); @@ -311,6 +315,10 @@ void ServiceWorkerRegistrationInfo::TryToActivate() { if (idle && (!controlling || skipWaiting)) { Activate(); } + + if (aCallback) { + aCallback(); + } } void ServiceWorkerRegistrationInfo::Activate() { diff --git a/dom/serviceworkers/ServiceWorkerRegistrationInfo.h b/dom/serviceworkers/ServiceWorkerRegistrationInfo.h index 378b26de7219..b85dcc5684dd 100644 --- a/dom/serviceworkers/ServiceWorkerRegistrationInfo.h +++ b/dom/serviceworkers/ServiceWorkerRegistrationInfo.h @@ -7,6 +7,8 @@ #ifndef mozilla_dom_serviceworkerregistrationinfo_h #define mozilla_dom_serviceworkerregistrationinfo_h +#include + #include "mozilla/dom/ServiceWorkerInfo.h" #include "mozilla/dom/ServiceWorkerRegistrationBinding.h" #include "mozilla/dom/ServiceWorkerRegistrationDescriptor.h" @@ -68,6 +70,8 @@ class ServiceWorkerRegistrationInfo final NS_DECL_ISUPPORTS NS_DECL_NSISERVICEWORKERREGISTRATIONINFO + typedef std::function TryToActivateCallback; + ServiceWorkerRegistrationInfo(const nsACString& aScope, nsIPrincipal* aPrincipal, ServiceWorkerUpdateViaCache aUpdateViaCache); @@ -120,9 +124,9 @@ class ServiceWorkerRegistrationInfo final bool IsCorrupt() const; - void TryToActivateAsync(); + void TryToActivateAsync(TryToActivateCallback&& aCallback = nullptr); - void TryToActivate(); + void TryToActivate(TryToActivateCallback&& aCallback); void Activate(); diff --git a/dom/workers/WorkerError.cpp b/dom/workers/WorkerError.cpp index 431970298389..b51d8cdc49f0 100644 --- a/dom/workers/WorkerError.cpp +++ b/dom/workers/WorkerError.cpp @@ -11,6 +11,7 @@ #include "mozilla/dom/ErrorEventBinding.h" #include "mozilla/dom/RemoteWorkerChild.h" #include "mozilla/dom/ServiceWorkerManager.h" +#include "mozilla/dom/ServiceWorkerUtils.h" #include "mozilla/dom/SimpleGlobalObject.h" #include "mozilla/dom/WorkerDebuggerGlobalScopeBinding.h" #include "mozilla/dom/WorkerGlobalScopeBinding.h" @@ -80,15 +81,28 @@ class ReportErrorRunnable final : public WorkerDebuggeeRunnable { // worker error reporting will crash. Instead, pass the error to // the ServiceWorkerManager to report on any controlled documents. if (aWorkerPrivate->IsServiceWorker()) { - RefPtr swm = ServiceWorkerManager::GetInstance(); - if (swm) { - swm->HandleError(aCx, aWorkerPrivate->GetPrincipal(), - aWorkerPrivate->ServiceWorkerScope(), - aWorkerPrivate->ScriptURL(), mReport->mMessage, - mReport->mFilename, mReport->mLine, - mReport->mLineNumber, mReport->mColumnNumber, - mReport->mFlags, mReport->mExnType); + if (ServiceWorkerParentInterceptEnabled()) { + RefPtr actor( + aWorkerPrivate->GetRemoteWorkerControllerWeakRef()); + + Unused << NS_WARN_IF(!actor); + + if (actor) { + actor->ErrorPropagationOnMainThread(nullptr, false); + } + + } else { + RefPtr swm = + ServiceWorkerManager::GetInstance(); + if (swm) { + swm->HandleError(aCx, aWorkerPrivate->GetPrincipal(), + aWorkerPrivate->ServiceWorkerScope(), + aWorkerPrivate->ScriptURL(), EmptyString(), + EmptyString(), EmptyString(), 0, 0, JSREPORT_ERROR, + JSEXN_ERR); + } } + return true; } @@ -159,14 +173,27 @@ class ReportGenericErrorRunnable final : public WorkerDebuggeeRunnable { } if (aWorkerPrivate->IsServiceWorker()) { - RefPtr swm = ServiceWorkerManager::GetInstance(); - if (swm) { - swm->HandleError(aCx, aWorkerPrivate->GetPrincipal(), - aWorkerPrivate->ServiceWorkerScope(), - aWorkerPrivate->ScriptURL(), EmptyString(), - EmptyString(), EmptyString(), 0, 0, JSREPORT_ERROR, - JSEXN_ERR); + if (ServiceWorkerParentInterceptEnabled()) { + RefPtr actor( + aWorkerPrivate->GetRemoteWorkerControllerWeakRef()); + + Unused << NS_WARN_IF(!actor); + + if (actor) { + actor->ErrorPropagationOnMainThread(nullptr, false); + } + + } else { + RefPtr swm = ServiceWorkerManager::GetInstance(); + if (swm) { + swm->HandleError(aCx, aWorkerPrivate->GetPrincipal(), + aWorkerPrivate->ServiceWorkerScope(), + aWorkerPrivate->ScriptURL(), EmptyString(), + EmptyString(), EmptyString(), 0, 0, JSREPORT_ERROR, + JSEXN_ERR); + } } + return true; } diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 8db98a591592..efeaf833ea7d 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -36,6 +36,7 @@ #include "mozilla/dom/PerformanceStorageWorker.h" #include "mozilla/dom/PromiseDebugging.h" #include "mozilla/dom/RemoteWorkerChild.h" +#include "mozilla/dom/RemoteWorkerService.h" #include "mozilla/dom/TimeoutHandler.h" #include "mozilla/dom/WorkerBinding.h" #include "mozilla/StorageAccess.h" @@ -53,6 +54,7 @@ #include "nsIURI.h" #include "nsIURL.h" #include "nsPrintfCString.h" +#include "nsProxyRelease.h" #include "nsQueryObject.h" #include "nsRFPService.h" #include "nsSandboxFlags.h" @@ -4846,6 +4848,40 @@ RemoteWorkerChild* WorkerPrivate::GetRemoteWorkerController() { return mRemoteWorkerController; } +void WorkerPrivate::SetRemoteWorkerControllerWeakRef( + ThreadSafeWeakPtr aWeakRef) { + MOZ_ASSERT(aWeakRef); + MOZ_ASSERT(!mRemoteWorkerControllerWeakRef); + MOZ_ASSERT(IsServiceWorker()); + + mRemoteWorkerControllerWeakRef = std::move(aWeakRef); +} + +ThreadSafeWeakPtr +WorkerPrivate::GetRemoteWorkerControllerWeakRef() { + MOZ_ASSERT(IsServiceWorker()); + return mRemoteWorkerControllerWeakRef; +} + +RefPtr WorkerPrivate::SetServiceWorkerSkipWaitingFlag() { + AssertIsOnWorkerThread(); + MOZ_ASSERT(IsServiceWorker()); + + RefPtr rwc(mRemoteWorkerControllerWeakRef); + + if (!rwc) { + return GenericPromise::CreateAndReject(NS_ERROR_DOM_ABORT_ERR, __func__); + } + + RefPtr promise = + rwc->MaybeSendSetServiceWorkerSkipWaitingFlag(); + + NS_ProxyRelease("WorkerPrivate::mRemoteWorkerControllerWeakRef", + RemoteWorkerService::Thread(), rwc.forget()); + + return promise; +} + nsAString& WorkerPrivate::Id() { AssertIsOnMainThread(); diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index cc930bdecb0d..3e6bd9f0c9ef 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -12,14 +12,17 @@ #include "mozilla/Attributes.h" #include "mozilla/CondVar.h" #include "mozilla/DOMEventTargetHelper.h" +#include "mozilla/MozPromise.h" #include "mozilla/RelativeTimeline.h" #include "mozilla/StorageAccess.h" +#include "mozilla/ThreadSafeWeakPtr.h" #include "nsContentUtils.h" #include "nsIContentSecurityPolicy.h" #include "nsIEventTarget.h" #include "nsTObserverArray.h" #include "js/ContextOptions.h" +#include "mozilla/dom/RemoteWorkerChild.h" #include "mozilla/dom/Worker.h" #include "mozilla/dom/WorkerLoadInfo.h" #include "mozilla/dom/workerinternals/JSSettings.h" @@ -43,7 +46,6 @@ class Function; class MessagePort; class MessagePortIdentifier; class PerformanceStorage; -class RemoteWorkerChild; class TimeoutHandler; class WorkerControlRunnable; class WorkerCSPEventListener; @@ -789,6 +791,13 @@ class WorkerPrivate : public RelativeTimeline { void SetRemoteWorkerController(RemoteWorkerChild* aController); + void SetRemoteWorkerControllerWeakRef( + ThreadSafeWeakPtr aWeakRef); + + ThreadSafeWeakPtr GetRemoteWorkerControllerWeakRef(); + + RefPtr SetServiceWorkerSkipWaitingFlag(); + // We can assume that an nsPIDOMWindow will be available for Freeze, Thaw // as these are only used for globals going in and out of the bfcache. bool Freeze(nsPIDOMWindowInner* aWindow); @@ -1065,6 +1074,9 @@ class WorkerPrivate : public RelativeTimeline { // Only touched on the parent thread. This is set only if IsSharedWorker(). RefPtr mRemoteWorkerController; + // This is set only if IsServiceWorker(). + ThreadSafeWeakPtr mRemoteWorkerControllerWeakRef; + JS::UniqueChars mDefaultLocale; // nulled during worker JSContext init TimeStamp mKillTime; WorkerStatus mParentStatus; diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index fb1baad8e901..c388be3ad598 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -25,6 +25,7 @@ #include "mozilla/dom/Promise.h" #include "mozilla/dom/PromiseWorkerProxy.h" #include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h" +#include "mozilla/dom/ServiceWorkerUtils.h" #include "mozilla/dom/SharedWorkerGlobalScopeBinding.h" #include "mozilla/dom/SimpleGlobalObject.h" #include "mozilla/dom/TimeoutHandler.h" @@ -858,6 +859,21 @@ already_AddRefed ServiceWorkerGlobalScope::SkipWaiting( return nullptr; } + if (ServiceWorkerParentInterceptEnabled()) { + mWorkerPrivate->SetServiceWorkerSkipWaitingFlag()->Then( + GetCurrentThreadSerialEventTarget(), __func__, + [promise](bool aOk) { + Unused << NS_WARN_IF(!aOk); + promise->MaybeResolveWithUndefined(); + }, + [promise](nsresult aRv) { + MOZ_ASSERT(NS_FAILED(aRv)); + promise->MaybeResolveWithUndefined(); + }); + + return promise.forget(); + } + RefPtr promiseProxy = PromiseWorkerProxy::Create(mWorkerPrivate, promise); if (!promiseProxy) { diff --git a/dom/workers/moz.build b/dom/workers/moz.build index 0587d7ab639e..d546701fdf34 100644 --- a/dom/workers/moz.build +++ b/dom/workers/moz.build @@ -71,6 +71,7 @@ LOCAL_INCLUDES += [ '/dom/base', '/dom/bindings', '/dom/system', + '/dom/workers/remoteworkers', '/js/xpconnect/loader', '/netwerk/base', '/xpcom/build', diff --git a/dom/workers/remoteworkers/PRemoteWorker.ipdl b/dom/workers/remoteworkers/PRemoteWorker.ipdl index b46dd52639f4..3b38a523c630 100644 --- a/dom/workers/remoteworkers/PRemoteWorker.ipdl +++ b/dom/workers/remoteworkers/PRemoteWorker.ipdl @@ -69,6 +69,8 @@ parent: async Close(); + async SetServiceWorkerSkipWaitingFlag() returns (bool aOk); + child: async PFetchEventOpProxy(ServiceWorkerFetchEventOpArgs aArgs); diff --git a/dom/workers/remoteworkers/PRemoteWorkerController.ipdl b/dom/workers/remoteworkers/PRemoteWorkerController.ipdl index 1a948f40a8cb..7deae7c8e1c0 100644 --- a/dom/workers/remoteworkers/PRemoteWorkerController.ipdl +++ b/dom/workers/remoteworkers/PRemoteWorkerController.ipdl @@ -25,6 +25,8 @@ protocol PRemoteWorkerController { async Terminated(); + async SetServiceWorkerSkipWaitingFlag() returns (bool aOk); + parent: async PFetchEventOp(ServiceWorkerFetchEventOpArgs aArgs); diff --git a/dom/workers/remoteworkers/RemoteWorkerChild.cpp b/dom/workers/remoteworkers/RemoteWorkerChild.cpp index 4c84732a1685..7971b64b2db9 100644 --- a/dom/workers/remoteworkers/RemoteWorkerChild.cpp +++ b/dom/workers/remoteworkers/RemoteWorkerChild.cpp @@ -454,6 +454,9 @@ nsresult RemoteWorkerChild::ExecWorkerOnMainThread(RemoteWorkerData&& aData) { } if (mIsServiceWorker) { + RefPtr self = this; + workerPrivate->SetRemoteWorkerControllerWeakRef( + ThreadSafeWeakPtr(self)); } else { workerPrivate->SetRemoteWorkerController(this); } @@ -927,6 +930,42 @@ IPCResult RemoteWorkerChild::RecvExecServiceWorkerOp( return IPC_OK(); } +RefPtr +RemoteWorkerChild::MaybeSendSetServiceWorkerSkipWaitingFlag() { + RefPtr promise = + new GenericPromise::Private(__func__); + + RefPtr self = this; + + nsCOMPtr r = NS_NewRunnableFunction(__func__, [self = std::move( + self), + promise] { + MOZ_ACCESS_THREAD_BOUND(self->mLauncherData, launcherData); + + if (!launcherData->mIPCActive) { + promise->Reject(NS_ERROR_DOM_ABORT_ERR, __func__); + return; + } + + self->SendSetServiceWorkerSkipWaitingFlag()->Then( + GetCurrentThreadSerialEventTarget(), __func__, + [promise]( + const SetServiceWorkerSkipWaitingFlagPromise::ResolveOrRejectValue& + aResult) { + if (NS_WARN_IF(aResult.IsReject())) { + promise->Reject(NS_ERROR_DOM_ABORT_ERR, __func__); + return; + } + + promise->Resolve(aResult.ResolveValue(), __func__); + }); + }); + + GetOwningEventTarget()->Dispatch(r.forget(), NS_DISPATCH_NORMAL); + + return promise; +} + /** * PFetchEventOpProxy methods */ diff --git a/dom/workers/remoteworkers/RemoteWorkerChild.h b/dom/workers/remoteworkers/RemoteWorkerChild.h index d86f546a65d1..51ff75090529 100644 --- a/dom/workers/remoteworkers/RemoteWorkerChild.h +++ b/dom/workers/remoteworkers/RemoteWorkerChild.h @@ -63,7 +63,7 @@ class RemoteWorkerChild final RefPtr GetTerminationPromise(); - void CloseWorkerOnMainThread(); + RefPtr MaybeSendSetServiceWorkerSkipWaitingFlag(); private: class InitializeWorkerRunnable; diff --git a/dom/workers/remoteworkers/RemoteWorkerController.cpp b/dom/workers/remoteworkers/RemoteWorkerController.cpp index a6cd8afa563f..087f2686e433 100644 --- a/dom/workers/remoteworkers/RemoteWorkerController.cpp +++ b/dom/workers/remoteworkers/RemoteWorkerController.cpp @@ -278,6 +278,21 @@ RefPtr RemoteWorkerController::ExecServiceWorkerOp( return promise; } +RefPtr RemoteWorkerController::SetServiceWorkerSkipWaitingFlag() + const { + AssertIsOnBackgroundThread(); + MOZ_ASSERT(mObserver); + + RefPtr promise = + new GenericPromise::Private(__func__); + + static_cast(mObserver.get()) + ->MaybeSendSetServiceWorkerSkipWaitingFlag( + [promise](bool aOk) { promise->Resolve(aOk, __func__); }); + + return promise; +} + RemoteWorkerController::PendingSharedWorkerOp::PendingSharedWorkerOp( Type aType, uint64_t aWindowID) : mType(aType), mWindowID(aWindowID) { diff --git a/dom/workers/remoteworkers/RemoteWorkerController.h b/dom/workers/remoteworkers/RemoteWorkerController.h index bf244bedc455..d81538a16273 100644 --- a/dom/workers/remoteworkers/RemoteWorkerController.h +++ b/dom/workers/remoteworkers/RemoteWorkerController.h @@ -135,6 +135,8 @@ class RemoteWorkerController final { RefPtr ExecServiceWorkerOp( ServiceWorkerOpArgs&& aArgs); + RefPtr SetServiceWorkerSkipWaitingFlag() const; + private: RemoteWorkerController(const RemoteWorkerData& aData, RemoteWorkerObserver* aObserver); diff --git a/dom/workers/remoteworkers/RemoteWorkerControllerChild.cpp b/dom/workers/remoteworkers/RemoteWorkerControllerChild.cpp index e1bb107559b6..a346f4d0cb38 100644 --- a/dom/workers/remoteworkers/RemoteWorkerControllerChild.cpp +++ b/dom/workers/remoteworkers/RemoteWorkerControllerChild.cpp @@ -12,6 +12,7 @@ #include "nsError.h" #include "nsThreadUtils.h" +#include "ServiceWorkerPrivateImpl.h" #include "mozilla/Assertions.h" #include "mozilla/RefPtr.h" #include "mozilla/Unused.h" @@ -96,6 +97,27 @@ IPCResult RemoteWorkerControllerChild::RecvTerminated() { return IPC_OK(); } +IPCResult RemoteWorkerControllerChild::RecvSetServiceWorkerSkipWaitingFlag( + SetServiceWorkerSkipWaitingFlagResolver&& aResolve) { + AssertIsOnMainThread(); + + if (mObserver) { + static_cast(mObserver.get()) + ->SetSkipWaitingFlag() + ->Then(GetCurrentThreadSerialEventTarget(), __func__, + [resolve = std::move(aResolve)]( + const GenericPromise::ResolveOrRejectValue& aResult) { + resolve(aResult.IsResolve() ? aResult.ResolveValue() : false); + }); + + return IPC_OK(); + } + + aResolve(false); + + return IPC_OK(); +} + void RemoteWorkerControllerChild::RevokeObserver( RemoteWorkerObserver* aObserver) { AssertIsOnMainThread(); diff --git a/dom/workers/remoteworkers/RemoteWorkerControllerChild.h b/dom/workers/remoteworkers/RemoteWorkerControllerChild.h index 940d5dabb333..a27f16a9f668 100644 --- a/dom/workers/remoteworkers/RemoteWorkerControllerChild.h +++ b/dom/workers/remoteworkers/RemoteWorkerControllerChild.h @@ -48,6 +48,9 @@ class RemoteWorkerControllerChild final : public PRemoteWorkerControllerChild { mozilla::ipc::IPCResult RecvTerminated(); + mozilla::ipc::IPCResult RecvSetServiceWorkerSkipWaitingFlag( + SetServiceWorkerSkipWaitingFlagResolver&& aResolve); + RefPtr mObserver; bool mIPCActive = true; diff --git a/dom/workers/remoteworkers/RemoteWorkerControllerParent.cpp b/dom/workers/remoteworkers/RemoteWorkerControllerParent.cpp index 9fb124648ce1..88282d38f202 100644 --- a/dom/workers/remoteworkers/RemoteWorkerControllerParent.cpp +++ b/dom/workers/remoteworkers/RemoteWorkerControllerParent.cpp @@ -42,6 +42,25 @@ RefPtr RemoteWorkerControllerParent::GetRemoteWorkerParent() return mRemoteWorkerController->mActor; } +void RemoteWorkerControllerParent::MaybeSendSetServiceWorkerSkipWaitingFlag( + std::function&& aCallback) { + AssertIsOnBackgroundThread(); + MOZ_ASSERT(aCallback); + + if (!mIPCActive) { + aCallback(false); + return; + } + + SendSetServiceWorkerSkipWaitingFlag()->Then( + GetCurrentThreadSerialEventTarget(), __func__, + [callback = std::move(aCallback)]( + const SetServiceWorkerSkipWaitingFlagPromise::ResolveOrRejectValue& + aResult) { + callback(aResult.IsResolve() ? aResult.ResolveValue() : false); + }); +} + RemoteWorkerControllerParent::~RemoteWorkerControllerParent() { AssertIsOnBackgroundThread(); MOZ_ASSERT(!mIPCActive); diff --git a/dom/workers/remoteworkers/RemoteWorkerControllerParent.h b/dom/workers/remoteworkers/RemoteWorkerControllerParent.h index d6d04e094121..10a98472bbe5 100644 --- a/dom/workers/remoteworkers/RemoteWorkerControllerParent.h +++ b/dom/workers/remoteworkers/RemoteWorkerControllerParent.h @@ -31,6 +31,9 @@ class RemoteWorkerControllerParent final : public PRemoteWorkerControllerParent, // Returns the corresponding RemoteWorkerParent (if any). RefPtr GetRemoteWorkerParent() const; + void MaybeSendSetServiceWorkerSkipWaitingFlag( + std::function&& aCallback); + private: ~RemoteWorkerControllerParent(); diff --git a/dom/workers/remoteworkers/RemoteWorkerParent.cpp b/dom/workers/remoteworkers/RemoteWorkerParent.cpp index 485cc3b2cd94..1ddeefb6d285 100644 --- a/dom/workers/remoteworkers/RemoteWorkerParent.cpp +++ b/dom/workers/remoteworkers/RemoteWorkerParent.cpp @@ -165,5 +165,22 @@ void RemoteWorkerParent::SetController(RemoteWorkerController* aController) { mController = aController; } +IPCResult RemoteWorkerParent::RecvSetServiceWorkerSkipWaitingFlag( + SetServiceWorkerSkipWaitingFlagResolver&& aResolve) { + AssertIsOnBackgroundThread(); + MOZ_ASSERT(XRE_IsParentProcess()); + + if (mController) { + mController->SetServiceWorkerSkipWaitingFlag()->Then( + GetCurrentThreadSerialEventTarget(), __func__, + [resolve = aResolve](bool /* unused */) { resolve(true); }, + [resolve = aResolve](nsresult /* unused */) { resolve(false); }); + } else { + aResolve(false); + } + + return IPC_OK(); +} + } // namespace dom } // namespace mozilla diff --git a/dom/workers/remoteworkers/RemoteWorkerParent.h b/dom/workers/remoteworkers/RemoteWorkerParent.h index 54637f1225b7..ce62b00ff743 100644 --- a/dom/workers/remoteworkers/RemoteWorkerParent.h +++ b/dom/workers/remoteworkers/RemoteWorkerParent.h @@ -44,6 +44,9 @@ class RemoteWorkerParent final : public PRemoteWorkerParent { mozilla::ipc::IPCResult RecvCreated(const bool& aStatus); + mozilla::ipc::IPCResult RecvSetServiceWorkerSkipWaitingFlag( + SetServiceWorkerSkipWaitingFlagResolver&& aResolve); + bool mDeleteSent = false; RefPtr mController; }; diff --git a/dom/workers/remoteworkers/moz.build b/dom/workers/remoteworkers/moz.build index e014467b3bef..a512f8ed53f6 100644 --- a/dom/workers/remoteworkers/moz.build +++ b/dom/workers/remoteworkers/moz.build @@ -28,6 +28,7 @@ UNIFIED_SOURCES += [ ] LOCAL_INCLUDES += [ + '/dom/serviceworkers', '/xpcom/build', ]