Bug 1509555 - Part 2: Remove the core fastblock code r=valentin

Depends on D12828

Differential Revision: https://phabricator.services.mozilla.com/D12829

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ehsan Akhgari 2018-11-26 11:37:01 +00:00
parent 15bf246249
commit b0af8bcf40
5 changed files with 6 additions and 145 deletions

View File

@ -348,11 +348,10 @@ interface nsIContentPolicy : nsISupports
/* When adding new content types, please update nsContentBlocker,
* NS_CP_ContentTypeName, nsCSPContext, CSP_ContentTypeToDirective,
* DoContentSecurityChecks, IsContentPolicyTypeWhitelistedForFastBlock,
* all nsIContentPolicy implementations, the static_assert in
* dom/cache/DBSchema.cpp, ChannelWrapper.webidl, ChannelWrapper.cpp,
* nsPermissionManager.cpp, and other things that are not listed here
* that are related to nsIContentPolicy. */
* DoContentSecurityChecks, all nsIContentPolicy implementations, the
* static_assert in dom/cache/DBSchema.cpp, ChannelWrapper.webidl,
* ChannelWrapper.cpp, nsPermissionManager.cpp, and other things that are not
* listed here that are related to nsIContentPolicy. */
//////////////////////////////////////////////////////////////////////

View File

