ChromeHistory class
class ChromeHistory extends ChromeApi { static final JsObject _history = chrome['history']; ChromeHistory._(); bool get available => _history != null; /** * Searches the history for the last visit time of each page matching the * query. */ Future<List<HistoryItem>> search(HistorySearchParams query) { if (_history == null) _throwNotAvailable(); var completer = new ChromeCompleter<List<HistoryItem>>.oneArg((e) => listify(e, _createHistoryItem)); _history.callMethod('search', [jsify(query), completer.callback]); return completer.future; } /** * Retrieves information about visits to a URL. */ Future<List<VisitItem>> getVisits(HistoryGetVisitsParams details) { if (_history == null) _throwNotAvailable(); var completer = new ChromeCompleter<List<VisitItem>>.oneArg((e) => listify(e, _createVisitItem)); _history.callMethod('getVisits', [jsify(details), completer.callback]); return completer.future; } /** * Adds a URL to the history at the current time with a [transition * type](#transition_types) of "link". */ Future addUrl(HistoryAddUrlParams details) { if (_history == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _history.callMethod('addUrl', [jsify(details), completer.callback]); return completer.future; } /** * Removes all occurrences of the given URL from the history. */ Future deleteUrl(HistoryDeleteUrlParams details) { if (_history == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _history.callMethod('deleteUrl', [jsify(details), completer.callback]); return completer.future; } /** * Removes all items within the specified date range from the history. Pages * will not be removed from the history unless all visits fall within the * range. */ Future deleteRange(HistoryDeleteRangeParams range) { if (_history == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _history.callMethod('deleteRange', [jsify(range), completer.callback]); return completer.future; } /** * Deletes all items from the history. */ Future deleteAll() { if (_history == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _history.callMethod('deleteAll', [completer.callback]); return completer.future; } /** * Fired when a URL is visited, providing the HistoryItem data for that URL. * This event fires before the page has loaded. */ Stream<HistoryItem> get onVisited => _onVisited.stream; final ChromeStreamController<HistoryItem> _onVisited = new ChromeStreamController<HistoryItem>.oneArg(_history, 'onVisited', _createHistoryItem); /** * Fired when one or more URLs are removed from the history service. When all * visits have been removed the URL is purged from history. */ Stream<Map> get onVisitRemoved => _onVisitRemoved.stream; final ChromeStreamController<Map> _onVisitRemoved = new ChromeStreamController<Map>.oneArg(_history, 'onVisitRemoved', mapify); void _throwNotAvailable() { throw new UnsupportedError("'chrome.history' is not available"); } }
Extends
ChromeApi > ChromeHistory
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 => _history != null;
final Stream<HistoryItem> onVisited #
Fired when a URL is visited, providing the HistoryItem data for that URL. This event fires before the page has loaded.
Stream<HistoryItem> get onVisited => _onVisited.stream;
final Stream<Map> onVisitRemoved #
Fired when one or more URLs are removed from the history service. When all visits have been removed the URL is purged from history.
Stream<Map> get onVisitRemoved => _onVisitRemoved.stream;
Methods
Future addUrl(HistoryAddUrlParams details) #
Adds a URL to the history at the current time with a transition type of "link".
Future addUrl(HistoryAddUrlParams details) { if (_history == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _history.callMethod('addUrl', [jsify(details), completer.callback]); return completer.future; }
Future deleteAll() #
Deletes all items from the history.
Future deleteAll() { if (_history == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _history.callMethod('deleteAll', [completer.callback]); return completer.future; }
Future deleteRange(HistoryDeleteRangeParams range) #
Removes all items within the specified date range from the history. Pages will not be removed from the history unless all visits fall within the range.
Future deleteRange(HistoryDeleteRangeParams range) { if (_history == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _history.callMethod('deleteRange', [jsify(range), completer.callback]); return completer.future; }
Future deleteUrl(HistoryDeleteUrlParams details) #
Removes all occurrences of the given URL from the history.
Future deleteUrl(HistoryDeleteUrlParams details) { if (_history == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _history.callMethod('deleteUrl', [jsify(details), completer.callback]); return completer.future; }
Future<List<VisitItem>> getVisits(HistoryGetVisitsParams details) #
Retrieves information about visits to a URL.
Future<List<VisitItem>> getVisits(HistoryGetVisitsParams details) { if (_history == null) _throwNotAvailable(); var completer = new ChromeCompleter<List<VisitItem>>.oneArg((e) => listify(e, _createVisitItem)); _history.callMethod('getVisits', [jsify(details), completer.callback]); return completer.future; }
Future<List<HistoryItem>> search(HistorySearchParams query) #
Searches the history for the last visit time of each page matching the query.
Future<List<HistoryItem>> search(HistorySearchParams query) { if (_history == null) _throwNotAvailable(); var completer = new ChromeCompleter<List<HistoryItem>>.oneArg((e) => listify(e, _createHistoryItem)); _history.callMethod('search', [jsify(query), completer.callback]); return completer.future; }