[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" |
asvitkine | 8d51e9d | 2016-09-02 23:55:43 | [diff] [blame] | 25 | #include "base/metrics/histogram_macros.h" |
[email protected] | d3b4ee2 | 2013-07-24 22:50:06 | [diff] [blame] | 26 | #include "base/process/kill.h" |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 27 | #include "base/process/process.h" |
fdoray | 7a8954a4 | 2016-06-07 04:28:38 | [diff] [blame] | 28 | #include "base/single_thread_task_runner.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" |
dalecurtis | cd97125 | 2016-09-21 16:09:00 | [diff] [blame] | 35 | #include "base/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" |
Daniel Murphy | e3eec92c | 2018-02-23 19:09:15 | [diff] [blame] | 44 | #include "content/common/dom_storage/dom_storage_namespace_ids.h" |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 45 | #include "content/common/dom_storage/dom_storage_types.h" |
[email protected] | 59f4f2fa | 2011-03-23 01:00:55 | [diff] [blame] | 46 | #include "content/common/drag_messages.h" |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 47 | #include "content/common/frame_messages.h" |
alexmos | bc7eafa | 2014-12-06 01:38:09 | [diff] [blame] | 48 | #include "content/common/frame_replication_state.h" |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 49 | #include "content/common/input_messages.h" |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 50 | #include "content/common/page_messages.h" |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 51 | #include "content/common/render_message_filter.mojom.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 52 | #include "content/common/view_messages.h" |
arthursonzogni | c517fc3 | 2016-08-11 11:04:24 | [diff] [blame] | 53 | #include "content/public/common/browser_side_navigation_policy.h" |
[email protected] | 744c2a2 | 2012-03-15 18:42:04 | [diff] [blame] | 54 | #include "content/public/common/content_client.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 55 | #include "content/public/common/content_constants.h" |
Tarun Bansal | 73dd2ff8 | 2017-10-03 05:29:34 | [diff] [blame] | 56 | #include "content/public/common/content_features.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 57 | #include "content/public/common/content_switches.h" |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 58 | #include "content/public/common/page_importance_signals.h" |
clamy | da97e832 | 2014-10-07 21:57:25 | [diff] [blame] | 59 | #include "content/public/common/page_state.h" |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 60 | #include "content/public/common/page_zoom.h" |
[email protected] | 818915cd | 2012-11-20 13:14:11 | [diff] [blame] | 61 | #include "content/public/common/three_d_api_types.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 62 | #include "content/public/common/url_constants.h" |
Jaebaek Seo | 53ab80a66 | 2018-01-29 04:50:46 | [diff] [blame] | 63 | #include "content/public/common/use_zoom_for_dsf_policy.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 64 | #include "content/public/common/web_preferences.h" |
[email protected] | d344114c | 2011-10-01 01:24:34 | [diff] [blame] | 65 | #include "content/public/renderer/content_renderer_client.h" |
[email protected] | 007733c | 2011-11-17 00:34:07 | [diff] [blame] | 66 | #include "content/public/renderer/document_state.h" |
[email protected] | 82ddba1c | 2011-10-04 00:15:32 | [diff] [blame] | 67 | #include "content/public/renderer/navigation_state.h" |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 68 | #include "content/public/renderer/render_view_observer.h" |
[email protected] | 64ffa044 | 2011-10-03 22:08:36 | [diff] [blame] | 69 | #include "content/public/renderer/render_view_visitor.h" |
scottmg | 8e6c608 | 2017-02-13 23:15:48 | [diff] [blame] | 70 | #include "content/public/renderer/window_features_converter.h" |
John Abd-El-Malek | dcf1d137 | 2017-10-22 06:39:41 | [diff] [blame] | 71 | #include "content/renderer/appcache/appcache_dispatcher.h" |
| 72 | #include "content/renderer/appcache/web_application_cache_host_impl.h" |
[email protected] | e6e5675 | 2012-08-10 00:46:06 | [diff] [blame] | 73 | #include "content/renderer/browser_plugin/browser_plugin.h" |
| 74 | #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
[email protected] | dc293a7 | 2013-07-01 11:11:22 | [diff] [blame] | 75 | #include "content/renderer/drop_data_builder.h" |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 76 | #include "content/renderer/gpu/layer_tree_view.h" |
[email protected] | dc06435 | 2014-04-25 08:36:38 | [diff] [blame] | 77 | #include "content/renderer/history_serialization.h" |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 78 | #include "content/renderer/ime_event_guard.h" |
[email protected] | 92d45780 | 2013-04-01 19:18:49 | [diff] [blame] | 79 | #include "content/renderer/internal_document_state_data.h" |
John Abd-El-Malek | 6b56ef71 | 2017-10-21 22:52:46 | [diff] [blame] | 80 | #include "content/renderer/loader/request_extra_data.h" |
Amos Lim | bcc710e | 2018-06-08 05:51:17 | [diff] [blame] | 81 | #include "content/renderer/media/audio/audio_device_factory.h" |
Miguel Casas | a8c2c5a | 2018-02-12 18:51:03 | [diff] [blame] | 82 | #include "content/renderer/media/stream/media_stream_device_observer.h" |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 83 | #include "content/renderer/media/video_capture_impl_manager.h" |
Patrik Höglund | b564859b | 2018-05-17 11:17:16 | [diff] [blame] | 84 | #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" |
| 85 | #include "content/renderer/media/webrtc/rtc_peer_connection_handler.h" |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 86 | #include "content/renderer/navigation_state_impl.h" |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 87 | #include "content/renderer/render_frame_impl.h" |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 88 | #include "content/renderer/render_frame_proxy.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 89 | #include "content/renderer/render_process.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 90 | #include "content/renderer/render_thread_impl.h" |
[email protected] | 2cff005 | 2011-03-18 16:51:44 | [diff] [blame] | 91 | #include "content/renderer/render_widget_fullscreen_pepper.h" |
Daniel Murphy | e3eec92c | 2018-02-23 19:09:15 | [diff] [blame] | 92 | #include "content/renderer/renderer_blink_platform_impl.h" |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 93 | #include "content/renderer/renderer_webapplicationcachehost_impl.h" |
[email protected] | 5b45ad4 | 2013-10-25 00:42:04 | [diff] [blame] | 94 | #include "content/renderer/resizing_mode_selector.h" |
[email protected] | 12a936d | 2013-05-15 04:55:49 | [diff] [blame] | 95 | #include "content/renderer/savable_resources.h" |
John Abd-El-Malek | 312a30bb | 2017-10-23 19:51:52 | [diff] [blame] | 96 | #include "content/renderer/v8_value_converter_impl.h" |
[email protected] | 940ed1d | 2012-11-27 21:03:21 | [diff] [blame] | 97 | #include "content/renderer/web_ui_extension_data.h" |
[email protected] | f596114 | 2013-04-17 23:09:42 | [diff] [blame] | 98 | #include "media/audio/audio_output_device.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 99 | #include "media/base/media_switches.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 100 | #include "media/media_buildflags.h" |
servolk | f54f5c8f | 2015-02-24 20:32:39 | [diff] [blame] | 101 | #include "media/renderers/audio_renderer_impl.h" |
Dale Curtis | 863022e | 2017-08-19 02:05:34 | [diff] [blame] | 102 | #include "media/video/gpu_video_accelerator_factories.h" |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 103 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 104 | #include "net/base/escape.h" |
| 105 | #include "net/base/net_errors.h" |
[email protected] | 18fb7a77 | 2012-09-20 19:25:09 | [diff] [blame] | 106 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 52c6865 | 2010-12-07 17:47:04 | [diff] [blame] | 107 | #include "net/http/http_util.h" |
Tarun Bansal | 73d67f0 | 2018-01-17 05:56:25 | [diff] [blame] | 108 | #include "net/nqe/effective_connection_type.h" |
Scott Violet | 02e38b9 | 2018-03-27 23:42:14 | [diff] [blame] | 109 | #include "ppapi/buildflags/buildflags.h" |
luken | b171b53 | 2014-09-24 05:50:38 | [diff] [blame] | 110 | #include "skia/ext/platform_canvas.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 111 | #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" |
Mustaq Ahmed | 76c2f431 | 2018-06-07 20:48:01 | [diff] [blame] | 112 | #include "third_party/blink/public/common/frame/user_activation_update_source.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 113 | #include "third_party/blink/public/mojom/page/page_visibility_state.mojom.h" |
| 114 | #include "third_party/blink/public/platform/file_path_conversion.h" |
| 115 | #include "third_party/blink/public/platform/url_conversion.h" |
| 116 | #include "third_party/blink/public/platform/web_connection_type.h" |
| 117 | #include "third_party/blink/public/platform/web_effective_connection_type.h" |
| 118 | #include "third_party/blink/public/platform/web_http_body.h" |
| 119 | #include "third_party/blink/public/platform/web_image.h" |
| 120 | #include "third_party/blink/public/platform/web_input_event.h" |
| 121 | #include "third_party/blink/public/platform/web_input_event_result.h" |
| 122 | #include "third_party/blink/public/platform/web_network_state_notifier.h" |
| 123 | #include "third_party/blink/public/platform/web_point.h" |
| 124 | #include "third_party/blink/public/platform/web_rect.h" |
| 125 | #include "third_party/blink/public/platform/web_runtime_features.h" |
| 126 | #include "third_party/blink/public/platform/web_size.h" |
| 127 | #include "third_party/blink/public/platform/web_string.h" |
| 128 | #include "third_party/blink/public/platform/web_url.h" |
| 129 | #include "third_party/blink/public/platform/web_url_error.h" |
| 130 | #include "third_party/blink/public/platform/web_url_request.h" |
| 131 | #include "third_party/blink/public/platform/web_url_response.h" |
| 132 | #include "third_party/blink/public/platform/web_vector.h" |
| 133 | #include "third_party/blink/public/public_buildflags.h" |
| 134 | #include "third_party/blink/public/web/web_autofill_client.h" |
| 135 | #include "third_party/blink/public/web/web_ax_object.h" |
| 136 | #include "third_party/blink/public/web/web_date_time_chooser_completion.h" |
| 137 | #include "third_party/blink/public/web/web_date_time_chooser_params.h" |
| 138 | #include "third_party/blink/public/web/web_document.h" |
| 139 | #include "third_party/blink/public/web/web_dom_event.h" |
| 140 | #include "third_party/blink/public/web/web_dom_message_event.h" |
| 141 | #include "third_party/blink/public/web/web_element.h" |
| 142 | #include "third_party/blink/public/web/web_file_chooser_params.h" |
| 143 | #include "third_party/blink/public/web/web_form_control_element.h" |
| 144 | #include "third_party/blink/public/web/web_form_element.h" |
| 145 | #include "third_party/blink/public/web/web_frame.h" |
| 146 | #include "third_party/blink/public/web/web_frame_content_dumper.h" |
| 147 | #include "third_party/blink/public/web/web_frame_widget.h" |
| 148 | #include "third_party/blink/public/web/web_history_item.h" |
| 149 | #include "third_party/blink/public/web/web_hit_test_result.h" |
| 150 | #include "third_party/blink/public/web/web_input_element.h" |
| 151 | #include "third_party/blink/public/web/web_local_frame.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 152 | #include "third_party/blink/public/web/web_navigation_policy.h" |
| 153 | #include "third_party/blink/public/web/web_page_importance_signals.h" |
| 154 | #include "third_party/blink/public/web/web_plugin.h" |
| 155 | #include "third_party/blink/public/web/web_plugin_action.h" |
| 156 | #include "third_party/blink/public/web/web_range.h" |
| 157 | #include "third_party/blink/public/web/web_render_theme.h" |
| 158 | #include "third_party/blink/public/web/web_script_source.h" |
| 159 | #include "third_party/blink/public/web/web_searchable_form_data.h" |
| 160 | #include "third_party/blink/public/web/web_security_policy.h" |
| 161 | #include "third_party/blink/public/web/web_settings.h" |
| 162 | #include "third_party/blink/public/web/web_user_gesture_indicator.h" |
| 163 | #include "third_party/blink/public/web/web_view.h" |
| 164 | #include "third_party/blink/public/web/web_window_features.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 165 | #include "third_party/icu/source/common/unicode/uchar.h" |
| 166 | #include "third_party/icu/source/common/unicode/uscript.h" |
eseckler | f2bd55f7 | 2017-03-31 09:11:57 | [diff] [blame] | 167 | #include "third_party/skia/include/core/SkColor.h" |
[email protected] | 1400e6dc | 2013-04-27 02:36:27 | [diff] [blame] | 168 | #include "ui/base/ui_base_switches_util.h" |
tfarina | 655f81d | 2014-12-23 02:38:50 | [diff] [blame] | 169 | #include "ui/gfx/geometry/point.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 170 | #include "ui/gfx/geometry/rect.h" |
| 171 | #include "ui/gfx/geometry/rect_conversions.h" |
tfarina | ebe974f0 | 2015-01-03 04:25:32 | [diff] [blame] | 172 | #include "ui/gfx/geometry/size_conversions.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 173 | #include "ui/gfx/native_widget_types.h" |
ccameron | 772317d | 2017-06-04 18:35:03 | [diff] [blame] | 174 | #include "ui/gfx/switches.h" |
mfomitchev | 3ba450ad | 2017-04-03 18:20:40 | [diff] [blame] | 175 | #include "ui/latency/latency_info.h" |
csharrison | d88f975 | 2016-10-26 23:56:36 | [diff] [blame] | 176 | #include "url/origin.h" |
markdittmer | 67b71ea | 2016-03-03 22:40:03 | [diff] [blame] | 177 | #include "url/url_constants.h" |
[email protected] | c4a9e93 | 2011-03-05 04:05:55 | [diff] [blame] | 178 | #include "v8/include/v8.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 179 | |
[email protected] | 25fb9b3 | 2012-04-27 03:21:55 | [diff] [blame] | 180 | #if defined(OS_ANDROID) |
[email protected] | befe5478 | 2013-04-23 00:49:25 | [diff] [blame] | 181 | #include <cpu-features.h> |
| 182 | |
dalecurtis | cd97125 | 2016-09-21 16:09:00 | [diff] [blame] | 183 | #include "base/android/build_info.h" |
kylechar | e7d8d5c7 | 2018-01-05 19:06:28 | [diff] [blame] | 184 | #include "base/memory/shared_memory.h" |
| 185 | #include "content/child/child_thread_impl.h" |
estade | 6b9696bd | 2016-05-04 23:51:36 | [diff] [blame] | 186 | #include "content/renderer/android/disambiguation_popup_helper.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 187 | #include "ui/gfx/geometry/rect_f.h" |
[email protected] | e69bb06 | 2013-06-03 13:05:40 | [diff] [blame] | 188 | |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 189 | #elif defined(OS_MACOSX) |
| 190 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 191 | #endif |
| 192 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 193 | #if BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 194 | #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 195 | #include "content/renderer/pepper/pepper_plugin_registry.h" |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 196 | #endif |
| 197 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 198 | using blink::WebAXObject; |
| 199 | using blink::WebApplicationCacheHost; |
| 200 | using blink::WebApplicationCacheHostClient; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 201 | using blink::WebConsoleMessage; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 202 | using blink::WebData; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 203 | using blink::WebDocument; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 204 | using blink::WebDragOperation; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 205 | using blink::WebElement; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 206 | using blink::WebFileChooserCompletion; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 207 | using blink::WebFormControlElement; |
| 208 | using blink::WebFormElement; |
| 209 | using blink::WebFrame; |
dglazkov | 0322349 | 2016-02-08 22:16:03 | [diff] [blame] | 210 | using blink::WebFrameContentDumper; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 211 | using blink::WebGestureEvent; |
| 212 | using blink::WebHistoryItem; |
| 213 | using blink::WebHTTPBody; |
dglazkov | 8d0c21dd | 2016-08-06 15:56:36 | [diff] [blame] | 214 | using blink::WebHitTestResult; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 215 | using blink::WebImage; |
| 216 | using blink::WebInputElement; |
| 217 | using blink::WebInputEvent; |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 218 | using blink::WebLocalFrame; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 219 | using blink::WebMouseEvent; |
| 220 | using blink::WebNavigationPolicy; |
| 221 | using blink::WebNavigationType; |
| 222 | using blink::WebNode; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 223 | using blink::WebPluginAction; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 224 | using blink::WebPoint; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 225 | using blink::WebRect; |
| 226 | using blink::WebReferrerPolicy; |
Daniel Cheng | d5e56ff | 2017-06-24 07:44:02 | [diff] [blame] | 227 | using blink::WebSandboxFlags; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 228 | using blink::WebScriptSource; |
| 229 | using blink::WebSearchableFormData; |
| 230 | using blink::WebSecurityOrigin; |
| 231 | using blink::WebSecurityPolicy; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 232 | using blink::WebSettings; |
| 233 | using blink::WebSize; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 234 | using blink::WebString; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 235 | using blink::WebTextDirection; |
| 236 | using blink::WebTouchEvent; |
| 237 | using blink::WebURL; |
| 238 | using blink::WebURLError; |
| 239 | using blink::WebURLRequest; |
| 240 | using blink::WebURLResponse; |
| 241 | using blink::WebUserGestureIndicator; |
| 242 | using blink::WebVector; |
| 243 | using blink::WebView; |
| 244 | using blink::WebWidget; |
| 245 | using blink::WebWindowFeatures; |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 246 | using blink::WebRuntimeFeatures; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 247 | using base::TimeDelta; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 248 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 249 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 250 | namespace content { |
| 251 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 252 | //----------------------------------------------------------------------------- |
| 253 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 254 | typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap; |
jbroman | 8319b23 | 2017-03-08 22:53:29 | [diff] [blame] | 255 | static base::LazyInstance<ViewMap>::Leaky g_view_map = |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 256 | LAZY_INSTANCE_INITIALIZER; |
scottmg | 5e65e3a | 2017-03-08 08:48:46 | [diff] [blame] | 257 | typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap; |
jbroman | 8319b23 | 2017-03-08 22:53:29 | [diff] [blame] | 258 | static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map = |
| 259 | LAZY_INSTANCE_INITIALIZER; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 260 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 261 | // Time, in seconds, we delay before sending content state changes (such as form |
| 262 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 263 | // spamming the browser. |
| 264 | // To avoid having tab/session restore require sending a message to get the |
| 265 | // current content state during tab closing we use a shorter timeout for the |
| 266 | // foreground renderer. This means there is a small window of time from which |
| 267 | // content state is modified and not sent to session restore, but this is |
| 268 | // better than having to wake up all renderers during shutdown. |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 269 | const int kDelaySecondsForContentStateSyncHidden = 5; |
| 270 | const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 271 | |
dcheng | 35d31c11 | 2015-07-22 00:17:36 | [diff] [blame] | 272 | static RenderViewImpl* (*g_create_render_view_impl)( |
| 273 | CompositorDependencies* compositor_deps, |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 274 | const mojom::CreateViewParams&) = nullptr; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 275 | |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 276 | // static |
[email protected] | e507045d | 2013-07-24 15:23:44 | [diff] [blame] | 277 | Referrer RenderViewImpl::GetReferrerFromRequest( |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 278 | WebFrame* frame, |
| 279 | const WebURLRequest& request) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 280 | return Referrer(blink::WebStringToGURL( |
| 281 | request.HttpHeaderField(WebString::FromUTF8("Referer"))), |
| 282 | request.GetReferrerPolicy()); |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 283 | } |
| 284 | |
[email protected] | c6bc2033 | 2014-02-28 18:30:39 | [diff] [blame] | 285 | // static |
[email protected] | 65920f33 | 2014-03-04 21:14:18 | [diff] [blame] | 286 | WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition( |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 287 | WebNavigationPolicy policy) { |
| 288 | switch (policy) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 289 | case blink::kWebNavigationPolicyIgnore: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 290 | return WindowOpenDisposition::IGNORE_ACTION; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 291 | case blink::kWebNavigationPolicyDownload: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 292 | return WindowOpenDisposition::SAVE_TO_DISK; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 293 | case blink::kWebNavigationPolicyCurrentTab: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 294 | return WindowOpenDisposition::CURRENT_TAB; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 295 | case blink::kWebNavigationPolicyNewBackgroundTab: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 296 | return WindowOpenDisposition::NEW_BACKGROUND_TAB; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 297 | case blink::kWebNavigationPolicyNewForegroundTab: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 298 | return WindowOpenDisposition::NEW_FOREGROUND_TAB; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 299 | case blink::kWebNavigationPolicyNewWindow: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 300 | return WindowOpenDisposition::NEW_WINDOW; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 301 | case blink::kWebNavigationPolicyNewPopup: |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 302 | return WindowOpenDisposition::NEW_POPUP; |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 303 | default: |
| 304 | NOTREACHED() << "Unexpected WebNavigationPolicy"; |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 305 | return WindowOpenDisposition::IGNORE_ACTION; |
[email protected] | 48861e2 | 2013-01-09 00:27:32 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 309 | /////////////////////////////////////////////////////////////////////////////// |
| 310 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 311 | namespace { |
| 312 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 313 | typedef void (*SetFontFamilyWrapper)(blink::WebSettings*, |
| 314 | const base::string16&, |
| 315 | UScriptCode); |
| 316 | |
| 317 | void SetStandardFontFamilyWrapper(WebSettings* settings, |
| 318 | const base::string16& font, |
| 319 | UScriptCode script) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 320 | settings->SetStandardFontFamily(WebString::FromUTF16(font), script); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | void SetFixedFontFamilyWrapper(WebSettings* settings, |
| 324 | const base::string16& font, |
| 325 | UScriptCode script) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 326 | settings->SetFixedFontFamily(WebString::FromUTF16(font), script); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | void SetSerifFontFamilyWrapper(WebSettings* settings, |
| 330 | const base::string16& font, |
| 331 | UScriptCode script) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 332 | settings->SetSerifFontFamily(WebString::FromUTF16(font), script); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | void SetSansSerifFontFamilyWrapper(WebSettings* settings, |
| 336 | const base::string16& font, |
| 337 | UScriptCode script) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 338 | settings->SetSansSerifFontFamily(WebString::FromUTF16(font), script); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | void SetCursiveFontFamilyWrapper(WebSettings* settings, |
| 342 | const base::string16& font, |
| 343 | UScriptCode script) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 344 | settings->SetCursiveFontFamily(WebString::FromUTF16(font), script); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | void SetFantasyFontFamilyWrapper(WebSettings* settings, |
| 348 | const base::string16& font, |
| 349 | UScriptCode script) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 350 | settings->SetFantasyFontFamily(WebString::FromUTF16(font), script); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | void SetPictographFontFamilyWrapper(WebSettings* settings, |
| 354 | const base::string16& font, |
| 355 | UScriptCode script) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 356 | settings->SetPictographFontFamily(WebString::FromUTF16(font), script); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | // If |scriptCode| is a member of a family of "similar" script codes, returns |
| 360 | // the script code in that family that is used by WebKit for font selection |
| 361 | // purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are |
| 362 | // considered equivalent for the purposes of font selection. WebKit uses the |
| 363 | // script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is |
| 364 | // USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit |
| 365 | // uses different scripts than the ones in Chrome pref names because the version |
| 366 | // of ICU included on certain ports does not have some of the newer scripts. If |
| 367 | // |scriptCode| is not a member of such a family, returns |scriptCode|. |
| 368 | UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) { |
| 369 | switch (scriptCode) { |
| 370 | case USCRIPT_HIRAGANA: |
| 371 | case USCRIPT_KATAKANA: |
| 372 | case USCRIPT_JAPANESE: |
| 373 | return USCRIPT_KATAKANA_OR_HIRAGANA; |
| 374 | case USCRIPT_KOREAN: |
| 375 | return USCRIPT_HANGUL; |
| 376 | default: |
| 377 | return scriptCode; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | void ApplyFontsFromMap(const ScriptFontFamilyMap& map, |
| 382 | SetFontFamilyWrapper setter, |
| 383 | WebSettings* settings) { |
| 384 | for (ScriptFontFamilyMap::const_iterator it = map.begin(); it != map.end(); |
| 385 | ++it) { |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 386 | int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str()); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 387 | if (script >= 0 && script < USCRIPT_CODE_LIMIT) { |
| 388 | UScriptCode code = static_cast<UScriptCode>(script); |
| 389 | (*setter)(settings, it->second, GetScriptForWebSettings(code)); |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | |
wangxianzhu | 3bf39be5 | 2015-04-10 23:56:41 | [diff] [blame] | 394 | void ApplyBlinkSettings(const base::CommandLine& command_line, |
| 395 | WebSettings* settings) { |
| 396 | if (!command_line.HasSwitch(switches::kBlinkSettings)) |
| 397 | return; |
| 398 | |
brettw | 26dab8f0 | 2015-08-08 00:28:47 | [diff] [blame] | 399 | std::vector<std::string> blink_settings = base::SplitString( |
| 400 | command_line.GetSwitchValueASCII(switches::kBlinkSettings), |
| 401 | ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
wangxianzhu | 3bf39be5 | 2015-04-10 23:56:41 | [diff] [blame] | 402 | for (const std::string& setting : blink_settings) { |
| 403 | size_t pos = setting.find('='); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 404 | settings->SetFromStrings( |
| 405 | blink::WebString::FromLatin1(setting.substr(0, pos)), |
| 406 | blink::WebString::FromLatin1( |
wangxianzhu | 3bf39be5 | 2015-04-10 23:56:41 | [diff] [blame] | 407 | pos == std::string::npos ? "" : setting.substr(pos + 1))); |
| 408 | } |
| 409 | } |
| 410 | |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 411 | content::mojom::WindowContainerType WindowFeaturesToContainerType( |
scottmg | 05324cb | 2017-02-09 23:46:04 | [diff] [blame] | 412 | const blink::WebWindowFeatures& window_features) { |
japhet | bfc4789 | 2017-06-02 23:01:19 | [diff] [blame] | 413 | if (window_features.background) { |
| 414 | if (window_features.persistent) |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 415 | return content::mojom::WindowContainerType::PERSISTENT; |
scottmg | 05324cb | 2017-02-09 23:46:04 | [diff] [blame] | 416 | else |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 417 | return content::mojom::WindowContainerType::BACKGROUND; |
scottmg | 05324cb | 2017-02-09 23:46:04 | [diff] [blame] | 418 | } else { |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 419 | return content::mojom::WindowContainerType::NORMAL; |
scottmg | 05324cb | 2017-02-09 23:46:04 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 423 | } // namespace |
| 424 | |
Hajime Hoshi | abb3c8f | 2017-12-04 18:41:39 | [diff] [blame] | 425 | RenderViewImpl::RenderViewImpl( |
| 426 | CompositorDependencies* compositor_deps, |
| 427 | const mojom::CreateViewParams& params, |
| 428 | scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 429 | : RenderWidget(params.main_frame_widget_routing_id, |
nick | 8331f8ad | 2016-11-15 20:42:45 | [diff] [blame] | 430 | compositor_deps, |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 431 | blink::kWebPopupTypeNone, |
Scott Violet | ae08f33 | 2018-07-27 17:37:23 | [diff] [blame] | 432 | params.visual_properties.screen_info, |
danakj | 73dd303 | 2018-07-28 17:49:53 | [diff] [blame^] | 433 | params.visual_properties.display_mode, |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 434 | params.swapped_out, |
| 435 | params.hidden, |
Hajime Hoshi | abb3c8f | 2017-12-04 18:41:39 | [diff] [blame] | 436 | params.never_visible, |
| 437 | task_runner), |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 438 | routing_id_(params.view_id), |
danakj | 73dd303 | 2018-07-28 17:49:53 | [diff] [blame^] | 439 | renderer_wide_named_frame_lookup_( |
| 440 | params.renderer_wide_named_frame_lookup), |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 441 | webkit_preferences_(params.web_preferences), |
changwan | d659e20 | 2016-06-13 02:39:12 | [diff] [blame] | 442 | session_storage_namespace_id_(params.session_storage_namespace_id), |
wjmaclean | 1d97062 | 2017-01-21 22:28:24 | [diff] [blame] | 443 | weak_ptr_factory_(this) { |
avi | 40b5be7a | 2016-03-03 21:13:44 | [diff] [blame] | 444 | GetWidget()->set_owner_delegate(this); |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 445 | RenderThread::Get()->AddRoute(routing_id_, this); |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 446 | } |
| 447 | |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 448 | void RenderViewImpl::Initialize( |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 449 | mojom::CreateViewParamsPtr params, |
danakj | df1ceb7 | 2018-07-18 20:02:25 | [diff] [blame] | 450 | RenderWidget::ShowCallback show_callback, |
Hajime Hoshi | f3437441 | 2018-03-05 14:32:54 | [diff] [blame] | 451 | scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 452 | bool has_show_callback = !!show_callback; |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 453 | #if defined(OS_ANDROID) |
| 454 | // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated |
| 455 | // HandleNavigation codepath. |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 456 | was_created_by_renderer_ = has_show_callback; |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 457 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 458 | |
Lukasz Anforowicz | af2f3357 | 2018-01-17 14:05:08 | [diff] [blame] | 459 | WebFrame* opener_frame = |
| 460 | RenderFrameImpl::ResolveOpener(params->opener_frame_route_id); |
| 461 | |
danakj | 9a8a9cf | 2018-07-17 23:52:12 | [diff] [blame] | 462 | // Pass WidgetClient(), not |this|, as the WebWidgetClient. The method may |
| 463 | // be overridden in layout tests to inject a test-only WebWidgetClient. |
Lukasz Anforowicz | af2f3357 | 2018-01-17 14:05:08 | [diff] [blame] | 464 | webview_ = |
danakj | 9a8a9cf | 2018-07-17 23:52:12 | [diff] [blame] | 465 | WebView::Create(this, WidgetClient(), |
Lukasz Anforowicz | af2f3357 | 2018-01-17 14:05:08 | [diff] [blame] | 466 | is_hidden() ? blink::mojom::PageVisibilityState::kHidden |
| 467 | : blink::mojom::PageVisibilityState::kVisible, |
| 468 | opener_frame ? opener_frame->View() : nullptr); |
Scott Violet | ae08f33 | 2018-07-27 17:37:23 | [diff] [blame] | 469 | RenderWidget::Init(std::move(show_callback), webview_->GetWidget()); |
[email protected] | 11fee233 | 2011-03-29 20:36:35 | [diff] [blame] | 470 | |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 471 | g_view_map.Get().insert(std::make_pair(webview(), this)); |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 472 | g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this)); |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 473 | |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 474 | const base::CommandLine& command_line = |
| 475 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 476 | |
[email protected] | 27c521a | 2013-05-29 20:44:32 | [diff] [blame] | 477 | if (command_line.HasSwitch(switches::kStatsCollectionController)) |
| 478 | stats_collection_observer_.reset(new StatsCollectionObserver(this)); |
| 479 | |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 480 | webview()->SetDisplayMode(GetWidget()->display_mode()); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 481 | webview()->GetSettings()->SetThreadedScrollingEnabled( |
dcheng | 0ff94cfc | 2016-03-15 21:50:51 | [diff] [blame] | 482 | !command_line.HasSwitch(switches::kDisableThreadedScrolling)); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 483 | webview()->SetShowFPSCounter( |
dcheng | 0ff94cfc | 2016-03-15 21:50:51 | [diff] [blame] | 484 | command_line.HasSwitch(cc::switches::kShowFPSCounter)); |
| 485 | |
danakj | 39f6812 | 2018-07-16 20:11:46 | [diff] [blame] | 486 | ApplyWebPreferencesInternal(webkit_preferences_, webview()); |
dcheng | 0ff94cfc | 2016-03-15 21:50:51 | [diff] [blame] | 487 | |
| 488 | if (switches::IsTouchDragDropEnabled()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 489 | webview()->GetSettings()->SetTouchDragDropEnabled(true); |
dcheng | 0ff94cfc | 2016-03-15 21:50:51 | [diff] [blame] | 490 | |
| 491 | WebSettings::SelectionStrategyType selection_strategy = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 492 | WebSettings::SelectionStrategyType::kCharacter; |
dcheng | 0ff94cfc | 2016-03-15 21:50:51 | [diff] [blame] | 493 | const std::string selection_strategy_str = |
Gyuyoung Kim | 63abad2 | 2018-06-15 03:16:55 | [diff] [blame] | 494 | command_line.GetSwitchValueASCII(switches::kTouchTextSelectionStrategy); |
dcheng | 0ff94cfc | 2016-03-15 21:50:51 | [diff] [blame] | 495 | if (selection_strategy_str == "direction") |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 496 | selection_strategy = WebSettings::SelectionStrategyType::kDirection; |
| 497 | webview()->GetSettings()->SetSelectionStrategy(selection_strategy); |
dcheng | 0ff94cfc | 2016-03-15 21:50:51 | [diff] [blame] | 498 | |
Gyuyoung Kim | 63abad2 | 2018-06-15 03:16:55 | [diff] [blame] | 499 | std::string passive_listeners_default = |
dtapuska | f65650b | 2016-05-13 17:21:34 | [diff] [blame] | 500 | command_line.GetSwitchValueASCII(switches::kPassiveListenersDefault); |
Gyuyoung Kim | 63abad2 | 2018-06-15 03:16:55 | [diff] [blame] | 501 | if (!passive_listeners_default.empty()) { |
dtapuska | f65650b | 2016-05-13 17:21:34 | [diff] [blame] | 502 | WebSettings::PassiveEventListenerDefault passiveDefault = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 503 | WebSettings::PassiveEventListenerDefault::kFalse; |
Gyuyoung Kim | 63abad2 | 2018-06-15 03:16:55 | [diff] [blame] | 504 | if (passive_listeners_default == "true") |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 505 | passiveDefault = WebSettings::PassiveEventListenerDefault::kTrue; |
Gyuyoung Kim | 63abad2 | 2018-06-15 03:16:55 | [diff] [blame] | 506 | else if (passive_listeners_default == "forcealltrue") |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 507 | passiveDefault = WebSettings::PassiveEventListenerDefault::kForceAllTrue; |
| 508 | webview()->GetSettings()->SetPassiveEventListenerDefault(passiveDefault); |
dtapuska | f65650b | 2016-05-13 17:21:34 | [diff] [blame] | 509 | } |
| 510 | |
Gyuyoung Kim | 63abad2 | 2018-06-15 03:16:55 | [diff] [blame] | 511 | std::string fmp_network_quiet_timeout = |
| 512 | command_line.GetSwitchValueASCII(switches::kFMPNetworkQuietTimeout); |
| 513 | if (!fmp_network_quiet_timeout.empty()) { |
| 514 | double fmp_network_quiet_timeout_seconds = 0.0; |
| 515 | if (base::StringToDouble(fmp_network_quiet_timeout, |
| 516 | &fmp_network_quiet_timeout_seconds)) { |
| 517 | webview()->GetSettings()->SetFMPNetworkQuietTimeout( |
| 518 | fmp_network_quiet_timeout_seconds); |
| 519 | } |
| 520 | } |
| 521 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 522 | ApplyBlinkSettings(command_line, webview()->GetSettings()); |
dcheng | 0ff94cfc | 2016-03-15 21:50:51 | [diff] [blame] | 523 | |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 524 | if (params->main_frame_routing_id != MSG_ROUTING_NONE) { |
Ken Rockot | 26efbd6 | 2017-11-16 04:39:49 | [diff] [blame] | 525 | CHECK(params->main_frame_interface_provider.is_valid()); |
| 526 | service_manager::mojom::InterfaceProviderPtr main_frame_interface_provider( |
| 527 | std::move(params->main_frame_interface_provider)); |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 528 | main_render_frame_ = RenderFrameImpl::CreateMainFrame( |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 529 | this, params->main_frame_routing_id, |
Ken Rockot | 26efbd6 | 2017-11-16 04:39:49 | [diff] [blame] | 530 | std::move(main_frame_interface_provider), |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 531 | params->main_frame_widget_routing_id, params->hidden, |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 532 | GetWidget()->GetWebScreenInfo(), GetWidget()->compositor_deps(), |
| 533 | opener_frame, params->devtools_main_frame_token, |
| 534 | params->replicated_frame_state, params->has_committed_real_load); |
dcheng | c5ef1a5 | 2015-08-26 20:58:30 | [diff] [blame] | 535 | } |
| 536 | |
Daniel Cheng | d5e56ff | 2017-06-24 07:44:02 | [diff] [blame] | 537 | // TODO(dcheng): Shouldn't these be mutually exclusive at this point? See |
| 538 | // https://crbug.com/720116 where the browser is apparently sending both |
| 539 | // routing IDs... |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 540 | if (params->proxy_routing_id != MSG_ROUTING_NONE) { |
| 541 | CHECK(params->swapped_out); |
| 542 | RenderFrameProxy::CreateFrameProxy(params->proxy_routing_id, GetRoutingID(), |
nick | 3b5a21f | 2016-11-22 23:07:11 | [diff] [blame] | 543 | opener_frame, MSG_ROUTING_NONE, |
Dmitry Gozman | 8936121 | 2018-02-13 16:10:44 | [diff] [blame] | 544 | params->replicated_frame_state, |
| 545 | params->devtools_main_frame_token); |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 546 | } |
| 547 | |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 548 | if (main_render_frame_) |
| 549 | main_render_frame_->Initialize(); |
| 550 | |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 551 | // If this RenderView's creation was initiated by an opener page in this |
| 552 | // process, (e.g. window.open()), we won't be visible until we ask the opener, |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 553 | // via |show_callback|, to make us visible. Otherwise, we went through a |
| 554 | // browser-initiated creation, and Show() won't be called. In this case, no |
| 555 | // |show_callback| is given to inform that Show() won't be called. |
| 556 | if (!has_show_callback) |
| 557 | RenderWidget::set_did_show(); |
mfomitchev | 5ad034ec | 2015-04-24 21:57:27 | [diff] [blame] | 558 | |
[email protected] | c7c0d82 | 2014-04-16 20:19:49 | [diff] [blame] | 559 | // TODO(davidben): Move this state from Blink into content. |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 560 | if (params->window_was_created_with_opener) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 561 | webview()->SetOpenedByDOM(); |
[email protected] | c7c0d82 | 2014-04-16 20:19:49 | [diff] [blame] | 562 | |
dcheng | 0ff94cfc | 2016-03-15 21:50:51 | [diff] [blame] | 563 | UpdateWebViewWithDeviceScaleFactor(); |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 564 | OnSetRendererPrefs(params->renderer_preferences); |
Fady Samuel | ff5b6eb56 | 2018-05-01 16:16:08 | [diff] [blame] | 565 | OnSynchronizeVisualProperties(params->visual_properties); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 566 | RenderWidget::SetUpIdleUserDetector(); |
[email protected] | 1784b2f | 2011-11-24 10:53:48 | [diff] [blame] | 567 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 568 | GetContentClient()->renderer()->RenderViewCreated(this); |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 569 | page_zoom_level_ = 0; |
Hajime Hoshi | f3437441 | 2018-03-05 14:32:54 | [diff] [blame] | 570 | |
| 571 | nav_state_sync_timer_.SetTaskRunner(task_runner); |
| 572 | check_preferred_size_timer_.SetTaskRunner(std::move(task_runner)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 573 | } |
| 574 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 575 | RenderViewImpl::~RenderViewImpl() { |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 576 | DCHECK(!frame_widget_); |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 577 | RenderThread::Get()->RemoveRoute(routing_id_); |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 578 | |
[email protected] | 8ed1d3f | 2013-02-20 11:45:55 | [diff] [blame] | 579 | #if defined(OS_ANDROID) |
davve | 17e025e1 | 2016-05-23 15:30:20 | [diff] [blame] | 580 | // The date/time picker client is both a std::unique_ptr member of this class |
| 581 | // and a RenderViewObserver. Reset it to prevent double deletion. |
[email protected] | 8ed1d3f | 2013-02-20 11:45:55 | [diff] [blame] | 582 | date_time_picker_client_.reset(); |
| 583 | #endif |
| 584 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 585 | #ifndef NDEBUG |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 586 | // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap. |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 587 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 588 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 589 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 058561b | 2012-12-03 06:48:22 | [diff] [blame] | 590 | RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer(); |
| 591 | for (RoutingIDViewMap::iterator it = routing_id_views->begin(); |
| 592 | it != routing_id_views->end(); ++it) |
| 593 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 594 | #endif |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 595 | |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 596 | for (auto& observer : observers_) |
| 597 | observer.RenderViewGone(); |
| 598 | for (auto& observer : observers_) |
| 599 | observer.OnDestruct(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | /*static*/ |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 603 | RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 604 | ViewMap* views = g_view_map.Pointer(); |
| 605 | ViewMap::iterator it = views->find(webview); |
| 606 | return it == views->end() ? NULL : it->second; |
| 607 | } |
| 608 | |
| 609 | /*static*/ |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 610 | RenderView* RenderView::FromWebView(blink::WebView* webview) { |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 611 | return RenderViewImpl::FromWebView(webview); |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | /*static*/ |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 615 | RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) { |
[email protected] | 640e303c | 2012-12-05 01:36:07 | [diff] [blame] | 616 | RoutingIDViewMap* views = g_routing_id_view_map.Pointer(); |
| 617 | RoutingIDViewMap::iterator it = views->find(routing_id); |
| 618 | return it == views->end() ? NULL : it->second; |
| 619 | } |
| 620 | |
| 621 | /*static*/ |
| 622 | RenderView* RenderView::FromRoutingID(int routing_id) { |
| 623 | return RenderViewImpl::FromRoutingID(routing_id); |
| 624 | } |
| 625 | |
[email protected] | f3a9531 | 2014-06-12 16:46:58 | [diff] [blame] | 626 | /* static */ |
jochen | 9c7b8f24 | 2015-06-01 15:32:02 | [diff] [blame] | 627 | size_t RenderView::GetRenderViewCount() { |
[email protected] | f3a9531 | 2014-06-12 16:46:58 | [diff] [blame] | 628 | return g_view_map.Get().size(); |
| 629 | } |
| 630 | |
[email protected] | 640e303c | 2012-12-05 01:36:07 | [diff] [blame] | 631 | /*static*/ |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 632 | void RenderView::ForEach(RenderViewVisitor* visitor) { |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 633 | ViewMap* views = g_view_map.Pointer(); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 634 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 635 | if (!visitor->Visit(it->second)) |
| 636 | return; |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | /*static*/ |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 641 | void RenderView::ApplyWebPreferences(const WebPreferences& prefs, |
| 642 | WebView* web_view) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 643 | WebSettings* settings = web_view->GetSettings(); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 644 | ApplyFontsFromMap(prefs.standard_font_family_map, |
| 645 | SetStandardFontFamilyWrapper, settings); |
| 646 | ApplyFontsFromMap(prefs.fixed_font_family_map, |
| 647 | SetFixedFontFamilyWrapper, settings); |
| 648 | ApplyFontsFromMap(prefs.serif_font_family_map, |
| 649 | SetSerifFontFamilyWrapper, settings); |
| 650 | ApplyFontsFromMap(prefs.sans_serif_font_family_map, |
| 651 | SetSansSerifFontFamilyWrapper, settings); |
| 652 | ApplyFontsFromMap(prefs.cursive_font_family_map, |
| 653 | SetCursiveFontFamilyWrapper, settings); |
| 654 | ApplyFontsFromMap(prefs.fantasy_font_family_map, |
| 655 | SetFantasyFontFamilyWrapper, settings); |
| 656 | ApplyFontsFromMap(prefs.pictograph_font_family_map, |
| 657 | SetPictographFontFamilyWrapper, settings); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 658 | settings->SetDefaultFontSize(prefs.default_font_size); |
| 659 | settings->SetDefaultFixedFontSize(prefs.default_fixed_font_size); |
| 660 | settings->SetMinimumFontSize(prefs.minimum_font_size); |
| 661 | settings->SetMinimumLogicalFontSize(prefs.minimum_logical_font_size); |
| 662 | settings->SetDefaultTextEncodingName( |
| 663 | WebString::FromASCII(prefs.default_encoding)); |
| 664 | settings->SetJavaScriptEnabled(prefs.javascript_enabled); |
| 665 | settings->SetWebSecurityEnabled(prefs.web_security_enabled); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 666 | settings->SetLoadsImagesAutomatically(prefs.loads_images_automatically); |
| 667 | settings->SetImagesEnabled(prefs.images_enabled); |
| 668 | settings->SetPluginsEnabled(prefs.plugins_enabled); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 669 | settings->SetDOMPasteAllowed(prefs.dom_paste_enabled); |
| 670 | settings->SetTextAreasAreResizable(prefs.text_areas_are_resizable); |
| 671 | settings->SetAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows); |
| 672 | settings->SetDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled); |
| 673 | settings->SetJavaScriptCanAccessClipboard( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 674 | prefs.javascript_can_access_clipboard); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 675 | WebRuntimeFeatures::EnableXSLT(prefs.xslt_enabled); |
| 676 | settings->SetXSSAuditorEnabled(prefs.xss_auditor_enabled); |
| 677 | settings->SetDNSPrefetchingEnabled(prefs.dns_prefetching_enabled); |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 678 | blink::WebNetworkStateNotifier::SetSaveDataEnabled(prefs.data_saver_enabled); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 679 | settings->SetLocalStorageEnabled(prefs.local_storage_enabled); |
| 680 | settings->SetSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled); |
| 681 | WebRuntimeFeatures::EnableDatabase(prefs.databases_enabled); |
| 682 | settings->SetOfflineWebApplicationCacheEnabled( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 683 | prefs.application_cache_enabled); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 684 | settings->SetHistoryEntryRequiresUserGesture( |
japhet | 5018fe6 | 2016-09-14 19:14:04 | [diff] [blame] | 685 | prefs.history_entry_requires_user_gesture); |
Chris Palmer | 917bc05 | 2018-03-14 19:28:31 | [diff] [blame] | 686 | settings->SetShouldThrottlePushState(!prefs.disable_pushstate_throttle); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 687 | settings->SetHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled); |
| 688 | settings->SetCookieEnabled(prefs.cookie_enabled); |
| 689 | settings->SetNavigateOnDragDrop(prefs.navigate_on_drag_drop); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 690 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 691 | // By default, allow_universal_access_from_file_urls is set to false and thus |
| 692 | // we mitigate attacks from local HTML files by not granting file:// URLs |
| 693 | // universal access. Only test shell will enable this. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 694 | settings->SetAllowUniversalAccessFromFileURLs( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 695 | prefs.allow_universal_access_from_file_urls); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 696 | settings->SetAllowFileAccessFromFileURLs( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 697 | prefs.allow_file_access_from_file_urls); |
| 698 | |
Zhenyao Mo | a3fda997 | 2017-09-16 01:34:40 | [diff] [blame] | 699 | settings->SetWebGL1Enabled(prefs.webgl1_enabled); |
| 700 | settings->SetWebGL2Enabled(prefs.webgl2_enabled); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 701 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 702 | // Enable WebGL errors to the JS console if requested. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 703 | settings->SetWebGLErrorsToConsoleEnabled( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 704 | prefs.webgl_errors_to_console_enabled); |
| 705 | |
| 706 | // Uses the mock theme engine for scrollbars. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 707 | settings->SetMockScrollbarsEnabled(prefs.mock_scrollbars_enabled); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 708 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 709 | settings->SetHideScrollbars(prefs.hide_scrollbars); |
eseckler | 61ff914 | 2016-09-23 22:57:59 | [diff] [blame] | 710 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 711 | // Enable gpu-accelerated 2d canvas if requested on the command line. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 712 | WebRuntimeFeatures::EnableAccelerated2dCanvas( |
junov | 524668f2 | 2016-08-08 20:16:52 | [diff] [blame] | 713 | prefs.accelerated_2d_canvas_enabled); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 714 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 715 | settings->SetMinimumAccelerated2dCanvasSize( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 716 | prefs.minimum_accelerated_2d_canvas_size); |
| 717 | |
| 718 | // Disable antialiasing for 2d canvas if requested on the command line. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 719 | settings->SetAntialiased2dCanvasEnabled( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 720 | !prefs.antialiased_2d_canvas_disabled); |
| 721 | |
zakerinasab | 20ebca0 | 2016-09-27 14:22:34 | [diff] [blame] | 722 | // Disable antialiasing of clips for 2d canvas if requested on the command |
robertphillips | e25137b | 2014-10-20 13:44:34 | [diff] [blame] | 723 | // line. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 724 | settings->SetAntialiasedClips2dCanvasEnabled( |
robertphillips | e25137b | 2014-10-20 13:44:34 | [diff] [blame] | 725 | prefs.antialiased_clips_2d_canvas_enabled); |
| 726 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 727 | // Set MSAA sample count for 2d canvas if requested on the command line (or |
| 728 | // default value if not). |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 729 | settings->SetAccelerated2dCanvasMSAASampleCount( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 730 | prefs.accelerated_2d_canvas_msaa_sample_count); |
| 731 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 732 | // Tabs to link is not part of the settings. WebCore calls |
| 733 | // ChromeClient::tabsToLinks which is part of the glue code. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 734 | web_view->SetTabsToLinks(prefs.tabs_to_links); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 735 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 736 | settings->SetAllowRunningOfInsecureContent( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 737 | prefs.allow_running_insecure_content); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 738 | settings->SetDisableReadingFromCanvas(prefs.disable_reading_from_canvas); |
| 739 | settings->SetStrictMixedContentChecking(prefs.strict_mixed_content_checking); |
mkwst | 2384c822 | 2015-07-30 07:26:47 | [diff] [blame] | 740 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 741 | settings->SetStrictlyBlockBlockableMixedContent( |
mkwst | 2384c822 | 2015-07-30 07:26:47 | [diff] [blame] | 742 | prefs.strictly_block_blockable_mixed_content); |
| 743 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 744 | settings->SetStrictMixedContentCheckingForPlugin( |
mkwst | 0d233e5 | 2015-08-10 09:33:14 | [diff] [blame] | 745 | prefs.block_mixed_plugin_content); |
| 746 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 747 | settings->SetStrictPowerfulFeatureRestrictions( |
mkwst | 673a452f | 2015-01-10 14:41:50 | [diff] [blame] | 748 | prefs.strict_powerful_feature_restrictions); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 749 | settings->SetAllowGeolocationOnInsecureOrigins( |
jww | 9d4ca2d | 2016-01-19 20:58:59 | [diff] [blame] | 750 | prefs.allow_geolocation_on_insecure_origins); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 751 | settings->SetPasswordEchoEnabled(prefs.password_echo_enabled); |
| 752 | settings->SetShouldPrintBackgrounds(prefs.should_print_backgrounds); |
| 753 | settings->SetShouldClearDocumentBackground( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 754 | prefs.should_clear_document_background); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 755 | settings->SetEnableScrollAnimator(prefs.enable_scroll_animator); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 756 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 757 | WebRuntimeFeatures::EnableTouchEventFeatureDetection( |
sunyunjia | fa6a8afc | 2016-12-09 04:25:47 | [diff] [blame] | 758 | prefs.touch_event_feature_detection_enabled); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 759 | settings->SetMaxTouchPoints(prefs.pointer_events_max_touch_points); |
| 760 | settings->SetAvailablePointerTypes(prefs.available_pointer_types); |
| 761 | settings->SetPrimaryPointerType( |
nzolghadr | c0d1663c | 2015-11-26 21:15:24 | [diff] [blame] | 762 | static_cast<blink::PointerType>(prefs.primary_pointer_type)); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 763 | settings->SetAvailableHoverTypes(prefs.available_hover_types); |
| 764 | settings->SetPrimaryHoverType( |
nzolghadr | c0d1663c | 2015-11-26 21:15:24 | [diff] [blame] | 765 | static_cast<blink::HoverType>(prefs.primary_hover_type)); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 766 | settings->SetEnableTouchAdjustment(prefs.touch_adjustment_enabled); |
Dave Tapuska | a59fdb6 | 2017-08-23 16:28:27 | [diff] [blame] | 767 | settings->SetBarrelButtonForDragEnabled(prefs.barrel_button_for_drag_enabled); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 768 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 769 | settings->SetShouldRespectImageOrientation( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 770 | prefs.should_respect_image_orientation); |
| 771 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 772 | settings->SetEditingBehavior( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 773 | static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior)); |
| 774 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 775 | settings->SetSupportsMultipleWindows(prefs.supports_multiple_windows); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 776 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 777 | settings->SetMainFrameClipsContent(!prefs.record_whole_document); |
khushalsagar | 2da2b23 | 2016-03-23 22:11:35 | [diff] [blame] | 778 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 779 | settings->SetSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 780 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 781 | settings->SetSpatialNavigationEnabled(prefs.spatial_navigation_enabled); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 782 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 783 | settings->SetSelectionIncludesAltImageText(true); |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 784 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 785 | settings->SetV8CacheOptions( |
[email protected] | 35103c0 | 2014-08-12 15:08:47 | [diff] [blame] | 786 | static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options)); |
| 787 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 788 | settings->SetImageAnimationPolicy( |
je_julie.kim | 7fbb5a1a | 2015-02-09 17:26:05 | [diff] [blame] | 789 | static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy)); |
| 790 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 791 | settings->SetPresentationRequiresUserGesture( |
zqzhang | 1215ad42 | 2016-02-10 13:27:22 | [diff] [blame] | 792 | prefs.user_gesture_required_for_presentation); |
| 793 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 794 | settings->SetTextTrackMarginPercentage(prefs.text_track_margin_percentage); |
halliwell | 4002be4 | 2016-03-18 18:33:40 | [diff] [blame] | 795 | |
dcheng | 5ae8ca36 | 2015-02-05 04:03:47 | [diff] [blame] | 796 | // Needs to happen before setIgnoreVIewportTagScaleLimits below. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 797 | web_view->SetDefaultPageScaleLimits(prefs.default_minimum_page_scale_factor, |
| 798 | prefs.default_maximum_page_scale_factor); |
dcheng | 5ae8ca36 | 2015-02-05 04:03:47 | [diff] [blame] | 799 | |
Nate Chapin | 9638e710 | 2017-09-20 22:11:01 | [diff] [blame] | 800 | settings->SetSavePreviousDocumentResources( |
| 801 | static_cast<WebSettings::SavePreviousDocumentResources>( |
| 802 | prefs.save_previous_document_resources)); |
| 803 | |
Ahmed Fakhry | 4222145 | 2018-05-30 01:18:39 | [diff] [blame] | 804 | settings->SetTextAutosizingEnabled(prefs.text_autosizing_enabled); |
| 805 | settings->SetDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled); |
| 806 | |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 807 | #if defined(OS_ANDROID) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 808 | settings->SetAllowCustomScrollbarInMainFrame(false); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 809 | settings->SetAccessibilityFontScaleFactor(prefs.font_scale_factor); |
| 810 | settings->SetDeviceScaleAdjustment(prefs.device_scale_adjustment); |
| 811 | settings->SetFullscreenSupported(prefs.fullscreen_supported); |
| 812 | web_view->SetIgnoreViewportTagScaleLimits(prefs.force_enable_zoom); |
| 813 | settings->SetAutoZoomFocusedNodeToLegibleScale(true); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 814 | settings->SetMediaPlaybackGestureWhitelistScope( |
| 815 | blink::WebString::FromUTF8(prefs.media_playback_gesture_whitelist_scope)); |
| 816 | settings->SetDefaultVideoPosterURL( |
| 817 | WebString::FromASCII(prefs.default_video_poster_url.spec())); |
| 818 | settings->SetSupportDeprecatedTargetDensityDPI( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 819 | prefs.support_deprecated_target_density_dpi); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 820 | settings->SetUseLegacyBackgroundSizeShorthandBehavior( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 821 | prefs.use_legacy_background_size_shorthand_behavior); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 822 | settings->SetWideViewportQuirkEnabled(prefs.wide_viewport_quirk); |
| 823 | settings->SetUseWideViewport(prefs.use_wide_viewport); |
| 824 | settings->SetForceZeroLayoutHeight(prefs.force_zero_layout_height); |
| 825 | settings->SetViewportMetaLayoutSizeQuirk( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 826 | prefs.viewport_meta_layout_size_quirk); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 827 | settings->SetViewportMetaMergeContentQuirk( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 828 | prefs.viewport_meta_merge_content_quirk); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 829 | settings->SetViewportMetaNonUserScalableQuirk( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 830 | prefs.viewport_meta_non_user_scalable_quirk); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 831 | settings->SetViewportMetaZeroValuesQuirk( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 832 | prefs.viewport_meta_zero_values_quirk); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 833 | settings->SetClobberUserAgentInitialScaleQuirk( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 834 | prefs.clobber_user_agent_initial_scale_quirk); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 835 | settings->SetIgnoreMainFrameOverflowHiddenQuirk( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 836 | prefs.ignore_main_frame_overflow_hidden_quirk); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 837 | settings->SetReportScreenSizeInPhysicalPixelsQuirk( |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 838 | prefs.report_screen_size_in_physical_pixels_quirk); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 839 | settings->SetShouldReuseGlobalForUnownedMainFrame( |
tzik | 30eb52c | 2018-03-27 06:55:18 | [diff] [blame] | 840 | prefs.reuse_global_for_unowned_main_frame); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 841 | settings->SetPreferHiddenVolumeControls(true); |
| 842 | settings->SetSpellCheckEnabledByDefault(prefs.spellcheck_enabled_by_default); |
dalecurtis | cd97125 | 2016-09-21 16:09:00 | [diff] [blame] | 843 | |
aelias | e678aa4 | 2017-04-14 22:41:04 | [diff] [blame] | 844 | // Force preload=none and disable autoplay on older Android |
dalecurtis | cd97125 | 2016-09-21 16:09:00 | [diff] [blame] | 845 | // platforms because their media pipelines are not stable enough to handle |
| 846 | // concurrent elements. See http://crbug.com/612909, http://crbug.com/622826. |
aelias | e678aa4 | 2017-04-14 22:41:04 | [diff] [blame] | 847 | const bool is_jelly_bean = |
dalecurtis | cd97125 | 2016-09-21 16:09:00 | [diff] [blame] | 848 | base::android::BuildInfo::GetInstance()->sdk_int() <= |
aelias | e678aa4 | 2017-04-14 22:41:04 | [diff] [blame] | 849 | base::android::SDK_VERSION_JELLY_BEAN_MR2; |
| 850 | settings->SetForcePreloadNoneForMediaElements(is_jelly_bean); |
mlamouri | 1d266bf | 2016-12-05 17:42:36 | [diff] [blame] | 851 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 852 | WebRuntimeFeatures::EnableVideoFullscreenOrientationLock( |
mlamouri | 1d266bf | 2016-12-05 17:42:36 | [diff] [blame] | 853 | prefs.video_fullscreen_orientation_lock_enabled); |
johnme | 913ee5f | 2017-04-28 21:36:16 | [diff] [blame] | 854 | WebRuntimeFeatures::EnableVideoRotateToFullscreen( |
| 855 | prefs.video_rotate_to_fullscreen_enabled); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 856 | WebRuntimeFeatures::EnableVideoFullscreenDetection( |
zqzhang | 93e959d1 | 2017-03-16 13:10:20 | [diff] [blame] | 857 | prefs.video_fullscreen_detection_enabled); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 858 | settings->SetEmbeddedMediaExperienceEnabled( |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 859 | prefs.embedded_media_experience_enabled); |
Ian Vollick | eeca1d8 | 2018-02-07 02:43:42 | [diff] [blame] | 860 | settings->SetImmersiveModeEnabled(prefs.immersive_mode_enabled); |
khushalsagar | c5447db2 | 2017-08-22 17:53:01 | [diff] [blame] | 861 | settings->SetMediaDownloadInProductHelpEnabled( |
| 862 | prefs.enable_media_download_in_product_help); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 863 | settings->SetDoNotUpdateSelectionOnMutatingSelectionRange( |
changwan | e54ccdb9 | 2017-04-05 19:20:54 | [diff] [blame] | 864 | prefs.do_not_update_selection_on_mutating_selection_range); |
Noel Gordon | f311a84 | 2017-07-27 00:10:07 | [diff] [blame] | 865 | WebRuntimeFeatures::EnableCSSHexAlphaColor(prefs.css_hex_alpha_color_enabled); |
Tobias Sargeant | 416174f | 2017-09-01 01:18:09 | [diff] [blame] | 866 | WebRuntimeFeatures::EnableScrollTopLeftInterop( |
| 867 | prefs.scroll_top_left_interop_enabled); |
zqzhang | df72ed08 | 2016-12-08 16:07:55 | [diff] [blame] | 868 | #endif // defined(OS_ANDROID) |
liberato | 9e93489 | 2016-05-03 19:00:27 | [diff] [blame] | 869 | |
mlamouri | 55a0543c | 2017-05-11 10:34:07 | [diff] [blame] | 870 | switch (prefs.autoplay_policy) { |
| 871 | case AutoplayPolicy::kNoUserGestureRequired: |
mlamouri | 276a6f3 | 2017-05-12 09:24:28 | [diff] [blame] | 872 | settings->SetAutoplayPolicy( |
| 873 | WebSettings::AutoplayPolicy::kNoUserGestureRequired); |
mlamouri | 55a0543c | 2017-05-11 10:34:07 | [diff] [blame] | 874 | break; |
| 875 | case AutoplayPolicy::kUserGestureRequired: |
mlamouri | 276a6f3 | 2017-05-12 09:24:28 | [diff] [blame] | 876 | settings->SetAutoplayPolicy( |
| 877 | WebSettings::AutoplayPolicy::kUserGestureRequired); |
mlamouri | 55a0543c | 2017-05-11 10:34:07 | [diff] [blame] | 878 | break; |
| 879 | case AutoplayPolicy::kUserGestureRequiredForCrossOrigin: |
mlamouri | 276a6f3 | 2017-05-12 09:24:28 | [diff] [blame] | 880 | settings->SetAutoplayPolicy( |
| 881 | WebSettings::AutoplayPolicy::kUserGestureRequiredForCrossOrigin); |
mlamouri | 55a0543c | 2017-05-11 10:34:07 | [diff] [blame] | 882 | break; |
mlamouri | 431bb4e | 2017-06-06 08:54:24 | [diff] [blame] | 883 | case AutoplayPolicy::kDocumentUserActivationRequired: |
| 884 | settings->SetAutoplayPolicy( |
| 885 | WebSettings::AutoplayPolicy::kDocumentUserActivationRequired); |
| 886 | break; |
mlamouri | 55a0543c | 2017-05-11 10:34:07 | [diff] [blame] | 887 | } |
| 888 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 889 | settings->SetViewportEnabled(prefs.viewport_enabled); |
| 890 | settings->SetViewportMetaEnabled(prefs.viewport_meta_enabled); |
| 891 | settings->SetShrinksViewportContentToFit( |
| 892 | prefs.shrinks_viewport_contents_to_fit); |
| 893 | settings->SetViewportStyle( |
alokp | 5d56696 | 2016-04-19 00:54:16 | [diff] [blame] | 894 | static_cast<blink::WebViewportStyle>(prefs.viewport_style)); |
| 895 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 896 | settings->SetLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale); |
| 897 | settings->SetMainFrameResizesAreOrientationChanges( |
yoav | a1a508b4 | 2015-10-20 12:03:21 | [diff] [blame] | 898 | prefs.main_frame_resizes_are_orientation_changes); |
| 899 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 900 | settings->SetUseSolidColorScrollbars(prefs.use_solid_color_scrollbars); |
jinho.bang | 8f11ffa | 2014-12-04 06:03:03 | [diff] [blame] | 901 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 902 | settings->SetShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up); |
| 903 | settings->SetAlwaysShowContextMenuOnTouch( |
amaralp | 547e419 | 2016-06-03 19:17:35 | [diff] [blame] | 904 | prefs.always_show_context_menu_on_touch); |
Sandra Sun | c79fc93a | 2018-04-10 15:22:23 | [diff] [blame] | 905 | settings->SetSmoothScrollForFindEnabled(prefs.smooth_scroll_for_find_enabled); |
ccameron | 2fd70de7 | 2015-02-19 00:40:40 | [diff] [blame] | 906 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 907 | settings->SetHideDownloadUI(prefs.hide_download_ui); |
| 908 | WebRuntimeFeatures::EnableBackgroundVideoTrackOptimization( |
avayvod | 39c10240 | 2016-11-23 21:43:13 | [diff] [blame] | 909 | prefs.background_video_track_optimization_enabled); |
avayvod | 23275794 | 2017-04-29 04:12:34 | [diff] [blame] | 910 | WebRuntimeFeatures::EnableNewRemotePlaybackPipeline( |
| 911 | base::FeatureList::IsEnabled(media::kNewRemotePlaybackPipeline)); |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 912 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 913 | settings->SetPresentationReceiver(prefs.presentation_receiver); |
mlamouri | 57359d91 | 2016-11-29 20:11:50 | [diff] [blame] | 914 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 915 | settings->SetMediaControlsEnabled(prefs.media_controls_enabled); |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 916 | |
Tarun Bansal | 73d67f0 | 2018-01-17 05:56:25 | [diff] [blame] | 917 | settings->SetLowPriorityIframesThreshold( |
| 918 | static_cast<blink::WebEffectiveConnectionType>( |
| 919 | prefs.low_priority_iframes_threshold)); |
| 920 | |
Mounir Lamouri | 9c99a160 | 2018-07-05 15:01:44 | [diff] [blame] | 921 | settings->SetPictureInPictureEnabled( |
| 922 | prefs.picture_in_picture_enabled && |
| 923 | MediaFactory::VideoSurfaceLayerEnabled()); |
François Beaufort | 8c08979fc | 2018-03-05 13:06:31 | [diff] [blame] | 924 | |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 925 | settings->SetDataSaverHoldbackWebApi( |
| 926 | prefs.data_saver_holdback_web_api_enabled); |
| 927 | settings->SetDataSaverHoldbackMediaApi( |
| 928 | prefs.data_saver_holdback_media_api_enabled); |
| 929 | |
Scott Little | 878f7d670 | 2018-05-31 22:09:06 | [diff] [blame] | 930 | for (const auto& ect_distance_pair : |
| 931 | prefs.lazy_frame_loading_distance_thresholds_px) { |
| 932 | switch (ect_distance_pair.first) { |
| 933 | case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN: |
| 934 | settings->SetLazyFrameLoadingDistanceThresholdPxUnknown( |
| 935 | ect_distance_pair.second); |
| 936 | break; |
| 937 | case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE: |
| 938 | settings->SetLazyFrameLoadingDistanceThresholdPxOffline( |
| 939 | ect_distance_pair.second); |
| 940 | break; |
| 941 | case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G: |
| 942 | settings->SetLazyFrameLoadingDistanceThresholdPxSlow2G( |
| 943 | ect_distance_pair.second); |
| 944 | break; |
| 945 | case net::EFFECTIVE_CONNECTION_TYPE_2G: |
| 946 | settings->SetLazyFrameLoadingDistanceThresholdPx2G( |
| 947 | ect_distance_pair.second); |
| 948 | break; |
| 949 | case net::EFFECTIVE_CONNECTION_TYPE_3G: |
| 950 | settings->SetLazyFrameLoadingDistanceThresholdPx3G( |
| 951 | ect_distance_pair.second); |
| 952 | break; |
| 953 | case net::EFFECTIVE_CONNECTION_TYPE_4G: |
| 954 | settings->SetLazyFrameLoadingDistanceThresholdPx4G( |
| 955 | ect_distance_pair.second); |
| 956 | break; |
| 957 | default: |
| 958 | NOTREACHED(); |
| 959 | } |
| 960 | } |
| 961 | |
ccameron | 2fd70de7 | 2015-02-19 00:40:40 | [diff] [blame] | 962 | #if defined(OS_MACOSX) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 963 | settings->SetDoubleTapToZoomEnabled(true); |
| 964 | web_view->SetMaximumLegibleScale(prefs.default_maximum_page_scale_factor); |
ccameron | 2fd70de7 | 2015-02-19 00:40:40 | [diff] [blame] | 965 | #endif |
sunyunjia | 87f287b | 2016-09-09 00:38:13 | [diff] [blame] | 966 | |
| 967 | #if defined(OS_WIN) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 968 | WebRuntimeFeatures::EnableMiddleClickAutoscroll(true); |
sunyunjia | 87f287b | 2016-09-09 00:38:13 | [diff] [blame] | 969 | #endif |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | /*static*/ |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 973 | RenderViewImpl* RenderViewImpl::Create( |
| 974 | CompositorDependencies* compositor_deps, |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 975 | mojom::CreateViewParamsPtr params, |
danakj | df1ceb7 | 2018-07-18 20:02:25 | [diff] [blame] | 976 | RenderWidget::ShowCallback show_callback, |
Hajime Hoshi | abb3c8f | 2017-12-04 18:41:39 | [diff] [blame] | 977 | scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 978 | DCHECK(params->view_id != MSG_ROUTING_NONE); |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 979 | DCHECK(params->main_frame_widget_routing_id != MSG_ROUTING_NONE); |
Lei Zhang | 88f23ba | 2017-10-27 05:56:26 | [diff] [blame] | 980 | RenderViewImpl* render_view; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 981 | if (g_create_render_view_impl) |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 982 | render_view = g_create_render_view_impl(compositor_deps, *params); |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 983 | else |
Hajime Hoshi | abb3c8f | 2017-12-04 18:41:39 | [diff] [blame] | 984 | render_view = new RenderViewImpl(compositor_deps, *params, task_runner); |
[email protected] | 0287e76 | 2014-04-11 13:07:58 | [diff] [blame] | 985 | |
danakj | df1ceb7 | 2018-07-18 20:02:25 | [diff] [blame] | 986 | render_view->Initialize(std::move(params), std::move(show_callback), |
Hajime Hoshi | f3437441 | 2018-03-05 14:32:54 | [diff] [blame] | 987 | std::move(task_runner)); |
[email protected] | 07536691 | 2013-02-18 07:13:24 | [diff] [blame] | 988 | return render_view; |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | // static |
dcheng | 35d31c11 | 2015-07-22 00:17:36 | [diff] [blame] | 992 | void RenderViewImpl::InstallCreateHook(RenderViewImpl* ( |
| 993 | *create_render_view_impl)(CompositorDependencies* compositor_deps, |
rockot | 067ca55f | 2016-09-30 22:00:15 | [diff] [blame] | 994 | const mojom::CreateViewParams&)) { |
[email protected] | 8d41d761 | 2012-11-14 20:32:19 | [diff] [blame] | 995 | CHECK(!g_create_render_view_impl); |
| 996 | g_create_render_view_impl = create_render_view_impl; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 997 | } |
| 998 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 999 | void RenderViewImpl::AddObserver(RenderViewObserver* observer) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1000 | observers_.AddObserver(observer); |
| 1001 | } |
| 1002 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1003 | void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) { |
| 1004 | observer->RenderViewGone(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1005 | observers_.RemoveObserver(observer); |
| 1006 | } |
| 1007 | |
Peter Kasting | a4a3ed1 | 2018-01-31 04:07:59 | [diff] [blame] | 1008 | blink::WebView* RenderViewImpl::webview() { |
| 1009 | return webview_; |
| 1010 | } |
| 1011 | |
| 1012 | const blink::WebView* RenderViewImpl::webview() const { |
lfg | 4fa48da | 2016-05-09 18:25:13 | [diff] [blame] | 1013 | return webview_; |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 1014 | } |
| 1015 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1016 | // RenderWidgetOwnerDelegate ----------------------------------------- |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1017 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1018 | blink::WebWidget* RenderViewImpl::GetWebWidgetForWidget() const { |
| 1019 | return frame_widget_; |
| 1020 | } |
| 1021 | |
| 1022 | bool RenderViewImpl::RenderWidgetWillHandleMouseEventForWidget( |
avi | d7d6b2e | 2016-03-04 19:41:17 | [diff] [blame] | 1023 | const blink::WebMouseEvent& event) { |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1024 | // If the mouse is locked, only the current owner of the mouse lock can |
| 1025 | // process mouse events. |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1026 | return GetWidget()->mouse_lock_dispatcher()->WillHandleMouseEvent(event); |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1027 | } |
| 1028 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1029 | void RenderViewImpl::SetActiveForWidget(bool active) { |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 1030 | if (webview()) |
| 1031 | webview()->SetIsActive(active); |
| 1032 | } |
| 1033 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1034 | void RenderViewImpl::SetBackgroundOpaqueForWidget(bool opaque) { |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 1035 | if (!frame_widget_) |
| 1036 | return; |
| 1037 | |
| 1038 | if (opaque) { |
| 1039 | frame_widget_->ClearBaseBackgroundColorOverride(); |
| 1040 | frame_widget_->ClearBackgroundColorOverride(); |
| 1041 | } else { |
| 1042 | frame_widget_->SetBaseBackgroundColorOverride(SK_ColorTRANSPARENT); |
| 1043 | frame_widget_->SetBackgroundColorOverride(SK_ColorTRANSPARENT); |
| 1044 | } |
| 1045 | } |
| 1046 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1047 | bool RenderViewImpl::SupportsMultipleWindowsForWidget() { |
| 1048 | return webkit_preferences_.supports_multiple_windows; |
| 1049 | } |
| 1050 | |
| 1051 | void RenderViewImpl::DidHandleGestureEventForWidget( |
| 1052 | const WebGestureEvent& event) { |
| 1053 | for (auto& observer : observers_) |
| 1054 | observer.DidHandleGestureEvent(event); |
| 1055 | } |
| 1056 | |
| 1057 | void RenderViewImpl::OverrideCloseForWidget() { |
| 1058 | DCHECK(frame_widget_); |
| 1059 | frame_widget_->Close(); |
| 1060 | frame_widget_ = nullptr; |
| 1061 | } |
| 1062 | |
| 1063 | void RenderViewImpl::DidCloseWidget() { |
| 1064 | // The webview_ is already destroyed by the time we get here, remove any |
| 1065 | // references to it. |
| 1066 | g_view_map.Get().erase(webview_); |
| 1067 | webview_ = nullptr; |
| 1068 | g_routing_id_view_map.Get().erase(GetRoutingID()); |
| 1069 | // TODO(ajwong): Does this message actually get sent? |
| 1070 | RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(GetRoutingID())); |
| 1071 | } |
| 1072 | |
| 1073 | void RenderViewImpl::ApplyNewSizeForWidget(const gfx::Size& old_size, |
| 1074 | const gfx::Size& new_size) { |
| 1075 | if (webview()) { |
| 1076 | // Only hide popups when the size changes. There are situations (e.g. hiding |
| 1077 | // the ChromeOS virtual keyboard) where we send a resize message with no |
| 1078 | // change in size, but we don't want to close popups. |
| 1079 | // See https://crbug.com/761908. |
| 1080 | if (new_size != old_size) |
| 1081 | webview()->HidePopups(); |
| 1082 | |
| 1083 | if (send_preferred_size_changes_ && |
| 1084 | webview()->MainFrame()->IsWebLocalFrame()) { |
| 1085 | webview()->MainFrame()->ToWebLocalFrame()->SetCanHaveScrollbars( |
| 1086 | ShouldDisplayScrollbars(new_size.width(), new_size.height())); |
| 1087 | } |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | void RenderViewImpl::ApplyNewDisplayModeForWidget( |
| 1092 | const blink::WebDisplayMode& new_display_mode) { |
| 1093 | if (webview()) |
| 1094 | webview()->SetDisplayMode(new_display_mode); |
| 1095 | } |
| 1096 | |
| 1097 | void RenderViewImpl::ApplyAutoResizeLimitsForWidget(const gfx::Size& min_size, |
| 1098 | const gfx::Size& max_size) { |
| 1099 | webview()->EnableAutoResizeMode(min_size, max_size); |
| 1100 | } |
| 1101 | |
| 1102 | void RenderViewImpl::DisableAutoResizeForWidget() { |
| 1103 | webview()->DisableAutoResizeMode(); |
| 1104 | } |
| 1105 | |
| 1106 | void RenderViewImpl::ScrollFocusedNodeIntoViewForWidget() { |
| 1107 | if (WebLocalFrame* focused_frame = GetWebView()->FocusedFrame()) { |
| 1108 | auto* frame_widget = focused_frame->LocalRoot()->FrameWidget(); |
| 1109 | frame_widget->ScrollFocusedEditableElementIntoView(); |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | void RenderViewImpl::DidReceiveSetFocusEventForWidget() { |
| 1114 | // This message must always be received when the main frame is a |
| 1115 | // WebLocalFrame. |
| 1116 | // TODO(ajwong): Can this be removed and just check |owner_delegate_| in |
| 1117 | // RenderWidget instead? |
| 1118 | CHECK(webview()->MainFrame()->IsWebLocalFrame()); |
| 1119 | } |
| 1120 | |
| 1121 | void RenderViewImpl::DidChangeFocusForWidget() { |
| 1122 | // Notify all BrowserPlugins of the RenderView's focus state. |
| 1123 | if (BrowserPluginManager::Get()) |
| 1124 | BrowserPluginManager::Get()->UpdateFocusState(); |
| 1125 | } |
| 1126 | |
| 1127 | GURL RenderViewImpl::GetURLForGraphicsContext3DForWidget() { |
| 1128 | DCHECK(webview()); |
| 1129 | WebFrame* main_frame = webview()->MainFrame(); |
| 1130 | if (main_frame && main_frame->IsWebLocalFrame()) |
| 1131 | return GURL(main_frame->ToWebLocalFrame()->GetDocument().Url()); |
| 1132 | else |
| 1133 | return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D"); |
| 1134 | } |
| 1135 | |
| 1136 | void RenderViewImpl::DidCommitCompositorFrameForWidget() { |
| 1137 | for (auto& observer : observers_) |
| 1138 | observer.DidCommitCompositorFrame(); |
| 1139 | } |
| 1140 | |
| 1141 | void RenderViewImpl::DidCompletePageScaleAnimationForWidget() { |
| 1142 | if (auto* focused_frame = GetWebView()->FocusedFrame()) { |
| 1143 | if (focused_frame->AutofillClient()) |
| 1144 | focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame(); |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | void RenderViewImpl::ResizeWebWidgetForWidget( |
| 1149 | const gfx::Size& size, |
| 1150 | float top_controls_height, |
| 1151 | float bottom_controls_height, |
| 1152 | bool browser_controls_shrink_blink_size) { |
| 1153 | webview()->ResizeWithBrowserControls(size, top_controls_height, |
| 1154 | bottom_controls_height, |
| 1155 | browser_controls_shrink_blink_size); |
| 1156 | } |
| 1157 | |
| 1158 | void RenderViewImpl::RequestScheduleAnimationForWidget() { |
| 1159 | // Schedule the animation on the WidgetClient() which may not be the |
| 1160 | // RenderWidget directly in layout tests. |
| 1161 | WidgetClient()->ScheduleAnimation(); |
| 1162 | } |
| 1163 | |
| 1164 | void RenderViewImpl::SetScreenMetricsEmulationParametersForWidget( |
| 1165 | bool enabled, |
| 1166 | const blink::WebDeviceEmulationParams& params) { |
| 1167 | if (webview() && GetWidget()->layer_tree_view()) { |
| 1168 | if (enabled) |
| 1169 | webview()->EnableDeviceEmulation(params); |
| 1170 | else |
| 1171 | webview()->DisableDeviceEmulation(); |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | // IPC message handlers ----------------------------------------- |
| 1176 | |
| 1177 | void RenderViewImpl::OnSelectWordAroundCaret() { |
| 1178 | // TODO(ajwong): Move this into RenderWidget. http://crbug.com/545684 |
| 1179 | // Set default values for the ACK |
| 1180 | bool did_select = false; |
| 1181 | int start_adjust = 0; |
| 1182 | int end_adjust = 0; |
| 1183 | |
| 1184 | if (webview()) { |
| 1185 | WebLocalFrame* focused_frame = GetWebView()->FocusedFrame(); |
| 1186 | if (focused_frame) { |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 1187 | GetWidget()->SetHandlingInputEvent(true); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1188 | blink::WebRange initial_range = focused_frame->SelectionRange(); |
| 1189 | if (!initial_range.IsNull()) |
| 1190 | did_select = focused_frame->SelectWordAroundCaret(); |
| 1191 | if (did_select) { |
| 1192 | blink::WebRange adjusted_range = focused_frame->SelectionRange(); |
| 1193 | start_adjust = |
| 1194 | adjusted_range.StartOffset() - initial_range.StartOffset(); |
| 1195 | end_adjust = adjusted_range.EndOffset() - initial_range.EndOffset(); |
| 1196 | } |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 1197 | GetWidget()->SetHandlingInputEvent(false); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1198 | } |
| 1199 | } |
| 1200 | Send(new ViewHostMsg_SelectWordAroundCaretAck( |
| 1201 | GetWidget()->routing_id(), did_select, start_adjust, end_adjust)); |
| 1202 | } |
| 1203 | |
| 1204 | void RenderViewImpl::OnUpdateTargetURLAck() { |
| 1205 | // Check if there is a targeturl waiting to be sent. |
| 1206 | if (target_url_status_ == TARGET_PENDING) |
| 1207 | Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), pending_target_url_)); |
| 1208 | |
| 1209 | target_url_status_ = TARGET_NONE; |
| 1210 | } |
| 1211 | |
| 1212 | void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset, |
| 1213 | int history_length) { |
| 1214 | // -1 <= history_offset < history_length <= kMaxSessionHistoryEntries(50). |
| 1215 | DCHECK_LE(-1, history_offset); |
| 1216 | DCHECK_LT(history_offset, history_length); |
| 1217 | DCHECK_LE(history_length, kMaxSessionHistoryEntries); |
| 1218 | |
| 1219 | history_list_offset_ = history_offset; |
| 1220 | history_list_length_ = history_length; |
| 1221 | } |
| 1222 | |
| 1223 | void RenderViewImpl::OnSetInitialFocus(bool reverse) { |
| 1224 | if (!webview()) |
| 1225 | return; |
| 1226 | webview()->SetInitialFocus(reverse); |
| 1227 | } |
| 1228 | |
| 1229 | void RenderViewImpl::OnUpdateWindowScreenRect(gfx::Rect window_screen_rect) { |
| 1230 | // Defers to the RenderWidget message handler. |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 1231 | GetWidget()->SetWindowScreenRect(window_screen_rect); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | void RenderViewImpl::OnAudioStateChanged(bool is_audio_playing) { |
| 1235 | webview()->AudioStateChanged(is_audio_playing); |
| 1236 | } |
| 1237 | |
| 1238 | void RenderViewImpl::OnPausePageScheduledTasks(bool paused) { |
| 1239 | webview()->PausePageScheduledTasks(paused); |
| 1240 | } |
| 1241 | |
| 1242 | /////////////////////////////////////////////////////////////////////////////// |
| 1243 | |
| 1244 | void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget, |
| 1245 | WebNavigationPolicy policy, |
| 1246 | const gfx::Rect& initial_rect) { |
| 1247 | Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(), |
| 1248 | initial_rect)); |
| 1249 | } |
| 1250 | |
| 1251 | void RenderViewImpl::ShowCreatedFullscreenWidget( |
| 1252 | RenderWidget* fullscreen_widget, |
| 1253 | WebNavigationPolicy policy, |
| 1254 | const gfx::Rect& initial_rect) { |
| 1255 | Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(), |
| 1256 | fullscreen_widget->routing_id())); |
| 1257 | } |
| 1258 | |
| 1259 | void RenderViewImpl::SendFrameStateUpdates() { |
| 1260 | // Tell each frame with pending state to send its UpdateState message. |
| 1261 | for (int render_frame_routing_id : frames_with_pending_state_) { |
| 1262 | RenderFrameImpl* frame = |
| 1263 | RenderFrameImpl::FromRoutingID(render_frame_routing_id); |
| 1264 | if (frame) |
| 1265 | frame->SendUpdateState(); |
| 1266 | } |
| 1267 | frames_with_pending_state_.clear(); |
| 1268 | } |
| 1269 | |
| 1270 | void RenderViewImpl::ApplyWebPreferencesInternal(const WebPreferences& prefs, |
| 1271 | blink::WebView* web_view) { |
| 1272 | ApplyWebPreferences(prefs, web_view); |
| 1273 | } |
| 1274 | |
| 1275 | // IPC::Listener ------------------------------------------------------------- |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1276 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1277 | bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 1278 | WebFrame* main_frame = webview() ? webview()->MainFrame() : nullptr; |
Avi Drissman | b5f8e24 | 2017-12-12 05:21:56 | [diff] [blame] | 1279 | if (main_frame) { |
| 1280 | GURL active_url; |
| 1281 | if (main_frame->IsWebLocalFrame()) |
| 1282 | active_url = main_frame->ToWebLocalFrame()->GetDocument().Url(); |
lukasza | bedb4b2 | 2017-06-23 00:00:13 | [diff] [blame] | 1283 | GetContentClient()->SetActiveURL( |
Avi Drissman | b5f8e24 | 2017-12-12 05:21:56 | [diff] [blame] | 1284 | active_url, main_frame->Top()->GetSecurityOrigin().ToString().Utf8()); |
| 1285 | } |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 1286 | |
dcheng | a2d442c2 | 2016-10-13 15:39:21 | [diff] [blame] | 1287 | for (auto& observer : observers_) { |
| 1288 | if (observer.OnMessageReceived(message)) |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 1289 | return true; |
dcheng | a2d442c2 | 2016-10-13 15:39:21 | [diff] [blame] | 1290 | } |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1291 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1292 | bool handled = true; |
[email protected] | e44d134 | 2014-05-16 21:29:33 | [diff] [blame] | 1293 | IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message) |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 1294 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1295 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1296 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 1297 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 1298 | IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, |
| 1299 | OnEnumerateDirectoryResponse) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1300 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 1301 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 1302 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 1303 | OnEnablePreferredSizeChangedMode) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 1304 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 1305 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1306 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 1307 | IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt) |
aelias | 1b55156e5 | 2017-04-01 00:46:05 | [diff] [blame] | 1308 | IPC_MESSAGE_HANDLER(ViewMsg_ResolveTapDisambiguation, |
| 1309 | OnResolveTapDisambiguation) |
[email protected] | 4dda6a6c | 2014-05-17 15:35:04 | [diff] [blame] | 1310 | IPC_MESSAGE_HANDLER(ViewMsg_SelectWordAroundCaret, OnSelectWordAroundCaret) |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1311 | |
| 1312 | // Page messages. |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 1313 | IPC_MESSAGE_HANDLER(PageMsg_UpdateWindowScreenRect, |
| 1314 | OnUpdateWindowScreenRect) |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 1315 | IPC_MESSAGE_HANDLER(PageMsg_WasHidden, OnPageWasHidden) |
| 1316 | IPC_MESSAGE_HANDLER(PageMsg_WasShown, OnPageWasShown) |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 1317 | IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength, |
| 1318 | OnSetHistoryOffsetAndLength) |
altimin | d8bd26c | 2016-11-04 11:44:54 | [diff] [blame] | 1319 | IPC_MESSAGE_HANDLER(PageMsg_AudioStateChanged, OnAudioStateChanged) |
Gyuyoung Kim | 80143f5e | 2018-04-02 02:40:25 | [diff] [blame] | 1320 | IPC_MESSAGE_HANDLER(PageMsg_PausePageScheduledTasks, |
| 1321 | OnPausePageScheduledTasks) |
lfg | 8d649cc | 2017-04-28 18:04:30 | [diff] [blame] | 1322 | IPC_MESSAGE_HANDLER(PageMsg_UpdateScreenInfo, OnUpdateScreenInfo) |
Francois Doray | 47f759d | 2018-06-11 18:13:51 | [diff] [blame] | 1323 | IPC_MESSAGE_HANDLER(PageMsg_SetPageFrozen, SetPageFrozen) |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 1324 | |
Matthew Jones | b4456421b | 2018-02-22 20:29:41 | [diff] [blame] | 1325 | #if defined(OS_MACOSX) |
nasko | c288745f | 2015-05-01 22:54:21 | [diff] [blame] | 1326 | IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose) |
[email protected] | 55750b3 | 2012-09-21 14:05:03 | [diff] [blame] | 1327 | #endif |
[email protected] | a794f3a | 2013-10-30 17:00:32 | [diff] [blame] | 1328 | // Adding a new message? Add platform independent ones first, then put the |
| 1329 | // platform specific ones at the end. |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1330 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1331 | // Have the super handle all other messages. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1332 | IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1333 | IPC_END_MESSAGE_MAP() |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1334 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 1335 | return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1336 | } |
| 1337 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1338 | // blink::WebViewClient ------------------------------------------------------ |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1339 | |
Mustaq Ahmed | 55944cb | 2018-05-25 20:44:27 | [diff] [blame] | 1340 | // TODO(csharrison): Migrate this method to WebLocalFrameClient / |
| 1341 | // RenderFrameImpl, as it is now serviced by a mojo interface scoped to the |
| 1342 | // opener frame. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1343 | WebView* RenderViewImpl::CreateView(WebLocalFrame* creator, |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 1344 | const WebURLRequest& request, |
| 1345 | const WebWindowFeatures& features, |
| 1346 | const WebString& frame_name, |
| 1347 | WebNavigationPolicy policy, |
Daniel Cheng | d5e56ff | 2017-06-24 07:44:02 | [diff] [blame] | 1348 | bool suppress_opener, |
| 1349 | WebSandboxFlags sandbox_flags) { |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 1350 | RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator); |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 1351 | mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New(); |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 1352 | |
| 1353 | // User Activation v2 moves user gesture checks to the browser process, with |
| 1354 | // the exception of the extensions case handled through the following |if|. |
| 1355 | params->mimic_user_gesture = |
| 1356 | base::FeatureList::IsEnabled(features::kUserActivationV2) |
| 1357 | ? false |
| 1358 | : WebUserGestureIndicator::IsProcessingUserGesture(creator); |
[email protected] | 00323f0 | 2013-07-24 15:47:41 | [diff] [blame] | 1359 | if (GetContentClient()->renderer()->AllowPopup()) |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 1360 | params->mimic_user_gesture = true; |
| 1361 | |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 1362 | params->window_container_type = WindowFeaturesToContainerType(features); |
Daniel Murphy | e3eec92c | 2018-02-23 19:09:15 | [diff] [blame] | 1363 | |
| 1364 | params->session_storage_namespace_id = AllocateSessionStorageNamespaceId(); |
| 1365 | params->clone_from_session_storage_namespace_id = |
| 1366 | session_storage_namespace_id_; |
| 1367 | if (base::FeatureList::IsEnabled(features::kMojoSessionStorage)) { |
| 1368 | RenderThreadImpl::current_blink_platform_impl() |
| 1369 | ->CloneSessionStorageNamespace(session_storage_namespace_id_, |
| 1370 | params->session_storage_namespace_id); |
| 1371 | } |
| 1372 | |
Daniel Cheng | d5e56ff | 2017-06-24 07:44:02 | [diff] [blame] | 1373 | const std::string& frame_name_utf8 = frame_name.Utf8( |
| 1374 | WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD); |
| 1375 | params->frame_name = frame_name_utf8; |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 1376 | params->opener_suppressed = suppress_opener; |
| 1377 | params->disposition = NavigationPolicyToDisposition(policy); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1378 | if (!request.IsNull()) { |
| 1379 | params->target_url = request.Url(); |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 1380 | params->referrer = GetReferrerFromRequest(creator, request); |
[email protected] | 44e55b01 | 2013-07-23 14:21:56 | [diff] [blame] | 1381 | } |
scottmg | 8e6c608 | 2017-02-13 23:15:48 | [diff] [blame] | 1382 | params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features); |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1383 | |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 1384 | // We preserve this information before sending the message since |params| is |
| 1385 | // moved on send. |
| 1386 | bool is_background_tab = |
| 1387 | params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB; |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 1388 | bool opened_by_user_gesture = params->mimic_user_gesture; |
[email protected] | 22217ed3 | 2013-11-18 18:40:23 | [diff] [blame] | 1389 | |
Daniel Cheng | 8bb30c6 | 2017-10-23 20:40:47 | [diff] [blame] | 1390 | mojom::CreateNewWindowStatus status; |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 1391 | mojom::CreateNewWindowReplyPtr reply; |
Balazs Engedy | a40712f | 2017-09-15 15:01:11 | [diff] [blame] | 1392 | auto* frame_host = creator_frame->GetFrameHost(); |
Daniel Cheng | 8bb30c6 | 2017-10-23 20:40:47 | [diff] [blame] | 1393 | bool err = !frame_host->CreateNewWindow(std::move(params), &status, &reply); |
| 1394 | if (err || status == mojom::CreateNewWindowStatus::kIgnore) |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 1395 | return nullptr; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1396 | |
Jochen Eisinger | 515337a | 2017-05-26 14:12:52 | [diff] [blame] | 1397 | // For Android WebView, we support a pop-up like behavior for window.open() |
| 1398 | // even if the embedding app doesn't support multiple windows. In this case, |
| 1399 | // window.open() will return "window" and navigate it to whatever URL was |
Jochen Eisinger | 8cb2849 | 2017-10-04 10:58:13 | [diff] [blame] | 1400 | // passed. We also don't need to consume user gestures to protect against |
| 1401 | // multiple windows being opened, because, well, the app doesn't support |
| 1402 | // multiple windows. |
Daniel Cheng | 8bb30c6 | 2017-10-23 20:40:47 | [diff] [blame] | 1403 | // TODO(dcheng): It's awkward that this is plumbed into Blink but not really |
| 1404 | // used much in Blink, except to enable layout testing... perhaps this should |
| 1405 | // be checked directly in the browser side. |
| 1406 | if (status == mojom::CreateNewWindowStatus::kReuse) |
Jochen Eisinger | 515337a | 2017-05-26 14:12:52 | [diff] [blame] | 1407 | return webview(); |
| 1408 | |
Daniel Cheng | 8bb30c6 | 2017-10-23 20:40:47 | [diff] [blame] | 1409 | DCHECK(reply); |
| 1410 | DCHECK_NE(MSG_ROUTING_NONE, reply->route_id); |
| 1411 | DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_route_id); |
| 1412 | DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_widget_route_id); |
| 1413 | |
Mustaq Ahmed | 76c2f431 | 2018-06-07 20:48:01 | [diff] [blame] | 1414 | // The browser allowed creation of a new window and consumed the user |
| 1415 | // activation (UAv2 only). |
| 1416 | WebUserGestureIndicator::ConsumeUserGesture( |
| 1417 | creator, blink::UserActivationUpdateSource::kBrowser); |
Jochen Eisinger | 8cb2849 | 2017-10-04 10:58:13 | [diff] [blame] | 1418 | |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 1419 | // While this view may be a background extension page, it can spawn a visible |
| 1420 | // render view. So we just assume that the new one is not another background |
| 1421 | // page instead of passing on our own value. |
| 1422 | // TODO(vangelis): Can we tell if the new view will be a background page? |
| 1423 | bool never_visible = false; |
[email protected] | 9115d5f | 2013-03-24 04:37:41 | [diff] [blame] | 1424 | |
Fady Samuel | ff5b6eb56 | 2018-05-01 16:16:08 | [diff] [blame] | 1425 | VisualProperties visual_properties = VisualProperties(); |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 1426 | visual_properties.screen_info = GetWidget()->screen_info(); |
mkosiba | 58fa72f0 | 2014-11-12 01:21:36 | [diff] [blame] | 1427 | |
[email protected] | d6fa88f | 2013-10-18 16:00:43 | [diff] [blame] | 1428 | // The initial hidden state for the RenderViewImpl here has to match what the |
| 1429 | // browser will eventually decide for the given disposition. Since we have to |
| 1430 | // return from this call synchronously, we just have to make our best guess |
| 1431 | // and rely on the browser sending a WasHidden / WasShown message if it |
| 1432 | // disagrees. |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 1433 | mojom::CreateViewParamsPtr view_params = mojom::CreateViewParams::New(); |
alexmos | 5ac402d | 2015-07-09 07:51:10 | [diff] [blame] | 1434 | |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 1435 | view_params->opener_frame_route_id = creator_frame->GetRoutingID(); |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 1436 | DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID()); |
alexmos | 5ac402d | 2015-07-09 07:51:10 | [diff] [blame] | 1437 | |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 1438 | view_params->window_was_created_with_opener = true; |
| 1439 | view_params->renderer_preferences = renderer_preferences_; |
| 1440 | view_params->web_preferences = webkit_preferences_; |
| 1441 | view_params->view_id = reply->route_id; |
| 1442 | view_params->main_frame_routing_id = reply->main_frame_route_id; |
| 1443 | view_params->main_frame_interface_provider = |
| 1444 | std::move(reply->main_frame_interface_provider); |
| 1445 | view_params->main_frame_widget_routing_id = reply->main_frame_widget_route_id; |
| 1446 | view_params->session_storage_namespace_id = |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 1447 | reply->cloned_session_storage_namespace_id; |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 1448 | view_params->swapped_out = false; |
| 1449 | view_params->replicated_frame_state.frame_policy.sandbox_flags = |
| 1450 | sandbox_flags; |
| 1451 | view_params->replicated_frame_state.name = frame_name_utf8; |
| 1452 | view_params->devtools_main_frame_token = reply->devtools_main_frame_token; |
Daniel Cheng | d5e56ff | 2017-06-24 07:44:02 | [diff] [blame] | 1453 | // Even if the main frame has a name, the main frame's unique name is always |
| 1454 | // the empty string. |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 1455 | view_params->hidden = is_background_tab; |
| 1456 | view_params->never_visible = never_visible; |
Fady Samuel | ff5b6eb56 | 2018-05-01 16:16:08 | [diff] [blame] | 1457 | view_params->visual_properties = visual_properties; |
nasko | bd91133 | 2014-11-25 01:13:36 | [diff] [blame] | 1458 | |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 1459 | // Unretained() is safe here because our calling function will also call |
| 1460 | // show(). |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 1461 | RenderWidget::ShowCallback show_callback = |
danakj | df1ceb7 | 2018-07-18 20:02:25 | [diff] [blame] | 1462 | base::BindOnce(&RenderFrameImpl::ShowCreatedWindow, |
| 1463 | base::Unretained(creator_frame), opened_by_user_gesture); |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 1464 | |
Balazs Engedy | ba034e7 | 2017-10-27 22:26:28 | [diff] [blame] | 1465 | RenderViewImpl* view = RenderViewImpl::Create( |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 1466 | GetWidget()->compositor_deps(), std::move(view_params), |
| 1467 | std::move(show_callback), |
Hajime Hoshi | 6fc9114 | 2018-05-11 08:21:17 | [diff] [blame] | 1468 | creator->GetTaskRunner(blink::TaskType::kInternalDefault)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1469 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1470 | return view->webview(); |
| 1471 | } |
| 1472 | |
Hajime Hoshi | abb3c8f | 2017-12-04 18:41:39 | [diff] [blame] | 1473 | WebWidget* RenderViewImpl::CreatePopup(blink::WebLocalFrame* creator, |
| 1474 | blink::WebPopupType popup_type) { |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 1475 | RenderWidget* popup_widget = RenderWidget::CreateForPopup( |
| 1476 | this, GetWidget()->compositor_deps(), popup_type, |
| 1477 | GetWidget()->screen_info(), |
Hajime Hoshi | 6fc9114 | 2018-05-11 08:21:17 | [diff] [blame] | 1478 | creator->GetTaskRunner(blink::TaskType::kInternalDefault)); |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 1479 | if (!popup_widget) |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 1480 | return nullptr; |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 1481 | popup_widget->ApplyEmulatedScreenMetricsForPopupWidget(GetWidget()); |
| 1482 | return popup_widget->GetWebWidget(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1483 | } |
| 1484 | |
Daniel Murphy | 31bbb8b1 | 2018-02-07 21:44:10 | [diff] [blame] | 1485 | base::StringPiece RenderViewImpl::GetSessionStorageNamespaceId() { |
| 1486 | CHECK(!session_storage_namespace_id_.empty()); |
Daniel Murphy | 0ce6e2c | 2017-11-21 01:54:26 | [diff] [blame] | 1487 | return session_storage_namespace_id_; |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1488 | } |
| 1489 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1490 | void RenderViewImpl::PrintPage(WebLocalFrame* frame) { |
nasko | e440d8c | 2016-10-12 23:07:56 | [diff] [blame] | 1491 | UMA_HISTOGRAM_BOOLEAN("PrintPreview.InitiatedByScript", |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1492 | frame->Top() == frame); |
nasko | e440d8c | 2016-10-12 23:07:56 | [diff] [blame] | 1493 | |
| 1494 | // Logging whether the top frame is remote is sufficient in this case. If |
| 1495 | // the top frame is local, the printing code will function correctly and |
| 1496 | // the frame itself will be printed, so the cases this histogram tracks is |
| 1497 | // where printing of a subframe will fail as of now. |
| 1498 | UMA_HISTOGRAM_BOOLEAN("PrintPreview.OutOfProcessSubframe", |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1499 | frame->Top()->IsWebRemoteFrame()); |
nasko | e440d8c | 2016-10-12 23:07:56 | [diff] [blame] | 1500 | |
thestig | cb959ce | 2016-11-17 05:56:32 | [diff] [blame] | 1501 | RenderFrameImpl::FromWebFrame(frame)->ScriptedPrint( |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 1502 | GetWidget()->input_handler().handling_input_event()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1503 | } |
| 1504 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1505 | bool RenderViewImpl::EnumerateChosenDirectory( |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 1506 | const WebString& path, |
| 1507 | WebFileChooserCompletion* chooser_completion) { |
| 1508 | int id = enumeration_completion_id_++; |
| 1509 | enumeration_completions_[id] = chooser_completion; |
| 1510 | return Send(new ViewHostMsg_EnumerateDirectory( |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 1511 | GetRoutingID(), id, blink::WebStringToFilePath(path))); |
[email protected] | 8a58c1c | 2011-04-19 18:40:12 | [diff] [blame] | 1512 | } |
| 1513 | |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1514 | void RenderViewImpl::FrameDidStartLoading(WebFrame* frame) { |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1515 | DCHECK_GE(frames_in_progress_, 0); |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 1516 | if (frames_in_progress_ == 0) { |
| 1517 | for (auto& observer : observers_) |
| 1518 | observer.DidStartLoading(); |
| 1519 | } |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1520 | frames_in_progress_++; |
[email protected] | 6dd5c32 | 2014-03-12 07:58:46 | [diff] [blame] | 1521 | } |
| 1522 | |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1523 | void RenderViewImpl::FrameDidStopLoading(WebFrame* frame) { |
[email protected] | eb47377 | 2014-04-11 20:54:33 | [diff] [blame] | 1524 | // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes |
| 1525 | // calls DidStopLoading() without a matching DidStartLoading(). |
| 1526 | if (frames_in_progress_ == 0) |
| 1527 | return; |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1528 | frames_in_progress_--; |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1529 | if (frames_in_progress_ == 0) { |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 1530 | for (auto& observer : observers_) |
| 1531 | observer.DidStopLoading(); |
[email protected] | 7e9523b | 2014-03-25 03:02:42 | [diff] [blame] | 1532 | } |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1533 | } |
| 1534 | |
lfg | caab514 | 2016-02-26 19:06:52 | [diff] [blame] | 1535 | void RenderViewImpl::AttachWebFrameWidget(blink::WebFrameWidget* frame_widget) { |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1536 | // The previous WebFrameWidget must already be detached by CloseForFrame(). |
| 1537 | DCHECK(!frame_widget_); |
| 1538 | frame_widget_ = frame_widget; |
| 1539 | } |
| 1540 | |
tommycli | 8aad3ba | 2015-08-12 17:57:59 | [diff] [blame] | 1541 | void RenderViewImpl::SetZoomLevel(double zoom_level) { |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1542 | // If we change the zoom level for the view, make sure any subsequent subframe |
| 1543 | // loads reflect the current zoom level. |
| 1544 | page_zoom_level_ = zoom_level; |
| 1545 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1546 | webview()->SetZoomLevel(zoom_level); |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 1547 | for (auto& observer : observers_) |
| 1548 | observer.OnZoomLevelChanged(); |
tommycli | 8aad3ba | 2015-08-12 17:57:59 | [diff] [blame] | 1549 | } |
| 1550 | |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 1551 | void RenderViewImpl::SetValidationMessageDirection( |
| 1552 | base::string16* wrapped_main_text, |
| 1553 | blink::WebTextDirection main_text_hint, |
| 1554 | base::string16* wrapped_sub_text, |
| 1555 | blink::WebTextDirection sub_text_hint) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1556 | if (main_text_hint == blink::kWebTextDirectionLeftToRight) { |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 1557 | *wrapped_main_text = |
| 1558 | base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1559 | } else if (main_text_hint == blink::kWebTextDirectionRightToLeft && |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 1560 | !base::i18n::IsRTL()) { |
| 1561 | base::i18n::WrapStringWithRTLFormatting(wrapped_main_text); |
| 1562 | } |
| 1563 | |
| 1564 | if (!wrapped_sub_text->empty()) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1565 | if (sub_text_hint == blink::kWebTextDirectionLeftToRight) { |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 1566 | *wrapped_sub_text = |
| 1567 | base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1568 | } else if (sub_text_hint == blink::kWebTextDirectionRightToLeft) { |
habib.virji | 597255e | 2014-09-09 00:30:18 | [diff] [blame] | 1569 | base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text); |
| 1570 | } |
| 1571 | } |
| 1572 | } |
| 1573 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1574 | void RenderViewImpl::UpdateTargetURL(const GURL& url, |
| 1575 | const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 1576 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1577 | if (latest_url == target_url_) |
| 1578 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1579 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1580 | // Tell the browser to display a destination link. |
| 1581 | if (target_url_status_ == TARGET_INFLIGHT || |
| 1582 | target_url_status_ == TARGET_PENDING) { |
| 1583 | // If we have a request in-flight, save the URL to be sent when we |
| 1584 | // receive an ACK to the in-flight request. We can happily overwrite |
| 1585 | // any existing pending sends. |
| 1586 | pending_target_url_ = latest_url; |
| 1587 | target_url_status_ = TARGET_PENDING; |
| 1588 | } else { |
mnaganov | bf08742 | 2015-12-16 05:10:03 | [diff] [blame] | 1589 | // URLs larger than |kMaxURLChars| cannot be sent through IPC - |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 1590 | // see |ParamTraits<GURL>|. |
markdittmer | 67b71ea | 2016-03-03 22:40:03 | [diff] [blame] | 1591 | if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars) |
[email protected] | c85f021 | 2011-11-04 16:54:41 | [diff] [blame] | 1592 | latest_url = GURL(); |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 1593 | Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), latest_url)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1594 | target_url_ = latest_url; |
| 1595 | target_url_status_ = TARGET_INFLIGHT; |
| 1596 | } |
| 1597 | } |
| 1598 | |
creis | 69b184a47 | 2015-11-26 05:29:51 | [diff] [blame] | 1599 | void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) { |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 1600 | // Keep track of which frames have pending updates. |
| 1601 | frames_with_pending_state_.insert(frame->GetRoutingID()); |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 1602 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1603 | int delay; |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1604 | if (send_content_state_immediately_) |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1605 | delay = 0; |
| 1606 | else if (is_hidden()) |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1607 | delay = kDelaySecondsForContentStateSyncHidden; |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1608 | else |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1609 | delay = kDelaySecondsForContentStateSync; |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1610 | |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1611 | if (nav_state_sync_timer_.IsRunning()) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1612 | // The timer is already running. If the delay of the timer maches the amount |
| 1613 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 1614 | // gets started with the right delay. |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1615 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1616 | return; |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1617 | nav_state_sync_timer_.Stop(); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1618 | } |
| 1619 | |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 1620 | // Tell each frame with pending state to inform the browser. |
| 1621 | nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this, |
| 1622 | &RenderViewImpl::SendFrameStateUpdates); |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1623 | } |
| 1624 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1625 | void RenderViewImpl::SetMouseOverURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1626 | mouse_over_url_ = GURL(url); |
| 1627 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 1628 | } |
| 1629 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1630 | void RenderViewImpl::SetKeyboardFocusURL(const WebURL& url) { |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1631 | focus_url_ = GURL(url); |
| 1632 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 1633 | } |
| 1634 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1635 | bool RenderViewImpl::AcceptsLoadDrops() { |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 1636 | return renderer_preferences_.can_accept_load_drops; |
| 1637 | } |
| 1638 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1639 | void RenderViewImpl::FocusNext() { |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 1640 | Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1641 | } |
| 1642 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1643 | void RenderViewImpl::FocusPrevious() { |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 1644 | Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1645 | } |
| 1646 | |
esprehn | 3d4471a | 2015-09-17 07:13:20 | [diff] [blame] | 1647 | // TODO(esprehn): Blink only ever passes Elements, this should take WebElement. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1648 | void RenderViewImpl::FocusedNodeChanged(const WebNode& fromNode, |
estade | 31c5434 | 2015-01-23 03:34:36 | [diff] [blame] | 1649 | const WebNode& toNode) { |
estade | 31c5434 | 2015-01-23 03:34:36 | [diff] [blame] | 1650 | RenderFrameImpl* previous_frame = nullptr; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1651 | if (!fromNode.IsNull()) |
| 1652 | previous_frame = |
| 1653 | RenderFrameImpl::FromWebFrame(fromNode.GetDocument().GetFrame()); |
estade | 31c5434 | 2015-01-23 03:34:36 | [diff] [blame] | 1654 | RenderFrameImpl* new_frame = nullptr; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1655 | if (!toNode.IsNull()) |
| 1656 | new_frame = RenderFrameImpl::FromWebFrame(toNode.GetDocument().GetFrame()); |
estade | 31c5434 | 2015-01-23 03:34:36 | [diff] [blame] | 1657 | |
| 1658 | if (previous_frame && previous_frame != new_frame) |
| 1659 | previous_frame->FocusedNodeChanged(WebNode()); |
| 1660 | if (new_frame) |
| 1661 | new_frame->FocusedNodeChanged(toNode); |
| 1662 | |
| 1663 | // TODO(dmazzoni): remove once there's a separate a11y tree per frame. |
nasko | e8d11575 | 2015-08-07 00:43:13 | [diff] [blame] | 1664 | if (main_render_frame_) |
| 1665 | main_render_frame_->FocusedNodeChangedForAccessibility(toNode); |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 1666 | } |
| 1667 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1668 | void RenderViewImpl::DidUpdateLayout() { |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 1669 | for (auto& observer : observers_) |
| 1670 | observer.DidUpdateLayout(); |
[email protected] | d01b2a6 | 2013-09-18 23:21:33 | [diff] [blame] | 1671 | |
[email protected] | 169d428 | 2011-11-30 19:33:59 | [diff] [blame] | 1672 | // We don't always want to set up a timer, only if we've been put in that |
| 1673 | // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 1674 | // message. |
| 1675 | if (!send_preferred_size_changes_ || !webview()) |
| 1676 | return; |
| 1677 | |
| 1678 | if (check_preferred_size_timer_.IsRunning()) |
| 1679 | return; |
| 1680 | check_preferred_size_timer_.Start(FROM_HERE, |
| 1681 | TimeDelta::FromMilliseconds(0), this, |
| 1682 | &RenderViewImpl::CheckPreferredSize); |
| 1683 | } |
| 1684 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1685 | void RenderViewImpl::NavigateBackForwardSoon(int offset) { |
Alex Clarke | bf3dceb | 2017-11-24 12:27:43 | [diff] [blame] | 1686 | history_navigation_virtual_time_pauser_ = |
| 1687 | RenderThreadImpl::current() |
Yuta Kitamura | 3331f5c | 2018-04-05 11:12:25 | [diff] [blame] | 1688 | ->GetWebMainThreadScheduler() |
Alex Clarke | b28db54 | 2018-02-07 12:53:13 | [diff] [blame] | 1689 | ->CreateWebScopedVirtualTimePauser( |
Alex Clarke | aaf006b | 2018-04-05 18:35:24 | [diff] [blame] | 1690 | "NavigateBackForwardSoon", |
Alex Clarke | b28db54 | 2018-02-07 12:53:13 | [diff] [blame] | 1691 | blink::WebScopedVirtualTimePauser::VirtualTaskDuration::kInstant); |
Alex Clarke | aaf006b | 2018-04-05 18:35:24 | [diff] [blame] | 1692 | history_navigation_virtual_time_pauser_.PauseVirtualTime(); |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 1693 | Send(new ViewHostMsg_GoToEntryAtOffset(GetRoutingID(), offset)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1694 | } |
| 1695 | |
Alex Clarke | bf3dceb | 2017-11-24 12:27:43 | [diff] [blame] | 1696 | void RenderViewImpl::DidCommitProvisionalHistoryLoad() { |
Alex Clarke | aaf006b | 2018-04-05 18:35:24 | [diff] [blame] | 1697 | history_navigation_virtual_time_pauser_.UnpauseVirtualTime(); |
Alex Clarke | bf3dceb | 2017-11-24 12:27:43 | [diff] [blame] | 1698 | } |
| 1699 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1700 | int RenderViewImpl::HistoryBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1701 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1702 | } |
| 1703 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1704 | int RenderViewImpl::HistoryForwardListCount() { |
| 1705 | return history_list_length_ - HistoryBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1706 | } |
| 1707 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1708 | // blink::WebWidgetClient ---------------------------------------------------- |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1709 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1710 | bool RenderViewImpl::CanHandleGestureEvent() { |
slangley | 1a6375e6 | 2017-03-29 06:03:23 | [diff] [blame] | 1711 | return true; |
| 1712 | } |
| 1713 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1714 | bool RenderViewImpl::CanUpdateLayout() { |
slangley | 1a6375e6 | 2017-03-29 06:03:23 | [diff] [blame] | 1715 | return true; |
| 1716 | } |
| 1717 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1718 | blink::WebWidgetClient* RenderViewImpl::WidgetClient() { |
danakj | 9a8a9cf | 2018-07-17 23:52:12 | [diff] [blame] | 1719 | return this; |
lfg | 0f44062 | 2016-07-20 04:27:14 | [diff] [blame] | 1720 | } |
| 1721 | |
Mustaq Ahmed | 55944cb | 2018-05-25 20:44:27 | [diff] [blame] | 1722 | // blink::WebLocalFrameClient |
| 1723 | // ----------------------------------------------------- |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1724 | |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 1725 | void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name, |
| 1726 | const std::string& value) { |
alexmos | 5656749 | 2016-09-13 00:52:46 | [diff] [blame] | 1727 | GetWidget()->SetEditCommandForNextKeyEvent(name, value); |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | void RenderViewImpl::ClearEditCommands() { |
alexmos | 5656749 | 2016-09-13 00:52:46 | [diff] [blame] | 1731 | GetWidget()->ClearEditCommands(); |
[email protected] | b2324b09 | 2012-11-01 10:34:11 | [diff] [blame] | 1732 | } |
| 1733 | |
[email protected] | b38806a | 2013-10-04 16:01:38 | [diff] [blame] | 1734 | const std::string& RenderViewImpl::GetAcceptLanguages() const { |
| 1735 | return renderer_preferences_.accept_languages; |
| 1736 | } |
| 1737 | |
danakj | dea2efb | 2016-03-10 19:13:17 | [diff] [blame] | 1738 | void RenderViewImpl::ConvertViewportToWindowViaWidget(blink::WebRect* rect) { |
danakj | 9a8a9cf | 2018-07-17 23:52:12 | [diff] [blame] | 1739 | WidgetClient()->ConvertViewportToWindow(rect); |
oshima | e2b3b40 | 2015-12-04 04:27:24 | [diff] [blame] | 1740 | } |
| 1741 | |
huangs | 2a34235 | 2015-12-15 16:59:24 | [diff] [blame] | 1742 | gfx::RectF RenderViewImpl::ElementBoundsInWindow( |
| 1743 | const blink::WebElement& element) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1744 | blink::WebRect bounding_box_in_window = element.BoundsInViewport(); |
danakj | 9a8a9cf | 2018-07-17 23:52:12 | [diff] [blame] | 1745 | WidgetClient()->ConvertViewportToWindow(&bounding_box_in_window); |
huangs | 2a34235 | 2015-12-15 16:59:24 | [diff] [blame] | 1746 | return gfx::RectF(bounding_box_in_window); |
| 1747 | } |
| 1748 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1749 | void RenderViewImpl::CheckPreferredSize() { |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 1750 | // We don't always want to send the change messages over IPC, only if we've |
| 1751 | // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| 1752 | // message. |
| 1753 | if (!send_preferred_size_changes_ || !webview()) |
| 1754 | return; |
oshima | 1a688b5c | 2017-06-16 19:00:13 | [diff] [blame] | 1755 | blink::WebSize tmp_size = webview()->ContentsPreferredMinimumSize(); |
| 1756 | blink::WebRect tmp_rect(0, 0, tmp_size.width, tmp_size.height); |
danakj | 9a8a9cf | 2018-07-17 23:52:12 | [diff] [blame] | 1757 | WidgetClient()->ConvertViewportToWindow(&tmp_rect); |
oshima | 1a688b5c | 2017-06-16 19:00:13 | [diff] [blame] | 1758 | gfx::Size size(tmp_rect.width, tmp_rect.height); |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 1759 | if (size == preferred_size_) |
| 1760 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 1761 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 1762 | preferred_size_ = size; |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 1763 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(GetRoutingID(), |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 1764 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1765 | } |
| 1766 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1767 | blink::WebString RenderViewImpl::AcceptLanguages() { |
| 1768 | return WebString::FromUTF8(renderer_preferences_.accept_languages); |
[email protected] | 9982c80 | 2013-06-12 15:22:06 | [diff] [blame] | 1769 | } |
| 1770 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1771 | // RenderView implementation --------------------------------------------------- |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1772 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1773 | bool RenderViewImpl::Send(IPC::Message* message) { |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1774 | // This method is an override of IPC::Sender, but RenderWidget also has an |
| 1775 | // override of IPC::Sender, so this method also overrides RenderWidget. Thus |
| 1776 | // we must call to the base class, not via an upcast or virtual dispatch would |
| 1777 | // go back here. |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1778 | return RenderWidget::Send(message); |
| 1779 | } |
| 1780 | |
Peter Kasting | a4a3ed1 | 2018-01-31 04:07:59 | [diff] [blame] | 1781 | RenderWidget* RenderViewImpl::GetWidget() { |
| 1782 | return this; |
avi | 8a45c109 | 2016-03-01 16:12:34 | [diff] [blame] | 1783 | } |
| 1784 | |
mostynb | c3335323 | 2014-09-12 09:38:31 | [diff] [blame] | 1785 | RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() { |
nasko | 77de231 | 2015-05-12 03:09:16 | [diff] [blame] | 1786 | return main_render_frame_; |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 1787 | } |
| 1788 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 1789 | int RenderViewImpl::GetRoutingID() const { |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 1790 | return routing_id_; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1791 | } |
| 1792 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 1793 | gfx::Size RenderViewImpl::GetSize() const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1794 | return size(); |
| 1795 | } |
| 1796 | |
oshima | 129b75e | 2016-01-14 09:15:14 | [diff] [blame] | 1797 | float RenderViewImpl::GetDeviceScaleFactor() const { |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 1798 | return GetWebScreenInfo().device_scale_factor; |
oshima | 129b75e | 2016-01-14 09:15:14 | [diff] [blame] | 1799 | } |
| 1800 | |
Marc Treib | 06d6603 | 2017-10-19 08:43:20 | [diff] [blame] | 1801 | float RenderViewImpl::GetZoomLevel() const { |
| 1802 | return page_zoom_level_; |
| 1803 | } |
| 1804 | |
thestig | 8a8fdfd3 | 2017-05-06 18:46:54 | [diff] [blame] | 1805 | const WebPreferences& RenderViewImpl::GetWebkitPreferences() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1806 | return webkit_preferences_; |
| 1807 | } |
| 1808 | |
[email protected] | 324825d | 2012-11-30 12:37:15 | [diff] [blame] | 1809 | void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) { |
| 1810 | OnUpdateWebPreferences(preferences); |
| 1811 | } |
| 1812 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1813 | blink::WebView* RenderViewImpl::GetWebView() { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1814 | return webview(); |
| 1815 | } |
| 1816 | |
lfg | caab514 | 2016-02-26 19:06:52 | [diff] [blame] | 1817 | blink::WebFrameWidget* RenderViewImpl::GetWebFrameWidget() { |
| 1818 | return frame_widget_; |
| 1819 | } |
| 1820 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1821 | bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1822 | return (!send_preferred_size_changes_ || |
| 1823 | (disable_scrollbars_size_limit_.width() <= width || |
| 1824 | disable_scrollbars_size_limit_.height() <= height)); |
| 1825 | } |
| 1826 | |
avi | f937e1d | 2014-11-02 18:13:07 | [diff] [blame] | 1827 | bool RenderViewImpl::GetContentStateImmediately() const { |
| 1828 | return send_content_state_immediately_; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 1829 | } |
| 1830 | |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 1831 | void RenderViewImpl::OnSetPageScale(float page_scale_factor) { |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 1832 | if (!webview()) |
| 1833 | return; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1834 | webview()->SetPageScaleFactor(page_scale_factor); |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 1835 | } |
| 1836 | |
akaba | 3483d8f | 2018-07-10 21:43:09 | [diff] [blame] | 1837 | void RenderViewImpl::UpdateZoomLevel(double zoom_level) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1838 | webview()->HidePopups(); |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1839 | SetZoomLevel(zoom_level); |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 1840 | } |
| 1841 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1842 | void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 1843 | webkit_preferences_ = prefs; |
danakj | 39f6812 | 2018-07-16 20:11:46 | [diff] [blame] | 1844 | ApplyWebPreferencesInternal(webkit_preferences_, webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1845 | } |
| 1846 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1847 | void RenderViewImpl::OnEnumerateDirectoryResponse( |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 1848 | int id, |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 1849 | const std::vector<base::FilePath>& paths) { |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 1850 | if (!enumeration_completions_[id]) |
| 1851 | return; |
| 1852 | |
| 1853 | WebVector<WebString> ws_file_names(paths.size()); |
| 1854 | for (size_t i = 0; i < paths.size(); ++i) |
kinuko | a429302 | 2017-01-27 06:43:25 | [diff] [blame] | 1855 | ws_file_names[i] = blink::FilePathToWebString(paths[i]); |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 1856 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1857 | enumeration_completions_[id]->DidChooseFile(ws_file_names); |
[email protected] | 600ea40 | 2011-04-12 00:01:51 | [diff] [blame] | 1858 | enumeration_completions_.erase(id); |
| 1859 | } |
| 1860 | |
[email protected] | 2bf834f | 2011-11-17 20:02:21 | [diff] [blame] | 1861 | void RenderViewImpl::OnEnablePreferredSizeChangedMode() { |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 1862 | if (send_preferred_size_changes_) |
| 1863 | return; |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 1864 | send_preferred_size_changes_ = true; |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 1865 | |
[email protected] | d812fd1 | 2011-05-27 23:05:07 | [diff] [blame] | 1866 | // Start off with an initial preferred size notification (in case |
| 1867 | // |didUpdateLayout| was already called). |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1868 | DidUpdateLayout(); |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 1869 | } |
| 1870 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1871 | void RenderViewImpl::OnDisableScrollbarsForSmallWindows( |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 1872 | const gfx::Size& disable_scrollbar_size_limit) { |
| 1873 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 1874 | } |
| 1875 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1876 | void RenderViewImpl::OnSetRendererPrefs( |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1877 | const RendererPreferences& renderer_prefs) { |
[email protected] | ebd5ea5 | 2014-05-28 14:51:15 | [diff] [blame] | 1878 | std::string old_accept_languages = renderer_preferences_.accept_languages; |
| 1879 | |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1880 | renderer_preferences_ = renderer_prefs; |
ananta | 59b9fe7 | 2015-04-07 01:33:26 | [diff] [blame] | 1881 | |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 1882 | UpdateFontRenderingFromRendererPrefs(); |
scottmg | b92365e | 2016-08-30 20:54:40 | [diff] [blame] | 1883 | UpdateThemePrefs(); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1884 | blink::SetCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 1885 | |
brettw | 8a274fa | 2016-11-15 00:20:40 | [diff] [blame] | 1886 | #if BUILDFLAG(USE_DEFAULT_RENDER_THEME) |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 1887 | if (renderer_prefs.use_custom_colors) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1888 | blink::SetFocusRingColor(renderer_prefs.focus_ring_color); |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 1889 | |
| 1890 | if (webview()) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1891 | webview()->SetSelectionColors(renderer_prefs.active_selection_bg_color, |
| 1892 | renderer_prefs.active_selection_fg_color, |
| 1893 | renderer_prefs.inactive_selection_bg_color, |
| 1894 | renderer_prefs.inactive_selection_fg_color); |
| 1895 | webview()->ThemeChanged(); |
[email protected] | 1596efb | 2013-01-17 22:13:01 | [diff] [blame] | 1896 | } |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 1897 | } |
brettw | 8a274fa | 2016-11-15 00:20:40 | [diff] [blame] | 1898 | #endif // BUILDFLAG(USE_DEFAULT_RENDER_THEME) |
[email protected] | d299d97 | 2012-03-23 02:26:55 | [diff] [blame] | 1899 | |
[email protected] | ebd5ea5 | 2014-05-28 14:51:15 | [diff] [blame] | 1900 | if (webview() && |
| 1901 | old_accept_languages != renderer_preferences_.accept_languages) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1902 | webview()->AcceptLanguagesChanged(); |
[email protected] | ebd5ea5 | 2014-05-28 14:51:15 | [diff] [blame] | 1903 | } |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1904 | } |
| 1905 | |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 1906 | void RenderViewImpl::OnPluginActionAt(const gfx::Point& location, |
| 1907 | const WebPluginAction& action) { |
| 1908 | if (webview()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1909 | webview()->PerformPluginAction(action, location); |
[email protected] | 81375e87 | 2012-01-11 21:40:36 | [diff] [blame] | 1910 | } |
| 1911 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1912 | void RenderViewImpl::OnClosePage() { |
lukasza | 5d0dee4 | 2017-06-14 21:57:37 | [diff] [blame] | 1913 | // ViewMsg_ClosePage should only be sent to active, non-swapped-out views. |
| 1914 | DCHECK(webview()->MainFrame()->IsWebLocalFrame()); |
| 1915 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1916 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 1917 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 1918 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 1919 | // calling the FrameLoader's CloseURL method directly. This should be |
| 1920 | // revisited to avoid having two ways to close a page. Having a single way |
| 1921 | // to close that can run onunload is also useful for fixing |
| 1922 | // http://b/issue?id=753080. |
lukasza | 5d0dee4 | 2017-06-14 21:57:37 | [diff] [blame] | 1923 | webview()->MainFrame()->ToWebLocalFrame()->DispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1924 | |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 1925 | Send(new ViewHostMsg_ClosePage_ACK(GetRoutingID())); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1926 | } |
| 1927 | |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 1928 | #if defined(OS_MACOSX) |
nasko | c288745f | 2015-05-01 22:54:21 | [diff] [blame] | 1929 | void RenderViewImpl::OnClose() { |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 1930 | if (GetWidget()->closing()) |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 1931 | RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(GetRoutingID())); |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 1932 | // This method is protected for OS_MACOSX only, because the message gets sent |
| 1933 | // to the RenderViewImpl instead of to the RenderWidget. |
| 1934 | // TODO(danakj): Move this message to RenderWidget? |
nasko | c288745f | 2015-05-01 22:54:21 | [diff] [blame] | 1935 | RenderWidget::OnClose(); |
| 1936 | } |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 1937 | #endif |
nasko | c288745f | 2015-05-01 22:54:21 | [diff] [blame] | 1938 | |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1939 | void RenderViewImpl::OnMoveOrResizeStarted() { |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 1940 | if (webview()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1941 | webview()->HidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 1942 | } |
| 1943 | |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 1944 | void RenderViewImpl::OnPageWasHidden() { |
braveyao | 1d8ee7b | 2017-03-29 21:10:04 | [diff] [blame] | 1945 | #if defined(OS_ANDROID) |
| 1946 | SuspendVideoCaptureDevices(true); |
braveyao | 1d8ee7b | 2017-03-29 21:10:04 | [diff] [blame] | 1947 | #endif |
[email protected] | 2d7b82c | 2012-06-01 05:57:50 | [diff] [blame] | 1948 | |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 1949 | if (webview()) { |
| 1950 | // TODO(lfg): It's not correct to defer the page visibility to the main |
| 1951 | // frame. Currently, this is done because the main frame may override the |
| 1952 | // visibility of the page when prerendering. In order to fix this, |
| 1953 | // prerendering must be made aware of OOPIFs. https://crbug.com/440544 |
xzhan96 | cf0a3c54 | 2017-11-17 04:33:01 | [diff] [blame] | 1954 | blink::mojom::PageVisibilityState visibilityState = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1955 | GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState() |
xzhan96 | cf0a3c54 | 2017-11-17 04:33:01 | [diff] [blame] | 1956 | : blink::mojom::PageVisibilityState::kHidden; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1957 | webview()->SetVisibilityState(visibilityState, false); |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 1958 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 1959 | } |
| 1960 | |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 1961 | void RenderViewImpl::OnPageWasShown() { |
braveyao | 1d8ee7b | 2017-03-29 21:10:04 | [diff] [blame] | 1962 | #if defined(OS_ANDROID) |
| 1963 | SuspendVideoCaptureDevices(false); |
[email protected] | 6392d98 | 2013-04-16 16:59:22 | [diff] [blame] | 1964 | #endif |
| 1965 | |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 1966 | if (webview()) { |
xzhan96 | cf0a3c54 | 2017-11-17 04:33:01 | [diff] [blame] | 1967 | blink::mojom::PageVisibilityState visibilityState = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1968 | GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState() |
xzhan96 | cf0a3c54 | 2017-11-17 04:33:01 | [diff] [blame] | 1969 | : blink::mojom::PageVisibilityState::kVisible; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1970 | webview()->SetVisibilityState(visibilityState, false); |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 1971 | } |
[email protected] | a6939ca4 | 2011-02-18 17:58:07 | [diff] [blame] | 1972 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 1973 | |
lfg | 8d649cc | 2017-04-28 18:04:30 | [diff] [blame] | 1974 | void RenderViewImpl::OnUpdateScreenInfo(const ScreenInfo& screen_info) { |
| 1975 | // This IPC only updates the screen info on RenderViews that have a remote |
| 1976 | // main frame. For local main frames, the ScreenInfo is updated in |
| 1977 | // ViewMsg_Resize. |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 1978 | // TODO(danakj): Move this message to RenderWidget? |
lfg | 8d649cc | 2017-04-28 18:04:30 | [diff] [blame] | 1979 | if (!main_render_frame_) |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 1980 | GetWidget()->set_screen_info(screen_info); |
lfg | 8d649cc | 2017-04-28 18:04:30 | [diff] [blame] | 1981 | } |
| 1982 | |
Francois Doray | 47f759d | 2018-06-11 18:13:51 | [diff] [blame] | 1983 | void RenderViewImpl::SetPageFrozen(bool frozen) { |
| 1984 | if (webview()) |
| 1985 | webview()->SetPageFrozen(frozen); |
Fadi Meawad | a6573e0 | 2018-03-10 00:52:11 | [diff] [blame] | 1986 | } |
| 1987 | |
alexmos | 3fcd0ca | 2015-10-23 18:18:33 | [diff] [blame] | 1988 | void RenderViewImpl::SetFocus(bool enable) { |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1989 | // This is not an IPC message, don't go through the IPC handler. This is used |
| 1990 | // in cases where the IPC message should not happen. |
| 1991 | GetWidget()->SetFocus(enable); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 1992 | } |
| 1993 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1994 | void RenderViewImpl::ZoomLimitsChanged(double minimum_level, |
[email protected] | 310ebd630 | 2011-10-10 19:06:28 | [diff] [blame] | 1995 | double maximum_level) { |
a.sarkar.arun | daadc71 | 2015-02-26 05:39:08 | [diff] [blame] | 1996 | // Round the double to avoid returning incorrect minimum/maximum zoom |
| 1997 | // percentages. |
| 1998 | int minimum_percent = round( |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 1999 | ZoomLevelToZoomFactor(minimum_level) * 100); |
a.sarkar.arun | daadc71 | 2015-02-26 05:39:08 | [diff] [blame] | 2000 | int maximum_percent = round( |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 2001 | ZoomLevelToZoomFactor(maximum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 2002 | |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 2003 | Send(new ViewHostMsg_UpdateZoomLimits(GetRoutingID(), minimum_percent, |
fsamuel | e8326c74 | 2016-01-12 00:49:39 | [diff] [blame] | 2004 | maximum_percent)); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 2005 | } |
| 2006 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2007 | void RenderViewImpl::PageScaleFactorChanged() { |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 2008 | if (!webview()) |
| 2009 | return; |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 2010 | |
avi | a3dca18 | 2016-03-19 01:09:52 | [diff] [blame] | 2011 | Send(new ViewHostMsg_PageScaleFactorChanged(GetRoutingID(), |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2012 | webview()->PageScaleFactor())); |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 2013 | } |
| 2014 | |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 2015 | double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const { |
| 2016 | return ZoomLevelToZoomFactor(zoom_level); |
| 2017 | } |
| 2018 | |
| 2019 | double RenderViewImpl::zoomFactorToZoomLevel(double factor) const { |
| 2020 | return ZoomFactorToZoomLevel(factor); |
| 2021 | } |
| 2022 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2023 | void RenderViewImpl::PageImportanceSignalsChanged() { |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 2024 | if (!webview() || !main_render_frame_) |
| 2025 | return; |
| 2026 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2027 | auto* web_signals = webview()->PageImportanceSignals(); |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 2028 | |
| 2029 | PageImportanceSignals signals; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2030 | signals.had_form_interaction = web_signals->HadFormInteraction(); |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 2031 | |
| 2032 | main_render_frame_->Send(new FrameHostMsg_UpdatePageImportanceSignals( |
| 2033 | main_render_frame_->GetRoutingID(), signals)); |
| 2034 | } |
| 2035 | |
danakj | 9a8a9cf | 2018-07-17 23:52:12 | [diff] [blame] | 2036 | void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) { |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 2037 | GetWidget()->DidAutoResize(newSize); |
danakj | 9a8a9cf | 2018-07-17 23:52:12 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | blink::WebRect RenderViewImpl::RootWindowRect() { |
| 2041 | return WidgetClient()->WindowRect(); |
| 2042 | } |
| 2043 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 2044 | void RenderViewImpl::DidFocus(blink::WebLocalFrame* calling_frame) { |
| 2045 | // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed |
| 2046 | // we won't have to test for user gesture anymore and we can |
| 2047 | // move that code back to render_widget.cc |
| 2048 | if (WebUserGestureIndicator::IsProcessingUserGesture(calling_frame) && |
| 2049 | !RenderThreadImpl::current()->layout_test_mode()) { |
| 2050 | Send(new ViewHostMsg_Focus(GetRoutingID())); |
| 2051 | |
| 2052 | // Tattle on the frame that called |window.focus()|. |
| 2053 | RenderFrameImpl* calling_render_frame = |
| 2054 | RenderFrameImpl::FromWebFrame(calling_frame); |
| 2055 | if (calling_render_frame) |
| 2056 | calling_render_frame->FrameDidCallFocus(); |
| 2057 | } |
| 2058 | } |
| 2059 | |
[email protected] | 20657a8 | 2012-08-21 20:23:03 | [diff] [blame] | 2060 | #if defined(OS_ANDROID) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2061 | bool RenderViewImpl::OpenDateTimeChooser( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2062 | const blink::WebDateTimeChooserParams& params, |
| 2063 | blink::WebDateTimeChooserCompletion* completion) { |
[email protected] | e807256 | 2013-12-04 06:04:13 | [diff] [blame] | 2064 | // JavaScript may try to open a date time chooser while one is already open. |
| 2065 | if (date_time_picker_client_) |
| 2066 | return false; |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 2067 | date_time_picker_client_.reset( |
| 2068 | new RendererDateTimePicker(this, params, completion)); |
| 2069 | return date_time_picker_client_->Open(); |
| 2070 | } |
| 2071 | |
[email protected] | e807256 | 2013-12-04 06:04:13 | [diff] [blame] | 2072 | void RenderViewImpl::DismissDateTimeDialog() { |
| 2073 | DCHECK(date_time_picker_client_); |
Lei Zhang | 88f23ba | 2017-10-27 05:56:26 | [diff] [blame] | 2074 | date_time_picker_client_.reset(); |
[email protected] | e807256 | 2013-12-04 06:04:13 | [diff] [blame] | 2075 | } |
[email protected] | e807256 | 2013-12-04 06:04:13 | [diff] [blame] | 2076 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2077 | bool RenderViewImpl::DidTapMultipleTargets( |
timav | 29a8d0f6 | 2014-09-25 20:45:53 | [diff] [blame] | 2078 | const WebSize& inner_viewport_offset, |
| 2079 | const WebRect& touch_rect, |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 2080 | const WebVector<WebRect>& target_rects) { |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 2081 | // Never show a disambiguation popup when accessibility is enabled, |
| 2082 | // as this interferes with "touch exploration". |
Doug Turner | 63f3c7b | 2017-07-29 05:10:01 | [diff] [blame] | 2083 | ui::AXMode accessibility_mode = GetMainRenderFrame()->accessibility_mode(); |
| 2084 | if (accessibility_mode == ui::kAXModeComplete) |
[email protected] | 8d3dfee6 | 2013-06-19 05:50:33 | [diff] [blame] | 2085 | return false; |
| 2086 | |
timav | 29a8d0f6 | 2014-09-25 20:45:53 | [diff] [blame] | 2087 | // The touch_rect, target_rects and zoom_rect are in the outer viewport |
| 2088 | // reference frame. |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 2089 | float to_pix = |
| 2090 | IsUseZoomForDSFEnabled() ? 1 : GetWebScreenInfo().device_scale_factor; |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 2091 | gfx::Rect zoom_rect; |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 2092 | float new_total_scale = |
| 2093 | DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( |
timav | 29a8d0f6 | 2014-09-25 20:45:53 | [diff] [blame] | 2094 | touch_rect, target_rects, GetSize(), |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2095 | gfx::Rect(webview()->MainFrame()->VisibleContentRect()).size(), |
Jaebaek Seo | 6de124a | 2018-02-15 03:34:03 | [diff] [blame] | 2096 | to_pix * webview()->PageScaleFactor(), &zoom_rect); |
jbauman | 0ed0918 | 2015-01-30 22:33:49 | [diff] [blame] | 2097 | if (!new_total_scale || zoom_rect.IsEmpty()) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 2098 | return false; |
| 2099 | |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 2100 | bool handled = false; |
| 2101 | switch (renderer_preferences_.tap_multiple_targets_strategy) { |
| 2102 | case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2103 | handled = webview()->ZoomToMultipleTargetsRect(zoom_rect); |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 2104 | break; |
| 2105 | case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: { |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 2106 | gfx::Size canvas_size = |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 2107 | gfx::ScaleToCeiledSize(zoom_rect.size(), new_total_scale); |
kylechar | e7d8d5c7 | 2018-01-05 19:06:28 | [diff] [blame] | 2108 | |
| 2109 | SkImageInfo info = |
| 2110 | SkImageInfo::MakeN32Premul(canvas_size.width(), canvas_size.height()); |
| 2111 | size_t shm_size = info.computeMinByteSize(); |
| 2112 | |
| 2113 | if (shm_size == 0) { |
| 2114 | DLOG(ERROR) << "Invalid size for SharedMemory"; |
| 2115 | return false; |
| 2116 | } |
| 2117 | |
| 2118 | auto shm = ChildThreadImpl::AllocateSharedMemory(shm_size); |
| 2119 | if (!shm || !shm->Map(shm_size)) { |
| 2120 | DLOG(ERROR) << "SharedMemory allocate/map failed"; |
| 2121 | return false; |
| 2122 | } |
| 2123 | |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 2124 | { |
[email protected] | cb189e06 | 2014-04-23 00:57:01 | [diff] [blame] | 2125 | SkBitmap bitmap; |
kylechar | e7d8d5c7 | 2018-01-05 19:06:28 | [diff] [blame] | 2126 | bitmap.installPixels(info, shm->memory(), info.minRowBytes()); |
enne | 98c9f805 | 2017-03-15 19:38:22 | [diff] [blame] | 2127 | cc::SkiaPaintCanvas canvas(bitmap); |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 2128 | |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 2129 | // TODO(trchen): Cleanup the device scale factor mess. |
| 2130 | // device scale will be applied in WebKit |
| 2131 | // --> zoom_rect doesn't include device scale, |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 2132 | // but WebKit will still draw on zoom_rect * |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 2133 | // GetWebScreenInfo().device_scale_factor |
Jaebaek Seo | 6de124a | 2018-02-15 03:34:03 | [diff] [blame] | 2134 | canvas.scale(new_total_scale / to_pix, new_total_scale / to_pix); |
| 2135 | canvas.translate(-zoom_rect.x() * to_pix, -zoom_rect.y() * to_pix); |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 2136 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2137 | DCHECK(webview_->IsAcceleratedCompositingActive()); |
Chris Harrelson | c5b48e2 | 2018-01-27 03:48:06 | [diff] [blame] | 2138 | webview_->UpdateAllLifecyclePhases(); |
David Bokan | c929486 | 2018-07-17 18:39:06 | [diff] [blame] | 2139 | webview_->PaintContentIgnoringCompositing(&canvas, zoom_rect); |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 2140 | } |
| 2141 | |
timav | 29a8d0f6 | 2014-09-25 20:45:53 | [diff] [blame] | 2142 | gfx::Rect zoom_rect_in_screen = |
| 2143 | zoom_rect - gfx::Vector2d(inner_viewport_offset.width, |
| 2144 | inner_viewport_offset.height); |
| 2145 | |
[email protected] | bc2804d | 2013-08-06 07:45:49 | [diff] [blame] | 2146 | gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect( |
Jaebaek Seo | 6de124a | 2018-02-15 03:34:03 | [diff] [blame] | 2147 | gfx::ScaleRect(gfx::RectF(zoom_rect_in_screen), |
| 2148 | to_pix * webview()->PageScaleFactor())); |
timav | 29a8d0f6 | 2014-09-25 20:45:53 | [diff] [blame] | 2149 | |
kylechar | e7d8d5c7 | 2018-01-05 19:06:28 | [diff] [blame] | 2150 | // A SharedMemoryHandle is sent to the browser process, which is |
| 2151 | // responsible for freeing the shared memory when no longer needed. |
fsamuel | e8326c74 | 2016-01-12 00:49:39 | [diff] [blame] | 2152 | Send(new ViewHostMsg_ShowDisambiguationPopup( |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 2153 | GetWidget()->routing_id(), physical_window_zoom_rect, canvas_size, |
kylechar | e7d8d5c7 | 2018-01-05 19:06:28 | [diff] [blame] | 2154 | shm->TakeHandle())); |
| 2155 | |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 2156 | handled = true; |
| 2157 | break; |
| 2158 | } |
| 2159 | case TAP_MULTIPLE_TARGETS_STRATEGY_NONE: |
| 2160 | // No-op. |
| 2161 | break; |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 2162 | } |
[email protected] | 70221f0 | 2013-01-31 22:17:07 | [diff] [blame] | 2163 | |
[email protected] | 4ded1dbf | 2013-08-28 21:11:03 | [diff] [blame] | 2164 | return handled; |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 2165 | } |
braveyao | 1d8ee7b | 2017-03-29 21:10:04 | [diff] [blame] | 2166 | |
| 2167 | void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) { |
| 2168 | if (!main_render_frame_) |
| 2169 | return; |
| 2170 | |
Chandan Padhi | 26dbd9b3 | 2017-11-27 11:13:35 | [diff] [blame] | 2171 | MediaStreamDeviceObserver* media_stream_device_observer = |
| 2172 | main_render_frame_->GetMediaStreamDeviceObserver(); |
| 2173 | if (!media_stream_device_observer) |
braveyao | 1d8ee7b | 2017-03-29 21:10:04 | [diff] [blame] | 2174 | return; |
| 2175 | |
Chandan Padhi | 6dbfb73 | 2017-09-01 16:08:49 | [diff] [blame] | 2176 | MediaStreamDevices video_devices = |
Chandan Padhi | 26dbd9b3 | 2017-11-27 11:13:35 | [diff] [blame] | 2177 | media_stream_device_observer->GetNonScreenCaptureDevices(); |
braveyao | 1d8ee7b | 2017-03-29 21:10:04 | [diff] [blame] | 2178 | RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices( |
Chandan Padhi | 6dbfb73 | 2017-09-01 16:08:49 | [diff] [blame] | 2179 | video_devices, suspend); |
braveyao | 1d8ee7b | 2017-03-29 21:10:04 | [diff] [blame] | 2180 | } |
estade | 6b9696bd | 2016-05-04 23:51:36 | [diff] [blame] | 2181 | #endif // defined(OS_ANDROID) |
[email protected] | f9526d1 | 2012-10-18 01:55:03 | [diff] [blame] | 2182 | |
[email protected] | b283d29 | 2013-02-21 08:40:34 | [diff] [blame] | 2183 | unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const { |
| 2184 | return history_list_length_; |
| 2185 | } |
| 2186 | |
[email protected] | cc290f90 | 2013-03-04 20:06:02 | [diff] [blame] | 2187 | void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) { |
Nasko Oskov | a463a05 | 2018-05-08 16:42:14 | [diff] [blame] | 2188 | // If the main frame is remote, return immediately. Page level focus |
| 2189 | // should be set from the browser process, so if needed by tests it should |
| 2190 | // be properly supported. |
| 2191 | if (webview()->MainFrame()->IsWebRemoteFrame()) |
| 2192 | return; |
| 2193 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 2194 | if (enable == has_focus()) |
| 2195 | return; |
| 2196 | |
[email protected] | cc290f90 | 2013-03-04 20:06:02 | [diff] [blame] | 2197 | if (enable) { |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 2198 | SetActiveForWidget(true); |
| 2199 | // Fake an IPC message so go through the IPC handler. |
[email protected] | cc290f90 | 2013-03-04 20:06:02 | [diff] [blame] | 2200 | OnSetFocus(true); |
| 2201 | } else { |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 2202 | // Fake an IPC message so go through the IPC handler. |
[email protected] | cc290f90 | 2013-03-04 20:06:02 | [diff] [blame] | 2203 | OnSetFocus(false); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 2204 | SetActiveForWidget(false); |
[email protected] | cc290f90 | 2013-03-04 20:06:02 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | |
Daniel Cheng | 224569ee | 2018-04-25 05:45:06 | [diff] [blame] | 2208 | void RenderViewImpl::OnResolveTapDisambiguation( |
| 2209 | base::TimeTicks timestamp, |
| 2210 | const gfx::Point& tap_viewport_offset, |
| 2211 | bool is_long_press) { |
| 2212 | webview()->ResolveTapDisambiguation(timestamp, tap_viewport_offset, |
aelias | 1b55156e5 | 2017-04-01 00:46:05 | [diff] [blame] | 2213 | is_long_press); |
| 2214 | } |
| 2215 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2216 | } // namespace content |