Bug 476274 - security.js: Fix typos and bit-rot; r+sr=neil
authorKrang <bugzilla@technodrome.com>
Sun, 22 Mar 2009 15:28:46 +0100
changeset 2257 9b8d068b160bf8321af8c2d2bdf43a8b933a3ce7
parent 2256 573fb4c0ec8bd028b0171609caaa73d14c357dfe
child 2258 06a2b33231051938af962f623c31401f8037ece7
push idunknown
push userunknown
push dateunknown
bugs476274
Bug 476274 - security.js: Fix typos and bit-rot; r+sr=neil
suite/browser/pageinfo/security.js
suite/common/permissions/cookieViewer.js
--- a/suite/browser/pageinfo/security.js
+++ b/suite/browser/pageinfo/security.js
@@ -133,44 +133,64 @@ var security = {
 
     // No mapping required
     return name;
   },
   
   /**
    * Open the cookie manager window
    */
-  viewCookies: windowOpener("Browser:Cookies",
-                            "chrome://communicator/content/permissions/cookieViewer.xul",
-                            "cookieManager"),
+  viewCookies : function()
+  {
+    var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+                       .getService(Components.interfaces.nsIWindowMediator);
+    var win = wm.getMostRecentWindow("mozilla:cookieviewer");
+    var eTLDService = Components.classes["@mozilla.org/network/effective-tld-service;1"].
+                      getService(Components.interfaces.nsIEffectiveTLDService);
+
+    var eTLD;
+    var uri = gDocument.documentURIObject;
+    try {
+      eTLD = eTLDService.getBaseDomain(uri);
+    }
+    catch (e) {
+      // getBaseDomain will fail if the host is an IP address or is empty
+      eTLD = uri.asciiHost;
+    }
+
+    if (win) {
+      win.setFilter(eTLD);
+      win.focus();
+    }
+    else
+      window.openDialog("chrome://communicator/content/permissions/cookieViewer.xul",
+                        "", "resizable", {filterString : eTLD});
+  },
   
   /**
    * Open the login manager window
    */
-  viewPasswords: windowOpener("Toolkit:PasswordManager",
-                              "chrome://communicator/content/wallet/SignonViewer.xul",
-                              "S"),
+  viewPasswords : function()
+  {
+    var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+                       .getService(Components.interfaces.nsIWindowMediator);
+    var win = wm.getMostRecentWindow("Toolkit:PasswordManager");
+    if (win) {
+      win.setFilter(this._getSecurityInfo().hostName);
+      win.focus();
+    }
+    else
+      window.openDialog("chrome://communicator/content/passwordManager.xul",
+                        "", "resizable",
+                        {filterString : this._getSecurityInfo().hostName});
+  },
 
   _cert : null
 };
 
-function windowOpener(class, url, args)
-{
-  return function()
-  {
-    var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
-                       .getService(Components.interfaces.nsIWindowMediator);
-    var win = wm.getMostRecentWindow(class);
-    if (win)
-      win.focus();
-    else
-      window.openDialog(url, class, "chrome,resizable", args);
-  }
-}
-
 function securityOnLoad() {
   var info = security._getSecurityInfo();
   if (!info)
     return;
 
   const pageInfoBundle = document.getElementById("pageinfobundle");
 
   /* Set Identity section text */
--- a/suite/common/permissions/cookieViewer.js
+++ b/suite/common/permissions/cookieViewer.js
@@ -90,16 +90,22 @@ function Startup() {
   loadCookies();
   loadPermissions();
 
   // be prepared to reload the display if anything changes
   kObserverService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
   kObserverService.addObserver(cookieReloadDisplay, "cookie-changed", false);
   kObserverService.addObserver(cookieReloadDisplay, "perm-changed", false);
 
+  // filter the table if requested by caller
+  if (window.arguments &&
+      window.arguments[0] &&
+      window.arguments[0].filterString)
+    setFilter(window.arguments[0].filterString);
+
   document.getElementById("filter").focus();
 }
 
 function Shutdown() {
   kObserverService.removeObserver(cookieReloadDisplay, "cookie-changed");
   kObserverService.removeObserver(cookieReloadDisplay, "perm-changed");
 }
 
@@ -604,14 +610,20 @@ function filter(filter)
   else
     document.getElementById("removeAllCookies").removeAttribute("disabled");
 
   // if the view is filtered and not empty then select the first item
   if (filter && cookies.length)
     cookiesTreeView.selection.select(0);
 }
 
+function setFilter(aFilterString)
+{
+  document.getElementById("filter").value = aFilterString;
+  filter(aFilterString);
+}
+
 function focusFilterBox()
 {
   var filterBox = document.getElementById("filter");
   filterBox.focus();
   filterBox.select();
 }