From c8306bf2d93e3e585c271df213bafa7dc6bac05d Mon Sep 17 00:00:00 2001 From: Dimi Lee Date: Thu, 9 Jul 2020 20:10:18 +0000 Subject: [PATCH] Bug 1447935 - P2. Use fission-compatible third-party checks r=baku Differential Revision: https://phabricator.services.mozilla.com/D80187 --- ...lassifierFeatureCryptominingProtection.cpp | 34 ++++++++----------- ...ssifierFeatureFingerprintingProtection.cpp | 33 ++++++++---------- ...ssifierFeatureSocialTrackingProtection.cpp | 34 ++++++++----------- ...UrlClassifierFeatureTrackingProtection.cpp | 32 ++++++++--------- 4 files changed, 59 insertions(+), 74 deletions(-) diff --git a/netwerk/url-classifier/UrlClassifierFeatureCryptominingProtection.cpp b/netwerk/url-classifier/UrlClassifierFeatureCryptominingProtection.cpp index f8c15ae72848..f792cb2e3574 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureCryptominingProtection.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureCryptominingProtection.cpp @@ -6,10 +6,10 @@ #include "UrlClassifierFeatureCryptominingProtection.h" +#include "mozilla/AntiTrackingUtils.h" #include "mozilla/net/UrlClassifierCommon.h" #include "ChannelClassifierService.h" #include "mozilla/StaticPrefs_privacy.h" -#include "nsContentUtils.h" #include "nsNetUtil.h" namespace mozilla { @@ -87,27 +87,23 @@ UrlClassifierFeatureCryptominingProtection::MaybeCreate(nsIChannel* aChannel) { return nullptr; } - nsCOMPtr chanURI; - nsresult rv = aChannel->GetURI(getter_AddRefs(chanURI)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return nullptr; - } - - bool isThirdParty = - nsContentUtils::IsThirdPartyWindowOrChannel(nullptr, aChannel, chanURI); + bool isThirdParty = AntiTrackingUtils::IsThirdPartyChannel(aChannel); if (!isThirdParty) { if (UC_LOG_ENABLED()) { - nsCString spec = chanURI->GetSpecOrDefault(); - spec.Truncate( - std::min(spec.Length(), UrlClassifierCommon::sMaxSpecLength)); - UC_LOG( - ("UrlClassifierFeatureCryptominingProtection: Skipping cryptomining " - "checks " - "for first party or top-level load channel[%p] " - "with uri %s", - aChannel, spec.get())); + nsCOMPtr chanURI; + Unused << aChannel->GetURI(getter_AddRefs(chanURI)); + if (chanURI) { + nsCString spec = chanURI->GetSpecOrDefault(); + spec.Truncate( + std::min(spec.Length(), UrlClassifierCommon::sMaxSpecLength)); + UC_LOG( + ("UrlClassifierFeatureCryptominingProtection: Skipping cryptomining " + "checks " + "for first party or top-level load channel[%p] " + "with uri %s", + aChannel, spec.get())); + } } - return nullptr; } diff --git a/netwerk/url-classifier/UrlClassifierFeatureFingerprintingProtection.cpp b/netwerk/url-classifier/UrlClassifierFeatureFingerprintingProtection.cpp index c64b48ad658d..469d0e10288c 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureFingerprintingProtection.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureFingerprintingProtection.cpp @@ -6,10 +6,10 @@ #include "UrlClassifierFeatureFingerprintingProtection.h" +#include "mozilla/AntiTrackingUtils.h" #include "mozilla/net/UrlClassifierCommon.h" #include "ChannelClassifierService.h" #include "mozilla/StaticPrefs_privacy.h" -#include "nsContentUtils.h" #include "nsNetUtil.h" namespace mozilla { @@ -90,25 +90,22 @@ UrlClassifierFeatureFingerprintingProtection::MaybeCreate( return nullptr; } - nsCOMPtr chanURI; - nsresult rv = aChannel->GetURI(getter_AddRefs(chanURI)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return nullptr; - } - - bool isThirdParty = - nsContentUtils::IsThirdPartyWindowOrChannel(nullptr, aChannel, chanURI); + bool isThirdParty = AntiTrackingUtils::IsThirdPartyChannel(aChannel); if (!isThirdParty) { if (UC_LOG_ENABLED()) { - nsCString spec = chanURI->GetSpecOrDefault(); - spec.Truncate( - std::min(spec.Length(), UrlClassifierCommon::sMaxSpecLength)); - UC_LOG( - ("UrlClassifierFeatureFingerprintingProtection: Skipping " - "fingerprinting checks " - "for first party or top-level load channel[%p] " - "with uri %s", - aChannel, spec.get())); + nsCOMPtr chanURI; + Unused << aChannel->GetURI(getter_AddRefs(chanURI)); + if (chanURI) { + nsCString spec = chanURI->GetSpecOrDefault(); + spec.Truncate( + std::min(spec.Length(), UrlClassifierCommon::sMaxSpecLength)); + UC_LOG( + ("UrlClassifierFeatureFingerprintingProtection: Skipping " + "fingerprinting checks " + "for first party or top-level load channel[%p] " + "with uri %s", + aChannel, spec.get())); + } } return nullptr; } diff --git a/netwerk/url-classifier/UrlClassifierFeatureSocialTrackingProtection.cpp b/netwerk/url-classifier/UrlClassifierFeatureSocialTrackingProtection.cpp index 02404f59d232..66483ff3df02 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureSocialTrackingProtection.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureSocialTrackingProtection.cpp @@ -6,10 +6,10 @@ #include "UrlClassifierFeatureSocialTrackingProtection.h" +#include "mozilla/AntiTrackingUtils.h" #include "mozilla/net/UrlClassifierCommon.h" #include "ChannelClassifierService.h" #include "mozilla/StaticPrefs_privacy.h" -#include "nsContentUtils.h" #include "nsNetUtil.h" namespace mozilla { @@ -90,27 +90,23 @@ UrlClassifierFeatureSocialTrackingProtection::MaybeCreate( return nullptr; } - nsCOMPtr chanURI; - nsresult rv = aChannel->GetURI(getter_AddRefs(chanURI)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return nullptr; - } - - bool isThirdParty = - nsContentUtils::IsThirdPartyWindowOrChannel(nullptr, aChannel, chanURI); + bool isThirdParty = AntiTrackingUtils::IsThirdPartyChannel(aChannel); if (!isThirdParty) { if (UC_LOG_ENABLED()) { - nsCString spec = chanURI->GetSpecOrDefault(); - spec.Truncate( - std::min(spec.Length(), UrlClassifierCommon::sMaxSpecLength)); - UC_LOG( - ("UrlClassifierFeatureSocialTrackingProtection: Skipping " - "socialtracking checks " - "for first party or top-level load channel[%p] " - "with uri %s", - aChannel, spec.get())); + nsCOMPtr chanURI; + Unused << aChannel->GetURI(getter_AddRefs(chanURI)); + if (chanURI) { + nsCString spec = chanURI->GetSpecOrDefault(); + spec.Truncate( + std::min(spec.Length(), UrlClassifierCommon::sMaxSpecLength)); + UC_LOG( + ("UrlClassifierFeatureSocialTrackingProtection: Skipping " + "socialtracking checks " + "for first party or top-level load channel[%p] " + "with uri %s", + aChannel, spec.get())); + } } - return nullptr; } diff --git a/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp b/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp index 800fb2038506..0864e1c82de6 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp @@ -6,9 +6,9 @@ #include "UrlClassifierFeatureTrackingProtection.h" +#include "mozilla/AntiTrackingUtils.h" #include "mozilla/net/UrlClassifierCommon.h" #include "ChannelClassifierService.h" -#include "nsContentUtils.h" #include "nsIHttpChannelInternal.h" #include "nsILoadContext.h" #include "nsNetUtil.h" @@ -93,26 +93,22 @@ UrlClassifierFeatureTrackingProtection::MaybeCreate(nsIChannel* aChannel) { return nullptr; } - nsCOMPtr chanURI; - nsresult rv = aChannel->GetURI(getter_AddRefs(chanURI)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return nullptr; - } - - bool isThirdParty = - nsContentUtils::IsThirdPartyWindowOrChannel(nullptr, aChannel, chanURI); + bool isThirdParty = AntiTrackingUtils::IsThirdPartyChannel(aChannel); if (!isThirdParty) { if (UC_LOG_ENABLED()) { - nsCString spec = chanURI->GetSpecOrDefault(); - spec.Truncate( - std::min(spec.Length(), UrlClassifierCommon::sMaxSpecLength)); - UC_LOG( - ("UrlClassifierFeatureTrackingProtection: Skipping tracking " - "protection checks for first party or top-level load channel[%p] " - "with uri %s", - aChannel, spec.get())); + nsCOMPtr chanURI; + Unused << aChannel->GetURI(getter_AddRefs(chanURI)); + if (chanURI) { + nsCString spec = chanURI->GetSpecOrDefault(); + spec.Truncate( + std::min(spec.Length(), UrlClassifierCommon::sMaxSpecLength)); + UC_LOG( + ("UrlClassifierFeatureTrackingProtection: Skipping tracking " + "protection checks for first party or top-level load channel[%p] " + "with uri %s", + aChannel, spec.get())); + } } - return nullptr; }