mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 20:33:07 +08:00
CB-5059 Adds CookieManager abstraction for pluggable webviews (close #151)
Crosswalk and GeckoView implementations of CordovaWebView can provide their own ICordovaCookieManager implementation for plugins to use.
This commit is contained in:
parent
b59705bed4
commit
8cf8da5776
60
framework/src/org/apache/cordova/AndroidCookieManager.java
Normal file
60
framework/src/org/apache/cordova/AndroidCookieManager.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.cordova;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
|
import android.webkit.CookieManager;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
class AndroidCookieManager implements ICordovaCookieManager {
|
||||||
|
|
||||||
|
protected WebView webView;
|
||||||
|
|
||||||
|
public AndroidCookieManager(WebView webview) {
|
||||||
|
webView = webview;
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
{
|
||||||
|
CookieManager cookieManager = CookieManager.getInstance();
|
||||||
|
cookieManager.setAcceptThirdPartyCookies(webView, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCookiesEnabled(boolean accept) {
|
||||||
|
CookieManager.getInstance().setAcceptCookie(accept);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCookie(final String url, final String value) {
|
||||||
|
CookieManager.getInstance().setCookie(url, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCookie(final String url) {
|
||||||
|
return CookieManager.getInstance().getCookie(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearCookies() {
|
||||||
|
CookieManager.getInstance().removeAllCookie();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void flush() {
|
||||||
|
CookieManager.getInstance().flush();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -66,6 +66,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
|||||||
private HashSet<Integer> boundKeyCodes = new HashSet<Integer>();
|
private HashSet<Integer> boundKeyCodes = new HashSet<Integer>();
|
||||||
|
|
||||||
PluginManager pluginManager;
|
PluginManager pluginManager;
|
||||||
|
AndroidCookieManager cookieManager;
|
||||||
|
|
||||||
private BroadcastReceiver receiver;
|
private BroadcastReceiver receiver;
|
||||||
|
|
||||||
@ -124,6 +125,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
|||||||
this.preferences = preferences;
|
this.preferences = preferences;
|
||||||
|
|
||||||
pluginManager = new PluginManager(this, this.cordova, pluginEntries);
|
pluginManager = new PluginManager(this, this.cordova, pluginEntries);
|
||||||
|
cookieManager = new AndroidCookieManager(this);
|
||||||
resourceApi = new CordovaResourceApi(this.getContext(), pluginManager);
|
resourceApi = new CordovaResourceApi(this.getContext(), pluginManager);
|
||||||
bridge = new CordovaBridge(pluginManager, new NativeToJsMessageQueue(this, cordova), this.cordova.getActivity().getPackageName());
|
bridge = new CordovaBridge(pluginManager, new NativeToJsMessageQueue(this, cordova), this.cordova.getActivity().getPackageName());
|
||||||
initWebViewSettings();
|
initWebViewSettings();
|
||||||
@ -136,11 +138,6 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
|||||||
new IceCreamCordovaWebViewClient(cordova, this));
|
new IceCreamCordovaWebViewClient(cordova, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
|
||||||
{
|
|
||||||
CookieManager cookieManager = CookieManager.getInstance();
|
|
||||||
cookieManager.setAcceptThirdPartyCookies(this, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.chromeClient == null) {
|
if (this.chromeClient == null) {
|
||||||
setWebChromeClient(new AndroidChromeClient(cordova, this));
|
setWebChromeClient(new AndroidChromeClient(cordova, this));
|
||||||
@ -800,6 +797,11 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
|||||||
return preferences;
|
return preferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ICordovaCookieManager getCookieManager() {
|
||||||
|
return cookieManager;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object postMessage(String id, Object data) {
|
public Object postMessage(String id, Object data) {
|
||||||
return pluginManager.postMessage(id, data);
|
return pluginManager.postMessage(id, data);
|
||||||
|
@ -84,6 +84,7 @@ public interface CordovaWebView {
|
|||||||
Whitelist getWhitelist();
|
Whitelist getWhitelist();
|
||||||
Whitelist getExternalWhitelist();
|
Whitelist getExternalWhitelist();
|
||||||
CordovaPreferences getPreferences();
|
CordovaPreferences getPreferences();
|
||||||
|
ICordovaCookieManager getCookieManager();
|
||||||
|
|
||||||
void setNetworkAvailable(boolean online);
|
void setNetworkAvailable(boolean online);
|
||||||
|
|
||||||
|
33
framework/src/org/apache/cordova/ICordovaCookieManager.java
Normal file
33
framework/src/org/apache/cordova/ICordovaCookieManager.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.cordova;
|
||||||
|
|
||||||
|
public interface ICordovaCookieManager {
|
||||||
|
|
||||||
|
public void setCookiesEnabled(boolean accept);
|
||||||
|
|
||||||
|
public void setCookie(final String url, final String value);
|
||||||
|
|
||||||
|
public String getCookie(final String url);
|
||||||
|
|
||||||
|
public void clearCookies();
|
||||||
|
|
||||||
|
public void flush();
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user