Bug 463176 - NS_ERROR_FACTORY_NOT_REGISTERED from nsIDocShellHistory.useGlobalHistory opening view source; Disable all BACK/FORWARD UI and logic when disablehistory="true"; r=gavin.sharp
authorCurtis Bartley <cbartley@mozilla.com>
Sat, 06 Dec 2008 18:06:59 +0100
changeset 22434 7650cecd9913e5d7a3f86648e379e01a24a58359
parent 22433 eff94ca7dcae4c42af4012c5a257ad986eaa74f1
child 22435 7482683c532a2bf452f6f4e38e3e0956c0183442
push idunknown
push userunknown
push dateunknown
reviewersgavin.sharp
bugs463176
milestone1.9.2a1pre
Bug 463176 - NS_ERROR_FACTORY_NOT_REGISTERED from nsIDocShellHistory.useGlobalHistory opening view source; Disable all BACK/FORWARD UI and logic when disablehistory="true"; r=gavin.sharp
toolkit/components/viewsource/content/viewSource.js
toolkit/components/viewsource/content/viewSource.xul
--- a/toolkit/components/viewsource/content/viewSource.js
+++ b/toolkit/components/viewsource/content/viewSource.js
@@ -94,26 +94,39 @@ var gViewSourceProgressListener = {
   }
 
 }
 
 function onLoadViewSource() 
 {
   viewSource(window.arguments[0]);
   document.commandDispatcher.focusedWindow = content;
-  
-  // Attach the progress listener.
-  getBrowser().addProgressListener(gViewSourceProgressListener, 
-      Components.interfaces.nsIWebProgress.NOTIFY_ALL);
+      
+  if (isHistoryEnabled()) {
+    // Attach the progress listener.
+    getBrowser().addProgressListener(gViewSourceProgressListener, 
+        Components.interfaces.nsIWebProgress.NOTIFY_ALL);
+  } else {
+    // Disable the BACK and FORWARD commands and hide the related menu items.
+    var viewSourceNavigation = document.getElementById("viewSourceNavigation");
+    viewSourceNavigation.setAttribute("disabled", "true");
+    viewSourceNavigation.setAttribute("hidden", "true");
+  }
 }
 
 function onUnloadViewSource() 
 {
   // Detach the progress listener.
-  getBrowser().removeProgressListener(gViewSourceProgressListener);
+  if (isHistoryEnabled()) {
+    getBrowser().removeProgressListener(gViewSourceProgressListener);
+  }
+}
+
+function isHistoryEnabled() {
+  return !getBrowser().hasAttribute("disablehistory");
 }
 
 function getBrowser()
 {
   if (!gBrowser)
     gBrowser = document.getElementById("content");
   return gBrowser;
 }
--- a/toolkit/components/viewsource/content/viewSource.xul
+++ b/toolkit/components/viewsource/content/viewSource.xul
@@ -93,18 +93,20 @@
   <command id="cmd_reload" oncommand="ViewSourceReload();"/>
   <command id="cmd_goToLine" oncommand="ViewSourceGoToLine();" disabled="true"/>
   <command id="cmd_highlightSyntax" oncommand="highlightSyntax();"/>
   <command id="cmd_wrapLongLines" oncommand="wrapLongLines()"/>
   <command id="cmd_textZoomReduce" oncommand="ZoomManager.reduce();"/>
   <command id="cmd_textZoomEnlarge" oncommand="ZoomManager.enlarge();"/>
   <command id="cmd_textZoomReset" oncommand="ZoomManager.reset();"/>
 
-  <command id="Browser:Back" oncommand="BrowserBack();"/>
-  <command id="Browser:Forward" oncommand="BrowserForward();"/>
+  <command id="Browser:Back" oncommand="BrowserBack();" observes="viewSourceNavigation"/>
+  <command id="Browser:Forward" oncommand="BrowserForward();" observes="viewSourceNavigation"/>
+
+  <broadcaster id="viewSourceNavigation"/>
 
   <keyset id="editMenuKeys"/>
   <keyset id="viewSourceKeys">
     <key id="key_savePage" key="&savePageCmd.commandkey;" modifiers="accel" command="cmd_savePage"/>
     <key id="key_print" key="&printCmd.commandkey;" modifiers="accel" command="cmd_print"/>
     <key id="key_close" key="&closeCmd.commandkey;" modifiers="accel" command="cmd_close"/>
     <key id="key_goToLine"     key="&goToLineCmd.commandkey;"  command="cmd_goToLine"  modifiers="accel"/>
 
@@ -141,22 +143,24 @@
 #endif
 
   </keyset>
 
   <popup id="viewSourceContextMenu">
     <menuitem id="context-back"
               label="&backCmd.label;"
               accesskey="&backCmd.accesskey;"
-              command="Browser:Back"/>
+              command="Browser:Back"
+              observes="viewSourceNavigation"/>
     <menuitem id="context-forward"
               label="&forwardCmd.label;"
               accesskey="&forwardCmd.accesskey;"
-              command="Browser:Forward"/>
-    <menuseparator/>
+              command="Browser:Forward"
+              observes="viewSourceNavigation"/>
+    <menuseparator observes="viewSourceNavigation"/>
     <menuitem id="cMenu_findAgain"/>
     <menuseparator/>
     <menuitem id="cMenu_copy"/>
     <menuseparator/>
     <menuitem id="cMenu_selectAll"/>
   </popup>
 
   <!-- Menu -->