Bug 1395743 - Pocket button should come before bookmarks star button in urlbar. r=Gijs
authorDrew Willcoxon <adw@mozilla.com>
Fri, 01 Sep 2017 14:46:52 -0700
changeset 428375 71d59cfac7dfb49889416a4c209c7a57bc707c36
parent 428374 c884cca7be4ac09214a0317f14d6495d71c1f59a
child 428376 4249740f06643e7d766db832ea15816518455152
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1395743
milestone57.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 1395743 - Pocket button should come before bookmarks star button in urlbar. r=Gijs MozReview-Commit-ID: 2KPSv3Fy8kn
browser/extensions/pocket/bootstrap.js
browser/modules/PageActions.jsm
--- a/browser/extensions/pocket/bootstrap.js
+++ b/browser/extensions/pocket/bootstrap.js
@@ -94,16 +94,17 @@ var PocketPageAction = {
       this.pageAction = PageActions.addAction(new PageActions.Action({
         id,
         title: gPocketBundle.GetStringFromName("saveToPocketCmd.label"),
         shownInUrlbar: true,
         wantsIframe: true,
         urlbarIDOverride: "pocket-button-box",
         anchorIDOverride: "pocket-button",
         _insertBeforeActionID: PageActions.ACTION_ID_BOOKMARK_SEPARATOR,
+        _urlbarInsertBeforeActionID: PageActions.ACTION_ID_BOOKMARK,
         _urlbarNodeInMarkup: true,
         onBeforePlacedInWindow(window) {
           let doc = window.document;
 
           if (doc.getElementById("pocket-button-box")) {
             return;
           }
 
--- a/browser/modules/PageActions.jsm
+++ b/browser/modules/PageActions.jsm
@@ -4,31 +4,33 @@
 
 "use strict";
 
 this.EXPORTED_SYMBOLS = [
   "PageActions",
   // PageActions.Action
   // PageActions.Button
   // PageActions.Subview
+  // PageActions.ACTION_ID_BOOKMARK
   // PageActions.ACTION_ID_BOOKMARK_SEPARATOR
   // PageActions.ACTION_ID_BUILT_IN_SEPARATOR
 ];
 
 const { utils: Cu } = Components;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
   "resource://gre/modules/AppConstants.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "BinarySearch",
   "resource://gre/modules/BinarySearch.jsm");
 
 
+const ACTION_ID_BOOKMARK = "bookmark";
 const ACTION_ID_BOOKMARK_SEPARATOR = "bookmarkSeparator";
 const ACTION_ID_BUILT_IN_SEPARATOR = "builtInSeparator";
 
 const PREF_PERSISTED_ACTIONS = "browser.pageActions.persistedActions";
 
 
 this.PageActions = {
   /**
@@ -223,17 +225,27 @@ this.PageActions = {
       // so that onActionToggledShownInUrlbar isn't called, which happens when
       // the public version is set.
       action._shownInUrlbar =
         this._persistedActions.idsInUrlbar.includes(action.id);
     } else {
       // The action is new.  Store it in the persisted actions.
       this._persistedActions.ids[action.id] = true;
       if (action.shownInUrlbar) {
-        this._persistedActions.idsInUrlbar.push(action.id);
+        // Also store it in idsInUrlbar.
+        let index =
+          !action.__urlbarInsertBeforeActionID ? -1 :
+          this._persistedActions.idsInUrlbar.indexOf(
+            action.__urlbarInsertBeforeActionID
+          );
+        if (index < 0) {
+          // Append the action.
+          index = this._persistedActions.idsInUrlbar.length;
+        }
+        this._persistedActions.idsInUrlbar.splice(index, 0, action.id);
       }
       this._storePersistedActions();
     }
   },
 
   _builtInActions: [],
   _nonBuiltInActions: [],
   _actionsByID: new Map(),
@@ -481,20 +493,25 @@ function Action(options) {
     subview: false,
     tooltip: false,
     urlbarIDOverride: false,
     wantsIframe: false,
 
     // private
 
     // (string, optional)
-    // The ID of another action before which to insert this new action.  Applies
-    // to the page action panel only, not the urlbar.
+    // The ID of another action before which to insert this new action in the
+    // panel.
     _insertBeforeActionID: false,
 
+    // (string, optional)
+    // The ID of another action before which to insert this new action in the
+    // urlbar.
+    _urlbarInsertBeforeActionID: false,
+
     // (bool, optional)
     // True if this isn't really an action but a separator to be shown in the
     // page action panel.
     _isSeparator: false,
 
     // (bool, optional)
     // True if the action's urlbar button is defined in markup.  In that case, a
     // node with the action's urlbar node ID should already exist in the DOM
@@ -872,32 +889,32 @@ Button.prototype = {
       this._onCommand(event, buttonNode);
     }
   }
 };
 
 this.PageActions.Button = Button;
 
 
-// This is only necessary so that Pocket and the test can specify it for
-// action._insertBeforeActionID.
+// These are only necessary so that Pocket and the test can use them.
+this.PageActions.ACTION_ID_BOOKMARK = ACTION_ID_BOOKMARK;
 this.PageActions.ACTION_ID_BOOKMARK_SEPARATOR = ACTION_ID_BOOKMARK_SEPARATOR;
 
 // This is only necessary so that the test can access it.
 this.PageActions.ACTION_ID_BUILT_IN_SEPARATOR = ACTION_ID_BUILT_IN_SEPARATOR;
 
 
 // Sorted in the order in which they should appear in the page action panel.
 // Does not include the page actions of extensions bundled with the browser.
 // They're added by the relevant extension code.
 var gBuiltInActions = [
 
   // bookmark
   {
-    id: "bookmark",
+    id: ACTION_ID_BOOKMARK,
     urlbarIDOverride: "star-button-box",
     _urlbarNodeInMarkup: true,
     title: "",
     shownInUrlbar: true,
     nodeAttributes: {
       observes: "bookmarkThisPageBroadcaster",
     },
     onShowingInPanel(buttonNode) {