Bug 1522210 - Fingerprinting and cryptomining classifiers must have separate nsIWebProgressListener blocking state codes - part 3 - Canceling nsIChannel with error code, r=ehsan

Differential Revision: https://phabricator.services.mozilla.com/D17638
This commit is contained in:
Andrea Marchesini 2019-01-25 14:50:26 +01:00
Родитель 3386d20a2c
Коммит ef89767387
9 изменённых файлов: 39 добавлений и 29 удалений

Просмотреть файл

@ -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; }

Просмотреть файл

@ -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;

Просмотреть файл

@ -610,7 +610,7 @@ TrackingDummyChannel::SetNavigationStartTimeStamp(
}
NS_IMETHODIMP
TrackingDummyChannel::CancelForTrackingProtection() {
TrackingDummyChannel::CancelByChannelClassifier(nsresult aErrorCode) {
return NS_ERROR_NOT_IMPLEMENTED;
}

Просмотреть файл

@ -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<uint32_t>(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) {

Просмотреть файл

@ -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<nsresult(nsHttpChannel *)> &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.)

Просмотреть файл

@ -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.

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -148,7 +148,7 @@ UrlClassifierFeatureTrackingProtection::ProcessChannel(nsIChannel* aChannel,
aChannel));
nsCOMPtr<nsIHttpChannelInternal> httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
Unused << httpChannel->CancelForTrackingProtection();
Unused << httpChannel->CancelByChannelClassifier(NS_ERROR_TRACKING_URI);
} else {
Unused << aChannel->Cancel(NS_ERROR_TRACKING_URI);
}