WebContentsObserverAndroid.java revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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    // TODO(mkosiba): delete once downstream rolls.
54    @Deprecated
55    @CalledByNative
56    public void didNavigateMainFrame(String url, String baseUrl,
57            boolean isNavigationToDifferentPage) {
58    }
59
60    /**
61     * Called when the main frame of the page has committed.
62     * @param url The validated url for the page.
63     * @param baseUrl The validated base url for the page.
64     * @param isNavigationToDifferentPage Whether the main frame navigated to a different page.
65     * @param isNavigationInPage Whether the main frame navigation did not cause changes to the
66     *                           document (for example scrolling to a named anchor or PopState).
67     */
68    @CalledByNative
69    public void didNavigateMainFrame(String url, String baseUrl,
70            boolean isNavigationToDifferentPage, boolean isNavigationInPage) {
71    }
72
73    /**
74     * Called when the page had painted something non-empty.
75     * @param pageId unique ID of the page in history entries.
76     */
77    @CalledByNative
78    public void didFirstVisuallyNonEmptyPaint(int pageId) {
79    }
80
81    /**
82     * Similar to didNavigateMainFrame but also called on subframe navigations.
83     * @param url The validated url for the page.
84     * @param baseUrl The validated base url for the page.
85     * @param isReload True if this navigation is a reload.
86     */
87    @CalledByNative
88    public void didNavigateAnyFrame(String url, String baseUrl, boolean isReload) {
89    }
90
91    /**
92     * Notifies that a load is started for a given frame.
93     * @param frameId A positive, non-zero integer identifying the navigating frame.
94     * @param parentFrameId The frame identifier of the frame containing the navigating frame,
95     *                      or -1 if the frame is not contained in another frame.
96     * @param isMainFrame Whether the load is happening for the main frame.
97     * @param validatedUrl The validated URL that is being navigated to.
98     * @param isErrorPage Whether this is navigating to an error page.
99     * @param isIframeSrcdoc Whether this is navigating to about:srcdoc.
100     */
101    @CalledByNative
102    public void didStartProvisionalLoadForFrame(
103            long frameId,
104            long parentFrameId,
105            boolean isMainFrame,
106            String validatedUrl,
107            boolean isErrorPage,
108            boolean isIframeSrcdoc) {
109    }
110
111    /**
112     * Notifies that the provisional load was successfully committed. The RenderViewHost is now
113     * the current RenderViewHost of the WebContents.
114     * @param frameId A positive, non-zero integer identifying the navigating frame.
115     * @param isMainFrame Whether the load is happening for the main frame.
116     * @param url The committed URL being navigated to.
117     * @param transitionType The transition type as defined in
118     *                      {@link org.chromium.content.browser.PageTransitionTypes} for the load.
119     */
120    @CalledByNative
121    public void didCommitProvisionalLoadForFrame(
122            long frameId, boolean isMainFrame, String url, int transitionType) {
123
124    }
125
126    /**
127     * Notifies that a load has finished for a given frame.
128     * @param frameId A positive, non-zero integer identifying the navigating frame.
129     * @param validatedUrl The validated URL that is being navigated to.
130     * @param isMainFrame Whether the load is happening for the main frame.
131     */
132    @CalledByNative
133    public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) {
134    }
135
136    /**
137     * Notifies that a navigation entry has been committed.
138     */
139    @CalledByNative
140    public void navigationEntryCommitted() {
141    }
142
143    /**
144     * Invoked when visible SSL state changes.
145     */
146    @CalledByNative
147    public void didChangeVisibleSSLState() {
148    }
149
150    /**
151     * Called when an interstitial page gets attached to the tab content.
152     */
153    @CalledByNative
154    public void didAttachInterstitialPage() {
155    }
156
157    /**
158     * Called when an interstitial page gets detached from the tab content.
159     */
160    @CalledByNative
161    public void didDetachInterstitialPage() {
162    }
163
164    /**
165     * Destroy the corresponding native object.
166     */
167    @CalledByNative
168    public void detachFromWebContents() {
169        if (mNativeWebContentsObserverAndroid != 0) {
170            nativeDestroy(mNativeWebContentsObserverAndroid);
171            mNativeWebContentsObserverAndroid = 0;
172        }
173    }
174
175    private native long nativeInit(long contentViewCorePtr);
176    private native void nativeDestroy(long nativeWebContentsObserverAndroid);
177}
178