diff --git a/docshell/base/BrowsingContextWebProgress.cpp b/docshell/base/BrowsingContextWebProgress.cpp index d6ff00af9c67..a95712d1baa8 100644 --- a/docshell/base/BrowsingContextWebProgress.cpp +++ b/docshell/base/BrowsingContextWebProgress.cpp @@ -42,7 +42,14 @@ NS_INTERFACE_MAP_END BrowsingContextWebProgress::BrowsingContextWebProgress( CanonicalBrowsingContext* aBrowsingContext) - : mCurrentBrowsingContext(aBrowsingContext) {} + : mCurrentBrowsingContext(aBrowsingContext) { + if (aBrowsingContext->IsTop()) { + mScopedPrefs = new mozilla::ScopedPrefs(); + } else { + // inherit top scoped prefs from top browsing context + mScopedPrefs = aBrowsingContext->Top()->GetWebProgress()->mScopedPrefs; + } +} BrowsingContextWebProgress::~BrowsingContextWebProgress() = default; @@ -210,6 +217,10 @@ void BrowsingContextWebProgress::DropBounceTrackingState() { mBounceTrackingState = nullptr; } +already_AddRefed BrowsingContextWebProgress::ScopedPrefs() { + return do_AddRef(mScopedPrefs); +} + //////////////////////////////////////////////////////////////////////////////// // nsIWebProgressListener diff --git a/docshell/base/BrowsingContextWebProgress.h b/docshell/base/BrowsingContextWebProgress.h index d0379f0fbfa7..2766efa46bdf 100644 --- a/docshell/base/BrowsingContextWebProgress.h +++ b/docshell/base/BrowsingContextWebProgress.h @@ -5,6 +5,7 @@ #ifndef mozilla_dom_BrowsingContextWebProgress_h #define mozilla_dom_BrowsingContextWebProgress_h +#include "nsIScopedPrefs.h" #include "nsIWebProgress.h" #include "nsIWebProgressListener.h" #include "nsTObserverArray.h" @@ -63,6 +64,7 @@ class BrowsingContextWebProgress final : public nsIWebProgress, void SetLoadType(uint32_t aLoadType) { mLoadType = aLoadType; } already_AddRefed GetBounceTrackingState(); + already_AddRefed ScopedPrefs(); // Drops our reference to BounceTrackingState. This is used when the feature // gets disabled. @@ -102,6 +104,10 @@ class BrowsingContextWebProgress final : public nsIWebProgress, bool mIsLoadingDocument = false; RefPtr mBounceTrackingState; + + // Allow overriding some prefs for the lifetime of a particular tab + // one per TopBrowsingContext + nsCOMPtr mScopedPrefs; }; } // namespace mozilla::dom diff --git a/docshell/base/CanonicalBrowsingContext.cpp b/docshell/base/CanonicalBrowsingContext.cpp index 8fa60394df85..1b5e286d6a49 100644 --- a/docshell/base/CanonicalBrowsingContext.cpp +++ b/docshell/base/CanonicalBrowsingContext.cpp @@ -3620,6 +3620,13 @@ CanonicalBrowsingContext::GetBounceTrackingState() { return mWebProgress->GetBounceTrackingState(); } +already_AddRefed CanonicalBrowsingContext::GetScopedPrefs() { + if (!mWebProgress) { + return nullptr; + } + return mWebProgress->ScopedPrefs(); +} + bool CanonicalBrowsingContext::CanOpenModalPicker() { if (!mozilla::StaticPrefs::browser_disable_pickers_background_tabs()) { return true; diff --git a/docshell/base/CanonicalBrowsingContext.h b/docshell/base/CanonicalBrowsingContext.h index 87d317345c15..5549f8eeec30 100644 --- a/docshell/base/CanonicalBrowsingContext.h +++ b/docshell/base/CanonicalBrowsingContext.h @@ -439,6 +439,7 @@ class CanonicalBrowsingContext final : public BrowsingContext { already_AddRefed GetMostRecentLoadingSessionHistoryEntry(); already_AddRefed GetBounceTrackingState(); + already_AddRefed GetScopedPrefs(); bool CanOpenModalPicker(); diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 44cea1c59be0..8e61d7978418 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -2030,6 +2030,7 @@ addExternalIface('URI', nativeType='nsIURI', headerFile='nsIURI.h', addExternalIface('XULCommandDispatcher', notflattened=True) addExternalIface('nsISHistory', nativeType='nsISHistory', notflattened=True) addExternalIface('nsISHEntry', nativeType='nsISHEntry', notflattened=True) +addExternalIface('nsIScopedPrefs', nativeType='nsIScopedPrefs', notflattened=True) addExternalIface('ReferrerInfo', nativeType='nsIReferrerInfo') addExternalIface('nsIPermissionDelegateHandler', nativeType='nsIPermissionDelegateHandler', diff --git a/dom/chrome-webidl/BrowsingContext.webidl b/dom/chrome-webidl/BrowsingContext.webidl index d80abcf58e0c..72c3b2f21b26 100644 --- a/dom/chrome-webidl/BrowsingContext.webidl +++ b/dom/chrome-webidl/BrowsingContext.webidl @@ -8,6 +8,7 @@ interface nsIDocShell; interface nsIDOMGeoPosition; interface nsISecureBrowserUI; interface nsISHEntry; +interface nsIScopedPrefs; interface nsIPrintSettings; interface nsIWebProgress; @@ -468,6 +469,8 @@ interface CanonicalBrowsingContext : BrowsingContext { readonly attribute nsISHEntry? mostRecentLoadingSessionHistoryEntry; + readonly attribute nsIScopedPrefs? scopedPrefs; + /** * Indicates if the embedder element or an ancestor has hidden * visibility, or no frame. diff --git a/netwerk/url-classifier/UrlClassifierFeatureConsentManagerAnnotation.cpp b/netwerk/url-classifier/UrlClassifierFeatureConsentManagerAnnotation.cpp index d1c8b7807aec..baa0f8982e2d 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureConsentManagerAnnotation.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureConsentManagerAnnotation.cpp @@ -10,6 +10,7 @@ #include "mozilla/Logging.h" #include "mozilla/StaticPrefs_privacy.h" #include "mozilla/StaticPtr.h" +#include "mozilla/ScopedPrefs.h" #include "mozilla/net/UrlClassifierCommon.h" #include "nsIChannel.h" #include "nsIClassifiedChannel.h" @@ -101,9 +102,8 @@ UrlClassifierFeatureConsentManagerAnnotation::MaybeCreate( } // We also don't need to annotate the channel if we are not blocking trackers - if (!StaticPrefs::privacy_trackingprotection_enabled() && - !(NS_UsePrivateBrowsing(aChannel) && - StaticPrefs::privacy_trackingprotection_pbmode_enabled())) { + if (!ScopedPrefs::BoolPrefScoped( + ScopedPrefs::PRIVACY_TRACKINGPROTECTION_ENABLED, aChannel)) { return nullptr; } diff --git a/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp b/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp index 8381b17611f0..def833efc5e8 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp @@ -7,6 +7,7 @@ #include "UrlClassifierFeatureTrackingProtection.h" #include "mozilla/AntiTrackingUtils.h" +#include "mozilla/ScopedPrefs.h" #include "mozilla/net/UrlClassifierCommon.h" #include "ChannelClassifierService.h" #include "nsIChannel.h" @@ -84,19 +85,26 @@ UrlClassifierFeatureTrackingProtection::MaybeCreate(nsIChannel* aChannel) { ("UrlClassifierFeatureTrackingProtection::MaybeCreate - channel %p", aChannel)); +#ifdef ANDROID // TODO(Bug 2005278): keep behavior between platforms consistent nsCOMPtr loadContext; NS_QueryNotificationCallbacks(aChannel, loadContext); if (!loadContext) { // Some channels don't have a loadcontext, check the global tracking // protection preference. - if (!StaticPrefs::privacy_trackingprotection_enabled() && - !(NS_UsePrivateBrowsing(aChannel) && - StaticPrefs::privacy_trackingprotection_pbmode_enabled())) { + if (!ScopedPrefs::BoolPrefScoped( + ScopedPrefs::PRIVACY_TRACKINGPROTECTION_ENABLED, aChannel)) { return nullptr; } } else if (!loadContext->UseTrackingProtection()) { return nullptr; } +#else // !ANDROID + // Always check tracking protection pref on desktop + if (!ScopedPrefs::BoolPrefScoped( + ScopedPrefs::PRIVACY_TRACKINGPROTECTION_ENABLED, aChannel)) { + return nullptr; + } +#endif // ANDROID RefPtr loadInfo = aChannel->LoadInfo(); bool isThirdParty = loadInfo->GetIsThirdPartyContextToTopWindow();