Bug 1008585 Fix popup blocker fallout from bug 933462 r=Ratty a=Ratty
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Mon, 09 Jun 2014 15:54:41 +0100
changeset 19999 e83fae600a28b856159927a707ce4bc55542bbf4
parent 19998 9539a7c8a0bfa6be14e38c5fe8708005e6197b16
child 20000 275585d6b51ab73ed629c87045acce9307c5f13e
push id1151
push usermbanner@mozilla.com
push dateMon, 09 Jun 2014 22:14:36 +0000
treeherdercomm-beta@ce127428ad7d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersRatty, Ratty
bugs1008585, 933462
Bug 1008585 Fix popup blocker fallout from bug 933462 r=Ratty a=Ratty
suite/common/bindings/notification.xml
suite/common/utilityOverlay.js
--- a/suite/common/bindings/notification.xml
+++ b/suite/common/bindings/notification.xml
@@ -2091,44 +2091,28 @@
                           .offline = false;
             }, true);
         ]]>
       </handler>
 
       <handler event="DOMUpdatePageReport" phase="capturing">
         <![CDATA[
           var browser = this.activeBrowser;
-          if (!browser.pageReport)
+          if (!browser.blockedPopups)
             return;
 
-          // this.popupCount can be 0, while browser.pageReport has not been cleared.
-          if (!this.popupCount && browser.pageReport.length > 1) {
-            this.popupCount = browser.pageReport.length;
+          // this.popupCount can be 0, while browser.blockedPopups has not been cleared.
+          if (!this.popupCount && browser.blockedPopups.length > 1) {
+            this.popupCount = browser.blockedPopups.length;
           } else {
             this.popupCount++;
           }
           this.playSoundForBlockedPopup();
           this.notifyPopupCountChanged();
 
-          // Check for duplicates and remove the old occurence of this url,
-          // to update the features.
-          var lastItemPlace = browser.pageReport.length - 1;
-          var lastItem = browser.pageReport[lastItemPlace];
-          for (var i = 0; i < lastItemPlace; i++) {
-            if (browser.pageReport[i].popupWindowURI.equals(lastItem.popupWindowURI)) {
-              browser.pageReport.splice(i, 1);
-              break;
-            }
-          }
-
-          // Limit the length of the menu to some reasonable size.
-          // We only add one item every time in browser.xml, so no need for more complex stuff.
-          if (browser.pageReport.length > 100)
-            browser.pageReport.shift();
-
           var tmp = {};
           Components.utils.import("resource://gre/modules/PluralForm.jsm", tmp);
           if (this._prefs.getBoolPref("privacy.popups.showBrowserMessage"))
           {
             var brandShortName = this._brandStringBundle.GetStringFromName("brandShortName");
             var message = this._stringBundle.GetStringFromName("popupWarning.message");
             message = tmp.PluralForm.get(this.popupCount, message)
                                     .replace("#1", brandShortName)
--- a/suite/common/utilityOverlay.js
+++ b/suite/common/utilityOverlay.js
@@ -1224,51 +1224,56 @@ function popupNotificationMenuShowing(ev
   }
 
   var separator = document.getElementById("popupNotificationMenuSeparator");
   separator.hidden = !createShowPopupsMenu(event.target, notificationbox.activeBrowser);
 }
 
 function RemovePopupsItems(parent)
 {
-  while (parent.lastChild && ("popup" in parent.lastChild))
+  while (parent.lastChild && parent.lastChild.hasAttribute("popupReportIndex"))
     parent.lastChild.remove();
 }
 
 function createShowPopupsMenu(parent, browser)
 {
   if (!browser)
     return false;
 
-  var popups = browser.pageReport;
+  var popups = browser.blockedPopups;
 
   if (!popups)
     return false;
 
+  parent.browser = browser;
+
   for (var i = 0; i < popups.length; i++) {
-    var popup = popups[i];
-    var menuitem = document.createElement("menuitem");
-    var str = gUtilityBundle.getFormattedString("popupMenuShow",
-                                                [popup.popupWindowURI.spec]);
-    menuitem.setAttribute("label", str);
-    menuitem.popup = popup;
+    // popupWindowURI will be null if a file input was blocked.
+    var URI = popups[i].popupWindowURI;
+    if (!URI)
+      continue;
+
+    var str = gUtilityBundle.getFormattedString("popupMenuShow", [URI]);
+    // Check for duplicates and reuse the old menuitem.
+    var menuitem = parent.getElementsByAttribute("label", str).item(0);
+    if (!menuitem) {
+      menuitem = document.createElement("menuitem");
+      menuitem.setAttribute("label", str);
+    }
+    menuitem.setAttribute("popupReportIndex", i);
     parent.appendChild(menuitem);
   }
 
-  return true;
+  return parent.getElementsByAttribute("popupReportIndex", "*").item(0) != null;
 }
 
 function popupBlockerMenuCommand(target)
 {
-  if (!("popup" in target))
-    return;
-  var popup = target.popup;
-  var reqWin = popup.requestingWindow;
-  if (reqWin.document == popup.requestingDocument)
-    reqWin.open(popup.popupWindowURI.spec, popup.popupWindowName, popup.popupWindowFeatures);
+  if (target.hasAttribute("popupReportIndex"))
+    target.parentNode.browser.unblockPopup(target.getAttribute("popupReportIndex"));
 }
 
 function disablePopupBlockerNotifications()
 {
   Services.prefs.setBoolPref("privacy.popups.showBrowserMessage", false);
 }
 
 /**