Bug 1323838 - make allowing popups work better, r=felipe
MozReview-Commit-ID: LnW5QoxQiGK
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -511,17 +511,17 @@ var gPopupBlockerObserver = {
}
},
toggleAllowPopupsForSite: function(aEvent)
{
var pm = Services.perms;
var shouldBlock = aEvent.target.getAttribute("block") == "true";
var perm = shouldBlock ? pm.DENY_ACTION : pm.ALLOW_ACTION;
- pm.add(gBrowser.currentURI, "popup", perm);
+ pm.addFromPrincipal(gBrowser.contentPrincipal, "popup", perm);
if (!shouldBlock)
this.showAllBlockedPopups(gBrowser.selectedBrowser);
gBrowser.getNotificationBox().removeCurrentNotification();
},
fillPopupList: function(aEvent)
@@ -531,32 +531,32 @@ var gPopupBlockerObserver = {
// menuitems for the common subset of hosts present in the report, this will
// make us frame-safe.
//
// XXXjst - Note that when this is fixed to work with multi-framed sites,
// also back out the fix for bug 343772 where
// nsGlobalWindow::CheckOpenAllow() was changed to also
// check if the top window's location is whitelisted.
let browser = gBrowser.selectedBrowser;
- var uri = browser.currentURI;
+ var uri = browser.contentPrincipal.URI || browser.currentURI;
var blockedPopupAllowSite = document.getElementById("blockedPopupAllowSite");
try {
blockedPopupAllowSite.removeAttribute("hidden");
-
+ let uriHost = uri.asciiHost ? uri.host : uri.spec;
var pm = Services.perms;
if (pm.testPermission(uri, "popup") == pm.ALLOW_ACTION) {
// Offer an item to block popups for this site, if a whitelist entry exists
// already for it.
- let blockString = gNavigatorBundle.getFormattedString("popupBlock", [uri.host || uri.spec]);
+ let blockString = gNavigatorBundle.getFormattedString("popupBlock", [uriHost]);
blockedPopupAllowSite.setAttribute("label", blockString);
blockedPopupAllowSite.setAttribute("block", "true");
}
else {
// Offer an item to allow popups for this site
- let allowString = gNavigatorBundle.getFormattedString("popupAllow", [uri.host || uri.spec]);
+ let allowString = gNavigatorBundle.getFormattedString("popupAllow", [uriHost]);
blockedPopupAllowSite.setAttribute("label", allowString);
blockedPopupAllowSite.removeAttribute("block");
}
}
catch (e) {
blockedPopupAllowSite.setAttribute("hidden", "true");
}
@@ -657,27 +657,40 @@ var gPopupBlockerObserver = {
if (popups[i].popupWindowURIspec)
aBrowser.unblockPopup(i);
}
}, null);
},
editPopupSettings: function()
{
- var host = "";
+ let prefillValue = "";
try {
- host = gBrowser.currentURI.host;
+ // We use contentPrincipal rather than currentURI to get the right
+ // value in case this is a data: URI that's inherited off something else.
+ // Some principals don't have URIs, so fall back in case URI is not present.
+ let principalURI = gBrowser.contentPrincipal.URI || gBrowser.currentURI;
+ if (principalURI) {
+ // asciiHost conveniently doesn't throw.
+ if (principalURI.asciiHost) {
+ prefillValue = principalURI.prePath;
+ } else {
+ // For host-less URIs like file://, prePath would effectively allow
+ // popups everywhere on file://. Use the full spec:
+ prefillValue = principalURI.spec;
+ }
+ }
}
catch (e) { }
var bundlePreferences = document.getElementById("bundle_preferences");
var params = { blockVisible : false,
sessionVisible : false,
allowVisible : true,
- prefilledHost : host,
+ prefilledHost : prefillValue,
permissionType : "popup",
windowTitle : bundlePreferences.getString("popuppermissionstitle"),
introText : bundlePreferences.getString("popuppermissionstext") };
var existingWindow = Services.wm.getMostRecentWindow("Browser:Permissions");
if (existingWindow) {
existingWindow.initWithParams(params);
existingWindow.focus();
}