Skip to content

Commit

Permalink
webview: Remove AwContents.activityFromContext.
Browse files Browse the repository at this point in the history
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: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706209}
  • Loading branch information
tornewuff authored and Commit Bot committed Oct 15, 2019
1 parent 5d45d30 commit 7672a9f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import com.android.webview.chromium.WebViewDelegateFactory.WebViewDelegate;

import org.chromium.android_webview.AwConsoleMessage;
import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.AwContentsClient;
import org.chromium.android_webview.AwContentsClientBridge;
import org.chromium.android_webview.AwGeolocationPermissions;
Expand All @@ -50,6 +49,7 @@
import org.chromium.android_webview.permission.AwPermissionRequest;
import org.chromium.android_webview.permission.Resource;
import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.TraceEvent;
import org.chromium.base.metrics.ScopedSysTraceEvent;
Expand Down Expand Up @@ -720,7 +720,7 @@ private boolean showDefaultJsDialog(JsPromptResult res, int jsDialogType, String
String message, String url) {
// Note we must unwrap the Context here due to JsDialogHelper only using instanceof to
// check if a Context is an Activity.
Context activityContext = AwContents.activityFromContext(mContext);
Context activityContext = ContextUtils.activityFromContext(mContext);
if (activityContext == null) {
Log.w(TAG, "Unable to create JsDialog without an Activity");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.Context;

import org.chromium.autofill.mojom.SubmissionSource;
import org.chromium.base.ContextUtils;
import org.chromium.base.metrics.RecordHistogram;

import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -181,7 +182,7 @@ private int toUMAAutofillSessionValue() {

public AwAutofillUMA(Context context) {
RecordHistogram.recordBooleanHistogram(UMA_AUTOFILL_WEBVIEW_CREATED_BY_ACTIVITY_CONTEXT,
AwContents.activityFromContext(context) != null);
ContextUtils.activityFromContext(context) != null);
}

public void onFormSubmitted(int submissionSource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -1171,7 +1170,7 @@ private static WindowAndroidWrapper getWindowAndroid(Context context) {
if (wrapper != null) return wrapper;

try (ScopedSysTraceEvent e = ScopedSysTraceEvent.scoped("AwContents.getWindowAndroid")) {
boolean contextWrapsActivity = activityFromContext(context) != null;
boolean contextWrapsActivity = ContextUtils.activityFromContext(context) != null;
if (contextWrapsActivity) {
ActivityWindowAndroid activityWindow;
try (ScopedSysTraceEvent e2 =
Expand Down Expand Up @@ -1529,11 +1528,6 @@ public static void 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
* Object.keys() method and "for .. in" loops. This is intended for applications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.chromium.android_webview.permission.AwPermissionRequest;
import org.chromium.android_webview.safe_browsing.AwSafeBrowsingResponse;
import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.ScopedSysTraceEvent;
Expand Down Expand Up @@ -242,7 +243,7 @@ private static boolean sendBrowsingIntent(Context context, String url, boolean h
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());

// 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.");
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import android.content.Intent;
import android.view.LayoutInflater;

import org.chromium.base.ContextUtils;

import java.lang.ref.WeakReference;
import java.util.WeakHashMap;

Expand Down Expand Up @@ -110,7 +112,7 @@ public void unregisterComponentCallbacks(ComponentCallbacks callback) {

@Override
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
// context.
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Expand Down

0 comments on commit 7672a9f

Please sign in to comment.