@ -1716,13 +1716,6 @@ VARCACHE_PREF(
uint32_t, 32
)
// Whether FastBlock has been enabled.
VARCACHE_PREF(
"browser.fastblock.enabled",
browser_fastblock_enabled,
bool, false
)
// Anti-tracking permission expiration
VARCACHE_PREF(
"privacy.restrict3rdpartystorage.expiration",

View File

@ -5563,7 +5563,7 @@ pref("urlclassifier.trackingTable", "test-track-simple,base-track-digest256");
pref("urlclassifier.trackingWhitelistTable", "test-trackwhite-simple,mozstd-trackwhite-digest256");
// These tables will never trigger a gethash call.
pref("urlclassifier.disallow_completions", "test-malware-simple,test-harmful-simple,test-phish-simple,test-unwanted-simple,test-track-simple,test-trackwhite-simple,test-block-simple,goog-downloadwhite-digest256,base-track-digest256,mozstd-trackwhite-digest256,content-track-digest256,mozplugin-block-digest256,mozplugin2-block-digest256,block-flash-digest256,except-flash-digest256,allow-flashallow-digest256,except-flashallow-digest256,block-flashsubdoc-digest256,except-flashsubdoc-digest256,except-flashinfobar-digest256,goog-passwordwhite-proto,ads-track-digest256,social-track-digest256,analytics-track-digest256,fastblock1-track-digest256,fastblock1-trackwhite-digest256,fastblock2-track-digest256,fastblock2-trackwhite-digest256,fastblock3-track-digest256");
pref("urlclassifier.disallow_completions", "test-malware-simple,test-harmful-simple,test-phish-simple,test-unwanted-simple,test-track-simple,test-trackwhite-simple,test-block-simple,goog-downloadwhite-digest256,base-track-digest256,mozstd-trackwhite-digest256,content-track-digest256,mozplugin-block-digest256,mozplugin2-block-digest256,block-flash-digest256,except-flash-digest256,allow-flashallow-digest256,except-flashallow-digest256,block-flashsubdoc-digest256,except-flashsubdoc-digest256,except-flashinfobar-digest256,goog-passwordwhite-proto,ads-track-digest256,social-track-digest256,analytics-track-digest256");
// Number of random entries to send with a gethash request
pref("urlclassifier.gethashnoise", 4);
@ -5635,7 +5635,7 @@ pref("browser.safebrowsing.reportPhishURL", "https://%LOCALE%.phish-report.mozil
// Mozilla Safe Browsing provider (for tracking protection and plugin blocking)
pref("browser.safebrowsing.provider.mozilla.pver", "2.2");
pref("browser.safebrowsing.provider.mozilla.lists", "base-track-digest256,mozstd-trackwhite-digest256,content-track-digest256,mozplugin-block-digest256,mozplugin2-block-digest256,block-flash-digest256,except-flash-digest256,allow-flashallow-digest256,except-flashallow-digest256,block-flashsubdoc-digest256,except-flashsubdoc-digest256,except-flashinfobar-digest256,ads-track-digest256,social-track-digest256,analytics-track-digest256,fastblock1-track-digest256,fastblock1-trackwhite-digest256,fastblock2-track-digest256,fastblock2-trackwhite-digest256,fastblock3-track-digest256");
pref("browser.safebrowsing.provider.mozilla.lists", "base-track-digest256,mozstd-trackwhite-digest256,content-track-digest256,mozplugin-block-digest256,mozplugin2-block-digest256,block-flash-digest256,except-flash-digest256,allow-flashallow-digest256,except-flashallow-digest256,block-flashsubdoc-digest256,except-flashsubdoc-digest256,except-flashinfobar-digest256,ads-track-digest256,social-track-digest256,analytics-track-digest256");
pref("browser.safebrowsing.provider.mozilla.updateURL", "https://shavar.services.mozilla.com/downloads?client=SAFEBROWSING_ID&appver=%MAJOR_VERSION%&pver=2.2");
pref("browser.safebrowsing.provider.mozilla.gethashURL", "https://shavar.services.mozilla.com/gethash?client=SAFEBROWSING_ID&appver=%MAJOR_VERSION%&pver=2.2");
// Set to a date in the past to force immediate download in new profiles.
@ -5975,13 +5975,6 @@ pref("general.document_open_conversion_depth_limit", 20);
// documentElement and document.body are passive by default.
pref("dom.event.default_to_passive_touch_listeners", true);
// The amount of time (ms) since navigation start after which all
// tracker connections will be cancelled.
pref("browser.fastblock.timeout", 5000);
// The amount of time (ms) since navigation start after which
// we'll stop blocking tracker connections (0 = no limit).
pref("browser.fastblock.limit", 20000);
// Enable clipboard readText() and writeText() by default
pref("dom.events.asyncClipboard", true);
// Disable clipboard read() and write() by default

View File

@ -668,112 +668,6 @@ nsHttpChannel::Connect()
return ConnectOnTailUnblock();
}
static bool
IsContentPolicyTypeWhitelistedForFastBlock(nsILoadInfo* aLoadInfo)
{
nsContentPolicyType type = aLoadInfo ?
aLoadInfo->GetExternalContentPolicyType() :
nsIContentPolicy::TYPE_OTHER;
switch (type) {
// images
case nsIContentPolicy::TYPE_IMAGE:
case nsIContentPolicy::TYPE_IMAGESET:
case nsIContentPolicy::TYPE_INTERNAL_IMAGE:
case nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD:
case nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON:
// fonts
case nsIContentPolicy::TYPE_FONT:
// stylesheets
case nsIContentPolicy::TYPE_STYLESHEET:
case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET:
case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD:
return true;
default:
return false;
}
}
bool
nsHttpChannel::CheckFastBlocked()
{
LOG(("nsHttpChannel::CheckFastBlocked [this=%p, url=%s]",
this, mSpec.get()));
MOZ_ASSERT(mIsThirdPartyTrackingResource);
static bool sFastBlockInited = false;
static uint32_t sFastBlockTimeout = 0;
static uint32_t sFastBlockLimit = 0;
if (!sFastBlockInited) {
sFastBlockInited = true;
Preferences::AddUintVarCache(&sFastBlockTimeout, "browser.fastblock.timeout");
Preferences::AddUintVarCache(&sFastBlockLimit, "browser.fastblock.limit");
}
if (!StaticPrefs::browser_fastblock_enabled()) {
LOG(("FastBlock disabled by pref [this=%p]\n", this));
return false;
}
TimeStamp timestamp;
if (NS_FAILED(GetNavigationStartTimeStamp(&timestamp)) || !timestamp) {
LOG(("FastBlock passed (no timestamp) [this=%p]\n", this));
return false;
}
bool engageFastBlock = false;
TimeDuration duration = TimeStamp::NowLoRes() - timestamp;
if (IsContentPolicyTypeWhitelistedForFastBlock(mLoadInfo)) {
LOG(("FastBlock passed (whitelisted content type %u) (%lf) [this=%p]\n",
mLoadInfo ? mLoadInfo->GetExternalContentPolicyType() : nsIContentPolicy::TYPE_OTHER,
duration.ToMilliseconds(), this));
} else if (mLoadInfo && mLoadInfo->GetDocumentHasUserInteracted()) {
LOG(("FastBlock passed (user interaction) (%lf) [this=%p]\n",
duration.ToMilliseconds(), this));
} else if (mLoadInfo && mLoadInfo->GetDocumentHasLoaded()) {
LOG(("FastBlock passed (document loaded) (%lf) [this=%p]\n",
duration.ToMilliseconds(), this));
} else {
bool hasFastBlockStarted = duration.ToMilliseconds() >= sFastBlockTimeout;
bool hasFastBlockStopped = false;
if ((sFastBlockLimit != 0) && (sFastBlockLimit > sFastBlockTimeout)) {
hasFastBlockStopped = duration.ToMilliseconds() > sFastBlockLimit;
}
LOG(("FastBlock started=%d stopped=%d (%lf) [this=%p]\n",
static_cast<int>(hasFastBlockStarted),
static_cast<int>(hasFastBlockStopped),
duration.ToMilliseconds(),
this));
engageFastBlock = hasFastBlockStarted && !hasFastBlockStopped;
}
if (!engageFastBlock) {
return false;
}
TimeDuration duration = TimeStamp::NowLoRes() - timestamp;
bool hasFastBlockStarted = duration.ToMilliseconds() >= sFastBlockTimeout;
bool hasFastBlockStopped = false;
if ((sFastBlockLimit != 0) && (sFastBlockLimit > sFastBlockTimeout)) {
hasFastBlockStopped = duration.ToMilliseconds() > sFastBlockLimit;
}
const bool isFastBlocking = hasFastBlockStarted && !hasFastBlockStopped;
if (isFastBlocking && mLoadInfo) {
MOZ_ALWAYS_SUCCEEDS(mLoadInfo->SetIsTrackerBlocked(true));
}
LOG(("FastBlock started=%d stopped=%d (%lf) [this=%p]\n",
static_cast<int>(hasFastBlockStarted),
static_cast<int>(hasFastBlockStopped),
duration.ToMilliseconds(),
this));
return isFastBlocking;
}
nsresult
nsHttpChannel::ConnectOnTailUnblock()
{
@ -781,21 +675,6 @@ nsHttpChannel::ConnectOnTailUnblock()
LOG(("nsHttpChannel::ConnectOnTailUnblock [this=%p]\n", this));
bool isTrackingResource = mIsThirdPartyTrackingResource; // is atomic
if (isTrackingResource) {
bool engageFastBlock = CheckFastBlocked();
AntiTrackingCommon::NotifyBlockingDecision(this,
engageFastBlock ?
AntiTrackingCommon::BlockingDecision::eBlock :
AntiTrackingCommon::BlockingDecision::eAllow,
nsIWebProgressListener::STATE_BLOCKED_SLOW_TRACKING_CONTENT);
if (engageFastBlock) {
Unused << AsyncAbort(NS_ERROR_TRACKING_ANNOTATION_URI);
CloseCacheEntry(false);
return NS_OK;
}
}
// Consider opening a TCP connection right away.
SpeculativeConnect();

View File

@ -688,9 +688,6 @@ private:
// Called on untail when tailed because of being a tracking resource.
nsresult ConnectOnTailUnblock();
// Check if current channel should be canceled by FastBlock rules.
bool CheckFastBlocked();
nsCString mUsername;
// If non-null, warnings should be reported to this object.