/src/mozilla-central/uriloader/prefetch/OfflineCacheUpdateParent.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #include "OfflineCacheUpdateParent.h" |
7 | | |
8 | | #include "BackgroundUtils.h" |
9 | | #include "mozilla/BasePrincipal.h" |
10 | | #include "mozilla/dom/Element.h" |
11 | | #include "mozilla/dom/TabParent.h" |
12 | | #include "mozilla/ipc/URIUtils.h" |
13 | | #include "mozilla/Unused.h" |
14 | | #include "nsContentUtils.h" |
15 | | #include "nsOfflineCacheUpdate.h" |
16 | | #include "nsIApplicationCache.h" |
17 | | #include "nsIScriptSecurityManager.h" |
18 | | #include "nsNetUtil.h" |
19 | | |
20 | | using namespace mozilla::ipc; |
21 | | using mozilla::BasePrincipal; |
22 | | using mozilla::OriginAttributes; |
23 | | using mozilla::dom::TabParent; |
24 | | |
25 | | // |
26 | | // To enable logging (see mozilla/Logging.h for full details): |
27 | | // |
28 | | // set MOZ_LOG=nsOfflineCacheUpdate:5 |
29 | | // set MOZ_LOG_FILE=offlineupdate.log |
30 | | // |
31 | | // this enables LogLevel::Debug level information and places all output in |
32 | | // the file offlineupdate.log |
33 | | // |
34 | | extern mozilla::LazyLogModule gOfflineCacheUpdateLog; |
35 | | |
36 | | #undef LOG |
37 | 0 | #define LOG(args) MOZ_LOG(gOfflineCacheUpdateLog, mozilla::LogLevel::Debug, args) |
38 | | |
39 | | #undef LOG_ENABLED |
40 | | #define LOG_ENABLED() MOZ_LOG_TEST(gOfflineCacheUpdateLog, mozilla::LogLevel::Debug) |
41 | | |
42 | | namespace mozilla { |
43 | | namespace docshell { |
44 | | |
45 | | //----------------------------------------------------------------------------- |
46 | | // OfflineCacheUpdateParent::nsISupports |
47 | | //----------------------------------------------------------------------------- |
48 | | |
49 | | NS_IMPL_ISUPPORTS(OfflineCacheUpdateParent, |
50 | | nsIOfflineCacheUpdateObserver, |
51 | | nsILoadContext) |
52 | | |
53 | | //----------------------------------------------------------------------------- |
54 | | // OfflineCacheUpdateParent <public> |
55 | | //----------------------------------------------------------------------------- |
56 | | |
57 | | |
58 | | OfflineCacheUpdateParent::OfflineCacheUpdateParent() |
59 | | : mIPCClosed(false) |
60 | 0 | { |
61 | 0 | // Make sure the service has been initialized |
62 | 0 | nsOfflineCacheUpdateService::EnsureService(); |
63 | 0 |
|
64 | 0 | LOG(("OfflineCacheUpdateParent::OfflineCacheUpdateParent [%p]", this)); |
65 | 0 | } |
66 | | |
67 | | OfflineCacheUpdateParent::~OfflineCacheUpdateParent() |
68 | 0 | { |
69 | 0 | LOG(("OfflineCacheUpdateParent::~OfflineCacheUpdateParent [%p]", this)); |
70 | 0 | } |
71 | | |
72 | | void |
73 | | OfflineCacheUpdateParent::ActorDestroy(ActorDestroyReason why) |
74 | 0 | { |
75 | 0 | mIPCClosed = true; |
76 | 0 | } |
77 | | |
78 | | nsresult |
79 | | OfflineCacheUpdateParent::Schedule(const URIParams& aManifestURI, |
80 | | const URIParams& aDocumentURI, |
81 | | const PrincipalInfo& aLoadingPrincipalInfo, |
82 | | const bool& stickDocument) |
83 | 0 | { |
84 | 0 | LOG(("OfflineCacheUpdateParent::RecvSchedule [%p]", this)); |
85 | 0 |
|
86 | 0 | nsresult rv; |
87 | 0 |
|
88 | 0 | RefPtr<nsOfflineCacheUpdate> update; |
89 | 0 | nsCOMPtr<nsIURI> manifestURI = DeserializeURI(aManifestURI); |
90 | 0 | if (!manifestURI) |
91 | 0 | return NS_ERROR_FAILURE; |
92 | 0 | |
93 | 0 | mLoadingPrincipal = PrincipalInfoToPrincipal(aLoadingPrincipalInfo, &rv); |
94 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
95 | 0 |
|
96 | 0 | nsOfflineCacheUpdateService* service = |
97 | 0 | nsOfflineCacheUpdateService::EnsureService(); |
98 | 0 | if (!service) |
99 | 0 | return NS_ERROR_FAILURE; |
100 | 0 | |
101 | 0 | bool offlinePermissionAllowed = false; |
102 | 0 |
|
103 | 0 | rv = service->OfflineAppAllowed( |
104 | 0 | mLoadingPrincipal, nullptr, &offlinePermissionAllowed); |
105 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
106 | 0 |
|
107 | 0 | if (!offlinePermissionAllowed) |
108 | 0 | return NS_ERROR_DOM_SECURITY_ERR; |
109 | 0 | |
110 | 0 | nsCOMPtr<nsIURI> documentURI = DeserializeURI(aDocumentURI); |
111 | 0 | if (!documentURI) |
112 | 0 | return NS_ERROR_FAILURE; |
113 | 0 | |
114 | 0 | if (!NS_SecurityCompareURIs(manifestURI, documentURI, false)) |
115 | 0 | return NS_ERROR_DOM_SECURITY_ERR; |
116 | 0 | |
117 | 0 | nsAutoCString originSuffix; |
118 | 0 | rv = mLoadingPrincipal->GetOriginSuffix(originSuffix); |
119 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
120 | 0 |
|
121 | 0 | service->FindUpdate(manifestURI, |
122 | 0 | originSuffix, |
123 | 0 | nullptr, |
124 | 0 | getter_AddRefs(update)); |
125 | 0 | if (!update) { |
126 | 0 | update = new nsOfflineCacheUpdate(); |
127 | 0 |
|
128 | 0 | // Leave aDocument argument null. Only glues and children keep |
129 | 0 | // document instances. |
130 | 0 | rv = update->Init(manifestURI, documentURI, mLoadingPrincipal, nullptr, nullptr); |
131 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
132 | 0 |
|
133 | 0 | // Must add before Schedule() call otherwise we would miss |
134 | 0 | // oncheck event notification. |
135 | 0 | update->AddObserver(this, false); |
136 | 0 |
|
137 | 0 | rv = update->Schedule(); |
138 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
139 | 0 | } else { |
140 | 0 | update->AddObserver(this, false); |
141 | 0 | } |
142 | 0 |
|
143 | 0 | if (stickDocument) { |
144 | 0 | update->StickDocument(documentURI); |
145 | 0 | } |
146 | 0 |
|
147 | 0 | return NS_OK; |
148 | 0 | } |
149 | | |
150 | | NS_IMETHODIMP |
151 | | OfflineCacheUpdateParent::UpdateStateChanged(nsIOfflineCacheUpdate* aUpdate, uint32_t state) |
152 | 0 | { |
153 | 0 | if (mIPCClosed) |
154 | 0 | return NS_ERROR_UNEXPECTED; |
155 | 0 | |
156 | 0 | LOG(("OfflineCacheUpdateParent::StateEvent [%p]", this)); |
157 | 0 |
|
158 | 0 | uint64_t byteProgress; |
159 | 0 | aUpdate->GetByteProgress(&byteProgress); |
160 | 0 | Unused << SendNotifyStateEvent(state, byteProgress); |
161 | 0 |
|
162 | 0 | if (state == nsIOfflineCacheUpdateObserver::STATE_FINISHED) { |
163 | 0 | // Tell the child the particulars after the update has finished. |
164 | 0 | // Sending the Finish event will release the child side of the protocol |
165 | 0 | // and notify "offline-cache-update-completed" on the child process. |
166 | 0 | bool isUpgrade; |
167 | 0 | aUpdate->GetIsUpgrade(&isUpgrade); |
168 | 0 | bool succeeded; |
169 | 0 | aUpdate->GetSucceeded(&succeeded); |
170 | 0 |
|
171 | 0 | Unused << SendFinish(succeeded, isUpgrade); |
172 | 0 | } |
173 | 0 |
|
174 | 0 | return NS_OK; |
175 | 0 | } |
176 | | |
177 | | NS_IMETHODIMP |
178 | | OfflineCacheUpdateParent::ApplicationCacheAvailable(nsIApplicationCache* aApplicationCache) |
179 | 0 | { |
180 | 0 | if (mIPCClosed) |
181 | 0 | return NS_ERROR_UNEXPECTED; |
182 | 0 | |
183 | 0 | NS_ENSURE_ARG(aApplicationCache); |
184 | 0 |
|
185 | 0 | nsCString cacheClientId; |
186 | 0 | aApplicationCache->GetClientID(cacheClientId); |
187 | 0 | nsCString cacheGroupId; |
188 | 0 | aApplicationCache->GetGroupID(cacheGroupId); |
189 | 0 |
|
190 | 0 | Unused << SendAssociateDocuments(cacheGroupId, cacheClientId); |
191 | 0 | return NS_OK; |
192 | 0 | } |
193 | | |
194 | | //----------------------------------------------------------------------------- |
195 | | // OfflineCacheUpdateParent::nsILoadContext |
196 | | //----------------------------------------------------------------------------- |
197 | | |
198 | | NS_IMETHODIMP |
199 | | OfflineCacheUpdateParent::GetAssociatedWindow(mozIDOMWindowProxy** aAssociatedWindow) |
200 | 0 | { |
201 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
202 | 0 | } |
203 | | |
204 | | NS_IMETHODIMP |
205 | | OfflineCacheUpdateParent::GetTopWindow(mozIDOMWindowProxy** aTopWindow) |
206 | 0 | { |
207 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
208 | 0 | } |
209 | | |
210 | | NS_IMETHODIMP |
211 | | OfflineCacheUpdateParent::GetTopFrameElement(dom::Element** aElement) |
212 | 0 | { |
213 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
214 | 0 | } |
215 | | |
216 | | NS_IMETHODIMP |
217 | | OfflineCacheUpdateParent::GetNestedFrameId(uint64_t* aId) |
218 | 0 | { |
219 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
220 | 0 | } |
221 | | |
222 | | NS_IMETHODIMP |
223 | | OfflineCacheUpdateParent::GetIsContent(bool* aIsContent) |
224 | 0 | { |
225 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
226 | 0 | } |
227 | | |
228 | | NS_IMETHODIMP |
229 | | OfflineCacheUpdateParent::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing) |
230 | 0 | { |
231 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
232 | 0 | } |
233 | | NS_IMETHODIMP |
234 | | OfflineCacheUpdateParent::SetUsePrivateBrowsing(bool aUsePrivateBrowsing) |
235 | 0 | { |
236 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
237 | 0 | } |
238 | | |
239 | | NS_IMETHODIMP |
240 | | OfflineCacheUpdateParent::SetPrivateBrowsing(bool aUsePrivateBrowsing) |
241 | 0 | { |
242 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
243 | 0 | } |
244 | | |
245 | | NS_IMETHODIMP |
246 | | OfflineCacheUpdateParent::GetUseRemoteTabs(bool* aUseRemoteTabs) |
247 | 0 | { |
248 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
249 | 0 | } |
250 | | |
251 | | NS_IMETHODIMP |
252 | | OfflineCacheUpdateParent::SetRemoteTabs(bool aUseRemoteTabs) |
253 | 0 | { |
254 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
255 | 0 | } |
256 | | |
257 | | NS_IMETHODIMP |
258 | | OfflineCacheUpdateParent::GetIsInIsolatedMozBrowserElement(bool* aIsInIsolatedMozBrowserElement) |
259 | 0 | { |
260 | 0 | NS_ENSURE_TRUE(mLoadingPrincipal, NS_ERROR_UNEXPECTED); |
261 | 0 | return mLoadingPrincipal->GetIsInIsolatedMozBrowserElement(aIsInIsolatedMozBrowserElement); |
262 | 0 | } |
263 | | |
264 | | NS_IMETHODIMP |
265 | | OfflineCacheUpdateParent::GetScriptableOriginAttributes(JS::MutableHandleValue aAttrs) |
266 | 0 | { |
267 | 0 | NS_ENSURE_TRUE(mLoadingPrincipal, NS_ERROR_UNEXPECTED); |
268 | 0 |
|
269 | 0 | JSContext* cx = nsContentUtils::GetCurrentJSContext(); |
270 | 0 | MOZ_ASSERT(cx); |
271 | 0 |
|
272 | 0 | nsresult rv = mLoadingPrincipal->GetOriginAttributes(cx, aAttrs); |
273 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
274 | 0 |
|
275 | 0 | return NS_OK; |
276 | 0 | } |
277 | | |
278 | | NS_IMETHODIMP_(void) |
279 | | OfflineCacheUpdateParent::GetOriginAttributes(mozilla::OriginAttributes& aAttrs) |
280 | 0 | { |
281 | 0 | if (mLoadingPrincipal) { |
282 | 0 | aAttrs = mLoadingPrincipal->OriginAttributesRef(); |
283 | 0 | } |
284 | 0 | } |
285 | | |
286 | | NS_IMETHODIMP |
287 | | OfflineCacheUpdateParent::GetUseTrackingProtection(bool* aUseTrackingProtection) |
288 | 0 | { |
289 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
290 | 0 | } |
291 | | |
292 | | NS_IMETHODIMP |
293 | | OfflineCacheUpdateParent::SetUseTrackingProtection(bool aUseTrackingProtection) |
294 | 0 | { |
295 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
296 | 0 | } |
297 | | |
298 | | } // namespace docshell |
299 | | } // namespace mozilla |