blob: e97e4616cb51f2096050dfb51416deed1a1abce7 [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"
[email protected]d8c660432011-12-22 20:51:2514#include "content/common/content_export.h"
[email protected]71fde352011-12-29 03:29:5615#include "content/public/browser/navigation_controller.h"
toyoshim0df1d3a2016-09-09 09:52:4816#include "content/public/browser/reload_type.h"
Francois Dorayfe4a1772018-02-17 04:17:0917#include "content/public/browser/visibility.h"
[email protected]37567b432014-02-12 01:12:2218#include "content/public/common/frame_navigate_params.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:5619#include "content/public/common/resource_load_info.mojom-forward.h"
jam91dd24e2016-08-12 17:16:4220#include "content/public/common/resource_type.h"
[email protected]c47317e2012-06-20 22:35:3121#include "ipc/ipc_listener.h"
Ben Goodger9e24929e2017-07-21 03:13:4022#include "mojo/public/cpp/system/message_pipe.h"
23#include "services/service_manager/public/cpp/bind_source_info.h"
Blink Reformata30d4232018-04-07 15:31:0624#include "third_party/blink/public/platform/web_input_event.h"
[email protected]e7104762014-06-20 19:17:2525#include "third_party/skia/include/core/SkColor.h"
Sylvain Defresnec6ccc77d2014-09-19 10:19:3526#include "ui/base/page_transition_types.h"
[email protected]f47621b2013-01-22 20:50:3327#include "ui/base/window_open_disposition.h"
[email protected]d8c660432011-12-22 20:51:2528
Becca Hughes6fe54e432018-06-09 04:18:5629namespace blink {
30namespace mojom {
31enum class ViewportFit;
32} // namespace mojom
33} // namespace blink
34
peconn257951522017-06-09 18:24:5935namespace gfx {
36class Size;
37} // namespace gfx
38
[email protected]d8c660432011-12-22 20:51:2539namespace content {
40
[email protected]1ef02d242013-10-07 16:18:5341class NavigationEntry;
clamy0e119882015-07-31 16:12:3342class NavigationHandle;
[email protected]b849847b2013-12-10 21:57:5843class RenderFrameHost;
Avi Drissmanb3d355f2018-01-29 20:08:1844class RenderProcessHost;
[email protected]eaabba22012-03-07 15:02:1145class RenderViewHost;
afakhry98241832016-03-11 19:27:4746class RenderWidgetHost;
[email protected]26b5e322011-12-23 01:36:4747class WebContents;
[email protected]8ff00d72012-10-23 19:12:2148class WebContentsImpl;
[email protected]31a71eaf2014-03-13 01:47:3649struct AXEventNotificationDetails;
dmazzoni2400c462016-08-23 15:07:1350struct AXLocationChangeNotificationDetails;
Sam McNally5c087a32017-08-25 01:46:1451struct EntryChangedDetails;
[email protected]795c28972012-12-06 06:13:3952struct FaviconURL;
Jeff Fisher709b4c52019-07-29 20:07:3453struct FocusedNodeDetails;
[email protected]71fde352011-12-29 03:29:5654struct LoadCommittedDetails;
Mounir Lamouri0f5bdf52019-04-04 16:32:3555struct MediaPlayerId;
Sam McNally5c087a32017-08-25 01:46:1456struct PrunedDetails;
[email protected]d8c660432011-12-22 20:51:2557struct Referrer;
[email protected]d8c660432011-12-22 20:51:2558
59// An observer API implemented by classes which are interested in various page
[email protected]b172aee2012-04-10 17:05:2660// load events from WebContents. They also get a chance to filter IPC messages.
[email protected]87eca182013-01-31 21:20:0061//
[email protected]d16609c2013-08-23 06:01:4062// Since a WebContents can be a delegate to almost arbitrarily many
[email protected]87eca182013-01-31 21:20:0063// RenderViewHosts, it is important to check in those WebContentsObserver
64// methods which take a RenderViewHost that the event came from the
65// RenderViewHost the observer cares about.
66//
67// Usually, observers should only care about the current RenderViewHost as
68// returned by GetRenderViewHost().
69//
70// TODO(creis, jochen): Hide the fact that there are several RenderViewHosts
71// from the WebContentsObserver API. http://crbug.com/173325
Lukasz Anforowiczf4357ca2017-09-07 01:43:3272class CONTENT_EXPORT WebContentsObserver : public IPC::Listener {
[email protected]d8c660432011-12-22 20:51:2573 public:
aviee9b7372016-06-28 20:34:4374 // Frames and Views ----------------------------------------------------------
75
nasko005282522015-01-22 02:30:0276 // Called when a RenderFrame for |render_frame_host| is created in the
77 // renderer process. Use |RenderFrameDeleted| to listen for when this
78 // RenderFrame goes away.
[email protected]b849847b2013-12-10 21:57:5879 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) {}
80
nasko005282522015-01-22 02:30:0281 // Called when a RenderFrame for |render_frame_host| is deleted or the
82 // renderer process in which it runs it has died. Use |RenderFrameCreated| to
83 // listen for when RenderFrame objects are created.
[email protected]b849847b2013-12-10 21:57:5884 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) {}
85
nasko005282522015-01-22 02:30:0286 // This method is invoked whenever one of the current frames of a WebContents
87 // swaps its RenderFrameHost with another one; for example because that frame
88 // navigated and the new content is in a different process. The
89 // RenderFrameHost that has been replaced is in |old_host|, which can be
90 // nullptr if the old RenderFrameHost was shut down or a new frame has been
91 // created and no old RenderFrameHost exists.
92 //
93 // This method, in combination with |FrameDeleted|, is appropriate for
94 // observers wishing to track the set of current RenderFrameHosts -- i.e.,
Lei Zhangebcc6302018-01-12 19:46:4595 // those hosts that would be visited by calling WebContents::ForEachFrame().
nasko005282522015-01-22 02:30:0296 virtual void RenderFrameHostChanged(RenderFrameHost* old_host,
97 RenderFrameHost* new_host) {}
98
99 // This method is invoked when a subframe associated with a WebContents is
100 // deleted or the WebContents is destroyed and the top-level frame is deleted.
101 // Use |RenderFrameHostChanged| to listen for when a RenderFrameHost object is
102 // made the current host for a frame.
103 virtual void FrameDeleted(RenderFrameHost* render_frame_host) {}
104
[email protected]a86c0e962013-12-17 17:10:39105 // This is called when a RVH is created for a WebContents, but not if it's an
106 // interstitial.
[email protected]d8c660432011-12-22 20:51:25107 virtual void RenderViewCreated(RenderViewHost* render_view_host) {}
[email protected]a86c0e962013-12-17 17:10:39108
109 // Called for every RenderFrameHost that's created for an interstitial.
110 virtual void RenderFrameForInterstitialPageCreated(
111 RenderFrameHost* render_frame_host) {}
[email protected]87eca182013-01-31 21:20:00112
113 // This method is invoked when the RenderView of the current RenderViewHost
114 // is ready, e.g. because we recreated it after a crash.
[email protected]d8c660432011-12-22 20:51:25115 virtual void RenderViewReady() {}
[email protected]87eca182013-01-31 21:20:00116
117 // This method is invoked when a RenderViewHost of the WebContents is
118 // deleted. Note that this does not always happen when the WebContents starts
119 // to use a different RenderViewHost, as the old RenderViewHost might get
120 // just swapped out.
121 virtual void RenderViewDeleted(RenderViewHost* render_view_host) {}
122
avi33601202015-07-11 01:39:26123 // This method is invoked when the process for the current main
124 // RenderFrameHost exits (usually by crashing, though possibly by other
125 // means). The WebContents continues to use the RenderFrameHost, e.g. when the
126 // user reloads the current page. When the RenderFrameHost itself is deleted,
127 // the RenderFrameDeleted method will be invoked.
[email protected]4d614412014-01-10 08:29:37128 //
avi33601202015-07-11 01:39:26129 // Note that this is triggered upstream through
130 // RenderProcessHostObserver::RenderProcessExited(); for code that doesn't
131 // otherwise need to be a WebContentsObserver, that API is probably a better
132 // choice.
[email protected]58d5cfe2013-07-10 02:40:52133 virtual void RenderProcessGone(base::TerminationStatus status) {}
[email protected]87eca182013-01-31 21:20:00134
[email protected]02d7b6e2014-06-24 21:01:50135 // This method is invoked when a WebContents swaps its visible RenderViewHost
136 // with another one, possibly changing processes. The RenderViewHost that has
mlamouri8c61ffc2015-01-13 16:17:59137 // been replaced is in |old_host|, which is nullptr if the old RVH was shut
138 // down.
[email protected]7b712ee22013-10-03 00:57:28139 virtual void RenderViewHostChanged(RenderViewHost* old_host,
140 RenderViewHost* new_host) {}
[email protected]da7a7182013-09-06 08:11:11141
Avi Drissmanb3d355f2018-01-29 20:08:18142 // This method is invoked when a process in the WebContents becomes
143 // unresponsive.
144 virtual void OnRendererUnresponsive(RenderProcessHost* render_process_host) {}
afakhry98241832016-03-11 19:27:47145
aviee9b7372016-06-28 20:34:43146 // Navigation ----------------------------------------------------------------
clamy0e119882015-07-31 16:12:33147
148 // Called when a navigation started in the WebContents. |navigation_handle|
149 // is unique to a specific navigation. The same |navigation_handle| will be
nasko14baf392016-02-02 02:15:38150 // provided on subsequent calls to DidRedirectNavigation, DidFinishNavigation,
151 // and ReadyToCommitNavigation when related to this navigation. Observers
152 // should clear any references to |navigation_handle| in DidFinishNavigation,
153 // just before it is destroyed.
clamy0e119882015-07-31 16:12:33154 //
155 // Note that this is fired by navigations in any frame of the WebContents,
156 // not just the main frame.
157 //
eugenebuta11672fb2017-03-07 17:13:51158 // Note that this is fired by same-document navigations, such as fragment
clamy57f99bd22016-11-30 18:25:11159 // navigations or pushState/replaceState, which will not result in a document
eugenebuta11672fb2017-03-07 17:13:51160 // change. To filter these out, use NavigationHandle::IsSameDocument.
clamy57f99bd22016-11-30 18:25:11161 //
clamy0e119882015-07-31 16:12:33162 // Note that more than one navigation can be ongoing in the same frame at the
163 // same time (including the main frame). Each will get its own
164 // NavigationHandle.
165 //
166 // Note that there is no guarantee that DidFinishNavigation will be called
167 // for any particular navigation before DidStartNavigation is called on the
168 // next.
169 virtual void DidStartNavigation(NavigationHandle* navigation_handle) {}
170
171 // Called when a navigation encountered a server redirect.
172 virtual void DidRedirectNavigation(NavigationHandle* navigation_handle) {}
173
clamyb876f0a72015-09-24 20:01:05174 // Called when the navigation is ready to be committed in a renderer. Most
175 // observers should use DidFinishNavigation instead, which happens right
176 // after the navigation commits. This method is for observers that want to
177 // initialize renderer-side state just before the RenderFrame commits the
178 // navigation.
179 //
clamyb876f0a72015-09-24 20:01:05180 // This is the first point in time where a RenderFrameHost is associated with
181 // the navigation.
clamyefca29e2015-09-17 00:22:11182 virtual void ReadyToCommitNavigation(NavigationHandle* navigation_handle) {}
183
clamyb876f0a72015-09-24 20:01:05184 // Called when a navigation finished in the WebContents. This happens when a
185 // navigation is committed, aborted or replaced by a new one. To know if the
vabrd9092d32016-03-16 19:03:32186 // navigation has committed, use NavigationHandle::HasCommitted; use
clamyb876f0a72015-09-24 20:01:05187 // NavigationHandle::IsErrorPage to know if the navigation resulted in an
188 // error page.
189 //
190 // If this is called because the navigation committed, then the document load
191 // will still be ongoing in the RenderFrameHost returned by
192 // |navigation_handle|. Use the document loads events such as DidStopLoading
193 // and related methods to listen for continued events from this
194 // RenderFrameHost.
195 //
eugenebuta11672fb2017-03-07 17:13:51196 // Note that this is fired by same-document navigations, such as fragment
clamy57f99bd22016-11-30 18:25:11197 // navigations or pushState/replaceState, which will not result in a document
eugenebuta11672fb2017-03-07 17:13:51198 // change. To filter these out, use NavigationHandle::IsSameDocument.
clamy57f99bd22016-11-30 18:25:11199 //
clamyb876f0a72015-09-24 20:01:05200 // Note that |navigation_handle| will be destroyed at the end of this call,
201 // so do not keep a reference to it afterward.
clamy0e119882015-07-31 16:12:33202 virtual void DidFinishNavigation(NavigationHandle* navigation_handle) {}
203
aviee9b7372016-06-28 20:34:43204 // Navigation (obsolete and deprecated) --------------------------------------
205
206 // This method is invoked after the browser process starts a navigation to a
207 // pending NavigationEntry. It is not called for renderer-initiated
208 // navigations unless they are sent to the browser process via OpenURL. It may
209 // be called multiple times for a given navigation, such as a typed URL
210 // followed by a cross-process client or server redirect.
211 //
Arthur Hemery0dd65812019-08-01 14:18:45212 // SOON TO BE DEPRECATED. Use DidStartNavigation instead.
213 // TODO(clamy): Remove this function.
toyoshim0df1d3a2016-09-09 09:52:48214 virtual void DidStartNavigationToPendingEntry(const GURL& url,
215 ReloadType reload_type) {}
aviee9b7372016-06-28 20:34:43216
clamyb876f0a72015-09-24 20:01:05217 // Document load events ------------------------------------------------------
218
Chris Hamiltonf82f2a702018-02-15 19:37:29219 // These three methods correspond to the points in time when a document starts
220 // loading for the first time (initiates outgoing requests), when incoming
221 // data subsequently starts arriving, and when it finishes loading.
clamyb876f0a72015-09-24 20:01:05222 virtual void DidStartLoading() {}
Chris Hamiltonf82f2a702018-02-15 19:37:29223 virtual void DidReceiveResponse() {}
clamyb876f0a72015-09-24 20:01:05224 virtual void DidStopLoading() {}
225
226 // This method is invoked once the window.document object of the main frame
227 // was created.
228 virtual void DocumentAvailableInMainFrame() {}
229
230 // This method is invoked once the onload handler of the main frame has
231 // completed.
232 virtual void DocumentOnLoadCompletedInMainFrame() {}
233
234 // This method is invoked when the document in the given frame finished
235 // loading. At this point, scripts marked as defer were executed, and
236 // content scripts marked "document_end" get injected into the frame.
237 virtual void DocumentLoadedInFrame(RenderFrameHost* render_frame_host) {}
238
aviee9b7372016-06-28 20:34:43239 // This method is invoked when the load is done, i.e. the spinner of the tab
240 // will stop spinning, and the onload event was dispatched.
clamyb876f0a72015-09-24 20:01:05241 //
242 // If the WebContents is displaying replacement content, e.g. network error
243 // pages, DidFinishLoad is invoked for frames that were not sending
244 // navigational events before. It is safe to ignore these events.
245 virtual void DidFinishLoad(RenderFrameHost* render_frame_host,
246 const GURL& validated_url) {}
247
248 // This method is like DidFinishLoad, but when the load failed or was
249 // cancelled, e.g. window.stop() is invoked.
250 virtual void DidFailLoad(RenderFrameHost* render_frame_host,
251 const GURL& validated_url,
252 int error_code,
Yutaka Hirano16d3c5d2017-07-31 06:17:30253 const base::string16& error_description) {}
clamyb876f0a72015-09-24 20:01:05254
cjgrant6d1d727a2016-12-09 21:16:57255 // This method is invoked when the visible security state of the page changes.
256 virtual void DidChangeVisibleSecurityState() {}
lgarron662dd522015-06-08 23:20:01257
[email protected]b0f724c2013-09-05 04:21:13258 // This method is invoked when content was loaded from an in-memory cache.
259 virtual void DidLoadResourceFromMemoryCache(
jam91dd24e2016-08-12 17:16:42260 const GURL& url,
261 const std::string& mime_type,
262 ResourceType resource_type) {}
[email protected]b0f724c2013-09-05 04:21:13263
Jay Civelli718fd6c02018-05-11 21:04:27264 // This method is invoked when a resource associate with the frame
Clark DuVall36164bd2018-08-09 22:49:08265 // |render_frame_host| has been loaded, successfully or not. |request_id| will
266 // only be populated for main frame resources.
Jay Civelli116683f2018-03-27 19:56:23267 virtual void ResourceLoadComplete(
Jay Civelli718fd6c02018-05-11 21:04:27268 RenderFrameHost* render_frame_host,
Clark DuVall36164bd2018-08-09 22:49:08269 const GlobalRequestID& request_id,
Jay Civelli718fd6c02018-05-11 21:04:27270 const mojom::ResourceLoadInfo& resource_load_info) {}
[email protected]b0f724c2013-09-05 04:21:13271
Josh Karlindaba39322019-07-17 23:24:33272 // This method is invoked when a document or resource reads a cookie. Note
273 // that this isn't tied to any particular navigation (e.g., it may be called
274 // after a subsequent navigation commits).
275 virtual void OnCookiesRead(const GURL& url,
276 const GURL& first_party_url,
277 const net::CookieList& cookie_list,
278 bool blocked_by_policy) {}
279
280 // This method is invoked when an attempt has been made to set |cookie|. Note
281 // that this isn't tied to any particular navigation (e.g., it may be called
282 // after a subsequent navigation commits).
283 virtual void OnCookieChange(const GURL& url,
284 const GURL& first_party_url,
285 const net::CanonicalCookie& cookie,
286 bool blocked_by_policy) {}
287
[email protected]cbb1ef592013-06-05 19:49:46288 // This method is invoked when a new non-pending navigation entry is created.
289 // This corresponds to one NavigationController entry being created
290 // (in the case of new navigations) or renavigated to (for back/forward
291 // navigations).
292 virtual void NavigationEntryCommitted(
293 const LoadCommittedDetails& load_details) {}
294
Sam McNally5c087a32017-08-25 01:46:14295 // Invoked when the NavigationController decreased its back/forward list count
296 // by removing entries from either the front or back of its list. This is
297 // usually the result of going back and then doing a new navigation, meaning
298 // all the "forward" items are deleted.
299 //
300 // This normally happens as a result of a new navigation. It will be
301 // followed by a NavigationEntryCommitted() call for the new page that
302 // caused the pruning. It could also be a result of removing an item from
Christian Dullweberb13ffda2018-02-23 11:42:14303 // the list to delete history or fix up after interstitials.
Sam McNally5c087a32017-08-25 01:46:14304 virtual void NavigationListPruned(const PrunedDetails& pruned_details) {}
305
Christian Dullweber1af31e62018-02-22 11:49:48306 // Invoked when NavigationEntries have been deleted because of a history
307 // deletion. Observers should ensure that they remove all traces of the
308 // deleted entries.
309 virtual void NavigationEntriesDeleted() {}
310
Sam McNally5c087a32017-08-25 01:46:14311 // Invoked when a NavigationEntry has changed.
312 //
313 // This will NOT be sent on navigation, interested parties should also
314 // implement NavigationEntryCommitted() to handle that case. This will be
315 // sent when the entry is updated outside of navigation (like when a new
316 // title comes).
317 virtual void NavigationEntryChanged(
318 const EntryChangedDetails& change_details) {}
319
[email protected]87eca182013-01-31 21:20:00320 // This method is invoked when a new WebContents was created in response to
321 // an action in the observed WebContents, e.g. a link with target=_blank was
creis114ca1b2014-11-13 23:51:46322 // clicked. The |source_render_frame_host| is the frame in which the action
323 // took place.
[email protected]26b5e322011-12-23 01:36:47324 virtual void DidOpenRequestedURL(WebContents* new_contents,
creis114ca1b2014-11-13 23:51:46325 RenderFrameHost* source_render_frame_host,
[email protected]d8c660432011-12-22 20:51:25326 const GURL& url,
327 const Referrer& referrer,
328 WindowOpenDisposition disposition,
pnoland488944652017-02-22 18:58:54329 ui::PageTransition transition,
pnolandaae574e2017-03-06 21:04:21330 bool started_from_context_menu,
331 bool renderer_initiated) {}
[email protected]d8c660432011-12-22 20:51:25332
nasko005282522015-01-22 02:30:02333 // This method is invoked when the renderer process has completed its first
334 // paint after a non-empty layout.
[email protected]50279492014-05-05 23:24:29335 virtual void DidFirstVisuallyNonEmptyPaint() {}
[email protected]9f268072013-11-07 00:02:15336
[email protected]d16609c2013-08-23 06:01:40337 // When WebContents::Stop() is called, the WebContents stops loading and then
338 // invokes this method. If there are ongoing navigations, their respective
339 // failure methods will also be invoked.
340 virtual void NavigationStopped() {}
[email protected]87eca182013-01-31 21:20:00341
Robert Ogden34e97962018-09-14 23:50:27342 // This method is invoked when the WebContents reloads all the LoFi images in
343 // the frame. LoFi is a type of Preview where Chrome shows gray boxes in place
344 // of the images on a webpage in order to conserve data for data-sensitive
345 // users. See http://bit.ly/LoFiPublicDoc.
346 virtual void DidReloadLoFiImages() {}
347
dominickn2dd142dd2015-10-29 05:30:50348 // Called when there has been direct user interaction with the WebContents.
dominicknad9c99d2015-11-06 01:52:49349 // The type argument specifies the kind of interaction. Direct user input
350 // signalled through this callback includes:
351 // 1) any mouse down event (blink::WebInputEvent::MouseDown);
dominickn5cc29a42016-03-25 03:06:22352 // 2) the start of a scroll (blink::WebInputEvent::GestureScrollBegin);
Dominick Ng37a15052018-07-17 23:56:35353 // 3) any raw key down event (blink::WebInputEvent::RawKeyDown); and
354 // 4) any touch event (inc. scrolls) (blink::WebInputEvent::TouchStart).
dominickn2dd142dd2015-10-29 05:30:50355 virtual void DidGetUserInteraction(const blink::WebInputEvent::Type type) {}
356
[email protected]87eca182013-01-31 21:20:00357 // This method is invoked when a RenderViewHost of this WebContents was
358 // configured to ignore UI events, and an UI event took place.
359 virtual void DidGetIgnoredUIEvent() {}
360
Francois Dorayfe4a1772018-02-17 04:17:09361 // Invoked every time the WebContents changes visibility.
362 virtual void OnVisibilityChanged(Visibility visibility) {}
[email protected]3e324142012-06-25 18:26:33363
estaded0a0c992015-01-21 14:12:06364 // Invoked when the main frame changes size.
rouslan2f5993f2015-01-29 00:18:31365 virtual void MainFrameWasResized(bool width_changed) {}
estaded0a0c992015-01-21 14:12:06366
alexmosbe2f4c32015-03-10 02:30:23367 // Invoked when the given frame changes its window.name property.
368 virtual void FrameNameChanged(RenderFrameHost* render_frame_host,
369 const std::string& name) {}
370
John Delaneyedd8d6c2019-01-25 00:23:57371 // Called when the sticky user activation bit has been set on the frame.
372 // This will not be called for new RenderFrameHosts whose underlying
373 // FrameTreeNode was already activated. This should not be used to determine a
374 // RenderFrameHost's user activation state.
375 virtual void FrameReceivedFirstUserActivation(
376 RenderFrameHost* render_frame_host) {}
377
John Delaney0146a742019-01-25 19:25:28378 // Invoked when the display state of the frame changes.
379 virtual void FrameDisplayStateChanged(RenderFrameHost* render_frame_host,
380 bool is_display_none) {}
381
382 // Invoked when a frame changes size.
383 virtual void FrameSizeChanged(RenderFrameHost* render_frame_host,
384 const gfx::Size& frame_size) {}
385
Avi Drissmana2ca5b142017-11-14 21:10:47386 // This method is invoked when the title of the WebContents is set. Note that
387 // |entry| may be null if the web page whose title changed has not yet had a
388 // NavigationEntry assigned to it.
Avi Drissman93002212017-09-27 03:20:52389 virtual void TitleWasSet(NavigationEntry* entry) {}
[email protected]66798902013-10-01 18:40:16390
[email protected]d8c660432011-12-22 20:51:25391 virtual void AppCacheAccessed(const GURL& manifest_url,
392 bool blocked_by_policy) {}
393
emaxxe70f5e12015-05-29 11:26:00394 // These methods are invoked when a Pepper plugin instance is created/deleted
395 // in the DOM.
396 virtual void PepperInstanceCreated() {}
397 virtual void PepperInstanceDeleted() {}
398
Becca Hughes6fe54e432018-06-09 04:18:56399 // This method is called when the viewport fit of a WebContents changes.
400 virtual void ViewportFitChanged(blink::mojom::ViewportFit value) {}
401
[email protected]3fc07c52012-04-20 00:27:44402 // Notification that a plugin has crashed.
[email protected]cf4d6e742013-01-10 14:06:42403 // |plugin_pid| is the process ID identifying the plugin process. Note that
nasko005282522015-01-22 02:30:02404 // this ID is supplied by the renderer process, so should not be trusted.
405 // Besides, the corresponding process has probably died at this point. The ID
406 // may even have been reused by a new process.
[email protected]c42de732013-02-16 06:26:31407 virtual void PluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:42408 base::ProcessId plugin_pid) {}
[email protected]3fc07c52012-04-20 00:27:44409
[email protected]d16609c2013-08-23 06:01:40410 // Notification that the given plugin has hung or become unhung. This
[email protected]3fc07c52012-04-20 00:27:44411 // notification is only for Pepper plugins.
412 //
413 // The plugin_child_id is the unique child process ID from the plugin. Note
nasko005282522015-01-22 02:30:02414 // that this ID is supplied by the renderer process, so should be validated
415 // before it's used for anything in case there's an exploited renderer
416 // process.
[email protected]3fc07c52012-04-20 00:27:44417 virtual void PluginHungStatusChanged(int plugin_child_id,
[email protected]c42de732013-02-16 06:26:31418 const base::FilePath& plugin_path,
[email protected]3fc07c52012-04-20 00:27:44419 bool is_hung) {}
420
Sean Toppingbbc4a2bd2019-01-30 02:16:14421 // Notifies that an inner WebContents instance has been created with the
422 // observed WebContents as its container. |inner_web_contents| has not been
423 // added to the WebContents tree at this point, but can be observed safely.
424 virtual void InnerWebContentsCreated(WebContents* inner_web_contents) {}
425
[email protected]7381d9f2012-09-12 20:26:22426 // Invoked when WebContents::Clone() was used to clone a WebContents.
427 virtual void DidCloneToNewWebContents(WebContents* old_web_contents,
428 WebContents* new_web_contents) {}
429
[email protected]26b5e322011-12-23 01:36:47430 // Invoked when the WebContents is being destroyed. Gives subclasses a chance
[email protected]12a46832014-05-09 13:35:58431 // to cleanup. After the whole loop over all WebContentsObservers has been
mlamouri8c61ffc2015-01-13 16:17:59432 // finished, web_contents() returns nullptr.
[email protected]12a46832014-05-09 13:35:58433 virtual void WebContentsDestroyed() {}
[email protected]d8c660432011-12-22 20:51:25434
[email protected]8d0f3312012-08-18 01:47:53435 // Called when the user agent override for a WebContents has been changed.
436 virtual void UserAgentOverrideSet(const std::string& user_agent) {}
437
nasko005282522015-01-22 02:30:02438 // Invoked when new FaviconURL candidates are received from the renderer
439 // process.
[email protected]50279492014-05-05 23:24:29440 virtual void DidUpdateFaviconURL(const std::vector<FaviconURL>& candidates) {}
[email protected]795c28972012-12-06 06:13:39441
Chris Hamiltoneb41198f2018-05-24 18:41:26442 // Called when an audio change occurs.
443 virtual void OnAudioStateChanged(bool audible) {}
444
wjmaclean2f797c782016-01-07 14:52:03445 // Invoked when the WebContents is muted/unmuted.
446 virtual void DidUpdateAudioMutingState(bool muted) {}
447
[email protected]44470a22013-01-24 01:21:54448 // Invoked when a pepper plugin creates and shows or destroys a fullscreen
nasko005282522015-01-22 02:30:02449 // RenderWidget.
alexmos899e06f2016-05-13 23:08:09450 virtual void DidShowFullscreenWidget() {}
451 virtual void DidDestroyFullscreenWidget() {}
[email protected]44470a22013-01-24 01:21:54452
nasko005282522015-01-22 02:30:02453 // Invoked when the renderer process has toggled the tab into/out of
454 // fullscreen mode.
bokanece34a82016-01-28 19:49:46455 virtual void DidToggleFullscreenModeForTab(bool entered_fullscreen,
456 bool will_cause_resize) {}
[email protected]657c8e02014-03-19 19:18:37457
Becca Hughesfd5d8f892018-06-14 18:23:36458 // Signals that |rfh| has the current fullscreen element. This is invoked
459 // when:
460 // 1) an element in this frame enters fullscreen or in nested fullscreen, or
461 // 2) after an element in a descendant frame exits fullscreen and makes
462 // this frame own the current fullscreen element again.
463 virtual void DidAcquireFullscreen(RenderFrameHost* rfh) {}
464
[email protected]20ca0382013-02-28 19:50:07465 // Invoked when an interstitial page is attached or detached.
466 virtual void DidAttachInterstitialPage() {}
467 virtual void DidDetachInterstitialPage() {}
468
[email protected]17e286e2013-03-01 23:29:39469 // Invoked before a form repost warning is shown.
470 virtual void BeforeFormRepostWarningShow() {}
471
Chris Hamilton3b3e315d2018-09-19 13:16:21472 // Invoked when the beforeunload handler fires. |proceed| is set to true if
473 // the beforeunload can safely proceed, otherwise it should be interrupted.
474 // The time is from the renderer process.
475 virtual void BeforeUnloadFired(bool proceed,
476 const base::TimeTicks& proceed_time) {}
[email protected]6d65a462013-06-21 21:29:12477
478 // Invoked when a user cancels a before unload dialog.
479 virtual void BeforeUnloadDialogCancelled() {}
480
dmazzonidd3d51a72016-12-14 18:41:01481 // Called when accessibility events or location changes are received
482 // from a render frame, but only when the accessibility mode has the
Doug Turner63f3c7b2017-07-29 05:10:01483 // ui::AXMode::kWebContents flag set.
Dominic Mazzonia7b0edb22017-08-09 16:32:51484 virtual void AccessibilityEventReceived(
Dominic Mazzoniccbaa9b2018-06-06 07:44:23485 const AXEventNotificationDetails& details) {}
dmazzoni2400c462016-08-23 15:07:13486 virtual void AccessibilityLocationChangesReceived(
487 const std::vector<AXLocationChangeNotificationDetails>& details) {}
488
[email protected]37b64c52014-07-11 21:14:05489 // Invoked when theme color is changed to |theme_color|.
Alan Cutter92d59252019-03-29 02:32:33490 virtual void DidChangeThemeColor(base::Optional<SkColor> theme_color) {}
[email protected]e7104762014-06-20 19:17:25491
dalecurtis88c240072015-12-09 02:11:18492 // Invoked when media is playing or paused. |id| is unique per player and per
493 // RenderFrameHost. There may be multiple players within a RenderFrameHost
494 // and subsequently within a WebContents. MediaStartedPlaying() will always
495 // be followed by MediaStoppedPlaying() after player teardown. Observers must
496 // release all stored copies of |id| when MediaStoppedPlaying() is received.
Mounir Lamouri366dd8472018-06-19 17:20:04497 // |has_video| and |has_audio| can both be false in cases where the media
498 // is playing muted and should be considered as inaudible for all intent and
499 // purposes.
billorr21c005d2016-11-17 03:57:04500 struct MediaPlayerInfo {
Becca Hughes3f921362017-06-08 14:08:36501 MediaPlayerInfo(bool has_video, bool has_audio)
502 : has_video(has_video), has_audio(has_audio) {}
billorr21c005d2016-11-17 03:57:04503 bool has_video;
Becca Hughes3f921362017-06-08 14:08:36504 bool has_audio;
billorr21c005d2016-11-17 03:57:04505 };
François Beaufortddaf8a82018-07-16 16:43:12506
billorr21c005d2016-11-17 03:57:04507 virtual void MediaStartedPlaying(const MediaPlayerInfo& video_type,
508 const MediaPlayerId& id) {}
Becca Hughes220bfc102017-11-14 18:24:07509 enum class MediaStoppedReason {
510 // The media was stopped for an unspecified reason.
511 kUnspecified,
512
513 // The media was stopped because it reached the end of the stream.
514 kReachedEndOfStream,
515 };
516 virtual void MediaStoppedPlaying(
517 const MediaPlayerInfo& video_type,
518 const MediaPlayerId& id,
519 WebContentsObserver::MediaStoppedReason reason) {}
peconn257951522017-06-09 18:24:59520 virtual void MediaResized(const gfx::Size& size, const MediaPlayerId& id) {}
Peter E Conneccb34c22017-09-08 09:37:58521 // Invoked when media enters or exits fullscreen. We must use a heuristic
522 // to determine this as it is not trivial for media with custom controls.
523 // There is a slight delay between media entering or exiting fullscreen
524 // and it being detected.
525 virtual void MediaEffectivelyFullscreenChanged(bool is_fullscreen) {}
François Beauforta2f0a3ca2018-08-28 12:46:11526 virtual void MediaPictureInPictureChanged(bool is_picture_in_picture) {}
Becca Hughes9f6fd4b82017-06-15 10:01:40527 virtual void MediaMutedStatusChanged(const MediaPlayerId& id, bool muted) {}
prashantv0c9b968d22015-03-26 00:58:54528
mcnee432e47d2015-11-09 19:37:46529 // Invoked when the renderer process changes the page scale factor.
530 virtual void OnPageScaleFactorChanged(float page_scale_factor) {}
531
Archana Simhaf67090c2019-05-06 23:43:23532 // Invoked when a paste event occurs.
533 virtual void OnPaste() {}
534
[email protected]64ffefa2014-05-10 12:06:33535 // Invoked if an IPC message is coming from a specific RenderFrameHost.
536 virtual bool OnMessageReceived(const IPC::Message& message,
537 RenderFrameHost* render_frame_host);
538
Michael Thiessen896405db2017-07-20 17:52:32539 // Notification that the |render_widget_host| for this WebContents has gained
540 // focus.
541 virtual void OnWebContentsFocused(RenderWidgetHost* render_widget_host) {}
calamity7fe55ce2015-04-10 03:59:37542
Michael Thiessen896405db2017-07-20 17:52:32543 // Notification that the |render_widget_host| for this WebContents has lost
544 // focus.
545 virtual void OnWebContentsLostFocus(RenderWidgetHost* render_widget_host) {}
zijiehe3bee08e22017-05-17 04:14:46546
Jeff Fisher709b4c52019-07-29 20:07:34547 // Notification that a RenderFrameHost inside this WebContents has updated
548 // its focused element. |details| contains information on the element
549 // that has received focus. This allows for observing focus changes
550 // within WebContents, as opposed to OnWebContentsFocused/LostFocus
551 // which allows observation that the RenderWidgetHost for the
552 // WebContents has gained/lost focus.
553 virtual void OnFocusChangedInPage(FocusedNodeDetails* details) {}
554
Sam McNally145fb172017-05-10 00:13:23555 // Notifies that the manifest URL for the main frame changed to
556 // |manifest_url|. This will be invoked when a document with a manifest loads
557 // or when the manifest URL changes (possibly to nothing). It is not invoked
558 // when a document with no manifest loads. During document load, if the
559 // document has both a manifest and a favicon, DidUpdateWebManifestURL() will
560 // be invoked before DidUpdateFaviconURL().
561 virtual void DidUpdateWebManifestURL(
562 const base::Optional<GURL>& manifest_url) {}
563
Ben Goodger9e24929e2017-07-21 03:13:40564 // Called to give the embedder an opportunity to bind an interface request
565 // from a frame. If the request can be bound, |interface_pipe| will be taken.
566 virtual void OnInterfaceRequestFromFrame(
567 RenderFrameHost* render_frame_host,
568 const std::string& interface_name,
569 mojo::ScopedMessagePipeHandle* interface_pipe) {}
570
Yiming Zhoudd60b0b2018-07-20 18:51:35571 // Notifies that the RenderWidgetCompositor has issued a draw command. An
572 // observer can use this method to detect when Chrome visually updated a
573 // tab.
574 virtual void DidCommitAndDrawCompositorFrame() {}
575
Raymond Toye413650c2018-08-31 00:12:47576 // Called when "audible" playback starts or stops on a WebAudio AudioContext.
577 using AudioContextId = std::pair<RenderFrameHost*, int>;
578 virtual void AudioContextPlaybackStarted(
579 const AudioContextId& audio_context_id) {}
580 virtual void AudioContextPlaybackStopped(
581 const AudioContextId& audio_context_id) {}
582
[email protected]c47317e2012-06-20 22:35:31583 // IPC::Listener implementation.
Lukasz Anforowiczcf0a94a2017-08-31 19:10:09584 // DEPRECATED: Use (i.e. override) the other overload instead:
585 // virtual bool OnMessageReceived(const IPC::Message& message,
586 // RenderFrameHost* render_frame_host);
587 // TODO(https://crbug.com/758026): Delete this overload when possible.
dchenge933b3e2014-10-21 11:44:09588 bool OnMessageReceived(const IPC::Message& message) override;
[email protected]d8c660432011-12-22 20:51:25589
lucinka.brozkovac25f7fb92014-09-04 06:42:56590 WebContents* web_contents() const;
591
[email protected]d8c660432011-12-22 20:51:25592 protected:
[email protected]26b5e322011-12-23 01:36:47593 // Use this constructor when the object is tied to a single WebContents for
[email protected]d8c660432011-12-22 20:51:25594 // its entire lifetime.
[email protected]26b5e322011-12-23 01:36:47595 explicit WebContentsObserver(WebContents* web_contents);
[email protected]d8c660432011-12-22 20:51:25596
[email protected]b172aee2012-04-10 17:05:26597 // Use this constructor when the object wants to observe a WebContents for
[email protected]d8c660432011-12-22 20:51:25598 // part of its lifetime. It can then call Observe() to start and stop
599 // observing.
600 WebContentsObserver();
601
dchenge933b3e2014-10-21 11:44:09602 ~WebContentsObserver() override;
[email protected]d8c660432011-12-22 20:51:25603
[email protected]26b5e322011-12-23 01:36:47604 // Start observing a different WebContents; used with the default constructor.
605 void Observe(WebContents* web_contents);
[email protected]d8c660432011-12-22 20:51:25606
[email protected]d8c660432011-12-22 20:51:25607 private:
[email protected]8ff00d72012-10-23 19:12:21608 friend class WebContentsImpl;
[email protected]d8c660432011-12-22 20:51:25609
[email protected]12a46832014-05-09 13:35:58610 void ResetWebContents();
[email protected]d8c660432011-12-22 20:51:25611
[email protected]b172aee2012-04-10 17:05:26612 WebContentsImpl* web_contents_;
[email protected]d8c660432011-12-22 20:51:25613
614 DISALLOW_COPY_AND_ASSIGN(WebContentsObserver);
615};
616
617} // namespace content
618
619#endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_