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:
Ben Kelly 2018-07-09 16:02:40 -07:00
parent 4207daa618
commit be03ee0457
6 changed files with 84 additions and 1 deletions

View File

@ -21,6 +21,9 @@ parent:
ServiceWorkerUpdateViaCache aUpdateViaCache)
returns (IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult aResult);
async GetRegistration(IPCClientInfo aClientInfo, nsCString aURL)
returns (IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult aResult);
child:
async __delete__();
};

View File

@ -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

View File

@ -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()
{
}

View File

@ -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();

View File

@ -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

View File

@ -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);
};