Dart Documentationchrome.cookiesChromeCookies

ChromeCookies class

class ChromeCookies extends ChromeApi {
 static final JsObject _cookies = chrome['cookies'];

 ChromeCookies._();

 bool get available => _cookies != null;

 /**
  * Retrieves information about a single cookie. If more than one cookie of the
  * same name exists for the given URL, the one with the longest path will be
  * returned. For cookies with the same path length, the cookie with the
  * earliest creation time will be returned.
  * 
  * [details] Details to identify the cookie being retrieved.
  * 
  * Returns:
  * Contains details about the cookie. This parameter is null if no such cookie
  * was found.
  */
 Future<Cookie> get(CookiesGetParams details) {
   if (_cookies == null) _throwNotAvailable();

   var completer = new ChromeCompleter<Cookie>.oneArg(_createCookie);
   _cookies.callMethod('get', [jsify(details), completer.callback]);
   return completer.future;
 }

 /**
  * Retrieves all cookies from a single cookie store that match the given
  * information.  The cookies returned will be sorted, with those with the
  * longest path first.  If multiple cookies have the same path length, those
  * with the earliest creation time will be first.
  * 
  * [details] Information to filter the cookies being retrieved.
  * 
  * Returns:
  * All the existing, unexpired cookies that match the given cookie info.
  */
 Future<List<Cookie>> getAll(CookiesGetAllParams details) {
   if (_cookies == null) _throwNotAvailable();

   var completer = new ChromeCompleter<List<Cookie>>.oneArg((e) => listify(e, _createCookie));
   _cookies.callMethod('getAll', [jsify(details), completer.callback]);
   return completer.future;
 }

 /**
  * Sets a cookie with the given cookie data; may overwrite equivalent cookies
  * if they exist.
  * 
  * [details] Details about the cookie being set.
  * 
  * Returns:
  * Contains details about the cookie that's been set.  If setting failed for
  * any reason, this will be "null", and "chrome.runtime.lastError" will be
  * set.
  */
 Future<Cookie> set(CookiesSetParams details) {
   if (_cookies == null) _throwNotAvailable();

   var completer = new ChromeCompleter<Cookie>.oneArg(_createCookie);
   _cookies.callMethod('set', [jsify(details), completer.callback]);
   return completer.future;
 }

 /**
  * Deletes a cookie by name.
  * 
  * [details] Information to identify the cookie to remove.
  * 
  * Returns:
  * Contains details about the cookie that's been removed.  If removal failed
  * for any reason, this will be "null", and "chrome.runtime.lastError" will be
  * set.
  */
 Future<Map> remove(CookiesRemoveParams details) {
   if (_cookies == null) _throwNotAvailable();

   var completer = new ChromeCompleter<Map>.oneArg(mapify);
   _cookies.callMethod('remove', [jsify(details), completer.callback]);
   return completer.future;
 }

 /**
  * Lists all existing cookie stores.
  * 
  * Returns:
  * All the existing cookie stores.
  */
 Future<List<CookieStore>> getAllCookieStores() {
   if (_cookies == null) _throwNotAvailable();

   var completer = new ChromeCompleter<List<CookieStore>>.oneArg((e) => listify(e, _createCookieStore));
   _cookies.callMethod('getAllCookieStores', [completer.callback]);
   return completer.future;
 }

 /**
  * Fired when a cookie is set or removed. As a special case, note that
  * updating a cookie's properties is implemented as a two step process: the
  * cookie to be updated is first removed entirely, generating a notification
  * with "cause" of "overwrite" .  Afterwards, a new cookie is written with the
  * updated values, generating a second notification with "cause" "explicit".
  */
 Stream<Map> get onChanged => _onChanged.stream;

 final ChromeStreamController<Map> _onChanged =
     new ChromeStreamController<Map>.oneArg(_cookies, 'onChanged', mapify);

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

Extends

ChromeApi > ChromeCookies

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

final Stream<Map> onChanged #

Fired when a cookie is set or removed. As a special case, note that updating a cookie's properties is implemented as a two step process: the cookie to be updated is first removed entirely, generating a notification with "cause" of "overwrite" . Afterwards, a new cookie is written with the updated values, generating a second notification with "cause" "explicit".

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

Methods

Future<Cookie> get(CookiesGetParams details) #

Retrieves information about a single cookie. If more than one cookie of the same name exists for the given URL, the one with the longest path will be returned. For cookies with the same path length, the cookie with the earliest creation time will be returned.

details Details to identify the cookie being retrieved.

Returns: Contains details about the cookie. This parameter is null if no such cookie was found.

Future<Cookie> get(CookiesGetParams details) {
 if (_cookies == null) _throwNotAvailable();

 var completer = new ChromeCompleter<Cookie>.oneArg(_createCookie);
 _cookies.callMethod('get', [jsify(details), completer.callback]);
 return completer.future;
}

Future<List<Cookie>> getAll(CookiesGetAllParams details) #

Retrieves all cookies from a single cookie store that match the given information. The cookies returned will be sorted, with those with the longest path first. If multiple cookies have the same path length, those with the earliest creation time will be first.

details Information to filter the cookies being retrieved.

Returns: All the existing, unexpired cookies that match the given cookie info.

Future<List<Cookie>> getAll(CookiesGetAllParams details) {
 if (_cookies == null) _throwNotAvailable();

 var completer = new ChromeCompleter<List<Cookie>>.oneArg((e) => listify(e, _createCookie));
 _cookies.callMethod('getAll', [jsify(details), completer.callback]);
 return completer.future;
}

Future<List<CookieStore>> getAllCookieStores() #

Lists all existing cookie stores.

Returns: All the existing cookie stores.

Future<List<CookieStore>> getAllCookieStores() {
 if (_cookies == null) _throwNotAvailable();

 var completer = new ChromeCompleter<List<CookieStore>>.oneArg((e) => listify(e, _createCookieStore));
 _cookies.callMethod('getAllCookieStores', [completer.callback]);
 return completer.future;
}

Future<Map> remove(CookiesRemoveParams details) #

Deletes a cookie by name.

details Information to identify the cookie to remove.

Returns: Contains details about the cookie that's been removed. If removal failed for any reason, this will be "null", and "chrome.runtime.lastError" will be set.

Future<Map> remove(CookiesRemoveParams details) {
 if (_cookies == null) _throwNotAvailable();

 var completer = new ChromeCompleter<Map>.oneArg(mapify);
 _cookies.callMethod('remove', [jsify(details), completer.callback]);
 return completer.future;
}

Future<Cookie> set(CookiesSetParams details) #

Sets a cookie with the given cookie data; may overwrite equivalent cookies if they exist.

details Details about the cookie being set.

Returns: Contains details about the cookie that's been set. If setting failed for any reason, this will be "null", and "chrome.runtime.lastError" will be set.

Future<Cookie> set(CookiesSetParams details) {
 if (_cookies == null) _throwNotAvailable();

 var completer = new ChromeCompleter<Cookie>.oneArg(_createCookie);
 _cookies.callMethod('set', [jsify(details), completer.callback]);
 return completer.future;
}