blob: abed0829204114a111d17264501ff99b99e4c6a4 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.webkit;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.net.WebAddress;
Doug Zongker45a9a142010-02-03 13:52:18 -080020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021/**
Steve Block77db9992012-02-20 11:46:13 +000022 * Manages the cookies used by an application's {@link WebView} instances.
23 * Cookies are manipulated according to RFC2109.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024 */
Jonathan Dixon939e5042012-04-12 21:21:07 +010025public class CookieManager {
Jonathan Dixond3101b12012-04-12 20:51:51 +010026 /**
27 * @hide Only for use by WebViewProvider implementations
28 */
29 protected CookieManager() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030 }
31
Jonathan Dixond3101b12012-04-12 20:51:51 +010032 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033 protected Object clone() throws CloneNotSupportedException {
34 throw new CloneNotSupportedException("doesn't implement Cloneable");
35 }
36
37 /**
Steve Block77db9992012-02-20 11:46:13 +000038 * Gets the singleton CookieManager instance. If this method is used
39 * before the application instantiates a {@link WebView} instance,
Steve Blockc723e352012-08-14 14:48:05 +010040 * {@link CookieSyncManager#createInstance CookieSyncManager.createInstance(Context)}
41 * must be called first.
Jonathan Dixond3101b12012-04-12 20:51:51 +010042 *
Steve Block4e584df2012-04-24 23:12:47 +010043 * @return the singleton CookieManager instance
Patrick Scott06312ca2010-03-19 15:40:05 -040044 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045 public static synchronized CookieManager getInstance() {
Jonathan Dixond3101b12012-04-12 20:51:51 +010046 return WebViewFactory.getProvider().getCookieManager();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047 }
48
49 /**
Steve Block77db9992012-02-20 11:46:13 +000050 * Sets whether the application's {@link WebView} instances should send and
51 * accept cookies.
Steve Block4e584df2012-04-24 23:12:47 +010052 *
53 * @param accept whether {@link WebView} instances should send and accept
Steve Block77db9992012-02-20 11:46:13 +000054 * cookies
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 */
56 public synchronized void setAcceptCookie(boolean accept) {
Jonathan Dixond3101b12012-04-12 20:51:51 +010057 throw new MustOverrideException();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058 }
59
60 /**
Steve Block77db9992012-02-20 11:46:13 +000061 * Gets whether the application's {@link WebView} instances send and accept
62 * cookies.
Steve Block4e584df2012-04-24 23:12:47 +010063 *
64 * @return true if {@link WebView} instances send and accept cookies
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 */
66 public synchronized boolean acceptCookie() {
Jonathan Dixond3101b12012-04-12 20:51:51 +010067 throw new MustOverrideException();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 }
69
Jonathan Dixond3101b12012-04-12 20:51:51 +010070 /**
Steve Block77db9992012-02-20 11:46:13 +000071 * Sets a cookie for the given URL. Any existing cookie with the same host,
72 * path and name will be replaced with the new cookie. The cookie being set
Hector Dearman0ac81cb2014-04-30 18:33:18 +010073 * will be ignored if it is expired.
Steve Block4e584df2012-04-24 23:12:47 +010074 *
75 * @param url the URL for which the cookie is set
76 * @param value the cookie as a string, using the format of the 'Set-Cookie'
Jonathan Dixond3101b12012-04-12 20:51:51 +010077 * HTTP response header
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 */
79 public void setCookie(String url, String value) {
Jonathan Dixond3101b12012-04-12 20:51:51 +010080 throw new MustOverrideException();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 }
82
83 /**
Steve Block77db9992012-02-20 11:46:13 +000084 * Gets the cookies for the given URL.
Steve Block4e584df2012-04-24 23:12:47 +010085 *
86 * @param url the URL for which the cookies are requested
87 * @return value the cookies as a string, using the format of the 'Cookie'
Steve Block77db9992012-02-20 11:46:13 +000088 * HTTP request header
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 */
90 public String getCookie(String url) {
Jonathan Dixond3101b12012-04-12 20:51:51 +010091 throw new MustOverrideException();
Kristian Monsen469aebb2011-03-01 20:14:59 +000092 }
93
94 /**
Steve Block4e584df2012-04-24 23:12:47 +010095 * See {@link #getCookie(String)}.
96 *
97 * @param url the URL for which the cookies are requested
98 * @param privateBrowsing whether to use the private browsing cookie jar
99 * @return value the cookies as a string, using the format of the 'Cookie'
Steve Block77db9992012-02-20 11:46:13 +0000100 * HTTP request header
101 * @hide Used by Browser, no intention to publish.
Kristian Monsen469aebb2011-03-01 20:14:59 +0000102 */
103 public String getCookie(String url, boolean privateBrowsing) {
Jonathan Dixond3101b12012-04-12 20:51:51 +0100104 throw new MustOverrideException();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 }
106
107 /**
Steve Block4e584df2012-04-24 23:12:47 +0100108 * Gets cookie(s) for a given uri so that it can be set to "cookie:" in http
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 * request header.
Steve Block4e584df2012-04-24 23:12:47 +0100110 *
111 * @param uri the WebAddress for which the cookies are requested
112 * @return value the cookies as a string, using the format of the 'Cookie'
Steve Block77db9992012-02-20 11:46:13 +0000113 * HTTP request header
114 * @hide Used by RequestHandle, no intention to publish.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 */
116 public synchronized String getCookie(WebAddress uri) {
Jonathan Dixond3101b12012-04-12 20:51:51 +0100117 throw new MustOverrideException();
Kristian Monsen85173052010-12-08 15:29:29 +0000118 }
119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 /**
Steve Block77db9992012-02-20 11:46:13 +0000121 * Removes all session cookies, which are cookies without an expiration
122 * date.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 */
124 public void removeSessionCookie() {
Jonathan Dixond3101b12012-04-12 20:51:51 +0100125 throw new MustOverrideException();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 }
127
128 /**
Steve Block77db9992012-02-20 11:46:13 +0000129 * Removes all cookies.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 */
131 public void removeAllCookie() {
Jonathan Dixond3101b12012-04-12 20:51:51 +0100132 throw new MustOverrideException();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 }
134
135 /**
Steve Block77db9992012-02-20 11:46:13 +0000136 * Gets whether there are stored cookies.
Steve Block4e584df2012-04-24 23:12:47 +0100137 *
138 * @return true if there are stored cookies
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 */
140 public synchronized boolean hasCookies() {
Jonathan Dixond3101b12012-04-12 20:51:51 +0100141 throw new MustOverrideException();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 }
143
144 /**
Jonathan Dixond3101b12012-04-12 20:51:51 +0100145 * See {@link #hasCookies()}.
Steve Block4e584df2012-04-24 23:12:47 +0100146 *
147 * @param privateBrowsing whether to use the private browsing cookie jar
Steve Block77db9992012-02-20 11:46:13 +0000148 * @hide Used by Browser, no intention to publish.
Kristian Monsen469aebb2011-03-01 20:14:59 +0000149 */
150 public synchronized boolean hasCookies(boolean privateBrowsing) {
Jonathan Dixond3101b12012-04-12 20:51:51 +0100151 throw new MustOverrideException();
Kristian Monsen469aebb2011-03-01 20:14:59 +0000152 }
153
154 /**
Steve Block77db9992012-02-20 11:46:13 +0000155 * Removes all expired cookies.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 */
157 public void removeExpiredCookie() {
Jonathan Dixond3101b12012-04-12 20:51:51 +0100158 throw new MustOverrideException();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 }
160
161 /**
Steve Block4e584df2012-04-24 23:12:47 +0100162 * Flushes all cookies managed by the Chrome HTTP stack to flash.
Jonathan Dixond3101b12012-04-12 20:51:51 +0100163 *
164 * @hide Package level api, called from CookieSyncManager
Iain Merrickc40fc2c2010-11-30 11:44:32 +0000165 */
Jonathan Dixond3101b12012-04-12 20:51:51 +0100166 protected void flushCookieStore() {
167 throw new MustOverrideException();
Iain Merrickc40fc2c2010-11-30 11:44:32 +0000168 }
169
170 /**
Steve Block77db9992012-02-20 11:46:13 +0000171 * Gets whether the application's {@link WebView} instances send and accept
172 * cookies for file scheme URLs.
Steve Block4e584df2012-04-24 23:12:47 +0100173 *
174 * @return true if {@link WebView} instances send and accept cookies for
Steve Block77db9992012-02-20 11:46:13 +0000175 * file scheme URLs
Kristian Monsen16d041c2010-12-06 13:43:51 +0000176 */
Jonathan Dixonbe58c402012-04-24 09:48:28 +0100177 // Static for backward compatibility.
Kristian Monsen16d041c2010-12-06 13:43:51 +0000178 public static boolean allowFileSchemeCookies() {
Jonathan Dixonbe58c402012-04-24 09:48:28 +0100179 return getInstance().allowFileSchemeCookiesImpl();
180 }
181
182 /**
Steve Block4e584df2012-04-24 23:12:47 +0100183 * Implements {@link #allowFileSchemeCookies()}.
184 *
Jonathan Dixonbe58c402012-04-24 09:48:28 +0100185 * @hide Only for use by WebViewProvider implementations
186 */
187 protected boolean allowFileSchemeCookiesImpl() {
188 throw new MustOverrideException();
Kristian Monsen16d041c2010-12-06 13:43:51 +0000189 }
190
191 /**
Steve Block77db9992012-02-20 11:46:13 +0000192 * Sets whether the application's {@link WebView} instances should send and
193 * accept cookies for file scheme URLs.
194 * Use of cookies with file scheme URLs is potentially insecure. Do not use
195 * this feature unless you can be sure that no unintentional sharing of
196 * cookie data can take place.
Kristian Monsen16d041c2010-12-06 13:43:51 +0000197 * <p>
Steve Block77db9992012-02-20 11:46:13 +0000198 * Note that calls to this method will have no effect if made after a
199 * {@link WebView} or CookieManager instance has been created.
Kristian Monsen16d041c2010-12-06 13:43:51 +0000200 */
Jonathan Dixonbe58c402012-04-24 09:48:28 +0100201 // Static for backward compatibility.
Kristian Monsen16d041c2010-12-06 13:43:51 +0000202 public static void setAcceptFileSchemeCookies(boolean accept) {
Jonathan Dixonbe58c402012-04-24 09:48:28 +0100203 getInstance().setAcceptFileSchemeCookiesImpl(accept);
204 }
205
206 /**
Steve Block4e584df2012-04-24 23:12:47 +0100207 * Implements {@link #setAcceptFileSchemeCookies(boolean)}.
208 *
Jonathan Dixonbe58c402012-04-24 09:48:28 +0100209 * @hide Only for use by WebViewProvider implementations
210 */
211 protected void setAcceptFileSchemeCookiesImpl(boolean accept) {
212 throw new MustOverrideException();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214}