Dart Documentationchrome.bookmarksChromeBookmarks

ChromeBookmarks class

class ChromeBookmarks extends ChromeApi {
 static final JsObject _bookmarks = chrome['bookmarks'];

 ChromeBookmarks._();

 bool get available => _bookmarks != null;

 /**
  * The maximum number of `move`, `update`, `create`, or `remove` operations
  * that can be performed each hour. Updates that would cause this limit to be
  * exceeded fail.
  */
 int get MAX_WRITE_OPERATIONS_PER_HOUR => _bookmarks['MAX_WRITE_OPERATIONS_PER_HOUR'];

 /**
  * The maximum number of `move`, `update`, `create`, or `remove` operations
  * that can be performed each minute, sustained over 10 minutes. Updates that
  * would cause this limit to be exceeded fail.
  */
 int get MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE => _bookmarks['MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE'];

 /**
  * Retrieves the specified BookmarkTreeNode(s).
  * 
  * [idOrIdList] A single string-valued id, or an array of string-valued ids
  */
 Future<List<BookmarkTreeNode>> get(dynamic idOrIdList) {
   if (_bookmarks == null) _throwNotAvailable();

   var completer = new ChromeCompleter<List<BookmarkTreeNode>>.oneArg((e) => listify(e, _createBookmarkTreeNode));
   _bookmarks.callMethod('get', [jsify(idOrIdList), completer.callback]);
   return completer.future;
 }

 /**
  * Retrieves the children of the specified BookmarkTreeNode id.
  */
 Future<List<BookmarkTreeNode>> getChildren(String id) {
   if (_bookmarks == null) _throwNotAvailable();

   var completer = new ChromeCompleter<List<BookmarkTreeNode>>.oneArg((e) => listify(e, _createBookmarkTreeNode));
   _bookmarks.callMethod('getChildren', [id, completer.callback]);
   return completer.future;
 }

 /**
  * Retrieves the recently added bookmarks.
  * 
  * [numberOfItems] The maximum number of items to return.
  */
 Future<List<BookmarkTreeNode>> getRecent(int numberOfItems) {
   if (_bookmarks == null) _throwNotAvailable();

   var completer = new ChromeCompleter<List<BookmarkTreeNode>>.oneArg((e) => listify(e, _createBookmarkTreeNode));
   _bookmarks.callMethod('getRecent', [numberOfItems, completer.callback]);
   return completer.future;
 }

 /**
  * Retrieves the entire Bookmarks hierarchy.
  */
 Future<List<BookmarkTreeNode>> getTree() {
   if (_bookmarks == null) _throwNotAvailable();

   var completer = new ChromeCompleter<List<BookmarkTreeNode>>.oneArg((e) => listify(e, _createBookmarkTreeNode));
   _bookmarks.callMethod('getTree', [completer.callback]);
   return completer.future;
 }

 /**
  * Retrieves part of the Bookmarks hierarchy, starting at the specified node.
  * 
  * [id] The ID of the root of the subtree to retrieve.
  */
 Future<List<BookmarkTreeNode>> getSubTree(String id) {
   if (_bookmarks == null) _throwNotAvailable();

   var completer = new ChromeCompleter<List<BookmarkTreeNode>>.oneArg((e) => listify(e, _createBookmarkTreeNode));
   _bookmarks.callMethod('getSubTree', [id, completer.callback]);
   return completer.future;
 }

 /**
  * Searches for BookmarkTreeNodes matching the given query.
  */
 Future<List<BookmarkTreeNode>> search(String query) {
   if (_bookmarks == null) _throwNotAvailable();

   var completer = new ChromeCompleter<List<BookmarkTreeNode>>.oneArg((e) => listify(e, _createBookmarkTreeNode));
   _bookmarks.callMethod('search', [query, completer.callback]);
   return completer.future;
 }

 /**
  * Creates a bookmark or folder under the specified parentId.  If url is NULL
  * or missing, it will be a folder.
  */
 Future<BookmarkTreeNode> create(BookmarksCreateParams bookmark) {
   if (_bookmarks == null) _throwNotAvailable();

   var completer = new ChromeCompleter<BookmarkTreeNode>.oneArg(_createBookmarkTreeNode);
   _bookmarks.callMethod('create', [jsify(bookmark), completer.callback]);
   return completer.future;
 }

