Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / dom / serviceworkers / ServiceWorkerManagerParent.cpp
blobd2d0a6427557aab58c599122bf7b84d6ad9658fe
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "ServiceWorkerManagerParent.h"
8 #include "ServiceWorkerUtils.h"
9 #include "mozilla/dom/ContentParent.h"
10 #include "mozilla/dom/ServiceWorkerRegistrar.h"
11 #include "mozilla/ipc/BackgroundParent.h"
12 #include "mozilla/ipc/BackgroundUtils.h"
13 #include "mozilla/Unused.h"
14 #include "nsThreadUtils.h"
16 namespace mozilla {
18 using namespace ipc;
20 namespace dom {
22 ServiceWorkerManagerParent::ServiceWorkerManagerParent() {
23 AssertIsOnBackgroundThread();
26 ServiceWorkerManagerParent::~ServiceWorkerManagerParent() {
27 AssertIsOnBackgroundThread();
30 mozilla::ipc::IPCResult ServiceWorkerManagerParent::RecvRegister(
31 const ServiceWorkerRegistrationData& aData) {
32 AssertIsInMainProcess();
33 AssertIsOnBackgroundThread();
34 MOZ_ASSERT(!BackgroundParent::IsOtherProcessActor(Manager()));
36 // Basic validation.
37 if (aData.scope().IsEmpty() ||
38 aData.principal().type() == PrincipalInfo::TNullPrincipalInfo ||
39 aData.principal().type() == PrincipalInfo::TSystemPrincipalInfo) {
40 return IPC_FAIL_NO_REASON(this);
43 // If false then we have shutdown during the process of trying to update the
44 // registrar. We can give up on this modification.
45 if (const RefPtr<dom::ServiceWorkerRegistrar> service =
46 dom::ServiceWorkerRegistrar::Get()) {
47 service->RegisterServiceWorker(aData);
50 return IPC_OK();
53 mozilla::ipc::IPCResult ServiceWorkerManagerParent::RecvUnregister(
54 const PrincipalInfo& aPrincipalInfo, const nsString& aScope) {
55 AssertIsInMainProcess();
56 AssertIsOnBackgroundThread();
57 MOZ_ASSERT(!BackgroundParent::IsOtherProcessActor(Manager()));
59 // Basic validation.
60 if (aScope.IsEmpty() ||
61 aPrincipalInfo.type() == PrincipalInfo::TNullPrincipalInfo ||
62 aPrincipalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) {
63 return IPC_FAIL_NO_REASON(this);
66 // If false then we have shutdown during the process of trying to update the
67 // registrar. We can give up on this modification.
68 if (const RefPtr<dom::ServiceWorkerRegistrar> service =
69 dom::ServiceWorkerRegistrar::Get()) {
70 service->UnregisterServiceWorker(aPrincipalInfo,
71 NS_ConvertUTF16toUTF8(aScope));
74 return IPC_OK();
77 mozilla::ipc::IPCResult ServiceWorkerManagerParent::RecvPropagateUnregister(
78 const PrincipalInfo& aPrincipalInfo, const nsString& aScope) {
79 AssertIsOnBackgroundThread();
81 RefPtr<dom::ServiceWorkerRegistrar> service =
82 dom::ServiceWorkerRegistrar::Get();
83 MOZ_ASSERT(service);
85 // It's possible that we don't have any ServiceWorkerManager managing this
86 // scope but we still need to unregister it from the ServiceWorkerRegistrar.
87 service->UnregisterServiceWorker(aPrincipalInfo,
88 NS_ConvertUTF16toUTF8(aScope));
90 // There is no longer any point to propagating because the only sender is the
91 // one and only ServiceWorkerManager, but it is necessary for us to have run
92 // the unregister call above because until Bug 1183245 is fixed,
93 // nsIServiceWorkerManager.propagateUnregister() is a de facto API for
94 // clearing ServiceWorker registrations by Sanitizer.sys.mjs via
95 // ServiceWorkerCleanUp.sys.mjs, as well as devtools "unregister" affordance
96 // and the no-longer-relevant about:serviceworkers UI.
98 return IPC_OK();
101 void ServiceWorkerManagerParent::ActorDestroy(ActorDestroyReason aWhy) {
102 AssertIsOnBackgroundThread();
105 } // namespace dom
106 } // namespace mozilla