diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index e7505a6fe1d9..9a5ba69e3809 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -3555,16 +3555,14 @@ public: --mIgnoreOpensDuringUnloadCounter; } - void IncrementTrackerCount() + void IncrementTrackerCount(bool aIsTrackerBlocked) { MOZ_ASSERT(!GetSameTypeParentDocument()); - ++mNumTrackersFound; - } - void IncrementTrackerBlockedCount() - { - MOZ_ASSERT(!GetSameTypeParentDocument()); - ++mNumTrackersBlocked; + ++mNumTrackersFound; + if (aIsTrackerBlocked) { + ++mNumTrackersBlocked; + } } uint32_t NumTrackersFound() diff --git a/netwerk/base/nsChannelClassifier.cpp b/netwerk/base/nsChannelClassifier.cpp index f6572bb9ae91..2c74c073a703 100644 --- a/netwerk/base/nsChannelClassifier.cpp +++ b/netwerk/base/nsChannelClassifier.cpp @@ -911,6 +911,8 @@ nsChannelClassifier::SetBlockedContent(nsIChannel *channel, nsCOMPtr doc = docShell->GetDocument(); NS_ENSURE_TRUE(doc, NS_OK); + doc->IncrementTrackerCount(true); + unsigned state; if (aErrorCode == NS_ERROR_TRACKING_URI) { state = nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT; diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index 7fde8ced991b..e9354b4aafc2 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -331,10 +331,6 @@ HttpBaseChannel::SetIsTrackingResource(bool aIsThirdParty) MOZ_ASSERT(!mIsThirdPartyTrackingResource); mIsFirstPartyTrackingResource = true; } - - if (mLoadInfo) { - MOZ_ALWAYS_SUCCEEDS(mLoadInfo->SetIsTracker(true)); - } } nsresult diff --git a/netwerk/protocol/http/HttpChannelChild.cpp b/netwerk/protocol/http/HttpChannelChild.cpp index 0f04f3470a86..7d5b8adacc18 100644 --- a/netwerk/protocol/http/HttpChannelChild.cpp +++ b/netwerk/protocol/http/HttpChannelChild.cpp @@ -747,10 +747,10 @@ HttpChannelChild::DoOnStartRequest(nsIRequest* aRequest, nsISupports* aContext) } bool isTracker; - MOZ_ALWAYS_SUCCEEDS(mLoadInfo->GetIsTracker(&isTracker)); - if (isTracker) { + if (NS_SUCCEEDED(mLoadInfo->GetIsTracker(&isTracker)) && isTracker) { bool isTrackerBlocked; - MOZ_ALWAYS_SUCCEEDS(mLoadInfo->GetIsTrackerBlocked(&isTrackerBlocked)); + Unused << mLoadInfo->GetIsTrackerBlocked(&isTrackerBlocked); + LOG(("HttpChannelChild::DoOnStartRequest FastBlock %d [this=%p]\n", isTrackerBlocked, this)); @@ -758,10 +758,8 @@ HttpChannelChild::DoOnStartRequest(nsIRequest* aRequest, nsISupports* aContext) nsCOMPtr doc; if (!NS_WARN_IF(NS_FAILED(GetTopDocument(this, getter_AddRefs(doc))))) { - doc->IncrementTrackerCount(); - if (isTrackerBlocked) { - doc->IncrementTrackerBlockedCount(); - } + + doc->IncrementTrackerCount(isTrackerBlocked); } } diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 632eff1e63e5..1381afd634ec 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -694,7 +694,6 @@ bool nsHttpChannel::CheckFastBlocked() { LOG(("nsHttpChannel::CheckFastBlocked [this=%p]\n", this)); - MOZ_ASSERT(mIsThirdPartyTrackingResource); static bool sFastBlockInited = false; static bool sIsFastBlockEnabled = false; @@ -707,26 +706,23 @@ nsHttpChannel::CheckFastBlocked() } TimeStamp timestamp; - if (NS_FAILED(GetNavigationStartTimeStamp(×tamp)) || !timestamp) { - LOG(("FastBlock passed (no timestamp) [this=%p]\n", this)); - + if (NS_FAILED(GetNavigationStartTimeStamp(×tamp))) { return false; } if (!StaticPrefs::browser_contentblocking_enabled() || !sIsFastBlockEnabled || - IsContentPolicyTypeWhitelistedForFastBlock(mLoadInfo)) { - - LOG(("FastBlock passed (invalid) [this=%p]\n", this)); - + IsContentPolicyTypeWhitelistedForFastBlock(mLoadInfo) || + !timestamp) { return false; } TimeDuration duration = TimeStamp::NowLoRes() - timestamp; bool isFastBlocking = duration.ToMilliseconds() >= sFastBlockTimeout; - if (isFastBlocking && mLoadInfo) { - MOZ_ALWAYS_SUCCEEDS(mLoadInfo->SetIsTrackerBlocked(true)); + if (mLoadInfo) { + MOZ_ALWAYS_SUCCEEDS(mLoadInfo->SetIsTracker(true)); + MOZ_ALWAYS_SUCCEEDS(mLoadInfo->SetIsTrackerBlocked(isFastBlocking)); } LOG(("FastBlock %s (%lf) [this=%p]\n", @@ -6109,10 +6105,6 @@ nsHttpChannel::CancelInternal(nsresult status) !!mTrackingProtectionCancellationPending; if (status == NS_ERROR_TRACKING_URI) { mTrackingProtectionCancellationPending = 0; - if (mLoadInfo) { - MOZ_ALWAYS_SUCCEEDS(mLoadInfo->SetIsTracker(true)); - MOZ_ALWAYS_SUCCEEDS(mLoadInfo->SetIsTrackerBlocked(true)); - } } mCanceled = true;