Dart Documentationchrome.pageActionChromePageAction

ChromePageAction class

class ChromePageAction extends ChromeApi {
 static final JsObject _pageAction = chrome['pageAction'];

 ChromePageAction._();

 bool get available => _pageAction != null;

 /**
  * Shows the page action. The page action is shown whenever the tab is
  * selected.
  * 
  * [tabId] The id of the tab for which you want to modify the page action.
  */
 void show(int tabId) {
   if (_pageAction == null) _throwNotAvailable();

   _pageAction.callMethod('show', [tabId]);
 }

 /**
  * Hides the page action.
  * 
  * [tabId] The id of the tab for which you want to modify the page action.
  */
 void hide(int tabId) {
   if (_pageAction == null) _throwNotAvailable();

   _pageAction.callMethod('hide', [tabId]);
 }

 /**
  * Sets the title of the page action. This is displayed in a tooltip over the
  * page action.
  */
 void setTitle(PageActionSetTitleParams details) {
   if (_pageAction == null) _throwNotAvailable();

   _pageAction.callMethod('setTitle', [jsify(details)]);
 }

 /**
  * Gets the title of the page action.
  */
 Future<String> getTitle(PageActionGetTitleParams details) {
   if (_pageAction == null) _throwNotAvailable();

   var completer = new ChromeCompleter<String>.oneArg();
   _pageAction.callMethod('getTitle', [jsify(details), completer.callback]);
   return completer.future;
 }

 /**
  * Sets the icon for the page action. The icon can be specified either as the
  * path to an image file or as the pixel data from a canvas element, or as
  * dictionary of either one of those. Either the <b>path</b> or the
  * <b>imageData</b> property must be specified.
  */
 Future setIcon(PageActionSetIconParams details) {
   if (_pageAction == null) _throwNotAvailable();

   var completer = new ChromeCompleter.noArgs();
   _pageAction.callMethod('setIcon', [jsify(details), completer.callback]);
   return completer.future;
 }

 /**
  * Sets the html document to be opened as a popup when the user clicks on the
  * page action's icon.
  */
 void setPopup(PageActionSetPopupParams details) {
   if (_pageAction == null) _throwNotAvailable();

   _pageAction.callMethod('setPopup', [jsify(details)]);
 }

 /**
  * Gets the html document set as the popup for this page action.
  */
 Future<String> getPopup(PageActionGetPopupParams details) {
   if (_pageAction == null) _throwNotAvailable();

   var completer = new ChromeCompleter<String>.oneArg();
   _pageAction.callMethod('getPopup', [jsify(details), completer.callback]);
   return completer.future;
 }

 /**
  * Fired when a page action icon is clicked.  This event will not fire if the
  * page action has a popup.
  */
 Stream<Tab> get onClicked => _onClicked.stream;

 final ChromeStreamController<Tab> _onClicked =
     new ChromeStreamController<Tab>.oneArg(_pageAction, 'onClicked', _createTab);

 void _throwNotAvailable() {
   throw new UnsupportedError("'chrome.pageAction' is not available");
 }
}

Extends

ChromeApi > ChromePageAction

Properties

final bool available #

Returns true if the API is available. The common causes of an API not being avilable are:

  • a permission is missing in the application's manifest.json file
  • the API is defined on a newer version of Chrome then the current runtime
docs inherited from ChromeApi
bool get available => _pageAction != null;

final Stream<Tab> onClicked #

Fired when a page action icon is clicked. This event will not fire if the page action has a popup.

Stream<Tab> get onClicked => _onClicked.stream;

Methods

Future<String> getPopup(PageActionGetPopupParams details) #

Gets the html document set as the popup for this page action.

Future<String> getPopup(PageActionGetPopupParams details) {
 if (_pageAction == null) _throwNotAvailable();

 var completer = new ChromeCompleter<String>.oneArg();
 _pageAction.callMethod('getPopup', [jsify(details), completer.callback]);
 return completer.future;
}

Future<String> getTitle(PageActionGetTitleParams details) #

Gets the title of the page action.

Future<String> getTitle(PageActionGetTitleParams details) {
 if (_pageAction == null) _throwNotAvailable();

 var completer = new ChromeCompleter<String>.oneArg();
 _pageAction.callMethod('getTitle', [jsify(details), completer.callback]);
 return completer.future;
}

void hide(int tabId) #

Hides the page action.

tabId The id of the tab for which you want to modify the page action.

void hide(int tabId) {
 if (_pageAction == null) _throwNotAvailable();

 _pageAction.callMethod('hide', [tabId]);
}

Future setIcon(PageActionSetIconParams details) #

Sets the icon for the page action. The icon can be specified either as the path to an image file or as the pixel data from a canvas element, or as dictionary of either one of those. Either the <b>path</b> or the <b>imageData</b> property must be specified.

Future setIcon(PageActionSetIconParams details) {
 if (_pageAction == null) _throwNotAvailable();

 var completer = new ChromeCompleter.noArgs();
 _pageAction.callMethod('setIcon', [jsify(details), completer.callback]);
 return completer.future;
}

void setPopup(PageActionSetPopupParams details) #

Sets the html document to be opened as a popup when the user clicks on the page action's icon.

void setPopup(PageActionSetPopupParams details) {
 if (_pageAction == null) _throwNotAvailable();

 _pageAction.callMethod('setPopup', [jsify(details)]);
}

void setTitle(PageActionSetTitleParams details) #

Sets the title of the page action. This is displayed in a tooltip over the page action.

void setTitle(PageActionSetTitleParams details) {
 if (_pageAction == null) _throwNotAvailable();

 _pageAction.callMethod('setTitle', [jsify(details)]);
}

void show(int tabId) #

Shows the page action. The page action is shown whenever the tab is selected.

tabId The id of the tab for which you want to modify the page action.

void show(int tabId) {
 if (_pageAction == null) _throwNotAvailable();

 _pageAction.callMethod('show', [tabId]);
}