Bug 1219804 - Show last 5 recent bookmarks in the bookmarks menu. r=mak
authorDão Gottwald <dao@mozilla.com>
Fri, 12 Feb 2016 12:21:17 +0100
changeset 320441 2ba1faa2dcf944b3aced5e64632106efb2844112
parent 320440 b9d3adb8692c10d93125eabcef0ac67b3d955c56
child 320442 0485ab41f1410c120e0e00c56152b5878fe4bb56
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1219804
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1219804 - Show last 5 recent bookmarks in the bookmarks menu. r=mak
browser/base/content/browser-menubar.inc
browser/base/content/browser-places.js
browser/base/content/browser.xul
browser/components/customizableui/CustomizableWidgets.jsm
browser/locales/en-US/chrome/browser/browser.dtd
--- a/browser/base/content/browser-menubar.inc
+++ b/browser/base/content/browser-menubar.inc
@@ -446,16 +446,20 @@
                    oncommand="return FeedHandler.subscribeToFeed(null, event);"
                    onclick="checkForMiddleClick(this, event);"/>
       </menu>
       <menuitem id="menu_bookmarkAllTabs"
                 label="&addCurPagesCmd.label;"
                 class="show-only-for-keyboard"
                 command="Browser:BookmarkAllTabs"
                 key="bookmarkAllTabsKb"/>
+      <menuseparator/>
+      <menuitem label="&recentBookmarks.label;"
+                disabled="true"/>
+      <vbox id="menu_recentBookmarks"/>
       <menuseparator id="bookmarksToolbarSeparator"/>
       <menu id="bookmarksToolbarFolderMenu"
             class="menu-iconic bookmark-item"
             label="&personalbarCmd.label;"
             container="true">
         <menupopup id="bookmarksToolbarFolderPopup"
 #ifndef XP_MACOSX
                    placespopup="true"
--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -1300,16 +1300,19 @@ var BookmarkingUI = {
     if (widget.overflowed) {
       // Don't open a popup in the overflow popup, rather just open the Library.
       event.preventDefault();
       widget.node.removeAttribute("closemenu");
       PlacesCommandHook.showPlacesOrganizer("BookmarksMenu");
       return;
     }
 
+    this._updateRecentBookmarks(document.getElementById("BMB_recentBookmarks"),
+                                "subviewbutton");
+
     if (!this._popupNeedsUpdate)
       return;
     this._popupNeedsUpdate = false;
 
     let popup = event.target;
     let getPlacesAnonymousElement =
       aAnonId => document.getAnonymousElementByAttribute(popup.parentNode,
                                                          "placesanonid",
@@ -1333,16 +1336,70 @@ var BookmarkingUI = {
       extraClasses: {
         entry: "subviewbutton",
         footer: "panel-subview-footer"
       },
       insertionPoint: ".panel-subview-footer"
     });
   },
 
