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;
9 import org.chromium.base.ThreadUtils;
10 import org.chromium.content_public.browser.WebContents;
13 * This class receives callbacks that act as hooks for various a native web contents events related
14 * to loading a url. A single web contents can have multiple WebContentObserverAndroids.
16 @JNINamespace("content")
17 public abstract class WebContentsObserverAndroid {
18 private long mNativeWebContentsObserverAndroid;
20 public WebContentsObserverAndroid(WebContents webContents) {
21 ThreadUtils.assertOnUiThread();
22 mNativeWebContentsObserverAndroid = nativeInit(webContents);
26 public void renderProcessGone(boolean wasOomProtected) {
30 * Called when the a page starts loading.
31 * @param url The validated url for the loading page.
34 public void didStartLoading(String url) {
38 * Called when the a page finishes loading.
39 * @param url The validated url for the page.
42 public void didStopLoading(String url) {
46 * Called when an error occurs while loading a page and/or the page fails to load.
47 * @param errorCode Error code for the occurring error.
48 * @param description The description for the error.
49 * @param failingUrl The url that was loading when the error occurred.
52 public void didFailLoad(boolean isProvisionalLoad,
53 boolean isMainFrame, int errorCode, String description, String failingUrl) {
57 * Called when the main frame of the page has committed.
58 * @param url The validated url for the page.
59 * @param baseUrl The validated base url for the page.
60 * @param isNavigationToDifferentPage Whether the main frame navigated to a different page.
61 * @param isFragmentNavigation Whether the main frame navigation did not cause changes to the
62 * document (for example scrolling to a named anchor or PopState).
65 public void didNavigateMainFrame(String url, String baseUrl,
66 boolean isNavigationToDifferentPage, boolean isFragmentNavigation) {
70 * Called when the page had painted something non-empty.
73 public void didFirstVisuallyNonEmptyPaint() {
77 * Similar to didNavigateMainFrame but also called on subframe navigations.
78 * @param url The validated url for the page.
79 * @param baseUrl The validated base url for the page.
80 * @param isReload True if this navigation is a reload.
83 public void didNavigateAnyFrame(String url, String baseUrl, boolean isReload) {
87 * Notifies that a load is started for a given frame.
88 * @param frameId A positive, non-zero integer identifying the navigating frame.
89 * @param parentFrameId The frame identifier of the frame containing the navigating frame,
90 * or -1 if the frame is not contained in another frame.
91 * @param isMainFrame Whether the load is happening for the main frame.
92 * @param validatedUrl The validated URL that is being navigated to.
93 * @param isErrorPage Whether this is navigating to an error page.
94 * @param isIframeSrcdoc Whether this is navigating to about:srcdoc.
97 public void didStartProvisionalLoadForFrame(
103 boolean isIframeSrcdoc) {
107 * Notifies that the provisional load was successfully committed. The RenderViewHost is now
108 * the current RenderViewHost of the WebContents.
109 * @param frameId A positive, non-zero integer identifying the navigating frame.
110 * @param isMainFrame Whether the load is happening for the main frame.
111 * @param url The committed URL being navigated to.
112 * @param transitionType The transition type as defined in
113 * {@link org.chromium.ui.base.PageTransitionTypes} for the load.
116 public void didCommitProvisionalLoadForFrame(
117 long frameId, boolean isMainFrame, String url, int transitionType) {
122 * Notifies that a load has finished for a given frame.
123 * @param frameId A positive, non-zero integer identifying the navigating frame.
124 * @param validatedUrl The validated URL that is being navigated to.
125 * @param isMainFrame Whether the load is happening for the main frame.
128 public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) {
132 * Notifies that the document has finished loading for the given frame.
133 * @param frameId A positive, non-zero integer identifying the navigating frame.
136 public void documentLoadedInFrame(long frameId) {
140 * Notifies that a navigation entry has been committed.
143 public void navigationEntryCommitted() {
147 * Called when an interstitial page gets attached to the tab content.
150 public void didAttachInterstitialPage() {
154 * Called when an interstitial page gets detached from the tab content.
157 public void didDetachInterstitialPage() {
161 * Called when the theme color was changed.
162 * @param color the new color in ARGB format
165 public void didChangeThemeColor(int color) {
169 * Destroy the corresponding native object.
172 public void detachFromWebContents() {
173 if (mNativeWebContentsObserverAndroid != 0) {
174 nativeDestroy(mNativeWebContentsObserverAndroid);
175 mNativeWebContentsObserverAndroid = 0;
179 private native long nativeInit(WebContents webContents);
180 private native void nativeDestroy(long nativeWebContentsObserverAndroid);