Bug 444917 - Port |Bug 388504 – It should be possible for an extension to reload Page Info on a different document| to SeaMonkey; r+sr=neil
authorPhilip Chee <philip.chee@gmail.com>
Mon, 08 Jun 2009 17:45:53 +0200
changeset 2804 86f9ec8efa439392362be2fc47f1758007fa04e2
parent 2803 4a231a0cac5e305a1816fea6b40ae6a6abc3b828
child 2805 14a9407ebddb8c5d0abbde11d2d18c4e76516d9a
push idunknown
push userunknown
push dateunknown
bugs444917, 388504
Bug 444917 - Port |Bug 388504 – It should be possible for an extension to reload Page Info on a different document| to SeaMonkey; r+sr=neil
suite/browser/pageinfo/pageInfo.js
suite/browser/pageinfo/permissions.js
suite/browser/pageinfo/security.js
--- a/suite/browser/pageinfo/pageInfo.js
+++ b/suite/browser/pageinfo/pageInfo.js
@@ -246,19 +246,26 @@ const XHTMLre = RegExp(XHTMLNSre + "|" +
  * These arrays are used to hold callbacks that Page Info will call at
  * various stages. Use them by simply appending a function to them.
  * For example, add a function to onLoadRegistry by invoking
  *   "onLoadRegistry.push(XXXLoadFunc);"
  * The XXXLoadFunc should be unique to the overlay module, and will be
  * invoked as "XXXLoadFunc();"
  */
 
-// These functions are called once when the Page Info window is opened.
+// These functions are called to build the data displayed in the Page
+// Info window. The global variables gDocument and gWindow are set.
 var onLoadRegistry = [ ];
 
+// These functions are called to remove old data still displayed in
+// the window when the document whose information is displayed
+// changes. For example, the list of images in the Media tab
+// is cleared.
+var onResetRegistry = [ ];
+
 // These are called once for each subframe of the target document and
 // the target document itself. The frame is passed as an argument.
 var onProcessFrame = [ ];
 
 // These functions are called once for each element (in all subframes, if any)
 // in the target document. The element is passed as an argument.
 var onProcessElement = [ ];
 
@@ -296,57 +303,102 @@ function onLoadPageInfo()
   else {
     if ("gBrowser" in window.opener)
       gWindow = window.opener.gBrowser.contentWindow;
     else
       gWindow = window.opener.frames[0];
     gDocument = gWindow.document;
   }
 
-  var titleFormat = gWindow != gWindow.top ? "pageInfo.frame.title"
-                                           : "pageInfo.page.title";
-  document.title = gBundle.getFormattedString(titleFormat, [gDocument.location]);
-
-  document.getElementById("main-window").setAttribute("relatedUrl", gDocument.location);
-
-  // do the easy stuff first
-  makeGeneralTab();
-
   // init views
   function initView(treeid, view)
   {
     document.getElementById(treeid).view = view;
   }
 
   initView("imagetree", gImageView);
   initView("formtree", gFormView);
   initView("formpreview", gFieldView);
   initView("linktree", gLinkView);
+  initPermission();
+
+  // build the content
+  loadPageInfo();
+
+  /* Select the requested tab, if the name is specified */
+  var initialTab = "generalTab";
+  if ("arguments" in window && window.arguments.length >= 1 &&
+       window.arguments[0] && window.arguments[0].initialTab)
+    initialTab = window.arguments[0].initialTab;
+  showTab(initialTab);
+  Components.classes["@mozilla.org/observer-service;1"]
+            .getService(Components.interfaces.nsIObserverService)
+            .notifyObservers(window, "page-info-dialog-loaded", null);
+}
+
+function loadPageInfo()
+{
+  var titleFormat = gWindow != gWindow.top ? "pageInfo.frame.title"
+                                           : "pageInfo.page.title";
+  document.title = gBundle.getFormattedString(titleFormat, [gDocument.location]);
+
+  document.getElementById("main-window").setAttribute("relatedUrl", gDocument.location);
+
+  // do the easy stuff first
+  makeGeneralTab();
 
   // and then the hard stuff
   makeTabs(gDocument, gWindow);
 
   initFeedTab();
   onLoadPermission();
 
   /* Call registered overlay init functions */
   onLoadRegistry.forEach(function(func) { func(); });
+}
 
