/src/mozilla-central/dom/serviceworkers/ServiceWorkerContainerParent.cpp
Line | Count | Source (jump to first uncovered line) |
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 "ServiceWorkerContainerParent.h" |
8 | | |
9 | | #include "ServiceWorkerContainerProxy.h" |
10 | | |
11 | | namespace mozilla { |
12 | | namespace dom { |
13 | | |
14 | | using mozilla::ipc::IPCResult; |
15 | | |
16 | | void |
17 | | ServiceWorkerContainerParent::ActorDestroy(ActorDestroyReason aReason) |
18 | 0 | { |
19 | 0 | if (mProxy) { |
20 | 0 | mProxy->RevokeActor(this); |
21 | 0 | mProxy = nullptr; |
22 | 0 | } |
23 | 0 | } |
24 | | |
25 | | IPCResult |
26 | | ServiceWorkerContainerParent::RecvTeardown() |
27 | 0 | { |
28 | 0 | Unused << Send__delete__(this); |
29 | 0 | return IPC_OK(); |
30 | 0 | } |
31 | | |
32 | | IPCResult |
33 | | ServiceWorkerContainerParent::RecvRegister(const IPCClientInfo& aClientInfo, |
34 | | const nsCString& aScopeURL, |
35 | | const nsCString& aScriptURL, |
36 | | const ServiceWorkerUpdateViaCache& aUpdateViaCache, |
37 | | RegisterResolver&& aResolver) |
38 | 0 | { |
39 | 0 | if (!mProxy) { |
40 | 0 | aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR)); |
41 | 0 | return IPC_OK(); |
42 | 0 | } |
43 | 0 |
|
44 | 0 | mProxy->Register(ClientInfo(aClientInfo), aScopeURL, aScriptURL, aUpdateViaCache)->Then( |
45 | 0 | GetCurrentThreadSerialEventTarget(), __func__, |
46 | 0 | [aResolver] (const ServiceWorkerRegistrationDescriptor& aDescriptor) { |
47 | 0 | aResolver(aDescriptor.ToIPC()); |
48 | 0 | }, [aResolver] (const CopyableErrorResult& aResult) { |
49 | 0 | aResolver(aResult); |
50 | 0 | }); |
51 | 0 |
|
52 | 0 | return IPC_OK(); |
53 | 0 | } |
54 | | |
55 | | IPCResult |
56 | | ServiceWorkerContainerParent::RecvGetRegistration(const IPCClientInfo& aClientInfo, |
57 | | const nsCString& aURL, |
58 | | GetRegistrationResolver&& aResolver) |
59 | 0 | { |
60 | 0 | if (!mProxy) { |
61 | 0 | aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR)); |
62 | 0 | return IPC_OK(); |
63 | 0 | } |
64 | 0 |
|
65 | 0 | mProxy->GetRegistration(ClientInfo(aClientInfo), aURL)->Then( |
66 | 0 | GetCurrentThreadSerialEventTarget(), __func__, |
67 | 0 | [aResolver] (const ServiceWorkerRegistrationDescriptor& aDescriptor) { |
68 | 0 | aResolver(aDescriptor.ToIPC()); |
69 | 0 | }, [aResolver] (const CopyableErrorResult& aResult) { |
70 | 0 | aResolver(aResult); |
71 | 0 | }); |
72 | 0 |
|
73 | 0 | return IPC_OK(); |
74 | 0 | } |
75 | | |
76 | | IPCResult |
77 | | ServiceWorkerContainerParent::RecvGetRegistrations(const IPCClientInfo& aClientInfo, |
78 | | GetRegistrationsResolver&& aResolver) |
79 | 0 | { |
80 | 0 | if (!mProxy) { |
81 | 0 | aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR)); |
82 | 0 | return IPC_OK(); |
83 | 0 | } |
84 | 0 |
|
85 | 0 | mProxy->GetRegistrations(ClientInfo(aClientInfo))->Then( |
86 | 0 | GetCurrentThreadSerialEventTarget(), __func__, |
87 | 0 | [aResolver] (const nsTArray<ServiceWorkerRegistrationDescriptor>& aList) { |
88 | 0 | IPCServiceWorkerRegistrationDescriptorList ipcList; |
89 | 0 | for (auto& desc : aList) { |
90 | 0 | ipcList.values().AppendElement(desc.ToIPC()); |
91 | 0 | } |
92 | 0 | aResolver(std::move(ipcList)); |
93 | 0 | }, [aResolver] (const CopyableErrorResult& aResult) { |
94 | 0 | aResolver(aResult); |
95 | 0 | }); |
96 | 0 |
|
97 | 0 | return IPC_OK(); |
98 | 0 | } |
99 | | |
100 | | IPCResult |
101 | | ServiceWorkerContainerParent::RecvGetReady(const IPCClientInfo& aClientInfo, |
102 | | GetReadyResolver&& aResolver) |
103 | 0 | { |
104 | 0 | if (!mProxy) { |
105 | 0 | aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR)); |
106 | 0 | return IPC_OK(); |
107 | 0 | } |
108 | 0 |
|
109 | 0 | mProxy->GetReady(ClientInfo(aClientInfo))->Then( |
110 | 0 | GetCurrentThreadSerialEventTarget(), __func__, |
111 | 0 | [aResolver] (const ServiceWorkerRegistrationDescriptor& aDescriptor) { |
112 | 0 | aResolver(aDescriptor.ToIPC()); |
113 | 0 | }, [aResolver] (const CopyableErrorResult& aResult) { |
114 | 0 | aResolver(aResult); |
115 | 0 | }); |
116 | 0 |
|
117 | 0 | return IPC_OK(); |
118 | 0 | } |
119 | | |
120 | | ServiceWorkerContainerParent::ServiceWorkerContainerParent() |
121 | 0 | { |
122 | 0 | } |
123 | | |
124 | | ServiceWorkerContainerParent::~ServiceWorkerContainerParent() |
125 | 0 | { |
126 | 0 | MOZ_DIAGNOSTIC_ASSERT(!mProxy); |
127 | 0 | } |
128 | | |
129 | | void |
130 | | ServiceWorkerContainerParent::Init() |
131 | 0 | { |
132 | 0 | mProxy = new ServiceWorkerContainerProxy(this); |
133 | 0 | } |
134 | | |
135 | | } // namespace dom |
136 | | } // namespace mozilla |