[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 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 | |
avi | 652869c | 2015-12-25 01:48:45 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 10 | #include "base/memory/raw_ptr.h" |
[email protected] | c3c10f2 | 2013-07-25 14:21:12 | [diff] [blame] | 11 | #include "base/process/kill.h" |
| 12 | #include "base/process/process_handle.h" |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 13 | #include "base/threading/thread_restrictions.h" |
David Black | 9cca359 | 2019-11-06 23:02:22 | [diff] [blame] | 14 | #include "components/viz/common/vertical_scroll_direction.h" |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 15 | #include "content/common/content_export.h" |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 16 | #include "content/public/browser/allow_service_worker_result.h" |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 17 | #include "content/public/browser/reload_type.h" |
Christian Dullweber | 5e66727b | 2021-07-02 13:23:15 | [diff] [blame] | 18 | #include "content/public/browser/render_frame_host.h" |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 19 | #include "content/public/browser/visibility.h" |
Christian Dullweber | 5e66727b | 2021-07-02 13:23:15 | [diff] [blame] | 20 | #include "ipc/ipc_message.h" |
Ben Goodger | 9e24929e | 2017-07-21 03:13:40 | [diff] [blame] | 21 | #include "mojo/public/cpp/system/message_pipe.h" |
Kinuko Yasuda | 433f710a | 2020-02-14 02:11:58 | [diff] [blame] | 22 | #include "services/network/public/mojom/fetch_api.mojom-forward.h" |
Ben Goodger | 9e24929e | 2017-07-21 03:13:40 | [diff] [blame] | 23 | #include "services/service_manager/public/cpp/bind_source_info.h" |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 24 | #include "third_party/abseil-cpp/absl/types/optional.h" |
Dave Tapuska | 129cef8 | 2019-12-19 16:36:48 | [diff] [blame] | 25 | #include "third_party/blink/public/common/input/web_input_event.h" |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 26 | #include "third_party/blink/public/common/user_agent/user_agent_metadata.h" |
Michael Bai | 19f17a30 | 2021-12-08 04:08:33 | [diff] [blame] | 27 | #include "third_party/blink/public/mojom/css/preferred_color_scheme.mojom.h" |
Devlin Cronin | 5ea668f3 | 2019-12-18 21:57:58 | [diff] [blame] | 28 | #include "third_party/blink/public/mojom/devtools/console_message.mojom.h" |
Hans Wennborg | 7d15b70 | 2021-03-31 17:58:55 | [diff] [blame] | 29 | #include "third_party/blink/public/mojom/favicon/favicon_url.mojom-forward.h" |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 30 | #include "third_party/blink/public/mojom/loader/resource_load_info.mojom-forward.h" |
Lei Zhang | 3ee2b78a | 2021-05-18 20:58:44 | [diff] [blame] | 31 | #include "third_party/blink/public/mojom/media/capture_handle_config.mojom-forward.h" |
[email protected] | e710476 | 2014-06-20 19:17:25 | [diff] [blame] | 32 | #include "third_party/skia/include/core/SkColor.h" |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 33 | #include "ui/base/page_transition_types.h" |
[email protected] | f47621b | 2013-01-22 20:50:33 | [diff] [blame] | 34 | #include "ui/base/window_open_disposition.h" |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 35 | |
Christian Dullweber | 5e66727b | 2021-07-02 13:23:15 | [diff] [blame] | 36 | class GURL; |
| 37 | |
Becca Hughes | 6fe54e43 | 2018-06-09 04:18:56 | [diff] [blame] | 38 | namespace blink { |
| 39 | namespace mojom { |
| 40 | enum class ViewportFit; |
| 41 | } // namespace mojom |
| 42 | } // namespace blink |
| 43 | |
peconn | 25795152 | 2017-06-09 18:24:59 | [diff] [blame] | 44 | namespace gfx { |
| 45 | class Size; |
| 46 | } // namespace gfx |
| 47 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 48 | namespace content { |
| 49 | |
[email protected] | 1ef02d24 | 2013-10-07 16:18:53 | [diff] [blame] | 50 | class NavigationEntry; |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 51 | class NavigationHandle; |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 52 | class RenderFrameHost; |
Avi Drissman | b3d355f | 2018-01-29 20:08:18 | [diff] [blame] | 53 | class RenderProcessHost; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 54 | class RenderViewHost; |
afakhry | 9824183 | 2016-03-11 19:27:47 | [diff] [blame] | 55 | class RenderWidgetHost; |
Sreeja Kamishetty | 5346897 | 2021-07-13 11:53:32 | [diff] [blame] | 56 | class Page; |
[email protected] | 26b5e32 | 2011-12-23 01:36:47 | [diff] [blame] | 57 | class WebContents; |
[email protected] | 31a71eaf | 2014-03-13 01:47:36 | [diff] [blame] | 58 | struct AXEventNotificationDetails; |
dmazzoni | 2400c46 | 2016-08-23 15:07:13 | [diff] [blame] | 59 | struct AXLocationChangeNotificationDetails; |
Christian Dullweber | 5e66727b | 2021-07-02 13:23:15 | [diff] [blame] | 60 | struct CookieAccessDetails; |
Sam McNally | 5c087a3 | 2017-08-25 01:46:14 | [diff] [blame] | 61 | struct EntryChangedDetails; |
Jeff Fisher | 709b4c5 | 2019-07-29 20:07:34 | [diff] [blame] | 62 | struct FocusedNodeDetails; |
Christian Dullweber | 5e66727b | 2021-07-02 13:23:15 | [diff] [blame] | 63 | struct GlobalRequestID; |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 64 | struct LoadCommittedDetails; |
Mounir Lamouri | 0f5bdf5 | 2019-04-04 16:32:35 | [diff] [blame] | 65 | struct MediaPlayerId; |
Sam McNally | 5c087a3 | 2017-08-25 01:46:14 | [diff] [blame] | 66 | struct PrunedDetails; |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 67 | struct Referrer; |
| 68 | |
Daniel Cheng | 2809eff | 2021-09-28 00:20:31 | [diff] [blame] | 69 | // Note: before adding a new `WebContentsObserver` subclass, consider if simpler |
| 70 | // helpers will suffice: |
| 71 | // |
| 72 | // - Classes that have a 1:1 relationship with one RenderFrameHost can often |
Sreeja Kamishetty | 0a0961f | 2021-10-11 16:23:53 | [diff] [blame] | 73 | // use `DocumentUserData` instead. |
Daniel Cheng | 2809eff | 2021-09-28 00:20:31 | [diff] [blame] | 74 | // - Mojo interface implementations that have a 1 RenderFrameHost to many |
Daniel Cheng | 9fb887ff | 2021-10-01 20:27:38 | [diff] [blame] | 75 | // instances relationship can often use `DocumentService` instead. |
Daniel Cheng | 2809eff | 2021-09-28 00:20:31 | [diff] [blame] | 76 | // |
| 77 | // These helpers can help avoid memory safety bugs, such as retaining a pointer |
| 78 | // to a deleted RenderFrameHost, or other security issues, such as origin |
| 79 | // confusion when a RenderFrameHost is reused after a cross-document navigation. |
| 80 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 81 | // An observer API implemented by classes which are interested in various page |
John Abd-El-Malek | 5b1d725 | 2021-03-05 21:03:08 | [diff] [blame] | 82 | // events from WebContents. They also get a chance to filter IPC messages. |
| 83 | // The difference between WebContentsDelegate (WCD) and WebContentsObserver |
| 84 | // (WCO) is that there is one WCD per WebContents and many WCOs. Methods which |
| 85 | // have a return value, e.g. are expected to change state, should be on WCD. |
[email protected] | 87eca18 | 2013-01-31 21:20:00 | [diff] [blame] | 86 | // |
[email protected] | d16609c | 2013-08-23 06:01:40 | [diff] [blame] | 87 | // Since a WebContents can be a delegate to almost arbitrarily many |
[email protected] | 87eca18 | 2013-01-31 21:20:00 | [diff] [blame] | 88 | // RenderViewHosts, it is important to check in those WebContentsObserver |
| 89 | // methods which take a RenderViewHost that the event came from the |
| 90 | // RenderViewHost the observer cares about. |
| 91 | // |
| 92 | // Usually, observers should only care about the current RenderViewHost as |
| 93 | // returned by GetRenderViewHost(). |
| 94 | // |
Jochen Eisinger | 3bc9897 | 2022-01-12 18:44:23 | [diff] [blame] | 95 | // TODO(creis): Hide the fact that there are several RenderViewHosts |
[email protected] | 87eca18 | 2013-01-31 21:20:00 | [diff] [blame] | 96 | // from the WebContentsObserver API. http://crbug.com/173325 |
Dave Tapuska | 34310de | 2021-06-02 20:21:01 | [diff] [blame] | 97 | class CONTENT_EXPORT WebContentsObserver { |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 98 | public: |
Peter Boström | 9b03653 | 2021-10-28 23:37:28 | [diff] [blame] | 99 | WebContentsObserver(const WebContentsObserver&) = delete; |
| 100 | WebContentsObserver& operator=(const WebContentsObserver&) = delete; |
| 101 | |
avi | ee9b737 | 2016-06-28 20:34:43 | [diff] [blame] | 102 | // Frames and Views ---------------------------------------------------------- |
| 103 | |
nasko | 00528252 | 2015-01-22 02:30:02 | [diff] [blame] | 104 | // Called when a RenderFrame for |render_frame_host| is created in the |
Scott Violet | 507cbcb2 | 2020-05-21 17:24:22 | [diff] [blame] | 105 | // renderer process. Use |RenderFrameDeleted| to listen for when this |
| 106 | // RenderFrame goes away. |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 107 | virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) {} |
| 108 | |
nasko | 00528252 | 2015-01-22 02:30:02 | [diff] [blame] | 109 | // Called when a RenderFrame for |render_frame_host| is deleted or the |
| 110 | // renderer process in which it runs it has died. Use |RenderFrameCreated| to |
| 111 | // listen for when RenderFrame objects are created. |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 112 | virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) {} |
| 113 | |
Kevin McNee | c9d0fda | 2021-05-19 15:55:17 | [diff] [blame] | 114 | // This method is invoked whenever one of the frames of a WebContents |
nasko | 00528252 | 2015-01-22 02:30:02 | [diff] [blame] | 115 | // swaps its RenderFrameHost with another one; for example because that frame |
| 116 | // navigated and the new content is in a different process. The |
| 117 | // RenderFrameHost that has been replaced is in |old_host|, which can be |
| 118 | // nullptr if the old RenderFrameHost was shut down or a new frame has been |
| 119 | // created and no old RenderFrameHost exists. |
| 120 | // |
| 121 | // This method, in combination with |FrameDeleted|, is appropriate for |
Kevin McNee | c9d0fda | 2021-05-19 15:55:17 | [diff] [blame] | 122 | // observers wishing to track the set of RenderFrameHosts that are current in |
| 123 | // their frame tree. Note that being current in a frame tree is separate from |
| 124 | // the lifecycle state of the RenderFrameHosts. Consider using |
| 125 | // |RenderFrameHostStateChanged|. |
nasko | 00528252 | 2015-01-22 02:30:02 | [diff] [blame] | 126 | virtual void RenderFrameHostChanged(RenderFrameHost* old_host, |
| 127 | RenderFrameHost* new_host) {} |
| 128 | |
Sreeja Kamishetty | 5346897 | 2021-07-13 11:53:32 | [diff] [blame] | 129 | // This method is invoked whenever primary page of a WebContents |
| 130 | // (WebContents::GetPrimaryPage()) changes to `page`. This happens in one of |
| 131 | // the following cases: |
Sreeja Kamishetty | a21b4f6 | 2021-06-25 07:48:25 | [diff] [blame] | 132 | // 1) when the current RenderFrameHost in the primary main frame changes after |
| 133 | // a navigation. |
| 134 | // 2) when the current RenderFrameHost in the primary main frame is |
| 135 | // reinitialized after a crash. |
| 136 | // 3) when a cross-document navigation commits in the current RenderFrameHost |
| 137 | // of the primary main frame. |
| 138 | |
| 139 | // The new primary page might either be a brand new one (if the committed |
| 140 | // navigation created a new document in the primary main frame) or an existing |
| 141 | // one (back-forward cache restore or prerendering activation). |
| 142 | |
| 143 | // This notification is not dispatched for changes of pages in the non-primary |
| 144 | // frame trees (prerendering, fenced frames) and when the primary page is |
| 145 | // destroyed (e.g., when closing a tab). |
| 146 | |
| 147 | // This method is useful for updating the tab-related UI which depends on the |
| 148 | // primary page's state (e.g. theme colour, such state should typically be |
| 149 | // available as a method on a Page or stored in PageUserData). Prefer |
| 150 | // listening to this method to listening to DidFinishNavigation and checking |
| 151 | // NavigationHandle::IsInPrimaryMainFrame && !NavigationHandle::IsSameDocument |
| 152 | // && NavigationHandle::HasCommitted (unless your code has to listen to |
| 153 | // DidFinishNavigation for some other reason, in which case listening only to |
| 154 | // DidFinishNavigation is recommended). |
Sreeja Kamishetty | 5346897 | 2021-07-13 11:53:32 | [diff] [blame] | 155 | virtual void PrimaryPageChanged(Page& page) {} |
Sreeja Kamishetty | a21b4f6 | 2021-06-25 07:48:25 | [diff] [blame] | 156 | |
Carlos Caballero | bf362496 | 2021-04-02 01:26:02 | [diff] [blame] | 157 | // This method is invoked when a frame is destroyed. A subframe is destroyed |
| 158 | // when its parent detaches it or navigates to a different document. A main |
| 159 | // frame is destroyed when the whole WebContents is going away, or, with |
| 160 | // MPArch, when a non-primary frame tree (e.g., prerendered page) is |
| 161 | // destroyed. |
nasko | 00528252 | 2015-01-22 02:30:02 | [diff] [blame] | 162 | // Use |RenderFrameHostChanged| to listen for when a RenderFrameHost object is |
| 163 | // made the current host for a frame. |
Carlos Caballero | bf362496 | 2021-04-02 01:26:02 | [diff] [blame] | 164 | virtual void FrameDeleted(int frame_tree_node_id) {} |
nasko | 00528252 | 2015-01-22 02:30:02 | [diff] [blame] | 165 | |
Sreeja Kamishetty | 2771b7d | 2021-04-07 06:34:18 | [diff] [blame] | 166 | // This method is invoked whenever one of the frames of a WebContents changes |
| 167 | // its |RenderFrameHost::GetLifecycleState()| i.e., when RenderFrameHost |
| 168 | // LifecycleState changes from |old_state| to |new_state|. The old |
| 169 | // LifecycleState that is being changed is |old_state| and the LifecycleState |
| 170 | // that it changes to is |new_state|. |old_state| and |new_state| are always |
| 171 | // different, i.e., a frame can't transition to the same state. |
| 172 | // |
| 173 | // This method allows code to react to RenderFrameHost LifecycleState changes. |
| 174 | // For example, to detect changes in the currently active document and perform |
| 175 | // different actions accordingly, like closing UI/resetting states, |
| 176 | // RenderFrameHostStateChanged is preferred instead of DidFinishNavigation. |
| 177 | // DidFinishNavigation does not guarantee that the old document will go away. |
| 178 | // Instead, it could enter the BackForwardCache and then become kActive later. |
| 179 | // Features that need to handle transitions like these should monitor |
| 180 | // LifecycleState changes instead. |
| 181 | // |
| 182 | // A particular document may change its LifecycleState and trigger |
| 183 | // RenderFrameHostStateChanged as part of being committed in a navigation, |
| 184 | // when another document replaces it by navigating in the same frame, in |
| 185 | // response to being detached from the DOM, or (with MPArch) as part of |
| 186 | // activating a prerendered page. |
| 187 | // |
| 188 | // When committing a cross-document, cross-RenderFrameHost navigation, |
| 189 | // navigation-related callbacks are dispatched in the following order: |
| 190 | // - RenderFrameHostStateChanged(new_frame, old_state, new_state) |
| 191 | // - RenderFrameHostChanged(old_frame, new_frame) |
| 192 | // - RenderFrameHostStateChanged(old_frame, old_state, new_state) |
| 193 | // - DidFinishNavigation(navigation_handle) |
| 194 | virtual void RenderFrameHostStateChanged( |
| 195 | RenderFrameHost* render_frame_host, |
| 196 | RenderFrameHost::LifecycleState old_state, |
| 197 | RenderFrameHost::LifecycleState new_state) {} |
| 198 | |
Alexander Cooper | 987d046cc | 2021-04-14 00:07:21 | [diff] [blame] | 199 | // This method is invoked when something "replaces" the contents of the |
| 200 | // WebContents or otherwise changes the FrameSinkId of the contents that |
| 201 | // should be captured if capturing this WebContents, WITHOUT changing the |
| 202 | // RenderFrameHost. |
| 203 | virtual void CaptureTargetChanged() {} |
| 204 | |
Elad Alon | f156eb6 | 2021-05-17 22:02:37 | [diff] [blame] | 205 | // This method is invoked when the capture handle config changes. This can |
| 206 | // happen when: |
| 207 | // 1. The web-application calls |mediaDevices.setCaptureHandleConfig|. |
| 208 | // 2. The top-level frame is navigated cross-document. |
| 209 | virtual void OnCaptureHandleConfigUpdate( |
| 210 | const blink::mojom::CaptureHandleConfig& config) {} |
| 211 | |
[email protected] | 87eca18 | 2013-01-31 21:20:00 | [diff] [blame] | 212 | // This method is invoked when the RenderView of the current RenderViewHost |
| 213 | // is ready, e.g. because we recreated it after a crash. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 214 | virtual void RenderViewReady() {} |
[email protected] | 87eca18 | 2013-01-31 21:20:00 | [diff] [blame] | 215 | |
| 216 | // This method is invoked when a RenderViewHost of the WebContents is |
| 217 | // deleted. Note that this does not always happen when the WebContents starts |
| 218 | // to use a different RenderViewHost, as the old RenderViewHost might get |
| 219 | // just swapped out. |
| 220 | virtual void RenderViewDeleted(RenderViewHost* render_view_host) {} |
| 221 | |
Dave Tapuska | f8d1784 | 2021-06-23 21:34:22 | [diff] [blame] | 222 | // This method is invoked when the process for the current RenderFrameHost |
| 223 | // of the primary main frame exits (usually by crashing, though possibly by |
| 224 | // other means). The WebContents continues to use the RenderFrameHost, e.g. |
| 225 | // when the user reloads the current page. When the RenderFrameHost itself is |
| 226 | // deleted, the RenderFrameDeleted method will be invoked. |
[email protected] | 4d61441 | 2014-01-10 08:29:37 | [diff] [blame] | 227 | // |
avi | 3360120 | 2015-07-11 01:39:26 | [diff] [blame] | 228 | // Note that this is triggered upstream through |
| 229 | // RenderProcessHostObserver::RenderProcessExited(); for code that doesn't |
| 230 | // otherwise need to be a WebContentsObserver, that API is probably a better |
| 231 | // choice. |
Dave Tapuska | 7052b7c5 | 2021-10-18 17:30:53 | [diff] [blame] | 232 | virtual void PrimaryMainFrameRenderProcessGone( |
| 233 | base::TerminationStatus status) {} |
[email protected] | 87eca18 | 2013-01-31 21:20:00 | [diff] [blame] | 234 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 235 | // This method is invoked when a WebContents swaps its visible RenderViewHost |
| 236 | // with another one, possibly changing processes. The RenderViewHost that has |
mlamouri | 8c61ffc | 2015-01-13 16:17:59 | [diff] [blame] | 237 | // been replaced is in |old_host|, which is nullptr if the old RVH was shut |
| 238 | // down. |
[email protected] | 7b712ee2 | 2013-10-03 00:57:28 | [diff] [blame] | 239 | virtual void RenderViewHostChanged(RenderViewHost* old_host, |
| 240 | RenderViewHost* new_host) {} |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 241 | |
Avi Drissman | b3d355f | 2018-01-29 20:08:18 | [diff] [blame] | 242 | // This method is invoked when a process in the WebContents becomes |
| 243 | // unresponsive. |
| 244 | virtual void OnRendererUnresponsive(RenderProcessHost* render_process_host) {} |
afakhry | 9824183 | 2016-03-11 19:27:47 | [diff] [blame] | 245 | |
Scott Violet | 48202e6 | 2020-05-26 17:19:33 | [diff] [blame] | 246 | // See WebContentsDelegate::RendererResponsive(). |
| 247 | virtual void OnRendererResponsive(RenderProcessHost* render_process_host) {} |
| 248 | |
avi | ee9b737 | 2016-06-28 20:34:43 | [diff] [blame] | 249 | // Navigation ---------------------------------------------------------------- |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 250 | |
| 251 | // Called when a navigation started in the WebContents. |navigation_handle| |
| 252 | // is unique to a specific navigation. The same |navigation_handle| will be |
nasko | 14baf39 | 2016-02-02 02:15:38 | [diff] [blame] | 253 | // provided on subsequent calls to DidRedirectNavigation, DidFinishNavigation, |
| 254 | // and ReadyToCommitNavigation when related to this navigation. Observers |
| 255 | // should clear any references to |navigation_handle| in DidFinishNavigation, |
| 256 | // just before it is destroyed. |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 257 | // |
Alexander Timin | 26fb41a | 2021-09-14 22:18:28 | [diff] [blame] | 258 | // NOTES: |
| 259 | // - Starting a navigation doesn't affect which document is shown, or |
| 260 | // (in many cases) which URL is displayed in the omnibox. Most effects of the |
| 261 | // navigation only occur at DidFinishNavigation, if it commits. Feature code |
| 262 | // generally should not use DidStartNavigation to reset their state (e.g. |
| 263 | // close the UI), especially given that a renderer process can easily start a |
| 264 | // navigation which is guaranteed not to commit (e.g. by navigating to |
| 265 | // a URL returning a response with HTTP status code of 204 or a download). |
Alexander Timin | c618141 | 2021-09-17 01:54:30 | [diff] [blame] | 266 | // Consider listening to PrimaryPageChanged or DidFinishNavigation instead. |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 267 | // |
Alexander Timin | 26fb41a | 2021-09-14 22:18:28 | [diff] [blame] | 268 | // - This notification is fired by navigations in any frame of the |
| 269 | // WebContents, not just the primary main frame. |
| 270 | // |
| 271 | // - This notification is fired by same-document navigations, such as fragment |
clamy | 57f99bd2 | 2016-11-30 18:25:11 | [diff] [blame] | 272 | // navigations or pushState/replaceState, which will not result in a document |
eugenebut | a11672fb | 2017-03-07 17:13:51 | [diff] [blame] | 273 | // change. To filter these out, use NavigationHandle::IsSameDocument. |
clamy | 57f99bd2 | 2016-11-30 18:25:11 | [diff] [blame] | 274 | // |
Alexander Timin | 26fb41a | 2021-09-14 22:18:28 | [diff] [blame] | 275 | // - There can be more than one navigation can be ongoing in the same frame at |
| 276 | // the same time (including the main frame). Each will get its own |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 277 | // NavigationHandle. |
| 278 | // |
Alexander Timin | 26fb41a | 2021-09-14 22:18:28 | [diff] [blame] | 279 | // - There is no guarantee that DidFinishNavigation will be called |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 280 | // for any particular navigation before DidStartNavigation is called on the |
| 281 | // next. |
| 282 | virtual void DidStartNavigation(NavigationHandle* navigation_handle) {} |
| 283 | |
| 284 | // Called when a navigation encountered a server redirect. |
| 285 | virtual void DidRedirectNavigation(NavigationHandle* navigation_handle) {} |
| 286 | |
John Abd-El-Malek | df8e3da | 2019-10-30 00:57:37 | [diff] [blame] | 287 | // Called when the navigation is ready to be committed in a renderer. This |
| 288 | // occurs when the response code isn't 204/205 (which tell the browser that |
| 289 | // the request is successful but there's no content that follows) or a |
| 290 | // download (either from a response header or based on mime sniffing the |
| 291 | // response). The browser then is ready to switch rendering the new document. |
| 292 | // Most observers should use DidFinishNavigation instead, which happens right |
clamy | b876f0a7 | 2015-09-24 20:01:05 | [diff] [blame] | 293 | // after the navigation commits. This method is for observers that want to |
| 294 | // initialize renderer-side state just before the RenderFrame commits the |
| 295 | // navigation. |
| 296 | // |
| 297 | // This is the first point in time where a RenderFrameHost is associated with |
| 298 | // the navigation. |
clamy | efca29e | 2015-09-17 00:22:11 | [diff] [blame] | 299 | virtual void ReadyToCommitNavigation(NavigationHandle* navigation_handle) {} |
| 300 | |
clamy | b876f0a7 | 2015-09-24 20:01:05 | [diff] [blame] | 301 | // Called when a navigation finished in the WebContents. This happens when a |
| 302 | // navigation is committed, aborted or replaced by a new one. To know if the |
vabr | d9092d3 | 2016-03-16 19:03:32 | [diff] [blame] | 303 | // navigation has committed, use NavigationHandle::HasCommitted; use |
clamy | b876f0a7 | 2015-09-24 20:01:05 | [diff] [blame] | 304 | // NavigationHandle::IsErrorPage to know if the navigation resulted in an |
| 305 | // error page. |
| 306 | // |
| 307 | // If this is called because the navigation committed, then the document load |
| 308 | // will still be ongoing in the RenderFrameHost returned by |
| 309 | // |navigation_handle|. Use the document loads events such as DidStopLoading |
| 310 | // and related methods to listen for continued events from this |
| 311 | // RenderFrameHost. |
| 312 | // |
eugenebut | a11672fb | 2017-03-07 17:13:51 | [diff] [blame] | 313 | // Note that this is fired by same-document navigations, such as fragment |
clamy | 57f99bd2 | 2016-11-30 18:25:11 | [diff] [blame] | 314 | // navigations or pushState/replaceState, which will not result in a document |
eugenebut | a11672fb | 2017-03-07 17:13:51 | [diff] [blame] | 315 | // change. To filter these out, use NavigationHandle::IsSameDocument. |
clamy | 57f99bd2 | 2016-11-30 18:25:11 | [diff] [blame] | 316 | // |
clamy | b876f0a7 | 2015-09-24 20:01:05 | [diff] [blame] | 317 | // Note that |navigation_handle| will be destroyed at the end of this call, |
| 318 | // so do not keep a reference to it afterward. |
Alexander Timin | 57b9c74 | 2020-07-06 14:04:03 | [diff] [blame] | 319 | // |
| 320 | // Note that using DidFinishNavigation to detect changes in the currently |
Sreeja Kamishetty | a21b4f6 | 2021-06-25 07:48:25 | [diff] [blame] | 321 | // active document / page and reset per-document state is strongly |
| 322 | // discouraged. |
| 323 | // |
| 324 | // Listening to PrimaryPageChanged should be preferred to listening to |
| 325 | // DidFinishNavigation and checking IsInPrimaryMainFrame, !IsSameDocument, and |
| 326 | // HasCommitted. |
| 327 | // |
| 328 | // The per-document / per-page data should be stored in |
Sreeja Kamishetty | 0a0961f | 2021-10-11 16:23:53 | [diff] [blame] | 329 | // DocumentUserData / PageUserData instead of resetting it in |
Sreeja Kamishetty | a21b4f6 | 2021-06-25 07:48:25 | [diff] [blame] | 330 | // DidFinishNavigation. (In particular, the page might be stored in the |
| 331 | // back-forward cache instead of being deleted. See comments in PageUserData / |
Sreeja Kamishetty | 0a0961f | 2021-10-11 16:23:53 | [diff] [blame] | 332 | // DocumentUserData for more details). |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 333 | virtual void DidFinishNavigation(NavigationHandle* navigation_handle) {} |
| 334 | |
Lucas Gadani | 97298562 | 2020-05-28 20:52:51 | [diff] [blame] | 335 | // Called after the contents replaces the |predecessor_contents| in its |
| 336 | // container due to portal activation. The |predecessor_contents| is now a |
| 337 | // portal pending adoption. |predecessor_contents| is non-null, but may |
| 338 | // subsequently be destroyed if it is not adopted. |
| 339 | // |activation_time| is the time the activation happened. |
| 340 | virtual void DidActivatePortal(WebContents* predecessor_web_contents, |
| 341 | base::TimeTicks activation_time) {} |
| 342 | |
clamy | b876f0a7 | 2015-09-24 20:01:05 | [diff] [blame] | 343 | // Document load events ------------------------------------------------------ |
| 344 | |
Chris Hamilton | f82f2a70 | 2018-02-15 19:37:29 | [diff] [blame] | 345 | // These three methods correspond to the points in time when a document starts |
| 346 | // loading for the first time (initiates outgoing requests), when incoming |
| 347 | // data subsequently starts arriving, and when it finishes loading. |
clamy | b876f0a7 | 2015-09-24 20:01:05 | [diff] [blame] | 348 | virtual void DidStartLoading() {} |
| 349 | virtual void DidStopLoading() {} |
| 350 | |
Evan Stade | 9f32811 | 2019-10-23 20:49:25 | [diff] [blame] | 351 | // The page has made some progress loading. |progress| is a value between 0.0 |
| 352 | // (nothing loaded) to 1.0 (page fully loaded). |
| 353 | virtual void LoadProgressChanged(double progress) {} |
| 354 | |
Sreeja Kamishetty | 9bc31e2c | 2022-01-11 05:48:46 | [diff] [blame] | 355 | // This method is invoked once the window.document element of the primary main |
| 356 | // frame's current document (i.e., |render_frame_host|) is ready. This happens |
| 357 | // when the document's main HTML resource has finished parsing. Here |
| 358 | // document element refers to DOMDocument, which is different from browser |
| 359 | // implementation of blink::Document in DocumentUserData/DocumentService which |
| 360 | // are typically created when navigation commits. |
| 361 | // |
Sreeja Kamishetty | 4978330 | 2022-01-28 17:52:25 | [diff] [blame] | 362 | // Note that PrimaryMainDocumentElementAvailable should be used when the |
| 363 | // observers which send IPCs to the renderer want to ensure that |
| 364 | // window.document is non-null. For for the comment cases like observing |
| 365 | // primary document/URL changes in the omnibox due to navigation |
Sreeja Kamishetty | 9bc31e2c | 2022-01-11 05:48:46 | [diff] [blame] | 366 | // WebContentsObserver::PrimaryPageChanged should be used and to observe fully |
| 367 | // loaded signal WebContentsObserver::DidFinishLoad can be used. |
| 368 | // |
| 369 | // This event is dispatched once in the document's lifetime, which means it's |
| 370 | // not dispatched after navigation that restores a Back/Forward Cache page. |
| 371 | // For prerendering, this signal is dispatched when the main document element |
| 372 | // is available and the document is shown to the user (i.e., after the |
| 373 | // activation). |
Sreeja Kamishetty | 4978330 | 2022-01-28 17:52:25 | [diff] [blame] | 374 | virtual void PrimaryMainDocumentElementAvailable() {} |
clamy | b876f0a7 | 2015-09-24 20:01:05 | [diff] [blame] | 375 | |
Sreeja Kamishetty | 6b55ecc | 2021-12-10 11:28:17 | [diff] [blame] | 376 | // This method is invoked once the onload handler of the primary main frame's |
| 377 | // current document (i.e., |render_frame_host|) has completed. This happens |
| 378 | // when the primary main document has finished running onload events after |
| 379 | // loading all content (images, scripts, etc). Prefer using |
Sreeja Kamishetty | 8134758 | 2022-01-06 12:46:33 | [diff] [blame] | 380 | // WebContents::IsDocumentOnLoadCompletedInPrimaryMainFrame instead of saving |
| 381 | // this state in your component. |
Sreeja Kamishetty | 6b55ecc | 2021-12-10 11:28:17 | [diff] [blame] | 382 | // |
Sreeja Kamishetty | 8134758 | 2022-01-06 12:46:33 | [diff] [blame] | 383 | // For prerendering we dispatch DocumentOnLoadCompletedInPrimaryMainFrame on |
Sreeja Kamishetty | 6b55ecc | 2021-12-10 11:28:17 | [diff] [blame] | 384 | // activation whereas for BackForwardCache restores we don't dispatch |
Sreeja Kamishetty | 8134758 | 2022-01-06 12:46:33 | [diff] [blame] | 385 | // DocumentOnLoadCompletedInPrimaryMainFrame. |
Sreeja Kamishetty | 6b55ecc | 2021-12-10 11:28:17 | [diff] [blame] | 386 | // |
Sreeja Kamishetty | 8134758 | 2022-01-06 12:46:33 | [diff] [blame] | 387 | // DocumentOnLoadCompletedInPrimaryMainFrame is typically used by the |
| 388 | // embedders to perform actions on a loaded page, for example showing load |
| 389 | // completion bubbles, injecting scripts which take page snapshots. Note, |
| 390 | // however, that some web pages might still be loading (i.e. if they |
| 391 | // dynamically inject content). |
| 392 | virtual void DocumentOnLoadCompletedInPrimaryMainFrame() {} |
clamy | b876f0a7 | 2015-09-24 20:01:05 | [diff] [blame] | 393 | |
Ewelina Baran | ed2df8ad | 2021-12-22 10:05:37 | [diff] [blame] | 394 | // This method is invoked when we have received a response from the |
| 395 | // renderer in response to a dom automation controller action. |
| 396 | // For example, `window.domAutomationController.send(foo())` sends the |
| 397 | // result of foo() here. |
| 398 | // |json_string| is a string with the response which came from a specific |
| 399 | // |render_frame_host|. |
| 400 | virtual void DomOperationResponse(RenderFrameHost* render_frame_host, |
| 401 | const std::string& json_string) {} |
| 402 | |
clamy | b876f0a7 | 2015-09-24 20:01:05 | [diff] [blame] | 403 | // This method is invoked when the document in the given frame finished |
| 404 | // loading. At this point, scripts marked as defer were executed, and |
| 405 | // content scripts marked "document_end" get injected into the frame. |
Kouhei Ueno | f6e9624 | 2019-09-27 01:54:35 | [diff] [blame] | 406 | virtual void DOMContentLoaded(RenderFrameHost* render_frame_host) {} |
clamy | b876f0a7 | 2015-09-24 20:01:05 | [diff] [blame] | 407 | |
avi | ee9b737 | 2016-06-28 20:34:43 | [diff] [blame] | 408 | // This method is invoked when the load is done, i.e. the spinner of the tab |
| 409 | // will stop spinning, and the onload event was dispatched. |
clamy | b876f0a7 | 2015-09-24 20:01:05 | [diff] [blame] | 410 | // |
| 411 | // If the WebContents is displaying replacement content, e.g. network error |
| 412 | // pages, DidFinishLoad is invoked for frames that were not sending |
| 413 | // navigational events before. It is safe to ignore these events. |
| 414 | virtual void DidFinishLoad(RenderFrameHost* render_frame_host, |
| 415 | const GURL& validated_url) {} |
| 416 | |
| 417 | // This method is like DidFinishLoad, but when the load failed or was |
| 418 | // cancelled, e.g. window.stop() is invoked. |
| 419 | virtual void DidFailLoad(RenderFrameHost* render_frame_host, |
| 420 | const GURL& validated_url, |
Dave Tapuska | 924ef3c | 2020-01-22 18:20:59 | [diff] [blame] | 421 | int error_code) {} |
clamy | b876f0a7 | 2015-09-24 20:01:05 | [diff] [blame] | 422 | |
cjgrant | 6d1d727a | 2016-12-09 21:16:57 | [diff] [blame] | 423 | // This method is invoked when the visible security state of the page changes. |
| 424 | virtual void DidChangeVisibleSecurityState() {} |
lgarron | 662dd52 | 2015-06-08 23:20:01 | [diff] [blame] | 425 | |
[email protected] | b0f724c | 2013-09-05 04:21:13 | [diff] [blame] | 426 | // This method is invoked when content was loaded from an in-memory cache. |
| 427 | virtual void DidLoadResourceFromMemoryCache( |
Lucas Furukawa Gadani | 07b45e15 | 2021-04-14 00:56:44 | [diff] [blame] | 428 | RenderFrameHost* render_frame_host, |
jam | 91dd24e | 2016-08-12 17:16:42 | [diff] [blame] | 429 | const GURL& url, |
| 430 | const std::string& mime_type, |
Kinuko Yasuda | 433f710a | 2020-02-14 02:11:58 | [diff] [blame] | 431 | network::mojom::RequestDestination request_destination) {} |
[email protected] | b0f724c | 2013-09-05 04:21:13 | [diff] [blame] | 432 | |
Jay Civelli | 718fd6c0 | 2018-05-11 21:04:27 | [diff] [blame] | 433 | // This method is invoked when a resource associate with the frame |
Clark DuVall | 36164bd | 2018-08-09 22:49:08 | [diff] [blame] | 434 | // |render_frame_host| has been loaded, successfully or not. |request_id| will |
| 435 | // only be populated for main frame resources. |
Jay Civelli | 116683f | 2018-03-27 19:56:23 | [diff] [blame] | 436 | virtual void ResourceLoadComplete( |
Jay Civelli | 718fd6c0 | 2018-05-11 21:04:27 | [diff] [blame] | 437 | RenderFrameHost* render_frame_host, |
Clark DuVall | 36164bd | 2018-08-09 22:49:08 | [diff] [blame] | 438 | const GlobalRequestID& request_id, |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 439 | const blink::mojom::ResourceLoadInfo& resource_load_info) {} |
[email protected] | b0f724c | 2013-09-05 04:21:13 | [diff] [blame] | 440 | |
Alexander Timin | 1cc31f4 | 2020-05-12 16:26:01 | [diff] [blame] | 441 | // Called when document reads or sets a cookie (either via document.cookie or |
| 442 | // issuing a network request). |
| 443 | // Cookie reads/writes for a dedicated worker are attributed to the |
| 444 | // RenderFrameHost which created it. |
| 445 | virtual void OnCookiesAccessed(RenderFrameHost* render_frame_host, |
| 446 | const CookieAccessDetails& details) {} |
| 447 | |
| 448 | // Called when a network request issued by the navigation reads or sets a |
| 449 | // cookie. If a notification is received after the navigation has committed, |
| 450 | // it will be attributed to the RenderFrameHost created by the navigation. |
| 451 | virtual void OnCookiesAccessed(NavigationHandle* navigation_handle, |
| 452 | const CookieAccessDetails& details) {} |
Josh Karlin | daba3932 | 2019-07-17 23:24:33 | [diff] [blame] | 453 | |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 454 | // This method is invoked when a new non-pending navigation entry is created. |
| 455 | // This corresponds to one NavigationController entry being created |
| 456 | // (in the case of new navigations) or renavigated to (for back/forward |
| 457 | // navigations). |
Yoshisato Yanagisawa | 8414148 | 2021-11-24 23:46:42 | [diff] [blame] | 458 | // |
| 459 | // Note that this function is only dispatched for NavigationEntries of primary |
| 460 | // pages (e.g. not for prerendered pages or fenced frames). |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 461 | virtual void NavigationEntryCommitted( |
| 462 | const LoadCommittedDetails& load_details) {} |
| 463 | |
Sam McNally | 5c087a3 | 2017-08-25 01:46:14 | [diff] [blame] | 464 | // Invoked when the NavigationController decreased its back/forward list count |
| 465 | // by removing entries from either the front or back of its list. This is |
| 466 | // usually the result of going back and then doing a new navigation, meaning |
| 467 | // all the "forward" items are deleted. |
| 468 | // |
| 469 | // This normally happens as a result of a new navigation. It will be |
| 470 | // followed by a NavigationEntryCommitted() call for the new page that |
| 471 | // caused the pruning. It could also be a result of removing an item from |
Christian Dullweber | b13ffda | 2018-02-23 11:42:14 | [diff] [blame] | 472 | // the list to delete history or fix up after interstitials. |
Sam McNally | 5c087a3 | 2017-08-25 01:46:14 | [diff] [blame] | 473 | virtual void NavigationListPruned(const PrunedDetails& pruned_details) {} |
| 474 | |
Christian Dullweber | 1af31e6 | 2018-02-22 11:49:48 | [diff] [blame] | 475 | // Invoked when NavigationEntries have been deleted because of a history |
| 476 | // deletion. Observers should ensure that they remove all traces of the |
| 477 | // deleted entries. |
| 478 | virtual void NavigationEntriesDeleted() {} |
| 479 | |
Sam McNally | 5c087a3 | 2017-08-25 01:46:14 | [diff] [blame] | 480 | // Invoked when a NavigationEntry has changed. |
| 481 | // |
| 482 | // This will NOT be sent on navigation, interested parties should also |
| 483 | // implement NavigationEntryCommitted() to handle that case. This will be |
| 484 | // sent when the entry is updated outside of navigation (like when a new |
| 485 | // title comes). |
| 486 | virtual void NavigationEntryChanged( |
| 487 | const EntryChangedDetails& change_details) {} |
| 488 | |
[email protected] | 87eca18 | 2013-01-31 21:20:00 | [diff] [blame] | 489 | // This method is invoked when a new WebContents was created in response to |
| 490 | // an action in the observed WebContents, e.g. a link with target=_blank was |
creis | 114ca1b | 2014-11-13 23:51:46 | [diff] [blame] | 491 | // clicked. The |source_render_frame_host| is the frame in which the action |
| 492 | // took place. |
[email protected] | 26b5e32 | 2011-12-23 01:36:47 | [diff] [blame] | 493 | virtual void DidOpenRequestedURL(WebContents* new_contents, |
creis | 114ca1b | 2014-11-13 23:51:46 | [diff] [blame] | 494 | RenderFrameHost* source_render_frame_host, |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 495 | const GURL& url, |
| 496 | const Referrer& referrer, |
| 497 | WindowOpenDisposition disposition, |
pnoland | 48894465 | 2017-02-22 18:58:54 | [diff] [blame] | 498 | ui::PageTransition transition, |
pnoland | aae574e | 2017-03-06 21:04:21 | [diff] [blame] | 499 | bool started_from_context_menu, |
| 500 | bool renderer_initiated) {} |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 501 | |
nasko | 00528252 | 2015-01-22 02:30:02 | [diff] [blame] | 502 | // This method is invoked when the renderer process has completed its first |
| 503 | // paint after a non-empty layout. |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 504 | virtual void DidFirstVisuallyNonEmptyPaint() {} |
[email protected] | 9f26807 | 2013-11-07 00:02:15 | [diff] [blame] | 505 | |
[email protected] | d16609c | 2013-08-23 06:01:40 | [diff] [blame] | 506 | // When WebContents::Stop() is called, the WebContents stops loading and then |
| 507 | // invokes this method. If there are ongoing navigations, their respective |
| 508 | // failure methods will also be invoked. |
| 509 | virtual void NavigationStopped() {} |
[email protected] | 87eca18 | 2013-01-31 21:20:00 | [diff] [blame] | 510 | |
dominickn | 2dd142dd | 2015-10-29 05:30:50 | [diff] [blame] | 511 | // Called when there has been direct user interaction with the WebContents. |
Emily Stark | c7bd40c4 | 2020-07-21 19:12:55 | [diff] [blame] | 512 | // The type of the event specifies the kind of interaction. Direct user input |
dominickn | ad9c99d | 2015-11-06 01:52:49 | [diff] [blame] | 513 | // signalled through this callback includes: |
| 514 | // 1) any mouse down event (blink::WebInputEvent::MouseDown); |
dominickn | 5cc29a4 | 2016-03-25 03:06:22 | [diff] [blame] | 515 | // 2) the start of a scroll (blink::WebInputEvent::GestureScrollBegin); |
Dominick Ng | 37a1505 | 2018-07-17 23:56:35 | [diff] [blame] | 516 | // 3) any raw key down event (blink::WebInputEvent::RawKeyDown); and |
| 517 | // 4) any touch event (inc. scrolls) (blink::WebInputEvent::TouchStart). |
Emily Stark | c7bd40c4 | 2020-07-21 19:12:55 | [diff] [blame] | 518 | virtual void DidGetUserInteraction(const blink::WebInputEvent& event) {} |
dominickn | 2dd142dd | 2015-10-29 05:30:50 | [diff] [blame] | 519 | |
[email protected] | 87eca18 | 2013-01-31 21:20:00 | [diff] [blame] | 520 | // This method is invoked when a RenderViewHost of this WebContents was |
| 521 | // configured to ignore UI events, and an UI event took place. |
| 522 | virtual void DidGetIgnoredUIEvent() {} |
| 523 | |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 524 | // Invoked every time the WebContents changes visibility. |
| 525 | virtual void OnVisibilityChanged(Visibility visibility) {} |
[email protected] | 3e32414 | 2012-06-25 18:26:33 | [diff] [blame] | 526 | |
Dave Tapuska | 1ca6d5f | 2021-10-13 22:40:03 | [diff] [blame] | 527 | // Invoked when the primary main frame changes size. |
| 528 | virtual void PrimaryMainFrameWasResized(bool width_changed) {} |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 529 | |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 530 | // Invoked when the given frame changes its window.name property. |
| 531 | virtual void FrameNameChanged(RenderFrameHost* render_frame_host, |
| 532 | const std::string& name) {} |
| 533 | |
Michael Bai | 19f17a30 | 2021-12-08 04:08:33 | [diff] [blame] | 534 | // Invoked when the color scheme of the primary main document of the |
| 535 | // WebContents is updated (either because the primary main document's color |
| 536 | // has been inferred or the primary main document has changed). |
| 537 | virtual void InferredColorSchemeUpdated( |
| 538 | absl::optional<blink::mojom::PreferredColorScheme> color_scheme) {} |
| 539 | |
John Delaney | b625dca9 | 2021-04-14 17:00:34 | [diff] [blame] | 540 | // Called when a frame receives user activation. This may be called multiple |
| 541 | // times for the same frame. This should not be used to determine a |
| 542 | // RenderFrameHost's user activation state. Does not include frames activated |
| 543 | // by the same-origin visibility heuristic, see `UserActivationState` for |
| 544 | // details. |
| 545 | virtual void FrameReceivedUserActivation(RenderFrameHost* render_frame_host) { |
| 546 | } |
John Delaney | edd8d6c | 2019-01-25 00:23:57 | [diff] [blame] | 547 | |
John Delaney | 0146a74 | 2019-01-25 19:25:28 | [diff] [blame] | 548 | // Invoked when the display state of the frame changes. |
| 549 | virtual void FrameDisplayStateChanged(RenderFrameHost* render_frame_host, |
| 550 | bool is_display_none) {} |
| 551 | |
| 552 | // Invoked when a frame changes size. |
| 553 | virtual void FrameSizeChanged(RenderFrameHost* render_frame_host, |
| 554 | const gfx::Size& frame_size) {} |
| 555 | |
Avi Drissman | a2ca5b14 | 2017-11-14 21:10:47 | [diff] [blame] | 556 | // This method is invoked when the title of the WebContents is set. Note that |
| 557 | // |entry| may be null if the web page whose title changed has not yet had a |
| 558 | // NavigationEntry assigned to it. |
Avi Drissman | 9300221 | 2017-09-27 03:20:52 | [diff] [blame] | 559 | virtual void TitleWasSet(NavigationEntry* entry) {} |
[email protected] | 6679890 | 2013-10-01 18:40:16 | [diff] [blame] | 560 | |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 561 | // These methods are invoked when a Pepper plugin instance is created/deleted |
| 562 | // in the DOM. |
| 563 | virtual void PepperInstanceCreated() {} |
| 564 | virtual void PepperInstanceDeleted() {} |
| 565 | |
Becca Hughes | 6fe54e43 | 2018-06-09 04:18:56 | [diff] [blame] | 566 | // This method is called when the viewport fit of a WebContents changes. |
| 567 | virtual void ViewportFitChanged(blink::mojom::ViewportFit value) {} |
| 568 | |
[email protected] | 3fc07c5 | 2012-04-20 00:27:44 | [diff] [blame] | 569 | // Notification that a plugin has crashed. |
[email protected] | cf4d6e74 | 2013-01-10 14:06:42 | [diff] [blame] | 570 | // |plugin_pid| is the process ID identifying the plugin process. Note that |
nasko | 00528252 | 2015-01-22 02:30:02 | [diff] [blame] | 571 | // this ID is supplied by the renderer process, so should not be trusted. |
| 572 | // Besides, the corresponding process has probably died at this point. The ID |
| 573 | // may even have been reused by a new process. |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 574 | virtual void PluginCrashed(const base::FilePath& plugin_path, |
[email protected] | cf4d6e74 | 2013-01-10 14:06:42 | [diff] [blame] | 575 | base::ProcessId plugin_pid) {} |
[email protected] | 3fc07c5 | 2012-04-20 00:27:44 | [diff] [blame] | 576 | |
[email protected] | d16609c | 2013-08-23 06:01:40 | [diff] [blame] | 577 | // Notification that the given plugin has hung or become unhung. This |
[email protected] | 3fc07c5 | 2012-04-20 00:27:44 | [diff] [blame] | 578 | // notification is only for Pepper plugins. |
| 579 | // |
| 580 | // The plugin_child_id is the unique child process ID from the plugin. Note |
nasko | 00528252 | 2015-01-22 02:30:02 | [diff] [blame] | 581 | // that this ID is supplied by the renderer process, so should be validated |
| 582 | // before it's used for anything in case there's an exploited renderer |
| 583 | // process. |
[email protected] | 3fc07c5 | 2012-04-20 00:27:44 | [diff] [blame] | 584 | virtual void PluginHungStatusChanged(int plugin_child_id, |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 585 | const base::FilePath& plugin_path, |
[email protected] | 3fc07c5 | 2012-04-20 00:27:44 | [diff] [blame] | 586 | bool is_hung) {} |
| 587 | |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 588 | // Notifies that an inner WebContents instance has been created with the |
| 589 | // observed WebContents as its container. |inner_web_contents| has not been |
| 590 | // added to the WebContents tree at this point, but can be observed safely. |
| 591 | virtual void InnerWebContentsCreated(WebContents* inner_web_contents) {} |
| 592 | |
Chris Hamilton | 16b5d1d | 2020-06-04 00:08:12 | [diff] [blame] | 593 | // Notifies that an |inner_web_contents| instance has been attached to the |
| 594 | // provided |render_frame_host|. By the time this is called the |
| 595 | // |inner_web_contents| will have been added to the WebContents tree. |
| 596 | virtual void InnerWebContentsAttached(WebContents* inner_web_contents, |
| 597 | RenderFrameHost* render_frame_host, |
| 598 | bool is_full_page) {} |
| 599 | |
| 600 | // Notifies that an |inner_web_contents| instance has been detached from this |
| 601 | // WebContents. InnerWebContentsAttached() will already have been called for |
| 602 | // the |inner_web_contents|. By the time this is called the |
| 603 | // |inner_web_contents| will have been removed from the WebContents tree, but |
| 604 | // will still be alive and is safe to observe. |
| 605 | virtual void InnerWebContentsDetached(WebContents* inner_web_contents) {} |
| 606 | |
[email protected] | 7381d9f | 2012-09-12 20:26:22 | [diff] [blame] | 607 | // Invoked when WebContents::Clone() was used to clone a WebContents. |
| 608 | virtual void DidCloneToNewWebContents(WebContents* old_web_contents, |
| 609 | WebContents* new_web_contents) {} |
| 610 | |
[email protected] | 26b5e32 | 2011-12-23 01:36:47 | [diff] [blame] | 611 | // Invoked when the WebContents is being destroyed. Gives subclasses a chance |
[email protected] | 12a4683 | 2014-05-09 13:35:58 | [diff] [blame] | 612 | // to cleanup. After the whole loop over all WebContentsObservers has been |
mlamouri | 8c61ffc | 2015-01-13 16:17:59 | [diff] [blame] | 613 | // finished, web_contents() returns nullptr. |
[email protected] | 12a4683 | 2014-05-09 13:35:58 | [diff] [blame] | 614 | virtual void WebContentsDestroyed() {} |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 615 | |
[email protected] | 8d0f331 | 2012-08-18 01:47:53 | [diff] [blame] | 616 | // Called when the user agent override for a WebContents has been changed. |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 617 | virtual void UserAgentOverrideSet( |
| 618 | const blink::UserAgentOverride& ua_override) {} |
[email protected] | 8d0f331 | 2012-08-18 01:47:53 | [diff] [blame] | 619 | |
Miyoung Shin | 5709ab0 | 2020-02-19 06:50:41 | [diff] [blame] | 620 | // Invoked when new blink::mojom::FaviconURLPtr candidates are received from |
| 621 | // the renderer process. If the instance is created after the page is loaded, |
| 622 | // it is recommended to call WebContents::GetFaviconURLs() to get the current |
| 623 | // list as this callback will not be executed unless there is an update. |
Sreeja Kamishetty | cfb4b86 | 2022-03-29 16:59:39 | [diff] [blame] | 624 | // `render_frame_host` is the main RenderFrameHost for the primary page. |
Miyoung Shin | 5709ab0 | 2020-02-19 06:50:41 | [diff] [blame] | 625 | virtual void DidUpdateFaviconURL( |
Yuzu Saijo | 0c263c70 | 2020-06-08 03:41:24 | [diff] [blame] | 626 | RenderFrameHost* render_frame_host, |
Miyoung Shin | 5709ab0 | 2020-02-19 06:50:41 | [diff] [blame] | 627 | const std::vector<blink::mojom::FaviconURLPtr>& candidates) {} |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 628 | |
Chris Hamilton | 16ca64a | 2020-05-14 23:13:17 | [diff] [blame] | 629 | // Called when an audio change occurs to this WebContents. If |audible| is |
| 630 | // true then one or more frames or child contents are emitting audio; if |
| 631 | // false, then no frames or child contents are emitting audio. See |
| 632 | // OnFrameAudioStateChanged for per-frame information. |
Chris Hamilton | eb41198f | 2018-05-24 18:41:26 | [diff] [blame] | 633 | virtual void OnAudioStateChanged(bool audible) {} |
| 634 | |
Chris Hamilton | 16ca64a | 2020-05-14 23:13:17 | [diff] [blame] | 635 | // Called when the audio state of an individual frame changes. |
| 636 | virtual void OnFrameAudioStateChanged(RenderFrameHost* rfh, bool audible) {} |
| 637 | |
Francois Doray | 66766a57 | 2019-12-17 20:56:49 | [diff] [blame] | 638 | // Called when the connected to Bluetooth device state changes. |
| 639 | virtual void OnIsConnectedToBluetoothDeviceChanged( |
| 640 | bool is_connected_to_bluetooth_device) {} |
| 641 | |
wjmaclean | 2f797c78 | 2016-01-07 14:52:03 | [diff] [blame] | 642 | // Invoked when the WebContents is muted/unmuted. |
| 643 | virtual void DidUpdateAudioMutingState(bool muted) {} |
| 644 | |
nasko | 00528252 | 2015-01-22 02:30:02 | [diff] [blame] | 645 | // Invoked when the renderer process has toggled the tab into/out of |
| 646 | // fullscreen mode. |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 647 | virtual void DidToggleFullscreenModeForTab(bool entered_fullscreen, |
| 648 | bool will_cause_resize) {} |
[email protected] | 657c8e0 | 2014-03-19 19:18:37 | [diff] [blame] | 649 | |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 650 | // Signals that |rfh| has the current fullscreen element. This is invoked |
| 651 | // when: |
| 652 | // 1) an element in this frame enters fullscreen or in nested fullscreen, or |
| 653 | // 2) after an element in a descendant frame exits fullscreen and makes |
| 654 | // this frame own the current fullscreen element again. |
| 655 | virtual void DidAcquireFullscreen(RenderFrameHost* rfh) {} |
| 656 | |
David Black | 9cca359 | 2019-11-06 23:02:22 | [diff] [blame] | 657 | // Invoked when the vertical scroll direction of the root layer is changed. |
| 658 | // Note that if a scroll in a given direction occurs, the scroll is completed, |
| 659 | // and then another scroll in the *same* direction occurs, we will not |
| 660 | // consider the second scroll event to have caused a change in direction. Also |
| 661 | // note that this API will *never* be called with |kNull| which only exists to |
| 662 | // indicate the absence of a vertical scroll direction. |
| 663 | virtual void DidChangeVerticalScrollDirection( |
| 664 | viz::VerticalScrollDirection scroll_direction) {} |
| 665 | |
[email protected] | 17e286e | 2013-03-01 23:29:39 | [diff] [blame] | 666 | // Invoked before a form repost warning is shown. |
| 667 | virtual void BeforeFormRepostWarningShow() {} |
| 668 | |
Chris Hamilton | 3b3e315d | 2018-09-19 13:16:21 | [diff] [blame] | 669 | // Invoked when the beforeunload handler fires. |proceed| is set to true if |
| 670 | // the beforeunload can safely proceed, otherwise it should be interrupted. |
| 671 | // The time is from the renderer process. |
| 672 | virtual void BeforeUnloadFired(bool proceed, |
| 673 | const base::TimeTicks& proceed_time) {} |
[email protected] | 6d65a46 | 2013-06-21 21:29:12 | [diff] [blame] | 674 | |
| 675 | // Invoked when a user cancels a before unload dialog. |
| 676 | virtual void BeforeUnloadDialogCancelled() {} |
| 677 | |
Mario Sanchez Prada | 5d7f1ac | 2020-07-16 17:18:40 | [diff] [blame] | 678 | // Called whenever the AXTreeID for the main frame has changed. |
| 679 | virtual void AXTreeIDForMainFrameHasChanged() {} |
| 680 | |
dmazzoni | dd3d51a7 | 2016-12-14 18:41:01 | [diff] [blame] | 681 | // Called when accessibility events or location changes are received |
| 682 | // from a render frame, but only when the accessibility mode has the |
Doug Turner | 63f3c7b | 2017-07-29 05:10:01 | [diff] [blame] | 683 | // ui::AXMode::kWebContents flag set. |
Dominic Mazzoni | a7b0edb2 | 2017-08-09 16:32:51 | [diff] [blame] | 684 | virtual void AccessibilityEventReceived( |
Dominic Mazzoni | ccbaa9b | 2018-06-06 07:44:23 | [diff] [blame] | 685 | const AXEventNotificationDetails& details) {} |
dmazzoni | 2400c46 | 2016-08-23 15:07:13 | [diff] [blame] | 686 | virtual void AccessibilityLocationChangesReceived( |
| 687 | const std::vector<AXLocationChangeNotificationDetails>& details) {} |
| 688 | |
Peter Kasting | b14e578 | 2020-01-06 23:55:04 | [diff] [blame] | 689 | // Invoked when theme color is changed. |
| 690 | virtual void DidChangeThemeColor() {} |
[email protected] | e710476 | 2014-06-20 19:17:25 | [diff] [blame] | 691 | |
Alan Cutter | d73a15d9 | 2020-08-21 07:12:45 | [diff] [blame] | 692 | // Invoked when background color is changed. |
| 693 | virtual void OnBackgroundColorChanged() {} |
| 694 | |
Tom Lukaszewicz | 22b784a4 | 2021-11-29 22:56:49 | [diff] [blame] | 695 | // Invoked when the ColorProvider instance associated with this WebContents |
| 696 | // has changed. |
| 697 | virtual void OnColorProviderChanged() {} |
| 698 | |
Devlin Cronin | 5ea668f3 | 2019-12-18 21:57:58 | [diff] [blame] | 699 | // Called when a message is added to the console of the WebContents. This is |
| 700 | // invoked before forwarding the message to the WebContents' delegate. |
Ian Barkley-Yeung | 07d8a26 | 2020-11-19 22:45:35 | [diff] [blame] | 701 | // |source_id| is a URL. |untrusted_stack_trace| is not present for most |
| 702 | // messages; only when requested in advance and only for exceptions. |
Devlin Cronin | 5ea668f3 | 2019-12-18 21:57:58 | [diff] [blame] | 703 | virtual void OnDidAddMessageToConsole( |
Ian Barkley-Yeung | addf092 | 2020-11-04 19:44:56 | [diff] [blame] | 704 | RenderFrameHost* source_frame, |
Devlin Cronin | 5ea668f3 | 2019-12-18 21:57:58 | [diff] [blame] | 705 | blink::mojom::ConsoleMessageLevel log_level, |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 706 | const std::u16string& message, |
Devlin Cronin | 5ea668f3 | 2019-12-18 21:57:58 | [diff] [blame] | 707 | int32_t line_no, |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 708 | const std::u16string& source_id, |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 709 | const absl::optional<std::u16string>& untrusted_stack_trace) {} |
Devlin Cronin | 5ea668f3 | 2019-12-18 21:57:58 | [diff] [blame] | 710 | |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 711 | // Invoked when media is playing or paused. |id| is unique per player and per |
| 712 | // RenderFrameHost. There may be multiple players within a RenderFrameHost |
| 713 | // and subsequently within a WebContents. MediaStartedPlaying() will always |
| 714 | // be followed by MediaStoppedPlaying() after player teardown. Observers must |
| 715 | // release all stored copies of |id| when MediaStoppedPlaying() is received. |
Mounir Lamouri | 366dd847 | 2018-06-19 17:20:04 | [diff] [blame] | 716 | // |has_video| and |has_audio| can both be false in cases where the media |
| 717 | // is playing muted and should be considered as inaudible for all intent and |
| 718 | // purposes. |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 719 | struct MediaPlayerInfo { |
Becca Hughes | 3f92136 | 2017-06-08 14:08:36 | [diff] [blame] | 720 | MediaPlayerInfo(bool has_video, bool has_audio) |
| 721 | : has_video(has_video), has_audio(has_audio) {} |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 722 | bool has_video; |
Becca Hughes | 3f92136 | 2017-06-08 14:08:36 | [diff] [blame] | 723 | bool has_audio; |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 724 | }; |
François Beaufort | ddaf8a8 | 2018-07-16 16:43:12 | [diff] [blame] | 725 | |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 726 | virtual void MediaStartedPlaying(const MediaPlayerInfo& video_type, |
| 727 | const MediaPlayerId& id) {} |
Becca Hughes | 220bfc10 | 2017-11-14 18:24:07 | [diff] [blame] | 728 | enum class MediaStoppedReason { |
| 729 | // The media was stopped for an unspecified reason. |
| 730 | kUnspecified, |
| 731 | |
| 732 | // The media was stopped because it reached the end of the stream. |
| 733 | kReachedEndOfStream, |
| 734 | }; |
| 735 | virtual void MediaStoppedPlaying( |
| 736 | const MediaPlayerInfo& video_type, |
| 737 | const MediaPlayerId& id, |
| 738 | WebContentsObserver::MediaStoppedReason reason) {} |
peconn | 25795152 | 2017-06-09 18:24:59 | [diff] [blame] | 739 | virtual void MediaResized(const gfx::Size& size, const MediaPlayerId& id) {} |
Peter E Conn | eccb34c2 | 2017-09-08 09:37:58 | [diff] [blame] | 740 | // Invoked when media enters or exits fullscreen. We must use a heuristic |
| 741 | // to determine this as it is not trivial for media with custom controls. |
| 742 | // There is a slight delay between media entering or exiting fullscreen |
| 743 | // and it being detected. |
| 744 | virtual void MediaEffectivelyFullscreenChanged(bool is_fullscreen) {} |
François Beaufort | a2f0a3ca | 2018-08-28 12:46:11 | [diff] [blame] | 745 | virtual void MediaPictureInPictureChanged(bool is_picture_in_picture) {} |
Becca Hughes | 9f6fd4b8 | 2017-06-15 10:01:40 | [diff] [blame] | 746 | virtual void MediaMutedStatusChanged(const MediaPlayerId& id, bool muted) {} |
Chris Hamilton | c347e10 | 2020-11-18 23:10:21 | [diff] [blame] | 747 | virtual void MediaDestroyed(const MediaPlayerId& id) {} |
prashantv | 0c9b968d2 | 2015-03-26 00:58:54 | [diff] [blame] | 748 | |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 749 | // Invoked when the renderer process changes the page scale factor. |
| 750 | virtual void OnPageScaleFactorChanged(float page_scale_factor) {} |
| 751 | |
Archana Simha | f67090c | 2019-05-06 23:43:23 | [diff] [blame] | 752 | // Invoked when a paste event occurs. |
| 753 | virtual void OnPaste() {} |
| 754 | |
[email protected] | 64ffefa | 2014-05-10 12:06:33 | [diff] [blame] | 755 | // Invoked if an IPC message is coming from a specific RenderFrameHost. |
| 756 | virtual bool OnMessageReceived(const IPC::Message& message, |
| 757 | RenderFrameHost* render_frame_host); |
| 758 | |
Michael Thiessen | 896405db | 2017-07-20 17:52:32 | [diff] [blame] | 759 | // Notification that the |render_widget_host| for this WebContents has gained |
| 760 | // focus. |
| 761 | virtual void OnWebContentsFocused(RenderWidgetHost* render_widget_host) {} |
calamity | 7fe55ce | 2015-04-10 03:59:37 | [diff] [blame] | 762 | |
Michael Thiessen | 896405db | 2017-07-20 17:52:32 | [diff] [blame] | 763 | // Notification that the |render_widget_host| for this WebContents has lost |
| 764 | // focus. |
| 765 | virtual void OnWebContentsLostFocus(RenderWidgetHost* render_widget_host) {} |
zijiehe | 3bee08e2 | 2017-05-17 04:14:46 | [diff] [blame] | 766 | |
Jeff Fisher | 709b4c5 | 2019-07-29 20:07:34 | [diff] [blame] | 767 | // Notification that a RenderFrameHost inside this WebContents has updated |
| 768 | // its focused element. |details| contains information on the element |
| 769 | // that has received focus. This allows for observing focus changes |
| 770 | // within WebContents, as opposed to OnWebContentsFocused/LostFocus |
| 771 | // which allows observation that the RenderWidgetHost for the |
| 772 | // WebContents has gained/lost focus. |
| 773 | virtual void OnFocusChangedInPage(FocusedNodeDetails* details) {} |
| 774 | |
Sam McNally | 145fb17 | 2017-05-10 00:13:23 | [diff] [blame] | 775 | // Notifies that the manifest URL for the main frame changed to |
| 776 | // |manifest_url|. This will be invoked when a document with a manifest loads |
| 777 | // or when the manifest URL changes (possibly to nothing). It is not invoked |
| 778 | // when a document with no manifest loads. During document load, if the |
| 779 | // document has both a manifest and a favicon, DidUpdateWebManifestURL() will |
Sreeja Kamishetty | cfb4b86 | 2022-03-29 16:59:39 | [diff] [blame] | 780 | // be invoked before DidUpdateFaviconURL(). `target_frame` is the main render |
| 781 | // frame host for the primary page. |
Julie Jeongeun Kim | d74c1e7f | 2021-06-18 04:06:18 | [diff] [blame] | 782 | virtual void DidUpdateWebManifestURL(RenderFrameHost* target_frame, |
| 783 | const GURL& manifest_url) {} |
Sam McNally | 145fb17 | 2017-05-10 00:13:23 | [diff] [blame] | 784 | |
Raymond Toy | e413650c | 2018-08-31 00:12:47 | [diff] [blame] | 785 | // Called when "audible" playback starts or stops on a WebAudio AudioContext. |
| 786 | using AudioContextId = std::pair<RenderFrameHost*, int>; |
| 787 | virtual void AudioContextPlaybackStarted( |
| 788 | const AudioContextId& audio_context_id) {} |
| 789 | virtual void AudioContextPlaybackStopped( |
| 790 | const AudioContextId& audio_context_id) {} |
| 791 | |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 792 | // Called when the RenderFrameHost tries to use a ServiceWorker |
| 793 | // (e.g. via navigation.serviceWorker API). |
| 794 | virtual void OnServiceWorkerAccessed(RenderFrameHost* render_frame_host, |
| 795 | const GURL& scope, |
| 796 | AllowServiceWorkerResult allowed) {} |
| 797 | // Called when the NavigationHandle accesses ServiceWorker to see if the |
| 798 | // network request should be handled by the ServiceWorker instead |
| 799 | // (e.g. for navigations to URLs which are in scope of a ServiceWorker). |
| 800 | virtual void OnServiceWorkerAccessed(NavigationHandle* navigation_handle, |
| 801 | const GURL& scope, |
| 802 | AllowServiceWorkerResult allowed) {} |
lucinka.brozkova | c25f7fb9 | 2014-09-04 06:42:56 | [diff] [blame] | 803 | WebContents* web_contents() const; |
| 804 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 805 | protected: |
[email protected] | 26b5e32 | 2011-12-23 01:36:47 | [diff] [blame] | 806 | // Use this constructor when the object is tied to a single WebContents for |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 807 | // its entire lifetime. |
[email protected] | 26b5e32 | 2011-12-23 01:36:47 | [diff] [blame] | 808 | explicit WebContentsObserver(WebContents* web_contents); |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 809 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 810 | // Use this constructor when the object wants to observe a WebContents for |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 811 | // part of its lifetime. It can then call Observe() to start and stop |
| 812 | // observing. |
| 813 | WebContentsObserver(); |
| 814 | |
Dave Tapuska | 34310de | 2021-06-02 20:21:01 | [diff] [blame] | 815 | virtual ~WebContentsObserver(); |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 816 | |
[email protected] | 26b5e32 | 2011-12-23 01:36:47 | [diff] [blame] | 817 | // Start observing a different WebContents; used with the default constructor. |
| 818 | void Observe(WebContents* web_contents); |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 819 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 820 | private: |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 821 | friend class WebContentsImpl; |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 822 | |
[email protected] | 12a4683 | 2014-05-09 13:35:58 | [diff] [blame] | 823 | void ResetWebContents(); |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 824 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 825 | raw_ptr<WebContents> web_contents_ = nullptr; |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 826 | }; |
| 827 | |
| 828 | } // namespace content |
| 829 | |
| 830 | #endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ |