Use document's principal for favicons in browser

This commit is contained in:
JustOff 2018-04-14 00:32:14 +03:00 • committed by Roy Tam
commit e05e624eb8
4 changed files with 27 additions and 12 deletions

View file

@ -2849,7 +2849,7 @@ const DOMLinkHandler = {
break; break;
let tab = gBrowser.tabs[browserIndex]; let tab = gBrowser.tabs[browserIndex];
gBrowser.setIcon(tab, uri.spec); gBrowser.setIcon(tab, uri.spec, link.ownerDocument.nodePrincipal);
iconAdded = true; iconAdded = true;
} }
break; break;

View file

@ -778,19 +778,28 @@
<method name="setIcon"> <method name="setIcon">
<parameter name="aTab"/> <parameter name="aTab"/>
<parameter name="aURI"/> <parameter name="aURI"/>
<parameter name="aLoadingPrincipal"/>
<body> <body>
<![CDATA[ <![CDATA[
var browser = this.getBrowserForTab(aTab); let browser = this.getBrowserForTab(aTab);
browser.mIconURL = aURI instanceof Ci.nsIURI ? aURI.spec : aURI; browser.mIconURL = aURI instanceof Ci.nsIURI ? aURI.spec : aURI;
if (aURI && this.mFaviconService) { if (aURI && this.mFaviconService) {
if (!(aURI instanceof Ci.nsIURI)) if (!(aURI instanceof Ci.nsIURI)) {
aURI = makeURI(aURI); aURI = makeURI(aURI);
this.mFaviconService.setAndFetchFaviconForPage(browser.currentURI, }
aURI, false, // We do not serialize the principal from within SessionStore.jsm,
PrivateBrowsingUtils.isWindowPrivate(window) ? // hence if aLoadingPrincipal is null we default to the
this.mFaviconService.FAVICON_LOAD_PRIVATE : // systemPrincipal which will allow the favicon to load.
this.mFaviconService.FAVICON_LOAD_NON_PRIVATE); 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 || ""; let sizedIconUrl = browser.mIconURL || "";
@ -886,7 +895,7 @@
if (!this.isFailedIcon(url)) if (!this.isFailedIcon(url))
icon = url; icon = url;
} }
this.setIcon(aTab, icon); this.setIcon(aTab, icon, browser.contentPrincipal);
]]> ]]>
</body> </body>
</method> </method>
@ -2146,7 +2155,7 @@
// Workarounds for bug 458697 // Workarounds for bug 458697
// Icon might have been set on DOMLinkAdded, don't override that. // Icon might have been set on DOMLinkAdded, don't override that.
if (!ourBrowser.mIconURL && otherBrowser.mIconURL) if (!ourBrowser.mIconURL && otherBrowser.mIconURL)
this.setIcon(aOurTab, otherBrowser.mIconURL); this.setIcon(aOurTab, otherBrowser.mIconURL, otherBrowser.contentPrincipal);
var isBusy = aOtherTab.hasAttribute("busy"); var isBusy = aOtherTab.hasAttribute("busy");
if (isBusy) { if (isBusy) {
aOurTab.setAttribute("busy", "true"); aOurTab.setAttribute("busy", "true");

View file

@ -1395,6 +1395,8 @@ FeedWriter.prototype = {
.QueryInterface(Ci.nsIDocShell) .QueryInterface(Ci.nsIDocShell)
.QueryInterface(Ci.nsILoadContext) .QueryInterface(Ci.nsILoadContext)
.usePrivateBrowsing; .usePrivateBrowsing;
var nullPrincipal = Cc["@mozilla.org/nullprincipal;1"]
.createInstance(Ci.nsIPrincipal);
this._faviconService.setAndFetchFaviconForPage(readerURI, faviconURI, false, this._faviconService.setAndFetchFaviconForPage(readerURI, faviconURI, false,
usePrivateBrowsing ? this._faviconService.FAVICON_LOAD_PRIVATE usePrivateBrowsing ? this._faviconService.FAVICON_LOAD_PRIVATE
: this._faviconService.FAVICON_LOAD_NON_PRIVATE, : this._faviconService.FAVICON_LOAD_NON_PRIVATE,
@ -1409,7 +1411,7 @@ FeedWriter.prototype = {
self._contentSandbox.menuItem = null; self._contentSandbox.menuItem = null;
self._contentSandbox.dataURL = null; self._contentSandbox.dataURL = null;
} }
}); }, nullPrincipal);
}, },
classID: FEEDWRITER_CID, classID: FEEDWRITER_CID,

View file

@ -3131,7 +3131,11 @@ let SessionStoreInternal = {
// Restore the tab icon. // Restore the tab icon.
if ("image" in tabData) { if ("image" in tabData) {
aWindow.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.
aWindow.gBrowser.setIcon(tab, tabData.image, null);
} }
if (tabData.storage && browser.docShell instanceof Ci.nsIDocShell) if (tabData.storage && browser.docShell instanceof Ci.nsIDocShell)