-  /* Select the requested tab, if the name is specified */
-  var initialTab = "generalTab";
-  if ("arguments" in window && window.arguments.length >= 1 &&
-       window.arguments[0] && window.arguments[0].initialTab)
-    initialTab = window.arguments[0].initialTab;
-  var tabbox = document.getElementById("tabbox");
-  initialTab = document.getElementById(initialTab) || document.getElementById("generalTab");
-  tabbox.selectedTab = initialTab;
-  tabbox.selectedTab.focus();
+function resetPageInfo(args)
+{
+  /* Reset Media tab */
+  // Remove the observer, only if there is at least 1 image.
+  if (gImageView.data.length != 0) {
+    Components.classes["@mozilla.org/observer-service;1"]
+              .getService(Components.interfaces.nsIObserverService)
+              .removeObserver(imagePermissionObserver, "perm-changed");
+  }
+
+  /* Reset tree views */
+  gMetaView.clear();
+  gFormView.clear();
+  gFieldView.clear();
+  gLinkView.clear();
+  gImageView.clear();
+  gImageHash = {};
+
+  /* Reset Feeds Tab */
+  var feedListbox = document.getElementById("feedListbox");
+  while (feedListbox.hasChildNodes())
+    feedListbox.removeChild(feedListbox.lastChild);
+
+  /* Call registered overlay reset functions */
+  onResetRegistry.forEach(function(func) { func(); });
+
+  if (args && args.doc) {
+    gDocument = args.doc;
+    gWindow = gDocument.defaultView;
+  }
+
+  /* Rebuild the data */
+  loadPageInfo();
+
+  if (args && args.initialTab)
+    showTab(args.initialTab);
   Components.classes["@mozilla.org/observer-service;1"]
             .getService(Components.interfaces.nsIObserverService)
-            .notifyObservers(window, "page-info-dialog-loaded", null);
+            .notifyObservers(window, "page-info-dialog-reset", null);
 }
 
 function onUnloadPageInfo()
 {
   // Remove the observer, only if there is at least 1 image.
   if (gImageView.data.length != 0) {
     Components.classes["@mozilla.org/observer-service;1"]
               .getService(Components.interfaces.nsIObserverService)
@@ -369,21 +421,29 @@ function doHelpButton()
     "securityTab": "pageinfo_security"
   };
 
   var tabbox = document.getElementById("tabbox");
   var helpdoc = helpTopics[tabbox.selectedTab.id] || "nav-page-info";
   openHelp(helpdoc, "chrome://communicator/locale/help/suitehelp.rdf");
 }
 
