mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 23:02:20 +00:00
Bug 1459209 P13 Implement RemoteServiceWorkerContainerImpl::GetRegistration() across IPC to the parent-side SWM. r=mrbkap
--HG-- extra : rebase_source : 60f674e9d1d5c0701f6ed3145427ad8fc7012e55
This commit is contained in:
parent
4207daa618
commit
be03ee0457
@ -21,6 +21,9 @@ parent:
|
||||
ServiceWorkerUpdateViaCache aUpdateViaCache)
|
||||
returns (IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult aResult);
|
||||
|
||||
async GetRegistration(IPCClientInfo aClientInfo, nsCString aURL)
|
||||
returns (IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult aResult);
|
||||
|
||||
child:
|
||||
async __delete__();
|
||||
};
|
||||
|
@ -94,7 +94,29 @@ RemoteServiceWorkerContainerImpl::GetRegistration(const ClientInfo& aClientInfo,
|
||||
ServiceWorkerRegistrationCallback&& aSuccessCB,
|
||||
ServiceWorkerFailureCallback&& aFailureCB) const
|
||||
{
|
||||
// TODO
|
||||
if (!mActor) {
|
||||
aFailureCB(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
|
||||
return;
|
||||
}
|
||||
|
||||
mActor->SendGetRegistration(aClientInfo.ToIPC(), nsCString(aURL),
|
||||
[successCB = std::move(aSuccessCB), aFailureCB]
|
||||
(const IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult& aResult) {
|
||||
if (aResult.type() == IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult::TCopyableErrorResult) {
|
||||
auto& rv = aResult.get_CopyableErrorResult();
|
||||
// If rv is a failure then this is an application layer error. Note,
|
||||
// though, we also reject with NS_OK to indicate that we just didn't
|
||||
// find a registration.
|
||||
aFailureCB(CopyableErrorResult(rv));
|
||||
return;
|
||||
}
|
||||
// success
|
||||
auto& ipcDesc = aResult.get_IPCServiceWorkerRegistrationDescriptor();
|
||||
successCB(ServiceWorkerRegistrationDescriptor(ipcDesc));
|
||||
}, [aFailureCB] (ResponseRejectReason aReason) {
|
||||
// IPC layer error
|
||||
aFailureCB(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -52,6 +52,27 @@ ServiceWorkerContainerParent::RecvRegister(const IPCClientInfo& aClientInfo,
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
IPCResult
|
||||
ServiceWorkerContainerParent::RecvGetRegistration(const IPCClientInfo& aClientInfo,
|
||||
const nsCString& aURL,
|
||||
GetRegistrationResolver&& aResolver)
|
||||
{
|
||||
if (!mProxy) {
|
||||
aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mProxy->GetRegistration(ClientInfo(aClientInfo), aURL)->Then(
|
||||
GetCurrentThreadSerialEventTarget(), __func__,
|
||||
[aResolver] (const ServiceWorkerRegistrationDescriptor& aDescriptor) {
|
||||
aResolver(aDescriptor.ToIPC());
|
||||
}, [aResolver] (const CopyableErrorResult& aResult) {
|
||||
aResolver(aResult);
|
||||
});
|
||||
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
ServiceWorkerContainerParent::ServiceWorkerContainerParent()
|
||||
{
|
||||
}
|
||||
|
@ -32,6 +32,11 @@ class ServiceWorkerContainerParent final : public PServiceWorkerContainerParent
|
||||
const ServiceWorkerUpdateViaCache& aUpdateViaCache,
|
||||
RegisterResolver&& aResolver) override;
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
RecvGetRegistration(const IPCClientInfo& aClientInfo,
|
||||
const nsCString& aURL,
|
||||
GetRegistrationResolver&& aResolver) override;
|
||||
|
||||
public:
|
||||
ServiceWorkerContainerParent();
|
||||
~ServiceWorkerContainerParent();
|
||||
|
@ -70,5 +70,34 @@ ServiceWorkerContainerProxy::Register(const ClientInfo& aClientInfo,
|
||||
return promise;
|
||||
}
|
||||
|
||||
RefPtr<ServiceWorkerRegistrationPromise>
|
||||
ServiceWorkerContainerProxy::GetRegistration(const ClientInfo& aClientInfo,
|
||||
const nsCString& aURL)
|
||||
{
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
RefPtr<ServiceWorkerRegistrationPromise::Private> promise =
|
||||
new ServiceWorkerRegistrationPromise::Private(__func__);
|
||||
|
||||
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(__func__,
|
||||
[aClientInfo, aURL, promise] () mutable {
|
||||
auto scopeExit = MakeScopeExit([&] {
|
||||
promise->Reject(NS_ERROR_DOM_INVALID_STATE_ERR, __func__);
|
||||
});
|
||||
|
||||
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
||||
NS_ENSURE_TRUE_VOID(swm);
|
||||
|
||||
swm->GetRegistration(aClientInfo, aURL)->ChainTo(promise.forget(),
|
||||
__func__);
|
||||
|
||||
scopeExit.release();
|
||||
});
|
||||
|
||||
MOZ_ALWAYS_SUCCEEDS(SystemGroup::Dispatch(TaskCategory::Other, r.forget()));
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -30,6 +30,9 @@ public:
|
||||
const nsCString& aScriptURL,
|
||||
ServiceWorkerUpdateViaCache aUpdateViaCache);
|
||||
|
||||
RefPtr<ServiceWorkerRegistrationPromise>
|
||||
GetRegistration(const ClientInfo& aClientInfo, const nsCString& aURL);
|
||||
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ServiceWorkerContainerProxy);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user