From 3ef1df6038d35835bc542fccbc639b8802f6dad7 Mon Sep 17 00:00:00 2001 From: Dorel Luca Date: Thu, 14 Mar 2019 09:14:15 +0200 Subject: [PATCH] Backed out 5 changesets (bug 1533074) for eslint failure Backed out changeset 36c6a7178a5c (bug 1533074) Backed out changeset 7e6a8fadff5b (bug 1533074) Backed out changeset 2a0494fed543 (bug 1533074) Backed out changeset 38470d2dd98c (bug 1533074) Backed out changeset af4e03d1f5c8 (bug 1533074) --- browser/app/profile/firefox.js | 2 - .../browser_trackingUI_cryptominers.js | 11 +- .../browser_trackingUI_fingerprinters.js | 12 +- dom/script/ScriptLoader.cpp | 2 +- modules/libpref/init/StaticPrefList.h | 22 +-- netwerk/base/SimpleChannelParent.cpp | 3 +- netwerk/base/nsIParentChannel.idl | 7 +- netwerk/cookie/CookieServiceParent.h | 2 +- netwerk/protocol/data/DataChannelParent.cpp | 3 +- netwerk/protocol/file/FileChannelParent.cpp | 3 +- netwerk/protocol/ftp/FTPChannelParent.cpp | 3 +- .../http/HttpBackgroundChannelChild.cpp | 15 +- .../http/HttpBackgroundChannelChild.h | 3 +- .../http/HttpBackgroundChannelParent.cpp | 19 +- .../http/HttpBackgroundChannelParent.h | 5 +- netwerk/protocol/http/HttpBaseChannel.cpp | 93 +++------ netwerk/protocol/http/HttpBaseChannel.h | 14 +- netwerk/protocol/http/HttpChannelChild.cpp | 11 +- netwerk/protocol/http/HttpChannelChild.h | 3 +- netwerk/protocol/http/HttpChannelParent.cpp | 12 +- netwerk/protocol/http/NullHttpChannel.cpp | 19 +- .../protocol/http/PHttpBackgroundChannel.ipdl | 5 +- .../protocol/http/PTrackingDummyChannel.ipdl | 8 +- .../protocol/http/TrackingDummyChannel.cpp | 11 +- netwerk/protocol/http/TrackingDummyChannel.h | 6 +- .../http/TrackingDummyChannelChild.cpp | 6 +- .../protocol/http/TrackingDummyChannelChild.h | 2 +- .../http/TrackingDummyChannelParent.cpp | 2 +- netwerk/protocol/http/nsHttpChannel.cpp | 6 +- netwerk/protocol/http/nsIHttpChannel.idl | 65 +----- .../viewsource/nsViewSourceChannel.cpp | 37 +--- .../AsyncUrlChannelClassifier.cpp | 3 +- .../url-classifier/UrlClassifierCommon.cpp | 186 ------------------ netwerk/url-classifier/UrlClassifierCommon.h | 11 -- .../UrlClassifierFeatureBase.cpp | 60 ++++++ .../url-classifier/UrlClassifierFeatureBase.h | 4 + ...lassifierFeatureCryptominingAnnotation.cpp | 158 --------------- ...lClassifierFeatureCryptominingAnnotation.h | 46 ----- ...lassifierFeatureCryptominingProtection.cpp | 46 +++-- .../UrlClassifierFeatureFactory.cpp | 44 +---- ...ssifierFeatureFingerprintingAnnotation.cpp | 160 --------------- ...lassifierFeatureFingerprintingAnnotation.h | 46 ----- ...ssifierFeatureFingerprintingProtection.cpp | 47 +++-- ...UrlClassifierFeatureTrackingAnnotation.cpp | 111 ++++++++++- ...UrlClassifierFeatureTrackingProtection.cpp | 4 +- netwerk/url-classifier/moz.build | 2 - .../url-classifier/SafeBrowsing.jsm | 23 +-- .../tests/mochitest/features.js | 156 --------------- .../tests/mochitest/mochitest.ini | 3 - .../mochitest/test_annotation_vs_TP.html | 149 ++++++++++++-- .../mochitest/test_cryptomining_annotate.html | 27 --- .../test_fingerprinting_annotate.html | 27 --- .../exthandler/nsExternalProtocolHandler.cpp | 3 +- 53 files changed, 489 insertions(+), 1239 deletions(-) delete mode 100644 netwerk/url-classifier/UrlClassifierFeatureCryptominingAnnotation.cpp delete mode 100644 netwerk/url-classifier/UrlClassifierFeatureCryptominingAnnotation.h delete mode 100644 netwerk/url-classifier/UrlClassifierFeatureFingerprintingAnnotation.cpp delete mode 100644 netwerk/url-classifier/UrlClassifierFeatureFingerprintingAnnotation.h delete mode 100644 toolkit/components/url-classifier/tests/mochitest/features.js delete mode 100644 toolkit/components/url-classifier/tests/mochitest/test_cryptomining_annotate.html delete mode 100644 toolkit/components/url-classifier/tests/mochitest/test_fingerprinting_annotate.html diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 6b9dbb841986..b33372a53f64 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -1247,9 +1247,7 @@ pref("services.sync.prefs.sync.privacy.fuzzyfox.clockgrainus", false); pref("services.sync.prefs.sync.privacy.sanitize.sanitizeOnShutdown", true); pref("services.sync.prefs.sync.privacy.trackingprotection.enabled", true); pref("services.sync.prefs.sync.privacy.trackingprotection.cryptomining.enabled", true); -pref("services.sync.prefs.sync.privacy.trackingprotection.cryptomining.annotate.enabled", true); pref("services.sync.prefs.sync.privacy.trackingprotection.fingerprinting.enabled", true); -pref("services.sync.prefs.sync.privacy.trackingprotection.fingerprinting.annotate.enabled", true); pref("services.sync.prefs.sync.privacy.trackingprotection.pbmode.enabled", true); pref("services.sync.prefs.sync.privacy.resistFingerprinting", true); pref("services.sync.prefs.sync.privacy.reduceTimerPrecision", true); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_cryptominers.js b/browser/base/content/test/trackingUI/browser_trackingUI_cryptominers.js index 9b5db3feccaf..f2b0c9260d99 100644 --- a/browser/base/content/test/trackingUI/browser_trackingUI_cryptominers.js +++ b/browser/base/content/test/trackingUI/browser_trackingUI_cryptominers.js @@ -5,18 +5,15 @@ "use strict"; const TRACKING_PAGE = "http://example.org/browser/browser/base/content/test/trackingUI/trackingPage.html"; -const CM_PROTECTION_PREF = "privacy.trackingprotection.cryptomining.enabled"; -const CM_ANNOTATION_PREF = "privacy.trackingprotection.cryptomining.annotate.enabled"; +const CM_PREF = "privacy.trackingprotection.cryptomining.enabled"; add_task(async function setup() { await SpecialPowers.pushPrefEnv({set: [ [ ContentBlocking.prefIntroCount, ContentBlocking.MAX_INTROS ], [ "urlclassifier.features.cryptomining.blacklistHosts", "cryptomining.example.com" ], - [ "urlclassifier.features.cryptomining.annotate.blacklistHosts", "cryptomining.example.com" ], [ "privacy.trackingprotection.enabled", false ], [ "privacy.trackingprotection.annotate_channels", false ], [ "privacy.trackingprotection.fingerprinting.enabled", false ], - [ "privacy.trackingprotection.fingerprinting.annotate.enabled", false ], ]}); }); @@ -107,8 +104,7 @@ async function testSubview(hasException) { } add_task(async function test() { - Services.prefs.setBoolPref(CM_PROTECTION_PREF, true); - Services.prefs.setBoolPref(CM_ANNOTATION_PREF, true); + Services.prefs.setBoolPref(CM_PREF, true); await testIdentityState(false); await testIdentityState(true); @@ -116,7 +112,6 @@ add_task(async function test() { await testSubview(false); await testSubview(true); - Services.prefs.clearUserPref(CM_PROTECTION_PREF); - Services.prefs.clearUserPref(CM_ANNOTATION_PREF); + Services.prefs.clearUserPref(CM_PREF); }); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_fingerprinters.js b/browser/base/content/test/trackingUI/browser_trackingUI_fingerprinters.js index 11294e3d6f75..9300eb1588f7 100644 --- a/browser/base/content/test/trackingUI/browser_trackingUI_fingerprinters.js +++ b/browser/base/content/test/trackingUI/browser_trackingUI_fingerprinters.js @@ -5,18 +5,15 @@ "use strict"; const TRACKING_PAGE = "http://example.org/browser/browser/base/content/test/trackingUI/trackingPage.html"; -const FP_PROTECTION_PREF = "privacy.trackingprotection.fingerprinting.enabled"; -const FP_ANNOTATION_PREF = "privacy.trackingprotection.fingerprinting.annotate.enabled"; +const FP_PREF = "privacy.trackingprotection.fingerprinting.enabled"; add_task(async function setup() { await SpecialPowers.pushPrefEnv({set: [ [ ContentBlocking.prefIntroCount, ContentBlocking.MAX_INTROS ], [ "urlclassifier.features.fingerprinting.blacklistHosts", "fingerprinting.example.com" ], - [ "urlclassifier.features.fingerprinting.annotate.blacklistHosts", "fingerprinting.example.com" ], [ "privacy.trackingprotection.enabled", false ], [ "privacy.trackingprotection.annotate_channels", false ], [ "privacy.trackingprotection.cryptomining.enabled", false ], - [ "privacy.trackingprotection.cryptomining.annotate.enabled", false ], ]}); }); @@ -107,8 +104,7 @@ async function testSubview(hasException) { } add_task(async function test() { - Services.prefs.setBoolPref(FP_PROTECTION_PREF, true); - Services.prefs.setBoolPref(FP_ANNOTATION_PREF, true); + Services.prefs.setBoolPref(FP_PREF, true); await testIdentityState(false); await testIdentityState(true); @@ -116,6 +112,6 @@ add_task(async function test() { await testSubview(false); await testSubview(true); - Services.prefs.clearUserPref(FP_PROTECTION_PREF); - Services.prefs.clearUserPref(FP_ANNOTATION_PREF); + Services.prefs.clearUserPref(FP_PREF); }); + diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 59d71e33a078..7050b94cc046 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -3340,7 +3340,7 @@ void ScriptLoader::HandleLoadError(ScriptLoadRequest* aRequest, nsresult aResult) { /* * Handle script not loading error because source was an tracking URL (or - * fingerprinting, cryptomining, etc). + * fingerprinting, cryptoming, etc). * We make a note of this script node by including it in a dedicated * array of blocked tracking nodes under its parent document. */ diff --git a/modules/libpref/init/StaticPrefList.h b/modules/libpref/init/StaticPrefList.h index c8ada0fd7a9a..70ff159db107 100644 --- a/modules/libpref/init/StaticPrefList.h +++ b/modules/libpref/init/StaticPrefList.h @@ -2007,32 +2007,22 @@ VARCACHE_PREF( ) // Block 3rd party fingerprinting resources. +# define PREF_VALUE false VARCACHE_PREF( "privacy.trackingprotection.fingerprinting.enabled", privacy_trackingprotection_fingerprinting_enabled, - bool, false -) - -// Annotate fingerprinting resources. -VARCACHE_PREF( - "privacy.trackingprotection.fingerprinting.annotate.enabled", - privacy_trackingprotection_fingerprinting_annotate_enabled, - bool, false + bool, PREF_VALUE ) +#undef PREF_VALUE // Block 3rd party cryptomining resources. +# define PREF_VALUE false VARCACHE_PREF( "privacy.trackingprotection.cryptomining.enabled", privacy_trackingprotection_cryptomining_enabled, - bool, false -) - -// Annotate cryptomining resources. -VARCACHE_PREF( - "privacy.trackingprotection.cryptomining.annotate.enabled", - privacy_trackingprotection_cryptomining_annotate_enabled, - bool, false + bool, PREF_VALUE ) +#undef PREF_VALUE // Lower the priority of network loads for resources on the tracking protection // list. Note that this requires the diff --git a/netwerk/base/SimpleChannelParent.cpp b/netwerk/base/SimpleChannelParent.cpp index 2e66de9b2035..3e43520f0b81 100644 --- a/netwerk/base/SimpleChannelParent.cpp +++ b/netwerk/base/SimpleChannelParent.cpp @@ -48,8 +48,7 @@ SimpleChannelParent::NotifyCookieBlocked(uint32_t aRejectedReason) { } NS_IMETHODIMP -SimpleChannelParent::NotifyClassificationFlags(uint32_t aClassificationFlags, - bool aIsThirdParty) { +SimpleChannelParent::NotifyTrackingResource(bool aIsThirdParty) { // Nothing to do. return NS_OK; } diff --git a/netwerk/base/nsIParentChannel.idl b/netwerk/base/nsIParentChannel.idl index 84c9e2691308..16bbd9bfb4b7 100644 --- a/netwerk/base/nsIParentChannel.idl +++ b/netwerk/base/nsIParentChannel.idl @@ -67,15 +67,12 @@ interface nsIParentChannel : nsIStreamListener /** * Called to notify the HttpChannelChild that the resource being loaded - * has been classified. - * @param aClassificationFlags - * What classifier identifies this channel. + * is on the tracking protection list. * @param aIsThirdParty * Whether or not the resourced is considered first-party * with the URI of the window. */ - [noscript] void notifyClassificationFlags(in uint32_t aClassificationFlags, - in bool aIsThirdParty); + [noscript] void notifyTrackingResource(in bool aIsThirdParty); /** * Called to invoke deletion of the IPC protocol. diff --git a/netwerk/cookie/CookieServiceParent.h b/netwerk/cookie/CookieServiceParent.h index 3129bf96c5e6..3caf82c681c3 100644 --- a/netwerk/cookie/CookieServiceParent.h +++ b/netwerk/cookie/CookieServiceParent.h @@ -54,7 +54,7 @@ class CookieServiceParent : public PCookieServiceParent { mozilla::ipc::IPCResult RecvPrepareCookieList( const URIParams &aHost, const bool &aIsForeign, - const bool &aIsTrackingResource, + const bool &aIsTackingResource, const bool &aFirstPartyStorageAccessGranted, const bool &aIsSafeTopLevelNav, const bool &aIsSameSiteForeign, const OriginAttributes &aAttrs); diff --git a/netwerk/protocol/data/DataChannelParent.cpp b/netwerk/protocol/data/DataChannelParent.cpp index 147d0f271a15..6e75d70bebdb 100644 --- a/netwerk/protocol/data/DataChannelParent.cpp +++ b/netwerk/protocol/data/DataChannelParent.cpp @@ -48,8 +48,7 @@ DataChannelParent::NotifyCookieBlocked(uint32_t aRejectedReason) { } NS_IMETHODIMP -DataChannelParent::NotifyClassificationFlags(uint32_t aClassificationFlags, - bool aIsThirdParty) { +DataChannelParent::NotifyTrackingResource(bool aIsThirdParty) { // Nothing to do. return NS_OK; } diff --git a/netwerk/protocol/file/FileChannelParent.cpp b/netwerk/protocol/file/FileChannelParent.cpp index 7074a8a456cd..630c69a7e175 100644 --- a/netwerk/protocol/file/FileChannelParent.cpp +++ b/netwerk/protocol/file/FileChannelParent.cpp @@ -48,8 +48,7 @@ FileChannelParent::NotifyCookieBlocked(uint32_t aRejectedReason) { } NS_IMETHODIMP -FileChannelParent::NotifyClassificationFlags(uint32_t aClassificationFlags, - bool aIsThirdParty) { +FileChannelParent::NotifyTrackingResource(bool aIsThirdParty) { // Nothing to do. return NS_OK; } diff --git a/netwerk/protocol/ftp/FTPChannelParent.cpp b/netwerk/protocol/ftp/FTPChannelParent.cpp index de54aaf74b1d..640fd08cb793 100644 --- a/netwerk/protocol/ftp/FTPChannelParent.cpp +++ b/netwerk/protocol/ftp/FTPChannelParent.cpp @@ -516,8 +516,7 @@ FTPChannelParent::NotifyCookieBlocked(uint32_t aRejectedReason) { } NS_IMETHODIMP -FTPChannelParent::NotifyClassificationFlags(uint32_t aClassificationFlags, - bool aIsThirdParty) { +FTPChannelParent::NotifyTrackingResource(bool aIsThirdParty) { // One day, this should probably be filled in. return NS_OK; } diff --git a/netwerk/protocol/http/HttpBackgroundChannelChild.cpp b/netwerk/protocol/http/HttpBackgroundChannelChild.cpp index 00b9cd499d2c..54006a43c0fa 100644 --- a/netwerk/protocol/http/HttpBackgroundChannelChild.cpp +++ b/netwerk/protocol/http/HttpBackgroundChannelChild.cpp @@ -344,22 +344,21 @@ IPCResult HttpBackgroundChannelChild::RecvNotifyCookieBlocked( return IPC_OK(); } -IPCResult HttpBackgroundChannelChild::RecvNotifyClassificationFlags( - const uint32_t& aClassificationFlags, const bool& aIsThirdParty) { +IPCResult HttpBackgroundChannelChild::RecvNotifyTrackingResource( + const bool& aIsThirdParty) { LOG( - ("HttpBackgroundChannelChild::RecvNotifyClassificationFlags " - "classificationFlags=%" PRIu32 ", thirdparty=%d [this=%p]\n", - aClassificationFlags, static_cast(aIsThirdParty), this)); + ("HttpBackgroundChannelChild::RecvNotifyTrackingResource thirdparty=%d " + "[this=%p]\n", + static_cast(aIsThirdParty), this)); MOZ_ASSERT(OnSocketThread()); if (NS_WARN_IF(!mChannelChild)) { return IPC_OK(); } - // NotifyClassificationFlags has no order dependency to OnStartRequest. + // NotifyTrackingResource has no order dependency to OnStartRequest. // It this be handled as soon as possible - mChannelChild->ProcessNotifyClassificationFlags(aClassificationFlags, - aIsThirdParty); + mChannelChild->ProcessNotifyTrackingResource(aIsThirdParty); return IPC_OK(); } diff --git a/netwerk/protocol/http/HttpBackgroundChannelChild.h b/netwerk/protocol/http/HttpBackgroundChannelChild.h index c4829b7465eb..f103a2945791 100644 --- a/netwerk/protocol/http/HttpBackgroundChannelChild.h +++ b/netwerk/protocol/http/HttpBackgroundChannelChild.h @@ -71,8 +71,7 @@ class HttpBackgroundChannelChild final : public PHttpBackgroundChannelChild { IPCResult RecvNotifyCookieBlocked(const uint32_t& aRejectedReason); - IPCResult RecvNotifyClassificationFlags(const uint32_t& aClassificationFlags, - const bool& aIsThirdParty); + IPCResult RecvNotifyTrackingResource(const bool& aIsThirdParty); IPCResult RecvNotifyFlashPluginStateChanged( const nsIHttpChannel::FlashPluginState& aState); diff --git a/netwerk/protocol/http/HttpBackgroundChannelParent.cpp b/netwerk/protocol/http/HttpBackgroundChannelParent.cpp index 03451d6a9fd1..77857bf27cb0 100644 --- a/netwerk/protocol/http/HttpBackgroundChannelParent.cpp +++ b/netwerk/protocol/http/HttpBackgroundChannelParent.cpp @@ -405,12 +405,11 @@ bool HttpBackgroundChannelParent::OnNotifyCookieBlocked( return SendNotifyCookieBlocked(aRejectedReason); } -bool HttpBackgroundChannelParent::OnNotifyClassificationFlags( - uint32_t aClassificationFlags, bool aIsThirdParty) { +bool HttpBackgroundChannelParent::OnNotifyTrackingResource(bool aIsThirdParty) { LOG( - ("HttpBackgroundChannelParent::OnNotifyClassificationFlags " - "classificationFlags=%" PRIu32 ", thirdparty=%d [this=%p]\n", - aClassificationFlags, static_cast(aIsThirdParty), this)); + ("HttpBackgroundChannelParent::OnNotifyTrackingResource thirdparty=%d " + "[this=%p]\n", + static_cast(aIsThirdParty), this)); AssertIsInMainProcess(); if (NS_WARN_IF(!mIPCOpened)) { @@ -420,10 +419,10 @@ bool HttpBackgroundChannelParent::OnNotifyClassificationFlags( if (!IsOnBackgroundThread()) { MutexAutoLock lock(mBgThreadMutex); nsresult rv = mBackgroundThread->Dispatch( - NewRunnableMethod( - "net::HttpBackgroundChannelParent::OnNotifyClassificationFlags", - this, &HttpBackgroundChannelParent::OnNotifyClassificationFlags, - aClassificationFlags, aIsThirdParty), + NewRunnableMethod( + "net::HttpBackgroundChannelParent::OnNotifyTrackingResource", this, + &HttpBackgroundChannelParent::OnNotifyTrackingResource, + aIsThirdParty), NS_DISPATCH_NORMAL); MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv)); @@ -431,7 +430,7 @@ bool HttpBackgroundChannelParent::OnNotifyClassificationFlags( return NS_SUCCEEDED(rv); } - return SendNotifyClassificationFlags(aClassificationFlags, aIsThirdParty); + return SendNotifyTrackingResource(aIsThirdParty); } bool HttpBackgroundChannelParent::OnNotifyFlashPluginStateChanged( diff --git a/netwerk/protocol/http/HttpBackgroundChannelParent.h b/netwerk/protocol/http/HttpBackgroundChannelParent.h index d83d7f60c32e..e61d4a20f88c 100644 --- a/netwerk/protocol/http/HttpBackgroundChannelParent.h +++ b/netwerk/protocol/http/HttpBackgroundChannelParent.h @@ -73,9 +73,8 @@ class HttpBackgroundChannelParent final : public PHttpBackgroundChannelParent { // To send NotifyCookieBlocked message over background channel. bool OnNotifyCookieBlocked(uint32_t aRejectedReason); - // To send NotifyClassificationFlags message over background channel. - bool OnNotifyClassificationFlags(uint32_t aClassificationFlags, - bool aIsThirdParty); + // To send NotifyTrackingResource message over background channel. + bool OnNotifyTrackingResource(bool aIsThirdParty); // To send NotifyFlashPluginStateChanged message over background channel. bool OnNotifyFlashPluginStateChanged(nsIHttpChannel::FlashPluginState aState); diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index b6869c1177d9..75a269054e72 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -64,7 +64,6 @@ #include "mozilla/DebugOnly.h" #include "mozilla/Move.h" #include "mozilla/net/PartiallySeekableInputStream.h" -#include "mozilla/net/UrlClassifierCommon.h" #include "mozilla/InputStreamLengthHelper.h" #include "nsIHttpHeaderVisitor.h" #include "nsIMIMEInputStream.h" @@ -169,8 +168,8 @@ HttpBaseChannel::HttpBaseChannel() mReqContentLength(0U), mStatus(NS_OK), mCanceled(false), - mFirstPartyClassificationFlags(0), - mThirdPartyClassificationFlags(0), + mIsFirstPartyTrackingResource(false), + mIsThirdPartyTrackingResource(false), mFlashPluginState(nsIHttpChannel::FlashPluginUnknown), mLoadFlags(LOAD_NORMAL), mCaps(0), @@ -309,17 +308,16 @@ void HttpBaseChannel::ReleaseMainThreadOnlyReferences() { NS_DispatchToMainThread(new ProxyReleaseRunnable(std::move(arrayToRelease))); } -void HttpBaseChannel::AddClassificationFlags(uint32_t aClassificationFlags, - bool aIsThirdParty) { - LOG( - ("HttpBaseChannel::AddClassificationFlags classificationFlags=%d " - "thirdparty=%d %p", - aClassificationFlags, static_cast(aIsThirdParty), this)); +void HttpBaseChannel::SetIsTrackingResource(bool aIsThirdParty) { + LOG(("HttpBaseChannel::SetIsTrackingResource thirdparty=%d %p", + static_cast(aIsThirdParty), this)); if (aIsThirdParty) { - mThirdPartyClassificationFlags |= aClassificationFlags; + MOZ_ASSERT(!mIsFirstPartyTrackingResource); + mIsThirdPartyTrackingResource = true; } else { - mFirstPartyClassificationFlags |= aClassificationFlags; + MOZ_ASSERT(!mIsThirdPartyTrackingResource); + mIsFirstPartyTrackingResource = true; } } @@ -1472,61 +1470,18 @@ NS_IMETHODIMP HttpBaseChannel::SetTopLevelContentWindowId(uint64_t aWindowId) { return NS_OK; } -bool -HttpBaseChannel::IsTrackingResource() const { - MOZ_ASSERT(!mFirstPartyClassificationFlags || - !mThirdPartyClassificationFlags); - return UrlClassifierCommon::IsTrackingClassificationFlag( - mThirdPartyClassificationFlags) || - UrlClassifierCommon::IsTrackingClassificationFlag( - mFirstPartyClassificationFlags); -} - NS_IMETHODIMP HttpBaseChannel::GetIsTrackingResource(bool* aIsTrackingResource) { - *aIsTrackingResource = IsTrackingResource(); + MOZ_ASSERT(!(mIsFirstPartyTrackingResource && mIsThirdPartyTrackingResource)); + *aIsTrackingResource = + mIsThirdPartyTrackingResource || mIsFirstPartyTrackingResource; return NS_OK; } -bool -HttpBaseChannel::IsThirdPartyTrackingResource() const { - MOZ_ASSERT( - !(mFirstPartyClassificationFlags && mThirdPartyClassificationFlags)); - return UrlClassifierCommon::IsTrackingClassificationFlag( - mThirdPartyClassificationFlags); -} - NS_IMETHODIMP HttpBaseChannel::GetIsThirdPartyTrackingResource(bool* aIsTrackingResource) { - *aIsTrackingResource = IsThirdPartyTrackingResource(); - return NS_OK; -} - -NS_IMETHODIMP -HttpBaseChannel::GetClassificationFlags(uint32_t* aFlags) { - MOZ_ASSERT(!mFirstPartyClassificationFlags || - !mThirdPartyClassificationFlags); - if (mThirdPartyClassificationFlags) { - *aFlags = mThirdPartyClassificationFlags; - } else { - *aFlags = mFirstPartyClassificationFlags; - } - return NS_OK; -} - -NS_IMETHODIMP -HttpBaseChannel::GetFirstPartyClassificationFlags(uint32_t* aFlags) { - MOZ_ASSERT( - !(mFirstPartyClassificationFlags && mFirstPartyClassificationFlags)); - *aFlags = mFirstPartyClassificationFlags; - return NS_OK; -} - -NS_IMETHODIMP -HttpBaseChannel::GetThirdPartyClassificationFlags(uint32_t* aFlags) { - MOZ_ASSERT( - !(mFirstPartyClassificationFlags && mThirdPartyClassificationFlags)); - *aFlags = mThirdPartyClassificationFlags; + MOZ_ASSERT(!(mIsFirstPartyTrackingResource && mIsThirdPartyTrackingResource)); + *aIsTrackingResource = mIsThirdPartyTrackingResource; return NS_OK; } @@ -1540,21 +1495,23 @@ HttpBaseChannel::GetFlashPluginState(nsIHttpChannel::FlashPluginState* aState) { NS_IMETHODIMP HttpBaseChannel::OverrideTrackingFlagsForDocumentCookieAccessor( nsIHttpChannel* aDocumentChannel) { - LOG(("HttpBaseChannel::OverrideTrackingFlagsForDocumentCookieAccessor() %p", - this)); + LOG( + ("HttpBaseChannel::OverrideTrackingFlagsForDocumentCookieAccessor() %p " + "mIsFirstPartyTrackingResource=%d mIsThirdPartyTrackingResource=%d", + this, static_cast(mIsFirstPartyTrackingResource), + static_cast(mIsThirdPartyTrackingResource))); // The semantics we'd like to achieve here are that document.cookie // should follow the same rules that the document is subject to with // regards to content blocking. Therefore we need to propagate the // same flags from the document channel to the fake channel here. + if (aDocumentChannel->GetIsThirdPartyTrackingResource()) { + mIsThirdPartyTrackingResource = true; + } else { + mIsFirstPartyTrackingResource = true; + } - mThirdPartyClassificationFlags = - aDocumentChannel->GetThirdPartyClassificationFlags(); - mFirstPartyClassificationFlags = - aDocumentChannel->GetFirstPartyClassificationFlags(); - - MOZ_ASSERT( - !(mFirstPartyClassificationFlags && mThirdPartyClassificationFlags)); + MOZ_ASSERT(!(mIsFirstPartyTrackingResource && mIsThirdPartyTrackingResource)); return NS_OK; } diff --git a/netwerk/protocol/http/HttpBaseChannel.h b/netwerk/protocol/http/HttpBaseChannel.h index b2736fa22868..86ac230cb99c 100644 --- a/netwerk/protocol/http/HttpBaseChannel.h +++ b/netwerk/protocol/http/HttpBaseChannel.h @@ -239,11 +239,6 @@ class HttpBaseChannel : public nsHashPropertyBag, NS_IMETHOD GetIsTrackingResource(bool *aIsTrackingResource) override; NS_IMETHOD GetIsThirdPartyTrackingResource( bool *aIsTrackingResource) override; - NS_IMETHOD GetClassificationFlags(uint32_t *aIsClassificationFlags) override; - NS_IMETHOD GetFirstPartyClassificationFlags( - uint32_t *aIsClassificationFlags) override; - NS_IMETHOD GetThirdPartyClassificationFlags( - uint32_t *aIsClassificationFlags) override; NS_IMETHOD OverrideTrackingFlagsForDocumentCookieAccessor( nsIHttpChannel *aDocumentChannel) override; NS_IMETHOD GetFlashPluginState( @@ -422,7 +417,7 @@ class HttpBaseChannel : public nsHashPropertyBag, // |EnsureUploadStreamIsCloneableComplete| to main thread. virtual void OnCopyComplete(nsresult aStatus); - void AddClassificationFlags(uint32_t aFlags, bool aIsThirdParty); + void SetIsTrackingResource(bool aIsThirdParty); void SetFlashPluginState(nsIHttpChannel::FlashPluginState aState); @@ -538,9 +533,6 @@ class HttpBaseChannel : public nsHashPropertyBag, bool MaybeWaitForUploadStreamLength(nsIStreamListener *aListener, nsISupports *aContext); - bool IsThirdPartyTrackingResource() const; - bool IsTrackingResource() const; - friend class PrivateBrowsingChannel; friend class InterceptFailedOnStop; @@ -670,8 +662,8 @@ class HttpBaseChannel : public nsHashPropertyBag, // Use Release-Acquire ordering to ensure the OMT ODA is ignored while channel // is canceled on main thread. Atomic mCanceled; - Atomic mFirstPartyClassificationFlags; - Atomic mThirdPartyClassificationFlags; + Atomic mIsFirstPartyTrackingResource; + Atomic mIsThirdPartyTrackingResource; Atomic mFlashPluginState; uint32_t mLoadFlags; diff --git a/netwerk/protocol/http/HttpChannelChild.cpp b/netwerk/protocol/http/HttpChannelChild.cpp index d8a273cf2be9..39658096d558 100644 --- a/netwerk/protocol/http/HttpChannelChild.cpp +++ b/netwerk/protocol/http/HttpChannelChild.cpp @@ -1874,15 +1874,14 @@ void HttpChannelChild::ProcessNotifyCookieBlocked(uint32_t aRejectedReason) { NS_DISPATCH_NORMAL); } -void HttpChannelChild::ProcessNotifyClassificationFlags( - uint32_t aClassificationFlags, bool aIsThirdParty) { +void HttpChannelChild::ProcessNotifyTrackingResource(bool aIsThirdParty) { LOG( - ("HttpChannelChild::ProcessNotifyClassificationFlags thirdparty=%d " - "flags=%" PRIu32 " [this=%p]\n", - static_cast(aIsThirdParty), aClassificationFlags, this)); + ("HttpChannelChild::ProcessNotifyTrackingResource thirdparty=%d " + "[this=%p]\n", + static_cast(aIsThirdParty), this)); MOZ_ASSERT(OnSocketThread()); - AddClassificationFlags(aClassificationFlags, aIsThirdParty); + SetIsTrackingResource(aIsThirdParty); } void HttpChannelChild::ProcessNotifyFlashPluginStateChanged( diff --git a/netwerk/protocol/http/HttpChannelChild.h b/netwerk/protocol/http/HttpChannelChild.h index 31bdccecfad7..3a4ae60f068c 100644 --- a/netwerk/protocol/http/HttpChannelChild.h +++ b/netwerk/protocol/http/HttpChannelChild.h @@ -266,8 +266,7 @@ class HttpChannelChild final : public PHttpChannelChild, uint32_t aAcceptedReason); void ProcessNotifyCookieAllowed(); void ProcessNotifyCookieBlocked(uint32_t aRejectedReason); - void ProcessNotifyClassificationFlags(uint32_t aClassificationFlags, - bool aIsThirdParty); + void ProcessNotifyTrackingResource(bool aIsThirdParty); void ProcessNotifyFlashPluginStateChanged( nsIHttpChannel::FlashPluginState aState); void ProcessSetClassifierMatchedInfo(const nsCString& aList, diff --git a/netwerk/protocol/http/HttpChannelParent.cpp b/netwerk/protocol/http/HttpChannelParent.cpp index 835df0aad934..83ce6b210f10 100644 --- a/netwerk/protocol/http/HttpChannelParent.cpp +++ b/netwerk/protocol/http/HttpChannelParent.cpp @@ -1850,16 +1850,12 @@ HttpChannelParent::SetClassifierMatchedInfo(const nsACString& aList, } NS_IMETHODIMP -HttpChannelParent::NotifyClassificationFlags(uint32_t aClassificationFlags, - bool aIsThirdParty) { - LOG( - ("HttpChannelParent::NotifyClassificationFlags " - "classificationFlags=%" PRIu32 ", thirdparty=%d [this=%p]\n", - aClassificationFlags, static_cast(aIsThirdParty), this)); +HttpChannelParent::NotifyTrackingResource(bool aIsThirdParty) { + LOG(("HttpChannelParent::NotifyTrackingResource thirdparty=%d [this=%p]\n", + static_cast(aIsThirdParty), this)); if (!mIPCClosed) { MOZ_ASSERT(mBgParent); - Unused << mBgParent->OnNotifyClassificationFlags(aClassificationFlags, - aIsThirdParty); + Unused << mBgParent->OnNotifyTrackingResource(aIsThirdParty); } return NS_OK; } diff --git a/netwerk/protocol/http/NullHttpChannel.cpp b/netwerk/protocol/http/NullHttpChannel.cpp index 5d5d36c596f7..34fd8581bad9 100644 --- a/netwerk/protocol/http/NullHttpChannel.cpp +++ b/netwerk/protocol/http/NullHttpChannel.cpp @@ -88,16 +88,6 @@ NullHttpChannel::GetIsTrackingResource(bool *aIsTrackingResource) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP -NullHttpChannel::GetIsThirdPartyTrackingResource(bool *aIsTrackingResource) { - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -NullHttpChannel::GetClassificationFlags(uint32_t *aClassificationFlags) { - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP NullHttpChannel::GetFlashPluginState( nsIHttpChannel::FlashPluginState *aResult) { @@ -105,14 +95,7 @@ NullHttpChannel::GetFlashPluginState( } NS_IMETHODIMP -NullHttpChannel::GetFirstPartyClassificationFlags( - uint32_t *aClassificationFlags) { - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -NullHttpChannel::GetThirdPartyClassificationFlags( - uint32_t *aClassificationFlags) { +NullHttpChannel::GetIsThirdPartyTrackingResource(bool *aIsTrackingResource) { return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/netwerk/protocol/http/PHttpBackgroundChannel.ipdl b/netwerk/protocol/http/PHttpBackgroundChannel.ipdl index 67e064b0ec00..30e075e09482 100644 --- a/netwerk/protocol/http/PHttpBackgroundChannel.ipdl +++ b/netwerk/protocol/http/PHttpBackgroundChannel.ipdl @@ -64,8 +64,9 @@ child: // Tell the child that tracking cookies are blocked for this load. async NotifyCookieBlocked(uint32_t aRejectedReason); - // Tell the child that the resource being loaded has been classified. - async NotifyClassificationFlags(uint32_t aClassificationFlags, bool aIsThirdParty); + // Tell the child that the resource being loaded is on the tracking + // protection list. + async NotifyTrackingResource(bool aIsThirdParty); // Tell the child that the current channel's document is not allowed to load // flash content. diff --git a/netwerk/protocol/http/PTrackingDummyChannel.ipdl b/netwerk/protocol/http/PTrackingDummyChannel.ipdl index db37c07dcdd9..3703f5093d99 100644 --- a/netwerk/protocol/http/PTrackingDummyChannel.ipdl +++ b/netwerk/protocol/http/PTrackingDummyChannel.ipdl @@ -11,9 +11,9 @@ namespace mozilla { namespace net { // This protocol provides a mechanism for the "child intercept" mode of -// ServiceWorker operation to work correctly with Classified channels. -// ServiceWorkers should not be allowed for third-party iframes which are -// annotated as tracking origins. +// ServiceWorker operation to work correctly with Tracking Protection +// annotations. ServiceWorkers should not be allowed for third-party iframes +// which are annotated as tracking origins. // // In child intercept mode, the decision to intercept a channel is made in the // child process without consulting the parent process. The decision is based @@ -39,7 +39,7 @@ protocol PTrackingDummyChannel manager PNecko; child: - async __delete__(uint32_t aClassificationFlags); + async __delete__(bool aTrackingResource); }; } // namespace net diff --git a/netwerk/protocol/http/TrackingDummyChannel.cpp b/netwerk/protocol/http/TrackingDummyChannel.cpp index 7856c82c2bd9..26b161bbb8e1 100644 --- a/netwerk/protocol/http/TrackingDummyChannel.cpp +++ b/netwerk/protocol/http/TrackingDummyChannel.cpp @@ -78,7 +78,7 @@ TrackingDummyChannel::TrackingDummyChannel(nsIURI* aURI, nsIURI* aTopWindowURI, nsILoadInfo* aLoadInfo) : mTopWindowURI(aTopWindowURI), mTopWindowURIResult(aTopWindowURIResult), - mClassificationFlags(0) { + mIsTrackingResource(false) { MOZ_ASSERT(XRE_IsParentProcess()); SetOriginalURI(aURI); @@ -94,13 +94,12 @@ TrackingDummyChannel::~TrackingDummyChannel() { mTopWindowURI.forget()); } -uint32_t TrackingDummyChannel::ClassificationFlags() const { - return mClassificationFlags; +bool TrackingDummyChannel::IsTrackingResource() const { + return mIsTrackingResource; } -void TrackingDummyChannel::AddClassificationFlags( - uint32_t aClassificationFlags) { - mClassificationFlags |= aClassificationFlags; +void TrackingDummyChannel::SetIsTrackingResource() { + mIsTrackingResource = true; } //----------------------------------------------------------------------------- diff --git a/netwerk/protocol/http/TrackingDummyChannel.h b/netwerk/protocol/http/TrackingDummyChannel.h index e677a5b94073..7c9b6e99c852 100644 --- a/netwerk/protocol/http/TrackingDummyChannel.h +++ b/netwerk/protocol/http/TrackingDummyChannel.h @@ -66,9 +66,9 @@ class TrackingDummyChannel final : public nsIChannel, TrackingDummyChannel(nsIURI* aURI, nsIURI* aTopWindowURI, nsresult aTopWindowURIResult, nsILoadInfo* aLoadInfo); - uint32_t ClassificationFlags() const; + bool IsTrackingResource() const; - void AddClassificationFlags(uint32_t); + void SetIsTrackingResource(); private: ~TrackingDummyChannel(); @@ -78,7 +78,7 @@ class TrackingDummyChannel final : public nsIChannel, nsCOMPtr mTopWindowURI; nsresult mTopWindowURIResult; - uint32_t mClassificationFlags; + bool mIsTrackingResource; }; NS_DEFINE_STATIC_IID_ACCESSOR(TrackingDummyChannel, TRACKING_DUMMY_CHANNEL_IID) diff --git a/netwerk/protocol/http/TrackingDummyChannelChild.cpp b/netwerk/protocol/http/TrackingDummyChannelChild.cpp index 91fc6dda91fb..0511e6e128de 100644 --- a/netwerk/protocol/http/TrackingDummyChannelChild.cpp +++ b/netwerk/protocol/http/TrackingDummyChannelChild.cpp @@ -68,7 +68,7 @@ void TrackingDummyChannelChild::Initialize( } mozilla::ipc::IPCResult TrackingDummyChannelChild::Recv__delete__( - const uint32_t& aClassificationFlags) { + const bool& aTrackingResource) { MOZ_ASSERT(NS_IsMainThread()); if (!mChannel) { @@ -78,7 +78,9 @@ mozilla::ipc::IPCResult TrackingDummyChannelChild::Recv__delete__( nsCOMPtr channel = std::move(mChannel); RefPtr httpChannel = do_QueryObject(channel); - httpChannel->AddClassificationFlags(aClassificationFlags, mIsThirdParty); + if (aTrackingResource) { + httpChannel->SetIsTrackingResource(mIsThirdParty); + } bool storageGranted = AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( httpChannel, mURI, nullptr); diff --git a/netwerk/protocol/http/TrackingDummyChannelChild.h b/netwerk/protocol/http/TrackingDummyChannelChild.h index 49b1a656cdbd..20f5cd6671ba 100644 --- a/netwerk/protocol/http/TrackingDummyChannelChild.h +++ b/netwerk/protocol/http/TrackingDummyChannelChild.h @@ -34,7 +34,7 @@ class TrackingDummyChannelChild final : public PTrackingDummyChannelChild { const std::function& aCallback); mozilla::ipc::IPCResult Recv__delete__( - const uint32_t& aClassificationFlags) override; + const bool& aTrackingResource) override; nsCOMPtr mChannel; nsCOMPtr mURI; diff --git a/netwerk/protocol/http/TrackingDummyChannelParent.cpp b/netwerk/protocol/http/TrackingDummyChannelParent.cpp index d4d8dedb1feb..82ecc3ac6ce9 100644 --- a/netwerk/protocol/http/TrackingDummyChannelParent.cpp +++ b/netwerk/protocol/http/TrackingDummyChannelParent.cpp @@ -37,7 +37,7 @@ void TrackingDummyChannelParent::Init(nsIURI* aURI, nsIURI* aTopWindowURI, bool willCallback = NS_SUCCEEDED(AsyncUrlChannelClassifier::CheckChannel( channel, [self = std::move(self), channel]() { if (self->mIPCActive) { - Unused << Send__delete__(self, channel->ClassificationFlags()); + Unused << Send__delete__(self, channel->IsTrackingResource()); } })); diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 13970660db69..1afc7f031544 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -650,7 +650,7 @@ nsresult nsHttpChannel::Connect() { return RedirectToInterceptedChannel(); } - bool isTrackingResource = IsThirdPartyTrackingResource(); + bool isTrackingResource = mIsThirdPartyTrackingResource; // is atomic LOG(("nsHttpChannel %p tracking resource=%d, cos=%u", this, isTrackingResource, mClassOfService)); @@ -2350,7 +2350,7 @@ nsresult nsHttpChannel::ProcessResponse() { nsCOMPtr lci = GetLoadContextInfo(this); mozilla::net::Predictor::UpdateCacheability( referrer, mURI, httpStatus, mRequestHead, mResponseHead, lci, - IsThirdPartyTrackingResource()); + mIsThirdPartyTrackingResource); } // Only allow 407 (authentication required) to continue @@ -3908,7 +3908,7 @@ nsresult nsHttpChannel::OpenCacheEntryInternal( extension.Append("TRR"); } - if (IsThirdPartyTrackingResource() && + if (mIsThirdPartyTrackingResource && !AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(this, mURI, nullptr)) { nsCOMPtr topWindowURI; diff --git a/netwerk/protocol/http/nsIHttpChannel.idl b/netwerk/protocol/http/nsIHttpChannel.idl index 69da4a8b90e7..6aadf4458483 100644 --- a/netwerk/protocol/http/nsIHttpChannel.idl +++ b/netwerk/protocol/http/nsIHttpChannel.idl @@ -495,55 +495,10 @@ interface nsIHttpChannel : nsIChannel [must_use] attribute uint64_t topLevelContentWindowId; /** - * Returns the classification flags if the channel has been processed by - * URL-Classifier features and is considered first-party. - */ - [infallible] readonly attribute unsigned long firstPartyClassificationFlags; - - /** - * Returns the classification flags if the channel has been processed by - * URL-Classifier features and is considered third-party with the top - * window URI. - */ - [infallible] readonly attribute unsigned long thirdPartyClassificationFlags; - - /* - * Returns the classification flags if the channel has been processed by - * URL-Classifier features. This value is equal to - * "firstPartyClassificationFlags || thirdPartyClassificationFlags". - * - * Note that top-level channels could be classified as well. - * In order to identify third-party resources specifically, use - * classificationThirdPartyFlags; - */ - [infallible] readonly attribute unsigned long classificationFlags; - - cenum ClassificationFlags : 32 { - /** - * The resource is on the fingerprinting list. This is only available if - * the privacy.trackingprotection.fingerprinting_annotate_enabled pref. - */ - CLASSIFIED_FINGERPRINTING = 0x01, - - /** - * The resource is on the cryptomining list. This is only available if - * the privacy.trackingprotection.cryptomining_annotate_enabled pref is set. - */ - CLASSIFIED_CRYPTOMINING = 0x02, - - /** - * The resource is on the tracking protection list. This is only available - * if the privacy.trackingprotection.annotate_channels pref. - */ - CLASSIFIED_TRACKING = 0x04, - }; - - /** - * Returns true if the channel has loaded a resource that is classified as - * tracker. - * This is a helper attribute which returns the same value of - * (classificationFlags & CLASSIFIED_TRACKING) || - * (classificationFlags & CLASSIFIED_FINGERPRINTING) + * Returns true if the channel has loaded a resource that is on the tracking + * protection list. This is only available if the + * privacy.trackingprotection.annotate_channels pref is set and its value + * should only be relied on after the channel has established a connection. * * Note that top-level channels could be marked as tracking * resource. In order to identify third-party tracking resources @@ -552,13 +507,11 @@ interface nsIHttpChannel : nsIChannel [infallible] readonly attribute boolean isTrackingResource; /** - * Returns the classification flags if the channel has been processed by - * URL-Classifier features and is considered third-party with the top - * window URI. - * - * This is a helper attribute which returns the same value of - * (thirdPartyClassificationFlags & CLASSIFIED_TRACKING) || - * (thirdPartyClassificationFlags & CLASSIFIED_FINGERPRINTING) + * Returns true if the channel has loaded a resource that is on the tracking + * protection list and is considered third-party with the top window URI. + * This is only available if the privacy.trackingprotection.annotate_channels + * pref is set and its value should only be relied on after the channel has + * established a connection. */ [infallible] readonly attribute boolean isThirdPartyTrackingResource; diff --git a/netwerk/protocol/viewsource/nsViewSourceChannel.cpp b/netwerk/protocol/viewsource/nsViewSourceChannel.cpp index 8cb7848d76d9..a1ca0f4837c3 100644 --- a/netwerk/protocol/viewsource/nsViewSourceChannel.cpp +++ b/netwerk/protocol/viewsource/nsViewSourceChannel.cpp @@ -712,6 +712,13 @@ nsViewSourceChannel::GetIsTrackingResource(bool *aIsTrackingResource) { : mHttpChannel->GetIsTrackingResource(aIsTrackingResource); } +NS_IMETHODIMP +nsViewSourceChannel::GetFlashPluginState( + nsIHttpChannel::FlashPluginState *aResult) { + return !mHttpChannel ? NS_ERROR_NULL_POINTER + : mHttpChannel->GetFlashPluginState(aResult); +} + NS_IMETHODIMP nsViewSourceChannel::GetIsThirdPartyTrackingResource( bool *aIsTrackingResource) { @@ -720,36 +727,6 @@ nsViewSourceChannel::GetIsThirdPartyTrackingResource( aIsTrackingResource); } -NS_IMETHODIMP -nsViewSourceChannel::GetClassificationFlags(uint32_t *aClassificationFlags) { - return !mHttpChannel - ? NS_ERROR_NULL_POINTER - : mHttpChannel->GetClassificationFlags(aClassificationFlags); -} - -NS_IMETHODIMP -nsViewSourceChannel::GetFirstPartyClassificationFlags( - uint32_t *aClassificationFlags) { - return !mHttpChannel ? NS_ERROR_NULL_POINTER - : mHttpChannel->GetFirstPartyClassificationFlags( - aClassificationFlags); -} - -NS_IMETHODIMP -nsViewSourceChannel::GetThirdPartyClassificationFlags( - uint32_t *aClassificationFlags) { - return !mHttpChannel ? NS_ERROR_NULL_POINTER - : mHttpChannel->GetThirdPartyClassificationFlags( - aClassificationFlags); -} - -NS_IMETHODIMP -nsViewSourceChannel::GetFlashPluginState( - nsIHttpChannel::FlashPluginState *aResult) { - return !mHttpChannel ? NS_ERROR_NULL_POINTER - : mHttpChannel->GetFlashPluginState(aResult); -} - NS_IMETHODIMP nsViewSourceChannel::OverrideTrackingFlagsForDocumentCookieAccessor( nsIHttpChannel *aDocumentChannel) { diff --git a/netwerk/url-classifier/AsyncUrlChannelClassifier.cpp b/netwerk/url-classifier/AsyncUrlChannelClassifier.cpp index 46518cc23a33..bcd9107378d6 100644 --- a/netwerk/url-classifier/AsyncUrlChannelClassifier.cpp +++ b/netwerk/url-classifier/AsyncUrlChannelClassifier.cpp @@ -416,8 +416,7 @@ bool FeatureData::MaybeCompleteClassification(nsIChannel* aChannel) { return true; } - if (!mBlacklistTables.IsEmpty() && - nsContentUtils::IsURIInList(mBlacklistTables[0]->URI(), skipList)) { + if (nsContentUtils::IsURIInList(mBlacklistTables[0]->URI(), skipList)) { UC_LOG( ("FeatureData::MaybeCompleteClassification[%p] - uri found in skiplist", this)); diff --git a/netwerk/url-classifier/UrlClassifierCommon.cpp b/netwerk/url-classifier/UrlClassifierCommon.cpp index a3dc383dff1c..5cde23c69c01 100644 --- a/netwerk/url-classifier/UrlClassifierCommon.cpp +++ b/netwerk/url-classifier/UrlClassifierCommon.cpp @@ -8,7 +8,6 @@ #include "mozilla/AntiTrackingCommon.h" #include "mozilla/BasePrincipal.h" -#include "mozilla/net/HttpBaseChannel.h" #include "mozilla/net/UrlClassifierFeatureFactory.h" #include "mozilla/StaticPrefs.h" #include "mozIThirdPartyUtil.h" @@ -23,8 +22,6 @@ #include "nsIScriptError.h" #include "nsIWebProgressListener.h" #include "nsNetUtil.h" -#include "nsQueryObject.h" -#include "TrackingDummyChannel.h" namespace mozilla { namespace net { @@ -278,188 +275,5 @@ nsresult UrlClassifierCommon::CreatePairwiseWhiteListURI(nsIChannel* aChannel, return NS_OK; } -namespace { - -void SetClassificationFlagsHelper(nsIChannel* aChannel, - uint32_t aClassificationFlags, - bool aIsThirdParty) { - MOZ_ASSERT(aChannel); - - nsCOMPtr parentChannel; - NS_QueryNotificationCallbacks(aChannel, parentChannel); - if (parentChannel) { - // This channel is a parent-process proxy for a child process - // request. We should notify the child process as well. - parentChannel->NotifyClassificationFlags(aClassificationFlags, - aIsThirdParty); - } - - RefPtr httpChannel = do_QueryObject(aChannel); - if (httpChannel) { - httpChannel->AddClassificationFlags(aClassificationFlags, aIsThirdParty); - } - - RefPtr dummyChannel = do_QueryObject(aChannel); - if (dummyChannel) { - dummyChannel->AddClassificationFlags(aClassificationFlags); - } -} - -void LowerPriorityHelper(nsIChannel* aChannel) { - MOZ_ASSERT(aChannel); - - bool isBlockingResource = false; - - nsCOMPtr cos(do_QueryInterface(aChannel)); - if (cos) { - if (nsContentUtils::IsTailingEnabled()) { - uint32_t cosFlags = 0; - cos->GetClassFlags(&cosFlags); - isBlockingResource = - cosFlags & (nsIClassOfService::UrgentStart | - nsIClassOfService::Leader | nsIClassOfService::Unblocked); - - // Requests not allowed to be tailed are usually those with higher - // prioritization. That overweights being a tracker: don't throttle - // them when not in background. - if (!(cosFlags & nsIClassOfService::TailForbidden)) { - cos->AddClassFlags(nsIClassOfService::Throttleable); - } - } else { - // Yes, we even don't want to evaluate the isBlockingResource when tailing - // is off see bug 1395525. - - cos->AddClassFlags(nsIClassOfService::Throttleable); - } - } - - if (!isBlockingResource) { - nsCOMPtr p = do_QueryInterface(aChannel); - if (p) { - if (UC_LOG_ENABLED()) { - nsCOMPtr uri; - aChannel->GetURI(getter_AddRefs(uri)); - nsAutoCString spec; - uri->GetAsciiSpec(spec); - spec.Truncate( - std::min(spec.Length(), UrlClassifierCommon::sMaxSpecLength)); - UC_LOG(("Setting PRIORITY_LOWEST for channel[%p] (%s)", aChannel, - spec.get())); - } - p->SetPriority(nsISupportsPriority::PRIORITY_LOWEST); - } - } -} - -} // namespace - -// static -void UrlClassifierCommon::AnnotateChannel( - nsIChannel* aChannel, - AntiTrackingCommon::ContentBlockingAllowListPurpose aPurpose, - uint32_t aClassificationFlags, uint32_t aLoadingState) { - MOZ_ASSERT(aChannel); - MOZ_ASSERT(aPurpose == AntiTrackingCommon::eTrackingProtection || - aPurpose == AntiTrackingCommon::eTrackingAnnotations || - aPurpose == AntiTrackingCommon::eFingerprinting || - aPurpose == AntiTrackingCommon::eCryptomining); - - nsCOMPtr chanURI; - nsresult rv = aChannel->GetURI(getter_AddRefs(chanURI)); - if (NS_WARN_IF(NS_FAILED(rv))) { - UC_LOG( - ("UrlClassifierCommon::AnnotateChannel nsIChannel::GetURI(%p) failed", - (void*)aChannel)); - return; - } - - bool isThirdPartyWithTopLevelWinURI = - nsContentUtils::IsThirdPartyWindowOrChannel(nullptr, aChannel, chanURI); - - UC_LOG(("UrlClassifierCommon::AnnotateChannel, annotating channel[%p]", - aChannel)); - - SetClassificationFlagsHelper(aChannel, aClassificationFlags, - isThirdPartyWithTopLevelWinURI); - - if (isThirdPartyWithTopLevelWinURI || IsAllowListed(aChannel, aPurpose)) { - UrlClassifierCommon::NotifyChannelClassifierProtectionDisabled( - aChannel, aLoadingState); - } - - if (isThirdPartyWithTopLevelWinURI && - StaticPrefs::privacy_trackingprotection_lower_network_priority()) { - LowerPriorityHelper(aChannel); - } -} - -// static -bool UrlClassifierCommon::IsAllowListed( - nsIChannel* aChannel, - AntiTrackingCommon::ContentBlockingAllowListPurpose aPurpose) { - MOZ_ASSERT(aPurpose == AntiTrackingCommon::eTrackingProtection || - aPurpose == AntiTrackingCommon::eTrackingAnnotations || - aPurpose == AntiTrackingCommon::eFingerprinting || - aPurpose == AntiTrackingCommon::eCryptomining); - - nsCOMPtr channel = do_QueryInterface(aChannel); - if (!channel) { - UC_LOG(("nsChannelClassifier: Not an HTTP channel")); - return false; - } - - nsCOMPtr topWinURI; - nsresult rv = channel->GetTopWindowURI(getter_AddRefs(topWinURI)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return false; - } - - if (!topWinURI && StaticPrefs::channelclassifier_allowlist_example()) { - UC_LOG(("nsChannelClassifier: Allowlisting test domain")); - nsCOMPtr ios = services::GetIOService(); - if (NS_WARN_IF(!ios)) { - return false; - } - - rv = ios->NewURI(NS_LITERAL_CSTRING("http://allowlisted.example.com"), - nullptr, nullptr, getter_AddRefs(topWinURI)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return false; - } - } - - bool isAllowListed = false; - rv = AntiTrackingCommon::IsOnContentBlockingAllowList( - topWinURI, NS_UsePrivateBrowsing(aChannel), aPurpose, isAllowListed); - if (NS_FAILED(rv)) { // normal for some loads, no need to print a warning - return false; - } - - if (isAllowListed) { - if (UC_LOG_ENABLED()) { - nsCOMPtr chanURI; - nsresult rv = aChannel->GetURI(getter_AddRefs(chanURI)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return isAllowListed; - } - - nsCString chanSpec = chanURI->GetSpecOrDefault(); - chanSpec.Truncate( - std::min(chanSpec.Length(), UrlClassifierCommon::sMaxSpecLength)); - UC_LOG(("nsChannelClassifier: User override on channel[%p] (%s)", - aChannel, chanSpec.get())); - } - } - - return isAllowListed; -} - -// static -bool UrlClassifierCommon::IsTrackingClassificationFlag(uint32_t aFlag) { - return (aFlag & nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING) || - (aFlag & - nsIHttpChannel::ClassificationFlags::CLASSIFIED_FINGERPRINTING); -} - } // namespace net } // namespace mozilla diff --git a/netwerk/url-classifier/UrlClassifierCommon.h b/netwerk/url-classifier/UrlClassifierCommon.h index b505a72ef889..bcd4b3b74883 100644 --- a/netwerk/url-classifier/UrlClassifierCommon.h +++ b/netwerk/url-classifier/UrlClassifierCommon.h @@ -42,17 +42,6 @@ class UrlClassifierCommon final { static nsresult CreatePairwiseWhiteListURI(nsIChannel* aChannel, nsIURI** aURI); - static void AnnotateChannel( - nsIChannel* aChannel, - AntiTrackingCommon::ContentBlockingAllowListPurpose aPurpose, - uint32_t aClassificationFlags, uint32_t aLoadingState); - - static bool IsAllowListed( - nsIChannel* aChannel, - AntiTrackingCommon::ContentBlockingAllowListPurpose aPurpose); - - static bool IsTrackingClassificationFlag(uint32_t aFlag); - private: // aBlockedReason must be one of the nsIWebProgressListener state. static void NotifyChannelBlocked(nsIChannel* aChannel, diff --git a/netwerk/url-classifier/UrlClassifierFeatureBase.cpp b/netwerk/url-classifier/UrlClassifierFeatureBase.cpp index 1d344f92c201..ff8855dc8dcd 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureBase.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureBase.cpp @@ -164,5 +164,65 @@ UrlClassifierFeatureBase::GetSkipHostList(nsACString& aList) { return NS_OK; } +bool UrlClassifierFeatureBase::IsAllowListed( + nsIChannel* aChannel, + AntiTrackingCommon::ContentBlockingAllowListPurpose aPurpose) { + MOZ_ASSERT(aPurpose == AntiTrackingCommon::eTrackingProtection || + aPurpose == AntiTrackingCommon::eTrackingAnnotations || + aPurpose == AntiTrackingCommon::eFingerprinting || + aPurpose == AntiTrackingCommon::eCryptomining); + + nsCOMPtr channel = do_QueryInterface(aChannel); + if (!channel) { + UC_LOG(("nsChannelClassifier: Not an HTTP channel")); + return false; + } + + nsCOMPtr topWinURI; + nsresult rv = channel->GetTopWindowURI(getter_AddRefs(topWinURI)); + if (NS_WARN_IF(NS_FAILED(rv))) { + return false; + } + + if (!topWinURI && StaticPrefs::channelclassifier_allowlist_example()) { + UC_LOG(("nsChannelClassifier: Allowlisting test domain")); + nsCOMPtr ios = services::GetIOService(); + if (NS_WARN_IF(!ios)) { + return false; + } + + rv = ios->NewURI(NS_LITERAL_CSTRING("http://allowlisted.example.com"), + nullptr, nullptr, getter_AddRefs(topWinURI)); + if (NS_WARN_IF(NS_FAILED(rv))) { + return false; + } + } + + bool isAllowListed = false; + rv = AntiTrackingCommon::IsOnContentBlockingAllowList( + topWinURI, NS_UsePrivateBrowsing(aChannel), aPurpose, isAllowListed); + if (NS_FAILED(rv)) { // normal for some loads, no need to print a warning + return false; + } + + if (isAllowListed) { + if (UC_LOG_ENABLED()) { + nsCOMPtr chanURI; + nsresult rv = aChannel->GetURI(getter_AddRefs(chanURI)); + if (NS_WARN_IF(NS_FAILED(rv))) { + return isAllowListed; + } + + nsCString chanSpec = chanURI->GetSpecOrDefault(); + chanSpec.Truncate( + std::min(chanSpec.Length(), UrlClassifierCommon::sMaxSpecLength)); + UC_LOG(("nsChannelClassifier: User override on channel[%p] (%s)", + aChannel, chanSpec.get())); + } + } + + return isAllowListed; +} + } // namespace net } // namespace mozilla diff --git a/netwerk/url-classifier/UrlClassifierFeatureBase.h b/netwerk/url-classifier/UrlClassifierFeatureBase.h index 6262904d58a0..efb90fb15c39 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureBase.h +++ b/netwerk/url-classifier/UrlClassifierFeatureBase.h @@ -58,6 +58,10 @@ class UrlClassifierFeatureBase : public nsIUrlClassifierFeature, void InitializePreferences(); void ShutdownPreferences(); + bool IsAllowListed( + nsIChannel* aChannel, + AntiTrackingCommon::ContentBlockingAllowListPurpose aPurpose); + private: nsCString mName; diff --git a/netwerk/url-classifier/UrlClassifierFeatureCryptominingAnnotation.cpp b/netwerk/url-classifier/UrlClassifierFeatureCryptominingAnnotation.cpp deleted file mode 100644 index beabf8f8553d..000000000000 --- a/netwerk/url-classifier/UrlClassifierFeatureCryptominingAnnotation.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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 "UrlClassifierFeatureCryptominingAnnotation.h" - -#include "mozilla/AntiTrackingCommon.h" -#include "mozilla/net/UrlClassifierCommon.h" -#include "mozilla/StaticPrefs.h" -#include "nsContentUtils.h" -#include "nsNetUtil.h" - -namespace mozilla { -namespace net { - -namespace { - -#define CRYPTOMINING_ANNOTATION_FEATURE_NAME "cryptomining-annotation" - -#define URLCLASSIFIER_CRYPTOMINING_ANNOTATION_BLACKLIST \ - "urlclassifier.features.cryptomining.annotate.blacklistTables" -#define URLCLASSIFIER_CRYPTOMINING_ANNOTATION_BLACKLIST_TEST_ENTRIES \ - "urlclassifier.features.cryptomining.annotate.blacklistHosts" -#define URLCLASSIFIER_CRYPTOMINING_ANNOTATION_WHITELIST \ - "urlclassifier.features.cryptomining.annotate.whitelistTables" -#define URLCLASSIFIER_CRYPTOMINING_ANNOTATION_WHITELIST_TEST_ENTRIES \ - "urlclassifier.features.cryptomining.annotate.whitelistHosts" -#define TABLE_CRYPTOMINING_ANNOTATION_BLACKLIST_PREF \ - "cryptomining-annotate-blacklist-pref" -#define TABLE_CRYPTOMINING_ANNOTATION_WHITELIST_PREF \ - "cryptomining-annotate-whitelist-pref" - -StaticRefPtr - gFeatureCryptominingAnnotation; - -} // namespace - -UrlClassifierFeatureCryptominingAnnotation:: - UrlClassifierFeatureCryptominingAnnotation() - : UrlClassifierFeatureBase( - NS_LITERAL_CSTRING(CRYPTOMINING_ANNOTATION_FEATURE_NAME), - NS_LITERAL_CSTRING(URLCLASSIFIER_CRYPTOMINING_ANNOTATION_BLACKLIST), - NS_LITERAL_CSTRING(URLCLASSIFIER_CRYPTOMINING_ANNOTATION_WHITELIST), - NS_LITERAL_CSTRING( - URLCLASSIFIER_CRYPTOMINING_ANNOTATION_BLACKLIST_TEST_ENTRIES), - NS_LITERAL_CSTRING( - URLCLASSIFIER_CRYPTOMINING_ANNOTATION_WHITELIST_TEST_ENTRIES), - NS_LITERAL_CSTRING(TABLE_CRYPTOMINING_ANNOTATION_BLACKLIST_PREF), - NS_LITERAL_CSTRING(TABLE_CRYPTOMINING_ANNOTATION_WHITELIST_PREF), - EmptyCString()) {} - -/* static */ const char* UrlClassifierFeatureCryptominingAnnotation::Name() { - return CRYPTOMINING_ANNOTATION_FEATURE_NAME; -} - -/* static */ -void UrlClassifierFeatureCryptominingAnnotation::MaybeInitialize() { - UC_LOG(("UrlClassifierFeatureCryptominingAnnotation: MaybeInitialize")); - - if (!gFeatureCryptominingAnnotation) { - gFeatureCryptominingAnnotation = - new UrlClassifierFeatureCryptominingAnnotation(); - gFeatureCryptominingAnnotation->InitializePreferences(); - } -} - -/* static */ -void UrlClassifierFeatureCryptominingAnnotation::MaybeShutdown() { - UC_LOG(("UrlClassifierFeatureCryptominingAnnotation: MaybeShutdown")); - - if (gFeatureCryptominingAnnotation) { - gFeatureCryptominingAnnotation->ShutdownPreferences(); - gFeatureCryptominingAnnotation = nullptr; - } -} - -/* static */ -already_AddRefed -UrlClassifierFeatureCryptominingAnnotation::MaybeCreate(nsIChannel* aChannel) { - MOZ_ASSERT(aChannel); - - UC_LOG( - ("UrlClassifierFeatureCryptominingAnnotation: MaybeCreate for channel %p", - aChannel)); - - if (!StaticPrefs:: - privacy_trackingprotection_cryptomining_annotate_enabled()) { - return nullptr; - } - - if (!UrlClassifierCommon::ShouldEnableClassifier(aChannel)) { - return nullptr; - } - - MaybeInitialize(); - MOZ_ASSERT(gFeatureCryptominingAnnotation); - - RefPtr self = - gFeatureCryptominingAnnotation; - return self.forget(); -} - -/* static */ -already_AddRefed -UrlClassifierFeatureCryptominingAnnotation::GetIfNameMatches( - const nsACString& aName) { - if (!aName.EqualsLiteral(CRYPTOMINING_ANNOTATION_FEATURE_NAME)) { - return nullptr; - } - - MaybeInitialize(); - MOZ_ASSERT(gFeatureCryptominingAnnotation); - - RefPtr self = - gFeatureCryptominingAnnotation; - return self.forget(); -} - -NS_IMETHODIMP -UrlClassifierFeatureCryptominingAnnotation::ProcessChannel( - nsIChannel* aChannel, const nsACString& aList, bool* aShouldContinue) { - NS_ENSURE_ARG_POINTER(aChannel); - NS_ENSURE_ARG_POINTER(aShouldContinue); - - // This is not a blocking feature. - *aShouldContinue = true; - - UC_LOG( - ("UrlClassifierFeatureCryptominingAnnotation::ProcessChannel, annotating " - "channel[%p]", - aChannel)); - - UrlClassifierCommon::AnnotateChannel( - aChannel, AntiTrackingCommon::eCryptomining, - nsIHttpChannel::ClassificationFlags::CLASSIFIED_CRYPTOMINING, - nsIWebProgressListener::STATE_LOADED_CRYPTOMINING_CONTENT); - return NS_OK; -} - -NS_IMETHODIMP -UrlClassifierFeatureCryptominingAnnotation::GetURIByListType( - nsIChannel* aChannel, nsIUrlClassifierFeature::listType aListType, - nsIURI** aURI) { - NS_ENSURE_ARG_POINTER(aChannel); - NS_ENSURE_ARG_POINTER(aURI); - - if (aListType == nsIUrlClassifierFeature::blacklist) { - return aChannel->GetURI(aURI); - } - - MOZ_ASSERT(aListType == nsIUrlClassifierFeature::whitelist); - return UrlClassifierCommon::CreatePairwiseWhiteListURI(aChannel, aURI); -} - -} // namespace net -} // namespace mozilla diff --git a/netwerk/url-classifier/UrlClassifierFeatureCryptominingAnnotation.h b/netwerk/url-classifier/UrlClassifierFeatureCryptominingAnnotation.h deleted file mode 100644 index 3b53d69cbcee..000000000000 --- a/netwerk/url-classifier/UrlClassifierFeatureCryptominingAnnotation.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/. */ - -#ifndef mozilla_net_UrlClassifierFeatureCryptominingAnnotation_h -#define mozilla_net_UrlClassifierFeatureCryptominingAnnotation_h - -#include "UrlClassifierFeatureBase.h" - -class nsIChannel; - -namespace mozilla { -namespace net { - -class UrlClassifierFeatureCryptominingAnnotation final - : public UrlClassifierFeatureBase { - public: - static const char* Name(); - - static void MaybeShutdown(); - - static already_AddRefed - MaybeCreate(nsIChannel* aChannel); - - static already_AddRefed GetIfNameMatches( - const nsACString& aName); - - NS_IMETHOD ProcessChannel(nsIChannel* aChannel, const nsACString& aList, - bool* aShouldContinue) override; - - NS_IMETHOD GetURIByListType(nsIChannel* aChannel, - nsIUrlClassifierFeature::listType aListType, - nsIURI** aURI) override; - - private: - UrlClassifierFeatureCryptominingAnnotation(); - - static void MaybeInitialize(); -}; - -} // namespace net -} // namespace mozilla - -#endif // mozilla_net_UrlClassifierFeatureCryptominingAnnotation_h diff --git a/netwerk/url-classifier/UrlClassifierFeatureCryptominingProtection.cpp b/netwerk/url-classifier/UrlClassifierFeatureCryptominingProtection.cpp index 582c4bf37841..a9ec541c3e25 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureCryptominingProtection.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureCryptominingProtection.cpp @@ -17,7 +17,7 @@ namespace net { namespace { -#define CRYPTOMINING_FEATURE_NAME "cryptomining-protection" +#define CRYPTOMINING_FEATURE_NAME "cryptomining" #define URLCLASSIFIER_CRYPTOMINING_BLACKLIST \ "urlclassifier.features.cryptomining.blacklistTables" @@ -143,30 +143,38 @@ UrlClassifierFeatureCryptominingProtection::ProcessChannel( NS_ENSURE_ARG_POINTER(aChannel); NS_ENSURE_ARG_POINTER(aShouldContinue); - bool isAllowListed = UrlClassifierCommon::IsAllowListed( - aChannel, AntiTrackingCommon::eCryptomining); + bool isAllowListed = + IsAllowListed(aChannel, AntiTrackingCommon::eCryptomining); // This is a blocking feature. *aShouldContinue = isAllowListed; if (isAllowListed) { - return NS_OK; - } - - UrlClassifierCommon::SetBlockedContent(aChannel, NS_ERROR_CRYPTOMINING_URI, - aList, EmptyCString(), EmptyCString()); - - UC_LOG( - ("UrlClassifierFeatureCryptominingProtection::ProcessChannel, " - "cancelling " - "channel[%p]", - aChannel)); - nsCOMPtr httpChannel = do_QueryInterface(aChannel); - - if (httpChannel) { - Unused << httpChannel->CancelByChannelClassifier(NS_ERROR_CRYPTOMINING_URI); + // Even with cryptomining blocking disabled, we still want to show the user + // that there are unblocked cryptominers on the site, so notify the UI that + // we loaded cryptomining content. UI code can treat this notification + // differently depending on whether cryptomining blocking is enabled or + // disabled. + UrlClassifierCommon::NotifyChannelClassifierProtectionDisabled( + aChannel, nsIWebProgressListener::STATE_LOADED_CRYPTOMINING_CONTENT); } else { - Unused << aChannel->Cancel(NS_ERROR_CRYPTOMINING_URI); + UrlClassifierCommon::SetBlockedContent(aChannel, NS_ERROR_CRYPTOMINING_URI, + aList, EmptyCString(), + EmptyCString()); + + UC_LOG( + ("UrlClassifierFeatureCryptominingProtection::ProcessChannel, " + "cancelling " + "channel[%p]", + aChannel)); + nsCOMPtr httpChannel = do_QueryInterface(aChannel); + + if (httpChannel) { + Unused << httpChannel->CancelByChannelClassifier( + NS_ERROR_CRYPTOMINING_URI); + } else { + Unused << aChannel->Cancel(NS_ERROR_CRYPTOMINING_URI); + } } return NS_OK; diff --git a/netwerk/url-classifier/UrlClassifierFeatureFactory.cpp b/netwerk/url-classifier/UrlClassifierFeatureFactory.cpp index f444f970c424..dc3b6667b9aa 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureFactory.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureFactory.cpp @@ -7,9 +7,7 @@ #include "mozilla/net/UrlClassifierFeatureFactory.h" // List of Features -#include "UrlClassifierFeatureCryptominingAnnotation.h" #include "UrlClassifierFeatureCryptominingProtection.h" -#include "UrlClassifierFeatureFingerprintingAnnotation.h" #include "UrlClassifierFeatureFingerprintingProtection.h" #include "UrlClassifierFeatureFlash.h" #include "UrlClassifierFeatureLoginReputation.h" @@ -30,9 +28,7 @@ void UrlClassifierFeatureFactory::Shutdown() { return; } - UrlClassifierFeatureCryptominingAnnotation::MaybeShutdown(); UrlClassifierFeatureCryptominingProtection::MaybeShutdown(); - UrlClassifierFeatureFingerprintingAnnotation::MaybeShutdown(); UrlClassifierFeatureFingerprintingProtection::MaybeShutdown(); UrlClassifierFeatureFlash::MaybeShutdown(); UrlClassifierFeatureLoginReputation::MaybeShutdown(); @@ -73,18 +69,6 @@ void UrlClassifierFeatureFactory::GetFeaturesFromChannel( aFeatures.AppendElement(feature); } - // Cryptomining Annotation - feature = UrlClassifierFeatureCryptominingAnnotation::MaybeCreate(aChannel); - if (feature) { - aFeatures.AppendElement(feature); - } - - // Fingerprinting Annotation - feature = UrlClassifierFeatureFingerprintingAnnotation::MaybeCreate(aChannel); - if (feature) { - aFeatures.AppendElement(feature); - } - // Tracking Annotation feature = UrlClassifierFeatureTrackingAnnotation::MaybeCreate(aChannel); if (feature) { @@ -118,25 +102,12 @@ UrlClassifierFeatureFactory::GetFeatureByName(const nsACString& aName) { nsCOMPtr feature; - // Cryptomining Annotation - feature = UrlClassifierFeatureCryptominingAnnotation::GetIfNameMatches(aName); - if (feature) { - return feature.forget(); - } - // Cryptomining Protection feature = UrlClassifierFeatureCryptominingProtection::GetIfNameMatches(aName); if (feature) { return feature.forget(); } - // Fingerprinting Annotation - feature = - UrlClassifierFeatureFingerprintingAnnotation::GetIfNameMatches(aName); - if (feature) { - return feature.forget(); - } - // Fingerprinting Protection feature = UrlClassifierFeatureFingerprintingProtection::GetIfNameMatches(aName); @@ -183,26 +154,13 @@ void UrlClassifierFeatureFactory::GetFeatureNames(nsTArray& aArray) { return; } - nsAutoCString name; - - // Cryptomining Annotation - name.Assign(UrlClassifierFeatureCryptominingAnnotation::Name()); - if (!name.IsEmpty()) { - aArray.AppendElement(name); - } - // Cryptomining Protection + nsAutoCString name; name.Assign(UrlClassifierFeatureCryptominingProtection::Name()); if (!name.IsEmpty()) { aArray.AppendElement(name); } - // Fingerprinting Annotation - name.Assign(UrlClassifierFeatureFingerprintingAnnotation::Name()); - if (!name.IsEmpty()) { - aArray.AppendElement(name); - } - // Fingerprinting Protection name.Assign(UrlClassifierFeatureFingerprintingProtection::Name()); if (!name.IsEmpty()) { diff --git a/netwerk/url-classifier/UrlClassifierFeatureFingerprintingAnnotation.cpp b/netwerk/url-classifier/UrlClassifierFeatureFingerprintingAnnotation.cpp deleted file mode 100644 index 42c35052f418..000000000000 --- a/netwerk/url-classifier/UrlClassifierFeatureFingerprintingAnnotation.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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 "UrlClassifierFeatureFingerprintingAnnotation.h" - -#include "mozilla/AntiTrackingCommon.h" -#include "mozilla/net/UrlClassifierCommon.h" -#include "mozilla/StaticPrefs.h" -#include "nsContentUtils.h" -#include "nsNetUtil.h" - -namespace mozilla { -namespace net { - -namespace { - -#define FINGERPRINTING_ANNOTATION_FEATURE_NAME "fingerprinting-annotation" - -#define URLCLASSIFIER_FINGERPRINTING_ANNOTATION_BLACKLIST \ - "urlclassifier.features.fingerprinting.annotate.blacklistTables" -#define URLCLASSIFIER_FINGERPRINTING_ANNOTATION_BLACKLIST_TEST_ENTRIES \ - "urlclassifier.features.fingerprinting.annotate.blacklistHosts" -#define URLCLASSIFIER_FINGERPRINTING_ANNOTATION_WHITELIST \ - "urlclassifier.features.fingerprinting.annotate.whitelistTables" -#define URLCLASSIFIER_FINGERPRINTING_ANNOTATION_WHITELIST_TEST_ENTRIES \ - "urlclassifier.features.fingerprinting.annotate.whitelistHosts" -#define TABLE_FINGERPRINTING_ANNOTATION_BLACKLIST_PREF \ - "fingerprinting-annotate-blacklist-pref" -#define TABLE_FINGERPRINTING_ANNOTATION_WHITELIST_PREF \ - "fingerprinting-annotate-whitelist-pref" - -StaticRefPtr - gFeatureFingerprintingAnnotation; - -} // namespace - -UrlClassifierFeatureFingerprintingAnnotation:: - UrlClassifierFeatureFingerprintingAnnotation() - : UrlClassifierFeatureBase( - NS_LITERAL_CSTRING(FINGERPRINTING_ANNOTATION_FEATURE_NAME), - NS_LITERAL_CSTRING(URLCLASSIFIER_FINGERPRINTING_ANNOTATION_BLACKLIST), - NS_LITERAL_CSTRING(URLCLASSIFIER_FINGERPRINTING_ANNOTATION_WHITELIST), - NS_LITERAL_CSTRING( - URLCLASSIFIER_FINGERPRINTING_ANNOTATION_BLACKLIST_TEST_ENTRIES), - NS_LITERAL_CSTRING( - URLCLASSIFIER_FINGERPRINTING_ANNOTATION_WHITELIST_TEST_ENTRIES), - NS_LITERAL_CSTRING(TABLE_FINGERPRINTING_ANNOTATION_BLACKLIST_PREF), - NS_LITERAL_CSTRING(TABLE_FINGERPRINTING_ANNOTATION_WHITELIST_PREF), - EmptyCString()) {} - -/* static */ const char* UrlClassifierFeatureFingerprintingAnnotation::Name() { - return FINGERPRINTING_ANNOTATION_FEATURE_NAME; -} - -/* static */ -void UrlClassifierFeatureFingerprintingAnnotation::MaybeInitialize() { - UC_LOG(("UrlClassifierFeatureFingerprintingAnnotation: MaybeInitialize")); - - if (!gFeatureFingerprintingAnnotation) { - gFeatureFingerprintingAnnotation = - new UrlClassifierFeatureFingerprintingAnnotation(); - gFeatureFingerprintingAnnotation->InitializePreferences(); - } -} - -/* static */ -void UrlClassifierFeatureFingerprintingAnnotation::MaybeShutdown() { - UC_LOG(("UrlClassifierFeatureFingerprintingAnnotation: MaybeShutdown")); - - if (gFeatureFingerprintingAnnotation) { - gFeatureFingerprintingAnnotation->ShutdownPreferences(); - gFeatureFingerprintingAnnotation = nullptr; - } -} - -/* static */ -already_AddRefed -UrlClassifierFeatureFingerprintingAnnotation::MaybeCreate( - nsIChannel* aChannel) { - MOZ_ASSERT(aChannel); - - UC_LOG( - ("UrlClassifierFeatureFingerprintingAnnotation: MaybeCreate for channel " - "%p", - aChannel)); - - if (!StaticPrefs:: - privacy_trackingprotection_fingerprinting_annotate_enabled()) { - return nullptr; - } - - if (!UrlClassifierCommon::ShouldEnableClassifier(aChannel)) { - return nullptr; - } - - MaybeInitialize(); - MOZ_ASSERT(gFeatureFingerprintingAnnotation); - - RefPtr self = - gFeatureFingerprintingAnnotation; - return self.forget(); -} - -/* static */ -already_AddRefed -UrlClassifierFeatureFingerprintingAnnotation::GetIfNameMatches( - const nsACString& aName) { - if (!aName.EqualsLiteral(FINGERPRINTING_ANNOTATION_FEATURE_NAME)) { - return nullptr; - } - - MaybeInitialize(); - MOZ_ASSERT(gFeatureFingerprintingAnnotation); - - RefPtr self = - gFeatureFingerprintingAnnotation; - return self.forget(); -} - -NS_IMETHODIMP -UrlClassifierFeatureFingerprintingAnnotation::ProcessChannel( - nsIChannel* aChannel, const nsACString& aList, bool* aShouldContinue) { - NS_ENSURE_ARG_POINTER(aChannel); - NS_ENSURE_ARG_POINTER(aShouldContinue); - - // This is not a blocking feature. - *aShouldContinue = true; - - UC_LOG( - ("UrlClassifierFeatureFingerprintingAnnotation::ProcessChannel, " - "annotating channel[%p]", - aChannel)); - - UrlClassifierCommon::AnnotateChannel( - aChannel, AntiTrackingCommon::eFingerprinting, - nsIHttpChannel::ClassificationFlags::CLASSIFIED_FINGERPRINTING, - nsIWebProgressListener::STATE_LOADED_FINGERPRINTING_CONTENT); - return NS_OK; -} - -NS_IMETHODIMP -UrlClassifierFeatureFingerprintingAnnotation::GetURIByListType( - nsIChannel* aChannel, nsIUrlClassifierFeature::listType aListType, - nsIURI** aURI) { - NS_ENSURE_ARG_POINTER(aChannel); - NS_ENSURE_ARG_POINTER(aURI); - - if (aListType == nsIUrlClassifierFeature::blacklist) { - return aChannel->GetURI(aURI); - } - - MOZ_ASSERT(aListType == nsIUrlClassifierFeature::whitelist); - return UrlClassifierCommon::CreatePairwiseWhiteListURI(aChannel, aURI); -} - -} // namespace net -} // namespace mozilla diff --git a/netwerk/url-classifier/UrlClassifierFeatureFingerprintingAnnotation.h b/netwerk/url-classifier/UrlClassifierFeatureFingerprintingAnnotation.h deleted file mode 100644 index e34d423f4f87..000000000000 --- a/netwerk/url-classifier/UrlClassifierFeatureFingerprintingAnnotation.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/. */ - -#ifndef mozilla_net_UrlClassifierFeatureFingerprintingAnnotation_h -#define mozilla_net_UrlClassifierFeatureFingerprintingAnnotation_h - -#include "UrlClassifierFeatureBase.h" - -class nsIChannel; - -namespace mozilla { -namespace net { - -class UrlClassifierFeatureFingerprintingAnnotation final - : public UrlClassifierFeatureBase { - public: - static const char* Name(); - - static void MaybeShutdown(); - - static already_AddRefed - MaybeCreate(nsIChannel* aChannel); - - static already_AddRefed GetIfNameMatches( - const nsACString& aName); - - NS_IMETHOD ProcessChannel(nsIChannel* aChannel, const nsACString& aList, - bool* aShouldContinue) override; - - NS_IMETHOD GetURIByListType(nsIChannel* aChannel, - nsIUrlClassifierFeature::listType aListType, - nsIURI** aURI) override; - - private: - UrlClassifierFeatureFingerprintingAnnotation(); - - static void MaybeInitialize(); -}; - -} // namespace net -} // namespace mozilla - -#endif // mozilla_net_UrlClassifierFeatureFingerprintingAnnotation_h diff --git a/netwerk/url-classifier/UrlClassifierFeatureFingerprintingProtection.cpp b/netwerk/url-classifier/UrlClassifierFeatureFingerprintingProtection.cpp index 96064d3b7d22..01788f3b03d4 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureFingerprintingProtection.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureFingerprintingProtection.cpp @@ -17,7 +17,7 @@ namespace net { namespace { -#define FINGERPRINTING_FEATURE_NAME "fingerprinting-protection" +#define FINGERPRINTING_FEATURE_NAME "fingerprinting" #define URLCLASSIFIER_FINGERPRINTING_BLACKLIST \ "urlclassifier.features.fingerprinting.blacklistTables" @@ -147,31 +147,38 @@ UrlClassifierFeatureFingerprintingProtection::ProcessChannel( NS_ENSURE_ARG_POINTER(aChannel); NS_ENSURE_ARG_POINTER(aShouldContinue); - bool isAllowListed = UrlClassifierCommon::IsAllowListed( - aChannel, AntiTrackingCommon::eFingerprinting); + bool isAllowListed = + IsAllowListed(aChannel, AntiTrackingCommon::eFingerprinting); // This is a blocking feature. *aShouldContinue = isAllowListed; if (isAllowListed) { - return NS_OK; - } - - UrlClassifierCommon::SetBlockedContent(aChannel, NS_ERROR_FINGERPRINTING_URI, - aList, EmptyCString(), EmptyCString()); - - UC_LOG( - ("UrlClassifierFeatureFingerprintingProtection::ProcessChannel, " - "cancelling " - "channel[%p]", - aChannel)); - nsCOMPtr httpChannel = do_QueryInterface(aChannel); - - if (httpChannel) { - Unused << httpChannel->CancelByChannelClassifier( - NS_ERROR_FINGERPRINTING_URI); + // Even with fingerprinting blocking disabled, we still want to show the + // user that there are unblocked trackers on the site, so notify the UI that + // we loaded tracking content. UI code can treat this notification + // differently depending on whether fingerprinting blocking is enabled or + // not. + UrlClassifierCommon::NotifyChannelClassifierProtectionDisabled( + aChannel, nsIWebProgressListener::STATE_LOADED_FINGERPRINTING_CONTENT); } else { - Unused << aChannel->Cancel(NS_ERROR_FINGERPRINTING_URI); + UrlClassifierCommon::SetBlockedContent(aChannel, + NS_ERROR_FINGERPRINTING_URI, aList, + EmptyCString(), EmptyCString()); + + UC_LOG( + ("UrlClassifierFeatureFingerprintingProtection::ProcessChannel, " + "cancelling " + "channel[%p]", + aChannel)); + nsCOMPtr httpChannel = do_QueryInterface(aChannel); + + if (httpChannel) { + Unused << httpChannel->CancelByChannelClassifier( + NS_ERROR_FINGERPRINTING_URI); + } else { + Unused << aChannel->Cancel(NS_ERROR_FINGERPRINTING_URI); + } } return NS_OK; diff --git a/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp b/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp index c5b98a09803b..6bb1d49cfeee 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp @@ -8,10 +8,13 @@ #include "mozilla/AntiTrackingCommon.h" #include "mozilla/Logging.h" +#include "mozilla/net/HttpBaseChannel.h" #include "mozilla/StaticPrefs.h" #include "mozilla/StaticPtr.h" #include "mozilla/net/UrlClassifierCommon.h" #include "nsContentUtils.h" +#include "nsQueryObject.h" +#include "TrackingDummyChannel.h" namespace mozilla { namespace net { @@ -35,6 +38,74 @@ namespace { StaticRefPtr gFeatureTrackingAnnotation; +static void SetIsTrackingResourceHelper(nsIChannel* aChannel, + bool aIsThirdParty) { + MOZ_ASSERT(aChannel); + + nsCOMPtr parentChannel; + NS_QueryNotificationCallbacks(aChannel, parentChannel); + if (parentChannel) { + // This channel is a parent-process proxy for a child process + // request. We should notify the child process as well. + parentChannel->NotifyTrackingResource(aIsThirdParty); + } + + RefPtr httpChannel = do_QueryObject(aChannel); + if (httpChannel) { + httpChannel->SetIsTrackingResource(aIsThirdParty); + } + + RefPtr dummyChannel = do_QueryObject(aChannel); + if (dummyChannel) { + dummyChannel->SetIsTrackingResource(); + } +} + +static void LowerPriorityHelper(nsIChannel* aChannel) { + MOZ_ASSERT(aChannel); + + bool isBlockingResource = false; + + nsCOMPtr cos(do_QueryInterface(aChannel)); + if (cos) { + if (nsContentUtils::IsTailingEnabled()) { + uint32_t cosFlags = 0; + cos->GetClassFlags(&cosFlags); + isBlockingResource = + cosFlags & (nsIClassOfService::UrgentStart | + nsIClassOfService::Leader | nsIClassOfService::Unblocked); + + // Requests not allowed to be tailed are usually those with higher + // prioritization. That overweights being a tracker: don't throttle + // them when not in background. + if (!(cosFlags & nsIClassOfService::TailForbidden)) { + cos->AddClassFlags(nsIClassOfService::Throttleable); + } + } else { + // Yes, we even don't want to evaluate the isBlockingResource when tailing + // is off see bug 1395525. + + cos->AddClassFlags(nsIClassOfService::Throttleable); + } + } + + if (!isBlockingResource) { + nsCOMPtr p = do_QueryInterface(aChannel); + if (p) { + if (UC_LOG_ENABLED()) { + nsCOMPtr uri; + aChannel->GetURI(getter_AddRefs(uri)); + nsAutoCString spec; + uri->GetAsciiSpec(spec); + spec.Truncate( + std::min(spec.Length(), UrlClassifierCommon::sMaxSpecLength)); + UC_LOG(("Setting PRIORITY_LOWEST for channel[%p] (%s)", aChannel, + spec.get())); + } + p->SetPriority(nsISupportsPriority::PRIORITY_LOWEST); + } + } +} } // namespace @@ -124,10 +195,42 @@ UrlClassifierFeatureTrackingAnnotation::ProcessChannel(nsIChannel* aChannel, // This is not a blocking feature. *aShouldContinue = true; - UrlClassifierCommon::AnnotateChannel( - aChannel, AntiTrackingCommon::eTrackingAnnotations, - nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING, - nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT); + nsCOMPtr chanURI; + nsresult rv = aChannel->GetURI(getter_AddRefs(chanURI)); + if (NS_WARN_IF(NS_FAILED(rv))) { + UC_LOG( + ("UrlClassifierFeatureTrackingAnnotation::ProcessChannel " + "nsIChannel::GetURI(%p) failed", + (void*)aChannel)); + return NS_OK; + } + + bool isThirdPartyWithTopLevelWinURI = + nsContentUtils::IsThirdPartyWindowOrChannel(nullptr, aChannel, chanURI); + + bool isAllowListed = + IsAllowListed(aChannel, AntiTrackingCommon::eTrackingAnnotations); + + UC_LOG( + ("UrlClassifierFeatureTrackingAnnotation::ProcessChannel, annotating " + "channel[%p]", + aChannel)); + + SetIsTrackingResourceHelper(aChannel, isThirdPartyWithTopLevelWinURI); + + if (isThirdPartyWithTopLevelWinURI || isAllowListed) { + // Even with TP disabled, we still want to show the user that there + // are unblocked trackers on the site, so notify the UI that we loaded + // tracking content. UI code can treat this notification differently + // depending on whether TP is enabled or disabled. + UrlClassifierCommon::NotifyChannelClassifierProtectionDisabled( + aChannel, nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT); + } + + if (isThirdPartyWithTopLevelWinURI && + StaticPrefs::privacy_trackingprotection_lower_network_priority()) { + LowerPriorityHelper(aChannel); + } return NS_OK; } diff --git a/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp b/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp index 31e99649f130..a2d996023bd2 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp @@ -139,8 +139,8 @@ UrlClassifierFeatureTrackingProtection::ProcessChannel(nsIChannel* aChannel, NS_ENSURE_ARG_POINTER(aChannel); NS_ENSURE_ARG_POINTER(aShouldContinue); - bool isAllowListed = UrlClassifierCommon::IsAllowListed( - aChannel, AntiTrackingCommon::eTrackingProtection); + bool isAllowListed = + IsAllowListed(aChannel, AntiTrackingCommon::eTrackingProtection); // This is a blocking feature. *aShouldContinue = isAllowListed; diff --git a/netwerk/url-classifier/moz.build b/netwerk/url-classifier/moz.build index b88cf4163a53..800d525b4f83 100644 --- a/netwerk/url-classifier/moz.build +++ b/netwerk/url-classifier/moz.build @@ -31,11 +31,9 @@ UNIFIED_SOURCES += [ 'nsChannelClassifier.cpp', 'UrlClassifierCommon.cpp', 'UrlClassifierFeatureBase.cpp', - 'UrlClassifierFeatureCryptominingAnnotation.cpp', 'UrlClassifierFeatureCryptominingProtection.cpp', 'UrlClassifierFeatureCustomTables.cpp', 'UrlClassifierFeatureFactory.cpp', - 'UrlClassifierFeatureFingerprintingAnnotation.cpp', 'UrlClassifierFeatureFingerprintingProtection.cpp', 'UrlClassifierFeatureFlash.cpp', 'UrlClassifierFeatureLoginReputation.cpp', diff --git a/toolkit/components/url-classifier/SafeBrowsing.jsm b/toolkit/components/url-classifier/SafeBrowsing.jsm index c971a58b20cf..b89ef77b5f4f 100644 --- a/toolkit/components/url-classifier/SafeBrowsing.jsm +++ b/toolkit/components/url-classifier/SafeBrowsing.jsm @@ -115,17 +115,7 @@ const FEATURES = [ return Services.prefs.getBoolPref("browser.safebrowsing.features.flashBlock.update", this.enabled()); }, }, - { name: "fingerprinting-annotation", - list: ["urlclassifier.features.fingerprinting.annotate.blacklistTables", - "urlclassifier.features.fingerprinting.annotate.whitelistTables"], - enabled() { - return Services.prefs.getBoolPref("privacy.trackingprotection.fingerprinting.annotate.enabled", false); - }, - update() { - return Services.prefs.getBoolPref("browser.safebrowsing.features.fingerprinting.annotate.update", this.enabled()); - }, - }, - { name: "fingerprinting-protection", + { name: "fingerprinting", list: ["urlclassifier.features.fingerprinting.blacklistTables", "urlclassifier.features.fingerprinting.whitelistTables"], enabled() { @@ -135,16 +125,7 @@ const FEATURES = [ return Services.prefs.getBoolPref("browser.safebrowsing.features.fingerprinting.update", this.enabled()); }, }, - { name: "cryptomining-annotation", - list: ["urlclassifier.features.cryptomining.annotate.blacklistTables", - "urlclassifier.features.cryptomining.annotate.whitelistTables"], - enabled() { - return Services.prefs.getBoolPref("privacy.trackingprotection.annotate.cryptomining.enabled", false); - }, - update() { - return Services.prefs.getBoolPref("browser.safebrowsing.features.cryptomining.annotate.update", this.enabled()); - }, - { name: "cryptomining-protection", + { name: "cryptomining", list: ["urlclassifier.features.cryptomining.blacklistTables", "urlclassifier.features.cryptomining.whitelistTables"], enabled() { diff --git a/toolkit/components/url-classifier/tests/mochitest/features.js b/toolkit/components/url-classifier/tests/mochitest/features.js deleted file mode 100644 index 09035eed6d7f..000000000000 --- a/toolkit/components/url-classifier/tests/mochitest/features.js +++ /dev/null @@ -1,156 +0,0 @@ -var tests = [ - // Config is an array with 4 elements: - // - annotation blacklist - // - annotation whitelist - // - tracking blacklist - // - tracking whitelist - - // All disabled. - { config: [ false, false, false, false ], loadExpected: true, annotationExpected: false }, - - // Just whitelisted. - { config: [ false, false, false, true ], loadExpected: true, annotationExpected: false }, - - // Just blacklisted. - { config: [ false, false, true, false ], loadExpected: false, annotationExpected: false }, - - // whitelist + blacklist => whitelist wins - { config: [ false, false, true, true ], loadExpected: true, annotationExpected: false }, - - // just annotated in whitelist. - { config: [ false, true, false, false ], loadExpected: true, annotationExpected: false }, - - // TP and annotation whitelisted. - { config: [ false, true, false, true ], loadExpected: true, annotationExpected: false }, - - // Annotation whitelisted, but TP blacklisted. - { config: [ false, true, true, false ], loadExpected: false, annotationExpected: false }, - - // Annotation whitelisted. TP blacklisted and whitelisted: whitelist wins. - { config: [ false, true, true, true ], loadExpected: true, annotationExpected: false }, - - // Just blacklist annotated. - { config: [ true, false, false, false ], loadExpected: true, annotationExpected: true }, - - // annotated but TP whitelisted. - { config: [ true, false, false, true ], loadExpected: true, annotationExpected: true }, - - // annotated and blacklisted. - { config: [ true, false, true, false ], loadExpected: false, annotationExpected: false }, - - // annotated, TP blacklisted and whitelisted: whitelist wins. - { config: [ true, false, true, true ], loadExpected: true, annotationExpected: true }, - - // annotated in white and blacklist. - { config: [ true, true, false, false ], loadExpected: true, annotationExpected: false }, - - // annotated in white and blacklist. TP Whiteslited - { config: [ true, true, false, true ], loadExpected: true, annotationExpected: false }, - - // everywhere. TP whitelist wins. - { config: [ true, true, true, true ], loadExpected: true, annotationExpected: false }, -]; - -function prefBlacklistValue(value) { - return value ? "example.com" : ""; -} - -function prefWhitelistValue(value) { - return value ? "mochi.test" : ""; -} - -async function runTest(test, expectedFlag, expectedTrackingResource, prefs) { - let config = [ - [ "urlclassifier.trackingAnnotationTable.testEntries", prefBlacklistValue(test.config[0]) ], - [ "urlclassifier.features.fingerprinting.annotate.blacklistHosts", prefBlacklistValue(test.config[0]) ], - [ "urlclassifier.features.cryptomining.annotate.blacklistHosts", prefBlacklistValue(test.config[0]) ], - - [ "urlclassifier.trackingAnnotationWhitelistTable.testEntries", prefWhitelistValue(test.config[1]) ], - [ "urlclassifier.features.fingerprinting.annotate.whitelistHosts", prefWhitelistValue(test.config[1]) ], - [ "urlclassifier.features.cryptomining.annotate.whitelistHosts", prefWhitelistValue(test.config[1]) ], - - [ "urlclassifier.trackingTable.testEntries", prefBlacklistValue(test.config[2]) ], - [ "urlclassifier.features.fingerprinting.blacklistHosts", prefBlacklistValue(test.config[2]) ], - [ "urlclassifier.features.cryptomining.blacklistHosts", prefBlacklistValue(test.config[2]) ], - - [ "urlclassifier.trackingWhitelistTable.testEntries", prefWhitelistValue(test.config[3]) ], - [ "urlclassifier.features.fingerprinting.whitelistHosts", prefWhitelistValue(test.config[3]) ], - [ "urlclassifier.features.cryptomining.whitelistHosts", prefWhitelistValue(test.config[3]) ], - ]; - - info("Testing: " + config.toSource() + "\n"); - - await SpecialPowers.pushPrefEnv({set: config.concat(prefs) }); - - // This promise will be resolved when the chromeScript knows if the channel - // is annotated or not. - let annotationPromise; - if (test.loadExpected) { - info("We want to have annotation information"); - annotationPromise = new Promise(resolve => { - chromeScript.addMessageListener("last-channel-flags", - data => resolve(data), - {once: true}); - }); - } - - // Let's load an image with a random query string, just to avoid network cache. - let result = await new Promise(resolve => { - let image = new Image(); - image.src = "http://example.com/tests/toolkit/components/url-classifier/tests/mochitest/raptor.jpg?" + Math.random(); - image.onload = _ => resolve(true); - image.onerror = _ => resolve(false); - }); - - is(result, test.loadExpected, "The loading happened correctly"); - - if (annotationPromise) { - let data = await annotationPromise; - is(!!data.classificationFlags, test.annotationExpected, "The annotation happened correctly"); - if (test.annotationExpected) { - is(data.classificationFlags, expectedFlag, "Correct flag"); - is(data.isTrackingResource, expectedTrackingResource, "Tracking resource flag matches"); - } - } -} - -var chromeScript; - -function runTests(flag, prefs, trackingResource) { - chromeScript = SpecialPowers.loadChromeScript(_ => { - const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); - - function onExamResp(subject, topic, data) { - let channel = subject.QueryInterface(Ci.nsIHttpChannel); - if (!channel || - !channel.URI.spec.startsWith("http://example.com/tests/toolkit/components/url-classifier/tests/mochitest/raptor.jpg")) { - return; - } - - // eslint-disable-next-line no-undef - sendAsyncMessage("last-channel-flags", { - classificationFlags: channel.classificationFlags, - isTrackingResource: channel.isTrackingResource, - }); - } - - // eslint-disable-next-line no-undef - addMessageListener("done", __ => { - Services.obs.removeObserver(onExamResp, "http-on-examine-response"); - }); - - Services.obs.addObserver(onExamResp, "http-on-examine-response"); - - // eslint-disable-next-line no-undef - sendAsyncMessage("start-test"); - }); - - chromeScript.addMessageListener("start-test", async _ => { - for (let test in tests) { - await runTest(tests[test], flag, trackingResource, prefs); - } - - chromeScript.sendAsyncMessage("done"); - SimpleTest.finish(); - }, {once: true}); -} diff --git a/toolkit/components/url-classifier/tests/mochitest/mochitest.ini b/toolkit/components/url-classifier/tests/mochitest/mochitest.ini index ec63393809ee..29510111a279 100644 --- a/toolkit/components/url-classifier/tests/mochitest/mochitest.ini +++ b/toolkit/components/url-classifier/tests/mochitest/mochitest.ini @@ -32,7 +32,6 @@ support-files = gethashFrame.html seek.webm cache.sjs - features.js [test_classifier.html] skip-if = (os == 'linux' && debug) #Bug 1199778 @@ -47,6 +46,4 @@ skip-if = (verify && debug && (os == 'win' || os == 'mac')) skip-if = verify [test_annotation_vs_TP.html] [test_fingerprinting.html] -[test_fingerprinting_annotate.html] [test_cryptomining.html] -[test_cryptomining_annotate.html] diff --git a/toolkit/components/url-classifier/tests/mochitest/test_annotation_vs_TP.html b/toolkit/components/url-classifier/tests/mochitest/test_annotation_vs_TP.html index ef5e293fd361..cce49500cd63 100644 --- a/toolkit/components/url-classifier/tests/mochitest/test_annotation_vs_TP.html +++ b/toolkit/components/url-classifier/tests/mochitest/test_annotation_vs_TP.html @@ -3,23 +3,150 @@ Test the relationship between annotation vs TP - diff --git a/toolkit/components/url-classifier/tests/mochitest/test_cryptomining_annotate.html b/toolkit/components/url-classifier/tests/mochitest/test_cryptomining_annotate.html deleted file mode 100644 index a37f8c4a5c65..000000000000 --- a/toolkit/components/url-classifier/tests/mochitest/test_cryptomining_annotate.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - Test the relationship between annotation vs blocking - cryptomining - - - - - - - - - diff --git a/toolkit/components/url-classifier/tests/mochitest/test_fingerprinting_annotate.html b/toolkit/components/url-classifier/tests/mochitest/test_fingerprinting_annotate.html deleted file mode 100644 index 39d1c59b9fe5..000000000000 --- a/toolkit/components/url-classifier/tests/mochitest/test_fingerprinting_annotate.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - Test the relationship between annotation vs blocking - fingerprinting - - - - - - - - - diff --git a/uriloader/exthandler/nsExternalProtocolHandler.cpp b/uriloader/exthandler/nsExternalProtocolHandler.cpp index 2030bef1f311..0907fa587516 100644 --- a/uriloader/exthandler/nsExternalProtocolHandler.cpp +++ b/uriloader/exthandler/nsExternalProtocolHandler.cpp @@ -405,8 +405,7 @@ NS_IMETHODIMP nsExtProtocolChannel::SetClassifierMatchedInfo( return NS_OK; } -NS_IMETHODIMP nsExtProtocolChannel::NotifyClassificationFlags( - uint32_t aClassificationFlags, bool aIsThirdParty) { +NS_IMETHODIMP nsExtProtocolChannel::NotifyTrackingResource(bool aIsThirdParty) { // nothing to do return NS_OK; }