diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index b291d1fff109..5b0c29c234ff 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -45,6 +45,7 @@ #include "mozilla/AntiTrackingCommon.h" #include "mozilla/dom/Performance.h" #include "mozilla/dom/PerformanceStorage.h" +#include "mozilla/net/UrlClassifierFeatureFactory.h" #include "mozilla/NullPrincipal.h" #include "mozilla/Services.h" #include "mozIThirdPartyUtil.h" @@ -4542,8 +4543,10 @@ HttpBaseChannel::GetNativeServerTiming( } NS_IMETHODIMP -HttpBaseChannel::CancelForTrackingProtection() { - return Cancel(NS_ERROR_TRACKING_URI); +HttpBaseChannel::CancelByChannelClassifier(nsresult aErrorCode) { + MOZ_ASSERT( + UrlClassifierFeatureFactory::IsClassifierBlockingErrorCode(aErrorCode)); + return Cancel(aErrorCode); } void HttpBaseChannel::SetIPv4Disabled() { mCaps |= NS_HTTP_DISABLE_IPV4; } diff --git a/netwerk/protocol/http/HttpBaseChannel.h b/netwerk/protocol/http/HttpBaseChannel.h index 7ebd598515ba..9b856e0299fe 100644 --- a/netwerk/protocol/http/HttpBaseChannel.h +++ b/netwerk/protocol/http/HttpBaseChannel.h @@ -307,7 +307,7 @@ class HttpBaseChannel : public nsHashPropertyBag, NS_IMETHOD SetLastRedirectFlags(uint32_t aValue) override; NS_IMETHOD GetNavigationStartTimeStamp(TimeStamp *aTimeStamp) override; NS_IMETHOD SetNavigationStartTimeStamp(TimeStamp aTimeStamp) override; - NS_IMETHOD CancelForTrackingProtection() override; + NS_IMETHOD CancelByChannelClassifier(nsresult aErrorCode) override; virtual void SetIPv4Disabled(void) override; virtual void SetIPv6Disabled(void) override; diff --git a/netwerk/protocol/http/TrackingDummyChannel.cpp b/netwerk/protocol/http/TrackingDummyChannel.cpp index 2f6940ecb8b2..f1b93726229c 100644 --- a/netwerk/protocol/http/TrackingDummyChannel.cpp +++ b/netwerk/protocol/http/TrackingDummyChannel.cpp @@ -610,7 +610,7 @@ TrackingDummyChannel::SetNavigationStartTimeStamp( } NS_IMETHODIMP -TrackingDummyChannel::CancelForTrackingProtection() { +TrackingDummyChannel::CancelByChannelClassifier(nsresult aErrorCode) { return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index d86fb90d016a..7aabf9e6f642 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -449,24 +449,27 @@ nsresult nsHttpChannel::PrepareToConnect() { return OnBeforeConnect(); } -void nsHttpChannel::HandleContinueCancelledByTrackingProtection() { +void nsHttpChannel::HandleContinueCancellingByChannelClassifier( + nsresult aErrorCode) { + MOZ_ASSERT( + UrlClassifierFeatureFactory::IsClassifierBlockingErrorCode(aErrorCode)); MOZ_ASSERT(!mCallOnResume, "How did that happen?"); if (mSuspendCount) { LOG( - ("Waiting until resume HandleContinueCancelledByTrackingProtection " + ("Waiting until resume HandleContinueCancellingByChannelClassifier " "[this=%p]\n", this)); - mCallOnResume = [](nsHttpChannel *self) { - self->HandleContinueCancelledByTrackingProtection(); + mCallOnResume = [aErrorCode](nsHttpChannel *self) { + self->HandleContinueCancellingByChannelClassifier(aErrorCode); return NS_OK; }; return; } - LOG(("nsHttpChannel::HandleContinueCancelledByTrackingProtection [this=%p]\n", + LOG(("nsHttpChannel::HandleContinueCancellingByChannelClassifier [this=%p]\n", this)); - ContinueCancelledByTrackingProtection(); + ContinueCancellingByChannelClassifier(aErrorCode); } void nsHttpChannel::HandleOnBeforeConnect() { @@ -5995,7 +5998,7 @@ nsHttpChannel::Cancel(nsresult status) { if (UrlClassifierFeatureFactory::IsClassifierBlockingErrorCode(status)) { MOZ_CRASH_UNSAFE_PRINTF( "Blocking classifier error %" PRIx32 - " need to be handled by CancelForTrackingProtection()", + " need to be handled by CancelByChannelClassifier()", static_cast(status)); } #endif @@ -6015,12 +6018,14 @@ nsHttpChannel::Cancel(nsresult status) { } NS_IMETHODIMP -nsHttpChannel::CancelForTrackingProtection() { +nsHttpChannel::CancelByChannelClassifier(nsresult aErrorCode) { + MOZ_ASSERT( + UrlClassifierFeatureFactory::IsClassifierBlockingErrorCode(aErrorCode)); MOZ_ASSERT(NS_IsMainThread()); // We should never have a pump open while a CORS preflight is in progress. MOZ_ASSERT_IF(mPreflightChannel, !mCachePump); - LOG(("nsHttpChannel::CancelForTrackingProtection [this=%p]\n", this)); + LOG(("nsHttpChannel::CancelByChannelClassifier [this=%p]\n", this)); if (mCanceled) { LOG((" ignoring; already canceled\n")); @@ -6052,8 +6057,8 @@ nsHttpChannel::CancelForTrackingProtection() { LOG(("Waiting until resume in Cancel [this=%p]\n", this)); MOZ_ASSERT(!mCallOnResume); mChannelClassifierCancellationPending = 1; - mCallOnResume = [](nsHttpChannel *self) { - self->HandleContinueCancelledByTrackingProtection(); + mCallOnResume = [aErrorCode](nsHttpChannel *self) { + self->HandleContinueCancellingByChannelClassifier(aErrorCode); return NS_OK; }; return NS_OK; @@ -6066,15 +6071,17 @@ nsHttpChannel::CancelForTrackingProtection() { return AsyncCall(&nsHttpChannel::HandleAsyncAPIRedirect); } - return CancelInternal(NS_ERROR_TRACKING_URI); + return CancelInternal(aErrorCode); } -void nsHttpChannel::ContinueCancelledByTrackingProtection() { +void nsHttpChannel::ContinueCancellingByChannelClassifier(nsresult aErrorCode) { + MOZ_ASSERT( + UrlClassifierFeatureFactory::IsClassifierBlockingErrorCode(aErrorCode)); MOZ_ASSERT(NS_IsMainThread()); // We should never have a pump open while a CORS preflight is in progress. MOZ_ASSERT_IF(mPreflightChannel, !mCachePump); - LOG(("nsHttpChannel::ContinueCancelledByTrackingProtection [this=%p]\n", + LOG(("nsHttpChannel::ContinueCancellingByChannelClassifier [this=%p]\n", this)); if (mCanceled) { LOG((" ignoring; already canceled\n")); @@ -6088,7 +6095,7 @@ void nsHttpChannel::ContinueCancelledByTrackingProtection() { return; } - Unused << CancelInternal(NS_ERROR_TRACKING_URI); + Unused << CancelInternal(aErrorCode); } nsresult nsHttpChannel::CancelInternal(nsresult status) { diff --git a/netwerk/protocol/http/nsHttpChannel.h b/netwerk/protocol/http/nsHttpChannel.h index d096eb8eff4c..e72b2408ea29 100644 --- a/netwerk/protocol/http/nsHttpChannel.h +++ b/netwerk/protocol/http/nsHttpChannel.h @@ -169,7 +169,7 @@ class nsHttpChannel final : public HttpBaseChannel, NS_IMETHOD SetChannelIsForDownload(bool aChannelIsForDownload) override; NS_IMETHOD GetNavigationStartTimeStamp(TimeStamp *aTimeStamp) override; NS_IMETHOD SetNavigationStartTimeStamp(TimeStamp aTimeStamp) override; - NS_IMETHOD CancelForTrackingProtection() override; + NS_IMETHOD CancelByChannelClassifier(nsresult aErrorCode) override; // nsISupportsPriority NS_IMETHOD SetPriority(int32_t value) override; // nsIClassOfService @@ -310,9 +310,9 @@ class nsHttpChannel final : public HttpBaseChannel, const std::function &aFunc); bool RequestIsConditional(); - void HandleContinueCancelledByTrackingProtection(); + void HandleContinueCancellingByChannelClassifier(nsresult aErrorCode); nsresult CancelInternal(nsresult status); - void ContinueCancelledByTrackingProtection(); + void ContinueCancellingByChannelClassifier(nsresult aErrorCode); // Connections will only be established in this function. // (including DNS prefetch and speculative connection.) diff --git a/netwerk/protocol/http/nsIHttpChannelInternal.idl b/netwerk/protocol/http/nsIHttpChannelInternal.idl index 1c18a079c28a..1774f99d90ad 100644 --- a/netwerk/protocol/http/nsIHttpChannelInternal.idl +++ b/netwerk/protocol/http/nsIHttpChannelInternal.idl @@ -352,11 +352,11 @@ interface nsIHttpChannelInternal : nsISupports /** * Cancel a channel because we have determined that it needs to be blocked - * for tracking protection. This is an internal API that is meant to be - * called by the channel classifier. Please DO NOT use this API if you don't - * know whether you should be using it. + * for safe-browsing protection. This is an internal API that is meant to + * be called by the channel classifier. Please DO NOT use this API if you + * don't know whether you should be using it. */ - [noscript] void cancelForTrackingProtection(); + [noscript] void cancelByChannelClassifier(in nsresult aErrorCode); /** * The channel will be loaded over IPv6, disabling IPv4. diff --git a/netwerk/url-classifier/UrlClassifierFeatureCryptomining.cpp b/netwerk/url-classifier/UrlClassifierFeatureCryptomining.cpp index 407b32779ade..68958e1b40d8 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureCryptomining.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureCryptomining.cpp @@ -148,7 +148,7 @@ UrlClassifierFeatureCryptomining::ProcessChannel(nsIChannel* aChannel, // FIXME: the way we cancel the channel depends on what the UI wants to show. // This needs to change, at some point. if (httpChannel) { - Unused << httpChannel->CancelForTrackingProtection(); + Unused << httpChannel->CancelByChannelClassifier(NS_ERROR_TRACKING_URI); } else { Unused << aChannel->Cancel(NS_ERROR_TRACKING_URI); } diff --git a/netwerk/url-classifier/UrlClassifierFeatureFingerprinting.cpp b/netwerk/url-classifier/UrlClassifierFeatureFingerprinting.cpp index 16c87bb84c14..8f432a40c751 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureFingerprinting.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureFingerprinting.cpp @@ -150,7 +150,7 @@ UrlClassifierFeatureFingerprinting::ProcessChannel(nsIChannel* aChannel, // FIXME: the way we cancel the channel depends on what the UI wants to show. // This needs to change, at some point. if (httpChannel) { - Unused << httpChannel->CancelForTrackingProtection(); + Unused << httpChannel->CancelByChannelClassifier(NS_ERROR_TRACKING_URI); } else { Unused << aChannel->Cancel(NS_ERROR_TRACKING_URI); } diff --git a/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp b/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp index 5528618df366..4bf9b6f06d16 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp @@ -148,7 +148,7 @@ UrlClassifierFeatureTrackingProtection::ProcessChannel(nsIChannel* aChannel, aChannel)); nsCOMPtr httpChannel = do_QueryInterface(aChannel); if (httpChannel) { - Unused << httpChannel->CancelForTrackingProtection(); + Unused << httpChannel->CancelByChannelClassifier(NS_ERROR_TRACKING_URI); } else { Unused << aChannel->Cancel(NS_ERROR_TRACKING_URI); }