Skip to content

Commit

Permalink
Bug 1119386 - Part 3: Use document's principal for favicons in browse…
Browse files Browse the repository at this point in the history
…r (r=billm)
  • Loading branch information
Christoph Kerschbaumer committed Nov 24, 2015
1 parent 3c326a3 commit b0f3027
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 19 deletions.
6 changes: 3 additions & 3 deletions browser/base/content/browser.js
Expand Up @@ -3418,7 +3418,7 @@ const DOMLinkHandler = {
break;

case "Link:SetIcon":
return this.setIcon(aMsg.target, aMsg.data.url);
return this.setIcon(aMsg.target, aMsg.data.url, aMsg.data.loadingPrincipal);
break;

case "Link:AddSearch":
Expand All @@ -3427,15 +3427,15 @@ const DOMLinkHandler = {
}
},

setIcon: function(aBrowser, aURL) {
setIcon: function(aBrowser, aURL, aLoadingPrincipal) {
if (gBrowser.isFailedIcon(aURL))
return false;

let tab = gBrowser.getTabForBrowser(aBrowser);
if (!tab)
return false;

gBrowser.setIcon(tab, aURL);
gBrowser.setIcon(tab, aURL, aLoadingPrincipal);
return true;
},

Expand Down
29 changes: 19 additions & 10 deletions browser/base/content/tabbrowser.xml
Expand Up @@ -856,19 +856,28 @@
<method name="setIcon">
<parameter name="aTab"/>
<parameter name="aURI"/>
<parameter name="aLoadingPrincipal"/>
<body>
<![CDATA[
var browser = this.getBrowserForTab(aTab);
let browser = this.getBrowserForTab(aTab);
browser.mIconURL = aURI instanceof Ci.nsIURI ? aURI.spec : aURI;
if (aURI && this.mFaviconService) {
if (!(aURI instanceof Ci.nsIURI))
if (!(aURI instanceof Ci.nsIURI)) {
aURI = makeURI(aURI);
this.mFaviconService.setAndFetchFaviconForPage(browser.currentURI,
aURI, false,
PrivateBrowsingUtils.isWindowPrivate(window) ?
this.mFaviconService.FAVICON_LOAD_PRIVATE :
this.mFaviconService.FAVICON_LOAD_NON_PRIVATE);
}
// We do not serialize the principal from within SessionStore.jsm,
// hence if aLoadingPrincipal is null we default to the
// systemPrincipal which will allow the favicon to load.
let loadingPrincipal = aLoadingPrincipal
? aLoadingPrincipal
: Services.scriptSecurityManager.getSystemPrincipal();
let loadType = PrivateBrowsingUtils.isWindowPrivate(window)
? this.mFaviconService.FAVICON_LOAD_PRIVATE
: this.mFaviconService.FAVICON_LOAD_NON_PRIVATE;
this.mFaviconService.setAndFetchFaviconForPage(
browser.currentURI, aURI, false, loadType, null, loadingPrincipal);
}
let sizedIconUrl = browser.mIconURL || "";
Expand Down Expand Up @@ -932,7 +941,7 @@
if (!this.isFailedIcon(url))
icon = url;
}
this.setIcon(aTab, icon);
this.setIcon(aTab, icon, browser.contentPrincipal);
]]>
</body>
</method>
Expand Down Expand Up @@ -2522,7 +2531,7 @@
// Workarounds for bug 458697
// Icon might have been set on DOMLinkAdded, don't override that.
if (!ourBrowser.mIconURL && otherBrowser.mIconURL)
this.setIcon(aOurTab, otherBrowser.mIconURL);
this.setIcon(aOurTab, otherBrowser.mIconURL, otherBrowser.contentPrincipal);
var isBusy = aOtherTab.hasAttribute("busy");
if (isBusy) {
aOurTab.setAttribute("busy", "true");
Expand Down Expand Up @@ -4444,7 +4453,7 @@
}
tab.removeAttribute("soundplaying");
this.setIcon(tab, icon);
this.setIcon(tab, icon, browser.contentPrincipal);
]]>
</handler>
<handler event="DOMAudioPlaybackStarted">
Expand Down
3 changes: 2 additions & 1 deletion browser/base/content/test/general/browser_bug477014.js
Expand Up @@ -10,7 +10,8 @@ add_task(function*() {
let tabToDetach = gBrowser.addTab(testPage);
yield waitForDocLoadComplete(tabToDetach.linkedBrowser);

gBrowser.setIcon(tabToDetach, iconURLSpec);
gBrowser.setIcon(tabToDetach, iconURLSpec,
Services.scriptSecurityManager.getSystemPrincipal());
tabToDetach.setAttribute("busy", "true");

// detach and set the listener on the new window
Expand Down
3 changes: 2 additions & 1 deletion browser/base/content/test/general/browser_discovery.js
Expand Up @@ -52,7 +52,8 @@ function runIconDiscoveryTest() {
function iconDiscovery() {
if (iconDiscoveryTests.length) {
setHandlerFunc(runIconDiscoveryTest);
gBrowser.setIcon(gBrowser.selectedTab, null);
gBrowser.setIcon(gBrowser.selectedTab, null,
Services.scriptSecurityManager.getSystemPrincipal());

var test = iconDiscoveryTests[0];
var head = doc().getElementById("linkparent");
Expand Down
4 changes: 3 additions & 1 deletion browser/components/feeds/FeedWriter.js
Expand Up @@ -1303,6 +1303,8 @@ FeedWriter.prototype = {
.QueryInterface(Ci.nsIDocShell)
.QueryInterface(Ci.nsILoadContext)
.usePrivateBrowsing;
var nullPrincipal = Cc["@mozilla.org/nullprincipal;1"]
.createInstance(Ci.nsIPrincipal);
this._faviconService.setAndFetchFaviconForPage(readerURI, faviconURI, false,
usePrivateBrowsing ? this._faviconService.FAVICON_LOAD_PRIVATE
: this._faviconService.FAVICON_LOAD_NON_PRIVATE,
Expand All @@ -1312,7 +1314,7 @@ FeedWriter.prototype = {
btoa(String.fromCharCode.apply(null, aData));
aMenuItem.setAttribute('image', dataURL);
}
});
}, nullPrincipal);
},

get _mm() {
Expand Down
6 changes: 5 additions & 1 deletion browser/components/sessionstore/SessionStore.jsm
Expand Up @@ -784,7 +784,11 @@ var SessionStoreInternal = {

// Restore the tab icon.
if ("image" in tabData) {
win.gBrowser.setIcon(tab, tabData.image);
// Using null as the loadingPrincipal because serializing
// the principal would be overkill. Within SetIcon we
// default to the systemPrincipal if aLoadingPrincipal is
// null which will allow the favicon to load.
win.gBrowser.setIcon(tab, tabData.image, null);
TabStateCache.update(browser, {image: null});
}

Expand Down
4 changes: 3 additions & 1 deletion browser/modules/ContentLinkHandler.jsm
Expand Up @@ -108,7 +108,9 @@ this.ContentLinkHandler = {
}
sizeHistogramTypes.add(sizesType);

[iconAdded] = chromeGlobal.sendSyncMessage("Link:SetIcon", {url: uri.spec});
[iconAdded] = chromeGlobal.sendSyncMessage(
"Link:SetIcon",
{url: uri.spec, loadingPrincipal: link.ownerDocument.nodePrincipal});
}
break;
case "search":
Expand Down
3 changes: 2 additions & 1 deletion extensions/cookie/test/browser_test_favicon.js
Expand Up @@ -23,5 +23,6 @@ function test() {
}, "cookie-rejected", false);

// kick off a favicon load
gBrowser.setIcon(gBrowser.selectedTab, "http://example.org/tests/extensions/cookie/test/damonbowling.jpg");
gBrowser.setIcon(gBrowser.selectedTab, "http://example.org/tests/extensions/cookie/test/damonbowling.jpg",
Services.scriptSecurityManager.getSystemPrincipal());
}

0 comments on commit b0f3027

Please sign in to comment.