Bug 1386786 - Fix Android browserAction.setTitle/getTitle behavior on switching and closing tab.
MozReview-Commit-ID: LFxnySvBBOz
--- 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();
}
}