diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 98affe1305b0..c6b6b3a63751 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -4537,7 +4537,8 @@ void ContentParent::NotifyRebuildFontList() { already_AddRefed ContentParent::AllocPOfflineCacheUpdateParent( const URIParams& aManifestURI, const URIParams& aDocumentURI, - const PrincipalInfo& aLoadingPrincipalInfo, const bool& aStickDocument) { + const PrincipalInfo& aLoadingPrincipalInfo, const bool& aStickDocument, + const CookieSettingsArgs& aCookieSettingsArgs) { RefPtr update = new mozilla::docshell::OfflineCacheUpdateParent(); return update.forget(); @@ -4546,14 +4547,14 @@ ContentParent::AllocPOfflineCacheUpdateParent( mozilla::ipc::IPCResult ContentParent::RecvPOfflineCacheUpdateConstructor( POfflineCacheUpdateParent* aActor, const URIParams& aManifestURI, const URIParams& aDocumentURI, const PrincipalInfo& aLoadingPrincipal, - const bool& aStickDocument) { + const bool& aStickDocument, const CookieSettingsArgs& aCookieSettingsArgs) { MOZ_ASSERT(aActor); RefPtr update = static_cast(aActor); nsresult rv = update->Schedule(aManifestURI, aDocumentURI, aLoadingPrincipal, - aStickDocument); + aStickDocument, aCookieSettingsArgs); if (NS_FAILED(rv) && IsAlive()) { // Inform the child of failure. Unused << update->SendFinish(false, false); diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index 1ccc7046f57b..fceb9e5cd49f 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -483,12 +483,14 @@ class ContentParent final : public PContentParent, already_AddRefed AllocPOfflineCacheUpdateParent( const URIParams& aManifestURI, const URIParams& aDocumentURI, - const PrincipalInfo& aLoadingPrincipalInfo, const bool& aStickDocument); + const PrincipalInfo& aLoadingPrincipalInfo, const bool& aStickDocument, + const CookieSettingsArgs& aCookieSettingsArgs); virtual mozilla::ipc::IPCResult RecvPOfflineCacheUpdateConstructor( POfflineCacheUpdateParent* aActor, const URIParams& aManifestURI, const URIParams& aDocumentURI, const PrincipalInfo& aLoadingPrincipal, - const bool& stickDocument) override; + const bool& stickDocument, + const CookieSettingsArgs& aCookieSettingsArgs) override; mozilla::ipc::IPCResult RecvSetOfflinePermission( const IPC::Principal& principal); diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index f4f851591857..c2cbc3d32d6d 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -1082,7 +1082,8 @@ parent: * To identify which tab owns the app. */ async POfflineCacheUpdate(URIParams manifestURI, URIParams documentURI, - PrincipalInfo loadingPrincipal, bool stickDocument); + PrincipalInfo loadingPrincipal, bool stickDocument, + CookieSettingsArgs cookieSettings); /** * Sets "offline-app" permission for the principal. Called when we hit diff --git a/dom/offline/nsDOMOfflineResourceList.cpp b/dom/offline/nsDOMOfflineResourceList.cpp index d97b3795654f..b8f8a282a118 100644 --- a/dom/offline/nsDOMOfflineResourceList.cpp +++ b/dom/offline/nsDOMOfflineResourceList.cpp @@ -374,8 +374,11 @@ void nsDOMOfflineResourceList::MozAdd(const nsAString& aURI, ErrorResult& aRv) { return; } + RefPtr doc = GetOwner()->GetExtantDoc(); + nsCOMPtr cs = doc ? doc->CookieSettings() : nullptr; + rv = update->InitPartial(mManifestURI, clientID, mDocumentURI, - mLoadingPrincipal); + mLoadingPrincipal, cs); if (NS_WARN_IF(NS_FAILED(rv))) { aRv.Throw(rv); return; diff --git a/netwerk/cookie/CookieSettings.h b/netwerk/cookie/CookieSettings.h index 24c9f59ffb73..c3a4bd6dbe54 100644 --- a/netwerk/cookie/CookieSettings.h +++ b/netwerk/cookie/CookieSettings.h @@ -113,6 +113,10 @@ class CookieSettings final : public nsICookieSettings { static already_AddRefed Create(); + static CookieSettings* Cast(nsICookieSettings* aCS) { + return static_cast(aCS); + } + void Serialize(CookieSettingsArgs& aData); static void Deserialize(const CookieSettingsArgs& aData, diff --git a/uriloader/prefetch/OfflineCacheUpdateChild.cpp b/uriloader/prefetch/OfflineCacheUpdateChild.cpp index 020a65efbf0d..f92916df96c5 100644 --- a/uriloader/prefetch/OfflineCacheUpdateChild.cpp +++ b/uriloader/prefetch/OfflineCacheUpdateChild.cpp @@ -20,6 +20,7 @@ #include "nsIDocShellTreeOwner.h" #include "nsPIDOMWindow.h" #include "mozilla/dom/Document.h" +#include "mozilla/net/CookieSettings.h" #include "nsIObserverService.h" #include "nsIURL.h" #include "nsIBrowserChild.h" @@ -118,6 +119,8 @@ void OfflineCacheUpdateChild::SetDocument(Document* aDocument) { // implicit (which are the reasons we collect documents here). if (!aDocument) return; + mCookieSettings = aDocument->CookieSettings(); + nsIChannel* channel = aDocument->GetChannel(); nsCOMPtr appCacheChannel = do_QueryInterface(channel); @@ -202,7 +205,8 @@ NS_IMETHODIMP OfflineCacheUpdateChild::InitPartial(nsIURI* aManifestURI, const nsACString& clientID, nsIURI* aDocumentURI, - nsIPrincipal* aLoadingPrincipal) { + nsIPrincipal* aLoadingPrincipal, + nsICookieSettings* aCookieSettings) { MOZ_ASSERT_UNREACHABLE( "Not expected to do partial offline cache updates" " on the child process"); @@ -394,8 +398,14 @@ OfflineCacheUpdateChild::Schedule() { // See also nsOfflineCacheUpdate::ScheduleImplicit. bool stickDocument = mDocument != nullptr; + CookieSettingsArgs csArgs; + if (mCookieSettings) { + CookieSettings::Cast(mCookieSettings)->Serialize(csArgs); + } + ContentChild::GetSingleton()->SendPOfflineCacheUpdateConstructor( - this, manifestURI, documentURI, loadingPrincipalInfo, stickDocument); + this, manifestURI, documentURI, loadingPrincipalInfo, stickDocument, + csArgs); return NS_OK; } diff --git a/uriloader/prefetch/OfflineCacheUpdateChild.h b/uriloader/prefetch/OfflineCacheUpdateChild.h index 0eaeb1699470..0fec77558271 100644 --- a/uriloader/prefetch/OfflineCacheUpdateChild.h +++ b/uriloader/prefetch/OfflineCacheUpdateChild.h @@ -66,6 +66,7 @@ class OfflineCacheUpdateChild : public nsIOfflineCacheUpdate, nsCOMPtr mManifestURI; nsCOMPtr mDocumentURI; nsCOMPtr mLoadingPrincipal; + nsCOMPtr mCookieSettings; nsCOMPtr mObserverService; diff --git a/uriloader/prefetch/OfflineCacheUpdateGlue.cpp b/uriloader/prefetch/OfflineCacheUpdateGlue.cpp index 86cbeae27524..c06f3ac504f1 100644 --- a/uriloader/prefetch/OfflineCacheUpdateGlue.cpp +++ b/uriloader/prefetch/OfflineCacheUpdateGlue.cpp @@ -62,6 +62,8 @@ nsIOfflineCacheUpdate* OfflineCacheUpdateGlue::EnsureUpdate() { mUpdate = new nsOfflineCacheUpdate(); LOG(("OfflineCacheUpdateGlue [%p] is using update [%p]", this, mUpdate.get())); + + mUpdate->SetCookieSettings(mCookieSettings); } return mUpdate; @@ -120,8 +122,12 @@ OfflineCacheUpdateGlue::Init(nsIURI* aManifestURI, nsIURI* aDocumentURI, return NS_OK; } - return mUpdate->Init(aManifestURI, aDocumentURI, aLoadingPrincipal, nullptr, - aCustomProfileDir); + rv = mUpdate->Init(aManifestURI, aDocumentURI, aLoadingPrincipal, nullptr, + aCustomProfileDir); + + mUpdate->SetCookieSettings(mCookieSettings); + + return rv; } void OfflineCacheUpdateGlue::SetDocument(Document* aDocument) { @@ -138,6 +144,8 @@ void OfflineCacheUpdateGlue::SetDocument(Document* aDocument) { // implicit (which are the reasons we collect documents here). if (!aDocument) return; + mCookieSettings = aDocument->CookieSettings(); + nsIChannel* channel = aDocument->GetChannel(); nsCOMPtr appCacheChannel = do_QueryInterface(channel); diff --git a/uriloader/prefetch/OfflineCacheUpdateGlue.h b/uriloader/prefetch/OfflineCacheUpdateGlue.h index 14489df018b4..a219990b9c53 100644 --- a/uriloader/prefetch/OfflineCacheUpdateGlue.h +++ b/uriloader/prefetch/OfflineCacheUpdateGlue.h @@ -51,10 +51,11 @@ namespace docshell { } \ NS_IMETHOD InitPartial(nsIURI* aManifestURI, const nsACString& aClientID, \ nsIURI* aDocumentURI, \ - nsIPrincipal* aLoadingPrincipal) override { \ + nsIPrincipal* aLoadingPrincipal, \ + nsICookieSettings* aCookieSettings) override { \ return !_to ? NS_ERROR_NULL_POINTER \ : _to->InitPartial(aManifestURI, aClientID, aDocumentURI, \ - aLoadingPrincipal); \ + aLoadingPrincipal, aCookieSettings); \ } \ NS_IMETHOD InitForUpdateCheck(nsIURI* aManifestURI, \ nsIPrincipal* aLoadingPrincipal, \ @@ -115,6 +116,7 @@ class OfflineCacheUpdateGlue final : public nsSupportsWeakReference, RefPtr mDocument; nsCOMPtr mDocumentURI; nsCOMPtr mLoadingPrincipal; + nsCOMPtr mCookieSettings; }; } // namespace docshell diff --git a/uriloader/prefetch/OfflineCacheUpdateParent.cpp b/uriloader/prefetch/OfflineCacheUpdateParent.cpp index df1364449780..5101feca2341 100644 --- a/uriloader/prefetch/OfflineCacheUpdateParent.cpp +++ b/uriloader/prefetch/OfflineCacheUpdateParent.cpp @@ -72,7 +72,8 @@ void OfflineCacheUpdateParent::ActorDestroy(ActorDestroyReason why) { nsresult OfflineCacheUpdateParent::Schedule( const URIParams& aManifestURI, const URIParams& aDocumentURI, - const PrincipalInfo& aLoadingPrincipalInfo, const bool& stickDocument) { + const PrincipalInfo& aLoadingPrincipalInfo, const bool& stickDocument, + const CookieSettingsArgs& aCookieSettingsArgs) { LOG(("OfflineCacheUpdateParent::RecvSchedule [%p]", this)); nsresult rv; @@ -116,6 +117,8 @@ nsresult OfflineCacheUpdateParent::Schedule( nullptr); NS_ENSURE_SUCCESS(rv, rv); + update->SetCookieSettingsArgs(aCookieSettingsArgs); + // Must add before Schedule() call otherwise we would miss // oncheck event notification. update->AddObserver(this, false); @@ -123,6 +126,8 @@ nsresult OfflineCacheUpdateParent::Schedule( rv = update->Schedule(); NS_ENSURE_SUCCESS(rv, rv); } else { + update->SetCookieSettingsArgs(aCookieSettingsArgs); + update->AddObserver(this, false); } diff --git a/uriloader/prefetch/OfflineCacheUpdateParent.h b/uriloader/prefetch/OfflineCacheUpdateParent.h index ff7af90e7362..1fe0374644f8 100644 --- a/uriloader/prefetch/OfflineCacheUpdateParent.h +++ b/uriloader/prefetch/OfflineCacheUpdateParent.h @@ -22,6 +22,10 @@ namespace ipc { class URIParams; } // namespace ipc +namespace net { +class CookieSettingsArgs; +} + namespace docshell { class OfflineCacheUpdateParent : public POfflineCacheUpdateParent, @@ -37,7 +41,8 @@ class OfflineCacheUpdateParent : public POfflineCacheUpdateParent, nsresult Schedule(const URIParams& manifestURI, const URIParams& documentURI, const PrincipalInfo& loadingPrincipalInfo, - const bool& stickDocument); + const bool& stickDocument, + const net::CookieSettingsArgs& aCookieSettingsArgs); void StopSendingMessagesToChild() { mIPCClosed = true; } diff --git a/uriloader/prefetch/nsIOfflineCacheUpdate.idl b/uriloader/prefetch/nsIOfflineCacheUpdate.idl index 170cd820a019..6c2cceff8108 100644 --- a/uriloader/prefetch/nsIOfflineCacheUpdate.idl +++ b/uriloader/prefetch/nsIOfflineCacheUpdate.idl @@ -13,6 +13,7 @@ interface nsIPrefBranch; interface nsIApplicationCache; interface nsIFile; interface nsIObserver; +interface nsICookieSettings; webidl Document; [scriptable, uuid(47360d57-8ef4-4a5d-8865-1a27a739ad1a)] @@ -126,9 +127,13 @@ interface nsIOfflineCacheUpdate : nsISupports { * @param aDocumentURI * The page that is requesting the update. May be null * when this information is unknown. + * @param aCookieSettings + * The cookie settings belonging to the page that is requesting + * the update. */ void initPartial(in nsIURI aManifestURI, in ACString aClientID, - in nsIURI aDocumentURI, in nsIPrincipal aPrincipal); + in nsIURI aDocumentURI, in nsIPrincipal aPrincipal, + in nsICookieSettings aCookieSettings); /** * Initialize the update to only check whether there is an update diff --git a/uriloader/prefetch/nsOfflineCacheUpdate.cpp b/uriloader/prefetch/nsOfflineCacheUpdate.cpp index c0fbc5d15cf0..8e2fb449fe02 100644 --- a/uriloader/prefetch/nsOfflineCacheUpdate.cpp +++ b/uriloader/prefetch/nsOfflineCacheUpdate.cpp @@ -154,8 +154,7 @@ nsresult nsManifestCheck::Begin() { NS_ENSURE_SUCCESS(rv, rv); rv = NS_NewChannel(getter_AddRefs(mChannel), mURI, mLoadingPrincipal, nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED, - nsIContentPolicy::TYPE_OTHER, - nullptr, // nsICookieSettings + nsIContentPolicy::TYPE_OTHER, mUpdate->CookieSettings(), nullptr, // PerformanceStorage nullptr, // loadGroup nullptr, // aCallbacks @@ -322,8 +321,7 @@ nsresult nsOfflineCacheUpdateItem::OpenChannel(nsOfflineCacheUpdate* aUpdate) { rv = NS_NewChannel(getter_AddRefs(mChannel), mURI, mLoadingPrincipal, nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, - nsIContentPolicy::TYPE_OTHER, - nullptr, // nsICookieSettings + nsIContentPolicy::TYPE_OTHER, aUpdate->CookieSettings(), nullptr, // PerformanceStorage nullptr, // aLoadGroup this, // aCallbacks @@ -1183,6 +1181,10 @@ nsresult nsOfflineCacheUpdate::Init(nsIURI* aManifestURI, nsIURI* aDocumentURI, mDocumentURI = aDocumentURI; + if (aDocument) { + mCookieSettings = aDocument->CookieSettings(); + } + if (aCustomProfileDir) { rv = cacheService->BuildGroupIDForSuffix(aManifestURI, originSuffix, mGroupID); @@ -1277,7 +1279,8 @@ nsresult nsOfflineCacheUpdate::InitForUpdateCheck( nsresult nsOfflineCacheUpdate::InitPartial(nsIURI* aManifestURI, const nsACString& clientID, nsIURI* aDocumentURI, - nsIPrincipal* aLoadingPrincipal) { + nsIPrincipal* aLoadingPrincipal, + nsICookieSettings* aCookieSettings) { nsresult rv; // Make sure the service has been initialized @@ -1324,6 +1327,8 @@ nsresult nsOfflineCacheUpdate::InitPartial(nsIURI* aManifestURI, &mPinned); NS_ENSURE_SUCCESS(rv, rv); + mCookieSettings = aCookieSettings; + mState = STATE_INITIALIZED; return NS_OK; } @@ -1626,6 +1631,8 @@ void nsOfflineCacheUpdate::ManifestCheckCompleted( newUpdate->Init(mManifestURI, mDocumentURI, mLoadingPrincipal, nullptr, mCustomProfileDir); + newUpdate->SetCookieSettings(mCookieSettings); + // 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. @@ -1932,7 +1939,7 @@ nsresult nsOfflineCacheUpdate::ScheduleImplicit() { } rv = update->InitPartial(mManifestURI, clientID, mDocumentURI, - mLoadingPrincipal); + mLoadingPrincipal, mCookieSettings); NS_ENSURE_SUCCESS(rv, rv); for (int32_t i = 0; i < mDocumentURIs.Count(); i++) { @@ -2293,6 +2300,19 @@ nsOfflineCacheUpdate::UpdateStateChanged(nsIOfflineCacheUpdate* aUpdate, return NS_OK; } +void nsOfflineCacheUpdate::SetCookieSettings( + nsICookieSettings* aCookieSettings) { + mCookieSettings = aCookieSettings; +} + +void nsOfflineCacheUpdate::SetCookieSettingsArgs( + const CookieSettingsArgs& aCookieSettingsArgs) { + MOZ_ASSERT(!mCookieSettings); + + CookieSettings::Deserialize(aCookieSettingsArgs, + getter_AddRefs(mCookieSettings)); +} + NS_IMETHODIMP nsOfflineCacheUpdate::ApplicationCacheAvailable( nsIApplicationCache* applicationCache) { diff --git a/uriloader/prefetch/nsOfflineCacheUpdate.h b/uriloader/prefetch/nsOfflineCacheUpdate.h index 027a194f540a..b32e11f6317d 100644 --- a/uriloader/prefetch/nsOfflineCacheUpdate.h +++ b/uriloader/prefetch/nsOfflineCacheUpdate.h @@ -32,6 +32,14 @@ #include "nsTHashtable.h" #include "nsHashKeys.h" +namespace mozilla { + +namespace net { +class CookieSettingsArgs; +} + +} // namespace mozilla + class nsOfflineCacheUpdate; class nsOfflineCacheUpdateItem : public nsIStreamListener, @@ -215,6 +223,11 @@ class nsOfflineCacheUpdate final : public nsIOfflineCacheUpdate, virtual nsresult UpdateFinished(nsOfflineCacheUpdate* aUpdate) override; + nsICookieSettings* CookieSettings() const { return mCookieSettings; } + void SetCookieSettings(nsICookieSettings* aCookieSettings); + void SetCookieSettingsArgs( + const mozilla::net::CookieSettingsArgs& aCookieSettingsArgs); + protected: ~nsOfflineCacheUpdate(); @@ -271,6 +284,7 @@ class nsOfflineCacheUpdate final : public nsIOfflineCacheUpdate, nsCOMPtr mDocumentURI; nsCOMPtr mLoadingPrincipal; nsCOMPtr mCustomProfileDir; + nsCOMPtr mCookieSettings; nsCOMPtr mUpdateAvailableObserver;