From 55f1da5063785edb8c73ee02ad74486ac80ed0e2 Mon Sep 17 00:00:00 2001 From: Perry Jiang Date: Wed, 14 Aug 2019 16:20:17 +0000 Subject: [PATCH] Bug 1231213 - Let ServiceWorkerOpArgs be sent from the parent process to a content process. r=asuth The args are sent from the parent process main thread to the parent process background thread and then from the background thread to a content process worker launcher thread. Differential Revision: https://phabricator.services.mozilla.com/D26173 --HG-- extra : moz-landing-system : lando --- dom/workers/remoteworkers/PRemoteWorker.ipdl | 3 ++ .../PRemoteWorkerController.ipdl | 2 ++ .../remoteworkers/RemoteWorkerChild.cpp | 13 ++++++++ dom/workers/remoteworkers/RemoteWorkerChild.h | 3 ++ .../remoteworkers/RemoteWorkerController.cpp | 31 +++++++++++++++++++ .../remoteworkers/RemoteWorkerController.h | 3 ++ .../RemoteWorkerControllerParent.cpp | 23 ++++++++++++++ .../RemoteWorkerControllerParent.h | 3 ++ 8 files changed, 81 insertions(+) diff --git a/dom/workers/remoteworkers/PRemoteWorker.ipdl b/dom/workers/remoteworkers/PRemoteWorker.ipdl index 2107ff597167..b46dd52639f4 100644 --- a/dom/workers/remoteworkers/PRemoteWorker.ipdl +++ b/dom/workers/remoteworkers/PRemoteWorker.ipdl @@ -75,6 +75,9 @@ child: async __delete__(); async ExecOp(RemoteWorkerOp op); + + async ExecServiceWorkerOp(ServiceWorkerOpArgs aArgs) + returns (ServiceWorkerOpResult aResult); }; } // namespace dom diff --git a/dom/workers/remoteworkers/PRemoteWorkerController.ipdl b/dom/workers/remoteworkers/PRemoteWorkerController.ipdl index 7e5cfa7b0a42..1a948f40a8cb 100644 --- a/dom/workers/remoteworkers/PRemoteWorkerController.ipdl +++ b/dom/workers/remoteworkers/PRemoteWorkerController.ipdl @@ -32,6 +32,8 @@ protocol PRemoteWorkerController { async Shutdown() returns (bool aOk); + async ExecServiceWorkerOp(ServiceWorkerOpArgs aArgs) + returns (ServiceWorkerOpResult aResult); }; } // namespace dom diff --git a/dom/workers/remoteworkers/RemoteWorkerChild.cpp b/dom/workers/remoteworkers/RemoteWorkerChild.cpp index c3a4a9239d1a..13c7c58d1ddb 100644 --- a/dom/workers/remoteworkers/RemoteWorkerChild.cpp +++ b/dom/workers/remoteworkers/RemoteWorkerChild.cpp @@ -34,6 +34,7 @@ #include "mozilla/dom/RemoteWorkerTypes.h" #include "mozilla/dom/ServiceWorkerDescriptor.h" #include "mozilla/dom/ServiceWorkerInterceptController.h" +#include "mozilla/dom/ServiceWorkerOp.h" #include "mozilla/dom/ServiceWorkerRegistrationDescriptor.h" #include "mozilla/dom/ServiceWorkerUtils.h" #include "mozilla/dom/workerinternals/ScriptLoader.h" @@ -923,6 +924,18 @@ IPCResult RemoteWorkerChild::RecvExecOp(RemoteWorkerOp&& aOp) { return IPC_OK(); } +IPCResult RemoteWorkerChild::RecvExecServiceWorkerOp( + ServiceWorkerOpArgs&& aArgs, ExecServiceWorkerOpResolver&& aResolve) { + MOZ_ASSERT(mIsServiceWorker); + MOZ_ASSERT( + aArgs.type() != ServiceWorkerOpArgs::TServiceWorkerFetchEventOpArgs, + "FetchEvent operations should be sent via PFetchEventOp(Proxy) actors!"); + + MaybeStartOp(ServiceWorkerOp::Create(aArgs, std::move(aResolve))); + + return IPC_OK(); +} + /** * PFetchEventOpProxy methods */ diff --git a/dom/workers/remoteworkers/RemoteWorkerChild.h b/dom/workers/remoteworkers/RemoteWorkerChild.h index 8e21975fb156..d86f546a65d1 100644 --- a/dom/workers/remoteworkers/RemoteWorkerChild.h +++ b/dom/workers/remoteworkers/RemoteWorkerChild.h @@ -105,6 +105,9 @@ class RemoteWorkerChild final mozilla::ipc::IPCResult RecvExecOp(RemoteWorkerOp&& aOp); + mozilla::ipc::IPCResult RecvExecServiceWorkerOp( + ServiceWorkerOpArgs&& aArgs, ExecServiceWorkerOpResolver&& aResolve); + PFetchEventOpProxyChild* AllocPFetchEventOpProxyChild( const ServiceWorkerFetchEventOpArgs& aArgs); diff --git a/dom/workers/remoteworkers/RemoteWorkerController.cpp b/dom/workers/remoteworkers/RemoteWorkerController.cpp index df927ea27ddf..a6cd8afa563f 100644 --- a/dom/workers/remoteworkers/RemoteWorkerController.cpp +++ b/dom/workers/remoteworkers/RemoteWorkerController.cpp @@ -260,6 +260,24 @@ void RemoteWorkerController::Thaw() { MaybeStartSharedWorkerOp(PendingSharedWorkerOp::eThaw); } +RefPtr RemoteWorkerController::ExecServiceWorkerOp( + ServiceWorkerOpArgs&& aArgs) { + AssertIsOnBackgroundThread(); + MOZ_ASSERT(mIsServiceWorker); + + RefPtr promise = + new ServiceWorkerOpPromise::Private(__func__); + + UniquePtr op = + MakeUnique(std::move(aArgs), promise); + + if (!op->MaybeStart(this)) { + mPendingOps.AppendElement(std::move(op)); + } + + return promise; +} + RemoteWorkerController::PendingSharedWorkerOp::PendingSharedWorkerOp( Type aType, uint64_t aWindowID) : mType(aType), mWindowID(aWindowID) { @@ -403,6 +421,19 @@ bool RemoteWorkerController::PendingServiceWorkerOp::MaybeStart( mArgs = std::move(copyArgs); } + aOwner->mActor->SendExecServiceWorkerOp(mArgs)->Then( + GetCurrentThreadSerialEventTarget(), __func__, + [promise = std::move(mPromise)]( + PRemoteWorkerParent::ExecServiceWorkerOpPromise:: + ResolveOrRejectValue&& aResult) { + if (NS_WARN_IF(aResult.IsReject())) { + promise->Reject(NS_ERROR_DOM_ABORT_ERR, __func__); + return; + } + + promise->Resolve(std::move(aResult.ResolveValue()), __func__); + }); + return true; } diff --git a/dom/workers/remoteworkers/RemoteWorkerController.h b/dom/workers/remoteworkers/RemoteWorkerController.h index 8063d2b71968..bf244bedc455 100644 --- a/dom/workers/remoteworkers/RemoteWorkerController.h +++ b/dom/workers/remoteworkers/RemoteWorkerController.h @@ -132,6 +132,9 @@ class RemoteWorkerController final { void Thaw(); + RefPtr ExecServiceWorkerOp( + ServiceWorkerOpArgs&& aArgs); + private: RemoteWorkerController(const RemoteWorkerData& aData, RemoteWorkerObserver* aObserver); diff --git a/dom/workers/remoteworkers/RemoteWorkerControllerParent.cpp b/dom/workers/remoteworkers/RemoteWorkerControllerParent.cpp index ccf699481e93..9fb124648ce1 100644 --- a/dom/workers/remoteworkers/RemoteWorkerControllerParent.cpp +++ b/dom/workers/remoteworkers/RemoteWorkerControllerParent.cpp @@ -16,6 +16,7 @@ #include "mozilla/Assertions.h" #include "mozilla/Unused.h" #include "mozilla/dom/FetchEventOpParent.h" +#include "mozilla/dom/ServiceWorkerOpPromise.h" #include "mozilla/ipc/BackgroundParent.h" namespace mozilla { @@ -75,6 +76,28 @@ bool RemoteWorkerControllerParent::DeallocPFetchEventOpParent( return true; } +IPCResult RemoteWorkerControllerParent::RecvExecServiceWorkerOp( + ServiceWorkerOpArgs&& aArgs, ExecServiceWorkerOpResolver&& aResolve) { + AssertIsOnBackgroundThread(); + MOZ_ASSERT(mIPCActive); + MOZ_ASSERT(mRemoteWorkerController); + + mRemoteWorkerController->ExecServiceWorkerOp(std::move(aArgs)) + ->Then(GetCurrentThreadSerialEventTarget(), __func__, + [resolve = std::move(aResolve)]( + ServiceWorkerOpPromise::ResolveOrRejectValue&& aResult) { + if (NS_WARN_IF(aResult.IsReject())) { + MOZ_ASSERT(NS_FAILED(aResult.RejectValue())); + resolve(aResult.RejectValue()); + return; + } + + resolve(aResult.ResolveValue()); + }); + + return IPC_OK(); +} + IPCResult RemoteWorkerControllerParent::RecvShutdown( ShutdownResolver&& aResolve) { AssertIsOnBackgroundThread(); diff --git a/dom/workers/remoteworkers/RemoteWorkerControllerParent.h b/dom/workers/remoteworkers/RemoteWorkerControllerParent.h index 9bc77678e9af..d6d04e094121 100644 --- a/dom/workers/remoteworkers/RemoteWorkerControllerParent.h +++ b/dom/workers/remoteworkers/RemoteWorkerControllerParent.h @@ -43,6 +43,9 @@ class RemoteWorkerControllerParent final : public PRemoteWorkerControllerParent, bool DeallocPFetchEventOpParent(PFetchEventOpParent* aActor); + mozilla::ipc::IPCResult RecvExecServiceWorkerOp( + ServiceWorkerOpArgs&& aArgs, ExecServiceWorkerOpResolver&& aResolve); + mozilla::ipc::IPCResult RecvShutdown(ShutdownResolver&& aResolve); mozilla::ipc::IPCResult Recv__delete__() override;