blob: 9ee3b74460c009c92fb811787250270ea13233b3 [file] [log] [blame]
[email protected]b172aee2012-04-10 17:05:261// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d8c660432011-12-22 20:51:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_
6#define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_
7
avi652869c2015-12-25 01:48:458#include <stdint.h>
9
Keishi Hattori0e45c022021-11-27 09:25:5210#include "base/memory/raw_ptr.h"
[email protected]c3c10f22013-07-25 14:21:1211#include "base/process/kill.h"
12#include "base/process/process_handle.h"
Alexander Timin17edc742020-04-23 18:22:1813#include "base/threading/thread_restrictions.h"
David Black9cca3592019-11-06 23:02:2214#include "components/viz/common/vertical_scroll_direction.h"
[email protected]d8c660432011-12-22 20:51:2515#include "content/common/content_export.h"
Alexander Timin17edc742020-04-23 18:22:1816#include "content/public/browser/allow_service_worker_result.h"
toyoshim0df1d3a2016-09-09 09:52:4817#include "content/public/browser/reload_type.h"
Christian Dullweber5e66727b2021-07-02 13:23:1518#include "content/public/browser/render_frame_host.h"
Francois Dorayfe4a1772018-02-17 04:17:0919#include "content/public/browser/visibility.h"
Christian Dullweber5e66727b2021-07-02 13:23:1520#include "ipc/ipc_message.h"
Ben Goodger9e24929e2017-07-21 03:13:4021#include "mojo/public/cpp/system/message_pipe.h"
Kinuko Yasuda433f710a2020-02-14 02:11:5822#include "services/network/public/mojom/fetch_api.mojom-forward.h"
Ben Goodger9e24929e2017-07-21 03:13:4023#include "services/service_manager/public/cpp/bind_source_info.h"
Anton Bikineevf62d1bf2021-05-15 17:56:0724#include "third_party/abseil-cpp/absl/types/optional.h"
Dave Tapuska129cef82019-12-19 16:36:4825#include "third_party/blink/public/common/input/web_input_event.h"
Maks Orlovich73f374d2020-04-02 12:46:1326#include "third_party/blink/public/common/user_agent/user_agent_metadata.h"
Michael Bai19f17a302021-12-08 04:08:3327#include "third_party/blink/public/mojom/css/preferred_color_scheme.mojom.h"
Devlin Cronin5ea668f32019-12-18 21:57:5828#include "third_party/blink/public/mojom/devtools/console_message.mojom.h"
Hans Wennborg7d15b702021-03-31 17:58:5529#include "third_party/blink/public/mojom/favicon/favicon_url.mojom-forward.h"
Minggang Wangee5af392020-02-05 02:55:2830#include "third_party/blink/public/mojom/loader/resource_load_info.mojom-forward.h"
Lei Zhang3ee2b78a2021-05-18 20:58:4431#include "third_party/blink/public/mojom/media/capture_handle_config.mojom-forward.h"
[email protected]e7104762014-06-20 19:17:2532#include "third_party/skia/include/core/SkColor.h"
Sylvain Defresnec6ccc77d2014-09-19 10:19:3533#include "ui/base/page_transition_types.h"
[email protected]f47621b2013-01-22 20:50:3334#include "ui/base/window_open_disposition.h"
[email protected]d8c660432011-12-22 20:51:2535
Christian Dullweber5e66727b2021-07-02 13:23:1536class GURL;
37
Becca Hughes6fe54e432018-06-09 04:18:5638namespace blink {
39namespace mojom {
40enum class ViewportFit;
41} // namespace mojom
42} // namespace blink
43
peconn257951522017-06-09 18:24:5944namespace gfx {
45class Size;
46} // namespace gfx
47
[email protected]d8c660432011-12-22 20:51:2548namespace content {
49
[email protected]1ef02d242013-10-07 16:18:5350class NavigationEntry;
clamy0e119882015-07-31 16:12:3351class NavigationHandle;
[email protected]b849847b2013-12-10 21:57:5852class RenderFrameHost;
Avi Drissmanb3d355f2018-01-29 20:08:1853class RenderProcessHost;
[email protected]eaabba22012-03-07 15:02:1154class RenderViewHost;
afakhry98241832016-03-11 19:27:4755class RenderWidgetHost;
Sreeja Kamishetty53468972021-07-13 11:53:3256class Page;
[email protected]26b5e322011-12-23 01:36:4757class WebContents;
[email protected]31a71eaf2014-03-13 01:47:3658struct AXEventNotificationDetails;
dmazzoni2400c462016-08-23 15:07:1359struct AXLocationChangeNotificationDetails;
Christian Dullweber5e66727b2021-07-02 13:23:1560struct CookieAccessDetails;
Sam McNally5c087a32017-08-25 01:46:1461struct EntryChangedDetails;
Jeff Fisher709b4c52019-07-29 20:07:3462struct FocusedNodeDetails;
Christian Dullweber5e66727b2021-07-02 13:23:1563struct GlobalRequestID;
[email protected]71fde352011-12-29 03:29:5664struct LoadCommittedDetails;
Mounir Lamouri0f5bdf52019-04-04 16:32:3565struct MediaPlayerId;
Sam McNally5c087a32017-08-25 01:46:1466struct PrunedDetails;
[email protected]d8c660432011-12-22 20:51:2567struct Referrer;
68
Daniel Cheng2809eff2021-09-28 00:20:3169// Note: before adding a new `WebContentsObserver` subclass, consider if simpler
70// helpers will suffice:
71//
72// - Classes that have a 1:1 relationship with one RenderFrameHost can often
Sreeja Kamishetty0a0961f2021-10-11 16:23:5373// use `DocumentUserData` instead.
Daniel Cheng2809eff2021-09-28 00:20:3174// - Mojo interface implementations that have a 1 RenderFrameHost to many
Daniel Cheng9fb887ff2021-10-01 20:27:3875// instances relationship can often use `DocumentService` instead.
Daniel Cheng2809eff2021-09-28 00:20:3176//
77// These helpers can help avoid memory safety bugs, such as retaining a pointer
78// to a deleted RenderFrameHost, or other security issues, such as origin
79// confusion when a RenderFrameHost is reused after a cross-document navigation.
80
[email protected]d8c660432011-12-22 20:51:2581// An observer API implemented by classes which are interested in various page
John Abd-El-Malek5b1d7252021-03-05 21:03:0882// events from WebContents. They also get a chance to filter IPC messages.
83// The difference between WebContentsDelegate (WCD) and WebContentsObserver
84// (WCO) is that there is one WCD per WebContents and many WCOs. Methods which
85// have a return value, e.g. are expected to change state, should be on WCD.
[email protected]87eca182013-01-31 21:20:0086//
[email protected]d16609c2013-08-23 06:01:4087// Since a WebContents can be a delegate to almost arbitrarily many
[email protected]87eca182013-01-31 21:20:0088// RenderViewHosts, it is important to check in those WebContentsObserver
89// methods which take a RenderViewHost that the event came from the
90// RenderViewHost the observer cares about.
91//
92// Usually, observers should only care about the current RenderViewHost as
93// returned by GetRenderViewHost().
94//
Jochen Eisinger3bc98972022-01-12 18:44:2395// TODO(creis): Hide the fact that there are several RenderViewHosts
[email protected]87eca182013-01-31 21:20:0096// from the WebContentsObserver API. http://crbug.com/173325
Dave Tapuska34310de2021-06-02 20:21:0197class CONTENT_EXPORT WebContentsObserver {
[email protected]d8c660432011-12-22 20:51:2598 public:
Peter Boström9b036532021-10-28 23:37:2899 WebContentsObserver(const WebContentsObserver&) = delete;
100 WebContentsObserver& operator=(const WebContentsObserver&) = delete;
101
aviee9b7372016-06-28 20:34:43102 // Frames and Views ----------------------------------------------------------
103
nasko005282522015-01-22 02:30:02104 // Called when a RenderFrame for |render_frame_host| is created in the
Scott Violet507cbcb22020-05-21 17:24:22105 // renderer process. Use |RenderFrameDeleted| to listen for when this
106 // RenderFrame goes away.
[email protected]b849847b2013-12-10 21:57:58107 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) {}
108
nasko005282522015-01-22 02:30:02109 // Called when a RenderFrame for |render_frame_host| is deleted or the
110 // renderer process in which it runs it has died. Use |RenderFrameCreated| to
111 // listen for when RenderFrame objects are created.
[email protected]b849847b2013-12-10 21:57:58112 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) {}
113
Kevin McNeec9d0fda2021-05-19 15:55:17114 // This method is invoked whenever one of the frames of a WebContents
nasko005282522015-01-22 02:30:02115 // swaps its RenderFrameHost with another one; for example because that frame
116 // navigated and the new content is in a different process. The
117 // RenderFrameHost that has been replaced is in |old_host|, which can be
118 // nullptr if the old RenderFrameHost was shut down or a new frame has been
119 // created and no old RenderFrameHost exists.
120 //
121 // This method, in combination with |FrameDeleted|, is appropriate for
Kevin McNeec9d0fda2021-05-19 15:55:17122 // observers wishing to track the set of RenderFrameHosts that are current in
123 // their frame tree. Note that being current in a frame tree is separate from
124 // the lifecycle state of the RenderFrameHosts. Consider using
125 // |RenderFrameHostStateChanged|.
nasko005282522015-01-22 02:30:02126 virtual void RenderFrameHostChanged(RenderFrameHost* old_host,
127 RenderFrameHost* new_host) {}
128
Sreeja Kamishetty53468972021-07-13 11:53:32129 // This method is invoked whenever primary page of a WebContents
130 // (WebContents::GetPrimaryPage()) changes to `page`. This happens in one of
131 // the following cases:
Sreeja Kamishettya21b4f62021-06-25 07:48:25132 // 1) when the current RenderFrameHost in the primary main frame changes after
133 // a navigation.
134 // 2) when the current RenderFrameHost in the primary main frame is
135 // reinitialized after a crash.
136 // 3) when a cross-document navigation commits in the current RenderFrameHost
137 // of the primary main frame.
138
139 // The new primary page might either be a brand new one (if the committed
140 // navigation created a new document in the primary main frame) or an existing
141 // one (back-forward cache restore or prerendering activation).
142
143 // This notification is not dispatched for changes of pages in the non-primary
144 // frame trees (prerendering, fenced frames) and when the primary page is
145 // destroyed (e.g., when closing a tab).
146
147 // This method is useful for updating the tab-related UI which depends on the
148 // primary page's state (e.g. theme colour, such state should typically be
149 // available as a method on a Page or stored in PageUserData). Prefer
150 // listening to this method to listening to DidFinishNavigation and checking
151 // NavigationHandle::IsInPrimaryMainFrame && !NavigationHandle::IsSameDocument
152 // && NavigationHandle::HasCommitted (unless your code has to listen to
153 // DidFinishNavigation for some other reason, in which case listening only to
154 // DidFinishNavigation is recommended).
Sreeja Kamishetty53468972021-07-13 11:53:32155 virtual void PrimaryPageChanged(Page& page) {}
Sreeja Kamishettya21b4f62021-06-25 07:48:25156
Carlos Caballerobf3624962021-04-02 01:26:02157 // This method is invoked when a frame is destroyed. A subframe is destroyed
158 // when its parent detaches it or navigates to a different document. A main
159 // frame is destroyed when the whole WebContents is going away, or, with
160 // MPArch, when a non-primary frame tree (e.g., prerendered page) is
161 // destroyed.
nasko005282522015-01-22 02:30:02162 // Use |RenderFrameHostChanged| to listen for when a RenderFrameHost object is
163 // made the current host for a frame.
Carlos Caballerobf3624962021-04-02 01:26:02164 virtual void FrameDeleted(int frame_tree_node_id) {}
nasko005282522015-01-22 02:30:02165
Sreeja Kamishetty2771b7d2021-04-07 06:34:18166 // This method is invoked whenever one of the frames of a WebContents changes
167 // its |RenderFrameHost::GetLifecycleState()| i.e., when RenderFrameHost
168 // LifecycleState changes from |old_state| to |new_state|. The old
169 // LifecycleState that is being changed is |old_state| and the LifecycleState
170 // that it changes to is |new_state|. |old_state| and |new_state| are always
171 // different, i.e., a frame can't transition to the same state.
172 //
173 // This method allows code to react to RenderFrameHost LifecycleState changes.
174 // For example, to detect changes in the currently active document and perform
175 // different actions accordingly, like closing UI/resetting states,
176 // RenderFrameHostStateChanged is preferred instead of DidFinishNavigation.
177 // DidFinishNavigation does not guarantee that the old document will go away.
178 // Instead, it could enter the BackForwardCache and then become kActive later.
179 // Features that need to handle transitions like these should monitor
180 // LifecycleState changes instead.
181 //
182 // A particular document may change its LifecycleState and trigger
183 // RenderFrameHostStateChanged as part of being committed in a navigation,
184 // when another document replaces it by navigating in the same frame, in
185 // response to being detached from the DOM, or (with MPArch) as part of
186 // activating a prerendered page.
187 //
188 // When committing a cross-document, cross-RenderFrameHost navigation,
189 // navigation-related callbacks are dispatched in the following order:
190 // - RenderFrameHostStateChanged(new_frame, old_state, new_state)
191 // - RenderFrameHostChanged(old_frame, new_frame)
192 // - RenderFrameHostStateChanged(old_frame, old_state, new_state)
193 // - DidFinishNavigation(navigation_handle)
194 virtual void RenderFrameHostStateChanged(
195 RenderFrameHost* render_frame_host,
196 RenderFrameHost::LifecycleState old_state,
197 RenderFrameHost::LifecycleState new_state) {}
198
Alexander Cooper987d046cc2021-04-14 00:07:21199 // This method is invoked when something "replaces" the contents of the
200 // WebContents or otherwise changes the FrameSinkId of the contents that
201 // should be captured if capturing this WebContents, WITHOUT changing the
202 // RenderFrameHost.
203 virtual void CaptureTargetChanged() {}
204
Elad Alonf156eb62021-05-17 22:02:37205 // This method is invoked when the capture handle config changes. This can
206 // happen when:
207 // 1. The web-application calls |mediaDevices.setCaptureHandleConfig|.
208 // 2. The top-level frame is navigated cross-document.
209 virtual void OnCaptureHandleConfigUpdate(
210 const blink::mojom::CaptureHandleConfig& config) {}
211
[email protected]87eca182013-01-31 21:20:00212 // This method is invoked when the RenderView of the current RenderViewHost
213 // is ready, e.g. because we recreated it after a crash.
[email protected]d8c660432011-12-22 20:51:25214 virtual void RenderViewReady() {}
[email protected]87eca182013-01-31 21:20:00215
216 // This method is invoked when a RenderViewHost of the WebContents is
217 // deleted. Note that this does not always happen when the WebContents starts
218 // to use a different RenderViewHost, as the old RenderViewHost might get
219 // just swapped out.
220 virtual void RenderViewDeleted(RenderViewHost* render_view_host) {}
221
Dave Tapuskaf8d17842021-06-23 21:34:22222 // This method is invoked when the process for the current RenderFrameHost
223 // of the primary main frame exits (usually by crashing, though possibly by
224 // other means). The WebContents continues to use the RenderFrameHost, e.g.
225 // when the user reloads the current page. When the RenderFrameHost itself is
226 // deleted, the RenderFrameDeleted method will be invoked.
[email protected]4d614412014-01-10 08:29:37227 //
avi33601202015-07-11 01:39:26228 // Note that this is triggered upstream through
229 // RenderProcessHostObserver::RenderProcessExited(); for code that doesn't
230 // otherwise need to be a WebContentsObserver, that API is probably a better
231 // choice.
Dave Tapuska7052b7c52021-10-18 17:30:53232 virtual void PrimaryMainFrameRenderProcessGone(
233 base::TerminationStatus status) {}
[email protected]87eca182013-01-31 21:20:00234
[email protected]02d7b6e2014-06-24 21:01:50235 // This method is invoked when a WebContents swaps its visible RenderViewHost
236 // with another one, possibly changing processes. The RenderViewHost that has
mlamouri8c61ffc2015-01-13 16:17:59237 // been replaced is in |old_host|, which is nullptr if the old RVH was shut
238 // down.
[email protected]7b712ee22013-10-03 00:57:28239 virtual void RenderViewHostChanged(RenderViewHost* old_host,
240 RenderViewHost* new_host) {}
[email protected]da7a7182013-09-06 08:11:11241
Avi Drissmanb3d355f2018-01-29 20:08:18242 // This method is invoked when a process in the WebContents becomes
243 // unresponsive.
244 virtual void OnRendererUnresponsive(RenderProcessHost* render_process_host) {}
afakhry98241832016-03-11 19:27:47245
Scott Violet48202e62020-05-26 17:19:33246 // See WebContentsDelegate::RendererResponsive().
247 virtual void OnRendererResponsive(RenderProcessHost* render_process_host) {}
248
aviee9b7372016-06-28 20:34:43249 // Navigation ----------------------------------------------------------------
clamy0e119882015-07-31 16:12:33250
251 // Called when a navigation started in the WebContents. |navigation_handle|
252 // is unique to a specific navigation. The same |navigation_handle| will be
nasko14baf392016-02-02 02:15:38253 // provided on subsequent calls to DidRedirectNavigation, DidFinishNavigation,
254 // and ReadyToCommitNavigation when related to this navigation. Observers
255 // should clear any references to |navigation_handle| in DidFinishNavigation,
256 // just before it is destroyed.
clamy0e119882015-07-31 16:12:33257 //
Alexander Timin26fb41a2021-09-14 22:18:28258 // NOTES:
259 // - Starting a navigation doesn't affect which document is shown, or
260 // (in many cases) which URL is displayed in the omnibox. Most effects of the
261 // navigation only occur at DidFinishNavigation, if it commits. Feature code
262 // generally should not use DidStartNavigation to reset their state (e.g.
263 // close the UI), especially given that a renderer process can easily start a
264 // navigation which is guaranteed not to commit (e.g. by navigating to
265 // a URL returning a response with HTTP status code of 204 or a download).
Alexander Timinc6181412021-09-17 01:54:30266 // Consider listening to PrimaryPageChanged or DidFinishNavigation instead.
clamy0e119882015-07-31 16:12:33267 //
Alexander Timin26fb41a2021-09-14 22:18:28268 // - This notification is fired by navigations in any frame of the
269 // WebContents, not just the primary main frame.
270 //
271 // - This notification is fired by same-document navigations, such as fragment
clamy57f99bd22016-11-30 18:25:11272 // navigations or pushState/replaceState, which will not result in a document
eugenebuta11672fb2017-03-07 17:13:51273 // change. To filter these out, use NavigationHandle::IsSameDocument.
clamy57f99bd22016-11-30 18:25:11274 //
Alexander Timin26fb41a2021-09-14 22:18:28275 // - There can be more than one navigation can be ongoing in the same frame at
276 // the same time (including the main frame). Each will get its own
clamy0e119882015-07-31 16:12:33277 // NavigationHandle.
278 //
Alexander Timin26fb41a2021-09-14 22:18:28279 // - There is no guarantee that DidFinishNavigation will be called
clamy0e119882015-07-31 16:12:33280 // for any particular navigation before DidStartNavigation is called on the
281 // next.
282 virtual void DidStartNavigation(NavigationHandle* navigation_handle) {}
283
284 // Called when a navigation encountered a server redirect.
285 virtual void DidRedirectNavigation(NavigationHandle* navigation_handle) {}
286
John Abd-El-Malekdf8e3da2019-10-30 00:57:37287 // Called when the navigation is ready to be committed in a renderer. This
288 // occurs when the response code isn't 204/205 (which tell the browser that
289 // the request is successful but there's no content that follows) or a
290 // download (either from a response header or based on mime sniffing the
291 // response). The browser then is ready to switch rendering the new document.
292 // Most observers should use DidFinishNavigation instead, which happens right
clamyb876f0a72015-09-24 20:01:05293 // after the navigation commits. This method is for observers that want to
294 // initialize renderer-side state just before the RenderFrame commits the
295 // navigation.
296 //
297 // This is the first point in time where a RenderFrameHost is associated with
298 // the navigation.
clamyefca29e2015-09-17 00:22:11299 virtual void ReadyToCommitNavigation(NavigationHandle* navigation_handle) {}
300
clamyb876f0a72015-09-24 20:01:05301 // Called when a navigation finished in the WebContents. This happens when a
302 // navigation is committed, aborted or replaced by a new one. To know if the
vabrd9092d32016-03-16 19:03:32303 // navigation has committed, use NavigationHandle::HasCommitted; use
clamyb876f0a72015-09-24 20:01:05304 // NavigationHandle::IsErrorPage to know if the navigation resulted in an
305 // error page.
306 //
307 // If this is called because the navigation committed, then the document load
308 // will still be ongoing in the RenderFrameHost returned by
309 // |navigation_handle|. Use the document loads events such as DidStopLoading
310 // and related methods to listen for continued events from this
311 // RenderFrameHost.
312 //
eugenebuta11672fb2017-03-07 17:13:51313 // Note that this is fired by same-document navigations, such as fragment
clamy57f99bd22016-11-30 18:25:11314 // navigations or pushState/replaceState, which will not result in a document
eugenebuta11672fb2017-03-07 17:13:51315 // change. To filter these out, use NavigationHandle::IsSameDocument.
clamy57f99bd22016-11-30 18:25:11316 //
clamyb876f0a72015-09-24 20:01:05317 // Note that |navigation_handle| will be destroyed at the end of this call,
318 // so do not keep a reference to it afterward.
Alexander Timin57b9c742020-07-06 14:04:03319 //
320 // Note that using DidFinishNavigation to detect changes in the currently
Sreeja Kamishettya21b4f62021-06-25 07:48:25321 // active document / page and reset per-document state is strongly
322 // discouraged.
323 //
324 // Listening to PrimaryPageChanged should be preferred to listening to
325 // DidFinishNavigation and checking IsInPrimaryMainFrame, !IsSameDocument, and
326 // HasCommitted.
327 //
328 // The per-document / per-page data should be stored in
Sreeja Kamishetty0a0961f2021-10-11 16:23:53329 // DocumentUserData / PageUserData instead of resetting it in
Sreeja Kamishettya21b4f62021-06-25 07:48:25330 // DidFinishNavigation. (In particular, the page might be stored in the
331 // back-forward cache instead of being deleted. See comments in PageUserData /
Sreeja Kamishetty0a0961f2021-10-11 16:23:53332 // DocumentUserData for more details).
clamy0e119882015-07-31 16:12:33333 virtual void DidFinishNavigation(NavigationHandle* navigation_handle) {}
334
Lucas Gadani972985622020-05-28 20:52:51335 // Called after the contents replaces the |predecessor_contents| in its
336 // container due to portal activation. The |predecessor_contents| is now a
337 // portal pending adoption. |predecessor_contents| is non-null, but may
338 // subsequently be destroyed if it is not adopted.
339 // |activation_time| is the time the activation happened.
340 virtual void DidActivatePortal(WebContents* predecessor_web_contents,
341 base::TimeTicks activation_time) {}
342
clamyb876f0a72015-09-24 20:01:05343 // Document load events ------------------------------------------------------
344
Chris Hamiltonf82f2a702018-02-15 19:37:29345 // These three methods correspond to the points in time when a document starts
346 // loading for the first time (initiates outgoing requests), when incoming
347 // data subsequently starts arriving, and when it finishes loading.
clamyb876f0a72015-09-24 20:01:05348 virtual void DidStartLoading() {}
349 virtual void DidStopLoading() {}
350
Evan Stade9f328112019-10-23 20:49:25351 // The page has made some progress loading. |progress| is a value between 0.0
352 // (nothing loaded) to 1.0 (page fully loaded).
353 virtual void LoadProgressChanged(double progress) {}
354
Sreeja Kamishetty9bc31e2c2022-01-11 05:48:46355 // This method is invoked once the window.document element of the primary main
356 // frame's current document (i.e., |render_frame_host|) is ready. This happens
357 // when the document's main HTML resource has finished parsing. Here
358 // document element refers to DOMDocument, which is different from browser
359 // implementation of blink::Document in DocumentUserData/DocumentService which
360 // are typically created when navigation commits.
361 //
Sreeja Kamishetty49783302022-01-28 17:52:25362 // Note that PrimaryMainDocumentElementAvailable should be used when the
363 // observers which send IPCs to the renderer want to ensure that
364 // window.document is non-null. For for the comment cases like observing
365 // primary document/URL changes in the omnibox due to navigation
Sreeja Kamishetty9bc31e2c2022-01-11 05:48:46366 // WebContentsObserver::PrimaryPageChanged should be used and to observe fully
367 // loaded signal WebContentsObserver::DidFinishLoad can be used.
368 //
369 // This event is dispatched once in the document's lifetime, which means it's
370 // not dispatched after navigation that restores a Back/Forward Cache page.
371 // For prerendering, this signal is dispatched when the main document element
372 // is available and the document is shown to the user (i.e., after the
373 // activation).
Sreeja Kamishetty49783302022-01-28 17:52:25374 virtual void PrimaryMainDocumentElementAvailable() {}
clamyb876f0a72015-09-24 20:01:05375
Sreeja Kamishetty6b55ecc2021-12-10 11:28:17376 // This method is invoked once the onload handler of the primary main frame's
377 // current document (i.e., |render_frame_host|) has completed. This happens
378 // when the primary main document has finished running onload events after
379 // loading all content (images, scripts, etc). Prefer using
Sreeja Kamishetty81347582022-01-06 12:46:33380 // WebContents::IsDocumentOnLoadCompletedInPrimaryMainFrame instead of saving
381 // this state in your component.
Sreeja Kamishetty6b55ecc2021-12-10 11:28:17382 //
Sreeja Kamishetty81347582022-01-06 12:46:33383 // For prerendering we dispatch DocumentOnLoadCompletedInPrimaryMainFrame on
Sreeja Kamishetty6b55ecc2021-12-10 11:28:17384 // activation whereas for BackForwardCache restores we don't dispatch
Sreeja Kamishetty81347582022-01-06 12:46:33385 // DocumentOnLoadCompletedInPrimaryMainFrame.
Sreeja Kamishetty6b55ecc2021-12-10 11:28:17386 //
Sreeja Kamishetty81347582022-01-06 12:46:33387 // DocumentOnLoadCompletedInPrimaryMainFrame is typically used by the
388 // embedders to perform actions on a loaded page, for example showing load
389 // completion bubbles, injecting scripts which take page snapshots. Note,
390 // however, that some web pages might still be loading (i.e. if they
391 // dynamically inject content).
392 virtual void DocumentOnLoadCompletedInPrimaryMainFrame() {}
clamyb876f0a72015-09-24 20:01:05393
Ewelina Baraned2df8ad2021-12-22 10:05:37394 // This method is invoked when we have received a response from the
395 // renderer in response to a dom automation controller action.
396 // For example, `window.domAutomationController.send(foo())` sends the
397 // result of foo() here.
398 // |json_string| is a string with the response which came from a specific
399 // |render_frame_host|.
400 virtual void DomOperationResponse(RenderFrameHost* render_frame_host,
401 const std::string& json_string) {}
402
clamyb876f0a72015-09-24 20:01:05403 // This method is invoked when the document in the given frame finished
404 // loading. At this point, scripts marked as defer were executed, and
405 // content scripts marked "document_end" get injected into the frame.
Kouhei Uenof6e96242019-09-27 01:54:35406 virtual void DOMContentLoaded(RenderFrameHost* render_frame_host) {}
clamyb876f0a72015-09-24 20:01:05407
aviee9b7372016-06-28 20:34:43408 // This method is invoked when the load is done, i.e. the spinner of the tab
409 // will stop spinning, and the onload event was dispatched.
clamyb876f0a72015-09-24 20:01:05410 //
411 // If the WebContents is displaying replacement content, e.g. network error
412 // pages, DidFinishLoad is invoked for frames that were not sending
413 // navigational events before. It is safe to ignore these events.
414 virtual void DidFinishLoad(RenderFrameHost* render_frame_host,
415 const GURL& validated_url) {}
416
417 // This method is like DidFinishLoad, but when the load failed or was
418 // cancelled, e.g. window.stop() is invoked.
419 virtual void DidFailLoad(RenderFrameHost* render_frame_host,
420 const GURL& validated_url,
Dave Tapuska924ef3c2020-01-22 18:20:59421 int error_code) {}
clamyb876f0a72015-09-24 20:01:05422
cjgrant6d1d727a2016-12-09 21:16:57423 // This method is invoked when the visible security state of the page changes.
424 virtual void DidChangeVisibleSecurityState() {}
lgarron662dd522015-06-08 23:20:01425
[email protected]b0f724c2013-09-05 04:21:13426 // This method is invoked when content was loaded from an in-memory cache.
427 virtual void DidLoadResourceFromMemoryCache(
Lucas Furukawa Gadani07b45e152021-04-14 00:56:44428 RenderFrameHost* render_frame_host,
jam91dd24e2016-08-12 17:16:42429 const GURL& url,
430 const std::string& mime_type,
Kinuko Yasuda433f710a2020-02-14 02:11:58431 network::mojom::RequestDestination request_destination) {}
[email protected]b0f724c2013-09-05 04:21:13432
Jay Civelli718fd6c02018-05-11 21:04:27433 // This method is invoked when a resource associate with the frame
Clark DuVall36164bd2018-08-09 22:49:08434 // |render_frame_host| has been loaded, successfully or not. |request_id| will
435 // only be populated for main frame resources.
Jay Civelli116683f2018-03-27 19:56:23436 virtual void ResourceLoadComplete(
Jay Civelli718fd6c02018-05-11 21:04:27437 RenderFrameHost* render_frame_host,
Clark DuVall36164bd2018-08-09 22:49:08438 const GlobalRequestID& request_id,
Minggang Wangee5af392020-02-05 02:55:28439 const blink::mojom::ResourceLoadInfo& resource_load_info) {}
[email protected]b0f724c2013-09-05 04:21:13440
Alexander Timin1cc31f42020-05-12 16:26:01441 // Called when document reads or sets a cookie (either via document.cookie or
442 // issuing a network request).
443 // Cookie reads/writes for a dedicated worker are attributed to the
444 // RenderFrameHost which created it.
445 virtual void OnCookiesAccessed(RenderFrameHost* render_frame_host,
446 const CookieAccessDetails& details) {}
447
448 // Called when a network request issued by the navigation reads or sets a
449 // cookie. If a notification is received after the navigation has committed,
450 // it will be attributed to the RenderFrameHost created by the navigation.
451 virtual void OnCookiesAccessed(NavigationHandle* navigation_handle,
452 const CookieAccessDetails& details) {}
Josh Karlindaba39322019-07-17 23:24:33453
[email protected]cbb1ef592013-06-05 19:49:46454 // This method is invoked when a new non-pending navigation entry is created.
455 // This corresponds to one NavigationController entry being created
456 // (in the case of new navigations) or renavigated to (for back/forward
457 // navigations).
Yoshisato Yanagisawa84141482021-11-24 23:46:42458 //
459 // Note that this function is only dispatched for NavigationEntries of primary
460 // pages (e.g. not for prerendered pages or fenced frames).
[email protected]cbb1ef592013-06-05 19:49:46461 virtual void NavigationEntryCommitted(
462 const LoadCommittedDetails& load_details) {}
463
Sam McNally5c087a32017-08-25 01:46:14464 // Invoked when the NavigationController decreased its back/forward list count
465 // by removing entries from either the front or back of its list. This is
466 // usually the result of going back and then doing a new navigation, meaning
467 // all the "forward" items are deleted.
468 //
469 // This normally happens as a result of a new navigation. It will be
470 // followed by a NavigationEntryCommitted() call for the new page that
471 // caused the pruning. It could also be a result of removing an item from
Christian Dullweberb13ffda2018-02-23 11:42:14472 // the list to delete history or fix up after interstitials.
Sam McNally5c087a32017-08-25 01:46:14473 virtual void NavigationListPruned(const PrunedDetails& pruned_details) {}
474
Christian Dullweber1af31e62018-02-22 11:49:48475 // Invoked when NavigationEntries have been deleted because of a history
476 // deletion. Observers should ensure that they remove all traces of the
477 // deleted entries.
478 virtual void NavigationEntriesDeleted() {}
479
Sam McNally5c087a32017-08-25 01:46:14480 // Invoked when a NavigationEntry has changed.
481 //
482 // This will NOT be sent on navigation, interested parties should also
483 // implement NavigationEntryCommitted() to handle that case. This will be
484 // sent when the entry is updated outside of navigation (like when a new
485 // title comes).
486 virtual void NavigationEntryChanged(
487 const EntryChangedDetails& change_details) {}
488
[email protected]87eca182013-01-31 21:20:00489 // This method is invoked when a new WebContents was created in response to
490 // an action in the observed WebContents, e.g. a link with target=_blank was
creis114ca1b2014-11-13 23:51:46491 // clicked. The |source_render_frame_host| is the frame in which the action
492 // took place.
[email protected]26b5e322011-12-23 01:36:47493 virtual void DidOpenRequestedURL(WebContents* new_contents,
creis114ca1b2014-11-13 23:51:46494 RenderFrameHost* source_render_frame_host,
[email protected]d8c660432011-12-22 20:51:25495 const GURL& url,
496 const Referrer& referrer,
497 WindowOpenDisposition disposition,
pnoland488944652017-02-22 18:58:54498 ui::PageTransition transition,
pnolandaae574e2017-03-06 21:04:21499 bool started_from_context_menu,
500 bool renderer_initiated) {}
[email protected]d8c660432011-12-22 20:51:25501
nasko005282522015-01-22 02:30:02502 // This method is invoked when the renderer process has completed its first
503 // paint after a non-empty layout.
[email protected]50279492014-05-05 23:24:29504 virtual void DidFirstVisuallyNonEmptyPaint() {}
[email protected]9f268072013-11-07 00:02:15505
[email protected]d16609c2013-08-23 06:01:40506 // When WebContents::Stop() is called, the WebContents stops loading and then
507 // invokes this method. If there are ongoing navigations, their respective
508 // failure methods will also be invoked.
509 virtual void NavigationStopped() {}
[email protected]87eca182013-01-31 21:20:00510
dominickn2dd142dd2015-10-29 05:30:50511 // Called when there has been direct user interaction with the WebContents.
Emily Starkc7bd40c42020-07-21 19:12:55512 // The type of the event specifies the kind of interaction. Direct user input
dominicknad9c99d2015-11-06 01:52:49513 // signalled through this callback includes:
514 // 1) any mouse down event (blink::WebInputEvent::MouseDown);
dominickn5cc29a42016-03-25 03:06:22515 // 2) the start of a scroll (blink::WebInputEvent::GestureScrollBegin);
Dominick Ng37a15052018-07-17 23:56:35516 // 3) any raw key down event (blink::WebInputEvent::RawKeyDown); and
517 // 4) any touch event (inc. scrolls) (blink::WebInputEvent::TouchStart).
Emily Starkc7bd40c42020-07-21 19:12:55518 virtual void DidGetUserInteraction(const blink::WebInputEvent& event) {}
dominickn2dd142dd2015-10-29 05:30:50519
[email protected]87eca182013-01-31 21:20:00520 // This method is invoked when a RenderViewHost of this WebContents was
521 // configured to ignore UI events, and an UI event took place.
522 virtual void DidGetIgnoredUIEvent() {}
523
Francois Dorayfe4a1772018-02-17 04:17:09524 // Invoked every time the WebContents changes visibility.
525 virtual void OnVisibilityChanged(Visibility visibility) {}
[email protected]3e324142012-06-25 18:26:33526
Dave Tapuska1ca6d5f2021-10-13 22:40:03527 // Invoked when the primary main frame changes size.
528 virtual void PrimaryMainFrameWasResized(bool width_changed) {}
estaded0a0c992015-01-21 14:12:06529
alexmosbe2f4c32015-03-10 02:30:23530 // Invoked when the given frame changes its window.name property.
531 virtual void FrameNameChanged(RenderFrameHost* render_frame_host,
532 const std::string& name) {}
533
Michael Bai19f17a302021-12-08 04:08:33534 // Invoked when the color scheme of the primary main document of the
535 // WebContents is updated (either because the primary main document's color
536 // has been inferred or the primary main document has changed).
537 virtual void InferredColorSchemeUpdated(
538 absl::optional<blink::mojom::PreferredColorScheme> color_scheme) {}
539
John Delaneyb625dca92021-04-14 17:00:34540 // Called when a frame receives user activation. This may be called multiple
541 // times for the same frame. This should not be used to determine a
542 // RenderFrameHost's user activation state. Does not include frames activated
543 // by the same-origin visibility heuristic, see `UserActivationState` for
544 // details.
545 virtual void FrameReceivedUserActivation(RenderFrameHost* render_frame_host) {
546 }
John Delaneyedd8d6c2019-01-25 00:23:57547
John Delaney0146a742019-01-25 19:25:28548 // Invoked when the display state of the frame changes.
549 virtual void FrameDisplayStateChanged(RenderFrameHost* render_frame_host,
550 bool is_display_none) {}
551
552 // Invoked when a frame changes size.
553 virtual void FrameSizeChanged(RenderFrameHost* render_frame_host,
554 const gfx::Size& frame_size) {}
555
Avi Drissmana2ca5b142017-11-14 21:10:47556 // This method is invoked when the title of the WebContents is set. Note that
557 // |entry| may be null if the web page whose title changed has not yet had a
558 // NavigationEntry assigned to it.
Avi Drissman93002212017-09-27 03:20:52559 virtual void TitleWasSet(NavigationEntry* entry) {}
[email protected]66798902013-10-01 18:40:16560
emaxxe70f5e12015-05-29 11:26:00561 // These methods are invoked when a Pepper plugin instance is created/deleted
562 // in the DOM.
563 virtual void PepperInstanceCreated() {}
564 virtual void PepperInstanceDeleted() {}
565
Becca Hughes6fe54e432018-06-09 04:18:56566 // This method is called when the viewport fit of a WebContents changes.
567 virtual void ViewportFitChanged(blink::mojom::ViewportFit value) {}
568
[email protected]3fc07c52012-04-20 00:27:44569 // Notification that a plugin has crashed.
[email protected]cf4d6e742013-01-10 14:06:42570 // |plugin_pid| is the process ID identifying the plugin process. Note that
nasko005282522015-01-22 02:30:02571 // this ID is supplied by the renderer process, so should not be trusted.
572 // Besides, the corresponding process has probably died at this point. The ID
573 // may even have been reused by a new process.
[email protected]c42de732013-02-16 06:26:31574 virtual void PluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:42575 base::ProcessId plugin_pid) {}
[email protected]3fc07c52012-04-20 00:27:44576
[email protected]d16609c2013-08-23 06:01:40577 // Notification that the given plugin has hung or become unhung. This
[email protected]3fc07c52012-04-20 00:27:44578 // notification is only for Pepper plugins.
579 //
580 // The plugin_child_id is the unique child process ID from the plugin. Note
nasko005282522015-01-22 02:30:02581 // that this ID is supplied by the renderer process, so should be validated
582 // before it's used for anything in case there's an exploited renderer
583 // process.
[email protected]3fc07c52012-04-20 00:27:44584 virtual void PluginHungStatusChanged(int plugin_child_id,
[email protected]c42de732013-02-16 06:26:31585 const base::FilePath& plugin_path,
[email protected]3fc07c52012-04-20 00:27:44586 bool is_hung) {}
587
Sean Toppingbbc4a2bd2019-01-30 02:16:14588 // Notifies that an inner WebContents instance has been created with the
589 // observed WebContents as its container. |inner_web_contents| has not been
590 // added to the WebContents tree at this point, but can be observed safely.
591 virtual void InnerWebContentsCreated(WebContents* inner_web_contents) {}
592
Chris Hamilton16b5d1d2020-06-04 00:08:12593 // Notifies that an |inner_web_contents| instance has been attached to the
594 // provided |render_frame_host|. By the time this is called the
595 // |inner_web_contents| will have been added to the WebContents tree.
596 virtual void InnerWebContentsAttached(WebContents* inner_web_contents,
597 RenderFrameHost* render_frame_host,
598 bool is_full_page) {}
599
600 // Notifies that an |inner_web_contents| instance has been detached from this
601 // WebContents. InnerWebContentsAttached() will already have been called for
602 // the |inner_web_contents|. By the time this is called the
603 // |inner_web_contents| will have been removed from the WebContents tree, but
604 // will still be alive and is safe to observe.
605 virtual void InnerWebContentsDetached(WebContents* inner_web_contents) {}
606
[email protected]7381d9f2012-09-12 20:26:22607 // Invoked when WebContents::Clone() was used to clone a WebContents.
608 virtual void DidCloneToNewWebContents(WebContents* old_web_contents,
609 WebContents* new_web_contents) {}
610
[email protected]26b5e322011-12-23 01:36:47611 // Invoked when the WebContents is being destroyed. Gives subclasses a chance
[email protected]12a46832014-05-09 13:35:58612 // to cleanup. After the whole loop over all WebContentsObservers has been
mlamouri8c61ffc2015-01-13 16:17:59613 // finished, web_contents() returns nullptr.
[email protected]12a46832014-05-09 13:35:58614 virtual void WebContentsDestroyed() {}
[email protected]d8c660432011-12-22 20:51:25615
[email protected]8d0f3312012-08-18 01:47:53616 // Called when the user agent override for a WebContents has been changed.
Maks Orlovich73f374d2020-04-02 12:46:13617 virtual void UserAgentOverrideSet(
618 const blink::UserAgentOverride& ua_override) {}
[email protected]8d0f3312012-08-18 01:47:53619
Miyoung Shin5709ab02020-02-19 06:50:41620 // Invoked when new blink::mojom::FaviconURLPtr candidates are received from
621 // the renderer process. If the instance is created after the page is loaded,
622 // it is recommended to call WebContents::GetFaviconURLs() to get the current
623 // list as this callback will not be executed unless there is an update.
Sreeja Kamishettycfb4b862022-03-29 16:59:39624 // `render_frame_host` is the main RenderFrameHost for the primary page.
Miyoung Shin5709ab02020-02-19 06:50:41625 virtual void DidUpdateFaviconURL(
Yuzu Saijo0c263c702020-06-08 03:41:24626 RenderFrameHost* render_frame_host,
Miyoung Shin5709ab02020-02-19 06:50:41627 const std::vector<blink::mojom::FaviconURLPtr>& candidates) {}
[email protected]795c28972012-12-06 06:13:39628
Chris Hamilton16ca64a2020-05-14 23:13:17629 // Called when an audio change occurs to this WebContents. If |audible| is
630 // true then one or more frames or child contents are emitting audio; if
631 // false, then no frames or child contents are emitting audio. See
632 // OnFrameAudioStateChanged for per-frame information.
Chris Hamiltoneb41198f2018-05-24 18:41:26633 virtual void OnAudioStateChanged(bool audible) {}
634
Chris Hamilton16ca64a2020-05-14 23:13:17635 // Called when the audio state of an individual frame changes.
636 virtual void OnFrameAudioStateChanged(RenderFrameHost* rfh, bool audible) {}
637
Francois Doray66766a572019-12-17 20:56:49638 // Called when the connected to Bluetooth device state changes.
639 virtual void OnIsConnectedToBluetoothDeviceChanged(
640 bool is_connected_to_bluetooth_device) {}
641
wjmaclean2f797c782016-01-07 14:52:03642 // Invoked when the WebContents is muted/unmuted.
643 virtual void DidUpdateAudioMutingState(bool muted) {}
644
nasko005282522015-01-22 02:30:02645 // Invoked when the renderer process has toggled the tab into/out of
646 // fullscreen mode.
bokanece34a82016-01-28 19:49:46647 virtual void DidToggleFullscreenModeForTab(bool entered_fullscreen,
648 bool will_cause_resize) {}
[email protected]657c8e02014-03-19 19:18:37649
Becca Hughesfd5d8f892018-06-14 18:23:36650 // Signals that |rfh| has the current fullscreen element. This is invoked
651 // when:
652 // 1) an element in this frame enters fullscreen or in nested fullscreen, or
653 // 2) after an element in a descendant frame exits fullscreen and makes
654 // this frame own the current fullscreen element again.
655 virtual void DidAcquireFullscreen(RenderFrameHost* rfh) {}
656
David Black9cca3592019-11-06 23:02:22657 // Invoked when the vertical scroll direction of the root layer is changed.
658 // Note that if a scroll in a given direction occurs, the scroll is completed,
659 // and then another scroll in the *same* direction occurs, we will not
660 // consider the second scroll event to have caused a change in direction. Also
661 // note that this API will *never* be called with |kNull| which only exists to
662 // indicate the absence of a vertical scroll direction.
663 virtual void DidChangeVerticalScrollDirection(
664 viz::VerticalScrollDirection scroll_direction) {}
665
[email protected]17e286e2013-03-01 23:29:39666 // Invoked before a form repost warning is shown.
667 virtual void BeforeFormRepostWarningShow() {}
668
Chris Hamilton3b3e315d2018-09-19 13:16:21669 // Invoked when the beforeunload handler fires. |proceed| is set to true if
670 // the beforeunload can safely proceed, otherwise it should be interrupted.
671 // The time is from the renderer process.
672 virtual void BeforeUnloadFired(bool proceed,
673 const base::TimeTicks& proceed_time) {}
[email protected]6d65a462013-06-21 21:29:12674
675 // Invoked when a user cancels a before unload dialog.
676 virtual void BeforeUnloadDialogCancelled() {}
677
Mario Sanchez Prada5d7f1ac2020-07-16 17:18:40678 // Called whenever the AXTreeID for the main frame has changed.
679 virtual void AXTreeIDForMainFrameHasChanged() {}
680
dmazzonidd3d51a72016-12-14 18:41:01681 // Called when accessibility events or location changes are received
682 // from a render frame, but only when the accessibility mode has the
Doug Turner63f3c7b2017-07-29 05:10:01683 // ui::AXMode::kWebContents flag set.
Dominic Mazzonia7b0edb22017-08-09 16:32:51684 virtual void AccessibilityEventReceived(
Dominic Mazzoniccbaa9b2018-06-06 07:44:23685 const AXEventNotificationDetails& details) {}
dmazzoni2400c462016-08-23 15:07:13686 virtual void AccessibilityLocationChangesReceived(
687 const std::vector<AXLocationChangeNotificationDetails>& details) {}
688
Peter Kastingb14e5782020-01-06 23:55:04689 // Invoked when theme color is changed.
690 virtual void DidChangeThemeColor() {}
[email protected]e7104762014-06-20 19:17:25691
Alan Cutterd73a15d92020-08-21 07:12:45692 // Invoked when background color is changed.
693 virtual void OnBackgroundColorChanged() {}
694
Tom Lukaszewicz22b784a42021-11-29 22:56:49695 // Invoked when the ColorProvider instance associated with this WebContents
696 // has changed.
697 virtual void OnColorProviderChanged() {}
698
Devlin Cronin5ea668f32019-12-18 21:57:58699 // Called when a message is added to the console of the WebContents. This is
700 // invoked before forwarding the message to the WebContents' delegate.
Ian Barkley-Yeung07d8a262020-11-19 22:45:35701 // |source_id| is a URL. |untrusted_stack_trace| is not present for most
702 // messages; only when requested in advance and only for exceptions.
Devlin Cronin5ea668f32019-12-18 21:57:58703 virtual void OnDidAddMessageToConsole(
Ian Barkley-Yeungaddf0922020-11-04 19:44:56704 RenderFrameHost* source_frame,
Devlin Cronin5ea668f32019-12-18 21:57:58705 blink::mojom::ConsoleMessageLevel log_level,
Jan Wilken Dörrieaace0cfef2021-03-11 22:01:58706 const std::u16string& message,
Devlin Cronin5ea668f32019-12-18 21:57:58707 int32_t line_no,
Jan Wilken Dörrieaace0cfef2021-03-11 22:01:58708 const std::u16string& source_id,
Anton Bikineevf62d1bf2021-05-15 17:56:07709 const absl::optional<std::u16string>& untrusted_stack_trace) {}
Devlin Cronin5ea668f32019-12-18 21:57:58710
dalecurtis88c240072015-12-09 02:11:18711 // Invoked when media is playing or paused. |id| is unique per player and per
712 // RenderFrameHost. There may be multiple players within a RenderFrameHost
713 // and subsequently within a WebContents. MediaStartedPlaying() will always
714 // be followed by MediaStoppedPlaying() after player teardown. Observers must
715 // release all stored copies of |id| when MediaStoppedPlaying() is received.
Mounir Lamouri366dd8472018-06-19 17:20:04716 // |has_video| and |has_audio| can both be false in cases where the media
717 // is playing muted and should be considered as inaudible for all intent and
718 // purposes.
billorr21c005d2016-11-17 03:57:04719 struct MediaPlayerInfo {
Becca Hughes3f921362017-06-08 14:08:36720 MediaPlayerInfo(bool has_video, bool has_audio)
721 : has_video(has_video), has_audio(has_audio) {}
billorr21c005d2016-11-17 03:57:04722 bool has_video;
Becca Hughes3f921362017-06-08 14:08:36723 bool has_audio;
billorr21c005d2016-11-17 03:57:04724 };
François Beaufortddaf8a82018-07-16 16:43:12725
billorr21c005d2016-11-17 03:57:04726 virtual void MediaStartedPlaying(const MediaPlayerInfo& video_type,
727 const MediaPlayerId& id) {}
Becca Hughes220bfc102017-11-14 18:24:07728 enum class MediaStoppedReason {
729 // The media was stopped for an unspecified reason.
730 kUnspecified,
731
732 // The media was stopped because it reached the end of the stream.
733 kReachedEndOfStream,
734 };
735 virtual void MediaStoppedPlaying(
736 const MediaPlayerInfo& video_type,
737 const MediaPlayerId& id,
738 WebContentsObserver::MediaStoppedReason reason) {}
peconn257951522017-06-09 18:24:59739 virtual void MediaResized(const gfx::Size& size, const MediaPlayerId& id) {}
Peter E Conneccb34c22017-09-08 09:37:58740 // Invoked when media enters or exits fullscreen. We must use a heuristic
741 // to determine this as it is not trivial for media with custom controls.
742 // There is a slight delay between media entering or exiting fullscreen
743 // and it being detected.
744 virtual void MediaEffectivelyFullscreenChanged(bool is_fullscreen) {}
François Beauforta2f0a3ca2018-08-28 12:46:11745 virtual void MediaPictureInPictureChanged(bool is_picture_in_picture) {}
Becca Hughes9f6fd4b82017-06-15 10:01:40746 virtual void MediaMutedStatusChanged(const MediaPlayerId& id, bool muted) {}
Chris Hamiltonc347e102020-11-18 23:10:21747 virtual void MediaDestroyed(const MediaPlayerId& id) {}
prashantv0c9b968d22015-03-26 00:58:54748
mcnee432e47d2015-11-09 19:37:46749 // Invoked when the renderer process changes the page scale factor.
750 virtual void OnPageScaleFactorChanged(float page_scale_factor) {}
751
Archana Simhaf67090c2019-05-06 23:43:23752 // Invoked when a paste event occurs.
753 virtual void OnPaste() {}
754
[email protected]64ffefa2014-05-10 12:06:33755 // Invoked if an IPC message is coming from a specific RenderFrameHost.
756 virtual bool OnMessageReceived(const IPC::Message& message,
757 RenderFrameHost* render_frame_host);
758
Michael Thiessen896405db2017-07-20 17:52:32759 // Notification that the |render_widget_host| for this WebContents has gained
760 // focus.
761 virtual void OnWebContentsFocused(RenderWidgetHost* render_widget_host) {}
calamity7fe55ce2015-04-10 03:59:37762
Michael Thiessen896405db2017-07-20 17:52:32763 // Notification that the |render_widget_host| for this WebContents has lost
764 // focus.
765 virtual void OnWebContentsLostFocus(RenderWidgetHost* render_widget_host) {}
zijiehe3bee08e22017-05-17 04:14:46766
Jeff Fisher709b4c52019-07-29 20:07:34767 // Notification that a RenderFrameHost inside this WebContents has updated
768 // its focused element. |details| contains information on the element
769 // that has received focus. This allows for observing focus changes
770 // within WebContents, as opposed to OnWebContentsFocused/LostFocus
771 // which allows observation that the RenderWidgetHost for the
772 // WebContents has gained/lost focus.
773 virtual void OnFocusChangedInPage(FocusedNodeDetails* details) {}
774
Sam McNally145fb172017-05-10 00:13:23775 // Notifies that the manifest URL for the main frame changed to
776 // |manifest_url|. This will be invoked when a document with a manifest loads
777 // or when the manifest URL changes (possibly to nothing). It is not invoked
778 // when a document with no manifest loads. During document load, if the
779 // document has both a manifest and a favicon, DidUpdateWebManifestURL() will
Sreeja Kamishettycfb4b862022-03-29 16:59:39780 // be invoked before DidUpdateFaviconURL(). `target_frame` is the main render
781 // frame host for the primary page.
Julie Jeongeun Kimd74c1e7f2021-06-18 04:06:18782 virtual void DidUpdateWebManifestURL(RenderFrameHost* target_frame,
783 const GURL& manifest_url) {}
Sam McNally145fb172017-05-10 00:13:23784
Raymond Toye413650c2018-08-31 00:12:47785 // Called when "audible" playback starts or stops on a WebAudio AudioContext.
786 using AudioContextId = std::pair<RenderFrameHost*, int>;
787 virtual void AudioContextPlaybackStarted(
788 const AudioContextId& audio_context_id) {}
789 virtual void AudioContextPlaybackStopped(
790 const AudioContextId& audio_context_id) {}
791
Alexander Timin17edc742020-04-23 18:22:18792 // Called when the RenderFrameHost tries to use a ServiceWorker
793 // (e.g. via navigation.serviceWorker API).
794 virtual void OnServiceWorkerAccessed(RenderFrameHost* render_frame_host,
795 const GURL& scope,
796 AllowServiceWorkerResult allowed) {}
797 // Called when the NavigationHandle accesses ServiceWorker to see if the
798 // network request should be handled by the ServiceWorker instead
799 // (e.g. for navigations to URLs which are in scope of a ServiceWorker).
800 virtual void OnServiceWorkerAccessed(NavigationHandle* navigation_handle,
801 const GURL& scope,
802 AllowServiceWorkerResult allowed) {}
lucinka.brozkovac25f7fb92014-09-04 06:42:56803 WebContents* web_contents() const;
804
[email protected]d8c660432011-12-22 20:51:25805 protected:
[email protected]26b5e322011-12-23 01:36:47806 // Use this constructor when the object is tied to a single WebContents for
[email protected]d8c660432011-12-22 20:51:25807 // its entire lifetime.
[email protected]26b5e322011-12-23 01:36:47808 explicit WebContentsObserver(WebContents* web_contents);
[email protected]d8c660432011-12-22 20:51:25809
[email protected]b172aee2012-04-10 17:05:26810 // Use this constructor when the object wants to observe a WebContents for
[email protected]d8c660432011-12-22 20:51:25811 // part of its lifetime. It can then call Observe() to start and stop
812 // observing.
813 WebContentsObserver();
814
Dave Tapuska34310de2021-06-02 20:21:01815 virtual ~WebContentsObserver();
[email protected]d8c660432011-12-22 20:51:25816
[email protected]26b5e322011-12-23 01:36:47817 // Start observing a different WebContents; used with the default constructor.
818 void Observe(WebContents* web_contents);
[email protected]d8c660432011-12-22 20:51:25819
[email protected]d8c660432011-12-22 20:51:25820 private:
[email protected]8ff00d72012-10-23 19:12:21821 friend class WebContentsImpl;
[email protected]d8c660432011-12-22 20:51:25822
[email protected]12a46832014-05-09 13:35:58823 void ResetWebContents();
[email protected]d8c660432011-12-22 20:51:25824
Keishi Hattori0e45c022021-11-27 09:25:52825 raw_ptr<WebContents> web_contents_ = nullptr;
[email protected]d8c660432011-12-22 20:51:25826};
827
828} // namespace content
829
830#endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_