Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Unified Diff: ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java

Issue 1572913003: Pull the Activity context from WindowAndroid if possible (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@2564
Patch Set: Reverted changes to ChromeWindow Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java
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 ad02b45884a08c9467fb8c7ead4a291f31a0a9e4..b2e9c465ea4416f77e2c249c6d59bbe11a197060 100644
--- a/ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java
+++ b/ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java
@@ -7,6 +7,7 @@ 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;
@@ -51,19 +52,23 @@ public class ActivityWindowAndroid
* Creates an Activity-specific WindowAndroid with associated intent functionality.
* TODO(jdduke): Remove this overload when all callsites have been updated to
* indicate their activity state listening preference.
- * @param activity The activity associated with the WindowAndroid.
+ * @param context Context wrapping an activity associated with the WindowAndroid.
*/
- public ActivityWindowAndroid(Activity activity) {
- this(activity, true);
+ public ActivityWindowAndroid(Context context) {
+ this(context, true);
}
/**
* Creates an Activity-specific WindowAndroid with associated intent functionality.
- * @param activity The activity associated with the WindowAndroid.
+ * @param context Context wrapping an activity associated with the WindowAndroid.
* @param listenToActivityState Whether to listen to activity state changes.
*/
- public ActivityWindowAndroid(Activity activity, boolean listenToActivityState) {
- super(activity.getApplicationContext());
+ 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");
+ }
mActivityRef = new WeakReference<Activity>(activity);
mHandler = new Handler();
mOutstandingPermissionRequests = new SparseArray<PermissionCallback>();
@@ -209,8 +214,7 @@ public class ActivityWindowAndroid
@Override
public WeakReference<Activity> getActivity() {
- // Return a new WeakReference to prevent clients from releasing our internal WeakReference.
- return new WeakReference<Activity>(mActivityRef.get());
+ return new WeakReference<Activity>(activityFromContext(getContext().get()));
}
@Override

Powered by Google App Engine
This is Rietveld 408576698