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 |