-function onClickMore()
+function showTab(id)
 {
   var tabbox = document.getElementById("tabbox");
-  var tab = document.getElementById("securityTab");
-  tabbox.selectedTab = tab;
+  var selectedTab = document.getElementById(id) ||
+                    document.getElementById(id + "Tab") || // Firefox compatibility sillyness
+                    document.getElementById("generalTab");
+  tabbox.selectedTab = selectedTab;
+  selectedTab.focus();
+}
+
+function onClickMore()
+{
+  showTab("securityTab");
 }
 
 function makeGeneralTab()
 {
   var title = (gDocument.title) ? gBundle.getFormattedString("pageTitle", [gDocument.title]) : gBundle.getString("noPageTitle");
   document.getElementById("titletext").value = title;
 
   var url = gDocument.location.toString();
--- a/suite/browser/pageinfo/permissions.js
+++ b/suite/browser/pageinfo/permissions.js
@@ -34,17 +34,18 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 const ALLOW = nsIPermissionManager.ALLOW_ACTION;   // 1
 const BLOCK = nsIPermissionManager.DENY_ACTION;    // 2
 const SESSION = nsICookiePermission.ACCESS_SESSION;// 8
 var gPermURI;
-var gPrefs;
+var gPrefs = Components.classes[PREFERENCES_CONTRACTID]
+                       .getService(Components.interfaces.nsIPrefBranch2);
 
 var gPermObj = {
   image: function getImageDefaultPermission()
   {
     if (gPrefs.getIntPref("permissions.default.image") == 2)
       return BLOCK;
     return ALLOW;
   },
@@ -71,56 +72,67 @@ var gPermObj = {
   }
 };
 
 var permissionObserver = {
   observe: function (aSubject, aTopic, aData)
   {
     if (aTopic == "perm-changed") {
       var permission = aSubject.QueryInterface(Components.interfaces.nsIPermission);
-      if (permission.host == gPermURI.host && permission.type in gPermObj)
+      if (/^https?/.test(gPermURI.scheme) &&
+          permission.host == gPermURI.host && permission.type in gPermObj)
         initRow(permission.type);
     }
   }
 };
 
+function initPermission()
+{
+  onUnloadRegistry.push(onUnloadPermission);
+  onResetRegistry.push(onUnloadPermission);
+}
+
 function onLoadPermission()
 {
-  gPrefs = Components.classes[PREFERENCES_CONTRACTID]
-                     .getService(Components.interfaces.nsIPrefBranch2);
-
-  var uri = gDocument.documentURIObject;
-  if(/^https?/.test(uri.scheme)) {
-    gPermURI = uri;
+  gPermURI = gDocument.documentURIObject;
+  if (/^https?/.test(gPermURI.scheme)) {
     var hostText = document.getElementById("hostText");
     hostText.value = gPermURI.host;
-
-    for (var i in gPermObj)
-      initRow(i);
     Components.classes["@mozilla.org/observer-service;1"]
               .getService(Components.interfaces.nsIObserverService)
               .addObserver(permissionObserver, "perm-changed", false);
-    onUnloadRegistry.push(onUnloadPermission);
   }
+  for (var i in gPermObj)
+    initRow(i);
 }
 
 function onUnloadPermission()
 {
-  Components.classes["@mozilla.org/observer-service;1"]
-            .getService(Components.interfaces.nsIObserverService)
-            .removeObserver(permissionObserver, "perm-changed");
+  if (/^https?/.test(gPermURI.scheme)) {
+    Components.classes["@mozilla.org/observer-service;1"]
+              .getService(Components.interfaces.nsIObserverService)
+              .removeObserver(permissionObserver, "perm-changed");
+  }
 }
 
 function initRow(aPartId)
 {
   var permissionManager = Components.classes[PERMISSION_CONTRACTID]
                                     .getService(nsIPermissionManager);
 
   var checkbox = document.getElementById(aPartId + "Def");
   var command  = document.getElementById("cmd_" + aPartId + "Toggle");
+  if (!/^https?/.test(gPermURI.scheme)) {
+    checkbox.checked = false;
+    checkbox.setAttribute("disabled", "true");
+    command.setAttribute("disabled", "true");
+    document.getElementById(aPartId + "RadioGroup").selectedItem = null;
+    return;
+  }
+  checkbox.removeAttribute("disabled");
   var perm = permissionManager.testPermission(gPermURI, aPartId);
   if (perm) {
     checkbox.checked = false;
     command.removeAttribute("disabled");
   }
   else {
     checkbox.checked = true;
     command.setAttribute("disabled", "true");
--- a/suite/browser/pageinfo/security.js
+++ b/suite/browser/pageinfo/security.js
@@ -225,23 +225,19 @@ function securityOnLoad() {
     generalPageIdentityString = owner;
   }
 
   setText("security-identity-owner-value", owner);
   setText("security-identity-verifier-value", verifier);
   setText("general-security-identity", generalPageIdentityString);
 
   /* Manage the View Cert button*/
-  if (info.cert) {
+  if (info.cert)
     security._cert = info.cert;
-  }
-  else {
-    var viewCert = document.getElementById("security-view-cert");
-    viewCert.collapsed = true;
-  }
+  document.getElementById("security-view-cert").collapsed = !info.cert;
 
   /* Set Privacy & History section text */
   var yesStr = pageInfoBundle.getString("yes");
   var noStr = pageInfoBundle.getString("no");
 
   setText("security-privacy-cookies-value",
           hostHasCookies(info.hostName) ? yesStr : noStr);
   setText("security-privacy-passwords-value",