Dart Documentationchrome.appChromeAppWindow

ChromeAppWindow class

Use the chrome.app.window API to create windows. Windows have an optional frame with title bar and size controls. They are not associated with any Chrome browser windows.

class ChromeAppWindow extends ChromeApi {
 static final JsObject _app_window = chrome['app']['window'];

 ChromeAppWindow._();

 bool get available => _app_window != null;

 /**
  * The size and position of a window can be specified in a number of different
  * ways. The most simple option is not specifying anything at all, in which
  * case a default size and platform dependent position will be used.
  * 
  * Another option is to use the bounds property, which will put the window at
  * the specified coordinates with the specified size. If the window has a
  * frame, it's total size will be the size given plus the size of the frame;
  * that is, the size in bounds is the content size, not the window size.
  * 
  * To automatically remember the positions of windows you can give them ids.
  * If a window has an id, This id is used to remember the size and position of
  * the window whenever it is moved or resized. This size and position is then
  * used instead of the specified bounds on subsequent opening of a window with
  * the same id. If you need to open a window with an id at a location other
  * than the remembered default, you can create it hidden, move it to the
  * desired location, then show it.
  * 
  * Returns:
  * Called in the creating window (parent) before the load event is called in
  * the created window (child). The parent can set fields or functions on the
  * child usable from onload. E.g. background.js:
  * 
  * `function(created_window) { created_window.contentWindow.foo = function ()
  * { }; };`
  * 
  * window.js:
  * 
  *  `window.onload = function () { foo(); }`
  */
 Future<AppWindow> create(String url, [CreateWindowOptions options]) {
   if (_app_window == null) _throwNotAvailable();

   var completer = new ChromeCompleter<AppWindow>.oneArg(_createAppWindow);
   _app_window.callMethod('create', [url, jsify(options), completer.callback]);
   return completer.future;
 }

 /**
  * Returns an [AppWindow] object for the current script context (ie JavaScript
  * 'window' object). This can also be called on a handle to a script context
  * for another page, for example: otherWindow.chrome.app.window.current().
  */
 AppWindow current() {
   if (_app_window == null) _throwNotAvailable();

   return _createAppWindow(_app_window.callMethod('current'));
 }

 void initializeAppWindow(dynamic state) {
   if (_app_window == null) _throwNotAvailable();

   _app_window.callMethod('initializeAppWindow', [jsify(state)]);
 }

 Stream get onBoundsChanged => _onBoundsChanged.stream;

 final ChromeStreamController _onBoundsChanged =
     new ChromeStreamController.noArgs(_app_window, 'onBoundsChanged');

 Stream get onClosed => _onClosed.stream;

 final ChromeStreamController _onClosed =
     new ChromeStreamController.noArgs(_app_window, 'onClosed');

 Stream get onFullscreened => _onFullscreened.stream;

 final ChromeStreamController _onFullscreened =
     new ChromeStreamController.noArgs(_app_window, 'onFullscreened');

 Stream get onMaximized => _onMaximized.stream;

 final ChromeStreamController _onMaximized =
     new ChromeStreamController.noArgs(_app_window, 'onMaximized');

 Stream get onMinimized => _onMinimized.stream;

 final ChromeStreamController _onMinimized =
     new ChromeStreamController.noArgs(_app_window, 'onMinimized');

 Stream get onRestored => _onRestored.stream;

 final ChromeStreamController _onRestored =
     new ChromeStreamController.noArgs(_app_window, 'onRestored');

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

Extends

ChromeApi > ChromeAppWindow

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 => _app_window != null;

final Stream onBoundsChanged #

Stream get onBoundsChanged => _onBoundsChanged.stream;

final Stream onClosed #

Stream get onClosed => _onClosed.stream;

final Stream onFullscreened #

Stream get onFullscreened => _onFullscreened.stream;

final Stream onMaximized #

Stream get onMaximized => _onMaximized.stream;

final Stream onMinimized #

Stream get onMinimized => _onMinimized.stream;

final Stream onRestored #

Stream get onRestored => _onRestored.stream;

Methods

Future<AppWindow> create(String url, [CreateWindowOptions options]) #

The size and position of a window can be specified in a number of different ways. The most simple option is not specifying anything at all, in which case a default size and platform dependent position will be used.

Another option is to use the bounds property, which will put the window at the specified coordinates with the specified size. If the window has a frame, it's total size will be the size given plus the size of the frame; that is, the size in bounds is the content size, not the window size.

To automatically remember the positions of windows you can give them ids. If a window has an id, This id is used to remember the size and position of the window whenever it is moved or resized. This size and position is then used instead of the specified bounds on subsequent opening of a window with the same id. If you need to open a window with an id at a location other than the remembered default, you can create it hidden, move it to the desired location, then show it.

Returns: Called in the creating window (parent) before the load event is called in the created window (child). The parent can set fields or functions on the child usable from onload. E.g. background.js:

function(created_window) { created_window.contentWindow.foo = function () { }; };

window.js:

window.onload = function () { foo(); }

Future<AppWindow> create(String url, [CreateWindowOptions options]) {
 if (_app_window == null) _throwNotAvailable();

 var completer = new ChromeCompleter<AppWindow>.oneArg(_createAppWindow);
 _app_window.callMethod('create', [url, jsify(options), completer.callback]);
 return completer.future;
}

AppWindow current() #

Returns an AppWindow object for the current script context (ie JavaScript 'window' object). This can also be called on a handle to a script context for another page, for example: otherWindow.chrome.app.window.current().

AppWindow current() {
 if (_app_window == null) _throwNotAvailable();

 return _createAppWindow(_app_window.callMethod('current'));
}

void initializeAppWindow(state) #

void initializeAppWindow(dynamic state) {
 if (_app_window == null) _throwNotAvailable();

 _app_window.callMethod('initializeAppWindow', [jsify(state)]);
}