Bug 728142 - Replace old synchronous favicons calls in tabview. r=ttaubert

--HG--
extra : rebase_source : 5dc2e1a50862eaa238cd16479dada60da507eb01
This commit is contained in:
Paolo Amadini 2012-04-12 12:27:27 +02:00
Родитель 1bb5c0078e
Коммит a4e2da87ad
2 изменённых файлов: 30 добавлений и 14 удалений

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

@ -1,6 +1,12 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* This file tests that, when there is an app tab that references an invalid
* favicon, the default favicon appears the group app tab tray, instead of an
* empty image that would not be visible.
*/
const fi = Cc["@mozilla.org/browser/favicon-service;1"]. const fi = Cc["@mozilla.org/browser/favicon-service;1"].
getService(Ci.nsIFaviconService); getService(Ci.nsIFaviconService);
@ -40,18 +46,20 @@ function onTabPinned() {
// code. // code.
executeSoon(function() { executeSoon(function() {
let iconSrc = $icon.attr("src"); let iconSrc = $icon.attr("src");
let hasData = true;
try {
fi.getFaviconDataAsDataURL(iconSrc);
} catch(e) {
hasData = false;
}
ok(!hasData, "The icon src doesn't return any data");
// with moz-anno:favicon automatically redirects to the default favIcon // with moz-anno:favicon automatically redirects to the default favIcon
// if the given url is invalid // if the given url is invalid
ok(/^moz-anno:favicon:/.test(iconSrc), ok(/^moz-anno:favicon:/.test(iconSrc),
"The icon url starts with moz-anno:favicon so the default fav icon would be displayed"); "The icon url starts with moz-anno:favicon so the default fav icon would be displayed");
// At this point, as an additional integrity check we could also verify
// that the iconSrc URI does not have any associated favicon data. This
// kind of check, however, is not easily supported by the asynchronous
// favicon API. Fortunately, the fact that we received the error event
// already indicates that the original favicon was not available.
// Morevover, since we are using a "moz-anno:favicon:" URI, we know that
// we'll not display an empty icon, but the default favicon.
// clean up // clean up
gBrowser.removeTab(newTab); gBrowser.removeTab(newTab);
let endGame = function() { let endGame = function() {

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

@ -1695,7 +1695,7 @@ let UI = {
// ---------- // ----------
// Function: getFavIconUrlForTab // Function: getFavIconUrlForTab
// Gets fav icon url for the given xul:tab. // Gets the "favicon link URI" for the given xul:tab, or null if unavailable.
getFavIconUrlForTab: function UI_getFavIconUrlForTab(tab, callback) { getFavIconUrlForTab: function UI_getFavIconUrlForTab(tab, callback) {
this._isImageDocument(tab, function(isImageDoc) { this._isImageDocument(tab, function(isImageDoc) {
if (isImageDoc) { if (isImageDoc) {
@ -1709,12 +1709,20 @@ let UI = {
callback(tabImage); callback(tabImage);
} else { } else {
// determine to load the default/cached icon or not and also ensure we don't show the default icon // ensure we don't show the default icon for about:-style error pages
// for about:-style error pages if (!this._shouldLoadFavIcon(tab)) {
let url = null; callback(null);
if (this._shouldLoadFavIcon(tab)) } else {
url = gFavIconService.getFaviconImageForPage(tab.linkedBrowser.currentURI).spec; // determine to load the default/cached icon or not
callback(url); gFavIconService.getFaviconURLForPage(tab.linkedBrowser.currentURI,
function (uri) {
if (!uri) {
callback(gFavIconService.defaultFavicon.spec);
} else {
callback(gFavIconService.getFaviconLinkForIcon(uri).spec);
}
});
}
} }
} }
}.bind(this)); }.bind(this));