Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content_public/browser/WebContentsObserver.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/WebContentsObserver.java b/content/public/android/java/src/org/chromium/content_public/browser/WebContentsObserver.java |
| similarity index 85% |
| rename from content/public/android/java/src/org/chromium/content/browser/WebContentsObserver.java |
| rename to content/public/android/java/src/org/chromium/content_public/browser/WebContentsObserver.java |
| index f1bf6a2fa0711e5f4e3ea7c0dbd1562c01a41f77..330901298529b38bcdac85c9c6228641fad8f681 100644 |
| --- a/content/public/android/java/src/org/chromium/content/browser/WebContentsObserver.java |
| +++ b/content/public/android/java/src/org/chromium/content_public/browser/WebContentsObserver.java |
| @@ -2,35 +2,29 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -package org.chromium.content.browser; |
| +package org.chromium.content_public.browser; |
| -import org.chromium.base.CalledByNative; |
| -import org.chromium.base.JNINamespace; |
| -import org.chromium.base.ThreadUtils; |
| -import org.chromium.content_public.browser.WebContents; |
| +import java.lang.ref.WeakReference; |
| /** |
| * This class receives callbacks that act as hooks for various a native web contents events related |
| * to loading a url. A single web contents can have multiple WebContentObservers. |
| */ |
| -@JNINamespace("content") |
| public abstract class WebContentsObserver { |
| - private long mNativeWebContentsObserverAndroid; |
| + private WeakReference<WebContents> mWebContents; |
| public WebContentsObserver(WebContents webContents) { |
| - ThreadUtils.assertOnUiThread(); |
| - mNativeWebContentsObserverAndroid = nativeInit(webContents); |
| + mWebContents = new WeakReference<WebContents>(webContents); |
| + webContents.addObserver(this); |
| } |
| /** |
| * Called when the RenderView of the current RenderViewHost is ready, e.g. because we recreated |
| * it after a crash. |
| */ |
| - @CalledByNative |
| public void renderViewReady() { |
| } |
| - @CalledByNative |
| public void renderProcessGone(boolean wasOomProtected) { |
| } |
| @@ -38,7 +32,6 @@ public abstract class WebContentsObserver { |
| * Called when the a page starts loading. |
| * @param url The validated url for the loading page. |
| */ |
| - @CalledByNative |
| public void didStartLoading(String url) { |
| } |
| @@ -46,7 +39,6 @@ public abstract class WebContentsObserver { |
| * Called when the a page finishes loading. |
| * @param url The validated url for the page. |
| */ |
| - @CalledByNative |
| public void didStopLoading(String url) { |
| } |
| @@ -56,7 +48,6 @@ public abstract class WebContentsObserver { |
| * @param description The description for the error. |
| * @param failingUrl The url that was loading when the error occurred. |
| */ |
| - @CalledByNative |
| public void didFailLoad(boolean isProvisionalLoad, |
| boolean isMainFrame, int errorCode, String description, String failingUrl) { |
| } |
| @@ -83,7 +74,6 @@ public abstract class WebContentsObserver { |
| * document (for example scrolling to a named anchor or PopState). |
| * @param statusCode The HTTP status code of the navigation. |
| */ |
| - @CalledByNative |
| public void didNavigateMainFrame(String url, String baseUrl, |
| boolean isNavigationToDifferentPage, boolean isFragmentNavigation, int statusCode) { |
| didNavigateMainFrame(url, baseUrl, isNavigationToDifferentPage, isFragmentNavigation); |
| @@ -92,7 +82,6 @@ public abstract class WebContentsObserver { |
| /** |
| * Called when the page had painted something non-empty. |
| */ |
| - @CalledByNative |
| public void didFirstVisuallyNonEmptyPaint() { |
| } |
| @@ -102,14 +91,12 @@ public abstract class WebContentsObserver { |
| * @param baseUrl The validated base url for the page. |
| * @param isReload True if this navigation is a reload. |
| */ |
| - @CalledByNative |
| public void didNavigateAnyFrame(String url, String baseUrl, boolean isReload) { |
| } |
| /** |
| * Called once the window.document object of the main frame was created. |
| */ |
| - @CalledByNative |
| public void documentAvailableInMainFrame() { |
| } |
| @@ -123,7 +110,6 @@ public abstract class WebContentsObserver { |
| * @param isErrorPage Whether this is navigating to an error page. |
| * @param isIframeSrcdoc Whether this is navigating to about:srcdoc. |
| */ |
| - @CalledByNative |
| public void didStartProvisionalLoadForFrame( |
| long frameId, |
| long parentFrameId, |
| @@ -142,7 +128,6 @@ public abstract class WebContentsObserver { |
| * @param transitionType The transition type as defined in |
| * {@link org.chromium.ui.base.PageTransition} for the load. |
| */ |
| - @CalledByNative |
| public void didCommitProvisionalLoadForFrame( |
| long frameId, boolean isMainFrame, String url, int transitionType) { |
| @@ -154,7 +139,6 @@ public abstract class WebContentsObserver { |
| * @param validatedUrl The validated URL that is being navigated to. |
| * @param isMainFrame Whether the load is happening for the main frame. |
| */ |
| - @CalledByNative |
| public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) { |
| } |
| @@ -162,28 +146,24 @@ public abstract class WebContentsObserver { |
| * Notifies that the document has finished loading for the given frame. |
| * @param frameId A positive, non-zero integer identifying the navigating frame. |
| */ |
| - @CalledByNative |
| public void documentLoadedInFrame(long frameId) { |
| } |
| /** |
| * Notifies that a navigation entry has been committed. |
| */ |
| - @CalledByNative |
| public void navigationEntryCommitted() { |
| } |
| /** |
| * Called when an interstitial page gets attached to the tab content. |
| */ |
| - @CalledByNative |
| public void didAttachInterstitialPage() { |
| } |
| /** |
| * Called when an interstitial page gets detached from the tab content. |
| */ |
| - @CalledByNative |
| public void didDetachInterstitialPage() { |
| } |
| @@ -191,7 +171,6 @@ public abstract class WebContentsObserver { |
| * Called when the theme color was changed. |
| * @param color the new color in ARGB format |
| */ |
| - @CalledByNative |
| public void didChangeThemeColor(int color) { |
| } |
| @@ -199,21 +178,19 @@ public abstract class WebContentsObserver { |
| * Called when we started navigation to the pending entry. |
| * @param url The URL that we are navigating to. |
| */ |
| - @CalledByNative |
| public void didStartNavigationToPendingEntry(String url) { |
| } |
| /** |
| - * Destroy the corresponding native object. |
| + * Stop observing the web contents. |
| */ |
| - @CalledByNative |
| public void detachFromWebContents() { |
|
Ted C
2015/02/18 22:54:37
I'd love to see method removed and require everyon
jdduke (slow)
2015/02/24 20:55:49
Agreed. OK if I tackle that in a follow-up?
|
| - if (mNativeWebContentsObserverAndroid != 0) { |
| - nativeDestroy(mNativeWebContentsObserverAndroid); |
| - mNativeWebContentsObserverAndroid = 0; |
| - } |
| + if (mWebContents == null) return; |
| + final WebContents webContents = mWebContents.get(); |
| + mWebContents = null; |
| + if (webContents == null) return; |
| + webContents.removeObserver(this); |
| } |
| - private native long nativeInit(WebContents webContents); |
| - private native void nativeDestroy(long nativeWebContentsObserverAndroid); |
| + protected WebContentsObserver() {} |
| } |