2018-07-09 23:02:39 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "ServiceWorkerRegistrationParent.h"
|
|
|
|
|
2020-01-08 03:21:27 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2018-07-09 23:02:40 +00:00
|
|
|
#include "ServiceWorkerRegistrationProxy.h"
|
|
|
|
|
2022-05-09 20:41:14 +00:00
|
|
|
namespace mozilla::dom {
|
2018-07-09 23:02:39 +00:00
|
|
|
|
|
|
|
using mozilla::ipc::IPCResult;
|
|
|
|
|
|
|
|
void ServiceWorkerRegistrationParent::ActorDestroy(ActorDestroyReason aReason) {
|
2018-07-09 23:02:40 +00:00
|
|
|
if (mProxy) {
|
|
|
|
mProxy->RevokeActor(this);
|
|
|
|
mProxy = nullptr;
|
|
|
|
}
|
2018-07-09 23:02:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IPCResult ServiceWorkerRegistrationParent::RecvTeardown() {
|
2018-07-09 23:02:40 +00:00
|
|
|
MaybeSendDelete();
|
2018-07-09 23:02:39 +00:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2018-07-09 23:02:40 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
void ResolveUnregister(
|
|
|
|
PServiceWorkerRegistrationParent::UnregisterResolver&& aResolver,
|
|
|
|
bool aSuccess, nsresult aRv) {
|
2023-03-27 07:20:25 +00:00
|
|
|
aResolver(std::tuple<const bool&, const CopyableErrorResult&>(
|
2018-07-09 23:02:40 +00:00
|
|
|
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(
|
2020-06-23 05:05:36 +00:00
|
|
|
GetCurrentSerialEventTarget(), __func__,
|
2018-07-09 23:02:40 +00:00
|
|
|
[aResolver](bool aSuccess) mutable {
|
|
|
|
ResolveUnregister(std::move(aResolver), aSuccess, NS_OK);
|
|
|
|
},
|
|
|
|
[aResolver](nsresult aRv) mutable {
|
|
|
|
ResolveUnregister(std::move(aResolver), false, aRv);
|
|
|
|
});
|
|
|
|
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2018-07-09 23:02:40 +00:00
|
|
|
IPCResult ServiceWorkerRegistrationParent::RecvUpdate(
|
2022-07-25 20:19:48 +00:00
|
|
|
const nsACString& aNewestWorkerScriptUrl, UpdateResolver&& aResolver) {
|
2018-07-09 23:02:40 +00:00
|
|
|
if (!mProxy) {
|
|
|
|
aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2020-01-08 03:21:27 +00:00
|
|
|
mProxy->Update(aNewestWorkerScriptUrl)
|
|
|
|
->Then(
|
2020-06-23 05:05:36 +00:00
|
|
|
GetCurrentSerialEventTarget(), __func__,
|
2020-01-08 03:21:27 +00:00
|
|
|
[aResolver](const ServiceWorkerRegistrationDescriptor& aDescriptor) {
|
|
|
|
aResolver(aDescriptor.ToIPC());
|
|
|
|
},
|
|
|
|
[aResolver](const CopyableErrorResult& aResult) {
|
|
|
|
aResolver(aResult);
|
|
|
|
});
|
2018-07-09 23:02:40 +00:00
|
|
|
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2021-06-10 06:01:27 +00:00
|
|
|
IPCResult ServiceWorkerRegistrationParent::RecvSetNavigationPreloadEnabled(
|
|
|
|
const bool& aEnabled, SetNavigationPreloadEnabledResolver&& aResolver) {
|
2021-06-10 06:01:27 +00:00
|
|
|
if (!mProxy) {
|
|
|
|
aResolver(false);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
mProxy->SetNavigationPreloadEnabled(aEnabled)->Then(
|
|
|
|
GetCurrentSerialEventTarget(), __func__,
|
|
|
|
[aResolver](bool) { aResolver(true); },
|
|
|
|
[aResolver](nsresult) { aResolver(false); });
|
|
|
|
|
2021-06-10 06:01:27 +00:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
IPCResult ServiceWorkerRegistrationParent::RecvSetNavigationPreloadHeader(
|
2022-07-25 20:19:48 +00:00
|
|
|
const nsACString& aHeader, SetNavigationPreloadHeaderResolver&& aResolver) {
|
2021-06-10 06:01:27 +00:00
|
|
|
if (!mProxy) {
|
|
|
|
aResolver(false);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
mProxy->SetNavigationPreloadHeader(aHeader)->Then(
|
|
|
|
GetCurrentSerialEventTarget(), __func__,
|
|
|
|
[aResolver](bool) { aResolver(true); },
|
|
|
|
[aResolver](nsresult) { aResolver(false); });
|
|
|
|
|
2021-06-10 06:01:27 +00:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
IPCResult ServiceWorkerRegistrationParent::RecvGetNavigationPreloadState(
|
|
|
|
GetNavigationPreloadStateResolver&& aResolver) {
|
2021-06-10 06:01:27 +00:00
|
|
|
if (!mProxy) {
|
|
|
|
aResolver(Nothing());
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
mProxy->GetNavigationPreloadState()->Then(
|
|
|
|
GetCurrentSerialEventTarget(), __func__,
|
|
|
|
[aResolver](const IPCNavigationPreloadState& aState) {
|
|
|
|
aResolver(Some(aState));
|
|
|
|
},
|
|
|
|
[aResolver](const CopyableErrorResult& aResult) {
|
|
|
|
aResolver(Nothing());
|
|
|
|
});
|
|
|
|
|
2021-06-10 06:01:27 +00:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2018-07-09 23:02:40 +00:00
|
|
|
ServiceWorkerRegistrationParent::ServiceWorkerRegistrationParent()
|
|
|
|
: mDeleteSent(false) {}
|
|
|
|
|
|
|
|
ServiceWorkerRegistrationParent::~ServiceWorkerRegistrationParent() {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mProxy);
|
|
|
|
}
|
|
|
|
|
2018-07-09 23:02:39 +00:00
|
|
|
void ServiceWorkerRegistrationParent::Init(
|
2024-10-24 03:02:41 +00:00
|
|
|
const IPCServiceWorkerRegistrationDescriptor& aDescriptor,
|
|
|
|
const IPCClientInfo& aForClient) {
|
2018-07-09 23:02:40 +00:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mProxy);
|
|
|
|
mProxy = new ServiceWorkerRegistrationProxy(
|
2024-10-24 03:02:41 +00:00
|
|
|
ServiceWorkerRegistrationDescriptor(aDescriptor), ClientInfo(aForClient));
|
2018-07-09 23:02:40 +00:00
|
|
|
mProxy->Init(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServiceWorkerRegistrationParent::MaybeSendDelete() {
|
|
|
|
if (mDeleteSent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mDeleteSent = true;
|
|
|
|
Unused << Send__delete__(this);
|
2018-07-09 23:02:39 +00:00
|
|
|
}
|
|
|
|
|
2022-05-09 20:41:14 +00:00
|
|
|
} // namespace mozilla::dom
|