ChromeWindows class
class ChromeWindows extends ChromeApi {
static final JsObject _windows = chrome['windows'];
ChromeWindows._();
bool get available => _windows != null;
/**
* The windowId value that represents the absence of a chrome browser window.
*/
int get WINDOW_ID_NONE => _windows['WINDOW_ID_NONE'];
/**
* The windowId value that represents the [current
* window](windows.html#current-window).
*/
int get WINDOW_ID_CURRENT => _windows['WINDOW_ID_CURRENT'];
/**
* Gets details about a window.
*
* [getInfo]
*/
Future<Window> get(int windowId, [WindowsGetParams getInfo]) {
if (_windows == null) _throwNotAvailable();
var completer = new ChromeCompleter<Window>.oneArg(_createWindow);
_windows.callMethod('get', [windowId, jsify(getInfo), completer.callback]);
return completer.future;
}
/**
* Gets the [current window](#current-window).
*
* [getInfo]
*/
Future<Window> getCurrent([WindowsGetCurrentParams getInfo]) {
if (_windows == null) _throwNotAvailable();
var completer = new ChromeCompleter<Window>.oneArg(_createWindow);
_windows.callMethod('getCurrent', [jsify(getInfo), completer.callback]);
return completer.future;
}
/**
* Gets the window that was most recently focused - typically the window 'on
* top'.
*
* [getInfo]
*/
Future<Window> getLastFocused([WindowsGetLastFocusedParams getInfo]) {
if (_windows == null) _throwNotAvailable();
var completer = new ChromeCompleter<Window>.oneArg(_createWindow);
_windows.callMethod('getLastFocused', [jsify(getInfo), completer.callback]);
return completer.future;
}
/**
* Gets all windows.
*
* [getInfo]
*/
Future<List<Window>> getAll([WindowsGetAllParams getInfo]) {
if (_windows == null) _throwNotAvailable();
var completer = new ChromeCompleter<List<Window>>.oneArg((e) => listify(e, _createWindow));
_windows.callMethod('getAll', [jsify(getInfo), completer.callback]);
return completer.future;
}
/**
* Creates (opens) a new browser with any optional sizing, position or default
* URL provided.
*
* Returns:
* Contains details about the created window.
*/
Future<Window> create([WindowsCreateParams createData]) {
if (_windows == null) _throwNotAvailable();
var completer = new ChromeCompleter<Window>.oneArg(_createWindow);
_windows.callMethod('create', [jsify(createData), completer.callback]);
return completer.future;
}
/**
* Updates the properties of a window. Specify only the properties that you
* want to change; unspecified properties will be left unchanged.
*/
Future<Window> update(int windowId, WindowsUpdateParams updateInfo) {
if (_windows == null) _throwNotAvailable();
var completer = new ChromeCompleter<Window>.oneArg(_createWindow);
_windows.callMethod('update', [windowId, jsify(updateInfo), completer.callback]);
return completer.future;
}
/**
* Removes (closes) a window, and all the tabs inside it.
*/
Future remove(int windowId) {
if (_windows == null) _throwNotAvailable();
var completer = new ChromeCompleter.noArgs();
_windows.callMethod('remove', [windowId, completer.callback]);
return completer.future;
}
/**
* Fired when a window is created.
*/
Stream<Window> get onCreated => _onCreated.stream;
final ChromeStreamController<Window> _onCreated =
new ChromeStreamController<Window>.oneArg(_windows, 'onCreated', _createWindow);
/**
* Fired when a window is removed (closed).
*/
Stream<int> get onRemoved => _onRemoved.stream;
final ChromeStreamController<int> _onRemoved =
new ChromeStreamController<int>.oneArg(_windows, 'onRemoved', selfConverter);
/**
* Fired when the currently focused window changes. Will be
* chrome.windows.WINDOW_ID_NONE if all chrome windows have lost focus. Note:
* On some Linux window managers, WINDOW_ID_NONE will always be sent
* immediately preceding a switch from one chrome window to another.
*/
Stream<int> get onFocusChanged => _onFocusChanged.stream;
final ChromeStreamController<int> _onFocusChanged =
new ChromeStreamController<int>.oneArg(_windows, 'onFocusChanged', selfConverter);
void _throwNotAvailable() {
throw new UnsupportedError("'chrome.windows' is not available");
}
}
Extends
ChromeApi > ChromeWindows
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
bool get available => _windows != null;
final Stream<Window> onCreated #
Fired when a window is created.
Stream<Window> get onCreated => _onCreated.stream;
final Stream<int> onFocusChanged #
Fired when the currently focused window changes. Will be chrome.windows.WINDOWIDNONE if all chrome windows have lost focus. Note: On some Linux window managers, WINDOWIDNONE will always be sent immediately preceding a switch from one chrome window to another.
Stream<int> get onFocusChanged => _onFocusChanged.stream;
final Stream<int> onRemoved #
Fired when a window is removed (closed).
Stream<int> get onRemoved => _onRemoved.stream;
final int WINDOW_ID_CURRENT #
The windowId value that represents the current window.
int get WINDOW_ID_CURRENT => _windows['WINDOW_ID_CURRENT'];
final int WINDOW_ID_NONE #
The windowId value that represents the absence of a chrome browser window.
int get WINDOW_ID_NONE => _windows['WINDOW_ID_NONE'];
Methods
Future<Window> create([WindowsCreateParams createData]) #
Creates (opens) a new browser with any optional sizing, position or default URL provided.
Returns: Contains details about the created window.
Future<Window> create([WindowsCreateParams createData]) {
if (_windows == null) _throwNotAvailable();
var completer = new ChromeCompleter<Window>.oneArg(_createWindow);
_windows.callMethod('create', [jsify(createData), completer.callback]);
return completer.future;
}
Future<Window> get(int windowId, [WindowsGetParams getInfo]) #
Gets details about a window.
getInfo
Future<Window> get(int windowId, [WindowsGetParams getInfo]) {
if (_windows == null) _throwNotAvailable();
var completer = new ChromeCompleter<Window>.oneArg(_createWindow);
_windows.callMethod('get', [windowId, jsify(getInfo), completer.callback]);
return completer.future;
}
Future<List<Window>> getAll([WindowsGetAllParams getInfo]) #
Gets all windows.
getInfo
Future<List<Window>> getAll([WindowsGetAllParams getInfo]) {
if (_windows == null) _throwNotAvailable();
var completer = new ChromeCompleter<List<Window>>.oneArg((e) => listify(e, _createWindow));
_windows.callMethod('getAll', [jsify(getInfo), completer.callback]);
return completer.future;
}
Future<Window> getCurrent([WindowsGetCurrentParams getInfo]) #
Gets the current window.
getInfo
Future<Window> getCurrent([WindowsGetCurrentParams getInfo]) {
if (_windows == null) _throwNotAvailable();
var completer = new ChromeCompleter<Window>.oneArg(_createWindow);
_windows.callMethod('getCurrent', [jsify(getInfo), completer.callback]);
return completer.future;
}
Future<Window> getLastFocused([WindowsGetLastFocusedParams getInfo]) #
Gets the window that was most recently focused - typically the window 'on top'.
getInfo
Future<Window> getLastFocused([WindowsGetLastFocusedParams getInfo]) {
if (_windows == null) _throwNotAvailable();
var completer = new ChromeCompleter<Window>.oneArg(_createWindow);
_windows.callMethod('getLastFocused', [jsify(getInfo), completer.callback]);
return completer.future;
}
Future remove(int windowId) #
Removes (closes) a window, and all the tabs inside it.
Future remove(int windowId) {
if (_windows == null) _throwNotAvailable();
var completer = new ChromeCompleter.noArgs();
_windows.callMethod('remove', [windowId, completer.callback]);
return completer.future;
}
Future<Window> update(int windowId, WindowsUpdateParams updateInfo) #
Updates the properties of a window. Specify only the properties that you want to change; unspecified properties will be left unchanged.
Future<Window> update(int windowId, WindowsUpdateParams updateInfo) {
if (_windows == null) _throwNotAvailable();
var completer = new ChromeCompleter<Window>.oneArg(_createWindow);
_windows.callMethod('update', [windowId, jsify(updateInfo), completer.callback]);
return completer.future;
}