blob: 0b9a8c72a4267a4ba15853f518361889512be25a [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"
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"
[email protected]71fde352011-12-29 03:29:5616#include "content/public/browser/navigation_controller.h"
toyoshim0df1d3a2016-09-09 09:52:4817#include "content/public/browser/reload_type.h"
Francois Dorayfe4a1772018-02-17 04:17:0918#include "content/public/browser/visibility.h"
[email protected]37567b432014-02-12 01:12:2219#include "content/public/common/frame_navigate_params.h"
[email protected]c47317e2012-06-20 22:35:3120#include "ipc/ipc_listener.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"
Dave Tapuska129cef82019-12-19 16:36:4824#include "third_party/blink/public/common/input/web_input_event.h"
Maks Orlovich73f374d2020-04-02 12:46:1325#include "third_party/blink/public/common/user_agent/user_agent_metadata.h"
Devlin Cronin5ea668f32019-12-18 21:57:5826#include "third_party/blink/public/mojom/devtools/console_message.mojom.h"
Minggang Wangee5af392020-02-05 02:55:2827#include "third_party/blink/public/mojom/loader/resource_load_info.mojom-forward.h"
[email protected]e7104762014-06-20 19:17:2528#include "third_party/skia/include/core/SkColor.h"
Sylvain Defresnec6ccc77d2014-09-19 10:19:3529#include "ui/base/page_transition_types.h"
[email protected]f47621b2013-01-22 20:50:3330#include "ui/base/window_open_disposition.h"
[email protected]d8c660432011-12-22 20:51:2531
Becca Hughes6fe54e432018-06-09 04:18:5632namespace blink {
33namespace mojom {
34enum class ViewportFit;
35} // namespace mojom
36} // namespace blink
37
peconn257951522017-06-09 18:24:5938namespace gfx {
39class Size;
40} // namespace gfx
41
[email protected]d8c660432011-12-22 20:51:2542namespace content {
43
[email protected]1ef02d242013-10-07 16:18:5344class NavigationEntry;
clamy0e119882015-07-31 16:12:3345class NavigationHandle;
[email protected]b849847b2013-12-10 21:57:5846class RenderFrameHost;
Avi Drissmanb3d355f2018-01-29 20:08:1847class RenderProcessHost;
[email protected]eaabba22012-03-07 15:02:1148class RenderViewHost;
afakhry98241832016-03-11 19:27:4749class RenderWidgetHost;
[email protected]26b5e322011-12-23 01:36:4750class WebContents;
[email protected]8ff00d72012-10-23 19:12:2151class WebContentsImpl;
[email protected]31a71eaf2014-03-13 01:47:3652struct AXEventNotificationDetails;
dmazzoni2400c462016-08-23 15:07:1353struct AXLocationChangeNotificationDetails;
Sam McNally5c087a32017-08-25 01:46:1454struct EntryChangedDetails;
Jeff Fisher709b4c52019-07-29 20:07:3455struct FocusedNodeDetails;
[email protected]71fde352011-12-29 03:29:5656struct LoadCommittedDetails;
Mounir Lamouri0f5bdf52019-04-04 16:32:3557struct MediaPlayerId;
Sam McNally5c087a32017-08-25 01:46:1458struct PrunedDetails;
[email protected]d8c660432011-12-22 20:51:2559struct Referrer;
[email protected]d8c660432011-12-22 20:51:2560
61// An observer API implemented by classes which are interested in various page
[email protected]b172aee2012-04-10 17:05:2662// load events from WebContents. They also get a chance to filter IPC messages.
[email protected]87eca182013-01-31 21:20:0063//
[email protected]d16609c2013-08-23 06:01:4064// Since a WebContents can be a delegate to almost arbitrarily many
[email protected]87eca182013-01-31 21:20:0065// RenderViewHosts, it is important to check in those WebContentsObserver
66// methods which take a RenderViewHost that the event came from the
67// RenderViewHost the observer cares about.
68//
69// Usually, observers should only care about the current RenderViewHost as
70// returned by GetRenderViewHost().
71//
72// TODO(creis, jochen): Hide the fact that there are several RenderViewHosts
73// from the WebContentsObserver API. http://crbug.com/173325
Lukasz Anforowiczf4357ca2017-09-07 01:43:3274class CONTENT_EXPORT WebContentsObserver : public IPC::Listener {
[email protected]d8c660432011-12-22 20:51:2575 public:
aviee9b7372016-06-28 20:34:4376 // Frames and Views ----------------------------------------------------------
77
nasko005282522015-01-22 02:30:0278 // Called when a RenderFrame for |render_frame_host| is created in the
79 // renderer process. Use |RenderFrameDeleted| to listen for when this
80 // RenderFrame goes away.
[email protected]b849847b2013-12-10 21:57:5881 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) {}
82
nasko005282522015-01-22 02:30:0283 // Called when a RenderFrame for |render_frame_host| is deleted or the
84 // renderer process in which it runs it has died. Use |RenderFrameCreated| to
85 // listen for when RenderFrame objects are created.
[email protected]b849847b2013-12-10 21:57:5886 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) {}
87
nasko005282522015-01-22 02:30:0288 // This method is invoked whenever one of the current frames of a WebContents
89 // swaps its RenderFrameHost with another one; for example because that frame
90 // navigated and the new content is in a different process. The
91 // RenderFrameHost that has been replaced is in |old_host|, which can be
92 // nullptr if the old RenderFrameHost was shut down or a new frame has been
93 // created and no old RenderFrameHost exists.
94 //
95 // This method, in combination with |FrameDeleted|, is appropriate for
96 // observers wishing to track the set of current RenderFrameHosts -- i.e.,
Lei Zhangebcc6302018-01-12 19:46:4597 // those hosts that would be visited by calling WebContents::ForEachFrame().
nasko005282522015-01-22 02:30:0298 virtual void RenderFrameHostChanged(RenderFrameHost* old_host,
99 RenderFrameHost* new_host) {}
100
101 // This method is invoked when a subframe associated with a WebContents is
102 // deleted or the WebContents is destroyed and the top-level frame is deleted.
103 // Use |RenderFrameHostChanged| to listen for when a RenderFrameHost object is
104 // made the current host for a frame.
105 virtual void FrameDeleted(RenderFrameHost* render_frame_host) {}
106
[email protected]a86c0e962013-12-17 17:10:39107 // This is called when a RVH is created for a WebContents, but not if it's an
108 // interstitial.
[email protected]d8c660432011-12-22 20:51:25109 virtual void RenderViewCreated(RenderViewHost* render_view_host) {}
[email protected]a86c0e962013-12-17 17:10:39110
111 // Called for every RenderFrameHost that's created for an interstitial.
112 virtual void RenderFrameForInterstitialPageCreated(
113 RenderFrameHost* render_frame_host) {}
[email protected]87eca182013-01-31 21:20:00114
115 // This method is invoked when the RenderView of the current RenderViewHost
116 // is ready, e.g. because we recreated it after a crash.
[email protected]d8c660432011-12-22 20:51:25117 virtual void RenderViewReady() {}
[email protected]87eca182013-01-31 21:20:00118
119 // This method is invoked when a RenderViewHost of the WebContents is
120 // deleted. Note that this does not always happen when the WebContents starts
121 // to use a different RenderViewHost, as the old RenderViewHost might get
122 // just swapped out.
123 virtual void RenderViewDeleted(RenderViewHost* render_view_host) {}
124
avi33601202015-07-11 01:39:26125 // This method is invoked when the process for the current main
126 // RenderFrameHost exits (usually by crashing, though possibly by other
127 // means). The WebContents continues to use the RenderFrameHost, e.g. when the
128 // user reloads the current page. When the RenderFrameHost itself is deleted,
129 // the RenderFrameDeleted method will be invoked.
[email protected]4d614412014-01-10 08:29:37130 //
avi33601202015-07-11 01:39:26131 // Note that this is triggered upstream through
132 // RenderProcessHostObserver::RenderProcessExited(); for code that doesn't
133 // otherwise need to be a WebContentsObserver, that API is probably a better
134 // choice.
[email protected]58d5cfe2013-07-10 02:40:52135 virtual void RenderProcessGone(base::TerminationStatus status) {}
[email protected]87eca182013-01-31 21:20:00136
[email protected]02d7b6e2014-06-24 21:01:50137 // This method is invoked when a WebContents swaps its visible RenderViewHost
138 // with another one, possibly changing processes. The RenderViewHost that has
mlamouri8c61ffc2015-01-13 16:17:59139 // been replaced is in |old_host|, which is nullptr if the old RVH was shut
140 // down.
[email protected]7b712ee22013-10-03 00:57:28141 virtual void RenderViewHostChanged(RenderViewHost* old_host,
142 RenderViewHost* new_host) {}
[email protected]da7a7182013-09-06 08:11:11143
Avi Drissmanb3d355f2018-01-29 20:08:18144 // This method is invoked when a process in the WebContents becomes
145 // unresponsive.
146 virtual void OnRendererUnresponsive(RenderProcessHost* render_process_host) {}
afakhry98241832016-03-11 19:27:47147
aviee9b7372016-06-28 20:34:43148 // Navigation ----------------------------------------------------------------
clamy0e119882015-07-31 16:12:33149
150 // Called when a navigation started in the WebContents. |navigation_handle|
151 // is unique to a specific navigation. The same |navigation_handle| will be
nasko14baf392016-02-02 02:15:38152 // provided on subsequent calls to DidRedirectNavigation, DidFinishNavigation,
153 // and ReadyToCommitNavigation when related to this navigation. Observers
154 // should clear any references to |navigation_handle| in DidFinishNavigation,
155 // just before it is destroyed.
clamy0e119882015-07-31 16:12:33156 //
157 // Note that this is fired by navigations in any frame of the WebContents,
158 // not just the main frame.
159 //
eugenebuta11672fb2017-03-07 17:13:51160 // Note that this is fired by same-document navigations, such as fragment
clamy57f99bd22016-11-30 18:25:11161 // navigations or pushState/replaceState, which will not result in a document
eugenebuta11672fb2017-03-07 17:13:51162 // change. To filter these out, use NavigationHandle::IsSameDocument.
clamy57f99bd22016-11-30 18:25:11163 //
clamy0e119882015-07-31 16:12:33164 // Note that more than one navigation can be ongoing in the same frame at the
165 // same time (including the main frame). Each will get its own
166 // NavigationHandle.
167 //
168 // Note that there is no guarantee that DidFinishNavigation will be called
169 // for any particular navigation before DidStartNavigation is called on the
170 // next.
171 virtual void DidStartNavigation(NavigationHandle* navigation_handle) {}
172
173 // Called when a navigation encountered a server redirect.
174 virtual void DidRedirectNavigation(NavigationHandle* navigation_handle) {}
175
John Abd-El-Malekdf8e3da2019-10-30 00:57:37176 // Called when the navigation is ready to be committed in a renderer. This
177 // occurs when the response code isn't 204/205 (which tell the browser that
178 // the request is successful but there's no content that follows) or a
179 // download (either from a response header or based on mime sniffing the
180 // response). The browser then is ready to switch rendering the new document.
181 // Most observers should use DidFinishNavigation instead, which happens right
clamyb876f0a72015-09-24 20:01:05182 // after the navigation commits. This method is for observers that want to
183 // initialize renderer-side state just before the RenderFrame commits the
184 // navigation.
185 //
clamyb876f0a72015-09-24 20:01:05186 // This is the first point in time where a RenderFrameHost is associated with
187 // the navigation.
clamyefca29e2015-09-17 00:22:11188 virtual void ReadyToCommitNavigation(NavigationHandle* navigation_handle) {}
189
clamyb876f0a72015-09-24 20:01:05190 // Called when a navigation finished in the WebContents. This happens when a
191 // navigation is committed, aborted or replaced by a new one. To know if the
vabrd9092d32016-03-16 19:03:32192 // navigation has committed, use NavigationHandle::HasCommitted; use
clamyb876f0a72015-09-24 20:01:05193 // NavigationHandle::IsErrorPage to know if the navigation resulted in an
194 // error page.
195 //
196 // If this is called because the navigation committed, then the document load
197 // will still be ongoing in the RenderFrameHost returned by
198 // |navigation_handle|. Use the document loads events such as DidStopLoading
199 // and related methods to listen for continued events from this
200 // RenderFrameHost.
201 //
eugenebuta11672fb2017-03-07 17:13:51202 // Note that this is fired by same-document navigations, such as fragment
clamy57f99bd22016-11-30 18:25:11203 // navigations or pushState/replaceState, which will not result in a document
eugenebuta11672fb2017-03-07 17:13:51204 // change. To filter these out, use NavigationHandle::IsSameDocument.
clamy57f99bd22016-11-30 18:25:11205 //
clamyb876f0a72015-09-24 20:01:05206 // Note that |navigation_handle| will be destroyed at the end of this call,
207 // so do not keep a reference to it afterward.
clamy0e119882015-07-31 16:12:33208 virtual void DidFinishNavigation(NavigationHandle* navigation_handle) {}
209
aviee9b7372016-06-28 20:34:43210 // Navigation (obsolete and deprecated) --------------------------------------
211
212 // This method is invoked after the browser process starts a navigation to a
213 // pending NavigationEntry. It is not called for renderer-initiated
214 // navigations unless they are sent to the browser process via OpenURL. It may
215 // be called multiple times for a given navigation, such as a typed URL
216 // followed by a cross-process client or server redirect.
217 //
Arthur Hemery0dd65812019-08-01 14:18:45218 // SOON TO BE DEPRECATED. Use DidStartNavigation instead.
219 // TODO(clamy): Remove this function.
toyoshim0df1d3a2016-09-09 09:52:48220 virtual void DidStartNavigationToPendingEntry(const GURL& url,
221 ReloadType reload_type) {}
aviee9b7372016-06-28 20:34:43222
clamyb876f0a72015-09-24 20:01:05223 // Document load events ------------------------------------------------------
224
Chris Hamiltonf82f2a702018-02-15 19:37:29225 // These three methods correspond to the points in time when a document starts
226 // loading for the first time (initiates outgoing requests), when incoming
227 // data subsequently starts arriving, and when it finishes loading.
clamyb876f0a72015-09-24 20:01:05228 virtual void DidStartLoading() {}
Chris Hamiltonf82f2a702018-02-15 19:37:29229 virtual void DidReceiveResponse() {}
clamyb876f0a72015-09-24 20:01:05230 virtual void DidStopLoading() {}
231
Evan Stade9f328112019-10-23 20:49:25232 // The page has made some progress loading. |progress| is a value between 0.0
233 // (nothing loaded) to 1.0 (page fully loaded).
234 virtual void LoadProgressChanged(double progress) {}
235
clamyb876f0a72015-09-24 20:01:05236 // This method is invoked once the window.document object of the main frame
237 // was created.
238 virtual void DocumentAvailableInMainFrame() {}
239
240 // This method is invoked once the onload handler of the main frame has
241 // completed.
Alexander Timindd0fa0c52019-11-06 13:03:37242 // Prefer using WebContents::IsDocumentOnLoadCompletedInMainFrame instead
243 // of saving this state in your component.
clamyb876f0a72015-09-24 20:01:05244 virtual void DocumentOnLoadCompletedInMainFrame() {}
245
246 // This method is invoked when the document in the given frame finished
247 // loading. At this point, scripts marked as defer were executed, and
248 // content scripts marked "document_end" get injected into the frame.
Kouhei Uenof6e96242019-09-27 01:54:35249 virtual void DOMContentLoaded(RenderFrameHost* render_frame_host) {}
clamyb876f0a72015-09-24 20:01:05250
aviee9b7372016-06-28 20:34:43251 // This method is invoked when the load is done, i.e. the spinner of the tab
252 // will stop spinning, and the onload event was dispatched.
clamyb876f0a72015-09-24 20:01:05253 //
254 // If the WebContents is displaying replacement content, e.g. network error
255 // pages, DidFinishLoad is invoked for frames that were not sending
256 // navigational events before. It is safe to ignore these events.
257 virtual void DidFinishLoad(RenderFrameHost* render_frame_host,
258 const GURL& validated_url) {}
259
260 // This method is like DidFinishLoad, but when the load failed or was
261 // cancelled, e.g. window.stop() is invoked.
262 virtual void DidFailLoad(RenderFrameHost* render_frame_host,
263 const GURL& validated_url,
Dave Tapuska924ef3c2020-01-22 18:20:59264 int error_code) {}
clamyb876f0a72015-09-24 20:01:05265
cjgrant6d1d727a2016-12-09 21:16:57266 // This method is invoked when the visible security state of the page changes.
267 virtual void DidChangeVisibleSecurityState() {}
lgarron662dd522015-06-08 23:20:01268
[email protected]b0f724c2013-09-05 04:21:13269 // This method is invoked when content was loaded from an in-memory cache.
270 virtual void DidLoadResourceFromMemoryCache(
jam91dd24e2016-08-12 17:16:42271 const GURL& url,
272 const std::string& mime_type,
Kinuko Yasuda433f710a2020-02-14 02:11:58273 network::mojom::RequestDestination request_destination) {}
[email protected]b0f724c2013-09-05 04:21:13274
Jay Civelli718fd6c02018-05-11 21:04:27275 // This method is invoked when a resource associate with the frame
Clark DuVall36164bd2018-08-09 22:49:08276 // |render_frame_host| has been loaded, successfully or not. |request_id| will
277 // only be populated for main frame resources.
Jay Civelli116683f2018-03-27 19:56:23278 virtual void ResourceLoadComplete(
Jay Civelli718fd6c02018-05-11 21:04:27279 RenderFrameHost* render_frame_host,
Clark DuVall36164bd2018-08-09 22:49:08280 const GlobalRequestID& request_id,
Minggang Wangee5af392020-02-05 02:55:28281 const blink::mojom::ResourceLoadInfo& resource_load_info) {}
[email protected]b0f724c2013-09-05 04:21:13282
Josh Karlindaba39322019-07-17 23:24:33283 // This method is invoked when a document or resource reads a cookie. Note
284 // that this isn't tied to any particular navigation (e.g., it may be called
285 // after a subsequent navigation commits).
286 virtual void OnCookiesRead(const GURL& url,
287 const GURL& first_party_url,
288 const net::CookieList& cookie_list,
289 bool blocked_by_policy) {}
290
291 // This method is invoked when an attempt has been made to set |cookie|. Note
292 // that this isn't tied to any particular navigation (e.g., it may be called
293 // after a subsequent navigation commits).
294 virtual void OnCookieChange(const GURL& url,
295 const GURL& first_party_url,
296 const net::CanonicalCookie& cookie,
297 bool blocked_by_policy) {}
298
[email protected]cbb1ef592013-06-05 19:49:46299 // This method is invoked when a new non-pending navigation entry is created.
300 // This corresponds to one NavigationController entry being created
301 // (in the case of new navigations) or renavigated to (for back/forward
302 // navigations).
303 virtual void NavigationEntryCommitted(
304 const LoadCommittedDetails& load_details) {}
305
Sam McNally5c087a32017-08-25 01:46:14306 // Invoked when the NavigationController decreased its back/forward list count
307 // by removing entries from either the front or back of its list. This is
308 // usually the result of going back and then doing a new navigation, meaning
309 // all the "forward" items are deleted.
310 //
311 // This normally happens as a result of a new navigation. It will be
312 // followed by a NavigationEntryCommitted() call for the new page that
313 // caused the pruning. It could also be a result of removing an item from
Christian Dullweberb13ffda2018-02-23 11:42:14314 // the list to delete history or fix up after interstitials.
Sam McNally5c087a32017-08-25 01:46:14315 virtual void NavigationListPruned(const PrunedDetails& pruned_details) {}
316
Christian Dullweber1af31e62018-02-22 11:49:48317 // Invoked when NavigationEntries have been deleted because of a history
318 // deletion. Observers should ensure that they remove all traces of the
319 // deleted entries.
320 virtual void NavigationEntriesDeleted() {}
321
Sam McNally5c087a32017-08-25 01:46:14322 // Invoked when a NavigationEntry has changed.
323 //
324 // This will NOT be sent on navigation, interested parties should also
325 // implement NavigationEntryCommitted() to handle that case. This will be
326 // sent when the entry is updated outside of navigation (like when a new
327 // title comes).
328 virtual void NavigationEntryChanged(
329 const EntryChangedDetails& change_details) {}
330
[email protected]87eca182013-01-31 21:20:00331 // This method is invoked when a new WebContents was created in response to
332 // an action in the observed WebContents, e.g. a link with target=_blank was
creis114ca1b2014-11-13 23:51:46333 // clicked. The |source_render_frame_host| is the frame in which the action
334 // took place.
[email protected]26b5e322011-12-23 01:36:47335 virtual void DidOpenRequestedURL(WebContents* new_contents,
creis114ca1b2014-11-13 23:51:46336 RenderFrameHost* source_render_frame_host,
[email protected]d8c660432011-12-22 20:51:25337 const GURL& url,
338 const Referrer& referrer,
339 WindowOpenDisposition disposition,
pnoland488944652017-02-22 18:58:54340 ui::PageTransition transition,
pnolandaae574e2017-03-06 21:04:21341 bool started_from_context_menu,
342 bool renderer_initiated) {}
[email protected]d8c660432011-12-22 20:51:25343
nasko005282522015-01-22 02:30:02344 // This method is invoked when the renderer process has completed its first
345 // paint after a non-empty layout.
[email protected]50279492014-05-05 23:24:29346 virtual void DidFirstVisuallyNonEmptyPaint() {}
[email protected]9f268072013-11-07 00:02:15347
[email protected]d16609c2013-08-23 06:01:40348 // When WebContents::Stop() is called, the WebContents stops loading and then
349 // invokes this method. If there are ongoing navigations, their respective
350 // failure methods will also be invoked.
351 virtual void NavigationStopped() {}
[email protected]87eca182013-01-31 21:20:00352
dominickn2dd142dd2015-10-29 05:30:50353 // Called when there has been direct user interaction with the WebContents.
dominicknad9c99d2015-11-06 01:52:49354 // The type argument specifies the kind of interaction. Direct user input
355 // signalled through this callback includes:
356 // 1) any mouse down event (blink::WebInputEvent::MouseDown);
dominickn5cc29a42016-03-25 03:06:22357 // 2) the start of a scroll (blink::WebInputEvent::GestureScrollBegin);
Dominick Ng37a15052018-07-17 23:56:35358 // 3) any raw key down event (blink::WebInputEvent::RawKeyDown); and
359 // 4) any touch event (inc. scrolls) (blink::WebInputEvent::TouchStart).
dominickn2dd142dd2015-10-29 05:30:50360 virtual void DidGetUserInteraction(const blink::WebInputEvent::Type type) {}
361
[email protected]87eca182013-01-31 21:20:00362 // This method is invoked when a RenderViewHost of this WebContents was
363 // configured to ignore UI events, and an UI event took place.
364 virtual void DidGetIgnoredUIEvent() {}
365
Francois Dorayfe4a1772018-02-17 04:17:09366 // Invoked every time the WebContents changes visibility.
367 virtual void OnVisibilityChanged(Visibility visibility) {}
[email protected]3e324142012-06-25 18:26:33368
estaded0a0c992015-01-21 14:12:06369 // Invoked when the main frame changes size.
rouslan2f5993f2015-01-29 00:18:31370 virtual void MainFrameWasResized(bool width_changed) {}
estaded0a0c992015-01-21 14:12:06371
alexmosbe2f4c32015-03-10 02:30:23372 // Invoked when the given frame changes its window.name property.
373 virtual void FrameNameChanged(RenderFrameHost* render_frame_host,
374 const std::string& name) {}
375
John Delaneyedd8d6c2019-01-25 00:23:57376 // Called when the sticky user activation bit has been set on the frame.
377 // This will not be called for new RenderFrameHosts whose underlying
378 // FrameTreeNode was already activated. This should not be used to determine a
379 // RenderFrameHost's user activation state.
380 virtual void FrameReceivedFirstUserActivation(
381 RenderFrameHost* render_frame_host) {}
382
John Delaney0146a742019-01-25 19:25:28383 // Invoked when the display state of the frame changes.
384 virtual void FrameDisplayStateChanged(RenderFrameHost* render_frame_host,
385 bool is_display_none) {}
386
387 // Invoked when a frame changes size.
388 virtual void FrameSizeChanged(RenderFrameHost* render_frame_host,
389 const gfx::Size& frame_size) {}
390
Avi Drissmana2ca5b142017-11-14 21:10:47391 // This method is invoked when the title of the WebContents is set. Note that
392 // |entry| may be null if the web page whose title changed has not yet had a
393 // NavigationEntry assigned to it.
Avi Drissman93002212017-09-27 03:20:52394 virtual void TitleWasSet(NavigationEntry* entry) {}
[email protected]66798902013-10-01 18:40:16395
[email protected]d8c660432011-12-22 20:51:25396 virtual void AppCacheAccessed(const GURL& manifest_url,
397 bool blocked_by_policy) {}
398
emaxxe70f5e12015-05-29 11:26:00399 // These methods are invoked when a Pepper plugin instance is created/deleted
400 // in the DOM.
401 virtual void PepperInstanceCreated() {}
402 virtual void PepperInstanceDeleted() {}
403
Becca Hughes6fe54e432018-06-09 04:18:56404 // This method is called when the viewport fit of a WebContents changes.
405 virtual void ViewportFitChanged(blink::mojom::ViewportFit value) {}
406
[email protected]3fc07c52012-04-20 00:27:44407 // Notification that a plugin has crashed.
[email protected]cf4d6e742013-01-10 14:06:42408 // |plugin_pid| is the process ID identifying the plugin process. Note that
nasko005282522015-01-22 02:30:02409 // this ID is supplied by the renderer process, so should not be trusted.
410 // Besides, the corresponding process has probably died at this point. The ID
411 // may even have been reused by a new process.
[email protected]c42de732013-02-16 06:26:31412 virtual void PluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:42413 base::ProcessId plugin_pid) {}
[email protected]3fc07c52012-04-20 00:27:44414
[email protected]d16609c2013-08-23 06:01:40415 // Notification that the given plugin has hung or become unhung. This
[email protected]3fc07c52012-04-20 00:27:44416 // notification is only for Pepper plugins.
417 //
418 // The plugin_child_id is the unique child process ID from the plugin. Note
nasko005282522015-01-22 02:30:02419 // that this ID is supplied by the renderer process, so should be validated
420 // before it's used for anything in case there's an exploited renderer
421 // process.
[email protected]3fc07c52012-04-20 00:27:44422 virtual void PluginHungStatusChanged(int plugin_child_id,
[email protected]c42de732013-02-16 06:26:31423 const base::FilePath& plugin_path,
[email protected]3fc07c52012-04-20 00:27:44424 bool is_hung) {}
425
Sean Toppingbbc4a2bd2019-01-30 02:16:14426 // Notifies that an inner WebContents instance has been created with the
427 // observed WebContents as its container. |inner_web_contents| has not been
428 // added to the WebContents tree at this point, but can be observed safely.
429 virtual void InnerWebContentsCreated(WebContents* inner_web_contents) {}
430
[email protected]7381d9f2012-09-12 20:26:22431 // Invoked when WebContents::Clone() was used to clone a WebContents.
432 virtual void DidCloneToNewWebContents(WebContents* old_web_contents,
433 WebContents* new_web_contents) {}
434
[email protected]26b5e322011-12-23 01:36:47435 // Invoked when the WebContents is being destroyed. Gives subclasses a chance
[email protected]12a46832014-05-09 13:35:58436 // to cleanup. After the whole loop over all WebContentsObservers has been
mlamouri8c61ffc2015-01-13 16:17:59437 // finished, web_contents() returns nullptr.
[email protected]12a46832014-05-09 13:35:58438 virtual void WebContentsDestroyed() {}
[email protected]d8c660432011-12-22 20:51:25439
[email protected]8d0f3312012-08-18 01:47:53440 // Called when the user agent override for a WebContents has been changed.
Maks Orlovich73f374d2020-04-02 12:46:13441 virtual void UserAgentOverrideSet(
442 const blink::UserAgentOverride& ua_override) {}
[email protected]8d0f3312012-08-18 01:47:53443
Miyoung Shin5709ab02020-02-19 06:50:41444 // Invoked when new blink::mojom::FaviconURLPtr candidates are received from
445 // the renderer process. If the instance is created after the page is loaded,
446 // it is recommended to call WebContents::GetFaviconURLs() to get the current
447 // list as this callback will not be executed unless there is an update.
448 virtual void DidUpdateFaviconURL(
449 const std::vector<blink::mojom::FaviconURLPtr>& candidates) {}
[email protected]795c28972012-12-06 06:13:39450
Chris Hamiltoneb41198f2018-05-24 18:41:26451 // Called when an audio change occurs.
452 virtual void OnAudioStateChanged(bool audible) {}
453
Francois Doray66766a572019-12-17 20:56:49454 // Called when the connected to Bluetooth device state changes.
455 virtual void OnIsConnectedToBluetoothDeviceChanged(
456 bool is_connected_to_bluetooth_device) {}
457
wjmaclean2f797c782016-01-07 14:52:03458 // Invoked when the WebContents is muted/unmuted.
459 virtual void DidUpdateAudioMutingState(bool muted) {}
460
[email protected]44470a22013-01-24 01:21:54461 // Invoked when a pepper plugin creates and shows or destroys a fullscreen
nasko005282522015-01-22 02:30:02462 // RenderWidget.
alexmos899e06f2016-05-13 23:08:09463 virtual void DidShowFullscreenWidget() {}
464 virtual void DidDestroyFullscreenWidget() {}
[email protected]44470a22013-01-24 01:21:54465
nasko005282522015-01-22 02:30:02466 // Invoked when the renderer process has toggled the tab into/out of
467 // fullscreen mode.
bokanece34a82016-01-28 19:49:46468 virtual void DidToggleFullscreenModeForTab(bool entered_fullscreen,
469 bool will_cause_resize) {}
[email protected]657c8e02014-03-19 19:18:37470
Becca Hughesfd5d8f892018-06-14 18:23:36471 // Signals that |rfh| has the current fullscreen element. This is invoked
472 // when:
473 // 1) an element in this frame enters fullscreen or in nested fullscreen, or
474 // 2) after an element in a descendant frame exits fullscreen and makes
475 // this frame own the current fullscreen element again.
476 virtual void DidAcquireFullscreen(RenderFrameHost* rfh) {}
477
[email protected]20ca0382013-02-28 19:50:07478 // Invoked when an interstitial page is attached or detached.
479 virtual void DidAttachInterstitialPage() {}
480 virtual void DidDetachInterstitialPage() {}
481
David Black9cca3592019-11-06 23:02:22482 // Invoked when the vertical scroll direction of the root layer is changed.
483 // Note that if a scroll in a given direction occurs, the scroll is completed,
484 // and then another scroll in the *same* direction occurs, we will not
485 // consider the second scroll event to have caused a change in direction. Also
486 // note that this API will *never* be called with |kNull| which only exists to
487 // indicate the absence of a vertical scroll direction.
488 virtual void DidChangeVerticalScrollDirection(
489 viz::VerticalScrollDirection scroll_direction) {}
490
[email protected]17e286e2013-03-01 23:29:39491 // Invoked before a form repost warning is shown.
492 virtual void BeforeFormRepostWarningShow() {}
493
Chris Hamilton3b3e315d2018-09-19 13:16:21494 // Invoked when the beforeunload handler fires. |proceed| is set to true if
495 // the beforeunload can safely proceed, otherwise it should be interrupted.
496 // The time is from the renderer process.
497 virtual void BeforeUnloadFired(bool proceed,
498 const base::TimeTicks& proceed_time) {}
[email protected]6d65a462013-06-21 21:29:12499
500 // Invoked when a user cancels a before unload dialog.
501 virtual void BeforeUnloadDialogCancelled() {}
502
dmazzonidd3d51a72016-12-14 18:41:01503 // Called when accessibility events or location changes are received
504 // from a render frame, but only when the accessibility mode has the
Doug Turner63f3c7b2017-07-29 05:10:01505 // ui::AXMode::kWebContents flag set.
Dominic Mazzonia7b0edb22017-08-09 16:32:51506 virtual void AccessibilityEventReceived(
Dominic Mazzoniccbaa9b2018-06-06 07:44:23507 const AXEventNotificationDetails& details) {}
dmazzoni2400c462016-08-23 15:07:13508 virtual void AccessibilityLocationChangesReceived(
509 const std::vector<AXLocationChangeNotificationDetails>& details) {}
510
Peter Kastingb14e5782020-01-06 23:55:04511 // Invoked when theme color is changed.
512 virtual void DidChangeThemeColor() {}
[email protected]e7104762014-06-20 19:17:25513
Devlin Cronin5ea668f32019-12-18 21:57:58514 // Called when a message is added to the console of the WebContents. This is
515 // invoked before forwarding the message to the WebContents' delegate.
516 virtual void OnDidAddMessageToConsole(
517 blink::mojom::ConsoleMessageLevel log_level,
518 const base::string16& message,
519 int32_t line_no,
520 const base::string16& source_id) {}
521
dalecurtis88c240072015-12-09 02:11:18522 // Invoked when media is playing or paused. |id| is unique per player and per
523 // RenderFrameHost. There may be multiple players within a RenderFrameHost
524 // and subsequently within a WebContents. MediaStartedPlaying() will always
525 // be followed by MediaStoppedPlaying() after player teardown. Observers must
526 // release all stored copies of |id| when MediaStoppedPlaying() is received.
Mounir Lamouri366dd8472018-06-19 17:20:04527 // |has_video| and |has_audio| can both be false in cases where the media
528 // is playing muted and should be considered as inaudible for all intent and
529 // purposes.
billorr21c005d2016-11-17 03:57:04530 struct MediaPlayerInfo {
Becca Hughes3f921362017-06-08 14:08:36531 MediaPlayerInfo(bool has_video, bool has_audio)
532 : has_video(has_video), has_audio(has_audio) {}
billorr21c005d2016-11-17 03:57:04533 bool has_video;
Becca Hughes3f921362017-06-08 14:08:36534 bool has_audio;
billorr21c005d2016-11-17 03:57:04535 };
François Beaufortddaf8a82018-07-16 16:43:12536
billorr21c005d2016-11-17 03:57:04537 virtual void MediaStartedPlaying(const MediaPlayerInfo& video_type,
538 const MediaPlayerId& id) {}
Becca Hughes220bfc102017-11-14 18:24:07539 enum class MediaStoppedReason {
540 // The media was stopped for an unspecified reason.
541 kUnspecified,
542
543 // The media was stopped because it reached the end of the stream.
544 kReachedEndOfStream,
545 };
546 virtual void MediaStoppedPlaying(
547 const MediaPlayerInfo& video_type,
548 const MediaPlayerId& id,
549 WebContentsObserver::MediaStoppedReason reason) {}
peconn257951522017-06-09 18:24:59550 virtual void MediaResized(const gfx::Size& size, const MediaPlayerId& id) {}
Peter E Conneccb34c22017-09-08 09:37:58551 // Invoked when media enters or exits fullscreen. We must use a heuristic
552 // to determine this as it is not trivial for media with custom controls.
553 // There is a slight delay between media entering or exiting fullscreen
554 // and it being detected.
555 virtual void MediaEffectivelyFullscreenChanged(bool is_fullscreen) {}
François Beauforta2f0a3ca2018-08-28 12:46:11556 virtual void MediaPictureInPictureChanged(bool is_picture_in_picture) {}
Becca Hughes9f6fd4b82017-06-15 10:01:40557 virtual void MediaMutedStatusChanged(const MediaPlayerId& id, bool muted) {}
prashantv0c9b968d22015-03-26 00:58:54558
mcnee432e47d2015-11-09 19:37:46559 // Invoked when the renderer process changes the page scale factor.
560 virtual void OnPageScaleFactorChanged(float page_scale_factor) {}
561
Archana Simhaf67090c2019-05-06 23:43:23562 // Invoked when a paste event occurs.
563 virtual void OnPaste() {}
564
[email protected]64ffefa2014-05-10 12:06:33565 // Invoked if an IPC message is coming from a specific RenderFrameHost.
566 virtual bool OnMessageReceived(const IPC::Message& message,
567 RenderFrameHost* render_frame_host);
568
Michael Thiessen896405db2017-07-20 17:52:32569 // Notification that the |render_widget_host| for this WebContents has gained
570 // focus.
571 virtual void OnWebContentsFocused(RenderWidgetHost* render_widget_host) {}
calamity7fe55ce2015-04-10 03:59:37572
Michael Thiessen896405db2017-07-20 17:52:32573 // Notification that the |render_widget_host| for this WebContents has lost
574 // focus.
575 virtual void OnWebContentsLostFocus(RenderWidgetHost* render_widget_host) {}
zijiehe3bee08e22017-05-17 04:14:46576
Jeff Fisher709b4c52019-07-29 20:07:34577 // Notification that a RenderFrameHost inside this WebContents has updated
578 // its focused element. |details| contains information on the element
579 // that has received focus. This allows for observing focus changes
580 // within WebContents, as opposed to OnWebContentsFocused/LostFocus
581 // which allows observation that the RenderWidgetHost for the
582 // WebContents has gained/lost focus.
583 virtual void OnFocusChangedInPage(FocusedNodeDetails* details) {}
584
Sam McNally145fb172017-05-10 00:13:23585 // Notifies that the manifest URL for the main frame changed to
586 // |manifest_url|. This will be invoked when a document with a manifest loads
587 // or when the manifest URL changes (possibly to nothing). It is not invoked
588 // when a document with no manifest loads. During document load, if the
589 // document has both a manifest and a favicon, DidUpdateWebManifestURL() will
590 // be invoked before DidUpdateFaviconURL().
591 virtual void DidUpdateWebManifestURL(
592 const base::Optional<GURL>& manifest_url) {}
593
Oksana Zhuravlova2838bb62020-03-18 18:59:06594 // DEPRECATED. Please register interface binders with BrowserInterfaceBroker
595 // instead (see 'Interface-Brokers' section in //docs/mojo_and_services.md).
Ben Goodger9e24929e2017-07-21 03:13:40596 // Called to give the embedder an opportunity to bind an interface request
597 // from a frame. If the request can be bound, |interface_pipe| will be taken.
598 virtual void OnInterfaceRequestFromFrame(
599 RenderFrameHost* render_frame_host,
600 const std::string& interface_name,
601 mojo::ScopedMessagePipeHandle* interface_pipe) {}
602
Raymond Toye413650c2018-08-31 00:12:47603 // Called when "audible" playback starts or stops on a WebAudio AudioContext.
604 using AudioContextId = std::pair<RenderFrameHost*, int>;
605 virtual void AudioContextPlaybackStarted(
606 const AudioContextId& audio_context_id) {}
607 virtual void AudioContextPlaybackStopped(
608 const AudioContextId& audio_context_id) {}
609
[email protected]c47317e2012-06-20 22:35:31610 // IPC::Listener implementation.
Lukasz Anforowiczcf0a94a2017-08-31 19:10:09611 // DEPRECATED: Use (i.e. override) the other overload instead:
612 // virtual bool OnMessageReceived(const IPC::Message& message,
613 // RenderFrameHost* render_frame_host);
614 // TODO(https://crbug.com/758026): Delete this overload when possible.
dchenge933b3e2014-10-21 11:44:09615 bool OnMessageReceived(const IPC::Message& message) override;
[email protected]d8c660432011-12-22 20:51:25616
lucinka.brozkovac25f7fb92014-09-04 06:42:56617 WebContents* web_contents() const;
618
[email protected]d8c660432011-12-22 20:51:25619 protected:
[email protected]26b5e322011-12-23 01:36:47620 // Use this constructor when the object is tied to a single WebContents for
[email protected]d8c660432011-12-22 20:51:25621 // its entire lifetime.
[email protected]26b5e322011-12-23 01:36:47622 explicit WebContentsObserver(WebContents* web_contents);
[email protected]d8c660432011-12-22 20:51:25623
[email protected]b172aee2012-04-10 17:05:26624 // Use this constructor when the object wants to observe a WebContents for
[email protected]d8c660432011-12-22 20:51:25625 // part of its lifetime. It can then call Observe() to start and stop
626 // observing.
627 WebContentsObserver();
628
dchenge933b3e2014-10-21 11:44:09629 ~WebContentsObserver() override;
[email protected]d8c660432011-12-22 20:51:25630
[email protected]26b5e322011-12-23 01:36:47631 // Start observing a different WebContents; used with the default constructor.
632 void Observe(WebContents* web_contents);
[email protected]d8c660432011-12-22 20:51:25633
[email protected]d8c660432011-12-22 20:51:25634 private:
[email protected]8ff00d72012-10-23 19:12:21635 friend class WebContentsImpl;
[email protected]d8c660432011-12-22 20:51:25636
[email protected]12a46832014-05-09 13:35:58637 void ResetWebContents();
[email protected]d8c660432011-12-22 20:51:25638
[email protected]b172aee2012-04-10 17:05:26639 WebContentsImpl* web_contents_;
[email protected]d8c660432011-12-22 20:51:25640
641 DISALLOW_COPY_AND_ASSIGN(WebContentsObserver);
642};
643
644} // namespace content
645
646#endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_