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 * TODO(pedrosimonetti): Remove this method once downstream changes are landed.
59 * @param url The validated url for the page.
60 * @param baseUrl The validated base url for the page.
61 * @param isNavigationToDifferentPage Whether the main frame navigated to a different page.
62 * @param isFragmentNavigation Whether the main frame navigation did not cause changes to the
63 * 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 main frame of the page has committed.
71 * @param url The validated url for the page.
72 * @param baseUrl The validated base url for the page.
73 * @param isNavigationToDifferentPage Whether the main frame navigated to a different page.
74 * @param isFragmentNavigation Whether the main frame navigation did not cause changes to the
75 * document (for example scrolling to a named anchor or PopState).
76 * @param statusCode The HTTP status code of the navigation.
79 public void didNavigateMainFrame(String url, String baseUrl,
80 boolean isNavigationToDifferentPage, boolean isFragmentNavigation, int statusCode) {
81 didNavigateMainFrame(url, baseUrl, isNavigationToDifferentPage, isFragmentNavigation);
85 * Called when the page had painted something non-empty.
88 public void didFirstVisuallyNonEmptyPaint() {
92 * Similar to didNavigateMainFrame but also called on subframe navigations.
93 * @param url The validated url for the page.
94 * @param baseUrl The validated base url for the page.
95 * @param isReload True if this navigation is a reload.
98 public void didNavigateAnyFrame(String url, String baseUrl, boolean isReload) {
102 * Notifies that a load is started for a given frame.
103 * @param frameId A positive, non-zero integer identifying the navigating frame.
104 * @param parentFrameId The frame identifier of the frame containing the navigating frame,
105 * or -1 if the frame is not contained in another frame.
106 * @param isMainFrame Whether the load is happening for the main frame.
107 * @param validatedUrl The validated URL that is being navigated to.
108 * @param isErrorPage Whether this is navigating to an error page.
109 * @param isIframeSrcdoc Whether this is navigating to about:srcdoc.
112 public void didStartProvisionalLoadForFrame(
118 boolean isIframeSrcdoc) {
122 * Notifies that the provisional load was successfully committed. The RenderViewHost is now
123 * the current RenderViewHost of the WebContents.
124 * @param frameId A positive, non-zero integer identifying the navigating frame.
125 * @param isMainFrame Whether the load is happening for the main frame.
126 * @param url The committed URL being navigated to.
127 * @param transitionType The transition type as defined in
128 * {@link org.chromium.ui.base.PageTransitionTypes} for the load.
131 public void didCommitProvisionalLoadForFrame(
132 long frameId, boolean isMainFrame, String url, int transitionType) {
137 * Notifies that a load has finished for a given frame.
138 * @param frameId A positive, non-zero integer identifying the navigating frame.
139 * @param validatedUrl The validated URL that is being navigated to.
140 * @param isMainFrame Whether the load is happening for the main frame.
143 public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) {
147 * Notifies that the document has finished loading for the given frame.
148 * @param frameId A positive, non-zero integer identifying the navigating frame.
151 public void documentLoadedInFrame(long frameId) {
155 * Notifies that a navigation entry has been committed.
158 public void navigationEntryCommitted() {
162 * Called when an interstitial page gets attached to the tab content.
165 public void didAttachInterstitialPage() {
169 * Called when an interstitial page gets detached from the tab content.
172 public void didDetachInterstitialPage() {
176 * Called when the theme color was changed.
177 * @param color the new color in ARGB format
180 public void didChangeThemeColor(int color) {
184 * Destroy the corresponding native object.
187 public void detachFromWebContents() {
188 if (mNativeWebContentsObserverAndroid != 0) {
189 nativeDestroy(mNativeWebContentsObserverAndroid);
190 mNativeWebContentsObserverAndroid = 0;
194 private native long nativeInit(WebContents webContents);
195 private native void nativeDestroy(long nativeWebContentsObserverAndroid);