Bug 1395525 - Make all changes landed as part of tracker request tailing preferrable. r=dragana

This commit is contained in:
Honza Bambas 2017-08-31 06:07:00 -04:00
Родитель 9084ce73bb
Коммит 8d492fe637
8 изменённых файлов: 48 добавлений и 23 удалений

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

@ -304,6 +304,7 @@ bool nsContentUtils::sGetBoxQuadsEnabled = false;
bool nsContentUtils::sSkipCursorMoveForSameValueSet = false;
bool nsContentUtils::sRequestIdleCallbackEnabled = false;
bool nsContentUtils::sLowerNetworkPriority = false;
bool nsContentUtils::sTailingEnabled = false;
bool nsContentUtils::sShowInputPlaceholderOnFocus = true;
bool nsContentUtils::sAutoFocusEnabled = true;
#ifndef RELEASE_OR_BETA
@ -768,6 +769,9 @@ nsContentUtils::Init()
Preferences::AddBoolVarCache(&sLowerNetworkPriority,
"privacy.trackingprotection.lower_network_priority", false);
Preferences::AddBoolVarCache(&sTailingEnabled,
"network.http.tailing.enabled", true);
Preferences::AddBoolVarCache(&sShowInputPlaceholderOnFocus,
"dom.placeholder.show_on_focus", true);

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

@ -3093,6 +3093,9 @@ public:
// if we want to lower the priority of the channel.
static bool IsLowerNetworkPriority() { return sLowerNetworkPriority; }
// Whether tracker tailing is turned on - "network.http.tailing.enabled".
static bool IsTailingEnabled() { return sTailingEnabled; }
// Check pref "dom.placeholder.show_on_focus" to see
// if we want to show the placeholder inside input elements
// when they have focus.
@ -3284,6 +3287,7 @@ private:
static bool sSkipCursorMoveForSameValueSet;
static bool sRequestIdleCallbackEnabled;
static bool sLowerNetworkPriority;
static bool sTailingEnabled;
static bool sShowInputPlaceholderOnFocus;
static bool sAutoFocusEnabled;
#ifndef RELEASE_OR_BETA

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

@ -378,10 +378,12 @@ FetchDriver::HttpFetch()
}
}
if (mIsTrackingFetch && nsContentUtils::IsLowerNetworkPriority()) {
if (mIsTrackingFetch && nsContentUtils::IsTailingEnabled()) {
cos->AddClassFlags(nsIClassOfService::Throttleable |
nsIClassOfService::Tail);
}
if (mIsTrackingFetch && nsContentUtils::IsLowerNetworkPriority()) {
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(chan);
if (p) {
p->SetPriority(nsISupportsPriority::PRIORITY_LOWEST);

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

@ -1067,7 +1067,12 @@ ScriptLoader::StartLoad(ScriptLoadRequest* aRequest)
// synchronous head scripts block loading of most other non js/css
// content such as images, Leader implicitely disallows tailing
cos->AddClassFlags(nsIClassOfService::Leader);
} else if (defer && !async) {
} else if (defer && (!async || !nsContentUtils::IsTailingEnabled())) {
// Bug 1395525 and the !nsContentUtils::IsTailingEnabled() bit:
// We want to make sure that turing tailing off by the pref makes
// the browser behave exactly the same way as before landing
// the tailing patch, which has added the "&& !async" part.
// head/body deferred scripts are blocked by leaders but are not
// allowed tailing because they block DOMContentLoaded
cos->AddClassFlags(nsIClassOfService::TailForbidden);

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

@ -2621,13 +2621,15 @@ XMLHttpRequestMainThread::MaybeLowerChannelPriority()
return;
}
nsCOMPtr<nsIClassOfService> cos = do_QueryInterface(mChannel);
if (cos) {
// Adding TailAllowed to overrule the Unblocked flag, but to preserve
// the effect of Unblocked when tailing is off.
cos->AddClassFlags(nsIClassOfService::Throttleable |
nsIClassOfService::Tail |
nsIClassOfService::TailAllowed);
if (nsContentUtils::IsTailingEnabled()) {
nsCOMPtr<nsIClassOfService> cos = do_QueryInterface(mChannel);
if (cos) {
// Adding TailAllowed to overrule the Unblocked flag, but to preserve
// the effect of Unblocked when tailing is off.
cos->AddClassFlags(nsIClassOfService::Throttleable |
nsIClassOfService::Tail |
nsIClassOfService::TailAllowed);
}
}
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(mChannel);

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

@ -210,16 +210,23 @@ LowerPriorityHelper(nsIChannel* aChannel)
nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(aChannel));
if (cos) {
uint32_t cosFlags = 0;
cos->GetClassFlags(&cosFlags);
isBlockingResource = cosFlags & (nsIClassOfService::UrgentStart |
nsIClassOfService::Leader |
nsIClassOfService::Unblocked);
if (nsContentUtils::IsTailingEnabled()) {
uint32_t cosFlags = 0;
cos->GetClassFlags(&cosFlags);
isBlockingResource = cosFlags & (nsIClassOfService::UrgentStart |
nsIClassOfService::Leader |
nsIClassOfService::Unblocked);
// Requests not allowed to be tailed are usually those with higher
// prioritization. That overweights being a tracker: don't throttle
// them when not in background.
if (!(cosFlags & nsIClassOfService::TailForbidden)) {
cos->AddClassFlags(nsIClassOfService::Throttleable);
}
} else {
// Yes, we even don't want to evaluate the isBlockingResource when tailing is off
// see bug 1395525.
// Requests not allowed to be tailed are usually those with higher
// prioritization. That overweights being a tracker: don't throttle
// them when not in background.
if (!(cosFlags & nsIClassOfService::TailForbidden)) {
cos->AddClassFlags(nsIClassOfService::Throttleable);
}
}

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

@ -7576,7 +7576,6 @@ nsHttpChannel::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult st
"We should not call OnStopRequest twice");
mListener->OnStopRequest(this, mListenerContext, status);
mOnStopRequestCalled = true;
}
RemoveAsNonTailRequest();

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

@ -594,10 +594,12 @@ AsyncFetchAndSetIconForPage::FetchFromNetwork() {
priorityChannel->AdjustPriority(nsISupportsPriority::PRIORITY_LOWEST);
}
nsCOMPtr<nsIClassOfService> cos = do_QueryInterface(channel);
if (cos) {
cos->AddClassFlags(nsIClassOfService::Tail |
nsIClassOfService::Throttleable);
if (nsContentUtils::IsTailingEnabled()) {
nsCOMPtr<nsIClassOfService> cos = do_QueryInterface(channel);
if (cos) {
cos->AddClassFlags(nsIClassOfService::Tail |
nsIClassOfService::Throttleable);
}
}
rv = channel->AsyncOpen2(this);