[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> |
[email protected] | 2bb17188 | 2012-03-07 02:09:46 | [diff] [blame] | 11 | #include <utility> |
rkaplow | e56a5203 | 2017-02-07 00:14:54 | [diff] [blame] | 12 | #include <vector> |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 13 | |
Sebastien Marchand | f8cbfab | 2019-01-25 16:02:30 | [diff] [blame] | 14 | #include "base/bind.h" |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 15 | #include "base/command_line.h" |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 16 | #include "base/containers/flat_set.h" |
creis | fafed88 | 2016-07-29 00:03:09 | [diff] [blame] | 17 | #include "base/debug/dump_without_crashing.h" |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 18 | #include "base/feature_list.h" |
Marijn Kruisselbrink | 46fa4bd | 2019-07-11 18:15:47 | [diff] [blame] | 19 | #include "base/files/file_path.h" |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 20 | #include "base/lazy_instance.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 21 | #include "base/location.h" |
[email protected] | 6d636e6 | 2013-07-31 03:15:56 | [diff] [blame] | 22 | #include "base/logging.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 23 | #include "base/macros.h" |
fdoray | ba12142 | 2016-12-23 19:51:48 | [diff] [blame] | 24 | #include "base/memory/ptr_util.h" |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 25 | #include "base/memory/ref_counted.h" |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 26 | #include "base/metrics/field_trial.h" |
asvitkine | 8d51e9d | 2016-09-02 23:55:43 | [diff] [blame] | 27 | #include "base/metrics/histogram_macros.h" |
bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 28 | #include "base/metrics/user_metrics.h" |
Avi Drissman | 4891b85 | 2018-09-25 18:12:58 | [diff] [blame] | 29 | #include "base/no_destructor.h" |
Carlos Caballero | 1215f88 | 2019-10-29 15:58:43 | [diff] [blame] | 30 | #include "base/optional.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 31 | #include "base/process/process.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 32 | #include "base/single_thread_task_runner.h" |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 33 | #include "base/stl_util.h" |
[email protected] | 348fbaac | 2013-06-11 06:31:51 | [diff] [blame] | 34 | #include "base/strings/string16.h" |
| 35 | #include "base/strings/string_number_conversions.h" |
Avi Drissman | 4891b85 | 2018-09-25 18:12:58 | [diff] [blame] | 36 | #include "base/strings/string_split.h" |
[email protected] | 348fbaac | 2013-06-11 06:31:51 | [diff] [blame] | 37 | #include "base/strings/string_util.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 38 | #include "base/strings/utf_string_conversions.h" |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 39 | #include "base/system/sys_info.h" |
gab | 30f26df | 2016-05-11 19:37:55 | [diff] [blame] | 40 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | a43858f | 2013-06-28 15:18:37 | [diff] [blame] | 41 | #include "base/time/time.h" |
ssid | 3e76561 | 2015-01-28 04:03:42 | [diff] [blame] | 42 | #include "base/trace_event/trace_event.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 43 | #include "build/build_config.h" |
Darin Fisher | 6cf20e78 | 2020-08-07 22:25:36 | [diff] [blame] | 44 | #include "build/lacros_buildflags.h" |
Min Qin | da0ed206 | 2018-02-23 22:00:53 | [diff] [blame] | 45 | #include "components/download/public/common/download_stats.h" |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 46 | #include "components/rappor/public/rappor_utils.h" |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 47 | #include "components/url_formatter/url_formatter.h" |
Abigail Klein | aa89874 | 2019-11-01 02:31:25 | [diff] [blame] | 48 | #include "content/browser/accessibility/accessibility_event_recorder.h" |
James Wallace-Lee | eafc94cb9 | 2018-07-23 21:35:09 | [diff] [blame] | 49 | #include "content/browser/accessibility/accessibility_tree_formatter_blink.h" |
jamescook | da250581 | 2015-03-20 18:01:18 | [diff] [blame] | 50 | #include "content/browser/bad_message.h" |
Max Morin | ddebb97 | 2018-09-20 10:04:14 | [diff] [blame] | 51 | #include "content/browser/browser_main_loop.h" |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 52 | #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 53 | #include "content/browser/browser_plugin/browser_plugin_guest.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 54 | #include "content/browser/child_process_security_policy_impl.h" |
John Delaney | 732721e9 | 2020-02-07 23:11:27 | [diff] [blame] | 55 | #include "content/browser/conversions/conversion_host.h" |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 56 | #include "content/browser/devtools/protocol/page_handler.h" |
dgozman | f00c4f7 | 2016-10-19 17:45:15 | [diff] [blame] | 57 | #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
Becca Hughes | 3b5a4348 | 2018-07-17 22:31:55 | [diff] [blame] | 58 | #include "content/browser/display_cutout/display_cutout_host_impl.h" |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 59 | #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
[email protected] | 1ea3c79 | 2012-04-17 01:25:04 | [diff] [blame] | 60 | #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
[email protected] | aa4f397 | 2012-03-01 18:12:12 | [diff] [blame] | 61 | #include "content/browser/download/mhtml_generation_manager.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 62 | #include "content/browser/download/save_package.h" |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 63 | #include "content/browser/find_request_manager.h" |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 64 | #include "content/browser/frame_host/cross_process_frame_connector.h" |
ananta | 4b7467a5 | 2016-09-23 01:42:38 | [diff] [blame] | 65 | #include "content/browser/frame_host/frame_tree_node.h" |
[email protected] | d4a8ca48 | 2013-10-30 21:06:40 | [diff] [blame] | 66 | #include "content/browser/frame_host/navigation_entry_impl.h" |
Arthur Hemery | c338017 | 2018-01-22 14:00:17 | [diff] [blame] | 67 | #include "content/browser/frame_host/navigation_request.h" |
Hiroki Nakagawa | 080f86c | 2020-05-13 10:56:42 | [diff] [blame] | 68 | #include "content/browser/frame_host/navigator.h" |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 69 | #include "content/browser/frame_host/render_frame_host_impl.h" |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 70 | #include "content/browser/frame_host/render_frame_proxy_host.h" |
Kenneth Russell | 954ed9ce | 2018-04-12 23:07:01 | [diff] [blame] | 71 | #include "content/browser/gpu/gpu_data_manager_impl.h" |
mlamouri | efdca9d | 2014-09-16 16:55:40 | [diff] [blame] | 72 | #include "content/browser/manifest/manifest_manager_host.h" |
Max Morin | 5bc74f5 | 2018-05-09 07:00:21 | [diff] [blame] | 73 | #include "content/browser/media/audio_stream_broker.h" |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 74 | #include "content/browser/media/audio_stream_monitor.h" |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 75 | #include "content/browser/media/capture/web_contents_audio_muter.h" |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 76 | #include "content/browser/media/media_web_contents_observer.h" |
zqzhang | 1adf3cb | 2016-11-01 11:26:45 | [diff] [blame] | 77 | #include "content/browser/media/session/media_session_impl.h" |
Yuzu Saijo | a11069a | 2020-04-22 10:56:55 | [diff] [blame] | 78 | #include "content/browser/plugin_content_origin_allowlist.h" |
Kevin McNee | 94ea52f5 | 2020-06-23 17:42:06 | [diff] [blame] | 79 | #include "content/browser/portal/portal.h" |
David Black | 9cca359 | 2019-11-06 23:02:22 | [diff] [blame] | 80 | #include "content/browser/renderer_host/frame_token_message_queue.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 81 | #include "content/browser/renderer_host/render_process_host_impl.h" |
[email protected] | 2116103 | 2014-05-05 16:56:50 | [diff] [blame] | 82 | #include "content/browser/renderer_host/render_view_host_delegate_view.h" |
[email protected] | b3c41c0b | 2012-03-06 15:48:32 | [diff] [blame] | 83 | #include "content/browser/renderer_host/render_view_host_impl.h" |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 84 | #include "content/browser/renderer_host/render_widget_host_impl.h" |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 85 | #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 86 | #include "content/browser/renderer_host/render_widget_host_view_base.h" |
Ken Buchanan | daef006b | 2017-08-17 18:32:15 | [diff] [blame] | 87 | #include "content/browser/renderer_host/render_widget_host_view_child_frame.h" |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 88 | #include "content/browser/renderer_host/text_input_manager.h" |
Mike Wasserman | b213b935 | 2020-04-16 00:32:34 | [diff] [blame] | 89 | #include "content/browser/screen_enumeration/screen_change_monitor.h" |
leon.han | 552e9de | 2017-02-09 14:37:30 | [diff] [blame] | 90 | #include "content/browser/screen_orientation/screen_orientation_provider.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 91 | #include "content/browser/site_instance_impl.h" |
Charlie Reis | 9607736 | 2019-07-04 00:34:04 | [diff] [blame] | 92 | #include "content/browser/web_contents/javascript_dialog_navigation_deferrer.h" |
lfg | c740d4b2 | 2016-04-15 16:45:33 | [diff] [blame] | 93 | #include "content/browser/web_contents/web_contents_view_child_frame.h" |
Tsuyoshi Horo | b0d8d90 | 2020-03-12 00:09:39 | [diff] [blame] | 94 | #include "content/browser/web_package/save_as_web_bundle_job.h" |
[email protected] | 86a0a6e | 2013-01-28 06:33:03 | [diff] [blame] | 95 | #include "content/browser/webui/web_ui_controller_factory_registry.h" |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 96 | #include "content/browser/webui/web_ui_impl.h" |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 97 | #include "content/common/browser_plugin/browser_plugin_constants.h" |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 98 | #include "content/common/content_switches_internal.h" |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 99 | #include "content/common/drag_messages.h" |
[email protected] | f114fa4 | 2013-12-06 17:06:44 | [diff] [blame] | 100 | #include "content/common/frame_messages.h" |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 101 | #include "content/common/input_messages.h" |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 102 | #include "content/common/page_messages.h" |
nasko | 3463467 | 2016-07-29 18:46:06 | [diff] [blame] | 103 | #include "content/common/page_state_serialization.h" |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 104 | #include "content/common/render_message_filter.mojom.h" |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 105 | #include "content/common/view_messages.h" |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 106 | #include "content/common/widget_messages.h" |
Abigail Klein | abb42833 | 2019-09-13 18:26:21 | [diff] [blame] | 107 | #include "content/public/browser/accessibility_tree_formatter.h" |
[email protected] | 31a71eaf | 2014-03-13 01:47:36 | [diff] [blame] | 108 | #include "content/public/browser/ax_event_notification_details.h" |
[email protected] | ccb79730 | 2011-12-15 16:55:11 | [diff] [blame] | 109 | #include "content/public/browser/browser_context.h" |
[email protected] | 139355f | 2014-05-11 14:21:28 | [diff] [blame] | 110 | #include "content/public/browser/browser_plugin_guest_manager.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 111 | #include "content/public/browser/browser_task_traits.h" |
Gabriel Charette | 790754c | 2018-03-16 21:32:59 | [diff] [blame] | 112 | #include "content/public/browser/browser_thread.h" |
[email protected] | 87f3c08 | 2011-10-19 18:07:44 | [diff] [blame] | 113 | #include "content/public/browser/content_browser_client.h" |
Lukasz Anforowicz | 8c4446dc | 2020-03-11 22:16:42 | [diff] [blame] | 114 | #include "content/public/browser/context_menu_params.h" |
Ken Rockot | ce010f0 | 2019-12-12 23:32:32 | [diff] [blame] | 115 | #include "content/public/browser/device_service.h" |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 116 | #include "content/public/browser/download_manager.h" |
Kent Tamura | 512a27e | 2018-10-04 00:49:32 | [diff] [blame] | 117 | #include "content/public/browser/file_select_listener.h" |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 118 | #include "content/public/browser/focused_node_details.h" |
Danyao Wang | a78f3dd2 | 2020-03-05 05:31:27 | [diff] [blame] | 119 | #include "content/public/browser/global_routing_id.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 120 | #include "content/public/browser/invalidate_type.h" |
[email protected] | 71a88bb | 2013-02-01 22:05:15 | [diff] [blame] | 121 | #include "content/public/browser/javascript_dialog_manager.h" |
sky | f65d9bb | 2017-03-24 02:26:39 | [diff] [blame] | 122 | #include "content/public/browser/keyboard_event_processing_result.h" |
[email protected] | 09d31d5 | 2012-03-11 22:30:27 | [diff] [blame] | 123 | #include "content/public/browser/load_notification_details.h" |
[email protected] | 5b96836f | 2011-12-22 07:39:00 | [diff] [blame] | 124 | #include "content/public/browser/navigation_details.h" |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 125 | #include "content/public/browser/notification_details.h" |
[email protected] | be2510c0 | 2012-05-28 14:52:14 | [diff] [blame] | 126 | #include "content/public/browser/notification_service.h" |
scottmg | 011d96e3 | 2016-06-29 19:15:08 | [diff] [blame] | 127 | #include "content/public/browser/notification_types.h" |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 128 | #include "content/public/browser/render_widget_host_iterator.h" |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 129 | #include "content/public/browser/restore_type.h" |
estark | 5ea80e5 | 2015-06-19 18:43:12 | [diff] [blame] | 130 | #include "content/public/browser/security_style_explanations.h" |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 131 | #include "content/public/browser/ssl_status.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 132 | #include "content/public/browser/storage_partition.h" |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 133 | #include "content/public/browser/web_contents_delegate.h" |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 134 | #include "content/public/browser/web_contents_receiver_set.h" |
Lei Zhang | ee3b63ad | 2018-06-06 23:25:31 | [diff] [blame] | 135 | #include "content/public/browser/web_ui_controller.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 136 | #include "content/public/common/bindings_policy.h" |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 137 | #include "content/public/common/child_process_host.h" |
Hans Wennborg | 5ffd139 | 2019-10-16 11:00:02 | [diff] [blame] | 138 | #include "content/public/common/content_client.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 139 | #include "content/public/common/content_constants.h" |
Francois Doray | 3f2afbd | 2018-04-06 19:18:18 | [diff] [blame] | 140 | #include "content/public/common/content_features.h" |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 141 | #include "content/public/common/content_switches.h" |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 142 | #include "content/public/common/page_state.h" |
Leon Han | 963dc18 | 2018-11-06 05:41:48 | [diff] [blame] | 143 | #include "content/public/common/referrer_type_converters.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 144 | #include "content/public/common/result_codes.h" |
[email protected] | f16cc678 | 2013-12-16 23:42:57 | [diff] [blame] | 145 | #include "content/public/common/url_utils.h" |
danakj | ffc8baf | 2019-10-10 23:49:42 | [diff] [blame] | 146 | #include "content/public/common/use_zoom_for_dsf_policy.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 147 | #include "content/public/common/web_preferences.h" |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 148 | #include "media/base/media_switches.h" |
Max Morin | ddebb97 | 2018-09-20 10:04:14 | [diff] [blame] | 149 | #include "media/base/user_input_monitor.h" |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 150 | #include "net/base/url_util.h" |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 151 | #include "net/http/http_cache.h" |
| 152 | #include "net/http/http_transaction_factory.h" |
David Van Cleve | f9988163 | 2020-07-16 19:41:13 | [diff] [blame] | 153 | #include "net/http/http_util.h" |
rhalavati | 0fbaeef3 | 2017-06-01 15:56:30 | [diff] [blame] | 154 | #include "net/traffic_annotation/network_traffic_annotation.h" |
Scott Violet | 02e38b9 | 2018-03-27 23:42:14 | [diff] [blame] | 155 | #include "ppapi/buildflags/buildflags.h" |
Mounir Lamouri | fd9dcefa | 2017-07-06 10:26:55 | [diff] [blame] | 156 | #include "services/metrics/public/cpp/ukm_recorder.h" |
John Abd-El-Malek | b175a61 | 2018-12-03 20:11:58 | [diff] [blame] | 157 | #include "services/network/public/cpp/features.h" |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 158 | #include "services/network/public/cpp/web_sandbox_flags.h" |
| 159 | #include "services/network/public/mojom/web_sandbox_flags.mojom.h" |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 160 | #include "services/service_manager/public/cpp/interface_provider.h" |
Becca Hughes | 6daf566 | 2018-06-27 16:50:54 | [diff] [blame] | 161 | #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 162 | #include "third_party/blink/public/common/mime_util/mime_util.h" |
danakj | 938b37a6 | 2019-09-24 18:35:54 | [diff] [blame] | 163 | #include "third_party/blink/public/common/page/page_zoom.h" |
Sergio Villar Senin | 9d9d4f5 | 2019-10-15 10:57:57 | [diff] [blame] | 164 | #include "third_party/blink/public/common/security/security_style.h" |
Abhijeet Kandalkar | de7348e | 2020-01-13 06:06:54 | [diff] [blame] | 165 | #include "third_party/blink/public/mojom/frame/frame.mojom.h" |
Dave Tapuska | a418951 | 2019-10-15 20:27:34 | [diff] [blame] | 166 | #include "third_party/blink/public/mojom/frame/fullscreen.mojom.h" |
Takuto Ikuta | aa3b796c | 2019-02-06 02:54:56 | [diff] [blame] | 167 | #include "third_party/blink/public/mojom/loader/pause_subresource_loading_handle.mojom.h" |
Antonio Gomes | 0d42960a | 2019-06-05 12:35:51 | [diff] [blame] | 168 | #include "third_party/blink/public/mojom/mediastream/media_stream.mojom-shared.h" |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 169 | #include "third_party/skia/include/core/SkBitmap.h" |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 170 | #include "ui/accessibility/ax_tree_combiner.h" |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 171 | #include "ui/base/device_form_factor.h" |
Mugdha Lakhani | 0a0d786 | 2020-07-29 09:58:45 | [diff] [blame] | 172 | #if defined(USE_AURA) |
| 173 | #include "ui/aura/window.h" |
| 174 | #endif |
[email protected] | a08412b6 | 2012-05-29 21:28:56 | [diff] [blame] | 175 | #include "ui/base/layout.h" |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 176 | #include "ui/base/ui_base_features.h" |
| 177 | #include "ui/base/ui_base_switches.h" |
| 178 | #include "ui/display/screen.h" |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 179 | #include "ui/events/base_event_utils.h" |
chongz | 4a975194 | 2016-08-17 17:49:39 | [diff] [blame] | 180 | #include "ui/events/blink/web_input_event_traits.h" |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 181 | #include "ui/gfx/animation/animation.h" |
[email protected] | 66bd551 | 2012-08-01 02:02:52 | [diff] [blame] | 182 | #include "ui/gl/gl_switches.h" |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 183 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 184 | #if defined(OS_WIN) |
| 185 | #include "content/browser/renderer_host/dip_util.h" |
| 186 | #include "ui/gfx/geometry/dip_util.h" |
| 187 | #endif |
| 188 | |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 189 | #if defined(OS_ANDROID) |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 190 | #include "content/browser/android/date_time_chooser_android.h" |
sammc | f5f1b0f | 2016-09-20 23:05:11 | [diff] [blame] | 191 | #include "content/browser/android/java_interfaces_impl.h" |
Leon Han | ccb985f | 2019-08-26 02:43:24 | [diff] [blame] | 192 | #include "content/browser/android/nfc_host.h" |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 193 | #include "content/browser/web_contents/web_contents_android.h" |
Ke He | 31d0bb0 | 2018-02-24 07:16:24 | [diff] [blame] | 194 | #include "services/device/public/mojom/nfc.mojom.h" |
Mugdha Lakhani | 0a0d786 | 2020-07-29 09:58:45 | [diff] [blame] | 195 | #include "ui/android/view_android.h" |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 196 | #else // !OS_ANDROID |
| 197 | #include "content/browser/host_zoom_map_impl.h" |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 198 | #endif // OS_ANDROID |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 199 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 200 | #if BUILDFLAG(ENABLE_PLUGINS) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 201 | #include "content/browser/media/session/pepper_playback_observer.h" |
Lei Zhang | ebcc630 | 2018-01-12 19:46:45 | [diff] [blame] | 202 | #endif |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 203 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 204 | namespace content { |
Abigail Klein | aa89874 | 2019-11-01 02:31:25 | [diff] [blame] | 205 | |
| 206 | using AccessibilityEventCallback = |
| 207 | base::RepeatingCallback<void(const std::string&)>; |
| 208 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 209 | namespace { |
| 210 | |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 211 | const int kMinimumDelayBetweenLoadingUpdatesMS = 100; |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 212 | const char kDotGoogleDotCom[] = ".google.com"; |
[email protected] | ca40603 | 2011-07-19 21:53:05 | [diff] [blame] | 213 | |
Sreeja Kamishetty | be0ccd6b | 2020-06-09 11:52:50 | [diff] [blame] | 214 | using LifecycleState = RenderFrameHostImpl::LifecycleState; |
| 215 | |
Alexander Timin | 33bd754c0 | 2020-03-10 22:50:18 | [diff] [blame] | 216 | // TODO(crbug.com/1059903): Clean up after the initial investigation. |
| 217 | constexpr base::Feature kCheckWebContentsAccessFromNonCurrentFrame{ |
| 218 | "CheckWebContentsAccessFromNonCurrentFrame", |
| 219 | base::FEATURE_DISABLED_BY_DEFAULT}; |
| 220 | |
Avi Drissman | a911482 | 2018-03-23 18:25:55 | [diff] [blame] | 221 | base::LazyInstance<std::vector< |
| 222 | WebContentsImpl::FriendWrapper::CreatedCallback>>::DestructorAtExit |
| 223 | g_created_callbacks = LAZY_INSTANCE_INITIALIZER; |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 224 | |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 225 | bool HasMatchingProcess(FrameTree* tree, int render_process_id) { |
| 226 | for (FrameTreeNode* node : tree->Nodes()) { |
| 227 | if (node->current_frame_host()->GetProcess()->GetID() == render_process_id) |
| 228 | return true; |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 229 | } |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 230 | return false; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 231 | } |
| 232 | |
kenrb | 1922185 | 2016-04-29 17:21:40 | [diff] [blame] | 233 | bool HasMatchingWidgetHost(FrameTree* tree, RenderWidgetHost* host) { |
| 234 | // This method scans the frame tree rather than checking whether |
| 235 | // host->delegate() == this, which allows it to return false when the host |
| 236 | // for a frame that is pending or pending deletion. |
| 237 | if (!host) |
| 238 | return false; |
| 239 | |
| 240 | for (FrameTreeNode* node : tree->Nodes()) { |
| 241 | if (node->current_frame_host()->GetRenderWidgetHost() == host) |
| 242 | return true; |
| 243 | } |
| 244 | return false; |
| 245 | } |
| 246 | |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 247 | void UpdateAccessibilityModeOnFrame(RenderFrameHost* frame_host) { |
| 248 | static_cast<RenderFrameHostImpl*>(frame_host)->UpdateAccessibilityMode(); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 249 | } |
| 250 | |
dtseng | 0dd3fa1 | 2015-07-22 19:00:52 | [diff] [blame] | 251 | void ResetAccessibility(RenderFrameHost* rfh) { |
| 252 | static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset(); |
| 253 | } |
| 254 | |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 255 | RenderFrameHostImpl* FindOpenerRFH(const WebContents::CreateParams& params) { |
| 256 | RenderFrameHostImpl* opener_rfh = nullptr; |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 257 | if (params.opener_render_frame_id != MSG_ROUTING_NONE) { |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 258 | opener_rfh = RenderFrameHostImpl::FromID(params.opener_render_process_id, |
| 259 | params.opener_render_frame_id); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 260 | } |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 261 | return opener_rfh; |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 262 | } |
| 263 | |
Dominick Ng | 37a1505 | 2018-07-17 23:56:35 | [diff] [blame] | 264 | // Returns |true| if |type| is the kind of user input that should trigger the |
| 265 | // user interaction observers. |
| 266 | bool IsUserInteractionInputType(blink::WebInputEvent::Type type) { |
| 267 | // Ideally, this list would be based more off of |
| 268 | // https://whatwg.org/C/interaction.html#triggered-by-user-activation. |
Dave Tapuska | 347d60a | 2020-04-21 23:55:47 | [diff] [blame] | 269 | return type == blink::WebInputEvent::Type::kMouseDown || |
| 270 | type == blink::WebInputEvent::Type::kGestureScrollBegin || |
| 271 | type == blink::WebInputEvent::Type::kTouchStart || |
| 272 | type == blink::WebInputEvent::Type::kRawKeyDown; |
Dominick Ng | 37a1505 | 2018-07-17 23:56:35 | [diff] [blame] | 273 | } |
| 274 | |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 275 | // Ensures that OnDialogClosed is only called once. |
| 276 | class CloseDialogCallbackWrapper |
| 277 | : public base::RefCountedThreadSafe<CloseDialogCallbackWrapper> { |
| 278 | public: |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 279 | using CloseCallback = |
| 280 | base::OnceCallback<void(bool, bool, const base::string16&)>; |
| 281 | |
| 282 | explicit CloseDialogCallbackWrapper(CloseCallback callback) |
| 283 | : callback_(std::move(callback)) {} |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 284 | |
| 285 | void Run(bool dialog_was_suppressed, |
| 286 | bool success, |
| 287 | const base::string16& user_input) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 288 | if (callback_.is_null()) |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 289 | return; |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 290 | std::move(callback_).Run(dialog_was_suppressed, success, user_input); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | private: |
| 294 | friend class base::RefCountedThreadSafe<CloseDialogCallbackWrapper>; |
| 295 | ~CloseDialogCallbackWrapper() {} |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 296 | |
| 297 | CloseCallback callback_; |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 298 | }; |
| 299 | |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 300 | bool FrameCompareDepth(RenderFrameHostImpl* a, RenderFrameHostImpl* b) { |
| 301 | return a->frame_tree_node()->depth() < b->frame_tree_node()->depth(); |
| 302 | } |
| 303 | |
Raymes Khoury | 58373df | 2019-08-06 06:29:20 | [diff] [blame] | 304 | bool AreValidRegisterProtocolHandlerArguments(const std::string& protocol, |
| 305 | const GURL& url, |
| 306 | const url::Origin& origin) { |
| 307 | ChildProcessSecurityPolicyImpl* policy = |
| 308 | ChildProcessSecurityPolicyImpl::GetInstance(); |
| 309 | if (policy->IsPseudoScheme(protocol)) |
| 310 | return false; |
| 311 | |
| 312 | url::Origin url_origin = url::Origin::Create(url); |
| 313 | if (url_origin.opaque()) |
| 314 | return false; |
| 315 | |
| 316 | if (!url_origin.IsSameOriginWith(origin)) |
| 317 | return false; |
| 318 | |
| 319 | return true; |
| 320 | } |
| 321 | |
yilkal | 796e89e | 2019-10-02 23:58:28 | [diff] [blame] | 322 | void RecordMaxFrameCountUMA(size_t max_frame_count) { |
| 323 | UMA_HISTOGRAM_COUNTS_10000("Navigation.MainFrame.MaxFrameCount", |
| 324 | max_frame_count); |
| 325 | } |
| 326 | |
Jeremy Roman | 03ce13ce | 2020-05-29 22:16:57 | [diff] [blame] | 327 | // Returns whether the condition provided applies to any inner contents. |
| 328 | // This check is not recursive (however, the predicate provided may itself |
| 329 | // recurse each contents' own inner contents). |
| 330 | // |
| 331 | // For example, if this is used to aggregate state from inner contents to outer |
| 332 | // contents, then that propagation will gather transitive descendants without |
| 333 | // need for this helper to do so. In fact, in such cases recursing on inner |
| 334 | // contents here would make that operation quadratic rather than linear. |
| 335 | template <typename Functor> |
| 336 | bool AnyInnerWebContents(WebContents* web_contents, const Functor& f) { |
| 337 | const auto& inner_contents = web_contents->GetInnerWebContents(); |
| 338 | return std::any_of(inner_contents.begin(), inner_contents.end(), f); |
| 339 | } |
| 340 | |
Xuehui Xie | b2300ae4 | 2020-06-09 20:25:05 | [diff] [blame] | 341 | std::vector<RenderFrameHost*> GetAllFramesImpl(FrameTree& frame_tree, |
| 342 | bool include_pending) { |
| 343 | std::vector<RenderFrameHost*> frame_hosts; |
| 344 | for (FrameTreeNode* node : frame_tree.Nodes()) { |
| 345 | frame_hosts.push_back(node->current_frame_host()); |
| 346 | if (include_pending) { |
| 347 | RenderFrameHostImpl* pending_frame_host = |
| 348 | node->render_manager()->speculative_frame_host(); |
| 349 | if (pending_frame_host) |
| 350 | frame_hosts.push_back(pending_frame_host); |
| 351 | } |
| 352 | } |
| 353 | return frame_hosts; |
| 354 | } |
| 355 | |
| 356 | int SendToAllFramesImpl(FrameTree& frame_tree, |
| 357 | bool include_pending, |
| 358 | IPC::Message* message) { |
| 359 | int number_of_messages = 0; |
| 360 | std::vector<RenderFrameHost*> frame_hosts = |
| 361 | GetAllFramesImpl(frame_tree, include_pending); |
| 362 | for (RenderFrameHost* rfh : frame_hosts) { |
| 363 | if (!rfh->IsRenderFrameLive()) |
| 364 | continue; |
| 365 | |
| 366 | ++number_of_messages; |
| 367 | IPC::Message* message_copy = new IPC::Message(*message); |
| 368 | message_copy->set_routing_id(rfh->GetRoutingID()); |
| 369 | rfh->Send(message_copy); |
| 370 | } |
| 371 | delete message; |
| 372 | return number_of_messages; |
| 373 | } |
| 374 | |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 375 | // Returns the set of all WebContentses that are reachable from |web_contents| |
| 376 | // by applying some combination of WebContents::GetOriginalOpener() and |
| 377 | // WebContents::GetOuterWebContents(). The |web_contents| parameter will be |
| 378 | // included in the returned set. |
| 379 | base::flat_set<WebContentsImpl*> GetAllOpeningWebContents( |
| 380 | WebContentsImpl* web_contents) { |
| 381 | base::flat_set<WebContentsImpl*> result; |
| 382 | base::flat_set<WebContentsImpl*> current; |
| 383 | |
| 384 | current.insert(web_contents); |
| 385 | |
| 386 | while (!current.empty()) { |
| 387 | WebContentsImpl* current_contents = *current.begin(); |
| 388 | current.erase(current.begin()); |
| 389 | auto insert_result = result.insert(current_contents); |
| 390 | |
| 391 | if (insert_result.second) { |
| 392 | RenderFrameHostImpl* opener_rfh = current_contents->GetOriginalOpener(); |
| 393 | if (opener_rfh) { |
| 394 | current.insert(static_cast<WebContentsImpl*>( |
| 395 | WebContents::FromRenderFrameHost(opener_rfh))); |
| 396 | } |
| 397 | |
| 398 | WebContentsImpl* outer_contents = current_contents->GetOuterWebContents(); |
| 399 | if (outer_contents) |
| 400 | current.insert(outer_contents); |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | return result; |
| 405 | } |
| 406 | |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 407 | #if defined(OS_ANDROID) |
| 408 | float GetDeviceScaleAdjustment(int min_width) { |
| 409 | static const float kMinFSM = 1.05f; |
| 410 | static const int kWidthForMinFSM = 320; |
| 411 | static const float kMaxFSM = 1.3f; |
| 412 | static const int kWidthForMaxFSM = 800; |
| 413 | |
| 414 | if (min_width <= kWidthForMinFSM) |
| 415 | return kMinFSM; |
| 416 | if (min_width >= kWidthForMaxFSM) |
| 417 | return kMaxFSM; |
| 418 | |
| 419 | // The font scale multiplier varies linearly between kMinFSM and kMaxFSM. |
| 420 | float ratio = static_cast<float>(min_width - kWidthForMinFSM) / |
| 421 | (kWidthForMaxFSM - kWidthForMinFSM); |
| 422 | return ratio * (kMaxFSM - kMinFSM) + kMinFSM; |
| 423 | } |
| 424 | #endif |
| 425 | |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 426 | // Used to attach the "set of fullscreen contents" to a browser context. Storing |
| 427 | // sets of WebContents on their browser context is done for two reasons. One, |
| 428 | // related WebContentses must necessarily share a browser context, so this saves |
| 429 | // lookup time by restricting to one specific browser context. Two, separating |
| 430 | // by browser context is preemptive paranoia about keeping things separate. |
| 431 | class FullscreenContentsHolder : public base::SupportsUserData::Data { |
| 432 | public: |
| 433 | FullscreenContentsHolder() = default; |
| 434 | ~FullscreenContentsHolder() override = default; |
| 435 | |
| 436 | FullscreenContentsHolder(const FullscreenContentsHolder&) = delete; |
| 437 | FullscreenContentsHolder& operator=(const FullscreenContentsHolder&) = delete; |
| 438 | |
| 439 | base::flat_set<WebContentsImpl*>* set() { return &set_; } |
| 440 | |
| 441 | private: |
| 442 | base::flat_set<WebContentsImpl*> set_; |
| 443 | }; |
| 444 | |
| 445 | const char kFullscreenContentsSet[] = "fullscreen-contents"; |
| 446 | |
| 447 | base::flat_set<WebContentsImpl*>* FullscreenContentsSet( |
| 448 | BrowserContext* browser_context) { |
| 449 | auto* set_holder = static_cast<FullscreenContentsHolder*>( |
| 450 | browser_context->GetUserData(kFullscreenContentsSet)); |
| 451 | if (!set_holder) { |
| 452 | auto new_holder = std::make_unique<FullscreenContentsHolder>(); |
| 453 | set_holder = new_holder.get(); |
| 454 | browser_context->SetUserData(kFullscreenContentsSet, std::move(new_holder)); |
| 455 | } |
| 456 | |
| 457 | return set_holder->set(); |
| 458 | } |
| 459 | |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 460 | } // namespace |
| 461 | |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 462 | CreatedWindow::CreatedWindow() = default; |
| 463 | CreatedWindow::CreatedWindow(std::unique_ptr<WebContentsImpl> contents, |
| 464 | GURL target_url) |
| 465 | : contents(std::move(contents)), target_url(std::move(target_url)) {} |
| 466 | CreatedWindow::~CreatedWindow() = default; |
| 467 | CreatedWindow::CreatedWindow(CreatedWindow&&) = default; |
| 468 | CreatedWindow& CreatedWindow::operator=(CreatedWindow&&) = default; |
| 469 | |
Erik Chen | bb8e738e | 2018-04-28 14:10:43 | [diff] [blame] | 470 | std::unique_ptr<WebContents> WebContents::Create( |
| 471 | const WebContents::CreateParams& params) { |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 472 | return WebContentsImpl::Create(params); |
| 473 | } |
| 474 | |
| 475 | std::unique_ptr<WebContentsImpl> WebContentsImpl::Create( |
| 476 | const CreateParams& params) { |
| 477 | return CreateWithOpener(params, FindOpenerRFH(params)); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 478 | } |
| 479 | |
erikchen | ade1fef | 2018-05-02 22:07:57 | [diff] [blame] | 480 | std::unique_ptr<WebContents> WebContents::CreateWithSessionStorage( |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 481 | const WebContents::CreateParams& params, |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 482 | const SessionStorageNamespaceMap& session_storage_namespace_map) { |
erikchen | ade1fef | 2018-05-02 22:07:57 | [diff] [blame] | 483 | std::unique_ptr<WebContentsImpl> new_contents( |
| 484 | new WebContentsImpl(params.browser_context)); |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 485 | RenderFrameHostImpl* opener_rfh = FindOpenerRFH(params); |
| 486 | FrameTreeNode* opener = nullptr; |
| 487 | if (opener_rfh) |
| 488 | opener = opener_rfh->frame_tree_node(); |
| 489 | new_contents->SetOpenerForNewContents(opener, params.opener_suppressed); |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 490 | |
jdoerrie | 55ec69d | 2018-10-08 13:34:46 | [diff] [blame] | 491 | for (auto it = session_storage_namespace_map.begin(); |
| 492 | it != session_storage_namespace_map.end(); ++it) { |
Fergal Daly | 09d6c76 | 2020-05-29 02:05:18 | [diff] [blame] | 493 | new_contents->GetController().SetSessionStorageNamespace(it->first, |
| 494 | it->second.get()); |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 495 | } |
| 496 | |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 497 | WebContentsImpl* outer_web_contents = nullptr; |
Sam McNally | 69a3377 | 2018-06-27 16:54:12 | [diff] [blame] | 498 | if (params.guest_delegate) { |
| 499 | // This makes |new_contents| act as a guest. |
| 500 | // For more info, see comment above class BrowserPluginGuest. |
Albert J. Wong | c55cc64d | 2018-10-12 02:50:04 | [diff] [blame] | 501 | BrowserPluginGuest::CreateInWebContents(new_contents.get(), |
| 502 | params.guest_delegate); |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 503 | outer_web_contents = static_cast<WebContentsImpl*>( |
| 504 | params.guest_delegate->GetOwnerWebContents()); |
Sam McNally | 69a3377 | 2018-06-27 16:54:12 | [diff] [blame] | 505 | } |
| 506 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 507 | new_contents->Init(params); |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 508 | if (outer_web_contents) |
| 509 | outer_web_contents->InnerWebContentsCreated(new_contents.get()); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 510 | return new_contents; |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 511 | } |
[email protected] | 746d305 | 2012-05-22 15:15:47 | [diff] [blame] | 512 | |
benwells | 5e7260d | 2017-03-20 23:36:33 | [diff] [blame] | 513 | void WebContentsImpl::FriendWrapper::AddCreatedCallbackForTesting( |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 514 | const CreatedCallback& callback) { |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 515 | g_created_callbacks.Get().push_back(callback); |
| 516 | } |
| 517 | |
benwells | 5e7260d | 2017-03-20 23:36:33 | [diff] [blame] | 518 | void WebContentsImpl::FriendWrapper::RemoveCreatedCallbackForTesting( |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 519 | const CreatedCallback& callback) { |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 520 | for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) { |
Robert Liao | 1db5a35 | 2019-06-05 20:57:34 | [diff] [blame] | 521 | if (g_created_callbacks.Get().at(i) == callback) { |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 522 | g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i); |
| 523 | return; |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 528 | WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) { |
| 529 | if (!rvh) |
| 530 | return nullptr; |
[email protected] | 746d305 | 2012-05-22 15:15:47 | [diff] [blame] | 531 | return rvh->GetDelegate()->GetAsWebContents(); |
| 532 | } |
| 533 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 534 | WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) { |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 535 | if (!rfh) |
| 536 | return nullptr; |
Alexander Timin | 33bd754c0 | 2020-03-10 22:50:18 | [diff] [blame] | 537 | if (!rfh->IsCurrent() && base::FeatureList::IsEnabled( |
| 538 | kCheckWebContentsAccessFromNonCurrentFrame)) { |
| 539 | // TODO(crbug.com/1059903): return nullptr here eventually. |
| 540 | base::debug::DumpWithoutCrashing(); |
| 541 | } |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 542 | return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents(); |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 543 | } |
| 544 | |
ananta | 4b7467a5 | 2016-09-23 01:42:38 | [diff] [blame] | 545 | WebContents* WebContents::FromFrameTreeNodeId(int frame_tree_node_id) { |
| 546 | FrameTreeNode* frame_tree_node = |
| 547 | FrameTreeNode::GloballyFindByID(frame_tree_node_id); |
ananta | b8cfa3b | 2016-10-14 22:43:19 | [diff] [blame] | 548 | if (!frame_tree_node) |
| 549 | return nullptr; |
jam | 8c4edd0 | 2017-05-06 18:50:33 | [diff] [blame] | 550 | return WebContentsImpl::FromFrameTreeNode(frame_tree_node); |
ananta | 4b7467a5 | 2016-09-23 01:42:38 | [diff] [blame] | 551 | } |
| 552 | |
leon.han | 552e9de | 2017-02-09 14:37:30 | [diff] [blame] | 553 | void WebContents::SetScreenOrientationDelegate( |
| 554 | ScreenOrientationDelegate* delegate) { |
| 555 | ScreenOrientationProvider::SetDelegate(delegate); |
| 556 | } |
| 557 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 558 | // WebContentsImpl::DestructionObserver ---------------------------------------- |
| 559 | |
| 560 | class WebContentsImpl::DestructionObserver : public WebContentsObserver { |
| 561 | public: |
| 562 | DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents) |
Fergal Daly | 09d6c76 | 2020-05-29 02:05:18 | [diff] [blame] | 563 | : WebContentsObserver(watched_contents), owner_(owner) {} |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 564 | |
| 565 | // WebContentsObserver: |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 566 | void WebContentsDestroyed() override { |
[email protected] | 12a4683 | 2014-05-09 13:35:58 | [diff] [blame] | 567 | owner_->OnWebContentsDestroyed( |
| 568 | static_cast<WebContentsImpl*>(web_contents())); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | private: |
| 572 | WebContentsImpl* owner_; |
| 573 | |
| 574 | DISALLOW_COPY_AND_ASSIGN(DestructionObserver); |
| 575 | }; |
| 576 | |
Sreeja Kamishetty | be0ccd6b | 2020-06-09 11:52:50 | [diff] [blame] | 577 | // TODO(sreejakshetty): Make |WebContentsImpl::ColorChooser| per-frame instead |
| 578 | // of WebContents-owned. |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 579 | // WebContentsImpl::ColorChooser ---------------------------------------------- |
Joel Hockey | 163835a | 2017-12-20 11:51:57 | [diff] [blame] | 580 | class WebContentsImpl::ColorChooser : public blink::mojom::ColorChooser { |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 581 | public: |
| 582 | ColorChooser(content::ColorChooser* chooser, |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 583 | mojo::PendingReceiver<blink::mojom::ColorChooser> receiver, |
| 584 | mojo::PendingRemote<blink::mojom::ColorChooserClient> client) |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 585 | : chooser_(chooser), |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 586 | receiver_(this, std::move(receiver)), |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 587 | client_(std::move(client)) { |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 588 | receiver_.set_disconnect_handler( |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 589 | base::BindOnce([](content::ColorChooser* chooser) { chooser->End(); }, |
| 590 | base::Unretained(chooser))); |
| 591 | } |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 592 | |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 593 | ~ColorChooser() override { chooser_->End(); } |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 594 | |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 595 | void SetSelectedColor(SkColor color) override { |
| 596 | chooser_->SetSelectedColor(color); |
| 597 | } |
| 598 | |
| 599 | void DidChooseColorInColorChooser(SkColor color) { |
| 600 | client_->DidChooseColor(color); |
| 601 | } |
| 602 | |
| 603 | private: |
| 604 | // Color chooser that was opened by this tab. |
| 605 | std::unique_ptr<content::ColorChooser> chooser_; |
| 606 | |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 607 | // mojo receiver. |
| 608 | mojo::Receiver<blink::mojom::ColorChooser> receiver_; |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 609 | |
| 610 | // mojo renderer client. |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 611 | mojo::Remote<blink::mojom::ColorChooserClient> client_; |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 612 | }; |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 613 | |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 614 | // WebContentsImpl::WebContentsTreeNode ---------------------------------------- |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 615 | WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode( |
| 616 | WebContentsImpl* current_web_contents) |
| 617 | : current_web_contents_(current_web_contents), |
| 618 | outer_web_contents_(nullptr), |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 619 | outer_contents_frame_tree_node_id_( |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 620 | FrameTreeNode::kFrameTreeNodeInvalidId), |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 621 | focused_web_contents_(current_web_contents) {} |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 622 | |
Lucas Furukawa Gadani | 3d38ec15 | 2018-10-26 20:55:18 | [diff] [blame] | 623 | WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {} |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 624 | |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 625 | std::unique_ptr<WebContents> |
| 626 | WebContentsImpl::WebContentsTreeNode::DisconnectFromOuterWebContents() { |
| 627 | std::unique_ptr<WebContents> inner_contents = |
| 628 | outer_web_contents_->node_.DetachInnerWebContents(current_web_contents_); |
| 629 | OuterContentsFrameTreeNode()->RemoveObserver(this); |
| 630 | outer_contents_frame_tree_node_id_ = FrameTreeNode::kFrameTreeNodeInvalidId; |
| 631 | outer_web_contents_ = nullptr; |
| 632 | return inner_contents; |
| 633 | } |
| 634 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 635 | void WebContentsImpl::WebContentsTreeNode::AttachInnerWebContents( |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 636 | std::unique_ptr<WebContents> inner_web_contents, |
| 637 | RenderFrameHostImpl* render_frame_host) { |
| 638 | WebContentsImpl* inner_web_contents_impl = |
| 639 | static_cast<WebContentsImpl*>(inner_web_contents.get()); |
| 640 | WebContentsTreeNode& inner_web_contents_node = inner_web_contents_impl->node_; |
| 641 | |
| 642 | inner_web_contents_node.focused_web_contents_ = nullptr; |
| 643 | inner_web_contents_node.outer_web_contents_ = current_web_contents_; |
| 644 | inner_web_contents_node.outer_contents_frame_tree_node_id_ = |
| 645 | render_frame_host->frame_tree_node()->frame_tree_node_id(); |
| 646 | |
Lucas Furukawa Gadani | 3d38ec15 | 2018-10-26 20:55:18 | [diff] [blame] | 647 | inner_web_contents_.push_back(std::move(inner_web_contents)); |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 648 | |
| 649 | render_frame_host->frame_tree_node()->AddObserver(&inner_web_contents_node); |
Jeremy Roman | 03ce13ce | 2020-05-29 22:16:57 | [diff] [blame] | 650 | current_web_contents_->InnerWebContentsAttached(inner_web_contents_impl); |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 651 | } |
| 652 | |
Lucas Furukawa Gadani | 3d38ec15 | 2018-10-26 20:55:18 | [diff] [blame] | 653 | std::unique_ptr<WebContents> |
| 654 | WebContentsImpl::WebContentsTreeNode::DetachInnerWebContents( |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 655 | WebContentsImpl* inner_web_contents) { |
Lucas Furukawa Gadani | 3d38ec15 | 2018-10-26 20:55:18 | [diff] [blame] | 656 | std::unique_ptr<WebContents> detached_contents; |
| 657 | for (std::unique_ptr<WebContents>& web_contents : inner_web_contents_) { |
| 658 | if (web_contents.get() == inner_web_contents) { |
| 659 | detached_contents = std::move(web_contents); |
| 660 | std::swap(web_contents, inner_web_contents_.back()); |
| 661 | inner_web_contents_.pop_back(); |
Jeremy Roman | 03ce13ce | 2020-05-29 22:16:57 | [diff] [blame] | 662 | current_web_contents_->InnerWebContentsDetached(inner_web_contents); |
Lucas Furukawa Gadani | 3d38ec15 | 2018-10-26 20:55:18 | [diff] [blame] | 663 | return detached_contents; |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | NOTREACHED(); |
| 668 | return nullptr; |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 669 | } |
| 670 | |
lfg | a3e2bdc | 2017-03-07 20:44:01 | [diff] [blame] | 671 | FrameTreeNode* |
| 672 | WebContentsImpl::WebContentsTreeNode::OuterContentsFrameTreeNode() const { |
| 673 | return FrameTreeNode::GloballyFindByID(outer_contents_frame_tree_node_id_); |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 674 | } |
| 675 | |
lfg | a3e2bdc | 2017-03-07 20:44:01 | [diff] [blame] | 676 | void WebContentsImpl::WebContentsTreeNode::OnFrameTreeNodeDestroyed( |
| 677 | FrameTreeNode* node) { |
| 678 | DCHECK_EQ(outer_contents_frame_tree_node_id_, node->frame_tree_node_id()) |
| 679 | << "WebContentsTreeNode should only receive notifications for the " |
| 680 | "FrameTreeNode in its outer WebContents that hosts it."; |
Lucas Furukawa Gadani | 3d38ec15 | 2018-10-26 20:55:18 | [diff] [blame] | 681 | |
| 682 | // Deletes |this| too. |
| 683 | outer_web_contents_->node_.DetachInnerWebContents(current_web_contents_); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 684 | } |
| 685 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 686 | void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents( |
| 687 | WebContentsImpl* web_contents) { |
| 688 | DCHECK(!outer_web_contents()) |
| 689 | << "Only the outermost WebContents tracks focus."; |
| 690 | focused_web_contents_ = web_contents; |
| 691 | } |
| 692 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 693 | WebContentsImpl* |
| 694 | WebContentsImpl::WebContentsTreeNode::GetInnerWebContentsInFrame( |
| 695 | const FrameTreeNode* frame) { |
| 696 | auto ftn_id = frame->frame_tree_node_id(); |
Lucas Furukawa Gadani | 3d38ec15 | 2018-10-26 20:55:18 | [diff] [blame] | 697 | for (auto& contents : inner_web_contents_) { |
| 698 | WebContentsImpl* impl = static_cast<WebContentsImpl*>(contents.get()); |
| 699 | if (impl->node_.outer_contents_frame_tree_node_id() == ftn_id) { |
| 700 | return impl; |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 701 | } |
| 702 | } |
| 703 | return nullptr; |
| 704 | } |
| 705 | |
Lucas Furukawa Gadani | 3d38ec15 | 2018-10-26 20:55:18 | [diff] [blame] | 706 | std::vector<WebContentsImpl*> |
| 707 | WebContentsImpl::WebContentsTreeNode::GetInnerWebContents() const { |
| 708 | std::vector<WebContentsImpl*> inner_web_contents; |
| 709 | for (auto& contents : inner_web_contents_) |
| 710 | inner_web_contents.push_back(static_cast<WebContentsImpl*>(contents.get())); |
| 711 | |
| 712 | return inner_web_contents; |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 713 | } |
| 714 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 715 | // WebContentsObserverList ----------------------------------------------------- |
| 716 | WebContentsImpl::WebContentsObserverList::WebContentsObserverList() = default; |
| 717 | WebContentsImpl::WebContentsObserverList::~WebContentsObserverList() = default; |
| 718 | |
| 719 | void WebContentsImpl::WebContentsObserverList::AddObserver( |
| 720 | WebContentsObserver* observer) { |
| 721 | observers_.AddObserver(observer); |
| 722 | } |
| 723 | |
| 724 | void WebContentsImpl::WebContentsObserverList::RemoveObserver( |
| 725 | WebContentsObserver* observer) { |
| 726 | observers_.RemoveObserver(observer); |
| 727 | } |
| 728 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 729 | // WebContentsImpl ------------------------------------------------------------- |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 730 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 731 | WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 732 | : delegate_(nullptr), |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 733 | controller_(this, browser_context), |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 734 | render_view_host_delegate_view_(nullptr), |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 735 | created_with_opener_(false), |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 736 | node_(this), |
Fergal Daly | 09d6c76 | 2020-05-29 02:05:18 | [diff] [blame] | 737 | frame_tree_(&controller_, this, this, this, this, this), |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 738 | is_load_to_different_document_(false), |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 739 | crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
| 740 | crashed_error_code_(0), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 741 | waiting_for_response_(false), |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 742 | load_state_(net::LOAD_STATE_IDLE, base::string16()), |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 743 | upload_size_(0), |
| 744 | upload_position_(0), |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 745 | is_resume_pending_(false), |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 746 | has_accessed_initial_document_(false), |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 747 | visible_capturer_count_(0), |
| 748 | hidden_capturer_count_(0), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 749 | is_being_destroyed_(false), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 750 | notify_disconnection_(false), |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 751 | dialog_manager_(nullptr), |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 752 | is_showing_before_unload_dialog_(false), |
gab | 0dccfef | 2015-05-20 18:43:39 | [diff] [blame] | 753 | last_active_time_(base::TimeTicks::Now()), |
[email protected] | ebf40a7 | 2010-07-22 01:46:38 | [diff] [blame] | 754 | closed_by_user_gesture_(false), |
danakj | 938b37a6 | 2019-09-24 18:35:54 | [diff] [blame] | 755 | minimum_zoom_percent_( |
| 756 | static_cast<int>(blink::kMinimumPageZoomFactor * 100)), |
| 757 | maximum_zoom_percent_( |
| 758 | static_cast<int>(blink::kMaximumPageZoomFactor * 100)), |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 759 | zoom_scroll_remainder_(0), |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 760 | fullscreen_widget_process_id_(ChildProcessHost::kInvalidUniqueID), |
[email protected] | 5dcaf8e | 2013-12-28 01:31:42 | [diff] [blame] | 761 | fullscreen_widget_routing_id_(MSG_ROUTING_NONE), |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 762 | fullscreen_widget_had_focus_at_shutdown_(false), |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 763 | force_disable_overscroll_content_(false), |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 764 | last_dialog_suppressed_(false), |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 765 | accessibility_mode_( |
Dominic Mazzoni | 21fb028 | 2019-02-13 18:32:47 | [diff] [blame] | 766 | GetContentClient()->browser()->GetAXModeForBrowserContext( |
| 767 | browser_context)), |
avayvod | cc85bbd | 2015-08-28 19:11:15 | [diff] [blame] | 768 | audio_stream_monitor_(this), |
Thomas Guilbert | 882c4cec | 2019-02-14 05:55:45 | [diff] [blame] | 769 | media_web_contents_observer_( |
| 770 | std::make_unique<MediaWebContentsObserver>(this)), |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 771 | #if !defined(OS_ANDROID) |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 772 | page_scale_factor_is_one_(true), |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 773 | #endif // !defined(OS_ANDROID) |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 774 | is_overlay_content_(false), |
ekaramad | f6750aa | 2017-06-06 18:29:42 | [diff] [blame] | 775 | showing_context_menu_(false), |
W. James MacLean | 6219867 | 2019-06-04 16:46:10 | [diff] [blame] | 776 | text_autosizer_page_info_({0, 0, 1.f}), |
shivanigithub | cceeacf | 2020-03-06 20:00:27 | [diff] [blame] | 777 | native_theme_observer_(this) { |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame] | 778 | frame_tree_.SetFrameRemoveListener(base::BindRepeating( |
| 779 | &WebContentsImpl::OnFrameRemoved, base::Unretained(this))); |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 780 | #if BUILDFLAG(ENABLE_PLUGINS) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 781 | pepper_playback_observer_.reset(new PepperPlaybackObserver(this)); |
| 782 | #endif |
blundell | e75a8f9 | 2017-03-27 08:11:17 | [diff] [blame] | 783 | |
Becca Hughes | 8633462 | 2018-07-09 21:29:38 | [diff] [blame] | 784 | #if defined(OS_ANDROID) |
Elly Fong-Jones | cdd7ae8 | 2019-02-20 23:26:33 | [diff] [blame] | 785 | display_cutout_host_impl_ = std::make_unique<DisplayCutoutHostImpl>(this); |
Becca Hughes | 8633462 | 2018-07-09 21:29:38 | [diff] [blame] | 786 | #endif |
John Delaney | 732721e9 | 2020-02-07 23:11:27 | [diff] [blame] | 787 | |
Alison Maher | 7f366dc6 | 2020-03-03 19:46:00 | [diff] [blame] | 788 | ui::NativeTheme* native_theme = ui::NativeTheme::GetInstanceForWeb(); |
| 789 | native_theme_observer_.Add(native_theme); |
| 790 | using_dark_colors_ = native_theme->ShouldUseDarkColors(); |
| 791 | preferred_color_scheme_ = native_theme->GetPreferredColorScheme(); |
| 792 | |
Mike Wasserman | b213b935 | 2020-04-16 00:32:34 | [diff] [blame] | 793 | screen_change_monitor_ = |
| 794 | std::make_unique<ScreenChangeMonitor>(base::BindRepeating( |
| 795 | &WebContentsImpl::OnScreensChange, base::Unretained(this))); |
| 796 | |
John Delaney | 732721e9 | 2020-02-07 23:11:27 | [diff] [blame] | 797 | // ConversionHost takes a weak ref on |this|, so it must be created outside of |
| 798 | // the initializer list. |
Charlie Harrison | 405f621 | 2020-04-14 21:57:32 | [diff] [blame] | 799 | if (base::FeatureList::IsEnabled(features::kConversionMeasurement)) { |
| 800 | conversion_host_ = std::make_unique<ConversionHost>(this); |
| 801 | } |
[email protected] | 332af773 | 2009-03-11 13:21:35 | [diff] [blame] | 802 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 803 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 804 | WebContentsImpl::~WebContentsImpl() { |
creis | ba91ba8 | 2017-05-12 22:56:19 | [diff] [blame] | 805 | // Imperfect sanity check against double free, given some crashes unexpectedly |
| 806 | // observed in the wild. |
| 807 | CHECK(!is_being_destroyed_); |
| 808 | |
| 809 | // We generally keep track of is_being_destroyed_ to let other features know |
| 810 | // to avoid certain actions during destruction. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 811 | is_being_destroyed_ = true; |
| 812 | |
creis | 97867aa | 2017-02-17 18:39:45 | [diff] [blame] | 813 | // A WebContents should never be deleted while it is notifying observers, |
creis | ba91ba8 | 2017-05-12 22:56:19 | [diff] [blame] | 814 | // 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] | 815 | // observers. |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 816 | CHECK(!observers_.is_notifying_observers()); |
creis | 97867aa | 2017-02-17 18:39:45 | [diff] [blame] | 817 | |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 818 | FullscreenContentsSet(GetBrowserContext())->erase(this); |
| 819 | |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 820 | rwh_input_event_router_.reset(); |
| 821 | |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 822 | for (auto& entry : receiver_sets_) |
| 823 | entry.second->CloseAllReceivers(); |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 824 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 825 | WebContentsImpl* outermost = GetOutermostWebContents(); |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 826 | if (this != outermost && ContainsOrIsFocusedWebContents()) { |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 827 | // If the current WebContents is in focus, unset it. |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 828 | outermost->SetAsFocusedWebContentsIfNecessary(); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 829 | } |
| 830 | |
Nick Carter | d73635b | 2018-03-13 18:31:41 | [diff] [blame] | 831 | if (mouse_lock_widget_) |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 832 | mouse_lock_widget_->RejectMouseLockOrUnlockIfNecessary( |
| 833 | blink::mojom::PointerLockResult::kElementDestroyed); |
Nick Carter | d73635b | 2018-03-13 18:31:41 | [diff] [blame] | 834 | |
dcheng | 72be33c | 2016-01-21 04:11:31 | [diff] [blame] | 835 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 836 | // Delete all RFHs pending shutdown, which will lead the corresponding RVHs |
| 837 | // to be shutdown and be deleted as well. |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 838 | node->render_manager()->ClearRFHsPendingShutdown(); |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 839 | node->render_manager()->ClearWebUIInstances(); |
dcheng | 72be33c | 2016-01-21 04:11:31 | [diff] [blame] | 840 | } |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 841 | |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 842 | for (RenderWidgetHostImpl* widget : created_widgets_) |
| 843 | widget->DetachDelegate(); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 844 | created_widgets_.clear(); |
| 845 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 846 | // Clear out any JavaScript state. |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 847 | if (dialog_manager_) { |
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 848 | dialog_manager_->CancelDialogs(this, /*reset_state=*/true); |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 849 | } |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 850 | |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 851 | color_chooser_.reset(); |
Rakina Zata Amni | 1619612 | 2018-11-14 02:14:00 | [diff] [blame] | 852 | find_request_manager_.reset(); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 853 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 854 | NotifyDisconnected(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 855 | |
[email protected] | ca13a44 | 2012-04-17 14:00:12 | [diff] [blame] | 856 | // Notify any observer that have a reference on this WebContents. |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 857 | NotificationService::current()->Notify( |
| 858 | NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 859 | Source<WebContents>(this), |
| 860 | NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 861 | |
Arthur Sonzogni | 5a9a88c | 2018-10-18 13:16:00 | [diff] [blame] | 862 | // Destroy all subframes now. This notifies observers. |
| 863 | GetMainFrame()->ResetChildren(); |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 864 | GetRenderManager()->ResetProxyHosts(); |
[email protected] | c06c58c | 2014-03-12 20:31:59 | [diff] [blame] | 865 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 866 | // Manually call the observer methods for the root frame tree node. It is |
| 867 | // necessary to manually delete all objects tracking navigations |
| 868 | // (NavigationHandle, NavigationRequest) for observers to be properly |
| 869 | // notified of these navigations stopping before the WebContents is |
| 870 | // destroyed. |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 871 | RenderFrameHostManager* root = GetRenderManager(); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 872 | |
Lowell Manners | 2025011 | 2019-10-18 15:06:15 | [diff] [blame] | 873 | GetController().GetBackForwardCache().Shutdown(); |
| 874 | |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 875 | root->current_frame_host()->SetRenderFrameCreated(false); |
clamy | fc3850d | 2018-02-23 14:35:28 | [diff] [blame] | 876 | root->current_frame_host()->ResetNavigationRequests(); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 877 | |
Arthur Hemery | c338017 | 2018-01-22 14:00:17 | [diff] [blame] | 878 | // Do not update state as the WebContents is being destroyed. |
Arthur Hemery | 241b939 | 2019-10-24 11:08:41 | [diff] [blame] | 879 | frame_tree_.root()->ResetNavigationRequest(true); |
Arthur Hemery | c338017 | 2018-01-22 14:00:17 | [diff] [blame] | 880 | if (root->speculative_frame_host()) { |
danakj | f234243 | 2019-05-15 21:46:09 | [diff] [blame] | 881 | root->speculative_frame_host()->DeleteRenderFrame( |
| 882 | FrameDeleteIntention::kSpeculativeMainFrameForShutdown); |
Arthur Hemery | c338017 | 2018-01-22 14:00:17 | [diff] [blame] | 883 | root->speculative_frame_host()->SetRenderFrameCreated(false); |
clamy | fc3850d | 2018-02-23 14:35:28 | [diff] [blame] | 884 | root->speculative_frame_host()->ResetNavigationRequests(); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 885 | } |
[email protected] | f273ee5 | 2013-10-18 16:05:27 | [diff] [blame] | 886 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 887 | #if BUILDFLAG(ENABLE_PLUGINS) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 888 | // Call this before WebContentsDestroyed() is broadcasted since |
| 889 | // AudioFocusManager will be destroyed after that. |
| 890 | pepper_playback_observer_.reset(); |
| 891 | #endif // defined(ENABLED_PLUGINS) |
| 892 | |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 893 | // If audio is playing then notify external observers of the audio stream |
| 894 | // disappearing. |
| 895 | if (is_currently_audible_) { |
| 896 | is_currently_audible_ = false; |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 897 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 898 | observer->OnAudioStateChanged(false); |
| 899 | }); |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 900 | if (GetOuterWebContents()) |
| 901 | GetOuterWebContents()->OnAudioStateChanged(); |
| 902 | } |
| 903 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 904 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 905 | observer->FrameDeleted(root->current_frame_host()); |
| 906 | }); |
| 907 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 908 | observer->RenderViewDeleted(root->current_host()); |
| 909 | }); |
Kevin McNee | 576bb5d8 | 2019-05-29 16:47:51 | [diff] [blame] | 910 | #if defined(OS_ANDROID) |
| 911 | // For simplicity, destroy the Java WebContents before we notify of the |
| 912 | // destruction of the WebContents. |
| 913 | ClearWebContentsAndroid(); |
| 914 | #endif |
| 915 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 916 | observers_.ForEachObserver( |
| 917 | [&](WebContentsObserver* observer) { observer->WebContentsDestroyed(); }); |
Becca Hughes | d11d650 | 2018-07-31 17:01:28 | [diff] [blame] | 918 | if (display_cutout_host_impl_) |
| 919 | display_cutout_host_impl_->WebContentsDestroyed(); |
| 920 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 921 | observers_.ForEachObserver( |
| 922 | [&](WebContentsObserver* observer) { observer->ResetWebContents(); }); |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 923 | SetDelegate(nullptr); |
[email protected] | b5a1d11c | 2011-02-17 03:09:42 | [diff] [blame] | 924 | } |
| 925 | |
erikchen | 50735fd | 2018-05-05 15:08:33 | [diff] [blame] | 926 | std::unique_ptr<WebContentsImpl> WebContentsImpl::CreateWithOpener( |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 927 | const WebContents::CreateParams& params, |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 928 | RenderFrameHostImpl* opener_rfh) { |
[email protected] | e11f0e9 | 2013-06-12 15:12:03 | [diff] [blame] | 929 | TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener"); |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 930 | FrameTreeNode* opener = nullptr; |
| 931 | if (opener_rfh) |
| 932 | opener = opener_rfh->frame_tree_node(); |
erikchen | 50735fd | 2018-05-05 15:08:33 | [diff] [blame] | 933 | std::unique_ptr<WebContentsImpl> new_contents( |
| 934 | new WebContentsImpl(params.browser_context)); |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 935 | new_contents->SetOpenerForNewContents(opener, params.opener_suppressed); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 936 | |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 937 | // If the opener is sandboxed, a new popup must inherit the opener's sandbox |
| 938 | // flags, and these flags take effect immediately. An exception is if the |
| 939 | // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts |
| 940 | // bit (which is controlled by the "allow-popups-to-escape-sandbox" token). |
| 941 | // See https://html.spec.whatwg.org/#attr-iframe-sandbox. |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 942 | FrameTreeNode* new_root = new_contents->GetFrameTree()->root(); |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 943 | if (opener) { |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 944 | network::mojom::WebSandboxFlags opener_flags = |
Antonio Gomes | 7096ac0 | 2020-02-14 14:29:54 | [diff] [blame] | 945 | opener_rfh->active_sandbox_flags(); |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 946 | const network::mojom::WebSandboxFlags inherit_flag = |
| 947 | network::mojom::WebSandboxFlags::kPropagatesToAuxiliaryBrowsingContexts; |
Ehsan Karamad | 3940708 | 2019-02-19 23:38:19 | [diff] [blame] | 948 | bool sandbox_propagates_to_auxilary_context = |
| 949 | (opener_flags & inherit_flag) == inherit_flag; |
| 950 | if (sandbox_propagates_to_auxilary_context) |
Charlie Hu | e1b77ac | 2019-12-13 21:30:17 | [diff] [blame] | 951 | new_root->SetPendingFramePolicy({opener_flags, |
| 952 | {} /* container_policy */, |
| 953 | {} /* required_document_policy */}); |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 954 | if (opener_flags == network::mojom::WebSandboxFlags::kNone || |
Ehsan Karamad | 3940708 | 2019-02-19 23:38:19 | [diff] [blame] | 955 | sandbox_propagates_to_auxilary_context) { |
| 956 | // TODO(ekaramad, iclelland): Do not propagate feature policies from non- |
| 957 | // sandboxed disowned openers (rel=noopener). |
| 958 | // If the current page is not sandboxed, or if the sandbox is to propagate |
| 959 | // to the popups then opener's feature policy will apply to the new popup |
| 960 | // as well. |
| 961 | new_root->SetOpenerFeaturePolicyState( |
Ehsan Karamad | 34d1068 | 2019-02-26 20:55:04 | [diff] [blame] | 962 | opener_rfh->feature_policy()->GetFeatureState()); |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 963 | } |
| 964 | } |
| 965 | |
mark a. foltz | ef394fce | 2017-10-21 09:11:02 | [diff] [blame] | 966 | // Apply starting sandbox flags. |
Luna Lu | c3fdacdf | 2017-11-08 04:48:53 | [diff] [blame] | 967 | blink::FramePolicy frame_policy(new_root->pending_frame_policy()); |
mark a. foltz | ef394fce | 2017-10-21 09:11:02 | [diff] [blame] | 968 | frame_policy.sandbox_flags |= params.starting_sandbox_flags; |
| 969 | new_root->SetPendingFramePolicy(frame_policy); |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 970 | new_root->CommitFramePolicy(frame_policy); |
mark a. foltz | ef394fce | 2017-10-21 09:11:02 | [diff] [blame] | 971 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 972 | // This may be true even when opener is null, such as when opening blocked |
| 973 | // popups. |
alexmos | 090fae8e | 2015-05-28 17:09:28 | [diff] [blame] | 974 | if (params.created_with_opener) |
| 975 | new_contents->created_with_opener_ = true; |
| 976 | |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 977 | WebContentsImpl* outer_web_contents = nullptr; |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 978 | if (params.guest_delegate) { |
[email protected] | 83100cd | 2014-05-10 11:50:06 | [diff] [blame] | 979 | // This makes |new_contents| act as a guest. |
| 980 | // For more info, see comment above class BrowserPluginGuest. |
Albert J. Wong | c55cc64d | 2018-10-12 02:50:04 | [diff] [blame] | 981 | BrowserPluginGuest::CreateInWebContents(new_contents.get(), |
| 982 | params.guest_delegate); |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 983 | outer_web_contents = static_cast<WebContentsImpl*>( |
| 984 | params.guest_delegate->GetOwnerWebContents()); |
[email protected] | 83100cd | 2014-05-10 11:50:06 | [diff] [blame] | 985 | } |
mark a. foltz | ef394fce | 2017-10-21 09:11:02 | [diff] [blame] | 986 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 987 | new_contents->Init(params); |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 988 | if (outer_web_contents) |
| 989 | outer_web_contents->InnerWebContentsCreated(new_contents.get()); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 990 | return new_contents; |
| 991 | } |
| 992 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 993 | // static |
| 994 | std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() { |
| 995 | std::vector<WebContentsImpl*> result; |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 996 | std::unique_ptr<RenderWidgetHostIterator> widgets( |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 997 | RenderWidgetHostImpl::GetRenderWidgetHosts()); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 998 | while (RenderWidgetHost* rwh = widgets->GetNextHost()) { |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 999 | RenderViewHost* rvh = RenderViewHost::From(rwh); |
| 1000 | if (!rvh) |
| 1001 | continue; |
| 1002 | WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
| 1003 | if (!web_contents) |
| 1004 | continue; |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 1005 | if (web_contents->GetRenderViewHost() != rvh) |
| 1006 | continue; |
| 1007 | // Because a WebContents can only have one current RVH at a time, there will |
| 1008 | // be no duplicate WebContents here. |
| 1009 | result.push_back(static_cast<WebContentsImpl*>(web_contents)); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1010 | } |
| 1011 | return result; |
| 1012 | } |
| 1013 | |
clamy | a16aa817 | 2015-05-26 13:07:25 | [diff] [blame] | 1014 | // static |
| 1015 | WebContentsImpl* WebContentsImpl::FromFrameTreeNode( |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 1016 | const FrameTreeNode* frame_tree_node) { |
clamy | a16aa817 | 2015-05-26 13:07:25 | [diff] [blame] | 1017 | return static_cast<WebContentsImpl*>( |
| 1018 | WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host())); |
| 1019 | } |
| 1020 | |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 1021 | // static |
Patrick Monette | 275a6f92b | 2020-01-09 21:05:04 | [diff] [blame] | 1022 | WebContents* WebContentsImpl::FromRenderFrameHostID( |
| 1023 | GlobalFrameRoutingId render_frame_host_id) { |
| 1024 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 1025 | !BrowserThread::IsThreadInitialized(BrowserThread::UI)); |
Patrick Monette | 7364e697 | 2020-01-09 22:56:02 | [diff] [blame] | 1026 | RenderFrameHost* render_frame_host = |
| 1027 | RenderFrameHost::FromID(render_frame_host_id); |
| 1028 | if (!render_frame_host) |
| 1029 | return nullptr; |
| 1030 | |
| 1031 | return WebContents::FromRenderFrameHost(render_frame_host); |
Patrick Monette | 275a6f92b | 2020-01-09 21:05:04 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | // static |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 1035 | WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id, |
| 1036 | int render_frame_host_id) { |
Patrick Monette | 7364e697 | 2020-01-09 22:56:02 | [diff] [blame] | 1037 | return FromRenderFrameHostID( |
| 1038 | GlobalFrameRoutingId(render_process_host_id, render_frame_host_id)); |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 1039 | } |
| 1040 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 1041 | // static |
| 1042 | WebContentsImpl* WebContentsImpl::FromOuterFrameTreeNode( |
| 1043 | const FrameTreeNode* frame_tree_node) { |
| 1044 | return WebContentsImpl::FromFrameTreeNode(frame_tree_node) |
| 1045 | ->node_.GetInnerWebContentsInFrame(frame_tree_node); |
| 1046 | } |
| 1047 | |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 1048 | RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1049 | return GetRenderManager(); |
[email protected] | 76518718 | 2012-01-11 23:59:28 | [diff] [blame] | 1050 | } |
| 1051 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 1052 | bool WebContentsImpl::OnMessageReceived(RenderViewHostImpl* render_view_host, |
[email protected] | 7bb76189 | 2012-07-20 09:32:47 | [diff] [blame] | 1053 | const IPC::Message& message) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 1054 | for (auto& observer : observers_.observer_list()) { |
Lukasz Anforowicz | 89f2c1b | 2017-08-30 21:36:46 | [diff] [blame] | 1055 | // TODO(nick, creis): https://crbug.com/758026: Replace all uses of this |
| 1056 | // variant of OnMessageReceived with the version that takes a |
| 1057 | // RenderFrameHost, and then delete it. |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 1058 | if (observer.OnMessageReceived(message)) |
| 1059 | return true; |
[email protected] | 64ffefa | 2014-05-10 12:06:33 | [diff] [blame] | 1060 | } |
[email protected] | 403415a | 2011-01-10 18:57:53 | [diff] [blame] | 1061 | |
Henrique Ferreiro | ba53547 | 2020-04-21 11:38:36 | [diff] [blame] | 1062 | #if BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1063 | bool handled = true; |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 1064 | IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_view_host) |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 1065 | IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, |
| 1066 | OnRequestPpapiBrokerPermission) |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 1067 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 1068 | IPC_END_MESSAGE_MAP() |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 1069 | return handled; |
Henrique Ferreiro | ba53547 | 2020-04-21 11:38:36 | [diff] [blame] | 1070 | #else |
| 1071 | return false; |
| 1072 | #endif |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | bool WebContentsImpl::OnMessageReceived(RenderFrameHostImpl* render_frame_host, |
| 1076 | const IPC::Message& message) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 1077 | for (auto& observer : observers_.observer_list()) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 1078 | if (observer.OnMessageReceived(message, render_frame_host)) |
| 1079 | return true; |
| 1080 | } |
| 1081 | |
| 1082 | bool handled = true; |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 1083 | #if BUILDFLAG(ENABLE_PLUGINS) |
Hiroki Nakagawa | 761b9b0 | 2020-07-13 11:12:02 | [diff] [blame] | 1084 | IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_frame_host) |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 1085 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated, |
| 1086 | OnPepperInstanceCreated) |
| 1087 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted, |
| 1088 | OnPepperInstanceDeleted) |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 1089 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 1090 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback, |
| 1091 | OnPepperStartsPlayback) |
| 1092 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback, |
| 1093 | OnPepperStopsPlayback) |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 1094 | IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed) |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1095 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | e44d134 | 2014-05-16 21:29:33 | [diff] [blame] | 1096 | IPC_END_MESSAGE_MAP() |
Hiroki Nakagawa | 761b9b0 | 2020-07-13 11:12:02 | [diff] [blame] | 1097 | #else |
| 1098 | handled = false; |
| 1099 | #endif |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1100 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1101 | return handled; |
| 1102 | } |
| 1103 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1104 | NavigationControllerImpl& WebContentsImpl::GetController() { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 1105 | return controller_; |
| 1106 | } |
| 1107 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1108 | BrowserContext* WebContentsImpl::GetBrowserContext() { |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 1109 | return controller_.GetBrowserContext(); |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 1110 | } |
| 1111 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1112 | const GURL& WebContentsImpl::GetURL() { |
Peter Boström | 101d767 | 2018-12-15 00:43:59 | [diff] [blame] | 1113 | return GetVisibleURL(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1114 | } |
| 1115 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1116 | const GURL& WebContentsImpl::GetVisibleURL() { |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 1117 | // We may not have a navigation entry yet. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1118 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 1119 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
| 1120 | } |
| 1121 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1122 | const GURL& WebContentsImpl::GetLastCommittedURL() { |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 1123 | // We may not have a navigation entry yet. |
| 1124 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
| 1125 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
| 1126 | } |
| 1127 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1128 | WebContentsDelegate* WebContentsImpl::GetDelegate() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1129 | return delegate_; |
| 1130 | } |
| 1131 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1132 | void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1133 | // TODO(cbentzel): remove this debugging code? |
| 1134 | if (delegate == delegate_) |
| 1135 | return; |
| 1136 | if (delegate_) |
| 1137 | delegate_->Detach(this); |
| 1138 | delegate_ = delegate; |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 1139 | if (delegate_) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1140 | delegate_->Attach(this); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 1141 | // Ensure the visible RVH reflects the new delegate's preferences. |
[email protected] | 86f98a2 | 2013-03-20 14:35:00 | [diff] [blame] | 1142 | if (view_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 1143 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
Joel Einbinder | 848001c | 2017-09-19 21:39:31 | [diff] [blame] | 1144 | if (GetRenderViewHost()) |
| 1145 | RenderFrameDevToolsAgentHost::WebContentsCreated(this); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 1146 | } |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1147 | } |
| 1148 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1149 | RenderFrameHostImpl* WebContentsImpl::GetMainFrame() { |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 1150 | return frame_tree_.root()->current_frame_host(); |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 1151 | } |
| 1152 | |
nick | 53d5cbf | 2015-04-23 22:50:14 | [diff] [blame] | 1153 | RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() { |
| 1154 | FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame(); |
| 1155 | if (!focused_node) |
| 1156 | return nullptr; |
| 1157 | return focused_node->current_frame_host(); |
[email protected] | 9c9343b | 2014-03-08 02:56:07 | [diff] [blame] | 1158 | } |
| 1159 | |
rob | 3e2a073 | 2016-01-06 21:22:09 | [diff] [blame] | 1160 | RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId( |
creis | f71a263 | 2017-05-04 19:03:50 | [diff] [blame] | 1161 | int frame_tree_node_id, |
| 1162 | int process_id) { |
| 1163 | FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id); |
| 1164 | |
| 1165 | // Sanity check that this is in the caller's expected process. Otherwise a |
| 1166 | // recent cross-process navigation may have led to a privilege change that the |
| 1167 | // caller is not expecting. |
| 1168 | if (!frame || |
| 1169 | frame->current_frame_host()->GetProcess()->GetID() != process_id) |
| 1170 | return nullptr; |
| 1171 | |
| 1172 | return frame->current_frame_host(); |
| 1173 | } |
| 1174 | |
| 1175 | RenderFrameHostImpl* WebContentsImpl::UnsafeFindFrameByFrameTreeNodeId( |
rob | 3e2a073 | 2016-01-06 21:22:09 | [diff] [blame] | 1176 | int frame_tree_node_id) { |
creis | f71a263 | 2017-05-04 19:03:50 | [diff] [blame] | 1177 | // Beware using this! The RenderFrameHost may have changed since the caller |
| 1178 | // obtained frame_tree_node_id. |
rob | 3e2a073 | 2016-01-06 21:22:09 | [diff] [blame] | 1179 | FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id); |
| 1180 | return frame ? frame->current_frame_host() : nullptr; |
| 1181 | } |
| 1182 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 1183 | void WebContentsImpl::ForEachFrame( |
Lei Zhang | ebcc630 | 2018-01-12 19:46:45 | [diff] [blame] | 1184 | const base::RepeatingCallback<void(RenderFrameHost*)>& on_frame) { |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1185 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 1186 | on_frame.Run(node->current_frame_host()); |
| 1187 | } |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 1188 | } |
| 1189 | |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1190 | std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() { |
Xuehui Xie | b2300ae4 | 2020-06-09 20:25:05 | [diff] [blame] | 1191 | return GetAllFramesImpl(frame_tree_, /*include_pending=*/false); |
| 1192 | } |
| 1193 | |
| 1194 | std::vector<RenderFrameHost*> WebContentsImpl::GetAllFramesIncludingPending() { |
| 1195 | return GetAllFramesImpl(frame_tree_, /*include_pending=*/true); |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1196 | } |
| 1197 | |
lukasza | cbdf52e | 2016-01-15 21:19:51 | [diff] [blame] | 1198 | int WebContentsImpl::SendToAllFrames(IPC::Message* message) { |
Xuehui Xie | b2300ae4 | 2020-06-09 20:25:05 | [diff] [blame] | 1199 | return SendToAllFramesImpl(frame_tree_, /*include_pending=*/false, message); |
| 1200 | } |
lukasza | 1a9ab242 | 2016-03-02 18:47:25 | [diff] [blame] | 1201 | |
Xuehui Xie | b2300ae4 | 2020-06-09 20:25:05 | [diff] [blame] | 1202 | int WebContentsImpl::SendToAllFramesIncludingPending(IPC::Message* message) { |
| 1203 | return SendToAllFramesImpl(frame_tree_, /*include_pending=*/true, message); |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 1204 | } |
| 1205 | |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 1206 | void WebContentsImpl::SendPageMessage(IPC::Message* msg) { |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 1207 | frame_tree_.root()->render_manager()->SendPageMessage(msg, nullptr); |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 1208 | } |
| 1209 | |
Gyuyoung Kim | 877e86d | 2020-07-21 04:01:02 | [diff] [blame] | 1210 | void WebContentsImpl::ExecutePageBroadcastMethod( |
| 1211 | PageBroadcastMethodCallback callback) { |
| 1212 | frame_tree_.root()->render_manager()->ExecutePageBroadcastMethod(callback); |
| 1213 | } |
| 1214 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1215 | RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1216 | return GetRenderManager()->current_host(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1217 | } |
| 1218 | |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 1219 | void WebContentsImpl::CancelActiveAndPendingDialogs() { |
Evan Stade | 753fc20 | 2020-07-13 18:09:54 | [diff] [blame] | 1220 | if (dialog_manager_) { |
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 1221 | dialog_manager_->CancelDialogs(this, /*reset_state=*/false); |
Evan Stade | 753fc20 | 2020-07-13 18:09:54 | [diff] [blame] | 1222 | } |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 1223 | if (browser_plugin_embedder_) |
| 1224 | browser_plugin_embedder_->CancelGuestDialogs(); |
| 1225 | } |
| 1226 | |
nasko | c0fceff | 2015-04-30 15:53:52 | [diff] [blame] | 1227 | void WebContentsImpl::ClosePage() { |
| 1228 | GetRenderViewHost()->ClosePage(); |
| 1229 | } |
| 1230 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1231 | RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1232 | return GetRenderManager()->GetRenderWidgetHostView(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1233 | } |
| 1234 | |
lfg | 265a267 | 2016-04-23 03:11:02 | [diff] [blame] | 1235 | RenderWidgetHostView* WebContentsImpl::GetTopLevelRenderWidgetHostView() { |
| 1236 | if (GetOuterWebContents()) |
| 1237 | return GetOuterWebContents()->GetTopLevelRenderWidgetHostView(); |
| 1238 | return GetRenderManager()->GetRenderWidgetHostView(); |
| 1239 | } |
| 1240 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1241 | RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView() { |
vmpstr | 6d9996c8 | 2017-02-23 00:43:25 | [diff] [blame] | 1242 | if (auto* widget_host = GetFullscreenRenderWidgetHost()) |
ekaramad | aeb3c5c | 2016-11-09 03:22:35 | [diff] [blame] | 1243 | return widget_host->GetView(); |
| 1244 | return nullptr; |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 1245 | } |
| 1246 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1247 | WebContentsView* WebContentsImpl::GetView() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1248 | return view_.get(); |
| 1249 | } |
| 1250 | |
Mike Wasserman | b213b935 | 2020-04-16 00:32:34 | [diff] [blame] | 1251 | void WebContentsImpl::OnScreensChange() { |
| 1252 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 1253 | RenderFrameHostImpl* rfh = node->current_frame_host(); |
| 1254 | rfh->GetAssociatedLocalFrame()->OnScreensChange(); |
| 1255 | } |
| 1256 | } |
| 1257 | |
leon.han | 552e9de | 2017-02-09 14:37:30 | [diff] [blame] | 1258 | void WebContentsImpl::OnScreenOrientationChange() { |
| 1259 | DCHECK(screen_orientation_provider_); |
Lan Wei | f81c6e7c | 2020-02-12 16:46:09 | [diff] [blame] | 1260 | DidChangeScreenOrientation(); |
Becca Hughes | e9e2795 | 2018-06-25 17:08:27 | [diff] [blame] | 1261 | screen_orientation_provider_->OnOrientationChange(); |
leon.han | e4db177a | 2017-02-07 14:19:16 | [diff] [blame] | 1262 | } |
| 1263 | |
Alan Cutter | 92d5925 | 2019-03-29 02:32:33 | [diff] [blame] | 1264 | base::Optional<SkColor> WebContentsImpl::GetThemeColor() { |
Carlos Caballero | 1215f88 | 2019-10-29 15:58:43 | [diff] [blame] | 1265 | return GetRenderViewHost()->theme_color(); |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 1266 | } |
| 1267 | |
Doug Turner | 63f3c7b | 2017-07-29 05:10:01 | [diff] [blame] | 1268 | void WebContentsImpl::SetAccessibilityMode(ui::AXMode mode) { |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1269 | if (mode == accessibility_mode_) |
| 1270 | return; |
| 1271 | |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 1272 | // Don't allow accessibility to be enabled for WebContents that are never |
danakj | 77eb7e8 | 2020-01-09 19:38:46 | [diff] [blame] | 1273 | // user-visible, like background pages. |
| 1274 | if (IsNeverComposited()) |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 1275 | return; |
| 1276 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1277 | accessibility_mode_ = mode; |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1278 | |
| 1279 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 1280 | UpdateAccessibilityModeOnFrame(node->current_frame_host()); |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 1281 | // Also update accessibility mode on the speculative RenderFrameHost for |
| 1282 | // this FrameTreeNode, if one exists. |
Alex Moshchuk | 3d8a1f39 | 2017-10-24 19:01:26 | [diff] [blame] | 1283 | RenderFrameHost* speculative_frame_host = |
| 1284 | node->render_manager()->speculative_frame_host(); |
| 1285 | if (speculative_frame_host) |
| 1286 | UpdateAccessibilityModeOnFrame(speculative_frame_host); |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1287 | } |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1288 | } |
| 1289 | |
Doug Turner | 63f3c7b | 2017-07-29 05:10:01 | [diff] [blame] | 1290 | void WebContentsImpl::AddAccessibilityMode(ui::AXMode mode) { |
| 1291 | ui::AXMode new_mode(accessibility_mode_); |
dougt | cd3dad73 | 2017-03-14 03:26:23 | [diff] [blame] | 1292 | new_mode |= mode; |
| 1293 | SetAccessibilityMode(new_mode); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1294 | } |
| 1295 | |
Avi Drissman | 1e620f3 | 2018-03-16 13:57:29 | [diff] [blame] | 1296 | // Helper class used by WebContentsImpl::RequestAXTreeSnapshot. |
| 1297 | // Handles the callbacks from parallel snapshot requests to each frame, |
| 1298 | // and feeds the results to an AXTreeCombiner, which converts them into a |
| 1299 | // single combined accessibility tree. |
| 1300 | class WebContentsImpl::AXTreeSnapshotCombiner |
| 1301 | : public base::RefCounted<AXTreeSnapshotCombiner> { |
| 1302 | public: |
| 1303 | explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback) |
| 1304 | : callback_(std::move(callback)) {} |
| 1305 | |
| 1306 | AXTreeSnapshotCallback AddFrame(bool is_root) { |
| 1307 | // Adds a reference to |this|. |
| 1308 | return base::BindOnce(&AXTreeSnapshotCombiner::ReceiveSnapshot, this, |
| 1309 | is_root); |
| 1310 | } |
| 1311 | |
| 1312 | void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) { |
| 1313 | combiner_.AddTree(snapshot, is_root); |
| 1314 | } |
| 1315 | |
| 1316 | private: |
| 1317 | friend class base::RefCounted<AXTreeSnapshotCombiner>; |
| 1318 | |
| 1319 | // This is called automatically after the last call to ReceiveSnapshot |
| 1320 | // when there are no more references to this object. |
| 1321 | ~AXTreeSnapshotCombiner() { |
| 1322 | combiner_.Combine(); |
| 1323 | std::move(callback_).Run(combiner_.combined()); |
| 1324 | } |
| 1325 | |
| 1326 | ui::AXTreeCombiner combiner_; |
| 1327 | AXTreeSnapshotCallback callback_; |
| 1328 | }; |
| 1329 | |
| 1330 | void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback, |
| 1331 | ui::AXMode ax_mode) { |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 1332 | // Send a request to each of the frames in parallel. Each one will return |
| 1333 | // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine |
| 1334 | // them into a single tree and call |callback| with that result, then |
| 1335 | // delete |combiner|. |
Avi Drissman | 1e620f3 | 2018-03-16 13:57:29 | [diff] [blame] | 1336 | FrameTreeNode* root_node = frame_tree_.root(); |
tzik | 58faa74 | 2018-08-01 10:54:18 | [diff] [blame] | 1337 | auto combiner = |
| 1338 | base::MakeRefCounted<AXTreeSnapshotCombiner>(std::move(callback)); |
Avi Drissman | 1e620f3 | 2018-03-16 13:57:29 | [diff] [blame] | 1339 | |
tzik | 58faa74 | 2018-08-01 10:54:18 | [diff] [blame] | 1340 | RecursiveRequestAXTreeSnapshotOnFrame(root_node, combiner.get(), ax_mode); |
Avi Drissman | 1e620f3 | 2018-03-16 13:57:29 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | void WebContentsImpl::RecursiveRequestAXTreeSnapshotOnFrame( |
| 1344 | FrameTreeNode* root_node, |
| 1345 | AXTreeSnapshotCombiner* combiner, |
| 1346 | ui::AXMode ax_mode) { |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 1347 | for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) { |
Avi Drissman | 1e620f3 | 2018-03-16 13:57:29 | [diff] [blame] | 1348 | WebContentsImpl* inner_contents = |
| 1349 | node_.GetInnerWebContentsInFrame(frame_tree_node); |
| 1350 | if (inner_contents) { |
| 1351 | inner_contents->RecursiveRequestAXTreeSnapshotOnFrame(root_node, combiner, |
| 1352 | ax_mode); |
| 1353 | } else { |
| 1354 | bool is_root = frame_tree_node == root_node; |
| 1355 | frame_tree_node->current_frame_host()->RequestAXTreeSnapshot( |
| 1356 | combiner->AddFrame(is_root), ax_mode); |
| 1357 | } |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 1358 | } |
dmazzoni | 83ba5c8 | 2015-04-14 07:11:51 | [diff] [blame] | 1359 | } |
| 1360 | |
Becca Hughes | 3b5a4348 | 2018-07-17 22:31:55 | [diff] [blame] | 1361 | void WebContentsImpl::NotifyViewportFitChanged( |
| 1362 | blink::mojom::ViewportFit value) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 1363 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 1364 | observer->ViewportFitChanged(value); |
| 1365 | }); |
Becca Hughes | 3b5a4348 | 2018-07-17 22:31:55 | [diff] [blame] | 1366 | } |
| 1367 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1368 | FindRequestManager* WebContentsImpl::GetFindRequestManagerForTesting() { |
Ehsan Karamad | 6beb2ea | 2018-11-25 18:15:13 | [diff] [blame] | 1369 | return GetFindRequestManager(); |
| 1370 | } |
| 1371 | |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 1372 | #if !defined(OS_ANDROID) |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 1373 | void WebContentsImpl::UpdateZoom() { |
| 1374 | RenderWidgetHostImpl* rwh = GetRenderViewHost()->GetWidget(); |
| 1375 | if (rwh->GetView()) |
| 1376 | rwh->SynchronizeVisualProperties(); |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1377 | } |
| 1378 | |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1379 | |
| 1380 | void WebContentsImpl::UpdateZoomIfNecessary(const std::string& scheme, |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 1381 | const std::string& host) { |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1382 | NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
| 1383 | if (!entry) |
| 1384 | return; |
| 1385 | |
| 1386 | GURL url = HostZoomMap::GetURLFromEntry(entry); |
| 1387 | if (host != net::GetHostOrSpecFromURL(url) || |
| 1388 | (!scheme.empty() && !url.SchemeIs(scheme))) { |
| 1389 | return; |
| 1390 | } |
| 1391 | |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 1392 | UpdateZoom(); |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1393 | } |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 1394 | #endif // !defined(OS_ANDROID) |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1395 | |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 1396 | base::OnceClosure WebContentsImpl::AddReceiverSet( |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 1397 | const std::string& interface_name, |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 1398 | WebContentsReceiverSet* receiver_set) { |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 1399 | auto result = |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 1400 | receiver_sets_.insert(std::make_pair(interface_name, receiver_set)); |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 1401 | DCHECK(result.second); |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 1402 | return base::BindOnce(&WebContentsImpl::RemoveReceiverSet, |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame] | 1403 | weak_factory_.GetWeakPtr(), interface_name); |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 1404 | } |
| 1405 | |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 1406 | WebContentsReceiverSet* WebContentsImpl::GetReceiverSet( |
rockot | 8bbad22 | 2017-03-22 04:34:05 | [diff] [blame] | 1407 | const std::string& interface_name) { |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 1408 | auto it = receiver_sets_.find(interface_name); |
| 1409 | if (it == receiver_sets_.end()) |
rockot | 8bbad22 | 2017-03-22 04:34:05 | [diff] [blame] | 1410 | return nullptr; |
| 1411 | return it->second; |
| 1412 | } |
| 1413 | |
John Delaney | 732721e9 | 2020-02-07 23:11:27 | [diff] [blame] | 1414 | void WebContentsImpl::RemoveReceiverSetForTesting( |
| 1415 | const std::string& interface_name) { |
| 1416 | RemoveReceiverSet(interface_name); |
| 1417 | } |
| 1418 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 1419 | std::vector<WebContentsImpl*> WebContentsImpl::GetWebContentsAndAllInner() { |
| 1420 | std::vector<WebContentsImpl*> all_contents(1, this); |
| 1421 | |
| 1422 | for (size_t i = 0; i != all_contents.size(); ++i) { |
| 1423 | for (auto* inner_contents : all_contents[i]->GetInnerWebContents()) { |
Lucas Furukawa Gadani | 2ec00c8 | 2018-12-14 15:53:16 | [diff] [blame] | 1424 | all_contents.push_back(static_cast<WebContentsImpl*>(inner_contents)); |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | return all_contents; |
| 1429 | } |
| 1430 | |
Sam McNally | 145fb17 | 2017-05-10 00:13:23 | [diff] [blame] | 1431 | void WebContentsImpl::NotifyManifestUrlChanged( |
Yuzu Saijo | 0c263c70 | 2020-06-08 03:41:24 | [diff] [blame] | 1432 | RenderFrameHost* rfh, |
Sam McNally | 145fb17 | 2017-05-10 00:13:23 | [diff] [blame] | 1433 | const base::Optional<GURL>& manifest_url) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 1434 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 1435 | observer->DidUpdateWebManifestURL(rfh, manifest_url); |
| 1436 | }); |
Sam McNally | 145fb17 | 2017-05-10 00:13:23 | [diff] [blame] | 1437 | } |
| 1438 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1439 | WebUI* WebContentsImpl::GetWebUI() { |
Nasko Oskov | 2f7d211 | 2019-10-29 03:26:57 | [diff] [blame] | 1440 | WebUI* committed_web_ui = GetCommittedWebUI(); |
| 1441 | if (committed_web_ui) |
| 1442 | return committed_web_ui; |
| 1443 | |
| 1444 | if (GetRenderManager()->speculative_frame_host()) |
| 1445 | return GetRenderManager()->speculative_frame_host()->web_ui(); |
| 1446 | |
| 1447 | return nullptr; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1448 | } |
| 1449 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1450 | WebUI* WebContentsImpl::GetCommittedWebUI() { |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 1451 | return frame_tree_.root()->current_frame_host()->web_ui(); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1452 | } |
| 1453 | |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 1454 | void WebContentsImpl::SetUserAgentOverride( |
| 1455 | const blink::UserAgentOverride& ua_override, |
| 1456 | bool override_in_new_tabs) { |
| 1457 | DCHECK(!ua_override.ua_metadata_override.has_value() || |
| 1458 | !ua_override.ua_string_override.empty()); |
| 1459 | |
| 1460 | if (GetUserAgentOverride() == ua_override) |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1461 | return; |
| 1462 | |
Changwan Ryu | c1134a8 | 2018-03-07 02:10:14 | [diff] [blame] | 1463 | should_override_user_agent_in_new_tabs_ = override_in_new_tabs; |
| 1464 | |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 1465 | renderer_preferences_.user_agent_override = ua_override; |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1466 | |
Bruce Long | 1e3e1f54 | 2019-10-16 17:56:28 | [diff] [blame] | 1467 | // Send the new override string to all renderers in the current page. |
| 1468 | SyncRendererPrefs(); |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1469 | |
| 1470 | // Reload the page if a load is currently in progress to avoid having |
| 1471 | // different parts of the page loaded using different user agents. |
Scott Violet | e1d58cc | 2020-04-28 23:07:17 | [diff] [blame] | 1472 | // No need to reload if the current entry matches that of the |
| 1473 | // NavigationRequest supplied to DidStartNavigation() as NavigationRequest |
| 1474 | // handles it. |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 1475 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
Scott Violet | e1d58cc | 2020-04-28 23:07:17 | [diff] [blame] | 1476 | if (IsLoading() && entry != nullptr && entry->GetIsOverridingUserAgent() && |
| 1477 | (!frame_tree_.root()->navigation_request() || |
| 1478 | frame_tree_.root()->navigation_request()->ua_change_requires_reload())) { |
toyoshim | 6142d96f | 2016-12-19 09:07:25 | [diff] [blame] | 1479 | controller_.Reload(ReloadType::BYPASSING_CACHE, true); |
Scott Violet | e1d58cc | 2020-04-28 23:07:17 | [diff] [blame] | 1480 | } |
[email protected] | 8d0f331 | 2012-08-18 01:47:53 | [diff] [blame] | 1481 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 1482 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 1483 | observer->UserAgentOverrideSet(ua_override); |
| 1484 | }); |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 1485 | } |
| 1486 | |
Scott Violet | 2a6c5bff | 2020-04-29 23:59:06 | [diff] [blame] | 1487 | void WebContentsImpl::SetRendererInitiatedUserAgentOverrideOption( |
| 1488 | NavigationController::UserAgentOverrideOption option) { |
| 1489 | renderer_initiated_user_agent_override_option_ = option; |
| 1490 | } |
| 1491 | |
Maks Orlovich | 73f374d | 2020-04-02 12:46:13 | [diff] [blame] | 1492 | const blink::UserAgentOverride& WebContentsImpl::GetUserAgentOverride() { |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1493 | return renderer_preferences_.user_agent_override; |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 1494 | } |
| 1495 | |
Scott Violet | 2a6c5bff | 2020-04-29 23:59:06 | [diff] [blame] | 1496 | bool WebContentsImpl::ShouldOverrideUserAgentForRendererInitiatedNavigation() { |
| 1497 | NavigationEntryImpl* current_entry = controller_.GetLastCommittedEntry(); |
| 1498 | if (!current_entry) |
| 1499 | return should_override_user_agent_in_new_tabs_; |
| 1500 | |
| 1501 | switch (renderer_initiated_user_agent_override_option_) { |
| 1502 | case NavigationController::UA_OVERRIDE_INHERIT: |
| 1503 | return current_entry->GetIsOverridingUserAgent(); |
| 1504 | case NavigationController::UA_OVERRIDE_TRUE: |
| 1505 | return true; |
| 1506 | case NavigationController::UA_OVERRIDE_FALSE: |
| 1507 | return false; |
| 1508 | default: |
| 1509 | break; |
| 1510 | } |
| 1511 | return false; |
Changwan Ryu | c1134a8 | 2018-03-07 02:10:14 | [diff] [blame] | 1512 | } |
| 1513 | |
dmazzoni | dd3d51a7 | 2016-12-14 18:41:01 | [diff] [blame] | 1514 | void WebContentsImpl::EnableWebContentsOnlyAccessibilityMode() { |
Dominic Mazzoni | d9fda17 | 2019-03-07 17:12:07 | [diff] [blame] | 1515 | // If accessibility is already enabled, we'll need to force a reset |
| 1516 | // in order to ensure new observers of accessibility events get the |
| 1517 | // full accessibility tree from scratch. |
| 1518 | bool need_reset = GetAccessibilityMode().has_mode(ui::AXMode::kWebContents); |
| 1519 | |
| 1520 | ui::AXMode desired_mode = |
| 1521 | GetContentClient()->browser()->GetAXModeForBrowserContext( |
| 1522 | GetBrowserContext()); |
| 1523 | desired_mode |= ui::kAXModeWebContentsOnly; |
| 1524 | AddAccessibilityMode(desired_mode); |
| 1525 | |
| 1526 | if (need_reset) { |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1527 | for (RenderFrameHost* rfh : GetAllFrames()) |
| 1528 | ResetAccessibility(rfh); |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1529 | } |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1530 | } |
| 1531 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1532 | bool WebContentsImpl::IsWebContentsOnlyAccessibilityModeForTesting() { |
Doug Turner | 63f3c7b | 2017-07-29 05:10:01 | [diff] [blame] | 1533 | return accessibility_mode_ == ui::kAXModeWebContentsOnly; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1534 | } |
| 1535 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1536 | bool WebContentsImpl::IsFullAccessibilityModeForTesting() { |
Doug Turner | 63f3c7b | 2017-07-29 05:10:01 | [diff] [blame] | 1537 | return accessibility_mode_ == ui::kAXModeComplete; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1538 | } |
| 1539 | |
Becca Hughes | 6daf566 | 2018-06-27 16:50:54 | [diff] [blame] | 1540 | #if defined(OS_ANDROID) |
| 1541 | |
| 1542 | void WebContentsImpl::SetDisplayCutoutSafeArea(gfx::Insets insets) { |
Becca Hughes | 8633462 | 2018-07-09 21:29:38 | [diff] [blame] | 1543 | if (display_cutout_host_impl_) |
| 1544 | display_cutout_host_impl_->SetDisplayCutoutSafeArea(insets); |
Becca Hughes | 6daf566 | 2018-06-27 16:50:54 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | #endif |
| 1548 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1549 | const base::string16& WebContentsImpl::GetTitle() { |
Nasko Oskov | 2f7d211 | 2019-10-29 03:26:57 | [diff] [blame] | 1550 | WebUI* our_web_ui = |
| 1551 | GetRenderManager()->speculative_frame_host() |
| 1552 | ? GetRenderManager()->speculative_frame_host()->web_ui() |
| 1553 | : GetRenderManager()->current_frame_host()->web_ui(); |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 1554 | if (our_web_ui) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1555 | // Don't override the title in view source mode. |
Carlos IL | 4dea890 | 2020-05-26 15:14:29 | [diff] [blame] | 1556 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1557 | if (!(entry && entry->IsViewSourceMode())) { |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 1558 | // Give the Web UI the chance to override our title. |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1559 | const base::string16& title = our_web_ui->GetOverriddenTitle(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1560 | if (!title.empty()) |
| 1561 | return title; |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | // We use the title for the last committed entry rather than a pending |
| 1566 | // navigation entry. For example, when the user types in a URL, we want to |
| 1567 | // keep the old page's title until the new load has committed and we get a new |
| 1568 | // title. |
Carlos IL | 4dea890 | 2020-05-26 15:14:29 | [diff] [blame] | 1569 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1570 | |
creis | 072b61f | 2015-09-28 20:52:24 | [diff] [blame] | 1571 | // We make an exception for initial navigations. We only want to use the title |
| 1572 | // from the visible entry if: |
| 1573 | // 1. The pending entry has been explicitly assigned a title to display. |
| 1574 | // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back), |
| 1575 | // which case there is a pending entry index other than -1. |
| 1576 | // |
| 1577 | // Otherwise, we want to stick with the last committed entry's title during |
| 1578 | // new navigations, which have pending entries at index -1 with no title. |
| 1579 | if (controller_.IsInitialNavigation() && |
| 1580 | ((controller_.GetVisibleEntry() && |
| 1581 | !controller_.GetVisibleEntry()->GetTitle().empty()) || |
| 1582 | controller_.GetPendingEntryIndex() != -1)) { |
| 1583 | entry = controller_.GetVisibleEntry(); |
[email protected] | 9eeafc01 | 2013-11-25 23:49:47 | [diff] [blame] | 1584 | } |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1585 | |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 1586 | if (entry) { |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame] | 1587 | return entry->GetTitleForDisplay(); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 1588 | } |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 1589 | |
| 1590 | // |page_title_when_no_navigation_entry_| is finally used |
| 1591 | // if no title cannot be retrieved. |
| 1592 | return page_title_when_no_navigation_entry_; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1593 | } |
| 1594 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1595 | SiteInstanceImpl* WebContentsImpl::GetSiteInstance() { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1596 | return GetRenderManager()->current_host()->GetSiteInstance(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1597 | } |
| 1598 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1599 | bool WebContentsImpl::IsLoading() { |
Carlos IL | d51e770 | 2020-05-07 18:51:39 | [diff] [blame] | 1600 | return frame_tree_.IsLoading(); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1601 | } |
| 1602 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1603 | double WebContentsImpl::GetLoadProgress() { |
Peter Boström | 18a40fa | 2018-10-31 19:03:50 | [diff] [blame] | 1604 | return frame_tree_.load_progress(); |
| 1605 | } |
| 1606 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1607 | bool WebContentsImpl::IsLoadingToDifferentDocument() { |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 1608 | return IsLoading() && is_load_to_different_document_; |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 1609 | } |
| 1610 | |
Alexander Timin | dd0fa0c5 | 2019-11-06 13:03:37 | [diff] [blame] | 1611 | bool WebContentsImpl::IsDocumentOnLoadCompletedInMainFrame() { |
| 1612 | return GetRenderViewHost()->IsDocumentOnLoadCompletedInMainFrame(); |
| 1613 | } |
| 1614 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1615 | bool WebContentsImpl::IsWaitingForResponse() { |
Peter Boström | a9a27f6e | 2018-11-21 13:12:19 | [diff] [blame] | 1616 | NavigationRequest* ongoing_navigation_request = |
| 1617 | frame_tree_.root()->navigation_request(); |
| 1618 | |
| 1619 | // An ongoing navigation request means we're waiting for a response. |
| 1620 | return ongoing_navigation_request != nullptr; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1621 | } |
| 1622 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1623 | const net::LoadStateWithParam& WebContentsImpl::GetLoadState() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1624 | return load_state_; |
| 1625 | } |
| 1626 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1627 | const base::string16& WebContentsImpl::GetLoadStateHost() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1628 | return load_state_host_; |
| 1629 | } |
| 1630 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1631 | uint64_t WebContentsImpl::GetUploadSize() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1632 | return upload_size_; |
| 1633 | } |
| 1634 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1635 | uint64_t WebContentsImpl::GetUploadPosition() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1636 | return upload_position_; |
| 1637 | } |
| 1638 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1639 | const std::string& WebContentsImpl::GetEncoding() { |
Alexander Timin | e5f20e2 | 2019-10-09 23:22:35 | [diff] [blame] | 1640 | return GetMainFrame()->GetEncoding(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1641 | } |
| 1642 | |
Charles Zhao | d72f99d | 2018-09-17 14:18:27 | [diff] [blame] | 1643 | bool WebContentsImpl::WasDiscarded() { |
| 1644 | return GetFrameTree()->root()->was_discarded(); |
| 1645 | } |
| 1646 | |
Shubhie Panicker | ddf2a4e | 2018-03-06 00:09:06 | [diff] [blame] | 1647 | void WebContentsImpl::SetWasDiscarded(bool was_discarded) { |
| 1648 | GetFrameTree()->root()->set_was_discarded(); |
| 1649 | } |
| 1650 | |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 1651 | void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size, |
| 1652 | bool stay_hidden) { |
[email protected] | 5a65223 | 2013-02-12 06:15:25 | [diff] [blame] | 1653 | DCHECK(!is_being_destroyed_); |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 1654 | if (stay_hidden) |
| 1655 | ++hidden_capturer_count_; |
| 1656 | else |
| 1657 | ++visible_capturer_count_; |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1658 | |
| 1659 | // Note: This provides a hint to upstream code to size the views optimally |
| 1660 | // for quality (e.g., to avoid scaling). |
| 1661 | if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) { |
| 1662 | preferred_size_for_capture_ = capture_size; |
| 1663 | OnPreferredSizeChanged(preferred_size_); |
| 1664 | } |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1665 | |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 1666 | UpdateVisibilityAndNotifyPageAndView(GetVisibility()); |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1667 | } |
| 1668 | |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 1669 | void WebContentsImpl::DecrementCapturerCount(bool stay_hidden) { |
| 1670 | if (stay_hidden) |
| 1671 | --hidden_capturer_count_; |
| 1672 | else |
| 1673 | --visible_capturer_count_; |
| 1674 | DCHECK_GE(hidden_capturer_count_, 0); |
| 1675 | DCHECK_GE(visible_capturer_count_, 0); |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1676 | |
[email protected] | 5a65223 | 2013-02-12 06:15:25 | [diff] [blame] | 1677 | if (is_being_destroyed_) |
| 1678 | return; |
| 1679 | |
Francois Doray | 24fc62c | 2017-12-11 17:27:33 | [diff] [blame] | 1680 | if (!IsBeingCaptured()) { |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1681 | const gfx::Size old_size = preferred_size_for_capture_; |
| 1682 | preferred_size_for_capture_ = gfx::Size(); |
| 1683 | OnPreferredSizeChanged(old_size); |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1684 | } |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 1685 | |
| 1686 | UpdateVisibilityAndNotifyPageAndView(GetVisibility()); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1687 | } |
| 1688 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1689 | bool WebContentsImpl::IsBeingCaptured() { |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 1690 | return visible_capturer_count_ + hidden_capturer_count_ > 0; |
[email protected] | f2bd4081 | 2013-07-20 04:30:44 | [diff] [blame] | 1691 | } |
| 1692 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1693 | bool WebContentsImpl::IsAudioMuted() { |
Guido Urdaneta | f837294 | 2019-11-15 09:47:21 | [diff] [blame] | 1694 | return audio_stream_factory_ && audio_stream_factory_->IsMuted(); |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | void WebContentsImpl::SetAudioMuted(bool mute) { |
| 1698 | DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted() |
| 1699 | << " for WebContentsImpl@" << this; |
| 1700 | |
| 1701 | if (mute == IsAudioMuted()) |
| 1702 | return; |
| 1703 | |
Guido Urdaneta | f837294 | 2019-11-15 09:47:21 | [diff] [blame] | 1704 | GetAudioStreamFactory()->SetMuted(mute); |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1705 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 1706 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 1707 | observer->DidUpdateAudioMutingState(mute); |
| 1708 | }); |
Jan Rucka | 442c83f | 2017-08-08 13:27:54 | [diff] [blame] | 1709 | // Notification for UI updates in response to the changed muting state. |
Collin Baker | af540cf | 2019-09-20 20:54:16 | [diff] [blame] | 1710 | NotifyNavigationStateChanged(INVALIDATE_TYPE_AUDIO); |
Jan Rucka | 442c83f | 2017-08-08 13:27:54 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | bool WebContentsImpl::IsCurrentlyAudible() { |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 1714 | return is_currently_audible_; |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1715 | } |
| 1716 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1717 | bool WebContentsImpl::IsConnectedToBluetoothDevice() { |
ortuno | df4d798 | 2016-04-08 02:33:35 | [diff] [blame] | 1718 | return bluetooth_connected_device_count_ > 0; |
ortuno | 32e7db3c | 2016-03-29 16:14:20 | [diff] [blame] | 1719 | } |
| 1720 | |
Ovidio Henriquez | 76696f6 | 2020-07-08 03:06:59 | [diff] [blame] | 1721 | bool WebContentsImpl::IsScanningForBluetoothDevices() { |
| 1722 | return bluetooth_scanning_sessions_count_ > 0; |
| 1723 | } |
| 1724 | |
Lucas Furukawa Gadani | 4b4eed0 | 2019-06-04 23:12:04 | [diff] [blame] | 1725 | bool WebContentsImpl::IsConnectedToSerialPort() { |
Reilly Grant | 5e7c79b2 | 2019-04-09 17:26:20 | [diff] [blame] | 1726 | return serial_active_frame_count_ > 0; |
| 1727 | } |
| 1728 | |
Matt Reynolds | e8c6c1f | 2019-11-02 09:53:53 | [diff] [blame] | 1729 | bool WebContentsImpl::IsConnectedToHidDevice() { |
| 1730 | return hid_active_frame_count_ > 0; |
| 1731 | } |
| 1732 | |
Marijn Kruisselbrink | 2905104 | 2019-08-06 22:56:55 | [diff] [blame] | 1733 | bool WebContentsImpl::HasNativeFileSystemHandles() { |
| 1734 | return native_file_system_handle_count_ > 0; |
| 1735 | } |
Marijn Kruisselbrink | f1714aa2 | 2019-07-02 03:45:33 | [diff] [blame] | 1736 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1737 | bool WebContentsImpl::HasPictureInPictureVideo() { |
sawtelle | a7333a8 | 2018-05-31 02:36:36 | [diff] [blame] | 1738 | return has_picture_in_picture_video_; |
| 1739 | } |
| 1740 | |
| 1741 | void WebContentsImpl::SetHasPictureInPictureVideo( |
| 1742 | bool has_picture_in_picture_video) { |
| 1743 | // If status of |this| is already accurate, there is no need to update. |
| 1744 | if (has_picture_in_picture_video == has_picture_in_picture_video_) |
| 1745 | return; |
| 1746 | has_picture_in_picture_video_ = has_picture_in_picture_video; |
| 1747 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 1748 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 1749 | observer->MediaPictureInPictureChanged(has_picture_in_picture_video_); |
| 1750 | }); |
sawtelle | a7333a8 | 2018-05-31 02:36:36 | [diff] [blame] | 1751 | } |
| 1752 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1753 | bool WebContentsImpl::IsCrashed() { |
Dominic Mazzoni | 73a4832 | 2018-05-25 18:14:07 | [diff] [blame] | 1754 | switch (crashed_status_) { |
| 1755 | case base::TERMINATION_STATUS_PROCESS_CRASHED: |
| 1756 | case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
| 1757 | case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
| 1758 | case base::TERMINATION_STATUS_OOM: |
| 1759 | case base::TERMINATION_STATUS_LAUNCH_FAILED: |
Darin Fisher | 6cf20e78 | 2020-08-07 22:25:36 | [diff] [blame] | 1760 | #if defined(OS_CHROMEOS) || BUILDFLAG(IS_LACROS) |
Dominic Mazzoni | 73a4832 | 2018-05-25 18:14:07 | [diff] [blame] | 1761 | case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM: |
oshima | 62022572 | 2015-06-04 19:45:27 | [diff] [blame] | 1762 | #endif |
Dominic Mazzoni | 73a4832 | 2018-05-25 18:14:07 | [diff] [blame] | 1763 | #if defined(OS_ANDROID) |
| 1764 | case base::TERMINATION_STATUS_OOM_PROTECTED: |
| 1765 | #endif |
Will Harris | 07925d1 | 2019-10-31 03:03:05 | [diff] [blame] | 1766 | #if defined(OS_WIN) |
| 1767 | case base::TERMINATION_STATUS_INTEGRITY_FAILURE: |
| 1768 | #endif |
Dominic Mazzoni | 73a4832 | 2018-05-25 18:14:07 | [diff] [blame] | 1769 | return true; |
| 1770 | case base::TERMINATION_STATUS_NORMAL_TERMINATION: |
| 1771 | case base::TERMINATION_STATUS_STILL_RUNNING: |
| 1772 | return false; |
| 1773 | case base::TERMINATION_STATUS_MAX_ENUM: |
| 1774 | NOTREACHED(); |
| 1775 | return false; |
| 1776 | } |
| 1777 | |
| 1778 | NOTREACHED(); |
| 1779 | return false; |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1780 | } |
| 1781 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1782 | void WebContentsImpl::SetIsCrashed(base::TerminationStatus status, |
| 1783 | int error_code) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 1784 | if (status == crashed_status_) |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1785 | return; |
| 1786 | |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 1787 | crashed_status_ = status; |
| 1788 | crashed_error_code_ = error_code; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1789 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1790 | } |
| 1791 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1792 | base::TerminationStatus WebContentsImpl::GetCrashedStatus() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1793 | return crashed_status_; |
| 1794 | } |
| 1795 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1796 | int WebContentsImpl::GetCrashedErrorCode() { |
afakhry | 9824183 | 2016-03-11 19:27:47 | [diff] [blame] | 1797 | return crashed_error_code_; |
| 1798 | } |
| 1799 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1800 | bool WebContentsImpl::IsBeingDestroyed() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1801 | return is_being_destroyed_; |
| 1802 | } |
| 1803 | |
[email protected] | 7f92483 | 2014-08-09 05:57:22 | [diff] [blame] | 1804 | void WebContentsImpl::NotifyNavigationStateChanged( |
| 1805 | InvalidateTypes changed_flags) { |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 1806 | // Notify the media observer of potential audibility changes. |
Collin Baker | af540cf | 2019-09-20 20:54:16 | [diff] [blame] | 1807 | if (changed_flags & INVALIDATE_TYPE_AUDIO) { |
mlamouri | 44e4ef4 | 2016-01-20 18:42:27 | [diff] [blame] | 1808 | media_web_contents_observer_->MaybeUpdateAudibleState(); |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 1809 | } |
| 1810 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1811 | if (delegate_) |
| 1812 | delegate_->NavigationStateChanged(this, changed_flags); |
wjmaclean | 1dabf3e3 | 2016-05-13 23:34:44 | [diff] [blame] | 1813 | |
| 1814 | if (GetOuterWebContents()) |
| 1815 | GetOuterWebContents()->NotifyNavigationStateChanged(changed_flags); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1816 | } |
| 1817 | |
W. James MacLean | 6f34b04 | 2019-07-12 19:25:30 | [diff] [blame] | 1818 | RenderFrameHostImpl* WebContentsImpl::GetFocusedFrameFromFocusedDelegate() { |
| 1819 | FrameTreeNode* focused_node = |
| 1820 | GetFocusedWebContents()->frame_tree_.GetFocusedFrame(); |
| 1821 | return focused_node ? focused_node->current_frame_host() : nullptr; |
| 1822 | } |
| 1823 | |
David Black | 9cca359 | 2019-11-06 23:02:22 | [diff] [blame] | 1824 | void WebContentsImpl::OnVerticalScrollDirectionChanged( |
| 1825 | viz::VerticalScrollDirection scroll_direction) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 1826 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 1827 | observer->DidChangeVerticalScrollDirection(scroll_direction); |
| 1828 | }); |
David Black | 9cca359 | 2019-11-06 23:02:22 | [diff] [blame] | 1829 | } |
| 1830 | |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 1831 | void WebContentsImpl::OnAudioStateChanged() { |
| 1832 | // This notification can come from any embedded contents or from this |
| 1833 | // WebContents' stream monitor. Aggregate these signals to get the actual |
| 1834 | // state. |
Jeremy Roman | 03ce13ce | 2020-05-29 22:16:57 | [diff] [blame] | 1835 | // |
| 1836 | // Note that guests may not be attached as inner contents, and so may need to |
| 1837 | // be checked separately. |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 1838 | bool is_currently_audible = |
| 1839 | audio_stream_monitor_.IsCurrentlyAudible() || |
| 1840 | (browser_plugin_embedder_ && |
Jeremy Roman | 03ce13ce | 2020-05-29 22:16:57 | [diff] [blame] | 1841 | browser_plugin_embedder_->AreAnyGuestsCurrentlyAudible()) || |
| 1842 | AnyInnerWebContents(this, [](WebContents* inner_contents) { |
| 1843 | return inner_contents->IsCurrentlyAudible(); |
| 1844 | }); |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 1845 | if (is_currently_audible == is_currently_audible_) |
| 1846 | return; |
| 1847 | |
| 1848 | // Update internal state. |
| 1849 | is_currently_audible_ = is_currently_audible; |
| 1850 | was_ever_audible_ = was_ever_audible_ || is_currently_audible_; |
| 1851 | |
Gyuyoung Kim | 877e86d | 2020-07-21 04:01:02 | [diff] [blame] | 1852 | ExecutePageBroadcastMethod(base::BindRepeating( |
| 1853 | [](bool is_currently_audible, RenderViewHostImpl* rvh) { |
| 1854 | if (auto& broadcast = rvh->GetAssociatedPageBroadcast()) |
| 1855 | broadcast->AudioStateChanged(is_currently_audible); |
| 1856 | }, |
| 1857 | is_currently_audible_)); |
altimin | d8bd26c | 2016-11-04 11:44:54 | [diff] [blame] | 1858 | |
altimin | ec87fd1f | 2016-11-17 20:22:49 | [diff] [blame] | 1859 | // Notification for UI updates in response to the changed audio state. |
Collin Baker | af540cf | 2019-09-20 20:54:16 | [diff] [blame] | 1860 | NotifyNavigationStateChanged(INVALIDATE_TYPE_AUDIO); |
Jan Rucka | 442c83f | 2017-08-08 13:27:54 | [diff] [blame] | 1861 | |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 1862 | // Ensure that audio state changes propagate from innermost to outermost |
| 1863 | // WebContents. |
| 1864 | if (GetOuterWebContents()) |
| 1865 | GetOuterWebContents()->OnAudioStateChanged(); |
Tommy Steimel | 1836051 | 2017-11-01 00:38:19 | [diff] [blame] | 1866 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 1867 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 1868 | observer->OnAudioStateChanged(is_currently_audible_); |
| 1869 | }); |
altimin | d8bd26c | 2016-11-04 11:44:54 | [diff] [blame] | 1870 | } |
| 1871 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1872 | base::TimeTicks WebContentsImpl::GetLastActiveTime() { |
[email protected] | 9a89045 | 2014-02-13 22:21:02 | [diff] [blame] | 1873 | return last_active_time_; |
[email protected] | 3e32414 | 2012-06-25 18:26:33 | [diff] [blame] | 1874 | } |
| 1875 | |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 1876 | void WebContentsImpl::WasShown() { |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 1877 | UpdateVisibilityAndNotifyPageAndView(Visibility::VISIBLE); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1878 | } |
| 1879 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1880 | void WebContentsImpl::WasHidden() { |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 1881 | UpdateVisibilityAndNotifyPageAndView(Visibility::HIDDEN); |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 1882 | } |
| 1883 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1884 | bool WebContentsImpl::HasRecentInteractiveInputEvent() { |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 1885 | static constexpr base::TimeDelta kMaxInterval = |
| 1886 | base::TimeDelta::FromSeconds(5); |
| 1887 | base::TimeDelta delta = |
| 1888 | ui::EventTimeForNow() - last_interactive_input_event_time_; |
| 1889 | // Note: the expectation is that the caller is typically expecting an input |
| 1890 | // event, e.g. validating that a WebUI message that requires a gesture is |
Daniel Cheng | e81030b3 | 2019-07-17 20:20:23 | [diff] [blame] | 1891 | // actually attached to a gesture. |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 1892 | return delta <= kMaxInterval; |
| 1893 | } |
| 1894 | |
Avi Drissman | 738ea19 | 2018-08-29 20:24:16 | [diff] [blame] | 1895 | void WebContentsImpl::SetIgnoreInputEvents(bool ignore_input_events) { |
| 1896 | ignore_input_events_ = ignore_input_events; |
| 1897 | } |
| 1898 | |
Bo Liu | 168c864 | 2017-08-28 18:26:02 | [diff] [blame] | 1899 | #if defined(OS_ANDROID) |
Bo Liu | 16dd7b832 | 2018-05-02 21:19:50 | [diff] [blame] | 1900 | void WebContentsImpl::SetMainFrameImportance( |
| 1901 | ChildProcessImportance importance) { |
| 1902 | GetMainFrame()->GetRenderWidgetHost()->SetImportance(importance); |
Bo Liu | 7c6779e9 | 2017-08-16 02:02:28 | [diff] [blame] | 1903 | } |
Bo Liu | 168c864 | 2017-08-28 18:26:02 | [diff] [blame] | 1904 | #endif |
Bo Liu | 7c6779e9 | 2017-08-16 02:02:28 | [diff] [blame] | 1905 | |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1906 | void WebContentsImpl::WasOccluded() { |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 1907 | UpdateVisibilityAndNotifyPageAndView(Visibility::OCCLUDED); |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1908 | } |
| 1909 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 1910 | Visibility WebContentsImpl::GetVisibility() { |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 1911 | return visibility_; |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 1912 | } |
| 1913 | |
Rakina Zata Amni | 26e8d8a | 2020-08-05 06:06:06 | [diff] [blame] | 1914 | bool WebContentsImpl::NeedToFireBeforeUnloadOrUnloadEvents() { |
Alexander Timin | c7bee32 | 2020-05-19 17:54:34 | [diff] [blame] | 1915 | if (!notify_disconnection_) |
Alex Moshchuk | 6fcaca75 | 2018-07-14 02:13:59 | [diff] [blame] | 1916 | return false; |
| 1917 | |
| 1918 | // Don't fire if the main frame's RenderViewHost indicates that beforeunload |
| 1919 | // and unload have already executed (e.g., after receiving a ClosePage ACK) |
| 1920 | // or should be ignored. |
| 1921 | if (GetRenderViewHost()->SuddenTerminationAllowed()) |
| 1922 | return false; |
| 1923 | |
Alex Moshchuk | c78dbc72 | 2019-10-31 20:00:50 | [diff] [blame] | 1924 | // 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] | 1925 | // unload-time event handlers. |
Alex Moshchuk | c78dbc72 | 2019-10-31 20:00:50 | [diff] [blame] | 1926 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 1927 | RenderFrameHostImpl* rfh = node->current_frame_host(); |
| 1928 | |
Rakina Zata Amni | 26e8d8a | 2020-08-05 06:06:06 | [diff] [blame] | 1929 | // No need to run beforeunload/unload-time events if the RenderFrame isn't |
| 1930 | // live. |
Alex Moshchuk | c78dbc72 | 2019-10-31 20:00:50 | [diff] [blame] | 1931 | if (!rfh->IsRenderFrameLive()) |
| 1932 | continue; |
Rakina Zata Amni | 26e8d8a | 2020-08-05 06:06:06 | [diff] [blame] | 1933 | bool should_run_before_unload_handler = |
Dave Tapuska | 97d22ab | 2019-12-03 17:56:36 | [diff] [blame] | 1934 | rfh->GetSuddenTerminationDisablerState( |
Rakina Zata Amni | 26e8d8a | 2020-08-05 06:06:06 | [diff] [blame] | 1935 | blink::mojom::SuddenTerminationDisablerType::kBeforeUnloadHandler); |
| 1936 | bool should_run_unload_handler = rfh->GetSuddenTerminationDisablerState( |
| 1937 | blink::mojom::SuddenTerminationDisablerType::kUnloadHandler); |
| 1938 | bool should_run_page_hide_handler = rfh->GetSuddenTerminationDisablerState( |
| 1939 | blink::mojom::SuddenTerminationDisablerType::kPageHideHandler); |
| 1940 | auto* rvh = static_cast<RenderViewHostImpl*>(rfh->GetRenderViewHost()); |
| 1941 | // If the tab is already hidden, we should not run visibilitychange |
| 1942 | // handlers. |
| 1943 | bool is_page_visible = rvh->GetPageLifecycleStateManager() |
| 1944 | ->CalculatePageLifecycleState() |
| 1945 | ->visibility == PageVisibilityState::kVisible; |
| 1946 | |
| 1947 | bool should_run_visibility_change_handler = |
| 1948 | is_page_visible && rfh->GetSuddenTerminationDisablerState( |
| 1949 | blink::mojom::SuddenTerminationDisablerType:: |
| 1950 | kVisibilityChangeHandler); |
| 1951 | if (should_run_before_unload_handler || should_run_unload_handler || |
| 1952 | should_run_page_hide_handler || should_run_visibility_change_handler) { |
Alex Moshchuk | c78dbc72 | 2019-10-31 20:00:50 | [diff] [blame] | 1953 | return true; |
| 1954 | } |
Aditya Keerthi | 34f37e6 | 2019-03-08 15:54:53 | [diff] [blame] | 1955 | } |
Alex Moshchuk | 6fcaca75 | 2018-07-14 02:13:59 | [diff] [blame] | 1956 | |
Alex Moshchuk | c78dbc72 | 2019-10-31 20:00:50 | [diff] [blame] | 1957 | return false; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1958 | } |
| 1959 | |
Chris Hamilton | 3b3e315d | 2018-09-19 13:16:21 | [diff] [blame] | 1960 | void WebContentsImpl::DispatchBeforeUnload(bool auto_cancel) { |
| 1961 | auto before_unload_type = |
| 1962 | auto_cancel ? RenderFrameHostImpl::BeforeUnloadType::DISCARD |
| 1963 | : RenderFrameHostImpl::BeforeUnloadType::TAB_CLOSE; |
| 1964 | GetMainFrame()->DispatchBeforeUnload(before_unload_type, false); |
[email protected] | 1c3f80bd | 2014-04-08 23:02:06 | [diff] [blame] | 1965 | } |
| 1966 | |
W. James MacLean | 2539adb3 | 2019-12-13 00:40:44 | [diff] [blame] | 1967 | bool WebContentsImpl::IsInnerWebContentsForGuest() { |
| 1968 | return !!browser_plugin_guest_; |
| 1969 | } |
| 1970 | |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 1971 | void WebContentsImpl::AttachInnerWebContents( |
| 1972 | std::unique_ptr<WebContents> inner_web_contents, |
W. James MacLean | 6288398 | 2019-11-12 20:39:00 | [diff] [blame] | 1973 | RenderFrameHost* render_frame_host, |
| 1974 | bool is_full_page) { |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 1975 | WebContentsImpl* inner_web_contents_impl = |
| 1976 | static_cast<WebContentsImpl*>(inner_web_contents.get()); |
| 1977 | DCHECK(!inner_web_contents_impl->node_.outer_web_contents()); |
| 1978 | auto* render_frame_host_impl = |
| 1979 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
Fergal Daly | 445af93 | 2020-06-02 06:37:23 | [diff] [blame] | 1980 | DCHECK_EQ(&frame_tree_, render_frame_host_impl->frame_tree()); |
Lucas Furukawa Gadani | 105de1e81 | 2018-05-31 19:38:39 | [diff] [blame] | 1981 | |
Yuzu Saijo | 3f86fb2 | 2020-06-11 03:51:10 | [diff] [blame] | 1982 | // Mark |render_frame_host_impl| as outer delegate frame. |
| 1983 | render_frame_host_impl->SetIsOuterDelegateFrame(true); |
| 1984 | |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 1985 | RenderFrameHostManager* inner_render_manager = |
| 1986 | inner_web_contents_impl->GetRenderManager(); |
| 1987 | RenderFrameHostImpl* inner_main_frame = |
| 1988 | inner_render_manager->current_frame_host(); |
| 1989 | RenderViewHostImpl* inner_render_view_host = |
| 1990 | inner_render_manager->current_host(); |
| 1991 | auto* outer_render_manager = |
| 1992 | render_frame_host_impl->frame_tree_node()->render_manager(); |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 1993 | |
Lucas Furukawa Gadani | 105de1e81 | 2018-05-31 19:38:39 | [diff] [blame] | 1994 | // When attaching a WebContents as an inner WebContents, we need to replace |
| 1995 | // the Webcontents' view with a WebContentsViewChildFrame. |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 1996 | inner_web_contents_impl->view_.reset(new WebContentsViewChildFrame( |
| 1997 | inner_web_contents_impl, |
| 1998 | GetContentClient()->browser()->GetWebContentsViewDelegate( |
| 1999 | inner_web_contents_impl), |
| 2000 | &inner_web_contents_impl->render_view_host_delegate_view_)); |
Lucas Furukawa Gadani | 105de1e81 | 2018-05-31 19:38:39 | [diff] [blame] | 2001 | |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 2002 | // When the WebContents being initialized has an opener, the browser side |
| 2003 | // Render{View,Frame}Host must be initialized and the RenderWidgetHostView |
| 2004 | // created. This is needed because the usual initialization happens during |
| 2005 | // the first navigation, but when attaching a new window we don't navigate |
| 2006 | // before attaching. If the browser side is already initialized, the calls |
| 2007 | // below will just early return. |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2008 | inner_render_manager->InitRenderView(inner_render_view_host, nullptr); |
| 2009 | inner_main_frame->Init(); |
| 2010 | if (!inner_render_manager->GetRenderWidgetHostView()) { |
| 2011 | inner_web_contents_impl->CreateRenderWidgetHostViewForRenderManager( |
| 2012 | inner_render_view_host); |
| 2013 | } |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 2014 | |
Adithya Srinivasan | e6e7f84 | 2019-12-16 18:41:36 | [diff] [blame] | 2015 | inner_web_contents_impl->RecursivelyUnregisterFrameSinkIds(); |
| 2016 | |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 2017 | // Create a link to our outer WebContents. |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2018 | node_.AttachInnerWebContents(std::move(inner_web_contents), |
| 2019 | render_frame_host_impl); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 2020 | |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 2021 | // Create a proxy in top-level RenderFrameHostManager, pointing to the |
| 2022 | // SiteInstance of the outer WebContents. The proxy will be used to send |
| 2023 | // postMessage to the inner WebContents. |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2024 | auto* proxy = inner_render_manager->CreateOuterDelegateProxy( |
| 2025 | render_frame_host_impl->GetSiteInstance()); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 2026 | |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 2027 | // When attaching a GuestView as an inner WebContents, there should already be |
| 2028 | // a live RenderFrame, which has to be swapped. When attaching a portal, there |
| 2029 | // will not be a live RenderFrame before creating the proxy. |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2030 | if (render_frame_host_impl->IsRenderFrameLive()) { |
| 2031 | inner_render_manager->SwapOuterDelegateFrame(render_frame_host_impl, proxy); |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 2032 | |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2033 | inner_web_contents_impl->ReattachToOuterWebContentsFrame(); |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 2034 | } |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 2035 | |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2036 | if (frame_tree_.GetFocusedFrame() == |
| 2037 | render_frame_host_impl->frame_tree_node()) { |
| 2038 | inner_web_contents_impl->SetFocusedFrame( |
| 2039 | inner_web_contents_impl->frame_tree_.root(), |
| 2040 | render_frame_host_impl->GetSiteInstance()); |
avallee | 7529b2a | 2017-04-26 11:37:51 | [diff] [blame] | 2041 | } |
Lucas Furukawa Gadani | 6e5b4f3 | 2019-03-02 04:18:50 | [diff] [blame] | 2042 | outer_render_manager->set_attach_complete(); |
W. James MacLean | 6288398 | 2019-11-12 20:39:00 | [diff] [blame] | 2043 | |
| 2044 | // If the inner WebContents is full frame, give it focus. |
| 2045 | if (is_full_page) { |
| 2046 | // There should only ever be one inner WebContents when |is_full_page| is |
| 2047 | // true, and it is the one we just attached. |
| 2048 | DCHECK_EQ(1u, node_.GetInnerWebContents().size()); |
| 2049 | inner_web_contents_impl->SetAsFocusedWebContentsIfNecessary(); |
| 2050 | } |
Chris Hamilton | 16b5d1d | 2020-06-04 00:08:12 | [diff] [blame] | 2051 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 2052 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2053 | observer->InnerWebContentsAttached(inner_web_contents_impl, |
| 2054 | render_frame_host, is_full_page); |
| 2055 | }); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 2056 | } |
| 2057 | |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 2058 | std::unique_ptr<WebContents> WebContentsImpl::DetachFromOuterWebContents() { |
Chris Hamilton | 16b5d1d | 2020-06-04 00:08:12 | [diff] [blame] | 2059 | auto* outer_web_contents = GetOuterWebContents(); |
| 2060 | DCHECK(outer_web_contents); |
Yuzu Saijo | 3f86fb2 | 2020-06-11 03:51:10 | [diff] [blame] | 2061 | GetMainFrame()->ParentOrOuterDelegateFrame()->SetIsOuterDelegateFrame(false); |
Chris Hamilton | 16b5d1d | 2020-06-04 00:08:12 | [diff] [blame] | 2062 | |
Adithya Srinivasan | e6e7f84 | 2019-12-16 18:41:36 | [diff] [blame] | 2063 | RecursivelyUnregisterFrameSinkIds(); |
Lucas Gadani | d2995258 | 2020-06-09 21:24:00 | [diff] [blame] | 2064 | |
| 2065 | // Each RenderViewHost has a RenderWidgetHost which can have a |
| 2066 | // RenderWidgetHostView, and it needs to be re-created with the appropriate |
| 2067 | // platform view. It is important to re-create all child views, not only the |
| 2068 | // current one, since the view can be swapped due to a cross-origin |
| 2069 | // navigation. |
| 2070 | std::set<RenderViewHostImpl*> render_view_hosts; |
| 2071 | for (auto& render_view_host : GetFrameTree()->render_view_hosts()) { |
| 2072 | if (render_view_host.second->GetWidget() && |
| 2073 | render_view_host.second->GetWidget()->GetView()) { |
| 2074 | DCHECK(render_view_host.second->GetWidget() |
| 2075 | ->GetView() |
| 2076 | ->IsRenderWidgetHostViewChildFrame()); |
| 2077 | render_view_hosts.insert(render_view_host.second); |
Kevin McNee | 6471a70 | 2020-01-27 18:23:07 | [diff] [blame] | 2078 | } |
| 2079 | } |
Lucas Gadani | d2995258 | 2020-06-09 21:24:00 | [diff] [blame] | 2080 | |
| 2081 | for (auto* render_view_host : render_view_hosts) |
| 2082 | render_view_host->GetWidget()->GetView()->Destroy(); |
| 2083 | |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 2084 | GetRenderManager()->DeleteOuterDelegateProxy( |
| 2085 | node_.OuterContentsFrameTreeNode() |
| 2086 | ->current_frame_host() |
| 2087 | ->GetSiteInstance()); |
| 2088 | view_.reset(CreateWebContentsView( |
| 2089 | this, GetContentClient()->browser()->GetWebContentsViewDelegate(this), |
| 2090 | &render_view_host_delegate_view_)); |
danakj | fc518493 | 2019-09-12 18:08:32 | [diff] [blame] | 2091 | view_->CreateView(nullptr); |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 2092 | std::unique_ptr<WebContents> web_contents = |
| 2093 | node_.DisconnectFromOuterWebContents(); |
| 2094 | DCHECK_EQ(web_contents.get(), this); |
| 2095 | node_.SetFocusedWebContents(this); |
Lucas Gadani | d2995258 | 2020-06-09 21:24:00 | [diff] [blame] | 2096 | |
| 2097 | for (auto* render_view_host : render_view_hosts) |
| 2098 | CreateRenderWidgetHostViewForRenderManager(render_view_host); |
| 2099 | |
Adithya Srinivasan | e6e7f84 | 2019-12-16 18:41:36 | [diff] [blame] | 2100 | RecursivelyRegisterFrameSinkIds(); |
Adithya Srinivasan | 6f0f67b | 2019-12-19 01:26:46 | [diff] [blame] | 2101 | // TODO(adithyas): |browser_plugin_embedder_ax_tree_id| should either not be |
| 2102 | // used for portals, or it should get a different name. |
| 2103 | GetMainFrame()->set_browser_plugin_embedder_ax_tree_id(ui::AXTreeIDUnknown()); |
| 2104 | GetMainFrame()->UpdateAXTreeData(); |
Chris Hamilton | 16b5d1d | 2020-06-04 00:08:12 | [diff] [blame] | 2105 | |
| 2106 | // Invoke on the *outer* web contents observers for symmetry. |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 2107 | outer_web_contents->observers_.ForEachObserver( |
| 2108 | [&](WebContentsObserver* observer) { |
| 2109 | observer->InnerWebContentsDetached(this); |
| 2110 | }); |
Chris Hamilton | 16b5d1d | 2020-06-04 00:08:12 | [diff] [blame] | 2111 | |
Lucas Furukawa Gadani | 9912582 | 2019-01-03 15:41:49 | [diff] [blame] | 2112 | return web_contents; |
| 2113 | } |
| 2114 | |
W. James MacLean | 2dc75ed4 | 2019-03-06 14:31:09 | [diff] [blame] | 2115 | void WebContentsImpl::RecursivelyRegisterFrameSinkIds() { |
Adithya Srinivasan | e6e7f84 | 2019-12-16 18:41:36 | [diff] [blame] | 2116 | for (auto* view : GetRenderWidgetHostViewsInWebContentsTree()) { |
| 2117 | auto* rwhvb = static_cast<RenderWidgetHostViewBase*>(view); |
| 2118 | if (rwhvb->IsRenderWidgetHostViewChildFrame()) |
| 2119 | static_cast<RenderWidgetHostViewChildFrame*>(view)->RegisterFrameSinkId(); |
| 2120 | } |
| 2121 | } |
W. James MacLean | 2dc75ed4 | 2019-03-06 14:31:09 | [diff] [blame] | 2122 | |
Adithya Srinivasan | e6e7f84 | 2019-12-16 18:41:36 | [diff] [blame] | 2123 | void WebContentsImpl::RecursivelyUnregisterFrameSinkIds() { |
| 2124 | for (auto* view : GetRenderWidgetHostViewsInWebContentsTree()) { |
| 2125 | auto* rwhvb = static_cast<RenderWidgetHostViewBase*>(view); |
| 2126 | if (rwhvb->IsRenderWidgetHostViewChildFrame()) { |
| 2127 | static_cast<RenderWidgetHostViewChildFrame*>(view) |
| 2128 | ->UnregisterFrameSinkId(); |
| 2129 | } |
W. James MacLean | 2dc75ed4 | 2019-03-06 14:31:09 | [diff] [blame] | 2130 | } |
| 2131 | } |
| 2132 | |
Lucas Furukawa Gadani | aed1fed | 2017-10-13 17:34:14 | [diff] [blame] | 2133 | void WebContentsImpl::ReattachToOuterWebContentsFrame() { |
| 2134 | DCHECK(node_.outer_web_contents()); |
| 2135 | auto* render_manager = GetRenderManager(); |
| 2136 | auto* parent_frame = |
| 2137 | node_.OuterContentsFrameTreeNode()->current_frame_host()->GetParent(); |
| 2138 | render_manager->SetRWHViewForInnerContents( |
| 2139 | render_manager->GetRenderWidgetHostView()); |
| 2140 | |
W. James MacLean | 2dc75ed4 | 2019-03-06 14:31:09 | [diff] [blame] | 2141 | RecursivelyRegisterFrameSinkIds(); |
Lucas Furukawa Gadani | aed1fed | 2017-10-13 17:34:14 | [diff] [blame] | 2142 | |
| 2143 | // Set up the the guest's AX tree to point back at the embedder's AX tree. |
| 2144 | GetMainFrame()->set_browser_plugin_embedder_ax_tree_id( |
| 2145 | parent_frame->GetAXTreeID()); |
| 2146 | GetMainFrame()->UpdateAXTreeData(); |
| 2147 | } |
| 2148 | |
Lucas Gadani | 97298562 | 2020-05-28 20:52:51 | [diff] [blame] | 2149 | void WebContentsImpl::DidActivatePortal( |
| 2150 | WebContentsImpl* predecessor_web_contents, |
| 2151 | base::TimeTicks activation_time) { |
| 2152 | DCHECK(predecessor_web_contents); |
Kevin McNee | f8eb64c | 2020-04-21 21:36:06 | [diff] [blame] | 2153 | NotifyInsidePortal(false); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 2154 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2155 | observer->DidActivatePortal(predecessor_web_contents, activation_time); |
| 2156 | }); |
Lucas Gadani | 97298562 | 2020-05-28 20:52:51 | [diff] [blame] | 2157 | GetDelegate()->WebContentsBecamePortal(predecessor_web_contents); |
Kevin McNee | f8eb64c | 2020-04-21 21:36:06 | [diff] [blame] | 2158 | } |
| 2159 | |
Adithya Srinivasan | 11af2c5 | 2019-12-16 22:52:55 | [diff] [blame] | 2160 | void WebContentsImpl::NotifyInsidePortal(bool inside_portal) { |
Gyuyoung Kim | 1c02971 | 2020-07-22 09:21:06 | [diff] [blame] | 2161 | ExecutePageBroadcastMethod(base::BindRepeating( |
| 2162 | [](bool inside_portal, RenderViewHostImpl* rvh) { |
| 2163 | if (auto& broadcast = rvh->GetAssociatedPageBroadcast()) |
| 2164 | broadcast->SetInsidePortal(inside_portal); |
| 2165 | }, |
| 2166 | inside_portal)); |
Adithya Srinivasan | 11af2c5 | 2019-12-16 22:52:55 | [diff] [blame] | 2167 | } |
| 2168 | |
dalecurtis | 6c58ed0 | 2016-10-28 23:02:37 | [diff] [blame] | 2169 | void WebContentsImpl::DidChangeVisibleSecurityState() { |
Emily Stark | c663b024 | 2019-04-26 19:34:45 | [diff] [blame] | 2170 | if (delegate_) |
dalecurtis | 6c58ed0 | 2016-10-28 23:02:37 | [diff] [blame] | 2171 | delegate_->VisibleSecurityStateChanged(this); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 2172 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2173 | observer->DidChangeVisibleSecurityState(); |
| 2174 | }); |
dalecurtis | 6c58ed0 | 2016-10-28 23:02:37 | [diff] [blame] | 2175 | } |
| 2176 | |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 2177 | const WebPreferences WebContentsImpl::ComputeWebPreferences() { |
| 2178 | TRACE_EVENT0("browser", "WebContentsImpl::ComputeWebPreferences"); |
| 2179 | WebPreferences prefs; |
| 2180 | |
| 2181 | const base::CommandLine& command_line = |
| 2182 | *base::CommandLine::ForCurrentProcess(); |
| 2183 | |
| 2184 | SetSlowWebPreferences(command_line, &prefs); |
| 2185 | |
| 2186 | prefs.web_security_enabled = |
| 2187 | !command_line.HasSwitch(switches::kDisableWebSecurity); |
| 2188 | |
| 2189 | prefs.remote_fonts_enabled = |
| 2190 | !command_line.HasSwitch(switches::kDisableRemoteFonts); |
| 2191 | prefs.application_cache_enabled = |
| 2192 | base::FeatureList::IsEnabled(blink::features::kAppCache); |
| 2193 | prefs.local_storage_enabled = |
| 2194 | !command_line.HasSwitch(switches::kDisableLocalStorage); |
| 2195 | prefs.databases_enabled = |
| 2196 | !command_line.HasSwitch(switches::kDisableDatabases); |
| 2197 | |
| 2198 | prefs.webgl1_enabled = !command_line.HasSwitch(switches::kDisable3DAPIs) && |
| 2199 | !command_line.HasSwitch(switches::kDisableWebGL); |
| 2200 | prefs.webgl2_enabled = !command_line.HasSwitch(switches::kDisable3DAPIs) && |
| 2201 | !command_line.HasSwitch(switches::kDisableWebGL) && |
| 2202 | !command_line.HasSwitch(switches::kDisableWebGL2); |
| 2203 | |
| 2204 | prefs.pepper_3d_enabled = !command_line.HasSwitch(switches::kDisablePepper3d); |
| 2205 | |
| 2206 | prefs.flash_3d_enabled = !command_line.HasSwitch(switches::kDisableFlash3d); |
| 2207 | prefs.flash_stage3d_enabled = |
| 2208 | !command_line.HasSwitch(switches::kDisableFlashStage3d); |
| 2209 | prefs.flash_stage3d_baseline_enabled = |
| 2210 | !command_line.HasSwitch(switches::kDisableFlashStage3d); |
| 2211 | |
| 2212 | prefs.allow_file_access_from_file_urls = |
| 2213 | command_line.HasSwitch(switches::kAllowFileAccessFromFiles); |
| 2214 | |
| 2215 | prefs.accelerated_2d_canvas_enabled = |
| 2216 | !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas); |
| 2217 | prefs.new_canvas_2d_api_enabled = |
Rakina Zata Amni | ea8d0c2 | 2020-07-30 17:22:50 | [diff] [blame] | 2218 | command_line.HasSwitch(switches::kEnableNewCanvas2DAPI) || |
| 2219 | base::FeatureList::IsEnabled(features::kEnableNewCanvas2DAPI); |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 2220 | prefs.antialiased_2d_canvas_disabled = |
| 2221 | command_line.HasSwitch(switches::kDisable2dCanvasAntialiasing); |
| 2222 | prefs.antialiased_clips_2d_canvas_enabled = |
| 2223 | !command_line.HasSwitch(switches::kDisable2dCanvasClipAntialiasing); |
| 2224 | |
| 2225 | prefs.disable_ipc_flooding_protection = |
| 2226 | command_line.HasSwitch(switches::kDisableIpcFloodingProtection) || |
| 2227 | command_line.HasSwitch(switches::kDisablePushStateThrottle); |
| 2228 | |
| 2229 | prefs.accelerated_video_decode_enabled = |
| 2230 | !command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode); |
| 2231 | |
| 2232 | std::string autoplay_policy = media::GetEffectiveAutoplayPolicy(command_line); |
| 2233 | if (autoplay_policy == switches::autoplay::kNoUserGestureRequiredPolicy) { |
| 2234 | prefs.autoplay_policy = AutoplayPolicy::kNoUserGestureRequired; |
| 2235 | } else if (autoplay_policy == |
| 2236 | switches::autoplay::kUserGestureRequiredPolicy) { |
| 2237 | prefs.autoplay_policy = AutoplayPolicy::kUserGestureRequired; |
| 2238 | } else if (autoplay_policy == |
| 2239 | switches::autoplay::kDocumentUserActivationRequiredPolicy) { |
| 2240 | prefs.autoplay_policy = AutoplayPolicy::kDocumentUserActivationRequired; |
| 2241 | } else { |
| 2242 | NOTREACHED(); |
| 2243 | } |
| 2244 | |
| 2245 | prefs.dont_send_key_events_to_javascript = |
| 2246 | base::FeatureList::IsEnabled(features::kDontSendKeyEventsToJavascript); |
| 2247 | |
| 2248 | // TODO(dtapuska): Enable barrel button selection drag support on Android. |
| 2249 | // crbug.com/758042 |
| 2250 | #if defined(OS_WIN) |
| 2251 | prefs.barrel_button_for_drag_enabled = |
| 2252 | base::FeatureList::IsEnabled(features::kDirectManipulationStylus); |
| 2253 | #endif // defined(OS_WIN) |
| 2254 | |
| 2255 | prefs.touch_adjustment_enabled = |
| 2256 | !command_line.HasSwitch(switches::kDisableTouchAdjustment); |
| 2257 | |
| 2258 | prefs.enable_scroll_animator = |
| 2259 | command_line.HasSwitch(switches::kEnableSmoothScrolling) || |
| 2260 | (!command_line.HasSwitch(switches::kDisableSmoothScrolling) && |
| 2261 | gfx::Animation::ScrollAnimationsEnabledBySystem()); |
| 2262 | |
| 2263 | prefs.prefers_reduced_motion = gfx::Animation::PrefersReducedMotion(); |
| 2264 | |
| 2265 | if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
| 2266 | GetRenderViewHost()->GetProcess()->GetID())) { |
| 2267 | prefs.loads_images_automatically = true; |
| 2268 | prefs.javascript_enabled = true; |
| 2269 | } |
| 2270 | |
| 2271 | prefs.viewport_enabled = command_line.HasSwitch(switches::kEnableViewport); |
| 2272 | |
| 2273 | if (IsOverridingUserAgent()) |
| 2274 | prefs.viewport_meta_enabled = false; |
| 2275 | |
| 2276 | prefs.main_frame_resizes_are_orientation_changes = |
| 2277 | command_line.HasSwitch(switches::kMainFrameResizesAreOrientationChanges); |
| 2278 | |
| 2279 | prefs.spatial_navigation_enabled = |
| 2280 | command_line.HasSwitch(switches::kEnableSpatialNavigation); |
| 2281 | |
| 2282 | if (IsSpatialNavigationDisabled()) |
| 2283 | prefs.spatial_navigation_enabled = false; |
| 2284 | |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 2285 | prefs.disable_reading_from_canvas = |
| 2286 | command_line.HasSwitch(switches::kDisableReadingFromCanvas); |
| 2287 | |
| 2288 | prefs.strict_mixed_content_checking = |
| 2289 | command_line.HasSwitch(switches::kEnableStrictMixedContentChecking); |
| 2290 | |
| 2291 | prefs.strict_powerful_feature_restrictions = command_line.HasSwitch( |
| 2292 | switches::kEnableStrictPowerfulFeatureRestrictions); |
| 2293 | |
| 2294 | const std::string blockable_mixed_content_group = |
| 2295 | base::FieldTrialList::FindFullName("BlockableMixedContent"); |
| 2296 | prefs.strictly_block_blockable_mixed_content = |
| 2297 | blockable_mixed_content_group == "StrictlyBlockBlockableMixedContent"; |
| 2298 | |
| 2299 | const std::string plugin_mixed_content_status = |
| 2300 | base::FieldTrialList::FindFullName("PluginMixedContentStatus"); |
| 2301 | prefs.block_mixed_plugin_content = |
| 2302 | plugin_mixed_content_status == "BlockableMixedContent"; |
| 2303 | |
| 2304 | prefs.v8_cache_options = GetV8CacheOptions(); |
| 2305 | |
| 2306 | prefs.user_gesture_required_for_presentation = !command_line.HasSwitch( |
| 2307 | switches::kDisableGestureRequirementForPresentation); |
| 2308 | |
| 2309 | if (HideDownloadUI()) |
| 2310 | prefs.hide_download_ui = true; |
| 2311 | |
| 2312 | // `media_controls_enabled` is `true` by default. |
| 2313 | if (HasPersistentVideo()) |
| 2314 | prefs.media_controls_enabled = false; |
| 2315 | |
| 2316 | #if defined(OS_ANDROID) |
| 2317 | display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 2318 | gfx::Size size = display.GetSizeInPixel(); |
| 2319 | int min_width = size.width() < size.height() ? size.width() : size.height(); |
| 2320 | prefs.device_scale_adjustment = GetDeviceScaleAdjustment( |
| 2321 | static_cast<int>(min_width / display.device_scale_factor())); |
| 2322 | #endif // OS_ANDROID |
| 2323 | |
| 2324 | GetContentClient()->browser()->OverrideWebkitPrefs(GetRenderViewHost(), |
| 2325 | &prefs); |
| 2326 | return prefs; |
| 2327 | } |
| 2328 | |
| 2329 | void WebContentsImpl::SetSlowWebPreferences( |
| 2330 | const base::CommandLine& command_line, |
| 2331 | WebPreferences* prefs) { |
| 2332 | if (web_preferences_.get()) { |
| 2333 | #define SET_FROM_CACHE(prefs, field) prefs->field = web_preferences_->field |
| 2334 | |
| 2335 | SET_FROM_CACHE(prefs, touch_event_feature_detection_enabled); |
| 2336 | SET_FROM_CACHE(prefs, available_pointer_types); |
| 2337 | SET_FROM_CACHE(prefs, available_hover_types); |
| 2338 | SET_FROM_CACHE(prefs, primary_pointer_type); |
| 2339 | SET_FROM_CACHE(prefs, primary_hover_type); |
| 2340 | SET_FROM_CACHE(prefs, pointer_events_max_touch_points); |
| 2341 | SET_FROM_CACHE(prefs, number_of_cpu_cores); |
| 2342 | |
| 2343 | #if defined(OS_ANDROID) |
| 2344 | SET_FROM_CACHE(prefs, video_fullscreen_orientation_lock_enabled); |
| 2345 | SET_FROM_CACHE(prefs, video_rotate_to_fullscreen_enabled); |
| 2346 | #endif |
| 2347 | |
| 2348 | #undef SET_FROM_CACHE |
| 2349 | } else { |
| 2350 | // Every prefs->field modified below should have a SET_FROM_CACHE entry |
| 2351 | // above. |
| 2352 | |
| 2353 | // On Android, Touch event feature detection is enabled by default, |
| 2354 | // Otherwise default is disabled. |
| 2355 | std::string touch_enabled_default_switch = |
| 2356 | switches::kTouchEventFeatureDetectionDisabled; |
| 2357 | #if defined(OS_ANDROID) |
| 2358 | touch_enabled_default_switch = switches::kTouchEventFeatureDetectionEnabled; |
| 2359 | #endif // defined(OS_ANDROID) |
| 2360 | const std::string touch_enabled_switch = |
| 2361 | command_line.HasSwitch(switches::kTouchEventFeatureDetection) |
| 2362 | ? command_line.GetSwitchValueASCII( |
| 2363 | switches::kTouchEventFeatureDetection) |
| 2364 | : touch_enabled_default_switch; |
| 2365 | |
| 2366 | prefs->touch_event_feature_detection_enabled = |
| 2367 | (touch_enabled_switch == switches::kTouchEventFeatureDetectionAuto) |
| 2368 | ? (ui::GetTouchScreensAvailability() == |
| 2369 | ui::TouchScreensAvailability::ENABLED) |
| 2370 | : (touch_enabled_switch.empty() || |
| 2371 | touch_enabled_switch == |
| 2372 | switches::kTouchEventFeatureDetectionEnabled); |
| 2373 | |
| 2374 | std::tie(prefs->available_pointer_types, prefs->available_hover_types) = |
| 2375 | ui::GetAvailablePointerAndHoverTypes(); |
| 2376 | prefs->primary_pointer_type = |
| 2377 | ui::GetPrimaryPointerType(prefs->available_pointer_types); |
| 2378 | prefs->primary_hover_type = |
| 2379 | ui::GetPrimaryHoverType(prefs->available_hover_types); |
| 2380 | |
| 2381 | prefs->pointer_events_max_touch_points = ui::MaxTouchPoints(); |
| 2382 | |
| 2383 | prefs->number_of_cpu_cores = base::SysInfo::NumberOfProcessors(); |
| 2384 | |
| 2385 | #if defined(OS_ANDROID) |
| 2386 | const bool device_is_phone = |
| 2387 | ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_PHONE; |
| 2388 | prefs->video_fullscreen_orientation_lock_enabled = device_is_phone; |
| 2389 | prefs->video_rotate_to_fullscreen_enabled = device_is_phone; |
| 2390 | #endif |
| 2391 | } |
| 2392 | } |
| 2393 | |
| 2394 | void WebContentsImpl::OnWebPreferencesChanged() { |
| 2395 | // This is defensive code to avoid infinite loops due to code run inside |
| 2396 | // SetWebPreferences() accidentally updating more preferences and thus |
| 2397 | // calling back into this code. See crbug.com/398751 for one past example. |
| 2398 | if (updating_web_preferences_) |
| 2399 | return; |
| 2400 | updating_web_preferences_ = true; |
| 2401 | SetWebPreferences(ComputeWebPreferences()); |
| 2402 | #if defined(OS_ANDROID) |
| 2403 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 2404 | RenderFrameHostImpl* rfh = node->current_frame_host(); |
| 2405 | if (rfh->is_local_root()) { |
| 2406 | if (auto* rwh = rfh->GetRenderWidgetHost()) |
| 2407 | rwh->SetForceEnableZoom(web_preferences_->force_enable_zoom); |
| 2408 | } |
| 2409 | } |
| 2410 | #endif |
| 2411 | updating_web_preferences_ = false; |
| 2412 | } |
| 2413 | |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 2414 | void WebContentsImpl::NotifyPreferencesChanged() { |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 2415 | // Recompute the WebPreferences based on the current state of the WebContents, |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 2416 | // etc. Note that OnWebPreferencesChanged will also call SetWebPreferences and |
| 2417 | // send the updated WebPreferences to all RenderViews for this WebContents. |
| 2418 | OnWebPreferencesChanged(); |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 2419 | } |
| 2420 | |
Bruce Long | 1e3e1f54 | 2019-10-16 17:56:28 | [diff] [blame] | 2421 | void WebContentsImpl::SyncRendererPrefs() { |
Peter Marshall | 2dc74e9 | 2020-07-29 20:02:30 | [diff] [blame] | 2422 | blink::mojom::RendererPreferences renderer_preferences = GetRendererPrefs(); |
Bruce Long | 1e3e1f54 | 2019-10-16 17:56:28 | [diff] [blame] | 2423 | RenderViewHostImpl::GetPlatformSpecificPrefs(&renderer_preferences); |
| 2424 | SendPageMessage( |
| 2425 | new PageMsg_SetRendererPrefs(MSG_ROUTING_NONE, renderer_preferences)); |
| 2426 | } |
| 2427 | |
Alexander Timin | 1cc31f4 | 2020-05-12 16:26:01 | [diff] [blame] | 2428 | void WebContentsImpl::OnCookiesAccessed(NavigationHandle* navigation, |
| 2429 | const CookieAccessDetails& details) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 2430 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2431 | observer->OnCookiesAccessed(navigation, details); |
| 2432 | }); |
Alexander Timin | 1cc31f4 | 2020-05-12 16:26:01 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | void WebContentsImpl::OnCookiesAccessed(RenderFrameHostImpl* rfh, |
| 2436 | const CookieAccessDetails& details) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 2437 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2438 | observer->OnCookiesAccessed(rfh, details); |
| 2439 | }); |
Josh Karlin | daba3932 | 2019-07-17 23:24:33 | [diff] [blame] | 2440 | } |
| 2441 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2442 | void WebContentsImpl::Stop() { |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 2443 | for (FrameTreeNode* node : frame_tree_.Nodes()) |
| 2444 | node->StopLoading(); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 2445 | observers_.ForEachObserver( |
| 2446 | [&](WebContentsObserver* observer) { observer->NavigationStopped(); }); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2447 | } |
| 2448 | |
Francois Doray | 47f759d | 2018-06-11 18:13:51 | [diff] [blame] | 2449 | void WebContentsImpl::SetPageFrozen(bool frozen) { |
| 2450 | // A visible page is never frozen. |
| 2451 | DCHECK_NE(Visibility::VISIBLE, GetVisibility()); |
| 2452 | |
Yuzu Saijo | 4fa1e9a | 2020-05-20 02:53:26 | [diff] [blame] | 2453 | for (auto& entry : frame_tree_.render_view_hosts()) { |
| 2454 | entry.second->SetIsFrozen(frozen); |
| 2455 | } |
Fadi Meawad | a6573e0 | 2018-03-10 00:52:11 | [diff] [blame] | 2456 | } |
| 2457 | |
erikchen | 6c7df7f7a | 2018-05-03 18:13:59 | [diff] [blame] | 2458 | std::unique_ptr<WebContents> WebContentsImpl::Clone() { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2459 | // We use our current SiteInstance since the cloned entry will use it anyway. |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 2460 | // 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] | 2461 | // before. |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 2462 | CreateParams create_params(GetBrowserContext(), GetSiteInstance()); |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 2463 | FrameTreeNode* opener = frame_tree_.root()->opener(); |
| 2464 | RenderFrameHostImpl* opener_rfh = nullptr; |
| 2465 | if (opener) |
| 2466 | opener_rfh = opener->current_frame_host(); |
erikchen | 6c7df7f7a | 2018-05-03 18:13:59 | [diff] [blame] | 2467 | std::unique_ptr<WebContentsImpl> tc = |
erikchen | 50735fd | 2018-05-05 15:08:33 | [diff] [blame] | 2468 | CreateWithOpener(create_params, opener_rfh); |
Lucas Furukawa Gadani | 5553a15 | 2019-01-08 18:55:57 | [diff] [blame] | 2469 | tc->GetController().CopyStateFrom(&controller_, true); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 2470 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2471 | observer->DidCloneToNewWebContents(this, tc.get()); |
| 2472 | }); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2473 | return tc; |
| 2474 | } |
| 2475 | |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2476 | void WebContentsImpl::Observe(int type, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2477 | const NotificationSource& source, |
| 2478 | const NotificationDetails& details) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2479 | switch (type) { |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2480 | case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { |
| 2481 | RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr(); |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 2482 | RenderWidgetHostView* view = host->GetView(); |
| 2483 | if (view == GetFullscreenRenderWidgetHostView()) { |
| 2484 | // We cannot just call view_->RestoreFocus() here. On some platforms, |
| 2485 | // attempting to focus the currently-invisible WebContentsView will be |
| 2486 | // flat-out ignored. Therefore, this boolean is used to track whether |
| 2487 | // we will request focus after the fullscreen widget has been |
| 2488 | // destroyed. |
| 2489 | fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus()); |
| 2490 | } else { |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2491 | for (auto i = pending_widget_views_.begin(); |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 2492 | i != pending_widget_views_.end(); ++i) { |
| 2493 | if (host->GetView() == i->second) { |
| 2494 | pending_widget_views_.erase(i); |
| 2495 | break; |
| 2496 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2497 | } |
| 2498 | } |
| 2499 | break; |
| 2500 | } |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2501 | default: |
| 2502 | NOTREACHED(); |
| 2503 | } |
| 2504 | } |
| 2505 | |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 2506 | WebContents* WebContentsImpl::GetWebContents() { |
| 2507 | return this; |
| 2508 | } |
| 2509 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 2510 | void WebContentsImpl::Init(const WebContents::CreateParams& params) { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 2511 | // This is set before initializing the render manager since |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 2512 | // RenderFrameHostManager::Init calls back into us via its delegate to ask if |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 2513 | // it should be hidden. |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 2514 | visibility_ = |
| 2515 | params.initially_hidden ? Visibility::HIDDEN : Visibility::VISIBLE; |
[email protected] | d6fa88f | 2013-10-18 16:00:43 | [diff] [blame] | 2516 | |
Sebastien Marchand | 28cf2318 | 2018-06-20 02:39:35 | [diff] [blame] | 2517 | if (!params.last_active_time.is_null()) |
| 2518 | last_active_time_ = params.last_active_time; |
| 2519 | |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2520 | scoped_refptr<SiteInstance> site_instance = params.site_instance; |
| 2521 | if (!site_instance) |
| 2522 | site_instance = SiteInstance::Create(params.browser_context); |
Lukasz Anforowicz | 3caa837 | 2018-06-05 17:22:07 | [diff] [blame] | 2523 | if (params.desired_renderer_state == CreateParams::kNoRendererProcess) { |
| 2524 | static_cast<SiteInstanceImpl*>(site_instance.get()) |
| 2525 | ->PreventAssociationWithSpareProcess(); |
| 2526 | } |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2527 | |
Fergal Daly | cb0c1fdf | 2020-03-16 07:13:49 | [diff] [blame] | 2528 | GetRenderManager()->InitRoot(site_instance.get(), |
| 2529 | params.renderer_initiated_creation); |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 2530 | |
lukasza | 5140a41 | 2016-09-15 21:12:30 | [diff] [blame] | 2531 | // blink::FrameTree::setName always keeps |unique_name| empty in case of a |
| 2532 | // main frame - let's do the same thing here. |
| 2533 | std::string unique_name; |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 2534 | frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2535 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2536 | WebContentsViewDelegate* delegate = |
| 2537 | GetContentClient()->browser()->GetWebContentsViewDelegate(this); |
| 2538 | |
W. James MacLean | 2539adb3 | 2019-12-13 00:40:44 | [diff] [blame] | 2539 | if (browser_plugin_guest_) { |
sky | 52a39e34 | 2016-12-17 17:23:22 | [diff] [blame] | 2540 | view_.reset(new WebContentsViewChildFrame( |
| 2541 | this, delegate, &render_view_host_delegate_view_)); |
| 2542 | } else { |
| 2543 | view_.reset(CreateWebContentsView(this, delegate, |
| 2544 | &render_view_host_delegate_view_)); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2545 | } |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2546 | CHECK(render_view_host_delegate_view_); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2547 | CHECK(view_.get()); |
| 2548 | |
danakj | fc518493 | 2019-09-12 18:08:32 | [diff] [blame] | 2549 | view_->CreateView(params.context); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2550 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 2551 | #if BUILDFLAG(ENABLE_PLUGINS) |
Yuzu Saijo | a11069a | 2020-04-22 10:56:55 | [diff] [blame] | 2552 | plugin_content_origin_allowlist_.reset( |
| 2553 | new PluginContentOriginAllowlist(this)); |
tommycli | eb25b2a | 2014-11-03 19:45:09 | [diff] [blame] | 2554 | #endif |
| 2555 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2556 | registrar_.Add(this, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2557 | NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 2558 | NotificationService::AllBrowserContextsAndSources()); |
[email protected] | f28ef9a3 | 2014-05-12 16:36:10 | [diff] [blame] | 2559 | |
leon.han | e4db177a | 2017-02-07 14:19:16 | [diff] [blame] | 2560 | screen_orientation_provider_.reset(new ScreenOrientationProvider(this)); |
[email protected] | 01f83f9 | 2014-06-17 14:41:54 | [diff] [blame] | 2561 | |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 2562 | #if defined(OS_ANDROID) |
Oksana Zhuravlova | 0b63433 | 2019-10-28 23:04:22 | [diff] [blame] | 2563 | DateTimeChooserAndroid::CreateForWebContents(this); |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 2564 | #endif |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 2565 | |
| 2566 | // BrowserPluginGuest::Init needs to be called after this WebContents has |
W. James MacLean | 6e78da34 | 2019-12-13 15:13:23 | [diff] [blame] | 2567 | // a RenderWidgetHostViewChildFrame. That is, |view_->CreateView| above. |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 2568 | if (browser_plugin_guest_) |
| 2569 | browser_plugin_guest_->Init(); |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 2570 | |
| 2571 | for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
| 2572 | g_created_callbacks.Get().at(i).Run(this); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 2573 | |
| 2574 | // If the WebContents creation was renderer-initiated, it means that the |
| 2575 | // corresponding RenderView and main RenderFrame have already been created. |
| 2576 | // Ensure observers are notified about this. |
| 2577 | if (params.renderer_initiated_creation) { |
Fergal Daly | bb2d659 | 2020-06-02 05:02:33 | [diff] [blame] | 2578 | GetRenderViewHost()->GetWidget()->set_renderer_initialized(true); |
Alex Moshchuk | 27caae8 | 2017-09-11 23:11:18 | [diff] [blame] | 2579 | GetRenderViewHost()->DispatchRenderViewCreated(); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 2580 | GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true); |
| 2581 | } |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 2582 | |
lof84 | 501da08 | 2016-05-23 21:22:54 | [diff] [blame] | 2583 | // Create the renderer process in advance if requested. |
Lukasz Anforowicz | 3caa837 | 2018-06-05 17:22:07 | [diff] [blame] | 2584 | if (params.desired_renderer_state == |
| 2585 | CreateParams::kInitializeAndWarmupRendererProcess) { |
lof84 | 501da08 | 2016-05-23 21:22:54 | [diff] [blame] | 2586 | if (!GetRenderManager()->current_frame_host()->IsRenderFrameLive()) { |
| 2587 | GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr); |
| 2588 | } |
| 2589 | } |
| 2590 | |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 2591 | // Ensure that observers are notified of the creation of this WebContents's |
| 2592 | // main RenderFrameHost. It must be done here for main frames, since the |
| 2593 | // NotifySwappedFromRenderManager expects view_ to already be created and that |
| 2594 | // happens after RenderFrameHostManager::Init. |
| 2595 | NotifySwappedFromRenderManager( |
| 2596 | nullptr, GetRenderManager()->current_frame_host(), true); |
Albert J. Wong | e76bf0b8 | 2019-09-27 07:47:06 | [diff] [blame] | 2597 | |
| 2598 | // For WebContents that are never shown, do critical initialization here which |
| 2599 | // would normally only happen when the WebContents is shown. |
| 2600 | if (params.is_never_visible) { |
| 2601 | // This has just been created so there can only be one frame. Thus it is |
| 2602 | // safe to initialize the root. |
| 2603 | GetMainFrame()->Init(); |
| 2604 | } |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2605 | } |
| 2606 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2607 | void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { |
| 2608 | RemoveDestructionObserver(web_contents); |
| 2609 | |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 2610 | // Clear a pending contents that has been closed before being shown. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2611 | for (auto iter = pending_contents_.begin(); iter != pending_contents_.end(); |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 2612 | ++iter) { |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 2613 | if (iter->second.contents.get() != web_contents) |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 2614 | continue; |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2615 | |
| 2616 | // Someone else has deleted the WebContents. That should never happen! |
| 2617 | // TODO(erikchen): Fix semantics here. https://crbug.com/832879. |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 2618 | iter->second.contents.release(); |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 2619 | pending_contents_.erase(iter); |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 2620 | return; |
| 2621 | } |
| 2622 | NOTREACHED(); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2623 | } |
| 2624 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2625 | void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) { |
Jan Wilken Dörrie | 73c901e | 2019-06-12 09:02:32 | [diff] [blame] | 2626 | if (!base::Contains(destruction_observers_, web_contents)) { |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2627 | destruction_observers_[web_contents] = |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 2628 | std::make_unique<DestructionObserver>(this, web_contents); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2629 | } |
| 2630 | } |
| 2631 | |
| 2632 | void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) { |
avi | a8cf8198 | 2016-08-12 20:28:46 | [diff] [blame] | 2633 | destruction_observers_.erase(web_contents); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2634 | } |
| 2635 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2636 | void WebContentsImpl::AddObserver(WebContentsObserver* observer) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2637 | observers_.AddObserver(observer); |
| 2638 | } |
| 2639 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2640 | void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2641 | observers_.RemoveObserver(observer); |
| 2642 | } |
| 2643 | |
[email protected] | 948481d | 2014-06-11 18:32:22 | [diff] [blame] | 2644 | std::set<RenderWidgetHostView*> |
| 2645 | WebContentsImpl::GetRenderWidgetHostViewsInTree() { |
| 2646 | std::set<RenderWidgetHostView*> set; |
Carlos IL | 07f282f | 2020-05-15 22:58:29 | [diff] [blame] | 2647 | for (RenderFrameHost* rfh : GetAllFrames()) { |
| 2648 | if (RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh) |
| 2649 | ->frame_tree_node() |
| 2650 | ->render_manager() |
| 2651 | ->GetRenderWidgetHostView()) { |
lfg | f949e0e | 2017-05-10 22:18:11 | [diff] [blame] | 2652 | set.insert(rwhv); |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 2653 | } |
[email protected] | 948481d | 2014-06-11 18:32:22 | [diff] [blame] | 2654 | } |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 2655 | return set; |
| 2656 | } |
| 2657 | |
Adithya Srinivasan | e6e7f84 | 2019-12-16 18:41:36 | [diff] [blame] | 2658 | std::set<RenderWidgetHostView*> |
| 2659 | WebContentsImpl::GetRenderWidgetHostViewsInWebContentsTree() { |
| 2660 | std::set<RenderWidgetHostView*> result; |
| 2661 | GetRenderWidgetHostViewsInWebContentsTree(result); |
| 2662 | return result; |
| 2663 | } |
| 2664 | |
| 2665 | void WebContentsImpl::GetRenderWidgetHostViewsInWebContentsTree( |
| 2666 | std::set<RenderWidgetHostView*>& result) { |
| 2667 | std::set<RenderWidgetHostView*> views = GetRenderWidgetHostViewsInTree(); |
| 2668 | result.insert(views.begin(), views.end()); |
| 2669 | for (auto* inner_web_contents : GetInnerWebContents()) { |
| 2670 | static_cast<WebContentsImpl*>(inner_web_contents) |
| 2671 | ->GetRenderWidgetHostViewsInWebContentsTree(result); |
| 2672 | } |
| 2673 | } |
| 2674 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2675 | void WebContentsImpl::Activate() { |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 2676 | if (delegate_) |
| 2677 | delegate_->ActivateContents(this); |
| 2678 | } |
| 2679 | |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 2680 | void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) { |
| 2681 | if (!RenderViewHostImpl::From(render_widget_host)) |
| 2682 | return; |
| 2683 | |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 2684 | if (delegate_) |
| 2685 | delegate_->LostCapture(); |
| 2686 | } |
| 2687 | |
Yue Ru Sun | 979c4b16 | 2019-11-06 16:11:04 | [diff] [blame] | 2688 | ukm::SourceId |
| 2689 | WebContentsImpl::GetUkmSourceIdForLastCommittedSourceIncludingSameDocument() |
| 2690 | const { |
| 2691 | return last_committed_source_id_including_same_document_; |
| 2692 | } |
| 2693 | |
Ahmed Fakhry | faa32d2 | 2018-10-05 15:56:16 | [diff] [blame] | 2694 | void WebContentsImpl::SetTopControlsShownRatio( |
| 2695 | RenderWidgetHostImpl* render_widget_host, |
| 2696 | float ratio) { |
| 2697 | if (!delegate_) |
| 2698 | return; |
| 2699 | |
| 2700 | RenderFrameHostImpl* rfh = GetMainFrame(); |
| 2701 | if (!rfh || render_widget_host != rfh->GetRenderWidgetHost()) |
| 2702 | return; |
| 2703 | |
| 2704 | delegate_->SetTopControlsShownRatio(this, ratio); |
Ahmed Fakhry | 58e6ef54 | 2018-09-04 18:05:38 | [diff] [blame] | 2705 | } |
| 2706 | |
Ahmed Fakhry | 58e6ef54 | 2018-09-04 18:05:38 | [diff] [blame] | 2707 | void WebContentsImpl::SetTopControlsGestureScrollInProgress(bool in_progress) { |
| 2708 | if (delegate_) |
| 2709 | delegate_->SetTopControlsGestureScrollInProgress(in_progress); |
| 2710 | } |
| 2711 | |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 2712 | void WebContentsImpl::RenderWidgetCreated( |
| 2713 | RenderWidgetHostImpl* render_widget_host) { |
| 2714 | created_widgets_.insert(render_widget_host); |
| 2715 | } |
| 2716 | |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 2717 | void WebContentsImpl::RenderWidgetDeleted( |
| 2718 | RenderWidgetHostImpl* render_widget_host) { |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 2719 | // Note that |is_being_destroyed_| can be true at this point as |
| 2720 | // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead |
| 2721 | // us here. |
| 2722 | created_widgets_.erase(render_widget_host); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 2723 | |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 2724 | if (is_being_destroyed_) |
| 2725 | return; |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 2726 | |
| 2727 | if (render_widget_host && |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 2728 | render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_ && |
| 2729 | render_widget_host->GetProcess()->GetID() == |
| 2730 | fullscreen_widget_process_id_) { |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2731 | if (delegate_ && delegate_->EmbedsFullscreenWidget()) |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2732 | delegate_->ExitFullscreenModeForTab(this); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 2733 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2734 | observer->DidDestroyFullscreenWidget(); |
| 2735 | }); |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 2736 | fullscreen_widget_process_id_ = ChildProcessHost::kInvalidUniqueID; |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 2737 | fullscreen_widget_routing_id_ = MSG_ROUTING_NONE; |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 2738 | if (fullscreen_widget_had_focus_at_shutdown_) |
| 2739 | view_->RestoreFocus(); |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 2740 | } |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 2741 | |
lfg | 7d4caad | 2017-03-22 09:01:45 | [diff] [blame] | 2742 | if (render_widget_host == mouse_lock_widget_) |
lfg | ff8dfc8d | 2016-10-21 17:42:32 | [diff] [blame] | 2743 | LostMouseLock(mouse_lock_widget_); |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 2744 | |
Joe Downing | c1a57efe | 2018-05-09 18:23:54 | [diff] [blame] | 2745 | CancelKeyboardLock(render_widget_host); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 2746 | } |
| 2747 | |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 2748 | void WebContentsImpl::RenderWidgetGotFocus( |
| 2749 | RenderWidgetHostImpl* render_widget_host) { |
calamity | 7fe55ce | 2015-04-10 03:59:37 | [diff] [blame] | 2750 | // Notify the observers if an embedded fullscreen widget was focused. |
| 2751 | if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() && |
| 2752 | render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) { |
Michael Thiessen | 896405db | 2017-07-20 17:52:32 | [diff] [blame] | 2753 | NotifyWebContentsFocused(render_widget_host); |
calamity | 7fe55ce | 2015-04-10 03:59:37 | [diff] [blame] | 2754 | } |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 2755 | } |
| 2756 | |
zijiehe | 3bee08e2 | 2017-05-17 04:14:46 | [diff] [blame] | 2757 | void WebContentsImpl::RenderWidgetLostFocus( |
| 2758 | RenderWidgetHostImpl* render_widget_host) { |
Michael Thiessen | 896405db | 2017-07-20 17:52:32 | [diff] [blame] | 2759 | // Notify the observers if an embedded fullscreen widget lost focus. |
| 2760 | if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() && |
| 2761 | render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) { |
| 2762 | NotifyWebContentsLostFocus(render_widget_host); |
| 2763 | } |
zijiehe | 3bee08e2 | 2017-05-17 04:14:46 | [diff] [blame] | 2764 | } |
| 2765 | |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 2766 | void WebContentsImpl::RenderWidgetWasResized( |
rouslan | 2f5993f | 2015-01-29 00:18:31 | [diff] [blame] | 2767 | RenderWidgetHostImpl* render_widget_host, |
| 2768 | bool width_changed) { |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2769 | RenderFrameHostImpl* rfh = GetMainFrame(); |
estade | ce344ec | 2015-01-23 00:12:29 | [diff] [blame] | 2770 | if (!rfh || render_widget_host != rfh->GetRenderWidgetHost()) |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 2771 | return; |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 2772 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 2773 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2774 | observer->MainFrameWasResized(width_changed); |
| 2775 | }); |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 2776 | } |
| 2777 | |
sky | f65d9bb | 2017-03-24 02:26:39 | [diff] [blame] | 2778 | KeyboardEventProcessingResult WebContentsImpl::PreHandleKeyboardEvent( |
| 2779 | const NativeWebKeyboardEvent& event) { |
W. James MacLean | e118727 | 2019-11-12 03:42:48 | [diff] [blame] | 2780 | auto* outermost_contents = GetOutermostWebContents(); |
| 2781 | // TODO(wjmaclean): Generalize this to forward all key events to the outermost |
| 2782 | // delegate's handler. |
Avi Drissman | 97aef04 | 2020-06-30 21:04:48 | [diff] [blame] | 2783 | if (outermost_contents != this && IsFullscreen() && |
W. James MacLean | e118727 | 2019-11-12 03:42:48 | [diff] [blame] | 2784 | event.windows_key_code == ui::VKEY_ESCAPE) { |
| 2785 | // When an inner WebContents has focus and is fullscreen, redirect <esc> |
| 2786 | // key events to the outermost WebContents so it can be handled by that |
| 2787 | // WebContents' delegate. |
| 2788 | if (outermost_contents->PreHandleKeyboardEvent(event) == |
| 2789 | KeyboardEventProcessingResult::HANDLED) { |
| 2790 | return KeyboardEventProcessingResult::HANDLED; |
| 2791 | } |
| 2792 | } |
sky | f65d9bb | 2017-03-24 02:26:39 | [diff] [blame] | 2793 | return delegate_ ? delegate_->PreHandleKeyboardEvent(this, event) |
| 2794 | : KeyboardEventProcessingResult::NOT_HANDLED; |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 2795 | } |
| 2796 | |
Dave Tapuska | 344399e | 2019-09-09 15:18:26 | [diff] [blame] | 2797 | bool WebContentsImpl::HandleMouseEvent(const blink::WebMouseEvent& event) { |
| 2798 | // Handle mouse button back/forward in the browser process after the render |
| 2799 | // process is done with the event. This ensures all renderer-initiated history |
| 2800 | // navigations can be treated consistently. |
| 2801 | if (event.GetType() == blink::WebInputEvent::Type::kMouseUp) { |
| 2802 | WebContentsImpl* outermost = GetOutermostWebContents(); |
| 2803 | if (event.button == blink::WebPointerProperties::Button::kBack && |
| 2804 | outermost->controller_.CanGoBack()) { |
| 2805 | outermost->controller_.GoBack(); |
| 2806 | return true; |
| 2807 | } else if (event.button == blink::WebPointerProperties::Button::kForward && |
| 2808 | outermost->controller_.CanGoForward()) { |
| 2809 | outermost->controller_.GoForward(); |
| 2810 | return true; |
| 2811 | } |
| 2812 | } |
| 2813 | return false; |
| 2814 | } |
| 2815 | |
Scott Violet | d5caa87 | 2018-10-16 22:00:51 | [diff] [blame] | 2816 | bool WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
[email protected] | 0b09400 | 2014-08-20 18:28:10 | [diff] [blame] | 2817 | if (browser_plugin_embedder_ && |
| 2818 | browser_plugin_embedder_->HandleKeyboardEvent(event)) { |
Scott Violet | d5caa87 | 2018-10-16 22:00:51 | [diff] [blame] | 2819 | return true; |
[email protected] | 0b09400 | 2014-08-20 18:28:10 | [diff] [blame] | 2820 | } |
Scott Violet | d5caa87 | 2018-10-16 22:00:51 | [diff] [blame] | 2821 | return delegate_ && delegate_->HandleKeyboardEvent(this, event); |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 2822 | } |
| 2823 | |
[email protected] | d92026ef | 2014-03-03 21:04:13 | [diff] [blame] | 2824 | bool WebContentsImpl::HandleWheelEvent( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2825 | const blink::WebMouseWheelEvent& event) { |
Avi Drissman | 7c57be7 | 2020-07-29 20:09:46 | [diff] [blame] | 2826 | #if !defined(OS_MAC) |
lanwei | a93644f | 2015-01-21 22:00:33 | [diff] [blame] | 2827 | // On platforms other than Mac, control+mousewheel may change zoom. On Mac, |
| 2828 | // this isn't done for two reasons: |
[email protected] | bccc447 | 2013-04-18 16:37:19 | [diff] [blame] | 2829 | // -the OS already has a gesture to do this through pinch-zoom |
| 2830 | // -if a user starts an inertial scroll, let's go, and presses control |
| 2831 | // (i.e. control+tab) then the OS's buffered scroll events will come in |
| 2832 | // with control key set which isn't what the user wants |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2833 | if (delegate_ && event.wheel_ticks_y && |
Ehsan Karamad | 0f83cb11 | 2018-09-06 22:07:36 | [diff] [blame] | 2834 | event.event_action == blink::WebMouseWheelEvent::EventAction::kPageZoom) { |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 2835 | // Count only integer cumulative scrolls as zoom events; this handles |
| 2836 | // smooth scroll and regular scroll device behavior. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2837 | zoom_scroll_remainder_ += event.wheel_ticks_y; |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 2838 | int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_); |
| 2839 | zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_; |
| 2840 | if (whole_zoom_scroll_remainder_ != 0) { |
| 2841 | delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0); |
| 2842 | } |
[email protected] | fb3f066e | 2013-02-12 19:12:52 | [diff] [blame] | 2843 | return true; |
| 2844 | } |
[email protected] | bccc447 | 2013-04-18 16:37:19 | [diff] [blame] | 2845 | #endif |
[email protected] | fb3f066e | 2013-02-12 19:12:52 | [diff] [blame] | 2846 | return false; |
| 2847 | } |
| 2848 | |
[email protected] | 04bce56 | 2014-01-30 05:34:54 | [diff] [blame] | 2849 | bool WebContentsImpl::PreHandleGestureEvent( |
| 2850 | const blink::WebGestureEvent& event) { |
[email protected] | 28042d3 | 2014-02-03 14:10:03 | [diff] [blame] | 2851 | return delegate_ && delegate_->PreHandleGestureEvent(this, event); |
[email protected] | 04bce56 | 2014-01-30 05:34:54 | [diff] [blame] | 2852 | } |
| 2853 | |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 2854 | RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() { |
wjmaclean | e31234f | 2015-12-14 17:20:45 | [diff] [blame] | 2855 | if (!is_being_destroyed_ && GetOuterWebContents()) |
| 2856 | return GetOuterWebContents()->GetInputEventRouter(); |
| 2857 | |
| 2858 | if (!rwh_input_event_router_.get() && !is_being_destroyed_) |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 2859 | rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter); |
| 2860 | return rwh_input_event_router_.get(); |
| 2861 | } |
| 2862 | |
alexmos | 3fcd0ca | 2015-10-23 18:18:33 | [diff] [blame] | 2863 | void WebContentsImpl::ReplicatePageFocus(bool is_focused) { |
| 2864 | // Focus loss may occur while this WebContents is being destroyed. Don't |
| 2865 | // send the message in this case, as the main frame's RenderFrameHost and |
| 2866 | // other state has already been cleared. |
| 2867 | if (is_being_destroyed_) |
| 2868 | return; |
| 2869 | |
| 2870 | frame_tree_.ReplicatePageFocus(is_focused); |
| 2871 | } |
| 2872 | |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 2873 | RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost( |
| 2874 | RenderWidgetHostImpl* receiving_widget) { |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 2875 | // Events for widgets other than the main frame (e.g., popup menus) should be |
| 2876 | // forwarded directly to the widget they arrived on. |
| 2877 | if (receiving_widget != GetMainFrame()->GetRenderWidgetHost()) |
| 2878 | return receiving_widget; |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 2879 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 2880 | // If the focused WebContents is a guest WebContents, then get the focused |
| 2881 | // frame in the embedder WebContents instead. |
W. James MacLean | 13d834d | 2019-12-04 16:06:45 | [diff] [blame] | 2882 | FrameTreeNode* focused_frame = |
| 2883 | GetFocusedWebContents()->frame_tree_.GetFocusedFrame(); |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 2884 | |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 2885 | if (!focused_frame) |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 2886 | return receiving_widget; |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 2887 | |
alexmos | 732ca3a | 2015-12-08 02:01:02 | [diff] [blame] | 2888 | // The view may be null if a subframe's renderer process has crashed while |
| 2889 | // the subframe has focus. Drop the event in that case. Do not give |
| 2890 | // it to the main frame, so that the user doesn't unexpectedly type into the |
| 2891 | // wrong frame if a focused subframe renderer crashes while they type. |
| 2892 | RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView(); |
| 2893 | if (!view) |
| 2894 | return nullptr; |
| 2895 | |
| 2896 | return RenderWidgetHostImpl::From(view->GetRenderWidgetHost()); |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 2897 | } |
| 2898 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 2899 | RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() { |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 2900 | WebContentsImpl* focused_web_contents = GetFocusedWebContents(); |
| 2901 | |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 2902 | return focused_web_contents->GetMainFrame()->GetRenderWidgetHost(); |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 2903 | } |
| 2904 | |
Avi Drissman | d1d2565 | 2020-03-06 21:28:58 | [diff] [blame] | 2905 | bool WebContentsImpl::CanEnterFullscreenMode() { |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 2906 | // It's possible that this WebContents was spawned while blocking UI was on |
| 2907 | // the screen, or that it was downstream from a WebContents when UI was |
| 2908 | // blocked. Therefore, disqualify it from fullscreen if it or any upstream |
| 2909 | // WebContents has an active blocker. |
| 2910 | auto openers = GetAllOpeningWebContents(this); |
| 2911 | return std::all_of(openers.begin(), openers.end(), [](auto* opener) { |
| 2912 | return opener->fullscreen_blocker_count_ == 0; |
| 2913 | }); |
Avi Drissman | d1d2565 | 2020-03-06 21:28:58 | [diff] [blame] | 2914 | } |
| 2915 | |
Dave Tapuska | 3ed4419 | 2018-05-01 18:53:30 | [diff] [blame] | 2916 | void WebContentsImpl::EnterFullscreenMode( |
Mike Wasserman | 4ca0979 | 2020-05-29 17:44:43 | [diff] [blame] | 2917 | RenderFrameHost* requesting_frame, |
Dave Tapuska | a418951 | 2019-10-15 20:27:34 | [diff] [blame] | 2918 | const blink::mojom::FullscreenOptions& options) { |
Avi Drissman | d1d2565 | 2020-03-06 21:28:58 | [diff] [blame] | 2919 | DCHECK(CanEnterFullscreenMode()); |
| 2920 | |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2921 | // This method is being called to enter renderer-initiated fullscreen mode. |
| 2922 | // Make sure any existing fullscreen widget is shut down first. |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2923 | RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); |
avi | 85a4cef | 2015-12-18 20:13:37 | [diff] [blame] | 2924 | if (widget_view) { |
| 2925 | RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) |
| 2926 | ->ShutdownAndDestroyWidget(true); |
| 2927 | } |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2928 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 2929 | if (delegate_) { |
Mike Wasserman | 4ca0979 | 2020-05-29 17:44:43 | [diff] [blame] | 2930 | delegate_->EnterFullscreenModeForTab(requesting_frame, options); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2931 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 2932 | if (keyboard_lock_widget_) |
| 2933 | delegate_->RequestKeyboardLock(this, esc_key_locked_); |
| 2934 | } |
| 2935 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 2936 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2937 | observer->DidToggleFullscreenModeForTab(IsFullscreen(), false); |
| 2938 | }); |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 2939 | FullscreenContentsSet(GetBrowserContext())->insert(this); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2940 | } |
| 2941 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 2942 | void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) { |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2943 | // This method is being called to leave renderer-initiated fullscreen mode. |
| 2944 | // Make sure any existing fullscreen widget is shut down first. |
| 2945 | RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); |
avi | 85a4cef | 2015-12-18 20:13:37 | [diff] [blame] | 2946 | if (widget_view) { |
| 2947 | RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) |
| 2948 | ->ShutdownAndDestroyWidget(true); |
| 2949 | } |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2950 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 2951 | if (delegate_) { |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2952 | delegate_->ExitFullscreenModeForTab(this); |
[email protected] | 657c8e0 | 2014-03-19 19:18:37 | [diff] [blame] | 2953 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 2954 | if (keyboard_lock_widget_) |
| 2955 | delegate_->CancelKeyboardLockRequest(this); |
| 2956 | } |
| 2957 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 2958 | // The fullscreen state is communicated to the renderer through a resize |
| 2959 | // message. If the change in fullscreen state doesn't cause a view resize |
| 2960 | // then we must ensure web contents exit the fullscreen state by explicitly |
| 2961 | // sending a resize message. This is required for the situation of the browser |
| 2962 | // moving the view into a "browser fullscreen" state and then the contents |
| 2963 | // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't |
| 2964 | // have the side effect of the view resizing, hence the explicit call here is |
| 2965 | // required. |
| 2966 | if (!will_cause_resize) { |
| 2967 | if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) { |
| 2968 | if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost()) |
Fady Samuel | 0b91182 | 2018-04-25 13:22:16 | [diff] [blame] | 2969 | render_widget_host->SynchronizeVisualProperties(); |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 2970 | } |
scheib | 3dcb6c93 | 2015-02-23 10:55:58 | [diff] [blame] | 2971 | } |
| 2972 | |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 2973 | current_fullscreen_frame_ = nullptr; |
Becca Hughes | e9e2795 | 2018-06-25 17:08:27 | [diff] [blame] | 2974 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 2975 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 2976 | observer->DidToggleFullscreenModeForTab(IsFullscreen(), will_cause_resize); |
| 2977 | }); |
Becca Hughes | d11d650 | 2018-07-31 17:01:28 | [diff] [blame] | 2978 | |
| 2979 | if (display_cutout_host_impl_) |
| 2980 | display_cutout_host_impl_->DidExitFullscreen(); |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 2981 | |
| 2982 | FullscreenContentsSet(GetBrowserContext())->erase(this); |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 2983 | } |
| 2984 | |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 2985 | void WebContentsImpl::FullscreenStateChanged(RenderFrameHost* rfh, |
| 2986 | bool is_fullscreen) { |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 2987 | RenderFrameHostImpl* frame = static_cast<RenderFrameHostImpl*>(rfh); |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 2988 | |
| 2989 | if (is_fullscreen) { |
Jan Wilken Dörrie | 531be7ca | 2019-06-07 10:05:57 | [diff] [blame] | 2990 | if (!base::Contains(fullscreen_frames_, frame)) { |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 2991 | fullscreen_frames_.insert(frame); |
| 2992 | FullscreenFrameSetUpdated(); |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 2993 | } |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 2994 | return; |
| 2995 | } |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 2996 | |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 2997 | // If |frame| is no longer in fullscreen, remove it and any descendants. |
| 2998 | // See https://fullscreen.spec.whatwg.org. |
Arthur Sonzogni | 969a794e | 2018-10-11 08:56:09 | [diff] [blame] | 2999 | size_t size_before_deletion = fullscreen_frames_.size(); |
| 3000 | base::EraseIf(fullscreen_frames_, [&](RenderFrameHostImpl* current) { |
| 3001 | return (current == frame || current->IsDescendantOf(frame)); |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 3002 | }); |
| 3003 | |
Arthur Sonzogni | 969a794e | 2018-10-11 08:56:09 | [diff] [blame] | 3004 | if (size_before_deletion != fullscreen_frames_.size()) |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 3005 | FullscreenFrameSetUpdated(); |
| 3006 | } |
| 3007 | |
| 3008 | void WebContentsImpl::FullscreenFrameSetUpdated() { |
| 3009 | if (fullscreen_frames_.empty()) { |
| 3010 | current_fullscreen_frame_ = nullptr; |
| 3011 | return; |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 3012 | } |
| 3013 | |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 3014 | // Find the current fullscreen frame and call the observers. |
| 3015 | // If frame A is fullscreen, then frame B goes into inner fullscreen, then B |
| 3016 | // exits fullscreen - that will result in A being fullscreen. |
| 3017 | RenderFrameHostImpl* new_fullscreen_frame = *std::max_element( |
| 3018 | fullscreen_frames_.begin(), fullscreen_frames_.end(), FrameCompareDepth); |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 3019 | |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 3020 | // If we have already notified observers about this frame then we should not |
| 3021 | // fire the observers again. |
| 3022 | if (new_fullscreen_frame == current_fullscreen_frame_) |
| 3023 | return; |
| 3024 | current_fullscreen_frame_ = new_fullscreen_frame; |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 3025 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 3026 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 3027 | observer->DidAcquireFullscreen(new_fullscreen_frame); |
| 3028 | }); |
Arthur Sonzogni | 929d29f | 2018-09-17 14:19:44 | [diff] [blame] | 3029 | if (display_cutout_host_impl_) |
| 3030 | display_cutout_host_impl_->DidAcquireFullscreen(new_fullscreen_frame); |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 3031 | } |
| 3032 | |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3033 | void WebContentsImpl::UpdateVisibilityAndNotifyPageAndView( |
| 3034 | Visibility new_visibility) { |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3035 | // Only hide the page if there are no entities capturing screenshots |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 3036 | // or video (e.g. mirroring). If there are, apply the correct state of |
| 3037 | // kHidden or kHiddenButPainting. |
| 3038 | PageVisibilityState page_visibility; |
| 3039 | if (new_visibility == Visibility::VISIBLE || visible_capturer_count_ > 0) |
| 3040 | page_visibility = PageVisibilityState::kVisible; |
| 3041 | else if (hidden_capturer_count_ > 0) |
| 3042 | page_visibility = PageVisibilityState::kHiddenButPainting; |
| 3043 | else |
| 3044 | page_visibility = PageVisibilityState::kHidden; |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3045 | // If there are entities in Picture-in-Picture mode, don't activate |
| 3046 | // the "disable rendering" optimization. |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 3047 | const bool view_is_visible = |
| 3048 | page_visibility != PageVisibilityState::kHidden || |
| 3049 | HasPictureInPictureVideo(); |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3050 | |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 3051 | if (page_visibility != PageVisibilityState::kHidden) { |
Dana Fried | cf3bc8e | 2019-11-13 20:00:24 | [diff] [blame] | 3052 | // We cannot show a page or capture video unless there is a valid renderer |
| 3053 | // associated with this web contents. The navigation controller for this |
| 3054 | // page must be set to active (allowing navigation to complete, a renderer |
| 3055 | // and its associated views to be created, etc.) if any of these conditions |
| 3056 | // holds. |
| 3057 | // |
| 3058 | // Previously, it was possible for browser-side code to try to capture video |
| 3059 | // from a restored tab (for a variety of reasons, including the browser |
| 3060 | // creating preview thumbnails) and the tab would never actually load. By |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 3061 | // keying this behavior off of |page_visibility| instead of just |
Dana Fried | cf3bc8e | 2019-11-13 20:00:24 | [diff] [blame] | 3062 | // |new_visibility| we avoid this case. See crbug.com/1020782 for more |
| 3063 | // context. |
| 3064 | controller_.SetActive(true); |
| 3065 | |
| 3066 | // This shows the Page before showing the individual RenderWidgets, as |
| 3067 | // RenderWidgets will work to produce compositor frames and handle input |
| 3068 | // as soon as they are shown. But the Page and other classes do not expect |
| 3069 | // to be producing frames when the Page is hidden. So we make sure the Page |
| 3070 | // is shown first. |
Yuzu Saijo | 232076f | 2020-05-29 07:14:02 | [diff] [blame] | 3071 | for (auto* rvh : GetRenderViewHostsIncludingBackForwardCached()) { |
| 3072 | rvh->SetVisibility(page_visibility); |
Yuzu Saijo | be024af0 | 2020-05-11 07:35:56 | [diff] [blame] | 3073 | } |
Collin Baker | 98457b5 | 2019-11-06 21:34:29 | [diff] [blame] | 3074 | } |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3075 | |
| 3076 | // |GetRenderWidgetHostView()| can be null if the user middle clicks a link to |
| 3077 | // open a tab in the background, then closes the tab before selecting it. |
| 3078 | // This is because closing the tab calls WebContentsImpl::Destroy(), which |
| 3079 | // removes the |GetRenderViewHost()|; then when we actually destroy the |
| 3080 | // window, OnWindowPosChanged() notices and calls WasHidden() (which |
| 3081 | // calls us). |
| 3082 | if (auto* view = GetRenderWidgetHostView()) { |
| 3083 | if (view_is_visible) { |
| 3084 | view->Show(); |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3085 | } else if (new_visibility == Visibility::HIDDEN) { |
| 3086 | view->Hide(); |
| 3087 | } else { |
| 3088 | view->WasOccluded(); |
| 3089 | } |
| 3090 | } |
| 3091 | |
Carlos IL | 07f282f | 2020-05-15 22:58:29 | [diff] [blame] | 3092 | SetVisibilityForChildViews(view_is_visible); |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3093 | |
| 3094 | // Make sure to call SetVisibilityAndNotifyObservers(VISIBLE) before notifying |
| 3095 | // the CrossProcessFrameConnector. |
| 3096 | if (new_visibility == Visibility::VISIBLE) { |
| 3097 | last_active_time_ = base::TimeTicks::Now(); |
| 3098 | SetVisibilityAndNotifyObservers(new_visibility); |
| 3099 | } |
| 3100 | |
Collin Baker | c525996 | 2019-11-14 17:51:58 | [diff] [blame] | 3101 | if (page_visibility == PageVisibilityState::kHidden) { |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3102 | // Similar to when showing the page, we only hide the page after |
| 3103 | // hiding the individual RenderWidgets. |
Yuzu Saijo | 232076f | 2020-05-29 07:14:02 | [diff] [blame] | 3104 | for (auto* rvh : GetRenderViewHostsIncludingBackForwardCached()) { |
| 3105 | rvh->SetVisibility(page_visibility); |
Yuzu Saijo | be024af0 | 2020-05-11 07:35:56 | [diff] [blame] | 3106 | } |
| 3107 | |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 3108 | } else { |
| 3109 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 3110 | RenderFrameProxyHost* parent = node->render_manager()->GetProxyToParent(); |
| 3111 | if (!parent) |
| 3112 | continue; |
| 3113 | |
| 3114 | parent->cross_process_frame_connector()->DelegateWasShown(); |
| 3115 | } |
| 3116 | } |
| 3117 | |
| 3118 | if (new_visibility != Visibility::VISIBLE) |
| 3119 | SetVisibilityAndNotifyObservers(new_visibility); |
| 3120 | } |
| 3121 | |
Clark DuVall | a0e4299 | 2018-09-17 17:00:11 | [diff] [blame] | 3122 | #if defined(OS_ANDROID) |
| 3123 | void WebContentsImpl::UpdateUserGestureCarryoverInfo() { |
| 3124 | if (delegate_) |
| 3125 | delegate_->UpdateUserGestureCarryoverInfo(this); |
| 3126 | } |
| 3127 | #endif |
| 3128 | |
Avi Drissman | 97aef04 | 2020-06-30 21:04:48 | [diff] [blame] | 3129 | bool WebContentsImpl::IsFullscreen() { |
[email protected] | 199bba6e | 2012-04-04 16:19:38 | [diff] [blame] | 3130 | return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false; |
[email protected] | 5d5f7af | 2011-10-01 01:38:12 | [diff] [blame] | 3131 | } |
| 3132 | |
Malay Keshav | 87c42c0 | 2019-01-15 08:37:47 | [diff] [blame] | 3133 | bool WebContentsImpl::ShouldShowStaleContentOnEviction() { |
| 3134 | return GetDelegate() && GetDelegate()->ShouldShowStaleContentOnEviction(this); |
| 3135 | } |
| 3136 | |
danakj | 45d4245 | 2020-04-08 17:24:18 | [diff] [blame] | 3137 | blink::mojom::DisplayMode WebContentsImpl::GetDisplayMode() const { |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 3138 | return delegate_ ? delegate_->GetDisplayMode(this) |
Eric Willigers | 052f043 | 2019-10-04 04:06:57 | [diff] [blame] | 3139 | : blink::mojom::DisplayMode::kBrowser; |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 3140 | } |
| 3141 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 3142 | void WebContentsImpl::RequestToLockMouse( |
| 3143 | RenderWidgetHostImpl* render_widget_host, |
| 3144 | bool user_gesture, |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 3145 | bool last_unlocked_by_target, |
| 3146 | bool privileged) { |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3147 | for (WebContentsImpl* current = this; current; |
| 3148 | current = current->GetOuterWebContents()) { |
| 3149 | if (current->mouse_lock_widget_) { |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 3150 | render_widget_host->GotResponseToLockMouseRequest( |
| 3151 | blink::mojom::PointerLockResult::kAlreadyLocked); |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3152 | return; |
| 3153 | } |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 3154 | } |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 3155 | |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 3156 | if (privileged) { |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3157 | DCHECK(!GetOuterWebContents()); |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 3158 | mouse_lock_widget_ = render_widget_host; |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 3159 | render_widget_host->GotResponseToLockMouseRequest( |
| 3160 | blink::mojom::PointerLockResult::kSuccess); |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 3161 | return; |
| 3162 | } |
| 3163 | |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 3164 | bool widget_in_frame_tree = false; |
| 3165 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 3166 | if (node->current_frame_host()->GetRenderWidgetHost() == |
| 3167 | render_widget_host) { |
| 3168 | widget_in_frame_tree = true; |
| 3169 | break; |
| 3170 | } |
| 3171 | } |
| 3172 | |
| 3173 | if (widget_in_frame_tree && delegate_) { |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3174 | for (WebContentsImpl* current = this; current; |
| 3175 | current = current->GetOuterWebContents()) { |
| 3176 | current->mouse_lock_widget_ = render_widget_host; |
| 3177 | } |
| 3178 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 3179 | delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target); |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 3180 | } else { |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 3181 | render_widget_host->GotResponseToLockMouseRequest( |
| 3182 | blink::mojom::PointerLockResult::kWrongDocument); |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 3183 | } |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 3184 | } |
| 3185 | |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 3186 | void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) { |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 3187 | CHECK(mouse_lock_widget_); |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3188 | |
| 3189 | if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) |
| 3190 | return mouse_lock_widget_->delegate()->LostMouseLock(render_widget_host); |
| 3191 | |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 3192 | mouse_lock_widget_->SendMouseLockLost(); |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3193 | for (WebContentsImpl* current = this; current; |
| 3194 | current = current->GetOuterWebContents()) { |
| 3195 | current->mouse_lock_widget_ = nullptr; |
| 3196 | } |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 3197 | |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 3198 | if (delegate_) |
| 3199 | delegate_->LostMouseLock(); |
| 3200 | } |
| 3201 | |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 3202 | bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) { |
| 3203 | // To verify if the mouse is locked, the mouse_lock_widget_ needs to be |
| 3204 | // assigned to the widget that requested the mouse lock, and the top-level |
| 3205 | // platform RenderWidgetHostView needs to hold the mouse lock from the OS. |
Lucas Gadani | a0ea017 | 2018-09-20 18:31:37 | [diff] [blame] | 3206 | auto* widget_host = GetTopLevelRenderWidgetHostView(); |
| 3207 | return mouse_lock_widget_ == render_widget_host && widget_host && |
| 3208 | widget_host->IsMouseLocked(); |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 3209 | } |
| 3210 | |
lfg | 84763c9 | 2017-02-16 18:55:15 | [diff] [blame] | 3211 | RenderWidgetHostImpl* WebContentsImpl::GetMouseLockWidget() { |
Lucas Gadani | a0ea017 | 2018-09-20 18:31:37 | [diff] [blame] | 3212 | auto* widget_host = GetTopLevelRenderWidgetHostView(); |
| 3213 | if ((widget_host && widget_host->IsMouseLocked()) || |
lfg | e2176fb | 2017-03-26 00:45:47 | [diff] [blame] | 3214 | (GetFullscreenRenderWidgetHostView() && |
Lucas Gadani | a0ea017 | 2018-09-20 18:31:37 | [diff] [blame] | 3215 | GetFullscreenRenderWidgetHostView()->IsMouseLocked())) { |
lfg | 84763c9 | 2017-02-16 18:55:15 | [diff] [blame] | 3216 | return mouse_lock_widget_; |
Lucas Gadani | a0ea017 | 2018-09-20 18:31:37 | [diff] [blame] | 3217 | } |
lfg | 84763c9 | 2017-02-16 18:55:15 | [diff] [blame] | 3218 | |
| 3219 | return nullptr; |
| 3220 | } |
| 3221 | |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 3222 | bool WebContentsImpl::RequestKeyboardLock( |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 3223 | RenderWidgetHostImpl* render_widget_host, |
| 3224 | bool esc_key_locked) { |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 3225 | DCHECK(render_widget_host); |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 3226 | if (render_widget_host->delegate()->GetAsWebContents() != this) { |
| 3227 | NOTREACHED(); |
| 3228 | return false; |
| 3229 | } |
| 3230 | |
| 3231 | // KeyboardLock is only supported when called by the top-level browsing |
| 3232 | // context and is not supported in embedded content scenarios. |
| 3233 | if (GetOuterWebContents()) |
| 3234 | return false; |
| 3235 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 3236 | esc_key_locked_ = esc_key_locked; |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 3237 | keyboard_lock_widget_ = render_widget_host; |
| 3238 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 3239 | if (delegate_) |
| 3240 | delegate_->RequestKeyboardLock(this, esc_key_locked_); |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 3241 | return true; |
| 3242 | } |
| 3243 | |
| 3244 | void WebContentsImpl::CancelKeyboardLock( |
| 3245 | RenderWidgetHostImpl* render_widget_host) { |
| 3246 | if (!keyboard_lock_widget_ || render_widget_host != keyboard_lock_widget_) |
| 3247 | return; |
| 3248 | |
| 3249 | RenderWidgetHostImpl* old_keyboard_lock_widget = keyboard_lock_widget_; |
| 3250 | keyboard_lock_widget_ = nullptr; |
| 3251 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 3252 | if (delegate_) |
| 3253 | delegate_->CancelKeyboardLockRequest(this); |
| 3254 | |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 3255 | old_keyboard_lock_widget->CancelKeyboardLock(); |
| 3256 | } |
| 3257 | |
| 3258 | RenderWidgetHostImpl* WebContentsImpl::GetKeyboardLockWidget() { |
| 3259 | return keyboard_lock_widget_; |
| 3260 | } |
| 3261 | |
Dave Tapuska | c334436 | 2019-02-20 17:54:28 | [diff] [blame] | 3262 | void WebContentsImpl::OnRenderFrameProxyVisibilityChanged( |
| 3263 | blink::mojom::FrameVisibility visibility) { |
| 3264 | switch (visibility) { |
| 3265 | case blink::mojom::FrameVisibility::kRenderedInViewport: |
| 3266 | WasShown(); |
| 3267 | break; |
| 3268 | case blink::mojom::FrameVisibility::kNotRendered: |
| 3269 | WasHidden(); |
| 3270 | break; |
| 3271 | case blink::mojom::FrameVisibility::kRenderedOutOfViewport: |
| 3272 | WasOccluded(); |
| 3273 | break; |
| 3274 | } |
ekaramad | a4f4269 | 2016-02-11 19:48:37 | [diff] [blame] | 3275 | } |
| 3276 | |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3277 | RenderFrameHostDelegate* WebContentsImpl::CreateNewWindow( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3278 | RenderFrameHost* opener, |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 3279 | const mojom::CreateNewWindowParams& params, |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3280 | bool is_new_browsing_instance, |
Sergey Kuznetsov | 32257a2 | 2019-02-11 20:26:50 | [diff] [blame] | 3281 | bool has_user_gesture, |
[email protected] | 97714c8 | 2012-06-06 10:15:13 | [diff] [blame] | 3282 | SessionStorageNamespace* session_storage_namespace) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3283 | DCHECK(opener); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3284 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3285 | int render_process_id = opener->GetProcess()->GetID(); |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3286 | |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3287 | SiteInstance* source_site_instance = opener->GetSiteInstance(); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3288 | |
Aaron Colwell | eb21998 | 2020-01-16 02:17:27 | [diff] [blame] | 3289 | const GURL source_site_url = source_site_instance->GetSiteURL(); |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 3290 | const std::string& partition_id = |
Aaron Colwell | eb21998 | 2020-01-16 02:17:27 | [diff] [blame] | 3291 | GetContentClient()->browser()->GetStoragePartitionIdForSite( |
| 3292 | GetBrowserContext(), source_site_url); |
| 3293 | { |
| 3294 | StoragePartition* partition = BrowserContext::GetStoragePartitionForSite( |
| 3295 | GetBrowserContext(), source_site_url); |
| 3296 | DOMStorageContextWrapper* dom_storage_context = |
| 3297 | static_cast<DOMStorageContextWrapper*>( |
| 3298 | partition->GetDOMStorageContext()); |
| 3299 | SessionStorageNamespaceImpl* session_storage_namespace_impl = |
| 3300 | static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace); |
| 3301 | CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context)); |
| 3302 | } |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 3303 | |
Albert J. Wong | 1ceccef9 | 2019-10-08 08:25:20 | [diff] [blame] | 3304 | if (delegate_ && delegate_->IsWebContentsCreationOverridden( |
| 3305 | source_site_instance, params.window_container_type, |
| 3306 | opener->GetLastCommittedURL(), params.frame_name, |
| 3307 | params.target_url)) { |
| 3308 | return static_cast<WebContentsImpl*>(delegate_->CreateCustomWebContents( |
| 3309 | opener, source_site_instance, is_new_browsing_instance, |
| 3310 | opener->GetLastCommittedURL(), params.frame_name, params.target_url, |
| 3311 | partition_id, session_storage_namespace)); |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 3312 | } |
| 3313 | |
danakj | 22b4e8b | 2019-08-01 23:14:39 | [diff] [blame] | 3314 | bool renderer_started_hidden = |
| 3315 | params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB; |
| 3316 | |
Aaron Colwell | eb21998 | 2020-01-16 02:17:27 | [diff] [blame] | 3317 | // We usually create the new window in the same BrowsingInstance (group of |
| 3318 | // script-related windows), by passing in the current SiteInstance. However, |
| 3319 | // if the opener is being suppressed (in a non-guest), we do not provide |
| 3320 | // a SiteInstance which causes a new one to get created in its own |
| 3321 | // BrowsingInstance. |
| 3322 | bool is_guest = BrowserPluginGuest::IsGuest(this); |
| 3323 | scoped_refptr<SiteInstance> site_instance = |
| 3324 | params.opener_suppressed && !is_guest ? nullptr : source_site_instance; |
| 3325 | |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 3326 | // Create the new web contents. This will automatically create the new |
| 3327 | // WebContentsView. In the future, we may want to create the view separately. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 3328 | CreateParams create_params(GetBrowserContext(), site_instance.get()); |
nasko | 48321ca3 | 2015-07-02 20:44:12 | [diff] [blame] | 3329 | create_params.main_frame_name = params.frame_name; |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 3330 | create_params.opener_render_process_id = render_process_id; |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3331 | create_params.opener_render_frame_id = opener->GetRoutingID(); |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 3332 | create_params.opener_suppressed = params.opener_suppressed; |
danakj | 22b4e8b | 2019-08-01 23:14:39 | [diff] [blame] | 3333 | create_params.initially_hidden = renderer_started_hidden; |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 3334 | |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3335 | // Even though all codepaths leading here are in response to a renderer |
| 3336 | // tryng to open a new window, if the new window ends up in a different |
| 3337 | // browsing instance, then the RenderViewHost, RenderWidgetHost, |
| 3338 | // RenderFrameHost constellation is effectively browser initiated |
| 3339 | // the opener's process will not given the routing IDs for the new |
| 3340 | // objects. |
| 3341 | create_params.renderer_initiated_creation = !is_new_browsing_instance; |
Albert J. Wong | 1ceccef9 | 2019-10-08 08:25:20 | [diff] [blame] | 3342 | |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3343 | std::unique_ptr<WebContentsImpl> new_contents; |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 3344 | if (!is_guest) { |
| 3345 | create_params.context = view_->GetNativeView(); |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3346 | new_contents = WebContentsImpl::Create(create_params); |
| 3347 | } else { |
| 3348 | new_contents = base::WrapUnique(static_cast<WebContentsImpl*>( |
| 3349 | GetBrowserPluginGuest()->CreateNewGuestWindow(create_params))); |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 3350 | } |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3351 | auto* new_contents_impl = new_contents.get(); |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3352 | |
| 3353 | new_contents_impl->GetController().SetSessionStorageNamespace( |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 3354 | partition_id, session_storage_namespace); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 3355 | |
alexmos | 646fec0 | 2015-07-25 00:11:49 | [diff] [blame] | 3356 | // If the new frame has a name, make sure any SiteInstances that can find |
| 3357 | // this named frame have proxies for it. Must be called after |
| 3358 | // SetSessionStorageNamespace, since this calls CreateRenderView, which uses |
| 3359 | // GetSessionStorageNamespace. |
| 3360 | if (!params.frame_name.empty()) |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3361 | new_contents_impl->GetRenderManager()->CreateProxiesForNewNamedFrame(); |
alexmos | 646fec0 | 2015-07-25 00:11:49 | [diff] [blame] | 3362 | |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 3363 | // 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] | 3364 | // will be shown immediately). |
| 3365 | if (!params.opener_suppressed) { |
| 3366 | if (!is_guest) { |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3367 | WebContentsView* new_view = new_contents_impl->view_.get(); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3368 | |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 3369 | // TODO(brettw): It seems bogus that we have to call this function on the |
| 3370 | // newly created object and give it one of its own member variables. |
danakj | 22b4e8b | 2019-08-01 23:14:39 | [diff] [blame] | 3371 | RenderWidgetHostView* widget_view = new_view->CreateViewForWidget( |
W. James MacLean | 13d834d | 2019-12-04 16:06:45 | [diff] [blame] | 3372 | new_contents_impl->GetRenderViewHost()->GetWidget()); |
danakj | 22b4e8b | 2019-08-01 23:14:39 | [diff] [blame] | 3373 | if (!renderer_started_hidden) { |
| 3374 | // RenderWidgets for frames always initialize as hidden. If the renderer |
| 3375 | // created this window as visible, then we show it here. |
| 3376 | widget_view->Show(); |
| 3377 | } |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 3378 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3379 | // Save the created window associated with the route so we can show it |
| 3380 | // later. |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 3381 | // |
| 3382 | // TODO(ajwong): This should be keyed off the RenderFrame routing id or the |
| 3383 | // FrameTreeNode id instead of the routing id of the Widget for the main |
| 3384 | // frame. https://crbug.com/545684 |
Fergal Daly | 052873a8 | 2020-03-11 14:45:49 | [diff] [blame] | 3385 | int32_t main_frame_routing_id = new_contents_impl->GetMainFrame() |
| 3386 | ->GetRenderWidgetHost() |
| 3387 | ->GetRoutingID(); |
| 3388 | GlobalRoutingID id(render_process_id, main_frame_routing_id); |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3389 | pending_contents_[id] = |
| 3390 | CreatedWindow(std::move(new_contents), params.target_url); |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3391 | AddDestructionObserver(new_contents_impl); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | if (delegate_) { |
Bryan McQuade | d2b93c0 | 2017-07-14 22:26:31 | [diff] [blame] | 3395 | delegate_->WebContentsCreated(this, render_process_id, |
| 3396 | opener->GetRoutingID(), params.frame_name, |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3397 | params.target_url, new_contents_impl); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3398 | } |
| 3399 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 3400 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 3401 | observer->DidOpenRequestedURL(new_contents_impl, opener, params.target_url, |
| 3402 | params.referrer.To<Referrer>(), |
| 3403 | params.disposition, ui::PAGE_TRANSITION_LINK, |
| 3404 | false, // started_from_context_menu |
| 3405 | true); // renderer_initiated |
| 3406 | }); |
pnoland | aae574e | 2017-03-06 21:04:21 | [diff] [blame] | 3407 | |
Avi Drissman | ba3b1b34 | 2017-08-29 18:16:13 | [diff] [blame] | 3408 | // Any new WebContents opened while this WebContents is in fullscreen can be |
| 3409 | // used to confuse the user, so drop fullscreen. |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 3410 | base::ScopedClosureRunner fullscreen_block = ForSecurityDropFullscreen(); |
| 3411 | // The new contents will be independent of this contents, so release the |
| 3412 | // fullscreen block. |
| 3413 | fullscreen_block.RunAndReset(); |
Avi Drissman | ba3b1b34 | 2017-08-29 18:16:13 | [diff] [blame] | 3414 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3415 | if (params.opener_suppressed) { |
| 3416 | // When the opener is suppressed, the original renderer cannot access the |
| 3417 | // 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] | 3418 | bool was_blocked = false; |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 3419 | |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 3420 | if (delegate_) { |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3421 | base::WeakPtr<WebContentsImpl> weak_new_contents = |
| 3422 | new_contents_impl->weak_factory_.GetWeakPtr(); |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 3423 | |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3424 | gfx::Rect initial_rect; // Report an empty initial rect. |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3425 | delegate_->AddNewContents(this, std::move(new_contents), |
Joel Hockey | 891e8806 | 2020-04-30 05:38:44 | [diff] [blame] | 3426 | params.target_url, params.disposition, |
| 3427 | initial_rect, has_user_gesture, &was_blocked); |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3428 | // The delegate may delete |new_contents_impl| during AddNewContents(). |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 3429 | if (!weak_new_contents) |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3430 | return nullptr; |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 3431 | } |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 3432 | |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 3433 | if (!was_blocked) { |
Nasko Oskov | 83a8cf9 | 2018-10-19 14:58:56 | [diff] [blame] | 3434 | std::unique_ptr<NavigationController::LoadURLParams> load_params = |
| 3435 | std::make_unique<NavigationController::LoadURLParams>( |
| 3436 | params.target_url); |
Nasko Oskov | 93e7c55c | 2018-12-19 01:59:29 | [diff] [blame] | 3437 | load_params->initiator_origin = opener->GetLastCommittedOrigin(); |
Lukasz Anforowicz | d2629b4 | 2020-08-11 16:07:31 | [diff] [blame] | 3438 | // Avoiding setting |load_params->source_site_instance| when |
| 3439 | // |opener_suppressed| is true, because in that case we do not want to use |
| 3440 | // the old SiteInstance and/or BrowsingInstance. See also the test here: |
| 3441 | // NewPopupCOOP_SameOriginPolicyAndCrossOriginIframeSetsNoopener. |
Leon Han | 963dc18 | 2018-11-06 05:41:48 | [diff] [blame] | 3442 | load_params->referrer = params.referrer.To<Referrer>(); |
Nasko Oskov | 83a8cf9 | 2018-10-19 14:58:56 | [diff] [blame] | 3443 | load_params->transition_type = ui::PAGE_TRANSITION_LINK; |
| 3444 | load_params->is_renderer_initiated = true; |
Sergey Kuznetsov | 32257a2 | 2019-02-11 20:26:50 | [diff] [blame] | 3445 | load_params->has_user_gesture = has_user_gesture; |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 3446 | |
| 3447 | if (delegate_ && !is_guest && |
| 3448 | !delegate_->ShouldResumeRequestsForCreatedWindow()) { |
Nasko Oskov | 83a8cf9 | 2018-10-19 14:58:56 | [diff] [blame] | 3449 | // We are in asynchronous add new contents path, delay navigation. |
| 3450 | DCHECK(!new_contents_impl->delayed_open_url_params_); |
| 3451 | new_contents_impl->delayed_load_url_params_ = std::move(load_params); |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 3452 | } else { |
Nasko Oskov | 83a8cf9 | 2018-10-19 14:58:56 | [diff] [blame] | 3453 | new_contents_impl->controller_.LoadURLWithParams(*load_params.get()); |
Nasko Oskov | 28ebd5b | 2018-12-07 22:29:33 | [diff] [blame] | 3454 | if (!is_guest) |
| 3455 | new_contents_impl->Focus(); |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 3456 | } |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 3457 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3458 | } |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 3459 | return new_contents_impl; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3460 | } |
| 3461 | |
Dave Tapuska | d983562 | 2020-03-10 17:32:31 | [diff] [blame] | 3462 | void WebContentsImpl::CreateNewWidget( |
| 3463 | int32_t render_process_id, |
| 3464 | int32_t widget_route_id, |
Dave Tapuska | 8499eec | 2020-03-16 17:54:30 | [diff] [blame] | 3465 | mojo::PendingAssociatedReceiver<blink::mojom::WidgetHost> blink_widget_host, |
| 3466 | mojo::PendingAssociatedRemote<blink::mojom::Widget> blink_widget) { |
Albert J. Wong | f6e13ed | 2018-09-18 15:25:47 | [diff] [blame] | 3467 | CreateNewWidget(render_process_id, widget_route_id, /*is_fullscreen=*/false, |
Dave Tapuska | b686c1b | 2020-06-09 00:40:23 | [diff] [blame] | 3468 | std::move(blink_widget_host), std::move(blink_widget)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3469 | } |
| 3470 | |
Julie Jeongeun Kim | caacf910 | 2019-09-12 02:13:05 | [diff] [blame] | 3471 | void WebContentsImpl::CreateNewFullscreenWidget( |
| 3472 | int32_t render_process_id, |
| 3473 | int32_t widget_route_id, |
Dave Tapuska | 8499eec | 2020-03-16 17:54:30 | [diff] [blame] | 3474 | mojo::PendingAssociatedReceiver<blink::mojom::WidgetHost> blink_widget_host, |
| 3475 | mojo::PendingAssociatedRemote<blink::mojom::Widget> blink_widget) { |
Albert J. Wong | f6e13ed | 2018-09-18 15:25:47 | [diff] [blame] | 3476 | CreateNewWidget(render_process_id, widget_route_id, /*is_fullscreen=*/true, |
Dave Tapuska | b686c1b | 2020-06-09 00:40:23 | [diff] [blame] | 3477 | std::move(blink_widget_host), std::move(blink_widget)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3478 | } |
| 3479 | |
Dave Tapuska | d983562 | 2020-03-10 17:32:31 | [diff] [blame] | 3480 | void WebContentsImpl::CreateNewWidget( |
| 3481 | int32_t render_process_id, |
| 3482 | int32_t route_id, |
| 3483 | bool is_fullscreen, |
Dave Tapuska | 8499eec | 2020-03-16 17:54:30 | [diff] [blame] | 3484 | mojo::PendingAssociatedReceiver<blink::mojom::WidgetHost> blink_widget_host, |
| 3485 | mojo::PendingAssociatedRemote<blink::mojom::Widget> blink_widget) { |
kenrb | a26d1509 | 2016-02-10 22:00:25 | [diff] [blame] | 3486 | RenderProcessHost* process = RenderProcessHost::FromID(render_process_id); |
kenrb | b46f86a | 2015-12-07 07:53:23 | [diff] [blame] | 3487 | // 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] | 3488 | // this WebContentsImpl instance. If any other process sends the request, |
| 3489 | // it is invalid and the process must be terminated. |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 3490 | if (!HasMatchingProcess(&frame_tree_, render_process_id)) { |
Lukasz Anforowicz | 6f74628 | 2018-01-04 23:24:51 | [diff] [blame] | 3491 | ReceivedBadMessage(process, bad_message::WCI_NEW_WIDGET_PROCESS_MISMATCH); |
[email protected] | a850402 | 2013-12-04 20:23:51 | [diff] [blame] | 3492 | return; |
| 3493 | } |
| 3494 | |
Dave Tapuska | b686c1b | 2020-06-09 00:40:23 | [diff] [blame] | 3495 | RenderWidgetHostImpl* widget_host = |
| 3496 | new RenderWidgetHostImpl(this, process, route_id, IsHidden(), |
| 3497 | std::make_unique<FrameTokenMessageQueue>()); |
Dave Tapuska | 8499eec | 2020-03-16 17:54:30 | [diff] [blame] | 3498 | |
| 3499 | widget_host->BindWidgetInterfaces(std::move(blink_widget_host), |
| 3500 | std::move(blink_widget)); |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 3501 | RenderWidgetHostViewBase* widget_view = |
| 3502 | static_cast<RenderWidgetHostViewBase*>( |
danakj | 0b24694 | 2018-09-17 21:30:27 | [diff] [blame] | 3503 | view_->CreateViewForChildWidget(widget_host)); |
[email protected] | 83918ec | 2013-01-10 15:37:19 | [diff] [blame] | 3504 | if (!widget_view) |
| 3505 | return; |
danakj | 0b24694 | 2018-09-17 21:30:27 | [diff] [blame] | 3506 | // Fullscreen child widgets are frames, other child widgets are popups, and |
| 3507 | // popups should not get activated. |
| 3508 | if (!is_fullscreen) |
| 3509 | widget_view->SetWidgetType(WidgetType::kPopup); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3510 | // Save the created widget associated with the route so we can show it later. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 3511 | pending_widget_views_[GlobalRoutingID(render_process_id, route_id)] = |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3512 | widget_view; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3513 | } |
| 3514 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3515 | void WebContentsImpl::ShowCreatedWindow(int process_id, |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3516 | int main_frame_widget_route_id, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3517 | WindowOpenDisposition disposition, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 3518 | const gfx::Rect& initial_rect, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3519 | bool user_gesture) { |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3520 | // This method is the renderer requesting an existing top level window to |
| 3521 | // show a new top level window that the renderer created. Each top level |
| 3522 | // window is associated with a WebContents. In this case it was created |
| 3523 | // earlier but showing it was deferred until the renderer requested for it |
| 3524 | // to be shown. We find that previously created WebContents here. |
| 3525 | // TODO(danakj): Why do we defer this show step until the renderer asks for it |
| 3526 | // when it will always do so. What needs to happen in the renderer before we |
| 3527 | // reach here? |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3528 | base::Optional<CreatedWindow> owned_created = |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3529 | GetCreatedWindow(process_id, main_frame_widget_route_id); |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3530 | |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3531 | // The browser may have rejected the request to make a new window, or the |
| 3532 | // renderer could be sending an invalid route id. Ignore the request then. |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3533 | if (!owned_created || !owned_created->contents) |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3534 | return; |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 3535 | |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3536 | WebContentsImpl* created = owned_created->contents.get(); |
| 3537 | |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3538 | // This uses the delegate for the WebContents where the window was created |
| 3539 | // from, to control how to show the newly created window. |
| 3540 | WebContentsDelegate* delegate = GetDelegate(); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3541 | |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3542 | // The delegate can be null in tests, so we must check for it :(. |
| 3543 | if (delegate) { |
| 3544 | // Mark the web contents as pending resume, then immediately do |
| 3545 | // the resume if the delegate wants it. |
| 3546 | created->is_resume_pending_ = true; |
| 3547 | if (delegate->ShouldResumeRequestsForCreatedWindow()) |
| 3548 | created->ResumeLoadingCreatedWebContents(); |
| 3549 | |
| 3550 | base::WeakPtr<WebContentsImpl> weak_created = |
| 3551 | created->weak_factory_.GetWeakPtr(); |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3552 | delegate->AddNewContents(this, std::move(owned_created->contents), |
Joel Hockey | 891e8806 | 2020-04-30 05:38:44 | [diff] [blame] | 3553 | std::move(owned_created->target_url), disposition, |
| 3554 | initial_rect, user_gesture, nullptr); |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3555 | // The delegate may delete |created| during AddNewContents(). |
| 3556 | if (!weak_created) |
| 3557 | return; |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 3558 | } |
danakj | e6c0162 | 2018-10-05 19:39:26 | [diff] [blame] | 3559 | |
| 3560 | RenderWidgetHostImpl* rwh = created->GetMainFrame()->GetRenderWidgetHost(); |
| 3561 | DCHECK_EQ(main_frame_widget_route_id, rwh->GetRoutingID()); |
| 3562 | rwh->Send(new WidgetMsg_SetBounds_ACK(rwh->GetRoutingID())); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3563 | } |
| 3564 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3565 | void WebContentsImpl::ShowCreatedWidget(int process_id, |
Albert J. Wong | f6e13ed | 2018-09-18 15:25:47 | [diff] [blame] | 3566 | int widget_route_id, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 3567 | const gfx::Rect& initial_rect) { |
Albert J. Wong | f6e13ed | 2018-09-18 15:25:47 | [diff] [blame] | 3568 | ShowCreatedWidget(process_id, widget_route_id, false, initial_rect); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3569 | } |
| 3570 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3571 | void WebContentsImpl::ShowCreatedFullscreenWidget(int process_id, |
Albert J. Wong | f6e13ed | 2018-09-18 15:25:47 | [diff] [blame] | 3572 | int widget_route_id) { |
| 3573 | ShowCreatedWidget(process_id, widget_route_id, true, gfx::Rect()); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3574 | } |
| 3575 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3576 | void WebContentsImpl::ShowCreatedWidget(int process_id, |
| 3577 | int route_id, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3578 | bool is_fullscreen, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 3579 | const gfx::Rect& initial_rect) { |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 3580 | RenderWidgetHostViewBase* widget_host_view = |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3581 | static_cast<RenderWidgetHostViewBase*>( |
| 3582 | GetCreatedWidget(process_id, route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3583 | if (!widget_host_view) |
| 3584 | return; |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 3585 | |
W. James MacLean | ec4125c | 2019-09-27 18:56:00 | [diff] [blame] | 3586 | // GetOutermostWebContents() returns |this| if there are no outer WebContents. |
W. James MacLean | 3c5f5046 | 2019-10-28 16:24:21 | [diff] [blame] | 3587 | auto* outer_web_contents = GetOuterWebContents(); |
| 3588 | auto* outermost_web_contents = GetOutermostWebContents(); |
W. James MacLean | ec4125c | 2019-09-27 18:56:00 | [diff] [blame] | 3589 | RenderWidgetHostView* view = |
W. James MacLean | 3c5f5046 | 2019-10-28 16:24:21 | [diff] [blame] | 3590 | outermost_web_contents->GetRenderWidgetHostView(); |
| 3591 | // It's not entirely obvious why we need the transform only in the case where |
| 3592 | // the outer webcontents is not the same as the outermost webcontents. It may |
| 3593 | // be due to the fact that oopifs that are children of the mainframe get |
| 3594 | // correct values for their screenrects, but deeper cross-process frames do |
| 3595 | // not. Hopefully this can be resolved with https://crbug.com/928825. |
| 3596 | // Handling these cases separately is needed for http://crbug.com/1015298. |
| 3597 | bool needs_transform = this != outermost_web_contents && |
| 3598 | outermost_web_contents != outer_web_contents; |
W. James MacLean | ec4125c | 2019-09-27 18:56:00 | [diff] [blame] | 3599 | |
| 3600 | gfx::Rect transformed_rect(initial_rect); |
| 3601 | RenderWidgetHostView* this_view = GetRenderWidgetHostView(); |
W. James MacLean | 3c5f5046 | 2019-10-28 16:24:21 | [diff] [blame] | 3602 | if (needs_transform) { |
W. James MacLean | ec4125c | 2019-09-27 18:56:00 | [diff] [blame] | 3603 | // We need to transform the coordinates of initial_rect. |
| 3604 | gfx::Point origin = |
| 3605 | this_view->TransformPointToRootCoordSpace(initial_rect.origin()); |
| 3606 | gfx::Point bottom_right = |
| 3607 | this_view->TransformPointToRootCoordSpace(initial_rect.bottom_right()); |
| 3608 | transformed_rect = |
| 3609 | gfx::Rect(origin.x(), origin.y(), bottom_right.x() - origin.x(), |
| 3610 | bottom_right.y() - origin.y()); |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 3611 | } |
| 3612 | |
danakj | 0b24694 | 2018-09-17 21:30:27 | [diff] [blame] | 3613 | // Fullscreen child widgets are frames, other child widgets are popups. |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 3614 | if (is_fullscreen) { |
[email protected] | d7f80ba | 2013-10-12 07:42:31 | [diff] [blame] | 3615 | DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_); |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 3616 | view_->StoreFocus(); |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 3617 | fullscreen_widget_process_id_ = |
| 3618 | widget_host_view->GetRenderWidgetHost()->GetProcess()->GetID(); |
[email protected] | d7f80ba | 2013-10-12 07:42:31 | [diff] [blame] | 3619 | fullscreen_widget_routing_id_ = route_id; |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 3620 | if (delegate_ && delegate_->EmbedsFullscreenWidget()) { |
| 3621 | widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView()); |
Mike Wasserman | 4ca0979 | 2020-05-29 17:44:43 | [diff] [blame] | 3622 | delegate_->EnterFullscreenModeForTab(GetMainFrame(), |
Dave Tapuska | a418951 | 2019-10-15 20:27:34 | [diff] [blame] | 3623 | blink::mojom::FullscreenOptions()); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 3624 | } else { |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 3625 | widget_host_view->InitAsFullscreen(view); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 3626 | } |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 3627 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 3628 | observer->DidShowFullscreenWidget(); |
| 3629 | }); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 3630 | if (!widget_host_view->HasFocus()) |
| 3631 | widget_host_view->Focus(); |
| 3632 | } else { |
W. James MacLean | ec4125c | 2019-09-27 18:56:00 | [diff] [blame] | 3633 | widget_host_view->InitAsPopup(view, transformed_rect); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 3634 | } |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 3635 | |
yiyix | cb1fbc4f | 2018-03-16 19:54:08 | [diff] [blame] | 3636 | RenderWidgetHostImpl* render_widget_host_impl = widget_host_view->host(); |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 3637 | render_widget_host_impl->Init(); |
[email protected] | d7f80ba | 2013-10-12 07:42:31 | [diff] [blame] | 3638 | // Only allow privileged mouse lock for fullscreen render widget, which is |
| 3639 | // used to implement Pepper Flash fullscreen. |
| 3640 | render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3641 | } |
| 3642 | |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3643 | base::Optional<CreatedWindow> WebContentsImpl::GetCreatedWindow( |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3644 | int process_id, |
| 3645 | int main_frame_widget_route_id) { |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 3646 | auto key = GlobalRoutingID(process_id, main_frame_widget_route_id); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3647 | auto iter = pending_contents_.find(key); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3648 | |
| 3649 | // Certain systems can block the creation of new windows. If we didn't succeed |
| 3650 | // in creating one, just return NULL. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3651 | if (iter == pending_contents_.end()) |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3652 | return base::nullopt; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3653 | |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3654 | CreatedWindow result = std::move(iter->second); |
| 3655 | WebContentsImpl* new_contents = result.contents.get(); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3656 | pending_contents_.erase(key); |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3657 | RemoveDestructionObserver(new_contents); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3658 | |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 3659 | // Don't initialize the guest WebContents immediately. |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3660 | if (BrowserPluginGuest::IsGuest(new_contents)) |
| 3661 | return result; |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 3662 | |
Lukasz Anforowicz | 5510ed65 | 2018-06-06 16:16:19 | [diff] [blame] | 3663 | if (!new_contents->GetMainFrame()->GetProcess()->IsInitializedAndNotDead() || |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3664 | !new_contents->GetMainFrame()->GetView()) { |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3665 | return base::nullopt; |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 3666 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3667 | |
Joel Hockey | 8c2011b2 | 2020-04-30 05:07:19 | [diff] [blame] | 3668 | return result; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3669 | } |
| 3670 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3671 | RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int process_id, |
| 3672 | int route_id) { |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 3673 | auto iter = pending_widget_views_.find(GlobalRoutingID(process_id, route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3674 | if (iter == pending_widget_views_.end()) { |
| 3675 | DCHECK(false); |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3676 | return nullptr; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | RenderWidgetHostView* widget_host_view = iter->second; |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 3680 | pending_widget_views_.erase(GlobalRoutingID(process_id, route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3681 | |
| 3682 | RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost(); |
Lukasz Anforowicz | 5510ed65 | 2018-06-06 16:16:19 | [diff] [blame] | 3683 | if (!widget_host->GetProcess()->IsInitializedAndNotDead()) { |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3684 | // The view has gone away or the renderer crashed. Nothing to do. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3685 | return nullptr; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3686 | } |
| 3687 | |
| 3688 | return widget_host_view; |
| 3689 | } |
| 3690 | |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 3691 | void WebContentsImpl::RequestMediaAccessPermission( |
[email protected] | 33662e5 | 2013-01-07 21:31:09 | [diff] [blame] | 3692 | const MediaStreamRequest& request, |
Mark Pilgrim | 5749908 | 2018-06-12 12:38:30 | [diff] [blame] | 3693 | MediaResponseCallback callback) { |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 3694 | if (delegate_) { |
Mark Pilgrim | 5749908 | 2018-06-12 12:38:30 | [diff] [blame] | 3695 | delegate_->RequestMediaAccessPermission(this, request, std::move(callback)); |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 3696 | } else { |
Antonio Gomes | 0d42960a | 2019-06-05 12:35:51 | [diff] [blame] | 3697 | std::move(callback).Run( |
| 3698 | blink::MediaStreamDevices(), |
| 3699 | blink::mojom::MediaStreamRequestResult::FAILED_DUE_TO_SHUTDOWN, |
| 3700 | std::unique_ptr<MediaStreamUI>()); |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 3701 | } |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 3702 | } |
| 3703 | |
Chandan Padhi | a4b8bcb7 | 2017-09-12 16:41:04 | [diff] [blame] | 3704 | bool WebContentsImpl::CheckMediaAccessPermission( |
Raymes Khoury | ad7c24a1 | 2018-03-05 23:22:58 | [diff] [blame] | 3705 | RenderFrameHost* render_frame_host, |
Chandan Padhi | a4b8bcb7 | 2017-09-12 16:41:04 | [diff] [blame] | 3706 | const url::Origin& security_origin, |
Antonio Gomes | c8b734b | 2019-06-05 18:22:16 | [diff] [blame] | 3707 | blink::mojom::MediaStreamType type) { |
| 3708 | DCHECK(type == blink::mojom::MediaStreamType::DEVICE_AUDIO_CAPTURE || |
| 3709 | type == blink::mojom::MediaStreamType::DEVICE_VIDEO_CAPTURE); |
Chandan Padhi | a4b8bcb7 | 2017-09-12 16:41:04 | [diff] [blame] | 3710 | return delegate_ && delegate_->CheckMediaAccessPermission( |
Raymes Khoury | ad7c24a1 | 2018-03-05 23:22:58 | [diff] [blame] | 3711 | render_frame_host, security_origin.GetURL(), type); |
grunell | 657d4d8 | 2014-09-18 00:09:43 | [diff] [blame] | 3712 | } |
| 3713 | |
Guido Urdaneta | 73fa663 | 2019-01-14 18:46:26 | [diff] [blame] | 3714 | std::string WebContentsImpl::GetDefaultMediaDeviceID( |
Antonio Gomes | c8b734b | 2019-06-05 18:22:16 | [diff] [blame] | 3715 | blink::mojom::MediaStreamType type) { |
guidou | 8a440b84 | 2017-01-30 13:58:43 | [diff] [blame] | 3716 | if (!delegate_) |
| 3717 | return std::string(); |
| 3718 | return delegate_->GetDefaultMediaDeviceID(this, type); |
| 3719 | } |
| 3720 | |
[email protected] | cc920043 | 2013-07-23 23:02:40 | [diff] [blame] | 3721 | SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace( |
| 3722 | SiteInstance* instance) { |
| 3723 | return controller_.GetSessionStorageNamespace(instance); |
| 3724 | } |
| 3725 | |
[email protected] | 6de7fc48 | 2014-06-06 10:46:44 | [diff] [blame] | 3726 | SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() { |
| 3727 | return controller_.GetSessionStorageNamespaceMap(); |
| 3728 | } |
| 3729 | |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 3730 | FrameTree* WebContentsImpl::GetFrameTree() { |
| 3731 | return &frame_tree_; |
| 3732 | } |
| 3733 | |
aelias | 5252baa | 2016-04-10 01:18:02 | [diff] [blame] | 3734 | bool WebContentsImpl::IsOverridingUserAgent() { |
| 3735 | return GetController().GetVisibleEntry() && |
| 3736 | GetController().GetVisibleEntry()->GetIsOverridingUserAgent(); |
| 3737 | } |
| 3738 | |
avi | 85ee836 | 2016-10-08 02:09:08 | [diff] [blame] | 3739 | bool WebContentsImpl::IsJavaScriptDialogShowing() const { |
| 3740 | return is_showing_javascript_dialog_; |
| 3741 | } |
| 3742 | |
avi | c031d39 | 2017-03-03 03:09:42 | [diff] [blame] | 3743 | bool WebContentsImpl::ShouldIgnoreUnresponsiveRenderer() { |
Dominique Fauteux-Chapleau | 9924438 | 2020-07-08 20:37:00 | [diff] [blame] | 3744 | if (suppress_unresponsive_renderer_count_ > 0) |
| 3745 | return true; |
| 3746 | |
avi | c031d39 | 2017-03-03 03:09:42 | [diff] [blame] | 3747 | // Ignore unresponsive renderers if the debugger is attached to them since the |
| 3748 | // unresponsiveness might be a result of the renderer sitting on a breakpoint. |
| 3749 | // |
David Bienvenu | 525f8a0 | 2019-02-15 02:02:42 | [diff] [blame] | 3750 | #ifdef OS_WIN |
| 3751 | // Check if a windows debugger is attached to the renderer process. |
| 3752 | base::ProcessHandle process_handle = |
| 3753 | GetMainFrame()->GetProcess()->GetProcess().Handle(); |
| 3754 | BOOL debugger_present = FALSE; |
| 3755 | if (CheckRemoteDebuggerPresent(process_handle, &debugger_present) && |
| 3756 | debugger_present) |
| 3757 | return true; |
| 3758 | #endif // OS_WIN |
| 3759 | |
avi | c031d39 | 2017-03-03 03:09:42 | [diff] [blame] | 3760 | // TODO(pfeldman): Fix this to only return true if the renderer is *actually* |
| 3761 | // sitting on a breakpoint. https://crbug.com/684202 |
| 3762 | return DevToolsAgentHost::IsDebuggerAttached(this); |
| 3763 | } |
| 3764 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 3765 | ui::AXMode WebContentsImpl::GetAccessibilityMode() { |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 3766 | return accessibility_mode_; |
| 3767 | } |
| 3768 | |
Mario Sanchez Prada | 5d7f1ac | 2020-07-16 17:18:40 | [diff] [blame] | 3769 | void WebContentsImpl::AXTreeIDForMainFrameHasChanged() { |
| 3770 | RenderWidgetHostViewBase* rwhv = |
| 3771 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 3772 | if (rwhv) |
| 3773 | rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID()); |
| 3774 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 3775 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 3776 | observer->AXTreeIDForMainFrameHasChanged(); |
| 3777 | }); |
Mario Sanchez Prada | 5d7f1ac | 2020-07-16 17:18:40 | [diff] [blame] | 3778 | } |
| 3779 | |
Dominic Mazzoni | a7b0edb2 | 2017-08-09 16:32:51 | [diff] [blame] | 3780 | void WebContentsImpl::AccessibilityEventReceived( |
Dominic Mazzoni | ccbaa9b | 2018-06-06 07:44:23 | [diff] [blame] | 3781 | const AXEventNotificationDetails& details) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 3782 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 3783 | observer->AccessibilityEventReceived(details); |
| 3784 | }); |
[email protected] | 31a71eaf | 2014-03-13 01:47:36 | [diff] [blame] | 3785 | } |
| 3786 | |
dmazzoni | 2400c46 | 2016-08-23 15:07:13 | [diff] [blame] | 3787 | void WebContentsImpl::AccessibilityLocationChangesReceived( |
| 3788 | const std::vector<AXLocationChangeNotificationDetails>& details) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 3789 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 3790 | observer->AccessibilityLocationChangesReceived(details); |
| 3791 | }); |
dmazzoni | 2400c46 | 2016-08-23 15:07:13 | [diff] [blame] | 3792 | } |
| 3793 | |
Abigail Klein | abb42833 | 2019-09-13 18:26:21 | [diff] [blame] | 3794 | base::string16 WebContentsImpl::DumpAccessibilityTree( |
| 3795 | bool internal, |
| 3796 | std::vector<AccessibilityTreeFormatter::PropertyFilter> property_filters) { |
James Wallace-Lee | eafc94cb9 | 2018-07-23 21:35:09 | [diff] [blame] | 3797 | auto* ax_mgr = GetOrCreateRootBrowserAccessibilityManager(); |
| 3798 | DCHECK(ax_mgr); |
Lei Zhang | c98caa382 | 2019-11-07 19:17:27 | [diff] [blame] | 3799 | return AccessibilityTreeFormatterBase::DumpAccessibilityTreeFromManager( |
Abigail Klein | abb42833 | 2019-09-13 18:26:21 | [diff] [blame] | 3800 | ax_mgr, internal, property_filters); |
James Wallace-Lee | eafc94cb9 | 2018-07-23 21:35:09 | [diff] [blame] | 3801 | } |
| 3802 | |
Abigail Klein | aa89874 | 2019-11-01 02:31:25 | [diff] [blame] | 3803 | void WebContentsImpl::RecordAccessibilityEvents( |
Abigail Klein | bb8304bd | 2020-05-18 21:44:18 | [diff] [blame] | 3804 | bool start_recording, |
| 3805 | base::Optional<AccessibilityEventCallback> callback) { |
| 3806 | // Only pass a callback to RecordAccessibilityEvents when starting to record. |
| 3807 | DCHECK_EQ(start_recording, callback.has_value()); |
| 3808 | if (start_recording) { |
Abigail Klein | aa89874 | 2019-11-01 02:31:25 | [diff] [blame] | 3809 | SetAccessibilityMode(ui::AXMode::kWebContents); |
| 3810 | auto* ax_mgr = GetOrCreateRootBrowserAccessibilityManager(); |
| 3811 | DCHECK(ax_mgr); |
| 3812 | base::ProcessId pid = base::Process::Current().Pid(); |
| 3813 | event_recorder_ = content::AccessibilityEventRecorder::Create( |
| 3814 | ax_mgr, pid, base::StringPiece{}); |
Abigail Klein | bb8304bd | 2020-05-18 21:44:18 | [diff] [blame] | 3815 | event_recorder_->ListenToEvents(*callback); |
Abigail Klein | aa89874 | 2019-11-01 02:31:25 | [diff] [blame] | 3816 | } else { |
Abigail Klein | bb8304bd | 2020-05-18 21:44:18 | [diff] [blame] | 3817 | if (event_recorder_) { |
| 3818 | event_recorder_->FlushAsyncEvents(); |
| 3819 | event_recorder_.reset(nullptr); |
| 3820 | } |
Abigail Klein | aa89874 | 2019-11-01 02:31:25 | [diff] [blame] | 3821 | } |
| 3822 | } |
| 3823 | |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 3824 | RenderFrameHost* WebContentsImpl::GetGuestByInstanceID( |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 3825 | RenderFrameHost* render_frame_host, |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 3826 | int browser_plugin_instance_id) { |
| 3827 | BrowserPluginGuestManager* guest_manager = |
| 3828 | GetBrowserContext()->GetGuestManager(); |
fsamuel | 9cbc00a | 2015-04-17 20:30:20 | [diff] [blame] | 3829 | if (!guest_manager) |
| 3830 | return nullptr; |
| 3831 | |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 3832 | WebContents* guest = guest_manager->GetGuestByInstanceID( |
fsamuel | 2e9413d | 2015-02-25 01:25:44 | [diff] [blame] | 3833 | render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id); |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 3834 | if (!guest) |
fsamuel | 9cbc00a | 2015-04-17 20:30:20 | [diff] [blame] | 3835 | return nullptr; |
| 3836 | |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 3837 | return guest->GetMainFrame(); |
| 3838 | } |
| 3839 | |
Ke He | 7319dbe | 2017-11-09 05:54:44 | [diff] [blame] | 3840 | device::mojom::GeolocationContext* WebContentsImpl::GetGeolocationContext() { |
Ella Ge | 3e375b70 | 2020-06-05 15:57:16 | [diff] [blame] | 3841 | if (delegate_) { |
| 3842 | auto* installed_webapp_context = |
| 3843 | delegate_->GetInstalledWebappGeolocationContext(); |
| 3844 | if (installed_webapp_context) |
| 3845 | return installed_webapp_context; |
| 3846 | } |
| 3847 | |
Ken Rockot | ce010f0 | 2019-12-12 23:32:32 | [diff] [blame] | 3848 | if (!geolocation_context_) { |
| 3849 | GetDeviceService().BindGeolocationContext( |
| 3850 | geolocation_context_.BindNewPipeAndPassReceiver()); |
| 3851 | } |
Conley Owens | 6894c4f | 2017-07-10 19:29:13 | [diff] [blame] | 3852 | return geolocation_context_.get(); |
blundell | c57b93f | 2014-10-29 13:19:57 | [diff] [blame] | 3853 | } |
| 3854 | |
ke.he | 98b761e | 2017-05-09 05:59:17 | [diff] [blame] | 3855 | device::mojom::WakeLockContext* WebContentsImpl::GetWakeLockContext() { |
blundell | d8cd72b | 2017-03-28 07:18:38 | [diff] [blame] | 3856 | if (!wake_lock_context_host_) |
| 3857 | wake_lock_context_host_.reset(new WakeLockContextHost(this)); |
blundell | e75a8f9 | 2017-03-27 08:11:17 | [diff] [blame] | 3858 | return wake_lock_context_host_->GetWakeLockContext(); |
alogvinov | f50445a | 2015-10-30 13:00:12 | [diff] [blame] | 3859 | } |
| 3860 | |
blundell | f5316fc | 2017-05-15 11:49:03 | [diff] [blame] | 3861 | #if defined(OS_ANDROID) |
Miyoung Shin | 59f39ff | 2019-09-17 07:23:20 | [diff] [blame] | 3862 | void WebContentsImpl::GetNFC( |
Reilly Grant | afbe224 | 2020-02-20 21:14:55 | [diff] [blame] | 3863 | RenderFrameHost* render_frame_host, |
Miyoung Shin | 59f39ff | 2019-09-17 07:23:20 | [diff] [blame] | 3864 | mojo::PendingReceiver<device::mojom::NFC> receiver) { |
Reilly Grant | afbe224 | 2020-02-20 21:14:55 | [diff] [blame] | 3865 | if (!nfc_host_) |
| 3866 | nfc_host_ = std::make_unique<NFCHost>(this); |
| 3867 | nfc_host_->GetNFC(render_frame_host, std::move(receiver)); |
blundell | f5316fc | 2017-05-15 11:49:03 | [diff] [blame] | 3868 | } |
| 3869 | #endif |
| 3870 | |
Evan Stade | 5e750ad0 | 2017-08-07 21:59:27 | [diff] [blame] | 3871 | void WebContentsImpl::SetNotWaitingForResponse() { |
| 3872 | if (waiting_for_response_ == false) |
| 3873 | return; |
| 3874 | |
| 3875 | waiting_for_response_ = false; |
| 3876 | if (delegate_) |
| 3877 | delegate_->LoadingStateChanged(this, is_load_to_different_document_); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 3878 | observers_.ForEachObserver( |
| 3879 | [&](WebContentsObserver* observer) { observer->DidReceiveResponse(); }); |
Evan Stade | 5e750ad0 | 2017-08-07 21:59:27 | [diff] [blame] | 3880 | } |
| 3881 | |
lfg | bb9c28a | 2016-03-01 03:19:49 | [diff] [blame] | 3882 | void WebContentsImpl::SendScreenRects() { |
kenrb | c52e1b4e | 2016-03-20 01:03:37 | [diff] [blame] | 3883 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
kenrb | 0e8dc20 | 2016-05-30 19:51:40 | [diff] [blame] | 3884 | if (node->current_frame_host()->is_local_root()) |
kenrb | c52e1b4e | 2016-03-20 01:03:37 | [diff] [blame] | 3885 | node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects(); |
| 3886 | } |
[email protected] | 32deec6 | 2013-05-15 23:55:04 | [diff] [blame] | 3887 | } |
| 3888 | |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 3889 | TextInputManager* WebContentsImpl::GetTextInputManager() { |
| 3890 | if (GetOuterWebContents()) |
| 3891 | return GetOuterWebContents()->GetTextInputManager(); |
| 3892 | |
Ehsan Karamad | c179dc0 | 2018-12-15 03:09:29 | [diff] [blame] | 3893 | if (!text_input_manager_ && !browser_plugin_guest_) { |
Darren Shen | ca53d5f | 2018-05-15 04:56:01 | [diff] [blame] | 3894 | text_input_manager_.reset(new TextInputManager( |
| 3895 | GetBrowserContext() && |
| 3896 | !GetBrowserContext()->IsOffTheRecord()) /* should_do_learning */); |
| 3897 | } |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 3898 | |
| 3899 | return text_input_manager_.get(); |
| 3900 | } |
| 3901 | |
paulmeyer | 7f6f1d4f | 2016-11-15 00:00:27 | [diff] [blame] | 3902 | bool WebContentsImpl::OnUpdateDragCursor() { |
Lei Zhang | 6410ec1a | 2019-01-31 21:38:58 | [diff] [blame] | 3903 | return browser_plugin_embedder_ && |
| 3904 | browser_plugin_embedder_->OnUpdateDragCursor(); |
paulmeyer | 7f6f1d4f | 2016-11-15 00:00:27 | [diff] [blame] | 3905 | } |
| 3906 | |
kenrb | 11f213a | 2017-03-24 18:12:06 | [diff] [blame] | 3907 | bool WebContentsImpl::IsWidgetForMainFrame( |
| 3908 | RenderWidgetHostImpl* render_widget_host) { |
| 3909 | return render_widget_host == GetMainFrame()->GetRenderWidgetHost(); |
| 3910 | } |
| 3911 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 3912 | BrowserAccessibilityManager* |
| 3913 | WebContentsImpl::GetRootBrowserAccessibilityManager() { |
Carlos IL | d51e770 | 2020-05-07 18:51:39 | [diff] [blame] | 3914 | RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 3915 | return rfh ? rfh->browser_accessibility_manager() : nullptr; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | BrowserAccessibilityManager* |
| 3919 | WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() { |
Carlos IL | d51e770 | 2020-05-07 18:51:39 | [diff] [blame] | 3920 | RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 3921 | return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 3922 | } |
| 3923 | |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3924 | void WebContentsImpl::ExecuteEditCommand( |
| 3925 | const std::string& command, |
| 3926 | const base::Optional<base::string16>& value) { |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 3927 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 3928 | if (!input_handler) |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3929 | return; |
| 3930 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 3931 | input_handler->ExecuteEditCommand(command, value); |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3932 | } |
| 3933 | |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 3934 | void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) { |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 3935 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 3936 | if (!input_handler) |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 3937 | return; |
| 3938 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 3939 | input_handler->MoveRangeSelectionExtent(extent); |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 3940 | } |
| 3941 | |
| 3942 | void WebContentsImpl::SelectRange(const gfx::Point& base, |
| 3943 | const gfx::Point& extent) { |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 3944 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 3945 | if (!input_handler) |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 3946 | return; |
| 3947 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 3948 | input_handler->SelectRange(base, extent); |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 3949 | } |
| 3950 | |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3951 | void WebContentsImpl::MoveCaret(const gfx::Point& extent) { |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 3952 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 3953 | if (!input_handler) |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3954 | return; |
| 3955 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 3956 | input_handler->MoveCaret(extent); |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3957 | } |
| 3958 | |
Shimi Zhang | 37deeb2 | 2017-09-28 00:59:01 | [diff] [blame] | 3959 | void WebContentsImpl::AdjustSelectionByCharacterOffset( |
| 3960 | int start_adjust, |
| 3961 | int end_adjust, |
| 3962 | bool show_selection_menu) { |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 3963 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 3964 | if (!input_handler) |
aurimas | ab031902 | 2015-07-10 21:57:38 | [diff] [blame] | 3965 | return; |
| 3966 | |
Shimi Zhang | 37deeb2 | 2017-09-28 00:59:01 | [diff] [blame] | 3967 | using blink::mojom::SelectionMenuBehavior; |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 3968 | input_handler->AdjustSelectionByCharacterOffset( |
Shimi Zhang | 37deeb2 | 2017-09-28 00:59:01 | [diff] [blame] | 3969 | start_adjust, end_adjust, |
| 3970 | show_selection_menu ? SelectionMenuBehavior::kShow |
| 3971 | : SelectionMenuBehavior::kHide); |
aurimas | ab031902 | 2015-07-10 21:57:38 | [diff] [blame] | 3972 | } |
| 3973 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3974 | void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 3975 | const gfx::Size old_size = GetPreferredSize(); |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 3976 | preferred_size_ = pref_size; |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 3977 | OnPreferredSizeChanged(old_size); |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 3978 | } |
| 3979 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 3980 | void WebContentsImpl::ResizeDueToAutoResize( |
| 3981 | RenderWidgetHostImpl* render_widget_host, |
Fady Samuel | 9794711 | 2018-05-05 16:24:54 | [diff] [blame] | 3982 | const gfx::Size& new_size) { |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 3983 | if (render_widget_host != GetRenderViewHost()->GetWidget()) |
| 3984 | return; |
| 3985 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 3986 | if (delegate_) |
| 3987 | delegate_->ResizeDueToAutoResize(this, new_size); |
| 3988 | } |
| 3989 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3990 | WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) { |
Aaron Colwell | 9dab165 | 2019-12-09 18:29:49 | [diff] [blame] | 3991 | #if DCHECK_IS_ON() |
| 3992 | DCHECK(params.Valid()); |
| 3993 | #endif |
| 3994 | |
Bo Liu | 300c605 | 2018-06-12 04:46:07 | [diff] [blame] | 3995 | if (!delegate_) { |
| 3996 | // Embedder can delay setting a delegate on new WebContents with |
| 3997 | // WebContentsDelegate::ShouldResumeRequestsForCreatedWindow. In the mean |
| 3998 | // time, navigations, including the initial one, that goes through OpenURL |
| 3999 | // should be delayed until embedder is ready to resume loading. |
| 4000 | delayed_open_url_params_ = std::make_unique<OpenURLParams>(params); |
Nasko Oskov | 83a8cf9 | 2018-10-19 14:58:56 | [diff] [blame] | 4001 | |
| 4002 | // If there was a navigation deferred when creating the window through |
| 4003 | // CreateNewWindow, drop it in favor of this navigation. |
| 4004 | delayed_load_url_params_.reset(); |
| 4005 | |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 4006 | return nullptr; |
Bo Liu | 300c605 | 2018-06-12 04:46:07 | [diff] [blame] | 4007 | } |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 4008 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 4009 | WebContents* new_contents = delegate_->OpenURLFromTab(this, params); |
pnoland | 48894465 | 2017-02-22 18:58:54 | [diff] [blame] | 4010 | |
| 4011 | RenderFrameHost* source_render_frame_host = RenderFrameHost::FromID( |
| 4012 | params.source_render_process_id, params.source_render_frame_id); |
| 4013 | |
| 4014 | if (source_render_frame_host && params.source_site_instance) { |
| 4015 | CHECK_EQ(source_render_frame_host->GetSiteInstance(), |
| 4016 | params.source_site_instance.get()); |
| 4017 | } |
| 4018 | |
| 4019 | if (new_contents && source_render_frame_host && new_contents != this) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 4020 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 4021 | observer->DidOpenRequestedURL( |
Lukasz Anforowicz | 48c9f87 | 2018-08-01 00:58:41 | [diff] [blame] | 4022 | new_contents, source_render_frame_host, params.url, params.referrer, |
| 4023 | params.disposition, params.transition, |
| 4024 | params.started_from_context_menu, params.is_renderer_initiated); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 4025 | }); |
pnoland | 48894465 | 2017-02-22 18:58:54 | [diff] [blame] | 4026 | } |
| 4027 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 4028 | return new_contents; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 4029 | } |
| 4030 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 4031 | void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset, |
| 4032 | int history_length) { |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 4033 | SendPageMessage(new PageMsg_SetHistoryOffsetAndLength( |
| 4034 | MSG_ROUTING_NONE, history_offset, history_length)); |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 4035 | } |
| 4036 | |
| 4037 | void WebContentsImpl::SetHistoryOffsetAndLengthForView( |
| 4038 | RenderViewHost* render_view_host, |
| 4039 | int history_offset, |
| 4040 | int history_length) { |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 4041 | render_view_host->Send(new PageMsg_SetHistoryOffsetAndLength( |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 4042 | render_view_host->GetRoutingID(), history_offset, history_length)); |
[email protected] | 796931a9 | 2011-08-10 01:32:14 | [diff] [blame] | 4043 | } |
| 4044 | |
arthursonzogni | 818c264 | 2019-09-27 12:18:10 | [diff] [blame] | 4045 | void WebContentsImpl::ReloadFocusedFrame() { |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 4046 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 4047 | if (!focused_frame) |
| 4048 | return; |
| 4049 | |
yilkal | 921048bd | 2019-10-09 23:51:04 | [diff] [blame] | 4050 | focused_frame->Reload(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | void WebContentsImpl::Undo() { |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4054 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4055 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4056 | return; |
| 4057 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4058 | input_handler->Undo(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4059 | RecordAction(base::UserMetricsAction("Undo")); |
| 4060 | } |
| 4061 | |
| 4062 | void WebContentsImpl::Redo() { |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4063 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4064 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4065 | return; |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4066 | |
| 4067 | input_handler->Redo(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4068 | RecordAction(base::UserMetricsAction("Redo")); |
| 4069 | } |
| 4070 | |
| 4071 | void WebContentsImpl::Cut() { |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4072 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4073 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4074 | return; |
| 4075 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4076 | input_handler->Cut(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4077 | RecordAction(base::UserMetricsAction("Cut")); |
| 4078 | } |
| 4079 | |
| 4080 | void WebContentsImpl::Copy() { |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4081 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4082 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4083 | return; |
| 4084 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4085 | input_handler->Copy(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4086 | RecordAction(base::UserMetricsAction("Copy")); |
| 4087 | } |
| 4088 | |
| 4089 | void WebContentsImpl::CopyToFindPboard() { |
Avi Drissman | 7c57be7 | 2020-07-29 20:09:46 | [diff] [blame] | 4090 | #if defined(OS_MAC) |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4091 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4092 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4093 | return; |
| 4094 | |
| 4095 | // Windows/Linux don't have the concept of a find pasteboard. |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4096 | input_handler->CopyToFindPboard(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4097 | RecordAction(base::UserMetricsAction("CopyToFindPboard")); |
| 4098 | #endif |
| 4099 | } |
| 4100 | |
| 4101 | void WebContentsImpl::Paste() { |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4102 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4103 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4104 | return; |
| 4105 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4106 | input_handler->Paste(); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 4107 | observers_.ForEachObserver( |
| 4108 | [&](WebContentsObserver* observer) { observer->OnPaste(); }); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4109 | RecordAction(base::UserMetricsAction("Paste")); |
| 4110 | } |
| 4111 | |
| 4112 | void WebContentsImpl::PasteAndMatchStyle() { |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4113 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4114 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4115 | return; |
| 4116 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4117 | input_handler->PasteAndMatchStyle(); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 4118 | observers_.ForEachObserver( |
| 4119 | [&](WebContentsObserver* observer) { observer->OnPaste(); }); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4120 | RecordAction(base::UserMetricsAction("PasteAndMatchStyle")); |
| 4121 | } |
| 4122 | |
| 4123 | void WebContentsImpl::Delete() { |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4124 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4125 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4126 | return; |
| 4127 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4128 | input_handler->Delete(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4129 | RecordAction(base::UserMetricsAction("DeleteSelection")); |
| 4130 | } |
| 4131 | |
| 4132 | void WebContentsImpl::SelectAll() { |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4133 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4134 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4135 | return; |
| 4136 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4137 | input_handler->SelectAll(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4138 | RecordAction(base::UserMetricsAction("SelectAll")); |
| 4139 | } |
| 4140 | |
yabinh | 351e7ec | 2017-03-10 02:43:24 | [diff] [blame] | 4141 | void WebContentsImpl::CollapseSelection() { |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4142 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4143 | if (!input_handler) |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4144 | return; |
| 4145 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4146 | input_handler->CollapseSelection(); |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | void WebContentsImpl::Replace(const base::string16& word) { |
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) |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 4152 | return; |
| 4153 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4154 | input_handler->Replace(word); |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 4155 | } |
| 4156 | |
| 4157 | void WebContentsImpl::ReplaceMisspelling(const base::string16& word) { |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 4158 | auto* input_handler = GetFocusedFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4159 | if (!input_handler) |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 4160 | return; |
| 4161 | |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 4162 | input_handler->ReplaceMisspelling(word); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | void WebContentsImpl::NotifyContextMenuClosed( |
| 4166 | const CustomContextMenuContext& context) { |
| 4167 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 4168 | if (!focused_frame) |
| 4169 | return; |
| 4170 | |
| 4171 | focused_frame->Send(new FrameMsg_ContextMenuClosed( |
| 4172 | focused_frame->GetRoutingID(), context)); |
| 4173 | } |
| 4174 | |
| 4175 | void WebContentsImpl::ExecuteCustomContextMenuCommand( |
| 4176 | int action, const CustomContextMenuContext& context) { |
| 4177 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 4178 | if (!focused_frame) |
| 4179 | return; |
| 4180 | |
| 4181 | focused_frame->Send(new FrameMsg_CustomContextMenuAction( |
| 4182 | focused_frame->GetRoutingID(), context, action)); |
[email protected] | 4fed370 | 2014-04-01 09:08:00 | [diff] [blame] | 4183 | } |
| 4184 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4185 | gfx::NativeView WebContentsImpl::GetNativeView() { |
| 4186 | return view_->GetNativeView(); |
| 4187 | } |
| 4188 | |
| 4189 | gfx::NativeView WebContentsImpl::GetContentNativeView() { |
| 4190 | return view_->GetContentNativeView(); |
| 4191 | } |
| 4192 | |
| 4193 | gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() { |
| 4194 | return view_->GetTopLevelNativeWindow(); |
| 4195 | } |
| 4196 | |
| 4197 | gfx::Rect WebContentsImpl::GetViewBounds() { |
| 4198 | return view_->GetViewBounds(); |
| 4199 | } |
| 4200 | |
| 4201 | gfx::Rect WebContentsImpl::GetContainerBounds() { |
Jeremy Roman | 352239c | 2020-05-21 16:31:32 | [diff] [blame] | 4202 | return view_->GetContainerBounds(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4203 | } |
| 4204 | |
| 4205 | DropData* WebContentsImpl::GetDropData() { |
| 4206 | return view_->GetDropData(); |
| 4207 | } |
| 4208 | |
| 4209 | void WebContentsImpl::Focus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 4210 | view_->Focus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4211 | } |
| 4212 | |
| 4213 | void WebContentsImpl::SetInitialFocus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 4214 | view_->SetInitialFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4215 | } |
| 4216 | |
| 4217 | void WebContentsImpl::StoreFocus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 4218 | view_->StoreFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | void WebContentsImpl::RestoreFocus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 4222 | view_->RestoreFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4223 | } |
| 4224 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4225 | void WebContentsImpl::FocusThroughTabTraversal(bool reverse) { |
Maxim Podgorodskiy | a926c4ff | 2017-11-20 02:06:39 | [diff] [blame] | 4226 | view_->FocusThroughTabTraversal(reverse); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 4227 | } |
| 4228 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4229 | bool WebContentsImpl::IsSavable() { |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 4230 | // WebKit creates Document object when MIME type is application/xhtml+xml, |
| 4231 | // so we also support this MIME type. |
Yuzu Saijo | c23e9b7 | 2020-06-25 07:21:27 | [diff] [blame] | 4232 | std::string mime_type = GetContentsMimeType(); |
| 4233 | return mime_type == "text/html" || mime_type == "text/xml" || |
| 4234 | mime_type == "application/xhtml+xml" || mime_type == "text/plain" || |
| 4235 | mime_type == "text/css" || |
| 4236 | blink::IsSupportedJavascriptMimeType(mime_type); |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 4237 | } |
| 4238 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4239 | void WebContentsImpl::OnSavePage() { |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 4240 | // If we can not save the page, try to download it. |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 4241 | if (!IsSavable()) { |
Min Qin | da0ed206 | 2018-02-23 22:00:53 | [diff] [blame] | 4242 | download::RecordSavePackageEvent( |
| 4243 | download::SAVE_PACKAGE_DOWNLOAD_ON_NON_HTML); |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 4244 | SaveFrame(GetLastCommittedURL(), Referrer()); |
[email protected] | 27678b2a | 2012-02-04 22:09:14 | [diff] [blame] | 4245 | return; |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 4246 | } |
| 4247 | |
| 4248 | Stop(); |
| 4249 | |
| 4250 | // Create the save package and possibly prompt the user for the name to save |
| 4251 | // the page as. The user prompt is an asynchronous operation that runs on |
| 4252 | // another thread. |
| 4253 | save_package_ = new SavePackage(this); |
| 4254 | save_package_->GetSaveInfo(); |
| 4255 | } |
| 4256 | |
| 4257 | // Used in automated testing to bypass prompting the user for file names. |
| 4258 | // Instead, the names and paths are hard coded rather than running them through |
| 4259 | // file name sanitation and extension / mime checking. |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 4260 | bool WebContentsImpl::SavePage(const base::FilePath& main_file, |
| 4261 | const base::FilePath& dir_path, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4262 | SavePageType save_type) { |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 4263 | // Stop the page from navigating. |
| 4264 | Stop(); |
| 4265 | |
| 4266 | save_package_ = new SavePackage(this, save_type, main_file, dir_path); |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4267 | return save_package_->Init(SavePackageDownloadCreatedCallback()); |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 4268 | } |
| 4269 | |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4270 | void WebContentsImpl::SaveFrame(const GURL& url, |
| 4271 | const Referrer& referrer) { |
Xing Liu | 10329bf | 2018-03-20 19:22:14 | [diff] [blame] | 4272 | SaveFrameWithHeaders(url, referrer, std::string(), base::string16()); |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 4273 | } |
| 4274 | |
Xing Liu | 10329bf | 2018-03-20 19:22:14 | [diff] [blame] | 4275 | void WebContentsImpl::SaveFrameWithHeaders( |
| 4276 | const GURL& url, |
| 4277 | const Referrer& referrer, |
| 4278 | const std::string& headers, |
| 4279 | const base::string16& suggested_filename) { |
Lei Zhang | 13a42e4 | 2019-02-19 23:28:11 | [diff] [blame] | 4280 | // Check and see if the guest can handle this. |
| 4281 | if (delegate_) { |
| 4282 | WebContents* guest_web_contents = nullptr; |
| 4283 | if (browser_plugin_embedder_) { |
| 4284 | BrowserPluginGuest* guest = browser_plugin_embedder_->GetFullPageGuest(); |
| 4285 | if (guest) |
| 4286 | guest_web_contents = guest->GetWebContents(); |
| 4287 | } else if (browser_plugin_guest_) { |
| 4288 | guest_web_contents = this; |
| 4289 | } |
| 4290 | |
| 4291 | if (guest_web_contents && delegate_->GuestSaveFrame(guest_web_contents)) |
| 4292 | return; |
| 4293 | } |
| 4294 | |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 4295 | if (!GetLastCommittedURL().is_valid()) |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4296 | return; |
sammc | 92af6155 | 2014-11-19 23:27:40 | [diff] [blame] | 4297 | if (delegate_ && delegate_->SaveFrame(url, referrer)) |
| 4298 | return; |
| 4299 | |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 4300 | // TODO(nasko): This check for main frame is incorrect and should be fixed |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 4301 | // by explicitly passing in which frame this method should target. This would |
| 4302 | // indicate whether it's the main frame, and also tell us the frame pointer |
| 4303 | // to use for routing. |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 4304 | bool is_main_frame = (url == GetLastCommittedURL()); |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 4305 | RenderFrameHost* frame_host = GetMainFrame(); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4306 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 4307 | int64_t post_id = -1; |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4308 | if (is_main_frame) { |
Lucas Furukawa Gadani | 5553a15 | 2019-01-08 18:55:57 | [diff] [blame] | 4309 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4310 | if (entry) |
| 4311 | post_id = entry->GetPostID(); |
| 4312 | } |
Ramin Halavati | 24e2101 | 2017-07-10 12:56:06 | [diff] [blame] | 4313 | net::NetworkTrafficAnnotationTag traffic_annotation = |
| 4314 | net::DefineNetworkTrafficAnnotation("download_web_contents_frame", R"( |
| 4315 | semantics { |
| 4316 | sender: "Save Page Action" |
| 4317 | description: |
| 4318 | "Saves the given frame's URL to the local file system." |
| 4319 | trigger: |
| 4320 | "The user has triggered a save operation on the frame through a " |
| 4321 | "context menu or other mechanism." |
| 4322 | data: "None." |
| 4323 | destination: WEBSITE |
| 4324 | } |
| 4325 | policy { |
Ramin Halavati | 3b97978 | 2017-07-21 11:40:26 | [diff] [blame] | 4326 | cookies_allowed: YES |
Ramin Halavati | 24e2101 | 2017-07-10 12:56:06 | [diff] [blame] | 4327 | cookies_store: "user" |
| 4328 | setting: |
| 4329 | "This feature cannot be disabled by settings, but it's is only " |
| 4330 | "triggered by user request." |
| 4331 | policy_exception_justification: "Not implemented." |
| 4332 | })"); |
Min Qin | a904f330 | 2018-02-13 23:33:34 | [diff] [blame] | 4333 | auto params = std::make_unique<download::DownloadUrlParameters>( |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 4334 | url, frame_host->GetProcess()->GetID(), |
| 4335 | frame_host->GetRenderViewHost()->GetRoutingID(), |
Matt Menke | 0dcaebc3 | 2020-03-06 17:00:10 | [diff] [blame] | 4336 | frame_host->GetRoutingID(), traffic_annotation); |
Min Qin | a904f330 | 2018-02-13 23:33:34 | [diff] [blame] | 4337 | params->set_referrer(referrer.url); |
| 4338 | params->set_referrer_policy( |
| 4339 | Referrer::ReferrerPolicyForUrlRequest(referrer.policy)); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4340 | params->set_post_id(post_id); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4341 | if (post_id >= 0) |
| 4342 | params->set_method("POST"); |
| 4343 | params->set_prompt(true); |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 4344 | |
| 4345 | if (headers.empty()) { |
| 4346 | params->set_prefer_cache(true); |
| 4347 | } else { |
Min Qin | a904f330 | 2018-02-13 23:33:34 | [diff] [blame] | 4348 | for (download::DownloadUrlParameters::RequestHeadersNameValuePair |
| 4349 | key_value : ParseDownloadHeaders(headers)) { |
Megan Jablonski | 2f6a4c5 | 2017-07-10 23:01:25 | [diff] [blame] | 4350 | params->add_request_header(key_value.first, key_value.second); |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 4351 | } |
| 4352 | } |
Xing Liu | 10329bf | 2018-03-20 19:22:14 | [diff] [blame] | 4353 | params->set_suggested_name(suggested_filename); |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 4354 | params->set_download_source(download::DownloadSource::WEB_CONTENTS_API); |
thestig | 859c7889 | 2017-05-15 21:17:06 | [diff] [blame] | 4355 | BrowserContext::GetDownloadManager(GetBrowserContext()) |
Ramin Halavati | 03efa73 | 2017-06-12 09:28:20 | [diff] [blame] | 4356 | ->DownloadUrl(std::move(params)); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 4357 | } |
| 4358 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4359 | void WebContentsImpl::GenerateMHTML( |
dewittj | 6dc5747a | 2016-05-17 01:48:47 | [diff] [blame] | 4360 | const MHTMLGenerationParams& params, |
Avi Drissman | 149b783 | 2018-03-23 14:31:49 | [diff] [blame] | 4361 | base::OnceCallback<void(int64_t)> callback) { |
Angel Alvarez | 90249668 | 2019-08-27 22:58:42 | [diff] [blame] | 4362 | base::OnceCallback<void(const MHTMLGenerationResult&)> wrapper_callback = |
| 4363 | base::BindOnce( |
| 4364 | [](base::OnceCallback<void(int64_t)> size_callback, |
| 4365 | const MHTMLGenerationResult& result) { |
| 4366 | std::move(size_callback).Run(result.file_size); |
| 4367 | }, |
| 4368 | std::move(callback)); |
| 4369 | MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params, |
| 4370 | std::move(wrapper_callback)); |
| 4371 | } |
| 4372 | |
| 4373 | void WebContentsImpl::GenerateMHTMLWithResult( |
| 4374 | const MHTMLGenerationParams& params, |
| 4375 | MHTMLGenerationResult::GenerateMHTMLCallback callback) { |
Avi Drissman | 149b783 | 2018-03-23 14:31:49 | [diff] [blame] | 4376 | MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params, |
| 4377 | std::move(callback)); |
[email protected] | aa4f397 | 2012-03-01 18:12:12 | [diff] [blame] | 4378 | } |
| 4379 | |
Tsuyoshi Horo | b0d8d90 | 2020-03-12 00:09:39 | [diff] [blame] | 4380 | void WebContentsImpl::GenerateWebBundle( |
| 4381 | const base::FilePath& file_path, |
| 4382 | base::OnceCallback<void(uint64_t /* file_size */, |
| 4383 | data_decoder::mojom::WebBundlerError)> callback) { |
| 4384 | SaveAsWebBundleJob::Start(this, file_path, std::move(callback)); |
| 4385 | } |
| 4386 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4387 | const std::string& WebContentsImpl::GetContentsMimeType() { |
Yuzu Saijo | c23e9b7 | 2020-06-25 07:21:27 | [diff] [blame] | 4388 | return GetRenderViewHost()->contents_mime_type(); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4389 | } |
| 4390 | |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 4391 | blink::mojom::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4392 | return &renderer_preferences_; |
| 4393 | } |
| 4394 | |
[email protected] | e35ccd5 | 2012-05-23 16:22:47 | [diff] [blame] | 4395 | void WebContentsImpl::Close() { |
| 4396 | Close(GetRenderViewHost()); |
| 4397 | } |
| 4398 | |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 4399 | void WebContentsImpl::DragSourceEndedAt(float client_x, |
| 4400 | float client_y, |
| 4401 | float screen_x, |
| 4402 | float screen_y, |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 4403 | blink::WebDragOperation operation, |
| 4404 | RenderWidgetHost* source_rwh) { |
Lei Zhang | 6410ec1a | 2019-01-31 21:38:58 | [diff] [blame] | 4405 | if (browser_plugin_embedder_) { |
W. James MacLean | 9437b5bf | 2019-12-06 17:33:44 | [diff] [blame] | 4406 | browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y, screen_x, |
| 4407 | screen_y, operation); |
Lei Zhang | 6410ec1a | 2019-01-31 21:38:58 | [diff] [blame] | 4408 | } |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 4409 | if (source_rwh) { |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 4410 | source_rwh->DragSourceEndedAt(gfx::PointF(client_x, client_y), |
| 4411 | gfx::PointF(screen_x, screen_y), operation); |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 4412 | } |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 4413 | } |
| 4414 | |
jam | 73f89264 | 2016-09-11 06:04:06 | [diff] [blame] | 4415 | void WebContentsImpl::LoadStateChanged( |
Charles Harrison | 911fa06 | 2018-03-06 21:01:46 | [diff] [blame] | 4416 | const std::string& host, |
jam | 73f89264 | 2016-09-11 06:04:06 | [diff] [blame] | 4417 | const net::LoadStateWithParam& load_state, |
| 4418 | uint64_t upload_position, |
| 4419 | uint64_t upload_size) { |
Charles Harrison | 911fa06 | 2018-03-06 21:01:46 | [diff] [blame] | 4420 | base::string16 host16 = url_formatter::IDNToUnicode(host); |
Elly Fong-Jones | cad9c3d1 | 2018-01-31 17:26:10 | [diff] [blame] | 4421 | // Drop no-op updates. |
| 4422 | if (load_state_.state == load_state.state && |
| 4423 | load_state_.param == load_state.param && |
| 4424 | upload_position_ == upload_position && upload_size_ == upload_size && |
Charles Harrison | 911fa06 | 2018-03-06 21:01:46 | [diff] [blame] | 4425 | load_state_host_ == host16) { |
Elly Fong-Jones | cad9c3d1 | 2018-01-31 17:26:10 | [diff] [blame] | 4426 | return; |
| 4427 | } |
jam | 73f89264 | 2016-09-11 06:04:06 | [diff] [blame] | 4428 | load_state_ = load_state; |
| 4429 | upload_position_ = upload_position; |
| 4430 | upload_size_ = upload_size; |
Charles Harrison | 911fa06 | 2018-03-06 21:01:46 | [diff] [blame] | 4431 | load_state_host_ = host16; |
jam | 73f89264 | 2016-09-11 06:04:06 | [diff] [blame] | 4432 | if (load_state_.state == net::LOAD_STATE_READING_RESPONSE) |
| 4433 | SetNotWaitingForResponse(); |
| 4434 | if (IsLoading()) { |
| 4435 | NotifyNavigationStateChanged(static_cast<InvalidateTypes>( |
| 4436 | INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB)); |
| 4437 | } |
| 4438 | } |
| 4439 | |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 4440 | void WebContentsImpl::SetVisibilityAndNotifyObservers(Visibility visibility) { |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 4441 | const Visibility previous_visibility = visibility_; |
| 4442 | visibility_ = visibility; |
| 4443 | |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 4444 | // Notify observers if the visibility changed or if WasShown() is being called |
| 4445 | // for the first time. |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 4446 | if (visibility != previous_visibility || |
| 4447 | (visibility == Visibility::VISIBLE && !did_first_set_visible_)) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 4448 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 4449 | observer->OnVisibilityChanged(visibility); |
| 4450 | }); |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 4451 | } |
| 4452 | } |
| 4453 | |
Michael Thiessen | 896405db | 2017-07-20 17:52:32 | [diff] [blame] | 4454 | void WebContentsImpl::NotifyWebContentsFocused( |
| 4455 | RenderWidgetHost* render_widget_host) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 4456 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 4457 | observer->OnWebContentsFocused(render_widget_host); |
| 4458 | }); |
calamity | 7fe55ce | 2015-04-10 03:59:37 | [diff] [blame] | 4459 | } |
| 4460 | |
Michael Thiessen | 896405db | 2017-07-20 17:52:32 | [diff] [blame] | 4461 | void WebContentsImpl::NotifyWebContentsLostFocus( |
| 4462 | RenderWidgetHost* render_widget_host) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 4463 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 4464 | observer->OnWebContentsLostFocus(render_widget_host); |
| 4465 | }); |
zijiehe | 3bee08e2 | 2017-05-17 04:14:46 | [diff] [blame] | 4466 | } |
| 4467 | |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 4468 | void WebContentsImpl::SystemDragEnded(RenderWidgetHost* source_rwh) { |
| 4469 | if (source_rwh) |
| 4470 | source_rwh->DragSourceSystemDragEnded(); |
Lei Zhang | 6410ec1a | 2019-01-31 21:38:58 | [diff] [blame] | 4471 | if (browser_plugin_embedder_) |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 4472 | browser_plugin_embedder_->SystemDragEnded(); |
[email protected] | 7813bd7 | 2011-02-05 02:19:34 | [diff] [blame] | 4473 | } |
| 4474 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4475 | void WebContentsImpl::SetClosedByUserGesture(bool value) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4476 | closed_by_user_gesture_ = value; |
| 4477 | } |
| 4478 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4479 | bool WebContentsImpl::GetClosedByUserGesture() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4480 | return closed_by_user_gesture_; |
| 4481 | } |
| 4482 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4483 | int WebContentsImpl::GetMinimumZoomPercent() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4484 | return minimum_zoom_percent_; |
| 4485 | } |
| 4486 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4487 | int WebContentsImpl::GetMaximumZoomPercent() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4488 | return maximum_zoom_percent_; |
| 4489 | } |
| 4490 | |
Dave Tapuska | 8f7c387 | 2020-02-07 01:16:38 | [diff] [blame] | 4491 | void WebContentsImpl::SetPageScale(float scale_factor) { |
| 4492 | GetMainFrame()->GetAssociatedLocalMainFrame()->SetScaleFactor(scale_factor); |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 4493 | } |
| 4494 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4495 | gfx::Size WebContentsImpl::GetPreferredSize() { |
Francois Doray | 24fc62c | 2017-12-11 17:27:33 | [diff] [blame] | 4496 | return IsBeingCaptured() ? preferred_size_for_capture_ : preferred_size_; |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 4497 | } |
| 4498 | |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 4499 | bool WebContentsImpl::GotResponseToLockMouseRequest( |
| 4500 | blink::mojom::PointerLockResult result) { |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 4501 | if (mouse_lock_widget_) { |
| 4502 | if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) { |
| 4503 | return mouse_lock_widget_->delegate() |
| 4504 | ->GetAsWebContents() |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 4505 | ->GotResponseToLockMouseRequest(result); |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 4506 | } |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 4507 | |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 4508 | if (mouse_lock_widget_->GotResponseToLockMouseRequest(result)) |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 4509 | return true; |
| 4510 | } |
| 4511 | |
| 4512 | for (WebContentsImpl* current = this; current; |
| 4513 | current = current->GetOuterWebContents()) { |
| 4514 | current->mouse_lock_widget_ = nullptr; |
| 4515 | } |
| 4516 | |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 4517 | return false; |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4518 | } |
| 4519 | |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 4520 | void WebContentsImpl::GotLockMousePermissionResponse(bool allowed) { |
| 4521 | GotResponseToLockMouseRequest( |
| 4522 | allowed ? blink::mojom::PointerLockResult::kSuccess |
| 4523 | : blink::mojom::PointerLockResult::kPermissionDenied); |
| 4524 | } |
| 4525 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 4526 | bool WebContentsImpl::GotResponseToKeyboardLockRequest(bool allowed) { |
| 4527 | if (!keyboard_lock_widget_) |
| 4528 | return false; |
| 4529 | |
| 4530 | if (keyboard_lock_widget_->delegate()->GetAsWebContents() != this) { |
| 4531 | NOTREACHED(); |
| 4532 | return false; |
| 4533 | } |
| 4534 | |
| 4535 | // KeyboardLock is only supported when called by the top-level browsing |
| 4536 | // context and is not supported in embedded content scenarios. |
| 4537 | if (GetOuterWebContents()) |
| 4538 | return false; |
| 4539 | |
| 4540 | keyboard_lock_widget_->GotResponseToKeyboardLockRequest(allowed); |
| 4541 | return true; |
| 4542 | } |
| 4543 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4544 | bool WebContentsImpl::HasOpener() { |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 4545 | return GetOpener() != nullptr; |
[email protected] | a0358d7 | 2012-03-09 14:06:50 | [diff] [blame] | 4546 | } |
| 4547 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4548 | RenderFrameHostImpl* WebContentsImpl::GetOpener() { |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 4549 | FrameTreeNode* opener_ftn = frame_tree_.root()->opener(); |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 4550 | return opener_ftn ? opener_ftn->current_frame_host() : nullptr; |
jochen | 55ff350 | 2014-12-18 20:52:57 | [diff] [blame] | 4551 | } |
| 4552 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4553 | bool WebContentsImpl::HasOriginalOpener() { |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 4554 | return GetOriginalOpener() != nullptr; |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 4555 | } |
| 4556 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 4557 | RenderFrameHostImpl* WebContentsImpl::GetOriginalOpener() { |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 4558 | FrameTreeNode* opener_ftn = frame_tree_.root()->original_opener(); |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 4559 | return opener_ftn ? opener_ftn->current_frame_host() : nullptr; |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 4560 | } |
| 4561 | |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 4562 | void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) { |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 4563 | color_chooser_->DidChooseColorInColorChooser(color); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 4564 | } |
| 4565 | |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 4566 | void WebContentsImpl::DidEndColorChooser() { |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 4567 | color_chooser_.reset(); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 4568 | } |
| 4569 | |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 4570 | int WebContentsImpl::DownloadImage( |
| 4571 | const GURL& url, |
| 4572 | bool is_favicon, |
Fredrik Söderquist | b2b39eb9 | 2019-11-18 16:16:50 | [diff] [blame] | 4573 | uint32_t preferred_size, |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 4574 | uint32_t max_bitmap_size, |
| 4575 | bool bypass_cache, |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 4576 | WebContents::ImageDownloadCallback callback) { |
Danyao Wang | a78f3dd2 | 2020-03-05 05:31:27 | [diff] [blame] | 4577 | return DownloadImageInFrame(GlobalFrameRoutingId(), url, is_favicon, |
| 4578 | preferred_size, max_bitmap_size, bypass_cache, |
| 4579 | std::move(callback)); |
| 4580 | } |
| 4581 | |
| 4582 | int WebContentsImpl::DownloadImageInFrame( |
| 4583 | const GlobalFrameRoutingId& initiator_frame_routing_id, |
| 4584 | const GURL& url, |
| 4585 | bool is_favicon, |
| 4586 | uint32_t preferred_size, |
| 4587 | uint32_t max_bitmap_size, |
| 4588 | bool bypass_cache, |
| 4589 | WebContents::ImageDownloadCallback callback) { |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 4590 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 4591 | static int next_image_download_id = 0; |
Danyao Wang | a78f3dd2 | 2020-03-05 05:31:27 | [diff] [blame] | 4592 | |
| 4593 | RenderFrameHostImpl* initiator_frame = |
| 4594 | initiator_frame_routing_id.child_id |
| 4595 | ? RenderFrameHostImpl::FromID(initiator_frame_routing_id) |
| 4596 | : GetMainFrame(); |
Julie Jeongeun Kim | b147357 | 2019-08-15 05:59:13 | [diff] [blame] | 4597 | const mojo::Remote<blink::mojom::ImageDownloader>& mojo_image_downloader = |
Danyao Wang | a78f3dd2 | 2020-03-05 05:31:27 | [diff] [blame] | 4598 | initiator_frame->GetMojoImageDownloader(); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 4599 | const int download_id = ++next_image_download_id; |
| 4600 | if (!mojo_image_downloader) { |
| 4601 | // If the renderer process is dead (i.e. crash, or memory pressure on |
| 4602 | // Android), the downloader service will be invalid. Pre-Mojo, this would |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 4603 | // hang the callback indefinitely since the IPC would be dropped. Now, |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 4604 | // respond with a 400 HTTP error code to indicate that something went wrong. |
Gabriel Charette | e7cdc5cd | 2020-05-27 23:35:05 | [diff] [blame] | 4605 | GetUIThreadTaskRunner({})->PostTask( |
| 4606 | FROM_HERE, |
tzik | e2aca99 | 2017-09-05 08:50:54 | [diff] [blame] | 4607 | base::BindOnce(&WebContentsImpl::OnDidDownloadImage, |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 4608 | weak_factory_.GetWeakPtr(), std::move(callback), |
| 4609 | download_id, url, 400, std::vector<SkBitmap>(), |
| 4610 | std::vector<gfx::Size>())); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 4611 | return download_id; |
| 4612 | } |
| 4613 | |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 4614 | mojo_image_downloader->DownloadImage( |
Fredrik Söderquist | b2b39eb9 | 2019-11-18 16:16:50 | [diff] [blame] | 4615 | url, is_favicon, preferred_size, max_bitmap_size, bypass_cache, |
tzik | e2aca99 | 2017-09-05 08:50:54 | [diff] [blame] | 4616 | base::BindOnce(&WebContentsImpl::OnDidDownloadImage, |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 4617 | weak_factory_.GetWeakPtr(), std::move(callback), |
| 4618 | download_id, url)); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 4619 | return download_id; |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 4620 | } |
| 4621 | |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 4622 | void WebContentsImpl::Find(int request_id, |
| 4623 | const base::string16& search_text, |
Rakina Zata Amni | 3f77dff | 2018-09-08 16:19:43 | [diff] [blame] | 4624 | blink::mojom::FindOptionsPtr options) { |
thestig | 6057a6b2 | 2015-11-12 23:01:33 | [diff] [blame] | 4625 | // Cowardly refuse to search for no text. |
| 4626 | if (search_text.empty()) { |
| 4627 | NOTREACHED(); |
| 4628 | return; |
| 4629 | } |
| 4630 | |
Rakina Zata Amni | 3f77dff | 2018-09-08 16:19:43 | [diff] [blame] | 4631 | GetOrCreateFindRequestManager()->Find(request_id, search_text, |
| 4632 | std::move(options)); |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 4633 | } |
| 4634 | |
| 4635 | void WebContentsImpl::StopFinding(StopFindAction action) { |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 4636 | if (FindRequestManager* manager = GetFindRequestManager()) |
| 4637 | manager->StopFinding(action); |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 4638 | } |
| 4639 | |
Tommy Steimel | 1836051 | 2017-11-01 00:38:19 | [diff] [blame] | 4640 | bool WebContentsImpl::WasEverAudible() { |
| 4641 | return was_ever_audible_; |
| 4642 | } |
| 4643 | |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 4644 | void WebContentsImpl::GetManifest(GetManifestCallback callback) { |
Yuzu Saijo | fce1832 | 2020-05-14 05:02:09 | [diff] [blame] | 4645 | // TODO(yuzus, 1061899): Move this function to RenderFrameHostImpl. |
| 4646 | ManifestManagerHost* manifest_manager_host = |
| 4647 | ManifestManagerHost::GetOrCreateForCurrentDocument(GetMainFrame()); |
| 4648 | manifest_manager_host->GetManifest(std::move(callback)); |
mlamouri | efdca9d | 2014-09-16 16:55:40 | [diff] [blame] | 4649 | } |
| 4650 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 4651 | void WebContentsImpl::ExitFullscreen(bool will_cause_resize) { |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 4652 | // Clean up related state and initiate the fullscreen exit. |
James Hollyer | d5c9de46 | 2020-03-10 19:02:45 | [diff] [blame] | 4653 | GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary( |
| 4654 | blink::mojom::PointerLockResult::kUserRejected); |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 4655 | ExitFullscreenMode(will_cause_resize); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 4656 | } |
| 4657 | |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 4658 | base::ScopedClosureRunner WebContentsImpl::ForSecurityDropFullscreen() { |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 4659 | // Kick WebContentses that are "related" to this WebContents out of |
| 4660 | // fullscreen. This needs to be done with two passes, because it is simple to |
| 4661 | // walk _up_ the chain of openers and outer contents, but it not simple to |
| 4662 | // walk _down_ the chain. |
| 4663 | |
| 4664 | // First, determine if any WebContents that is in fullscreen has this |
| 4665 | // WebContents as an upstream contents. Drop that WebContents out of |
| 4666 | // fullscreen if it does. This is theoretically quadratic-ish (fullscreen |
| 4667 | // contentses x each one's opener length) but neither of those is expected to |
| 4668 | // ever be a large number. |
| 4669 | |
| 4670 | auto fullscreen_set_copy = *FullscreenContentsSet(GetBrowserContext()); |
| 4671 | for (auto* fullscreen_contents : fullscreen_set_copy) { |
Avi Drissman | 97aef04 | 2020-06-30 21:04:48 | [diff] [blame] | 4672 | // Checking IsFullscreen() for tabs in the fullscreen set may seem |
| 4673 | // redundant, but teeeeechnically fullscreen is run by the delegate, and |
| 4674 | // it's possible that the delegate's notion of fullscreen may have changed |
| 4675 | // outside of WebContents's notice. |
| 4676 | if (fullscreen_contents->IsFullscreen()) { |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 4677 | auto opener_contentses = GetAllOpeningWebContents(fullscreen_contents); |
| 4678 | if (opener_contentses.count(this)) |
| 4679 | fullscreen_contents->ExitFullscreen(true); |
| 4680 | } |
| 4681 | } |
| 4682 | |
| 4683 | // Second, walk upstream from this WebContents, and drop the fullscreen of |
| 4684 | // all WebContentses that are in fullscreen. Block all the WebContentses in |
| 4685 | // the chain from entering fullscreen while the returned closure runner is |
| 4686 | // alive. It's OK that this set doesn't contain downstream WebContentses, as |
| 4687 | // any request to enter fullscreen will have the upstream of the WebContents |
| 4688 | // checked. (See CanEnterFullscreenMode().) |
Avi Drissman | ced52b6 | 2019-08-14 21:25:46 | [diff] [blame] | 4689 | |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 4690 | std::vector<base::WeakPtr<WebContentsImpl>> blocked_contentses; |
| 4691 | |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 4692 | for (auto* opener : GetAllOpeningWebContents(this)) { |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 4693 | // Drop fullscreen if the WebContents is in it, and... |
Avi Drissman | 97aef04 | 2020-06-30 21:04:48 | [diff] [blame] | 4694 | if (opener->IsFullscreen()) |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 4695 | opener->ExitFullscreen(true); |
Avi Drissman | ced52b6 | 2019-08-14 21:25:46 | [diff] [blame] | 4696 | |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 4697 | // ...block the WebContents from entering fullscreen until further notice. |
Avi Drissman | 3397294 | 2020-06-19 14:16:01 | [diff] [blame] | 4698 | ++opener->fullscreen_blocker_count_; |
| 4699 | blocked_contentses.push_back(opener->weak_factory_.GetWeakPtr()); |
Avi Drissman | ced52b6 | 2019-08-14 21:25:46 | [diff] [blame] | 4700 | } |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 4701 | |
| 4702 | return base::ScopedClosureRunner(base::BindOnce( |
| 4703 | [](std::vector<base::WeakPtr<WebContentsImpl>> blocked_contentses) { |
| 4704 | for (base::WeakPtr<WebContentsImpl>& web_contents : |
| 4705 | blocked_contentses) { |
| 4706 | if (web_contents) { |
| 4707 | DCHECK_GT(web_contents->fullscreen_blocker_count_, 0); |
| 4708 | --web_contents->fullscreen_blocker_count_; |
| 4709 | } |
| 4710 | } |
| 4711 | }, |
| 4712 | std::move(blocked_contentses))); |
Avi Drissman | ced52b6 | 2019-08-14 21:25:46 | [diff] [blame] | 4713 | } |
| 4714 | |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 4715 | void WebContentsImpl::ResumeLoadingCreatedWebContents() { |
Nasko Oskov | 83a8cf9 | 2018-10-19 14:58:56 | [diff] [blame] | 4716 | if (delayed_load_url_params_.get()) { |
| 4717 | DCHECK(!delayed_open_url_params_); |
| 4718 | controller_.LoadURLWithParams(*delayed_load_url_params_.get()); |
| 4719 | delayed_load_url_params_.reset(nullptr); |
| 4720 | return; |
| 4721 | } |
| 4722 | |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 4723 | if (delayed_open_url_params_.get()) { |
| 4724 | OpenURL(*delayed_open_url_params_.get()); |
| 4725 | delayed_open_url_params_.reset(nullptr); |
| 4726 | return; |
| 4727 | } |
| 4728 | |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 4729 | // Resume blocked requests for both the RenderViewHost and RenderFrameHost. |
| 4730 | // TODO(brettw): It seems bogus to reach into here and initialize the host. |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 4731 | if (is_resume_pending_) { |
| 4732 | is_resume_pending_ = false; |
avi | 0f1bbc971 | 2015-11-17 02:58:13 | [diff] [blame] | 4733 | GetRenderViewHost()->GetWidget()->Init(); |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 4734 | GetMainFrame()->Init(); |
| 4735 | } |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 4736 | } |
| 4737 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4738 | bool WebContentsImpl::FocusLocationBarByDefault() { |
Xiyuan Xia | 2a66b11 | 2018-12-06 15:52:16 | [diff] [blame] | 4739 | if (should_focus_location_bar_by_default_) |
[email protected] | 0c940663 | 2013-02-08 01:13:33 | [diff] [blame] | 4740 | return true; |
Xiyuan Xia | 2a66b11 | 2018-12-06 15:52:16 | [diff] [blame] | 4741 | |
[email protected] | 0c940663 | 2013-02-08 01:13:33 | [diff] [blame] | 4742 | return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4743 | } |
| 4744 | |
Tommy C. Li | 8bb5bf4 | 2019-01-18 18:45:51 | [diff] [blame] | 4745 | void WebContentsImpl::SetFocusToLocationBar() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4746 | if (delegate_) |
Tommy C. Li | 8bb5bf4 | 2019-01-18 18:45:51 | [diff] [blame] | 4747 | delegate_->SetFocusToLocationBar(); |
[email protected] | c40d623 | 2011-03-25 00:16:21 | [diff] [blame] | 4748 | } |
| 4749 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 4750 | void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) { |
Charles Harrison | 53096ba | 2017-12-15 15:39:48 | [diff] [blame] | 4751 | TRACE_EVENT1("navigation", "WebContentsImpl::DidStartNavigation", |
| 4752 | "navigation_handle", navigation_handle); |
Alan Cutter | ab48fc0 | 2020-02-24 12:26:42 | [diff] [blame] | 4753 | if (navigation_handle->IsInMainFrame()) |
| 4754 | favicon_urls_.clear(); |
Mounir Lamouri | 7b4a1f23 | 2019-12-23 16:32:10 | [diff] [blame] | 4755 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 4756 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 4757 | observer->DidStartNavigation(navigation_handle); |
| 4758 | }); |
Xiyuan Xia | 2a66b11 | 2018-12-06 15:52:16 | [diff] [blame] | 4759 | if (navigation_handle->IsInMainFrame()) { |
| 4760 | // When the browser is started with about:blank as the startup URL, focus |
| 4761 | // the location bar (which will also select its contents) so people can |
| 4762 | // simply begin typing to navigate elsewhere. |
| 4763 | // |
| 4764 | // We need to be careful not to trigger this for anything other than the |
| 4765 | // startup navigation. In particular, if we allow an attacker to open a |
| 4766 | // popup to about:blank, then navigate, focusing the Omnibox will cause the |
| 4767 | // end of the new URL to be scrolled into view instead of the start, |
| 4768 | // allowing the attacker to spoof other URLs. The conditions checked here |
| 4769 | // are all aimed at ensuring no such attacker-controlled navigation can |
| 4770 | // trigger this. |
| 4771 | should_focus_location_bar_by_default_ = |
| 4772 | controller_.IsInitialNavigation() && |
| 4773 | !navigation_handle->IsRendererInitiated() && |
| 4774 | navigation_handle->GetURL() == url::kAboutBlankURL; |
| 4775 | } |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 4776 | } |
| 4777 | |
| 4778 | void WebContentsImpl::DidRedirectNavigation( |
| 4779 | NavigationHandle* navigation_handle) { |
Charles Harrison | 53096ba | 2017-12-15 15:39:48 | [diff] [blame] | 4780 | TRACE_EVENT1("navigation", "WebContentsImpl::DidRedirectNavigation", |
| 4781 | "navigation_handle", navigation_handle); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 4782 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 4783 | observer->DidRedirectNavigation(navigation_handle); |
| 4784 | }); |
jam | 5f358e5 | 2017-02-13 16:37:03 | [diff] [blame] | 4785 | // Notify accessibility if this is a reload. This has to called on the |
| 4786 | // BrowserAccessibilityManager associated with the old RFHI. |
| 4787 | if (navigation_handle->GetReloadType() != ReloadType::NONE) { |
Mohamed Abdelhalim | 9579496 | 2019-09-20 11:16:49 | [diff] [blame] | 4788 | NavigationRequest* request = NavigationRequest::From(navigation_handle); |
jam | 5f358e5 | 2017-02-13 16:37:03 | [diff] [blame] | 4789 | BrowserAccessibilityManager* manager = |
Mohamed Abdelhalim | 9579496 | 2019-09-20 11:16:49 | [diff] [blame] | 4790 | request->frame_tree_node() |
jam | 5f358e5 | 2017-02-13 16:37:03 | [diff] [blame] | 4791 | ->current_frame_host() |
| 4792 | ->browser_accessibility_manager(); |
| 4793 | if (manager) |
| 4794 | manager->UserIsReloading(); |
| 4795 | } |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 4796 | } |
| 4797 | |
clamy | efca29e | 2015-09-17 00:22:11 | [diff] [blame] | 4798 | void WebContentsImpl::ReadyToCommitNavigation( |
| 4799 | NavigationHandle* navigation_handle) { |
Charles Harrison | 53096ba | 2017-12-15 15:39:48 | [diff] [blame] | 4800 | TRACE_EVENT1("navigation", "WebContentsImpl::ReadyToCommitNavigation", |
| 4801 | "navigation_handle", navigation_handle); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 4802 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 4803 | observer->ReadyToCommitNavigation(navigation_handle); |
| 4804 | }); |
Kenneth Russell | 954ed9ce | 2018-04-12 23:07:01 | [diff] [blame] | 4805 | // If any domains are blocked from accessing 3D APIs because they may |
| 4806 | // have caused the GPU to reset recently, unblock them here if the user |
| 4807 | // initiated this navigation. This implies that the user was involved in |
| 4808 | // the decision to navigate, so there's no concern about |
| 4809 | // denial-of-service issues. Want to do this as early as |
| 4810 | // possible to avoid race conditions with pages attempting to access |
| 4811 | // WebGL early on. |
| 4812 | // |
| 4813 | // TODO(crbug.com/617904): currently navigations initiated by the browser |
| 4814 | // (reload button, reload menu option, pressing return in the Omnibox) |
| 4815 | // return false from HasUserGesture(). If or when that is addressed, |
| 4816 | // remove the check for IsRendererInitiated() below. |
| 4817 | // |
| 4818 | // TODO(crbug.com/832180): HasUserGesture comes from the renderer |
| 4819 | // process and isn't validated. Until it is, don't trust it. |
| 4820 | if (!navigation_handle->IsRendererInitiated()) { |
| 4821 | GpuDataManagerImpl::GetInstance()->UnblockDomainFrom3DAPIs( |
| 4822 | navigation_handle->GetURL()); |
| 4823 | } |
| 4824 | |
John Abd-El-Malek | fde08e6da | 2017-12-05 04:06:24 | [diff] [blame] | 4825 | if (navigation_handle->IsSameDocument()) |
| 4826 | return; |
| 4827 | |
Livvie Lin | 139bf44 | 2018-08-10 00:18:54 | [diff] [blame] | 4828 | // SSLInfo is not needed on subframe navigations since the main-frame |
| 4829 | // certificate is the only one that can be inspected (using the info |
| 4830 | // bubble) without refreshing the page with DevTools open. |
Carlos IL | aed1e7b | 2019-03-12 19:27:21 | [diff] [blame] | 4831 | // We don't call DidStartResourceResponse on net errors, since that results on |
| 4832 | // existing cert exceptions being revoked, which leads to weird behavior with |
| 4833 | // committed interstitials or while offline. We only need the error check for |
| 4834 | // the main frame case because unlike this method, SubresourceResponseStarted |
| 4835 | // does not get called on network errors. |
| 4836 | if (navigation_handle->IsInMainFrame() && |
| 4837 | navigation_handle->GetNetErrorCode() == net::OK) { |
Livvie Lin | 139bf44 | 2018-08-10 00:18:54 | [diff] [blame] | 4838 | controller_.ssl_manager()->DidStartResourceResponse( |
Lukasz Anforowicz | d334bba | 2020-02-10 23:32:55 | [diff] [blame] | 4839 | navigation_handle->GetURL(), |
Camille Lamy | 62b82601 | 2019-02-26 09:15:47 | [diff] [blame] | 4840 | navigation_handle->GetSSLInfo().has_value() |
| 4841 | ? net::IsCertStatusError( |
| 4842 | navigation_handle->GetSSLInfo()->cert_status) |
| 4843 | : false); |
| 4844 | } |
John Abd-El-Malek | fde08e6da | 2017-12-05 04:06:24 | [diff] [blame] | 4845 | |
| 4846 | SetNotWaitingForResponse(); |
clamy | efca29e | 2015-09-17 00:22:11 | [diff] [blame] | 4847 | } |
| 4848 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 4849 | void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) { |
Charles Harrison | 53096ba | 2017-12-15 15:39:48 | [diff] [blame] | 4850 | TRACE_EVENT1("navigation", "WebContentsImpl::DidFinishNavigation", |
| 4851 | "navigation_handle", navigation_handle); |
Steven Holte | 3804134 | 2018-06-22 22:00:57 | [diff] [blame] | 4852 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 4853 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 4854 | observer->DidFinishNavigation(navigation_handle); |
| 4855 | }); |
Becca Hughes | d11d650 | 2018-07-31 17:01:28 | [diff] [blame] | 4856 | if (display_cutout_host_impl_) |
| 4857 | display_cutout_host_impl_->DidFinishNavigation(navigation_handle); |
| 4858 | |
jam | 5f358e5 | 2017-02-13 16:37:03 | [diff] [blame] | 4859 | if (navigation_handle->HasCommitted()) { |
Ian Prest | cdd843d | 2020-01-28 18:59:58 | [diff] [blame] | 4860 | // TODO(domfarolino, dmazzoni): Do this using WebContentsObserver. See |
| 4861 | // https://crbug.com/981271. |
| 4862 | BrowserAccessibilityManager* manager = |
| 4863 | static_cast<RenderFrameHostImpl*>( |
| 4864 | navigation_handle->GetRenderFrameHost()) |
| 4865 | ->browser_accessibility_manager(); |
| 4866 | if (manager) { |
| 4867 | if (navigation_handle->IsErrorPage()) { |
| 4868 | manager->NavigationFailed(); |
| 4869 | } else { |
| 4870 | manager->NavigationSucceeded(); |
| 4871 | } |
| 4872 | } |
| 4873 | |
Yue Ru Sun | 979c4b16 | 2019-11-06 16:11:04 | [diff] [blame] | 4874 | if (navigation_handle->IsInMainFrame()) { |
| 4875 | last_committed_source_id_including_same_document_ = |
Steven Holte | 3804134 | 2018-06-22 22:00:57 | [diff] [blame] | 4876 | ukm::ConvertToSourceId(navigation_handle->GetNavigationId(), |
| 4877 | ukm::SourceIdType::NAVIGATION_ID); |
Yue Ru Sun | 979c4b16 | 2019-11-06 16:11:04 | [diff] [blame] | 4878 | |
| 4879 | if (!navigation_handle->IsSameDocument()) { |
| 4880 | was_ever_audible_ = false; |
Yue Ru Sun | 979c4b16 | 2019-11-06 16:11:04 | [diff] [blame] | 4881 | } |
Tommy Steimel | 1836051 | 2017-11-01 00:38:19 | [diff] [blame] | 4882 | } |
Lan Wei | f81c6e7c | 2020-02-12 16:46:09 | [diff] [blame] | 4883 | |
| 4884 | if (!navigation_handle->IsSameDocument()) |
| 4885 | last_screen_orientation_change_time_ = base::TimeTicks(); |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 4886 | } |
Xiyuan Xia | 2a66b11 | 2018-12-06 15:52:16 | [diff] [blame] | 4887 | |
| 4888 | // If we didn't end up on about:blank after setting this in DidStartNavigation |
| 4889 | // then don't focus the location bar. |
| 4890 | if (should_focus_location_bar_by_default_ && |
| 4891 | navigation_handle->GetURL() != url::kAboutBlankURL) { |
| 4892 | should_focus_location_bar_by_default_ = false; |
| 4893 | } |
yilkal | 796e89e | 2019-10-02 23:58:28 | [diff] [blame] | 4894 | |
yilkal | 172da77 | 2019-11-06 22:49:07 | [diff] [blame] | 4895 | if (navigation_handle->IsInMainFrame() && first_navigation_completed_) |
| 4896 | RecordMaxFrameCountUMA(max_loaded_frame_count_); |
yilkal | 796e89e | 2019-10-02 23:58:28 | [diff] [blame] | 4897 | |
yilkal | 172da77 | 2019-11-06 22:49:07 | [diff] [blame] | 4898 | // If navigation has successfully finished in the main frame, set |
| 4899 | // |first_navigation_completed_| to true so that we will record |
| 4900 | // |max_loaded_frame_count_| above when future main frame navigations finish. |
| 4901 | if (navigation_handle->IsInMainFrame() && !navigation_handle->IsErrorPage()) { |
| 4902 | first_navigation_completed_ = true; |
| 4903 | |
| 4904 | // Navigation has completed in main frame. Reset |max_loaded_frame_count_|. |
| 4905 | // |max_loaded_frame_count_| is not necessarily 1 if the navigation was |
| 4906 | // served from BackForwardCache. |
| 4907 | max_loaded_frame_count_ = |
| 4908 | GetMainFrame()->frame_tree_node()->GetFrameTreeSize(); |
yilkal | 796e89e | 2019-10-02 23:58:28 | [diff] [blame] | 4909 | } |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 4910 | |
| 4911 | if (web_preferences_) { |
| 4912 | // Update the WebPreferences for this WebContents that depends on changes |
| 4913 | // that might occur during navigation. This will only update the preferences |
| 4914 | // that needs to be updated (and won't cause an update/overwrite preferences |
| 4915 | // that needs to stay the same after navigations). |
| 4916 | bool value_changed_due_to_override = |
| 4917 | GetContentClient()->browser()->OverrideWebPreferencesAfterNavigation( |
| 4918 | this, web_preferences_.get()); |
| 4919 | // We need to update the WebPreferences value on the renderer if the value |
| 4920 | // is changed due to the override above, or if the navigation is served from |
| 4921 | // the back-forward cache, because the WebPreferences value stored in the |
| 4922 | // renderer might be stale (because we don't send WebPreferences updates to |
| 4923 | // bfcached renderers). |
| 4924 | // TODO(rakina): Maybe handle the back-forward cache case in |
| 4925 | // ReadyToCommitNavigation instead? |
| 4926 | if (value_changed_due_to_override || |
| 4927 | NavigationRequest::From(navigation_handle) |
| 4928 | ->IsServedFromBackForwardCache()) { |
| 4929 | SetWebPreferences(*web_preferences_.get()); |
| 4930 | } |
| 4931 | } |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 4932 | } |
| 4933 | |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 4934 | void WebContentsImpl::DidFailLoadWithError( |
| 4935 | RenderFrameHostImpl* render_frame_host, |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 4936 | const GURL& url, |
Dave Tapuska | 924ef3c | 2020-01-22 18:20:59 | [diff] [blame] | 4937 | int error_code) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 4938 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 4939 | observer->DidFailLoad(render_frame_host, url, error_code); |
| 4940 | }); |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 4941 | } |
| 4942 | |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 4943 | void WebContentsImpl::NotifyChangedNavigationState( |
| 4944 | InvalidateTypes changed_flags) { |
| 4945 | NotifyNavigationStateChanged(changed_flags); |
| 4946 | } |
| 4947 | |
lukasza | 1d02573 | 2016-09-28 21:36:08 | [diff] [blame] | 4948 | bool WebContentsImpl::ShouldTransferNavigation(bool is_main_frame_navigation) { |
creis | 2946027 | 2015-12-16 04:38:22 | [diff] [blame] | 4949 | if (!delegate_) |
| 4950 | return true; |
lukasza | 1d02573 | 2016-09-28 21:36:08 | [diff] [blame] | 4951 | return delegate_->ShouldTransferNavigation(is_main_frame_navigation); |
creis | 2946027 | 2015-12-16 04:38:22 | [diff] [blame] | 4952 | } |
| 4953 | |
[email protected] | aa62afd | 2014-04-22 19:22:46 | [diff] [blame] | 4954 | bool WebContentsImpl::ShouldPreserveAbortedURLs() { |
| 4955 | if (!delegate_) |
| 4956 | return false; |
| 4957 | return delegate_->ShouldPreserveAbortedURLs(this); |
| 4958 | } |
| 4959 | |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 4960 | void WebContentsImpl::DidNavigateMainFramePreCommit( |
[email protected] | 5cfbddc | 2014-06-23 23:52:23 | [diff] [blame] | 4961 | bool navigation_is_within_page) { |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 4962 | // Ensure fullscreen mode is exited before committing the navigation to a |
| 4963 | // different page. The next page will not start out assuming it is in |
| 4964 | // fullscreen mode. |
[email protected] | 5cfbddc | 2014-06-23 23:52:23 | [diff] [blame] | 4965 | if (navigation_is_within_page) { |
[email protected] | dfc39cb | 2014-04-09 22:58:19 | [diff] [blame] | 4966 | // No page change? Then, the renderer and browser can remain in fullscreen. |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 4967 | return; |
| 4968 | } |
Avi Drissman | 97aef04 | 2020-06-30 21:04:48 | [diff] [blame] | 4969 | if (IsFullscreen()) |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 4970 | ExitFullscreen(false); |
Avi Drissman | 97aef04 | 2020-06-30 21:04:48 | [diff] [blame] | 4971 | DCHECK(!IsFullscreen()); |
Joe Downing | c1a57efe | 2018-05-09 18:23:54 | [diff] [blame] | 4972 | |
| 4973 | // Clean up keyboard lock state when navigating. |
| 4974 | CancelKeyboardLock(keyboard_lock_widget_); |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 4975 | } |
| 4976 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 4977 | void WebContentsImpl::DidNavigateMainFramePostCommit( |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 4978 | RenderFrameHostImpl* render_frame_host, |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 4979 | const LoadCommittedDetails& details, |
| 4980 | const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
| 4981 | if (details.is_navigation_to_different_page()) { |
| 4982 | // Clear the status bubble. This is a workaround for a bug where WebKit |
| 4983 | // doesn't let us know that the cursor left an element during a |
| 4984 | // transition (this is also why the mouse cursor remains as a hand after |
| 4985 | // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 4986 | // clear the bubble when a user navigates to a named anchor in the same |
| 4987 | // page. |
Lukasz Anforowicz | fd70714 | 2018-02-07 19:46:13 | [diff] [blame] | 4988 | ClearTargetURL(); |
lanwei | 9d343ad2 | 2015-02-11 01:46:00 | [diff] [blame] | 4989 | |
| 4990 | RenderWidgetHostViewBase* rwhvb = |
| 4991 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 4992 | if (rwhvb) |
| 4993 | rwhvb->OnDidNavigateMainFrameToNewPage(); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 4994 | } |
| 4995 | |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 4996 | if (delegate_) |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 4997 | delegate_->DidNavigateMainFramePostCommit(this); |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 4998 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
Shivani Sharma | 985474f | 2019-05-23 21:36:47 | [diff] [blame] | 4999 | |
Carlos Caballero | 91fffb2 | 2019-10-29 15:24:30 | [diff] [blame] | 5000 | if (details.is_navigation_to_different_page() && |
| 5001 | GetRenderViewHost()->did_first_visually_non_empty_paint()) { |
| 5002 | // This event will not fire again if the page is restored from the |
| 5003 | // BackForwardCache. So fire it ourselves if needed. |
| 5004 | DidFirstVisuallyNonEmptyPaint(GetRenderViewHost()); |
| 5005 | } |
Carlos Caballero | 1215f88 | 2019-10-29 15:58:43 | [diff] [blame] | 5006 | |
| 5007 | if (GetRenderViewHost()->theme_color() != last_sent_theme_color_) { |
| 5008 | // This event will not fire again if the page is restored from the |
| 5009 | // BackForwardCache. So fire it ourselves if needed. |
| 5010 | OnThemeColorChanged(GetRenderViewHost()); |
| 5011 | } |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 5012 | } |
| 5013 | |
| 5014 | void WebContentsImpl::DidNavigateAnyFramePostCommit( |
| 5015 | RenderFrameHostImpl* render_frame_host, |
| 5016 | const LoadCommittedDetails& details, |
| 5017 | const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 5018 | // Now that something has committed, we don't need to track whether the |
| 5019 | // initial page has been accessed. |
| 5020 | has_accessed_initial_document_ = false; |
| 5021 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 5022 | // If we navigate off the page, close all JavaScript dialogs. |
eugenebut | ee08663a | 2017-04-27 17:43:12 | [diff] [blame] | 5023 | if (!details.is_same_document) |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 5024 | CancelActiveAndPendingDialogs(); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 5025 | |
avi | d53461d | 2016-02-25 17:15:04 | [diff] [blame] | 5026 | // If this is a user-initiated navigation, start allowing JavaScript dialogs |
| 5027 | // again. |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 5028 | if (params.gesture == NavigationGestureUser && dialog_manager_) { |
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 5029 | dialog_manager_->CancelDialogs(this, /*reset_state=*/true); |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 5030 | } |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 5031 | } |
| 5032 | |
[email protected] | 277857a | 2014-06-03 10:38:01 | [diff] [blame] | 5033 | bool WebContentsImpl::CanOverscrollContent() const { |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 5034 | // Disable overscroll when touch emulation is on. See crbug.com/369938. |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 5035 | if (force_disable_overscroll_content_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 5036 | return false; |
| 5037 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 5038 | if (delegate_) |
| 5039 | return delegate_->CanOverscrollContent(); |
| 5040 | |
| 5041 | return false; |
| 5042 | } |
| 5043 | |
Carlos Caballero | 1215f88 | 2019-10-29 15:58:43 | [diff] [blame] | 5044 | void WebContentsImpl::OnThemeColorChanged(RenderViewHostImpl* source) { |
| 5045 | if (source->did_first_visually_non_empty_paint() && |
| 5046 | last_sent_theme_color_ != source->theme_color()) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5047 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5048 | observer->DidChangeThemeColor(); |
| 5049 | }); |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 5050 | } |
[email protected] | e710476 | 2014-06-20 19:17:25 | [diff] [blame] | 5051 | } |
| 5052 | |
Gyuyoung Kim | 1905f7c | 2020-05-02 00:00:24 | [diff] [blame] | 5053 | void WebContentsImpl::DidLoadResourceFromMemoryCache( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5054 | RenderFrameHostImpl* source, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 5055 | const GURL& url, |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 5056 | const std::string& http_method, |
[email protected] | 6d6cfb3a | 2012-05-23 22:53:18 | [diff] [blame] | 5057 | const std::string& mime_type, |
Kinuko Yasuda | 433f710a | 2020-02-14 02:11:58 | [diff] [blame] | 5058 | network::mojom::RequestDestination request_destination) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5059 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5060 | observer->DidLoadResourceFromMemoryCache(url, mime_type, |
| 5061 | request_destination); |
| 5062 | }); |
[email protected] | b0f724c | 2013-09-05 04:21:13 | [diff] [blame] | 5063 | |
Steven Bingler | 674fb082 | 2018-12-12 18:04:52 | [diff] [blame] | 5064 | if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5065 | StoragePartition* partition = source->GetProcess()->GetStoragePartition(); |
John Abd-El-Malek | f4fe9d8 | 2019-07-31 04:05:59 | [diff] [blame] | 5066 | partition->GetNetworkContext()->NotifyExternalCacheHit( |
Matt Menke | 2a33dee | 2019-12-02 17:01:54 | [diff] [blame] | 5067 | url, http_method, source->GetNetworkIsolationKey()); |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 5068 | } |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 5069 | } |
| 5070 | |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 5071 | void WebContentsImpl::DidDisplayInsecureContent() { |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 5072 | controller_.ssl_manager()->DidDisplayMixedContent(); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 5073 | } |
| 5074 | |
Dave Tapuska | a657d87 | 2019-10-21 20:23:21 | [diff] [blame] | 5075 | void WebContentsImpl::DidContainInsecureFormAction() { |
elawrence | b2ac2a23 | 2017-03-27 21:46:25 | [diff] [blame] | 5076 | controller_.ssl_manager()->DidContainInsecureFormAction(); |
| 5077 | } |
| 5078 | |
Julie Jeongeun Kim | 0b10349 | 2020-01-29 05:30:51 | [diff] [blame] | 5079 | void WebContentsImpl::DocumentAvailableInMainFrame() { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5080 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5081 | observer->DocumentAvailableInMainFrame(); |
| 5082 | }); |
Julie Jeongeun Kim | 0b10349 | 2020-01-29 05:30:51 | [diff] [blame] | 5083 | } |
| 5084 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5085 | void WebContentsImpl::OnDidRunInsecureContent(RenderFrameHostImpl* source, |
| 5086 | const GURL& security_origin, |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 5087 | const GURL& target_url) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5088 | // TODO(nick, estark): Should we call FilterURL using |source|'s process on |
| 5089 | // these parameters? |target_url| seems unused, except for a log message. And |
| 5090 | // |security_origin| might be replaceable with the origin of the main frame. |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 5091 | DidRunInsecureContent(security_origin, target_url); |
| 5092 | } |
| 5093 | |
| 5094 | void WebContentsImpl::DidRunInsecureContent(const GURL& security_origin, |
| 5095 | const GURL& target_url) { |
[email protected] | 9450c46 | 2013-11-23 01:22:58 | [diff] [blame] | 5096 | LOG(WARNING) << security_origin << " ran insecure content from " |
| 5097 | << target_url.possibly_invalid_spec(); |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 5098 | RecordAction(base::UserMetricsAction("SSL.RanInsecureContent")); |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 5099 | if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom, |
brettw | a7ff1b29 | 2015-07-16 17:49:29 | [diff] [blame] | 5100 | base::CompareCase::INSENSITIVE_ASCII)) |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 5101 | RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle")); |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 5102 | controller_.ssl_manager()->DidRunMixedContent(security_origin); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 5103 | } |
| 5104 | |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 5105 | void WebContentsImpl::PassiveInsecureContentFound(const GURL& resource_url) { |
Sergey Kuznetsov | 3ebc01b | 2018-02-01 04:57:36 | [diff] [blame] | 5106 | if (delegate_) { |
| 5107 | delegate_->PassiveInsecureContentFound(resource_url); |
| 5108 | } |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 5109 | } |
| 5110 | |
| 5111 | bool WebContentsImpl::ShouldAllowRunningInsecureContent( |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 5112 | bool allowed_per_prefs, |
| 5113 | const url::Origin& origin, |
| 5114 | const GURL& resource_url) { |
Sergey Kuznetsov | 3ebc01b | 2018-02-01 04:57:36 | [diff] [blame] | 5115 | if (delegate_) { |
Carlos IL | 29294a6 | 2020-05-15 00:21:16 | [diff] [blame] | 5116 | return delegate_->ShouldAllowRunningInsecureContent(this, allowed_per_prefs, |
| 5117 | origin, resource_url); |
Sergey Kuznetsov | 3ebc01b | 2018-02-01 04:57:36 | [diff] [blame] | 5118 | } |
| 5119 | |
| 5120 | return allowed_per_prefs; |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 5121 | } |
| 5122 | |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5123 | void WebContentsImpl::ViewSource(RenderFrameHostImpl* frame) { |
| 5124 | DCHECK_EQ(this, WebContents::FromRenderFrameHost(frame)); |
| 5125 | |
| 5126 | // Don't do anything if there is no |delegate_| that could accept and show the |
| 5127 | // new WebContents containing the view-source. |
| 5128 | if (!delegate_) |
| 5129 | return; |
| 5130 | |
| 5131 | // Use the last committed entry, since the pending entry hasn't loaded yet and |
| 5132 | // won't be copied into the cloned tab. |
| 5133 | NavigationEntryImpl* last_committed_entry = |
Fergal Daly | 09d6c76 | 2020-05-29 02:05:18 | [diff] [blame] | 5134 | GetController().GetLastCommittedEntry(); |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5135 | if (!last_committed_entry) |
| 5136 | return; |
| 5137 | |
| 5138 | FrameNavigationEntry* frame_entry = |
| 5139 | last_committed_entry->GetFrameEntry(frame->frame_tree_node()); |
| 5140 | if (!frame_entry) |
| 5141 | return; |
| 5142 | |
| 5143 | // Any new WebContents opened while this WebContents is in fullscreen can be |
| 5144 | // used to confuse the user, so drop fullscreen. |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 5145 | base::ScopedClosureRunner fullscreen_block = ForSecurityDropFullscreen(); |
| 5146 | // The new view source contents will be independent of this contents, so |
| 5147 | // release the fullscreen block. |
| 5148 | fullscreen_block.RunAndReset(); |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5149 | |
| 5150 | // We intentionally don't share the SiteInstance with the original frame so |
| 5151 | // that view source has a consistent process model and always ends up in a new |
| 5152 | // process (https://crbug.com/699493). |
| 5153 | scoped_refptr<SiteInstanceImpl> site_instance_for_view_source = nullptr; |
Lukasz Anforowicz | 435bcb58 | 2019-07-12 20:50:06 | [diff] [blame] | 5154 | // Referrer and initiator are not important, because view-source should not |
| 5155 | // hit the network, but should be served from the cache instead. |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5156 | Referrer referrer_for_view_source; |
Lukasz Anforowicz | 435bcb58 | 2019-07-12 20:50:06 | [diff] [blame] | 5157 | base::Optional<url::Origin> initiator_for_view_source = base::nullopt; |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5158 | // Do not restore title, derive it from the url. |
| 5159 | base::string16 title_for_view_source; |
| 5160 | auto navigation_entry = std::make_unique<NavigationEntryImpl>( |
| 5161 | site_instance_for_view_source, frame_entry->url(), |
Lukasz Anforowicz | 435bcb58 | 2019-07-12 20:50:06 | [diff] [blame] | 5162 | referrer_for_view_source, initiator_for_view_source, |
| 5163 | title_for_view_source, ui::PAGE_TRANSITION_LINK, |
Marijn Kruisselbrink | 7a0d5e18 | 2018-05-24 22:55:09 | [diff] [blame] | 5164 | /* is_renderer_initiated = */ false, |
| 5165 | /* blob_url_loader_factory = */ nullptr); |
Joel Hockey | 891e8806 | 2020-04-30 05:38:44 | [diff] [blame] | 5166 | const GURL url(content::kViewSourceScheme + std::string(":") + |
| 5167 | frame_entry->url().spec()); |
| 5168 | navigation_entry->SetVirtualURL(url); |
Matt Menke | a56c599 | 2020-04-10 20:53:56 | [diff] [blame] | 5169 | navigation_entry->set_isolation_info( |
| 5170 | frame->GetIsolationInfoForSubresources()); |
Yao Xiao | f68f57d | 2019-10-03 04:20:05 | [diff] [blame] | 5171 | |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5172 | // Do not restore scroller position. |
| 5173 | // TODO(creis, lukasza, arthursonzogni): Do not reuse the original PageState, |
| 5174 | // but start from a new one and only copy the needed data. |
| 5175 | const PageState& new_page_state = |
| 5176 | frame_entry->page_state().RemoveScrollOffset(); |
| 5177 | |
| 5178 | scoped_refptr<FrameNavigationEntry> new_frame_entry = |
| 5179 | navigation_entry->root_node()->frame_entry; |
| 5180 | new_frame_entry->set_method(frame_entry->method()); |
| 5181 | new_frame_entry->SetPageState(new_page_state); |
| 5182 | |
| 5183 | // Create a new WebContents, which is used to display the source code. |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 5184 | std::unique_ptr<WebContents> view_source_contents = |
Erik Chen | bb8e738e | 2018-04-28 14:10:43 | [diff] [blame] | 5185 | Create(CreateParams(GetBrowserContext())); |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5186 | |
| 5187 | // Restore the previously created NavigationEntry. |
| 5188 | std::vector<std::unique_ptr<NavigationEntry>> navigation_entries; |
| 5189 | navigation_entries.push_back(std::move(navigation_entry)); |
| 5190 | view_source_contents->GetController().Restore(0, RestoreType::CURRENT_SESSION, |
| 5191 | &navigation_entries); |
| 5192 | |
| 5193 | // Add |view_source_contents| as a new tab. |
| 5194 | gfx::Rect initial_rect; |
| 5195 | constexpr bool kUserGesture = true; |
| 5196 | bool ignored_was_blocked; |
Joel Hockey | 891e8806 | 2020-04-30 05:38:44 | [diff] [blame] | 5197 | delegate_->AddNewContents(this, std::move(view_source_contents), url, |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 5198 | WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 5199 | initial_rect, kUserGesture, &ignored_was_blocked); |
| 5200 | // Note that the |delegate_| could have deleted |view_source_contents| during |
| 5201 | // AddNewContents method call. |
| 5202 | } |
| 5203 | |
Lukasz Anforowicz | d334bba | 2020-02-10 23:32:55 | [diff] [blame] | 5204 | void WebContentsImpl::SubresourceResponseStarted(const GURL& url, |
| 5205 | net::CertStatus cert_status) { |
| 5206 | controller_.ssl_manager()->DidStartResourceResponse(url, cert_status); |
Jay Civelli | d5904f0 | 2018-03-23 19:43:57 | [diff] [blame] | 5207 | SetNotWaitingForResponse(); |
| 5208 | } |
| 5209 | |
Jay Civelli | 116683f | 2018-03-27 19:56:23 | [diff] [blame] | 5210 | void WebContentsImpl::ResourceLoadComplete( |
Jay Civelli | 52a6330 | 2018-04-30 22:39:55 | [diff] [blame] | 5211 | RenderFrameHost* render_frame_host, |
Clark DuVall | 36164bd | 2018-08-09 22:49:08 | [diff] [blame] | 5212 | const GlobalRequestID& request_id, |
Minggang Wang | ee5af39 | 2020-02-05 02:55:28 | [diff] [blame] | 5213 | blink::mojom::ResourceLoadInfoPtr resource_load_info) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5214 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5215 | observer->ResourceLoadComplete(render_frame_host, request_id, |
| 5216 | *resource_load_info); |
| 5217 | }); |
John Abd-El-Malek | d488264 | 2017-12-04 21:45:19 | [diff] [blame] | 5218 | } |
| 5219 | |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 5220 | const WebPreferences& WebContentsImpl::GetOrCreateWebPreferences() { |
| 5221 | // Compute WebPreferences based on the current state if it's null. |
| 5222 | if (!web_preferences_) |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 5223 | OnWebPreferencesChanged(); |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 5224 | return *web_preferences_.get(); |
| 5225 | } |
| 5226 | |
| 5227 | bool WebContentsImpl::IsWebPreferencesSet() const { |
| 5228 | return web_preferences_.get(); |
| 5229 | } |
| 5230 | |
| 5231 | void WebContentsImpl::SetWebPreferences(const WebPreferences& prefs) { |
| 5232 | web_preferences_ = std::make_unique<WebPreferences>(prefs); |
| 5233 | // Get all the RenderViewHosts (except the ones for currently back-forward |
| 5234 | // cached pages), and make them send the current WebPreferences |
| 5235 | // to the renderer. WebPreferences updates for back-forward cached pages will |
| 5236 | // be sent when we restore those pages from the back-forward cache. |
| 5237 | for (auto& rvh : frame_tree_.render_view_hosts()) { |
| 5238 | rvh.second->SendWebPreferencesToRenderer(); |
| 5239 | } |
| 5240 | } |
| 5241 | |
| 5242 | void WebContentsImpl::RecomputeWebPreferencesSlow() { |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 5243 | // OnWebPreferencesChanged is a no-op when this is true. |
| 5244 | if (updating_web_preferences_) |
| 5245 | return; |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 5246 | // Resets |web_preferences_| so that we won't have any cached value for slow |
| 5247 | // attributes (which won't get recomputed if we have pre-existing values for |
| 5248 | // them). |
| 5249 | web_preferences_.reset(); |
Rakina Zata Amni | 4029b6d | 2020-07-28 02:36:20 | [diff] [blame] | 5250 | OnWebPreferencesChanged(); |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 5251 | } |
| 5252 | |
Wei Li | 5bb65974 | 2018-02-14 03:07:58 | [diff] [blame] | 5253 | void WebContentsImpl::PrintCrossProcessSubframe( |
| 5254 | const gfx::Rect& rect, |
| 5255 | int document_cookie, |
| 5256 | RenderFrameHost* subframe_host) { |
Wei Li | 5c0b4d1 | 2018-03-22 15:05:22 | [diff] [blame] | 5257 | auto* outer_contents = GetOuterWebContents(); |
| 5258 | if (outer_contents) { |
| 5259 | // When an extension or app page is printed, the content should be |
| 5260 | // composited with outer content, so the outer contents should handle the |
| 5261 | // print request. |
| 5262 | outer_contents->PrintCrossProcessSubframe(rect, document_cookie, |
| 5263 | subframe_host); |
| 5264 | return; |
| 5265 | } |
| 5266 | |
Wei Li | 5bb65974 | 2018-02-14 03:07:58 | [diff] [blame] | 5267 | // If there is no delegate such as in tests or during deletion, do nothing. |
| 5268 | if (!delegate_) |
| 5269 | return; |
| 5270 | |
| 5271 | delegate_->PrintCrossProcessSubframe(this, rect, document_cookie, |
| 5272 | subframe_host); |
| 5273 | } |
| 5274 | |
ckitagawa | 8695799b | 2020-02-05 16:08:49 | [diff] [blame] | 5275 | void WebContentsImpl::CapturePaintPreviewOfCrossProcessSubframe( |
| 5276 | const gfx::Rect& rect, |
| 5277 | const base::UnguessableToken& guid, |
| 5278 | RenderFrameHost* render_frame_host) { |
| 5279 | if (!delegate_) |
| 5280 | return; |
ckitagawa | c43ac98 | 2020-07-07 17:41:17 | [diff] [blame] | 5281 | delegate_->CapturePaintPreviewOfSubframe(this, rect, guid, render_frame_host); |
ckitagawa | 8695799b | 2020-02-05 16:08:49 | [diff] [blame] | 5282 | } |
| 5283 | |
rob.buis | 300b087 | 2017-03-10 20:43:58 | [diff] [blame] | 5284 | #if defined(OS_ANDROID) |
| 5285 | base::android::ScopedJavaLocalRef<jobject> |
| 5286 | WebContentsImpl::GetJavaRenderFrameHostDelegate() { |
| 5287 | return GetJavaWebContents(); |
| 5288 | } |
| 5289 | #endif |
| 5290 | |
Hiroki Nakagawa | 39d1bbe | 2020-07-14 16:15:52 | [diff] [blame] | 5291 | void WebContentsImpl::OnDidDisplayContentWithCertificateErrors() { |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 5292 | controller_.ssl_manager()->DidDisplayContentWithCertErrors(); |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 5293 | } |
| 5294 | |
| 5295 | void WebContentsImpl::OnDidRunContentWithCertificateErrors( |
Zhuoyu Qian | 4353f7f | 2018-01-08 05:33:00 | [diff] [blame] | 5296 | RenderFrameHostImpl* source) { |
Emily Stark | abbdd66 | 2020-06-05 02:40:13 | [diff] [blame] | 5297 | // For RenderFrameHosts that are inactive and going to be discarded, we can |
| 5298 | // disregard this message; there's no need to update the UI if the UI will |
| 5299 | // never be shown again. |
| 5300 | // |
| 5301 | // We still process this message for speculative RenderFrameHosts. This can |
| 5302 | // happen when a subframe's main resource has a certificate error. The |
| 5303 | // currently committed navigation entry will get marked as having run insecure |
| 5304 | // content and that will carry over to the navigation entry for the |
| 5305 | // speculative RFH when it commits. |
| 5306 | if (source->lifecycle_state() != |
| 5307 | RenderFrameHostImpl::LifecycleState::kSpeculative && |
| 5308 | source->IsInactiveAndDisallowReactivation()) { |
estark | aeda142 | 2016-05-10 02:31:12 | [diff] [blame] | 5309 | return; |
Emily Stark | abbdd66 | 2020-06-05 02:40:13 | [diff] [blame] | 5310 | } |
estark | cd2e30c | 2016-08-12 06:51:15 | [diff] [blame] | 5311 | controller_.ssl_manager()->DidRunContentWithCertErrors( |
Emily Stark | abbdd66 | 2020-06-05 02:40:13 | [diff] [blame] | 5312 | source->GetMainFrame()->GetLastCommittedOrigin().GetURL()); |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 5313 | } |
| 5314 | |
Kouhei Ueno | 97e0990d | 2019-09-25 02:57:27 | [diff] [blame] | 5315 | void WebContentsImpl::DOMContentLoaded(RenderFrameHost* render_frame_host) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5316 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5317 | observer->DOMContentLoaded(render_frame_host); |
| 5318 | }); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 5319 | } |
| 5320 | |
Gyuyoung Kim | 525e0c5d | 2020-03-09 15:04:19 | [diff] [blame] | 5321 | void WebContentsImpl::OnDidFinishLoad(RenderFrameHost* render_frame_host, |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5322 | const GURL& url) { |
[email protected] | 8b3af1e | 2014-01-24 13:29:12 | [diff] [blame] | 5323 | GURL validated_url(url); |
Gyuyoung Kim | 525e0c5d | 2020-03-09 15:04:19 | [diff] [blame] | 5324 | render_frame_host->GetProcess()->FilterURL(false, &validated_url); |
[email protected] | 028053d4 | 2014-03-05 22:20:37 | [diff] [blame] | 5325 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5326 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5327 | observer->DidFinishLoad(render_frame_host, validated_url); |
| 5328 | }); |
yilkal | 172da77 | 2019-11-06 22:49:07 | [diff] [blame] | 5329 | size_t tree_size = frame_tree_.root()->GetFrameTreeSize(); |
| 5330 | if (max_loaded_frame_count_ < tree_size) |
| 5331 | max_loaded_frame_count_ = tree_size; |
| 5332 | |
Gyuyoung Kim | 525e0c5d | 2020-03-09 15:04:19 | [diff] [blame] | 5333 | if (!render_frame_host->GetParent()) |
yilkal | 172da77 | 2019-11-06 22:49:07 | [diff] [blame] | 5334 | UMA_HISTOGRAM_COUNTS_1000("Navigation.MainFrame.FrameCount", tree_size); |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 5335 | } |
| 5336 | |
Dave Tapuska | 549baab | 2019-03-19 15:52:40 | [diff] [blame] | 5337 | void WebContentsImpl::OnGoToEntryAtOffset(RenderFrameHostImpl* source, |
Julie Jeongeun Kim | 144f819 | 2020-01-18 06:59:03 | [diff] [blame] | 5338 | int32_t offset, |
Dave Tapuska | 043b94a | 2019-09-10 14:14:35 | [diff] [blame] | 5339 | bool has_user_gesture) { |
Arthur Sonzogni | a7d715a | 2018-09-20 16:11:13 | [diff] [blame] | 5340 | // Non-user initiated navigations coming from the renderer should be ignored |
| 5341 | // if there is an ongoing browser-initiated navigation. |
| 5342 | // See https://crbug.com/879965. |
| 5343 | // TODO(arthursonzogni): See if this should check for ongoing navigations in |
| 5344 | // the frame(s) affected by the session history navigation, rather than just |
| 5345 | // the main frame. |
Kevin McNee | 96851e1 | 2020-07-16 03:43:22 | [diff] [blame] | 5346 | if (Navigator::ShouldIgnoreIncomingRendererRequest( |
| 5347 | frame_tree_.root()->navigation_request(), has_user_gesture)) |
| 5348 | return; |
Arthur Sonzogni | a7d715a | 2018-09-20 16:11:13 | [diff] [blame] | 5349 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5350 | // All frames are allowed to navigate the global history. |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 5351 | if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) { |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 5352 | if (source->IsSandboxed(network::mojom::WebSandboxFlags::kTopNavigation)) { |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 5353 | // Keep track of whether this is a session history from a sandboxed iframe |
| 5354 | // with top level navigation disallowed. |
| 5355 | controller_.GoToOffsetInSandboxedFrame(offset, |
| 5356 | source->GetFrameTreeNodeId()); |
| 5357 | } else { |
| 5358 | controller_.GoToOffset(offset); |
| 5359 | } |
| 5360 | } |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 5361 | } |
| 5362 | |
Dave Tapuska | 4c02911b | 2020-02-14 22:52:07 | [diff] [blame] | 5363 | void WebContentsImpl::OnPageScaleFactorChanged(RenderFrameHostImpl* source, |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5364 | float page_scale_factor) { |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 5365 | #if !defined(OS_ANDROID) |
| 5366 | // While page scale factor is used on mobile, this PageScaleFactorIsOne logic |
| 5367 | // is only needed on desktop. |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 5368 | bool is_one = page_scale_factor == 1.f; |
| 5369 | if (is_one != page_scale_factor_is_one_) { |
| 5370 | page_scale_factor_is_one_ = is_one; |
| 5371 | |
| 5372 | HostZoomMapImpl* host_zoom_map = |
| 5373 | static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this)); |
| 5374 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5375 | if (host_zoom_map) { |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 5376 | host_zoom_map->SetPageScaleFactorIsOneForView( |
Dave Tapuska | 4c02911b | 2020-02-14 22:52:07 | [diff] [blame] | 5377 | source->GetProcess()->GetID(), |
| 5378 | source->GetRenderViewHost()->GetRoutingID(), |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 5379 | page_scale_factor_is_one_); |
| 5380 | } |
| 5381 | } |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 5382 | #endif // !defined(OS_ANDROID) |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 5383 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5384 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5385 | observer->OnPageScaleFactorChanged(page_scale_factor); |
| 5386 | }); |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 5387 | } |
| 5388 | |
W. James MacLean | 6219867 | 2019-06-04 16:46:10 | [diff] [blame] | 5389 | void WebContentsImpl::OnTextAutosizerPageInfoChanged( |
Henrique Ferreiro | ba53547 | 2020-04-21 11:38:36 | [diff] [blame] | 5390 | RenderFrameHostImpl* source, |
| 5391 | blink::mojom::TextAutosizerPageInfoPtr page_info) { |
W. James MacLean | 6219867 | 2019-06-04 16:46:10 | [diff] [blame] | 5392 | // Keep a copy of |page_info| in case we create a new RenderView before |
| 5393 | // the next update. |
Henrique Ferreiro | ba53547 | 2020-04-21 11:38:36 | [diff] [blame] | 5394 | text_autosizer_page_info_.main_frame_width = page_info->main_frame_width; |
| 5395 | text_autosizer_page_info_.main_frame_layout_width = |
| 5396 | page_info->main_frame_layout_width; |
| 5397 | text_autosizer_page_info_.device_scale_adjustment = |
| 5398 | page_info->device_scale_adjustment; |
Antonio Gomes | da7e03d | 2020-08-05 15:03:08 | [diff] [blame] | 5399 | |
| 5400 | auto remote_frames_broadcast_callback = base::BindRepeating( |
| 5401 | [](const blink::mojom::TextAutosizerPageInfo& page_info, |
| 5402 | RenderFrameProxyHost* proxy_host) { |
| 5403 | DCHECK(proxy_host); |
| 5404 | proxy_host->GetAssociatedRemoteMainFrame()->UpdateTextAutosizerPageInfo( |
| 5405 | page_info.Clone()); |
| 5406 | }, |
| 5407 | text_autosizer_page_info_); |
| 5408 | |
| 5409 | frame_tree_.root()->render_manager()->ExecuteRemoteFramesBroadcastMethod( |
| 5410 | std::move(remote_frames_broadcast_callback), source->GetSiteInstance()); |
W. James MacLean | 6219867 | 2019-06-04 16:46:10 | [diff] [blame] | 5411 | } |
| 5412 | |
Kent Tamura | 8c9e056 | 2018-11-06 07:02:19 | [diff] [blame] | 5413 | void WebContentsImpl::EnumerateDirectory( |
| 5414 | RenderFrameHost* render_frame_host, |
Kent Tamura | 3abb32d | 2020-07-02 00:23:01 | [diff] [blame] | 5415 | scoped_refptr<FileChooserImpl::FileSelectListenerImpl> listener, |
Kent Tamura | 8c9e056 | 2018-11-06 07:02:19 | [diff] [blame] | 5416 | const base::FilePath& directory_path) { |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 5417 | // Any explicit focusing of another window while this WebContents is in |
| 5418 | // fullscreen can be used to confuse the user, so drop fullscreen. |
| 5419 | base::ScopedClosureRunner fullscreen_block = ForSecurityDropFullscreen(); |
| 5420 | listener->SetFullscreenBlock(std::move(fullscreen_block)); |
| 5421 | |
Kent Tamura | 8c9e056 | 2018-11-06 07:02:19 | [diff] [blame] | 5422 | if (delegate_) |
| 5423 | delegate_->EnumerateDirectory(this, std::move(listener), directory_path); |
| 5424 | else |
| 5425 | listener->FileSelectionCanceled(); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 5426 | } |
| 5427 | |
Dave Tapuska | f9fc312 | 2019-10-18 19:42:55 | [diff] [blame] | 5428 | void WebContentsImpl::RegisterProtocolHandler(RenderFrameHostImpl* source, |
| 5429 | const std::string& protocol, |
| 5430 | const GURL& url, |
| 5431 | const base::string16& title, |
| 5432 | bool user_gesture) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5433 | // TODO(nick): Do we need to apply FilterURL to |url|? |
[email protected] | e5f2de0 | 2012-07-20 22:15:43 | [diff] [blame] | 5434 | if (!delegate_) |
| 5435 | return; |
| 5436 | |
Raymes Khoury | 58373df | 2019-08-06 06:29:20 | [diff] [blame] | 5437 | if (!AreValidRegisterProtocolHandlerArguments( |
| 5438 | protocol, url, source->GetLastCommittedOrigin())) { |
| 5439 | ReceivedBadMessage(source->GetProcess(), |
| 5440 | bad_message::REGISTER_PROTOCOL_HANDLER_INVALID_URL); |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 5441 | return; |
Raymes Khoury | 58373df | 2019-08-06 06:29:20 | [diff] [blame] | 5442 | } |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 5443 | |
Carlos Caballero | 8a6c6b7 | 2020-07-20 16:56:22 | [diff] [blame] | 5444 | delegate_->RegisterProtocolHandler(source, protocol, url, user_gesture); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 5445 | } |
| 5446 | |
Dave Tapuska | f9fc312 | 2019-10-18 19:42:55 | [diff] [blame] | 5447 | void WebContentsImpl::UnregisterProtocolHandler(RenderFrameHostImpl* source, |
| 5448 | const std::string& protocol, |
| 5449 | const GURL& url, |
| 5450 | bool user_gesture) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5451 | // TODO(nick): Do we need to apply FilterURL to |url|? |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 5452 | if (!delegate_) |
| 5453 | return; |
| 5454 | |
Raymes Khoury | 58373df | 2019-08-06 06:29:20 | [diff] [blame] | 5455 | if (!AreValidRegisterProtocolHandlerArguments( |
| 5456 | protocol, url, source->GetLastCommittedOrigin())) { |
| 5457 | ReceivedBadMessage(source->GetProcess(), |
| 5458 | bad_message::REGISTER_PROTOCOL_HANDLER_INVALID_URL); |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 5459 | return; |
Raymes Khoury | 58373df | 2019-08-06 06:29:20 | [diff] [blame] | 5460 | } |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 5461 | |
Carlos Caballero | 8a6c6b7 | 2020-07-20 16:56:22 | [diff] [blame] | 5462 | delegate_->UnregisterProtocolHandler(source, protocol, url, user_gesture); |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 5463 | } |
| 5464 | |
Marijn Kruisselbrink | 7f51967 | 2019-02-05 19:12:50 | [diff] [blame] | 5465 | void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5466 | bool blocked_by_policy) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5467 | // TODO(nick): Should we consider |source| here? Should we call FilterURL on |
| 5468 | // |manifest_url|? |
| 5469 | |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 5470 | // Notify observers about navigation. |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5471 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5472 | observer->AppCacheAccessed(manifest_url, blocked_by_policy); |
| 5473 | }); |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 5474 | } |
| 5475 | |
Gyuyoung Kim | c5f4ac1 | 2020-05-08 10:59:39 | [diff] [blame] | 5476 | void WebContentsImpl::DomOperationResponse(const std::string& json_string) { |
| 5477 | // TODO(lukasza): The notification below should probably indicate which |
| 5478 | // RenderFrameHostImpl the message is coming from. This can enable tests to |
| 5479 | // talk to 2 frames at the same time, without being confused which frame a |
| 5480 | // given response comes from. See also a corresponding TODO in the |
| 5481 | // ExecuteScriptHelper in //content/public/test/browser_test_utils.cc |
| 5482 | NotificationService::current()->Notify( |
| 5483 | NOTIFICATION_DOM_OPERATION_RESPONSE, Source<WebContents>(this), |
| 5484 | Details<const std::string>(&json_string)); |
| 5485 | } |
| 5486 | |
Gyuyoung Kim | 4c5051784 | 2020-06-04 17:50:44 | [diff] [blame] | 5487 | void WebContentsImpl::SavableResourceLinksResponse( |
| 5488 | RenderFrameHostImpl* source, |
| 5489 | const std::vector<GURL>& resources_list, |
| 5490 | blink::mojom::ReferrerPtr referrer, |
| 5491 | const std::vector<blink::mojom::SavableSubframePtr>& subframes) { |
| 5492 | save_package_->SavableResourceLinksResponse(source, resources_list, |
| 5493 | std::move(referrer), subframes); |
| 5494 | } |
| 5495 | |
| 5496 | void WebContentsImpl::SavableResourceLinksError(RenderFrameHostImpl* source) { |
| 5497 | save_package_->SavableResourceLinksError(source); |
| 5498 | } |
| 5499 | |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 5500 | void WebContentsImpl::OnServiceWorkerAccessed( |
| 5501 | RenderFrameHost* render_frame_host, |
| 5502 | const GURL& scope, |
| 5503 | AllowServiceWorkerResult allowed) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5504 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5505 | observer->OnServiceWorkerAccessed(render_frame_host, scope, allowed); |
| 5506 | }); |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 5507 | } |
| 5508 | |
| 5509 | void WebContentsImpl::OnServiceWorkerAccessed( |
| 5510 | NavigationHandle* navigation, |
| 5511 | const GURL& scope, |
| 5512 | AllowServiceWorkerResult allowed) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5513 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5514 | observer->OnServiceWorkerAccessed(navigation, scope, allowed); |
| 5515 | }); |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 5516 | } |
| 5517 | |
Miyoung Shin | cb6475a | 2019-11-09 10:49:45 | [diff] [blame] | 5518 | void WebContentsImpl::OnColorChooserFactoryReceiver( |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 5519 | mojo::PendingReceiver<blink::mojom::ColorChooserFactory> receiver) { |
| 5520 | color_chooser_factory_receivers_.Add(this, std::move(receiver)); |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 5521 | } |
| 5522 | |
| 5523 | void WebContentsImpl::OpenColorChooser( |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 5524 | mojo::PendingReceiver<blink::mojom::ColorChooser> chooser_receiver, |
| 5525 | mojo::PendingRemote<blink::mojom::ColorChooserClient> client, |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 5526 | SkColor color, |
Joel Hockey | 163835a | 2017-12-20 11:51:57 | [diff] [blame] | 5527 | std::vector<blink::mojom::ColorSuggestionPtr> suggestions) { |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 5528 | content::ColorChooser* new_color_chooser = |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 5529 | delegate_ ? delegate_->OpenColorChooser(this, color, suggestions) |
| 5530 | : nullptr; |
[email protected] | 820957a | 2014-01-14 14:56:30 | [diff] [blame] | 5531 | if (!new_color_chooser) |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 5532 | return; |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 5533 | |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 5534 | color_chooser_.reset(); |
| 5535 | color_chooser_ = std::make_unique<ColorChooser>( |
Julie Jeongeun Kim | 8e2879e | 2019-08-06 23:55:20 | [diff] [blame] | 5536 | new_color_chooser, std::move(chooser_receiver), std::move(client)); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 5537 | } |
| 5538 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 5539 | #if BUILDFLAG(ENABLE_PLUGINS) |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5540 | void WebContentsImpl::OnPepperInstanceCreated(RenderFrameHostImpl* source, |
| 5541 | int32_t pp_instance) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5542 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5543 | observer->PepperInstanceCreated(); |
| 5544 | }); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5545 | pepper_playback_observer_->PepperInstanceCreated(source, pp_instance); |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 5546 | } |
| 5547 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5548 | void WebContentsImpl::OnPepperInstanceDeleted(RenderFrameHostImpl* source, |
| 5549 | int32_t pp_instance) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5550 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5551 | observer->PepperInstanceDeleted(); |
| 5552 | }); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5553 | pepper_playback_observer_->PepperInstanceDeleted(source, pp_instance); |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 5554 | } |
| 5555 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5556 | void WebContentsImpl::OnPepperPluginHung(RenderFrameHostImpl* source, |
| 5557 | int plugin_child_id, |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 5558 | const base::FilePath& path, |
| 5559 | bool is_hung) { |
Steven Holte | 9592222 | 2018-09-14 20:06:23 | [diff] [blame] | 5560 | UMA_HISTOGRAM_COUNTS_1M("Pepper.PluginHung", 1); |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 5561 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5562 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5563 | observer->PluginHungStatusChanged(plugin_child_id, path, is_hung); |
| 5564 | }); |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 5565 | } |
| 5566 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5567 | void WebContentsImpl::OnPepperStartsPlayback(RenderFrameHostImpl* source, |
| 5568 | int32_t pp_instance) { |
| 5569 | pepper_playback_observer_->PepperStartsPlayback(source, pp_instance); |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 5570 | } |
| 5571 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5572 | void WebContentsImpl::OnPepperStopsPlayback(RenderFrameHostImpl* source, |
| 5573 | int32_t pp_instance) { |
| 5574 | pepper_playback_observer_->PepperStopsPlayback(source, pp_instance); |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 5575 | } |
| 5576 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5577 | void WebContentsImpl::OnPluginCrashed(RenderFrameHostImpl* source, |
| 5578 | const base::FilePath& plugin_path, |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 5579 | base::ProcessId plugin_pid) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5580 | // TODO(nick): Eliminate the |plugin_pid| parameter, which can't be trusted, |
Gyuyoung Kim | 26c7bc9 | 2020-04-29 00:53:00 | [diff] [blame] | 5581 | // and is only used by WebTestControlHost. |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5582 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5583 | observer->PluginCrashed(plugin_path, plugin_pid); |
| 5584 | }); |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 5585 | } |
| 5586 | |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 5587 | void WebContentsImpl::OnRequestPpapiBrokerPermission( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5588 | RenderViewHostImpl* source, |
| 5589 | int ppb_broker_route_id, |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 5590 | const GURL& url, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 5591 | const base::FilePath& plugin_path) { |
Avi Drissman | 0a2a967d | 2019-04-01 19:33:52 | [diff] [blame] | 5592 | base::OnceCallback<void(bool)> permission_result_callback = base::BindOnce( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5593 | &WebContentsImpl::SendPpapiBrokerPermissionResult, base::Unretained(this), |
| 5594 | source->GetProcess()->GetID(), ppb_broker_route_id); |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 5595 | if (!delegate_) { |
Tommy Nyquist | 4b749d0 | 2018-03-20 21:46:29 | [diff] [blame] | 5596 | std::move(permission_result_callback).Run(false); |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 5597 | return; |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 5598 | } |
| 5599 | |
Avi Drissman | 0a2a967d | 2019-04-01 19:33:52 | [diff] [blame] | 5600 | delegate_->RequestPpapiBrokerPermission( |
| 5601 | this, url, plugin_path, std::move(permission_result_callback)); |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 5602 | } |
| 5603 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5604 | void WebContentsImpl::SendPpapiBrokerPermissionResult(int process_id, |
| 5605 | int ppb_broker_route_id, |
| 5606 | bool result) { |
| 5607 | RenderProcessHost* rph = RenderProcessHost::FromID(process_id); |
| 5608 | if (rph) { |
| 5609 | // TODO(nick): Convert this from ViewMsg_ to a Ppapi msg, since it |
| 5610 | // is not routed to a RenderView. |
| 5611 | rph->Send( |
| 5612 | new ViewMsg_PpapiBrokerPermissionResult(ppb_broker_route_id, result)); |
| 5613 | } |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 5614 | } |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 5615 | #endif // BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | 19be7a6 | 2012-10-01 23:03:37 | [diff] [blame] | 5616 | |
Miyoung Shin | 5709ab0 | 2020-02-19 06:50:41 | [diff] [blame] | 5617 | void WebContentsImpl::UpdateFaviconURL( |
| 5618 | RenderFrameHost* source, |
| 5619 | std::vector<blink::mojom::FaviconURLPtr> candidates) { |
lukasza | 178ff09 | 2017-06-07 23:39:50 | [diff] [blame] | 5620 | // Ignore favicons for non-main frame. |
| 5621 | if (source->GetParent()) { |
| 5622 | NOTREACHED(); |
| 5623 | return; |
| 5624 | } |
| 5625 | |
pkotwicz | f9bc2059 | 2015-04-21 18:57:06 | [diff] [blame] | 5626 | // We get updated favicon URLs after the page stops loading. If a cross-site |
| 5627 | // navigation occurs while a page is still loading, the initial page |
| 5628 | // may stop loading and send us updated favicon URLs after the navigation |
| 5629 | // for the new page has committed. |
lukasza | 178ff09 | 2017-06-07 23:39:50 | [diff] [blame] | 5630 | if (!source->IsCurrent()) |
pkotwicz | f9bc2059 | 2015-04-21 18:57:06 | [diff] [blame] | 5631 | return; |
| 5632 | |
Miyoung Shin | 5709ab0 | 2020-02-19 06:50:41 | [diff] [blame] | 5633 | favicon_urls_ = std::move(candidates); |
Mounir Lamouri | 7b4a1f23 | 2019-12-23 16:32:10 | [diff] [blame] | 5634 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5635 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5636 | observer->DidUpdateFaviconURL(source, favicon_urls_); |
| 5637 | }); |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 5638 | } |
| 5639 | |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 5640 | void WebContentsImpl::SetIsOverlayContent(bool is_overlay_content) { |
| 5641 | is_overlay_content_ = is_overlay_content; |
| 5642 | } |
| 5643 | |
Albert J. Wong | fb64e14 | 2018-10-16 01:10:45 | [diff] [blame] | 5644 | void WebContentsImpl::DidFirstVisuallyNonEmptyPaint( |
| 5645 | RenderViewHostImpl* source) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 5646 | // TODO(nick): When this is ported to FrameHostMsg_, we should only listen if |
| 5647 | // |source| is the main frame. |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5648 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5649 | observer->DidFirstVisuallyNonEmptyPaint(); |
| 5650 | }); |
Carlos Caballero | 1215f88 | 2019-10-29 15:58:43 | [diff] [blame] | 5651 | if (source->theme_color() != last_sent_theme_color_) { |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 5652 | // Theme color should have updated by now if there was one. |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5653 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5654 | observer->DidChangeThemeColor(); |
| 5655 | }); |
Carlos Caballero | 1215f88 | 2019-10-29 15:58:43 | [diff] [blame] | 5656 | last_sent_theme_color_ = source->theme_color(); |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 5657 | } |
[email protected] | 9f26807 | 2013-11-07 00:02:15 | [diff] [blame] | 5658 | } |
[email protected] | d9030b8 | 2013-07-19 08:26:06 | [diff] [blame] | 5659 | |
Kevin McNee | 068c3eb | 2020-04-03 18:24:19 | [diff] [blame] | 5660 | bool WebContentsImpl::IsPortal() { |
Adithya Srinivasan | 46b8a79 | 2019-02-01 14:47:23 | [diff] [blame] | 5661 | return portal(); |
| 5662 | } |
| 5663 | |
Kevin McNee | 94ea52f5 | 2020-06-23 17:42:06 | [diff] [blame] | 5664 | WebContentsImpl* WebContentsImpl::GetPortalHostWebContents() { |
| 5665 | return portal() ? portal()->GetPortalHostContents() : nullptr; |
| 5666 | } |
| 5667 | |
[email protected] | 17e286e | 2013-03-01 23:29:39 | [diff] [blame] | 5668 | void WebContentsImpl::NotifyBeforeFormRepostWarningShow() { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5669 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5670 | observer->BeforeFormRepostWarningShow(); |
| 5671 | }); |
[email protected] | 17e286e | 2013-03-01 23:29:39 | [diff] [blame] | 5672 | } |
| 5673 | |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 5674 | void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() { |
| 5675 | Activate(); |
| 5676 | if (delegate_) |
| 5677 | delegate_->ShowRepostFormWarningDialog(this); |
| 5678 | } |
| 5679 | |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 5680 | bool WebContentsImpl::HasAccessedInitialDocument() { |
| 5681 | return has_accessed_initial_document_; |
| 5682 | } |
| 5683 | |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 5684 | void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 5685 | const base::string16& title) { |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 5686 | base::string16 final_title; |
Avi Drissman | 9300221 | 2017-09-27 03:20:52 | [diff] [blame] | 5687 | base::TrimWhitespace(title, base::TRIM_ALL, &final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5688 | |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 5689 | // If a page is created via window.open and never navigated, |
| 5690 | // there will be no navigation entry. In this situation, |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 5691 | // |page_title_when_no_navigation_entry_| will be used for page title. |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 5692 | if (entry) { |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 5693 | if (final_title == entry->GetTitle()) |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 5694 | return; // Nothing changed, don't bother. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5695 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 5696 | entry->SetTitle(final_title); |
Avi Drissman | 9300221 | 2017-09-27 03:20:52 | [diff] [blame] | 5697 | |
| 5698 | // The title for display may differ from the title just set; grab it. |
| 5699 | final_title = entry->GetTitleForDisplay(); |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 5700 | } else { |
| 5701 | if (page_title_when_no_navigation_entry_ == final_title) |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 5702 | return; // Nothing changed, don't bother. |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 5703 | |
| 5704 | page_title_when_no_navigation_entry_ = final_title; |
| 5705 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5706 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5707 | // Lastly, set the title for the view. |
[email protected] | 790e2fd | 2011-09-21 20:28:23 | [diff] [blame] | 5708 | view_->SetPageTitle(final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5709 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5710 | observers_.ForEachObserver( |
| 5711 | [&](WebContentsObserver* observer) { observer->TitleWasSet(entry); }); |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 5712 | // Broadcast notifications when the UI should be updated. |
| 5713 | if (entry == controller_.GetEntryAtOffset(0)) |
| 5714 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5715 | } |
| 5716 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 5717 | void WebContentsImpl::SendChangeLoadProgress() { |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 5718 | loading_last_progress_update_ = base::TimeTicks::Now(); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5719 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5720 | observer->LoadProgressChanged(frame_tree_.load_progress()); |
| 5721 | }); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 5722 | } |
| 5723 | |
| 5724 | void WebContentsImpl::ResetLoadProgressState() { |
fdegans | 1d1635516 | 2015-03-26 11:58:34 | [diff] [blame] | 5725 | frame_tree_.ResetLoadProgress(); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 5726 | loading_weak_factory_.InvalidateWeakPtrs(); |
| 5727 | loading_last_progress_update_ = base::TimeTicks(); |
| 5728 | } |
| 5729 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 5730 | // Notifies the RenderWidgetHost instance about the fact that the page is |
| 5731 | // loading, or done loading. |
| 5732 | void WebContentsImpl::LoadingStateChanged(bool to_different_document, |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 5733 | LoadNotificationDetails* details) { |
Nate Chapin | 22ea659 | 2019-03-05 22:29:02 | [diff] [blame] | 5734 | if (is_being_destroyed_) |
| 5735 | return; |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 5736 | |
| 5737 | bool is_loading = IsLoading(); |
| 5738 | |
| 5739 | if (!is_loading) { |
| 5740 | load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, |
| 5741 | base::string16()); |
| 5742 | load_state_host_.clear(); |
| 5743 | upload_size_ = 0; |
| 5744 | upload_position_ = 0; |
| 5745 | } |
| 5746 | |
| 5747 | GetRenderManager()->SetIsLoading(is_loading); |
| 5748 | |
| 5749 | waiting_for_response_ = is_loading; |
| 5750 | is_load_to_different_document_ = to_different_document; |
| 5751 | |
| 5752 | if (delegate_) |
| 5753 | delegate_->LoadingStateChanged(this, to_different_document); |
| 5754 | NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD); |
| 5755 | |
| 5756 | std::string url = (details ? details->url.possibly_invalid_spec() : "NULL"); |
| 5757 | if (is_loading) { |
| 5758 | TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading", |
| 5759 | this, "URL", url, "Main FrameTreeNode id", |
| 5760 | GetFrameTree()->root()->frame_tree_node_id()); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5761 | observers_.ForEachObserver( |
| 5762 | [&](WebContentsObserver* observer) { observer->DidStartLoading(); }); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 5763 | } else { |
| 5764 | TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading", |
| 5765 | this, "URL", url); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5766 | observers_.ForEachObserver( |
| 5767 | [&](WebContentsObserver* observer) { observer->DidStopLoading(); }); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 5768 | } |
| 5769 | |
| 5770 | // TODO(avi): Remove. http://crbug.com/170921 |
| 5771 | int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP; |
| 5772 | NotificationDetails det = NotificationService::NoDetails(); |
| 5773 | if (details) |
| 5774 | det = Details<LoadNotificationDetails>(details); |
| 5775 | NotificationService::current()->Notify( |
| 5776 | type, Source<NavigationController>(&controller_), det); |
| 5777 | } |
| 5778 | |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 5779 | void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_view, |
| 5780 | RenderViewHost* new_view) { |
| 5781 | DCHECK_NE(old_view, new_view); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5782 | // After sending out a swap notification, we need to send a disconnect |
| 5783 | // notification so that clients that pick up a pointer to |this| can NULL the |
| 5784 | // pointer. See Bug 1230284. |
| 5785 | notify_disconnection_ = true; |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5786 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5787 | observer->RenderViewHostChanged(old_view, new_view); |
| 5788 | }); |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 5789 | view_->RenderViewHostChanged(old_view, new_view); |
Jinsuk Kim | dc5284c2 | 2018-07-11 02:22:06 | [diff] [blame] | 5790 | |
Lucas Furukawa Gadani | f9ea4fc | 2018-08-03 23:57:13 | [diff] [blame] | 5791 | // If this is an inner WebContents that has swapped views, we need to reattach |
| 5792 | // it to its outer WebContents. |
| 5793 | if (node_.outer_web_contents()) |
| 5794 | ReattachToOuterWebContentsFrame(); |
| 5795 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 5796 | // Ensure that the associated embedder gets cleared after a RenderViewHost |
| 5797 | // gets swapped, so we don't reuse the same embedder next time a |
| 5798 | // RenderViewHost is attached to this WebContents. |
| 5799 | RemoveBrowserPluginEmbedder(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5800 | } |
| 5801 | |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 5802 | void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_frame, |
| 5803 | RenderFrameHost* new_frame, |
Jinsuk Kim | 895b2c5 | 2018-07-03 06:49:16 | [diff] [blame] | 5804 | bool is_main_frame) { |
Bo Liu | 168c864 | 2017-08-28 18:26:02 | [diff] [blame] | 5805 | #if defined(OS_ANDROID) |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 5806 | // Copy importance from |old_frame| if |new_frame| is a main frame. |
| 5807 | if (old_frame && !new_frame->GetParent()) { |
| 5808 | RenderWidgetHostImpl* old_widget = |
| 5809 | static_cast<RenderFrameHostImpl*>(old_frame)->GetRenderWidgetHost(); |
| 5810 | RenderWidgetHostImpl* new_widget = |
| 5811 | static_cast<RenderFrameHostImpl*>(new_frame)->GetRenderWidgetHost(); |
| 5812 | new_widget->SetImportance(old_widget->importance()); |
Bo Liu | 7c6779e9 | 2017-08-16 02:02:28 | [diff] [blame] | 5813 | } |
Bo Liu | 168c864 | 2017-08-28 18:26:02 | [diff] [blame] | 5814 | #endif |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5815 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5816 | observer->RenderFrameHostChanged(old_frame, new_frame); |
| 5817 | }); |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 5818 | } |
| 5819 | |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 5820 | // TODO(avi): Remove this entire function because this notification is already |
| 5821 | // covered by two observer functions. http://crbug.com/170921 |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5822 | void WebContentsImpl::NotifyDisconnected() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5823 | if (!notify_disconnection_) |
| 5824 | return; |
| 5825 | |
| 5826 | notify_disconnection_ = false; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 5827 | NotificationService::current()->Notify( |
| 5828 | NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 5829 | Source<WebContents>(this), |
| 5830 | NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5831 | } |
| 5832 | |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 5833 | void WebContentsImpl::NotifyNavigationEntryCommitted( |
| 5834 | const LoadCommittedDetails& load_details) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5835 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5836 | observer->NavigationEntryCommitted(load_details); |
| 5837 | }); |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 5838 | } |
| 5839 | |
Sam McNally | 5c087a3 | 2017-08-25 01:46:14 | [diff] [blame] | 5840 | void WebContentsImpl::NotifyNavigationEntryChanged( |
| 5841 | const EntryChangedDetails& change_details) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5842 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5843 | observer->NavigationEntryChanged(change_details); |
| 5844 | }); |
Sam McNally | 5c087a3 | 2017-08-25 01:46:14 | [diff] [blame] | 5845 | } |
| 5846 | |
| 5847 | void WebContentsImpl::NotifyNavigationListPruned( |
| 5848 | const PrunedDetails& pruned_details) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5849 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5850 | observer->NavigationListPruned(pruned_details); |
| 5851 | }); |
Sam McNally | 5c087a3 | 2017-08-25 01:46:14 | [diff] [blame] | 5852 | } |
| 5853 | |
Christian Dullweber | 1af31e6 | 2018-02-22 11:49:48 | [diff] [blame] | 5854 | void WebContentsImpl::NotifyNavigationEntriesDeleted() { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5855 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5856 | observer->NavigationEntriesDeleted(); |
| 5857 | }); |
Christian Dullweber | 1af31e6 | 2018-02-22 11:49:48 | [diff] [blame] | 5858 | } |
| 5859 | |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 5860 | void WebContentsImpl::OnAssociatedInterfaceRequest( |
| 5861 | RenderFrameHost* render_frame_host, |
| 5862 | const std::string& interface_name, |
| 5863 | mojo::ScopedInterfaceEndpointHandle handle) { |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 5864 | auto it = receiver_sets_.find(interface_name); |
| 5865 | if (it != receiver_sets_.end()) |
| 5866 | it->second->OnReceiverForFrame(render_frame_host, std::move(handle)); |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 5867 | } |
| 5868 | |
Ben Goodger | 9e24929e | 2017-07-21 03:13:40 | [diff] [blame] | 5869 | void WebContentsImpl::OnInterfaceRequest( |
| 5870 | RenderFrameHost* render_frame_host, |
| 5871 | const std::string& interface_name, |
| 5872 | mojo::ScopedMessagePipeHandle* interface_pipe) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5873 | for (auto& observer : observers_.observer_list()) { |
Ben Goodger | 9e24929e | 2017-07-21 03:13:40 | [diff] [blame] | 5874 | observer.OnInterfaceRequestFromFrame(render_frame_host, interface_name, |
| 5875 | interface_pipe); |
| 5876 | if (!interface_pipe->is_valid()) |
| 5877 | break; |
| 5878 | } |
| 5879 | } |
| 5880 | |
Varun Khaneja | 5da9430 | 2019-06-25 04:48:10 | [diff] [blame] | 5881 | void WebContentsImpl::OnDidBlockNavigation( |
| 5882 | const GURL& blocked_url, |
| 5883 | const GURL& initiator_url, |
Abhijeet Kandalkar | de7348e | 2020-01-13 06:06:54 | [diff] [blame] | 5884 | blink::mojom::NavigationBlockedReason reason) { |
Nicolas Dossou-gbete | bcab247 | 2017-09-09 12:28:40 | [diff] [blame] | 5885 | if (delegate_) |
Varun Khaneja | 5da9430 | 2019-06-25 04:48:10 | [diff] [blame] | 5886 | delegate_->OnDidBlockNavigation(this, blocked_url, initiator_url, reason); |
Nicolas Dossou-gbete | bcab247 | 2017-09-09 12:28:40 | [diff] [blame] | 5887 | } |
| 5888 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 5889 | const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() { |
[email protected] | c31a8480 | 2014-04-03 15:55:49 | [diff] [blame] | 5890 | return GetLastCommittedURL(); |
| 5891 | } |
| 5892 | |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 5893 | void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5894 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5895 | observer->RenderFrameCreated(render_frame_host); |
| 5896 | }); |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 5897 | UpdateAccessibilityModeOnFrame(render_frame_host); |
clamy | 91b7abf | 2016-03-24 15:17:45 | [diff] [blame] | 5898 | |
Becca Hughes | d11d650 | 2018-07-31 17:01:28 | [diff] [blame] | 5899 | if (display_cutout_host_impl_) |
| 5900 | display_cutout_host_impl_->RenderFrameCreated(render_frame_host); |
| 5901 | |
clamy | 91b7abf | 2016-03-24 15:17:45 | [diff] [blame] | 5902 | if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent()) |
| 5903 | return; |
| 5904 | |
| 5905 | NavigationEntry* entry = controller_.GetPendingEntry(); |
| 5906 | if (entry && entry->IsViewSourceMode()) { |
| 5907 | // Put the renderer in view source mode. |
Dave Tapuska | 3c05e1c | 2019-11-27 18:34:18 | [diff] [blame] | 5908 | static_cast<RenderFrameHostImpl*>(render_frame_host) |
| 5909 | ->GetAssociatedLocalFrame() |
| 5910 | ->EnableViewSourceMode(); |
clamy | 91b7abf | 2016-03-24 15:17:45 | [diff] [blame] | 5911 | } |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 5912 | } |
| 5913 | |
| 5914 | void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) { |
yilkal | 172da77 | 2019-11-06 22:49:07 | [diff] [blame] | 5915 | if (IsBeingDestroyed() && !render_frame_host->GetParent() && |
| 5916 | first_navigation_completed_ && |
Hajime Hoshi | bbc509c | 2020-04-06 08:55:08 | [diff] [blame] | 5917 | !render_frame_host->IsInBackForwardCache()) { |
yilkal | 796e89e | 2019-10-02 23:58:28 | [diff] [blame] | 5918 | // Main frame has been deleted because WebContents is being destroyed. |
Rakina Zata Amni | 74627df | 2019-10-15 02:03:17 | [diff] [blame] | 5919 | // Note that we aren't recording this here when the main frame is in the |
| 5920 | // back-forward cache because that means we've actually already navigated |
| 5921 | // away from it (and we got to this point because the WebContents is |
yilkal | 172da77 | 2019-11-06 22:49:07 | [diff] [blame] | 5922 | // deleted), which means |max_loaded_frame_count_| is already overwritten. |
| 5923 | // The |max_loaded_frame_count_| value will instead be recorded from within |
| 5924 | // |WebContentsImpl::DidFinishNavigation()|. |
| 5925 | RecordMaxFrameCountUMA(max_loaded_frame_count_); |
yilkal | 796e89e | 2019-10-02 23:58:28 | [diff] [blame] | 5926 | } |
| 5927 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 5928 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 5929 | observer->RenderFrameDeleted(render_frame_host); |
| 5930 | }); |
zqzhang | 7b6f4f0 | 2016-12-07 22:10:22 | [diff] [blame] | 5931 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 5932 | pepper_playback_observer_->RenderFrameDeleted(render_frame_host); |
| 5933 | #endif |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 5934 | |
Becca Hughes | d11d650 | 2018-07-31 17:01:28 | [diff] [blame] | 5935 | if (display_cutout_host_impl_) |
| 5936 | display_cutout_host_impl_->RenderFrameDeleted(render_frame_host); |
| 5937 | |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 5938 | // Remove any fullscreen state that the frame has stored. |
| 5939 | FullscreenStateChanged(render_frame_host, false /* is_fullscreen */); |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 5940 | } |
| 5941 | |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 5942 | void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host, |
| 5943 | const ContextMenuParams& params) { |
avi | e9fd872 | 2017-04-10 16:17:58 | [diff] [blame] | 5944 | // If a renderer fires off a second command to show a context menu before the |
| 5945 | // first context menu is closed, just ignore it. https://crbug.com/707534 |
ekaramad | f6750aa | 2017-06-06 18:29:42 | [diff] [blame] | 5946 | if (showing_context_menu_) |
avi | e9fd872 | 2017-04-10 16:17:58 | [diff] [blame] | 5947 | return; |
| 5948 | |
[email protected] | 077e704b | 2014-05-23 19:24:10 | [diff] [blame] | 5949 | ContextMenuParams context_menu_params(params); |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 5950 | // Allow WebContentsDelegates to handle the context menu operation first. |
Joel Klinghed | 0ea22ea | 2019-02-20 22:04:22 | [diff] [blame] | 5951 | if (delegate_ && |
| 5952 | delegate_->HandleContextMenu(render_frame_host, context_menu_params)) |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 5953 | return; |
| 5954 | |
[email protected] | 077e704b | 2014-05-23 19:24:10 | [diff] [blame] | 5955 | render_view_host_delegate_view_->ShowContextMenu(render_frame_host, |
| 5956 | context_menu_params); |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 5957 | } |
| 5958 | |
Avi Drissman | 4891b85 | 2018-09-25 18:12:58 | [diff] [blame] | 5959 | namespace { |
| 5960 | // Normalizes the line endings: \r\n -> \n, lone \r -> \n. |
| 5961 | base::string16 NormalizeLineBreaks(const base::string16& source) { |
| 5962 | static const base::NoDestructor<base::string16> kReturnNewline( |
| 5963 | base::ASCIIToUTF16("\r\n")); |
| 5964 | static const base::NoDestructor<base::string16> kReturn( |
| 5965 | base::ASCIIToUTF16("\r")); |
| 5966 | static const base::NoDestructor<base::string16> kNewline( |
| 5967 | base::ASCIIToUTF16("\n")); |
| 5968 | |
| 5969 | std::vector<base::StringPiece16> pieces; |
| 5970 | |
| 5971 | for (const auto& rn_line : base::SplitStringPieceUsingSubstr( |
| 5972 | source, *kReturnNewline, base::KEEP_WHITESPACE, |
| 5973 | base::SPLIT_WANT_ALL)) { |
| 5974 | auto r_lines = base::SplitStringPieceUsingSubstr( |
| 5975 | rn_line, *kReturn, base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 5976 | std::move(std::begin(r_lines), std::end(r_lines), |
| 5977 | std::back_inserter(pieces)); |
| 5978 | } |
| 5979 | |
| 5980 | return base::JoinString(pieces, *kNewline); |
| 5981 | } |
| 5982 | } // namespace |
| 5983 | |
Dave Tapuska | cdf545cc | 2020-01-23 18:38:52 | [diff] [blame] | 5984 | void WebContentsImpl::RunJavaScriptDialog( |
| 5985 | RenderFrameHost* render_frame_host, |
| 5986 | const base::string16& message, |
| 5987 | const base::string16& default_prompt, |
| 5988 | JavaScriptDialogType dialog_type, |
| 5989 | JavaScriptDialogCallback response_callback) { |
Avi Drissman | 2ccbb40 | 2018-03-20 21:11:36 | [diff] [blame] | 5990 | // Ensure that if showing a dialog is the first thing that a page does, that |
| 5991 | // the contents of the previous page aren't shown behind it. This is required |
| 5992 | // because showing a dialog freezes the renderer, so no frames will be coming |
| 5993 | // from it. https://crbug.com/823353 |
| 5994 | auto* render_widget_host_impl = |
| 5995 | static_cast<RenderFrameHostImpl*>(render_frame_host) |
| 5996 | ->GetRenderWidgetHost(); |
| 5997 | if (render_widget_host_impl) |
| 5998 | render_widget_host_impl->ForceFirstFrameAfterNavigationTimeout(); |
| 5999 | |
avi | 0720b02e | 2017-06-13 03:22:13 | [diff] [blame] | 6000 | // Running a dialog causes an exit to webpage-initiated fullscreen. |
| 6001 | // http://crbug.com/728276 |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 6002 | base::ScopedClosureRunner fullscreen_block = ForSecurityDropFullscreen(); |
avi | 0720b02e | 2017-06-13 03:22:13 | [diff] [blame] | 6003 | |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 6004 | auto callback = |
| 6005 | base::BindOnce(&WebContentsImpl::OnDialogClosed, base::Unretained(this), |
| 6006 | render_frame_host->GetProcess()->GetID(), |
| 6007 | render_frame_host->GetRoutingID(), |
| 6008 | std::move(response_callback), std::move(fullscreen_block)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6009 | |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6010 | std::vector<protocol::PageHandler*> page_handlers = |
| 6011 | protocol::PageHandler::EnabledForWebContents(this); |
| 6012 | |
Pavel Feldman | fab3cb6 | 2017-10-05 01:02:01 | [diff] [blame] | 6013 | if (delegate_) |
| 6014 | dialog_manager_ = delegate_->GetJavaScriptDialogManager(this); |
| 6015 | |
Charlie Reis | 9607736 | 2019-07-04 00:34:04 | [diff] [blame] | 6016 | // While a JS message dialog is showing, defer commits in this WebContents. |
| 6017 | javascript_dialog_navigation_deferrer_ = |
| 6018 | std::make_unique<JavaScriptDialogNavigationDeferrer>(); |
| 6019 | |
Carlos IL | 07f282f | 2020-05-15 22:58:29 | [diff] [blame] | 6020 | // Suppress JavaScript dialogs when requested. |
| 6021 | bool should_suppress = delegate_ && delegate_->ShouldSuppressDialogs(this); |
Pavel Feldman | 1c587bc5 | 2018-04-04 21:16:05 | [diff] [blame] | 6022 | bool has_non_devtools_handlers = delegate_ && dialog_manager_; |
| 6023 | bool has_handlers = page_handlers.size() || has_non_devtools_handlers; |
Pavel Feldman | fab3cb6 | 2017-10-05 01:02:01 | [diff] [blame] | 6024 | bool suppress_this_message = should_suppress || !has_handlers; |
| 6025 | |
| 6026 | if (suppress_this_message) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6027 | std::move(callback).Run(true, false, base::string16()); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6028 | return; |
| 6029 | } |
| 6030 | |
| 6031 | scoped_refptr<CloseDialogCallbackWrapper> wrapper = |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6032 | new CloseDialogCallbackWrapper(std::move(callback)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6033 | |
| 6034 | is_showing_javascript_dialog_ = true; |
| 6035 | |
Avi Drissman | 4891b85 | 2018-09-25 18:12:58 | [diff] [blame] | 6036 | base::string16 normalized_message = NormalizeLineBreaks(message); |
| 6037 | |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6038 | for (auto* handler : page_handlers) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6039 | handler->DidRunJavaScriptDialog( |
Avi Drissman | 4891b85 | 2018-09-25 18:12:58 | [diff] [blame] | 6040 | render_frame_host->GetLastCommittedURL(), normalized_message, |
| 6041 | default_prompt, dialog_type, has_non_devtools_handlers, |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6042 | base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6043 | } |
| 6044 | |
| 6045 | if (dialog_manager_) { |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6046 | dialog_manager_->RunJavaScriptDialog( |
Avi Drissman | 4891b85 | 2018-09-25 18:12:58 | [diff] [blame] | 6047 | this, render_frame_host, dialog_type, normalized_message, |
| 6048 | default_prompt, |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6049 | base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false), |
| 6050 | &suppress_this_message); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6051 | } |
| 6052 | |
| 6053 | if (suppress_this_message) { |
| 6054 | // If we are suppressing messages, just reply as if the user immediately |
| 6055 | // pressed "Cancel", passing true to |dialog_was_suppressed|. |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6056 | wrapper->Run(true, false, base::string16()); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6057 | } |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6058 | } |
| 6059 | |
| 6060 | void WebContentsImpl::RunBeforeUnloadConfirm( |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 6061 | RenderFrameHost* render_frame_host, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6062 | bool is_reload, |
Dave Tapuska | cdf545cc | 2020-01-23 18:38:52 | [diff] [blame] | 6063 | JavaScriptDialogCallback response_callback) { |
Avi Drissman | 2ccbb40 | 2018-03-20 21:11:36 | [diff] [blame] | 6064 | // Ensure that if showing a dialog is the first thing that a page does, that |
| 6065 | // the contents of the previous page aren't shown behind it. This is required |
| 6066 | // because showing a dialog freezes the renderer, so no frames will be coming |
| 6067 | // from it. https://crbug.com/823353 |
| 6068 | auto* render_widget_host_impl = |
| 6069 | static_cast<RenderFrameHostImpl*>(render_frame_host) |
| 6070 | ->GetRenderWidgetHost(); |
| 6071 | if (render_widget_host_impl) |
| 6072 | render_widget_host_impl->ForceFirstFrameAfterNavigationTimeout(); |
| 6073 | |
avi | 0720b02e | 2017-06-13 03:22:13 | [diff] [blame] | 6074 | // Running a dialog causes an exit to webpage-initiated fullscreen. |
| 6075 | // http://crbug.com/728276 |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 6076 | base::ScopedClosureRunner fullscreen_block = ForSecurityDropFullscreen(); |
avi | 0720b02e | 2017-06-13 03:22:13 | [diff] [blame] | 6077 | |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 6078 | RenderFrameHostImpl* rfhi = |
| 6079 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6080 | if (delegate_) |
| 6081 | delegate_->WillRunBeforeUnloadConfirm(); |
| 6082 | |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 6083 | auto callback = |
| 6084 | base::BindOnce(&WebContentsImpl::OnDialogClosed, base::Unretained(this), |
| 6085 | render_frame_host->GetProcess()->GetID(), |
| 6086 | render_frame_host->GetRoutingID(), |
| 6087 | std::move(response_callback), std::move(fullscreen_block)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6088 | |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6089 | std::vector<protocol::PageHandler*> page_handlers = |
| 6090 | protocol::PageHandler::EnabledForWebContents(this); |
| 6091 | |
Pavel Feldman | fab3cb6 | 2017-10-05 01:02:01 | [diff] [blame] | 6092 | if (delegate_) |
| 6093 | dialog_manager_ = delegate_->GetJavaScriptDialogManager(this); |
| 6094 | |
Charlie Reis | 9607736 | 2019-07-04 00:34:04 | [diff] [blame] | 6095 | // While a JS beforeunload dialog is showing, defer commits in this |
| 6096 | // WebContents. |
| 6097 | javascript_dialog_navigation_deferrer_ = |
| 6098 | std::make_unique<JavaScriptDialogNavigationDeferrer>(); |
| 6099 | |
Sreeja Kamishetty | f352e30 | 2020-06-10 13:21:24 | [diff] [blame] | 6100 | bool should_suppress = !rfhi->IsCurrent() || |
Tarun Bansal | c209b74 | 2019-12-24 06:53:25 | [diff] [blame] | 6101 | (delegate_ && delegate_->ShouldSuppressDialogs(this)); |
Pavel Feldman | 1c587bc5 | 2018-04-04 21:16:05 | [diff] [blame] | 6102 | bool has_non_devtools_handlers = delegate_ && dialog_manager_; |
| 6103 | bool has_handlers = page_handlers.size() || has_non_devtools_handlers; |
Pavel Feldman | fab3cb6 | 2017-10-05 01:02:01 | [diff] [blame] | 6104 | if (should_suppress || !has_handlers) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6105 | std::move(callback).Run(false, true, base::string16()); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6106 | return; |
| 6107 | } |
| 6108 | |
| 6109 | is_showing_before_unload_dialog_ = true; |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6110 | |
| 6111 | scoped_refptr<CloseDialogCallbackWrapper> wrapper = |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6112 | new CloseDialogCallbackWrapper(std::move(callback)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6113 | |
| 6114 | GURL frame_url = rfhi->GetLastCommittedURL(); |
| 6115 | for (auto* handler : page_handlers) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6116 | handler->DidRunBeforeUnloadConfirm( |
Pavel Feldman | 1c587bc5 | 2018-04-04 21:16:05 | [diff] [blame] | 6117 | frame_url, has_non_devtools_handlers, |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6118 | base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6119 | } |
| 6120 | |
| 6121 | if (dialog_manager_) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6122 | dialog_manager_->RunBeforeUnloadDialog( |
Avi Drissman | ff9ed75 | 2017-11-28 21:18:12 | [diff] [blame] | 6123 | this, render_frame_host, is_reload, |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 6124 | base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6125 | } |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6126 | } |
| 6127 | |
Kent Tamura | c260c9a | 2018-09-14 09:10:56 | [diff] [blame] | 6128 | void WebContentsImpl::RunFileChooser( |
| 6129 | RenderFrameHost* render_frame_host, |
Kent Tamura | 3abb32d | 2020-07-02 00:23:01 | [diff] [blame] | 6130 | scoped_refptr<FileChooserImpl::FileSelectListenerImpl> listener, |
Kent Tamura | c260c9a | 2018-09-14 09:10:56 | [diff] [blame] | 6131 | const blink::mojom::FileChooserParams& params) { |
Avi Drissman | 3d41e771 | 2018-08-27 21:18:08 | [diff] [blame] | 6132 | // Any explicit focusing of another window while this WebContents is in |
| 6133 | // fullscreen can be used to confuse the user, so drop fullscreen. |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 6134 | base::ScopedClosureRunner fullscreen_block = ForSecurityDropFullscreen(); |
| 6135 | listener->SetFullscreenBlock(std::move(fullscreen_block)); |
Avi Drissman | 3d41e771 | 2018-08-27 21:18:08 | [diff] [blame] | 6136 | |
nasko | ada75b2 | 2016-06-11 16:09:46 | [diff] [blame] | 6137 | if (delegate_) |
Kent Tamura | 512a27e | 2018-10-04 00:49:32 | [diff] [blame] | 6138 | delegate_->RunFileChooser(render_frame_host, std::move(listener), params); |
| 6139 | else |
| 6140 | listener->FileSelectionCanceled(); |
nasko | ada75b2 | 2016-06-11 16:09:46 | [diff] [blame] | 6141 | } |
| 6142 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 6143 | WebContents* WebContentsImpl::GetAsWebContents() { |
| 6144 | return this; |
| 6145 | } |
| 6146 | |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 6147 | #if !defined(OS_ANDROID) |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 6148 | double WebContentsImpl::GetPendingPageZoomLevel() { |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 6149 | NavigationEntry* pending_entry = GetController().GetPendingEntry(); |
| 6150 | if (!pending_entry) |
| 6151 | return HostZoomMap::GetZoomLevel(this); |
| 6152 | |
| 6153 | GURL url = pending_entry->GetURL(); |
| 6154 | return HostZoomMap::GetForWebContents(this)->GetZoomLevelForHostAndScheme( |
| 6155 | url.scheme(), net::GetHostOrSpecFromURL(url)); |
| 6156 | } |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 6157 | #endif // !defined(OS_ANDROID) |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 6158 | |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 6159 | bool WebContentsImpl::HideDownloadUI() const { |
| 6160 | return is_overlay_content_; |
| 6161 | } |
| 6162 | |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 6163 | bool WebContentsImpl::HasPersistentVideo() const { |
| 6164 | return has_persistent_video_; |
| 6165 | } |
| 6166 | |
Ian Vollick | 5d5c37f | 2019-06-19 22:50:57 | [diff] [blame] | 6167 | bool WebContentsImpl::IsSpatialNavigationDisabled() const { |
| 6168 | return is_spatial_navigation_disabled_; |
| 6169 | } |
| 6170 | |
Albert J. Wong | 65fe64d | 2019-09-20 02:48:14 | [diff] [blame] | 6171 | RenderFrameHostImpl* WebContentsImpl::GetPendingMainFrame() { |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 6172 | return GetRenderManager()->speculative_frame_host(); |
Alex Moshchuk | 27caae8 | 2017-09-11 23:11:18 | [diff] [blame] | 6173 | } |
| 6174 | |
mlamouri | e52c1b54 | 2017-02-23 14:57:50 | [diff] [blame] | 6175 | bool WebContentsImpl::HasActiveEffectivelyFullscreenVideo() const { |
| 6176 | return media_web_contents_observer_->HasActiveEffectivelyFullscreenVideo(); |
| 6177 | } |
| 6178 | |
François Beaufort | ad6c523 | 2018-02-26 11:00:44 | [diff] [blame] | 6179 | bool WebContentsImpl::IsPictureInPictureAllowedForFullscreenVideo() const { |
| 6180 | return media_web_contents_observer_ |
| 6181 | ->IsPictureInPictureAllowedForFullscreenVideo(); |
| 6182 | } |
| 6183 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 6184 | bool WebContentsImpl::IsFocusedElementEditable() { |
| 6185 | RenderFrameHostImpl* frame = GetFocusedFrame(); |
| 6186 | return frame && frame->has_focused_editable_element(); |
| 6187 | } |
| 6188 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 6189 | bool WebContentsImpl::IsShowingContextMenu() { |
ekaramad | f6750aa | 2017-06-06 18:29:42 | [diff] [blame] | 6190 | return showing_context_menu_; |
| 6191 | } |
| 6192 | |
| 6193 | void WebContentsImpl::SetShowingContextMenu(bool showing) { |
| 6194 | DCHECK_NE(showing_context_menu_, showing); |
| 6195 | showing_context_menu_ = showing; |
| 6196 | |
| 6197 | if (auto* view = GetRenderWidgetHostView()) { |
| 6198 | // Notify the main frame's RWHV to run the platform-specific code, if any. |
| 6199 | static_cast<RenderWidgetHostViewBase*>(view)->SetShowingContextMenu( |
| 6200 | showing); |
| 6201 | } |
| 6202 | } |
| 6203 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 6204 | void WebContentsImpl::ClearFocusedElement() { |
| 6205 | if (auto* frame = GetFocusedFrame()) |
| 6206 | frame->ClearFocusedElement(); |
| 6207 | } |
| 6208 | |
danakj | 77eb7e8 | 2020-01-09 19:38:46 | [diff] [blame] | 6209 | bool WebContentsImpl::IsNeverComposited() { |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 6210 | if (!delegate_) |
| 6211 | return false; |
danakj | 77eb7e8 | 2020-01-09 19:38:46 | [diff] [blame] | 6212 | return delegate_->IsNeverComposited(this); |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 6213 | } |
| 6214 | |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 6215 | RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() { |
| 6216 | return render_view_host_delegate_view_; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6217 | } |
| 6218 | |
Peter Marshall | 2dc74e9 | 2020-07-29 20:02:30 | [diff] [blame] | 6219 | blink::mojom::RendererPreferences WebContentsImpl::GetRendererPrefs() const { |
[email protected] | 840b151 | 2009-07-21 16:53:46 | [diff] [blame] | 6220 | return renderer_preferences_; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 6221 | } |
| 6222 | |
Lucas Furukawa Gadani | 2ec00c8 | 2018-12-14 15:53:16 | [diff] [blame] | 6223 | RenderFrameHostImpl* WebContentsImpl::GetOuterWebContentsFrame() { |
| 6224 | if (GetOuterDelegateFrameTreeNodeId() == |
| 6225 | FrameTreeNode::kFrameTreeNodeInvalidId) { |
| 6226 | return nullptr; |
| 6227 | } |
| 6228 | |
| 6229 | FrameTreeNode* outer_node = |
| 6230 | FrameTreeNode::GloballyFindByID(GetOuterDelegateFrameTreeNodeId()); |
| 6231 | // The outer node should be in the outer WebContents. |
| 6232 | DCHECK_EQ(outer_node->frame_tree(), GetOuterWebContents()->GetFrameTree()); |
Alexander Timin | 381e7e18 | 2020-04-28 19:04:03 | [diff] [blame] | 6233 | return outer_node->parent(); |
Lucas Furukawa Gadani | 2ec00c8 | 2018-12-14 15:53:16 | [diff] [blame] | 6234 | } |
| 6235 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 6236 | WebContentsImpl* WebContentsImpl::GetOuterWebContents() { |
Lucas Furukawa Gadani | 105de1e81 | 2018-05-31 19:38:39 | [diff] [blame] | 6237 | return node_.outer_web_contents(); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 6238 | } |
| 6239 | |
Lucas Furukawa Gadani | 2ec00c8 | 2018-12-14 15:53:16 | [diff] [blame] | 6240 | std::vector<WebContents*> WebContentsImpl::GetInnerWebContents() { |
| 6241 | std::vector<WebContents*> all_inner_contents; |
Lucas Furukawa Gadani | 2ec00c8 | 2018-12-14 15:53:16 | [diff] [blame] | 6242 | const auto& inner_contents = node_.GetInnerWebContents(); |
| 6243 | all_inner_contents.insert(all_inner_contents.end(), inner_contents.begin(), |
| 6244 | inner_contents.end()); |
| 6245 | return all_inner_contents; |
| 6246 | } |
| 6247 | |
Jeremy Roman | 7e70bf9 | 2020-01-07 23:23:58 | [diff] [blame] | 6248 | WebContentsImpl* WebContentsImpl::GetResponsibleWebContents() { |
| 6249 | // Iteratively ask delegates which other contents is responsible until a fixed |
| 6250 | // point is found. |
| 6251 | WebContentsImpl* contents = this; |
| 6252 | while (WebContentsDelegate* delegate = contents->GetDelegate()) { |
| 6253 | auto* responsible_contents = static_cast<WebContentsImpl*>( |
| 6254 | delegate->GetResponsibleWebContents(contents)); |
| 6255 | if (responsible_contents == contents) |
| 6256 | break; |
| 6257 | contents = responsible_contents; |
| 6258 | } |
| 6259 | return contents; |
| 6260 | } |
| 6261 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 6262 | WebContentsImpl* WebContentsImpl::GetFocusedWebContents() { |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 6263 | return GetOutermostWebContents()->node_.focused_web_contents(); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 6264 | } |
| 6265 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 6266 | bool WebContentsImpl::ContainsOrIsFocusedWebContents() { |
| 6267 | for (WebContentsImpl* focused_contents = GetFocusedWebContents(); |
| 6268 | focused_contents; |
| 6269 | focused_contents = focused_contents->GetOuterWebContents()) { |
| 6270 | if (focused_contents == this) |
| 6271 | return true; |
| 6272 | } |
| 6273 | |
| 6274 | return false; |
| 6275 | } |
| 6276 | |
W. James MacLean | 9437b5bf | 2019-12-06 17:33:44 | [diff] [blame] | 6277 | void WebContentsImpl::RemoveBrowserPluginEmbedder() { |
| 6278 | browser_plugin_embedder_.reset(); |
| 6279 | } |
| 6280 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 6281 | WebContentsImpl* WebContentsImpl::GetOutermostWebContents() { |
| 6282 | WebContentsImpl* root = this; |
| 6283 | while (root->GetOuterWebContents()) |
| 6284 | root = root->GetOuterWebContents(); |
| 6285 | return root; |
| 6286 | } |
| 6287 | |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 6288 | void WebContentsImpl::FocusOuterAttachmentFrameChain() { |
| 6289 | WebContentsImpl* outer_contents = GetOuterWebContents(); |
| 6290 | if (!outer_contents) |
| 6291 | return; |
| 6292 | |
| 6293 | FrameTreeNode* outer_node = |
| 6294 | FrameTreeNode::GloballyFindByID(GetOuterDelegateFrameTreeNodeId()); |
| 6295 | outer_contents->frame_tree_.SetFocusedFrame(outer_node, nullptr); |
| 6296 | |
| 6297 | // For a browser initiated focus change, let embedding renderer know of the |
| 6298 | // change. Otherwise, if the currently focused element is just across a |
| 6299 | // process boundary in focus order, it will not be possible to move across |
| 6300 | // that boundary. This is because the target element will already be focused |
| 6301 | // (that renderer was not notified) and drop the event. |
| 6302 | if (GetRenderManager()->GetProxyToOuterDelegate()) |
| 6303 | GetRenderManager()->GetProxyToOuterDelegate()->SetFocusedFrame(); |
| 6304 | |
| 6305 | outer_contents->FocusOuterAttachmentFrameChain(); |
| 6306 | } |
| 6307 | |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 6308 | void WebContentsImpl::InnerWebContentsCreated(WebContents* inner_web_contents) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 6309 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6310 | observer->InnerWebContentsCreated(inner_web_contents); |
| 6311 | }); |
Sean Topping | bbc4a2bd | 2019-01-30 02:16:14 | [diff] [blame] | 6312 | } |
| 6313 | |
Jeremy Roman | 03ce13ce | 2020-05-29 22:16:57 | [diff] [blame] | 6314 | void WebContentsImpl::InnerWebContentsAttached( |
| 6315 | WebContents* inner_web_contents) { |
| 6316 | if (inner_web_contents->IsCurrentlyAudible()) |
| 6317 | OnAudioStateChanged(); |
| 6318 | } |
| 6319 | |
| 6320 | void WebContentsImpl::InnerWebContentsDetached( |
| 6321 | WebContents* inner_web_contents) { |
| 6322 | if (!is_being_destroyed_) |
| 6323 | OnAudioStateChanged(); |
| 6324 | } |
| 6325 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 6326 | void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
[email protected] | 86f98a2 | 2013-03-20 14:35:00 | [diff] [blame] | 6327 | if (delegate_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 6328 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 6329 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 6330 | NotificationService::current()->Notify( |
| 6331 | NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
| 6332 | Source<WebContents>(this), |
| 6333 | Details<RenderViewHost>(render_view_host)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6334 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 6335 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6336 | observer->RenderViewCreated(render_view_host); |
| 6337 | }); |
Joel Einbinder | 848001c | 2017-09-19 21:39:31 | [diff] [blame] | 6338 | if (delegate_) |
| 6339 | RenderFrameDevToolsAgentHost::WebContentsCreated(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6340 | } |
| 6341 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 6342 | void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 6343 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6344 | // Don't notify the world, since this came from a renderer in the |
| 6345 | // background. |
| 6346 | return; |
| 6347 | } |
| 6348 | |
dmazzoni | 6211145 | 2017-04-28 23:46:55 | [diff] [blame] | 6349 | RenderWidgetHostViewBase* rwhv = |
| 6350 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 6351 | if (rwhv) |
| 6352 | rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID()); |
| 6353 | |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 6354 | notify_disconnection_ = true; |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 6355 | |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 6356 | bool was_crashed = IsCrashed(); |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 6357 | SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 6358 | |
| 6359 | // Restore the focus to the tab (otherwise the focus will be on the top |
| 6360 | // window). |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 6361 | if (was_crashed && !FocusLocationBarByDefault() && |
| 6362 | (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { |
[email protected] | f3615f0 | 2013-02-26 06:09:06 | [diff] [blame] | 6363 | view_->Focus(); |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 6364 | } |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 6365 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 6366 | observers_.ForEachObserver( |
| 6367 | [&](WebContentsObserver* observer) { observer->RenderViewReady(); }); |
Jinsuk Kim | 895b2c5 | 2018-07-03 06:49:16 | [diff] [blame] | 6368 | view_->RenderViewReady(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6369 | } |
| 6370 | |
[email protected] | ec6a7eb | 2013-04-22 17:34:22 | [diff] [blame] | 6371 | void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh, |
| 6372 | base::TerminationStatus status, |
| 6373 | int error_code) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 6374 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6375 | // The pending page's RenderViewHost is gone. |
| 6376 | return; |
| 6377 | } |
| 6378 | |
[email protected] | 2fcdcc3 | 2014-03-05 02:14:07 | [diff] [blame] | 6379 | // Ensure fullscreen mode is exited in the |delegate_| since a crashed |
| 6380 | // renderer may not have made a clean exit. |
Avi Drissman | 97aef04 | 2020-06-30 21:04:48 | [diff] [blame] | 6381 | if (IsFullscreen()) |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 6382 | ExitFullscreenMode(false); |
[email protected] | 2fcdcc3 | 2014-03-05 02:14:07 | [diff] [blame] | 6383 | |
Jennifer Apacible | b4b972a | 2018-06-07 04:41:02 | [diff] [blame] | 6384 | // Ensure any video in Picture-in-Picture is exited in the |delegate_| since |
| 6385 | // a crashed renderer may not have made a clean exit. |
| 6386 | if (HasPictureInPictureVideo()) |
| 6387 | ExitPictureInPicture(); |
| 6388 | |
[email protected] | 698191dc | 2014-02-25 01:06:13 | [diff] [blame] | 6389 | // Cancel any visible dialogs so they are not left dangling over the sad tab. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 6390 | CancelActiveAndPendingDialogs(); |
[email protected] | 698191dc | 2014-02-25 01:06:13 | [diff] [blame] | 6391 | |
dalecurtis | 3d1e130 | 2017-02-20 22:33:25 | [diff] [blame] | 6392 | audio_stream_monitor_.RenderProcessGone(rvh->GetProcess()->GetID()); |
| 6393 | |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 6394 | // Reset the loading progress. TODO(avi): What does it mean to have a |
| 6395 | // "renderer crash" when there is more than one renderer process serving a |
| 6396 | // webpage? Once this function is called at a more granular frame level, we |
| 6397 | // probably will need to more granularly reset the state here. |
| 6398 | ResetLoadProgressState(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 6399 | NotifyDisconnected(); |
| 6400 | SetIsCrashed(status, error_code); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 6401 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 6402 | TRACE_EVENT0("content", "Dispatching WebContentsObserver::RenderProcessGone"); |
| 6403 | // Some observers might destroy WebContents in RenderViewTerminated. |
| 6404 | base::WeakPtr<WebContentsImpl> weak_ptr = weak_factory_.GetWeakPtr(); |
| 6405 | auto crashed_status = GetCrashedStatus(); |
| 6406 | for (auto& observer : observers_.observer_list()) { |
| 6407 | observer.RenderProcessGone(crashed_status); |
| 6408 | if (!weak_ptr) |
| 6409 | return; |
| 6410 | } |
| 6411 | |
| 6412 | // |this| might have been deleted. Do not add code here. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6413 | } |
| 6414 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 6415 | void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 6416 | observers_.ForEachObserver( |
| 6417 | [&](WebContentsObserver* observer) { observer->RenderViewDeleted(rvh); }); |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 6418 | } |
| 6419 | |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 6420 | void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host, |
| 6421 | const GURL& url) { |
| 6422 | if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) { |
Lukasz Anforowicz | fd70714 | 2018-02-07 19:46:13 | [diff] [blame] | 6423 | // If we're in flash fullscreen (i.e. Pepper plugin fullscreen) only update |
| 6424 | // the url if it's from the fullscreen renderer. |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 6425 | RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView(); |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 6426 | if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget()) |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 6427 | return; |
| 6428 | } |
Lukasz Anforowicz | fd70714 | 2018-02-07 19:46:13 | [diff] [blame] | 6429 | |
| 6430 | // In case of racey updates from multiple RenderViewHosts, the last URL should |
| 6431 | // be shown - see also some discussion in https://crbug.com/807776. |
| 6432 | if (!url.is_valid() && render_view_host != view_that_set_last_target_url_) |
| 6433 | return; |
| 6434 | view_that_set_last_target_url_ = url.is_valid() ? render_view_host : nullptr; |
| 6435 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 6436 | if (delegate_) |
avi | 450ce00e | 2014-09-24 01:58:52 | [diff] [blame] | 6437 | delegate_->UpdateTargetURL(this, url); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6438 | } |
| 6439 | |
Lukasz Anforowicz | fd70714 | 2018-02-07 19:46:13 | [diff] [blame] | 6440 | void WebContentsImpl::ClearTargetURL() { |
| 6441 | view_that_set_last_target_url_ = nullptr; |
| 6442 | if (delegate_) |
| 6443 | delegate_->UpdateTargetURL(this, GURL()); |
| 6444 | } |
| 6445 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 6446 | void WebContentsImpl::Close(RenderViewHost* rvh) { |
Avi Drissman | 7c57be7 | 2020-07-29 20:09:46 | [diff] [blame] | 6447 | #if defined(OS_MAC) |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 6448 | // The UI may be in an event-tracking loop, such as between the |
| 6449 | // mouse-down and mouse-up in text selection or a button click. |
| 6450 | // Defer the close until after tracking is complete, so that we |
| 6451 | // don't free objects out from under the UI. |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 6452 | // TODO(shess): This could get more fine-grained. For instance, |
| 6453 | // closing a tab in another window while selecting text in the |
| 6454 | // current window's Omnibox should be just fine. |
Christopher Cameron | 9ae31e0d | 2019-03-01 20:01:19 | [diff] [blame] | 6455 | if (view_->CloseTabAfterEventTrackingIfNeeded()) |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 6456 | return; |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 6457 | #endif |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 6458 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6459 | // Ignore this if it comes from a RenderViewHost that we aren't showing. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 6460 | if (delegate_ && rvh == GetRenderViewHost()) |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 6461 | delegate_->CloseContents(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6462 | } |
| 6463 | |
Avi Drissman | 014dec7 | 2018-06-07 02:34:01 | [diff] [blame] | 6464 | void WebContentsImpl::RequestSetBounds(const gfx::Rect& new_bounds) { |
| 6465 | if (delegate_) |
| 6466 | delegate_->SetContentsBounds(this, new_bounds); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6467 | } |
| 6468 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 6469 | void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node, |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 6470 | bool to_different_document) { |
Evan Stade | c3b2602 | 2017-07-14 19:50:24 | [diff] [blame] | 6471 | LoadingStateChanged(frame_tree_node->IsMainFrame() && to_different_document, |
Carlos IL | 07f282f | 2020-05-15 22:58:29 | [diff] [blame] | 6472 | nullptr); |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 6473 | |
Xiyuan Xia | 2a66b11 | 2018-12-06 15:52:16 | [diff] [blame] | 6474 | // Reset the focus state from DidStartNavigation to false if a new load starts |
| 6475 | // afterward, in case loading logic triggers a FocusLocationBarByDefault call. |
| 6476 | should_focus_location_bar_by_default_ = false; |
Ian Prest | cdd843d | 2020-01-28 18:59:58 | [diff] [blame] | 6477 | |
| 6478 | // Notify accessibility that the user is navigating away from the |
| 6479 | // current document. |
| 6480 | // TODO(domfarolino, dmazzoni): Do this using WebContentsObserver. See |
| 6481 | // https://crbug.com/981271. |
| 6482 | BrowserAccessibilityManager* manager = |
| 6483 | frame_tree_node->current_frame_host()->browser_accessibility_manager(); |
| 6484 | if (manager) |
| 6485 | manager->UserIsNavigatingAway(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6486 | } |
| 6487 | |
fdegans | c73eec2 | 2015-03-19 14:47:54 | [diff] [blame] | 6488 | void WebContentsImpl::DidStopLoading() { |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 6489 | std::unique_ptr<LoadNotificationDetails> details; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6490 | |
[email protected] | 9595fd8 | 2013-04-19 21:28:49 | [diff] [blame] | 6491 | // Use the last committed entry rather than the active one, in case a |
| 6492 | // pending entry has been created. |
| 6493 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
| 6494 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6495 | // An entry may not exist for a stop when loading an initial blank page or |
| 6496 | // if an iframe injected by script into a blank page finishes loading. |
| 6497 | if (entry) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6498 | details.reset(new LoadNotificationDetails( |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 6499 | entry->GetVirtualURL(), |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6500 | &controller_, |
| 6501 | controller_.GetCurrentEntryIndex())); |
| 6502 | } |
| 6503 | |
Carlos IL | 07f282f | 2020-05-15 22:58:29 | [diff] [blame] | 6504 | LoadingStateChanged(true, details.get()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6505 | } |
| 6506 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 6507 | void WebContentsImpl::DidChangeLoadProgress() { |
Nate Chapin | 22ea659 | 2019-03-05 22:29:02 | [diff] [blame] | 6508 | if (is_being_destroyed_) |
| 6509 | return; |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 6510 | double load_progress = frame_tree_.load_progress(); |
| 6511 | |
| 6512 | // The delegate is notified immediately for the first and last updates. Also, |
| 6513 | // since the message loop may be pretty busy when a page is loaded, it might |
| 6514 | // not execute a posted task in a timely manner so the progress report is sent |
| 6515 | // immediately if enough time has passed. |
| 6516 | base::TimeDelta min_delay = |
| 6517 | base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS); |
| 6518 | bool delay_elapsed = loading_last_progress_update_.is_null() || |
| 6519 | base::TimeTicks::Now() - loading_last_progress_update_ > min_delay; |
| 6520 | |
| 6521 | if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) { |
| 6522 | // If there is a pending task to send progress, it is now obsolete. |
| 6523 | loading_weak_factory_.InvalidateWeakPtrs(); |
| 6524 | |
| 6525 | // Notify the load progress change. |
| 6526 | SendChangeLoadProgress(); |
| 6527 | |
| 6528 | // Clean-up the states if needed. |
| 6529 | if (load_progress == 1.0) |
| 6530 | ResetLoadProgressState(); |
| 6531 | return; |
| 6532 | } |
| 6533 | |
| 6534 | if (loading_weak_factory_.HasWeakPtrs()) |
| 6535 | return; |
| 6536 | |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 6537 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
tzik | e2aca99 | 2017-09-05 08:50:54 | [diff] [blame] | 6538 | FROM_HERE, |
| 6539 | base::BindOnce(&WebContentsImpl::SendChangeLoadProgress, |
| 6540 | loading_weak_factory_.GetWeakPtr()), |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 6541 | min_delay); |
| 6542 | } |
| 6543 | |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 6544 | std::vector<std::unique_ptr<NavigationThrottle>> |
| 6545 | WebContentsImpl::CreateThrottlesForNavigation( |
clamy | cbf524d4 | 2016-09-27 12:48:35 | [diff] [blame] | 6546 | NavigationHandle* navigation_handle) { |
Charlie Reis | 9607736 | 2019-07-04 00:34:04 | [diff] [blame] | 6547 | auto throttles = GetContentClient()->browser()->CreateThrottlesForNavigation( |
clamy | cbf524d4 | 2016-09-27 12:48:35 | [diff] [blame] | 6548 | navigation_handle); |
Charlie Reis | 9607736 | 2019-07-04 00:34:04 | [diff] [blame] | 6549 | |
| 6550 | // This is not a normal place to be adding a throttle. However, in the case |
| 6551 | // javascript dialogs, related logic is present in the web_contents/ layer, |
| 6552 | // and the purpose of the throttle is to ensure that navigation commits are |
| 6553 | // deferred for the entire WebContents. Most throttles are either added by |
| 6554 | // the embederrer outside of content/, or are per-frame and added by |
| 6555 | // NavigationThrottleRunner. |
| 6556 | std::unique_ptr<content::NavigationThrottle> dialog_throttle = |
| 6557 | JavaScriptDialogNavigationThrottle::MaybeCreateThrottleFor( |
| 6558 | navigation_handle); |
| 6559 | if (dialog_throttle) |
| 6560 | throttles.push_back(std::move(dialog_throttle)); |
| 6561 | |
| 6562 | return throttles; |
clamy | cbf524d4 | 2016-09-27 12:48:35 | [diff] [blame] | 6563 | } |
| 6564 | |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 6565 | std::unique_ptr<NavigationUIData> WebContentsImpl::GetNavigationUIData( |
| 6566 | NavigationHandle* navigation_handle) { |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 6567 | return GetContentClient()->browser()->GetNavigationUIData(navigation_handle); |
| 6568 | } |
| 6569 | |
W. James MacLean | 1c40862c | 2020-04-27 21:05:57 | [diff] [blame] | 6570 | void WebContentsImpl::RegisterExistingOriginToPreventOptInIsolation( |
W. James MacLean | b70fab8 | 2020-05-01 18:51:14 | [diff] [blame] | 6571 | const url::Origin& origin, |
| 6572 | NavigationRequest* navigation_request_to_exclude) { |
W. James MacLean | 1c40862c | 2020-04-27 21:05:57 | [diff] [blame] | 6573 | // Note: This function can be made static if we ever need call it without |
| 6574 | // a WebContentsImpl instance, in which case we can use a wrapper to |
| 6575 | // implement the override from NavigatorDelegate. |
| 6576 | for (WebContentsImpl* web_contents : GetAllWebContents()) { |
| 6577 | web_contents->controller_.RegisterExistingOriginToPreventOptInIsolation( |
| 6578 | origin); |
W. James MacLean | b70fab8 | 2020-05-01 18:51:14 | [diff] [blame] | 6579 | // Walk the frame tree to pick up any frames without FrameNavigationEntries. |
| 6580 | // * Some frames won't have FrameNavigationEntries (Issues 524208, 608402). |
| 6581 | // * Some pending navigations won't have NavigationEntries. |
| 6582 | web_contents->GetFrameTree()->RegisterExistingOriginToPreventOptInIsolation( |
| 6583 | origin, navigation_request_to_exclude); |
W. James MacLean | 1c40862c | 2020-04-27 21:05:57 | [diff] [blame] | 6584 | } |
| 6585 | } |
| 6586 | |
pdr | 15f5b5b | 2017-06-20 00:58:00 | [diff] [blame] | 6587 | void WebContentsImpl::DidCancelLoading() { |
| 6588 | controller_.DiscardNonCommittedEntries(); |
| 6589 | |
| 6590 | // Update the URL display. |
| 6591 | NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
| 6592 | } |
| 6593 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 6594 | void WebContentsImpl::DidAccessInitialDocument() { |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 6595 | has_accessed_initial_document_ = true; |
| 6596 | |
[email protected] | d1371bf8e | 2014-04-19 03:26:24 | [diff] [blame] | 6597 | // We may have left a failed browser-initiated navigation in the address bar |
| 6598 | // to let the user edit it and try again. Clear it now that content might |
| 6599 | // show up underneath it. |
| 6600 | if (!IsLoading() && controller_.GetPendingEntry()) |
avi | 45a7253 | 2015-04-07 21:01:45 | [diff] [blame] | 6601 | controller_.DiscardPendingEntry(false); |
[email protected] | d1371bf8e | 2014-04-19 03:26:24 | [diff] [blame] | 6602 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 6603 | // Update the URL display. |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 6604 | NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 6605 | } |
| 6606 | |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 6607 | void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host, |
| 6608 | const std::string& name) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 6609 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6610 | observer->FrameNameChanged(render_frame_host, name); |
| 6611 | }); |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 6612 | } |
| 6613 | |
John Delaney | edd8d6c | 2019-01-25 00:23:57 | [diff] [blame] | 6614 | void WebContentsImpl::DidReceiveFirstUserActivation( |
| 6615 | RenderFrameHost* render_frame_host) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 6616 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6617 | observer->FrameReceivedFirstUserActivation(render_frame_host); |
| 6618 | }); |
John Delaney | edd8d6c | 2019-01-25 00:23:57 | [diff] [blame] | 6619 | } |
| 6620 | |
John Delaney | 0146a74 | 2019-01-25 19:25:28 | [diff] [blame] | 6621 | void WebContentsImpl::DidChangeDisplayState(RenderFrameHost* render_frame_host, |
| 6622 | bool is_display_none) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 6623 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6624 | observer->FrameDisplayStateChanged(render_frame_host, is_display_none); |
| 6625 | }); |
John Delaney | 0146a74 | 2019-01-25 19:25:28 | [diff] [blame] | 6626 | } |
| 6627 | |
| 6628 | void WebContentsImpl::FrameSizeChanged(RenderFrameHost* render_frame_host, |
| 6629 | const gfx::Size& frame_size) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 6630 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6631 | observer->FrameSizeChanged(render_frame_host, frame_size); |
| 6632 | }); |
John Delaney | 0146a74 | 2019-01-25 19:25:28 | [diff] [blame] | 6633 | } |
| 6634 | |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 6635 | void WebContentsImpl::DocumentOnLoadCompleted( |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 6636 | RenderFrameHost* render_frame_host) { |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 6637 | ShowInsecureLocalhostWarningIfNeeded(); |
| 6638 | |
Alexander Timin | dd0fa0c5 | 2019-11-06 13:03:37 | [diff] [blame] | 6639 | GetRenderViewHost()->DocumentOnLoadCompletedInMainFrame(); |
| 6640 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 6641 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6642 | observer->DocumentOnLoadCompletedInMainFrame(); |
| 6643 | }); |
[email protected] | 6578fef | 2013-10-14 02:35:09 | [diff] [blame] | 6644 | |
| 6645 | // TODO(avi): Remove. http://crbug.com/170921 |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 6646 | NotificationService::current()->Notify( |
| 6647 | NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 6648 | Source<WebContents>(this), |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 6649 | NotificationService::NoDetails()); |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 6650 | } |
| 6651 | |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 6652 | void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host, |
| 6653 | const PageState& page_state) { |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 6654 | // The state update affects the last NavigationEntry associated with the given |
| 6655 | // |render_frame_host|. This may not be the last committed NavigationEntry (as |
| 6656 | // in the case of an UpdateState from a frame being swapped out). We track |
| 6657 | // which entry this is in the RenderFrameHost's nav_entry_id. |
| 6658 | RenderFrameHostImpl* rfhi = |
| 6659 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
| 6660 | NavigationEntryImpl* entry = |
| 6661 | controller_.GetEntryWithUniqueID(rfhi->nav_entry_id()); |
| 6662 | if (!entry) |
| 6663 | return; |
| 6664 | |
| 6665 | FrameNavigationEntry* frame_entry = |
| 6666 | entry->GetFrameEntry(rfhi->frame_tree_node()); |
| 6667 | if (!frame_entry) |
| 6668 | return; |
| 6669 | |
creis | d06a942 | 2015-11-11 03:08:45 | [diff] [blame] | 6670 | // The SiteInstance might not match if we do a cross-process navigation with |
| 6671 | // replacement (e.g., auto-subframe), in which case the swap out of the old |
| 6672 | // RenderFrameHost runs in the background after the old FrameNavigationEntry |
| 6673 | // has already been replaced and destroyed. |
| 6674 | if (frame_entry->site_instance() != rfhi->GetSiteInstance()) |
| 6675 | return; |
| 6676 | |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 6677 | if (page_state == frame_entry->page_state()) |
| 6678 | return; // Nothing to update. |
| 6679 | |
creis | 0cade2e | 2017-02-28 06:37:47 | [diff] [blame] | 6680 | DCHECK(page_state.IsValid()) << "Shouldn't set an empty PageState."; |
nasko | 3463467 | 2016-07-29 18:46:06 | [diff] [blame] | 6681 | |
| 6682 | // The document_sequence_number and item_sequence_number recorded in the |
| 6683 | // FrameNavigationEntry should not differ from the one coming with the update, |
| 6684 | // since it must come from the same document. Do not update it if a difference |
| 6685 | // is detected, as this indicates that |frame_entry| is not the correct one. |
| 6686 | ExplodedPageState exploded_state; |
| 6687 | if (!DecodePageState(page_state.ToEncodedData(), &exploded_state)) |
| 6688 | return; |
| 6689 | |
| 6690 | if (exploded_state.top.document_sequence_number != |
| 6691 | frame_entry->document_sequence_number() || |
| 6692 | exploded_state.top.item_sequence_number != |
| 6693 | frame_entry->item_sequence_number()) { |
| 6694 | return; |
| 6695 | } |
| 6696 | |
nasko | 04a322f25a | 2016-09-01 00:00:34 | [diff] [blame] | 6697 | frame_entry->SetPageState(page_state); |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 6698 | controller_.NotifyEntryChanged(entry); |
| 6699 | } |
| 6700 | |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 6701 | void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host, |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 6702 | const base::string16& title, |
| 6703 | base::i18n::TextDirection title_direction) { |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 6704 | // Try to find the navigation entry, which might not be the current one. |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 6705 | // For example, it might be from a recently swapped out RFH. |
avi | 1edc855 | 2016-10-13 21:37:16 | [diff] [blame] | 6706 | NavigationEntryImpl* entry = controller_.GetEntryWithUniqueID( |
creis | ad8c31a | 2016-05-24 17:07:04 | [diff] [blame] | 6707 | static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id()); |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 6708 | |
| 6709 | // We can handle title updates when we don't have an entry in |
| 6710 | // UpdateTitleForEntry, but only if the update is from the current RVH. |
| 6711 | // TODO(avi): Change to make decisions based on the RenderFrameHost. |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 6712 | if (!entry && render_frame_host != GetMainFrame()) |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 6713 | return; |
| 6714 | |
| 6715 | // TODO(evan): make use of title_direction. |
| 6716 | // http://code.google.com/p/chromium/issues/detail?id=27094 |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 6717 | UpdateTitleForEntry(entry, title); |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 6718 | } |
| 6719 | |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 6720 | bool WebContentsImpl::ShouldRouteMessageEvent( |
| 6721 | RenderFrameHost* target_rfh, |
| 6722 | SiteInstance* source_site_instance) const { |
| 6723 | // Allow the message if this WebContents is dedicated to a browser plugin |
| 6724 | // guest. |
[email protected] | 0eba810b | 2012-10-18 03:19:36 | [diff] [blame] | 6725 | // Note: This check means that an embedder could theoretically receive a |
| 6726 | // postMessage from anyone (not just its own guests). However, this is |
| 6727 | // probably not a risk for apps since other pages won't have references |
| 6728 | // to App windows. |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 6729 | return GetBrowserPluginGuest() || GetBrowserPluginEmbedder(); |
| 6730 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 6731 | |
alexmos | 5872904 | 2015-06-18 23:20:00 | [diff] [blame] | 6732 | void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) { |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 6733 | WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>( |
| 6734 | WebContents::FromRenderFrameHost(source_rfh)); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 6735 | |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 6736 | if (source_web_contents) { |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 6737 | // If this message is going to outer WebContents from inner WebContents, |
| 6738 | // then we should not create a RenderView. AttachToOuterWebContentsFrame() |
| 6739 | // already created a RenderFrameProxyHost for that purpose. |
| 6740 | if (GetBrowserPluginEmbedder() && |
W. James MacLean | 2539adb3 | 2019-12-13 00:40:44 | [diff] [blame] | 6741 | source_web_contents->browser_plugin_guest_) { |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 6742 | return; |
W. James MacLean | 2539adb3 | 2019-12-13 00:40:44 | [diff] [blame] | 6743 | } |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 6744 | |
lfg | 812874d | 2016-02-09 22:26:13 | [diff] [blame] | 6745 | if (this != source_web_contents && GetBrowserPluginGuest()) { |
nasko | b3041b98a4 | 2016-03-12 04:43:06 | [diff] [blame] | 6746 | // We create a RenderFrameProxyHost for the embedder in the guest's render |
| 6747 | // process but we intentionally do not expose the embedder's opener chain |
| 6748 | // to it. |
| 6749 | source_web_contents->GetRenderManager()->CreateRenderFrameProxy( |
| 6750 | GetSiteInstance()); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 6751 | } else { |
alexmos | 5872904 | 2015-06-18 23:20:00 | [diff] [blame] | 6752 | RenderFrameHostImpl* source_rfhi = |
| 6753 | static_cast<RenderFrameHostImpl*>(source_rfh); |
| 6754 | source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( |
alexmos | 90325cf | 2015-09-02 17:18:39 | [diff] [blame] | 6755 | GetSiteInstance(), nullptr); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 6756 | } |
| 6757 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 6758 | } |
| 6759 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 6760 | void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() { |
Adithya Srinivasan | 11af2c5 | 2019-12-16 22:52:55 | [diff] [blame] | 6761 | DCHECK(!portal()); |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 6762 | // Only change focus if we are not currently focused. |
| 6763 | WebContentsImpl* old_contents = GetFocusedWebContents(); |
| 6764 | if (old_contents == this) |
| 6765 | return; |
| 6766 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 6767 | GetOutermostWebContents()->node_.SetFocusedWebContents(this); |
| 6768 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 6769 | // Send a page level blur to the old contents so that it displays inactive UI |
| 6770 | // and focus this contents to activate it. |
| 6771 | if (old_contents) |
| 6772 | old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false); |
avallee | c2ff1ef | 2017-01-21 00:12:30 | [diff] [blame] | 6773 | |
| 6774 | // Make sure the outer web contents knows our frame is focused. Otherwise, the |
| 6775 | // outer renderer could have the element before or after the frame element |
| 6776 | // focused which would return early without actually advancing focus. |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 6777 | FocusOuterAttachmentFrameChain(); |
avallee | c2ff1ef | 2017-01-21 00:12:30 | [diff] [blame] | 6778 | |
Carlos IL | d51e770 | 2020-05-07 18:51:39 | [diff] [blame] | 6779 | GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true); |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 6780 | } |
| 6781 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 6782 | void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, |
| 6783 | SiteInstance* source) { |
Adithya Srinivasan | 11af2c5 | 2019-12-16 22:52:55 | [diff] [blame] | 6784 | DCHECK(!portal()); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 6785 | frame_tree_.SetFocusedFrame(node, source); |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 6786 | |
Lucas Furukawa Gadani | abbfa34 | 2017-08-29 19:37:57 | [diff] [blame] | 6787 | if (auto* inner_contents = node_.GetInnerWebContentsInFrame(node)) { |
| 6788 | // |this| is an outer WebContents and |node| represents an inner |
| 6789 | // WebContents. Transfer the focus to the inner contents if |this| is |
| 6790 | // focused. |
| 6791 | if (GetFocusedWebContents() == this) |
| 6792 | inner_contents->SetAsFocusedWebContentsIfNecessary(); |
| 6793 | } else if (node_.OuterContentsFrameTreeNode() && |
| 6794 | node_.OuterContentsFrameTreeNode() |
| 6795 | ->current_frame_host() |
| 6796 | ->GetSiteInstance() == source) { |
| 6797 | // |this| is an inner WebContents, |node| is its main FrameTreeNode and |
| 6798 | // the outer WebContents FrameTreeNode is at |source|'s SiteInstance. |
| 6799 | // Transfer the focus to the inner WebContents if the outer WebContents is |
| 6800 | // focused. This branch is used when an inner WebContents is focused through |
Lowell Manners | a953038 | 2019-08-01 09:46:57 | [diff] [blame] | 6801 | // its RenderFrameProxyHost (via FrameFocused mojo call, used to |
Lucas Furukawa Gadani | abbfa34 | 2017-08-29 19:37:57 | [diff] [blame] | 6802 | // implement the window.focus() API). |
| 6803 | if (GetFocusedWebContents() == GetOuterWebContents()) |
| 6804 | SetAsFocusedWebContentsIfNecessary(); |
| 6805 | } else if (!GetOuterWebContents()) { |
| 6806 | // This is an outermost WebContents. |
| 6807 | SetAsFocusedWebContentsIfNecessary(); |
Lucas Furukawa Gadani | abbfa34 | 2017-08-29 19:37:57 | [diff] [blame] | 6808 | } |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 6809 | } |
| 6810 | |
Avi Drissman | 36f801f | 2018-02-01 20:06:04 | [diff] [blame] | 6811 | void WebContentsImpl::DidCallFocus() { |
| 6812 | // Any explicit focusing of another window while this WebContents is in |
| 6813 | // fullscreen can be used to confuse the user, so drop fullscreen. |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 6814 | base::ScopedClosureRunner fullscreen_block = ForSecurityDropFullscreen(); |
| 6815 | // The other contents is independent of this contents, so release the |
| 6816 | // fullscreen block. |
| 6817 | fullscreen_block.RunAndReset(); |
Avi Drissman | 36f801f | 2018-02-01 20:06:04 | [diff] [blame] | 6818 | } |
| 6819 | |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 6820 | RenderFrameHost* WebContentsImpl::GetFocusedFrameIncludingInnerWebContents() { |
| 6821 | WebContentsImpl* contents = this; |
| 6822 | FrameTreeNode* focused_node = contents->frame_tree_.GetFocusedFrame(); |
| 6823 | |
| 6824 | // If there is no focused frame in the outer WebContents, we need to return |
| 6825 | // null. |
| 6826 | if (!focused_node) |
| 6827 | return nullptr; |
| 6828 | |
| 6829 | // If the focused frame is embedding an inner WebContents, we must descend |
| 6830 | // into that contents. If the current WebContents does not have a focused |
| 6831 | // frame, return the main frame of this contents instead of the focused empty |
| 6832 | // frame embedding this contents. |
| 6833 | while (true) { |
| 6834 | contents = contents->node_.GetInnerWebContentsInFrame(focused_node); |
| 6835 | if (!contents) |
| 6836 | return focused_node->current_frame_host(); |
| 6837 | |
| 6838 | focused_node = contents->frame_tree_.GetFocusedFrame(); |
| 6839 | if (!focused_node) |
| 6840 | return contents->GetMainFrame(); |
| 6841 | } |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 6842 | } |
| 6843 | |
Lucas Furukawa Gadani | abbfa34 | 2017-08-29 19:37:57 | [diff] [blame] | 6844 | void WebContentsImpl::OnAdvanceFocus(RenderFrameHostImpl* source_rfh) { |
| 6845 | // When a RenderFrame needs to advance focus to a RenderFrameProxy (by hitting |
| 6846 | // TAB), the RenderFrameProxy sends an IPC to RenderFrameProxyHost. When this |
| 6847 | // RenderFrameProxyHost represents an inner WebContents, the outer WebContents |
| 6848 | // needs to focus the inner WebContents. |
| 6849 | if (GetOuterWebContents() && |
| 6850 | GetOuterWebContents() == source_rfh->delegate()->GetAsWebContents() && |
| 6851 | GetFocusedWebContents() == GetOuterWebContents()) { |
| 6852 | SetAsFocusedWebContentsIfNecessary(); |
| 6853 | } |
| 6854 | } |
| 6855 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 6856 | void WebContentsImpl::OnFocusedElementChangedInFrame( |
| 6857 | RenderFrameHostImpl* frame, |
| 6858 | const gfx::Rect& bounds_in_root_view) { |
| 6859 | RenderWidgetHostViewBase* root_view = |
| 6860 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 6861 | if (!root_view || !frame->GetView()) |
| 6862 | return; |
Katie D | e013137 | 2020-07-09 23:03:10 | [diff] [blame] | 6863 | // Convert to screen coordinates from window coordinates by adding the |
| 6864 | // window's origin. |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 6865 | gfx::Point origin = bounds_in_root_view.origin(); |
| 6866 | origin += root_view->GetViewBounds().OffsetFromOrigin(); |
| 6867 | gfx::Rect bounds_in_screen(origin, bounds_in_root_view.size()); |
| 6868 | |
| 6869 | root_view->FocusedNodeChanged(frame->has_focused_editable_element(), |
| 6870 | bounds_in_screen); |
| 6871 | |
| 6872 | FocusedNodeDetails details = {frame->has_focused_editable_element(), |
| 6873 | bounds_in_screen}; |
| 6874 | |
| 6875 | // TODO(ekaramad): We should replace this with an observer notification |
| 6876 | // (https://crbug.com/675975). |
| 6877 | NotificationService::current()->Notify( |
| 6878 | NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
| 6879 | Source<RenderViewHost>(GetRenderViewHost()), |
| 6880 | Details<FocusedNodeDetails>(&details)); |
Jeff Fisher | 709b4c5 | 2019-07-29 20:07:34 | [diff] [blame] | 6881 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 6882 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6883 | observer->OnFocusChangedInPage(&details); |
| 6884 | }); |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 6885 | } |
| 6886 | |
Lowell Manners | 1de5242e | 2019-04-25 10:18:46 | [diff] [blame] | 6887 | bool WebContentsImpl::DidAddMessageToConsole( |
| 6888 | blink::mojom::ConsoleMessageLevel log_level, |
| 6889 | const base::string16& message, |
| 6890 | int32_t line_no, |
| 6891 | const base::string16& source_id) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 6892 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6893 | observer->OnDidAddMessageToConsole(log_level, message, line_no, source_id); |
| 6894 | }); |
[email protected] | a796f20 | 2012-05-30 14:14:25 | [diff] [blame] | 6895 | if (!delegate_) |
| 6896 | return false; |
Lowell Manners | 1de5242e | 2019-04-25 10:18:46 | [diff] [blame] | 6897 | return delegate_->DidAddMessageToConsole(this, log_level, message, line_no, |
avi | a90ae4e | 2016-11-11 20:49:33 | [diff] [blame] | 6898 | source_id); |
[email protected] | a796f20 | 2012-05-30 14:14:25 | [diff] [blame] | 6899 | } |
| 6900 | |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 6901 | void WebContentsImpl::DidReceiveInputEvent( |
dominickn | 9c7ceaa3 | 2016-02-27 01:52:53 | [diff] [blame] | 6902 | RenderWidgetHostImpl* render_widget_host, |
Emily Stark | c7bd40c4 | 2020-07-21 19:12:55 | [diff] [blame] | 6903 | const blink::WebInputEvent& event) { |
| 6904 | if (!IsUserInteractionInputType(event.GetType())) |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 6905 | return; |
| 6906 | |
kenrb | 1922185 | 2016-04-29 17:21:40 | [diff] [blame] | 6907 | // Ignore unless the widget is currently in the frame tree. |
| 6908 | if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host)) |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 6909 | return; |
| 6910 | |
Emily Stark | c7bd40c4 | 2020-07-21 19:12:55 | [diff] [blame] | 6911 | if (event.GetType() != blink::WebInputEvent::Type::kGestureScrollBegin) |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 6912 | last_interactive_input_event_time_ = ui::EventTimeForNow(); |
dominickn | 9c7ceaa3 | 2016-02-27 01:52:53 | [diff] [blame] | 6913 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 6914 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6915 | observer->DidGetUserInteraction(event); |
| 6916 | }); |
dominickn | 2dd142dd | 2015-10-29 05:30:50 | [diff] [blame] | 6917 | } |
| 6918 | |
Avi Drissman | 738ea19 | 2018-08-29 20:24:16 | [diff] [blame] | 6919 | bool WebContentsImpl::ShouldIgnoreInputEvents() { |
| 6920 | WebContentsImpl* web_contents = this; |
| 6921 | while (web_contents) { |
| 6922 | if (web_contents->ignore_input_events_) |
| 6923 | return true; |
| 6924 | web_contents = web_contents->GetOuterWebContents(); |
| 6925 | } |
| 6926 | |
| 6927 | return false; |
| 6928 | } |
| 6929 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 6930 | void WebContentsImpl::FocusOwningWebContents( |
| 6931 | RenderWidgetHostImpl* render_widget_host) { |
Alex Moshchuk | c4f0a72 | 2019-11-19 22:41:28 | [diff] [blame] | 6932 | RenderWidgetHostImpl* main_frame_widget_host = |
| 6933 | GetMainFrame()->GetRenderWidgetHost(); |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 6934 | RenderWidgetHostImpl* focused_widget = |
Alex Moshchuk | c4f0a72 | 2019-11-19 22:41:28 | [diff] [blame] | 6935 | GetFocusedRenderWidgetHost(main_frame_widget_host); |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 6936 | |
| 6937 | if (focused_widget != render_widget_host && |
avallee | 8e88159 | 2016-11-19 00:39:30 | [diff] [blame] | 6938 | (!focused_widget || |
| 6939 | focused_widget->delegate() != render_widget_host->delegate())) { |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 6940 | SetAsFocusedWebContentsIfNecessary(); |
| 6941 | } |
| 6942 | } |
| 6943 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 6944 | void WebContentsImpl::OnIgnoredUIEvent() { |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 6945 | // Notify observers. |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 6946 | observers_.ForEachObserver( |
| 6947 | [&](WebContentsObserver* observer) { observer->DidGetIgnoredUIEvent(); }); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 6948 | } |
| 6949 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 6950 | void WebContentsImpl::RendererUnresponsive( |
Lukasz Anforowicz | 52b9372 | 2018-06-20 16:11:39 | [diff] [blame] | 6951 | RenderWidgetHostImpl* render_widget_host, |
| 6952 | base::RepeatingClosure hang_monitor_restarter) { |
avi | c031d39 | 2017-03-03 03:09:42 | [diff] [blame] | 6953 | if (ShouldIgnoreUnresponsiveRenderer()) |
[email protected] | e5fc163 | 2011-08-08 07:51:53 | [diff] [blame] | 6954 | return; |
| 6955 | |
Lukasz Anforowicz | 4f0593d | 2018-09-21 18:33:54 | [diff] [blame] | 6956 | // Do not report hangs (to task manager, to hang renderer dialog, etc.) for |
| 6957 | // invisible tabs (like extension background page, background tabs). See |
| 6958 | // https://crbug.com/881812 for rationale and for choosing the visibility |
| 6959 | // (rather than process priority) as the signal here. |
| 6960 | if (GetVisibility() != Visibility::VISIBLE) |
| 6961 | return; |
| 6962 | |
Avi Drissman | 8920def | 2018-01-31 19:53:36 | [diff] [blame] | 6963 | if (!render_widget_host->renderer_initialized()) |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 6964 | return; |
| 6965 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 6966 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6967 | observer->OnRendererUnresponsive(render_widget_host->GetProcess()); |
| 6968 | }); |
Dave Tapuska | c6146c5 | 2017-12-20 22:48:15 | [diff] [blame] | 6969 | if (delegate_) |
Lukasz Anforowicz | 52b9372 | 2018-06-20 16:11:39 | [diff] [blame] | 6970 | delegate_->RendererUnresponsive(this, render_widget_host, |
| 6971 | std::move(hang_monitor_restarter)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6972 | } |
| 6973 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 6974 | void WebContentsImpl::RendererResponsive( |
| 6975 | RenderWidgetHostImpl* render_widget_host) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 6976 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 6977 | observer->OnRendererResponsive(render_widget_host->GetProcess()); |
| 6978 | }); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 6979 | if (delegate_) |
Avi Drissman | 1572e8c3c | 2018-02-02 19:06:36 | [diff] [blame] | 6980 | delegate_->RendererResponsive(this, render_widget_host); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6981 | } |
| 6982 | |
Alex Moshchuk | 7b4f065 | 2019-05-30 18:54:41 | [diff] [blame] | 6983 | void WebContentsImpl::SubframeCrashed( |
| 6984 | blink::mojom::FrameVisibility visibility) { |
| 6985 | // If a subframe crashed on a hidden tab, mark the tab for reload to avoid |
| 6986 | // showing a sad frame to the user if they ever switch back to that tab. Do |
| 6987 | // this for subframes that are either visible in viewport or visible but |
| 6988 | // scrolled out of view, but skip subframes that are not rendered (e.g., via |
| 6989 | // "display:none"), since in that case the user wouldn't see a sad frame |
| 6990 | // anyway. |
| 6991 | bool did_mark_for_reload = false; |
| 6992 | if (IsHidden() && visibility != blink::mojom::FrameVisibility::kNotRendered && |
| 6993 | base::FeatureList::IsEnabled( |
| 6994 | features::kReloadHiddenTabsWithCrashedSubframes)) { |
| 6995 | controller_.SetNeedsReload( |
| 6996 | NavigationControllerImpl::NeedsReloadType::kCrashedSubframe); |
| 6997 | did_mark_for_reload = true; |
| 6998 | UMA_HISTOGRAM_ENUMERATION( |
| 6999 | "Stability.ChildFrameCrash.TabMarkedForReload.Visibility", visibility); |
| 7000 | } |
| 7001 | |
| 7002 | UMA_HISTOGRAM_BOOLEAN("Stability.ChildFrameCrash.TabMarkedForReload", |
| 7003 | did_mark_for_reload); |
| 7004 | } |
| 7005 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 7006 | void WebContentsImpl::BeforeUnloadFiredFromRenderManager( |
[email protected] | feaded0 | 2012-09-25 19:12:55 | [diff] [blame] | 7007 | bool proceed, const base::TimeTicks& proceed_time, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7008 | bool* proceed_to_fire_unload) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 7009 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7010 | observer->BeforeUnloadFired(proceed, proceed_time); |
| 7011 | }); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 7012 | if (delegate_) |
| 7013 | delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload); |
[email protected] | e80af49 | 2013-06-24 21:52:09 | [diff] [blame] | 7014 | // Note: |this| might be deleted at this point. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7015 | } |
| 7016 | |
[email protected] | 58d5cfe | 2013-07-10 02:40:52 | [diff] [blame] | 7017 | void WebContentsImpl::RenderProcessGoneFromRenderManager( |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 7018 | RenderViewHost* render_view_host) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 7019 | DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING); |
[email protected] | ec6a7eb | 2013-04-22 17:34:22 | [diff] [blame] | 7020 | RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 7021 | } |
| 7022 | |
[email protected] | af90590 | 2013-10-01 21:38:51 | [diff] [blame] | 7023 | void WebContentsImpl::CancelModalDialogsForRenderManager() { |
| 7024 | // We need to cancel modal dialogs when doing a process swap, since the load |
avi | 2460c76 | 2015-04-17 15:21:54 | [diff] [blame] | 7025 | // deferrer would prevent us from swapping out. We also clear the state |
| 7026 | // because this is a cross-process navigation, which means that it's a new |
| 7027 | // site that should not have to pay for the sins of its predecessor. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 7028 | // |
Lei Zhang | 6410ec1a | 2019-01-31 21:38:58 | [diff] [blame] | 7029 | // Note that we don't bother telling |browser_plugin_embedder_| because the |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 7030 | // cross-process navigation will either destroy the browser plugins or not |
| 7031 | // require their dialogs to close. |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 7032 | if (dialog_manager_) { |
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 7033 | dialog_manager_->CancelDialogs(this, /*reset_state=*/true); |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 7034 | } |
[email protected] | af90590 | 2013-10-01 21:38:51 | [diff] [blame] | 7035 | } |
| 7036 | |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7037 | void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_frame, |
| 7038 | RenderFrameHost* new_frame, |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 7039 | bool is_main_frame) { |
| 7040 | if (is_main_frame) { |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7041 | // The |new_frame| and its various compadres are already swapped into place |
| 7042 | // for the WebContentsImpl when this method is called. |
| 7043 | DCHECK(GetMainFrame() == new_frame); |
| 7044 | DCHECK(GetRenderViewHost() == new_frame->GetRenderViewHost()); |
| 7045 | DCHECK(GetRenderWidgetHostView() == new_frame->GetView()); |
| 7046 | |
Fergal Daly | 6767b2e | 2020-02-04 03:15:16 | [diff] [blame] | 7047 | RenderViewHost* old_rvh = |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7048 | old_frame ? old_frame->GetRenderViewHost() : nullptr; |
| 7049 | RenderViewHost* new_rvh = new_frame->GetRenderViewHost(); |
Fergal Daly | 6767b2e | 2020-02-04 03:15:16 | [diff] [blame] | 7050 | // |old_rvh| and |new_rvh| might be equal when navigating from a crashed |
| 7051 | // RenderFrameHost to a new same-site one. With RenderDocument, this will |
| 7052 | // happen for every same-site navigation. |
| 7053 | if (old_rvh != new_rvh) |
| 7054 | NotifyViewSwapped(old_rvh, new_rvh); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 7055 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 7056 | // Make sure the visible RVH reflects the new delegate's preferences. |
| 7057 | if (delegate_) |
| 7058 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | d56a49e | 2013-02-23 00:47:39 | [diff] [blame] | 7059 | |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7060 | auto* rwhv = static_cast<RenderWidgetHostViewBase*>(new_frame->GetView()); |
| 7061 | if (rwhv) { |
| 7062 | rwhv->SetMainFrameAXTreeID(new_frame->GetAXTreeID()); |
| 7063 | |
| 7064 | // The RenderWidgetHostView for the speculative RenderFrameHost is not |
| 7065 | // resized with the current RenderFrameHost while a navigation is |
| 7066 | // pending. So when we swap in the main frame, we need to update the |
| 7067 | // RenderWidgetHostView's size. |
| 7068 | // |
| 7069 | // Historically, this was done to fix b/1079768 for interstitials. |
| 7070 | rwhv->SetSize(GetSizeForMainFrame()); |
| 7071 | } |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 7072 | } |
| 7073 | |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7074 | NotifyFrameSwapped(old_frame, new_frame, is_main_frame); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 7075 | } |
| 7076 | |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 7077 | void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager( |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7078 | RenderFrameHost* old_frame, |
| 7079 | RenderFrameHost* new_frame) { |
| 7080 | NotifyViewSwapped(old_frame ? old_frame->GetRenderViewHost() : nullptr, |
| 7081 | new_frame->GetRenderViewHost()); |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 7082 | } |
| 7083 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 7084 | NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() { |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 7085 | return GetController(); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 7086 | } |
| 7087 | |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 7088 | std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost( |
Miyoung Shin | 072d405 | 2020-07-13 07:52:44 | [diff] [blame] | 7089 | RenderFrameHost* frame_host, |
Denis Kuznetsov [CET] | 2c6f0159f | 2020-05-18 14:18:16 | [diff] [blame] | 7090 | const GURL& url) { |
Miyoung Shin | 072d405 | 2020-07-13 07:52:44 | [diff] [blame] | 7091 | return CreateWebUI(frame_host, url); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7092 | } |
| 7093 | |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 7094 | void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager( |
| 7095 | RenderViewHost* render_view_host) { |
lfg | c740d4b2 | 2016-04-15 16:45:33 | [diff] [blame] | 7096 | RenderWidgetHostViewBase* rwh_view = |
W. James MacLean | 13d834d | 2019-12-04 16:06:45 | [diff] [blame] | 7097 | view_->CreateViewForWidget(render_view_host->GetWidget()); |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7098 | rwh_view->SetSize(GetSizeForMainFrame()); |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 7099 | } |
| 7100 | |
| 7101 | bool WebContentsImpl::CreateRenderViewForRenderManager( |
| 7102 | RenderViewHost* render_view_host, |
Antonio Gomes | b3dd5fc | 2020-05-25 22:53:27 | [diff] [blame] | 7103 | const base::Optional<base::UnguessableToken>& opener_frame_token, |
Daniel Cheng | abfdb00 | 2020-06-04 06:02:30 | [diff] [blame] | 7104 | int proxy_routing_id) { |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 7105 | TRACE_EVENT0("browser,navigation", |
| 7106 | "WebContentsImpl::CreateRenderViewForRenderManager"); |
| 7107 | |
piman | 00cf940 | 2017-04-03 17:09:20 | [diff] [blame] | 7108 | if (proxy_routing_id == MSG_ROUTING_NONE) |
lfg | 9431efd | 2016-12-14 14:45:26 | [diff] [blame] | 7109 | CreateRenderWidgetHostViewForRenderManager(render_view_host); |
lfg | 9431efd | 2016-12-14 14:45:26 | [diff] [blame] | 7110 | |
piman | 00cf940 | 2017-04-03 17:09:20 | [diff] [blame] | 7111 | if (!static_cast<RenderViewHostImpl*>(render_view_host) |
Daniel Cheng | abfdb00 | 2020-06-04 06:02:30 | [diff] [blame] | 7112 | ->CreateRenderView(opener_frame_token, proxy_routing_id, |
Antonio Gomes | b3dd5fc | 2020-05-25 22:53:27 | [diff] [blame] | 7113 | created_with_opener_)) { |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 7114 | return false; |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 7115 | } |
W. James MacLean | 6219867 | 2019-06-04 16:46:10 | [diff] [blame] | 7116 | // Set the TextAutosizer state from the main frame's renderer on the new view, |
| 7117 | // but only if it's not for the main frame. Main frame renderers should create |
| 7118 | // this state themselves from up-to-date values, so we shouldn't override it |
| 7119 | // with the cached values. |
| 7120 | if (!render_view_host->GetMainFrame()) { |
Antonio Gomes | da7e03d | 2020-08-05 15:03:08 | [diff] [blame] | 7121 | auto* proxy_host = GetRenderManager()->GetRenderFrameProxyHost( |
| 7122 | render_view_host->GetSiteInstance()); |
| 7123 | proxy_host->GetAssociatedRemoteMainFrame()->UpdateTextAutosizerPageInfo( |
| 7124 | text_autosizer_page_info_.Clone()); |
W. James MacLean | 6219867 | 2019-06-04 16:46:10 | [diff] [blame] | 7125 | } |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 7126 | |
Lucas Furukawa Gadani | aed1fed | 2017-10-13 17:34:14 | [diff] [blame] | 7127 | if (proxy_routing_id == MSG_ROUTING_NONE && node_.outer_web_contents()) |
| 7128 | ReattachToOuterWebContentsFrame(); |
| 7129 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 7130 | SetHistoryOffsetAndLengthForView(render_view_host, |
| 7131 | controller_.GetLastCommittedEntryIndex(), |
| 7132 | controller_.GetEntryCount()); |
| 7133 | |
Avi Drissman | 7c57be7 | 2020-07-29 20:09:46 | [diff] [blame] | 7134 | #if defined(OS_POSIX) && !defined(OS_MAC) && !defined(OS_ANDROID) |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 7135 | // Force a ViewMsg_Resize to be sent, needed to make plugins show up on |
| 7136 | // linux. See crbug.com/83941. |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 7137 | RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView(); |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 7138 | if (rwh_view) { |
| 7139 | if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost()) |
Fady Samuel | 0b91182 | 2018-04-25 13:22:16 | [diff] [blame] | 7140 | render_widget_host->SynchronizeVisualProperties(); |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 7141 | } |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 7142 | #endif |
| 7143 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 7144 | return true; |
| 7145 | } |
| 7146 | |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 7147 | bool WebContentsImpl::CreateRenderFrameForRenderManager( |
| 7148 | RenderFrameHost* render_frame_host, |
arthursonzogni | 1efc7b96 | 2019-03-14 09:36:33 | [diff] [blame] | 7149 | int previous_routing_id, |
Antonio Gomes | 9d15054 | 2020-05-25 18:32:11 | [diff] [blame] | 7150 | const base::Optional<base::UnguessableToken>& opener_frame_token, |
japhet | e6adf14 | 2014-10-31 00:01:49 | [diff] [blame] | 7151 | int parent_routing_id, |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 7152 | int previous_sibling_routing_id) { |
nasko | b8744d2 | 2014-08-28 17:07:43 | [diff] [blame] | 7153 | TRACE_EVENT0("browser,navigation", |
| 7154 | "WebContentsImpl::CreateRenderFrameForRenderManager"); |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 7155 | |
| 7156 | RenderFrameHostImpl* rfh = |
| 7157 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
Antonio Gomes | 9d15054 | 2020-05-25 18:32:11 | [diff] [blame] | 7158 | if (!rfh->CreateRenderFrame(previous_routing_id, opener_frame_token, |
| 7159 | parent_routing_id, previous_sibling_routing_id)) { |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 7160 | return false; |
Antonio Gomes | 9d15054 | 2020-05-25 18:32:11 | [diff] [blame] | 7161 | } |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 7162 | |
| 7163 | // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed |
| 7164 | // RenderFrameHost will have to be associated with the appropriate |
| 7165 | // RenderWidgetHostView or a new one should be created here. |
| 7166 | |
| 7167 | return true; |
| 7168 | } |
| 7169 | |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 7170 | #if defined(OS_ANDROID) |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 7171 | |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 7172 | base::android::ScopedJavaLocalRef<jobject> |
| 7173 | WebContentsImpl::GetJavaWebContents() { |
mostynb | 042582e | 2015-03-16 22:13:40 | [diff] [blame] | 7174 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 0e813a5 | 2014-08-13 10:34:56 | [diff] [blame] | 7175 | return GetWebContentsAndroid()->GetJavaObject(); |
| 7176 | } |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 7177 | |
[email protected] | 0e813a5 | 2014-08-13 10:34:56 | [diff] [blame] | 7178 | WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() { |
Kevin McNee | 576bb5d8 | 2019-05-29 16:47:51 | [diff] [blame] | 7179 | if (!web_contents_android_) { |
| 7180 | web_contents_android_ = std::make_unique<WebContentsAndroid>(this); |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 7181 | } |
Kevin McNee | 576bb5d8 | 2019-05-29 16:47:51 | [diff] [blame] | 7182 | return web_contents_android_.get(); |
| 7183 | } |
| 7184 | |
| 7185 | void WebContentsImpl::ClearWebContentsAndroid() { |
| 7186 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 7187 | web_contents_android_.reset(); |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 7188 | } |
| 7189 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 7190 | void WebContentsImpl::ActivateNearestFindResult(float x, |
| 7191 | float y) { |
| 7192 | GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y); |
| 7193 | } |
| 7194 | |
| 7195 | void WebContentsImpl::RequestFindMatchRects(int current_version) { |
| 7196 | GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version); |
| 7197 | } |
| 7198 | |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 7199 | service_manager::InterfaceProvider* WebContentsImpl::GetJavaInterfaces() { |
sammc | f5f1b0f | 2016-09-20 23:05:11 | [diff] [blame] | 7200 | if (!java_interfaces_) { |
Gyuyoung Kim | 6c9ce902 | 2019-11-26 05:40:08 | [diff] [blame] | 7201 | mojo::PendingRemote<service_manager::mojom::InterfaceProvider> provider; |
| 7202 | BindInterfaceRegistryForWebContents( |
| 7203 | provider.InitWithNewPipeAndPassReceiver(), this); |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 7204 | java_interfaces_.reset(new service_manager::InterfaceProvider); |
sammc | f5f1b0f | 2016-09-20 23:05:11 | [diff] [blame] | 7205 | java_interfaces_->Bind(std::move(provider)); |
| 7206 | } |
| 7207 | return java_interfaces_.get(); |
| 7208 | } |
| 7209 | |
Francois Doray | 6c26f334 | 2018-08-24 17:17:22 | [diff] [blame] | 7210 | #endif |
| 7211 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 7212 | bool WebContentsImpl::CompletedFirstVisuallyNonEmptyPaint() { |
Carlos Caballero | 91fffb2 | 2019-10-29 15:24:30 | [diff] [blame] | 7213 | return GetRenderViewHost()->did_first_visually_non_empty_paint(); |
spqchan | e72c3cb | 2017-06-30 23:02:10 | [diff] [blame] | 7214 | } |
| 7215 | |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 7216 | void WebContentsImpl::OnDidDownloadImage( |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 7217 | ImageDownloadCallback callback, |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 7218 | int id, |
| 7219 | const GURL& image_url, |
leon.han | cbc4bc3c | 2016-02-26 07:08:52 | [diff] [blame] | 7220 | int32_t http_status_code, |
leon.han | c222853 | 2016-08-16 05:59:18 | [diff] [blame] | 7221 | const std::vector<SkBitmap>& images, |
| 7222 | const std::vector<gfx::Size>& original_image_sizes) { |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 7223 | std::move(callback).Run(id, http_status_code, image_url, images, |
| 7224 | original_image_sizes); |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 7225 | } |
| 7226 | |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 7227 | void WebContentsImpl::OnDialogClosed(int render_process_id, |
| 7228 | int render_frame_id, |
Dave Tapuska | cdf545cc | 2020-01-23 18:38:52 | [diff] [blame] | 7229 | JavaScriptDialogCallback response_callback, |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 7230 | base::ScopedClosureRunner fullscreen_block, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 7231 | bool dialog_was_suppressed, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 7232 | bool success, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 7233 | const base::string16& user_input) { |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 7234 | RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id, |
| 7235 | render_frame_id); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 7236 | last_dialog_suppressed_ = dialog_was_suppressed; |
Avi Drissman | 1a55a9d6 | 2020-03-10 18:56:45 | [diff] [blame] | 7237 | fullscreen_block.RunAndReset(); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 7238 | |
Charlie Reis | 9607736 | 2019-07-04 00:34:04 | [diff] [blame] | 7239 | javascript_dialog_navigation_deferrer_.reset(); |
| 7240 | |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 7241 | if (is_showing_before_unload_dialog_ && !success) { |
clamy | bc6f415 | 2016-04-01 20:14:23 | [diff] [blame] | 7242 | // It is possible for the current RenderFrameHost to have changed in the |
| 7243 | // meantime. Do not reset the navigation state in that case. |
| 7244 | if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) { |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 7245 | rfh->frame_tree_node()->BeforeUnloadCanceled(); |
clamy | bc6f415 | 2016-04-01 20:14:23 | [diff] [blame] | 7246 | controller_.DiscardNonCommittedEntries(); |
| 7247 | } |
[email protected] | ec8e8b0 | 2013-06-19 04:57:10 | [diff] [blame] | 7248 | |
Charles Reis | 15d60b13 | 2017-11-03 17:43:47 | [diff] [blame] | 7249 | // Update the URL display either way, to avoid showing a stale URL. |
| 7250 | NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
| 7251 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 7252 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7253 | observer->BeforeUnloadDialogCancelled(); |
| 7254 | }); |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 7255 | } |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 7256 | |
Dave Tapuska | cdf545cc | 2020-01-23 18:38:52 | [diff] [blame] | 7257 | std::move(response_callback).Run(success, user_input); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 7258 | |
Dave Tapuska | cdf545cc | 2020-01-23 18:38:52 | [diff] [blame] | 7259 | std::vector<protocol::PageHandler*> page_handlers = |
| 7260 | protocol::PageHandler::EnabledForWebContents(this); |
| 7261 | for (auto* handler : page_handlers) |
| 7262 | handler->DidCloseJavaScriptDialog(success, user_input); |
avi | 1c51fb6 | 2017-02-27 20:43:03 | [diff] [blame] | 7263 | |
| 7264 | is_showing_javascript_dialog_ = false; |
| 7265 | is_showing_before_unload_dialog_ = false; |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 7266 | } |
| 7267 | |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 7268 | bool WebContentsImpl::IsHidden() { |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 7269 | return !IsBeingCaptured() && visibility_ != Visibility::VISIBLE; |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 7270 | } |
| 7271 | |
rob | 9725074 | 2015-12-10 17:45:15 | [diff] [blame] | 7272 | int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() { |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 7273 | return node_.outer_contents_frame_tree_node_id(); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 7274 | } |
| 7275 | |
ekaramad | aeb3c5c | 2016-11-09 03:22:35 | [diff] [blame] | 7276 | RenderWidgetHostImpl* WebContentsImpl::GetFullscreenRenderWidgetHost() const { |
| 7277 | return RenderWidgetHostImpl::FromID(fullscreen_widget_process_id_, |
| 7278 | fullscreen_widget_routing_id_); |
| 7279 | } |
| 7280 | |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 7281 | RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 7282 | return frame_tree_.root()->render_manager(); |
| 7283 | } |
| 7284 | |
[email protected] | f849734 | 2013-02-05 22:15:02 | [diff] [blame] | 7285 | BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 7286 | return browser_plugin_guest_.get(); |
| 7287 | } |
| 7288 | |
Albert J. Wong | c55cc64d | 2018-10-12 02:50:04 | [diff] [blame] | 7289 | void WebContentsImpl::SetBrowserPluginGuest( |
| 7290 | std::unique_ptr<BrowserPluginGuest> guest) { |
| 7291 | DCHECK(!browser_plugin_guest_); |
| 7292 | DCHECK(guest); |
| 7293 | browser_plugin_guest_ = std::move(guest); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 7294 | } |
| 7295 | |
Aidan Wolter | 52bcc12a | 2018-11-14 03:27:29 | [diff] [blame] | 7296 | base::UnguessableToken WebContentsImpl::GetAudioGroupId() { |
Aidan Wolter | 52bcc12a | 2018-11-14 03:27:29 | [diff] [blame] | 7297 | return GetAudioStreamFactory()->group_id(); |
| 7298 | } |
| 7299 | |
Miyoung Shin | 5709ab0 | 2020-02-19 06:50:41 | [diff] [blame] | 7300 | const std::vector<blink::mojom::FaviconURLPtr>& |
| 7301 | WebContentsImpl::GetFaviconURLs() { |
Mounir Lamouri | 7b4a1f23 | 2019-12-23 16:32:10 | [diff] [blame] | 7302 | return favicon_urls_; |
| 7303 | } |
| 7304 | |
Mugdha Lakhani | 0a0d786 | 2020-07-29 09:58:45 | [diff] [blame] | 7305 | // The Mac implementation of the next two methods is in |
| 7306 | // web_contents_impl_mac.mm |
Avi Drissman | d4d79f7 | 2020-07-30 18:35:18 | [diff] [blame] | 7307 | #if !defined(OS_MAC) |
Mugdha Lakhani | 0a0d786 | 2020-07-29 09:58:45 | [diff] [blame] | 7308 | |
| 7309 | void WebContentsImpl::Resize(const gfx::Rect& new_bounds) { |
| 7310 | #if defined(USE_AURA) |
| 7311 | aura::Window* window = GetNativeView(); |
| 7312 | window->SetBounds(gfx::Rect(window->bounds().origin(), new_bounds.size())); |
| 7313 | #elif defined(OS_ANDROID) |
| 7314 | content::RenderWidgetHostView* view = GetRenderWidgetHostView(); |
| 7315 | if (view) |
| 7316 | view->SetBounds(new_bounds); |
| 7317 | #endif |
| 7318 | } |
| 7319 | |
| 7320 | gfx::Size WebContentsImpl::GetSize() { |
| 7321 | #if defined(USE_AURA) |
| 7322 | aura::Window* window = GetNativeView(); |
| 7323 | return window->bounds().size(); |
| 7324 | #elif defined(OS_ANDROID) |
| 7325 | ui::ViewAndroid* view_android = GetNativeView(); |
| 7326 | return view_android->bounds().size(); |
| 7327 | #endif |
| 7328 | } |
| 7329 | |
Avi Drissman | d4d79f7 | 2020-07-30 18:35:18 | [diff] [blame] | 7330 | #endif // !defined(OS_MAC) |
Mugdha Lakhani | 0a0d786 | 2020-07-29 09:58:45 | [diff] [blame] | 7331 | |
[email protected] | f849734 | 2013-02-05 22:15:02 | [diff] [blame] | 7332 | BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 7333 | return browser_plugin_embedder_.get(); |
| 7334 | } |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 7335 | |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 7336 | void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { |
| 7337 | if (browser_plugin_embedder_) |
| 7338 | return; |
| 7339 | browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this)); |
| 7340 | } |
| 7341 | |
danakj | a0bce4c95 | 2020-05-12 20:40:28 | [diff] [blame] | 7342 | gfx::Size WebContentsImpl::GetSizeForMainFrame() { |
| 7343 | if (delegate_) { |
| 7344 | // The delegate has a chance to specify a size independent of the UI. |
| 7345 | gfx::Size delegate_size = delegate_->GetSizeForNewRenderView(this); |
| 7346 | if (!delegate_size.IsEmpty()) |
| 7347 | return delegate_size; |
| 7348 | } |
| 7349 | |
| 7350 | // Device emulation, when enabled, can specify a size independent of the UI. |
| 7351 | if (!device_emulation_size_.IsEmpty()) |
| 7352 | return device_emulation_size_; |
| 7353 | |
| 7354 | return GetContainerBounds().size(); |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 7355 | } |
| 7356 | |
[email protected] | ae7eeda | 2014-07-04 01:53:26 | [diff] [blame] | 7357 | void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 7358 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7359 | observer->FrameDeleted(render_frame_host); |
| 7360 | }); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 7361 | } |
| 7362 | |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 7363 | void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
| 7364 | if (!delegate_) |
| 7365 | return; |
| 7366 | const gfx::Size new_size = GetPreferredSize(); |
| 7367 | if (new_size != old_size) |
| 7368 | delegate_->UpdatePreferredSize(this, new_size); |
| 7369 | } |
| 7370 | |
Miyoung Shin | 072d405 | 2020-07-13 07:52:44 | [diff] [blame] | 7371 | std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUI( |
| 7372 | RenderFrameHost* frame_host, |
| 7373 | const GURL& url) { |
| 7374 | std::unique_ptr<WebUIImpl> web_ui = |
| 7375 | std::make_unique<WebUIImpl>(this, frame_host); |
Lei Zhang | ee3b63ad | 2018-06-06 23:25:31 | [diff] [blame] | 7376 | std::unique_ptr<WebUIController> controller( |
avi | e865b1d | 2016-10-24 19:42:59 | [diff] [blame] | 7377 | WebUIControllerFactoryRegistry::GetInstance() |
Lei Zhang | ee3b63ad | 2018-06-06 23:25:31 | [diff] [blame] | 7378 | ->CreateWebUIControllerForURL(web_ui.get(), url)); |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 7379 | if (controller) { |
Lei Zhang | ee3b63ad | 2018-06-06 23:25:31 | [diff] [blame] | 7380 | web_ui->SetController(std::move(controller)); |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 7381 | return web_ui; |
| 7382 | } |
| 7383 | |
avi | e865b1d | 2016-10-24 19:42:59 | [diff] [blame] | 7384 | return nullptr; |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 7385 | } |
| 7386 | |
Lucas Furukawa Gadani | e1c5dfda | 2018-11-29 17:57:41 | [diff] [blame] | 7387 | FindRequestManager* WebContentsImpl::GetFindRequestManager() { |
| 7388 | for (auto* contents = this; contents; |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 7389 | contents = contents->GetOuterWebContents()) { |
| 7390 | if (contents->find_request_manager_) |
| 7391 | return contents->find_request_manager_.get(); |
| 7392 | } |
| 7393 | |
| 7394 | return nullptr; |
| 7395 | } |
| 7396 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 7397 | FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() { |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 7398 | if (FindRequestManager* manager = GetFindRequestManager()) |
| 7399 | return manager; |
| 7400 | |
Ehsan Karamad | 6beb2ea | 2018-11-25 18:15:13 | [diff] [blame] | 7401 | DCHECK(!browser_plugin_guest_ || GetOuterWebContents()); |
| 7402 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 7403 | // No existing FindRequestManager found, so one must be created. |
| 7404 | find_request_manager_.reset(new FindRequestManager(this)); |
| 7405 | |
| 7406 | // Concurrent find sessions must not overlap, so destroy any existing |
| 7407 | // FindRequestManagers in any inner WebContentses. |
Lucas Furukawa Gadani | 2ec00c8 | 2018-12-14 15:53:16 | [diff] [blame] | 7408 | for (WebContents* contents : GetWebContentsAndAllInner()) { |
| 7409 | auto* web_contents_impl = static_cast<WebContentsImpl*>(contents); |
| 7410 | if (web_contents_impl == this) |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 7411 | continue; |
Lucas Furukawa Gadani | 2ec00c8 | 2018-12-14 15:53:16 | [diff] [blame] | 7412 | if (web_contents_impl->find_request_manager_) { |
| 7413 | web_contents_impl->find_request_manager_->StopFinding( |
| 7414 | STOP_FIND_ACTION_CLEAR_SELECTION); |
| 7415 | web_contents_impl->find_request_manager_.release(); |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 7416 | } |
| 7417 | } |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 7418 | |
| 7419 | return find_request_manager_.get(); |
| 7420 | } |
| 7421 | |
| 7422 | void WebContentsImpl::NotifyFindReply(int request_id, |
| 7423 | int number_of_matches, |
| 7424 | const gfx::Rect& selection_rect, |
| 7425 | int active_match_ordinal, |
| 7426 | bool final_update) { |
Sebastien Marchand | cf97ed5 | 2017-07-24 23:50:34 | [diff] [blame] | 7427 | if (delegate_ && !is_being_destroyed_ && |
Lukasz Anforowicz | e9ae372 | 2017-09-29 17:37:38 | [diff] [blame] | 7428 | !GetMainFrame()->GetProcess()->FastShutdownStarted()) { |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 7429 | delegate_->FindReply(this, request_id, number_of_matches, selection_rect, |
| 7430 | active_match_ordinal, final_update); |
| 7431 | } |
| 7432 | } |
| 7433 | |
ortuno | 467e579 | 2016-06-10 04:32:39 | [diff] [blame] | 7434 | void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() { |
| 7435 | // Trying to invalidate the tab state while being destroyed could result in a |
| 7436 | // use after free. |
| 7437 | if (IsBeingDestroyed()) { |
| 7438 | return; |
| 7439 | } |
| 7440 | // Notify for UI updates if the state changes. |
| 7441 | bluetooth_connected_device_count_++; |
| 7442 | if (bluetooth_connected_device_count_ == 1) { |
Francois Doray | 66766a57 | 2019-12-17 20:56:49 | [diff] [blame] | 7443 | OnIsConnectedToBluetoothDeviceChanged(true); |
ortuno | 467e579 | 2016-06-10 04:32:39 | [diff] [blame] | 7444 | } |
| 7445 | } |
| 7446 | |
| 7447 | void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() { |
| 7448 | // Trying to invalidate the tab state while being destroyed could result in a |
| 7449 | // use after free. |
| 7450 | if (IsBeingDestroyed()) { |
| 7451 | return; |
| 7452 | } |
| 7453 | // Notify for UI updates if the state changes. |
Lukasz Anforowicz | e9ae372 | 2017-09-29 17:37:38 | [diff] [blame] | 7454 | DCHECK_NE(bluetooth_connected_device_count_, 0u); |
ortuno | 467e579 | 2016-06-10 04:32:39 | [diff] [blame] | 7455 | bluetooth_connected_device_count_--; |
| 7456 | if (bluetooth_connected_device_count_ == 0) { |
Francois Doray | 66766a57 | 2019-12-17 20:56:49 | [diff] [blame] | 7457 | OnIsConnectedToBluetoothDeviceChanged(false); |
| 7458 | } |
| 7459 | } |
| 7460 | |
| 7461 | void WebContentsImpl::OnIsConnectedToBluetoothDeviceChanged( |
| 7462 | bool is_connected_to_bluetooth_device) { |
| 7463 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 7464 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7465 | observer->OnIsConnectedToBluetoothDeviceChanged( |
Francois Doray | 66766a57 | 2019-12-17 20:56:49 | [diff] [blame] | 7466 | is_connected_to_bluetooth_device); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 7467 | }); |
ortuno | 467e579 | 2016-06-10 04:32:39 | [diff] [blame] | 7468 | } |
| 7469 | |
Ovidio Henriquez | 76696f6 | 2020-07-08 03:06:59 | [diff] [blame] | 7470 | void WebContentsImpl::IncrementBluetoothScanningSessionsCount() { |
| 7471 | // Trying to invalidate the tab state while being destroyed could result in a |
| 7472 | // use after free. |
| 7473 | if (IsBeingDestroyed()) |
| 7474 | return; |
| 7475 | |
| 7476 | // Notify for UI updates if the state changes. |
| 7477 | bluetooth_scanning_sessions_count_++; |
| 7478 | if (bluetooth_scanning_sessions_count_ == 1) |
| 7479 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 7480 | } |
| 7481 | |
| 7482 | void WebContentsImpl::DecrementBluetoothScanningSessionsCount() { |
| 7483 | // Trying to invalidate the tab state while being destroyed could result in a |
| 7484 | // use after free. |
| 7485 | if (IsBeingDestroyed()) |
| 7486 | return; |
| 7487 | |
| 7488 | DCHECK_NE(0u, bluetooth_scanning_sessions_count_); |
| 7489 | bluetooth_scanning_sessions_count_--; |
| 7490 | if (bluetooth_scanning_sessions_count_ == 0) |
| 7491 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 7492 | } |
| 7493 | |
Reilly Grant | 5e7c79b2 | 2019-04-09 17:26:20 | [diff] [blame] | 7494 | void WebContentsImpl::IncrementSerialActiveFrameCount() { |
| 7495 | // Trying to invalidate the tab state while being destroyed could result in a |
| 7496 | // use after free. |
| 7497 | if (IsBeingDestroyed()) |
| 7498 | return; |
| 7499 | |
| 7500 | // Notify for UI updates if the state changes. |
| 7501 | serial_active_frame_count_++; |
| 7502 | if (serial_active_frame_count_ == 1) |
| 7503 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 7504 | } |
| 7505 | |
| 7506 | void WebContentsImpl::DecrementSerialActiveFrameCount() { |
| 7507 | // Trying to invalidate the tab state while being destroyed could result in a |
| 7508 | // use after free. |
| 7509 | if (IsBeingDestroyed()) |
| 7510 | return; |
| 7511 | |
| 7512 | // Notify for UI updates if the state changes. |
| 7513 | DCHECK_NE(0u, serial_active_frame_count_); |
| 7514 | serial_active_frame_count_--; |
| 7515 | if (serial_active_frame_count_ == 0) |
| 7516 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 7517 | } |
| 7518 | |
Matt Reynolds | e8c6c1f | 2019-11-02 09:53:53 | [diff] [blame] | 7519 | void WebContentsImpl::IncrementHidActiveFrameCount() { |
| 7520 | // Trying to invalidate the tab state while being destroyed could result in a |
| 7521 | // use after free. |
| 7522 | if (IsBeingDestroyed()) |
| 7523 | return; |
| 7524 | |
| 7525 | // Notify for UI updates if the active frame count transitions from zero to |
| 7526 | // non-zero. |
| 7527 | hid_active_frame_count_++; |
| 7528 | if (hid_active_frame_count_ == 1) |
| 7529 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 7530 | } |
| 7531 | |
| 7532 | void WebContentsImpl::DecrementHidActiveFrameCount() { |
| 7533 | // Trying to invalidate the tab state while being destroyed could result in a |
| 7534 | // use after free. |
| 7535 | if (IsBeingDestroyed()) |
| 7536 | return; |
| 7537 | |
| 7538 | // Notify for UI updates if the active frame count transitions from non-zero |
| 7539 | // to zero. |
| 7540 | DCHECK_NE(0u, hid_active_frame_count_); |
| 7541 | hid_active_frame_count_--; |
| 7542 | if (hid_active_frame_count_ == 0) |
| 7543 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 7544 | } |
| 7545 | |
Marijn Kruisselbrink | 2905104 | 2019-08-06 22:56:55 | [diff] [blame] | 7546 | void WebContentsImpl::IncrementNativeFileSystemHandleCount() { |
| 7547 | // Trying to invalidate the tab state while being destroyed could result in a |
| 7548 | // use after free. |
| 7549 | if (IsBeingDestroyed()) |
| 7550 | return; |
| 7551 | |
| 7552 | // Notify for UI updates if the state changes. Need both TYPE_TAB and TYPE_URL |
| 7553 | // to update both the tab-level usage indicator and the usage indicator in the |
| 7554 | // omnibox. |
| 7555 | native_file_system_handle_count_++; |
| 7556 | if (native_file_system_handle_count_ == 1) { |
| 7557 | NotifyNavigationStateChanged(static_cast<content::InvalidateTypes>( |
| 7558 | INVALIDATE_TYPE_TAB | INVALIDATE_TYPE_URL)); |
| 7559 | } |
| 7560 | } |
| 7561 | |
| 7562 | void WebContentsImpl::DecrementNativeFileSystemHandleCount() { |
| 7563 | // Trying to invalidate the tab state while being destroyed could result in a |
| 7564 | // use after free. |
| 7565 | if (IsBeingDestroyed()) |
| 7566 | return; |
| 7567 | |
| 7568 | // Notify for UI updates if the state changes. Need both TYPE_TAB and TYPE_URL |
| 7569 | // to update both the tab-level usage indicator and the usage indicator in the |
| 7570 | // omnibox. |
| 7571 | DCHECK_NE(0u, native_file_system_handle_count_); |
| 7572 | native_file_system_handle_count_--; |
| 7573 | if (native_file_system_handle_count_ == 0) { |
| 7574 | NotifyNavigationStateChanged(static_cast<content::InvalidateTypes>( |
| 7575 | INVALIDATE_TYPE_TAB | INVALIDATE_TYPE_URL)); |
| 7576 | } |
| 7577 | } |
| 7578 | |
zqzhang | 8ac4900 | 2017-03-16 21:51:35 | [diff] [blame] | 7579 | void WebContentsImpl::SetHasPersistentVideo(bool has_persistent_video) { |
| 7580 | if (has_persistent_video_ == has_persistent_video) |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 7581 | return; |
| 7582 | |
zqzhang | 8ac4900 | 2017-03-16 21:51:35 | [diff] [blame] | 7583 | has_persistent_video_ = has_persistent_video; |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 7584 | NotifyPreferencesChanged(); |
zqzhang | 8ac4900 | 2017-03-16 21:51:35 | [diff] [blame] | 7585 | media_web_contents_observer()->RequestPersistentVideo(has_persistent_video); |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 7586 | } |
| 7587 | |
Ian Vollick | 5d5c37f | 2019-06-19 22:50:57 | [diff] [blame] | 7588 | void WebContentsImpl::SetSpatialNavigationDisabled(bool disabled) { |
| 7589 | if (is_spatial_navigation_disabled_ == disabled) |
| 7590 | return; |
| 7591 | |
| 7592 | is_spatial_navigation_disabled_ = disabled; |
| 7593 | NotifyPreferencesChanged(); |
| 7594 | } |
| 7595 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 7596 | void WebContentsImpl::BrowserPluginGuestWillDetach() { |
| 7597 | WebContentsImpl* outermost = GetOutermostWebContents(); |
| 7598 | if (this != outermost && ContainsOrIsFocusedWebContents()) |
| 7599 | outermost->SetAsFocusedWebContentsIfNecessary(); |
| 7600 | } |
| 7601 | |
Becca Hughes | 112832e | 2019-06-11 17:19:02 | [diff] [blame] | 7602 | PictureInPictureResult WebContentsImpl::EnterPictureInPicture( |
Mounir Lamouri | 11e9ef4 | 2018-05-22 03:10:16 | [diff] [blame] | 7603 | const viz::SurfaceId& surface_id, |
| 7604 | const gfx::Size& natural_size) { |
François Beaufort | f09e446 | 2019-01-18 14:34:51 | [diff] [blame] | 7605 | return delegate_ |
| 7606 | ? delegate_->EnterPictureInPicture(this, surface_id, natural_size) |
Becca Hughes | 112832e | 2019-06-11 17:19:02 | [diff] [blame] | 7607 | : PictureInPictureResult::kNotSupported; |
Mounir Lamouri | 11e9ef4 | 2018-05-22 03:10:16 | [diff] [blame] | 7608 | } |
| 7609 | |
Mounir Lamouri | 6d759e1 | 2018-05-16 20:01:30 | [diff] [blame] | 7610 | void WebContentsImpl::ExitPictureInPicture() { |
| 7611 | if (delegate_) |
| 7612 | delegate_->ExitPictureInPicture(); |
| 7613 | } |
| 7614 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 7615 | #if defined(OS_ANDROID) |
| 7616 | void WebContentsImpl::NotifyFindMatchRectsReply( |
| 7617 | int version, |
| 7618 | const std::vector<gfx::RectF>& rects, |
| 7619 | const gfx::RectF& active_rect) { |
| 7620 | if (delegate_) |
| 7621 | delegate_->FindMatchRectsReply(this, version, rects, active_rect); |
| 7622 | } |
| 7623 | #endif |
| 7624 | |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 7625 | void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 7626 | force_disable_overscroll_content_ = force_disable; |
| 7627 | if (view_) |
| 7628 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 7629 | } |
| 7630 | |
Jianzhou Feng | d8720c7 | 2018-01-18 03:06:30 | [diff] [blame] | 7631 | bool WebContentsImpl::SetDeviceEmulationSize(const gfx::Size& new_size) { |
| 7632 | device_emulation_size_ = new_size; |
| 7633 | RenderWidgetHostView* rwhv = GetMainFrame()->GetView(); |
| 7634 | |
| 7635 | const gfx::Size current_size = rwhv->GetViewBounds().size(); |
| 7636 | if (view_size_before_emulation_.IsEmpty()) |
| 7637 | view_size_before_emulation_ = current_size; |
| 7638 | |
| 7639 | if (current_size != new_size) |
| 7640 | rwhv->SetSize(new_size); |
| 7641 | |
| 7642 | return current_size != new_size; |
| 7643 | } |
| 7644 | |
| 7645 | void WebContentsImpl::ClearDeviceEmulationSize() { |
| 7646 | RenderWidgetHostView* rwhv = GetMainFrame()->GetView(); |
| 7647 | // WebContentsView could get resized during emulation, which also resizes |
| 7648 | // RWHV. If it happens, assume user would like to keep using the size after |
| 7649 | // emulation. |
| 7650 | // TODO(jzfeng): Prohibit resizing RWHV through any other means (at least when |
| 7651 | // WebContentsView size changes). |
Dmitry Gozman | c6370718 | 2018-03-06 00:09:39 | [diff] [blame] | 7652 | if (!view_size_before_emulation_.IsEmpty() && rwhv && |
| 7653 | rwhv->GetViewBounds().size() == device_emulation_size_) { |
Jianzhou Feng | d8720c7 | 2018-01-18 03:06:30 | [diff] [blame] | 7654 | rwhv->SetSize(view_size_before_emulation_); |
Dmitry Gozman | c6370718 | 2018-03-06 00:09:39 | [diff] [blame] | 7655 | } |
Jianzhou Feng | d8720c7 | 2018-01-18 03:06:30 | [diff] [blame] | 7656 | device_emulation_size_ = gfx::Size(); |
| 7657 | view_size_before_emulation_ = gfx::Size(); |
| 7658 | } |
| 7659 | |
Max Morin | 5bc74f5 | 2018-05-09 07:00:21 | [diff] [blame] | 7660 | ForwardingAudioStreamFactory* WebContentsImpl::GetAudioStreamFactory() { |
| 7661 | if (!audio_stream_factory_) { |
| 7662 | audio_stream_factory_.emplace( |
| 7663 | this, |
Max Morin | ddebb97 | 2018-09-20 10:04:14 | [diff] [blame] | 7664 | // BrowserMainLoop::GetInstance() may be null in unit tests. |
| 7665 | BrowserMainLoop::GetInstance() |
| 7666 | ? static_cast<media::UserInputMonitorBase*>( |
| 7667 | BrowserMainLoop::GetInstance()->user_input_monitor()) |
| 7668 | : nullptr, |
Ken Rockot | 7296440 | 2019-12-06 10:40:51 | [diff] [blame] | 7669 | AudioStreamBrokerFactory::CreateImpl()); |
Max Morin | 5bc74f5 | 2018-05-09 07:00:21 | [diff] [blame] | 7670 | } |
| 7671 | |
| 7672 | return &*audio_stream_factory_; |
| 7673 | } |
| 7674 | |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 7675 | void WebContentsImpl::MediaStartedPlaying( |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 7676 | const WebContentsObserver::MediaPlayerInfo& media_info, |
Mounir Lamouri | 0f5bdf5 | 2019-04-04 16:32:35 | [diff] [blame] | 7677 | const MediaPlayerId& id) { |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 7678 | if (media_info.has_video) |
| 7679 | currently_playing_video_count_++; |
| 7680 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 7681 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7682 | observer->MediaStartedPlaying(media_info, id); |
| 7683 | }); |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 7684 | } |
| 7685 | |
| 7686 | void WebContentsImpl::MediaStoppedPlaying( |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 7687 | const WebContentsObserver::MediaPlayerInfo& media_info, |
Mounir Lamouri | 0f5bdf5 | 2019-04-04 16:32:35 | [diff] [blame] | 7688 | const MediaPlayerId& id, |
Becca Hughes | 220bfc10 | 2017-11-14 18:24:07 | [diff] [blame] | 7689 | WebContentsObserver::MediaStoppedReason reason) { |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 7690 | if (media_info.has_video) |
| 7691 | currently_playing_video_count_--; |
| 7692 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 7693 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7694 | observer->MediaStoppedPlaying(media_info, id, reason); |
| 7695 | }); |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 7696 | } |
| 7697 | |
Mounir Lamouri | 0f5bdf5 | 2019-04-04 16:32:35 | [diff] [blame] | 7698 | void WebContentsImpl::MediaResized(const gfx::Size& size, |
| 7699 | const MediaPlayerId& id) { |
peconn | 25795152 | 2017-06-09 18:24:59 | [diff] [blame] | 7700 | cached_video_sizes_[id] = size; |
| 7701 | |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 7702 | observers_.ForEachObserver( |
| 7703 | [&](WebContentsObserver* observer) { observer->MediaResized(size, id); }); |
peconn | 25795152 | 2017-06-09 18:24:59 | [diff] [blame] | 7704 | } |
| 7705 | |
Michael Crouse | e75c7a4 | 2020-07-31 21:11:55 | [diff] [blame] | 7706 | void WebContentsImpl::MediaBufferUnderflow(const MediaPlayerId& id) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 7707 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7708 | observer->MediaBufferUnderflow(id); |
| 7709 | }); |
Michael Crouse | e75c7a4 | 2020-07-31 21:11:55 | [diff] [blame] | 7710 | } |
| 7711 | |
Peter E Conn | eccb34c2 | 2017-09-08 09:37:58 | [diff] [blame] | 7712 | void WebContentsImpl::MediaEffectivelyFullscreenChanged(bool is_fullscreen) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 7713 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7714 | observer->MediaEffectivelyFullscreenChanged(is_fullscreen); |
| 7715 | }); |
Peter E Conn | eccb34c2 | 2017-09-08 09:37:58 | [diff] [blame] | 7716 | } |
| 7717 | |
Peter Conn | 31c726a | 2017-08-17 11:07:34 | [diff] [blame] | 7718 | base::Optional<gfx::Size> WebContentsImpl::GetFullscreenVideoSize() { |
Mounir Lamouri | 0f5bdf5 | 2019-04-04 16:32:35 | [diff] [blame] | 7719 | base::Optional<MediaPlayerId> id = |
Peter Conn | 31c726a | 2017-08-17 11:07:34 | [diff] [blame] | 7720 | media_web_contents_observer_->GetFullscreenVideoMediaPlayerId(); |
Jan Wilken Dörrie | 531be7ca | 2019-06-07 10:05:57 | [diff] [blame] | 7721 | if (id && base::Contains(cached_video_sizes_, id.value())) |
Peter Conn | 31c726a | 2017-08-17 11:07:34 | [diff] [blame] | 7722 | return base::Optional<gfx::Size>(cached_video_sizes_[id.value()]); |
Lei Zhang | 6410ec1a | 2019-01-31 21:38:58 | [diff] [blame] | 7723 | return base::nullopt; |
peconn | 25795152 | 2017-06-09 18:24:59 | [diff] [blame] | 7724 | } |
| 7725 | |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 7726 | int WebContentsImpl::GetCurrentlyPlayingVideoCount() { |
| 7727 | return currently_playing_video_count_; |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 7728 | } |
| 7729 | |
Raymond Toy | e413650c | 2018-08-31 00:12:47 | [diff] [blame] | 7730 | void WebContentsImpl::AudioContextPlaybackStarted(RenderFrameHost* host, |
| 7731 | int context_id) { |
| 7732 | WebContentsObserver::AudioContextId audio_context_id(host, context_id); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 7733 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7734 | observer->AudioContextPlaybackStarted(audio_context_id); |
| 7735 | }); |
Raymond Toy | e413650c | 2018-08-31 00:12:47 | [diff] [blame] | 7736 | } |
| 7737 | |
| 7738 | void WebContentsImpl::AudioContextPlaybackStopped(RenderFrameHost* host, |
| 7739 | int context_id) { |
| 7740 | WebContentsObserver::AudioContextId audio_context_id(host, context_id); |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 7741 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7742 | observer->AudioContextPlaybackStopped(audio_context_id); |
| 7743 | }); |
Raymond Toy | e413650c | 2018-08-31 00:12:47 | [diff] [blame] | 7744 | } |
| 7745 | |
Chris Hamilton | 16ca64a | 2020-05-14 23:13:17 | [diff] [blame] | 7746 | void WebContentsImpl::OnFrameAudioStateChanged(RenderFrameHost* host, |
| 7747 | bool is_audible) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 7748 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7749 | observer->OnFrameAudioStateChanged(host, is_audible); |
| 7750 | }); |
Chris Hamilton | 16ca64a | 2020-05-14 23:13:17 | [diff] [blame] | 7751 | } |
| 7752 | |
evliu | 7f736f0 | 2019-11-07 17:43:50 | [diff] [blame] | 7753 | media::MediaMetricsProvider::RecordAggregateWatchTimeCallback |
| 7754 | WebContentsImpl::GetRecordAggregateWatchTimeCallback() { |
Becca Hughes | 5365244 | 2020-03-17 15:35:42 | [diff] [blame] | 7755 | if (!delegate_ || !delegate_->GetDelegateWeakPtr()) |
| 7756 | return base::DoNothing(); |
| 7757 | |
evliu | 7f736f0 | 2019-11-07 17:43:50 | [diff] [blame] | 7758 | return base::BindRepeating( |
Becca Hughes | 5365244 | 2020-03-17 15:35:42 | [diff] [blame] | 7759 | [](base::WeakPtr<WebContentsDelegate> delegate, GURL last_committed_url, |
| 7760 | base::TimeDelta total_watch_time, base::TimeDelta time_stamp, |
| 7761 | bool has_video, bool has_audio) { |
evliu | a283c9e | 2019-11-08 22:57:22 | [diff] [blame] | 7762 | content::MediaPlayerWatchTime watch_time( |
| 7763 | last_committed_url, last_committed_url.GetOrigin(), |
| 7764 | total_watch_time, time_stamp, has_video, has_audio); |
evliu | 7f736f0 | 2019-11-07 17:43:50 | [diff] [blame] | 7765 | |
| 7766 | // Save the watch time if the delegate is still alive. |
| 7767 | if (delegate) |
| 7768 | delegate->MediaWatchTimeChanged(watch_time); |
| 7769 | }, |
Becca Hughes | 5365244 | 2020-03-17 15:35:42 | [diff] [blame] | 7770 | delegate_->GetDelegateWeakPtr(), GetMainFrameLastCommittedURL()); |
evliu | 7f736f0 | 2019-11-07 17:43:50 | [diff] [blame] | 7771 | } |
| 7772 | |
Ehsan Karamad | 1c63176 | 2019-05-13 23:04:01 | [diff] [blame] | 7773 | RenderFrameHostImpl* WebContentsImpl::GetMainFrameForInnerDelegate( |
| 7774 | FrameTreeNode* frame_tree_node) { |
| 7775 | if (auto* web_contents = node_.GetInnerWebContentsInFrame(frame_tree_node)) |
| 7776 | return web_contents->GetMainFrame(); |
| 7777 | return nullptr; |
| 7778 | } |
| 7779 | |
John Budorick | ee1c951 | 2019-10-17 15:32:19 | [diff] [blame] | 7780 | bool WebContentsImpl::IsFrameLowPriority( |
| 7781 | const RenderFrameHost* render_frame_host) { |
| 7782 | if (!delegate_) |
| 7783 | return false; |
| 7784 | return delegate_->IsFrameLowPriority(this, render_frame_host); |
| 7785 | } |
| 7786 | |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 7787 | void WebContentsImpl::IsClipboardPasteAllowed( |
| 7788 | const GURL& url, |
| 7789 | const ui::ClipboardFormatType& data_type, |
| 7790 | const std::string& data, |
| 7791 | IsClipboardPasteAllowedCallback callback) { |
Dominique Fauteux-Chapleau | 9924438 | 2020-07-08 20:37:00 | [diff] [blame] | 7792 | ++suppress_unresponsive_renderer_count_; |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 7793 | GetContentClient()->browser()->IsClipboardPasteAllowed( |
Dominique Fauteux-Chapleau | 9924438 | 2020-07-08 20:37:00 | [diff] [blame] | 7794 | this, url, data_type, data, |
| 7795 | base::BindOnce(&WebContentsImpl::IsClipboardPasteAllowedWrapperCallback, |
| 7796 | weak_factory_.GetWeakPtr(), std::move(callback))); |
| 7797 | } |
| 7798 | |
| 7799 | void WebContentsImpl::IsClipboardPasteAllowedWrapperCallback( |
| 7800 | IsClipboardPasteAllowedCallback callback, |
| 7801 | ClipboardPasteAllowed allowed) { |
| 7802 | std::move(callback).Run(allowed); |
| 7803 | --suppress_unresponsive_renderer_count_; |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 7804 | } |
| 7805 | |
Lan Wei | f81c6e7c | 2020-02-12 16:46:09 | [diff] [blame] | 7806 | bool WebContentsImpl::HasSeenRecentScreenOrientationChange() { |
| 7807 | static constexpr base::TimeDelta kMaxInterval = |
| 7808 | base::TimeDelta::FromSeconds(1); |
| 7809 | base::TimeDelta delta = |
| 7810 | ui::EventTimeForNow() - last_screen_orientation_change_time_; |
| 7811 | // Return whether there is a screen orientation change happened in the recent |
| 7812 | // 1 second. |
| 7813 | return delta <= kMaxInterval; |
| 7814 | } |
| 7815 | |
| 7816 | void WebContentsImpl::DidChangeScreenOrientation() { |
| 7817 | last_screen_orientation_change_time_ = ui::EventTimeForNow(); |
| 7818 | } |
| 7819 | |
Miyoung Shin | 8f2e183 | 2020-04-27 09:00:02 | [diff] [blame] | 7820 | bool WebContentsImpl::ShowPopupMenu( |
Miyoung Shin | 4d947d2 | 2020-04-24 04:48:33 | [diff] [blame] | 7821 | RenderFrameHostImpl* render_frame_host, |
Miyoung Shin | 8f2e183 | 2020-04-27 09:00:02 | [diff] [blame] | 7822 | mojo::PendingRemote<blink::mojom::PopupMenuClient>* popup_client, |
Miyoung Shin | 4d947d2 | 2020-04-24 04:48:33 | [diff] [blame] | 7823 | const gfx::Rect& bounds, |
| 7824 | int32_t item_height, |
| 7825 | double font_size, |
| 7826 | int32_t selected_item, |
| 7827 | std::vector<blink::mojom::MenuItemPtr>* menu_items, |
| 7828 | bool right_aligned, |
| 7829 | bool allow_multiple_selection) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 7830 | for (auto& observer : observers_.observer_list()) { |
Miyoung Shin | 8f2e183 | 2020-04-27 09:00:02 | [diff] [blame] | 7831 | if (observer.ShowPopupMenu(render_frame_host, popup_client, bounds, |
| 7832 | item_height, font_size, selected_item, |
| 7833 | menu_items, right_aligned, |
| 7834 | allow_multiple_selection)) { |
Miyoung Shin | 4d947d2 | 2020-04-24 04:48:33 | [diff] [blame] | 7835 | return true; |
| 7836 | } |
| 7837 | } |
| 7838 | return false; |
| 7839 | } |
| 7840 | |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 7841 | void WebContentsImpl::UpdateWebContentsVisibility(Visibility visibility) { |
Francois Doray | 3f2afbd | 2018-04-06 19:18:18 | [diff] [blame] | 7842 | // Occlusion is disabled when |features::kWebContentsOcclusion| is disabled |
| 7843 | // (for power and speed impact assessment) or when |
| 7844 | // |switches::kDisableBackgroundingOccludedWindowsForTesting| is specified on |
| 7845 | // the command line (to avoid flakiness in browser tests). |
| 7846 | const bool occlusion_is_disabled = |
| 7847 | !base::FeatureList::IsEnabled(features::kWebContentsOcclusion) || |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 7848 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 7849 | switches::kDisableBackgroundingOccludedWindowsForTesting); |
| 7850 | if (occlusion_is_disabled && visibility == Visibility::OCCLUDED) |
| 7851 | visibility = Visibility::VISIBLE; |
| 7852 | |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 7853 | if (!did_first_set_visible_) { |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 7854 | if (visibility == Visibility::VISIBLE) { |
| 7855 | // A WebContents created with CreateParams::initially_hidden = false |
| 7856 | // starts with GetVisibility() == Visibility::VISIBLE even though it is |
| 7857 | // not really visible. Call WasShown() when it becomes visible for real as |
| 7858 | // the page load mechanism and some WebContentsObserver rely on that. |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 7859 | WasShown(); |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 7860 | did_first_set_visible_ = true; |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 7861 | } |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 7862 | |
| 7863 | // Trust the initial visibility of the WebContents and do not switch it to |
| 7864 | // HIDDEN or OCCLUDED before it becomes VISIBLE for real. Doing so would |
| 7865 | // result in destroying resources that would immediately be recreated (e.g. |
| 7866 | // UpdateWebContents(HIDDEN) can be called when a WebContents is added to a |
| 7867 | // hidden window that is about to be shown). |
| 7868 | |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 7869 | return; |
| 7870 | } |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 7871 | |
| 7872 | if (visibility == visibility_) |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 7873 | return; |
| 7874 | |
Collin Baker | 989e088 | 2019-11-01 01:27:17 | [diff] [blame] | 7875 | UpdateVisibilityAndNotifyPageAndView(visibility); |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 7876 | } |
| 7877 | |
aelias | 5252baa | 2016-04-10 01:18:02 | [diff] [blame] | 7878 | void WebContentsImpl::UpdateOverridingUserAgent() { |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 7879 | NotifyPreferencesChanged(); |
aelias | 5252baa | 2016-04-10 01:18:02 | [diff] [blame] | 7880 | } |
| 7881 | |
avi | d53461d | 2016-02-25 17:15:04 | [diff] [blame] | 7882 | void WebContentsImpl::SetJavaScriptDialogManagerForTesting( |
| 7883 | JavaScriptDialogManager* dialog_manager) { |
| 7884 | dialog_manager_ = dialog_manager; |
| 7885 | } |
| 7886 | |
Julie Jeongeun Kim | 7d098617 | 2019-12-04 03:17:25 | [diff] [blame] | 7887 | void WebContentsImpl::RemoveReceiverSet(const std::string& interface_name) { |
| 7888 | auto it = receiver_sets_.find(interface_name); |
| 7889 | if (it != receiver_sets_.end()) |
| 7890 | receiver_sets_.erase(it); |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 7891 | } |
| 7892 | |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 7893 | bool WebContentsImpl::AddDomainInfoToRapporSample(rappor::Sample* sample) { |
nzolghadr | bbffc6c | 2017-05-25 17:56:39 | [diff] [blame] | 7894 | // Here we associate this metric to the main frame URL regardless of what |
| 7895 | // caused it. |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 7896 | sample->SetStringField("Domain", ::rappor::GetDomainAndRegistrySampleFromGURL( |
| 7897 | GetLastCommittedURL())); |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 7898 | return true; |
| 7899 | } |
| 7900 | |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 7901 | void WebContentsImpl::ShowInsecureLocalhostWarningIfNeeded() { |
| 7902 | bool allow_localhost = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 7903 | switches::kAllowInsecureLocalhost); |
| 7904 | if (!allow_localhost) |
| 7905 | return; |
| 7906 | |
| 7907 | content::NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
Rob Wu | f79b3ba | 2018-01-14 01:54:31 | [diff] [blame] | 7908 | if (!entry || !net::IsLocalhost(entry->GetURL())) |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 7909 | return; |
| 7910 | |
| 7911 | content::SSLStatus ssl_status = entry->GetSSL(); |
Matt Mueller | 93651144 | 2019-09-03 18:15:12 | [diff] [blame] | 7912 | if (!net::IsCertStatusError(ssl_status.cert_status)) |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 7913 | return; |
| 7914 | |
| 7915 | GetMainFrame()->AddMessageToConsole( |
Abhijeet Kandalkar | a5928a0a | 2019-03-13 05:04:42 | [diff] [blame] | 7916 | blink::mojom::ConsoleMessageLevel::kWarning, |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 7917 | base::StringPrintf("This site does not have a valid SSL " |
| 7918 | "certificate! Without SSL, your site's and " |
| 7919 | "visitors' data is vulnerable to theft and " |
| 7920 | "tampering. Get a valid SSL certificate before" |
| 7921 | " releasing your website to the public.")); |
| 7922 | } |
| 7923 | |
ekaramad | f6750aa | 2017-06-06 18:29:42 | [diff] [blame] | 7924 | bool WebContentsImpl::IsShowingContextMenuOnPage() const { |
| 7925 | return showing_context_menu_; |
| 7926 | } |
| 7927 | |
Min Qin | a904f330 | 2018-02-13 23:33:34 | [diff] [blame] | 7928 | download::DownloadUrlParameters::RequestHeadersType |
| 7929 | WebContentsImpl::ParseDownloadHeaders(const std::string& headers) { |
| 7930 | download::DownloadUrlParameters::RequestHeadersType request_headers; |
Megan Jablonski | 2f6a4c5 | 2017-07-10 23:01:25 | [diff] [blame] | 7931 | for (const base::StringPiece& key_value : base::SplitStringPiece( |
| 7932 | headers, "\r\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { |
| 7933 | std::vector<std::string> pair = base::SplitString( |
| 7934 | key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 7935 | if (2ul == pair.size()) |
| 7936 | request_headers.push_back(make_pair(pair[0], pair[1])); |
| 7937 | } |
| 7938 | return request_headers; |
| 7939 | } |
| 7940 | |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 7941 | void WebContentsImpl::SetOpenerForNewContents(FrameTreeNode* opener, |
| 7942 | bool opener_suppressed) { |
| 7943 | if (opener) { |
| 7944 | FrameTreeNode* new_root = GetFrameTree()->root(); |
| 7945 | |
| 7946 | // For the "original opener", track the opener's main frame instead, because |
| 7947 | // if the opener is a subframe, the opener tracking could be easily bypassed |
| 7948 | // by spawning from a subframe and deleting the subframe. |
| 7949 | // https://crbug.com/705316 |
| 7950 | new_root->SetOriginalOpener(opener->frame_tree()->root()); |
| 7951 | |
| 7952 | if (!opener_suppressed) { |
| 7953 | new_root->SetOpener(opener); |
| 7954 | created_with_opener_ = true; |
| 7955 | } |
| 7956 | } |
| 7957 | } |
| 7958 | |
Mounir Lamouri | 0f5bdf5 | 2019-04-04 16:32:35 | [diff] [blame] | 7959 | void WebContentsImpl::MediaMutedStatusChanged(const MediaPlayerId& id, |
| 7960 | bool muted) { |
Alexander Timin | 90c20c3 | 2020-08-12 15:28:32 | [diff] [blame^] | 7961 | observers_.ForEachObserver([&](WebContentsObserver* observer) { |
| 7962 | observer->MediaMutedStatusChanged(id, muted); |
| 7963 | }); |
Becca Hughes | 9f6fd4b8 | 2017-06-15 10:01:40 | [diff] [blame] | 7964 | } |
| 7965 | |
EhsanK | 2075c7e | 2017-08-21 02:42:39 | [diff] [blame] | 7966 | void WebContentsImpl::SetVisibilityForChildViews(bool visible) { |
| 7967 | GetMainFrame()->SetVisibilityForChildViews(visible); |
| 7968 | } |
| 7969 | |
Alison Maher | 7f366dc6 | 2020-03-03 19:46:00 | [diff] [blame] | 7970 | void WebContentsImpl::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) { |
| 7971 | DCHECK(native_theme_observer_.IsObserving(observed_theme)); |
| 7972 | |
| 7973 | bool using_dark_colors = observed_theme->ShouldUseDarkColors(); |
| 7974 | ui::NativeTheme::PreferredColorScheme preferred_color_scheme = |
| 7975 | observed_theme->GetPreferredColorScheme(); |
| 7976 | bool preferences_changed = false; |
| 7977 | |
| 7978 | if (using_dark_colors_ != using_dark_colors) { |
| 7979 | using_dark_colors_ = using_dark_colors; |
| 7980 | preferences_changed = true; |
| 7981 | } |
| 7982 | if (preferred_color_scheme_ != preferred_color_scheme) { |
| 7983 | preferred_color_scheme_ = preferred_color_scheme; |
| 7984 | preferences_changed = true; |
| 7985 | } |
| 7986 | |
| 7987 | if (preferences_changed) |
| 7988 | NotifyPreferencesChanged(); |
| 7989 | } |
| 7990 | |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 7991 | blink::mojom::FrameWidgetInputHandler* |
| 7992 | WebContentsImpl::GetFocusedFrameWidgetInputHandler() { |
| 7993 | auto* focused_render_widget_host = |
| 7994 | GetFocusedRenderWidgetHost(GetMainFrame()->GetRenderWidgetHost()); |
| 7995 | if (!focused_render_widget_host) |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 7996 | return nullptr; |
Dave Tapuska | 58a099e | 2020-06-08 21:48:40 | [diff] [blame] | 7997 | return focused_render_widget_host->GetFrameWidgetInputHandler(); |
Dave Tapuska | e782bea | 2019-07-09 16:21:51 | [diff] [blame] | 7998 | } |
| 7999 | |
Alexander Timin | e3ec419 | 2020-04-20 16:39:40 | [diff] [blame] | 8000 | ukm::SourceId WebContentsImpl::GetCurrentPageUkmSourceId() { |
| 8001 | return GetMainFrame()->GetPageUkmSourceId(); |
| 8002 | } |
| 8003 | |
Yuzu Saijo | 232076f | 2020-05-29 07:14:02 | [diff] [blame] | 8004 | std::set<RenderViewHostImpl*> |
| 8005 | WebContentsImpl::GetRenderViewHostsIncludingBackForwardCached() { |
| 8006 | std::set<RenderViewHostImpl*> render_view_hosts; |
| 8007 | |
| 8008 | // Add RenderViewHostImpls outside of BackForwardCache. |
| 8009 | for (auto& render_view_host : frame_tree_.render_view_hosts()) { |
| 8010 | render_view_hosts.insert(render_view_host.second); |
| 8011 | } |
| 8012 | |
| 8013 | // Add RenderViewHostImpls in BackForwardCache. |
| 8014 | const auto& entries = GetController().GetBackForwardCache().GetEntries(); |
| 8015 | for (const auto& entry : entries) { |
| 8016 | std::set<RenderViewHostImpl*> bfcached_hosts = entry->render_view_hosts; |
| 8017 | render_view_hosts.insert(bfcached_hosts.begin(), bfcached_hosts.end()); |
| 8018 | } |
| 8019 | |
| 8020 | return render_view_hosts; |
| 8021 | } |
| 8022 | |
Sreeja Kamishetty | be0ccd6b | 2020-06-09 11:52:50 | [diff] [blame] | 8023 | void WebContentsImpl::RenderFrameHostStateChanged( |
| 8024 | RenderFrameHost* render_frame_host, |
| 8025 | LifecycleState old_state, |
| 8026 | LifecycleState new_state) { |
| 8027 | if (render_frame_host->GetParent()) |
| 8028 | return; |
| 8029 | |
| 8030 | if (old_state == LifecycleState::kActive && |
| 8031 | new_state != LifecycleState::kActive) { |
| 8032 | // TODO(sreejakshetty): Remove this reset when ColorChooser becomes |
| 8033 | // per-frame. |
| 8034 | // Close the color chooser popup when RenderFrameHost changes state from |
| 8035 | // kActive. |
| 8036 | color_chooser_.reset(); |
| 8037 | } |
| 8038 | } |
| 8039 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 8040 | } // namespace content |