Bug 1337672 - Part 1: Reduce the priority of prefetch network requests. r?mayhemer
Reduce the priority of <link rel="prefetch"> network requests from PRIORITY_NORMAL to PRIORITY_LOWEST, the same as favicons. These prefetch requests are already deferred until the browser is idle using nsIWebProgressListener, but we can also adjust the network request priority to reflect their lower importance.
https://developer.mozilla.org/docs/Web/HTTP/Link_prefetching_FAQ#How_is_browser_idle_time_determined.3F
MozReview-Commit-ID: 2PjGRGOgKUU
--- a/uriloader/prefetch/nsPrefetchService.cpp
+++ b/uriloader/prefetch/nsPrefetchService.cpp
@@ -9,16 +9,17 @@
#include "nsICategoryManager.h"
#include "nsIObserverService.h"
#include "nsIWebProgress.h"
#include "nsCURILoader.h"
#include "nsICacheInfoChannel.h"
#include "nsIHttpChannel.h"
#include "nsIURL.h"
#include "nsISimpleEnumerator.h"
+#include "nsISupportsPriority.h"
#include "nsNetUtil.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsStreamUtils.h"
#include "nsAutoPtr.h"
#include "prtime.h"
#include "mozilla/Logging.h"
@@ -151,16 +152,22 @@ nsPrefetchNode::OpenChannel()
if (httpChannel) {
httpChannel->SetReferrerWithPolicy(mReferrerURI, referrerPolicy);
httpChannel->SetRequestHeader(
NS_LITERAL_CSTRING("X-Moz"),
NS_LITERAL_CSTRING("prefetch"),
false);
}
+ // Reduce the priority of prefetch network requests.
+ nsCOMPtr<nsISupportsPriority> priorityChannel = do_QueryInterface(mChannel);
+ if (priorityChannel) {
+ priorityChannel->AdjustPriority(nsISupportsPriority::PRIORITY_LOWEST);
+ }
+
rv = mChannel->AsyncOpen2(this);
if (NS_WARN_IF(NS_FAILED(rv))) {
// Drop the ref to the channel, because we don't want to end up with
// cycles through it.
mChannel = nullptr;
}
return rv;
}