Chromium Code Reviews| 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..3634df8234a3a38a951bca8053f816f63cd95a21 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,10 @@ public class WindowAndroid { |
| protected Context mApplicationContext; |
| protected SparseArray<IntentCallback> mOutstandingIntents; |
| + // To render properly on an external display through a Presentation we need to fetch |
| + // 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. |
| + protected WeakReference<Context> mDisplayContextRef; |
|
boliu
2015/10/21 16:55:38
private?
Explain this needs to be a weakreference
gsennton
2015/10/23 16:27:07
Done.
|
| // 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 +140,14 @@ public class WindowAndroid { |
| */ |
| @SuppressLint("UseSparseArrays") |
| public WindowAndroid(Context context) { |
| - assert context == context.getApplicationContext(); |
| - mApplicationContext = context; |
| + mApplicationContext = context.getApplicationContext(); |
| + // context could be an Activity Context so we can't hold a strong reference to it. |
| + mDisplayContextRef = 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); |
| } |
| /** |
| @@ -583,6 +588,11 @@ public class WindowAndroid { |
| }); |
| } |
| + @CalledByNative |
| + private Context getDisplayContext() { |
| + return mDisplayContextRef.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 |