[email protected] | b553edd5 | 2012-01-10 12:15:23 | [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] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 5 | #include "content/renderer/render_view_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
| 7 | #include <algorithm> |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 8 | #include <cmath> |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 9 | #include <memory> |
lukasza | 5d0dee4 | 2017-06-14 21:57:37 | [diff] [blame] | 10 | #include <utility> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 11 | |
[email protected] | 5d4e36d | 2013-02-15 15:18:20 | [diff] [blame] | 12 | #include "base/auto_reset.h" |
[email protected] | 6e80682 | 2011-11-19 01:51:08 | [diff] [blame] | 13 | #include "base/bind.h" |
| 14 | #include "base/bind_helpers.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | #include "base/command_line.h" |
[email protected] | bb063b7 | 2009-03-27 23:18:50 | [diff] [blame] | 16 | #include "base/compiler_specific.h" |
[email protected] | 2132d6b | 2013-06-05 00:15:43 | [diff] [blame] | 17 | #include "base/debug/alias.h" |
avayvod | 23275794 | 2017-04-29 04:12:34 | [diff] [blame] | 18 | #include "base/feature_list.h" |
[email protected] | 728c2ee | 2013-06-25 04:01:07 | [diff] [blame] | 19 | #include "base/files/file_path.h" |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 20 | #include "base/i18n/rtl.h" |
[email protected] | b1cf337 | 2011-04-20 21:28:10 | [diff] [blame] | 21 | #include "base/json/json_writer.h" |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 22 | #include "base/lazy_instance.h" |
fdoray | 7a8954a4 | 2016-06-07 04:28:38 | [diff] [blame] | 23 | #include "base/location.h" |
[email protected] | f29efe6b | 2014-06-09 05:01:51 | [diff] [blame] | 24 | #include "base/metrics/field_trial.h" |
[email protected] | d3b4ee2 | 2013-07-24 22:50:06 | [diff] [blame] | 25 | #include "base/process/kill.h" |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 26 | #include "base/process/process.h" |
fdoray | 7a8954a4 | 2016-06-07 04:28:38 | [diff] [blame] | 27 | #include "base/single_thread_task_runner.h" |
danakj | a4ba7e5 | 2018-11-29 23:04:31 | [diff] [blame] | 28 | #include "base/stl_util.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 29 | #include "base/strings/string_number_conversions.h" |
[email protected] | b9e7c479f | 2013-04-12 04:33:24 | [diff] [blame] | 30 | #include "base/strings/string_piece.h" |
[email protected] | 27c0573 | 2013-02-15 21:55:49 | [diff] [blame] | 31 | #include "base/strings/string_split.h" |
[email protected] | 21aa9968 | 2013-06-11 07:17:01 | [diff] [blame] | 32 | #include "base/strings/string_util.h" |
[email protected] | 40d11e0 | 2013-03-28 17:43:14 | [diff] [blame] | 33 | #include "base/strings/sys_string_conversions.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 34 | #include "base/strings/utf_string_conversions.h" |
Sebastien Marchand | 75a7cdf | 2018-11-13 23:47:03 | [diff] [blame] | 35 | #include "base/system/sys_info.h" |
fdoray | 7a8954a4 | 2016-06-07 04:28:38 | [diff] [blame] | 36 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | abb52216 | 2013-06-28 01:54:16 | [diff] [blame] | 37 | #include "base/time/time.h" |
primiano | 9e38d55 | 2015-01-28 04:18:01 | [diff] [blame] | 38 | #include "base/trace_event/trace_event.h" |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 39 | #include "build/build_config.h" |
dongseong.hwang | e095dfa | 2016-02-04 11:21:39 | [diff] [blame] | 40 | #include "cc/base/switches.h" |
enne | 98c9f805 | 2017-03-15 19:38:22 | [diff] [blame] | 41 | #include "cc/paint/skia_paint_canvas.h" |
danakj | 4c98765 | 2018-07-05 15:49:41 | [diff] [blame] | 42 | #include "cc/trees/layer_tree_host.h" |
jinho.bang | 632a1a72 | 2014-09-18 03:02:56 | [diff] [blame] | 43 | #include "content/common/content_constants_internal.h" |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 44 | #include "content/common/drag_messages.h" |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 45 | #include "content/common/frame_messages.h" |
alexmos | bc7eafa | 2014-12-06 01:38:09 | [diff] [blame] | 46 | #include "content/common/frame_replication_state.h" |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 47 | #include "content/common/input_messages.h" |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 48 | #include "content/common/page_messages.h" |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 49 | #include "content/common/render_message_filter.mojom.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 50 | #include "content/common/view_messages.h" |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 51 | #include "content/public/common/content_client.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 52 | #include "content/public/common/content_constants.h" |
Tarun Bansal | 73dd2ff8 | 2017-10-03 05:29:34 | [diff] [blame] | 53 | #include "content/public/common/content_features.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 54 | #include "content/public/common/content_switches.h" |
clamy | da97e832 | 2014-10-07 21:57:25 | [diff] [blame] | 55 | #include "content/public/common/page_state.h" |
Leon Han | 963dc18 | 2018-11-06 05:41:48 | [diff] [blame] | 56 | #include "content/public/common/referrer_type_converters.h" |
[email protected] | 818915cd | 2012-11-20 13:14:11 | [diff] [blame] | 57 | #include "content/public/common/three_d_api_types.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 58 | #include "content/public/common/url_constants.h" |
[email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 59 | #include "content/public/renderer/content_renderer_client.h" |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 60 | #include "content/public/renderer/document_state.h" |
Avi Drissman | 07d2245 | 2019-03-25 17:56:39 | [diff] [blame] | 61 | #include "content/public/renderer/render_thread.h" |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 62 | #include "content/public/renderer/render_view_observer.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 63 | #include "content/public/renderer/render_view_visitor.h" |
scottmg | 8e6c608 | 2017-02-13 23:15:48 | [diff] [blame] | 64 | #include "content/public/renderer/window_features_converter.h" |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 65 | #include "content/renderer/drop_data_builder.h" |
[email protected] | dc06435 | 2014-04-25 08:36:38 | [diff] [blame] | 66 | #include "content/renderer/history_serialization.h" |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 67 | #include "content/renderer/internal_document_state_data.h" |
John Abd-El-Malek | 6b56ef71 | 2017-10-21 22:52:46 | [diff] [blame] | 68 | #include "content/renderer/loader/request_extra_data.h" |
Amos Lim | bcc710e | 2018-06-08 05:51:17 | [diff] [blame] | 69 | #include "content/renderer/media/audio/audio_device_factory.h" |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 70 | #include "content/renderer/render_frame_impl.h" |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 71 | #include "content/renderer/render_frame_proxy.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 72 | #include "content/renderer/render_process.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 73 | #include "content/renderer/render_thread_impl.h" |
[email protected] | 2cff005 | 2011-03-18 16:51:44 | [diff] [blame] | 74 | #include "content/renderer/render_widget_fullscreen_pepper.h" |
Daniel Murphy | e3eec92c | 2018-02-23 19:09:15 | [diff] [blame] | 75 | #include "content/renderer/renderer_blink_platform_impl.h" |
John Abd-El-Malek | 312a30bb | 2017-10-23 19:51:52 | [diff] [blame] | 76 | #include "content/renderer/v8_value_converter_impl.h" |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 77 | #include "content/renderer/web_ui_extension_data.h" |
[email protected] | f596114 | 2013-04-17 23:09:42 | [diff] [blame] | 78 | #include "media/audio/audio_output_device.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 79 | #include "media/base/media_switches.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 80 | #include "media/media_buildflags.h" |
servolk | f54f5c8f | 2015-02-24 20:32:39 | [diff] [blame] | 81 | #include "media/renderers/audio_renderer_impl.h" |
Dale Curtis | 863022e | 2017-08-19 02:05:34 | [diff] [blame] | 82 | #include "media/video/gpu_video_accelerator_factories.h" |
Julie Jeongeun Kim | caacf910 | 2019-09-12 02:13:05 | [diff] [blame] | 83 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 84 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 85 | #include "net/base/escape.h" |
| 86 | #include "net/base/net_errors.h" |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame] | 87 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 88 | #include "net/http/http_util.h" |
Tarun Bansal | 73d67f0 | 2018-01-17 05:56:25 | [diff] [blame] | 89 | #include "net/nqe/effective_connection_type.h" |
Scott Violet | 02e38b9 | 2018-03-27 23:42:14 | [diff] [blame] | 90 | #include "ppapi/buildflags/buildflags.h" |
luken | b171b53 | 2014-09-24 05:50:38 | [diff] [blame] | 91 | #include "skia/ext/platform_canvas.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 92 | #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" |
Daniel Murphy | 95792ef | 2018-10-04 01:29:55 | [diff] [blame] | 93 | #include "third_party/blink/public/common/dom_storage/session_storage_namespace_id.h" |
Mustaq Ahmed | 76c2f431 | 2018-06-07 20:48:01 | [diff] [blame] | 94 | #include "third_party/blink/public/common/frame/user_activation_update_source.h" |
Dave Tapuska | 129cef8 | 2019-12-19 16:36:48 | [diff] [blame] | 95 | #include "third_party/blink/public/common/input/web_input_event.h" |
Gyuyoung Kim | a252d4a | 2020-09-16 07:20:31 | [diff] [blame] | 96 | #include "third_party/blink/public/common/switches.h" |
Gyuyoung Kim | 1ac4ca78 | 2020-09-11 03:32:51 | [diff] [blame] | 97 | #include "third_party/blink/public/common/web_preferences/web_preferences.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 98 | #include "third_party/blink/public/platform/file_path_conversion.h" |
Antonio Gomes | 925f9b9 | 2019-07-30 23:23:23 | [diff] [blame] | 99 | #include "third_party/blink/public/platform/modules/video_capture/web_video_capture_impl_manager.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 100 | #include "third_party/blink/public/platform/url_conversion.h" |
| 101 | #include "third_party/blink/public/platform/web_connection_type.h" |
| 102 | #include "third_party/blink/public/platform/web_effective_connection_type.h" |
| 103 | #include "third_party/blink/public/platform/web_http_body.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 104 | #include "third_party/blink/public/platform/web_input_event_result.h" |
| 105 | #include "third_party/blink/public/platform/web_network_state_notifier.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 106 | #include "third_party/blink/public/platform/web_rect.h" |
| 107 | #include "third_party/blink/public/platform/web_runtime_features.h" |
| 108 | #include "third_party/blink/public/platform/web_size.h" |
| 109 | #include "third_party/blink/public/platform/web_string.h" |
| 110 | #include "third_party/blink/public/platform/web_url.h" |
| 111 | #include "third_party/blink/public/platform/web_url_error.h" |
| 112 | #include "third_party/blink/public/platform/web_url_request.h" |
| 113 | #include "third_party/blink/public/platform/web_url_response.h" |
| 114 | #include "third_party/blink/public/platform/web_vector.h" |
| 115 | #include "third_party/blink/public/public_buildflags.h" |
Guido Urdaneta | dc709037 | 2019-07-29 17:59:54 | [diff] [blame] | 116 | #include "third_party/blink/public/web/modules/mediastream/web_media_stream_device_observer.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 117 | #include "third_party/blink/public/web/web_autofill_client.h" |
| 118 | #include "third_party/blink/public/web/web_ax_object.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 119 | #include "third_party/blink/public/web/web_document.h" |
| 120 | #include "third_party/blink/public/web/web_dom_event.h" |
| 121 | #include "third_party/blink/public/web/web_dom_message_event.h" |
| 122 | #include "third_party/blink/public/web/web_element.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 123 | #include "third_party/blink/public/web/web_form_control_element.h" |
| 124 | #include "third_party/blink/public/web/web_form_element.h" |
| 125 | #include "third_party/blink/public/web/web_frame.h" |
| 126 | #include "third_party/blink/public/web/web_frame_content_dumper.h" |
| 127 | #include "third_party/blink/public/web/web_frame_widget.h" |
| 128 | #include "third_party/blink/public/web/web_history_item.h" |
| 129 | #include "third_party/blink/public/web/web_hit_test_result.h" |
| 130 | #include "third_party/blink/public/web/web_input_element.h" |
| 131 | #include "third_party/blink/public/web/web_local_frame.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 132 | #include "third_party/blink/public/web/web_navigation_policy.h" |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 133 | #include "third_party/blink/public/web/web_page_popup.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 134 | #include "third_party/blink/public/web/web_plugin.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 135 | #include "third_party/blink/public/web/web_range.h" |
| 136 | #include "third_party/blink/public/web/web_render_theme.h" |
| 137 | #include "third_party/blink/public/web/web_script_source.h" |
| 138 | #include "third_party/blink/public/web/web_searchable_form_data.h" |
| 139 | #include "third_party/blink/public/web/web_security_policy.h" |
| 140 | #include "third_party/blink/public/web/web_settings.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 141 | #include "third_party/blink/public/web/web_view.h" |
| 142 | #include "third_party/blink/public/web/web_window_features.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 143 | #include "third_party/icu/source/common/unicode/uchar.h" |
| 144 | #include "third_party/icu/source/common/unicode/uscript.h" |
eseckler | f2bd55f7 | 2017-03-31 09:11:57 | [diff] [blame] | 145 | #include "third_party/skia/include/core/SkColor.h" |
Ionel Popescu | 2649f2f | 2020-01-10 10:06:59 | [diff] [blame] | 146 | #include "ui/base/ui_base_features.h" |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 147 | #include "ui/base/ui_base_switches_util.h" |
tfarina | 655f81d | 2014-12-23 02:38:50 | [diff] [blame] | 148 | #include "ui/gfx/geometry/point.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 149 | #include "ui/gfx/geometry/rect.h" |
| 150 | #include "ui/gfx/geometry/rect_conversions.h" |
tfarina | ebe974f0 | 2015-01-03 04:25:32 | [diff] [blame] | 151 | #include "ui/gfx/geometry/size_conversions.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 152 | #include "ui/gfx/native_widget_types.h" |
ccameron | 772317d | 2017-06-04 18:35:03 | [diff] [blame] | 153 | #include "ui/gfx/switches.h" |
mfomitchev | 3ba450ad | 2017-04-03 18:20:40 | [diff] [blame] | 154 | #include "ui/latency/latency_info.h" |
csharrison | d88f975 | 2016-10-26 23:56:36 | [diff] [blame] | 155 | #include "url/origin.h" |
markdittmer | 67b71ea | 2016-03-03 22:40:03 | [diff] [blame] | 156 | #include "url/url_constants.h" |
[email protected] | c4a9e93 | 2011-03-05 04:05:55 | [diff] [blame] | 157 | #include "v8/include/v8.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 158 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 159 | #if defined(OS_ANDROID) |
[email protected] | befe5478 | 2013-04-23 00:49:25 | [diff] [blame] | 160 | #include <cpu-features.h> |
| 161 | |
dalecurtis | cd97125 | 2016-09-21 16:09:00 | [diff] [blame] | 162 | #include "base/android/build_info.h" |
kylechar | e7d8d5c7 | 2018-01-05 19:06:28 | [diff] [blame] | 163 | #include "content/child/child_thread_impl.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 164 | #include "ui/gfx/geometry/rect_f.h" |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 165 | |
Avi Drissman | 7c57be7 | 2020-07-29 20:09:46 | [diff] [blame] | 166 | #elif defined(OS_MAC) |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 167 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 168 | #endif |
| 169 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 170 | #if BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 171 | #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 172 | #include "content/renderer/pepper/pepper_plugin_registry.h" |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 173 | #endif |
| 174 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 175 | using blink::WebAXObject; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 176 | using blink::WebConsoleMessage; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 177 | using blink::WebData; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 178 | using blink::WebDocument; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 179 | using blink::WebDragOperation; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 180 | using blink::WebElement; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 181 | using blink::WebFormControlElement; |
| 182 | using blink::WebFormElement; |
| 183 | using blink::WebFrame; |
dglazkov | 0322349 | 2016-02-08 22:16:03 | [diff] [blame] | 184 | using blink::WebFrameContentDumper; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 185 | using blink::WebGestureEvent; |
| 186 | using blink::WebHistoryItem; |
dglazkov | 8d0c21dd | 2016-08-06 15:56:36 | [diff] [blame] | 187 | using blink::WebHitTestResult; |
Sergio Villar Senin | eb8c25245 | 2019-10-04 17:18:28 | [diff] [blame] | 188 | using blink::WebHTTPBody; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 189 | using blink::WebInputElement; |
| 190 | using blink::WebInputEvent; |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 191 | using blink::WebLocalFrame; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 192 | using blink::WebMouseEvent; |
| 193 | using blink::WebNavigationPolicy; |
| 194 | using blink::WebNavigationType; |
| 195 | using blink::WebNode; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 196 | using blink::WebRect; |
Sergio Villar Senin | eb8c25245 | 2019-10-04 17:18:28 | [diff] [blame] | 197 | using blink::WebRuntimeFeatures; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 198 | using blink::WebScriptSource; |
| 199 | using blink::WebSearchableFormData; |
| 200 | using blink::WebSecurityOrigin; |
| 201 | using blink::WebSecurityPolicy; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 202 | using blink::WebSettings; |
| 203 | using blink::WebSize; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 204 | using blink::WebString; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 205 | using blink::WebTouchEvent; |
| 206 | using blink::WebURL; |
| 207 | using blink::WebURLError; |
| 208 | using blink::WebURLRequest; |
| 209 | using blink::WebURLResponse; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 210 | using blink::WebVector; |
| 211 | using blink::WebView; |
| 212 | using blink::WebWidget; |
| 213 | using blink::WebWindowFeatures; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 214 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 215 | namespace content { |
| 216 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 217 | //----------------------------------------------------------------------------- |
| 218 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 219 | typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap; |
jbroman | 8319b23 | 2017-03-08 22:53:29 | [diff] [blame] | 220 | static base::LazyInstance<ViewMap>::Leaky g_view_map = |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 221 | LAZY_INSTANCE_INITIALIZER; |
scottmg | 5e65e3a | 2017-03-08 08:48:46 | [diff] [blame] | 222 | typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap; |
jbroman | 8319b23 | 2017-03-08 22:53:29 | [diff] [blame] | 223 | static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map = |
| 224 | LAZY_INSTANCE_INITIALIZER; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 225 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 226 | // Time, in seconds, we delay before sending content state changes (such as form |
| 227 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 228 | // spamming the browser. |
| 229 | // To avoid having tab/session restore require sending a message to get the |
| 230 | // current content state during tab closing we use a shorter timeout for the |
| 231 | // foreground renderer. This means there is a small window of time from which |
| 232 | // content state is modified and not sent to session restore, but this is |
| 233 | // better than having to wake up all renderers during shutdown. |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 234 | const int kDelaySecondsForContentStateSyncHidden = 5; |
| 235 | const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 236 | |
dcheng | 35d31c11 | 2015-07-22 00:17:36 | [diff] [blame] | 237 | static RenderViewImpl* (*g_create_render_view_impl)( |
| 238 | CompositorDependencies* compositor_deps, |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 239 | const mojom::CreateViewParams&) = nullptr; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 240 | |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 241 | // static |
[email protected] | 65920f33 | 2014-03-04 21:14:18 | [diff] [blame] | 242 | WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition( |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 243 | WebNavigationPolicy policy) { |
| 244 | switch (policy) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 245 | case blink::kWebNavigationPolicyDownload: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 246 | return WindowOpenDisposition::SAVE_TO_DISK; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 247 | case blink::kWebNavigationPolicyCurrentTab: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 248 | return WindowOpenDisposition::CURRENT_TAB; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 249 | case blink::kWebNavigationPolicyNewBackgroundTab: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 250 | return WindowOpenDisposition::NEW_BACKGROUND_TAB; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 251 | case blink::kWebNavigationPolicyNewForegroundTab: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 252 | return WindowOpenDisposition::NEW_FOREGROUND_TAB; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 253 | case blink::kWebNavigationPolicyNewWindow: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 254 | return WindowOpenDisposition::NEW_WINDOW; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 255 | case blink::kWebNavigationPolicyNewPopup: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 256 | return WindowOpenDisposition::NEW_POPUP; |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 257 | default: |
| 258 | NOTREACHED() << "Unexpected WebNavigationPolicy"; |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 259 | return WindowOpenDisposition::IGNORE_ACTION; |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 263 | /////////////////////////////////////////////////////////////////////////////// |
| 264 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 265 | namespace { |
| 266 | |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 267 | content::mojom::WindowContainerType WindowFeaturesToContainerType( |
scottmg | 05324cb | 2017-02-09 23:46:04 | [diff] [blame] | 268 | const blink::WebWindowFeatures& window_features) { |
japhet | bfc4789 | 2017-06-02 23:01:19 | [diff] [blame] | 269 | if (window_features.background) { |
| 270 | if (window_features.persistent) |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 271 | return content::mojom::WindowContainerType::PERSISTENT; |
scottmg | 05324cb | 2017-02-09 23:46:04 | [diff] [blame] | 272 | else |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 273 | return content::mojom::WindowContainerType::BACKGROUND; |
scottmg | 05324cb | 2017-02-09 23:46:04 | [diff] [blame] | 274 | } else { |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 275 | return content::mojom::WindowContainerType::NORMAL; |
scottmg | 05324cb | 2017-02-09 23:46:04 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 279 | } // namespace |
| 280 | |
Hajime Hoshi | 315a61f | 2018-08-14 17:27:28 | [diff] [blame] | 281 | RenderViewImpl::RenderViewImpl(CompositorDependencies* compositor_deps, |
| 282 | const mojom::CreateViewParams& params) |
Albert J. Wong | 7faa3da | 2019-03-21 20:43:43 | [diff] [blame] | 283 | : routing_id_(params.view_id), |
danakj | 73dd303 | 2018-07-28 17:49:53 | [diff] [blame] | 284 | renderer_wide_named_frame_lookup_( |
| 285 | params.renderer_wide_named_frame_lookup), |
danakj | 77eb7e8 | 2020-01-09 19:38:46 | [diff] [blame] | 286 | widgets_never_composited_(params.never_composited), |
danakj | 4b8a2d9a | 2019-10-15 15:53:59 | [diff] [blame] | 287 | compositor_deps_(compositor_deps), |
Jeremy Roman | 3bca4bf | 2019-07-11 03:41:25 | [diff] [blame] | 288 | session_storage_namespace_id_(params.session_storage_namespace_id) { |
Daniel Murphy | 95792ef | 2018-10-04 01:29:55 | [diff] [blame] | 289 | DCHECK(!session_storage_namespace_id_.empty()) |
| 290 | << "Session storage namespace must be populated."; |
Albert J. Wong | 7faa3da | 2019-03-21 20:43:43 | [diff] [blame] | 291 | // Please put all logic in RenderViewImpl::Initialize(). |
| 292 | } |
Albert J. Wong | 7bbf22d | 2018-12-20 00:27:27 | [diff] [blame] | 293 | |
Albert J. Wong | 7faa3da | 2019-03-21 20:43:43 | [diff] [blame] | 294 | void RenderViewImpl::Initialize( |
Erik Chen | 10e9b02 | 2019-08-21 23:33:23 | [diff] [blame] | 295 | CompositorDependencies* compositor_deps, |
Albert J. Wong | 7faa3da | 2019-03-21 20:43:43 | [diff] [blame] | 296 | mojom::CreateViewParamsPtr params, |
| 297 | RenderWidget::ShowCallback show_callback, |
| 298 | scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
Avi Drissman | 07d2245 | 2019-03-25 17:56:39 | [diff] [blame] | 299 | DCHECK(RenderThread::IsMainThread()); |
| 300 | |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 301 | RenderThread::Get()->AddRoute(routing_id_, this); |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 302 | |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 303 | #if defined(OS_ANDROID) |
danakj | c87bfede | 2018-10-10 22:32:49 | [diff] [blame] | 304 | bool has_show_callback = !!show_callback; |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 305 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 306 | |
Antonio Gomes | de8657a45 | 2020-05-25 17:14:47 | [diff] [blame] | 307 | auto opener_frame_token = |
Antonio Gomes | b3dd5fc | 2020-05-25 22:53:27 | [diff] [blame] | 308 | params->opener_frame_token.value_or(base::UnguessableToken()); |
| 309 | auto* opener_frame = WebFrame::FromFrameToken(opener_frame_token); |
Lukasz Anforowicz | af2f3357 | 2018-01-17 14:05:08 | [diff] [blame] | 310 | |
Erik Chen | 562ca42b | 2019-08-22 19:46:06 | [diff] [blame] | 311 | // The newly created webview_ is owned by this instance. |
Gyuyoung Kim | 1c02971 | 2020-07-22 09:21:06 | [diff] [blame] | 312 | webview_ = WebView::Create( |
| 313 | this, params->hidden, |
| 314 | params->type == mojom::ViewWidgetType::kPortal ? true : false, |
| 315 | /*compositing_enabled=*/true, |
| 316 | opener_frame ? opener_frame->View() : nullptr, |
| 317 | std::move(params->blink_page_broadcast)); |
Albert J. Wong | 2727e8a8 | 2019-02-15 16:56:11 | [diff] [blame] | 318 | |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 319 | g_view_map.Get().insert(std::make_pair(GetWebView(), this)); |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 320 | g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this)); |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 321 | |
danakj | 242c2e1 | 2019-10-08 16:34:15 | [diff] [blame] | 322 | bool local_main_frame = params->main_frame_routing_id != MSG_ROUTING_NONE; |
| 323 | |
Gyuyoung Kim | a252d4a | 2020-09-16 07:20:31 | [diff] [blame] | 324 | webview_->SetWebPreferences(params->web_preferences); |
dcheng | 0ff94cfc | 2016-03-15 21:50:51 | [diff] [blame] | 325 | |
danakj | 242c2e1 | 2019-10-08 16:34:15 | [diff] [blame] | 326 | if (local_main_frame) { |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 327 | main_render_frame_ = RenderFrameImpl::CreateMainFrame( |
Erik Chen | 10e9b02 | 2019-08-21 23:33:23 | [diff] [blame] | 328 | this, compositor_deps, opener_frame, ¶ms, std::move(show_callback)); |
danakj | af29226f | 2018-09-25 17:56:57 | [diff] [blame] | 329 | } else { |
Dave Tapuska | 8444938 | 2020-05-01 00:39:04 | [diff] [blame] | 330 | RenderFrameProxy::CreateFrameProxy( |
Antonio Gomes | de8657a45 | 2020-05-25 17:14:47 | [diff] [blame] | 331 | params->proxy_routing_id, GetRoutingID(), opener_frame_token, |
Dave Tapuska | 8444938 | 2020-05-01 00:39:04 | [diff] [blame] | 332 | MSG_ROUTING_NONE, params->replicated_frame_state, |
| 333 | params->main_frame_frame_token, params->devtools_main_frame_token); |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 334 | } |
| 335 | |
[email protected] | c7c0d82 | 2014-04-16 20:19:49 | [diff] [blame] | 336 | // TODO(davidben): Move this state from Blink into content. |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 337 | if (params->window_was_created_with_opener) |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 338 | GetWebView()->SetOpenedByDOM(); |
[email protected] | c7c0d82 | 2014-04-16 20:19:49 | [diff] [blame] | 339 | |
Leon Han | 2c81b5d | 2019-01-25 01:58:33 | [diff] [blame] | 340 | OnSetRendererPrefs(*params->renderer_preferences); |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 341 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 342 | GetContentClient()->renderer()->RenderViewCreated(this); |
Hajime Hoshi | f3437441 | 2018-03-05 14:32:54 | [diff] [blame] | 343 | |
| 344 | nav_state_sync_timer_.SetTaskRunner(task_runner); |
danakj | c87bfede | 2018-10-10 22:32:49 | [diff] [blame] | 345 | |
| 346 | #if defined(OS_ANDROID) |
| 347 | // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated |
| 348 | // HandleNavigation codepath. |
| 349 | // Renderer-created RenderViews have a ShowCallback because they send a Show |
| 350 | // request (ViewHostMsg_ShowWidget, ViewHostMsg_ShowFullscreenWidget, or |
| 351 | // FrameHostMsg_ShowCreatedWindow) to the browser to attach them to the UI |
| 352 | // there. Browser-created RenderViews do not send a Show request to the |
| 353 | // browser, so have no such callback. |
| 354 | was_created_by_renderer_ = has_show_callback; |
| 355 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 356 | } |
| 357 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 358 | RenderViewImpl::~RenderViewImpl() { |
danakj | cdfc426 | 2019-10-01 20:09:48 | [diff] [blame] | 359 | DCHECK(destroying_); // Always deleted through Destroy(). |
danakj | cdfc426 | 2019-10-01 20:09:48 | [diff] [blame] | 360 | |
| 361 | g_routing_id_view_map.Get().erase(routing_id_); |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 362 | RenderThread::Get()->RemoveRoute(routing_id_); |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 363 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 364 | #ifndef NDEBUG |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 365 | // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap. |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 366 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 367 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 368 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 369 | RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer(); |
| 370 | for (RoutingIDViewMap::iterator it = routing_id_views->begin(); |
| 371 | it != routing_id_views->end(); ++it) |
| 372 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 373 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 374 | |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 375 | for (auto& observer : observers_) |
| 376 | observer.RenderViewGone(); |
| 377 | for (auto& observer : observers_) |
| 378 | observer.OnDestruct(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | /*static*/ |
Johann | 6e6d9758 | 2020-07-31 07:54:26 | [diff] [blame] | 382 | RenderView* RenderView::FromWebView(blink::WebView* webview) { |
Avi Drissman | 07d2245 | 2019-03-25 17:56:39 | [diff] [blame] | 383 | DCHECK(RenderThread::IsMainThread()); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 384 | ViewMap* views = g_view_map.Pointer(); |
jdoerrie | 5a73d0fa | 2018-10-02 23:54:05 | [diff] [blame] | 385 | auto it = views->find(webview); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 386 | return it == views->end() ? NULL : it->second; |
| 387 | } |
| 388 | |
| 389 | /*static*/ |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 390 | RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) { |
Avi Drissman | 07d2245 | 2019-03-25 17:56:39 | [diff] [blame] | 391 | DCHECK(RenderThread::IsMainThread()); |
[email protected] | 640e303c | 2012-12-05 01:36:07 | [diff] [blame] | 392 | RoutingIDViewMap* views = g_routing_id_view_map.Pointer(); |
jdoerrie | 5a73d0fa | 2018-10-02 23:54:05 | [diff] [blame] | 393 | auto it = views->find(routing_id); |
[email protected] | 640e303c | 2012-12-05 01:36:07 | [diff] [blame] | 394 | return it == views->end() ? NULL : it->second; |
| 395 | } |
| 396 | |
| 397 | /*static*/ |
| 398 | RenderView* RenderView::FromRoutingID(int routing_id) { |
| 399 | return RenderViewImpl::FromRoutingID(routing_id); |
| 400 | } |
| 401 | |
[email protected] | f3a9531 | 2014-06-12 16:46:58 | [diff] [blame] | 402 | /* static */ |
jochen | 9c7b8f24 | 2015-06-01 15:32:02 | [diff] [blame] | 403 | size_t RenderView::GetRenderViewCount() { |
[email protected] | f3a9531 | 2014-06-12 16:46:58 | [diff] [blame] | 404 | return g_view_map.Get().size(); |
| 405 | } |
| 406 | |
[email protected] | 640e303c | 2012-12-05 01:36:07 | [diff] [blame] | 407 | /*static*/ |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 408 | void RenderView::ForEach(RenderViewVisitor* visitor) { |
Avi Drissman | 07d2245 | 2019-03-25 17:56:39 | [diff] [blame] | 409 | DCHECK(RenderThread::IsMainThread()); |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 410 | ViewMap* views = g_view_map.Pointer(); |
jdoerrie | 5a73d0fa | 2018-10-02 23:54:05 | [diff] [blame] | 411 | for (auto it = views->begin(); it != views->end(); ++it) { |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 412 | if (!visitor->Visit(it->second)) |
| 413 | return; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | /*static*/ |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 418 | RenderViewImpl* RenderViewImpl::Create( |
| 419 | CompositorDependencies* compositor_deps, |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 420 | mojom::CreateViewParamsPtr params, |
danakj | df1ceb7 | 2018-07-18 20:02:25 | [diff] [blame] | 421 | RenderWidget::ShowCallback show_callback, |
Hajime Hoshi | abb3c8f | 2017-12-04 18:41:39 | [diff] [blame] | 422 | scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 423 | DCHECK(params->view_id != MSG_ROUTING_NONE); |
danakj | d434db4 | 2020-01-07 22:27:39 | [diff] [blame] | 424 | // Frame and widget routing ids come together. |
| 425 | DCHECK_EQ(params->main_frame_routing_id == MSG_ROUTING_NONE, |
| 426 | params->main_frame_widget_routing_id == MSG_ROUTING_NONE); |
| 427 | // We have either a main frame or a proxy routing id. |
| 428 | DCHECK_NE(params->main_frame_routing_id != MSG_ROUTING_NONE, |
| 429 | params->proxy_routing_id != MSG_ROUTING_NONE); |
[email protected] | 0287e76 | 2014-04-11 13:07:58 | [diff] [blame] | 430 | |
danakj | d434db4 | 2020-01-07 22:27:39 | [diff] [blame] | 431 | RenderViewImpl* render_view; |
Albert J. Wong | 7faa3da | 2019-03-21 20:43:43 | [diff] [blame] | 432 | if (g_create_render_view_impl) { |
| 433 | render_view = g_create_render_view_impl(compositor_deps, *params); |
| 434 | } else { |
| 435 | render_view = new RenderViewImpl(compositor_deps, *params); |
| 436 | } |
| 437 | |
Erik Chen | 10e9b02 | 2019-08-21 23:33:23 | [diff] [blame] | 438 | render_view->Initialize(compositor_deps, std::move(params), |
Albert J. Wong | 7faa3da | 2019-03-21 20:43:43 | [diff] [blame] | 439 | std::move(show_callback), std::move(task_runner)); |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 440 | return render_view; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 441 | } |
| 442 | |
Erik Chen | 3433ee0 | 2019-08-05 20:14:26 | [diff] [blame] | 443 | void RenderViewImpl::Destroy() { |
danakj | cdfc426 | 2019-10-01 20:09:48 | [diff] [blame] | 444 | destroying_ = true; |
| 445 | |
Erik Chen | 562ca42b | 2019-08-22 19:46:06 | [diff] [blame] | 446 | webview_->Close(); |
Erik Chen | 3433ee0 | 2019-08-05 20:14:26 | [diff] [blame] | 447 | // The webview_ is already destroyed by the time we get here, remove any |
| 448 | // references to it. |
| 449 | g_view_map.Get().erase(webview_); |
| 450 | webview_ = nullptr; |
Erik Chen | 562ca42b | 2019-08-22 19:46:06 | [diff] [blame] | 451 | |
Erik Chen | 3433ee0 | 2019-08-05 20:14:26 | [diff] [blame] | 452 | delete this; |
| 453 | } |
| 454 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 455 | // static |
dcheng | 35d31c11 | 2015-07-22 00:17:36 | [diff] [blame] | 456 | void RenderViewImpl::InstallCreateHook(RenderViewImpl* ( |
| 457 | *create_render_view_impl)(CompositorDependencies* compositor_deps, |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 458 | const mojom::CreateViewParams&)) { |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 459 | CHECK(!g_create_render_view_impl); |
| 460 | g_create_render_view_impl = create_render_view_impl; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 461 | } |
| 462 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 463 | void RenderViewImpl::AddObserver(RenderViewObserver* observer) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 464 | observers_.AddObserver(observer); |
| 465 | } |
| 466 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 467 | void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { |
| 468 | observer->RenderViewGone(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 469 | observers_.RemoveObserver(observer); |
| 470 | } |
| 471 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 472 | // RenderWidgetOwnerDelegate ----------------------------------------- |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 473 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 474 | void RenderViewImpl::SetActiveForWidget(bool active) { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 475 | if (GetWebView()) |
| 476 | GetWebView()->SetIsActive(active); |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 477 | } |
| 478 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 479 | bool RenderViewImpl::SupportsMultipleWindowsForWidget() { |
Gyuyoung Kim | a252d4a | 2020-09-16 07:20:31 | [diff] [blame] | 480 | return webview_->GetWebPreferences().supports_multiple_windows; |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 481 | } |
| 482 | |
David Bokan | 11f6ef48 | 2019-03-18 17:47:27 | [diff] [blame] | 483 | bool RenderViewImpl::ShouldAckSyntheticInputImmediately() { |
| 484 | // TODO(bokan): The RequestPresentation API appears not to function in VR. As |
| 485 | // a short term workaround for https://crbug.com/940063, ACK input |
| 486 | // immediately rather than using RequestPresentation. |
Gyuyoung Kim | a252d4a | 2020-09-16 07:20:31 | [diff] [blame] | 487 | if (webview_->GetWebPreferences().immersive_mode_enabled) |
David Bokan | 11f6ef48 | 2019-03-18 17:47:27 | [diff] [blame] | 488 | return true; |
| 489 | return false; |
| 490 | } |
| 491 | |
Dave Tapuska | 4947078 | 2020-08-11 19:48:33 | [diff] [blame] | 492 | bool RenderViewImpl::AutoResizeMode() { |
| 493 | return GetWebView()->AutoResizeMode(); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 494 | } |
| 495 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 496 | void RenderViewImpl::DidReceiveSetFocusEventForWidget() { |
| 497 | // This message must always be received when the main frame is a |
| 498 | // WebLocalFrame. |
Albert J. Wong | 7bbf22d | 2018-12-20 00:27:27 | [diff] [blame] | 499 | // TODO(ajwong): Can this be removed and just check |delegate_| in |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 500 | // RenderWidget instead? |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 501 | CHECK(GetWebView()->MainFrame()->IsWebLocalFrame()); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 502 | } |
| 503 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 504 | void RenderViewImpl::DidCommitCompositorFrameForWidget() { |
| 505 | for (auto& observer : observers_) |
| 506 | observer.DidCommitCompositorFrame(); |
Antonio Gomes | bc5ef25 | 2020-03-05 10:37:01 | [diff] [blame] | 507 | |
| 508 | if (GetWebView()) |
| 509 | GetWebView()->UpdatePreferredSize(); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | void RenderViewImpl::DidCompletePageScaleAnimationForWidget() { |
| 513 | if (auto* focused_frame = GetWebView()->FocusedFrame()) { |
| 514 | if (focused_frame->AutofillClient()) |
| 515 | focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame(); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | void RenderViewImpl::ResizeWebWidgetForWidget( |
danakj | 748ef909 | 2019-10-17 23:40:53 | [diff] [blame] | 520 | const gfx::Size& widget_size, |
danakj | d4533c7 | 2020-03-11 13:07:10 | [diff] [blame] | 521 | const gfx::Size& visible_viewport_size, |
Sinan Sahin | 92a360bc | 2019-12-05 19:20:45 | [diff] [blame] | 522 | cc::BrowserControlsParams browser_controls_params) { |
danakj | d4533c7 | 2020-03-11 13:07:10 | [diff] [blame] | 523 | GetWebView()->ResizeWithBrowserControls(widget_size, visible_viewport_size, |
| 524 | browser_controls_params); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 525 | } |
| 526 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 527 | // IPC message handlers ----------------------------------------- |
| 528 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 529 | void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset, |
| 530 | int history_length) { |
| 531 | // -1 <= history_offset < history_length <= kMaxSessionHistoryEntries(50). |
| 532 | DCHECK_LE(-1, history_offset); |
| 533 | DCHECK_LT(history_offset, history_length); |
| 534 | DCHECK_LE(history_length, kMaxSessionHistoryEntries); |
| 535 | |
| 536 | history_list_offset_ = history_offset; |
| 537 | history_list_length_ = history_length; |
| 538 | } |
| 539 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 540 | /////////////////////////////////////////////////////////////////////////////// |
| 541 | |
| 542 | void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget, |
| 543 | WebNavigationPolicy policy, |
| 544 | const gfx::Rect& initial_rect) { |
| 545 | Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(), |
| 546 | initial_rect)); |
| 547 | } |
| 548 | |
| 549 | void RenderViewImpl::ShowCreatedFullscreenWidget( |
| 550 | RenderWidget* fullscreen_widget, |
| 551 | WebNavigationPolicy policy, |
| 552 | const gfx::Rect& initial_rect) { |
| 553 | Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(), |
| 554 | fullscreen_widget->routing_id())); |
| 555 | } |
| 556 | |
| 557 | void RenderViewImpl::SendFrameStateUpdates() { |
| 558 | // Tell each frame with pending state to send its UpdateState message. |
| 559 | for (int render_frame_routing_id : frames_with_pending_state_) { |
| 560 | RenderFrameImpl* frame = |
| 561 | RenderFrameImpl::FromRoutingID(render_frame_routing_id); |
| 562 | if (frame) |
| 563 | frame->SendUpdateState(); |
| 564 | } |
| 565 | frames_with_pending_state_.clear(); |
| 566 | } |
| 567 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 568 | // IPC::Listener ------------------------------------------------------------- |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 569 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 570 | bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 571 | WebFrame* main_frame = GetWebView() ? GetWebView()->MainFrame() : nullptr; |
Avi Drissman | b5f8e24 | 2017-12-12 05:21:56 | [diff] [blame] | 572 | if (main_frame) { |
| 573 | GURL active_url; |
| 574 | if (main_frame->IsWebLocalFrame()) |
| 575 | active_url = main_frame->ToWebLocalFrame()->GetDocument().Url(); |
lukasza | bedb4b2 | 2017-06-23 00:00:13 | [diff] [blame] | 576 | GetContentClient()->SetActiveURL( |
Avi Drissman | b5f8e24 | 2017-12-12 05:21:56 | [diff] [blame] | 577 | active_url, main_frame->Top()->GetSecurityOrigin().ToString().Utf8()); |
| 578 | } |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 579 | |
dcheng | a2d442c2 | 2016-10-13 15:39:21 | [diff] [blame] | 580 | for (auto& observer : observers_) { |
| 581 | if (observer.OnMessageReceived(message)) |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 582 | return true; |
dcheng | a2d442c2 | 2016-10-13 15:39:21 | [diff] [blame] | 583 | } |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 584 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 585 | bool handled = true; |
[email protected] | e44d134 | 2014-05-16 21:29:33 | [diff] [blame] | 586 | IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 587 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 588 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 589 | |
| 590 | // Page messages. |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 591 | IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength, |
| 592 | OnSetHistoryOffsetAndLength) |
Bruce Long | 1e3e1f54 | 2019-10-16 17:56:28 | [diff] [blame] | 593 | IPC_MESSAGE_HANDLER(PageMsg_SetRendererPrefs, OnSetRendererPrefs) |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 594 | |
[email protected] | a794f3a | 2013-10-30 17:00:32 | [diff] [blame] | 595 | // Adding a new message? Add platform independent ones first, then put the |
| 596 | // platform specific ones at the end. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 597 | IPC_END_MESSAGE_MAP() |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 598 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 599 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 600 | } |
| 601 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 602 | // blink::WebViewClient ------------------------------------------------------ |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 603 | |
Mustaq Ahmed | 55944cb | 2018-05-25 20:44:27 | [diff] [blame] | 604 | // TODO(csharrison): Migrate this method to WebLocalFrameClient / |
| 605 | // RenderFrameImpl, as it is now serviced by a mojo interface scoped to the |
| 606 | // opener frame. |
Daniel Murphy | c8e991a | 2018-10-12 22:09:03 | [diff] [blame] | 607 | WebView* RenderViewImpl::CreateView( |
| 608 | WebLocalFrame* creator, |
| 609 | const WebURLRequest& request, |
| 610 | const WebWindowFeatures& features, |
| 611 | const WebString& frame_name, |
| 612 | WebNavigationPolicy policy, |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 613 | network::mojom::WebSandboxFlags sandbox_flags, |
Kent Tamura | 326c2db | 2020-07-20 06:28:05 | [diff] [blame] | 614 | const blink::FeaturePolicyFeatureState& opener_feature_state, |
Daniel Murphy | c8e991a | 2018-10-12 22:09:03 | [diff] [blame] | 615 | const blink::SessionStorageNamespaceId& session_storage_namespace_id) { |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 616 | RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator); |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 617 | mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New(); |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 618 | |
Mustaq Ahmed | e5f1256 | 2019-10-30 18:02:03 | [diff] [blame] | 619 | // The user activation check is done at the browser process through |
| 620 | // |frame_host->CreateNewWindow()| call below. But the extensions case |
| 621 | // handled through the following |if| is an exception. |
Mustaq Ahmed | 8601a56 | 2020-01-31 18:05:52 | [diff] [blame] | 622 | params->allow_popup = false; |
[email protected] | 00323f0 | 2013-07-24 15:47:41 | [diff] [blame] | 623 | if (GetContentClient()->renderer()->AllowPopup()) |
Mustaq Ahmed | 8601a56 | 2020-01-31 18:05:52 | [diff] [blame] | 624 | params->allow_popup = true; |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 625 | |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 626 | params->window_container_type = WindowFeaturesToContainerType(features); |
Daniel Murphy | e3eec92c | 2018-02-23 19:09:15 | [diff] [blame] | 627 | |
Daniel Murphy | c8e991a | 2018-10-12 22:09:03 | [diff] [blame] | 628 | params->session_storage_namespace_id = session_storage_namespace_id; |
| 629 | // TODO(dmurph): Don't copy session storage when features.noopener is true: |
| 630 | // https://html.spec.whatwg.org/multipage/browsers.html#copy-session-storage |
| 631 | // https://crbug.com/771959 |
Daniel Murphy | e3eec92c | 2018-02-23 19:09:15 | [diff] [blame] | 632 | params->clone_from_session_storage_namespace_id = |
| 633 | session_storage_namespace_id_; |
Daniel Murphy | e3eec92c | 2018-02-23 19:09:15 | [diff] [blame] | 634 | |
Daniel Cheng | d5e56ff | 2017-06-24 07:44:02 | [diff] [blame] | 635 | const std::string& frame_name_utf8 = frame_name.Utf8( |
| 636 | WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD); |
| 637 | params->frame_name = frame_name_utf8; |
Nate Chapin | 43f307d | 2019-04-15 21:04:41 | [diff] [blame] | 638 | params->opener_suppressed = features.noopener; |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 639 | params->disposition = NavigationPolicyToDisposition(policy); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 640 | if (!request.IsNull()) { |
| 641 | params->target_url = request.Url(); |
Dominic Farolino | aee9c1b8 | 2019-12-18 03:20:10 | [diff] [blame] | 642 | params->referrer = blink::mojom::Referrer::New( |
| 643 | blink::WebStringToGURL(request.ReferrerString()), |
| 644 | request.GetReferrerPolicy()); |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 645 | } |
scottmg | 8e6c608 | 2017-02-13 23:15:48 | [diff] [blame] | 646 | params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 647 | |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 648 | // We preserve this information before sending the message since |params| is |
| 649 | // moved on send. |
| 650 | bool is_background_tab = |
| 651 | params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB; |
[email protected] | 22217ed3 | 2013-11-18 18:40:23 | [diff] [blame] | 652 | |
Daniel Cheng | 8bb30c6 | 2017-10-23 20:40:47 | [diff] [blame] | 653 | mojom::CreateNewWindowStatus status; |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 654 | mojom::CreateNewWindowReplyPtr reply; |
Balazs Engedy | a40712f | 2017-09-15 15:01:11 | [diff] [blame] | 655 | auto* frame_host = creator_frame->GetFrameHost(); |
Daniel Cheng | 8bb30c6 | 2017-10-23 20:40:47 | [diff] [blame] | 656 | bool err = !frame_host->CreateNewWindow(std::move(params), &status, &reply); |
| 657 | if (err || status == mojom::CreateNewWindowStatus::kIgnore) |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 658 | return nullptr; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 659 | |
Jochen Eisinger | 515337a | 2017-05-26 14:12:52 | [diff] [blame] | 660 | // For Android WebView, we support a pop-up like behavior for window.open() |
| 661 | // even if the embedding app doesn't support multiple windows. In this case, |
| 662 | // window.open() will return "window" and navigate it to whatever URL was |
Jochen Eisinger | 8cb2849 | 2017-10-04 10:58:13 | [diff] [blame] | 663 | // passed. We also don't need to consume user gestures to protect against |
| 664 | // multiple windows being opened, because, well, the app doesn't support |
| 665 | // multiple windows. |
Daniel Cheng | 8bb30c6 | 2017-10-23 20:40:47 | [diff] [blame] | 666 | // TODO(dcheng): It's awkward that this is plumbed into Blink but not really |
Kent Tamura | 21d1de6 | 2018-12-10 04:45:20 | [diff] [blame] | 667 | // used much in Blink, except to enable web testing... perhaps this should |
Daniel Cheng | 8bb30c6 | 2017-10-23 20:40:47 | [diff] [blame] | 668 | // be checked directly in the browser side. |
| 669 | if (status == mojom::CreateNewWindowStatus::kReuse) |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 670 | return GetWebView(); |
Jochen Eisinger | 515337a | 2017-05-26 14:12:52 | [diff] [blame] | 671 | |
Daniel Cheng | 8bb30c6 | 2017-10-23 20:40:47 | [diff] [blame] | 672 | DCHECK(reply); |
| 673 | DCHECK_NE(MSG_ROUTING_NONE, reply->route_id); |
| 674 | DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_route_id); |
| 675 | DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_widget_route_id); |
| 676 | |
Mustaq Ahmed | 76c2f431 | 2018-06-07 20:48:01 | [diff] [blame] | 677 | // The browser allowed creation of a new window and consumed the user |
Mustaq Ahmed | e5f1256 | 2019-10-30 18:02:03 | [diff] [blame] | 678 | // activation. |
Mustaq Ahmed | 4baa9a6e8 | 2019-12-20 23:43:46 | [diff] [blame] | 679 | bool was_consumed = creator->ConsumeTransientUserActivation( |
| 680 | blink::UserActivationUpdateSource::kBrowser); |
Jochen Eisinger | 8cb2849 | 2017-10-04 10:58:13 | [diff] [blame] | 681 | |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 682 | // While this view may be a background extension page, it can spawn a visible |
| 683 | // render view. So we just assume that the new one is not another background |
| 684 | // page instead of passing on our own value. |
| 685 | // TODO(vangelis): Can we tell if the new view will be a background page? |
danakj | 77eb7e8 | 2020-01-09 19:38:46 | [diff] [blame] | 686 | bool never_composited = false; |
[email protected] | 9115d5f | 2013-03-24 04:37:41 | [diff] [blame] | 687 | |
[email protected] | d6fa88f | 2013-10-18 16:00:43 | [diff] [blame] | 688 | // The initial hidden state for the RenderViewImpl here has to match what the |
| 689 | // browser will eventually decide for the given disposition. Since we have to |
| 690 | // return from this call synchronously, we just have to make our best guess |
| 691 | // and rely on the browser sending a WasHidden / WasShown message if it |
| 692 | // disagrees. |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 693 | mojom::CreateViewParamsPtr view_params = mojom::CreateViewParams::New(); |
alexmos | 5ac402d | 2015-07-09 07:51:10 | [diff] [blame] | 694 | |
Antonio Gomes | b3dd5fc | 2020-05-25 22:53:27 | [diff] [blame] | 695 | view_params->opener_frame_token = creator->GetFrameToken(); |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 696 | DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID()); |
alexmos | 5ac402d | 2015-07-09 07:51:10 | [diff] [blame] | 697 | |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 698 | view_params->window_was_created_with_opener = true; |
Leon Han | 2c81b5d | 2019-01-25 01:58:33 | [diff] [blame] | 699 | view_params->renderer_preferences = renderer_preferences_.Clone(); |
Gyuyoung Kim | a252d4a | 2020-09-16 07:20:31 | [diff] [blame] | 700 | view_params->web_preferences = webview_->GetWebPreferences(); |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 701 | view_params->view_id = reply->route_id; |
Dave Tapuska | 8444938 | 2020-05-01 00:39:04 | [diff] [blame] | 702 | view_params->main_frame_frame_token = reply->main_frame_frame_token; |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 703 | view_params->main_frame_routing_id = reply->main_frame_route_id; |
Dave Tapuska | 8499eec | 2020-03-16 17:54:30 | [diff] [blame] | 704 | view_params->frame_widget_host = std::move(reply->frame_widget_host); |
| 705 | view_params->frame_widget = std::move(reply->frame_widget); |
| 706 | view_params->widget_host = std::move(reply->widget_host); |
| 707 | view_params->widget = std::move(reply->widget), |
Yuzu Saijo | d46f498a | 2020-08-04 02:56:22 | [diff] [blame] | 708 | view_params->blink_page_broadcast = std::move(reply->page_broadcast); |
Dave Tapuska | 8499eec | 2020-03-16 17:54:30 | [diff] [blame] | 709 | view_params->main_frame_interface_bundle = |
| 710 | mojom::DocumentScopedInterfaceBundle::New( |
| 711 | std::move(reply->main_frame_interface_bundle->interface_provider), |
| 712 | std::move( |
| 713 | reply->main_frame_interface_bundle->browser_interface_broker)); |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 714 | view_params->main_frame_widget_routing_id = reply->main_frame_widget_route_id; |
| 715 | view_params->session_storage_namespace_id = |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 716 | reply->cloned_session_storage_namespace_id; |
Daniel Murphy | 95792ef | 2018-10-04 01:29:55 | [diff] [blame] | 717 | DCHECK(!view_params->session_storage_namespace_id.empty()) |
| 718 | << "Session storage namespace must be populated."; |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 719 | view_params->replicated_frame_state.frame_policy.sandbox_flags = |
| 720 | sandbox_flags; |
Ehsan Karamad | 3940708 | 2019-02-19 23:38:19 | [diff] [blame] | 721 | view_params->replicated_frame_state.opener_feature_state = |
| 722 | opener_feature_state; |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 723 | view_params->replicated_frame_state.name = frame_name_utf8; |
| 724 | view_params->devtools_main_frame_token = reply->devtools_main_frame_token; |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 725 | view_params->hidden = is_background_tab; |
danakj | 77eb7e8 | 2020-01-09 19:38:46 | [diff] [blame] | 726 | view_params->never_composited = never_composited; |
danakj | be56b813 | 2019-10-12 00:57:41 | [diff] [blame] | 727 | view_params->visual_properties = reply->visual_properties; |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 728 | |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 729 | // Unretained() is safe here because our calling function will also call |
| 730 | // show(). |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 731 | RenderWidget::ShowCallback show_callback = |
danakj | df1ceb7 | 2018-07-18 20:02:25 | [diff] [blame] | 732 | base::BindOnce(&RenderFrameImpl::ShowCreatedWindow, |
Mustaq Ahmed | e5f1256 | 2019-10-30 18:02:03 | [diff] [blame] | 733 | base::Unretained(creator_frame), was_consumed); |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 734 | |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 735 | RenderViewImpl* view = RenderViewImpl::Create( |
danakj | 4b8a2d9a | 2019-10-15 15:53:59 | [diff] [blame] | 736 | compositor_deps_, std::move(view_params), std::move(show_callback), |
Hajime Hoshi | 6fc9114 | 2018-05-11 08:21:17 | [diff] [blame] | 737 | creator->GetTaskRunner(blink::TaskType::kInternalDefault)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 738 | |
Yury Semikhatsky | 82730ff | 2020-02-25 22:29:26 | [diff] [blame] | 739 | if (reply->wait_for_debugger) { |
danakj | d370dbb | 2020-05-21 17:54:38 | [diff] [blame] | 740 | blink::WebFrameWidget* frame_widget = |
| 741 | view->GetMainRenderFrame()->GetLocalRootWebFrameWidget(); |
| 742 | frame_widget->WaitForDebuggerWhenShown(); |
Yury Semikhatsky | 82730ff | 2020-02-25 22:29:26 | [diff] [blame] | 743 | } |
| 744 | |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 745 | return view->GetWebView(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 746 | } |
| 747 | |
danakj | 19f3e51 | 2018-12-14 21:02:05 | [diff] [blame] | 748 | blink::WebPagePopup* RenderViewImpl::CreatePopup( |
| 749 | blink::WebLocalFrame* creator) { |
Dave Tapuska | 8499eec | 2020-03-16 17:54:30 | [diff] [blame] | 750 | mojo::PendingAssociatedRemote<blink::mojom::Widget> blink_widget; |
| 751 | mojo::PendingAssociatedReceiver<blink::mojom::Widget> blink_widget_receiver = |
| 752 | blink_widget.InitWithNewEndpointAndPassReceiver(); |
| 753 | |
| 754 | mojo::PendingAssociatedRemote<blink::mojom::WidgetHost> blink_widget_host; |
| 755 | mojo::PendingAssociatedReceiver<blink::mojom::WidgetHost> |
| 756 | blink_widget_host_receiver = |
| 757 | blink_widget_host.InitWithNewEndpointAndPassReceiver(); |
| 758 | |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 759 | // Do a synchronous IPC to obtain a routing ID. |
| 760 | int32_t widget_routing_id = MSG_ROUTING_NONE; |
| 761 | bool success = |
Dave Tapuska | d983562 | 2020-03-10 17:32:31 | [diff] [blame] | 762 | RenderFrameImpl::FromWebFrame(creator)->GetFrameHost()->CreateNewWidget( |
Dave Tapuska | b686c1b | 2020-06-09 00:40:23 | [diff] [blame] | 763 | std::move(blink_widget_host_receiver), std::move(blink_widget), |
| 764 | &widget_routing_id); |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 765 | if (!success) { |
| 766 | // When the renderer is being killed the mojo message will fail. |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 767 | return nullptr; |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | RenderWidget::ShowCallback opener_callback = base::BindOnce( |
| 771 | &RenderViewImpl::ShowCreatedPopupWidget, weak_ptr_factory_.GetWeakPtr()); |
| 772 | |
danakj | 9359397 | 2019-10-11 00:02:49 | [diff] [blame] | 773 | RenderWidget* opener_render_widget = |
Erik Chen | 6bc8da0 | 2019-09-20 15:51:38 | [diff] [blame] | 774 | RenderFrameImpl::FromWebFrame(creator)->GetLocalRootRenderWidget(); |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 775 | |
Erik Chen | 3433ee0 | 2019-08-05 20:14:26 | [diff] [blame] | 776 | RenderWidget* popup_widget = RenderWidget::CreateForPopup( |
danakj | 9359397 | 2019-10-11 00:02:49 | [diff] [blame] | 777 | widget_routing_id, opener_render_widget->compositor_deps(), |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 778 | /*hidden=*/false, |
Dave Tapuska | b686c1b | 2020-06-09 00:40:23 | [diff] [blame] | 779 | /*never_composited=*/false); |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 780 | |
| 781 | // The returned WebPagePopup is self-referencing, so the pointer here is not |
danakj | 45e4a4f | 2019-03-12 22:50:42 | [diff] [blame] | 782 | // an owning pointer. It is de-referenced by calling Close(). |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 783 | blink::WebPagePopup* popup_web_widget = |
Dave Tapuska | 8499eec | 2020-03-16 17:54:30 | [diff] [blame] | 784 | blink::WebPagePopup::Create(popup_widget, std::move(blink_widget_host), |
| 785 | std::move(blink_widget_receiver)); |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 786 | |
| 787 | // Adds a self-reference on the |popup_widget| so it will not be destroyed |
| 788 | // when leaving scope. The WebPagePopup takes responsibility for Close()ing |
| 789 | // and thus destroying the RenderWidget. |
Dave Tapuska | 4fde167 | 2020-08-26 19:53:46 | [diff] [blame] | 790 | popup_widget->InitForPopup( |
| 791 | std::move(opener_callback), opener_render_widget, popup_web_widget, |
| 792 | opener_render_widget->GetWebWidget()->GetOriginalScreenInfo()); |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 793 | return popup_web_widget; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 794 | } |
| 795 | |
Daniel Murphy | 31bbb8b1 | 2018-02-07 21:44:10 | [diff] [blame] | 796 | base::StringPiece RenderViewImpl::GetSessionStorageNamespaceId() { |
| 797 | CHECK(!session_storage_namespace_id_.empty()); |
Daniel Murphy | 0ce6e2c | 2017-11-21 01:54:26 | [diff] [blame] | 798 | return session_storage_namespace_id_; |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 799 | } |
| 800 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 801 | void RenderViewImpl::PrintPage(WebLocalFrame* frame) { |
Erik Chen | faa928c | 2019-09-20 23:41:15 | [diff] [blame] | 802 | RenderFrameImpl* render_frame = RenderFrameImpl::FromWebFrame(frame); |
| 803 | RenderWidget* render_widget = render_frame->GetLocalRootRenderWidget(); |
| 804 | |
| 805 | render_frame->ScriptedPrint( |
Dave Tapuska | 11acff8 | 2020-05-27 16:14:04 | [diff] [blame] | 806 | render_widget->GetWebWidget()->HandlingInputEvent()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 807 | } |
| 808 | |
Dave Tapuska | fd01e9d | 2020-07-29 16:38:19 | [diff] [blame] | 809 | void RenderViewImpl::ZoomLevelChanged() { |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 810 | for (auto& observer : observers_) |
| 811 | observer.OnZoomLevelChanged(); |
danakj | cf409aa | 2019-09-20 15:22:30 | [diff] [blame] | 812 | } |
| 813 | |
danakj | cf409aa | 2019-09-20 15:22:30 | [diff] [blame] | 814 | void RenderViewImpl::SetDeviceScaleFactor(bool use_zoom_for_dsf, |
| 815 | float device_scale_factor) { |
| 816 | if (use_zoom_for_dsf) |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 817 | GetWebView()->SetZoomFactorForDeviceScaleFactor(device_scale_factor); |
danakj | cf409aa | 2019-09-20 15:22:30 | [diff] [blame] | 818 | else |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 819 | GetWebView()->SetDeviceScaleFactor(device_scale_factor); |
danakj | cf409aa | 2019-09-20 15:22:30 | [diff] [blame] | 820 | } |
| 821 | |
danakj | d4533c7 | 2020-03-11 13:07:10 | [diff] [blame] | 822 | void RenderViewImpl::SetVisibleViewportSizeForChildLocalRoot( |
| 823 | const gfx::Size& visible_viewport_size) { |
| 824 | // The main frame is updated on a different path. If we're in the same frame |
| 825 | // tree as it, there's nothing to do for child local roots. |
| 826 | if (main_render_frame_) |
| 827 | return; |
| 828 | |
| 829 | // RenderWidgets in a RenderView's frame tree without a local main frame |
| 830 | // set the size of the WebView to be the |visible_viewport_size|, in order |
| 831 | // to limit compositing in (out of process) child frames to what is visible. |
| 832 | // |
| 833 | // Note that child frames in the same process/RenderView frame tree as the |
| 834 | // main frame do not do this in order to not clobber the source of truth in |
| 835 | // the main frame. |
| 836 | GetWebView()->Resize(visible_viewport_size); |
| 837 | } |
| 838 | |
danakj | cf409aa | 2019-09-20 15:22:30 | [diff] [blame] | 839 | void RenderViewImpl::PropagatePageZoomToNewlyAttachedFrame( |
| 840 | bool use_zoom_for_dsf, |
| 841 | float device_scale_factor) { |
| 842 | if (use_zoom_for_dsf) |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 843 | GetWebView()->SetZoomFactorForDeviceScaleFactor(device_scale_factor); |
danakj | cf409aa | 2019-09-20 15:22:30 | [diff] [blame] | 844 | else |
Dave Tapuska | fd01e9d | 2020-07-29 16:38:19 | [diff] [blame] | 845 | GetWebView()->SetZoomLevel(GetWebView()->ZoomLevel()); |
tommycli | 8aad3ba | 2015-08-12 17:57:59 | [diff] [blame] | 846 | } |
| 847 | |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 848 | void RenderViewImpl::SetValidationMessageDirection( |
| 849 | base::string16* wrapped_main_text, |
Miyoung Shin | 8dabef3 | 2020-02-19 16:25:25 | [diff] [blame] | 850 | base::i18n::TextDirection main_text_hint, |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 851 | base::string16* wrapped_sub_text, |
Miyoung Shin | 8dabef3 | 2020-02-19 16:25:25 | [diff] [blame] | 852 | base::i18n::TextDirection sub_text_hint) { |
| 853 | if (main_text_hint == base::i18n::LEFT_TO_RIGHT) { |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 854 | *wrapped_main_text = |
| 855 | base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text); |
Miyoung Shin | 8dabef3 | 2020-02-19 16:25:25 | [diff] [blame] | 856 | } else if (main_text_hint == base::i18n::RIGHT_TO_LEFT && |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 857 | !base::i18n::IsRTL()) { |
| 858 | base::i18n::WrapStringWithRTLFormatting(wrapped_main_text); |
| 859 | } |
| 860 | |
| 861 | if (!wrapped_sub_text->empty()) { |
Miyoung Shin | 8dabef3 | 2020-02-19 16:25:25 | [diff] [blame] | 862 | if (sub_text_hint == base::i18n::RIGHT_TO_LEFT) { |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 863 | *wrapped_sub_text = |
| 864 | base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text); |
Miyoung Shin | 8dabef3 | 2020-02-19 16:25:25 | [diff] [blame] | 865 | } else if (sub_text_hint == base::i18n::LEFT_TO_RIGHT) { |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 866 | base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text); |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | |
creis | 69b184a47 | 2015-11-26 05:29:51 | [diff] [blame] | 871 | void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) { |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 872 | // Keep track of which frames have pending updates. |
| 873 | frames_with_pending_state_.insert(frame->GetRoutingID()); |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 874 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 875 | int delay; |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 876 | if (send_content_state_immediately_) |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 877 | delay = 0; |
Collin Baker | 98457b5 | 2019-11-06 21:34:29 | [diff] [blame] | 878 | else if (GetWebView()->GetVisibilityState() != PageVisibilityState::kVisible) |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 879 | delay = kDelaySecondsForContentStateSyncHidden; |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 880 | else |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 881 | delay = kDelaySecondsForContentStateSync; |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 882 | |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 883 | if (nav_state_sync_timer_.IsRunning()) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 884 | // The timer is already running. If the delay of the timer maches the amount |
| 885 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 886 | // gets started with the right delay. |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 887 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 888 | return; |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 889 | nav_state_sync_timer_.Stop(); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 890 | } |
| 891 | |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 892 | // Tell each frame with pending state to inform the browser. |
danakj | 19f3e51 | 2018-12-14 21:02:05 | [diff] [blame] | 893 | nav_state_sync_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay), |
| 894 | this, &RenderViewImpl::SendFrameStateUpdates); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 895 | } |
| 896 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 897 | bool RenderViewImpl::AcceptsLoadDrops() { |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 898 | return renderer_preferences_.can_accept_load_drops; |
| 899 | } |
| 900 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 901 | void RenderViewImpl::FocusNext() { |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 902 | Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 903 | } |
| 904 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 905 | void RenderViewImpl::FocusPrevious() { |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 906 | Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 907 | } |
| 908 | |
Philip Rogers | 07965881 | 2018-08-01 23:19:09 | [diff] [blame] | 909 | void RenderViewImpl::DidUpdateMainFrameLayout() { |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 910 | for (auto& observer : observers_) |
Philip Rogers | 07965881 | 2018-08-01 23:19:09 | [diff] [blame] | 911 | observer.DidUpdateMainFrameLayout(); |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 912 | } |
| 913 | |
Michael Martis | 2415478f | 2019-04-17 07:35:00 | [diff] [blame] | 914 | void RenderViewImpl::RegisterRendererPreferenceWatcher( |
Julie Jeongeun Kim | 6d8b749 | 2019-08-20 19:24:11 | [diff] [blame] | 915 | mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) { |
| 916 | renderer_preference_watchers_.Add(std::move(watcher)); |
Makoto Shimazu | c3c730e | 2018-08-15 09:51:11 | [diff] [blame] | 917 | } |
| 918 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 919 | int RenderViewImpl::HistoryBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 920 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 921 | } |
| 922 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 923 | int RenderViewImpl::HistoryForwardListCount() { |
| 924 | return history_list_length_ - HistoryBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 925 | } |
| 926 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 927 | // blink::WebWidgetClient ---------------------------------------------------- |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 928 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 929 | bool RenderViewImpl::CanHandleGestureEvent() { |
slangley | 1a6375e6 | 2017-03-29 06:03:23 | [diff] [blame] | 930 | return true; |
| 931 | } |
| 932 | |
Avi Drissman | 4a80048 | 2019-12-12 15:03:28 | [diff] [blame] | 933 | // TODO(https://crbug.com/937569): Remove this in Chrome 88. |
Avi Drissman | fb96126 | 2019-03-05 22:50:29 | [diff] [blame] | 934 | bool RenderViewImpl::AllowPopupsDuringPageUnload() { |
Avi Drissman | 16dfa1c | 2019-10-09 21:41:13 | [diff] [blame] | 935 | // The switch version is for enabling via enterprise policy. The feature |
| 936 | // version is for enabling via about:flags and Finch policy. |
Avi Drissman | fb96126 | 2019-03-05 22:50:29 | [diff] [blame] | 937 | const base::CommandLine& command_line = |
| 938 | *base::CommandLine::ForCurrentProcess(); |
Avi Drissman | 7e5079f | 2019-09-30 14:06:40 | [diff] [blame] | 939 | return command_line.HasSwitch(switches::kAllowPopupsDuringPageUnload) || |
| 940 | base::FeatureList::IsEnabled(features::kAllowPopupsDuringPageUnload); |
Avi Drissman | fb96126 | 2019-03-05 22:50:29 | [diff] [blame] | 941 | } |
| 942 | |
Yuzu Saijo | be024af0 | 2020-05-11 07:35:56 | [diff] [blame] | 943 | void RenderViewImpl::OnPageVisibilityChanged(PageVisibilityState visibility) { |
| 944 | #if defined(OS_ANDROID) |
| 945 | SuspendVideoCaptureDevices(visibility != PageVisibilityState::kVisible); |
| 946 | #endif |
| 947 | for (auto& observer : observers_) |
| 948 | observer.OnPageVisibilityChanged(visibility); |
| 949 | } |
| 950 | |
Carlos Caballero | 7934eb6 | 2020-08-05 13:24:53 | [diff] [blame] | 951 | void RenderViewImpl::OnPageFrozenChanged(bool frozen) { |
| 952 | if (frozen) { |
| 953 | // Make sure browser has the latest info before the page is frozen. If the |
| 954 | // page goes into the back-forward cache it could be evicted and some of the |
| 955 | // updates lost. |
| 956 | nav_state_sync_timer_.Stop(); |
| 957 | SendFrameStateUpdates(); |
| 958 | } |
| 959 | } |
| 960 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 961 | bool RenderViewImpl::CanUpdateLayout() { |
slangley | 1a6375e6 | 2017-03-29 06:03:23 | [diff] [blame] | 962 | return true; |
| 963 | } |
| 964 | |
Lucas Furukawa Gadani | d51ff5d6 | 2018-12-07 21:26:49 | [diff] [blame] | 965 | const std::string& RenderViewImpl::GetAcceptLanguages() { |
[email protected] | b38806a | 2013-10-04 16:01:38 | [diff] [blame] | 966 | return renderer_preferences_.accept_languages; |
| 967 | } |
| 968 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 969 | blink::WebString RenderViewImpl::AcceptLanguages() { |
| 970 | return WebString::FromUTF8(renderer_preferences_.accept_languages); |
[email protected] | 9982c80 | 2013-06-12 15:22:06 | [diff] [blame] | 971 | } |
| 972 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 973 | // RenderView implementation --------------------------------------------------- |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 974 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 975 | bool RenderViewImpl::Send(IPC::Message* message) { |
danakj | 3130f12 | 2019-07-16 17:49:47 | [diff] [blame] | 976 | // No messages sent through RenderView come without a routing id, yay. Let's |
| 977 | // keep that up. |
| 978 | CHECK_NE(message->routing_id(), MSG_ROUTING_NONE); |
danakj | 3130f12 | 2019-07-16 17:49:47 | [diff] [blame] | 979 | return RenderThread::Get()->Send(message); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 980 | } |
| 981 | |
mostynb | c3335323 | 2014-09-12 09:38:31 | [diff] [blame] | 982 | RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() { |
nasko | 77de231 | 2015-05-12 03:09:16 | [diff] [blame] | 983 | return main_render_frame_; |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 984 | } |
| 985 | |
Lucas Furukawa Gadani | d51ff5d6 | 2018-12-07 21:26:49 | [diff] [blame] | 986 | int RenderViewImpl::GetRoutingID() { |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 987 | return routing_id_; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 988 | } |
| 989 | |
Lucas Furukawa Gadani | d51ff5d6 | 2018-12-07 21:26:49 | [diff] [blame] | 990 | float RenderViewImpl::GetZoomLevel() { |
Dave Tapuska | fd01e9d | 2020-07-29 16:38:19 | [diff] [blame] | 991 | return webview_->ZoomLevel(); |
Marc Treib | 06d6603 | 2017-10-19 08:43:20 | [diff] [blame] | 992 | } |
| 993 | |
Gyuyoung Kim | a252d4a | 2020-09-16 07:20:31 | [diff] [blame] | 994 | const blink::web_pref::WebPreferences& RenderViewImpl::GetBlinkPreferences() { |
| 995 | return webview_->GetWebPreferences(); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 996 | } |
| 997 | |
Gyuyoung Kim | a252d4a | 2020-09-16 07:20:31 | [diff] [blame] | 998 | void RenderViewImpl::SetBlinkPreferences( |
Gyuyoung Kim | 1ac4ca78 | 2020-09-11 03:32:51 | [diff] [blame] | 999 | const blink::web_pref::WebPreferences& preferences) { |
[email protected] | 324825d | 2012-11-30 12:37:15 | [diff] [blame] | 1000 | OnUpdateWebPreferences(preferences); |
| 1001 | } |
| 1002 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1003 | blink::WebView* RenderViewImpl::GetWebView() { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1004 | return webview_; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1005 | } |
| 1006 | |
Lucas Furukawa Gadani | d51ff5d6 | 2018-12-07 21:26:49 | [diff] [blame] | 1007 | bool RenderViewImpl::GetContentStateImmediately() { |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1008 | return send_content_state_immediately_; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1009 | } |
| 1010 | |
Gyuyoung Kim | 1ac4ca78 | 2020-09-11 03:32:51 | [diff] [blame] | 1011 | void RenderViewImpl::OnUpdateWebPreferences( |
| 1012 | const blink::web_pref::WebPreferences& prefs) { |
Gyuyoung Kim | a252d4a | 2020-09-16 07:20:31 | [diff] [blame] | 1013 | webview_->SetWebPreferences(prefs); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1014 | } |
| 1015 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1016 | void RenderViewImpl::OnSetRendererPrefs( |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 1017 | const blink::mojom::RendererPreferences& renderer_prefs) { |
[email protected] | ebd5ea5 | 2014-05-28 14:51:15 | [diff] [blame] | 1018 | std::string old_accept_languages = renderer_preferences_.accept_languages; |
| 1019 | |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1020 | renderer_preferences_ = renderer_prefs; |
ananta | 59b9fe7 | 2015-04-07 01:33:26 | [diff] [blame] | 1021 | |
Julie Jeongeun Kim | 6d8b749 | 2019-08-20 19:24:11 | [diff] [blame] | 1022 | for (auto& watcher : renderer_preference_watchers_) |
| 1023 | watcher->NotifyUpdate(renderer_prefs.Clone()); |
Makoto Shimazu | c3c730e | 2018-08-15 09:51:11 | [diff] [blame] | 1024 | |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 1025 | UpdateFontRenderingFromRendererPrefs(); |
scottmg | b92365e | 2016-08-30 20:54:40 | [diff] [blame] | 1026 | UpdateThemePrefs(); |
Leon Han | 2c81b5d | 2019-01-25 01:58:33 | [diff] [blame] | 1027 | blink::SetCaretBlinkInterval( |
| 1028 | renderer_prefs.caret_blink_interval.has_value() |
| 1029 | ? renderer_prefs.caret_blink_interval.value() |
| 1030 | : base::TimeDelta::FromMilliseconds( |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 1031 | blink::mojom::kDefaultCaretBlinkIntervalInMilliseconds)); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 1032 | |
Christopher Cameron | f8e279d3 | 2019-05-15 18:50:56 | [diff] [blame] | 1033 | #if defined(USE_AURA) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 1034 | if (renderer_prefs.use_custom_colors) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1035 | blink::SetFocusRingColor(renderer_prefs.focus_ring_color); |
Christopher Cameron | f6fc7ec | 2019-05-13 18:52:53 | [diff] [blame] | 1036 | blink::SetSelectionColors(renderer_prefs.active_selection_bg_color, |
| 1037 | renderer_prefs.active_selection_fg_color, |
| 1038 | renderer_prefs.inactive_selection_bg_color, |
| 1039 | renderer_prefs.inactive_selection_fg_color); |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1040 | if (GetWebView() && GetWebView()->MainFrameWidget()) |
| 1041 | GetWebView()->MainFrameWidget()->ThemeChanged(); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 1042 | } |
Christopher Cameron | f8e279d3 | 2019-05-15 18:50:56 | [diff] [blame] | 1043 | #endif |
[email protected] | d299d97 | 2012-03-23 02:26:55 | [diff] [blame] | 1044 | |
Ionel Popescu | 2649f2f | 2020-01-10 10:06:59 | [diff] [blame] | 1045 | if (features::IsFormControlsRefreshEnabled() && |
| 1046 | renderer_prefs.use_custom_colors) { |
| 1047 | blink::SetFocusRingColor(renderer_prefs.focus_ring_color); |
| 1048 | } |
| 1049 | |
Dominic Mazzoni | 554089e | 2020-07-31 22:12:04 | [diff] [blame] | 1050 | if (GetWebView()) { |
| 1051 | if (old_accept_languages != renderer_preferences_.accept_languages) |
| 1052 | GetWebView()->AcceptLanguagesChanged(); |
| 1053 | |
| 1054 | GetWebView()->GetSettings()->SetCaretBrowsingEnabled( |
| 1055 | renderer_preferences_.caret_browsing_enabled); |
[email protected] | ebd5ea5 | 2014-05-28 14:51:15 | [diff] [blame] | 1056 | } |
Alexander Dunaev | 5baa6d64 | 2020-08-10 13:39:07 | [diff] [blame] | 1057 | |
| 1058 | #if defined(USE_X11) || defined(USE_OZONE) |
| 1059 | GetWebView()->GetSettings()->SetSelectionClipboardBufferAvailable( |
| 1060 | renderer_preferences_.selection_clipboard_buffer_available); |
| 1061 | #endif // defined(USE_X11) || defined(USE_OZONE) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1062 | } |
| 1063 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1064 | void RenderViewImpl::OnMoveOrResizeStarted() { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1065 | if (GetWebView()) |
| 1066 | GetWebView()->CancelPagePopup(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 1067 | } |
| 1068 | |
Francois Doray | 47f759d | 2018-06-11 18:13:51 | [diff] [blame] | 1069 | void RenderViewImpl::SetPageFrozen(bool frozen) { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1070 | if (GetWebView()) |
| 1071 | GetWebView()->SetPageFrozen(frozen); |
Fadi Meawad | a6573e0 | 2018-03-10 00:52:11 | [diff] [blame] | 1072 | } |
| 1073 | |
danakj | 9a8a9cf | 2018-07-17 23:52:12 | [diff] [blame] | 1074 | void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) { |
Erik Chen | e4ae6b4 | 2019-10-01 12:06:28 | [diff] [blame] | 1075 | // Auto resize should only happen on local main frames. |
danakj | ee8f490 | 2020-01-17 18:06:10 | [diff] [blame] | 1076 | DCHECK(main_render_frame_); |
| 1077 | main_render_frame_->GetLocalRootRenderWidget()->DidAutoResize(newSize); |
danakj | 9a8a9cf | 2018-07-17 23:52:12 | [diff] [blame] | 1078 | } |
| 1079 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 1080 | #if defined(OS_ANDROID) |
braveyao | 1d8ee7b | 2017-03-29 21:10:04 | [diff] [blame] | 1081 | void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) { |
| 1082 | if (!main_render_frame_) |
| 1083 | return; |
| 1084 | |
Guido Urdaneta | dc709037 | 2019-07-29 17:59:54 | [diff] [blame] | 1085 | blink::WebMediaStreamDeviceObserver* media_stream_device_observer = |
Antonio Gomes | 32f24faf | 2019-08-18 16:41:36 | [diff] [blame] | 1086 | main_render_frame_->MediaStreamDeviceObserver(); |
Chandan Padhi | 26dbd9b3 | 2017-11-27 11:13:35 | [diff] [blame] | 1087 | if (!media_stream_device_observer) |
braveyao | 1d8ee7b | 2017-03-29 21:10:04 | [diff] [blame] | 1088 | return; |
| 1089 | |
Guido Urdaneta | 73fa663 | 2019-01-14 18:46:26 | [diff] [blame] | 1090 | blink::MediaStreamDevices video_devices = |
Chandan Padhi | 26dbd9b3 | 2017-11-27 11:13:35 | [diff] [blame] | 1091 | media_stream_device_observer->GetNonScreenCaptureDevices(); |
braveyao | 1d8ee7b | 2017-03-29 21:10:04 | [diff] [blame] | 1092 | RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices( |
Chandan Padhi | 6dbfb73 | 2017-09-01 16:08:49 | [diff] [blame] | 1093 | video_devices, suspend); |
braveyao | 1d8ee7b | 2017-03-29 21:10:04 | [diff] [blame] | 1094 | } |
estade | 6b9696bd | 2016-05-04 23:51:36 | [diff] [blame] | 1095 | #endif // defined(OS_ANDROID) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 1096 | |
[email protected] | b283d29 | 2013-02-21 08:40:34 | [diff] [blame] | 1097 | unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const { |
| 1098 | return history_list_length_; |
| 1099 | } |
| 1100 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1101 | } // namespace content |