Make cookieManager a field in AndroidCookieManager rather than using getInstance() every time

This commit is contained in:
Andrew Grieve 2015-02-19 10:28:18 -05:00
parent 11d6b8029f
commit 7be600d8e9

View File

@ -24,38 +24,37 @@ import android.webkit.CookieManager;
import android.webkit.WebView; import android.webkit.WebView;
class AndroidCookieManager implements ICordovaCookieManager { class AndroidCookieManager implements ICordovaCookieManager {
protected final WebView webView;
protected WebView webView; private final CookieManager cookieManager;
public AndroidCookieManager(WebView webview) { public AndroidCookieManager(WebView webview) {
webView = webview; webView = webview;
cookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
{
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptThirdPartyCookies(webView, true); cookieManager.setAcceptThirdPartyCookies(webView, true);
} }
} }
public void setCookiesEnabled(boolean accept) { public void setCookiesEnabled(boolean accept) {
CookieManager.getInstance().setAcceptCookie(accept); cookieManager.setAcceptCookie(accept);
} }
public void setCookie(final String url, final String value) { public void setCookie(final String url, final String value) {
CookieManager.getInstance().setCookie(url, value); cookieManager.setCookie(url, value);
} }
public String getCookie(final String url) { public String getCookie(final String url) {
return CookieManager.getInstance().getCookie(url); return cookieManager.getCookie(url);
} }
public void clearCookies() { public void clearCookies() {
CookieManager.getInstance().removeAllCookie(); cookieManager.removeAllCookie();
} }
public void flush() { public void flush() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().flush(); cookieManager.flush();
} }
} }
}; };