зеркало из https://github.com/mozilla/pjs.git
Add popup blocker UI. b=436057 r=mfinkle
This commit is contained in:
Родитель
374ee06e42
Коммит
d2158575fe
|
@ -38,6 +38,7 @@
|
|||
|
||||
pref("toolkit.defaultChromeURI", "chrome://browser/content/browser.xul");
|
||||
pref("general.useragent.extra.mobile", "@APP_UA_NAME@/@APP_VERSION@");
|
||||
pref("browser.chromeURL", "chrome://browser/content/");
|
||||
|
||||
pref("browser.startup.homepage", "http://www.mozilla.org/");
|
||||
pref("browser.ui.cursor", false);
|
||||
|
@ -124,4 +125,8 @@ pref("browser.display.use_focus_colors", true);
|
|||
pref("browser.display.focus_background_color", "#ffffa0");
|
||||
pref("browser.display.focus_text_color", "#00000");
|
||||
|
||||
/* block popups by default, and notify the user about blocked popups */
|
||||
pref("dom.disable_open_during_load", true);
|
||||
pref("privacy.popups.showBrowserMessage", true);
|
||||
|
||||
pref("snav.enabled", true);
|
||||
|
|
|
@ -45,6 +45,14 @@ const Cu = Components.utils;
|
|||
|
||||
Cu.import("resource://gre/modules/SpatialNavigation.js");
|
||||
|
||||
// create a lazy-initialized handle for the pref service on the global object
|
||||
// in the style of bug 385809
|
||||
__defineGetter__("gPrefService", function () {
|
||||
delete gPrefService;
|
||||
return gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch2);
|
||||
});
|
||||
|
||||
function getBrowser() {
|
||||
return Browser.content.browser;
|
||||
}
|
||||
|
@ -83,7 +91,7 @@ var Browser = {
|
|||
|
||||
this._content = document.getElementById("content");
|
||||
this._content.addEventListener("DOMTitleChanged", this, true);
|
||||
|
||||
this._content.addEventListener("DOMUpdatePageReport", gPopupBlockerObserver.onUpdatePageReport, false);
|
||||
BrowserUI.init();
|
||||
|
||||
this._progressController = new ProgressController(this.content);
|
||||
|
@ -128,6 +136,14 @@ var Browser = {
|
|||
return this._content;
|
||||
},
|
||||
|
||||
/**
|
||||
* Return the currently active <browser> object, since a <deckbrowser> may
|
||||
* have more than one
|
||||
*/
|
||||
get currentBrowser() {
|
||||
return this._content.browser;
|
||||
},
|
||||
|
||||
handleEvent: function (aEvent) {
|
||||
switch (aEvent.type) {
|
||||
case "DOMTitleChanged":
|
||||
|
@ -251,10 +267,39 @@ ProgressController.prototype = {
|
|||
},
|
||||
|
||||
// This method is called to indicate a change to the current location.
|
||||
onLocationChange : function(aWebProgress, aRequest, aLocation) {
|
||||
onLocationChange : function(aWebProgress, aRequest, aLocationURI) {
|
||||
|
||||
var location = aLocationURI ? aLocationURI.spec : "";
|
||||
this._hostChanged = true;
|
||||
|
||||
// This code here does not compare uris exactly when determining
|
||||
// whether or not the message(s) should be hidden since the message
|
||||
// may be prematurely hidden when an install is invoked by a click
|
||||
// on a link that looks like this:
|
||||
//
|
||||
// <a href="#" onclick="return install();">Install Foo</a>
|
||||
//
|
||||
// - which fires a onLocationChange message to uri + '#'...
|
||||
cBrowser = Browser.currentBrowser;
|
||||
if (cBrowser.lastURI) {
|
||||
var oldSpec = cBrowser.lastURI.spec;
|
||||
var oldIndexOfHash = oldSpec.indexOf("#");
|
||||
if (oldIndexOfHash != -1)
|
||||
oldSpec = oldSpec.substr(0, oldIndexOfHash);
|
||||
var newSpec = location;
|
||||
var newIndexOfHash = newSpec.indexOf("#");
|
||||
if (newIndexOfHash != -1)
|
||||
newSpec = newSpec.substr(0, newSpec.indexOf("#"));
|
||||
if (newSpec != oldSpec) {
|
||||
// Remove all the notifications, except for those which want to
|
||||
// persist across the first location change.
|
||||
var nBox = Browser.getNotificationBox();
|
||||
nBox.removeTransientNotifications();
|
||||
}
|
||||
}
|
||||
cBrowser.lastURI = aLocationURI;
|
||||
|
||||
|
||||
if (aWebProgress.DOMWindow == this._browser.contentWindow) {
|
||||
BrowserUI.setURI();
|
||||
this._tabbrowser.updateCanvasState(true);
|
||||
|
@ -614,3 +659,84 @@ function getIdentityHandler() {
|
|||
gIdentityHandler = new IdentityHandler();
|
||||
return gIdentityHandler;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handler for blocked popups, triggered by DOMUpdatePageReport events in browser.xml
|
||||
*/
|
||||
const gPopupBlockerObserver = {
|
||||
_kIPM: Components.interfaces.nsIPermissionManager,
|
||||
|
||||
onUpdatePageReport: function (aEvent)
|
||||
{
|
||||
var cBrowser = Browser.currentBrowser;
|
||||
if (aEvent.originalTarget != cBrowser)
|
||||
return;
|
||||
|
||||
if (!cBrowser.pageReport)
|
||||
return;
|
||||
|
||||
// Only show the notification again if we've not already shown it. Since
|
||||
// notifications are per-browser, we don't need to worry about re-adding
|
||||
// it.
|
||||
if (!cBrowser.pageReport.reported) {
|
||||
if(gPrefService.getBoolPref("privacy.popups.showBrowserMessage")) {
|
||||
var bundle_browser = document.getElementById("bundle_browser");
|
||||
var brandBundle = document.getElementById("bundle_brand");
|
||||
var brandShortName = brandBundle.getString("brandShortName");
|
||||
var message;
|
||||
var popupCount = cBrowser.pageReport.length;
|
||||
|
||||
if (popupCount > 1)
|
||||
message = bundle_browser.getFormattedString("popupWarningMultiple", [brandShortName, popupCount]);
|
||||
else
|
||||
message = bundle_browser.getFormattedString("popupWarning", [brandShortName]);
|
||||
|
||||
var notificationBox = Browser.getNotificationBox();
|
||||
var notification = notificationBox.getNotificationWithValue("popup-blocked");
|
||||
if (notification) {
|
||||
notification.label = message;
|
||||
}
|
||||
else {
|
||||
var buttons = [
|
||||
{
|
||||
label: bundle_browser.getString("popupButtonAlwaysAllow"),
|
||||
accessKey: bundle_browser.getString("popupButtonAlwaysAllow.accesskey"),
|
||||
callback: function() { gPopupBlockerObserver.toggleAllowPopupsForSite(); }
|
||||
},
|
||||
{
|
||||
label: bundle_browser.getString("popupButtonNeverWarn"),
|
||||
accessKey: bundle_browser.getString("popupButtonNeverWarn.accesskey"),
|
||||
callback: function() { gPopupBlockerObserver.dontShowMessage(); }
|
||||
}
|
||||
];
|
||||
|
||||
const priority = notificationBox.PRIORITY_WARNING_MEDIUM;
|
||||
notificationBox.appendNotification(message, "popup-blocked",
|
||||
"",
|
||||
priority, buttons);
|
||||
}
|
||||
}
|
||||
// Record the fact that we've reported this blocked popup, so we don't
|
||||
// show it again.
|
||||
cBrowser.pageReport.reported = true;
|
||||
}
|
||||
},
|
||||
|
||||
toggleAllowPopupsForSite: function (aEvent)
|
||||
{
|
||||
var currentURI = Browser.currentBrowser.webNavigation.currentURI;
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(this._kIPM);
|
||||
pm.add(currentURI, "popup", this._kIPM.ALLOW_ACTION);
|
||||
|
||||
Browser.getNotificationBox().removeCurrentNotification();
|
||||
},
|
||||
|
||||
dontShowMessage: function ()
|
||||
{
|
||||
var showMessage = gPrefService.getBoolPref("privacy.popups.showBrowserMessage");
|
||||
gPrefService.setBoolPref("privacy.popups.showBrowserMessage", !showMessage);
|
||||
Browser.getNotificationBox().removeCurrentNotification();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
|
||||
<stringbundleset id="stringbundleset">
|
||||
<stringbundle id="bundle_browser" src="chrome://browser/locale/browser.properties"/>
|
||||
<stringbundle id="bundle_brand" src="chrome://branding/locale/brand.properties"/>
|
||||
</stringbundleset>
|
||||
|
||||
<commandset id="cmdset_main">
|
||||
|
|
|
@ -1,11 +1,18 @@
|
|||
# Popup Blocker
|
||||
popupWarning=%S prevented this site from opening a pop-up window.
|
||||
popupWarningMultiple=%S prevented this site from opening %S pop-up windows.
|
||||
popupButtonAlwaysAllow=Always Allow
|
||||
popupButtonAlwaysAllow.accesskey=A
|
||||
popupButtonNeverWarn=Never tell me
|
||||
popupButtonNeverWarn.accesskey=N
|
||||
|
||||
|
||||
# Site Identity
|
||||
identity.identified.verifier=Verified by: %S
|
||||
identity.identified.verified_by_you=You have added a security exception for this site
|
||||
identity.identified.state_and_country=%S, %S
|
||||
identity.identified.title_with_country=%S (%S)
|
||||
|
||||
identity.encrypted=Your connection to this web site is encrypted to prevent eavesdropping.
|
||||
identity.unencrypted=Your connection to this web site is not encrypted.
|
||||
|
||||
identity.unknown.tooltip=This web site does not supply identity information.
|
||||
|
||||
identity.ownerUnknown2=(unknown)
|
||||
|
|
Загрузка…
Ссылка в новой задаче