1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.content.browser;
7 import org.chromium.base.CalledByNative;
8 import org.chromium.base.JNINamespace;
11 * This class receives callbacks that act as hooks for various a native web contents events related
12 * to loading a url. A single web contents can have multiple WebContentObserverAndroids.
14 @JNINamespace("content")
15 public abstract class WebContentsObserverAndroid {
16 private long mNativeWebContentsObserverAndroid;
18 public WebContentsObserverAndroid(ContentViewCore contentViewCore) {
19 mNativeWebContentsObserverAndroid = nativeInit(contentViewCore.getNativeContentViewCore());
23 public void renderProcessGone(boolean wasOomProtected) {
27 * Called when the a page starts loading.
28 * @param url The validated url for the loading page.
31 public void didStartLoading(String url) {
35 * Called when the a page finishes loading.
36 * @param url The validated url for the page.
39 public void didStopLoading(String url) {
43 * Called when an error occurs while loading a page and/or the page fails to load.
44 * @param errorCode Error code for the occurring error.
45 * @param description The description for the error.
46 * @param failingUrl The url that was loading when the error occurred.
49 public void didFailLoad(boolean isProvisionalLoad,
50 boolean isMainFrame, int errorCode, String description, String failingUrl) {
54 * Called when the main frame of the page has committed.
55 * @param url The validated url for the page.
56 * @param baseUrl The validated base url for the page.
57 * @param isNavigationToDifferentPage Whether the main frame navigated to a different page.
58 * @param isNavigationInPage Whether the main frame navigation did not cause changes to the
59 * document (for example scrolling to a named anchor or PopState).
62 public void didNavigateMainFrame(String url, String baseUrl,
63 boolean isNavigationToDifferentPage, boolean isNavigationInPage) {
67 * Called when the page had painted something non-empty.
70 public void didFirstVisuallyNonEmptyPaint() {
74 * Similar to didNavigateMainFrame but also called on subframe navigations.
75 * @param url The validated url for the page.
76 * @param baseUrl The validated base url for the page.
77 * @param isReload True if this navigation is a reload.
80 public void didNavigateAnyFrame(String url, String baseUrl, boolean isReload) {
84 * Notifies that a load is started for a given frame.
85 * @param frameId A positive, non-zero integer identifying the navigating frame.
86 * @param parentFrameId The frame identifier of the frame containing the navigating frame,
87 * or -1 if the frame is not contained in another frame.
88 * @param isMainFrame Whether the load is happening for the main frame.
89 * @param validatedUrl The validated URL that is being navigated to.
90 * @param isErrorPage Whether this is navigating to an error page.
91 * @param isIframeSrcdoc Whether this is navigating to about:srcdoc.
94 public void didStartProvisionalLoadForFrame(
100 boolean isIframeSrcdoc) {
104 * Notifies that the provisional load was successfully committed. The RenderViewHost is now
105 * the current RenderViewHost of the WebContents.
106 * @param frameId A positive, non-zero integer identifying the navigating frame.
107 * @param isMainFrame Whether the load is happening for the main frame.
108 * @param url The committed URL being navigated to.
109 * @param transitionType The transition type as defined in
110 * {@link org.chromium.content.browser.PageTransitionTypes} for the load.
113 public void didCommitProvisionalLoadForFrame(
114 long frameId, boolean isMainFrame, String url, int transitionType) {
119 * Notifies that a load has finished for a given frame.
120 * @param frameId A positive, non-zero integer identifying the navigating frame.
121 * @param validatedUrl The validated URL that is being navigated to.
122 * @param isMainFrame Whether the load is happening for the main frame.
125 public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) {
129 * Notifies that a navigation entry has been committed.
132 public void navigationEntryCommitted() {
136 * Invoked when visible SSL state changes.
139 public void didChangeVisibleSSLState() {
143 * Called when an interstitial page gets attached to the tab content.
146 public void didAttachInterstitialPage() {
150 * Called when an interstitial page gets detached from the tab content.
153 public void didDetachInterstitialPage() {
157 * Destroy the corresponding native object.
160 public void detachFromWebContents() {
161 if (mNativeWebContentsObserverAndroid != 0) {
162 nativeDestroy(mNativeWebContentsObserverAndroid);
163 mNativeWebContentsObserverAndroid = 0;
167 private native long nativeInit(long contentViewCorePtr);
168 private native void nativeDestroy(long nativeWebContentsObserverAndroid);