1 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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/. */
6 #include "OfflineCacheUpdateParent.h"
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"
20 using namespace mozilla::ipc
;
21 using mozilla::BasePrincipal
;
22 using mozilla::OriginAttributes
;
23 using mozilla::dom::TabParent
;
26 // To enable logging (see mozilla/Logging.h for full details):
28 // set MOZ_LOG=nsOfflineCacheUpdate:5
29 // set MOZ_LOG_FILE=offlineupdate.log
31 // this enables LogLevel::Debug level information and places all output in
32 // the file offlineupdate.log
34 extern mozilla::LazyLogModule gOfflineCacheUpdateLog
;
38 MOZ_LOG(gOfflineCacheUpdateLog, mozilla::LogLevel::Debug, args)
41 #define LOG_ENABLED() \
42 MOZ_LOG_TEST(gOfflineCacheUpdateLog, mozilla::LogLevel::Debug)
47 //-----------------------------------------------------------------------------
48 // OfflineCacheUpdateParent::nsISupports
49 //-----------------------------------------------------------------------------
51 NS_IMPL_ISUPPORTS(OfflineCacheUpdateParent
, nsIOfflineCacheUpdateObserver
,
54 //-----------------------------------------------------------------------------
55 // OfflineCacheUpdateParent <public>
56 //-----------------------------------------------------------------------------
58 OfflineCacheUpdateParent::OfflineCacheUpdateParent() : mIPCClosed(false) {
59 // Make sure the service has been initialized
60 nsOfflineCacheUpdateService::EnsureService();
62 LOG(("OfflineCacheUpdateParent::OfflineCacheUpdateParent [%p]", this));
65 OfflineCacheUpdateParent::~OfflineCacheUpdateParent() {
66 LOG(("OfflineCacheUpdateParent::~OfflineCacheUpdateParent [%p]", this));
69 void OfflineCacheUpdateParent::ActorDestroy(ActorDestroyReason why
) {
73 nsresult
OfflineCacheUpdateParent::Schedule(
74 const URIParams
& aManifestURI
, const URIParams
& aDocumentURI
,
75 const PrincipalInfo
& aLoadingPrincipalInfo
, const bool& stickDocument
) {
76 LOG(("OfflineCacheUpdateParent::RecvSchedule [%p]", this));
80 RefPtr
<nsOfflineCacheUpdate
> update
;
81 nsCOMPtr
<nsIURI
> manifestURI
= DeserializeURI(aManifestURI
);
82 if (!manifestURI
) return NS_ERROR_FAILURE
;
84 mLoadingPrincipal
= PrincipalInfoToPrincipal(aLoadingPrincipalInfo
, &rv
);
85 NS_ENSURE_SUCCESS(rv
, rv
);
87 nsOfflineCacheUpdateService
* service
=
88 nsOfflineCacheUpdateService::EnsureService();
89 if (!service
) return NS_ERROR_FAILURE
;
91 bool offlinePermissionAllowed
= false;
93 rv
= service
->OfflineAppAllowed(mLoadingPrincipal
, nullptr,
94 &offlinePermissionAllowed
);
95 NS_ENSURE_SUCCESS(rv
, rv
);
97 if (!offlinePermissionAllowed
) return NS_ERROR_DOM_SECURITY_ERR
;
99 nsCOMPtr
<nsIURI
> documentURI
= DeserializeURI(aDocumentURI
);
100 if (!documentURI
) return NS_ERROR_FAILURE
;
102 if (!NS_SecurityCompareURIs(manifestURI
, documentURI
, false))
103 return NS_ERROR_DOM_SECURITY_ERR
;
105 nsAutoCString originSuffix
;
106 rv
= mLoadingPrincipal
->GetOriginSuffix(originSuffix
);
107 NS_ENSURE_SUCCESS(rv
, rv
);
109 service
->FindUpdate(manifestURI
, originSuffix
, nullptr,
110 getter_AddRefs(update
));
112 update
= new nsOfflineCacheUpdate();
114 // Leave aDocument argument null. Only glues and children keep
115 // document instances.
116 rv
= update
->Init(manifestURI
, documentURI
, mLoadingPrincipal
, nullptr,
118 NS_ENSURE_SUCCESS(rv
, rv
);
120 // Must add before Schedule() call otherwise we would miss
121 // oncheck event notification.
122 update
->AddObserver(this, false);
124 rv
= update
->Schedule();
125 NS_ENSURE_SUCCESS(rv
, rv
);
127 update
->AddObserver(this, false);
131 update
->StickDocument(documentURI
);
138 OfflineCacheUpdateParent::UpdateStateChanged(nsIOfflineCacheUpdate
* aUpdate
,
140 if (mIPCClosed
) return NS_ERROR_UNEXPECTED
;
142 LOG(("OfflineCacheUpdateParent::StateEvent [%p]", this));
144 uint64_t byteProgress
;
145 aUpdate
->GetByteProgress(&byteProgress
);
146 Unused
<< SendNotifyStateEvent(state
, byteProgress
);
148 if (state
== nsIOfflineCacheUpdateObserver::STATE_FINISHED
) {
149 // Tell the child the particulars after the update has finished.
150 // Sending the Finish event will release the child side of the protocol
151 // and notify "offline-cache-update-completed" on the child process.
153 aUpdate
->GetIsUpgrade(&isUpgrade
);
155 aUpdate
->GetSucceeded(&succeeded
);
157 Unused
<< SendFinish(succeeded
, isUpgrade
);
164 OfflineCacheUpdateParent::ApplicationCacheAvailable(
165 nsIApplicationCache
* aApplicationCache
) {
166 if (mIPCClosed
) return NS_ERROR_UNEXPECTED
;
168 NS_ENSURE_ARG(aApplicationCache
);
170 nsCString cacheClientId
;
171 aApplicationCache
->GetClientID(cacheClientId
);
172 nsCString cacheGroupId
;
173 aApplicationCache
->GetGroupID(cacheGroupId
);
175 Unused
<< SendAssociateDocuments(cacheGroupId
, cacheClientId
);
179 //-----------------------------------------------------------------------------
180 // OfflineCacheUpdateParent::nsILoadContext
181 //-----------------------------------------------------------------------------
184 OfflineCacheUpdateParent::GetAssociatedWindow(
185 mozIDOMWindowProxy
** aAssociatedWindow
) {
186 return NS_ERROR_NOT_IMPLEMENTED
;
190 OfflineCacheUpdateParent::GetTopWindow(mozIDOMWindowProxy
** aTopWindow
) {
191 return NS_ERROR_NOT_IMPLEMENTED
;
195 OfflineCacheUpdateParent::GetTopFrameElement(dom::Element
** aElement
) {
196 return NS_ERROR_NOT_IMPLEMENTED
;
200 OfflineCacheUpdateParent::GetNestedFrameId(uint64_t* aId
) {
201 return NS_ERROR_NOT_IMPLEMENTED
;
205 OfflineCacheUpdateParent::GetIsContent(bool* aIsContent
) {
206 return NS_ERROR_NOT_IMPLEMENTED
;
210 OfflineCacheUpdateParent::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing
) {
211 return NS_ERROR_NOT_IMPLEMENTED
;
214 OfflineCacheUpdateParent::SetUsePrivateBrowsing(bool aUsePrivateBrowsing
) {
215 return NS_ERROR_NOT_IMPLEMENTED
;
219 OfflineCacheUpdateParent::SetPrivateBrowsing(bool aUsePrivateBrowsing
) {
220 return NS_ERROR_NOT_IMPLEMENTED
;
224 OfflineCacheUpdateParent::GetUseRemoteTabs(bool* aUseRemoteTabs
) {
225 return NS_ERROR_NOT_IMPLEMENTED
;
229 OfflineCacheUpdateParent::SetRemoteTabs(bool aUseRemoteTabs
) {
230 return NS_ERROR_NOT_IMPLEMENTED
;
234 OfflineCacheUpdateParent::GetIsInIsolatedMozBrowserElement(
235 bool* aIsInIsolatedMozBrowserElement
) {
236 NS_ENSURE_TRUE(mLoadingPrincipal
, NS_ERROR_UNEXPECTED
);
237 return mLoadingPrincipal
->GetIsInIsolatedMozBrowserElement(
238 aIsInIsolatedMozBrowserElement
);
242 OfflineCacheUpdateParent::GetScriptableOriginAttributes(
243 JSContext
* aCx
, JS::MutableHandleValue aAttrs
) {
244 NS_ENSURE_TRUE(mLoadingPrincipal
, NS_ERROR_UNEXPECTED
);
246 nsresult rv
= mLoadingPrincipal
->GetOriginAttributes(aCx
, aAttrs
);
247 NS_ENSURE_SUCCESS(rv
, rv
);
253 OfflineCacheUpdateParent::GetOriginAttributes(
254 mozilla::OriginAttributes
& aAttrs
) {
255 if (mLoadingPrincipal
) {
256 aAttrs
= mLoadingPrincipal
->OriginAttributesRef();
261 OfflineCacheUpdateParent::GetUseTrackingProtection(
262 bool* aUseTrackingProtection
) {
263 return NS_ERROR_NOT_IMPLEMENTED
;
267 OfflineCacheUpdateParent::SetUseTrackingProtection(
268 bool aUseTrackingProtection
) {
269 return NS_ERROR_NOT_IMPLEMENTED
;
272 } // namespace docshell
273 } // namespace mozilla