OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ |
6 #define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ | 6 #define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ |
7 | 7 |
8 #include "base/process/kill.h" | 8 #include "base/process/kill.h" |
9 #include "base/process/process_handle.h" | 9 #include "base/process/process_handle.h" |
10 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // been replaced is in |old_host|, which is nullptr if the old RVH was shut | 115 // been replaced is in |old_host|, which is nullptr if the old RVH was shut |
116 // down. | 116 // down. |
117 virtual void RenderViewHostChanged(RenderViewHost* old_host, | 117 virtual void RenderViewHostChanged(RenderViewHost* old_host, |
118 RenderViewHost* new_host) {} | 118 RenderViewHost* new_host) {} |
119 | 119 |
120 // Navigation related events ------------------------------------------------ | 120 // Navigation related events ------------------------------------------------ |
121 | 121 |
122 // Called when a navigation started in the WebContents. |navigation_handle| | 122 // Called when a navigation started in the WebContents. |navigation_handle| |
123 // is unique to a specific navigation. The same |navigation_handle| will be | 123 // is unique to a specific navigation. The same |navigation_handle| will be |
124 // provided on subsequent calls to | 124 // provided on subsequent calls to |
125 // DidRedirect/Commit/FinishNavigation/ReadyToCommitNavigation related to | 125 // DidRedirect/FinishNavigation/ReadyToCommitNavigation related to this |
126 // this navigation. | 126 // navigation. |
127 // | 127 // |
128 // Note that this is fired by navigations in any frame of the WebContents, | 128 // Note that this is fired by navigations in any frame of the WebContents, |
129 // not just the main frame. | 129 // not just the main frame. |
130 // | 130 // |
131 // Note that more than one navigation can be ongoing in the same frame at the | 131 // Note that more than one navigation can be ongoing in the same frame at the |
132 // same time (including the main frame). Each will get its own | 132 // same time (including the main frame). Each will get its own |
133 // NavigationHandle. | 133 // NavigationHandle. |
134 // | 134 // |
135 // Note that there is no guarantee that DidFinishNavigation will be called | 135 // Note that there is no guarantee that DidFinishNavigation will be called |
136 // for any particular navigation before DidStartNavigation is called on the | 136 // for any particular navigation before DidStartNavigation is called on the |
137 // next. | 137 // next. |
138 virtual void DidStartNavigation(NavigationHandle* navigation_handle) {} | 138 virtual void DidStartNavigation(NavigationHandle* navigation_handle) {} |
139 | 139 |
140 // Called when a navigation encountered a server redirect. | 140 // Called when a navigation encountered a server redirect. |
141 virtual void DidRedirectNavigation(NavigationHandle* navigation_handle) {} | 141 virtual void DidRedirectNavigation(NavigationHandle* navigation_handle) {} |
142 | 142 |
143 // PlzNavigate | 143 // PlzNavigate |
144 // Called when the navigation is ready to be committed in a renderer. This is | 144 // Called when the navigation is ready to be committed in a renderer. Most |
145 // the first point in time where a RenderFrameHost is associated with the | 145 // observers should use DidFinishNavigation instead, which happens right |
146 // navigation. Observers that want to initialize any renderer side | 146 // after the navigation commits. This method is for observers that want to |
147 // structures/state before the RenderFrame is navigated, should use this | 147 // initialize renderer-side state just before the RenderFrame commits the |
148 // method as opposed to DidCommitNavigation, which is after the fact. | 148 // navigation. |
| 149 // |
| 150 // This is the first point in time where a RenderFrameHost is associated with |
| 151 // the navigation. |
149 virtual void ReadyToCommitNavigation(NavigationHandle* navigation_handle) {} | 152 virtual void ReadyToCommitNavigation(NavigationHandle* navigation_handle) {} |
150 | 153 |
151 // Called when a navigation was committed. | 154 // Called when a navigation finished in the WebContents. This happens when a |
152 virtual void DidCommitNavigation(NavigationHandle* navigation_handle) {} | 155 // navigation is committed, aborted or replaced by a new one. To know if the |
| 156 // navigation has committed, use NavigationHandle::HasCommited; use |
| 157 // NavigationHandle::IsErrorPage to know if the navigation resulted in an |
| 158 // error page. |
| 159 // |
| 160 // If this is called because the navigation committed, then the document load |
| 161 // will still be ongoing in the RenderFrameHost returned by |
| 162 // |navigation_handle|. Use the document loads events such as DidStopLoading |
| 163 // and related methods to listen for continued events from this |
| 164 // RenderFrameHost. |
| 165 // |
| 166 // Note that |navigation_handle| will be destroyed at the end of this call, |
| 167 // so do not keep a reference to it afterward. |
| 168 virtual void DidFinishNavigation(NavigationHandle* navigation_handle) {} |
153 | 169 |
154 // Called when a navigation stopped in the WebContents. This happens when a | 170 // Document load events ------------------------------------------------------ |
155 // navigation is either aborted, replaced by a new one, or the document load | 171 |
156 // finishes. Note that |navigation_handle| will be destroyed at the end of | 172 // These two methods correspond to the points in time when the spinner of the |
157 // this call, so do not keep a reference to it afterward. | 173 // tab starts and stops spinning. |
158 virtual void DidFinishNavigation(NavigationHandle* navigation_handle) {} | 174 virtual void DidStartLoading() {} |
| 175 virtual void DidStopLoading() {} |
| 176 |
| 177 // This method is invoked once the window.document object of the main frame |
| 178 // was created. |
| 179 virtual void DocumentAvailableInMainFrame() {} |
| 180 |
| 181 // This method is invoked once the onload handler of the main frame has |
| 182 // completed. |
| 183 virtual void DocumentOnLoadCompletedInMainFrame() {} |
| 184 |
| 185 // This method is invoked when the document in the given frame finished |
| 186 // loading. At this point, scripts marked as defer were executed, and |
| 187 // content scripts marked "document_end" get injected into the frame. |
| 188 virtual void DocumentLoadedInFrame(RenderFrameHost* render_frame_host) {} |
| 189 |
| 190 // This method is invoked when the navigation is done, i.e. the spinner of |
| 191 // the tab will stop spinning, and the onload event was dispatched. |
| 192 // |
| 193 // If the WebContents is displaying replacement content, e.g. network error |
| 194 // pages, DidFinishLoad is invoked for frames that were not sending |
| 195 // navigational events before. It is safe to ignore these events. |
| 196 virtual void DidFinishLoad(RenderFrameHost* render_frame_host, |
| 197 const GURL& validated_url) {} |
| 198 |
| 199 // This method is like DidFinishLoad, but when the load failed or was |
| 200 // cancelled, e.g. window.stop() is invoked. |
| 201 virtual void DidFailLoad(RenderFrameHost* render_frame_host, |
| 202 const GURL& validated_url, |
| 203 int error_code, |
| 204 const base::string16& error_description, |
| 205 bool was_ignored_by_handler) {} |
159 | 206 |
160 // --------------------------------------------------------------------------- | 207 // --------------------------------------------------------------------------- |
161 | 208 |
162 // This method is invoked after the WebContents decides which RenderFrameHost | 209 // This method is invoked after the WebContents decides which RenderFrameHost |
163 // to use for the next browser-initiated navigation, but before the navigation | 210 // to use for the next browser-initiated navigation, but before the navigation |
164 // starts. It is not called for most renderer-initiated navigations, and it | 211 // starts. It is not called for most renderer-initiated navigations, and it |
165 // does not guarantee that the navigation will commit (e.g., 204s, downloads). | 212 // does not guarantee that the navigation will commit (e.g., 204s, downloads). |
166 // | 213 // |
167 // DEPRECATED. This method is difficult to use correctly and should be | 214 // DEPRECATED. This method is difficult to use correctly and should be |
168 // removed. TODO(creis): Remove in http://crbug.com/424641. | 215 // removed. TODO(creis): Remove in http://crbug.com/424641. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 const FrameNavigateParams& params) {} | 273 const FrameNavigateParams& params) {} |
227 | 274 |
228 // This method is invoked when the SecurityStyle of the WebContents changes. | 275 // This method is invoked when the SecurityStyle of the WebContents changes. |
229 // |security_style| is the new SecurityStyle. |security_style_explanations| | 276 // |security_style| is the new SecurityStyle. |security_style_explanations| |
230 // contains human-readable strings explaining why the SecurityStyle of the | 277 // contains human-readable strings explaining why the SecurityStyle of the |
231 // page has been downgraded. | 278 // page has been downgraded. |
232 virtual void SecurityStyleChanged( | 279 virtual void SecurityStyleChanged( |
233 SecurityStyle security_style, | 280 SecurityStyle security_style, |
234 const SecurityStyleExplanations& security_style_explanations) {} | 281 const SecurityStyleExplanations& security_style_explanations) {} |
235 | 282 |
236 // This method is invoked once the window.document object of the main frame | |
237 // was created. | |
238 virtual void DocumentAvailableInMainFrame() {} | |
239 | |
240 // This method is invoked once the onload handler of the main frame has | |
241 // completed. | |
242 virtual void DocumentOnLoadCompletedInMainFrame() {} | |
243 | |
244 // This method is invoked when the document in the given frame finished | |
245 // loading. At this point, scripts marked as defer were executed, and | |
246 // content scripts marked "document_end" get injected into the frame. | |
247 virtual void DocumentLoadedInFrame(RenderFrameHost* render_frame_host) {} | |
248 | |
249 // This method is invoked when the navigation is done, i.e. the spinner of | |
250 // the tab will stop spinning, and the onload event was dispatched. | |
251 // | |
252 // If the WebContents is displaying replacement content, e.g. network error | |
253 // pages, DidFinishLoad is invoked for frames that were not sending | |
254 // navigational events before. It is safe to ignore these events. | |
255 virtual void DidFinishLoad(RenderFrameHost* render_frame_host, | |
256 const GURL& validated_url) {} | |
257 | |
258 // This method is like DidFinishLoad, but when the load failed or was | |
259 // cancelled, e.g. window.stop() is invoked. | |
260 virtual void DidFailLoad(RenderFrameHost* render_frame_host, | |
261 const GURL& validated_url, | |
262 int error_code, | |
263 const base::string16& error_description, | |
264 bool was_ignored_by_handler) {} | |
265 | |
266 // This method is invoked when content was loaded from an in-memory cache. | 283 // This method is invoked when content was loaded from an in-memory cache. |
267 virtual void DidLoadResourceFromMemoryCache( | 284 virtual void DidLoadResourceFromMemoryCache( |
268 const LoadFromMemoryCacheDetails& details) {} | 285 const LoadFromMemoryCacheDetails& details) {} |
269 | 286 |
270 // This method is invoked when a response has been received for a resource | 287 // This method is invoked when a response has been received for a resource |
271 // request. | 288 // request. |
272 virtual void DidGetResourceResponseStart( | 289 virtual void DidGetResourceResponseStart( |
273 const ResourceRequestDetails& details) {} | 290 const ResourceRequestDetails& details) {} |
274 | 291 |
275 // This method is invoked when a redirect was received while requesting a | 292 // This method is invoked when a redirect was received while requesting a |
(...skipping 17 matching lines...) Expand all Loading... |
293 RenderFrameHost* source_render_frame_host, | 310 RenderFrameHost* source_render_frame_host, |
294 const GURL& url, | 311 const GURL& url, |
295 const Referrer& referrer, | 312 const Referrer& referrer, |
296 WindowOpenDisposition disposition, | 313 WindowOpenDisposition disposition, |
297 ui::PageTransition transition) {} | 314 ui::PageTransition transition) {} |
298 | 315 |
299 // This method is invoked when the renderer process has completed its first | 316 // This method is invoked when the renderer process has completed its first |
300 // paint after a non-empty layout. | 317 // paint after a non-empty layout. |
301 virtual void DidFirstVisuallyNonEmptyPaint() {} | 318 virtual void DidFirstVisuallyNonEmptyPaint() {} |
302 | 319 |
303 // These two methods correspond to the points in time when the spinner of the | |
304 // tab starts and stops spinning. | |
305 virtual void DidStartLoading() {} | |
306 virtual void DidStopLoading() {} | |
307 | |
308 // When WebContents::Stop() is called, the WebContents stops loading and then | 320 // When WebContents::Stop() is called, the WebContents stops loading and then |
309 // invokes this method. If there are ongoing navigations, their respective | 321 // invokes this method. If there are ongoing navigations, their respective |
310 // failure methods will also be invoked. | 322 // failure methods will also be invoked. |
311 virtual void NavigationStopped() {} | 323 virtual void NavigationStopped() {} |
312 | 324 |
313 // This indicates that the next navigation was triggered by a user gesture. | 325 // This indicates that the next navigation was triggered by a user gesture. |
314 virtual void DidGetUserGesture() {} | 326 virtual void DidGetUserGesture() {} |
315 | 327 |
316 // This method is invoked when a RenderViewHost of this WebContents was | 328 // This method is invoked when a RenderViewHost of this WebContents was |
317 // configured to ignore UI events, and an UI event took place. | 329 // configured to ignore UI events, and an UI event took place. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 void ResetWebContents(); | 465 void ResetWebContents(); |
454 | 466 |
455 WebContentsImpl* web_contents_; | 467 WebContentsImpl* web_contents_; |
456 | 468 |
457 DISALLOW_COPY_AND_ASSIGN(WebContentsObserver); | 469 DISALLOW_COPY_AND_ASSIGN(WebContentsObserver); |
458 }; | 470 }; |
459 | 471 |
460 } // namespace content | 472 } // namespace content |
461 | 473 |
462 #endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ | 474 #endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ |
OLD | NEW |