+  _updateRecentBookmarks: function(container, extraCSSClass = "") {
+    const kMaxResults = 5;
+
+    let options = PlacesUtils.history.getNewQueryOptions();
+    options.excludeQueries = true;
+    options.queryType = options.QUERY_TYPE_BOOKMARKS;
+    options.sortingMode = options.SORT_BY_DATE_DESCENDING;
+    options.maxResults = kMaxResults;
+    let query = PlacesUtils.history.getNewQuery();
+
+    while (container.firstChild) {
+      container.firstChild.remove();
+    }
+
+    PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
+                       .asyncExecuteLegacyQueries([query], 1, options, {
+      handleResult: function (aResultSet) {
+        let onItemClick = function (aEvent) {
+          let item = aEvent.target;
+          openUILink(item.getAttribute("targetURI"), aEvent);
+          CustomizableUI.hidePanelForNode(item);
+        };
+
+        let fragment = document.createDocumentFragment();
+        let row;
+        while ((row = aResultSet.getNextRow())) {
+          let uri = row.getResultByIndex(1);
+          let title = row.getResultByIndex(2);
+          let icon = row.getResultByIndex(6);
+
+          let item =
+            document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
+                                     "menuitem");
+          item.setAttribute("label", title || uri);
+          item.setAttribute("targetURI", uri);
+          item.setAttribute("class", "menuitem-iconic menuitem-with-favicon bookmark-item " +
+                                     extraCSSClass);
+          item.addEventListener("click", onItemClick);
+          if (icon) {
+            let iconURL = "moz-anno:favicon:" + icon;
+            item.setAttribute("image", iconURL);
+          }
+          fragment.appendChild(item);
+        }
+        container.appendChild(fragment);
+      },
+      handleError: function (aError) {
+        Cu.reportError("Error while attempting to show recent bookmarks: " + aError);
+      },
+      handleCompletion: function (aReason) {
+      },
+    });
+  },
+
   /**
    * Handles star styling based on page proxy state changes.
    */
   onPageProxyStateChanged: function BUI_onPageProxyStateChanged(aState) {
     if (!this._shouldUpdateStarState() || !this.star) {
       return;
     }
 
@@ -1545,16 +1602,17 @@ var BookmarkingUI = {
     if (this.broadcaster) {
       this.broadcaster.setAttribute("label", this.broadcaster.getAttribute(label));
     }
   },
 
   onMainMenuPopupShowing: function BUI_onMainMenuPopupShowing(event) {
     this._updateBookmarkPageMenuItem();
     PlacesCommandHook.updateBookmarkAllTabsCommand();
+    this._updateRecentBookmarks(document.getElementById("menu_recentBookmarks"));
   },
 
   _showBookmarkedNotification: function BUI_showBookmarkedNotification() {
     function getCenteringTransformForRects(rectToPosition, referenceRect) {
       let topDiff = referenceRect.top - rectToPosition.top;
       let leftDiff = referenceRect.left - rectToPosition.left;
       let heightDiff = referenceRect.height - rectToPosition.height;
       let widthDiff = referenceRect.width - rectToPosition.width;
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -807,16 +807,21 @@
             </menuitem>
             <!-- NB: temporary solution for bug 985024, this should go away soon. -->
             <menuitem id="BMB_bookmarksShowAllTop"
                       class="menuitem-iconic subviewbutton"
                       label="&showAllBookmarks2.label;"
                       command="Browser:ShowAllBookmarks"
                       key="manBookmarkKb"/>
             <menuseparator/>
+            <menuitem label="&recentBookmarks.label;"
+                      disabled="true"
+                      class="subviewbutton"/>
+            <vbox id="BMB_recentBookmarks"/>
+            <menuseparator/>
             <menu id="BMB_bookmarksToolbar"
                   class="menu-iconic bookmark-item subviewbutton"
                   label="&personalbarCmd.label;"
                   container="true">
               <menupopup id="BMB_bookmarksToolbarPopup"
                          placespopup="true"
                          context="placesContext"
                          onpopupshowing="if (!this.parentNode._placesView)
--- a/browser/components/customizableui/CustomizableWidgets.jsm
+++ b/browser/components/customizableui/CustomizableWidgets.jsm
@@ -179,18 +179,16 @@ const CustomizableWidgets = [
     onViewShowing: function(aEvent) {
       // Populate our list of history
       const kMaxResults = 15;
       let doc = aEvent.detail.ownerDocument;
       let win = doc.defaultView;
 
       let options = PlacesUtils.history.getNewQueryOptions();
       options.excludeQueries = true;
-      options.includeHidden = false;
-      options.resultType = options.RESULTS_AS_URI;
       options.queryType = options.QUERY_TYPE_HISTORY;
       options.sortingMode = options.SORT_BY_DATE_DESCENDING;
       options.maxResults = kMaxResults;
       let query = PlacesUtils.history.getNewQuery();
 
       let items = doc.getElementById("PanelUI-historyItems");
       // Clear previous history items.
       while (items.firstChild) {
--- a/browser/locales/en-US/chrome/browser/browser.dtd
+++ b/browser/locales/en-US/chrome/browser/browser.dtd
@@ -163,16 +163,17 @@ These should match what Safari and other
 <!ENTITY shareSelect.accesskey "r">
 <!ENTITY shareVideo.label "Share This Video">
 <!ENTITY shareVideo.accesskey "r">
 <!ENTITY feedsMenu2.label "Subscribe to This Page">
 <!ENTITY subscribeToPageMenupopup.label "Subscribe to This Page">
 <!ENTITY subscribeToPageMenuitem.label "Subscribe to This Page…">
 <!ENTITY addCurPagesCmd.label "Bookmark All Tabs…">
 <!ENTITY showAllBookmarks2.label "Show All Bookmarks">
+<!ENTITY recentBookmarks.label "Recently Bookmarked">
 <!ENTITY unsortedBookmarksCmd.label "Unsorted Bookmarks">
 <!ENTITY bookmarksToolbarChevron.tooltip "Show more bookmarks">
 
 <!ENTITY backCmd.label                "Back">
 <!ENTITY backButton.tooltip           "Go back one page">
 <!ENTITY forwardCmd.label             "Forward">
 <!ENTITY forwardButton.tooltip        "Go forward one page">
 <!ENTITY backForwardButtonMenu.tooltip "Right-click or pull down to show history">