diff options
| author | dtu <dtu@chromium.org> | 2015-12-18 12:25:20 -0800 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2015-12-18 20:26:34 +0000 |
| commit | b370242ecaeee80710008a3e1927fcd1d73f568e (patch) | |
| tree | 708194a5ac90e5d7259c37cbc955e2dfdc42c571 | |
| parent | ac189a63979ecb6503d2db7c32930d1f08d5c48f (diff) | |
| download | chromium_src-b370242ecaeee80710008a3e1927fcd1d73f568e.zip chromium_src-b370242ecaeee80710008a3e1927fcd1d73f568e.tar.gz chromium_src-b370242ecaeee80710008a3e1927fcd1d73f568e.tar.bz2 | |
Revert of Pull the Activity context from WindowAndroid if possible (patchset #4 id:60001 of https://codereview.chromium.org/1528733002/ )
Reason for revert:
Failing on perf Android Builders.
https://build.chromium.org/p/chromium.perf/builders/Android%20Builder/builds/56908
https://build.chromium.org/p/chromium.perf/builders/Android%20arm64%20Builder/builds/14488
Original issue's description:
> Pull the Activity context from WindowAndroid if possible
>
> WebView uses ContentViewCore's context for displaying dialogs and
> wraps it at construction time. This change makes sure that if there
> is an activity that can be reached through WindowAndroid, we use
> that as the context inside ColorChooser. Also make sure if there is no activity, we
> dont attempt to create a color chooser and try to show it.
> Update ActivityWindowAndroid to take a Context type so
> that in Android WebView, the activity context can remain wrapped.
>
> BUG=550410, 570429
>
> Committed: https://crrev.com/fdf17ed2da4f4554400c25993aa688cb9355c004
> Cr-Commit-Position: refs/heads/master@{#366125}
TBR=boliu@chromium.org,torne@chromium.org,tedchoc@chromium.org,tobiasjs@chromium.org,newt@chromium.org,yusufo@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=550410, 570429
Review URL: https://codereview.chromium.org/1541473002
Cr-Commit-Position: refs/heads/master@{#366159}
6 files changed, 33 insertions, 45 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java index 2352b57..8ecc734 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -925,28 +925,28 @@ public class AwContents implements SmartClipProvider, } } private static WindowAndroidWrapper sCachedWindowAndroid; - private static WeakHashMap<Context, WindowAndroidWrapper> sActivityContextWindowMap; + private static WeakHashMap<Activity, WindowAndroidWrapper> sActivityWindowMap; // getWindowAndroid is only called on UI thread, so there are no threading issues with lazy // initialization. @SuppressFBWarnings("LI_LAZY_INIT_STATIC") private static WindowAndroidWrapper getWindowAndroid(Context context) { // TODO(boliu): WebView does not currently initialize ApplicationStatus, crbug.com/470582. - boolean contextWrapsActivity = activityFromContext(context) != null; - if (!contextWrapsActivity) { + Activity activity = ContentViewCore.activityFromContext(context); + if (activity == null) { if (sCachedWindowAndroid == null) { sCachedWindowAndroid = new WindowAndroidWrapper(new WindowAndroid(context)); } return sCachedWindowAndroid; } - if (sActivityContextWindowMap == null) sActivityContextWindowMap = new WeakHashMap<>(); - WindowAndroidWrapper activityWindowAndroid = sActivityContextWindowMap.get(context); + if (sActivityWindowMap == null) sActivityWindowMap = new WeakHashMap<>(); + WindowAndroidWrapper activityWindowAndroid = sActivityWindowMap.get(activity); if (activityWindowAndroid == null) { final boolean listenToActivityState = false; activityWindowAndroid = new WindowAndroidWrapper( - new ActivityWindowAndroid(context, listenToActivityState)); - sActivityContextWindowMap.put(context, activityWindowAndroid); + new ActivityWindowAndroid(activity, listenToActivityState)); + sActivityWindowMap.put(activity, activityWindowAndroid); } return activityWindowAndroid; } @@ -1208,7 +1208,7 @@ public class AwContents implements SmartClipProvider, } public static Activity activityFromContext(Context context) { - return WindowAndroid.activityFromContext(context); + return ContentViewCore.activityFromContext(context); } /** * Disables contents of JS-to-Java bridge objects to be inspectable using @@ -2256,7 +2256,7 @@ public class AwContents implements SmartClipProvider, intent.putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, true); } - if (WindowAndroid.activityFromContext(mContext) == null) { + if (ContentViewCore.activityFromContext(mContext) == null) { mContext.startActivity(intent); return; } diff --git a/components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/ColorChooserAndroid.java b/components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/ColorChooserAndroid.java index 25f5f62..207fee2 100644 --- a/components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/ColorChooserAndroid.java +++ b/components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/ColorChooserAndroid.java @@ -12,7 +12,6 @@ import org.chromium.content.browser.ContentViewCore; import org.chromium.ui.ColorPickerDialog; import org.chromium.ui.ColorSuggestion; import org.chromium.ui.OnColorChangedListener; -import org.chromium.ui.base.WindowAndroid; /** * ColorChooserAndroid communicates with the java ColorPickerDialog and the @@ -52,11 +51,8 @@ public class ColorChooserAndroid { ContentViewCore contentViewCore, int initialColor, ColorSuggestion[] suggestions) { - if (contentViewCore.getWindowAndroid() == null) return null; - Context windowContext = contentViewCore.getWindowAndroid().getContext().get(); - if (WindowAndroid.activityFromContext(windowContext) == null) return null; ColorChooserAndroid chooser = new ColorChooserAndroid(nativeColorChooserAndroid, - windowContext, initialColor, suggestions); + contentViewCore.getContext(), initialColor, suggestions); chooser.openColorChooser(); return chooser; } diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java b/content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java index 52e00d0..76db5cb 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java +++ b/content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java @@ -26,7 +26,6 @@ import org.chromium.base.Log; import org.chromium.base.ThreadUtils; import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.JNINamespace; -import org.chromium.ui.base.WindowAndroid; /** * This class implements accelerated fullscreen video playback using surface view. @@ -228,7 +227,7 @@ public class ContentVideoView extends FrameLayout mCurrentState = STATE_ERROR; - if (WindowAndroid.activityFromContext(getContext()) == null) { + if (ContentViewCore.activityFromContext(getContext()) == null) { Log.w(TAG, "Unable to show alert dialog because it requires an activity context"); return; } diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java index 7147b93..b7bbcf4 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java +++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java @@ -12,6 +12,7 @@ import android.app.assist.AssistStructure.ViewNode; import android.content.ClipboardManager; import android.content.ContentResolver; import android.content.Context; +import android.content.ContextWrapper; import android.content.Intent; import android.content.pm.PackageManager; import android.content.res.Configuration; @@ -432,6 +433,22 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen public void onSmartClipDataExtracted(String text, String html, Rect clipRect); } + /** + * Cast from Context to Activity taking ContextWrapper into account. + */ + public static Activity activityFromContext(Context context) { + // Only retrieve the base context if the supplied context is a ContextWrapper but not + // an Activity, given that Activity is already a subclass of ContextWrapper. + if (context instanceof Activity) { + return ((Activity) context); + } else if (context instanceof ContextWrapper) { + context = ((ContextWrapper) context).getBaseContext(); + return activityFromContext(context); + } else { + return null; + } + } + private final Context mContext; private ViewGroup mContainerView; private InternalAccessDelegate mContainerViewInternals; diff --git a/ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java b/ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java index 3993815..615b0ab 100644 --- a/ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java +++ b/ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java @@ -7,7 +7,6 @@ package org.chromium.ui.base; import android.app.Activity; import android.app.PendingIntent; import android.content.ActivityNotFoundException; -import android.content.Context; import android.content.Intent; import android.content.IntentSender.SendIntentException; import android.content.SharedPreferences; @@ -53,8 +52,8 @@ public class ActivityWindowAndroid * indicate their activity state listening preference. * @param activity The activity associated with the WindowAndroid. */ - public ActivityWindowAndroid(Context context) { - this(context, true); + public ActivityWindowAndroid(Activity activity) { + this(activity, true); } /** @@ -62,12 +61,8 @@ public class ActivityWindowAndroid * @param activity The activity associated with the WindowAndroid. * @param listenToActivityState Whether to listen to activity state changes. */ - public ActivityWindowAndroid(Context context, boolean listenToActivityState) { - super(context); - Activity activity = activityFromContext(context); - if (activity == null) { - throw new IllegalArgumentException("Context is not and does not wrap an Activity"); - } + public ActivityWindowAndroid(Activity activity, boolean listenToActivityState) { + super(activity); mHandler = new Handler(); mOutstandingPermissionRequests = new SparseArray<PermissionCallback>(); if (listenToActivityState) { @@ -212,7 +207,7 @@ public class ActivityWindowAndroid @Override public WeakReference<Activity> getActivity() { - return new WeakReference<Activity>(activityFromContext(getContext().get())); + return new WeakReference<Activity>((Activity) getContext().get()); } @Override diff --git a/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java b/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java index 25951fb..658d0be 100644 --- a/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java +++ b/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java @@ -12,7 +12,6 @@ import android.app.Activity; import android.app.PendingIntent; import android.content.ContentResolver; import android.content.Context; -import android.content.ContextWrapper; import android.content.Intent; import android.content.pm.PackageManager; import android.os.Build; @@ -126,24 +125,6 @@ public class WindowAndroid { }; /** - * Extract the activity if the given Context either is or wraps one. - * Only retrieve the base context if the supplied context is a {@link ContextWrapper} but not - * an Activity, given that Activity is already a subclass of ContextWrapper. - * @param context The context to check. - * @return The {@link Activity} that is extracted through the given Context. - */ - public static Activity activityFromContext(Context context) { - if (context instanceof Activity) { - return ((Activity) context); - } else if (context instanceof ContextWrapper) { - context = ((ContextWrapper) context).getBaseContext(); - return activityFromContext(context); - } else { - return null; - } - } - - /** * @return true if onVSync handler is executing. * * @see org.chromium.ui.VSyncMonitor#isInsideVSync() |
