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

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

Issue 1419843002: Hold a reference to any kind of context in WindowAndroid. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move weak context/activity ref from ActivityWA to WA (WindowAndroid) and remove Context ref in Reso… Created 5 years, 1 month 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/WindowAndroid.java
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 3d775de11c9f19e5be9260380f87fbb609a9f2fa..8b1b081919322831328a81066ec0b76ddc2c6e5e 100644
--- a/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java
+++ b/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java
@@ -77,6 +77,11 @@ public class WindowAndroid {
protected Context mApplicationContext;
protected SparseArray<IntentCallback> mOutstandingIntents;
+ // To render properly on an external display through a Presentation we need to fetch
Ted C 2015/11/11 00:19:45 This comment seems more like the CL description th
gsennton 2015/11/13 20:00:05 Done.
+ // display metrics from the context provided by the Presentation. This context is not the same
+ // as the application context since the application context targets the primary display.
+ // We use a weak reference here to prevent this from leaking in WebView.
+ private WeakReference<Context> mContextRef;
// Ideally, this would be a SparseArray<String>, but there's no easy way to store a
// SparseArray<String> in a bundle during saveInstanceState(). So we use a HashMap and suppress
@@ -136,13 +141,20 @@ public class WindowAndroid {
*/
@SuppressLint("UseSparseArrays")
public WindowAndroid(Context context) {
- assert context == context.getApplicationContext();
- mApplicationContext = context;
+ mApplicationContext = context.getApplicationContext();
+ // context does not have the same lifetime guarantees as an application context so we can't
+ // hold a strong reference to it.
+ mContextRef = new WeakReference<Context>(context);
mOutstandingIntents = new SparseArray<IntentCallback>();
mIntentErrors = new HashMap<Integer, String>();
mVSyncMonitor = new VSyncMonitor(context, mVSyncListener);
- mAccessibilityManager = (AccessibilityManager)
- context.getSystemService(Context.ACCESSIBILITY_SERVICE);
+ mAccessibilityManager = (AccessibilityManager) mApplicationContext.getSystemService(
+ Context.ACCESSIBILITY_SERVICE);
+ }
+
+ @CalledByNative
+ private static WindowAndroid createForTesting(Context context) {
+ return new WindowAndroid(context);
}
/**
@@ -583,6 +595,11 @@ public class WindowAndroid {
});
}
+ public WeakReference<Context> getContext() {
Ted C 2015/11/11 00:19:45 add javadoc (probably should add a warning that ma
gsennton 2015/11/13 20:00:05 Done.
+ // Return a new WeakReference to prevent clients from releasing our internal WeakReference.
+ return new WeakReference<Context>(mContextRef.get());
+ }
+
/**
* Update whether the placeholder is 'drawn' based on whether an animation is running
* or touch exploration is enabled - if either of those are true, we call

Powered by Google App Engine
This is Rietveld 408576698