 /**
  * Moves the specified BookmarkTreeNode to the provided location.
  */
 Future<BookmarkTreeNode> move(String id, BookmarksMoveParams destination) {
   if (_bookmarks == null) _throwNotAvailable();

   var completer = new ChromeCompleter<BookmarkTreeNode>.oneArg(_createBookmarkTreeNode);
   _bookmarks.callMethod('move', [id, jsify(destination), completer.callback]);
   return completer.future;
 }

 /**
  * Updates the properties of a bookmark or folder. Specify only the properties
  * that you want to change; unspecified properties will be left unchanged.
  * <b>Note:</b> Currently, only 'title' and 'url' are supported.
  */
 Future<BookmarkTreeNode> update(String id, BookmarksUpdateParams changes) {
   if (_bookmarks == null) _throwNotAvailable();

   var completer = new ChromeCompleter<BookmarkTreeNode>.oneArg(_createBookmarkTreeNode);
   _bookmarks.callMethod('update', [id, jsify(changes), completer.callback]);
   return completer.future;
 }

 /**
  * Removes a bookmark or an empty bookmark folder.
  */
 Future remove(String id) {
   if (_bookmarks == null) _throwNotAvailable();

   var completer = new ChromeCompleter.noArgs();
   _bookmarks.callMethod('remove', [id, completer.callback]);
   return completer.future;
 }

 /**
  * Recursively removes a bookmark folder.
  */
 Future removeTree(String id) {
   if (_bookmarks == null) _throwNotAvailable();

   var completer = new ChromeCompleter.noArgs();
   _bookmarks.callMethod('removeTree', [id, completer.callback]);
   return completer.future;
 }

 /**
  * Imports bookmarks from a chrome html bookmark file
  */
 Future import() {
   if (_bookmarks == null) _throwNotAvailable();

   var completer = new ChromeCompleter.noArgs();
   _bookmarks.callMethod('import', [completer.callback]);
   return completer.future;
 }

 /**
  * Exports bookmarks to a chrome html bookmark file
  */
 Future export() {
   if (_bookmarks == null) _throwNotAvailable();

   var completer = new ChromeCompleter.noArgs();
   _bookmarks.callMethod('export', [completer.callback]);
   return completer.future;
 }

 /**
  * Fired when a bookmark or folder is created.
  */
 Stream<OnCreatedEvent> get onCreated => _onCreated.stream;

 final ChromeStreamController<OnCreatedEvent> _onCreated =
     new ChromeStreamController<OnCreatedEvent>.twoArgs(_bookmarks, 'onCreated', _createOnCreatedEvent);

 /**
  * Fired when a bookmark or folder is removed.  When a folder is removed
  * recursively, a single notification is fired for the folder, and none for
  * its contents.
  */
 Stream<BookmarksOnRemovedEvent> get onRemoved => _onRemoved.stream;

 final ChromeStreamController<BookmarksOnRemovedEvent> _onRemoved =
     new ChromeStreamController<BookmarksOnRemovedEvent>.twoArgs(_bookmarks, 'onRemoved', _createOnRemovedEvent);

 /**
  * Fired when a bookmark or folder changes.  <b>Note:</b> Currently, only
  * title and url changes trigger this.
  */
 Stream<BookmarksOnChangedEvent> get onChanged => _onChanged.stream;

 final ChromeStreamController<BookmarksOnChangedEvent> _onChanged =
     new ChromeStreamController<BookmarksOnChangedEvent>.twoArgs(_bookmarks, 'onChanged', _createOnChangedEvent);

 /**
  * Fired when a bookmark or folder is moved to a different parent folder.
  */
 Stream<BookmarksOnMovedEvent> get onMoved => _onMoved.stream;

 final ChromeStreamController<BookmarksOnMovedEvent> _onMoved =
     new ChromeStreamController<BookmarksOnMovedEvent>.twoArgs(_bookmarks, 'onMoved', _createOnMovedEvent);

 /**
  * Fired when the children of a folder have changed their order due to the
  * order being sorted in the UI.  This is not called as a result of a move().
  */
 Stream<OnChildrenReorderedEvent> get onChildrenReordered => _onChildrenReordered.stream;

 final ChromeStreamController<OnChildrenReorderedEvent> _onChildrenReordered =
     new ChromeStreamController<OnChildrenReorderedEvent>.twoArgs(_bookmarks, 'onChildrenReordered', _createOnChildrenReorderedEvent);

