1616
1717package android .webkit ;
1818
19- import android .net .ParseException ;
2019import android .net .WebAddress ;
21- import android .os .AsyncTask ;
22- import android .util .Log ;
23-
2420
2521/**
2622 * Manages the cookies used by an application's {@link WebView} instances.
2723 * Cookies are manipulated according to RFC2109.
2824 */
2925public class CookieManager {
30-
31- private static CookieManager sRef ;
32-
33- private static final String LOGTAG = "webkit" ;
34-
35- private int mPendingCookieOperations = 0 ;
36-
37- private CookieManager () {
26+ /**
27+ * @hide Only for use by WebViewProvider implementations
28+ */
29+ protected CookieManager () {
3830 }
3931
32+ @ Override
4033 protected Object clone () throws CloneNotSupportedException {
4134 throw new CloneNotSupportedException ("doesn't implement Cloneable" );
4235 }
@@ -46,14 +39,11 @@ protected Object clone() throws CloneNotSupportedException {
4639 * before the application instantiates a {@link WebView} instance,
4740 * {@link CookieSyncManager#createInstance(Context)} must be called
4841 * first.
49- *
42+ *
5043 * @return The singleton CookieManager instance
5144 */
5245 public static synchronized CookieManager getInstance () {
53- if (sRef == null ) {
54- sRef = new CookieManager ();
55- }
56- return sRef ;
46+ return WebViewFactory .getProvider ().getCookieManager ();
5747 }
5848
5949 /**
@@ -63,7 +53,7 @@ public static synchronized CookieManager getInstance() {
6353 * cookies
6454 */
6555 public synchronized void setAcceptCookie (boolean accept ) {
66- nativeSetAcceptCookie ( accept );
56+ throw new MustOverrideException ( );
6757 }
6858
6959 /**
@@ -72,39 +62,20 @@ public synchronized void setAcceptCookie(boolean accept) {
7262 * @return True if {@link WebView} instances send and accept cookies
7363 */
7464 public synchronized boolean acceptCookie () {
75- return nativeAcceptCookie ();
65+ throw new MustOverrideException ();
7666 }
7767
78- /**
68+ /**
7969 * Sets a cookie for the given URL. Any existing cookie with the same host,
8070 * path and name will be replaced with the new cookie. The cookie being set
8171 * must not have expired and must not be a session cookie, otherwise it
8272 * will be ignored.
8373 * @param url The URL for which the cookie is set
84- * @param value The cookie as a string, using the format of the
85- * 'Set-Cookie' HTTP response header
74+ * @param value The cookie as a string, using the format of the 'Set-Cookie'
75+ * HTTP response header
8676 */
8777 public void setCookie (String url , String value ) {
88- setCookie (url , value , false );
89- }
90-
91- /**
92- * See {@link setCookie(String, String)}
93- * @param url The URL for which the cookie is set
94- * @param value The value of the cookie, as a string, using the format of
95- * the 'Set-Cookie' HTTP response header
96- * @param privateBrowsing Whether to use the private browsing cookie jar
97- */
98- void setCookie (String url , String value , boolean privateBrowsing ) {
99- WebAddress uri ;
100- try {
101- uri = new WebAddress (url );
102- } catch (ParseException ex ) {
103- Log .e (LOGTAG , "Bad address: " + url );
104- return ;
105- }
106-
107- nativeSetCookie (uri .toString (), value , privateBrowsing );
78+ throw new MustOverrideException ();
10879 }
10980
11081 /**
@@ -114,27 +85,19 @@ void setCookie(String url, String value, boolean privateBrowsing) {
11485 * HTTP request header
11586 */
11687 public String getCookie (String url ) {
117- return getCookie ( url , false );
88+ throw new MustOverrideException ( );
11889 }
11990
12091 /**
121- * See {@link getCookie(String)}
92+ * See {@link # getCookie(String)}
12293 * @param url The URL for which the cookies are requested
12394 * @param privateBrowsing Whether to use the private browsing cookie jar
12495 * @return value The cookies as a string, using the format of the 'Cookie'
12596 * HTTP request header
12697 * @hide Used by Browser, no intention to publish.
12798 */
12899 public String getCookie (String url , boolean privateBrowsing ) {
129- WebAddress uri ;
130- try {
131- uri = new WebAddress (url );
132- } catch (ParseException ex ) {
133- Log .e (LOGTAG , "Bad address: " + url );
134- return null ;
135- }
136-
137- return nativeGetCookie (uri .toString (), privateBrowsing );
100+ throw new MustOverrideException ();
138101 }
139102
140103 /**
@@ -146,87 +109,55 @@ public String getCookie(String url, boolean privateBrowsing) {
146109 * @hide Used by RequestHandle, no intention to publish.
147110 */
148111 public synchronized String getCookie (WebAddress uri ) {
149- return nativeGetCookie (uri .toString (), false );
150- }
151-
152- /**
153- * Waits for pending operations to completed.
154- */
155- void waitForCookieOperationsToComplete () {
156- // Note that this function is applicable for both the java
157- // and native http stacks, and works correctly with either.
158- synchronized (this ) {
159- while (mPendingCookieOperations > 0 ) {
160- try {
161- wait ();
162- } catch (InterruptedException e ) { }
163- }
164- }
165- }
166-
167- private synchronized void signalCookieOperationsComplete () {
168- mPendingCookieOperations --;
169- assert mPendingCookieOperations > -1 ;
170- notify ();
171- }
172-
173- private synchronized void signalCookieOperationsStart () {
174- mPendingCookieOperations ++;
112+ throw new MustOverrideException ();
175113 }
176114
177115 /**
178116 * Removes all session cookies, which are cookies without an expiration
179117 * date.
180118 */
181119 public void removeSessionCookie () {
182- signalCookieOperationsStart ();
183- new AsyncTask <Void , Void , Void >() {
184- protected Void doInBackground (Void ... none ) {
185- nativeRemoveSessionCookie ();
186- signalCookieOperationsComplete ();
187- return null ;
188- }
189- }.execute ();
120+ throw new MustOverrideException ();
190121 }
191122
192123 /**
193124 * Removes all cookies.
194125 */
195126 public void removeAllCookie () {
196- nativeRemoveAllCookie ();
127+ throw new MustOverrideException ();
197128 }
198129
199130 /**
200131 * Gets whether there are stored cookies.
201132 * @return True if there are stored cookies.
202133 */
203134 public synchronized boolean hasCookies () {
204- return hasCookies ( false );
135+ throw new MustOverrideException ( );
205136 }
206137
207138 /**
208- * See {@link hasCookies()}.
139+ * See {@link # hasCookies()}.
209140 * @param privateBrowsing Whether to use the private browsing cookie jar
210141 * @hide Used by Browser, no intention to publish.
211142 */
212143 public synchronized boolean hasCookies (boolean privateBrowsing ) {
213- return nativeHasCookies ( privateBrowsing );
144+ throw new MustOverrideException ( );
214145 }
215146
216147 /**
217148 * Removes all expired cookies.
218149 */
219150 public void removeExpiredCookie () {
220- nativeRemoveExpiredCookie ();
151+ throw new MustOverrideException ();
221152 }
222153
223154 /**
224- * Package level api, called from CookieSyncManager
225- *
226155 * Flush all cookies managed by the Chrome HTTP stack to flash.
156+ *
157+ * @hide Package level api, called from CookieSyncManager
227158 */
228- void flushCookieStore () {
229- nativeFlushCookieStore ();
159+ protected void flushCookieStore () {
160+ throw new MustOverrideException ();
230161 }
231162
232163 /**
@@ -236,7 +167,7 @@ void flushCookieStore() {
236167 * file scheme URLs
237168 */
238169 public static boolean allowFileSchemeCookies () {
239- return nativeAcceptFileSchemeCookies ();
170+ throw new MustOverrideException ();
240171 }
241172
242173 /**
@@ -250,19 +181,6 @@ public static boolean allowFileSchemeCookies() {
250181 * {@link WebView} or CookieManager instance has been created.
251182 */
252183 public static void setAcceptFileSchemeCookies (boolean accept ) {
253- nativeSetAcceptFileSchemeCookies ( accept );
184+ throw new MustOverrideException ( );
254185 }
255-
256- // Native functions
257- private static native boolean nativeAcceptCookie ();
258- private static native String nativeGetCookie (String url , boolean privateBrowsing );
259- private static native boolean nativeHasCookies (boolean privateBrowsing );
260- private static native void nativeRemoveAllCookie ();
261- private static native void nativeRemoveExpiredCookie ();
262- private static native void nativeRemoveSessionCookie ();
263- private static native void nativeSetAcceptCookie (boolean accept );
264- private static native void nativeSetCookie (String url , String value , boolean privateBrowsing );
265- private static native void nativeFlushCookieStore ();
266- private static native boolean nativeAcceptFileSchemeCookies ();
267- private static native void nativeSetAcceptFileSchemeCookies (boolean accept );
268186}
0 commit comments