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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/webcontents/WebContentsImpl.java

Issue 786933005: [Android] Add proxy for Java-based WebContentsObservers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 10 months 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: 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 049e5af8d0ea21e9ed7813af43f522d757c165e0..f7a82e6992d0722a52d2bfc47728b1fcb3211cd7 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
@@ -312,6 +320,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);

Powered by Google App Engine
This is Rietveld 408576698