Bug 1250806 - Add menuitems for recent bookmarks synchronously so that they show up in the native menubar on OS X. r=mak
authorDão Gottwald <dao@mozilla.com>
Wed, 02 Mar 2016 17:16:59 +0100
changeset 324665 f7149b0bcf7491e23edacbffce6fa418b05e776e
parent 324664 970aa793c5e2778172cd8e527f9dc04848400d40
child 324666 63132b94b6a39f017e9952486e01b1041b5a2d9f
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1250806
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 1250806 - Add menuitems for recent bookmarks synchronously so that they show up in the native menubar on OS X. r=mak
browser/base/content/browser-places.js
--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -1374,54 +1374,47 @@ var BookmarkingUI = {
     options.maxResults = kMaxResults;
     let query = PlacesUtils.history.getNewQuery();
 
     while (aHeaderItem.nextSibling &&
            aHeaderItem.nextSibling.localName == "menuitem") {
       aHeaderItem.nextSibling.remove();
     }
 
-    PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
-                       .asyncExecuteLegacyQueries([query], 1, options, {
-      handleResult: function (aResultSet) {
-        let onItemCommand = function (aEvent) {
-          let item = aEvent.target;
-          openUILink(item.getAttribute("targetURI"), aEvent);
-          CustomizableUI.hidePanelForNode(item);
-        };
+    let onItemCommand = 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 fragment = document.createDocumentFragment();
+    let root = PlacesUtils.history.executeQuery(query, options).root;
+    root.containerOpen = true;
+    for (let i = 0; i < root.childCount; i++) {
+      let node = root.getChild(i);
+      let uri = node.uri;
+      let title = node.title;
+      let icon = node.icon;
 
-          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("command", onItemCommand);
-          if (icon) {
-            let iconURL = "moz-anno:favicon:" + icon;
-            item.setAttribute("image", iconURL);
-          }
-          fragment.appendChild(item);
-        }
-        aHeaderItem.parentNode.insertBefore(fragment, aHeaderItem.nextSibling);
-      },
-      handleError: function (aError) {
-        Cu.reportError("Error while attempting to show recent bookmarks: " + aError);
-      },
-      handleCompletion: function (aReason) {
-      },
-    });
+      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("command", onItemCommand);
+      if (icon) {
+        let iconURL = "moz-anno:favicon:" + icon;
+        item.setAttribute("image", iconURL);
+      }
+      fragment.appendChild(item);
+    }
+    root.containerOpen = false;
+    aHeaderItem.parentNode.insertBefore(fragment, aHeaderItem.nextSibling);
   },
 
   /**
    * Handles star styling based on page proxy state changes.
    */
   onPageProxyStateChanged: function BUI_onPageProxyStateChanged(aState) {
     if (!this._shouldUpdateStarState() || !this.star) {
       return;