| Index: content/public/android/java/src/org/chromium/content/browser/webcontents/WebContentsImpl.java
|
| diff --git a/content/public/android/java/src/org/chromium/content/browser/webcontents/WebContentsImpl.java b/content/public/android/java/src/org/chromium/content/browser/webcontents/WebContentsImpl.java
|
| index d6cb714f86af849bfea8bf5593f41e69eedc11f4..68dc1c6e770bb0a3e2e87d03845f8c0aea2023bf 100644
|
| --- a/content/public/android/java/src/org/chromium/content/browser/webcontents/WebContentsImpl.java
|
| +++ b/content/public/android/java/src/org/chromium/content/browser/webcontents/WebContentsImpl.java
|
| @@ -10,6 +10,7 @@ import org.chromium.content_public.browser.JavaScriptCallback;
|
| import org.chromium.content_public.browser.NavigationController;
|
| import org.chromium.content_public.browser.NavigationTransitionDelegate;
|
| import org.chromium.content_public.browser.WebContents;
|
| +import org.chromium.content_public.browser.WebContentsObserver;
|
|
|
| /**
|
| * The WebContentsImpl Java wrapper to allow communicating with the native WebContentsImpl
|
| @@ -23,6 +24,9 @@ import org.chromium.content_public.browser.WebContents;
|
| private long mNativeWebContentsAndroid;
|
| private NavigationController mNavigationController;
|
|
|
| + // Lazily created proxy observer for handling all Java-based WebContentsObservers.
|
| + private WebContentsObserverProxy mObserverProxy;
|
| +
|
| private NavigationTransitionDelegate mNavigationTransitionDelegate = null;
|
|
|
| private WebContentsImpl(
|
| @@ -41,6 +45,10 @@ import org.chromium.content_public.browser.WebContents;
|
| private void clearNativePtr() {
|
| mNativeWebContentsAndroid = 0;
|
| mNavigationController = null;
|
| + if (mObserverProxy != null) {
|
| + mObserverProxy.destroy();
|
| + mObserverProxy = null;
|
| + }
|
| }
|
|
|
| @CalledByNative
|
| @@ -302,6 +310,23 @@ import org.chromium.content_public.browser.WebContents;
|
| callback.handleJavaScriptResult(jsonResult);
|
| }
|
|
|
| + @Override
|
| + public void addObserver(WebContentsObserver observer) {
|
| + assert mNativeWebContentsAndroid != 0;
|
| + if (mObserverProxy == null) mObserverProxy = new WebContentsObserverProxy(this);
|
| + mObserverProxy.addObserver(observer);
|
| + }
|
| +
|
| + @Override
|
| + public void removeObserver(WebContentsObserver observer) {
|
| + if (mObserverProxy == null) return;
|
| + mObserverProxy.removeObserver(observer);
|
| + if (!mObserverProxy.hasObservers()) {
|
| + mObserverProxy.destroy();
|
| + mObserverProxy = null;
|
| + }
|
| + }
|
| +
|
| // This is static to avoid exposing a public destroy method on the native side of this class.
|
| private static native void nativeDestroyWebContents(long webContentsAndroidPtr);
|
|
|
|
|