blob: da2c6572dd7e9bbd6f59b864edc73dae56ca2103 [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
10#include "base/macros.h"
zqzhang24ae1ae2016-09-08 11:37:1011#include "base/optional.h"
[email protected]c3c10f22013-07-25 14:21:1212#include "base/process/kill.h"
13#include "base/process/process_handle.h"
Alexander Timin17edc742020-04-23 18:22:1814#include "base/threading/thread_restrictions.h"
David Black9cca3592019-11-06 23:02:2215#include "components/viz/common/vertical_scroll_direction.h"
[email protected]d8c660432011-12-22 20:51:2516#include "content/common/content_export.h"
Alexander Timin17edc742020-04-23 18:22:1817#include "content/public/browser/allow_service_worker_result.h"
Alexander Timin9df1e3e2020-04-28 20:49:5618#include "content/public/browser/cookie_access_details.h"
[email protected]71fde352011-12-29 03:29:5619#include "content/public/browser/navigation_controller.h"
toyoshim0df1d3a2016-09-09 09:52:4820#include "content/public/browser/reload_type.h"
Francois Dorayfe4a1772018-02-17 04:17:0921#include "content/public/browser/visibility.h"
[email protected]37567b432014-02-12 01:12:2222#include "content/public/common/frame_navigate_params.h"
[email protected]c47317e2012-06-20 22:35:3123#include "ipc/ipc_listener.h"
Ben Goodger9e24929e2017-07-21 03:13:4024#include "mojo/public/cpp/system/message_pipe.h"
Kinuko Yasuda433f710a2020-02-14 02:11:5825#include "services/network/public/mojom/fetch_api.mojom-forward.h"
Ben Goodger9e24929e2017-07-21 03:13:4026#include "services/service_manager/public/cpp/bind_source_info.h"
Dave Tapuska129cef82019-12-19 16:36:4827#include "third_party/blink/public/common/input/web_input_event.h"
Maks Orlovich73f374d2020-04-02 12:46:1328#include "third_party/blink/public/common/user_agent/user_agent_metadata.h"
Miyoung Shin8f2e1832020-04-27 09:00:0229#include "third_party/blink/public/mojom/choosers/popup_menu.mojom.h"
Devlin Cronin5ea668f32019-12-18 21:57:5830#include "third_party/blink/public/mojom/devtools/console_message.mojom.h"
Minggang Wangee5af392020-02-05 02:55:2831#include "third_party/blink/public/mojom/loader/resource_load_info.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
Becca Hughes6fe54e432018-06-09 04:18:5636namespace blink {
37namespace mojom {
38enum class ViewportFit;
39} // namespace mojom
40} // namespace blink
41
peconn257951522017-06-09 18:24:5942namespace gfx {
43class Size;
44} // namespace gfx
45
[email protected]d8c660432011-12-22 20:51:2546namespace content {
47
[email protected]1ef02d242013-10-07 16:18:5348class NavigationEntry;
clamy0e119882015-07-31 16:12:3349class NavigationHandle;
[email protected]b849847b2013-12-10 21:57:5850class RenderFrameHost;
Avi Drissmanb3d355f2018-01-29 20:08:1851class RenderProcessHost;
[email protected]eaabba22012-03-07 15:02:1152class RenderViewHost;
afakhry98241832016-03-11 19:27:4753class RenderWidgetHost;
[email protected]26b5e322011-12-23 01:36:4754class WebContents;
[email protected]8ff00d72012-10-23 19:12:2155class WebContentsImpl;
[email protected]31a71eaf2014-03-13 01:47:3656struct AXEventNotificationDetails;
dmazzoni2400c462016-08-23 15:07:1357struct AXLocationChangeNotificationDetails;
Sam McNally5c087a32017-08-25 01:46:1458struct EntryChangedDetails;
Jeff Fisher709b4c52019-07-29 20:07:3459struct FocusedNodeDetails;
[email protected]71fde352011-12-29 03:29:5660struct LoadCommittedDetails;
Mounir Lamouri0f5bdf52019-04-04 16:32:3561struct MediaPlayerId;
Sam McNally5c087a32017-08-25 01:46:1462struct PrunedDetails;
[email protected]d8c660432011-12-22 20:51:2563struct Referrer;
[email protected]d8c660432011-12-22 20:51:2564
65// An observer API implemented by classes which are interested in various page
[email protected]b172aee2012-04-10 17:05:2666// load events from WebContents. They also get a chance to filter IPC messages.
[email protected]87eca182013-01-31 21:20:0067//
[email protected]d16609c2013-08-23 06:01:4068// Since a WebContents can be a delegate to almost arbitrarily many
[email protected]87eca182013-01-31 21:20:0069// RenderViewHosts, it is important to check in those WebContentsObserver
70// methods which take a RenderViewHost that the event came from the
71// RenderViewHost the observer cares about.
72//
73// Usually, observers should only care about the current RenderViewHost as
74// returned by GetRenderViewHost().
75//
76// TODO(creis, jochen): Hide the fact that there are several RenderViewHosts
77// from the WebContentsObserver API. http://crbug.com/173325
Lukasz Anforowiczf4357ca2017-09-07 01:43:3278class CONTENT_EXPORT WebContentsObserver : public IPC::Listener {
[email protected]d8c660432011-12-22 20:51:2579 public:
aviee9b7372016-06-28 20:34:4380 // Frames and Views ----------------------------------------------------------
81
nasko005282522015-01-22 02:30:0282 // Called when a RenderFrame for |render_frame_host| is created in the
Scott Violet507cbcb22020-05-21 17:24:2283 // renderer process. Use |RenderFrameDeleted| to listen for when this
84 // RenderFrame goes away.
[email protected]b849847b2013-12-10 21:57:5885 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) {}
86
nasko005282522015-01-22 02:30:0287 // Called when a RenderFrame for |render_frame_host| is deleted or the
88 // renderer process in which it runs it has died. Use |RenderFrameCreated| to
89 // listen for when RenderFrame objects are created.
[email protected]b849847b2013-12-10 21:57:5890 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) {}
91
nasko005282522015-01-22 02:30:0292 // This method is invoked whenever one of the current frames of a WebContents
93 // swaps its RenderFrameHost with another one; for example because that frame
94 // navigated and the new content is in a different process. The
95 // RenderFrameHost that has been replaced is in |old_host|, which can be
96 // nullptr if the old RenderFrameHost was shut down or a new frame has been
97 // created and no old RenderFrameHost exists.
98 //
99 // This method, in combination with |FrameDeleted|, is appropriate for
100 // observers wishing to track the set of current RenderFrameHosts -- i.e.,
Lei Zhangebcc6302018-01-12 19:46:45101 // those hosts that would be visited by calling WebContents::ForEachFrame().
nasko005282522015-01-22 02:30:02102 virtual void RenderFrameHostChanged(RenderFrameHost* old_host,
103 RenderFrameHost* new_host) {}
104
105 // This method is invoked when a subframe associated with a WebContents is
106 // deleted or the WebContents is destroyed and the top-level frame is deleted.
107 // Use |RenderFrameHostChanged| to listen for when a RenderFrameHost object is
108 // made the current host for a frame.
109 virtual void FrameDeleted(RenderFrameHost* render_frame_host) {}
110
[email protected]a86c0e962013-12-17 17:10:39111 // This is called when a RVH is created for a WebContents, but not if it's an
112 // interstitial.
[email protected]d8c660432011-12-22 20:51:25113 virtual void RenderViewCreated(RenderViewHost* render_view_host) {}
[email protected]a86c0e962013-12-17 17:10:39114
115 // Called for every RenderFrameHost that's created for an interstitial.
116 virtual void RenderFrameForInterstitialPageCreated(
117 RenderFrameHost* render_frame_host) {}
[email protected]87eca182013-01-31 21:20:00118
119 // This method is invoked when the RenderView of the current RenderViewHost
120 // is ready, e.g. because we recreated it after a crash.
[email protected]d8c660432011-12-22 20:51:25121 virtual void RenderViewReady() {}
[email protected]87eca182013-01-31 21:20:00122
123 // This method is invoked when a RenderViewHost of the WebContents is
124 // deleted. Note that this does not always happen when the WebContents starts
125 // to use a different RenderViewHost, as the old RenderViewHost might get
126 // just swapped out.
127 virtual void RenderViewDeleted(RenderViewHost* render_view_host) {}
128
avi33601202015-07-11 01:39:26129 // This method is invoked when the process for the current main
130 // RenderFrameHost exits (usually by crashing, though possibly by other
131 // means). The WebContents continues to use the RenderFrameHost, e.g. when the
132 // user reloads the current page. When the RenderFrameHost itself is deleted,
133 // the RenderFrameDeleted method will be invoked.
[email protected]4d614412014-01-10 08:29:37134 //
avi33601202015-07-11 01:39:26135 // Note that this is triggered upstream through
136 // RenderProcessHostObserver::RenderProcessExited(); for code that doesn't
137 // otherwise need to be a WebContentsObserver, that API is probably a better
138 // choice.
[email protected]58d5cfe2013-07-10 02:40:52139 virtual void RenderProcessGone(base::TerminationStatus status) {}
[email protected]87eca182013-01-31 21:20:00140
[email protected]02d7b6e2014-06-24 21:01:50141 // This method is invoked when a WebContents swaps its visible RenderViewHost
142 // with another one, possibly changing processes. The RenderViewHost that has
mlamouri8c61ffc2015-01-13 16:17:59143 // been replaced is in |old_host|, which is nullptr if the old RVH was shut
144 // down.
[email protected]7b712ee22013-10-03 00:57:28145 virtual void RenderViewHostChanged(RenderViewHost* old_host,
146 RenderViewHost* new_host) {}
[email protected]da7a7182013-09-06 08:11:11147
Avi Drissmanb3d355f2018-01-29 20:08:18148 // This method is invoked when a process in the WebContents becomes
149 // unresponsive.
150 virtual void OnRendererUnresponsive(RenderProcessHost* render_process_host) {}
afakhry98241832016-03-11 19:27:47151
Scott Violet48202e62020-05-26 17:19:33152 // See WebContentsDelegate::RendererResponsive().
153 virtual void OnRendererResponsive(RenderProcessHost* render_process_host) {}
154
aviee9b7372016-06-28 20:34:43155 // Navigation ----------------------------------------------------------------
clamy0e119882015-07-31 16:12:33156
157 // Called when a navigation started in the WebContents. |navigation_handle|
158 // is unique to a specific navigation. The same |navigation_handle| will be
nasko14baf392016-02-02 02:15:38159 // provided on subsequent calls to DidRedirectNavigation, DidFinishNavigation,
160 // and ReadyToCommitNavigation when related to this navigation. Observers
161 // should clear any references to |navigation_handle| in DidFinishNavigation,
162 // just before it is destroyed.
clamy0e119882015-07-31 16:12:33163 //
164 // Note that this is fired by navigations in any frame of the WebContents,
165 // not just the main frame.
166 //
eugenebuta11672fb2017-03-07 17:13:51167 // Note that this is fired by same-document navigations, such as fragment
clamy57f99bd22016-11-30 18:25:11168 // navigations or pushState/replaceState, which will not result in a document
eugenebuta11672fb2017-03-07 17:13:51169 // change. To filter these out, use NavigationHandle::IsSameDocument.
clamy57f99bd22016-11-30 18:25:11170 //
clamy0e119882015-07-31 16:12:33171 // Note that more than one navigation can be ongoing in the same frame at the
172 // same time (including the main frame). Each will get its own
173 // NavigationHandle.
174 //
175 // Note that there is no guarantee that DidFinishNavigation will be called
176 // for any particular navigation before DidStartNavigation is called on the
177 // next.
178 virtual void DidStartNavigation(NavigationHandle* navigation_handle) {}
179
180 // Called when a navigation encountered a server redirect.
181 virtual void DidRedirectNavigation(NavigationHandle* navigation_handle) {}
182
John Abd-El-Malekdf8e3da2019-10-30 00:57:37183 // Called when the navigation is ready to be committed in a renderer. This
184 // occurs when the response code isn't 204/205 (which tell the browser that
185 // the request is successful but there's no content that follows) or a
186 // download (either from a response header or based on mime sniffing the
187 // response). The browser then is ready to switch rendering the new document.
188 // Most observers should use DidFinishNavigation instead, which happens right
clamyb876f0a72015-09-24 20:01:05189 // after the navigation commits. This method is for observers that want to
190 // initialize renderer-side state just before the RenderFrame commits the
191 // navigation.
192 //
clamyb876f0a72015-09-24 20:01:05193 // This is the first point in time where a RenderFrameHost is associated with
194 // the navigation.
clamyefca29e2015-09-17 00:22:11195 virtual void ReadyToCommitNavigation(NavigationHandle* navigation_handle) {}
196
clamyb876f0a72015-09-24 20:01:05197 // Called when a navigation finished in the WebContents. This happens when a
198 // navigation is committed, aborted or replaced by a new one. To know if the
vabrd9092d32016-03-16 19:03:32199 // navigation has committed, use NavigationHandle::HasCommitted; use
clamyb876f0a72015-09-24 20:01:05200 // NavigationHandle::IsErrorPage to know if the navigation resulted in an
201 // error page.
202 //
203 // If this is called because the navigation committed, then the document load
204 // will still be ongoing in the RenderFrameHost returned by
205 // |navigation_handle|. Use the document loads events such as DidStopLoading
206 // and related methods to listen for continued events from this
207 // RenderFrameHost.
208 //
eugenebuta11672fb2017-03-07 17:13:51209 // Note that this is fired by same-document navigations, such as fragment
clamy57f99bd22016-11-30 18:25:11210 // navigations or pushState/replaceState, which will not result in a document
eugenebuta11672fb2017-03-07 17:13:51211 // change. To filter these out, use NavigationHandle::IsSameDocument.
clamy57f99bd22016-11-30 18:25:11212 //
clamyb876f0a72015-09-24 20:01:05213 // Note that |navigation_handle| will be destroyed at the end of this call,
214 // so do not keep a reference to it afterward.
clamy0e119882015-07-31 16:12:33215 virtual void DidFinishNavigation(NavigationHandle* navigation_handle) {}
216
Lucas Gadani972985622020-05-28 20:52:51217 // Called after the contents replaces the |predecessor_contents| in its
218 // container due to portal activation. The |predecessor_contents| is now a
219 // portal pending adoption. |predecessor_contents| is non-null, but may
220 // subsequently be destroyed if it is not adopted.
221 // |activation_time| is the time the activation happened.
222 virtual void DidActivatePortal(WebContents* predecessor_web_contents,
223 base::TimeTicks activation_time) {}
224
clamyb876f0a72015-09-24 20:01:05225 // Document load events ------------------------------------------------------
226
Chris Hamiltonf82f2a702018-02-15 19:37:29227 // These three methods correspond to the points in time when a document starts
228 // loading for the first time (initiates outgoing requests), when incoming
229 // data subsequently starts arriving, and when it finishes loading.
clamyb876f0a72015-09-24 20:01:05230 virtual void DidStartLoading() {}
Chris Hamiltonf82f2a702018-02-15 19:37:29231 virtual void DidReceiveResponse() {}
clamyb876f0a72015-09-24 20:01:05232 virtual void DidStopLoading() {}
233
Evan Stade9f328112019-10-23 20:49:25234 // The page has made some progress loading. |progress| is a value between 0.0
235 // (nothing loaded) to 1.0 (page fully loaded).
236 virtual void LoadProgressChanged(double progress) {}
237
clamyb876f0a72015-09-24 20:01:05238 // This method is invoked once the window.document object of the main frame
239 // was created.
240 virtual void DocumentAvailableInMainFrame() {}
241
242 // This method is invoked once the onload handler of the main frame has
243 // completed.
Alexander Timindd0fa0c52019-11-06 13:03:37244 // Prefer using WebContents::IsDocumentOnLoadCompletedInMainFrame instead
245 // of saving this state in your component.
clamyb876f0a72015-09-24 20:01:05246 virtual void DocumentOnLoadCompletedInMainFrame() {}
247
248 // This method is invoked when the document in the given frame finished
249 // loading. At this point, scripts marked as defer were executed, and
250 // content scripts marked "document_end" get injected into the frame.
Kouhei Uenof6e96242019-09-27 01:54:35251 virtual void DOMContentLoaded(RenderFrameHost* render_frame_host) {}
clamyb876f0a72015-09-24 20:01:05252
aviee9b7372016-06-28 20:34:43253 // This method is invoked when the load is done, i.e. the spinner of the tab
254 // will stop spinning, and the onload event was dispatched.
clamyb876f0a72015-09-24 20:01:05255 //
256 // If the WebContents is displaying replacement content, e.g. network error
257 // pages, DidFinishLoad is invoked for frames that were not sending
258 // navigational events before. It is safe to ignore these events.
259 virtual void DidFinishLoad(RenderFrameHost* render_frame_host,
260 const GURL& validated_url) {}
261
262 // This method is like DidFinishLoad, but when the load failed or was
263 // cancelled, e.g. window.stop() is invoked.
264 virtual void DidFailLoad(RenderFrameHost* render_frame_host,
265 const GURL& validated_url,
Dave Tapuska924ef3c2020-01-22 18:20:59266 int error_code) {}
clamyb876f0a72015-09-24 20:01:05267
cjgrant6d1d727a2016-12-09 21:16:57268 // This method is invoked when the visible security state of the page changes.
269 virtual void DidChangeVisibleSecurityState() {}
lgarron662dd522015-06-08 23:20:01270
[email protected]b0f724c2013-09-05 04:21:13271 // This method is invoked when content was loaded from an in-memory cache.
272 virtual void DidLoadResourceFromMemoryCache(
jam91dd24e2016-08-12 17:16:42273 const GURL& url,
274 const std::string& mime_type,
Kinuko Yasuda433f710a2020-02-14 02:11:58275 network::mojom::RequestDestination request_destination) {}
[email protected]b0f724c2013-09-05 04:21:13276
Jay Civelli718fd6c02018-05-11 21:04:27277 // This method is invoked when a resource associate with the frame
Clark DuVall36164bd2018-08-09 22:49:08278 // |render_frame_host| has been loaded, successfully or not. |request_id| will
279 // only be populated for main frame resources.
Jay Civelli116683f2018-03-27 19:56:23280 virtual void ResourceLoadComplete(
Jay Civelli718fd6c02018-05-11 21:04:27281 RenderFrameHost* render_frame_host,
Clark DuVall36164bd2018-08-09 22:49:08282 const GlobalRequestID& request_id,
Minggang Wangee5af392020-02-05 02:55:28283 const blink::mojom::ResourceLoadInfo& resource_load_info) {}
[email protected]b0f724c2013-09-05 04:21:13284
Alexander Timin1cc31f42020-05-12 16:26:01285 // Called when document reads or sets a cookie (either via document.cookie or
286 // issuing a network request).
287 // Cookie reads/writes for a dedicated worker are attributed to the
288 // RenderFrameHost which created it.
289 virtual void OnCookiesAccessed(RenderFrameHost* render_frame_host,
290 const CookieAccessDetails& details) {}
291
292 // Called when a network request issued by the navigation reads or sets a
293 // cookie. If a notification is received after the navigation has committed,
294 // it will be attributed to the RenderFrameHost created by the navigation.
295 virtual void OnCookiesAccessed(NavigationHandle* navigation_handle,
296 const CookieAccessDetails& details) {}
Josh Karlindaba39322019-07-17 23:24:33297
[email protected]cbb1ef592013-06-05 19:49:46298 // This method is invoked when a new non-pending navigation entry is created.
299 // This corresponds to one NavigationController entry being created
300 // (in the case of new navigations) or renavigated to (for back/forward
301 // navigations).
302 virtual void NavigationEntryCommitted(
303 const LoadCommittedDetails& load_details) {}
304
Sam McNally5c087a32017-08-25 01:46:14305 // Invoked when the NavigationController decreased its back/forward list count
306 // by removing entries from either the front or back of its list. This is
307 // usually the result of going back and then doing a new navigation, meaning
308 // all the "forward" items are deleted.
309 //
310 // This normally happens as a result of a new navigation. It will be
311 // followed by a NavigationEntryCommitted() call for the new page that
312 // caused the pruning. It could also be a result of removing an item from
Christian Dullweberb13ffda2018-02-23 11:42:14313 // the list to delete history or fix up after interstitials.
Sam McNally5c087a32017-08-25 01:46:14314 virtual void NavigationListPruned(const PrunedDetails& pruned_details) {}
315
Christian Dullweber1af31e62018-02-22 11:49:48316 // Invoked when NavigationEntries have been deleted because of a history
317 // deletion. Observers should ensure that they remove all traces of the
318 // deleted entries.
319 virtual void NavigationEntriesDeleted() {}
320
Sam McNally5c087a32017-08-25 01:46:14321 // Invoked when a NavigationEntry has changed.
322 //
323 // This will NOT be sent on navigation, interested parties should also
324 // implement NavigationEntryCommitted() to handle that case. This will be
325 // sent when the entry is updated outside of navigation (like when a new
326 // title comes).
327 virtual void NavigationEntryChanged(
328 const EntryChangedDetails& change_details) {}
329
[email protected]87eca182013-01-31 21:20:00330 // This method is invoked when a new WebContents was created in response to
331 // an action in the observed WebContents, e.g. a link with target=_blank was
creis114ca1b2014-11-13 23:51:46332 // clicked. The |source_render_frame_host| is the frame in which the action
333 // took place.
[email protected]26b5e322011-12-23 01:36:47334 virtual void DidOpenRequestedURL(WebContents* new_contents,
creis114ca1b2014-11-13 23:51:46335 RenderFrameHost* source_render_frame_host,
[email protected]d8c660432011-12-22 20:51:25336 const GURL& url,
337 const Referrer& referrer,
338 WindowOpenDisposition disposition,
pnoland488944652017-02-22 18:58:54339 ui::PageTransition transition,
pnolandaae574e2017-03-06 21:04:21340 bool started_from_context_menu,
341 bool renderer_initiated) {}
[email protected]d8c660432011-12-22 20:51:25342
nasko005282522015-01-22 02:30:02343 // This method is invoked when the renderer process has completed its first
344 // paint after a non-empty layout.
[email protected]50279492014-05-05 23:24:29345 virtual void DidFirstVisuallyNonEmptyPaint() {}
[email protected]9f268072013-11-07 00:02:15346
[email protected]d16609c2013-08-23 06:01:40347 // When WebContents::Stop() is called, the WebContents stops loading and then
348 // invokes this method. If there are ongoing navigations, their respective
349 // failure methods will also be invoked.
350 virtual void NavigationStopped() {}
[email protected]87eca182013-01-31 21:20:00351
dominickn2dd142dd2015-10-29 05:30:50352 // Called when there has been direct user interaction with the WebContents.
dominicknad9c99d2015-11-06 01:52:49353 // The type argument specifies the kind of interaction. Direct user input
354 // signalled through this callback includes:
355 // 1) any mouse down event (blink::WebInputEvent::MouseDown);
dominickn5cc29a42016-03-25 03:06:22356 // 2) the start of a scroll (blink::WebInputEvent::GestureScrollBegin);
Dominick Ng37a15052018-07-17 23:56:35357 // 3) any raw key down event (blink::WebInputEvent::RawKeyDown); and
358 // 4) any touch event (inc. scrolls) (blink::WebInputEvent::TouchStart).
dominickn2dd142dd2015-10-29 05:30:50359 virtual void DidGetUserInteraction(const blink::WebInputEvent::Type type) {}
360
[email protected]87eca182013-01-31 21:20:00361 // This method is invoked when a RenderViewHost of this WebContents was
362 // configured to ignore UI events, and an UI event took place.
363 virtual void DidGetIgnoredUIEvent() {}
364
Francois Dorayfe4a1772018-02-17 04:17:09365 // Invoked every time the WebContents changes visibility.
366 virtual void OnVisibilityChanged(Visibility visibility) {}
[email protected]3e324142012-06-25 18:26:33367
estaded0a0c992015-01-21 14:12:06368 // Invoked when the main frame changes size.
rouslan2f5993f2015-01-29 00:18:31369 virtual void MainFrameWasResized(bool width_changed) {}
estaded0a0c992015-01-21 14:12:06370
alexmosbe2f4c32015-03-10 02:30:23371 // Invoked when the given frame changes its window.name property.
372 virtual void FrameNameChanged(RenderFrameHost* render_frame_host,
373 const std::string& name) {}
374
John Delaneyedd8d6c2019-01-25 00:23:57375 // Called when the sticky user activation bit has been set on the frame.
376 // This will not be called for new RenderFrameHosts whose underlying
377 // FrameTreeNode was already activated. This should not be used to determine a
378 // RenderFrameHost's user activation state.
379 virtual void FrameReceivedFirstUserActivation(
380 RenderFrameHost* render_frame_host) {}
381
John Delaney0146a742019-01-25 19:25:28382 // Invoked when the display state of the frame changes.
383 virtual void FrameDisplayStateChanged(RenderFrameHost* render_frame_host,
384 bool is_display_none) {}
385
386 // Invoked when a frame changes size.
387 virtual void FrameSizeChanged(RenderFrameHost* render_frame_host,
388 const gfx::Size& frame_size) {}
389
Avi Drissmana2ca5b142017-11-14 21:10:47390 // This method is invoked when the title of the WebContents is set. Note that
391 // |entry| may be null if the web page whose title changed has not yet had a
392 // NavigationEntry assigned to it.
Avi Drissman93002212017-09-27 03:20:52393 virtual void TitleWasSet(NavigationEntry* entry) {}
[email protected]66798902013-10-01 18:40:16394
[email protected]d8c660432011-12-22 20:51:25395 virtual void AppCacheAccessed(const GURL& manifest_url,
396 bool blocked_by_policy) {}
397
emaxxe70f5e12015-05-29 11:26:00398 // These methods are invoked when a Pepper plugin instance is created/deleted
399 // in the DOM.
400 virtual void PepperInstanceCreated() {}
401 virtual void PepperInstanceDeleted() {}
402
Becca Hughes6fe54e432018-06-09 04:18:56403 // This method is called when the viewport fit of a WebContents changes.
404 virtual void ViewportFitChanged(blink::mojom::ViewportFit value) {}
405
[email protected]3fc07c52012-04-20 00:27:44406 // Notification that a plugin has crashed.
[email protected]cf4d6e742013-01-10 14:06:42407 // |plugin_pid| is the process ID identifying the plugin process. Note that
nasko005282522015-01-22 02:30:02408 // this ID is supplied by the renderer process, so should not be trusted.
409 // Besides, the corresponding process has probably died at this point. The ID
410 // may even have been reused by a new process.
[email protected]c42de732013-02-16 06:26:31411 virtual void PluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:42412 base::ProcessId plugin_pid) {}
[email protected]3fc07c52012-04-20 00:27:44413
[email protected]d16609c2013-08-23 06:01:40414 // Notification that the given plugin has hung or become unhung. This
[email protected]3fc07c52012-04-20 00:27:44415 // notification is only for Pepper plugins.
416 //
417 // The plugin_child_id is the unique child process ID from the plugin. Note
nasko005282522015-01-22 02:30:02418 // that this ID is supplied by the renderer process, so should be validated
419 // before it's used for anything in case there's an exploited renderer
420 // process.
[email protected]3fc07c52012-04-20 00:27:44421 virtual void PluginHungStatusChanged(int plugin_child_id,
[email protected]c42de732013-02-16 06:26:31422 const base::FilePath& plugin_path,
[email protected]3fc07c52012-04-20 00:27:44423 bool is_hung) {}
424
Sean Toppingbbc4a2bd2019-01-30 02:16:14425 // Notifies that an inner WebContents instance has been created with the
426 // observed WebContents as its container. |inner_web_contents| has not been
427 // added to the WebContents tree at this point, but can be observed safely.
428 virtual void InnerWebContentsCreated(WebContents* inner_web_contents) {}
429
[email protected]7381d9f2012-09-12 20:26:22430 // Invoked when WebContents::Clone() was used to clone a WebContents.
431 virtual void DidCloneToNewWebContents(WebContents* old_web_contents,
432 WebContents* new_web_contents) {}
433
[email protected]26b5e322011-12-23 01:36:47434 // Invoked when the WebContents is being destroyed. Gives subclasses a chance
[email protected]12a46832014-05-09 13:35:58435 // to cleanup. After the whole loop over all WebContentsObservers has been
mlamouri8c61ffc2015-01-13 16:17:59436 // finished, web_contents() returns nullptr.
[email protected]12a46832014-05-09 13:35:58437 virtual void WebContentsDestroyed() {}
[email protected]d8c660432011-12-22 20:51:25438
[email protected]8d0f3312012-08-18 01:47:53439 // Called when the user agent override for a WebContents has been changed.
Maks Orlovich73f374d2020-04-02 12:46:13440 virtual void UserAgentOverrideSet(
441 const blink::UserAgentOverride& ua_override) {}
[email protected]8d0f3312012-08-18 01:47:53442
Miyoung Shin5709ab02020-02-19 06:50:41443 // Invoked when new blink::mojom::FaviconURLPtr candidates are received from
444 // the renderer process. If the instance is created after the page is loaded,
445 // it is recommended to call WebContents::GetFaviconURLs() to get the current
446 // list as this callback will not be executed unless there is an update.
447 virtual void DidUpdateFaviconURL(
448 const std::vector<blink::mojom::FaviconURLPtr>& candidates) {}
[email protected]795c28972012-12-06 06:13:39449
Chris Hamilton16ca64a2020-05-14 23:13:17450 // Called when an audio change occurs to this WebContents. If |audible| is
451 // true then one or more frames or child contents are emitting audio; if
452 // false, then no frames or child contents are emitting audio. See
453 // OnFrameAudioStateChanged for per-frame information.
Chris Hamiltoneb41198f2018-05-24 18:41:26454 virtual void OnAudioStateChanged(bool audible) {}
455
Chris Hamilton16ca64a2020-05-14 23:13:17456 // Called when the audio state of an individual frame changes.
457 virtual void OnFrameAudioStateChanged(RenderFrameHost* rfh, bool audible) {}
458
Francois Doray66766a572019-12-17 20:56:49459 // Called when the connected to Bluetooth device state changes.
460 virtual void OnIsConnectedToBluetoothDeviceChanged(
461 bool is_connected_to_bluetooth_device) {}
462
wjmaclean2f797c782016-01-07 14:52:03463 // Invoked when the WebContents is muted/unmuted.
464 virtual void DidUpdateAudioMutingState(bool muted) {}
465
[email protected]44470a22013-01-24 01:21:54466 // Invoked when a pepper plugin creates and shows or destroys a fullscreen
nasko005282522015-01-22 02:30:02467 // RenderWidget.
alexmos899e06f2016-05-13 23:08:09468 virtual void DidShowFullscreenWidget() {}
469 virtual void DidDestroyFullscreenWidget() {}
[email protected]44470a22013-01-24 01:21:54470
nasko005282522015-01-22 02:30:02471 // Invoked when the renderer process has toggled the tab into/out of
472 // fullscreen mode.
bokanece34a82016-01-28 19:49:46473 virtual void DidToggleFullscreenModeForTab(bool entered_fullscreen,
474 bool will_cause_resize) {}
[email protected]657c8e02014-03-19 19:18:37475
Becca Hughesfd5d8f892018-06-14 18:23:36476 // Signals that |rfh| has the current fullscreen element. This is invoked
477 // when:
478 // 1) an element in this frame enters fullscreen or in nested fullscreen, or
479 // 2) after an element in a descendant frame exits fullscreen and makes
480 // this frame own the current fullscreen element again.
481 virtual void DidAcquireFullscreen(RenderFrameHost* rfh) {}
482
David Black9cca3592019-11-06 23:02:22483 // Invoked when the vertical scroll direction of the root layer is changed.
484 // Note that if a scroll in a given direction occurs, the scroll is completed,
485 // and then another scroll in the *same* direction occurs, we will not
486 // consider the second scroll event to have caused a change in direction. Also
487 // note that this API will *never* be called with |kNull| which only exists to
488 // indicate the absence of a vertical scroll direction.
489 virtual void DidChangeVerticalScrollDirection(
490 viz::VerticalScrollDirection scroll_direction) {}
491
[email protected]17e286e2013-03-01 23:29:39492 // Invoked before a form repost warning is shown.
493 virtual void BeforeFormRepostWarningShow() {}
494
Chris Hamilton3b3e315d2018-09-19 13:16:21495 // Invoked when the beforeunload handler fires. |proceed| is set to true if
496 // the beforeunload can safely proceed, otherwise it should be interrupted.
497 // The time is from the renderer process.
498 virtual void BeforeUnloadFired(bool proceed,
499 const base::TimeTicks& proceed_time) {}
[email protected]6d65a462013-06-21 21:29:12500
501 // Invoked when a user cancels a before unload dialog.
502 virtual void BeforeUnloadDialogCancelled() {}
503
dmazzonidd3d51a72016-12-14 18:41:01504 // Called when accessibility events or location changes are received
505 // from a render frame, but only when the accessibility mode has the
Doug Turner63f3c7b2017-07-29 05:10:01506 // ui::AXMode::kWebContents flag set.
Dominic Mazzonia7b0edb22017-08-09 16:32:51507 virtual void AccessibilityEventReceived(
Dominic Mazzoniccbaa9b2018-06-06 07:44:23508 const AXEventNotificationDetails& details) {}
dmazzoni2400c462016-08-23 15:07:13509 virtual void AccessibilityLocationChangesReceived(
510 const std::vector<AXLocationChangeNotificationDetails>& details) {}
511
Peter Kastingb14e5782020-01-06 23:55:04512 // Invoked when theme color is changed.
513 virtual void DidChangeThemeColor() {}
[email protected]e7104762014-06-20 19:17:25514
Devlin Cronin5ea668f32019-12-18 21:57:58515 // Called when a message is added to the console of the WebContents. This is
516 // invoked before forwarding the message to the WebContents' delegate.
517 virtual void OnDidAddMessageToConsole(
518 blink::mojom::ConsoleMessageLevel log_level,
519 const base::string16& message,
520 int32_t line_no,
521 const base::string16& source_id) {}
522
dalecurtis88c240072015-12-09 02:11:18523 // Invoked when media is playing or paused. |id| is unique per player and per
524 // RenderFrameHost. There may be multiple players within a RenderFrameHost
525 // and subsequently within a WebContents. MediaStartedPlaying() will always
526 // be followed by MediaStoppedPlaying() after player teardown. Observers must
527 // release all stored copies of |id| when MediaStoppedPlaying() is received.
Mounir Lamouri366dd8472018-06-19 17:20:04528 // |has_video| and |has_audio| can both be false in cases where the media
529 // is playing muted and should be considered as inaudible for all intent and
530 // purposes.
billorr21c005d2016-11-17 03:57:04531 struct MediaPlayerInfo {
Becca Hughes3f921362017-06-08 14:08:36532 MediaPlayerInfo(bool has_video, bool has_audio)
533 : has_video(has_video), has_audio(has_audio) {}
billorr21c005d2016-11-17 03:57:04534 bool has_video;
Becca Hughes3f921362017-06-08 14:08:36535 bool has_audio;
billorr21c005d2016-11-17 03:57:04536 };
François Beaufortddaf8a82018-07-16 16:43:12537
billorr21c005d2016-11-17 03:57:04538 virtual void MediaStartedPlaying(const MediaPlayerInfo& video_type,
539 const MediaPlayerId& id) {}
Becca Hughes220bfc102017-11-14 18:24:07540 enum class MediaStoppedReason {
541 // The media was stopped for an unspecified reason.
542 kUnspecified,
543
544 // The media was stopped because it reached the end of the stream.
545 kReachedEndOfStream,
546 };
547 virtual void MediaStoppedPlaying(
548 const MediaPlayerInfo& video_type,
549 const MediaPlayerId& id,
550 WebContentsObserver::MediaStoppedReason reason) {}
peconn257951522017-06-09 18:24:59551 virtual void MediaResized(const gfx::Size& size, const MediaPlayerId& id) {}
Peter E Conneccb34c22017-09-08 09:37:58552 // Invoked when media enters or exits fullscreen. We must use a heuristic
553 // to determine this as it is not trivial for media with custom controls.
554 // There is a slight delay between media entering or exiting fullscreen
555 // and it being detected.
556 virtual void MediaEffectivelyFullscreenChanged(bool is_fullscreen) {}
François Beauforta2f0a3ca2018-08-28 12:46:11557 virtual void MediaPictureInPictureChanged(bool is_picture_in_picture) {}
Becca Hughes9f6fd4b82017-06-15 10:01:40558 virtual void MediaMutedStatusChanged(const MediaPlayerId& id, bool muted) {}
prashantv0c9b968d22015-03-26 00:58:54559
mcnee432e47d2015-11-09 19:37:46560 // Invoked when the renderer process changes the page scale factor.
561 virtual void OnPageScaleFactorChanged(float page_scale_factor) {}
562
Archana Simhaf67090c2019-05-06 23:43:23563 // Invoked when a paste event occurs.
564 virtual void OnPaste() {}
565
[email protected]64ffefa2014-05-10 12:06:33566 // Invoked if an IPC message is coming from a specific RenderFrameHost.
567 virtual bool OnMessageReceived(const IPC::Message& message,
568 RenderFrameHost* render_frame_host);
569
Michael Thiessen896405db2017-07-20 17:52:32570 // Notification that the |render_widget_host| for this WebContents has gained
571 // focus.
572 virtual void OnWebContentsFocused(RenderWidgetHost* render_widget_host) {}
calamity7fe55ce2015-04-10 03:59:37573
Michael Thiessen896405db2017-07-20 17:52:32574 // Notification that the |render_widget_host| for this WebContents has lost
575 // focus.
576 virtual void OnWebContentsLostFocus(RenderWidgetHost* render_widget_host) {}
zijiehe3bee08e22017-05-17 04:14:46577
Jeff Fisher709b4c52019-07-29 20:07:34578 // Notification that a RenderFrameHost inside this WebContents has updated
579 // its focused element. |details| contains information on the element
580 // that has received focus. This allows for observing focus changes
581 // within WebContents, as opposed to OnWebContentsFocused/LostFocus
582 // which allows observation that the RenderWidgetHost for the
583 // WebContents has gained/lost focus.
584 virtual void OnFocusChangedInPage(FocusedNodeDetails* details) {}
585
Sam McNally145fb172017-05-10 00:13:23586 // Notifies that the manifest URL for the main frame changed to
587 // |manifest_url|. This will be invoked when a document with a manifest loads
588 // or when the manifest URL changes (possibly to nothing). It is not invoked
589 // when a document with no manifest loads. During document load, if the
590 // document has both a manifest and a favicon, DidUpdateWebManifestURL() will
591 // be invoked before DidUpdateFaviconURL().
592 virtual void DidUpdateWebManifestURL(
593 const base::Optional<GURL>& manifest_url) {}
594
Oksana Zhuravlova2838bb62020-03-18 18:59:06595 // DEPRECATED. Please register interface binders with BrowserInterfaceBroker
596 // instead (see 'Interface-Brokers' section in //docs/mojo_and_services.md).
Ben Goodger9e24929e2017-07-21 03:13:40597 // Called to give the embedder an opportunity to bind an interface request
598 // from a frame. If the request can be bound, |interface_pipe| will be taken.
599 virtual void OnInterfaceRequestFromFrame(
600 RenderFrameHost* render_frame_host,
601 const std::string& interface_name,
602 mojo::ScopedMessagePipeHandle* interface_pipe) {}
603
Raymond Toye413650c2018-08-31 00:12:47604 // Called when "audible" playback starts or stops on a WebAudio AudioContext.
605 using AudioContextId = std::pair<RenderFrameHost*, int>;
606 virtual void AudioContextPlaybackStarted(
607 const AudioContextId& audio_context_id) {}
608 virtual void AudioContextPlaybackStopped(
609 const AudioContextId& audio_context_id) {}
610
Alexander Timin17edc742020-04-23 18:22:18611 // Called when the RenderFrameHost tries to use a ServiceWorker
612 // (e.g. via navigation.serviceWorker API).
613 virtual void OnServiceWorkerAccessed(RenderFrameHost* render_frame_host,
614 const GURL& scope,
615 AllowServiceWorkerResult allowed) {}
616 // Called when the NavigationHandle accesses ServiceWorker to see if the
617 // network request should be handled by the ServiceWorker instead
618 // (e.g. for navigations to URLs which are in scope of a ServiceWorker).
619 virtual void OnServiceWorkerAccessed(NavigationHandle* navigation_handle,
620 const GURL& scope,
621 AllowServiceWorkerResult allowed) {}
Miyoung Shin8f2e1832020-04-27 09:00:02622 virtual bool ShowPopupMenu(
Miyoung Shin4d947d22020-04-24 04:48:33623 RenderFrameHost* render_frame_host,
Miyoung Shin8f2e1832020-04-27 09:00:02624 mojo::PendingRemote<blink::mojom::PopupMenuClient>* popup_client,
Miyoung Shin4d947d22020-04-24 04:48:33625 const gfx::Rect& bounds,
626 int32_t item_height,
627 double font_size,
628 int32_t selected_item,
629 std::vector<blink::mojom::MenuItemPtr>* menu_items,
630 bool right_aligned,
631 bool allow_multiple_selection);
Alexander Timin17edc742020-04-23 18:22:18632
[email protected]c47317e2012-06-20 22:35:31633 // IPC::Listener implementation.
Lukasz Anforowiczcf0a94a2017-08-31 19:10:09634 // DEPRECATED: Use (i.e. override) the other overload instead:
635 // virtual bool OnMessageReceived(const IPC::Message& message,
636 // RenderFrameHost* render_frame_host);
637 // TODO(https://crbug.com/758026): Delete this overload when possible.
dchenge933b3e2014-10-21 11:44:09638 bool OnMessageReceived(const IPC::Message& message) override;
[email protected]d8c660432011-12-22 20:51:25639
lucinka.brozkovac25f7fb92014-09-04 06:42:56640 WebContents* web_contents() const;
641
[email protected]d8c660432011-12-22 20:51:25642 protected:
[email protected]26b5e322011-12-23 01:36:47643 // Use this constructor when the object is tied to a single WebContents for
[email protected]d8c660432011-12-22 20:51:25644 // its entire lifetime.
[email protected]26b5e322011-12-23 01:36:47645 explicit WebContentsObserver(WebContents* web_contents);
[email protected]d8c660432011-12-22 20:51:25646
[email protected]b172aee2012-04-10 17:05:26647 // Use this constructor when the object wants to observe a WebContents for
[email protected]d8c660432011-12-22 20:51:25648 // part of its lifetime. It can then call Observe() to start and stop
649 // observing.
650 WebContentsObserver();
651
dchenge933b3e2014-10-21 11:44:09652 ~WebContentsObserver() override;
[email protected]d8c660432011-12-22 20:51:25653
[email protected]26b5e322011-12-23 01:36:47654 // Start observing a different WebContents; used with the default constructor.
655 void Observe(WebContents* web_contents);
[email protected]d8c660432011-12-22 20:51:25656
[email protected]d8c660432011-12-22 20:51:25657 private:
[email protected]8ff00d72012-10-23 19:12:21658 friend class WebContentsImpl;
[email protected]d8c660432011-12-22 20:51:25659
[email protected]12a46832014-05-09 13:35:58660 void ResetWebContents();
[email protected]d8c660432011-12-22 20:51:25661
[email protected]b172aee2012-04-10 17:05:26662 WebContentsImpl* web_contents_;
[email protected]d8c660432011-12-22 20:51:25663
664 DISALLOW_COPY_AND_ASSIGN(WebContentsObserver);
665};
666
667} // namespace content
668
669#endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_