35 var popupBlocker = {};
36 popupBlocker.init_once = 0;
37 popupBlocker.deinit_once = 0;
38 popupBlocker.onLoad =
function()
40 if (popupBlocker.init_once++) {
41 dump(
"WARNING: popupBlocker double init!!\n");
44 if (typeof gBrowser ==
'undefined') {
49 popupBlocker.onUnload =
function()
51 if (popupBlocker.deinit_once++) {
52 dump(
"WARNING: popupBlocker double deinit!!\n");
55 window.removeEventListener(
"load", popupBlocker.onLoad,
false);
56 window.removeEventListener(
"unload", popupBlocker.onUnload,
false);
57 if (typeof gBrowser ==
'undefined') {
64 window.addEventListener(
"load", popupBlocker.onLoad,
false);
65 window.addEventListener(
"unload", popupBlocker.onUnload,
false);
69 _kIPM: Components.interfaces.nsIPermissionManager,
72 _blockedPopupAllowSite:
null,
73 _blockedPopupEditSettings:
null,
74 _blockedPopupDontShowMessage:
null,
75 _blockedPopupSeparator:
null,
76 _blockedPopupMenu:
null,
79 _brandingStrings:
null,
80 _browserStrings:
null,
84 this._sbs = Components.classes[
"@mozilla.org/intl/stringbundle;1"]
85 .getService(Components.interfaces.nsIStringBundleService);
86 this._brandingStrings = this._sbs.createBundle(
87 "chrome://branding/locale/brand.properties");
88 this._browserStrings = this._sbs.createBundle(
89 "chrome://browser/locale/browser.properties");
90 this._prefStrings = this._sbs.createBundle(
91 "chrome://browser/locale/preferences/preferences.properties");
93 this._prefService = Components.classes[
"@mozilla.org/preferences-service;1"]
94 .getService(Components.interfaces.nsIPrefBranch);
95 gBrowser.addEventListener(
"DOMUpdatePageReport", gPopupBlockerObserver.onUpdatePageReport,
false);
100 gBrowser.removeEventListener(
"DOMUpdatePageReport", gPopupBlockerObserver.onUpdatePageReport,
false);
104 onUpdatePageReport:
function() {
105 if (!gPopupBlockerObserver._reportButton) {
106 gPopupBlockerObserver._reportButton = document.getElementById(
"page-report-button");
108 if (gBrowser.selectedBrowser.pageReport) {
109 gPopupBlockerObserver._reportButton.setAttribute(
"blocked",
"true");
110 gPopupBlockerObserver.showNotification();
112 gPopupBlockerObserver._reportButton.removeAttribute(
"blocked");
116 getElements:
function(
menu) {
117 this._blockedPopupAllowSite =
menu.getElementsByAttribute(
"sbid",
"blockedPopupAllowSite")[0];
118 this._blockedPopupEditSettings =
menu.getElementsByAttribute(
"sbid",
"blockedPopupEditSettings")[0];
119 this._blockedPopupDontShowMessage =
menu.getElementsByAttribute(
"sbid",
"blockedPopupDontShowMessage")[0];
120 this._blockedPopupSeparator =
menu.getElementsByAttribute(
"sbid",
"blockedPopupSeparator")[0];
123 showNotification:
function() {
124 if (this._prefService.getBoolPref(
"privacy.popups.showBrowserMessage")) {
125 var pageReport = gBrowser.selectedBrowser.pageReport;
126 var popupCount = pageReport.length;
128 var brandShortName =
"Songbird";
130 brandShortName = this._brandingStrings.GetStringFromName(
"brandShortName");
135 message =
"%S prevented this site from opening %S popup windows.";
137 message =
"%S prevented this site from opening a popup window.";
140 message = this._browserStrings.GetStringFromName(
"popupWarningMultiple");
142 message = this._browserStrings.GetStringFromName(
"popupWarning");
144 message = message.replace(
"%S", brandShortName);
145 if (popupCount > 1) message = message.replace(
"%S", popupCount);
147 var notificationName =
"popup-blocked";
148 var iconURL =
"chrome://songbird/skin/notification-bar/icon-blocked-popup.png";
149 var optionsLabel, optionsAccessKey;
150 optionsLabel =
"Options";
151 optionsAccessKey =
"O";
153 optionsLabel = this._browserStrings.getString(
"popupWarningButton");
157 this._browserStrings.getString(
"popupWarningButton.accesskey");
163 accessKey: optionsAccessKey,
164 popup:
"blockedPopupOptions",
169 var
browser = gBrowser.selectedBrowser;
170 var notificationBox = browser.parentNode;
171 const priority = notificationBox.PRIORITY_WARNING_MEDIUM;
172 gBrowser.showNotification(browser,
181 fillPopupList:
function(aEvent) {
182 this.getElements(aEvent.target);
184 var
uri = gBrowser.selectedBrowser.webNavigation.currentURI;
186 this._blockedPopupAllowSite.hidden =
false;
187 var pm = Components.classes[
"@mozilla.org/permissionmanager;1"]
188 .getService(this._kIPM);
189 if (pm.testPermission(uri,
"popup") == this._kIPM.ALLOW_ACTION) {
192 var blockString = this._browserStrings.GetStringFromName(
"popupBlock").replace(
"%S", uri.host);
193 this._blockedPopupAllowSite.setAttribute(
"label", blockString);
194 this._blockedPopupAllowSite.setAttribute(
"block",
"true");
198 var allowString = this._browserStrings.GetStringFromName(
"popupAllow").replace(
"%S", uri.host);
199 this._blockedPopupAllowSite.setAttribute(
"label", allowString);
200 this._blockedPopupAllowSite.removeAttribute(
"block");
204 this._blockedPopupAllowSite.hidden =
true;
207 while (aEvent.target.lastChild !=
this._blockedPopupSeparator)
208 aEvent.target.removeChild(aEvent.target.lastChild);
210 var pageReport = gBrowser.selectedBrowser.pageReport;
211 if (pageReport && pageReport.length > 0) {
212 this._blockedPopupSeparator.hidden =
false;
213 for (var
i = 0;
i < pageReport.length; ++
i) {
214 var popupURIspec = pageReport[
i].popupWindowURI.spec;
215 if (popupURIspec ==
"" || popupURIspec ==
"about:blank" ||
216 popupURIspec == uri.spec)
219 var menuitem = document.createElement(
"menuitem");
220 menuitem.setAttribute(
"sbtype",
"popupBlockerItem");
221 var
label = this._browserStrings.GetStringFromName(
"popupShowPopupPrefix")
222 .replace(
"%S", popupURIspec);
223 menuitem.setAttribute(
"label", label);
224 menuitem.requestingWindow = pageReport[
i].requestingWindow;
225 menuitem.requestingDocument = pageReport[
i].requestingDocument;
226 menuitem.setAttribute(
"popupWindowURI", popupURIspec);
227 menuitem.setAttribute(
"popupWindowFeatures", pageReport[
i].popupWindowFeatures);
228 menuitem.setAttribute(
"oncommand",
"gPopupBlockerObserver.showBlockedPopup(event);");
229 aEvent.target.appendChild(menuitem);
233 this._blockedPopupSeparator.hidden =
true;
236 var showMessage =
true;
238 showMessage = this._prefService.getBoolPref(
"privacy.popups.showBrowserMessage");
241 this._blockedPopupDontShowMessage.setAttribute(
"checked", !showMessage);
242 if (aEvent.target.localName ==
"popup") {
243 this._blockedPopupDontShowMessage.setAttribute(
"label",
244 this._browserStrings.GetStringFromName(
"popupWarningDontShowFromMessage"));
246 this._blockedPopupDontShowMessage.setAttribute(
"label",
247 this._browserStrings.GetStringFromName(
"popupWarningDontShowFromStatusbar"));
251 showBlockedPopup:
function(
event) {
252 var
target =
event.target;
253 var popupWindowURI = target.getAttribute(
"popupWindowURI");
254 var features = target.getAttribute(
"popupWindowFeatures");
255 var
name = target.getAttribute(
"popupWindowName");
257 var dwi = target.requestingWindow;
261 if (dwi && dwi.document == target.requestingDocument) {
262 dwi.open(popupWindowURI, name, features);
266 editPopupSettings:
function () {
269 var uri = gBrowser.selectedBrowser.webNavigation.currentURI;
274 var params = { blockVisible :
false,
275 sessionVisible :
false,
277 prefilledHost : host,
278 permissionType :
"popup",
279 windowTitle : this._prefStrings.GetStringFromName(
"popuppermissionstitle"),
280 introText : this._prefStrings.GetStringFromName(
"popuppermissionstext") };
281 var
wm = Components.classes[
"@mozilla.org/appshell/window-mediator;1"]
282 .getService(Components.interfaces.nsIWindowMediator);
283 var existingWindow = wm.getMostRecentWindow(
"Browser:Permissions");
284 if (existingWindow) {
285 existingWindow.initWithParams(params);
286 existingWindow.focus();
289 window.openDialog(
"chrome://browser/content/preferences/permissions.xul",
290 "_blank",
"resizable,dialog=no,centerscreen", params);
293 dontShowMessage:
function () {
294 var showMessage =
true;
296 showMessage = this._prefService.
301 firstTime = this._prefService.
308 if (showMessage && firstTime) {
309 window.openDialog(
"chrome://browser/content/pageReportFirstTime.xul",
"_blank",
313 this._prefService.setBoolPref(
"privacy.popups.showBrowserMessage", !showMessage);
315 var
browser = gBrowser.selectedBrowser;
316 var notificationBox = browser.parentNode;
317 var notification = notificationBox.getNotificationWithValue(
"popup-blocked");
319 notification.close();
322 toggleAllowPopupsForSite:
function(
event) {
323 var currentURI = gBrowser.selectedBrowser.webNavigation.currentURI;
324 var pm = Components.classes[
"@mozilla.org/permissionmanager;1"]
325 .getService(this._kIPM);
326 var shouldBlock =
event.target.getAttribute(
"block") ==
"true";
327 var perm = shouldBlock ? this._kIPM.DENY_ACTION : this._kIPM.ALLOW_ACTION;
328 pm.add(currentURI,
"popup", perm);
330 var browser = gBrowser.selectedBrowser;
331 var notificationBox = browser.parentNode;
332 var notification = notificationBox.getNotificationWithValue(
"popup-blocked");
334 notification.close();
340 dump(
"popupBlocker.js - " + err);
function getBoolPref(prefname, def)
sbDownloadDeviceServicePaneModule prototype shutdown
this _contentSandbox label
const gPopupBlockerObserver
_getSelectedPageStyle s i