Bug 1386786 - Fix Android browserAction.setTitle/getTitle behavior on switching and closing tab. r=mixedpuppy
authorLuca Greco <lgreco@mozilla.com>
Wed, 02 Aug 2017 21:26:50 +0200
changeset 422372 7fcd967f247d62593d90ebaabad88cf11bf63e92
parent 422371 9ab1b265e36d96b81500612137f4d1ceab4e6e72
child 422373 e6ba2424ca8c799134df7855a9f14309a359ea6c
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)
reviewersmixedpuppy
bugs1386786
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 1386786 - Fix Android browserAction.setTitle/getTitle behavior on switching and closing tab. r=mixedpuppy MozReview-Commit-ID: LFxnySvBBOz
mobile/android/components/extensions/ext-browserAction.js
mobile/android/modules/BrowserActions.jsm
--- a/mobile/android/components/extensions/ext-browserAction.js
+++ b/mobile/android/components/extensions/ext-browserAction.js
@@ -33,47 +33,38 @@ class BrowserAction {
     this.tabContext.on("tab-closed", // eslint-disable-line mozilla/balanced-listeners
                        (evt, tabId) => { this.onTabClosed(tabId); });
 
     BrowserActions.register(this);
     EventEmitter.decorate(this);
   }
 
   /**
-   * Retrieves the name for the active tab. Used for testing only.
-   * @returns {string} the name used for the active tab.
-   */
-  get activeName() {
-    let tab = tabTracker.activeTab;
-    return this.tabContext.get(tab.id).name || this.defaults.name;
-  }
-
-  /**
    * Required by the BrowserActions module. This event will get
    * called whenever the browser action is clicked on.
    */
   onClicked() {
     this.emit("click", tabTracker.activeTab);
   }
 
   /**
    * Updates the browser action whenever a tab is selected.
-   * @param {Object} tab The tab to update.
+   * @param {string} tabId The tab id to update.
    */
-  onTabSelected(tab) {
-    let name = this.tabContext.get(tab.id).name || this.defaults.name;
+  onTabSelected(tabId) {
+    let name = this.tabContext.get(tabId).name || this.defaults.name;
     BrowserActions.update(this.uuid, {name});
   }
 
   /**
    * Removes the tab from the property map now that it is closed.
-   * @param {Object} tab The tab which closed.
+   * @param {string} tabId The tab id of the closed tab.
    */
-  onTabClosed(tab) {
-    this.tabContext.clear(tab.id);
+  onTabClosed(tabId) {
+    this.tabContext.clear(tabId);
   }
 
   /**
    * Sets a property for the browser action for the specified tab. If the property is set
    * for the active tab, the browser action is also updated.
    *
    * @param {Object} tab The tab to set. If null, the browser action's default value is set.
    * @param {string} prop The property to update. Currently only "name" is supported.
@@ -88,17 +79,17 @@ class BrowserAction {
       let properties = this.tabContext.get(tab.id);
       if (value) {
         properties[prop] = value;
       } else {
         delete properties[prop];
       }
     }
 
-    if (tab && tab.selected) {
+    if (!tab || tab.selected) {
       BrowserActions.update(this.uuid, {[prop]: value});
     }
   }
 
   /**
    * Retreives a property of the browser action for the specified tab.
    *
    * @param {Object} tab The tab to retrieve the property from. If null, the default value is returned.
--- a/mobile/android/modules/BrowserActions.jsm
+++ b/mobile/android/modules/BrowserActions.jsm
@@ -8,16 +8,17 @@ const { classes: Cc, interfaces: Ci, uti
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/Messaging.jsm");
 
 this.EXPORTED_SYMBOLS = ["BrowserActions"];
 
 var BrowserActions = {
   _browserActions: {},
+  _browserActionTitles: {},
 
   _initialized: false,
 
   _nextMenuId: 0,
 
   /**
    * Registers the listeners only if they have not been initialized
    * already and there is at least one browser action.
@@ -68,43 +69,46 @@ var BrowserActions = {
     EventDispatcher.instance.sendRequest({
       type: "Menu:AddBrowserAction",
       id: this._nextMenuId++,
       uuid: browserAction.uuid,
       name: browserAction.defaults.name,
     });
 
     this._browserActions[browserAction.uuid] = browserAction;
+    this._browserActionTitles[browserAction.uuid] = browserAction.defaults.name;
 
     this._maybeRegisterListeners();
   },
 
   /**
    * Updates the browser action with the specified UUID.
    * @param {string} uuid The UUID of the browser action.
    * @param {Object} options The properties to update.
    */
   update(uuid, options) {
     if (options.name) {
       EventDispatcher.instance.sendRequest({
         type: "Menu:UpdateBrowserAction",
         uuid,
         options,
       });
+
+      this._browserActionTitles[uuid] = options.name;
     }
   },
 
   /**
    * Retrieves the name currently used for the browser action with the
    * specified UUID. Used for testing only.
    * @param {string} uuid The UUID of the browser action.
    * @returns {string} the name currently used for the browser action.
    */
   getNameForActiveTab(uuid) {
-    return this._browserActions[uuid].activeName;
+    return this._browserActionTitles[uuid];
   },
 
   /**
    * Checks to see if the browser action is shown. Used for testing only.
    * @param {string} uuid The UUID of the browser action.
    * @returns {boolean} true if the browser action is shown; false otherwise.
    */
   isShown(uuid) {
@@ -132,11 +136,12 @@ var BrowserActions = {
     if (!browserAction) {
       throw new Error(`No BrowserAction with UUID ${uuid} was found`);
     }
     EventDispatcher.instance.sendRequest({
       type: "Menu:RemoveBrowserAction",
       uuid,
     });
     delete this._browserActions[uuid];
+    delete this._browserActionTitles[uuid];
     this._maybeUnregisterListeners();
   }
 }