blob: 632c50bb0b4fcfa66141fa3f4a39815c4e9d84b9 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2012 The Chromium Authors
[email protected]6934a702011-12-20 00:04:512// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]58f5d562011-12-20 17:13:035#ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_H_
6#define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_H_
[email protected]6934a702011-12-20 00:04:517
Lei Zhangfcf71672021-05-14 16:28:208#include <stddef.h>
avi652869c2015-12-25 01:48:459#include <stdint.h>
10
avie865b1d2016-10-24 19:42:5911#include <memory>
Arthur Sonzognic686e8f2024-01-11 08:36:3712#include <optional>
Lukasz Anforowicze9ae3722017-09-29 17:37:3813#include <string>
14#include <vector>
[email protected]c3c10f22013-07-25 14:21:1215
Avi Drissmanadac21992023-01-11 23:46:3916#include "base/functional/callback_forward.h"
17#include "base/functional/callback_helpers.h"
Daniel Cheng982f2b22022-08-25 23:46:1618#include "base/functional/function_ref.h"
Lukasz Anforowicz2c1573a2021-09-21 18:58:1819#include "base/location.h"
Keishi Hattori0e45c022021-11-27 09:25:5220#include "base/memory/raw_ptr.h"
mikt24c74622023-11-28 05:46:3121#include "base/memory/safety_checks.h"
Lei Zhangfcf71672021-05-14 16:28:2022#include "base/memory/scoped_refptr.h"
Claudio DeSouza2be02d42021-08-12 23:23:4023#include "base/memory/weak_ptr.h"
[email protected]c3c10f22013-07-25 14:21:1224#include "base/process/kill.h"
[email protected]36a22c42012-08-23 00:03:1125#include "base/supports_user_data.h"
Sebastien Marchand28cf23182018-06-20 02:39:3526#include "base/time/time.h"
avi652869c2015-12-25 01:48:4527#include "build/build_config.h"
Yoshisato Yanagisawa607a7cca2021-10-14 02:45:3628#include "cc/input/browser_controls_state.h"
[email protected]6934a702011-12-20 00:04:5129#include "content/common/content_export.h"
[email protected]7f924832014-08-09 05:57:2230#include "content/public/browser/invalidate_type.h"
Angel Alvarez902496682019-08-27 22:58:4231#include "content/public/browser/mhtml_generation_result.h"
[email protected]d1198fd2012-08-13 22:50:1932#include "content/public/browser/navigation_controller.h"
Sreeja Kamishetty3dde6312021-06-22 14:05:2933#include "content/public/browser/page.h"
[email protected]e5d549d2011-12-28 01:29:2034#include "content/public/browser/page_navigator.h"
Domenic Denicolabb5d843c2023-07-18 01:47:3335#include "content/public/browser/preloading.h"
Kouhei Ueno3f37992b2023-11-09 23:29:0236#include "content/public/browser/preloading_trigger_type.h"
Robert Linc37fb582021-11-11 03:18:4737#include "content/public/browser/prerender_handle.h"
[email protected]a53209b2012-01-20 16:48:1638#include "content/public/browser/save_page_type.h"
Francois Dorayfe4a1772018-02-17 04:17:0939#include "content/public/browser/visibility.h"
[email protected]36ec24f2014-01-09 00:32:0840#include "content/public/common/stop_find_action.h"
Avi Drissman0b2a20d2021-12-08 00:59:1641#include "services/network/public/mojom/web_sandbox_flags.mojom-shared.h"
Hans Wennborg3e67bab2021-04-08 11:34:3142#include "third_party/blink/public/mojom/favicon/favicon_url.mojom-forward.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:5643#include "third_party/blink/public/mojom/frame/find_in_page.mojom-forward.h"
Lei Zhang96fce972022-08-05 23:15:0744#include "third_party/blink/public/mojom/frame/remote_frame.mojom-forward.h"
James Hollyerd5c9de462020-03-10 19:02:4545#include "third_party/blink/public/mojom/input/pointer_lock_result.mojom.h"
Lei Zhang3ee2b78a2021-05-18 20:58:4446#include "third_party/blink/public/mojom/media/capture_handle_config.mojom-forward.h"
Bryant Chandler490c6de2024-01-02 22:08:3647#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-forward.h"
Tommy Steimel57eafde2023-01-27 17:33:2448#include "third_party/blink/public/mojom/picture_in_picture_window_options/picture_in_picture_window_options.mojom.h"
Alexander Timine9f413e82021-03-12 14:06:4449#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"
[email protected]da8543762012-03-20 08:52:2050#include "third_party/skia/include/core/SkColor.h"
Dominic Mazzoni90501482018-09-05 22:43:3151#include "ui/accessibility/ax_mode.h"
Nektarios Paisios8e9da982024-02-20 23:14:2252#include "ui/accessibility/ax_node.h"
Jacques Newmane313e142024-03-13 18:47:2253#include "ui/accessibility/platform/inspect/ax_api_type.h"
Andy Paicu5608bda82023-03-03 15:09:2054#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
Sean Kaufc4c41c2023-06-22 16:21:5455#include "ui/color/color_provider_key.h"
Mike Wassermanb6bc0152020-08-25 22:46:2056#include "ui/display/types/display_constants.h"
tfarina3b0452d2014-12-31 15:20:0957#include "ui/gfx/geometry/rect.h"
Lei Zhangfcf71672021-05-14 16:28:2058#include "ui/gfx/geometry/size.h"
[email protected]0bfbf882011-12-22 18:19:2759#include "ui/gfx/native_widget_types.h"
Lei Zhangfcf71672021-05-14 16:28:2060#include "url/gurl.h"
[email protected]6934a702011-12-20 00:04:5161
Xiaohan Wang6099ccb2022-01-13 22:09:4262#if BUILDFLAG(IS_ANDROID)
[email protected]155c7f22013-12-09 17:07:1863#include "base/android/scoped_java_ref.h"
64#endif
65
Lei Zhang17575082021-05-10 20:19:1866namespace base {
67class FilePath;
Lei Zhang17575082021-05-10 20:19:1868} // namespace base
69
Dmitry Gozman88ca5a992018-05-18 00:13:3370namespace blink {
Gyuyoung Kim1ac4ca782020-09-11 03:32:5171namespace web_pref {
72struct WebPreferences;
73}
Takashi Toyoshimad72a465a2024-03-11 23:37:3174class WebInputEvent;
Maks Orlovich73f374d2020-04-02 12:46:1375struct UserAgentOverride;
Mario Sanchez Prada0bd8b8c2020-10-21 17:49:2376struct RendererPreferences;
Leon Hanc819dc62019-01-28 04:30:1977} // namespace blink
Dmitry Gozman88ca5a992018-05-18 00:13:3378
ke.he98b761e2017-05-09 05:59:1779namespace device {
80namespace mojom {
81class WakeLockContext;
82}
83}
84
[email protected]be1f56ab2011-12-22 06:55:3185namespace net {
86struct LoadStateWithParam;
[email protected]6934a702011-12-20 00:04:5187}
88
rockot400ea35b2016-10-15 19:15:3289namespace service_manager {
sammcf5f1b0f2016-09-20 23:05:1190class InterfaceProvider;
91}
92
Alexander Surkovbe2878f2020-11-03 18:25:2593namespace ui {
94struct AXPropertyFilter;
Lei Zhangfcf71672021-05-14 16:28:2095struct AXTreeUpdate;
Tom Lukaszewicz63b3da52022-01-26 01:37:5796class ColorProvider;
tom855c4bf32021-09-30 00:27:2697class ColorProviderSource;
Alexander Surkovbe2878f2020-11-03 18:25:2598}
99
[email protected]6934a702011-12-20 00:04:51100namespace content {
101
William Liu6cf58fe2024-01-19 21:29:32102class BackForwardTransitionAnimationManager;
[email protected]627e0512011-12-21 22:55:30103class BrowserContext;
[email protected]4858e432014-06-23 18:14:17104class BrowserPluginGuestDelegate;
[email protected]60eca4eb2013-12-06 00:02:16105class RenderFrameHost;
[email protected]eaabba22012-03-07 15:02:11106class RenderViewHost;
[email protected]5626b0892012-02-20 14:46:58107class RenderWidgetHostView;
Lei Zhangfcf71672021-05-14 16:28:20108class ScreenOrientationDelegate;
109class SiteInstance;
[email protected]adbfb8df2012-02-24 01:19:43110class WebContentsDelegate;
Lei Zhang4b21e9c2020-02-28 00:32:02111class WebUI;
[email protected]fc2b46b2014-05-03 16:33:45112struct DropData;
dewittj6dc5747a2016-05-17 01:48:47113struct MHTMLGenerationParams;
Sreeja Kamishettyac12140e2022-07-14 22:16:51114class PreloadingAttempt;
[email protected]674bc592011-12-20 23:00:42115
[email protected]a906995f2012-12-17 23:30:48116// WebContents is the core class in content/. A WebContents renders web content
117// (usually HTML) in a rectangular area.
118//
119// Instantiating one is simple:
dcheng6003e0b2016-04-09 18:42:34120// std::unique_ptr<content::WebContents> web_contents(
[email protected]a906995f2012-12-17 23:30:48121// content::WebContents::Create(
122// content::WebContents::CreateParams(browser_context)));
[email protected]fc2b46b2014-05-03 16:33:45123// gfx::NativeView view = web_contents->GetNativeView();
Nick Diego Yamaneee67b3c2019-07-01 23:20:37124// // |view| is an HWND, NSView*, etc.; insert it into the view hierarchy
125// // wherever it needs to go.
[email protected]a906995f2012-12-17 23:30:48126//
127// That's it; go to your kitchen, grab a scone, and chill. WebContents will do
128// all the multi-process stuff behind the scenes. More details are at
Adam Langley4463fb832018-01-28 22:42:26129// https://www.chromium.org/developers/design-documents/multi-process-architecture
dcheng6003e0b2016-04-09 18:42:34130// .
[email protected]a906995f2012-12-17 23:30:48131//
Lukasz Anforowicz7a0381c2022-12-07 20:23:08132// The owner of `std::unique_ptr<content::WebContents> web_contents` is
133// responsible for ensuring that `web_contents` are destroyed (e.g. closed)
134// *before* the corresponding `browser_context` is destroyed.
135//
Kevin McNee88bf2242022-11-23 00:27:34136// Each WebContents has a `NavigationController`, which can be obtained from
137// `GetController()`, and is used to load URLs into the WebContents, navigate
138// it backwards/forwards, etc.
139// See navigation_controller.h for more details.
[email protected]36a22c42012-08-23 00:03:11140class WebContents : public PageNavigator,
[email protected]36a22c42012-08-23 00:03:11141 public base::SupportsUserData {
mikt24c74622023-11-28 05:46:31142 // Do not remove this macro!
143 // The macro is maintained by the memory safety team.
144 ADVANCED_MEMORY_SAFETY_CHECKS();
145
[email protected]6934a702011-12-20 00:04:51146 public:
[email protected]54944cde2012-12-09 09:24:59147 struct CONTENT_EXPORT CreateParams {
Lukasz Anforowicz2c1573a2021-09-21 18:58:18148 explicit CreateParams(
149 BrowserContext* context,
150 base::Location creator_location = base::Location::Current());
Lukasz Anforowicz2c1573a2021-09-21 18:58:18151 CreateParams(BrowserContext* context,
152 scoped_refptr<SiteInstance> site,
153 base::Location creator_location = base::Location::Current());
Avi Drissman0b2a20d2021-12-08 00:59:16154 CreateParams(const CreateParams& other);
155 ~CreateParams();
[email protected]54944cde2012-12-09 09:24:59156
Keishi Hattori0e45c022021-11-27 09:25:52157 raw_ptr<BrowserContext> browser_context;
[email protected]a902d9a2013-08-08 16:05:09158
159 // Specifying a SiteInstance here is optional. It can be set to avoid an
160 // extra process swap if the first navigation is expected to require a
161 // privileged process.
dchengbccd6b82016-03-30 16:24:19162 scoped_refptr<SiteInstance> site_instance;
[email protected]a902d9a2013-08-08 16:05:09163
alexmose201c7cd2015-06-10 17:14:21164 // The process id of the frame initiating the open.
Avi Drissman0b2a20d2021-12-08 00:59:16165 int opener_render_process_id = content::ChildProcessHost::kInvalidUniqueID;
alexmose201c7cd2015-06-10 17:14:21166
167 // The routing id of the frame initiating the open.
Avi Drissman0b2a20d2021-12-08 00:59:16168 int opener_render_frame_id = MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:06169
170 // If the opener is suppressed, then the new WebContents doesn't hold a
171 // reference to its opener.
Avi Drissman0b2a20d2021-12-08 00:59:16172 bool opener_suppressed = false;
avic2c29d782014-12-12 00:23:54173
Rakina Zata Amnic7ffea882021-08-16 10:04:28174 // Indicates whether this WebContents was created by another window.
alexmos090fae8e2015-05-28 17:09:28175 // This is used when determining whether the WebContents is allowed to be
176 // closed via window.close(). This may be true even with a null |opener|
Rakina Zata Amnic7ffea882021-08-16 10:04:28177 // (e.g., for blocked popups), or when the window is opened with "noopener".
Avi Drissman0b2a20d2021-12-08 00:59:16178 bool opened_by_another_window = false;
alexmos090fae8e2015-05-28 17:09:28179
naskoc9f51dd2015-05-13 00:39:28180 // The name of the top-level frame of the new window. It is non-empty
181 // when creating a named window (e.g. <a target="foo"> or
182 // window.open('', 'bar')).
183 std::string main_frame_name;
184
arthursonzogni034bb9c2020-10-01 08:29:56185 // New window starts from the initial empty document. When created by an
186 // opener, the latter can request an initial navigation attempt to be made.
187 // This is the url specified in: `window.open(initial_popup_url, ...)`.
188 // This is empty otherwise.
189 GURL initial_popup_url;
190
[email protected]1ac10dca2013-08-20 20:47:04191 // True if the contents should be initially hidden.
Avi Drissman0b2a20d2021-12-08 00:59:16192 bool initially_hidden = false;
[email protected]1ac10dca2013-08-20 20:47:04193
[email protected]4858e432014-06-23 18:14:17194 // If non-null then this WebContents will be hosted by a BrowserPlugin.
Avi Drissman0b2a20d2021-12-08 00:59:16195 raw_ptr<BrowserPluginGuestDelegate> guest_delegate = nullptr;
[email protected]83100cd2014-05-10 11:50:06196
[email protected]54944cde2012-12-09 09:24:59197 // Used to specify the location context which display the new view should
Avi Drissmandad01b0e2023-06-16 22:55:46198 // belong. This can be unset if not needed.
199 gfx::NativeView context = gfx::NativeView();
naskob21fe4872015-02-24 14:15:56200
201 // Used to specify that the new WebContents creation is driven by the
202 // renderer process. In this case, the renderer-side objects, such as
203 // RenderFrame, have already been created on the renderer side, and
204 // WebContents construction should take this into account.
Avi Drissman0b2a20d2021-12-08 00:59:16205 bool renderer_initiated_creation = false;
lof84501da082016-05-23 21:22:54206
Lukasz Anforowicz3caa8372018-06-05 17:22:07207 // Used to specify how far WebContents::Create can initialize a renderer
208 // process.
209 //
210 // This is useful in two scenarios:
211 // - Conserving resources - e.g. tab discarding and session restore do not
212 // want to use an actual renderer process before the WebContents are
213 // loaded or reloaded. This can be accomplished via kNoRendererProcess.
214 // - Avoiding the latency of the first navigation
215 // - kInitializeAndWarmupRendererProcess is most aggressive in avoiding
216 // the latency, but may be incompatible with scenarios that require
217 // manipulating the freshly created WebContents prior to initializing
218 // renderer-side objects (e.g. in scenarios like
219 // WebContentsImpl::CreateNewWindow which needs to copy the
220 // SessionStorageNamespace)
221 // - kOkayToHaveRendererProcess is the default latency-conserving mode.
222 // In this mode a spare, pre-spawned RenderProcessHost may be claimed
223 // by the newly created WebContents, but no renderer-side objects will
224 // be initialized from within WebContents::Create method.
225 //
lof84501da082016-05-23 21:22:54226 // Note that the pre-created renderer process may not be used if the first
227 // navigation requires a dedicated or privileged process, such as a WebUI.
Lukasz Anforowicz3caa8372018-06-05 17:22:07228 // This can be avoided by ensuring that |site_instance| matches the first
229 // navigation's destination.
230 enum RendererInitializationState {
231 // Creation of WebContents should not spawn a new OS process and should
232 // not reuse a RenderProcessHost that might be associated with an existing
233 // OS process (as in the case of SpareRenderProcessHostManager).
234 kNoRendererProcess,
235
236 // Created WebContents may or may not be associated with an actual OS
237 // process.
238 kOkayToHaveRendererProcess,
239
240 // Ensures that the created WebContents are backed by an OS process which
Dave Tapuska2cf1f532022-08-10 15:30:49241 // has an initialized `blink::WebView`.
Lukasz Anforowicz3caa8372018-06-05 17:22:07242 //
243 // TODO(lukasza): https://crbug.com/848366: Remove
244 // kInitializeAndWarmupRendererProcess value - warming up the renderer by
Dave Tapuska2cf1f532022-08-10 15:30:49245 // initializing the `blink::WebView` is redundant with the warm-up that
246 // can be
Lukasz Anforowicz3caa8372018-06-05 17:22:07247 // achieved by either 1) warming up the spare renderer before creating
248 // WebContents and/or 2) speculative RenderFrameHost used internally
249 // during a navigation.
250 kInitializeAndWarmupRendererProcess,
Avi Drissman0b2a20d2021-12-08 00:59:16251 } desired_renderer_state = kOkayToHaveRendererProcess;
mark a. foltzef394fce2017-10-21 09:11:02252
253 // Sandboxing flags set on the new WebContents.
Avi Drissman0b2a20d2021-12-08 00:59:16254 network::mojom::WebSandboxFlags starting_sandbox_flags =
255 network::mojom::WebSandboxFlags::kNone;
Sebastien Marchand28cf23182018-06-20 02:39:35256
257 // Value used to set the last time the WebContents was made active, this is
258 // the value that'll be returned by GetLastActiveTime(). If this is left
259 // default initialized then the value is not passed on to the WebContents
260 // and GetLastActiveTime() will return the WebContents' creation time.
261 base::TimeTicks last_active_time;
Albert J. Wonge76bf0b82019-09-27 07:47:06262
Lukasz Anforowicz2c1573a2021-09-21 18:58:18263 // Code location responsible for creating the CreateParams. This is used
264 // mostly for debugging (e.g. to help attribute specific scenarios or
265 // invariant violations to a particular flavor of WebContents).
266 base::Location creator_location;
Thoren Paulsond344c0a2021-10-14 19:20:31267
Nicolas Ouellet-Payeur177a6c42023-01-25 20:25:07268#if BUILDFLAG(IS_ANDROID)
269 // Same as `creator_location`, for WebContents created via Java. This
270 // java.lang.Throwable contains the entire
271 // WebContentsCreator.createWebContents() stack trace.
272 base::android::ScopedJavaGlobalRef<jthrowable> java_creator_location;
273#endif // BUILDFLAG(IS_ANDROID)
274
Thoren Paulsond344c0a2021-10-14 19:20:31275 // Enables contents to hold wake locks, for example, to keep the screen on
276 // while playing video.
Avi Drissman0b2a20d2021-12-08 00:59:16277 bool enable_wake_locks = true;
Tommy Steimel991916c42022-06-24 20:59:57278
279 // Options specific to WebContents created for picture-in-picture windows.
Arthur Sonzognic686e8f2024-01-11 08:36:37280 std::optional<blink::mojom::PictureInPictureWindowOptions>
Tommy Steimel57eafde2023-01-27 17:33:24281 picture_in_picture_options;
Takashi Toyoshima881f4d72023-11-09 05:07:43282
Takashi Toyoshima8dfc05c2024-01-29 21:03:51283 // Enable preview mode that shows a page with a capability restriction
284 // for previewing the page.
285 bool preview_mode = false;
[email protected]54944cde2012-12-09 09:24:59286 };
287
Frank Liberatoe837b362023-10-20 23:31:15288 // Token that causes input to be blocked on this WebContents for at least as
289 // long as it exists.
290 class CONTENT_EXPORT ScopedIgnoreInputEvents {
291 public:
292 ~ScopedIgnoreInputEvents();
293
294 ScopedIgnoreInputEvents(ScopedIgnoreInputEvents&&);
295 ScopedIgnoreInputEvents& operator=(ScopedIgnoreInputEvents&&);
296
297 private:
298 friend class WebContentsImpl;
299 explicit ScopedIgnoreInputEvents(base::OnceClosure on_destruction_cb);
300
301 base::ScopedClosureRunner on_destruction_cb_;
302 };
303
[email protected]54944cde2012-12-09 09:24:59304 // Creates a new WebContents.
Lukasz Anforowicz7a0381c2022-12-07 20:23:08305 //
306 // The caller is responsible for ensuring that the returned WebContents is
307 // destroyed (e.g. closed) *before* the BrowserContext associated with
Lukasz Anforowicz16eddbc72022-12-19 20:08:43308 // `params` is destroyed. It is a security bug if WebContents haven't been
309 // destroyed when the destructor of BrowserContext starts running. It is not
Lukasz Anforowicz7a0381c2022-12-07 20:23:08310 // necessarily a bug if WebContents haven't been destroyed when
311 // BrowserContext::NotifyWillBeDestroyed starts running.
Lukasz Anforowicz16eddbc72022-12-19 20:08:43312 //
313 // Best practices for managing the lifetime of `WebContents` and
314 // `BrowserContext` will vary across different //content embedders. For
315 // example, for information specific to the //chrome layer, please see the
316 // "Managing lifetime of a Profile" section in
317 // //chrome/browser/profiles/README.md.
Erik Chenbb8e738e2018-04-28 14:10:43318 CONTENT_EXPORT static std::unique_ptr<WebContents> Create(
319 const CreateParams& params);
[email protected]d1198fd2012-08-13 22:50:19320
[email protected]fdac6ade2013-07-20 01:06:30321 // Similar to Create() above but should be used when you need to prepopulate
322 // the SessionStorageNamespaceMap of the WebContents. This can happen if
[email protected]d1198fd2012-08-13 22:50:19323 // you duplicate a WebContents, try to reconstitute it from a saved state,
324 // or when you create a new WebContents based on another one (eg., when
325 // servicing a window.open() call).
326 //
327 // You do not want to call this. If you think you do, make sure you completely
328 // understand when SessionStorageNamespace objects should be cloned, why
329 // they should not be shared by multiple WebContents, and what bad things
330 // can happen if you share the object.
erikchenade1fef2018-05-02 22:07:57331 CONTENT_EXPORT static std::unique_ptr<WebContents> CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59332 const CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30333 const SessionStorageNamespaceMap& session_storage_namespace_map);
[email protected]a81343d232011-12-27 07:39:20334
Matt Falkenhagenc70a9d102021-09-08 04:49:00335 // Returns the WebContents that owns the RenderViewHost.
336 //
337 // WARNING: `rvh` may belong to a prerendered page, a page in the back/forward
338 // cache, or a pending deletion page, so it might be inappropriate for it to
339 // to trigger changes to the WebContents. See also the below comments for
340 // FromRenderFrameHost().
avidf38c952015-10-27 13:45:13341 CONTENT_EXPORT static WebContents* FromRenderViewHost(RenderViewHost* rvh);
[email protected]746d3052012-05-22 15:15:47342
Xiaohan Wang009c0842020-09-17 05:43:24343 // Returns the WebContents for the RenderFrameHost. It is unsafe to call this
344 // function with an invalid (e.g. destructed) `rfh`.
Matt Falkenhagenc70a9d102021-09-08 04:49:00345 //
346 // WARNING: It might be inappropriate for `rfh` to trigger changes to the
347 // WebContents, so be careful when calling this. Some cases to be aware of
348 // are:
349 // * Pages/documents which are not active are not observable by the user
350 // and therefore should not show UI elements (e.g., a colour picker). These
351 // features should use `rfh->IsActive()` to determine whether `rfh` is
352 // active. See the comments there for more information.
353 // * Pages/documents which are not primary generally should not update
354 // per-WebContents state (e.g., theme colour). Use
355 // `rfh->GetPage().IsPrimary()` to check for primary. Fenced frames are
356 // one case where a RenderFrameHost can be active but not primary.
[email protected]a86c0e962013-12-17 17:10:39357 CONTENT_EXPORT static WebContents* FromRenderFrameHost(RenderFrameHost* rfh);
358
John Abd-El-Malek2ea05542020-03-04 00:03:36359 // Returns the WebContents associated with the |frame_tree_node_id|. This may
360 // return nullptr if the RenderFrameHost is shutting down.
ananta4b7467a52016-09-23 01:42:38361 CONTENT_EXPORT static WebContents* FromFrameTreeNodeId(
362 int frame_tree_node_id);
363
John Abd-El-Malek92bf3602019-07-31 02:25:48364 // A callback that returns a pointer to a WebContents. The callback can
365 // always be used, but it may return nullptr: if the info used to
366 // instantiate the callback can no longer be used to return a WebContents,
367 // nullptr will be returned instead.
368 // The callback should only run on the UI thread and it should always be
369 // non-null.
Erik Chen540d71942024-01-12 00:00:50370 // Most uses of Getter and OnceGetter can likely be safety replaced with
371 // base::WeakPtr<WebContents>.
danakjf4b9e942019-11-29 15:43:04372 using Getter = base::RepeatingCallback<WebContents*(void)>;
373 // Use this variant for instances that will only run the callback a single
374 // time.
375 using OnceGetter = base::OnceCallback<WebContents*(void)>;
John Abd-El-Malek92bf3602019-07-31 02:25:48376
leon.han552e9de2017-02-09 14:37:30377 // Sets delegate for platform specific screen orientation functionality.
378 CONTENT_EXPORT static void SetScreenOrientationDelegate(
379 ScreenOrientationDelegate* delegate);
380
Avi Drissman0b2a20d2021-12-08 00:59:16381 ~WebContents() override = default;
[email protected]36fc0392011-12-25 03:59:51382
[email protected]6934a702011-12-20 00:04:51383 // Intrinsic tab state -------------------------------------------------------
384
[email protected]674bc592011-12-20 23:00:42385 // Gets/Sets the delegate.
386 virtual WebContentsDelegate* GetDelegate() = 0;
387 virtual void SetDelegate(WebContentsDelegate* delegate) = 0;
[email protected]6934a702011-12-20 00:04:51388
Matt Falkenhagen91a80432021-07-05 03:32:44389 // Gets the NavigationController for primary frame tree of this WebContents.
390 // See comments on NavigationController for more details.
[email protected]cdcb1dee2012-01-04 00:46:20391 virtual NavigationController& GetController() = 0;
[email protected]f5fa20e2011-12-21 22:35:56392
[email protected]627e0512011-12-21 22:55:30393 // Returns the user browser context associated with this WebContents (via the
394 // NavigationController).
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41395 virtual content::BrowserContext* GetBrowserContext() = 0;
[email protected]627e0512011-12-21 22:55:30396
Claudio DeSouza2be02d42021-08-12 23:23:40397 // Returns a weak pointer.
398 virtual base::WeakPtr<WebContents> GetWeakPtr() = 0;
399
[email protected]ea049a02011-12-25 21:37:09400 // Gets the URL that is currently being displayed, if there is one.
[email protected]a093ce02013-07-22 20:53:14401 // This method is deprecated. DO NOT USE! Pick either |GetVisibleURL| or
[email protected]c854a7e2013-05-21 16:42:24402 // |GetLastCommittedURL| as appropriate.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41403 virtual const GURL& GetURL() = 0;
[email protected]f5fa20e2011-12-21 22:35:56404
dominickn319d6932016-06-21 00:59:26405 // Gets the virtual URL currently being displayed in the URL bar, if there is
406 // one. This URL might be a pending navigation that hasn't committed yet, so
Carlos IL07f282f2020-05-15 22:58:29407 // it is not guaranteed to match the current page in this WebContents.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41408 virtual const GURL& GetVisibleURL() = 0;
[email protected]c854a7e2013-05-21 16:42:24409
dominickn319d6932016-06-21 00:59:26410 // Gets the virtual URL of the last committed page in this WebContents.
411 // Virtual URLs are meant to be displayed to the user (e.g., they include the
412 // "view-source:" prefix for view source URLs, unlike NavigationEntry::GetURL
413 // and NavigationHandle::GetURL). The last committed page is the current
414 // security context and the content that is actually displayed within the tab.
Rakina Zata Amniafd3c6582021-11-30 06:19:17415 // See also GetVisibleURL above, which may differ from this URL. Note that
416 // this might return an empty GURL if no navigation has committed in the
417 // WebContents' main frame.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41418 virtual const GURL& GetLastCommittedURL() = 0;
[email protected]c854a7e2013-05-21 16:42:24419
Dave Tapuska1d5e5772022-06-02 17:26:01420 // Returns the primary main frame for the currently active page. Always
421 // non-null except during WebContents destruction. This WebContents may
422 // have additional main frames for prerendered pages, bfcached pages, etc.
Kevin McNee88bf2242022-11-23 00:27:34423 // See docs/frame_trees.md for more details.
Peter Kasting2caacff62023-05-24 16:06:53424 virtual const RenderFrameHost* GetPrimaryMainFrame() const = 0;
Dave Tapuska1d5e5772022-06-02 17:26:01425 virtual RenderFrameHost* GetPrimaryMainFrame() = 0;
426
Sreeja Kamishetty3dde6312021-06-22 14:05:29427 // Returns the current page in the primary frame tree of this WebContents.
428 // If this WebContents is associated with an omnibox, usually the URL of the
429 // main document of this page will be displayed in it.
430 //
431 // Primary page can change as a result of a navigation, both to a new page
432 // (navigation loading a new main document) and an existing one (when
433 // restoring the page from back/forward cache or activating a prerendering
434 // page). This change can be observed using
435 // WebContentsObserver::PrimaryPageChanged, see the comments there for more
436 // details.
437 //
438 // The primary page's lifetime corresponds to its main document's lifetime
439 // and may differ from a RenderFrameHost's lifetime (for cross-document same
440 // RenderFrameHost navigations).
441 //
442 // Apart from the primary page, additional pages might be associated with this
443 // WebContents:
444 // - Pending commit pages (which will become primary after-and-if the ongoing
445 // main frame navigation successfully commits).
446 // - Pending deletion pages (pages the user has navigated from, but which are
447 // still alive as they are running unload handlers in background).
448 // - Pages in back/forward cache (which can be navigated to later).
449 // - Prerendered pages (pages which are loading in the background in
450 // anticipation of user navigating to them).
451 //
452 // Given the existence of multiple pages, in many cases (especially when
453 // handling IPCs from the renderer process), calling GetPrimaryPage would not
454 // be appropriate as it might return a wrong page. If the code already has a
455 // reference to RenderFrameHost or a Page (e.g. each IPC from the renderer
456 // process should be associated with a particular RenderFrameHost), it should
457 // be used instead of getting the primary page from the WebContents.
Kevin McNee88bf2242022-11-23 00:27:34458 // See docs/frame_trees.md for more details.
Sreeja Kamishetty3dde6312021-06-22 14:05:29459 virtual Page& GetPrimaryPage() = 0;
460
Kevin McNee61927b32022-07-05 16:35:38461 // Returns the focused frame for the primary page or an inner page thereof.
462 // Might be nullptr if nothing is focused.
[email protected]9c9343b2014-03-08 02:56:07463 virtual RenderFrameHost* GetFocusedFrame() = 0;
464
Kevin McNee07c67ec92021-08-11 16:18:33465 // Returns true if |frame_tree_node_id| refers to a frame in a prerendered
466 // page.
467 // TODO(1196715, 1232528): This will be extended to also return true if it is
468 // in an inner page of a prerendered page.
469 virtual bool IsPrerenderedFrame(int frame_tree_node_id) = 0;
470
Kevin McNeed1fa70a52021-07-16 21:43:01471 // NOTE: This is generally unsafe to use. A frame's RenderFrameHost may
472 // change over its lifetime, such as during cross-process navigation (and
473 // thus privilege change). Use RenderFrameHost::FromID instead wherever
474 // possible.
475 //
Kunihiko Sakamoto1c5a09e2021-08-10 02:40:39476 // Given a FrameTreeNode ID that belongs to this WebContents, returns the
477 // current RenderFrameHost regardless of which FrameTree it is in.
Kevin McNeed1fa70a52021-07-16 21:43:01478 //
creisf71a2632017-05-04 19:03:50479 // See RenderFrameHost::GetFrameTreeNodeId for documentation on this ID.
480 virtual RenderFrameHost* UnsafeFindFrameByFrameTreeNodeId(
rob3e2a0732016-01-06 21:22:09481 int frame_tree_node_id) = 0;
482
Kevin McNeec9d0fda2021-05-19 15:55:17483 // Calls |on_frame| for every RenderFrameHost in this WebContents. Note that
484 // this includes RenderFrameHosts that are not descended from the primary main
485 // frame (e.g. bfcached pages and prerendered pages). The order of traversal
486 // for RenderFrameHosts within a page is consistent with
487 // |RenderFrameHost::ForEachRenderFrameHost|'s order, however no order is
488 // guaranteed between pages.
489 // For callers only interested in the primary page,
490 // |GetMainFrame()->ForEachRenderFrameHost()| can be used.
491 // See |RenderFrameHost::ForEachRenderFrameHost| for details.
Daniel Cheng982f2b22022-08-25 23:46:16492 using FrameIterationAction = RenderFrameHost::FrameIterationAction;
493 virtual void ForEachRenderFrameHostWithAction(
494 base::FunctionRef<FrameIterationAction(RenderFrameHost*)> on_frame) = 0;
Kevin McNeec9d0fda2021-05-19 15:55:17495 virtual void ForEachRenderFrameHost(
Daniel Cheng982f2b22022-08-25 23:46:16496 base::FunctionRef<void(RenderFrameHost*)> on_frame) = 0;
Kevin McNeec9d0fda2021-05-19 15:55:17497
[email protected]151a63d2011-12-20 22:32:52498 // Gets the current RenderViewHost for this tab.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41499 virtual RenderViewHost* GetRenderViewHost() = 0;
[email protected]d487beefe2011-12-21 05:41:21500
501 // Returns the currently active RenderWidgetHostView. This may change over
mlamouri8c61ffc2015-01-13 16:17:59502 // time and can be nullptr (during setup and teardown).
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41503 virtual RenderWidgetHostView* GetRenderWidgetHostView() = 0;
[email protected]4aebbcaa2013-09-17 22:26:49504
lfg265a2672016-04-23 03:11:02505 // Returns the outermost RenderWidgetHostView. This will return the platform
506 // specific RenderWidgetHostView (as opposed to
507 // RenderWidgetHostViewChildFrame), which can be used to create context
508 // menus.
509 virtual RenderWidgetHostView* GetTopLevelRenderWidgetHostView() = 0;
510
muyuanlic693ba12017-04-27 19:12:40511 // Request a one-time snapshot of the accessibility tree without changing
Dominic Mazzoni77d0aba2021-01-14 09:42:16512 // the accessibility mode. See RenderFrame::AXTreeSnapshotter for
513 // definitions of |ax_mode|, |max_nodes|, and |timeout|.
Avi Drissmanb30851c2018-03-08 20:34:33514 using AXTreeSnapshotCallback =
515 base::OnceCallback<void(const ui::AXTreeUpdate&)>;
Avi Drissman1e620f32018-03-16 13:57:29516 virtual void RequestAXTreeSnapshot(AXTreeSnapshotCallback callback,
Dominic Mazzoni77d0aba2021-01-14 09:42:16517 ui::AXMode ax_mode,
Dominic Mazzoni77d0aba2021-01-14 09:42:16518 size_t max_nodes,
519 base::TimeDelta timeout) = 0;
muyuanlic693ba12017-04-27 19:12:40520
naskoc0fceff2015-04-30 15:53:52521 // Causes the current page to be closed, including running its onunload event
522 // handler.
523 virtual void ClosePage() = 0;
524
yusufod41c5f92015-03-06 00:14:28525 // Returns the theme color for the underlying content as set by the
Alan Cutter92d59252019-03-29 02:32:33526 // theme-color meta tag if any.
Arthur Sonzognic686e8f2024-01-11 08:36:37527 virtual std::optional<SkColor> GetThemeColor() = 0;
yusufod41c5f92015-03-06 00:14:28528
Alan Cutterd73a15d92020-08-21 07:12:45529 // Returns the background color for the underlying content as set by CSS if
530 // any.
Arthur Sonzognic686e8f2024-01-11 08:36:37531 virtual std::optional<SkColor> GetBackgroundColor() = 0;
Alan Cutterd73a15d92020-08-21 07:12:45532
Bo Liub5e79d92021-06-12 01:40:41533 // Sets the renderer-side default background color of the page. This is used
534 // when the page has not loaded enough to know a background color or if the
535 // page does not set a background color.
536 // Pass in nullopt to reset back to the default.
537 // Note there are situations where the base background color is not used, such
538 // as fullscreen.
539 // Note currently this is sent directly to the renderer, so does not interact
540 // directly with `RenderWidgetHostView::SetBackgroundColor`. There is pending
541 // refactor to remove `RenderWidgetHostView::SetBackgroundColor` and merge its
542 // functionality here, which will be more consistent and simpler to
543 // understand.
Arthur Sonzognic686e8f2024-01-11 08:36:37544 virtual void SetPageBaseBackgroundColor(std::optional<SkColor> color) = 0;
Bo Liub5e79d92021-06-12 01:40:41545
tom855c4bf32021-09-30 00:27:26546 // Sets the ColorProviderSource for the WebContents. The WebContents will
547 // maintain an observation of `source` until a new source is set or the
548 // current source is destroyed. WebContents will receive updates when the
549 // source's ColorProvider changes.
550 virtual void SetColorProviderSource(ui::ColorProviderSource* source) = 0;
551
Tom Lukaszewicz63b3da52022-01-26 01:37:57552 // Returns the ColorProvider instance for this WebContents object. This will
553 // always return a valid ColorProvider instance.
554 virtual const ui::ColorProvider& GetColorProvider() const = 0;
555
Thomas Lukaszewiczc6b1f22d2023-06-13 18:24:50556 // Gets the color mode for the ColorProvider associated with this WebContents.
Sean Kaufc4c41c2023-06-22 16:21:54557 virtual ui::ColorProviderKey::ColorMode GetColorMode() const = 0;
Thomas Lukaszewiczc6b1f22d2023-06-13 18:24:50558
Charlie Reis4589bf32021-07-20 00:36:23559 // Returns the committed WebUI if one exists.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41560 virtual WebUI* GetWebUI() = 0;
[email protected]be1f56ab2011-12-22 06:55:31561
Scott Violet2a6c5bff2020-04-29 23:59:06562 // Sets the user-agent that may be used for navigations in this WebContents.
563 // The user-agent is *only* used when
564 // NavigationEntry::SetIsOverridingUserAgent(true) is used (the value of
565 // is-overriding-user-agent may be specified in LoadURLParams). If
566 // |override_in_new_tabs| is true, and the first navigation in the tab is
567 // renderer initiated, then is-overriding-user-agent is set to true for the
568 // NavigationEntry. See SetRendererInitiatedUserAgentOverrideOption() for
569 // details on how renderer initiated navigations are configured.
David Van Clevede398a52020-12-28 21:33:03570 //
571 // If nonempty, |ua_override|'s value must not contain '\0', '\r', or '\n' (in
572 // other words, it must be a valid HTTP header value).
Maks Orlovich73f374d2020-04-02 12:46:13573 virtual void SetUserAgentOverride(const blink::UserAgentOverride& ua_override,
Changwan Ryuc1134a82018-03-07 02:10:14574 bool override_in_new_tabs) = 0;
Scott Violet2a6c5bff2020-04-29 23:59:06575
576 // Configures the value of is-overriding-user-agent for renderer initiated
577 // navigations. The default is UA_OVERRIDE_INHERIT. This value does not apply
578 // to the first renderer initiated navigation if the tab has no navigations.
579 // See SetUserAgentOverride() for details on that.
580 virtual void SetRendererInitiatedUserAgentOverrideOption(
581 NavigationController::UserAgentOverrideOption option) = 0;
582
Maks Orlovich73f374d2020-04-02 12:46:13583 virtual const blink::UserAgentOverride& GetUserAgentOverride() = 0;
[email protected]86ef6a392012-05-11 22:03:11584
Aman Vermaa4b33cf2023-06-13 19:32:33585 // Updates all renderers to start sending subresource notifications since a
586 // certificate error or HTTP exception has been allowed by the user.
587 virtual void SetAlwaysSendSubresourceNotifications() = 0;
588 virtual bool GetSendSubresourceNotification() = 0;
589
dmazzonidd3d51a72016-12-14 18:41:01590 // Returns true only if the WebContentsObserver accessibility mode is
591 // enabled.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41592 virtual bool IsWebContentsOnlyAccessibilityModeForTesting() = 0;
[email protected]95640212014-07-26 18:14:30593
594 // Returns true only if complete accessibility mode is on, meaning there's
595 // both renderer accessibility, and a native browser accessibility tree.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41596 virtual bool IsFullAccessibilityModeForTesting() = 0;
[email protected]95640212014-07-26 18:14:30597
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41598 virtual ui::AXMode GetAccessibilityMode() = 0;
James Wallace-Leeeafc94cb92018-07-23 21:35:09599
Greg Thompsonf855bf882024-01-30 10:39:45600 // Forces a reset of accessibility state in the instance's renderers.
601 // Observers will receive a new accessibility tree.
602 virtual void ResetAccessibility() = 0;
James Wallace-Leeeafc94cb92018-07-23 21:35:09603
Nektarios Paisios8e9da982024-02-20 23:14:22604 // Returns a pointer to the root node of the live accessibility tree for the
605 // main frame, if accessibility is turned on. Otherwise, returns nullptr.
606 virtual ui::AXNode* GetAccessibilityRootNode() = 0;
607
Alexander Surkov2ab51622020-09-02 12:01:42608 virtual std::string DumpAccessibilityTree(
Abigail Kleinabb428332019-09-13 18:26:21609 bool internal,
Alexander Surkov90482882020-10-12 16:30:38610 std::vector<ui::AXPropertyFilter> property_filters) = 0;
James Wallace-Leeeafc94cb92018-07-23 21:35:09611
Jacques Newmane313e142024-03-13 18:47:22612 virtual std::string DumpAccessibilityTree(
613 ui::AXApiType::Type api_type,
614 std::vector<ui::AXPropertyFilter> property_filters) = 0;
615
Abigail Kleinaa898742019-11-01 02:31:25616 // A callback that takes a string which contains accessibility event
617 // information.
618 using AccessibilityEventCallback =
619 base::RepeatingCallback<void(const std::string&)>;
620
Abigail Kleinbb8304bd2020-05-18 21:44:18621 // Starts or stops recording accessibility events. |start_recording| is true
622 // when recording should start and false when recording should stop.
623 // |callback| is an optional function which is called when an accessibility
624 // event is received while accessibility events are being recorded. When
625 // |start_recording| is true, it is expected that |callback| has a value; when
626 // |start_recording| is false, it is expected that |callback| does not.
627 virtual void RecordAccessibilityEvents(
628 bool start_recording,
Arthur Sonzognic686e8f2024-01-11 08:36:37629 std::optional<AccessibilityEventCallback> callback) = 0;
Abigail Kleinaa898742019-11-01 02:31:25630
Jacques Newmane313e142024-03-13 18:47:22631 virtual void RecordAccessibilityEvents(
632 ui::AXApiType::Type api_type,
633 bool start_recording,
634 std::optional<AccessibilityEventCallback> callback) = 0;
[email protected]be1f56ab2011-12-22 06:55:31635 // Tab navigation state ------------------------------------------------------
636
637 // Returns the current navigation properties, which if a navigation is
638 // pending may be provisional (e.g., the navigation could result in a
639 // download, in which case the URL would revert to what it was previously).
Jan Wilken Dörrieaace0cfef2021-03-11 22:01:58640 virtual const std::u16string& GetTitle() = 0;
[email protected]be1f56ab2011-12-22 06:55:31641
afakhry6f0c1ec22016-07-14 13:55:13642 // Saves the given title to the navigation entry and does associated work. It
643 // will update history and the view with the new title, and also synthesize
644 // titles for file URLs that have none. Thus |entry| must have a URL set.
645 virtual void UpdateTitleForEntry(NavigationEntry* entry,
Jan Wilken Dörrieaace0cfef2021-03-11 22:01:58646 const std::u16string& title) = 0;
afakhry6f0c1ec22016-07-14 13:55:13647
Haben Foto533aa352024-01-09 22:01:16648 // Returns app title of the current navigation entry. The apptitle is
649 // an alternative title text that can be used by app windows.
650 // See
651 // https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/DocumentSubtitle/explainer.md
652 virtual const std::u16string& GetAppTitle() = 0;
653
[email protected]be1f56ab2011-12-22 06:55:31654 // Returns the SiteInstance associated with the current page.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41655 virtual SiteInstance* GetSiteInstance() = 0;
[email protected]be1f56ab2011-12-22 06:55:31656
[email protected]6dfed692014-05-22 04:18:03657 // Returns whether this WebContents is loading a resource.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41658 virtual bool IsLoading() = 0;
[email protected]be1f56ab2011-12-22 06:55:31659
Peter Boström18a40fa2018-10-31 19:03:50660 // Returns the current load progress.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41661 virtual double GetLoadProgress() = 0;
Peter Boström18a40fa2018-10-31 19:03:50662
Nate Chapin9aabf5f2021-11-12 00:31:19663 // Returns whether a navigation is currently in progress that should show
664 // loading UI if such UI exists (progress bar, loading spinner, stop button,
Domenic Denicola30810742022-03-17 20:11:23665 // etc.) True for different-document navigations and the navigation API's
Nate Chapin24295252022-09-27 18:31:08666 // intercept(). This being true implies that IsLoading() is also true.
Nate Chapin9aabf5f2021-11-12 00:31:19667 virtual bool ShouldShowLoadingUI() = 0;
[email protected]6dfed692014-05-22 04:18:03668
Sreeja Kamishetty6b55ecc2021-12-10 11:28:17669 // Returns whether the current primary main document has reached and finished
Alexander Timindd0fa0c52019-11-06 13:03:37670 // executing its onload() handler. Corresponds to
Sreeja Kamishetty81347582022-01-06 12:46:33671 // WebContentsObserver::DocumentOnLoadCompletedInPrimaryMainFrame() and see
672 // comments there for more details.
673 virtual bool IsDocumentOnLoadCompletedInPrimaryMainFrame() = 0;
Alexander Timindd0fa0c52019-11-06 13:03:37674
[email protected]ca13a442012-04-17 14:00:12675 // Returns whether this WebContents is waiting for a first-response for the
[email protected]be1f56ab2011-12-22 06:55:31676 // main resource of the page.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41677 virtual bool IsWaitingForResponse() = 0;
[email protected]be1f56ab2011-12-22 06:55:31678
Lijin Shen8c0f4362024-03-25 20:05:09679 // Returns whether this WebContents's primary frame tree node is navigating,
680 // i.e. it has an associated NavigationRequest.
681 virtual bool HasUncommittedNavigationInPrimaryMainFrame() = 0;
682
[email protected]6dfed692014-05-22 04:18:03683 // Returns the current load state and the URL associated with it.
andresantoso9d019942015-05-27 17:01:08684 // The load state is only updated while IsLoading() is true.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41685 virtual const net::LoadStateWithParam& GetLoadState() = 0;
Jan Wilken Dörrieaace0cfef2021-03-11 22:01:58686 virtual const std::u16string& GetLoadStateHost() = 0;
[email protected]be1f56ab2011-12-22 06:55:31687
[email protected]6dfed692014-05-22 04:18:03688 // Returns the upload progress.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41689 virtual uint64_t GetUploadSize() = 0;
690 virtual uint64_t GetUploadPosition() = 0;
[email protected]be1f56ab2011-12-22 06:55:31691
[email protected]6dfed692014-05-22 04:18:03692 // Returns the character encoding of the page.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41693 virtual const std::string& GetEncoding() = 0;
[email protected]be1f56ab2011-12-22 06:55:31694
Shubhie Panickerddf2a4e2018-03-06 00:09:06695 // Indicates that the tab was previously discarded.
696 // wasDiscarded is exposed on Document after discard, see:
697 // https://github.com/WICG/web-lifecycle
698 // When a tab is discarded, WebContents sets was_discarded on its
699 // root FrameTreeNode.
700 // In addition, when a child frame is created, this bit is passed on from
701 // parent to child.
702 // When a navigation request is created, was_discarded is passed on to the
703 // request and reset to false in FrameTreeNode.
Charles Zhaod72f99d2018-09-17 14:18:27704 virtual bool WasDiscarded() = 0;
Shubhie Panickerddf2a4e2018-03-06 00:09:06705 virtual void SetWasDiscarded(bool was_discarded) = 0;
706
Anthony Vallee-Duboisaa026522022-12-07 17:24:28707 // Notifies observers that this WebContents is about to be discarded, and
708 // replaced with `new_contents`. See the comment on
709 // WebContentsObserver::AboutToBeDiscarded.
710 virtual void AboutToBeDiscarded(WebContents* new_contents) = 0;
711
[email protected]be1f56ab2011-12-22 06:55:31712 // Internal state ------------------------------------------------------------
713
Yuri Wiitalaba4a68e2021-01-07 23:32:19714 // Indicates whether the WebContents is being captured (e.g., for screenshots,
715 // or mirroring video and/or audio). Each IncrementCapturerCount() call must
716 // be balanced with a corresponding DecrementCapturerCount() call.
717 //
718 // Both internal-to-content and embedders must increment the capturer count
719 // while capturing to ensure "hidden rendering" optimizations are disabled.
720 // For example, renderers will be configured to produce compositor frames
721 // regardless of their "backgrounded" or on-screen occlusion state.
722 //
723 // Embedders can detect whether a WebContents is being captured (see
724 // IsBeingCaptured() below) and use this, for example, to provide an
725 // alternative user interface. So, developers should be careful to understand
726 // the side-effects from using or changing these APIs, both upstream and
727 // downstream of this API layer.
728 //
Dale Curtis7030f252021-04-07 14:05:31729 // Callers must hold onto the returned base::ScopedClosureRunner until they
730 // are done capturing.
731 //
Yuri Wiitalaba4a68e2021-01-07 23:32:19732 // |capture_size| is only used in the case of mirroring (i.e., screen capture
733 // video); otherwise, an empty gfx::Size should be provided. This specifies
734 // the capturer's target video resolution, but can be empty to mean
735 // "unspecified." This becomes a temporary override to GetPreferredSize(),
736 // allowing embedders to size the WebContents on-screen views for optimal
737 // capture quality.
738 //
739 // |stay_hidden| affects the page visibility state of the renderers (i.e., a
740 // web page can be made aware of whether it is actually user-visible). If
741 // true, the show/hide state of the WebContents will be passed to the
742 // renderers, like normal. If false, the renderers will always be told they
743 // are user-visible while being captured.
Dale Curtis7030f252021-04-07 14:05:31744 //
745 // |stay_awake| will cause a WakeLock to be held which prevents system sleep.
Elad Alon0feb6602021-10-14 09:26:36746 //
747 // |is_activity| means the capture will cause the last active time to be
748 // updated.
Daniel Cheng9c9fa1a2022-01-14 03:42:11749 [[nodiscard]] virtual base::ScopedClosureRunner IncrementCapturerCount(
Dale Curtis7030f252021-04-07 14:05:31750 const gfx::Size& capture_size,
751 bool stay_hidden,
Elad Alon0feb6602021-10-14 09:26:36752 bool stay_awake,
Daniel Cheng9c9fa1a2022-01-14 03:42:11753 bool is_activity = true) = 0;
Yuri Wiitalaba4a68e2021-01-07 23:32:19754
Elad Alonf156eb62021-05-17 22:02:37755 // Getter for the capture handle, which allows a captured application to
756 // opt-in to exposing information to its capturer(s).
757 virtual const blink::mojom::CaptureHandleConfig& GetCaptureHandleConfig() = 0;
758
Yuri Wiitalaba4a68e2021-01-07 23:32:19759 // Returns true if audio/screenshot/video is being captured by the embedder,
760 // as indicated by calls to IncrementCapturerCount().
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41761 virtual bool IsBeingCaptured() = 0;
Yuri Wiitalaba4a68e2021-01-07 23:32:19762
763 // Returns true if audio/screenshot/video is being captured by the embedder
764 // and renderers are being told they are always user-visible, as indicated by
765 // calls to IncrementCapturerCount().
Xianzhu Wangc61434c2020-08-21 19:17:30766 virtual bool IsBeingVisiblyCaptured() = 0;
[email protected]be1f56ab2011-12-22 06:55:31767
miu50f97892014-09-22 22:49:52768 // Indicates/Sets whether all audio output from this WebContents is muted.
Yuri Wiitalaba4a68e2021-01-07 23:32:19769 // This does not affect audio capture, just local/system output.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41770 virtual bool IsAudioMuted() = 0;
miu50f97892014-09-22 22:49:52771 virtual void SetAudioMuted(bool mute) = 0;
772
Jan Rucka442c83f2017-08-08 13:27:54773 // Returns true if the audio is currently audible.
774 virtual bool IsCurrentlyAudible() = 0;
775
ortunodf4d7982016-04-08 02:33:35776 // Indicates whether any frame in the WebContents is connected to a Bluetooth
777 // Device.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41778 virtual bool IsConnectedToBluetoothDevice() = 0;
ortuno32e7db3c2016-03-29 16:14:20779
Ovidio Henriquez76696f62020-07-08 03:06:59780 // Indicates whether any frame in the WebContents is scanning for Bluetooth
781 // devices.
782 virtual bool IsScanningForBluetoothDevices() = 0;
783
Reilly Grant5e7c79b22019-04-09 17:26:20784 // Indicates whether any frame in the WebContents is connected to a serial
785 // port.
Lucas Furukawa Gadani4b4eed02019-06-04 23:12:04786 virtual bool IsConnectedToSerialPort() = 0;
Reilly Grant5e7c79b22019-04-09 17:26:20787
Matt Reynoldse8c6c1f2019-11-02 09:53:53788 // Indicates whether any frame in the WebContents is connected to a HID
789 // device.
790 virtual bool IsConnectedToHidDevice() = 0;
791
Matt Reynoldsed00ca7e72022-08-18 20:56:20792 // Indicates whether any frame in the WebContents is connected to a USB
793 // device.
794 virtual bool IsConnectedToUsbDevice() = 0;
795
Austin Sullivanafefb722021-01-14 01:26:39796 // Indicates whether any frame in the WebContents has File System Access
Marijn Kruisselbrink29051042019-08-06 22:56:55797 // handles.
Austin Sullivanafefb722021-01-14 01:26:39798 virtual bool HasFileSystemAccessHandles() = 0;
Marijn Kruisselbrink29051042019-08-06 22:56:55799
sawtellea7333a82018-05-31 02:36:36800 // Indicates whether a video is in Picture-in-Picture for |this|.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41801 virtual bool HasPictureInPictureVideo() = 0;
sawtellea7333a82018-05-31 02:36:36802
Klaus Weidnerd8219432022-02-08 21:50:59803 // Indicates whether a document is in Picture-in-Picture for |this|.
804 virtual bool HasPictureInPictureDocument() = 0;
805
danakjcdab6ed52021-02-10 23:44:13806 // Indicates whether this tab should be considered crashed. This becomes false
807 // again when the renderer process is recreated after a crash in order to
808 // recreate the main frame.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41809 virtual bool IsCrashed() = 0;
[email protected]be1f56ab2011-12-22 06:55:31810
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41811 virtual base::TerminationStatus GetCrashedStatus() = 0;
812 virtual int GetCrashedErrorCode() = 0;
[email protected]be1f56ab2011-12-22 06:55:31813
814 // Whether the tab is in the process of being destroyed.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41815 virtual bool IsBeingDestroyed() = 0;
[email protected]be1f56ab2011-12-22 06:55:31816
817 // Convenience method for notifying the delegate of a navigation state
[email protected]7f924832014-08-09 05:57:22818 // change.
819 virtual void NotifyNavigationStateChanged(InvalidateTypes changed_flags) = 0;
[email protected]be1f56ab2011-12-22 06:55:31820
Chris Hamiltondf0d72cd2018-05-29 16:23:53821 // Notifies the WebContents that audio state has changed. The contents is
822 // aware of all of its potential sources of audio and needs to poll them
823 // directly to determine its aggregate audio state.
824 virtual void OnAudioStateChanged() = 0;
altimind8bd26c2016-11-04 11:44:54825
georgesak5582cbe2015-05-22 22:08:07826 // Get/Set the last time that the WebContents was made active (either when it
827 // was created or shown with WasShown()).
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41828 virtual base::TimeTicks GetLastActiveTime() = 0;
[email protected]be1f56ab2011-12-22 06:55:31829
Francois Doray18800972017-08-25 22:38:58830 // Invoked when the WebContents becomes shown/hidden. A hidden WebContents
831 // isn't painted on the screen.
[email protected]9e2e4632012-07-27 16:38:41832 virtual void WasShown() = 0;
[email protected]3e324142012-06-25 18:26:33833 virtual void WasHidden() = 0;
[email protected]be1f56ab2011-12-22 06:55:31834
Francois Doraye6161152018-03-27 22:05:37835 // Invoked when the WebContents becomes occluded. An occluded WebContents
836 // isn't painted on the screen, except in a window switching feature (e.g.
837 // Alt-Tab).
Francois Doray18800972017-08-25 22:38:58838 virtual void WasOccluded() = 0;
Francois Doray18800972017-08-25 22:38:58839
Francois Dorayfe4a1772018-02-17 04:17:09840 // Returns the visibility of the WebContents' view.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41841 virtual Visibility GetVisibility() = 0;
Francois Dorayfe4a1772018-02-17 04:17:09842
Sreeja Kamishetty1c1ca7a2023-05-12 16:36:40843 // Sets the visibility of the WebContents' view and notifies the WebContents
844 // observers about Visibility change. Call UpdateWebContentsVisibility instead
845 // of WasShown() if you are setting Visibility to VISIBLE for the first time.
Alison Gale53c77f62024-04-22 15:16:27846 // TODO(crbug.com/40911760): Make updating Visibility more robust.
Sreeja Kamishetty1c1ca7a2023-05-12 16:36:40847 virtual void UpdateWebContentsVisibility(Visibility visibility) = 0;
848
Alex Moshchuk5bcd7c12019-11-12 22:55:31849 // This function checks *all* frames in this WebContents (not just the main
850 // frame) and returns true if at least one frame has either a beforeunload or
Rakina Zata Amni26e8d8a2020-08-05 06:06:06851 // an unload/pagehide/visibilitychange handler.
Alex Moshchuk5bcd7c12019-11-12 22:55:31852 //
853 // The value of this may change over time. For example, if true and the
854 // beforeunload listener is executed and allows the user to exit, then this
[email protected]be1f56ab2011-12-22 06:55:31855 // returns false.
Rakina Zata Amni26e8d8a2020-08-05 06:06:06856 virtual bool NeedToFireBeforeUnloadOrUnloadEvents() = 0;
[email protected]be1f56ab2011-12-22 06:55:31857
Alex Moshchuk6fcaca752018-07-14 02:13:59858 // Runs the beforeunload handler for the main frame and all its subframes.
859 // See also ClosePage in RenderViewHostImpl, which runs the unload handler.
Chris Hamilton3b3e315d2018-09-19 13:16:21860 // If |auto_cancel| is true, and the beforeunload handler returns a non-empty
861 // string (indicating the page wants to present a confirmation dialog), then
862 // the beforeunload operation will automatically return with |proceed=false|
863 // and no dialog will be shown to the user. This is used to interrupt a
864 // potential discard without causing the dialog to appear.
865 virtual void DispatchBeforeUnload(bool auto_cancel) = 0;
[email protected]1c3f80bd2014-04-08 23:02:06866
Lucas Furukawa Gadani6e5b4f32019-03-02 04:18:50867 // Attaches |inner_web_contents| to the container frame |render_frame_host|,
Kevin McNee9bec6a3d2021-05-13 22:19:02868 // which must be in a FrameTree for this WebContents. This outer WebContents
Lucas Furukawa Gadani6e5b4f32019-03-02 04:18:50869 // takes ownership of |inner_web_contents|.
870 // Note: |render_frame_host| will be swapped out and destroyed during the
Ehsan Karamad44fc72112019-02-26 18:15:47871 // process. Generally a frame same-process with its parent is the right choice
872 // but ideally it should be "about:blank" to avoid problems with beforeunload.
873 // To ensure sane usage of this API users first should call the async API
874 // RenderFrameHost::PrepareForInnerWebContentsAttach first.
W. James MacLean62883982019-11-12 20:39:00875 // Note: If |is_full_page| is true, focus will be given to the inner
876 // WebContents.
Lucas Furukawa Gadani6e5b4f32019-03-02 04:18:50877 virtual void AttachInnerWebContents(
878 std::unique_ptr<WebContents> inner_web_contents,
W. James MacLean62883982019-11-12 20:39:00879 RenderFrameHost* render_frame_host,
Dave Tapuska82b54012022-07-15 23:26:10880 mojo::PendingAssociatedRemote<blink::mojom::RemoteFrame> remote_frame,
881 mojo::PendingAssociatedReceiver<blink::mojom::RemoteFrameHost>
882 remote_frame_host_receiver,
W. James MacLean62883982019-11-12 20:39:00883 bool is_full_page) = 0;
lazyboy6ec48b2a2015-06-29 15:18:14884
W. James MacLean2539adb32019-12-13 00:40:44885 // Returns whether this WebContents is an inner WebContents for a guest.
886 // Important: please avoid using this in new callsites, and use
887 // GetOuterWebContents instead.
888 virtual bool IsInnerWebContentsForGuest() = 0;
889
Lucas Furukawa Gadani2ec00c82018-12-14 15:53:16890 // Returns the outer WebContents frame, the same frame that this WebContents
891 // was attached in AttachToOuterWebContentsFrame().
892 virtual RenderFrameHost* GetOuterWebContentsFrame() = 0;
893
Wei Li5c0b4d12018-03-22 15:05:22894 // Returns the outer WebContents of this WebContents if any.
895 // Otherwise, return nullptr.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41896 virtual WebContents* GetOuterWebContents() = 0;
Wei Li5c0b4d12018-03-22 15:05:22897
W. James MacLean3f9fba232018-08-16 15:20:36898 // Returns the root WebContents of the WebContents tree. Always returns
899 // non-null value.
900 virtual WebContents* GetOutermostWebContents() = 0;
901
Lucas Furukawa Gadani2ec00c82018-12-14 15:53:16902 // Returns a vector to the inner WebContents within this WebContents.
903 virtual std::vector<WebContents*> GetInnerWebContents() = 0;
904
Jeremy Roman7e70bf952020-01-07 23:23:58905 // Returns the user-visible WebContents that is responsible for the UI
906 // activity in the provided WebContents. For example, this delegate may be
907 // aware that the contents is embedded in some other contents, or hosts
908 // background activity on behalf of a user-visible tab which should be used to
909 // display dialogs and similar affordances to the user.
910 //
911 // This may be distinct from the outer web contents (for example, the
912 // responsible contents may logically "own" a contents but not currently embed
913 // it for rendering).
914 //
915 // Always returns a non-null value.
Jeremy Romanc0c69be2023-11-21 19:14:52916 //
Alison Gale81f4f2c72024-04-22 19:33:31917 // TODO(crbug.com/40939539): Consider replacing this with
Jeremy Romanc0c69be2023-11-21 19:14:52918 // GuestViewBase::GetTopLevelWebContents, since that is now the only case
919 // where this would return a contents other than |this|.
Jeremy Roman7e70bf952020-01-07 23:23:58920 virtual WebContents* GetResponsibleWebContents() = 0;
921
dalecurtis6c58ed02016-10-28 23:02:37922 // Invoked when visible security state changes.
923 virtual void DidChangeVisibleSecurityState() = 0;
924
Bruce Long1e3e1f542019-10-16 17:56:28925 // Sends the current preferences to all renderer processes for the current
926 // page.
927 virtual void SyncRendererPrefs() = 0;
928
[email protected]0bfbf882011-12-22 18:19:27929 // Commands ------------------------------------------------------------------
930
931 // Stop any pending navigation.
932 virtual void Stop() = 0;
933
Francois Doray47f759d2018-06-11 18:13:51934 // Freezes or unfreezes the current page. A frozen page runs as few tasks as
935 // possible. This cannot be called when the page is visible. If the page is
936 // made visible after this is called, it is automatically unfrozen.
937 virtual void SetPageFrozen(bool frozen) = 0;
Fadi Meawada6573e02018-03-10 00:52:11938
[email protected]d9083482012-01-06 00:38:46939 // Creates a new WebContents with the same state as this one. The returned
[email protected]0bfbf882011-12-22 18:19:27940 // heap-allocated pointer is owned by the caller.
erikchen6c7df7f7a2018-05-03 18:13:59941 virtual std::unique_ptr<WebContents> Clone() = 0;
[email protected]0bfbf882011-12-22 18:19:27942
[email protected]1f3fc1d2014-04-03 14:50:17943 // Reloads the focused frame.
arthursonzogni818c2642019-09-27 12:18:10944 virtual void ReloadFocusedFrame() = 0;
[email protected]4fed3702014-04-01 09:08:00945
[email protected]1f3fc1d2014-04-03 14:50:17946 // Editing commands ----------------------------------------------------------
947
[email protected]959be4c2014-04-08 15:01:33948 virtual void Undo() = 0;
949 virtual void Redo() = 0;
950 virtual void Cut() = 0;
951 virtual void Copy() = 0;
952 virtual void CopyToFindPboard() = 0;
Leonard Greyc2bc8002023-03-08 17:53:06953 virtual void CenterSelection() = 0;
[email protected]959be4c2014-04-08 15:01:33954 virtual void Paste() = 0;
955 virtual void PasteAndMatchStyle() = 0;
956 virtual void Delete() = 0;
957 virtual void SelectAll() = 0;
yabinh351e7ec2017-03-10 02:43:24958 virtual void CollapseSelection() = 0;
Leonard Greyf378e7d2021-03-25 20:53:50959 virtual void ScrollToTopOfDocument() = 0;
960 virtual void ScrollToBottomOfDocument() = 0;
[email protected]959be4c2014-04-08 15:01:33961
aurimasab0319022015-07-10 21:57:38962 // Adjust the selection starting and ending points in the focused frame by
963 // the given amounts. A negative amount moves the selection towards the
964 // beginning of the document, a positive amount moves the selection towards
965 // the end of the document.
966 virtual void AdjustSelectionByCharacterOffset(int start_adjust,
Shimi Zhang37deeb22017-09-28 00:59:01967 int end_adjust,
968 bool show_selection_menu) = 0;
aurimasab0319022015-07-10 21:57:38969
[email protected]1f3fc1d2014-04-03 14:50:17970 // Replaces the currently selected word or a word around the cursor.
Jan Wilken Dörrieaace0cfef2021-03-11 22:01:58971 virtual void Replace(const std::u16string& word) = 0;
[email protected]1f3fc1d2014-04-03 14:50:17972
973 // Replaces the misspelling in the current selection.
Jan Wilken Dörrieaace0cfef2021-03-11 22:01:58974 virtual void ReplaceMisspelling(const std::u16string& word) = 0;
[email protected]1f3fc1d2014-04-03 14:50:17975
[email protected]959be4c2014-04-08 15:01:33976 // Let the renderer know that the menu has been closed.
Gyuyoung Kim1bc1ba82021-02-08 23:32:44977 virtual void NotifyContextMenuClosed(const GURL& link_followed) = 0;
[email protected]959be4c2014-04-08 15:01:33978
979 // Executes custom context menu action that was provided from Blink.
Gyuyoung Kim1bc1ba82021-02-08 23:32:44980 virtual void ExecuteCustomContextMenuCommand(int action,
981 const GURL& link_followed) = 0;
[email protected]959be4c2014-04-08 15:01:33982
[email protected]0bfbf882011-12-22 18:19:27983 // Views and focus -----------------------------------------------------------
[email protected]4fed3702014-04-01 09:08:00984
[email protected]fc2b46b2014-05-03 16:33:45985 // Returns the native widget that contains the contents of the tab.
986 virtual gfx::NativeView GetNativeView() = 0;
987
988 // Returns the native widget with the main content of the tab (i.e. the main
989 // render view host, though there may be many popups in the tab as children of
990 // the container).
991 virtual gfx::NativeView GetContentNativeView() = 0;
992
993 // Returns the outermost native view. This will be used as the parent for
994 // dialog boxes.
995 virtual gfx::NativeWindow GetTopLevelNativeWindow() = 0;
996
997 // Computes the rectangle for the native widget that contains the contents of
998 // the tab in the screen coordinate system.
999 virtual gfx::Rect GetContainerBounds() = 0;
1000
Takashi Toyoshimaec7f26722024-02-16 05:47:261001 // Get the bounds of the View in the global screen position.
[email protected]fc2b46b2014-05-03 16:33:451002 virtual gfx::Rect GetViewBounds() = 0;
1003
Mugdha Lakhani0a0d7862020-07-29 09:58:451004 // Resize a WebContents to |new_bounds|.
1005 virtual void Resize(const gfx::Rect& new_bounds) = 0;
1006
1007 // Get the size of a WebContents.
1008 virtual gfx::Size GetSize() = 0;
1009
[email protected]fc2b46b2014-05-03 16:33:451010 // Returns the current drop data, if any.
1011 virtual DropData* GetDropData() = 0;
1012
1013 // Sets focus to the native widget for this tab.
1014 virtual void Focus() = 0;
1015
1016 // Sets focus to the appropriate element when the WebContents is shown the
1017 // first time.
1018 virtual void SetInitialFocus() = 0;
1019
1020 // Stores the currently focused view.
1021 virtual void StoreFocus() = 0;
1022
1023 // Restores focus to the last focus view. If StoreFocus has not yet been
1024 // invoked, SetInitialFocus is invoked.
1025 virtual void RestoreFocus() = 0;
1026
[email protected]0bfbf882011-12-22 18:19:271027 // Focuses the first (last if |reverse| is true) element in the page.
1028 // Invoked when this tab is getting the focus through tab traversal (|reverse|
1029 // is true when using Shift-Tab).
1030 virtual void FocusThroughTabTraversal(bool reverse) = 0;
1031
[email protected]0bfbf882011-12-22 18:19:271032 // Misc state & callbacks ----------------------------------------------------
1033
[email protected]a53209b2012-01-20 16:48:161034 // Check whether we can do the saving page operation this page given its MIME
1035 // type.
1036 virtual bool IsSavable() = 0;
1037
[email protected]0bfbf882011-12-22 18:19:271038 // Prepare for saving the current web page to disk.
1039 virtual void OnSavePage() = 0;
1040
1041 // Save page with the main HTML file path, the directory for saving resources,
1042 // and the save type: HTML only or complete web page. Returns true if the
1043 // saving process has been initiated successfully.
[email protected]c42de732013-02-16 06:26:311044 virtual bool SavePage(const base::FilePath& main_file,
1045 const base::FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161046 SavePageType save_type) = 0;
[email protected]0bfbf882011-12-22 18:19:271047
Yao Xiaoe5007042021-02-26 02:32:091048 // Saves the given frame's URL to the local filesystem. If `rfh` is provided,
1049 // the saving is performed in its context. For example, the associated
1050 // navigation isolation info will be used for making the network request.
[email protected]3c71576ce2013-07-23 02:00:011051 virtual void SaveFrame(const GURL& url,
Yao Xiaoe5007042021-02-26 02:32:091052 const Referrer& referrer,
1053 RenderFrameHost* rfh) = 0;
[email protected]3c71576ce2013-07-23 02:00:011054
kundaji6c7f9692015-03-09 18:00:371055 // Saves the given frame's URL to the local filesystem. The headers, if
1056 // provided, is used to make a request to the URL rather than using cache.
1057 // Format of |headers| is a new line separated list of key value pairs:
Jeremy Romancfa82c652021-07-06 21:43:271058 // "<key1>: <value1>\r\n<key2>: <value2>". The saving is performed in the
1059 // context of `rfh`. For example, the associated navigation isolation info
Jeremy Roman4d408d8a2024-01-10 02:27:211060 // will be used for making the network request. If `is_subresource` is true,
1061 // the URL is assumed to correspond to a subresource loaded in the frame,
1062 // as opposed to the main (generally, document) resource.
Yao Xiaoe5007042021-02-26 02:32:091063 virtual void SaveFrameWithHeaders(const GURL& url,
1064 const Referrer& referrer,
1065 const std::string& headers,
Jan Wilken Dörrieaace0cfef2021-03-11 22:01:581066 const std::u16string& suggested_filename,
Jeremy Roman4d408d8a2024-01-10 02:27:211067 RenderFrameHost* rfh,
1068 bool is_subresource) = 0;
kundaji6c7f9692015-03-09 18:00:371069
Angel Alvarez902496682019-08-27 22:58:421070 // Generate an MHTML representation of the current page conforming to the
1071 // settings provided by |params| and returning final status information via
1072 // the callback. See MHTMLGenerationParams for details on generation settings.
1073 // A resulting |file_size| of -1 represents a failure. Any other value
1074 // represents the size of the successfully generated file.
1075 //
1076 // TODO(https://crbug.com/915966): GenerateMHTML will eventually be removed
1077 // and GenerateMHTMLWithResult will be renamed to GenerateMHTML to replace it.
1078 // Both GenerateMHTML and GenerateMHTMLWithResult perform the same operation.
1079 // however, GenerateMHTMLWithResult provides a struct as output, that contains
1080 // the file size and more.
[email protected]aa4f3972012-03-01 18:12:121081 virtual void GenerateMHTML(
dewittj6dc5747a2016-05-17 01:48:471082 const MHTMLGenerationParams& params,
Tsuyoshi Horob0d8d902020-03-12 00:09:391083 base::OnceCallback<void(int64_t /* file_size */)> callback) = 0;
Angel Alvarez902496682019-08-27 22:58:421084 virtual void GenerateMHTMLWithResult(
1085 const MHTMLGenerationParams& params,
1086 MHTMLGenerationResult::GenerateMHTMLCallback callback) = 0;
[email protected]aa4f3972012-03-01 18:12:121087
Takashi Toyoshima6c58bbd2023-05-19 09:41:351088 // Returns the MIME type bound to the primary page contents after a primary
1089 // page navigation.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411090 virtual const std::string& GetContentsMimeType() = 0;
[email protected]0bfbf882011-12-22 18:19:271091
[email protected]0bfbf882011-12-22 18:19:271092 // Returns the settings which get passed to the renderer.
Mario Sanchez Prada0bd8b8c2020-10-21 17:49:231093 virtual blink::RendererPreferences* GetMutableRendererPrefs() = 0;
[email protected]0bfbf882011-12-22 18:19:271094
[email protected]e35ccd552012-05-23 16:22:471095 // Tells the tab to close now. The tab will take care not to close until it's
gab2998ee72017-05-05 16:23:501096 // out of nested run loops.
[email protected]e35ccd552012-05-23 16:22:471097 virtual void Close() = 0;
1098
[email protected]0bfbf882011-12-22 18:19:271099 // Indicates if this tab was explicitly closed by the user (control-w, close
1100 // tab menu item...). This is false for actions that indirectly close the tab,
1101 // such as closing the window. The setter is maintained by TabStripModel, and
1102 // the getter only useful from within TAB_CLOSED notification
1103 virtual void SetClosedByUserGesture(bool value) = 0;
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411104 virtual bool GetClosedByUserGesture() = 0;
[email protected]0bfbf882011-12-22 18:19:271105
[email protected]0bfbf882011-12-22 18:19:271106 // Gets the minimum/maximum zoom percent.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411107 virtual int GetMinimumZoomPercent() = 0;
1108 virtual int GetMaximumZoomPercent() = 0;
[email protected]0bfbf882011-12-22 18:19:271109
mcnee432e47d2015-11-09 19:37:461110 // Set the renderer's page scale to the given factor.
1111 virtual void SetPageScale(float page_scale_factor) = 0;
ccameronb7c1d6c2015-03-09 17:08:241112
[email protected]bcd2815602012-01-14 18:17:231113 // Gets the preferred size of the contents.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411114 virtual gfx::Size GetPreferredSize() = 0;
[email protected]bcd2815602012-01-14 18:17:231115
Takumi Fujimoto4661871d2024-01-25 02:04:181116 // Called when the response to a pending pointer lock request has arrived.
[email protected]0bfbf882011-12-22 18:19:271117 // Returns true if |allowed| is true and the mouse has been successfully
1118 // locked.
Takumi Fujimoto4661871d2024-01-25 02:04:181119 virtual bool GotResponseToPointerLockRequest(
James Hollyerd5c9de462020-03-10 19:02:451120 blink::mojom::PointerLockResult result) = 0;
1121
Takumi Fujimoto4661871d2024-01-25 02:04:181122 // Wrapper around GotResponseToPointerLockRequest to fit into
James Hollyerd5c9de462020-03-10 19:02:451123 // ChromeWebViewPermissionHelperDelegate's structure.
Takumi Fujimoto4661871d2024-01-25 02:04:181124 virtual void GotPointerLockPermissionResponse(bool allowed) = 0;
[email protected]bb81f382012-01-03 22:45:441125
Dave Tapuskab4998782020-10-08 17:22:471126 // Drop the mouse lock if it is currently locked, or reject an
1127 // outstanding request if it is pending.
Takumi Fujimoto4661871d2024-01-25 02:04:181128 virtual void DropPointerLockForTesting() = 0;
Dave Tapuskab4998782020-10-08 17:22:471129
Joe Downing13dd76b2018-04-09 18:32:151130 // Called when the response to a keyboard mouse lock request has arrived.
1131 // Returns false if the request is no longer valid, otherwise true.
1132 virtual bool GotResponseToKeyboardLockRequest(bool allowed) = 0;
1133
Julie Jeongeun Kim88ce9ec2023-07-28 02:25:401134#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_APPLE)
[email protected]da8543762012-03-20 08:52:201135 // Called when the user has selected a color in the color chooser.
[email protected]cb805452013-05-22 15:16:211136 virtual void DidChooseColorInColorChooser(SkColor color) = 0;
[email protected]da8543762012-03-20 08:52:201137
1138 // Called when the color chooser has ended.
[email protected]cb805452013-05-22 15:16:211139 virtual void DidEndColorChooser() = 0;
Julie Jeongeun Kim88ce9ec2023-07-28 02:25:401140#endif
[email protected]da8543762012-03-20 08:52:201141
[email protected]bb81f382012-01-03 22:45:441142 // Returns true if the location bar should be focused by default rather than
1143 // the page contents. The view calls this function when the tab is focused
1144 // to see what it should do.
1145 virtual bool FocusLocationBarByDefault() = 0;
1146
jochen6004a362017-02-04 00:11:401147 // Does this have an opener (corresponding to window.opener in JavaScript)
1148 // associated with it?
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411149 virtual bool HasOpener() = 0;
[email protected]795c28972012-12-06 06:13:391150
mlamouri8c61ffc2015-01-13 16:17:591151 // Returns the opener if HasOpener() is true, or nullptr otherwise.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411152 virtual RenderFrameHost* GetOpener() = 0;
jochen55ff3502014-12-18 20:52:571153
jochen6004a362017-02-04 00:11:401154 // Returns true if this WebContents was opened by another WebContents, even
1155 // if the opener was suppressed. In contrast to HasOpener/GetOpener, the
Rakina Zata Amni3a48ae42022-05-05 03:39:561156 // "original opener chain" doesn't reflect window.opener which can be
1157 // suppressed or updated. The "original opener" is the main frame of the
1158 // actual opener of this frame. This traces the all the way back, so if the
1159 // original opener was closed (deleted or severed due to COOP), but _it_ had
1160 // an original opener, this will return the original opener's original opener,
1161 // etc.
1162 virtual bool HasLiveOriginalOpenerChain() = 0;
jochen6004a362017-02-04 00:11:401163
Rakina Zata Amni3a48ae42022-05-05 03:39:561164 // Returns the "original opener WebContents" if HasLiveOriginalOpenerChain()
1165 // is true, or nullptr otherwise. See the comment for
1166 // `HasLiveOriginalOpenerChain()` for more details.
1167 virtual WebContents* GetFirstWebContentsInLiveOriginalOpenerChain() = 0;
jochen6004a362017-02-04 00:11:401168
ke.he98b761e2017-05-09 05:59:171169 // Returns the WakeLockContext accociated with this WebContents.
1170 virtual device::mojom::WakeLockContext* GetWakeLockContext() = 0;
1171
Alan Cutter1c0d3732020-03-04 14:56:211172 // |http_status_code| can be 0 e.g. for data: URLs.
1173 // |bitmaps| will be empty on download failure.
1174 // |sizes| are the sizes in pixels of the bitmaps before they were resized due
1175 // to the max bitmap size passed to DownloadImage(). Each entry in the bitmaps
Mikel Astiz034ba14e2021-04-30 07:23:491176 // vector corresponds to an entry in the sizes vector (both vector sizes are
1177 // guaranteed to be equal). If a bitmap was resized, there should be a single
1178 // returned bitmap.
Alan Cutter1c0d3732020-03-04 14:56:211179 using ImageDownloadCallback =
1180 base::OnceCallback<void(int id,
1181 int http_status_code,
1182 const GURL& image_url,
1183 const std::vector<SkBitmap>& bitmaps,
1184 const std::vector<gfx::Size>& sizes)>;
[email protected]795c28972012-12-06 06:13:391185
[email protected]41225fe2013-03-29 05:32:021186 // Sends a request to download the given image |url| and returns the unique
[email protected]795c28972012-12-06 06:13:391187 // id of the download request. When the download is finished, |callback| will
pkotwiczfd773552015-03-16 00:29:141188 // be called with the bitmaps received from the renderer.
1189 // If |is_favicon| is true, the cookies are not sent and not accepted during
1190 // download.
Eric Secklerfaddda8c2022-08-11 18:05:491191 // If there are no bitmap results <= |max_bitmap_size|, the smallest bitmap
1192 // is resized to |max_bitmap_size| and is the only result.
Dibyajyoti Pal328a1752022-07-22 16:33:451193 // A |max_bitmap_size| of 0 means unlimited.
Fredrik Söderquistb2b39eb92019-11-18 16:16:501194 // For vector images, |preferred_size| will serve as a viewport into which
1195 // the image will be rendered. This would usually be the dimensions of the
Rouslan Solomakhindb19343e2021-09-15 15:34:551196 // rectangle where the bitmap will be rendered. If |preferred_size| is empty,
1197 // any existing intrinsic dimensions of the image will be used. If
Fredrik Söderquistb2b39eb92019-11-18 16:16:501198 // |max_bitmap_size| is non-zero it will also impose an upper bound on the
Rouslan Solomakhindb19343e2021-09-15 15:34:551199 // longest edge of |preferred_size| (|preferred_size| will be scaled down).
pkotwiczfd773552015-03-16 00:29:141200 // If |bypass_cache| is true, |url| is requested from the server even if it
1201 // is present in the browser cache.
[email protected]41225fe2013-03-29 05:32:021202 virtual int DownloadImage(const GURL& url,
1203 bool is_favicon,
Rouslan Solomakhindb19343e2021-09-15 15:34:551204 const gfx::Size& preferred_size,
[email protected]263cb08f2013-09-18 00:26:301205 uint32_t max_bitmap_size,
pkotwiczfd773552015-03-16 00:29:141206 bool bypass_cache,
Avi Drissmana5a52dd2018-03-27 03:39:021207 ImageDownloadCallback callback) = 0;
[email protected]795c28972012-12-06 06:13:391208
Danyao Wanga78f3dd22020-03-05 05:31:271209 // Same as DownloadImage(), but uses the ImageDownloader from the specified
1210 // frame instead of the main frame.
1211 virtual int DownloadImageInFrame(
Alexander Timin8690530c2021-06-19 00:34:321212 const GlobalRenderFrameHostId& initiator_frame_routing_id,
Danyao Wanga78f3dd22020-03-05 05:31:271213 const GURL& url,
1214 bool is_favicon,
Rouslan Solomakhindb19343e2021-09-15 15:34:551215 const gfx::Size& preferred_size,
Danyao Wanga78f3dd22020-03-05 05:31:271216 uint32_t max_bitmap_size,
1217 bool bypass_cache,
1218 ImageDownloadCallback callback) = 0;
1219
Joey Arharcac45bf2022-01-07 21:59:311220 // Finds text on a page. |search_text| should not be empty. |skip_delay|
1221 // indicates that the find request should be sent to the renderer immediately
1222 // instead of waiting for privacy/performance mitigations.
[email protected]36ec24f2014-01-09 00:32:081223 virtual void Find(int request_id,
Jan Wilken Dörrieaace0cfef2021-03-11 22:01:581224 const std::u16string& search_text,
Joey Arharcac45bf2022-01-07 21:59:311225 blink::mojom::FindOptionsPtr options,
1226 bool skip_delay = false) = 0;
[email protected]36ec24f2014-01-09 00:32:081227
1228 // Notifies the renderer that the user has closed the FindInPage window
1229 // (and what action to take regarding the selection).
1230 virtual void StopFinding(StopFindAction action) = 0;
1231
Tommy Steimel18360512017-11-01 00:38:191232 // Returns true if audio has been audible from the WebContents since the last
1233 // navigation.
1234 virtual bool WasEverAudible() = 0;
1235
avi0720b02e2017-06-13 03:22:131236 // Returns whether the renderer is in fullscreen mode.
Avi Drissman97aef042020-06-30 21:04:481237 virtual bool IsFullscreen() = 0;
avi0720b02e2017-06-13 03:22:131238
Rakina Zata Amni347b70902020-07-22 10:49:041239 // Returns a copy of the current WebPreferences associated with this
1240 // WebContents. If it does not exist, this will create one and send the newly
1241 // computed value to all renderers.
1242 // Note that this will not trigger a recomputation of WebPreferences if it
1243 // already exists - this will return the last computed/set value of
1244 // WebPreferences. If we want to guarantee that the value reflects the current
1245 // state of the WebContents, NotifyPreferencesChanged() should be called
1246 // before calling this.
Gyuyoung Kim1ac4ca782020-09-11 03:32:511247 virtual const blink::web_pref::WebPreferences&
1248 GetOrCreateWebPreferences() = 0;
Rakina Zata Amni347b70902020-07-22 10:49:041249
1250 // Notify this WebContents that the preferences have changed, so it needs to
1251 // recompute the current WebPreferences based on the current state of the
1252 // WebContents, etc. This will send an IPC to all the renderer processes
1253 // associated with this WebContents.
Rakina Zata Amni4029b6d2020-07-28 02:36:201254 // Note that this will do this by creating a new WebPreferences with default
1255 // values, then recomputing some of the attributes based on current states.
1256 // This means if there's any value previously set through SetWebPreferences
1257 // which does not have special recomputation logic in either
1258 // WebContentsImpl::ComputeWebPreferences or
1259 // ContentBrowserClient::OverrideWebkitPrefs, it will return back to its
1260 // default value whenever this function is called.
Rakina Zata Amni347b70902020-07-22 10:49:041261 virtual void NotifyPreferencesChanged() = 0;
1262
1263 // Sets the WebPreferences to |prefs|. This will send an IPC to all the
1264 // renderer processes associated with this WebContents.
1265 // Note that this is different from NotifyPreferencesChanged, which recomputes
1266 // the WebPreferences based on the current state of things. Instead, we're
1267 // setting this to a specific value. This also means that if we trigger a
1268 // recomputation of WebPreferences after this, the WebPreferences value will
Rakina Zata Amni4029b6d2020-07-28 02:36:201269 // be overridden. if there's any value previously set through
1270 // SetWebPreferences which does not have special recomputation logic in either
1271 // WebContentsImpl::ComputeWebPreferences or
1272 // ContentBrowserClient::OverrideWebkitPrefs, it will return back to its
1273 // default value, which might be different from the value we set it to here.
1274 // If you want to use this function outside of tests, consider adding
1275 // recomputation logic in either of those functions.
1276 // TODO(rakina): Try to make values set through this function stick even after
1277 // recomputations.
Gyuyoung Kim1ac4ca782020-09-11 03:32:511278 virtual void SetWebPreferences(
1279 const blink::web_pref::WebPreferences& prefs) = 0;
Rakina Zata Amni347b70902020-07-22 10:49:041280
Rakina Zata Amni4029b6d2020-07-28 02:36:201281 // Passes current web preferences to all renderer in this WebContents after
1282 // possibly recomputing them as follows: all "fast" preferences (those not
1283 // requiring slow platform/device polling) are recomputed unconditionally; the
1284 // remaining "slow" ones are recomputed only if they have not been computed
1285 // before.
1286 //
1287 // This method must be called if any state that affects web preferences has
1288 // changed so that it can be recomputed and sent to the renderer.
1289 virtual void OnWebPreferencesChanged() = 0;
1290
Muyao Xudb226be52023-12-01 04:23:091291 // Requests the renderer to exit fullscreen.
1292 // |will_cause_resize| indicates whether the fullscreen change causes a
1293 // view resize. e.g. This will be false when going from tab fullscreen to
1294 // browser fullscreen.
1295 virtual void ExitFullscreen(bool will_cause_resize) = 0;
mlamouri7a78d6fd2015-01-17 13:23:531296
Avi Drissmanced52b62019-08-14 21:25:461297 // The WebContents is trying to take some action that would cause user
1298 // confusion if taken while in fullscreen. If this WebContents or any outer
1299 // WebContents is in fullscreen, drop it.
Avi Drissman1a55a9d62020-03-10 18:56:451300 //
1301 // Returns a ScopedClosureRunner, and for the lifetime of that closure, this
1302 // (and other related) WebContentses will not enter fullscreen. If the action
1303 // should cause a one-time dropping of fullscreen (e.g. a UI element not
1304 // attached to the WebContents), invoke RunAndReset() on the returned
1305 // base::ScopedClosureRunner to release the fullscreen block immediately.
1306 // Otherwise, if the action should cause fullscreen to be prohibited for a
1307 // span of time (e.g. a UI element attached to the WebContents), keep the
1308 // closure alive for that duration.
Mike Wassermanb6bc0152020-08-25 22:46:201309 //
1310 // If |display_id| is valid, only WebContentses on that specific screen will
1311 // exit fullscreen; the scoped prohibition will still apply to all displays.
1312 // This supports sites using cross-screen window placement capabilities to
1313 // retain fullscreen and open or place a window on another screen.
Daniel Cheng9c9fa1a2022-01-14 03:42:111314 [[nodiscard]] virtual base::ScopedClosureRunner ForSecurityDropFullscreen(
1315 int64_t display_id = display::kInvalidDisplayId) = 0;
Avi Drissmanced52b62019-08-14 21:25:461316
mariakhomenko44bdc4732015-04-29 01:55:381317 // Unblocks requests from renderer for a newly created window. This is
1318 // used in showCreatedWindow() or sometimes later in cases where
1319 // delegate->ShouldResumeRequestsForCreatedWindow() indicated the requests
1320 // should not yet be resumed. Then the client is responsible for calling this
1321 // as soon as they are ready.
1322 virtual void ResumeLoadingCreatedWebContents() = 0;
1323
qinmin72e8bd02016-10-21 19:35:371324 // Sets whether the WebContents is for overlaying content on a page.
1325 virtual void SetIsOverlayContent(bool is_overlay_content) = 0;
1326
billorr21c005d2016-11-17 03:57:041327 virtual int GetCurrentlyPlayingVideoCount() = 0;
peconn257951522017-06-09 18:24:591328
Arthur Sonzognic686e8f2024-01-11 08:36:371329 virtual std::optional<gfx::Size> GetFullscreenVideoSize() = 0;
billorr21c005d2016-11-17 03:57:041330
ekaramad5c1f9392017-01-25 02:05:231331 // Tells the renderer to clear the focused element (if any).
1332 virtual void ClearFocusedElement() = 0;
1333
1334 // Returns true if the current focused element is editable.
1335 virtual bool IsFocusedElementEditable() = 0;
1336
ekaramadf6750aa2017-06-06 18:29:421337 // Returns true if a context menu is showing on the page.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411338 virtual bool IsShowingContextMenu() = 0;
ekaramadf6750aa2017-06-06 18:29:421339
1340 // Tells the WebContents whether the context menu is showing.
1341 virtual void SetShowingContextMenu(bool showing) = 0;
1342
Xiaohan Wang6099ccb2022-01-13 22:09:421343#if BUILDFLAG(IS_ANDROID)
[email protected]155c7f22013-12-09 17:07:181344 CONTENT_EXPORT static WebContents* FromJavaWebContents(
torneb5fe8a62016-09-08 12:00:541345 const base::android::JavaRef<jobject>& jweb_contents_android);
[email protected]155c7f22013-12-09 17:07:181346 virtual base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents() = 0;
paulmeyerc0b762b2016-04-13 11:55:171347
Nicolas Ouellet-Payeur177a6c42023-01-25 20:25:071348 // Returns the value from CreateParams::java_creator_location.
1349 virtual base::android::ScopedJavaLocalRef<jthrowable>
1350 GetJavaCreatorLocation() = 0;
1351
paulmeyerc0b762b2016-04-13 11:55:171352 // Selects and zooms to the find result nearest to the point (x,y) defined in
1353 // find-in-page coordinates.
1354 virtual void ActivateNearestFindResult(float x, float y) = 0;
1355
1356 // Requests the rects of the current find matches from the renderer
1357 // process. |current_version| is the version of find rects that the caller
1358 // already knows about. This version will be compared to the current find
1359 // rects version in the renderer process (which is updated whenever the rects
1360 // change), to see which new rect data will need to be sent back.
1361 //
1362 // TODO(paulmeyer): This process will change slightly once multi-process
1363 // find-in-page is implemented. This comment should be updated at that time.
1364 virtual void RequestFindMatchRects(int current_version) = 0;
sammcf5f1b0f2016-09-20 23:05:111365
1366 // Returns an InterfaceProvider for Java-implemented interfaces that are
1367 // scoped to this WebContents. This provides access to interfaces implemented
1368 // in Java in the browser process to C++ code in the browser process.
rockot400ea35b2016-10-15 19:15:321369 virtual service_manager::InterfaceProvider* GetJavaInterfaces() = 0;
Xiaohan Wangf9beb2ea1d2022-01-15 22:14:541370#endif // BUILDFLAG(IS_ANDROID)
[email protected]155c7f22013-12-09 17:07:181371
Francois Doray6c26f3342018-08-24 17:17:221372 // Returns true if the WebContents has completed its first meaningful paint
1373 // since the last navigation.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411374 virtual bool CompletedFirstVisuallyNonEmptyPaint() = 0;
Francois Doray6c26f3342018-08-24 17:17:221375
Alison Gale923a33e2024-04-22 23:34:281376 // TODO(crbug.com/41379215): This is a simple mitigation to validate
Min Qin7b7cbbbf2018-06-04 21:49:311377 // that an action that requires a user gesture actually has one in the
1378 // trustworthy browser process, rather than relying on the untrustworthy
1379 // renderer. This should be eventually merged into and accounted for in the
Evan Stade6decc972022-10-24 19:42:181380 // user activation work: crbug.com/848778
1381 virtual bool HasRecentInteraction() = 0;
Min Qin7b7cbbbf2018-06-04 21:49:311382
Frank Liberatoe837b362023-10-20 23:31:151383 // Causes the WebContents to ignore input events for at least as long as the
Takashi Toyoshimad72a465a2024-03-11 23:37:311384 // token exists. In the event of multiple calls, input events will be ignored
Frank Liberatoe837b362023-10-20 23:31:151385 // until all tokens have been destroyed.
Takashi Toyoshimad72a465a2024-03-11 23:37:311386 // If WebInputEventAuditCallback is given, it can audits WebInputEvent based
1387 // input events and ignore only events that the callback returns false for the
1388 // event. Other kind of events, such as focus event or ui::Events will be
1389 // always ignored without asking the callback. The given callback will be
1390 // invoked only while the returned ScopedIgnoreInputEvents alives.
1391 using WebInputEventAuditCallback =
1392 base::RepeatingCallback<bool(const blink::WebInputEvent&)>;
1393 [[nodiscard]] virtual ScopedIgnoreInputEvents IgnoreInputEvents(
1394 std::optional<WebInputEventAuditCallback> audit_callback) = 0;
Avi Drissman738ea192018-08-29 20:24:161395
Aidan Wolter52bcc12a2018-11-14 03:27:291396 // Returns the group id for all audio streams that correspond to a single
1397 // WebContents. This can be used to determine if a AudioOutputStream was
1398 // created from a renderer that originated from this WebContents.
1399 virtual base::UnguessableToken GetAudioGroupId() = 0;
1400
Mounir Lamouri7b4a1f232019-12-23 16:32:101401 // Returns the raw list of favicon candidates as reported to observers via
1402 // WebContentsObserver::DidUpdateFaviconURL() since the last navigation start.
1403 // Consider using FaviconDriver in components/favicon if possible for more
1404 // reliable favicon-related state.
Miyoung Shin5709ab02020-02-19 06:50:411405 virtual const std::vector<blink::mojom::FaviconURLPtr>& GetFaviconURLs() = 0;
Mounir Lamouri7b4a1f232019-12-23 16:32:101406
Amanda Baker228ec482021-03-24 19:50:081407 // Intended for desktop PWAs with manifest entry of window-controls-overlay,
1408 // This sends the available title bar area bounds to the renderer process.
1409 virtual void UpdateWindowControlsOverlay(const gfx::Rect& bounding_rect) = 0;
Hassan Talatd96dbc02021-01-20 08:02:041410
Amanda Bakercee4f7f2021-07-02 01:53:471411 // Returns the Window Control Overlay rectangle. Only applies to an
1412 // outermost main frame's widget. Other widgets always returns an empty rect.
1413 virtual gfx::Rect GetWindowsControlsOverlayRect() const = 0;
1414
Sebastien Marchandc38e5ae2021-02-18 20:28:131415 // Whether the WebContents has an active player that is effectively
1416 // fullscreen. That means that the video is either fullscreen or it is the
1417 // content of a fullscreen page (in other words, a fullscreen video with
1418 // custom controls).
1419 virtual bool HasActiveEffectivelyFullscreenVideo() = 0;
1420
Alexander Timine9f413e82021-03-12 14:06:441421 // Serialise this object into a trace.
Alexander Timinbebb2002021-04-20 15:42:241422 virtual void WriteIntoTrace(perfetto::TracedValue context) = 0;
Alexander Timine9f413e82021-03-12 14:06:441423
Lukasz Anforowicz2c1573a2021-09-21 18:58:181424 // Returns the value from CreateParams::creator_location.
1425 virtual const base::Location& GetCreatorLocation() = 0;
1426
Tommy Steimel57eafde2023-01-27 17:33:241427 // Returns the parameters associated with PictureInPicture WebContents
Arthur Sonzognic686e8f2024-01-11 08:36:371428 virtual const std::optional<blink::mojom::PictureInPictureWindowOptions>&
Tommy Steimel57eafde2023-01-27 17:33:241429 GetPictureInPictureOptions() const = 0;
Tommy Steimel991916c42022-06-24 20:59:571430
Yoshisato Yanagisawa607a7cca2021-10-14 02:45:361431 // Hide or show the browser controls for the given WebContents, based on
1432 // allowed states, desired state and whether the transition should be animated
1433 // or not.
1434 virtual void UpdateBrowserControlsState(cc::BrowserControlsState constraints,
1435 cc::BrowserControlsState current,
1436 bool animate) = 0;
1437
Marja Hölttä2019e9d2023-09-07 14:07:351438 // Transmits data to V8CrowdsourcedCompileHintsConsumer in the renderer. The
1439 // data is a model describing which JavaScript functions on the page should be
1440 // eagerly parsed & compiled by the JS engine.
1441 virtual void SetV8CompileHints(base::ReadOnlySharedMemoryRegion data) = 0;
1442
Joe Mason7ae0e2b2021-11-01 12:30:361443 // Sets the last time a tab switch made this WebContents visible.
1444 // `start_time` is the timestamp of the input event that triggered the tab
1445 // switch. `destination_is_loaded` is true when
1446 // ResourceCoordinatorTabHelper::IsLoaded() is true for the new tab contents.
1447 // These will be used to record metrics with the latency between the input
1448 // event and the time when the WebContents is painted.
1449 virtual void SetTabSwitchStartTime(base::TimeTicks start_time,
1450 bool destination_is_loaded) = 0;
1451
Takashi Toyoshima8dfc05c2024-01-29 21:03:511452 // Checks if the WebContents host pages in preview mode.
1453 virtual bool IsInPreviewMode() const = 0;
1454
1455 // Called before ActivatePreviewPage() to prepare the activation. This will
1456 // end the preview mode and IsInPreviewMode() will start returning false after
1457 // the call. This allows embedders to run preparation steps on the activating
1458 // WebContents (e.g. attach TabHelpers) before activating the page shown by
1459 // the WebContents through ActivatePreviewPage().
1460 virtual void WillActivatePreviewPage() = 0;
1461
Takashi Toyoshima9ca82102023-10-24 02:13:271462 // Activates the primary page that is shown in preview mode. This will relax
1463 // capability restriction in the browser process, and notify the renderer to
1464 // process the prerendering activation algorithm.
Takashi Toyoshima138cf44a2023-11-02 10:33:251465 // This all processes happens asynchronously, and
1466 // `WebContentsDelegate::DidActivatePreviewedPage` will be called once it's
1467 // done.
Takashi Toyoshima138cf44a2023-11-02 10:33:251468 virtual void ActivatePreviewPage() = 0;
Takashi Toyoshima9ca82102023-10-24 02:13:271469
Robert Linc37fb582021-11-11 03:18:471470 // Starts an embedder triggered (browser-initiated) prerendering page and
1471 // returns the unique_ptr<PrerenderHandle>, which cancels prerendering on its
1472 // destruction. If the prerendering failed to start (e.g. if prerendering is
1473 // disabled, failure happened or because this URL is already being
1474 // prerendered), this function returns a nullptr.
Sreeja Kamishettyac12140e2022-07-14 22:16:511475 // PreloadingAttempt helps us to log various metrics associated with
1476 // particular prerendering attempt. `url_match_predicate` allows embedders to
1477 // define their own predicates for matching same-origin URLs during
1478 // prerendering activation; it would be useful if embedders want Prerender2 to
1479 // ignore some parameter mismatches. Note that if the mismatched prerender URL
1480 // will be activated due to the predicate returning true, the last committed
1481 // URL in the prerendered RenderFrameHost will be activated.
HuanPo Lin2ebb36c2023-10-06 01:48:481482 // `prerender_navigation_handle_callback` allows embedders to attach their own
1483 // NavigationHandleUserData when prerender starts, and the user data can be
1484 // used for identifying the types of embedder for metrics logging.
Robert Linc37fb582021-11-11 03:18:471485 virtual std::unique_ptr<PrerenderHandle> StartPrerendering(
Asami Doicf0f1642021-11-25 05:00:261486 const GURL& prerendering_url,
Kouhei Ueno3f37992b2023-11-09 23:29:021487 PreloadingTriggerType trigger_type,
Robert Lin125720c042022-01-21 01:14:581488 const std::string& embedder_histogram_suffix,
Lingqi Chi21d9feb2022-02-02 09:42:181489 ui::PageTransition page_transition,
Domenic Denicolabb5d843c2023-07-18 01:47:331490 PreloadingHoldbackStatus holdback_status_override,
Sreeja Kamishettyac12140e2022-07-14 22:16:511491 PreloadingAttempt* preloading_attempt,
Taiyo Mizuhashi72be9642024-03-21 13:45:371492 base::RepeatingCallback<bool(const GURL&)> url_match_predicate,
Arthur Sonzognifd1e08d2024-03-05 15:59:361493 base::RepeatingCallback<void(NavigationHandle&)>
Taiyo Mizuhashi72be9642024-03-21 13:45:371494 prerender_navigation_handle_callback) = 0;
Robert Linc37fb582021-11-11 03:18:471495
Kevin McNee097680d2023-04-05 22:14:511496 // May be called when the embedder believes that it is likely that the user
1497 // will perform a back navigation due to the trigger indicated by `predictor`
1498 // (e.g. they're hovering over a back button). `disposition` indicates where
1499 // the navigation is predicted to happen (which could differ from where the
1500 // navigation actually happens).
1501 virtual void BackNavigationLikely(PreloadingPredictor predictor,
1502 WindowOpenDisposition disposition) = 0;
1503
Andy Paicu5608bda82023-03-03 15:09:201504 // Returns a scope object that needs to be owned by caller in order to
Jan Keitel1d8d51d2023-08-22 05:53:471505 // disallow custom cursors. Custom cursors whose width or height are larger
1506 // than `max_dimension_dips` are diallowed in this web contents for as long as
1507 // any of the returned `ScopedClosureRunner` objects is alive.
Andy Paicu5608bda82023-03-03 15:09:201508 [[nodiscard]] virtual base::ScopedClosureRunner
Jan Keitel1d8d51d2023-08-22 05:53:471509 CreateDisallowCustomCursorScope(int max_dimension_dips = 0) = 0;
Andy Paicu5608bda82023-03-03 15:09:201510
Charles Mengc2cca37e2023-08-15 18:14:301511 // Enables overscroll history navigation.
1512 virtual void SetOverscrollNavigationEnabled(bool enabled) = 0;
1513
Bo Liud4ced692023-09-18 21:17:141514 // Tag `WebContents` with its owner. Used purely for debugging purposes so it
1515 // does not need to be exhaustive or perfectly correct.
Alison Gale81f4f2c72024-04-22 19:33:311516 // TODO(crbug.com/40062641): Remove after bug is fixed.
Bo Liud4ced692023-09-18 21:17:141517 virtual void SetOwnerLocationForDebug(
Arthur Sonzognic686e8f2024-01-11 08:36:371518 std::optional<base::Location> owner_location) = 0;
Bo Liud4ced692023-09-18 21:17:141519
Joanne de Abreu7cbed872023-10-30 23:25:261520 // Sends the attribution support state to all renderer processes for the
1521 // current page.
1522 virtual void UpdateAttributionSupportRenderer() = 0;
1523
Bryant Chandler490c6de2024-01-02 22:08:361524 // Return all currently streaming devices of `type` via `callback`.
1525 virtual void GetMediaCaptureRawDeviceIdsOpened(
1526 blink::mojom::MediaStreamType type,
1527 base::OnceCallback<void(std::vector<std::string>)> callback) = 0;
1528
William Liu6cf58fe2024-01-19 21:29:321529 // Returns an animation manager that displays a preview of the history page
1530 // during a session history navigation gesture. Only non-null if
1531 // `features::kBackForwardTransitions` is enabled for the supported platform.
1532 virtual BackForwardTransitionAnimationManager*
1533 GetBackForwardTransitionAnimationManager() = 0;
1534
[email protected]7f4a04c2013-03-11 23:04:201535 private:
1536 // This interface should only be implemented inside content.
1537 friend class WebContentsImpl;
Avi Drissman0b2a20d2021-12-08 00:59:161538 WebContents() = default;
[email protected]6934a702011-12-20 00:04:511539};
1540
1541} // namespace content
1542
[email protected]58f5d562011-12-20 17:13:031543#endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_H_