menu

This article is in need of a technical review.

The NativeWindow object is only available to privileged code running on Firefox for Android, and is intended for use by Firefox for Android add-ons.

Summary

Returns a reference to the NativeWindow.menu object, which can be used to add items to the main Firefox for Android menu, and subsequently remove them. You can add a menu item to a browser window using NativeWindow.menu.add() and remove it using NativeWindow.menu.remove().

A common pattern is for a restartless add-on to add and remove menu items in the add-on's bootstrap.js:

This ensures that the item is always present while the add-on is installed and enabled, and that it is cleaned up properly when the add-on is uninstalled or disabled. But note that bootstrap.js is not attached to a DOM window, so you need to get a window, for example using nsIWindowMediator, before you can use this pattern.

Example

The following example adds a menu item with the label "Show Toast", which displays a toast notification when clicked:NativeWindow-menu.png

function showToast(window) {
  window.NativeWindow.toast.show("Showing you a toast", "short");
}

var menuID;

function addMenuItem(window) {
  menuID = window.NativeWindow.menu.add({
    name: "Show Toast",
    icon: null,
    callback: function(){
      showToast(window);
    }
  });
}

function removeMenuItem(window) {
  window.NativeWindow.menu.remove(menuID);
}

Methods

add
Add an item to the menu.
remove
Remove an item from the menu.
update
Update an item in the menu.

Attributes

Attribute Type Description
toolsMenuID int Use this as the parent ID to add your menu item to the Tools menu (only shown on Android 3.0+. On earlier versions your menu item will just be added to the base menu).

See also

Attachments

File Size Date Attached by
NativeWindow-menu.png
77056 bytes 2012-06-19 21:19:44 wbamberg

Document Tags and Contributors

Contributors to this page: wbamberg, kscarfone, sriramramani, gregg.lind, wesj
Last updated by: wbamberg,