blob: 1cb1c2f1a30d3ede5cf920ac34ac6b5c3ba2b7cc [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
avib7348942015-12-25 20:57:107#include <stddef.h>
8
w.shackleton49bcd392016-01-06 17:38:229#include <cmath>
[email protected]2bb171882012-03-07 02:09:4610#include <utility>
rkaplowe56a52032017-02-07 00:14:5411#include <vector>
[email protected]b75b8292010-10-01 07:28:2512
Sebastien Marchandf8cbfab2019-01-25 16:02:3013#include "base/bind.h"
[email protected]36fb2c7c2011-04-04 15:49:0814#include "base/command_line.h"
creisfafed882016-07-29 00:03:0915#include "base/debug/dump_without_crashing.h"
zqzhang181047e62016-07-01 13:37:1716#include "base/feature_list.h"
Marijn Kruisselbrink46fa4bd2019-07-11 18:15:4717#include "base/files/file_path.h"
[email protected]cbb1ef592013-06-05 19:49:4618#include "base/lazy_instance.h"
skyostil95082a62015-06-05 19:53:0719#include "base/location.h"
[email protected]6d636e62013-07-31 03:15:5620#include "base/logging.h"
avib7348942015-12-25 20:57:1021#include "base/macros.h"
fdorayba121422016-12-23 19:51:4822#include "base/memory/ptr_util.h"
dmazzonid95ae842016-04-12 21:17:3923#include "base/memory/ref_counted.h"
asvitkine8d51e9d2016-09-02 23:55:4324#include "base/metrics/histogram_macros.h"
bratell0a7406f2017-03-28 07:46:3725#include "base/metrics/user_metrics.h"
Avi Drissman4891b852018-09-25 18:12:5826#include "base/no_destructor.h"
Carlos Caballero1215f882019-10-29 15:58:4327#include "base/optional.h"
[email protected]04cbd3d2013-12-04 04:58:2028#include "base/process/process.h"
skyostil95082a62015-06-05 19:53:0729#include "base/single_thread_task_runner.h"
Arthur Sonzogni929d29f2018-09-17 14:19:4430#include "base/stl_util.h"
[email protected]348fbaac2013-06-11 06:31:5131#include "base/strings/string16.h"
32#include "base/strings/string_number_conversions.h"
Avi Drissman4891b852018-09-25 18:12:5833#include "base/strings/string_split.h"
[email protected]348fbaac2013-06-11 06:31:5134#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0035#include "base/strings/utf_string_conversions.h"
Eric Seckler8652dcd52018-09-20 10:42:2836#include "base/task/post_task.h"
gab30f26df2016-05-11 19:37:5537#include "base/threading/thread_task_runner_handle.h"
[email protected]a43858f2013-06-28 15:18:3738#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4239#include "base/trace_event/trace_event.h"
avib7348942015-12-25 20:57:1040#include "build/build_config.h"
Min Qinda0ed2062018-02-23 22:00:5341#include "components/download/public/common/download_stats.h"
nzolghadrd87a308d2016-12-07 15:45:5642#include "components/rappor/public/rappor_utils.h"
rsleevi24f64dc22015-08-07 21:39:2143#include "components/url_formatter/url_formatter.h"
Abigail Kleinaa898742019-11-01 02:31:2544#include "content/browser/accessibility/accessibility_event_recorder.h"
James Wallace-Leeeafc94cb92018-07-23 21:35:0945#include "content/browser/accessibility/accessibility_tree_formatter_blink.h"
jamescookda2505812015-03-20 18:01:1846#include "content/browser/bad_message.h"
Max Morinddebb972018-09-20 10:04:1447#include "content/browser/browser_main_loop.h"
[email protected]7a846df2012-09-20 19:17:3948#include "content/browser/browser_plugin/browser_plugin_embedder.h"
49#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5950#include "content/browser/child_process_security_policy_impl.h"
John Delaney732721e92020-02-07 23:11:2751#include "content/browser/conversions/conversion_host.h"
Pavel Feldman3c1842b2017-08-02 05:00:1652#include "content/browser/devtools/protocol/page_handler.h"
dgozmanf00c4f72016-10-19 17:45:1553#include "content/browser/devtools/render_frame_devtools_agent_host.h"
Becca Hughes3b5a43482018-07-17 22:31:5554#include "content/browser/display_cutout/display_cutout_host_impl.h"
[email protected]5f2aa722013-08-07 16:59:4155#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0456#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]aa4f3972012-03-01 18:12:1257#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1658#include "content/browser/download/save_package.h"
paulmeyerc0b762b2016-04-13 11:55:1759#include "content/browser/find_request_manager.h"
[email protected]bffc8302014-01-23 20:52:1660#include "content/browser/frame_host/cross_process_frame_connector.h"
ananta4b7467a52016-09-23 01:42:3861#include "content/browser/frame_host/frame_tree_node.h"
[email protected]d4a8ca482013-10-30 21:06:4062#include "content/browser/frame_host/interstitial_page_impl.h"
63#include "content/browser/frame_host/navigation_entry_impl.h"
Arthur Hemeryc3380172018-01-22 14:00:1764#include "content/browser/frame_host/navigation_request.h"
[email protected]6ea6bdf2013-12-06 13:35:0165#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1866#include "content/browser/frame_host/render_frame_host_impl.h"
lfgdb5c4ed2016-03-04 23:09:0767#include "content/browser/frame_host/render_frame_proxy_host.h"
Kenneth Russell954ed9ce2018-04-12 23:07:0168#include "content/browser/gpu/gpu_data_manager_impl.h"
mlamouriefdca9d2014-09-16 16:55:4069#include "content/browser/manifest/manifest_manager_host.h"
Max Morin5bc74f52018-05-09 07:00:2170#include "content/browser/media/audio_stream_broker.h"
dalecurtisbc6572e12014-09-12 19:22:3071#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5272#include "content/browser/media/capture/web_contents_audio_muter.h"
dalecurtis88c240072015-12-09 02:11:1873#include "content/browser/media/media_web_contents_observer.h"
zqzhang1adf3cb2016-11-01 11:26:4574#include "content/browser/media/session/media_session_impl.h"
tommyclieb25b2a2014-11-03 19:45:0975#include "content/browser/plugin_content_origin_whitelist.h"
David Black9cca3592019-11-06 23:02:2276#include "content/browser/renderer_host/frame_token_message_queue.h"
[email protected]f3b1a082011-11-18 00:34:3077#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5078#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3279#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5080#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5981#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4882#include "content/browser/renderer_host/render_widget_host_view_base.h"
Ken Buchanandaef006b2017-08-17 18:32:1583#include "content/browser/renderer_host/render_widget_host_view_child_frame.h"
ekaramadadd882292016-06-08 15:22:5684#include "content/browser/renderer_host/text_input_manager.h"
leon.han552e9de2017-02-09 14:37:3085#include "content/browser/screen_orientation/screen_orientation_provider.h"
[email protected]b6583592012-01-25 19:52:3386#include "content/browser/site_instance_impl.h"
Charlie Reis96077362019-07-04 00:34:0487#include "content/browser/web_contents/javascript_dialog_navigation_deferrer.h"
lfgc740d4b22016-04-15 16:45:3388#include "content/browser/web_contents/web_contents_view_child_frame.h"
[email protected]86a0a6e2013-01-28 06:33:0389#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5690#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1491#include "content/common/browser_plugin/browser_plugin_constants.h"
Paul Meyer0c58c3712016-11-17 22:59:5192#include "content/common/drag_messages.h"
[email protected]f114fa42013-12-06 17:06:4493#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1794#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0795#include "content/common/page_messages.h"
nasko34634672016-07-29 18:46:0696#include "content/common/page_state_serialization.h"
rockot5c478a72016-09-28 23:14:1897#include "content/common/render_message_filter.mojom.h"
[email protected]2c5569662011-03-22 20:45:0298#include "content/common/view_messages.h"
Albert J. Wong3c93c182018-09-27 17:29:4399#include "content/common/widget_messages.h"
Abigail Kleinabb428332019-09-13 18:26:21100#include "content/public/browser/accessibility_tree_formatter.h"
[email protected]31a71eaf2014-03-13 01:47:36101#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:11102#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:28103#include "content/public/browser/browser_plugin_guest_manager.h"
Eric Seckler8652dcd52018-09-20 10:42:28104#include "content/public/browser/browser_task_traits.h"
Gabriel Charette790754c2018-03-16 21:32:59105#include "content/public/browser/browser_thread.h"
[email protected]87f3c082011-10-19 18:07:44106#include "content/public/browser/content_browser_client.h"
Ken Rockotce010f02019-12-12 23:32:32107#include "content/public/browser/device_service.h"
[email protected]e582fdd2011-12-20 16:48:17108#include "content/public/browser/download_manager.h"
Kent Tamura512a27e2018-10-04 00:49:32109#include "content/public/browser/file_select_listener.h"
ekaramada110f642016-12-21 19:47:28110#include "content/public/browser/focused_node_details.h"
[email protected]d9083482012-01-06 00:38:46111#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:15112#include "content/public/browser/javascript_dialog_manager.h"
skyf65d9bb2017-03-24 02:26:39113#include "content/public/browser/keyboard_event_processing_result.h"
[email protected]09d31d52012-03-11 22:30:27114#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:00115#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:37116#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:14117#include "content/public/browser/notification_service.h"
scottmg011d96e32016-06-29 19:15:08118#include "content/public/browser/notification_types.h"
[email protected]95640212014-07-26 18:14:30119#include "content/public/browser/render_widget_host_iterator.h"
Lukasz Anforowicze1b954d92017-10-30 21:28:06120#include "content/public/browser/restore_type.h"
estark5ea80e52015-06-19 18:43:12121#include "content/public/browser/security_style_explanations.h"
falken52a56e32016-12-08 05:02:40122#include "content/public/browser/ssl_status.h"
[email protected]4c3a23582012-08-18 08:54:34123#include "content/public/browser/storage_partition.h"
[email protected]674bc592011-12-20 23:00:42124#include "content/public/browser/web_contents_delegate.h"
Julie Jeongeun Kim7d0986172019-12-04 03:17:25125#include "content/public/browser/web_contents_receiver_set.h"
Lei Zhangee3b63ad2018-06-06 23:25:31126#include "content/public/browser/web_ui_controller.h"
[email protected]e091df82011-10-11 18:13:21127#include "content/public/common/bindings_policy.h"
alexmosc9e76ec2016-05-16 22:59:37128#include "content/public/common/child_process_host.h"
Hans Wennborg5ffd1392019-10-16 11:00:02129#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:48130#include "content/public/common/content_constants.h"
Francois Doray3f2afbd2018-04-06 19:18:18131#include "content/public/common/content_features.h"
[email protected]64d69de42012-02-06 00:19:54132#include "content/public/common/content_switches.h"
Lukasz Anforowicze1b954d92017-10-30 21:28:06133#include "content/public/common/page_state.h"
Leon Han963dc182018-11-06 05:41:48134#include "content/public/common/referrer_type_converters.h"
[email protected]04cbd3d2013-12-04 04:58:20135#include "content/public/common/result_codes.h"
[email protected]f16cc6782013-12-16 23:42:57136#include "content/public/common/url_utils.h"
danakjffc8baf2019-10-10 23:49:42137#include "content/public/common/use_zoom_for_dsf_policy.h"
[email protected]b3a97b52014-07-09 06:25:05138#include "content/public/common/web_preferences.h"
Max Morinddebb972018-09-20 10:04:14139#include "media/base/user_input_monitor.h"
wjmaclean64951902016-04-29 20:59:12140#include "net/base/url_util.h"
[email protected]8bfc8272013-09-09 20:10:53141#include "net/http/http_cache.h"
142#include "net/http/http_transaction_factory.h"
rhalavati0fbaeef32017-06-01 15:56:30143#include "net/traffic_annotation/network_traffic_annotation.h"
[email protected]8bfc8272013-09-09 20:10:53144#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34145#include "net/url_request/url_request_context_getter.h"
Scott Violet02e38b92018-03-27 23:42:14146#include "ppapi/buildflags/buildflags.h"
Mounir Lamourifd9dcefa2017-07-06 10:26:55147#include "services/metrics/public/cpp/ukm_recorder.h"
John Abd-El-Malekb175a612018-12-03 20:11:58148#include "services/network/public/cpp/features.h"
rockot734fb662016-10-15 16:41:30149#include "services/service_manager/public/cpp/interface_provider.h"
Becca Hughes6daf5662018-06-27 16:50:54150#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
Blink Reformata30d4232018-04-07 15:31:06151#include "third_party/blink/public/common/frame/sandbox_flags.h"
152#include "third_party/blink/public/common/mime_util/mime_util.h"
danakj938b37a62019-09-24 18:35:54153#include "third_party/blink/public/common/page/page_zoom.h"
Sergio Villar Senin9d9d4f52019-10-15 10:57:57154#include "third_party/blink/public/common/security/security_style.h"
Abhijeet Kandalkarde7348e2020-01-13 06:06:54155#include "third_party/blink/public/mojom/frame/frame.mojom.h"
Dave Tapuskaa4189512019-10-15 20:27:34156#include "third_party/blink/public/mojom/frame/fullscreen.mojom.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:56157#include "third_party/blink/public/mojom/loader/pause_subresource_loading_handle.mojom.h"
Antonio Gomes0d42960a2019-06-05 12:35:51158#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-shared.h"
halton.huoca2eabd2015-07-06 08:17:40159#include "third_party/skia/include/core/SkBitmap.h"
dmazzonid95ae842016-04-12 21:17:39160#include "ui/accessibility/ax_tree_combiner.h"
[email protected]a08412b62012-05-29 21:28:56161#include "ui/base/layout.h"
Daniel Cheng90196c82018-04-25 21:49:14162#include "ui/events/base_event_utils.h"
chongz4a9751942016-08-17 17:49:39163#include "ui/events/blink/web_input_event_traits.h"
[email protected]66bd5512012-08-01 02:02:52164#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31165
ekaramada110f642016-12-21 19:47:28166#if defined(OS_WIN)
167#include "content/browser/renderer_host/dip_util.h"
168#include "ui/gfx/geometry/dip_util.h"
169#endif
170
[email protected]583418cc2013-01-17 14:01:10171#if defined(OS_ANDROID)
mfomitchev2b8b066a2016-01-28 19:23:15172#include "content/browser/android/date_time_chooser_android.h"
sammcf5f1b0f2016-09-20 23:05:11173#include "content/browser/android/java_interfaces_impl.h"
Leon Hanccb985f2019-08-26 02:43:24174#include "content/browser/android/nfc_host.h"
[email protected]155c7f22013-12-09 17:07:18175#include "content/browser/web_contents/web_contents_android.h"
Ke He31d0bb02018-02-24 07:16:24176#include "services/device/public/mojom/nfc.mojom.h"
mcnee336ea2c2017-05-23 22:50:59177#else // !OS_ANDROID
178#include "content/browser/host_zoom_map_impl.h"
mfomitchev2b8b066a2016-01-28 19:23:15179#endif // OS_ANDROID
[email protected]583418cc2013-01-17 14:01:10180
brettw4b461082016-11-19 18:55:16181#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17182#include "content/browser/media/session/pepper_playback_observer.h"
Lei Zhangebcc6302018-01-12 19:46:45183#endif
zqzhang181047e62016-07-01 13:37:17184
[email protected]8ff00d72012-10-23 19:12:21185namespace content {
Abigail Kleinaa898742019-11-01 02:31:25186
187using AccessibilityEventCallback =
188 base::RepeatingCallback<void(const std::string&)>;
189
[email protected]420ae012009-04-24 05:16:32190namespace {
191
[email protected]960b0372014-05-19 18:01:00192const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41193const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05194
Avi Drissmana9114822018-03-23 18:25:55195base::LazyInstance<std::vector<
196 WebContentsImpl::FriendWrapper::CreatedCallback>>::DestructorAtExit
197 g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
[email protected]cbb1ef592013-06-05 19:49:46198
dcheng57e39e22016-01-21 00:25:38199bool HasMatchingProcess(FrameTree* tree, int render_process_id) {
200 for (FrameTreeNode* node : tree->Nodes()) {
201 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id)
202 return true;
alexmos4cf2aa32015-07-15 23:40:43203 }
dcheng57e39e22016-01-21 00:25:38204 return false;
[email protected]95640212014-07-26 18:14:30205}
206
kenrb19221852016-04-29 17:21:40207bool HasMatchingWidgetHost(FrameTree* tree, RenderWidgetHost* host) {
208 // This method scans the frame tree rather than checking whether
209 // host->delegate() == this, which allows it to return false when the host
210 // for a frame that is pending or pending deletion.
211 if (!host)
212 return false;
213
214 for (FrameTreeNode* node : tree->Nodes()) {
215 if (node->current_frame_host()->GetRenderWidgetHost() == host)
216 return true;
217 }
218 return false;
219}
220
dmazzonif8a31042016-12-03 00:52:13221void UpdateAccessibilityModeOnFrame(RenderFrameHost* frame_host) {
222 static_cast<RenderFrameHostImpl*>(frame_host)->UpdateAccessibilityMode();
[email protected]95640212014-07-26 18:14:30223}
224
dtseng0dd3fa12015-07-22 19:00:52225void ResetAccessibility(RenderFrameHost* rfh) {
226 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
227}
228
Ian Clelland5cbaaf82017-11-27 22:00:03229RenderFrameHostImpl* FindOpenerRFH(const WebContents::CreateParams& params) {
230 RenderFrameHostImpl* opener_rfh = nullptr;
alexmose201c7cd2015-06-10 17:14:21231 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
Ian Clelland5cbaaf82017-11-27 22:00:03232 opener_rfh = RenderFrameHostImpl::FromID(params.opener_render_process_id,
233 params.opener_render_frame_id);
alexmose201c7cd2015-06-10 17:14:21234 }
Ian Clelland5cbaaf82017-11-27 22:00:03235 return opener_rfh;
lukasza6f8ac622017-06-06 03:10:20236}
237
Dominick Ng37a15052018-07-17 23:56:35238// Returns |true| if |type| is the kind of user input that should trigger the
239// user interaction observers.
240bool IsUserInteractionInputType(blink::WebInputEvent::Type type) {
241 // Ideally, this list would be based more off of
242 // https://whatwg.org/C/interaction.html#triggered-by-user-activation.
243 return type == blink::WebInputEvent::kMouseDown ||
244 type == blink::WebInputEvent::kGestureScrollBegin ||
245 type == blink::WebInputEvent::kTouchStart ||
246 type == blink::WebInputEvent::kRawKeyDown;
247}
248
Pavel Feldman3c1842b2017-08-02 05:00:16249// Ensures that OnDialogClosed is only called once.
250class CloseDialogCallbackWrapper
251 : public base::RefCountedThreadSafe<CloseDialogCallbackWrapper> {
252 public:
Avi Drissmane04d3992017-10-05 15:11:36253 using CloseCallback =
254 base::OnceCallback<void(bool, bool, const base::string16&)>;
255
256 explicit CloseDialogCallbackWrapper(CloseCallback callback)
257 : callback_(std::move(callback)) {}
Pavel Feldman3c1842b2017-08-02 05:00:16258
259 void Run(bool dialog_was_suppressed,
260 bool success,
261 const base::string16& user_input) {
Avi Drissmane04d3992017-10-05 15:11:36262 if (callback_.is_null())
Pavel Feldman3c1842b2017-08-02 05:00:16263 return;
Avi Drissmane04d3992017-10-05 15:11:36264 std::move(callback_).Run(dialog_was_suppressed, success, user_input);
Pavel Feldman3c1842b2017-08-02 05:00:16265 }
266
267 private:
268 friend class base::RefCountedThreadSafe<CloseDialogCallbackWrapper>;
269 ~CloseDialogCallbackWrapper() {}
Avi Drissmane04d3992017-10-05 15:11:36270
271 CloseCallback callback_;
Pavel Feldman3c1842b2017-08-02 05:00:16272};
273
Arthur Sonzogni929d29f2018-09-17 14:19:44274bool FrameCompareDepth(RenderFrameHostImpl* a, RenderFrameHostImpl* b) {
275 return a->frame_tree_node()->depth() < b->frame_tree_node()->depth();
276}
277
Raymes Khoury58373df2019-08-06 06:29:20278bool AreValidRegisterProtocolHandlerArguments(const std::string& protocol,
279 const GURL& url,
280 const url::Origin& origin) {
281 ChildProcessSecurityPolicyImpl* policy =
282 ChildProcessSecurityPolicyImpl::GetInstance();
283 if (policy->IsPseudoScheme(protocol))
284 return false;
285
286 url::Origin url_origin = url::Origin::Create(url);
287 if (url_origin.opaque())
288 return false;
289
290 if (!url_origin.IsSameOriginWith(origin))
291 return false;
292
293 return true;
294}
295
yilkal796e89e2019-10-02 23:58:28296void RecordMaxFrameCountUMA(size_t max_frame_count) {
297 UMA_HISTOGRAM_COUNTS_10000("Navigation.MainFrame.MaxFrameCount",
298 max_frame_count);
299}
300
lukasza6f8ac622017-06-06 03:10:20301} // namespace
302
Erik Chenbb8e738e2018-04-28 14:10:43303std::unique_ptr<WebContents> WebContents::Create(
304 const WebContents::CreateParams& params) {
Albert J. Wong65fe64d2019-09-20 02:48:14305 return WebContentsImpl::Create(params);
306}
307
308std::unique_ptr<WebContentsImpl> WebContentsImpl::Create(
309 const CreateParams& params) {
310 return CreateWithOpener(params, FindOpenerRFH(params));
[email protected]d1198fd2012-08-13 22:50:19311}
312
erikchenade1fef2018-05-02 22:07:57313std::unique_ptr<WebContents> WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59314 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30315 const SessionStorageNamespaceMap& session_storage_namespace_map) {
erikchenade1fef2018-05-02 22:07:57316 std::unique_ptr<WebContentsImpl> new_contents(
317 new WebContentsImpl(params.browser_context));
Ian Clelland5cbaaf82017-11-27 22:00:03318 RenderFrameHostImpl* opener_rfh = FindOpenerRFH(params);
319 FrameTreeNode* opener = nullptr;
320 if (opener_rfh)
321 opener = opener_rfh->frame_tree_node();
322 new_contents->SetOpenerForNewContents(opener, params.opener_suppressed);
[email protected]fdac6ade2013-07-20 01:06:30323
jdoerrie55ec69d2018-10-08 13:34:46324 for (auto it = session_storage_namespace_map.begin();
325 it != session_storage_namespace_map.end(); ++it) {
[email protected]fdac6ade2013-07-20 01:06:30326 new_contents->GetController()
327 .SetSessionStorageNamespace(it->first, it->second.get());
328 }
329
Sean Toppingbbc4a2bd2019-01-30 02:16:14330 WebContentsImpl* outer_web_contents = nullptr;
Sam McNally69a33772018-06-27 16:54:12331 if (params.guest_delegate) {
332 // This makes |new_contents| act as a guest.
333 // For more info, see comment above class BrowserPluginGuest.
Albert J. Wongc55cc64d2018-10-12 02:50:04334 BrowserPluginGuest::CreateInWebContents(new_contents.get(),
335 params.guest_delegate);
Sean Toppingbbc4a2bd2019-01-30 02:16:14336 outer_web_contents = static_cast<WebContentsImpl*>(
337 params.guest_delegate->GetOwnerWebContents());
Sam McNally69a33772018-06-27 16:54:12338 }
339
[email protected]54944cde2012-12-09 09:24:59340 new_contents->Init(params);
Sean Toppingbbc4a2bd2019-01-30 02:16:14341 if (outer_web_contents)
342 outer_web_contents->InnerWebContentsCreated(new_contents.get());
[email protected]d1198fd2012-08-13 22:50:19343 return new_contents;
[email protected]a81343d232011-12-27 07:39:20344}
[email protected]746d3052012-05-22 15:15:47345
benwells5e7260d2017-03-20 23:36:33346void WebContentsImpl::FriendWrapper::AddCreatedCallbackForTesting(
nickf9acfbe2014-12-23 19:12:37347 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46348 g_created_callbacks.Get().push_back(callback);
349}
350
benwells5e7260d2017-03-20 23:36:33351void WebContentsImpl::FriendWrapper::RemoveCreatedCallbackForTesting(
nickf9acfbe2014-12-23 19:12:37352 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46353 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
Robert Liao1db5a352019-06-05 20:57:34354 if (g_created_callbacks.Get().at(i) == callback) {
[email protected]cbb1ef592013-06-05 19:49:46355 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
356 return;
357 }
358 }
359}
360
avidf38c952015-10-27 13:45:13361WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
362 if (!rvh)
363 return nullptr;
[email protected]746d3052012-05-22 15:15:47364 return rvh->GetDelegate()->GetAsWebContents();
365}
366
[email protected]a86c0e962013-12-17 17:10:39367WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13368 if (!rfh)
369 return nullptr;
370 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39371}
372
ananta4b7467a52016-09-23 01:42:38373WebContents* WebContents::FromFrameTreeNodeId(int frame_tree_node_id) {
374 FrameTreeNode* frame_tree_node =
375 FrameTreeNode::GloballyFindByID(frame_tree_node_id);
anantab8cfa3b2016-10-14 22:43:19376 if (!frame_tree_node)
377 return nullptr;
jam8c4edd02017-05-06 18:50:33378 return WebContentsImpl::FromFrameTreeNode(frame_tree_node);
ananta4b7467a52016-09-23 01:42:38379}
380
leon.han552e9de2017-02-09 14:37:30381void WebContents::SetScreenOrientationDelegate(
382 ScreenOrientationDelegate* delegate) {
383 ScreenOrientationProvider::SetDelegate(delegate);
384}
385
[email protected]7fff43e2013-05-21 20:21:10386// WebContentsImpl::DestructionObserver ----------------------------------------
387
388class WebContentsImpl::DestructionObserver : public WebContentsObserver {
389 public:
390 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
391 : WebContentsObserver(watched_contents),
392 owner_(owner) {
393 }
394
395 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58396 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58397 owner_->OnWebContentsDestroyed(
398 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10399 }
400
401 private:
402 WebContentsImpl* owner_;
403
404 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
405};
406
Joel Hockey85b379d2017-12-11 10:42:13407// WebContentsImpl::ColorChooser ----------------------------------------------
Joel Hockey163835a2017-12-20 11:51:57408class WebContentsImpl::ColorChooser : public blink::mojom::ColorChooser {
Joel Hockey85b379d2017-12-11 10:42:13409 public:
410 ColorChooser(content::ColorChooser* chooser,
Julie Jeongeun Kim8e2879e2019-08-06 23:55:20411 mojo::PendingReceiver<blink::mojom::ColorChooser> receiver,
412 mojo::PendingRemote<blink::mojom::ColorChooserClient> client)
Joel Hockey85b379d2017-12-11 10:42:13413 : chooser_(chooser),
Julie Jeongeun Kim8e2879e2019-08-06 23:55:20414 receiver_(this, std::move(receiver)),
Joel Hockey85b379d2017-12-11 10:42:13415 client_(std::move(client)) {
Julie Jeongeun Kim8e2879e2019-08-06 23:55:20416 receiver_.set_disconnect_handler(
Joel Hockey85b379d2017-12-11 10:42:13417 base::BindOnce([](content::ColorChooser* chooser) { chooser->End(); },
418 base::Unretained(chooser)));
419 }
[email protected]8ed16472014-04-11 19:02:48420
Joel Hockey85b379d2017-12-11 10:42:13421 ~ColorChooser() override { chooser_->End(); }
[email protected]8ed16472014-04-11 19:02:48422
Joel Hockey85b379d2017-12-11 10:42:13423 void SetSelectedColor(SkColor color) override {
424 chooser_->SetSelectedColor(color);
425 }
426
427 void DidChooseColorInColorChooser(SkColor color) {
428 client_->DidChooseColor(color);
429 }
430
431 private:
432 // Color chooser that was opened by this tab.
433 std::unique_ptr<content::ColorChooser> chooser_;
434
Julie Jeongeun Kim8e2879e2019-08-06 23:55:20435 // mojo receiver.
436 mojo::Receiver<blink::mojom::ColorChooser> receiver_;
Joel Hockey85b379d2017-12-11 10:42:13437
438 // mojo renderer client.
Julie Jeongeun Kim8e2879e2019-08-06 23:55:20439 mojo::Remote<blink::mojom::ColorChooserClient> client_;
Joel Hockey85b379d2017-12-11 10:42:13440};
nicka0ac8382016-12-15 23:59:23441
lazyboy6ec48b2a2015-06-29 15:18:14442// WebContentsImpl::WebContentsTreeNode ----------------------------------------
lfg601233692017-03-06 22:45:44443WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode(
444 WebContentsImpl* current_web_contents)
445 : current_web_contents_(current_web_contents),
446 outer_web_contents_(nullptr),
lazyboy6ec48b2a2015-06-29 15:18:14447 outer_contents_frame_tree_node_id_(
avallee0206f782016-07-28 18:55:33448 FrameTreeNode::kFrameTreeNodeInvalidId),
lfg601233692017-03-06 22:45:44449 focused_web_contents_(current_web_contents) {}
lazyboy6ec48b2a2015-06-29 15:18:14450
Lucas Furukawa Gadani3d38ec152018-10-26 20:55:18451WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {}
lazyboy6ec48b2a2015-06-29 15:18:14452
Lucas Furukawa Gadani99125822019-01-03 15:41:49453std::unique_ptr<WebContents>
454WebContentsImpl::WebContentsTreeNode::DisconnectFromOuterWebContents() {
455 std::unique_ptr<WebContents> inner_contents =
456 outer_web_contents_->node_.DetachInnerWebContents(current_web_contents_);
457 OuterContentsFrameTreeNode()->RemoveObserver(this);
458 outer_contents_frame_tree_node_id_ = FrameTreeNode::kFrameTreeNodeInvalidId;
459 outer_web_contents_ = nullptr;
460 return inner_contents;
461}
462
paulmeyerfeafc2d2017-04-25 21:46:40463void WebContentsImpl::WebContentsTreeNode::AttachInnerWebContents(
Lucas Furukawa Gadani6e5b4f32019-03-02 04:18:50464 std::unique_ptr<WebContents> inner_web_contents,
465 RenderFrameHostImpl* render_frame_host) {
466 WebContentsImpl* inner_web_contents_impl =
467 static_cast<WebContentsImpl*>(inner_web_contents.get());
468 WebContentsTreeNode& inner_web_contents_node = inner_web_contents_impl->node_;
469
470 inner_web_contents_node.focused_web_contents_ = nullptr;
471 inner_web_contents_node.outer_web_contents_ = current_web_contents_;
472 inner_web_contents_node.outer_contents_frame_tree_node_id_ =
473 render_frame_host->frame_tree_node()->frame_tree_node_id();
474
Lucas Furukawa Gadani3d38ec152018-10-26 20:55:18475 inner_web_contents_.push_back(std::move(inner_web_contents));
Lucas Furukawa Gadani6e5b4f32019-03-02 04:18:50476
477 render_frame_host->frame_tree_node()->AddObserver(&inner_web_contents_node);
paulmeyerfeafc2d2017-04-25 21:46:40478}
479
Lucas Furukawa Gadani3d38ec152018-10-26 20:55:18480std::unique_ptr<WebContents>
481WebContentsImpl::WebContentsTreeNode::DetachInnerWebContents(
paulmeyerfeafc2d2017-04-25 21:46:40482 WebContentsImpl* inner_web_contents) {
Lucas Furukawa Gadani3d38ec152018-10-26 20:55:18483 std::unique_ptr<WebContents> detached_contents;
484 for (std::unique_ptr<WebContents>& web_contents : inner_web_contents_) {
485 if (web_contents.get() == inner_web_contents) {
486 detached_contents = std::move(web_contents);
487 std::swap(web_contents, inner_web_contents_.back());
488 inner_web_contents_.pop_back();
489 return detached_contents;
490 }
491 }
492
493 NOTREACHED();
494 return nullptr;
paulmeyerfeafc2d2017-04-25 21:46:40495}
496
lfga3e2bdc2017-03-07 20:44:01497FrameTreeNode*
498WebContentsImpl::WebContentsTreeNode::OuterContentsFrameTreeNode() const {
499 return FrameTreeNode::GloballyFindByID(outer_contents_frame_tree_node_id_);
lfg601233692017-03-06 22:45:44500}
501
lfga3e2bdc2017-03-07 20:44:01502void WebContentsImpl::WebContentsTreeNode::OnFrameTreeNodeDestroyed(
503 FrameTreeNode* node) {
504 DCHECK_EQ(outer_contents_frame_tree_node_id_, node->frame_tree_node_id())
505 << "WebContentsTreeNode should only receive notifications for the "
506 "FrameTreeNode in its outer WebContents that hosts it.";
Lucas Furukawa Gadani3d38ec152018-10-26 20:55:18507
508 // Deletes |this| too.
509 outer_web_contents_->node_.DetachInnerWebContents(current_web_contents_);
lazyboy6ec48b2a2015-06-29 15:18:14510}
511
avallee0206f782016-07-28 18:55:33512void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents(
513 WebContentsImpl* web_contents) {
514 DCHECK(!outer_web_contents())
515 << "Only the outermost WebContents tracks focus.";
516 focused_web_contents_ = web_contents;
517}
518
paulmeyerfeafc2d2017-04-25 21:46:40519WebContentsImpl*
520WebContentsImpl::WebContentsTreeNode::GetInnerWebContentsInFrame(
521 const FrameTreeNode* frame) {
522 auto ftn_id = frame->frame_tree_node_id();
Lucas Furukawa Gadani3d38ec152018-10-26 20:55:18523 for (auto& contents : inner_web_contents_) {
524 WebContentsImpl* impl = static_cast<WebContentsImpl*>(contents.get());
525 if (impl->node_.outer_contents_frame_tree_node_id() == ftn_id) {
526 return impl;
paulmeyerfeafc2d2017-04-25 21:46:40527 }
528 }
529 return nullptr;
530}
531
Lucas Furukawa Gadani3d38ec152018-10-26 20:55:18532std::vector<WebContentsImpl*>
533WebContentsImpl::WebContentsTreeNode::GetInnerWebContents() const {
534 std::vector<WebContentsImpl*> inner_web_contents;
535 for (auto& contents : inner_web_contents_)
536 inner_web_contents.push_back(static_cast<WebContentsImpl*>(contents.get()));
537
538 return inner_web_contents;
paulmeyerfeafc2d2017-04-25 21:46:40539}
540
[email protected]b172aee2012-04-10 17:05:26541// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32542
alexmose201c7cd2015-06-10 17:14:21543WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28544 : delegate_(nullptr),
[email protected]69e797f2013-04-30 01:10:22545 controller_(this, browser_context),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28546 render_view_host_delegate_view_(nullptr),
alexmose201c7cd2015-06-10 17:14:21547 created_with_opener_(false),
Lucas Furukawa Gadani99125822019-01-03 15:41:49548 node_(this),
[email protected]6ea6bdf2013-12-06 13:35:01549 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57550 this,
551 this,
552 this,
553 this),
[email protected]6dfed692014-05-22 04:18:03554 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23555 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
556 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34557 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26558 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56559 upload_size_(0),
560 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16561 is_resume_pending_(false),
creisadca9862017-06-16 19:12:11562 interstitial_page_(nullptr),
[email protected]b4c84012014-04-28 19:51:10563 has_accessed_initial_document_(false),
Collin Bakerc5259962019-11-14 17:51:58564 visible_capturer_count_(0),
565 hidden_capturer_count_(0),
[email protected]fdd61c62009-04-22 19:22:57566 is_being_destroyed_(false),
creis97867aa2017-02-17 18:39:45567 is_notifying_observers_(false),
[email protected]fdd61c62009-04-22 19:22:57568 notify_disconnection_(false),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28569 dialog_manager_(nullptr),
[email protected]7ab1e7d62009-10-14 23:32:01570 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39571 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38572 closed_by_user_gesture_(false),
danakj938b37a62019-09-24 18:35:54573 minimum_zoom_percent_(
574 static_cast<int>(blink::kMinimumPageZoomFactor * 100)),
575 maximum_zoom_percent_(
576 static_cast<int>(blink::kMaximumPageZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22577 zoom_scroll_remainder_(0),
alexmosc9e76ec2016-05-16 22:59:37578 fullscreen_widget_process_id_(ChildProcessHost::kInvalidUniqueID),
[email protected]5dcaf8e2013-12-28 01:31:42579 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03580 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]34ff1cfc2014-08-20 06:16:05581 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30582 last_dialog_suppressed_(false),
waffles1c12bf402016-02-10 17:45:48583 accessibility_mode_(
Dominic Mazzoni21fb0282019-02-13 18:32:47584 GetContentClient()->browser()->GetAXModeForBrowserContext(
585 browser_context)),
avayvodcc85bbd2015-08-28 19:11:15586 audio_stream_monitor_(this),
Thomas Guilbert882c4cec2019-02-14 05:55:45587 media_web_contents_observer_(
588 std::make_unique<MediaWebContentsObserver>(this)),
mcnee336ea2c2017-05-23 22:50:59589#if !defined(OS_ANDROID)
mcnee432e47d2015-11-09 19:37:46590 page_scale_factor_is_one_(true),
mcnee336ea2c2017-05-23 22:50:59591#endif // !defined(OS_ANDROID)
qinmin72e8bd02016-10-21 19:35:37592 is_overlay_content_(false),
ekaramadf6750aa2017-06-06 18:29:42593 showing_context_menu_(false),
W. James MacLean62198672019-06-04 16:46:10594 text_autosizer_page_info_({0, 0, 1.f}),
Jeremy Roman3bca4bf2019-07-11 03:41:25595 had_inner_webcontents_(false) {
danakjf4b9e942019-11-29 15:43:04596 frame_tree_.SetFrameRemoveListener(base::BindRepeating(
597 &WebContentsImpl::OnFrameRemoved, base::Unretained(this)));
brettw4b461082016-11-19 18:55:16598#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17599 pepper_playback_observer_.reset(new PepperPlaybackObserver(this));
600#endif
blundelle75a8f92017-03-27 08:11:17601
Becca Hughes86334622018-07-09 21:29:38602#if defined(OS_ANDROID)
Elly Fong-Jonescdd7ae82019-02-20 23:26:33603 display_cutout_host_impl_ = std::make_unique<DisplayCutoutHostImpl>(this);
Becca Hughes86334622018-07-09 21:29:38604#endif
John Delaney732721e92020-02-07 23:11:27605
606 // ConversionHost takes a weak ref on |this|, so it must be created outside of
607 // the initializer list.
608 conversion_host_ = std::make_unique<ConversionHost>(this);
[email protected]332af7732009-03-11 13:21:35609}
initial.commit09911bf2008-07-26 23:55:29610
[email protected]b172aee2012-04-10 17:05:26611WebContentsImpl::~WebContentsImpl() {
creisba91ba82017-05-12 22:56:19612 // Imperfect sanity check against double free, given some crashes unexpectedly
613 // observed in the wild.
614 CHECK(!is_being_destroyed_);
615
616 // We generally keep track of is_being_destroyed_ to let other features know
617 // to avoid certain actions during destruction.
[email protected]420ae012009-04-24 05:16:32618 is_being_destroyed_ = true;
619
creis97867aa2017-02-17 18:39:45620 // A WebContents should never be deleted while it is notifying observers,
creisba91ba82017-05-12 22:56:19621 // since this will lead to a use-after-free as it continues to notify later
creis97867aa2017-02-17 18:39:45622 // observers.
623 CHECK(!is_notifying_observers_);
624
kenrb2a565f82015-09-02 20:24:59625 rwh_input_event_router_.reset();
626
Julie Jeongeun Kim7d0986172019-12-04 03:17:25627 for (auto& entry : receiver_sets_)
628 entry.second->CloseAllReceivers();
rockotf62002a2016-09-15 00:08:59629
avallee0206f782016-07-28 18:55:33630 WebContentsImpl* outermost = GetOutermostWebContents();
avallee9993fca2016-11-17 06:16:50631 if (this != outermost && ContainsOrIsFocusedWebContents()) {
avallee0206f782016-07-28 18:55:33632 // If the current WebContents is in focus, unset it.
avallee9993fca2016-11-17 06:16:50633 outermost->SetAsFocusedWebContentsIfNecessary();
avallee0206f782016-07-28 18:55:33634 }
635
Nick Carterd73635b2018-03-13 18:31:41636 if (mouse_lock_widget_)
637 mouse_lock_widget_->RejectMouseLockOrUnlockIfNecessary();
638
dcheng72be33c2016-01-21 04:11:31639 for (FrameTreeNode* node : frame_tree_.Nodes()) {
640 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs
641 // to be shutdown and be deleted as well.
dcheng57e39e22016-01-21 00:25:38642 node->render_manager()->ClearRFHsPendingShutdown();
dcheng57e39e22016-01-21 00:25:38643 node->render_manager()->ClearWebUIInstances();
dcheng72be33c2016-01-21 04:11:31644 }
carlosk35f35af2015-12-01 10:55:40645
dcheng57e39e22016-01-21 00:25:38646 for (RenderWidgetHostImpl* widget : created_widgets_)
647 widget->DetachDelegate();
[email protected]b24b68a2012-09-24 21:57:26648 created_widgets_.clear();
649
[email protected]3ab9cb82011-06-03 18:02:07650 // Clear out any JavaScript state.
avi5d3b8692016-10-12 22:00:46651 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:53652 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:46653 }
[email protected]3ab9cb82011-06-03 18:02:07654
Joel Hockey85b379d2017-12-11 10:42:13655 color_chooser_.reset();
Rakina Zata Amni16196122018-11-14 02:14:00656 find_request_manager_.reset();
[email protected]da8543762012-03-20 08:52:20657
[email protected]420ae012009-04-24 05:16:32658 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32659
[email protected]ca13a442012-04-17 14:00:12660 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21661 NotificationService::current()->Notify(
662 NOTIFICATION_WEB_CONTENTS_DESTROYED,
663 Source<WebContents>(this),
664 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32665
Arthur Sonzogni5a9a88c2018-10-18 13:16:00666 // Destroy all subframes now. This notifies observers.
667 GetMainFrame()->ResetChildren();
[email protected]df0c843f2014-05-23 20:37:23668 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59669
clamy0e119882015-07-31 16:12:33670 // Manually call the observer methods for the root frame tree node. It is
671 // necessary to manually delete all objects tracking navigations
672 // (NavigationHandle, NavigationRequest) for observers to be properly
673 // notified of these navigations stopping before the WebContents is
674 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23675 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56676
Lowell Manners20250112019-10-18 15:06:15677 GetController().GetBackForwardCache().Shutdown();
678
naskob21fe4872015-02-24 14:15:56679 root->current_frame_host()->SetRenderFrameCreated(false);
clamyfc3850d2018-02-23 14:35:28680 root->current_frame_host()->ResetNavigationRequests();
clamy0e119882015-07-31 16:12:33681
Arthur Hemeryc3380172018-01-22 14:00:17682 // Do not update state as the WebContents is being destroyed.
Arthur Hemery241b9392019-10-24 11:08:41683 frame_tree_.root()->ResetNavigationRequest(true);
Arthur Hemeryc3380172018-01-22 14:00:17684 if (root->speculative_frame_host()) {
danakjf2342432019-05-15 21:46:09685 root->speculative_frame_host()->DeleteRenderFrame(
686 FrameDeleteIntention::kSpeculativeMainFrameForShutdown);
Arthur Hemeryc3380172018-01-22 14:00:17687 root->speculative_frame_host()->SetRenderFrameCreated(false);
clamyfc3850d2018-02-23 14:35:28688 root->speculative_frame_host()->ResetNavigationRequests();
clamy0e119882015-07-31 16:12:33689 }
[email protected]f273ee52013-10-18 16:05:27690
brettw4b461082016-11-19 18:55:16691#if BUILDFLAG(ENABLE_PLUGINS)
zqzhang181047e62016-07-01 13:37:17692 // Call this before WebContentsDestroyed() is broadcasted since
693 // AudioFocusManager will be destroyed after that.
694 pepper_playback_observer_.reset();
695#endif // defined(ENABLED_PLUGINS)
696
Chris Hamiltondf0d72cd2018-05-29 16:23:53697 // If audio is playing then notify external observers of the audio stream
698 // disappearing.
699 if (is_currently_audible_) {
700 is_currently_audible_ = false;
701 for (auto& observer : observers_)
702 observer.OnAudioStateChanged(false);
703
704 if (GetOuterWebContents())
705 GetOuterWebContents()->OnAudioStateChanged();
706 }
707
ericwilligersde386342016-10-19 02:35:09708 for (auto& observer : observers_)
709 observer.FrameDeleted(root->current_frame_host());
naskoa83483fb2015-02-27 16:57:10710
ericwilligersde386342016-10-19 02:35:09711 for (auto& observer : observers_)
712 observer.RenderViewDeleted(root->current_host());
[email protected]f273ee52013-10-18 16:05:27713
Kevin McNee576bb5d82019-05-29 16:47:51714#if defined(OS_ANDROID)
715 // For simplicity, destroy the Java WebContents before we notify of the
716 // destruction of the WebContents.
717 ClearWebContentsAndroid();
718#endif
719
ericwilligersde386342016-10-19 02:35:09720 for (auto& observer : observers_)
721 observer.WebContentsDestroyed();
[email protected]12a46832014-05-09 13:35:58722
Becca Hughesd11d6502018-07-31 17:01:28723 if (display_cutout_host_impl_)
724 display_cutout_host_impl_->WebContentsDestroyed();
725
ericwilligersde386342016-10-19 02:35:09726 for (auto& observer : observers_)
727 observer.ResetWebContents();
[email protected]232a5812011-03-04 22:42:08728
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28729 SetDelegate(nullptr);
[email protected]b5a1d11c2011-02-17 03:09:42730}
731
erikchen50735fd2018-05-05 15:08:33732std::unique_ptr<WebContentsImpl> WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59733 const WebContents::CreateParams& params,
Ian Clelland5cbaaf82017-11-27 22:00:03734 RenderFrameHostImpl* opener_rfh) {
[email protected]e11f0e92013-06-12 15:12:03735 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
Ian Clelland5cbaaf82017-11-27 22:00:03736 FrameTreeNode* opener = nullptr;
737 if (opener_rfh)
738 opener = opener_rfh->frame_tree_node();
erikchen50735fd2018-05-05 15:08:33739 std::unique_ptr<WebContentsImpl> new_contents(
740 new WebContentsImpl(params.browser_context));
lukasza6f8ac622017-06-06 03:10:20741 new_contents->SetOpenerForNewContents(opener, params.opener_suppressed);
alexmose201c7cd2015-06-10 17:14:21742
alexmosaedfc6f2016-01-21 23:57:38743 // If the opener is sandboxed, a new popup must inherit the opener's sandbox
744 // flags, and these flags take effect immediately. An exception is if the
745 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts
746 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token).
747 // See https://html.spec.whatwg.org/#attr-iframe-sandbox.
lukasza6f8ac622017-06-06 03:10:20748 FrameTreeNode* new_root = new_contents->GetFrameTree()->root();
alexmosaedfc6f2016-01-21 23:57:38749 if (opener) {
Antonio Gomes7096ac02020-02-14 14:29:54750 blink::mojom::WebSandboxFlags opener_flags =
751 opener_rfh->active_sandbox_flags();
752 const blink::mojom::WebSandboxFlags inherit_flag =
753 blink::mojom::WebSandboxFlags::kPropagatesToAuxiliaryBrowsingContexts;
Ehsan Karamad39407082019-02-19 23:38:19754 bool sandbox_propagates_to_auxilary_context =
755 (opener_flags & inherit_flag) == inherit_flag;
756 if (sandbox_propagates_to_auxilary_context)
Charlie Hue1b77ac2019-12-13 21:30:17757 new_root->SetPendingFramePolicy({opener_flags,
758 {} /* container_policy */,
759 {} /* required_document_policy */});
Antonio Gomes7096ac02020-02-14 14:29:54760 if (opener_flags == blink::mojom::WebSandboxFlags::kNone ||
Ehsan Karamad39407082019-02-19 23:38:19761 sandbox_propagates_to_auxilary_context) {
762 // TODO(ekaramad, iclelland): Do not propagate feature policies from non-
763 // sandboxed disowned openers (rel=noopener).
764 // If the current page is not sandboxed, or if the sandbox is to propagate
765 // to the popups then opener's feature policy will apply to the new popup
766 // as well.
767 new_root->SetOpenerFeaturePolicyState(
Ehsan Karamad34d10682019-02-26 20:55:04768 opener_rfh->feature_policy()->GetFeatureState());
alexmosaedfc6f2016-01-21 23:57:38769 }
770 }
771
mark a. foltzef394fce2017-10-21 09:11:02772 // Apply starting sandbox flags.
Luna Luc3fdacdf2017-11-08 04:48:53773 blink::FramePolicy frame_policy(new_root->pending_frame_policy());
mark a. foltzef394fce2017-10-21 09:11:02774 frame_policy.sandbox_flags |= params.starting_sandbox_flags;
775 new_root->SetPendingFramePolicy(frame_policy);
Charlie Hu5ffc0152019-12-06 15:59:53776 new_root->CommitFramePolicy(frame_policy);
mark a. foltzef394fce2017-10-21 09:11:02777
alexmose201c7cd2015-06-10 17:14:21778 // This may be true even when opener is null, such as when opening blocked
779 // popups.
alexmos090fae8e2015-05-28 17:09:28780 if (params.created_with_opener)
781 new_contents->created_with_opener_ = true;
782
Sean Toppingbbc4a2bd2019-01-30 02:16:14783 WebContentsImpl* outer_web_contents = nullptr;
[email protected]4858e432014-06-23 18:14:17784 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06785 // This makes |new_contents| act as a guest.
786 // For more info, see comment above class BrowserPluginGuest.
Albert J. Wongc55cc64d2018-10-12 02:50:04787 BrowserPluginGuest::CreateInWebContents(new_contents.get(),
788 params.guest_delegate);
Sean Toppingbbc4a2bd2019-01-30 02:16:14789 outer_web_contents = static_cast<WebContentsImpl*>(
790 params.guest_delegate->GetOwnerWebContents());
[email protected]83100cd2014-05-10 11:50:06791 }
mark a. foltzef394fce2017-10-21 09:11:02792
[email protected]54944cde2012-12-09 09:24:59793 new_contents->Init(params);
Sean Toppingbbc4a2bd2019-01-30 02:16:14794 if (outer_web_contents)
795 outer_web_contents->InnerWebContentsCreated(new_contents.get());
[email protected]d1198fd2012-08-13 22:50:19796 return new_contents;
797}
798
[email protected]95640212014-07-26 18:14:30799// static
800std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
801 std::vector<WebContentsImpl*> result;
dcheng59716272016-04-09 05:19:08802 std::unique_ptr<RenderWidgetHostIterator> widgets(
[email protected]95640212014-07-26 18:14:30803 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30804 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30805 RenderViewHost* rvh = RenderViewHost::From(rwh);
806 if (!rvh)
807 continue;
808 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
809 if (!web_contents)
810 continue;
avidf38c952015-10-27 13:45:13811 if (web_contents->GetRenderViewHost() != rvh)
812 continue;
813 // Because a WebContents can only have one current RVH at a time, there will
814 // be no duplicate WebContents here.
815 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30816 }
817 return result;
818}
819
clamya16aa8172015-05-26 13:07:25820// static
821WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
paulmeyerfeafc2d2017-04-25 21:46:40822 const FrameTreeNode* frame_tree_node) {
clamya16aa8172015-05-26 13:07:25823 return static_cast<WebContentsImpl*>(
824 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
825}
826
clamy0d32d6d2015-11-24 11:16:26827// static
Patrick Monette275a6f92b2020-01-09 21:05:04828WebContents* WebContentsImpl::FromRenderFrameHostID(
829 GlobalFrameRoutingId render_frame_host_id) {
830 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
831 !BrowserThread::IsThreadInitialized(BrowserThread::UI));
Patrick Monette7364e6972020-01-09 22:56:02832 RenderFrameHost* render_frame_host =
833 RenderFrameHost::FromID(render_frame_host_id);
834 if (!render_frame_host)
835 return nullptr;
836
837 return WebContents::FromRenderFrameHost(render_frame_host);
Patrick Monette275a6f92b2020-01-09 21:05:04838}
839
840// static
clamy0d32d6d2015-11-24 11:16:26841WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
842 int render_frame_host_id) {
Patrick Monette7364e6972020-01-09 22:56:02843 return FromRenderFrameHostID(
844 GlobalFrameRoutingId(render_process_host_id, render_frame_host_id));
clamy0d32d6d2015-11-24 11:16:26845}
846
paulmeyerfeafc2d2017-04-25 21:46:40847// static
848WebContentsImpl* WebContentsImpl::FromOuterFrameTreeNode(
849 const FrameTreeNode* frame_tree_node) {
850 return WebContentsImpl::FromFrameTreeNode(frame_tree_node)
851 ->node_.GetInnerWebContentsInFrame(frame_tree_node);
852}
853
[email protected]b0936d22013-11-28 06:47:36854RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21855 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28856}
857
nicka0ac8382016-12-15 23:59:23858bool WebContentsImpl::OnMessageReceived(RenderViewHostImpl* render_view_host,
[email protected]7bb761892012-07-20 09:32:47859 const IPC::Message& message) {
nicka0ac8382016-12-15 23:59:23860 for (auto& observer : observers_) {
Lukasz Anforowicz89f2c1b2017-08-30 21:36:46861 // TODO(nick, creis): https://crbug.com/758026: Replace all uses of this
862 // variant of OnMessageReceived with the version that takes a
863 // RenderFrameHost, and then delete it.
nicka0ac8382016-12-15 23:59:23864 if (observer.OnMessageReceived(message))
865 return true;
[email protected]64ffefa2014-05-10 12:06:33866 }
[email protected]403415a2011-01-10 18:57:53867
[email protected]724159a2010-12-30 01:11:18868 bool handled = true;
nicka0ac8382016-12-15 23:59:23869 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_view_host)
nicka0ac8382016-12-15 23:59:23870 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
871 OnPageScaleFactorChanged)
W. James MacLean62198672019-06-04 16:46:10872 IPC_MESSAGE_HANDLER(
873 ViewHostMsg_NotifyTextAutosizerPageInfoChangedInLocalMainFrame,
874 OnTextAutosizerPageInfoChanged)
nicka0ac8382016-12-15 23:59:23875#if BUILDFLAG(ENABLE_PLUGINS)
876 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
877 OnRequestPpapiBrokerPermission)
878#endif
nicka0ac8382016-12-15 23:59:23879 IPC_MESSAGE_UNHANDLED(handled = false)
880 IPC_END_MESSAGE_MAP()
881
882 return handled;
883}
884
885bool WebContentsImpl::OnMessageReceived(RenderFrameHostImpl* render_frame_host,
886 const IPC::Message& message) {
Lukasz Anforowicz02923102017-10-09 18:11:37887 {
888 WebUIImpl* web_ui = render_frame_host->web_ui();
889 if (web_ui && web_ui->OnMessageReceived(message, render_frame_host))
890 return true;
891 }
892
nicka0ac8382016-12-15 23:59:23893 for (auto& observer : observers_) {
894 if (observer.OnMessageReceived(message, render_frame_host))
895 return true;
896 }
897
898 bool handled = true;
899 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_frame_host)
[email protected]cfa856d62014-02-22 07:58:40900 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
901 OnDomOperationResponse)
[email protected]8ed16472014-04-11 19:02:48902 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
avi7830c852015-08-31 23:46:25903 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18904 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54905 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18906 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41907 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
908 OnDidDisplayContentWithCertificateErrors)
909 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
910 OnDidRunContentWithCertificateErrors)
lukasza178ff092017-06-07 23:39:50911 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
brettw4b461082016-11-19 18:55:16912#if BUILDFLAG(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00913 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
914 OnPepperInstanceCreated)
915 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
916 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42917 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
zqzhang181047e62016-07-01 13:37:17918 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback,
919 OnPepperStartsPlayback)
920 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback,
921 OnPepperStopsPlayback)
tommyclie6633ca72014-10-31 00:40:42922 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
thestigc4cac8f2014-09-04 21:17:50923#endif
[email protected]724159a2010-12-30 01:11:18924 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33925 IPC_END_MESSAGE_MAP()
[email protected]724159a2010-12-30 01:11:18926
[email protected]724159a2010-12-30 01:11:18927 return handled;
928}
929
[email protected]d1198fd2012-08-13 22:50:19930NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56931 return controller_;
932}
933
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41934BrowserContext* WebContentsImpl::GetBrowserContext() {
[email protected]a26023822011-12-29 00:23:55935 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30936}
937
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41938const GURL& WebContentsImpl::GetURL() {
Peter Boström101d7672018-12-15 00:43:59939 return GetVisibleURL();
[email protected]be1f56ab2011-12-22 06:55:31940}
941
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41942const GURL& WebContentsImpl::GetVisibleURL() {
[email protected]c854a7e2013-05-21 16:42:24943 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32944 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24945 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
946}
947
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41948const GURL& WebContentsImpl::GetLastCommittedURL() {
[email protected]c854a7e2013-05-21 16:42:24949 // We may not have a navigation entry yet.
950 NavigationEntry* entry = controller_.GetLastCommittedEntry();
951 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
952}
953
[email protected]8ff00d72012-10-23 19:12:21954WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31955 return delegate_;
956}
957
[email protected]8ff00d72012-10-23 19:12:21958void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31959 // TODO(cbentzel): remove this debugging code?
960 if (delegate == delegate_)
961 return;
962 if (delegate_)
963 delegate_->Detach(this);
964 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08965 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31966 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08967 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00968 if (view_)
[email protected]e85165c642014-06-10 14:34:31969 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
Joel Einbinder848001c2017-09-19 21:39:31970 if (GetRenderViewHost())
971 RenderFrameDevToolsAgentHost::WebContentsCreated(this);
[email protected]a6b73c62013-02-11 23:05:08972 }
[email protected]be1f56ab2011-12-22 06:55:31973}
974
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:41975RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41976 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16977}
978
nick53d5cbf2015-04-23 22:50:14979RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
980 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
981 if (!focused_node)
982 return nullptr;
983 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07984}
985
rob3e2a0732016-01-06 21:22:09986RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
creisf71a2632017-05-04 19:03:50987 int frame_tree_node_id,
988 int process_id) {
989 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
990
991 // Sanity check that this is in the caller's expected process. Otherwise a
992 // recent cross-process navigation may have led to a privilege change that the
993 // caller is not expecting.
994 if (!frame ||
995 frame->current_frame_host()->GetProcess()->GetID() != process_id)
996 return nullptr;
997
998 return frame->current_frame_host();
999}
1000
1001RenderFrameHostImpl* WebContentsImpl::UnsafeFindFrameByFrameTreeNodeId(
rob3e2a0732016-01-06 21:22:091002 int frame_tree_node_id) {
creisf71a2632017-05-04 19:03:501003 // Beware using this! The RenderFrameHost may have changed since the caller
1004 // obtained frame_tree_node_id.
rob3e2a0732016-01-06 21:22:091005 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
1006 return frame ? frame->current_frame_host() : nullptr;
1007}
1008
[email protected]a86c0e962013-12-17 17:10:391009void WebContentsImpl::ForEachFrame(
Lei Zhangebcc6302018-01-12 19:46:451010 const base::RepeatingCallback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:381011 for (FrameTreeNode* node : frame_tree_.Nodes()) {
1012 on_frame.Run(node->current_frame_host());
1013 }
[email protected]a86c0e962013-12-17 17:10:391014}
1015
dchengafb53e22016-02-04 08:11:081016std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
1017 std::vector<RenderFrameHost*> frame_hosts;
1018 for (FrameTreeNode* node : frame_tree_.Nodes())
1019 frame_hosts.push_back(node->current_frame_host());
1020 return frame_hosts;
1021}
1022
lukaszacbdf52e2016-01-15 21:19:511023int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
1024 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:081025 for (RenderFrameHost* rfh : GetAllFrames()) {
lukasza1a9ab2422016-03-02 18:47:251026 if (!rfh->IsRenderFrameLive())
1027 continue;
1028
dchengafb53e22016-02-04 08:11:081029 ++number_of_messages;
1030 IPC::Message* message_copy = new IPC::Message(*message);
1031 message_copy->set_routing_id(rfh->GetRoutingID());
1032 rfh->Send(message_copy);
1033 }
[email protected]a86c0e962013-12-17 17:10:391034 delete message;
lukaszacbdf52e2016-01-15 21:19:511035 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:391036}
1037
lfgdb5c4ed2016-03-04 23:09:071038void WebContentsImpl::SendPageMessage(IPC::Message* msg) {
alexmos136fd6e62016-08-15 20:58:411039 frame_tree_.root()->render_manager()->SendPageMessage(msg, nullptr);
lfgdb5c4ed2016-03-04 23:09:071040}
1041
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411042RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() {
[email protected]fa944cb82013-11-15 17:51:211043 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:311044}
1045
creis89a0f782015-05-27 16:13:171046void WebContentsImpl::CancelActiveAndPendingDialogs() {
avi5d3b8692016-10-12 22:00:461047 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:531048 dialog_manager_->CancelDialogs(this, /*reset_state=*/false);
avi5d3b8692016-10-12 22:00:461049 }
creis89a0f782015-05-27 16:13:171050 if (browser_plugin_embedder_)
1051 browser_plugin_embedder_->CancelGuestDialogs();
1052}
1053
naskoc0fceff2015-04-30 15:53:521054void WebContentsImpl::ClosePage() {
1055 GetRenderViewHost()->ClosePage();
1056}
1057
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411058RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() {
[email protected]fa944cb82013-11-15 17:51:211059 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:311060}
1061
lfg265a2672016-04-23 03:11:021062RenderWidgetHostView* WebContentsImpl::GetTopLevelRenderWidgetHostView() {
1063 if (GetOuterWebContents())
1064 return GetOuterWebContents()->GetTopLevelRenderWidgetHostView();
1065 return GetRenderManager()->GetRenderWidgetHostView();
1066}
1067
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411068RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView() {
vmpstr6d9996c82017-02-23 00:43:251069 if (auto* widget_host = GetFullscreenRenderWidgetHost())
ekaramadaeb3c5c2016-11-09 03:22:351070 return widget_host->GetView();
1071 return nullptr;
[email protected]4aebbca2013-09-17 22:26:491072}
1073
[email protected]8ff00d72012-10-23 19:12:211074WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:311075 return view_.get();
1076}
1077
leon.han552e9de2017-02-09 14:37:301078void WebContentsImpl::OnScreenOrientationChange() {
1079 DCHECK(screen_orientation_provider_);
Lan Weif81c6e7c2020-02-12 16:46:091080 DidChangeScreenOrientation();
Becca Hughese9e27952018-06-25 17:08:271081 screen_orientation_provider_->OnOrientationChange();
leon.hane4db177a2017-02-07 14:19:161082}
1083
Alan Cutter92d59252019-03-29 02:32:331084base::Optional<SkColor> WebContentsImpl::GetThemeColor() {
Carlos Caballero1215f882019-10-29 15:58:431085 return GetRenderViewHost()->theme_color();
yusufod41c5f92015-03-06 00:14:281086}
1087
Doug Turner63f3c7b2017-07-29 05:10:011088void WebContentsImpl::SetAccessibilityMode(ui::AXMode mode) {
[email protected]95640212014-07-26 18:14:301089 if (mode == accessibility_mode_)
1090 return;
1091
dmazzonif8a31042016-12-03 00:52:131092 // Don't allow accessibility to be enabled for WebContents that are never
danakj77eb7e82020-01-09 19:38:461093 // user-visible, like background pages.
1094 if (IsNeverComposited())
dmazzonif8a31042016-12-03 00:52:131095 return;
1096
[email protected]95640212014-07-26 18:14:301097 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:381098
1099 for (FrameTreeNode* node : frame_tree_.Nodes()) {
dmazzonif8a31042016-12-03 00:52:131100 UpdateAccessibilityModeOnFrame(node->current_frame_host());
clamy610c63b32017-12-22 15:05:181101 // Also update accessibility mode on the speculative RenderFrameHost for
1102 // this FrameTreeNode, if one exists.
Alex Moshchuk3d8a1f392017-10-24 19:01:261103 RenderFrameHost* speculative_frame_host =
1104 node->render_manager()->speculative_frame_host();
1105 if (speculative_frame_host)
1106 UpdateAccessibilityModeOnFrame(speculative_frame_host);
dcheng57e39e22016-01-21 00:25:381107 }
[email protected]95640212014-07-26 18:14:301108}
1109
Doug Turner63f3c7b2017-07-29 05:10:011110void WebContentsImpl::AddAccessibilityMode(ui::AXMode mode) {
1111 ui::AXMode new_mode(accessibility_mode_);
dougtcd3dad732017-03-14 03:26:231112 new_mode |= mode;
1113 SetAccessibilityMode(new_mode);
[email protected]95640212014-07-26 18:14:301114}
1115
Avi Drissman1e620f32018-03-16 13:57:291116// Helper class used by WebContentsImpl::RequestAXTreeSnapshot.
1117// Handles the callbacks from parallel snapshot requests to each frame,
1118// and feeds the results to an AXTreeCombiner, which converts them into a
1119// single combined accessibility tree.
1120class WebContentsImpl::AXTreeSnapshotCombiner
1121 : public base::RefCounted<AXTreeSnapshotCombiner> {
1122 public:
1123 explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback)
1124 : callback_(std::move(callback)) {}
1125
1126 AXTreeSnapshotCallback AddFrame(bool is_root) {
1127 // Adds a reference to |this|.
1128 return base::BindOnce(&AXTreeSnapshotCombiner::ReceiveSnapshot, this,
1129 is_root);
1130 }
1131
1132 void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) {
1133 combiner_.AddTree(snapshot, is_root);
1134 }
1135
1136 private:
1137 friend class base::RefCounted<AXTreeSnapshotCombiner>;
1138
1139 // This is called automatically after the last call to ReceiveSnapshot
1140 // when there are no more references to this object.
1141 ~AXTreeSnapshotCombiner() {
1142 combiner_.Combine();
1143 std::move(callback_).Run(combiner_.combined());
1144 }
1145
1146 ui::AXTreeCombiner combiner_;
1147 AXTreeSnapshotCallback callback_;
1148};
1149
1150void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback,
1151 ui::AXMode ax_mode) {
dmazzonid95ae842016-04-12 21:17:391152 // Send a request to each of the frames in parallel. Each one will return
1153 // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine
1154 // them into a single tree and call |callback| with that result, then
1155 // delete |combiner|.
Avi Drissman1e620f32018-03-16 13:57:291156 FrameTreeNode* root_node = frame_tree_.root();
tzik58faa742018-08-01 10:54:181157 auto combiner =
1158 base::MakeRefCounted<AXTreeSnapshotCombiner>(std::move(callback));
Avi Drissman1e620f32018-03-16 13:57:291159
tzik58faa742018-08-01 10:54:181160 RecursiveRequestAXTreeSnapshotOnFrame(root_node, combiner.get(), ax_mode);
Avi Drissman1e620f32018-03-16 13:57:291161}
1162
1163void WebContentsImpl::RecursiveRequestAXTreeSnapshotOnFrame(
1164 FrameTreeNode* root_node,
1165 AXTreeSnapshotCombiner* combiner,
1166 ui::AXMode ax_mode) {
dmazzonid95ae842016-04-12 21:17:391167 for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) {
Avi Drissman1e620f32018-03-16 13:57:291168 WebContentsImpl* inner_contents =
1169 node_.GetInnerWebContentsInFrame(frame_tree_node);
1170 if (inner_contents) {
1171 inner_contents->RecursiveRequestAXTreeSnapshotOnFrame(root_node, combiner,
1172 ax_mode);
1173 } else {
1174 bool is_root = frame_tree_node == root_node;
1175 frame_tree_node->current_frame_host()->RequestAXTreeSnapshot(
1176 combiner->AddFrame(is_root), ax_mode);
1177 }
dmazzonid95ae842016-04-12 21:17:391178 }
dmazzoni83ba5c82015-04-14 07:11:511179}
1180
Becca Hughes3b5a43482018-07-17 22:31:551181void WebContentsImpl::NotifyViewportFitChanged(
1182 blink::mojom::ViewportFit value) {
1183 for (auto& observer : observers_)
1184 observer.ViewportFitChanged(value);
1185}
1186
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411187FindRequestManager* WebContentsImpl::GetFindRequestManagerForTesting() {
Ehsan Karamad6beb2ea2018-11-25 18:15:131188 return GetFindRequestManager();
1189}
1190
mcnee336ea2c2017-05-23 22:50:591191#if !defined(OS_ANDROID)
akabac6bd1212018-06-25 20:10:481192void WebContentsImpl::UpdateZoom() {
1193 RenderWidgetHostImpl* rwh = GetRenderViewHost()->GetWidget();
1194 if (rwh->GetView())
1195 rwh->SynchronizeVisualProperties();
wjmaclean64951902016-04-29 20:59:121196}
1197
wjmaclean64951902016-04-29 20:59:121198
1199void WebContentsImpl::UpdateZoomIfNecessary(const std::string& scheme,
akabac6bd1212018-06-25 20:10:481200 const std::string& host) {
wjmaclean64951902016-04-29 20:59:121201 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1202 if (!entry)
1203 return;
1204
1205 GURL url = HostZoomMap::GetURLFromEntry(entry);
1206 if (host != net::GetHostOrSpecFromURL(url) ||
1207 (!scheme.empty() && !url.SchemeIs(scheme))) {
1208 return;
1209 }
1210
akabac6bd1212018-06-25 20:10:481211 UpdateZoom();
wjmaclean64951902016-04-29 20:59:121212}
mcnee336ea2c2017-05-23 22:50:591213#endif // !defined(OS_ANDROID)
wjmaclean64951902016-04-29 20:59:121214
Julie Jeongeun Kim7d0986172019-12-04 03:17:251215base::OnceClosure WebContentsImpl::AddReceiverSet(
rockotf62002a2016-09-15 00:08:591216 const std::string& interface_name,
Julie Jeongeun Kim7d0986172019-12-04 03:17:251217 WebContentsReceiverSet* receiver_set) {
rockotf62002a2016-09-15 00:08:591218 auto result =
Julie Jeongeun Kim7d0986172019-12-04 03:17:251219 receiver_sets_.insert(std::make_pair(interface_name, receiver_set));
rockotf62002a2016-09-15 00:08:591220 DCHECK(result.second);
Julie Jeongeun Kim7d0986172019-12-04 03:17:251221 return base::BindOnce(&WebContentsImpl::RemoveReceiverSet,
danakjf4b9e942019-11-29 15:43:041222 weak_factory_.GetWeakPtr(), interface_name);
rockotf62002a2016-09-15 00:08:591223}
1224
Julie Jeongeun Kim7d0986172019-12-04 03:17:251225WebContentsReceiverSet* WebContentsImpl::GetReceiverSet(
rockot8bbad222017-03-22 04:34:051226 const std::string& interface_name) {
Julie Jeongeun Kim7d0986172019-12-04 03:17:251227 auto it = receiver_sets_.find(interface_name);
1228 if (it == receiver_sets_.end())
rockot8bbad222017-03-22 04:34:051229 return nullptr;
1230 return it->second;
1231}
1232
John Delaney732721e92020-02-07 23:11:271233void WebContentsImpl::RemoveReceiverSetForTesting(
1234 const std::string& interface_name) {
1235 RemoveReceiverSet(interface_name);
1236}
1237
paulmeyerfeafc2d2017-04-25 21:46:401238std::vector<WebContentsImpl*> WebContentsImpl::GetWebContentsAndAllInner() {
1239 std::vector<WebContentsImpl*> all_contents(1, this);
1240
1241 for (size_t i = 0; i != all_contents.size(); ++i) {
1242 for (auto* inner_contents : all_contents[i]->GetInnerWebContents()) {
Lucas Furukawa Gadani2ec00c82018-12-14 15:53:161243 all_contents.push_back(static_cast<WebContentsImpl*>(inner_contents));
paulmeyerfeafc2d2017-04-25 21:46:401244 }
1245 }
1246
1247 return all_contents;
1248}
1249
Sam McNally145fb172017-05-10 00:13:231250void WebContentsImpl::NotifyManifestUrlChanged(
1251 const base::Optional<GURL>& manifest_url) {
1252 for (auto& observer : observers_)
1253 observer.DidUpdateWebManifestURL(manifest_url);
1254}
1255
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411256WebUI* WebContentsImpl::GetWebUI() {
Nasko Oskov2f7d2112019-10-29 03:26:571257 WebUI* committed_web_ui = GetCommittedWebUI();
1258 if (committed_web_ui)
1259 return committed_web_ui;
1260
1261 if (GetRenderManager()->speculative_frame_host())
1262 return GetRenderManager()->speculative_frame_host()->web_ui();
1263
1264 return nullptr;
[email protected]be1f56ab2011-12-22 06:55:311265}
1266
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411267WebUI* WebContentsImpl::GetCommittedWebUI() {
carlosk35f35af2015-12-01 10:55:401268 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:341269}
1270
Changwan Ryuc1134a82018-03-07 02:10:141271void WebContentsImpl::SetUserAgentOverride(const std::string& override,
1272 bool override_in_new_tabs) {
[email protected]bf70edce2012-06-20 22:32:221273 if (GetUserAgentOverride() == override)
1274 return;
1275
Changwan Ryuc1134a82018-03-07 02:10:141276 should_override_user_agent_in_new_tabs_ = override_in_new_tabs;
1277
[email protected]bf70edce2012-06-20 22:32:221278 renderer_preferences_.user_agent_override = override;
1279
Bruce Long1e3e1f542019-10-16 17:56:281280 // Send the new override string to all renderers in the current page.
1281 SyncRendererPrefs();
[email protected]bf70edce2012-06-20 22:32:221282
1283 // Reload the page if a load is currently in progress to avoid having
1284 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:271285 NavigationEntry* entry = controller_.GetVisibleEntry();
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281286 if (IsLoading() && entry != nullptr && entry->GetIsOverridingUserAgent())
toyoshim6142d96f2016-12-19 09:07:251287 controller_.Reload(ReloadType::BYPASSING_CACHE, true);
[email protected]8d0f3312012-08-18 01:47:531288
ericwilligersde386342016-10-19 02:35:091289 for (auto& observer : observers_)
1290 observer.UserAgentOverrideSet(override);
[email protected]86ef6a392012-05-11 22:03:111291}
1292
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411293const std::string& WebContentsImpl::GetUserAgentOverride() {
[email protected]bf70edce2012-06-20 22:32:221294 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:111295}
1296
Changwan Ryuc1134a82018-03-07 02:10:141297bool WebContentsImpl::ShouldOverrideUserAgentInNewTabs() {
1298 return should_override_user_agent_in_new_tabs_;
1299}
1300
dmazzonidd3d51a72016-12-14 18:41:011301void WebContentsImpl::EnableWebContentsOnlyAccessibilityMode() {
Dominic Mazzonid9fda172019-03-07 17:12:071302 // If accessibility is already enabled, we'll need to force a reset
1303 // in order to ensure new observers of accessibility events get the
1304 // full accessibility tree from scratch.
1305 bool need_reset = GetAccessibilityMode().has_mode(ui::AXMode::kWebContents);
1306
1307 ui::AXMode desired_mode =
1308 GetContentClient()->browser()->GetAXModeForBrowserContext(
1309 GetBrowserContext());
1310 desired_mode |= ui::kAXModeWebContentsOnly;
1311 AddAccessibilityMode(desired_mode);
1312
1313 if (need_reset) {
dchengafb53e22016-02-04 08:11:081314 for (RenderFrameHost* rfh : GetAllFrames())
1315 ResetAccessibility(rfh);
dchengafb53e22016-02-04 08:11:081316 }
[email protected]95640212014-07-26 18:14:301317}
1318
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411319bool WebContentsImpl::IsWebContentsOnlyAccessibilityModeForTesting() {
Doug Turner63f3c7b2017-07-29 05:10:011320 return accessibility_mode_ == ui::kAXModeWebContentsOnly;
[email protected]95640212014-07-26 18:14:301321}
1322
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411323bool WebContentsImpl::IsFullAccessibilityModeForTesting() {
Doug Turner63f3c7b2017-07-29 05:10:011324 return accessibility_mode_ == ui::kAXModeComplete;
[email protected]95640212014-07-26 18:14:301325}
1326
Becca Hughes6daf5662018-06-27 16:50:541327#if defined(OS_ANDROID)
1328
1329void WebContentsImpl::SetDisplayCutoutSafeArea(gfx::Insets insets) {
Becca Hughes86334622018-07-09 21:29:381330 if (display_cutout_host_impl_)
1331 display_cutout_host_impl_->SetDisplayCutoutSafeArea(insets);
Becca Hughes6daf5662018-06-27 16:50:541332}
1333
1334#endif
1335
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411336const base::string16& WebContentsImpl::GetTitle() {
[email protected]4c6092c5b2009-06-06 00:23:551337 // Transient entries take precedence. They are used for interstitial pages
1338 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:231339 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:231340 if (entry) {
jshin1fb76462016-04-05 22:13:031341 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231342 }
carlosk35f35af2015-12-01 10:55:401343
Nasko Oskov2f7d2112019-10-29 03:26:571344 WebUI* our_web_ui =
1345 GetRenderManager()->speculative_frame_host()
1346 ? GetRenderManager()->speculative_frame_host()->web_ui()
1347 : GetRenderManager()->current_frame_host()->web_ui();
[email protected]7ade2732011-02-10 00:13:581348 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:541349 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:321350 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:541351 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:351352 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:261353 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:541354 if (!title.empty())
1355 return title;
1356 }
1357 }
1358
1359 // We use the title for the last committed entry rather than a pending
1360 // navigation entry. For example, when the user types in a URL, we want to
1361 // keep the old page's title until the new load has committed and we get a new
1362 // title.
[email protected]96d185d2009-04-24 03:28:541363 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:321364
creis072b61f2015-09-28 20:52:241365 // We make an exception for initial navigations. We only want to use the title
1366 // from the visible entry if:
1367 // 1. The pending entry has been explicitly assigned a title to display.
1368 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
1369 // which case there is a pending entry index other than -1.
1370 //
1371 // Otherwise, we want to stick with the last committed entry's title during
1372 // new navigations, which have pending entries at index -1 with no title.
1373 if (controller_.IsInitialNavigation() &&
1374 ((controller_.GetVisibleEntry() &&
1375 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
1376 controller_.GetPendingEntryIndex() != -1)) {
1377 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:471378 }
[email protected]59167c22013-06-03 18:07:321379
[email protected]45d0ef7f2011-01-05 13:46:231380 if (entry) {
jshin1fb76462016-04-05 22:13:031381 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231382 }
[email protected]987fc3a2011-05-26 14:18:091383
1384 // |page_title_when_no_navigation_entry_| is finally used
1385 // if no title cannot be retrieved.
1386 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:541387}
1388
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411389SiteInstanceImpl* WebContentsImpl::GetSiteInstance() {
[email protected]fa944cb82013-11-15 17:51:211390 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541391}
1392
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411393bool WebContentsImpl::IsLoading() {
clamy44e84ce2016-02-22 15:38:251394 return frame_tree_.IsLoading() &&
creisadca9862017-06-16 19:12:111395 !(ShowingInterstitialPage() && interstitial_page_->pause_throbber());
[email protected]3c9e1872010-11-18 16:17:491396}
1397
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411398double WebContentsImpl::GetLoadProgress() {
Peter Boström18a40fa2018-10-31 19:03:501399 return frame_tree_.load_progress();
1400}
1401
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411402bool WebContentsImpl::IsLoadingToDifferentDocument() {
clamy44e84ce2016-02-22 15:38:251403 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031404}
1405
Alexander Timindd0fa0c52019-11-06 13:03:371406bool WebContentsImpl::IsDocumentOnLoadCompletedInMainFrame() {
1407 return GetRenderViewHost()->IsDocumentOnLoadCompletedInMainFrame();
1408}
1409
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411410bool WebContentsImpl::IsWaitingForResponse() {
Peter Boströma9a27f6e2018-11-21 13:12:191411 NavigationRequest* ongoing_navigation_request =
1412 frame_tree_.root()->navigation_request();
1413
1414 // An ongoing navigation request means we're waiting for a response.
1415 return ongoing_navigation_request != nullptr;
[email protected]be1f56ab2011-12-22 06:55:311416}
1417
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411418const net::LoadStateWithParam& WebContentsImpl::GetLoadState() {
[email protected]be1f56ab2011-12-22 06:55:311419 return load_state_;
1420}
1421
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411422const base::string16& WebContentsImpl::GetLoadStateHost() {
[email protected]be1f56ab2011-12-22 06:55:311423 return load_state_host_;
1424}
1425
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411426uint64_t WebContentsImpl::GetUploadSize() {
[email protected]be1f56ab2011-12-22 06:55:311427 return upload_size_;
1428}
1429
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411430uint64_t WebContentsImpl::GetUploadPosition() {
[email protected]be1f56ab2011-12-22 06:55:311431 return upload_position_;
1432}
1433
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411434const std::string& WebContentsImpl::GetEncoding() {
Alexander Timine5f20e22019-10-09 23:22:351435 return GetMainFrame()->GetEncoding();
[email protected]be1f56ab2011-12-22 06:55:311436}
1437
Charles Zhaod72f99d2018-09-17 14:18:271438bool WebContentsImpl::WasDiscarded() {
1439 return GetFrameTree()->root()->was_discarded();
1440}
1441
Shubhie Panickerddf2a4e2018-03-06 00:09:061442void WebContentsImpl::SetWasDiscarded(bool was_discarded) {
1443 GetFrameTree()->root()->set_was_discarded();
1444}
1445
Collin Bakerc5259962019-11-14 17:51:581446void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size,
1447 bool stay_hidden) {
[email protected]5a652232013-02-12 06:15:251448 DCHECK(!is_being_destroyed_);
Collin Bakerc5259962019-11-14 17:51:581449 if (stay_hidden)
1450 ++hidden_capturer_count_;
1451 else
1452 ++visible_capturer_count_;
[email protected]222f5822014-02-05 23:40:491453
1454 // Note: This provides a hint to upstream code to size the views optimally
1455 // for quality (e.g., to avoid scaling).
1456 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1457 preferred_size_for_capture_ = capture_size;
1458 OnPreferredSizeChanged(preferred_size_);
1459 }
ccameron8807c38f2015-01-17 00:29:191460
Collin Bakerc5259962019-11-14 17:51:581461 UpdateVisibilityAndNotifyPageAndView(GetVisibility());
[email protected]54597982013-02-06 01:59:551462}
1463
Collin Bakerc5259962019-11-14 17:51:581464void WebContentsImpl::DecrementCapturerCount(bool stay_hidden) {
1465 if (stay_hidden)
1466 --hidden_capturer_count_;
1467 else
1468 --visible_capturer_count_;
1469 DCHECK_GE(hidden_capturer_count_, 0);
1470 DCHECK_GE(visible_capturer_count_, 0);
[email protected]54597982013-02-06 01:59:551471
[email protected]5a652232013-02-12 06:15:251472 if (is_being_destroyed_)
1473 return;
1474
Francois Doray24fc62c2017-12-11 17:27:331475 if (!IsBeingCaptured()) {
[email protected]222f5822014-02-05 23:40:491476 const gfx::Size old_size = preferred_size_for_capture_;
1477 preferred_size_for_capture_ = gfx::Size();
1478 OnPreferredSizeChanged(old_size);
[email protected]54597982013-02-06 01:59:551479 }
Collin Bakerc5259962019-11-14 17:51:581480
1481 UpdateVisibilityAndNotifyPageAndView(GetVisibility());
[email protected]be1f56ab2011-12-22 06:55:311482}
1483
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411484bool WebContentsImpl::IsBeingCaptured() {
Collin Bakerc5259962019-11-14 17:51:581485 return visible_capturer_count_ + hidden_capturer_count_ > 0;
[email protected]f2bd40812013-07-20 04:30:441486}
1487
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411488bool WebContentsImpl::IsAudioMuted() {
Guido Urdanetaf8372942019-11-15 09:47:211489 return audio_stream_factory_ && audio_stream_factory_->IsMuted();
miu50f97892014-09-22 22:49:521490}
1491
1492void WebContentsImpl::SetAudioMuted(bool mute) {
1493 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1494 << " for WebContentsImpl@" << this;
1495
1496 if (mute == IsAudioMuted())
1497 return;
1498
Guido Urdanetaf8372942019-11-15 09:47:211499 GetAudioStreamFactory()->SetMuted(mute);
miu50f97892014-09-22 22:49:521500
ericwilligersde386342016-10-19 02:35:091501 for (auto& observer : observers_)
1502 observer.DidUpdateAudioMutingState(mute);
wjmaclean2f797c782016-01-07 14:52:031503
Jan Rucka442c83f2017-08-08 13:27:541504 // Notification for UI updates in response to the changed muting state.
Collin Bakeraf540cf2019-09-20 20:54:161505 NotifyNavigationStateChanged(INVALIDATE_TYPE_AUDIO);
Jan Rucka442c83f2017-08-08 13:27:541506}
1507
1508bool WebContentsImpl::IsCurrentlyAudible() {
Chris Hamiltondf0d72cd2018-05-29 16:23:531509 return is_currently_audible_;
miu50f97892014-09-22 22:49:521510}
1511
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411512bool WebContentsImpl::IsConnectedToBluetoothDevice() {
ortunodf4d7982016-04-08 02:33:351513 return bluetooth_connected_device_count_ > 0;
ortuno32e7db3c2016-03-29 16:14:201514}
1515
Lucas Furukawa Gadani4b4eed02019-06-04 23:12:041516bool WebContentsImpl::IsConnectedToSerialPort() {
Reilly Grant5e7c79b22019-04-09 17:26:201517 return serial_active_frame_count_ > 0;
1518}
1519
Matt Reynoldse8c6c1f2019-11-02 09:53:531520bool WebContentsImpl::IsConnectedToHidDevice() {
1521 return hid_active_frame_count_ > 0;
1522}
1523
Marijn Kruisselbrink29051042019-08-06 22:56:551524bool WebContentsImpl::HasNativeFileSystemHandles() {
1525 return native_file_system_handle_count_ > 0;
1526}
Marijn Kruisselbrinkf1714aa22019-07-02 03:45:331527bool WebContentsImpl::HasNativeFileSystemDirectoryHandles() {
Marijn Kruisselbrink46fa4bd2019-07-11 18:15:471528 return !native_file_system_directory_handles_.empty();
1529}
1530
1531std::vector<base::FilePath>
1532WebContentsImpl::GetNativeFileSystemDirectoryHandles() {
1533 std::vector<base::FilePath> result;
1534 result.reserve(native_file_system_directory_handles_.size());
1535 for (auto const& entry : native_file_system_directory_handles_)
1536 result.push_back(entry.first);
1537 return result;
Marijn Kruisselbrinkf1714aa22019-07-02 03:45:331538}
1539
1540bool WebContentsImpl::HasWritableNativeFileSystemHandles() {
1541 return native_file_system_writable_handle_count_ > 0;
1542}
1543
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411544bool WebContentsImpl::HasPictureInPictureVideo() {
sawtellea7333a82018-05-31 02:36:361545 return has_picture_in_picture_video_;
1546}
1547
1548void WebContentsImpl::SetHasPictureInPictureVideo(
1549 bool has_picture_in_picture_video) {
1550 // If status of |this| is already accurate, there is no need to update.
1551 if (has_picture_in_picture_video == has_picture_in_picture_video_)
1552 return;
1553 has_picture_in_picture_video_ = has_picture_in_picture_video;
1554 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
François Beaufort058085d2018-08-30 15:29:141555 for (auto& observer : observers_)
1556 observer.MediaPictureInPictureChanged(has_picture_in_picture_video_);
sawtellea7333a82018-05-31 02:36:361557}
1558
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411559bool WebContentsImpl::IsCrashed() {
Dominic Mazzoni73a48322018-05-25 18:14:071560 switch (crashed_status_) {
1561 case base::TERMINATION_STATUS_PROCESS_CRASHED:
1562 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
1563 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
1564 case base::TERMINATION_STATUS_OOM:
1565 case base::TERMINATION_STATUS_LAUNCH_FAILED:
oshima620225722015-06-04 19:45:271566#if defined(OS_CHROMEOS)
Dominic Mazzoni73a48322018-05-25 18:14:071567 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM:
oshima620225722015-06-04 19:45:271568#endif
Dominic Mazzoni73a48322018-05-25 18:14:071569#if defined(OS_ANDROID)
1570 case base::TERMINATION_STATUS_OOM_PROTECTED:
1571#endif
Will Harris07925d12019-10-31 03:03:051572#if defined(OS_WIN)
1573 case base::TERMINATION_STATUS_INTEGRITY_FAILURE:
1574#endif
Dominic Mazzoni73a48322018-05-25 18:14:071575 return true;
1576 case base::TERMINATION_STATUS_NORMAL_TERMINATION:
1577 case base::TERMINATION_STATUS_STILL_RUNNING:
1578 return false;
1579 case base::TERMINATION_STATUS_MAX_ENUM:
1580 NOTREACHED();
1581 return false;
1582 }
1583
1584 NOTREACHED();
1585 return false;
[email protected]3c9e1872010-11-18 16:17:491586}
1587
[email protected]b172aee2012-04-10 17:05:261588void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1589 int error_code) {
[email protected]443b80e2010-12-14 00:42:231590 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341591 return;
1592
[email protected]443b80e2010-12-14 00:42:231593 crashed_status_ = status;
1594 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211595 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341596}
1597
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411598base::TerminationStatus WebContentsImpl::GetCrashedStatus() {
[email protected]be1f56ab2011-12-22 06:55:311599 return crashed_status_;
1600}
1601
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411602int WebContentsImpl::GetCrashedErrorCode() {
afakhry98241832016-03-11 19:27:471603 return crashed_error_code_;
1604}
1605
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411606bool WebContentsImpl::IsBeingDestroyed() {
[email protected]be1f56ab2011-12-22 06:55:311607 return is_being_destroyed_;
1608}
1609
[email protected]7f924832014-08-09 05:57:221610void WebContentsImpl::NotifyNavigationStateChanged(
1611 InvalidateTypes changed_flags) {
dalecurtis88c240072015-12-09 02:11:181612 // Notify the media observer of potential audibility changes.
Collin Bakeraf540cf2019-09-20 20:54:161613 if (changed_flags & INVALIDATE_TYPE_AUDIO) {
mlamouri44e4ef42016-01-20 18:42:271614 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301615 }
1616
[email protected]d5f942ba2008-09-26 19:30:341617 if (delegate_)
1618 delegate_->NavigationStateChanged(this, changed_flags);
wjmaclean1dabf3e32016-05-13 23:34:441619
1620 if (GetOuterWebContents())
1621 GetOuterWebContents()->NotifyNavigationStateChanged(changed_flags);
[email protected]d5f942ba2008-09-26 19:30:341622}
1623
W. James MacLean6f34b042019-07-12 19:25:301624RenderFrameHostImpl* WebContentsImpl::GetFocusedFrameFromFocusedDelegate() {
1625 FrameTreeNode* focused_node =
1626 GetFocusedWebContents()->frame_tree_.GetFocusedFrame();
1627 return focused_node ? focused_node->current_frame_host() : nullptr;
1628}
1629
David Black9cca3592019-11-06 23:02:221630void WebContentsImpl::OnVerticalScrollDirectionChanged(
1631 viz::VerticalScrollDirection scroll_direction) {
1632 for (auto& observer : observers_)
1633 observer.DidChangeVerticalScrollDirection(scroll_direction);
1634}
1635
Chris Hamiltondf0d72cd2018-05-29 16:23:531636void WebContentsImpl::OnAudioStateChanged() {
1637 // This notification can come from any embedded contents or from this
1638 // WebContents' stream monitor. Aggregate these signals to get the actual
1639 // state.
1640 bool is_currently_audible =
1641 audio_stream_monitor_.IsCurrentlyAudible() ||
1642 (browser_plugin_embedder_ &&
1643 browser_plugin_embedder_->AreAnyGuestsCurrentlyAudible());
1644 if (is_currently_audible == is_currently_audible_)
1645 return;
1646
1647 // Update internal state.
1648 is_currently_audible_ = is_currently_audible;
1649 was_ever_audible_ = was_ever_audible_ || is_currently_audible_;
1650
1651 SendPageMessage(
1652 new PageMsg_AudioStateChanged(MSG_ROUTING_NONE, is_currently_audible_));
altimind8bd26c2016-11-04 11:44:541653
altiminec87fd1f2016-11-17 20:22:491654 // Notification for UI updates in response to the changed audio state.
Collin Bakeraf540cf2019-09-20 20:54:161655 NotifyNavigationStateChanged(INVALIDATE_TYPE_AUDIO);
Jan Rucka442c83f2017-08-08 13:27:541656
Chris Hamiltondf0d72cd2018-05-29 16:23:531657 // Ensure that audio state changes propagate from innermost to outermost
1658 // WebContents.
1659 if (GetOuterWebContents())
1660 GetOuterWebContents()->OnAudioStateChanged();
Tommy Steimel18360512017-11-01 00:38:191661
Chris Hamiltoneb41198f2018-05-24 18:41:261662 for (auto& observer : observers_)
Chris Hamiltondf0d72cd2018-05-29 16:23:531663 observer.OnAudioStateChanged(is_currently_audible_);
altimind8bd26c2016-11-04 11:44:541664}
1665
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411666base::TimeTicks WebContentsImpl::GetLastActiveTime() {
[email protected]9a890452014-02-13 22:21:021667 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331668}
1669
[email protected]9e2e4632012-07-27 16:38:411670void WebContentsImpl::WasShown() {
Collin Baker989e0882019-11-01 01:27:171671 UpdateVisibilityAndNotifyPageAndView(Visibility::VISIBLE);
[email protected]be1f56ab2011-12-22 06:55:311672}
1673
[email protected]b172aee2012-04-10 17:05:261674void WebContentsImpl::WasHidden() {
Collin Baker989e0882019-11-01 01:27:171675 UpdateVisibilityAndNotifyPageAndView(Visibility::HIDDEN);
[email protected]375fa1b2012-05-22 22:05:371676}
1677
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411678bool WebContentsImpl::HasRecentInteractiveInputEvent() {
Daniel Cheng90196c82018-04-25 21:49:141679 static constexpr base::TimeDelta kMaxInterval =
1680 base::TimeDelta::FromSeconds(5);
1681 base::TimeDelta delta =
1682 ui::EventTimeForNow() - last_interactive_input_event_time_;
1683 // Note: the expectation is that the caller is typically expecting an input
1684 // event, e.g. validating that a WebUI message that requires a gesture is
Daniel Chenge81030b32019-07-17 20:20:231685 // actually attached to a gesture.
Daniel Cheng90196c82018-04-25 21:49:141686 return delta <= kMaxInterval;
1687}
1688
Avi Drissman738ea192018-08-29 20:24:161689void WebContentsImpl::SetIgnoreInputEvents(bool ignore_input_events) {
1690 ignore_input_events_ = ignore_input_events;
1691}
1692
Bo Liu168c8642017-08-28 18:26:021693#if defined(OS_ANDROID)
Bo Liu16dd7b8322018-05-02 21:19:501694void WebContentsImpl::SetMainFrameImportance(
1695 ChildProcessImportance importance) {
1696 GetMainFrame()->GetRenderWidgetHost()->SetImportance(importance);
Bo Liu7c6779e92017-08-16 02:02:281697 if (ShowingInterstitialPage()) {
Bo Liu16dd7b8322018-05-02 21:19:501698 static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame())
1699 ->GetRenderWidgetHost()
1700 ->SetImportance(importance);
Bo Liu7c6779e92017-08-16 02:02:281701 }
Bo Liu7c6779e92017-08-16 02:02:281702}
Bo Liu168c8642017-08-28 18:26:021703#endif
Bo Liu7c6779e92017-08-16 02:02:281704
ccameron8807c38f2015-01-17 00:29:191705void WebContentsImpl::WasOccluded() {
Collin Baker989e0882019-11-01 01:27:171706 UpdateVisibilityAndNotifyPageAndView(Visibility::OCCLUDED);
ccameron8807c38f2015-01-17 00:29:191707}
1708
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:411709Visibility WebContentsImpl::GetVisibility() {
Francois Doraye6161152018-03-27 22:05:371710 return visibility_;
Francois Dorayfe4a1772018-02-17 04:17:091711}
1712
Alex Moshchuk5bcd7c12019-11-12 22:55:311713bool WebContentsImpl::NeedToFireBeforeUnloadOrUnload() {
[email protected]be1f56ab2011-12-22 06:55:311714 // TODO(creis): Should we fire even for interstitial pages?
Alex Moshchuk6fcaca752018-07-14 02:13:591715 if (ShowingInterstitialPage())
1716 return false;
1717
1718 if (!WillNotifyDisconnection())
1719 return false;
1720
1721 // Don't fire if the main frame's RenderViewHost indicates that beforeunload
1722 // and unload have already executed (e.g., after receiving a ClosePage ACK)
1723 // or should be ignored.
1724 if (GetRenderViewHost()->SuddenTerminationAllowed())
1725 return false;
1726
Alex Moshchukc78dbc722019-10-31 20:00:501727 // Check whether any frame in the frame tree needs to run beforeunload or
1728 // unload handlers.
1729 for (FrameTreeNode* node : frame_tree_.Nodes()) {
1730 RenderFrameHostImpl* rfh = node->current_frame_host();
1731
1732 // No need to run beforeunload/unload if the RenderFrame isn't live.
1733 if (!rfh->IsRenderFrameLive())
1734 continue;
1735
Dave Tapuska97d22ab2019-12-03 17:56:361736 if (rfh->GetSuddenTerminationDisablerState(
1737 blink::mojom::SuddenTerminationDisablerType::
1738 kBeforeUnloadHandler) ||
1739 rfh->GetSuddenTerminationDisablerState(
1740 blink::mojom::SuddenTerminationDisablerType::kUnloadHandler)) {
Alex Moshchukc78dbc722019-10-31 20:00:501741 return true;
1742 }
Aditya Keerthi34f37e62019-03-08 15:54:531743 }
Alex Moshchuk6fcaca752018-07-14 02:13:591744
Alex Moshchukc78dbc722019-10-31 20:00:501745 return false;
[email protected]be1f56ab2011-12-22 06:55:311746}
1747
Chris Hamilton3b3e315d2018-09-19 13:16:211748void WebContentsImpl::DispatchBeforeUnload(bool auto_cancel) {
1749 auto before_unload_type =
1750 auto_cancel ? RenderFrameHostImpl::BeforeUnloadType::DISCARD
1751 : RenderFrameHostImpl::BeforeUnloadType::TAB_CLOSE;
1752 GetMainFrame()->DispatchBeforeUnload(before_unload_type, false);
[email protected]1c3f80bd2014-04-08 23:02:061753}
1754
W. James MacLean2539adb32019-12-13 00:40:441755bool WebContentsImpl::IsInnerWebContentsForGuest() {
1756 return !!browser_plugin_guest_;
1757}
1758
Lucas Furukawa Gadani6e5b4f32019-03-02 04:18:501759void WebContentsImpl::AttachInnerWebContents(
1760 std::unique_ptr<WebContents> inner_web_contents,
W. James MacLean62883982019-11-12 20:39:001761 RenderFrameHost* render_frame_host,
1762 bool is_full_page) {
Lucas Furukawa Gadani6e5b4f32019-03-02 04:18:501763 WebContentsImpl* inner_web_contents_impl =
1764 static_cast<WebContentsImpl*>(inner_web_contents.get());
1765 DCHECK(!inner_web_contents_impl->node_.outer_web_contents());
1766 auto* render_frame_host_impl =
1767 static_cast<RenderFrameHostImpl*>(render_frame_host);
1768 DCHECK_EQ(&frame_tree_,
1769 render_frame_host_impl->frame_tree_node()->frame_tree());
Lucas Furukawa Gadani105de1e812018-05-31 19:38:391770
Lucas Furukawa Gadani6e5b4f32019-03-02 04:18:501771 RenderFrameHostManager* inner_render_manager =
1772 inner_web_contents_impl->GetRenderManager();
1773 RenderFrameHostImpl* inner_main_frame =
1774 inner_render_manager->current_frame_host();
1775 RenderViewHostImpl* inner_render_view_host =
1776 inner_render_manager->current_host();
1777 auto* outer_render_manager =
1778 render_frame_host_impl->frame_tree_node()->render_manager();
lfg91a79e12016-04-01 23:52:191779
Lucas Furukawa Gadani105de1e812018-05-31 19:38:391780 // When attaching a WebContents as an inner WebContents, we need to replace
1781 // the Webcontents' view with a WebContentsViewChildFrame.
Lucas Furukawa Gadani6e5b4f32019-03-02 04:18:501782 inner_web_contents_impl->view_.reset(new WebContentsViewChildFrame(
1783 inner_web_contents_impl,
1784 GetContentClient()->browser()->GetWebContentsViewDelegate(
1785 inner_web_contents_impl),
1786 &inner_web_contents_impl->render_view_host_delegate_view_));
Lucas Furukawa Gadani105de1e812018-05-31 19:38:391787
lfg91a79e12016-04-01 23:52:191788 // When the WebContents being initialized has an opener, the browser side
1789 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView
1790 // created. This is needed because the usual initialization happens during
1791 // the first navigation, but when attaching a new window we don't navigate
1792 // before attaching. If the browser side is already initialized, the calls
1793 // below will just early return.
Lucas Furukawa Gadani6e5b4f32019-03-02 04:18:501794 inner_render_manager->InitRenderView(inner_render_view_host, nullptr);
1795 inner_main_frame->Init();
1796 if (!inner_render_manager->GetRenderWidgetHostView()) {
1797 inner_web_contents_impl->CreateRenderWidgetHostViewForRenderManager(
1798 inner_render_view_host);
1799 }
lfg91a79e12016-04-01 23:52:191800
Adithya Srinivasane6e7f842019-12-16 18:41:361801 inner_web_contents_impl->RecursivelyUnregisterFrameSinkIds();
1802
lazyboy6ec48b2a2015-06-29 15:18:141803 // Create a link to our outer WebContents.
Lucas Furukawa Gadani6e5b4f32019-03-02 04:18:501804 node_.AttachInnerWebContents(std::move(inner_web_contents),
1805 render_frame_host_impl);
lazyboy6ec48b2a2015-06-29 15:18:141806
lazyboy6ec48b2a2015-06-29 15:18:141807 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1808 // SiteInstance of the outer WebContents. The proxy will be used to send
1809 // postMessage to the inner WebContents.
Lucas Furukawa Gadani6e5b4f32019-03-02 04:18:501810 auto* proxy = inner_render_manager->CreateOuterDelegateProxy(
1811 render_frame_host_impl->GetSiteInstance());
lazyboy6ec48b2a2015-06-29 15:18:141812
Lucas Furukawa Gadani99125822019-01-03 15:41:491813 // When attaching a GuestView as an inner WebContents, there should already be
1814 // a live RenderFrame, which has to be swapped. When attaching a portal, there
1815 // will not be a live RenderFrame before creating the proxy.
Lucas Furukawa Gadani6e5b4f32019-03-02 04:18:501816 if (render_frame_host_impl->IsRenderFrameLive()) {
1817 inner_render_manager->SwapOuterDelegateFrame(render_frame_host_impl, proxy);
Lucas Furukawa Gadani99125822019-01-03 15:41:491818
Lucas Furukawa Gadani6e5b4f32019-03-02 04:18:501819 inner_web_contents_impl->ReattachToOuterWebContentsFrame();
Lucas Furukawa Gadani99125822019-01-03 15:41:491820 }
ekaramadadd882292016-06-08 15:22:561821
Lucas Furukawa Gadani6e5b4f32019-03-02 04:18:501822 if (frame_tree_.GetFocusedFrame() ==
1823 render_frame_host_impl->frame_tree_node()) {
1824 inner_web_contents_impl->SetFocusedFrame(
1825 inner_web_contents_impl->frame_tree_.root(),
1826 render_frame_host_impl->GetSiteInstance());
avallee7529b2a2017-04-26 11:37:511827 }
Lucas Furukawa Gadani6e5b4f32019-03-02 04:18:501828 outer_render_manager->set_attach_complete();
W. James MacLean62883982019-11-12 20:39:001829
1830 // If the inner WebContents is full frame, give it focus.
1831 if (is_full_page) {
1832 // There should only ever be one inner WebContents when |is_full_page| is
1833 // true, and it is the one we just attached.
1834 DCHECK_EQ(1u, node_.GetInnerWebContents().size());
1835 inner_web_contents_impl->SetAsFocusedWebContentsIfNecessary();
1836 }
lazyboy6ec48b2a2015-06-29 15:18:141837}
1838
Lucas Furukawa Gadani99125822019-01-03 15:41:491839std::unique_ptr<WebContents> WebContentsImpl::DetachFromOuterWebContents() {
1840 DCHECK(node_.outer_web_contents());
Adithya Srinivasane6e7f842019-12-16 18:41:361841 RecursivelyUnregisterFrameSinkIds();
Lucas Furukawa Gadani99125822019-01-03 15:41:491842 if (RenderWidgetHostViewBase* view =
1843 static_cast<RenderWidgetHostViewBase*>(GetMainFrame()->GetView())) {
Kevin McNee6471a702020-01-27 18:23:071844 DCHECK(view->IsRenderWidgetHostViewChildFrame());
Lucas Furukawa Gadani99125822019-01-03 15:41:491845 view->Destroy();
1846 }
Kevin McNee6471a702020-01-27 18:23:071847 if (GetPendingMainFrame()) {
1848 if (RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
1849 GetPendingMainFrame()->GetView())) {
1850 DCHECK(view->IsRenderWidgetHostViewChildFrame());
1851 view->Destroy();
1852 }
1853 }
Lucas Furukawa Gadani99125822019-01-03 15:41:491854 GetRenderManager()->DeleteOuterDelegateProxy(
1855 node_.OuterContentsFrameTreeNode()
1856 ->current_frame_host()
1857 ->GetSiteInstance());
1858 view_.reset(CreateWebContentsView(
1859 this, GetContentClient()->browser()->GetWebContentsViewDelegate(this),
1860 &render_view_host_delegate_view_));
danakjfc5184932019-09-12 18:08:321861 view_->CreateView(nullptr);
Lucas Furukawa Gadani99125822019-01-03 15:41:491862 std::unique_ptr<WebContents> web_contents =
1863 node_.DisconnectFromOuterWebContents();
1864 DCHECK_EQ(web_contents.get(), this);
1865 node_.SetFocusedWebContents(this);
1866 CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost());
Kevin McNee6471a702020-01-27 18:23:071867 if (GetPendingMainFrame()) {
1868 CreateRenderWidgetHostViewForRenderManager(
1869 GetPendingMainFrame()->render_view_host());
1870 }
Adithya Srinivasane6e7f842019-12-16 18:41:361871 RecursivelyRegisterFrameSinkIds();
Adithya Srinivasan6f0f67b2019-12-19 01:26:461872 // TODO(adithyas): |browser_plugin_embedder_ax_tree_id| should either not be
1873 // used for portals, or it should get a different name.
1874 GetMainFrame()->set_browser_plugin_embedder_ax_tree_id(ui::AXTreeIDUnknown());
1875 GetMainFrame()->UpdateAXTreeData();
Lucas Furukawa Gadani99125822019-01-03 15:41:491876 return web_contents;
1877}
1878
W. James MacLean2dc75ed42019-03-06 14:31:091879void WebContentsImpl::RecursivelyRegisterFrameSinkIds() {
Adithya Srinivasane6e7f842019-12-16 18:41:361880 for (auto* view : GetRenderWidgetHostViewsInWebContentsTree()) {
1881 auto* rwhvb = static_cast<RenderWidgetHostViewBase*>(view);
1882 if (rwhvb->IsRenderWidgetHostViewChildFrame())
1883 static_cast<RenderWidgetHostViewChildFrame*>(view)->RegisterFrameSinkId();
1884 }
1885}
W. James MacLean2dc75ed42019-03-06 14:31:091886
Adithya Srinivasane6e7f842019-12-16 18:41:361887void WebContentsImpl::RecursivelyUnregisterFrameSinkIds() {
1888 for (auto* view : GetRenderWidgetHostViewsInWebContentsTree()) {
1889 auto* rwhvb = static_cast<RenderWidgetHostViewBase*>(view);
1890 if (rwhvb->IsRenderWidgetHostViewChildFrame()) {
1891 static_cast<RenderWidgetHostViewChildFrame*>(view)
1892 ->UnregisterFrameSinkId();
1893 }
W. James MacLean2dc75ed42019-03-06 14:31:091894 }
1895}
1896
Lucas Furukawa Gadaniaed1fed2017-10-13 17:34:141897void WebContentsImpl::ReattachToOuterWebContentsFrame() {
1898 DCHECK(node_.outer_web_contents());
1899 auto* render_manager = GetRenderManager();
1900 auto* parent_frame =
1901 node_.OuterContentsFrameTreeNode()->current_frame_host()->GetParent();
1902 render_manager->SetRWHViewForInnerContents(
1903 render_manager->GetRenderWidgetHostView());
1904
W. James MacLean2dc75ed42019-03-06 14:31:091905 RecursivelyRegisterFrameSinkIds();
Lucas Furukawa Gadaniaed1fed2017-10-13 17:34:141906
1907 // Set up the the guest's AX tree to point back at the embedder's AX tree.
1908 GetMainFrame()->set_browser_plugin_embedder_ax_tree_id(
1909 parent_frame->GetAXTreeID());
1910 GetMainFrame()->UpdateAXTreeData();
1911}
1912
Adithya Srinivasan11af2c52019-12-16 22:52:551913void WebContentsImpl::NotifyInsidePortal(bool inside_portal) {
1914 SendPageMessage(new PageMsg_SetInsidePortal(MSG_ROUTING_NONE, inside_portal));
1915}
1916
dalecurtis6c58ed02016-10-28 23:02:371917void WebContentsImpl::DidChangeVisibleSecurityState() {
Emily Starkc663b0242019-04-26 19:34:451918 if (delegate_)
dalecurtis6c58ed02016-10-28 23:02:371919 delegate_->VisibleSecurityStateChanged(this);
Emily Starkc663b0242019-04-26 19:34:451920 for (auto& observer : observers_)
1921 observer.DidChangeVisibleSecurityState();
dalecurtis6c58ed02016-10-28 23:02:371922}
1923
Ahmed Fakhryd70bf37b2018-04-04 17:07:241924void WebContentsImpl::NotifyPreferencesChanged() {
1925 std::set<RenderViewHost*> render_view_host_set;
1926 for (FrameTreeNode* node : frame_tree_.Nodes()) {
Giovanni Ortuño Urquidi17a5d7c2018-04-30 06:48:531927 render_view_host_set.insert(
1928 node->current_frame_host()->GetRenderViewHost());
Ahmed Fakhryd70bf37b2018-04-04 17:07:241929 }
Giovanni Ortuño Urquidi17a5d7c2018-04-30 06:48:531930
Ahmed Fakhryd70bf37b2018-04-04 17:07:241931 for (RenderViewHost* render_view_host : render_view_host_set)
1932 render_view_host->OnWebkitPreferencesChanged();
1933}
1934
Bruce Long1e3e1f542019-10-16 17:56:281935void WebContentsImpl::SyncRendererPrefs() {
1936 blink::mojom::RendererPreferences renderer_preferences =
1937 GetRendererPrefs(GetBrowserContext());
1938 RenderViewHostImpl::GetPlatformSpecificPrefs(&renderer_preferences);
1939 SendPageMessage(
1940 new PageMsg_SetRendererPrefs(MSG_ROUTING_NONE, renderer_preferences));
1941}
1942
Josh Karlindaba39322019-07-17 23:24:331943void WebContentsImpl::OnCookiesRead(const GURL& url,
1944 const GURL& first_party_url,
1945 const net::CookieList& cookie_list,
1946 bool blocked_by_policy) {
1947 for (auto& observer : observers_) {
1948 observer.OnCookiesRead(url, first_party_url, cookie_list,
1949 blocked_by_policy);
1950 }
1951}
1952
1953void WebContentsImpl::OnCookieChange(const GURL& url,
1954 const GURL& first_party_url,
1955 const net::CanonicalCookie& cookie,
1956 bool blocked_by_policy) {
1957 for (auto& observer : observers_) {
1958 observer.OnCookieChange(url, first_party_url, cookie, blocked_by_policy);
1959 }
1960}
1961
[email protected]b172aee2012-04-10 17:05:261962void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381963 for (FrameTreeNode* node : frame_tree_.Nodes())
1964 node->StopLoading();
ericwilligersde386342016-10-19 02:35:091965 for (auto& observer : observers_)
1966 observer.NavigationStopped();
[email protected]0bfbf882011-12-22 18:19:271967}
1968
Francois Doray47f759d2018-06-11 18:13:511969void WebContentsImpl::SetPageFrozen(bool frozen) {
1970 // A visible page is never frozen.
1971 DCHECK_NE(Visibility::VISIBLE, GetVisibility());
1972
1973 SendPageMessage(new PageMsg_SetPageFrozen(MSG_ROUTING_NONE, frozen));
Fadi Meawada6573e02018-03-10 00:52:111974}
1975
erikchen6c7df7f7a2018-05-03 18:13:591976std::unique_ptr<WebContents> WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441977 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211978 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451979 // before.
[email protected]54944cde2012-12-09 09:24:591980 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
Ian Clelland5cbaaf82017-11-27 22:00:031981 FrameTreeNode* opener = frame_tree_.root()->opener();
1982 RenderFrameHostImpl* opener_rfh = nullptr;
1983 if (opener)
1984 opener_rfh = opener->current_frame_host();
erikchen6c7df7f7a2018-05-03 18:13:591985 std::unique_ptr<WebContentsImpl> tc =
erikchen50735fd2018-05-05 15:08:331986 CreateWithOpener(create_params, opener_rfh);
Lucas Furukawa Gadani5553a152019-01-08 18:55:571987 tc->GetController().CopyStateFrom(&controller_, true);
ericwilligersde386342016-10-19 02:35:091988 for (auto& observer : observers_)
erikchen6c7df7f7a2018-05-03 18:13:591989 observer.DidCloneToNewWebContents(this, tc.get());
[email protected]0bfbf882011-12-22 18:19:271990 return tc;
1991}
1992
[email protected]14392a52012-05-02 20:28:441993void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211994 const NotificationSource& source,
1995 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441996 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211997 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1998 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031999 RenderWidgetHostView* view = host->GetView();
2000 if (view == GetFullscreenRenderWidgetHostView()) {
2001 // We cannot just call view_->RestoreFocus() here. On some platforms,
2002 // attempting to focus the currently-invisible WebContentsView will be
2003 // flat-out ignored. Therefore, this boolean is used to track whether
2004 // we will request focus after the fullscreen widget has been
2005 // destroyed.
2006 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
2007 } else {
alexmosc2a8cec2016-05-23 22:19:532008 for (auto i = pending_widget_views_.begin();
[email protected]0b431992014-06-24 00:08:032009 i != pending_widget_views_.end(); ++i) {
2010 if (host->GetView() == i->second) {
2011 pending_widget_views_.erase(i);
2012 break;
2013 }
[email protected]bafe6cd2012-05-23 23:09:502014 }
2015 }
2016 break;
2017 }
[email protected]14392a52012-05-02 20:28:442018 default:
2019 NOTREACHED();
2020 }
2021}
2022
[email protected]ec6c05f2013-10-23 18:41:572023WebContents* WebContentsImpl::GetWebContents() {
2024 return this;
2025}
2026
[email protected]54944cde2012-12-09 09:24:592027void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:212028 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:362029 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:212030 // it should be hidden.
Francois Doraye6161152018-03-27 22:05:372031 visibility_ =
2032 params.initially_hidden ? Visibility::HIDDEN : Visibility::VISIBLE;
[email protected]d6fa88f2013-10-18 16:00:432033
Sebastien Marchand28cf23182018-06-20 02:39:352034 if (!params.last_active_time.is_null())
2035 last_active_time_ = params.last_active_time;
2036
dcheng3ce04b62015-10-26 23:30:552037 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:542038 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:552039 params.main_frame_routing_id == MSG_ROUTING_NONE &&
2040 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:542041 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:552042 params.main_frame_routing_id != MSG_ROUTING_NONE &&
2043 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
2044
2045 scoped_refptr<SiteInstance> site_instance = params.site_instance;
2046 if (!site_instance)
2047 site_instance = SiteInstance::Create(params.browser_context);
Lukasz Anforowicz3caa8372018-06-05 17:22:072048 if (params.desired_renderer_state == CreateParams::kNoRendererProcess) {
2049 static_cast<SiteInstanceImpl*>(site_instance.get())
2050 ->PreventAssociationWithSpareProcess();
2051 }
dcheng3ce04b62015-10-26 23:30:552052
2053 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
2054 // local root by definition.
2055 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
2056 // longer be necessary to eagerly grab a routing ID for the view.
2057 // https://crbug.com/545684
2058 int32_t view_routing_id = params.routing_id;
2059 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
2060 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
Albert J. Wongcb004632018-07-10 22:58:252061 view_routing_id = site_instance->GetProcess()->GetNextRoutingID();
2062 main_frame_widget_routing_id =
dcheng3ce04b62015-10-26 23:30:552063 site_instance->GetProcess()->GetNextRoutingID();
2064 }
2065
Albert J. Wongcb004632018-07-10 22:58:252066 DCHECK_NE(view_routing_id, main_frame_widget_routing_id);
2067
Dave Tapuska485aca92017-08-08 00:47:582068 GetRenderManager()->Init(
2069 site_instance.get(), view_routing_id, params.main_frame_routing_id,
2070 main_frame_widget_routing_id, params.renderer_initiated_creation);
lukasza464d8692016-02-22 19:26:322071
lukasza5140a412016-09-15 21:12:302072 // blink::FrameTree::setName always keeps |unique_name| empty in case of a
2073 // main frame - let's do the same thing here.
2074 std::string unique_name;
lukasza464d8692016-02-22 19:26:322075 frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name);
[email protected]d1198fd2012-08-13 22:50:192076
[email protected]fc2b46b2014-05-03 16:33:452077 WebContentsViewDelegate* delegate =
2078 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
2079
W. James MacLean2539adb32019-12-13 00:40:442080 if (browser_plugin_guest_) {
sky52a39e342016-12-17 17:23:222081 view_.reset(new WebContentsViewChildFrame(
2082 this, delegate, &render_view_host_delegate_view_));
2083 } else {
2084 view_.reset(CreateWebContentsView(this, delegate,
2085 &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:192086 }
[email protected]fc2b46b2014-05-03 16:33:452087 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:192088 CHECK(view_.get());
2089
danakjfc5184932019-09-12 18:08:322090 view_->CreateView(params.context);
[email protected]d1198fd2012-08-13 22:50:192091
brettw4b461082016-11-19 18:55:162092#if BUILDFLAG(ENABLE_PLUGINS)
tommyclieb25b2a2014-11-03 19:45:092093 plugin_content_origin_whitelist_.reset(
2094 new PluginContentOriginWhitelist(this));
2095#endif
2096
[email protected]d1198fd2012-08-13 22:50:192097 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:212098 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
2099 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:102100
leon.hane4db177a2017-02-07 14:19:162101 screen_orientation_provider_.reset(new ScreenOrientationProvider(this));
[email protected]01f83f92014-06-17 14:41:542102
mlamouriefdca9d2014-09-16 16:55:402103 manifest_manager_host_.reset(new ManifestManagerHost(this));
2104
mfomitchev2b8b066a2016-01-28 19:23:152105#if defined(OS_ANDROID)
Oksana Zhuravlova0b634332019-10-28 23:04:222106 DateTimeChooserAndroid::CreateForWebContents(this);
[email protected]583418cc2013-01-17 14:01:102107#endif
fsamuel7310a4262014-12-05 05:06:442108
2109 // BrowserPluginGuest::Init needs to be called after this WebContents has
W. James MacLean6e78da342019-12-13 15:13:232110 // a RenderWidgetHostViewChildFrame. That is, |view_->CreateView| above.
fsamuel7310a4262014-12-05 05:06:442111 if (browser_plugin_guest_)
2112 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:372113
2114 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
2115 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:562116
2117 // If the WebContents creation was renderer-initiated, it means that the
2118 // corresponding RenderView and main RenderFrame have already been created.
2119 // Ensure observers are notified about this.
2120 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:432121 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
Alex Moshchuk27caae82017-09-11 23:11:182122 GetRenderViewHost()->DispatchRenderViewCreated();
naskob21fe4872015-02-24 14:15:562123 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
2124 }
naskof5940b9f2015-03-02 23:04:052125
lof84501da082016-05-23 21:22:542126 // Create the renderer process in advance if requested.
Lukasz Anforowicz3caa8372018-06-05 17:22:072127 if (params.desired_renderer_state ==
2128 CreateParams::kInitializeAndWarmupRendererProcess) {
lof84501da082016-05-23 21:22:542129 if (!GetRenderManager()->current_frame_host()->IsRenderFrameLive()) {
2130 GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr);
2131 }
2132 }
2133
naskof5940b9f2015-03-02 23:04:052134 // Ensure that observers are notified of the creation of this WebContents's
2135 // main RenderFrameHost. It must be done here for main frames, since the
2136 // NotifySwappedFromRenderManager expects view_ to already be created and that
2137 // happens after RenderFrameHostManager::Init.
2138 NotifySwappedFromRenderManager(
2139 nullptr, GetRenderManager()->current_frame_host(), true);
Albert J. Wonge76bf0b82019-09-27 07:47:062140
2141 // For WebContents that are never shown, do critical initialization here which
2142 // would normally only happen when the WebContents is shown.
2143 if (params.is_never_visible) {
2144 // This has just been created so there can only be one frame. Thus it is
2145 // safe to initialize the root.
2146 GetMainFrame()->Init();
2147 }
[email protected]d1198fd2012-08-13 22:50:192148}
2149
[email protected]7fff43e2013-05-21 20:21:102150void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
2151 RemoveDestructionObserver(web_contents);
2152
[email protected]ceee8cd2013-03-08 04:59:512153 // Clear a pending contents that has been closed before being shown.
alexmosc2a8cec2016-05-23 22:19:532154 for (auto iter = pending_contents_.begin(); iter != pending_contents_.end();
[email protected]ceee8cd2013-03-08 04:59:512155 ++iter) {
erikchenbee5c9622018-04-27 19:30:252156 if (iter->second.get() != web_contents)
[email protected]ceee8cd2013-03-08 04:59:512157 continue;
erikchenbee5c9622018-04-27 19:30:252158
2159 // Someone else has deleted the WebContents. That should never happen!
2160 // TODO(erikchen): Fix semantics here. https://crbug.com/832879.
2161 iter->second.release();
[email protected]ceee8cd2013-03-08 04:59:512162 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:512163 return;
2164 }
2165 NOTREACHED();
[email protected]14392a52012-05-02 20:28:442166}
2167
[email protected]7fff43e2013-05-21 20:21:102168void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
Jan Wilken Dörrie73c901e2019-06-12 09:02:322169 if (!base::Contains(destruction_observers_, web_contents)) {
[email protected]7fff43e2013-05-21 20:21:102170 destruction_observers_[web_contents] =
Jeremy Roman04f27c372017-10-27 15:20:552171 std::make_unique<DestructionObserver>(this, web_contents);
[email protected]7fff43e2013-05-21 20:21:102172 }
2173}
2174
2175void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
avia8cf81982016-08-12 20:28:462176 destruction_observers_.erase(web_contents);
[email protected]7fff43e2013-05-21 20:21:102177}
2178
[email protected]b172aee2012-04-10 17:05:262179void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:312180 observers_.AddObserver(observer);
2181}
2182
[email protected]b172aee2012-04-10 17:05:262183void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:312184 observers_.RemoveObserver(observer);
2185}
2186
[email protected]948481d2014-06-11 18:32:222187std::set<RenderWidgetHostView*>
2188WebContentsImpl::GetRenderWidgetHostViewsInTree() {
2189 std::set<RenderWidgetHostView*> set;
2190 if (ShowingInterstitialPage()) {
lfgf949e0e2017-05-10 22:18:112191 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView())
2192 set.insert(rwhv);
[email protected]948481d2014-06-11 18:32:222193 } else {
dchengafb53e22016-02-04 08:11:082194 for (RenderFrameHost* rfh : GetAllFrames()) {
lfgf949e0e2017-05-10 22:18:112195 if (RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
2196 ->frame_tree_node()
2197 ->render_manager()
2198 ->GetRenderWidgetHostView()) {
2199 set.insert(rwhv);
2200 }
dchengafb53e22016-02-04 08:11:082201 }
[email protected]948481d2014-06-11 18:32:222202 }
[email protected]de3c5d82014-05-28 22:12:592203 return set;
2204}
2205
Adithya Srinivasane6e7f842019-12-16 18:41:362206std::set<RenderWidgetHostView*>
2207WebContentsImpl::GetRenderWidgetHostViewsInWebContentsTree() {
2208 std::set<RenderWidgetHostView*> result;
2209 GetRenderWidgetHostViewsInWebContentsTree(result);
2210 return result;
2211}
2212
2213void WebContentsImpl::GetRenderWidgetHostViewsInWebContentsTree(
2214 std::set<RenderWidgetHostView*>& result) {
2215 std::set<RenderWidgetHostView*> views = GetRenderWidgetHostViewsInTree();
2216 result.insert(views.begin(), views.end());
2217 for (auto* inner_web_contents : GetInnerWebContents()) {
2218 static_cast<WebContentsImpl*>(inner_web_contents)
2219 ->GetRenderWidgetHostViewsInWebContentsTree(result);
2220 }
2221}
2222
[email protected]b172aee2012-04-10 17:05:262223void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:342224 if (delegate_)
2225 delegate_->ActivateContents(this);
2226}
2227
avi3e4b8512015-11-11 01:55:492228void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
2229 if (!RenderViewHostImpl::From(render_widget_host))
2230 return;
2231
[email protected]63954792011-07-11 04:17:482232 if (delegate_)
2233 delegate_->LostCapture();
2234}
2235
Steven Holte38041342018-06-22 22:00:572236ukm::SourceId WebContentsImpl::GetUkmSourceIdForLastCommittedSource() const {
2237 return last_committed_source_id_;
2238}
2239
Yue Ru Sun979c4b162019-11-06 16:11:042240ukm::SourceId
2241WebContentsImpl::GetUkmSourceIdForLastCommittedSourceIncludingSameDocument()
2242 const {
2243 return last_committed_source_id_including_same_document_;
2244}
2245
Ahmed Fakhryfaa32d22018-10-05 15:56:162246void WebContentsImpl::SetTopControlsShownRatio(
2247 RenderWidgetHostImpl* render_widget_host,
2248 float ratio) {
2249 if (!delegate_)
2250 return;
2251
2252 RenderFrameHostImpl* rfh = GetMainFrame();
2253 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
2254 return;
2255
2256 delegate_->SetTopControlsShownRatio(this, ratio);
Ahmed Fakhry58e6ef542018-09-04 18:05:382257}
2258
Ahmed Fakhry58e6ef542018-09-04 18:05:382259void WebContentsImpl::SetTopControlsGestureScrollInProgress(bool in_progress) {
2260 if (delegate_)
2261 delegate_->SetTopControlsGestureScrollInProgress(in_progress);
2262}
2263
lazyboy63f5b312015-11-23 20:19:522264void WebContentsImpl::RenderWidgetCreated(
2265 RenderWidgetHostImpl* render_widget_host) {
2266 created_widgets_.insert(render_widget_host);
2267}
2268
[email protected]b24b68a2012-09-24 21:57:262269void WebContentsImpl::RenderWidgetDeleted(
2270 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:522271 // Note that |is_being_destroyed_| can be true at this point as
2272 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
2273 // us here.
2274 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:262275
lazyboy63f5b312015-11-23 20:19:522276 if (is_being_destroyed_)
2277 return;
[email protected]44470a22013-01-24 01:21:542278
2279 if (render_widget_host &&
alexmosc9e76ec2016-05-16 22:59:372280 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_ &&
2281 render_widget_host->GetProcess()->GetID() ==
2282 fullscreen_widget_process_id_) {
[email protected]4aebbca2013-09-17 22:26:492283 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:532284 delegate_->ExitFullscreenModeForTab(this);
ericwilligersde386342016-10-19 02:35:092285 for (auto& observer : observers_)
2286 observer.DidDestroyFullscreenWidget();
alexmosc9e76ec2016-05-16 22:59:372287 fullscreen_widget_process_id_ = ChildProcessHost::kInvalidUniqueID;
[email protected]44470a22013-01-24 01:21:542288 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:032289 if (fullscreen_widget_had_focus_at_shutdown_)
2290 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:542291 }
lfgbee1e0a2016-06-08 21:24:212292
lfg7d4caad2017-03-22 09:01:452293 if (render_widget_host == mouse_lock_widget_)
lfgff8dfc8d2016-10-21 17:42:322294 LostMouseLock(mouse_lock_widget_);
Joe Downing192998b22018-03-22 15:51:362295
Joe Downingc1a57efe2018-05-09 18:23:542296 CancelKeyboardLock(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:262297}
2298
miu9e14e492014-10-25 02:39:042299void WebContentsImpl::RenderWidgetGotFocus(
2300 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:372301 // Notify the observers if an embedded fullscreen widget was focused.
2302 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
2303 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
Michael Thiessen896405db2017-07-20 17:52:322304 NotifyWebContentsFocused(render_widget_host);
calamity7fe55ce2015-04-10 03:59:372305 }
miu9e14e492014-10-25 02:39:042306}
2307
zijiehe3bee08e22017-05-17 04:14:462308void WebContentsImpl::RenderWidgetLostFocus(
2309 RenderWidgetHostImpl* render_widget_host) {
Michael Thiessen896405db2017-07-20 17:52:322310 // Notify the observers if an embedded fullscreen widget lost focus.
2311 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
2312 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
2313 NotifyWebContentsLostFocus(render_widget_host);
2314 }
zijiehe3bee08e22017-05-17 04:14:462315}
2316
estaded0a0c992015-01-21 14:12:062317void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:312318 RenderWidgetHostImpl* render_widget_host,
2319 bool width_changed) {
creisc014b402015-04-23 16:41:452320 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:292321 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:062322 return;
estaded0a0c992015-01-21 14:12:062323
ericwilligersde386342016-10-19 02:35:092324 for (auto& observer : observers_)
2325 observer.MainFrameWasResized(width_changed);
estaded0a0c992015-01-21 14:12:062326}
2327
skyf65d9bb2017-03-24 02:26:392328KeyboardEventProcessingResult WebContentsImpl::PreHandleKeyboardEvent(
2329 const NativeWebKeyboardEvent& event) {
W. James MacLeane1187272019-11-12 03:42:482330 auto* outermost_contents = GetOutermostWebContents();
2331 // TODO(wjmaclean): Generalize this to forward all key events to the outermost
2332 // delegate's handler.
2333 if (outermost_contents != this && IsFullscreenForCurrentTab() &&
2334 event.windows_key_code == ui::VKEY_ESCAPE) {
2335 // When an inner WebContents has focus and is fullscreen, redirect <esc>
2336 // key events to the outermost WebContents so it can be handled by that
2337 // WebContents' delegate.
2338 if (outermost_contents->PreHandleKeyboardEvent(event) ==
2339 KeyboardEventProcessingResult::HANDLED) {
2340 return KeyboardEventProcessingResult::HANDLED;
2341 }
2342 }
skyf65d9bb2017-03-24 02:26:392343 return delegate_ ? delegate_->PreHandleKeyboardEvent(this, event)
2344 : KeyboardEventProcessingResult::NOT_HANDLED;
[email protected]63954792011-07-11 04:17:482345}
2346
Dave Tapuska344399e2019-09-09 15:18:262347bool WebContentsImpl::HandleMouseEvent(const blink::WebMouseEvent& event) {
2348 // Handle mouse button back/forward in the browser process after the render
2349 // process is done with the event. This ensures all renderer-initiated history
2350 // navigations can be treated consistently.
2351 if (event.GetType() == blink::WebInputEvent::Type::kMouseUp) {
2352 WebContentsImpl* outermost = GetOutermostWebContents();
2353 if (event.button == blink::WebPointerProperties::Button::kBack &&
2354 outermost->controller_.CanGoBack()) {
2355 outermost->controller_.GoBack();
2356 return true;
2357 } else if (event.button == blink::WebPointerProperties::Button::kForward &&
2358 outermost->controller_.CanGoForward()) {
2359 outermost->controller_.GoForward();
2360 return true;
2361 }
2362 }
2363 return false;
2364}
2365
Scott Violetd5caa872018-10-16 22:00:512366bool WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:102367 if (browser_plugin_embedder_ &&
2368 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
Scott Violetd5caa872018-10-16 22:00:512369 return true;
[email protected]0b094002014-08-20 18:28:102370 }
Scott Violetd5caa872018-10-16 22:00:512371 return delegate_ && delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:482372}
2373
[email protected]d92026ef2014-03-03 21:04:132374bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:462375 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:192376#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:332377 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
2378 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:192379 // -the OS already has a gesture to do this through pinch-zoom
2380 // -if a user starts an inertial scroll, let's go, and presses control
2381 // (i.e. control+tab) then the OS's buffered scroll events will come in
2382 // with control key set which isn't what the user wants
Blink Reformat1c4d759e2017-04-09 16:34:542383 if (delegate_ && event.wheel_ticks_y &&
Ehsan Karamad0f83cb112018-09-06 22:07:362384 event.event_action == blink::WebMouseWheelEvent::EventAction::kPageZoom) {
w.shackleton49bcd392016-01-06 17:38:222385 // Count only integer cumulative scrolls as zoom events; this handles
2386 // smooth scroll and regular scroll device behavior.
Blink Reformat1c4d759e2017-04-09 16:34:542387 zoom_scroll_remainder_ += event.wheel_ticks_y;
w.shackleton49bcd392016-01-06 17:38:222388 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
2389 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
2390 if (whole_zoom_scroll_remainder_ != 0) {
2391 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
2392 }
[email protected]fb3f066e2013-02-12 19:12:522393 return true;
2394 }
[email protected]bccc4472013-04-18 16:37:192395#endif
[email protected]fb3f066e2013-02-12 19:12:522396 return false;
2397}
2398
[email protected]04bce562014-01-30 05:34:542399bool WebContentsImpl::PreHandleGestureEvent(
2400 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:032401 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:542402}
2403
kenrb2a565f82015-09-02 20:24:592404RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:452405 if (!is_being_destroyed_ && GetOuterWebContents())
2406 return GetOuterWebContents()->GetInputEventRouter();
2407
2408 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:592409 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
2410 return rwh_input_event_router_.get();
2411}
2412
alexmos3fcd0ca2015-10-23 18:18:332413void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
2414 // Focus loss may occur while this WebContents is being destroyed. Don't
2415 // send the message in this case, as the main frame's RenderFrameHost and
2416 // other state has already been cleared.
2417 if (is_being_destroyed_)
2418 return;
2419
2420 frame_tree_.ReplicatePageFocus(is_focused);
2421}
2422
alexmosc4cbacb2015-11-21 01:29:222423RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
2424 RenderWidgetHostImpl* receiving_widget) {
alexmosc4cbacb2015-11-21 01:29:222425 // Events for widgets other than the main frame (e.g., popup menus) should be
2426 // forwarded directly to the widget they arrived on.
2427 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
2428 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:522429
lfg1453e412017-04-11 00:48:502430 WebContentsImpl* focused_contents = GetFocusedWebContents();
2431
2432 // If the focused WebContents is showing an interstitial, return the
2433 // interstitial's widget.
2434 if (focused_contents->ShowingInterstitialPage()) {
2435 return static_cast<RenderFrameHostImpl*>(
creisadca9862017-06-16 19:12:112436 focused_contents->interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:502437 ->GetRenderWidgetHost();
2438 }
2439
paulmeyerfeafc2d2017-04-25 21:46:402440 // If the focused WebContents is a guest WebContents, then get the focused
2441 // frame in the embedder WebContents instead.
W. James MacLean13d834d2019-12-04 16:06:452442 FrameTreeNode* focused_frame =
2443 GetFocusedWebContents()->frame_tree_.GetFocusedFrame();
lfg1453e412017-04-11 00:48:502444
alexmosc4d183e2015-11-06 00:46:522445 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:222446 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:522447
alexmos732ca3a2015-12-08 02:01:022448 // The view may be null if a subframe's renderer process has crashed while
2449 // the subframe has focus. Drop the event in that case. Do not give
2450 // it to the main frame, so that the user doesn't unexpectedly type into the
2451 // wrong frame if a focused subframe renderer crashes while they type.
2452 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
2453 if (!view)
2454 return nullptr;
2455
2456 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:522457}
2458
avallee9993fca2016-11-17 06:16:502459RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() {
lfg1453e412017-04-11 00:48:502460 WebContentsImpl* focused_web_contents = GetFocusedWebContents();
2461
2462 if (focused_web_contents->ShowingInterstitialPage()) {
2463 return static_cast<RenderFrameHostImpl*>(
creisadca9862017-06-16 19:12:112464 focused_web_contents->interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:502465 ->GetRenderWidgetHost();
2466 }
2467
2468 return focused_web_contents->GetMainFrame()->GetRenderWidgetHost();
avallee9993fca2016-11-17 06:16:502469}
2470
Dave Tapuska3ed44192018-05-01 18:53:302471void WebContentsImpl::EnterFullscreenMode(
2472 const GURL& origin,
Dave Tapuskaa4189512019-10-15 20:27:342473 const blink::mojom::FullscreenOptions& options) {
mlamouri7a78d6fd2015-01-17 13:23:532474 // This method is being called to enter renderer-initiated fullscreen mode.
2475 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:492476 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:372477 if (widget_view) {
2478 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
2479 ->ShutdownAndDestroyWidget(true);
2480 }
[email protected]4aebbca2013-09-17 22:26:492481
Joe Downing13dd76b2018-04-09 18:32:152482 if (delegate_) {
Dave Tapuska3ed44192018-05-01 18:53:302483 delegate_->EnterFullscreenModeForTab(this, origin, options);
mlamouri7a78d6fd2015-01-17 13:23:532484
Joe Downing13dd76b2018-04-09 18:32:152485 if (keyboard_lock_widget_)
2486 delegate_->RequestKeyboardLock(this, esc_key_locked_);
2487 }
2488
ericwilligersde386342016-10-19 02:35:092489 for (auto& observer : observers_)
2490 observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(), false);
mlamouri7a78d6fd2015-01-17 13:23:532491}
2492
bokanece34a82016-01-28 19:49:462493void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:532494 // This method is being called to leave renderer-initiated fullscreen mode.
2495 // Make sure any existing fullscreen widget is shut down first.
2496 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:372497 if (widget_view) {
2498 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
2499 ->ShutdownAndDestroyWidget(true);
2500 }
mlamouri7a78d6fd2015-01-17 13:23:532501
Joe Downing13dd76b2018-04-09 18:32:152502 if (delegate_) {
mlamouri7a78d6fd2015-01-17 13:23:532503 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:372504
Joe Downing13dd76b2018-04-09 18:32:152505 if (keyboard_lock_widget_)
2506 delegate_->CancelKeyboardLockRequest(this);
2507 }
2508
bokanece34a82016-01-28 19:49:462509 // The fullscreen state is communicated to the renderer through a resize
2510 // message. If the change in fullscreen state doesn't cause a view resize
2511 // then we must ensure web contents exit the fullscreen state by explicitly
2512 // sending a resize message. This is required for the situation of the browser
2513 // moving the view into a "browser fullscreen" state and then the contents
2514 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
2515 // have the side effect of the view resizing, hence the explicit call here is
2516 // required.
2517 if (!will_cause_resize) {
2518 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
2519 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
Fady Samuel0b911822018-04-25 13:22:162520 render_widget_host->SynchronizeVisualProperties();
bokanece34a82016-01-28 19:49:462521 }
scheib3dcb6c932015-02-23 10:55:582522 }
2523
Arthur Sonzogni929d29f2018-09-17 14:19:442524 current_fullscreen_frame_ = nullptr;
Becca Hughese9e27952018-06-25 17:08:272525
ericwilligersde386342016-10-19 02:35:092526 for (auto& observer : observers_) {
2527 observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(),
2528 will_cause_resize);
2529 }
Becca Hughesd11d6502018-07-31 17:01:282530
2531 if (display_cutout_host_impl_)
2532 display_cutout_host_impl_->DidExitFullscreen();
[email protected]8a5e0ca2011-08-25 06:30:472533}
2534
Becca Hughesfd5d8f892018-06-14 18:23:362535void WebContentsImpl::FullscreenStateChanged(RenderFrameHost* rfh,
2536 bool is_fullscreen) {
Arthur Sonzogni929d29f2018-09-17 14:19:442537 RenderFrameHostImpl* frame = static_cast<RenderFrameHostImpl*>(rfh);
Becca Hughesfd5d8f892018-06-14 18:23:362538
2539 if (is_fullscreen) {
Jan Wilken Dörrie531be7ca2019-06-07 10:05:572540 if (!base::Contains(fullscreen_frames_, frame)) {
Arthur Sonzogni929d29f2018-09-17 14:19:442541 fullscreen_frames_.insert(frame);
2542 FullscreenFrameSetUpdated();
Becca Hughesfd5d8f892018-06-14 18:23:362543 }
Arthur Sonzogni929d29f2018-09-17 14:19:442544 return;
2545 }
Becca Hughesfd5d8f892018-06-14 18:23:362546
Arthur Sonzogni929d29f2018-09-17 14:19:442547 // If |frame| is no longer in fullscreen, remove it and any descendants.
2548 // See https://fullscreen.spec.whatwg.org.
Arthur Sonzogni969a794e2018-10-11 08:56:092549 size_t size_before_deletion = fullscreen_frames_.size();
2550 base::EraseIf(fullscreen_frames_, [&](RenderFrameHostImpl* current) {
2551 return (current == frame || current->IsDescendantOf(frame));
Arthur Sonzogni929d29f2018-09-17 14:19:442552 });
2553
Arthur Sonzogni969a794e2018-10-11 08:56:092554 if (size_before_deletion != fullscreen_frames_.size())
Arthur Sonzogni929d29f2018-09-17 14:19:442555 FullscreenFrameSetUpdated();
2556}
2557
2558void WebContentsImpl::FullscreenFrameSetUpdated() {
2559 if (fullscreen_frames_.empty()) {
2560 current_fullscreen_frame_ = nullptr;
2561 return;
Becca Hughesfd5d8f892018-06-14 18:23:362562 }
2563
Arthur Sonzogni929d29f2018-09-17 14:19:442564 // Find the current fullscreen frame and call the observers.
2565 // If frame A is fullscreen, then frame B goes into inner fullscreen, then B
2566 // exits fullscreen - that will result in A being fullscreen.
2567 RenderFrameHostImpl* new_fullscreen_frame = *std::max_element(
2568 fullscreen_frames_.begin(), fullscreen_frames_.end(), FrameCompareDepth);
Becca Hughesfd5d8f892018-06-14 18:23:362569
Arthur Sonzogni929d29f2018-09-17 14:19:442570 // If we have already notified observers about this frame then we should not
2571 // fire the observers again.
2572 if (new_fullscreen_frame == current_fullscreen_frame_)
2573 return;
2574 current_fullscreen_frame_ = new_fullscreen_frame;
Becca Hughesfd5d8f892018-06-14 18:23:362575
Arthur Sonzogni929d29f2018-09-17 14:19:442576 for (auto& observer : observers_)
2577 observer.DidAcquireFullscreen(new_fullscreen_frame);
Becca Hughesfd5d8f892018-06-14 18:23:362578
Arthur Sonzogni929d29f2018-09-17 14:19:442579 if (display_cutout_host_impl_)
2580 display_cutout_host_impl_->DidAcquireFullscreen(new_fullscreen_frame);
Becca Hughesfd5d8f892018-06-14 18:23:362581}
2582
Collin Baker989e0882019-11-01 01:27:172583void WebContentsImpl::UpdateVisibilityAndNotifyPageAndView(
2584 Visibility new_visibility) {
Collin Baker989e0882019-11-01 01:27:172585 // Only hide the page if there are no entities capturing screenshots
Collin Bakerc5259962019-11-14 17:51:582586 // or video (e.g. mirroring). If there are, apply the correct state of
2587 // kHidden or kHiddenButPainting.
2588 PageVisibilityState page_visibility;
2589 if (new_visibility == Visibility::VISIBLE || visible_capturer_count_ > 0)
2590 page_visibility = PageVisibilityState::kVisible;
2591 else if (hidden_capturer_count_ > 0)
2592 page_visibility = PageVisibilityState::kHiddenButPainting;
2593 else
2594 page_visibility = PageVisibilityState::kHidden;
Collin Baker989e0882019-11-01 01:27:172595 // If there are entities in Picture-in-Picture mode, don't activate
2596 // the "disable rendering" optimization.
Collin Bakerc5259962019-11-14 17:51:582597 const bool view_is_visible =
2598 page_visibility != PageVisibilityState::kHidden ||
2599 HasPictureInPictureVideo();
Collin Baker989e0882019-11-01 01:27:172600
Collin Bakerc5259962019-11-14 17:51:582601 if (page_visibility != PageVisibilityState::kHidden) {
Dana Friedcf3bc8e2019-11-13 20:00:242602 // We cannot show a page or capture video unless there is a valid renderer
2603 // associated with this web contents. The navigation controller for this
2604 // page must be set to active (allowing navigation to complete, a renderer
2605 // and its associated views to be created, etc.) if any of these conditions
2606 // holds.
2607 //
2608 // Previously, it was possible for browser-side code to try to capture video
2609 // from a restored tab (for a variety of reasons, including the browser
2610 // creating preview thumbnails) and the tab would never actually load. By
Collin Bakerc5259962019-11-14 17:51:582611 // keying this behavior off of |page_visibility| instead of just
Dana Friedcf3bc8e2019-11-13 20:00:242612 // |new_visibility| we avoid this case. See crbug.com/1020782 for more
2613 // context.
2614 controller_.SetActive(true);
2615
2616 // This shows the Page before showing the individual RenderWidgets, as
2617 // RenderWidgets will work to produce compositor frames and handle input
2618 // as soon as they are shown. But the Page and other classes do not expect
2619 // to be producing frames when the Page is hidden. So we make sure the Page
2620 // is shown first.
Collin Bakerc5259962019-11-14 17:51:582621 SendPageMessage(
2622 new PageMsg_VisibilityChanged(MSG_ROUTING_NONE, page_visibility));
Collin Baker98457b52019-11-06 21:34:292623 }
Collin Baker989e0882019-11-01 01:27:172624
2625 // |GetRenderWidgetHostView()| can be null if the user middle clicks a link to
2626 // open a tab in the background, then closes the tab before selecting it.
2627 // This is because closing the tab calls WebContentsImpl::Destroy(), which
2628 // removes the |GetRenderViewHost()|; then when we actually destroy the
2629 // window, OnWindowPosChanged() notices and calls WasHidden() (which
2630 // calls us).
2631 if (auto* view = GetRenderWidgetHostView()) {
2632 if (view_is_visible) {
2633 view->Show();
Collin Baker989e0882019-11-01 01:27:172634 } else if (new_visibility == Visibility::HIDDEN) {
2635 view->Hide();
2636 } else {
2637 view->WasOccluded();
2638 }
2639 }
2640
2641 if (!ShowingInterstitialPage())
2642 SetVisibilityForChildViews(view_is_visible);
2643
2644 // Make sure to call SetVisibilityAndNotifyObservers(VISIBLE) before notifying
2645 // the CrossProcessFrameConnector.
2646 if (new_visibility == Visibility::VISIBLE) {
2647 last_active_time_ = base::TimeTicks::Now();
2648 SetVisibilityAndNotifyObservers(new_visibility);
2649 }
2650
Collin Bakerc5259962019-11-14 17:51:582651 if (page_visibility == PageVisibilityState::kHidden) {
Collin Baker989e0882019-11-01 01:27:172652 // Similar to when showing the page, we only hide the page after
2653 // hiding the individual RenderWidgets.
Collin Baker98457b52019-11-06 21:34:292654 SendPageMessage(new PageMsg_VisibilityChanged(
2655 MSG_ROUTING_NONE, PageVisibilityState::kHidden));
Collin Baker989e0882019-11-01 01:27:172656 } else {
2657 for (FrameTreeNode* node : frame_tree_.Nodes()) {
2658 RenderFrameProxyHost* parent = node->render_manager()->GetProxyToParent();
2659 if (!parent)
2660 continue;
2661
2662 parent->cross_process_frame_connector()->DelegateWasShown();
2663 }
2664 }
2665
2666 if (new_visibility != Visibility::VISIBLE)
2667 SetVisibilityAndNotifyObservers(new_visibility);
2668}
2669
Clark DuValla0e42992018-09-17 17:00:112670#if defined(OS_ANDROID)
2671void WebContentsImpl::UpdateUserGestureCarryoverInfo() {
2672 if (delegate_)
2673 delegate_->UpdateUserGestureCarryoverInfo(this);
2674}
2675#endif
2676
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:412677bool WebContentsImpl::IsFullscreenForCurrentTab() {
[email protected]199bba6e2012-04-04 16:19:382678 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:122679}
2680
Malay Keshav87c42c02019-01-15 08:37:472681bool WebContentsImpl::ShouldShowStaleContentOnEviction() {
2682 return GetDelegate() && GetDelegate()->ShouldShowStaleContentOnEviction(this);
2683}
2684
billorr21c005d2016-11-17 03:57:042685bool WebContentsImpl::IsFullscreen() {
2686 return IsFullscreenForCurrentTab();
2687}
2688
Eric Willigers052f0432019-10-04 04:06:572689blink::mojom::DisplayMode WebContentsImpl::GetDisplayMode(
avibf58fa0c2015-11-11 01:45:522690 RenderWidgetHostImpl* render_widget_host) const {
2691 if (!RenderViewHostImpl::From(render_widget_host))
Eric Willigers052f0432019-10-04 04:06:572692 return blink::mojom::DisplayMode::kBrowser;
avibf58fa0c2015-11-11 01:45:522693
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122694 return delegate_ ? delegate_->GetDisplayMode(this)
Eric Willigers052f0432019-10-04 04:06:572695 : blink::mojom::DisplayMode::kBrowser;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122696}
2697
avic3aa8422015-11-09 20:57:222698void WebContentsImpl::RequestToLockMouse(
2699 RenderWidgetHostImpl* render_widget_host,
2700 bool user_gesture,
lfgad8244352016-07-13 16:55:512701 bool last_unlocked_by_target,
2702 bool privileged) {
lfgf0cd46e2017-01-04 00:05:232703 for (WebContentsImpl* current = this; current;
2704 current = current->GetOuterWebContents()) {
2705 if (current->mouse_lock_widget_) {
2706 render_widget_host->GotResponseToLockMouseRequest(false);
2707 return;
2708 }
[email protected]e9621112011-10-17 05:38:372709 }
avic3aa8422015-11-09 20:57:222710
lfgad8244352016-07-13 16:55:512711 if (privileged) {
lfgf0cd46e2017-01-04 00:05:232712 DCHECK(!GetOuterWebContents());
lfgad8244352016-07-13 16:55:512713 mouse_lock_widget_ = render_widget_host;
2714 render_widget_host->GotResponseToLockMouseRequest(true);
2715 return;
2716 }
2717
lfgbee1e0a2016-06-08 21:24:212718 bool widget_in_frame_tree = false;
2719 for (FrameTreeNode* node : frame_tree_.Nodes()) {
2720 if (node->current_frame_host()->GetRenderWidgetHost() ==
2721 render_widget_host) {
2722 widget_in_frame_tree = true;
2723 break;
2724 }
2725 }
2726
2727 if (widget_in_frame_tree && delegate_) {
lfgf0cd46e2017-01-04 00:05:232728 for (WebContentsImpl* current = this; current;
2729 current = current->GetOuterWebContents()) {
2730 current->mouse_lock_widget_ = render_widget_host;
2731 }
2732
avic3aa8422015-11-09 20:57:222733 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
lfgbee1e0a2016-06-08 21:24:212734 } else {
2735 render_widget_host->GotResponseToLockMouseRequest(false);
2736 }
[email protected]e9621112011-10-17 05:38:372737}
2738
avi3e4b8512015-11-11 01:55:492739void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
lfgbee1e0a2016-06-08 21:24:212740 CHECK(mouse_lock_widget_);
lfgf0cd46e2017-01-04 00:05:232741
2742 if (mouse_lock_widget_->delegate()->GetAsWebContents() != this)
2743 return mouse_lock_widget_->delegate()->LostMouseLock(render_widget_host);
2744
lfgbee1e0a2016-06-08 21:24:212745 mouse_lock_widget_->SendMouseLockLost();
lfgf0cd46e2017-01-04 00:05:232746 for (WebContentsImpl* current = this; current;
2747 current = current->GetOuterWebContents()) {
2748 current->mouse_lock_widget_ = nullptr;
2749 }
avi3e4b8512015-11-11 01:55:492750
[email protected]e9621112011-10-17 05:38:372751 if (delegate_)
2752 delegate_->LostMouseLock();
2753}
2754
lfgad8244352016-07-13 16:55:512755bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) {
2756 // To verify if the mouse is locked, the mouse_lock_widget_ needs to be
2757 // assigned to the widget that requested the mouse lock, and the top-level
2758 // platform RenderWidgetHostView needs to hold the mouse lock from the OS.
Lucas Gadania0ea0172018-09-20 18:31:372759 auto* widget_host = GetTopLevelRenderWidgetHostView();
2760 return mouse_lock_widget_ == render_widget_host && widget_host &&
2761 widget_host->IsMouseLocked();
lfgad8244352016-07-13 16:55:512762}
2763
lfg84763c92017-02-16 18:55:152764RenderWidgetHostImpl* WebContentsImpl::GetMouseLockWidget() {
Lucas Gadania0ea0172018-09-20 18:31:372765 auto* widget_host = GetTopLevelRenderWidgetHostView();
2766 if ((widget_host && widget_host->IsMouseLocked()) ||
lfge2176fb2017-03-26 00:45:472767 (GetFullscreenRenderWidgetHostView() &&
Lucas Gadania0ea0172018-09-20 18:31:372768 GetFullscreenRenderWidgetHostView()->IsMouseLocked())) {
lfg84763c92017-02-16 18:55:152769 return mouse_lock_widget_;
Lucas Gadania0ea0172018-09-20 18:31:372770 }
lfg84763c92017-02-16 18:55:152771
2772 return nullptr;
2773}
2774
Joe Downing192998b22018-03-22 15:51:362775bool WebContentsImpl::RequestKeyboardLock(
Joe Downing13dd76b2018-04-09 18:32:152776 RenderWidgetHostImpl* render_widget_host,
2777 bool esc_key_locked) {
Joe Downing192998b22018-03-22 15:51:362778 DCHECK(render_widget_host);
Joe Downing192998b22018-03-22 15:51:362779 if (render_widget_host->delegate()->GetAsWebContents() != this) {
2780 NOTREACHED();
2781 return false;
2782 }
2783
2784 // KeyboardLock is only supported when called by the top-level browsing
2785 // context and is not supported in embedded content scenarios.
2786 if (GetOuterWebContents())
2787 return false;
2788
Joe Downing13dd76b2018-04-09 18:32:152789 esc_key_locked_ = esc_key_locked;
Joe Downing192998b22018-03-22 15:51:362790 keyboard_lock_widget_ = render_widget_host;
2791
Joe Downing13dd76b2018-04-09 18:32:152792 if (delegate_)
2793 delegate_->RequestKeyboardLock(this, esc_key_locked_);
Joe Downing192998b22018-03-22 15:51:362794 return true;
2795}
2796
2797void WebContentsImpl::CancelKeyboardLock(
2798 RenderWidgetHostImpl* render_widget_host) {
2799 if (!keyboard_lock_widget_ || render_widget_host != keyboard_lock_widget_)
2800 return;
2801
2802 RenderWidgetHostImpl* old_keyboard_lock_widget = keyboard_lock_widget_;
2803 keyboard_lock_widget_ = nullptr;
2804
Joe Downing13dd76b2018-04-09 18:32:152805 if (delegate_)
2806 delegate_->CancelKeyboardLockRequest(this);
2807
Joe Downing192998b22018-03-22 15:51:362808 old_keyboard_lock_widget->CancelKeyboardLock();
2809}
2810
2811RenderWidgetHostImpl* WebContentsImpl::GetKeyboardLockWidget() {
2812 return keyboard_lock_widget_;
2813}
2814
Dave Tapuskac3344362019-02-20 17:54:282815void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(
2816 blink::mojom::FrameVisibility visibility) {
2817 switch (visibility) {
2818 case blink::mojom::FrameVisibility::kRenderedInViewport:
2819 WasShown();
2820 break;
2821 case blink::mojom::FrameVisibility::kNotRendered:
2822 WasHidden();
2823 break;
2824 case blink::mojom::FrameVisibility::kRenderedOutOfViewport:
2825 WasOccluded();
2826 break;
2827 }
ekaramada4f42692016-02-11 19:48:372828}
2829
Albert J. Wong65fe64d2019-09-20 02:48:142830RenderFrameHostDelegate* WebContentsImpl::CreateNewWindow(
csharrison95f01e922017-04-24 18:52:352831 RenderFrameHost* opener,
rockot5c478a72016-09-28 23:14:182832 const mojom::CreateNewWindowParams& params,
Albert J. Wong65fe64d2019-09-20 02:48:142833 bool is_new_browsing_instance,
Sergey Kuznetsov32257a22019-02-11 20:26:502834 bool has_user_gesture,
[email protected]97714c82012-06-06 10:15:132835 SessionStorageNamespace* session_storage_namespace) {
csharrison95f01e922017-04-24 18:52:352836 DCHECK(opener);
nick5ae4d2d2017-01-06 01:18:352837
csharrison95f01e922017-04-24 18:52:352838 int render_process_id = opener->GetProcess()->GetID();
csharrison95f01e922017-04-24 18:52:352839
Albert J. Wong65fe64d2019-09-20 02:48:142840 SiteInstance* source_site_instance = opener->GetSiteInstance();
nick5ae4d2d2017-01-06 01:18:352841
Aaron Colwelleb219982020-01-16 02:17:272842 const GURL source_site_url = source_site_instance->GetSiteURL();
[email protected]fdac6ade2013-07-20 01:06:302843 const std::string& partition_id =
Aaron Colwelleb219982020-01-16 02:17:272844 GetContentClient()->browser()->GetStoragePartitionIdForSite(
2845 GetBrowserContext(), source_site_url);
2846 {
2847 StoragePartition* partition = BrowserContext::GetStoragePartitionForSite(
2848 GetBrowserContext(), source_site_url);
2849 DOMStorageContextWrapper* dom_storage_context =
2850 static_cast<DOMStorageContextWrapper*>(
2851 partition->GetDOMStorageContext());
2852 SessionStorageNamespaceImpl* session_storage_namespace_impl =
2853 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
2854 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
2855 }
[email protected]dd6730412013-08-14 15:03:372856
Albert J. Wong1ceccef92019-10-08 08:25:202857 if (delegate_ && delegate_->IsWebContentsCreationOverridden(
2858 source_site_instance, params.window_container_type,
2859 opener->GetLastCommittedURL(), params.frame_name,
2860 params.target_url)) {
2861 return static_cast<WebContentsImpl*>(delegate_->CreateCustomWebContents(
2862 opener, source_site_instance, is_new_browsing_instance,
2863 opener->GetLastCommittedURL(), params.frame_name, params.target_url,
2864 partition_id, session_storage_namespace));
[email protected]dd6730412013-08-14 15:03:372865 }
2866
danakj22b4e8b2019-08-01 23:14:392867 bool renderer_started_hidden =
2868 params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB;
2869
Aaron Colwelleb219982020-01-16 02:17:272870 // We usually create the new window in the same BrowsingInstance (group of
2871 // script-related windows), by passing in the current SiteInstance. However,
2872 // if the opener is being suppressed (in a non-guest), we do not provide
2873 // a SiteInstance which causes a new one to get created in its own
2874 // BrowsingInstance.
2875 bool is_guest = BrowserPluginGuest::IsGuest(this);
2876 scoped_refptr<SiteInstance> site_instance =
2877 params.opener_suppressed && !is_guest ? nullptr : source_site_instance;
2878
[email protected]dd6730412013-08-14 15:03:372879 // Create the new web contents. This will automatically create the new
2880 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:462881 CreateParams create_params(GetBrowserContext(), site_instance.get());
nasko48321ca32015-07-02 20:44:122882 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:432883 create_params.opener_render_process_id = render_process_id;
csharrison95f01e922017-04-24 18:52:352884 create_params.opener_render_frame_id = opener->GetRoutingID();
[email protected]50d326e2014-05-20 17:59:062885 create_params.opener_suppressed = params.opener_suppressed;
danakj22b4e8b2019-08-01 23:14:392886 create_params.initially_hidden = renderer_started_hidden;
[email protected]50d326e2014-05-20 17:59:062887
Albert J. Wong65fe64d2019-09-20 02:48:142888 // Even though all codepaths leading here are in response to a renderer
2889 // tryng to open a new window, if the new window ends up in a different
2890 // browsing instance, then the RenderViewHost, RenderWidgetHost,
2891 // RenderFrameHost constellation is effectively browser initiated
2892 // the opener's process will not given the routing IDs for the new
2893 // objects.
2894 create_params.renderer_initiated_creation = !is_new_browsing_instance;
Albert J. Wong1ceccef92019-10-08 08:25:202895
2896 // If |is_new_browsing_instance| is true, defer routing_id allocation
2897 // to the WebContentsImpl::Create() call. This is required because with
2898 // a new browsing instance, WebContentsImpl::Create() may elect a different
2899 // SiteInstance from |site_instance| (which happens if |site_instance| is
2900 // nullptr for example).
2901 //
2902 // TODO(ajwong): This routing id allocation should be pushed down further
2903 // into WebContentsImpl::Create().
2904 if (!is_new_browsing_instance) {
2905 create_params.routing_id = opener->GetProcess()->GetNextRoutingID();
2906 create_params.main_frame_routing_id =
2907 opener->GetProcess()->GetNextRoutingID();
2908 create_params.main_frame_widget_routing_id =
2909 opener->GetProcess()->GetNextRoutingID();
2910 }
Albert J. Wong65fe64d2019-09-20 02:48:142911
2912 std::unique_ptr<WebContentsImpl> new_contents;
[email protected]c4538072013-03-18 02:17:552913 if (!is_guest) {
2914 create_params.context = view_->GetNativeView();
Albert J. Wong65fe64d2019-09-20 02:48:142915 new_contents = WebContentsImpl::Create(create_params);
2916 } else {
2917 new_contents = base::WrapUnique(static_cast<WebContentsImpl*>(
2918 GetBrowserPluginGuest()->CreateNewGuestWindow(create_params)));
[email protected]c4538072013-03-18 02:17:552919 }
Albert J. Wong65fe64d2019-09-20 02:48:142920 auto* new_contents_impl = new_contents.get();
danakje6c01622018-10-05 19:39:262921
2922 new_contents_impl->GetController().SetSessionStorageNamespace(
erikchenbee5c9622018-04-27 19:30:252923 partition_id, session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:192924
alexmos646fec02015-07-25 00:11:492925 // If the new frame has a name, make sure any SiteInstances that can find
2926 // this named frame have proxies for it. Must be called after
2927 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
2928 // GetSessionStorageNamespace.
2929 if (!params.frame_name.empty())
danakje6c01622018-10-05 19:39:262930 new_contents_impl->GetRenderManager()->CreateProxiesForNewNamedFrame();
alexmos646fec02015-07-25 00:11:492931
[email protected]c4538072013-03-18 02:17:552932 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:342933 // will be shown immediately).
2934 if (!params.opener_suppressed) {
2935 if (!is_guest) {
danakje6c01622018-10-05 19:39:262936 WebContentsView* new_view = new_contents_impl->view_.get();
[email protected]bafe6cd2012-05-23 23:09:502937
[email protected]d70bea92013-04-05 04:23:342938 // TODO(brettw): It seems bogus that we have to call this function on the
2939 // newly created object and give it one of its own member variables.
danakj22b4e8b2019-08-01 23:14:392940 RenderWidgetHostView* widget_view = new_view->CreateViewForWidget(
W. James MacLean13d834d2019-12-04 16:06:452941 new_contents_impl->GetRenderViewHost()->GetWidget());
danakj22b4e8b2019-08-01 23:14:392942 if (!renderer_started_hidden) {
2943 // RenderWidgets for frames always initialize as hidden. If the renderer
2944 // created this window as visible, then we show it here.
2945 widget_view->Show();
2946 }
[email protected]d70bea92013-04-05 04:23:342947 }
[email protected]bafe6cd2012-05-23 23:09:502948 // Save the created window associated with the route so we can show it
2949 // later.
Albert J. Wongcb004632018-07-10 22:58:252950 //
2951 // TODO(ajwong): This should be keyed off the RenderFrame routing id or the
2952 // FrameTreeNode id instead of the routing id of the Widget for the main
2953 // frame. https://crbug.com/545684
Albert J. Wong1ceccef92019-10-08 08:25:202954 DCHECK_NE(MSG_ROUTING_NONE, create_params.main_frame_routing_id);
2955 GlobalRoutingID id(render_process_id,
2956 create_params.main_frame_widget_routing_id);
Albert J. Wong65fe64d2019-09-20 02:48:142957 pending_contents_[id] = std::move(new_contents);
danakje6c01622018-10-05 19:39:262958 AddDestructionObserver(new_contents_impl);
[email protected]bafe6cd2012-05-23 23:09:502959 }
2960
2961 if (delegate_) {
Bryan McQuaded2b93c02017-07-14 22:26:312962 delegate_->WebContentsCreated(this, render_process_id,
2963 opener->GetRoutingID(), params.frame_name,
danakje6c01622018-10-05 19:39:262964 params.target_url, new_contents_impl);
[email protected]bafe6cd2012-05-23 23:09:502965 }
2966
Charlie Harrisonf60dd1c2018-08-15 21:15:412967 for (auto& observer : observers_) {
danakje6c01622018-10-05 19:39:262968 observer.DidOpenRequestedURL(new_contents_impl, opener, params.target_url,
Leon Han963dc182018-11-06 05:41:482969 params.referrer.To<Referrer>(),
2970 params.disposition, ui::PAGE_TRANSITION_LINK,
Charlie Harrisonf60dd1c2018-08-15 21:15:412971 false, // started_from_context_menu
2972 true); // renderer_initiated
pnolandaae574e2017-03-06 21:04:212973 }
2974
Avi Drissmanba3b1b342017-08-29 18:16:132975 // Any new WebContents opened while this WebContents is in fullscreen can be
2976 // used to confuse the user, so drop fullscreen.
Avi Drissmand18c51972018-08-15 18:32:092977 ForSecurityDropFullscreen();
Avi Drissmanba3b1b342017-08-29 18:16:132978
[email protected]bafe6cd2012-05-23 23:09:502979 if (params.opener_suppressed) {
2980 // When the opener is suppressed, the original renderer cannot access the
2981 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:002982 bool was_blocked = false;
erikchenbee5c9622018-04-27 19:30:252983
[email protected]eda238a12012-09-07 23:44:002984 if (delegate_) {
danakje6c01622018-10-05 19:39:262985 base::WeakPtr<WebContentsImpl> weak_new_contents =
2986 new_contents_impl->weak_factory_.GetWeakPtr();
nick0d558482017-02-13 22:27:222987
danakje6c01622018-10-05 19:39:262988 gfx::Rect initial_rect; // Report an empty initial rect.
Albert J. Wong65fe64d2019-09-20 02:48:142989 delegate_->AddNewContents(this, std::move(new_contents),
erikchenbee5c9622018-04-27 19:30:252990 params.disposition, initial_rect,
Sergey Kuznetsov32257a22019-02-11 20:26:502991 has_user_gesture, &was_blocked);
danakje6c01622018-10-05 19:39:262992 // The delegate may delete |new_contents_impl| during AddNewContents().
nick0d558482017-02-13 22:27:222993 if (!weak_new_contents)
Albert J. Wong65fe64d2019-09-20 02:48:142994 return nullptr;
[email protected]eda238a12012-09-07 23:44:002995 }
erikchenbee5c9622018-04-27 19:30:252996
[email protected]eda238a12012-09-07 23:44:002997 if (!was_blocked) {
Nasko Oskov83a8cf92018-10-19 14:58:562998 std::unique_ptr<NavigationController::LoadURLParams> load_params =
2999 std::make_unique<NavigationController::LoadURLParams>(
3000 params.target_url);
Nasko Oskov93e7c55c2018-12-19 01:59:293001 load_params->initiator_origin = opener->GetLastCommittedOrigin();
Aaron Colwell9dab1652019-12-09 18:29:493002 load_params->source_site_instance = source_site_instance;
Leon Han963dc182018-11-06 05:41:483003 load_params->referrer = params.referrer.To<Referrer>();
Nasko Oskov83a8cf92018-10-19 14:58:563004 load_params->transition_type = ui::PAGE_TRANSITION_LINK;
3005 load_params->is_renderer_initiated = true;
Sergey Kuznetsov32257a22019-02-11 20:26:503006 load_params->has_user_gesture = has_user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:373007
3008 if (delegate_ && !is_guest &&
3009 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
Nasko Oskov83a8cf92018-10-19 14:58:563010 // We are in asynchronous add new contents path, delay navigation.
3011 DCHECK(!new_contents_impl->delayed_open_url_params_);
3012 new_contents_impl->delayed_load_url_params_ = std::move(load_params);
mariakhomenkoa4971c12015-07-21 19:04:373013 } else {
Nasko Oskov83a8cf92018-10-19 14:58:563014 new_contents_impl->controller_.LoadURLWithParams(*load_params.get());
Nasko Oskov28ebd5b2018-12-07 22:29:333015 if (!is_guest)
3016 new_contents_impl->Focus();
mariakhomenkoa4971c12015-07-21 19:04:373017 }
[email protected]eda238a12012-09-07 23:44:003018 }
[email protected]bafe6cd2012-05-23 23:09:503019 }
Albert J. Wong65fe64d2019-09-20 02:48:143020 return new_contents_impl;
[email protected]bafe6cd2012-05-23 23:09:503021}
3022
Erik Chenc71b51fe2019-09-19 21:34:273023void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
3024 int32_t widget_route_id,
3025 mojo::PendingRemote<mojom::Widget> widget,
3026 RenderViewHostImpl* render_view_host) {
Albert J. Wongf6e13ed2018-09-18 15:25:473027 CreateNewWidget(render_process_id, widget_route_id, /*is_fullscreen=*/false,
Erik Chenc71b51fe2019-09-19 21:34:273028 std::move(widget), render_view_host);
[email protected]bafe6cd2012-05-23 23:09:503029}
3030
Julie Jeongeun Kimcaacf9102019-09-12 02:13:053031void WebContentsImpl::CreateNewFullscreenWidget(
3032 int32_t render_process_id,
3033 int32_t widget_route_id,
Erik Chenc71b51fe2019-09-19 21:34:273034 mojo::PendingRemote<mojom::Widget> widget,
3035 RenderViewHostImpl* render_view_host) {
Albert J. Wongf6e13ed2018-09-18 15:25:473036 CreateNewWidget(render_process_id, widget_route_id, /*is_fullscreen=*/true,
Erik Chenc71b51fe2019-09-19 21:34:273037 std::move(widget), render_view_host);
[email protected]bafe6cd2012-05-23 23:09:503038}
3039
Erik Chenc71b51fe2019-09-19 21:34:273040void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
3041 int32_t route_id,
3042 bool is_fullscreen,
3043 mojo::PendingRemote<mojom::Widget> widget,
3044 RenderViewHostImpl* render_view_host) {
kenrba26d15092016-02-10 22:00:253045 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
kenrbb46f86a2015-12-07 07:53:233046 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:513047 // this WebContentsImpl instance. If any other process sends the request,
3048 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:383049 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
Lukasz Anforowicz6f746282018-01-04 23:24:513050 ReceivedBadMessage(process, bad_message::WCI_NEW_WIDGET_PROCESS_MISMATCH);
[email protected]a8504022013-12-04 20:23:513051 return;
3052 }
3053
Dave Tapuska485aca92017-08-08 00:47:583054 RenderWidgetHostImpl* widget_host = new RenderWidgetHostImpl(
David Black9cca3592019-11-06 23:02:223055 this, process, route_id, std::move(widget), IsHidden(),
3056 std::make_unique<FrameTokenMessageQueue>());
[email protected]cfd80b02014-05-01 17:46:483057 RenderWidgetHostViewBase* widget_view =
3058 static_cast<RenderWidgetHostViewBase*>(
danakj0b246942018-09-17 21:30:273059 view_->CreateViewForChildWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:193060 if (!widget_view)
3061 return;
danakj0b246942018-09-17 21:30:273062 // Fullscreen child widgets are frames, other child widgets are popups, and
3063 // popups should not get activated.
3064 if (!is_fullscreen)
3065 widget_view->SetWidgetType(WidgetType::kPopup);
[email protected]bafe6cd2012-05-23 23:09:503066 // Save the created widget associated with the route so we can show it later.
Lukasz Anforowicz09060bdf72018-08-23 15:53:173067 pending_widget_views_[GlobalRoutingID(render_process_id, route_id)] =
alexmosc2a8cec2016-05-23 22:19:533068 widget_view;
[email protected]bafe6cd2012-05-23 23:09:503069}
3070
alexmosc2a8cec2016-05-23 22:19:533071void WebContentsImpl::ShowCreatedWindow(int process_id,
nick5ae4d2d2017-01-06 01:18:353072 int main_frame_widget_route_id,
[email protected]bafe6cd2012-05-23 23:09:503073 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:393074 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:503075 bool user_gesture) {
danakje6c01622018-10-05 19:39:263076 // This method is the renderer requesting an existing top level window to
3077 // show a new top level window that the renderer created. Each top level
3078 // window is associated with a WebContents. In this case it was created
3079 // earlier but showing it was deferred until the renderer requested for it
3080 // to be shown. We find that previously created WebContents here.
3081 // TODO(danakj): Why do we defer this show step until the renderer asks for it
3082 // when it will always do so. What needs to happen in the renderer before we
3083 // reach here?
3084 std::unique_ptr<WebContentsImpl> owned_created =
nick5ae4d2d2017-01-06 01:18:353085 GetCreatedWindow(process_id, main_frame_widget_route_id);
danakje6c01622018-10-05 19:39:263086 WebContentsImpl* created = owned_created.get();
3087 // The browser may have rejected the request to make a new window, or the
3088 // renderer could be sending an invalid route id. Ignore the request then.
3089 if (!created)
3090 return;
mariakhomenko44bdc4732015-04-29 01:55:383091
danakje6c01622018-10-05 19:39:263092 // This uses the delegate for the WebContents where the window was created
3093 // from, to control how to show the newly created window.
3094 WebContentsDelegate* delegate = GetDelegate();
nick5ae4d2d2017-01-06 01:18:353095
danakje6c01622018-10-05 19:39:263096 // The delegate can be null in tests, so we must check for it :(.
3097 if (delegate) {
3098 // Mark the web contents as pending resume, then immediately do
3099 // the resume if the delegate wants it.
3100 created->is_resume_pending_ = true;
3101 if (delegate->ShouldResumeRequestsForCreatedWindow())
3102 created->ResumeLoadingCreatedWebContents();
3103
3104 base::WeakPtr<WebContentsImpl> weak_created =
3105 created->weak_factory_.GetWeakPtr();
3106 delegate->AddNewContents(this, std::move(owned_created), disposition,
3107 initial_rect, user_gesture, nullptr);
3108 // The delegate may delete |created| during AddNewContents().
3109 if (!weak_created)
3110 return;
[email protected]eda238a12012-09-07 23:44:003111 }
danakje6c01622018-10-05 19:39:263112
3113 RenderWidgetHostImpl* rwh = created->GetMainFrame()->GetRenderWidgetHost();
3114 DCHECK_EQ(main_frame_widget_route_id, rwh->GetRoutingID());
3115 rwh->Send(new WidgetMsg_SetBounds_ACK(rwh->GetRoutingID()));
[email protected]bafe6cd2012-05-23 23:09:503116}
3117
alexmosc2a8cec2016-05-23 22:19:533118void WebContentsImpl::ShowCreatedWidget(int process_id,
Albert J. Wongf6e13ed2018-09-18 15:25:473119 int widget_route_id,
bokan107a47f2015-02-03 23:23:393120 const gfx::Rect& initial_rect) {
Albert J. Wongf6e13ed2018-09-18 15:25:473121 ShowCreatedWidget(process_id, widget_route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:503122}
3123
alexmosc2a8cec2016-05-23 22:19:533124void WebContentsImpl::ShowCreatedFullscreenWidget(int process_id,
Albert J. Wongf6e13ed2018-09-18 15:25:473125 int widget_route_id) {
3126 ShowCreatedWidget(process_id, widget_route_id, true, gfx::Rect());
[email protected]bafe6cd2012-05-23 23:09:503127}
3128
alexmosc2a8cec2016-05-23 22:19:533129void WebContentsImpl::ShowCreatedWidget(int process_id,
3130 int route_id,
[email protected]bafe6cd2012-05-23 23:09:503131 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:393132 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:483133 RenderWidgetHostViewBase* widget_host_view =
alexmosc2a8cec2016-05-23 22:19:533134 static_cast<RenderWidgetHostViewBase*>(
3135 GetCreatedWidget(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:503136 if (!widget_host_view)
3137 return;
[email protected]cfd80b02014-05-01 17:46:483138
W. James MacLeanec4125c2019-09-27 18:56:003139 // GetOutermostWebContents() returns |this| if there are no outer WebContents.
W. James MacLean3c5f50462019-10-28 16:24:213140 auto* outer_web_contents = GetOuterWebContents();
3141 auto* outermost_web_contents = GetOutermostWebContents();
W. James MacLeanec4125c2019-09-27 18:56:003142 RenderWidgetHostView* view =
W. James MacLean3c5f50462019-10-28 16:24:213143 outermost_web_contents->GetRenderWidgetHostView();
3144 // It's not entirely obvious why we need the transform only in the case where
3145 // the outer webcontents is not the same as the outermost webcontents. It may
3146 // be due to the fact that oopifs that are children of the mainframe get
3147 // correct values for their screenrects, but deeper cross-process frames do
3148 // not. Hopefully this can be resolved with https://crbug.com/928825.
3149 // Handling these cases separately is needed for http://crbug.com/1015298.
3150 bool needs_transform = this != outermost_web_contents &&
3151 outermost_web_contents != outer_web_contents;
W. James MacLeanec4125c2019-09-27 18:56:003152
3153 gfx::Rect transformed_rect(initial_rect);
3154 RenderWidgetHostView* this_view = GetRenderWidgetHostView();
W. James MacLean3c5f50462019-10-28 16:24:213155 if (needs_transform) {
W. James MacLeanec4125c2019-09-27 18:56:003156 // We need to transform the coordinates of initial_rect.
3157 gfx::Point origin =
3158 this_view->TransformPointToRootCoordSpace(initial_rect.origin());
3159 gfx::Point bottom_right =
3160 this_view->TransformPointToRootCoordSpace(initial_rect.bottom_right());
3161 transformed_rect =
3162 gfx::Rect(origin.x(), origin.y(), bottom_right.x() - origin.x(),
3163 bottom_right.y() - origin.y());
[email protected]cfd80b02014-05-01 17:46:483164 }
3165
danakj0b246942018-09-17 21:30:273166 // Fullscreen child widgets are frames, other child widgets are popups.
[email protected]4aebbca2013-09-17 22:26:493167 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:313168 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:033169 view_->StoreFocus();
alexmosc9e76ec2016-05-16 22:59:373170 fullscreen_widget_process_id_ =
3171 widget_host_view->GetRenderWidgetHost()->GetProcess()->GetID();
[email protected]d7f80ba2013-10-12 07:42:313172 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:493173 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
3174 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
Dave Tapuska3ed44192018-05-01 18:53:303175 delegate_->EnterFullscreenModeForTab(this, GURL(),
Dave Tapuskaa4189512019-10-15 20:27:343176 blink::mojom::FullscreenOptions());
[email protected]4aebbca2013-09-17 22:26:493177 } else {
[email protected]cfd80b02014-05-01 17:46:483178 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:493179 }
ericwilligersde386342016-10-19 02:35:093180 for (auto& observer : observers_)
3181 observer.DidShowFullscreenWidget();
[email protected]4aebbca2013-09-17 22:26:493182 if (!widget_host_view->HasFocus())
3183 widget_host_view->Focus();
3184 } else {
W. James MacLeanec4125c2019-09-27 18:56:003185 widget_host_view->InitAsPopup(view, transformed_rect);
[email protected]4aebbca2013-09-17 22:26:493186 }
[email protected]89054502012-06-03 10:29:243187
yiyixcb1fbc4f2018-03-16 19:54:083188 RenderWidgetHostImpl* render_widget_host_impl = widget_host_view->host();
[email protected]89054502012-06-03 10:29:243189 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:313190 // Only allow privileged mouse lock for fullscreen render widget, which is
3191 // used to implement Pepper Flash fullscreen.
3192 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:503193}
3194
danakje6c01622018-10-05 19:39:263195std::unique_ptr<WebContentsImpl> WebContentsImpl::GetCreatedWindow(
nick5ae4d2d2017-01-06 01:18:353196 int process_id,
3197 int main_frame_widget_route_id) {
Lukasz Anforowicz09060bdf72018-08-23 15:53:173198 auto key = GlobalRoutingID(process_id, main_frame_widget_route_id);
nick5ae4d2d2017-01-06 01:18:353199 auto iter = pending_contents_.find(key);
[email protected]bafe6cd2012-05-23 23:09:503200
3201 // Certain systems can block the creation of new windows. If we didn't succeed
3202 // in creating one, just return NULL.
alexmosc2a8cec2016-05-23 22:19:533203 if (iter == pending_contents_.end())
3204 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:503205
danakje6c01622018-10-05 19:39:263206 std::unique_ptr<WebContentsImpl> new_contents = std::move(iter->second);
nick5ae4d2d2017-01-06 01:18:353207 pending_contents_.erase(key);
danakje6c01622018-10-05 19:39:263208 RemoveDestructionObserver(new_contents.get());
[email protected]bafe6cd2012-05-23 23:09:503209
[email protected]d70bea92013-04-05 04:23:343210 // Don't initialize the guest WebContents immediately.
danakje6c01622018-10-05 19:39:263211 if (BrowserPluginGuest::IsGuest(new_contents.get()))
[email protected]d70bea92013-04-05 04:23:343212 return new_contents;
3213
Lukasz Anforowicz5510ed652018-06-06 16:16:193214 if (!new_contents->GetMainFrame()->GetProcess()->IsInitializedAndNotDead() ||
nick5ae4d2d2017-01-06 01:18:353215 !new_contents->GetMainFrame()->GetView()) {
alexmosc2a8cec2016-05-23 22:19:533216 return nullptr;
nick5ae4d2d2017-01-06 01:18:353217 }
[email protected]bafe6cd2012-05-23 23:09:503218
[email protected]bafe6cd2012-05-23 23:09:503219 return new_contents;
3220}
3221
alexmosc2a8cec2016-05-23 22:19:533222RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int process_id,
3223 int route_id) {
Lukasz Anforowicz09060bdf72018-08-23 15:53:173224 auto iter = pending_widget_views_.find(GlobalRoutingID(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:503225 if (iter == pending_widget_views_.end()) {
3226 DCHECK(false);
alexmosc2a8cec2016-05-23 22:19:533227 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:503228 }
3229
3230 RenderWidgetHostView* widget_host_view = iter->second;
Lukasz Anforowicz09060bdf72018-08-23 15:53:173231 pending_widget_views_.erase(GlobalRoutingID(process_id, route_id));
[email protected]bafe6cd2012-05-23 23:09:503232
3233 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
Lukasz Anforowicz5510ed652018-06-06 16:16:193234 if (!widget_host->GetProcess()->IsInitializedAndNotDead()) {
[email protected]bafe6cd2012-05-23 23:09:503235 // The view has gone away or the renderer crashed. Nothing to do.
alexmosc2a8cec2016-05-23 22:19:533236 return nullptr;
[email protected]bafe6cd2012-05-23 23:09:503237 }
3238
3239 return widget_host_view;
3240}
3241
[email protected]f13b4202012-06-12 23:53:233242void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:093243 const MediaStreamRequest& request,
Mark Pilgrim57499082018-06-12 12:38:303244 MediaResponseCallback callback) {
[email protected]d19b84b2014-03-14 11:52:373245 if (delegate_) {
Mark Pilgrim57499082018-06-12 12:38:303246 delegate_->RequestMediaAccessPermission(this, request, std::move(callback));
[email protected]d19b84b2014-03-14 11:52:373247 } else {
Antonio Gomes0d42960a2019-06-05 12:35:513248 std::move(callback).Run(
3249 blink::MediaStreamDevices(),
3250 blink::mojom::MediaStreamRequestResult::FAILED_DUE_TO_SHUTDOWN,
3251 std::unique_ptr<MediaStreamUI>());
[email protected]d19b84b2014-03-14 11:52:373252 }
[email protected]f13b4202012-06-12 23:53:233253}
3254
Chandan Padhia4b8bcb72017-09-12 16:41:043255bool WebContentsImpl::CheckMediaAccessPermission(
Raymes Khouryad7c24a12018-03-05 23:22:583256 RenderFrameHost* render_frame_host,
Chandan Padhia4b8bcb72017-09-12 16:41:043257 const url::Origin& security_origin,
Antonio Gomesc8b734b2019-06-05 18:22:163258 blink::mojom::MediaStreamType type) {
3259 DCHECK(type == blink::mojom::MediaStreamType::DEVICE_AUDIO_CAPTURE ||
3260 type == blink::mojom::MediaStreamType::DEVICE_VIDEO_CAPTURE);
Chandan Padhia4b8bcb72017-09-12 16:41:043261 return delegate_ && delegate_->CheckMediaAccessPermission(
Raymes Khouryad7c24a12018-03-05 23:22:583262 render_frame_host, security_origin.GetURL(), type);
grunell657d4d82014-09-18 00:09:433263}
3264
Guido Urdaneta73fa6632019-01-14 18:46:263265std::string WebContentsImpl::GetDefaultMediaDeviceID(
Antonio Gomesc8b734b2019-06-05 18:22:163266 blink::mojom::MediaStreamType type) {
guidou8a440b842017-01-30 13:58:433267 if (!delegate_)
3268 return std::string();
3269 return delegate_->GetDefaultMediaDeviceID(this, type);
3270}
3271
[email protected]cc9200432013-07-23 23:02:403272SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
3273 SiteInstance* instance) {
3274 return controller_.GetSessionStorageNamespace(instance);
3275}
3276
[email protected]6de7fc482014-06-06 10:46:443277SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
3278 return controller_.GetSessionStorageNamespaceMap();
3279}
3280
[email protected]9b159a52013-10-03 17:24:553281FrameTree* WebContentsImpl::GetFrameTree() {
3282 return &frame_tree_;
3283}
3284
aelias5252baa2016-04-10 01:18:023285bool WebContentsImpl::IsOverridingUserAgent() {
3286 return GetController().GetVisibleEntry() &&
3287 GetController().GetVisibleEntry()->GetIsOverridingUserAgent();
3288}
3289
avi85ee8362016-10-08 02:09:083290bool WebContentsImpl::IsJavaScriptDialogShowing() const {
3291 return is_showing_javascript_dialog_;
3292}
3293
avic031d392017-03-03 03:09:423294bool WebContentsImpl::ShouldIgnoreUnresponsiveRenderer() {
3295 // Ignore unresponsive renderers if the debugger is attached to them since the
3296 // unresponsiveness might be a result of the renderer sitting on a breakpoint.
3297 //
David Bienvenu525f8a02019-02-15 02:02:423298#ifdef OS_WIN
3299 // Check if a windows debugger is attached to the renderer process.
3300 base::ProcessHandle process_handle =
3301 GetMainFrame()->GetProcess()->GetProcess().Handle();
3302 BOOL debugger_present = FALSE;
3303 if (CheckRemoteDebuggerPresent(process_handle, &debugger_present) &&
3304 debugger_present)
3305 return true;
3306#endif // OS_WIN
3307
avic031d392017-03-03 03:09:423308 // TODO(pfeldman): Fix this to only return true if the renderer is *actually*
3309 // sitting on a breakpoint. https://crbug.com/684202
3310 return DevToolsAgentHost::IsDebuggerAttached(this);
3311}
3312
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:413313ui::AXMode WebContentsImpl::GetAccessibilityMode() {
[email protected]95640212014-07-26 18:14:303314 return accessibility_mode_;
3315}
3316
Dominic Mazzonia7b0edb22017-08-09 16:32:513317void WebContentsImpl::AccessibilityEventReceived(
Dominic Mazzoniccbaa9b2018-06-06 07:44:233318 const AXEventNotificationDetails& details) {
ericwilligersde386342016-10-19 02:35:093319 for (auto& observer : observers_)
Dominic Mazzonia7b0edb22017-08-09 16:32:513320 observer.AccessibilityEventReceived(details);
[email protected]31a71eaf2014-03-13 01:47:363321}
3322
dmazzoni2400c462016-08-23 15:07:133323void WebContentsImpl::AccessibilityLocationChangesReceived(
3324 const std::vector<AXLocationChangeNotificationDetails>& details) {
ericwilligersde386342016-10-19 02:35:093325 for (auto& observer : observers_)
Dominic Mazzonia7b0edb22017-08-09 16:32:513326 observer.AccessibilityLocationChangesReceived(details);
dmazzoni2400c462016-08-23 15:07:133327}
3328
Abigail Kleinabb428332019-09-13 18:26:213329base::string16 WebContentsImpl::DumpAccessibilityTree(
3330 bool internal,
3331 std::vector<AccessibilityTreeFormatter::PropertyFilter> property_filters) {
James Wallace-Leeeafc94cb92018-07-23 21:35:093332 auto* ax_mgr = GetOrCreateRootBrowserAccessibilityManager();
3333 DCHECK(ax_mgr);
Lei Zhangc98caa3822019-11-07 19:17:273334 return AccessibilityTreeFormatterBase::DumpAccessibilityTreeFromManager(
Abigail Kleinabb428332019-09-13 18:26:213335 ax_mgr, internal, property_filters);
James Wallace-Leeeafc94cb92018-07-23 21:35:093336}
3337
Abigail Kleinaa898742019-11-01 02:31:253338void WebContentsImpl::RecordAccessibilityEvents(
3339 AccessibilityEventCallback callback,
3340 bool start) {
3341 if (start) {
3342 SetAccessibilityMode(ui::AXMode::kWebContents);
3343 auto* ax_mgr = GetOrCreateRootBrowserAccessibilityManager();
3344 DCHECK(ax_mgr);
3345 base::ProcessId pid = base::Process::Current().Pid();
3346 event_recorder_ = content::AccessibilityEventRecorder::Create(
3347 ax_mgr, pid, base::StringPiece{});
3348 event_recorder_->ListenToEvents(callback);
3349 } else {
3350 DCHECK(event_recorder_);
3351 event_recorder_->FlushAsyncEvents();
3352 event_recorder_ = nullptr;
3353 }
3354}
3355
dmazzonia656928e2014-09-15 20:28:543356RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:403357 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:543358 int browser_plugin_instance_id) {
3359 BrowserPluginGuestManager* guest_manager =
3360 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:203361 if (!guest_manager)
3362 return nullptr;
3363
dmazzonia656928e2014-09-15 20:28:543364 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:443365 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:543366 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:203367 return nullptr;
3368
dmazzonia656928e2014-09-15 20:28:543369 return guest->GetMainFrame();
3370}
3371
Ke He7319dbe2017-11-09 05:54:443372device::mojom::GeolocationContext* WebContentsImpl::GetGeolocationContext() {
Ken Rockotce010f02019-12-12 23:32:323373 if (!geolocation_context_) {
3374 GetDeviceService().BindGeolocationContext(
3375 geolocation_context_.BindNewPipeAndPassReceiver());
3376 }
Conley Owens6894c4f2017-07-10 19:29:133377 return geolocation_context_.get();
blundellc57b93f2014-10-29 13:19:573378}
3379
ke.he98b761e2017-05-09 05:59:173380device::mojom::WakeLockContext* WebContentsImpl::GetWakeLockContext() {
blundelld8cd72b2017-03-28 07:18:383381 if (!wake_lock_context_host_)
3382 wake_lock_context_host_.reset(new WakeLockContextHost(this));
blundelle75a8f92017-03-27 08:11:173383 return wake_lock_context_host_->GetWakeLockContext();
alogvinovf50445a2015-10-30 13:00:123384}
3385
blundellf5316fc2017-05-15 11:49:033386#if defined(OS_ANDROID)
Miyoung Shin59f39ff2019-09-17 07:23:203387void WebContentsImpl::GetNFC(
3388 mojo::PendingReceiver<device::mojom::NFC> receiver) {
Leon Hanccb985f2019-08-26 02:43:243389 NFCHost nfc_host(this);
Miyoung Shin59f39ff2019-09-17 07:23:203390 nfc_host.GetNFC(std::move(receiver));
blundellf5316fc2017-05-15 11:49:033391}
3392#endif
3393
Evan Stade5e750ad02017-08-07 21:59:273394void WebContentsImpl::SetNotWaitingForResponse() {
3395 if (waiting_for_response_ == false)
3396 return;
3397
3398 waiting_for_response_ = false;
3399 if (delegate_)
3400 delegate_->LoadingStateChanged(this, is_load_to_different_document_);
Chris Hamiltonf82f2a702018-02-15 19:37:293401 for (auto& observer : observers_)
3402 observer.DidReceiveResponse();
Evan Stade5e750ad02017-08-07 21:59:273403}
3404
lfgbb9c28a2016-03-01 03:19:493405void WebContentsImpl::SendScreenRects() {
kenrbc52e1b4e2016-03-20 01:03:373406 for (FrameTreeNode* node : frame_tree_.Nodes()) {
kenrb0e8dc202016-05-30 19:51:403407 if (node->current_frame_host()->is_local_root())
kenrbc52e1b4e2016-03-20 01:03:373408 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
3409 }
lfgbb9c28a2016-03-01 03:19:493410
danakj4df8a9d02019-02-05 20:36:593411 // Interstitials have their own |frame_tree_|.
3412 if (interstitial_page_) {
3413 FrameTree* interstitial_frame_tree = interstitial_page_->GetFrameTree();
3414 for (FrameTreeNode* node : interstitial_frame_tree->Nodes()) {
3415 if (node->current_frame_host()->is_local_root())
3416 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
3417 }
lfgdb5c4ed2016-03-04 23:09:073418 }
[email protected]32deec62013-05-15 23:55:043419}
3420
ekaramadadd882292016-06-08 15:22:563421TextInputManager* WebContentsImpl::GetTextInputManager() {
3422 if (GetOuterWebContents())
3423 return GetOuterWebContents()->GetTextInputManager();
3424
Ehsan Karamadc179dc02018-12-15 03:09:293425 if (!text_input_manager_ && !browser_plugin_guest_) {
Darren Shenca53d5f2018-05-15 04:56:013426 text_input_manager_.reset(new TextInputManager(
3427 GetBrowserContext() &&
3428 !GetBrowserContext()->IsOffTheRecord()) /* should_do_learning */);
3429 }
ekaramadadd882292016-06-08 15:22:563430
3431 return text_input_manager_.get();
3432}
3433
paulmeyer7f6f1d4f2016-11-15 00:00:273434bool WebContentsImpl::OnUpdateDragCursor() {
Lei Zhang6410ec1a2019-01-31 21:38:583435 return browser_plugin_embedder_ &&
3436 browser_plugin_embedder_->OnUpdateDragCursor();
paulmeyer7f6f1d4f2016-11-15 00:00:273437}
3438
kenrb11f213a2017-03-24 18:12:063439bool WebContentsImpl::IsWidgetForMainFrame(
3440 RenderWidgetHostImpl* render_widget_host) {
3441 return render_widget_host == GetMainFrame()->GetRenderWidgetHost();
3442}
3443
[email protected]95640212014-07-26 18:14:303444BrowserAccessibilityManager*
3445 WebContentsImpl::GetRootBrowserAccessibilityManager() {
Dominic Mazzoniefb5f9e32017-12-21 01:08:223446 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(
3447 ShowingInterstitialPage() ? GetInterstitialPage()->GetMainFrame()
3448 : GetMainFrame());
creisc014b402015-04-23 16:41:453449 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:303450}
3451
3452BrowserAccessibilityManager*
3453 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
Dominic Mazzoniefb5f9e32017-12-21 01:08:223454 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(
3455 ShowingInterstitialPage() ? GetInterstitialPage()->GetMainFrame()
3456 : GetMainFrame());
creisc014b402015-04-23 16:41:453457 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:303458}
3459
Dave Tapuskab336b922017-07-06 19:24:053460void WebContentsImpl::ExecuteEditCommand(
3461 const std::string& command,
3462 const base::Optional<base::string16>& value) {
Dave Tapuskae782bea2019-07-09 16:21:513463 auto* input_handler = GetFocusedFrameInputHandler();
3464 if (!input_handler)
Dave Tapuskab336b922017-07-06 19:24:053465 return;
3466
Dave Tapuskae782bea2019-07-09 16:21:513467 input_handler->ExecuteEditCommand(command, value);
Dave Tapuskab336b922017-07-06 19:24:053468}
3469
mohsen7ab1ec16ec2015-07-02 18:26:233470void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
Dave Tapuskae782bea2019-07-09 16:21:513471 auto* input_handler = GetFocusedFrameInputHandler();
3472 if (!input_handler)
mohsen7ab1ec16ec2015-07-02 18:26:233473 return;
3474
Dave Tapuskae782bea2019-07-09 16:21:513475 input_handler->MoveRangeSelectionExtent(extent);
mohsen7ab1ec16ec2015-07-02 18:26:233476}
3477
3478void WebContentsImpl::SelectRange(const gfx::Point& base,
3479 const gfx::Point& extent) {
Dave Tapuskae782bea2019-07-09 16:21:513480 auto* input_handler = GetFocusedFrameInputHandler();
3481 if (!input_handler)
mohsen7ab1ec16ec2015-07-02 18:26:233482 return;
3483
Dave Tapuskae782bea2019-07-09 16:21:513484 input_handler->SelectRange(base, extent);
mohsen7ab1ec16ec2015-07-02 18:26:233485}
3486
Dave Tapuskab336b922017-07-06 19:24:053487void WebContentsImpl::MoveCaret(const gfx::Point& extent) {
Dave Tapuskae782bea2019-07-09 16:21:513488 auto* input_handler = GetFocusedFrameInputHandler();
3489 if (!input_handler)
Dave Tapuskab336b922017-07-06 19:24:053490 return;
3491
Dave Tapuskae782bea2019-07-09 16:21:513492 input_handler->MoveCaret(extent);
Dave Tapuskab336b922017-07-06 19:24:053493}
3494
Shimi Zhang37deeb22017-09-28 00:59:013495void WebContentsImpl::AdjustSelectionByCharacterOffset(
3496 int start_adjust,
3497 int end_adjust,
3498 bool show_selection_menu) {
Dave Tapuskae782bea2019-07-09 16:21:513499 auto* input_handler = GetFocusedFrameInputHandler();
3500 if (!input_handler)
aurimasab0319022015-07-10 21:57:383501 return;
3502
Shimi Zhang37deeb22017-09-28 00:59:013503 using blink::mojom::SelectionMenuBehavior;
Dave Tapuskae782bea2019-07-09 16:21:513504 input_handler->AdjustSelectionByCharacterOffset(
Shimi Zhang37deeb22017-09-28 00:59:013505 start_adjust, end_adjust,
3506 show_selection_menu ? SelectionMenuBehavior::kShow
3507 : SelectionMenuBehavior::kHide);
aurimasab0319022015-07-10 21:57:383508}
3509
[email protected]b172aee2012-04-10 17:05:263510void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:493511 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:233512 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:493513 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:333514}
3515
avic3aa8422015-11-09 20:57:223516void WebContentsImpl::ResizeDueToAutoResize(
3517 RenderWidgetHostImpl* render_widget_host,
Fady Samuel97947112018-05-05 16:24:543518 const gfx::Size& new_size) {
avic3aa8422015-11-09 20:57:223519 if (render_widget_host != GetRenderViewHost()->GetWidget())
3520 return;
3521
kenrbe4f91082017-06-02 20:32:083522 auto_resize_size_ = new_size;
3523
3524 // Out-of-process iframe visible viewport sizes usually come from the
3525 // top-level RenderWidgetHostView, but when auto-resize is enabled on the
3526 // top frame then that size is used instead.
3527 for (FrameTreeNode* node : frame_tree_.Nodes()) {
3528 if (node->current_frame_host()->is_local_root()) {
3529 RenderWidgetHostImpl* host =
3530 node->current_frame_host()->GetRenderWidgetHost();
3531 if (host != render_widget_host)
Fady Samuel0b911822018-04-25 13:22:163532 host->SynchronizeVisualProperties();
kenrbe4f91082017-06-02 20:32:083533 }
3534 }
3535
[email protected]61e2b3cc2012-03-02 16:13:343536 if (delegate_)
3537 delegate_->ResizeDueToAutoResize(this, new_size);
3538}
3539
kenrbe4f91082017-06-02 20:32:083540gfx::Size WebContentsImpl::GetAutoResizeSize() {
3541 return auto_resize_size_;
3542}
3543
3544void WebContentsImpl::ResetAutoResizeSize() {
3545 auto_resize_size_ = gfx::Size();
3546}
3547
[email protected]b172aee2012-04-10 17:05:263548WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
Aaron Colwell9dab1652019-12-09 18:29:493549#if DCHECK_IS_ON()
3550 DCHECK(params.Valid());
3551#endif
3552
Bo Liu300c6052018-06-12 04:46:073553 if (!delegate_) {
3554 // Embedder can delay setting a delegate on new WebContents with
3555 // WebContentsDelegate::ShouldResumeRequestsForCreatedWindow. In the mean
3556 // time, navigations, including the initial one, that goes through OpenURL
3557 // should be delayed until embedder is ready to resume loading.
3558 delayed_open_url_params_ = std::make_unique<OpenURLParams>(params);
Nasko Oskov83a8cf92018-10-19 14:58:563559
3560 // If there was a navigation deferred when creating the window through
3561 // CreateNewWindow, drop it in favor of this navigation.
3562 delayed_load_url_params_.reset();
3563
Ivan Kotenkov2c0d2bb32017-11-01 15:41:283564 return nullptr;
Bo Liu300c6052018-06-12 04:46:073565 }
[email protected]00c37fc2011-08-02 00:22:503566
[email protected]e5d549d2011-12-28 01:29:203567 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
pnoland488944652017-02-22 18:58:543568
3569 RenderFrameHost* source_render_frame_host = RenderFrameHost::FromID(
3570 params.source_render_process_id, params.source_render_frame_id);
3571
3572 if (source_render_frame_host && params.source_site_instance) {
3573 CHECK_EQ(source_render_frame_host->GetSiteInstance(),
3574 params.source_site_instance.get());
3575 }
3576
3577 if (new_contents && source_render_frame_host && new_contents != this) {
3578 for (auto& observer : observers_) {
Lukasz Anforowicz48c9f872018-08-01 00:58:413579 observer.DidOpenRequestedURL(
3580 new_contents, source_render_frame_host, params.url, params.referrer,
3581 params.disposition, params.transition,
3582 params.started_from_context_menu, params.is_renderer_initiated);
pnoland488944652017-02-22 18:58:543583 }
3584 }
3585
[email protected]e5d549d2011-12-28 01:29:203586 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:343587}
3588
[email protected]a86c0e962013-12-17 17:10:393589void WebContentsImpl::RenderFrameForInterstitialPageCreated(
3590 RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:093591 for (auto& observer : observers_)
3592 observer.RenderFrameForInterstitialPageCreated(render_frame_host);
[email protected]ba45bfd2012-05-22 21:51:443593}
3594
[email protected]20ca0382013-02-28 19:50:073595void WebContentsImpl::AttachInterstitialPage(
3596 InterstitialPageImpl* interstitial_page) {
creisadca9862017-06-16 19:12:113597 DCHECK(!interstitial_page_ && interstitial_page);
3598 interstitial_page_ = interstitial_page;
[email protected]90fb08ed2013-09-24 17:43:293599
3600 // Cancel any visible dialogs so that they don't interfere with the
3601 // interstitial.
creis89a0f782015-05-27 16:13:173602 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:293603
ericwilligersde386342016-10-19 02:35:093604 for (auto& observer : observers_)
3605 observer.DidAttachInterstitialPage();
clamy44e84ce2016-02-22 15:38:253606
3607 // Stop the throbber if needed while the interstitial page is shown.
3608 if (frame_tree_.IsLoading())
3609 LoadingStateChanged(true, true, nullptr);
lfg1453e412017-04-11 00:48:503610
3611 // Connect to outer WebContents if necessary.
3612 if (node_.OuterContentsFrameTreeNode()) {
3613 if (GetRenderManager()->GetProxyToOuterDelegate()) {
3614 DCHECK(
3615 static_cast<RenderWidgetHostViewBase*>(interstitial_page->GetView())
3616 ->IsRenderWidgetHostViewChildFrame());
3617 RenderWidgetHostViewChildFrame* view =
3618 static_cast<RenderWidgetHostViewChildFrame*>(
3619 interstitial_page->GetView());
3620 GetRenderManager()->SetRWHViewForInnerContents(view);
3621 }
3622 }
Bo Liu7c6779e92017-08-16 02:02:283623
Bo Liu168c8642017-08-28 18:26:023624#if defined(OS_ANDROID)
Bo Liu7c6779e92017-08-16 02:02:283625 // Update importance of the interstitial.
3626 static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame())
3627 ->GetRenderWidgetHost()
3628 ->SetImportance(GetMainFrame()->GetRenderWidgetHost()->importance());
Bo Liu168c8642017-08-28 18:26:023629#endif
Dominic Mazzoniefb5f9e32017-12-21 01:08:223630
3631 if (accessibility_mode_.has_mode(ui::AXMode::kNativeAPIs)) {
3632 // Make sure that the main page's accessibility tree is hidden and the
3633 // interstitial gets focus.
3634 RenderFrameHostImpl* rfh =
3635 static_cast<RenderFrameHostImpl*>(GetMainFrame());
3636 if (rfh) {
3637 BrowserAccessibilityManager* accessibility_manager =
3638 rfh->browser_accessibility_manager();
3639 if (accessibility_manager)
3640 accessibility_manager->set_hidden_by_interstitial_page(true);
3641 }
3642 rfh = static_cast<RenderFrameHostImpl*>(
3643 GetInterstitialPage()->GetMainFrame());
3644 if (rfh) {
3645 BrowserAccessibilityManager* accessibility_manager =
3646 rfh->GetOrCreateBrowserAccessibilityManager();
3647 if (accessibility_manager)
3648 accessibility_manager->OnWindowFocused();
3649 }
3650 }
clamy44e84ce2016-02-22 15:38:253651}
3652
3653void WebContentsImpl::DidProceedOnInterstitial() {
3654 // The interstitial page should no longer be pausing the throbber.
creisadca9862017-06-16 19:12:113655 DCHECK(!(ShowingInterstitialPage() && interstitial_page_->pause_throbber()));
clamy44e84ce2016-02-22 15:38:253656
3657 // Restart the throbber now that the interstitial page no longer pauses it.
3658 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
3659 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:073660}
3661
Shivani Sharma985474f2019-05-23 21:36:473662bool WebContentsImpl::HadInnerWebContents() {
3663 return had_inner_webcontents_;
3664}
3665
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:043666void WebContentsImpl::DetachInterstitialPage(bool has_focus) {
Lucas Furukawa Gadani69b609192017-07-10 17:08:343667 bool interstitial_pausing_throbber =
3668 ShowingInterstitialPage() && interstitial_page_->pause_throbber();
3669 if (ShowingInterstitialPage())
3670 interstitial_page_ = nullptr;
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:043671
Dominic Mazzoniefb5f9e32017-12-21 01:08:223672 // Make sure that the main page's accessibility tree is no longer
3673 // suppressed.
3674 RenderFrameHostImpl* rfh = GetMainFrame();
3675 if (rfh) {
3676 BrowserAccessibilityManager* accessibility_manager =
3677 rfh->browser_accessibility_manager();
3678 if (accessibility_manager)
3679 accessibility_manager->set_hidden_by_interstitial_page(false);
3680 }
3681
Lucas Furukawa Gadani7f1241d2017-07-12 01:45:043682 // If the focus was on the interstitial, let's keep it to the page.
3683 // (Note that in unit-tests the RVH may not have a view).
3684 if (has_focus && GetRenderViewHost()->GetWidget()->GetView())
3685 GetRenderViewHost()->GetWidget()->GetView()->Focus();
3686
Lucas Furukawa Gadani69b609192017-07-10 17:08:343687 for (auto& observer : observers_)
3688 observer.DidDetachInterstitialPage();
3689
3690 // Disconnect from outer WebContents if necessary. This must happen after the
3691 // interstitial page is cleared above, since the call to
3692 // SetRWHViewForInnerContents below may loop over all the
3693 // RenderWidgetHostViews in the tree (otherwise, including the now-deleted
3694 // view for the interstitial).
lfg1453e412017-04-11 00:48:503695 if (node_.OuterContentsFrameTreeNode()) {
3696 if (GetRenderManager()->GetProxyToOuterDelegate()) {
3697 DCHECK(static_cast<RenderWidgetHostViewBase*>(
3698 GetRenderManager()->current_frame_host()->GetView())
3699 ->IsRenderWidgetHostViewChildFrame());
3700 RenderWidgetHostViewChildFrame* view =
3701 static_cast<RenderWidgetHostViewChildFrame*>(
3702 GetRenderManager()->current_frame_host()->GetView());
3703 GetRenderManager()->SetRWHViewForInnerContents(view);
3704 }
3705 }
3706
clamy44e84ce2016-02-22 15:38:253707 // Restart the throbber if needed now that the interstitial page is going
3708 // away.
3709 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
3710 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:073711}
3712
avi2b177592014-12-10 02:08:023713void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
3714 int history_length) {
alexmos136fd6e62016-08-15 20:58:413715 SendPageMessage(new PageMsg_SetHistoryOffsetAndLength(
3716 MSG_ROUTING_NONE, history_offset, history_length));
avi2b177592014-12-10 02:08:023717}
3718
3719void WebContentsImpl::SetHistoryOffsetAndLengthForView(
3720 RenderViewHost* render_view_host,
3721 int history_offset,
3722 int history_length) {
alexmos136fd6e62016-08-15 20:58:413723 render_view_host->Send(new PageMsg_SetHistoryOffsetAndLength(
avi2b177592014-12-10 02:08:023724 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:143725}
3726
arthursonzogni818c2642019-09-27 12:18:103727void WebContentsImpl::ReloadFocusedFrame() {
[email protected]1f3fc1d2014-04-03 14:50:173728 RenderFrameHost* focused_frame = GetFocusedFrame();
3729 if (!focused_frame)
3730 return;
3731
yilkal921048bd2019-10-09 23:51:043732 focused_frame->Reload();
[email protected]959be4c2014-04-08 15:01:333733}
3734
Miyoung Shin298d5ad2019-09-05 01:52:373735std::vector<mojo::Remote<blink::mojom::PauseSubresourceLoadingHandle>>
Ryan Sturmc65dbe42018-05-31 20:37:043736WebContentsImpl::PauseSubresourceLoading() {
Miyoung Shin298d5ad2019-09-05 01:52:373737 std::vector<mojo::Remote<blink::mojom::PauseSubresourceLoadingHandle>>
3738 handles;
Ryan Sturmc65dbe42018-05-31 20:37:043739 for (RenderFrameHost* rfh : GetAllFrames()) {
3740 if (!rfh->IsRenderFrameLive())
3741 continue;
3742 handles.push_back(rfh->PauseSubresourceLoading());
3743 }
3744 return handles;
3745}
3746
[email protected]959be4c2014-04-08 15:01:333747void WebContentsImpl::Undo() {
Dave Tapuskae782bea2019-07-09 16:21:513748 auto* input_handler = GetFocusedFrameInputHandler();
3749 if (!input_handler)
[email protected]959be4c2014-04-08 15:01:333750 return;
3751
Dave Tapuskae782bea2019-07-09 16:21:513752 input_handler->Undo();
[email protected]959be4c2014-04-08 15:01:333753 RecordAction(base::UserMetricsAction("Undo"));
3754}
3755
3756void WebContentsImpl::Redo() {
Dave Tapuskae782bea2019-07-09 16:21:513757 auto* input_handler = GetFocusedFrameInputHandler();
3758 if (!input_handler)
[email protected]959be4c2014-04-08 15:01:333759 return;
Dave Tapuskae782bea2019-07-09 16:21:513760
3761 input_handler->Redo();
[email protected]959be4c2014-04-08 15:01:333762 RecordAction(base::UserMetricsAction("Redo"));
3763}
3764
3765void WebContentsImpl::Cut() {
Dave Tapuskae782bea2019-07-09 16:21:513766 auto* input_handler = GetFocusedFrameInputHandler();
3767 if (!input_handler)
[email protected]959be4c2014-04-08 15:01:333768 return;
3769
Dave Tapuskae782bea2019-07-09 16:21:513770 input_handler->Cut();
[email protected]959be4c2014-04-08 15:01:333771 RecordAction(base::UserMetricsAction("Cut"));
3772}
3773
3774void WebContentsImpl::Copy() {
Dave Tapuskae782bea2019-07-09 16:21:513775 auto* input_handler = GetFocusedFrameInputHandler();
3776 if (!input_handler)
[email protected]959be4c2014-04-08 15:01:333777 return;
3778
Dave Tapuskae782bea2019-07-09 16:21:513779 input_handler->Copy();
[email protected]959be4c2014-04-08 15:01:333780 RecordAction(base::UserMetricsAction("Copy"));
3781}
3782
3783void WebContentsImpl::CopyToFindPboard() {
3784#if defined(OS_MACOSX)
Dave Tapuskae782bea2019-07-09 16:21:513785 auto* input_handler = GetFocusedFrameInputHandler();
3786 if (!input_handler)
[email protected]959be4c2014-04-08 15:01:333787 return;
3788
3789 // Windows/Linux don't have the concept of a find pasteboard.
Dave Tapuskae782bea2019-07-09 16:21:513790 input_handler->CopyToFindPboard();
[email protected]959be4c2014-04-08 15:01:333791 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
3792#endif
3793}
3794
3795void WebContentsImpl::Paste() {
Dave Tapuskae782bea2019-07-09 16:21:513796 auto* input_handler = GetFocusedFrameInputHandler();
3797 if (!input_handler)
[email protected]959be4c2014-04-08 15:01:333798 return;
3799
Dave Tapuskae782bea2019-07-09 16:21:513800 input_handler->Paste();
Archana Simhaf67090c2019-05-06 23:43:233801 for (auto& observer : observers_)
3802 observer.OnPaste();
[email protected]959be4c2014-04-08 15:01:333803 RecordAction(base::UserMetricsAction("Paste"));
3804}
3805
3806void WebContentsImpl::PasteAndMatchStyle() {
Dave Tapuskae782bea2019-07-09 16:21:513807 auto* input_handler = GetFocusedFrameInputHandler();
3808 if (!input_handler)
[email protected]959be4c2014-04-08 15:01:333809 return;
3810
Dave Tapuskae782bea2019-07-09 16:21:513811 input_handler->PasteAndMatchStyle();
Archana Simhaf67090c2019-05-06 23:43:233812 for (auto& observer : observers_)
3813 observer.OnPaste();
[email protected]959be4c2014-04-08 15:01:333814 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
3815}
3816
3817void WebContentsImpl::Delete() {
Dave Tapuskae782bea2019-07-09 16:21:513818 auto* input_handler = GetFocusedFrameInputHandler();
3819 if (!input_handler)
[email protected]959be4c2014-04-08 15:01:333820 return;
3821
Dave Tapuskae782bea2019-07-09 16:21:513822 input_handler->Delete();
[email protected]959be4c2014-04-08 15:01:333823 RecordAction(base::UserMetricsAction("DeleteSelection"));
3824}
3825
3826void WebContentsImpl::SelectAll() {
Dave Tapuskae782bea2019-07-09 16:21:513827 auto* input_handler = GetFocusedFrameInputHandler();
3828 if (!input_handler)
[email protected]959be4c2014-04-08 15:01:333829 return;
3830
Dave Tapuskae782bea2019-07-09 16:21:513831 input_handler->SelectAll();
[email protected]959be4c2014-04-08 15:01:333832 RecordAction(base::UserMetricsAction("SelectAll"));
3833}
3834
yabinh351e7ec2017-03-10 02:43:243835void WebContentsImpl::CollapseSelection() {
Dave Tapuskae782bea2019-07-09 16:21:513836 auto* input_handler = GetFocusedFrameInputHandler();
3837 if (!input_handler)
[email protected]959be4c2014-04-08 15:01:333838 return;
3839
Dave Tapuskae782bea2019-07-09 16:21:513840 input_handler->CollapseSelection();
[email protected]1f3fc1d2014-04-03 14:50:173841}
3842
3843void WebContentsImpl::Replace(const base::string16& word) {
Dave Tapuskae782bea2019-07-09 16:21:513844 auto* input_handler = GetFocusedFrameInputHandler();
3845 if (!input_handler)
[email protected]1f3fc1d2014-04-03 14:50:173846 return;
3847
Dave Tapuskae782bea2019-07-09 16:21:513848 input_handler->Replace(word);
[email protected]1f3fc1d2014-04-03 14:50:173849}
3850
3851void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
Dave Tapuskae782bea2019-07-09 16:21:513852 auto* input_handler = GetFocusedFrameInputHandler();
3853 if (!input_handler)
[email protected]1f3fc1d2014-04-03 14:50:173854 return;
3855
Dave Tapuskae782bea2019-07-09 16:21:513856 input_handler->ReplaceMisspelling(word);
[email protected]959be4c2014-04-08 15:01:333857}
3858
3859void WebContentsImpl::NotifyContextMenuClosed(
3860 const CustomContextMenuContext& context) {
3861 RenderFrameHost* focused_frame = GetFocusedFrame();
3862 if (!focused_frame)
3863 return;
3864
3865 focused_frame->Send(new FrameMsg_ContextMenuClosed(
3866 focused_frame->GetRoutingID(), context));
3867}
3868
3869void WebContentsImpl::ExecuteCustomContextMenuCommand(
3870 int action, const CustomContextMenuContext& context) {
3871 RenderFrameHost* focused_frame = GetFocusedFrame();
3872 if (!focused_frame)
3873 return;
3874
3875 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
3876 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:003877}
3878
[email protected]fc2b46b2014-05-03 16:33:453879gfx::NativeView WebContentsImpl::GetNativeView() {
3880 return view_->GetNativeView();
3881}
3882
3883gfx::NativeView WebContentsImpl::GetContentNativeView() {
3884 return view_->GetContentNativeView();
3885}
3886
3887gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
3888 return view_->GetTopLevelNativeWindow();
3889}
3890
3891gfx::Rect WebContentsImpl::GetViewBounds() {
3892 return view_->GetViewBounds();
3893}
3894
3895gfx::Rect WebContentsImpl::GetContainerBounds() {
3896 gfx::Rect rv;
3897 view_->GetContainerBounds(&rv);
3898 return rv;
3899}
3900
3901DropData* WebContentsImpl::GetDropData() {
3902 return view_->GetDropData();
3903}
3904
3905void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:043906 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:453907}
3908
3909void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:043910 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:453911}
3912
3913void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:043914 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:453915}
3916
3917void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:043918 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:453919}
3920
[email protected]b172aee2012-04-10 17:05:263921void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
Maxim Podgorodskiya926c4ff2017-11-20 02:06:393922 view_->FocusThroughTabTraversal(reverse);
[email protected]96d185d2009-04-24 03:28:543923}
3924
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:413925bool WebContentsImpl::ShowingInterstitialPage() {
creisadca9862017-06-16 19:12:113926 return interstitial_page_ != nullptr;
[email protected]96d185d2009-04-24 03:28:543927}
3928
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:413929InterstitialPageImpl* WebContentsImpl::GetInterstitialPage() {
creisadca9862017-06-16 19:12:113930 return interstitial_page_;
[email protected]686493142011-07-15 21:47:223931}
3932
[email protected]b172aee2012-04-10 17:05:263933bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:163934 // WebKit creates Document object when MIME type is application/xhtml+xml,
3935 // so we also support this MIME type.
3936 return contents_mime_type_ == "text/html" ||
3937 contents_mime_type_ == "text/xml" ||
3938 contents_mime_type_ == "application/xhtml+xml" ||
3939 contents_mime_type_ == "text/plain" ||
3940 contents_mime_type_ == "text/css" ||
Kinuko Yasuda74702f92017-07-31 03:27:533941 blink::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:163942}
3943
[email protected]b172aee2012-04-10 17:05:263944void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:593945 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:163946 if (!IsSavable()) {
Min Qinda0ed2062018-02-23 22:00:533947 download::RecordSavePackageEvent(
3948 download::SAVE_PACKAGE_DOWNLOAD_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:193949 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:143950 return;
[email protected]c7dd2f62011-07-18 15:57:593951 }
3952
3953 Stop();
3954
3955 // Create the save package and possibly prompt the user for the name to save
3956 // the page as. The user prompt is an asynchronous operation that runs on
3957 // another thread.
3958 save_package_ = new SavePackage(this);
3959 save_package_->GetSaveInfo();
3960}
3961
3962// Used in automated testing to bypass prompting the user for file names.
3963// Instead, the names and paths are hard coded rather than running them through
3964// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:343965bool WebContentsImpl::SavePage(const base::FilePath& main_file,
3966 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:213967 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:593968 // Stop the page from navigating.
3969 Stop();
3970
3971 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:213972 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:593973}
3974
[email protected]3c71576ce2013-07-23 02:00:013975void WebContentsImpl::SaveFrame(const GURL& url,
3976 const Referrer& referrer) {
Xing Liu10329bf2018-03-20 19:22:143977 SaveFrameWithHeaders(url, referrer, std::string(), base::string16());
kundaji6c7f9692015-03-09 18:00:373978}
3979
Xing Liu10329bf2018-03-20 19:22:143980void WebContentsImpl::SaveFrameWithHeaders(
3981 const GURL& url,
3982 const Referrer& referrer,
3983 const std::string& headers,
3984 const base::string16& suggested_filename) {
Lei Zhang13a42e42019-02-19 23:28:113985 // Check and see if the guest can handle this.
3986 if (delegate_) {
3987 WebContents* guest_web_contents = nullptr;
3988 if (browser_plugin_embedder_) {
3989 BrowserPluginGuest* guest = browser_plugin_embedder_->GetFullPageGuest();
3990 if (guest)
3991 guest_web_contents = guest->GetWebContents();
3992 } else if (browser_plugin_guest_) {
3993 guest_web_contents = this;
3994 }
3995
3996 if (guest_web_contents && delegate_->GuestSaveFrame(guest_web_contents))
3997 return;
3998 }
3999
nasko89ad7742015-03-05 22:14:194000 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:014001 return;
sammc92af61552014-11-19 23:27:404002 if (delegate_ && delegate_->SaveFrame(url, referrer))
4003 return;
4004
nasko89ad7742015-03-05 22:14:194005 // TODO(nasko): This check for main frame is incorrect and should be fixed
brettw760f7442016-05-23 21:19:224006 // by explicitly passing in which frame this method should target. This would
4007 // indicate whether it's the main frame, and also tell us the frame pointer
4008 // to use for routing.
nasko89ad7742015-03-05 22:14:194009 bool is_main_frame = (url == GetLastCommittedURL());
brettw760f7442016-05-23 21:19:224010 RenderFrameHost* frame_host = GetMainFrame();
[email protected]3c71576ce2013-07-23 02:00:014011
avib7348942015-12-25 20:57:104012 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:014013 if (is_main_frame) {
Lucas Furukawa Gadani5553a152019-01-08 18:55:574014 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:014015 if (entry)
4016 post_id = entry->GetPostID();
4017 }
Ramin Halavati24e21012017-07-10 12:56:064018 net::NetworkTrafficAnnotationTag traffic_annotation =
4019 net::DefineNetworkTrafficAnnotation("download_web_contents_frame", R"(
4020 semantics {
4021 sender: "Save Page Action"
4022 description:
4023 "Saves the given frame's URL to the local file system."
4024 trigger:
4025 "The user has triggered a save operation on the frame through a "
4026 "context menu or other mechanism."
4027 data: "None."
4028 destination: WEBSITE
4029 }
4030 policy {
Ramin Halavati3b979782017-07-21 11:40:264031 cookies_allowed: YES
Ramin Halavati24e21012017-07-10 12:56:064032 cookies_store: "user"
4033 setting:
4034 "This feature cannot be disabled by settings, but it's is only "
4035 "triggered by user request."
4036 policy_exception_justification: "Not implemented."
4037 })");
Min Qina904f3302018-02-13 23:33:344038 auto params = std::make_unique<download::DownloadUrlParameters>(
brettw760f7442016-05-23 21:19:224039 url, frame_host->GetProcess()->GetID(),
4040 frame_host->GetRenderViewHost()->GetRoutingID(),
Yao Xiao65d20b82019-12-05 22:04:204041 frame_host->GetRoutingID(), traffic_annotation,
4042 frame_host->GetNetworkIsolationKey());
Min Qina904f3302018-02-13 23:33:344043 params->set_referrer(referrer.url);
4044 params->set_referrer_policy(
4045 Referrer::ReferrerPolicyForUrlRequest(referrer.policy));
[email protected]3c71576ce2013-07-23 02:00:014046 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:014047 if (post_id >= 0)
4048 params->set_method("POST");
4049 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:374050
4051 if (headers.empty()) {
4052 params->set_prefer_cache(true);
4053 } else {
Min Qina904f3302018-02-13 23:33:344054 for (download::DownloadUrlParameters::RequestHeadersNameValuePair
4055 key_value : ParseDownloadHeaders(headers)) {
Megan Jablonski2f6a4c52017-07-10 23:01:254056 params->add_request_header(key_value.first, key_value.second);
kundaji6c7f9692015-03-09 18:00:374057 }
4058 }
Xing Liu10329bf2018-03-20 19:22:144059 params->set_suggested_name(suggested_filename);
Min Qin0ca8e1ee2018-01-31 00:49:354060 params->set_download_source(download::DownloadSource::WEB_CONTENTS_API);
thestig859c78892017-05-15 21:17:064061 BrowserContext::GetDownloadManager(GetBrowserContext())
Ramin Halavati03efa732017-06-12 09:28:204062 ->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:014063}
4064
[email protected]b172aee2012-04-10 17:05:264065void WebContentsImpl::GenerateMHTML(
dewittj6dc5747a2016-05-17 01:48:474066 const MHTMLGenerationParams& params,
Avi Drissman149b7832018-03-23 14:31:494067 base::OnceCallback<void(int64_t)> callback) {
Angel Alvarez902496682019-08-27 22:58:424068 base::OnceCallback<void(const MHTMLGenerationResult&)> wrapper_callback =
4069 base::BindOnce(
4070 [](base::OnceCallback<void(int64_t)> size_callback,
4071 const MHTMLGenerationResult& result) {
4072 std::move(size_callback).Run(result.file_size);
4073 },
4074 std::move(callback));
4075 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params,
4076 std::move(wrapper_callback));
4077}
4078
4079void WebContentsImpl::GenerateMHTMLWithResult(
4080 const MHTMLGenerationParams& params,
4081 MHTMLGenerationResult::GenerateMHTMLCallback callback) {
Avi Drissman149b7832018-03-23 14:31:494082 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params,
4083 std::move(callback));
[email protected]aa4f3972012-03-01 18:12:124084}
4085
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:414086const std::string& WebContentsImpl::GetContentsMimeType() {
[email protected]0bfbf882011-12-22 18:19:274087 return contents_mime_type_;
4088}
4089
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:414090bool WebContentsImpl::WillNotifyDisconnection() {
[email protected]0bfbf882011-12-22 18:19:274091 return notify_disconnection_;
4092}
4093
Leon Hanc819dc62019-01-28 04:30:194094blink::mojom::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:274095 return &renderer_preferences_;
4096}
4097
[email protected]e35ccd52012-05-23 16:22:474098void WebContentsImpl::Close() {
4099 Close(GetRenderViewHost());
4100}
4101
Ella Ge80a52dce2017-11-15 18:01:524102void WebContentsImpl::DragSourceEndedAt(float client_x,
4103 float client_y,
4104 float screen_x,
4105 float screen_y,
Paul Meyer0c58c3712016-11-17 22:59:514106 blink::WebDragOperation operation,
4107 RenderWidgetHost* source_rwh) {
Lei Zhang6410ec1a2019-01-31 21:38:584108 if (browser_plugin_embedder_) {
W. James MacLean9437b5bf2019-12-06 17:33:444109 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y, screen_x,
4110 screen_y, operation);
Lei Zhang6410ec1a2019-01-31 21:38:584111 }
Paul Meyer0c58c3712016-11-17 22:59:514112 if (source_rwh) {
Ella Ge80a52dce2017-11-15 18:01:524113 source_rwh->DragSourceEndedAt(gfx::PointF(client_x, client_y),
4114 gfx::PointF(screen_x, screen_y), operation);
Paul Meyer0c58c3712016-11-17 22:59:514115 }
[email protected]cf200a562013-05-03 16:24:294116}
4117
jam73f892642016-09-11 06:04:064118void WebContentsImpl::LoadStateChanged(
Charles Harrison911fa062018-03-06 21:01:464119 const std::string& host,
jam73f892642016-09-11 06:04:064120 const net::LoadStateWithParam& load_state,
4121 uint64_t upload_position,
4122 uint64_t upload_size) {
Charles Harrison911fa062018-03-06 21:01:464123 base::string16 host16 = url_formatter::IDNToUnicode(host);
Elly Fong-Jonescad9c3d12018-01-31 17:26:104124 // Drop no-op updates.
4125 if (load_state_.state == load_state.state &&
4126 load_state_.param == load_state.param &&
4127 upload_position_ == upload_position && upload_size_ == upload_size &&
Charles Harrison911fa062018-03-06 21:01:464128 load_state_host_ == host16) {
Elly Fong-Jonescad9c3d12018-01-31 17:26:104129 return;
4130 }
jam73f892642016-09-11 06:04:064131 load_state_ = load_state;
4132 upload_position_ = upload_position;
4133 upload_size_ = upload_size;
Charles Harrison911fa062018-03-06 21:01:464134 load_state_host_ = host16;
jam73f892642016-09-11 06:04:064135 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
4136 SetNotWaitingForResponse();
4137 if (IsLoading()) {
4138 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4139 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
4140 }
4141}
4142
Collin Baker989e0882019-11-01 01:27:174143void WebContentsImpl::SetVisibilityAndNotifyObservers(Visibility visibility) {
Francois Doraye6161152018-03-27 22:05:374144 const Visibility previous_visibility = visibility_;
4145 visibility_ = visibility;
4146
Francois Dorayfe4a1772018-02-17 04:17:094147 // Notify observers if the visibility changed or if WasShown() is being called
4148 // for the first time.
Francois Dorayfe4a1772018-02-17 04:17:094149 if (visibility != previous_visibility ||
4150 (visibility == Visibility::VISIBLE && !did_first_set_visible_)) {
4151 for (auto& observer : observers_)
4152 observer.OnVisibilityChanged(visibility);
4153 }
4154}
4155
Michael Thiessen896405db2017-07-20 17:52:324156void WebContentsImpl::NotifyWebContentsFocused(
4157 RenderWidgetHost* render_widget_host) {
ericwilligersde386342016-10-19 02:35:094158 for (auto& observer : observers_)
Michael Thiessen896405db2017-07-20 17:52:324159 observer.OnWebContentsFocused(render_widget_host);
calamity7fe55ce2015-04-10 03:59:374160}
4161
Michael Thiessen896405db2017-07-20 17:52:324162void WebContentsImpl::NotifyWebContentsLostFocus(
4163 RenderWidgetHost* render_widget_host) {
zijiehe3bee08e22017-05-17 04:14:464164 for (auto& observer : observers_)
Michael Thiessen896405db2017-07-20 17:52:324165 observer.OnWebContentsLostFocus(render_widget_host);
zijiehe3bee08e22017-05-17 04:14:464166}
4167
Paul Meyer0c58c3712016-11-17 22:59:514168void WebContentsImpl::SystemDragEnded(RenderWidgetHost* source_rwh) {
4169 if (source_rwh)
4170 source_rwh->DragSourceSystemDragEnded();
Lei Zhang6410ec1a2019-01-31 21:38:584171 if (browser_plugin_embedder_)
[email protected]cf200a562013-05-03 16:24:294172 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:344173}
4174
[email protected]b172aee2012-04-10 17:05:264175void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:274176 closed_by_user_gesture_ = value;
4177}
4178
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:414179bool WebContentsImpl::GetClosedByUserGesture() {
[email protected]0bfbf882011-12-22 18:19:274180 return closed_by_user_gesture_;
4181}
4182
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:414183int WebContentsImpl::GetMinimumZoomPercent() {
[email protected]0bfbf882011-12-22 18:19:274184 return minimum_zoom_percent_;
4185}
4186
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:414187int WebContentsImpl::GetMaximumZoomPercent() {
[email protected]0bfbf882011-12-22 18:19:274188 return maximum_zoom_percent_;
4189}
4190
Dave Tapuska8f7c3872020-02-07 01:16:384191void WebContentsImpl::SetPageScale(float scale_factor) {
4192 GetMainFrame()->GetAssociatedLocalMainFrame()->SetScaleFactor(scale_factor);
ccameronb7c1d6c2015-03-09 17:08:244193}
4194
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:414195gfx::Size WebContentsImpl::GetPreferredSize() {
Francois Doray24fc62c2017-12-11 17:27:334196 return IsBeingCaptured() ? preferred_size_for_capture_ : preferred_size_;
[email protected]bcd2815602012-01-14 18:17:234197}
4198
[email protected]b172aee2012-04-10 17:05:264199bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
lfgf0cd46e2017-01-04 00:05:234200 if (mouse_lock_widget_) {
4201 if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) {
4202 return mouse_lock_widget_->delegate()
4203 ->GetAsWebContents()
4204 ->GotResponseToLockMouseRequest(allowed);
4205 }
lfgad8244352016-07-13 16:55:514206
lfgf0cd46e2017-01-04 00:05:234207 if (mouse_lock_widget_->GotResponseToLockMouseRequest(allowed))
4208 return true;
4209 }
4210
4211 for (WebContentsImpl* current = this; current;
4212 current = current->GetOuterWebContents()) {
4213 current->mouse_lock_widget_ = nullptr;
4214 }
4215
lfgbee1e0a2016-06-08 21:24:214216 return false;
[email protected]0bfbf882011-12-22 18:19:274217}
4218
Joe Downing13dd76b2018-04-09 18:32:154219bool WebContentsImpl::GotResponseToKeyboardLockRequest(bool allowed) {
4220 if (!keyboard_lock_widget_)
4221 return false;
4222
4223 if (keyboard_lock_widget_->delegate()->GetAsWebContents() != this) {
4224 NOTREACHED();
4225 return false;
4226 }
4227
4228 // KeyboardLock is only supported when called by the top-level browsing
4229 // context and is not supported in embedded content scenarios.
4230 if (GetOuterWebContents())
4231 return false;
4232
4233 keyboard_lock_widget_->GotResponseToKeyboardLockRequest(allowed);
4234 return true;
4235}
4236
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:414237bool WebContentsImpl::HasOpener() {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:284238 return GetOpener() != nullptr;
[email protected]a0358d72012-03-09 14:06:504239}
4240
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:414241RenderFrameHostImpl* WebContentsImpl::GetOpener() {
alexmose201c7cd2015-06-10 17:14:214242 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
lukasza6f8ac622017-06-06 03:10:204243 return opener_ftn ? opener_ftn->current_frame_host() : nullptr;
jochen55ff3502014-12-18 20:52:574244}
4245
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:414246bool WebContentsImpl::HasOriginalOpener() {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:284247 return GetOriginalOpener() != nullptr;
jochen6004a362017-02-04 00:11:404248}
4249
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:414250RenderFrameHostImpl* WebContentsImpl::GetOriginalOpener() {
jochen6004a362017-02-04 00:11:404251 FrameTreeNode* opener_ftn = frame_tree_.root()->original_opener();
lukasza6f8ac622017-06-06 03:10:204252 return opener_ftn ? opener_ftn->current_frame_host() : nullptr;
jochen6004a362017-02-04 00:11:404253}
4254
[email protected]cb805452013-05-22 15:16:214255void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
Joel Hockey85b379d2017-12-11 10:42:134256 color_chooser_->DidChooseColorInColorChooser(color);
[email protected]da8543762012-03-20 08:52:204257}
4258
[email protected]cb805452013-05-22 15:16:214259void WebContentsImpl::DidEndColorChooser() {
Joel Hockey85b379d2017-12-11 10:42:134260 color_chooser_.reset();
[email protected]da8543762012-03-20 08:52:204261}
4262
halton.huoca2eabd2015-07-06 08:17:404263int WebContentsImpl::DownloadImage(
4264 const GURL& url,
4265 bool is_favicon,
Fredrik Söderquistb2b39eb92019-11-18 16:16:504266 uint32_t preferred_size,
halton.huoca2eabd2015-07-06 08:17:404267 uint32_t max_bitmap_size,
4268 bool bypass_cache,
Avi Drissmana5a52dd2018-03-27 03:39:024269 WebContents::ImageDownloadCallback callback) {
amistry9f01b772015-07-29 01:54:554270 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:404271 static int next_image_download_id = 0;
Julie Jeongeun Kimb1473572019-08-15 05:59:134272 const mojo::Remote<blink::mojom::ImageDownloader>& mojo_image_downloader =
halton.huoca2eabd2015-07-06 08:17:404273 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:554274 const int download_id = ++next_image_download_id;
4275 if (!mojo_image_downloader) {
4276 // If the renderer process is dead (i.e. crash, or memory pressure on
4277 // Android), the downloader service will be invalid. Pre-Mojo, this would
Avi Drissmana5a52dd2018-03-27 03:39:024278 // hang the callback indefinitely since the IPC would be dropped. Now,
amistry9f01b772015-07-29 01:54:554279 // respond with a 400 HTTP error code to indicate that something went wrong.
Sami Kyostila8e4d5a92019-08-02 12:45:054280 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:284281 FROM_HERE, {BrowserThread::UI},
tzike2aca992017-09-05 08:50:544282 base::BindOnce(&WebContentsImpl::OnDidDownloadImage,
Avi Drissmana5a52dd2018-03-27 03:39:024283 weak_factory_.GetWeakPtr(), std::move(callback),
4284 download_id, url, 400, std::vector<SkBitmap>(),
4285 std::vector<gfx::Size>()));
amistry9f01b772015-07-29 01:54:554286 return download_id;
4287 }
4288
halton.huoca2eabd2015-07-06 08:17:404289 mojo_image_downloader->DownloadImage(
Fredrik Söderquistb2b39eb92019-11-18 16:16:504290 url, is_favicon, preferred_size, max_bitmap_size, bypass_cache,
tzike2aca992017-09-05 08:50:544291 base::BindOnce(&WebContentsImpl::OnDidDownloadImage,
Avi Drissmana5a52dd2018-03-27 03:39:024292 weak_factory_.GetWeakPtr(), std::move(callback),
4293 download_id, url));
amistry9f01b772015-07-29 01:54:554294 return download_id;
[email protected]795c28972012-12-06 06:13:394295}
4296
[email protected]36ec24f2014-01-09 00:32:084297void WebContentsImpl::Find(int request_id,
4298 const base::string16& search_text,
Rakina Zata Amni3f77dff2018-09-08 16:19:434299 blink::mojom::FindOptionsPtr options) {
thestig6057a6b22015-11-12 23:01:334300 // Cowardly refuse to search for no text.
4301 if (search_text.empty()) {
4302 NOTREACHED();
4303 return;
4304 }
4305
Rakina Zata Amni3f77dff2018-09-08 16:19:434306 GetOrCreateFindRequestManager()->Find(request_id, search_text,
4307 std::move(options));
[email protected]36ec24f2014-01-09 00:32:084308}
4309
4310void WebContentsImpl::StopFinding(StopFindAction action) {
paulmeyerfeafc2d2017-04-25 21:46:404311 if (FindRequestManager* manager = GetFindRequestManager())
4312 manager->StopFinding(action);
[email protected]36ec24f2014-01-09 00:32:084313}
4314
Tommy Steimel18360512017-11-01 00:38:194315bool WebContentsImpl::WasEverAudible() {
4316 return was_ever_audible_;
4317}
4318
Avi Drissmana5a52dd2018-03-27 03:39:024319void WebContentsImpl::GetManifest(GetManifestCallback callback) {
4320 manifest_manager_host_->GetManifest(std::move(callback));
mlamouriefdca9d2014-09-16 16:55:404321}
4322
bokanece34a82016-01-28 19:49:464323void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:534324 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:434325 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:464326 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:534327}
4328
Avi Drissmanced52b62019-08-14 21:25:464329void WebContentsImpl::ForSecurityDropFullscreen() {
4330 // There are two chains of WebContents to kick out of fullscreen.
4331 //
4332 // Chain 1, the inner/outer WebContents chain. If an inner WebContents has
4333 // done something that requires the browser to drop fullscreen, drop
4334 // fullscreen from it and any outer WebContents that may be in fullscreen.
4335 //
4336 // Chain 2, the opener WebContents chain. If a WebContents has done something
4337 // that requires the browser to drop fullscreen, drop fullscreen from any
4338 // WebContents that was involved in the chain of opening it.
4339 //
4340 // Note that these two chains don't interact, as only a top-level WebContents
4341 // can have an opener. This simplifies things.
4342
4343 WebContents* web_contents = this;
4344 while (web_contents) {
4345 if (web_contents->IsFullscreenForCurrentTab())
4346 web_contents->ExitFullscreen(true);
4347
4348 if (web_contents->HasOriginalOpener())
4349 web_contents = FromRenderFrameHost(web_contents->GetOriginalOpener());
4350 else
4351 web_contents = web_contents->GetOuterWebContents();
4352 }
4353}
4354
mariakhomenko44bdc4732015-04-29 01:55:384355void WebContentsImpl::ResumeLoadingCreatedWebContents() {
Nasko Oskov83a8cf92018-10-19 14:58:564356 if (delayed_load_url_params_.get()) {
4357 DCHECK(!delayed_open_url_params_);
4358 controller_.LoadURLWithParams(*delayed_load_url_params_.get());
4359 delayed_load_url_params_.reset(nullptr);
4360 return;
4361 }
4362
mariakhomenkoa4971c12015-07-21 19:04:374363 if (delayed_open_url_params_.get()) {
4364 OpenURL(*delayed_open_url_params_.get());
4365 delayed_open_url_params_.reset(nullptr);
4366 return;
4367 }
4368
mariakhomenko44bdc4732015-04-29 01:55:384369 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
4370 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:164371 if (is_resume_pending_) {
4372 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:134373 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:164374 GetMainFrame()->Init();
4375 }
mariakhomenko44bdc4732015-04-29 01:55:384376}
4377
[email protected]b172aee2012-04-10 17:05:264378bool WebContentsImpl::FocusLocationBarByDefault() {
Xiyuan Xia2a66b112018-12-06 15:52:164379 if (should_focus_location_bar_by_default_)
[email protected]0c9406632013-02-08 01:13:334380 return true;
Xiyuan Xia2a66b112018-12-06 15:52:164381
[email protected]0c9406632013-02-08 01:13:334382 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:274383}
4384
Tommy C. Li8bb5bf42019-01-18 18:45:514385void WebContentsImpl::SetFocusToLocationBar() {
[email protected]0bfbf882011-12-22 18:19:274386 if (delegate_)
Tommy C. Li8bb5bf42019-01-18 18:45:514387 delegate_->SetFocusToLocationBar();
[email protected]c40d6232011-03-25 00:16:214388}
4389
clamy0e119882015-07-31 16:12:334390void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484391 TRACE_EVENT1("navigation", "WebContentsImpl::DidStartNavigation",
4392 "navigation_handle", navigation_handle);
Mounir Lamouri7b4a1f232019-12-23 16:32:104393 favicon_urls_.clear();
4394
ericwilligersde386342016-10-19 02:35:094395 for (auto& observer : observers_)
4396 observer.DidStartNavigation(navigation_handle);
Becca Hughesd11d6502018-07-31 17:01:284397
4398 if (display_cutout_host_impl_)
4399 display_cutout_host_impl_->DidStartNavigation(navigation_handle);
Xiyuan Xia2a66b112018-12-06 15:52:164400
4401 if (navigation_handle->IsInMainFrame()) {
4402 // When the browser is started with about:blank as the startup URL, focus
4403 // the location bar (which will also select its contents) so people can
4404 // simply begin typing to navigate elsewhere.
4405 //
4406 // We need to be careful not to trigger this for anything other than the
4407 // startup navigation. In particular, if we allow an attacker to open a
4408 // popup to about:blank, then navigate, focusing the Omnibox will cause the
4409 // end of the new URL to be scrolled into view instead of the start,
4410 // allowing the attacker to spoof other URLs. The conditions checked here
4411 // are all aimed at ensuring no such attacker-controlled navigation can
4412 // trigger this.
4413 should_focus_location_bar_by_default_ =
4414 controller_.IsInitialNavigation() &&
4415 !navigation_handle->IsRendererInitiated() &&
4416 navigation_handle->GetURL() == url::kAboutBlankURL;
4417 }
clamy0e119882015-07-31 16:12:334418}
4419
4420void WebContentsImpl::DidRedirectNavigation(
4421 NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484422 TRACE_EVENT1("navigation", "WebContentsImpl::DidRedirectNavigation",
4423 "navigation_handle", navigation_handle);
ericwilligersde386342016-10-19 02:35:094424 for (auto& observer : observers_)
4425 observer.DidRedirectNavigation(navigation_handle);
jam5f358e52017-02-13 16:37:034426
4427 // Notify accessibility if this is a reload. This has to called on the
4428 // BrowserAccessibilityManager associated with the old RFHI.
4429 if (navigation_handle->GetReloadType() != ReloadType::NONE) {
Mohamed Abdelhalim95794962019-09-20 11:16:494430 NavigationRequest* request = NavigationRequest::From(navigation_handle);
jam5f358e52017-02-13 16:37:034431 BrowserAccessibilityManager* manager =
Mohamed Abdelhalim95794962019-09-20 11:16:494432 request->frame_tree_node()
jam5f358e52017-02-13 16:37:034433 ->current_frame_host()
4434 ->browser_accessibility_manager();
4435 if (manager)
4436 manager->UserIsReloading();
4437 }
clamy0e119882015-07-31 16:12:334438}
4439
clamyefca29e2015-09-17 00:22:114440void WebContentsImpl::ReadyToCommitNavigation(
4441 NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484442 TRACE_EVENT1("navigation", "WebContentsImpl::ReadyToCommitNavigation",
4443 "navigation_handle", navigation_handle);
ericwilligersde386342016-10-19 02:35:094444 for (auto& observer : observers_)
4445 observer.ReadyToCommitNavigation(navigation_handle);
John Abd-El-Malekd4882642017-12-04 21:45:194446
Kenneth Russell954ed9ce2018-04-12 23:07:014447 // If any domains are blocked from accessing 3D APIs because they may
4448 // have caused the GPU to reset recently, unblock them here if the user
4449 // initiated this navigation. This implies that the user was involved in
4450 // the decision to navigate, so there's no concern about
4451 // denial-of-service issues. Want to do this as early as
4452 // possible to avoid race conditions with pages attempting to access
4453 // WebGL early on.
4454 //
4455 // TODO(crbug.com/617904): currently navigations initiated by the browser
4456 // (reload button, reload menu option, pressing return in the Omnibox)
4457 // return false from HasUserGesture(). If or when that is addressed,
4458 // remove the check for IsRendererInitiated() below.
4459 //
4460 // TODO(crbug.com/832180): HasUserGesture comes from the renderer
4461 // process and isn't validated. Until it is, don't trust it.
4462 if (!navigation_handle->IsRendererInitiated()) {
4463 GpuDataManagerImpl::GetInstance()->UnblockDomainFrom3DAPIs(
4464 navigation_handle->GetURL());
4465 }
4466
John Abd-El-Malekfde08e6da2017-12-05 04:06:244467 if (navigation_handle->IsSameDocument())
4468 return;
4469
Livvie Lin139bf442018-08-10 00:18:544470 // SSLInfo is not needed on subframe navigations since the main-frame
4471 // certificate is the only one that can be inspected (using the info
4472 // bubble) without refreshing the page with DevTools open.
Carlos ILaed1e7b2019-03-12 19:27:214473 // We don't call DidStartResourceResponse on net errors, since that results on
4474 // existing cert exceptions being revoked, which leads to weird behavior with
4475 // committed interstitials or while offline. We only need the error check for
4476 // the main frame case because unlike this method, SubresourceResponseStarted
4477 // does not get called on network errors.
4478 if (navigation_handle->IsInMainFrame() &&
4479 navigation_handle->GetNetErrorCode() == net::OK) {
Livvie Lin139bf442018-08-10 00:18:544480 controller_.ssl_manager()->DidStartResourceResponse(
Lukasz Anforowiczd334bba2020-02-10 23:32:554481 navigation_handle->GetURL(),
Camille Lamy62b826012019-02-26 09:15:474482 navigation_handle->GetSSLInfo().has_value()
4483 ? net::IsCertStatusError(
4484 navigation_handle->GetSSLInfo()->cert_status)
4485 : false);
4486 }
John Abd-El-Malekfde08e6da2017-12-05 04:06:244487
4488 SetNotWaitingForResponse();
clamyefca29e2015-09-17 00:22:114489}
4490
clamy0e119882015-07-31 16:12:334491void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
Charles Harrison53096ba2017-12-15 15:39:484492 TRACE_EVENT1("navigation", "WebContentsImpl::DidFinishNavigation",
4493 "navigation_handle", navigation_handle);
Steven Holte38041342018-06-22 22:00:574494
ericwilligersde386342016-10-19 02:35:094495 for (auto& observer : observers_)
4496 observer.DidFinishNavigation(navigation_handle);
clamy0e119882015-07-31 16:12:334497
Becca Hughesd11d6502018-07-31 17:01:284498 if (display_cutout_host_impl_)
4499 display_cutout_host_impl_->DidFinishNavigation(navigation_handle);
4500
jam5f358e52017-02-13 16:37:034501 if (navigation_handle->HasCommitted()) {
Ian Prestcdd843d2020-01-28 18:59:584502 // TODO(domfarolino, dmazzoni): Do this using WebContentsObserver. See
4503 // https://crbug.com/981271.
4504 BrowserAccessibilityManager* manager =
4505 static_cast<RenderFrameHostImpl*>(
4506 navigation_handle->GetRenderFrameHost())
4507 ->browser_accessibility_manager();
4508 if (manager) {
4509 if (navigation_handle->IsErrorPage()) {
4510 manager->NavigationFailed();
4511 } else {
4512 manager->NavigationSucceeded();
4513 }
4514 }
4515
Yue Ru Sun979c4b162019-11-06 16:11:044516 if (navigation_handle->IsInMainFrame()) {
4517 last_committed_source_id_including_same_document_ =
Steven Holte38041342018-06-22 22:00:574518 ukm::ConvertToSourceId(navigation_handle->GetNavigationId(),
4519 ukm::SourceIdType::NAVIGATION_ID);
Yue Ru Sun979c4b162019-11-06 16:11:044520
4521 if (!navigation_handle->IsSameDocument()) {
4522 was_ever_audible_ = false;
4523 last_committed_source_id_ =
4524 last_committed_source_id_including_same_document_;
4525 }
Tommy Steimel18360512017-11-01 00:38:194526 }
Lan Weif81c6e7c2020-02-12 16:46:094527
4528 if (!navigation_handle->IsSameDocument())
4529 last_screen_orientation_change_time_ = base::TimeTicks();
dmazzonibf8cec42015-02-08 08:28:084530 }
Xiyuan Xia2a66b112018-12-06 15:52:164531
4532 // If we didn't end up on about:blank after setting this in DidStartNavigation
4533 // then don't focus the location bar.
4534 if (should_focus_location_bar_by_default_ &&
4535 navigation_handle->GetURL() != url::kAboutBlankURL) {
4536 should_focus_location_bar_by_default_ = false;
4537 }
yilkal796e89e2019-10-02 23:58:284538
yilkal172da772019-11-06 22:49:074539 if (navigation_handle->IsInMainFrame() && first_navigation_completed_)
4540 RecordMaxFrameCountUMA(max_loaded_frame_count_);
yilkal796e89e2019-10-02 23:58:284541
yilkal172da772019-11-06 22:49:074542 // If navigation has successfully finished in the main frame, set
4543 // |first_navigation_completed_| to true so that we will record
4544 // |max_loaded_frame_count_| above when future main frame navigations finish.
4545 if (navigation_handle->IsInMainFrame() && !navigation_handle->IsErrorPage()) {
4546 first_navigation_completed_ = true;
4547
4548 // Navigation has completed in main frame. Reset |max_loaded_frame_count_|.
4549 // |max_loaded_frame_count_| is not necessarily 1 if the navigation was
4550 // served from BackForwardCache.
4551 max_loaded_frame_count_ =
4552 GetMainFrame()->frame_tree_node()->GetFrameTreeSize();
yilkal796e89e2019-10-02 23:58:284553 }
[email protected]400992b2012-06-14 00:03:544554}
4555
[email protected]b80624c2014-02-09 02:46:554556void WebContentsImpl::DidFailLoadWithError(
4557 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:554558 const GURL& url,
Dave Tapuska924ef3c2020-01-22 18:20:594559 int error_code) {
ericwilligersde386342016-10-19 02:35:094560 for (auto& observer : observers_) {
Dave Tapuska924ef3c2020-01-22 18:20:594561 observer.DidFailLoad(render_frame_host, url, error_code);
ericwilligersde386342016-10-19 02:35:094562 }
[email protected]b80624c2014-02-09 02:46:554563}
4564
[email protected]52913802013-12-10 05:52:184565void WebContentsImpl::NotifyChangedNavigationState(
4566 InvalidateTypes changed_flags) {
4567 NotifyNavigationStateChanged(changed_flags);
4568}
4569
toyoshim0df1d3a2016-09-09 09:52:484570void WebContentsImpl::DidStartNavigationToPendingEntry(const GURL& url,
4571 ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:204572 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:094573 for (auto& observer : observers_)
4574 observer.DidStartNavigationToPendingEntry(url, reload_type);
[email protected]3691e5cf2014-01-22 10:16:204575}
4576
lukasza1d025732016-09-28 21:36:084577bool WebContentsImpl::ShouldTransferNavigation(bool is_main_frame_navigation) {
creis29460272015-12-16 04:38:224578 if (!delegate_)
4579 return true;
lukasza1d025732016-09-28 21:36:084580 return delegate_->ShouldTransferNavigation(is_main_frame_navigation);
creis29460272015-12-16 04:38:224581}
4582
[email protected]aa62afd2014-04-22 19:22:464583bool WebContentsImpl::ShouldPreserveAbortedURLs() {
4584 if (!delegate_)
4585 return false;
4586 return delegate_->ShouldPreserveAbortedURLs(this);
4587}
4588
[email protected]0d0f4c492014-04-02 06:42:574589void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:234590 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:574591 // Ensure fullscreen mode is exited before committing the navigation to a
4592 // different page. The next page will not start out assuming it is in
4593 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:234594 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:194595 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:574596 return;
4597 }
alexmos5dd617d2016-06-07 04:21:154598 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:464599 ExitFullscreen(false);
alexmos5dd617d2016-06-07 04:21:154600 DCHECK(!IsFullscreenForCurrentTab());
Joe Downingc1a57efe2018-05-09 18:23:544601
4602 // Clean up keyboard lock state when navigating.
4603 CancelKeyboardLock(keyboard_lock_widget_);
[email protected]0d0f4c492014-04-02 06:42:574604}
4605
[email protected]37567b432014-02-12 01:12:224606void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:284607 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:224608 const LoadCommittedDetails& details,
4609 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
4610 if (details.is_navigation_to_different_page()) {
4611 // Clear the status bubble. This is a workaround for a bug where WebKit
4612 // doesn't let us know that the cursor left an element during a
4613 // transition (this is also why the mouse cursor remains as a hand after
4614 // clicking on a link); see bugs 1184641 and 980803. We don't want to
4615 // clear the bubble when a user navigates to a named anchor in the same
4616 // page.
Lukasz Anforowiczfd707142018-02-07 19:46:134617 ClearTargetURL();
lanwei9d343ad22015-02-11 01:46:004618
4619 RenderWidgetHostViewBase* rwhvb =
4620 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
4621 if (rwhvb)
4622 rwhvb->OnDidNavigateMainFrameToNewPage();
[email protected]37567b432014-02-12 01:12:224623 }
4624
[email protected]e85165c642014-06-10 14:34:314625 if (delegate_)
[email protected]37567b432014-02-12 01:12:224626 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:314627 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
Shivani Sharma985474f2019-05-23 21:36:474628
4629 if (!details.is_same_document && GetInnerWebContents().empty())
4630 had_inner_webcontents_ = false;
Carlos Caballero91fffb22019-10-29 15:24:304631
4632 if (details.is_navigation_to_different_page() &&
4633 GetRenderViewHost()->did_first_visually_non_empty_paint()) {
4634 // This event will not fire again if the page is restored from the
4635 // BackForwardCache. So fire it ourselves if needed.
4636 DidFirstVisuallyNonEmptyPaint(GetRenderViewHost());
4637 }
Carlos Caballero1215f882019-10-29 15:58:434638
4639 if (GetRenderViewHost()->theme_color() != last_sent_theme_color_) {
4640 // This event will not fire again if the page is restored from the
4641 // BackForwardCache. So fire it ourselves if needed.
4642 OnThemeColorChanged(GetRenderViewHost());
4643 }
[email protected]37567b432014-02-12 01:12:224644}
4645
4646void WebContentsImpl::DidNavigateAnyFramePostCommit(
4647 RenderFrameHostImpl* render_frame_host,
4648 const LoadCommittedDetails& details,
4649 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:104650 // Now that something has committed, we don't need to track whether the
4651 // initial page has been accessed.
4652 has_accessed_initial_document_ = false;
4653
[email protected]37567b432014-02-12 01:12:224654 // If we navigate off the page, close all JavaScript dialogs.
eugenebutee08663a2017-04-27 17:43:124655 if (!details.is_same_document)
creis89a0f782015-05-27 16:13:174656 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:224657
avid53461d2016-02-25 17:15:044658 // If this is a user-initiated navigation, start allowing JavaScript dialogs
4659 // again.
avi5d3b8692016-10-12 22:00:464660 if (params.gesture == NavigationGestureUser && dialog_manager_) {
avi6879fcf2017-01-21 05:27:534661 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:464662 }
[email protected]37567b432014-02-12 01:12:224663}
4664
4665void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
4666 contents_mime_type_ = mime_type;
4667}
4668
[email protected]277857a2014-06-03 10:38:014669bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:314670 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:054671 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:314672 return false;
4673
[email protected]37567b432014-02-12 01:12:224674 if (delegate_)
4675 return delegate_->CanOverscrollContent();
4676
4677 return false;
4678}
4679
Carlos Caballero1215f882019-10-29 15:58:434680void WebContentsImpl::OnThemeColorChanged(RenderViewHostImpl* source) {
4681 if (source->did_first_visually_non_empty_paint() &&
4682 last_sent_theme_color_ != source->theme_color()) {
ericwilligersde386342016-10-19 02:35:094683 for (auto& observer : observers_)
Peter Kastingb14e5782020-01-06 23:55:044684 observer.DidChangeThemeColor();
Carlos Caballero1215f882019-10-29 15:58:434685 last_sent_theme_color_ = source->theme_color();
peter90afaba2015-06-01 12:05:294686 }
[email protected]e7104762014-06-20 19:17:254687}
4688
[email protected]b172aee2012-04-10 17:05:264689void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
nicka0ac8382016-12-15 23:59:234690 RenderFrameHostImpl* source,
[email protected]724159a2010-12-30 01:11:184691 const GURL& url,
[email protected]70435962011-08-02 20:13:284692 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:184693 const std::string& mime_type,
Kinuko Yasuda433f710a2020-02-14 02:11:584694 network::mojom::RequestDestination request_destination) {
ericwilligersde386342016-10-19 02:35:094695 for (auto& observer : observers_)
Kinuko Yasuda433f710a2020-02-14 02:11:584696 observer.DidLoadResourceFromMemoryCache(url, mime_type,
4697 request_destination);
[email protected]b0f724c2013-09-05 04:21:134698
Steven Bingler674fb0822018-12-12 18:04:524699 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
nicka0ac8382016-12-15 23:59:234700 StoragePartition* partition = source->GetProcess()->GetStoragePartition();
John Abd-El-Malekf4fe9d82019-07-31 04:05:594701 partition->GetNetworkContext()->NotifyExternalCacheHit(
Matt Menke2a33dee2019-12-02 17:01:544702 url, http_method, source->GetNetworkIsolationKey());
[email protected]8bfc8272013-09-09 20:10:534703 }
[email protected]724159a2010-12-30 01:11:184704}
4705
carloskd9d97942017-02-16 08:58:094706void WebContentsImpl::DidDisplayInsecureContent() {
estarkc2273502016-10-12 22:03:024707 controller_.ssl_manager()->DidDisplayMixedContent();
[email protected]724159a2010-12-30 01:11:184708}
4709
Dave Tapuskaa657d872019-10-21 20:23:214710void WebContentsImpl::DidContainInsecureFormAction() {
elawrenceb2ac2a232017-03-27 21:46:254711 controller_.ssl_manager()->DidContainInsecureFormAction();
4712}
4713
Julie Jeongeun Kim0b103492020-01-29 05:30:514714void WebContentsImpl::DocumentAvailableInMainFrame() {
4715 for (auto& observer : observers_)
4716 observer.DocumentAvailableInMainFrame();
4717}
4718
nicka0ac8382016-12-15 23:59:234719void WebContentsImpl::OnDidRunInsecureContent(RenderFrameHostImpl* source,
4720 const GURL& security_origin,
estark910b4572015-12-09 20:55:414721 const GURL& target_url) {
nicka0ac8382016-12-15 23:59:234722 // TODO(nick, estark): Should we call FilterURL using |source|'s process on
4723 // these parameters? |target_url| seems unused, except for a log message. And
4724 // |security_origin| might be replaceable with the origin of the main frame.
carloskd9d97942017-02-16 08:58:094725 DidRunInsecureContent(security_origin, target_url);
4726}
4727
4728void WebContentsImpl::DidRunInsecureContent(const GURL& security_origin,
4729 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:584730 LOG(WARNING) << security_origin << " ran insecure content from "
4731 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:394732 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:414733 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:294734 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:394735 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
estarkc2273502016-10-12 22:03:024736 controller_.ssl_manager()->DidRunMixedContent(security_origin);
[email protected]724159a2010-12-30 01:11:184737}
4738
carloskd9d97942017-02-16 08:58:094739void WebContentsImpl::PassiveInsecureContentFound(const GURL& resource_url) {
Sergey Kuznetsov3ebc01b2018-02-01 04:57:364740 if (delegate_) {
4741 delegate_->PassiveInsecureContentFound(resource_url);
4742 }
carloskd9d97942017-02-16 08:58:094743}
4744
4745bool WebContentsImpl::ShouldAllowRunningInsecureContent(
4746 WebContents* web_contents,
4747 bool allowed_per_prefs,
4748 const url::Origin& origin,
4749 const GURL& resource_url) {
Sergey Kuznetsov3ebc01b2018-02-01 04:57:364750 if (delegate_) {
4751 return delegate_->ShouldAllowRunningInsecureContent(
4752 web_contents, allowed_per_prefs, origin, resource_url);
4753 }
4754
4755 return allowed_per_prefs;
carloskd9d97942017-02-16 08:58:094756}
4757
Lukasz Anforowicze1b954d92017-10-30 21:28:064758void WebContentsImpl::ViewSource(RenderFrameHostImpl* frame) {
4759 DCHECK_EQ(this, WebContents::FromRenderFrameHost(frame));
4760
4761 // Don't do anything if there is no |delegate_| that could accept and show the
4762 // new WebContents containing the view-source.
4763 if (!delegate_)
4764 return;
4765
4766 // Use the last committed entry, since the pending entry hasn't loaded yet and
4767 // won't be copied into the cloned tab.
4768 NavigationEntryImpl* last_committed_entry =
4769 static_cast<NavigationEntryImpl*>(frame->frame_tree_node()
4770 ->navigator()
4771 ->GetController()
4772 ->GetLastCommittedEntry());
4773 if (!last_committed_entry)
4774 return;
4775
4776 FrameNavigationEntry* frame_entry =
4777 last_committed_entry->GetFrameEntry(frame->frame_tree_node());
4778 if (!frame_entry)
4779 return;
4780
4781 // Any new WebContents opened while this WebContents is in fullscreen can be
4782 // used to confuse the user, so drop fullscreen.
Avi Drissmand18c51972018-08-15 18:32:094783 ForSecurityDropFullscreen();
Lukasz Anforowicze1b954d92017-10-30 21:28:064784
4785 // We intentionally don't share the SiteInstance with the original frame so
4786 // that view source has a consistent process model and always ends up in a new
4787 // process (https://crbug.com/699493).
4788 scoped_refptr<SiteInstanceImpl> site_instance_for_view_source = nullptr;
Lukasz Anforowicz435bcb582019-07-12 20:50:064789 // Referrer and initiator are not important, because view-source should not
4790 // hit the network, but should be served from the cache instead.
Lukasz Anforowicze1b954d92017-10-30 21:28:064791 Referrer referrer_for_view_source;
Lukasz Anforowicz435bcb582019-07-12 20:50:064792 base::Optional<url::Origin> initiator_for_view_source = base::nullopt;
Lukasz Anforowicze1b954d92017-10-30 21:28:064793 // Do not restore title, derive it from the url.
4794 base::string16 title_for_view_source;
4795 auto navigation_entry = std::make_unique<NavigationEntryImpl>(
4796 site_instance_for_view_source, frame_entry->url(),
Lukasz Anforowicz435bcb582019-07-12 20:50:064797 referrer_for_view_source, initiator_for_view_source,
4798 title_for_view_source, ui::PAGE_TRANSITION_LINK,
Marijn Kruisselbrink7a0d5e182018-05-24 22:55:094799 /* is_renderer_initiated = */ false,
4800 /* blob_url_loader_factory = */ nullptr);
Lukasz Anforowicze1b954d92017-10-30 21:28:064801 navigation_entry->SetVirtualURL(GURL(content::kViewSourceScheme +
4802 std::string(":") +
4803 frame_entry->url().spec()));
4804
Matt Menke2a33dee2019-12-02 17:01:544805 navigation_entry->set_network_isolation_key(frame->GetNetworkIsolationKey());
Yao Xiaof68f57d2019-10-03 04:20:054806
Lukasz Anforowicze1b954d92017-10-30 21:28:064807 // Do not restore scroller position.
4808 // TODO(creis, lukasza, arthursonzogni): Do not reuse the original PageState,
4809 // but start from a new one and only copy the needed data.
4810 const PageState& new_page_state =
4811 frame_entry->page_state().RemoveScrollOffset();
4812
4813 scoped_refptr<FrameNavigationEntry> new_frame_entry =
4814 navigation_entry->root_node()->frame_entry;
4815 new_frame_entry->set_method(frame_entry->method());
4816 new_frame_entry->SetPageState(new_page_state);
4817
4818 // Create a new WebContents, which is used to display the source code.
erikchenbee5c9622018-04-27 19:30:254819 std::unique_ptr<WebContents> view_source_contents =
Erik Chenbb8e738e2018-04-28 14:10:434820 Create(CreateParams(GetBrowserContext()));
Lukasz Anforowicze1b954d92017-10-30 21:28:064821
4822 // Restore the previously created NavigationEntry.
4823 std::vector<std::unique_ptr<NavigationEntry>> navigation_entries;
4824 navigation_entries.push_back(std::move(navigation_entry));
4825 view_source_contents->GetController().Restore(0, RestoreType::CURRENT_SESSION,
4826 &navigation_entries);
4827
4828 // Add |view_source_contents| as a new tab.
4829 gfx::Rect initial_rect;
4830 constexpr bool kUserGesture = true;
4831 bool ignored_was_blocked;
erikchenbee5c9622018-04-27 19:30:254832 delegate_->AddNewContents(this, std::move(view_source_contents),
Lukasz Anforowicze1b954d92017-10-30 21:28:064833 WindowOpenDisposition::NEW_FOREGROUND_TAB,
4834 initial_rect, kUserGesture, &ignored_was_blocked);
4835 // Note that the |delegate_| could have deleted |view_source_contents| during
4836 // AddNewContents method call.
4837}
4838
Lukasz Anforowiczd334bba2020-02-10 23:32:554839void WebContentsImpl::SubresourceResponseStarted(const GURL& url,
4840 net::CertStatus cert_status) {
4841 controller_.ssl_manager()->DidStartResourceResponse(url, cert_status);
Jay Civellid5904f02018-03-23 19:43:574842 SetNotWaitingForResponse();
4843}
4844
Jay Civelli116683f2018-03-27 19:56:234845void WebContentsImpl::ResourceLoadComplete(
Jay Civelli52a63302018-04-30 22:39:554846 RenderFrameHost* render_frame_host,
Clark DuVall36164bd2018-08-09 22:49:084847 const GlobalRequestID& request_id,
Minggang Wangee5af392020-02-05 02:55:284848 blink::mojom::ResourceLoadInfoPtr resource_load_info) {
John Abd-El-Malek9b8f7fa2017-12-04 23:52:254849 for (auto& observer : observers_) {
Clark DuVall36164bd2018-08-09 22:49:084850 observer.ResourceLoadComplete(render_frame_host, request_id,
4851 *resource_load_info);
John Abd-El-Malek9b8f7fa2017-12-04 23:52:254852 }
John Abd-El-Malekd4882642017-12-04 21:45:194853}
4854
Wei Li5bb659742018-02-14 03:07:584855void WebContentsImpl::PrintCrossProcessSubframe(
4856 const gfx::Rect& rect,
4857 int document_cookie,
4858 RenderFrameHost* subframe_host) {
Wei Li5c0b4d12018-03-22 15:05:224859 auto* outer_contents = GetOuterWebContents();
4860 if (outer_contents) {
4861 // When an extension or app page is printed, the content should be
4862 // composited with outer content, so the outer contents should handle the
4863 // print request.
4864 outer_contents->PrintCrossProcessSubframe(rect, document_cookie,
4865 subframe_host);
4866 return;
4867 }
4868
Wei Li5bb659742018-02-14 03:07:584869 // If there is no delegate such as in tests or during deletion, do nothing.
4870 if (!delegate_)
4871 return;
4872
4873 delegate_->PrintCrossProcessSubframe(this, rect, document_cookie,
4874 subframe_host);
4875}
4876
ckitagawa8695799b2020-02-05 16:08:494877void WebContentsImpl::CapturePaintPreviewOfCrossProcessSubframe(
4878 const gfx::Rect& rect,
4879 const base::UnguessableToken& guid,
4880 RenderFrameHost* render_frame_host) {
4881 if (!delegate_)
4882 return;
4883 delegate_->CapturePaintPreviewOfCrossProcessSubframe(this, rect, guid,
4884 render_frame_host);
4885}
4886
rob.buis300b0872017-03-10 20:43:584887#if defined(OS_ANDROID)
4888base::android::ScopedJavaLocalRef<jobject>
4889WebContentsImpl::GetJavaRenderFrameHostDelegate() {
4890 return GetJavaWebContents();
4891}
4892#endif
4893
estark910b4572015-12-09 20:55:414894void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
Zhuoyu Qian4353f7f2018-01-08 05:33:004895 RenderFrameHostImpl* source) {
estarkc2273502016-10-12 22:03:024896 controller_.ssl_manager()->DidDisplayContentWithCertErrors();
estark910b4572015-12-09 20:55:414897}
4898
4899void WebContentsImpl::OnDidRunContentWithCertificateErrors(
Zhuoyu Qian4353f7f2018-01-08 05:33:004900 RenderFrameHostImpl* source) {
nicka0ac8382016-12-15 23:59:234901 // TODO(nick, estark): Do we need to consider |source| here somehow?
estarkcd2e30c2016-08-12 06:51:154902 NavigationEntry* entry = controller_.GetVisibleEntry();
4903 if (!entry)
estarkaeda1422016-05-10 02:31:124904 return;
4905
estarkaeda1422016-05-10 02:31:124906 // TODO(estark): check that this does something reasonable for
4907 // about:blank and sandboxed origins. https://crbug.com/609527
estarkcd2e30c2016-08-12 06:51:154908 controller_.ssl_manager()->DidRunContentWithCertErrors(
4909 entry->GetURL().GetOrigin());
estark910b4572015-12-09 20:55:414910}
4911
Kouhei Ueno97e0990d2019-09-25 02:57:274912void WebContentsImpl::DOMContentLoaded(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:094913 for (auto& observer : observers_)
Kouhei Uenof6e96242019-09-27 01:54:354914 observer.DOMContentLoaded(render_frame_host);
[email protected]724159a2010-12-30 01:11:184915}
4916
nicka0ac8382016-12-15 23:59:234917void WebContentsImpl::OnDidFinishLoad(RenderFrameHostImpl* source,
4918 const GURL& url) {
[email protected]8b3af1e2014-01-24 13:29:124919 GURL validated_url(url);
nicka0ac8382016-12-15 23:59:234920 source->GetProcess()->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:374921
ericwilligersde386342016-10-19 02:35:094922 for (auto& observer : observers_)
nicka0ac8382016-12-15 23:59:234923 observer.DidFinishLoad(source, validated_url);
yilkal172da772019-11-06 22:49:074924
4925 size_t tree_size = frame_tree_.root()->GetFrameTreeSize();
4926 if (max_loaded_frame_count_ < tree_size)
4927 max_loaded_frame_count_ = tree_size;
4928
4929 if (!source->GetParent())
4930 UMA_HISTOGRAM_COUNTS_1000("Navigation.MainFrame.FrameCount", tree_size);
[email protected]1a55c5be2011-11-29 11:36:314931}
4932
Dave Tapuska549baab2019-03-19 15:52:404933void WebContentsImpl::OnGoToEntryAtOffset(RenderFrameHostImpl* source,
Julie Jeongeun Kim144f8192020-01-18 06:59:034934 int32_t offset,
Dave Tapuska043b94a2019-09-10 14:14:354935 bool has_user_gesture) {
Arthur Sonzognia7d715a2018-09-20 16:11:134936 // Non-user initiated navigations coming from the renderer should be ignored
4937 // if there is an ongoing browser-initiated navigation.
4938 // See https://crbug.com/879965.
4939 // TODO(arthursonzogni): See if this should check for ongoing navigations in
4940 // the frame(s) affected by the session history navigation, rather than just
4941 // the main frame.
4942 if (!has_user_gesture) {
4943 NavigationRequest* ongoing_navigation_request =
4944 frame_tree_.root()->navigation_request();
4945 if (ongoing_navigation_request &&
4946 ongoing_navigation_request->browser_initiated()) {
4947 return;
4948 }
4949 }
4950
nicka0ac8382016-12-15 23:59:234951 // All frames are allowed to navigate the global history.
Dave Tapuska8bfd84c2019-03-26 20:47:164952 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
Antonio Gomes7096ac02020-02-14 14:29:544953 if (source->IsSandboxed(blink::mojom::WebSandboxFlags::kTopNavigation)) {
Dave Tapuska8bfd84c2019-03-26 20:47:164954 // Keep track of whether this is a session history from a sandboxed iframe
4955 // with top level navigation disallowed.
4956 controller_.GoToOffsetInSandboxedFrame(offset,
4957 source->GetFrameTreeNodeId());
4958 } else {
4959 controller_.GoToOffset(offset);
4960 }
4961 }
[email protected]216813952011-05-19 22:21:264962}
4963
nicka0ac8382016-12-15 23:59:234964void WebContentsImpl::OnPageScaleFactorChanged(RenderViewHostImpl* source,
4965 float page_scale_factor) {
mcnee336ea2c2017-05-23 22:50:594966#if !defined(OS_ANDROID)
4967 // While page scale factor is used on mobile, this PageScaleFactorIsOne logic
4968 // is only needed on desktop.
mcnee432e47d2015-11-09 19:37:464969 bool is_one = page_scale_factor == 1.f;
4970 if (is_one != page_scale_factor_is_one_) {
4971 page_scale_factor_is_one_ = is_one;
4972
4973 HostZoomMapImpl* host_zoom_map =
4974 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
4975
nicka0ac8382016-12-15 23:59:234976 if (host_zoom_map) {
mcnee432e47d2015-11-09 19:37:464977 host_zoom_map->SetPageScaleFactorIsOneForView(
nicka0ac8382016-12-15 23:59:234978 source->GetProcess()->GetID(), source->GetRoutingID(),
mcnee432e47d2015-11-09 19:37:464979 page_scale_factor_is_one_);
4980 }
4981 }
mcnee336ea2c2017-05-23 22:50:594982#endif // !defined(OS_ANDROID)
mcnee432e47d2015-11-09 19:37:464983
ericwilligersde386342016-10-19 02:35:094984 for (auto& observer : observers_)
4985 observer.OnPageScaleFactorChanged(page_scale_factor);
mcnee432e47d2015-11-09 19:37:464986}
4987
W. James MacLean62198672019-06-04 16:46:104988void WebContentsImpl::OnTextAutosizerPageInfoChanged(
4989 RenderViewHostImpl* source,
4990 const blink::WebTextAutosizerPageInfo& page_info) {
4991 // Keep a copy of |page_info| in case we create a new RenderView before
4992 // the next update.
4993 text_autosizer_page_info_ = page_info;
4994 frame_tree_.root()->render_manager()->SendPageMessage(
4995 new PageMsg_UpdateTextAutosizerPageInfoForRemoteMainFrames(
4996 MSG_ROUTING_NONE, page_info),
4997 source->GetSiteInstance());
4998}
4999
Kent Tamura8c9e0562018-11-06 07:02:195000void WebContentsImpl::EnumerateDirectory(
5001 RenderFrameHost* render_frame_host,
5002 std::unique_ptr<FileSelectListener> listener,
5003 const base::FilePath& directory_path) {
5004 if (delegate_)
5005 delegate_->EnumerateDirectory(this, std::move(listener), directory_path);
5006 else
5007 listener->FileSelectionCanceled();
[email protected]3a29a6e2011-08-24 18:26:215008}
5009
Dave Tapuskaf9fc3122019-10-18 19:42:555010void WebContentsImpl::RegisterProtocolHandler(RenderFrameHostImpl* source,
5011 const std::string& protocol,
5012 const GURL& url,
5013 const base::string16& title,
5014 bool user_gesture) {
nicka0ac8382016-12-15 23:59:235015 // TODO(nick): Should we consider |source| here or pass it to the delegate?
5016 // TODO(nick): Do we need to apply FilterURL to |url|?
[email protected]e5f2de02012-07-20 22:15:435017 if (!delegate_)
5018 return;
5019
Raymes Khoury58373df2019-08-06 06:29:205020 if (!AreValidRegisterProtocolHandlerArguments(
5021 protocol, url, source->GetLastCommittedOrigin())) {
5022 ReceivedBadMessage(source->GetProcess(),
5023 bad_message::REGISTER_PROTOCOL_HANDLER_INVALID_URL);
[email protected]b9535422012-02-09 01:47:595024 return;
Raymes Khoury58373df2019-08-06 06:29:205025 }
[email protected]8f810632013-06-06 22:33:325026
[email protected]c125e532014-05-10 20:39:065027 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:205028}
5029
Dave Tapuskaf9fc3122019-10-18 19:42:555030void WebContentsImpl::UnregisterProtocolHandler(RenderFrameHostImpl* source,
5031 const std::string& protocol,
5032 const GURL& url,
5033 bool user_gesture) {
nicka0ac8382016-12-15 23:59:235034 // TODO(nick): Should we consider |source| here or pass it to the delegate?
5035 // TODO(nick): Do we need to apply FilterURL to |url|?
[email protected]f5273e52014-07-14 16:30:205036 if (!delegate_)
5037 return;
5038
Raymes Khoury58373df2019-08-06 06:29:205039 if (!AreValidRegisterProtocolHandlerArguments(
5040 protocol, url, source->GetLastCommittedOrigin())) {
5041 ReceivedBadMessage(source->GetProcess(),
5042 bad_message::REGISTER_PROTOCOL_HANDLER_INVALID_URL);
[email protected]f5273e52014-07-14 16:30:205043 return;
Raymes Khoury58373df2019-08-06 06:29:205044 }
[email protected]f5273e52014-07-14 16:30:205045
5046 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
5047}
5048
nicka0ac8382016-12-15 23:59:235049void WebContentsImpl::OnDomOperationResponse(RenderFrameHostImpl* source,
5050 const std::string& json_string) {
5051 // TODO(nick, lukasza): The notification below should probably be updated to
5052 // include |source|.
avi60bd4902015-09-23 20:39:245053 std::string json = json_string;
5054 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
5055 Source<WebContents>(this),
5056 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:405057}
5058
Marijn Kruisselbrink7f519672019-02-05 19:12:505059void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
[email protected]b172aee2012-04-10 17:05:265060 bool blocked_by_policy) {
nicka0ac8382016-12-15 23:59:235061 // TODO(nick): Should we consider |source| here? Should we call FilterURL on
5062 // |manifest_url|?
5063
[email protected]7fc4bbb2011-09-08 21:23:105064 // Notify observers about navigation.
ericwilligersde386342016-10-19 02:35:095065 for (auto& observer : observers_)
5066 observer.AppCacheAccessed(manifest_url, blocked_by_policy);
[email protected]7fc4bbb2011-09-08 21:23:105067}
5068
Miyoung Shincb6475a2019-11-09 10:49:455069void WebContentsImpl::OnColorChooserFactoryReceiver(
Julie Jeongeun Kim8e2879e2019-08-06 23:55:205070 mojo::PendingReceiver<blink::mojom::ColorChooserFactory> receiver) {
5071 color_chooser_factory_receivers_.Add(this, std::move(receiver));
Joel Hockey85b379d2017-12-11 10:42:135072}
5073
5074void WebContentsImpl::OpenColorChooser(
Julie Jeongeun Kim8e2879e2019-08-06 23:55:205075 mojo::PendingReceiver<blink::mojom::ColorChooser> chooser_receiver,
5076 mojo::PendingRemote<blink::mojom::ColorChooserClient> client,
[email protected]8ed16472014-04-11 19:02:485077 SkColor color,
Joel Hockey163835a2017-12-20 11:51:575078 std::vector<blink::mojom::ColorSuggestionPtr> suggestions) {
Joel Hockey85b379d2017-12-11 10:42:135079 content::ColorChooser* new_color_chooser =
Ivan Kotenkov2c0d2bb32017-11-01 15:41:285080 delegate_ ? delegate_->OpenColorChooser(this, color, suggestions)
5081 : nullptr;
[email protected]820957a2014-01-14 14:56:305082 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:215083 return;
[email protected]8ed16472014-04-11 19:02:485084
Joel Hockey85b379d2017-12-11 10:42:135085 color_chooser_.reset();
5086 color_chooser_ = std::make_unique<ColorChooser>(
Julie Jeongeun Kim8e2879e2019-08-06 23:55:205087 new_color_chooser, std::move(chooser_receiver), std::move(client));
[email protected]da8543762012-03-20 08:52:205088}
5089
brettw4b461082016-11-19 18:55:165090#if BUILDFLAG(ENABLE_PLUGINS)
nicka0ac8382016-12-15 23:59:235091void WebContentsImpl::OnPepperInstanceCreated(RenderFrameHostImpl* source,
5092 int32_t pp_instance) {
ericwilligersde386342016-10-19 02:35:095093 for (auto& observer : observers_)
5094 observer.PepperInstanceCreated();
nicka0ac8382016-12-15 23:59:235095 pepper_playback_observer_->PepperInstanceCreated(source, pp_instance);
emaxxe70f5e12015-05-29 11:26:005096}
5097
nicka0ac8382016-12-15 23:59:235098void WebContentsImpl::OnPepperInstanceDeleted(RenderFrameHostImpl* source,
5099 int32_t pp_instance) {
ericwilligersde386342016-10-19 02:35:095100 for (auto& observer : observers_)
5101 observer.PepperInstanceDeleted();
nicka0ac8382016-12-15 23:59:235102 pepper_playback_observer_->PepperInstanceDeleted(source, pp_instance);
emaxxe70f5e12015-05-29 11:26:005103}
5104
nicka0ac8382016-12-15 23:59:235105void WebContentsImpl::OnPepperPluginHung(RenderFrameHostImpl* source,
5106 int plugin_child_id,
tommyclie6633ca72014-10-31 00:40:425107 const base::FilePath& path,
5108 bool is_hung) {
Steven Holte95922222018-09-14 20:06:235109 UMA_HISTOGRAM_COUNTS_1M("Pepper.PluginHung", 1);
tommyclie6633ca72014-10-31 00:40:425110
ericwilligersde386342016-10-19 02:35:095111 for (auto& observer : observers_)
5112 observer.PluginHungStatusChanged(plugin_child_id, path, is_hung);
tommyclie6633ca72014-10-31 00:40:425113}
5114
nicka0ac8382016-12-15 23:59:235115void WebContentsImpl::OnPepperStartsPlayback(RenderFrameHostImpl* source,
5116 int32_t pp_instance) {
5117 pepper_playback_observer_->PepperStartsPlayback(source, pp_instance);
zqzhang181047e62016-07-01 13:37:175118}
5119
nicka0ac8382016-12-15 23:59:235120void WebContentsImpl::OnPepperStopsPlayback(RenderFrameHostImpl* source,
5121 int32_t pp_instance) {
5122 pepper_playback_observer_->PepperStopsPlayback(source, pp_instance);
zqzhang181047e62016-07-01 13:37:175123}
5124
nicka0ac8382016-12-15 23:59:235125void WebContentsImpl::OnPluginCrashed(RenderFrameHostImpl* source,
5126 const base::FilePath& plugin_path,
tommyclie6633ca72014-10-31 00:40:425127 base::ProcessId plugin_pid) {
nicka0ac8382016-12-15 23:59:235128 // TODO(nick): Eliminate the |plugin_pid| parameter, which can't be trusted,
5129 // and is only used by BlinkTestController.
ericwilligersde386342016-10-19 02:35:095130 for (auto& observer : observers_)
5131 observer.PluginCrashed(plugin_path, plugin_pid);
tommyclie6633ca72014-10-31 00:40:425132}
5133
[email protected]d8415ad92012-08-23 14:40:505134void WebContentsImpl::OnRequestPpapiBrokerPermission(
nicka0ac8382016-12-15 23:59:235135 RenderViewHostImpl* source,
5136 int ppb_broker_route_id,
[email protected]d8415ad92012-08-23 14:40:505137 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:345138 const base::FilePath& plugin_path) {
Avi Drissman0a2a967d2019-04-01 19:33:525139 base::OnceCallback<void(bool)> permission_result_callback = base::BindOnce(
nicka0ac8382016-12-15 23:59:235140 &WebContentsImpl::SendPpapiBrokerPermissionResult, base::Unretained(this),
5141 source->GetProcess()->GetID(), ppb_broker_route_id);
[email protected]8c8fc292012-11-23 18:57:165142 if (!delegate_) {
Tommy Nyquist4b749d02018-03-20 21:46:295143 std::move(permission_result_callback).Run(false);
[email protected]8c8fc292012-11-23 18:57:165144 return;
[email protected]d8415ad92012-08-23 14:40:505145 }
5146
Avi Drissman0a2a967d2019-04-01 19:33:525147 delegate_->RequestPpapiBrokerPermission(
5148 this, url, plugin_path, std::move(permission_result_callback));
[email protected]d8415ad92012-08-23 14:40:505149}
5150
nicka0ac8382016-12-15 23:59:235151void WebContentsImpl::SendPpapiBrokerPermissionResult(int process_id,
5152 int ppb_broker_route_id,
5153 bool result) {
5154 RenderProcessHost* rph = RenderProcessHost::FromID(process_id);
5155 if (rph) {
5156 // TODO(nick): Convert this from ViewMsg_ to a Ppapi msg, since it
5157 // is not routed to a RenderView.
5158 rph->Send(
5159 new ViewMsg_PpapiBrokerPermissionResult(ppb_broker_route_id, result));
5160 }
[email protected]d8415ad92012-08-23 14:40:505161}
brettw4b461082016-11-19 18:55:165162#endif // BUILDFLAG(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:375163
[email protected]795c28972012-12-06 06:13:395164void WebContentsImpl::OnUpdateFaviconURL(
lukasza178ff092017-06-07 23:39:505165 RenderFrameHostImpl* source,
[email protected]795c28972012-12-06 06:13:395166 const std::vector<FaviconURL>& candidates) {
lukasza178ff092017-06-07 23:39:505167 // Ignore favicons for non-main frame.
5168 if (source->GetParent()) {
5169 NOTREACHED();
5170 return;
5171 }
5172
pkotwiczf9bc20592015-04-21 18:57:065173 // We get updated favicon URLs after the page stops loading. If a cross-site
5174 // navigation occurs while a page is still loading, the initial page
5175 // may stop loading and send us updated favicon URLs after the navigation
5176 // for the new page has committed.
lukasza178ff092017-06-07 23:39:505177 if (!source->IsCurrent())
pkotwiczf9bc20592015-04-21 18:57:065178 return;
5179
Mounir Lamouri7b4a1f232019-12-23 16:32:105180 favicon_urls_ = candidates;
5181
ericwilligersde386342016-10-19 02:35:095182 for (auto& observer : observers_)
5183 observer.DidUpdateFaviconURL(candidates);
[email protected]795c28972012-12-06 06:13:395184}
5185
qinmin72e8bd02016-10-21 19:35:375186void WebContentsImpl::SetIsOverlayContent(bool is_overlay_content) {
5187 is_overlay_content_ = is_overlay_content;
5188}
5189
Albert J. Wongfb64e142018-10-16 01:10:455190void WebContentsImpl::DidFirstVisuallyNonEmptyPaint(
5191 RenderViewHostImpl* source) {
nicka0ac8382016-12-15 23:59:235192 // TODO(nick): When this is ported to FrameHostMsg_, we should only listen if
5193 // |source| is the main frame.
ericwilligersde386342016-10-19 02:35:095194 for (auto& observer : observers_)
5195 observer.DidFirstVisuallyNonEmptyPaint();
yusufod41c5f92015-03-06 00:14:285196
Carlos Caballero1215f882019-10-29 15:58:435197 if (source->theme_color() != last_sent_theme_color_) {
yusufod41c5f92015-03-06 00:14:285198 // Theme color should have updated by now if there was one.
ericwilligersde386342016-10-19 02:35:095199 for (auto& observer : observers_)
Peter Kastingb14e5782020-01-06 23:55:045200 observer.DidChangeThemeColor();
Carlos Caballero1215f882019-10-29 15:58:435201 last_sent_theme_color_ = source->theme_color();
yusufod41c5f92015-03-06 00:14:285202 }
[email protected]9f268072013-11-07 00:02:155203}
[email protected]d9030b82013-07-19 08:26:065204
Adithya Srinivasan46b8a792019-02-01 14:47:235205bool WebContentsImpl::IsPortal() const {
5206 return portal();
5207}
5208
[email protected]17e286e2013-03-01 23:29:395209void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
ericwilligersde386342016-10-19 02:35:095210 for (auto& observer : observers_)
5211 observer.BeforeFormRepostWarningShow();
[email protected]17e286e2013-03-01 23:29:395212}
5213
[email protected]ec6c05f2013-10-23 18:41:575214void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
5215 Activate();
5216 if (delegate_)
5217 delegate_->ShowRepostFormWarningDialog(this);
5218}
5219
[email protected]b4c84012014-04-28 19:51:105220bool WebContentsImpl::HasAccessedInitialDocument() {
5221 return has_accessed_initial_document_;
5222}
5223
afakhry6f0c1ec22016-07-14 13:55:135224void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry,
[email protected]fcf75d42013-12-03 20:11:265225 const base::string16& title) {
[email protected]fcf75d42013-12-03 20:11:265226 base::string16 final_title;
Avi Drissman93002212017-09-27 03:20:525227 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:325228
[email protected]987fc3a2011-05-26 14:18:095229 // If a page is created via window.open and never navigated,
5230 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:555231 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:095232 if (entry) {
[email protected]36fc0392011-12-25 03:59:515233 if (final_title == entry->GetTitle())
afakhry6f0c1ec22016-07-14 13:55:135234 return; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:325235
[email protected]36fc0392011-12-25 03:59:515236 entry->SetTitle(final_title);
Avi Drissman93002212017-09-27 03:20:525237
5238 // The title for display may differ from the title just set; grab it.
5239 final_title = entry->GetTitleForDisplay();
[email protected]987fc3a2011-05-26 14:18:095240 } else {
5241 if (page_title_when_no_navigation_entry_ == final_title)
afakhry6f0c1ec22016-07-14 13:55:135242 return; // Nothing changed, don't bother.
[email protected]987fc3a2011-05-26 14:18:095243
5244 page_title_when_no_navigation_entry_ = final_title;
5245 }
[email protected]420ae012009-04-24 05:16:325246
[email protected]420ae012009-04-24 05:16:325247 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:235248 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:325249
ericwilligersde386342016-10-19 02:35:095250 for (auto& observer : observers_)
Avi Drissman93002212017-09-27 03:20:525251 observer.TitleWasSet(entry);
[email protected]66798902013-10-01 18:40:165252
afakhry6f0c1ec22016-07-14 13:55:135253 // Broadcast notifications when the UI should be updated.
5254 if (entry == controller_.GetEntryAtOffset(0))
5255 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:325256}
5257
fdegansa696e5112015-04-17 01:57:595258void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:005259 loading_last_progress_update_ = base::TimeTicks::Now();
Evan Stade9f328112019-10-23 20:49:255260 for (auto& observer : observers_)
5261 observer.LoadProgressChanged(frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:005262}
5263
5264void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:345265 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:005266 loading_weak_factory_.InvalidateWeakPtrs();
5267 loading_last_progress_update_ = base::TimeTicks();
5268}
5269
clamy44e84ce2016-02-22 15:38:255270// Notifies the RenderWidgetHost instance about the fact that the page is
5271// loading, or done loading.
5272void WebContentsImpl::LoadingStateChanged(bool to_different_document,
5273 bool due_to_interstitial,
5274 LoadNotificationDetails* details) {
Nate Chapin22ea6592019-03-05 22:29:025275 if (is_being_destroyed_)
5276 return;
clamy44e84ce2016-02-22 15:38:255277 // Do not send notifications about loading changes in the FrameTree while the
5278 // interstitial page is pausing the throbber.
creisadca9862017-06-16 19:12:115279 if (ShowingInterstitialPage() && interstitial_page_->pause_throbber() &&
clamy44e84ce2016-02-22 15:38:255280 !due_to_interstitial) {
5281 return;
5282 }
5283
5284 bool is_loading = IsLoading();
5285
5286 if (!is_loading) {
5287 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
5288 base::string16());
5289 load_state_host_.clear();
5290 upload_size_ = 0;
5291 upload_position_ = 0;
5292 }
5293
5294 GetRenderManager()->SetIsLoading(is_loading);
5295
5296 waiting_for_response_ = is_loading;
5297 is_load_to_different_document_ = to_different_document;
5298
5299 if (delegate_)
5300 delegate_->LoadingStateChanged(this, to_different_document);
5301 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
5302
5303 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
5304 if (is_loading) {
5305 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
5306 this, "URL", url, "Main FrameTreeNode id",
5307 GetFrameTree()->root()->frame_tree_node_id());
ericwilligersde386342016-10-19 02:35:095308 for (auto& observer : observers_)
5309 observer.DidStartLoading();
clamy44e84ce2016-02-22 15:38:255310 } else {
5311 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
5312 this, "URL", url);
ericwilligersde386342016-10-19 02:35:095313 for (auto& observer : observers_)
5314 observer.DidStopLoading();
clamy44e84ce2016-02-22 15:38:255315 }
5316
5317 // TODO(avi): Remove. http://crbug.com/170921
5318 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
5319 NotificationDetails det = NotificationService::NoDetails();
5320 if (details)
5321 det = Details<LoadNotificationDetails>(details);
5322 NotificationService::current()->Notify(
5323 type, Source<NavigationController>(&controller_), det);
5324}
5325
[email protected]02d7b6e2014-06-24 21:01:505326void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
5327 RenderViewHost* new_host) {
Fergal Daly6767b2e2020-02-04 03:15:165328 DCHECK_NE(old_host, new_host);
[email protected]420ae012009-04-24 05:16:325329 // After sending out a swap notification, we need to send a disconnect
5330 // notification so that clients that pick up a pointer to |this| can NULL the
5331 // pointer. See Bug 1230284.
5332 notify_disconnection_ = true;
ericwilligersde386342016-10-19 02:35:095333 for (auto& observer : observers_)
5334 observer.RenderViewHostChanged(old_host, new_host);
[email protected]da7a7182013-09-06 08:11:115335
Jinsuk Kimdc5284c22018-07-11 02:22:065336 view_->RenderViewHostChanged(old_host, new_host);
5337
Lucas Furukawa Gadanif9ea4fc2018-08-03 23:57:135338 // If this is an inner WebContents that has swapped views, we need to reattach
5339 // it to its outer WebContents.
5340 if (node_.outer_web_contents())
5341 ReattachToOuterWebContentsFrame();
5342
[email protected]7a846df2012-09-20 19:17:395343 // Ensure that the associated embedder gets cleared after a RenderViewHost
5344 // gets swapped, so we don't reuse the same embedder next time a
5345 // RenderViewHost is attached to this WebContents.
5346 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:325347}
5348
[email protected]02d7b6e2014-06-24 21:01:505349void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
Jinsuk Kim895b2c52018-07-03 06:49:165350 RenderFrameHost* new_host,
5351 bool is_main_frame) {
Bo Liu168c8642017-08-28 18:26:025352#if defined(OS_ANDROID)
Bo Liu16dd7b8322018-05-02 21:19:505353 // Copy importance from |old_host| if |new_host| is a main frame.
5354 if (old_host && !new_host->GetParent()) {
Bo Liu7c6779e92017-08-16 02:02:285355 static_cast<RenderFrameHostImpl*>(new_host)
5356 ->GetRenderWidgetHost()
Bo Liu16dd7b8322018-05-02 21:19:505357 ->SetImportance(static_cast<RenderFrameHostImpl*>(old_host)
5358 ->GetRenderWidgetHost()
5359 ->importance());
Bo Liu7c6779e92017-08-16 02:02:285360 }
Bo Liu168c8642017-08-28 18:26:025361#endif
ericwilligersde386342016-10-19 02:35:095362 for (auto& observer : observers_)
5363 observer.RenderFrameHostChanged(old_host, new_host);
[email protected]02d7b6e2014-06-24 21:01:505364}
5365
[email protected]da7a7182013-09-06 08:11:115366// TODO(avi): Remove this entire function because this notification is already
5367// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:265368void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:325369 if (!notify_disconnection_)
5370 return;
5371
5372 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:215373 NotificationService::current()->Notify(
5374 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
5375 Source<WebContents>(this),
5376 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:325377}
5378
[email protected]cbb1ef592013-06-05 19:49:465379void WebContentsImpl::NotifyNavigationEntryCommitted(
5380 const LoadCommittedDetails& load_details) {
ericwilligersde386342016-10-19 02:35:095381 for (auto& observer : observers_)
5382 observer.NavigationEntryCommitted(load_details);
[email protected]cbb1ef592013-06-05 19:49:465383}
5384
Sam McNally5c087a32017-08-25 01:46:145385void WebContentsImpl::NotifyNavigationEntryChanged(
5386 const EntryChangedDetails& change_details) {
5387 for (auto& observer : observers_)
5388 observer.NavigationEntryChanged(change_details);
5389}
5390
5391void WebContentsImpl::NotifyNavigationListPruned(
5392 const PrunedDetails& pruned_details) {
5393 for (auto& observer : observers_)
5394 observer.NavigationListPruned(pruned_details);
5395}
5396
Christian Dullweber1af31e62018-02-22 11:49:485397void WebContentsImpl::NotifyNavigationEntriesDeleted() {
5398 for (auto& observer : observers_)
5399 observer.NavigationEntriesDeleted();
5400}
5401
rockotf62002a2016-09-15 00:08:595402void WebContentsImpl::OnAssociatedInterfaceRequest(
5403 RenderFrameHost* render_frame_host,
5404 const std::string& interface_name,
5405 mojo::ScopedInterfaceEndpointHandle handle) {
Julie Jeongeun Kim7d0986172019-12-04 03:17:255406 auto it = receiver_sets_.find(interface_name);
5407 if (it != receiver_sets_.end())
5408 it->second->OnReceiverForFrame(render_frame_host, std::move(handle));
rockotf62002a2016-09-15 00:08:595409}
5410
Ben Goodger9e24929e2017-07-21 03:13:405411void WebContentsImpl::OnInterfaceRequest(
5412 RenderFrameHost* render_frame_host,
5413 const std::string& interface_name,
5414 mojo::ScopedMessagePipeHandle* interface_pipe) {
5415 for (auto& observer : observers_) {
5416 observer.OnInterfaceRequestFromFrame(render_frame_host, interface_name,
5417 interface_pipe);
5418 if (!interface_pipe->is_valid())
5419 break;
5420 }
5421}
5422
Varun Khaneja5da94302019-06-25 04:48:105423void WebContentsImpl::OnDidBlockNavigation(
5424 const GURL& blocked_url,
5425 const GURL& initiator_url,
Abhijeet Kandalkarde7348e2020-01-13 06:06:545426 blink::mojom::NavigationBlockedReason reason) {
Nicolas Dossou-gbetebcab2472017-09-09 12:28:405427 if (delegate_)
Varun Khaneja5da94302019-06-25 04:48:105428 delegate_->OnDidBlockNavigation(this, blocked_url, initiator_url, reason);
Nicolas Dossou-gbetebcab2472017-09-09 12:28:405429}
5430
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:415431const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() {
[email protected]c31a84802014-04-03 15:55:495432 return GetLastCommittedURL();
5433}
5434
[email protected]b849847b2013-12-10 21:57:585435void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:095436 for (auto& observer : observers_)
5437 observer.RenderFrameCreated(render_frame_host);
dmazzonif8a31042016-12-03 00:52:135438 UpdateAccessibilityModeOnFrame(render_frame_host);
clamy91b7abf2016-03-24 15:17:455439
Becca Hughesd11d6502018-07-31 17:01:285440 if (display_cutout_host_impl_)
5441 display_cutout_host_impl_->RenderFrameCreated(render_frame_host);
5442
clamy91b7abf2016-03-24 15:17:455443 if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent())
5444 return;
5445
5446 NavigationEntry* entry = controller_.GetPendingEntry();
5447 if (entry && entry->IsViewSourceMode()) {
5448 // Put the renderer in view source mode.
Dave Tapuska3c05e1c2019-11-27 18:34:185449 static_cast<RenderFrameHostImpl*>(render_frame_host)
5450 ->GetAssociatedLocalFrame()
5451 ->EnableViewSourceMode();
clamy91b7abf2016-03-24 15:17:455452 }
[email protected]b849847b2013-12-10 21:57:585453}
5454
5455void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
yilkal172da772019-11-06 22:49:075456 if (IsBeingDestroyed() && !render_frame_host->GetParent() &&
5457 first_navigation_completed_ &&
Rakina Zata Amni74627df2019-10-15 02:03:175458 !static_cast<RenderFrameHostImpl*>(render_frame_host)
5459 ->is_in_back_forward_cache()) {
yilkal796e89e2019-10-02 23:58:285460 // Main frame has been deleted because WebContents is being destroyed.
Rakina Zata Amni74627df2019-10-15 02:03:175461 // Note that we aren't recording this here when the main frame is in the
5462 // back-forward cache because that means we've actually already navigated
5463 // away from it (and we got to this point because the WebContents is
yilkal172da772019-11-06 22:49:075464 // deleted), which means |max_loaded_frame_count_| is already overwritten.
5465 // The |max_loaded_frame_count_| value will instead be recorded from within
5466 // |WebContentsImpl::DidFinishNavigation()|.
5467 RecordMaxFrameCountUMA(max_loaded_frame_count_);
yilkal796e89e2019-10-02 23:58:285468 }
5469
creis3638897452017-05-09 22:07:505470 is_notifying_observers_ = true;
ericwilligersde386342016-10-19 02:35:095471 for (auto& observer : observers_)
5472 observer.RenderFrameDeleted(render_frame_host);
creis3638897452017-05-09 22:07:505473 is_notifying_observers_ = false;
zqzhang7b6f4f02016-12-07 22:10:225474#if BUILDFLAG(ENABLE_PLUGINS)
5475 pepper_playback_observer_->RenderFrameDeleted(render_frame_host);
5476#endif
Becca Hughesfd5d8f892018-06-14 18:23:365477
Becca Hughesd11d6502018-07-31 17:01:285478 if (display_cutout_host_impl_)
5479 display_cutout_host_impl_->RenderFrameDeleted(render_frame_host);
5480
Becca Hughesfd5d8f892018-06-14 18:23:365481 // Remove any fullscreen state that the frame has stored.
5482 FullscreenStateChanged(render_frame_host, false /* is_fullscreen */);
[email protected]b849847b2013-12-10 21:57:585483}
5484
[email protected]a09d53ce2014-01-31 00:46:425485void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
5486 const ContextMenuParams& params) {
avie9fd8722017-04-10 16:17:585487 // If a renderer fires off a second command to show a context menu before the
5488 // first context menu is closed, just ignore it. https://crbug.com/707534
ekaramadf6750aa2017-06-06 18:29:425489 if (showing_context_menu_)
avie9fd8722017-04-10 16:17:585490 return;
5491
[email protected]077e704b2014-05-23 19:24:105492 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:425493 // Allow WebContentsDelegates to handle the context menu operation first.
Joel Klinghed0ea22ea2019-02-20 22:04:225494 if (delegate_ &&
5495 delegate_->HandleContextMenu(render_frame_host, context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:425496 return;
5497
[email protected]077e704b2014-05-23 19:24:105498 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
5499 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:425500}
5501
Avi Drissman4891b852018-09-25 18:12:585502namespace {
5503// Normalizes the line endings: \r\n -> \n, lone \r -> \n.
5504base::string16 NormalizeLineBreaks(const base::string16& source) {
5505 static const base::NoDestructor<base::string16> kReturnNewline(
5506 base::ASCIIToUTF16("\r\n"));
5507 static const base::NoDestructor<base::string16> kReturn(
5508 base::ASCIIToUTF16("\r"));
5509 static const base::NoDestructor<base::string16> kNewline(
5510 base::ASCIIToUTF16("\n"));
5511
5512 std::vector<base::StringPiece16> pieces;
5513
5514 for (const auto& rn_line : base::SplitStringPieceUsingSubstr(
5515 source, *kReturnNewline, base::KEEP_WHITESPACE,
5516 base::SPLIT_WANT_ALL)) {
5517 auto r_lines = base::SplitStringPieceUsingSubstr(
5518 rn_line, *kReturn, base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
5519 std::move(std::begin(r_lines), std::end(r_lines),
5520 std::back_inserter(pieces));
5521 }
5522
5523 return base::JoinString(pieces, *kNewline);
5524}
5525} // namespace
5526
Dave Tapuskacdf545cc2020-01-23 18:38:525527void WebContentsImpl::RunJavaScriptDialog(
5528 RenderFrameHost* render_frame_host,
5529 const base::string16& message,
5530 const base::string16& default_prompt,
5531 JavaScriptDialogType dialog_type,
5532 JavaScriptDialogCallback response_callback) {
Avi Drissman2ccbb402018-03-20 21:11:365533 // Ensure that if showing a dialog is the first thing that a page does, that
5534 // the contents of the previous page aren't shown behind it. This is required
5535 // because showing a dialog freezes the renderer, so no frames will be coming
5536 // from it. https://crbug.com/823353
5537 auto* render_widget_host_impl =
5538 static_cast<RenderFrameHostImpl*>(render_frame_host)
5539 ->GetRenderWidgetHost();
5540 if (render_widget_host_impl)
5541 render_widget_host_impl->ForceFirstFrameAfterNavigationTimeout();
5542
avi0720b02e2017-06-13 03:22:135543 // Running a dialog causes an exit to webpage-initiated fullscreen.
5544 // http://crbug.com/728276
Avi Drissmand18c51972018-08-15 18:32:095545 ForSecurityDropFullscreen();
avi0720b02e2017-06-13 03:22:135546
Dave Tapuskacdf545cc2020-01-23 18:38:525547 auto callback = base::BindOnce(
5548 &WebContentsImpl::OnDialogClosed, base::Unretained(this),
5549 render_frame_host->GetProcess()->GetID(),
5550 render_frame_host->GetRoutingID(), std::move(response_callback));
Pavel Feldman3c1842b2017-08-02 05:00:165551
Pavel Feldman3c1842b2017-08-02 05:00:165552 std::vector<protocol::PageHandler*> page_handlers =
5553 protocol::PageHandler::EnabledForWebContents(this);
5554
Pavel Feldmanfab3cb62017-10-05 01:02:015555 if (delegate_)
5556 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
5557
Charlie Reis96077362019-07-04 00:34:045558 // While a JS message dialog is showing, defer commits in this WebContents.
5559 javascript_dialog_navigation_deferrer_ =
5560 std::make_unique<JavaScriptDialogNavigationDeferrer>();
5561
Pavel Feldmanfab3cb62017-10-05 01:02:015562 // Suppress JavaScript dialogs when requested. Also suppress messages when
5563 // showing an interstitial as it's shown over the previous page and we don't
5564 // want the hidden page's dialogs to interfere with the interstitial.
Tarun Bansalc209b742019-12-24 06:53:255565 bool should_suppress = ShowingInterstitialPage() ||
5566 (delegate_ && delegate_->ShouldSuppressDialogs(this));
Pavel Feldman1c587bc52018-04-04 21:16:055567 bool has_non_devtools_handlers = delegate_ && dialog_manager_;
5568 bool has_handlers = page_handlers.size() || has_non_devtools_handlers;
Pavel Feldmanfab3cb62017-10-05 01:02:015569 bool suppress_this_message = should_suppress || !has_handlers;
5570
5571 if (suppress_this_message) {
Avi Drissmane04d3992017-10-05 15:11:365572 std::move(callback).Run(true, false, base::string16());
Pavel Feldman3c1842b2017-08-02 05:00:165573 return;
5574 }
5575
5576 scoped_refptr<CloseDialogCallbackWrapper> wrapper =
Avi Drissmane04d3992017-10-05 15:11:365577 new CloseDialogCallbackWrapper(std::move(callback));
Pavel Feldman3c1842b2017-08-02 05:00:165578
5579 is_showing_javascript_dialog_ = true;
5580
Avi Drissman4891b852018-09-25 18:12:585581 base::string16 normalized_message = NormalizeLineBreaks(message);
5582
Pavel Feldman3c1842b2017-08-02 05:00:165583 for (auto* handler : page_handlers) {
Avi Drissmane04d3992017-10-05 15:11:365584 handler->DidRunJavaScriptDialog(
Avi Drissman4891b852018-09-25 18:12:585585 render_frame_host->GetLastCommittedURL(), normalized_message,
5586 default_prompt, dialog_type, has_non_devtools_handlers,
Avi Drissmane04d3992017-10-05 15:11:365587 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false));
Pavel Feldman3c1842b2017-08-02 05:00:165588 }
5589
5590 if (dialog_manager_) {
[email protected]87de04b02014-04-08 22:14:495591 dialog_manager_->RunJavaScriptDialog(
Avi Drissman4891b852018-09-25 18:12:585592 this, render_frame_host, dialog_type, normalized_message,
5593 default_prompt,
Avi Drissmane04d3992017-10-05 15:11:365594 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false),
5595 &suppress_this_message);
[email protected]87de04b02014-04-08 22:14:495596 }
5597
5598 if (suppress_this_message) {
5599 // If we are suppressing messages, just reply as if the user immediately
5600 // pressed "Cancel", passing true to |dialog_was_suppressed|.
Avi Drissmane04d3992017-10-05 15:11:365601 wrapper->Run(true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:495602 }
[email protected]87de04b02014-04-08 22:14:495603}
5604
5605void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:015606 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:495607 bool is_reload,
Dave Tapuskacdf545cc2020-01-23 18:38:525608 JavaScriptDialogCallback response_callback) {
Avi Drissman2ccbb402018-03-20 21:11:365609 // Ensure that if showing a dialog is the first thing that a page does, that
5610 // the contents of the previous page aren't shown behind it. This is required
5611 // because showing a dialog freezes the renderer, so no frames will be coming
5612 // from it. https://crbug.com/823353
5613 auto* render_widget_host_impl =
5614 static_cast<RenderFrameHostImpl*>(render_frame_host)
5615 ->GetRenderWidgetHost();
5616 if (render_widget_host_impl)
5617 render_widget_host_impl->ForceFirstFrameAfterNavigationTimeout();
5618
avi0720b02e2017-06-13 03:22:135619 // Running a dialog causes an exit to webpage-initiated fullscreen.
5620 // http://crbug.com/728276
Avi Drissmand18c51972018-08-15 18:32:095621 ForSecurityDropFullscreen();
avi0720b02e2017-06-13 03:22:135622
[email protected]39f2f9252014-05-03 00:54:015623 RenderFrameHostImpl* rfhi =
5624 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:495625 if (delegate_)
5626 delegate_->WillRunBeforeUnloadConfirm();
5627
Dave Tapuskacdf545cc2020-01-23 18:38:525628 auto callback = base::BindOnce(
5629 &WebContentsImpl::OnDialogClosed, base::Unretained(this),
5630 render_frame_host->GetProcess()->GetID(),
5631 render_frame_host->GetRoutingID(), std::move(response_callback));
Pavel Feldman3c1842b2017-08-02 05:00:165632
Pavel Feldman3c1842b2017-08-02 05:00:165633 std::vector<protocol::PageHandler*> page_handlers =
5634 protocol::PageHandler::EnabledForWebContents(this);
5635
Pavel Feldmanfab3cb62017-10-05 01:02:015636 if (delegate_)
5637 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
5638
Charlie Reis96077362019-07-04 00:34:045639 // While a JS beforeunload dialog is showing, defer commits in this
5640 // WebContents.
5641 javascript_dialog_navigation_deferrer_ =
5642 std::make_unique<JavaScriptDialogNavigationDeferrer>();
5643
Tarun Bansalc209b742019-12-24 06:53:255644 bool should_suppress = ShowingInterstitialPage() || !rfhi->is_active() ||
5645 (delegate_ && delegate_->ShouldSuppressDialogs(this));
Pavel Feldman1c587bc52018-04-04 21:16:055646 bool has_non_devtools_handlers = delegate_ && dialog_manager_;
5647 bool has_handlers = page_handlers.size() || has_non_devtools_handlers;
Pavel Feldmanfab3cb62017-10-05 01:02:015648 if (should_suppress || !has_handlers) {
Avi Drissmane04d3992017-10-05 15:11:365649 std::move(callback).Run(false, true, base::string16());
[email protected]87de04b02014-04-08 22:14:495650 return;
5651 }
5652
5653 is_showing_before_unload_dialog_ = true;
Pavel Feldman3c1842b2017-08-02 05:00:165654
5655 scoped_refptr<CloseDialogCallbackWrapper> wrapper =
Avi Drissmane04d3992017-10-05 15:11:365656 new CloseDialogCallbackWrapper(std::move(callback));
Pavel Feldman3c1842b2017-08-02 05:00:165657
5658 GURL frame_url = rfhi->GetLastCommittedURL();
5659 for (auto* handler : page_handlers) {
Avi Drissmane04d3992017-10-05 15:11:365660 handler->DidRunBeforeUnloadConfirm(
Pavel Feldman1c587bc52018-04-04 21:16:055661 frame_url, has_non_devtools_handlers,
Avi Drissmane04d3992017-10-05 15:11:365662 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false));
Pavel Feldman3c1842b2017-08-02 05:00:165663 }
5664
5665 if (dialog_manager_) {
Avi Drissmane04d3992017-10-05 15:11:365666 dialog_manager_->RunBeforeUnloadDialog(
Avi Drissmanff9ed752017-11-28 21:18:125667 this, render_frame_host, is_reload,
Avi Drissmane04d3992017-10-05 15:11:365668 base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false));
Pavel Feldman3c1842b2017-08-02 05:00:165669 }
[email protected]87de04b02014-04-08 22:14:495670}
5671
Kent Tamurac260c9a2018-09-14 09:10:565672void WebContentsImpl::RunFileChooser(
5673 RenderFrameHost* render_frame_host,
Kent Tamura512a27e2018-10-04 00:49:325674 std::unique_ptr<content::FileSelectListener> listener,
Kent Tamurac260c9a2018-09-14 09:10:565675 const blink::mojom::FileChooserParams& params) {
Avi Drissman3d41e7712018-08-27 21:18:085676 // Any explicit focusing of another window while this WebContents is in
5677 // fullscreen can be used to confuse the user, so drop fullscreen.
5678 ForSecurityDropFullscreen();
5679
naskoada75b22016-06-11 16:09:465680 if (delegate_)
Kent Tamura512a27e2018-10-04 00:49:325681 delegate_->RunFileChooser(render_frame_host, std::move(listener), params);
5682 else
5683 listener->FileSelectionCanceled();
naskoada75b22016-06-11 16:09:465684}
5685
[email protected]a86c0e962013-12-17 17:10:395686WebContents* WebContentsImpl::GetAsWebContents() {
5687 return this;
5688}
5689
mcnee336ea2c2017-05-23 22:50:595690#if !defined(OS_ANDROID)
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:415691double WebContentsImpl::GetPendingPageZoomLevel() {
wjmaclean64951902016-04-29 20:59:125692 NavigationEntry* pending_entry = GetController().GetPendingEntry();
5693 if (!pending_entry)
5694 return HostZoomMap::GetZoomLevel(this);
5695
5696 GURL url = pending_entry->GetURL();
5697 return HostZoomMap::GetForWebContents(this)->GetZoomLevelForHostAndScheme(
5698 url.scheme(), net::GetHostOrSpecFromURL(url));
5699}
mcnee336ea2c2017-05-23 22:50:595700#endif // !defined(OS_ANDROID)
wjmaclean64951902016-04-29 20:59:125701
qinmin72e8bd02016-10-21 19:35:375702bool WebContentsImpl::HideDownloadUI() const {
5703 return is_overlay_content_;
5704}
5705
mlamouri5cd9ae82017-02-18 11:05:095706bool WebContentsImpl::HasPersistentVideo() const {
5707 return has_persistent_video_;
5708}
5709
Ian Vollick5d5c37f2019-06-19 22:50:575710bool WebContentsImpl::IsSpatialNavigationDisabled() const {
5711 return is_spatial_navigation_disabled_;
5712}
5713
Albert J. Wong65fe64d2019-09-20 02:48:145714RenderFrameHostImpl* WebContentsImpl::GetPendingMainFrame() {
clamy610c63b32017-12-22 15:05:185715 return GetRenderManager()->speculative_frame_host();
Alex Moshchuk27caae82017-09-11 23:11:185716}
5717
mlamourie52c1b542017-02-23 14:57:505718bool WebContentsImpl::HasActiveEffectivelyFullscreenVideo() const {
5719 return media_web_contents_observer_->HasActiveEffectivelyFullscreenVideo();
5720}
5721
François Beaufortad6c5232018-02-26 11:00:445722bool WebContentsImpl::IsPictureInPictureAllowedForFullscreenVideo() const {
5723 return media_web_contents_observer_
5724 ->IsPictureInPictureAllowedForFullscreenVideo();
5725}
5726
ekaramada110f642016-12-21 19:47:285727bool WebContentsImpl::IsFocusedElementEditable() {
5728 RenderFrameHostImpl* frame = GetFocusedFrame();
5729 return frame && frame->has_focused_editable_element();
5730}
5731
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:415732bool WebContentsImpl::IsShowingContextMenu() {
ekaramadf6750aa2017-06-06 18:29:425733 return showing_context_menu_;
5734}
5735
5736void WebContentsImpl::SetShowingContextMenu(bool showing) {
5737 DCHECK_NE(showing_context_menu_, showing);
5738 showing_context_menu_ = showing;
5739
5740 if (auto* view = GetRenderWidgetHostView()) {
5741 // Notify the main frame's RWHV to run the platform-specific code, if any.
5742 static_cast<RenderWidgetHostViewBase*>(view)->SetShowingContextMenu(
5743 showing);
5744 }
5745}
5746
ekaramada110f642016-12-21 19:47:285747void WebContentsImpl::ClearFocusedElement() {
5748 if (auto* frame = GetFocusedFrame())
5749 frame->ClearFocusedElement();
5750}
5751
danakj77eb7e82020-01-09 19:38:465752bool WebContentsImpl::IsNeverComposited() {
[email protected]7912e822014-04-16 02:37:035753 if (!delegate_)
5754 return false;
danakj77eb7e82020-01-09 19:38:465755 return delegate_->IsNeverComposited(this);
[email protected]7912e822014-04-16 02:37:035756}
5757
[email protected]5a3bdf52012-05-24 15:12:575758RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
5759 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:325760}
5761
Leon Hanc819dc62019-01-28 04:30:195762blink::mojom::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]8ff00d72012-10-23 19:12:215763 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:465764 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:515765}
5766
Lucas Furukawa Gadani2ec00c82018-12-14 15:53:165767RenderFrameHostImpl* WebContentsImpl::GetOuterWebContentsFrame() {
5768 if (GetOuterDelegateFrameTreeNodeId() ==
5769 FrameTreeNode::kFrameTreeNodeInvalidId) {
5770 return nullptr;
5771 }
5772
5773 FrameTreeNode* outer_node =
5774 FrameTreeNode::GloballyFindByID(GetOuterDelegateFrameTreeNodeId());
5775 // The outer node should be in the outer WebContents.
5776 DCHECK_EQ(outer_node->frame_tree(), GetOuterWebContents()->GetFrameTree());
5777 return outer_node->parent()->current_frame_host();
5778}
5779
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:415780WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
Lucas Furukawa Gadani105de1e812018-05-31 19:38:395781 return node_.outer_web_contents();
avallee0206f782016-07-28 18:55:335782}
5783
Lucas Furukawa Gadani2ec00c82018-12-14 15:53:165784std::vector<WebContents*> WebContentsImpl::GetInnerWebContents() {
5785 std::vector<WebContents*> all_inner_contents;
Lucas Furukawa Gadani2ec00c82018-12-14 15:53:165786 const auto& inner_contents = node_.GetInnerWebContents();
5787 all_inner_contents.insert(all_inner_contents.end(), inner_contents.begin(),
5788 inner_contents.end());
5789 return all_inner_contents;
5790}
5791
Jeremy Roman7e70bf92020-01-07 23:23:585792WebContentsImpl* WebContentsImpl::GetResponsibleWebContents() {
5793 // Iteratively ask delegates which other contents is responsible until a fixed
5794 // point is found.
5795 WebContentsImpl* contents = this;
5796 while (WebContentsDelegate* delegate = contents->GetDelegate()) {
5797 auto* responsible_contents = static_cast<WebContentsImpl*>(
5798 delegate->GetResponsibleWebContents(contents));
5799 if (responsible_contents == contents)
5800 break;
5801 contents = responsible_contents;
5802 }
5803 return contents;
5804}
5805
avallee0206f782016-07-28 18:55:335806WebContentsImpl* WebContentsImpl::GetFocusedWebContents() {
lfg601233692017-03-06 22:45:445807 return GetOutermostWebContents()->node_.focused_web_contents();
avallee0206f782016-07-28 18:55:335808}
5809
avallee9993fca2016-11-17 06:16:505810bool WebContentsImpl::ContainsOrIsFocusedWebContents() {
5811 for (WebContentsImpl* focused_contents = GetFocusedWebContents();
5812 focused_contents;
5813 focused_contents = focused_contents->GetOuterWebContents()) {
5814 if (focused_contents == this)
5815 return true;
5816 }
5817
5818 return false;
5819}
5820
W. James MacLean9437b5bf2019-12-06 17:33:445821void WebContentsImpl::RemoveBrowserPluginEmbedder() {
5822 browser_plugin_embedder_.reset();
5823}
5824
avallee0206f782016-07-28 18:55:335825WebContentsImpl* WebContentsImpl::GetOutermostWebContents() {
5826 WebContentsImpl* root = this;
5827 while (root->GetOuterWebContents())
5828 root = root->GetOuterWebContents();
5829 return root;
5830}
5831
avalleed68cdd12017-06-21 22:07:275832void WebContentsImpl::FocusOuterAttachmentFrameChain() {
5833 WebContentsImpl* outer_contents = GetOuterWebContents();
5834 if (!outer_contents)
5835 return;
5836
5837 FrameTreeNode* outer_node =
5838 FrameTreeNode::GloballyFindByID(GetOuterDelegateFrameTreeNodeId());
5839 outer_contents->frame_tree_.SetFocusedFrame(outer_node, nullptr);
5840
5841 // For a browser initiated focus change, let embedding renderer know of the
5842 // change. Otherwise, if the currently focused element is just across a
5843 // process boundary in focus order, it will not be possible to move across
5844 // that boundary. This is because the target element will already be focused
5845 // (that renderer was not notified) and drop the event.
5846 if (GetRenderManager()->GetProxyToOuterDelegate())
5847 GetRenderManager()->GetProxyToOuterDelegate()->SetFocusedFrame();
5848
5849 outer_contents->FocusOuterAttachmentFrameChain();
5850}
5851
Sean Toppingbbc4a2bd2019-01-30 02:16:145852void WebContentsImpl::InnerWebContentsCreated(WebContents* inner_web_contents) {
Shivani Sharma985474f2019-05-23 21:36:475853 had_inner_webcontents_ = true;
Sean Toppingbbc4a2bd2019-01-30 02:16:145854 for (auto& observer : observers_)
5855 observer.InnerWebContentsCreated(inner_web_contents);
5856}
5857
[email protected]b172aee2012-04-10 17:05:265858void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]86f98a22013-03-20 14:35:005859 if (delegate_)
[email protected]e85165c642014-06-10 14:34:315860 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:085861
[email protected]8ff00d72012-10-23 19:12:215862 NotificationService::current()->Notify(
5863 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
5864 Source<WebContents>(this),
5865 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:325866
[email protected]60780f412013-02-25 16:34:105867 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:265868
ericwilligersde386342016-10-19 02:35:095869 for (auto& observer : observers_)
5870 observer.RenderViewCreated(render_view_host);
Joel Einbinder848001c2017-09-19 21:39:315871 if (delegate_)
5872 RenderFrameDevToolsAgentHost::WebContentsCreated(this);
[email protected]420ae012009-04-24 05:16:325873}
5874
[email protected]b172aee2012-04-10 17:05:265875void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:525876 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:325877 // Don't notify the world, since this came from a renderer in the
5878 // background.
5879 return;
5880 }
5881
dmazzoni62111452017-04-28 23:46:555882 RenderWidgetHostViewBase* rwhv =
5883 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
5884 if (rwhv)
5885 rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID());
5886
[email protected]da7a7182013-09-06 08:11:115887 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:115888
[email protected]be1f56ab2011-12-22 06:55:315889 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:235890 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:305891
5892 // Restore the focus to the tab (otherwise the focus will be on the top
5893 // window).
[email protected]484ae5912010-09-29 19:16:145894 if (was_crashed && !FocusLocationBarByDefault() &&
5895 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:065896 view_->Focus();
[email protected]484ae5912010-09-29 19:16:145897 }
[email protected]32ded2212011-11-10 18:51:435898
ericwilligersde386342016-10-19 02:35:095899 for (auto& observer : observers_)
5900 observer.RenderViewReady();
Jinsuk Kim895b2c52018-07-03 06:49:165901
5902 view_->RenderViewReady();
[email protected]420ae012009-04-24 05:16:325903}
5904
[email protected]ec6a7eb2013-04-22 17:34:225905void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
5906 base::TerminationStatus status,
5907 int error_code) {
[email protected]151a63d2011-12-20 22:32:525908 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:325909 // The pending page's RenderViewHost is gone.
5910 return;
5911 }
5912
[email protected]2fcdcc32014-03-05 02:14:075913 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
5914 // renderer may not have made a clean exit.
alexmos5dd617d2016-06-07 04:21:155915 if (IsFullscreenForCurrentTab())
bokanece34a82016-01-28 19:49:465916 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:075917
Jennifer Apacibleb4b972a2018-06-07 04:41:025918 // Ensure any video in Picture-in-Picture is exited in the |delegate_| since
5919 // a crashed renderer may not have made a clean exit.
5920 if (HasPictureInPictureVideo())
5921 ExitPictureInPicture();
5922
[email protected]698191dc2014-02-25 01:06:135923 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:175924 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:135925
dalecurtis3d1e1302017-02-20 22:33:255926 audio_stream_monitor_.RenderProcessGone(rvh->GetProcess()->GetID());
5927
[email protected]960b0372014-05-19 18:01:005928 // Reset the loading progress. TODO(avi): What does it mean to have a
5929 // "renderer crash" when there is more than one renderer process serving a
5930 // webpage? Once this function is called at a more granular frame level, we
5931 // probably will need to more granularly reset the state here.
5932 ResetLoadProgressState();
clamy44e84ce2016-02-22 15:38:255933 NotifyDisconnected();
5934 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:005935
ericwilligersde386342016-10-19 02:35:095936 for (auto& observer : observers_)
5937 observer.RenderProcessGone(GetCrashedStatus());
[email protected]420ae012009-04-24 05:16:325938}
5939
[email protected]b172aee2012-04-10 17:05:265940void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
ericwilligersde386342016-10-19 02:35:095941 for (auto& observer : observers_)
5942 observer.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:065943}
5944
sky8b00392d2015-01-10 00:30:285945void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
5946 const GURL& url) {
5947 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
Lukasz Anforowiczfd707142018-02-07 19:46:135948 // If we're in flash fullscreen (i.e. Pepper plugin fullscreen) only update
5949 // the url if it's from the fullscreen renderer.
sky8b00392d2015-01-10 00:30:285950 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:445951 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:285952 return;
5953 }
Lukasz Anforowiczfd707142018-02-07 19:46:135954
5955 // In case of racey updates from multiple RenderViewHosts, the last URL should
5956 // be shown - see also some discussion in https://crbug.com/807776.
5957 if (!url.is_valid() && render_view_host != view_that_set_last_target_url_)
5958 return;
5959 view_that_set_last_target_url_ = url.is_valid() ? render_view_host : nullptr;
5960
[email protected]6934a702011-12-20 00:04:515961 if (delegate_)
avi450ce00e2014-09-24 01:58:525962 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:325963}
5964
Lukasz Anforowiczfd707142018-02-07 19:46:135965void WebContentsImpl::ClearTargetURL() {
5966 view_that_set_last_target_url_ = nullptr;
5967 if (delegate_)
5968 delegate_->UpdateTargetURL(this, GURL());
5969}
5970
[email protected]b172aee2012-04-10 17:05:265971void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:105972#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:295973 // The UI may be in an event-tracking loop, such as between the
5974 // mouse-down and mouse-up in text selection or a button click.
5975 // Defer the close until after tracking is complete, so that we
5976 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:295977 // TODO(shess): This could get more fine-grained. For instance,
5978 // closing a tab in another window while selecting text in the
5979 // current window's Omnibox should be just fine.
Christopher Cameron9ae31e0d2019-03-01 20:01:195980 if (view_->CloseTabAfterEventTrackingIfNeeded())
[email protected]07707302009-11-06 00:50:295981 return;
[email protected]60780f412013-02-25 16:34:105982#endif
[email protected]07707302009-11-06 00:50:295983
[email protected]420ae012009-04-24 05:16:325984 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:525985 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:515986 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:325987}
5988
Avi Drissman014dec72018-06-07 02:34:015989void WebContentsImpl::RequestSetBounds(const gfx::Rect& new_bounds) {
5990 if (delegate_)
5991 delegate_->SetContentsBounds(this, new_bounds);
[email protected]420ae012009-04-24 05:16:325992}
5993
fdegansa696e5112015-04-17 01:57:595994void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:095995 bool to_different_document) {
Evan Stadec3b26022017-07-14 19:50:245996 LoadingStateChanged(frame_tree_node->IsMainFrame() && to_different_document,
5997 false, nullptr);
dmazzonibf8cec42015-02-08 08:28:085998
Xiyuan Xia2a66b112018-12-06 15:52:165999 // Reset the focus state from DidStartNavigation to false if a new load starts
6000 // afterward, in case loading logic triggers a FocusLocationBarByDefault call.
6001 should_focus_location_bar_by_default_ = false;
Ian Prestcdd843d2020-01-28 18:59:586002
6003 // Notify accessibility that the user is navigating away from the
6004 // current document.
6005 // TODO(domfarolino, dmazzoni): Do this using WebContentsObserver. See
6006 // https://crbug.com/981271.
6007 BrowserAccessibilityManager* manager =
6008 frame_tree_node->current_frame_host()->browser_accessibility_manager();
6009 if (manager)
6010 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:326011}
6012
fdegansc73eec22015-03-19 14:47:546013void WebContentsImpl::DidStopLoading() {
dcheng59716272016-04-09 05:19:086014 std::unique_ptr<LoadNotificationDetails> details;
[email protected]420ae012009-04-24 05:16:326015
[email protected]9595fd82013-04-19 21:28:496016 // Use the last committed entry rather than the active one, in case a
6017 // pending entry has been created.
6018 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:206019 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:496020
[email protected]420ae012009-04-24 05:16:326021 // An entry may not exist for a stop when loading an initial blank page or
6022 // if an iframe injected by script into a blank page finishes loading.
6023 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:206024 base::TimeDelta elapsed =
6025 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:326026
6027 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:516028 entry->GetVirtualURL(),
[email protected]420ae012009-04-24 05:16:326029 elapsed,
6030 &controller_,
6031 controller_.GetCurrentEntryIndex()));
6032 }
6033
clamy44e84ce2016-02-22 15:38:256034 LoadingStateChanged(true, false, details.get());
[email protected]420ae012009-04-24 05:16:326035}
6036
fdegansa696e5112015-04-17 01:57:596037void WebContentsImpl::DidChangeLoadProgress() {
Nate Chapin22ea6592019-03-05 22:29:026038 if (is_being_destroyed_)
6039 return;
fdegansa696e5112015-04-17 01:57:596040 double load_progress = frame_tree_.load_progress();
6041
6042 // The delegate is notified immediately for the first and last updates. Also,
6043 // since the message loop may be pretty busy when a page is loaded, it might
6044 // not execute a posted task in a timely manner so the progress report is sent
6045 // immediately if enough time has passed.
6046 base::TimeDelta min_delay =
6047 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
6048 bool delay_elapsed = loading_last_progress_update_.is_null() ||
6049 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
6050
6051 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
6052 // If there is a pending task to send progress, it is now obsolete.
6053 loading_weak_factory_.InvalidateWeakPtrs();
6054
6055 // Notify the load progress change.
6056 SendChangeLoadProgress();
6057
6058 // Clean-up the states if needed.
6059 if (load_progress == 1.0)
6060 ResetLoadProgressState();
6061 return;
6062 }
6063
6064 if (loading_weak_factory_.HasWeakPtrs())
6065 return;
6066
skyostil95082a62015-06-05 19:53:076067 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
tzike2aca992017-09-05 08:50:546068 FROM_HERE,
6069 base::BindOnce(&WebContentsImpl::SendChangeLoadProgress,
6070 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:596071 min_delay);
6072}
6073
avid6d88b912017-01-13 00:16:006074std::vector<std::unique_ptr<NavigationThrottle>>
6075WebContentsImpl::CreateThrottlesForNavigation(
clamycbf524d42016-09-27 12:48:356076 NavigationHandle* navigation_handle) {
Charlie Reis96077362019-07-04 00:34:046077 auto throttles = GetContentClient()->browser()->CreateThrottlesForNavigation(
clamycbf524d42016-09-27 12:48:356078 navigation_handle);
Charlie Reis96077362019-07-04 00:34:046079
6080 // This is not a normal place to be adding a throttle. However, in the case
6081 // javascript dialogs, related logic is present in the web_contents/ layer,
6082 // and the purpose of the throttle is to ensure that navigation commits are
6083 // deferred for the entire WebContents. Most throttles are either added by
6084 // the embederrer outside of content/, or are per-frame and added by
6085 // NavigationThrottleRunner.
6086 std::unique_ptr<content::NavigationThrottle> dialog_throttle =
6087 JavaScriptDialogNavigationThrottle::MaybeCreateThrottleFor(
6088 navigation_handle);
6089 if (dialog_throttle)
6090 throttles.push_back(std::move(dialog_throttle));
6091
6092 return throttles;
clamycbf524d42016-09-27 12:48:356093}
6094
clamy1e5574e2016-09-29 16:48:446095std::unique_ptr<NavigationUIData> WebContentsImpl::GetNavigationUIData(
6096 NavigationHandle* navigation_handle) {
clamy1e5574e2016-09-29 16:48:446097 return GetContentClient()->browser()->GetNavigationUIData(navigation_handle);
6098}
6099
pdr15f5b5b2017-06-20 00:58:006100void WebContentsImpl::DidCancelLoading() {
6101 controller_.DiscardNonCommittedEntries();
6102
6103 // Update the URL display.
6104 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
6105}
6106
[email protected]59167c22013-06-03 18:07:326107void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:106108 has_accessed_initial_document_ = true;
6109
[email protected]d1371bf8e2014-04-19 03:26:246110 // We may have left a failed browser-initiated navigation in the address bar
6111 // to let the user edit it and try again. Clear it now that content might
6112 // show up underneath it.
6113 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:456114 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:246115
[email protected]59167c22013-06-03 18:07:326116 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:506117 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:326118}
6119
alexmosbe2f4c32015-03-10 02:30:236120void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
6121 const std::string& name) {
ericwilligersde386342016-10-19 02:35:096122 for (auto& observer : observers_)
6123 observer.FrameNameChanged(render_frame_host, name);
alexmosbe2f4c32015-03-10 02:30:236124}
6125
John Delaneyedd8d6c2019-01-25 00:23:576126void WebContentsImpl::DidReceiveFirstUserActivation(
6127 RenderFrameHost* render_frame_host) {
6128 for (auto& observer : observers_)
6129 observer.FrameReceivedFirstUserActivation(render_frame_host);
6130}
6131
John Delaney0146a742019-01-25 19:25:286132void WebContentsImpl::DidChangeDisplayState(RenderFrameHost* render_frame_host,
6133 bool is_display_none) {
6134 for (auto& observer : observers_)
6135 observer.FrameDisplayStateChanged(render_frame_host, is_display_none);
6136}
6137
6138void WebContentsImpl::FrameSizeChanged(RenderFrameHost* render_frame_host,
6139 const gfx::Size& frame_size) {
6140 for (auto& observer : observers_)
6141 observer.FrameSizeChanged(render_frame_host, frame_size);
6142}
6143
[email protected]39f2f9252014-05-03 00:54:016144void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:296145 RenderFrameHost* render_frame_host) {
falken52a56e32016-12-08 05:02:406146 ShowInsecureLocalhostWarningIfNeeded();
6147
Alexander Timindd0fa0c52019-11-06 13:03:376148 GetRenderViewHost()->DocumentOnLoadCompletedInMainFrame();
6149
creis97867aa2017-02-17 18:39:456150 is_notifying_observers_ = true;
ericwilligersde386342016-10-19 02:35:096151 for (auto& observer : observers_)
6152 observer.DocumentOnLoadCompletedInMainFrame();
creis97867aa2017-02-17 18:39:456153 is_notifying_observers_ = false;
[email protected]6578fef2013-10-14 02:35:096154
6155 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:216156 NotificationService::current()->Notify(
6157 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
6158 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:296159 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:086160}
6161
creis8eb8ef22015-11-04 22:51:386162void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
6163 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:386164 // The state update affects the last NavigationEntry associated with the given
6165 // |render_frame_host|. This may not be the last committed NavigationEntry (as
6166 // in the case of an UpdateState from a frame being swapped out). We track
6167 // which entry this is in the RenderFrameHost's nav_entry_id.
6168 RenderFrameHostImpl* rfhi =
6169 static_cast<RenderFrameHostImpl*>(render_frame_host);
6170 NavigationEntryImpl* entry =
6171 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
6172 if (!entry)
6173 return;
6174
6175 FrameNavigationEntry* frame_entry =
6176 entry->GetFrameEntry(rfhi->frame_tree_node());
6177 if (!frame_entry)
6178 return;
6179
creisd06a9422015-11-11 03:08:456180 // The SiteInstance might not match if we do a cross-process navigation with
6181 // replacement (e.g., auto-subframe), in which case the swap out of the old
6182 // RenderFrameHost runs in the background after the old FrameNavigationEntry
6183 // has already been replaced and destroyed.
6184 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
6185 return;
6186
creis8eb8ef22015-11-04 22:51:386187 if (page_state == frame_entry->page_state())
6188 return; // Nothing to update.
6189
creis0cade2e2017-02-28 06:37:476190 DCHECK(page_state.IsValid()) << "Shouldn't set an empty PageState.";
nasko34634672016-07-29 18:46:066191
6192 // The document_sequence_number and item_sequence_number recorded in the
6193 // FrameNavigationEntry should not differ from the one coming with the update,
6194 // since it must come from the same document. Do not update it if a difference
6195 // is detected, as this indicates that |frame_entry| is not the correct one.
6196 ExplodedPageState exploded_state;
6197 if (!DecodePageState(page_state.ToEncodedData(), &exploded_state))
6198 return;
6199
6200 if (exploded_state.top.document_sequence_number !=
6201 frame_entry->document_sequence_number() ||
6202 exploded_state.top.item_sequence_number !=
6203 frame_entry->item_sequence_number()) {
6204 return;
6205 }
6206
nasko04a322f25a2016-09-01 00:00:346207 frame_entry->SetPageState(page_state);
creis8eb8ef22015-11-04 22:51:386208 controller_.NotifyEntryChanged(entry);
6209}
6210
[email protected]ef3adfc2014-05-11 00:04:546211void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
[email protected]ef3adfc2014-05-11 00:04:546212 const base::string16& title,
6213 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:546214 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:586215 // For example, it might be from a recently swapped out RFH.
avi1edc8552016-10-13 21:37:166216 NavigationEntryImpl* entry = controller_.GetEntryWithUniqueID(
creisad8c31a2016-05-24 17:07:046217 static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id());
[email protected]ef3adfc2014-05-11 00:04:546218
6219 // We can handle title updates when we don't have an entry in
6220 // UpdateTitleForEntry, but only if the update is from the current RVH.
6221 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:586222 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:546223 return;
6224
6225 // TODO(evan): make use of title_direction.
6226 // http://code.google.com/p/chromium/issues/detail?id=27094
afakhry6f0c1ec22016-07-14 13:55:136227 UpdateTitleForEntry(entry, title);
[email protected]ef3adfc2014-05-11 00:04:546228}
6229
[email protected]e1c3a552012-05-04 20:51:326230void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
6231 // Tell the active RenderViewHost to run unload handlers and close, as long
6232 // as the request came from a RenderViewHost in the same BrowsingInstance.
6233 // In most cases, we receive this from a swapped out RenderViewHost.
6234 // It is possible to receive it from one that has just been swapped in,
6235 // in which case we might as well deliver the message anyway.
6236 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:526237 ClosePage();
[email protected]e1c3a552012-05-04 20:51:326238}
6239
alexmose7da5a12015-04-09 02:22:166240bool WebContentsImpl::ShouldRouteMessageEvent(
6241 RenderFrameHost* target_rfh,
6242 SiteInstance* source_site_instance) const {
6243 // Allow the message if this WebContents is dedicated to a browser plugin
6244 // guest.
[email protected]0eba810b2012-10-18 03:19:366245 // Note: This check means that an embedder could theoretically receive a
6246 // postMessage from anyone (not just its own guests). However, this is
6247 // probably not a risk for apps since other pages won't have references
6248 // to App windows.
alexmose7da5a12015-04-09 02:22:166249 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
6250}
[email protected]f546640b2012-05-15 00:03:496251
alexmos58729042015-06-18 23:20:006252void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:166253 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
6254 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:496255
alexmose7da5a12015-04-09 02:22:166256 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:146257 // If this message is going to outer WebContents from inner WebContents,
6258 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
6259 // already created a RenderFrameProxyHost for that purpose.
6260 if (GetBrowserPluginEmbedder() &&
W. James MacLean2539adb32019-12-13 00:40:446261 source_web_contents->browser_plugin_guest_) {
lazyboy6ec48b2a2015-06-29 15:18:146262 return;
W. James MacLean2539adb32019-12-13 00:40:446263 }
lazyboy6ec48b2a2015-06-29 15:18:146264
lfg812874d2016-02-09 22:26:136265 if (this != source_web_contents && GetBrowserPluginGuest()) {
naskob3041b98a42016-03-12 04:43:066266 // We create a RenderFrameProxyHost for the embedder in the guest's render
6267 // process but we intentionally do not expose the embedder's opener chain
6268 // to it.
6269 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
6270 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:496271 } else {
alexmos58729042015-06-18 23:20:006272 RenderFrameHostImpl* source_rfhi =
6273 static_cast<RenderFrameHostImpl*>(source_rfh);
6274 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:396275 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:496276 }
6277 }
[email protected]f546640b2012-05-15 00:03:496278}
6279
avallee9993fca2016-11-17 06:16:506280void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() {
Adithya Srinivasan11af2c52019-12-16 22:52:556281 DCHECK(!portal());
avallee9993fca2016-11-17 06:16:506282 // Only change focus if we are not currently focused.
6283 WebContentsImpl* old_contents = GetFocusedWebContents();
6284 if (old_contents == this)
6285 return;
6286
paulmeyerfeafc2d2017-04-25 21:46:406287 GetOutermostWebContents()->node_.SetFocusedWebContents(this);
6288
avallee9993fca2016-11-17 06:16:506289 // Send a page level blur to the old contents so that it displays inactive UI
6290 // and focus this contents to activate it.
6291 if (old_contents)
6292 old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false);
avalleec2ff1ef2017-01-21 00:12:306293
6294 // Make sure the outer web contents knows our frame is focused. Otherwise, the
6295 // outer renderer could have the element before or after the frame element
6296 // focused which would return early without actually advancing focus.
avalleed68cdd12017-06-21 22:07:276297 FocusOuterAttachmentFrameChain();
avalleec2ff1ef2017-01-21 00:12:306298
lfg1453e412017-04-11 00:48:506299 if (ShowingInterstitialPage()) {
creisadca9862017-06-16 19:12:116300 static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame())
lfg1453e412017-04-11 00:48:506301 ->GetRenderWidgetHost()
6302 ->SetPageFocus(true);
6303 } else {
6304 GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true);
6305 }
avallee9993fca2016-11-17 06:16:506306}
6307
avallee0206f782016-07-28 18:55:336308void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node,
6309 SiteInstance* source) {
Adithya Srinivasan11af2c52019-12-16 22:52:556310 DCHECK(!portal());
avallee0206f782016-07-28 18:55:336311 frame_tree_.SetFocusedFrame(node, source);
avalleed68cdd12017-06-21 22:07:276312
Lucas Furukawa Gadaniabbfa342017-08-29 19:37:576313 if (auto* inner_contents = node_.GetInnerWebContentsInFrame(node)) {
6314 // |this| is an outer WebContents and |node| represents an inner
6315 // WebContents. Transfer the focus to the inner contents if |this| is
6316 // focused.
6317 if (GetFocusedWebContents() == this)
6318 inner_contents->SetAsFocusedWebContentsIfNecessary();
6319 } else if (node_.OuterContentsFrameTreeNode() &&
6320 node_.OuterContentsFrameTreeNode()
6321 ->current_frame_host()
6322 ->GetSiteInstance() == source) {
6323 // |this| is an inner WebContents, |node| is its main FrameTreeNode and
6324 // the outer WebContents FrameTreeNode is at |source|'s SiteInstance.
6325 // Transfer the focus to the inner WebContents if the outer WebContents is
6326 // focused. This branch is used when an inner WebContents is focused through
Lowell Mannersa9530382019-08-01 09:46:576327 // its RenderFrameProxyHost (via FrameFocused mojo call, used to
Lucas Furukawa Gadaniabbfa342017-08-29 19:37:576328 // implement the window.focus() API).
6329 if (GetFocusedWebContents() == GetOuterWebContents())
6330 SetAsFocusedWebContentsIfNecessary();
6331 } else if (!GetOuterWebContents()) {
6332 // This is an outermost WebContents.
6333 SetAsFocusedWebContentsIfNecessary();
Lucas Furukawa Gadaniabbfa342017-08-29 19:37:576334 }
avalleed68cdd12017-06-21 22:07:276335}
6336
Avi Drissman36f801f2018-02-01 20:06:046337void WebContentsImpl::DidCallFocus() {
6338 // Any explicit focusing of another window while this WebContents is in
6339 // fullscreen can be used to confuse the user, so drop fullscreen.
Avi Drissmand18c51972018-08-15 18:32:096340 ForSecurityDropFullscreen();
Avi Drissman36f801f2018-02-01 20:06:046341}
6342
avalleed68cdd12017-06-21 22:07:276343RenderFrameHost* WebContentsImpl::GetFocusedFrameIncludingInnerWebContents() {
6344 WebContentsImpl* contents = this;
6345 FrameTreeNode* focused_node = contents->frame_tree_.GetFocusedFrame();
6346
6347 // If there is no focused frame in the outer WebContents, we need to return
6348 // null.
6349 if (!focused_node)
6350 return nullptr;
6351
6352 // If the focused frame is embedding an inner WebContents, we must descend
6353 // into that contents. If the current WebContents does not have a focused
6354 // frame, return the main frame of this contents instead of the focused empty
6355 // frame embedding this contents.
6356 while (true) {
6357 contents = contents->node_.GetInnerWebContentsInFrame(focused_node);
6358 if (!contents)
6359 return focused_node->current_frame_host();
6360
6361 focused_node = contents->frame_tree_.GetFocusedFrame();
6362 if (!focused_node)
6363 return contents->GetMainFrame();
6364 }
avallee0206f782016-07-28 18:55:336365}
6366
Lucas Furukawa Gadaniabbfa342017-08-29 19:37:576367void WebContentsImpl::OnAdvanceFocus(RenderFrameHostImpl* source_rfh) {
6368 // When a RenderFrame needs to advance focus to a RenderFrameProxy (by hitting
6369 // TAB), the RenderFrameProxy sends an IPC to RenderFrameProxyHost. When this
6370 // RenderFrameProxyHost represents an inner WebContents, the outer WebContents
6371 // needs to focus the inner WebContents.
6372 if (GetOuterWebContents() &&
6373 GetOuterWebContents() == source_rfh->delegate()->GetAsWebContents() &&
6374 GetFocusedWebContents() == GetOuterWebContents()) {
6375 SetAsFocusedWebContentsIfNecessary();
6376 }
6377}
6378
ekaramada110f642016-12-21 19:47:286379void WebContentsImpl::OnFocusedElementChangedInFrame(
6380 RenderFrameHostImpl* frame,
6381 const gfx::Rect& bounds_in_root_view) {
6382 RenderWidgetHostViewBase* root_view =
6383 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
6384 if (!root_view || !frame->GetView())
6385 return;
6386
6387 // Converting to screen coordinates.
6388 gfx::Point origin = bounds_in_root_view.origin();
6389 origin += root_view->GetViewBounds().OffsetFromOrigin();
6390 gfx::Rect bounds_in_screen(origin, bounds_in_root_view.size());
6391
6392 root_view->FocusedNodeChanged(frame->has_focused_editable_element(),
6393 bounds_in_screen);
6394
6395 FocusedNodeDetails details = {frame->has_focused_editable_element(),
6396 bounds_in_screen};
6397
6398 // TODO(ekaramad): We should replace this with an observer notification
6399 // (https://crbug.com/675975).
6400 NotificationService::current()->Notify(
6401 NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
6402 Source<RenderViewHost>(GetRenderViewHost()),
6403 Details<FocusedNodeDetails>(&details));
Jeff Fisher709b4c52019-07-29 20:07:346404
6405 for (auto& observer : observers_)
6406 observer.OnFocusChangedInPage(&details);
ekaramada110f642016-12-21 19:47:286407}
6408
Lowell Manners1de5242e2019-04-25 10:18:466409bool WebContentsImpl::DidAddMessageToConsole(
6410 blink::mojom::ConsoleMessageLevel log_level,
6411 const base::string16& message,
6412 int32_t line_no,
6413 const base::string16& source_id) {
Devlin Cronin5ea668f32019-12-18 21:57:586414 for (auto& observer : observers_)
6415 observer.OnDidAddMessageToConsole(log_level, message, line_no, source_id);
6416
[email protected]a796f202012-05-30 14:14:256417 if (!delegate_)
6418 return false;
Lowell Manners1de5242e2019-04-25 10:18:466419 return delegate_->DidAddMessageToConsole(this, log_level, message, line_no,
avia90ae4e2016-11-11 20:49:336420 source_id);
[email protected]a796f202012-05-30 14:14:256421}
6422
Daniel Cheng90196c82018-04-25 21:49:146423void WebContentsImpl::DidReceiveInputEvent(
dominickn9c7ceaa32016-02-27 01:52:536424 RenderWidgetHostImpl* render_widget_host,
6425 const blink::WebInputEvent::Type type) {
Dominick Ng37a15052018-07-17 23:56:356426 if (!IsUserInteractionInputType(type))
Daniel Cheng90196c82018-04-25 21:49:146427 return;
6428
kenrb19221852016-04-29 17:21:406429 // Ignore unless the widget is currently in the frame tree.
6430 if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host))
avic3aa8422015-11-09 20:57:226431 return;
6432
Daniel Cheng90196c82018-04-25 21:49:146433 if (type != blink::WebInputEvent::kGestureScrollBegin)
6434 last_interactive_input_event_time_ = ui::EventTimeForNow();
dominickn9c7ceaa32016-02-27 01:52:536435
Dominick Ng37a15052018-07-17 23:56:356436 for (auto& observer : observers_)
6437 observer.DidGetUserInteraction(type);
dominickn2dd142dd2015-10-29 05:30:506438}
6439
Avi Drissman738ea192018-08-29 20:24:166440bool WebContentsImpl::ShouldIgnoreInputEvents() {
6441 WebContentsImpl* web_contents = this;
6442 while (web_contents) {
6443 if (web_contents->ignore_input_events_)
6444 return true;
6445 web_contents = web_contents->GetOuterWebContents();
6446 }
6447
6448 return false;
6449}
6450
avallee9993fca2016-11-17 06:16:506451void WebContentsImpl::FocusOwningWebContents(
6452 RenderWidgetHostImpl* render_widget_host) {
Alex Moshchukc4f0a722019-11-19 22:41:286453 RenderWidgetHostImpl* main_frame_widget_host =
6454 GetMainFrame()->GetRenderWidgetHost();
avallee9993fca2016-11-17 06:16:506455 RenderWidgetHostImpl* focused_widget =
Alex Moshchukc4f0a722019-11-19 22:41:286456 GetFocusedRenderWidgetHost(main_frame_widget_host);
avallee9993fca2016-11-17 06:16:506457
6458 if (focused_widget != render_widget_host &&
avallee8e881592016-11-19 00:39:306459 (!focused_widget ||
6460 focused_widget->delegate() != render_widget_host->delegate())) {
avallee9993fca2016-11-17 06:16:506461 SetAsFocusedWebContentsIfNecessary();
6462 }
6463}
6464
[email protected]b172aee2012-04-10 17:05:266465void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:446466 // Notify observers.
ericwilligersde386342016-10-19 02:35:096467 for (auto& observer : observers_)
6468 observer.DidGetIgnoredUIEvent();
[email protected]fa1cf0b82010-01-15 21:49:446469}
6470
avic3aa8422015-11-09 20:57:226471void WebContentsImpl::RendererUnresponsive(
Lukasz Anforowicz52b93722018-06-20 16:11:396472 RenderWidgetHostImpl* render_widget_host,
6473 base::RepeatingClosure hang_monitor_restarter) {
avic031d392017-03-03 03:09:426474 if (ShouldIgnoreUnresponsiveRenderer())
[email protected]e5fc1632011-08-08 07:51:536475 return;
6476
Lukasz Anforowicz4f0593d2018-09-21 18:33:546477 // Do not report hangs (to task manager, to hang renderer dialog, etc.) for
6478 // invisible tabs (like extension background page, background tabs). See
6479 // https://crbug.com/881812 for rationale and for choosing the visibility
6480 // (rather than process priority) as the signal here.
6481 if (GetVisibility() != Visibility::VISIBLE)
6482 return;
6483
Avi Drissman8920def2018-01-31 19:53:366484 if (!render_widget_host->renderer_initialized())
[email protected]55452902011-06-01 21:57:476485 return;
6486
Lukasz Anforowicz4f0593d2018-09-21 18:33:546487 for (auto& observer : observers_)
6488 observer.OnRendererUnresponsive(render_widget_host->GetProcess());
6489
Dave Tapuskac6146c52017-12-20 22:48:156490 if (delegate_)
Lukasz Anforowicz52b93722018-06-20 16:11:396491 delegate_->RendererUnresponsive(this, render_widget_host,
6492 std::move(hang_monitor_restarter));
[email protected]420ae012009-04-24 05:16:326493}
6494
avic3aa8422015-11-09 20:57:226495void WebContentsImpl::RendererResponsive(
6496 RenderWidgetHostImpl* render_widget_host) {
[email protected]6934a702011-12-20 00:04:516497 if (delegate_)
Avi Drissman1572e8c3c2018-02-02 19:06:366498 delegate_->RendererResponsive(this, render_widget_host);
[email protected]420ae012009-04-24 05:16:326499}
6500
Alex Moshchuk7b4f0652019-05-30 18:54:416501void WebContentsImpl::SubframeCrashed(
6502 blink::mojom::FrameVisibility visibility) {
6503 // If a subframe crashed on a hidden tab, mark the tab for reload to avoid
6504 // showing a sad frame to the user if they ever switch back to that tab. Do
6505 // this for subframes that are either visible in viewport or visible but
6506 // scrolled out of view, but skip subframes that are not rendered (e.g., via
6507 // "display:none"), since in that case the user wouldn't see a sad frame
6508 // anyway.
6509 bool did_mark_for_reload = false;
6510 if (IsHidden() && visibility != blink::mojom::FrameVisibility::kNotRendered &&
6511 base::FeatureList::IsEnabled(
6512 features::kReloadHiddenTabsWithCrashedSubframes)) {
6513 controller_.SetNeedsReload(
6514 NavigationControllerImpl::NeedsReloadType::kCrashedSubframe);
6515 did_mark_for_reload = true;
6516 UMA_HISTOGRAM_ENUMERATION(
6517 "Stability.ChildFrameCrash.TabMarkedForReload.Visibility", visibility);
6518 }
6519
6520 UMA_HISTOGRAM_BOOLEAN("Stability.ChildFrameCrash.TabMarkedForReload",
6521 did_mark_for_reload);
6522}
6523
[email protected]b172aee2012-04-10 17:05:266524void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:556525 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:326526 bool* proceed_to_fire_unload) {
ericwilligersde386342016-10-19 02:35:096527 for (auto& observer : observers_)
Chris Hamilton3b3e315d2018-09-19 13:16:216528 observer.BeforeUnloadFired(proceed, proceed_time);
[email protected]6934a702011-12-20 00:04:516529 if (delegate_)
6530 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:096531 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:326532}
6533
[email protected]58d5cfe2013-07-10 02:40:526534void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:546535 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:236536 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:226537 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:546538}
6539
Jianzhou Fengd8720c72018-01-18 03:06:306540void WebContentsImpl::UpdateRenderViewSizeForRenderManager(bool is_main_frame) {
[email protected]8643e6d2012-01-18 20:26:106541 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
Jianzhou Fengd8720c72018-01-18 03:06:306542 gfx::Size size = GetSizeForNewRenderView(is_main_frame);
[email protected]0323ee42010-02-17 22:03:266543 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
6544 // here during container initialization and normal window size will be set
6545 // later. In case of tab duplication this resizing to 0x0 prevents setting
6546 // normal size later so just ignore it.
6547 if (!size.IsEmpty())
6548 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:326549}
6550
[email protected]af905902013-10-01 21:38:516551void WebContentsImpl::CancelModalDialogsForRenderManager() {
6552 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:546553 // deferrer would prevent us from swapping out. We also clear the state
6554 // because this is a cross-process navigation, which means that it's a new
6555 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:176556 //
Lei Zhang6410ec1a2019-01-31 21:38:586557 // Note that we don't bother telling |browser_plugin_embedder_| because the
creis89a0f782015-05-27 16:13:176558 // cross-process navigation will either destroy the browser plugins or not
6559 // require their dialogs to close.
avi5d3b8692016-10-12 22:00:466560 if (dialog_manager_) {
avi6879fcf2017-01-21 05:27:536561 dialog_manager_->CancelDialogs(this, /*reset_state=*/true);
avi5d3b8692016-10-12 22:00:466562 }
[email protected]af905902013-10-01 21:38:516563}
6564
[email protected]02d7b6e2014-06-24 21:01:506565void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
6566 RenderFrameHost* new_host,
6567 bool is_main_frame) {
6568 if (is_main_frame) {
Fergal Daly6767b2e2020-02-04 03:15:166569 RenderViewHost* old_rvh =
6570 old_host ? old_host->GetRenderViewHost() : nullptr;
6571 RenderViewHost* new_rvh = new_host->GetRenderViewHost();
6572 // |old_rvh| and |new_rvh| might be equal when navigating from a crashed
6573 // RenderFrameHost to a new same-site one. With RenderDocument, this will
6574 // happen for every same-site navigation.
6575 if (old_rvh != new_rvh)
6576 NotifyViewSwapped(old_rvh, new_rvh);
[email protected]a6b73c62013-02-11 23:05:086577
[email protected]02d7b6e2014-06-24 21:01:506578 // Make sure the visible RVH reflects the new delegate's preferences.
6579 if (delegate_)
6580 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:396581
dmazzoni62111452017-04-28 23:46:556582 RenderWidgetHostViewBase* rwhv =
6583 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
6584 if (rwhv)
6585 rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID());
[email protected]02d7b6e2014-06-24 21:01:506586 }
6587
Jinsuk Kim895b2c52018-07-03 06:49:166588 NotifyFrameSwapped(old_host, new_host, is_main_frame);
[email protected]3a3d47472010-07-15 21:03:546589}
6590
naskof5940b9f2015-03-02 23:04:056591void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
Jinsuk Kim895b2c52018-07-03 06:49:166592 RenderFrameHost* old_host,
6593 RenderFrameHost* new_host) {
6594 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
6595 new_host->GetRenderViewHost());
naskof5940b9f2015-03-02 23:04:056596}
6597
[email protected]b172aee2012-04-10 17:05:266598NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:196599 return GetController();
[email protected]3a3d47472010-07-15 21:03:546600}
6601
dcheng59716272016-04-09 05:19:086602std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:296603 const GURL& url) {
Dan Beam055fe8f2017-10-04 23:23:366604 return CreateWebUI(url);
[email protected]420ae012009-04-24 05:16:326605}
6606
creisadca9862017-06-16 19:12:116607InterstitialPageImpl* WebContentsImpl::GetInterstitialForRenderManager() {
6608 return interstitial_page_;
6609}
6610
lfgbede6392015-09-11 21:54:066611void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
6612 RenderViewHost* render_view_host) {
lfgc740d4b22016-04-15 16:45:336613 RenderWidgetHostViewBase* rwh_view =
W. James MacLean13d834d2019-12-04 16:06:456614 view_->CreateViewForWidget(render_view_host->GetWidget());
danakjf616f2252019-09-18 21:44:096615 rwh_view->SetSize(GetSizeForNewRenderView(true));
lfgbede6392015-09-11 21:54:066616}
6617
6618bool WebContentsImpl::CreateRenderViewForRenderManager(
6619 RenderViewHost* render_view_host,
6620 int opener_frame_routing_id,
6621 int proxy_routing_id,
Pavel Feldman25234722017-10-11 02:49:066622 const base::UnguessableToken& devtools_frame_token,
lfgbede6392015-09-11 21:54:066623 const FrameReplicationState& replicated_frame_state) {
6624 TRACE_EVENT0("browser,navigation",
6625 "WebContentsImpl::CreateRenderViewForRenderManager");
6626
piman00cf9402017-04-03 17:09:206627 if (proxy_routing_id == MSG_ROUTING_NONE)
lfg9431efd2016-12-14 14:45:266628 CreateRenderWidgetHostViewForRenderManager(render_view_host);
lfg9431efd2016-12-14 14:45:266629
piman00cf9402017-04-03 17:09:206630 if (!static_cast<RenderViewHostImpl*>(render_view_host)
6631 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
Pavel Feldman25234722017-10-11 02:49:066632 devtools_frame_token, replicated_frame_state,
6633 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:526634 return false;
[email protected]14392a52012-05-02 20:28:446635 }
W. James MacLean62198672019-06-04 16:46:106636 // Set the TextAutosizer state from the main frame's renderer on the new view,
6637 // but only if it's not for the main frame. Main frame renderers should create
6638 // this state themselves from up-to-date values, so we shouldn't override it
6639 // with the cached values.
6640 if (!render_view_host->GetMainFrame()) {
6641 render_view_host->Send(
6642 new PageMsg_UpdateTextAutosizerPageInfoForRemoteMainFrames(
6643 render_view_host->GetRoutingID(), text_autosizer_page_info_));
6644 }
[email protected]a4127722011-04-27 23:13:526645
Lucas Furukawa Gadaniaed1fed2017-10-13 17:34:146646 if (proxy_routing_id == MSG_ROUTING_NONE && node_.outer_web_contents())
6647 ReattachToOuterWebContentsFrame();
6648
avi2b177592014-12-10 02:08:026649 SetHistoryOffsetAndLengthForView(render_view_host,
6650 controller_.GetLastCommittedEntryIndex(),
6651 controller_.GetEntryCount());
6652
[email protected]a220b5932013-09-21 03:47:446653#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:506654 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
6655 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:446656 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:446657 if (rwh_view) {
6658 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
Fady Samuel0b911822018-04-25 13:22:166659 render_widget_host->SynchronizeVisualProperties();
[email protected]245f7d52011-11-28 15:36:446660 }
[email protected]f8233cc2011-05-31 20:24:506661#endif
6662
[email protected]420ae012009-04-24 05:16:326663 return true;
6664}
6665
[email protected]82307f6b2014-08-07 03:30:126666bool WebContentsImpl::CreateRenderFrameForRenderManager(
6667 RenderFrameHost* render_frame_host,
arthursonzogni1efc7b962019-03-14 09:36:336668 int previous_routing_id,
alexmosa181efc2015-09-03 00:39:046669 int opener_routing_id,
japhete6adf142014-10-31 00:01:496670 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:046671 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:436672 TRACE_EVENT0("browser,navigation",
6673 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:126674
6675 RenderFrameHostImpl* rfh =
6676 static_cast<RenderFrameHostImpl*>(render_frame_host);
arthursonzogni1efc7b962019-03-14 09:36:336677 if (!rfh->CreateRenderFrame(previous_routing_id, opener_routing_id,
alexmosa181efc2015-09-03 00:39:046678 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:126679 return false;
6680
6681 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
6682 // RenderFrameHost will have to be associated with the appropriate
6683 // RenderWidgetHostView or a new one should be created here.
6684
6685 return true;
6686}
6687
mfomitchev2b8b066a2016-01-28 19:23:156688#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:456689
[email protected]155c7f22013-12-09 17:07:186690base::android::ScopedJavaLocalRef<jobject>
6691WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:406692 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:566693 return GetWebContentsAndroid()->GetJavaObject();
6694}
[email protected]155c7f22013-12-09 17:07:186695
[email protected]0e813a52014-08-13 10:34:566696WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
Kevin McNee576bb5d82019-05-29 16:47:516697 if (!web_contents_android_) {
6698 web_contents_android_ = std::make_unique<WebContentsAndroid>(this);
[email protected]155c7f22013-12-09 17:07:186699 }
Kevin McNee576bb5d82019-05-29 16:47:516700 return web_contents_android_.get();
6701}
6702
6703void WebContentsImpl::ClearWebContentsAndroid() {
6704 DCHECK_CURRENTLY_ON(BrowserThread::UI);
6705 web_contents_android_.reset();
[email protected]155c7f22013-12-09 17:07:186706}
6707
paulmeyerc0b762b2016-04-13 11:55:176708void WebContentsImpl::ActivateNearestFindResult(float x,
6709 float y) {
6710 GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y);
6711}
6712
6713void WebContentsImpl::RequestFindMatchRects(int current_version) {
6714 GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version);
6715}
6716
[email protected]7d244f12013-08-22 21:41:516717bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:066718 return CreateRenderViewForRenderManager(
6719 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
Pavel Feldman25234722017-10-11 02:49:066720 frame_tree_.root()->devtools_frame_token(),
lfgbede6392015-09-11 21:54:066721 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:516722}
[email protected]fc2b46b2014-05-03 16:33:456723
rockot400ea35b2016-10-15 19:15:326724service_manager::InterfaceProvider* WebContentsImpl::GetJavaInterfaces() {
sammcf5f1b0f2016-09-20 23:05:116725 if (!java_interfaces_) {
Gyuyoung Kim6c9ce9022019-11-26 05:40:086726 mojo::PendingRemote<service_manager::mojom::InterfaceProvider> provider;
6727 BindInterfaceRegistryForWebContents(
6728 provider.InitWithNewPipeAndPassReceiver(), this);
rockot400ea35b2016-10-15 19:15:326729 java_interfaces_.reset(new service_manager::InterfaceProvider);
sammcf5f1b0f2016-09-20 23:05:116730 java_interfaces_->Bind(std::move(provider));
6731 }
6732 return java_interfaces_.get();
6733}
6734
Francois Doray6c26f3342018-08-24 17:17:226735#endif
6736
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:416737bool WebContentsImpl::CompletedFirstVisuallyNonEmptyPaint() {
Carlos Caballero91fffb22019-10-29 15:24:306738 return GetRenderViewHost()->did_first_visually_non_empty_paint();
spqchane72c3cb2017-06-30 23:02:106739}
6740
pkotwicz75ca8ffd2016-02-16 23:10:196741void WebContentsImpl::OnDidDownloadImage(
Avi Drissmana5a52dd2018-03-27 03:39:026742 ImageDownloadCallback callback,
pkotwicz75ca8ffd2016-02-16 23:10:196743 int id,
6744 const GURL& image_url,
leon.hancbc4bc3c2016-02-26 07:08:526745 int32_t http_status_code,
leon.hanc2228532016-08-16 05:59:186746 const std::vector<SkBitmap>& images,
6747 const std::vector<gfx::Size>& original_image_sizes) {
Avi Drissmana5a52dd2018-03-27 03:39:026748 std::move(callback).Run(id, http_status_code, image_url, images,
6749 original_image_sizes);
pkotwicz75ca8ffd2016-02-16 23:10:196750}
6751
[email protected]6fba26d2014-04-29 09:38:286752void WebContentsImpl::OnDialogClosed(int render_process_id,
6753 int render_frame_id,
Dave Tapuskacdf545cc2020-01-23 18:38:526754 JavaScriptDialogCallback response_callback,
[email protected]87de04b02014-04-08 22:14:496755 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:266756 bool success,
[email protected]fcf75d42013-12-03 20:11:266757 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:286758 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
6759 render_frame_id);
[email protected]87de04b02014-04-08 22:14:496760 last_dialog_suppressed_ = dialog_was_suppressed;
6761
Charlie Reis96077362019-07-04 00:34:046762 javascript_dialog_navigation_deferrer_.reset();
6763
[email protected]beb440c2009-11-06 04:08:546764 if (is_showing_before_unload_dialog_ && !success) {
clamybc6f4152016-04-01 20:14:236765 // It is possible for the current RenderFrameHost to have changed in the
6766 // meantime. Do not reset the navigation state in that case.
6767 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) {
clamy44e84ce2016-02-22 15:38:256768 rfh->frame_tree_node()->BeforeUnloadCanceled();
clamybc6f4152016-04-01 20:14:236769 controller_.DiscardNonCommittedEntries();
6770 }
[email protected]ec8e8b02013-06-19 04:57:106771
Charles Reis15d60b132017-11-03 17:43:476772 // Update the URL display either way, to avoid showing a stale URL.
6773 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
6774
ericwilligersde386342016-10-19 02:35:096775 for (auto& observer : observers_)
6776 observer.BeforeUnloadDialogCancelled();
[email protected]beb440c2009-11-06 04:08:546777 }
[email protected]87de04b02014-04-08 22:14:496778
Dave Tapuskacdf545cc2020-01-23 18:38:526779 std::move(response_callback).Run(success, user_input);
Pavel Feldman3c1842b2017-08-02 05:00:166780
Dave Tapuskacdf545cc2020-01-23 18:38:526781 std::vector<protocol::PageHandler*> page_handlers =
6782 protocol::PageHandler::EnabledForWebContents(this);
6783 for (auto* handler : page_handlers)
6784 handler->DidCloseJavaScriptDialog(success, user_input);
avi1c51fb62017-02-27 20:43:036785
6786 is_showing_javascript_dialog_ = false;
6787 is_showing_before_unload_dialog_ = false;
[email protected]beb440c2009-11-06 04:08:546788}
6789
[email protected]1ac10dca2013-08-20 20:47:046790bool WebContentsImpl::IsHidden() {
Francois Doraye6161152018-03-27 22:05:376791 return !IsBeingCaptured() && visibility_ != Visibility::VISIBLE;
[email protected]1ac10dca2013-08-20 20:47:046792}
6793
rob97250742015-12-10 17:45:156794int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lfg601233692017-03-06 22:45:446795 return node_.outer_contents_frame_tree_node_id();
lazyboy6ec48b2a2015-06-29 15:18:146796}
6797
ekaramadaeb3c5c2016-11-09 03:22:356798RenderWidgetHostImpl* WebContentsImpl::GetFullscreenRenderWidgetHost() const {
6799 return RenderWidgetHostImpl::FromID(fullscreen_widget_process_id_,
6800 fullscreen_widget_routing_id_);
6801}
6802
[email protected]b0936d22013-11-28 06:47:366803RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:216804 return frame_tree_.root()->render_manager();
6805}
6806
[email protected]f8497342013-02-05 22:15:026807BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:396808 return browser_plugin_guest_.get();
6809}
6810
Albert J. Wongc55cc64d2018-10-12 02:50:046811void WebContentsImpl::SetBrowserPluginGuest(
6812 std::unique_ptr<BrowserPluginGuest> guest) {
6813 DCHECK(!browser_plugin_guest_);
6814 DCHECK(guest);
6815 browser_plugin_guest_ = std::move(guest);
[email protected]738f57a2013-06-29 21:06:546816}
6817
Aidan Wolter52bcc12a2018-11-14 03:27:296818base::UnguessableToken WebContentsImpl::GetAudioGroupId() {
Aidan Wolter52bcc12a2018-11-14 03:27:296819 return GetAudioStreamFactory()->group_id();
6820}
6821
Sofiya Semenova5e9d9122019-07-11 02:46:416822ukm::SourceId WebContentsImpl::GetLastCommittedSourceId() {
6823 return last_committed_source_id_;
6824}
6825
Mounir Lamouri7b4a1f232019-12-23 16:32:106826std::vector<FaviconURL> WebContentsImpl::GetFaviconURLs() {
6827 return favicon_urls_;
6828}
6829
[email protected]f8497342013-02-05 22:15:026830BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:396831 return browser_plugin_embedder_.get();
6832}
[email protected]8ff00d72012-10-23 19:12:216833
fsamuel60b42282015-03-10 03:29:146834void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
6835 if (browser_plugin_embedder_)
6836 return;
6837 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
6838}
6839
Jianzhou Fengd8720c72018-01-18 03:06:306840gfx::Size WebContentsImpl::GetSizeForNewRenderView(bool is_main_frame) {
[email protected]dc0fd432013-08-27 15:29:216841 gfx::Size size;
Jianzhou Fengd8720c72018-01-18 03:06:306842 if (is_main_frame)
6843 size = device_emulation_size_;
6844 if (size.IsEmpty() && delegate_)
[email protected]dc0fd432013-08-27 15:29:216845 size = delegate_->GetSizeForNewRenderView(this);
6846 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:456847 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:216848 return size;
6849}
6850
[email protected]ae7eeda2014-07-04 01:53:266851void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
ericwilligersde386342016-10-19 02:35:096852 for (auto& observer : observers_)
6853 observer.FrameDeleted(render_frame_host);
[email protected]9b159a52013-10-03 17:24:556854}
6855
[email protected]222f5822014-02-05 23:40:496856void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
6857 if (!delegate_)
6858 return;
6859 const gfx::Size new_size = GetPreferredSize();
6860 if (new_size != old_size)
6861 delegate_->UpdatePreferredSize(this, new_size);
6862}
6863
Dan Beam055fe8f2017-10-04 23:23:366864std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUI(const GURL& url) {
Jeremy Roman04f27c372017-10-27 15:20:556865 std::unique_ptr<WebUIImpl> web_ui = std::make_unique<WebUIImpl>(this);
Lei Zhangee3b63ad2018-06-06 23:25:316866 std::unique_ptr<WebUIController> controller(
avie865b1d2016-10-24 19:42:596867 WebUIControllerFactoryRegistry::GetInstance()
Lei Zhangee3b63ad2018-06-06 23:25:316868 ->CreateWebUIControllerForURL(web_ui.get(), url));
dbeama1b926a2015-08-31 23:17:516869 if (controller) {
Lei Zhangee3b63ad2018-06-06 23:25:316870 web_ui->SetController(std::move(controller));
dbeama1b926a2015-08-31 23:17:516871 return web_ui;
6872 }
6873
avie865b1d2016-10-24 19:42:596874 return nullptr;
dbeama1b926a2015-08-31 23:17:516875}
6876
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:416877FindRequestManager* WebContentsImpl::GetFindRequestManager() {
6878 for (auto* contents = this; contents;
paulmeyerfeafc2d2017-04-25 21:46:406879 contents = contents->GetOuterWebContents()) {
6880 if (contents->find_request_manager_)
6881 return contents->find_request_manager_.get();
6882 }
6883
6884 return nullptr;
6885}
6886
paulmeyerc0b762b2016-04-13 11:55:176887FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() {
paulmeyerfeafc2d2017-04-25 21:46:406888 if (FindRequestManager* manager = GetFindRequestManager())
6889 return manager;
6890
Ehsan Karamad6beb2ea2018-11-25 18:15:136891 DCHECK(!browser_plugin_guest_ || GetOuterWebContents());
6892
paulmeyerfeafc2d2017-04-25 21:46:406893 // No existing FindRequestManager found, so one must be created.
6894 find_request_manager_.reset(new FindRequestManager(this));
6895
6896 // Concurrent find sessions must not overlap, so destroy any existing
6897 // FindRequestManagers in any inner WebContentses.
Lucas Furukawa Gadani2ec00c82018-12-14 15:53:166898 for (WebContents* contents : GetWebContentsAndAllInner()) {
6899 auto* web_contents_impl = static_cast<WebContentsImpl*>(contents);
6900 if (web_contents_impl == this)
paulmeyerfeafc2d2017-04-25 21:46:406901 continue;
Lucas Furukawa Gadani2ec00c82018-12-14 15:53:166902 if (web_contents_impl->find_request_manager_) {
6903 web_contents_impl->find_request_manager_->StopFinding(
6904 STOP_FIND_ACTION_CLEAR_SELECTION);
6905 web_contents_impl->find_request_manager_.release();
paulmeyerfeafc2d2017-04-25 21:46:406906 }
6907 }
paulmeyerc0b762b2016-04-13 11:55:176908
6909 return find_request_manager_.get();
6910}
6911
6912void WebContentsImpl::NotifyFindReply(int request_id,
6913 int number_of_matches,
6914 const gfx::Rect& selection_rect,
6915 int active_match_ordinal,
6916 bool final_update) {
Sebastien Marchandcf97ed52017-07-24 23:50:346917 if (delegate_ && !is_being_destroyed_ &&
Lukasz Anforowicze9ae3722017-09-29 17:37:386918 !GetMainFrame()->GetProcess()->FastShutdownStarted()) {
paulmeyerc0b762b2016-04-13 11:55:176919 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
6920 active_match_ordinal, final_update);
6921 }
6922}
6923
ortuno467e5792016-06-10 04:32:396924void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() {
6925 // Trying to invalidate the tab state while being destroyed could result in a
6926 // use after free.
6927 if (IsBeingDestroyed()) {
6928 return;
6929 }
6930 // Notify for UI updates if the state changes.
6931 bluetooth_connected_device_count_++;
6932 if (bluetooth_connected_device_count_ == 1) {
Francois Doray66766a572019-12-17 20:56:496933 OnIsConnectedToBluetoothDeviceChanged(true);
ortuno467e5792016-06-10 04:32:396934 }
6935}
6936
6937void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() {
6938 // Trying to invalidate the tab state while being destroyed could result in a
6939 // use after free.
6940 if (IsBeingDestroyed()) {
6941 return;
6942 }
6943 // Notify for UI updates if the state changes.
Lukasz Anforowicze9ae3722017-09-29 17:37:386944 DCHECK_NE(bluetooth_connected_device_count_, 0u);
ortuno467e5792016-06-10 04:32:396945 bluetooth_connected_device_count_--;
6946 if (bluetooth_connected_device_count_ == 0) {
Francois Doray66766a572019-12-17 20:56:496947 OnIsConnectedToBluetoothDeviceChanged(false);
6948 }
6949}
6950
6951void WebContentsImpl::OnIsConnectedToBluetoothDeviceChanged(
6952 bool is_connected_to_bluetooth_device) {
6953 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
6954 for (auto& observer : observers_) {
6955 observer.OnIsConnectedToBluetoothDeviceChanged(
6956 is_connected_to_bluetooth_device);
ortuno467e5792016-06-10 04:32:396957 }
6958}
6959
Reilly Grant5e7c79b22019-04-09 17:26:206960void WebContentsImpl::IncrementSerialActiveFrameCount() {
6961 // Trying to invalidate the tab state while being destroyed could result in a
6962 // use after free.
6963 if (IsBeingDestroyed())
6964 return;
6965
6966 // Notify for UI updates if the state changes.
6967 serial_active_frame_count_++;
6968 if (serial_active_frame_count_ == 1)
6969 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
6970}
6971
6972void WebContentsImpl::DecrementSerialActiveFrameCount() {
6973 // Trying to invalidate the tab state while being destroyed could result in a
6974 // use after free.
6975 if (IsBeingDestroyed())
6976 return;
6977
6978 // Notify for UI updates if the state changes.
6979 DCHECK_NE(0u, serial_active_frame_count_);
6980 serial_active_frame_count_--;
6981 if (serial_active_frame_count_ == 0)
6982 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
6983}
6984
Matt Reynoldse8c6c1f2019-11-02 09:53:536985void WebContentsImpl::IncrementHidActiveFrameCount() {
6986 // Trying to invalidate the tab state while being destroyed could result in a
6987 // use after free.
6988 if (IsBeingDestroyed())
6989 return;
6990
6991 // Notify for UI updates if the active frame count transitions from zero to
6992 // non-zero.
6993 hid_active_frame_count_++;
6994 if (hid_active_frame_count_ == 1)
6995 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
6996}
6997
6998void WebContentsImpl::DecrementHidActiveFrameCount() {
6999 // Trying to invalidate the tab state while being destroyed could result in a
7000 // use after free.
7001 if (IsBeingDestroyed())
7002 return;
7003
7004 // Notify for UI updates if the active frame count transitions from non-zero
7005 // to zero.
7006 DCHECK_NE(0u, hid_active_frame_count_);
7007 hid_active_frame_count_--;
7008 if (hid_active_frame_count_ == 0)
7009 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
7010}
7011
Marijn Kruisselbrink29051042019-08-06 22:56:557012void WebContentsImpl::IncrementNativeFileSystemHandleCount() {
7013 // Trying to invalidate the tab state while being destroyed could result in a
7014 // use after free.
7015 if (IsBeingDestroyed())
7016 return;
7017
7018 // Notify for UI updates if the state changes. Need both TYPE_TAB and TYPE_URL
7019 // to update both the tab-level usage indicator and the usage indicator in the
7020 // omnibox.
7021 native_file_system_handle_count_++;
7022 if (native_file_system_handle_count_ == 1) {
7023 NotifyNavigationStateChanged(static_cast<content::InvalidateTypes>(
7024 INVALIDATE_TYPE_TAB | INVALIDATE_TYPE_URL));
7025 }
7026}
7027
7028void WebContentsImpl::DecrementNativeFileSystemHandleCount() {
7029 // Trying to invalidate the tab state while being destroyed could result in a
7030 // use after free.
7031 if (IsBeingDestroyed())
7032 return;
7033
7034 // Notify for UI updates if the state changes. Need both TYPE_TAB and TYPE_URL
7035 // to update both the tab-level usage indicator and the usage indicator in the
7036 // omnibox.
7037 DCHECK_NE(0u, native_file_system_handle_count_);
7038 native_file_system_handle_count_--;
7039 if (native_file_system_handle_count_ == 0) {
7040 NotifyNavigationStateChanged(static_cast<content::InvalidateTypes>(
7041 INVALIDATE_TYPE_TAB | INVALIDATE_TYPE_URL));
7042 }
7043}
7044
Marijn Kruisselbrink46fa4bd2019-07-11 18:15:477045void WebContentsImpl::AddNativeFileSystemDirectoryHandle(
7046 const base::FilePath& path) {
Marijn Kruisselbrinkf1714aa22019-07-02 03:45:337047 // Trying to invalidate the tab state while being destroyed could result in a
7048 // use after free.
7049 if (IsBeingDestroyed())
7050 return;
7051
7052 // Notify for UI updates if the state changes. Need both TYPE_TAB and TYPE_URL
7053 // to update both the tab-level usage indicator and the usage indicator in the
7054 // omnibox.
Marijn Kruisselbrink46fa4bd2019-07-11 18:15:477055 const bool was_empty = native_file_system_directory_handles_.empty();
7056 native_file_system_directory_handles_[path]++;
7057 if (was_empty) {
Marijn Kruisselbrinkf1714aa22019-07-02 03:45:337058 NotifyNavigationStateChanged(static_cast<content::InvalidateTypes>(
7059 INVALIDATE_TYPE_TAB | INVALIDATE_TYPE_URL));
7060 }
7061}
7062
Marijn Kruisselbrink46fa4bd2019-07-11 18:15:477063void WebContentsImpl::RemoveNativeFileSystemDirectoryHandle(
7064 const base::FilePath& path) {
Marijn Kruisselbrinkf1714aa22019-07-02 03:45:337065 // Trying to invalidate the tab state while being destroyed could result in a
7066 // use after free.
7067 if (IsBeingDestroyed())
7068 return;
7069
7070 // Notify for UI updates if the state changes. Need both TYPE_TAB and TYPE_URL
7071 // to update both the tab-level usage indicator and the usage indicator in the
7072 // omnibox.
Marijn Kruisselbrink46fa4bd2019-07-11 18:15:477073 auto it = native_file_system_directory_handles_.find(path);
7074 DCHECK(it != native_file_system_directory_handles_.end());
7075 DCHECK_NE(0u, it->second);
7076 it->second--;
7077 if (it->second == 0)
7078 native_file_system_directory_handles_.erase(it);
7079 if (native_file_system_directory_handles_.empty()) {
Marijn Kruisselbrinkf1714aa22019-07-02 03:45:337080 NotifyNavigationStateChanged(static_cast<content::InvalidateTypes>(
7081 INVALIDATE_TYPE_TAB | INVALIDATE_TYPE_URL));
7082 }
7083}
7084
7085void WebContentsImpl::IncrementWritableNativeFileSystemHandleCount() {
7086 // Trying to invalidate the tab state while being destroyed could result in a
7087 // use after free.
7088 if (IsBeingDestroyed())
7089 return;
7090
7091 // Notify for UI updates if the state changes. Need both TYPE_TAB and TYPE_URL
7092 // to update both the tab-level usage indicator and the usage indicator in the
7093 // omnibox.
7094 native_file_system_writable_handle_count_++;
7095 if (native_file_system_writable_handle_count_ == 1) {
7096 NotifyNavigationStateChanged(static_cast<content::InvalidateTypes>(
7097 INVALIDATE_TYPE_TAB | INVALIDATE_TYPE_URL));
7098 }
7099}
7100
7101void WebContentsImpl::DecrementWritableNativeFileSystemHandleCount() {
7102 // Trying to invalidate the tab state while being destroyed could result in a
7103 // use after free.
7104 if (IsBeingDestroyed())
7105 return;
7106
7107 // Notify for UI updates if the state changes. Need both TYPE_TAB and TYPE_URL
7108 // to update both the tab-level usage indicator and the usage indicator in the
7109 // omnibox.
7110 DCHECK_NE(0u, native_file_system_writable_handle_count_);
7111 native_file_system_writable_handle_count_--;
7112 if (native_file_system_writable_handle_count_ == 0) {
7113 NotifyNavigationStateChanged(static_cast<content::InvalidateTypes>(
7114 INVALIDATE_TYPE_TAB | INVALIDATE_TYPE_URL));
7115 }
7116}
7117
zqzhang8ac49002017-03-16 21:51:357118void WebContentsImpl::SetHasPersistentVideo(bool has_persistent_video) {
7119 if (has_persistent_video_ == has_persistent_video)
mlamouri5cd9ae82017-02-18 11:05:097120 return;
7121
zqzhang8ac49002017-03-16 21:51:357122 has_persistent_video_ = has_persistent_video;
mlamouri5cd9ae82017-02-18 11:05:097123 NotifyPreferencesChanged();
zqzhang8ac49002017-03-16 21:51:357124 media_web_contents_observer()->RequestPersistentVideo(has_persistent_video);
mlamouri5cd9ae82017-02-18 11:05:097125}
7126
Ian Vollick5d5c37f2019-06-19 22:50:577127void WebContentsImpl::SetSpatialNavigationDisabled(bool disabled) {
7128 if (is_spatial_navigation_disabled_ == disabled)
7129 return;
7130
7131 is_spatial_navigation_disabled_ = disabled;
7132 NotifyPreferencesChanged();
7133}
7134
paulmeyerfeafc2d2017-04-25 21:46:407135void WebContentsImpl::BrowserPluginGuestWillDetach() {
7136 WebContentsImpl* outermost = GetOutermostWebContents();
7137 if (this != outermost && ContainsOrIsFocusedWebContents())
7138 outermost->SetAsFocusedWebContentsIfNecessary();
7139}
7140
Becca Hughes112832e2019-06-11 17:19:027141PictureInPictureResult WebContentsImpl::EnterPictureInPicture(
Mounir Lamouri11e9ef42018-05-22 03:10:167142 const viz::SurfaceId& surface_id,
7143 const gfx::Size& natural_size) {
François Beaufortf09e4462019-01-18 14:34:517144 return delegate_
7145 ? delegate_->EnterPictureInPicture(this, surface_id, natural_size)
Becca Hughes112832e2019-06-11 17:19:027146 : PictureInPictureResult::kNotSupported;
Mounir Lamouri11e9ef42018-05-22 03:10:167147}
7148
Mounir Lamouri6d759e12018-05-16 20:01:307149void WebContentsImpl::ExitPictureInPicture() {
7150 if (delegate_)
7151 delegate_->ExitPictureInPicture();
7152}
7153
paulmeyerc0b762b2016-04-13 11:55:177154#if defined(OS_ANDROID)
7155void WebContentsImpl::NotifyFindMatchRectsReply(
7156 int version,
7157 const std::vector<gfx::RectF>& rects,
7158 const gfx::RectF& active_rect) {
7159 if (delegate_)
7160 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
7161}
7162#endif
7163
[email protected]34ff1cfc2014-08-20 06:16:057164void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
7165 force_disable_overscroll_content_ = force_disable;
7166 if (view_)
7167 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
7168}
7169
Jianzhou Fengd8720c72018-01-18 03:06:307170bool WebContentsImpl::SetDeviceEmulationSize(const gfx::Size& new_size) {
7171 device_emulation_size_ = new_size;
7172 RenderWidgetHostView* rwhv = GetMainFrame()->GetView();
7173
7174 const gfx::Size current_size = rwhv->GetViewBounds().size();
7175 if (view_size_before_emulation_.IsEmpty())
7176 view_size_before_emulation_ = current_size;
7177
7178 if (current_size != new_size)
7179 rwhv->SetSize(new_size);
7180
7181 return current_size != new_size;
7182}
7183
7184void WebContentsImpl::ClearDeviceEmulationSize() {
7185 RenderWidgetHostView* rwhv = GetMainFrame()->GetView();
7186 // WebContentsView could get resized during emulation, which also resizes
7187 // RWHV. If it happens, assume user would like to keep using the size after
7188 // emulation.
7189 // TODO(jzfeng): Prohibit resizing RWHV through any other means (at least when
7190 // WebContentsView size changes).
Dmitry Gozmanc63707182018-03-06 00:09:397191 if (!view_size_before_emulation_.IsEmpty() && rwhv &&
7192 rwhv->GetViewBounds().size() == device_emulation_size_) {
Jianzhou Fengd8720c72018-01-18 03:06:307193 rwhv->SetSize(view_size_before_emulation_);
Dmitry Gozmanc63707182018-03-06 00:09:397194 }
Jianzhou Fengd8720c72018-01-18 03:06:307195 device_emulation_size_ = gfx::Size();
7196 view_size_before_emulation_ = gfx::Size();
7197}
7198
Max Morin5bc74f52018-05-09 07:00:217199ForwardingAudioStreamFactory* WebContentsImpl::GetAudioStreamFactory() {
7200 if (!audio_stream_factory_) {
7201 audio_stream_factory_.emplace(
7202 this,
Max Morinddebb972018-09-20 10:04:147203 // BrowserMainLoop::GetInstance() may be null in unit tests.
7204 BrowserMainLoop::GetInstance()
7205 ? static_cast<media::UserInputMonitorBase*>(
7206 BrowserMainLoop::GetInstance()->user_input_monitor())
7207 : nullptr,
Ken Rockot72964402019-12-06 10:40:517208 AudioStreamBrokerFactory::CreateImpl());
Max Morin5bc74f52018-05-09 07:00:217209 }
7210
7211 return &*audio_stream_factory_;
7212}
7213
dalecurtis88c240072015-12-09 02:11:187214void WebContentsImpl::MediaStartedPlaying(
billorr21c005d2016-11-17 03:57:047215 const WebContentsObserver::MediaPlayerInfo& media_info,
Mounir Lamouri0f5bdf52019-04-04 16:32:357216 const MediaPlayerId& id) {
billorr21c005d2016-11-17 03:57:047217 if (media_info.has_video)
7218 currently_playing_video_count_++;
7219
ericwilligersde386342016-10-19 02:35:097220 for (auto& observer : observers_)
billorr21c005d2016-11-17 03:57:047221 observer.MediaStartedPlaying(media_info, id);
dalecurtis88c240072015-12-09 02:11:187222}
7223
7224void WebContentsImpl::MediaStoppedPlaying(
billorr21c005d2016-11-17 03:57:047225 const WebContentsObserver::MediaPlayerInfo& media_info,
Mounir Lamouri0f5bdf52019-04-04 16:32:357226 const MediaPlayerId& id,
Becca Hughes220bfc102017-11-14 18:24:077227 WebContentsObserver::MediaStoppedReason reason) {
billorr21c005d2016-11-17 03:57:047228 if (media_info.has_video)
7229 currently_playing_video_count_--;
7230
ericwilligersde386342016-10-19 02:35:097231 for (auto& observer : observers_)
Becca Hughes220bfc102017-11-14 18:24:077232 observer.MediaStoppedPlaying(media_info, id, reason);
billorr21c005d2016-11-17 03:57:047233}
7234
Mounir Lamouri0f5bdf52019-04-04 16:32:357235void WebContentsImpl::MediaResized(const gfx::Size& size,
7236 const MediaPlayerId& id) {
peconn257951522017-06-09 18:24:597237 cached_video_sizes_[id] = size;
7238
7239 for (auto& observer : observers_)
7240 observer.MediaResized(size, id);
7241}
7242
Peter E Conneccb34c22017-09-08 09:37:587243void WebContentsImpl::MediaEffectivelyFullscreenChanged(bool is_fullscreen) {
7244 for (auto& observer : observers_)
7245 observer.MediaEffectivelyFullscreenChanged(is_fullscreen);
7246}
7247
Peter Conn31c726a2017-08-17 11:07:347248base::Optional<gfx::Size> WebContentsImpl::GetFullscreenVideoSize() {
Mounir Lamouri0f5bdf52019-04-04 16:32:357249 base::Optional<MediaPlayerId> id =
Peter Conn31c726a2017-08-17 11:07:347250 media_web_contents_observer_->GetFullscreenVideoMediaPlayerId();
Jan Wilken Dörrie531be7ca2019-06-07 10:05:577251 if (id && base::Contains(cached_video_sizes_, id.value()))
Peter Conn31c726a2017-08-17 11:07:347252 return base::Optional<gfx::Size>(cached_video_sizes_[id.value()]);
Lei Zhang6410ec1a2019-01-31 21:38:587253 return base::nullopt;
peconn257951522017-06-09 18:24:597254}
7255
billorr21c005d2016-11-17 03:57:047256int WebContentsImpl::GetCurrentlyPlayingVideoCount() {
7257 return currently_playing_video_count_;
dalecurtis88c240072015-12-09 02:11:187258}
7259
Raymond Toye413650c2018-08-31 00:12:477260void WebContentsImpl::AudioContextPlaybackStarted(RenderFrameHost* host,
7261 int context_id) {
7262 WebContentsObserver::AudioContextId audio_context_id(host, context_id);
7263 for (auto& observer : observers_)
7264 observer.AudioContextPlaybackStarted(audio_context_id);
7265}
7266
7267void WebContentsImpl::AudioContextPlaybackStopped(RenderFrameHost* host,
7268 int context_id) {
7269 WebContentsObserver::AudioContextId audio_context_id(host, context_id);
7270 for (auto& observer : observers_)
7271 observer.AudioContextPlaybackStopped(audio_context_id);
7272}
7273
evliufc233aa2019-10-31 19:53:037274void WebContentsImpl::MediaWatchTimeChanged(
7275 const content::MediaPlayerWatchTime& watch_time) {
7276 for (auto& observer : observers_)
7277 observer.MediaWatchTimeChanged(watch_time);
7278}
7279
evliu7f736f02019-11-07 17:43:507280media::MediaMetricsProvider::RecordAggregateWatchTimeCallback
7281WebContentsImpl::GetRecordAggregateWatchTimeCallback() {
7282 return base::BindRepeating(
7283 [](base::WeakPtr<RenderFrameHostDelegate> delegate,
7284 GURL last_committed_url, base::TimeDelta total_watch_time,
evliua283c9e2019-11-08 22:57:227285 base::TimeDelta time_stamp, bool has_video, bool has_audio) {
7286 content::MediaPlayerWatchTime watch_time(
7287 last_committed_url, last_committed_url.GetOrigin(),
7288 total_watch_time, time_stamp, has_video, has_audio);
evliu7f736f02019-11-07 17:43:507289
7290 // Save the watch time if the delegate is still alive.
7291 if (delegate)
7292 delegate->MediaWatchTimeChanged(watch_time);
7293 },
7294 weak_factory_.GetWeakPtr(), GetMainFrameLastCommittedURL());
7295}
7296
Ehsan Karamad1c631762019-05-13 23:04:017297RenderFrameHostImpl* WebContentsImpl::GetMainFrameForInnerDelegate(
7298 FrameTreeNode* frame_tree_node) {
7299 if (auto* web_contents = node_.GetInnerWebContentsInFrame(frame_tree_node))
7300 return web_contents->GetMainFrame();
7301 return nullptr;
7302}
7303
John Budorickee1c9512019-10-17 15:32:197304bool WebContentsImpl::IsFrameLowPriority(
7305 const RenderFrameHost* render_frame_host) {
7306 if (!delegate_)
7307 return false;
7308 return delegate_->IsFrameLowPriority(this, render_frame_host);
7309}
7310
Roger Tawa03ffdbd2020-01-16 18:12:547311void WebContentsImpl::IsClipboardPasteAllowed(
7312 const GURL& url,
7313 const ui::ClipboardFormatType& data_type,
7314 const std::string& data,
7315 IsClipboardPasteAllowedCallback callback) {
7316 GetContentClient()->browser()->IsClipboardPasteAllowed(
7317 this, url, data_type, data, std::move(callback));
7318}
7319
Lan Weif81c6e7c2020-02-12 16:46:097320bool WebContentsImpl::HasSeenRecentScreenOrientationChange() {
7321 static constexpr base::TimeDelta kMaxInterval =
7322 base::TimeDelta::FromSeconds(1);
7323 base::TimeDelta delta =
7324 ui::EventTimeForNow() - last_screen_orientation_change_time_;
7325 // Return whether there is a screen orientation change happened in the recent
7326 // 1 second.
7327 return delta <= kMaxInterval;
7328}
7329
7330void WebContentsImpl::DidChangeScreenOrientation() {
7331 last_screen_orientation_change_time_ = ui::EventTimeForNow();
7332}
7333
Francois Doraye6161152018-03-27 22:05:377334void WebContentsImpl::UpdateWebContentsVisibility(Visibility visibility) {
Francois Doray3f2afbd2018-04-06 19:18:187335 // Occlusion is disabled when |features::kWebContentsOcclusion| is disabled
7336 // (for power and speed impact assessment) or when
7337 // |switches::kDisableBackgroundingOccludedWindowsForTesting| is specified on
7338 // the command line (to avoid flakiness in browser tests).
7339 const bool occlusion_is_disabled =
7340 !base::FeatureList::IsEnabled(features::kWebContentsOcclusion) ||
Francois Doraye6161152018-03-27 22:05:377341 base::CommandLine::ForCurrentProcess()->HasSwitch(
7342 switches::kDisableBackgroundingOccludedWindowsForTesting);
7343 if (occlusion_is_disabled && visibility == Visibility::OCCLUDED)
7344 visibility = Visibility::VISIBLE;
7345
tapted65ff2ea72016-03-01 23:39:007346 if (!did_first_set_visible_) {
Francois Doraye6161152018-03-27 22:05:377347 if (visibility == Visibility::VISIBLE) {
7348 // A WebContents created with CreateParams::initially_hidden = false
7349 // starts with GetVisibility() == Visibility::VISIBLE even though it is
7350 // not really visible. Call WasShown() when it becomes visible for real as
7351 // the page load mechanism and some WebContentsObserver rely on that.
tapted65ff2ea72016-03-01 23:39:007352 WasShown();
Francois Dorayfe4a1772018-02-17 04:17:097353 did_first_set_visible_ = true;
tapted65ff2ea72016-03-01 23:39:007354 }
Francois Doraye6161152018-03-27 22:05:377355
7356 // Trust the initial visibility of the WebContents and do not switch it to
7357 // HIDDEN or OCCLUDED before it becomes VISIBLE for real. Doing so would
7358 // result in destroying resources that would immediately be recreated (e.g.
7359 // UpdateWebContents(HIDDEN) can be called when a WebContents is added to a
7360 // hidden window that is about to be shown).
7361
tapted65ff2ea72016-03-01 23:39:007362 return;
7363 }
Francois Doraye6161152018-03-27 22:05:377364
7365 if (visibility == visibility_)
tapted65ff2ea72016-03-01 23:39:007366 return;
7367
Collin Baker989e0882019-11-01 01:27:177368 UpdateVisibilityAndNotifyPageAndView(visibility);
tapted65ff2ea72016-03-01 23:39:007369}
7370
aelias5252baa2016-04-10 01:18:027371void WebContentsImpl::UpdateOverridingUserAgent() {
mlamouri5cd9ae82017-02-18 11:05:097372 NotifyPreferencesChanged();
aelias5252baa2016-04-10 01:18:027373}
7374
avid53461d2016-02-25 17:15:047375void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
7376 JavaScriptDialogManager* dialog_manager) {
7377 dialog_manager_ = dialog_manager;
7378}
7379
Julie Jeongeun Kim7d0986172019-12-04 03:17:257380void WebContentsImpl::RemoveReceiverSet(const std::string& interface_name) {
7381 auto it = receiver_sets_.find(interface_name);
7382 if (it != receiver_sets_.end())
7383 receiver_sets_.erase(it);
rockotf62002a2016-09-15 00:08:597384}
7385
nzolghadrd87a308d2016-12-07 15:45:567386bool WebContentsImpl::AddDomainInfoToRapporSample(rappor::Sample* sample) {
nzolghadrbbffc6c2017-05-25 17:56:397387 // Here we associate this metric to the main frame URL regardless of what
7388 // caused it.
nzolghadrd87a308d2016-12-07 15:45:567389 sample->SetStringField("Domain", ::rappor::GetDomainAndRegistrySampleFromGURL(
7390 GetLastCommittedURL()));
nzolghadrd87a308d2016-12-07 15:45:567391 return true;
7392}
7393
falken52a56e32016-12-08 05:02:407394void WebContentsImpl::ShowInsecureLocalhostWarningIfNeeded() {
7395 bool allow_localhost = base::CommandLine::ForCurrentProcess()->HasSwitch(
7396 switches::kAllowInsecureLocalhost);
7397 if (!allow_localhost)
7398 return;
7399
7400 content::NavigationEntry* entry = GetController().GetLastCommittedEntry();
Rob Wuf79b3ba2018-01-14 01:54:317401 if (!entry || !net::IsLocalhost(entry->GetURL()))
falken52a56e32016-12-08 05:02:407402 return;
7403
7404 content::SSLStatus ssl_status = entry->GetSSL();
Matt Mueller936511442019-09-03 18:15:127405 if (!net::IsCertStatusError(ssl_status.cert_status))
falken52a56e32016-12-08 05:02:407406 return;
7407
7408 GetMainFrame()->AddMessageToConsole(
Abhijeet Kandalkara5928a0a2019-03-13 05:04:427409 blink::mojom::ConsoleMessageLevel::kWarning,
falken52a56e32016-12-08 05:02:407410 base::StringPrintf("This site does not have a valid SSL "
7411 "certificate! Without SSL, your site's and "
7412 "visitors' data is vulnerable to theft and "
7413 "tampering. Get a valid SSL certificate before"
7414 " releasing your website to the public."));
7415}
7416
ekaramadf6750aa2017-06-06 18:29:427417bool WebContentsImpl::IsShowingContextMenuOnPage() const {
7418 return showing_context_menu_;
7419}
7420
Min Qina904f3302018-02-13 23:33:347421download::DownloadUrlParameters::RequestHeadersType
7422WebContentsImpl::ParseDownloadHeaders(const std::string& headers) {
7423 download::DownloadUrlParameters::RequestHeadersType request_headers;
Megan Jablonski2f6a4c52017-07-10 23:01:257424 for (const base::StringPiece& key_value : base::SplitStringPiece(
7425 headers, "\r\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
7426 std::vector<std::string> pair = base::SplitString(
7427 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
7428 if (2ul == pair.size())
7429 request_headers.push_back(make_pair(pair[0], pair[1]));
7430 }
7431 return request_headers;
7432}
7433
lukasza6f8ac622017-06-06 03:10:207434void WebContentsImpl::SetOpenerForNewContents(FrameTreeNode* opener,
7435 bool opener_suppressed) {
7436 if (opener) {
7437 FrameTreeNode* new_root = GetFrameTree()->root();
7438
7439 // For the "original opener", track the opener's main frame instead, because
7440 // if the opener is a subframe, the opener tracking could be easily bypassed
7441 // by spawning from a subframe and deleting the subframe.
7442 // https://crbug.com/705316
7443 new_root->SetOriginalOpener(opener->frame_tree()->root());
7444
7445 if (!opener_suppressed) {
7446 new_root->SetOpener(opener);
7447 created_with_opener_ = true;
7448 }
7449 }
7450}
7451
Mounir Lamouri0f5bdf52019-04-04 16:32:357452void WebContentsImpl::MediaMutedStatusChanged(const MediaPlayerId& id,
7453 bool muted) {
Becca Hughes9f6fd4b82017-06-15 10:01:407454 for (auto& observer : observers_)
7455 observer.MediaMutedStatusChanged(id, muted);
7456}
7457
EhsanK2075c7e2017-08-21 02:42:397458void WebContentsImpl::SetVisibilityForChildViews(bool visible) {
7459 GetMainFrame()->SetVisibilityForChildViews(visible);
7460}
7461
Dave Tapuskae782bea2019-07-09 16:21:517462mojom::FrameInputHandler* WebContentsImpl::GetFocusedFrameInputHandler() {
7463 auto* focused_frame = GetFocusedFrame();
7464 if (!focused_frame)
7465 return nullptr;
7466 return focused_frame->GetFrameInputHandler();
7467}
7468
[email protected]8ff00d72012-10-23 19:12:217469} // namespace content