mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 1459209 P10 Implement RemoteServiceWorkerRegistrationImpl::Unregister() across IPC to the parent-side SWM. r=mrbkap
--HG-- extra : rebase_source : 8411bc26ff172a9888e040fc09b21cab745e4161
This commit is contained in:
parent
94f85205a9
commit
39b1a104c9
@ -16,6 +16,7 @@ protocol PServiceWorkerRegistration
|
||||
parent:
|
||||
async Teardown();
|
||||
|
||||
async Unregister() returns (bool aSuccess, CopyableErrorResult aRv);
|
||||
async Update() returns (IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult aResult);
|
||||
|
||||
child:
|
||||
|
@ -85,7 +85,25 @@ void
|
||||
RemoteServiceWorkerRegistrationImpl::Unregister(ServiceWorkerBoolCallback&& aSuccessCB,
|
||||
ServiceWorkerFailureCallback&& aFailureCB)
|
||||
{
|
||||
// TODO
|
||||
if (!mActor) {
|
||||
aFailureCB(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
|
||||
return;
|
||||
}
|
||||
|
||||
mActor->SendUnregister(
|
||||
[successCB = std::move(aSuccessCB), aFailureCB]
|
||||
(Tuple<bool, CopyableErrorResult>&& aResult) {
|
||||
if (Get<1>(aResult).Failed()) {
|
||||
// application layer error
|
||||
aFailureCB(Get<1>(aResult));
|
||||
return;
|
||||
}
|
||||
// success
|
||||
successCB(Get<0>(aResult));
|
||||
}, [aFailureCB] (ResponseRejectReason aReason) {
|
||||
// IPC layer error
|
||||
aFailureCB(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
|
||||
});
|
||||
}
|
||||
|
||||
RemoteServiceWorkerRegistrationImpl::RemoteServiceWorkerRegistrationImpl(const ServiceWorkerRegistrationDescriptor& aDescriptor)
|
||||
|
@ -29,6 +29,36 @@ ServiceWorkerRegistrationParent::RecvTeardown()
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void
|
||||
ResolveUnregister(PServiceWorkerRegistrationParent::UnregisterResolver&& aResolver,
|
||||
bool aSuccess, nsresult aRv)
|
||||
{
|
||||
aResolver(Tuple<const bool&, const CopyableErrorResult&>(
|
||||
aSuccess, CopyableErrorResult(aRv)));
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
IPCResult
|
||||
ServiceWorkerRegistrationParent::RecvUnregister(UnregisterResolver&& aResolver)
|
||||
{
|
||||
if (!mProxy) {
|
||||
ResolveUnregister(std::move(aResolver), false, NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mProxy->Unregister()->Then(GetCurrentThreadSerialEventTarget(), __func__,
|
||||
[aResolver] (bool aSuccess) mutable {
|
||||
ResolveUnregister(std::move(aResolver), aSuccess, NS_OK);
|
||||
}, [aResolver] (nsresult aRv) mutable {
|
||||
ResolveUnregister(std::move(aResolver), false, aRv);
|
||||
});
|
||||
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
IPCResult
|
||||
ServiceWorkerRegistrationParent::RecvUpdate(UpdateResolver&& aResolver)
|
||||
{
|
||||
|
@ -27,6 +27,9 @@ class ServiceWorkerRegistrationParent final : public PServiceWorkerRegistrationP
|
||||
mozilla::ipc::IPCResult
|
||||
RecvTeardown() override;
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
RecvUnregister(UnregisterResolver&& aResolver) override;
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
RecvUpdate(UpdateResolver&& aResolver) override;
|
||||
|
||||
|
@ -172,6 +172,78 @@ ServiceWorkerRegistrationProxy::RevokeActor(ServiceWorkerRegistrationParent* aAc
|
||||
|
||||
namespace {
|
||||
|
||||
class UnregisterCallback final : public nsIServiceWorkerUnregisterCallback
|
||||
{
|
||||
RefPtr<GenericPromise::Private> mPromise;
|
||||
|
||||
~UnregisterCallback() = default;
|
||||
|
||||
public:
|
||||
explicit UnregisterCallback(GenericPromise::Private* aPromise)
|
||||
: mPromise(aPromise)
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(mPromise);
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
UnregisterSucceeded(bool aState) override
|
||||
{
|
||||
mPromise->Resolve(aState, __func__);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
UnregisterFailed() override
|
||||
{
|
||||
mPromise->Reject(NS_ERROR_DOM_SECURITY_ERR, __func__);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(UnregisterCallback, nsIServiceWorkerUnregisterCallback)
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
RefPtr<GenericPromise>
|
||||
ServiceWorkerRegistrationProxy::Unregister()
|
||||
{
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
RefPtr<ServiceWorkerRegistrationProxy> self = this;
|
||||
RefPtr<GenericPromise::Private> promise =
|
||||
new GenericPromise::Private(__func__);
|
||||
|
||||
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(__func__,
|
||||
[self, promise] () mutable {
|
||||
nsresult rv = NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
auto scopeExit = MakeScopeExit([&] {
|
||||
promise->Reject(rv, __func__);
|
||||
});
|
||||
|
||||
NS_ENSURE_TRUE_VOID(self->mReg);
|
||||
|
||||
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
||||
NS_ENSURE_TRUE_VOID(swm);
|
||||
|
||||
RefPtr<UnregisterCallback> cb = new UnregisterCallback(promise);
|
||||
|
||||
rv = swm->Unregister(self->mReg->Principal(), cb,
|
||||
NS_ConvertUTF8toUTF16(self->mReg->Scope()));
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
|
||||
|
||||
scopeExit.release();
|
||||
});
|
||||
|
||||
MOZ_ALWAYS_SUCCEEDS(SystemGroup::Dispatch(TaskCategory::Other, r.forget()));
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class UpdateCallback final : public ServiceWorkerUpdateFinishCallback
|
||||
{
|
||||
RefPtr<ServiceWorkerRegistrationPromise::Private> mPromise;
|
||||
|
@ -72,6 +72,9 @@ public:
|
||||
void
|
||||
RevokeActor(ServiceWorkerRegistrationParent* aActor);
|
||||
|
||||
RefPtr<GenericPromise>
|
||||
Unregister();
|
||||
|
||||
RefPtr<ServiceWorkerRegistrationPromise>
|
||||
Update();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user