Bug 734688 - OpenSearch broke session history for content tabs; r=Standard8
authorJim Porter <squibblyflabbetydoo@gmail.com>
Tue, 17 Apr 2012 22:07:37 +0100
changeset 11653 da4a29c6727648633609e925e442ee698bdd7125
parent 11652 5dc4741eb87d83bbf188422b0f95ac0c72ae514c
child 11654 a030c1d425855f456575dbab80ff354627c4720e
push idunknown
push userunknown
push dateunknown
reviewersStandard8
bugs734688
Bug 734688 - OpenSearch broke session history for content tabs; r=Standard8
mail/base/content/msgMail3PaneWindow.js
mail/base/content/webSearchTab.js
mail/base/content/webSearchTab.xul
--- a/mail/base/content/msgMail3PaneWindow.js
+++ b/mail/base/content/msgMail3PaneWindow.js
@@ -422,17 +422,17 @@ function OnLoadMessenger()
     panelcontainer.addEventListener("ResetBrowserThemePreview",
                                     LightWeightThemeWebInstaller, false, true);
   }
 
   Services.obs.addObserver(gPluginHandler.pluginCrashed, "plugin-crashed", false);
 
   // This also registers the contentTabType ("contentTab")
   specialTabs.openSpecialTabsOnStartup();
-  tabmail.registerTabType(webSearchTabType);
+  webSearchTabType.initialize();
   tabmail.registerTabType(accountProvisionerTabType);
 
   // Set up the summary frame manager to handle loading pages in the
   // multi-message pane
   gSummaryFrameManager = new SummaryFrameManager(
                          document.getElementById("multimessage"));
 
   window.addEventListener("AppCommand", HandleAppCommandEvent, true);
