[email protected] | 91854cd | 2012-01-10 19:43:57 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 93ddb3c | 2012-04-11 21:44:29 | [diff] [blame] | 5 | #include "content/browser/web_contents/web_contents_impl.h" |
[email protected] | 3952656 | 2011-02-05 03:41:51 | [diff] [blame] | 6 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 9 | #include <algorithm> |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 10 | #include <cmath> |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 11 | #include <memory> |
[email protected] | 2bb17188 | 2012-03-07 02:09:46 | [diff] [blame] | 12 | #include <utility> |
rkaplow | e56a5203 | 2017-02-07 00:14:54 | [diff] [blame] | 13 | #include <vector> |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 14 | |
Sebastien Marchand | f8cbfab | 2019-01-25 16:02:30 | [diff] [blame] | 15 | #include "base/bind.h" |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 16 | #include "base/command_line.h" |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 17 | #include "base/containers/flat_set.h" |
creis | fafed88 | 2016-07-29 00:03:09 | [diff] [blame] | 18 | #include "base/debug/dump_without_crashing.h" |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 19 | #include "base/feature_list.h" |
Marijn Kruisselbrink | 46fa4bd | 2019-07-11 18:15:47 | [diff] [blame] | 20 | #include "base/files/file_path.h" |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 21 | #include "base/lazy_instance.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 22 | #include "base/location.h" |
[email protected] | 6d636e6 | 2013-07-31 03:15:56 | [diff] [blame] | 23 | #include "base/logging.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 24 | #include "base/macros.h" |
fdoray | ba12142 | 2016-12-23 19:51:48 | [diff] [blame] | 25 | #include "base/memory/ptr_util.h" |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 26 | #include "base/memory/ref_counted.h" |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 27 | #include "base/metrics/field_trial.h" |
asvitkine | 8d51e9d | 2016-09-02 23:55:43 | [diff] [blame] | 28 | #include "base/metrics/histogram_macros.h" |
bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 29 | #include "base/metrics/user_metrics.h" |
Avi Drissman | 4891b85 | 2018-09-25 18:12:58 | [diff] [blame] | 30 | #include "base/no_destructor.h" |
Carlos Caballero | 1215f88 | 2019-10-29 15:58:43 | [diff] [blame] | 31 | #include "base/optional.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 32 | #include "base/process/process.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 33 | #include "base/single_thread_task_runner.h" |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 34 | #include "base/stl_util.h" |
[email protected] | 348fbaac | 2013-06-11 06:31:51 | [diff] [blame] | 35 | #include "base/strings/string16.h" |
| 36 | #include "base/strings/string_number_conversions.h" |
Avi Drissman | 4891b85 | 2018-09-25 18:12:58 | [diff] [blame] | 37 | #include "base/strings/string_split.h" |
[email protected] | 348fbaac | 2013-06-11 06:31:51 | [diff] [blame] | 38 | #include "base/strings/string_util.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 39 | #include "base/strings/utf_string_conversions.h" |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 40 | #include "base/system/sys_info.h" |
gab | 30f26df | 2016-05-11 19:37:55 | [diff] [blame] | 41 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | a43858f | 2013-06-28 15:18:37 | [diff] [blame] | 42 | #include "base/time/time.h" |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 43 | #include "base/trace_event/optional_trace_event.h" |
| 44 | #include "base/trace_event/trace_conversion_helper.h" |
ssid | 3e76561 | 2015-01-28 04:03:42 | [diff] [blame] | 45 | #include "base/trace_event/trace_event.h" |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 46 | #include "base/trace_event/traced_value.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 47 | #include "build/build_config.h" |
Hidehiko Abe | 7c68f58 | 2020-09-03 15:47:25 | [diff] [blame] | 48 | #include "build/chromeos_buildflags.h" |
Min Qin | da0ed206 | 2018-02-23 22:00:53 | [diff] [blame] | 49 | #include "components/download/public/common/download_stats.h" |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 50 | #include "components/rappor/public/rappor_utils.h" |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 51 | #include "components/url_formatter/url_formatter.h" |
Abigail Klein | aa89874 | 2019-11-01 02:31:25 | [diff] [blame] | 52 | #include "content/browser/accessibility/accessibility_event_recorder.h" |
James Wallace-Lee | eafc94cb9 | 2018-07-23 21:35:09 | [diff] [blame] | 53 | #include "content/browser/accessibility/accessibility_tree_formatter_blink.h" |
jamescook | da250581 | 2015-03-20 18:01:18 | [diff] [blame] | 54 | #include "content/browser/bad_message.h" |
Max Morin | ddebb97 | 2018-09-20 10:04:14 | [diff] [blame] | 55 | #include "content/browser/browser_main_loop.h" |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 56 | #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 57 | #include "content/browser/browser_plugin/browser_plugin_guest.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 58 | #include "content/browser/child_process_security_policy_impl.h" |
John Delaney | 732721e9 | 2020-02-07 23:11:27 | [diff] [blame] | 59 | #include "content/browser/conversions/conversion_host.h" |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 60 | #include "content/browser/devtools/protocol/page_handler.h" |
dgozman | f00c4f7 | 2016-10-19 17:45:15 | [diff] [blame] | 61 | #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
Becca Hughes | 3b5a4348 | 2018-07-17 22:31:55 | [diff] [blame] | 62 | #include "content/browser/display_cutout/display_cutout_host_impl.h" |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 63 | #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
[email protected] | 1ea3c79 | 2012-04-17 01:25:04 | [diff] [blame] | 64 | #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
[email protected] | aa4f397 | 2012-03-01 18:12:12 | [diff] [blame] | 65 | #include "content/browser/download/mhtml_generation_manager.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 66 | #include "content/browser/download/save_package.h" |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 67 | #include "content/browser/find_request_manager.h" |
Kenneth Russell | 954ed9ce | 2018-04-12 23:07:01 | [diff] [blame] | 68 | #include "content/browser/gpu/gpu_data_manager_impl.h" |
mlamouri | efdca9d | 2014-09-16 16:55:40 | [diff] [blame] | 69 | #include "content/browser/manifest/manifest_manager_host.h" |
Max Morin | 5bc74f5 | 2018-05-09 07:00:21 | [diff] [blame] | 70 | #include "content/browser/media/audio_stream_broker.h" |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 71 | #include "content/browser/media/audio_stream_monitor.h" |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 72 | #include "content/browser/media/capture/web_contents_audio_muter.h" |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 73 | #include "content/browser/media/media_web_contents_observer.h" |
zqzhang | 1adf3cb | 2016-11-01 11:26:45 | [diff] [blame] | 74 | #include "content/browser/media/session/media_session_impl.h" |
Mike Wasserman | dabad61 | 2020-08-13 04:26:27 | [diff] [blame] | 75 | #include "content/browser/permissions/permission_controller_impl.h" |
Yuzu Saijo | a11069a | 2020-04-22 10:56:55 | [diff] [blame] | 76 | #include "content/browser/plugin_content_origin_allowlist.h" |
Kevin McNee | 94ea52f5 | 2020-06-23 17:42:06 | [diff] [blame] | 77 | #include "content/browser/portal/portal.h" |
Tal Pressman | 5dcd238 | 2020-08-26 07:13:05 | [diff] [blame] | 78 | #include "content/browser/renderer_host/agent_scheduling_group_host.h" |
danakj | e34636e | 2020-09-15 22:15:00 | [diff] [blame] | 79 | #include "content/browser/renderer_host/cross_process_frame_connector.h" |
David Black | 9cca359 | 2019-11-06 23:02:22 | [diff] [blame] | 80 | #include "content/browser/renderer_host/frame_token_message_queue.h" |
danakj | e34636e | 2020-09-15 22:15:00 | [diff] [blame] | 81 | #include "content/browser/renderer_host/frame_tree_node.h" |
| 82 | #include "content/browser/renderer_host/navigation_entry_impl.h" |
| 83 | #include "content/browser/renderer_host/navigation_request.h" |
| 84 | #include "content/browser/renderer_host/navigator.h" |
| 85 | #include "content/browser/renderer_host/render_frame_host_impl.h" |
| 86 | #include "content/browser/renderer_host/render_frame_proxy_host.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 87 | #include "content/browser/renderer_host/render_process_host_impl.h" |
[email protected] | 2116103 | 2014-05-05 16:56:50 | [diff] [blame] | 88 | #include "content/browser/renderer_host/render_view_host_delegate_view.h" |
[email protected] | b3c41c0b | 2012-03-06 15:48:32 | [diff] [blame] | 89 | #include "content/browser/renderer_host/render_view_host_impl.h" |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 90 | #include "content/browser/renderer_host/render_widget_host_impl.h" |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 91 | #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 92 | #include "content/browser/renderer_host/render_widget_host_view_base.h" |
Ken Buchanan | daef006b | 2017-08-17 18:32:15 | [diff] [blame] | 93 | #include "content/browser/renderer_host/render_widget_host_view_child_frame.h" |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 94 | #include "content/browser/renderer_host/text_input_manager.h" |
Mike Wasserman | b213b935 | 2020-04-16 00:32:34 | [diff] [blame] | 95 | #include "content/browser/screen_enumeration/screen_change_monitor.h" |
leon.han | 552e9de | 2017-02-09 14:37:30 | [diff] [blame] | 96 | #include "content/browser/screen_orientation/screen_orientation_provider.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 97 | #include "content/browser/site_instance_impl.h" |
Charlie Reis | 9607736 | 2019-07-04 00:34:04 | [diff] [blame] | 98 | #include "content/browser/web_contents/javascript_dialog_navigation_deferrer.h" |
lfg | c740d4b2 | 2016-04-15 16:45:33 | [diff] [blame] | 99 | #include "content/browser/web_contents/web_contents_view_child_frame.h" |
Tsuyoshi Horo | b0d8d90 | 2020-03-12 00:09:39 | [diff] [blame] | 100 | #include "content/browser/web_package/save_as_web_bundle_job.h" |
[email protected] | 86a0a6e | 2013-01-28 06:33:03 | [diff] [blame] | 101 | #include "content/browser/webui/web_ui_controller_factory_registry.h" |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 102 | #include "content/browser/webui/web_ui_impl.h" |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 103 | #include "content/common/content_switches_internal.h" |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 104 | #include "content/common/drag_messages.h" |
[email protected] | f114fa4 | 2013-12-06 17:06:44 | [diff] [blame] | 105 | #include "content/common/frame_messages.h" |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 106 | #include "content/common/input_messages.h" |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 107 | #include "content/common/page_messages.h" |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 108 | #include "content/common/render_message_filter.mojom.h" |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 109 | #include "content/common/view_messages.h" |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 110 | #include "content/common/widget_messages.h" |
Abigail Klein | abb42833 | 2019-09-13 18:26:21 | [diff] [blame] | 111 | #include "content/public/browser/accessibility_tree_formatter.h" |
[email protected] | 31a71eaf | 2014-03-13 01:47:36 | [diff] [blame] | 112 | #include "content/public/browser/ax_event_notification_details.h" |
[email protected] | ccb79730 | 2011-12-15 16:55:11 | [diff] [blame] | 113 | #include "content/public/browser/browser_context.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 114 | #include "content/public/browser/browser_task_traits.h" |
Gabriel Charette | 790754c | 2018-03-16 21:32:59 | [diff] [blame] | 115 | #include "content/public/browser/browser_thread.h" |
[email protected] | 87f3c08 | 2011-10-19 18:07:44 | [diff] [blame] | 116 | #include "content/public/browser/content_browser_client.h" |
Lukasz Anforowicz | 8c4446dc | 2020-03-11 22:16:42 | [diff] [blame] | 117 | #include "content/public/browser/context_menu_params.h" |
Ken Rockot | ce010f0 | 2019-12-12 23:32:32 | [diff] [blame] | 118 | #include "content/public/browser/device_service.h" |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 119 | #include "content/public/browser/download_manager.h" |
Kent Tamura | 512a27e | 2018-10-04 00:49:32 | [diff] [blame] | 120 | #include "content/public/browser/file_select_listener.h" |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 121 | #include "content/public/browser/focused_node_details.h" |
Danyao Wang | a78f3dd2 | 2020-03-05 05:31:27 | [diff] [blame] | 122 | #include "content/public/browser/global_routing_id.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 123 | #include "content/public/browser/invalidate_type.h" |
[email protected] | 71a88bb | 2013-02-01 22:05:15 | [diff] [blame] | 124 | #include "content/public/browser/javascript_dialog_manager.h" |
sky | f65d9bb | 2017-03-24 02:26:39 | [diff] [blame] | 125 | #include "content/public/browser/keyboard_event_processing_result.h" |
[email protected] | 09d31d5 | 2012-03-11 22:30:27 | [diff] [blame] | 126 | #include "content/public/browser/load_notification_details.h" |
[email protected] | 5b96836f | 2011-12-22 07:39:00 | [diff] [blame] | 127 | #include "content/public/browser/navigation_details.h" |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 128 | #include "content/public/browser/notification_details.h" |
[email protected] | be2510c0 | 2012-05-28 14:52:14 | [diff] [blame] | 129 | #include "content/public/browser/notification_service.h" |
scottmg | 011d96e3 | 2016-06-29 19:15:08 | [diff] [blame] | 130 | #include "content/public/browser/notification_types.h" |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 131 | #include "content/public/browser/render_widget_host_iterator.h" |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 132 | #include "content/public/browser/restore_type.h" |
estark | 5ea80e5 | 2015-06-19 18:43:12 | [diff] [blame] | 133 | #include "content/public/browser/security_style_explanations.h" |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 134 | #include "content/public/browser/ssl_status.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 135 | #include "content/public/browser/storage_partition.h" |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 136 | #include "content/public/browser/web_contents_delegate.h" |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 137 | #include "content/public/browser/web_contents_receiver_set.h" |
Lei Zhang | ee3b63ad | 2018-06-06 23:25:31 | [diff] [blame] | 138 | #include "content/public/browser/web_ui_controller.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 139 | #include "content/public/common/bindings_policy.h" |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 140 | #include "content/public/common/child_process_host.h" |
Hans Wennborg | 5ffd139 | 2019-10-16 11:00:02 | [diff] [blame] | 141 | #include "content/public/common/content_client.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 142 | #include "content/public/common/content_constants.h" |
Francois Doray | 3f2afbd | 2018-04-06 19:18:18 | [diff] [blame] | 143 | #include "content/public/common/content_features.h" |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 144 | #include "content/public/common/content_switches.h" |
Leon Han | 963dc18 | 2018-11-06 05:41:48 | [diff] [blame] | 145 | #include "content/public/common/referrer_type_converters.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 146 | #include "content/public/common/result_codes.h" |
[email protected] | f16cc678 | 2013-12-16 23:42:57 | [diff] [blame] | 147 | #include "content/public/common/url_utils.h" |
danakj | ffc8baf | 2019-10-10 23:49:42 | [diff] [blame] | 148 | #include "content/public/common/use_zoom_for_dsf_policy.h" |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 149 | #include "media/base/media_switches.h" |
Max Morin | ddebb97 | 2018-09-20 10:04:14 | [diff] [blame] | 150 | #include "media/base/user_input_monitor.h" |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 151 | #include "net/base/url_util.h" |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 152 | #include "net/http/http_cache.h" |
| 153 | #include "net/http/http_transaction_factory.h" |
David Van Cleve | f9988163 | 2020-07-16 19:41:13 | [diff] [blame] | 154 | #include "net/http/http_util.h" |
rhalavati | 0fbaeef3 | 2017-06-01 15:56:30 | [diff] [blame] | 155 | #include "net/traffic_annotation/network_traffic_annotation.h" |
Scott Violet | 02e38b9 | 2018-03-27 23:42:14 | [diff] [blame] | 156 | #include "ppapi/buildflags/buildflags.h" |
Mounir Lamouri | fd9dcefa | 2017-07-06 10:26:55 | [diff] [blame] | 157 | #include "services/metrics/public/cpp/ukm_recorder.h" |
John Abd-El-Malek | b175a61 | 2018-12-03 20:11:58 | [diff] [blame] | 158 | #include "services/network/public/cpp/features.h" |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 159 | #include "services/network/public/cpp/web_sandbox_flags.h" |
| 160 | #include "services/network/public/mojom/web_sandbox_flags.mojom.h" |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 161 | #include "services/service_manager/public/cpp/interface_provider.h" |
Becca Hughes | 6daf566 | 2018-06-27 16:50:54 | [diff] [blame] | 162 | #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 163 | #include "third_party/blink/public/common/mime_util/mime_util.h" |
danakj | 938b37a6 | 2019-09-24 18:35:54 | [diff] [blame] | 164 | #include "third_party/blink/public/common/page/page_zoom.h" |
Miyoung Shin | 5d77f7207 | 2020-10-09 15:14:20 | [diff] [blame] | 165 | #include "third_party/blink/public/common/page_state/page_state.h" |
| 166 | #include "third_party/blink/public/common/page_state/page_state_serialization.h" |
Sergio Villar Senin | 9d9d4f5 | 2019-10-15 10:57:57 | [diff] [blame] | 167 | #include "third_party/blink/public/common/security/security_style.h" |
Gyuyoung Kim | 1ac4ca78 | 2020-09-11 03:32:51 | [diff] [blame] | 168 | #include "third_party/blink/public/common/web_preferences/web_preferences.h" |
Abhijeet Kandalkar | de7348e | 2020-01-13 06:06:54 | [diff] [blame] | 169 | #include "third_party/blink/public/mojom/frame/frame.mojom.h" |
Dave Tapuska | a418951 | 2019-10-15 20:27:34 | [diff] [blame] | 170 | #include "third_party/blink/public/mojom/frame/fullscreen.mojom.h" |
Takuto Ikuta | aa3b796c | 2019-02-06 02:54:56 | [diff] [blame] | 171 | #include "third_party/blink/public/mojom/loader/pause_subresource_loading_handle.mojom.h" |
Antonio Gomes | 0d42960a | 2019-06-05 12:35:51 | [diff] [blame] | 172 | #include "third_party/blink/public/mojom/mediastream/media_stream.mojom-shared.h" |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 173 | #include "third_party/skia/include/core/SkBitmap.h" |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 174 | #include "ui/accessibility/ax_tree_combiner.h" |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 175 | #include "ui/base/device_form_factor.h" |
Mugdha Lakhani | 0a0d786 | 2020-07-29 09:58:45 | [diff] [blame] | 176 | #if defined(USE_AURA) |
| 177 | #include "ui/aura/window.h" |
| 178 | #endif |
[email protected] | a08412b6 | 2012-05-29 21:28:56 | [diff] [blame] | 179 | #include "ui/base/layout.h" |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 180 | #include "ui/base/ui_base_features.h" |
| 181 | #include "ui/base/ui_base_switches.h" |
| 182 | #include "ui/display/screen.h" |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 183 | #include "ui/events/base_event_utils.h" |
chongz | 4a975194 | 2016-08-17 17:49:39 | [diff] [blame] | 184 | #include "ui/events/blink/web_input_event_traits.h" |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 185 | #include "ui/gfx/animation/animation.h" |
[email protected] | 66bd551 | 2012-08-01 02:02:52 | [diff] [blame] | 186 | #include "ui/gl/gl_switches.h" |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 187 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 188 | #if defined(OS_WIN) |
| 189 | #include "content/browser/renderer_host/dip_util.h" |
| 190 | #include "ui/gfx/geometry/dip_util.h" |
| 191 | #endif |
| 192 | |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 193 | #if defined(OS_ANDROID) |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 194 | #include "content/browser/android/date_time_chooser_android.h" |
sammc | f5f1b0f | 2016-09-20 23:05:11 | [diff] [blame] | 195 | #include "content/browser/android/java_interfaces_impl.h" |
Leon Han | ccb985f | 2019-08-26 02:43:24 | [diff] [blame] | 196 | #include "content/browser/android/nfc_host.h" |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 197 | #include "content/browser/web_contents/web_contents_android.h" |
Ke He | 31d0bb0 | 2018-02-24 07:16:24 | [diff] [blame] | 198 | #include "services/device/public/mojom/nfc.mojom.h" |
Mugdha Lakhani | 0a0d786 | 2020-07-29 09:58:45 | [diff] [blame] | 199 | #include "ui/android/view_android.h" |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 200 | #else // !OS_ANDROID |
| 201 | #include "content/browser/host_zoom_map_impl.h" |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 202 | #endif // OS_ANDROID |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 203 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 204 | #if BUILDFLAG(ENABLE_PLUGINS) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 205 | #include "content/browser/media/session/pepper_playback_observer.h" |
Lei Zhang | ebcc630 | 2018-01-12 19:46:45 | [diff] [blame] | 206 | #endif |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 207 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 208 | namespace content { |
Abigail Klein | aa89874 | 2019-11-01 02:31:25 | [diff] [blame] | 209 | |
| 210 | using AccessibilityEventCallback = |
| 211 | base::RepeatingCallback<void(const std::string&)>; |
| 212 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 213 | namespace { |
| 214 | |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 215 | const int kMinimumDelayBetweenLoadingUpdatesMS = 100; |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 216 | const char kDotGoogleDotCom[] = ".google.com"; |
[email protected] | ca40603 | 2011-07-19 21:53:05 | [diff] [blame] | 217 | |
Sreeja Kamishetty | be0ccd6b | 2020-06-09 11:52:50 | [diff] [blame] | 218 | using LifecycleState = RenderFrameHostImpl::LifecycleState; |
| 219 | |
Alexander Timin | 33bd754c0 | 2020-03-10 22:50:18 | [diff] [blame] | 220 | // TODO(crbug.com/1059903): Clean up after the initial investigation. |
| 221 | constexpr base::Feature kCheckWebContentsAccessFromNonCurrentFrame{ |
| 222 | "CheckWebContentsAccessFromNonCurrentFrame", |
| 223 | base::FEATURE_DISABLED_BY_DEFAULT}; |
| 224 | |
Avi Drissman | a911482 | 2018-03-23 18:25:55 | [diff] [blame] | 225 | base::LazyInstance<std::vector< |
| 226 | WebContentsImpl::FriendWrapper::CreatedCallback>>::DestructorAtExit |
| 227 | g_created_callbacks = LAZY_INSTANCE_INITIALIZER; |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 228 | |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 229 | bool HasMatchingProcess(FrameTree* tree, int render_process_id) { |
| 230 | for (FrameTreeNode* node : tree->Nodes()) { |
| 231 | if (node->current_frame_host()->GetProcess()->GetID() == render_process_id) |
| 232 | return true; |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 233 | } |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 234 | return false; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 235 | } |
| 236 | |
kenrb | 1922185 | 2016-04-29 17:21:40 | [diff] [blame] | 237 | bool HasMatchingWidgetHost(FrameTree* tree, RenderWidgetHost* host) { |
| 238 | // This method scans the frame tree rather than checking whether |
| 239 | // host->delegate() == this, which allows it to return false when the host |
| 240 | // for a frame that is pending or pending deletion. |
| 241 | if (!host) |
| 242 | return false; |
| 243 | |
| 244 | for (FrameTreeNode* node : tree->Nodes()) { |
| 245 | if (node->current_frame_host()->GetRenderWidgetHost() == host) |
| 246 | return true; |
| 247 | } |
| 248 | return false; |
| 249 | } |
| 250 | |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 251 | void UpdateAccessibilityModeOnFrame(RenderFrameHost* frame_host) { |
| 252 | static_cast<RenderFrameHostImpl*>(frame_host)->UpdateAccessibilityMode(); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 253 | } |
| 254 | |
dtseng | 0dd3fa1 | 2015-07-22 19:00:52 | [diff] [blame] | 255 | void ResetAccessibility(RenderFrameHost* rfh) { |
| 256 | static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset(); |
| 257 | } |
| 258 | |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 259 | RenderFrameHostImpl* FindOpenerRFH(const WebContents::CreateParams& params) { |
| 260 | RenderFrameHostImpl* opener_rfh = nullptr; |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 261 | if (params.opener_render_frame_id != MSG_ROUTING_NONE) { |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 262 | opener_rfh = RenderFrameHostImpl::FromID(params.opener_render_process_id, |
| 263 | params.opener_render_frame_id); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 264 | } |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 265 | return opener_rfh; |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 266 | } |
| 267 | |
Dominick Ng | 37a1505 | 2018-07-17 23:56:35 | [diff] [blame] | 268 | // Returns |true| if |type| is the kind of user input that should trigger the |
| 269 | // user interaction observers. |
| 270 | bool IsUserInteractionInputType(blink::WebInputEvent::Type type) { |
| 271 | // Ideally, this list would be based more off of |
| 272 | // https://whatwg.org/C/interaction.html#triggered-by-user-activation. |
Dave Tapuska | 347d60a | 2020-04-21 23:55:47 | [diff] [blame] | 273 | return type == blink::WebInputEvent::Type::kMouseDown || |
| 274 | type == blink::WebInputEvent::Type::kGestureScrollBegin || |
| 275 | type == blink::WebInputEvent::Type::kTouchStart || |
| 276 | type == blink::WebInputEvent::Type::kRawKeyDown; |
Dominick Ng | 37a1505 | 2018-07-17 23:56:35 | [diff] [blame] | 277 | } |
| 278 | |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 279 | // Ensures that OnDialogClosed is only called once. |
| 280 | class CloseDialogCallbackWrapper |
| 281 | : public base::RefCountedThreadSafe<CloseDialogCallbackWrapper> { |
| 282 | public: |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 283 | using CloseCallback = |
| 284 | base::OnceCallback<void(bool, bool, const base::string16&)>; |
| 285 | |
| 286 | explicit CloseDialogCallbackWrapper(CloseCallback callback) |
| 287 | : callback_(std::move(callback)) {} |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 288 | |
| 289 | void Run(bool dialog_was_suppressed, |
| 290 | bool success, |
| 291 | const base::string16& user_input) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 292 | if (callback_.is_null()) |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 293 | return; |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 294 | std::move(callback_).Run(dialog_was_suppressed, success, user_input); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | private: |
| 298 | friend class base::RefCountedThreadSafe<CloseDialogCallbackWrapper>; |
Fergal Daly | 55b6d72 | 2020-09-11 07:56:33 | [diff] [blame] | 299 | ~CloseDialogCallbackWrapper() = default; |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 300 | |
| 301 | CloseCallback callback_; |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 302 | }; |
| 303 | |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 304 | bool FrameCompareDepth(RenderFrameHostImpl* a, RenderFrameHostImpl* b) { |
| 305 | return a->frame_tree_node()->depth() < b->frame_tree_node()->depth(); |
| 306 | } |
| 307 | |
Raymes Khoury | 58373df | 2019-08-06 06:29:20 | [diff] [blame] | 308 | bool AreValidRegisterProtocolHandlerArguments(const std::string& protocol, |
| 309 | const GURL& url, |
| 310 | const url::Origin& origin) { |
| 311 | ChildProcessSecurityPolicyImpl* policy = |
| 312 | ChildProcessSecurityPolicyImpl::GetInstance(); |
| 313 | if (policy->IsPseudoScheme(protocol)) |
| 314 | return false; |
| 315 | |
| 316 | url::Origin url_origin = url::Origin::Create(url); |
| 317 | if (url_origin.opaque()) |
| 318 | return false; |
| 319 | |
| 320 | if (!url_origin.IsSameOriginWith(origin)) |
| 321 | return false; |
| 322 | |
| 323 | return true; |
| 324 | } |
| 325 | |
yilkal | 796e89e | 2019-10-02 23:58:28 | [diff] [blame] | 326 | void RecordMaxFrameCountUMA(size_t max_frame_count) { |
| 327 | UMA_HISTOGRAM_COUNTS_10000("Navigation.MainFrame.MaxFrameCount", |
| 328 | max_frame_count); |
| 329 | } |
| 330 | |
Jeremy Roman | 03ce13ce | 2020-05-29 22:16:57 | [diff] [blame] | 331 | // Returns whether the condition provided applies to any inner contents. |
| 332 | // This check is not recursive (however, the predicate provided may itself |
| 333 | // recurse each contents' own inner contents). |
| 334 | // |
| 335 | // For example, if this is used to aggregate state from inner contents to outer |
| 336 | // contents, then that propagation will gather transitive descendants without |
| 337 | // need for this helper to do so. In fact, in such cases recursing on inner |
| 338 | // contents here would make that operation quadratic rather than linear. |
| 339 | template <typename Functor> |
| 340 | bool AnyInnerWebContents(WebContents* web_contents, const Functor& f) { |
| 341 | const auto& inner_contents = web_contents->GetInnerWebContents(); |
| 342 | return std::any_of(inner_contents.begin(), inner_contents.end(), f); |
| 343 | } |
| 344 | |
Xuehui Xie | b2300ae4 | 2020-06-09 20:25:05 | [diff] [blame] | 345 | std::vector<RenderFrameHost*> GetAllFramesImpl(FrameTree& frame_tree, |
| 346 | bool include_pending) { |
| 347 | std::vector<RenderFrameHost*> frame_hosts; |
| 348 | for (FrameTreeNode* node : frame_tree.Nodes()) { |
| 349 | frame_hosts.push_back(node->current_frame_host()); |
| 350 | if (include_pending) { |
| 351 | RenderFrameHostImpl* pending_frame_host = |
| 352 | node->render_manager()->speculative_frame_host(); |
| 353 | if (pending_frame_host) |
| 354 | frame_hosts.push_back(pending_frame_host); |
| 355 | } |
| 356 | } |
| 357 | return frame_hosts; |
| 358 | } |
| 359 | |
| 360 | int SendToAllFramesImpl(FrameTree& frame_tree, |
| 361 | bool include_pending, |
| 362 | IPC::Message* message) { |
| 363 | int number_of_messages = 0; |
| 364 | std::vector<RenderFrameHost*> frame_hosts = |
| 365 | GetAllFramesImpl(frame_tree, include_pending); |
| 366 | for (RenderFrameHost* rfh : frame_hosts) { |
| 367 | if (!rfh->IsRenderFrameLive()) |
| 368 | continue; |
| 369 | |
| 370 | ++number_of_messages; |
| 371 | IPC::Message* message_copy = new IPC::Message(*message); |
| 372 | message_copy->set_routing_id(rfh->GetRoutingID()); |
| 373 | rfh->Send(message_copy); |
| 374 | } |
| 375 | delete message; |
| 376 | return number_of_messages; |
| 377 | } |
| 378 | |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 379 | // Returns the set of all WebContentses that are reachable from |web_contents| |
| 380 | // by applying some combination of WebContents::GetOriginalOpener() and |
| 381 | // WebContents::GetOuterWebContents(). The |web_contents| parameter will be |
| 382 | // included in the returned set. |
| 383 | base::flat_set<WebContentsImpl*> GetAllOpeningWebContents( |
| 384 | WebContentsImpl* web_contents) { |
| 385 | base::flat_set<WebContentsImpl*> result; |
| 386 | base::flat_set<WebContentsImpl*> current; |
| 387 | |
| 388 | current.insert(web_contents); |
| 389 | |
| 390 | while (!current.empty()) { |
| 391 | WebContentsImpl* current_contents = *current.begin(); |
| 392 | current.erase(current.begin()); |
| 393 | auto insert_result = result.insert(current_contents); |
| 394 | |
| 395 | if (insert_result.second) { |
| 396 | RenderFrameHostImpl* opener_rfh = current_contents->GetOriginalOpener(); |
| 397 | if (opener_rfh) { |
| 398 | current.insert(static_cast<WebContentsImpl*>( |
| 399 | WebContents::FromRenderFrameHost(opener_rfh))); |
| 400 | } |
| 401 | |
| 402 | WebContentsImpl* outer_contents = current_contents->GetOuterWebContents(); |
| 403 | if (outer_contents) |
| 404 | current.insert(outer_contents); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | return result; |
| 409 | } |
| 410 | |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 411 | #if defined(OS_ANDROID) |
| 412 | float GetDeviceScaleAdjustment(int min_width) { |
| 413 | static const float kMinFSM = 1.05f; |
| 414 | static const int kWidthForMinFSM = 320; |
| 415 | static const float kMaxFSM = 1.3f; |
| 416 | static const int kWidthForMaxFSM = 800; |
| 417 | |
| 418 | if (min_width <= kWidthForMinFSM) |
| 419 | return kMinFSM; |
| 420 | if (min_width >= kWidthForMaxFSM) |
| 421 | return kMaxFSM; |
| 422 | |
| 423 | // The font scale multiplier varies linearly between kMinFSM and kMaxFSM. |
| 424 | float ratio = static_cast<float>(min_width - kWidthForMinFSM) / |
| 425 | (kWidthForMaxFSM - kWidthForMinFSM); |
| 426 | return ratio * (kMaxFSM - kMinFSM) + kMinFSM; |
| 427 | } |
| 428 | #endif |
| 429 | |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 430 | // Used to attach the "set of fullscreen contents" to a browser context. Storing |
| 431 | // sets of WebContents on their browser context is done for two reasons. One, |
| 432 | // related WebContentses must necessarily share a browser context, so this saves |
| 433 | // lookup time by restricting to one specific browser context. Two, separating |
| 434 | // by browser context is preemptive paranoia about keeping things separate. |
| 435 | class FullscreenContentsHolder : public base::SupportsUserData::Data { |
| 436 | public: |
| 437 | FullscreenContentsHolder() = default; |
| 438 | ~FullscreenContentsHolder() override = default; |
| 439 | |
| 440 | FullscreenContentsHolder(const FullscreenContentsHolder&) = delete; |
| 441 | FullscreenContentsHolder& operator=(const FullscreenContentsHolder&) = delete; |
| 442 | |
| 443 | base::flat_set<WebContentsImpl*>* set() { return &set_; } |
| 444 | |
| 445 | private: |
| 446 | base::flat_set<WebContentsImpl*> set_; |
| 447 | }; |
| 448 | |
| 449 | const char kFullscreenContentsSet[] = "fullscreen-contents"; |
| 450 | |
| 451 | base::flat_set<WebContentsImpl*>* FullscreenContentsSet( |
| 452 | BrowserContext* browser_context) { |
| 453 | auto* set_holder = static_cast<FullscreenContentsHolder*>( |
| 454 | browser_context->GetUserData(kFullscreenContentsSet)); |
| 455 | if (!set_holder) { |
| 456 | auto new_holder = std::make_unique<FullscreenContentsHolder>(); |
| 457 | set_holder = new_holder.get(); |
| 458 | browser_context->SetUserData(kFullscreenContentsSet, std::move(new_holder)); |
| 459 | } |
| 460 | |
| 461 | return set_holder->set(); |
| 462 | } |
| 463 | |
Mike Wasserman | 5b7d3bf | 2020-08-21 21:52:26 | [diff] [blame] | 464 | // Returns true if |host| has the Window Placement permission granted. |
Mike Wasserman | db8f4f0 | 2020-10-06 01:18:37 | [diff] [blame] | 465 | bool IsWindowPlacementGranted(RenderFrameHost* host) { |
Mike Wasserman | 5b7d3bf | 2020-08-21 21:52:26 | [diff] [blame] | 466 | auto* controller = |
| 467 | PermissionControllerImpl::FromBrowserContext(host->GetBrowserContext()); |
| 468 | return controller && controller->GetPermissionStatusForFrame( |
| 469 | PermissionType::WINDOW_PLACEMENT, host, |
| 470 | host->GetLastCommittedURL()) == |
| 471 | blink::mojom::PermissionStatus::GRANTED; |
| 472 | } |
| 473 | |
Mike Wasserman | b6bc015 | 2020-08-25 22:46:20 | [diff] [blame] | 474 | // Adjust the requested |bounds| for opening or placing a window and return the |
| 475 | // id of the display where the window will be placed. The bounds may not extend |
| 476 | // outside a single screen's work area, and the |host| requires permission to |
| 477 | // specify bounds on a screen other than its current screen. |
Mike Wasserman | dabad61 | 2020-08-13 04:26:27 | [diff] [blame] | 478 | // TODO(crbug.com/897300): These adjustments are inaccurate for window.open(), |
| 479 | // which specifies the inner content size, and for window.moveTo, resizeTo, etc. |
| 480 | // calls on newly created windows, which may pass empty sizes or positions to |
| 481 | // indicate uninitialized placement information in the renderer. Constraints |
| 482 | // enforced later should resolve most inaccuracies, but this early enforcement |
| 483 | // is needed to ensure bounds indicate the appropriate display. |
Mike Wasserman | b6bc015 | 2020-08-25 22:46:20 | [diff] [blame] | 484 | int64_t AdjustRequestedWindowBounds(gfx::Rect* bounds, RenderFrameHost* host) { |
Mike Wasserman | dabad61 | 2020-08-13 04:26:27 | [diff] [blame] | 485 | auto* screen = display::Screen::GetScreen(); |
Mike Wasserman | b6bc015 | 2020-08-25 22:46:20 | [diff] [blame] | 486 | auto display = screen->GetDisplayMatching(*bounds); |
Mike Wasserman | dabad61 | 2020-08-13 04:26:27 | [diff] [blame] | 487 | |
| 488 | // Check, but do not prompt, for permission to place windows on other screens. |
| 489 | // Sites generally need permission to get such bounds in the first place. |
| 490 | // Also clamp offscreen bounds to the window's current screen. |
Mike Wasserman | db8f4f0 | 2020-10-06 01:18:37 | [diff] [blame] | 491 | if (!bounds->Intersects(display.bounds()) || !IsWindowPlacementGranted(host)) |
Mike Wasserman | dabad61 | 2020-08-13 04:26:27 | [diff] [blame] | 492 | display = screen->GetDisplayNearestView(host->GetNativeView()); |
Mike Wasserman | dabad61 | 2020-08-13 04:26:27 | [diff] [blame] | 493 | |
Mike Wasserman | b6bc015 | 2020-08-25 22:46:20 | [diff] [blame] | 494 | bounds->AdjustToFit(display.work_area()); |
| 495 | return display.id(); |
Mike Wasserman | dabad61 | 2020-08-13 04:26:27 | [diff] [blame] | 496 | } |
| 497 | |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 498 | } // namespace |
| 499 | |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 500 | CreatedWindow::CreatedWindow() = default; |
| 501 | CreatedWindow::CreatedWindow(std::unique_ptr<WebContentsImpl> contents, |
| 502 | GURL target_url) |
| 503 | : contents(std::move(contents)), target_url(std::move(target_url)) {} |
| 504 | CreatedWindow::~CreatedWindow() = default; |
| 505 | CreatedWindow::CreatedWindow(CreatedWindow&&) = default; |
| 506 | CreatedWindow& CreatedWindow::operator=(CreatedWindow&&) = default; |
| 507 | |
Erik Chen | bb8e738e | 2018-04-28 14:10:43 | [diff] [blame] | 508 | std::unique_ptr<WebContents> WebContents::Create( |
| 509 | const WebContents::CreateParams& params) { |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 510 | return WebContentsImpl::Create(params); |
| 511 | } |
| 512 | |
| 513 | std::unique_ptr<WebContentsImpl> WebContentsImpl::Create( |
| 514 | const CreateParams& params) { |
| 515 | return CreateWithOpener(params, FindOpenerRFH(params)); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 516 | } |
| 517 | |
erikchen | ade1fef | 2018-05-02 22:07:57 | [diff] [blame] | 518 | std::unique_ptr<WebContents> WebContents::CreateWithSessionStorage( |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 519 | const WebContents::CreateParams& params, |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 520 | const SessionStorageNamespaceMap& session_storage_namespace_map) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 521 | OPTIONAL_TRACE_EVENT0("content", "WebContents::CreateWithSessionStorage"); |
erikchen | ade1fef | 2018-05-02 22:07:57 | [diff] [blame] | 522 | std::unique_ptr<WebContentsImpl> new_contents( |
| 523 | new WebContentsImpl(params.browser_context)); |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 524 | RenderFrameHostImpl* opener_rfh = FindOpenerRFH(params); |
| 525 | FrameTreeNode* opener = nullptr; |
| 526 | if (opener_rfh) |
| 527 | opener = opener_rfh->frame_tree_node(); |
| 528 | new_contents->SetOpenerForNewContents(opener, params.opener_suppressed); |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 529 | |
Fergal Daly | 55b6d72 | 2020-09-11 07:56:33 | [diff] [blame] | 530 | for (const auto& it : session_storage_namespace_map) { |
| 531 | new_contents->GetController().SetSessionStorageNamespace(it.first, |
| 532 | it.second.get()); |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 533 | } |
| 534 | |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 535 | WebContentsImpl* outer_web_contents = nullptr; |
Sam McNally | 69a3377 | 2018-06-27 16:54:12 | [diff] [blame] | 536 | if (params.guest_delegate) { |
| 537 | // This makes |new_contents| act as a guest. |
| 538 | // For more info, see comment above class BrowserPluginGuest. |
Albert J. Wong | c55cc64d | 2018-10-12 02:50:04 | [diff] [blame] | 539 | BrowserPluginGuest::CreateInWebContents(new_contents.get(), |
| 540 | params.guest_delegate); |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 541 | outer_web_contents = static_cast<WebContentsImpl*>( |
| 542 | params.guest_delegate->GetOwnerWebContents()); |
Sam McNally | 69a3377 | 2018-06-27 16:54:12 | [diff] [blame] | 543 | } |
| 544 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 545 | new_contents->Init(params); |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 546 | if (outer_web_contents) |
| 547 | outer_web_contents->InnerWebContentsCreated(new_contents.get()); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 548 | return new_contents; |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 549 | } |
[email protected] | 746d305 | 2012-05-22 15:15:47 | [diff] [blame] | 550 | |
benwells | 5e7260d | 2017-03-20 23:36:33 | [diff] [blame] | 551 | void WebContentsImpl::FriendWrapper::AddCreatedCallbackForTesting( |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 552 | const CreatedCallback& callback) { |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 553 | g_created_callbacks.Get().push_back(callback); |
| 554 | } |
| 555 | |
benwells | 5e7260d | 2017-03-20 23:36:33 | [diff] [blame] | 556 | void WebContentsImpl::FriendWrapper::RemoveCreatedCallbackForTesting( |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 557 | const CreatedCallback& callback) { |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 558 | for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) { |
Robert Liao | 1db5a35 | 2019-06-05 20:57:34 | [diff] [blame] | 559 | if (g_created_callbacks.Get().at(i) == callback) { |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 560 | g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i); |
| 561 | return; |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 566 | WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 567 | OPTIONAL_TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 568 | "WebContents::FromRenderViewHost", "render_view_host", |
| 569 | rvh); |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 570 | if (!rvh) |
| 571 | return nullptr; |
[email protected] | 746d305 | 2012-05-22 15:15:47 | [diff] [blame] | 572 | return rvh->GetDelegate()->GetAsWebContents(); |
| 573 | } |
| 574 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 575 | WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 576 | OPTIONAL_TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 577 | "WebContents::FromRenderFrameHost", "render_frame_host", |
| 578 | base::trace_event::ToTracedValue(rfh)); |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 579 | if (!rfh) |
| 580 | return nullptr; |
Alexander Timin | 33bd754c0 | 2020-03-10 22:50:18 | [diff] [blame] | 581 | if (!rfh->IsCurrent() && base::FeatureList::IsEnabled( |
| 582 | kCheckWebContentsAccessFromNonCurrentFrame)) { |
| 583 | // TODO(crbug.com/1059903): return nullptr here eventually. |
| 584 | base::debug::DumpWithoutCrashing(); |
| 585 | } |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 586 | return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents(); |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 587 | } |
| 588 | |
ananta | 4b7467a5 | 2016-09-23 01:42:38 | [diff] [blame] | 589 | WebContents* WebContents::FromFrameTreeNodeId(int frame_tree_node_id) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 590 | OPTIONAL_TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 591 | "WebContents::FromFrameTreeNodeId", |
| 592 | "frame_tree_node_id", frame_tree_node_id); |
ananta | 4b7467a5 | 2016-09-23 01:42:38 | [diff] [blame] | 593 | FrameTreeNode* frame_tree_node = |
| 594 | FrameTreeNode::GloballyFindByID(frame_tree_node_id); |
ananta | b8cfa3b | 2016-10-14 22:43:19 | [diff] [blame] | 595 | if (!frame_tree_node) |
| 596 | return nullptr; |
jam | 8c4edd0 | 2017-05-06 18:50:33 | [diff] [blame] | 597 | return WebContentsImpl::FromFrameTreeNode(frame_tree_node); |
ananta | 4b7467a5 | 2016-09-23 01:42:38 | [diff] [blame] | 598 | } |
| 599 | |
leon.han | 552e9de | 2017-02-09 14:37:30 | [diff] [blame] | 600 | void WebContents::SetScreenOrientationDelegate( |
| 601 | ScreenOrientationDelegate* delegate) { |
| 602 | ScreenOrientationProvider::SetDelegate(delegate); |
| 603 | } |
| 604 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 605 | // WebContentsImpl::DestructionObserver ---------------------------------------- |
| 606 | |
| 607 | class WebContentsImpl::DestructionObserver : public WebContentsObserver { |
| 608 | public: |
| 609 | DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents) |
Fergal Daly | 09d6c76 | 2020-05-29 02:05:18 | [diff] [blame] | 610 | : WebContentsObserver(watched_contents), owner_(owner) {} |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 611 | |
| 612 | // WebContentsObserver: |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 613 | void WebContentsDestroyed() override { |
[email protected] | 12a4683 | 2014-05-09 13:35:58 | [diff] [blame] | 614 | owner_->OnWebContentsDestroyed( |
| 615 | static_cast<WebContentsImpl*>(web_contents())); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | private: |
| 619 | WebContentsImpl* owner_; |
| 620 | |
| 621 | DISALLOW_COPY_AND_ASSIGN(DestructionObserver); |
| 622 | }; |
| 623 | |
Sreeja Kamishetty | be0ccd6b | 2020-06-09 11:52:50 | [diff] [blame] | 624 | // TODO(sreejakshetty): Make |WebContentsImpl::ColorChooser| per-frame instead |
| 625 | // of WebContents-owned. |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 626 | // WebContentsImpl::ColorChooser ---------------------------------------------- |
Joel Hockey | 163835a | 2017-12-20 11:51:57 | [diff] [blame] | 627 | class WebContentsImpl::ColorChooser : public blink::mojom::ColorChooser { |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 628 | public: |
| 629 | ColorChooser(content::ColorChooser* chooser, |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 630 | mojo::PendingReceiver<blink::mojom::ColorChooser> receiver, |
| 631 | mojo::PendingRemote<blink::mojom::ColorChooserClient> client) |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 632 | : chooser_(chooser), |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 633 | receiver_(this, std::move(receiver)), |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 634 | client_(std::move(client)) { |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 635 | receiver_.set_disconnect_handler( |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 636 | base::BindOnce([](content::ColorChooser* chooser) { chooser->End(); }, |
| 637 | base::Unretained(chooser))); |
| 638 | } |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 639 | |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 640 | ~ColorChooser() override { chooser_->End(); } |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 641 | |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 642 | void SetSelectedColor(SkColor color) override { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 643 | OPTIONAL_TRACE_EVENT0("content", |
| 644 | "WebContentsImpl::ColorChooser::SetSelectedColor"); |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 645 | chooser_->SetSelectedColor(color); |
| 646 | } |
| 647 | |
| 648 | void DidChooseColorInColorChooser(SkColor color) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 649 | OPTIONAL_TRACE_EVENT0( |
| 650 | "content", |
| 651 | "WebContentsImpl::ColorChooser::DidChooseColorInColorChooser"); |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 652 | client_->DidChooseColor(color); |
| 653 | } |
| 654 | |
| 655 | private: |
| 656 | // Color chooser that was opened by this tab. |
| 657 | std::unique_ptr<content::ColorChooser> chooser_; |
| 658 | |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 659 | // mojo receiver. |
| 660 | mojo::Receiver<blink::mojom::ColorChooser> receiver_; |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 661 | |
| 662 | // mojo renderer client. |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 663 | mojo::Remote<blink::mojom::ColorChooserClient> client_; |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 664 | }; |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 665 | |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 666 | // WebContentsImpl::WebContentsTreeNode ---------------------------------------- |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 667 | WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode( |
| 668 | WebContentsImpl* current_web_contents) |
| 669 | : current_web_contents_(current_web_contents), |
| 670 | outer_web_contents_(nullptr), |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 671 | outer_contents_frame_tree_node_id_( |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 672 | FrameTreeNode::kFrameTreeNodeInvalidId), |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 673 | focused_web_contents_(current_web_contents) {} |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 674 | |
Fergal Daly | 55b6d72 | 2020-09-11 07:56:33 | [diff] [blame] | 675 | WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() = default; |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 676 | |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 677 | std::unique_ptr<WebContents> |
| 678 | WebContentsImpl::WebContentsTreeNode::DisconnectFromOuterWebContents() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 679 | OPTIONAL_TRACE_EVENT0("content", |
| 680 | "WebContentsTreeNode::DisconnectFromOuterWebContents"); |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 681 | std::unique_ptr<WebContents> inner_contents = |
| 682 | outer_web_contents_->node_.DetachInnerWebContents(current_web_contents_); |
| 683 | OuterContentsFrameTreeNode()->RemoveObserver(this); |
| 684 | outer_contents_frame_tree_node_id_ = FrameTreeNode::kFrameTreeNodeInvalidId; |
| 685 | outer_web_contents_ = nullptr; |
| 686 | return inner_contents; |
| 687 | } |
| 688 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 689 | void WebContentsImpl::WebContentsTreeNode::AttachInnerWebContents( |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 690 | std::unique_ptr<WebContents> inner_web_contents, |
| 691 | RenderFrameHostImpl* render_frame_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 692 | OPTIONAL_TRACE_EVENT0("content", |
| 693 | "WebContentsTreeNode::AttachInnerWebContents"); |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 694 | WebContentsImpl* inner_web_contents_impl = |
| 695 | static_cast<WebContentsImpl*>(inner_web_contents.get()); |
| 696 | WebContentsTreeNode& inner_web_contents_node = inner_web_contents_impl->node_; |
| 697 | |
| 698 | inner_web_contents_node.focused_web_contents_ = nullptr; |
| 699 | inner_web_contents_node.outer_web_contents_ = current_web_contents_; |
| 700 | inner_web_contents_node.outer_contents_frame_tree_node_id_ = |
| 701 | render_frame_host->frame_tree_node()->frame_tree_node_id(); |
| 702 | |
Lucas Furukawa Gadani | 3d38ec15 | 2018-10-26 20:55:18 | [diff] [blame] | 703 | inner_web_contents_.push_back(std::move(inner_web_contents)); |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 704 | |
| 705 | render_frame_host->frame_tree_node()->AddObserver(&inner_web_contents_node); |
Jeremy Roman | 03ce13ce | 2020-05-29 22:16:57 | [diff] [blame] | 706 | current_web_contents_->InnerWebContentsAttached(inner_web_contents_impl); |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 707 | } |
| 708 | |
Lucas Furukawa Gadani | 3d38ec15 | 2018-10-26 20:55:18 | [diff] [blame] | 709 | std::unique_ptr<WebContents> |
| 710 | WebContentsImpl::WebContentsTreeNode::DetachInnerWebContents( |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 711 | WebContentsImpl* inner_web_contents) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 712 | OPTIONAL_TRACE_EVENT0( |
| 713 | "content", |
| 714 | "WebContentsImpl::WebContentsTreeNode::DetachInnerWebContents"); |
Lucas Furukawa Gadani | 3d38ec15 | 2018-10-26 20:55:18 | [diff] [blame] | 715 | std::unique_ptr<WebContents> detached_contents; |
| 716 | for (std::unique_ptr<WebContents>& web_contents : inner_web_contents_) { |
| 717 | if (web_contents.get() == inner_web_contents) { |
| 718 | detached_contents = std::move(web_contents); |
| 719 | std::swap(web_contents, inner_web_contents_.back()); |
| 720 | inner_web_contents_.pop_back(); |
Jeremy Roman | 03ce13ce | 2020-05-29 22:16:57 | [diff] [blame] | 721 | current_web_contents_->InnerWebContentsDetached(inner_web_contents); |
Lucas Furukawa Gadani | 3d38ec15 | 2018-10-26 20:55:18 | [diff] [blame] | 722 | return detached_contents; |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | NOTREACHED(); |
| 727 | return nullptr; |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 728 | } |
| 729 | |
lfg | a3e2bdc | 2017-03-07 20:44:01 | [diff] [blame] | 730 | FrameTreeNode* |
| 731 | WebContentsImpl::WebContentsTreeNode::OuterContentsFrameTreeNode() const { |
| 732 | return FrameTreeNode::GloballyFindByID(outer_contents_frame_tree_node_id_); |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 733 | } |
| 734 | |
lfg | a3e2bdc | 2017-03-07 20:44:01 | [diff] [blame] | 735 | void WebContentsImpl::WebContentsTreeNode::OnFrameTreeNodeDestroyed( |
| 736 | FrameTreeNode* node) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 737 | OPTIONAL_TRACE_EVENT0("content", |
| 738 | "WebContentsTreeNode::OnFrameTreeNodeDestroyed"); |
lfg | a3e2bdc | 2017-03-07 20:44:01 | [diff] [blame] | 739 | DCHECK_EQ(outer_contents_frame_tree_node_id_, node->frame_tree_node_id()) |
| 740 | << "WebContentsTreeNode should only receive notifications for the " |
| 741 | "FrameTreeNode in its outer WebContents that hosts it."; |
Lucas Furukawa Gadani | 3d38ec15 | 2018-10-26 20:55:18 | [diff] [blame] | 742 | |
| 743 | // Deletes |this| too. |
| 744 | outer_web_contents_->node_.DetachInnerWebContents(current_web_contents_); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 745 | } |
| 746 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 747 | void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents( |
| 748 | WebContentsImpl* web_contents) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 749 | OPTIONAL_TRACE_EVENT0("content", |
| 750 | "WebContentsTreeNode::SetFocusedWebContents"); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 751 | DCHECK(!outer_web_contents()) |
| 752 | << "Only the outermost WebContents tracks focus."; |
| 753 | focused_web_contents_ = web_contents; |
| 754 | } |
| 755 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 756 | WebContentsImpl* |
| 757 | WebContentsImpl::WebContentsTreeNode::GetInnerWebContentsInFrame( |
| 758 | const FrameTreeNode* frame) { |
| 759 | auto ftn_id = frame->frame_tree_node_id(); |
Lucas Furukawa Gadani | 3d38ec15 | 2018-10-26 20:55:18 | [diff] [blame] | 760 | for (auto& contents : inner_web_contents_) { |
| 761 | WebContentsImpl* impl = static_cast<WebContentsImpl*>(contents.get()); |
| 762 | if (impl->node_.outer_contents_frame_tree_node_id() == ftn_id) { |
| 763 | return impl; |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | return nullptr; |
| 767 | } |
| 768 | |
Lucas Furukawa Gadani | 3d38ec15 | 2018-10-26 20:55:18 | [diff] [blame] | 769 | std::vector<WebContentsImpl*> |
| 770 | WebContentsImpl::WebContentsTreeNode::GetInnerWebContents() const { |
| 771 | std::vector<WebContentsImpl*> inner_web_contents; |
| 772 | for (auto& contents : inner_web_contents_) |
| 773 | inner_web_contents.push_back(static_cast<WebContentsImpl*>(contents.get())); |
| 774 | |
| 775 | return inner_web_contents; |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 776 | } |
| 777 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 778 | // WebContentsObserverList ----------------------------------------------------- |
| 779 | WebContentsImpl::WebContentsObserverList::WebContentsObserverList() = default; |
| 780 | WebContentsImpl::WebContentsObserverList::~WebContentsObserverList() = default; |
| 781 | |
| 782 | void WebContentsImpl::WebContentsObserverList::AddObserver( |
| 783 | WebContentsObserver* observer) { |
| 784 | observers_.AddObserver(observer); |
| 785 | } |
| 786 | |
| 787 | void WebContentsImpl::WebContentsObserverList::RemoveObserver( |
| 788 | WebContentsObserver* observer) { |
| 789 | observers_.RemoveObserver(observer); |
| 790 | } |
| 791 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 792 | // WebContentsImpl ------------------------------------------------------------- |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 793 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 794 | WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 795 | : delegate_(nullptr), |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 796 | controller_(this, browser_context), |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 797 | render_view_host_delegate_view_(nullptr), |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 798 | created_with_opener_(false), |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 799 | node_(this), |
Fergal Daly | 09d6c76 | 2020-05-29 02:05:18 | [diff] [blame] | 800 | frame_tree_(&controller_, this, this, this, this, this), |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 801 | is_load_to_different_document_(false), |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 802 | crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
| 803 | crashed_error_code_(0), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 804 | waiting_for_response_(false), |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 805 | load_state_(net::LOAD_STATE_IDLE, base::string16()), |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 806 | upload_size_(0), |
| 807 | upload_position_(0), |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 808 | is_resume_pending_(false), |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 809 | has_accessed_initial_document_(false), |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 810 | visible_capturer_count_(0), |
| 811 | hidden_capturer_count_(0), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 812 | is_being_destroyed_(false), |
| 813 | notify_disconnection_(false), |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 814 | dialog_manager_(nullptr), |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 815 | is_showing_before_unload_dialog_(false), |
gab | 0dccfef | 2015-05-20 18:43:39 | [diff] [blame] | 816 | last_active_time_(base::TimeTicks::Now()), |
[email protected] | ebf40a7 | 2010-07-22 01:46:38 | [diff] [blame] | 817 | closed_by_user_gesture_(false), |
danakj | 938b37a6 | 2019-09-24 18:35:54 | [diff] [blame] | 818 | minimum_zoom_percent_( |
| 819 | static_cast<int>(blink::kMinimumPageZoomFactor * 100)), |
| 820 | maximum_zoom_percent_( |
| 821 | static_cast<int>(blink::kMaximumPageZoomFactor * 100)), |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 822 | zoom_scroll_remainder_(0), |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 823 | force_disable_overscroll_content_(false), |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 824 | last_dialog_suppressed_(false), |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 825 | accessibility_mode_( |
Dominic Mazzoni | 21fb028 | 2019-02-13 18:32:47 | [diff] [blame] | 826 | GetContentClient()->browser()->GetAXModeForBrowserContext( |
| 827 | browser_context)), |
avayvod | cc85bbd | 2015-08-28 19:11:15 | [diff] [blame] | 828 | audio_stream_monitor_(this), |
Thomas Guilbert | 882c4cec | 2019-02-14 05:55:45 | [diff] [blame] | 829 | media_web_contents_observer_( |
| 830 | std::make_unique<MediaWebContentsObserver>(this)), |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 831 | #if !defined(OS_ANDROID) |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 832 | page_scale_factor_is_one_(true), |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 833 | #endif // !defined(OS_ANDROID) |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 834 | is_overlay_content_(false), |
ekaramad | f6750aa | 2017-06-06 18:29:42 | [diff] [blame] | 835 | showing_context_menu_(false), |
W. James MacLean | 6219867 | 2019-06-04 16:46:10 | [diff] [blame] | 836 | text_autosizer_page_info_({0, 0, 1.f}), |
shivanigithub | cceeacf | 2020-03-06 20:00:27 | [diff] [blame] | 837 | native_theme_observer_(this) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 838 | TRACE_EVENT0("content", "WebContentsImpl::WebContentsImpl"); |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame] | 839 | frame_tree_.SetFrameRemoveListener(base::BindRepeating( |
| 840 | &WebContentsImpl::OnFrameRemoved, base::Unretained(this))); |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 841 | #if BUILDFLAG(ENABLE_PLUGINS) |
Fergal Daly | 55b6d72 | 2020-09-11 07:56:33 | [diff] [blame] | 842 | pepper_playback_observer_ = std::make_unique<PepperPlaybackObserver>(this); |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 843 | #endif |
blundell | e75a8f9 | 2017-03-27 08:11:17 | [diff] [blame] | 844 | |
Becca Hughes | 8633462 | 2018-07-09 21:29:38 | [diff] [blame] | 845 | #if defined(OS_ANDROID) |
Elly Fong-Jones | cdd7ae8 | 2019-02-20 23:26:33 | [diff] [blame] | 846 | display_cutout_host_impl_ = std::make_unique<DisplayCutoutHostImpl>(this); |
Becca Hughes | 8633462 | 2018-07-09 21:29:38 | [diff] [blame] | 847 | #endif |
John Delaney | 732721e9 | 2020-02-07 23:11:27 | [diff] [blame] | 848 | |
Alison Maher | 7f366dc6 | 2020-03-03 19:46:00 | [diff] [blame] | 849 | ui::NativeTheme* native_theme = ui::NativeTheme::GetInstanceForWeb(); |
| 850 | native_theme_observer_.Add(native_theme); |
| 851 | using_dark_colors_ = native_theme->ShouldUseDarkColors(); |
| 852 | preferred_color_scheme_ = native_theme->GetPreferredColorScheme(); |
| 853 | |
Mike Wasserman | b213b935 | 2020-04-16 00:32:34 | [diff] [blame] | 854 | screen_change_monitor_ = |
| 855 | std::make_unique<ScreenChangeMonitor>(base::BindRepeating( |
| 856 | &WebContentsImpl::OnScreensChange, base::Unretained(this))); |
| 857 | |
John Delaney | 732721e9 | 2020-02-07 23:11:27 | [diff] [blame] | 858 | // ConversionHost takes a weak ref on |this|, so it must be created outside of |
| 859 | // the initializer list. |
Charlie Harrison | 405f621 | 2020-04-14 21:57:32 | [diff] [blame] | 860 | if (base::FeatureList::IsEnabled(features::kConversionMeasurement)) { |
| 861 | conversion_host_ = std::make_unique<ConversionHost>(this); |
| 862 | } |
[email protected] | 332af773 | 2009-03-11 13:21:35 | [diff] [blame] | 863 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 864 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 865 | WebContentsImpl::~WebContentsImpl() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 866 | TRACE_EVENT0("content", "WebContentsImpl::~WebContentsImpl"); |
| 867 | |
creis | ba91ba8 | 2017-05-12 22:56:19 | [diff] [blame] | 868 | // Imperfect sanity check against double free, given some crashes unexpectedly |
| 869 | // observed in the wild. |
| 870 | CHECK(!is_being_destroyed_); |
| 871 | |
| 872 | // We generally keep track of is_being_destroyed_ to let other features know |
| 873 | // to avoid certain actions during destruction. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 874 | is_being_destroyed_ = true; |
| 875 | |
creis | 97867aa | 2017-02-17 18:39:45 | [diff] [blame] | 876 | // A WebContents should never be deleted while it is notifying observers, |
creis | ba91ba8 | 2017-05-12 22:56:19 | [diff] [blame] | 877 | // since this will lead to a use-after-free as it continues to notify later |
creis | 97867aa | 2017-02-17 18:39:45 | [diff] [blame] | 878 | // observers. |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 879 | CHECK(!observers_.is_notifying_observers()); |
creis | 97867aa | 2017-02-17 18:39:45 | [diff] [blame] | 880 | |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 881 | FullscreenContentsSet(GetBrowserContext())->erase(this); |
| 882 | |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 883 | rwh_input_event_router_.reset(); |
| 884 | |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 885 | for (auto& entry : receiver_sets_) |
| 886 | entry.second->CloseAllReceivers(); |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 887 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 888 | WebContentsImpl* outermost = GetOutermostWebContents(); |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 889 | if (this != outermost && ContainsOrIsFocusedWebContents()) { |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 890 | // If the current WebContents is in focus, unset it. |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 891 | outermost->SetAsFocusedWebContentsIfNecessary(); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 892 | } |
| 893 | |
Nick Carter | d73635b | 2018-03-13 18:31:41 | [diff] [blame] | 894 | if (mouse_lock_widget_) |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 895 | mouse_lock_widget_->RejectMouseLockOrUnlockIfNecessary( |
| 896 | blink::mojom::PointerLockResult::kElementDestroyed); |
Nick Carter | d73635b | 2018-03-13 18:31:41 | [diff] [blame] | 897 | |
dcheng | 72be33c | 2016-01-21 04:11:31 | [diff] [blame] | 898 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 899 | // Delete all RFHs pending shutdown, which will lead the corresponding RVHs |
| 900 | // to be shutdown and be deleted as well. |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 901 | node->render_manager()->ClearRFHsPendingShutdown(); |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 902 | node->render_manager()->ClearWebUIInstances(); |
dcheng | 72be33c | 2016-01-21 04:11:31 | [diff] [blame] | 903 | } |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 904 | |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 905 | for (RenderWidgetHostImpl* widget : created_widgets_) |
| 906 | widget->DetachDelegate(); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 907 | created_widgets_.clear(); |
| 908 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 909 | // Clear out any JavaScript state. |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 910 | if (dialog_manager_) { |
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 911 | dialog_manager_->CancelDialogs(this, /*reset_state=*/true); |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 912 | } |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 913 | |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 914 | color_chooser_.reset(); |
Rakina Zata Amni | 1619612 | 2018-11-14 02:14:00 | [diff] [blame] | 915 | find_request_manager_.reset(); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 916 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 917 | NotifyDisconnected(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 918 | |
[email protected] | ca13a44 | 2012-04-17 14:00:12 | [diff] [blame] | 919 | // Notify any observer that have a reference on this WebContents. |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 920 | NotificationService::current()->Notify( |
| 921 | NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 922 | Source<WebContents>(this), |
| 923 | NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 924 | |
Arthur Sonzogni | 5a9a88c | 2018-10-18 13:16:00 | [diff] [blame] | 925 | // Destroy all subframes now. This notifies observers. |
| 926 | GetMainFrame()->ResetChildren(); |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 927 | GetRenderManager()->ResetProxyHosts(); |
[email protected] | c06c58c | 2014-03-12 20:31:59 | [diff] [blame] | 928 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 929 | // Manually call the observer methods for the root frame tree node. It is |
| 930 | // necessary to manually delete all objects tracking navigations |
| 931 | // (NavigationHandle, NavigationRequest) for observers to be properly |
| 932 | // notified of these navigations stopping before the WebContents is |
| 933 | // destroyed. |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 934 | RenderFrameHostManager* root = GetRenderManager(); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 935 | |
Lowell Manners | 2025011 | 2019-10-18 15:06:15 | [diff] [blame] | 936 | GetController().GetBackForwardCache().Shutdown(); |
| 937 | |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 938 | root->current_frame_host()->SetRenderFrameCreated(false); |
clamy | fc3850d | 2018-02-23 14:35:28 | [diff] [blame] | 939 | root->current_frame_host()->ResetNavigationRequests(); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 940 | |
Arthur Hemery | c338017 | 2018-01-22 14:00:17 | [diff] [blame] | 941 | // Do not update state as the WebContents is being destroyed. |
Arthur Hemery | 241b939 | 2019-10-24 11:08:41 | [diff] [blame] | 942 | frame_tree_.root()->ResetNavigationRequest(true); |
Arthur Hemery | c338017 | 2018-01-22 14:00:17 | [diff] [blame] | 943 | if (root->speculative_frame_host()) { |
danakj | f234243 | 2019-05-15 21:46:09 | [diff] [blame] | 944 | root->speculative_frame_host()->DeleteRenderFrame( |
| 945 | FrameDeleteIntention::kSpeculativeMainFrameForShutdown); |
Arthur Hemery | c338017 | 2018-01-22 14:00:17 | [diff] [blame] | 946 | root->speculative_frame_host()->SetRenderFrameCreated(false); |
clamy | fc3850d | 2018-02-23 14:35:28 | [diff] [blame] | 947 | root->speculative_frame_host()->ResetNavigationRequests(); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 948 | } |
[email protected] | f273ee5 | 2013-10-18 16:05:27 | [diff] [blame] | 949 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 950 | #if BUILDFLAG(ENABLE_PLUGINS) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 951 | // Call this before WebContentsDestroyed() is broadcasted since |
| 952 | // AudioFocusManager will be destroyed after that. |
| 953 | pepper_playback_observer_.reset(); |
| 954 | #endif // defined(ENABLED_PLUGINS) |
| 955 | |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 956 | // If audio is playing then notify external observers of the audio stream |
| 957 | // disappearing. |
| 958 | if (is_currently_audible_) { |
| 959 | is_currently_audible_ = false; |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 960 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 961 | observer->OnAudioStateChanged(false); |
| 962 | }); |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 963 | if (GetOuterWebContents()) |
| 964 | GetOuterWebContents()->OnAudioStateChanged(); |
| 965 | } |
| 966 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 967 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 968 | observer->FrameDeleted(root->current_frame_host()); |
| 969 | }); |
| 970 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 971 | observer->RenderViewDeleted(root->current_host()); |
| 972 | }); |
Kevin McNee | 576bb5d8 | 2019-05-29 16:47:51 | [diff] [blame] | 973 | #if defined(OS_ANDROID) |
| 974 | // For simplicity, destroy the Java WebContents before we notify of the |
| 975 | // destruction of the WebContents. |
| 976 | ClearWebContentsAndroid(); |
| 977 | #endif |
| 978 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 979 | observers_.ForEachObserver( |
| 980 | [&](WebContentsObserver* observer) { observer->WebContentsDestroyed(); }); |
Becca Hughes | d11d650 | 2018-07-31 17:01:28 | [diff] [blame] | 981 | if (display_cutout_host_impl_) |
| 982 | display_cutout_host_impl_->WebContentsDestroyed(); |
| 983 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 984 | observers_.ForEachObserver( |
| 985 | [&](WebContentsObserver* observer) { observer->ResetWebContents(); }); |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 986 | SetDelegate(nullptr); |
[email protected] | b5a1d11c | 2011-02-17 03:09:42 | [diff] [blame] | 987 | } |
| 988 | |
erikchen | 50735fd | 2018-05-05 15:08:33 | [diff] [blame] | 989 | std::unique_ptr<WebContentsImpl> WebContentsImpl::CreateWithOpener( |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 990 | const WebContents::CreateParams& params, |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 991 | RenderFrameHostImpl* opener_rfh) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 992 | OPTIONAL_TRACE_EVENT1("browser", "WebContentsImpl::CreateWithOpener", |
| 993 | "opener", base::trace_event::ToTracedValue(opener_rfh)); |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 994 | FrameTreeNode* opener = nullptr; |
| 995 | if (opener_rfh) |
| 996 | opener = opener_rfh->frame_tree_node(); |
erikchen | 50735fd | 2018-05-05 15:08:33 | [diff] [blame] | 997 | std::unique_ptr<WebContentsImpl> new_contents( |
| 998 | new WebContentsImpl(params.browser_context)); |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 999 | new_contents->SetOpenerForNewContents(opener, params.opener_suppressed); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 1000 | |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 1001 | // If the opener is sandboxed, a new popup must inherit the opener's sandbox |
| 1002 | // flags, and these flags take effect immediately. An exception is if the |
| 1003 | // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts |
| 1004 | // bit (which is controlled by the "allow-popups-to-escape-sandbox" token). |
| 1005 | // See https://html.spec.whatwg.org/#attr-iframe-sandbox. |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 1006 | FrameTreeNode* new_root = new_contents->GetFrameTree()->root(); |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 1007 | if (opener) { |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 1008 | network::mojom::WebSandboxFlags opener_flags = |
Antonio Gomes | 7096ac0 | 2020-02-14 14:29:54 | [diff] [blame] | 1009 | opener_rfh->active_sandbox_flags(); |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 1010 | const network::mojom::WebSandboxFlags inherit_flag = |
| 1011 | network::mojom::WebSandboxFlags::kPropagatesToAuxiliaryBrowsingContexts; |
Ehsan Karamad | 3940708 | 2019-02-19 23:38:19 | [diff] [blame] | 1012 | bool sandbox_propagates_to_auxilary_context = |
| 1013 | (opener_flags & inherit_flag) == inherit_flag; |
| 1014 | if (sandbox_propagates_to_auxilary_context) |
Charlie Hu | e1b77ac | 2019-12-13 21:30:17 | [diff] [blame] | 1015 | new_root->SetPendingFramePolicy({opener_flags, |
| 1016 | {} /* container_policy */, |
| 1017 | {} /* required_document_policy */}); |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 1018 | if (opener_flags == network::mojom::WebSandboxFlags::kNone || |
Ehsan Karamad | 3940708 | 2019-02-19 23:38:19 | [diff] [blame] | 1019 | sandbox_propagates_to_auxilary_context) { |
| 1020 | // TODO(ekaramad, iclelland): Do not propagate feature policies from non- |
| 1021 | // sandboxed disowned openers (rel=noopener). |
| 1022 | // If the current page is not sandboxed, or if the sandbox is to propagate |
| 1023 | // to the popups then opener's feature policy will apply to the new popup |
| 1024 | // as well. |
| 1025 | new_root->SetOpenerFeaturePolicyState( |
Ehsan Karamad | 34d1068 | 2019-02-26 20:55:04 | [diff] [blame] | 1026 | opener_rfh->feature_policy()->GetFeatureState()); |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 1027 | } |
arthursonzogni | 034bb9c | 2020-10-01 08:29:56 | [diff] [blame] | 1028 | |
| 1029 | new_root->SetInitialPopupURL(params.initial_popup_url); |
| 1030 | new_root->SetPopupCreatorOrigin(opener_rfh->GetLastCommittedOrigin()); |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 1031 | } |
| 1032 | |
mark a. foltz | ef394fce | 2017-10-21 09:11:02 | [diff] [blame] | 1033 | // Apply starting sandbox flags. |
Luna Lu | c3fdacdf | 2017-11-08 04:48:53 | [diff] [blame] | 1034 | blink::FramePolicy frame_policy(new_root->pending_frame_policy()); |
mark a. foltz | ef394fce | 2017-10-21 09:11:02 | [diff] [blame] | 1035 | frame_policy.sandbox_flags |= params.starting_sandbox_flags; |
| 1036 | new_root->SetPendingFramePolicy(frame_policy); |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 1037 | new_root->CommitFramePolicy(frame_policy); |
mark a. foltz | ef394fce | 2017-10-21 09:11:02 | [diff] [blame] | 1038 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 1039 | // This may be true even when opener is null, such as when opening blocked |
| 1040 | // popups. |
alexmos | 090fae8e | 2015-05-28 17:09:28 | [diff] [blame] | 1041 | if (params.created_with_opener) |
| 1042 | new_contents->created_with_opener_ = true; |
| 1043 | |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 1044 | WebContentsImpl* outer_web_contents = nullptr; |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 1045 | if (params.guest_delegate) { |
[email protected] | 83100cd | 2014-05-10 11:50:06 | [diff] [blame] | 1046 | // This makes |new_contents| act as a guest. |
| 1047 | // For more info, see comment above class BrowserPluginGuest. |
Albert J. Wong | c55cc64d | 2018-10-12 02:50:04 | [diff] [blame] | 1048 | BrowserPluginGuest::CreateInWebContents(new_contents.get(), |
| 1049 | params.guest_delegate); |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 1050 | outer_web_contents = static_cast<WebContentsImpl*>( |
| 1051 | params.guest_delegate->GetOwnerWebContents()); |
[email protected] | 83100cd | 2014-05-10 11:50:06 | [diff] [blame] | 1052 | } |
mark a. foltz | ef394fce | 2017-10-21 09:11:02 | [diff] [blame] | 1053 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 1054 | new_contents->Init(params); |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 1055 | if (outer_web_contents) |
| 1056 | outer_web_contents->InnerWebContentsCreated(new_contents.get()); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1057 | return new_contents; |
| 1058 | } |
| 1059 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1060 | // static |
| 1061 | std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1062 | OPTIONAL_TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 1063 | "WebContentsImpl::GetAllWebContents"); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1064 | std::vector<WebContentsImpl*> result; |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 1065 | std::unique_ptr<RenderWidgetHostIterator> widgets( |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1066 | RenderWidgetHostImpl::GetRenderWidgetHosts()); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1067 | while (RenderWidgetHost* rwh = widgets->GetNextHost()) { |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1068 | RenderViewHost* rvh = RenderViewHost::From(rwh); |
| 1069 | if (!rvh) |
| 1070 | continue; |
| 1071 | WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
| 1072 | if (!web_contents) |
| 1073 | continue; |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 1074 | if (web_contents->GetRenderViewHost() != rvh) |
| 1075 | continue; |
| 1076 | // Because a WebContents can only have one current RVH at a time, there will |
| 1077 | // be no duplicate WebContents here. |
| 1078 | result.push_back(static_cast<WebContentsImpl*>(web_contents)); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1079 | } |
| 1080 | return result; |
| 1081 | } |
| 1082 | |
clamy | a16aa817 | 2015-05-26 13:07:25 | [diff] [blame] | 1083 | // static |
| 1084 | WebContentsImpl* WebContentsImpl::FromFrameTreeNode( |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 1085 | const FrameTreeNode* frame_tree_node) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1086 | OPTIONAL_TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 1087 | "WebContentsImpl::FromFrameTreeNode", "frame_tree_node", |
| 1088 | frame_tree_node); |
clamy | a16aa817 | 2015-05-26 13:07:25 | [diff] [blame] | 1089 | return static_cast<WebContentsImpl*>( |
| 1090 | WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host())); |
| 1091 | } |
| 1092 | |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 1093 | // static |
Patrick Monette | 275a6f92b | 2020-01-09 21:05:04 | [diff] [blame] | 1094 | WebContents* WebContentsImpl::FromRenderFrameHostID( |
| 1095 | GlobalFrameRoutingId render_frame_host_id) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1096 | OPTIONAL_TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 1097 | "WebContentsImpl::FromRenderFrameHostID", "process_id", |
| 1098 | render_frame_host_id.child_id, "frame_id", |
| 1099 | render_frame_host_id.frame_routing_id); |
Patrick Monette | 275a6f92b | 2020-01-09 21:05:04 | [diff] [blame] | 1100 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 1101 | !BrowserThread::IsThreadInitialized(BrowserThread::UI)); |
Patrick Monette | 7364e697 | 2020-01-09 22:56:02 | [diff] [blame] | 1102 | RenderFrameHost* render_frame_host = |
| 1103 | RenderFrameHost::FromID(render_frame_host_id); |
| 1104 | if (!render_frame_host) |
| 1105 | return nullptr; |
| 1106 | |
| 1107 | return WebContents::FromRenderFrameHost(render_frame_host); |
Patrick Monette | 275a6f92b | 2020-01-09 21:05:04 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | // static |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 1111 | WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id, |
| 1112 | int render_frame_host_id) { |
Patrick Monette | 7364e697 | 2020-01-09 22:56:02 | [diff] [blame] | 1113 | return FromRenderFrameHostID( |
| 1114 | GlobalFrameRoutingId(render_process_host_id, render_frame_host_id)); |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 1115 | } |
| 1116 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 1117 | // static |
| 1118 | WebContentsImpl* WebContentsImpl::FromOuterFrameTreeNode( |
| 1119 | const FrameTreeNode* frame_tree_node) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1120 | OPTIONAL_TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 1121 | "WebContentsImpl::FromOuterFrameTreeNode", |
| 1122 | "frame_tree_node", frame_tree_node); |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 1123 | return WebContentsImpl::FromFrameTreeNode(frame_tree_node) |
| 1124 | ->node_.GetInnerWebContentsInFrame(frame_tree_node); |
| 1125 | } |
| 1126 | |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 1127 | RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1128 | return GetRenderManager(); |
[email protected] | 76518718 | 2012-01-11 23:59:28 | [diff] [blame] | 1129 | } |
| 1130 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 1131 | bool WebContentsImpl::OnMessageReceived(RenderViewHostImpl* render_view_host, |
[email protected] | 7bb76189 | 2012-07-20 09:32:47 | [diff] [blame] | 1132 | const IPC::Message& message) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1133 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnMessageReceived", |
| 1134 | "render_view_host", render_view_host); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 1135 | for (auto& observer : observers_.observer_list()) { |
Lukasz Anforowicz | 89f2c1b | 2017-08-30 21:36:46 | [diff] [blame] | 1136 | // TODO(nick, creis): https://crbug.com/758026: Replace all uses of this |
| 1137 | // variant of OnMessageReceived with the version that takes a |
| 1138 | // RenderFrameHost, and then delete it. |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 1139 | if (observer.OnMessageReceived(message)) |
| 1140 | return true; |
[email protected] | 64ffefa | 2014-05-10 12:06:33 | [diff] [blame] | 1141 | } |
[email protected] | 403415a | 2011-01-10 18:57:53 | [diff] [blame] | 1142 | |
Henrique Ferreiro | ba53547 | 2020-04-21 11:38:36 | [diff] [blame] | 1143 | return false; |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | bool WebContentsImpl::OnMessageReceived(RenderFrameHostImpl* render_frame_host, |
| 1147 | const IPC::Message& message) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1148 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnMessageReceived", |
| 1149 | "render_frame_host", |
| 1150 | base::trace_event::ToTracedValue(render_frame_host)); |
| 1151 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 1152 | for (auto& observer : observers_.observer_list()) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 1153 | if (observer.OnMessageReceived(message, render_frame_host)) |
| 1154 | return true; |
| 1155 | } |
| 1156 | |
| 1157 | bool handled = true; |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 1158 | #if BUILDFLAG(ENABLE_PLUGINS) |
Hiroki Nakagawa | 761b9b0 | 2020-07-13 11:12:02 | [diff] [blame] | 1159 | IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_frame_host) |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 1160 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated, |
| 1161 | OnPepperInstanceCreated) |
| 1162 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted, |
| 1163 | OnPepperInstanceDeleted) |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 1164 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 1165 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback, |
| 1166 | OnPepperStartsPlayback) |
| 1167 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback, |
| 1168 | OnPepperStopsPlayback) |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 1169 | IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed) |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1170 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | e44d134 | 2014-05-16 21:29:33 | [diff] [blame] | 1171 | IPC_END_MESSAGE_MAP() |
Hiroki Nakagawa | 761b9b0 | 2020-07-13 11:12:02 | [diff] [blame] | 1172 | #else |
| 1173 | handled = false; |
| 1174 | #endif |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1175 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1176 | return handled; |
| 1177 | } |
| 1178 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1179 | NavigationControllerImpl& WebContentsImpl::GetController() { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 1180 | return controller_; |
| 1181 | } |
| 1182 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1183 | BrowserContext* WebContentsImpl::GetBrowserContext() { |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 1184 | return controller_.GetBrowserContext(); |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 1185 | } |
| 1186 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1187 | const GURL& WebContentsImpl::GetURL() { |
Peter Boström | 101d767 | 2018-12-15 00:43:59 | [diff] [blame] | 1188 | return GetVisibleURL(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1189 | } |
| 1190 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1191 | const GURL& WebContentsImpl::GetVisibleURL() { |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 1192 | // We may not have a navigation entry yet. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1193 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 1194 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
| 1195 | } |
| 1196 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1197 | const GURL& WebContentsImpl::GetLastCommittedURL() { |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 1198 | // We may not have a navigation entry yet. |
| 1199 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
| 1200 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
| 1201 | } |
| 1202 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1203 | WebContentsDelegate* WebContentsImpl::GetDelegate() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1204 | return delegate_; |
| 1205 | } |
| 1206 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1207 | void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1208 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::SetDelegate", "delegate", |
| 1209 | delegate); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1210 | // TODO(cbentzel): remove this debugging code? |
| 1211 | if (delegate == delegate_) |
| 1212 | return; |
| 1213 | if (delegate_) |
| 1214 | delegate_->Detach(this); |
| 1215 | delegate_ = delegate; |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 1216 | if (delegate_) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1217 | delegate_->Attach(this); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 1218 | // Ensure the visible RVH reflects the new delegate's preferences. |
[email protected] | 86f98a2 | 2013-03-20 14:35:00 | [diff] [blame] | 1219 | if (view_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 1220 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
Joel Einbinder | 848001c | 2017-09-19 21:39:31 | [diff] [blame] | 1221 | if (GetRenderViewHost()) |
| 1222 | RenderFrameDevToolsAgentHost::WebContentsCreated(this); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 1223 | } |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1224 | } |
| 1225 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1226 | RenderFrameHostImpl* WebContentsImpl::GetMainFrame() { |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 1227 | return frame_tree_.root()->current_frame_host(); |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 1228 | } |
| 1229 | |
nick | 53d5cbf | 2015-04-23 22:50:14 | [diff] [blame] | 1230 | RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() { |
| 1231 | FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame(); |
| 1232 | if (!focused_node) |
| 1233 | return nullptr; |
| 1234 | return focused_node->current_frame_host(); |
[email protected] | 9c9343b | 2014-03-08 02:56:07 | [diff] [blame] | 1235 | } |
| 1236 | |
rob | 3e2a073 | 2016-01-06 21:22:09 | [diff] [blame] | 1237 | RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId( |
creis | f71a263 | 2017-05-04 19:03:50 | [diff] [blame] | 1238 | int frame_tree_node_id, |
| 1239 | int process_id) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1240 | OPTIONAL_TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 1241 | "WebContentsImpl::FindFrameByFrameTreeNodeId", |
| 1242 | "frame_tree_node_id", frame_tree_node_id, "process_id", |
| 1243 | process_id); |
creis | f71a263 | 2017-05-04 19:03:50 | [diff] [blame] | 1244 | FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id); |
| 1245 | |
| 1246 | // Sanity check that this is in the caller's expected process. Otherwise a |
| 1247 | // recent cross-process navigation may have led to a privilege change that the |
| 1248 | // caller is not expecting. |
| 1249 | if (!frame || |
| 1250 | frame->current_frame_host()->GetProcess()->GetID() != process_id) |
| 1251 | return nullptr; |
| 1252 | |
| 1253 | return frame->current_frame_host(); |
| 1254 | } |
| 1255 | |
| 1256 | RenderFrameHostImpl* WebContentsImpl::UnsafeFindFrameByFrameTreeNodeId( |
rob | 3e2a073 | 2016-01-06 21:22:09 | [diff] [blame] | 1257 | int frame_tree_node_id) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1258 | OPTIONAL_TRACE_EVENT1("content", |
| 1259 | "WebContentsImpl::UnsafeFindFrameByFrameTreeNodeId", |
| 1260 | "frame_tree_node_id", frame_tree_node_id); |
creis | f71a263 | 2017-05-04 19:03:50 | [diff] [blame] | 1261 | // Beware using this! The RenderFrameHost may have changed since the caller |
| 1262 | // obtained frame_tree_node_id. |
rob | 3e2a073 | 2016-01-06 21:22:09 | [diff] [blame] | 1263 | FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id); |
| 1264 | return frame ? frame->current_frame_host() : nullptr; |
| 1265 | } |
| 1266 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 1267 | void WebContentsImpl::ForEachFrame( |
Lei Zhang | ebcc630 | 2018-01-12 19:46:45 | [diff] [blame] | 1268 | const base::RepeatingCallback<void(RenderFrameHost*)>& on_frame) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1269 | OPTIONAL_TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 1270 | "WebContentsImpl::ForEachFrame"); |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1271 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 1272 | on_frame.Run(node->current_frame_host()); |
| 1273 | } |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 1274 | } |
| 1275 | |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1276 | std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() { |
Xuehui Xie | b2300ae4 | 2020-06-09 20:25:05 | [diff] [blame] | 1277 | return GetAllFramesImpl(frame_tree_, /*include_pending=*/false); |
| 1278 | } |
| 1279 | |
| 1280 | std::vector<RenderFrameHost*> WebContentsImpl::GetAllFramesIncludingPending() { |
| 1281 | return GetAllFramesImpl(frame_tree_, /*include_pending=*/true); |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1282 | } |
| 1283 | |
lukasza | cbdf52e | 2016-01-15 21:19:51 | [diff] [blame] | 1284 | int WebContentsImpl::SendToAllFrames(IPC::Message* message) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1285 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::SendToAllFrames"); |
Xuehui Xie | b2300ae4 | 2020-06-09 20:25:05 | [diff] [blame] | 1286 | return SendToAllFramesImpl(frame_tree_, /*include_pending=*/false, message); |
| 1287 | } |
lukasza | 1a9ab242 | 2016-03-02 18:47:25 | [diff] [blame] | 1288 | |
Xuehui Xie | b2300ae4 | 2020-06-09 20:25:05 | [diff] [blame] | 1289 | int WebContentsImpl::SendToAllFramesIncludingPending(IPC::Message* message) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1290 | OPTIONAL_TRACE_EVENT0("content", |
| 1291 | "WebContentsImpl::SentToAllFramesIncludingPending"); |
Xuehui Xie | b2300ae4 | 2020-06-09 20:25:05 | [diff] [blame] | 1292 | return SendToAllFramesImpl(frame_tree_, /*include_pending=*/true, message); |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 1293 | } |
| 1294 | |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 1295 | void WebContentsImpl::SendPageMessage(IPC::Message* msg) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1296 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::SendPageMessage"); |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 1297 | frame_tree_.root()->render_manager()->SendPageMessage(msg, nullptr); |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 1298 | } |
| 1299 | |
Gyuyoung Kim | 877e86d | 2020-07-21 04:01:02 | [diff] [blame] | 1300 | void WebContentsImpl::ExecutePageBroadcastMethod( |
| 1301 | PageBroadcastMethodCallback callback) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1302 | OPTIONAL_TRACE_EVENT0("content", |
| 1303 | "WebContentsImpl::ExecutePageBroadcastMethod"); |
Gyuyoung Kim | 877e86d | 2020-07-21 04:01:02 | [diff] [blame] | 1304 | frame_tree_.root()->render_manager()->ExecutePageBroadcastMethod(callback); |
| 1305 | } |
| 1306 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1307 | RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1308 | return GetRenderManager()->current_host(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1309 | } |
| 1310 | |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 1311 | void WebContentsImpl::CancelActiveAndPendingDialogs() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1312 | OPTIONAL_TRACE_EVENT0("content", |
| 1313 | "WebContentsImpl::CancelActiveAndPendingDialogs"); |
Evan Stade | 753fc20 | 2020-07-13 18:09:54 | [diff] [blame] | 1314 | if (dialog_manager_) { |
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 1315 | dialog_manager_->CancelDialogs(this, /*reset_state=*/false); |
Evan Stade | 753fc20 | 2020-07-13 18:09:54 | [diff] [blame] | 1316 | } |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 1317 | if (browser_plugin_embedder_) |
| 1318 | browser_plugin_embedder_->CancelGuestDialogs(); |
| 1319 | } |
| 1320 | |
nasko | c0fceff | 2015-04-30 15:53:52 | [diff] [blame] | 1321 | void WebContentsImpl::ClosePage() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1322 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::ClosePage"); |
nasko | c0fceff | 2015-04-30 15:53:52 | [diff] [blame] | 1323 | GetRenderViewHost()->ClosePage(); |
| 1324 | } |
| 1325 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1326 | RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1327 | return GetRenderManager()->GetRenderWidgetHostView(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1328 | } |
| 1329 | |
lfg | 265a267 | 2016-04-23 03:11:02 | [diff] [blame] | 1330 | RenderWidgetHostView* WebContentsImpl::GetTopLevelRenderWidgetHostView() { |
| 1331 | if (GetOuterWebContents()) |
| 1332 | return GetOuterWebContents()->GetTopLevelRenderWidgetHostView(); |
| 1333 | return GetRenderManager()->GetRenderWidgetHostView(); |
| 1334 | } |
| 1335 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1336 | WebContentsView* WebContentsImpl::GetView() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1337 | return view_.get(); |
| 1338 | } |
| 1339 | |
Mike Wasserman | 5a3cc61d | 2020-08-27 21:12:03 | [diff] [blame] | 1340 | void WebContentsImpl::OnScreensChange(bool is_multi_screen_changed) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1341 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnScreensChange", |
| 1342 | "is_multi_screen_changed", is_multi_screen_changed); |
Mike Wasserman | db8f4f0 | 2020-10-06 01:18:37 | [diff] [blame] | 1343 | // Allow fullscreen requests shortly after user-generated screens changes. |
| 1344 | transient_allow_fullscreen_.Activate(); |
Mike Wasserman | 5a3cc61d | 2020-08-27 21:12:03 | [diff] [blame] | 1345 | // Send |is_multi_screen_changed| events to all visible frames, but limit |
| 1346 | // other events to frames with the Window Placement permission. This obviates |
| 1347 | // the most pressing need for sites to poll isMultiScreen(), which is exposed |
| 1348 | // without explicit permission, while also protecting privacy. |
| 1349 | // TODO(crbug.com/1109989): Postpone events; refine utility/privacy balance. |
Mike Wasserman | b213b935 | 2020-04-16 00:32:34 | [diff] [blame] | 1350 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 1351 | RenderFrameHostImpl* rfh = node->current_frame_host(); |
Mike Wasserman | 5a3cc61d | 2020-08-27 21:12:03 | [diff] [blame] | 1352 | if ((is_multi_screen_changed && |
| 1353 | rfh->GetVisibilityState() == PageVisibilityState::kVisible) || |
Mike Wasserman | db8f4f0 | 2020-10-06 01:18:37 | [diff] [blame] | 1354 | IsWindowPlacementGranted(rfh)) { |
Mike Wasserman | 5a3cc61d | 2020-08-27 21:12:03 | [diff] [blame] | 1355 | rfh->GetAssociatedLocalFrame()->OnScreensChange(); |
| 1356 | } |
Mike Wasserman | b213b935 | 2020-04-16 00:32:34 | [diff] [blame] | 1357 | } |
| 1358 | } |
| 1359 | |
leon.han | 552e9de | 2017-02-09 14:37:30 | [diff] [blame] | 1360 | void WebContentsImpl::OnScreenOrientationChange() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1361 | OPTIONAL_TRACE_EVENT0("content", |
| 1362 | "WebContentsImpl::OnScreenOrientationChange"); |
leon.han | 552e9de | 2017-02-09 14:37:30 | [diff] [blame] | 1363 | DCHECK(screen_orientation_provider_); |
Lan Wei | f81c6e7c | 2020-02-12 16:46:09 | [diff] [blame] | 1364 | DidChangeScreenOrientation(); |
Becca Hughes | e9e2795 | 2018-06-25 17:08:27 | [diff] [blame] | 1365 | screen_orientation_provider_->OnOrientationChange(); |
leon.han | e4db177a | 2017-02-07 14:19:16 | [diff] [blame] | 1366 | } |
| 1367 | |
Alan Cutter | 92d5925 | 2019-03-29 02:32:33 | [diff] [blame] | 1368 | base::Optional<SkColor> WebContentsImpl::GetThemeColor() { |
Carlos Caballero | 1215f88 | 2019-10-29 15:58:43 | [diff] [blame] | 1369 | return GetRenderViewHost()->theme_color(); |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 1370 | } |
| 1371 | |
Alan Cutter | d73a15d9 | 2020-08-21 07:12:45 | [diff] [blame] | 1372 | base::Optional<SkColor> WebContentsImpl::GetBackgroundColor() { |
| 1373 | return GetRenderViewHost()->background_color(); |
| 1374 | } |
| 1375 | |
Doug Turner | 63f3c7b | 2017-07-29 05:10:01 | [diff] [blame] | 1376 | void WebContentsImpl::SetAccessibilityMode(ui::AXMode mode) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1377 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::SetAccessibilityMode", |
| 1378 | "mode", mode.ToString(), "previous_mode", |
| 1379 | accessibility_mode_.ToString()); |
| 1380 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1381 | if (mode == accessibility_mode_) |
| 1382 | return; |
| 1383 | |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 1384 | // Don't allow accessibility to be enabled for WebContents that are never |
danakj | 77eb7e8 | 2020-01-09 19:38:46 | [diff] [blame] | 1385 | // user-visible, like background pages. |
| 1386 | if (IsNeverComposited()) |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 1387 | return; |
| 1388 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1389 | accessibility_mode_ = mode; |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1390 | |
| 1391 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 1392 | UpdateAccessibilityModeOnFrame(node->current_frame_host()); |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 1393 | // Also update accessibility mode on the speculative RenderFrameHost for |
| 1394 | // this FrameTreeNode, if one exists. |
Alex Moshchuk | 3d8a1f39 | 2017-10-24 19:01:26 | [diff] [blame] | 1395 | RenderFrameHost* speculative_frame_host = |
| 1396 | node->render_manager()->speculative_frame_host(); |
| 1397 | if (speculative_frame_host) |
| 1398 | UpdateAccessibilityModeOnFrame(speculative_frame_host); |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1399 | } |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1400 | } |
| 1401 | |
Doug Turner | 63f3c7b | 2017-07-29 05:10:01 | [diff] [blame] | 1402 | void WebContentsImpl::AddAccessibilityMode(ui::AXMode mode) { |
| 1403 | ui::AXMode new_mode(accessibility_mode_); |
dougt | cd3dad73 | 2017-03-14 03:26:23 | [diff] [blame] | 1404 | new_mode |= mode; |
| 1405 | SetAccessibilityMode(new_mode); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1406 | } |
| 1407 | |
Avi Drissman | 1e620f3 | 2018-03-16 13:57:29 | [diff] [blame] | 1408 | // Helper class used by WebContentsImpl::RequestAXTreeSnapshot. |
| 1409 | // Handles the callbacks from parallel snapshot requests to each frame, |
| 1410 | // and feeds the results to an AXTreeCombiner, which converts them into a |
| 1411 | // single combined accessibility tree. |
| 1412 | class WebContentsImpl::AXTreeSnapshotCombiner |
| 1413 | : public base::RefCounted<AXTreeSnapshotCombiner> { |
| 1414 | public: |
| 1415 | explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback) |
| 1416 | : callback_(std::move(callback)) {} |
| 1417 | |
| 1418 | AXTreeSnapshotCallback AddFrame(bool is_root) { |
| 1419 | // Adds a reference to |this|. |
| 1420 | return base::BindOnce(&AXTreeSnapshotCombiner::ReceiveSnapshot, this, |
| 1421 | is_root); |
| 1422 | } |
| 1423 | |
| 1424 | void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) { |
| 1425 | combiner_.AddTree(snapshot, is_root); |
| 1426 | } |
| 1427 | |
| 1428 | private: |
| 1429 | friend class base::RefCounted<AXTreeSnapshotCombiner>; |
| 1430 | |
| 1431 | // This is called automatically after the last call to ReceiveSnapshot |
| 1432 | // when there are no more references to this object. |
| 1433 | ~AXTreeSnapshotCombiner() { |
| 1434 | combiner_.Combine(); |
| 1435 | std::move(callback_).Run(combiner_.combined()); |
| 1436 | } |
| 1437 | |
| 1438 | ui::AXTreeCombiner combiner_; |
| 1439 | AXTreeSnapshotCallback callback_; |
| 1440 | }; |
| 1441 | |
| 1442 | void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback, |
| 1443 | ui::AXMode ax_mode) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1444 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::RequestAXTreeSnapshot", |
| 1445 | "mode", ax_mode.ToString()); |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 1446 | // Send a request to each of the frames in parallel. Each one will return |
| 1447 | // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine |
| 1448 | // them into a single tree and call |callback| with that result, then |
| 1449 | // delete |combiner|. |
Avi Drissman | 1e620f3 | 2018-03-16 13:57:29 | [diff] [blame] | 1450 | FrameTreeNode* root_node = frame_tree_.root(); |
tzik | 58faa74 | 2018-08-01 10:54:18 | [diff] [blame] | 1451 | auto combiner = |
| 1452 | base::MakeRefCounted<AXTreeSnapshotCombiner>(std::move(callback)); |
Avi Drissman | 1e620f3 | 2018-03-16 13:57:29 | [diff] [blame] | 1453 | |
tzik | 58faa74 | 2018-08-01 10:54:18 | [diff] [blame] | 1454 | RecursiveRequestAXTreeSnapshotOnFrame(root_node, combiner.get(), ax_mode); |
Avi Drissman | 1e620f3 | 2018-03-16 13:57:29 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | void WebContentsImpl::RecursiveRequestAXTreeSnapshotOnFrame( |
| 1458 | FrameTreeNode* root_node, |
| 1459 | AXTreeSnapshotCombiner* combiner, |
| 1460 | ui::AXMode ax_mode) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1461 | OPTIONAL_TRACE_EVENT0( |
| 1462 | "content", "WebContentsImpl::RecursiveRequestAXTreeSnapshotOnFrame"); |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 1463 | for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) { |
Avi Drissman | 1e620f3 | 2018-03-16 13:57:29 | [diff] [blame] | 1464 | WebContentsImpl* inner_contents = |
| 1465 | node_.GetInnerWebContentsInFrame(frame_tree_node); |
| 1466 | if (inner_contents) { |
| 1467 | inner_contents->RecursiveRequestAXTreeSnapshotOnFrame(root_node, combiner, |
| 1468 | ax_mode); |
| 1469 | } else { |
| 1470 | bool is_root = frame_tree_node == root_node; |
| 1471 | frame_tree_node->current_frame_host()->RequestAXTreeSnapshot( |
| 1472 | combiner->AddFrame(is_root), ax_mode); |
| 1473 | } |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 1474 | } |
dmazzoni | 83ba5c8 | 2015-04-14 07:11:51 | [diff] [blame] | 1475 | } |
| 1476 | |
Becca Hughes | 3b5a4348 | 2018-07-17 22:31:55 | [diff] [blame] | 1477 | void WebContentsImpl::NotifyViewportFitChanged( |
| 1478 | blink::mojom::ViewportFit value) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1479 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::NotifyViewportFitChanged", |
| 1480 | "value", static_cast<int>(value)); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 1481 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 1482 | observer->ViewportFitChanged(value); |
| 1483 | }); |
Becca Hughes | 3b5a4348 | 2018-07-17 22:31:55 | [diff] [blame] | 1484 | } |
| 1485 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1486 | FindRequestManager* WebContentsImpl::GetFindRequestManagerForTesting() { |
Ehsan Karamad | 6beb2ea | 2018-11-25 18:15:13 | [diff] [blame] | 1487 | return GetFindRequestManager(); |
| 1488 | } |
| 1489 | |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 1490 | #if !defined(OS_ANDROID) |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 1491 | void WebContentsImpl::UpdateZoom() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1492 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::UpdateZoom"); |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 1493 | RenderWidgetHostImpl* rwh = GetRenderViewHost()->GetWidget(); |
| 1494 | if (rwh->GetView()) |
| 1495 | rwh->SynchronizeVisualProperties(); |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1496 | } |
| 1497 | |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1498 | |
| 1499 | void WebContentsImpl::UpdateZoomIfNecessary(const std::string& scheme, |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 1500 | const std::string& host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1501 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::UpdateZoomIfNecessary", |
| 1502 | "scheme", scheme, "host", host); |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1503 | NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
| 1504 | if (!entry) |
| 1505 | return; |
| 1506 | |
| 1507 | GURL url = HostZoomMap::GetURLFromEntry(entry); |
| 1508 | if (host != net::GetHostOrSpecFromURL(url) || |
| 1509 | (!scheme.empty() && !url.SchemeIs(scheme))) { |
| 1510 | return; |
| 1511 | } |
| 1512 | |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 1513 | UpdateZoom(); |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1514 | } |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 1515 | #endif // !defined(OS_ANDROID) |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1516 | |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 1517 | base::OnceClosure WebContentsImpl::AddReceiverSet( |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 1518 | const std::string& interface_name, |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 1519 | WebContentsReceiverSet* receiver_set) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1520 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::AddReceiverSet", |
| 1521 | "interface_name", interface_name); |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 1522 | auto result = |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 1523 | receiver_sets_.insert(std::make_pair(interface_name, receiver_set)); |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 1524 | DCHECK(result.second); |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 1525 | return base::BindOnce(&WebContentsImpl::RemoveReceiverSet, |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame] | 1526 | weak_factory_.GetWeakPtr(), interface_name); |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 1527 | } |
| 1528 | |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 1529 | WebContentsReceiverSet* WebContentsImpl::GetReceiverSet( |
rockot | 8bbad22 | 2017-03-22 04:34:05 | [diff] [blame] | 1530 | const std::string& interface_name) { |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 1531 | auto it = receiver_sets_.find(interface_name); |
| 1532 | if (it == receiver_sets_.end()) |
rockot | 8bbad22 | 2017-03-22 04:34:05 | [diff] [blame] | 1533 | return nullptr; |
| 1534 | return it->second; |
| 1535 | } |
| 1536 | |
John Delaney | 732721e9 | 2020-02-07 23:11:27 | [diff] [blame] | 1537 | void WebContentsImpl::RemoveReceiverSetForTesting( |
| 1538 | const std::string& interface_name) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1539 | OPTIONAL_TRACE_EVENT1("content", |
| 1540 | "WebContentsImpl::RemoveReceiverSetForTesting", |
| 1541 | "interface_name", interface_name); |
John Delaney | 732721e9 | 2020-02-07 23:11:27 | [diff] [blame] | 1542 | RemoveReceiverSet(interface_name); |
| 1543 | } |
| 1544 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 1545 | std::vector<WebContentsImpl*> WebContentsImpl::GetWebContentsAndAllInner() { |
| 1546 | std::vector<WebContentsImpl*> all_contents(1, this); |
| 1547 | |
| 1548 | for (size_t i = 0; i != all_contents.size(); ++i) { |
| 1549 | for (auto* inner_contents : all_contents[i]->GetInnerWebContents()) { |
Lucas Furukawa Gadani | 2ec00c8 | 2018-12-14 15:53:16 | [diff] [blame] | 1550 | all_contents.push_back(static_cast<WebContentsImpl*>(inner_contents)); |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | return all_contents; |
| 1555 | } |
| 1556 | |
Sam McNally | 145fb17 | 2017-05-10 00:13:23 | [diff] [blame] | 1557 | void WebContentsImpl::NotifyManifestUrlChanged( |
Yuzu Saijo | 0c263c70 | 2020-06-08 03:41:24 | [diff] [blame] | 1558 | RenderFrameHost* rfh, |
Sam McNally | 145fb17 | 2017-05-10 00:13:23 | [diff] [blame] | 1559 | const base::Optional<GURL>& manifest_url) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1560 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::NotifyManifestUrlChanged", |
| 1561 | "render_frame_host", |
| 1562 | base::trace_event::ToTracedValue(rfh), "manifest_url", |
| 1563 | base::trace_event::ValueToString(manifest_url)); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 1564 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 1565 | observer->DidUpdateWebManifestURL(rfh, manifest_url); |
| 1566 | }); |
Sam McNally | 145fb17 | 2017-05-10 00:13:23 | [diff] [blame] | 1567 | } |
| 1568 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1569 | WebUI* WebContentsImpl::GetWebUI() { |
Nasko Oskov | 2f7d211 | 2019-10-29 03:26:57 | [diff] [blame] | 1570 | WebUI* committed_web_ui = GetCommittedWebUI(); |
| 1571 | if (committed_web_ui) |
| 1572 | return committed_web_ui; |
| 1573 | |
| 1574 | if (GetRenderManager()->speculative_frame_host()) |
| 1575 | return GetRenderManager()->speculative_frame_host()->web_ui(); |
| 1576 | |
| 1577 | return nullptr; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1578 | } |
| 1579 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1580 | WebUI* WebContentsImpl::GetCommittedWebUI() { |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 1581 | return frame_tree_.root()->current_frame_host()->web_ui(); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1582 | } |
| 1583 | |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 1584 | void WebContentsImpl::SetUserAgentOverride( |
| 1585 | const blink::UserAgentOverride& ua_override, |
| 1586 | bool override_in_new_tabs) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1587 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::SetUserAgentOverride", |
| 1588 | "ua_override", ua_override.ua_string_override, |
| 1589 | "override_in_new_tabs", override_in_new_tabs); |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 1590 | DCHECK(!ua_override.ua_metadata_override.has_value() || |
| 1591 | !ua_override.ua_string_override.empty()); |
| 1592 | |
| 1593 | if (GetUserAgentOverride() == ua_override) |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1594 | return; |
| 1595 | |
Changwan Ryu | c1134a8 | 2018-03-07 02:10:14 | [diff] [blame] | 1596 | should_override_user_agent_in_new_tabs_ = override_in_new_tabs; |
| 1597 | |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 1598 | renderer_preferences_.user_agent_override = ua_override; |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1599 | |
Bruce Long | 1e3e1f54 | 2019-10-16 17:56:28 | [diff] [blame] | 1600 | // Send the new override string to all renderers in the current page. |
| 1601 | SyncRendererPrefs(); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1602 | |
| 1603 | // Reload the page if a load is currently in progress to avoid having |
| 1604 | // different parts of the page loaded using different user agents. |
Scott Violet | e1d58cc | 2020-04-28 23:07:17 | [diff] [blame] | 1605 | // No need to reload if the current entry matches that of the |
| 1606 | // NavigationRequest supplied to DidStartNavigation() as NavigationRequest |
| 1607 | // handles it. |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 1608 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
Scott Violet | e1d58cc | 2020-04-28 23:07:17 | [diff] [blame] | 1609 | if (IsLoading() && entry != nullptr && entry->GetIsOverridingUserAgent() && |
| 1610 | (!frame_tree_.root()->navigation_request() || |
| 1611 | frame_tree_.root()->navigation_request()->ua_change_requires_reload())) { |
toyoshim | 6142d96f | 2016-12-19 09:07:25 | [diff] [blame] | 1612 | controller_.Reload(ReloadType::BYPASSING_CACHE, true); |
Scott Violet | e1d58cc | 2020-04-28 23:07:17 | [diff] [blame] | 1613 | } |
[email protected] | 8d0f331 | 2012-08-18 01:47:53 | [diff] [blame] | 1614 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 1615 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 1616 | observer->UserAgentOverrideSet(ua_override); |
| 1617 | }); |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 1618 | } |
| 1619 | |
Scott Violet | 2a6c5bff | 2020-04-29 23:59:06 | [diff] [blame] | 1620 | void WebContentsImpl::SetRendererInitiatedUserAgentOverrideOption( |
| 1621 | NavigationController::UserAgentOverrideOption option) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1622 | OPTIONAL_TRACE_EVENT0( |
| 1623 | "content", |
| 1624 | "WebContentsImpl::SetRendererInitiatedUserAgentOverrideOption"); |
Scott Violet | 2a6c5bff | 2020-04-29 23:59:06 | [diff] [blame] | 1625 | renderer_initiated_user_agent_override_option_ = option; |
| 1626 | } |
| 1627 | |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 1628 | const blink::UserAgentOverride& WebContentsImpl::GetUserAgentOverride() { |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1629 | return renderer_preferences_.user_agent_override; |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 1630 | } |
| 1631 | |
Scott Violet | 2a6c5bff | 2020-04-29 23:59:06 | [diff] [blame] | 1632 | bool WebContentsImpl::ShouldOverrideUserAgentForRendererInitiatedNavigation() { |
| 1633 | NavigationEntryImpl* current_entry = controller_.GetLastCommittedEntry(); |
| 1634 | if (!current_entry) |
| 1635 | return should_override_user_agent_in_new_tabs_; |
| 1636 | |
| 1637 | switch (renderer_initiated_user_agent_override_option_) { |
| 1638 | case NavigationController::UA_OVERRIDE_INHERIT: |
| 1639 | return current_entry->GetIsOverridingUserAgent(); |
| 1640 | case NavigationController::UA_OVERRIDE_TRUE: |
| 1641 | return true; |
| 1642 | case NavigationController::UA_OVERRIDE_FALSE: |
| 1643 | return false; |
| 1644 | default: |
| 1645 | break; |
| 1646 | } |
| 1647 | return false; |
Changwan Ryu | c1134a8 | 2018-03-07 02:10:14 | [diff] [blame] | 1648 | } |
| 1649 | |
dmazzoni | dd3d51a7 | 2016-12-14 18:41:01 | [diff] [blame] | 1650 | void WebContentsImpl::EnableWebContentsOnlyAccessibilityMode() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1651 | OPTIONAL_TRACE_EVENT0( |
| 1652 | "content", "WebContentsImpl::EnableWebContentsOnlyAccessibilityMode"); |
Dominic Mazzoni | d9fda17 | 2019-03-07 17:12:07 | [diff] [blame] | 1653 | // If accessibility is already enabled, we'll need to force a reset |
| 1654 | // in order to ensure new observers of accessibility events get the |
| 1655 | // full accessibility tree from scratch. |
| 1656 | bool need_reset = GetAccessibilityMode().has_mode(ui::AXMode::kWebContents); |
| 1657 | |
| 1658 | ui::AXMode desired_mode = |
| 1659 | GetContentClient()->browser()->GetAXModeForBrowserContext( |
| 1660 | GetBrowserContext()); |
| 1661 | desired_mode |= ui::kAXModeWebContentsOnly; |
| 1662 | AddAccessibilityMode(desired_mode); |
| 1663 | |
| 1664 | if (need_reset) { |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1665 | for (RenderFrameHost* rfh : GetAllFrames()) |
| 1666 | ResetAccessibility(rfh); |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1667 | } |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1668 | } |
| 1669 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1670 | bool WebContentsImpl::IsWebContentsOnlyAccessibilityModeForTesting() { |
Doug Turner | 63f3c7b | 2017-07-29 05:10:01 | [diff] [blame] | 1671 | return accessibility_mode_ == ui::kAXModeWebContentsOnly; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1672 | } |
| 1673 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1674 | bool WebContentsImpl::IsFullAccessibilityModeForTesting() { |
Doug Turner | 63f3c7b | 2017-07-29 05:10:01 | [diff] [blame] | 1675 | return accessibility_mode_ == ui::kAXModeComplete; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1676 | } |
| 1677 | |
Becca Hughes | 6daf566 | 2018-06-27 16:50:54 | [diff] [blame] | 1678 | #if defined(OS_ANDROID) |
| 1679 | |
| 1680 | void WebContentsImpl::SetDisplayCutoutSafeArea(gfx::Insets insets) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1681 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::SetDisplayCutoutSafeArea"); |
Becca Hughes | 8633462 | 2018-07-09 21:29:38 | [diff] [blame] | 1682 | if (display_cutout_host_impl_) |
| 1683 | display_cutout_host_impl_->SetDisplayCutoutSafeArea(insets); |
Becca Hughes | 6daf566 | 2018-06-27 16:50:54 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | #endif |
| 1687 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1688 | const base::string16& WebContentsImpl::GetTitle() { |
Nasko Oskov | 2f7d211 | 2019-10-29 03:26:57 | [diff] [blame] | 1689 | WebUI* our_web_ui = |
| 1690 | GetRenderManager()->speculative_frame_host() |
| 1691 | ? GetRenderManager()->speculative_frame_host()->web_ui() |
| 1692 | : GetRenderManager()->current_frame_host()->web_ui(); |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 1693 | if (our_web_ui) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1694 | // Don't override the title in view source mode. |
Carlos IL | 4dea890 | 2020-05-26 15:14:29 | [diff] [blame] | 1695 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1696 | if (!(entry && entry->IsViewSourceMode())) { |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 1697 | // Give the Web UI the chance to override our title. |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1698 | const base::string16& title = our_web_ui->GetOverriddenTitle(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1699 | if (!title.empty()) |
| 1700 | return title; |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | // We use the title for the last committed entry rather than a pending |
| 1705 | // navigation entry. For example, when the user types in a URL, we want to |
| 1706 | // keep the old page's title until the new load has committed and we get a new |
| 1707 | // title. |
Carlos IL | 4dea890 | 2020-05-26 15:14:29 | [diff] [blame] | 1708 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1709 | |
creis | 072b61f | 2015-09-28 20:52:24 | [diff] [blame] | 1710 | // We make an exception for initial navigations. We only want to use the title |
| 1711 | // from the visible entry if: |
| 1712 | // 1. The pending entry has been explicitly assigned a title to display. |
| 1713 | // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back), |
| 1714 | // which case there is a pending entry index other than -1. |
| 1715 | // |
| 1716 | // Otherwise, we want to stick with the last committed entry's title during |
| 1717 | // new navigations, which have pending entries at index -1 with no title. |
| 1718 | if (controller_.IsInitialNavigation() && |
| 1719 | ((controller_.GetVisibleEntry() && |
| 1720 | !controller_.GetVisibleEntry()->GetTitle().empty()) || |
| 1721 | controller_.GetPendingEntryIndex() != -1)) { |
| 1722 | entry = controller_.GetVisibleEntry(); |
[email protected] | 9eeafc01 | 2013-11-25 23:49:47 | [diff] [blame] | 1723 | } |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1724 | |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 1725 | if (entry) { |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame] | 1726 | return entry->GetTitleForDisplay(); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 1727 | } |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 1728 | |
| 1729 | // |page_title_when_no_navigation_entry_| is finally used |
| 1730 | // if no title cannot be retrieved. |
| 1731 | return page_title_when_no_navigation_entry_; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1732 | } |
| 1733 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1734 | SiteInstanceImpl* WebContentsImpl::GetSiteInstance() { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1735 | return GetRenderManager()->current_host()->GetSiteInstance(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1736 | } |
| 1737 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1738 | bool WebContentsImpl::IsLoading() { |
Carlos IL | d51e770 | 2020-05-07 18:51:39 | [diff] [blame] | 1739 | return frame_tree_.IsLoading(); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1740 | } |
| 1741 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1742 | double WebContentsImpl::GetLoadProgress() { |
Peter Boström | 18a40fa | 2018-10-31 19:03:50 | [diff] [blame] | 1743 | return frame_tree_.load_progress(); |
| 1744 | } |
| 1745 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1746 | bool WebContentsImpl::IsLoadingToDifferentDocument() { |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 1747 | return IsLoading() && is_load_to_different_document_; |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 1748 | } |
| 1749 | |
Alexander Timin | dd0fa0c5 | 2019-11-06 13:03:37 | [diff] [blame] | 1750 | bool WebContentsImpl::IsDocumentOnLoadCompletedInMainFrame() { |
| 1751 | return GetRenderViewHost()->IsDocumentOnLoadCompletedInMainFrame(); |
| 1752 | } |
| 1753 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1754 | bool WebContentsImpl::IsWaitingForResponse() { |
Peter Boström | a9a27f6e | 2018-11-21 13:12:19 | [diff] [blame] | 1755 | NavigationRequest* ongoing_navigation_request = |
| 1756 | frame_tree_.root()->navigation_request(); |
| 1757 | |
| 1758 | // An ongoing navigation request means we're waiting for a response. |
| 1759 | return ongoing_navigation_request != nullptr; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1760 | } |
| 1761 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1762 | const net::LoadStateWithParam& WebContentsImpl::GetLoadState() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1763 | return load_state_; |
| 1764 | } |
| 1765 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1766 | const base::string16& WebContentsImpl::GetLoadStateHost() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1767 | return load_state_host_; |
| 1768 | } |
| 1769 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1770 | uint64_t WebContentsImpl::GetUploadSize() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1771 | return upload_size_; |
| 1772 | } |
| 1773 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1774 | uint64_t WebContentsImpl::GetUploadPosition() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1775 | return upload_position_; |
| 1776 | } |
| 1777 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1778 | const std::string& WebContentsImpl::GetEncoding() { |
Alexander Timin | e5f20e2 | 2019-10-09 23:22:35 | [diff] [blame] | 1779 | return GetMainFrame()->GetEncoding(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1780 | } |
| 1781 | |
Charles Zhao | d72f99d | 2018-09-17 14:18:27 | [diff] [blame] | 1782 | bool WebContentsImpl::WasDiscarded() { |
| 1783 | return GetFrameTree()->root()->was_discarded(); |
| 1784 | } |
| 1785 | |
Shubhie Panicker | ddf2a4e | 2018-03-06 00:09:06 | [diff] [blame] | 1786 | void WebContentsImpl::SetWasDiscarded(bool was_discarded) { |
| 1787 | GetFrameTree()->root()->set_was_discarded(); |
| 1788 | } |
| 1789 | |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 1790 | void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size, |
| 1791 | bool stay_hidden) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1792 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::IncrementCapturerCount"); |
[email protected] | 5a65223 | 2013-02-12 06:15:25 | [diff] [blame] | 1793 | DCHECK(!is_being_destroyed_); |
Xianzhu Wang | 724e08f | 2020-09-01 21:35:07 | [diff] [blame] | 1794 | if (stay_hidden) { |
| 1795 | // A hidden capture should not have side effect on the web contents, so it |
| 1796 | // should not pass a non-empty |capture_size| which will cause side effect. |
| 1797 | DCHECK(capture_size.IsEmpty()); |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 1798 | ++hidden_capturer_count_; |
Xianzhu Wang | 724e08f | 2020-09-01 21:35:07 | [diff] [blame] | 1799 | } else { |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 1800 | ++visible_capturer_count_; |
Xianzhu Wang | 724e08f | 2020-09-01 21:35:07 | [diff] [blame] | 1801 | } |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1802 | |
| 1803 | // Note: This provides a hint to upstream code to size the views optimally |
| 1804 | // for quality (e.g., to avoid scaling). |
| 1805 | if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) { |
| 1806 | preferred_size_for_capture_ = capture_size; |
| 1807 | OnPreferredSizeChanged(preferred_size_); |
| 1808 | } |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1809 | |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 1810 | UpdateVisibilityAndNotifyPageAndView(GetVisibility()); |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1811 | } |
| 1812 | |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 1813 | void WebContentsImpl::DecrementCapturerCount(bool stay_hidden) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1814 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::DecrementCapturerCount"); |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 1815 | if (stay_hidden) |
| 1816 | --hidden_capturer_count_; |
| 1817 | else |
| 1818 | --visible_capturer_count_; |
| 1819 | DCHECK_GE(hidden_capturer_count_, 0); |
| 1820 | DCHECK_GE(visible_capturer_count_, 0); |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1821 | |
[email protected] | 5a65223 | 2013-02-12 06:15:25 | [diff] [blame] | 1822 | if (is_being_destroyed_) |
| 1823 | return; |
| 1824 | |
Francois Doray | 24fc62c | 2017-12-11 17:27:33 | [diff] [blame] | 1825 | if (!IsBeingCaptured()) { |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1826 | const gfx::Size old_size = preferred_size_for_capture_; |
| 1827 | preferred_size_for_capture_ = gfx::Size(); |
| 1828 | OnPreferredSizeChanged(old_size); |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1829 | } |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 1830 | |
| 1831 | UpdateVisibilityAndNotifyPageAndView(GetVisibility()); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1832 | } |
| 1833 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1834 | bool WebContentsImpl::IsBeingCaptured() { |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 1835 | return visible_capturer_count_ + hidden_capturer_count_ > 0; |
[email protected] | f2bd4081 | 2013-07-20 04:30:44 | [diff] [blame] | 1836 | } |
| 1837 | |
Xianzhu Wang | c61434c | 2020-08-21 19:17:30 | [diff] [blame] | 1838 | bool WebContentsImpl::IsBeingVisiblyCaptured() { |
| 1839 | return visible_capturer_count_ > 0; |
| 1840 | } |
| 1841 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1842 | bool WebContentsImpl::IsAudioMuted() { |
Guido Urdaneta | f837294 | 2019-11-15 09:47:21 | [diff] [blame] | 1843 | return audio_stream_factory_ && audio_stream_factory_->IsMuted(); |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | void WebContentsImpl::SetAudioMuted(bool mute) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1847 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::SetAudioMuted", "mute", |
| 1848 | mute); |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1849 | DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted() |
| 1850 | << " for WebContentsImpl@" << this; |
| 1851 | |
| 1852 | if (mute == IsAudioMuted()) |
| 1853 | return; |
| 1854 | |
Guido Urdaneta | f837294 | 2019-11-15 09:47:21 | [diff] [blame] | 1855 | GetAudioStreamFactory()->SetMuted(mute); |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1856 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 1857 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 1858 | observer->DidUpdateAudioMutingState(mute); |
| 1859 | }); |
Jan Rucka | 442c83f | 2017-08-08 13:27:54 | [diff] [blame] | 1860 | // Notification for UI updates in response to the changed muting state. |
Collin Baker | af540cf | 2019-09-20 20:54:16 | [diff] [blame] | 1861 | NotifyNavigationStateChanged(INVALIDATE_TYPE_AUDIO); |
Jan Rucka | 442c83f | 2017-08-08 13:27:54 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | bool WebContentsImpl::IsCurrentlyAudible() { |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 1865 | return is_currently_audible_; |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1866 | } |
| 1867 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1868 | bool WebContentsImpl::IsConnectedToBluetoothDevice() { |
ortuno | df4d798 | 2016-04-08 02:33:35 | [diff] [blame] | 1869 | return bluetooth_connected_device_count_ > 0; |
ortuno | 32e7db3c | 2016-03-29 16:14:20 | [diff] [blame] | 1870 | } |
| 1871 | |
Ovidio Henriquez | 76696f6 | 2020-07-08 03:06:59 | [diff] [blame] | 1872 | bool WebContentsImpl::IsScanningForBluetoothDevices() { |
| 1873 | return bluetooth_scanning_sessions_count_ > 0; |
| 1874 | } |
| 1875 | |
Lucas Furukawa Gadani | 4b4eed0 | 2019-06-04 23:12:04 | [diff] [blame] | 1876 | bool WebContentsImpl::IsConnectedToSerialPort() { |
Reilly Grant | 5e7c79b2 | 2019-04-09 17:26:20 | [diff] [blame] | 1877 | return serial_active_frame_count_ > 0; |
| 1878 | } |
| 1879 | |
Matt Reynolds | e8c6c1f | 2019-11-02 09:53:53 | [diff] [blame] | 1880 | bool WebContentsImpl::IsConnectedToHidDevice() { |
| 1881 | return hid_active_frame_count_ > 0; |
| 1882 | } |
| 1883 | |
Marijn Kruisselbrink | 2905104 | 2019-08-06 22:56:55 | [diff] [blame] | 1884 | bool WebContentsImpl::HasNativeFileSystemHandles() { |
| 1885 | return native_file_system_handle_count_ > 0; |
| 1886 | } |
Marijn Kruisselbrink | f1714aa2 | 2019-07-02 03:45:33 | [diff] [blame] | 1887 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1888 | bool WebContentsImpl::HasPictureInPictureVideo() { |
sawtelle | a7333a8 | 2018-05-31 02:36:36 | [diff] [blame] | 1889 | return has_picture_in_picture_video_; |
| 1890 | } |
| 1891 | |
| 1892 | void WebContentsImpl::SetHasPictureInPictureVideo( |
| 1893 | bool has_picture_in_picture_video) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1894 | OPTIONAL_TRACE_EVENT1("content", |
| 1895 | "WebContentsImpl::SetHasPictureInPictureVideo", |
| 1896 | "has_pip_video", has_picture_in_picture_video); |
sawtelle | a7333a8 | 2018-05-31 02:36:36 | [diff] [blame] | 1897 | // If status of |this| is already accurate, there is no need to update. |
| 1898 | if (has_picture_in_picture_video == has_picture_in_picture_video_) |
| 1899 | return; |
| 1900 | has_picture_in_picture_video_ = has_picture_in_picture_video; |
| 1901 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 1902 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 1903 | observer->MediaPictureInPictureChanged(has_picture_in_picture_video_); |
| 1904 | }); |
sawtelle | a7333a8 | 2018-05-31 02:36:36 | [diff] [blame] | 1905 | } |
| 1906 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1907 | bool WebContentsImpl::IsCrashed() { |
Dominic Mazzoni | 73a4832 | 2018-05-25 18:14:07 | [diff] [blame] | 1908 | switch (crashed_status_) { |
| 1909 | case base::TERMINATION_STATUS_PROCESS_CRASHED: |
| 1910 | case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
| 1911 | case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
| 1912 | case base::TERMINATION_STATUS_OOM: |
| 1913 | case base::TERMINATION_STATUS_LAUNCH_FAILED: |
Darin Fisher | 6cf20e78 | 2020-08-07 22:25:36 | [diff] [blame] | 1914 | #if defined(OS_CHROMEOS) || BUILDFLAG(IS_LACROS) |
Dominic Mazzoni | 73a4832 | 2018-05-25 18:14:07 | [diff] [blame] | 1915 | case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM: |
oshima | 62022572 | 2015-06-04 19:45:27 | [diff] [blame] | 1916 | #endif |
Dominic Mazzoni | 73a4832 | 2018-05-25 18:14:07 | [diff] [blame] | 1917 | #if defined(OS_ANDROID) |
| 1918 | case base::TERMINATION_STATUS_OOM_PROTECTED: |
| 1919 | #endif |
Will Harris | 07925d1 | 2019-10-31 03:03:05 | [diff] [blame] | 1920 | #if defined(OS_WIN) |
| 1921 | case base::TERMINATION_STATUS_INTEGRITY_FAILURE: |
| 1922 | #endif |
Dominic Mazzoni | 73a4832 | 2018-05-25 18:14:07 | [diff] [blame] | 1923 | return true; |
| 1924 | case base::TERMINATION_STATUS_NORMAL_TERMINATION: |
| 1925 | case base::TERMINATION_STATUS_STILL_RUNNING: |
| 1926 | return false; |
| 1927 | case base::TERMINATION_STATUS_MAX_ENUM: |
| 1928 | NOTREACHED(); |
| 1929 | return false; |
| 1930 | } |
| 1931 | |
| 1932 | NOTREACHED(); |
| 1933 | return false; |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1934 | } |
| 1935 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1936 | void WebContentsImpl::SetIsCrashed(base::TerminationStatus status, |
| 1937 | int error_code) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1938 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::SetIsCrashed", "status", |
| 1939 | static_cast<int>(status), "old_status", |
| 1940 | static_cast<int>(crashed_status_)); |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 1941 | if (status == crashed_status_) |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1942 | return; |
| 1943 | |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 1944 | crashed_status_ = status; |
| 1945 | crashed_error_code_ = error_code; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1946 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1947 | } |
| 1948 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1949 | base::TerminationStatus WebContentsImpl::GetCrashedStatus() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1950 | return crashed_status_; |
| 1951 | } |
| 1952 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1953 | int WebContentsImpl::GetCrashedErrorCode() { |
afakhry | 9824183 | 2016-03-11 19:27:47 | [diff] [blame] | 1954 | return crashed_error_code_; |
| 1955 | } |
| 1956 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1957 | bool WebContentsImpl::IsBeingDestroyed() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1958 | return is_being_destroyed_; |
| 1959 | } |
| 1960 | |
[email protected] | 7f92483 | 2014-08-09 05:57:22 | [diff] [blame] | 1961 | void WebContentsImpl::NotifyNavigationStateChanged( |
| 1962 | InvalidateTypes changed_flags) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1963 | TRACE_EVENT1("content,navigation", |
| 1964 | "WebContentsImpl::NotifyNavigationStateChanged", "changed_flags", |
| 1965 | static_cast<int>(changed_flags)); |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 1966 | // Notify the media observer of potential audibility changes. |
Collin Baker | af540cf | 2019-09-20 20:54:16 | [diff] [blame] | 1967 | if (changed_flags & INVALIDATE_TYPE_AUDIO) { |
mlamouri | 44e4ef4 | 2016-01-20 18:42:27 | [diff] [blame] | 1968 | media_web_contents_observer_->MaybeUpdateAudibleState(); |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 1969 | } |
| 1970 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1971 | if (delegate_) |
| 1972 | delegate_->NavigationStateChanged(this, changed_flags); |
wjmaclean | 1dabf3e3 | 2016-05-13 23:34:44 | [diff] [blame] | 1973 | |
| 1974 | if (GetOuterWebContents()) |
| 1975 | GetOuterWebContents()->NotifyNavigationStateChanged(changed_flags); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1976 | } |
| 1977 | |
W. James MacLean | 6f34b04 | 2019-07-12 19:25:30 | [diff] [blame] | 1978 | RenderFrameHostImpl* WebContentsImpl::GetFocusedFrameFromFocusedDelegate() { |
| 1979 | FrameTreeNode* focused_node = |
| 1980 | GetFocusedWebContents()->frame_tree_.GetFocusedFrame(); |
| 1981 | return focused_node ? focused_node->current_frame_host() : nullptr; |
| 1982 | } |
| 1983 | |
David Black | 9cca359 | 2019-11-06 23:02:22 | [diff] [blame] | 1984 | void WebContentsImpl::OnVerticalScrollDirectionChanged( |
| 1985 | viz::VerticalScrollDirection scroll_direction) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 1986 | OPTIONAL_TRACE_EVENT1("content", |
| 1987 | "WebContentsImpl::OnVerticalScrollDirectionChanged", |
| 1988 | "scroll_direction", static_cast<int>(scroll_direction)); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 1989 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 1990 | observer->DidChangeVerticalScrollDirection(scroll_direction); |
| 1991 | }); |
David Black | 9cca359 | 2019-11-06 23:02:22 | [diff] [blame] | 1992 | } |
| 1993 | |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 1994 | void WebContentsImpl::OnAudioStateChanged() { |
| 1995 | // This notification can come from any embedded contents or from this |
| 1996 | // WebContents' stream monitor. Aggregate these signals to get the actual |
| 1997 | // state. |
Jeremy Roman | 03ce13ce | 2020-05-29 22:16:57 | [diff] [blame] | 1998 | // |
| 1999 | // Note that guests may not be attached as inner contents, and so may need to |
| 2000 | // be checked separately. |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 2001 | bool is_currently_audible = |
| 2002 | audio_stream_monitor_.IsCurrentlyAudible() || |
| 2003 | (browser_plugin_embedder_ && |
Jeremy Roman | 03ce13ce | 2020-05-29 22:16:57 | [diff] [blame] | 2004 | browser_plugin_embedder_->AreAnyGuestsCurrentlyAudible()) || |
| 2005 | AnyInnerWebContents(this, [](WebContents* inner_contents) { |
| 2006 | return inner_contents->IsCurrentlyAudible(); |
| 2007 | }); |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2008 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::OnAudioStateChanged", |
| 2009 | "is_currently_audible", is_currently_audible, |
| 2010 | "was_audible", is_currently_audible_); |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 2011 | if (is_currently_audible == is_currently_audible_) |
| 2012 | return; |
| 2013 | |
| 2014 | // Update internal state. |
| 2015 | is_currently_audible_ = is_currently_audible; |
| 2016 | was_ever_audible_ = was_ever_audible_ || is_currently_audible_; |
| 2017 | |
Gyuyoung Kim | 877e86d | 2020-07-21 04:01:02 | [diff] [blame] | 2018 | ExecutePageBroadcastMethod(base::BindRepeating( |
| 2019 | [](bool is_currently_audible, RenderViewHostImpl* rvh) { |
| 2020 | if (auto& broadcast = rvh->GetAssociatedPageBroadcast()) |
| 2021 | broadcast->AudioStateChanged(is_currently_audible); |
| 2022 | }, |
| 2023 | is_currently_audible_)); |
altimin | d8bd26c | 2016-11-04 11:44:54 | [diff] [blame] | 2024 | |
altimin | ec87fd1f | 2016-11-17 20:22:49 | [diff] [blame] | 2025 | // Notification for UI updates in response to the changed audio state. |
Collin Baker | af540cf | 2019-09-20 20:54:16 | [diff] [blame] | 2026 | NotifyNavigationStateChanged(INVALIDATE_TYPE_AUDIO); |
Jan Rucka | 442c83f | 2017-08-08 13:27:54 | [diff] [blame] | 2027 | |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 2028 | // Ensure that audio state changes propagate from innermost to outermost |
| 2029 | // WebContents. |
| 2030 | if (GetOuterWebContents()) |
| 2031 | GetOuterWebContents()->OnAudioStateChanged(); |
Tommy Steimel | 1836051 | 2017-11-01 00:38:19 | [diff] [blame] | 2032 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 2033 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2034 | observer->OnAudioStateChanged(is_currently_audible_); |
| 2035 | }); |
altimin | d8bd26c | 2016-11-04 11:44:54 | [diff] [blame] | 2036 | } |
| 2037 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 2038 | base::TimeTicks WebContentsImpl::GetLastActiveTime() { |
[email protected] | 9a89045 | 2014-02-13 22:21:02 | [diff] [blame] | 2039 | return last_active_time_; |
[email protected] | 3e32414 | 2012-06-25 18:26:33 | [diff] [blame] | 2040 | } |
| 2041 | |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 2042 | void WebContentsImpl::WasShown() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2043 | TRACE_EVENT0("content", "WebContentsImpl::WasShown"); |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 2044 | UpdateVisibilityAndNotifyPageAndView(Visibility::VISIBLE); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2045 | } |
| 2046 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2047 | void WebContentsImpl::WasHidden() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2048 | TRACE_EVENT0("content", "WebContentsImpl::WasHidden"); |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 2049 | UpdateVisibilityAndNotifyPageAndView(Visibility::HIDDEN); |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 2050 | } |
| 2051 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 2052 | bool WebContentsImpl::HasRecentInteractiveInputEvent() { |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 2053 | static constexpr base::TimeDelta kMaxInterval = |
| 2054 | base::TimeDelta::FromSeconds(5); |
| 2055 | base::TimeDelta delta = |
| 2056 | ui::EventTimeForNow() - last_interactive_input_event_time_; |
| 2057 | // Note: the expectation is that the caller is typically expecting an input |
| 2058 | // event, e.g. validating that a WebUI message that requires a gesture is |
Daniel Cheng | e81030b3 | 2019-07-17 20:20:23 | [diff] [blame] | 2059 | // actually attached to a gesture. |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 2060 | return delta <= kMaxInterval; |
| 2061 | } |
| 2062 | |
Avi Drissman | 738ea19 | 2018-08-29 20:24:16 | [diff] [blame] | 2063 | void WebContentsImpl::SetIgnoreInputEvents(bool ignore_input_events) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2064 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::SetIgnoreInputEvents", |
| 2065 | "ignore_input_events", ignore_input_events); |
Avi Drissman | 738ea19 | 2018-08-29 20:24:16 | [diff] [blame] | 2066 | ignore_input_events_ = ignore_input_events; |
| 2067 | } |
| 2068 | |
Bo Liu | 168c864 | 2017-08-28 18:26:02 | [diff] [blame] | 2069 | #if defined(OS_ANDROID) |
Bo Liu | 16dd7b832 | 2018-05-02 21:19:50 | [diff] [blame] | 2070 | void WebContentsImpl::SetMainFrameImportance( |
| 2071 | ChildProcessImportance importance) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2072 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::SetMainFrameImportance", |
| 2073 | "importance", static_cast<int>(importance)); |
Bo Liu | 16dd7b832 | 2018-05-02 21:19:50 | [diff] [blame] | 2074 | GetMainFrame()->GetRenderWidgetHost()->SetImportance(importance); |
Bo Liu | 7c6779e9 | 2017-08-16 02:02:28 | [diff] [blame] | 2075 | } |
Bo Liu | 168c864 | 2017-08-28 18:26:02 | [diff] [blame] | 2076 | #endif |
Bo Liu | 7c6779e9 | 2017-08-16 02:02:28 | [diff] [blame] | 2077 | |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 2078 | void WebContentsImpl::WasOccluded() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2079 | TRACE_EVENT0("content", "WebContentsImpl::WasOccluded"); |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 2080 | UpdateVisibilityAndNotifyPageAndView(Visibility::OCCLUDED); |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 2081 | } |
| 2082 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 2083 | Visibility WebContentsImpl::GetVisibility() { |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 2084 | return visibility_; |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 2085 | } |
| 2086 | |
Rakina Zata Amni | 26e8d8a | 2020-08-05 06:06:06 | [diff] [blame] | 2087 | bool WebContentsImpl::NeedToFireBeforeUnloadOrUnloadEvents() { |
Alexander Timin | c7bee32 | 2020-05-19 17:54:34 | [diff] [blame] | 2088 | if (!notify_disconnection_) |
Alex Moshchuk | 6fcaca75 | 2018-07-14 02:13:59 | [diff] [blame] | 2089 | return false; |
| 2090 | |
| 2091 | // Don't fire if the main frame's RenderViewHost indicates that beforeunload |
| 2092 | // and unload have already executed (e.g., after receiving a ClosePage ACK) |
| 2093 | // or should be ignored. |
| 2094 | if (GetRenderViewHost()->SuddenTerminationAllowed()) |
| 2095 | return false; |
| 2096 | |
Alex Moshchuk | c78dbc72 | 2019-10-31 20:00:50 | [diff] [blame] | 2097 | // Check whether any frame in the frame tree needs to run beforeunload or |
Rakina Zata Amni | 26e8d8a | 2020-08-05 06:06:06 | [diff] [blame] | 2098 | // unload-time event handlers. |
Alex Moshchuk | c78dbc72 | 2019-10-31 20:00:50 | [diff] [blame] | 2099 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 2100 | RenderFrameHostImpl* rfh = node->current_frame_host(); |
| 2101 | |
Rakina Zata Amni | 26e8d8a | 2020-08-05 06:06:06 | [diff] [blame] | 2102 | // No need to run beforeunload/unload-time events if the RenderFrame isn't |
| 2103 | // live. |
Alex Moshchuk | c78dbc72 | 2019-10-31 20:00:50 | [diff] [blame] | 2104 | if (!rfh->IsRenderFrameLive()) |
| 2105 | continue; |
Rakina Zata Amni | 26e8d8a | 2020-08-05 06:06:06 | [diff] [blame] | 2106 | bool should_run_before_unload_handler = |
Dave Tapuska | 97d22ab | 2019-12-03 17:56:36 | [diff] [blame] | 2107 | rfh->GetSuddenTerminationDisablerState( |
Rakina Zata Amni | 26e8d8a | 2020-08-05 06:06:06 | [diff] [blame] | 2108 | blink::mojom::SuddenTerminationDisablerType::kBeforeUnloadHandler); |
| 2109 | bool should_run_unload_handler = rfh->GetSuddenTerminationDisablerState( |
| 2110 | blink::mojom::SuddenTerminationDisablerType::kUnloadHandler); |
| 2111 | bool should_run_page_hide_handler = rfh->GetSuddenTerminationDisablerState( |
| 2112 | blink::mojom::SuddenTerminationDisablerType::kPageHideHandler); |
| 2113 | auto* rvh = static_cast<RenderViewHostImpl*>(rfh->GetRenderViewHost()); |
| 2114 | // If the tab is already hidden, we should not run visibilitychange |
| 2115 | // handlers. |
| 2116 | bool is_page_visible = rvh->GetPageLifecycleStateManager() |
| 2117 | ->CalculatePageLifecycleState() |
| 2118 | ->visibility == PageVisibilityState::kVisible; |
| 2119 | |
| 2120 | bool should_run_visibility_change_handler = |
| 2121 | is_page_visible && rfh->GetSuddenTerminationDisablerState( |
| 2122 | blink::mojom::SuddenTerminationDisablerType:: |
| 2123 | kVisibilityChangeHandler); |
| 2124 | if (should_run_before_unload_handler || should_run_unload_handler || |
| 2125 | should_run_page_hide_handler || should_run_visibility_change_handler) { |
Alex Moshchuk | c78dbc72 | 2019-10-31 20:00:50 | [diff] [blame] | 2126 | return true; |
| 2127 | } |
Aditya Keerthi | 34f37e6 | 2019-03-08 15:54:53 | [diff] [blame] | 2128 | } |
Alex Moshchuk | 6fcaca75 | 2018-07-14 02:13:59 | [diff] [blame] | 2129 | |
Alex Moshchuk | c78dbc72 | 2019-10-31 20:00:50 | [diff] [blame] | 2130 | return false; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2131 | } |
| 2132 | |
Chris Hamilton | 3b3e315d | 2018-09-19 13:16:21 | [diff] [blame] | 2133 | void WebContentsImpl::DispatchBeforeUnload(bool auto_cancel) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2134 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::DispatchBeforeUnload", |
| 2135 | "auto_cancel", auto_cancel); |
Chris Hamilton | 3b3e315d | 2018-09-19 13:16:21 | [diff] [blame] | 2136 | auto before_unload_type = |
| 2137 | auto_cancel ? RenderFrameHostImpl::BeforeUnloadType::DISCARD |
| 2138 | : RenderFrameHostImpl::BeforeUnloadType::TAB_CLOSE; |
| 2139 | GetMainFrame()->DispatchBeforeUnload(before_unload_type, false); |
[email protected] | 1c3f80bd | 2014-04-08 23:02:06 | [diff] [blame] | 2140 | } |
| 2141 | |
W. James MacLean | 2539adb3 | 2019-12-13 00:40:44 | [diff] [blame] | 2142 | bool WebContentsImpl::IsInnerWebContentsForGuest() { |
| 2143 | return !!browser_plugin_guest_; |
| 2144 | } |
| 2145 | |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2146 | void WebContentsImpl::AttachInnerWebContents( |
| 2147 | std::unique_ptr<WebContents> inner_web_contents, |
W. James MacLean | 6288398 | 2019-11-12 20:39:00 | [diff] [blame] | 2148 | RenderFrameHost* render_frame_host, |
| 2149 | bool is_full_page) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2150 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::AttachInnerWebContents", |
| 2151 | "inner_web_contents", inner_web_contents.get(), |
| 2152 | "is_full_page", is_full_page); |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2153 | WebContentsImpl* inner_web_contents_impl = |
| 2154 | static_cast<WebContentsImpl*>(inner_web_contents.get()); |
| 2155 | DCHECK(!inner_web_contents_impl->node_.outer_web_contents()); |
| 2156 | auto* render_frame_host_impl = |
| 2157 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
Fergal Daly | 445af93 | 2020-06-02 06:37:23 | [diff] [blame] | 2158 | DCHECK_EQ(&frame_tree_, render_frame_host_impl->frame_tree()); |
Lucas Furukawa Gadani | 105de1e81 | 2018-05-31 19:38:39 | [diff] [blame] | 2159 | |
Yuzu Saijo | 3f86fb2 | 2020-06-11 03:51:10 | [diff] [blame] | 2160 | // Mark |render_frame_host_impl| as outer delegate frame. |
| 2161 | render_frame_host_impl->SetIsOuterDelegateFrame(true); |
| 2162 | |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2163 | RenderFrameHostManager* inner_render_manager = |
| 2164 | inner_web_contents_impl->GetRenderManager(); |
| 2165 | RenderFrameHostImpl* inner_main_frame = |
| 2166 | inner_render_manager->current_frame_host(); |
| 2167 | RenderViewHostImpl* inner_render_view_host = |
| 2168 | inner_render_manager->current_host(); |
| 2169 | auto* outer_render_manager = |
| 2170 | render_frame_host_impl->frame_tree_node()->render_manager(); |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 2171 | |
Lucas Furukawa Gadani | 105de1e81 | 2018-05-31 19:38:39 | [diff] [blame] | 2172 | // When attaching a WebContents as an inner WebContents, we need to replace |
| 2173 | // the Webcontents' view with a WebContentsViewChildFrame. |
Fergal Daly | 55b6d72 | 2020-09-11 07:56:33 | [diff] [blame] | 2174 | inner_web_contents_impl->view_ = std::make_unique<WebContentsViewChildFrame>( |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2175 | inner_web_contents_impl, |
| 2176 | GetContentClient()->browser()->GetWebContentsViewDelegate( |
| 2177 | inner_web_contents_impl), |
Fergal Daly | 55b6d72 | 2020-09-11 07:56:33 | [diff] [blame] | 2178 | &inner_web_contents_impl->render_view_host_delegate_view_); |
Lucas Furukawa Gadani | 105de1e81 | 2018-05-31 19:38:39 | [diff] [blame] | 2179 | |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 2180 | // When the WebContents being initialized has an opener, the browser side |
| 2181 | // Render{View,Frame}Host must be initialized and the RenderWidgetHostView |
| 2182 | // created. This is needed because the usual initialization happens during |
| 2183 | // the first navigation, but when attaching a new window we don't navigate |
| 2184 | // before attaching. If the browser side is already initialized, the calls |
| 2185 | // below will just early return. |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2186 | inner_render_manager->InitRenderView(inner_render_view_host, nullptr); |
| 2187 | inner_main_frame->Init(); |
| 2188 | if (!inner_render_manager->GetRenderWidgetHostView()) { |
| 2189 | inner_web_contents_impl->CreateRenderWidgetHostViewForRenderManager( |
| 2190 | inner_render_view_host); |
| 2191 | } |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 2192 | |
Adithya Srinivasan | e6e7f84 | 2019-12-16 18:41:36 | [diff] [blame] | 2193 | inner_web_contents_impl->RecursivelyUnregisterFrameSinkIds(); |
| 2194 | |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 2195 | // Create a link to our outer WebContents. |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2196 | node_.AttachInnerWebContents(std::move(inner_web_contents), |
| 2197 | render_frame_host_impl); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 2198 | |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 2199 | // Create a proxy in top-level RenderFrameHostManager, pointing to the |
| 2200 | // SiteInstance of the outer WebContents. The proxy will be used to send |
| 2201 | // postMessage to the inner WebContents. |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2202 | auto* proxy = inner_render_manager->CreateOuterDelegateProxy( |
| 2203 | render_frame_host_impl->GetSiteInstance()); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 2204 | |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 2205 | // When attaching a GuestView as an inner WebContents, there should already be |
| 2206 | // a live RenderFrame, which has to be swapped. When attaching a portal, there |
| 2207 | // will not be a live RenderFrame before creating the proxy. |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2208 | if (render_frame_host_impl->IsRenderFrameLive()) { |
| 2209 | inner_render_manager->SwapOuterDelegateFrame(render_frame_host_impl, proxy); |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 2210 | |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2211 | inner_web_contents_impl->ReattachToOuterWebContentsFrame(); |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 2212 | } |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 2213 | |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2214 | if (frame_tree_.GetFocusedFrame() == |
| 2215 | render_frame_host_impl->frame_tree_node()) { |
| 2216 | inner_web_contents_impl->SetFocusedFrame( |
| 2217 | inner_web_contents_impl->frame_tree_.root(), |
| 2218 | render_frame_host_impl->GetSiteInstance()); |
avallee | 7529b2a | 2017-04-26 11:37:51 | [diff] [blame] | 2219 | } |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2220 | outer_render_manager->set_attach_complete(); |
W. James MacLean | 6288398 | 2019-11-12 20:39:00 | [diff] [blame] | 2221 | |
| 2222 | // If the inner WebContents is full frame, give it focus. |
| 2223 | if (is_full_page) { |
| 2224 | // There should only ever be one inner WebContents when |is_full_page| is |
| 2225 | // true, and it is the one we just attached. |
| 2226 | DCHECK_EQ(1u, node_.GetInnerWebContents().size()); |
| 2227 | inner_web_contents_impl->SetAsFocusedWebContentsIfNecessary(); |
| 2228 | } |
Chris Hamilton | 16b5d1d | 2020-06-04 00:08:12 | [diff] [blame] | 2229 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 2230 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2231 | observer->InnerWebContentsAttached(inner_web_contents_impl, |
| 2232 | render_frame_host, is_full_page); |
| 2233 | }); |
Mario Sanchez Prada | 989aeb7a | 2020-10-13 09:42:56 | [diff] [blame] | 2234 | |
| 2235 | // Make sure that the inner web contents and its outer delegate get properly |
| 2236 | // linked via the embedding token now that inner web contents are attached. |
| 2237 | inner_main_frame->PropagateEmbeddingTokenToParentFrame(); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 2238 | } |
| 2239 | |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 2240 | std::unique_ptr<WebContents> WebContentsImpl::DetachFromOuterWebContents() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2241 | OPTIONAL_TRACE_EVENT0("content", |
| 2242 | "WebContentsImpl::DetachFromOuterWebContents"); |
Chris Hamilton | 16b5d1d | 2020-06-04 00:08:12 | [diff] [blame] | 2243 | auto* outer_web_contents = GetOuterWebContents(); |
| 2244 | DCHECK(outer_web_contents); |
Yuzu Saijo | 3f86fb2 | 2020-06-11 03:51:10 | [diff] [blame] | 2245 | GetMainFrame()->ParentOrOuterDelegateFrame()->SetIsOuterDelegateFrame(false); |
Chris Hamilton | 16b5d1d | 2020-06-04 00:08:12 | [diff] [blame] | 2246 | |
Adithya Srinivasan | e6e7f84 | 2019-12-16 18:41:36 | [diff] [blame] | 2247 | RecursivelyUnregisterFrameSinkIds(); |
Lucas Gadani | d2995258 | 2020-06-09 21:24:00 | [diff] [blame] | 2248 | |
| 2249 | // Each RenderViewHost has a RenderWidgetHost which can have a |
| 2250 | // RenderWidgetHostView, and it needs to be re-created with the appropriate |
| 2251 | // platform view. It is important to re-create all child views, not only the |
| 2252 | // current one, since the view can be swapped due to a cross-origin |
| 2253 | // navigation. |
| 2254 | std::set<RenderViewHostImpl*> render_view_hosts; |
| 2255 | for (auto& render_view_host : GetFrameTree()->render_view_hosts()) { |
| 2256 | if (render_view_host.second->GetWidget() && |
| 2257 | render_view_host.second->GetWidget()->GetView()) { |
| 2258 | DCHECK(render_view_host.second->GetWidget() |
| 2259 | ->GetView() |
| 2260 | ->IsRenderWidgetHostViewChildFrame()); |
| 2261 | render_view_hosts.insert(render_view_host.second); |
Kevin McNee | 6471a70 | 2020-01-27 18:23:07 | [diff] [blame] | 2262 | } |
| 2263 | } |
Lucas Gadani | d2995258 | 2020-06-09 21:24:00 | [diff] [blame] | 2264 | |
| 2265 | for (auto* render_view_host : render_view_hosts) |
| 2266 | render_view_host->GetWidget()->GetView()->Destroy(); |
| 2267 | |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 2268 | GetRenderManager()->DeleteOuterDelegateProxy( |
| 2269 | node_.OuterContentsFrameTreeNode() |
| 2270 | ->current_frame_host() |
| 2271 | ->GetSiteInstance()); |
| 2272 | view_.reset(CreateWebContentsView( |
| 2273 | this, GetContentClient()->browser()->GetWebContentsViewDelegate(this), |
| 2274 | &render_view_host_delegate_view_)); |
danakj | fc518493 | 2019-09-12 18:08:32 | [diff] [blame] | 2275 | view_->CreateView(nullptr); |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 2276 | std::unique_ptr<WebContents> web_contents = |
| 2277 | node_.DisconnectFromOuterWebContents(); |
| 2278 | DCHECK_EQ(web_contents.get(), this); |
| 2279 | node_.SetFocusedWebContents(this); |
Lucas Gadani | d2995258 | 2020-06-09 21:24:00 | [diff] [blame] | 2280 | |
| 2281 | for (auto* render_view_host : render_view_hosts) |
| 2282 | CreateRenderWidgetHostViewForRenderManager(render_view_host); |
| 2283 | |
Adithya Srinivasan | e6e7f84 | 2019-12-16 18:41:36 | [diff] [blame] | 2284 | RecursivelyRegisterFrameSinkIds(); |
Adithya Srinivasan | 6f0f67b | 2019-12-19 01:26:46 | [diff] [blame] | 2285 | // TODO(adithyas): |browser_plugin_embedder_ax_tree_id| should either not be |
| 2286 | // used for portals, or it should get a different name. |
| 2287 | GetMainFrame()->set_browser_plugin_embedder_ax_tree_id(ui::AXTreeIDUnknown()); |
| 2288 | GetMainFrame()->UpdateAXTreeData(); |
Chris Hamilton | 16b5d1d | 2020-06-04 00:08:12 | [diff] [blame] | 2289 | |
| 2290 | // Invoke on the *outer* web contents observers for symmetry. |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 2291 | outer_web_contents->observers_.ForEachObserver( |
| 2292 | [&](WebContentsObserver* observer) { |
| 2293 | observer->InnerWebContentsDetached(this); |
| 2294 | }); |
Chris Hamilton | 16b5d1d | 2020-06-04 00:08:12 | [diff] [blame] | 2295 | |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 2296 | return web_contents; |
| 2297 | } |
| 2298 | |
W. James MacLean | 2dc75ed4 | 2019-03-06 14:31:09 | [diff] [blame] | 2299 | void WebContentsImpl::RecursivelyRegisterFrameSinkIds() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2300 | OPTIONAL_TRACE_EVENT0("content", |
| 2301 | "WebContentsImpl::RecursivelyRegisterFrameSinkIds"); |
Adithya Srinivasan | e6e7f84 | 2019-12-16 18:41:36 | [diff] [blame] | 2302 | for (auto* view : GetRenderWidgetHostViewsInWebContentsTree()) { |
| 2303 | auto* rwhvb = static_cast<RenderWidgetHostViewBase*>(view); |
| 2304 | if (rwhvb->IsRenderWidgetHostViewChildFrame()) |
| 2305 | static_cast<RenderWidgetHostViewChildFrame*>(view)->RegisterFrameSinkId(); |
| 2306 | } |
| 2307 | } |
W. James MacLean | 2dc75ed4 | 2019-03-06 14:31:09 | [diff] [blame] | 2308 | |
Adithya Srinivasan | e6e7f84 | 2019-12-16 18:41:36 | [diff] [blame] | 2309 | void WebContentsImpl::RecursivelyUnregisterFrameSinkIds() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2310 | OPTIONAL_TRACE_EVENT0("content", |
| 2311 | "WebContentsImpl::RecursivelyUnregisterFrameSinkIds"); |
Adithya Srinivasan | e6e7f84 | 2019-12-16 18:41:36 | [diff] [blame] | 2312 | for (auto* view : GetRenderWidgetHostViewsInWebContentsTree()) { |
| 2313 | auto* rwhvb = static_cast<RenderWidgetHostViewBase*>(view); |
| 2314 | if (rwhvb->IsRenderWidgetHostViewChildFrame()) { |
| 2315 | static_cast<RenderWidgetHostViewChildFrame*>(view) |
| 2316 | ->UnregisterFrameSinkId(); |
| 2317 | } |
W. James MacLean | 2dc75ed4 | 2019-03-06 14:31:09 | [diff] [blame] | 2318 | } |
| 2319 | } |
| 2320 | |
Lucas Furukawa Gadani | aed1fed | 2017-10-13 17:34:14 | [diff] [blame] | 2321 | void WebContentsImpl::ReattachToOuterWebContentsFrame() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2322 | OPTIONAL_TRACE_EVENT0("content", |
| 2323 | "WebContentsImpl::ReattachToOuterWebContentsFrame"); |
Lucas Furukawa Gadani | aed1fed | 2017-10-13 17:34:14 | [diff] [blame] | 2324 | DCHECK(node_.outer_web_contents()); |
| 2325 | auto* render_manager = GetRenderManager(); |
| 2326 | auto* parent_frame = |
| 2327 | node_.OuterContentsFrameTreeNode()->current_frame_host()->GetParent(); |
| 2328 | render_manager->SetRWHViewForInnerContents( |
| 2329 | render_manager->GetRenderWidgetHostView()); |
| 2330 | |
W. James MacLean | 2dc75ed4 | 2019-03-06 14:31:09 | [diff] [blame] | 2331 | RecursivelyRegisterFrameSinkIds(); |
Lucas Furukawa Gadani | aed1fed | 2017-10-13 17:34:14 | [diff] [blame] | 2332 | |
| 2333 | // Set up the the guest's AX tree to point back at the embedder's AX tree. |
| 2334 | GetMainFrame()->set_browser_plugin_embedder_ax_tree_id( |
| 2335 | parent_frame->GetAXTreeID()); |
| 2336 | GetMainFrame()->UpdateAXTreeData(); |
| 2337 | } |
| 2338 | |
Lucas Gadani | 97298562 | 2020-05-28 20:52:51 | [diff] [blame] | 2339 | void WebContentsImpl::DidActivatePortal( |
| 2340 | WebContentsImpl* predecessor_web_contents, |
| 2341 | base::TimeTicks activation_time) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2342 | TRACE_EVENT2("content", "WebContentsImpl::DidActivatePortal", "predecessor", |
| 2343 | predecessor_web_contents, "activation_time", activation_time); |
Lucas Gadani | 97298562 | 2020-05-28 20:52:51 | [diff] [blame] | 2344 | DCHECK(predecessor_web_contents); |
Kevin McNee | f8eb64c | 2020-04-21 21:36:06 | [diff] [blame] | 2345 | NotifyInsidePortal(false); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 2346 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2347 | observer->DidActivatePortal(predecessor_web_contents, activation_time); |
| 2348 | }); |
Lucas Gadani | 97298562 | 2020-05-28 20:52:51 | [diff] [blame] | 2349 | GetDelegate()->WebContentsBecamePortal(predecessor_web_contents); |
Kevin McNee | f8eb64c | 2020-04-21 21:36:06 | [diff] [blame] | 2350 | } |
| 2351 | |
Adithya Srinivasan | 11af2c5 | 2019-12-16 22:52:55 | [diff] [blame] | 2352 | void WebContentsImpl::NotifyInsidePortal(bool inside_portal) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2353 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::NotifyInsidePortal", |
| 2354 | "inside_portal", inside_portal); |
Gyuyoung Kim | 1c02971 | 2020-07-22 09:21:06 | [diff] [blame] | 2355 | ExecutePageBroadcastMethod(base::BindRepeating( |
| 2356 | [](bool inside_portal, RenderViewHostImpl* rvh) { |
| 2357 | if (auto& broadcast = rvh->GetAssociatedPageBroadcast()) |
| 2358 | broadcast->SetInsidePortal(inside_portal); |
| 2359 | }, |
| 2360 | inside_portal)); |
Adithya Srinivasan | 11af2c5 | 2019-12-16 22:52:55 | [diff] [blame] | 2361 | } |
| 2362 | |
dalecurtis | 6c58ed0 | 2016-10-28 23:02:37 | [diff] [blame] | 2363 | void WebContentsImpl::DidChangeVisibleSecurityState() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2364 | OPTIONAL_TRACE_EVENT0("content", |
| 2365 | "WebContentsImpl::DidChangeVisibleSecurityState"); |
Emily Stark | c663b024 | 2019-04-26 19:34:45 | [diff] [blame] | 2366 | if (delegate_) |
dalecurtis | 6c58ed0 | 2016-10-28 23:02:37 | [diff] [blame] | 2367 | delegate_->VisibleSecurityStateChanged(this); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 2368 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2369 | observer->DidChangeVisibleSecurityState(); |
| 2370 | }); |
dalecurtis | 6c58ed0 | 2016-10-28 23:02:37 | [diff] [blame] | 2371 | } |
| 2372 | |
Gyuyoung Kim | 1ac4ca78 | 2020-09-11 03:32:51 | [diff] [blame] | 2373 | const blink::web_pref::WebPreferences WebContentsImpl::ComputeWebPreferences() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2374 | OPTIONAL_TRACE_EVENT0("browser", "WebContentsImpl::ComputeWebPreferences"); |
| 2375 | |
Gyuyoung Kim | 1ac4ca78 | 2020-09-11 03:32:51 | [diff] [blame] | 2376 | blink::web_pref::WebPreferences prefs; |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 2377 | |
| 2378 | const base::CommandLine& command_line = |
| 2379 | *base::CommandLine::ForCurrentProcess(); |
| 2380 | |
| 2381 | SetSlowWebPreferences(command_line, &prefs); |
| 2382 | |
| 2383 | prefs.web_security_enabled = |
| 2384 | !command_line.HasSwitch(switches::kDisableWebSecurity); |
| 2385 | |
| 2386 | prefs.remote_fonts_enabled = |
| 2387 | !command_line.HasSwitch(switches::kDisableRemoteFonts); |
| 2388 | prefs.application_cache_enabled = |
| 2389 | base::FeatureList::IsEnabled(blink::features::kAppCache); |
| 2390 | prefs.local_storage_enabled = |
| 2391 | !command_line.HasSwitch(switches::kDisableLocalStorage); |
| 2392 | prefs.databases_enabled = |
| 2393 | !command_line.HasSwitch(switches::kDisableDatabases); |
| 2394 | |
| 2395 | prefs.webgl1_enabled = !command_line.HasSwitch(switches::kDisable3DAPIs) && |
| 2396 | !command_line.HasSwitch(switches::kDisableWebGL); |
| 2397 | prefs.webgl2_enabled = !command_line.HasSwitch(switches::kDisable3DAPIs) && |
| 2398 | !command_line.HasSwitch(switches::kDisableWebGL) && |
| 2399 | !command_line.HasSwitch(switches::kDisableWebGL2); |
| 2400 | |
| 2401 | prefs.pepper_3d_enabled = !command_line.HasSwitch(switches::kDisablePepper3d); |
| 2402 | |
| 2403 | prefs.flash_3d_enabled = !command_line.HasSwitch(switches::kDisableFlash3d); |
| 2404 | prefs.flash_stage3d_enabled = |
| 2405 | !command_line.HasSwitch(switches::kDisableFlashStage3d); |
| 2406 | prefs.flash_stage3d_baseline_enabled = |
| 2407 | !command_line.HasSwitch(switches::kDisableFlashStage3d); |
| 2408 | |
| 2409 | prefs.allow_file_access_from_file_urls = |
| 2410 | command_line.HasSwitch(switches::kAllowFileAccessFromFiles); |
| 2411 | |
| 2412 | prefs.accelerated_2d_canvas_enabled = |
| 2413 | !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas); |
| 2414 | prefs.new_canvas_2d_api_enabled = |
Rakina Zata Amni | ea8d0c2 | 2020-07-30 17:22:50 | [diff] [blame] | 2415 | command_line.HasSwitch(switches::kEnableNewCanvas2DAPI) || |
| 2416 | base::FeatureList::IsEnabled(features::kEnableNewCanvas2DAPI); |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 2417 | prefs.antialiased_2d_canvas_disabled = |
| 2418 | command_line.HasSwitch(switches::kDisable2dCanvasAntialiasing); |
| 2419 | prefs.antialiased_clips_2d_canvas_enabled = |
| 2420 | !command_line.HasSwitch(switches::kDisable2dCanvasClipAntialiasing); |
| 2421 | |
| 2422 | prefs.disable_ipc_flooding_protection = |
| 2423 | command_line.HasSwitch(switches::kDisableIpcFloodingProtection) || |
| 2424 | command_line.HasSwitch(switches::kDisablePushStateThrottle); |
| 2425 | |
| 2426 | prefs.accelerated_video_decode_enabled = |
| 2427 | !command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode); |
| 2428 | |
| 2429 | std::string autoplay_policy = media::GetEffectiveAutoplayPolicy(command_line); |
| 2430 | if (autoplay_policy == switches::autoplay::kNoUserGestureRequiredPolicy) { |
Gyuyoung Kim | 1ac4ca78 | 2020-09-11 03:32:51 | [diff] [blame] | 2431 | prefs.autoplay_policy = |
Gyuyoung Kim | f6c02a26 | 2020-10-13 01:36:13 | [diff] [blame] | 2432 | blink::mojom::AutoplayPolicy::kNoUserGestureRequired; |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 2433 | } else if (autoplay_policy == |
| 2434 | switches::autoplay::kUserGestureRequiredPolicy) { |
Gyuyoung Kim | f6c02a26 | 2020-10-13 01:36:13 | [diff] [blame] | 2435 | prefs.autoplay_policy = blink::mojom::AutoplayPolicy::kUserGestureRequired; |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 2436 | } else if (autoplay_policy == |
| 2437 | switches::autoplay::kDocumentUserActivationRequiredPolicy) { |
Gyuyoung Kim | 1ac4ca78 | 2020-09-11 03:32:51 | [diff] [blame] | 2438 | prefs.autoplay_policy = |
Gyuyoung Kim | f6c02a26 | 2020-10-13 01:36:13 | [diff] [blame] | 2439 | blink::mojom::AutoplayPolicy::kDocumentUserActivationRequired; |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 2440 | } else { |
| 2441 | NOTREACHED(); |
| 2442 | } |
| 2443 | |
| 2444 | prefs.dont_send_key_events_to_javascript = |
| 2445 | base::FeatureList::IsEnabled(features::kDontSendKeyEventsToJavascript); |
| 2446 | |
| 2447 | // TODO(dtapuska): Enable barrel button selection drag support on Android. |
| 2448 | // crbug.com/758042 |
| 2449 | #if defined(OS_WIN) |
| 2450 | prefs.barrel_button_for_drag_enabled = |
| 2451 | base::FeatureList::IsEnabled(features::kDirectManipulationStylus); |
| 2452 | #endif // defined(OS_WIN) |
| 2453 | |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 2454 | prefs.enable_scroll_animator = |
| 2455 | command_line.HasSwitch(switches::kEnableSmoothScrolling) || |
| 2456 | (!command_line.HasSwitch(switches::kDisableSmoothScrolling) && |
| 2457 | gfx::Animation::ScrollAnimationsEnabledBySystem()); |
| 2458 | |
| 2459 | prefs.prefers_reduced_motion = gfx::Animation::PrefersReducedMotion(); |
| 2460 | |
| 2461 | if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
| 2462 | GetRenderViewHost()->GetProcess()->GetID())) { |
| 2463 | prefs.loads_images_automatically = true; |
| 2464 | prefs.javascript_enabled = true; |
| 2465 | } |
| 2466 | |
| 2467 | prefs.viewport_enabled = command_line.HasSwitch(switches::kEnableViewport); |
| 2468 | |
| 2469 | if (IsOverridingUserAgent()) |
| 2470 | prefs.viewport_meta_enabled = false; |
| 2471 | |
| 2472 | prefs.main_frame_resizes_are_orientation_changes = |
| 2473 | command_line.HasSwitch(switches::kMainFrameResizesAreOrientationChanges); |
| 2474 | |
| 2475 | prefs.spatial_navigation_enabled = |
| 2476 | command_line.HasSwitch(switches::kEnableSpatialNavigation); |
| 2477 | |
| 2478 | if (IsSpatialNavigationDisabled()) |
| 2479 | prefs.spatial_navigation_enabled = false; |
| 2480 | |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 2481 | prefs.disable_reading_from_canvas = |
| 2482 | command_line.HasSwitch(switches::kDisableReadingFromCanvas); |
| 2483 | |
| 2484 | prefs.strict_mixed_content_checking = |
| 2485 | command_line.HasSwitch(switches::kEnableStrictMixedContentChecking); |
| 2486 | |
| 2487 | prefs.strict_powerful_feature_restrictions = command_line.HasSwitch( |
| 2488 | switches::kEnableStrictPowerfulFeatureRestrictions); |
| 2489 | |
| 2490 | const std::string blockable_mixed_content_group = |
| 2491 | base::FieldTrialList::FindFullName("BlockableMixedContent"); |
| 2492 | prefs.strictly_block_blockable_mixed_content = |
| 2493 | blockable_mixed_content_group == "StrictlyBlockBlockableMixedContent"; |
| 2494 | |
| 2495 | const std::string plugin_mixed_content_status = |
| 2496 | base::FieldTrialList::FindFullName("PluginMixedContentStatus"); |
| 2497 | prefs.block_mixed_plugin_content = |
| 2498 | plugin_mixed_content_status == "BlockableMixedContent"; |
| 2499 | |
| 2500 | prefs.v8_cache_options = GetV8CacheOptions(); |
| 2501 | |
| 2502 | prefs.user_gesture_required_for_presentation = !command_line.HasSwitch( |
| 2503 | switches::kDisableGestureRequirementForPresentation); |
| 2504 | |
| 2505 | if (HideDownloadUI()) |
| 2506 | prefs.hide_download_ui = true; |
| 2507 | |
| 2508 | // `media_controls_enabled` is `true` by default. |
| 2509 | if (HasPersistentVideo()) |
| 2510 | prefs.media_controls_enabled = false; |
| 2511 | |
| 2512 | #if defined(OS_ANDROID) |
| 2513 | display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 2514 | gfx::Size size = display.GetSizeInPixel(); |
| 2515 | int min_width = size.width() < size.height() ? size.width() : size.height(); |
| 2516 | prefs.device_scale_adjustment = GetDeviceScaleAdjustment( |
| 2517 | static_cast<int>(min_width / display.device_scale_factor())); |
| 2518 | #endif // OS_ANDROID |
| 2519 | |
| 2520 | GetContentClient()->browser()->OverrideWebkitPrefs(GetRenderViewHost(), |
| 2521 | &prefs); |
| 2522 | return prefs; |
| 2523 | } |
| 2524 | |
| 2525 | void WebContentsImpl::SetSlowWebPreferences( |
| 2526 | const base::CommandLine& command_line, |
Gyuyoung Kim | 1ac4ca78 | 2020-09-11 03:32:51 | [diff] [blame] | 2527 | blink::web_pref::WebPreferences* prefs) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2528 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::SetSlowWebPreferences"); |
| 2529 | |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 2530 | if (web_preferences_.get()) { |
| 2531 | #define SET_FROM_CACHE(prefs, field) prefs->field = web_preferences_->field |
| 2532 | |
| 2533 | SET_FROM_CACHE(prefs, touch_event_feature_detection_enabled); |
| 2534 | SET_FROM_CACHE(prefs, available_pointer_types); |
| 2535 | SET_FROM_CACHE(prefs, available_hover_types); |
| 2536 | SET_FROM_CACHE(prefs, primary_pointer_type); |
| 2537 | SET_FROM_CACHE(prefs, primary_hover_type); |
| 2538 | SET_FROM_CACHE(prefs, pointer_events_max_touch_points); |
| 2539 | SET_FROM_CACHE(prefs, number_of_cpu_cores); |
| 2540 | |
| 2541 | #if defined(OS_ANDROID) |
| 2542 | SET_FROM_CACHE(prefs, video_fullscreen_orientation_lock_enabled); |
| 2543 | SET_FROM_CACHE(prefs, video_rotate_to_fullscreen_enabled); |
| 2544 | #endif |
| 2545 | |
| 2546 | #undef SET_FROM_CACHE |
| 2547 | } else { |
| 2548 | // Every prefs->field modified below should have a SET_FROM_CACHE entry |
| 2549 | // above. |
| 2550 | |
| 2551 | // On Android, Touch event feature detection is enabled by default, |
| 2552 | // Otherwise default is disabled. |
| 2553 | std::string touch_enabled_default_switch = |
| 2554 | switches::kTouchEventFeatureDetectionDisabled; |
| 2555 | #if defined(OS_ANDROID) |
| 2556 | touch_enabled_default_switch = switches::kTouchEventFeatureDetectionEnabled; |
| 2557 | #endif // defined(OS_ANDROID) |
| 2558 | const std::string touch_enabled_switch = |
| 2559 | command_line.HasSwitch(switches::kTouchEventFeatureDetection) |
| 2560 | ? command_line.GetSwitchValueASCII( |
| 2561 | switches::kTouchEventFeatureDetection) |
| 2562 | : touch_enabled_default_switch; |
| 2563 | |
| 2564 | prefs->touch_event_feature_detection_enabled = |
| 2565 | (touch_enabled_switch == switches::kTouchEventFeatureDetectionAuto) |
| 2566 | ? (ui::GetTouchScreensAvailability() == |
| 2567 | ui::TouchScreensAvailability::ENABLED) |
| 2568 | : (touch_enabled_switch.empty() || |
| 2569 | touch_enabled_switch == |
| 2570 | switches::kTouchEventFeatureDetectionEnabled); |
| 2571 | |
| 2572 | std::tie(prefs->available_pointer_types, prefs->available_hover_types) = |
| 2573 | ui::GetAvailablePointerAndHoverTypes(); |
| 2574 | prefs->primary_pointer_type = |
| 2575 | ui::GetPrimaryPointerType(prefs->available_pointer_types); |
| 2576 | prefs->primary_hover_type = |
| 2577 | ui::GetPrimaryHoverType(prefs->available_hover_types); |
| 2578 | |
| 2579 | prefs->pointer_events_max_touch_points = ui::MaxTouchPoints(); |
| 2580 | |
| 2581 | prefs->number_of_cpu_cores = base::SysInfo::NumberOfProcessors(); |
| 2582 | |
| 2583 | #if defined(OS_ANDROID) |
| 2584 | const bool device_is_phone = |
| 2585 | ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_PHONE; |
| 2586 | prefs->video_fullscreen_orientation_lock_enabled = device_is_phone; |
| 2587 | prefs->video_rotate_to_fullscreen_enabled = device_is_phone; |
| 2588 | #endif |
| 2589 | } |
| 2590 | } |
| 2591 | |
| 2592 | void WebContentsImpl::OnWebPreferencesChanged() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2593 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::OnWebPreferencesChanged"); |
| 2594 | |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 2595 | // This is defensive code to avoid infinite loops due to code run inside |
| 2596 | // SetWebPreferences() accidentally updating more preferences and thus |
| 2597 | // calling back into this code. See crbug.com/398751 for one past example. |
| 2598 | if (updating_web_preferences_) |
| 2599 | return; |
| 2600 | updating_web_preferences_ = true; |
| 2601 | SetWebPreferences(ComputeWebPreferences()); |
| 2602 | #if defined(OS_ANDROID) |
| 2603 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 2604 | RenderFrameHostImpl* rfh = node->current_frame_host(); |
| 2605 | if (rfh->is_local_root()) { |
| 2606 | if (auto* rwh = rfh->GetRenderWidgetHost()) |
| 2607 | rwh->SetForceEnableZoom(web_preferences_->force_enable_zoom); |
| 2608 | } |
| 2609 | } |
| 2610 | #endif |
| 2611 | updating_web_preferences_ = false; |
| 2612 | } |
| 2613 | |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 2614 | void WebContentsImpl::NotifyPreferencesChanged() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2615 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::NotifyPreferencesChanged"); |
| 2616 | |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 2617 | // Recompute the WebPreferences based on the current state of the WebContents, |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 2618 | // etc. Note that OnWebPreferencesChanged will also call SetWebPreferences and |
| 2619 | // send the updated WebPreferences to all RenderViews for this WebContents. |
| 2620 | OnWebPreferencesChanged(); |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 2621 | } |
| 2622 | |
Bruce Long | 1e3e1f54 | 2019-10-16 17:56:28 | [diff] [blame] | 2623 | void WebContentsImpl::SyncRendererPrefs() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2624 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::SyncRendererPrefs"); |
| 2625 | |
Mario Sanchez Prada | 0bd8b8c | 2020-10-21 17:49:23 | [diff] [blame] | 2626 | blink::RendererPreferences renderer_preferences = GetRendererPrefs(); |
Bruce Long | 1e3e1f54 | 2019-10-16 17:56:28 | [diff] [blame] | 2627 | RenderViewHostImpl::GetPlatformSpecificPrefs(&renderer_preferences); |
| 2628 | SendPageMessage( |
| 2629 | new PageMsg_SetRendererPrefs(MSG_ROUTING_NONE, renderer_preferences)); |
| 2630 | } |
| 2631 | |
Alexander Timin | 1cc31f4 | 2020-05-12 16:26:01 | [diff] [blame] | 2632 | void WebContentsImpl::OnCookiesAccessed(NavigationHandle* navigation, |
| 2633 | const CookieAccessDetails& details) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2634 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnCookiesAccessed", |
| 2635 | "navigation_handle", navigation); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 2636 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2637 | observer->OnCookiesAccessed(navigation, details); |
| 2638 | }); |
Alexander Timin | 1cc31f4 | 2020-05-12 16:26:01 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | void WebContentsImpl::OnCookiesAccessed(RenderFrameHostImpl* rfh, |
| 2642 | const CookieAccessDetails& details) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2643 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnCookiesAccessed", |
| 2644 | "render_frame_host", |
| 2645 | base::trace_event::ToTracedValue(rfh)); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 2646 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2647 | observer->OnCookiesAccessed(rfh, details); |
| 2648 | }); |
Josh Karlin | daba3932 | 2019-07-17 23:24:33 | [diff] [blame] | 2649 | } |
| 2650 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2651 | void WebContentsImpl::Stop() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2652 | TRACE_EVENT0("content", "WebContentsImpl::Stop"); |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 2653 | for (FrameTreeNode* node : frame_tree_.Nodes()) |
| 2654 | node->StopLoading(); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 2655 | observers_.ForEachObserver( |
| 2656 | [&](WebContentsObserver* observer) { observer->NavigationStopped(); }); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2657 | } |
| 2658 | |
Francois Doray | 47f759d | 2018-06-11 18:13:51 | [diff] [blame] | 2659 | void WebContentsImpl::SetPageFrozen(bool frozen) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2660 | TRACE_EVENT1("content", "WebContentsImpl::SetPageFrozen", "frozen", frozen); |
| 2661 | |
Francois Doray | 47f759d | 2018-06-11 18:13:51 | [diff] [blame] | 2662 | // A visible page is never frozen. |
| 2663 | DCHECK_NE(Visibility::VISIBLE, GetVisibility()); |
| 2664 | |
Yuzu Saijo | 4fa1e9a | 2020-05-20 02:53:26 | [diff] [blame] | 2665 | for (auto& entry : frame_tree_.render_view_hosts()) { |
| 2666 | entry.second->SetIsFrozen(frozen); |
| 2667 | } |
Fadi Meawad | a6573e0 | 2018-03-10 00:52:11 | [diff] [blame] | 2668 | } |
| 2669 | |
erikchen | 6c7df7f7a | 2018-05-03 18:13:59 | [diff] [blame] | 2670 | std::unique_ptr<WebContents> WebContentsImpl::Clone() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2671 | TRACE_EVENT0("content", "WebContentsImpl::Clone"); |
| 2672 | |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2673 | // We use our current SiteInstance since the cloned entry will use it anyway. |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 2674 | // We pass our own opener so that the cloned page can access it if it was set |
[email protected] | ed245db | 2012-12-18 08:00:45 | [diff] [blame] | 2675 | // before. |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 2676 | CreateParams create_params(GetBrowserContext(), GetSiteInstance()); |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 2677 | FrameTreeNode* opener = frame_tree_.root()->opener(); |
| 2678 | RenderFrameHostImpl* opener_rfh = nullptr; |
| 2679 | if (opener) |
| 2680 | opener_rfh = opener->current_frame_host(); |
erikchen | 6c7df7f7a | 2018-05-03 18:13:59 | [diff] [blame] | 2681 | std::unique_ptr<WebContentsImpl> tc = |
erikchen | 50735fd | 2018-05-05 15:08:33 | [diff] [blame] | 2682 | CreateWithOpener(create_params, opener_rfh); |
Lucas Furukawa Gadani | 5553a15 | 2019-01-08 18:55:57 | [diff] [blame] | 2683 | tc->GetController().CopyStateFrom(&controller_, true); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 2684 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2685 | observer->DidCloneToNewWebContents(this, tc.get()); |
| 2686 | }); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2687 | return tc; |
| 2688 | } |
| 2689 | |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2690 | void WebContentsImpl::Observe(int type, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2691 | const NotificationSource& source, |
| 2692 | const NotificationDetails& details) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2693 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::Observe", "type", type); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2694 | switch (type) { |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2695 | case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { |
| 2696 | RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr(); |
Dave Tapuska | 406647a | 2020-10-21 00:55:57 | [diff] [blame] | 2697 | for (auto i = pending_widget_views_.begin(); |
| 2698 | i != pending_widget_views_.end(); ++i) { |
| 2699 | if (host->GetView() == i->second) { |
| 2700 | pending_widget_views_.erase(i); |
| 2701 | break; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2702 | } |
| 2703 | } |
| 2704 | break; |
| 2705 | } |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2706 | default: |
| 2707 | NOTREACHED(); |
| 2708 | } |
| 2709 | } |
| 2710 | |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 2711 | WebContents* WebContentsImpl::GetWebContents() { |
| 2712 | return this; |
| 2713 | } |
| 2714 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 2715 | void WebContentsImpl::Init(const WebContents::CreateParams& params) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2716 | TRACE_EVENT0("content", "WebContentsImpl::Init"); |
| 2717 | |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 2718 | // This is set before initializing the render manager since |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 2719 | // RenderFrameHostManager::Init calls back into us via its delegate to ask if |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 2720 | // it should be hidden. |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 2721 | visibility_ = |
| 2722 | params.initially_hidden ? Visibility::HIDDEN : Visibility::VISIBLE; |
[email protected] | d6fa88f | 2013-10-18 16:00:43 | [diff] [blame] | 2723 | |
Sebastien Marchand | 28cf2318 | 2018-06-20 02:39:35 | [diff] [blame] | 2724 | if (!params.last_active_time.is_null()) |
| 2725 | last_active_time_ = params.last_active_time; |
| 2726 | |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2727 | scoped_refptr<SiteInstance> site_instance = params.site_instance; |
| 2728 | if (!site_instance) |
| 2729 | site_instance = SiteInstance::Create(params.browser_context); |
Lukasz Anforowicz | 3caa837 | 2018-06-05 17:22:07 | [diff] [blame] | 2730 | if (params.desired_renderer_state == CreateParams::kNoRendererProcess) { |
| 2731 | static_cast<SiteInstanceImpl*>(site_instance.get()) |
| 2732 | ->PreventAssociationWithSpareProcess(); |
| 2733 | } |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2734 | |
Fergal Daly | cb0c1fdf | 2020-03-16 07:13:49 | [diff] [blame] | 2735 | GetRenderManager()->InitRoot(site_instance.get(), |
| 2736 | params.renderer_initiated_creation); |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 2737 | |
lukasza | 5140a41 | 2016-09-15 21:12:30 | [diff] [blame] | 2738 | // blink::FrameTree::setName always keeps |unique_name| empty in case of a |
| 2739 | // main frame - let's do the same thing here. |
| 2740 | std::string unique_name; |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 2741 | frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2742 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2743 | WebContentsViewDelegate* delegate = |
| 2744 | GetContentClient()->browser()->GetWebContentsViewDelegate(this); |
| 2745 | |
W. James MacLean | 2539adb3 | 2019-12-13 00:40:44 | [diff] [blame] | 2746 | if (browser_plugin_guest_) { |
Fergal Daly | 55b6d72 | 2020-09-11 07:56:33 | [diff] [blame] | 2747 | view_ = std::make_unique<WebContentsViewChildFrame>( |
| 2748 | this, delegate, &render_view_host_delegate_view_); |
sky | 52a39e34 | 2016-12-17 17:23:22 | [diff] [blame] | 2749 | } else { |
| 2750 | view_.reset(CreateWebContentsView(this, delegate, |
| 2751 | &render_view_host_delegate_view_)); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2752 | } |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2753 | CHECK(render_view_host_delegate_view_); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2754 | CHECK(view_.get()); |
| 2755 | |
danakj | fc518493 | 2019-09-12 18:08:32 | [diff] [blame] | 2756 | view_->CreateView(params.context); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2757 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 2758 | #if BUILDFLAG(ENABLE_PLUGINS) |
Fergal Daly | 55b6d72 | 2020-09-11 07:56:33 | [diff] [blame] | 2759 | plugin_content_origin_allowlist_ = |
| 2760 | std::make_unique<PluginContentOriginAllowlist>(this); |
tommycli | eb25b2a | 2014-11-03 19:45:09 | [diff] [blame] | 2761 | #endif |
| 2762 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2763 | registrar_.Add(this, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2764 | NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 2765 | NotificationService::AllBrowserContextsAndSources()); |
[email protected] | f28ef9a3 | 2014-05-12 16:36:10 | [diff] [blame] | 2766 | |
Fergal Daly | 55b6d72 | 2020-09-11 07:56:33 | [diff] [blame] | 2767 | screen_orientation_provider_ = |
| 2768 | std::make_unique<ScreenOrientationProvider>(this); |
[email protected] | 01f83f9 | 2014-06-17 14:41:54 | [diff] [blame] | 2769 | |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 2770 | #if defined(OS_ANDROID) |
Oksana Zhuravlova | 0b63433 | 2019-10-28 23:04:22 | [diff] [blame] | 2771 | DateTimeChooserAndroid::CreateForWebContents(this); |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 2772 | #endif |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 2773 | |
| 2774 | // BrowserPluginGuest::Init needs to be called after this WebContents has |
W. James MacLean | 6e78da34 | 2019-12-13 15:13:23 | [diff] [blame] | 2775 | // a RenderWidgetHostViewChildFrame. That is, |view_->CreateView| above. |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 2776 | if (browser_plugin_guest_) |
| 2777 | browser_plugin_guest_->Init(); |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 2778 | |
Fergal Daly | 55b6d72 | 2020-09-11 07:56:33 | [diff] [blame] | 2779 | for (auto& i : g_created_callbacks.Get()) |
| 2780 | i.Run(this); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 2781 | |
| 2782 | // If the WebContents creation was renderer-initiated, it means that the |
| 2783 | // corresponding RenderView and main RenderFrame have already been created. |
| 2784 | // Ensure observers are notified about this. |
| 2785 | if (params.renderer_initiated_creation) { |
Fergal Daly | bb2d659 | 2020-06-02 05:02:33 | [diff] [blame] | 2786 | GetRenderViewHost()->GetWidget()->set_renderer_initialized(true); |
Alex Moshchuk | 27caae8 | 2017-09-11 23:11:18 | [diff] [blame] | 2787 | GetRenderViewHost()->DispatchRenderViewCreated(); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 2788 | GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true); |
| 2789 | } |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 2790 | |
lof84 | 501da08 | 2016-05-23 21:22:54 | [diff] [blame] | 2791 | // Create the renderer process in advance if requested. |
Lukasz Anforowicz | 3caa837 | 2018-06-05 17:22:07 | [diff] [blame] | 2792 | if (params.desired_renderer_state == |
| 2793 | CreateParams::kInitializeAndWarmupRendererProcess) { |
lof84 | 501da08 | 2016-05-23 21:22:54 | [diff] [blame] | 2794 | if (!GetRenderManager()->current_frame_host()->IsRenderFrameLive()) { |
| 2795 | GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr); |
| 2796 | } |
| 2797 | } |
| 2798 | |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 2799 | // Ensure that observers are notified of the creation of this WebContents's |
| 2800 | // main RenderFrameHost. It must be done here for main frames, since the |
| 2801 | // NotifySwappedFromRenderManager expects view_ to already be created and that |
| 2802 | // happens after RenderFrameHostManager::Init. |
| 2803 | NotifySwappedFromRenderManager( |
| 2804 | nullptr, GetRenderManager()->current_frame_host(), true); |
Albert J. Wong | e76bf0b8 | 2019-09-27 07:47:06 | [diff] [blame] | 2805 | |
| 2806 | // For WebContents that are never shown, do critical initialization here which |
| 2807 | // would normally only happen when the WebContents is shown. |
| 2808 | if (params.is_never_visible) { |
| 2809 | // This has just been created so there can only be one frame. Thus it is |
| 2810 | // safe to initialize the root. |
| 2811 | GetMainFrame()->Init(); |
| 2812 | } |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2813 | } |
| 2814 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2815 | void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2816 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::OnWebContentsDestroyed"); |
| 2817 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2818 | RemoveDestructionObserver(web_contents); |
| 2819 | |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 2820 | // Clear a pending contents that has been closed before being shown. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2821 | for (auto iter = pending_contents_.begin(); iter != pending_contents_.end(); |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 2822 | ++iter) { |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 2823 | if (iter->second.contents.get() != web_contents) |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 2824 | continue; |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2825 | |
| 2826 | // Someone else has deleted the WebContents. That should never happen! |
| 2827 | // TODO(erikchen): Fix semantics here. https://crbug.com/832879. |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 2828 | iter->second.contents.release(); |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 2829 | pending_contents_.erase(iter); |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 2830 | return; |
| 2831 | } |
| 2832 | NOTREACHED(); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2833 | } |
| 2834 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2835 | void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2836 | OPTIONAL_TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 2837 | "WebContentsImpl::AddDestructionObserver"); |
| 2838 | |
Jan Wilken Dörrie | 73c901e | 2019-06-12 09:02:32 | [diff] [blame] | 2839 | if (!base::Contains(destruction_observers_, web_contents)) { |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2840 | destruction_observers_[web_contents] = |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 2841 | std::make_unique<DestructionObserver>(this, web_contents); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2842 | } |
| 2843 | } |
| 2844 | |
| 2845 | void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2846 | OPTIONAL_TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 2847 | "WebContentsImpl::RemoveDestructionObserver"); |
avi | a8cf8198 | 2016-08-12 20:28:46 | [diff] [blame] | 2848 | destruction_observers_.erase(web_contents); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2849 | } |
| 2850 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2851 | void WebContentsImpl::AddObserver(WebContentsObserver* observer) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2852 | OPTIONAL_TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 2853 | "WebContentsImpl::AddObserver"); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2854 | observers_.AddObserver(observer); |
| 2855 | } |
| 2856 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2857 | void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2858 | OPTIONAL_TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 2859 | "WebContentsImpl::RemoveObserver"); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2860 | observers_.RemoveObserver(observer); |
| 2861 | } |
| 2862 | |
[email protected] | 948481d | 2014-06-11 18:32:22 | [diff] [blame] | 2863 | std::set<RenderWidgetHostView*> |
| 2864 | WebContentsImpl::GetRenderWidgetHostViewsInTree() { |
| 2865 | std::set<RenderWidgetHostView*> set; |
Carlos IL | 07f282f | 2020-05-15 22:58:29 | [diff] [blame] | 2866 | for (RenderFrameHost* rfh : GetAllFrames()) { |
| 2867 | if (RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh) |
| 2868 | ->frame_tree_node() |
| 2869 | ->render_manager() |
| 2870 | ->GetRenderWidgetHostView()) { |
lfg | f949e0e | 2017-05-10 22:18:11 | [diff] [blame] | 2871 | set.insert(rwhv); |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 2872 | } |
[email protected] | 948481d | 2014-06-11 18:32:22 | [diff] [blame] | 2873 | } |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 2874 | return set; |
| 2875 | } |
| 2876 | |
Adithya Srinivasan | e6e7f84 | 2019-12-16 18:41:36 | [diff] [blame] | 2877 | std::set<RenderWidgetHostView*> |
| 2878 | WebContentsImpl::GetRenderWidgetHostViewsInWebContentsTree() { |
| 2879 | std::set<RenderWidgetHostView*> result; |
| 2880 | GetRenderWidgetHostViewsInWebContentsTree(result); |
| 2881 | return result; |
| 2882 | } |
| 2883 | |
| 2884 | void WebContentsImpl::GetRenderWidgetHostViewsInWebContentsTree( |
| 2885 | std::set<RenderWidgetHostView*>& result) { |
| 2886 | std::set<RenderWidgetHostView*> views = GetRenderWidgetHostViewsInTree(); |
| 2887 | result.insert(views.begin(), views.end()); |
| 2888 | for (auto* inner_web_contents : GetInnerWebContents()) { |
| 2889 | static_cast<WebContentsImpl*>(inner_web_contents) |
| 2890 | ->GetRenderWidgetHostViewsInWebContentsTree(result); |
| 2891 | } |
| 2892 | } |
| 2893 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2894 | void WebContentsImpl::Activate() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2895 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::Activate"); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 2896 | if (delegate_) |
| 2897 | delegate_->ActivateContents(this); |
| 2898 | } |
| 2899 | |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 2900 | void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2901 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::LostCapture", |
| 2902 | "render_widget_host", render_widget_host); |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 2903 | if (!RenderViewHostImpl::From(render_widget_host)) |
| 2904 | return; |
| 2905 | |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 2906 | if (delegate_) |
| 2907 | delegate_->LostCapture(); |
| 2908 | } |
| 2909 | |
Yue Ru Sun | 979c4b16 | 2019-11-06 16:11:04 | [diff] [blame] | 2910 | ukm::SourceId |
| 2911 | WebContentsImpl::GetUkmSourceIdForLastCommittedSourceIncludingSameDocument() |
| 2912 | const { |
| 2913 | return last_committed_source_id_including_same_document_; |
| 2914 | } |
| 2915 | |
Ahmed Fakhry | faa32d2 | 2018-10-05 15:56:16 | [diff] [blame] | 2916 | void WebContentsImpl::SetTopControlsShownRatio( |
| 2917 | RenderWidgetHostImpl* render_widget_host, |
| 2918 | float ratio) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2919 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::SetTopControlsShownRatio", |
| 2920 | "render_widget_host", render_widget_host, "ratio", |
| 2921 | ratio); |
Ahmed Fakhry | faa32d2 | 2018-10-05 15:56:16 | [diff] [blame] | 2922 | if (!delegate_) |
| 2923 | return; |
| 2924 | |
| 2925 | RenderFrameHostImpl* rfh = GetMainFrame(); |
| 2926 | if (!rfh || render_widget_host != rfh->GetRenderWidgetHost()) |
| 2927 | return; |
| 2928 | |
| 2929 | delegate_->SetTopControlsShownRatio(this, ratio); |
Ahmed Fakhry | 58e6ef54 | 2018-09-04 18:05:38 | [diff] [blame] | 2930 | } |
| 2931 | |
Ahmed Fakhry | 58e6ef54 | 2018-09-04 18:05:38 | [diff] [blame] | 2932 | void WebContentsImpl::SetTopControlsGestureScrollInProgress(bool in_progress) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2933 | OPTIONAL_TRACE_EVENT1( |
| 2934 | "content", "WebContentsImpl::SetTopControlsGestureScrollInProgress", |
| 2935 | "in_progress", in_progress); |
Ahmed Fakhry | 58e6ef54 | 2018-09-04 18:05:38 | [diff] [blame] | 2936 | if (delegate_) |
| 2937 | delegate_->SetTopControlsGestureScrollInProgress(in_progress); |
| 2938 | } |
| 2939 | |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 2940 | void WebContentsImpl::RenderWidgetCreated( |
| 2941 | RenderWidgetHostImpl* render_widget_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2942 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::RenderWidgetCreated", |
| 2943 | "render_widget_host", render_widget_host); |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 2944 | created_widgets_.insert(render_widget_host); |
| 2945 | } |
| 2946 | |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 2947 | void WebContentsImpl::RenderWidgetDeleted( |
| 2948 | RenderWidgetHostImpl* render_widget_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2949 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::RenderWidgetDeleted", |
| 2950 | "render_widget_host", render_widget_host); |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 2951 | // Note that |is_being_destroyed_| can be true at this point as |
| 2952 | // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead |
| 2953 | // us here. |
| 2954 | created_widgets_.erase(render_widget_host); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 2955 | |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 2956 | if (is_being_destroyed_) |
| 2957 | return; |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 2958 | |
lfg | 7d4caad | 2017-03-22 09:01:45 | [diff] [blame] | 2959 | if (render_widget_host == mouse_lock_widget_) |
lfg | ff8dfc8d | 2016-10-21 17:42:32 | [diff] [blame] | 2960 | LostMouseLock(mouse_lock_widget_); |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 2961 | |
Joe Downing | c1a57efe | 2018-05-09 18:23:54 | [diff] [blame] | 2962 | CancelKeyboardLock(render_widget_host); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 2963 | } |
| 2964 | |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 2965 | void WebContentsImpl::RenderWidgetWasResized( |
rouslan | 2f5993f | 2015-01-29 00:18:31 | [diff] [blame] | 2966 | RenderWidgetHostImpl* render_widget_host, |
| 2967 | bool width_changed) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2968 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::RenderWidgetWasResized", |
| 2969 | "render_widget_host", render_widget_host, |
| 2970 | "width_changed", width_changed); |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2971 | RenderFrameHostImpl* rfh = GetMainFrame(); |
estade | ce344ec | 2015-01-23 00:12:29 | [diff] [blame] | 2972 | if (!rfh || render_widget_host != rfh->GetRenderWidgetHost()) |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 2973 | return; |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 2974 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 2975 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2976 | observer->MainFrameWasResized(width_changed); |
| 2977 | }); |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 2978 | } |
| 2979 | |
sky | f65d9bb | 2017-03-24 02:26:39 | [diff] [blame] | 2980 | KeyboardEventProcessingResult WebContentsImpl::PreHandleKeyboardEvent( |
| 2981 | const NativeWebKeyboardEvent& event) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 2982 | OPTIONAL_TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 2983 | "WebContentsImpl::PreHandleKeyboardEvent"); |
W. James MacLean | e118727 | 2019-11-12 03:42:48 | [diff] [blame] | 2984 | auto* outermost_contents = GetOutermostWebContents(); |
| 2985 | // TODO(wjmaclean): Generalize this to forward all key events to the outermost |
| 2986 | // delegate's handler. |
Avi Drissman | 97aef04 | 2020-06-30 21:04:48 | [diff] [blame] | 2987 | if (outermost_contents != this && IsFullscreen() && |
W. James MacLean | e118727 | 2019-11-12 03:42:48 | [diff] [blame] | 2988 | event.windows_key_code == ui::VKEY_ESCAPE) { |
| 2989 | // When an inner WebContents has focus and is fullscreen, redirect <esc> |
| 2990 | // key events to the outermost WebContents so it can be handled by that |
| 2991 | // WebContents' delegate. |
| 2992 | if (outermost_contents->PreHandleKeyboardEvent(event) == |
| 2993 | KeyboardEventProcessingResult::HANDLED) { |
| 2994 | return KeyboardEventProcessingResult::HANDLED; |
| 2995 | } |
| 2996 | } |
sky | f65d9bb | 2017-03-24 02:26:39 | [diff] [blame] | 2997 | return delegate_ ? delegate_->PreHandleKeyboardEvent(this, event) |
| 2998 | : KeyboardEventProcessingResult::NOT_HANDLED; |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 2999 | } |
| 3000 | |
Dave Tapuska | 344399e | 2019-09-09 15:18:26 | [diff] [blame] | 3001 | bool WebContentsImpl::HandleMouseEvent(const blink::WebMouseEvent& event) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3002 | OPTIONAL_TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 3003 | "WebContentsImpl::HandleMouseEvent"); |
Dave Tapuska | 344399e | 2019-09-09 15:18:26 | [diff] [blame] | 3004 | // Handle mouse button back/forward in the browser process after the render |
| 3005 | // process is done with the event. This ensures all renderer-initiated history |
| 3006 | // navigations can be treated consistently. |
| 3007 | if (event.GetType() == blink::WebInputEvent::Type::kMouseUp) { |
| 3008 | WebContentsImpl* outermost = GetOutermostWebContents(); |
| 3009 | if (event.button == blink::WebPointerProperties::Button::kBack && |
| 3010 | outermost->controller_.CanGoBack()) { |
| 3011 | outermost->controller_.GoBack(); |
| 3012 | return true; |
| 3013 | } else if (event.button == blink::WebPointerProperties::Button::kForward && |
| 3014 | outermost->controller_.CanGoForward()) { |
| 3015 | outermost->controller_.GoForward(); |
| 3016 | return true; |
| 3017 | } |
| 3018 | } |
| 3019 | return false; |
| 3020 | } |
| 3021 | |
Scott Violet | d5caa87 | 2018-10-16 22:00:51 | [diff] [blame] | 3022 | bool WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3023 | OPTIONAL_TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 3024 | "WebContentsImpl::HandleKeyboardEvent"); |
[email protected] | 0b09400 | 2014-08-20 18:28:10 | [diff] [blame] | 3025 | if (browser_plugin_embedder_ && |
| 3026 | browser_plugin_embedder_->HandleKeyboardEvent(event)) { |
Scott Violet | d5caa87 | 2018-10-16 22:00:51 | [diff] [blame] | 3027 | return true; |
[email protected] | 0b09400 | 2014-08-20 18:28:10 | [diff] [blame] | 3028 | } |
Scott Violet | d5caa87 | 2018-10-16 22:00:51 | [diff] [blame] | 3029 | return delegate_ && delegate_->HandleKeyboardEvent(this, event); |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 3030 | } |
| 3031 | |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3032 | bool WebContentsImpl::HandleWheelEvent(const blink::WebMouseWheelEvent& event) { |
| 3033 | OPTIONAL_TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 3034 | "WebContentsImpl::HandleWheelEvent"); |
Avi Drissman | 7c57be7 | 2020-07-29 20:09:46 | [diff] [blame] | 3035 | #if !defined(OS_MAC) |
lanwei | a93644f | 2015-01-21 22:00:33 | [diff] [blame] | 3036 | // On platforms other than Mac, control+mousewheel may change zoom. On Mac, |
| 3037 | // this isn't done for two reasons: |
[email protected] | bccc447 | 2013-04-18 16:37:19 | [diff] [blame] | 3038 | // -the OS already has a gesture to do this through pinch-zoom |
| 3039 | // -if a user starts an inertial scroll, let's go, and presses control |
| 3040 | // (i.e. control+tab) then the OS's buffered scroll events will come in |
| 3041 | // with control key set which isn't what the user wants |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 3042 | if (delegate_ && event.wheel_ticks_y && |
Ehsan Karamad | 0f83cb11 | 2018-09-06 22:07:36 | [diff] [blame] | 3043 | event.event_action == blink::WebMouseWheelEvent::EventAction::kPageZoom) { |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 3044 | // Count only integer cumulative scrolls as zoom events; this handles |
| 3045 | // smooth scroll and regular scroll device behavior. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 3046 | zoom_scroll_remainder_ += event.wheel_ticks_y; |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 3047 | int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_); |
| 3048 | zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_; |
| 3049 | if (whole_zoom_scroll_remainder_ != 0) { |
| 3050 | delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0); |
| 3051 | } |
[email protected] | fb3f066e | 2013-02-12 19:12:52 | [diff] [blame] | 3052 | return true; |
| 3053 | } |
[email protected] | bccc447 | 2013-04-18 16:37:19 | [diff] [blame] | 3054 | #endif |
[email protected] | fb3f066e | 2013-02-12 19:12:52 | [diff] [blame] | 3055 | return false; |
| 3056 | } |
| 3057 | |
[email protected] | 04bce56 | 2014-01-30 05:34:54 | [diff] [blame] | 3058 | bool WebContentsImpl::PreHandleGestureEvent( |
| 3059 | const blink::WebGestureEvent& event) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3060 | OPTIONAL_TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 3061 | "WebContentsImpl::PreHandleGestureEvent"); |
[email protected] | 28042d3 | 2014-02-03 14:10:03 | [diff] [blame] | 3062 | return delegate_ && delegate_->PreHandleGestureEvent(this, event); |
[email protected] | 04bce56 | 2014-01-30 05:34:54 | [diff] [blame] | 3063 | } |
| 3064 | |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 3065 | RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() { |
wjmaclean | e31234f | 2015-12-14 17:20:45 | [diff] [blame] | 3066 | if (!is_being_destroyed_ && GetOuterWebContents()) |
| 3067 | return GetOuterWebContents()->GetInputEventRouter(); |
| 3068 | |
| 3069 | if (!rwh_input_event_router_.get() && !is_being_destroyed_) |
Fergal Daly | 55b6d72 | 2020-09-11 07:56:33 | [diff] [blame] | 3070 | rwh_input_event_router_ = |
| 3071 | std::make_unique<RenderWidgetHostInputEventRouter>(); |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 3072 | return rwh_input_event_router_.get(); |
| 3073 | } |
| 3074 | |
alexmos | 3fcd0ca | 2015-10-23 18:18:33 | [diff] [blame] | 3075 | void WebContentsImpl::ReplicatePageFocus(bool is_focused) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3076 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::ReplicatePageFocus", |
| 3077 | "is_focused", is_focused); |
alexmos | 3fcd0ca | 2015-10-23 18:18:33 | [diff] [blame] | 3078 | // Focus loss may occur while this WebContents is being destroyed. Don't |
| 3079 | // send the message in this case, as the main frame's RenderFrameHost and |
| 3080 | // other state has already been cleared. |
| 3081 | if (is_being_destroyed_) |
| 3082 | return; |
| 3083 | |
| 3084 | frame_tree_.ReplicatePageFocus(is_focused); |
| 3085 | } |
| 3086 | |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 3087 | RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost( |
| 3088 | RenderWidgetHostImpl* receiving_widget) { |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 3089 | // Events for widgets other than the main frame (e.g., popup menus) should be |
| 3090 | // forwarded directly to the widget they arrived on. |
| 3091 | if (receiving_widget != GetMainFrame()->GetRenderWidgetHost()) |
| 3092 | return receiving_widget; |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 3093 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 3094 | // If the focused WebContents is a guest WebContents, then get the focused |
| 3095 | // frame in the embedder WebContents instead. |
W. James MacLean | 13d834d | 2019-12-04 16:06:45 | [diff] [blame] | 3096 | FrameTreeNode* focused_frame = |
| 3097 | GetFocusedWebContents()->frame_tree_.GetFocusedFrame(); |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 3098 | |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 3099 | if (!focused_frame) |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 3100 | return receiving_widget; |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 3101 | |
alexmos | 732ca3a | 2015-12-08 02:01:02 | [diff] [blame] | 3102 | // The view may be null if a subframe's renderer process has crashed while |
| 3103 | // the subframe has focus. Drop the event in that case. Do not give |
| 3104 | // it to the main frame, so that the user doesn't unexpectedly type into the |
| 3105 | // wrong frame if a focused subframe renderer crashes while they type. |
| 3106 | RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView(); |
| 3107 | if (!view) |
| 3108 | return nullptr; |
| 3109 | |
| 3110 | return RenderWidgetHostImpl::From(view->GetRenderWidgetHost()); |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 3111 | } |
| 3112 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 3113 | RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() { |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 3114 | WebContentsImpl* focused_web_contents = GetFocusedWebContents(); |
| 3115 | |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 3116 | return focused_web_contents->GetMainFrame()->GetRenderWidgetHost(); |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 3117 | } |
| 3118 | |
Avi Drissman | d1d2565 | 2020-03-06 21:28:58 | [diff] [blame] | 3119 | bool WebContentsImpl::CanEnterFullscreenMode() { |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 3120 | // It's possible that this WebContents was spawned while blocking UI was on |
| 3121 | // the screen, or that it was downstream from a WebContents when UI was |
| 3122 | // blocked. Therefore, disqualify it from fullscreen if it or any upstream |
| 3123 | // WebContents has an active blocker. |
| 3124 | auto openers = GetAllOpeningWebContents(this); |
| 3125 | return std::all_of(openers.begin(), openers.end(), [](auto* opener) { |
| 3126 | return opener->fullscreen_blocker_count_ == 0; |
| 3127 | }); |
Avi Drissman | d1d2565 | 2020-03-06 21:28:58 | [diff] [blame] | 3128 | } |
| 3129 | |
Dave Tapuska | 3ed4419 | 2018-05-01 18:53:30 | [diff] [blame] | 3130 | void WebContentsImpl::EnterFullscreenMode( |
Mike Wasserman | 4ca0979 | 2020-05-29 17:44:43 | [diff] [blame] | 3131 | RenderFrameHost* requesting_frame, |
Dave Tapuska | a418951 | 2019-10-15 20:27:34 | [diff] [blame] | 3132 | const blink::mojom::FullscreenOptions& options) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3133 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::EnterFullscreenMode"); |
Avi Drissman | d1d2565 | 2020-03-06 21:28:58 | [diff] [blame] | 3134 | DCHECK(CanEnterFullscreenMode()); |
| 3135 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 3136 | if (delegate_) { |
Mike Wasserman | 4ca0979 | 2020-05-29 17:44:43 | [diff] [blame] | 3137 | delegate_->EnterFullscreenModeForTab(requesting_frame, options); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 3138 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 3139 | if (keyboard_lock_widget_) |
| 3140 | delegate_->RequestKeyboardLock(this, esc_key_locked_); |
| 3141 | } |
| 3142 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 3143 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 3144 | observer->DidToggleFullscreenModeForTab(IsFullscreen(), false); |
| 3145 | }); |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 3146 | FullscreenContentsSet(GetBrowserContext())->insert(this); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 3147 | } |
| 3148 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 3149 | void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3150 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::ExitFullscreenMode", |
| 3151 | "will_cause_resize", will_cause_resize); |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 3152 | if (delegate_) { |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 3153 | delegate_->ExitFullscreenModeForTab(this); |
[email protected] | 657c8e0 | 2014-03-19 19:18:37 | [diff] [blame] | 3154 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 3155 | if (keyboard_lock_widget_) |
| 3156 | delegate_->CancelKeyboardLockRequest(this); |
| 3157 | } |
| 3158 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 3159 | // The fullscreen state is communicated to the renderer through a resize |
| 3160 | // message. If the change in fullscreen state doesn't cause a view resize |
| 3161 | // then we must ensure web contents exit the fullscreen state by explicitly |
| 3162 | // sending a resize message. This is required for the situation of the browser |
| 3163 | // moving the view into a "browser fullscreen" state and then the contents |
| 3164 | // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't |
| 3165 | // have the side effect of the view resizing, hence the explicit call here is |
| 3166 | // required. |
| 3167 | if (!will_cause_resize) { |
| 3168 | if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) { |
| 3169 | if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost()) |
Fady Samuel | 0b91182 | 2018-04-25 13:22:16 | [diff] [blame] | 3170 | render_widget_host->SynchronizeVisualProperties(); |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 3171 | } |
scheib | 3dcb6c93 | 2015-02-23 10:55:58 | [diff] [blame] | 3172 | } |
| 3173 | |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 3174 | current_fullscreen_frame_ = nullptr; |
Becca Hughes | e9e2795 | 2018-06-25 17:08:27 | [diff] [blame] | 3175 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 3176 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 3177 | observer->DidToggleFullscreenModeForTab(IsFullscreen(), will_cause_resize); |
| 3178 | }); |
Becca Hughes | d11d650 | 2018-07-31 17:01:28 | [diff] [blame] | 3179 | |
| 3180 | if (display_cutout_host_impl_) |
| 3181 | display_cutout_host_impl_->DidExitFullscreen(); |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 3182 | |
| 3183 | FullscreenContentsSet(GetBrowserContext())->erase(this); |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 3184 | } |
| 3185 | |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 3186 | void WebContentsImpl::FullscreenStateChanged(RenderFrameHost* rfh, |
| 3187 | bool is_fullscreen) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3188 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::FullscreenStateChanged", |
| 3189 | "render_frame_host", rfh, "is_fullscreen", |
| 3190 | is_fullscreen); |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 3191 | RenderFrameHostImpl* frame = static_cast<RenderFrameHostImpl*>(rfh); |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 3192 | |
| 3193 | if (is_fullscreen) { |
Jan Wilken Dörrie | 531be7ca | 2019-06-07 10:05:57 | [diff] [blame] | 3194 | if (!base::Contains(fullscreen_frames_, frame)) { |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 3195 | fullscreen_frames_.insert(frame); |
| 3196 | FullscreenFrameSetUpdated(); |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 3197 | } |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 3198 | return; |
| 3199 | } |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 3200 | |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 3201 | // If |frame| is no longer in fullscreen, remove it and any descendants. |
| 3202 | // See https://fullscreen.spec.whatwg.org. |
Arthur Sonzogni | 969a794e | 2018-10-11 08:56:09 | [diff] [blame] | 3203 | size_t size_before_deletion = fullscreen_frames_.size(); |
| 3204 | base::EraseIf(fullscreen_frames_, [&](RenderFrameHostImpl* current) { |
| 3205 | return (current == frame || current->IsDescendantOf(frame)); |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 3206 | }); |
| 3207 | |
Arthur Sonzogni | 969a794e | 2018-10-11 08:56:09 | [diff] [blame] | 3208 | if (size_before_deletion != fullscreen_frames_.size()) |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 3209 | FullscreenFrameSetUpdated(); |
| 3210 | } |
| 3211 | |
| 3212 | void WebContentsImpl::FullscreenFrameSetUpdated() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3213 | OPTIONAL_TRACE_EVENT0("content", |
| 3214 | "WebContentsImpl::FullscreenFrameSetUpdated"); |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 3215 | if (fullscreen_frames_.empty()) { |
| 3216 | current_fullscreen_frame_ = nullptr; |
| 3217 | return; |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 3218 | } |
| 3219 | |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 3220 | // Find the current fullscreen frame and call the observers. |
| 3221 | // If frame A is fullscreen, then frame B goes into inner fullscreen, then B |
| 3222 | // exits fullscreen - that will result in A being fullscreen. |
| 3223 | RenderFrameHostImpl* new_fullscreen_frame = *std::max_element( |
| 3224 | fullscreen_frames_.begin(), fullscreen_frames_.end(), FrameCompareDepth); |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 3225 | |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 3226 | // If we have already notified observers about this frame then we should not |
| 3227 | // fire the observers again. |
| 3228 | if (new_fullscreen_frame == current_fullscreen_frame_) |
| 3229 | return; |
| 3230 | current_fullscreen_frame_ = new_fullscreen_frame; |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 3231 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 3232 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 3233 | observer->DidAcquireFullscreen(new_fullscreen_frame); |
| 3234 | }); |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 3235 | if (display_cutout_host_impl_) |
| 3236 | display_cutout_host_impl_->DidAcquireFullscreen(new_fullscreen_frame); |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 3237 | } |
| 3238 | |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3239 | void WebContentsImpl::UpdateVisibilityAndNotifyPageAndView( |
| 3240 | Visibility new_visibility) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3241 | OPTIONAL_TRACE_EVENT1("content", |
| 3242 | "WebContentsImpl::UpdateVisibilityAndNotifyPageAndView", |
| 3243 | "new_visibility", static_cast<int>(new_visibility)); |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3244 | // Only hide the page if there are no entities capturing screenshots |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 3245 | // or video (e.g. mirroring). If there are, apply the correct state of |
| 3246 | // kHidden or kHiddenButPainting. |
| 3247 | PageVisibilityState page_visibility; |
| 3248 | if (new_visibility == Visibility::VISIBLE || visible_capturer_count_ > 0) |
| 3249 | page_visibility = PageVisibilityState::kVisible; |
| 3250 | else if (hidden_capturer_count_ > 0) |
| 3251 | page_visibility = PageVisibilityState::kHiddenButPainting; |
| 3252 | else |
| 3253 | page_visibility = PageVisibilityState::kHidden; |
Fergal Daly | 6de62f5 | 2020-10-14 01:56:44 | [diff] [blame] | 3254 | // If there are entities in Picture-in-Picture mode, don't activate the |
| 3255 | // "disable rendering" optimization. A crashed frame might be covered by a sad |
| 3256 | // tab. See docs on SadTabHelper exactly when it is or isn't. Either way, |
| 3257 | // don't make it visible. |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 3258 | const bool view_is_visible = |
Fergal Daly | 6de62f5 | 2020-10-14 01:56:44 | [diff] [blame] | 3259 | !IsCrashed() && (page_visibility != PageVisibilityState::kHidden || |
| 3260 | HasPictureInPictureVideo()); |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3261 | |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 3262 | if (page_visibility != PageVisibilityState::kHidden) { |
Dana Fried | cf3bc8e | 2019-11-13 20:00:24 | [diff] [blame] | 3263 | // We cannot show a page or capture video unless there is a valid renderer |
| 3264 | // associated with this web contents. The navigation controller for this |
| 3265 | // page must be set to active (allowing navigation to complete, a renderer |
| 3266 | // and its associated views to be created, etc.) if any of these conditions |
| 3267 | // holds. |
| 3268 | // |
| 3269 | // Previously, it was possible for browser-side code to try to capture video |
| 3270 | // from a restored tab (for a variety of reasons, including the browser |
| 3271 | // creating preview thumbnails) and the tab would never actually load. By |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 3272 | // keying this behavior off of |page_visibility| instead of just |
Dana Fried | cf3bc8e | 2019-11-13 20:00:24 | [diff] [blame] | 3273 | // |new_visibility| we avoid this case. See crbug.com/1020782 for more |
| 3274 | // context. |
| 3275 | controller_.SetActive(true); |
| 3276 | |
| 3277 | // This shows the Page before showing the individual RenderWidgets, as |
| 3278 | // RenderWidgets will work to produce compositor frames and handle input |
| 3279 | // as soon as they are shown. But the Page and other classes do not expect |
| 3280 | // to be producing frames when the Page is hidden. So we make sure the Page |
| 3281 | // is shown first. |
Yuzu Saijo | 232076f | 2020-05-29 07:14:02 | [diff] [blame] | 3282 | for (auto* rvh : GetRenderViewHostsIncludingBackForwardCached()) { |
| 3283 | rvh->SetVisibility(page_visibility); |
Yuzu Saijo | be024af0 | 2020-05-11 07:35:56 | [diff] [blame] | 3284 | } |
Collin Baker | 98457b5 | 2019-11-06 21:34:29 | [diff] [blame] | 3285 | } |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3286 | |
| 3287 | // |GetRenderWidgetHostView()| can be null if the user middle clicks a link to |
| 3288 | // open a tab in the background, then closes the tab before selecting it. |
| 3289 | // This is because closing the tab calls WebContentsImpl::Destroy(), which |
| 3290 | // removes the |GetRenderViewHost()|; then when we actually destroy the |
| 3291 | // window, OnWindowPosChanged() notices and calls WasHidden() (which |
| 3292 | // calls us). |
| 3293 | if (auto* view = GetRenderWidgetHostView()) { |
| 3294 | if (view_is_visible) { |
| 3295 | view->Show(); |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3296 | } else if (new_visibility == Visibility::HIDDEN) { |
| 3297 | view->Hide(); |
| 3298 | } else { |
| 3299 | view->WasOccluded(); |
| 3300 | } |
| 3301 | } |
| 3302 | |
Carlos IL | 07f282f | 2020-05-15 22:58:29 | [diff] [blame] | 3303 | SetVisibilityForChildViews(view_is_visible); |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3304 | |
| 3305 | // Make sure to call SetVisibilityAndNotifyObservers(VISIBLE) before notifying |
| 3306 | // the CrossProcessFrameConnector. |
| 3307 | if (new_visibility == Visibility::VISIBLE) { |
| 3308 | last_active_time_ = base::TimeTicks::Now(); |
| 3309 | SetVisibilityAndNotifyObservers(new_visibility); |
| 3310 | } |
| 3311 | |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 3312 | if (page_visibility == PageVisibilityState::kHidden) { |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3313 | // Similar to when showing the page, we only hide the page after |
| 3314 | // hiding the individual RenderWidgets. |
Yuzu Saijo | 232076f | 2020-05-29 07:14:02 | [diff] [blame] | 3315 | for (auto* rvh : GetRenderViewHostsIncludingBackForwardCached()) { |
| 3316 | rvh->SetVisibility(page_visibility); |
Yuzu Saijo | be024af0 | 2020-05-11 07:35:56 | [diff] [blame] | 3317 | } |
| 3318 | |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3319 | } else { |
| 3320 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 3321 | RenderFrameProxyHost* parent = node->render_manager()->GetProxyToParent(); |
| 3322 | if (!parent) |
| 3323 | continue; |
| 3324 | |
| 3325 | parent->cross_process_frame_connector()->DelegateWasShown(); |
| 3326 | } |
| 3327 | } |
| 3328 | |
| 3329 | if (new_visibility != Visibility::VISIBLE) |
| 3330 | SetVisibilityAndNotifyObservers(new_visibility); |
| 3331 | } |
| 3332 | |
Clark DuVall | a0e4299 | 2018-09-17 17:00:11 | [diff] [blame] | 3333 | #if defined(OS_ANDROID) |
| 3334 | void WebContentsImpl::UpdateUserGestureCarryoverInfo() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3335 | OPTIONAL_TRACE_EVENT0("content", |
| 3336 | "WebContentsImpl::UpdateUserGestureCarryoverInfo"); |
Clark DuVall | a0e4299 | 2018-09-17 17:00:11 | [diff] [blame] | 3337 | if (delegate_) |
| 3338 | delegate_->UpdateUserGestureCarryoverInfo(this); |
| 3339 | } |
| 3340 | #endif |
| 3341 | |
Avi Drissman | 97aef04 | 2020-06-30 21:04:48 | [diff] [blame] | 3342 | bool WebContentsImpl::IsFullscreen() { |
[email protected] | 199bba6e | 2012-04-04 16:19:38 | [diff] [blame] | 3343 | return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false; |
[email protected] | 5d5f7af | 2011-10-01 01:38:12 | [diff] [blame] | 3344 | } |
| 3345 | |
Malay Keshav | 87c42c0 | 2019-01-15 08:37:47 | [diff] [blame] | 3346 | bool WebContentsImpl::ShouldShowStaleContentOnEviction() { |
| 3347 | return GetDelegate() && GetDelegate()->ShouldShowStaleContentOnEviction(this); |
| 3348 | } |
| 3349 | |
danakj | 45d4245 | 2020-04-08 17:24:18 | [diff] [blame] | 3350 | blink::mojom::DisplayMode WebContentsImpl::GetDisplayMode() const { |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 3351 | return delegate_ ? delegate_->GetDisplayMode(this) |
Eric Willigers | 052f043 | 2019-10-04 04:06:57 | [diff] [blame] | 3352 | : blink::mojom::DisplayMode::kBrowser; |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 3353 | } |
| 3354 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 3355 | void WebContentsImpl::RequestToLockMouse( |
| 3356 | RenderWidgetHostImpl* render_widget_host, |
| 3357 | bool user_gesture, |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 3358 | bool last_unlocked_by_target, |
| 3359 | bool privileged) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3360 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::RequestToLockMouse", |
| 3361 | "render_widget_host", render_widget_host, "privileged", |
| 3362 | privileged); |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3363 | for (WebContentsImpl* current = this; current; |
| 3364 | current = current->GetOuterWebContents()) { |
| 3365 | if (current->mouse_lock_widget_) { |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 3366 | render_widget_host->GotResponseToLockMouseRequest( |
| 3367 | blink::mojom::PointerLockResult::kAlreadyLocked); |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3368 | return; |
| 3369 | } |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 3370 | } |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 3371 | |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 3372 | if (privileged) { |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3373 | DCHECK(!GetOuterWebContents()); |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 3374 | mouse_lock_widget_ = render_widget_host; |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 3375 | render_widget_host->GotResponseToLockMouseRequest( |
| 3376 | blink::mojom::PointerLockResult::kSuccess); |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 3377 | return; |
| 3378 | } |
| 3379 | |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 3380 | bool widget_in_frame_tree = false; |
| 3381 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 3382 | if (node->current_frame_host()->GetRenderWidgetHost() == |
| 3383 | render_widget_host) { |
| 3384 | widget_in_frame_tree = true; |
| 3385 | break; |
| 3386 | } |
| 3387 | } |
| 3388 | |
| 3389 | if (widget_in_frame_tree && delegate_) { |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3390 | for (WebContentsImpl* current = this; current; |
| 3391 | current = current->GetOuterWebContents()) { |
| 3392 | current->mouse_lock_widget_ = render_widget_host; |
| 3393 | } |
| 3394 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 3395 | delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target); |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 3396 | } else { |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 3397 | render_widget_host->GotResponseToLockMouseRequest( |
| 3398 | blink::mojom::PointerLockResult::kWrongDocument); |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 3399 | } |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 3400 | } |
| 3401 | |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 3402 | void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3403 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::LostMouseLock", |
| 3404 | "render_widget_host", render_widget_host); |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 3405 | CHECK(mouse_lock_widget_); |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3406 | |
| 3407 | if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) |
| 3408 | return mouse_lock_widget_->delegate()->LostMouseLock(render_widget_host); |
| 3409 | |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 3410 | mouse_lock_widget_->SendMouseLockLost(); |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3411 | for (WebContentsImpl* current = this; current; |
| 3412 | current = current->GetOuterWebContents()) { |
| 3413 | current->mouse_lock_widget_ = nullptr; |
| 3414 | } |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 3415 | |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 3416 | if (delegate_) |
| 3417 | delegate_->LostMouseLock(); |
| 3418 | } |
| 3419 | |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 3420 | bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) { |
| 3421 | // To verify if the mouse is locked, the mouse_lock_widget_ needs to be |
| 3422 | // assigned to the widget that requested the mouse lock, and the top-level |
| 3423 | // platform RenderWidgetHostView needs to hold the mouse lock from the OS. |
Lucas Gadani | a0ea017 | 2018-09-20 18:31:37 | [diff] [blame] | 3424 | auto* widget_host = GetTopLevelRenderWidgetHostView(); |
| 3425 | return mouse_lock_widget_ == render_widget_host && widget_host && |
| 3426 | widget_host->IsMouseLocked(); |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 3427 | } |
| 3428 | |
lfg | 84763c9 | 2017-02-16 18:55:15 | [diff] [blame] | 3429 | RenderWidgetHostImpl* WebContentsImpl::GetMouseLockWidget() { |
Lucas Gadani | a0ea017 | 2018-09-20 18:31:37 | [diff] [blame] | 3430 | auto* widget_host = GetTopLevelRenderWidgetHostView(); |
Dave Tapuska | 406647a | 2020-10-21 00:55:57 | [diff] [blame] | 3431 | if (widget_host && widget_host->IsMouseLocked()) { |
lfg | 84763c9 | 2017-02-16 18:55:15 | [diff] [blame] | 3432 | return mouse_lock_widget_; |
Lucas Gadani | a0ea017 | 2018-09-20 18:31:37 | [diff] [blame] | 3433 | } |
lfg | 84763c9 | 2017-02-16 18:55:15 | [diff] [blame] | 3434 | |
| 3435 | return nullptr; |
| 3436 | } |
| 3437 | |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 3438 | bool WebContentsImpl::RequestKeyboardLock( |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 3439 | RenderWidgetHostImpl* render_widget_host, |
| 3440 | bool esc_key_locked) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3441 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::RequestKeyboardLock", |
| 3442 | "render_widget_host", render_widget_host, |
| 3443 | "esc_key_locked", esc_key_locked); |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 3444 | DCHECK(render_widget_host); |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 3445 | if (render_widget_host->delegate()->GetAsWebContents() != this) { |
| 3446 | NOTREACHED(); |
| 3447 | return false; |
| 3448 | } |
| 3449 | |
| 3450 | // KeyboardLock is only supported when called by the top-level browsing |
| 3451 | // context and is not supported in embedded content scenarios. |
| 3452 | if (GetOuterWebContents()) |
| 3453 | return false; |
| 3454 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 3455 | esc_key_locked_ = esc_key_locked; |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 3456 | keyboard_lock_widget_ = render_widget_host; |
| 3457 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 3458 | if (delegate_) |
| 3459 | delegate_->RequestKeyboardLock(this, esc_key_locked_); |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 3460 | return true; |
| 3461 | } |
| 3462 | |
| 3463 | void WebContentsImpl::CancelKeyboardLock( |
| 3464 | RenderWidgetHostImpl* render_widget_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3465 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::CancelKeyboardLockRequest", |
| 3466 | "render_widget_host", render_widget_host); |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 3467 | if (!keyboard_lock_widget_ || render_widget_host != keyboard_lock_widget_) |
| 3468 | return; |
| 3469 | |
| 3470 | RenderWidgetHostImpl* old_keyboard_lock_widget = keyboard_lock_widget_; |
| 3471 | keyboard_lock_widget_ = nullptr; |
| 3472 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 3473 | if (delegate_) |
| 3474 | delegate_->CancelKeyboardLockRequest(this); |
| 3475 | |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 3476 | old_keyboard_lock_widget->CancelKeyboardLock(); |
| 3477 | } |
| 3478 | |
| 3479 | RenderWidgetHostImpl* WebContentsImpl::GetKeyboardLockWidget() { |
| 3480 | return keyboard_lock_widget_; |
| 3481 | } |
| 3482 | |
Dave Tapuska | c334436 | 2019-02-20 17:54:28 | [diff] [blame] | 3483 | void WebContentsImpl::OnRenderFrameProxyVisibilityChanged( |
| 3484 | blink::mojom::FrameVisibility visibility) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3485 | OPTIONAL_TRACE_EVENT1("content", |
| 3486 | "WebContentsImpl::OnRenderFrameProxyVisibilityChanged", |
| 3487 | "visibility", static_cast<int>(visibility)); |
Dave Tapuska | c334436 | 2019-02-20 17:54:28 | [diff] [blame] | 3488 | switch (visibility) { |
| 3489 | case blink::mojom::FrameVisibility::kRenderedInViewport: |
| 3490 | WasShown(); |
| 3491 | break; |
| 3492 | case blink::mojom::FrameVisibility::kNotRendered: |
| 3493 | WasHidden(); |
| 3494 | break; |
| 3495 | case blink::mojom::FrameVisibility::kRenderedOutOfViewport: |
| 3496 | WasOccluded(); |
| 3497 | break; |
| 3498 | } |
ekaramad | a4f4269 | 2016-02-11 19:48:37 | [diff] [blame] | 3499 | } |
| 3500 | |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3501 | RenderFrameHostDelegate* WebContentsImpl::CreateNewWindow( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3502 | RenderFrameHost* opener, |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 3503 | const mojom::CreateNewWindowParams& params, |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3504 | bool is_new_browsing_instance, |
Sergey Kuznetsov | 32257a2 | 2019-02-11 20:26:50 | [diff] [blame] | 3505 | bool has_user_gesture, |
[email protected] | 97714c8 | 2012-06-06 10:15:13 | [diff] [blame] | 3506 | SessionStorageNamespace* session_storage_namespace) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3507 | TRACE_EVENT2("browser,content,navigation", "WebContentsImpl::CreateNewWindow", |
| 3508 | "opener", base::trace_event::ToTracedValue(opener), "params", |
| 3509 | base::trace_event::ToTracedValue(params)); |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3510 | DCHECK(opener); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3511 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3512 | int render_process_id = opener->GetProcess()->GetID(); |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3513 | |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3514 | SiteInstance* source_site_instance = opener->GetSiteInstance(); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3515 | |
Aaron Colwell | eb21998 | 2020-01-16 02:17:27 | [diff] [blame] | 3516 | const GURL source_site_url = source_site_instance->GetSiteURL(); |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 3517 | const std::string& partition_id = |
Aaron Colwell | eb21998 | 2020-01-16 02:17:27 | [diff] [blame] | 3518 | GetContentClient()->browser()->GetStoragePartitionIdForSite( |
| 3519 | GetBrowserContext(), source_site_url); |
| 3520 | { |
| 3521 | StoragePartition* partition = BrowserContext::GetStoragePartitionForSite( |
| 3522 | GetBrowserContext(), source_site_url); |
| 3523 | DOMStorageContextWrapper* dom_storage_context = |
| 3524 | static_cast<DOMStorageContextWrapper*>( |
| 3525 | partition->GetDOMStorageContext()); |
| 3526 | SessionStorageNamespaceImpl* session_storage_namespace_impl = |
| 3527 | static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace); |
| 3528 | CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context)); |
| 3529 | } |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 3530 | |
Albert J. Wong | 1ceccef9 | 2019-10-08 08:25:20 | [diff] [blame] | 3531 | if (delegate_ && delegate_->IsWebContentsCreationOverridden( |
| 3532 | source_site_instance, params.window_container_type, |
| 3533 | opener->GetLastCommittedURL(), params.frame_name, |
| 3534 | params.target_url)) { |
| 3535 | return static_cast<WebContentsImpl*>(delegate_->CreateCustomWebContents( |
| 3536 | opener, source_site_instance, is_new_browsing_instance, |
| 3537 | opener->GetLastCommittedURL(), params.frame_name, params.target_url, |
| 3538 | partition_id, session_storage_namespace)); |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 3539 | } |
| 3540 | |
danakj | 22b4e8b | 2019-08-01 23:14:39 | [diff] [blame] | 3541 | bool renderer_started_hidden = |
| 3542 | params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB; |
| 3543 | |
Aaron Colwell | eb21998 | 2020-01-16 02:17:27 | [diff] [blame] | 3544 | // We usually create the new window in the same BrowsingInstance (group of |
| 3545 | // script-related windows), by passing in the current SiteInstance. However, |
| 3546 | // if the opener is being suppressed (in a non-guest), we do not provide |
| 3547 | // a SiteInstance which causes a new one to get created in its own |
| 3548 | // BrowsingInstance. |
| 3549 | bool is_guest = BrowserPluginGuest::IsGuest(this); |
| 3550 | scoped_refptr<SiteInstance> site_instance = |
| 3551 | params.opener_suppressed && !is_guest ? nullptr : source_site_instance; |
| 3552 | |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 3553 | // Create the new web contents. This will automatically create the new |
| 3554 | // WebContentsView. In the future, we may want to create the view separately. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 3555 | CreateParams create_params(GetBrowserContext(), site_instance.get()); |
nasko | 48321ca3 | 2015-07-02 20:44:12 | [diff] [blame] | 3556 | create_params.main_frame_name = params.frame_name; |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 3557 | create_params.opener_render_process_id = render_process_id; |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3558 | create_params.opener_render_frame_id = opener->GetRoutingID(); |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 3559 | create_params.opener_suppressed = params.opener_suppressed; |
danakj | 22b4e8b | 2019-08-01 23:14:39 | [diff] [blame] | 3560 | create_params.initially_hidden = renderer_started_hidden; |
arthursonzogni | 034bb9c | 2020-10-01 08:29:56 | [diff] [blame] | 3561 | create_params.initial_popup_url = params.target_url; |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 3562 | |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3563 | // Even though all codepaths leading here are in response to a renderer |
| 3564 | // tryng to open a new window, if the new window ends up in a different |
| 3565 | // browsing instance, then the RenderViewHost, RenderWidgetHost, |
| 3566 | // RenderFrameHost constellation is effectively browser initiated |
| 3567 | // the opener's process will not given the routing IDs for the new |
| 3568 | // objects. |
| 3569 | create_params.renderer_initiated_creation = !is_new_browsing_instance; |
Albert J. Wong | 1ceccef9 | 2019-10-08 08:25:20 | [diff] [blame] | 3570 | |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3571 | std::unique_ptr<WebContentsImpl> new_contents; |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 3572 | if (!is_guest) { |
| 3573 | create_params.context = view_->GetNativeView(); |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3574 | new_contents = WebContentsImpl::Create(create_params); |
| 3575 | } else { |
| 3576 | new_contents = base::WrapUnique(static_cast<WebContentsImpl*>( |
| 3577 | GetBrowserPluginGuest()->CreateNewGuestWindow(create_params))); |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 3578 | } |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3579 | auto* new_contents_impl = new_contents.get(); |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3580 | |
| 3581 | new_contents_impl->GetController().SetSessionStorageNamespace( |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 3582 | partition_id, session_storage_namespace); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 3583 | |
alexmos | 646fec0 | 2015-07-25 00:11:49 | [diff] [blame] | 3584 | // If the new frame has a name, make sure any SiteInstances that can find |
| 3585 | // this named frame have proxies for it. Must be called after |
| 3586 | // SetSessionStorageNamespace, since this calls CreateRenderView, which uses |
| 3587 | // GetSessionStorageNamespace. |
| 3588 | if (!params.frame_name.empty()) |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3589 | new_contents_impl->GetRenderManager()->CreateProxiesForNewNamedFrame(); |
alexmos | 646fec0 | 2015-07-25 00:11:49 | [diff] [blame] | 3590 | |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 3591 | // Save the window for later if we're not suppressing the opener (since it |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 3592 | // will be shown immediately). |
| 3593 | if (!params.opener_suppressed) { |
| 3594 | if (!is_guest) { |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3595 | WebContentsView* new_view = new_contents_impl->view_.get(); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3596 | |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 3597 | // TODO(brettw): It seems bogus that we have to call this function on the |
| 3598 | // newly created object and give it one of its own member variables. |
danakj | 22b4e8b | 2019-08-01 23:14:39 | [diff] [blame] | 3599 | RenderWidgetHostView* widget_view = new_view->CreateViewForWidget( |
W. James MacLean | 13d834d | 2019-12-04 16:06:45 | [diff] [blame] | 3600 | new_contents_impl->GetRenderViewHost()->GetWidget()); |
danakj | 22b4e8b | 2019-08-01 23:14:39 | [diff] [blame] | 3601 | if (!renderer_started_hidden) { |
| 3602 | // RenderWidgets for frames always initialize as hidden. If the renderer |
| 3603 | // created this window as visible, then we show it here. |
| 3604 | widget_view->Show(); |
| 3605 | } |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 3606 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3607 | // Save the created window associated with the route so we can show it |
| 3608 | // later. |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 3609 | // |
| 3610 | // TODO(ajwong): This should be keyed off the RenderFrame routing id or the |
| 3611 | // FrameTreeNode id instead of the routing id of the Widget for the main |
| 3612 | // frame. https://crbug.com/545684 |
Fergal Daly | 052873a8 | 2020-03-11 14:45:49 | [diff] [blame] | 3613 | int32_t main_frame_routing_id = new_contents_impl->GetMainFrame() |
| 3614 | ->GetRenderWidgetHost() |
| 3615 | ->GetRoutingID(); |
| 3616 | GlobalRoutingID id(render_process_id, main_frame_routing_id); |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3617 | pending_contents_[id] = |
| 3618 | CreatedWindow(std::move(new_contents), params.target_url); |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3619 | AddDestructionObserver(new_contents_impl); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3620 | } |
| 3621 | |
| 3622 | if (delegate_) { |
Bryan McQuade | d2b93c0 | 2017-07-14 22:26:31 | [diff] [blame] | 3623 | delegate_->WebContentsCreated(this, render_process_id, |
| 3624 | opener->GetRoutingID(), params.frame_name, |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3625 | params.target_url, new_contents_impl); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3626 | } |
| 3627 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 3628 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 3629 | observer->DidOpenRequestedURL(new_contents_impl, opener, params.target_url, |
| 3630 | params.referrer.To<Referrer>(), |
| 3631 | params.disposition, ui::PAGE_TRANSITION_LINK, |
| 3632 | false, // started_from_context_menu |
| 3633 | true); // renderer_initiated |
| 3634 | }); |
pnoland | aae574e | 2017-03-06 21:04:21 | [diff] [blame] | 3635 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3636 | if (params.opener_suppressed) { |
| 3637 | // When the opener is suppressed, the original renderer cannot access the |
| 3638 | // new window. As a result, we need to show and navigate the window here. |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 3639 | bool was_blocked = false; |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 3640 | |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 3641 | if (delegate_) { |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3642 | base::WeakPtr<WebContentsImpl> weak_new_contents = |
| 3643 | new_contents_impl->weak_factory_.GetWeakPtr(); |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 3644 | |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3645 | gfx::Rect initial_rect; // Report an empty initial rect. |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3646 | delegate_->AddNewContents(this, std::move(new_contents), |
Joel Hockey | 891e8806 | 2020-04-30 05:38:44 | [diff] [blame] | 3647 | params.target_url, params.disposition, |
| 3648 | initial_rect, has_user_gesture, &was_blocked); |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3649 | // The delegate may delete |new_contents_impl| during AddNewContents(). |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 3650 | if (!weak_new_contents) |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3651 | return nullptr; |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 3652 | } |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 3653 | |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 3654 | if (!was_blocked) { |
Nasko Oskov | 83a8cf9 | 2018-10-19 14:58:56 | [diff] [blame] | 3655 | std::unique_ptr<NavigationController::LoadURLParams> load_params = |
| 3656 | std::make_unique<NavigationController::LoadURLParams>( |
| 3657 | params.target_url); |
Nasko Oskov | 93e7c55c | 2018-12-19 01:59:29 | [diff] [blame] | 3658 | load_params->initiator_origin = opener->GetLastCommittedOrigin(); |
Lukasz Anforowicz | d2629b4 | 2020-08-11 16:07:31 | [diff] [blame] | 3659 | // Avoiding setting |load_params->source_site_instance| when |
| 3660 | // |opener_suppressed| is true, because in that case we do not want to use |
| 3661 | // the old SiteInstance and/or BrowsingInstance. See also the test here: |
| 3662 | // NewPopupCOOP_SameOriginPolicyAndCrossOriginIframeSetsNoopener. |
Leon Han | 963dc18 | 2018-11-06 05:41:48 | [diff] [blame] | 3663 | load_params->referrer = params.referrer.To<Referrer>(); |
Nasko Oskov | 83a8cf9 | 2018-10-19 14:58:56 | [diff] [blame] | 3664 | load_params->transition_type = ui::PAGE_TRANSITION_LINK; |
| 3665 | load_params->is_renderer_initiated = true; |
Sergey Kuznetsov | 32257a2 | 2019-02-11 20:26:50 | [diff] [blame] | 3666 | load_params->has_user_gesture = has_user_gesture; |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 3667 | |
| 3668 | if (delegate_ && !is_guest && |
| 3669 | !delegate_->ShouldResumeRequestsForCreatedWindow()) { |
Nasko Oskov | 83a8cf9 | 2018-10-19 14:58:56 | [diff] [blame] | 3670 | // We are in asynchronous add new contents path, delay navigation. |
| 3671 | DCHECK(!new_contents_impl->delayed_open_url_params_); |
| 3672 | new_contents_impl->delayed_load_url_params_ = std::move(load_params); |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 3673 | } else { |
Nasko Oskov | 83a8cf9 | 2018-10-19 14:58:56 | [diff] [blame] | 3674 | new_contents_impl->controller_.LoadURLWithParams(*load_params.get()); |
Nasko Oskov | 28ebd5b | 2018-12-07 22:29:33 | [diff] [blame] | 3675 | if (!is_guest) |
| 3676 | new_contents_impl->Focus(); |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 3677 | } |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 3678 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3679 | } |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3680 | return new_contents_impl; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3681 | } |
| 3682 | |
Dave Tapuska | 04ccda06 | 2020-10-21 21:58:12 | [diff] [blame^] | 3683 | void WebContentsImpl::CreateNewPopupWidget( |
Tal Pressman | 5dcd238 | 2020-08-26 07:13:05 | [diff] [blame] | 3684 | AgentSchedulingGroupHost& agent_scheduling_group, |
| 3685 | int32_t route_id, |
Dave Tapuska | 04ccda06 | 2020-10-21 21:58:12 | [diff] [blame^] | 3686 | mojo::PendingAssociatedReceiver<blink::mojom::PopupWidgetHost> |
| 3687 | blink_popup_widget_host, |
Dave Tapuska | 8499eec | 2020-03-16 17:54:30 | [diff] [blame] | 3688 | mojo::PendingAssociatedReceiver<blink::mojom::WidgetHost> blink_widget_host, |
| 3689 | mojo::PendingAssociatedRemote<blink::mojom::Widget> blink_widget) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3690 | OPTIONAL_TRACE_EVENT1( |
| 3691 | "content", "WebContentsImpl::CreateNewWidget", "params", |
Dave Tapuska | 04b305f9 | 2020-10-19 18:20:28 | [diff] [blame] | 3692 | base::trace_event::TracedValue::Build({{"route_id", route_id}})); |
Tal Pressman | 5dcd238 | 2020-08-26 07:13:05 | [diff] [blame] | 3693 | RenderProcessHost* process = agent_scheduling_group.GetProcess(); |
kenrb | b46f86a | 2015-12-07 07:53:23 | [diff] [blame] | 3694 | // A message to create a new widget can only come from an active process for |
[email protected] | a850402 | 2013-12-04 20:23:51 | [diff] [blame] | 3695 | // this WebContentsImpl instance. If any other process sends the request, |
| 3696 | // it is invalid and the process must be terminated. |
Tal Pressman | 5dcd238 | 2020-08-26 07:13:05 | [diff] [blame] | 3697 | if (!HasMatchingProcess(&frame_tree_, process->GetID())) { |
Lukasz Anforowicz | 6f74628 | 2018-01-04 23:24:51 | [diff] [blame] | 3698 | ReceivedBadMessage(process, bad_message::WCI_NEW_WIDGET_PROCESS_MISMATCH); |
[email protected] | a850402 | 2013-12-04 20:23:51 | [diff] [blame] | 3699 | return; |
| 3700 | } |
| 3701 | |
Tal Pressman | 5dcd238 | 2020-08-26 07:13:05 | [diff] [blame] | 3702 | RenderWidgetHostImpl* widget_host = new RenderWidgetHostImpl( |
| 3703 | this, agent_scheduling_group, route_id, IsHidden(), |
| 3704 | std::make_unique<FrameTokenMessageQueue>()); |
Dave Tapuska | 8499eec | 2020-03-16 17:54:30 | [diff] [blame] | 3705 | |
| 3706 | widget_host->BindWidgetInterfaces(std::move(blink_widget_host), |
| 3707 | std::move(blink_widget)); |
Dave Tapuska | 04ccda06 | 2020-10-21 21:58:12 | [diff] [blame^] | 3708 | widget_host->BindPopupWidgetInterface(std::move(blink_popup_widget_host)); |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 3709 | RenderWidgetHostViewBase* widget_view = |
| 3710 | static_cast<RenderWidgetHostViewBase*>( |
danakj | 0b24694 | 2018-09-17 21:30:27 | [diff] [blame] | 3711 | view_->CreateViewForChildWidget(widget_host)); |
[email protected] | 83918ec | 2013-01-10 15:37:19 | [diff] [blame] | 3712 | if (!widget_view) |
| 3713 | return; |
Dave Tapuska | 04b305f9 | 2020-10-19 18:20:28 | [diff] [blame] | 3714 | widget_view->SetWidgetType(WidgetType::kPopup); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3715 | // Save the created widget associated with the route so we can show it later. |
Tal Pressman | 5dcd238 | 2020-08-26 07:13:05 | [diff] [blame] | 3716 | pending_widget_views_[GlobalRoutingID(process->GetID(), route_id)] = |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3717 | widget_view; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3718 | } |
| 3719 | |
Mike Wasserman | dabad61 | 2020-08-13 04:26:27 | [diff] [blame] | 3720 | void WebContentsImpl::ShowCreatedWindow(RenderFrameHost* opener, |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3721 | int main_frame_widget_route_id, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3722 | WindowOpenDisposition disposition, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 3723 | const gfx::Rect& initial_rect, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3724 | bool user_gesture) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3725 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::ShowCreatedWindow", |
| 3726 | "opener", base::trace_event::ToTracedValue(opener), |
| 3727 | "main_frame_widget_route_id", |
| 3728 | main_frame_widget_route_id); |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3729 | // This method is the renderer requesting an existing top level window to |
| 3730 | // show a new top level window that the renderer created. Each top level |
| 3731 | // window is associated with a WebContents. In this case it was created |
| 3732 | // earlier but showing it was deferred until the renderer requested for it |
| 3733 | // to be shown. We find that previously created WebContents here. |
| 3734 | // TODO(danakj): Why do we defer this show step until the renderer asks for it |
| 3735 | // when it will always do so. What needs to happen in the renderer before we |
| 3736 | // reach here? |
Mike Wasserman | dabad61 | 2020-08-13 04:26:27 | [diff] [blame] | 3737 | base::Optional<CreatedWindow> owned_created = GetCreatedWindow( |
| 3738 | opener->GetProcess()->GetID(), main_frame_widget_route_id); |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3739 | |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3740 | // The browser may have rejected the request to make a new window, or the |
| 3741 | // renderer could be sending an invalid route id. Ignore the request then. |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3742 | if (!owned_created || !owned_created->contents) |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3743 | return; |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 3744 | |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3745 | WebContentsImpl* created = owned_created->contents.get(); |
| 3746 | |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3747 | // This uses the delegate for the WebContents where the window was created |
| 3748 | // from, to control how to show the newly created window. |
| 3749 | WebContentsDelegate* delegate = GetDelegate(); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3750 | |
Mike Wasserman | b6bc015 | 2020-08-25 22:46:20 | [diff] [blame] | 3751 | // Individual members of |initial_rect| may be 0 to indicate that the |
| 3752 | // window.open() feature string did not specify a value. This code does not |
| 3753 | // have the ability to distinguish between an unspecified value and 0. |
| 3754 | // Assume that if any single value is non-zero, all values should be used. |
| 3755 | // TODO(crbug.com/897300): Plumb values as specified; set defaults here? |
| 3756 | gfx::Rect adjusted_rect = initial_rect; |
| 3757 | int64_t display_id = display::kInvalidDisplayId; |
| 3758 | if (adjusted_rect != gfx::Rect()) |
| 3759 | display_id = AdjustRequestedWindowBounds(&adjusted_rect, opener); |
| 3760 | |
| 3761 | // Drop fullscreen when opening a WebContents to prohibit deceptive behavior. |
| 3762 | // Only drop fullscreen on the specific destination display, if it is known. |
| 3763 | // This supports sites using cross-screen window placement capabilities to |
| 3764 | // retain fullscreen and open a window on another screen. |
| 3765 | ForSecurityDropFullscreen(display_id).RunAndReset(); |
| 3766 | |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3767 | // The delegate can be null in tests, so we must check for it :(. |
| 3768 | if (delegate) { |
| 3769 | // Mark the web contents as pending resume, then immediately do |
| 3770 | // the resume if the delegate wants it. |
| 3771 | created->is_resume_pending_ = true; |
| 3772 | if (delegate->ShouldResumeRequestsForCreatedWindow()) |
| 3773 | created->ResumeLoadingCreatedWebContents(); |
| 3774 | |
| 3775 | base::WeakPtr<WebContentsImpl> weak_created = |
| 3776 | created->weak_factory_.GetWeakPtr(); |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3777 | delegate->AddNewContents(this, std::move(owned_created->contents), |
Joel Hockey | 891e8806 | 2020-04-30 05:38:44 | [diff] [blame] | 3778 | std::move(owned_created->target_url), disposition, |
Mike Wasserman | dabad61 | 2020-08-13 04:26:27 | [diff] [blame] | 3779 | adjusted_rect, user_gesture, nullptr); |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3780 | // The delegate may delete |created| during AddNewContents(). |
| 3781 | if (!weak_created) |
| 3782 | return; |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 3783 | } |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3784 | |
| 3785 | RenderWidgetHostImpl* rwh = created->GetMainFrame()->GetRenderWidgetHost(); |
| 3786 | DCHECK_EQ(main_frame_widget_route_id, rwh->GetRoutingID()); |
| 3787 | rwh->Send(new WidgetMsg_SetBounds_ACK(rwh->GetRoutingID())); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3788 | } |
| 3789 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3790 | void WebContentsImpl::ShowCreatedWidget(int process_id, |
Albert J. Wong | f6e13ed | 2018-09-18 15:25:47 | [diff] [blame] | 3791 | int widget_route_id, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 3792 | const gfx::Rect& initial_rect) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3793 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::ShowCreatedWidget", |
| 3794 | "process_id", process_id, "widget_route_id", |
| 3795 | widget_route_id); |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 3796 | RenderWidgetHostViewBase* widget_host_view = |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3797 | static_cast<RenderWidgetHostViewBase*>( |
Dave Tapuska | 22cafa3 | 2020-10-06 11:56:05 | [diff] [blame] | 3798 | GetCreatedWidget(process_id, widget_route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3799 | if (!widget_host_view) |
| 3800 | return; |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 3801 | |
W. James MacLean | ec4125c | 2019-09-27 18:56:00 | [diff] [blame] | 3802 | // GetOutermostWebContents() returns |this| if there are no outer WebContents. |
W. James MacLean | 3c5f5046 | 2019-10-28 16:24:21 | [diff] [blame] | 3803 | auto* outer_web_contents = GetOuterWebContents(); |
| 3804 | auto* outermost_web_contents = GetOutermostWebContents(); |
W. James MacLean | ec4125c | 2019-09-27 18:56:00 | [diff] [blame] | 3805 | RenderWidgetHostView* view = |
W. James MacLean | 3c5f5046 | 2019-10-28 16:24:21 | [diff] [blame] | 3806 | outermost_web_contents->GetRenderWidgetHostView(); |
| 3807 | // It's not entirely obvious why we need the transform only in the case where |
| 3808 | // the outer webcontents is not the same as the outermost webcontents. It may |
| 3809 | // be due to the fact that oopifs that are children of the mainframe get |
| 3810 | // correct values for their screenrects, but deeper cross-process frames do |
| 3811 | // not. Hopefully this can be resolved with https://crbug.com/928825. |
| 3812 | // Handling these cases separately is needed for http://crbug.com/1015298. |
| 3813 | bool needs_transform = this != outermost_web_contents && |
| 3814 | outermost_web_contents != outer_web_contents; |
W. James MacLean | ec4125c | 2019-09-27 18:56:00 | [diff] [blame] | 3815 | |
| 3816 | gfx::Rect transformed_rect(initial_rect); |
| 3817 | RenderWidgetHostView* this_view = GetRenderWidgetHostView(); |
W. James MacLean | 3c5f5046 | 2019-10-28 16:24:21 | [diff] [blame] | 3818 | if (needs_transform) { |
W. James MacLean | ec4125c | 2019-09-27 18:56:00 | [diff] [blame] | 3819 | // We need to transform the coordinates of initial_rect. |
| 3820 | gfx::Point origin = |
| 3821 | this_view->TransformPointToRootCoordSpace(initial_rect.origin()); |
| 3822 | gfx::Point bottom_right = |
| 3823 | this_view->TransformPointToRootCoordSpace(initial_rect.bottom_right()); |
| 3824 | transformed_rect = |
| 3825 | gfx::Rect(origin.x(), origin.y(), bottom_right.x() - origin.x(), |
| 3826 | bottom_right.y() - origin.y()); |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 3827 | } |
| 3828 | |
Dave Tapuska | 22cafa3 | 2020-10-06 11:56:05 | [diff] [blame] | 3829 | widget_host_view->InitAsPopup(view, transformed_rect); |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 3830 | |
yiyix | cb1fbc4f | 2018-03-16 19:54:08 | [diff] [blame] | 3831 | RenderWidgetHostImpl* render_widget_host_impl = widget_host_view->host(); |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 3832 | render_widget_host_impl->Init(); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3833 | } |
| 3834 | |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3835 | base::Optional<CreatedWindow> WebContentsImpl::GetCreatedWindow( |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3836 | int process_id, |
| 3837 | int main_frame_widget_route_id) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3838 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::GetCreatedWindow", |
| 3839 | "process_id", process_id, "main_frame_widget_route_id", |
| 3840 | main_frame_widget_route_id); |
| 3841 | |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 3842 | auto key = GlobalRoutingID(process_id, main_frame_widget_route_id); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3843 | auto iter = pending_contents_.find(key); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3844 | |
| 3845 | // Certain systems can block the creation of new windows. If we didn't succeed |
| 3846 | // in creating one, just return NULL. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3847 | if (iter == pending_contents_.end()) |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3848 | return base::nullopt; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3849 | |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3850 | CreatedWindow result = std::move(iter->second); |
| 3851 | WebContentsImpl* new_contents = result.contents.get(); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3852 | pending_contents_.erase(key); |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3853 | RemoveDestructionObserver(new_contents); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3854 | |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 3855 | // Don't initialize the guest WebContents immediately. |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3856 | if (BrowserPluginGuest::IsGuest(new_contents)) |
| 3857 | return result; |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 3858 | |
Lukasz Anforowicz | 5510ed65 | 2018-06-06 16:16:19 | [diff] [blame] | 3859 | if (!new_contents->GetMainFrame()->GetProcess()->IsInitializedAndNotDead() || |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3860 | !new_contents->GetMainFrame()->GetView()) { |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3861 | return base::nullopt; |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3862 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3863 | |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3864 | return result; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3865 | } |
| 3866 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3867 | RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int process_id, |
| 3868 | int route_id) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3869 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::GetCreatedWidget", |
| 3870 | "process_id", process_id, "route_id", route_id); |
| 3871 | |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 3872 | auto iter = pending_widget_views_.find(GlobalRoutingID(process_id, route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3873 | if (iter == pending_widget_views_.end()) { |
| 3874 | DCHECK(false); |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3875 | return nullptr; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3876 | } |
| 3877 | |
| 3878 | RenderWidgetHostView* widget_host_view = iter->second; |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 3879 | pending_widget_views_.erase(GlobalRoutingID(process_id, route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3880 | |
| 3881 | RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost(); |
Lukasz Anforowicz | 5510ed65 | 2018-06-06 16:16:19 | [diff] [blame] | 3882 | if (!widget_host->GetProcess()->IsInitializedAndNotDead()) { |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3883 | // The view has gone away or the renderer crashed. Nothing to do. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3884 | return nullptr; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3885 | } |
| 3886 | |
| 3887 | return widget_host_view; |
| 3888 | } |
| 3889 | |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 3890 | void WebContentsImpl::RequestMediaAccessPermission( |
[email protected] | 33662e5 | 2013-01-07 21:31:09 | [diff] [blame] | 3891 | const MediaStreamRequest& request, |
Mark Pilgrim | 5749908 | 2018-06-12 12:38:30 | [diff] [blame] | 3892 | MediaResponseCallback callback) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3893 | OPTIONAL_TRACE_EVENT2("content", |
| 3894 | "WebContentsImpl::RequestMediaAccessPermission", |
| 3895 | "render_process_id", request.render_process_id, |
| 3896 | "render_frame_id", request.render_frame_id); |
| 3897 | |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 3898 | if (delegate_) { |
Mark Pilgrim | 5749908 | 2018-06-12 12:38:30 | [diff] [blame] | 3899 | delegate_->RequestMediaAccessPermission(this, request, std::move(callback)); |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 3900 | } else { |
Antonio Gomes | 0d42960a | 2019-06-05 12:35:51 | [diff] [blame] | 3901 | std::move(callback).Run( |
| 3902 | blink::MediaStreamDevices(), |
| 3903 | blink::mojom::MediaStreamRequestResult::FAILED_DUE_TO_SHUTDOWN, |
| 3904 | std::unique_ptr<MediaStreamUI>()); |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 3905 | } |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 3906 | } |
| 3907 | |
Chandan Padhi | a4b8bcb7 | 2017-09-12 16:41:04 | [diff] [blame] | 3908 | bool WebContentsImpl::CheckMediaAccessPermission( |
Raymes Khoury | ad7c24a1 | 2018-03-05 23:22:58 | [diff] [blame] | 3909 | RenderFrameHost* render_frame_host, |
Chandan Padhi | a4b8bcb7 | 2017-09-12 16:41:04 | [diff] [blame] | 3910 | const url::Origin& security_origin, |
Antonio Gomes | c8b734b | 2019-06-05 18:22:16 | [diff] [blame] | 3911 | blink::mojom::MediaStreamType type) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3912 | OPTIONAL_TRACE_EVENT2("content", |
| 3913 | "WebContentsImpl::CheckMediaAccessPermission", |
| 3914 | "render_frame_host", render_frame_host, |
| 3915 | "security_origin", security_origin.Serialize()); |
| 3916 | |
Antonio Gomes | c8b734b | 2019-06-05 18:22:16 | [diff] [blame] | 3917 | DCHECK(type == blink::mojom::MediaStreamType::DEVICE_AUDIO_CAPTURE || |
| 3918 | type == blink::mojom::MediaStreamType::DEVICE_VIDEO_CAPTURE); |
Chandan Padhi | a4b8bcb7 | 2017-09-12 16:41:04 | [diff] [blame] | 3919 | return delegate_ && delegate_->CheckMediaAccessPermission( |
Raymes Khoury | ad7c24a1 | 2018-03-05 23:22:58 | [diff] [blame] | 3920 | render_frame_host, security_origin.GetURL(), type); |
grunell | 657d4d8 | 2014-09-18 00:09:43 | [diff] [blame] | 3921 | } |
| 3922 | |
Guido Urdaneta | 73fa663 | 2019-01-14 18:46:26 | [diff] [blame] | 3923 | std::string WebContentsImpl::GetDefaultMediaDeviceID( |
Antonio Gomes | c8b734b | 2019-06-05 18:22:16 | [diff] [blame] | 3924 | blink::mojom::MediaStreamType type) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3925 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::GetDefaultMediaDeviceID", |
| 3926 | "type", static_cast<int>(type)); |
| 3927 | |
guidou | 8a440b84 | 2017-01-30 13:58:43 | [diff] [blame] | 3928 | if (!delegate_) |
| 3929 | return std::string(); |
| 3930 | return delegate_->GetDefaultMediaDeviceID(this, type); |
| 3931 | } |
| 3932 | |
[email protected] | cc920043 | 2013-07-23 23:02:40 | [diff] [blame] | 3933 | SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace( |
| 3934 | SiteInstance* instance) { |
| 3935 | return controller_.GetSessionStorageNamespace(instance); |
| 3936 | } |
| 3937 | |
[email protected] | 6de7fc48 | 2014-06-06 10:46:44 | [diff] [blame] | 3938 | SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() { |
| 3939 | return controller_.GetSessionStorageNamespaceMap(); |
| 3940 | } |
| 3941 | |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 3942 | FrameTree* WebContentsImpl::GetFrameTree() { |
| 3943 | return &frame_tree_; |
| 3944 | } |
| 3945 | |
aelias | 5252baa | 2016-04-10 01:18:02 | [diff] [blame] | 3946 | bool WebContentsImpl::IsOverridingUserAgent() { |
| 3947 | return GetController().GetVisibleEntry() && |
| 3948 | GetController().GetVisibleEntry()->GetIsOverridingUserAgent(); |
| 3949 | } |
| 3950 | |
avi | 85ee836 | 2016-10-08 02:09:08 | [diff] [blame] | 3951 | bool WebContentsImpl::IsJavaScriptDialogShowing() const { |
| 3952 | return is_showing_javascript_dialog_; |
| 3953 | } |
| 3954 | |
avi | c031d39 | 2017-03-03 03:09:42 | [diff] [blame] | 3955 | bool WebContentsImpl::ShouldIgnoreUnresponsiveRenderer() { |
Dominique Fauteux-Chapleau | 9924438 | 2020-07-08 20:37:00 | [diff] [blame] | 3956 | if (suppress_unresponsive_renderer_count_ > 0) |
| 3957 | return true; |
| 3958 | |
avi | c031d39 | 2017-03-03 03:09:42 | [diff] [blame] | 3959 | // Ignore unresponsive renderers if the debugger is attached to them since the |
| 3960 | // unresponsiveness might be a result of the renderer sitting on a breakpoint. |
| 3961 | // |
David Bienvenu | 525f8a0 | 2019-02-15 02:02:42 | [diff] [blame] | 3962 | #ifdef OS_WIN |
| 3963 | // Check if a windows debugger is attached to the renderer process. |
| 3964 | base::ProcessHandle process_handle = |
| 3965 | GetMainFrame()->GetProcess()->GetProcess().Handle(); |
| 3966 | BOOL debugger_present = FALSE; |
| 3967 | if (CheckRemoteDebuggerPresent(process_handle, &debugger_present) && |
| 3968 | debugger_present) |
| 3969 | return true; |
| 3970 | #endif // OS_WIN |
| 3971 | |
avi | c031d39 | 2017-03-03 03:09:42 | [diff] [blame] | 3972 | // TODO(pfeldman): Fix this to only return true if the renderer is *actually* |
| 3973 | // sitting on a breakpoint. https://crbug.com/684202 |
| 3974 | return DevToolsAgentHost::IsDebuggerAttached(this); |
| 3975 | } |
| 3976 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 3977 | ui::AXMode WebContentsImpl::GetAccessibilityMode() { |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 3978 | return accessibility_mode_; |
| 3979 | } |
| 3980 | |
Mario Sanchez Prada | 5d7f1ac | 2020-07-16 17:18:40 | [diff] [blame] | 3981 | void WebContentsImpl::AXTreeIDForMainFrameHasChanged() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3982 | OPTIONAL_TRACE_EVENT0("content", |
| 3983 | "WebContentsImpl::AXTreeIDForMainFrameHasChanged"); |
| 3984 | |
Mario Sanchez Prada | 5d7f1ac | 2020-07-16 17:18:40 | [diff] [blame] | 3985 | RenderWidgetHostViewBase* rwhv = |
| 3986 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 3987 | if (rwhv) |
| 3988 | rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID()); |
| 3989 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 3990 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 3991 | observer->AXTreeIDForMainFrameHasChanged(); |
| 3992 | }); |
Mario Sanchez Prada | 5d7f1ac | 2020-07-16 17:18:40 | [diff] [blame] | 3993 | } |
| 3994 | |
Dominic Mazzoni | a7b0edb2 | 2017-08-09 16:32:51 | [diff] [blame] | 3995 | void WebContentsImpl::AccessibilityEventReceived( |
Dominic Mazzoni | ccbaa9b | 2018-06-06 07:44:23 | [diff] [blame] | 3996 | const AXEventNotificationDetails& details) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 3997 | OPTIONAL_TRACE_EVENT0("content", |
| 3998 | "WebContentsImpl::AccessibilityEventReceived"); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 3999 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 4000 | observer->AccessibilityEventReceived(details); |
| 4001 | }); |
[email protected] | 31a71eaf | 2014-03-13 01:47:36 | [diff] [blame] | 4002 | } |
| 4003 | |
dmazzoni | 2400c46 | 2016-08-23 15:07:13 | [diff] [blame] | 4004 | void WebContentsImpl::AccessibilityLocationChangesReceived( |
| 4005 | const std::vector<AXLocationChangeNotificationDetails>& details) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4006 | OPTIONAL_TRACE_EVENT0( |
| 4007 | "content", "WebContentsImpl::AccessibilityLocationChangesReceived"); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 4008 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 4009 | observer->AccessibilityLocationChangesReceived(details); |
| 4010 | }); |
dmazzoni | 2400c46 | 2016-08-23 15:07:13 | [diff] [blame] | 4011 | } |
| 4012 | |
Alexander Surkov | 2ab5162 | 2020-09-02 12:01:42 | [diff] [blame] | 4013 | std::string WebContentsImpl::DumpAccessibilityTree( |
Abigail Klein | abb42833 | 2019-09-13 18:26:21 | [diff] [blame] | 4014 | bool internal, |
Alexander Surkov | 9048288 | 2020-10-12 16:30:38 | [diff] [blame] | 4015 | std::vector<ui::AXPropertyFilter> property_filters) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4016 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::DumpAccessibilityTree"); |
James Wallace-Lee | eafc94cb9 | 2018-07-23 21:35:09 | [diff] [blame] | 4017 | auto* ax_mgr = GetOrCreateRootBrowserAccessibilityManager(); |
| 4018 | DCHECK(ax_mgr); |
Lei Zhang | c98caa382 | 2019-11-07 19:17:27 | [diff] [blame] | 4019 | return AccessibilityTreeFormatterBase::DumpAccessibilityTreeFromManager( |
Abigail Klein | abb42833 | 2019-09-13 18:26:21 | [diff] [blame] | 4020 | ax_mgr, internal, property_filters); |
James Wallace-Lee | eafc94cb9 | 2018-07-23 21:35:09 | [diff] [blame] | 4021 | } |
| 4022 | |
Abigail Klein | aa89874 | 2019-11-01 02:31:25 | [diff] [blame] | 4023 | void WebContentsImpl::RecordAccessibilityEvents( |
Abigail Klein | bb8304bd | 2020-05-18 21:44:18 | [diff] [blame] | 4024 | bool start_recording, |
| 4025 | base::Optional<AccessibilityEventCallback> callback) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4026 | OPTIONAL_TRACE_EVENT0("content", |
| 4027 | "WebContentsImpl::RecordAccessibilityEvents"); |
Abigail Klein | bb8304bd | 2020-05-18 21:44:18 | [diff] [blame] | 4028 | // Only pass a callback to RecordAccessibilityEvents when starting to record. |
| 4029 | DCHECK_EQ(start_recording, callback.has_value()); |
| 4030 | if (start_recording) { |
Abigail Klein | aa89874 | 2019-11-01 02:31:25 | [diff] [blame] | 4031 | SetAccessibilityMode(ui::AXMode::kWebContents); |
| 4032 | auto* ax_mgr = GetOrCreateRootBrowserAccessibilityManager(); |
| 4033 | DCHECK(ax_mgr); |
| 4034 | base::ProcessId pid = base::Process::Current().Pid(); |
Alexander Surkov | 97e96963 | 2020-09-29 02:30:05 | [diff] [blame] | 4035 | event_recorder_ = content::AccessibilityEventRecorder::Create(ax_mgr, pid); |
Abigail Klein | bb8304bd | 2020-05-18 21:44:18 | [diff] [blame] | 4036 | event_recorder_->ListenToEvents(*callback); |
Abigail Klein | aa89874 | 2019-11-01 02:31:25 | [diff] [blame] | 4037 | } else { |
Abigail Klein | bb8304bd | 2020-05-18 21:44:18 | [diff] [blame] | 4038 | if (event_recorder_) { |
| 4039 | event_recorder_->FlushAsyncEvents(); |
| 4040 | event_recorder_.reset(nullptr); |
| 4041 | } |
Abigail Klein | aa89874 | 2019-11-01 02:31:25 | [diff] [blame] | 4042 | } |
| 4043 | } |
| 4044 | |
Ke He | 7319dbe | 2017-11-09 05:54:44 | [diff] [blame] | 4045 | device::mojom::GeolocationContext* WebContentsImpl::GetGeolocationContext() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4046 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::GetGeolocationContext"); |
Ella Ge | 3e375b70 | 2020-06-05 15:57:16 | [diff] [blame] | 4047 | if (delegate_) { |
| 4048 | auto* installed_webapp_context = |
| 4049 | delegate_->GetInstalledWebappGeolocationContext(); |
| 4050 | if (installed_webapp_context) |
| 4051 | return installed_webapp_context; |
| 4052 | } |
| 4053 | |
Ken Rockot | ce010f0 | 2019-12-12 23:32:32 | [diff] [blame] | 4054 | if (!geolocation_context_) { |
| 4055 | GetDeviceService().BindGeolocationContext( |
| 4056 | geolocation_context_.BindNewPipeAndPassReceiver()); |
| 4057 | } |
Conley Owens | 6894c4f | 2017-07-10 19:29:13 | [diff] [blame] | 4058 | return geolocation_context_.get(); |
blundell | c57b93f | 2014-10-29 13:19:57 | [diff] [blame] | 4059 | } |
| 4060 | |
ke.he | 98b761e | 2017-05-09 05:59:17 | [diff] [blame] | 4061 | device::mojom::WakeLockContext* WebContentsImpl::GetWakeLockContext() { |
blundell | d8cd72b | 2017-03-28 07:18:38 | [diff] [blame] | 4062 | if (!wake_lock_context_host_) |
Fergal Daly | 55b6d72 | 2020-09-11 07:56:33 | [diff] [blame] | 4063 | wake_lock_context_host_ = std::make_unique<WakeLockContextHost>(this); |
blundell | e75a8f9 | 2017-03-27 08:11:17 | [diff] [blame] | 4064 | return wake_lock_context_host_->GetWakeLockContext(); |
alogvinov | f50445a | 2015-10-30 13:00:12 | [diff] [blame] | 4065 | } |
| 4066 | |
blundell | f5316fc | 2017-05-15 11:49:03 | [diff] [blame] | 4067 | #if defined(OS_ANDROID) |
Miyoung Shin | 59f39ff | 2019-09-17 07:23:20 | [diff] [blame] | 4068 | void WebContentsImpl::GetNFC( |
Reilly Grant | afbe224 | 2020-02-20 21:14:55 | [diff] [blame] | 4069 | RenderFrameHost* render_frame_host, |
Miyoung Shin | 59f39ff | 2019-09-17 07:23:20 | [diff] [blame] | 4070 | mojo::PendingReceiver<device::mojom::NFC> receiver) { |
Reilly Grant | afbe224 | 2020-02-20 21:14:55 | [diff] [blame] | 4071 | if (!nfc_host_) |
| 4072 | nfc_host_ = std::make_unique<NFCHost>(this); |
| 4073 | nfc_host_->GetNFC(render_frame_host, std::move(receiver)); |
blundell | f5316fc | 2017-05-15 11:49:03 | [diff] [blame] | 4074 | } |
| 4075 | #endif |
| 4076 | |
Evan Stade | 5e750ad0 | 2017-08-07 21:59:27 | [diff] [blame] | 4077 | void WebContentsImpl::SetNotWaitingForResponse() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4078 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::SetNotWaitingForResponse", |
| 4079 | "was_waiting_for_response", waiting_for_response_); |
Evan Stade | 5e750ad0 | 2017-08-07 21:59:27 | [diff] [blame] | 4080 | if (waiting_for_response_ == false) |
| 4081 | return; |
| 4082 | |
| 4083 | waiting_for_response_ = false; |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 4084 | observers_.ForEachObserver( |
| 4085 | [&](WebContentsObserver* observer) { observer->DidReceiveResponse(); }); |
Bruce Dawson | e1c5c84 | 2020-09-15 02:09:14 | [diff] [blame] | 4086 | |
| 4087 | // LoadingStateChanged must be called last in case it triggers deletion of |
| 4088 | // |this| due to recursive message pumps. |
| 4089 | if (delegate_) |
| 4090 | delegate_->LoadingStateChanged(this, is_load_to_different_document_); |
Evan Stade | 5e750ad0 | 2017-08-07 21:59:27 | [diff] [blame] | 4091 | } |
| 4092 | |
lfg | bb9c28a | 2016-03-01 03:19:49 | [diff] [blame] | 4093 | void WebContentsImpl::SendScreenRects() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4094 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::SendScreenRects"); |
kenrb | c52e1b4e | 2016-03-20 01:03:37 | [diff] [blame] | 4095 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
kenrb | 0e8dc20 | 2016-05-30 19:51:40 | [diff] [blame] | 4096 | if (node->current_frame_host()->is_local_root()) |
kenrb | c52e1b4e | 2016-03-20 01:03:37 | [diff] [blame] | 4097 | node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects(); |
| 4098 | } |
[email protected] | 32deec6 | 2013-05-15 23:55:04 | [diff] [blame] | 4099 | } |
| 4100 | |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 4101 | TextInputManager* WebContentsImpl::GetTextInputManager() { |
| 4102 | if (GetOuterWebContents()) |
| 4103 | return GetOuterWebContents()->GetTextInputManager(); |
| 4104 | |
Ehsan Karamad | c179dc0 | 2018-12-15 03:09:29 | [diff] [blame] | 4105 | if (!text_input_manager_ && !browser_plugin_guest_) { |
Fergal Daly | 55b6d72 | 2020-09-11 07:56:33 | [diff] [blame] | 4106 | text_input_manager_ = std::make_unique<TextInputManager>( |
Darren Shen | ca53d5f | 2018-05-15 04:56:01 | [diff] [blame] | 4107 | GetBrowserContext() && |
Fergal Daly | 55b6d72 | 2020-09-11 07:56:33 | [diff] [blame] | 4108 | !GetBrowserContext()->IsOffTheRecord() /* should_do_learning */); |
Darren Shen | ca53d5f | 2018-05-15 04:56:01 | [diff] [blame] | 4109 | } |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 4110 | |
| 4111 | return text_input_manager_.get(); |
| 4112 | } |
| 4113 | |
paulmeyer | 7f6f1d4f | 2016-11-15 00:00:27 | [diff] [blame] | 4114 | bool WebContentsImpl::OnUpdateDragCursor() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4115 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::OnUpdateDragCursor"); |
Lei Zhang | 6410ec1a | 2019-01-31 21:38:58 | [diff] [blame] | 4116 | return browser_plugin_embedder_ && |
| 4117 | browser_plugin_embedder_->OnUpdateDragCursor(); |
paulmeyer | 7f6f1d4f | 2016-11-15 00:00:27 | [diff] [blame] | 4118 | } |
| 4119 | |
kenrb | 11f213a | 2017-03-24 18:12:06 | [diff] [blame] | 4120 | bool WebContentsImpl::IsWidgetForMainFrame( |
| 4121 | RenderWidgetHostImpl* render_widget_host) { |
| 4122 | return render_widget_host == GetMainFrame()->GetRenderWidgetHost(); |
| 4123 | } |
| 4124 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 4125 | BrowserAccessibilityManager* |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4126 | WebContentsImpl::GetRootBrowserAccessibilityManager() { |
Carlos IL | d51e770 | 2020-05-07 18:51:39 | [diff] [blame] | 4127 | RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 4128 | return rfh ? rfh->browser_accessibility_manager() : nullptr; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 4129 | } |
| 4130 | |
| 4131 | BrowserAccessibilityManager* |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4132 | WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() { |
Carlos IL | d51e770 | 2020-05-07 18:51:39 | [diff] [blame] | 4133 | RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 4134 | return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 4135 | } |
| 4136 | |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 4137 | void WebContentsImpl::ExecuteEditCommand( |
| 4138 | const std::string& command, |
| 4139 | const base::Optional<base::string16>& value) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4140 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::ExecuteEditCommand"); |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4141 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4142 | if (!input_handler) |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 4143 | return; |
| 4144 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4145 | input_handler->ExecuteEditCommand(command, value); |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 4146 | } |
| 4147 | |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 4148 | void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4149 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::MoveRangeSelectionExtent"); |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4150 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4151 | if (!input_handler) |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 4152 | return; |
| 4153 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4154 | input_handler->MoveRangeSelectionExtent(extent); |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 4155 | } |
| 4156 | |
| 4157 | void WebContentsImpl::SelectRange(const gfx::Point& base, |
| 4158 | const gfx::Point& extent) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4159 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::SelectRange"); |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4160 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4161 | if (!input_handler) |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 4162 | return; |
| 4163 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4164 | input_handler->SelectRange(base, extent); |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 4165 | } |
| 4166 | |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 4167 | void WebContentsImpl::MoveCaret(const gfx::Point& extent) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4168 | OPTIONAL_TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 4169 | "WebContentsImpl::MoveCaret"); |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4170 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4171 | if (!input_handler) |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 4172 | return; |
| 4173 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4174 | input_handler->MoveCaret(extent); |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 4175 | } |
| 4176 | |
Shimi Zhang | 37deeb2 | 2017-09-28 00:59:01 | [diff] [blame] | 4177 | void WebContentsImpl::AdjustSelectionByCharacterOffset( |
| 4178 | int start_adjust, |
| 4179 | int end_adjust, |
| 4180 | bool show_selection_menu) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4181 | OPTIONAL_TRACE_EVENT0("content", |
| 4182 | "WebContentsImpl::AdjustSelectionByCharacterOffset"); |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4183 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4184 | if (!input_handler) |
aurimas | ab031902 | 2015-07-10 21:57:38 | [diff] [blame] | 4185 | return; |
| 4186 | |
Shimi Zhang | 37deeb2 | 2017-09-28 00:59:01 | [diff] [blame] | 4187 | using blink::mojom::SelectionMenuBehavior; |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4188 | input_handler->AdjustSelectionByCharacterOffset( |
Shimi Zhang | 37deeb2 | 2017-09-28 00:59:01 | [diff] [blame] | 4189 | start_adjust, end_adjust, |
| 4190 | show_selection_menu ? SelectionMenuBehavior::kShow |
| 4191 | : SelectionMenuBehavior::kHide); |
aurimas | ab031902 | 2015-07-10 21:57:38 | [diff] [blame] | 4192 | } |
| 4193 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4194 | void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4195 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::UpdatePreferredSize"); |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 4196 | const gfx::Size old_size = GetPreferredSize(); |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 4197 | preferred_size_ = pref_size; |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 4198 | OnPreferredSizeChanged(old_size); |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 4199 | } |
| 4200 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 4201 | void WebContentsImpl::ResizeDueToAutoResize( |
| 4202 | RenderWidgetHostImpl* render_widget_host, |
Fady Samuel | 9794711 | 2018-05-05 16:24:54 | [diff] [blame] | 4203 | const gfx::Size& new_size) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4204 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::ResizeDueToAutoResize", |
| 4205 | "render_widget_host", render_widget_host); |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 4206 | if (render_widget_host != GetRenderViewHost()->GetWidget()) |
| 4207 | return; |
| 4208 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 4209 | if (delegate_) |
| 4210 | delegate_->ResizeDueToAutoResize(this, new_size); |
| 4211 | } |
| 4212 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4213 | WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4214 | TRACE_EVENT1("content", "WebContentsImpl::OpenURL", "url", |
| 4215 | base::trace_event::ValueToString(params.url)); |
Aaron Colwell | 9dab165 | 2019-12-09 18:29:49 | [diff] [blame] | 4216 | #if DCHECK_IS_ON() |
| 4217 | DCHECK(params.Valid()); |
| 4218 | #endif |
| 4219 | |
Bo Liu | 300c605 | 2018-06-12 04:46:07 | [diff] [blame] | 4220 | if (!delegate_) { |
| 4221 | // Embedder can delay setting a delegate on new WebContents with |
| 4222 | // WebContentsDelegate::ShouldResumeRequestsForCreatedWindow. In the mean |
| 4223 | // time, navigations, including the initial one, that goes through OpenURL |
| 4224 | // should be delayed until embedder is ready to resume loading. |
| 4225 | delayed_open_url_params_ = std::make_unique<OpenURLParams>(params); |
Nasko Oskov | 83a8cf9 | 2018-10-19 14:58:56 | [diff] [blame] | 4226 | |
| 4227 | // If there was a navigation deferred when creating the window through |
| 4228 | // CreateNewWindow, drop it in favor of this navigation. |
| 4229 | delayed_load_url_params_.reset(); |
| 4230 | |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 4231 | return nullptr; |
Bo Liu | 300c605 | 2018-06-12 04:46:07 | [diff] [blame] | 4232 | } |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 4233 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 4234 | WebContents* new_contents = delegate_->OpenURLFromTab(this, params); |
pnoland | 48894465 | 2017-02-22 18:58:54 | [diff] [blame] | 4235 | |
| 4236 | RenderFrameHost* source_render_frame_host = RenderFrameHost::FromID( |
| 4237 | params.source_render_process_id, params.source_render_frame_id); |
| 4238 | |
| 4239 | if (source_render_frame_host && params.source_site_instance) { |
| 4240 | CHECK_EQ(source_render_frame_host->GetSiteInstance(), |
| 4241 | params.source_site_instance.get()); |
| 4242 | } |
| 4243 | |
| 4244 | if (new_contents && source_render_frame_host && new_contents != this) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 4245 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 4246 | observer->DidOpenRequestedURL( |
Lukasz Anforowicz | 48c9f87 | 2018-08-01 00:58:41 | [diff] [blame] | 4247 | new_contents, source_render_frame_host, params.url, params.referrer, |
| 4248 | params.disposition, params.transition, |
| 4249 | params.started_from_context_menu, params.is_renderer_initiated); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 4250 | }); |
pnoland | 48894465 | 2017-02-22 18:58:54 | [diff] [blame] | 4251 | } |
| 4252 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 4253 | return new_contents; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 4254 | } |
| 4255 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 4256 | void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset, |
| 4257 | int history_length) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4258 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::SetHistoryOffsetAndLength", |
| 4259 | "history_offset", history_offset, "history_length", |
| 4260 | history_length); |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 4261 | SendPageMessage(new PageMsg_SetHistoryOffsetAndLength( |
| 4262 | MSG_ROUTING_NONE, history_offset, history_length)); |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | void WebContentsImpl::SetHistoryOffsetAndLengthForView( |
| 4266 | RenderViewHost* render_view_host, |
| 4267 | int history_offset, |
| 4268 | int history_length) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4269 | OPTIONAL_TRACE_EVENT2( |
| 4270 | "content", "WebContentsImpl::SetHistoryOffsetAndLengthForView", |
| 4271 | "history_offset", history_offset, "history_length", history_length); |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 4272 | render_view_host->Send(new PageMsg_SetHistoryOffsetAndLength( |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 4273 | render_view_host->GetRoutingID(), history_offset, history_length)); |
[email protected] | 796931a9 | 2011-08-10 01:32:14 | [diff] [blame] | 4274 | } |
| 4275 | |
arthursonzogni | 818c264 | 2019-09-27 12:18:10 | [diff] [blame] | 4276 | void WebContentsImpl::ReloadFocusedFrame() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4277 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::ReloadFocusedFrame"); |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 4278 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 4279 | if (!focused_frame) |
| 4280 | return; |
| 4281 | |
yilkal | 921048bd | 2019-10-09 23:51:04 | [diff] [blame] | 4282 | focused_frame->Reload(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4283 | } |
| 4284 | |
| 4285 | void WebContentsImpl::Undo() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4286 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::Undo"); |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4287 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4288 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4289 | return; |
| 4290 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4291 | input_handler->Undo(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4292 | RecordAction(base::UserMetricsAction("Undo")); |
| 4293 | } |
| 4294 | |
| 4295 | void WebContentsImpl::Redo() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4296 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::Redo"); |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4297 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4298 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4299 | return; |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4300 | |
| 4301 | input_handler->Redo(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4302 | RecordAction(base::UserMetricsAction("Redo")); |
| 4303 | } |
| 4304 | |
| 4305 | void WebContentsImpl::Cut() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4306 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::Cut"); |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4307 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4308 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4309 | return; |
| 4310 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4311 | input_handler->Cut(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4312 | RecordAction(base::UserMetricsAction("Cut")); |
| 4313 | } |
| 4314 | |
| 4315 | void WebContentsImpl::Copy() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4316 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::Copy"); |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4317 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4318 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4319 | return; |
| 4320 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4321 | input_handler->Copy(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4322 | RecordAction(base::UserMetricsAction("Copy")); |
| 4323 | } |
| 4324 | |
| 4325 | void WebContentsImpl::CopyToFindPboard() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4326 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::CopyToFindPboard"); |
Avi Drissman | 7c57be7 | 2020-07-29 20:09:46 | [diff] [blame] | 4327 | #if defined(OS_MAC) |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4328 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4329 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4330 | return; |
| 4331 | |
| 4332 | // Windows/Linux don't have the concept of a find pasteboard. |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4333 | input_handler->CopyToFindPboard(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4334 | RecordAction(base::UserMetricsAction("CopyToFindPboard")); |
| 4335 | #endif |
| 4336 | } |
| 4337 | |
| 4338 | void WebContentsImpl::Paste() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4339 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::Paste"); |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4340 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4341 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4342 | return; |
| 4343 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4344 | input_handler->Paste(); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 4345 | observers_.ForEachObserver( |
| 4346 | [&](WebContentsObserver* observer) { observer->OnPaste(); }); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4347 | RecordAction(base::UserMetricsAction("Paste")); |
| 4348 | } |
| 4349 | |
| 4350 | void WebContentsImpl::PasteAndMatchStyle() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4351 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::PasteAndMatchStyle"); |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4352 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4353 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4354 | return; |
| 4355 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4356 | input_handler->PasteAndMatchStyle(); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 4357 | observers_.ForEachObserver( |
| 4358 | [&](WebContentsObserver* observer) { observer->OnPaste(); }); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4359 | RecordAction(base::UserMetricsAction("PasteAndMatchStyle")); |
| 4360 | } |
| 4361 | |
| 4362 | void WebContentsImpl::Delete() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4363 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::Delete"); |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4364 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4365 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4366 | return; |
| 4367 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4368 | input_handler->Delete(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4369 | RecordAction(base::UserMetricsAction("DeleteSelection")); |
| 4370 | } |
| 4371 | |
| 4372 | void WebContentsImpl::SelectAll() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4373 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::SelectAll"); |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4374 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4375 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4376 | return; |
| 4377 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4378 | input_handler->SelectAll(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4379 | RecordAction(base::UserMetricsAction("SelectAll")); |
| 4380 | } |
| 4381 | |
yabinh | 351e7ec | 2017-03-10 02:43:24 | [diff] [blame] | 4382 | void WebContentsImpl::CollapseSelection() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4383 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::CollapseSelection"); |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4384 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4385 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4386 | return; |
| 4387 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4388 | input_handler->CollapseSelection(); |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 4389 | } |
| 4390 | |
| 4391 | void WebContentsImpl::Replace(const base::string16& word) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4392 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::Replace"); |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4393 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4394 | if (!input_handler) |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 4395 | return; |
| 4396 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4397 | input_handler->Replace(word); |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 4398 | } |
| 4399 | |
| 4400 | void WebContentsImpl::ReplaceMisspelling(const base::string16& word) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4401 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::ReplaceMisspelling"); |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4402 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4403 | if (!input_handler) |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 4404 | return; |
| 4405 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4406 | input_handler->ReplaceMisspelling(word); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4407 | } |
| 4408 | |
| 4409 | void WebContentsImpl::NotifyContextMenuClosed( |
| 4410 | const CustomContextMenuContext& context) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4411 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::NotifyContextMenuClosed"); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4412 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 4413 | if (!focused_frame) |
| 4414 | return; |
| 4415 | |
| 4416 | focused_frame->Send(new FrameMsg_ContextMenuClosed( |
| 4417 | focused_frame->GetRoutingID(), context)); |
| 4418 | } |
| 4419 | |
| 4420 | void WebContentsImpl::ExecuteCustomContextMenuCommand( |
| 4421 | int action, const CustomContextMenuContext& context) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4422 | OPTIONAL_TRACE_EVENT1("content", |
| 4423 | "WebContentsImpl::ExecuteCustomContextMenuCommand", |
| 4424 | "action", action); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4425 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 4426 | if (!focused_frame) |
| 4427 | return; |
| 4428 | |
| 4429 | focused_frame->Send(new FrameMsg_CustomContextMenuAction( |
| 4430 | focused_frame->GetRoutingID(), context, action)); |
[email protected] | 4fed370 | 2014-04-01 09:08:00 | [diff] [blame] | 4431 | } |
| 4432 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4433 | gfx::NativeView WebContentsImpl::GetNativeView() { |
| 4434 | return view_->GetNativeView(); |
| 4435 | } |
| 4436 | |
| 4437 | gfx::NativeView WebContentsImpl::GetContentNativeView() { |
| 4438 | return view_->GetContentNativeView(); |
| 4439 | } |
| 4440 | |
| 4441 | gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() { |
| 4442 | return view_->GetTopLevelNativeWindow(); |
| 4443 | } |
| 4444 | |
| 4445 | gfx::Rect WebContentsImpl::GetViewBounds() { |
| 4446 | return view_->GetViewBounds(); |
| 4447 | } |
| 4448 | |
| 4449 | gfx::Rect WebContentsImpl::GetContainerBounds() { |
Jeremy Roman | 352239c | 2020-05-21 16:31:32 | [diff] [blame] | 4450 | return view_->GetContainerBounds(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4451 | } |
| 4452 | |
| 4453 | DropData* WebContentsImpl::GetDropData() { |
| 4454 | return view_->GetDropData(); |
| 4455 | } |
| 4456 | |
| 4457 | void WebContentsImpl::Focus() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4458 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::Focus"); |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 4459 | view_->Focus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4460 | } |
| 4461 | |
| 4462 | void WebContentsImpl::SetInitialFocus() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4463 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::SetInitialFocus"); |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 4464 | view_->SetInitialFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4465 | } |
| 4466 | |
| 4467 | void WebContentsImpl::StoreFocus() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4468 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::StoreFocus"); |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 4469 | view_->StoreFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4470 | } |
| 4471 | |
| 4472 | void WebContentsImpl::RestoreFocus() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4473 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::RestoreFocus"); |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 4474 | view_->RestoreFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4475 | } |
| 4476 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4477 | void WebContentsImpl::FocusThroughTabTraversal(bool reverse) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4478 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::FocusThroughTabTraversal", |
| 4479 | "reverse", reverse); |
Maxim Podgorodskiy | a926c4ff | 2017-11-20 02:06:39 | [diff] [blame] | 4480 | view_->FocusThroughTabTraversal(reverse); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 4481 | } |
| 4482 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4483 | bool WebContentsImpl::IsSavable() { |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 4484 | // WebKit creates Document object when MIME type is application/xhtml+xml, |
| 4485 | // so we also support this MIME type. |
Yuzu Saijo | c23e9b7 | 2020-06-25 07:21:27 | [diff] [blame] | 4486 | std::string mime_type = GetContentsMimeType(); |
| 4487 | return mime_type == "text/html" || mime_type == "text/xml" || |
| 4488 | mime_type == "application/xhtml+xml" || mime_type == "text/plain" || |
| 4489 | mime_type == "text/css" || |
| 4490 | blink::IsSupportedJavascriptMimeType(mime_type); |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 4491 | } |
| 4492 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4493 | void WebContentsImpl::OnSavePage() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4494 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::OnSavePage"); |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 4495 | // If we can not save the page, try to download it. |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 4496 | if (!IsSavable()) { |
Min Qin | da0ed206 | 2018-02-23 22:00:53 | [diff] [blame] | 4497 | download::RecordSavePackageEvent( |
| 4498 | download::SAVE_PACKAGE_DOWNLOAD_ON_NON_HTML); |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 4499 | SaveFrame(GetLastCommittedURL(), Referrer()); |
[email protected] | 27678b2a | 2012-02-04 22:09:14 | [diff] [blame] | 4500 | return; |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 4501 | } |
| 4502 | |
| 4503 | Stop(); |
| 4504 | |
| 4505 | // Create the save package and possibly prompt the user for the name to save |
| 4506 | // the page as. The user prompt is an asynchronous operation that runs on |
| 4507 | // another thread. |
| 4508 | save_package_ = new SavePackage(this); |
| 4509 | save_package_->GetSaveInfo(); |
| 4510 | } |
| 4511 | |
| 4512 | // Used in automated testing to bypass prompting the user for file names. |
| 4513 | // Instead, the names and paths are hard coded rather than running them through |
| 4514 | // file name sanitation and extension / mime checking. |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 4515 | bool WebContentsImpl::SavePage(const base::FilePath& main_file, |
| 4516 | const base::FilePath& dir_path, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4517 | SavePageType save_type) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4518 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::SavePage", "main_file", |
| 4519 | base::trace_event::ValueToString(main_file), "dir_path", |
| 4520 | base::trace_event::ValueToString(dir_path)); |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 4521 | // Stop the page from navigating. |
| 4522 | Stop(); |
| 4523 | |
| 4524 | save_package_ = new SavePackage(this, save_type, main_file, dir_path); |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4525 | return save_package_->Init(SavePackageDownloadCreatedCallback()); |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 4526 | } |
| 4527 | |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4528 | void WebContentsImpl::SaveFrame(const GURL& url, const Referrer& referrer) { |
| 4529 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::SaveFrame"); |
Xing Liu | 10329bf | 2018-03-20 19:22:14 | [diff] [blame] | 4530 | SaveFrameWithHeaders(url, referrer, std::string(), base::string16()); |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 4531 | } |
| 4532 | |
Xing Liu | 10329bf | 2018-03-20 19:22:14 | [diff] [blame] | 4533 | void WebContentsImpl::SaveFrameWithHeaders( |
| 4534 | const GURL& url, |
| 4535 | const Referrer& referrer, |
| 4536 | const std::string& headers, |
| 4537 | const base::string16& suggested_filename) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4538 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::SaveFrameWithHeaders", |
| 4539 | "url", base::trace_event::ValueToString(url), "headers", |
| 4540 | headers); |
Lei Zhang | 13a42e4 | 2019-02-19 23:28:11 | [diff] [blame] | 4541 | // Check and see if the guest can handle this. |
| 4542 | if (delegate_) { |
| 4543 | WebContents* guest_web_contents = nullptr; |
| 4544 | if (browser_plugin_embedder_) { |
| 4545 | BrowserPluginGuest* guest = browser_plugin_embedder_->GetFullPageGuest(); |
| 4546 | if (guest) |
| 4547 | guest_web_contents = guest->GetWebContents(); |
| 4548 | } else if (browser_plugin_guest_) { |
| 4549 | guest_web_contents = this; |
| 4550 | } |
| 4551 | |
| 4552 | if (guest_web_contents && delegate_->GuestSaveFrame(guest_web_contents)) |
| 4553 | return; |
| 4554 | } |
| 4555 | |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 4556 | if (!GetLastCommittedURL().is_valid()) |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4557 | return; |
sammc | 92af6155 | 2014-11-19 23:27:40 | [diff] [blame] | 4558 | if (delegate_ && delegate_->SaveFrame(url, referrer)) |
| 4559 | return; |
| 4560 | |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 4561 | // TODO(nasko): This check for main frame is incorrect and should be fixed |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 4562 | // by explicitly passing in which frame this method should target. This would |
| 4563 | // indicate whether it's the main frame, and also tell us the frame pointer |
| 4564 | // to use for routing. |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 4565 | bool is_main_frame = (url == GetLastCommittedURL()); |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 4566 | RenderFrameHost* frame_host = GetMainFrame(); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4567 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 4568 | int64_t post_id = -1; |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4569 | if (is_main_frame) { |
Lucas Furukawa Gadani | 5553a15 | 2019-01-08 18:55:57 | [diff] [blame] | 4570 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4571 | if (entry) |
| 4572 | post_id = entry->GetPostID(); |
| 4573 | } |
Ramin Halavati | 24e2101 | 2017-07-10 12:56:06 | [diff] [blame] | 4574 | net::NetworkTrafficAnnotationTag traffic_annotation = |
| 4575 | net::DefineNetworkTrafficAnnotation("download_web_contents_frame", R"( |
| 4576 | semantics { |
| 4577 | sender: "Save Page Action" |
| 4578 | description: |
| 4579 | "Saves the given frame's URL to the local file system." |
| 4580 | trigger: |
| 4581 | "The user has triggered a save operation on the frame through a " |
| 4582 | "context menu or other mechanism." |
| 4583 | data: "None." |
| 4584 | destination: WEBSITE |
| 4585 | } |
| 4586 | policy { |
Ramin Halavati | 3b97978 | 2017-07-21 11:40:26 | [diff] [blame] | 4587 | cookies_allowed: YES |
Ramin Halavati | 24e2101 | 2017-07-10 12:56:06 | [diff] [blame] | 4588 | cookies_store: "user" |
| 4589 | setting: |
| 4590 | "This feature cannot be disabled by settings, but it's is only " |
| 4591 | "triggered by user request." |
| 4592 | policy_exception_justification: "Not implemented." |
| 4593 | })"); |
Min Qin | a904f330 | 2018-02-13 23:33:34 | [diff] [blame] | 4594 | auto params = std::make_unique<download::DownloadUrlParameters>( |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 4595 | url, frame_host->GetProcess()->GetID(), |
| 4596 | frame_host->GetRenderViewHost()->GetRoutingID(), |
Matt Menke | 0dcaebc3 | 2020-03-06 17:00:10 | [diff] [blame] | 4597 | frame_host->GetRoutingID(), traffic_annotation); |
Min Qin | a904f330 | 2018-02-13 23:33:34 | [diff] [blame] | 4598 | params->set_referrer(referrer.url); |
| 4599 | params->set_referrer_policy( |
| 4600 | Referrer::ReferrerPolicyForUrlRequest(referrer.policy)); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4601 | params->set_post_id(post_id); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4602 | if (post_id >= 0) |
| 4603 | params->set_method("POST"); |
| 4604 | params->set_prompt(true); |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 4605 | |
| 4606 | if (headers.empty()) { |
| 4607 | params->set_prefer_cache(true); |
| 4608 | } else { |
Min Qin | a904f330 | 2018-02-13 23:33:34 | [diff] [blame] | 4609 | for (download::DownloadUrlParameters::RequestHeadersNameValuePair |
| 4610 | key_value : ParseDownloadHeaders(headers)) { |
Megan Jablonski | 2f6a4c5 | 2017-07-10 23:01:25 | [diff] [blame] | 4611 | params->add_request_header(key_value.first, key_value.second); |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 4612 | } |
| 4613 | } |
Xing Liu | 10329bf | 2018-03-20 19:22:14 | [diff] [blame] | 4614 | params->set_suggested_name(suggested_filename); |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 4615 | params->set_download_source(download::DownloadSource::WEB_CONTENTS_API); |
thestig | 859c7889 | 2017-05-15 21:17:06 | [diff] [blame] | 4616 | BrowserContext::GetDownloadManager(GetBrowserContext()) |
Ramin Halavati | 03efa73 | 2017-06-12 09:28:20 | [diff] [blame] | 4617 | ->DownloadUrl(std::move(params)); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4618 | } |
| 4619 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4620 | void WebContentsImpl::GenerateMHTML( |
dewittj | 6dc5747a | 2016-05-17 01:48:47 | [diff] [blame] | 4621 | const MHTMLGenerationParams& params, |
Avi Drissman | 149b783 | 2018-03-23 14:31:49 | [diff] [blame] | 4622 | base::OnceCallback<void(int64_t)> callback) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4623 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::GenerateMHTML"); |
Angel Alvarez | 90249668 | 2019-08-27 22:58:42 | [diff] [blame] | 4624 | base::OnceCallback<void(const MHTMLGenerationResult&)> wrapper_callback = |
| 4625 | base::BindOnce( |
| 4626 | [](base::OnceCallback<void(int64_t)> size_callback, |
| 4627 | const MHTMLGenerationResult& result) { |
| 4628 | std::move(size_callback).Run(result.file_size); |
| 4629 | }, |
| 4630 | std::move(callback)); |
| 4631 | MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params, |
| 4632 | std::move(wrapper_callback)); |
| 4633 | } |
| 4634 | |
| 4635 | void WebContentsImpl::GenerateMHTMLWithResult( |
| 4636 | const MHTMLGenerationParams& params, |
| 4637 | MHTMLGenerationResult::GenerateMHTMLCallback callback) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4638 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::GenerateMHTMLWithResult"); |
Avi Drissman | 149b783 | 2018-03-23 14:31:49 | [diff] [blame] | 4639 | MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params, |
| 4640 | std::move(callback)); |
[email protected] | aa4f397 | 2012-03-01 18:12:12 | [diff] [blame] | 4641 | } |
| 4642 | |
Tsuyoshi Horo | b0d8d90 | 2020-03-12 00:09:39 | [diff] [blame] | 4643 | void WebContentsImpl::GenerateWebBundle( |
| 4644 | const base::FilePath& file_path, |
| 4645 | base::OnceCallback<void(uint64_t /* file_size */, |
| 4646 | data_decoder::mojom::WebBundlerError)> callback) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4647 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::GenerateWebBundle", |
| 4648 | "file_path", |
| 4649 | base::trace_event::ValueToString(file_path)); |
Tsuyoshi Horo | b0d8d90 | 2020-03-12 00:09:39 | [diff] [blame] | 4650 | SaveAsWebBundleJob::Start(this, file_path, std::move(callback)); |
| 4651 | } |
| 4652 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4653 | const std::string& WebContentsImpl::GetContentsMimeType() { |
Yuzu Saijo | c23e9b7 | 2020-06-25 07:21:27 | [diff] [blame] | 4654 | return GetRenderViewHost()->contents_mime_type(); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4655 | } |
| 4656 | |
Mario Sanchez Prada | 0bd8b8c | 2020-10-21 17:49:23 | [diff] [blame] | 4657 | blink::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4658 | return &renderer_preferences_; |
| 4659 | } |
| 4660 | |
[email protected] | e35ccd5 | 2012-05-23 16:22:47 | [diff] [blame] | 4661 | void WebContentsImpl::Close() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4662 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::Close"); |
[email protected] | e35ccd5 | 2012-05-23 16:22:47 | [diff] [blame] | 4663 | Close(GetRenderViewHost()); |
| 4664 | } |
| 4665 | |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 4666 | void WebContentsImpl::DragSourceEndedAt(float client_x, |
| 4667 | float client_y, |
| 4668 | float screen_x, |
| 4669 | float screen_y, |
Gyuyoung Kim | bad7da7c7d | 2020-09-25 16:26:59 | [diff] [blame] | 4670 | blink::DragOperation operation, |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 4671 | RenderWidgetHost* source_rwh) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4672 | OPTIONAL_TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("content.verbose"), |
| 4673 | "WebContentsImpl::DragSourceEndedAt"); |
Lei Zhang | 6410ec1a | 2019-01-31 21:38:58 | [diff] [blame] | 4674 | if (browser_plugin_embedder_) { |
W. James MacLean | 9437b5bf | 2019-12-06 17:33:44 | [diff] [blame] | 4675 | browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y, screen_x, |
| 4676 | screen_y, operation); |
Lei Zhang | 6410ec1a | 2019-01-31 21:38:58 | [diff] [blame] | 4677 | } |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 4678 | if (source_rwh) { |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 4679 | source_rwh->DragSourceEndedAt(gfx::PointF(client_x, client_y), |
| 4680 | gfx::PointF(screen_x, screen_y), operation); |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 4681 | } |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 4682 | } |
| 4683 | |
jam | 73f89264 | 2016-09-11 06:04:06 | [diff] [blame] | 4684 | void WebContentsImpl::LoadStateChanged( |
Charles Harrison | 911fa06 | 2018-03-06 21:01:46 | [diff] [blame] | 4685 | const std::string& host, |
jam | 73f89264 | 2016-09-11 06:04:06 | [diff] [blame] | 4686 | const net::LoadStateWithParam& load_state, |
| 4687 | uint64_t upload_position, |
| 4688 | uint64_t upload_size) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4689 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::LoadStateChanged", "host", |
| 4690 | host, "load_state", static_cast<int>(load_state.state)); |
Charles Harrison | 911fa06 | 2018-03-06 21:01:46 | [diff] [blame] | 4691 | base::string16 host16 = url_formatter::IDNToUnicode(host); |
Elly Fong-Jones | cad9c3d1 | 2018-01-31 17:26:10 | [diff] [blame] | 4692 | // Drop no-op updates. |
| 4693 | if (load_state_.state == load_state.state && |
| 4694 | load_state_.param == load_state.param && |
| 4695 | upload_position_ == upload_position && upload_size_ == upload_size && |
Charles Harrison | 911fa06 | 2018-03-06 21:01:46 | [diff] [blame] | 4696 | load_state_host_ == host16) { |
Elly Fong-Jones | cad9c3d1 | 2018-01-31 17:26:10 | [diff] [blame] | 4697 | return; |
| 4698 | } |
jam | 73f89264 | 2016-09-11 06:04:06 | [diff] [blame] | 4699 | load_state_ = load_state; |
| 4700 | upload_position_ = upload_position; |
| 4701 | upload_size_ = upload_size; |
Charles Harrison | 911fa06 | 2018-03-06 21:01:46 | [diff] [blame] | 4702 | load_state_host_ = host16; |
jam | 73f89264 | 2016-09-11 06:04:06 | [diff] [blame] | 4703 | if (load_state_.state == net::LOAD_STATE_READING_RESPONSE) |
| 4704 | SetNotWaitingForResponse(); |
jam | 73f89264 | 2016-09-11 06:04:06 | [diff] [blame] | 4705 | } |
| 4706 | |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 4707 | void WebContentsImpl::SetVisibilityAndNotifyObservers(Visibility visibility) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4708 | OPTIONAL_TRACE_EVENT1("content", |
| 4709 | "WebContentsImpl::SetVisibilityAndNotifyObservers", |
| 4710 | "visibility", static_cast<int>(visibility)); |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 4711 | const Visibility previous_visibility = visibility_; |
| 4712 | visibility_ = visibility; |
| 4713 | |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 4714 | // Notify observers if the visibility changed or if WasShown() is being called |
| 4715 | // for the first time. |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 4716 | if (visibility != previous_visibility || |
| 4717 | (visibility == Visibility::VISIBLE && !did_first_set_visible_)) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 4718 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 4719 | observer->OnVisibilityChanged(visibility); |
| 4720 | }); |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 4721 | } |
| 4722 | } |
| 4723 | |
Michael Thiessen | 896405db | 2017-07-20 17:52:32 | [diff] [blame] | 4724 | void WebContentsImpl::NotifyWebContentsFocused( |
| 4725 | RenderWidgetHost* render_widget_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4726 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::NotifyWebContentsFocused", |
| 4727 | "render_widget_host", render_widget_host); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 4728 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 4729 | observer->OnWebContentsFocused(render_widget_host); |
| 4730 | }); |
calamity | 7fe55ce | 2015-04-10 03:59:37 | [diff] [blame] | 4731 | } |
| 4732 | |
Michael Thiessen | 896405db | 2017-07-20 17:52:32 | [diff] [blame] | 4733 | void WebContentsImpl::NotifyWebContentsLostFocus( |
| 4734 | RenderWidgetHost* render_widget_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4735 | OPTIONAL_TRACE_EVENT1("content", |
| 4736 | "WebContentsImpl::NotifyWebContentsLostFocus", |
| 4737 | "render_widget_host", render_widget_host); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 4738 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 4739 | observer->OnWebContentsLostFocus(render_widget_host); |
| 4740 | }); |
zijiehe | 3bee08e2 | 2017-05-17 04:14:46 | [diff] [blame] | 4741 | } |
| 4742 | |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 4743 | void WebContentsImpl::SystemDragEnded(RenderWidgetHost* source_rwh) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4744 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::SystemDragEnded", |
| 4745 | "render_widget_host", source_rwh); |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 4746 | if (source_rwh) |
| 4747 | source_rwh->DragSourceSystemDragEnded(); |
Lei Zhang | 6410ec1a | 2019-01-31 21:38:58 | [diff] [blame] | 4748 | if (browser_plugin_embedder_) |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 4749 | browser_plugin_embedder_->SystemDragEnded(); |
[email protected] | 7813bd7 | 2011-02-05 02:19:34 | [diff] [blame] | 4750 | } |
| 4751 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4752 | void WebContentsImpl::SetClosedByUserGesture(bool value) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4753 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::SetClosedByUserGesture", |
| 4754 | "value", value); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4755 | closed_by_user_gesture_ = value; |
| 4756 | } |
| 4757 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4758 | bool WebContentsImpl::GetClosedByUserGesture() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4759 | return closed_by_user_gesture_; |
| 4760 | } |
| 4761 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4762 | int WebContentsImpl::GetMinimumZoomPercent() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4763 | return minimum_zoom_percent_; |
| 4764 | } |
| 4765 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4766 | int WebContentsImpl::GetMaximumZoomPercent() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4767 | return maximum_zoom_percent_; |
| 4768 | } |
| 4769 | |
Dave Tapuska | 8f7c387 | 2020-02-07 01:16:38 | [diff] [blame] | 4770 | void WebContentsImpl::SetPageScale(float scale_factor) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4771 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::SetPageScale", |
| 4772 | "scale_factor", scale_factor); |
Dave Tapuska | 8f7c387 | 2020-02-07 01:16:38 | [diff] [blame] | 4773 | GetMainFrame()->GetAssociatedLocalMainFrame()->SetScaleFactor(scale_factor); |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 4774 | } |
| 4775 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4776 | gfx::Size WebContentsImpl::GetPreferredSize() { |
Francois Doray | 24fc62c | 2017-12-11 17:27:33 | [diff] [blame] | 4777 | return IsBeingCaptured() ? preferred_size_for_capture_ : preferred_size_; |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 4778 | } |
| 4779 | |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 4780 | bool WebContentsImpl::GotResponseToLockMouseRequest( |
| 4781 | blink::mojom::PointerLockResult result) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4782 | OPTIONAL_TRACE_EVENT0("content", |
| 4783 | "WebContentsImpl::GotResponseToLockMouseRequest"); |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 4784 | if (mouse_lock_widget_) { |
| 4785 | if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) { |
| 4786 | return mouse_lock_widget_->delegate() |
| 4787 | ->GetAsWebContents() |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 4788 | ->GotResponseToLockMouseRequest(result); |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 4789 | } |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 4790 | |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 4791 | if (mouse_lock_widget_->GotResponseToLockMouseRequest(result)) |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 4792 | return true; |
| 4793 | } |
| 4794 | |
| 4795 | for (WebContentsImpl* current = this; current; |
| 4796 | current = current->GetOuterWebContents()) { |
| 4797 | current->mouse_lock_widget_ = nullptr; |
| 4798 | } |
| 4799 | |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 4800 | return false; |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4801 | } |
| 4802 | |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 4803 | void WebContentsImpl::GotLockMousePermissionResponse(bool allowed) { |
| 4804 | GotResponseToLockMouseRequest( |
| 4805 | allowed ? blink::mojom::PointerLockResult::kSuccess |
| 4806 | : blink::mojom::PointerLockResult::kPermissionDenied); |
| 4807 | } |
| 4808 | |
Dave Tapuska | b499878 | 2020-10-08 17:22:47 | [diff] [blame] | 4809 | void WebContentsImpl::DropMouseLockForTesting() { |
| 4810 | if (mouse_lock_widget_) { |
| 4811 | mouse_lock_widget_->RejectMouseLockOrUnlockIfNecessary( |
| 4812 | blink::mojom::PointerLockResult::kUnknownError); |
| 4813 | for (WebContentsImpl* current = this; current; |
| 4814 | current = current->GetOuterWebContents()) { |
| 4815 | current->mouse_lock_widget_ = nullptr; |
| 4816 | } |
| 4817 | } |
| 4818 | } |
| 4819 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 4820 | bool WebContentsImpl::GotResponseToKeyboardLockRequest(bool allowed) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4821 | OPTIONAL_TRACE_EVENT1("content", |
| 4822 | "WebContentsImpl::GotResponseToKeyboardLockRequest", |
| 4823 | "allowed", allowed); |
| 4824 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 4825 | if (!keyboard_lock_widget_) |
| 4826 | return false; |
| 4827 | |
| 4828 | if (keyboard_lock_widget_->delegate()->GetAsWebContents() != this) { |
| 4829 | NOTREACHED(); |
| 4830 | return false; |
| 4831 | } |
| 4832 | |
| 4833 | // KeyboardLock is only supported when called by the top-level browsing |
| 4834 | // context and is not supported in embedded content scenarios. |
| 4835 | if (GetOuterWebContents()) |
| 4836 | return false; |
| 4837 | |
| 4838 | keyboard_lock_widget_->GotResponseToKeyboardLockRequest(allowed); |
| 4839 | return true; |
| 4840 | } |
| 4841 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4842 | bool WebContentsImpl::HasOpener() { |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 4843 | return GetOpener() != nullptr; |
[email protected] | a0358d7 | 2012-03-09 14:06:50 | [diff] [blame] | 4844 | } |
| 4845 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4846 | RenderFrameHostImpl* WebContentsImpl::GetOpener() { |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 4847 | FrameTreeNode* opener_ftn = frame_tree_.root()->opener(); |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 4848 | return opener_ftn ? opener_ftn->current_frame_host() : nullptr; |
jochen | 55ff350 | 2014-12-18 20:52:57 | [diff] [blame] | 4849 | } |
| 4850 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4851 | bool WebContentsImpl::HasOriginalOpener() { |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 4852 | return GetOriginalOpener() != nullptr; |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 4853 | } |
| 4854 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4855 | RenderFrameHostImpl* WebContentsImpl::GetOriginalOpener() { |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 4856 | FrameTreeNode* opener_ftn = frame_tree_.root()->original_opener(); |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 4857 | return opener_ftn ? opener_ftn->current_frame_host() : nullptr; |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 4858 | } |
| 4859 | |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 4860 | void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4861 | OPTIONAL_TRACE_EVENT1("content", |
| 4862 | "WebContentsImpl::DidChooseColorInColorChooser", |
| 4863 | "color", color); |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 4864 | color_chooser_->DidChooseColorInColorChooser(color); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 4865 | } |
| 4866 | |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 4867 | void WebContentsImpl::DidEndColorChooser() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4868 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::DidEndColorChooser"); |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 4869 | color_chooser_.reset(); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 4870 | } |
| 4871 | |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 4872 | int WebContentsImpl::DownloadImage( |
| 4873 | const GURL& url, |
| 4874 | bool is_favicon, |
Fredrik Söderquist | b2b39eb9 | 2019-11-18 16:16:50 | [diff] [blame] | 4875 | uint32_t preferred_size, |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 4876 | uint32_t max_bitmap_size, |
| 4877 | bool bypass_cache, |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 4878 | WebContents::ImageDownloadCallback callback) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4879 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::DownloadImage", "url", |
| 4880 | base::trace_event::ValueToString(url)); |
Danyao Wang | a78f3dd2 | 2020-03-05 05:31:27 | [diff] [blame] | 4881 | return DownloadImageInFrame(GlobalFrameRoutingId(), url, is_favicon, |
| 4882 | preferred_size, max_bitmap_size, bypass_cache, |
| 4883 | std::move(callback)); |
| 4884 | } |
| 4885 | |
| 4886 | int WebContentsImpl::DownloadImageInFrame( |
| 4887 | const GlobalFrameRoutingId& initiator_frame_routing_id, |
| 4888 | const GURL& url, |
| 4889 | bool is_favicon, |
| 4890 | uint32_t preferred_size, |
| 4891 | uint32_t max_bitmap_size, |
| 4892 | bool bypass_cache, |
| 4893 | WebContents::ImageDownloadCallback callback) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4894 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::DownloadImageInFrame"); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 4895 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 4896 | static int next_image_download_id = 0; |
Danyao Wang | a78f3dd2 | 2020-03-05 05:31:27 | [diff] [blame] | 4897 | |
| 4898 | RenderFrameHostImpl* initiator_frame = |
| 4899 | initiator_frame_routing_id.child_id |
| 4900 | ? RenderFrameHostImpl::FromID(initiator_frame_routing_id) |
| 4901 | : GetMainFrame(); |
Julie Jeongeun Kim | b147357 | 2019-08-15 05:59:13 | [diff] [blame] | 4902 | const mojo::Remote<blink::mojom::ImageDownloader>& mojo_image_downloader = |
Danyao Wang | a78f3dd2 | 2020-03-05 05:31:27 | [diff] [blame] | 4903 | initiator_frame->GetMojoImageDownloader(); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 4904 | const int download_id = ++next_image_download_id; |
| 4905 | if (!mojo_image_downloader) { |
| 4906 | // If the renderer process is dead (i.e. crash, or memory pressure on |
| 4907 | // Android), the downloader service will be invalid. Pre-Mojo, this would |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 4908 | // hang the callback indefinitely since the IPC would be dropped. Now, |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 4909 | // respond with a 400 HTTP error code to indicate that something went wrong. |
Gabriel Charette | e7cdc5cd | 2020-05-27 23:35:05 | [diff] [blame] | 4910 | GetUIThreadTaskRunner({})->PostTask( |
| 4911 | FROM_HERE, |
tzik | e2aca99 | 2017-09-05 08:50:54 | [diff] [blame] | 4912 | base::BindOnce(&WebContentsImpl::OnDidDownloadImage, |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 4913 | weak_factory_.GetWeakPtr(), std::move(callback), |
| 4914 | download_id, url, 400, std::vector<SkBitmap>(), |
| 4915 | std::vector<gfx::Size>())); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 4916 | return download_id; |
| 4917 | } |
| 4918 | |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 4919 | mojo_image_downloader->DownloadImage( |
Fredrik Söderquist | b2b39eb9 | 2019-11-18 16:16:50 | [diff] [blame] | 4920 | url, is_favicon, preferred_size, max_bitmap_size, bypass_cache, |
tzik | e2aca99 | 2017-09-05 08:50:54 | [diff] [blame] | 4921 | base::BindOnce(&WebContentsImpl::OnDidDownloadImage, |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 4922 | weak_factory_.GetWeakPtr(), std::move(callback), |
| 4923 | download_id, url)); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 4924 | return download_id; |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 4925 | } |
| 4926 | |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 4927 | void WebContentsImpl::Find(int request_id, |
| 4928 | const base::string16& search_text, |
Rakina Zata Amni | 3f77dff | 2018-09-08 16:19:43 | [diff] [blame] | 4929 | blink::mojom::FindOptionsPtr options) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4930 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::Find"); |
thestig | 6057a6b2 | 2015-11-12 23:01:33 | [diff] [blame] | 4931 | // Cowardly refuse to search for no text. |
| 4932 | if (search_text.empty()) { |
| 4933 | NOTREACHED(); |
| 4934 | return; |
| 4935 | } |
| 4936 | |
Rakina Zata Amni | 3f77dff | 2018-09-08 16:19:43 | [diff] [blame] | 4937 | GetOrCreateFindRequestManager()->Find(request_id, search_text, |
| 4938 | std::move(options)); |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 4939 | } |
| 4940 | |
| 4941 | void WebContentsImpl::StopFinding(StopFindAction action) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4942 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::StopFinding"); |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 4943 | if (FindRequestManager* manager = GetFindRequestManager()) |
| 4944 | manager->StopFinding(action); |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 4945 | } |
| 4946 | |
Tommy Steimel | 1836051 | 2017-11-01 00:38:19 | [diff] [blame] | 4947 | bool WebContentsImpl::WasEverAudible() { |
| 4948 | return was_ever_audible_; |
| 4949 | } |
| 4950 | |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 4951 | void WebContentsImpl::GetManifest(GetManifestCallback callback) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4952 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::GetManifest"); |
Yuzu Saijo | fce1832 | 2020-05-14 05:02:09 | [diff] [blame] | 4953 | // TODO(yuzus, 1061899): Move this function to RenderFrameHostImpl. |
| 4954 | ManifestManagerHost* manifest_manager_host = |
| 4955 | ManifestManagerHost::GetOrCreateForCurrentDocument(GetMainFrame()); |
| 4956 | manifest_manager_host->GetManifest(std::move(callback)); |
mlamouri | efdca9d | 2014-09-16 16:55:40 | [diff] [blame] | 4957 | } |
| 4958 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 4959 | void WebContentsImpl::ExitFullscreen(bool will_cause_resize) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4960 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::ExitFullscreen"); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 4961 | // Clean up related state and initiate the fullscreen exit. |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 4962 | GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary( |
| 4963 | blink::mojom::PointerLockResult::kUserRejected); |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 4964 | ExitFullscreenMode(will_cause_resize); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 4965 | } |
| 4966 | |
Mike Wasserman | b6bc015 | 2020-08-25 22:46:20 | [diff] [blame] | 4967 | base::ScopedClosureRunner WebContentsImpl::ForSecurityDropFullscreen( |
| 4968 | int64_t display_id) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 4969 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::ForSecurityDropFullscreen", |
| 4970 | "display_id", display_id); |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 4971 | // Kick WebContentses that are "related" to this WebContents out of |
| 4972 | // fullscreen. This needs to be done with two passes, because it is simple to |
| 4973 | // walk _up_ the chain of openers and outer contents, but it not simple to |
| 4974 | // walk _down_ the chain. |
| 4975 | |
| 4976 | // First, determine if any WebContents that is in fullscreen has this |
| 4977 | // WebContents as an upstream contents. Drop that WebContents out of |
| 4978 | // fullscreen if it does. This is theoretically quadratic-ish (fullscreen |
| 4979 | // contentses x each one's opener length) but neither of those is expected to |
| 4980 | // ever be a large number. |
| 4981 | |
Mike Wasserman | b6bc015 | 2020-08-25 22:46:20 | [diff] [blame] | 4982 | auto* screen = display::Screen::GetScreen(); |
| 4983 | |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 4984 | auto fullscreen_set_copy = *FullscreenContentsSet(GetBrowserContext()); |
| 4985 | for (auto* fullscreen_contents : fullscreen_set_copy) { |
Avi Drissman | 97aef04 | 2020-06-30 21:04:48 | [diff] [blame] | 4986 | // Checking IsFullscreen() for tabs in the fullscreen set may seem |
| 4987 | // redundant, but teeeeechnically fullscreen is run by the delegate, and |
| 4988 | // it's possible that the delegate's notion of fullscreen may have changed |
| 4989 | // outside of WebContents's notice. |
Mike Wasserman | b6bc015 | 2020-08-25 22:46:20 | [diff] [blame] | 4990 | if (fullscreen_contents->IsFullscreen() && |
| 4991 | (display_id == display::kInvalidDisplayId || !screen || |
| 4992 | display_id == |
| 4993 | screen->GetDisplayNearestView(fullscreen_contents->GetNativeView()) |
| 4994 | .id())) { |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 4995 | auto opener_contentses = GetAllOpeningWebContents(fullscreen_contents); |
| 4996 | if (opener_contentses.count(this)) |
| 4997 | fullscreen_contents->ExitFullscreen(true); |
| 4998 | } |
| 4999 | } |
| 5000 | |
| 5001 | // Second, walk upstream from this WebContents, and drop the fullscreen of |
| 5002 | // all WebContentses that are in fullscreen. Block all the WebContentses in |
| 5003 | // the chain from entering fullscreen while the returned closure runner is |
| 5004 | // alive. It's OK that this set doesn't contain downstream WebContentses, as |
| 5005 | // any request to enter fullscreen will have the upstream of the WebContents |
| 5006 | // checked. (See CanEnterFullscreenMode().) |
Avi Drissman | ced52b6 | 2019-08-14 21:25:46 | [diff] [blame] | 5007 | |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 5008 | std::vector<base::WeakPtr<WebContentsImpl>> blocked_contentses; |
| 5009 | |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 5010 | for (auto* opener : GetAllOpeningWebContents(this)) { |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 5011 | // Drop fullscreen if the WebContents is in it, and... |
Mike Wasserman | b6bc015 | 2020-08-25 22:46:20 | [diff] [blame] | 5012 | if (opener->IsFullscreen() && |
| 5013 | (display_id == display::kInvalidDisplayId || !screen || |
| 5014 | display_id == |
| 5015 | screen->GetDisplayNearestView(opener->GetNativeView()).id())) |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 5016 | opener->ExitFullscreen(true); |
Avi Drissman | ced52b6 | 2019-08-14 21:25:46 | [diff] [blame] | 5017 | |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 5018 | // ...block the WebContents from entering fullscreen until further notice. |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 5019 | ++opener->fullscreen_blocker_count_; |
| 5020 | blocked_contentses.push_back(opener->weak_factory_.GetWeakPtr()); |
Avi Drissman | ced52b6 | 2019-08-14 21:25:46 | [diff] [blame] | 5021 | } |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 5022 | |
| 5023 | return base::ScopedClosureRunner(base::BindOnce( |
| 5024 | [](std::vector<base::WeakPtr<WebContentsImpl>> blocked_contentses) { |
| 5025 | for (base::WeakPtr<WebContentsImpl>& web_contents : |
| 5026 | blocked_contentses) { |
| 5027 | if (web_contents) { |
| 5028 | DCHECK_GT(web_contents->fullscreen_blocker_count_, 0); |
| 5029 | --web_contents->fullscreen_blocker_count_; |
| 5030 | } |
| 5031 | } |
| 5032 | }, |
| 5033 | std::move(blocked_contentses))); |
Avi Drissman | ced52b6 | 2019-08-14 21:25:46 | [diff] [blame] | 5034 | } |
| 5035 | |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 5036 | void WebContentsImpl::ResumeLoadingCreatedWebContents() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5037 | OPTIONAL_TRACE_EVENT0("content", |
| 5038 | "WebContentsImpl::ResumeLoadingCreatedWebContents"); |
Nasko Oskov | 83a8cf9 | 2018-10-19 14:58:56 | [diff] [blame] | 5039 | if (delayed_load_url_params_.get()) { |
| 5040 | DCHECK(!delayed_open_url_params_); |
| 5041 | controller_.LoadURLWithParams(*delayed_load_url_params_.get()); |
| 5042 | delayed_load_url_params_.reset(nullptr); |
| 5043 | return; |
| 5044 | } |
| 5045 | |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 5046 | if (delayed_open_url_params_.get()) { |
| 5047 | OpenURL(*delayed_open_url_params_.get()); |
| 5048 | delayed_open_url_params_.reset(nullptr); |
| 5049 | return; |
| 5050 | } |
| 5051 | |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 5052 | // Resume blocked requests for both the RenderViewHost and RenderFrameHost. |
| 5053 | // TODO(brettw): It seems bogus to reach into here and initialize the host. |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 5054 | if (is_resume_pending_) { |
| 5055 | is_resume_pending_ = false; |
avi | 0f1bbc971 | 2015-11-17 02:58:13 | [diff] [blame] | 5056 | GetRenderViewHost()->GetWidget()->Init(); |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 5057 | GetMainFrame()->Init(); |
| 5058 | } |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 5059 | } |
| 5060 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5061 | bool WebContentsImpl::FocusLocationBarByDefault() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5062 | OPTIONAL_TRACE_EVENT0("content", |
| 5063 | "WebContentsImpl::FocusLocationBarByDefault"); |
Xiyuan Xia | 2a66b11 | 2018-12-06 15:52:16 | [diff] [blame] | 5064 | if (should_focus_location_bar_by_default_) |
[email protected] | 0c940663 | 2013-02-08 01:13:33 | [diff] [blame] | 5065 | return true; |
Xiyuan Xia | 2a66b11 | 2018-12-06 15:52:16 | [diff] [blame] | 5066 | |
[email protected] | 0c940663 | 2013-02-08 01:13:33 | [diff] [blame] | 5067 | return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 5068 | } |
| 5069 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 5070 | void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) { |
Charles Harrison | 53096ba | 2017-12-15 15:39:48 | [diff] [blame] | 5071 | TRACE_EVENT1("navigation", "WebContentsImpl::DidStartNavigation", |
| 5072 | "navigation_handle", navigation_handle); |
Alan Cutter | ab48fc0 | 2020-02-24 12:26:42 | [diff] [blame] | 5073 | if (navigation_handle->IsInMainFrame()) |
| 5074 | favicon_urls_.clear(); |
Mounir Lamouri | 7b4a1f23 | 2019-12-23 16:32:10 | [diff] [blame] | 5075 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 5076 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5077 | observer->DidStartNavigation(navigation_handle); |
| 5078 | }); |
Xiyuan Xia | 2a66b11 | 2018-12-06 15:52:16 | [diff] [blame] | 5079 | if (navigation_handle->IsInMainFrame()) { |
| 5080 | // When the browser is started with about:blank as the startup URL, focus |
| 5081 | // the location bar (which will also select its contents) so people can |
| 5082 | // simply begin typing to navigate elsewhere. |
| 5083 | // |
| 5084 | // We need to be careful not to trigger this for anything other than the |
| 5085 | // startup navigation. In particular, if we allow an attacker to open a |
| 5086 | // popup to about:blank, then navigate, focusing the Omnibox will cause the |
| 5087 | // end of the new URL to be scrolled into view instead of the start, |
| 5088 | // allowing the attacker to spoof other URLs. The conditions checked here |
| 5089 | // are all aimed at ensuring no such attacker-controlled navigation can |
| 5090 | // trigger this. |
| 5091 | should_focus_location_bar_by_default_ = |
| 5092 | controller_.IsInitialNavigation() && |
| 5093 | !navigation_handle->IsRendererInitiated() && |
| 5094 | navigation_handle->GetURL() == url::kAboutBlankURL; |
| 5095 | } |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 5096 | } |
| 5097 | |
| 5098 | void WebContentsImpl::DidRedirectNavigation( |
| 5099 | NavigationHandle* navigation_handle) { |
Charles Harrison | 53096ba | 2017-12-15 15:39:48 | [diff] [blame] | 5100 | TRACE_EVENT1("navigation", "WebContentsImpl::DidRedirectNavigation", |
| 5101 | "navigation_handle", navigation_handle); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 5102 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5103 | observer->DidRedirectNavigation(navigation_handle); |
| 5104 | }); |
jam | 5f358e5 | 2017-02-13 16:37:03 | [diff] [blame] | 5105 | // Notify accessibility if this is a reload. This has to called on the |
| 5106 | // BrowserAccessibilityManager associated with the old RFHI. |
| 5107 | if (navigation_handle->GetReloadType() != ReloadType::NONE) { |
Mohamed Abdelhalim | 9579496 | 2019-09-20 11:16:49 | [diff] [blame] | 5108 | NavigationRequest* request = NavigationRequest::From(navigation_handle); |
jam | 5f358e5 | 2017-02-13 16:37:03 | [diff] [blame] | 5109 | BrowserAccessibilityManager* manager = |
Mohamed Abdelhalim | 9579496 | 2019-09-20 11:16:49 | [diff] [blame] | 5110 | request->frame_tree_node() |
jam | 5f358e5 | 2017-02-13 16:37:03 | [diff] [blame] | 5111 | ->current_frame_host() |
| 5112 | ->browser_accessibility_manager(); |
| 5113 | if (manager) |
| 5114 | manager->UserIsReloading(); |
| 5115 | } |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 5116 | } |
| 5117 | |
clamy | efca29e | 2015-09-17 00:22:11 | [diff] [blame] | 5118 | void WebContentsImpl::ReadyToCommitNavigation( |
| 5119 | NavigationHandle* navigation_handle) { |
Charles Harrison | 53096ba | 2017-12-15 15:39:48 | [diff] [blame] | 5120 | TRACE_EVENT1("navigation", "WebContentsImpl::ReadyToCommitNavigation", |
| 5121 | "navigation_handle", navigation_handle); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 5122 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5123 | observer->ReadyToCommitNavigation(navigation_handle); |
| 5124 | }); |
Kenneth Russell | 954ed9ce | 2018-04-12 23:07:01 | [diff] [blame] | 5125 | // If any domains are blocked from accessing 3D APIs because they may |
| 5126 | // have caused the GPU to reset recently, unblock them here if the user |
| 5127 | // initiated this navigation. This implies that the user was involved in |
| 5128 | // the decision to navigate, so there's no concern about |
| 5129 | // denial-of-service issues. Want to do this as early as |
| 5130 | // possible to avoid race conditions with pages attempting to access |
| 5131 | // WebGL early on. |
| 5132 | // |
| 5133 | // TODO(crbug.com/617904): currently navigations initiated by the browser |
| 5134 | // (reload button, reload menu option, pressing return in the Omnibox) |
| 5135 | // return false from HasUserGesture(). If or when that is addressed, |
| 5136 | // remove the check for IsRendererInitiated() below. |
| 5137 | // |
| 5138 | // TODO(crbug.com/832180): HasUserGesture comes from the renderer |
| 5139 | // process and isn't validated. Until it is, don't trust it. |
| 5140 | if (!navigation_handle->IsRendererInitiated()) { |
| 5141 | GpuDataManagerImpl::GetInstance()->UnblockDomainFrom3DAPIs( |
| 5142 | navigation_handle->GetURL()); |
| 5143 | } |
| 5144 | |
John Abd-El-Malek | fde08e6da | 2017-12-05 04:06:24 | [diff] [blame] | 5145 | if (navigation_handle->IsSameDocument()) |
| 5146 | return; |
| 5147 | |
Livvie Lin | 139bf44 | 2018-08-10 00:18:54 | [diff] [blame] | 5148 | // SSLInfo is not needed on subframe navigations since the main-frame |
| 5149 | // certificate is the only one that can be inspected (using the info |
| 5150 | // bubble) without refreshing the page with DevTools open. |
Carlos IL | aed1e7b | 2019-03-12 19:27:21 | [diff] [blame] | 5151 | // We don't call DidStartResourceResponse on net errors, since that results on |
| 5152 | // existing cert exceptions being revoked, which leads to weird behavior with |
| 5153 | // committed interstitials or while offline. We only need the error check for |
| 5154 | // the main frame case because unlike this method, SubresourceResponseStarted |
| 5155 | // does not get called on network errors. |
| 5156 | if (navigation_handle->IsInMainFrame() && |
| 5157 | navigation_handle->GetNetErrorCode() == net::OK) { |
Livvie Lin | 139bf44 | 2018-08-10 00:18:54 | [diff] [blame] | 5158 | controller_.ssl_manager()->DidStartResourceResponse( |
Lukasz Anforowicz | d334bba | 2020-02-10 23:32:55 | [diff] [blame] | 5159 | navigation_handle->GetURL(), |
Camille Lamy | 62b82601 | 2019-02-26 09:15:47 | [diff] [blame] | 5160 | navigation_handle->GetSSLInfo().has_value() |
| 5161 | ? net::IsCertStatusError( |
| 5162 | navigation_handle->GetSSLInfo()->cert_status) |
| 5163 | : false); |
| 5164 | } |
John Abd-El-Malek | fde08e6da | 2017-12-05 04:06:24 | [diff] [blame] | 5165 | |
Bruce Dawson | e1c5c84 | 2020-09-15 02:09:14 | [diff] [blame] | 5166 | // LoadingStateChanged must be called last in case it triggers deletion of |
| 5167 | // |this| due to recursive message pumps. |
John Abd-El-Malek | fde08e6da | 2017-12-05 04:06:24 | [diff] [blame] | 5168 | SetNotWaitingForResponse(); |
clamy | efca29e | 2015-09-17 00:22:11 | [diff] [blame] | 5169 | } |
| 5170 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 5171 | void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) { |
Charles Harrison | 53096ba | 2017-12-15 15:39:48 | [diff] [blame] | 5172 | TRACE_EVENT1("navigation", "WebContentsImpl::DidFinishNavigation", |
| 5173 | "navigation_handle", navigation_handle); |
Steven Holte | 3804134 | 2018-06-22 22:00:57 | [diff] [blame] | 5174 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 5175 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5176 | observer->DidFinishNavigation(navigation_handle); |
| 5177 | }); |
Becca Hughes | d11d650 | 2018-07-31 17:01:28 | [diff] [blame] | 5178 | if (display_cutout_host_impl_) |
| 5179 | display_cutout_host_impl_->DidFinishNavigation(navigation_handle); |
| 5180 | |
jam | 5f358e5 | 2017-02-13 16:37:03 | [diff] [blame] | 5181 | if (navigation_handle->HasCommitted()) { |
Ian Prest | cdd843d | 2020-01-28 18:59:58 | [diff] [blame] | 5182 | // TODO(domfarolino, dmazzoni): Do this using WebContentsObserver. See |
| 5183 | // https://crbug.com/981271. |
| 5184 | BrowserAccessibilityManager* manager = |
| 5185 | static_cast<RenderFrameHostImpl*>( |
| 5186 | navigation_handle->GetRenderFrameHost()) |
| 5187 | ->browser_accessibility_manager(); |
| 5188 | if (manager) { |
| 5189 | if (navigation_handle->IsErrorPage()) { |
| 5190 | manager->NavigationFailed(); |
| 5191 | } else { |
| 5192 | manager->NavigationSucceeded(); |
| 5193 | } |
| 5194 | } |
| 5195 | |
Yue Ru Sun | 979c4b16 | 2019-11-06 16:11:04 | [diff] [blame] | 5196 | if (navigation_handle->IsInMainFrame()) { |
| 5197 | last_committed_source_id_including_same_document_ = |
Steven Holte | 3804134 | 2018-06-22 22:00:57 | [diff] [blame] | 5198 | ukm::ConvertToSourceId(navigation_handle->GetNavigationId(), |
| 5199 | ukm::SourceIdType::NAVIGATION_ID); |
Yue Ru Sun | 979c4b16 | 2019-11-06 16:11:04 | [diff] [blame] | 5200 | |
| 5201 | if (!navigation_handle->IsSameDocument()) { |
| 5202 | was_ever_audible_ = false; |
Yue Ru Sun | 979c4b16 | 2019-11-06 16:11:04 | [diff] [blame] | 5203 | } |
Tommy Steimel | 1836051 | 2017-11-01 00:38:19 | [diff] [blame] | 5204 | } |
Lan Wei | f81c6e7c | 2020-02-12 16:46:09 | [diff] [blame] | 5205 | |
| 5206 | if (!navigation_handle->IsSameDocument()) |
| 5207 | last_screen_orientation_change_time_ = base::TimeTicks(); |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 5208 | } |
Xiyuan Xia | 2a66b11 | 2018-12-06 15:52:16 | [diff] [blame] | 5209 | |
| 5210 | // If we didn't end up on about:blank after setting this in DidStartNavigation |
| 5211 | // then don't focus the location bar. |
| 5212 | if (should_focus_location_bar_by_default_ && |
| 5213 | navigation_handle->GetURL() != url::kAboutBlankURL) { |
| 5214 | should_focus_location_bar_by_default_ = false; |
| 5215 | } |
yilkal | 796e89e | 2019-10-02 23:58:28 | [diff] [blame] | 5216 | |
yilkal | 172da77 | 2019-11-06 22:49:07 | [diff] [blame] | 5217 | if (navigation_handle->IsInMainFrame() && first_navigation_completed_) |
| 5218 | RecordMaxFrameCountUMA(max_loaded_frame_count_); |
yilkal | 796e89e | 2019-10-02 23:58:28 | [diff] [blame] | 5219 | |
yilkal | 172da77 | 2019-11-06 22:49:07 | [diff] [blame] | 5220 | // If navigation has successfully finished in the main frame, set |
| 5221 | // |first_navigation_completed_| to true so that we will record |
| 5222 | // |max_loaded_frame_count_| above when future main frame navigations finish. |
| 5223 | if (navigation_handle->IsInMainFrame() && !navigation_handle->IsErrorPage()) { |
| 5224 | first_navigation_completed_ = true; |
| 5225 | |
| 5226 | // Navigation has completed in main frame. Reset |max_loaded_frame_count_|. |
| 5227 | // |max_loaded_frame_count_| is not necessarily 1 if the navigation was |
| 5228 | // served from BackForwardCache. |
| 5229 | max_loaded_frame_count_ = |
| 5230 | GetMainFrame()->frame_tree_node()->GetFrameTreeSize(); |
yilkal | 796e89e | 2019-10-02 23:58:28 | [diff] [blame] | 5231 | } |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 5232 | |
| 5233 | if (web_preferences_) { |
| 5234 | // Update the WebPreferences for this WebContents that depends on changes |
| 5235 | // that might occur during navigation. This will only update the preferences |
| 5236 | // that needs to be updated (and won't cause an update/overwrite preferences |
| 5237 | // that needs to stay the same after navigations). |
| 5238 | bool value_changed_due_to_override = |
| 5239 | GetContentClient()->browser()->OverrideWebPreferencesAfterNavigation( |
| 5240 | this, web_preferences_.get()); |
| 5241 | // We need to update the WebPreferences value on the renderer if the value |
| 5242 | // is changed due to the override above, or if the navigation is served from |
| 5243 | // the back-forward cache, because the WebPreferences value stored in the |
| 5244 | // renderer might be stale (because we don't send WebPreferences updates to |
| 5245 | // bfcached renderers). |
| 5246 | // TODO(rakina): Maybe handle the back-forward cache case in |
| 5247 | // ReadyToCommitNavigation instead? |
| 5248 | if (value_changed_due_to_override || |
| 5249 | NavigationRequest::From(navigation_handle) |
| 5250 | ->IsServedFromBackForwardCache()) { |
| 5251 | SetWebPreferences(*web_preferences_.get()); |
| 5252 | } |
| 5253 | } |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 5254 | } |
| 5255 | |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 5256 | void WebContentsImpl::DidFailLoadWithError( |
| 5257 | RenderFrameHostImpl* render_frame_host, |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 5258 | const GURL& url, |
Dave Tapuska | 924ef3c | 2020-01-22 18:20:59 | [diff] [blame] | 5259 | int error_code) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5260 | TRACE_EVENT2("content,navigation", "WebContentsImpl::DidFailLoadWithError", |
| 5261 | "render_frame_host", |
| 5262 | base::trace_event::ToTracedValue(render_frame_host), "url", |
| 5263 | base::trace_event::ValueToString(url)); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 5264 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5265 | observer->DidFailLoad(render_frame_host, url, error_code); |
| 5266 | }); |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 5267 | } |
| 5268 | |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 5269 | void WebContentsImpl::NotifyChangedNavigationState( |
| 5270 | InvalidateTypes changed_flags) { |
| 5271 | NotifyNavigationStateChanged(changed_flags); |
| 5272 | } |
| 5273 | |
lukasza | 1d02573 | 2016-09-28 21:36:08 | [diff] [blame] | 5274 | bool WebContentsImpl::ShouldTransferNavigation(bool is_main_frame_navigation) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5275 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::ShouldTransferNavigation", |
| 5276 | "is_main_frame_navigation", is_main_frame_navigation); |
creis | 2946027 | 2015-12-16 04:38:22 | [diff] [blame] | 5277 | if (!delegate_) |
| 5278 | return true; |
lukasza | 1d02573 | 2016-09-28 21:36:08 | [diff] [blame] | 5279 | return delegate_->ShouldTransferNavigation(is_main_frame_navigation); |
creis | 2946027 | 2015-12-16 04:38:22 | [diff] [blame] | 5280 | } |
| 5281 | |
[email protected] | aa62afd | 2014-04-22 19:22:46 | [diff] [blame] | 5282 | bool WebContentsImpl::ShouldPreserveAbortedURLs() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5283 | OPTIONAL_TRACE_EVENT0("content", |
| 5284 | "WebContentsImpl::ShouldPreserveAbortedURLs"); |
[email protected] | aa62afd | 2014-04-22 19:22:46 | [diff] [blame] | 5285 | if (!delegate_) |
| 5286 | return false; |
| 5287 | return delegate_->ShouldPreserveAbortedURLs(this); |
| 5288 | } |
| 5289 | |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 5290 | void WebContentsImpl::DidNavigateMainFramePreCommit( |
[email protected] | 5cfbddc | 2014-06-23 23:52:23 | [diff] [blame] | 5291 | bool navigation_is_within_page) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5292 | TRACE_EVENT1("content,navigation", |
| 5293 | "WebContentsImpl::DidNavigateMainFramePreCommit", |
| 5294 | "navigation_is_within_page", navigation_is_within_page); |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 5295 | // Ensure fullscreen mode is exited before committing the navigation to a |
| 5296 | // different page. The next page will not start out assuming it is in |
| 5297 | // fullscreen mode. |
[email protected] | 5cfbddc | 2014-06-23 23:52:23 | [diff] [blame] | 5298 | if (navigation_is_within_page) { |
[email protected] | dfc39cb | 2014-04-09 22:58:19 | [diff] [blame] | 5299 | // No page change? Then, the renderer and browser can remain in fullscreen. |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 5300 | return; |
| 5301 | } |
Avi Drissman | 97aef04 | 2020-06-30 21:04:48 | [diff] [blame] | 5302 | if (IsFullscreen()) |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 5303 | ExitFullscreen(false); |
Avi Drissman | 97aef04 | 2020-06-30 21:04:48 | [diff] [blame] | 5304 | DCHECK(!IsFullscreen()); |
Joe Downing | c1a57efe | 2018-05-09 18:23:54 | [diff] [blame] | 5305 | |
| 5306 | // Clean up keyboard lock state when navigating. |
| 5307 | CancelKeyboardLock(keyboard_lock_widget_); |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 5308 | } |
| 5309 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 5310 | void WebContentsImpl::DidNavigateMainFramePostCommit( |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 5311 | RenderFrameHostImpl* render_frame_host, |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 5312 | const LoadCommittedDetails& details, |
| 5313 | const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5314 | OPTIONAL_TRACE_EVENT1( |
| 5315 | "content,navigation", "WebContentsImpl::DidNavigateMainFramePostCommit", |
| 5316 | "render_frame_host", base::trace_event::ToTracedValue(render_frame_host)); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 5317 | if (details.is_navigation_to_different_page()) { |
| 5318 | // Clear the status bubble. This is a workaround for a bug where WebKit |
| 5319 | // doesn't let us know that the cursor left an element during a |
| 5320 | // transition (this is also why the mouse cursor remains as a hand after |
| 5321 | // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 5322 | // clear the bubble when a user navigates to a named anchor in the same |
| 5323 | // page. |
Lukasz Anforowicz | fd70714 | 2018-02-07 19:46:13 | [diff] [blame] | 5324 | ClearTargetURL(); |
lanwei | 9d343ad2 | 2015-02-11 01:46:00 | [diff] [blame] | 5325 | |
| 5326 | RenderWidgetHostViewBase* rwhvb = |
| 5327 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 5328 | if (rwhvb) |
| 5329 | rwhvb->OnDidNavigateMainFrameToNewPage(); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 5330 | } |
| 5331 | |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 5332 | if (delegate_) |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 5333 | delegate_->DidNavigateMainFramePostCommit(this); |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 5334 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
Shivani Sharma | 985474f | 2019-05-23 21:36:47 | [diff] [blame] | 5335 | |
Alan Cutter | d73a15d9 | 2020-08-21 07:12:45 | [diff] [blame] | 5336 | // The following events will not fire again if the page is restored from the |
| 5337 | // BackForwardCache. So fire them ourselves if needed. |
Carlos Caballero | 91fffb2 | 2019-10-29 15:24:30 | [diff] [blame] | 5338 | if (details.is_navigation_to_different_page() && |
| 5339 | GetRenderViewHost()->did_first_visually_non_empty_paint()) { |
Carlos Caballero | 91fffb2 | 2019-10-29 15:24:30 | [diff] [blame] | 5340 | DidFirstVisuallyNonEmptyPaint(GetRenderViewHost()); |
| 5341 | } |
Alan Cutter | d73a15d9 | 2020-08-21 07:12:45 | [diff] [blame] | 5342 | if (GetRenderViewHost()->theme_color() != last_sent_theme_color_) |
Carlos Caballero | 1215f88 | 2019-10-29 15:58:43 | [diff] [blame] | 5343 | OnThemeColorChanged(GetRenderViewHost()); |
Alan Cutter | d73a15d9 | 2020-08-21 07:12:45 | [diff] [blame] | 5344 | if (GetRenderViewHost()->background_color() != last_sent_background_color_) |
| 5345 | OnBackgroundColorChanged(GetRenderViewHost()); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 5346 | } |
| 5347 | |
| 5348 | void WebContentsImpl::DidNavigateAnyFramePostCommit( |
| 5349 | RenderFrameHostImpl* render_frame_host, |
| 5350 | const LoadCommittedDetails& details, |
| 5351 | const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5352 | OPTIONAL_TRACE_EVENT1( |
| 5353 | "content,navigation", "WebContentsImpl::DidNavigateAnyFramePostCommit", |
| 5354 | "render_frame_host", base::trace_event::ToTracedValue(render_frame_host)); |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 5355 | // Now that something has committed, we don't need to track whether the |
| 5356 | // initial page has been accessed. |
| 5357 | has_accessed_initial_document_ = false; |
| 5358 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 5359 | // If we navigate off the page, close all JavaScript dialogs. |
eugenebut | ee08663a | 2017-04-27 17:43:12 | [diff] [blame] | 5360 | if (!details.is_same_document) |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 5361 | CancelActiveAndPendingDialogs(); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 5362 | |
avi | d53461d | 2016-02-25 17:15:04 | [diff] [blame] | 5363 | // If this is a user-initiated navigation, start allowing JavaScript dialogs |
| 5364 | // again. |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 5365 | if (params.gesture == NavigationGestureUser && dialog_manager_) { |
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 5366 | dialog_manager_->CancelDialogs(this, /*reset_state=*/true); |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 5367 | } |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 5368 | } |
| 5369 | |
[email protected] | 277857a | 2014-06-03 10:38:01 | [diff] [blame] | 5370 | bool WebContentsImpl::CanOverscrollContent() const { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5371 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::CanOverscrollContent"); |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 5372 | // Disable overscroll when touch emulation is on. See crbug.com/369938. |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 5373 | if (force_disable_overscroll_content_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 5374 | return false; |
| 5375 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 5376 | if (delegate_) |
| 5377 | return delegate_->CanOverscrollContent(); |
| 5378 | |
| 5379 | return false; |
| 5380 | } |
| 5381 | |
Carlos Caballero | 1215f88 | 2019-10-29 15:58:43 | [diff] [blame] | 5382 | void WebContentsImpl::OnThemeColorChanged(RenderViewHostImpl* source) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5383 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnThemeColorChanged", |
| 5384 | "render_view_host", source); |
Carlos Caballero | 1215f88 | 2019-10-29 15:58:43 | [diff] [blame] | 5385 | if (source->did_first_visually_non_empty_paint() && |
| 5386 | last_sent_theme_color_ != source->theme_color()) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 5387 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5388 | observer->DidChangeThemeColor(); |
| 5389 | }); |
Matt Jones | 36fc288 | 2020-08-25 14:25:12 | [diff] [blame] | 5390 | last_sent_theme_color_ = source->theme_color(); |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 5391 | } |
[email protected] | e710476 | 2014-06-20 19:17:25 | [diff] [blame] | 5392 | } |
| 5393 | |
Alan Cutter | d73a15d9 | 2020-08-21 07:12:45 | [diff] [blame] | 5394 | void WebContentsImpl::OnBackgroundColorChanged(RenderViewHostImpl* source) { |
Rune Lillesveen | d14781f | 2020-10-06 19:36:11 | [diff] [blame] | 5395 | if (source->did_first_visually_non_empty_paint()) { |
| 5396 | if (last_sent_background_color_ != source->background_color()) { |
| 5397 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5398 | observer->OnBackgroundColorChanged(); |
| 5399 | }); |
| 5400 | last_sent_background_color_ = source->background_color(); |
| 5401 | } |
| 5402 | return; |
| 5403 | } |
| 5404 | |
| 5405 | if (source->background_color().has_value()) { |
| 5406 | // <meta name="color-scheme" content="dark"> may pass the dark canvas |
| 5407 | // background before the first paint in order to avoid flashing the white |
| 5408 | // background in between loading documents. If we perform a navigation |
| 5409 | // within the same renderer process, we keep the content background from the |
| 5410 | // previous page while rendering is blocked in the new page, but for cross |
| 5411 | // process navigations we would paint the default background (typically |
| 5412 | // white) while the rendering is blocked. |
| 5413 | if (auto* view = GetRenderWidgetHostView()) { |
| 5414 | static_cast<RenderWidgetHostViewBase*>(view)->SetContentBackgroundColor( |
| 5415 | source->background_color().value()); |
| 5416 | } |
Alan Cutter | d73a15d9 | 2020-08-21 07:12:45 | [diff] [blame] | 5417 | } |
| 5418 | } |
| 5419 | |
Gyuyoung Kim | 1905f7c | 2020-05-02 00:00:24 | [diff] [blame] | 5420 | void WebContentsImpl::DidLoadResourceFromMemoryCache( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5421 | RenderFrameHostImpl* source, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 5422 | const GURL& url, |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 5423 | const std::string& http_method, |
[email protected] | 6d6cfb3a | 2012-05-23 22:53:18 | [diff] [blame] | 5424 | const std::string& mime_type, |
Kinuko Yasuda | 433f710a | 2020-02-14 02:11:58 | [diff] [blame] | 5425 | network::mojom::RequestDestination request_destination) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5426 | OPTIONAL_TRACE_EVENT2( |
| 5427 | "content", "WebContentsImpl::DidLoadResourceFromMemoryCache", |
| 5428 | "render_frame_host", base::trace_event::ToTracedValue(source), "url", |
| 5429 | base::trace_event::ValueToString(url)); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 5430 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5431 | observer->DidLoadResourceFromMemoryCache(url, mime_type, |
| 5432 | request_destination); |
| 5433 | }); |
[email protected] | b0f724c | 2013-09-05 04:21:13 | [diff] [blame] | 5434 | |
Steven Bingler | 674fb082 | 2018-12-12 18:04:52 | [diff] [blame] | 5435 | if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5436 | StoragePartition* partition = source->GetProcess()->GetStoragePartition(); |
John Abd-El-Malek | f4fe9d8 | 2019-07-31 04:05:59 | [diff] [blame] | 5437 | partition->GetNetworkContext()->NotifyExternalCacheHit( |
Matt Menke | 2a33dee | 2019-12-02 17:01:54 | [diff] [blame] | 5438 | url, http_method, source->GetNetworkIsolationKey()); |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 5439 | } |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 5440 | } |
| 5441 | |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 5442 | void WebContentsImpl::DidDisplayInsecureContent() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5443 | OPTIONAL_TRACE_EVENT0("content", |
| 5444 | "WebContentsImpl::DidDisplayInsecureContent"); |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 5445 | controller_.ssl_manager()->DidDisplayMixedContent(); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 5446 | } |
| 5447 | |
Dave Tapuska | a657d87 | 2019-10-21 20:23:21 | [diff] [blame] | 5448 | void WebContentsImpl::DidContainInsecureFormAction() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5449 | OPTIONAL_TRACE_EVENT0("content", |
| 5450 | "WebContentsImpl::DidContainInsecureFormAction"); |
elawrence | b2ac2a23 | 2017-03-27 21:46:25 | [diff] [blame] | 5451 | controller_.ssl_manager()->DidContainInsecureFormAction(); |
| 5452 | } |
| 5453 | |
Julie Jeongeun Kim | 0b10349 | 2020-01-29 05:30:51 | [diff] [blame] | 5454 | void WebContentsImpl::DocumentAvailableInMainFrame() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5455 | OPTIONAL_TRACE_EVENT0("content", |
| 5456 | "WebContentsImpl::DocumentAvailableInMainFrame"); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 5457 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5458 | observer->DocumentAvailableInMainFrame(); |
| 5459 | }); |
Julie Jeongeun Kim | 0b10349 | 2020-01-29 05:30:51 | [diff] [blame] | 5460 | } |
| 5461 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5462 | void WebContentsImpl::OnDidRunInsecureContent(RenderFrameHostImpl* source, |
| 5463 | const GURL& security_origin, |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 5464 | const GURL& target_url) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5465 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnDidRunInsecureContent", |
| 5466 | "render_frame_host", |
| 5467 | base::trace_event::ToTracedValue(source)); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5468 | // TODO(nick, estark): Should we call FilterURL using |source|'s process on |
| 5469 | // these parameters? |target_url| seems unused, except for a log message. And |
| 5470 | // |security_origin| might be replaceable with the origin of the main frame. |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 5471 | DidRunInsecureContent(security_origin, target_url); |
| 5472 | } |
| 5473 | |
| 5474 | void WebContentsImpl::DidRunInsecureContent(const GURL& security_origin, |
| 5475 | const GURL& target_url) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5476 | OPTIONAL_TRACE_EVENT2( |
| 5477 | "content", "WebContentsImpl::DidRunInsecureContent", "security_origin", |
| 5478 | base::trace_event::ValueToString(security_origin), "target_url", |
| 5479 | base::trace_event::ValueToString(target_url)); |
[email protected] | 9450c46 | 2013-11-23 01:22:58 | [diff] [blame] | 5480 | LOG(WARNING) << security_origin << " ran insecure content from " |
| 5481 | << target_url.possibly_invalid_spec(); |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 5482 | RecordAction(base::UserMetricsAction("SSL.RanInsecureContent")); |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 5483 | if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom, |
brettw | a7ff1b29 | 2015-07-16 17:49:29 | [diff] [blame] | 5484 | base::CompareCase::INSENSITIVE_ASCII)) |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 5485 | RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle")); |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 5486 | controller_.ssl_manager()->DidRunMixedContent(security_origin); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 5487 | } |
| 5488 | |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 5489 | void WebContentsImpl::PassiveInsecureContentFound(const GURL& resource_url) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5490 | OPTIONAL_TRACE_EVENT1( |
| 5491 | "content", "WebContentsImpl::PassiveInsecureContentFound", "resource_url", |
| 5492 | base::trace_event::ValueToString(resource_url)); |
Sergey Kuznetsov | 3ebc01b | 2018-02-01 04:57:36 | [diff] [blame] | 5493 | if (delegate_) { |
| 5494 | delegate_->PassiveInsecureContentFound(resource_url); |
| 5495 | } |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 5496 | } |
| 5497 | |
| 5498 | bool WebContentsImpl::ShouldAllowRunningInsecureContent( |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 5499 | bool allowed_per_prefs, |
| 5500 | const url::Origin& origin, |
| 5501 | const GURL& resource_url) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5502 | OPTIONAL_TRACE_EVENT0("content", |
| 5503 | "WebContentsImpl::ShouldAllowRunningInsecureContent"); |
Sergey Kuznetsov | 3ebc01b | 2018-02-01 04:57:36 | [diff] [blame] | 5504 | if (delegate_) { |
Carlos IL | 29294a6 | 2020-05-15 00:21:16 | [diff] [blame] | 5505 | return delegate_->ShouldAllowRunningInsecureContent(this, allowed_per_prefs, |
| 5506 | origin, resource_url); |
Sergey Kuznetsov | 3ebc01b | 2018-02-01 04:57:36 | [diff] [blame] | 5507 | } |
| 5508 | |
| 5509 | return allowed_per_prefs; |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 5510 | } |
| 5511 | |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5512 | void WebContentsImpl::ViewSource(RenderFrameHostImpl* frame) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5513 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::ViewSource", |
| 5514 | "render_frame_host", |
| 5515 | base::trace_event::ToTracedValue(frame)); |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5516 | DCHECK_EQ(this, WebContents::FromRenderFrameHost(frame)); |
| 5517 | |
| 5518 | // Don't do anything if there is no |delegate_| that could accept and show the |
| 5519 | // new WebContents containing the view-source. |
| 5520 | if (!delegate_) |
| 5521 | return; |
| 5522 | |
| 5523 | // Use the last committed entry, since the pending entry hasn't loaded yet and |
| 5524 | // won't be copied into the cloned tab. |
| 5525 | NavigationEntryImpl* last_committed_entry = |
Fergal Daly | 09d6c76 | 2020-05-29 02:05:18 | [diff] [blame] | 5526 | GetController().GetLastCommittedEntry(); |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5527 | if (!last_committed_entry) |
| 5528 | return; |
| 5529 | |
| 5530 | FrameNavigationEntry* frame_entry = |
| 5531 | last_committed_entry->GetFrameEntry(frame->frame_tree_node()); |
| 5532 | if (!frame_entry) |
| 5533 | return; |
| 5534 | |
| 5535 | // Any new WebContents opened while this WebContents is in fullscreen can be |
| 5536 | // used to confuse the user, so drop fullscreen. |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 5537 | base::ScopedClosureRunner fullscreen_block = ForSecurityDropFullscreen(); |
| 5538 | // The new view source contents will be independent of this contents, so |
| 5539 | // release the fullscreen block. |
| 5540 | fullscreen_block.RunAndReset(); |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5541 | |
| 5542 | // We intentionally don't share the SiteInstance with the original frame so |
| 5543 | // that view source has a consistent process model and always ends up in a new |
| 5544 | // process (https://crbug.com/699493). |
| 5545 | scoped_refptr<SiteInstanceImpl> site_instance_for_view_source = nullptr; |
Lukasz Anforowicz | 435bcb58 | 2019-07-12 20:50:06 | [diff] [blame] | 5546 | // Referrer and initiator are not important, because view-source should not |
| 5547 | // hit the network, but should be served from the cache instead. |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5548 | Referrer referrer_for_view_source; |
Lukasz Anforowicz | 435bcb58 | 2019-07-12 20:50:06 | [diff] [blame] | 5549 | base::Optional<url::Origin> initiator_for_view_source = base::nullopt; |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5550 | // Do not restore title, derive it from the url. |
| 5551 | base::string16 title_for_view_source; |
| 5552 | auto navigation_entry = std::make_unique<NavigationEntryImpl>( |
| 5553 | site_instance_for_view_source, frame_entry->url(), |
Lukasz Anforowicz | 435bcb58 | 2019-07-12 20:50:06 | [diff] [blame] | 5554 | referrer_for_view_source, initiator_for_view_source, |
| 5555 | title_for_view_source, ui::PAGE_TRANSITION_LINK, |
Marijn Kruisselbrink | 7a0d5e18 | 2018-05-24 22:55:09 | [diff] [blame] | 5556 | /* is_renderer_initiated = */ false, |
| 5557 | /* blob_url_loader_factory = */ nullptr); |
Joel Hockey | 891e8806 | 2020-04-30 05:38:44 | [diff] [blame] | 5558 | const GURL url(content::kViewSourceScheme + std::string(":") + |
| 5559 | frame_entry->url().spec()); |
| 5560 | navigation_entry->SetVirtualURL(url); |
Matt Menke | a56c599 | 2020-04-10 20:53:56 | [diff] [blame] | 5561 | navigation_entry->set_isolation_info( |
| 5562 | frame->GetIsolationInfoForSubresources()); |
Yao Xiao | f68f57d | 2019-10-03 04:20:05 | [diff] [blame] | 5563 | |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5564 | // Do not restore scroller position. |
| 5565 | // TODO(creis, lukasza, arthursonzogni): Do not reuse the original PageState, |
| 5566 | // but start from a new one and only copy the needed data. |
Miyoung Shin | 5d77f7207 | 2020-10-09 15:14:20 | [diff] [blame] | 5567 | const blink::PageState& new_page_state = |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5568 | frame_entry->page_state().RemoveScrollOffset(); |
| 5569 | |
| 5570 | scoped_refptr<FrameNavigationEntry> new_frame_entry = |
| 5571 | navigation_entry->root_node()->frame_entry; |
| 5572 | new_frame_entry->set_method(frame_entry->method()); |
| 5573 | new_frame_entry->SetPageState(new_page_state); |
| 5574 | |
| 5575 | // Create a new WebContents, which is used to display the source code. |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 5576 | std::unique_ptr<WebContents> view_source_contents = |
Erik Chen | bb8e738e | 2018-04-28 14:10:43 | [diff] [blame] | 5577 | Create(CreateParams(GetBrowserContext())); |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5578 | |
| 5579 | // Restore the previously created NavigationEntry. |
| 5580 | std::vector<std::unique_ptr<NavigationEntry>> navigation_entries; |
| 5581 | navigation_entries.push_back(std::move(navigation_entry)); |
| 5582 | view_source_contents->GetController().Restore(0, RestoreType::CURRENT_SESSION, |
| 5583 | &navigation_entries); |
| 5584 | |
| 5585 | // Add |view_source_contents| as a new tab. |
| 5586 | gfx::Rect initial_rect; |
| 5587 | constexpr bool kUserGesture = true; |
| 5588 | bool ignored_was_blocked; |
Joel Hockey | 891e8806 | 2020-04-30 05:38:44 | [diff] [blame] | 5589 | delegate_->AddNewContents(this, std::move(view_source_contents), url, |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5590 | WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 5591 | initial_rect, kUserGesture, &ignored_was_blocked); |
| 5592 | // Note that the |delegate_| could have deleted |view_source_contents| during |
| 5593 | // AddNewContents method call. |
| 5594 | } |
| 5595 | |
Lukasz Anforowicz | d334bba | 2020-02-10 23:32:55 | [diff] [blame] | 5596 | void WebContentsImpl::SubresourceResponseStarted(const GURL& url, |
| 5597 | net::CertStatus cert_status) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5598 | OPTIONAL_TRACE_EVENT1("content", |
| 5599 | "WebContentsImpl::SubresourceResponseStarted", "url", |
| 5600 | base::trace_event::ValueToString(url)); |
Lukasz Anforowicz | d334bba | 2020-02-10 23:32:55 | [diff] [blame] | 5601 | controller_.ssl_manager()->DidStartResourceResponse(url, cert_status); |
Jay Civelli | d5904f0 | 2018-03-23 19:43:57 | [diff] [blame] | 5602 | SetNotWaitingForResponse(); |
| 5603 | } |
| 5604 | |
Jay Civelli | 116683f | 2018-03-27 19:56:23 | [diff] [blame] | 5605 | void WebContentsImpl::ResourceLoadComplete( |
Jay Civelli | 52a6330 | 2018-04-30 22:39:55 | [diff] [blame] | 5606 | RenderFrameHost* render_frame_host, |
Clark DuVall | 36164bd | 2018-08-09 22:49:08 | [diff] [blame] | 5607 | const GlobalRequestID& request_id, |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 5608 | blink::mojom::ResourceLoadInfoPtr resource_load_info) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5609 | OPTIONAL_TRACE_EVENT2( |
| 5610 | "content", "WebContentsImpl::ResourceLoadComplete", "render_frame_host", |
| 5611 | base::trace_event::ToTracedValue(render_frame_host), "request_id", |
| 5612 | base::trace_event::TracedValue::Build( |
| 5613 | {{"child_id", request_id.child_id}, |
| 5614 | {"request_id", request_id.request_id}})); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 5615 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5616 | observer->ResourceLoadComplete(render_frame_host, request_id, |
| 5617 | *resource_load_info); |
| 5618 | }); |
John Abd-El-Malek | d488264 | 2017-12-04 21:45:19 | [diff] [blame] | 5619 | } |
| 5620 | |
Gyuyoung Kim | 1ac4ca78 | 2020-09-11 03:32:51 | [diff] [blame] | 5621 | const blink::web_pref::WebPreferences& |
| 5622 | WebContentsImpl::GetOrCreateWebPreferences() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5623 | OPTIONAL_TRACE_EVENT0("content", |
| 5624 | "WebContentsImpl::GetOrCreateWebPreferences"); |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 5625 | // Compute WebPreferences based on the current state if it's null. |
| 5626 | if (!web_preferences_) |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 5627 | OnWebPreferencesChanged(); |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 5628 | return *web_preferences_.get(); |
| 5629 | } |
| 5630 | |
| 5631 | bool WebContentsImpl::IsWebPreferencesSet() const { |
| 5632 | return web_preferences_.get(); |
| 5633 | } |
| 5634 | |
Gyuyoung Kim | 1ac4ca78 | 2020-09-11 03:32:51 | [diff] [blame] | 5635 | void WebContentsImpl::SetWebPreferences( |
| 5636 | const blink::web_pref::WebPreferences& prefs) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5637 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::SetWebPreferences"); |
Gyuyoung Kim | 1ac4ca78 | 2020-09-11 03:32:51 | [diff] [blame] | 5638 | web_preferences_ = std::make_unique<blink::web_pref::WebPreferences>(prefs); |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 5639 | // Get all the RenderViewHosts (except the ones for currently back-forward |
| 5640 | // cached pages), and make them send the current WebPreferences |
| 5641 | // to the renderer. WebPreferences updates for back-forward cached pages will |
| 5642 | // be sent when we restore those pages from the back-forward cache. |
| 5643 | for (auto& rvh : frame_tree_.render_view_hosts()) { |
| 5644 | rvh.second->SendWebPreferencesToRenderer(); |
| 5645 | } |
| 5646 | } |
| 5647 | |
| 5648 | void WebContentsImpl::RecomputeWebPreferencesSlow() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5649 | OPTIONAL_TRACE_EVENT0("content", |
| 5650 | "WebContentsImpl::RecomputeWebPreferencesSlow"); |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 5651 | // OnWebPreferencesChanged is a no-op when this is true. |
| 5652 | if (updating_web_preferences_) |
| 5653 | return; |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 5654 | // Resets |web_preferences_| so that we won't have any cached value for slow |
| 5655 | // attributes (which won't get recomputed if we have pre-existing values for |
| 5656 | // them). |
| 5657 | web_preferences_.reset(); |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 5658 | OnWebPreferencesChanged(); |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 5659 | } |
| 5660 | |
Wei Li | 5bb65974 | 2018-02-14 03:07:58 | [diff] [blame] | 5661 | void WebContentsImpl::PrintCrossProcessSubframe( |
| 5662 | const gfx::Rect& rect, |
| 5663 | int document_cookie, |
| 5664 | RenderFrameHost* subframe_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5665 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::PrintCrossProcessSubframe", |
| 5666 | "subframe", |
| 5667 | base::trace_event::ToTracedValue(subframe_host)); |
Wei Li | 5c0b4d1 | 2018-03-22 15:05:22 | [diff] [blame] | 5668 | auto* outer_contents = GetOuterWebContents(); |
| 5669 | if (outer_contents) { |
| 5670 | // When an extension or app page is printed, the content should be |
| 5671 | // composited with outer content, so the outer contents should handle the |
| 5672 | // print request. |
| 5673 | outer_contents->PrintCrossProcessSubframe(rect, document_cookie, |
| 5674 | subframe_host); |
| 5675 | return; |
| 5676 | } |
| 5677 | |
Wei Li | 5bb65974 | 2018-02-14 03:07:58 | [diff] [blame] | 5678 | // If there is no delegate such as in tests or during deletion, do nothing. |
| 5679 | if (!delegate_) |
| 5680 | return; |
| 5681 | |
| 5682 | delegate_->PrintCrossProcessSubframe(this, rect, document_cookie, |
| 5683 | subframe_host); |
| 5684 | } |
| 5685 | |
ckitagawa | 8695799b | 2020-02-05 16:08:49 | [diff] [blame] | 5686 | void WebContentsImpl::CapturePaintPreviewOfCrossProcessSubframe( |
| 5687 | const gfx::Rect& rect, |
| 5688 | const base::UnguessableToken& guid, |
| 5689 | RenderFrameHost* render_frame_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5690 | OPTIONAL_TRACE_EVENT1( |
| 5691 | "content", "WebContentsImpl::CapturePaintPreviewOfCrossProcessSubframe", |
| 5692 | "render_frame_host", base::trace_event::ToTracedValue(render_frame_host)); |
ckitagawa | 8695799b | 2020-02-05 16:08:49 | [diff] [blame] | 5693 | if (!delegate_) |
| 5694 | return; |
ckitagawa | c43ac98 | 2020-07-07 17:41:17 | [diff] [blame] | 5695 | delegate_->CapturePaintPreviewOfSubframe(this, rect, guid, render_frame_host); |
ckitagawa | 8695799b | 2020-02-05 16:08:49 | [diff] [blame] | 5696 | } |
| 5697 | |
rob.buis | 300b087 | 2017-03-10 20:43:58 | [diff] [blame] | 5698 | #if defined(OS_ANDROID) |
| 5699 | base::android::ScopedJavaLocalRef<jobject> |
| 5700 | WebContentsImpl::GetJavaRenderFrameHostDelegate() { |
| 5701 | return GetJavaWebContents(); |
| 5702 | } |
| 5703 | #endif |
| 5704 | |
Hiroki Nakagawa | 39d1bbe | 2020-07-14 16:15:52 | [diff] [blame] | 5705 | void WebContentsImpl::OnDidDisplayContentWithCertificateErrors() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5706 | OPTIONAL_TRACE_EVENT0( |
| 5707 | "content", "WebContentsImpl::OnDidDisplayContentWithCertificateErrors"); |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 5708 | controller_.ssl_manager()->DidDisplayContentWithCertErrors(); |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 5709 | } |
| 5710 | |
| 5711 | void WebContentsImpl::OnDidRunContentWithCertificateErrors( |
Zhuoyu Qian | 4353f7f | 2018-01-08 05:33:00 | [diff] [blame] | 5712 | RenderFrameHostImpl* source) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5713 | OPTIONAL_TRACE_EVENT1( |
| 5714 | "content", "WebContentsImpl::OnDidRunContentWithCertificateErrors", |
| 5715 | "render_frame_host", base::trace_event::ToTracedValue(source)); |
Emily Stark | abbdd66 | 2020-06-05 02:40:13 | [diff] [blame] | 5716 | // For RenderFrameHosts that are inactive and going to be discarded, we can |
| 5717 | // disregard this message; there's no need to update the UI if the UI will |
| 5718 | // never be shown again. |
| 5719 | // |
| 5720 | // We still process this message for speculative RenderFrameHosts. This can |
| 5721 | // happen when a subframe's main resource has a certificate error. The |
| 5722 | // currently committed navigation entry will get marked as having run insecure |
| 5723 | // content and that will carry over to the navigation entry for the |
| 5724 | // speculative RFH when it commits. |
| 5725 | if (source->lifecycle_state() != |
| 5726 | RenderFrameHostImpl::LifecycleState::kSpeculative && |
| 5727 | source->IsInactiveAndDisallowReactivation()) { |
estark | aeda142 | 2016-05-10 02:31:12 | [diff] [blame] | 5728 | return; |
Emily Stark | abbdd66 | 2020-06-05 02:40:13 | [diff] [blame] | 5729 | } |
estark | cd2e30c | 2016-08-12 06:51:15 | [diff] [blame] | 5730 | controller_.ssl_manager()->DidRunContentWithCertErrors( |
Emily Stark | abbdd66 | 2020-06-05 02:40:13 | [diff] [blame] | 5731 | source->GetMainFrame()->GetLastCommittedOrigin().GetURL()); |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 5732 | } |
| 5733 | |
Kouhei Ueno | 97e0990d | 2019-09-25 02:57:27 | [diff] [blame] | 5734 | void WebContentsImpl::DOMContentLoaded(RenderFrameHost* render_frame_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5735 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::DOMContentLoaded", |
| 5736 | "render_frame_host", |
| 5737 | base::trace_event::ToTracedValue(render_frame_host)); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 5738 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5739 | observer->DOMContentLoaded(render_frame_host); |
| 5740 | }); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 5741 | } |
| 5742 | |
Gyuyoung Kim | 525e0c5d | 2020-03-09 15:04:19 | [diff] [blame] | 5743 | void WebContentsImpl::OnDidFinishLoad(RenderFrameHost* render_frame_host, |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5744 | const GURL& url) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5745 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::OnDidFinishLoad", |
| 5746 | "render_frame_host", |
| 5747 | base::trace_event::ToTracedValue(render_frame_host), |
| 5748 | "url", base::trace_event::ValueToString(url)); |
[email protected] | 8b3af1e | 2014-01-24 13:29:12 | [diff] [blame] | 5749 | GURL validated_url(url); |
Gyuyoung Kim | 525e0c5d | 2020-03-09 15:04:19 | [diff] [blame] | 5750 | render_frame_host->GetProcess()->FilterURL(false, &validated_url); |
[email protected] | 028053d4 | 2014-03-05 22:20:37 | [diff] [blame] | 5751 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 5752 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5753 | observer->DidFinishLoad(render_frame_host, validated_url); |
| 5754 | }); |
yilkal | 172da77 | 2019-11-06 22:49:07 | [diff] [blame] | 5755 | size_t tree_size = frame_tree_.root()->GetFrameTreeSize(); |
| 5756 | if (max_loaded_frame_count_ < tree_size) |
| 5757 | max_loaded_frame_count_ = tree_size; |
| 5758 | |
Gyuyoung Kim | 525e0c5d | 2020-03-09 15:04:19 | [diff] [blame] | 5759 | if (!render_frame_host->GetParent()) |
yilkal | 172da77 | 2019-11-06 22:49:07 | [diff] [blame] | 5760 | UMA_HISTOGRAM_COUNTS_1000("Navigation.MainFrame.FrameCount", tree_size); |
[email protected] | 1a55c5b | 2011-11-29 11:36:31 | [diff] [blame] | 5761 | } |
| 5762 | |
Dave Tapuska | 549baab | 2019-03-19 15:52:40 | [diff] [blame] | 5763 | void WebContentsImpl::OnGoToEntryAtOffset(RenderFrameHostImpl* source, |
Julie Jeongeun Kim | 144f819 | 2020-01-18 06:59:03 | [diff] [blame] | 5764 | int32_t offset, |
Dave Tapuska | 043b94a | 2019-09-10 14:14:35 | [diff] [blame] | 5765 | bool has_user_gesture) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5766 | OPTIONAL_TRACE_EVENT2( |
| 5767 | "content", "WebContentsImpl::OnGoToEntryAtOffset", "render_frame_host", |
| 5768 | base::trace_event::ToTracedValue(source), "offset", offset); |
Arthur Sonzogni | a7d715a | 2018-09-20 16:11:13 | [diff] [blame] | 5769 | // Non-user initiated navigations coming from the renderer should be ignored |
| 5770 | // if there is an ongoing browser-initiated navigation. |
| 5771 | // See https://crbug.com/879965. |
| 5772 | // TODO(arthursonzogni): See if this should check for ongoing navigations in |
| 5773 | // the frame(s) affected by the session history navigation, rather than just |
| 5774 | // the main frame. |
Kevin McNee | 96851e1 | 2020-07-16 03:43:22 | [diff] [blame] | 5775 | if (Navigator::ShouldIgnoreIncomingRendererRequest( |
| 5776 | frame_tree_.root()->navigation_request(), has_user_gesture)) |
| 5777 | return; |
Arthur Sonzogni | a7d715a | 2018-09-20 16:11:13 | [diff] [blame] | 5778 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5779 | // All frames are allowed to navigate the global history. |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 5780 | if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) { |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 5781 | if (source->IsSandboxed(network::mojom::WebSandboxFlags::kTopNavigation)) { |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 5782 | // Keep track of whether this is a session history from a sandboxed iframe |
| 5783 | // with top level navigation disallowed. |
| 5784 | controller_.GoToOffsetInSandboxedFrame(offset, |
| 5785 | source->GetFrameTreeNodeId()); |
| 5786 | } else { |
| 5787 | controller_.GoToOffset(offset); |
| 5788 | } |
| 5789 | } |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 5790 | } |
| 5791 | |
Dave Tapuska | 4c02911b | 2020-02-14 22:52:07 | [diff] [blame] | 5792 | void WebContentsImpl::OnPageScaleFactorChanged(RenderFrameHostImpl* source, |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5793 | float page_scale_factor) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5794 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::OnPageScaleFactorChanged", |
| 5795 | "render_frame_host", |
| 5796 | base::trace_event::ToTracedValue(source), |
| 5797 | "page_scale_factor", page_scale_factor); |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 5798 | #if !defined(OS_ANDROID) |
| 5799 | // While page scale factor is used on mobile, this PageScaleFactorIsOne logic |
| 5800 | // is only needed on desktop. |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 5801 | bool is_one = page_scale_factor == 1.f; |
| 5802 | if (is_one != page_scale_factor_is_one_) { |
| 5803 | page_scale_factor_is_one_ = is_one; |
| 5804 | |
| 5805 | HostZoomMapImpl* host_zoom_map = |
| 5806 | static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this)); |
| 5807 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5808 | if (host_zoom_map) { |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 5809 | host_zoom_map->SetPageScaleFactorIsOneForView( |
Dave Tapuska | 4c02911b | 2020-02-14 22:52:07 | [diff] [blame] | 5810 | source->GetProcess()->GetID(), |
| 5811 | source->GetRenderViewHost()->GetRoutingID(), |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 5812 | page_scale_factor_is_one_); |
| 5813 | } |
| 5814 | } |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 5815 | #endif // !defined(OS_ANDROID) |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 5816 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 5817 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5818 | observer->OnPageScaleFactorChanged(page_scale_factor); |
| 5819 | }); |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 5820 | } |
| 5821 | |
W. James MacLean | 6219867 | 2019-06-04 16:46:10 | [diff] [blame] | 5822 | void WebContentsImpl::OnTextAutosizerPageInfoChanged( |
Henrique Ferreiro | ba53547 | 2020-04-21 11:38:36 | [diff] [blame] | 5823 | RenderFrameHostImpl* source, |
| 5824 | blink::mojom::TextAutosizerPageInfoPtr page_info) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5825 | OPTIONAL_TRACE_EVENT1( |
| 5826 | "content", "WebContentsImpl::OnTextAutosizerPageInfoChanged", |
| 5827 | "render_frame_host", base::trace_event::ToTracedValue(source)); |
W. James MacLean | 6219867 | 2019-06-04 16:46:10 | [diff] [blame] | 5828 | // Keep a copy of |page_info| in case we create a new RenderView before |
| 5829 | // the next update. |
Henrique Ferreiro | ba53547 | 2020-04-21 11:38:36 | [diff] [blame] | 5830 | text_autosizer_page_info_.main_frame_width = page_info->main_frame_width; |
| 5831 | text_autosizer_page_info_.main_frame_layout_width = |
| 5832 | page_info->main_frame_layout_width; |
| 5833 | text_autosizer_page_info_.device_scale_adjustment = |
| 5834 | page_info->device_scale_adjustment; |
Antonio Gomes | da7e03d | 2020-08-05 15:03:08 | [diff] [blame] | 5835 | |
| 5836 | auto remote_frames_broadcast_callback = base::BindRepeating( |
| 5837 | [](const blink::mojom::TextAutosizerPageInfo& page_info, |
| 5838 | RenderFrameProxyHost* proxy_host) { |
| 5839 | DCHECK(proxy_host); |
| 5840 | proxy_host->GetAssociatedRemoteMainFrame()->UpdateTextAutosizerPageInfo( |
| 5841 | page_info.Clone()); |
| 5842 | }, |
| 5843 | text_autosizer_page_info_); |
| 5844 | |
| 5845 | frame_tree_.root()->render_manager()->ExecuteRemoteFramesBroadcastMethod( |
| 5846 | std::move(remote_frames_broadcast_callback), source->GetSiteInstance()); |
W. James MacLean | 6219867 | 2019-06-04 16:46:10 | [diff] [blame] | 5847 | } |
| 5848 | |
Kent Tamura | 8c9e056 | 2018-11-06 07:02:19 | [diff] [blame] | 5849 | void WebContentsImpl::EnumerateDirectory( |
| 5850 | RenderFrameHost* render_frame_host, |
Kent Tamura | 3abb32d | 2020-07-02 00:23:01 | [diff] [blame] | 5851 | scoped_refptr<FileChooserImpl::FileSelectListenerImpl> listener, |
Kent Tamura | 8c9e056 | 2018-11-06 07:02:19 | [diff] [blame] | 5852 | const base::FilePath& directory_path) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5853 | OPTIONAL_TRACE_EVENT2( |
| 5854 | "content", "WebContentsImpl::EnumerateDirectory", "render_frame_host", |
| 5855 | base::trace_event::ToTracedValue(render_frame_host), "directory_path", |
| 5856 | base::trace_event::ValueToString(directory_path)); |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 5857 | // Any explicit focusing of another window while this WebContents is in |
| 5858 | // fullscreen can be used to confuse the user, so drop fullscreen. |
| 5859 | base::ScopedClosureRunner fullscreen_block = ForSecurityDropFullscreen(); |
| 5860 | listener->SetFullscreenBlock(std::move(fullscreen_block)); |
| 5861 | |
Kent Tamura | 8c9e056 | 2018-11-06 07:02:19 | [diff] [blame] | 5862 | if (delegate_) |
| 5863 | delegate_->EnumerateDirectory(this, std::move(listener), directory_path); |
| 5864 | else |
| 5865 | listener->FileSelectionCanceled(); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 5866 | } |
| 5867 | |
Dave Tapuska | f9fc312 | 2019-10-18 19:42:55 | [diff] [blame] | 5868 | void WebContentsImpl::RegisterProtocolHandler(RenderFrameHostImpl* source, |
| 5869 | const std::string& protocol, |
| 5870 | const GURL& url, |
| 5871 | const base::string16& title, |
| 5872 | bool user_gesture) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5873 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::RegisterProtocolHandler", |
| 5874 | "render_frame_host", |
| 5875 | base::trace_event::ToTracedValue(source), "protocol", |
| 5876 | protocol); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5877 | // TODO(nick): Do we need to apply FilterURL to |url|? |
[email protected] | e5f2de0 | 2012-07-20 22:15:43 | [diff] [blame] | 5878 | if (!delegate_) |
| 5879 | return; |
| 5880 | |
Raymes Khoury | 58373df | 2019-08-06 06:29:20 | [diff] [blame] | 5881 | if (!AreValidRegisterProtocolHandlerArguments( |
| 5882 | protocol, url, source->GetLastCommittedOrigin())) { |
| 5883 | ReceivedBadMessage(source->GetProcess(), |
| 5884 | bad_message::REGISTER_PROTOCOL_HANDLER_INVALID_URL); |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 5885 | return; |
Raymes Khoury | 58373df | 2019-08-06 06:29:20 | [diff] [blame] | 5886 | } |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 5887 | |
Carlos Caballero | 8a6c6b7 | 2020-07-20 16:56:22 | [diff] [blame] | 5888 | delegate_->RegisterProtocolHandler(source, protocol, url, user_gesture); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 5889 | } |
| 5890 | |
Dave Tapuska | f9fc312 | 2019-10-18 19:42:55 | [diff] [blame] | 5891 | void WebContentsImpl::UnregisterProtocolHandler(RenderFrameHostImpl* source, |
| 5892 | const std::string& protocol, |
| 5893 | const GURL& url, |
| 5894 | bool user_gesture) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5895 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::UnregisterProtocolHandler", |
| 5896 | "render_frame_host", |
| 5897 | base::trace_event::ToTracedValue(source), "protocol", |
| 5898 | protocol); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5899 | // TODO(nick): Do we need to apply FilterURL to |url|? |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 5900 | if (!delegate_) |
| 5901 | return; |
| 5902 | |
Raymes Khoury | 58373df | 2019-08-06 06:29:20 | [diff] [blame] | 5903 | if (!AreValidRegisterProtocolHandlerArguments( |
| 5904 | protocol, url, source->GetLastCommittedOrigin())) { |
| 5905 | ReceivedBadMessage(source->GetProcess(), |
| 5906 | bad_message::REGISTER_PROTOCOL_HANDLER_INVALID_URL); |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 5907 | return; |
Raymes Khoury | 58373df | 2019-08-06 06:29:20 | [diff] [blame] | 5908 | } |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 5909 | |
Carlos Caballero | 8a6c6b7 | 2020-07-20 16:56:22 | [diff] [blame] | 5910 | delegate_->UnregisterProtocolHandler(source, protocol, url, user_gesture); |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 5911 | } |
| 5912 | |
Marijn Kruisselbrink | 7f51967 | 2019-02-05 19:12:50 | [diff] [blame] | 5913 | void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5914 | bool blocked_by_policy) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5915 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::OnAppCacheAccessed"); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5916 | // TODO(nick): Should we consider |source| here? Should we call FilterURL on |
| 5917 | // |manifest_url|? |
| 5918 | |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 5919 | // Notify observers about navigation. |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 5920 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5921 | observer->AppCacheAccessed(manifest_url, blocked_by_policy); |
| 5922 | }); |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 5923 | } |
| 5924 | |
Gyuyoung Kim | c5f4ac1 | 2020-05-08 10:59:39 | [diff] [blame] | 5925 | void WebContentsImpl::DomOperationResponse(const std::string& json_string) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5926 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::DomOperationResponse", |
| 5927 | "json_string", json_string); |
| 5928 | |
Gyuyoung Kim | c5f4ac1 | 2020-05-08 10:59:39 | [diff] [blame] | 5929 | // TODO(lukasza): The notification below should probably indicate which |
| 5930 | // RenderFrameHostImpl the message is coming from. This can enable tests to |
| 5931 | // talk to 2 frames at the same time, without being confused which frame a |
| 5932 | // given response comes from. See also a corresponding TODO in the |
| 5933 | // ExecuteScriptHelper in //content/public/test/browser_test_utils.cc |
| 5934 | NotificationService::current()->Notify( |
| 5935 | NOTIFICATION_DOM_OPERATION_RESPONSE, Source<WebContents>(this), |
| 5936 | Details<const std::string>(&json_string)); |
| 5937 | } |
| 5938 | |
Gyuyoung Kim | 4c5051784 | 2020-06-04 17:50:44 | [diff] [blame] | 5939 | void WebContentsImpl::SavableResourceLinksResponse( |
| 5940 | RenderFrameHostImpl* source, |
| 5941 | const std::vector<GURL>& resources_list, |
| 5942 | blink::mojom::ReferrerPtr referrer, |
| 5943 | const std::vector<blink::mojom::SavableSubframePtr>& subframes) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5944 | OPTIONAL_TRACE_EVENT1( |
| 5945 | "content", "WebContentsImpl::SavableResourceLinksResponse", |
| 5946 | "render_frame_host", base::trace_event::ToTracedValue(source)); |
Gyuyoung Kim | 4c5051784 | 2020-06-04 17:50:44 | [diff] [blame] | 5947 | save_package_->SavableResourceLinksResponse(source, resources_list, |
| 5948 | std::move(referrer), subframes); |
| 5949 | } |
| 5950 | |
| 5951 | void WebContentsImpl::SavableResourceLinksError(RenderFrameHostImpl* source) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5952 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::SavableResourceLinksError", |
| 5953 | "render_frame_host", |
| 5954 | base::trace_event::ToTracedValue(source)); |
Gyuyoung Kim | 4c5051784 | 2020-06-04 17:50:44 | [diff] [blame] | 5955 | save_package_->SavableResourceLinksError(source); |
| 5956 | } |
| 5957 | |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 5958 | void WebContentsImpl::OnServiceWorkerAccessed( |
| 5959 | RenderFrameHost* render_frame_host, |
| 5960 | const GURL& scope, |
| 5961 | AllowServiceWorkerResult allowed) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5962 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::OnServiceWorkerAccessed", |
| 5963 | "render_frame_host", |
| 5964 | base::trace_event::ToTracedValue(render_frame_host), |
| 5965 | "scope", base::trace_event::ValueToString(scope)); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 5966 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5967 | observer->OnServiceWorkerAccessed(render_frame_host, scope, allowed); |
| 5968 | }); |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 5969 | } |
| 5970 | |
| 5971 | void WebContentsImpl::OnServiceWorkerAccessed( |
| 5972 | NavigationHandle* navigation, |
| 5973 | const GURL& scope, |
| 5974 | AllowServiceWorkerResult allowed) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5975 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::OnServiceWorkerAccessed", |
| 5976 | "navigation_handle", navigation, "scope", |
| 5977 | base::trace_event::ValueToString(scope)); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 5978 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5979 | observer->OnServiceWorkerAccessed(navigation, scope, allowed); |
| 5980 | }); |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 5981 | } |
| 5982 | |
Miyoung Shin | cb6475a | 2019-11-09 10:49:45 | [diff] [blame] | 5983 | void WebContentsImpl::OnColorChooserFactoryReceiver( |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 5984 | mojo::PendingReceiver<blink::mojom::ColorChooserFactory> receiver) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5985 | OPTIONAL_TRACE_EVENT0("content", |
| 5986 | "WebContentsImpl::OnColorChooserFactoryReceiver"); |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 5987 | color_chooser_factory_receivers_.Add(this, std::move(receiver)); |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 5988 | } |
| 5989 | |
| 5990 | void WebContentsImpl::OpenColorChooser( |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 5991 | mojo::PendingReceiver<blink::mojom::ColorChooser> chooser_receiver, |
| 5992 | mojo::PendingRemote<blink::mojom::ColorChooserClient> client, |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 5993 | SkColor color, |
Joel Hockey | 163835a | 2017-12-20 11:51:57 | [diff] [blame] | 5994 | std::vector<blink::mojom::ColorSuggestionPtr> suggestions) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 5995 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::OpenColorChooser"); |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 5996 | content::ColorChooser* new_color_chooser = |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 5997 | delegate_ ? delegate_->OpenColorChooser(this, color, suggestions) |
| 5998 | : nullptr; |
[email protected] | 820957a | 2014-01-14 14:56:30 | [diff] [blame] | 5999 | if (!new_color_chooser) |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 6000 | return; |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 6001 | |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 6002 | color_chooser_.reset(); |
| 6003 | color_chooser_ = std::make_unique<ColorChooser>( |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 6004 | new_color_chooser, std::move(chooser_receiver), std::move(client)); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 6005 | } |
| 6006 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 6007 | #if BUILDFLAG(ENABLE_PLUGINS) |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 6008 | void WebContentsImpl::OnPepperInstanceCreated(RenderFrameHostImpl* source, |
| 6009 | int32_t pp_instance) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6010 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnPepperInstanceCreated", |
| 6011 | "render_frame_host", |
| 6012 | base::trace_event::ToTracedValue(source)); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6013 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6014 | observer->PepperInstanceCreated(); |
| 6015 | }); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 6016 | pepper_playback_observer_->PepperInstanceCreated(source, pp_instance); |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 6017 | } |
| 6018 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 6019 | void WebContentsImpl::OnPepperInstanceDeleted(RenderFrameHostImpl* source, |
| 6020 | int32_t pp_instance) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6021 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnPepperInstanceDeleted", |
| 6022 | "render_frame_host", |
| 6023 | base::trace_event::ToTracedValue(source)); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6024 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6025 | observer->PepperInstanceDeleted(); |
| 6026 | }); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 6027 | pepper_playback_observer_->PepperInstanceDeleted(source, pp_instance); |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 6028 | } |
| 6029 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 6030 | void WebContentsImpl::OnPepperPluginHung(RenderFrameHostImpl* source, |
| 6031 | int plugin_child_id, |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 6032 | const base::FilePath& path, |
| 6033 | bool is_hung) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6034 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnPepperPluginHung", |
| 6035 | "render_frame_host", |
| 6036 | base::trace_event::ToTracedValue(source)); |
Steven Holte | 9592222 | 2018-09-14 20:06:23 | [diff] [blame] | 6037 | UMA_HISTOGRAM_COUNTS_1M("Pepper.PluginHung", 1); |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 6038 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6039 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6040 | observer->PluginHungStatusChanged(plugin_child_id, path, is_hung); |
| 6041 | }); |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 6042 | } |
| 6043 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 6044 | void WebContentsImpl::OnPepperStartsPlayback(RenderFrameHostImpl* source, |
| 6045 | int32_t pp_instance) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6046 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnPepperStartsPlayback", |
| 6047 | "render_frame_host", |
| 6048 | base::trace_event::ToTracedValue(source)); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 6049 | pepper_playback_observer_->PepperStartsPlayback(source, pp_instance); |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 6050 | } |
| 6051 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 6052 | void WebContentsImpl::OnPepperStopsPlayback(RenderFrameHostImpl* source, |
| 6053 | int32_t pp_instance) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6054 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnPepperStopsPlayback", |
| 6055 | "render_frame_host", |
| 6056 | base::trace_event::ToTracedValue(source)); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 6057 | pepper_playback_observer_->PepperStopsPlayback(source, pp_instance); |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 6058 | } |
| 6059 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 6060 | void WebContentsImpl::OnPluginCrashed(RenderFrameHostImpl* source, |
| 6061 | const base::FilePath& plugin_path, |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 6062 | base::ProcessId plugin_pid) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6063 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnPluginCrashed", |
| 6064 | "render_frame_host", |
| 6065 | base::trace_event::ToTracedValue(source)); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 6066 | // TODO(nick): Eliminate the |plugin_pid| parameter, which can't be trusted, |
Gyuyoung Kim | 26c7bc9 | 2020-04-29 00:53:00 | [diff] [blame] | 6067 | // and is only used by WebTestControlHost. |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6068 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6069 | observer->PluginCrashed(plugin_path, plugin_pid); |
| 6070 | }); |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 6071 | } |
| 6072 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 6073 | #endif // BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | 19be7a6 | 2012-10-01 23:03:37 | [diff] [blame] | 6074 | |
Miyoung Shin | 5709ab0 | 2020-02-19 06:50:41 | [diff] [blame] | 6075 | void WebContentsImpl::UpdateFaviconURL( |
| 6076 | RenderFrameHost* source, |
| 6077 | std::vector<blink::mojom::FaviconURLPtr> candidates) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6078 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::UpdateFaviconURL", |
| 6079 | "render_frame_host", |
| 6080 | base::trace_event::ToTracedValue(source)); |
lukasza | 178ff09 | 2017-06-07 23:39:50 | [diff] [blame] | 6081 | // Ignore favicons for non-main frame. |
| 6082 | if (source->GetParent()) { |
| 6083 | NOTREACHED(); |
| 6084 | return; |
| 6085 | } |
| 6086 | |
pkotwicz | f9bc2059 | 2015-04-21 18:57:06 | [diff] [blame] | 6087 | // We get updated favicon URLs after the page stops loading. If a cross-site |
| 6088 | // navigation occurs while a page is still loading, the initial page |
| 6089 | // may stop loading and send us updated favicon URLs after the navigation |
| 6090 | // for the new page has committed. |
lukasza | 178ff09 | 2017-06-07 23:39:50 | [diff] [blame] | 6091 | if (!source->IsCurrent()) |
pkotwicz | f9bc2059 | 2015-04-21 18:57:06 | [diff] [blame] | 6092 | return; |
| 6093 | |
Miyoung Shin | 5709ab0 | 2020-02-19 06:50:41 | [diff] [blame] | 6094 | favicon_urls_ = std::move(candidates); |
Mounir Lamouri | 7b4a1f23 | 2019-12-23 16:32:10 | [diff] [blame] | 6095 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6096 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6097 | observer->DidUpdateFaviconURL(source, favicon_urls_); |
| 6098 | }); |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 6099 | } |
| 6100 | |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 6101 | void WebContentsImpl::SetIsOverlayContent(bool is_overlay_content) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6102 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::SetIsOverlayContent", |
| 6103 | "is_overlay_content", is_overlay_content); |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 6104 | is_overlay_content_ = is_overlay_content; |
| 6105 | } |
| 6106 | |
Albert J. Wong | fb64e14 | 2018-10-16 01:10:45 | [diff] [blame] | 6107 | void WebContentsImpl::DidFirstVisuallyNonEmptyPaint( |
| 6108 | RenderViewHostImpl* source) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6109 | OPTIONAL_TRACE_EVENT1("content", |
| 6110 | "WebContentsImpl::DidFirstVisuallyNonEmptyPaint", |
| 6111 | "render_view_host", source); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 6112 | // TODO(nick): When this is ported to FrameHostMsg_, we should only listen if |
| 6113 | // |source| is the main frame. |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6114 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6115 | observer->DidFirstVisuallyNonEmptyPaint(); |
| 6116 | }); |
Carlos Caballero | 1215f88 | 2019-10-29 15:58:43 | [diff] [blame] | 6117 | if (source->theme_color() != last_sent_theme_color_) { |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 6118 | // Theme color should have updated by now if there was one. |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6119 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6120 | observer->DidChangeThemeColor(); |
| 6121 | }); |
Carlos Caballero | 1215f88 | 2019-10-29 15:58:43 | [diff] [blame] | 6122 | last_sent_theme_color_ = source->theme_color(); |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 6123 | } |
Alan Cutter | d73a15d9 | 2020-08-21 07:12:45 | [diff] [blame] | 6124 | |
| 6125 | if (source->background_color() != last_sent_background_color_) { |
| 6126 | // Background color should have updated by now if there was one. |
| 6127 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6128 | observer->OnBackgroundColorChanged(); |
| 6129 | }); |
| 6130 | last_sent_background_color_ = source->background_color(); |
| 6131 | } |
[email protected] | 9f26807 | 2013-11-07 00:02:15 | [diff] [blame] | 6132 | } |
[email protected] | d9030b8 | 2013-07-19 08:26:06 | [diff] [blame] | 6133 | |
Kevin McNee | 068c3eb | 2020-04-03 18:24:19 | [diff] [blame] | 6134 | bool WebContentsImpl::IsPortal() { |
Adithya Srinivasan | 46b8a79 | 2019-02-01 14:47:23 | [diff] [blame] | 6135 | return portal(); |
| 6136 | } |
| 6137 | |
Kevin McNee | 94ea52f5 | 2020-06-23 17:42:06 | [diff] [blame] | 6138 | WebContentsImpl* WebContentsImpl::GetPortalHostWebContents() { |
| 6139 | return portal() ? portal()->GetPortalHostContents() : nullptr; |
| 6140 | } |
| 6141 | |
[email protected] | 17e286e | 2013-03-01 23:29:39 | [diff] [blame] | 6142 | void WebContentsImpl::NotifyBeforeFormRepostWarningShow() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6143 | OPTIONAL_TRACE_EVENT0("content", |
| 6144 | "WebContentsImpl::NotifyBeforeFormRepostWarningShow"); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6145 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6146 | observer->BeforeFormRepostWarningShow(); |
| 6147 | }); |
[email protected] | 17e286e | 2013-03-01 23:29:39 | [diff] [blame] | 6148 | } |
| 6149 | |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 6150 | void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6151 | OPTIONAL_TRACE_EVENT0( |
| 6152 | "content", "WebContentsImpl::ActivateAndShowRepostFormWarningDialog"); |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 6153 | Activate(); |
| 6154 | if (delegate_) |
| 6155 | delegate_->ShowRepostFormWarningDialog(this); |
| 6156 | } |
| 6157 | |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 6158 | bool WebContentsImpl::HasAccessedInitialDocument() { |
| 6159 | return has_accessed_initial_document_; |
| 6160 | } |
| 6161 | |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 6162 | void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 6163 | const base::string16& title) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6164 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::UpdateTitleForEntry", |
| 6165 | "title", base::trace_event::ValueToString(title)); |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 6166 | base::string16 final_title; |
Avi Drissman | 9300221 | 2017-09-27 03:20:52 | [diff] [blame] | 6167 | base::TrimWhitespace(title, base::TRIM_ALL, &final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6168 | |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 6169 | // If a page is created via window.open and never navigated, |
| 6170 | // there will be no navigation entry. In this situation, |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 6171 | // |page_title_when_no_navigation_entry_| will be used for page title. |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 6172 | if (entry) { |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 6173 | if (final_title == entry->GetTitle()) |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 6174 | return; // Nothing changed, don't bother. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6175 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 6176 | entry->SetTitle(final_title); |
Avi Drissman | 9300221 | 2017-09-27 03:20:52 | [diff] [blame] | 6177 | |
| 6178 | // The title for display may differ from the title just set; grab it. |
| 6179 | final_title = entry->GetTitleForDisplay(); |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 6180 | } else { |
| 6181 | if (page_title_when_no_navigation_entry_ == final_title) |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 6182 | return; // Nothing changed, don't bother. |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 6183 | |
| 6184 | page_title_when_no_navigation_entry_ = final_title; |
| 6185 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6186 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6187 | // Lastly, set the title for the view. |
[email protected] | 790e2fd | 2011-09-21 20:28:23 | [diff] [blame] | 6188 | view_->SetPageTitle(final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6189 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6190 | observers_.ForEachObserver( |
| 6191 | [&](WebContentsObserver* observer) { observer->TitleWasSet(entry); }); |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 6192 | // Broadcast notifications when the UI should be updated. |
| 6193 | if (entry == controller_.GetEntryAtOffset(0)) |
| 6194 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6195 | } |
| 6196 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 6197 | void WebContentsImpl::SendChangeLoadProgress() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6198 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::SendChangeLoadProgress", |
| 6199 | "load_progress", frame_tree_.load_progress()); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 6200 | loading_last_progress_update_ = base::TimeTicks::Now(); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6201 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6202 | observer->LoadProgressChanged(frame_tree_.load_progress()); |
| 6203 | }); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 6204 | } |
| 6205 | |
| 6206 | void WebContentsImpl::ResetLoadProgressState() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6207 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::ResetLoadProgressState"); |
fdegans | 1d1635516 | 2015-03-26 11:58:34 | [diff] [blame] | 6208 | frame_tree_.ResetLoadProgress(); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 6209 | loading_weak_factory_.InvalidateWeakPtrs(); |
| 6210 | loading_last_progress_update_ = base::TimeTicks(); |
| 6211 | } |
| 6212 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 6213 | // Notifies the RenderWidgetHost instance about the fact that the page is |
| 6214 | // loading, or done loading. |
| 6215 | void WebContentsImpl::LoadingStateChanged(bool to_different_document, |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 6216 | LoadNotificationDetails* details) { |
Nate Chapin | 22ea659 | 2019-03-05 22:29:02 | [diff] [blame] | 6217 | if (is_being_destroyed_) |
| 6218 | return; |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 6219 | |
| 6220 | bool is_loading = IsLoading(); |
| 6221 | |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6222 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::LoadingStateChanged", |
| 6223 | "is_loading", is_loading); |
| 6224 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 6225 | if (!is_loading) { |
| 6226 | load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, |
| 6227 | base::string16()); |
| 6228 | load_state_host_.clear(); |
| 6229 | upload_size_ = 0; |
| 6230 | upload_position_ = 0; |
| 6231 | } |
| 6232 | |
| 6233 | GetRenderManager()->SetIsLoading(is_loading); |
| 6234 | |
| 6235 | waiting_for_response_ = is_loading; |
| 6236 | is_load_to_different_document_ = to_different_document; |
| 6237 | |
| 6238 | if (delegate_) |
| 6239 | delegate_->LoadingStateChanged(this, to_different_document); |
| 6240 | NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD); |
| 6241 | |
| 6242 | std::string url = (details ? details->url.possibly_invalid_spec() : "NULL"); |
| 6243 | if (is_loading) { |
| 6244 | TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading", |
| 6245 | this, "URL", url, "Main FrameTreeNode id", |
| 6246 | GetFrameTree()->root()->frame_tree_node_id()); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6247 | observers_.ForEachObserver( |
| 6248 | [&](WebContentsObserver* observer) { observer->DidStartLoading(); }); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 6249 | } else { |
| 6250 | TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading", |
| 6251 | this, "URL", url); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6252 | observers_.ForEachObserver( |
| 6253 | [&](WebContentsObserver* observer) { observer->DidStopLoading(); }); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 6254 | } |
| 6255 | |
| 6256 | // TODO(avi): Remove. http://crbug.com/170921 |
| 6257 | int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP; |
| 6258 | NotificationDetails det = NotificationService::NoDetails(); |
| 6259 | if (details) |
| 6260 | det = Details<LoadNotificationDetails>(details); |
| 6261 | NotificationService::current()->Notify( |
| 6262 | type, Source<NavigationController>(&controller_), det); |
| 6263 | } |
| 6264 | |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 6265 | void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_view, |
| 6266 | RenderViewHost* new_view) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6267 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::NotifyViewSwapped", |
| 6268 | "old_view", old_view, "new_view", new_view); |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 6269 | DCHECK_NE(old_view, new_view); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6270 | // After sending out a swap notification, we need to send a disconnect |
| 6271 | // notification so that clients that pick up a pointer to |this| can NULL the |
| 6272 | // pointer. See Bug 1230284. |
| 6273 | notify_disconnection_ = true; |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6274 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6275 | observer->RenderViewHostChanged(old_view, new_view); |
| 6276 | }); |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 6277 | view_->RenderViewHostChanged(old_view, new_view); |
Jinsuk Kim | dc5284c2 | 2018-07-11 02:22:06 | [diff] [blame] | 6278 | |
Lucas Furukawa Gadani | f9ea4fc | 2018-08-03 23:57:13 | [diff] [blame] | 6279 | // If this is an inner WebContents that has swapped views, we need to reattach |
| 6280 | // it to its outer WebContents. |
| 6281 | if (node_.outer_web_contents()) |
| 6282 | ReattachToOuterWebContentsFrame(); |
| 6283 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 6284 | // Ensure that the associated embedder gets cleared after a RenderViewHost |
| 6285 | // gets swapped, so we don't reuse the same embedder next time a |
| 6286 | // RenderViewHost is attached to this WebContents. |
| 6287 | RemoveBrowserPluginEmbedder(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6288 | } |
| 6289 | |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 6290 | void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_frame, |
| 6291 | RenderFrameHost* new_frame, |
Jinsuk Kim | 895b2c5 | 2018-07-03 06:49:16 | [diff] [blame] | 6292 | bool is_main_frame) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6293 | TRACE_EVENT2("content", "WebContentsImpl::NotifyFrameSwapped", "old_frame", |
| 6294 | base::trace_event::ToTracedValue(old_frame), "new_frame", |
| 6295 | base::trace_event::ToTracedValue(new_frame)); |
Bo Liu | 168c864 | 2017-08-28 18:26:02 | [diff] [blame] | 6296 | #if defined(OS_ANDROID) |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 6297 | // Copy importance from |old_frame| if |new_frame| is a main frame. |
| 6298 | if (old_frame && !new_frame->GetParent()) { |
| 6299 | RenderWidgetHostImpl* old_widget = |
| 6300 | static_cast<RenderFrameHostImpl*>(old_frame)->GetRenderWidgetHost(); |
| 6301 | RenderWidgetHostImpl* new_widget = |
| 6302 | static_cast<RenderFrameHostImpl*>(new_frame)->GetRenderWidgetHost(); |
| 6303 | new_widget->SetImportance(old_widget->importance()); |
Bo Liu | 7c6779e9 | 2017-08-16 02:02:28 | [diff] [blame] | 6304 | } |
Bo Liu | 168c864 | 2017-08-28 18:26:02 | [diff] [blame] | 6305 | #endif |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6306 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6307 | observer->RenderFrameHostChanged(old_frame, new_frame); |
| 6308 | }); |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 6309 | } |
| 6310 | |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 6311 | // TODO(avi): Remove this entire function because this notification is already |
| 6312 | // covered by two observer functions. http://crbug.com/170921 |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 6313 | void WebContentsImpl::NotifyDisconnected() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6314 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::NotifyDisconnected"); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6315 | if (!notify_disconnection_) |
| 6316 | return; |
| 6317 | |
| 6318 | notify_disconnection_ = false; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 6319 | NotificationService::current()->Notify( |
| 6320 | NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 6321 | Source<WebContents>(this), |
| 6322 | NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6323 | } |
| 6324 | |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 6325 | void WebContentsImpl::NotifyNavigationEntryCommitted( |
| 6326 | const LoadCommittedDetails& load_details) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6327 | OPTIONAL_TRACE_EVENT0("content", |
| 6328 | "WebContentsImpl::NotifyNavigationEntryCommitted"); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6329 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6330 | observer->NavigationEntryCommitted(load_details); |
| 6331 | }); |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 6332 | } |
| 6333 | |
Sam McNally | 5c087a3 | 2017-08-25 01:46:14 | [diff] [blame] | 6334 | void WebContentsImpl::NotifyNavigationEntryChanged( |
| 6335 | const EntryChangedDetails& change_details) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6336 | OPTIONAL_TRACE_EVENT0("content", |
| 6337 | "WebContentsImpl::NotifyNavigationEntryChanged"); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6338 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6339 | observer->NavigationEntryChanged(change_details); |
| 6340 | }); |
Sam McNally | 5c087a3 | 2017-08-25 01:46:14 | [diff] [blame] | 6341 | } |
| 6342 | |
| 6343 | void WebContentsImpl::NotifyNavigationListPruned( |
| 6344 | const PrunedDetails& pruned_details) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6345 | OPTIONAL_TRACE_EVENT0("content", |
| 6346 | "WebContentsImpl::NotifyNavigationListPruned"); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6347 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6348 | observer->NavigationListPruned(pruned_details); |
| 6349 | }); |
Sam McNally | 5c087a3 | 2017-08-25 01:46:14 | [diff] [blame] | 6350 | } |
| 6351 | |
Christian Dullweber | 1af31e6 | 2018-02-22 11:49:48 | [diff] [blame] | 6352 | void WebContentsImpl::NotifyNavigationEntriesDeleted() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6353 | OPTIONAL_TRACE_EVENT0("content", |
| 6354 | "WebContentsImpl::NotifyNavigationEntriesDeleted"); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6355 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6356 | observer->NavigationEntriesDeleted(); |
| 6357 | }); |
Christian Dullweber | 1af31e6 | 2018-02-22 11:49:48 | [diff] [blame] | 6358 | } |
| 6359 | |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 6360 | void WebContentsImpl::OnAssociatedInterfaceRequest( |
| 6361 | RenderFrameHost* render_frame_host, |
| 6362 | const std::string& interface_name, |
| 6363 | mojo::ScopedInterfaceEndpointHandle handle) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6364 | OPTIONAL_TRACE_EVENT2( |
| 6365 | "content", "WebContentsImpl::OnAssociatedInterfaceRequest", |
| 6366 | "render_frame_host", base::trace_event::ToTracedValue(render_frame_host), |
| 6367 | "interface_name", interface_name); |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 6368 | auto it = receiver_sets_.find(interface_name); |
| 6369 | if (it != receiver_sets_.end()) |
| 6370 | it->second->OnReceiverForFrame(render_frame_host, std::move(handle)); |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 6371 | } |
| 6372 | |
Ben Goodger | 9e24929e | 2017-07-21 03:13:40 | [diff] [blame] | 6373 | void WebContentsImpl::OnInterfaceRequest( |
| 6374 | RenderFrameHost* render_frame_host, |
| 6375 | const std::string& interface_name, |
| 6376 | mojo::ScopedMessagePipeHandle* interface_pipe) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6377 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::OnInterfaceRequest", |
| 6378 | "render_frame_host", |
| 6379 | base::trace_event::ToTracedValue(render_frame_host), |
| 6380 | "interface_name", interface_name); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6381 | for (auto& observer : observers_.observer_list()) { |
Ben Goodger | 9e24929e | 2017-07-21 03:13:40 | [diff] [blame] | 6382 | observer.OnInterfaceRequestFromFrame(render_frame_host, interface_name, |
| 6383 | interface_pipe); |
| 6384 | if (!interface_pipe->is_valid()) |
| 6385 | break; |
| 6386 | } |
| 6387 | } |
| 6388 | |
Varun Khaneja | 5da9430 | 2019-06-25 04:48:10 | [diff] [blame] | 6389 | void WebContentsImpl::OnDidBlockNavigation( |
| 6390 | const GURL& blocked_url, |
| 6391 | const GURL& initiator_url, |
Abhijeet Kandalkar | de7348e | 2020-01-13 06:06:54 | [diff] [blame] | 6392 | blink::mojom::NavigationBlockedReason reason) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6393 | OPTIONAL_TRACE_EVENT1( |
| 6394 | "content", "WebContentsImpl::OnDidBlockNavigation", "details", |
| 6395 | base::trace_event::TracedValue::Build( |
| 6396 | {{"blocked_url", base::trace_event::ValueToString(blocked_url)}, |
| 6397 | {"initiator_url", base::trace_event::ValueToString(initiator_url)}, |
| 6398 | {"reason", base::trace_event::ValueToString(reason)}})); |
Nicolas Dossou-gbete | bcab247 | 2017-09-09 12:28:40 | [diff] [blame] | 6399 | if (delegate_) |
Varun Khaneja | 5da9430 | 2019-06-25 04:48:10 | [diff] [blame] | 6400 | delegate_->OnDidBlockNavigation(this, blocked_url, initiator_url, reason); |
Nicolas Dossou-gbete | bcab247 | 2017-09-09 12:28:40 | [diff] [blame] | 6401 | } |
| 6402 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 6403 | const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() { |
[email protected] | c31a8480 | 2014-04-03 15:55:49 | [diff] [blame] | 6404 | return GetLastCommittedURL(); |
| 6405 | } |
| 6406 | |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 6407 | void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6408 | TRACE_EVENT1("content", "WebContentsImpl::RenderFrameCreated", |
| 6409 | "render_frame_host", render_frame_host); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6410 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6411 | observer->RenderFrameCreated(render_frame_host); |
| 6412 | }); |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 6413 | UpdateAccessibilityModeOnFrame(render_frame_host); |
clamy | 91b7abf | 2016-03-24 15:17:45 | [diff] [blame] | 6414 | |
Becca Hughes | d11d650 | 2018-07-31 17:01:28 | [diff] [blame] | 6415 | if (display_cutout_host_impl_) |
| 6416 | display_cutout_host_impl_->RenderFrameCreated(render_frame_host); |
| 6417 | |
clamy | 91b7abf | 2016-03-24 15:17:45 | [diff] [blame] | 6418 | if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent()) |
| 6419 | return; |
| 6420 | |
| 6421 | NavigationEntry* entry = controller_.GetPendingEntry(); |
| 6422 | if (entry && entry->IsViewSourceMode()) { |
| 6423 | // Put the renderer in view source mode. |
Dave Tapuska | 3c05e1c | 2019-11-27 18:34:18 | [diff] [blame] | 6424 | static_cast<RenderFrameHostImpl*>(render_frame_host) |
| 6425 | ->GetAssociatedLocalFrame() |
| 6426 | ->EnableViewSourceMode(); |
clamy | 91b7abf | 2016-03-24 15:17:45 | [diff] [blame] | 6427 | } |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 6428 | } |
| 6429 | |
| 6430 | void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6431 | TRACE_EVENT1("content", "WebContentsImpl::RenderFrameDeleted", |
| 6432 | "render_frame_host", |
| 6433 | base::trace_event::ToTracedValue(render_frame_host)); |
yilkal | 172da77 | 2019-11-06 22:49:07 | [diff] [blame] | 6434 | if (IsBeingDestroyed() && !render_frame_host->GetParent() && |
| 6435 | first_navigation_completed_ && |
Hajime Hoshi | bbc509c | 2020-04-06 08:55:08 | [diff] [blame] | 6436 | !render_frame_host->IsInBackForwardCache()) { |
yilkal | 796e89e | 2019-10-02 23:58:28 | [diff] [blame] | 6437 | // Main frame has been deleted because WebContents is being destroyed. |
Rakina Zata Amni | 74627df | 2019-10-15 02:03:17 | [diff] [blame] | 6438 | // Note that we aren't recording this here when the main frame is in the |
| 6439 | // back-forward cache because that means we've actually already navigated |
| 6440 | // away from it (and we got to this point because the WebContents is |
yilkal | 172da77 | 2019-11-06 22:49:07 | [diff] [blame] | 6441 | // deleted), which means |max_loaded_frame_count_| is already overwritten. |
| 6442 | // The |max_loaded_frame_count_| value will instead be recorded from within |
| 6443 | // |WebContentsImpl::DidFinishNavigation()|. |
| 6444 | RecordMaxFrameCountUMA(max_loaded_frame_count_); |
yilkal | 796e89e | 2019-10-02 23:58:28 | [diff] [blame] | 6445 | } |
| 6446 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6447 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6448 | observer->RenderFrameDeleted(render_frame_host); |
| 6449 | }); |
zqzhang | 7b6f4f0 | 2016-12-07 22:10:22 | [diff] [blame] | 6450 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 6451 | pepper_playback_observer_->RenderFrameDeleted(render_frame_host); |
| 6452 | #endif |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 6453 | |
Becca Hughes | d11d650 | 2018-07-31 17:01:28 | [diff] [blame] | 6454 | if (display_cutout_host_impl_) |
| 6455 | display_cutout_host_impl_->RenderFrameDeleted(render_frame_host); |
| 6456 | |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 6457 | // Remove any fullscreen state that the frame has stored. |
| 6458 | FullscreenStateChanged(render_frame_host, false /* is_fullscreen */); |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 6459 | } |
| 6460 | |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 6461 | void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host, |
| 6462 | const ContextMenuParams& params) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6463 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::ShowContextMenu", |
| 6464 | "render_frame_host", |
| 6465 | base::trace_event::ToTracedValue(render_frame_host)); |
avi | e9fd872 | 2017-04-10 16:17:58 | [diff] [blame] | 6466 | // If a renderer fires off a second command to show a context menu before the |
| 6467 | // first context menu is closed, just ignore it. https://crbug.com/707534 |
ekaramad | f6750aa | 2017-06-06 18:29:42 | [diff] [blame] | 6468 | if (showing_context_menu_) |
avi | e9fd872 | 2017-04-10 16:17:58 | [diff] [blame] | 6469 | return; |
| 6470 | |
[email protected] | 077e704b | 2014-05-23 19:24:10 | [diff] [blame] | 6471 | ContextMenuParams context_menu_params(params); |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 6472 | // Allow WebContentsDelegates to handle the context menu operation first. |
Joel Klinghed | 0ea22ea | 2019-02-20 22:04:22 | [diff] [blame] | 6473 | if (delegate_ && |
| 6474 | delegate_->HandleContextMenu(render_frame_host, context_menu_params)) |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 6475 | return; |
| 6476 | |
[email protected] | 077e704b | 2014-05-23 19:24:10 | [diff] [blame] | 6477 | render_view_host_delegate_view_->ShowContextMenu(render_frame_host, |
| 6478 | context_menu_params); |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 6479 | } |
| 6480 | |
Avi Drissman | 4891b85 | 2018-09-25 18:12:58 | [diff] [blame] | 6481 | namespace { |
| 6482 | // Normalizes the line endings: \r\n -> \n, lone \r -> \n. |
| 6483 | base::string16 NormalizeLineBreaks(const base::string16& source) { |
| 6484 | static const base::NoDestructor<base::string16> kReturnNewline( |
| 6485 | base::ASCIIToUTF16("\r\n")); |
| 6486 | static const base::NoDestructor<base::string16> kReturn( |
| 6487 | base::ASCIIToUTF16("\r")); |
| 6488 | static const base::NoDestructor<base::string16> kNewline( |
| 6489 | base::ASCIIToUTF16("\n")); |
| 6490 | |
| 6491 | std::vector<base::StringPiece16> pieces; |
| 6492 | |
| 6493 | for (const auto& rn_line : base::SplitStringPieceUsingSubstr( |
| 6494 | source, *kReturnNewline, base::KEEP_WHITESPACE, |
| 6495 | base::SPLIT_WANT_ALL)) { |
| 6496 | auto r_lines = base::SplitStringPieceUsingSubstr( |
| 6497 | rn_line, *kReturn, base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 6498 | std::move(std::begin(r_lines), std::end(r_lines), |
| 6499 | std::back_inserter(pieces)); |
| 6500 | } |
| 6501 | |
| 6502 | return base::JoinString(pieces, *kNewline); |
| 6503 | } |
| 6504 | } // namespace |
| 6505 | |
Dave Tapuska | cdf545cc | 2020-01-23 18:38:52 | [diff] [blame] | 6506 | void WebContentsImpl::RunJavaScriptDialog( |
| 6507 | RenderFrameHost* render_frame_host, |
| 6508 | const base::string16& message, |
| 6509 | const base::string16& default_prompt, |
| 6510 | JavaScriptDialogType dialog_type, |
| 6511 | JavaScriptDialogCallback response_callback) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6512 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::RunJavaScriptDialog", |
| 6513 | "render_frame_host", |
| 6514 | base::trace_event::ToTracedValue(render_frame_host)); |
Avi Drissman | 2ccbb40 | 2018-03-20 21:11:36 | [diff] [blame] | 6515 | // Ensure that if showing a dialog is the first thing that a page does, that |
| 6516 | // the contents of the previous page aren't shown behind it. This is required |
| 6517 | // because showing a dialog freezes the renderer, so no frames will be coming |
| 6518 | // from it. https://crbug.com/823353 |
| 6519 | auto* render_widget_host_impl = |
| 6520 | static_cast<RenderFrameHostImpl*>(render_frame_host) |
| 6521 | ->GetRenderWidgetHost(); |
| 6522 | if (render_widget_host_impl) |
| 6523 | render_widget_host_impl->ForceFirstFrameAfterNavigationTimeout(); |
| 6524 | |
avi | 0720b02e | 2017-06-13 03:22:13 | [diff] [blame] | 6525 | // Running a dialog causes an exit to webpage-initiated fullscreen. |
| 6526 | // http://crbug.com/728276 |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 6527 | base::ScopedClosureRunner fullscreen_block = ForSecurityDropFullscreen(); |
avi | 0720b02e | 2017-06-13 03:22:13 | [diff] [blame] | 6528 | |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 6529 | auto callback = |
| 6530 | base::BindOnce(&WebContentsImpl::OnDialogClosed, base::Unretained(this), |
| 6531 | render_frame_host->GetProcess()->GetID(), |
| 6532 | render_frame_host->GetRoutingID(), |
| 6533 | std::move(response_callback), std::move(fullscreen_block)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6534 | |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6535 | std::vector<protocol::PageHandler*> page_handlers = |
| 6536 | protocol::PageHandler::EnabledForWebContents(this); |
| 6537 | |
Pavel Feldman | fab3cb6 | 2017-10-05 01:02:01 | [diff] [blame] | 6538 | if (delegate_) |
| 6539 | dialog_manager_ = delegate_->GetJavaScriptDialogManager(this); |
| 6540 | |
Charlie Reis | 9607736 | 2019-07-04 00:34:04 | [diff] [blame] | 6541 | // While a JS message dialog is showing, defer commits in this WebContents. |
| 6542 | javascript_dialog_navigation_deferrer_ = |
| 6543 | std::make_unique<JavaScriptDialogNavigationDeferrer>(); |
| 6544 | |
Carlos IL | 07f282f | 2020-05-15 22:58:29 | [diff] [blame] | 6545 | // Suppress JavaScript dialogs when requested. |
| 6546 | bool should_suppress = delegate_ && delegate_->ShouldSuppressDialogs(this); |
Pavel Feldman | 1c587bc5 | 2018-04-04 21:16:05 | [diff] [blame] | 6547 | bool has_non_devtools_handlers = delegate_ && dialog_manager_; |
| 6548 | bool has_handlers = page_handlers.size() || has_non_devtools_handlers; |
Pavel Feldman | fab3cb6 | 2017-10-05 01:02:01 | [diff] [blame] | 6549 | bool suppress_this_message = should_suppress || !has_handlers; |
| 6550 | |
| 6551 | if (suppress_this_message) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6552 | std::move(callback).Run(true, false, base::string16()); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6553 | return; |
| 6554 | } |
| 6555 | |
| 6556 | scoped_refptr<CloseDialogCallbackWrapper> wrapper = |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6557 | new CloseDialogCallbackWrapper(std::move(callback)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6558 | |
| 6559 | is_showing_javascript_dialog_ = true; |
| 6560 | |
Avi Drissman | 4891b85 | 2018-09-25 18:12:58 | [diff] [blame] | 6561 | base::string16 normalized_message = NormalizeLineBreaks(message); |
| 6562 | |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6563 | for (auto* handler : page_handlers) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6564 | handler->DidRunJavaScriptDialog( |
Avi Drissman | 4891b85 | 2018-09-25 18:12:58 | [diff] [blame] | 6565 | render_frame_host->GetLastCommittedURL(), normalized_message, |
| 6566 | default_prompt, dialog_type, has_non_devtools_handlers, |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6567 | base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6568 | } |
| 6569 | |
| 6570 | if (dialog_manager_) { |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6571 | dialog_manager_->RunJavaScriptDialog( |
Avi Drissman | 4891b85 | 2018-09-25 18:12:58 | [diff] [blame] | 6572 | this, render_frame_host, dialog_type, normalized_message, |
| 6573 | default_prompt, |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6574 | base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false), |
| 6575 | &suppress_this_message); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6576 | } |
| 6577 | |
| 6578 | if (suppress_this_message) { |
| 6579 | // If we are suppressing messages, just reply as if the user immediately |
| 6580 | // pressed "Cancel", passing true to |dialog_was_suppressed|. |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6581 | wrapper->Run(true, false, base::string16()); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6582 | } |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6583 | } |
| 6584 | |
| 6585 | void WebContentsImpl::RunBeforeUnloadConfirm( |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 6586 | RenderFrameHost* render_frame_host, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6587 | bool is_reload, |
Dave Tapuska | cdf545cc | 2020-01-23 18:38:52 | [diff] [blame] | 6588 | JavaScriptDialogCallback response_callback) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6589 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::RunBeforeUnloadConfirm", |
| 6590 | "render_frame_host", |
| 6591 | base::trace_event::ToTracedValue(render_frame_host), |
| 6592 | "is_reload", is_reload); |
Avi Drissman | 2ccbb40 | 2018-03-20 21:11:36 | [diff] [blame] | 6593 | // Ensure that if showing a dialog is the first thing that a page does, that |
| 6594 | // the contents of the previous page aren't shown behind it. This is required |
| 6595 | // because showing a dialog freezes the renderer, so no frames will be coming |
| 6596 | // from it. https://crbug.com/823353 |
| 6597 | auto* render_widget_host_impl = |
| 6598 | static_cast<RenderFrameHostImpl*>(render_frame_host) |
| 6599 | ->GetRenderWidgetHost(); |
| 6600 | if (render_widget_host_impl) |
| 6601 | render_widget_host_impl->ForceFirstFrameAfterNavigationTimeout(); |
| 6602 | |
avi | 0720b02e | 2017-06-13 03:22:13 | [diff] [blame] | 6603 | // Running a dialog causes an exit to webpage-initiated fullscreen. |
| 6604 | // http://crbug.com/728276 |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 6605 | base::ScopedClosureRunner fullscreen_block = ForSecurityDropFullscreen(); |
avi | 0720b02e | 2017-06-13 03:22:13 | [diff] [blame] | 6606 | |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 6607 | RenderFrameHostImpl* rfhi = |
| 6608 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6609 | if (delegate_) |
| 6610 | delegate_->WillRunBeforeUnloadConfirm(); |
| 6611 | |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 6612 | auto callback = |
| 6613 | base::BindOnce(&WebContentsImpl::OnDialogClosed, base::Unretained(this), |
| 6614 | render_frame_host->GetProcess()->GetID(), |
| 6615 | render_frame_host->GetRoutingID(), |
| 6616 | std::move(response_callback), std::move(fullscreen_block)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6617 | |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6618 | std::vector<protocol::PageHandler*> page_handlers = |
| 6619 | protocol::PageHandler::EnabledForWebContents(this); |
| 6620 | |
Pavel Feldman | fab3cb6 | 2017-10-05 01:02:01 | [diff] [blame] | 6621 | if (delegate_) |
| 6622 | dialog_manager_ = delegate_->GetJavaScriptDialogManager(this); |
| 6623 | |
Charlie Reis | 9607736 | 2019-07-04 00:34:04 | [diff] [blame] | 6624 | // While a JS beforeunload dialog is showing, defer commits in this |
| 6625 | // WebContents. |
| 6626 | javascript_dialog_navigation_deferrer_ = |
| 6627 | std::make_unique<JavaScriptDialogNavigationDeferrer>(); |
| 6628 | |
Sreeja Kamishetty | f352e30 | 2020-06-10 13:21:24 | [diff] [blame] | 6629 | bool should_suppress = !rfhi->IsCurrent() || |
Tarun Bansal | c209b74 | 2019-12-24 06:53:25 | [diff] [blame] | 6630 | (delegate_ && delegate_->ShouldSuppressDialogs(this)); |
Pavel Feldman | 1c587bc5 | 2018-04-04 21:16:05 | [diff] [blame] | 6631 | bool has_non_devtools_handlers = delegate_ && dialog_manager_; |
| 6632 | bool has_handlers = page_handlers.size() || has_non_devtools_handlers; |
Pavel Feldman | fab3cb6 | 2017-10-05 01:02:01 | [diff] [blame] | 6633 | if (should_suppress || !has_handlers) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6634 | std::move(callback).Run(false, true, base::string16()); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6635 | return; |
| 6636 | } |
| 6637 | |
| 6638 | is_showing_before_unload_dialog_ = true; |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6639 | |
| 6640 | scoped_refptr<CloseDialogCallbackWrapper> wrapper = |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6641 | new CloseDialogCallbackWrapper(std::move(callback)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6642 | |
| 6643 | GURL frame_url = rfhi->GetLastCommittedURL(); |
| 6644 | for (auto* handler : page_handlers) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6645 | handler->DidRunBeforeUnloadConfirm( |
Pavel Feldman | 1c587bc5 | 2018-04-04 21:16:05 | [diff] [blame] | 6646 | frame_url, has_non_devtools_handlers, |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6647 | base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6648 | } |
| 6649 | |
| 6650 | if (dialog_manager_) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6651 | dialog_manager_->RunBeforeUnloadDialog( |
Avi Drissman | ff9ed75 | 2017-11-28 21:18:12 | [diff] [blame] | 6652 | this, render_frame_host, is_reload, |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6653 | base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6654 | } |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6655 | } |
| 6656 | |
Kent Tamura | c260c9a | 2018-09-14 09:10:56 | [diff] [blame] | 6657 | void WebContentsImpl::RunFileChooser( |
| 6658 | RenderFrameHost* render_frame_host, |
Kent Tamura | 3abb32d | 2020-07-02 00:23:01 | [diff] [blame] | 6659 | scoped_refptr<FileChooserImpl::FileSelectListenerImpl> listener, |
Kent Tamura | c260c9a | 2018-09-14 09:10:56 | [diff] [blame] | 6660 | const blink::mojom::FileChooserParams& params) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6661 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::RunFileChooser", |
| 6662 | "render_frame_host", |
| 6663 | base::trace_event::ToTracedValue(render_frame_host)); |
Avi Drissman | 3d41e771 | 2018-08-27 21:18:08 | [diff] [blame] | 6664 | // Any explicit focusing of another window while this WebContents is in |
| 6665 | // fullscreen can be used to confuse the user, so drop fullscreen. |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 6666 | base::ScopedClosureRunner fullscreen_block = ForSecurityDropFullscreen(); |
| 6667 | listener->SetFullscreenBlock(std::move(fullscreen_block)); |
Avi Drissman | 3d41e771 | 2018-08-27 21:18:08 | [diff] [blame] | 6668 | |
nasko | ada75b2 | 2016-06-11 16:09:46 | [diff] [blame] | 6669 | if (delegate_) |
Kent Tamura | 512a27e | 2018-10-04 00:49:32 | [diff] [blame] | 6670 | delegate_->RunFileChooser(render_frame_host, std::move(listener), params); |
| 6671 | else |
| 6672 | listener->FileSelectionCanceled(); |
nasko | ada75b2 | 2016-06-11 16:09:46 | [diff] [blame] | 6673 | } |
| 6674 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 6675 | WebContents* WebContentsImpl::GetAsWebContents() { |
| 6676 | return this; |
| 6677 | } |
| 6678 | |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 6679 | #if !defined(OS_ANDROID) |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 6680 | double WebContentsImpl::GetPendingPageZoomLevel() { |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 6681 | NavigationEntry* pending_entry = GetController().GetPendingEntry(); |
| 6682 | if (!pending_entry) |
| 6683 | return HostZoomMap::GetZoomLevel(this); |
| 6684 | |
| 6685 | GURL url = pending_entry->GetURL(); |
| 6686 | return HostZoomMap::GetForWebContents(this)->GetZoomLevelForHostAndScheme( |
| 6687 | url.scheme(), net::GetHostOrSpecFromURL(url)); |
| 6688 | } |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 6689 | #endif // !defined(OS_ANDROID) |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 6690 | |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 6691 | bool WebContentsImpl::HideDownloadUI() const { |
| 6692 | return is_overlay_content_; |
| 6693 | } |
| 6694 | |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 6695 | bool WebContentsImpl::HasPersistentVideo() const { |
| 6696 | return has_persistent_video_; |
| 6697 | } |
| 6698 | |
Ian Vollick | 5d5c37f | 2019-06-19 22:50:57 | [diff] [blame] | 6699 | bool WebContentsImpl::IsSpatialNavigationDisabled() const { |
| 6700 | return is_spatial_navigation_disabled_; |
| 6701 | } |
| 6702 | |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 6703 | RenderFrameHostImpl* WebContentsImpl::GetPendingMainFrame() { |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 6704 | return GetRenderManager()->speculative_frame_host(); |
Alex Moshchuk | 27caae8 | 2017-09-11 23:11:18 | [diff] [blame] | 6705 | } |
| 6706 | |
mlamouri | e52c1b54 | 2017-02-23 14:57:50 | [diff] [blame] | 6707 | bool WebContentsImpl::HasActiveEffectivelyFullscreenVideo() const { |
| 6708 | return media_web_contents_observer_->HasActiveEffectivelyFullscreenVideo(); |
| 6709 | } |
| 6710 | |
François Beaufort | ad6c523 | 2018-02-26 11:00:44 | [diff] [blame] | 6711 | bool WebContentsImpl::IsPictureInPictureAllowedForFullscreenVideo() const { |
| 6712 | return media_web_contents_observer_ |
| 6713 | ->IsPictureInPictureAllowedForFullscreenVideo(); |
| 6714 | } |
| 6715 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 6716 | bool WebContentsImpl::IsFocusedElementEditable() { |
| 6717 | RenderFrameHostImpl* frame = GetFocusedFrame(); |
| 6718 | return frame && frame->has_focused_editable_element(); |
| 6719 | } |
| 6720 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 6721 | bool WebContentsImpl::IsShowingContextMenu() { |
ekaramad | f6750aa | 2017-06-06 18:29:42 | [diff] [blame] | 6722 | return showing_context_menu_; |
| 6723 | } |
| 6724 | |
| 6725 | void WebContentsImpl::SetShowingContextMenu(bool showing) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6726 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::SetShowingContextMenu", |
| 6727 | "showing", showing); |
| 6728 | |
ekaramad | f6750aa | 2017-06-06 18:29:42 | [diff] [blame] | 6729 | DCHECK_NE(showing_context_menu_, showing); |
| 6730 | showing_context_menu_ = showing; |
| 6731 | |
| 6732 | if (auto* view = GetRenderWidgetHostView()) { |
| 6733 | // Notify the main frame's RWHV to run the platform-specific code, if any. |
| 6734 | static_cast<RenderWidgetHostViewBase*>(view)->SetShowingContextMenu( |
| 6735 | showing); |
| 6736 | } |
| 6737 | } |
| 6738 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 6739 | void WebContentsImpl::ClearFocusedElement() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6740 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::ClearFocusedElement"); |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 6741 | if (auto* frame = GetFocusedFrame()) |
| 6742 | frame->ClearFocusedElement(); |
| 6743 | } |
| 6744 | |
danakj | 77eb7e8 | 2020-01-09 19:38:46 | [diff] [blame] | 6745 | bool WebContentsImpl::IsNeverComposited() { |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 6746 | if (!delegate_) |
| 6747 | return false; |
danakj | 77eb7e8 | 2020-01-09 19:38:46 | [diff] [blame] | 6748 | return delegate_->IsNeverComposited(this); |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 6749 | } |
| 6750 | |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 6751 | RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() { |
| 6752 | return render_view_host_delegate_view_; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6753 | } |
| 6754 | |
Mario Sanchez Prada | 0bd8b8c | 2020-10-21 17:49:23 | [diff] [blame] | 6755 | const blink::RendererPreferences& WebContentsImpl::GetRendererPrefs() const { |
[email protected] | 840b151 | 2009-07-21 16:53:46 | [diff] [blame] | 6756 | return renderer_preferences_; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 6757 | } |
| 6758 | |
Lucas Furukawa Gadani | 2ec00c8 | 2018-12-14 15:53:16 | [diff] [blame] | 6759 | RenderFrameHostImpl* WebContentsImpl::GetOuterWebContentsFrame() { |
| 6760 | if (GetOuterDelegateFrameTreeNodeId() == |
| 6761 | FrameTreeNode::kFrameTreeNodeInvalidId) { |
| 6762 | return nullptr; |
| 6763 | } |
| 6764 | |
| 6765 | FrameTreeNode* outer_node = |
| 6766 | FrameTreeNode::GloballyFindByID(GetOuterDelegateFrameTreeNodeId()); |
| 6767 | // The outer node should be in the outer WebContents. |
| 6768 | DCHECK_EQ(outer_node->frame_tree(), GetOuterWebContents()->GetFrameTree()); |
Alexander Timin | 381e7e18 | 2020-04-28 19:04:03 | [diff] [blame] | 6769 | return outer_node->parent(); |
Lucas Furukawa Gadani | 2ec00c8 | 2018-12-14 15:53:16 | [diff] [blame] | 6770 | } |
| 6771 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 6772 | WebContentsImpl* WebContentsImpl::GetOuterWebContents() { |
Lucas Furukawa Gadani | 105de1e81 | 2018-05-31 19:38:39 | [diff] [blame] | 6773 | return node_.outer_web_contents(); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 6774 | } |
| 6775 | |
Lucas Furukawa Gadani | 2ec00c8 | 2018-12-14 15:53:16 | [diff] [blame] | 6776 | std::vector<WebContents*> WebContentsImpl::GetInnerWebContents() { |
| 6777 | std::vector<WebContents*> all_inner_contents; |
Lucas Furukawa Gadani | 2ec00c8 | 2018-12-14 15:53:16 | [diff] [blame] | 6778 | const auto& inner_contents = node_.GetInnerWebContents(); |
| 6779 | all_inner_contents.insert(all_inner_contents.end(), inner_contents.begin(), |
| 6780 | inner_contents.end()); |
| 6781 | return all_inner_contents; |
| 6782 | } |
| 6783 | |
Jeremy Roman | 7e70bf9 | 2020-01-07 23:23:58 | [diff] [blame] | 6784 | WebContentsImpl* WebContentsImpl::GetResponsibleWebContents() { |
| 6785 | // Iteratively ask delegates which other contents is responsible until a fixed |
| 6786 | // point is found. |
| 6787 | WebContentsImpl* contents = this; |
| 6788 | while (WebContentsDelegate* delegate = contents->GetDelegate()) { |
| 6789 | auto* responsible_contents = static_cast<WebContentsImpl*>( |
| 6790 | delegate->GetResponsibleWebContents(contents)); |
| 6791 | if (responsible_contents == contents) |
| 6792 | break; |
| 6793 | contents = responsible_contents; |
| 6794 | } |
| 6795 | return contents; |
| 6796 | } |
| 6797 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 6798 | WebContentsImpl* WebContentsImpl::GetFocusedWebContents() { |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 6799 | return GetOutermostWebContents()->node_.focused_web_contents(); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 6800 | } |
| 6801 | |
Lukasz Anforowicz | 2cd231bf | 2020-10-02 19:13:20 | [diff] [blame] | 6802 | void WebContentsImpl::SetFocusToLocationBar() { |
| 6803 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::SetFocusToLocationBar"); |
| 6804 | if (delegate_) |
| 6805 | delegate_->SetFocusToLocationBar(); |
| 6806 | } |
| 6807 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 6808 | bool WebContentsImpl::ContainsOrIsFocusedWebContents() { |
| 6809 | for (WebContentsImpl* focused_contents = GetFocusedWebContents(); |
| 6810 | focused_contents; |
| 6811 | focused_contents = focused_contents->GetOuterWebContents()) { |
| 6812 | if (focused_contents == this) |
| 6813 | return true; |
| 6814 | } |
| 6815 | |
| 6816 | return false; |
| 6817 | } |
| 6818 | |
W. James MacLean | 9437b5bf | 2019-12-06 17:33:44 | [diff] [blame] | 6819 | void WebContentsImpl::RemoveBrowserPluginEmbedder() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6820 | OPTIONAL_TRACE_EVENT0("content", |
| 6821 | "WebContentsImpl::RemoveBrowserPluginEmbedder"); |
W. James MacLean | 9437b5bf | 2019-12-06 17:33:44 | [diff] [blame] | 6822 | browser_plugin_embedder_.reset(); |
| 6823 | } |
| 6824 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 6825 | WebContentsImpl* WebContentsImpl::GetOutermostWebContents() { |
| 6826 | WebContentsImpl* root = this; |
| 6827 | while (root->GetOuterWebContents()) |
| 6828 | root = root->GetOuterWebContents(); |
| 6829 | return root; |
| 6830 | } |
| 6831 | |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 6832 | void WebContentsImpl::FocusOuterAttachmentFrameChain() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6833 | OPTIONAL_TRACE_EVENT0("content", |
| 6834 | "WebContentsImpl::FocusOuterAttachmentFrameChain"); |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 6835 | WebContentsImpl* outer_contents = GetOuterWebContents(); |
| 6836 | if (!outer_contents) |
| 6837 | return; |
| 6838 | |
| 6839 | FrameTreeNode* outer_node = |
| 6840 | FrameTreeNode::GloballyFindByID(GetOuterDelegateFrameTreeNodeId()); |
| 6841 | outer_contents->frame_tree_.SetFocusedFrame(outer_node, nullptr); |
| 6842 | |
| 6843 | // For a browser initiated focus change, let embedding renderer know of the |
| 6844 | // change. Otherwise, if the currently focused element is just across a |
| 6845 | // process boundary in focus order, it will not be possible to move across |
| 6846 | // that boundary. This is because the target element will already be focused |
| 6847 | // (that renderer was not notified) and drop the event. |
| 6848 | if (GetRenderManager()->GetProxyToOuterDelegate()) |
| 6849 | GetRenderManager()->GetProxyToOuterDelegate()->SetFocusedFrame(); |
| 6850 | |
| 6851 | outer_contents->FocusOuterAttachmentFrameChain(); |
| 6852 | } |
| 6853 | |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 6854 | void WebContentsImpl::InnerWebContentsCreated(WebContents* inner_web_contents) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6855 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::InnerWebContentsCreated"); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6856 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6857 | observer->InnerWebContentsCreated(inner_web_contents); |
| 6858 | }); |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 6859 | } |
| 6860 | |
Jeremy Roman | 03ce13ce | 2020-05-29 22:16:57 | [diff] [blame] | 6861 | void WebContentsImpl::InnerWebContentsAttached( |
| 6862 | WebContents* inner_web_contents) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6863 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::InnerWebContentsDetached"); |
Jeremy Roman | 03ce13ce | 2020-05-29 22:16:57 | [diff] [blame] | 6864 | if (inner_web_contents->IsCurrentlyAudible()) |
| 6865 | OnAudioStateChanged(); |
| 6866 | } |
| 6867 | |
| 6868 | void WebContentsImpl::InnerWebContentsDetached( |
| 6869 | WebContents* inner_web_contents) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6870 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::InnerWebContentsCreated"); |
Jeremy Roman | 03ce13ce | 2020-05-29 22:16:57 | [diff] [blame] | 6871 | if (!is_being_destroyed_) |
| 6872 | OnAudioStateChanged(); |
| 6873 | } |
| 6874 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 6875 | void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6876 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::RenderViewCreated", |
| 6877 | "render_view_host", render_view_host); |
[email protected] | 86f98a2 | 2013-03-20 14:35:00 | [diff] [blame] | 6878 | if (delegate_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 6879 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 6880 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 6881 | NotificationService::current()->Notify( |
| 6882 | NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
| 6883 | Source<WebContents>(this), |
| 6884 | Details<RenderViewHost>(render_view_host)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6885 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6886 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6887 | observer->RenderViewCreated(render_view_host); |
| 6888 | }); |
Joel Einbinder | 848001c | 2017-09-19 21:39:31 | [diff] [blame] | 6889 | if (delegate_) |
| 6890 | RenderFrameDevToolsAgentHost::WebContentsCreated(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6891 | } |
| 6892 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 6893 | void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6894 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::RenderViewReady", |
| 6895 | "render_view_host", rvh); |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 6896 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6897 | // Don't notify the world, since this came from a renderer in the |
| 6898 | // background. |
| 6899 | return; |
| 6900 | } |
| 6901 | |
dmazzoni | 6211145 | 2017-04-28 23:46:55 | [diff] [blame] | 6902 | RenderWidgetHostViewBase* rwhv = |
| 6903 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 6904 | if (rwhv) |
| 6905 | rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID()); |
| 6906 | |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 6907 | notify_disconnection_ = true; |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 6908 | |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 6909 | bool was_crashed = IsCrashed(); |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 6910 | SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 6911 | |
| 6912 | // Restore the focus to the tab (otherwise the focus will be on the top |
| 6913 | // window). |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 6914 | if (was_crashed && !FocusLocationBarByDefault() && |
| 6915 | (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { |
[email protected] | f3615f0 | 2013-02-26 06:09:06 | [diff] [blame] | 6916 | view_->Focus(); |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 6917 | } |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 6918 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6919 | observers_.ForEachObserver( |
| 6920 | [&](WebContentsObserver* observer) { observer->RenderViewReady(); }); |
Jinsuk Kim | 895b2c5 | 2018-07-03 06:49:16 | [diff] [blame] | 6921 | view_->RenderViewReady(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6922 | } |
| 6923 | |
[email protected] | ec6a7eb | 2013-04-22 17:34:22 | [diff] [blame] | 6924 | void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh, |
| 6925 | base::TerminationStatus status, |
| 6926 | int error_code) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6927 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::RenderViewTerminated", |
| 6928 | "render_view_host", rvh, "status", |
| 6929 | static_cast<int>(status)); |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 6930 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6931 | // The pending page's RenderViewHost is gone. |
| 6932 | return; |
| 6933 | } |
[email protected] | 2fcdcc3 | 2014-03-05 02:14:07 | [diff] [blame] | 6934 | // Ensure fullscreen mode is exited in the |delegate_| since a crashed |
| 6935 | // renderer may not have made a clean exit. |
Avi Drissman | 97aef04 | 2020-06-30 21:04:48 | [diff] [blame] | 6936 | if (IsFullscreen()) |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 6937 | ExitFullscreenMode(false); |
[email protected] | 2fcdcc3 | 2014-03-05 02:14:07 | [diff] [blame] | 6938 | |
Jennifer Apacible | b4b972a | 2018-06-07 04:41:02 | [diff] [blame] | 6939 | // Ensure any video in Picture-in-Picture is exited in the |delegate_| since |
| 6940 | // a crashed renderer may not have made a clean exit. |
| 6941 | if (HasPictureInPictureVideo()) |
| 6942 | ExitPictureInPicture(); |
| 6943 | |
[email protected] | 698191dc | 2014-02-25 01:06:13 | [diff] [blame] | 6944 | // Cancel any visible dialogs so they are not left dangling over the sad tab. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 6945 | CancelActiveAndPendingDialogs(); |
[email protected] | 698191dc | 2014-02-25 01:06:13 | [diff] [blame] | 6946 | |
dalecurtis | 3d1e130 | 2017-02-20 22:33:25 | [diff] [blame] | 6947 | audio_stream_monitor_.RenderProcessGone(rvh->GetProcess()->GetID()); |
| 6948 | |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 6949 | // Reset the loading progress. TODO(avi): What does it mean to have a |
| 6950 | // "renderer crash" when there is more than one renderer process serving a |
| 6951 | // webpage? Once this function is called at a more granular frame level, we |
| 6952 | // probably will need to more granularly reset the state here. |
| 6953 | ResetLoadProgressState(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 6954 | NotifyDisconnected(); |
| 6955 | SetIsCrashed(status, error_code); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 6956 | |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6957 | TRACE_EVENT0("content", |
| 6958 | "Dispatching WebContentsObserver::RenderViewTerminated"); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6959 | // Some observers might destroy WebContents in RenderViewTerminated. |
| 6960 | base::WeakPtr<WebContentsImpl> weak_ptr = weak_factory_.GetWeakPtr(); |
| 6961 | auto crashed_status = GetCrashedStatus(); |
| 6962 | for (auto& observer : observers_.observer_list()) { |
| 6963 | observer.RenderProcessGone(crashed_status); |
| 6964 | if (!weak_ptr) |
| 6965 | return; |
| 6966 | } |
| 6967 | |
| 6968 | // |this| might have been deleted. Do not add code here. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6969 | } |
| 6970 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 6971 | void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6972 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::RenderViewDeleted", |
| 6973 | "render_view_host", rvh); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 6974 | observers_.ForEachObserver( |
| 6975 | [&](WebContentsObserver* observer) { observer->RenderViewDeleted(rvh); }); |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 6976 | } |
| 6977 | |
Lukasz Anforowicz | fd70714 | 2018-02-07 19:46:13 | [diff] [blame] | 6978 | void WebContentsImpl::ClearTargetURL() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6979 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::ClearTargetURL"); |
Mario Sanchez Prada | dffbe66e | 2020-09-07 12:01:08 | [diff] [blame] | 6980 | frame_that_set_last_target_url_ = nullptr; |
Lukasz Anforowicz | fd70714 | 2018-02-07 19:46:13 | [diff] [blame] | 6981 | if (delegate_) |
| 6982 | delegate_->UpdateTargetURL(this, GURL()); |
| 6983 | } |
| 6984 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 6985 | void WebContentsImpl::Close(RenderViewHost* rvh) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 6986 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::Close", "render_view_host", |
| 6987 | rvh); |
Avi Drissman | 7c57be7 | 2020-07-29 20:09:46 | [diff] [blame] | 6988 | #if defined(OS_MAC) |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 6989 | // The UI may be in an event-tracking loop, such as between the |
| 6990 | // mouse-down and mouse-up in text selection or a button click. |
| 6991 | // Defer the close until after tracking is complete, so that we |
| 6992 | // don't free objects out from under the UI. |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 6993 | // TODO(shess): This could get more fine-grained. For instance, |
| 6994 | // closing a tab in another window while selecting text in the |
| 6995 | // current window's Omnibox should be just fine. |
Christopher Cameron | 9ae31e0d | 2019-03-01 20:01:19 | [diff] [blame] | 6996 | if (view_->CloseTabAfterEventTrackingIfNeeded()) |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 6997 | return; |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 6998 | #endif |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 6999 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7000 | // Ignore this if it comes from a RenderViewHost that we aren't showing. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 7001 | if (delegate_ && rvh == GetRenderViewHost()) |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 7002 | delegate_->CloseContents(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7003 | } |
| 7004 | |
Avi Drissman | 014dec7 | 2018-06-07 02:34:01 | [diff] [blame] | 7005 | void WebContentsImpl::RequestSetBounds(const gfx::Rect& new_bounds) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7006 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::RequestSetBounds"); |
Mike Wasserman | dabad61 | 2020-08-13 04:26:27 | [diff] [blame] | 7007 | if (!delegate_) |
| 7008 | return; |
| 7009 | |
| 7010 | // Members of |new_bounds| may be 0 to indicate uninitialized values for newly |
| 7011 | // opened windows, even if the |GetContainerBounds()| inner rect is correct. |
| 7012 | // TODO(crbug.com/897300): Plumb values as specified; fallback on outer rect. |
| 7013 | auto bounds = new_bounds; |
| 7014 | if (bounds.IsEmpty()) |
| 7015 | bounds.set_size(GetContainerBounds().size()); |
| 7016 | |
| 7017 | // Only requests from the main frame, not subframes, should reach this code. |
Mike Wasserman | b6bc015 | 2020-08-25 22:46:20 | [diff] [blame] | 7018 | int64_t display_id = AdjustRequestedWindowBounds(&bounds, GetMainFrame()); |
| 7019 | |
| 7020 | // Drop fullscreen when placing a WebContents to prohibit deceptive behavior. |
| 7021 | // Only drop fullscreen on the specific destination display, which is known. |
| 7022 | // This supports sites using cross-screen window placement capabilities to |
| 7023 | // retain fullscreen and place a window on another screen. |
| 7024 | ForSecurityDropFullscreen(display_id).RunAndReset(); |
| 7025 | |
Mike Wasserman | dabad61 | 2020-08-13 04:26:27 | [diff] [blame] | 7026 | delegate_->SetContentsBounds(this, bounds); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7027 | } |
| 7028 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 7029 | void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node, |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 7030 | bool to_different_document) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7031 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::DidStartLoading", |
| 7032 | "frame_tree_node", frame_tree_node); |
Evan Stade | c3b2602 | 2017-07-14 19:50:24 | [diff] [blame] | 7033 | LoadingStateChanged(frame_tree_node->IsMainFrame() && to_different_document, |
Carlos IL | 07f282f | 2020-05-15 22:58:29 | [diff] [blame] | 7034 | nullptr); |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 7035 | |
Xiyuan Xia | 2a66b11 | 2018-12-06 15:52:16 | [diff] [blame] | 7036 | // Reset the focus state from DidStartNavigation to false if a new load starts |
| 7037 | // afterward, in case loading logic triggers a FocusLocationBarByDefault call. |
| 7038 | should_focus_location_bar_by_default_ = false; |
Ian Prest | cdd843d | 2020-01-28 18:59:58 | [diff] [blame] | 7039 | |
| 7040 | // Notify accessibility that the user is navigating away from the |
| 7041 | // current document. |
| 7042 | // TODO(domfarolino, dmazzoni): Do this using WebContentsObserver. See |
| 7043 | // https://crbug.com/981271. |
| 7044 | BrowserAccessibilityManager* manager = |
| 7045 | frame_tree_node->current_frame_host()->browser_accessibility_manager(); |
| 7046 | if (manager) |
| 7047 | manager->UserIsNavigatingAway(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7048 | } |
| 7049 | |
fdegans | c73eec2 | 2015-03-19 14:47:54 | [diff] [blame] | 7050 | void WebContentsImpl::DidStopLoading() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7051 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::DidStopLoading"); |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 7052 | std::unique_ptr<LoadNotificationDetails> details; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7053 | |
[email protected] | 9595fd8 | 2013-04-19 21:28:49 | [diff] [blame] | 7054 | // Use the last committed entry rather than the active one, in case a |
| 7055 | // pending entry has been created. |
| 7056 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
| 7057 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7058 | // An entry may not exist for a stop when loading an initial blank page or |
| 7059 | // if an iframe injected by script into a blank page finishes loading. |
| 7060 | if (entry) { |
Fergal Daly | 55b6d72 | 2020-09-11 07:56:33 | [diff] [blame] | 7061 | details = std::make_unique<LoadNotificationDetails>( |
| 7062 | entry->GetVirtualURL(), &controller_, |
| 7063 | controller_.GetCurrentEntryIndex()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7064 | } |
| 7065 | |
Carlos IL | 07f282f | 2020-05-15 22:58:29 | [diff] [blame] | 7066 | LoadingStateChanged(true, details.get()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7067 | } |
| 7068 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 7069 | void WebContentsImpl::DidChangeLoadProgress() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7070 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::DidChangeLoadProgress"); |
Nate Chapin | 22ea659 | 2019-03-05 22:29:02 | [diff] [blame] | 7071 | if (is_being_destroyed_) |
| 7072 | return; |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 7073 | double load_progress = frame_tree_.load_progress(); |
| 7074 | |
| 7075 | // The delegate is notified immediately for the first and last updates. Also, |
| 7076 | // since the message loop may be pretty busy when a page is loaded, it might |
| 7077 | // not execute a posted task in a timely manner so the progress report is sent |
| 7078 | // immediately if enough time has passed. |
| 7079 | base::TimeDelta min_delay = |
| 7080 | base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS); |
| 7081 | bool delay_elapsed = loading_last_progress_update_.is_null() || |
| 7082 | base::TimeTicks::Now() - loading_last_progress_update_ > min_delay; |
| 7083 | |
| 7084 | if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) { |
| 7085 | // If there is a pending task to send progress, it is now obsolete. |
| 7086 | loading_weak_factory_.InvalidateWeakPtrs(); |
| 7087 | |
| 7088 | // Notify the load progress change. |
| 7089 | SendChangeLoadProgress(); |
| 7090 | |
| 7091 | // Clean-up the states if needed. |
| 7092 | if (load_progress == 1.0) |
| 7093 | ResetLoadProgressState(); |
| 7094 | return; |
| 7095 | } |
| 7096 | |
| 7097 | if (loading_weak_factory_.HasWeakPtrs()) |
| 7098 | return; |
| 7099 | |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 7100 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
tzik | e2aca99 | 2017-09-05 08:50:54 | [diff] [blame] | 7101 | FROM_HERE, |
| 7102 | base::BindOnce(&WebContentsImpl::SendChangeLoadProgress, |
| 7103 | loading_weak_factory_.GetWeakPtr()), |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 7104 | min_delay); |
| 7105 | } |
| 7106 | |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 7107 | std::vector<std::unique_ptr<NavigationThrottle>> |
| 7108 | WebContentsImpl::CreateThrottlesForNavigation( |
clamy | cbf524d4 | 2016-09-27 12:48:35 | [diff] [blame] | 7109 | NavigationHandle* navigation_handle) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7110 | OPTIONAL_TRACE_EVENT1("content", |
| 7111 | "WebContentsImpl::CreateThrottlesForNavigation", |
| 7112 | "navigation", navigation_handle); |
Charlie Reis | 9607736 | 2019-07-04 00:34:04 | [diff] [blame] | 7113 | auto throttles = GetContentClient()->browser()->CreateThrottlesForNavigation( |
clamy | cbf524d4 | 2016-09-27 12:48:35 | [diff] [blame] | 7114 | navigation_handle); |
Charlie Reis | 9607736 | 2019-07-04 00:34:04 | [diff] [blame] | 7115 | |
| 7116 | // This is not a normal place to be adding a throttle. However, in the case |
| 7117 | // javascript dialogs, related logic is present in the web_contents/ layer, |
| 7118 | // and the purpose of the throttle is to ensure that navigation commits are |
| 7119 | // deferred for the entire WebContents. Most throttles are either added by |
| 7120 | // the embederrer outside of content/, or are per-frame and added by |
| 7121 | // NavigationThrottleRunner. |
| 7122 | std::unique_ptr<content::NavigationThrottle> dialog_throttle = |
| 7123 | JavaScriptDialogNavigationThrottle::MaybeCreateThrottleFor( |
| 7124 | navigation_handle); |
| 7125 | if (dialog_throttle) |
| 7126 | throttles.push_back(std::move(dialog_throttle)); |
| 7127 | |
| 7128 | return throttles; |
clamy | cbf524d4 | 2016-09-27 12:48:35 | [diff] [blame] | 7129 | } |
| 7130 | |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 7131 | std::unique_ptr<NavigationUIData> WebContentsImpl::GetNavigationUIData( |
| 7132 | NavigationHandle* navigation_handle) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7133 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::GetNavigationUIData"); |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 7134 | return GetContentClient()->browser()->GetNavigationUIData(navigation_handle); |
| 7135 | } |
| 7136 | |
W. James MacLean | 1c40862c | 2020-04-27 21:05:57 | [diff] [blame] | 7137 | void WebContentsImpl::RegisterExistingOriginToPreventOptInIsolation( |
W. James MacLean | b70fab8 | 2020-05-01 18:51:14 | [diff] [blame] | 7138 | const url::Origin& origin, |
| 7139 | NavigationRequest* navigation_request_to_exclude) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7140 | OPTIONAL_TRACE_EVENT2( |
| 7141 | "content", |
| 7142 | "WebContentsImpl::RegisterExistingOriginToPreventOptInIsolation", |
| 7143 | "origin", base::trace_event::ValueToString(origin), |
| 7144 | "navigation_request_to_exclude", navigation_request_to_exclude); |
W. James MacLean | 1c40862c | 2020-04-27 21:05:57 | [diff] [blame] | 7145 | // Note: This function can be made static if we ever need call it without |
| 7146 | // a WebContentsImpl instance, in which case we can use a wrapper to |
| 7147 | // implement the override from NavigatorDelegate. |
| 7148 | for (WebContentsImpl* web_contents : GetAllWebContents()) { |
| 7149 | web_contents->controller_.RegisterExistingOriginToPreventOptInIsolation( |
| 7150 | origin); |
W. James MacLean | b70fab8 | 2020-05-01 18:51:14 | [diff] [blame] | 7151 | // Walk the frame tree to pick up any frames without FrameNavigationEntries. |
| 7152 | // * Some frames won't have FrameNavigationEntries (Issues 524208, 608402). |
| 7153 | // * Some pending navigations won't have NavigationEntries. |
| 7154 | web_contents->GetFrameTree()->RegisterExistingOriginToPreventOptInIsolation( |
| 7155 | origin, navigation_request_to_exclude); |
W. James MacLean | 1c40862c | 2020-04-27 21:05:57 | [diff] [blame] | 7156 | } |
| 7157 | } |
| 7158 | |
pdr | 15f5b5b | 2017-06-20 00:58:00 | [diff] [blame] | 7159 | void WebContentsImpl::DidCancelLoading() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7160 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::DidCancelLoading"); |
pdr | 15f5b5b | 2017-06-20 00:58:00 | [diff] [blame] | 7161 | controller_.DiscardNonCommittedEntries(); |
| 7162 | |
| 7163 | // Update the URL display. |
| 7164 | NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
| 7165 | } |
| 7166 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 7167 | void WebContentsImpl::DidAccessInitialDocument() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7168 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::DidAccessInitialDocument"); |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 7169 | has_accessed_initial_document_ = true; |
| 7170 | |
[email protected] | d1371bf8e | 2014-04-19 03:26:24 | [diff] [blame] | 7171 | // We may have left a failed browser-initiated navigation in the address bar |
| 7172 | // to let the user edit it and try again. Clear it now that content might |
| 7173 | // show up underneath it. |
| 7174 | if (!IsLoading() && controller_.GetPendingEntry()) |
avi | 45a7253 | 2015-04-07 21:01:45 | [diff] [blame] | 7175 | controller_.DiscardPendingEntry(false); |
[email protected] | d1371bf8e | 2014-04-19 03:26:24 | [diff] [blame] | 7176 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 7177 | // Update the URL display. |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 7178 | NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 7179 | } |
| 7180 | |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 7181 | void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host, |
| 7182 | const std::string& name) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7183 | OPTIONAL_TRACE_EVENT2( |
| 7184 | "content", "WebContentsImpl::DidChangeName", "render_frame_host", |
| 7185 | base::trace_event::ToTracedValue(render_frame_host), "name", name); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 7186 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7187 | observer->FrameNameChanged(render_frame_host, name); |
| 7188 | }); |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 7189 | } |
| 7190 | |
John Delaney | edd8d6c | 2019-01-25 00:23:57 | [diff] [blame] | 7191 | void WebContentsImpl::DidReceiveFirstUserActivation( |
| 7192 | RenderFrameHost* render_frame_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7193 | OPTIONAL_TRACE_EVENT1( |
| 7194 | "content", "WebContentsImpl::DidReceiveFirstUserActivation", |
| 7195 | "render_frame_host", base::trace_event::ToTracedValue(render_frame_host)); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 7196 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7197 | observer->FrameReceivedFirstUserActivation(render_frame_host); |
| 7198 | }); |
John Delaney | edd8d6c | 2019-01-25 00:23:57 | [diff] [blame] | 7199 | } |
| 7200 | |
John Delaney | 0146a74 | 2019-01-25 19:25:28 | [diff] [blame] | 7201 | void WebContentsImpl::DidChangeDisplayState(RenderFrameHost* render_frame_host, |
| 7202 | bool is_display_none) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7203 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::DidChangeDisplayState", |
| 7204 | "render_frame_host", |
| 7205 | base::trace_event::ToTracedValue(render_frame_host), |
| 7206 | "is_display_none", is_display_none); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 7207 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7208 | observer->FrameDisplayStateChanged(render_frame_host, is_display_none); |
| 7209 | }); |
John Delaney | 0146a74 | 2019-01-25 19:25:28 | [diff] [blame] | 7210 | } |
| 7211 | |
| 7212 | void WebContentsImpl::FrameSizeChanged(RenderFrameHost* render_frame_host, |
| 7213 | const gfx::Size& frame_size) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7214 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::FrameSizeChanged", |
| 7215 | "render_frame_host", |
| 7216 | base::trace_event::ToTracedValue(render_frame_host)); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 7217 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7218 | observer->FrameSizeChanged(render_frame_host, frame_size); |
| 7219 | }); |
John Delaney | 0146a74 | 2019-01-25 19:25:28 | [diff] [blame] | 7220 | } |
| 7221 | |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 7222 | void WebContentsImpl::DocumentOnLoadCompleted( |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 7223 | RenderFrameHost* render_frame_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7224 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::DocumentOnLoadCompleted", |
| 7225 | "render_frame_host", |
| 7226 | base::trace_event::ToTracedValue(render_frame_host)); |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 7227 | ShowInsecureLocalhostWarningIfNeeded(); |
| 7228 | |
Alexander Timin | dd0fa0c5 | 2019-11-06 13:03:37 | [diff] [blame] | 7229 | GetRenderViewHost()->DocumentOnLoadCompletedInMainFrame(); |
| 7230 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 7231 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7232 | observer->DocumentOnLoadCompletedInMainFrame(); |
| 7233 | }); |
[email protected] | 6578fef | 2013-10-14 02:35:09 | [diff] [blame] | 7234 | |
| 7235 | // TODO(avi): Remove. http://crbug.com/170921 |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 7236 | NotificationService::current()->Notify( |
| 7237 | NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 7238 | Source<WebContents>(this), |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 7239 | NotificationService::NoDetails()); |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 7240 | } |
| 7241 | |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 7242 | void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host, |
Miyoung Shin | 5d77f7207 | 2020-10-09 15:14:20 | [diff] [blame] | 7243 | const blink::PageState& page_state) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7244 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::UpdateStateForFrame", |
| 7245 | "render_frame_host", |
| 7246 | base::trace_event::ToTracedValue(render_frame_host)); |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 7247 | // The state update affects the last NavigationEntry associated with the given |
| 7248 | // |render_frame_host|. This may not be the last committed NavigationEntry (as |
| 7249 | // in the case of an UpdateState from a frame being swapped out). We track |
| 7250 | // which entry this is in the RenderFrameHost's nav_entry_id. |
| 7251 | RenderFrameHostImpl* rfhi = |
| 7252 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
| 7253 | NavigationEntryImpl* entry = |
| 7254 | controller_.GetEntryWithUniqueID(rfhi->nav_entry_id()); |
| 7255 | if (!entry) |
| 7256 | return; |
| 7257 | |
| 7258 | FrameNavigationEntry* frame_entry = |
| 7259 | entry->GetFrameEntry(rfhi->frame_tree_node()); |
| 7260 | if (!frame_entry) |
| 7261 | return; |
| 7262 | |
creis | d06a942 | 2015-11-11 03:08:45 | [diff] [blame] | 7263 | // The SiteInstance might not match if we do a cross-process navigation with |
| 7264 | // replacement (e.g., auto-subframe), in which case the swap out of the old |
| 7265 | // RenderFrameHost runs in the background after the old FrameNavigationEntry |
| 7266 | // has already been replaced and destroyed. |
| 7267 | if (frame_entry->site_instance() != rfhi->GetSiteInstance()) |
| 7268 | return; |
| 7269 | |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 7270 | if (page_state == frame_entry->page_state()) |
| 7271 | return; // Nothing to update. |
| 7272 | |
creis | 0cade2e | 2017-02-28 06:37:47 | [diff] [blame] | 7273 | DCHECK(page_state.IsValid()) << "Shouldn't set an empty PageState."; |
nasko | 3463467 | 2016-07-29 18:46:06 | [diff] [blame] | 7274 | |
| 7275 | // The document_sequence_number and item_sequence_number recorded in the |
| 7276 | // FrameNavigationEntry should not differ from the one coming with the update, |
| 7277 | // since it must come from the same document. Do not update it if a difference |
| 7278 | // is detected, as this indicates that |frame_entry| is not the correct one. |
Miyoung Shin | 5d77f7207 | 2020-10-09 15:14:20 | [diff] [blame] | 7279 | blink::ExplodedPageState exploded_state; |
| 7280 | if (!blink::DecodePageState(page_state.ToEncodedData(), &exploded_state)) |
nasko | 3463467 | 2016-07-29 18:46:06 | [diff] [blame] | 7281 | return; |
| 7282 | |
| 7283 | if (exploded_state.top.document_sequence_number != |
| 7284 | frame_entry->document_sequence_number() || |
| 7285 | exploded_state.top.item_sequence_number != |
| 7286 | frame_entry->item_sequence_number()) { |
| 7287 | return; |
| 7288 | } |
| 7289 | |
nasko | 04a322f25a | 2016-09-01 00:00:34 | [diff] [blame] | 7290 | frame_entry->SetPageState(page_state); |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 7291 | controller_.NotifyEntryChanged(entry); |
| 7292 | } |
| 7293 | |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 7294 | void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host, |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 7295 | const base::string16& title, |
| 7296 | base::i18n::TextDirection title_direction) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7297 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::UpdateTitle", |
| 7298 | "render_frame_host", |
| 7299 | base::trace_event::ToTracedValue(render_frame_host), |
| 7300 | "title", base::trace_event::ValueToString(title)); |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 7301 | // Try to find the navigation entry, which might not be the current one. |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 7302 | // For example, it might be from a recently swapped out RFH. |
avi | 1edc855 | 2016-10-13 21:37:16 | [diff] [blame] | 7303 | NavigationEntryImpl* entry = controller_.GetEntryWithUniqueID( |
creis | ad8c31a | 2016-05-24 17:07:04 | [diff] [blame] | 7304 | static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id()); |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 7305 | |
| 7306 | // We can handle title updates when we don't have an entry in |
| 7307 | // UpdateTitleForEntry, but only if the update is from the current RVH. |
| 7308 | // TODO(avi): Change to make decisions based on the RenderFrameHost. |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 7309 | if (!entry && render_frame_host != GetMainFrame()) |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 7310 | return; |
| 7311 | |
| 7312 | // TODO(evan): make use of title_direction. |
| 7313 | // http://code.google.com/p/chromium/issues/detail?id=27094 |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 7314 | UpdateTitleForEntry(entry, title); |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 7315 | } |
| 7316 | |
Mario Sanchez Prada | dffbe66e | 2020-09-07 12:01:08 | [diff] [blame] | 7317 | void WebContentsImpl::UpdateTargetURL(RenderFrameHost* render_frame_host, |
| 7318 | const GURL& url) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7319 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::UpdateTargetURL", |
| 7320 | "render_frame_host", |
| 7321 | base::trace_event::ToTracedValue(render_frame_host), |
| 7322 | "url", base::trace_event::ValueToString(url)); |
Mario Sanchez Prada | dffbe66e | 2020-09-07 12:01:08 | [diff] [blame] | 7323 | // In case of racey updates from multiple RenderViewHosts, the last URL should |
| 7324 | // be shown - see also some discussion in https://crbug.com/807776. |
| 7325 | if (!url.is_valid() && render_frame_host != frame_that_set_last_target_url_) |
| 7326 | return; |
| 7327 | frame_that_set_last_target_url_ = |
| 7328 | url.is_valid() ? render_frame_host : nullptr; |
| 7329 | |
| 7330 | if (delegate_) |
| 7331 | delegate_->UpdateTargetURL(this, url); |
| 7332 | } |
| 7333 | |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 7334 | bool WebContentsImpl::ShouldRouteMessageEvent( |
| 7335 | RenderFrameHost* target_rfh, |
| 7336 | SiteInstance* source_site_instance) const { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7337 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::ShouldRouteMessageEvent", |
| 7338 | "render_frame_host", |
| 7339 | base::trace_event::ToTracedValue(target_rfh), |
| 7340 | "source_site_instance", source_site_instance); |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 7341 | // Allow the message if this WebContents is dedicated to a browser plugin |
| 7342 | // guest. |
[email protected] | 0eba810b | 2012-10-18 03:19:36 | [diff] [blame] | 7343 | // Note: This check means that an embedder could theoretically receive a |
| 7344 | // postMessage from anyone (not just its own guests). However, this is |
| 7345 | // probably not a risk for apps since other pages won't have references |
| 7346 | // to App windows. |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 7347 | return GetBrowserPluginGuest() || GetBrowserPluginEmbedder(); |
| 7348 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 7349 | |
alexmos | 5872904 | 2015-06-18 23:20:00 | [diff] [blame] | 7350 | void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7351 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::EnsureOpenerProxiesExist", |
| 7352 | "render_frame_host", |
| 7353 | base::trace_event::ToTracedValue(source_rfh)); |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 7354 | WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>( |
| 7355 | WebContents::FromRenderFrameHost(source_rfh)); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 7356 | |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 7357 | if (source_web_contents) { |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 7358 | // If this message is going to outer WebContents from inner WebContents, |
| 7359 | // then we should not create a RenderView. AttachToOuterWebContentsFrame() |
| 7360 | // already created a RenderFrameProxyHost for that purpose. |
| 7361 | if (GetBrowserPluginEmbedder() && |
W. James MacLean | 2539adb3 | 2019-12-13 00:40:44 | [diff] [blame] | 7362 | source_web_contents->browser_plugin_guest_) { |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 7363 | return; |
W. James MacLean | 2539adb3 | 2019-12-13 00:40:44 | [diff] [blame] | 7364 | } |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 7365 | |
lfg | 812874d | 2016-02-09 22:26:13 | [diff] [blame] | 7366 | if (this != source_web_contents && GetBrowserPluginGuest()) { |
nasko | b3041b98a4 | 2016-03-12 04:43:06 | [diff] [blame] | 7367 | // We create a RenderFrameProxyHost for the embedder in the guest's render |
| 7368 | // process but we intentionally do not expose the embedder's opener chain |
| 7369 | // to it. |
| 7370 | source_web_contents->GetRenderManager()->CreateRenderFrameProxy( |
| 7371 | GetSiteInstance()); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 7372 | } else { |
alexmos | 5872904 | 2015-06-18 23:20:00 | [diff] [blame] | 7373 | RenderFrameHostImpl* source_rfhi = |
| 7374 | static_cast<RenderFrameHostImpl*>(source_rfh); |
| 7375 | source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( |
alexmos | 90325cf | 2015-09-02 17:18:39 | [diff] [blame] | 7376 | GetSiteInstance(), nullptr); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 7377 | } |
| 7378 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 7379 | } |
| 7380 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 7381 | void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7382 | OPTIONAL_TRACE_EVENT0("content", |
| 7383 | "WebContentsImpl::SetAsFocusedWebContentsIfNecessary"); |
Adithya Srinivasan | 11af2c5 | 2019-12-16 22:52:55 | [diff] [blame] | 7384 | DCHECK(!portal()); |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 7385 | // Only change focus if we are not currently focused. |
| 7386 | WebContentsImpl* old_contents = GetFocusedWebContents(); |
| 7387 | if (old_contents == this) |
| 7388 | return; |
| 7389 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 7390 | GetOutermostWebContents()->node_.SetFocusedWebContents(this); |
| 7391 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 7392 | // Send a page level blur to the old contents so that it displays inactive UI |
| 7393 | // and focus this contents to activate it. |
| 7394 | if (old_contents) |
| 7395 | old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false); |
avallee | c2ff1ef | 2017-01-21 00:12:30 | [diff] [blame] | 7396 | |
| 7397 | // Make sure the outer web contents knows our frame is focused. Otherwise, the |
| 7398 | // outer renderer could have the element before or after the frame element |
| 7399 | // focused which would return early without actually advancing focus. |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 7400 | FocusOuterAttachmentFrameChain(); |
avallee | c2ff1ef | 2017-01-21 00:12:30 | [diff] [blame] | 7401 | |
Carlos IL | d51e770 | 2020-05-07 18:51:39 | [diff] [blame] | 7402 | GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true); |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 7403 | } |
| 7404 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 7405 | void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, |
| 7406 | SiteInstance* source) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7407 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::SetFocusedFrame", |
| 7408 | "frame_tree_node", node, "source_site_instance", |
| 7409 | source); |
Adithya Srinivasan | 11af2c5 | 2019-12-16 22:52:55 | [diff] [blame] | 7410 | DCHECK(!portal()); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 7411 | frame_tree_.SetFocusedFrame(node, source); |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 7412 | |
Lucas Furukawa Gadani | abbfa34 | 2017-08-29 19:37:57 | [diff] [blame] | 7413 | if (auto* inner_contents = node_.GetInnerWebContentsInFrame(node)) { |
| 7414 | // |this| is an outer WebContents and |node| represents an inner |
| 7415 | // WebContents. Transfer the focus to the inner contents if |this| is |
| 7416 | // focused. |
| 7417 | if (GetFocusedWebContents() == this) |
| 7418 | inner_contents->SetAsFocusedWebContentsIfNecessary(); |
| 7419 | } else if (node_.OuterContentsFrameTreeNode() && |
| 7420 | node_.OuterContentsFrameTreeNode() |
| 7421 | ->current_frame_host() |
| 7422 | ->GetSiteInstance() == source) { |
| 7423 | // |this| is an inner WebContents, |node| is its main FrameTreeNode and |
| 7424 | // the outer WebContents FrameTreeNode is at |source|'s SiteInstance. |
| 7425 | // Transfer the focus to the inner WebContents if the outer WebContents is |
| 7426 | // focused. This branch is used when an inner WebContents is focused through |
Lowell Manners | a953038 | 2019-08-01 09:46:57 | [diff] [blame] | 7427 | // its RenderFrameProxyHost (via FrameFocused mojo call, used to |
Lucas Furukawa Gadani | abbfa34 | 2017-08-29 19:37:57 | [diff] [blame] | 7428 | // implement the window.focus() API). |
| 7429 | if (GetFocusedWebContents() == GetOuterWebContents()) |
| 7430 | SetAsFocusedWebContentsIfNecessary(); |
| 7431 | } else if (!GetOuterWebContents()) { |
| 7432 | // This is an outermost WebContents. |
| 7433 | SetAsFocusedWebContentsIfNecessary(); |
Lucas Furukawa Gadani | abbfa34 | 2017-08-29 19:37:57 | [diff] [blame] | 7434 | } |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 7435 | } |
| 7436 | |
Avi Drissman | 36f801f | 2018-02-01 20:06:04 | [diff] [blame] | 7437 | void WebContentsImpl::DidCallFocus() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7438 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::DidCallFocus"); |
Avi Drissman | 36f801f | 2018-02-01 20:06:04 | [diff] [blame] | 7439 | // Any explicit focusing of another window while this WebContents is in |
| 7440 | // fullscreen can be used to confuse the user, so drop fullscreen. |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 7441 | base::ScopedClosureRunner fullscreen_block = ForSecurityDropFullscreen(); |
| 7442 | // The other contents is independent of this contents, so release the |
| 7443 | // fullscreen block. |
| 7444 | fullscreen_block.RunAndReset(); |
Avi Drissman | 36f801f | 2018-02-01 20:06:04 | [diff] [blame] | 7445 | } |
| 7446 | |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 7447 | RenderFrameHost* WebContentsImpl::GetFocusedFrameIncludingInnerWebContents() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7448 | OPTIONAL_TRACE_EVENT0( |
| 7449 | "content", "WebContentsImpl::GetFocusedFrameIncludingInnerWebContents"); |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 7450 | WebContentsImpl* contents = this; |
| 7451 | FrameTreeNode* focused_node = contents->frame_tree_.GetFocusedFrame(); |
| 7452 | |
| 7453 | // If there is no focused frame in the outer WebContents, we need to return |
| 7454 | // null. |
| 7455 | if (!focused_node) |
| 7456 | return nullptr; |
| 7457 | |
| 7458 | // If the focused frame is embedding an inner WebContents, we must descend |
| 7459 | // into that contents. If the current WebContents does not have a focused |
| 7460 | // frame, return the main frame of this contents instead of the focused empty |
| 7461 | // frame embedding this contents. |
| 7462 | while (true) { |
| 7463 | contents = contents->node_.GetInnerWebContentsInFrame(focused_node); |
| 7464 | if (!contents) |
| 7465 | return focused_node->current_frame_host(); |
| 7466 | |
| 7467 | focused_node = contents->frame_tree_.GetFocusedFrame(); |
| 7468 | if (!focused_node) |
| 7469 | return contents->GetMainFrame(); |
| 7470 | } |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 7471 | } |
| 7472 | |
Lucas Furukawa Gadani | abbfa34 | 2017-08-29 19:37:57 | [diff] [blame] | 7473 | void WebContentsImpl::OnAdvanceFocus(RenderFrameHostImpl* source_rfh) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7474 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnAdvanceFocus", |
| 7475 | "render_frame_host", |
| 7476 | base::trace_event::ToTracedValue(source_rfh)); |
Lucas Furukawa Gadani | abbfa34 | 2017-08-29 19:37:57 | [diff] [blame] | 7477 | // When a RenderFrame needs to advance focus to a RenderFrameProxy (by hitting |
| 7478 | // TAB), the RenderFrameProxy sends an IPC to RenderFrameProxyHost. When this |
| 7479 | // RenderFrameProxyHost represents an inner WebContents, the outer WebContents |
| 7480 | // needs to focus the inner WebContents. |
| 7481 | if (GetOuterWebContents() && |
| 7482 | GetOuterWebContents() == source_rfh->delegate()->GetAsWebContents() && |
| 7483 | GetFocusedWebContents() == GetOuterWebContents()) { |
| 7484 | SetAsFocusedWebContentsIfNecessary(); |
| 7485 | } |
| 7486 | } |
| 7487 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 7488 | void WebContentsImpl::OnFocusedElementChangedInFrame( |
| 7489 | RenderFrameHostImpl* frame, |
Emily Stark | 023dbacc | 2020-08-27 22:31:40 | [diff] [blame] | 7490 | const gfx::Rect& bounds_in_root_view, |
| 7491 | blink::mojom::FocusType focus_type) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7492 | OPTIONAL_TRACE_EVENT1( |
| 7493 | "content", "WebContentsImpl::OnFocusedElementChangedInFrame", |
| 7494 | "render_frame_host", base::trace_event::ToTracedValue(frame)); |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 7495 | RenderWidgetHostViewBase* root_view = |
| 7496 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 7497 | if (!root_view || !frame->GetView()) |
| 7498 | return; |
Katie D | e013137 | 2020-07-09 23:03:10 | [diff] [blame] | 7499 | // Convert to screen coordinates from window coordinates by adding the |
| 7500 | // window's origin. |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 7501 | gfx::Point origin = bounds_in_root_view.origin(); |
| 7502 | origin += root_view->GetViewBounds().OffsetFromOrigin(); |
| 7503 | gfx::Rect bounds_in_screen(origin, bounds_in_root_view.size()); |
| 7504 | |
| 7505 | root_view->FocusedNodeChanged(frame->has_focused_editable_element(), |
| 7506 | bounds_in_screen); |
| 7507 | |
| 7508 | FocusedNodeDetails details = {frame->has_focused_editable_element(), |
Emily Stark | 023dbacc | 2020-08-27 22:31:40 | [diff] [blame] | 7509 | bounds_in_screen, focus_type}; |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 7510 | |
| 7511 | // TODO(ekaramad): We should replace this with an observer notification |
| 7512 | // (https://crbug.com/675975). |
| 7513 | NotificationService::current()->Notify( |
| 7514 | NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
| 7515 | Source<RenderViewHost>(GetRenderViewHost()), |
| 7516 | Details<FocusedNodeDetails>(&details)); |
Jeff Fisher | 709b4c5 | 2019-07-29 20:07:34 | [diff] [blame] | 7517 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 7518 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7519 | observer->OnFocusChangedInPage(&details); |
| 7520 | }); |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 7521 | } |
| 7522 | |
Lowell Manners | 1de5242e | 2019-04-25 10:18:46 | [diff] [blame] | 7523 | bool WebContentsImpl::DidAddMessageToConsole( |
| 7524 | blink::mojom::ConsoleMessageLevel log_level, |
| 7525 | const base::string16& message, |
| 7526 | int32_t line_no, |
| 7527 | const base::string16& source_id) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7528 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::DidAddMessageToConsole", |
| 7529 | "message", base::trace_event::ValueToString(message)); |
| 7530 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 7531 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7532 | observer->OnDidAddMessageToConsole(log_level, message, line_no, source_id); |
| 7533 | }); |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7534 | |
[email protected] | a796f20 | 2012-05-30 14:14:25 | [diff] [blame] | 7535 | if (!delegate_) |
| 7536 | return false; |
Lowell Manners | 1de5242e | 2019-04-25 10:18:46 | [diff] [blame] | 7537 | return delegate_->DidAddMessageToConsole(this, log_level, message, line_no, |
avi | a90ae4e | 2016-11-11 20:49:33 | [diff] [blame] | 7538 | source_id); |
[email protected] | a796f20 | 2012-05-30 14:14:25 | [diff] [blame] | 7539 | } |
| 7540 | |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 7541 | void WebContentsImpl::DidReceiveInputEvent( |
dominickn | 9c7ceaa3 | 2016-02-27 01:52:53 | [diff] [blame] | 7542 | RenderWidgetHostImpl* render_widget_host, |
Emily Stark | c7bd40c | 2020-07-21 19:12:55 | [diff] [blame] | 7543 | const blink::WebInputEvent& event) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7544 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::DidReceiveInputEvent", |
| 7545 | "render_widget_host", render_widget_host); |
| 7546 | |
Emily Stark | c7bd40c | 2020-07-21 19:12:55 | [diff] [blame] | 7547 | if (!IsUserInteractionInputType(event.GetType())) |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 7548 | return; |
| 7549 | |
kenrb | 1922185 | 2016-04-29 17:21:40 | [diff] [blame] | 7550 | // Ignore unless the widget is currently in the frame tree. |
| 7551 | if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host)) |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 7552 | return; |
| 7553 | |
Emily Stark | c7bd40c | 2020-07-21 19:12:55 | [diff] [blame] | 7554 | if (event.GetType() != blink::WebInputEvent::Type::kGestureScrollBegin) |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 7555 | last_interactive_input_event_time_ = ui::EventTimeForNow(); |
dominickn | 9c7ceaa3 | 2016-02-27 01:52:53 | [diff] [blame] | 7556 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 7557 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7558 | observer->DidGetUserInteraction(event); |
| 7559 | }); |
dominickn | 2dd142dd | 2015-10-29 05:30:50 | [diff] [blame] | 7560 | } |
| 7561 | |
Avi Drissman | 738ea19 | 2018-08-29 20:24:16 | [diff] [blame] | 7562 | bool WebContentsImpl::ShouldIgnoreInputEvents() { |
| 7563 | WebContentsImpl* web_contents = this; |
| 7564 | while (web_contents) { |
| 7565 | if (web_contents->ignore_input_events_) |
| 7566 | return true; |
| 7567 | web_contents = web_contents->GetOuterWebContents(); |
| 7568 | } |
| 7569 | |
| 7570 | return false; |
| 7571 | } |
| 7572 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 7573 | void WebContentsImpl::FocusOwningWebContents( |
| 7574 | RenderWidgetHostImpl* render_widget_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7575 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::FocusOwningWebContents", |
| 7576 | "render_widget_host", render_widget_host); |
Alex Moshchuk | c4f0a72 | 2019-11-19 22:41:28 | [diff] [blame] | 7577 | RenderWidgetHostImpl* main_frame_widget_host = |
| 7578 | GetMainFrame()->GetRenderWidgetHost(); |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 7579 | RenderWidgetHostImpl* focused_widget = |
Alex Moshchuk | c4f0a72 | 2019-11-19 22:41:28 | [diff] [blame] | 7580 | GetFocusedRenderWidgetHost(main_frame_widget_host); |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 7581 | |
| 7582 | if (focused_widget != render_widget_host && |
avallee | 8e88159 | 2016-11-19 00:39:30 | [diff] [blame] | 7583 | (!focused_widget || |
| 7584 | focused_widget->delegate() != render_widget_host->delegate())) { |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 7585 | SetAsFocusedWebContentsIfNecessary(); |
| 7586 | } |
| 7587 | } |
| 7588 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 7589 | void WebContentsImpl::OnIgnoredUIEvent() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7590 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::OnIgnoredUIEvent"); |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 7591 | // Notify observers. |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 7592 | observers_.ForEachObserver( |
| 7593 | [&](WebContentsObserver* observer) { observer->DidGetIgnoredUIEvent(); }); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 7594 | } |
| 7595 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 7596 | void WebContentsImpl::RendererUnresponsive( |
Lukasz Anforowicz | 52b9372 | 2018-06-20 16:11:39 | [diff] [blame] | 7597 | RenderWidgetHostImpl* render_widget_host, |
| 7598 | base::RepeatingClosure hang_monitor_restarter) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7599 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::RendererUnresponsive", |
| 7600 | "render_widget_host", render_widget_host); |
avi | c031d39 | 2017-03-03 03:09:42 | [diff] [blame] | 7601 | if (ShouldIgnoreUnresponsiveRenderer()) |
[email protected] | e5fc163 | 2011-08-08 07:51:53 | [diff] [blame] | 7602 | return; |
| 7603 | |
Lukasz Anforowicz | 4f0593d | 2018-09-21 18:33:54 | [diff] [blame] | 7604 | // Do not report hangs (to task manager, to hang renderer dialog, etc.) for |
| 7605 | // invisible tabs (like extension background page, background tabs). See |
| 7606 | // https://crbug.com/881812 for rationale and for choosing the visibility |
| 7607 | // (rather than process priority) as the signal here. |
| 7608 | if (GetVisibility() != Visibility::VISIBLE) |
| 7609 | return; |
| 7610 | |
Avi Drissman | 8920def | 2018-01-31 19:53:36 | [diff] [blame] | 7611 | if (!render_widget_host->renderer_initialized()) |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 7612 | return; |
| 7613 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 7614 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7615 | observer->OnRendererUnresponsive(render_widget_host->GetProcess()); |
| 7616 | }); |
Dave Tapuska | c6146c5 | 2017-12-20 22:48:15 | [diff] [blame] | 7617 | if (delegate_) |
Lukasz Anforowicz | 52b9372 | 2018-06-20 16:11:39 | [diff] [blame] | 7618 | delegate_->RendererUnresponsive(this, render_widget_host, |
| 7619 | std::move(hang_monitor_restarter)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7620 | } |
| 7621 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 7622 | void WebContentsImpl::RendererResponsive( |
| 7623 | RenderWidgetHostImpl* render_widget_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7624 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::RenderResponsive", |
| 7625 | "render_widget_host", render_widget_host); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 7626 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7627 | observer->OnRendererResponsive(render_widget_host->GetProcess()); |
| 7628 | }); |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7629 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 7630 | if (delegate_) |
Avi Drissman | 1572e8c3c | 2018-02-02 19:06:36 | [diff] [blame] | 7631 | delegate_->RendererResponsive(this, render_widget_host); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7632 | } |
| 7633 | |
Alex Moshchuk | 7b4f065 | 2019-05-30 18:54:41 | [diff] [blame] | 7634 | void WebContentsImpl::SubframeCrashed( |
| 7635 | blink::mojom::FrameVisibility visibility) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7636 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::SubframeCrashed", |
| 7637 | "visibility", |
| 7638 | base::trace_event::ValueToString(visibility)); |
Alex Moshchuk | 7b4f065 | 2019-05-30 18:54:41 | [diff] [blame] | 7639 | // If a subframe crashed on a hidden tab, mark the tab for reload to avoid |
| 7640 | // showing a sad frame to the user if they ever switch back to that tab. Do |
| 7641 | // this for subframes that are either visible in viewport or visible but |
| 7642 | // scrolled out of view, but skip subframes that are not rendered (e.g., via |
| 7643 | // "display:none"), since in that case the user wouldn't see a sad frame |
| 7644 | // anyway. |
| 7645 | bool did_mark_for_reload = false; |
| 7646 | if (IsHidden() && visibility != blink::mojom::FrameVisibility::kNotRendered && |
| 7647 | base::FeatureList::IsEnabled( |
| 7648 | features::kReloadHiddenTabsWithCrashedSubframes)) { |
| 7649 | controller_.SetNeedsReload( |
| 7650 | NavigationControllerImpl::NeedsReloadType::kCrashedSubframe); |
| 7651 | did_mark_for_reload = true; |
| 7652 | UMA_HISTOGRAM_ENUMERATION( |
| 7653 | "Stability.ChildFrameCrash.TabMarkedForReload.Visibility", visibility); |
| 7654 | } |
| 7655 | |
| 7656 | UMA_HISTOGRAM_BOOLEAN("Stability.ChildFrameCrash.TabMarkedForReload", |
| 7657 | did_mark_for_reload); |
| 7658 | } |
| 7659 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 7660 | void WebContentsImpl::BeforeUnloadFiredFromRenderManager( |
[email protected] | feaded0 | 2012-09-25 19:12:55 | [diff] [blame] | 7661 | bool proceed, const base::TimeTicks& proceed_time, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7662 | bool* proceed_to_fire_unload) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7663 | OPTIONAL_TRACE_EVENT0("content", |
| 7664 | "WebContentsImpl::BeforeUnloadFiredFromRenderManager"); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 7665 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7666 | observer->BeforeUnloadFired(proceed, proceed_time); |
| 7667 | }); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 7668 | if (delegate_) |
| 7669 | delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload); |
[email protected] | e80af49 | 2013-06-24 21:52:09 | [diff] [blame] | 7670 | // Note: |this| might be deleted at this point. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7671 | } |
| 7672 | |
[email protected] | 58d5cfe | 2013-07-10 02:40:52 | [diff] [blame] | 7673 | void WebContentsImpl::RenderProcessGoneFromRenderManager( |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 7674 | RenderViewHost* render_view_host) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 7675 | DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING); |
[email protected] | ec6a7eb | 2013-04-22 17:34:22 | [diff] [blame] | 7676 | RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 7677 | } |
| 7678 | |
[email protected] | af90590 | 2013-10-01 21:38:51 | [diff] [blame] | 7679 | void WebContentsImpl::CancelModalDialogsForRenderManager() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7680 | OPTIONAL_TRACE_EVENT0("content", |
| 7681 | "WebContentsImpl::CancelModalDialogsForRenderManager"); |
[email protected] | af90590 | 2013-10-01 21:38:51 | [diff] [blame] | 7682 | // We need to cancel modal dialogs when doing a process swap, since the load |
avi | 2460c76 | 2015-04-17 15:21:54 | [diff] [blame] | 7683 | // deferrer would prevent us from swapping out. We also clear the state |
| 7684 | // because this is a cross-process navigation, which means that it's a new |
| 7685 | // site that should not have to pay for the sins of its predecessor. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 7686 | // |
Lei Zhang | 6410ec1a | 2019-01-31 21:38:58 | [diff] [blame] | 7687 | // Note that we don't bother telling |browser_plugin_embedder_| because the |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 7688 | // cross-process navigation will either destroy the browser plugins or not |
| 7689 | // require their dialogs to close. |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 7690 | if (dialog_manager_) { |
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 7691 | dialog_manager_->CancelDialogs(this, /*reset_state=*/true); |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 7692 | } |
[email protected] | af90590 | 2013-10-01 21:38:51 | [diff] [blame] | 7693 | } |
| 7694 | |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7695 | void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_frame, |
| 7696 | RenderFrameHost* new_frame, |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 7697 | bool is_main_frame) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7698 | TRACE_EVENT2( |
| 7699 | "content", "WebContentsImpl::NotifySwappedFromRenderManager", |
| 7700 | "old_render_frame_host", base::trace_event::ToTracedValue(old_frame), |
| 7701 | "new_render_frame_host", base::trace_event::ToTracedValue(new_frame)); |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 7702 | if (is_main_frame) { |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7703 | // The |new_frame| and its various compadres are already swapped into place |
| 7704 | // for the WebContentsImpl when this method is called. |
| 7705 | DCHECK(GetMainFrame() == new_frame); |
| 7706 | DCHECK(GetRenderViewHost() == new_frame->GetRenderViewHost()); |
| 7707 | DCHECK(GetRenderWidgetHostView() == new_frame->GetView()); |
| 7708 | |
Fergal Daly | 6767b2e | 2020-02-04 03:15:16 | [diff] [blame] | 7709 | RenderViewHost* old_rvh = |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7710 | old_frame ? old_frame->GetRenderViewHost() : nullptr; |
| 7711 | RenderViewHost* new_rvh = new_frame->GetRenderViewHost(); |
Fergal Daly | 6767b2e | 2020-02-04 03:15:16 | [diff] [blame] | 7712 | // |old_rvh| and |new_rvh| might be equal when navigating from a crashed |
| 7713 | // RenderFrameHost to a new same-site one. With RenderDocument, this will |
| 7714 | // happen for every same-site navigation. |
| 7715 | if (old_rvh != new_rvh) |
| 7716 | NotifyViewSwapped(old_rvh, new_rvh); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 7717 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 7718 | // Make sure the visible RVH reflects the new delegate's preferences. |
| 7719 | if (delegate_) |
| 7720 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | d56a49e | 2013-02-23 00:47:39 | [diff] [blame] | 7721 | |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7722 | auto* rwhv = static_cast<RenderWidgetHostViewBase*>(new_frame->GetView()); |
| 7723 | if (rwhv) { |
| 7724 | rwhv->SetMainFrameAXTreeID(new_frame->GetAXTreeID()); |
| 7725 | |
| 7726 | // The RenderWidgetHostView for the speculative RenderFrameHost is not |
| 7727 | // resized with the current RenderFrameHost while a navigation is |
| 7728 | // pending. So when we swap in the main frame, we need to update the |
| 7729 | // RenderWidgetHostView's size. |
| 7730 | // |
| 7731 | // Historically, this was done to fix b/1079768 for interstitials. |
| 7732 | rwhv->SetSize(GetSizeForMainFrame()); |
| 7733 | } |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 7734 | } |
| 7735 | |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7736 | NotifyFrameSwapped(old_frame, new_frame, is_main_frame); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 7737 | } |
| 7738 | |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 7739 | void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager( |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7740 | RenderFrameHost* old_frame, |
| 7741 | RenderFrameHost* new_frame) { |
| 7742 | NotifyViewSwapped(old_frame ? old_frame->GetRenderViewHost() : nullptr, |
| 7743 | new_frame->GetRenderViewHost()); |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 7744 | } |
| 7745 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 7746 | NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() { |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 7747 | return GetController(); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 7748 | } |
| 7749 | |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 7750 | std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost( |
Miyoung Shin | 072d405 | 2020-07-13 07:52:44 | [diff] [blame] | 7751 | RenderFrameHost* frame_host, |
Denis Kuznetsov [CET] | 2c6f0159f | 2020-05-18 14:18:16 | [diff] [blame] | 7752 | const GURL& url) { |
Miyoung Shin | 072d405 | 2020-07-13 07:52:44 | [diff] [blame] | 7753 | return CreateWebUI(frame_host, url); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7754 | } |
| 7755 | |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 7756 | void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager( |
| 7757 | RenderViewHost* render_view_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7758 | OPTIONAL_TRACE_EVENT1( |
| 7759 | "content", "WebContentsImpl::CreateRenderWidgetHostViewForRenderManager", |
| 7760 | "render_view_host", render_view_host); |
lfg | c740d4b2 | 2016-04-15 16:45:33 | [diff] [blame] | 7761 | RenderWidgetHostViewBase* rwh_view = |
W. James MacLean | 13d834d | 2019-12-04 16:06:45 | [diff] [blame] | 7762 | view_->CreateViewForWidget(render_view_host->GetWidget()); |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7763 | rwh_view->SetSize(GetSizeForMainFrame()); |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 7764 | } |
| 7765 | |
Fergal Daly | 6de62f5 | 2020-10-14 01:56:44 | [diff] [blame] | 7766 | void WebContentsImpl::ReattachOuterDelegateIfNeeded() { |
| 7767 | if (node_.outer_web_contents()) |
| 7768 | ReattachToOuterWebContentsFrame(); |
| 7769 | } |
| 7770 | |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 7771 | bool WebContentsImpl::CreateRenderViewForRenderManager( |
| 7772 | RenderViewHost* render_view_host, |
Antonio Gomes | b3dd5fc | 2020-05-25 22:53:27 | [diff] [blame] | 7773 | const base::Optional<base::UnguessableToken>& opener_frame_token, |
Daniel Cheng | abfdb00 | 2020-06-04 06:02:30 | [diff] [blame] | 7774 | int proxy_routing_id) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7775 | TRACE_EVENT1("browser,navigation", |
| 7776 | "WebContentsImpl::CreateRenderViewForRenderManager", |
| 7777 | "render_view_host", render_view_host); |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 7778 | |
piman | 00cf940 | 2017-04-03 17:09:20 | [diff] [blame] | 7779 | if (proxy_routing_id == MSG_ROUTING_NONE) |
lfg | 9431efd | 2016-12-14 14:45:26 | [diff] [blame] | 7780 | CreateRenderWidgetHostViewForRenderManager(render_view_host); |
lfg | 9431efd | 2016-12-14 14:45:26 | [diff] [blame] | 7781 | |
piman | 00cf940 | 2017-04-03 17:09:20 | [diff] [blame] | 7782 | if (!static_cast<RenderViewHostImpl*>(render_view_host) |
Daniel Cheng | abfdb00 | 2020-06-04 06:02:30 | [diff] [blame] | 7783 | ->CreateRenderView(opener_frame_token, proxy_routing_id, |
Antonio Gomes | b3dd5fc | 2020-05-25 22:53:27 | [diff] [blame] | 7784 | created_with_opener_)) { |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 7785 | return false; |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 7786 | } |
W. James MacLean | 6219867 | 2019-06-04 16:46:10 | [diff] [blame] | 7787 | // Set the TextAutosizer state from the main frame's renderer on the new view, |
| 7788 | // but only if it's not for the main frame. Main frame renderers should create |
| 7789 | // this state themselves from up-to-date values, so we shouldn't override it |
| 7790 | // with the cached values. |
| 7791 | if (!render_view_host->GetMainFrame()) { |
Antonio Gomes | da7e03d | 2020-08-05 15:03:08 | [diff] [blame] | 7792 | auto* proxy_host = GetRenderManager()->GetRenderFrameProxyHost( |
| 7793 | render_view_host->GetSiteInstance()); |
| 7794 | proxy_host->GetAssociatedRemoteMainFrame()->UpdateTextAutosizerPageInfo( |
| 7795 | text_autosizer_page_info_.Clone()); |
W. James MacLean | 6219867 | 2019-06-04 16:46:10 | [diff] [blame] | 7796 | } |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 7797 | |
Fergal Daly | 6de62f5 | 2020-10-14 01:56:44 | [diff] [blame] | 7798 | if (proxy_routing_id == MSG_ROUTING_NONE) |
| 7799 | ReattachOuterDelegateIfNeeded(); |
Lucas Furukawa Gadani | aed1fed | 2017-10-13 17:34:14 | [diff] [blame] | 7800 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 7801 | SetHistoryOffsetAndLengthForView(render_view_host, |
| 7802 | controller_.GetLastCommittedEntryIndex(), |
| 7803 | controller_.GetEntryCount()); |
| 7804 | |
Avi Drissman | 7c57be7 | 2020-07-29 20:09:46 | [diff] [blame] | 7805 | #if defined(OS_POSIX) && !defined(OS_MAC) && !defined(OS_ANDROID) |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 7806 | // Force a ViewMsg_Resize to be sent, needed to make plugins show up on |
| 7807 | // linux. See crbug.com/83941. |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 7808 | RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView(); |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 7809 | if (rwh_view) { |
| 7810 | if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost()) |
Fady Samuel | 0b91182 | 2018-04-25 13:22:16 | [diff] [blame] | 7811 | render_widget_host->SynchronizeVisualProperties(); |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 7812 | } |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 7813 | #endif |
| 7814 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7815 | return true; |
| 7816 | } |
| 7817 | |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 7818 | #if defined(OS_ANDROID) |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 7819 | |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 7820 | base::android::ScopedJavaLocalRef<jobject> |
| 7821 | WebContentsImpl::GetJavaWebContents() { |
mostynb | 042582e | 2015-03-16 22:13:40 | [diff] [blame] | 7822 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 0e813a5 | 2014-08-13 10:34:56 | [diff] [blame] | 7823 | return GetWebContentsAndroid()->GetJavaObject(); |
| 7824 | } |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 7825 | |
[email protected] | 0e813a5 | 2014-08-13 10:34:56 | [diff] [blame] | 7826 | WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() { |
Kevin McNee | 576bb5d8 | 2019-05-29 16:47:51 | [diff] [blame] | 7827 | if (!web_contents_android_) { |
| 7828 | web_contents_android_ = std::make_unique<WebContentsAndroid>(this); |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 7829 | } |
Kevin McNee | 576bb5d8 | 2019-05-29 16:47:51 | [diff] [blame] | 7830 | return web_contents_android_.get(); |
| 7831 | } |
| 7832 | |
| 7833 | void WebContentsImpl::ClearWebContentsAndroid() { |
| 7834 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 7835 | web_contents_android_.reset(); |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 7836 | } |
| 7837 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 7838 | void WebContentsImpl::ActivateNearestFindResult(float x, |
| 7839 | float y) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7840 | OPTIONAL_TRACE_EVENT0("content", |
| 7841 | "WebContentsImpl::ActivateNearestFindResult"); |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 7842 | GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y); |
| 7843 | } |
| 7844 | |
| 7845 | void WebContentsImpl::RequestFindMatchRects(int current_version) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7846 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::RequestFindMatchRects"); |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 7847 | GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version); |
| 7848 | } |
| 7849 | |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 7850 | service_manager::InterfaceProvider* WebContentsImpl::GetJavaInterfaces() { |
sammc | f5f1b0f | 2016-09-20 23:05:11 | [diff] [blame] | 7851 | if (!java_interfaces_) { |
Gyuyoung Kim | 6c9ce902 | 2019-11-26 05:40:08 | [diff] [blame] | 7852 | mojo::PendingRemote<service_manager::mojom::InterfaceProvider> provider; |
| 7853 | BindInterfaceRegistryForWebContents( |
| 7854 | provider.InitWithNewPipeAndPassReceiver(), this); |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 7855 | java_interfaces_.reset(new service_manager::InterfaceProvider); |
sammc | f5f1b0f | 2016-09-20 23:05:11 | [diff] [blame] | 7856 | java_interfaces_->Bind(std::move(provider)); |
| 7857 | } |
| 7858 | return java_interfaces_.get(); |
| 7859 | } |
| 7860 | |
Francois Doray | 6c26f334 | 2018-08-24 17:17:22 | [diff] [blame] | 7861 | #endif |
| 7862 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 7863 | bool WebContentsImpl::CompletedFirstVisuallyNonEmptyPaint() { |
Carlos Caballero | 91fffb2 | 2019-10-29 15:24:30 | [diff] [blame] | 7864 | return GetRenderViewHost()->did_first_visually_non_empty_paint(); |
spqchan | e72c3cb | 2017-06-30 23:02:10 | [diff] [blame] | 7865 | } |
| 7866 | |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 7867 | void WebContentsImpl::OnDidDownloadImage( |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 7868 | ImageDownloadCallback callback, |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 7869 | int id, |
| 7870 | const GURL& image_url, |
leon.han | cbc4bc3c | 2016-02-26 07:08:52 | [diff] [blame] | 7871 | int32_t http_status_code, |
leon.han | c222853 | 2016-08-16 05:59:18 | [diff] [blame] | 7872 | const std::vector<SkBitmap>& images, |
| 7873 | const std::vector<gfx::Size>& original_image_sizes) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7874 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnDidDownloadImage", |
| 7875 | "image_url", |
| 7876 | base::trace_event::ValueToString(image_url)); |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 7877 | std::move(callback).Run(id, http_status_code, image_url, images, |
| 7878 | original_image_sizes); |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 7879 | } |
| 7880 | |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 7881 | void WebContentsImpl::OnDialogClosed(int render_process_id, |
| 7882 | int render_frame_id, |
Dave Tapuska | cdf545cc | 2020-01-23 18:38:52 | [diff] [blame] | 7883 | JavaScriptDialogCallback response_callback, |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 7884 | base::ScopedClosureRunner fullscreen_block, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 7885 | bool dialog_was_suppressed, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 7886 | bool success, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 7887 | const base::string16& user_input) { |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 7888 | RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id, |
| 7889 | render_frame_id); |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7890 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnDialogClosed", |
| 7891 | "render_frame_host", |
| 7892 | base::trace_event::ToTracedValue(rfh)); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 7893 | last_dialog_suppressed_ = dialog_was_suppressed; |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 7894 | fullscreen_block.RunAndReset(); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 7895 | |
Charlie Reis | 9607736 | 2019-07-04 00:34:04 | [diff] [blame] | 7896 | javascript_dialog_navigation_deferrer_.reset(); |
| 7897 | |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 7898 | if (is_showing_before_unload_dialog_ && !success) { |
clamy | bc6f415 | 2016-04-01 20:14:23 | [diff] [blame] | 7899 | // It is possible for the current RenderFrameHost to have changed in the |
| 7900 | // meantime. Do not reset the navigation state in that case. |
| 7901 | if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) { |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 7902 | rfh->frame_tree_node()->BeforeUnloadCanceled(); |
clamy | bc6f415 | 2016-04-01 20:14:23 | [diff] [blame] | 7903 | controller_.DiscardNonCommittedEntries(); |
| 7904 | } |
[email protected] | ec8e8b0 | 2013-06-19 04:57:10 | [diff] [blame] | 7905 | |
Charles Reis | 15d60b13 | 2017-11-03 17:43:47 | [diff] [blame] | 7906 | // Update the URL display either way, to avoid showing a stale URL. |
| 7907 | NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
| 7908 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 7909 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7910 | observer->BeforeUnloadDialogCancelled(); |
| 7911 | }); |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 7912 | } |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 7913 | |
Dave Tapuska | cdf545cc | 2020-01-23 18:38:52 | [diff] [blame] | 7914 | std::move(response_callback).Run(success, user_input); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 7915 | |
Dave Tapuska | cdf545cc | 2020-01-23 18:38:52 | [diff] [blame] | 7916 | std::vector<protocol::PageHandler*> page_handlers = |
| 7917 | protocol::PageHandler::EnabledForWebContents(this); |
| 7918 | for (auto* handler : page_handlers) |
| 7919 | handler->DidCloseJavaScriptDialog(success, user_input); |
avi | 1c51fb6 | 2017-02-27 20:43:03 | [diff] [blame] | 7920 | |
| 7921 | is_showing_javascript_dialog_ = false; |
| 7922 | is_showing_before_unload_dialog_ = false; |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 7923 | } |
| 7924 | |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 7925 | bool WebContentsImpl::IsHidden() { |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 7926 | return !IsBeingCaptured() && visibility_ != Visibility::VISIBLE; |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 7927 | } |
| 7928 | |
rob | 9725074 | 2015-12-10 17:45:15 | [diff] [blame] | 7929 | int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() { |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 7930 | return node_.outer_contents_frame_tree_node_id(); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 7931 | } |
| 7932 | |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 7933 | RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 7934 | return frame_tree_.root()->render_manager(); |
| 7935 | } |
| 7936 | |
[email protected] | f849734 | 2013-02-05 22:15:02 | [diff] [blame] | 7937 | BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 7938 | return browser_plugin_guest_.get(); |
| 7939 | } |
| 7940 | |
Albert J. Wong | c55cc64d | 2018-10-12 02:50:04 | [diff] [blame] | 7941 | void WebContentsImpl::SetBrowserPluginGuest( |
| 7942 | std::unique_ptr<BrowserPluginGuest> guest) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7943 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::SetBrowserPluginGuest"); |
Albert J. Wong | c55cc64d | 2018-10-12 02:50:04 | [diff] [blame] | 7944 | DCHECK(!browser_plugin_guest_); |
| 7945 | DCHECK(guest); |
| 7946 | browser_plugin_guest_ = std::move(guest); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 7947 | } |
| 7948 | |
Aidan Wolter | 52bcc12a | 2018-11-14 03:27:29 | [diff] [blame] | 7949 | base::UnguessableToken WebContentsImpl::GetAudioGroupId() { |
Aidan Wolter | 52bcc12a | 2018-11-14 03:27:29 | [diff] [blame] | 7950 | return GetAudioStreamFactory()->group_id(); |
| 7951 | } |
| 7952 | |
Miyoung Shin | 5709ab0 | 2020-02-19 06:50:41 | [diff] [blame] | 7953 | const std::vector<blink::mojom::FaviconURLPtr>& |
| 7954 | WebContentsImpl::GetFaviconURLs() { |
Mounir Lamouri | 7b4a1f23 | 2019-12-23 16:32:10 | [diff] [blame] | 7955 | return favicon_urls_; |
| 7956 | } |
| 7957 | |
Mugdha Lakhani | 0a0d786 | 2020-07-29 09:58:45 | [diff] [blame] | 7958 | // The Mac implementation of the next two methods is in |
| 7959 | // web_contents_impl_mac.mm |
Avi Drissman | d4d79f7 | 2020-07-30 18:35:18 | [diff] [blame] | 7960 | #if !defined(OS_MAC) |
Mugdha Lakhani | 0a0d786 | 2020-07-29 09:58:45 | [diff] [blame] | 7961 | |
| 7962 | void WebContentsImpl::Resize(const gfx::Rect& new_bounds) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7963 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::Resize"); |
Mugdha Lakhani | 0a0d786 | 2020-07-29 09:58:45 | [diff] [blame] | 7964 | #if defined(USE_AURA) |
| 7965 | aura::Window* window = GetNativeView(); |
| 7966 | window->SetBounds(gfx::Rect(window->bounds().origin(), new_bounds.size())); |
| 7967 | #elif defined(OS_ANDROID) |
| 7968 | content::RenderWidgetHostView* view = GetRenderWidgetHostView(); |
| 7969 | if (view) |
| 7970 | view->SetBounds(new_bounds); |
| 7971 | #endif |
| 7972 | } |
| 7973 | |
| 7974 | gfx::Size WebContentsImpl::GetSize() { |
| 7975 | #if defined(USE_AURA) |
| 7976 | aura::Window* window = GetNativeView(); |
| 7977 | return window->bounds().size(); |
| 7978 | #elif defined(OS_ANDROID) |
| 7979 | ui::ViewAndroid* view_android = GetNativeView(); |
| 7980 | return view_android->bounds().size(); |
| 7981 | #endif |
| 7982 | } |
| 7983 | |
Avi Drissman | d4d79f7 | 2020-07-30 18:35:18 | [diff] [blame] | 7984 | #endif // !defined(OS_MAC) |
Mugdha Lakhani | 0a0d786 | 2020-07-29 09:58:45 | [diff] [blame] | 7985 | |
[email protected] | f849734 | 2013-02-05 22:15:02 | [diff] [blame] | 7986 | BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 7987 | return browser_plugin_embedder_.get(); |
| 7988 | } |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 7989 | |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 7990 | void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 7991 | OPTIONAL_TRACE_EVENT0( |
| 7992 | "content", "WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary"); |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 7993 | if (browser_plugin_embedder_) |
| 7994 | return; |
| 7995 | browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this)); |
| 7996 | } |
| 7997 | |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7998 | gfx::Size WebContentsImpl::GetSizeForMainFrame() { |
| 7999 | if (delegate_) { |
| 8000 | // The delegate has a chance to specify a size independent of the UI. |
| 8001 | gfx::Size delegate_size = delegate_->GetSizeForNewRenderView(this); |
| 8002 | if (!delegate_size.IsEmpty()) |
| 8003 | return delegate_size; |
| 8004 | } |
| 8005 | |
| 8006 | // Device emulation, when enabled, can specify a size independent of the UI. |
| 8007 | if (!device_emulation_size_.IsEmpty()) |
| 8008 | return device_emulation_size_; |
| 8009 | |
| 8010 | return GetContainerBounds().size(); |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 8011 | } |
| 8012 | |
[email protected] | ae7eeda | 2014-07-04 01:53:26 | [diff] [blame] | 8013 | void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8014 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::OnFrameRemoved", |
| 8015 | "render_frame_host", |
| 8016 | base::trace_event::ToTracedValue(render_frame_host)); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 8017 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 8018 | observer->FrameDeleted(render_frame_host); |
| 8019 | }); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 8020 | } |
| 8021 | |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 8022 | void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8023 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::OnPreferredSizeChanged"); |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 8024 | if (!delegate_) |
| 8025 | return; |
| 8026 | const gfx::Size new_size = GetPreferredSize(); |
| 8027 | if (new_size != old_size) |
| 8028 | delegate_->UpdatePreferredSize(this, new_size); |
| 8029 | } |
| 8030 | |
Miyoung Shin | 072d405 | 2020-07-13 07:52:44 | [diff] [blame] | 8031 | std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUI( |
| 8032 | RenderFrameHost* frame_host, |
| 8033 | const GURL& url) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8034 | TRACE_EVENT2("content", "WebContentsImpl::CreateWebUI", "frame_host", |
| 8035 | base::trace_event::ToTracedValue(frame_host), "url", |
| 8036 | base::trace_event::ValueToString(url)); |
Miyoung Shin | 072d405 | 2020-07-13 07:52:44 | [diff] [blame] | 8037 | std::unique_ptr<WebUIImpl> web_ui = |
| 8038 | std::make_unique<WebUIImpl>(this, frame_host); |
Lei Zhang | ee3b63ad | 2018-06-06 23:25:31 | [diff] [blame] | 8039 | std::unique_ptr<WebUIController> controller( |
avi | e865b1d | 2016-10-24 19:42:59 | [diff] [blame] | 8040 | WebUIControllerFactoryRegistry::GetInstance() |
Lei Zhang | ee3b63ad | 2018-06-06 23:25:31 | [diff] [blame] | 8041 | ->CreateWebUIControllerForURL(web_ui.get(), url)); |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 8042 | if (controller) { |
Lei Zhang | ee3b63ad | 2018-06-06 23:25:31 | [diff] [blame] | 8043 | web_ui->SetController(std::move(controller)); |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 8044 | return web_ui; |
| 8045 | } |
| 8046 | |
avi | e865b1d | 2016-10-24 19:42:59 | [diff] [blame] | 8047 | return nullptr; |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 8048 | } |
| 8049 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 8050 | FindRequestManager* WebContentsImpl::GetFindRequestManager() { |
| 8051 | for (auto* contents = this; contents; |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 8052 | contents = contents->GetOuterWebContents()) { |
| 8053 | if (contents->find_request_manager_) |
| 8054 | return contents->find_request_manager_.get(); |
| 8055 | } |
| 8056 | |
| 8057 | return nullptr; |
| 8058 | } |
| 8059 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 8060 | FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() { |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 8061 | if (FindRequestManager* manager = GetFindRequestManager()) |
| 8062 | return manager; |
| 8063 | |
Ehsan Karamad | 6beb2ea | 2018-11-25 18:15:13 | [diff] [blame] | 8064 | DCHECK(!browser_plugin_guest_ || GetOuterWebContents()); |
| 8065 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 8066 | // No existing FindRequestManager found, so one must be created. |
Fergal Daly | 55b6d72 | 2020-09-11 07:56:33 | [diff] [blame] | 8067 | find_request_manager_ = std::make_unique<FindRequestManager>(this); |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 8068 | |
| 8069 | // Concurrent find sessions must not overlap, so destroy any existing |
| 8070 | // FindRequestManagers in any inner WebContentses. |
Lucas Furukawa Gadani | 2ec00c8 | 2018-12-14 15:53:16 | [diff] [blame] | 8071 | for (WebContents* contents : GetWebContentsAndAllInner()) { |
| 8072 | auto* web_contents_impl = static_cast<WebContentsImpl*>(contents); |
| 8073 | if (web_contents_impl == this) |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 8074 | continue; |
Lucas Furukawa Gadani | 2ec00c8 | 2018-12-14 15:53:16 | [diff] [blame] | 8075 | if (web_contents_impl->find_request_manager_) { |
| 8076 | web_contents_impl->find_request_manager_->StopFinding( |
| 8077 | STOP_FIND_ACTION_CLEAR_SELECTION); |
| 8078 | web_contents_impl->find_request_manager_.release(); |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 8079 | } |
| 8080 | } |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 8081 | |
| 8082 | return find_request_manager_.get(); |
| 8083 | } |
| 8084 | |
| 8085 | void WebContentsImpl::NotifyFindReply(int request_id, |
| 8086 | int number_of_matches, |
| 8087 | const gfx::Rect& selection_rect, |
| 8088 | int active_match_ordinal, |
| 8089 | bool final_update) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8090 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::NotifyFindReply"); |
Sebastien Marchand | cf97ed5 | 2017-07-24 23:50:34 | [diff] [blame] | 8091 | if (delegate_ && !is_being_destroyed_ && |
Lukasz Anforowicz | e9ae372 | 2017-09-29 17:37:38 | [diff] [blame] | 8092 | !GetMainFrame()->GetProcess()->FastShutdownStarted()) { |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 8093 | delegate_->FindReply(this, request_id, number_of_matches, selection_rect, |
| 8094 | active_match_ordinal, final_update); |
| 8095 | } |
| 8096 | } |
| 8097 | |
ortuno | 467e579 | 2016-06-10 04:32:39 | [diff] [blame] | 8098 | void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8099 | OPTIONAL_TRACE_EVENT0( |
| 8100 | "content", "WebContentsImpl::IncrementBluetoothConnectedDeviceCount"); |
ortuno | 467e579 | 2016-06-10 04:32:39 | [diff] [blame] | 8101 | // Trying to invalidate the tab state while being destroyed could result in a |
| 8102 | // use after free. |
| 8103 | if (IsBeingDestroyed()) { |
| 8104 | return; |
| 8105 | } |
| 8106 | // Notify for UI updates if the state changes. |
| 8107 | bluetooth_connected_device_count_++; |
| 8108 | if (bluetooth_connected_device_count_ == 1) { |
Francois Doray | 66766a57 | 2019-12-17 20:56:49 | [diff] [blame] | 8109 | OnIsConnectedToBluetoothDeviceChanged(true); |
ortuno | 467e579 | 2016-06-10 04:32:39 | [diff] [blame] | 8110 | } |
| 8111 | } |
| 8112 | |
| 8113 | void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8114 | OPTIONAL_TRACE_EVENT0( |
| 8115 | "content", "WebContentsImpl::DecrementBluetoothConnectedDeviceCount"); |
ortuno | 467e579 | 2016-06-10 04:32:39 | [diff] [blame] | 8116 | // Trying to invalidate the tab state while being destroyed could result in a |
| 8117 | // use after free. |
| 8118 | if (IsBeingDestroyed()) { |
| 8119 | return; |
| 8120 | } |
| 8121 | // Notify for UI updates if the state changes. |
Lukasz Anforowicz | e9ae372 | 2017-09-29 17:37:38 | [diff] [blame] | 8122 | DCHECK_NE(bluetooth_connected_device_count_, 0u); |
ortuno | 467e579 | 2016-06-10 04:32:39 | [diff] [blame] | 8123 | bluetooth_connected_device_count_--; |
| 8124 | if (bluetooth_connected_device_count_ == 0) { |
Francois Doray | 66766a57 | 2019-12-17 20:56:49 | [diff] [blame] | 8125 | OnIsConnectedToBluetoothDeviceChanged(false); |
| 8126 | } |
| 8127 | } |
| 8128 | |
| 8129 | void WebContentsImpl::OnIsConnectedToBluetoothDeviceChanged( |
| 8130 | bool is_connected_to_bluetooth_device) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8131 | OPTIONAL_TRACE_EVENT0( |
| 8132 | "content", "WebContentsImpl::OnIsConnectedToBluetoothDeviceChanged"); |
Francois Doray | 66766a57 | 2019-12-17 20:56:49 | [diff] [blame] | 8133 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 8134 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 8135 | observer->OnIsConnectedToBluetoothDeviceChanged( |
Francois Doray | 66766a57 | 2019-12-17 20:56:49 | [diff] [blame] | 8136 | is_connected_to_bluetooth_device); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 8137 | }); |
ortuno | 467e579 | 2016-06-10 04:32:39 | [diff] [blame] | 8138 | } |
| 8139 | |
Ovidio Henriquez | 76696f6 | 2020-07-08 03:06:59 | [diff] [blame] | 8140 | void WebContentsImpl::IncrementBluetoothScanningSessionsCount() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8141 | OPTIONAL_TRACE_EVENT0( |
| 8142 | "content", "WebContentsImpl::IncrementBluetoothScanningSessionsCount"); |
Ovidio Henriquez | 76696f6 | 2020-07-08 03:06:59 | [diff] [blame] | 8143 | // Trying to invalidate the tab state while being destroyed could result in a |
| 8144 | // use after free. |
| 8145 | if (IsBeingDestroyed()) |
| 8146 | return; |
| 8147 | |
| 8148 | // Notify for UI updates if the state changes. |
| 8149 | bluetooth_scanning_sessions_count_++; |
| 8150 | if (bluetooth_scanning_sessions_count_ == 1) |
| 8151 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 8152 | } |
| 8153 | |
| 8154 | void WebContentsImpl::DecrementBluetoothScanningSessionsCount() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8155 | OPTIONAL_TRACE_EVENT0( |
| 8156 | "content", "WebContentsImpl::DecrementBluetoothScanningSessionsCount"); |
Ovidio Henriquez | 76696f6 | 2020-07-08 03:06:59 | [diff] [blame] | 8157 | // Trying to invalidate the tab state while being destroyed could result in a |
| 8158 | // use after free. |
| 8159 | if (IsBeingDestroyed()) |
| 8160 | return; |
| 8161 | |
| 8162 | DCHECK_NE(0u, bluetooth_scanning_sessions_count_); |
| 8163 | bluetooth_scanning_sessions_count_--; |
| 8164 | if (bluetooth_scanning_sessions_count_ == 0) |
| 8165 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 8166 | } |
| 8167 | |
Reilly Grant | 5e7c79b2 | 2019-04-09 17:26:20 | [diff] [blame] | 8168 | void WebContentsImpl::IncrementSerialActiveFrameCount() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8169 | OPTIONAL_TRACE_EVENT0("content", |
| 8170 | "WebContentsImpl::IncrementSerialActiveFrameCount"); |
Reilly Grant | 5e7c79b2 | 2019-04-09 17:26:20 | [diff] [blame] | 8171 | // Trying to invalidate the tab state while being destroyed could result in a |
| 8172 | // use after free. |
| 8173 | if (IsBeingDestroyed()) |
| 8174 | return; |
| 8175 | |
| 8176 | // Notify for UI updates if the state changes. |
| 8177 | serial_active_frame_count_++; |
| 8178 | if (serial_active_frame_count_ == 1) |
| 8179 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 8180 | } |
| 8181 | |
| 8182 | void WebContentsImpl::DecrementSerialActiveFrameCount() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8183 | OPTIONAL_TRACE_EVENT0("content", |
| 8184 | "WebContentsImpl::DecrementSerialActiveFrameCount"); |
Reilly Grant | 5e7c79b2 | 2019-04-09 17:26:20 | [diff] [blame] | 8185 | // Trying to invalidate the tab state while being destroyed could result in a |
| 8186 | // use after free. |
| 8187 | if (IsBeingDestroyed()) |
| 8188 | return; |
| 8189 | |
| 8190 | // Notify for UI updates if the state changes. |
| 8191 | DCHECK_NE(0u, serial_active_frame_count_); |
| 8192 | serial_active_frame_count_--; |
| 8193 | if (serial_active_frame_count_ == 0) |
| 8194 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 8195 | } |
| 8196 | |
Matt Reynolds | e8c6c1f | 2019-11-02 09:53:53 | [diff] [blame] | 8197 | void WebContentsImpl::IncrementHidActiveFrameCount() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8198 | OPTIONAL_TRACE_EVENT0("content", |
| 8199 | "WebContentsImpl::IncrementHidActiveFrameCount"); |
Matt Reynolds | e8c6c1f | 2019-11-02 09:53:53 | [diff] [blame] | 8200 | // Trying to invalidate the tab state while being destroyed could result in a |
| 8201 | // use after free. |
| 8202 | if (IsBeingDestroyed()) |
| 8203 | return; |
| 8204 | |
| 8205 | // Notify for UI updates if the active frame count transitions from zero to |
| 8206 | // non-zero. |
| 8207 | hid_active_frame_count_++; |
| 8208 | if (hid_active_frame_count_ == 1) |
| 8209 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 8210 | } |
| 8211 | |
| 8212 | void WebContentsImpl::DecrementHidActiveFrameCount() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8213 | OPTIONAL_TRACE_EVENT0("content", |
| 8214 | "WebContentsImpl::DecrementHidActiveFrameCount"); |
Matt Reynolds | e8c6c1f | 2019-11-02 09:53:53 | [diff] [blame] | 8215 | // Trying to invalidate the tab state while being destroyed could result in a |
| 8216 | // use after free. |
| 8217 | if (IsBeingDestroyed()) |
| 8218 | return; |
| 8219 | |
| 8220 | // Notify for UI updates if the active frame count transitions from non-zero |
| 8221 | // to zero. |
| 8222 | DCHECK_NE(0u, hid_active_frame_count_); |
| 8223 | hid_active_frame_count_--; |
| 8224 | if (hid_active_frame_count_ == 0) |
| 8225 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 8226 | } |
| 8227 | |
Marijn Kruisselbrink | 2905104 | 2019-08-06 22:56:55 | [diff] [blame] | 8228 | void WebContentsImpl::IncrementNativeFileSystemHandleCount() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8229 | OPTIONAL_TRACE_EVENT0( |
| 8230 | "content", "WebContentsImpl::IncrementNativeFileSystemHandleCount"); |
Marijn Kruisselbrink | 2905104 | 2019-08-06 22:56:55 | [diff] [blame] | 8231 | // Trying to invalidate the tab state while being destroyed could result in a |
| 8232 | // use after free. |
| 8233 | if (IsBeingDestroyed()) |
| 8234 | return; |
| 8235 | |
| 8236 | // Notify for UI updates if the state changes. Need both TYPE_TAB and TYPE_URL |
| 8237 | // to update both the tab-level usage indicator and the usage indicator in the |
| 8238 | // omnibox. |
| 8239 | native_file_system_handle_count_++; |
| 8240 | if (native_file_system_handle_count_ == 1) { |
| 8241 | NotifyNavigationStateChanged(static_cast<content::InvalidateTypes>( |
| 8242 | INVALIDATE_TYPE_TAB | INVALIDATE_TYPE_URL)); |
| 8243 | } |
| 8244 | } |
| 8245 | |
| 8246 | void WebContentsImpl::DecrementNativeFileSystemHandleCount() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8247 | OPTIONAL_TRACE_EVENT0( |
| 8248 | "content", "WebContentsImpl::DecrementNativeFileSystemHandleCount"); |
Marijn Kruisselbrink | 2905104 | 2019-08-06 22:56:55 | [diff] [blame] | 8249 | // Trying to invalidate the tab state while being destroyed could result in a |
| 8250 | // use after free. |
| 8251 | if (IsBeingDestroyed()) |
| 8252 | return; |
| 8253 | |
| 8254 | // Notify for UI updates if the state changes. Need both TYPE_TAB and TYPE_URL |
| 8255 | // to update both the tab-level usage indicator and the usage indicator in the |
| 8256 | // omnibox. |
| 8257 | DCHECK_NE(0u, native_file_system_handle_count_); |
| 8258 | native_file_system_handle_count_--; |
| 8259 | if (native_file_system_handle_count_ == 0) { |
| 8260 | NotifyNavigationStateChanged(static_cast<content::InvalidateTypes>( |
| 8261 | INVALIDATE_TYPE_TAB | INVALIDATE_TYPE_URL)); |
| 8262 | } |
| 8263 | } |
| 8264 | |
zqzhang | 8ac4900 | 2017-03-16 21:51:35 | [diff] [blame] | 8265 | void WebContentsImpl::SetHasPersistentVideo(bool has_persistent_video) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8266 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::SetHasPersistentVideo", |
| 8267 | "has_persistent_video", has_persistent_video, |
| 8268 | "had_persistent_value", has_persistent_video_); |
zqzhang | 8ac4900 | 2017-03-16 21:51:35 | [diff] [blame] | 8269 | if (has_persistent_video_ == has_persistent_video) |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 8270 | return; |
| 8271 | |
zqzhang | 8ac4900 | 2017-03-16 21:51:35 | [diff] [blame] | 8272 | has_persistent_video_ = has_persistent_video; |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 8273 | NotifyPreferencesChanged(); |
zqzhang | 8ac4900 | 2017-03-16 21:51:35 | [diff] [blame] | 8274 | media_web_contents_observer()->RequestPersistentVideo(has_persistent_video); |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 8275 | } |
| 8276 | |
Ian Vollick | 5d5c37f | 2019-06-19 22:50:57 | [diff] [blame] | 8277 | void WebContentsImpl::SetSpatialNavigationDisabled(bool disabled) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8278 | OPTIONAL_TRACE_EVENT2( |
| 8279 | "content", "WebContentsImpl::SetSpatialNavigationDisabled", "disabled", |
| 8280 | disabled, "was_disabled", is_spatial_navigation_disabled_); |
Ian Vollick | 5d5c37f | 2019-06-19 22:50:57 | [diff] [blame] | 8281 | if (is_spatial_navigation_disabled_ == disabled) |
| 8282 | return; |
| 8283 | |
| 8284 | is_spatial_navigation_disabled_ = disabled; |
| 8285 | NotifyPreferencesChanged(); |
| 8286 | } |
| 8287 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 8288 | void WebContentsImpl::BrowserPluginGuestWillDetach() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8289 | OPTIONAL_TRACE_EVENT0("content", |
| 8290 | "WebContentsImpl::BrowserPluginGuestWillDetach"); |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 8291 | WebContentsImpl* outermost = GetOutermostWebContents(); |
| 8292 | if (this != outermost && ContainsOrIsFocusedWebContents()) |
| 8293 | outermost->SetAsFocusedWebContentsIfNecessary(); |
| 8294 | } |
| 8295 | |
Becca Hughes | 112832e | 2019-06-11 17:19:02 | [diff] [blame] | 8296 | PictureInPictureResult WebContentsImpl::EnterPictureInPicture( |
Mounir Lamouri | 11e9ef4 | 2018-05-22 03:10:16 | [diff] [blame] | 8297 | const viz::SurfaceId& surface_id, |
| 8298 | const gfx::Size& natural_size) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8299 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::EnterPictureInPicture"); |
François Beaufort | f09e446 | 2019-01-18 14:34:51 | [diff] [blame] | 8300 | return delegate_ |
| 8301 | ? delegate_->EnterPictureInPicture(this, surface_id, natural_size) |
Becca Hughes | 112832e | 2019-06-11 17:19:02 | [diff] [blame] | 8302 | : PictureInPictureResult::kNotSupported; |
Mounir Lamouri | 11e9ef4 | 2018-05-22 03:10:16 | [diff] [blame] | 8303 | } |
| 8304 | |
Mounir Lamouri | 6d759e1 | 2018-05-16 20:01:30 | [diff] [blame] | 8305 | void WebContentsImpl::ExitPictureInPicture() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8306 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::ExitPictureInPicture"); |
Mounir Lamouri | 6d759e1 | 2018-05-16 20:01:30 | [diff] [blame] | 8307 | if (delegate_) |
| 8308 | delegate_->ExitPictureInPicture(); |
| 8309 | } |
| 8310 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 8311 | #if defined(OS_ANDROID) |
| 8312 | void WebContentsImpl::NotifyFindMatchRectsReply( |
| 8313 | int version, |
| 8314 | const std::vector<gfx::RectF>& rects, |
| 8315 | const gfx::RectF& active_rect) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8316 | OPTIONAL_TRACE_EVENT0("content", |
| 8317 | "WebContentsImpl::NotifyFindMatchRectsReply"); |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 8318 | if (delegate_) |
| 8319 | delegate_->FindMatchRectsReply(this, version, rects, active_rect); |
| 8320 | } |
| 8321 | #endif |
| 8322 | |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 8323 | void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8324 | OPTIONAL_TRACE_EVENT1("content", |
| 8325 | "WebContentsImpl::SetForceDisableOverscrollContent", |
| 8326 | "force_disable", force_disable); |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 8327 | force_disable_overscroll_content_ = force_disable; |
| 8328 | if (view_) |
| 8329 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 8330 | } |
| 8331 | |
Jianzhou Feng | d8720c7 | 2018-01-18 03:06:30 | [diff] [blame] | 8332 | bool WebContentsImpl::SetDeviceEmulationSize(const gfx::Size& new_size) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8333 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::SetDeviceEmulationSize"); |
Jianzhou Feng | d8720c7 | 2018-01-18 03:06:30 | [diff] [blame] | 8334 | device_emulation_size_ = new_size; |
| 8335 | RenderWidgetHostView* rwhv = GetMainFrame()->GetView(); |
| 8336 | |
| 8337 | const gfx::Size current_size = rwhv->GetViewBounds().size(); |
| 8338 | if (view_size_before_emulation_.IsEmpty()) |
| 8339 | view_size_before_emulation_ = current_size; |
| 8340 | |
| 8341 | if (current_size != new_size) |
| 8342 | rwhv->SetSize(new_size); |
| 8343 | |
| 8344 | return current_size != new_size; |
| 8345 | } |
| 8346 | |
| 8347 | void WebContentsImpl::ClearDeviceEmulationSize() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8348 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::ClearDeviceEmulationSize"); |
Jianzhou Feng | d8720c7 | 2018-01-18 03:06:30 | [diff] [blame] | 8349 | RenderWidgetHostView* rwhv = GetMainFrame()->GetView(); |
| 8350 | // WebContentsView could get resized during emulation, which also resizes |
| 8351 | // RWHV. If it happens, assume user would like to keep using the size after |
| 8352 | // emulation. |
| 8353 | // TODO(jzfeng): Prohibit resizing RWHV through any other means (at least when |
| 8354 | // WebContentsView size changes). |
Dmitry Gozman | c6370718 | 2018-03-06 00:09:39 | [diff] [blame] | 8355 | if (!view_size_before_emulation_.IsEmpty() && rwhv && |
| 8356 | rwhv->GetViewBounds().size() == device_emulation_size_) { |
Jianzhou Feng | d8720c7 | 2018-01-18 03:06:30 | [diff] [blame] | 8357 | rwhv->SetSize(view_size_before_emulation_); |
Dmitry Gozman | c6370718 | 2018-03-06 00:09:39 | [diff] [blame] | 8358 | } |
Jianzhou Feng | d8720c7 | 2018-01-18 03:06:30 | [diff] [blame] | 8359 | device_emulation_size_ = gfx::Size(); |
| 8360 | view_size_before_emulation_ = gfx::Size(); |
| 8361 | } |
| 8362 | |
Max Morin | 5bc74f5 | 2018-05-09 07:00:21 | [diff] [blame] | 8363 | ForwardingAudioStreamFactory* WebContentsImpl::GetAudioStreamFactory() { |
| 8364 | if (!audio_stream_factory_) { |
| 8365 | audio_stream_factory_.emplace( |
| 8366 | this, |
Max Morin | ddebb97 | 2018-09-20 10:04:14 | [diff] [blame] | 8367 | // BrowserMainLoop::GetInstance() may be null in unit tests. |
| 8368 | BrowserMainLoop::GetInstance() |
| 8369 | ? static_cast<media::UserInputMonitorBase*>( |
| 8370 | BrowserMainLoop::GetInstance()->user_input_monitor()) |
| 8371 | : nullptr, |
Ken Rockot | 7296440 | 2019-12-06 10:40:51 | [diff] [blame] | 8372 | AudioStreamBrokerFactory::CreateImpl()); |
Max Morin | 5bc74f5 | 2018-05-09 07:00:21 | [diff] [blame] | 8373 | } |
| 8374 | |
| 8375 | return &*audio_stream_factory_; |
| 8376 | } |
| 8377 | |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 8378 | void WebContentsImpl::MediaStartedPlaying( |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 8379 | const WebContentsObserver::MediaPlayerInfo& media_info, |
Mounir Lamouri | 0f5bdf5 | 2019-04-04 16:32:35 | [diff] [blame] | 8380 | const MediaPlayerId& id) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8381 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::MediaStartedPlaying"); |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 8382 | if (media_info.has_video) |
| 8383 | currently_playing_video_count_++; |
| 8384 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 8385 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 8386 | observer->MediaStartedPlaying(media_info, id); |
| 8387 | }); |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 8388 | } |
| 8389 | |
| 8390 | void WebContentsImpl::MediaStoppedPlaying( |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 8391 | const WebContentsObserver::MediaPlayerInfo& media_info, |
Mounir Lamouri | 0f5bdf5 | 2019-04-04 16:32:35 | [diff] [blame] | 8392 | const MediaPlayerId& id, |
Becca Hughes | 220bfc10 | 2017-11-14 18:24:07 | [diff] [blame] | 8393 | WebContentsObserver::MediaStoppedReason reason) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8394 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::MediaStoppedPlaying"); |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 8395 | if (media_info.has_video) |
| 8396 | currently_playing_video_count_--; |
| 8397 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 8398 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 8399 | observer->MediaStoppedPlaying(media_info, id, reason); |
| 8400 | }); |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 8401 | } |
| 8402 | |
Mounir Lamouri | 0f5bdf5 | 2019-04-04 16:32:35 | [diff] [blame] | 8403 | void WebContentsImpl::MediaResized(const gfx::Size& size, |
| 8404 | const MediaPlayerId& id) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8405 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::MediaResized"); |
peconn | 25795152 | 2017-06-09 18:24:59 | [diff] [blame] | 8406 | cached_video_sizes_[id] = size; |
| 8407 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 8408 | observers_.ForEachObserver( |
| 8409 | [&](WebContentsObserver* observer) { observer->MediaResized(size, id); }); |
peconn | 25795152 | 2017-06-09 18:24:59 | [diff] [blame] | 8410 | } |
| 8411 | |
Michael Crouse | e75c7a4 | 2020-07-31 21:11:55 | [diff] [blame] | 8412 | void WebContentsImpl::MediaBufferUnderflow(const MediaPlayerId& id) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8413 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::MediaBufferUnderflow"); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 8414 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 8415 | observer->MediaBufferUnderflow(id); |
| 8416 | }); |
Michael Crouse | e75c7a4 | 2020-07-31 21:11:55 | [diff] [blame] | 8417 | } |
| 8418 | |
rajendrant | 4c28846 | 2020-10-13 07:35:35 | [diff] [blame] | 8419 | void WebContentsImpl::MediaPlayerSeek(const MediaPlayerId& id) { |
| 8420 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::MediaPlayerSeek"); |
| 8421 | observers_.ForEachObserver( |
| 8422 | [&](WebContentsObserver* observer) { observer->MediaPlayerSeek(id); }); |
| 8423 | } |
| 8424 | |
Peter E Conn | eccb34c2 | 2017-09-08 09:37:58 | [diff] [blame] | 8425 | void WebContentsImpl::MediaEffectivelyFullscreenChanged(bool is_fullscreen) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8426 | OPTIONAL_TRACE_EVENT1("content", |
| 8427 | "WebContentsImpl::MediaEffectivelyFullscreenChanged", |
| 8428 | "is_fullscreen", is_fullscreen); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 8429 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 8430 | observer->MediaEffectivelyFullscreenChanged(is_fullscreen); |
| 8431 | }); |
Peter E Conn | eccb34c2 | 2017-09-08 09:37:58 | [diff] [blame] | 8432 | } |
| 8433 | |
Peter Conn | 31c726a | 2017-08-17 11:07:34 | [diff] [blame] | 8434 | base::Optional<gfx::Size> WebContentsImpl::GetFullscreenVideoSize() { |
Mounir Lamouri | 0f5bdf5 | 2019-04-04 16:32:35 | [diff] [blame] | 8435 | base::Optional<MediaPlayerId> id = |
Peter Conn | 31c726a | 2017-08-17 11:07:34 | [diff] [blame] | 8436 | media_web_contents_observer_->GetFullscreenVideoMediaPlayerId(); |
Jan Wilken Dörrie | 531be7ca | 2019-06-07 10:05:57 | [diff] [blame] | 8437 | if (id && base::Contains(cached_video_sizes_, id.value())) |
Peter Conn | 31c726a | 2017-08-17 11:07:34 | [diff] [blame] | 8438 | return base::Optional<gfx::Size>(cached_video_sizes_[id.value()]); |
Lei Zhang | 6410ec1a | 2019-01-31 21:38:58 | [diff] [blame] | 8439 | return base::nullopt; |
peconn | 25795152 | 2017-06-09 18:24:59 | [diff] [blame] | 8440 | } |
| 8441 | |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 8442 | int WebContentsImpl::GetCurrentlyPlayingVideoCount() { |
| 8443 | return currently_playing_video_count_; |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 8444 | } |
| 8445 | |
Raymond Toy | e413650c | 2018-08-31 00:12:47 | [diff] [blame] | 8446 | void WebContentsImpl::AudioContextPlaybackStarted(RenderFrameHost* host, |
| 8447 | int context_id) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8448 | OPTIONAL_TRACE_EVENT1( |
| 8449 | "content", "WebContentsImpl::AudioContextPlaybackStarted", |
| 8450 | "render_frame_host", base::trace_event::ToTracedValue(host)); |
Raymond Toy | e413650c | 2018-08-31 00:12:47 | [diff] [blame] | 8451 | WebContentsObserver::AudioContextId audio_context_id(host, context_id); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 8452 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 8453 | observer->AudioContextPlaybackStarted(audio_context_id); |
| 8454 | }); |
Raymond Toy | e413650c | 2018-08-31 00:12:47 | [diff] [blame] | 8455 | } |
| 8456 | |
| 8457 | void WebContentsImpl::AudioContextPlaybackStopped(RenderFrameHost* host, |
| 8458 | int context_id) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8459 | OPTIONAL_TRACE_EVENT1( |
| 8460 | "content", "WebContentsImpl::AudioContextPlaybackStopped", |
| 8461 | "render_frame_host", base::trace_event::ToTracedValue(host)); |
Raymond Toy | e413650c | 2018-08-31 00:12:47 | [diff] [blame] | 8462 | WebContentsObserver::AudioContextId audio_context_id(host, context_id); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 8463 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 8464 | observer->AudioContextPlaybackStopped(audio_context_id); |
| 8465 | }); |
Raymond Toy | e413650c | 2018-08-31 00:12:47 | [diff] [blame] | 8466 | } |
| 8467 | |
Chris Hamilton | 16ca64a | 2020-05-14 23:13:17 | [diff] [blame] | 8468 | void WebContentsImpl::OnFrameAudioStateChanged(RenderFrameHost* host, |
| 8469 | bool is_audible) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8470 | OPTIONAL_TRACE_EVENT2("content", "WebContentsImpl::OnFrameAudioStateChanged", |
| 8471 | "render_frame_host", |
| 8472 | base::trace_event::ToTracedValue(host), "is_audible", |
| 8473 | is_audible); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 8474 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 8475 | observer->OnFrameAudioStateChanged(host, is_audible); |
| 8476 | }); |
Chris Hamilton | 16ca64a | 2020-05-14 23:13:17 | [diff] [blame] | 8477 | } |
| 8478 | |
evliu | 7f736f0 | 2019-11-07 17:43:50 | [diff] [blame] | 8479 | media::MediaMetricsProvider::RecordAggregateWatchTimeCallback |
| 8480 | WebContentsImpl::GetRecordAggregateWatchTimeCallback() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8481 | OPTIONAL_TRACE_EVENT0("content", |
| 8482 | "WebContentsImpl::RecordAggregateWatchTimeCallback"); |
Becca Hughes | 5365244 | 2020-03-17 15:35:42 | [diff] [blame] | 8483 | if (!delegate_ || !delegate_->GetDelegateWeakPtr()) |
| 8484 | return base::DoNothing(); |
| 8485 | |
evliu | 7f736f0 | 2019-11-07 17:43:50 | [diff] [blame] | 8486 | return base::BindRepeating( |
Becca Hughes | 5365244 | 2020-03-17 15:35:42 | [diff] [blame] | 8487 | [](base::WeakPtr<WebContentsDelegate> delegate, GURL last_committed_url, |
| 8488 | base::TimeDelta total_watch_time, base::TimeDelta time_stamp, |
| 8489 | bool has_video, bool has_audio) { |
evliu | a283c9e | 2019-11-08 22:57:22 | [diff] [blame] | 8490 | content::MediaPlayerWatchTime watch_time( |
| 8491 | last_committed_url, last_committed_url.GetOrigin(), |
| 8492 | total_watch_time, time_stamp, has_video, has_audio); |
evliu | 7f736f0 | 2019-11-07 17:43:50 | [diff] [blame] | 8493 | |
| 8494 | // Save the watch time if the delegate is still alive. |
| 8495 | if (delegate) |
| 8496 | delegate->MediaWatchTimeChanged(watch_time); |
| 8497 | }, |
Becca Hughes | 5365244 | 2020-03-17 15:35:42 | [diff] [blame] | 8498 | delegate_->GetDelegateWeakPtr(), GetMainFrameLastCommittedURL()); |
evliu | 7f736f0 | 2019-11-07 17:43:50 | [diff] [blame] | 8499 | } |
| 8500 | |
Ehsan Karamad | 1c63176 | 2019-05-13 23:04:01 | [diff] [blame] | 8501 | RenderFrameHostImpl* WebContentsImpl::GetMainFrameForInnerDelegate( |
| 8502 | FrameTreeNode* frame_tree_node) { |
| 8503 | if (auto* web_contents = node_.GetInnerWebContentsInFrame(frame_tree_node)) |
| 8504 | return web_contents->GetMainFrame(); |
| 8505 | return nullptr; |
| 8506 | } |
| 8507 | |
John Budorick | ee1c951 | 2019-10-17 15:32:19 | [diff] [blame] | 8508 | bool WebContentsImpl::IsFrameLowPriority( |
| 8509 | const RenderFrameHost* render_frame_host) { |
| 8510 | if (!delegate_) |
| 8511 | return false; |
| 8512 | return delegate_->IsFrameLowPriority(this, render_frame_host); |
| 8513 | } |
| 8514 | |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 8515 | void WebContentsImpl::IsClipboardPasteAllowed( |
| 8516 | const GURL& url, |
| 8517 | const ui::ClipboardFormatType& data_type, |
| 8518 | const std::string& data, |
| 8519 | IsClipboardPasteAllowedCallback callback) { |
Dominique Fauteux-Chapleau | 9924438 | 2020-07-08 20:37:00 | [diff] [blame] | 8520 | ++suppress_unresponsive_renderer_count_; |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 8521 | GetContentClient()->browser()->IsClipboardPasteAllowed( |
Dominique Fauteux-Chapleau | 9924438 | 2020-07-08 20:37:00 | [diff] [blame] | 8522 | this, url, data_type, data, |
| 8523 | base::BindOnce(&WebContentsImpl::IsClipboardPasteAllowedWrapperCallback, |
| 8524 | weak_factory_.GetWeakPtr(), std::move(callback))); |
| 8525 | } |
| 8526 | |
| 8527 | void WebContentsImpl::IsClipboardPasteAllowedWrapperCallback( |
| 8528 | IsClipboardPasteAllowedCallback callback, |
| 8529 | ClipboardPasteAllowed allowed) { |
| 8530 | std::move(callback).Run(allowed); |
| 8531 | --suppress_unresponsive_renderer_count_; |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 8532 | } |
| 8533 | |
Lan Wei | f81c6e7c | 2020-02-12 16:46:09 | [diff] [blame] | 8534 | bool WebContentsImpl::HasSeenRecentScreenOrientationChange() { |
| 8535 | static constexpr base::TimeDelta kMaxInterval = |
| 8536 | base::TimeDelta::FromSeconds(1); |
| 8537 | base::TimeDelta delta = |
| 8538 | ui::EventTimeForNow() - last_screen_orientation_change_time_; |
Mike Wasserman | db8f4f0 | 2020-10-06 01:18:37 | [diff] [blame] | 8539 | // Return whether a screen orientation change happened in the last 1 second. |
Lan Wei | f81c6e7c | 2020-02-12 16:46:09 | [diff] [blame] | 8540 | return delta <= kMaxInterval; |
| 8541 | } |
| 8542 | |
Mike Wasserman | db8f4f0 | 2020-10-06 01:18:37 | [diff] [blame] | 8543 | bool WebContentsImpl::IsTransientAllowFullscreenActive() const { |
| 8544 | return transient_allow_fullscreen_.IsActive(); |
| 8545 | } |
| 8546 | |
Lan Wei | f81c6e7c | 2020-02-12 16:46:09 | [diff] [blame] | 8547 | void WebContentsImpl::DidChangeScreenOrientation() { |
| 8548 | last_screen_orientation_change_time_ = ui::EventTimeForNow(); |
| 8549 | } |
| 8550 | |
Miyoung Shin | 8f2e183 | 2020-04-27 09:00:02 | [diff] [blame] | 8551 | bool WebContentsImpl::ShowPopupMenu( |
Miyoung Shin | 4d947d2 | 2020-04-24 04:48:33 | [diff] [blame] | 8552 | RenderFrameHostImpl* render_frame_host, |
Miyoung Shin | 8f2e183 | 2020-04-27 09:00:02 | [diff] [blame] | 8553 | mojo::PendingRemote<blink::mojom::PopupMenuClient>* popup_client, |
Miyoung Shin | 4d947d2 | 2020-04-24 04:48:33 | [diff] [blame] | 8554 | const gfx::Rect& bounds, |
| 8555 | int32_t item_height, |
| 8556 | double font_size, |
| 8557 | int32_t selected_item, |
| 8558 | std::vector<blink::mojom::MenuItemPtr>* menu_items, |
| 8559 | bool right_aligned, |
| 8560 | bool allow_multiple_selection) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8561 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::ShowPopupMenu", |
| 8562 | "render_frame_host", |
| 8563 | base::trace_event::ToTracedValue(render_frame_host)); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 8564 | for (auto& observer : observers_.observer_list()) { |
Miyoung Shin | 8f2e183 | 2020-04-27 09:00:02 | [diff] [blame] | 8565 | if (observer.ShowPopupMenu(render_frame_host, popup_client, bounds, |
| 8566 | item_height, font_size, selected_item, |
| 8567 | menu_items, right_aligned, |
| 8568 | allow_multiple_selection)) { |
Miyoung Shin | 4d947d2 | 2020-04-24 04:48:33 | [diff] [blame] | 8569 | return true; |
| 8570 | } |
| 8571 | } |
| 8572 | return false; |
| 8573 | } |
| 8574 | |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 8575 | void WebContentsImpl::UpdateWebContentsVisibility(Visibility visibility) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8576 | OPTIONAL_TRACE_EVENT1("content", |
| 8577 | "WebContentsImpl::UpdateWebContentsVisibility", |
| 8578 | "visibility", visibility); |
Francois Doray | 3f2afbd | 2018-04-06 19:18:18 | [diff] [blame] | 8579 | // Occlusion is disabled when |features::kWebContentsOcclusion| is disabled |
| 8580 | // (for power and speed impact assessment) or when |
| 8581 | // |switches::kDisableBackgroundingOccludedWindowsForTesting| is specified on |
| 8582 | // the command line (to avoid flakiness in browser tests). |
| 8583 | const bool occlusion_is_disabled = |
| 8584 | !base::FeatureList::IsEnabled(features::kWebContentsOcclusion) || |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 8585 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 8586 | switches::kDisableBackgroundingOccludedWindowsForTesting); |
| 8587 | if (occlusion_is_disabled && visibility == Visibility::OCCLUDED) |
| 8588 | visibility = Visibility::VISIBLE; |
| 8589 | |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 8590 | if (!did_first_set_visible_) { |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 8591 | if (visibility == Visibility::VISIBLE) { |
| 8592 | // A WebContents created with CreateParams::initially_hidden = false |
| 8593 | // starts with GetVisibility() == Visibility::VISIBLE even though it is |
| 8594 | // not really visible. Call WasShown() when it becomes visible for real as |
| 8595 | // the page load mechanism and some WebContentsObserver rely on that. |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 8596 | WasShown(); |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 8597 | did_first_set_visible_ = true; |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 8598 | } |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 8599 | |
| 8600 | // Trust the initial visibility of the WebContents and do not switch it to |
| 8601 | // HIDDEN or OCCLUDED before it becomes VISIBLE for real. Doing so would |
| 8602 | // result in destroying resources that would immediately be recreated (e.g. |
| 8603 | // UpdateWebContents(HIDDEN) can be called when a WebContents is added to a |
| 8604 | // hidden window that is about to be shown). |
| 8605 | |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 8606 | return; |
| 8607 | } |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 8608 | |
| 8609 | if (visibility == visibility_) |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 8610 | return; |
| 8611 | |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 8612 | UpdateVisibilityAndNotifyPageAndView(visibility); |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 8613 | } |
| 8614 | |
aelias | 5252baa | 2016-04-10 01:18:02 | [diff] [blame] | 8615 | void WebContentsImpl::UpdateOverridingUserAgent() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8616 | OPTIONAL_TRACE_EVENT0("content", |
| 8617 | "WebContentsImpl::UpdateOverridingUserAgent"); |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 8618 | NotifyPreferencesChanged(); |
aelias | 5252baa | 2016-04-10 01:18:02 | [diff] [blame] | 8619 | } |
| 8620 | |
avi | d53461d | 2016-02-25 17:15:04 | [diff] [blame] | 8621 | void WebContentsImpl::SetJavaScriptDialogManagerForTesting( |
| 8622 | JavaScriptDialogManager* dialog_manager) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8623 | OPTIONAL_TRACE_EVENT0( |
| 8624 | "content", "WebContentsImpl::SetJavaScriptDialogManagerForTesting"); |
avi | d53461d | 2016-02-25 17:15:04 | [diff] [blame] | 8625 | dialog_manager_ = dialog_manager; |
| 8626 | } |
| 8627 | |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 8628 | void WebContentsImpl::RemoveReceiverSet(const std::string& interface_name) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8629 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::RemoveReceiverSet", |
| 8630 | "interface_name", interface_name); |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 8631 | auto it = receiver_sets_.find(interface_name); |
| 8632 | if (it != receiver_sets_.end()) |
| 8633 | receiver_sets_.erase(it); |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 8634 | } |
| 8635 | |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 8636 | bool WebContentsImpl::AddDomainInfoToRapporSample(rappor::Sample* sample) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8637 | OPTIONAL_TRACE_EVENT0("content", |
| 8638 | "WebContentsImpl::AddDomainInfoToRapporSample"); |
nzolghadr | bbffc6c | 2017-05-25 17:56:39 | [diff] [blame] | 8639 | // Here we associate this metric to the main frame URL regardless of what |
| 8640 | // caused it. |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 8641 | sample->SetStringField("Domain", ::rappor::GetDomainAndRegistrySampleFromGURL( |
| 8642 | GetLastCommittedURL())); |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 8643 | return true; |
| 8644 | } |
| 8645 | |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 8646 | void WebContentsImpl::ShowInsecureLocalhostWarningIfNeeded() { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8647 | OPTIONAL_TRACE_EVENT0( |
| 8648 | "content", "WebContentsImpl::ShowInsecureLocalhostWarningIfNeeded"); |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 8649 | bool allow_localhost = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 8650 | switches::kAllowInsecureLocalhost); |
| 8651 | if (!allow_localhost) |
| 8652 | return; |
| 8653 | |
| 8654 | content::NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
Rob Wu | f79b3ba | 2018-01-14 01:54:31 | [diff] [blame] | 8655 | if (!entry || !net::IsLocalhost(entry->GetURL())) |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 8656 | return; |
| 8657 | |
| 8658 | content::SSLStatus ssl_status = entry->GetSSL(); |
Matt Mueller | 93651144 | 2019-09-03 18:15:12 | [diff] [blame] | 8659 | if (!net::IsCertStatusError(ssl_status.cert_status)) |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 8660 | return; |
| 8661 | |
| 8662 | GetMainFrame()->AddMessageToConsole( |
Abhijeet Kandalkar | a5928a0a | 2019-03-13 05:04:42 | [diff] [blame] | 8663 | blink::mojom::ConsoleMessageLevel::kWarning, |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 8664 | base::StringPrintf("This site does not have a valid SSL " |
| 8665 | "certificate! Without SSL, your site's and " |
| 8666 | "visitors' data is vulnerable to theft and " |
| 8667 | "tampering. Get a valid SSL certificate before" |
| 8668 | " releasing your website to the public.")); |
| 8669 | } |
| 8670 | |
ekaramad | f6750aa | 2017-06-06 18:29:42 | [diff] [blame] | 8671 | bool WebContentsImpl::IsShowingContextMenuOnPage() const { |
| 8672 | return showing_context_menu_; |
| 8673 | } |
| 8674 | |
Min Qin | a904f330 | 2018-02-13 23:33:34 | [diff] [blame] | 8675 | download::DownloadUrlParameters::RequestHeadersType |
| 8676 | WebContentsImpl::ParseDownloadHeaders(const std::string& headers) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8677 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::ParseDownloadHeaders", |
| 8678 | "headers", headers); |
Min Qin | a904f330 | 2018-02-13 23:33:34 | [diff] [blame] | 8679 | download::DownloadUrlParameters::RequestHeadersType request_headers; |
Megan Jablonski | 2f6a4c5 | 2017-07-10 23:01:25 | [diff] [blame] | 8680 | for (const base::StringPiece& key_value : base::SplitStringPiece( |
| 8681 | headers, "\r\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { |
| 8682 | std::vector<std::string> pair = base::SplitString( |
| 8683 | key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 8684 | if (2ul == pair.size()) |
| 8685 | request_headers.push_back(make_pair(pair[0], pair[1])); |
| 8686 | } |
| 8687 | return request_headers; |
| 8688 | } |
| 8689 | |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 8690 | void WebContentsImpl::SetOpenerForNewContents(FrameTreeNode* opener, |
| 8691 | bool opener_suppressed) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8692 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::SetOpenerForNewContents"); |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 8693 | if (opener) { |
| 8694 | FrameTreeNode* new_root = GetFrameTree()->root(); |
| 8695 | |
| 8696 | // For the "original opener", track the opener's main frame instead, because |
| 8697 | // if the opener is a subframe, the opener tracking could be easily bypassed |
| 8698 | // by spawning from a subframe and deleting the subframe. |
| 8699 | // https://crbug.com/705316 |
| 8700 | new_root->SetOriginalOpener(opener->frame_tree()->root()); |
Wolfgang Beyer | d8809db | 2020-09-30 15:29:39 | [diff] [blame] | 8701 | new_root->SetOpenerDevtoolsFrameToken(opener->devtools_frame_token()); |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 8702 | |
| 8703 | if (!opener_suppressed) { |
| 8704 | new_root->SetOpener(opener); |
| 8705 | created_with_opener_ = true; |
| 8706 | } |
| 8707 | } |
| 8708 | } |
| 8709 | |
Mounir Lamouri | 0f5bdf5 | 2019-04-04 16:32:35 | [diff] [blame] | 8710 | void WebContentsImpl::MediaMutedStatusChanged(const MediaPlayerId& id, |
| 8711 | bool muted) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8712 | OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::MediaMutedStatusChanged", |
| 8713 | "muted", muted); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame] | 8714 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 8715 | observer->MediaMutedStatusChanged(id, muted); |
| 8716 | }); |
Becca Hughes | 9f6fd4b8 | 2017-06-15 10:01:40 | [diff] [blame] | 8717 | } |
| 8718 | |
EhsanK | 2075c7e | 2017-08-21 02:42:39 | [diff] [blame] | 8719 | void WebContentsImpl::SetVisibilityForChildViews(bool visible) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8720 | OPTIONAL_TRACE_EVENT1("content", |
| 8721 | "WebContentsImpl::SetVisibilityForChildViews", |
| 8722 | "visible", visible); |
EhsanK | 2075c7e | 2017-08-21 02:42:39 | [diff] [blame] | 8723 | GetMainFrame()->SetVisibilityForChildViews(visible); |
| 8724 | } |
| 8725 | |
Alison Maher | 7f366dc6 | 2020-03-03 19:46:00 | [diff] [blame] | 8726 | void WebContentsImpl::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8727 | OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::OnNativeThemeUpdated"); |
Alison Maher | 7f366dc6 | 2020-03-03 19:46:00 | [diff] [blame] | 8728 | DCHECK(native_theme_observer_.IsObserving(observed_theme)); |
| 8729 | |
| 8730 | bool using_dark_colors = observed_theme->ShouldUseDarkColors(); |
| 8731 | ui::NativeTheme::PreferredColorScheme preferred_color_scheme = |
| 8732 | observed_theme->GetPreferredColorScheme(); |
| 8733 | bool preferences_changed = false; |
| 8734 | |
| 8735 | if (using_dark_colors_ != using_dark_colors) { |
| 8736 | using_dark_colors_ = using_dark_colors; |
| 8737 | preferences_changed = true; |
| 8738 | } |
| 8739 | if (preferred_color_scheme_ != preferred_color_scheme) { |
| 8740 | preferred_color_scheme_ = preferred_color_scheme; |
| 8741 | preferences_changed = true; |
| 8742 | } |
| 8743 | |
| 8744 | if (preferences_changed) |
| 8745 | NotifyPreferencesChanged(); |
| 8746 | } |
| 8747 | |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 8748 | blink::mojom::FrameWidgetInputHandler* |
| 8749 | WebContentsImpl::GetFocusedFrameWidgetInputHandler() { |
| 8750 | auto* focused_render_widget_host = |
| 8751 | GetFocusedRenderWidgetHost(GetMainFrame()->GetRenderWidgetHost()); |
| 8752 | if (!focused_render_widget_host) |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 8753 | return nullptr; |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 8754 | return focused_render_widget_host->GetFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 8755 | } |
| 8756 | |
Alexander Timin | e3ec419 | 2020-04-20 16:39:40 | [diff] [blame] | 8757 | ukm::SourceId WebContentsImpl::GetCurrentPageUkmSourceId() { |
| 8758 | return GetMainFrame()->GetPageUkmSourceId(); |
| 8759 | } |
| 8760 | |
Yuzu Saijo | 232076f | 2020-05-29 07:14:02 | [diff] [blame] | 8761 | std::set<RenderViewHostImpl*> |
| 8762 | WebContentsImpl::GetRenderViewHostsIncludingBackForwardCached() { |
| 8763 | std::set<RenderViewHostImpl*> render_view_hosts; |
| 8764 | |
| 8765 | // Add RenderViewHostImpls outside of BackForwardCache. |
| 8766 | for (auto& render_view_host : frame_tree_.render_view_hosts()) { |
| 8767 | render_view_hosts.insert(render_view_host.second); |
| 8768 | } |
| 8769 | |
| 8770 | // Add RenderViewHostImpls in BackForwardCache. |
| 8771 | const auto& entries = GetController().GetBackForwardCache().GetEntries(); |
| 8772 | for (const auto& entry : entries) { |
| 8773 | std::set<RenderViewHostImpl*> bfcached_hosts = entry->render_view_hosts; |
| 8774 | render_view_hosts.insert(bfcached_hosts.begin(), bfcached_hosts.end()); |
| 8775 | } |
| 8776 | |
| 8777 | return render_view_hosts; |
| 8778 | } |
| 8779 | |
Sreeja Kamishetty | be0ccd6b | 2020-06-09 11:52:50 | [diff] [blame] | 8780 | void WebContentsImpl::RenderFrameHostStateChanged( |
| 8781 | RenderFrameHost* render_frame_host, |
| 8782 | LifecycleState old_state, |
| 8783 | LifecycleState new_state) { |
Alexander Timin | 5fdeff2 | 2020-09-08 09:20:37 | [diff] [blame] | 8784 | OPTIONAL_TRACE_EVENT2( |
| 8785 | "content", "WebContentsImpl::RenderFrameHostStateChanged", |
| 8786 | "render_frame_host", base::trace_event::ToTracedValue(render_frame_host), |
| 8787 | "states", |
| 8788 | base::trace_event::TracedValue::Build( |
| 8789 | {{"old", base::trace_event::ValueToString(old_state)}, |
| 8790 | {"new", base::trace_event::ValueToString(new_state)}})); |
Sreeja Kamishetty | be0ccd6b | 2020-06-09 11:52:50 | [diff] [blame] | 8791 | if (render_frame_host->GetParent()) |
| 8792 | return; |
| 8793 | |
| 8794 | if (old_state == LifecycleState::kActive && |
| 8795 | new_state != LifecycleState::kActive) { |
| 8796 | // TODO(sreejakshetty): Remove this reset when ColorChooser becomes |
| 8797 | // per-frame. |
| 8798 | // Close the color chooser popup when RenderFrameHost changes state from |
| 8799 | // kActive. |
| 8800 | color_chooser_.reset(); |
| 8801 | } |
| 8802 | } |
| 8803 | |
danakj | c5ce6760 | 2020-09-23 20:06:57 | [diff] [blame] | 8804 | void WebContentsImpl::GetFrameSequenceNumbersForDebugging( |
| 8805 | RenderFrameHostImpl* render_frame_host, |
| 8806 | int64_t& item_sequence_number, |
| 8807 | int64_t& document_sequence_number) { |
| 8808 | NavigationEntryImpl* entry = |
| 8809 | controller_.GetEntryWithUniqueID(render_frame_host->nav_entry_id()); |
| 8810 | if (!entry) |
| 8811 | return; |
| 8812 | |
| 8813 | FrameNavigationEntry* frame_entry = |
| 8814 | entry->GetFrameEntry(render_frame_host->frame_tree_node()); |
| 8815 | if (frame_entry) { |
| 8816 | item_sequence_number = frame_entry->item_sequence_number(); |
| 8817 | document_sequence_number = frame_entry->document_sequence_number(); |
| 8818 | } |
| 8819 | } |
| 8820 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 8821 | } // namespace content |