зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1472475: Properly clear the current favicon when navigating to a new URL. r=mak
In practice this is an easy fix, just clear the icon when the page first changes to a new URL. In practice that breaks our hack for setting an early favicon for certain in-content pages so we have to workaround that somewhat. Differential Revision: https://phabricator.services.mozilla.com/D1909 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
acb2be40d6
Коммит
f713e07b96
|
@ -5,6 +5,17 @@
|
|||
|
||||
/* eslint-env mozilla/browser-window */
|
||||
|
||||
/**
|
||||
* A set of known icons to use for internal pages. These are hardcoded so we can
|
||||
* start loading them faster than ContentLinkHandler would normally find them.
|
||||
*/
|
||||
const FAVICON_DEFAULTS = {
|
||||
"about:newtab": "chrome://branding/content/icon32.png",
|
||||
"about:home": "chrome://branding/content/icon32.png",
|
||||
"about:welcome": "chrome://branding/content/icon32.png",
|
||||
"about:privatebrowsing": "chrome://browser/skin/privatebrowsing/favicon.svg",
|
||||
};
|
||||
|
||||
window._gBrowser = {
|
||||
init() {
|
||||
ChromeUtils.defineModuleGetter(this, "AsyncTabSwitcher",
|
||||
|
@ -2399,10 +2410,8 @@ 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 == "about:newtab" || aURI == "about:home" || aURI == "about:welcome") {
|
||||
this.setIcon(t, "chrome://branding/content/icon32.png");
|
||||
} else if (aURI == "about:privatebrowsing") {
|
||||
this.setIcon(t, "chrome://browser/skin/privatebrowsing/favicon.svg");
|
||||
if (aURI in FAVICON_DEFAULTS) {
|
||||
this.setIcon(t, FAVICON_DEFAULTS[aURI]);
|
||||
}
|
||||
|
||||
// Dispatch a new tab notification. We do this once we're
|
||||
|
@ -4554,6 +4563,16 @@ class TabProgressListener {
|
|||
}
|
||||
}
|
||||
|
||||
// If we don't already have an icon for this tab then clear the tab's
|
||||
// icon. Don't do this on the initial about:blank load to prevent
|
||||
// flickering. Don't clear the icon if we already set it from one of the
|
||||
// known defaults. Note we use the original URL since about:newtab
|
||||
// redirects to a prerendered page.
|
||||
if (!this.mBrowser.mIconURL && !ignoreBlank &&
|
||||
!(originalLocation.spec in FAVICON_DEFAULTS)) {
|
||||
this.mTab.removeAttribute("image");
|
||||
}
|
||||
|
||||
// For keyword URIs clear the user typed value since they will be changed into real URIs
|
||||
if (location.scheme == "keyword")
|
||||
this.mBrowser.userTypedValue = null;
|
||||
|
@ -4653,6 +4672,8 @@ class TabProgressListener {
|
|||
if (!this.mTab.hasAttribute("pending") &&
|
||||
aWebProgress.isLoadingDocument &&
|
||||
!isSameDocument) {
|
||||
// Removing the tab's image here causes flickering, wait until the load
|
||||
// is complete.
|
||||
this.mBrowser.mIconURL = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
</html>
|
|
@ -40,6 +40,9 @@ support-files =
|
|||
file_bug970276_popup1.html
|
||||
file_bug970276_popup2.html
|
||||
file_bug970276_favicon2.ico
|
||||
[browser_missing_favicon.js]
|
||||
support-files =
|
||||
blank.html
|
||||
[browser_redirect.js]
|
||||
support-files =
|
||||
file_favicon_redirect.html
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
add_task(async () => {
|
||||
let testPath = getRootDirectory(gTestPath);
|
||||
|
||||
// The default favicon would interfere with this test.
|
||||
Services.prefs.setBoolPref("browser.chrome.guess_favicon", false);
|
||||
registerCleanupFunction(() => {
|
||||
Services.prefs.setBoolPref("browser.chrome.guess_favicon", true);
|
||||
});
|
||||
|
||||
await BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" }, async (browser) => {
|
||||
const expectedIcon = testPath + "file_generic_favicon.ico";
|
||||
let faviconPromise = waitForLinkAvailable(browser);
|
||||
|
||||
BrowserTestUtils.loadURI(browser, testPath + "file_with_favicon.html");
|
||||
|
||||
let iconURI = await faviconPromise;
|
||||
is(iconURI, expectedIcon, "Got correct icon.");
|
||||
|
||||
BrowserTestUtils.loadURI(browser, testPath + "blank.html");
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
|
||||
is(browser.mIconURL, null, "Should have blanked the icon.");
|
||||
is(gBrowser.getTabForBrowser(browser).getAttribute("image"), "", "Should have blanked the tab icon.");
|
||||
});
|
||||
});
|
Загрузка…
Ссылка в новой задаче