author | Christoph Kerschbaumer <mozilla@christophkerschbaumer.com> |
Fri, 02 Oct 2015 09:13:52 -0700 | |
changeset 265765 | cf9e1eb325c81f51a7ac7b55bfe71853cbf264e9 |
parent 265764 | 31da4a02d8b67b01cf6e88305222036f028312eb |
child 265766 | d699f02b8d9e65f56be7b68bb3997f14580cc359 |
push id | 66019 |
push user | mozilla@christophkerschbaumer.com |
push date | Fri, 02 Oct 2015 16:20:50 +0000 |
treeherder | mozilla-inbound@eb4a8da5c964 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | mayhemer |
bugs | 1199295 |
milestone | 44.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -55,16 +55,17 @@ include protocol PWebrtcGlobal; include protocol PPresentation; include DOMTypes; include JavaScriptTypes; include InputStreamParams; include PTabContext; include URIParams; include PluginTypes; include ProtocolTypes; +include PBackgroundSharedTypes; include PContentPermission; include BrowserConfiguration; include GraphicsMessages; // Workaround to prevent error if PContentChild.cpp & PContentBridgeParent.cpp // are put into different UnifiedProtocolsXX.cpp files. // XXX Remove this once bug 1069073 is fixed include "mozilla/dom/PContentBridgeParent.h"; @@ -1016,16 +1017,18 @@ parent: async NotifyTabDestroying(TabId tabId, ContentParentId cpId); /** * Starts an offline application cache update. * @param manifestURI * URI of the manifest to fetch, the application cache group ID * @param documentURI * URI of the document that referred the manifest + * @param loadingPrincipal + * Principal of the document that referred the manifest * @param stickDocument * True if the update was initiated by a document load that referred * a manifest. * False if the update was initiated by applicationCache.update() call. * * Tells the update to carry the documentURI to a potential separate * update of implicit (master) items. * @@ -1035,17 +1038,18 @@ parent: * cache group update. But we must cache the document (identified by the * documentURI). This argument will ensure that a previously uncached * document will get cached and that we don't re-cache a document that * has already been cached (stickDocument=false). * @param tabId * To identify which tab owns the app. */ POfflineCacheUpdate(URIParams manifestURI, URIParams documentURI, - bool stickDocument, TabId tabId); + PrincipalInfo loadingPrincipal, bool stickDocument, + TabId tabId); /** * Sets "offline-app" permission for the principal. Called when we hit * a web app with the manifest attribute in <html> and * offline-apps.allow_by_default is set to true. */ SetOfflinePermission(Principal principal);
--- a/dom/offline/nsDOMOfflineResourceList.cpp +++ b/dom/offline/nsDOMOfflineResourceList.cpp @@ -356,17 +356,18 @@ nsDOMOfflineResourceList::MozAdd(const n nsCOMPtr<nsIOfflineCacheUpdate> update = do_CreateInstance(NS_OFFLINECACHEUPDATE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); nsAutoCString clientID; rv = appCache->GetClientID(clientID); NS_ENSURE_SUCCESS(rv, rv); - rv = update->InitPartial(mManifestURI, clientID, mDocumentURI); + rv = update->InitPartial(mManifestURI, clientID, + mDocumentURI, mLoadingPrincipal); NS_ENSURE_SUCCESS(rv, rv); rv = update->AddDynamicURI(requestedURI); NS_ENSURE_SUCCESS(rv, rv); rv = update->Schedule(); NS_ENSURE_SUCCESS(rv, rv);
--- a/uriloader/prefetch/OfflineCacheUpdateChild.cpp +++ b/uriloader/prefetch/OfflineCacheUpdateChild.cpp @@ -1,13 +1,14 @@ /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "BackgroundUtils.h" #include "OfflineCacheUpdateChild.h" #include "nsOfflineCacheUpdate.h" #include "mozilla/dom/ContentChild.h" #include "mozilla/dom/TabChild.h" #include "mozilla/ipc/URIUtils.h" #include "mozilla/net/NeckoCommon.h" #include "nsIApplicationCacheContainer.h" @@ -169,16 +170,17 @@ OfflineCacheUpdateChild::AssociateDocume //----------------------------------------------------------------------------- // OfflineCacheUpdateChild::nsIOfflineCacheUpdate //----------------------------------------------------------------------------- NS_IMETHODIMP OfflineCacheUpdateChild::Init(nsIURI *aManifestURI, nsIURI *aDocumentURI, + nsIPrincipal *aLoadingPrincipal, nsIDOMDocument *aDocument, nsIFile *aCustomProfileDir, uint32_t aAppID, bool aInBrowser) { nsresult rv; // Make sure the service has been initialized @@ -207,41 +209,44 @@ OfflineCacheUpdateChild::Init(nsIURI *aM } mManifestURI = aManifestURI; rv = mManifestURI->GetAsciiHost(mUpdateDomain); NS_ENSURE_SUCCESS(rv, rv); mDocumentURI = aDocumentURI; + mLoadingPrincipal = aLoadingPrincipal; mState = STATE_INITIALIZED; if (aDocument) SetDocument(aDocument); mAppID = aAppID; mInBrowser = aInBrowser; return NS_OK; } NS_IMETHODIMP OfflineCacheUpdateChild::InitPartial(nsIURI *aManifestURI, const nsACString& clientID, - nsIURI *aDocumentURI) + nsIURI *aDocumentURI, + nsIPrincipal *aLoadingPrincipal) { NS_NOTREACHED("Not expected to do partial offline cache updates" " on the child process"); // For now leaving this method, we may discover we need it. return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP OfflineCacheUpdateChild::InitForUpdateCheck(nsIURI *aManifestURI, + nsIPrincipal* aLoadingPrincipal, uint32_t aAppID, bool aInBrowser, nsIObserver *aObserver) { NS_NOTREACHED("Not expected to do only update checks" " from the child process"); return NS_ERROR_NOT_IMPLEMENTED; } @@ -404,16 +409,22 @@ OfflineCacheUpdateChild::Schedule() if (MissingRequiredTabChild(child, "offlinecacheupdate")) { return NS_ERROR_FAILURE; } URIParams manifestURI, documentURI; SerializeURI(mManifestURI, manifestURI); SerializeURI(mDocumentURI, documentURI); + nsresult rv = NS_OK; + PrincipalInfo loadingPrincipalInfo; + rv = PrincipalToPrincipalInfo(mLoadingPrincipal, + &loadingPrincipalInfo); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService(); if (observerService) { LOG(("Calling offline-cache-update-added")); observerService->NotifyObservers(static_cast<nsIOfflineCacheUpdate*>(this), "offline-cache-update-added", nullptr); LOG(("Done offline-cache-update-added")); @@ -426,17 +437,17 @@ OfflineCacheUpdateChild::Schedule() // has not been changed since the last fetch. // See also nsOfflineCacheUpdate::ScheduleImplicit. bool stickDocument = mDocument != nullptr; // Need to addref ourself here, because the IPC stack doesn't hold // a reference to us. Will be released in RecvFinish() that identifies // the work has been done. ContentChild::GetSingleton()->SendPOfflineCacheUpdateConstructor( - this, manifestURI, documentURI, + this, manifestURI, documentURI, loadingPrincipalInfo, stickDocument, child->GetTabId()); // ContentChild::DeallocPOfflineCacheUpdate will release this. NS_ADDREF_THIS(); return NS_OK; }
--- a/uriloader/prefetch/OfflineCacheUpdateChild.h +++ b/uriloader/prefetch/OfflineCacheUpdateChild.h @@ -63,16 +63,17 @@ private: } mState; bool mIsUpgrade; bool mSucceeded; nsCString mUpdateDomain; nsCOMPtr<nsIURI> mManifestURI; nsCOMPtr<nsIURI> mDocumentURI; + nsCOMPtr<nsIPrincipal> mLoadingPrincipal; nsCOMPtr<nsIObserverService> mObserverService; uint32_t mAppID; bool mInBrowser; /* Clients watching this update for changes */ nsCOMArray<nsIWeakReference> mWeakObservers;
--- a/uriloader/prefetch/OfflineCacheUpdateGlue.cpp +++ b/uriloader/prefetch/OfflineCacheUpdateGlue.cpp @@ -90,18 +90,19 @@ OfflineCacheUpdateGlue::Schedule() if (mCoalesced) // already scheduled return NS_OK; return mUpdate->Schedule(); } NS_IMETHODIMP -OfflineCacheUpdateGlue::Init(nsIURI *aManifestURI, +OfflineCacheUpdateGlue::Init(nsIURI *aManifestURI, nsIURI *aDocumentURI, + nsIPrincipal* aLoadingPrincipal, nsIDOMDocument *aDocument, nsIFile *aCustomProfileDir, uint32_t aAppID, bool aInBrowser) { nsOfflineCacheUpdateService* service = nsOfflineCacheUpdateService::EnsureService(); if (service) { @@ -109,26 +110,28 @@ OfflineCacheUpdateGlue::Init(nsIURI *aMa getter_AddRefs(mUpdate)); mCoalesced = !!mUpdate; } if (!EnsureUpdate()) return NS_ERROR_NULL_POINTER; mDocumentURI = aDocumentURI; + mLoadingPrincipal = aLoadingPrincipal; if (aDocument) SetDocument(aDocument); if (mCoalesced) { // already initialized LOG(("OfflineCacheUpdateGlue %p coalesced with update %p", this, mUpdate.get())); return NS_OK; } - return mUpdate->Init(aManifestURI, aDocumentURI, nullptr, aCustomProfileDir, aAppID, aInBrowser); + return mUpdate->Init(aManifestURI, aDocumentURI, aLoadingPrincipal, nullptr, + aCustomProfileDir, aAppID, aInBrowser); } void OfflineCacheUpdateGlue::SetDocument(nsIDOMDocument *aDocument) { // The design is one document for one cache update on the content process. NS_ASSERTION(!mDocument, "Setting more then a single document on an instance of OfflineCacheUpdateGlue");
--- a/uriloader/prefetch/OfflineCacheUpdateGlue.h +++ b/uriloader/prefetch/OfflineCacheUpdateGlue.h @@ -24,18 +24,18 @@ namespace docshell { // Init #define NS_ADJUSTED_FORWARD_NSIOFFLINECACHEUPDATE(_to) \ NS_IMETHOD GetStatus(uint16_t *aStatus) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetStatus(aStatus); } \ NS_IMETHOD GetPartial(bool *aPartial) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetPartial(aPartial); } \ NS_IMETHOD GetIsUpgrade(bool *aIsUpgrade) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetIsUpgrade(aIsUpgrade); } \ NS_IMETHOD GetUpdateDomain(nsACString & aUpdateDomain) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetUpdateDomain(aUpdateDomain); } \ NS_IMETHOD GetManifestURI(nsIURI **aManifestURI) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetManifestURI(aManifestURI); } \ NS_IMETHOD GetSucceeded(bool *aSucceeded) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetSucceeded(aSucceeded); } \ - NS_IMETHOD InitPartial(nsIURI *aManifestURI, const nsACString & aClientID, nsIURI *aDocumentURI) override { return !_to ? NS_ERROR_NULL_POINTER : _to->InitPartial(aManifestURI, aClientID, aDocumentURI); } \ - NS_IMETHOD InitForUpdateCheck(nsIURI *aManifestURI, uint32_t aAppID, bool aInBrowser, nsIObserver *aObserver) override { return !_to ? NS_ERROR_NULL_POINTER : _to->InitForUpdateCheck(aManifestURI, aAppID, aInBrowser, aObserver); } \ + NS_IMETHOD InitPartial(nsIURI *aManifestURI, const nsACString & aClientID, nsIURI *aDocumentURI, nsIPrincipal *aLoadingPrincipal) override { return !_to ? NS_ERROR_NULL_POINTER : _to->InitPartial(aManifestURI, aClientID, aDocumentURI, aLoadingPrincipal); } \ + NS_IMETHOD InitForUpdateCheck(nsIURI *aManifestURI, nsIPrincipal* aLoadingPrincipal, uint32_t aAppID, bool aInBrowser, nsIObserver *aObserver) override { return !_to ? NS_ERROR_NULL_POINTER : _to->InitForUpdateCheck(aManifestURI, aLoadingPrincipal, aAppID, aInBrowser, aObserver); } \ NS_IMETHOD AddDynamicURI(nsIURI *aURI) override { return !_to ? NS_ERROR_NULL_POINTER : _to->AddDynamicURI(aURI); } \ NS_IMETHOD AddObserver(nsIOfflineCacheUpdateObserver *aObserver, bool aHoldWeak) override { return !_to ? NS_ERROR_NULL_POINTER : _to->AddObserver(aObserver, aHoldWeak); } \ NS_IMETHOD RemoveObserver(nsIOfflineCacheUpdateObserver *aObserver) override { return !_to ? NS_ERROR_NULL_POINTER : _to->RemoveObserver(aObserver); } \ NS_IMETHOD GetByteProgress(uint64_t * _result) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetByteProgress(_result); } \ NS_IMETHOD Cancel() override { return !_to ? NS_ERROR_NULL_POINTER : _to->Cancel(); } class OfflineCacheUpdateGlue final : public nsSupportsWeakReference , public nsIOfflineCacheUpdate @@ -45,18 +45,19 @@ public: NS_DECL_ISUPPORTS private: nsIOfflineCacheUpdate* EnsureUpdate(); public: NS_ADJUSTED_FORWARD_NSIOFFLINECACHEUPDATE(EnsureUpdate()) NS_IMETHOD Schedule(void) override; - NS_IMETHOD Init(nsIURI *aManifestURI, + NS_IMETHOD Init(nsIURI *aManifestURI, nsIURI *aDocumentURI, + nsIPrincipal* aLoadingPrincipal, nsIDOMDocument *aDocument, nsIFile *aCustomProfileDir, uint32_t aAppID, bool aInBrowser) override; NS_DECL_NSIOFFLINECACHEUPDATEOBSERVER OfflineCacheUpdateGlue(); @@ -67,14 +68,15 @@ private: ~OfflineCacheUpdateGlue(); nsRefPtr<nsOfflineCacheUpdate> mUpdate; bool mCoalesced; /* Document that requested this update */ nsCOMPtr<nsIDOMDocument> mDocument; nsCOMPtr<nsIURI> mDocumentURI; + nsCOMPtr<nsIPrincipal> mLoadingPrincipal; }; } // namespace docshell } // namespace mozilla #endif
--- a/uriloader/prefetch/OfflineCacheUpdateParent.cpp +++ b/uriloader/prefetch/OfflineCacheUpdateParent.cpp @@ -1,15 +1,16 @@ /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "OfflineCacheUpdateParent.h" +#include "BackgroundUtils.h" #include "mozilla/BasePrincipal.h" #include "mozilla/dom/TabParent.h" #include "mozilla/ipc/URIUtils.h" #include "mozilla/unused.h" #include "nsOfflineCacheUpdate.h" #include "nsIApplicationCache.h" #include "nsIScriptSecurityManager.h" #include "nsNetUtil.h" @@ -72,16 +73,17 @@ void OfflineCacheUpdateParent::ActorDestroy(ActorDestroyReason why) { mIPCClosed = true; } nsresult OfflineCacheUpdateParent::Schedule(const URIParams& aManifestURI, const URIParams& aDocumentURI, + const PrincipalInfo& aLoadingPrincipalInfo, const bool& stickDocument) { LOG(("OfflineCacheUpdateParent::RecvSchedule [%p]", this)); nsRefPtr<nsOfflineCacheUpdate> update; nsCOMPtr<nsIURI> manifestURI = DeserializeURI(aManifestURI); if (!manifestURI) return NS_ERROR_FAILURE; @@ -114,19 +116,23 @@ OfflineCacheUpdateParent::Schedule(const service->FindUpdate(manifestURI, mOriginAttributes.mAppId, mOriginAttributes.mInBrowser, nullptr, getter_AddRefs(update)); if (!update) { update = new nsOfflineCacheUpdate(); + nsCOMPtr<nsIPrincipal> loadingPrincipal = + PrincipalInfoToPrincipal(aLoadingPrincipalInfo, &rv); + NS_ENSURE_SUCCESS(rv, rv); + // Leave aDocument argument null. Only glues and children keep // document instances. - rv = update->Init(manifestURI, documentURI, nullptr, nullptr, + rv = update->Init(manifestURI, documentURI, loadingPrincipal, nullptr, nullptr, mOriginAttributes.mAppId, mOriginAttributes.mInBrowser); NS_ENSURE_SUCCESS(rv, rv); rv = update->Schedule(); NS_ENSURE_SUCCESS(rv, rv); } update->AddObserver(this, false);
--- a/uriloader/prefetch/OfflineCacheUpdateParent.h +++ b/uriloader/prefetch/OfflineCacheUpdateParent.h @@ -21,25 +21,27 @@ class URIParams; namespace docshell { class OfflineCacheUpdateParent : public POfflineCacheUpdateParent , public nsIOfflineCacheUpdateObserver , public nsILoadContext { typedef mozilla::ipc::URIParams URIParams; + typedef mozilla::ipc::PrincipalInfo PrincipalInfo; public: NS_DECL_ISUPPORTS NS_DECL_NSIOFFLINECACHEUPDATEOBSERVER NS_DECL_NSILOADCONTEXT nsresult Schedule(const URIParams& manifestURI, const URIParams& documentURI, + const PrincipalInfo& loadingPrincipalInfo, const bool& stickDocument); void StopSendingMessagesToChild() { mIPCClosed = true; }
--- a/uriloader/prefetch/nsIOfflineCacheUpdate.idl +++ b/uriloader/prefetch/nsIOfflineCacheUpdate.idl @@ -53,17 +53,17 @@ interface nsIOfflineCacheUpdateObserver * resources. * * It can be used to perform partial or complete updates. * * One update object will be updating at a time. The active object will * load its items one by one, sending itemCompleted() to any registered * observers. */ -[scriptable, uuid(a4503a53-6ab8-4b50-b01e-1c4f393fc980)] +[scriptable, uuid(e9029838-3553-4192-a00b-f0f11073a6eb)] interface nsIOfflineCacheUpdate : nsISupports { /** * Fetch the status of the running update. This will return a value * defined in nsIDOMOfflineResourceList. */ readonly attribute unsigned short status; /** @@ -96,18 +96,23 @@ interface nsIOfflineCacheUpdate : nsISup /** * Initialize the update. * * @param aManifestURI * The manifest URI to be checked. * @param aDocumentURI * The page that is requesting the update. + * @param aLoadingPrincipal + * The principal of the page that is requesting the update. */ - void init(in nsIURI aManifestURI, in nsIURI aDocumentURI, in nsIDOMDocument aDocument, + void init(in nsIURI aManifestURI, + in nsIURI aDocumentURI, + in nsIPrincipal aLoadingPrincipal, + in nsIDOMDocument aDocument, [optional] in nsIFile aCustomProfileDir, [optional] in unsigned long aAppId, [optional] in boolean aInBrowser); /** * Initialize the update for partial processing. * * @param aManifestURI @@ -115,17 +120,18 @@ interface nsIOfflineCacheUpdate : nsISup * @param aClientID * Client ID of the cache to store resource to. This ClientID * must be ID of cache in the cache group identified by * the manifest URI passed in the first parameter. * @param aDocumentURI * The page that is requesting the update. May be null * when this information is unknown. */ - void initPartial(in nsIURI aManifestURI, in ACString aClientID, in nsIURI aDocumentURI); + void initPartial(in nsIURI aManifestURI, in ACString aClientID, + in nsIURI aDocumentURI, in nsIPrincipal aPrincipal); /** * Initialize the update to only check whether there is an update * to the manifest available (if it has actually changed on the server). * * @param aManifestURI * The manifest URI of the related cache. * @param aAppID @@ -136,16 +142,17 @@ interface nsIOfflineCacheUpdate : nsISup * nsIObserver implementation that receives the result. * When aTopic == "offline-cache-update-available" there is an update to * to download. Update of the app cache will lead to a new version * download. * When aTopic == "offline-cache-update-unavailable" then there is no * update available (the manifest has not changed on the server). */ void initForUpdateCheck(in nsIURI aManifestURI, + in nsIPrincipal aLoadingPrincipal, in unsigned long aAppID, in boolean aInBrowser, in nsIObserver aObserver); /** * Add a dynamic URI to the offline cache as part of the update. * * @param aURI @@ -187,17 +194,17 @@ interface nsIOfflineCacheUpdate : nsISup void cancel(); /** * Return the number of bytes downloaded so far */ readonly attribute uint64_t byteProgress; }; -[scriptable, uuid(0668910d-d14f-4cee-8db5-25faebc360ab)] +[scriptable, uuid(a297a334-bcae-4779-a564-555593edc96b)] interface nsIOfflineCacheUpdateService : nsISupports { /** * Constants for the offline-app permission. * * XXX: This isn't a great place for this, but it's really the only * private offline-app-related interface */ @@ -215,50 +222,54 @@ interface nsIOfflineCacheUpdateService : /** * Schedule a cache update for a given offline manifest. If an * existing update is scheduled or running, that update will be returned. * Otherwise a new update will be scheduled. */ nsIOfflineCacheUpdate scheduleUpdate(in nsIURI aManifestURI, in nsIURI aDocumentURI, + in nsIPrincipal aLoadingPrincipal, in nsIDOMWindow aWindow); /** * Schedule a cache update for a given offline manifest using app cache * bound to the given appID+inBrowser flag. If an existing update is * scheduled or running, that update will be returned. Otherwise a new * update will be scheduled. */ nsIOfflineCacheUpdate scheduleAppUpdate(in nsIURI aManifestURI, in nsIURI aDocumentURI, + in nsIPrincipal aLoadingPrincipal, in unsigned long aAppID, in boolean aInBrowser, in nsIFile aProfileDir); /** * Schedule a cache update for a manifest when the document finishes * loading. */ void scheduleOnDocumentStop(in nsIURI aManifestURI, in nsIURI aDocumentURI, + in nsIPrincipal aLoadingPrincipal, in nsIDOMDocument aDocument); /** * Schedule a check to see if an update is available. * * This will not update or make any changes to the appcache. * It only notifies the observer to indicate whether the manifest has * changed on the server (or not): a changed manifest means that an * update is available. * * For arguments see nsIOfflineCacheUpdate.initForUpdateCheck() method * description. */ void checkForUpdate(in nsIURI aManifestURI, + in nsIPrincipal aLoadingPrincipal, in unsigned long aAppID, in boolean aInBrowser, in nsIObserver aObserver); /** * Checks whether a principal should have access to the offline * cache. * @param aPrincipal
--- a/uriloader/prefetch/nsOfflineCacheUpdate.cpp +++ b/uriloader/prefetch/nsOfflineCacheUpdate.cpp @@ -32,16 +32,17 @@ #include "nsThreadUtils.h" #include "nsProxyRelease.h" #include "nsIConsoleService.h" #include "mozilla/Logging.h" #include "nsIAsyncVerifyRedirectCallback.h" #include "mozilla/Preferences.h" #include "mozilla/Attributes.h" #include "nsContentUtils.h" +#include "nsIPrincipal.h" #include "nsXULAppAPI.h" using namespace mozilla; static const uint32_t kRescheduleLimit = 3; // Max number of retries for every entry of pinned app. static const uint32_t kPinnedEntryRetriesLimit = 3; @@ -115,20 +116,22 @@ LogToConsole(const char * message, nsOff class nsManifestCheck final : public nsIStreamListener , public nsIChannelEventSink , public nsIInterfaceRequestor { public: nsManifestCheck(nsOfflineCacheUpdate *aUpdate, nsIURI *aURI, - nsIURI *aReferrerURI) + nsIURI *aReferrerURI, + nsIPrincipal* aLoadingPrincipal) : mUpdate(aUpdate) , mURI(aURI) , mReferrerURI(aReferrerURI) + , mLoadingPrincipal(aLoadingPrincipal) {} NS_DECL_ISUPPORTS NS_DECL_NSIREQUESTOBSERVER NS_DECL_NSISTREAMLISTENER NS_DECL_NSICHANNELEVENTSINK NS_DECL_NSIINTERFACEREQUESTOR @@ -143,16 +146,17 @@ private: const char *aFromSegment, uint32_t aOffset, uint32_t aCount, uint32_t *aBytesConsumed); nsRefPtr<nsOfflineCacheUpdate> mUpdate; nsCOMPtr<nsIURI> mURI; nsCOMPtr<nsIURI> mReferrerURI; + nsCOMPtr<nsIPrincipal> mLoadingPrincipal; nsCOMPtr<nsICryptoHash> mManifestHash; nsCOMPtr<nsIChannel> mChannel; }; //----------------------------------------------------------------------------- // nsManifestCheck::nsISupports //----------------------------------------------------------------------------- NS_IMPL_ISUPPORTS(nsManifestCheck, @@ -171,18 +175,18 @@ nsManifestCheck::Begin() nsresult rv; mManifestHash = do_CreateInstance("@mozilla.org/security/hash;1", &rv); NS_ENSURE_SUCCESS(rv, rv); rv = mManifestHash->Init(nsICryptoHash::MD5); NS_ENSURE_SUCCESS(rv, rv); rv = NS_NewChannel(getter_AddRefs(mChannel), mURI, - nsContentUtils::GetSystemPrincipal(), - nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, + mLoadingPrincipal, + nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED, nsIContentPolicy::TYPE_OTHER, nullptr, // loadGroup nullptr, // aCallbacks nsIRequest::LOAD_BYPASS_CACHE); NS_ENSURE_SUCCESS(rv, rv); // configure HTTP specific stuff @@ -312,21 +316,23 @@ NS_IMPL_ISUPPORTS(nsOfflineCacheUpdateIt nsIChannelEventSink) //----------------------------------------------------------------------------- // nsOfflineCacheUpdateItem <public> //----------------------------------------------------------------------------- nsOfflineCacheUpdateItem::nsOfflineCacheUpdateItem(nsIURI *aURI, nsIURI *aReferrerURI, + nsIPrincipal* aLoadingPrincipal, nsIApplicationCache *aApplicationCache, nsIApplicationCache *aPreviousApplicationCache, uint32_t type) : mURI(aURI) , mReferrerURI(aReferrerURI) + , mLoadingPrincipal(aLoadingPrincipal) , mApplicationCache(aApplicationCache) , mPreviousApplicationCache(aPreviousApplicationCache) , mItemType(type) , mChannel(nullptr) , mState(LoadStatus::UNINITIALIZED) , mBytesRead(0) { } @@ -362,17 +368,17 @@ nsOfflineCacheUpdateItem::OpenChannel(ns // Same app cache to read from and to write to is used during // an only-update-check procedure. Here we protect the existing // cache from being modified. flags |= nsIRequest::INHIBIT_CACHING; } rv = NS_NewChannel(getter_AddRefs(mChannel), mURI, - nsContentUtils::GetSystemPrincipal(), + mLoadingPrincipal, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, nsIContentPolicy::TYPE_OTHER, nullptr, // aLoadGroup this, // aCallbacks flags); NS_ENSURE_SUCCESS(rv, rv); @@ -669,19 +675,20 @@ nsOfflineCacheUpdateItem::GetStatus(uint //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // nsOfflineManifestItem <public> //----------------------------------------------------------------------------- nsOfflineManifestItem::nsOfflineManifestItem(nsIURI *aURI, nsIURI *aReferrerURI, + nsIPrincipal* aLoadingPrincipal, nsIApplicationCache *aApplicationCache, nsIApplicationCache *aPreviousApplicationCache) - : nsOfflineCacheUpdateItem(aURI, aReferrerURI, + : nsOfflineCacheUpdateItem(aURI, aReferrerURI, aLoadingPrincipal, aApplicationCache, aPreviousApplicationCache, nsIApplicationCache::ITEM_MANIFEST) , mParserState(PARSE_INIT) , mNeedsUpdate(true) , mManifestHashInitialized(false) { ReadStrictFileOriginPolicyPref(); } @@ -1183,61 +1190,64 @@ nsOfflineCacheUpdate::GetCacheKey(nsIURI rv = newURI->GetAsciiSpec(aKey); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; } nsresult -nsOfflineCacheUpdate::InitInternal(nsIURI *aManifestURI) +nsOfflineCacheUpdate::InitInternal(nsIURI *aManifestURI, + nsIPrincipal* aLoadingPrincipal) { nsresult rv; // Only http and https applications are supported. bool match; rv = aManifestURI->SchemeIs("http", &match); NS_ENSURE_SUCCESS(rv, rv); if (!match) { rv = aManifestURI->SchemeIs("https", &match); NS_ENSURE_SUCCESS(rv, rv); if (!match) return NS_ERROR_ABORT; } mManifestURI = aManifestURI; + mLoadingPrincipal = aLoadingPrincipal; rv = mManifestURI->GetAsciiHost(mUpdateDomain); NS_ENSURE_SUCCESS(rv, rv); mPartialUpdate = false; return NS_OK; } nsresult nsOfflineCacheUpdate::Init(nsIURI *aManifestURI, nsIURI *aDocumentURI, + nsIPrincipal* aLoadingPrincipal, nsIDOMDocument *aDocument, nsIFile *aCustomProfileDir, uint32_t aAppID, bool aInBrowser) { nsresult rv; // Make sure the service has been initialized nsOfflineCacheUpdateService* service = nsOfflineCacheUpdateService::EnsureService(); if (!service) return NS_ERROR_FAILURE; LOG(("nsOfflineCacheUpdate::Init [%p]", this)); - rv = InitInternal(aManifestURI); + rv = InitInternal(aManifestURI, aLoadingPrincipal); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIApplicationCacheService> cacheService = do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); mDocumentURI = aDocumentURI; @@ -1287,31 +1297,32 @@ nsOfflineCacheUpdate::Init(nsIURI *aMani mInBrowser = aInBrowser; mState = STATE_INITIALIZED; return NS_OK; } nsresult nsOfflineCacheUpdate::InitForUpdateCheck(nsIURI *aManifestURI, + nsIPrincipal* aLoadingPrincipal, uint32_t aAppID, bool aInBrowser, nsIObserver *aObserver) { nsresult rv; // Make sure the service has been initialized nsOfflineCacheUpdateService* service = nsOfflineCacheUpdateService::EnsureService(); if (!service) return NS_ERROR_FAILURE; LOG(("nsOfflineCacheUpdate::InitForUpdateCheck [%p]", this)); - rv = InitInternal(aManifestURI); + rv = InitInternal(aManifestURI, aLoadingPrincipal); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIApplicationCacheService> cacheService = do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); rv = cacheService->BuildGroupIDForApp(aManifestURI, aAppID, aInBrowser, @@ -1340,30 +1351,32 @@ nsOfflineCacheUpdate::InitForUpdateCheck mState = STATE_INITIALIZED; return NS_OK; } nsresult nsOfflineCacheUpdate::InitPartial(nsIURI *aManifestURI, const nsACString& clientID, - nsIURI *aDocumentURI) + nsIURI *aDocumentURI, + nsIPrincipal *aLoadingPrincipal) { nsresult rv; // Make sure the service has been initialized nsOfflineCacheUpdateService* service = nsOfflineCacheUpdateService::EnsureService(); if (!service) return NS_ERROR_FAILURE; LOG(("nsOfflineCacheUpdate::InitPartial [%p]", this)); mPartialUpdate = true; mDocumentURI = aDocumentURI; + mLoadingPrincipal = aLoadingPrincipal; mManifestURI = aManifestURI; rv = mManifestURI->GetAsciiHost(mUpdateDomain); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIApplicationCacheService> cacheService = do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); @@ -1691,17 +1704,17 @@ nsOfflineCacheUpdate::ManifestCheckCompl // from a new update through this dead update to them is absolutely // correct. FinishNoNotify(); nsRefPtr<nsOfflineCacheUpdate> newUpdate = new nsOfflineCacheUpdate(); // Leave aDocument argument null. Only glues and children keep // document instances. - newUpdate->Init(mManifestURI, mDocumentURI, nullptr, + newUpdate->Init(mManifestURI, mDocumentURI, mLoadingPrincipal, nullptr, mCustomProfileDir, mAppID, mInBrowser); // In a rare case the manifest will not be modified on the next refetch // transfer all master document URIs to the new update to ensure that // all documents refering it will be properly cached. for (int32_t i = 0; i < mDocumentURIs.Count(); i++) { newUpdate->StickDocument(mDocumentURIs[i]); } @@ -1743,16 +1756,17 @@ nsOfflineCacheUpdate::Begin() return NS_OK; } // Start checking the manifest. nsCOMPtr<nsIURI> uri; mManifestItem = new nsOfflineManifestItem(mManifestURI, mDocumentURI, + mLoadingPrincipal, mApplicationCache, mPreviousApplicationCache); if (!mManifestItem) { return NS_ERROR_OUT_OF_MEMORY; } mState = STATE_CHECKING; mByteProgress = 0; @@ -1848,17 +1862,17 @@ nsOfflineCacheUpdate::ProcessNextURI() if (mPartialUpdate) { return Finish(); } else { // Verify that the manifest wasn't changed during the // update, to prevent capturing a cache while the server // is being updated. The check will call // ManifestCheckCompleted() when it's done. nsRefPtr<nsManifestCheck> manifestCheck = - new nsManifestCheck(this, mManifestURI, mDocumentURI); + new nsManifestCheck(this, mManifestURI, mDocumentURI, mLoadingPrincipal); if (NS_FAILED(manifestCheck->Begin())) { mSucceeded = false; NotifyState(nsIOfflineCacheUpdateObserver::STATE_ERROR); return Finish(); } return NS_OK; } @@ -2041,17 +2055,17 @@ nsOfflineCacheUpdate::ScheduleImplicit() else if (mApplicationCache) { rv = mApplicationCache->GetClientID(clientID); NS_ENSURE_SUCCESS(rv, rv); } else { NS_ERROR("Offline cache update not having set mApplicationCache?"); } - rv = update->InitPartial(mManifestURI, clientID, mDocumentURI); + rv = update->InitPartial(mManifestURI, clientID, mDocumentURI, mLoadingPrincipal); NS_ENSURE_SUCCESS(rv, rv); for (int32_t i = 0; i < mDocumentURIs.Count(); i++) { rv = update->AddURI(mDocumentURIs[i], nsIApplicationCache::ITEM_IMPLICIT); NS_ENSURE_SUCCESS(rv, rv); } @@ -2283,16 +2297,17 @@ nsOfflineCacheUpdate::AddURI(nsIURI *aUR mItems[i]->mItemType |= aType; return NS_OK; } } nsRefPtr<nsOfflineCacheUpdateItem> item = new nsOfflineCacheUpdateItem(aURI, mDocumentURI, + mLoadingPrincipal, mApplicationCache, mPreviousApplicationCache, aType); if (!item) return NS_ERROR_OUT_OF_MEMORY; mItems.AppendElement(item); mAddedItems = true;
--- a/uriloader/prefetch/nsOfflineCacheUpdate.h +++ b/uriloader/prefetch/nsOfflineCacheUpdate.h @@ -46,26 +46,28 @@ public: NS_DECL_NSIREQUESTOBSERVER NS_DECL_NSISTREAMLISTENER NS_DECL_NSIRUNNABLE NS_DECL_NSIINTERFACEREQUESTOR NS_DECL_NSICHANNELEVENTSINK nsOfflineCacheUpdateItem(nsIURI *aURI, nsIURI *aReferrerURI, + nsIPrincipal* aLoadingPrincipal, nsIApplicationCache *aApplicationCache, nsIApplicationCache *aPreviousApplicationCache, uint32_t aType); - nsCOMPtr<nsIURI> mURI; - nsCOMPtr<nsIURI> mReferrerURI; + nsCOMPtr<nsIURI> mURI; + nsCOMPtr<nsIURI> mReferrerURI; + nsCOMPtr<nsIPrincipal> mLoadingPrincipal; nsCOMPtr<nsIApplicationCache> mApplicationCache; nsCOMPtr<nsIApplicationCache> mPreviousApplicationCache; - nsCString mCacheKey; - uint32_t mItemType; + nsCString mCacheKey; + uint32_t mItemType; nsresult OpenChannel(nsOfflineCacheUpdate *aUpdate); nsresult Cancel(); nsresult GetRequestSucceeded(bool * succeeded); bool IsInProgress(); bool IsScheduled(); bool IsCompleted(); @@ -94,16 +96,17 @@ protected: class nsOfflineManifestItem : public nsOfflineCacheUpdateItem { public: NS_DECL_NSISTREAMLISTENER NS_DECL_NSIREQUESTOBSERVER nsOfflineManifestItem(nsIURI *aURI, nsIURI *aReferrerURI, + nsIPrincipal* aLoadingPrincipal, nsIApplicationCache *aApplicationCache, nsIApplicationCache *aPreviousApplicationCache); virtual ~nsOfflineManifestItem(); nsCOMArray<nsIURI> &GetExplicitURIs() { return mExplicitURIs; } nsCOMArray<nsIURI> &GetFallbackURIs() { return mFallbackURIs; } nsTArray<nsCString> &GetOpportunisticNamespaces() @@ -223,17 +226,17 @@ public: protected: ~nsOfflineCacheUpdate(); friend class nsOfflineCacheUpdateItem; void OnByteProgress(uint64_t byteIncrement); private: - nsresult InitInternal(nsIURI *aManifestURI); + nsresult InitInternal(nsIURI *aManifestURI, nsIPrincipal* aPrincipal); nsresult HandleManifest(bool *aDoUpdate); nsresult AddURI(nsIURI *aURI, uint32_t aItemType); nsresult ProcessNextURI(); // Adds items from the previous cache witha type matching aType. // If namespaceFilter is non-null, only items matching the // specified namespaces will be added. @@ -270,16 +273,17 @@ private: bool mOnlyCheckUpdate; bool mSucceeded; bool mObsolete; nsCString mUpdateDomain; nsCString mGroupID; nsCOMPtr<nsIURI> mManifestURI; nsCOMPtr<nsIURI> mDocumentURI; + nsCOMPtr<nsIPrincipal> mLoadingPrincipal; nsCOMPtr<nsIFile> mCustomProfileDir; uint32_t mAppID; bool mInBrowser; nsCOMPtr<nsIObserver> mUpdateAvailableObserver; nsCOMPtr<nsIApplicationCache> mApplicationCache; @@ -333,16 +337,17 @@ public: nsresult FindUpdate(nsIURI *aManifestURI, uint32_t aAppID, bool aInBrowser, nsIFile *aCustomProfileDir, nsOfflineCacheUpdate **aUpdate); nsresult Schedule(nsIURI *aManifestURI, nsIURI *aDocumentURI, + nsIPrincipal* aLoadingPrincipal, nsIDOMDocument *aDocument, nsIDOMWindow* aWindow, nsIFile* aCustomProfileDir, uint32_t aAppID, bool aInBrowser, nsIOfflineCacheUpdate **aUpdate); virtual nsresult UpdateFinished(nsOfflineCacheUpdate *aUpdate) override;
--- a/uriloader/prefetch/nsOfflineCacheUpdateService.cpp +++ b/uriloader/prefetch/nsOfflineCacheUpdateService.cpp @@ -126,31 +126,34 @@ class nsOfflineCachePendingUpdate final { public: NS_DECL_ISUPPORTS NS_DECL_NSIWEBPROGRESSLISTENER nsOfflineCachePendingUpdate(nsOfflineCacheUpdateService *aService, nsIURI *aManifestURI, nsIURI *aDocumentURI, + nsIPrincipal* aLoadingPrincipal, nsIDOMDocument *aDocument) : mService(aService) , mManifestURI(aManifestURI) , mDocumentURI(aDocumentURI) + , mLoadingPrincipal(aLoadingPrincipal) , mDidReleaseThis(false) { mDocument = do_GetWeakReference(aDocument); } private: ~nsOfflineCachePendingUpdate() {} nsRefPtr<nsOfflineCacheUpdateService> mService; nsCOMPtr<nsIURI> mManifestURI; nsCOMPtr<nsIURI> mDocumentURI; + nsCOMPtr<nsIPrincipal> mLoadingPrincipal; nsCOMPtr<nsIWeakReference> mDocument; bool mDidReleaseThis; }; NS_IMPL_ISUPPORTS(nsOfflineCachePendingUpdate, nsIWebProgressListener, nsISupportsWeakReference) @@ -213,19 +216,18 @@ nsOfflineCachePendingUpdate::OnStateChan if (NS_SUCCEEDED(aStatus)) { // Get extended origin attributes uint32_t appId; bool isInBrowserElement; nsresult rv = GetAppIDAndInBrowserFromWindow(window, &appId, &isInBrowserElement); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIOfflineCacheUpdate> update; - mService->Schedule(mManifestURI, mDocumentURI, - updateDoc, window, nullptr, - appId, isInBrowserElement, getter_AddRefs(update)); + mService->Schedule(mManifestURI, mDocumentURI, mLoadingPrincipal, updateDoc, window, + nullptr, appId, isInBrowserElement, getter_AddRefs(update)); if (mDidReleaseThis) { return NS_OK; } } aWebProgress->RemoveProgressListener(this); MOZ_ASSERT(!mDidReleaseThis); mDidReleaseThis = true; @@ -370,29 +372,30 @@ nsOfflineCacheUpdateService::ScheduleUpd ProcessNextUpdate(); return NS_OK; } NS_IMETHODIMP nsOfflineCacheUpdateService::ScheduleOnDocumentStop(nsIURI *aManifestURI, nsIURI *aDocumentURI, + nsIPrincipal* aLoadingPrincipal, nsIDOMDocument *aDocument) { LOG(("nsOfflineCacheUpdateService::ScheduleOnDocumentStop [%p, manifestURI=%p, documentURI=%p doc=%p]", this, aManifestURI, aDocumentURI, aDocument)); nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDocument); nsCOMPtr<nsIWebProgress> progress = do_QueryInterface(doc->GetContainer()); NS_ENSURE_TRUE(progress, NS_ERROR_INVALID_ARG); // Proceed with cache update nsRefPtr<nsOfflineCachePendingUpdate> update = - new nsOfflineCachePendingUpdate(this, aManifestURI, - aDocumentURI, aDocument); + new nsOfflineCachePendingUpdate(this, aManifestURI, aDocumentURI, + aLoadingPrincipal, aDocument); NS_ENSURE_TRUE(update, NS_ERROR_OUT_OF_MEMORY); nsresult rv = progress->AddProgressListener (update, nsIWebProgress::NOTIFY_STATE_DOCUMENT); NS_ENSURE_SUCCESS(rv, rv); // The update will release when it has scheduled itself. unused << update.forget(); @@ -515,16 +518,17 @@ nsOfflineCacheUpdateService::FindUpdate( } return NS_ERROR_NOT_AVAILABLE; } nsresult nsOfflineCacheUpdateService::Schedule(nsIURI *aManifestURI, nsIURI *aDocumentURI, + nsIPrincipal* aLoadingPrincipal, nsIDOMDocument *aDocument, nsIDOMWindow* aWindow, nsIFile* aCustomProfileDir, uint32_t aAppID, bool aInBrowser, nsIOfflineCacheUpdate **aUpdate) { nsCOMPtr<nsIOfflineCacheUpdate> update; @@ -540,70 +544,73 @@ nsOfflineCacheUpdateService::Schedule(ns if (aWindow) { // Ensure there is window.applicationCache object that is // responsible for association of the new applicationCache // with the corresponding document. Just ignore the result. nsCOMPtr<nsIDOMOfflineResourceList> appCacheWindowObject; aWindow->GetApplicationCache(getter_AddRefs(appCacheWindowObject)); } - rv = update->Init(aManifestURI, aDocumentURI, aDocument, + rv = update->Init(aManifestURI, aDocumentURI, aLoadingPrincipal, aDocument, aCustomProfileDir, aAppID, aInBrowser); NS_ENSURE_SUCCESS(rv, rv); rv = update->Schedule(); NS_ENSURE_SUCCESS(rv, rv); NS_ADDREF(*aUpdate = update); return NS_OK; } NS_IMETHODIMP nsOfflineCacheUpdateService::ScheduleUpdate(nsIURI *aManifestURI, nsIURI *aDocumentURI, + nsIPrincipal* aLoadingPrincipal, nsIDOMWindow *aWindow, nsIOfflineCacheUpdate **aUpdate) { // Get extended origin attributes uint32_t appId; bool isInBrowser; nsresult rv = GetAppIDAndInBrowserFromWindow(aWindow, &appId, &isInBrowser); NS_ENSURE_SUCCESS(rv, rv); - return Schedule(aManifestURI, aDocumentURI, nullptr, aWindow, nullptr, - appId, isInBrowser, aUpdate); + return Schedule(aManifestURI, aDocumentURI, aLoadingPrincipal, nullptr, aWindow, + nullptr, appId, isInBrowser, aUpdate); } NS_IMETHODIMP nsOfflineCacheUpdateService::ScheduleAppUpdate(nsIURI *aManifestURI, nsIURI *aDocumentURI, + nsIPrincipal* aLoadingPrincipal, uint32_t aAppID, bool aInBrowser, nsIFile *aProfileDir, nsIOfflineCacheUpdate **aUpdate) { - return Schedule(aManifestURI, aDocumentURI, nullptr, nullptr, aProfileDir, - aAppID, aInBrowser, aUpdate); + return Schedule(aManifestURI, aDocumentURI, aLoadingPrincipal, nullptr, nullptr, + aProfileDir, aAppID, aInBrowser, aUpdate); } NS_IMETHODIMP nsOfflineCacheUpdateService::CheckForUpdate(nsIURI *aManifestURI, + nsIPrincipal* aLoadingPrincipal, uint32_t aAppID, bool aInBrowser, nsIObserver *aObserver) { if (GeckoProcessType_Default != XRE_GetProcessType()) { // Not intended to support this on child processes return NS_ERROR_NOT_IMPLEMENTED; } nsCOMPtr<nsIOfflineCacheUpdate> update = new OfflineCacheUpdateGlue(); nsresult rv; - rv = update->InitForUpdateCheck(aManifestURI, aAppID, aInBrowser, aObserver); + rv = update->InitForUpdateCheck(aManifestURI, aLoadingPrincipal, aAppID, aInBrowser, aObserver); NS_ENSURE_SUCCESS(rv, rv); rv = update->Schedule(); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; }