--- a/mail/base/content/webSearchTab.js
+++ b/mail/base/content/webSearchTab.js
@@ -61,16 +61,37 @@ let webSearchTabType = {
 
   modes: {
     webSearchTab: {
       type: "webSearchTab",
       maxTabs: 10
     }
   },
 
+  initialize: function() {
+    let browser = document.getElementById("dummywebsearchbrowser");
+
+    // Manually hook up session and global history for the first browser
+    // so that we don't have to load global history before bringing up a
+    // window.
+    // Wire up session and global history before any possible
+    // progress notifications for back/forward button updating
+    browser.webNavigation.sessionHistory =
+      Components.classes["@mozilla.org/browser/shistory;1"]
+                .createInstance(Components.interfaces.nsISHistory);
+    Services.obs.addObserver(browser, "browser:purge-session-history", false);
+
+    // remove the disablehistory attribute so the browser cleans up, as
+    // though it had done this work itself
+    browser.removeAttribute("disablehistory");
+
+    let tabmail = document.getElementById("tabmail");
+    tabmail.registerTabType(this);
+  },
+
   openTab: function onTabOpened(aTab, aArgs) {
     if (!"contentPane" in aArgs || !"engine" in aArgs || !"query" in aArgs)
       throw("contentPage, engine, and query must be specified");
 
     // First clone the page and set up the basics.
     let clone = document.getElementById("webSearchTab").firstChild
                         .cloneNode(true);
 
@@ -147,16 +168,19 @@ let webSearchTabType = {
     aTab.defaultButton.addEventListener("click", function () {
       Services.search.currentEngine = aTab.currentEngine;
       self._setDefaultButtonState(aTab, true);
     }, true);
 
     aTab.browser.loadURIWithFlags(aArgs.contentPage, null, null, null,
                                   aArgs.postData);
 
+    goUpdateCommand("cmd_goBackSearch");
+    goUpdateCommand("cmd_goForwardSearch");
+
     this.lastBrowserId++;
   },
 
   persistTab: function onPersistTab(aTab) {
     if (aTab.browser.currentURI.spec == "about:blank")
       return null;
 
     let onClick = aTab.clickHandler;
@@ -196,45 +220,62 @@ let webSearchTabType = {
         if (!this._isInEngine(tab.currentEngine, preUri, postUri)) {
           aEvent.preventDefault();
           openLinkExternally(href);
         }
       }
     }
   },
 
+  commands: {
+    cmd_goBackSearch: {
+      isEnabled: function(aTab) {
+        return aTab.browser.canGoBack;
+      },
+      doCommand: function(aTab) {
+        aTab.browser.goBack();
+      }
+    },
+
+    cmd_goForwardSearch: {
+      isEnabled: function(aTab) {
+        return aTab.browser.canGoForward;
+      },
+      doCommand: function(aTab) {
+        aTab.browser.goForward();
+      }
+    },
+  },
+
   supportsCommand: function supportsCommand(aCommand, aTab) {
-    switch (aCommand) {
-      case "cmd_goBackSearch":
-      case "cmd_goForwardSearch":
-        return true;
-      default:
-        return this.__proto__.supportsCommand(aCommand, aTab);
-    }
+    return (aCommand in this.commands) ||
+           this.__proto__.supportsCommand(aCommand, aTab);
   },
 
   isCommandEnabled: function isCommandEnabled(aCommand, aTab) {
-    switch (aCommand) {
-      case "cmd_goBackSearch":
-        return aTab.browser.canGoBack;
-      case "cmd_goForwardSearch":
-        return aTab.browser.canGoForward;
-      default:
-        return this.__proto__.isCommandEnabled(aCommand, aTab);
-    }
+    if (!this.supportsCommand(aCommand))
+      return;
+
+    if (aCommand in this.commands)
+      return this.commands[aCommand].isEnabled(aTab);
+    else
+      return this.__proto__.isCommandEnabled(aCommand, aTab);
   },
 
   doCommand: function doCommand(aCommand, aTab) {
-    switch (aCommand) {
-      case "cmd_goBackSearch":
-        aTab.browser.goBack();
-      case "cmd_goForwardSearch":
-        aTab.browser.goForward();
-      default:
-        this.__proto__.doCommand(aCommand, aTab);
+    if (!this.supportsCommand(aCommand))
+      return;
+
+    if (aCommand in this.commands) {
+      var cmd = this.commands[aCommand];
+      if (!cmd.isEnabled(aTab))
+        return;
+      cmd.doCommand(aTab);
+    } else {
+      this.__proto__.doCommand(aCommand, aTab);
     }
   },
 
   _doSearch: function(aTab, engine) {
     aTab.currentEngine = engine;
     let submission = aTab.currentEngine.getSubmission(aTab.query);
 
     aTab.browser.loadURIWithFlags(submission.uri.spec, null, null, null,
--- a/mail/base/content/webSearchTab.xul
+++ b/mail/base/content/webSearchTab.xul
@@ -45,35 +45,33 @@
           src="chrome://messenger/content/webSearchTab.js"/>
 
   <commandset id="webSearchItems" commandupdater="true">
     <command id="cmd_goBackSearch" oncommand="goDoCommand('cmd_goBackSearch')"/>
     <command id="cmd_goForwardSearch" oncommand="goDoCommand('cmd_goForwardSearch')"/>
   </commandset>
 
 
-  <!--We want to enable browser history, and at least the Go menu-->
-  <browser id="dummycontentbrowser" type="content" disablehistory="false"/>
   <hbox id="tabmail-container">
     <vbox id="webSearchTab" collapsed="true">
       <vbox flex="1">
-        <toolbox id="dummycontenttoolbox" class="contentTabToolbox">
-          <toolbar id="dummycontenttoolbar" class="contentTabToolbar"></toolbar>
+        <toolbox id="dummywebsearchtoolbox" class="contentTabToolbox">
+          <toolbar id="dummywebsearchtoolbar" class="contentTabToolbar"/>
         </toolbox>
         <hbox flex="1">
           <vbox class="navbar">
             <vbox class="navbuttons">
               <toolbarbutton class="back" command="cmd_goBackSearch"/>
               <toolbarbutton class="forward" command="cmd_goForwardSearch"/>
             </vbox>
             <arrowscrollbox class="engines" orient="vertical"
                             flex="1"/>
             <button class="defaultButton" type="checkbox"/>
           </vbox>
-          <browser id="dummycontentbrowser" type="content-targetable" flex="1"
+          <browser id="dummywebsearchbrowser" type="content-targetable" flex="1"
                    disablehistory="true" autocompletepopup="PopupAutoComplete"
                    context="mailContext"/>
-          <findbar browserid="dummycontentbrowser"/>
         </hbox>
+        <findbar browserid="dummywebsearchbrowser"/>
       </vbox>
     </vbox>
   </hbox>
 </overlay>