Bug 1414084 - Part 5 - Unify menu click event handling. r?grisha
Now that both Webextensions and the NativeWindow API manage their onClick call-
back handling by UUID, we can start using the same EventDispatcher message for
both.
MozReview-Commit-ID: J3RRXrwPdTI
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -3344,17 +3344,17 @@ public class BrowserApp extends GeckoApp
private void addBrowserActionMenuItemToMenu(final Menu menu, final MenuItemInfo info) {
final MenuItem item = menu.add(Menu.NONE, info.id, Menu.NONE, info.label);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
final GeckoBundle data = new GeckoBundle(1);
data.putString("item", info.uuid);
- EventDispatcher.getInstance().dispatch("Menu:BrowserActionClicked", data);
+ EventDispatcher.getInstance().dispatch("Menu:Clicked", data);
return true;
}
});
item.setCheckable(info.checkable);
item.setChecked(info.checked);
item.setEnabled(info.enabled);
item.setVisible(info.visible);
--- a/mobile/android/modules/BrowserActions.jsm
+++ b/mobile/android/modules/BrowserActions.jsm
@@ -18,47 +18,48 @@ var BrowserActions = {
/**
* Registers the listeners only if they have not been initialized
* already and there is at least one browser action.
*/
_maybeRegisterListeners() {
if (!this._initialized && Object.keys(this._browserActions).length) {
this._initialized = true;
- EventDispatcher.instance.registerListener(this, "Menu:BrowserActionClicked");
+ EventDispatcher.instance.registerListener(this, "Menu:Clicked");
}
},
/**
* Unregisters the listeners if they are already initizliaed and
* all of the browser actions have been removed.
*/
_maybeUnregisterListeners() {
if (this._initialized && !Object.keys(this._browserActions).length) {
this._initialized = false;
- EventDispatcher.instance.unregisterListener(this, "Menu:BrowserActionClicked");
+ EventDispatcher.instance.unregisterListener(this, "Menu:Clicked");
}
},
/**
* Called when a browser action is clicked on.
* @param {string} event The name of the event, which should always
- * be "Menu:BrowserActionClicked".
+ * be "Menu:Clicked".
* @param {Object} data An object containing information about the
* browser action, which in this case should contain an `item`
* property which is browser action's UUID.
*/
onEvent(event, data) {
- if (event !== "Menu:BrowserActionClicked") {
- throw new Error(`Expected "Menu:BrowserActionClicked" event - received "${event}" instead`);
+ if (event !== "Menu:Clicked") {
+ throw new Error(`Expected "Menu:Clicked" event - received "${event}" instead`);
}
let browserAction = this._browserActions[data.item];
if (!browserAction) {
- throw new Error(`No browser action found with UUID ${data.item}`);
+ // This was probably meant for the NativeWindow menu handler.
+ return;
}
browserAction.onClicked();
},
/**
* Registers a new browser action.
* @param {Object} browserAction The browser action to add.
*/