1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
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
8#include <stdint.h>
9
10#include "base/macros.h"
11#include "base/optional.h"
12#include "base/process/kill.h"
13#include "base/process/process_handle.h"
14#include "content/common/content_export.h"
15#include "content/public/browser/navigation_controller.h"
16#include "content/public/browser/reload_type.h"
17#include "content/public/browser/visibility.h"
18#include "content/public/common/frame_navigate_params.h"
19#include "content/public/common/resource_load_info.mojom-forward.h"
20#include "content/public/common/resource_type.h"
21#include "ipc/ipc_listener.h"
22#include "mojo/public/cpp/system/message_pipe.h"
23#include "services/service_manager/public/cpp/bind_source_info.h"
24#include "third_party/blink/public/platform/web_input_event.h"
25#include "third_party/skia/include/core/SkColor.h"
26#include "ui/base/page_transition_types.h"
27#include "ui/base/window_open_disposition.h"
28
29namespace blink {
30namespace mojom {
31enum class ViewportFit;
32} // namespace mojom
33} // namespace blink
34
35namespace gfx {
36class Size;
37} // namespace gfx
38
39namespace content {
40
41class NavigationEntry;
42class NavigationHandle;
43class RenderFrameHost;
44class RenderProcessHost;
45class RenderViewHost;
46class RenderWidgetHost;
47class WebContents;
48class WebContentsImpl;
49struct AXEventNotificationDetails;
50struct AXLocationChangeNotificationDetails;
51struct EntryChangedDetails;
52struct FaviconURL;
53struct LoadCommittedDetails;
54struct MediaPlayerId;
55struct PrunedDetails;
56struct Referrer;
57
58// An observer API implemented by classes which are interested in various page
59// load events from WebContents. They also get a chance to filter IPC messages.
60//
61// Since a WebContents can be a delegate to almost arbitrarily many
62// RenderViewHosts, it is important to check in those WebContentsObserver
63// methods which take a RenderViewHost that the event came from the
64// RenderViewHost the observer cares about.
65//
66// Usually, observers should only care about the current RenderViewHost as
67// returned by GetRenderViewHost().
68//
69// TODO(creis, jochen): Hide the fact that there are several RenderViewHosts
70// from the WebContentsObserver API. http://crbug.com/173325
71class CONTENT_EXPORT WebContentsObserver : public IPC::Listener {
72 public:
73 // Frames and Views ----------------------------------------------------------
74
75 // Called when a RenderFrame for |render_frame_host| is created in the
76 // renderer process. Use |RenderFrameDeleted| to listen for when this
77 // RenderFrame goes away.
78 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) {}
79
80 // Called when a RenderFrame for |render_frame_host| is deleted or the
81 // renderer process in which it runs it has died. Use |RenderFrameCreated| to
82 // listen for when RenderFrame objects are created.
83 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) {}
84
85 // This method is invoked whenever one of the current frames of a WebContents
86 // swaps its RenderFrameHost with another one; for example because that frame
87 // navigated and the new content is in a different process. The
88 // RenderFrameHost that has been replaced is in |old_host|, which can be
89 // nullptr if the old RenderFrameHost was shut down or a new frame has been
90 // created and no old RenderFrameHost exists.
91 //
92 // This method, in combination with |FrameDeleted|, is appropriate for
93 // observers wishing to track the set of current RenderFrameHosts -- i.e.,
94 // those hosts that would be visited by calling WebContents::ForEachFrame().
95 virtual void RenderFrameHostChanged(RenderFrameHost* old_host,
96 RenderFrameHost* new_host) {}
97
98 // This method is invoked when a subframe associated with a WebContents is
99 // deleted or the WebContents is destroyed and the top-level frame is deleted.
100 // Use |RenderFrameHostChanged| to listen for when a RenderFrameHost object is
101 // made the current host for a frame.
102 virtual void FrameDeleted(RenderFrameHost* render_frame_host) {}
103
104 // This is called when a RVH is created for a WebContents, but not if it's an
105 // interstitial.
106 virtual void RenderViewCreated(RenderViewHost* render_view_host) {}
107
108 // Called for every RenderFrameHost that's created for an interstitial.
109 virtual void RenderFrameForInterstitialPageCreated(
110 RenderFrameHost* render_frame_host) {}
111
112 // This method is invoked when the RenderView of the current RenderViewHost
113 // is ready, e.g. because we recreated it after a crash.
114 virtual void RenderViewReady() {}
115
116 // This method is invoked when a RenderViewHost of the WebContents is
117 // deleted. Note that this does not always happen when the WebContents starts
118 // to use a different RenderViewHost, as the old RenderViewHost might get
119 // just swapped out.
120 virtual void RenderViewDeleted(RenderViewHost* render_view_host) {}
121
122 // This method is invoked when the process for the current main
123 // RenderFrameHost exits (usually by crashing, though possibly by other
124 // means). The WebContents continues to use the RenderFrameHost, e.g. when the
125 // user reloads the current page. When the RenderFrameHost itself is deleted,
126 // the RenderFrameDeleted method will be invoked.
127 //
128 // Note that this is triggered upstream through
129 // RenderProcessHostObserver::RenderProcessExited(); for code that doesn't
130 // otherwise need to be a WebContentsObserver, that API is probably a better
131 // choice.
132 virtual void RenderProcessGone(base::TerminationStatus status) {}
133
134 // This method is invoked when a WebContents swaps its visible RenderViewHost
135 // with another one, possibly changing processes. The RenderViewHost that has
136 // been replaced is in |old_host|, which is nullptr if the old RVH was shut
137 // down.
138 virtual void RenderViewHostChanged(RenderViewHost* old_host,
139 RenderViewHost* new_host) {}
140
141 // This method is invoked when a process in the WebContents becomes
142 // unresponsive.
143 virtual void OnRendererUnresponsive(RenderProcessHost* render_process_host) {}
144
145 // Navigation ----------------------------------------------------------------
146
147 // Called when a navigation started in the WebContents. |navigation_handle|
148 // is unique to a specific navigation. The same |navigation_handle| will be
149 // provided on subsequent calls to DidRedirectNavigation, DidFinishNavigation,
150 // and ReadyToCommitNavigation when related to this navigation. Observers
151 // should clear any references to |navigation_handle| in DidFinishNavigation,
152 // just before it is destroyed.
153 //
154 // Note that this is fired by navigations in any frame of the WebContents,
155 // not just the main frame.
156 //
157 // Note that this is fired by same-document navigations, such as fragment
158 // navigations or pushState/replaceState, which will not result in a document
159 // change. To filter these out, use NavigationHandle::IsSameDocument.
160 //
161 // Note that more than one navigation can be ongoing in the same frame at the
162 // same time (including the main frame). Each will get its own
163 // NavigationHandle.
164 //
165 // Note that there is no guarantee that DidFinishNavigation will be called
166 // for any particular navigation before DidStartNavigation is called on the
167 // next.
168 virtual void DidStartNavigation(NavigationHandle* navigation_handle) {}
169
170 // Called when a navigation encountered a server redirect.
171 virtual void DidRedirectNavigation(NavigationHandle* navigation_handle) {}
172
173 // Called when the navigation is ready to be committed in a renderer. Most
174 // observers should use DidFinishNavigation instead, which happens right
175 // after the navigation commits. This method is for observers that want to
176 // initialize renderer-side state just before the RenderFrame commits the
177 // navigation.
178 //
179 // PlzNavigate
180 // This is the first point in time where a RenderFrameHost is associated with
181 // the navigation.
182 virtual void ReadyToCommitNavigation(NavigationHandle* navigation_handle) {}
183
184 // 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
186 // navigation has committed, use NavigationHandle::HasCommitted; use
187 // 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 //
196 // Note that this is fired by same-document navigations, such as fragment
197 // navigations or pushState/replaceState, which will not result in a document
198 // change. To filter these out, use NavigationHandle::IsSameDocument.
199 //
200 // Note that |navigation_handle| will be destroyed at the end of this call,
201 // so do not keep a reference to it afterward.
202 virtual void DidFinishNavigation(NavigationHandle* navigation_handle) {}
203
204 // 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 //
212 // SOON TO BE DEPRECATED. Use DidStartNavigation instead in PlzNavigate. In
213 // default mode, it is still necessary to override this function to be
214 // notified about a navigation earlier than DidStartProvisionalLoad. This
215 // function will be removed when PlzNavigate is enabled.
216 virtual void DidStartNavigationToPendingEntry(const GURL& url,
217 ReloadType reload_type) {}
218
219 // Document load events ------------------------------------------------------
220
221 // These three methods correspond to the points in time when a document starts
222 // loading for the first time (initiates outgoing requests), when incoming
223 // data subsequently starts arriving, and when it finishes loading.
224 virtual void DidStartLoading() {}
225 virtual void DidReceiveResponse() {}
226 virtual void DidStopLoading() {}
227
228 // This method is invoked once the window.document object of the main frame
229 // was created.
230 virtual void DocumentAvailableInMainFrame() {}
231
232 // This method is invoked once the onload handler of the main frame has
233 // completed.
234 virtual void DocumentOnLoadCompletedInMainFrame() {}
235
236 // This method is invoked when the document in the given frame finished
237 // loading. At this point, scripts marked as defer were executed, and
238 // content scripts marked "document_end" get injected into the frame.
239 virtual void DocumentLoadedInFrame(RenderFrameHost* render_frame_host) {}
240
241 // This method is invoked when the load is done, i.e. the spinner of the tab
242 // will stop spinning, and the onload event was dispatched.
243 //
244 // If the WebContents is displaying replacement content, e.g. network error
245 // pages, DidFinishLoad is invoked for frames that were not sending
246 // navigational events before. It is safe to ignore these events.
247 virtual void DidFinishLoad(RenderFrameHost* render_frame_host,
248 const GURL& validated_url) {}
249
250 // This method is like DidFinishLoad, but when the load failed or was
251 // cancelled, e.g. window.stop() is invoked.
252 virtual void DidFailLoad(RenderFrameHost* render_frame_host,
253 const GURL& validated_url,
254 int error_code,
255 const base::string16& error_description) {}
256
257 // This method is invoked when the visible security state of the page changes.
258 virtual void DidChangeVisibleSecurityState() {}
259
260 // This method is invoked when content was loaded from an in-memory cache.
261 virtual void DidLoadResourceFromMemoryCache(
262 const GURL& url,
263 const std::string& mime_type,
264 ResourceType resource_type) {}
265
266 // This method is invoked when a resource associate with the frame
267 // |render_frame_host| has been loaded, successfully or not. |request_id| will
268 // only be populated for main frame resources.
269 virtual void ResourceLoadComplete(
270 RenderFrameHost* render_frame_host,
271 const GlobalRequestID& request_id,
272 const mojom::ResourceLoadInfo& resource_load_info) {}
273
274 // This method is invoked when a new non-pending navigation entry is created.
275 // This corresponds to one NavigationController entry being created
276 // (in the case of new navigations) or renavigated to (for back/forward
277 // navigations).
278 virtual void NavigationEntryCommitted(
279 const LoadCommittedDetails& load_details) {}
280
281 // Invoked when the NavigationController decreased its back/forward list count
282 // by removing entries from either the front or back of its list. This is
283 // usually the result of going back and then doing a new navigation, meaning
284 // all the "forward" items are deleted.
285 //
286 // This normally happens as a result of a new navigation. It will be
287 // followed by a NavigationEntryCommitted() call for the new page that
288 // caused the pruning. It could also be a result of removing an item from
289 // the list to delete history or fix up after interstitials.
290 virtual void NavigationListPruned(const PrunedDetails& pruned_details) {}
291
292 // Invoked when NavigationEntries have been deleted because of a history
293 // deletion. Observers should ensure that they remove all traces of the
294 // deleted entries.
295 virtual void NavigationEntriesDeleted() {}
296
297 // Invoked when a NavigationEntry has changed.
298 //
299 // This will NOT be sent on navigation, interested parties should also
300 // implement NavigationEntryCommitted() to handle that case. This will be
301 // sent when the entry is updated outside of navigation (like when a new
302 // title comes).
303 virtual void NavigationEntryChanged(
304 const EntryChangedDetails& change_details) {}
305
306 // This method is invoked when a new WebContents was created in response to
307 // an action in the observed WebContents, e.g. a link with target=_blank was
308 // clicked. The |source_render_frame_host| is the frame in which the action
309 // took place.
310 virtual void DidOpenRequestedURL(WebContents* new_contents,
311 RenderFrameHost* source_render_frame_host,
312 const GURL& url,
313 const Referrer& referrer,
314 WindowOpenDisposition disposition,
315 ui::PageTransition transition,
316 bool started_from_context_menu,
317 bool renderer_initiated) {}
318
319 // This method is invoked when the renderer process has completed its first
320 // paint after a non-empty layout.
321 virtual void DidFirstVisuallyNonEmptyPaint() {}
322
323 // When WebContents::Stop() is called, the WebContents stops loading and then
324 // invokes this method. If there are ongoing navigations, their respective
325 // failure methods will also be invoked.
326 virtual void NavigationStopped() {}
327
328 // This method is invoked when the WebContents reloads all the LoFi images in
329 // the frame. LoFi is a type of Preview where Chrome shows gray boxes in place
330 // of the images on a webpage in order to conserve data for data-sensitive
331 // users. See http://bit.ly/LoFiPublicDoc.
332 virtual void DidReloadLoFiImages() {}
333
334 // Called when there has been direct user interaction with the WebContents.
335 // The type argument specifies the kind of interaction. Direct user input
336 // signalled through this callback includes:
337 // 1) any mouse down event (blink::WebInputEvent::MouseDown);
338 // 2) the start of a scroll (blink::WebInputEvent::GestureScrollBegin);
339 // 3) any raw key down event (blink::WebInputEvent::RawKeyDown); and
340 // 4) any touch event (inc. scrolls) (blink::WebInputEvent::TouchStart).
341 virtual void DidGetUserInteraction(const blink::WebInputEvent::Type type) {}
342
343 // This method is invoked when a RenderViewHost of this WebContents was
344 // configured to ignore UI events, and an UI event took place.
345 virtual void DidGetIgnoredUIEvent() {}
346
347 // Invoked every time the WebContents changes visibility.
348 virtual void OnVisibilityChanged(Visibility visibility) {}
349
350 // Invoked when the main frame changes size.
351 virtual void MainFrameWasResized(bool width_changed) {}
352
353 // Invoked when the given frame changes its window.name property.
354 virtual void FrameNameChanged(RenderFrameHost* render_frame_host,
355 const std::string& name) {}
356
357 // Called when the sticky user activation bit has been set on the frame.
358 // This will not be called for new RenderFrameHosts whose underlying
359 // FrameTreeNode was already activated. This should not be used to determine a
360 // RenderFrameHost's user activation state.
361 virtual void FrameReceivedFirstUserActivation(
362 RenderFrameHost* render_frame_host) {}
363
364 // Invoked when the display state of the frame changes.
365 virtual void FrameDisplayStateChanged(RenderFrameHost* render_frame_host,
366 bool is_display_none) {}
367
368 // Invoked when a frame changes size.
369 virtual void FrameSizeChanged(RenderFrameHost* render_frame_host,
370 const gfx::Size& frame_size) {}
371
372 // This method is invoked when the title of the WebContents is set. Note that
373 // |entry| may be null if the web page whose title changed has not yet had a
374 // NavigationEntry assigned to it.
375 virtual void TitleWasSet(NavigationEntry* entry) {}
376
377 virtual void AppCacheAccessed(const GURL& manifest_url,
378 bool blocked_by_policy) {}
379
380 // These methods are invoked when a Pepper plugin instance is created/deleted
381 // in the DOM.
382 virtual void PepperInstanceCreated() {}
383 virtual void PepperInstanceDeleted() {}
384
385 // This method is called when the viewport fit of a WebContents changes.
386 virtual void ViewportFitChanged(blink::mojom::ViewportFit value) {}
387
388 // Notification that a plugin has crashed.
389 // |plugin_pid| is the process ID identifying the plugin process. Note that
390 // this ID is supplied by the renderer process, so should not be trusted.
391 // Besides, the corresponding process has probably died at this point. The ID
392 // may even have been reused by a new process.
393 virtual void PluginCrashed(const base::FilePath& plugin_path,
394 base::ProcessId plugin_pid) {}
395
396 // Notification that the given plugin has hung or become unhung. This
397 // notification is only for Pepper plugins.
398 //
399 // The plugin_child_id is the unique child process ID from the plugin. Note
400 // that this ID is supplied by the renderer process, so should be validated
401 // before it's used for anything in case there's an exploited renderer
402 // process.
403 virtual void PluginHungStatusChanged(int plugin_child_id,
404 const base::FilePath& plugin_path,
405 bool is_hung) {}
406
407 // Notifies that an inner WebContents instance has been created with the
408 // observed WebContents as its container. |inner_web_contents| has not been
409 // added to the WebContents tree at this point, but can be observed safely.
410 virtual void InnerWebContentsCreated(WebContents* inner_web_contents) {}
411
412 // Invoked when WebContents::Clone() was used to clone a WebContents.
413 virtual void DidCloneToNewWebContents(WebContents* old_web_contents,
414 WebContents* new_web_contents) {}
415
416 // Invoked when the WebContents is being destroyed. Gives subclasses a chance
417 // to cleanup. After the whole loop over all WebContentsObservers has been
418 // finished, web_contents() returns nullptr.
419 virtual void WebContentsDestroyed() {}
420
421 // Called when the user agent override for a WebContents has been changed.
422 virtual void UserAgentOverrideSet(const std::string& user_agent) {}
423
424 // Invoked when new FaviconURL candidates are received from the renderer
425 // process.
426 virtual void DidUpdateFaviconURL(const std::vector<FaviconURL>& candidates) {}
427
428 // Called when an audio change occurs.
429 virtual void OnAudioStateChanged(bool audible) {}
430
431 // Invoked when the WebContents is muted/unmuted.
432 virtual void DidUpdateAudioMutingState(bool muted) {}
433
434 // Invoked when a pepper plugin creates and shows or destroys a fullscreen
435 // RenderWidget.
436 virtual void DidShowFullscreenWidget() {}
437 virtual void DidDestroyFullscreenWidget() {}
438
439 // Invoked when the renderer process has toggled the tab into/out of
440 // fullscreen mode.
441 virtual void DidToggleFullscreenModeForTab(bool entered_fullscreen,
442 bool will_cause_resize) {}
443
444 // Signals that |rfh| has the current fullscreen element. This is invoked
445 // when:
446 // 1) an element in this frame enters fullscreen or in nested fullscreen, or
447 // 2) after an element in a descendant frame exits fullscreen and makes
448 // this frame own the current fullscreen element again.
449 virtual void DidAcquireFullscreen(RenderFrameHost* rfh) {}
450
451 // Invoked when an interstitial page is attached or detached.
452 virtual void DidAttachInterstitialPage() {}
453 virtual void DidDetachInterstitialPage() {}
454
455 // Invoked before a form repost warning is shown.
456 virtual void BeforeFormRepostWarningShow() {}
457
458 // Invoked when the beforeunload handler fires. |proceed| is set to true if
459 // the beforeunload can safely proceed, otherwise it should be interrupted.
460 // The time is from the renderer process.
461 virtual void BeforeUnloadFired(bool proceed,
462 const base::TimeTicks& proceed_time) {}
463
464 // Invoked when a user cancels a before unload dialog.
465 virtual void BeforeUnloadDialogCancelled() {}
466
467 // Called when accessibility events or location changes are received
468 // from a render frame, but only when the accessibility mode has the
469 // ui::AXMode::kWebContents flag set.
470 virtual void AccessibilityEventReceived(
471 const AXEventNotificationDetails& details) {}
472 virtual void AccessibilityLocationChangesReceived(
473 const std::vector<AXLocationChangeNotificationDetails>& details) {}
474
475 // Invoked when theme color is changed to |theme_color|.
476 virtual void DidChangeThemeColor(base::Optional<SkColor> theme_color) {}
477
478 // Invoked when media is playing or paused. |id| is unique per player and per
479 // RenderFrameHost. There may be multiple players within a RenderFrameHost
480 // and subsequently within a WebContents. MediaStartedPlaying() will always
481 // be followed by MediaStoppedPlaying() after player teardown. Observers must
482 // release all stored copies of |id| when MediaStoppedPlaying() is received.
483 // |has_video| and |has_audio| can both be false in cases where the media
484 // is playing muted and should be considered as inaudible for all intent and
485 // purposes.
486 struct MediaPlayerInfo {
487 MediaPlayerInfo(bool has_video, bool has_audio)
488 : has_video(has_video), has_audio(has_audio) {}
489 bool has_video;
490 bool has_audio;
491 };
492
493 virtual void MediaStartedPlaying(const MediaPlayerInfo& video_type,
494 const MediaPlayerId& id) {}
495 enum class MediaStoppedReason {
496 // The media was stopped for an unspecified reason.
497 kUnspecified,
498
499 // The media was stopped because it reached the end of the stream.
500 kReachedEndOfStream,
501 };
502 virtual void MediaStoppedPlaying(
503 const MediaPlayerInfo& video_type,
504 const MediaPlayerId& id,
505 WebContentsObserver::MediaStoppedReason reason) {}
506 virtual void MediaResized(const gfx::Size& size, const MediaPlayerId& id) {}
507 // Invoked when media enters or exits fullscreen. We must use a heuristic
508 // to determine this as it is not trivial for media with custom controls.
509 // There is a slight delay between media entering or exiting fullscreen
510 // and it being detected.
511 virtual void MediaEffectivelyFullscreenChanged(bool is_fullscreen) {}
512 virtual void MediaPictureInPictureChanged(bool is_picture_in_picture) {}
513 virtual void MediaMutedStatusChanged(const MediaPlayerId& id, bool muted) {}
514
515 // Invoked when the renderer process changes the page scale factor.
516 virtual void OnPageScaleFactorChanged(float page_scale_factor) {}
517
518 // Invoked if an IPC message is coming from a specific RenderFrameHost.
519 virtual bool OnMessageReceived(const IPC::Message& message,
520 RenderFrameHost* render_frame_host);
521
522 // Notification that the |render_widget_host| for this WebContents has gained
523 // focus.
524 virtual void OnWebContentsFocused(RenderWidgetHost* render_widget_host) {}
525
526 // Notification that the |render_widget_host| for this WebContents has lost
527 // focus.
528 virtual void OnWebContentsLostFocus(RenderWidgetHost* render_widget_host) {}
529
530 // Notifies that the manifest URL for the main frame changed to
531 // |manifest_url|. This will be invoked when a document with a manifest loads
532 // or when the manifest URL changes (possibly to nothing). It is not invoked
533 // when a document with no manifest loads. During document load, if the
534 // document has both a manifest and a favicon, DidUpdateWebManifestURL() will
535 // be invoked before DidUpdateFaviconURL().
536 virtual void DidUpdateWebManifestURL(
537 const base::Optional<GURL>& manifest_url) {}
538
539 // Called to give the embedder an opportunity to bind an interface request
540 // from a frame. If the request can be bound, |interface_pipe| will be taken.
541 virtual void OnInterfaceRequestFromFrame(
542 RenderFrameHost* render_frame_host,
543 const std::string& interface_name,
544 mojo::ScopedMessagePipeHandle* interface_pipe) {}
545
546 // Notifies that the RenderWidgetCompositor has issued a draw command. An
547 // observer can use this method to detect when Chrome visually updated a
548 // tab.
549 virtual void DidCommitAndDrawCompositorFrame() {}
550
551 // Called when "audible" playback starts or stops on a WebAudio AudioContext.
552 using AudioContextId = std::pair<RenderFrameHost*, int>;
553 virtual void AudioContextPlaybackStarted(
554 const AudioContextId& audio_context_id) {}
555 virtual void AudioContextPlaybackStopped(
556 const AudioContextId& audio_context_id) {}
557
558 // IPC::Listener implementation.
559 // DEPRECATED: Use (i.e. override) the other overload instead:
560 // virtual bool OnMessageReceived(const IPC::Message& message,
561 // RenderFrameHost* render_frame_host);
562 // TODO(https://crbug.com/758026): Delete this overload when possible.
563 bool OnMessageReceived(const IPC::Message& message) override;
564
565 WebContents* web_contents() const;
566
567 protected:
568 // Use this constructor when the object is tied to a single WebContents for
569 // its entire lifetime.
570 explicit WebContentsObserver(WebContents* web_contents);
571
572 // Use this constructor when the object wants to observe a WebContents for
573 // part of its lifetime. It can then call Observe() to start and stop
574 // observing.
575 WebContentsObserver();
576
577 ~WebContentsObserver() override;
578
579 // Start observing a different WebContents; used with the default constructor.
580 void Observe(WebContents* web_contents);
581
582 private:
583 friend class WebContentsImpl;
584
585 void ResetWebContents();
586
587 WebContentsImpl* web_contents_;
588
589 DISALLOW_COPY_AND_ASSIGN(WebContentsObserver);
590};
591
592} // namespace content
593
594#endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_
595