Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: android_webview/glue/java/src/com/android/webview/chromium/CookieManagerAdapter.java

Issue 1912083002: [WebView] Don't try to set cookies with null values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package com.android.webview.chromium; 5 package com.android.webview.chromium;
6 6
7 import android.net.ParseException; 7 import android.net.ParseException;
8 import android.net.WebAddress; 8 import android.net.WebAddress;
9 import android.util.Log;
10 import android.webkit.CookieManager; 9 import android.webkit.CookieManager;
11 import android.webkit.ValueCallback; 10 import android.webkit.ValueCallback;
12 import android.webkit.WebView; 11 import android.webkit.WebView;
13 12
14 import org.chromium.android_webview.AwCookieManager; 13 import org.chromium.android_webview.AwCookieManager;
14 import org.chromium.base.Log;
15 import org.chromium.base.annotations.SuppressFBWarnings; 15 import org.chromium.base.annotations.SuppressFBWarnings;
16 16
17 /** 17 /**
18 * Chromium implementation of CookieManager -- forwards calls to the 18 * Chromium implementation of CookieManager -- forwards calls to the
19 * chromium internal implementation. 19 * chromium internal implementation.
20 */ 20 */
21 @SuppressWarnings("deprecation") 21 @SuppressWarnings("deprecation")
22 @SuppressFBWarnings("CHROMIUM_SYNCHRONIZED_METHOD") 22 @SuppressFBWarnings("CHROMIUM_SYNCHRONIZED_METHOD")
23 public class CookieManagerAdapter extends CookieManager { 23 public class CookieManagerAdapter extends CookieManager {
24 private static final String LOGTAG = "CookieManager"; 24 private static final String TAG = "CookieManager";
25 25
26 AwCookieManager mChromeCookieManager; 26 AwCookieManager mChromeCookieManager;
27 27
28 public CookieManagerAdapter(AwCookieManager chromeCookieManager) { 28 public CookieManagerAdapter(AwCookieManager chromeCookieManager) {
29 mChromeCookieManager = chromeCookieManager; 29 mChromeCookieManager = chromeCookieManager;
30 } 30 }
31 31
32 @Override 32 @Override
33 public synchronized void setAcceptCookie(boolean accept) { 33 public synchronized void setAcceptCookie(boolean accept) {
34 mChromeCookieManager.setAcceptCookie(accept); 34 mChromeCookieManager.setAcceptCookie(accept);
35 } 35 }
36 36
37 @Override 37 @Override
38 public synchronized boolean acceptCookie() { 38 public synchronized boolean acceptCookie() {
39 return mChromeCookieManager.acceptCookie(); 39 return mChromeCookieManager.acceptCookie();
40 } 40 }
41 41
42 @Override 42 @Override
43 public synchronized void setAcceptThirdPartyCookies(WebView webView, boolean accept) { 43 public synchronized void setAcceptThirdPartyCookies(WebView webView, boolean accept) {
44 webView.getSettings().setAcceptThirdPartyCookies(accept); 44 webView.getSettings().setAcceptThirdPartyCookies(accept);
45 } 45 }
46 46
47 @Override 47 @Override
48 public synchronized boolean acceptThirdPartyCookies(WebView webView) { 48 public synchronized boolean acceptThirdPartyCookies(WebView webView) {
49 return webView.getSettings().getAcceptThirdPartyCookies(); 49 return webView.getSettings().getAcceptThirdPartyCookies();
50 } 50 }
51 51
52 @Override 52 @Override
53 public void setCookie(String url, String value) { 53 public void setCookie(String url, String value) {
54 if (value == null) {
55 Log.e(TAG, "Not setting cookie with null value for URL: %s", url);
56 return;
57 }
58
54 try { 59 try {
55 mChromeCookieManager.setCookie(fixupUrl(url), value); 60 mChromeCookieManager.setCookie(fixupUrl(url), value);
56 } catch (ParseException e) { 61 } catch (ParseException e) {
57 Log.e(LOGTAG, "Not setting cookie due to error parsing URL: " + url, e); 62 Log.e(TAG, "Not setting cookie due to error parsing URL: %s", url, e );
58 } 63 }
59 } 64 }
60 65
61 @Override 66 @Override
62 public void setCookie(String url, String value, ValueCallback<Boolean> callb ack) { 67 public void setCookie(String url, String value, ValueCallback<Boolean> callb ack) {
68 if (value == null) {
69 Log.e(TAG, "Not setting cookie with null value for URL: %s", url);
70 return;
71 }
72
63 try { 73 try {
64 mChromeCookieManager.setCookie(fixupUrl(url), value, callback); 74 mChromeCookieManager.setCookie(fixupUrl(url), value, callback);
65 } catch (ParseException e) { 75 } catch (ParseException e) {
66 Log.e(LOGTAG, "Not setting cookie due to error parsing URL: " + url, e); 76 Log.e(TAG, "Not setting cookie due to error parsing URL: %s", url, e );
67 } 77 }
68 } 78 }
69 79
70 @Override 80 @Override
71 public String getCookie(String url) { 81 public String getCookie(String url) {
72 try { 82 try {
73 return mChromeCookieManager.getCookie(fixupUrl(url)); 83 return mChromeCookieManager.getCookie(fixupUrl(url));
74 } catch (ParseException e) { 84 } catch (ParseException e) {
75 Log.e(LOGTAG, "Unable to get cookies due to error parsing URL: " + u rl, e); 85 Log.e(TAG, "Unable to get cookies due to error parsing URL: %s", url , e);
76 return null; 86 return null;
77 } 87 }
78 } 88 }
79 89
80 @Override 90 @Override
81 public String getCookie(String url, boolean privateBrowsing) { 91 public String getCookie(String url, boolean privateBrowsing) {
82 return getCookie(url); 92 return getCookie(url);
83 } 93 }
84 94
85 // TODO(igsolla): remove this override once the WebView apk does not longer need 95 // TODO(igsolla): remove this override once the WebView apk does not longer need
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 154 }
145 155
146 private static String fixupUrl(String url) throws ParseException { 156 private static String fixupUrl(String url) throws ParseException {
147 // WebAddress is a private API in the android framework and a "quirk" 157 // WebAddress is a private API in the android framework and a "quirk"
148 // of the Classic WebView implementation that allowed embedders to 158 // of the Classic WebView implementation that allowed embedders to
149 // be relaxed about what URLs they passed into the CookieManager, so we 159 // be relaxed about what URLs they passed into the CookieManager, so we
150 // do the same normalisation before entering the chromium stack. 160 // do the same normalisation before entering the chromium stack.
151 return new WebAddress(url).toString(); 161 return new WebAddress(url).toString();
152 } 162 }
153 } 163 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698