From 66dc23a3e4e8dd017c5179a8cc171cf8a4b2e7d2 Mon Sep 17 00:00:00 2001 From: Tim Huang Date: Mon, 29 Mar 2021 11:01:52 +0000 Subject: [PATCH] Bug 1695050 - Part 5: Update the call-sites of CookieJarSettings::Create() for Necko. r=dimi,necko-reviewers,valentin This patch updates the call-sites of CookieJarSettings::Create() in both LoadInfo.cpp, nsHttpChannel.cpp and CookieCommons.cpp. Differential Revision: https://phabricator.services.mozilla.com/D109048 --- netwerk/base/LoadInfo.cpp | 20 ++++++++++++++------ netwerk/cookie/CookieCommons.cpp | 2 +- netwerk/protocol/http/nsHttpChannel.cpp | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/netwerk/base/LoadInfo.cpp b/netwerk/base/LoadInfo.cpp index 7d38443f6fe9..0ddb68e465a7 100644 --- a/netwerk/base/LoadInfo.cpp +++ b/netwerk/base/LoadInfo.cpp @@ -367,7 +367,9 @@ LoadInfo::LoadInfo(nsPIDOMWindowOuter* aOuterWindow, // Let's take the current cookie behavior and current cookie permission // for the documents' loadInfo. Note that for any other loadInfos, // cookieBehavior will be BEHAVIOR_REJECT for security reasons. - mCookieJarSettings = CookieJarSettings::Create(); + bool isPrivate = mOriginAttributes.mPrivateBrowsingId > 0; + mCookieJarSettings = CookieJarSettings::Create( + isPrivate ? CookieJarSettings::ePrivate : CookieJarSettings::eRegular); } LoadInfo::LoadInfo(dom::CanonicalBrowsingContext* aBrowsingContext, @@ -406,7 +408,9 @@ LoadInfo::LoadInfo(dom::CanonicalBrowsingContext* aBrowsingContext, // Let's take the current cookie behavior and current cookie permission // for the documents' loadInfo. Note that for any other loadInfos, // cookieBehavior will be BEHAVIOR_REJECT for security reasons. - mCookieJarSettings = CookieJarSettings::Create(); + bool isPrivate = mOriginAttributes.mPrivateBrowsingId > 0; + mCookieJarSettings = CookieJarSettings::Create( + isPrivate ? CookieJarSettings::ePrivate : CookieJarSettings::eRegular); } LoadInfo::LoadInfo(dom::WindowGlobalParent* aParentWGP, @@ -973,9 +977,10 @@ LoadInfo::GetCookiePolicy(uint32_t* aResult) { namespace { already_AddRefed CreateCookieJarSettings( - nsContentPolicyType aContentPolicyType) { + nsContentPolicyType aContentPolicyType, bool aIsPrivate) { if (StaticPrefs::network_cookieJarSettings_unblocked_for_testing()) { - return CookieJarSettings::Create(); + return aIsPrivate ? CookieJarSettings::Create(CookieJarSettings::ePrivate) + : CookieJarSettings::Create(CookieJarSettings::eRegular); } // These contentPolictTypes require a real CookieJarSettings because favicon @@ -983,7 +988,8 @@ already_AddRefed CreateCookieJarSettings( // send/receive cookies. if (aContentPolicyType == nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON || aContentPolicyType == nsIContentPolicy::TYPE_SAVEAS_DOWNLOAD) { - return CookieJarSettings::Create(); + return aIsPrivate ? CookieJarSettings::Create(CookieJarSettings::ePrivate) + : CookieJarSettings::Create(CookieJarSettings::eRegular); } return CookieJarSettings::GetBlockingAll(); @@ -994,7 +1000,9 @@ already_AddRefed CreateCookieJarSettings( NS_IMETHODIMP LoadInfo::GetCookieJarSettings(nsICookieJarSettings** aCookieJarSettings) { if (!mCookieJarSettings) { - mCookieJarSettings = CreateCookieJarSettings(mInternalContentPolicyType); + bool isPrivate = mOriginAttributes.mPrivateBrowsingId > 0; + mCookieJarSettings = + CreateCookieJarSettings(mInternalContentPolicyType, isPrivate); } nsCOMPtr cookieJarSettings = mCookieJarSettings; diff --git a/netwerk/cookie/CookieCommons.cpp b/netwerk/cookie/CookieCommons.cpp index 06b206fbdedb..1aef96a0680c 100644 --- a/netwerk/cookie/CookieCommons.cpp +++ b/netwerk/cookie/CookieCommons.cpp @@ -457,7 +457,7 @@ already_AddRefed CookieCommons::GetCookieJarSettings( cookieJarSettings = CookieJarSettings::GetBlockingAll(); } } else { - cookieJarSettings = CookieJarSettings::Create(); + cookieJarSettings = CookieJarSettings::Create(CookieJarSettings::eRegular); } MOZ_ASSERT(cookieJarSettings); diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 054200c8f779..2a7e59665263 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -10057,7 +10057,7 @@ void nsHttpChannel::ReEvaluateReferrerAfterTrackingStatusIsKnown() { Unused << mLoadInfo->GetCookieJarSettings(getter_AddRefs(cjs)); } if (!cjs) { - cjs = net::CookieJarSettings::Create(); + cjs = net::CookieJarSettings::Create(mLoadInfo->GetLoadingPrincipal()); } if (cjs->GetRejectThirdPartyContexts()) { bool isPrivate = mLoadInfo->GetOriginAttributes().mPrivateBrowsingId > 0;