Source code

Revision control

Other Tools

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/. */
6
7
#include "ServiceWorkerManagerChild.h"
8
#include "ServiceWorkerManager.h"
9
#include "ServiceWorkerUpdaterChild.h"
10
#include "mozilla/Unused.h"
11
12
namespace mozilla {
13
14
using namespace ipc;
15
16
namespace dom {
17
18
mozilla::ipc::IPCResult ServiceWorkerManagerChild::RecvNotifyRegister(
19
const ServiceWorkerRegistrationData& aData) {
20
if (mShuttingDown) {
21
return IPC_OK();
22
}
23
24
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
25
if (swm) {
26
swm->LoadRegistration(aData);
27
}
28
29
return IPC_OK();
30
}
31
32
mozilla::ipc::IPCResult ServiceWorkerManagerChild::RecvNotifySoftUpdate(
33
const OriginAttributes& aOriginAttributes, const nsString& aScope) {
34
if (mShuttingDown) {
35
return IPC_OK();
36
}
37
38
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
39
if (swm) {
40
swm->SoftUpdate(aOriginAttributes, NS_ConvertUTF16toUTF8(aScope));
41
}
42
43
return IPC_OK();
44
}
45
46
mozilla::ipc::IPCResult ServiceWorkerManagerChild::RecvNotifyUnregister(
47
const PrincipalInfo& aPrincipalInfo, const nsString& aScope) {
48
if (mShuttingDown) {
49
return IPC_OK();
50
}
51
52
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
53
if (!swm) {
54
// browser shutdown
55
return IPC_OK();
56
}
57
58
nsCOMPtr<nsIPrincipal> principal = PrincipalInfoToPrincipal(aPrincipalInfo);
59
if (NS_WARN_IF(!principal)) {
60
return IPC_OK();
61
}
62
63
nsresult rv = swm->NotifyUnregister(principal, aScope);
64
Unused << NS_WARN_IF(NS_FAILED(rv));
65
return IPC_OK();
66
}
67
68
mozilla::ipc::IPCResult ServiceWorkerManagerChild::RecvNotifyRemove(
69
const nsCString& aHost) {
70
if (mShuttingDown) {
71
return IPC_OK();
72
}
73
74
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
75
if (swm) {
76
swm->Remove(aHost);
77
}
78
79
return IPC_OK();
80
}
81
82
mozilla::ipc::IPCResult ServiceWorkerManagerChild::RecvNotifyRemoveAll() {
83
if (mShuttingDown) {
84
return IPC_OK();
85
}
86
87
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
88
if (swm) {
89
swm->RemoveAll();
90
}
91
92
return IPC_OK();
93
}
94
95
PServiceWorkerUpdaterChild*
96
ServiceWorkerManagerChild::AllocPServiceWorkerUpdaterChild(
97
const OriginAttributes& aOriginAttributes, const nsCString& aScope) {
98
MOZ_CRASH("Do no use ServiceWorkerUpdaterChild IPC CTOR.");
99
}
100
101
bool ServiceWorkerManagerChild::DeallocPServiceWorkerUpdaterChild(
102
PServiceWorkerUpdaterChild* aActor) {
103
delete aActor;
104
return true;
105
}
106
107
} // namespace dom
108
} // namespace mozilla