Bug 715263 - Browser should use the favicon size optimized for device resolution. r=mfinkle

This commit is contained in:
Margaret Leibovic 2012-05-29 14:10:48 -07:00
Родитель 9b3cfd79f4
Коммит 4bd01d4f2f
3 изменённых файлов: 65 добавлений и 28 удалений

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

@ -653,8 +653,7 @@ abstract public class GeckoApp
}
tab.setContentType(contentType);
tab.updateFavicon(null);
tab.updateFaviconURL(null);
tab.clearFavicon();
tab.updateIdentityData(null);
tab.removeTransientDoorHangers();
tab.setAllowZoom(true);
@ -850,8 +849,9 @@ abstract public class GeckoApp
final int tabId = message.getInt("tabID");
final String rel = message.getString("rel");
final String href = message.getString("href");
Log.i(LOGTAG, "link rel - " + rel + ", href - " + href);
handleLinkAdded(tabId, rel, href);
final int size = message.getInt("size");
Log.i(LOGTAG, "link rel - " + rel + ", href - " + href + ", size - " + size);
handleLinkAdded(tabId, rel, href, size);
} else if (event.equals("DOMWindowClose")) {
final int tabId = message.getInt("tabID");
handleWindowClose(tabId);
@ -1321,24 +1321,26 @@ abstract public class GeckoApp
});
}
void handleLinkAdded(final int tabId, String rel, final String href) {
if (rel.indexOf("[icon]") != -1) {
final Tab tab = Tabs.getInstance().getTab(tabId);
if (tab != null) {
tab.updateFaviconURL(href);
void handleLinkAdded(final int tabId, String rel, final String href, int size) {
if (rel.indexOf("[icon]") == -1)
return;
// If tab is not loading and the favicon is updated, we
// want to load the image straight away. If tab is still
// loading, we only load the favicon once the page's content
// is fully loaded (see handleContentLoaded()).
if (tab.getState() != Tab.STATE_LOADING) {
mMainHandler.post(new Runnable() {
public void run() {
loadFavicon(tab);
}
});
final Tab tab = Tabs.getInstance().getTab(tabId);
if (tab == null)
return;
tab.updateFaviconURL(href, size);
// If tab is not loading and the favicon is updated, we
// want to load the image straight away. If tab is still
// loading, we only load the favicon once the page's content
// is fully loaded (see handleContentLoaded()).
if (tab.getState() != Tab.STATE_LOADING) {
mMainHandler.post(new Runnable() {
public void run() {
loadFavicon(tab);
}
}
});
}
}

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

@ -41,6 +41,7 @@ public final class Tab {
private String mTitle;
private Drawable mFavicon;
private String mFaviconUrl;
private int mFaviconSize;
private JSONObject mIdentityData;
private Drawable mThumbnail;
private int mHistoryIndex;
@ -77,6 +78,7 @@ public final class Tab {
mTitle = title;
mFavicon = null;
mFaviconUrl = null;
mFaviconSize = 0;
mIdentityData = null;
mThumbnail = null;
mHistoryIndex = -1;
@ -306,9 +308,24 @@ public final class Tab {
Log.i(LOGTAG, "Updated favicon for tab with id: " + mId);
}
public void updateFaviconURL(String faviconUrl) {
mFaviconUrl = faviconUrl;
Log.i(LOGTAG, "Updated favicon URL for tab with id: " + mId);
public void updateFaviconURL(String faviconUrl, int size) {
// If we already have an "any" sized icon, don't update the icon.
if (mFaviconSize == -1)
return;
// Only update the favicon if it's bigger than the current favicon.
// We use -1 to represent icons with sizes="any".
if (size == -1 || size > mFaviconSize) {
mFaviconUrl = faviconUrl;
mFaviconSize = size;
Log.i(LOGTAG, "Updated favicon URL for tab with id: " + mId);
}
}
public void clearFavicon() {
mFavicon = null;
mFaviconUrl = null;
mFaviconSize = 0;
}

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

@ -2015,19 +2015,37 @@ Tab.prototype = {
list.push("[" + rel + "]");
}
// We want to get the largest icon size possible for our UI.
let maxSize = 0;
// We use the sizes attribute if available
// see http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-icon
if (target.hasAttribute("sizes")) {
let sizes = target.getAttribute("sizes").toLowerCase();
if (sizes == "any") {
// Since Java expects an integer, use -1 to represent icons with sizes="any"
maxSize = -1;
} else {
let tokens = sizes.split(" ");
tokens.forEach(function(token) {
// TODO: check for invalid tokens
let [w, h] = token.split("x");
maxSize = Math.max(maxSize, Math.max(w, h));
});
}
}
let json = {
type: "DOMLinkAdded",
tabID: this.id,
href: resolveGeckoURI(target.href),
charset: target.ownerDocument.characterSet,
title: target.title,
rel: list.join(" ")
rel: list.join(" "),
size: maxSize
};
// rel=icon can also have a sizes attribute
if (target.hasAttribute("sizes"))
json.sizes = target.getAttribute("sizes");
sendMessageToJava({ gecko: json });
break;
}