Skip to content

Commit

Permalink
[Android] Export XWalkCookieManager
Browse files Browse the repository at this point in the history
Expose XWalkCookieManager to developer, Change the name of XWalkCookieManager
to XWalkCookieManagerInternal for generating wrapper and bridge of the class.
  • Loading branch information
fujunwei committed Jun 30, 2015
1 parent 98cee25 commit c5504aa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
import org.chromium.base.JNINamespace;

/**
* XWalkCookieManager manages cookies according to RFC2109 spec.
* XWalkCookieManagerInternal manages cookies according to RFC2109 spec.
*
* Methods in this class are thread safe.
*
* @hide
*/
@JNINamespace("xwalk")
public final class XWalkCookieManager {
@XWalkAPI(createExternally = true)
public class XWalkCookieManagerInternal {
/**
* Control whether cookie is enabled or disabled
* @param accept TRUE if accept cookie
*/
@XWalkAPI
public void setAcceptCookie(boolean accept) {
nativeSetAcceptCookie(accept);
}
Expand All @@ -27,6 +29,7 @@ public void setAcceptCookie(boolean accept) {
* Return whether cookie is enabled
* @return TRUE if accept cookie
*/
@XWalkAPI
public boolean acceptCookie() {
return nativeAcceptCookie();
}
Expand All @@ -38,6 +41,7 @@ public boolean acceptCookie() {
* @param url The url which cookie is set for
* @param value The value for set-cookie: in http response header
*/
@XWalkAPI
public void setCookie(final String url, final String value) {
nativeSetCookie(url, value);
}
Expand All @@ -48,6 +52,7 @@ public void setCookie(final String url, final String value) {
* @param url The url needs cookie
* @return The cookies in the format of NAME=VALUE [; NAME=VALUE]
*/
@XWalkAPI
public String getCookie(final String url) {
String cookie = nativeGetCookie(url.toString());
// Return null if the string is empty to match legacy behavior
Expand All @@ -57,38 +62,44 @@ public String getCookie(final String url) {
/**
* Remove all session cookies, which are cookies without expiration date
*/
@XWalkAPI
public void removeSessionCookie() {
nativeRemoveSessionCookie();
}

/**
* Remove all cookies
*/
@XWalkAPI
public void removeAllCookie() {
nativeRemoveAllCookie();
}

/**
* Return true if there are stored cookies.
*/
@XWalkAPI
public boolean hasCookies() {
return nativeHasCookies();
}

/**
* Remove all expired cookies
*/
@XWalkAPI
public void removeExpiredCookie() {
nativeRemoveExpiredCookie();
}

@XWalkAPI
public void flushCookieStore() {
nativeFlushCookieStore();
}

/**
* Whether cookies are accepted for file scheme URLs.
*/
@XWalkAPI
public boolean allowFileSchemeCookies() {
return nativeAllowFileSchemeCookies();
}
Expand All @@ -103,6 +114,7 @@ public boolean allowFileSchemeCookies() {
* Note that calls to this method will have no effect if made after a
* WebView or CookieManager instance has been created.
*/
@XWalkAPI
public void setAcceptFileSchemeCookies(boolean accept) {
nativeSetAcceptFileSchemeCookies(accept);
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/browser/android/cookie_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/url_constants.h"
#include "jni/XWalkCookieManager_jni.h"
#include "jni/XWalkCookieManagerInternal_jni.h"
#include "net/cookies/cookie_monster.h"
#include "net/cookies/cookie_options.h"
#include "net/url_request/url_request_context.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
import java.util.Set;

import org.xwalk.core.XWalkView;
import org.xwalk.core.internal.XWalkCookieManager;
import org.xwalk.core.internal.XWalkCookieManagerInternal;
import org.xwalk.core.internal.XWalkClient;

/**
* Tests for the CookieManager.
*/
public class CookieManagerTest extends XWalkViewTestBase {

private XWalkCookieManager mCookieManager = null;
private XWalkCookieManagerInternal mCookieManager = null;

@Override
public void setUp() throws Exception {
super.setUp();

mCookieManager = new XWalkCookieManager();
mCookieManager = new XWalkCookieManagerInternal();
}

@SmallTest
Expand Down
1 change: 1 addition & 0 deletions tools/reflection_generator/reflection_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

# Classes list that have to generate bridge and wrap code.
CLASSES_TO_BE_PROCESS = [
'XWalkCookieManagerInternal',
'XWalkDownloadListenerInternal',
'XWalkExtensionInternal',
'XWalkViewInternal',
Expand Down
2 changes: 1 addition & 1 deletion xwalk_android.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
'runtime/android/core_internal/src/org/xwalk/core/internal/XWalkContent.java',
'runtime/android/core_internal/src/org/xwalk/core/internal/XWalkContentsClientBridge.java',
'runtime/android/core_internal/src/org/xwalk/core/internal/XWalkContentsIoThreadClient.java',
'runtime/android/core_internal/src/org/xwalk/core/internal/XWalkCookieManager.java',
'runtime/android/core_internal/src/org/xwalk/core/internal/XWalkCookieManagerInternal.java',
'runtime/android/core_internal/src/org/xwalk/core/internal/XWalkDevToolsServer.java',
'runtime/android/core_internal/src/org/xwalk/core/internal/XWalkHttpAuthHandler.java',
'runtime/android/core_internal/src/org/xwalk/core/internal/XWalkPathHelper.java',
Expand Down

0 comments on commit c5504aa

Please sign in to comment.