 /**
  * Fired when a bookmark import session is begun.  Expensive observers should
  * ignore onCreated updates until onImportEnded is fired.  Observers should
  * still handle other notifications immediately.
  */
 Stream get onImportBegan => _onImportBegan.stream;

 final ChromeStreamController _onImportBegan =
     new ChromeStreamController.noArgs(_bookmarks, 'onImportBegan');

 /**
  * Fired when a bookmark import session is ended.
  */
 Stream get onImportEnded => _onImportEnded.stream;

 final ChromeStreamController _onImportEnded =
     new ChromeStreamController.noArgs(_bookmarks, 'onImportEnded');

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

Extends

ChromeApi > ChromeBookmarks

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

final int MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE #

The maximum number of move, update, create, or remove operations that can be performed each minute, sustained over 10 minutes. Updates that would cause this limit to be exceeded fail.

int get MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE => _bookmarks['MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE'];

final int MAX_WRITE_OPERATIONS_PER_HOUR #

The maximum number of move, update, create, or remove operations that can be performed each hour. Updates that would cause this limit to be exceeded fail.

int get MAX_WRITE_OPERATIONS_PER_HOUR => _bookmarks['MAX_WRITE_OPERATIONS_PER_HOUR'];

final Stream<BookmarksOnChangedEvent> onChanged #

Fired when a bookmark or folder changes. <b>Note:</b> Currently, only title and url changes trigger this.

Stream<BookmarksOnChangedEvent> get onChanged => _onChanged.stream;

final Stream<OnChildrenReorderedEvent> onChildrenReordered #

Fired when the children of a folder have changed their order due to the order being sorted in the UI. This is not called as a result of a move().

Stream<OnChildrenReorderedEvent> get onChildrenReordered => _onChildrenReordered.stream;

final Stream<OnCreatedEvent> onCreated #

Fired when a bookmark or folder is created.

Stream<OnCreatedEvent> get onCreated => _onCreated.stream;

final Stream onImportBegan #

Fired when a bookmark import session is begun. Expensive observers should ignore onCreated updates until onImportEnded is fired. Observers should still handle other notifications immediately.

Stream get onImportBegan => _onImportBegan.stream;

final Stream onImportEnded #

Fired when a bookmark import session is ended.

Stream get onImportEnded => _onImportEnded.stream;

final Stream<BookmarksOnMovedEvent> onMoved #

Fired when a bookmark or folder is moved to a different parent folder.

Stream<BookmarksOnMovedEvent> get onMoved => _onMoved.stream;

final Stream<BookmarksOnRemovedEvent> onRemoved #

Fired when a bookmark or folder is removed. When a folder is removed recursively, a single notification is fired for the folder, and none for its contents.

Stream<BookmarksOnRemovedEvent> get onRemoved => _onRemoved.stream;

Methods

Future<BookmarkTreeNode> create(BookmarksCreateParams bookmark) #

Creates a bookmark or folder under the specified parentId. If url is NULL or missing, it will be a folder.

Future<BookmarkTreeNode> create(BookmarksCreateParams bookmark) {
 if (_bookmarks == null) _throwNotAvailable();

 var completer = new ChromeCompleter<BookmarkTreeNode>.oneArg(_createBookmarkTreeNode);
 _bookmarks.callMethod('create', [jsify(bookmark), completer.callback]);
 return completer.future;
}

Future export() #

Exports bookmarks to a chrome html bookmark file

Future export() {
 if (_bookmarks == null) _throwNotAvailable();

 var completer = new ChromeCompleter.noArgs();
 _bookmarks.callMethod('export', [completer.callback]);
 return completer.future;
}

Future<List<BookmarkTreeNode>> get(idOrIdList) #

Retrieves the specified BookmarkTreeNode(s).

idOrIdList A single string-valued id, or an array of string-valued ids

Future<List<BookmarkTreeNode>> get(dynamic idOrIdList) {
 if (_bookmarks == null) _throwNotAvailable();

 var completer = new ChromeCompleter<List<BookmarkTreeNode>>.oneArg((e) => listify(e, _createBookmarkTreeNode));
 _bookmarks.callMethod('get', [jsify(idOrIdList), completer.callback]);
 return completer.future;
}

Future<List<BookmarkTreeNode>> getChildren(String id) #

Retrieves the children of the specified BookmarkTreeNode id.

Future<List<BookmarkTreeNode>> getChildren(String id) {
 if (_bookmarks == null) _throwNotAvailable();

 var completer = new ChromeCompleter<List<BookmarkTreeNode>>.oneArg((e) => listify(e, _createBookmarkTreeNode));
 _bookmarks.callMethod('getChildren', [id, completer.callback]);
 return completer.future;
}

Future<List<BookmarkTreeNode>> getRecent(int numberOfItems) #

Retrieves the recently added bookmarks.

numberOfItems The maximum number of items to return.

Future<List<BookmarkTreeNode>> getRecent(int numberOfItems) {
 if (_bookmarks == null) _throwNotAvailable();

 var completer = new ChromeCompleter<List<BookmarkTreeNode>>.oneArg((e) => listify(e, _createBookmarkTreeNode));
 _bookmarks.callMethod('getRecent', [numberOfItems, completer.callback]);
 return completer.future;
}

Future<List<BookmarkTreeNode>> getSubTree(String id) #

Retrieves part of the Bookmarks hierarchy, starting at the specified node.

id The ID of the root of the subtree to retrieve.

Future<List<BookmarkTreeNode>> getSubTree(String id) {
 if (_bookmarks == null) _throwNotAvailable();

 var completer = new ChromeCompleter<List<BookmarkTreeNode>>.oneArg((e) => listify(e, _createBookmarkTreeNode));
 _bookmarks.callMethod('getSubTree', [id, completer.callback]);
 return completer.future;
}

Future<List<BookmarkTreeNode>> getTree() #

Retrieves the entire Bookmarks hierarchy.

Future<List<BookmarkTreeNode>> getTree() {
 if (_bookmarks == null) _throwNotAvailable();

 var completer = new ChromeCompleter<List<BookmarkTreeNode>>.oneArg((e) => listify(e, _createBookmarkTreeNode));
 _bookmarks.callMethod('getTree', [completer.callback]);
 return completer.future;
}

Future import() #

Imports bookmarks from a chrome html bookmark file

Future import() {
 if (_bookmarks == null) _throwNotAvailable();

 var completer = new ChromeCompleter.noArgs();
 _bookmarks.callMethod('import', [completer.callback]);
 return completer.future;
}

Future<BookmarkTreeNode> move(String id, BookmarksMoveParams destination) #

Moves the specified BookmarkTreeNode to the provided location.

Future<BookmarkTreeNode> move(String id, BookmarksMoveParams destination) {
 if (_bookmarks == null) _throwNotAvailable();

 var completer = new ChromeCompleter<BookmarkTreeNode>.oneArg(_createBookmarkTreeNode);
 _bookmarks.callMethod('move', [id, jsify(destination), completer.callback]);
 return completer.future;
}

Future remove(String id) #

Removes a bookmark or an empty bookmark folder.

Future remove(String id) {
 if (_bookmarks == null) _throwNotAvailable();

 var completer = new ChromeCompleter.noArgs();
 _bookmarks.callMethod('remove', [id, completer.callback]);
 return completer.future;
}

Future removeTree(String id) #

Recursively removes a bookmark folder.

Future removeTree(String id) {
 if (_bookmarks == null) _throwNotAvailable();

 var completer = new ChromeCompleter.noArgs();
 _bookmarks.callMethod('removeTree', [id, completer.callback]);
 return completer.future;
}

Searches for BookmarkTreeNodes matching the given query.

Future<List<BookmarkTreeNode>> search(String query) {
 if (_bookmarks == null) _throwNotAvailable();

 var completer = new ChromeCompleter<List<BookmarkTreeNode>>.oneArg((e) => listify(e, _createBookmarkTreeNode));
 _bookmarks.callMethod('search', [query, completer.callback]);
 return completer.future;
}

Future<BookmarkTreeNode> update(String id, BookmarksUpdateParams changes) #

Updates the properties of a bookmark or folder. Specify only the properties that you want to change; unspecified properties will be left unchanged. <b>Note:</b> Currently, only 'title' and 'url' are supported.

Future<BookmarkTreeNode> update(String id, BookmarksUpdateParams changes) {
 if (_bookmarks == null) _throwNotAvailable();

 var completer = new ChromeCompleter<BookmarkTreeNode>.oneArg(_createBookmarkTreeNode);
 _bookmarks.callMethod('update', [id, jsify(changes), completer.callback]);
 return completer.future;
}