Bug 1449523 - ContentLinkHandler only picks perfectly sized icons. r=Mardak

MozReview-Commit-ID: IY5vOIliWWC

--HG--
extra : rebase_source : 125201afee6771d22ed5079e70b966bb0d193f07
This commit is contained in:
Marco Bonardo 2018-03-28 12:40:02 +02:00
Родитель 8369cbcd06
Коммит 57d906ecd0
2 изменённых файлов: 37 добавлений и 1 удалений

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

@ -164,3 +164,28 @@ add_task(async function guess_invalid() {
// Must have at least one test.
Assert.ok(true, "The expected icon has been set");
});
add_task(async function guess_bestSized() {
let preferredWidth = 16 * Math.ceil(window.devicePixelRatio);
let promise = waitIcon(ROOT + "icon3.png");
await createLinks([
{ href: ROOT + "icon.png",
type: "image/png",
size: preferredWidth - 1
},
{ href: ROOT + "icon2.png",
type: "image/png",
},
{ href: ROOT + "icon3.png",
type: "image/png",
size: preferredWidth + 1
},
{ href: ROOT + "icon4.png",
type: "image/png",
size: preferredWidth + 2
},
]);
await promise;
// Must have at least one test.
Assert.ok(true, "The expected icon has been set");
});

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

@ -160,6 +160,7 @@ function faviconTimeoutCallback(aFaviconLoads, aPageUrl, aChromeGlobal) {
let preferredIcon;
let preferredWidth = 16 * Math.ceil(aChromeGlobal.content.devicePixelRatio);
let bestSizedIcon;
// Other links with the "icon" tag are the default icons
let defaultIcon;
// Rich icons are either apple-touch or fluid icons, or the ones of the
@ -178,6 +179,13 @@ function faviconTimeoutCallback(aFaviconLoads, aPageUrl, aChromeGlobal) {
} else if (guessType(icon) == TYPE_ICO && (!preferredIcon || guessType(preferredIcon) == TYPE_ICO)) {
preferredIcon = icon;
}
// Check for an icon larger yet closest to preferredWidth, that can be
// downscaled efficiently.
if (icon.width >= preferredWidth &&
(!bestSizedIcon || bestSizedIcon.width >= icon.width)) {
bestSizedIcon = icon;
}
}
// Note that some sites use hi-res icons without specifying them as
@ -193,7 +201,8 @@ function faviconTimeoutCallback(aFaviconLoads, aPageUrl, aChromeGlobal) {
// Now set the favicons for the page in the following order:
// 1. Set the best rich icon if any.
// 2. Set the preferred one if any, otherwise use the default one.
// 2. Set the preferred one if any, otherwise check if there's a better
// sized fit.
// This order allows smaller icon frames to eventually override rich icon
// frames.
if (largestRichIcon) {
@ -201,6 +210,8 @@ function faviconTimeoutCallback(aFaviconLoads, aPageUrl, aChromeGlobal) {
}
if (preferredIcon) {
setIconForLink(preferredIcon, aChromeGlobal);
} else if (bestSizedIcon) {
setIconForLink(bestSizedIcon, aChromeGlobal);
} else if (defaultIcon) {
setIconForLink(defaultIcon, aChromeGlobal);
}