Terjemahan ini belum lengkap. Mohon bantu menerjemahkan artikel ini dari Bahasa Inggris.
The NativeWindow
object enables Firefox for Android add-ons to create user interface components.
NativeWindow
is available as a property of the chrome window
object. For example, if you use this template for initializing your extension, you can access it from the window
argument passed into loadIntoWindow()
:
function loadIntoWindow(window) { window.NativeWindow.toast.show("I'm starting!", "short"); }
You can also access the chrome window using nsIWindowMediator
:
let window = Services.wm.getMostRecentWindow("navigator:browser"); window.NativeWindow.toast.show("Here's another toast message!", "short");
The NativeWindow
object enables developers of Firefox for Android add-ons to create UI components.
It supports the following components:
menu
Add items to the main menu in Firefox for Android. See the menu API documentation.
/* label: menu label icon: file:// or data: URI for an icon callback: JS function called when menu is tapped returns a menu ID that can be used to remove the menu */ let id = NativeWindow.menu.add(label, icon, callback); NativeWindow.menu.remove(id);
doorhanger
Show and hide doorhanger notifications. See the doorhanger API documentation.
/* message: displayed text value: string based tag buttons: array of JS objects used to create buttons in the notification tabId: tab associated with this notification options: JS object that has 'persistence' and 'timeout' options */ NativeWindow.doorhanger.show(message, value, buttons, tabId, options); NativeWindow.doorhanger.hide(value, tabId);
contextmenus
Add and remove context menu items. See the contextmenus API documentation.
/* label: menu label selector: JS object that has a 'matches(element)' function. Used to show the menu. callback: JS function called when menu is tapped returns a menu ID that can be used to remove the menu */ let id = NativeWindow.contextmenu.add(label, selector, callback); NativeWindow.contextmenu.remove(id);
toast
Show Android toast notifications. See the toast API documentation.
/* message: displayed text duration: "short" or "long"; Used for alert timeout */ NativeWindow.toast.show(message, duration);
pageactions
Add and remove pageactions, i.e. clickable indicators in the URL bar. See the pageactions API documentation.
/* title: Pageaction title icon: Icon image for the pageaction clickCallback: Callback called when pageaction is clicked longClickCallback: Callback called when pageaction is long pressed */ let options = { title: "title", icon: "chrome://myaddon/skin/image.png", clickCallback: function() { }, longClickCallback: function() { } (optional) }; //Adding pageaction let id = NativeWindow.pageactions.add(options); //Remove pageaction NativeWindow.pageactions.remove(id);