public interface CookieStore extends ProfileService
Cookies can be stored in the process memory (session cookies) or on the file system (persistent cookies). The service provides access to both the session and persistent cookies.
The persistent cookies are stored in the user data directory. You can configure the user data
directory path via the
EngineOptions.Builder.userDataDir(Path)
method. For example:
Engine engine = Engine.newInstance(EngineOptions.newBuilder(renderingMode) .userDataDir(Paths.get("/Users/MyApp/Data")) .build());
All the changes to the cookie store are made in memory, so when you restart the application
you will not see the changes you made with the persistent cookies if you do not invoke the
persist()
method before application exit.
Modifier and Type | Method and Description |
---|---|
java.util.List<Cookie> |
cookies()
Returns an immutable list of all the cookies available in the cookie store.
|
java.util.List<Cookie> |
cookies(java.lang.String url)
Returns an immutable list of cookies for the given
url . |
void |
delete(Cookie cookie)
Deletes the given
cookie from the cookie store. |
int |
deleteAll()
Deletes all the cookies from the cookie store and returns the number of deleted cookies.
|
void |
persist()
Persists all the changes performed to the cookie store.
|
void |
set(Cookie cookie)
Sets the
cookie . |
profile
java.util.List<Cookie> cookies()
The returned cookies are ordered by longest path, then by earliest creation time. Can be empty if there are no cookies in the cookie store.
ObjectClosedException
- when the profile is deleted or its engine is closedjava.util.List<Cookie> cookies(java.lang.String url)
url
.
The list includes both the persistent and session cookies.
The returned cookies are ordered by longest path, then by earliest creation time. Can be empty if there are no cookies associated with the given URL in the cookie store.
url
- the URL of the resource to get cookies fromjava.lang.IllegalArgumentException
- when url
is empty or blankObjectClosedException
- when the profile is deleted or its engine is closedvoid delete(Cookie cookie)
cookie
from the cookie store.
Important: this method makes the cookie changes in memory. To keep these changes
for the persistent cookies after application restart you must invoke the persist()
method before application exit.
cookie
- a Cookie
instance to deleteObjectClosedException
- when the profile is deleted or its engine is closedint deleteAll()
Important: this method makes the cookie changes in memory. To keep these changes
for persistent cookies after application restart you must invoke the persist()
method before application exit.
ObjectClosedException
- when the profile is deleted or its engine is closedvoid set(Cookie cookie)
cookie
.
This method expects that each cookie attribute in the given cookie
is
well-formed.
Please note that Chromium may modify some of the cookie attributes (such as domain or expiration time).
Important: this method makes the cookie changes in memory. To keep these changes
for the persistent cookies after the application restart invoke the persist()
method
before the application exit.
cookie
- a cookie to setjava.lang.IllegalArgumentException
- when the cookie can't be setObjectClosedException
- when the profile is deleted or its engine is closedvoid persist()
By default, all the changes to the cookie store are made in memory, so when you restart the application you will not see the changes you made with persistent cookies if you do not invoke this method before application exit.
This method can be invoked after every change you made to the cookie store.
ObjectClosedException
- when the profile is deleted or its engine is closed