19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2006 The Android Open Source Project
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License.
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License.
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.webkit;
189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.net.WebAddress;
2045a9a14006214e6478311ffcb980e766702d5a76Doug Zongker
219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
2277db9990777efd100bee4ec47568414ea039e99bSteve Block * Manages the cookies used by an application's {@link WebView} instances.
2377db9990777efd100bee4ec47568414ea039e99bSteve Block * Cookies are manipulated according to RFC2109.
249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
25939e5040b51539be561db1d18dec18196f201f5cJonathan Dixonpublic class CookieManager {
26d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon    /**
27d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon     * @hide Only for use by WebViewProvider implementations
28d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon     */
29d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon    protected CookieManager() {
309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
32d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon    @Override
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    protected Object clone() throws CloneNotSupportedException {
349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        throw new CloneNotSupportedException("doesn't implement Cloneable");
359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3877db9990777efd100bee4ec47568414ea039e99bSteve Block     * Gets the singleton CookieManager instance. If this method is used
3977db9990777efd100bee4ec47568414ea039e99bSteve Block     * before the application instantiates a {@link WebView} instance,
40c723e35336e764a1e708f1a4a8ee3f7bff711c0fSteve Block     * {@link CookieSyncManager#createInstance CookieSyncManager.createInstance(Context)}
41c723e35336e764a1e708f1a4a8ee3f7bff711c0fSteve Block     * must be called first.
42d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon     *
434e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @return the singleton CookieManager instance
4406312cae6b0e00c4ccbe84e9c682de8d607897a9Patrick Scott     */
459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static synchronized CookieManager getInstance() {
46d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        return WebViewFactory.getProvider().getCookieManager();
479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
5077db9990777efd100bee4ec47568414ea039e99bSteve Block     * Sets whether the application's {@link WebView} instances should send and
5177db9990777efd100bee4ec47568414ea039e99bSteve Block     * accept cookies.
529f59526f0389ff17027ecdca7b3e31a729b2937bHector Dearman     * By default this is set to true and the WebView accepts cookies.
539f59526f0389ff17027ecdca7b3e31a729b2937bHector Dearman     * <p>
549f59526f0389ff17027ecdca7b3e31a729b2937bHector Dearman     * When this is true
559f59526f0389ff17027ecdca7b3e31a729b2937bHector Dearman     * {@link CookieManager#setAcceptThirdPartyCookies setAcceptThirdPartyCookies} and
569f59526f0389ff17027ecdca7b3e31a729b2937bHector Dearman     * {@link CookieManager#setAcceptFileSchemeCookies setAcceptFileSchemeCookies}
579f59526f0389ff17027ecdca7b3e31a729b2937bHector Dearman     * can be used to control the policy for those specific types of cookie.
584e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     *
594e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @param accept whether {@link WebView} instances should send and accept
6077db9990777efd100bee4ec47568414ea039e99bSteve Block     *               cookies
619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public synchronized void setAcceptCookie(boolean accept) {
63d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        throw new MustOverrideException();
649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
6777db9990777efd100bee4ec47568414ea039e99bSteve Block     * Gets whether the application's {@link WebView} instances send and accept
6877db9990777efd100bee4ec47568414ea039e99bSteve Block     * cookies.
694e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     *
704e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @return true if {@link WebView} instances send and accept cookies
719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public synchronized boolean acceptCookie() {
73d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        throw new MustOverrideException();
749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
76a70d1d99de6cdadd68176cb849c02d56b8536021Hector Dearman   /**
77fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     * Sets whether the {@link WebView} should allow third party cookies to be set.
78fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     * Allowing third party cookies is a per WebView policy and can be set
79fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     * differently on different WebView instances.
80fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     * <p>
81fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     * Apps that target {@link android.os.Build.VERSION_CODES#KITKAT} or below
82fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     * default to allowing third party cookies. Apps targeting
83955d8d69ea6caabce1461dc25b339b9bf9dc61a6Dianne Hackborn     * {@link android.os.Build.VERSION_CODES#LOLLIPOP} or later default to disallowing
84fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     * third party cookies.
85fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     *
86fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     * @param webview the {@link WebView} instance to set the cookie policy on
87fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     * @param accept whether the {@link WebView} instance should accept
88fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     *               third party cookies
89fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     */
90ffae67288198b941cd8d266ca272474818d2da6cHector Dearman    public void setAcceptThirdPartyCookies(WebView webview, boolean accept) {
91fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman        throw new MustOverrideException();
92fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman    }
93fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman
94fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman    /**
95fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     * Gets whether the {@link WebView} should allow third party cookies to be set.
96fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     *
97fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     * @param webview the {@link WebView} instance to get the cookie policy for
98fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     * @return true if the {@link WebView} accepts third party cookies
99fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman     */
10042a9ee5036f18866a5341c83bb6fcde7c8b355ffHector Dearman    public boolean acceptThirdPartyCookies(WebView webview) {
101fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman        throw new MustOverrideException();
102fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman    }
103fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman
104fc9a27aa5a50d30731bdaa6f69e0434a3557584dHector Dearman    /**
10577db9990777efd100bee4ec47568414ea039e99bSteve Block     * Sets a cookie for the given URL. Any existing cookie with the same host,
10677db9990777efd100bee4ec47568414ea039e99bSteve Block     * path and name will be replaced with the new cookie. The cookie being set
1070ac81cb785241f49abc39ba639abddc33b891971Hector Dearman     * will be ignored if it is expired.
1084e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     *
10924a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * @param url the URL for which the cookie is to be set
1104e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @param value the cookie as a string, using the format of the 'Set-Cookie'
111d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon     *              HTTP response header
1129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void setCookie(String url, String value) {
114d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        throw new MustOverrideException();
1159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
11824a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * Sets a cookie for the given URL. Any existing cookie with the same host,
11924a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * path and name will be replaced with the new cookie. The cookie being set
12024a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * will be ignored if it is expired.
12124a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * <p>
12224a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * This method is asynchronous.
12324a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * If a {@link ValueCallback} is provided,
12424a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * {@link ValueCallback#onReceiveValue(T) onReceiveValue()} will be called on the current
12524a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * thread's {@link android.os.Looper} once the operation is complete.
12624a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * The value provided to the callback indicates whether the cookie was set successfully.
12724a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * You can pass {@code null} as the callback if you don't need to know when the operation
12824a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * completes or whether it succeeded, and in this case it is safe to call the method from a
12924a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * thread without a Looper.
13024a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     *
13124a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * @param url the URL for which the cookie is to be set
13224a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * @param value the cookie as a string, using the format of the 'Set-Cookie'
13324a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     *              HTTP response header
13424a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * @param callback a callback to be executed when the cookie has been set
13524a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     */
13624a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman    public void setCookie(String url, String value, ValueCallback<Boolean> callback) {
13724a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman        throw new MustOverrideException();
13824a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman    }
13924a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman
14024a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman    /**
14177db9990777efd100bee4ec47568414ea039e99bSteve Block     * Gets the cookies for the given URL.
1424e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     *
1434e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @param url the URL for which the cookies are requested
1444e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @return value the cookies as a string, using the format of the 'Cookie'
14577db9990777efd100bee4ec47568414ea039e99bSteve Block     *               HTTP request header
1469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public String getCookie(String url) {
148d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        throw new MustOverrideException();
149469aebbbd92a5300c5ebd6a420ca48976d21e9d1Kristian Monsen    }
150469aebbbd92a5300c5ebd6a420ca48976d21e9d1Kristian Monsen
151469aebbbd92a5300c5ebd6a420ca48976d21e9d1Kristian Monsen    /**
1524e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * See {@link #getCookie(String)}.
1534e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     *
1544e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @param url the URL for which the cookies are requested
1554e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @param privateBrowsing whether to use the private browsing cookie jar
1564e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @return value the cookies as a string, using the format of the 'Cookie'
15777db9990777efd100bee4ec47568414ea039e99bSteve Block     *               HTTP request header
15877db9990777efd100bee4ec47568414ea039e99bSteve Block     * @hide Used by Browser, no intention to publish.
159469aebbbd92a5300c5ebd6a420ca48976d21e9d1Kristian Monsen     */
160469aebbbd92a5300c5ebd6a420ca48976d21e9d1Kristian Monsen    public String getCookie(String url, boolean privateBrowsing) {
161d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        throw new MustOverrideException();
1629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1654e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * Gets cookie(s) for a given uri so that it can be set to "cookie:" in http
1669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * request header.
1674e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     *
1684e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @param uri the WebAddress for which the cookies are requested
1694e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @return value the cookies as a string, using the format of the 'Cookie'
17077db9990777efd100bee4ec47568414ea039e99bSteve Block     *               HTTP request header
17177db9990777efd100bee4ec47568414ea039e99bSteve Block     * @hide Used by RequestHandle, no intention to publish.
1729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public synchronized String getCookie(WebAddress uri) {
174d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        throw new MustOverrideException();
175851730552166bf6e99ed60438ba91f09f36b829fKristian Monsen    }
176851730552166bf6e99ed60438ba91f09f36b829fKristian Monsen
1779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
17877db9990777efd100bee4ec47568414ea039e99bSteve Block     * Removes all session cookies, which are cookies without an expiration
17977db9990777efd100bee4ec47568414ea039e99bSteve Block     * date.
18024a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * @deprecated use {@link #removeSessionCookies(ValueCallback)} instead.
1819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void removeSessionCookie() {
183d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        throw new MustOverrideException();
1849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
18724a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * Removes all session cookies, which are cookies without an expiration
18824a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * date.
18924a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * <p>
19024a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * This method is asynchronous.
19124a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * If a {@link ValueCallback} is provided,
19224a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * {@link ValueCallback#onReceiveValue(T) onReceiveValue()} will be called on the current
19324a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * thread's {@link android.os.Looper} once the operation is complete.
19424a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * The value provided to the callback indicates whether any cookies were removed.
19524a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * You can pass {@code null} as the callback if you don't need to know when the operation
19624a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * completes or whether any cookie were removed, and in this case it is safe to call the
19724a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * method from a thread without a Looper.
19824a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * @param callback a callback which is executed when the session cookies have been removed
19924a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     */
20024a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman    public void removeSessionCookies(ValueCallback<Boolean> callback) {
20124a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman        throw new MustOverrideException();
20224a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman    }
20324a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman
20424a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman    /**
20577db9990777efd100bee4ec47568414ea039e99bSteve Block     * Removes all cookies.
20624a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * @deprecated Use {@link #removeAllCookies(ValueCallback)} instead.
2079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
20824a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman    @Deprecated
2099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void removeAllCookie() {
210d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        throw new MustOverrideException();
2119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
21424a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * Removes all cookies.
21524a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * <p>
21624a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * This method is asynchronous.
21724a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * If a {@link ValueCallback} is provided,
21824a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * {@link ValueCallback#onReceiveValue(T) onReceiveValue()} will be called on the current
21924a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * thread's {@link android.os.Looper} once the operation is complete.
22024a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * The value provided to the callback indicates whether any cookies were removed.
22124a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * You can pass {@code null} as the callback if you don't need to know when the operation
22224a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * completes or whether any cookies were removed, and in this case it is safe to call the
22324a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * method from a thread without a Looper.
22424a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * @param callback a callback which is executed when the cookies have been removed
22524a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     */
22624a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman    public void removeAllCookies(ValueCallback<Boolean> callback) {
22724a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman        throw new MustOverrideException();
22824a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman    }
22924a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman
23024a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman    /**
23177db9990777efd100bee4ec47568414ea039e99bSteve Block     * Gets whether there are stored cookies.
2324e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     *
2334e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @return true if there are stored cookies
2349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public synchronized boolean hasCookies() {
236d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        throw new MustOverrideException();
2379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
240d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon     * See {@link #hasCookies()}.
2414e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     *
2424e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @param privateBrowsing whether to use the private browsing cookie jar
24377db9990777efd100bee4ec47568414ea039e99bSteve Block     * @hide Used by Browser, no intention to publish.
244469aebbbd92a5300c5ebd6a420ca48976d21e9d1Kristian Monsen     */
245469aebbbd92a5300c5ebd6a420ca48976d21e9d1Kristian Monsen    public synchronized boolean hasCookies(boolean privateBrowsing) {
246d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        throw new MustOverrideException();
247469aebbbd92a5300c5ebd6a420ca48976d21e9d1Kristian Monsen    }
248469aebbbd92a5300c5ebd6a420ca48976d21e9d1Kristian Monsen
249469aebbbd92a5300c5ebd6a420ca48976d21e9d1Kristian Monsen    /**
25077db9990777efd100bee4ec47568414ea039e99bSteve Block     * Removes all expired cookies.
25124a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman     * @deprecated The WebView handles removing expired cookies automatically.
2529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
25324a11d311c014c6199d83d97b64565c3bcc25029Hector Dearman    @Deprecated
2549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void removeExpiredCookie() {
255d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon        throw new MustOverrideException();
2569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
2579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
259a70d1d99de6cdadd68176cb849c02d56b8536021Hector Dearman     * Ensures all cookies currently accessible through the getCookie API are
260a70d1d99de6cdadd68176cb849c02d56b8536021Hector Dearman     * written to persistent storage.
261a70d1d99de6cdadd68176cb849c02d56b8536021Hector Dearman     * This call will block the caller until it is done and may perform I/O.
262a70d1d99de6cdadd68176cb849c02d56b8536021Hector Dearman     */
263a70d1d99de6cdadd68176cb849c02d56b8536021Hector Dearman    public void flush() {
264a70d1d99de6cdadd68176cb849c02d56b8536021Hector Dearman        flushCookieStore();
265a70d1d99de6cdadd68176cb849c02d56b8536021Hector Dearman    }
266a70d1d99de6cdadd68176cb849c02d56b8536021Hector Dearman
267a70d1d99de6cdadd68176cb849c02d56b8536021Hector Dearman    /**
2684e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * Flushes all cookies managed by the Chrome HTTP stack to flash.
269d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon     *
270d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon     * @hide Package level api, called from CookieSyncManager
271c40fc2c31a55f7e8312aa2721bf51fcb74bb3a95Iain Merrick     */
272d3101b1d300f5942fdb7dfa323dc8830c4edc007Jonathan Dixon    protected void flushCookieStore() {
273c40fc2c31a55f7e8312aa2721bf51fcb74bb3a95Iain Merrick    }
274c40fc2c31a55f7e8312aa2721bf51fcb74bb3a95Iain Merrick
275c40fc2c31a55f7e8312aa2721bf51fcb74bb3a95Iain Merrick    /**
27677db9990777efd100bee4ec47568414ea039e99bSteve Block     * Gets whether the application's {@link WebView} instances send and accept
27777db9990777efd100bee4ec47568414ea039e99bSteve Block     * cookies for file scheme URLs.
2784e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     *
2794e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * @return true if {@link WebView} instances send and accept cookies for
28077db9990777efd100bee4ec47568414ea039e99bSteve Block     *         file scheme URLs
28116d041cc9f4b67c37abf7dc5f8d49c7de81f2c84Kristian Monsen     */
282be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon    // Static for backward compatibility.
28316d041cc9f4b67c37abf7dc5f8d49c7de81f2c84Kristian Monsen    public static boolean allowFileSchemeCookies() {
284be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon        return getInstance().allowFileSchemeCookiesImpl();
285be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon    }
286be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon
287be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon    /**
2884e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * Implements {@link #allowFileSchemeCookies()}.
2894e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     *
290be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon     * @hide Only for use by WebViewProvider implementations
291be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon     */
292be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon    protected boolean allowFileSchemeCookiesImpl() {
293be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon        throw new MustOverrideException();
29416d041cc9f4b67c37abf7dc5f8d49c7de81f2c84Kristian Monsen    }
29516d041cc9f4b67c37abf7dc5f8d49c7de81f2c84Kristian Monsen
29616d041cc9f4b67c37abf7dc5f8d49c7de81f2c84Kristian Monsen    /**
29777db9990777efd100bee4ec47568414ea039e99bSteve Block     * Sets whether the application's {@link WebView} instances should send and
29877db9990777efd100bee4ec47568414ea039e99bSteve Block     * accept cookies for file scheme URLs.
2999f59526f0389ff17027ecdca7b3e31a729b2937bHector Dearman     * Use of cookies with file scheme URLs is potentially insecure and turned
3009f59526f0389ff17027ecdca7b3e31a729b2937bHector Dearman     * off by default.
3019f59526f0389ff17027ecdca7b3e31a729b2937bHector Dearman     * Do not use this feature unless you can be sure that no unintentional
3029f59526f0389ff17027ecdca7b3e31a729b2937bHector Dearman     * sharing of cookie data can take place.
30316d041cc9f4b67c37abf7dc5f8d49c7de81f2c84Kristian Monsen     * <p>
30477db9990777efd100bee4ec47568414ea039e99bSteve Block     * Note that calls to this method will have no effect if made after a
30577db9990777efd100bee4ec47568414ea039e99bSteve Block     * {@link WebView} or CookieManager instance has been created.
30616d041cc9f4b67c37abf7dc5f8d49c7de81f2c84Kristian Monsen     */
307be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon    // Static for backward compatibility.
30816d041cc9f4b67c37abf7dc5f8d49c7de81f2c84Kristian Monsen    public static void setAcceptFileSchemeCookies(boolean accept) {
309be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon        getInstance().setAcceptFileSchemeCookiesImpl(accept);
310be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon    }
311be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon
312be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon    /**
3134e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     * Implements {@link #setAcceptFileSchemeCookies(boolean)}.
3144e584df4cee8334bc371c04a67bcd0a32e2f9480Steve Block     *
315be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon     * @hide Only for use by WebViewProvider implementations
316be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon     */
317be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon    protected void setAcceptFileSchemeCookiesImpl(boolean accept) {
318be58c40646ed5694136970cf0e88ffd6087a3c2aJonathan Dixon        throw new MustOverrideException();
3199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
321