• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 package org.chromium.content.browser;
6 
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;
11 
12 /**
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.
15  */
16 @JNINamespace("content")
17 public abstract class WebContentsObserverAndroid {
18     private long mNativeWebContentsObserverAndroid;
19 
WebContentsObserverAndroid(WebContents webContents)20     public WebContentsObserverAndroid(WebContents webContents) {
21         ThreadUtils.assertOnUiThread();
22         mNativeWebContentsObserverAndroid = nativeInit(webContents);
23     }
24 
25     @CalledByNative
renderProcessGone(boolean wasOomProtected)26     public void renderProcessGone(boolean wasOomProtected) {
27     }
28 
29     /**
30      * Called when the a page starts loading.
31      * @param url The validated url for the loading page.
32      */
33     @CalledByNative
didStartLoading(String url)34     public void didStartLoading(String url) {
35     }
36 
37     /**
38      * Called when the a page finishes loading.
39      * @param url The validated url for the page.
40      */
41     @CalledByNative
didStopLoading(String url)42     public void didStopLoading(String url) {
43     }
44 
45     /**
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.
50      */
51     @CalledByNative
didFailLoad(boolean isProvisionalLoad, boolean isMainFrame, int errorCode, String description, String failingUrl)52     public void didFailLoad(boolean isProvisionalLoad,
53             boolean isMainFrame, int errorCode, String description, String failingUrl) {
54     }
55 
56     /**
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).
64      */
didNavigateMainFrame(String url, String baseUrl, boolean isNavigationToDifferentPage, boolean isFragmentNavigation)65     public void didNavigateMainFrame(String url, String baseUrl,
66             boolean isNavigationToDifferentPage, boolean isFragmentNavigation) {
67     }
68 
69     /**
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.
77      */
78     @CalledByNative
didNavigateMainFrame(String url, String baseUrl, boolean isNavigationToDifferentPage, boolean isFragmentNavigation, int statusCode)79     public void didNavigateMainFrame(String url, String baseUrl,
80             boolean isNavigationToDifferentPage, boolean isFragmentNavigation, int statusCode) {
81         didNavigateMainFrame(url, baseUrl, isNavigationToDifferentPage, isFragmentNavigation);
82     }
83 
84     /**
85      * Called when the page had painted something non-empty.
86      */
87     @CalledByNative
didFirstVisuallyNonEmptyPaint()88     public void didFirstVisuallyNonEmptyPaint() {
89     }
90 
91     /**
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.
96      */
97     @CalledByNative
didNavigateAnyFrame(String url, String baseUrl, boolean isReload)98     public void didNavigateAnyFrame(String url, String baseUrl, boolean isReload) {
99     }
100 
101     /**
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.
110      */
111     @CalledByNative
didStartProvisionalLoadForFrame( long frameId, long parentFrameId, boolean isMainFrame, String validatedUrl, boolean isErrorPage, boolean isIframeSrcdoc)112     public void didStartProvisionalLoadForFrame(
113             long frameId,
114             long parentFrameId,
115             boolean isMainFrame,
116             String validatedUrl,
117             boolean isErrorPage,
118             boolean isIframeSrcdoc) {
119     }
120 
121     /**
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.
129      */
130     @CalledByNative
didCommitProvisionalLoadForFrame( long frameId, boolean isMainFrame, String url, int transitionType)131     public void didCommitProvisionalLoadForFrame(
132             long frameId, boolean isMainFrame, String url, int transitionType) {
133 
134     }
135 
136     /**
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.
141      */
142     @CalledByNative
didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame)143     public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) {
144     }
145 
146     /**
147      * Notifies that the document has finished loading for the given frame.
148      * @param frameId A positive, non-zero integer identifying the navigating frame.
149      */
150     @CalledByNative
documentLoadedInFrame(long frameId)151     public void documentLoadedInFrame(long frameId) {
152     }
153 
154     /**
155      * Notifies that a navigation entry has been committed.
156      */
157     @CalledByNative
navigationEntryCommitted()158     public void navigationEntryCommitted() {
159     }
160 
161     /**
162      * Called when an interstitial page gets attached to the tab content.
163      */
164     @CalledByNative
didAttachInterstitialPage()165     public void didAttachInterstitialPage() {
166     }
167 
168     /**
169      * Called when an interstitial page gets detached from the tab content.
170      */
171     @CalledByNative
didDetachInterstitialPage()172     public void didDetachInterstitialPage() {
173     }
174 
175     /**
176      * Called when the theme color was changed.
177      * @param color the new color in ARGB format
178      */
179     @CalledByNative
didChangeThemeColor(int color)180     public void didChangeThemeColor(int color) {
181     }
182 
183     /**
184      * Destroy the corresponding native object.
185      */
186     @CalledByNative
detachFromWebContents()187     public void detachFromWebContents() {
188         if (mNativeWebContentsObserverAndroid != 0) {
189             nativeDestroy(mNativeWebContentsObserverAndroid);
190             mNativeWebContentsObserverAndroid = 0;
191         }
192     }
193 
nativeInit(WebContents webContents)194     private native long nativeInit(WebContents webContents);
nativeDestroy(long nativeWebContentsObserverAndroid)195     private native void nativeDestroy(long nativeWebContentsObserverAndroid);
196 }
197