Bug 1472212 - Ensure that tab does not show busy or burst status whenever we navigate to about:home, about:newtab, or about:welcome in a new window. r=Gijs

Now that we have moved some about: pages to the privileged content process,
opening these URLs from a non-privileged content process will trigger SessionStore
to restore the tab state due to a process flip. We will set favicons for these
URLs earlier to avoid flickering and improve perceived performance.

This patch also prevents the spinner whenever a page with a local about: URI
(about:blank and about: pages that resolve to jar:// or file:// URIs) is
loaded from a process that the URI cannot load in (e.g. loading about:newtab
in the web content process), as well as during tab duplication or session
restoration for such local about: URIs.

Before this patch, there were additional frames when opening a new window, causing
browser/base/content/test/performance/browser_windowopen.js to fail. This patch
will reduce the number of frames when opening a new window.

MozReview-Commit-ID: yjj2964KSz

--HG--
extra : rebase_source : a5588b5b6496c983350f591602d0959f906235d5
extra : intermediate-source : 176f3ee14e67f493bafefbd599fbf0fe194a25a6
extra : source : cecc2d52e72e7c6e61137a9147735cb07a079d51
This commit is contained in:
Jay Lim 2018-07-20 16:43:12 -04:00
parent 0c4aac09cd
commit 6fe4aee23e
4 changed files with 51 additions and 15 deletions

View File

@ -710,7 +710,7 @@ window._gBrowser = {
/**
* Determine if a URI is an about: page pointing to a local resource.
*/
_isLocalAboutURI(aURI, aResolvedURI) {
isLocalAboutURI(aURI, aResolvedURI) {
if (!aURI.schemeIs("about")) {
return false;
}
@ -737,6 +737,15 @@ window._gBrowser = {
}
},
/**
* Sets an icon for the tab if the URI is defined in FAVICON_DEFAULTS.
*/
setDefaultIcon(aTab, aURI) {
if (aURI && aURI.spec in FAVICON_DEFAULTS) {
this.setIcon(aTab, FAVICON_DEFAULTS[aURI.spec]);
}
},
setIcon(aTab, aIconURL = "", aOriginalURL = aIconURL, aLoadingPrincipal = null) {
let makeString = (url) => url instanceof Ci.nsIURI ? url.spec : url;
@ -2505,9 +2514,7 @@ window._gBrowser = {
// Hack to ensure that the about:newtab, and about:welcome favicon is loaded
// instantaneously, to avoid flickering and improve perceived performance.
if (aURI in FAVICON_DEFAULTS) {
this.setIcon(t, FAVICON_DEFAULTS[aURI]);
}
this.setDefaultIcon(t, aURIObject);
// Dispatch a new tab notification. We do this once we're
// entirely done, so that things are in a consistent state
@ -4816,7 +4823,7 @@ class TabProgressListener {
// Don't show progress indicators in tabs for about: URIs
// pointing to local resources.
if ((aRequest instanceof Ci.nsIChannel) &&
gBrowser._isLocalAboutURI(aRequest.originalURI, aRequest.URI)) {
gBrowser.isLocalAboutURI(aRequest.originalURI, aRequest.URI)) {
return false;
}

View File

@ -4,7 +4,7 @@
"use strict";
/**
* Unit tests for tabbrowser._isLocalAboutURI to make sure it returns the
* Unit tests for tabbrowser.isLocalAboutURI to make sure it returns the
* appropriate values for various URIs as well as optional resolved URI.
*/
@ -12,9 +12,9 @@ add_task(function test_URI() {
const check = (spec, expect, description) => {
const URI = Services.io.newURI(spec);
try {
is(gBrowser._isLocalAboutURI(URI), expect, description);
is(gBrowser.isLocalAboutURI(URI), expect, description);
} catch (ex) {
ok(false, "_isLocalAboutURI should not throw");
ok(false, "isLocalAboutURI should not throw");
}
};
check("https://www.mozilla.org/", false, "https is not about");
@ -30,7 +30,7 @@ add_task(function test_URI_with_resolved() {
const check = (spec, resolvedSpec, expect, description) => {
const URI = Services.io.newURI(spec);
const resolvedURI = Services.io.newURI(resolvedSpec);
is(gBrowser._isLocalAboutURI(URI, resolvedURI), expect, description);
is(gBrowser.isLocalAboutURI(URI, resolvedURI), expect, description);
};
check("about:newtab",
"jar:file:///Applications/Firefox.app/Contents/Resources/browser/omni.ja!/chrome/browser/res/activity-stream/prerendered/en-US/activity-stream.html",

View File

@ -2436,8 +2436,17 @@ var SessionStoreInternal = {
let newTab = aWindow.gBrowser.addTrustedTab(null, tabOptions);
// Start the throbber to pretend we're doing something while actually
// waiting for data from the frame script.
newTab.setAttribute("busy", "true");
// waiting for data from the frame script. This throbber is disabled
// if the URI is a local about: URI.
let uriObj = aTab.linkedBrowser.currentURI;
if (!uriObj || (uriObj && !aWindow.gBrowser.isLocalAboutURI(uriObj))) {
newTab.setAttribute("busy", "true");
}
// Hack to ensure that the about:home, about:newtab, and about:welcome
// favicon is loaded instantaneously, to avoid flickering and improve
// perceived performance.
aWindow.gBrowser.setDefaultIcon(newTab, uriObj);
// Collect state before flushing.
let tabState = TabState.collect(aTab, TAB_CUSTOM_VALUES.get(aTab));
@ -2774,7 +2783,14 @@ var SessionStoreInternal = {
// Restore the tab icon.
if ("image" in tabData) {
win.gBrowser.setIcon(tab, tabData.image, undefined, tabData.iconLoadingPrincipal);
// We know that about:blank is safe to load in any remote type. Since
// SessionStore is triggered with about:blank, there must be a process
// flip. We will ignore the first about:blank load to prevent resetting the
// favicon that we have set earlier to avoid flickering and improve
// perceived performance.
if (!activePageData || (activePageData && activePageData.url != "about:blank")) {
win.gBrowser.setIcon(tab, tabData.image, undefined, tabData.iconLoadingPrincipal);
}
TabStateCache.update(browser, { image: null, iconLoadingPrincipal: null });
}
},
@ -3014,9 +3030,22 @@ var SessionStoreInternal = {
return;
}
let uriObj;
try {
uriObj = Services.io.newURI(loadArguments.uri);
} catch (e) {}
// Start the throbber to pretend we're doing something while actually
// waiting for data from the frame script.
tab.setAttribute("busy", "true");
// waiting for data from the frame script. This throbber is disabled
// if the URI is a local about: URI.
if (!uriObj || (uriObj && !window.gBrowser.isLocalAboutURI(uriObj))) {
tab.setAttribute("busy", "true");
}
// Hack to ensure that the about:home, about:newtab, and about:welcome
// favicon is loaded instantaneously, to avoid flickering and improve
// perceived performance.
window.gBrowser.setDefaultIcon(tab, uriObj);
// Flush to get the latest tab state.
TabStateFlusher.flush(browser).then(() => {

View File

@ -353,7 +353,7 @@ class AsyncTabSwitcher {
// determined by the busy state on the tab element and checking
// if the loaded URI is local.
let hasSufficientlyLoaded = !this.requestedTab.hasAttribute("busy") &&
!this.tabbrowser._isLocalAboutURI(requestedBrowser.currentURI);
!this.tabbrowser.isLocalAboutURI(requestedBrowser.currentURI);
let fl = requestedBrowser.frameLoader;
shouldBeBlank = !this.minimizedOrFullyOccluded &&