# HG changeset patch
# User Matt A. Tobin <email@mattatobin.com>
# Date 1724087287 18000
# Node ID 39ebd2dfbe6aaae94a845bca2d0e9d7409764466
# Parent  21e8c1325dd88a9ff2fdca1a937f810c21a2e027
Bug 1913787 - Replace session history in the Go Menu with places history items

diff --git a/suite/browser/browser-places.js b/suite/browser/browser-places.js
--- a/suite/browser/browser-places.js
+++ b/suite/browser/browser-places.js
@@ -954,8 +954,19 @@ var BookmarksMenu = {
       // Need to set the label on Unsorted Bookmarks menu.
       let unsortedBookmarksElt =
         document.getElementById(aPrefix + "unsortedBookmarksFolderMenu");
       unsortedBookmarksElt.label =
         PlacesUtils.getString("OtherBookmarksFolderTitle");
     }
   },
 };
+
+// Handles the history menu popup
+function HistoryMenu(aPopupShowingEvent) {
+  // Workaround for Bug 610187.  The sidebar does not include all the Places
+  // views definitions, and we don't need them there.
+  // Defining the prototype inheritance in the prototype itself would cause
+  // navigator.js to halt on "PlacesMenu is not defined" error.
+  this.__proto__.__proto__ = PlacesMenu.prototype;
+  PlacesMenu.call(this, aPopupShowingEvent, "place:queryType=0&sort=4&maxResults=15"); 
+}
+HistoryMenu.prototype = {};
diff --git a/suite/browser/navigator.css b/suite/browser/navigator.css
--- a/suite/browser/navigator.css
+++ b/suite/browser/navigator.css
@@ -85,16 +85,22 @@ panel[for="urlbar"] {
 searchbar {
   -moz-binding: url("chrome://communicator/content/search/search.xml#searchbar");
 }
 
 #wrapper-search-container > #search-container > #searchbar > .searchbar-textbox > .autocomplete-textbox-container > .textbox-input-box > html|*.textbox-input {
   visibility: hidden;
 }
 
+/* ::::: places menus ::::: */
+
+menupopup[emptyplacesresult="true"] > .hide-if-empty-places-result {
+  display: none;
+}
+
 /* ::::: bookmarks menu ::::: */
 
 .isempty:not(:last-child) {
   display: none;
 }
 
 /* ::::: bookmarks toolbar ::::: */
 
diff --git a/suite/browser/navigatorOverlay.xul b/suite/browser/navigatorOverlay.xul
--- a/suite/browser/navigatorOverlay.xul
+++ b/suite/browser/navigatorOverlay.xul
@@ -444,21 +444,24 @@
         <menuseparator />
         <!-- overlayed from viewApplyThemeOverlay.xul -->
         <menu id="menu_viewApplyTheme"/>
       </menupopup>
     </menu>
 
     <menu id="history-menu"
           label="&goMenu.label;"
-          accesskey="&goMenu.accesskey;"
-          oncommand="gotoHistoryIndex(event);"
-          onclick="checkForMiddleClick(this, event);">
-      <menupopup id="goPopup"
-                 onpopupshowing="updateGoMenu(event);">
+          accesskey="&goMenu.accesskey;">
+      <menupopup id="historyPopup"
+                 placespopup="true"
+                 context="placescontext"
+                 oncommand="BookmarksEventHandler.onCommand(event);"
+                 onclick="BookmarksEventHandler.onClick(event);"
+                 onpopupshowing="updateRecentMenuItems();
+                                 if (!this.parentNode._placesView) { new HistoryMenu(event); }">
         <menuitem id="historyMenuBack"
                   label="&goBackCmd.label;"
                   accesskey="&goBackCmd.accesskey;"
                   key="goBackKb"
                   oncommand="BrowserBack(event);"
                   onclick="checkForMiddleClick(this, event);"
                   observes="canGoBack"/>
         <menuitem id="historyMenuForward"
@@ -500,23 +503,18 @@
                   oncommand="restoreLastSession();"
                   disabled="true"/>
         <menuseparator/>
         <menuitem id="menu_showAllHistory"
                   label="&historyCmd.label;"
                   accesskey="&historyCmd.accesskey;"
                   oncommand="PlacesCommandHook.showPlacesOrganizer('History');"
                   key="key_gotoHistory"/>
-        <menuseparator id="startHistorySeparator" hidden="true"/>
-        <menuseparator id="endHistorySeparator" hidden="true"/>
-        <!-- Dead for now.
-        <menuitem id="sync-tabs-menuitem"
-                  label="&syncTabsMenu.label;"
-                  oncommand="BrowserOpenSyncTabs();"
-                  disabled="true"/> -->
+        <menuseparator id="startHistorySeparator"
+                       class="hide-if-empty-places-result"/>
       </menupopup>
     </menu>
 
     <menu id="bookmarksMenu"
           label="&bookmarksMenu.label;"
           accesskey="&bookmarksMenu.accesskey;"
           ondragenter="PlacesMenuDNDHandler.onDragEnter(event);"
           ondragover="PlacesMenuDNDHandler.onDragOver(event);"
diff --git a/suite/browser/sessionHistoryUI.js b/suite/browser/sessionHistoryUI.js
--- a/suite/browser/sessionHistoryUI.js
+++ b/suite/browser/sessionHistoryUI.js
@@ -59,33 +59,16 @@ function FillHistoryMenu(aParent, aMenu)
         return false;
       for (let j = index + 1; j <= end; j++)
       {
         let entry = sessionHistory.getEntryAtIndex(j, false);
         if (entry)
           createHistoryMenuItem(aParent, j, entry);
       }
       break;
-    case "go":
-      var startHistory = document.getElementById("startHistorySeparator");
-      var endHistory = document.getElementById("endHistorySeparator");
-      // var syncMenuItem = document.getElementById("sync-tabs-menuitem");
-      startHistory.hidden = (count == 0);
-      end = count > MAX_HISTORY_MENU_ITEMS ? count - MAX_HISTORY_MENU_ITEMS
-                                           : 0;
-      for (let j = count - 1; j >= end; j--)
-      {
-        let entry = sessionHistory.getEntryAtIndex(j, false);
-        if (entry)
-          createHistoryMenuItem(aParent, j, entry, endHistory, j == index);
-      }
-      // toggleTabsFromOtherComputers();
-      // endHistory.hidden = (endHistory == aParent.lastChild || syncMenuItem.hidden);
-      endHistory.hidden = (endHistory == aParent.lastChild);
-      break;
   }
   return true;
 }
 
 function executeUrlBarHistoryCommand( aTarget )
   {
     var index = aTarget.getAttribute("index");
     var label = aTarget.getAttribute("label");
@@ -158,13 +141,8 @@ function deleteHistoryItems(aParent)
   var children = aParent.childNodes;
   for (let i = children.length - 1; i >= 0; --i)
   {
     if (children[i].hasAttribute("index"))
       children[i].remove();
   }
 }
 
-function updateGoMenu(event)
-  {
-    FillHistoryMenu(event.target, "go");
-    updateRecentMenuItems();
-  }
