Commit 7672a9f7 authored by Torne (Richard Coles)'s avatar Torne (Richard Coles) Committed by Commit Bot

webview: Remove AwContents.activityFromContext.

This method (now) just wraps ContextUtils.activityFromContext and adds a
trace, but it's not used consistently. The trace was added to diagnose
performance issues caused by class verification failures, but we should
have this under control now.

Change-Id: I2415cd99f0e9f337956888918388d36aaf6d05af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1862729
Commit-Queue: Richard Coles <torne@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Auto-Submit: Richard Coles <torne@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706209}
parent 5d45d30e
...@@ -37,7 +37,6 @@ import android.webkit.WebViewClient; ...@@ -37,7 +37,6 @@ import android.webkit.WebViewClient;
import com.android.webview.chromium.WebViewDelegateFactory.WebViewDelegate; import com.android.webview.chromium.WebViewDelegateFactory.WebViewDelegate;
import org.chromium.android_webview.AwConsoleMessage; import org.chromium.android_webview.AwConsoleMessage;
import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.AwContentsClient; import org.chromium.android_webview.AwContentsClient;
import org.chromium.android_webview.AwContentsClientBridge; import org.chromium.android_webview.AwContentsClientBridge;
import org.chromium.android_webview.AwGeolocationPermissions; import org.chromium.android_webview.AwGeolocationPermissions;
...@@ -50,6 +49,7 @@ import org.chromium.android_webview.JsResultReceiver; ...@@ -50,6 +49,7 @@ import org.chromium.android_webview.JsResultReceiver;
import org.chromium.android_webview.permission.AwPermissionRequest; import org.chromium.android_webview.permission.AwPermissionRequest;
import org.chromium.android_webview.permission.Resource; import org.chromium.android_webview.permission.Resource;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.TraceEvent; import org.chromium.base.TraceEvent;
import org.chromium.base.metrics.ScopedSysTraceEvent; import org.chromium.base.metrics.ScopedSysTraceEvent;
...@@ -720,7 +720,7 @@ class WebViewContentsClientAdapter extends SharedWebViewContentsClientAdapter { ...@@ -720,7 +720,7 @@ class WebViewContentsClientAdapter extends SharedWebViewContentsClientAdapter {
String message, String url) { String message, String url) {
// Note we must unwrap the Context here due to JsDialogHelper only using instanceof to // Note we must unwrap the Context here due to JsDialogHelper only using instanceof to
// check if a Context is an Activity. // check if a Context is an Activity.
Context activityContext = AwContents.activityFromContext(mContext); Context activityContext = ContextUtils.activityFromContext(mContext);
if (activityContext == null) { if (activityContext == null) {
Log.w(TAG, "Unable to create JsDialog without an Activity"); Log.w(TAG, "Unable to create JsDialog without an Activity");
return false; return false;
......
...@@ -7,6 +7,7 @@ package org.chromium.android_webview; ...@@ -7,6 +7,7 @@ package org.chromium.android_webview;
import android.content.Context; import android.content.Context;
import org.chromium.autofill.mojom.SubmissionSource; import org.chromium.autofill.mojom.SubmissionSource;
import org.chromium.base.ContextUtils;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -181,7 +182,7 @@ public class AwAutofillUMA { ...@@ -181,7 +182,7 @@ public class AwAutofillUMA {
public AwAutofillUMA(Context context) { public AwAutofillUMA(Context context) {
RecordHistogram.recordBooleanHistogram(UMA_AUTOFILL_WEBVIEW_CREATED_BY_ACTIVITY_CONTEXT, RecordHistogram.recordBooleanHistogram(UMA_AUTOFILL_WEBVIEW_CREATED_BY_ACTIVITY_CONTEXT,
AwContents.activityFromContext(context) != null); ContextUtils.activityFromContext(context) != null);
} }
public void onFormSubmitted(int submissionSource) { public void onFormSubmitted(int submissionSource) {
......
...@@ -6,7 +6,6 @@ package org.chromium.android_webview; ...@@ -6,7 +6,6 @@ package org.chromium.android_webview;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ComponentCallbacks2; import android.content.ComponentCallbacks2;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
...@@ -1171,7 +1170,7 @@ public class AwContents implements SmartClipProvider { ...@@ -1171,7 +1170,7 @@ public class AwContents implements SmartClipProvider {
if (wrapper != null) return wrapper; if (wrapper != null) return wrapper;
try (ScopedSysTraceEvent e = ScopedSysTraceEvent.scoped("AwContents.getWindowAndroid")) { try (ScopedSysTraceEvent e = ScopedSysTraceEvent.scoped("AwContents.getWindowAndroid")) {
boolean contextWrapsActivity = activityFromContext(context) != null; boolean contextWrapsActivity = ContextUtils.activityFromContext(context) != null;
if (contextWrapsActivity) { if (contextWrapsActivity) {
ActivityWindowAndroid activityWindow; ActivityWindowAndroid activityWindow;
try (ScopedSysTraceEvent e2 = try (ScopedSysTraceEvent e2 =
...@@ -1529,11 +1528,6 @@ public class AwContents implements SmartClipProvider { ...@@ -1529,11 +1528,6 @@ public class AwContents implements SmartClipProvider {
AwContentsJni.get().setShouldDownloadFavicons(); AwContentsJni.get().setShouldDownloadFavicons();
} }
public static Activity activityFromContext(Context context) {
try (ScopedSysTraceEvent e = ScopedSysTraceEvent.scoped("AwContents.activityFromContext")) {
return ContextUtils.activityFromContext(context);
}
}
/** /**
* Disables contents of JS-to-Java bridge objects to be inspectable using * Disables contents of JS-to-Java bridge objects to be inspectable using
* Object.keys() method and "for .. in" loops. This is intended for applications * Object.keys() method and "for .. in" loops. This is intended for applications
......
...@@ -25,6 +25,7 @@ import androidx.annotation.Nullable; ...@@ -25,6 +25,7 @@ import androidx.annotation.Nullable;
import org.chromium.android_webview.permission.AwPermissionRequest; import org.chromium.android_webview.permission.AwPermissionRequest;
import org.chromium.android_webview.safe_browsing.AwSafeBrowsingResponse; import org.chromium.android_webview.safe_browsing.AwSafeBrowsingResponse;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.ScopedSysTraceEvent; import org.chromium.base.metrics.ScopedSysTraceEvent;
...@@ -242,7 +243,7 @@ public abstract class AwContentsClient { ...@@ -242,7 +243,7 @@ public abstract class AwContentsClient {
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
// Check whether the context is activity context. // Check whether the context is activity context.
if (AwContents.activityFromContext(context) == null) { if (ContextUtils.activityFromContext(context) == null) {
Log.w(TAG, "Cannot call startActivity on non-activity context."); Log.w(TAG, "Cannot call startActivity on non-activity context.");
return false; return false;
} }
......
...@@ -10,6 +10,8 @@ import android.content.ContextWrapper; ...@@ -10,6 +10,8 @@ import android.content.ContextWrapper;
import android.content.Intent; import android.content.Intent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import org.chromium.base.ContextUtils;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.WeakHashMap; import java.util.WeakHashMap;
...@@ -110,7 +112,7 @@ public class ResourcesContextWrapperFactory { ...@@ -110,7 +112,7 @@ public class ResourcesContextWrapperFactory {
@Override @Override
public void startActivity(Intent intent) { public void startActivity(Intent intent) {
if (AwContents.activityFromContext(this) == null) { if (ContextUtils.activityFromContext(this) == null) {
// FLAG_ACTIVITY_NEW_TASK is needed to start activities from a non-activity // FLAG_ACTIVITY_NEW_TASK is needed to start activities from a non-activity
// context. // context.
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
......
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