From e6d0e7dfda48f1bd65c1cec1f80a1e32a29cfeea Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Sat, 19 Oct 2019 04:30:24 +0000 Subject: [PATCH] Bug 1588899 - P1. Move classification flags related method to nsIClassifiedChannel. r=Ehsan,baku This is where it should have been in the first place. Those attributes belong there. Differential Revision: https://phabricator.services.mozilla.com/D49577 --HG-- extra : moz-landing-system : lando --- .../network-monitor/network-observer.js | 10 +- dom/base/nsContentUtils.cpp | 13 +- dom/chrome-webidl/ChannelWrapper.webidl | 2 +- dom/ipc/RemoteWebProgressRequest.cpp | 29 ++++ dom/script/ScriptLoader.cpp | 6 +- netwerk/base/nsIClassifiedChannel.idl | 129 +++++++++++++++++- netwerk/cookie/CookieServiceChild.cpp | 28 ++-- netwerk/cookie/CookieServiceParent.cpp | 9 +- netwerk/cookie/nsCookieService.cpp | 19 +-- netwerk/ipc/DocumentChannelChild.cpp | 32 +++++ netwerk/protocol/http/HttpBaseChannel.h | 10 +- netwerk/protocol/http/NullHttpChannel.cpp | 27 ---- netwerk/protocol/http/nsHttpChannel.cpp | 2 +- netwerk/protocol/http/nsIHttpChannel.idl | 127 ----------------- .../viewsource/nsViewSourceChannel.cpp | 36 ----- ...est_trackingProtection_annotateChannels.js | 2 +- .../url-classifier/UrlClassifierCommon.cpp | 20 +-- ...lassifierFeatureCryptominingAnnotation.cpp | 5 +- ...ssifierFeatureFingerprintingAnnotation.cpp | 5 +- ...ssifierFeatureSocialTrackingAnnotation.cpp | 9 +- ...UrlClassifierFeatureTrackingAnnotation.cpp | 14 +- .../antitracking/AntiTrackingCommon.cpp | 20 ++- .../test/browser/antitracking_head.js | 2 +- .../test_ext_webRequest_urlclassification.js | 4 +- .../extensions/webrequest/ChannelWrapper.cpp | 15 +- .../tests/mochitest/features.js | 6 +- .../mochitest/test_annotation_vs_TP.html | 2 +- .../mochitest/test_cryptomining_annotate.html | 2 +- .../test_fingerprinting_annotate.html | 2 +- .../test_socialtracking_annotate.html | 2 +- .../tests/unit/test_shouldclassify.js | 4 +- 31 files changed, 315 insertions(+), 278 deletions(-) diff --git a/devtools/server/actors/network-monitor/network-observer.js b/devtools/server/actors/network-monitor/network-observer.js index 46137c583dd3..d6e13d33e83c 100644 --- a/devtools/server/actors/network-monitor/network-observer.js +++ b/devtools/server/actors/network-monitor/network-observer.js @@ -348,13 +348,15 @@ NetworkObserver.prototype = { (topic != "http-on-examine-response" && topic != "http-on-examine-cached-response" && topic != "http-on-failed-opening-request") || - !(subject instanceof Ci.nsIHttpChannel) + !(subject instanceof Ci.nsIHttpChannel) || + !(subject instanceof Ci.nsIClassifiedChannel) ) { return; } const blockedOrFailed = topic === "http-on-failed-opening-request"; + subject.QueryInterface(Ci.nsIClassifiedChannel); const channel = subject.QueryInterface(Ci.nsIHttpChannel); if (!matchRequest(channel, this.filters)) { @@ -559,11 +561,15 @@ NetworkObserver.prototype = { return; } - if (!(channel instanceof Ci.nsIHttpChannel)) { + if ( + !(channel instanceof Ci.nsIHttpChannel) || + !(channel instanceof Ci.nsIClassifiedChannel) + ) { return; } channel = channel.QueryInterface(Ci.nsIHttpChannel); + channel = channel.QueryInterface(Ci.nsIClassifiedChannel); if ( activitySubtype == gActivityDistributor.ACTIVITY_SUBTYPE_REQUEST_HEADER diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 10b163ce26f7..3cee5b2c253c 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -169,6 +169,7 @@ #include "nsIForm.h" #include "nsIFragmentContentSink.h" #include "nsContainerFrame.h" +#include "nsIClassifiedChannel.h" #include "nsIHttpChannelInternal.h" #include "nsIIdleService.h" #include "nsIImageLoadingContent.h" @@ -7993,13 +7994,13 @@ bool nsContentUtils::IsTrackingResourceWindow(nsPIDOMWindowInner* aWindow) { return false; } - nsCOMPtr httpChannel = + nsCOMPtr classifiedChannel = do_QueryInterface(document->GetChannel()); - if (!httpChannel) { + if (!classifiedChannel) { return false; } - return httpChannel->IsTrackingResource(); + return classifiedChannel->IsTrackingResource(); } // static public @@ -8012,13 +8013,13 @@ bool nsContentUtils::IsThirdPartyTrackingResourceWindow( return false; } - nsCOMPtr httpChannel = + nsCOMPtr classifiedChannel = do_QueryInterface(document->GetChannel()); - if (!httpChannel) { + if (!classifiedChannel) { return false; } - return httpChannel->IsThirdPartyTrackingResource(); + return classifiedChannel->IsThirdPartyTrackingResource(); } namespace { diff --git a/dom/chrome-webidl/ChannelWrapper.webidl b/dom/chrome-webidl/ChannelWrapper.webidl index 6097dcc14f84..6739918100cc 100644 --- a/dom/chrome-webidl/ChannelWrapper.webidl +++ b/dom/chrome-webidl/ChannelWrapper.webidl @@ -38,7 +38,7 @@ enum MozContentPolicyType { }; /** - * String versions of CLASSIFIED_* tracking flags from nsHttpChannel.idl + * String versions of CLASSIFIED_* tracking flags from nsIClassifiedChannel.idl */ enum MozUrlClassificationFlags { "fingerprinting", diff --git a/dom/ipc/RemoteWebProgressRequest.cpp b/dom/ipc/RemoteWebProgressRequest.cpp index 49dc0498dbb2..52d2d2e7840a 100644 --- a/dom/ipc/RemoteWebProgressRequest.cpp +++ b/dom/ipc/RemoteWebProgressRequest.cpp @@ -227,5 +227,34 @@ NS_IMETHODIMP RemoteWebProgressRequest::SetLoadFlags(nsLoadFlags aLoadFlags) { return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP +RemoteWebProgressRequest::IsTrackingResource(bool* aIsTrackingResource) { + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +RemoteWebProgressRequest::IsThirdPartyTrackingResource( + bool* aIsTrackingResource) { + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +RemoteWebProgressRequest::GetClassificationFlags( + uint32_t* aClassificationFlags) { + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +RemoteWebProgressRequest::GetFirstPartyClassificationFlags( + uint32_t* aClassificationFlags) { + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +RemoteWebProgressRequest::GetThirdPartyClassificationFlags( + uint32_t* aClassificationFlags) { + return NS_ERROR_NOT_IMPLEMENTED; +} + } // namespace dom } // namespace mozilla diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 3fd29dd0a9f7..5823e5a40dcb 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -43,6 +43,7 @@ #include "nsIPrincipal.h" #include "nsJSPrincipals.h" #include "nsContentPolicyUtils.h" +#include "nsIClassifiedChannel.h" #include "nsIHttpChannel.h" #include "nsIHttpChannelInternal.h" #include "nsIClassOfService.h" @@ -3592,7 +3593,10 @@ nsresult ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest, aRequest->mSourceMapURL = NS_ConvertUTF8toUTF16(sourceMapURL); } - if (httpChannel->IsThirdPartyTrackingResource()) { + nsCOMPtr classifiedChannel = do_QueryInterface(req); + MOZ_ASSERT(classifiedChannel); + if (classifiedChannel && + classifiedChannel->IsThirdPartyTrackingResource()) { aRequest->SetIsTracking(); } } diff --git a/netwerk/base/nsIClassifiedChannel.idl b/netwerk/base/nsIClassifiedChannel.idl index bd51c9d23b4a..b5bb37dcdb2b 100644 --- a/netwerk/base/nsIClassifiedChannel.idl +++ b/netwerk/base/nsIClassifiedChannel.idl @@ -12,7 +12,7 @@ * result information of channel classifier. The information contains, for * example, the name of matched table and the name of matched provider. */ -[scriptable, uuid(70cf6091-a1de-4aa8-8224-058f8964be31)] +[builtinclass, scriptable, uuid(70cf6091-a1de-4aa8-8224-058f8964be31)] interface nsIClassifiedChannel : nsISupports { /** @@ -64,4 +64,131 @@ interface nsIClassifiedChannel : nsISupports * Full hash of URLs that matched */ readonly attribute Array matchedTrackingFullHashes; + + /** + * 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. + */ + CLASSIFIED_FINGERPRINTING = 0x0001, + CLASSIFIED_FINGERPRINTING_CONTENT = 0x0080, + + /** + * The resource is on the cryptomining list. + */ + CLASSIFIED_CRYPTOMINING = 0x0002, + CLASSIFIED_CRYPTOMINING_CONTENT = 0x0100, + + /** + * The following are about tracking annotation and are available only + * if the privacy.trackingprotection.annotate_channels pref. + * CLASSIFIED_TRACKING is set if we are not able to identify the + * type of classification. + */ + CLASSIFIED_TRACKING = 0x0004, + CLASSIFIED_TRACKING_AD = 0x0008, + CLASSIFIED_TRACKING_ANALYTICS = 0x0010, + CLASSIFIED_TRACKING_SOCIAL = 0x0020, + CLASSIFIED_TRACKING_CONTENT = 0x0040, + + /** + * The following are about social tracking. + */ + CLASSIFIED_SOCIALTRACKING = 0x0200, + CLASSIFIED_SOCIALTRACKING_FACEBOOK = 0x0400, + CLASSIFIED_SOCIALTRACKING_LINKEDIN = 0x0800, + CLASSIFIED_SOCIALTRACKING_TWITTER = 0x1000, + + /** + * This is exposed to help to identify tracking classification using the + * basic lists. + */ + CLASSIFIED_ANY_BASIC_TRACKING = CLASSIFIED_TRACKING | + CLASSIFIED_TRACKING_AD | CLASSIFIED_TRACKING_ANALYTICS | + CLASSIFIED_TRACKING_SOCIAL | CLASSIFIED_FINGERPRINTING, + + /** + * This is exposed to help to identify tracking classification using the + * strict lists. + */ + CLASSIFIED_ANY_STRICT_TRACKING = CLASSIFIED_ANY_BASIC_TRACKING | + CLASSIFIED_TRACKING_CONTENT | CLASSIFIED_FINGERPRINTING_CONTENT, + + /** + * This is exposed to help to identify social tracking classification + * flags. + */ + CLASSIFIED_ANY_SOCIAL_TRACKING = CLASSIFIED_SOCIALTRACKING | + CLASSIFIED_SOCIALTRACKING_FACEBOOK | + CLASSIFIED_SOCIALTRACKING_LINKEDIN | CLASSIFIED_SOCIALTRACKING_TWITTER, + }; + + /** + * 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_ANY_BASIC_TRACKING) or + * (classificationFlags & CLASSIFIED_ANY_STRICT_TRACKING) + * + * Note that top-level channels could be marked as tracking + * resource. In order to identify third-party tracking resources + * specifically, use isThirdPartyTrackingResource(). + */ + boolean isTrackingResource(); + +%{ C++ + inline bool IsTrackingResource() + { + bool value = false; + if (NS_SUCCEEDED(IsTrackingResource(&value)) && value) { + return true; + } + return false; + } +%} + + /** + * 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_ANY_BASIC_TRACKING) or + * (thirdPartyClassificationFlags & CLASSIFIED_ANY_STRICT_TRACKING) + */ + boolean isThirdPartyTrackingResource(); + +%{ C++ + inline bool IsThirdPartyTrackingResource() + { + bool value = false; + if (NS_SUCCEEDED(IsThirdPartyTrackingResource(&value)) && value) { + return true; + } + return false; + } +%} }; diff --git a/netwerk/cookie/CookieServiceChild.cpp b/netwerk/cookie/CookieServiceChild.cpp index ee1b2ef05c09..624dbb4cf5ff 100644 --- a/netwerk/cookie/CookieServiceChild.cpp +++ b/netwerk/cookie/CookieServiceChild.cpp @@ -21,6 +21,7 @@ #include "nsNetCID.h" #include "nsNetUtil.h" #include "nsIChannel.h" +#include "nsIClassifiedChannel.h" #include "nsIHttpChannel.h" #include "nsCookiePermission.h" #include "nsIEffectiveTLDService.h" @@ -143,14 +144,15 @@ void CookieServiceChild::TrackCookieLoad(nsIChannel* aChannel) { if (RequireThirdPartyCheck(loadInfo)) { mThirdPartyUtil->IsThirdPartyChannel(aChannel, uri, &isForeign); } - nsCOMPtr httpChannel = do_QueryInterface(aChannel); - if (httpChannel) { - isTrackingResource = httpChannel->IsTrackingResource(); + nsCOMPtr classifiedChannel = + do_QueryInterface(aChannel); + if (classifiedChannel) { + isTrackingResource = classifiedChannel->IsTrackingResource(); // Check first-party storage access even for non-tracking resources, since // we will need the result when computing the access rights for the reject // foreign cookie behavior mode. if (isForeign && AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( - httpChannel, uri, &rejectedReason)) { + aChannel, uri, &rejectedReason)) { firstPartyStorageAccessGranted = true; } @@ -471,14 +473,15 @@ nsresult CookieServiceChild::GetCookieStringInternal( bool isTrackingResource = false; bool firstPartyStorageAccessGranted = false; uint32_t rejectedReason = 0; - nsCOMPtr httpChannel = do_QueryInterface(aChannel); - if (httpChannel) { - isTrackingResource = httpChannel->IsTrackingResource(); + nsCOMPtr classifiedChannel = + do_QueryInterface(aChannel); + if (classifiedChannel) { + isTrackingResource = classifiedChannel->IsTrackingResource(); // Check first-party storage access even for non-tracking resources, since // we will need the result when computing the access rights for the reject // foreign cookie behavior mode. if (isForeign && AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( - httpChannel, aHostURI, &rejectedReason)) { + aChannel, aHostURI, &rejectedReason)) { firstPartyStorageAccessGranted = true; } } @@ -515,14 +518,15 @@ nsresult CookieServiceChild::SetCookieStringInternal( bool isTrackingResource = false; bool firstPartyStorageAccessGranted = false; uint32_t rejectedReason = 0; - nsCOMPtr httpChannel = do_QueryInterface(aChannel); - if (httpChannel) { - isTrackingResource = httpChannel->IsTrackingResource(); + nsCOMPtr classifiedChannel = + do_QueryInterface(aChannel); + if (classifiedChannel) { + isTrackingResource = classifiedChannel->IsTrackingResource(); // Check first-party storage access even for non-tracking resources, since // we will need the result when computing the access rights for the reject // foreign cookie behavior mode. if (isForeign && AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( - httpChannel, aHostURI, &rejectedReason)) { + aChannel, aHostURI, &rejectedReason)) { firstPartyStorageAccessGranted = true; } } diff --git a/netwerk/cookie/CookieServiceParent.cpp b/netwerk/cookie/CookieServiceParent.cpp index 415d5e4246ba..83e196163460 100644 --- a/netwerk/cookie/CookieServiceParent.cpp +++ b/netwerk/cookie/CookieServiceParent.cpp @@ -122,14 +122,15 @@ void CookieServiceParent::TrackCookieLoad(nsIChannel* aChannel) { bool isTrackingResource = false; bool storageAccessGranted = false; uint32_t rejectedReason = 0; - nsCOMPtr httpChannel = do_QueryInterface(aChannel); - if (httpChannel) { - isTrackingResource = httpChannel->IsTrackingResource(); + nsCOMPtr classifiedChannel = + do_QueryInterface(aChannel); + if (classifiedChannel) { + isTrackingResource = classifiedChannel->IsTrackingResource(); // Check first-party storage access even for non-tracking resources, since // we will need the result when computing the access rights for the reject // foreign cookie behavior mode. if (AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( - httpChannel, uri, &rejectedReason)) { + aChannel, uri, &rejectedReason)) { storageAccessGranted = true; } } diff --git a/netwerk/cookie/nsCookieService.cpp b/netwerk/cookie/nsCookieService.cpp index 2334881fee10..439106627155 100644 --- a/netwerk/cookie/nsCookieService.cpp +++ b/netwerk/cookie/nsCookieService.cpp @@ -19,6 +19,7 @@ #include "nsCookieService.h" #include "nsContentUtils.h" +#include "nsIClassifiedChannel.h" #include "nsIServiceManager.h" #include "nsIScriptSecurityManager.h" #include "nsIWebProgressListener.h" @@ -2012,15 +2013,16 @@ nsresult nsCookieService::GetCookieStringCommon(nsIURI* aHostURI, bool isTrackingResource = false; bool firstPartyStorageAccessGranted = false; uint32_t rejectedReason = 0; - nsCOMPtr httpChannel = do_QueryInterface(aChannel); - if (httpChannel) { - isTrackingResource = httpChannel->IsTrackingResource(); + nsCOMPtr classifiedChannel = + do_QueryInterface(aChannel); + if (classifiedChannel) { + isTrackingResource = classifiedChannel->IsTrackingResource(); // Check first-party storage access even for non-tracking resources, since // we will need the result when computing the access rights for the reject // foreign cookie behavior mode. if (AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( - httpChannel, aHostURI, &rejectedReason)) { + aChannel, aHostURI, &rejectedReason)) { firstPartyStorageAccessGranted = true; } } @@ -2134,15 +2136,16 @@ nsresult nsCookieService::SetCookieStringCommon(nsIURI* aHostURI, bool isTrackingResource = false; bool firstPartyStorageAccessGranted = false; uint32_t rejectedReason = 0; - nsCOMPtr httpChannel = do_QueryInterface(aChannel); - if (httpChannel) { - isTrackingResource = httpChannel->IsTrackingResource(); + nsCOMPtr classifiedChannel = + do_QueryInterface(aChannel); + if (classifiedChannel) { + isTrackingResource = classifiedChannel->IsTrackingResource(); // Check first-party storage access even for non-tracking resources, since // we will need the result when computing the access rights for the reject // foreign cookie behavior mode. if (AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( - httpChannel, aHostURI, &rejectedReason)) { + aChannel, aHostURI, &rejectedReason)) { firstPartyStorageAccessGranted = true; } } diff --git a/netwerk/ipc/DocumentChannelChild.cpp b/netwerk/ipc/DocumentChannelChild.cpp index fd59458a448b..4383d5227d56 100644 --- a/netwerk/ipc/DocumentChannelChild.cpp +++ b/netwerk/ipc/DocumentChannelChild.cpp @@ -567,5 +567,37 @@ DocumentChannelChild::Resume() { return NS_OK; } +NS_IMETHODIMP +DocumentChannelChild::IsTrackingResource(bool* aIsTrackingResource) { + // TODO + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +DocumentChannelChild::IsThirdPartyTrackingResource(bool* aIsTrackingResource) { + // TODO + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +DocumentChannelChild::GetClassificationFlags(uint32_t* aClassificationFlags) { + // TODO + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +DocumentChannelChild::GetFirstPartyClassificationFlags( + uint32_t* aClassificationFlags) { + // TODO + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +DocumentChannelChild::GetThirdPartyClassificationFlags( + uint32_t* aClassificationFlags) { + // TODO + return NS_ERROR_NOT_IMPLEMENTED; +} + } // namespace net } // namespace mozilla diff --git a/netwerk/protocol/http/HttpBaseChannel.h b/netwerk/protocol/http/HttpBaseChannel.h index 33dfbff315b0..b76e8367b9fc 100644 --- a/netwerk/protocol/http/HttpBaseChannel.h +++ b/netwerk/protocol/http/HttpBaseChannel.h @@ -234,17 +234,11 @@ class HttpBaseChannel : public nsHashPropertyBag, NS_IMETHOD SetTopLevelContentWindowId(uint64_t aContentWindowId) override; NS_IMETHOD GetTopLevelOuterContentWindowId(uint64_t* aWindowId) override; NS_IMETHOD SetTopLevelOuterContentWindowId(uint64_t aWindowId) override; - NS_IMETHOD IsTrackingResource(bool* aIsTrackingResource) override; - NS_IMETHOD IsThirdPartyTrackingResource(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 GetFlashPluginState( nsIHttpChannel::FlashPluginState* aState) override; - using nsIHttpChannel::IsThirdPartyTrackingResource; + using nsIClassifiedChannel::IsThirdPartyTrackingResource; virtual void SetSource(UniqueProfilerBacktrace aSource) override { mSource = std::move(aSource); diff --git a/netwerk/protocol/http/NullHttpChannel.cpp b/netwerk/protocol/http/NullHttpChannel.cpp index 1127659c45d1..899228fbf948 100644 --- a/netwerk/protocol/http/NullHttpChannel.cpp +++ b/netwerk/protocol/http/NullHttpChannel.cpp @@ -83,39 +83,12 @@ NullHttpChannel::SetTopLevelOuterContentWindowId(uint64_t aWindowId) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP -NullHttpChannel::IsTrackingResource(bool* aIsTrackingResource) { - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -NullHttpChannel::IsThirdPartyTrackingResource(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) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP -NullHttpChannel::GetFirstPartyClassificationFlags( - uint32_t* aClassificationFlags) { - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -NullHttpChannel::GetThirdPartyClassificationFlags( - uint32_t* aClassificationFlags) { - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP NullHttpChannel::GetTransferSize(uint64_t* aTransferSize) { return NS_ERROR_NOT_IMPLEMENTED; diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 2d9a2656a8c5..4239e89318f5 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -1335,7 +1335,7 @@ HttpTrafficCategory nsHttpChannel::CreateTrafficCategory() { uint32_t flags = isThirdParty ? mThirdPartyClassificationFlags : mFirstPartyClassificationFlags; - using CF = nsIHttpChannel::ClassificationFlags; + using CF = nsIClassifiedChannel::ClassificationFlags; using TC = HttpTrafficAnalyzer::TrackingClassification; if (flags & CF::CLASSIFIED_TRACKING_CONTENT) { diff --git a/netwerk/protocol/http/nsIHttpChannel.idl b/netwerk/protocol/http/nsIHttpChannel.idl index 1f6f3359179c..b8dd1e9795d6 100644 --- a/netwerk/protocol/http/nsIHttpChannel.idl +++ b/netwerk/protocol/http/nsIHttpChannel.idl @@ -438,133 +438,6 @@ interface nsIHttpChannel : nsIIdentChannel */ [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. - */ - CLASSIFIED_FINGERPRINTING = 0x0001, - CLASSIFIED_FINGERPRINTING_CONTENT = 0x0080, - - /** - * The resource is on the cryptomining list. - */ - CLASSIFIED_CRYPTOMINING = 0x0002, - CLASSIFIED_CRYPTOMINING_CONTENT = 0x0100, - - /** - * The following are about tracking annotation and are available only - * if the privacy.trackingprotection.annotate_channels pref. - * CLASSIFIED_TRACKING is set if we are not able to identify the - * type of classification. - */ - CLASSIFIED_TRACKING = 0x0004, - CLASSIFIED_TRACKING_AD = 0x0008, - CLASSIFIED_TRACKING_ANALYTICS = 0x0010, - CLASSIFIED_TRACKING_SOCIAL = 0x0020, - CLASSIFIED_TRACKING_CONTENT = 0x0040, - - /** - * The following are about social tracking. - */ - CLASSIFIED_SOCIALTRACKING = 0x0200, - CLASSIFIED_SOCIALTRACKING_FACEBOOK = 0x0400, - CLASSIFIED_SOCIALTRACKING_LINKEDIN = 0x0800, - CLASSIFIED_SOCIALTRACKING_TWITTER = 0x1000, - - /** - * This is exposed to help to identify tracking classification using the - * basic lists. - */ - CLASSIFIED_ANY_BASIC_TRACKING = CLASSIFIED_TRACKING | - CLASSIFIED_TRACKING_AD | CLASSIFIED_TRACKING_ANALYTICS | - CLASSIFIED_TRACKING_SOCIAL | CLASSIFIED_FINGERPRINTING, - - /** - * This is exposed to help to identify tracking classification using the - * strict lists. - */ - CLASSIFIED_ANY_STRICT_TRACKING = CLASSIFIED_ANY_BASIC_TRACKING | - CLASSIFIED_TRACKING_CONTENT | CLASSIFIED_FINGERPRINTING_CONTENT, - - /** - * This is exposed to help to identify social tracking classification - * flags. - */ - CLASSIFIED_ANY_SOCIAL_TRACKING = CLASSIFIED_SOCIALTRACKING | - CLASSIFIED_SOCIALTRACKING_FACEBOOK | - CLASSIFIED_SOCIALTRACKING_LINKEDIN | CLASSIFIED_SOCIALTRACKING_TWITTER, - }; - - /** - * 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_ANY_BASIC_TRACKING) or - * (classificationFlags & CLASSIFIED_ANY_STRICT_TRACKING) - * - * Note that top-level channels could be marked as tracking - * resource. In order to identify third-party tracking resources - * specifically, use isThirdPartyTrackingResource(). - */ - boolean isTrackingResource(); - -%{ C++ - inline bool IsTrackingResource() - { - bool value = false; - if (NS_SUCCEEDED(IsTrackingResource(&value)) && value) { - return true; - } - return false; - } -%} - - /** - * 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_ANY_BASIC_TRACKING) or - * (thirdPartyClassificationFlags & CLASSIFIED_ANY_STRICT_TRACKING) - */ - boolean isThirdPartyTrackingResource(); - -%{ C++ - inline bool IsThirdPartyTrackingResource() - { - bool value = false; - if (NS_SUCCEEDED(IsThirdPartyTrackingResource(&value)) && value) { - return true; - } - return false; - } -%} - /** * Returns the allowing status for flash plugin for this channel. */ diff --git a/netwerk/protocol/viewsource/nsViewSourceChannel.cpp b/netwerk/protocol/viewsource/nsViewSourceChannel.cpp index d62f127c9091..77a5bb0a7337 100644 --- a/netwerk/protocol/viewsource/nsViewSourceChannel.cpp +++ b/netwerk/protocol/viewsource/nsViewSourceChannel.cpp @@ -695,42 +695,6 @@ nsViewSourceChannel::SetTopLevelOuterContentWindowId(uint64_t aWindowId) { : mHttpChannel->SetTopLevelOuterContentWindowId(aWindowId); } -NS_IMETHODIMP -nsViewSourceChannel::IsTrackingResource(bool* aIsTrackingResource) { - return !mHttpChannel ? NS_ERROR_NULL_POINTER - : mHttpChannel->IsTrackingResource(aIsTrackingResource); -} - -NS_IMETHODIMP -nsViewSourceChannel::IsThirdPartyTrackingResource(bool* aIsTrackingResource) { - return !mHttpChannel - ? NS_ERROR_NULL_POINTER - : mHttpChannel->IsThirdPartyTrackingResource(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) { diff --git a/netwerk/test/unit/test_trackingProtection_annotateChannels.js b/netwerk/test/unit/test_trackingProtection_annotateChannels.js index 81e71bfdf267..ebedf520fd02 100644 --- a/netwerk/test/unit/test_trackingProtection_annotateChannels.js +++ b/netwerk/test/unit/test_trackingProtection_annotateChannels.js @@ -36,7 +36,7 @@ function listener(tracking, priority, throttleable, nextTest) { listener.prototype = { onStartRequest(request) { Assert.equal( - request.QueryInterface(Ci.nsIHttpChannel).isTrackingResource(), + request.QueryInterface(Ci.nsIClassifiedChannel).isTrackingResource(), this._tracking, "tracking flag" ); diff --git a/netwerk/url-classifier/UrlClassifierCommon.cpp b/netwerk/url-classifier/UrlClassifierCommon.cpp index ede46f768110..7b85cdcd88bb 100644 --- a/netwerk/url-classifier/UrlClassifierCommon.cpp +++ b/netwerk/url-classifier/UrlClassifierCommon.cpp @@ -538,30 +538,32 @@ bool UrlClassifierCommon::IsAllowListed(nsIChannel* aChannel) { // static bool UrlClassifierCommon::IsTrackingClassificationFlag(uint32_t aFlag) { if (StaticPrefs::privacy_annotate_channels_strict_list_enabled() && - (aFlag & - nsIHttpChannel::ClassificationFlags::CLASSIFIED_ANY_STRICT_TRACKING)) { + (aFlag & nsIClassifiedChannel::ClassificationFlags:: + CLASSIFIED_ANY_STRICT_TRACKING)) { return true; } if (StaticPrefs::privacy_socialtracking_block_cookies_enabled() && - (aFlag & - nsIHttpChannel::ClassificationFlags::CLASSIFIED_ANY_SOCIAL_TRACKING)) { + (aFlag & nsIClassifiedChannel::ClassificationFlags:: + CLASSIFIED_ANY_SOCIAL_TRACKING)) { return true; } - return (aFlag & - nsIHttpChannel::ClassificationFlags::CLASSIFIED_ANY_BASIC_TRACKING); + return ( + aFlag & + nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_ANY_BASIC_TRACKING); } // static bool UrlClassifierCommon::IsCryptominingClassificationFlag(uint32_t aFlag) { - if (aFlag & nsIHttpChannel::ClassificationFlags::CLASSIFIED_CRYPTOMINING) { + if (aFlag & + nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_CRYPTOMINING) { return true; } if (StaticPrefs::privacy_annotate_channels_strict_list_enabled() && - (aFlag & - nsIHttpChannel::ClassificationFlags::CLASSIFIED_CRYPTOMINING_CONTENT)) { + (aFlag & nsIClassifiedChannel::ClassificationFlags:: + CLASSIFIED_CRYPTOMINING_CONTENT)) { return true; } diff --git a/netwerk/url-classifier/UrlClassifierFeatureCryptominingAnnotation.cpp b/netwerk/url-classifier/UrlClassifierFeatureCryptominingAnnotation.cpp index 652b7ce80bad..3d086c96898a 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureCryptominingAnnotation.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureCryptominingAnnotation.cpp @@ -8,6 +8,7 @@ #include "mozilla/AntiTrackingCommon.h" #include "mozilla/net/UrlClassifierCommon.h" +#include "nsIClassifiedChannel.h" #include "nsContentUtils.h" #include "nsNetUtil.h" @@ -133,13 +134,13 @@ UrlClassifierFeatureCryptominingAnnotation::ProcessChannel( static std::vector sClassificationData = { {NS_LITERAL_CSTRING("content-cryptomining-track-"), - nsIHttpChannel::ClassificationFlags:: + nsIClassifiedChannel::ClassificationFlags:: CLASSIFIED_CRYPTOMINING_CONTENT}, }; uint32_t flags = UrlClassifierCommon::TablesToClassificationFlags( aList, sClassificationData, - nsIHttpChannel::ClassificationFlags::CLASSIFIED_CRYPTOMINING); + nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_CRYPTOMINING); UrlClassifierCommon::SetTrackingInfo(aChannel, aList, aHashes); diff --git a/netwerk/url-classifier/UrlClassifierFeatureFingerprintingAnnotation.cpp b/netwerk/url-classifier/UrlClassifierFeatureFingerprintingAnnotation.cpp index f69edb21f2a3..9cc870a32d0e 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureFingerprintingAnnotation.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureFingerprintingAnnotation.cpp @@ -8,6 +8,7 @@ #include "mozilla/AntiTrackingCommon.h" #include "mozilla/net/UrlClassifierCommon.h" +#include "nsIClassifiedChannel.h" #include "nsContentUtils.h" #include "nsNetUtil.h" @@ -135,13 +136,13 @@ UrlClassifierFeatureFingerprintingAnnotation::ProcessChannel( static std::vector sClassificationData = { {NS_LITERAL_CSTRING("content-fingerprinting-track-"), - nsIHttpChannel::ClassificationFlags:: + nsIClassifiedChannel::ClassificationFlags:: CLASSIFIED_FINGERPRINTING_CONTENT}, }; uint32_t flags = UrlClassifierCommon::TablesToClassificationFlags( aList, sClassificationData, - nsIHttpChannel::ClassificationFlags::CLASSIFIED_FINGERPRINTING); + nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_FINGERPRINTING); UrlClassifierCommon::SetTrackingInfo(aChannel, aList, aHashes); diff --git a/netwerk/url-classifier/UrlClassifierFeatureSocialTrackingAnnotation.cpp b/netwerk/url-classifier/UrlClassifierFeatureSocialTrackingAnnotation.cpp index 6d70aa13a85f..1a2a3bce5346 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureSocialTrackingAnnotation.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureSocialTrackingAnnotation.cpp @@ -8,6 +8,7 @@ #include "mozilla/AntiTrackingCommon.h" #include "mozilla/net/UrlClassifierCommon.h" +#include "nsIClassifiedChannel.h" #include "nsContentUtils.h" #include "nsNetUtil.h" @@ -135,19 +136,19 @@ UrlClassifierFeatureSocialTrackingAnnotation::ProcessChannel( static std::vector sClassificationData = { {NS_LITERAL_CSTRING("social-tracking-protection-facebook-"), - nsIHttpChannel::ClassificationFlags:: + nsIClassifiedChannel::ClassificationFlags:: CLASSIFIED_SOCIALTRACKING_FACEBOOK}, {NS_LITERAL_CSTRING("social-tracking-protection-linkedin-"), - nsIHttpChannel::ClassificationFlags:: + nsIClassifiedChannel::ClassificationFlags:: CLASSIFIED_SOCIALTRACKING_LINKEDIN}, {NS_LITERAL_CSTRING("social-tracking-protection-twitter-"), - nsIHttpChannel::ClassificationFlags:: + nsIClassifiedChannel::ClassificationFlags:: CLASSIFIED_SOCIALTRACKING_TWITTER}, }; uint32_t flags = UrlClassifierCommon::TablesToClassificationFlags( aList, sClassificationData, - nsIHttpChannel::ClassificationFlags::CLASSIFIED_SOCIALTRACKING); + nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_SOCIALTRACKING); UrlClassifierCommon::AnnotateChannel( aChannel, flags, diff --git a/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp b/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp index e8257f802d42..57537b53ea45 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp @@ -12,6 +12,7 @@ #include "mozilla/StaticPrefs_privacy.h" #include "mozilla/StaticPtr.h" #include "mozilla/net/UrlClassifierCommon.h" +#include "nsIClassifiedChannel.h" #include "nsContentUtils.h" namespace mozilla { @@ -127,18 +128,21 @@ UrlClassifierFeatureTrackingAnnotation::ProcessChannel( static std::vector sClassificationData = { {NS_LITERAL_CSTRING("ads-track-"), - nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING_AD}, + nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_TRACKING_AD}, {NS_LITERAL_CSTRING("analytics-track-"), - nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING_ANALYTICS}, + nsIClassifiedChannel::ClassificationFlags:: + CLASSIFIED_TRACKING_ANALYTICS}, {NS_LITERAL_CSTRING("social-track-"), - nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING_SOCIAL}, + nsIClassifiedChannel::ClassificationFlags:: + CLASSIFIED_TRACKING_SOCIAL}, {NS_LITERAL_CSTRING("content-track-"), - nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING_CONTENT}, + nsIClassifiedChannel::ClassificationFlags:: + CLASSIFIED_TRACKING_CONTENT}, }; uint32_t flags = UrlClassifierCommon::TablesToClassificationFlags( aList, sClassificationData, - nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING); + nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_TRACKING); UrlClassifierCommon::SetTrackingInfo(aChannel, aList, aHashes); diff --git a/toolkit/components/antitracking/AntiTrackingCommon.cpp b/toolkit/components/antitracking/AntiTrackingCommon.cpp index b39704321596..dddd701ae537 100644 --- a/toolkit/components/antitracking/AntiTrackingCommon.cpp +++ b/toolkit/components/antitracking/AntiTrackingCommon.cpp @@ -21,6 +21,7 @@ #include "mozIThirdPartyUtil.h" #include "nsContentUtils.h" #include "nsGlobalWindowInner.h" +#include "nsIClassifiedChannel.h" #include "nsICookiePermission.h" #include "nsICookieService.h" #include "nsIDocShell.h" @@ -892,22 +893,23 @@ void NotifyBlockingDecisionInternal( nsIWebProgressListener::STATE_COOKIES_LOADED, aReportingChannel, false, aURI, aTrackingChannel); - nsCOMPtr httpChannel = do_QueryInterface(aTrackingChannel); - if (!httpChannel) { + nsCOMPtr classifiedChannel = + do_QueryInterface(aTrackingChannel); + if (!classifiedChannel) { return; } uint32_t classificationFlags = - httpChannel->GetThirdPartyClassificationFlags(); + classifiedChannel->GetThirdPartyClassificationFlags(); if (classificationFlags & - nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING) { + nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_TRACKING) { aWindow->NotifyContentBlockingEvent( nsIWebProgressListener::STATE_COOKIES_LOADED_TRACKER, aReportingChannel, false, aURI, aTrackingChannel); } if (classificationFlags & - nsIHttpChannel::ClassificationFlags::CLASSIFIED_SOCIALTRACKING) { + nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_SOCIALTRACKING) { aWindow->NotifyContentBlockingEvent( nsIWebProgressListener::STATE_COOKIES_LOADED_SOCIALTRACKER, aReportingChannel, false, aURI, aTrackingChannel); @@ -1683,15 +1685,19 @@ bool AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER; // Not a tracker. + nsCOMPtr classifiedChannel = + do_QueryInterface(aChannel); if (behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER) { - if (httpChannel && !httpChannel->IsThirdPartyTrackingResource()) { + if (classifiedChannel && + !classifiedChannel->IsThirdPartyTrackingResource()) { LOG(("Our channel isn't a third-party tracking channel")); return true; } } else { MOZ_ASSERT(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN); - if (httpChannel && httpChannel->IsThirdPartyTrackingResource()) { + if (classifiedChannel && + classifiedChannel->IsThirdPartyTrackingResource()) { // fall through } else if (nsContentUtils::IsThirdPartyWindowOrChannel(nullptr, aChannel, aURI)) { diff --git a/toolkit/components/antitracking/test/browser/antitracking_head.js b/toolkit/components/antitracking/test/browser/antitracking_head.js index d42fa0cf5af2..59de6ce3d90f 100644 --- a/toolkit/components/antitracking/test/browser/antitracking_head.js +++ b/toolkit/components/antitracking/test/browser/antitracking_head.js @@ -1067,6 +1067,6 @@ this.AntiTracking = { channel.asyncOpen(listener); }); - return channel.QueryInterface(Ci.nsIHttpChannel).isTrackingResource(); + return channel.QueryInterface(Ci.nsIClassifiedChannel).isTrackingResource(); }, }; diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_urlclassification.js b/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_urlclassification.js index 06a644c1a05e..9c2296c7daae 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_urlclassification.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_urlclassification.js @@ -3,7 +3,7 @@ const { Schemas } = ChromeUtils.import("resource://gre/modules/Schemas.jsm"); /** - * If this test fails, likely nsIHttpChannel has added or changed a + * If this test fails, likely nsIClassifiedChannel has added or changed a * CLASSIFIED_* flag. Those changes must be in sync with * ChannelWrapper.webidl/cpp and the web_request.json schema file. */ @@ -20,7 +20,7 @@ add_task(async function test_webrequest_url_classification_enum() { let prefix = /^(?:CLASSIFIED_)/; let entries = 0; - for (let c of Object.keys(Ci.nsIHttpChannel).filter(name => + for (let c of Object.keys(Ci.nsIClassifiedChannel).filter(name => prefix.test(name) )) { let entry = c.replace(prefix, "").toLowerCase(); diff --git a/toolkit/components/extensions/webrequest/ChannelWrapper.cpp b/toolkit/components/extensions/webrequest/ChannelWrapper.cpp index 2e1b3656f942..b523c508d605 100644 --- a/toolkit/components/extensions/webrequest/ChannelWrapper.cpp +++ b/toolkit/components/extensions/webrequest/ChannelWrapper.cpp @@ -24,6 +24,7 @@ #include "mozilla/dom/Event.h" #include "mozilla/dom/BrowserHost.h" #include "nsIContentPolicy.h" +#include "nsIClassifiedChannel.h" #include "nsIHttpChannelInternal.h" #include "nsIHttpHeaderVisitor.h" #include "nsIInterfaceRequestor.h" @@ -48,7 +49,7 @@ namespace extensions { #define CHANNELWRAPPER_PROP_KEY \ NS_LITERAL_STRING("ChannelWrapper::CachedInstance") -using CF = nsIHttpChannel::ClassificationFlags; +using CF = nsIClassifiedChannel::ClassificationFlags; using MUC = MozUrlClassificationFlags; struct ClassificationStruct { @@ -906,14 +907,20 @@ void FillClassification( void ChannelWrapper::GetUrlClassification( dom::Nullable& aRetVal, ErrorResult& aRv) const { MozUrlClassification classification; - if (nsCOMPtr chan = MaybeHttpChannel()) { + nsCOMPtr chan = MaybeHttpChannel(); + nsCOMPtr classified = do_QueryInterface(chan); + MOZ_DIAGNOSTIC_ASSERT( + classified, + "Must be an object inheriting from both nsIHttpChannel and " + "nsIClassifiedChannel"); + if (classified) { uint32_t classificationFlags; - chan->GetFirstPartyClassificationFlags(&classificationFlags); + classified->GetFirstPartyClassificationFlags(&classificationFlags); FillClassification(classification.mFirstParty, classificationFlags, aRv); if (aRv.Failed()) { return; } - chan->GetThirdPartyClassificationFlags(&classificationFlags); + classified->GetThirdPartyClassificationFlags(&classificationFlags); FillClassification(classification.mThirdParty, classificationFlags, aRv); } aRetVal.SetValue(std::move(classification)); diff --git a/toolkit/components/url-classifier/tests/mochitest/features.js b/toolkit/components/url-classifier/tests/mochitest/features.js index 8ee9960efecc..805f40c6e6ec 100644 --- a/toolkit/components/url-classifier/tests/mochitest/features.js +++ b/toolkit/components/url-classifier/tests/mochitest/features.js @@ -248,8 +248,10 @@ function runTests(flag, prefs, trackingResource) { function onExamResp(subject, topic, data) { let channel = subject.QueryInterface(Ci.nsIHttpChannel); + let classifiedChannel = subject.QueryInterface(Ci.nsIClassifiedChannel); if ( !channel || + !classifiedChannel || !channel.URI.spec.startsWith( "http://example.com/tests/toolkit/components/url-classifier/tests/mochitest/raptor.jpg" ) @@ -259,8 +261,8 @@ function runTests(flag, prefs, trackingResource) { // eslint-disable-next-line no-undef sendAsyncMessage("last-channel-flags", { - classificationFlags: channel.classificationFlags, - isTrackingResource: channel.isTrackingResource(), + classificationFlags: classifiedChannel.classificationFlags, + isTrackingResource: classifiedChannel.isTrackingResource(), }); } 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 e060ed4ae473..ad8e98005b22 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 @@ -10,7 +10,7 @@