[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] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 59 | #include "content/public/common/web_preferences.h" |
[email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 60 | #include "content/public/renderer/content_renderer_client.h" |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 61 | #include "content/public/renderer/document_state.h" |
Avi Drissman | 07d2245 | 2019-03-25 17:56:39 | [diff] [blame] | 62 | #include "content/public/renderer/render_thread.h" |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 63 | #include "content/public/renderer/render_view_observer.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 64 | #include "content/public/renderer/render_view_visitor.h" |
scottmg | 8e6c608 | 2017-02-13 23:15:48 | [diff] [blame] | 65 | #include "content/public/renderer/window_features_converter.h" |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 66 | #include "content/renderer/drop_data_builder.h" |
[email protected] | dc06435 | 2014-04-25 08:36:38 | [diff] [blame] | 67 | #include "content/renderer/history_serialization.h" |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 68 | #include "content/renderer/ime_event_guard.h" |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 69 | #include "content/renderer/internal_document_state_data.h" |
John Abd-El-Malek | 6b56ef71 | 2017-10-21 22:52:46 | [diff] [blame] | 70 | #include "content/renderer/loader/request_extra_data.h" |
Amos Lim | bcc710e | 2018-06-08 05:51:17 | [diff] [blame] | 71 | #include "content/renderer/media/audio/audio_device_factory.h" |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 72 | #include "content/renderer/render_frame_impl.h" |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 73 | #include "content/renderer/render_frame_proxy.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 74 | #include "content/renderer/render_process.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 75 | #include "content/renderer/render_thread_impl.h" |
[email protected] | 2cff005 | 2011-03-18 16:51:44 | [diff] [blame] | 76 | #include "content/renderer/render_widget_fullscreen_pepper.h" |
Daniel Murphy | e3eec92c | 2018-02-23 19:09:15 | [diff] [blame] | 77 | #include "content/renderer/renderer_blink_platform_impl.h" |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 78 | #include "content/renderer/savable_resources.h" |
John Abd-El-Malek | 312a30bb | 2017-10-23 19:51:52 | [diff] [blame] | 79 | #include "content/renderer/v8_value_converter_impl.h" |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 80 | #include "content/renderer/web_ui_extension_data.h" |
[email protected] | f596114 | 2013-04-17 23:09:42 | [diff] [blame] | 81 | #include "media/audio/audio_output_device.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 82 | #include "media/base/media_switches.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 83 | #include "media/media_buildflags.h" |
servolk | f54f5c8f | 2015-02-24 20:32:39 | [diff] [blame] | 84 | #include "media/renderers/audio_renderer_impl.h" |
Dale Curtis | 863022e | 2017-08-19 02:05:34 | [diff] [blame] | 85 | #include "media/video/gpu_video_accelerator_factories.h" |
Julie Jeongeun Kim | caacf910 | 2019-09-12 02:13:05 | [diff] [blame] | 86 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 87 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 88 | #include "net/base/escape.h" |
| 89 | #include "net/base/net_errors.h" |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame] | 90 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 91 | #include "net/http/http_util.h" |
Tarun Bansal | 73d67f0 | 2018-01-17 05:56:25 | [diff] [blame] | 92 | #include "net/nqe/effective_connection_type.h" |
Scott Violet | 02e38b9 | 2018-03-27 23:42:14 | [diff] [blame] | 93 | #include "ppapi/buildflags/buildflags.h" |
luken | b171b53 | 2014-09-24 05:50:38 | [diff] [blame] | 94 | #include "skia/ext/platform_canvas.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 95 | #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" |
Daniel Murphy | 95792ef | 2018-10-04 01:29:55 | [diff] [blame] | 96 | #include "third_party/blink/public/common/dom_storage/session_storage_namespace_id.h" |
Mustaq Ahmed | 76c2f431 | 2018-06-07 20:48:01 | [diff] [blame] | 97 | #include "third_party/blink/public/common/frame/user_activation_update_source.h" |
Dave Tapuska | 129cef8 | 2019-12-19 16:36:48 | [diff] [blame] | 98 | #include "third_party/blink/public/common/input/web_input_event.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 99 | #include "third_party/blink/public/platform/file_path_conversion.h" |
Antonio Gomes | 925f9b9 | 2019-07-30 23:23:23 | [diff] [blame] | 100 | #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] | 101 | #include "third_party/blink/public/platform/url_conversion.h" |
| 102 | #include "third_party/blink/public/platform/web_connection_type.h" |
| 103 | #include "third_party/blink/public/platform/web_effective_connection_type.h" |
| 104 | #include "third_party/blink/public/platform/web_http_body.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 105 | #include "third_party/blink/public/platform/web_input_event_result.h" |
| 106 | #include "third_party/blink/public/platform/web_network_state_notifier.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 107 | #include "third_party/blink/public/platform/web_rect.h" |
| 108 | #include "third_party/blink/public/platform/web_runtime_features.h" |
| 109 | #include "third_party/blink/public/platform/web_size.h" |
| 110 | #include "third_party/blink/public/platform/web_string.h" |
W. James MacLean | 6219867 | 2019-06-04 16:46:10 | [diff] [blame] | 111 | #include "third_party/blink/public/platform/web_text_autosizer_page_info.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 112 | #include "third_party/blink/public/platform/web_url.h" |
| 113 | #include "third_party/blink/public/platform/web_url_error.h" |
| 114 | #include "third_party/blink/public/platform/web_url_request.h" |
| 115 | #include "third_party/blink/public/platform/web_url_response.h" |
| 116 | #include "third_party/blink/public/platform/web_vector.h" |
| 117 | #include "third_party/blink/public/public_buildflags.h" |
Guido Urdaneta | dc709037 | 2019-07-29 17:59:54 | [diff] [blame] | 118 | #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] | 119 | #include "third_party/blink/public/web/web_autofill_client.h" |
| 120 | #include "third_party/blink/public/web/web_ax_object.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 121 | #include "third_party/blink/public/web/web_document.h" |
| 122 | #include "third_party/blink/public/web/web_dom_event.h" |
| 123 | #include "third_party/blink/public/web/web_dom_message_event.h" |
| 124 | #include "third_party/blink/public/web/web_element.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 125 | #include "third_party/blink/public/web/web_form_control_element.h" |
| 126 | #include "third_party/blink/public/web/web_form_element.h" |
| 127 | #include "third_party/blink/public/web/web_frame.h" |
| 128 | #include "third_party/blink/public/web/web_frame_content_dumper.h" |
| 129 | #include "third_party/blink/public/web/web_frame_widget.h" |
| 130 | #include "third_party/blink/public/web/web_history_item.h" |
| 131 | #include "third_party/blink/public/web/web_hit_test_result.h" |
| 132 | #include "third_party/blink/public/web/web_input_element.h" |
| 133 | #include "third_party/blink/public/web/web_local_frame.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 134 | #include "third_party/blink/public/web/web_navigation_policy.h" |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 135 | #include "third_party/blink/public/web/web_page_popup.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 136 | #include "third_party/blink/public/web/web_plugin.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 137 | #include "third_party/blink/public/web/web_range.h" |
| 138 | #include "third_party/blink/public/web/web_render_theme.h" |
| 139 | #include "third_party/blink/public/web/web_script_source.h" |
| 140 | #include "third_party/blink/public/web/web_searchable_form_data.h" |
| 141 | #include "third_party/blink/public/web/web_security_policy.h" |
| 142 | #include "third_party/blink/public/web/web_settings.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 143 | #include "third_party/blink/public/web/web_view.h" |
| 144 | #include "third_party/blink/public/web/web_window_features.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 145 | #include "third_party/icu/source/common/unicode/uchar.h" |
| 146 | #include "third_party/icu/source/common/unicode/uscript.h" |
eseckler | f2bd55f7 | 2017-03-31 09:11:57 | [diff] [blame] | 147 | #include "third_party/skia/include/core/SkColor.h" |
Ionel Popescu | 2649f2f | 2020-01-10 10:06:59 | [diff] [blame] | 148 | #include "ui/base/ui_base_features.h" |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 149 | #include "ui/base/ui_base_switches_util.h" |
tfarina | 655f81d | 2014-12-23 02:38:50 | [diff] [blame] | 150 | #include "ui/gfx/geometry/point.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 151 | #include "ui/gfx/geometry/rect.h" |
| 152 | #include "ui/gfx/geometry/rect_conversions.h" |
tfarina | ebe974f0 | 2015-01-03 04:25:32 | [diff] [blame] | 153 | #include "ui/gfx/geometry/size_conversions.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 154 | #include "ui/gfx/native_widget_types.h" |
ccameron | 772317d | 2017-06-04 18:35:03 | [diff] [blame] | 155 | #include "ui/gfx/switches.h" |
mfomitchev | 3ba450ad | 2017-04-03 18:20:40 | [diff] [blame] | 156 | #include "ui/latency/latency_info.h" |
csharrison | d88f975 | 2016-10-26 23:56:36 | [diff] [blame] | 157 | #include "url/origin.h" |
markdittmer | 67b71ea | 2016-03-03 22:40:03 | [diff] [blame] | 158 | #include "url/url_constants.h" |
[email protected] | c4a9e93 | 2011-03-05 04:05:55 | [diff] [blame] | 159 | #include "v8/include/v8.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 160 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 161 | #if defined(OS_ANDROID) |
[email protected] | befe5478 | 2013-04-23 00:49:25 | [diff] [blame] | 162 | #include <cpu-features.h> |
| 163 | |
dalecurtis | cd97125 | 2016-09-21 16:09:00 | [diff] [blame] | 164 | #include "base/android/build_info.h" |
kylechar | e7d8d5c7 | 2018-01-05 19:06:28 | [diff] [blame] | 165 | #include "content/child/child_thread_impl.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 166 | #include "ui/gfx/geometry/rect_f.h" |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 167 | |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 168 | #elif defined(OS_MACOSX) |
| 169 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 170 | #endif |
| 171 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 172 | #if BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 173 | #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 174 | #include "content/renderer/pepper/pepper_plugin_registry.h" |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 175 | #endif |
| 176 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 177 | using blink::WebAXObject; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 178 | using blink::WebConsoleMessage; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 179 | using blink::WebData; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 180 | using blink::WebDocument; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 181 | using blink::WebDragOperation; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 182 | using blink::WebElement; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 183 | using blink::WebFormControlElement; |
| 184 | using blink::WebFormElement; |
| 185 | using blink::WebFrame; |
dglazkov | 0322349 | 2016-02-08 22:16:03 | [diff] [blame] | 186 | using blink::WebFrameContentDumper; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 187 | using blink::WebGestureEvent; |
| 188 | using blink::WebHistoryItem; |
dglazkov | 8d0c21dd | 2016-08-06 15:56:36 | [diff] [blame] | 189 | using blink::WebHitTestResult; |
Sergio Villar Senin | eb8c25245 | 2019-10-04 17:18:28 | [diff] [blame] | 190 | using blink::WebHTTPBody; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 191 | using blink::WebInputElement; |
| 192 | using blink::WebInputEvent; |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 193 | using blink::WebLocalFrame; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 194 | using blink::WebMouseEvent; |
| 195 | using blink::WebNavigationPolicy; |
| 196 | using blink::WebNavigationType; |
| 197 | using blink::WebNode; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 198 | using blink::WebRect; |
Sergio Villar Senin | eb8c25245 | 2019-10-04 17:18:28 | [diff] [blame] | 199 | using blink::WebRuntimeFeatures; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 200 | using blink::WebScriptSource; |
| 201 | using blink::WebSearchableFormData; |
| 202 | using blink::WebSecurityOrigin; |
| 203 | using blink::WebSecurityPolicy; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 204 | using blink::WebSettings; |
| 205 | using blink::WebSize; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 206 | using blink::WebString; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 207 | using blink::WebTouchEvent; |
| 208 | using blink::WebURL; |
| 209 | using blink::WebURLError; |
| 210 | using blink::WebURLRequest; |
| 211 | using blink::WebURLResponse; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 212 | using blink::WebVector; |
| 213 | using blink::WebView; |
| 214 | using blink::WebWidget; |
| 215 | using blink::WebWindowFeatures; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 216 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 217 | namespace content { |
| 218 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 219 | //----------------------------------------------------------------------------- |
| 220 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 221 | typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap; |
jbroman | 8319b23 | 2017-03-08 22:53:29 | [diff] [blame] | 222 | static base::LazyInstance<ViewMap>::Leaky g_view_map = |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 223 | LAZY_INSTANCE_INITIALIZER; |
scottmg | 5e65e3a | 2017-03-08 08:48:46 | [diff] [blame] | 224 | typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap; |
jbroman | 8319b23 | 2017-03-08 22:53:29 | [diff] [blame] | 225 | static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map = |
| 226 | LAZY_INSTANCE_INITIALIZER; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 227 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 228 | // Time, in seconds, we delay before sending content state changes (such as form |
| 229 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 230 | // spamming the browser. |
| 231 | // To avoid having tab/session restore require sending a message to get the |
| 232 | // current content state during tab closing we use a shorter timeout for the |
| 233 | // foreground renderer. This means there is a small window of time from which |
| 234 | // content state is modified and not sent to session restore, but this is |
| 235 | // better than having to wake up all renderers during shutdown. |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 236 | const int kDelaySecondsForContentStateSyncHidden = 5; |
| 237 | const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 238 | |
dcheng | 35d31c11 | 2015-07-22 00:17:36 | [diff] [blame] | 239 | static RenderViewImpl* (*g_create_render_view_impl)( |
| 240 | CompositorDependencies* compositor_deps, |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 241 | const mojom::CreateViewParams&) = nullptr; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 242 | |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 243 | // static |
[email protected] | 65920f33 | 2014-03-04 21:14:18 | [diff] [blame] | 244 | WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition( |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 245 | WebNavigationPolicy policy) { |
| 246 | switch (policy) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 247 | case blink::kWebNavigationPolicyDownload: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 248 | return WindowOpenDisposition::SAVE_TO_DISK; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 249 | case blink::kWebNavigationPolicyCurrentTab: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 250 | return WindowOpenDisposition::CURRENT_TAB; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 251 | case blink::kWebNavigationPolicyNewBackgroundTab: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 252 | return WindowOpenDisposition::NEW_BACKGROUND_TAB; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 253 | case blink::kWebNavigationPolicyNewForegroundTab: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 254 | return WindowOpenDisposition::NEW_FOREGROUND_TAB; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 255 | case blink::kWebNavigationPolicyNewWindow: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 256 | return WindowOpenDisposition::NEW_WINDOW; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 257 | case blink::kWebNavigationPolicyNewPopup: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 258 | return WindowOpenDisposition::NEW_POPUP; |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 259 | default: |
| 260 | NOTREACHED() << "Unexpected WebNavigationPolicy"; |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 261 | return WindowOpenDisposition::IGNORE_ACTION; |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 265 | /////////////////////////////////////////////////////////////////////////////// |
| 266 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 267 | namespace { |
| 268 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 269 | typedef void (*SetFontFamilyWrapper)(blink::WebSettings*, |
| 270 | const base::string16&, |
| 271 | UScriptCode); |
| 272 | |
| 273 | void SetStandardFontFamilyWrapper(WebSettings* settings, |
| 274 | const base::string16& font, |
| 275 | UScriptCode script) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 276 | settings->SetStandardFontFamily(WebString::FromUTF16(font), script); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | void SetFixedFontFamilyWrapper(WebSettings* settings, |
| 280 | const base::string16& font, |
| 281 | UScriptCode script) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 282 | settings->SetFixedFontFamily(WebString::FromUTF16(font), script); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void SetSerifFontFamilyWrapper(WebSettings* settings, |
| 286 | const base::string16& font, |
| 287 | UScriptCode script) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 288 | settings->SetSerifFontFamily(WebString::FromUTF16(font), script); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | void SetSansSerifFontFamilyWrapper(WebSettings* settings, |
| 292 | const base::string16& font, |
| 293 | UScriptCode script) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 294 | settings->SetSansSerifFontFamily(WebString::FromUTF16(font), script); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | void SetCursiveFontFamilyWrapper(WebSettings* settings, |
| 298 | const base::string16& font, |
| 299 | UScriptCode script) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 300 | settings->SetCursiveFontFamily(WebString::FromUTF16(font), script); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | void SetFantasyFontFamilyWrapper(WebSettings* settings, |
| 304 | const base::string16& font, |
| 305 | UScriptCode script) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 306 | settings->SetFantasyFontFamily(WebString::FromUTF16(font), script); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | void SetPictographFontFamilyWrapper(WebSettings* settings, |
| 310 | const base::string16& font, |
| 311 | UScriptCode script) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 312 | settings->SetPictographFontFamily(WebString::FromUTF16(font), script); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | // If |scriptCode| is a member of a family of "similar" script codes, returns |
| 316 | // the script code in that family that is used by WebKit for font selection |
| 317 | // purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are |
| 318 | // considered equivalent for the purposes of font selection. WebKit uses the |
| 319 | // script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is |
| 320 | // USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit |
| 321 | // uses different scripts than the ones in Chrome pref names because the version |
| 322 | // of ICU included on certain ports does not have some of the newer scripts. If |
| 323 | // |scriptCode| is not a member of such a family, returns |scriptCode|. |
| 324 | UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) { |
| 325 | switch (scriptCode) { |
| 326 | case USCRIPT_HIRAGANA: |
| 327 | case USCRIPT_KATAKANA: |
| 328 | case USCRIPT_JAPANESE: |
| 329 | return USCRIPT_KATAKANA_OR_HIRAGANA; |
| 330 | case USCRIPT_KOREAN: |
| 331 | return USCRIPT_HANGUL; |
| 332 | default: |
| 333 | return scriptCode; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | void ApplyFontsFromMap(const ScriptFontFamilyMap& map, |
| 338 | SetFontFamilyWrapper setter, |
| 339 | WebSettings* settings) { |
jdoerrie | 5a73d0fa | 2018-10-02 23:54:05 | [diff] [blame] | 340 | for (auto it = map.begin(); it != map.end(); ++it) { |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 341 | int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str()); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 342 | if (script >= 0 && script < USCRIPT_CODE_LIMIT) { |
| 343 | UScriptCode code = static_cast<UScriptCode>(script); |
| 344 | (*setter)(settings, it->second, GetScriptForWebSettings(code)); |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | |
danakj | efcb843 | 2019-01-16 18:47:14 | [diff] [blame] | 349 | void ApplyCommandLineToSettings(WebSettings* settings) { |
| 350 | const base::CommandLine& command_line = |
| 351 | *base::CommandLine::ForCurrentProcess(); |
| 352 | |
danakj | ed946461 | 2019-01-16 00:00:59 | [diff] [blame] | 353 | settings->SetThreadedScrollingEnabled( |
| 354 | !command_line.HasSwitch(switches::kDisableThreadedScrolling)); |
wangxianzhu | 3bf39be5 | 2015-04-10 23:56:41 | [diff] [blame] | 355 | |
danakj | ed946461 | 2019-01-16 00:00:59 | [diff] [blame] | 356 | if (switches::IsTouchDragDropEnabled()) |
| 357 | settings->SetTouchDragDropEnabled(true); |
| 358 | |
| 359 | WebSettings::SelectionStrategyType selection_strategy; |
| 360 | if (command_line.GetSwitchValueASCII(switches::kTouchTextSelectionStrategy) == |
| 361 | "direction") |
| 362 | selection_strategy = WebSettings::SelectionStrategyType::kDirection; |
| 363 | else |
| 364 | selection_strategy = WebSettings::SelectionStrategyType::kCharacter; |
| 365 | settings->SetSelectionStrategy(selection_strategy); |
| 366 | |
| 367 | std::string passive_listeners_default = |
| 368 | command_line.GetSwitchValueASCII(switches::kPassiveListenersDefault); |
| 369 | if (!passive_listeners_default.empty()) { |
| 370 | WebSettings::PassiveEventListenerDefault passive_default = |
| 371 | WebSettings::PassiveEventListenerDefault::kFalse; |
| 372 | if (passive_listeners_default == "true") |
| 373 | passive_default = WebSettings::PassiveEventListenerDefault::kTrue; |
| 374 | else if (passive_listeners_default == "forcealltrue") |
| 375 | passive_default = WebSettings::PassiveEventListenerDefault::kForceAllTrue; |
| 376 | settings->SetPassiveEventListenerDefault(passive_default); |
| 377 | } |
| 378 | |
| 379 | std::string network_quiet_timeout = |
| 380 | command_line.GetSwitchValueASCII(switches::kNetworkQuietTimeout); |
| 381 | if (!network_quiet_timeout.empty()) { |
| 382 | double network_quiet_timeout_seconds = 0.0; |
| 383 | if (base::StringToDouble(network_quiet_timeout, |
| 384 | &network_quiet_timeout_seconds)) |
| 385 | settings->SetNetworkQuietTimeout(network_quiet_timeout_seconds); |
| 386 | } |
| 387 | |
| 388 | if (command_line.HasSwitch(switches::kBlinkSettings)) { |
| 389 | std::vector<std::string> blink_settings = base::SplitString( |
| 390 | command_line.GetSwitchValueASCII(switches::kBlinkSettings), ",", |
| 391 | base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 392 | for (const std::string& setting : blink_settings) { |
| 393 | size_t pos = setting.find('='); |
| 394 | settings->SetFromStrings( |
| 395 | blink::WebString::FromLatin1(setting.substr(0, pos)), |
| 396 | blink::WebString::FromLatin1( |
| 397 | pos == std::string::npos ? "" : setting.substr(pos + 1))); |
| 398 | } |
wangxianzhu | 3bf39be5 | 2015-04-10 23:56:41 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 402 | content::mojom::WindowContainerType WindowFeaturesToContainerType( |
scottmg | 05324cb | 2017-02-09 23:46:04 | [diff] [blame] | 403 | const blink::WebWindowFeatures& window_features) { |
japhet | bfc4789 | 2017-06-02 23:01:19 | [diff] [blame] | 404 | if (window_features.background) { |
| 405 | if (window_features.persistent) |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 406 | return content::mojom::WindowContainerType::PERSISTENT; |
scottmg | 05324cb | 2017-02-09 23:46:04 | [diff] [blame] | 407 | else |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 408 | return content::mojom::WindowContainerType::BACKGROUND; |
scottmg | 05324cb | 2017-02-09 23:46:04 | [diff] [blame] | 409 | } else { |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 410 | return content::mojom::WindowContainerType::NORMAL; |
scottmg | 05324cb | 2017-02-09 23:46:04 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 414 | } // namespace |
| 415 | |
Hajime Hoshi | 315a61f | 2018-08-14 17:27:28 | [diff] [blame] | 416 | RenderViewImpl::RenderViewImpl(CompositorDependencies* compositor_deps, |
| 417 | const mojom::CreateViewParams& params) |
Albert J. Wong | 7faa3da | 2019-03-21 20:43:43 | [diff] [blame] | 418 | : routing_id_(params.view_id), |
danakj | 73dd303 | 2018-07-28 17:49:53 | [diff] [blame] | 419 | renderer_wide_named_frame_lookup_( |
| 420 | params.renderer_wide_named_frame_lookup), |
danakj | 77eb7e8 | 2020-01-09 19:38:46 | [diff] [blame] | 421 | widgets_never_composited_(params.never_composited), |
danakj | 4b8a2d9a | 2019-10-15 15:53:59 | [diff] [blame] | 422 | compositor_deps_(compositor_deps), |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 423 | webkit_preferences_(params.web_preferences), |
Jeremy Roman | 3bca4bf | 2019-07-11 03:41:25 | [diff] [blame] | 424 | session_storage_namespace_id_(params.session_storage_namespace_id) { |
Daniel Murphy | 95792ef | 2018-10-04 01:29:55 | [diff] [blame] | 425 | DCHECK(!session_storage_namespace_id_.empty()) |
| 426 | << "Session storage namespace must be populated."; |
Albert J. Wong | 7faa3da | 2019-03-21 20:43:43 | [diff] [blame] | 427 | // Please put all logic in RenderViewImpl::Initialize(). |
| 428 | } |
Albert J. Wong | 7bbf22d | 2018-12-20 00:27:27 | [diff] [blame] | 429 | |
Albert J. Wong | 7faa3da | 2019-03-21 20:43:43 | [diff] [blame] | 430 | void RenderViewImpl::Initialize( |
Erik Chen | 10e9b02 | 2019-08-21 23:33:23 | [diff] [blame] | 431 | CompositorDependencies* compositor_deps, |
Albert J. Wong | 7faa3da | 2019-03-21 20:43:43 | [diff] [blame] | 432 | mojom::CreateViewParamsPtr params, |
| 433 | RenderWidget::ShowCallback show_callback, |
| 434 | scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
Avi Drissman | 07d2245 | 2019-03-25 17:56:39 | [diff] [blame] | 435 | DCHECK(RenderThread::IsMainThread()); |
| 436 | |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 437 | RenderThread::Get()->AddRoute(routing_id_, this); |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 438 | |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 439 | #if defined(OS_ANDROID) |
danakj | c87bfede | 2018-10-10 22:32:49 | [diff] [blame] | 440 | bool has_show_callback = !!show_callback; |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 441 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 442 | |
Antonio Gomes | de8657a45 | 2020-05-25 17:14:47 | [diff] [blame] | 443 | auto opener_frame_token = |
Antonio Gomes | b3dd5fc | 2020-05-25 22:53:27 | [diff] [blame^] | 444 | params->opener_frame_token.value_or(base::UnguessableToken()); |
| 445 | auto* opener_frame = WebFrame::FromFrameToken(opener_frame_token); |
Lukasz Anforowicz | af2f3357 | 2018-01-17 14:05:08 | [diff] [blame] | 446 | |
Erik Chen | 562ca42b | 2019-08-22 19:46:06 | [diff] [blame] | 447 | // The newly created webview_ is owned by this instance. |
danakj | 284d557d | 2019-01-16 17:00:26 | [diff] [blame] | 448 | webview_ = WebView::Create(this, params->hidden, |
Sadrul Habib Chowdhury | 042a471 | 2018-12-06 00:16:56 | [diff] [blame] | 449 | /*compositing_enabled=*/true, |
Yuzu Saijo | 797151f | 2020-02-28 09:08:27 | [diff] [blame] | 450 | opener_frame ? opener_frame->View() : nullptr, |
Daniel Cheng | 9a7c6c8 | 2020-04-25 04:58:17 | [diff] [blame] | 451 | std::move(params->blink_page_broadcast)); |
Albert J. Wong | 2727e8a8 | 2019-02-15 16:56:11 | [diff] [blame] | 452 | |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 453 | g_view_map.Get().insert(std::make_pair(GetWebView(), this)); |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 454 | g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this)); |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 455 | |
danakj | 242c2e1 | 2019-10-08 16:34:15 | [diff] [blame] | 456 | bool local_main_frame = params->main_frame_routing_id != MSG_ROUTING_NONE; |
| 457 | |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 458 | ApplyWebPreferences(webkit_preferences_, GetWebView()); |
| 459 | ApplyCommandLineToSettings(GetWebView()->GetSettings()); |
dcheng | 0ff94cfc | 2016-03-15 21:50:51 | [diff] [blame] | 460 | |
danakj | 242c2e1 | 2019-10-08 16:34:15 | [diff] [blame] | 461 | if (local_main_frame) { |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 462 | main_render_frame_ = RenderFrameImpl::CreateMainFrame( |
Erik Chen | 10e9b02 | 2019-08-21 23:33:23 | [diff] [blame] | 463 | this, compositor_deps, opener_frame, ¶ms, std::move(show_callback)); |
danakj | af29226f | 2018-09-25 17:56:57 | [diff] [blame] | 464 | } else { |
Dave Tapuska | 8444938 | 2020-05-01 00:39:04 | [diff] [blame] | 465 | RenderFrameProxy::CreateFrameProxy( |
Antonio Gomes | de8657a45 | 2020-05-25 17:14:47 | [diff] [blame] | 466 | params->proxy_routing_id, GetRoutingID(), opener_frame_token, |
Dave Tapuska | 8444938 | 2020-05-01 00:39:04 | [diff] [blame] | 467 | MSG_ROUTING_NONE, params->replicated_frame_state, |
| 468 | params->main_frame_frame_token, params->devtools_main_frame_token); |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 469 | } |
| 470 | |
[email protected] | c7c0d82 | 2014-04-16 20:19:49 | [diff] [blame] | 471 | // TODO(davidben): Move this state from Blink into content. |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 472 | if (params->window_was_created_with_opener) |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 473 | GetWebView()->SetOpenedByDOM(); |
[email protected] | c7c0d82 | 2014-04-16 20:19:49 | [diff] [blame] | 474 | |
Leon Han | 2c81b5d | 2019-01-25 01:58:33 | [diff] [blame] | 475 | OnSetRendererPrefs(*params->renderer_preferences); |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 476 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 477 | GetContentClient()->renderer()->RenderViewCreated(this); |
Hajime Hoshi | f3437441 | 2018-03-05 14:32:54 | [diff] [blame] | 478 | |
| 479 | nav_state_sync_timer_.SetTaskRunner(task_runner); |
danakj | c87bfede | 2018-10-10 22:32:49 | [diff] [blame] | 480 | |
Adithya Srinivasan | 46b8a79 | 2019-02-01 14:47:23 | [diff] [blame] | 481 | // We pass this state to Page, but it's only used by the main frame in the |
| 482 | // page. |
| 483 | if (params->inside_portal) |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 484 | GetWebView()->SetInsidePortal(true); |
Adithya Srinivasan | 46b8a79 | 2019-02-01 14:47:23 | [diff] [blame] | 485 | |
danakj | c87bfede | 2018-10-10 22:32:49 | [diff] [blame] | 486 | #if defined(OS_ANDROID) |
| 487 | // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated |
| 488 | // HandleNavigation codepath. |
| 489 | // Renderer-created RenderViews have a ShowCallback because they send a Show |
| 490 | // request (ViewHostMsg_ShowWidget, ViewHostMsg_ShowFullscreenWidget, or |
| 491 | // FrameHostMsg_ShowCreatedWindow) to the browser to attach them to the UI |
| 492 | // there. Browser-created RenderViews do not send a Show request to the |
| 493 | // browser, so have no such callback. |
| 494 | was_created_by_renderer_ = has_show_callback; |
| 495 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 496 | } |
| 497 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 498 | RenderViewImpl::~RenderViewImpl() { |
danakj | cdfc426 | 2019-10-01 20:09:48 | [diff] [blame] | 499 | DCHECK(destroying_); // Always deleted through Destroy(). |
danakj | cdfc426 | 2019-10-01 20:09:48 | [diff] [blame] | 500 | |
| 501 | g_routing_id_view_map.Get().erase(routing_id_); |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 502 | RenderThread::Get()->RemoveRoute(routing_id_); |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 503 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 504 | #ifndef NDEBUG |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 505 | // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap. |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 506 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 507 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 508 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 509 | RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer(); |
| 510 | for (RoutingIDViewMap::iterator it = routing_id_views->begin(); |
| 511 | it != routing_id_views->end(); ++it) |
| 512 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 513 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 514 | |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 515 | for (auto& observer : observers_) |
| 516 | observer.RenderViewGone(); |
| 517 | for (auto& observer : observers_) |
| 518 | observer.OnDestruct(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 522 | RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) { |
Avi Drissman | 07d2245 | 2019-03-25 17:56:39 | [diff] [blame] | 523 | DCHECK(RenderThread::IsMainThread()); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 524 | ViewMap* views = g_view_map.Pointer(); |
jdoerrie | 5a73d0fa | 2018-10-02 23:54:05 | [diff] [blame] | 525 | auto it = views->find(webview); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 526 | return it == views->end() ? NULL : it->second; |
| 527 | } |
| 528 | |
| 529 | /*static*/ |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 530 | RenderView* RenderView::FromWebView(blink::WebView* webview) { |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 531 | return RenderViewImpl::FromWebView(webview); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | /*static*/ |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 535 | RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) { |
Avi Drissman | 07d2245 | 2019-03-25 17:56:39 | [diff] [blame] | 536 | DCHECK(RenderThread::IsMainThread()); |
[email protected] | 640e303c | 2012-12-05 01:36:07 | [diff] [blame] | 537 | RoutingIDViewMap* views = g_routing_id_view_map.Pointer(); |
jdoerrie | 5a73d0fa | 2018-10-02 23:54:05 | [diff] [blame] | 538 | auto it = views->find(routing_id); |
[email protected] | 640e303c | 2012-12-05 01:36:07 | [diff] [blame] | 539 | return it == views->end() ? NULL : it->second; |
| 540 | } |
| 541 | |
| 542 | /*static*/ |
| 543 | RenderView* RenderView::FromRoutingID(int routing_id) { |
| 544 | return RenderViewImpl::FromRoutingID(routing_id); |
| 545 | } |
| 546 | |
[email protected] | f3a9531 | 2014-06-12 16:46:58 | [diff] [blame] | 547 | /* static */ |
jochen | 9c7b8f24 | 2015-06-01 15:32:02 | [diff] [blame] | 548 | size_t RenderView::GetRenderViewCount() { |
[email protected] | f3a9531 | 2014-06-12 16:46:58 | [diff] [blame] | 549 | return g_view_map.Get().size(); |
| 550 | } |
| 551 | |
[email protected] | 640e303c | 2012-12-05 01:36:07 | [diff] [blame] | 552 | /*static*/ |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 553 | void RenderView::ForEach(RenderViewVisitor* visitor) { |
Avi Drissman | 07d2245 | 2019-03-25 17:56:39 | [diff] [blame] | 554 | DCHECK(RenderThread::IsMainThread()); |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 555 | ViewMap* views = g_view_map.Pointer(); |
jdoerrie | 5a73d0fa | 2018-10-02 23:54:05 | [diff] [blame] | 556 | for (auto it = views->begin(); it != views->end(); ++it) { |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 557 | if (!visitor->Visit(it->second)) |
| 558 | return; |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | /*static*/ |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 563 | void RenderView::ApplyWebPreferences(const WebPreferences& prefs, |
| 564 | WebView* web_view) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 565 | WebSettings* settings = web_view->GetSettings(); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 566 | ApplyFontsFromMap(prefs.standard_font_family_map, |
| 567 | SetStandardFontFamilyWrapper, settings); |
| 568 | ApplyFontsFromMap(prefs.fixed_font_family_map, |
| 569 | SetFixedFontFamilyWrapper, settings); |
| 570 | ApplyFontsFromMap(prefs.serif_font_family_map, |
| 571 | SetSerifFontFamilyWrapper, settings); |
| 572 | ApplyFontsFromMap(prefs.sans_serif_font_family_map, |
| 573 | SetSansSerifFontFamilyWrapper, settings); |
| 574 | ApplyFontsFromMap(prefs.cursive_font_family_map, |
| 575 | SetCursiveFontFamilyWrapper, settings); |
| 576 | ApplyFontsFromMap(prefs.fantasy_font_family_map, |
| 577 | SetFantasyFontFamilyWrapper, settings); |
| 578 | ApplyFontsFromMap(prefs.pictograph_font_family_map, |
| 579 | SetPictographFontFamilyWrapper, settings); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 580 | settings->SetDefaultFontSize(prefs.default_font_size); |
| 581 | settings->SetDefaultFixedFontSize(prefs.default_fixed_font_size); |
| 582 | settings->SetMinimumFontSize(prefs.minimum_font_size); |
| 583 | settings->SetMinimumLogicalFontSize(prefs.minimum_logical_font_size); |
| 584 | settings->SetDefaultTextEncodingName( |
| 585 | WebString::FromASCII(prefs.default_encoding)); |
| 586 | settings->SetJavaScriptEnabled(prefs.javascript_enabled); |
| 587 | settings->SetWebSecurityEnabled(prefs.web_security_enabled); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 588 | settings->SetLoadsImagesAutomatically(prefs.loads_images_automatically); |
| 589 | settings->SetImagesEnabled(prefs.images_enabled); |
| 590 | settings->SetPluginsEnabled(prefs.plugins_enabled); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 591 | settings->SetDOMPasteAllowed(prefs.dom_paste_enabled); |
| 592 | settings->SetTextAreasAreResizable(prefs.text_areas_are_resizable); |
| 593 | settings->SetAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows); |
| 594 | settings->SetDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled); |
| 595 | settings->SetJavaScriptCanAccessClipboard( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 596 | prefs.javascript_can_access_clipboard); |
Chris Cunningham | e9b5ad74 | 2019-04-23 19:40:38 | [diff] [blame] | 597 | WebRuntimeFeatures::EnableXSLT(prefs.xslt_enabled); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 598 | settings->SetDNSPrefetchingEnabled(prefs.dns_prefetching_enabled); |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 599 | blink::WebNetworkStateNotifier::SetSaveDataEnabled(prefs.data_saver_enabled); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 600 | settings->SetLocalStorageEnabled(prefs.local_storage_enabled); |
| 601 | settings->SetSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled); |
| 602 | WebRuntimeFeatures::EnableDatabase(prefs.databases_enabled); |
| 603 | settings->SetOfflineWebApplicationCacheEnabled( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 604 | prefs.application_cache_enabled); |
Arthur Sonzogni | 721f48e | 2018-10-31 17:10:02 | [diff] [blame] | 605 | settings->SetShouldProtectAgainstIpcFlooding( |
| 606 | !prefs.disable_ipc_flooding_protection); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 607 | settings->SetHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled); |
| 608 | settings->SetCookieEnabled(prefs.cookie_enabled); |
| 609 | settings->SetNavigateOnDragDrop(prefs.navigate_on_drag_drop); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 610 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 611 | // By default, allow_universal_access_from_file_urls is set to false and thus |
| 612 | // we mitigate attacks from local HTML files by not granting file:// URLs |
| 613 | // universal access. Only test shell will enable this. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 614 | settings->SetAllowUniversalAccessFromFileURLs( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 615 | prefs.allow_universal_access_from_file_urls); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 616 | settings->SetAllowFileAccessFromFileURLs( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 617 | prefs.allow_file_access_from_file_urls); |
| 618 | |
Zhenyao Mo | a3fda997 | 2017-09-16 01:34:40 | [diff] [blame] | 619 | settings->SetWebGL1Enabled(prefs.webgl1_enabled); |
| 620 | settings->SetWebGL2Enabled(prefs.webgl2_enabled); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 621 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 622 | // Enable WebGL errors to the JS console if requested. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 623 | settings->SetWebGLErrorsToConsoleEnabled( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 624 | prefs.webgl_errors_to_console_enabled); |
| 625 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 626 | settings->SetHideScrollbars(prefs.hide_scrollbars); |
eseckler | 61ff914 | 2016-09-23 22:57:59 | [diff] [blame] | 627 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 628 | // Enable gpu-accelerated 2d canvas if requested on the command line. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 629 | WebRuntimeFeatures::EnableAccelerated2dCanvas( |
junov | 524668f2 | 2016-08-08 20:16:52 | [diff] [blame] | 630 | prefs.accelerated_2d_canvas_enabled); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 631 | |
Aaron Krajeski | 229cffd | 2020-05-11 22:30:33 | [diff] [blame] | 632 | // Enable new canvas 2d api features |
| 633 | WebRuntimeFeatures::EnableNewCanvas2DAPI(prefs.new_canvas_2d_api_enabled); |
| 634 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 635 | // Disable antialiasing for 2d canvas if requested on the command line. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 636 | settings->SetAntialiased2dCanvasEnabled( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 637 | !prefs.antialiased_2d_canvas_disabled); |
| 638 | |
zakerinasab | 20ebca0 | 2016-09-27 14:22:34 | [diff] [blame] | 639 | // Disable antialiasing of clips for 2d canvas if requested on the command |
robertphillips | e25137b | 2014-10-20 13:44:34 | [diff] [blame] | 640 | // line. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 641 | settings->SetAntialiasedClips2dCanvasEnabled( |
robertphillips | e25137b | 2014-10-20 13:44:34 | [diff] [blame] | 642 | prefs.antialiased_clips_2d_canvas_enabled); |
| 643 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 644 | // Set MSAA sample count for 2d canvas if requested on the command line (or |
| 645 | // default value if not). |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 646 | settings->SetAccelerated2dCanvasMSAASampleCount( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 647 | prefs.accelerated_2d_canvas_msaa_sample_count); |
| 648 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 649 | // Tabs to link is not part of the settings. WebCore calls |
| 650 | // ChromeClient::tabsToLinks which is part of the glue code. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 651 | web_view->SetTabsToLinks(prefs.tabs_to_links); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 652 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 653 | settings->SetAllowRunningOfInsecureContent( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 654 | prefs.allow_running_insecure_content); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 655 | settings->SetDisableReadingFromCanvas(prefs.disable_reading_from_canvas); |
| 656 | settings->SetStrictMixedContentChecking(prefs.strict_mixed_content_checking); |
mkwst | 2384c822 | 2015-07-30 07:26:47 | [diff] [blame] | 657 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 658 | settings->SetStrictlyBlockBlockableMixedContent( |
mkwst | 2384c822 | 2015-07-30 07:26:47 | [diff] [blame] | 659 | prefs.strictly_block_blockable_mixed_content); |
| 660 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 661 | settings->SetStrictMixedContentCheckingForPlugin( |
mkwst | 0d233e5 | 2015-08-10 09:33:14 | [diff] [blame] | 662 | prefs.block_mixed_plugin_content); |
| 663 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 664 | settings->SetStrictPowerfulFeatureRestrictions( |
mkwst | 673a452f | 2015-01-10 14:41:50 | [diff] [blame] | 665 | prefs.strict_powerful_feature_restrictions); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 666 | settings->SetAllowGeolocationOnInsecureOrigins( |
jww | 9d4ca2d | 2016-01-19 20:58:59 | [diff] [blame] | 667 | prefs.allow_geolocation_on_insecure_origins); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 668 | settings->SetPasswordEchoEnabled(prefs.password_echo_enabled); |
| 669 | settings->SetShouldPrintBackgrounds(prefs.should_print_backgrounds); |
| 670 | settings->SetShouldClearDocumentBackground( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 671 | prefs.should_clear_document_background); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 672 | settings->SetEnableScrollAnimator(prefs.enable_scroll_animator); |
Stephen McGruer | bc3d0e6 | 2019-01-23 17:40:19 | [diff] [blame] | 673 | settings->SetPrefersReducedMotion(prefs.prefers_reduced_motion); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 674 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 675 | WebRuntimeFeatures::EnableTouchEventFeatureDetection( |
sunyunjia | fa6a8afc | 2016-12-09 04:25:47 | [diff] [blame] | 676 | prefs.touch_event_feature_detection_enabled); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 677 | settings->SetMaxTouchPoints(prefs.pointer_events_max_touch_points); |
| 678 | settings->SetAvailablePointerTypes(prefs.available_pointer_types); |
| 679 | settings->SetPrimaryPointerType( |
nzolghadr | c0d1663c | 2015-11-26 21:15:24 | [diff] [blame] | 680 | static_cast<blink::PointerType>(prefs.primary_pointer_type)); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 681 | settings->SetAvailableHoverTypes(prefs.available_hover_types); |
| 682 | settings->SetPrimaryHoverType( |
nzolghadr | c0d1663c | 2015-11-26 21:15:24 | [diff] [blame] | 683 | static_cast<blink::HoverType>(prefs.primary_hover_type)); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 684 | settings->SetEnableTouchAdjustment(prefs.touch_adjustment_enabled); |
Dave Tapuska | a59fdb6 | 2017-08-23 16:28:27 | [diff] [blame] | 685 | settings->SetBarrelButtonForDragEnabled(prefs.barrel_button_for_drag_enabled); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 686 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 687 | settings->SetShouldRespectImageOrientation( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 688 | prefs.should_respect_image_orientation); |
| 689 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 690 | settings->SetEditingBehavior( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 691 | static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior)); |
| 692 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 693 | settings->SetSupportsMultipleWindows(prefs.supports_multiple_windows); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 694 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 695 | settings->SetMainFrameClipsContent(!prefs.record_whole_document); |
khushalsagar | 2da2b23 | 2016-03-23 22:11:35 | [diff] [blame] | 696 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 697 | settings->SetSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 698 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 699 | settings->SetSpatialNavigationEnabled(prefs.spatial_navigation_enabled); |
Hugo Holgersson | 943ae69 | 2019-01-10 10:04:14 | [diff] [blame] | 700 | // Spatnav depends on KeyboardFocusableScrollers. The WebUI team has |
| 701 | // disabled KFS because they need more time to update their custom elements, |
| 702 | // crbug.com/907284. Meanwhile, we pre-ship KFS to spatnav users. |
| 703 | if (prefs.spatial_navigation_enabled) |
| 704 | WebRuntimeFeatures::EnableKeyboardFocusableScrollers(true); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 705 | |
Bruce Long | 015d96f | 2019-07-12 22:59:10 | [diff] [blame] | 706 | settings->SetCaretBrowsingEnabled(prefs.caret_browsing_enabled); |
| 707 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 708 | settings->SetSelectionIncludesAltImageText(true); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 709 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 710 | settings->SetV8CacheOptions( |
[email protected] | 35103c0 | 2014-08-12 15:08:47 | [diff] [blame] | 711 | static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options)); |
| 712 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 713 | settings->SetImageAnimationPolicy( |
je_julie.kim | 7fbb5a1a | 2015-02-09 17:26:05 | [diff] [blame] | 714 | static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy)); |
| 715 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 716 | settings->SetPresentationRequiresUserGesture( |
zqzhang | 1215ad42 | 2016-02-10 13:27:22 | [diff] [blame] | 717 | prefs.user_gesture_required_for_presentation); |
| 718 | |
Miyoung Shin | 3bcd82c | 2020-03-13 00:34:38 | [diff] [blame] | 719 | if (prefs.text_tracks_enabled) { |
| 720 | settings->SetTextTrackKindUserPreference( |
| 721 | WebSettings::TextTrackKindUserPreference::kCaptions); |
| 722 | } else { |
| 723 | settings->SetTextTrackKindUserPreference( |
| 724 | WebSettings::TextTrackKindUserPreference::kDefault); |
| 725 | } |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 726 | settings->SetTextTrackBackgroundColor( |
| 727 | WebString::FromASCII(prefs.text_track_background_color)); |
| 728 | settings->SetTextTrackTextColor( |
| 729 | WebString::FromASCII(prefs.text_track_text_color)); |
Rahul Singh | 1862faa9 | 2019-03-06 22:41:43 | [diff] [blame] | 730 | settings->SetTextTrackTextSize( |
| 731 | WebString::FromASCII(prefs.text_track_text_size)); |
| 732 | settings->SetTextTrackTextShadow( |
| 733 | WebString::FromASCII(prefs.text_track_text_shadow)); |
| 734 | settings->SetTextTrackFontFamily( |
| 735 | WebString::FromASCII(prefs.text_track_font_family)); |
Miyoung Shin | 3bcd82c | 2020-03-13 00:34:38 | [diff] [blame] | 736 | settings->SetTextTrackFontStyle( |
| 737 | WebString::FromASCII(prefs.text_track_font_style)); |
Rahul Singh | 1862faa9 | 2019-03-06 22:41:43 | [diff] [blame] | 738 | settings->SetTextTrackFontVariant( |
| 739 | WebString::FromASCII(prefs.text_track_font_variant)); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 740 | settings->SetTextTrackMarginPercentage(prefs.text_track_margin_percentage); |
Abigail Klein | 74de85bd | 2019-07-11 19:11:56 | [diff] [blame] | 741 | settings->SetTextTrackWindowColor( |
| 742 | WebString::FromASCII(prefs.text_track_window_color)); |
| 743 | settings->SetTextTrackWindowPadding( |
| 744 | WebString::FromASCII(prefs.text_track_window_padding)); |
| 745 | settings->SetTextTrackWindowRadius( |
| 746 | WebString::FromASCII(prefs.text_track_window_radius)); |
halliwell | 4002be4 | 2016-03-18 18:33:40 | [diff] [blame] | 747 | |
David Bokan | a03511a9 | 2018-09-13 04:25:24 | [diff] [blame] | 748 | // Needs to happen before SetDefaultPageScaleLimits below since that'll |
| 749 | // recalculate the final page scale limits and that depends on this setting. |
| 750 | settings->SetShrinksViewportContentToFit( |
| 751 | prefs.shrinks_viewport_contents_to_fit); |
| 752 | |
| 753 | // Needs to happen before SetIgnoreViewportTagScaleLimits below. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 754 | web_view->SetDefaultPageScaleLimits(prefs.default_minimum_page_scale_factor, |
| 755 | prefs.default_maximum_page_scale_factor); |
dcheng | 5ae8ca36 | 2015-02-05 04:03:47 | [diff] [blame] | 756 | |
Allan Sandfeld Jensen | e3533709 | 2019-05-15 13:56:09 | [diff] [blame] | 757 | settings->SetFullscreenSupported(prefs.fullscreen_supported); |
Ahmed Fakhry | 4222145 | 2018-05-30 01:18:39 | [diff] [blame] | 758 | settings->SetTextAutosizingEnabled(prefs.text_autosizing_enabled); |
| 759 | settings->SetDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled); |
Tarun Bansal | d10f17a0 | 2018-09-13 00:23:17 | [diff] [blame] | 760 | blink::WebNetworkStateNotifier::SetNetworkQualityWebHoldback( |
| 761 | static_cast<blink::WebEffectiveConnectionType>( |
| 762 | prefs.network_quality_estimator_web_holdback)); |
Ahmed Fakhry | 4222145 | 2018-05-30 01:18:39 | [diff] [blame] | 763 | |
chaopeng | 7e8fb35 | 2019-03-26 03:34:49 | [diff] [blame] | 764 | settings->SetDontSendKeyEventsToJavascript( |
| 765 | prefs.dont_send_key_events_to_javascript); |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 766 | settings->SetWebAppScope(WebString::FromASCII(prefs.web_app_scope.spec())); |
| 767 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 768 | #if defined(OS_ANDROID) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 769 | settings->SetAllowCustomScrollbarInMainFrame(false); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 770 | settings->SetAccessibilityFontScaleFactor(prefs.font_scale_factor); |
| 771 | settings->SetDeviceScaleAdjustment(prefs.device_scale_adjustment); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 772 | web_view->SetIgnoreViewportTagScaleLimits(prefs.force_enable_zoom); |
| 773 | settings->SetAutoZoomFocusedNodeToLegibleScale(true); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 774 | settings->SetDefaultVideoPosterURL( |
| 775 | WebString::FromASCII(prefs.default_video_poster_url.spec())); |
| 776 | settings->SetSupportDeprecatedTargetDensityDPI( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 777 | prefs.support_deprecated_target_density_dpi); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 778 | settings->SetUseLegacyBackgroundSizeShorthandBehavior( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 779 | prefs.use_legacy_background_size_shorthand_behavior); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 780 | settings->SetWideViewportQuirkEnabled(prefs.wide_viewport_quirk); |
| 781 | settings->SetUseWideViewport(prefs.use_wide_viewport); |
| 782 | settings->SetForceZeroLayoutHeight(prefs.force_zero_layout_height); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 783 | settings->SetViewportMetaMergeContentQuirk( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 784 | prefs.viewport_meta_merge_content_quirk); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 785 | settings->SetViewportMetaNonUserScalableQuirk( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 786 | prefs.viewport_meta_non_user_scalable_quirk); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 787 | settings->SetViewportMetaZeroValuesQuirk( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 788 | prefs.viewport_meta_zero_values_quirk); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 789 | settings->SetClobberUserAgentInitialScaleQuirk( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 790 | prefs.clobber_user_agent_initial_scale_quirk); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 791 | settings->SetIgnoreMainFrameOverflowHiddenQuirk( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 792 | prefs.ignore_main_frame_overflow_hidden_quirk); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 793 | settings->SetReportScreenSizeInPhysicalPixelsQuirk( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 794 | prefs.report_screen_size_in_physical_pixels_quirk); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 795 | settings->SetShouldReuseGlobalForUnownedMainFrame( |
tzik | 30eb52c | 2018-03-27 06:55:18 | [diff] [blame] | 796 | prefs.reuse_global_for_unowned_main_frame); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 797 | settings->SetPreferHiddenVolumeControls(true); |
| 798 | settings->SetSpellCheckEnabledByDefault(prefs.spellcheck_enabled_by_default); |
dalecurtis | cd97125 | 2016-09-21 16:09:00 | [diff] [blame] | 799 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 800 | WebRuntimeFeatures::EnableVideoFullscreenOrientationLock( |
mlamouri | 1d266bf | 2016-12-05 17:42:36 | [diff] [blame] | 801 | prefs.video_fullscreen_orientation_lock_enabled); |
johnme | 913ee5f | 2017-04-28 21:36:16 | [diff] [blame] | 802 | WebRuntimeFeatures::EnableVideoRotateToFullscreen( |
| 803 | prefs.video_rotate_to_fullscreen_enabled); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 804 | settings->SetEmbeddedMediaExperienceEnabled( |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 805 | prefs.embedded_media_experience_enabled); |
Ian Vollick | eeca1d8 | 2018-02-07 02:43:42 | [diff] [blame] | 806 | settings->SetImmersiveModeEnabled(prefs.immersive_mode_enabled); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 807 | settings->SetDoNotUpdateSelectionOnMutatingSelectionRange( |
changwan | e54ccdb9 | 2017-04-05 19:20:54 | [diff] [blame] | 808 | prefs.do_not_update_selection_on_mutating_selection_range); |
Noel Gordon | f311a84 | 2017-07-27 00:10:07 | [diff] [blame] | 809 | WebRuntimeFeatures::EnableCSSHexAlphaColor(prefs.css_hex_alpha_color_enabled); |
Tobias Sargeant | 416174f | 2017-09-01 01:18:09 | [diff] [blame] | 810 | WebRuntimeFeatures::EnableScrollTopLeftInterop( |
| 811 | prefs.scroll_top_left_interop_enabled); |
Fernando Serboncini | 1fb12a8 | 2019-08-08 20:46:01 | [diff] [blame] | 812 | WebRuntimeFeatures::EnableSurfaceEmbeddingFeatures( |
| 813 | !prefs.disable_features_depending_on_viz); |
Aaron Krajeski | 0fb5128 | 2019-09-17 15:01:27 | [diff] [blame] | 814 | WebRuntimeFeatures::EnableAcceleratedSmallCanvases( |
| 815 | !prefs.disable_accelerated_small_canvases); |
Mason Freed | 8cbef17 | 2019-11-07 19:42:41 | [diff] [blame] | 816 | if (prefs.reenable_web_components_v0) { |
| 817 | WebRuntimeFeatures::EnableShadowDOMV0(true); |
| 818 | WebRuntimeFeatures::EnableCustomElementsV0(true); |
| 819 | WebRuntimeFeatures::EnableHTMLImports(true); |
| 820 | } |
zqzhang | df72ed08 | 2016-12-08 16:07:55 | [diff] [blame] | 821 | #endif // defined(OS_ANDROID) |
Rune Lillesveen | b46bb48 | 2019-04-02 07:36:29 | [diff] [blame] | 822 | settings->SetForceDarkModeEnabled(prefs.force_dark_mode_enabled); |
| 823 | |
Alice Boxhall | da265914 | 2020-05-14 06:04:37 | [diff] [blame] | 824 | settings->SetAccessibilityAlwaysShowFocus(prefs.always_show_focus); |
| 825 | |
mlamouri | 55a0543c | 2017-05-11 10:34:07 | [diff] [blame] | 826 | switch (prefs.autoplay_policy) { |
| 827 | case AutoplayPolicy::kNoUserGestureRequired: |
mlamouri | 276a6f3 | 2017-05-12 09:24:28 | [diff] [blame] | 828 | settings->SetAutoplayPolicy( |
| 829 | WebSettings::AutoplayPolicy::kNoUserGestureRequired); |
mlamouri | 55a0543c | 2017-05-11 10:34:07 | [diff] [blame] | 830 | break; |
| 831 | case AutoplayPolicy::kUserGestureRequired: |
mlamouri | 276a6f3 | 2017-05-12 09:24:28 | [diff] [blame] | 832 | settings->SetAutoplayPolicy( |
| 833 | WebSettings::AutoplayPolicy::kUserGestureRequired); |
mlamouri | 55a0543c | 2017-05-11 10:34:07 | [diff] [blame] | 834 | break; |
mlamouri | 431bb4e | 2017-06-06 08:54:24 | [diff] [blame] | 835 | case AutoplayPolicy::kDocumentUserActivationRequired: |
| 836 | settings->SetAutoplayPolicy( |
| 837 | WebSettings::AutoplayPolicy::kDocumentUserActivationRequired); |
| 838 | break; |
mlamouri | 55a0543c | 2017-05-11 10:34:07 | [diff] [blame] | 839 | } |
| 840 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 841 | settings->SetViewportEnabled(prefs.viewport_enabled); |
| 842 | settings->SetViewportMetaEnabled(prefs.viewport_meta_enabled); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 843 | settings->SetViewportStyle( |
alokp | 5d56696 | 2016-04-19 00:54:16 | [diff] [blame] | 844 | static_cast<blink::WebViewportStyle>(prefs.viewport_style)); |
| 845 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 846 | settings->SetLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale); |
| 847 | settings->SetMainFrameResizesAreOrientationChanges( |
yoav | a1a508b4 | 2015-10-20 12:03:21 | [diff] [blame] | 848 | prefs.main_frame_resizes_are_orientation_changes); |
| 849 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 850 | settings->SetShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up); |
| 851 | settings->SetAlwaysShowContextMenuOnTouch( |
amaralp | 547e419 | 2016-06-03 19:17:35 | [diff] [blame] | 852 | prefs.always_show_context_menu_on_touch); |
Sandra Sun | c79fc93a | 2018-04-10 15:22:23 | [diff] [blame] | 853 | settings->SetSmoothScrollForFindEnabled(prefs.smooth_scroll_for_find_enabled); |
ccameron | 2fd70de7 | 2015-02-19 00:40:40 | [diff] [blame] | 854 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 855 | settings->SetHideDownloadUI(prefs.hide_download_ui); |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 856 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 857 | settings->SetPresentationReceiver(prefs.presentation_receiver); |
mlamouri | 57359d91 | 2016-11-29 20:11:50 | [diff] [blame] | 858 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 859 | settings->SetMediaControlsEnabled(prefs.media_controls_enabled); |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 860 | |
Tarun Bansal | 73d67f0 | 2018-01-17 05:56:25 | [diff] [blame] | 861 | settings->SetLowPriorityIframesThreshold( |
| 862 | static_cast<blink::WebEffectiveConnectionType>( |
| 863 | prefs.low_priority_iframes_threshold)); |
| 864 | |
Mounir Lamouri | 9c99a160 | 2018-07-05 15:01:44 | [diff] [blame] | 865 | settings->SetPictureInPictureEnabled( |
| 866 | prefs.picture_in_picture_enabled && |
[email protected] | 69db58f | 2018-09-26 20:27:56 | [diff] [blame] | 867 | MediaFactory::GetVideoSurfaceLayerMode() != |
CJ DiMeglio | 8924047 | 2018-10-18 18:21:10 | [diff] [blame] | 868 | blink::WebMediaPlayer::SurfaceLayerMode::kNever); |
François Beaufort | 8c08979fc | 2018-03-05 13:06:31 | [diff] [blame] | 869 | |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 870 | settings->SetDataSaverHoldbackWebApi( |
| 871 | prefs.data_saver_holdback_web_api_enabled); |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 872 | |
rajendrant | e87ed71 | 2018-11-30 01:55:00 | [diff] [blame] | 873 | settings->SetLazyLoadEnabled(prefs.lazy_load_enabled); |
Alison Maher | 7f366dc6 | 2020-03-03 19:46:00 | [diff] [blame] | 874 | settings->SetPreferredColorScheme(prefs.preferred_color_scheme); |
rajendrant | e87ed71 | 2018-11-30 01:55:00 | [diff] [blame] | 875 | |
Scott Little | 878f7d670 | 2018-05-31 22:09:06 | [diff] [blame] | 876 | for (const auto& ect_distance_pair : |
| 877 | prefs.lazy_frame_loading_distance_thresholds_px) { |
| 878 | switch (ect_distance_pair.first) { |
| 879 | case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN: |
| 880 | settings->SetLazyFrameLoadingDistanceThresholdPxUnknown( |
| 881 | ect_distance_pair.second); |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 882 | continue; |
Scott Little | 878f7d670 | 2018-05-31 22:09:06 | [diff] [blame] | 883 | case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE: |
| 884 | settings->SetLazyFrameLoadingDistanceThresholdPxOffline( |
| 885 | ect_distance_pair.second); |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 886 | continue; |
Scott Little | 878f7d670 | 2018-05-31 22:09:06 | [diff] [blame] | 887 | case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G: |
| 888 | settings->SetLazyFrameLoadingDistanceThresholdPxSlow2G( |
| 889 | ect_distance_pair.second); |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 890 | continue; |
Scott Little | 878f7d670 | 2018-05-31 22:09:06 | [diff] [blame] | 891 | case net::EFFECTIVE_CONNECTION_TYPE_2G: |
| 892 | settings->SetLazyFrameLoadingDistanceThresholdPx2G( |
| 893 | ect_distance_pair.second); |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 894 | continue; |
Scott Little | 878f7d670 | 2018-05-31 22:09:06 | [diff] [blame] | 895 | case net::EFFECTIVE_CONNECTION_TYPE_3G: |
| 896 | settings->SetLazyFrameLoadingDistanceThresholdPx3G( |
| 897 | ect_distance_pair.second); |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 898 | continue; |
Scott Little | 878f7d670 | 2018-05-31 22:09:06 | [diff] [blame] | 899 | case net::EFFECTIVE_CONNECTION_TYPE_4G: |
| 900 | settings->SetLazyFrameLoadingDistanceThresholdPx4G( |
| 901 | ect_distance_pair.second); |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 902 | continue; |
| 903 | case net::EFFECTIVE_CONNECTION_TYPE_LAST: |
| 904 | continue; |
Scott Little | 878f7d670 | 2018-05-31 22:09:06 | [diff] [blame] | 905 | } |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 906 | NOTREACHED(); |
| 907 | } |
| 908 | |
| 909 | for (const auto& ect_distance_pair : |
| 910 | prefs.lazy_image_loading_distance_thresholds_px) { |
| 911 | switch (ect_distance_pair.first) { |
| 912 | case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN: |
| 913 | settings->SetLazyImageLoadingDistanceThresholdPxUnknown( |
| 914 | ect_distance_pair.second); |
| 915 | continue; |
| 916 | case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE: |
| 917 | settings->SetLazyImageLoadingDistanceThresholdPxOffline( |
| 918 | ect_distance_pair.second); |
| 919 | continue; |
| 920 | case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G: |
| 921 | settings->SetLazyImageLoadingDistanceThresholdPxSlow2G( |
| 922 | ect_distance_pair.second); |
| 923 | continue; |
| 924 | case net::EFFECTIVE_CONNECTION_TYPE_2G: |
| 925 | settings->SetLazyImageLoadingDistanceThresholdPx2G( |
| 926 | ect_distance_pair.second); |
| 927 | continue; |
| 928 | case net::EFFECTIVE_CONNECTION_TYPE_3G: |
| 929 | settings->SetLazyImageLoadingDistanceThresholdPx3G( |
| 930 | ect_distance_pair.second); |
| 931 | continue; |
| 932 | case net::EFFECTIVE_CONNECTION_TYPE_4G: |
| 933 | settings->SetLazyImageLoadingDistanceThresholdPx4G( |
| 934 | ect_distance_pair.second); |
| 935 | continue; |
| 936 | case net::EFFECTIVE_CONNECTION_TYPE_LAST: |
| 937 | continue; |
| 938 | } |
| 939 | NOTREACHED(); |
Scott Little | 878f7d670 | 2018-05-31 22:09:06 | [diff] [blame] | 940 | } |
| 941 | |
rajendrant | 3daeae29 | 2019-09-20 07:57:54 | [diff] [blame] | 942 | for (const auto& fully_load_k_pair : prefs.lazy_image_first_k_fully_load) { |
| 943 | switch (fully_load_k_pair.first) { |
| 944 | case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE: |
| 945 | continue; |
| 946 | case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN: |
| 947 | settings->SetLazyImageFirstKFullyLoadUnknown(fully_load_k_pair.second); |
| 948 | continue; |
| 949 | case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G: |
| 950 | settings->SetLazyImageFirstKFullyLoadSlow2G(fully_load_k_pair.second); |
| 951 | continue; |
| 952 | case net::EFFECTIVE_CONNECTION_TYPE_2G: |
| 953 | settings->SetLazyImageFirstKFullyLoad2G(fully_load_k_pair.second); |
| 954 | continue; |
| 955 | case net::EFFECTIVE_CONNECTION_TYPE_3G: |
| 956 | settings->SetLazyImageFirstKFullyLoad3G(fully_load_k_pair.second); |
| 957 | continue; |
| 958 | case net::EFFECTIVE_CONNECTION_TYPE_4G: |
| 959 | settings->SetLazyImageFirstKFullyLoad4G(fully_load_k_pair.second); |
| 960 | continue; |
| 961 | case net::EFFECTIVE_CONNECTION_TYPE_LAST: |
| 962 | continue; |
| 963 | } |
| 964 | NOTREACHED(); |
| 965 | } |
| 966 | |
ccameron | 2fd70de7 | 2015-02-19 00:40:40 | [diff] [blame] | 967 | #if defined(OS_MACOSX) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 968 | web_view->SetMaximumLegibleScale(prefs.default_maximum_page_scale_factor); |
ccameron | 2fd70de7 | 2015-02-19 00:40:40 | [diff] [blame] | 969 | #endif |
sunyunjia | 87f287b | 2016-09-09 00:38:13 | [diff] [blame] | 970 | |
| 971 | #if defined(OS_WIN) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 972 | WebRuntimeFeatures::EnableMiddleClickAutoscroll(true); |
sunyunjia | 87f287b | 2016-09-09 00:38:13 | [diff] [blame] | 973 | #endif |
Dave Tapuska | c6627e1 | 2018-08-30 15:07:19 | [diff] [blame] | 974 | |
Dave Tapuska | a38e325 | 2018-11-13 03:01:17 | [diff] [blame] | 975 | WebRuntimeFeatures::EnableTranslateService(prefs.translate_service_available); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | /*static*/ |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 979 | RenderViewImpl* RenderViewImpl::Create( |
| 980 | CompositorDependencies* compositor_deps, |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 981 | mojom::CreateViewParamsPtr params, |
danakj | df1ceb7 | 2018-07-18 20:02:25 | [diff] [blame] | 982 | RenderWidget::ShowCallback show_callback, |
Hajime Hoshi | abb3c8f | 2017-12-04 18:41:39 | [diff] [blame] | 983 | scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 984 | DCHECK(params->view_id != MSG_ROUTING_NONE); |
danakj | d434db4 | 2020-01-07 22:27:39 | [diff] [blame] | 985 | // Frame and widget routing ids come together. |
| 986 | DCHECK_EQ(params->main_frame_routing_id == MSG_ROUTING_NONE, |
| 987 | params->main_frame_widget_routing_id == MSG_ROUTING_NONE); |
| 988 | // We have either a main frame or a proxy routing id. |
| 989 | DCHECK_NE(params->main_frame_routing_id != MSG_ROUTING_NONE, |
| 990 | params->proxy_routing_id != MSG_ROUTING_NONE); |
[email protected] | 0287e76 | 2014-04-11 13:07:58 | [diff] [blame] | 991 | |
danakj | d434db4 | 2020-01-07 22:27:39 | [diff] [blame] | 992 | RenderViewImpl* render_view; |
Albert J. Wong | 7faa3da | 2019-03-21 20:43:43 | [diff] [blame] | 993 | if (g_create_render_view_impl) { |
| 994 | render_view = g_create_render_view_impl(compositor_deps, *params); |
| 995 | } else { |
| 996 | render_view = new RenderViewImpl(compositor_deps, *params); |
| 997 | } |
| 998 | |
Erik Chen | 10e9b02 | 2019-08-21 23:33:23 | [diff] [blame] | 999 | render_view->Initialize(compositor_deps, std::move(params), |
Albert J. Wong | 7faa3da | 2019-03-21 20:43:43 | [diff] [blame] | 1000 | std::move(show_callback), std::move(task_runner)); |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 1001 | return render_view; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1002 | } |
| 1003 | |
Erik Chen | 3433ee0 | 2019-08-05 20:14:26 | [diff] [blame] | 1004 | void RenderViewImpl::Destroy() { |
danakj | cdfc426 | 2019-10-01 20:09:48 | [diff] [blame] | 1005 | destroying_ = true; |
| 1006 | |
Erik Chen | 562ca42b | 2019-08-22 19:46:06 | [diff] [blame] | 1007 | webview_->Close(); |
Erik Chen | 3433ee0 | 2019-08-05 20:14:26 | [diff] [blame] | 1008 | // The webview_ is already destroyed by the time we get here, remove any |
| 1009 | // references to it. |
| 1010 | g_view_map.Get().erase(webview_); |
| 1011 | webview_ = nullptr; |
Erik Chen | 562ca42b | 2019-08-22 19:46:06 | [diff] [blame] | 1012 | |
Erik Chen | 3433ee0 | 2019-08-05 20:14:26 | [diff] [blame] | 1013 | delete this; |
| 1014 | } |
| 1015 | |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1016 | // static |
dcheng | 35d31c11 | 2015-07-22 00:17:36 | [diff] [blame] | 1017 | void RenderViewImpl::InstallCreateHook(RenderViewImpl* ( |
| 1018 | *create_render_view_impl)(CompositorDependencies* compositor_deps, |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 1019 | const mojom::CreateViewParams&)) { |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 1020 | CHECK(!g_create_render_view_impl); |
| 1021 | g_create_render_view_impl = create_render_view_impl; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1022 | } |
| 1023 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1024 | void RenderViewImpl::AddObserver(RenderViewObserver* observer) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1025 | observers_.AddObserver(observer); |
| 1026 | } |
| 1027 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1028 | void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { |
| 1029 | observer->RenderViewGone(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1030 | observers_.RemoveObserver(observer); |
| 1031 | } |
| 1032 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1033 | // RenderWidgetOwnerDelegate ----------------------------------------- |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1034 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1035 | void RenderViewImpl::SetActiveForWidget(bool active) { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1036 | if (GetWebView()) |
| 1037 | GetWebView()->SetIsActive(active); |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 1038 | } |
| 1039 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1040 | bool RenderViewImpl::SupportsMultipleWindowsForWidget() { |
| 1041 | return webkit_preferences_.supports_multiple_windows; |
| 1042 | } |
| 1043 | |
David Bokan | 11f6ef48 | 2019-03-18 17:47:27 | [diff] [blame] | 1044 | bool RenderViewImpl::ShouldAckSyntheticInputImmediately() { |
| 1045 | // TODO(bokan): The RequestPresentation API appears not to function in VR. As |
| 1046 | // a short term workaround for https://crbug.com/940063, ACK input |
| 1047 | // immediately rather than using RequestPresentation. |
| 1048 | if (webkit_preferences_.immersive_mode_enabled) |
| 1049 | return true; |
| 1050 | return false; |
| 1051 | } |
| 1052 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1053 | void RenderViewImpl::ApplyAutoResizeLimitsForWidget(const gfx::Size& min_size, |
| 1054 | const gfx::Size& max_size) { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1055 | GetWebView()->EnableAutoResizeMode(min_size, max_size); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | void RenderViewImpl::DisableAutoResizeForWidget() { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1059 | GetWebView()->DisableAutoResizeMode(); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | void RenderViewImpl::ScrollFocusedNodeIntoViewForWidget() { |
| 1063 | if (WebLocalFrame* focused_frame = GetWebView()->FocusedFrame()) { |
danakj | 5f06901 | 2019-10-09 23:14:17 | [diff] [blame] | 1064 | blink::WebFrameWidget* frame_widget = |
| 1065 | focused_frame->LocalRoot()->FrameWidget(); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1066 | frame_widget->ScrollFocusedEditableElementIntoView(); |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | void RenderViewImpl::DidReceiveSetFocusEventForWidget() { |
| 1071 | // This message must always be received when the main frame is a |
| 1072 | // WebLocalFrame. |
Albert J. Wong | 7bbf22d | 2018-12-20 00:27:27 | [diff] [blame] | 1073 | // TODO(ajwong): Can this be removed and just check |delegate_| in |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1074 | // RenderWidget instead? |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1075 | CHECK(GetWebView()->MainFrame()->IsWebLocalFrame()); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1076 | } |
| 1077 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1078 | void RenderViewImpl::DidCommitCompositorFrameForWidget() { |
| 1079 | for (auto& observer : observers_) |
| 1080 | observer.DidCommitCompositorFrame(); |
Antonio Gomes | bc5ef25 | 2020-03-05 10:37:01 | [diff] [blame] | 1081 | |
| 1082 | if (GetWebView()) |
| 1083 | GetWebView()->UpdatePreferredSize(); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | void RenderViewImpl::DidCompletePageScaleAnimationForWidget() { |
| 1087 | if (auto* focused_frame = GetWebView()->FocusedFrame()) { |
| 1088 | if (focused_frame->AutofillClient()) |
| 1089 | focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame(); |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | void RenderViewImpl::ResizeWebWidgetForWidget( |
danakj | 748ef909 | 2019-10-17 23:40:53 | [diff] [blame] | 1094 | const gfx::Size& widget_size, |
danakj | d4533c7 | 2020-03-11 13:07:10 | [diff] [blame] | 1095 | const gfx::Size& visible_viewport_size, |
Sinan Sahin | 92a360bc | 2019-12-05 19:20:45 | [diff] [blame] | 1096 | cc::BrowserControlsParams browser_controls_params) { |
danakj | d4533c7 | 2020-03-11 13:07:10 | [diff] [blame] | 1097 | GetWebView()->ResizeWithBrowserControls(widget_size, visible_viewport_size, |
| 1098 | browser_controls_params); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1099 | } |
| 1100 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1101 | void RenderViewImpl::SetScreenMetricsEmulationParametersForWidget( |
Andrey Kosyakov | 5bb020f | 2020-03-19 17:28:19 | [diff] [blame] | 1102 | bool enabled, |
| 1103 | const blink::WebDeviceEmulationParams& params) { |
| 1104 | if (enabled) |
| 1105 | GetWebView()->EnableDeviceEmulation(params); |
| 1106 | else |
| 1107 | GetWebView()->DisableDeviceEmulation(); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | // IPC message handlers ----------------------------------------- |
| 1111 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1112 | void RenderViewImpl::OnUpdateTargetURLAck() { |
| 1113 | // Check if there is a targeturl waiting to be sent. |
| 1114 | if (target_url_status_ == TARGET_PENDING) |
| 1115 | Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), pending_target_url_)); |
| 1116 | |
| 1117 | target_url_status_ = TARGET_NONE; |
| 1118 | } |
| 1119 | |
| 1120 | void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset, |
| 1121 | int history_length) { |
| 1122 | // -1 <= history_offset < history_length <= kMaxSessionHistoryEntries(50). |
| 1123 | DCHECK_LE(-1, history_offset); |
| 1124 | DCHECK_LT(history_offset, history_length); |
| 1125 | DCHECK_LE(history_length, kMaxSessionHistoryEntries); |
| 1126 | |
| 1127 | history_list_offset_ = history_offset; |
| 1128 | history_list_length_ = history_length; |
| 1129 | } |
| 1130 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1131 | void RenderViewImpl::OnAudioStateChanged(bool is_audio_playing) { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1132 | GetWebView()->AudioStateChanged(is_audio_playing); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1133 | } |
| 1134 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1135 | /////////////////////////////////////////////////////////////////////////////// |
| 1136 | |
| 1137 | void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget, |
| 1138 | WebNavigationPolicy policy, |
| 1139 | const gfx::Rect& initial_rect) { |
| 1140 | Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(), |
| 1141 | initial_rect)); |
| 1142 | } |
| 1143 | |
| 1144 | void RenderViewImpl::ShowCreatedFullscreenWidget( |
| 1145 | RenderWidget* fullscreen_widget, |
| 1146 | WebNavigationPolicy policy, |
| 1147 | const gfx::Rect& initial_rect) { |
| 1148 | Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(), |
| 1149 | fullscreen_widget->routing_id())); |
| 1150 | } |
| 1151 | |
| 1152 | void RenderViewImpl::SendFrameStateUpdates() { |
| 1153 | // Tell each frame with pending state to send its UpdateState message. |
| 1154 | for (int render_frame_routing_id : frames_with_pending_state_) { |
| 1155 | RenderFrameImpl* frame = |
| 1156 | RenderFrameImpl::FromRoutingID(render_frame_routing_id); |
| 1157 | if (frame) |
| 1158 | frame->SendUpdateState(); |
| 1159 | } |
| 1160 | frames_with_pending_state_.clear(); |
| 1161 | } |
| 1162 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1163 | // IPC::Listener ------------------------------------------------------------- |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1164 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1165 | bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1166 | WebFrame* main_frame = GetWebView() ? GetWebView()->MainFrame() : nullptr; |
Avi Drissman | b5f8e24 | 2017-12-12 05:21:56 | [diff] [blame] | 1167 | if (main_frame) { |
| 1168 | GURL active_url; |
| 1169 | if (main_frame->IsWebLocalFrame()) |
| 1170 | active_url = main_frame->ToWebLocalFrame()->GetDocument().Url(); |
lukasza | bedb4b2 | 2017-06-23 00:00:13 | [diff] [blame] | 1171 | GetContentClient()->SetActiveURL( |
Avi Drissman | b5f8e24 | 2017-12-12 05:21:56 | [diff] [blame] | 1172 | active_url, main_frame->Top()->GetSecurityOrigin().ToString().Utf8()); |
| 1173 | } |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 1174 | |
dcheng | a2d442c2 | 2016-10-13 15:39:21 | [diff] [blame] | 1175 | for (auto& observer : observers_) { |
| 1176 | if (observer.OnMessageReceived(message)) |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1177 | return true; |
dcheng | a2d442c2 | 2016-10-13 15:39:21 | [diff] [blame] | 1178 | } |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1179 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1180 | bool handled = true; |
[email protected] | e44d134 | 2014-05-16 21:29:33 | [diff] [blame] | 1181 | IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1182 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 1183 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 1184 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1185 | |
| 1186 | // Page messages. |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 1187 | IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength, |
| 1188 | OnSetHistoryOffsetAndLength) |
altimin | d8bd26c | 2016-11-04 11:44:54 | [diff] [blame] | 1189 | IPC_MESSAGE_HANDLER(PageMsg_AudioStateChanged, OnAudioStateChanged) |
Yuzu Saijo | dfba8fa6 | 2019-08-27 02:15:22 | [diff] [blame] | 1190 | IPC_MESSAGE_HANDLER(PageMsg_PutPageIntoBackForwardCache, |
| 1191 | PutPageIntoBackForwardCache) |
| 1192 | IPC_MESSAGE_HANDLER(PageMsg_RestorePageFromBackForwardCache, |
| 1193 | RestorePageFromBackForwardCache) |
W. James MacLean | 6219867 | 2019-06-04 16:46:10 | [diff] [blame] | 1194 | IPC_MESSAGE_HANDLER(PageMsg_UpdateTextAutosizerPageInfoForRemoteMainFrames, |
| 1195 | OnTextAutosizerPageInfoChanged) |
Bruce Long | 1e3e1f54 | 2019-10-16 17:56:28 | [diff] [blame] | 1196 | IPC_MESSAGE_HANDLER(PageMsg_SetRendererPrefs, OnSetRendererPrefs) |
Adithya Srinivasan | 11af2c5 | 2019-12-16 22:52:55 | [diff] [blame] | 1197 | IPC_MESSAGE_HANDLER(PageMsg_SetInsidePortal, OnSetInsidePortal) |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 1198 | |
[email protected] | a794f3a | 2013-10-30 17:00:32 | [diff] [blame] | 1199 | // Adding a new message? Add platform independent ones first, then put the |
| 1200 | // platform specific ones at the end. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1201 | IPC_END_MESSAGE_MAP() |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1202 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1203 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1204 | } |
| 1205 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1206 | // blink::WebViewClient ------------------------------------------------------ |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1207 | |
Mustaq Ahmed | 55944cb | 2018-05-25 20:44:27 | [diff] [blame] | 1208 | // TODO(csharrison): Migrate this method to WebLocalFrameClient / |
| 1209 | // RenderFrameImpl, as it is now serviced by a mojo interface scoped to the |
| 1210 | // opener frame. |
Daniel Murphy | c8e991a | 2018-10-12 22:09:03 | [diff] [blame] | 1211 | WebView* RenderViewImpl::CreateView( |
| 1212 | WebLocalFrame* creator, |
| 1213 | const WebURLRequest& request, |
| 1214 | const WebWindowFeatures& features, |
| 1215 | const WebString& frame_name, |
| 1216 | WebNavigationPolicy policy, |
arthursonzogni | b93a447 | 2020-04-10 07:38:00 | [diff] [blame] | 1217 | network::mojom::WebSandboxFlags sandbox_flags, |
Ehsan Karamad | 3940708 | 2019-02-19 23:38:19 | [diff] [blame] | 1218 | const blink::FeaturePolicy::FeatureState& opener_feature_state, |
Daniel Murphy | c8e991a | 2018-10-12 22:09:03 | [diff] [blame] | 1219 | const blink::SessionStorageNamespaceId& session_storage_namespace_id) { |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 1220 | RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator); |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 1221 | mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New(); |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 1222 | |
Mustaq Ahmed | e5f1256 | 2019-10-30 18:02:03 | [diff] [blame] | 1223 | // The user activation check is done at the browser process through |
| 1224 | // |frame_host->CreateNewWindow()| call below. But the extensions case |
| 1225 | // handled through the following |if| is an exception. |
Mustaq Ahmed | 8601a56 | 2020-01-31 18:05:52 | [diff] [blame] | 1226 | params->allow_popup = false; |
[email protected] | 00323f0 | 2013-07-24 15:47:41 | [diff] [blame] | 1227 | if (GetContentClient()->renderer()->AllowPopup()) |
Mustaq Ahmed | 8601a56 | 2020-01-31 18:05:52 | [diff] [blame] | 1228 | params->allow_popup = true; |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 1229 | |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 1230 | params->window_container_type = WindowFeaturesToContainerType(features); |
Daniel Murphy | e3eec92c | 2018-02-23 19:09:15 | [diff] [blame] | 1231 | |
Daniel Murphy | c8e991a | 2018-10-12 22:09:03 | [diff] [blame] | 1232 | params->session_storage_namespace_id = session_storage_namespace_id; |
| 1233 | // TODO(dmurph): Don't copy session storage when features.noopener is true: |
| 1234 | // https://html.spec.whatwg.org/multipage/browsers.html#copy-session-storage |
| 1235 | // https://crbug.com/771959 |
Daniel Murphy | e3eec92c | 2018-02-23 19:09:15 | [diff] [blame] | 1236 | params->clone_from_session_storage_namespace_id = |
| 1237 | session_storage_namespace_id_; |
Daniel Murphy | e3eec92c | 2018-02-23 19:09:15 | [diff] [blame] | 1238 | |
Daniel Cheng | d5e56ff | 2017-06-24 07:44:02 | [diff] [blame] | 1239 | const std::string& frame_name_utf8 = frame_name.Utf8( |
| 1240 | WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD); |
| 1241 | params->frame_name = frame_name_utf8; |
Nate Chapin | 43f307d | 2019-04-15 21:04:41 | [diff] [blame] | 1242 | params->opener_suppressed = features.noopener; |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 1243 | params->disposition = NavigationPolicyToDisposition(policy); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1244 | if (!request.IsNull()) { |
| 1245 | params->target_url = request.Url(); |
Dominic Farolino | aee9c1b8 | 2019-12-18 03:20:10 | [diff] [blame] | 1246 | params->referrer = blink::mojom::Referrer::New( |
| 1247 | blink::WebStringToGURL(request.ReferrerString()), |
| 1248 | request.GetReferrerPolicy()); |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 1249 | } |
scottmg | 8e6c608 | 2017-02-13 23:15:48 | [diff] [blame] | 1250 | params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1251 | |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 1252 | // We preserve this information before sending the message since |params| is |
| 1253 | // moved on send. |
| 1254 | bool is_background_tab = |
| 1255 | params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB; |
[email protected] | 22217ed3 | 2013-11-18 18:40:23 | [diff] [blame] | 1256 | |
Daniel Cheng | 8bb30c6 | 2017-10-23 20:40:47 | [diff] [blame] | 1257 | mojom::CreateNewWindowStatus status; |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 1258 | mojom::CreateNewWindowReplyPtr reply; |
Balazs Engedy | a40712f | 2017-09-15 15:01:11 | [diff] [blame] | 1259 | auto* frame_host = creator_frame->GetFrameHost(); |
Daniel Cheng | 8bb30c6 | 2017-10-23 20:40:47 | [diff] [blame] | 1260 | bool err = !frame_host->CreateNewWindow(std::move(params), &status, &reply); |
| 1261 | if (err || status == mojom::CreateNewWindowStatus::kIgnore) |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 1262 | return nullptr; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1263 | |
Jochen Eisinger | 515337a | 2017-05-26 14:12:52 | [diff] [blame] | 1264 | // For Android WebView, we support a pop-up like behavior for window.open() |
| 1265 | // even if the embedding app doesn't support multiple windows. In this case, |
| 1266 | // window.open() will return "window" and navigate it to whatever URL was |
Jochen Eisinger | 8cb2849 | 2017-10-04 10:58:13 | [diff] [blame] | 1267 | // passed. We also don't need to consume user gestures to protect against |
| 1268 | // multiple windows being opened, because, well, the app doesn't support |
| 1269 | // multiple windows. |
Daniel Cheng | 8bb30c6 | 2017-10-23 20:40:47 | [diff] [blame] | 1270 | // 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] | 1271 | // used much in Blink, except to enable web testing... perhaps this should |
Daniel Cheng | 8bb30c6 | 2017-10-23 20:40:47 | [diff] [blame] | 1272 | // be checked directly in the browser side. |
| 1273 | if (status == mojom::CreateNewWindowStatus::kReuse) |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1274 | return GetWebView(); |
Jochen Eisinger | 515337a | 2017-05-26 14:12:52 | [diff] [blame] | 1275 | |
Daniel Cheng | 8bb30c6 | 2017-10-23 20:40:47 | [diff] [blame] | 1276 | DCHECK(reply); |
| 1277 | DCHECK_NE(MSG_ROUTING_NONE, reply->route_id); |
| 1278 | DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_route_id); |
| 1279 | DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_widget_route_id); |
| 1280 | |
Mustaq Ahmed | 76c2f431 | 2018-06-07 20:48:01 | [diff] [blame] | 1281 | // The browser allowed creation of a new window and consumed the user |
Mustaq Ahmed | e5f1256 | 2019-10-30 18:02:03 | [diff] [blame] | 1282 | // activation. |
Mustaq Ahmed | 4baa9a6e8 | 2019-12-20 23:43:46 | [diff] [blame] | 1283 | bool was_consumed = creator->ConsumeTransientUserActivation( |
| 1284 | blink::UserActivationUpdateSource::kBrowser); |
Jochen Eisinger | 8cb2849 | 2017-10-04 10:58:13 | [diff] [blame] | 1285 | |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 1286 | // While this view may be a background extension page, it can spawn a visible |
| 1287 | // render view. So we just assume that the new one is not another background |
| 1288 | // page instead of passing on our own value. |
| 1289 | // TODO(vangelis): Can we tell if the new view will be a background page? |
danakj | 77eb7e8 | 2020-01-09 19:38:46 | [diff] [blame] | 1290 | bool never_composited = false; |
[email protected] | 9115d5f | 2013-03-24 04:37:41 | [diff] [blame] | 1291 | |
[email protected] | d6fa88f | 2013-10-18 16:00:43 | [diff] [blame] | 1292 | // The initial hidden state for the RenderViewImpl here has to match what the |
| 1293 | // browser will eventually decide for the given disposition. Since we have to |
| 1294 | // return from this call synchronously, we just have to make our best guess |
| 1295 | // and rely on the browser sending a WasHidden / WasShown message if it |
| 1296 | // disagrees. |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 1297 | mojom::CreateViewParamsPtr view_params = mojom::CreateViewParams::New(); |
alexmos | 5ac402d | 2015-07-09 07:51:10 | [diff] [blame] | 1298 | |
Antonio Gomes | b3dd5fc | 2020-05-25 22:53:27 | [diff] [blame^] | 1299 | view_params->opener_frame_token = creator->GetFrameToken(); |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 1300 | DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID()); |
alexmos | 5ac402d | 2015-07-09 07:51:10 | [diff] [blame] | 1301 | |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 1302 | view_params->window_was_created_with_opener = true; |
Leon Han | 2c81b5d | 2019-01-25 01:58:33 | [diff] [blame] | 1303 | view_params->renderer_preferences = renderer_preferences_.Clone(); |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 1304 | view_params->web_preferences = webkit_preferences_; |
| 1305 | view_params->view_id = reply->route_id; |
Dave Tapuska | 8444938 | 2020-05-01 00:39:04 | [diff] [blame] | 1306 | view_params->main_frame_frame_token = reply->main_frame_frame_token; |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 1307 | view_params->main_frame_routing_id = reply->main_frame_route_id; |
Dave Tapuska | 8499eec | 2020-03-16 17:54:30 | [diff] [blame] | 1308 | view_params->frame_widget_host = std::move(reply->frame_widget_host); |
| 1309 | view_params->frame_widget = std::move(reply->frame_widget); |
| 1310 | view_params->widget_host = std::move(reply->widget_host); |
| 1311 | view_params->widget = std::move(reply->widget), |
| 1312 | view_params->main_frame_interface_bundle = |
| 1313 | mojom::DocumentScopedInterfaceBundle::New( |
| 1314 | std::move(reply->main_frame_interface_bundle->interface_provider), |
| 1315 | std::move( |
| 1316 | reply->main_frame_interface_bundle->browser_interface_broker)); |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 1317 | view_params->main_frame_widget_routing_id = reply->main_frame_widget_route_id; |
| 1318 | view_params->session_storage_namespace_id = |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 1319 | reply->cloned_session_storage_namespace_id; |
Daniel Murphy | 95792ef | 2018-10-04 01:29:55 | [diff] [blame] | 1320 | DCHECK(!view_params->session_storage_namespace_id.empty()) |
| 1321 | << "Session storage namespace must be populated."; |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 1322 | view_params->replicated_frame_state.frame_policy.sandbox_flags = |
| 1323 | sandbox_flags; |
Ehsan Karamad | 3940708 | 2019-02-19 23:38:19 | [diff] [blame] | 1324 | view_params->replicated_frame_state.opener_feature_state = |
| 1325 | opener_feature_state; |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 1326 | view_params->replicated_frame_state.name = frame_name_utf8; |
| 1327 | view_params->devtools_main_frame_token = reply->devtools_main_frame_token; |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 1328 | view_params->hidden = is_background_tab; |
danakj | 77eb7e8 | 2020-01-09 19:38:46 | [diff] [blame] | 1329 | view_params->never_composited = never_composited; |
danakj | be56b813 | 2019-10-12 00:57:41 | [diff] [blame] | 1330 | view_params->visual_properties = reply->visual_properties; |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 1331 | |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 1332 | // Unretained() is safe here because our calling function will also call |
| 1333 | // show(). |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 1334 | RenderWidget::ShowCallback show_callback = |
danakj | df1ceb7 | 2018-07-18 20:02:25 | [diff] [blame] | 1335 | base::BindOnce(&RenderFrameImpl::ShowCreatedWindow, |
Mustaq Ahmed | e5f1256 | 2019-10-30 18:02:03 | [diff] [blame] | 1336 | base::Unretained(creator_frame), was_consumed); |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 1337 | |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 1338 | RenderViewImpl* view = RenderViewImpl::Create( |
danakj | 4b8a2d9a | 2019-10-15 15:53:59 | [diff] [blame] | 1339 | compositor_deps_, std::move(view_params), std::move(show_callback), |
Hajime Hoshi | 6fc9114 | 2018-05-11 08:21:17 | [diff] [blame] | 1340 | creator->GetTaskRunner(blink::TaskType::kInternalDefault)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1341 | |
Yury Semikhatsky | 82730ff | 2020-02-25 22:29:26 | [diff] [blame] | 1342 | if (reply->wait_for_debugger) { |
danakj | d370dbb | 2020-05-21 17:54:38 | [diff] [blame] | 1343 | blink::WebFrameWidget* frame_widget = |
| 1344 | view->GetMainRenderFrame()->GetLocalRootWebFrameWidget(); |
| 1345 | frame_widget->WaitForDebuggerWhenShown(); |
Yury Semikhatsky | 82730ff | 2020-02-25 22:29:26 | [diff] [blame] | 1346 | } |
| 1347 | |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1348 | return view->GetWebView(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1349 | } |
| 1350 | |
danakj | 19f3e51 | 2018-12-14 21:02:05 | [diff] [blame] | 1351 | blink::WebPagePopup* RenderViewImpl::CreatePopup( |
| 1352 | blink::WebLocalFrame* creator) { |
Julie Jeongeun Kim | caacf910 | 2019-09-12 02:13:05 | [diff] [blame] | 1353 | mojo::PendingRemote<mojom::Widget> widget_channel; |
| 1354 | mojo::PendingReceiver<mojom::Widget> widget_channel_receiver = |
| 1355 | widget_channel.InitWithNewPipeAndPassReceiver(); |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 1356 | |
Dave Tapuska | 8499eec | 2020-03-16 17:54:30 | [diff] [blame] | 1357 | mojo::PendingAssociatedRemote<blink::mojom::Widget> blink_widget; |
| 1358 | mojo::PendingAssociatedReceiver<blink::mojom::Widget> blink_widget_receiver = |
| 1359 | blink_widget.InitWithNewEndpointAndPassReceiver(); |
| 1360 | |
| 1361 | mojo::PendingAssociatedRemote<blink::mojom::WidgetHost> blink_widget_host; |
| 1362 | mojo::PendingAssociatedReceiver<blink::mojom::WidgetHost> |
| 1363 | blink_widget_host_receiver = |
| 1364 | blink_widget_host.InitWithNewEndpointAndPassReceiver(); |
| 1365 | |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 1366 | // Do a synchronous IPC to obtain a routing ID. |
| 1367 | int32_t widget_routing_id = MSG_ROUTING_NONE; |
| 1368 | bool success = |
Dave Tapuska | d983562 | 2020-03-10 17:32:31 | [diff] [blame] | 1369 | RenderFrameImpl::FromWebFrame(creator)->GetFrameHost()->CreateNewWidget( |
Dave Tapuska | 8499eec | 2020-03-16 17:54:30 | [diff] [blame] | 1370 | std::move(widget_channel), std::move(blink_widget_host_receiver), |
| 1371 | std::move(blink_widget), &widget_routing_id); |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 1372 | if (!success) { |
| 1373 | // When the renderer is being killed the mojo message will fail. |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 1374 | return nullptr; |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | RenderWidget::ShowCallback opener_callback = base::BindOnce( |
| 1378 | &RenderViewImpl::ShowCreatedPopupWidget, weak_ptr_factory_.GetWeakPtr()); |
| 1379 | |
danakj | 9359397 | 2019-10-11 00:02:49 | [diff] [blame] | 1380 | RenderWidget* opener_render_widget = |
Erik Chen | 6bc8da0 | 2019-09-20 15:51:38 | [diff] [blame] | 1381 | RenderFrameImpl::FromWebFrame(creator)->GetLocalRootRenderWidget(); |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 1382 | |
Erik Chen | 3433ee0 | 2019-08-05 20:14:26 | [diff] [blame] | 1383 | RenderWidget* popup_widget = RenderWidget::CreateForPopup( |
danakj | 9359397 | 2019-10-11 00:02:49 | [diff] [blame] | 1384 | widget_routing_id, opener_render_widget->compositor_deps(), |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 1385 | /*hidden=*/false, |
danakj | 77eb7e8 | 2020-01-09 19:38:46 | [diff] [blame] | 1386 | /*never_composited=*/false, std::move(widget_channel_receiver)); |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 1387 | |
| 1388 | // The returned WebPagePopup is self-referencing, so the pointer here is not |
danakj | 45e4a4f | 2019-03-12 22:50:42 | [diff] [blame] | 1389 | // an owning pointer. It is de-referenced by calling Close(). |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 1390 | blink::WebPagePopup* popup_web_widget = |
Dave Tapuska | 8499eec | 2020-03-16 17:54:30 | [diff] [blame] | 1391 | blink::WebPagePopup::Create(popup_widget, std::move(blink_widget_host), |
| 1392 | std::move(blink_widget_receiver)); |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 1393 | |
| 1394 | // Adds a self-reference on the |popup_widget| so it will not be destroyed |
| 1395 | // when leaving scope. The WebPagePopup takes responsibility for Close()ing |
| 1396 | // and thus destroying the RenderWidget. |
danakj | 9359397 | 2019-10-11 00:02:49 | [diff] [blame] | 1397 | popup_widget->InitForPopup(std::move(opener_callback), opener_render_widget, |
| 1398 | popup_web_widget, |
| 1399 | opener_render_widget->GetOriginalScreenInfo()); |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 1400 | return popup_web_widget; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1401 | } |
| 1402 | |
danakj | 295c43f18 | 2019-03-13 16:37:17 | [diff] [blame] | 1403 | void RenderViewImpl::DoDeferredClose() { |
| 1404 | // The main widget is currently not active. The active main frame widget is |
| 1405 | // in a different process. Have the browser route the close request to the |
| 1406 | // active widget instead, so that the correct unload handlers are run. |
| 1407 | Send(new ViewHostMsg_RouteCloseEvent(GetRoutingID())); |
| 1408 | } |
| 1409 | |
danakj | 45e4a4f | 2019-03-12 22:50:42 | [diff] [blame] | 1410 | void RenderViewImpl::CloseWindowSoon() { |
Avi Drissman | 07d2245 | 2019-03-25 17:56:39 | [diff] [blame] | 1411 | DCHECK(RenderThread::IsMainThread()); |
danakj | d330a8b | 2020-01-16 20:59:14 | [diff] [blame] | 1412 | if (!main_render_frame_) { |
danakj | 295c43f18 | 2019-03-13 16:37:17 | [diff] [blame] | 1413 | // Ask the RenderViewHost with a local main frame to initiate close. We |
| 1414 | // could be called from deep in Javascript. If we ask the RenderViewHost to |
| 1415 | // close now, the window could be closed before the JS finishes executing, |
danakj | bd1a86a | 2019-09-06 17:24:31 | [diff] [blame] | 1416 | // thanks to nested message loops running and handling the resulting Close |
danakj | 295c43f18 | 2019-03-13 16:37:17 | [diff] [blame] | 1417 | // IPC. So instead, post a message back to the message loop, which won't run |
| 1418 | // until the JS is complete, and then the Close request can be sent. |
| 1419 | GetCleanupTaskRunner()->PostTask( |
| 1420 | FROM_HERE, base::BindOnce(&RenderViewImpl::DoDeferredClose, |
| 1421 | weak_ptr_factory_.GetWeakPtr())); |
danakj | 45e4a4f | 2019-03-12 22:50:42 | [diff] [blame] | 1422 | return; |
| 1423 | } |
| 1424 | |
danakj | 50b3703 | 2020-01-15 22:44:00 | [diff] [blame] | 1425 | // If the main frame is in this RenderView's frame tree, then the Close |
danakj | d330a8b | 2020-01-16 20:59:14 | [diff] [blame] | 1426 | // request gets routed through the RenderWidget since non-frame RenderWidgets |
| 1427 | // share the code path. |
danakj | ee8f490 | 2020-01-17 18:06:10 | [diff] [blame] | 1428 | main_render_frame_->GetLocalRootRenderWidget()->CloseWidgetSoon(); |
danakj | 45e4a4f | 2019-03-12 22:50:42 | [diff] [blame] | 1429 | } |
| 1430 | |
Daniel Murphy | 31bbb8b1 | 2018-02-07 21:44:10 | [diff] [blame] | 1431 | base::StringPiece RenderViewImpl::GetSessionStorageNamespaceId() { |
| 1432 | CHECK(!session_storage_namespace_id_.empty()); |
Daniel Murphy | 0ce6e2c | 2017-11-21 01:54:26 | [diff] [blame] | 1433 | return session_storage_namespace_id_; |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1434 | } |
| 1435 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1436 | void RenderViewImpl::PrintPage(WebLocalFrame* frame) { |
Erik Chen | faa928c | 2019-09-20 23:41:15 | [diff] [blame] | 1437 | RenderFrameImpl* render_frame = RenderFrameImpl::FromWebFrame(frame); |
| 1438 | RenderWidget* render_widget = render_frame->GetLocalRootRenderWidget(); |
| 1439 | |
| 1440 | render_frame->ScriptedPrint( |
| 1441 | render_widget->input_handler().handling_input_event()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1442 | } |
| 1443 | |
danakj | cf409aa | 2019-09-20 15:22:30 | [diff] [blame] | 1444 | bool RenderViewImpl::SetZoomLevel(double zoom_level) { |
| 1445 | if (zoom_level == page_zoom_level_) |
| 1446 | return false; |
| 1447 | |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1448 | // If we change the zoom level for the view, make sure any subsequent subframe |
| 1449 | // loads reflect the current zoom level. |
| 1450 | page_zoom_level_ = zoom_level; |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1451 | GetWebView()->SetZoomLevel(zoom_level); |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 1452 | for (auto& observer : observers_) |
| 1453 | observer.OnZoomLevelChanged(); |
danakj | cf409aa | 2019-09-20 15:22:30 | [diff] [blame] | 1454 | return true; |
| 1455 | } |
| 1456 | |
| 1457 | void RenderViewImpl::SetPreferCompositingToLCDTextEnabled(bool prefer) { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1458 | GetWebView()->GetSettings()->SetPreferCompositingToLCDTextEnabled(prefer); |
danakj | cf409aa | 2019-09-20 15:22:30 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | void RenderViewImpl::SetDeviceScaleFactor(bool use_zoom_for_dsf, |
| 1462 | float device_scale_factor) { |
| 1463 | if (use_zoom_for_dsf) |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1464 | GetWebView()->SetZoomFactorForDeviceScaleFactor(device_scale_factor); |
danakj | cf409aa | 2019-09-20 15:22:30 | [diff] [blame] | 1465 | else |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1466 | GetWebView()->SetDeviceScaleFactor(device_scale_factor); |
danakj | cf409aa | 2019-09-20 15:22:30 | [diff] [blame] | 1467 | } |
| 1468 | |
danakj | d4533c7 | 2020-03-11 13:07:10 | [diff] [blame] | 1469 | void RenderViewImpl::SetVisibleViewportSizeForChildLocalRoot( |
| 1470 | const gfx::Size& visible_viewport_size) { |
| 1471 | // The main frame is updated on a different path. If we're in the same frame |
| 1472 | // tree as it, there's nothing to do for child local roots. |
| 1473 | if (main_render_frame_) |
| 1474 | return; |
| 1475 | |
| 1476 | // RenderWidgets in a RenderView's frame tree without a local main frame |
| 1477 | // set the size of the WebView to be the |visible_viewport_size|, in order |
| 1478 | // to limit compositing in (out of process) child frames to what is visible. |
| 1479 | // |
| 1480 | // Note that child frames in the same process/RenderView frame tree as the |
| 1481 | // main frame do not do this in order to not clobber the source of truth in |
| 1482 | // the main frame. |
| 1483 | GetWebView()->Resize(visible_viewport_size); |
| 1484 | } |
| 1485 | |
danakj | cf409aa | 2019-09-20 15:22:30 | [diff] [blame] | 1486 | void RenderViewImpl::PropagatePageZoomToNewlyAttachedFrame( |
| 1487 | bool use_zoom_for_dsf, |
| 1488 | float device_scale_factor) { |
| 1489 | if (use_zoom_for_dsf) |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1490 | GetWebView()->SetZoomFactorForDeviceScaleFactor(device_scale_factor); |
danakj | cf409aa | 2019-09-20 15:22:30 | [diff] [blame] | 1491 | else |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1492 | GetWebView()->SetZoomLevel(page_zoom_level_); |
tommycli | 8aad3ba | 2015-08-12 17:57:59 | [diff] [blame] | 1493 | } |
| 1494 | |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 1495 | void RenderViewImpl::SetValidationMessageDirection( |
| 1496 | base::string16* wrapped_main_text, |
Miyoung Shin | 8dabef3 | 2020-02-19 16:25:25 | [diff] [blame] | 1497 | base::i18n::TextDirection main_text_hint, |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 1498 | base::string16* wrapped_sub_text, |
Miyoung Shin | 8dabef3 | 2020-02-19 16:25:25 | [diff] [blame] | 1499 | base::i18n::TextDirection sub_text_hint) { |
| 1500 | if (main_text_hint == base::i18n::LEFT_TO_RIGHT) { |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 1501 | *wrapped_main_text = |
| 1502 | base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text); |
Miyoung Shin | 8dabef3 | 2020-02-19 16:25:25 | [diff] [blame] | 1503 | } else if (main_text_hint == base::i18n::RIGHT_TO_LEFT && |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 1504 | !base::i18n::IsRTL()) { |
| 1505 | base::i18n::WrapStringWithRTLFormatting(wrapped_main_text); |
| 1506 | } |
| 1507 | |
| 1508 | if (!wrapped_sub_text->empty()) { |
Miyoung Shin | 8dabef3 | 2020-02-19 16:25:25 | [diff] [blame] | 1509 | if (sub_text_hint == base::i18n::RIGHT_TO_LEFT) { |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 1510 | *wrapped_sub_text = |
| 1511 | base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text); |
Miyoung Shin | 8dabef3 | 2020-02-19 16:25:25 | [diff] [blame] | 1512 | } else if (sub_text_hint == base::i18n::LEFT_TO_RIGHT) { |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 1513 | base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text); |
| 1514 | } |
| 1515 | } |
| 1516 | } |
| 1517 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1518 | void RenderViewImpl::UpdateTargetURL(const GURL& url, |
| 1519 | const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 1520 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1521 | if (latest_url == target_url_) |
| 1522 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1523 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1524 | // Tell the browser to display a destination link. |
| 1525 | if (target_url_status_ == TARGET_INFLIGHT || |
| 1526 | target_url_status_ == TARGET_PENDING) { |
| 1527 | // If we have a request in-flight, save the URL to be sent when we |
| 1528 | // receive an ACK to the in-flight request. We can happily overwrite |
| 1529 | // any existing pending sends. |
| 1530 | pending_target_url_ = latest_url; |
| 1531 | target_url_status_ = TARGET_PENDING; |
| 1532 | } else { |
mnaganov | bf08742 | 2015-12-16 05:10:03 | [diff] [blame] | 1533 | // URLs larger than |kMaxURLChars| cannot be sent through IPC - |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 1534 | // see |ParamTraits<GURL>|. |
markdittmer | 67b71ea | 2016-03-03 22:40:03 | [diff] [blame] | 1535 | if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars) |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 1536 | latest_url = GURL(); |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 1537 | Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), latest_url)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1538 | target_url_ = latest_url; |
| 1539 | target_url_status_ = TARGET_INFLIGHT; |
| 1540 | } |
| 1541 | } |
| 1542 | |
creis | 69b184a47 | 2015-11-26 05:29:51 | [diff] [blame] | 1543 | void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) { |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 1544 | // Keep track of which frames have pending updates. |
| 1545 | frames_with_pending_state_.insert(frame->GetRoutingID()); |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 1546 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1547 | int delay; |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1548 | if (send_content_state_immediately_) |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1549 | delay = 0; |
Collin Baker | 98457b5 | 2019-11-06 21:34:29 | [diff] [blame] | 1550 | else if (GetWebView()->GetVisibilityState() != PageVisibilityState::kVisible) |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1551 | delay = kDelaySecondsForContentStateSyncHidden; |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1552 | else |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1553 | delay = kDelaySecondsForContentStateSync; |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1554 | |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1555 | if (nav_state_sync_timer_.IsRunning()) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1556 | // The timer is already running. If the delay of the timer maches the amount |
| 1557 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 1558 | // gets started with the right delay. |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1559 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1560 | return; |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1561 | nav_state_sync_timer_.Stop(); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1562 | } |
| 1563 | |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 1564 | // Tell each frame with pending state to inform the browser. |
danakj | 19f3e51 | 2018-12-14 21:02:05 | [diff] [blame] | 1565 | nav_state_sync_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay), |
| 1566 | this, &RenderViewImpl::SendFrameStateUpdates); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1567 | } |
| 1568 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1569 | void RenderViewImpl::SetMouseOverURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1570 | mouse_over_url_ = GURL(url); |
| 1571 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 1572 | } |
| 1573 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1574 | void RenderViewImpl::SetKeyboardFocusURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1575 | focus_url_ = GURL(url); |
| 1576 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 1577 | } |
| 1578 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1579 | bool RenderViewImpl::AcceptsLoadDrops() { |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 1580 | return renderer_preferences_.can_accept_load_drops; |
| 1581 | } |
| 1582 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1583 | void RenderViewImpl::FocusNext() { |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 1584 | Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1585 | } |
| 1586 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1587 | void RenderViewImpl::FocusPrevious() { |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 1588 | Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1589 | } |
| 1590 | |
Philip Rogers | 07965881 | 2018-08-01 23:19:09 | [diff] [blame] | 1591 | void RenderViewImpl::DidUpdateMainFrameLayout() { |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 1592 | for (auto& observer : observers_) |
Philip Rogers | 07965881 | 2018-08-01 23:19:09 | [diff] [blame] | 1593 | observer.DidUpdateMainFrameLayout(); |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 1594 | } |
| 1595 | |
Michael Martis | 2415478f | 2019-04-17 07:35:00 | [diff] [blame] | 1596 | void RenderViewImpl::RegisterRendererPreferenceWatcher( |
Julie Jeongeun Kim | 6d8b749 | 2019-08-20 19:24:11 | [diff] [blame] | 1597 | mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) { |
| 1598 | renderer_preference_watchers_.Add(std::move(watcher)); |
Makoto Shimazu | c3c730e | 2018-08-15 09:51:11 | [diff] [blame] | 1599 | } |
| 1600 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1601 | int RenderViewImpl::HistoryBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1602 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1603 | } |
| 1604 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1605 | int RenderViewImpl::HistoryForwardListCount() { |
| 1606 | return history_list_length_ - HistoryBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1607 | } |
| 1608 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1609 | // blink::WebWidgetClient ---------------------------------------------------- |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1610 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1611 | bool RenderViewImpl::CanHandleGestureEvent() { |
slangley | 1a6375e6 | 2017-03-29 06:03:23 | [diff] [blame] | 1612 | return true; |
| 1613 | } |
| 1614 | |
Avi Drissman | 4a80048 | 2019-12-12 15:03:28 | [diff] [blame] | 1615 | // TODO(https://crbug.com/937569): Remove this in Chrome 88. |
Avi Drissman | fb96126 | 2019-03-05 22:50:29 | [diff] [blame] | 1616 | bool RenderViewImpl::AllowPopupsDuringPageUnload() { |
Avi Drissman | 16dfa1c | 2019-10-09 21:41:13 | [diff] [blame] | 1617 | // The switch version is for enabling via enterprise policy. The feature |
| 1618 | // version is for enabling via about:flags and Finch policy. |
Avi Drissman | fb96126 | 2019-03-05 22:50:29 | [diff] [blame] | 1619 | const base::CommandLine& command_line = |
| 1620 | *base::CommandLine::ForCurrentProcess(); |
Avi Drissman | 7e5079f | 2019-09-30 14:06:40 | [diff] [blame] | 1621 | return command_line.HasSwitch(switches::kAllowPopupsDuringPageUnload) || |
| 1622 | base::FeatureList::IsEnabled(features::kAllowPopupsDuringPageUnload); |
Avi Drissman | fb96126 | 2019-03-05 22:50:29 | [diff] [blame] | 1623 | } |
| 1624 | |
Yuzu Saijo | be024af0 | 2020-05-11 07:35:56 | [diff] [blame] | 1625 | void RenderViewImpl::OnPageVisibilityChanged(PageVisibilityState visibility) { |
| 1626 | #if defined(OS_ANDROID) |
| 1627 | SuspendVideoCaptureDevices(visibility != PageVisibilityState::kVisible); |
| 1628 | #endif |
| 1629 | for (auto& observer : observers_) |
| 1630 | observer.OnPageVisibilityChanged(visibility); |
| 1631 | } |
| 1632 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1633 | bool RenderViewImpl::CanUpdateLayout() { |
slangley | 1a6375e6 | 2017-03-29 06:03:23 | [diff] [blame] | 1634 | return true; |
| 1635 | } |
| 1636 | |
Lucas Furukawa Gadani | d51ff5d6 | 2018-12-07 21:26:49 | [diff] [blame] | 1637 | const std::string& RenderViewImpl::GetAcceptLanguages() { |
[email protected] | b38806a | 2013-10-04 16:01:38 | [diff] [blame] | 1638 | return renderer_preferences_.accept_languages; |
| 1639 | } |
| 1640 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1641 | blink::WebString RenderViewImpl::AcceptLanguages() { |
| 1642 | return WebString::FromUTF8(renderer_preferences_.accept_languages); |
[email protected] | 9982c80 | 2013-06-12 15:22:06 | [diff] [blame] | 1643 | } |
| 1644 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1645 | // RenderView implementation --------------------------------------------------- |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1646 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1647 | bool RenderViewImpl::Send(IPC::Message* message) { |
danakj | 3130f12 | 2019-07-16 17:49:47 | [diff] [blame] | 1648 | // No messages sent through RenderView come without a routing id, yay. Let's |
| 1649 | // keep that up. |
| 1650 | CHECK_NE(message->routing_id(), MSG_ROUTING_NONE); |
danakj | 3130f12 | 2019-07-16 17:49:47 | [diff] [blame] | 1651 | return RenderThread::Get()->Send(message); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1652 | } |
| 1653 | |
mostynb | c3335323 | 2014-09-12 09:38:31 | [diff] [blame] | 1654 | RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() { |
nasko | 77de231 | 2015-05-12 03:09:16 | [diff] [blame] | 1655 | return main_render_frame_; |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 1656 | } |
| 1657 | |
Lucas Furukawa Gadani | d51ff5d6 | 2018-12-07 21:26:49 | [diff] [blame] | 1658 | int RenderViewImpl::GetRoutingID() { |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 1659 | return routing_id_; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1660 | } |
| 1661 | |
Lucas Furukawa Gadani | d51ff5d6 | 2018-12-07 21:26:49 | [diff] [blame] | 1662 | float RenderViewImpl::GetZoomLevel() { |
Marc Treib | 06d6603 | 2017-10-19 08:43:20 | [diff] [blame] | 1663 | return page_zoom_level_; |
| 1664 | } |
| 1665 | |
thestig | 8a8fdfd3 | 2017-05-06 18:46:54 | [diff] [blame] | 1666 | const WebPreferences& RenderViewImpl::GetWebkitPreferences() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1667 | return webkit_preferences_; |
| 1668 | } |
| 1669 | |
[email protected] | 324825d | 2012-11-30 12:37:15 | [diff] [blame] | 1670 | void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) { |
| 1671 | OnUpdateWebPreferences(preferences); |
| 1672 | } |
| 1673 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1674 | blink::WebView* RenderViewImpl::GetWebView() { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1675 | return webview_; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1676 | } |
| 1677 | |
Lucas Furukawa Gadani | d51ff5d6 | 2018-12-07 21:26:49 | [diff] [blame] | 1678 | bool RenderViewImpl::GetContentStateImmediately() { |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1679 | return send_content_state_immediately_; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1680 | } |
| 1681 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1682 | void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 1683 | webkit_preferences_ = prefs; |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1684 | ApplyWebPreferences(webkit_preferences_, GetWebView()); |
v.paturi | 8f6ed96 | 2020-03-17 18:03:10 | [diff] [blame] | 1685 | ApplyCommandLineToSettings(GetWebView()->GetSettings()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1686 | } |
| 1687 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1688 | void RenderViewImpl::OnSetRendererPrefs( |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 1689 | const blink::mojom::RendererPreferences& renderer_prefs) { |
[email protected] | ebd5ea5 | 2014-05-28 14:51:15 | [diff] [blame] | 1690 | std::string old_accept_languages = renderer_preferences_.accept_languages; |
| 1691 | |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1692 | renderer_preferences_ = renderer_prefs; |
ananta | 59b9fe7 | 2015-04-07 01:33:26 | [diff] [blame] | 1693 | |
Julie Jeongeun Kim | 6d8b749 | 2019-08-20 19:24:11 | [diff] [blame] | 1694 | for (auto& watcher : renderer_preference_watchers_) |
| 1695 | watcher->NotifyUpdate(renderer_prefs.Clone()); |
Makoto Shimazu | c3c730e | 2018-08-15 09:51:11 | [diff] [blame] | 1696 | |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 1697 | UpdateFontRenderingFromRendererPrefs(); |
scottmg | b92365e | 2016-08-30 20:54:40 | [diff] [blame] | 1698 | UpdateThemePrefs(); |
Leon Han | 2c81b5d | 2019-01-25 01:58:33 | [diff] [blame] | 1699 | blink::SetCaretBlinkInterval( |
| 1700 | renderer_prefs.caret_blink_interval.has_value() |
| 1701 | ? renderer_prefs.caret_blink_interval.value() |
| 1702 | : base::TimeDelta::FromMilliseconds( |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 1703 | blink::mojom::kDefaultCaretBlinkIntervalInMilliseconds)); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 1704 | |
Christopher Cameron | f8e279d3 | 2019-05-15 18:50:56 | [diff] [blame] | 1705 | #if defined(USE_AURA) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 1706 | if (renderer_prefs.use_custom_colors) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1707 | blink::SetFocusRingColor(renderer_prefs.focus_ring_color); |
Christopher Cameron | f6fc7ec | 2019-05-13 18:52:53 | [diff] [blame] | 1708 | blink::SetSelectionColors(renderer_prefs.active_selection_bg_color, |
| 1709 | renderer_prefs.active_selection_fg_color, |
| 1710 | renderer_prefs.inactive_selection_bg_color, |
| 1711 | renderer_prefs.inactive_selection_fg_color); |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1712 | if (GetWebView() && GetWebView()->MainFrameWidget()) |
| 1713 | GetWebView()->MainFrameWidget()->ThemeChanged(); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 1714 | } |
Christopher Cameron | f8e279d3 | 2019-05-15 18:50:56 | [diff] [blame] | 1715 | #endif |
[email protected] | d299d97 | 2012-03-23 02:26:55 | [diff] [blame] | 1716 | |
Ionel Popescu | 2649f2f | 2020-01-10 10:06:59 | [diff] [blame] | 1717 | if (features::IsFormControlsRefreshEnabled() && |
| 1718 | renderer_prefs.use_custom_colors) { |
| 1719 | blink::SetFocusRingColor(renderer_prefs.focus_ring_color); |
| 1720 | } |
| 1721 | |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1722 | if (GetWebView() && |
[email protected] | ebd5ea5 | 2014-05-28 14:51:15 | [diff] [blame] | 1723 | old_accept_languages != renderer_preferences_.accept_languages) { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1724 | GetWebView()->AcceptLanguagesChanged(); |
[email protected] | ebd5ea5 | 2014-05-28 14:51:15 | [diff] [blame] | 1725 | } |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1726 | } |
| 1727 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1728 | void RenderViewImpl::OnMoveOrResizeStarted() { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1729 | if (GetWebView()) |
| 1730 | GetWebView()->CancelPagePopup(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 1731 | } |
| 1732 | |
Francois Doray | 47f759d | 2018-06-11 18:13:51 | [diff] [blame] | 1733 | void RenderViewImpl::SetPageFrozen(bool frozen) { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1734 | if (GetWebView()) |
| 1735 | GetWebView()->SetPageFrozen(frozen); |
Fadi Meawad | a6573e0 | 2018-03-10 00:52:11 | [diff] [blame] | 1736 | } |
| 1737 | |
Yuzu Saijo | dfba8fa6 | 2019-08-27 02:15:22 | [diff] [blame] | 1738 | void RenderViewImpl::PutPageIntoBackForwardCache() { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1739 | if (GetWebView()) |
| 1740 | GetWebView()->PutPageIntoBackForwardCache(); |
Yuzu Saijo | dfba8fa6 | 2019-08-27 02:15:22 | [diff] [blame] | 1741 | } |
| 1742 | |
Fergal Daly | 87f79d6 | 2019-11-11 01:24:04 | [diff] [blame] | 1743 | void RenderViewImpl::RestorePageFromBackForwardCache( |
| 1744 | base::TimeTicks navigation_start) { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1745 | if (GetWebView()) |
| 1746 | GetWebView()->RestorePageFromBackForwardCache(navigation_start); |
Yuzu Saijo | dfba8fa6 | 2019-08-27 02:15:22 | [diff] [blame] | 1747 | } |
| 1748 | |
W. James MacLean | 6219867 | 2019-06-04 16:46:10 | [diff] [blame] | 1749 | // This function receives TextAutosizerPageInfo from the main frame's renderer |
| 1750 | // and makes it available to other renderers with frames on the same page. |
| 1751 | void RenderViewImpl::OnTextAutosizerPageInfoChanged( |
| 1752 | const blink::WebTextAutosizerPageInfo& page_info) { |
| 1753 | // Only propagate the remote page info if our main frame is remote. It's |
| 1754 | // possible a main frame renderer may receive this message, as SendPageMessage |
| 1755 | // in RenderFrameHostManager may send to a speculative RenderFrameHost that |
| 1756 | // corresponds to a local main frame. Since a local main frame will generate |
| 1757 | // these values for itself, we shouldn't override them with values from |
| 1758 | // another renderer. |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1759 | if (!GetWebView()->MainFrame()->IsWebLocalFrame()) |
Henrique Ferreiro | 6e80e25c | 2020-03-02 12:01:52 | [diff] [blame] | 1760 | GetWebView()->SetTextAutosizerPageInfo(page_info); |
W. James MacLean | 6219867 | 2019-06-04 16:46:10 | [diff] [blame] | 1761 | } |
| 1762 | |
Adithya Srinivasan | 11af2c5 | 2019-12-16 22:52:55 | [diff] [blame] | 1763 | void RenderViewImpl::OnSetInsidePortal(bool inside_portal) { |
Antonio Gomes | 778a0f7 | 2020-02-24 13:52:44 | [diff] [blame] | 1764 | GetWebView()->SetInsidePortal(inside_portal); |
Adithya Srinivasan | 11af2c5 | 2019-12-16 22:52:55 | [diff] [blame] | 1765 | } |
| 1766 | |
danakj | 9a8a9cf | 2018-07-17 23:52:12 | [diff] [blame] | 1767 | void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) { |
Erik Chen | e4ae6b4 | 2019-10-01 12:06:28 | [diff] [blame] | 1768 | // Auto resize should only happen on local main frames. |
danakj | ee8f490 | 2020-01-17 18:06:10 | [diff] [blame] | 1769 | DCHECK(main_render_frame_); |
| 1770 | main_render_frame_->GetLocalRootRenderWidget()->DidAutoResize(newSize); |
danakj | 9a8a9cf | 2018-07-17 23:52:12 | [diff] [blame] | 1771 | } |
| 1772 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1773 | void RenderViewImpl::DidFocus(blink::WebLocalFrame* calling_frame) { |
danakj | 674bf1c0 | 2020-05-01 18:37:51 | [diff] [blame] | 1774 | // We only allow focus to move to this RenderView when the request comes from |
| 1775 | // a user gesture. (See also https://bugs.webkit.org/show_bug.cgi?id=33389.) |
| 1776 | if (calling_frame && calling_frame->HasTransientUserActivation()) { |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1777 | Send(new ViewHostMsg_Focus(GetRoutingID())); |
| 1778 | |
| 1779 | // Tattle on the frame that called |window.focus()|. |
| 1780 | RenderFrameImpl* calling_render_frame = |
| 1781 | RenderFrameImpl::FromWebFrame(calling_frame); |
| 1782 | if (calling_render_frame) |
| 1783 | calling_render_frame->FrameDidCallFocus(); |
| 1784 | } |
| 1785 | } |
| 1786 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 1787 | #if defined(OS_ANDROID) |
braveyao | 1d8ee7b | 2017-03-29 21:10:04 | [diff] [blame] | 1788 | void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) { |
| 1789 | if (!main_render_frame_) |
| 1790 | return; |
| 1791 | |
Guido Urdaneta | dc709037 | 2019-07-29 17:59:54 | [diff] [blame] | 1792 | blink::WebMediaStreamDeviceObserver* media_stream_device_observer = |
Antonio Gomes | 32f24faf | 2019-08-18 16:41:36 | [diff] [blame] | 1793 | main_render_frame_->MediaStreamDeviceObserver(); |
Chandan Padhi | 26dbd9b3 | 2017-11-27 11:13:35 | [diff] [blame] | 1794 | if (!media_stream_device_observer) |
braveyao | 1d8ee7b | 2017-03-29 21:10:04 | [diff] [blame] | 1795 | return; |
| 1796 | |
Guido Urdaneta | 73fa663 | 2019-01-14 18:46:26 | [diff] [blame] | 1797 | blink::MediaStreamDevices video_devices = |
Chandan Padhi | 26dbd9b3 | 2017-11-27 11:13:35 | [diff] [blame] | 1798 | media_stream_device_observer->GetNonScreenCaptureDevices(); |
braveyao | 1d8ee7b | 2017-03-29 21:10:04 | [diff] [blame] | 1799 | RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices( |
Chandan Padhi | 6dbfb73 | 2017-09-01 16:08:49 | [diff] [blame] | 1800 | video_devices, suspend); |
braveyao | 1d8ee7b | 2017-03-29 21:10:04 | [diff] [blame] | 1801 | } |
estade | 6b9696bd | 2016-05-04 23:51:36 | [diff] [blame] | 1802 | #endif // defined(OS_ANDROID) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 1803 | |
[email protected] | b283d29 | 2013-02-21 08:40:34 | [diff] [blame] | 1804 | unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const { |
| 1805 | return history_list_length_; |
| 1806 | } |
| 1807 | |
danakj | 295c43f18 | 2019-03-13 16:37:17 | [diff] [blame] | 1808 | // static |
| 1809 | scoped_refptr<base::SingleThreadTaskRunner> |
| 1810 | RenderViewImpl::GetCleanupTaskRunner() { |
| 1811 | return RenderThreadImpl::current_blink_platform_impl() |
| 1812 | ->main_thread_scheduler() |
| 1813 | ->CleanupTaskRunner(); |
| 1814 | } |
| 1815 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1816 | } // namespace content |