Commit cda30669 authored by Tobias Sargeant's avatar Tobias Sargeant Committed by Commit Bot

aw: Make sure that the null WebViewClient is always returned.

Bug: 853175
Change-Id: I3982fd6c2bc6fecbda09c3f5edb6731921c8618a
Reviewed-on: https://chromium-review.googlesource.com/1102464Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Commit-Queue: Tobias Sargeant <tobiasjs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567701}
parent 2bd0fd44
...@@ -23,8 +23,10 @@ public class SharedWebViewChromium { ...@@ -23,8 +23,10 @@ public class SharedWebViewChromium {
// The WebView wrapper for ContentViewCore and required browser compontents. // The WebView wrapper for ContentViewCore and required browser compontents.
private AwContents mAwContents; private AwContents mAwContents;
// Default WebViewClient used to avoid null checks.
final static WebViewClient sNullWebViewClient = new WebViewClient();
// The WebViewClient instance that was passed to WebView.setWebViewClient(). // The WebViewClient instance that was passed to WebView.setWebViewClient().
private WebViewClient mWebViewClient; private WebViewClient mWebViewClient = sNullWebViewClient;
public SharedWebViewChromium(WebViewChromiumRunQueue runQueue, WebViewChromiumAwInit awInit) { public SharedWebViewChromium(WebViewChromiumRunQueue runQueue, WebViewChromiumAwInit awInit) {
mRunQueue = runQueue; mRunQueue = runQueue;
...@@ -32,7 +34,7 @@ public class SharedWebViewChromium { ...@@ -32,7 +34,7 @@ public class SharedWebViewChromium {
} }
void setWebViewClient(WebViewClient client) { void setWebViewClient(WebViewClient client) {
mWebViewClient = client; mWebViewClient = client != null ? client : sNullWebViewClient;
} }
public WebViewClient getWebViewClient() { public WebViewClient getWebViewClient() {
......
...@@ -1279,7 +1279,7 @@ class WebViewChromium implements WebViewProvider, WebViewProvider.ScrollDelegate ...@@ -1279,7 +1279,7 @@ class WebViewChromium implements WebViewProvider, WebViewProvider.ScrollDelegate
@Override @Override
public void setWebViewClient(WebViewClient client) { public void setWebViewClient(WebViewClient client) {
mSharedWebViewChromium.setWebViewClient(client); mSharedWebViewChromium.setWebViewClient(client);
mContentsClientAdapter.setWebViewClient(client); mContentsClientAdapter.setWebViewClient(mSharedWebViewChromium.getWebViewClient());
} }
@Override @Override
......
...@@ -92,14 +92,12 @@ class WebViewContentsClientAdapter extends AwContentsClient { ...@@ -92,14 +92,12 @@ class WebViewContentsClientAdapter extends AwContentsClient {
private static final String TAG = "WebViewCallback"; private static final String TAG = "WebViewCallback";
// Enables API callback tracing // Enables API callback tracing
private static final boolean TRACE = false; private static final boolean TRACE = false;
// Default WebViewClient used to avoid null checks.
private static WebViewClient sNullWebViewClient = new WebViewClient();
// The WebView instance that this adapter is serving. // The WebView instance that this adapter is serving.
protected final WebView mWebView; protected final WebView mWebView;
// The Context to use. This is different from mWebView.getContext(), which should not be used. // The Context to use. This is different from mWebView.getContext(), which should not be used.
private final Context mContext; private final Context mContext;
// A reference to the current WebViewClient associated with this WebView. // A reference to the current WebViewClient associated with this WebView.
protected WebViewClient mWebViewClient = sNullWebViewClient; protected WebViewClient mWebViewClient = SharedWebViewChromium.sNullWebViewClient;
// Some callbacks will be forwarded to this client for apps using the support library. // Some callbacks will be forwarded to this client for apps using the support library.
private final SupportLibWebViewContentsClientAdapter mSupportLibClient; private final SupportLibWebViewContentsClientAdapter mSupportLibClient;
// The WebChromeClient instance that was passed to WebView.setContentViewClient(). // The WebChromeClient instance that was passed to WebView.setContentViewClient().
...@@ -147,7 +145,6 @@ class WebViewContentsClientAdapter extends AwContentsClient { ...@@ -147,7 +145,6 @@ class WebViewContentsClientAdapter extends AwContentsClient {
try (ScopedSysTraceEvent event = try (ScopedSysTraceEvent event =
ScopedSysTraceEvent.scoped("WebViewContentsClientAdapter.constructor")) { ScopedSysTraceEvent.scoped("WebViewContentsClientAdapter.constructor")) {
mSupportLibClient = new SupportLibWebViewContentsClientAdapter(); mSupportLibClient = new SupportLibWebViewContentsClientAdapter();
setWebViewClient(null);
mUiThreadHandler = new Handler() { mUiThreadHandler = new Handler() {
@Override @Override
...@@ -180,14 +177,8 @@ class WebViewContentsClientAdapter extends AwContentsClient { ...@@ -180,14 +177,8 @@ class WebViewContentsClientAdapter extends AwContentsClient {
} }
void setWebViewClient(WebViewClient client) { void setWebViewClient(WebViewClient client) {
if (client != null) {
mWebViewClient = client; mWebViewClient = client;
} else { mSupportLibClient.setWebViewClient(client);
mWebViewClient = sNullWebViewClient;
}
// Always reset mSupportLibClient, since the WebViewClient may no longer be a
// WebViewClientCompat, or may support a different set of Features.
mSupportLibClient.setWebViewClient(mWebViewClient);
} }
void setWebChromeClient(WebChromeClient client) { void setWebChromeClient(WebChromeClient client) {
...@@ -220,7 +211,7 @@ class WebViewContentsClientAdapter extends AwContentsClient { ...@@ -220,7 +211,7 @@ class WebViewContentsClientAdapter extends AwContentsClient {
*/ */
@Override @Override
public boolean hasWebViewClient() { public boolean hasWebViewClient() {
return mWebViewClient != sNullWebViewClient; return mWebViewClient != SharedWebViewChromium.sNullWebViewClient;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment