Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java |
| 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 87d4533b103cdbda38129a887284a03a6e6259fe..46a82102158bd56e18640f9fc015e5fc65b5e304 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 |
| @@ -98,6 +98,21 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa |
| // produce little visible difference. |
| private static final float ZOOM_CONTROLS_EPSILON = 0.007f; |
| + /** |
| + * Observer for changes to WindowAndroid. Mirrors |
| + * ContentViewCoreImplObserver in native. Appends 'Android' to (a) match |
| + * WindowAndroid, and (b) avoid a name collision with View. |
| + */ |
| + public interface Observer { |
| + public void onContentViewCoreDestroyed(ContentViewCore cvc); |
| + public void onAttachedToWindowAndroid(ContentViewCore cvc); |
| + public void onDetachedFromWindowAndroid(ContentViewCore cvc); |
| + } |
| + |
| + // Single observer. We only support one right now, since we have only one |
| + // consumer of it. |
| + private Observer mObserver; |
| + |
| // If the embedder adds a JavaScript interface object that contains an indirect reference to |
| // the ContentViewCore, then storing a strong ref to the interface object on the native |
| // side would prevent garbage collection of the ContentViewCore (as that strong ref would |
| @@ -704,6 +719,7 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa |
| private void onNativeContentViewCoreDestroyed(long nativeContentViewCore) { |
| assert nativeContentViewCore == mNativeContentViewCore; |
| mNativeContentViewCore = 0; |
| + if (mObserver != null) mObserver.onContentViewCoreDestroyed(this); |
| } |
| /** |
| @@ -2813,6 +2829,31 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Displa |
| return mShowKeyboardResultReceiver; |
| } |
| + // Set our observer. We support only a single observer right now. If |
| + // |observer| is already an observer, then do nothing. |
| + public void addObserver(Observer observer) { |
| + assert mObserver == null || mObserver == observer; |
| + mObserver = observer; |
| + } |
| + |
| + // Remove our single observer. |
| + public void removeObserver(Observer observer) { |
| + assert mObserver == observer; |
| + // Note that this can be called as part of a callback, so be careful if |
| + // we're iterating over a list of observers when this is called. |
| + mObserver = null; |
| + } |
| + |
| + @CalledByNative |
| + private void onAttachedToWindowAndroid() { |
| + if (mObserver != null) mObserver.onAttachedToWindowAndroid(this); |
|
boliu
2017/01/04 23:14:39
sigh.. I should really unify these two different "
liberato (no reviews please)
2017/01/11 22:17:56
i didn't see an obvious way to do this. i'll re-c
|
| + } |
| + |
| + @CalledByNative |
| + private void onDetachedFromWindowAndroid() { |
| + if (mObserver != null) mObserver.onDetachedFromWindowAndroid(this); |
| + } |
| + |
| private native long nativeInit(WebContents webContents, ViewAndroidDelegate viewAndroidDelegate, |
| long windowAndroidPtr, float dipScale, HashSet<Object> retainedObjectSet); |
| private static native ContentViewCore nativeFromWebContentsAndroid(WebContents webContents); |