зеркало из https://github.com/mozilla/gecko-dev.git
Bug 874533 - Part 1: Speculative connect when users hover mouse on a tab or when restoring tabs automatically. r=mikedeboer
MozReview-Commit-ID: aJUyM4z3Nh --HG-- extra : rebase_source : 028e8c05ff1dc6285d9391525e6bee60919cbfe2
This commit is contained in:
Родитель
9c3a2bab1d
Коммит
1914bb6831
|
@ -3279,8 +3279,8 @@ var SessionStoreInternal = {
|
|||
}
|
||||
}
|
||||
|
||||
let restoreTabsLazily = this._prefBranch.getBoolPref("sessionstore.restore_tabs_lazily") &&
|
||||
this._prefBranch.getBoolPref("sessionstore.restore_on_demand");
|
||||
let restoreOnDemand = this._prefBranch.getBoolPref("sessionstore.restore_on_demand");
|
||||
let restoreTabsLazily = this._prefBranch.getBoolPref("sessionstore.restore_tabs_lazily") && restoreOnDemand;
|
||||
|
||||
for (var t = 0; t < newTabCount; t++) {
|
||||
let tabData = winData.tabs[t];
|
||||
|
@ -3333,6 +3333,13 @@ var SessionStoreInternal = {
|
|||
tabbrowser.selectedTab = tab;
|
||||
tabbrowser.removeTab(leftoverTab);
|
||||
}
|
||||
|
||||
// Prepare connection to the host when users hover mouse over this
|
||||
// tab. If we're not restoring on demand, we'll prepare connection
|
||||
// when we're restoring next tab.
|
||||
if (!tabData.pinned && restoreOnDemand) {
|
||||
this.speculativeConnectOnTabHover(tab, url);
|
||||
}
|
||||
}
|
||||
|
||||
tabs.push(tab);
|
||||
|
@ -3417,6 +3424,42 @@ var SessionStoreInternal = {
|
|||
this._sendRestoreCompletedNotifications();
|
||||
},
|
||||
|
||||
/**
|
||||
* Prepare connection to host beforehand.
|
||||
*
|
||||
* @param url
|
||||
* URL of a host.
|
||||
* @returns a flag indicates whether a connection has been made
|
||||
*/
|
||||
prepareConnectionToHost(url) {
|
||||
if (!url.startsWith("about:")) {
|
||||
let sc = Services.io.QueryInterface(Ci.nsISpeculativeConnect);
|
||||
let uri = Services.io.newURI(url);
|
||||
sc.speculativeConnect(uri, null, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Make a connection to a host when users hover mouse on a tab.
|
||||
*
|
||||
* @param tab
|
||||
* A tab to set up a hover listener.
|
||||
* @param url
|
||||
* URL of a host.
|
||||
*/
|
||||
speculativeConnectOnTabHover(tab, url) {
|
||||
tab.addEventListener("mouseover", () => {
|
||||
let prepared = this.prepareConnectionToHost(url);
|
||||
// This is used to test if a connection has been made beforehand.
|
||||
if (gDebuggingEnabled) {
|
||||
tab.__test_connection_prepared = prepared;
|
||||
tab.__test_connection_url = url;
|
||||
}
|
||||
}, {once: true});
|
||||
},
|
||||
|
||||
/**
|
||||
* Restore multiple windows using the provided state.
|
||||
* @param aWindow
|
||||
|
@ -3683,6 +3726,19 @@ var SessionStoreInternal = {
|
|||
this.restoreTabContent(tab, options);
|
||||
} else if (!forceOnDemand) {
|
||||
TabRestoreQueue.add(tab);
|
||||
// Check if a tab is in queue and will be restored
|
||||
// after the currently loading tabs. If so, prepare
|
||||
// a connection to host to speed up page loading.
|
||||
if (TabRestoreQueue.willRestoreSoon(tab)) {
|
||||
if (activeIndex in tabData.entries) {
|
||||
let url = tabData.entries[activeIndex].url;
|
||||
let prepared = this.prepareConnectionToHost(url);
|
||||
if (gDebuggingEnabled) {
|
||||
tab.__test_connection_prepared = prepared;
|
||||
tab.__test_connection_url = url;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.restoreNextTab();
|
||||
}
|
||||
} else {
|
||||
|
|
Загрузка…
Ссылка в новой задаче