Bug 1383299 - Ensure we start to set up network connection before content process requests. r=mconley

In chrome process, we often know which url is going to be loaded.
As a performance optimization, we can start initiating network
connection before sending out the 'LoadURI' message to the content
process.

MozReview-Commit-ID: L79ylHOaxX8

--HG--
extra : rebase_source : cc3aeefedde21dc8eaaf37c67710980b0204f4dc
This commit is contained in:
Evelyn Hung 2017-08-22 12:00:31 +08:00
Родитель 3fbdb1b349
Коммит 088e2c9eba
1 изменённых файлов: 25 добавлений и 0 удалений

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

@ -13,6 +13,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
"resource://gre/modules/NetUtil.jsm"); "resource://gre/modules/NetUtil.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Utils", XPCOMUtils.defineLazyModuleGetter(this, "Utils",
"resource://gre/modules/sessionstore/Utils.jsm"); "resource://gre/modules/sessionstore/Utils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
"resource://gre/modules/PrivateBrowsingUtils.jsm");
function makeURI(url) { function makeURI(url) {
return Services.io.newURI(url); return Services.io.newURI(url);
@ -72,6 +74,29 @@ RemoteWebNavigation.prototype = {
}, },
loadURIWithOptions(aURI, aLoadFlags, aReferrer, aReferrerPolicy, loadURIWithOptions(aURI, aLoadFlags, aReferrer, aReferrerPolicy,
aPostData, aHeaders, aBaseURI, aTriggeringPrincipal) { aPostData, aHeaders, aBaseURI, aTriggeringPrincipal) {
// We know the url is going to be loaded, let's start requesting network
// connection before the content process asks.
// Note that we might have already setup the speculative connection in some
// cases, especially when the url is from location bar or its popup menu.
if (aURI.startsWith("http")) {
let uri = makeURI(aURI);
let principal = aTriggeringPrincipal;
// We usually have a aTriggeringPrincipal assigned, but in case we don't
// have one, create it with OA inferred from the current context.
if (!principal) {
let attrs = {
userContextId: this._browser.getAttribute("usercontextid") || 0,
privateBrowsingId: PrivateBrowsingUtils.isBrowserPrivate(this._browser) ? 1 : 0
};
principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, attrs);
}
try {
Services.io.speculativeConnect2(uri, principal, null);
} catch (ex) {
// Can't setup speculative connection for this uri string for some
// reason, just ignore it.
}
}
this._sendMessage("WebNavigation:LoadURI", { this._sendMessage("WebNavigation:LoadURI", {
uri: aURI, uri: aURI,
flags: aLoadFlags, flags: aLoadFlags,