Bug 670749 - Have individual methods for cookie/image/popup menus in navigatorOverlay r=neil
authorIan Neal <iann_cvs@blueyonder.co.uk>
Wed, 13 Jul 2011 23:05:36 +0100
changeset 8280 7c0c838f516de331f7aca8ecba0707906920fd92
parent 8279 4579fdf3d43674cc5774113a1e5a4a0b1df3c307
child 8281 dd41379e2ec129411f26de9752100d1498dbb488
push id107
push userbugzilla@standard8.plus.com
push dateTue, 16 Aug 2011 23:11:19 +0000
treeherdercomm-aurora@cefe50ba1568 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil
bugs670749
Bug 670749 - Have individual methods for cookie/image/popup menus in navigatorOverlay r=neil
suite/browser/navigator.js
suite/browser/navigatorOverlay.xul
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -842,40 +842,37 @@ function Translate()
 function GetTypePermFromId(aId)
 {
   // Get type and action from splitting id, first is type, second is action.
   var [type, action] = aId.split("_");
   var perm = "ACCESS_" + action.toUpperCase();
   return [type, Components.interfaces.nsICookiePermission[perm]];
 }
 
-// Determine which items we need to hide or disable from the task menu.
-function CheckForVisibility()
+function CheckForVisibility(aEvent)
 {
-  // Determine current state (blocked or unblocked) and
-  // hide appropriate menu item.
   var uri = getBrowser().currentURI;
-  setRadioButtons(uri, "cookie");
-  setRadioButtons(uri, "image");
-
   var policy = Services.prefs.getBoolPref("dom.disable_open_during_load");
   document.getElementById("ManagePopups").hidden = !policy;
 
   var element = document.getElementById("AllowPopups");
   if (policy && (Services.perms.testPermission(uri, "popup") != Services.perms.ALLOW_ACTION))
     element.removeAttribute("disabled");
   else
     element.setAttribute("disabled", "true");
+
+  if (!/Mac/.test(navigator.platform))
+    popupBlockerMenuShowing(aEvent);
 }
 
-function setRadioButtons(aUri, aType)
+// Determine current state and check/uncheck the appropriate menu items.
+function CheckPermissionsMenu(aType, aNode)
 {
-  var currentPerm = Services.perms.testPermission(aUri, aType);
-  var items = document.getElementById("menu_" + aType + "Manager")
-                      .getElementsByAttribute("name", aType);
+  var currentPerm = Services.perms.testPermission(getBrowser().currentURI, aType);
+  var items = aNode.getElementsByAttribute("name", aType);
   for (var i = 0; i < items.length; i++) {
     var item = items[i];
     // Get type and perm from id.
     var [type, perm] = GetTypePermFromId(item.id);
     item.setAttribute("checked", perm == currentPerm);
   }
 }
 
--- a/suite/browser/navigatorOverlay.xul
+++ b/suite/browser/navigatorOverlay.xul
@@ -488,32 +488,32 @@
                      onpopupshowing="if (!this.parentNode._placesView)
                                        new PlacesMenu(event, 'place:folder=TOOLBAR');"/>
         </menu>
         <menuseparator/>
       </menupopup>
     </menu>
 
     <menu id="tasksMenu">
-      <menupopup id="taskPopup" onpopupshowing="CheckForVisibility();">
+      <menupopup id="taskPopup">
         <menuitem id="menu_searchWeb"
                   label="&searchInternetCmd.label;"
                   accesskey="&searchInternetCmd.accesskey;"
                   key="searchInternetKb"
                   command="Browser:SearchInternet"/>
         <menuitem id="menu_translate"
                   label="&translateMenu.label;"
                   accesskey="&translateMenu.accesskey;"
                   oncommand="Translate();"/>
         <menu id="menu_cookieManager"
               label="&cookieCookieManager.label;"
               accesskey="&cookieCookieManager.accesskey;"
               oncommand="if (event.target.id) CookieImageAction(event.target);
                          else toDataManager('|cookies');">
-          <menupopup>
+          <menupopup onpopupshowing="CheckPermissionsMenu('cookie', this);">
             <menuitem id="cookie_deny"
                       label="&cookieBlockCookiesCmd.label;"
                       accesskey="&cookieBlockCookiesCmd.accesskey;"
                       title="&cookieMessageTitle.label;"
                       msg="&cookieBlockCookiesMsg.label;"
                       type="radio"
                       name="cookie"/>
             <menuitem id="cookie_default"
@@ -542,17 +542,17 @@
                       accesskey="&cookieDisplayCookiesCmd.accesskey;"/>
           </menupopup>
         </menu>
         <menu id="menu_imageManager"
               label="&cookieImageManager.label;"
               accesskey="&cookieImageManager.accesskey;"
               oncommand="if (event.target.id) CookieImageAction(event.target);
                          else toDataManager('|permissions');">
-          <menupopup>
+          <menupopup onpopupshowing="CheckPermissionsMenu('image', this);">
             <menuitem id="image_deny"
                       label="&cookieBlockImagesCmd.label;"
                       accesskey="&cookieBlockImagesCmd.accesskey;"
                       title="&cookieImageMessageTitle.label;"
                       msg="&cookieBlockImagesMsg.label;"
                       type="radio"
                       name="image"/>
             <menuitem id="image_default"
@@ -572,19 +572,18 @@
             <menuseparator/>
             <menuitem label="&cookieDisplayImagesCmd.label;"
                       accesskey="&cookieDisplayImagesCmd.accesskey;"/>
           </menupopup>
         </menu>
         <menu id="menu_popupManager"
               label="&cookiePopupManager.label;"
               accesskey="&cookiePopupManager.accesskey;"
-              oncommand="popupBlockerMenuCommand(event.target);"
-              onpopupshowing="if (!/Mac/.test(navigator.platform)) return popupBlockerMenuShowing(event);">
-          <menupopup>
+              oncommand="popupBlockerMenuCommand(event.target);">
+          <menupopup onpopupshowing="CheckForVisibility(event);">
             <menuitem id="AllowPopups"
                       label="&cookieAllowPopupsCmd.label;"
                       accesskey="&cookieAllowPopupsCmd.accesskey;"
                       oncommand="toDataManager(popupHost() + '|permissions|add|popup');"/>
             <menuitem id="ManagePopups"
                       label="&cookieManagePopups.label;"
                       accesskey="&cookieManagePopups.accesskey;"
                       oncommand="toDataManager('|permissions');"