Commit 85f76de7 authored by James Wallace-Lee's avatar James Wallace-Lee Committed by Commit Bot

Avoid class verification on WebView startup for Lollipop

This adds utility classes ApiHelperForM in android_webview/glue and
content/browser/selection. It moves references to
WebResourceErrorAdapter and FloatingActionModeCallback into these
utility classes. On L devices, this reduces logspam caused by class
verification on startup.

Bug: 791099, 838702
Test: adb logcat | grep 'Rejecting re-init on previously-failed class'
Change-Id: I3c5f096d58fbe710c6429f48b8cc11268683af0d
Reviewed-on: https://chromium-review.googlesource.com/1100048
Commit-Queue: James Wallace-Lee <jamwalla@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567771}
parent facb7cb4
......@@ -33,6 +33,7 @@ android_library("glue") {
alternative_android_sdk_ijar = "$_ijar_dir/$_ijar"
alternative_android_sdk_jar = webview_public_framework_jar
java_files = [
"java/src/com/android/webview/chromium/ApiHelperForM.java",
"java/src/com/android/webview/chromium/ApiHelperForN.java",
"java/src/com/android/webview/chromium/ApiHelperForO.java",
"java/src/com/android/webview/chromium/ApiHelperForOMR1.java",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package com.android.webview.chromium;
import android.annotation.TargetApi;
import android.os.Build;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import org.chromium.android_webview.AwContentsClient;
import org.chromium.android_webview.AwWebResourceResponse;
/**
* Utility class to use new APIs that were added in M (API level 23). These need to exist in a
* separate class so that Android framework can successfully verify WebView classes without
* encountering the new APIs.
*/
@TargetApi(Build.VERSION_CODES.M)
public class ApiHelperForM {
private ApiHelperForM() {}
/**
* See {@link WebViewClient#onReceivedError(WebView, WebResourceRequest, WebResourceError)},
* which was added in M.
*/
public static void onReceivedError(WebViewClient webViewClient, WebView webView,
AwContentsClient.AwWebResourceRequest request,
AwContentsClient.AwWebResourceError error) {
webViewClient.onReceivedError(webView, new WebResourceRequestAdapter(request),
new WebResourceErrorAdapter(error));
}
/**
* See {@link WebViewClient#onReceivedHttpError(WebView, WebResourceRequest,
* WebResourceResponse)}, which was added in M.
*/
public static void onReceivedHttpError(WebViewClient webViewClient, WebView webView,
AwContentsClient.AwWebResourceRequest request, AwWebResourceResponse response) {
webViewClient.onReceivedHttpError(webView, new WebResourceRequestAdapter(request),
new WebResourceResponse(true, response.getMimeType(), response.getCharset(),
response.getStatusCode(), response.getReasonPhrase(),
response.getResponseHeaders(), response.getData()));
}
/**
* See {@link WebViewClient#onPageCommitVisible(WebView, String)}, which was added in M.
*/
public static void onPageCommitVisible(
WebViewClient webViewClient, WebView webView, String url) {
webViewClient.onPageCommitVisible(webView, url);
}
}
......@@ -535,7 +535,7 @@ class WebViewContentsClientAdapter extends AwContentsClient {
if (mSupportLibClient.isFeatureAvailable(Features.VISUAL_STATE_CALLBACK)) {
mSupportLibClient.onPageCommitVisible(mWebView, url);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mWebViewClient.onPageCommitVisible(mWebView, url);
ApiHelperForM.onPageCommitVisible(mWebViewClient, mWebView, url);
}
// Otherwise, the API does not exist, so do nothing.
} finally {
......@@ -588,8 +588,7 @@ class WebViewContentsClientAdapter extends AwContentsClient {
mSupportLibClient.onReceivedError(
mWebView, new WebResourceRequestAdapter(request), error);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mWebViewClient.onReceivedError(mWebView, new WebResourceRequestAdapter(request),
new WebResourceErrorAdapter(error));
ApiHelperForM.onReceivedError(mWebViewClient, mWebView, request, error);
}
// Otherwise, this is handled by {@link #onReceivedError}.
} finally {
......@@ -632,10 +631,7 @@ class WebViewContentsClientAdapter extends AwContentsClient {
response.getStatusCode(), response.getReasonPhrase(),
response.getResponseHeaders(), response.getData()));
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mWebViewClient.onReceivedHttpError(mWebView, new WebResourceRequestAdapter(request),
new WebResourceResponse(true, response.getMimeType(), response.getCharset(),
response.getStatusCode(), response.getReasonPhrase(),
response.getResponseHeaders(), response.getData()));
ApiHelperForM.onReceivedHttpError(mWebViewClient, mWebView, request, response);
}
// Otherwise, the API does not exist, so do nothing.
} finally {
......
......@@ -104,6 +104,7 @@ android_library("content_java") {
"java/src/org/chromium/content/app/PrivilegedProcessService1.java",
"java/src/org/chromium/content/app/PrivilegedProcessService2.java",
"java/src/org/chromium/content/app/SandboxedProcessService.java",
"java/src/org/chromium/content/browser/ApiHelperForM.java",
"java/src/org/chromium/content/browser/AppWebMessagePort.java",
"java/src/org/chromium/content/browser/AudioFocusDelegate.java",
"java/src/org/chromium/content/browser/BackgroundSyncNetworkObserver.java",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.content.browser;
import android.annotation.TargetApi;
import android.os.Build;
import android.view.ActionMode;
import android.view.View;
import org.chromium.content.browser.selection.FloatingActionModeCallback;
import org.chromium.content.browser.selection.SelectionPopupControllerImpl;
/**
* Utility class to use new APIs that were added in M (API level 23). These need to exist in a
* separate class so that Android framework can successfully verify selection classes without
* encountering the new APIs.
*/
@TargetApi(Build.VERSION_CODES.M)
public final class ApiHelperForM {
private ApiHelperForM() {}
/**
* See {@link View#startActionMode(ActionMode.Callback, int)}, which was added in M.
*/
public static ActionMode startActionMode(View view,
SelectionPopupControllerImpl selectionPopupController, ActionMode.Callback callback) {
return view.startActionMode(
new FloatingActionModeCallback(selectionPopupController, callback),
ActionMode.TYPE_FLOATING);
}
}
......@@ -18,7 +18,7 @@ import org.chromium.content_public.browser.ActionModeCallbackHelper;
* A class thatextends ActionMode.Callback2 to support floating ActionModes.
*/
@TargetApi(Build.VERSION_CODES.M)
class FloatingActionModeCallback extends ActionMode.Callback2 {
public class FloatingActionModeCallback extends ActionMode.Callback2 {
private final ActionModeCallbackHelper mHelper;
private final ActionMode.Callback mCallback;
......
......@@ -41,6 +41,7 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.content.R;
import org.chromium.content.browser.ApiHelperForM;
import org.chromium.content.browser.ContentClassFactory;
import org.chromium.content.browser.GestureListenerManagerImpl;
import org.chromium.content.browser.PopupController;
......@@ -465,10 +466,9 @@ public class SelectionPopupControllerImpl extends ActionModeCallbackHelper
if (!isActionModeValid()) clearSelection();
}
@TargetApi(Build.VERSION_CODES.M)
private ActionMode startFloatingActionMode() {
ActionMode actionMode = mView.startActionMode(
new FloatingActionModeCallback(this, mCallback), ActionMode.TYPE_FLOATING);
assert Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
ActionMode actionMode = ApiHelperForM.startActionMode(mView, this, mCallback);
return actionMode;
}
......
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