Bug 388504 - It should be possible for an extension to reload Page Info on a different document patch by Florian Quèze <f.qu@queze.net>, r=db48x, sr=neil
authordb48x@yahoo.com
Mon, 06 Aug 2007 09:13:05 -0700
changeset 4308 59b26c8b271fc00579c48b05019e5b7bfec80d96
parent 4307 336d1eb2ad935652daa594487d037587b6c8b8aa
child 4309 b52f7cd3d855e8008f36652b8ec8167316203a33
push idunknown
push userunknown
push dateunknown
reviewersdb48x, neil
bugs388504
milestone1.9a8pre
Bug 388504 - It should be possible for an extension to reload Page Info on a different document patch by Florian Quèze <f.qu@queze.net>, r=db48x, sr=neil
browser/base/content/pageinfo/feeds.js
browser/base/content/pageinfo/pageInfo.js
browser/base/content/pageinfo/permissions.js
browser/base/content/pageinfo/security.js
--- a/browser/base/content/pageinfo/feeds.js
+++ b/browser/base/content/pageinfo/feeds.js
@@ -57,18 +57,17 @@ function initFeedTab()
         type = feedTypes[type];
       else
         type = feedTypes["application/rss+xml"];
       addRow(feed.title, type, feed.href);
     }
   }
 
   var feedListbox = document.getElementById("feedListbox");
-  if (feedListbox.getRowCount() > 0)
-    document.getElementById("feedTab").hidden = false;
+  document.getElementById("feedTab").hidden = feedListbox.getRowCount() == 0;
 }
 
 function onSubscribeFeed()
 {
   var listbox = document.getElementById("feedListbox");
   openUILink(listbox.selectedItem.getAttribute("feedURL"),
              null, false, true, false, null);
 }
--- a/browser/base/content/pageinfo/pageInfo.js
+++ b/browser/base/content/pageinfo/pageInfo.js
@@ -238,19 +238,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, at this time, the list of images of 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 = [ ];
 
@@ -289,50 +296,84 @@ 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 media view
   var imageTree = document.getElementById("imagetree");
   imageTree.view = gImageView;
 
-  // and then the hard stuff
-  makeTabs(gDocument, gWindow);
-
-  initFeedTab();
-  onLoadPermission();
-
-  /* Call registered overlay init functions */
-  onLoadRegistry.map(function(func) { func(); });
+  // build the content
+  loadPageInfo();
 
   /* Select the requested tab, if the name is specified */
   var initialTab = "general";
   if ("arguments" in window && window.arguments.length >= 1 &&
        window.arguments[0] && window.arguments[0].initialTab)
     initialTab = window.arguments[0].initialTab;
   var radioGroup = document.getElementById("viewGroup");
   initialTab = document.getElementById(initialTab + "Tab") || document.getElementById("generalTab");
   radioGroup.selectedItem = initialTab;
   radioGroup.selectedItem.doCommand();
   radioGroup.focus();
 }
 
+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.map(function(func) { func(); });
+}
+
+function resetPageInfo()
+{
+  /* Reset Meta tags part */
+  gMetaView.clear();
+
+  /* Reset Media tab */
+  var mediaTab = document.getElementById("mediaTab");
+  if (!mediaTab.hidden) {
+    var os = Components.classes["@mozilla.org/observer-service;1"]
+                       .getService(Components.interfaces.nsIObserverService);
+    os.removeObserver(imagePermissionObserver, "perm-changed");
+    mediaTab.hidden = true;
+  }
+  gImageView.clear();
+  gImageHash = {};
+
+  /* Reset Feeds Tab */
+  var feedListbox = document.getElementById("feedListbox");
+  while (feedListbox.firstChild)
+    feedListbox.removeChild(feedListbox.firstChild);
+
+  /* Call registered overlay reset functions */
+  onResetRegistry.map(function(func) { func(); });
+
+  /* And let's rebuild the data */
+  loadPageInfo();
+}
+
 function onUnloadPageInfo()
 {
   if (!document.getElementById("mediaTab").hidden) {
     var os = Components.classes["@mozilla.org/observer-service;1"]
                        .getService(Components.interfaces.nsIObserverService);
     os.removeObserver(imagePermissionObserver, "perm-changed");
   }
 
@@ -405,31 +446,32 @@ function makeGeneralTab()
   // get the document characterset
   var encoding = gDocument.characterSet;
   document.getElementById("encodingtext").value = encoding;
 
   // get the meta tags
   var metaNodes = gDocument.getElementsByTagName("meta");
   var length = metaNodes.length;
 
-  if (!length) {
-    var metaGroup = document.getElementById("metaTags");
+  var metaGroup = document.getElementById("metaTags");
+  if (!length)
     metaGroup.collapsed = true;
-  }
   else {
     var metaTagsCaption = document.getElementById("metaTagsCaption");
     if (length == 1)
       metaTagsCaption.label = gBundle.getString("generalMetaTag");
     else
       metaTagsCaption.label = gBundle.getFormattedString("generalMetaTags", [length]);
     var metaTree = document.getElementById("metatree");
     metaTree.treeBoxObject.view = gMetaView;
 
     for (var i = 0; i < length; i++)
       gMetaView.addRow([metaNodes[i].name || metaNodes[i].httpEquiv, metaNodes[i].content]);
+
+    metaGroup.collapsed = false;
   }
 
   // get the date of last modification
   var modifiedText = formatDate(gDocument.lastModified, gStrings.notSet);
   document.getElementById("modifiedtext").value = modifiedText;
 
   // get cache info
   var cacheKey = url.replace(/#.*$/, "");
--- a/browser/base/content/pageinfo/permissions.js
+++ b/browser/base/content/pageinfo/permissions.js
@@ -81,30 +81,32 @@ var permissionObserver = {
 };
 
 function onLoadPermission()
 {
   gPrefs = Components.classes[PREFERENCES_CONTRACTID]
                      .getService(Components.interfaces.nsIPrefBranch2);
 
   var uri = gDocument.documentURIObject;
+  var permTab = document.getElementById("permTab");
   if(/^https?/.test(uri.scheme)) {
     gPermURI = uri;
     var hostText = document.getElementById("hostText");
     hostText.value = gPermURI.host;
 
     for (var i in gPermObj)
       initRow(i);
     var os = Components.classes["@mozilla.org/observer-service;1"]
                        .getService(Components.interfaces.nsIObserverService);
     os.addObserver(permissionObserver, "perm-changed", false);
     onUnloadRegistry.push(onUnloadPermission);
+    permTab.hidden = false;
   }
   else
-    document.getElementById("permTab").hidden = true;
+    permTab.hidden = true;
 }
 
 function onUnloadPermission()
 {
   var os = Components.classes["@mozilla.org/observer-service;1"]
                      .getService(Components.interfaces.nsIObserverService);
   os.removeObserver(permissionObserver, "perm-changed");
 }
--- a/browser/base/content/pageinfo/security.js
+++ b/browser/base/content/pageinfo/security.js
@@ -157,20 +157,24 @@ var security = {
 };
 
 function securityOnLoad() {
   var bundle = srGetStrBundle("chrome://pippki/locale/pippki.properties");
   var pageInfoBundle = document.getElementById("pageinfobundle");
 
   var info = security._getSecurityInfo();
   if (!info) {
-    document.getElementById("securityTab").setAttribute("hidden", true);
+    document.getElementById("securityTab").hidden = true;
     document.getElementById("securityBox").collapsed = true;
     return;
   }
+  else {
+    document.getElementById("securityTab").hidden = false;
+    document.getElementById("securityBox").collapsed = false;
+  }
 
   /* Set Identity section text */
   setText("security-identity-domain-value", info.hostName);
   
   // FIXME - Should only be showing the next two if the cert is EV.  Waiting on
   // bug 374336
   var owner, verifier, generalPageIdentityString;
   if (info.cert && !info.isBroken) {
@@ -193,25 +197,25 @@ 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*/
+  var viewCert = document.getElementById("security-view-cert");
   if (info.cert) {
     var viewText = pageInfoBundle.getString("securityCertText");
     setText("security-view-text", viewText);
     security._cert = info.cert;
+    viewCert.collapsed = false;
   }
-  else {
-    var viewCert = document.getElementById("security-view-cert");
+  else
     viewCert.collapsed = true;
-  }
 
   /* 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",