Bug 399265 - Use the favicon service's hash table instead of cache to store failed favicons. r/a=mconnor

git-svn-id: svn://10.0.0.236/trunk@237512 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rflint%ryanflint.com
2007-10-10 05:03:52 +00:00
parent 5cc81cc411
commit c14cfa5f8a
3 changed files with 36 additions and 74 deletions

View File

@@ -2663,18 +2663,14 @@ const DOMLinkHandler = {
if (!gPrefService.getBoolPref("browser.chrome.site_icons"))
break;
try {
var contentPolicy = Cc["@mozilla.org/layout/content-policy;1"].
getService(Ci.nsIContentPolicy);
} catch(e) {
break; // Refuse to load if we can't do a security check.
}
var targetDoc = link.ownerDocument;
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var uri = ios.newURI(link.href, targetDoc.characterSet, null);
if (gBrowser.isFailedIcon(uri))
break;
// Verify that the load of this icon is legal.
// error pages can load their favicon, to be on the safe side,
// only allow chrome:// favicons
@@ -2691,6 +2687,13 @@ const DOMLinkHandler = {
}
}
try {
var contentPolicy = Cc["@mozilla.org/layout/content-policy;1"].
getService(Ci.nsIContentPolicy);
} catch(e) {
break; // Refuse to load if we can't do a security check.
}
// Security says okay, now ask content policy
if (contentPolicy.shouldLoad(Ci.nsIContentPolicy.TYPE_IMAGE,
uri, targetDoc.documentURIObject,
@@ -3301,22 +3304,9 @@ nsBrowserStatusHandler.prototype =
onLinkIconAvailable : function(aBrowser)
{
if (gProxyFavIcon &&
gBrowser.mCurrentBrowser == aBrowser &&
if (gProxyFavIcon && gBrowser.mCurrentBrowser == aBrowser &&
gBrowser.userTypedValue === null)
{
// update the favicon in the URL bar
PageProxySetIcon(aBrowser.mIconURL);
}
// Save this favicon in the favicon service
if (aBrowser.mIconURL) {
var faviconService = Components.classes["@mozilla.org/browser/favicon-service;1"]
.getService(Components.interfaces.nsIFaviconService);
var uri = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService).newURI(aBrowser.mIconURL, null, null);
faviconService.setAndLoadFaviconForPage(aBrowser.currentURI, uri, false);
}
PageProxySetIcon(aBrowser.mIconURL); // update the favicon in the URL bar
},
onProgressChange : function (aWebProgress, aRequest,

View File

@@ -241,8 +241,7 @@
ondraggesture="PageProxyDragGesture(event);"
onload="this.parentNode.selectedIndex = 1;
event.stopPropagation();"
onerror="gBrowser.addToMissedIconCache(this.src);
this.removeAttribute('src');
onerror="this.removeAttribute('src');
this.parentNode.selectedIndex = 0;"
tooltiptext="&proxyIcon.tooltip;"/>
</deck>

View File

@@ -119,8 +119,7 @@
node = node.parentNode;
node.removeCurrentTab();">
<xul:tab selected="true" validate="never"
onerror="this.parentNode.parentNode.parentNode.parentNode.addToMissedIconCache(this.getAttribute('image'));
this.removeAttribute('image');"
onerror="this.removeAttribute('image');"
maxwidth="250" width="0" minwidth="100" flex="100"
class="tabbrowser-tab" label="&untitledTab;" crop="end"/>
</xul:tabs>
@@ -144,6 +143,10 @@
Components.classes["@mozilla.org/docshell/urifixup;1"]
.getService(Components.interfaces.nsIURIFixup);
</field>
<field name="mFaviconService" readonly="true">
Components.classes["@mozilla.org/browser/favicon-service;1"]
.getService(Components.interfaces.nsIFaviconService);
</field>
<field name="mTabBox" readonly="true">
document.getAnonymousElementByAttribute(this, "anonid", "tabbox");
</field>
@@ -189,9 +192,6 @@
<field name="mIsBusy">
false
</field>
<field name="mMissedIconCache">
null
</field>
<field name="mContextTab">
null
</field>
@@ -493,6 +493,16 @@
var browser = this.getBrowserForTab(aTab);
browser.mIconURL = aURI;
if (aURI) {
if (!(aURI instanceof Components.interfaces.nsIURI)) {
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
aURI = ios.newURI(aURI, null, null);
}
this.mFaviconService.setAndLoadFaviconForPage(browser.currentURI,
aURI, false);
}
this.updateIcon(aTab);
for (var i = 0; i < this.mProgressListeners.length; i++) {
@@ -552,61 +562,24 @@
}
else if (this.shouldLoadFavIcon(browser.currentURI)) {
var url = browser.currentURI.prePath + "/favicon.ico";
if (!this.isIconKnownMissing(url))
if (!this.isFailedIcon(url))
this.setIcon(aTab, url);
}
]]>
</body>
</method>
<method name="addToMissedIconCache">
<method name="isFailedIcon">
<parameter name="aURI"/>
<body>
<![CDATA[
var entry = this.openCacheEntry(aURI, Components.interfaces.nsICache.ACCESS_READ_WRITE);
if (!entry)
return;
if (entry.accessGranted == Components.interfaces.nsICache.ACCESS_WRITE)
// It's a new entry. Just write a bit of metadata in to the entry.
entry.setMetaDataElement("Icon", "Missed");
entry.markValid();
entry.close();
]]>
</body>
</method>
<method name="openCacheEntry">
<parameter name="key"/>
<parameter name="access"/>
<body>
<![CDATA[
try {
if (!this.mMissedIconCache) {
var cacheService = Components.classes['@mozilla.org/network/cache-service;1'].getService(Components.interfaces.nsICacheService);
this.mMissedIconCache = cacheService.createSession("MissedIconCache", Components.interfaces.nsICache.STORE_ANYWHERE, true);
if (!this.mMissedIconCache)
return null;
}
return this.mMissedIconCache.openCacheEntry(key, access, true);
if (!(aURI instanceof Components.interfaces.nsIURI)) {
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
aURI = ios.newURI(aURI, null, null);
}
catch (e) {
return null;
}
]]>
</body>
</method>
<method name="isIconKnownMissing">
<parameter name="key"/>
<body>
<![CDATA[
var e = this.openCacheEntry(key, Components.interfaces.nsICache.ACCESS_READ);
if (e) {
e.close();
return true;
}
return false;
return this.mFaviconService.isFailedFavicon(aURI);
]]>
</body>
</method>
@@ -1132,7 +1105,7 @@
t.width = 0;
t.setAttribute("flex", "100");
t.setAttribute("validate", "never");
t.setAttribute("onerror", "this.parentNode.parentNode.parentNode.parentNode.addToMissedIconCache(this.getAttribute('image')); this.removeAttribute('image');");
t.setAttribute("onerror", "this.removeAttribute('image');");
t.className = "tabbrowser-tab";
this.mTabContainer.appendChild(t);