| Index: android_webview/java/src/org/chromium/android_webview/AwCookieManager.java
|
| diff --git a/android_webview/java/src/org/chromium/android_webview/AwCookieManager.java b/android_webview/java/src/org/chromium/android_webview/AwCookieManager.java
|
| index ab91e5d48bf9f55844b2fa350e8cdcb9a719cc30..c7f04aa8b4c2ea8dca19aa142c6fc13eeb2debb0 100644
|
| --- a/android_webview/java/src/org/chromium/android_webview/AwCookieManager.java
|
| +++ b/android_webview/java/src/org/chromium/android_webview/AwCookieManager.java
|
| @@ -4,6 +4,11 @@
|
|
|
| package org.chromium.android_webview;
|
|
|
| +import android.os.Handler;
|
| +import android.os.Looper;
|
| +import android.webkit.ValueCallback;
|
| +
|
| +import org.chromium.base.CalledByNative;
|
| import org.chromium.base.JNINamespace;
|
|
|
| /**
|
| @@ -13,6 +18,22 @@ import org.chromium.base.JNINamespace;
|
| */
|
| @JNINamespace("android_webview")
|
| public final class AwCookieManager {
|
| +
|
| + // TODO(hjd): remove after landing android update to use new calls.
|
| + public void removeExpiredCookie() {
|
| + removeExpiredCookies();
|
| + }
|
| +
|
| + // TODO(hjd): remove after landing android update to use new calls.
|
| + public void removeAllCookie() {
|
| + removeAllCookies();
|
| + }
|
| +
|
| + // TODO(hjd): remove after landing android update to use new calls.
|
| + public void removeSessionCookie() {
|
| + removeSessionCookies();
|
| + }
|
| +
|
| /**
|
| * Control whether cookie is enabled or disabled
|
| * @param accept TRUE if accept cookie
|
| @@ -46,14 +67,42 @@ public final class AwCookieManager {
|
| }
|
|
|
| /**
|
| + * Synchronous version of setCookie.
|
| + */
|
| + public void setCookie(String url, String value) {
|
| + nativeSetCookieSync(url, value);
|
| + }
|
| +
|
| + /**
|
| + * Deprecated synchronous version of removeSessionCookies.
|
| + */
|
| + public void removeSessionCookies() {
|
| + nativeRemoveSessionCookiesSync();
|
| + }
|
| +
|
| + /**
|
| + * Deprecated synchronous version of removeAllCookies.
|
| + */
|
| + public void removeAllCookies() {
|
| + nativeRemoveAllCookiesSync();
|
| + }
|
| +
|
| + /**
|
| * Set cookie for a given url. The old cookie with same host/path/name will
|
| * be removed. The new cookie will be added if it is not expired or it does
|
| * not have expiration which implies it is session cookie.
|
| - * @param url The url which cookie is set for
|
| - * @param value The value for set-cookie: in http response header
|
| + * @param url The url which cookie is set for.
|
| + * @param value The value for set-cookie: in http response header.
|
| + * @param callback A callback called with the success status after the cookie is set.
|
| */
|
| - public void setCookie(final String url, final String value) {
|
| - nativeSetCookie(url, value);
|
| + public void setCookie(final String url, final String value,
|
| + final ValueCallback<Boolean> callback) {
|
| + try {
|
| + nativeSetCookie(url, value, CookieCallback.convert(callback));
|
| + } catch (IllegalStateException e) {
|
| + throw new IllegalStateException(
|
| + "SetCookie must be called on a thread with a running Looper.");
|
| + }
|
| }
|
|
|
| /**
|
| @@ -69,17 +118,31 @@ public final class AwCookieManager {
|
| }
|
|
|
| /**
|
| - * Remove all session cookies, which are cookies without expiration date
|
| + * Remove all session cookies, the cookies without an expiration date.
|
| + * The value of the callback is true iff at least one cookie was removed.
|
| + * @param callback A callback called after the cookies (if any) are removed.
|
| */
|
| - public void removeSessionCookie() {
|
| - nativeRemoveSessionCookie();
|
| + public void removeSessionCookies(ValueCallback<Boolean> callback) {
|
| + try {
|
| + nativeRemoveSessionCookies(CookieCallback.convert(callback));
|
| + } catch (IllegalStateException e) {
|
| + throw new IllegalStateException(
|
| + "removeSessionCookies must be called on a thread with a running Looper.");
|
| + }
|
| }
|
|
|
| /**
|
| - * Remove all cookies
|
| + * Remove all cookies.
|
| + * The value of the callback is true iff at least one cookie was removed.
|
| + * @param callback A callback called after the cookies (if any) are removed.
|
| */
|
| - public void removeAllCookie() {
|
| - nativeRemoveAllCookie();
|
| + public void removeAllCookies(ValueCallback<Boolean> callback) {
|
| + try {
|
| + nativeRemoveAllCookies(CookieCallback.convert(callback));
|
| + } catch (IllegalStateException e) {
|
| + throw new IllegalStateException(
|
| + "removeAllCookies must be called on a thread with a running Looper.");
|
| + }
|
| }
|
|
|
| /**
|
| @@ -92,8 +155,8 @@ public final class AwCookieManager {
|
| /**
|
| * Remove all expired cookies
|
| */
|
| - public void removeExpiredCookie() {
|
| - nativeRemoveExpiredCookie();
|
| + public void removeExpiredCookies() {
|
| + nativeRemoveExpiredCookies();
|
| }
|
|
|
| public void flushCookieStore() {
|
| @@ -120,18 +183,67 @@ public final class AwCookieManager {
|
| nativeSetAcceptFileSchemeCookies(accept);
|
| }
|
|
|
| + @CalledByNative
|
| + public static void invokeBooleanCookieCallback(CookieCallback<Boolean> callback,
|
| + boolean result) {
|
| + callback.onReceiveValue(result);
|
| + }
|
| +
|
| + /**
|
| + * CookieCallback is a bridge that knows how to call a ValueCallback on its original thread.
|
| + * We need to arrange for the users ValueCallback#onReceiveValue to be called on the original
|
| + * thread after the work is done. When the API is called we construct a CookieCallback which
|
| + * remembers the handler of the current thread. Later the native code uses
|
| + * invokeBooleanCookieCallback to call CookieCallback#onReceiveValue which posts a Runnable
|
| + * on the handler of the original thread which in turn calls ValueCallback#onReceiveValue.
|
| + */
|
| + private static class CookieCallback<T> {
|
| + ValueCallback<T> mCallback;
|
| + Handler mHandler;
|
| +
|
| + public CookieCallback(ValueCallback<T> callback, Handler handler) {
|
| + mCallback = callback;
|
| + mHandler = handler;
|
| + }
|
| +
|
| + public static<T> CookieCallback<T> convert(ValueCallback<T> callback) throws
|
| + IllegalStateException {
|
| + if (callback == null) {
|
| + return null;
|
| + }
|
| + if (Looper.myLooper() == null) {
|
| + throw new IllegalStateException(
|
| + "CookieCallback.convert should be called on a thread with a running Looper.");
|
| + }
|
| + return new CookieCallback<T>(callback, new Handler());
|
| + }
|
| +
|
| + public void onReceiveValue(final T t) {
|
| + mHandler.post(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + mCallback.onReceiveValue(t);
|
| + }
|
| + });
|
| + }
|
| + }
|
| +
|
| private native void nativeSetAcceptCookie(boolean accept);
|
| private native boolean nativeAcceptCookie();
|
|
|
| private native void nativeSetAcceptThirdPartyCookie(boolean accept);
|
| private native boolean nativeAcceptThirdPartyCookie();
|
|
|
| - private native void nativeSetCookie(String url, String value);
|
| + private native void nativeSetCookie(String url, String value,
|
| + CookieCallback<Boolean> callback);
|
| + private native void nativeSetCookieSync(String url, String value);
|
| private native String nativeGetCookie(String url);
|
|
|
| - private native void nativeRemoveSessionCookie();
|
| - private native void nativeRemoveAllCookie();
|
| - private native void nativeRemoveExpiredCookie();
|
| + private native void nativeRemoveSessionCookies(CookieCallback<Boolean> callback);
|
| + private native void nativeRemoveSessionCookiesSync();
|
| + private native void nativeRemoveAllCookies(CookieCallback<Boolean> callback);
|
| + private native void nativeRemoveAllCookiesSync();
|
| + private native void nativeRemoveExpiredCookies();
|
| private native void nativeFlushCookieStore();
|
|
|
| private native boolean nativeHasCookies();
|
|
|