WebContentsObserverAndroid.java revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
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.
4
5package org.chromium.content.browser;
6
7import org.chromium.base.CalledByNative;
8import org.chromium.base.JNINamespace;
9
10/**
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.
13 */
14@JNINamespace("content")
15public abstract class WebContentsObserverAndroid {
16    private long mNativeWebContentsObserverAndroid;
17
18    public WebContentsObserverAndroid(ContentViewCore contentViewCore) {
19        mNativeWebContentsObserverAndroid = nativeInit(contentViewCore.getNativeContentViewCore());
20    }
21
22    @CalledByNative
23    public void renderProcessGone(boolean wasOomProtected) {
24    }
25
26    /**
27     * Called when the a page starts loading.
28     * @param url The validated url for the loading page.
29     */
30    @CalledByNative
31    public void didStartLoading(String url) {
32    }
33
34    /**
35     * Called when the a page finishes loading.
36     * @param url The validated url for the page.
37     */
38    @CalledByNative
39    public void didStopLoading(String url) {
40    }
41
42    /**
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.
47     */
48    @CalledByNative
49    public void didFailLoad(boolean isProvisionalLoad,
50            boolean isMainFrame, int errorCode, String description, String failingUrl) {
51    }
52
53    /**
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 isFragmentNavigation Whether the main frame navigation did not cause changes to the
59     *                             document (for example scrolling to a named anchor or PopState).
60     */
61    @CalledByNative
62    public void didNavigateMainFrame(String url, String baseUrl,
63            boolean isNavigationToDifferentPage, boolean isFragmentNavigation) {
64    }
65
66    /**
67     * Called when the page had painted something non-empty.
68     */
69    @CalledByNative
70    public void didFirstVisuallyNonEmptyPaint() {
71    }
72
73    /**
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.
78     */
79    @CalledByNative
80    public void didNavigateAnyFrame(String url, String baseUrl, boolean isReload) {
81    }
82
83    /**
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.
92     */
93    @CalledByNative
94    public void didStartProvisionalLoadForFrame(
95            long frameId,
96            long parentFrameId,
97            boolean isMainFrame,
98            String validatedUrl,
99            boolean isErrorPage,
100            boolean isIframeSrcdoc) {
101    }
102
103    /**
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.
111     */
112    @CalledByNative
113    public void didCommitProvisionalLoadForFrame(
114            long frameId, boolean isMainFrame, String url, int transitionType) {
115
116    }
117
118    /**
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.
123     */
124    @CalledByNative
125    public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) {
126    }
127
128    /**
129     * Notifies that the document has finished loading for the given frame.
130     * @param frameId A positive, non-zero integer identifying the navigating frame.
131     */
132    @CalledByNative
133    public void documentLoadedInFrame(long frameId) {
134    }
135
136    /**
137     * Notifies that a navigation entry has been committed.
138     */
139    @CalledByNative
140    public void navigationEntryCommitted() {
141    }
142
143    /**
144     * Called when an interstitial page gets attached to the tab content.
145     */
146    @CalledByNative
147    public void didAttachInterstitialPage() {
148    }
149
150    /**
151     * Called when an interstitial page gets detached from the tab content.
152     */
153    @CalledByNative
154    public void didDetachInterstitialPage() {
155    }
156
157    /**
158     * Destroy the corresponding native object.
159     */
160    @CalledByNative
161    public void detachFromWebContents() {
162        if (mNativeWebContentsObserverAndroid != 0) {
163            nativeDestroy(mNativeWebContentsObserverAndroid);
164            mNativeWebContentsObserverAndroid = 0;
165        }
166    }
167
168    private native long nativeInit(long contentViewCorePtr);
169    private native void nativeDestroy(long nativeWebContentsObserverAndroid);
170}
171