blob: a59257a5d614e1343a48105c834b20b8bd4a9d4e [file] [log] [blame]
[email protected]b553edd52012-01-10 12:15:231// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]310ebd6302011-10-10 19:06:285#include "content/renderer/render_view_impl.h"
initial.commit09911bf2008-07-26 23:55:296
7#include <algorithm>
[email protected]b75b8292010-10-01 07:28:258#include <cmath>
dchengcedca5612016-04-09 01:40:159#include <memory>
lukasza5d0dee42017-06-14 21:57:3710#include <utility>
initial.commit09911bf2008-07-26 23:55:2911
[email protected]5d4e36d2013-02-15 15:18:2012#include "base/auto_reset.h"
[email protected]6e806822011-11-19 01:51:0813#include "base/bind.h"
14#include "base/bind_helpers.h"
initial.commit09911bf2008-07-26 23:55:2915#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5016#include "base/compiler_specific.h"
[email protected]2132d6b2013-06-05 00:15:4317#include "base/debug/alias.h"
avayvod232757942017-04-29 04:12:3418#include "base/feature_list.h"
[email protected]728c2ee2013-06-25 04:01:0719#include "base/files/file_path.h"
[email protected]edc3af82013-12-12 21:24:0720#include "base/i18n/rtl.h"
[email protected]b1cf3372011-04-20 21:28:1021#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4922#include "base/lazy_instance.h"
fdoray7a8954a42016-06-07 04:28:3823#include "base/location.h"
[email protected]f29efe6b2014-06-09 05:01:5124#include "base/metrics/field_trial.h"
[email protected]d3b4ee22013-07-24 22:50:0625#include "base/process/kill.h"
[email protected]7d08a9352013-10-15 08:24:5626#include "base/process/process.h"
fdoray7a8954a42016-06-07 04:28:3827#include "base/single_thread_task_runner.h"
danakja4ba7e52018-11-29 23:04:3128#include "base/stl_util.h"
[email protected]21aa99682013-06-11 07:17:0129#include "base/strings/string_number_conversions.h"
[email protected]b9e7c479f2013-04-12 04:33:2430#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4931#include "base/strings/string_split.h"
[email protected]21aa99682013-06-11 07:17:0132#include "base/strings/string_util.h"
[email protected]40d11e02013-03-28 17:43:1433#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0034#include "base/strings/utf_string_conversions.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0335#include "base/system/sys_info.h"
fdoray7a8954a42016-06-07 04:28:3836#include "base/threading/thread_task_runner_handle.h"
[email protected]abb522162013-06-28 01:54:1637#include "base/time/time.h"
primiano9e38d552015-01-28 04:18:0138#include "base/trace_event/trace_event.h"
avi1023d012015-12-25 02:39:1439#include "build/build_config.h"
dongseong.hwange095dfa2016-02-04 11:21:3940#include "cc/base/switches.h"
enne98c9f8052017-03-15 19:38:2241#include "cc/paint/skia_paint_canvas.h"
danakj4c987652018-07-05 15:49:4142#include "cc/trees/layer_tree_host.h"
jinho.bang632a1a722014-09-18 03:02:5643#include "content/common/content_constants_internal.h"
[email protected]59f4f2fa2011-03-23 01:00:5544#include "content/common/drag_messages.h"
[email protected]c6bc20332014-02-28 18:30:3945#include "content/common/frame_messages.h"
alexmosbc7eafa2014-12-06 01:38:0946#include "content/common/frame_replication_state.h"
[email protected]c084330e02013-04-27 01:08:1547#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0748#include "content/common/page_messages.h"
rockot5c478a72016-09-28 23:14:1849#include "content/common/render_message_filter.mojom.h"
[email protected]778574e2011-03-21 22:03:5050#include "content/common/view_messages.h"
[email protected]744c2a22012-03-15 18:42:0451#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4852#include "content/public/common/content_constants.h"
Tarun Bansal73dd2ff82017-10-03 05:29:3453#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2954#include "content/public/common/content_switches.h"
clamyda97e8322014-10-07 21:57:2555#include "content/public/common/page_state.h"
Leon Han963dc182018-11-06 05:41:4856#include "content/public/common/referrer_type_converters.h"
[email protected]818915cd2012-11-20 13:14:1157#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0358#include "content/public/common/url_constants.h"
[email protected]b3a97b52014-07-09 06:25:0559#include "content/public/common/web_preferences.h"
[email protected]d344114c2011-10-01 01:24:3460#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0761#include "content/public/renderer/document_state.h"
Avi Drissman07d22452019-03-25 17:56:3962#include "content/public/renderer/render_thread.h"
[email protected]3a034ebb2011-10-03 19:19:4463#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3664#include "content/public/renderer/render_view_visitor.h"
scottmg8e6c6082017-02-13 23:15:4865#include "content/public/renderer/window_features_converter.h"
Sadrul Habib Chowdhury31c98712018-12-11 04:15:1366#include "content/renderer/compositor/layer_tree_view.h"
[email protected]dc293a72013-07-01 11:11:2267#include "content/renderer/drop_data_builder.h"
[email protected]dc064352014-04-25 08:36:3868#include "content/renderer/history_serialization.h"
[email protected]66fca5bc2013-05-23 06:58:2969#include "content/renderer/ime_event_guard.h"
[email protected]92d457802013-04-01 19:18:4970#include "content/renderer/internal_document_state_data.h"
John Abd-El-Malek6b56ef712017-10-21 22:52:4671#include "content/renderer/loader/request_extra_data.h"
Amos Limbcc710e2018-06-08 05:51:1772#include "content/renderer/media/audio/audio_device_factory.h"
[email protected]227692c52013-05-31 22:43:0473#include "content/renderer/render_frame_impl.h"
[email protected]5a7100d2014-05-19 01:29:0474#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0575#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4476#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4477#include "content/renderer/render_widget_fullscreen_pepper.h"
Daniel Murphye3eec92c2018-02-23 19:09:1578#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]12a936d2013-05-15 04:55:4979#include "content/renderer/savable_resources.h"
John Abd-El-Malek312a30bb2017-10-23 19:51:5280#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:2181#include "content/renderer/web_ui_extension_data.h"
[email protected]f5961142013-04-17 23:09:4282#include "media/audio/audio_output_device.h"
[email protected]ee68378a2010-08-10 01:05:4183#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:4484#include "media/media_buildflags.h"
servolkf54f5c8f2015-02-24 20:32:3985#include "media/renderers/audio_renderer_impl.h"
Dale Curtis863022e2017-08-19 02:05:3486#include "media/video/gpu_video_accelerator_factories.h"
Julie Jeongeun Kimcaacf9102019-09-12 02:13:0587#include "mojo/public/cpp/bindings/pending_receiver.h"
[email protected]d1ef81d2012-07-24 11:39:3688#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2989#include "net/base/escape.h"
90#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:0991#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:0492#include "net/http/http_util.h"
Tarun Bansal73d67f02018-01-17 05:56:2593#include "net/nqe/effective_connection_type.h"
Scott Violet02e38b92018-03-27 23:42:1494#include "ppapi/buildflags/buildflags.h"
lukenb171b532014-09-24 05:50:3895#include "skia/ext/platform_canvas.h"
Blink Reformata30d4232018-04-07 15:31:0696#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
Daniel Murphy95792ef2018-10-04 01:29:5597#include "third_party/blink/public/common/dom_storage/session_storage_namespace_id.h"
Mustaq Ahmed76c2f4312018-06-07 20:48:0198#include "third_party/blink/public/common/frame/user_activation_update_source.h"
Dave Tapuska129cef82019-12-19 16:36:4899#include "third_party/blink/public/common/input/web_input_event.h"
Sergio Villar Senineb8c252452019-10-04 17:18:28100#include "third_party/blink/public/common/plugin/plugin_action.h"
Blink Reformata30d4232018-04-07 15:31:06101#include "third_party/blink/public/platform/file_path_conversion.h"
Antonio Gomes925f9b92019-07-30 23:23:23102#include "third_party/blink/public/platform/modules/video_capture/web_video_capture_impl_manager.h"
Blink Reformata30d4232018-04-07 15:31:06103#include "third_party/blink/public/platform/url_conversion.h"
104#include "third_party/blink/public/platform/web_connection_type.h"
105#include "third_party/blink/public/platform/web_effective_connection_type.h"
106#include "third_party/blink/public/platform/web_http_body.h"
Blink Reformata30d4232018-04-07 15:31:06107#include "third_party/blink/public/platform/web_input_event_result.h"
108#include "third_party/blink/public/platform/web_network_state_notifier.h"
Blink Reformata30d4232018-04-07 15:31:06109#include "third_party/blink/public/platform/web_rect.h"
110#include "third_party/blink/public/platform/web_runtime_features.h"
111#include "third_party/blink/public/platform/web_size.h"
112#include "third_party/blink/public/platform/web_string.h"
W. James MacLean62198672019-06-04 16:46:10113#include "third_party/blink/public/platform/web_text_autosizer_page_info.h"
Blink Reformata30d4232018-04-07 15:31:06114#include "third_party/blink/public/platform/web_url.h"
115#include "third_party/blink/public/platform/web_url_error.h"
116#include "third_party/blink/public/platform/web_url_request.h"
117#include "third_party/blink/public/platform/web_url_response.h"
118#include "third_party/blink/public/platform/web_vector.h"
119#include "third_party/blink/public/public_buildflags.h"
Guido Urdanetadc7090372019-07-29 17:59:54120#include "third_party/blink/public/web/modules/mediastream/web_media_stream_device_observer.h"
Blink Reformata30d4232018-04-07 15:31:06121#include "third_party/blink/public/web/web_autofill_client.h"
122#include "third_party/blink/public/web/web_ax_object.h"
Blink Reformata30d4232018-04-07 15:31:06123#include "third_party/blink/public/web/web_document.h"
124#include "third_party/blink/public/web/web_dom_event.h"
125#include "third_party/blink/public/web/web_dom_message_event.h"
126#include "third_party/blink/public/web/web_element.h"
Blink Reformata30d4232018-04-07 15:31:06127#include "third_party/blink/public/web/web_form_control_element.h"
128#include "third_party/blink/public/web/web_form_element.h"
129#include "third_party/blink/public/web/web_frame.h"
130#include "third_party/blink/public/web/web_frame_content_dumper.h"
131#include "third_party/blink/public/web/web_frame_widget.h"
132#include "third_party/blink/public/web/web_history_item.h"
133#include "third_party/blink/public/web/web_hit_test_result.h"
134#include "third_party/blink/public/web/web_input_element.h"
135#include "third_party/blink/public/web/web_local_frame.h"
Blink Reformata30d4232018-04-07 15:31:06136#include "third_party/blink/public/web/web_navigation_policy.h"
danakj25ec6e2b2018-09-26 17:01:31137#include "third_party/blink/public/web/web_page_popup.h"
Blink Reformata30d4232018-04-07 15:31:06138#include "third_party/blink/public/web/web_plugin.h"
Blink Reformata30d4232018-04-07 15:31:06139#include "third_party/blink/public/web/web_range.h"
140#include "third_party/blink/public/web/web_render_theme.h"
141#include "third_party/blink/public/web/web_script_source.h"
142#include "third_party/blink/public/web/web_searchable_form_data.h"
143#include "third_party/blink/public/web/web_security_policy.h"
144#include "third_party/blink/public/web/web_settings.h"
Blink Reformata30d4232018-04-07 15:31:06145#include "third_party/blink/public/web/web_view.h"
146#include "third_party/blink/public/web/web_window_features.h"
[email protected]b3a97b52014-07-09 06:25:05147#include "third_party/icu/source/common/unicode/uchar.h"
148#include "third_party/icu/source/common/unicode/uscript.h"
esecklerf2bd55f72017-03-31 09:11:57149#include "third_party/skia/include/core/SkColor.h"
Ionel Popescu2649f2f2020-01-10 10:06:59150#include "ui/base/ui_base_features.h"
[email protected]1400e6dc2013-04-27 02:36:27151#include "ui/base/ui_base_switches_util.h"
tfarina655f81d2014-12-23 02:38:50152#include "ui/gfx/geometry/point.h"
tfarina3b0452d2014-12-31 15:20:09153#include "ui/gfx/geometry/rect.h"
154#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32155#include "ui/gfx/geometry/size_conversions.h"
[email protected]08397d52011-02-05 01:53:38156#include "ui/gfx/native_widget_types.h"
ccameron772317d2017-06-04 18:35:03157#include "ui/gfx/switches.h"
mfomitchev3ba450ad2017-04-03 18:20:40158#include "ui/latency/latency_info.h"
csharrisond88f9752016-10-26 23:56:36159#include "url/origin.h"
markdittmer67b71ea2016-03-03 22:40:03160#include "url/url_constants.h"
[email protected]c4a9e932011-03-05 04:05:55161#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:29162
[email protected]25fb9b32012-04-27 03:21:55163#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25164#include <cpu-features.h>
165
dalecurtiscd971252016-09-21 16:09:00166#include "base/android/build_info.h"
kylechare7d8d5c72018-01-05 19:06:28167#include "content/child/child_thread_impl.h"
tfarina3b0452d2014-12-31 15:20:09168#include "ui/gfx/geometry/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40169
[email protected]78043bdd2010-04-05 18:45:33170#elif defined(OS_MACOSX)
171#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57172#endif
173
brettw4b461082016-11-19 18:55:16174#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]ea2fb972013-08-07 05:44:26175#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
176#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26177#endif
178
Sergio Villar Senineb8c252452019-10-04 17:18:28179using blink::PluginAction;
[email protected]180ef242013-11-07 06:50:46180using blink::WebAXObject;
[email protected]180ef242013-11-07 06:50:46181using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46182using blink::WebData;
[email protected]180ef242013-11-07 06:50:46183using blink::WebDocument;
[email protected]180ef242013-11-07 06:50:46184using blink::WebDragOperation;
[email protected]180ef242013-11-07 06:50:46185using blink::WebElement;
[email protected]180ef242013-11-07 06:50:46186using blink::WebFormControlElement;
187using blink::WebFormElement;
188using blink::WebFrame;
dglazkov03223492016-02-08 22:16:03189using blink::WebFrameContentDumper;
[email protected]180ef242013-11-07 06:50:46190using blink::WebGestureEvent;
191using blink::WebHistoryItem;
dglazkov8d0c21dd2016-08-06 15:56:36192using blink::WebHitTestResult;
Sergio Villar Senineb8c252452019-10-04 17:18:28193using blink::WebHTTPBody;
[email protected]180ef242013-11-07 06:50:46194using blink::WebInputElement;
195using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22196using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46197using blink::WebMouseEvent;
198using blink::WebNavigationPolicy;
199using blink::WebNavigationType;
200using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46201using blink::WebRect;
Sergio Villar Senineb8c252452019-10-04 17:18:28202using blink::WebRuntimeFeatures;
[email protected]180ef242013-11-07 06:50:46203using blink::WebScriptSource;
204using blink::WebSearchableFormData;
205using blink::WebSecurityOrigin;
206using blink::WebSecurityPolicy;
[email protected]180ef242013-11-07 06:50:46207using blink::WebSettings;
208using blink::WebSize;
[email protected]180ef242013-11-07 06:50:46209using blink::WebString;
[email protected]180ef242013-11-07 06:50:46210using blink::WebTouchEvent;
211using blink::WebURL;
212using blink::WebURLError;
213using blink::WebURLRequest;
214using blink::WebURLResponse;
[email protected]180ef242013-11-07 06:50:46215using blink::WebVector;
216using blink::WebView;
217using blink::WebWidget;
218using blink::WebWindowFeatures;
[email protected]e1acf6f2008-10-27 20:43:33219
[email protected]e9ff79c2012-10-19 21:31:26220namespace content {
221
initial.commit09911bf2008-07-26 23:55:29222//-----------------------------------------------------------------------------
223
[email protected]180ef242013-11-07 06:50:46224typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
jbroman8319b232017-03-08 22:53:29225static base::LazyInstance<ViewMap>::Leaky g_view_map =
[email protected]058561b2012-12-03 06:48:22226 LAZY_INSTANCE_INITIALIZER;
scottmg5e65e3a2017-03-08 08:48:46227typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap;
jbroman8319b232017-03-08 22:53:29228static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map =
229 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02230
[email protected]882daa92009-11-05 16:31:31231// Time, in seconds, we delay before sending content state changes (such as form
232// state and scroll position) to the browser. We delay sending changes to avoid
233// spamming the browser.
234// To avoid having tab/session restore require sending a message to get the
235// current content state during tab closing we use a shorter timeout for the
236// foreground renderer. This means there is a small window of time from which
237// content state is modified and not sent to session restore, but this is
238// better than having to wake up all renderers during shutdown.
avif937e1d2014-11-02 18:13:07239const int kDelaySecondsForContentStateSyncHidden = 5;
240const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29241
dcheng35d31c112015-07-22 00:17:36242static RenderViewImpl* (*g_create_render_view_impl)(
243 CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15244 const mojom::CreateViewParams&) = nullptr;
[email protected]8d41d7612012-11-14 20:32:19245
[email protected]c6bc20332014-02-28 18:30:39246// static
[email protected]65920f332014-03-04 21:14:18247WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32248 WebNavigationPolicy policy) {
249 switch (policy) {
Blink Reformat1c4d759e2017-04-09 16:34:54250 case blink::kWebNavigationPolicyDownload:
nick3b04f322016-08-31 19:29:19251 return WindowOpenDisposition::SAVE_TO_DISK;
Blink Reformat1c4d759e2017-04-09 16:34:54252 case blink::kWebNavigationPolicyCurrentTab:
nick3b04f322016-08-31 19:29:19253 return WindowOpenDisposition::CURRENT_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54254 case blink::kWebNavigationPolicyNewBackgroundTab:
nick3b04f322016-08-31 19:29:19255 return WindowOpenDisposition::NEW_BACKGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54256 case blink::kWebNavigationPolicyNewForegroundTab:
nick3b04f322016-08-31 19:29:19257 return WindowOpenDisposition::NEW_FOREGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54258 case blink::kWebNavigationPolicyNewWindow:
nick3b04f322016-08-31 19:29:19259 return WindowOpenDisposition::NEW_WINDOW;
Blink Reformat1c4d759e2017-04-09 16:34:54260 case blink::kWebNavigationPolicyNewPopup:
nick3b04f322016-08-31 19:29:19261 return WindowOpenDisposition::NEW_POPUP;
[email protected]48861e22013-01-09 00:27:32262 default:
263 NOTREACHED() << "Unexpected WebNavigationPolicy";
nick3b04f322016-08-31 19:29:19264 return WindowOpenDisposition::IGNORE_ACTION;
[email protected]48861e22013-01-09 00:27:32265 }
266}
267
initial.commit09911bf2008-07-26 23:55:29268///////////////////////////////////////////////////////////////////////////////
269
[email protected]217690d2012-01-27 07:33:11270namespace {
271
[email protected]b3a97b52014-07-09 06:25:05272typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
273 const base::string16&,
274 UScriptCode);
275
276void SetStandardFontFamilyWrapper(WebSettings* settings,
277 const base::string16& font,
278 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54279 settings->SetStandardFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05280}
281
282void SetFixedFontFamilyWrapper(WebSettings* settings,
283 const base::string16& font,
284 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54285 settings->SetFixedFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05286}
287
288void SetSerifFontFamilyWrapper(WebSettings* settings,
289 const base::string16& font,
290 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54291 settings->SetSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05292}
293
294void SetSansSerifFontFamilyWrapper(WebSettings* settings,
295 const base::string16& font,
296 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54297 settings->SetSansSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05298}
299
300void SetCursiveFontFamilyWrapper(WebSettings* settings,
301 const base::string16& font,
302 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54303 settings->SetCursiveFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05304}
305
306void SetFantasyFontFamilyWrapper(WebSettings* settings,
307 const base::string16& font,
308 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54309 settings->SetFantasyFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05310}
311
312void SetPictographFontFamilyWrapper(WebSettings* settings,
313 const base::string16& font,
314 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54315 settings->SetPictographFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05316}
317
318// If |scriptCode| is a member of a family of "similar" script codes, returns
319// the script code in that family that is used by WebKit for font selection
320// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
321// considered equivalent for the purposes of font selection. WebKit uses the
322// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
323// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
324// uses different scripts than the ones in Chrome pref names because the version
325// of ICU included on certain ports does not have some of the newer scripts. If
326// |scriptCode| is not a member of such a family, returns |scriptCode|.
327UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
328 switch (scriptCode) {
329 case USCRIPT_HIRAGANA:
330 case USCRIPT_KATAKANA:
331 case USCRIPT_JAPANESE:
332 return USCRIPT_KATAKANA_OR_HIRAGANA;
333 case USCRIPT_KOREAN:
334 return USCRIPT_HANGUL;
335 default:
336 return scriptCode;
337 }
338}
339
340void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
341 SetFontFamilyWrapper setter,
342 WebSettings* settings) {
jdoerrie5a73d0fa2018-10-02 23:54:05343 for (auto it = map.begin(); it != map.end(); ++it) {
avi1023d012015-12-25 02:39:14344 int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
[email protected]b3a97b52014-07-09 06:25:05345 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
346 UScriptCode code = static_cast<UScriptCode>(script);
347 (*setter)(settings, it->second, GetScriptForWebSettings(code));
348 }
349 }
350}
351
danakjefcb8432019-01-16 18:47:14352void ApplyCommandLineToSettings(WebSettings* settings) {
353 const base::CommandLine& command_line =
354 *base::CommandLine::ForCurrentProcess();
355
danakjed9464612019-01-16 00:00:59356 settings->SetThreadedScrollingEnabled(
357 !command_line.HasSwitch(switches::kDisableThreadedScrolling));
wangxianzhu3bf39be52015-04-10 23:56:41358
danakjed9464612019-01-16 00:00:59359 if (switches::IsTouchDragDropEnabled())
360 settings->SetTouchDragDropEnabled(true);
361
362 WebSettings::SelectionStrategyType selection_strategy;
363 if (command_line.GetSwitchValueASCII(switches::kTouchTextSelectionStrategy) ==
364 "direction")
365 selection_strategy = WebSettings::SelectionStrategyType::kDirection;
366 else
367 selection_strategy = WebSettings::SelectionStrategyType::kCharacter;
368 settings->SetSelectionStrategy(selection_strategy);
369
370 std::string passive_listeners_default =
371 command_line.GetSwitchValueASCII(switches::kPassiveListenersDefault);
372 if (!passive_listeners_default.empty()) {
373 WebSettings::PassiveEventListenerDefault passive_default =
374 WebSettings::PassiveEventListenerDefault::kFalse;
375 if (passive_listeners_default == "true")
376 passive_default = WebSettings::PassiveEventListenerDefault::kTrue;
377 else if (passive_listeners_default == "forcealltrue")
378 passive_default = WebSettings::PassiveEventListenerDefault::kForceAllTrue;
379 settings->SetPassiveEventListenerDefault(passive_default);
380 }
381
382 std::string network_quiet_timeout =
383 command_line.GetSwitchValueASCII(switches::kNetworkQuietTimeout);
384 if (!network_quiet_timeout.empty()) {
385 double network_quiet_timeout_seconds = 0.0;
386 if (base::StringToDouble(network_quiet_timeout,
387 &network_quiet_timeout_seconds))
388 settings->SetNetworkQuietTimeout(network_quiet_timeout_seconds);
389 }
390
391 if (command_line.HasSwitch(switches::kBlinkSettings)) {
392 std::vector<std::string> blink_settings = base::SplitString(
393 command_line.GetSwitchValueASCII(switches::kBlinkSettings), ",",
394 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
395 for (const std::string& setting : blink_settings) {
396 size_t pos = setting.find('=');
397 settings->SetFromStrings(
398 blink::WebString::FromLatin1(setting.substr(0, pos)),
399 blink::WebString::FromLatin1(
400 pos == std::string::npos ? "" : setting.substr(pos + 1)));
401 }
wangxianzhu3bf39be52015-04-10 23:56:41402 }
403}
404
scottmgde42fb92017-02-10 17:56:03405content::mojom::WindowContainerType WindowFeaturesToContainerType(
scottmg05324cb2017-02-09 23:46:04406 const blink::WebWindowFeatures& window_features) {
japhetbfc47892017-06-02 23:01:19407 if (window_features.background) {
408 if (window_features.persistent)
scottmgde42fb92017-02-10 17:56:03409 return content::mojom::WindowContainerType::PERSISTENT;
scottmg05324cb2017-02-09 23:46:04410 else
scottmgde42fb92017-02-10 17:56:03411 return content::mojom::WindowContainerType::BACKGROUND;
scottmg05324cb2017-02-09 23:46:04412 } else {
scottmgde42fb92017-02-10 17:56:03413 return content::mojom::WindowContainerType::NORMAL;
scottmg05324cb2017-02-09 23:46:04414 }
415}
416
[email protected]217690d2012-01-27 07:33:11417} // namespace
418
Hajime Hoshi315a61f2018-08-14 17:27:28419RenderViewImpl::RenderViewImpl(CompositorDependencies* compositor_deps,
420 const mojom::CreateViewParams& params)
Albert J. Wong7faa3da2019-03-21 20:43:43421 : routing_id_(params.view_id),
danakj73dd3032018-07-28 17:49:53422 renderer_wide_named_frame_lookup_(
423 params.renderer_wide_named_frame_lookup),
danakj77eb7e82020-01-09 19:38:46424 widgets_never_composited_(params.never_composited),
danakj4b8a2d9a2019-10-15 15:53:59425 compositor_deps_(compositor_deps),
naskobd911332014-11-25 01:13:36426 webkit_preferences_(params.web_preferences),
Jeremy Roman3bca4bf2019-07-11 03:41:25427 session_storage_namespace_id_(params.session_storage_namespace_id) {
Daniel Murphy95792ef2018-10-04 01:29:55428 DCHECK(!session_storage_namespace_id_.empty())
429 << "Session storage namespace must be populated.";
Albert J. Wong7faa3da2019-03-21 20:43:43430 // Please put all logic in RenderViewImpl::Initialize().
431}
Albert J. Wong7bbf22d2018-12-20 00:27:27432
Albert J. Wong7faa3da2019-03-21 20:43:43433void RenderViewImpl::Initialize(
Erik Chen10e9b022019-08-21 23:33:23434 CompositorDependencies* compositor_deps,
Albert J. Wong7faa3da2019-03-21 20:43:43435 mojom::CreateViewParamsPtr params,
436 RenderWidget::ShowCallback show_callback,
437 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Avi Drissman07d22452019-03-25 17:56:39438 DCHECK(RenderThread::IsMainThread());
439
Albert J. Wongcb004632018-07-10 22:58:25440 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]075366912013-02-18 07:13:24441
nickf7b38222016-11-22 21:59:35442#if defined(OS_ANDROID)
danakjc87bfede2018-10-10 22:32:49443 bool has_show_callback = !!show_callback;
nickf7b38222016-11-22 21:59:35444#endif
[email protected]676126f72011-01-15 00:03:51445
Lukasz Anforowiczaf2f33572018-01-17 14:05:08446 WebFrame* opener_frame =
447 RenderFrameImpl::ResolveOpener(params->opener_frame_route_id);
448
Erik Chen562ca42b2019-08-22 19:46:06449 // The newly created webview_ is owned by this instance.
danakj284d557d2019-01-16 17:00:26450 webview_ = WebView::Create(this, params->hidden,
Sadrul Habib Chowdhury042a4712018-12-06 00:16:56451 /*compositing_enabled=*/true,
danakja4ba7e52018-11-29 23:04:31452 opener_frame ? opener_frame->View() : nullptr);
Albert J. Wong2727e8a82019-02-15 16:56:11453
nasko4c0feb62015-06-05 18:37:06454 g_view_map.Get().insert(std::make_pair(webview(), this));
avia3dca182016-03-19 01:09:52455 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this));
nasko4c0feb62015-06-05 18:37:06456
danakj242c2e12019-10-08 16:34:15457 bool local_main_frame = params->main_frame_routing_id != MSG_ROUTING_NONE;
458
459 // TODO(danakj): Put this in with making the RenderFrame? Does order matter?
460 if (local_main_frame)
461 webview()->SetDisplayMode(params->visual_properties.display_mode);
dcheng0ff94cfc2016-03-15 21:50:51462
danakjfd0c7f42018-10-12 18:01:08463 ApplyWebPreferences(webkit_preferences_, webview());
danakjefcb8432019-01-16 18:47:14464 ApplyCommandLineToSettings(webview()->GetSettings());
dcheng0ff94cfc2016-03-15 21:50:51465
danakj242c2e12019-10-08 16:34:15466 if (local_main_frame) {
dcheng3ce04b62015-10-26 23:30:55467 main_render_frame_ = RenderFrameImpl::CreateMainFrame(
Erik Chen10e9b022019-08-21 23:33:23468 this, compositor_deps, opener_frame, &params, std::move(show_callback));
danakjaf29226f2018-09-25 17:56:57469 } else {
Balazs Engedyba034e72017-10-27 22:26:28470 RenderFrameProxy::CreateFrameProxy(params->proxy_routing_id, GetRoutingID(),
nick3b5a21f2016-11-22 23:07:11471 opener_frame, MSG_ROUTING_NONE,
Dmitry Gozman89361212018-02-13 16:10:44472 params->replicated_frame_state,
473 params->devtools_main_frame_token);
nasko4c0feb62015-06-05 18:37:06474 }
475
[email protected]c7c0d822014-04-16 20:19:49476 // TODO(davidben): Move this state from Blink into content.
Balazs Engedyba034e72017-10-27 22:26:28477 if (params->window_was_created_with_opener)
Blink Reformat1c4d759e2017-04-09 16:34:54478 webview()->SetOpenedByDOM();
[email protected]c7c0d822014-04-16 20:19:49479
Leon Han2c81b5d2019-01-25 01:58:33480 OnSetRendererPrefs(*params->renderer_preferences);
[email protected]1784b2f2011-11-24 10:53:48481
[email protected]e9ff79c2012-10-19 21:31:26482 GetContentClient()->renderer()->RenderViewCreated(this);
Hajime Hoshif34374412018-03-05 14:32:54483
484 nav_state_sync_timer_.SetTaskRunner(task_runner);
danakjc87bfede2018-10-10 22:32:49485
Adithya Srinivasan46b8a792019-02-01 14:47:23486 // We pass this state to Page, but it's only used by the main frame in the
487 // page.
488 if (params->inside_portal)
489 webview()->SetInsidePortal(true);
490
danakjc87bfede2018-10-10 22:32:49491#if defined(OS_ANDROID)
492 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated
493 // HandleNavigation codepath.
494 // Renderer-created RenderViews have a ShowCallback because they send a Show
495 // request (ViewHostMsg_ShowWidget, ViewHostMsg_ShowFullscreenWidget, or
496 // FrameHostMsg_ShowCreatedWindow) to the browser to attach them to the UI
497 // there. Browser-created RenderViews do not send a Show request to the
498 // browser, so have no such callback.
499 was_created_by_renderer_ = has_show_callback;
500#endif
initial.commit09911bf2008-07-26 23:55:29501}
502
[email protected]310ebd6302011-10-10 19:06:28503RenderViewImpl::~RenderViewImpl() {
danakjcdfc4262019-10-01 20:09:48504 DCHECK(destroying_); // Always deleted through Destroy().
danakjcdfc4262019-10-01 20:09:48505
506 g_routing_id_view_map.Get().erase(routing_id_);
Albert J. Wongcb004632018-07-10 22:58:25507 RenderThread::Get()->RemoveRoute(routing_id_);
dcheng3ce04b62015-10-26 23:30:55508
[email protected]60c42a8c72009-10-09 04:08:59509#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22510 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49511 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59512 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
513 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22514 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
515 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
516 it != routing_id_views->end(); ++it)
517 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59518#endif
[email protected]676126f72011-01-15 00:03:51519
ericwilligers88e69742016-10-17 19:29:55520 for (auto& observer : observers_)
521 observer.RenderViewGone();
522 for (auto& observer : observers_)
523 observer.OnDestruct();
[email protected]60c42a8c72009-10-09 04:08:59524}
525
526/*static*/
[email protected]310ebd6302011-10-10 19:06:28527RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
Avi Drissman07d22452019-03-25 17:56:39528 DCHECK(RenderThread::IsMainThread());
[email protected]a2ef54c2011-10-10 16:20:31529 ViewMap* views = g_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05530 auto it = views->find(webview);
[email protected]a2ef54c2011-10-10 16:20:31531 return it == views->end() ? NULL : it->second;
532}
533
534/*static*/
[email protected]180ef242013-11-07 06:50:46535RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28536 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31537}
538
539/*static*/
avi1023d012015-12-25 02:39:14540RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) {
Avi Drissman07d22452019-03-25 17:56:39541 DCHECK(RenderThread::IsMainThread());
[email protected]640e303c2012-12-05 01:36:07542 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05543 auto it = views->find(routing_id);
[email protected]640e303c2012-12-05 01:36:07544 return it == views->end() ? NULL : it->second;
545}
546
547/*static*/
548RenderView* RenderView::FromRoutingID(int routing_id) {
549 return RenderViewImpl::FromRoutingID(routing_id);
550}
551
[email protected]f3a95312014-06-12 16:46:58552/* static */
jochen9c7b8f242015-06-01 15:32:02553size_t RenderView::GetRenderViewCount() {
[email protected]f3a95312014-06-12 16:46:58554 return g_view_map.Get().size();
555}
556
[email protected]640e303c2012-12-05 01:36:07557/*static*/
[email protected]e9ff79c2012-10-19 21:31:26558void RenderView::ForEach(RenderViewVisitor* visitor) {
Avi Drissman07d22452019-03-25 17:56:39559 DCHECK(RenderThread::IsMainThread());
[email protected]625332e02010-12-14 07:48:49560 ViewMap* views = g_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05561 for (auto it = views->begin(); it != views->end(); ++it) {
[email protected]60c42a8c72009-10-09 04:08:59562 if (!visitor->Visit(it->second))
563 return;
564 }
565}
566
567/*static*/
[email protected]b3a97b52014-07-09 06:25:05568void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
569 WebView* web_view) {
Blink Reformat1c4d759e2017-04-09 16:34:54570 WebSettings* settings = web_view->GetSettings();
[email protected]b3a97b52014-07-09 06:25:05571 ApplyFontsFromMap(prefs.standard_font_family_map,
572 SetStandardFontFamilyWrapper, settings);
573 ApplyFontsFromMap(prefs.fixed_font_family_map,
574 SetFixedFontFamilyWrapper, settings);
575 ApplyFontsFromMap(prefs.serif_font_family_map,
576 SetSerifFontFamilyWrapper, settings);
577 ApplyFontsFromMap(prefs.sans_serif_font_family_map,
578 SetSansSerifFontFamilyWrapper, settings);
579 ApplyFontsFromMap(prefs.cursive_font_family_map,
580 SetCursiveFontFamilyWrapper, settings);
581 ApplyFontsFromMap(prefs.fantasy_font_family_map,
582 SetFantasyFontFamilyWrapper, settings);
583 ApplyFontsFromMap(prefs.pictograph_font_family_map,
584 SetPictographFontFamilyWrapper, settings);
Blink Reformat1c4d759e2017-04-09 16:34:54585 settings->SetDefaultFontSize(prefs.default_font_size);
586 settings->SetDefaultFixedFontSize(prefs.default_fixed_font_size);
587 settings->SetMinimumFontSize(prefs.minimum_font_size);
588 settings->SetMinimumLogicalFontSize(prefs.minimum_logical_font_size);
589 settings->SetDefaultTextEncodingName(
590 WebString::FromASCII(prefs.default_encoding));
591 settings->SetJavaScriptEnabled(prefs.javascript_enabled);
592 settings->SetWebSecurityEnabled(prefs.web_security_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54593 settings->SetLoadsImagesAutomatically(prefs.loads_images_automatically);
594 settings->SetImagesEnabled(prefs.images_enabled);
595 settings->SetPluginsEnabled(prefs.plugins_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54596 settings->SetDOMPasteAllowed(prefs.dom_paste_enabled);
597 settings->SetTextAreasAreResizable(prefs.text_areas_are_resizable);
598 settings->SetAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
599 settings->SetDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
600 settings->SetJavaScriptCanAccessClipboard(
[email protected]b3a97b52014-07-09 06:25:05601 prefs.javascript_can_access_clipboard);
Chris Cunninghame9b5ad742019-04-23 19:40:38602 WebRuntimeFeatures::EnableXSLT(prefs.xslt_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54603 settings->SetDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
Tarun Bansal333819e2018-05-15 16:38:42604 blink::WebNetworkStateNotifier::SetSaveDataEnabled(prefs.data_saver_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54605 settings->SetLocalStorageEnabled(prefs.local_storage_enabled);
606 settings->SetSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
607 WebRuntimeFeatures::EnableDatabase(prefs.databases_enabled);
608 settings->SetOfflineWebApplicationCacheEnabled(
[email protected]b3a97b52014-07-09 06:25:05609 prefs.application_cache_enabled);
Arthur Sonzogni721f48e2018-10-31 17:10:02610 settings->SetShouldProtectAgainstIpcFlooding(
611 !prefs.disable_ipc_flooding_protection);
Blink Reformat1c4d759e2017-04-09 16:34:54612 settings->SetHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
613 settings->SetCookieEnabled(prefs.cookie_enabled);
614 settings->SetNavigateOnDragDrop(prefs.navigate_on_drag_drop);
[email protected]b3a97b52014-07-09 06:25:05615
[email protected]b3a97b52014-07-09 06:25:05616 // By default, allow_universal_access_from_file_urls is set to false and thus
617 // we mitigate attacks from local HTML files by not granting file:// URLs
618 // universal access. Only test shell will enable this.
Blink Reformat1c4d759e2017-04-09 16:34:54619 settings->SetAllowUniversalAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05620 prefs.allow_universal_access_from_file_urls);
Blink Reformat1c4d759e2017-04-09 16:34:54621 settings->SetAllowFileAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05622 prefs.allow_file_access_from_file_urls);
623
Zhenyao Moa3fda9972017-09-16 01:34:40624 settings->SetWebGL1Enabled(prefs.webgl1_enabled);
625 settings->SetWebGL2Enabled(prefs.webgl2_enabled);
[email protected]b3a97b52014-07-09 06:25:05626
[email protected]b3a97b52014-07-09 06:25:05627 // Enable WebGL errors to the JS console if requested.
Blink Reformat1c4d759e2017-04-09 16:34:54628 settings->SetWebGLErrorsToConsoleEnabled(
[email protected]b3a97b52014-07-09 06:25:05629 prefs.webgl_errors_to_console_enabled);
630
Blink Reformat1c4d759e2017-04-09 16:34:54631 settings->SetHideScrollbars(prefs.hide_scrollbars);
eseckler61ff9142016-09-23 22:57:59632
[email protected]b3a97b52014-07-09 06:25:05633 // Enable gpu-accelerated 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54634 WebRuntimeFeatures::EnableAccelerated2dCanvas(
junov524668f22016-08-08 20:16:52635 prefs.accelerated_2d_canvas_enabled);
[email protected]b3a97b52014-07-09 06:25:05636
[email protected]b3a97b52014-07-09 06:25:05637 // Disable antialiasing for 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54638 settings->SetAntialiased2dCanvasEnabled(
[email protected]b3a97b52014-07-09 06:25:05639 !prefs.antialiased_2d_canvas_disabled);
640
zakerinasab20ebca02016-09-27 14:22:34641 // Disable antialiasing of clips for 2d canvas if requested on the command
robertphillipse25137b2014-10-20 13:44:34642 // line.
Blink Reformat1c4d759e2017-04-09 16:34:54643 settings->SetAntialiasedClips2dCanvasEnabled(
robertphillipse25137b2014-10-20 13:44:34644 prefs.antialiased_clips_2d_canvas_enabled);
645
[email protected]b3a97b52014-07-09 06:25:05646 // Set MSAA sample count for 2d canvas if requested on the command line (or
647 // default value if not).
Blink Reformat1c4d759e2017-04-09 16:34:54648 settings->SetAccelerated2dCanvasMSAASampleCount(
[email protected]b3a97b52014-07-09 06:25:05649 prefs.accelerated_2d_canvas_msaa_sample_count);
650
[email protected]b3a97b52014-07-09 06:25:05651 // Tabs to link is not part of the settings. WebCore calls
652 // ChromeClient::tabsToLinks which is part of the glue code.
Blink Reformat1c4d759e2017-04-09 16:34:54653 web_view->SetTabsToLinks(prefs.tabs_to_links);
[email protected]b3a97b52014-07-09 06:25:05654
Blink Reformat1c4d759e2017-04-09 16:34:54655 settings->SetAllowRunningOfInsecureContent(
[email protected]b3a97b52014-07-09 06:25:05656 prefs.allow_running_insecure_content);
Blink Reformat1c4d759e2017-04-09 16:34:54657 settings->SetDisableReadingFromCanvas(prefs.disable_reading_from_canvas);
658 settings->SetStrictMixedContentChecking(prefs.strict_mixed_content_checking);
mkwst2384c8222015-07-30 07:26:47659
Blink Reformat1c4d759e2017-04-09 16:34:54660 settings->SetStrictlyBlockBlockableMixedContent(
mkwst2384c8222015-07-30 07:26:47661 prefs.strictly_block_blockable_mixed_content);
662
Blink Reformat1c4d759e2017-04-09 16:34:54663 settings->SetStrictMixedContentCheckingForPlugin(
mkwst0d233e52015-08-10 09:33:14664 prefs.block_mixed_plugin_content);
665
Blink Reformat1c4d759e2017-04-09 16:34:54666 settings->SetStrictPowerfulFeatureRestrictions(
mkwst673a452f2015-01-10 14:41:50667 prefs.strict_powerful_feature_restrictions);
Blink Reformat1c4d759e2017-04-09 16:34:54668 settings->SetAllowGeolocationOnInsecureOrigins(
jww9d4ca2d2016-01-19 20:58:59669 prefs.allow_geolocation_on_insecure_origins);
Blink Reformat1c4d759e2017-04-09 16:34:54670 settings->SetPasswordEchoEnabled(prefs.password_echo_enabled);
671 settings->SetShouldPrintBackgrounds(prefs.should_print_backgrounds);
672 settings->SetShouldClearDocumentBackground(
[email protected]b3a97b52014-07-09 06:25:05673 prefs.should_clear_document_background);
Blink Reformat1c4d759e2017-04-09 16:34:54674 settings->SetEnableScrollAnimator(prefs.enable_scroll_animator);
Stephen McGruerbc3d0e62019-01-23 17:40:19675 settings->SetPrefersReducedMotion(prefs.prefers_reduced_motion);
[email protected]b3a97b52014-07-09 06:25:05676
Blink Reformat1c4d759e2017-04-09 16:34:54677 WebRuntimeFeatures::EnableTouchEventFeatureDetection(
sunyunjiafa6a8afc2016-12-09 04:25:47678 prefs.touch_event_feature_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54679 settings->SetMaxTouchPoints(prefs.pointer_events_max_touch_points);
680 settings->SetAvailablePointerTypes(prefs.available_pointer_types);
681 settings->SetPrimaryPointerType(
nzolghadrc0d1663c2015-11-26 21:15:24682 static_cast<blink::PointerType>(prefs.primary_pointer_type));
Blink Reformat1c4d759e2017-04-09 16:34:54683 settings->SetAvailableHoverTypes(prefs.available_hover_types);
684 settings->SetPrimaryHoverType(
nzolghadrc0d1663c2015-11-26 21:15:24685 static_cast<blink::HoverType>(prefs.primary_hover_type));
Blink Reformat1c4d759e2017-04-09 16:34:54686 settings->SetEnableTouchAdjustment(prefs.touch_adjustment_enabled);
Dave Tapuskaa59fdb62017-08-23 16:28:27687 settings->SetBarrelButtonForDragEnabled(prefs.barrel_button_for_drag_enabled);
[email protected]b3a97b52014-07-09 06:25:05688
Blink Reformat1c4d759e2017-04-09 16:34:54689 settings->SetShouldRespectImageOrientation(
[email protected]b3a97b52014-07-09 06:25:05690 prefs.should_respect_image_orientation);
691
Blink Reformat1c4d759e2017-04-09 16:34:54692 settings->SetEditingBehavior(
[email protected]b3a97b52014-07-09 06:25:05693 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
694
Blink Reformat1c4d759e2017-04-09 16:34:54695 settings->SetSupportsMultipleWindows(prefs.supports_multiple_windows);
[email protected]b3a97b52014-07-09 06:25:05696
Blink Reformat1c4d759e2017-04-09 16:34:54697 settings->SetMainFrameClipsContent(!prefs.record_whole_document);
khushalsagar2da2b232016-03-23 22:11:35698
Blink Reformat1c4d759e2017-04-09 16:34:54699 settings->SetSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
[email protected]b3a97b52014-07-09 06:25:05700
Blink Reformat1c4d759e2017-04-09 16:34:54701 settings->SetSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
Hugo Holgersson943ae692019-01-10 10:04:14702 // Spatnav depends on KeyboardFocusableScrollers. The WebUI team has
703 // disabled KFS because they need more time to update their custom elements,
704 // crbug.com/907284. Meanwhile, we pre-ship KFS to spatnav users.
705 if (prefs.spatial_navigation_enabled)
706 WebRuntimeFeatures::EnableKeyboardFocusableScrollers(true);
[email protected]b3a97b52014-07-09 06:25:05707
Bruce Long015d96f2019-07-12 22:59:10708 settings->SetCaretBrowsingEnabled(prefs.caret_browsing_enabled);
709
Blink Reformat1c4d759e2017-04-09 16:34:54710 settings->SetSelectionIncludesAltImageText(true);
[email protected]b3a97b52014-07-09 06:25:05711
Blink Reformat1c4d759e2017-04-09 16:34:54712 settings->SetV8CacheOptions(
[email protected]35103c02014-08-12 15:08:47713 static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options));
714
Blink Reformat1c4d759e2017-04-09 16:34:54715 settings->SetImageAnimationPolicy(
je_julie.kim7fbb5a1a2015-02-09 17:26:05716 static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy));
717
Blink Reformat1c4d759e2017-04-09 16:34:54718 settings->SetPresentationRequiresUserGesture(
zqzhang1215ad422016-02-10 13:27:22719 prefs.user_gesture_required_for_presentation);
720
Elly Fong-Jonesf92897392019-01-24 16:05:49721 settings->SetTextTrackBackgroundColor(
722 WebString::FromASCII(prefs.text_track_background_color));
723 settings->SetTextTrackTextColor(
724 WebString::FromASCII(prefs.text_track_text_color));
Rahul Singh1862faa92019-03-06 22:41:43725 settings->SetTextTrackTextSize(
726 WebString::FromASCII(prefs.text_track_text_size));
727 settings->SetTextTrackTextShadow(
728 WebString::FromASCII(prefs.text_track_text_shadow));
729 settings->SetTextTrackFontFamily(
730 WebString::FromASCII(prefs.text_track_font_family));
731 settings->SetTextTrackFontVariant(
732 WebString::FromASCII(prefs.text_track_font_variant));
Blink Reformat1c4d759e2017-04-09 16:34:54733 settings->SetTextTrackMarginPercentage(prefs.text_track_margin_percentage);
Abigail Klein74de85bd2019-07-11 19:11:56734 settings->SetTextTrackWindowColor(
735 WebString::FromASCII(prefs.text_track_window_color));
736 settings->SetTextTrackWindowPadding(
737 WebString::FromASCII(prefs.text_track_window_padding));
738 settings->SetTextTrackWindowRadius(
739 WebString::FromASCII(prefs.text_track_window_radius));
halliwell4002be42016-03-18 18:33:40740
David Bokana03511a92018-09-13 04:25:24741 // Needs to happen before SetDefaultPageScaleLimits below since that'll
742 // recalculate the final page scale limits and that depends on this setting.
743 settings->SetShrinksViewportContentToFit(
744 prefs.shrinks_viewport_contents_to_fit);
745
746 // Needs to happen before SetIgnoreViewportTagScaleLimits below.
Blink Reformat1c4d759e2017-04-09 16:34:54747 web_view->SetDefaultPageScaleLimits(prefs.default_minimum_page_scale_factor,
748 prefs.default_maximum_page_scale_factor);
dcheng5ae8ca362015-02-05 04:03:47749
Allan Sandfeld Jensene35337092019-05-15 13:56:09750 settings->SetFullscreenSupported(prefs.fullscreen_supported);
Ahmed Fakhry42221452018-05-30 01:18:39751 settings->SetTextAutosizingEnabled(prefs.text_autosizing_enabled);
752 settings->SetDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
Tarun Bansald10f17a02018-09-13 00:23:17753 blink::WebNetworkStateNotifier::SetNetworkQualityWebHoldback(
754 static_cast<blink::WebEffectiveConnectionType>(
755 prefs.network_quality_estimator_web_holdback));
Ahmed Fakhry42221452018-05-30 01:18:39756
chaopeng7e8fb352019-03-26 03:34:49757 settings->SetDontSendKeyEventsToJavascript(
758 prefs.dont_send_key_events_to_javascript);
Mounir Lamouri6926107f2019-01-31 18:17:43759 settings->SetWebAppScope(WebString::FromASCII(prefs.web_app_scope.spec()));
760
[email protected]b3a97b52014-07-09 06:25:05761#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:54762 settings->SetAllowCustomScrollbarInMainFrame(false);
Blink Reformat1c4d759e2017-04-09 16:34:54763 settings->SetAccessibilityFontScaleFactor(prefs.font_scale_factor);
764 settings->SetDeviceScaleAdjustment(prefs.device_scale_adjustment);
Blink Reformat1c4d759e2017-04-09 16:34:54765 web_view->SetIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
766 settings->SetAutoZoomFocusedNodeToLegibleScale(true);
Blink Reformat1c4d759e2017-04-09 16:34:54767 settings->SetDefaultVideoPosterURL(
768 WebString::FromASCII(prefs.default_video_poster_url.spec()));
769 settings->SetSupportDeprecatedTargetDensityDPI(
[email protected]b3a97b52014-07-09 06:25:05770 prefs.support_deprecated_target_density_dpi);
Blink Reformat1c4d759e2017-04-09 16:34:54771 settings->SetUseLegacyBackgroundSizeShorthandBehavior(
[email protected]b3a97b52014-07-09 06:25:05772 prefs.use_legacy_background_size_shorthand_behavior);
Blink Reformat1c4d759e2017-04-09 16:34:54773 settings->SetWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
774 settings->SetUseWideViewport(prefs.use_wide_viewport);
775 settings->SetForceZeroLayoutHeight(prefs.force_zero_layout_height);
Blink Reformat1c4d759e2017-04-09 16:34:54776 settings->SetViewportMetaMergeContentQuirk(
[email protected]b3a97b52014-07-09 06:25:05777 prefs.viewport_meta_merge_content_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54778 settings->SetViewportMetaNonUserScalableQuirk(
[email protected]b3a97b52014-07-09 06:25:05779 prefs.viewport_meta_non_user_scalable_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54780 settings->SetViewportMetaZeroValuesQuirk(
[email protected]b3a97b52014-07-09 06:25:05781 prefs.viewport_meta_zero_values_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54782 settings->SetClobberUserAgentInitialScaleQuirk(
[email protected]b3a97b52014-07-09 06:25:05783 prefs.clobber_user_agent_initial_scale_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54784 settings->SetIgnoreMainFrameOverflowHiddenQuirk(
[email protected]b3a97b52014-07-09 06:25:05785 prefs.ignore_main_frame_overflow_hidden_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54786 settings->SetReportScreenSizeInPhysicalPixelsQuirk(
[email protected]b3a97b52014-07-09 06:25:05787 prefs.report_screen_size_in_physical_pixels_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54788 settings->SetShouldReuseGlobalForUnownedMainFrame(
tzik30eb52c2018-03-27 06:55:18789 prefs.reuse_global_for_unowned_main_frame);
Blink Reformat1c4d759e2017-04-09 16:34:54790 settings->SetPreferHiddenVolumeControls(true);
791 settings->SetSpellCheckEnabledByDefault(prefs.spellcheck_enabled_by_default);
dalecurtiscd971252016-09-21 16:09:00792
Blink Reformat1c4d759e2017-04-09 16:34:54793 WebRuntimeFeatures::EnableVideoFullscreenOrientationLock(
mlamouri1d266bf2016-12-05 17:42:36794 prefs.video_fullscreen_orientation_lock_enabled);
johnme913ee5f2017-04-28 21:36:16795 WebRuntimeFeatures::EnableVideoRotateToFullscreen(
796 prefs.video_rotate_to_fullscreen_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54797 settings->SetEmbeddedMediaExperienceEnabled(
shaktisahuf97f7532017-02-24 22:46:13798 prefs.embedded_media_experience_enabled);
Ian Vollickeeca1d82018-02-07 02:43:42799 settings->SetImmersiveModeEnabled(prefs.immersive_mode_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54800 settings->SetDoNotUpdateSelectionOnMutatingSelectionRange(
changwane54ccdb92017-04-05 19:20:54801 prefs.do_not_update_selection_on_mutating_selection_range);
Noel Gordonf311a842017-07-27 00:10:07802 WebRuntimeFeatures::EnableCSSHexAlphaColor(prefs.css_hex_alpha_color_enabled);
Tobias Sargeant416174f2017-09-01 01:18:09803 WebRuntimeFeatures::EnableScrollTopLeftInterop(
804 prefs.scroll_top_left_interop_enabled);
Fernando Serboncini1fb12a82019-08-08 20:46:01805 WebRuntimeFeatures::EnableSurfaceEmbeddingFeatures(
806 !prefs.disable_features_depending_on_viz);
Aaron Krajeski0fb51282019-09-17 15:01:27807 WebRuntimeFeatures::EnableAcceleratedSmallCanvases(
808 !prefs.disable_accelerated_small_canvases);
Mason Freed8cbef172019-11-07 19:42:41809 if (prefs.reenable_web_components_v0) {
810 WebRuntimeFeatures::EnableShadowDOMV0(true);
811 WebRuntimeFeatures::EnableCustomElementsV0(true);
812 WebRuntimeFeatures::EnableHTMLImports(true);
813 }
zqzhangdf72ed082016-12-08 16:07:55814#endif // defined(OS_ANDROID)
Rune Lillesveenb46bb482019-04-02 07:36:29815 settings->SetForceDarkModeEnabled(prefs.force_dark_mode_enabled);
816
mlamouri55a0543c2017-05-11 10:34:07817 switch (prefs.autoplay_policy) {
818 case AutoplayPolicy::kNoUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28819 settings->SetAutoplayPolicy(
820 WebSettings::AutoplayPolicy::kNoUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07821 break;
822 case AutoplayPolicy::kUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28823 settings->SetAutoplayPolicy(
824 WebSettings::AutoplayPolicy::kUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07825 break;
mlamouri431bb4e2017-06-06 08:54:24826 case AutoplayPolicy::kDocumentUserActivationRequired:
827 settings->SetAutoplayPolicy(
828 WebSettings::AutoplayPolicy::kDocumentUserActivationRequired);
829 break;
mlamouri55a0543c2017-05-11 10:34:07830 }
831
Blink Reformat1c4d759e2017-04-09 16:34:54832 settings->SetViewportEnabled(prefs.viewport_enabled);
833 settings->SetViewportMetaEnabled(prefs.viewport_meta_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54834 settings->SetViewportStyle(
alokp5d566962016-04-19 00:54:16835 static_cast<blink::WebViewportStyle>(prefs.viewport_style));
836
Blink Reformat1c4d759e2017-04-09 16:34:54837 settings->SetLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
838 settings->SetMainFrameResizesAreOrientationChanges(
yoava1a508b42015-10-20 12:03:21839 prefs.main_frame_resizes_are_orientation_changes);
840
Blink Reformat1c4d759e2017-04-09 16:34:54841 settings->SetShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up);
842 settings->SetAlwaysShowContextMenuOnTouch(
amaralp547e4192016-06-03 19:17:35843 prefs.always_show_context_menu_on_touch);
Sandra Sunc79fc93a2018-04-10 15:22:23844 settings->SetSmoothScrollForFindEnabled(prefs.smooth_scroll_for_find_enabled);
ccameron2fd70de72015-02-19 00:40:40845
Blink Reformat1c4d759e2017-04-09 16:34:54846 settings->SetHideDownloadUI(prefs.hide_download_ui);
qinmin72e8bd02016-10-21 19:35:37847
Blink Reformat1c4d759e2017-04-09 16:34:54848 settings->SetPresentationReceiver(prefs.presentation_receiver);
mlamouri57359d912016-11-29 20:11:50849
Blink Reformat1c4d759e2017-04-09 16:34:54850 settings->SetMediaControlsEnabled(prefs.media_controls_enabled);
mlamouri5cd9ae82017-02-18 11:05:09851
Tarun Bansal73d67f02018-01-17 05:56:25852 settings->SetLowPriorityIframesThreshold(
853 static_cast<blink::WebEffectiveConnectionType>(
854 prefs.low_priority_iframes_threshold));
855
Mounir Lamouri9c99a1602018-07-05 15:01:44856 settings->SetPictureInPictureEnabled(
857 prefs.picture_in_picture_enabled &&
[email protected]69db58f2018-09-26 20:27:56858 MediaFactory::GetVideoSurfaceLayerMode() !=
CJ DiMeglio89240472018-10-18 18:21:10859 blink::WebMediaPlayer::SurfaceLayerMode::kNever);
François Beaufort8c08979fc2018-03-05 13:06:31860
Tarun Bansal333819e2018-05-15 16:38:42861 settings->SetDataSaverHoldbackWebApi(
862 prefs.data_saver_holdback_web_api_enabled);
Tarun Bansal333819e2018-05-15 16:38:42863
rajendrante87ed712018-11-30 01:55:00864 settings->SetLazyLoadEnabled(prefs.lazy_load_enabled);
865
Scott Little878f7d6702018-05-31 22:09:06866 for (const auto& ect_distance_pair :
867 prefs.lazy_frame_loading_distance_thresholds_px) {
868 switch (ect_distance_pair.first) {
869 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
870 settings->SetLazyFrameLoadingDistanceThresholdPxUnknown(
871 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39872 continue;
Scott Little878f7d6702018-05-31 22:09:06873 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
874 settings->SetLazyFrameLoadingDistanceThresholdPxOffline(
875 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39876 continue;
Scott Little878f7d6702018-05-31 22:09:06877 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
878 settings->SetLazyFrameLoadingDistanceThresholdPxSlow2G(
879 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39880 continue;
Scott Little878f7d6702018-05-31 22:09:06881 case net::EFFECTIVE_CONNECTION_TYPE_2G:
882 settings->SetLazyFrameLoadingDistanceThresholdPx2G(
883 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39884 continue;
Scott Little878f7d6702018-05-31 22:09:06885 case net::EFFECTIVE_CONNECTION_TYPE_3G:
886 settings->SetLazyFrameLoadingDistanceThresholdPx3G(
887 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39888 continue;
Scott Little878f7d6702018-05-31 22:09:06889 case net::EFFECTIVE_CONNECTION_TYPE_4G:
890 settings->SetLazyFrameLoadingDistanceThresholdPx4G(
891 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39892 continue;
893 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
894 continue;
Scott Little878f7d6702018-05-31 22:09:06895 }
rajendrantd8026342018-08-29 08:08:39896 NOTREACHED();
897 }
898
899 for (const auto& ect_distance_pair :
900 prefs.lazy_image_loading_distance_thresholds_px) {
901 switch (ect_distance_pair.first) {
902 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
903 settings->SetLazyImageLoadingDistanceThresholdPxUnknown(
904 ect_distance_pair.second);
905 continue;
906 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
907 settings->SetLazyImageLoadingDistanceThresholdPxOffline(
908 ect_distance_pair.second);
909 continue;
910 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
911 settings->SetLazyImageLoadingDistanceThresholdPxSlow2G(
912 ect_distance_pair.second);
913 continue;
914 case net::EFFECTIVE_CONNECTION_TYPE_2G:
915 settings->SetLazyImageLoadingDistanceThresholdPx2G(
916 ect_distance_pair.second);
917 continue;
918 case net::EFFECTIVE_CONNECTION_TYPE_3G:
919 settings->SetLazyImageLoadingDistanceThresholdPx3G(
920 ect_distance_pair.second);
921 continue;
922 case net::EFFECTIVE_CONNECTION_TYPE_4G:
923 settings->SetLazyImageLoadingDistanceThresholdPx4G(
924 ect_distance_pair.second);
925 continue;
926 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
927 continue;
928 }
929 NOTREACHED();
Scott Little878f7d6702018-05-31 22:09:06930 }
931
rajendrant3daeae292019-09-20 07:57:54932 for (const auto& fully_load_k_pair : prefs.lazy_image_first_k_fully_load) {
933 switch (fully_load_k_pair.first) {
934 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
935 continue;
936 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
937 settings->SetLazyImageFirstKFullyLoadUnknown(fully_load_k_pair.second);
938 continue;
939 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
940 settings->SetLazyImageFirstKFullyLoadSlow2G(fully_load_k_pair.second);
941 continue;
942 case net::EFFECTIVE_CONNECTION_TYPE_2G:
943 settings->SetLazyImageFirstKFullyLoad2G(fully_load_k_pair.second);
944 continue;
945 case net::EFFECTIVE_CONNECTION_TYPE_3G:
946 settings->SetLazyImageFirstKFullyLoad3G(fully_load_k_pair.second);
947 continue;
948 case net::EFFECTIVE_CONNECTION_TYPE_4G:
949 settings->SetLazyImageFirstKFullyLoad4G(fully_load_k_pair.second);
950 continue;
951 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
952 continue;
953 }
954 NOTREACHED();
955 }
956
ccameron2fd70de72015-02-19 00:40:40957#if defined(OS_MACOSX)
Blink Reformat1c4d759e2017-04-09 16:34:54958 web_view->SetMaximumLegibleScale(prefs.default_maximum_page_scale_factor);
ccameron2fd70de72015-02-19 00:40:40959#endif
sunyunjia87f287b2016-09-09 00:38:13960
961#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:54962 WebRuntimeFeatures::EnableMiddleClickAutoscroll(true);
sunyunjia87f287b2016-09-09 00:38:13963#endif
Dave Tapuskac6627e12018-08-30 15:07:19964
Dave Tapuskaa38e3252018-11-13 03:01:17965 WebRuntimeFeatures::EnableTranslateService(prefs.translate_service_available);
[email protected]b3a97b52014-07-09 06:25:05966}
967
968/*static*/
nickf7b38222016-11-22 21:59:35969RenderViewImpl* RenderViewImpl::Create(
970 CompositorDependencies* compositor_deps,
Balazs Engedyba034e72017-10-27 22:26:28971 mojom::CreateViewParamsPtr params,
danakjdf1ceb72018-07-18 20:02:25972 RenderWidget::ShowCallback show_callback,
Hajime Hoshiabb3c8f2017-12-04 18:41:39973 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Balazs Engedyba034e72017-10-27 22:26:28974 DCHECK(params->view_id != MSG_ROUTING_NONE);
danakjd434db42020-01-07 22:27:39975 // Frame and widget routing ids come together.
976 DCHECK_EQ(params->main_frame_routing_id == MSG_ROUTING_NONE,
977 params->main_frame_widget_routing_id == MSG_ROUTING_NONE);
978 // We have either a main frame or a proxy routing id.
979 DCHECK_NE(params->main_frame_routing_id != MSG_ROUTING_NONE,
980 params->proxy_routing_id != MSG_ROUTING_NONE);
[email protected]0287e762014-04-11 13:07:58981
danakjd434db42020-01-07 22:27:39982 RenderViewImpl* render_view;
Albert J. Wong7faa3da2019-03-21 20:43:43983 if (g_create_render_view_impl) {
984 render_view = g_create_render_view_impl(compositor_deps, *params);
985 } else {
986 render_view = new RenderViewImpl(compositor_deps, *params);
987 }
988
Erik Chen10e9b022019-08-21 23:33:23989 render_view->Initialize(compositor_deps, std::move(params),
Albert J. Wong7faa3da2019-03-21 20:43:43990 std::move(show_callback), std::move(task_runner));
[email protected]075366912013-02-18 07:13:24991 return render_view;
[email protected]8d41d7612012-11-14 20:32:19992}
993
Erik Chen3433ee02019-08-05 20:14:26994void RenderViewImpl::Destroy() {
danakjcdfc4262019-10-01 20:09:48995 destroying_ = true;
996
Erik Chen562ca42b2019-08-22 19:46:06997 webview_->Close();
Erik Chen3433ee02019-08-05 20:14:26998 // The webview_ is already destroyed by the time we get here, remove any
999 // references to it.
1000 g_view_map.Get().erase(webview_);
1001 webview_ = nullptr;
Erik Chen562ca42b2019-08-22 19:46:061002
Erik Chen3433ee02019-08-05 20:14:261003 delete this;
1004}
1005
[email protected]8d41d7612012-11-14 20:32:191006// static
dcheng35d31c112015-07-22 00:17:361007void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
1008 *create_render_view_impl)(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:151009 const mojom::CreateViewParams&)) {
[email protected]8d41d7612012-11-14 20:32:191010 CHECK(!g_create_render_view_impl);
1011 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291012}
1013
[email protected]310ebd6302011-10-10 19:06:281014void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511015 observers_.AddObserver(observer);
1016}
1017
[email protected]310ebd6302011-10-10 19:06:281018void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1019 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511020 observers_.RemoveObserver(observer);
1021}
1022
Peter Kastinga4a3ed12018-01-31 04:07:591023blink::WebView* RenderViewImpl::webview() {
1024 return webview_;
1025}
1026
1027const blink::WebView* RenderViewImpl::webview() const {
lfg4fa48da2016-05-09 18:25:131028 return webview_;
[email protected]4d51d5bf2010-07-26 18:48:261029}
1030
danakja2c9d0a92018-07-25 20:01:181031// RenderWidgetOwnerDelegate -----------------------------------------
fsamuel72464894f2015-12-15 06:59:311032
danakja2c9d0a92018-07-25 20:01:181033void RenderViewImpl::SetActiveForWidget(bool active) {
Albert J. Wongcb004632018-07-10 22:58:251034 if (webview())
1035 webview()->SetIsActive(active);
1036}
1037
danakja2c9d0a92018-07-25 20:01:181038bool RenderViewImpl::SupportsMultipleWindowsForWidget() {
1039 return webkit_preferences_.supports_multiple_windows;
1040}
1041
David Bokan11f6ef482019-03-18 17:47:271042bool RenderViewImpl::ShouldAckSyntheticInputImmediately() {
1043 // TODO(bokan): The RequestPresentation API appears not to function in VR. As
1044 // a short term workaround for https://crbug.com/940063, ACK input
1045 // immediately rather than using RequestPresentation.
1046 if (webkit_preferences_.immersive_mode_enabled)
1047 return true;
1048 return false;
1049}
1050
danakja2c9d0a92018-07-25 20:01:181051void RenderViewImpl::ApplyNewDisplayModeForWidget(
Eric Willigers052f0432019-10-04 04:06:571052 blink::mojom::DisplayMode new_display_mode) {
danakj1ab8faf2018-10-12 18:24:281053 webview()->SetDisplayMode(new_display_mode);
danakja2c9d0a92018-07-25 20:01:181054}
1055
1056void RenderViewImpl::ApplyAutoResizeLimitsForWidget(const gfx::Size& min_size,
1057 const gfx::Size& max_size) {
1058 webview()->EnableAutoResizeMode(min_size, max_size);
1059}
1060
1061void RenderViewImpl::DisableAutoResizeForWidget() {
1062 webview()->DisableAutoResizeMode();
1063}
1064
1065void RenderViewImpl::ScrollFocusedNodeIntoViewForWidget() {
1066 if (WebLocalFrame* focused_frame = GetWebView()->FocusedFrame()) {
danakj5f069012019-10-09 23:14:171067 blink::WebFrameWidget* frame_widget =
1068 focused_frame->LocalRoot()->FrameWidget();
danakja2c9d0a92018-07-25 20:01:181069 frame_widget->ScrollFocusedEditableElementIntoView();
1070 }
1071}
1072
1073void RenderViewImpl::DidReceiveSetFocusEventForWidget() {
1074 // This message must always be received when the main frame is a
1075 // WebLocalFrame.
Albert J. Wong7bbf22d2018-12-20 00:27:271076 // TODO(ajwong): Can this be removed and just check |delegate_| in
danakja2c9d0a92018-07-25 20:01:181077 // RenderWidget instead?
1078 CHECK(webview()->MainFrame()->IsWebLocalFrame());
1079}
1080
danakja2c9d0a92018-07-25 20:01:181081void RenderViewImpl::DidCommitCompositorFrameForWidget() {
1082 for (auto& observer : observers_)
1083 observer.DidCommitCompositorFrame();
Philip Rogers33cd2bcc2018-08-13 21:29:291084 UpdatePreferredSize();
danakja2c9d0a92018-07-25 20:01:181085}
1086
1087void RenderViewImpl::DidCompletePageScaleAnimationForWidget() {
1088 if (auto* focused_frame = GetWebView()->FocusedFrame()) {
1089 if (focused_frame->AutofillClient())
1090 focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame();
1091 }
1092}
1093
1094void RenderViewImpl::ResizeWebWidgetForWidget(
danakj748ef9092019-10-17 23:40:531095 const gfx::Size& widget_size,
Sinan Sahin92a360bc2019-12-05 19:20:451096 cc::BrowserControlsParams browser_controls_params) {
1097 webview()->ResizeWithBrowserControls(widget_size, browser_controls_params);
danakja2c9d0a92018-07-25 20:01:181098}
1099
danakja2c9d0a92018-07-25 20:01:181100void RenderViewImpl::SetScreenMetricsEmulationParametersForWidget(
1101 bool enabled,
1102 const blink::WebDeviceEmulationParams& params) {
danakj1ab8faf2018-10-12 18:24:281103 if (enabled)
1104 webview()->EnableDeviceEmulation(params);
1105 else
1106 webview()->DisableDeviceEmulation();
danakja2c9d0a92018-07-25 20:01:181107}
1108
1109// IPC message handlers -----------------------------------------
1110
danakja2c9d0a92018-07-25 20:01:181111void RenderViewImpl::OnUpdateTargetURLAck() {
1112 // Check if there is a targeturl waiting to be sent.
1113 if (target_url_status_ == TARGET_PENDING)
1114 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), pending_target_url_));
1115
1116 target_url_status_ = TARGET_NONE;
1117}
1118
1119void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset,
1120 int history_length) {
1121 // -1 <= history_offset < history_length <= kMaxSessionHistoryEntries(50).
1122 DCHECK_LE(-1, history_offset);
1123 DCHECK_LT(history_offset, history_length);
1124 DCHECK_LE(history_length, kMaxSessionHistoryEntries);
1125
1126 history_list_offset_ = history_offset;
1127 history_list_length_ = history_length;
1128}
1129
1130void RenderViewImpl::OnSetInitialFocus(bool reverse) {
1131 if (!webview())
1132 return;
1133 webview()->SetInitialFocus(reverse);
1134}
1135
danakja2c9d0a92018-07-25 20:01:181136void RenderViewImpl::OnAudioStateChanged(bool is_audio_playing) {
1137 webview()->AudioStateChanged(is_audio_playing);
1138}
1139
danakja2c9d0a92018-07-25 20:01:181140///////////////////////////////////////////////////////////////////////////////
1141
1142void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget,
1143 WebNavigationPolicy policy,
1144 const gfx::Rect& initial_rect) {
1145 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(),
1146 initial_rect));
1147}
1148
1149void RenderViewImpl::ShowCreatedFullscreenWidget(
1150 RenderWidget* fullscreen_widget,
1151 WebNavigationPolicy policy,
1152 const gfx::Rect& initial_rect) {
1153 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(),
1154 fullscreen_widget->routing_id()));
1155}
1156
1157void RenderViewImpl::SendFrameStateUpdates() {
1158 // Tell each frame with pending state to send its UpdateState message.
1159 for (int render_frame_routing_id : frames_with_pending_state_) {
1160 RenderFrameImpl* frame =
1161 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
1162 if (frame)
1163 frame->SendUpdateState();
1164 }
1165 frames_with_pending_state_.clear();
1166}
1167
danakja2c9d0a92018-07-25 20:01:181168// IPC::Listener -------------------------------------------------------------
fsamuel72464894f2015-12-15 06:59:311169
[email protected]310ebd6302011-10-10 19:06:281170bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281171 WebFrame* main_frame = webview() ? webview()->MainFrame() : nullptr;
Avi Drissmanb5f8e242017-12-12 05:21:561172 if (main_frame) {
1173 GURL active_url;
1174 if (main_frame->IsWebLocalFrame())
1175 active_url = main_frame->ToWebLocalFrame()->GetDocument().Url();
lukaszabedb4b22017-06-23 00:00:131176 GetContentClient()->SetActiveURL(
Avi Drissmanb5f8e242017-12-12 05:21:561177 active_url, main_frame->Top()->GetSecurityOrigin().ToString().Utf8());
1178 }
[email protected]f8b6b6f2009-03-10 16:48:261179
dchenga2d442c22016-10-13 15:39:211180 for (auto& observer : observers_) {
1181 if (observer.OnMessageReceived(message))
[email protected]676126f72011-01-15 00:03:511182 return true;
dchenga2d442c22016-10-13 15:39:211183 }
[email protected]b2abac72009-02-26 12:39:281184
[email protected]a95986a82010-12-24 06:19:281185 bool handled = true;
[email protected]e44d1342014-05-16 21:29:331186 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
initial.commit09911bf2008-07-26 23:55:291187 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291188 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1189 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]30f75e62009-02-25 22:01:001190 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]ab32b16c2009-10-16 14:57:251191 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1192 OnEnablePreferredSizeChangedMode)
[email protected]81375e872012-01-11 21:40:361193 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
W. James MacLeand973a55b2018-11-29 21:39:131194 IPC_MESSAGE_HANDLER(ViewMsg_AnimateDoubleTapZoom,
1195 OnAnimateDoubleTapZoomInMainFrame)
W. James MacLean5372eb72018-12-19 12:56:361196 IPC_MESSAGE_HANDLER(ViewMsg_ZoomToFindInPageRect, OnZoomToFindInPageRect)
danakjd51fd53d2018-12-21 23:06:091197 IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque, OnSetBackgroundOpaque)
wjmaclean64951902016-04-29 20:59:121198
1199 // Page messages.
Collin Baker98457b52019-11-06 21:34:291200 IPC_MESSAGE_HANDLER(PageMsg_VisibilityChanged, OnPageVisibilityChanged)
alexmos136fd6e62016-08-15 20:58:411201 IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength,
1202 OnSetHistoryOffsetAndLength)
altimind8bd26c2016-11-04 11:44:541203 IPC_MESSAGE_HANDLER(PageMsg_AudioStateChanged, OnAudioStateChanged)
Francois Doray47f759d2018-06-11 18:13:511204 IPC_MESSAGE_HANDLER(PageMsg_SetPageFrozen, SetPageFrozen)
Yuzu Saijodfba8fa62019-08-27 02:15:221205 IPC_MESSAGE_HANDLER(PageMsg_PutPageIntoBackForwardCache,
1206 PutPageIntoBackForwardCache)
1207 IPC_MESSAGE_HANDLER(PageMsg_RestorePageFromBackForwardCache,
1208 RestorePageFromBackForwardCache)
W. James MacLean62198672019-06-04 16:46:101209 IPC_MESSAGE_HANDLER(PageMsg_UpdateTextAutosizerPageInfoForRemoteMainFrames,
1210 OnTextAutosizerPageInfoChanged)
Bruce Long1e3e1f542019-10-16 17:56:281211 IPC_MESSAGE_HANDLER(PageMsg_SetRendererPrefs, OnSetRendererPrefs)
Adithya Srinivasan11af2c52019-12-16 22:52:551212 IPC_MESSAGE_HANDLER(PageMsg_SetInsidePortal, OnSetInsidePortal)
lfg717154072016-06-30 15:04:161213
[email protected]a794f3a2013-10-30 17:00:321214 // Adding a new message? Add platform independent ones first, then put the
1215 // platform specific ones at the end.
initial.commit09911bf2008-07-26 23:55:291216 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401217
[email protected]a95986a82010-12-24 06:19:281218 return handled;
initial.commit09911bf2008-07-26 23:55:291219}
1220
[email protected]180ef242013-11-07 06:50:461221// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521222
Mustaq Ahmed55944cb2018-05-25 20:44:271223// TODO(csharrison): Migrate this method to WebLocalFrameClient /
1224// RenderFrameImpl, as it is now serviced by a mojo interface scoped to the
1225// opener frame.
Daniel Murphyc8e991a2018-10-12 22:09:031226WebView* RenderViewImpl::CreateView(
1227 WebLocalFrame* creator,
1228 const WebURLRequest& request,
1229 const WebWindowFeatures& features,
1230 const WebString& frame_name,
1231 WebNavigationPolicy policy,
Antonio Gomes7096ac02020-02-14 14:29:541232 blink::mojom::WebSandboxFlags sandbox_flags,
Ehsan Karamad39407082019-02-19 23:38:191233 const blink::FeaturePolicy::FeatureState& opener_feature_state,
Daniel Murphyc8e991a2018-10-12 22:09:031234 const blink::SessionStorageNamespaceId& session_storage_namespace_id) {
nick5ae4d2d2017-01-06 01:18:351235 RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator);
rockot5c478a72016-09-28 23:14:181236 mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New();
Mustaq Ahmedc4cb7162018-06-05 16:28:361237
Mustaq Ahmede5f12562019-10-30 18:02:031238 // The user activation check is done at the browser process through
1239 // |frame_host->CreateNewWindow()| call below. But the extensions case
1240 // handled through the following |if| is an exception.
Mustaq Ahmed8601a562020-01-31 18:05:521241 params->allow_popup = false;
[email protected]00323f02013-07-24 15:47:411242 if (GetContentClient()->renderer()->AllowPopup())
Mustaq Ahmed8601a562020-01-31 18:05:521243 params->allow_popup = true;
Mustaq Ahmedc4cb7162018-06-05 16:28:361244
rockot5c478a72016-09-28 23:14:181245 params->window_container_type = WindowFeaturesToContainerType(features);
Daniel Murphye3eec92c2018-02-23 19:09:151246
Daniel Murphyc8e991a2018-10-12 22:09:031247 params->session_storage_namespace_id = session_storage_namespace_id;
1248 // TODO(dmurph): Don't copy session storage when features.noopener is true:
1249 // https://html.spec.whatwg.org/multipage/browsers.html#copy-session-storage
1250 // https://crbug.com/771959
Daniel Murphye3eec92c2018-02-23 19:09:151251 params->clone_from_session_storage_namespace_id =
1252 session_storage_namespace_id_;
Daniel Murphye3eec92c2018-02-23 19:09:151253
Daniel Chengd5e56ff2017-06-24 07:44:021254 const std::string& frame_name_utf8 = frame_name.Utf8(
1255 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
1256 params->frame_name = frame_name_utf8;
Nate Chapin43f307d2019-04-15 21:04:411257 params->opener_suppressed = features.noopener;
rockot5c478a72016-09-28 23:14:181258 params->disposition = NavigationPolicyToDisposition(policy);
Blink Reformat1c4d759e2017-04-09 16:34:541259 if (!request.IsNull()) {
1260 params->target_url = request.Url();
Dominic Farolinoaee9c1b82019-12-18 03:20:101261 params->referrer = blink::mojom::Referrer::New(
1262 blink::WebStringToGURL(request.ReferrerString()),
1263 request.GetReferrerPolicy());
[email protected]44e55b012013-07-23 14:21:561264 }
scottmg8e6c6082017-02-13 23:15:481265 params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
[email protected]8ab04652010-06-12 02:47:261266
rockot5c478a72016-09-28 23:14:181267 // We preserve this information before sending the message since |params| is
1268 // moved on send.
1269 bool is_background_tab =
1270 params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB;
[email protected]22217ed32013-11-18 18:40:231271
Daniel Cheng8bb30c62017-10-23 20:40:471272 mojom::CreateNewWindowStatus status;
rockot5c478a72016-09-28 23:14:181273 mojom::CreateNewWindowReplyPtr reply;
Balazs Engedya40712f2017-09-15 15:01:111274 auto* frame_host = creator_frame->GetFrameHost();
Daniel Cheng8bb30c62017-10-23 20:40:471275 bool err = !frame_host->CreateNewWindow(std::move(params), &status, &reply);
1276 if (err || status == mojom::CreateNewWindowStatus::kIgnore)
rockot5c478a72016-09-28 23:14:181277 return nullptr;
[email protected]48c9cf2d2009-09-16 16:47:521278
Jochen Eisinger515337a2017-05-26 14:12:521279 // For Android WebView, we support a pop-up like behavior for window.open()
1280 // even if the embedding app doesn't support multiple windows. In this case,
1281 // window.open() will return "window" and navigate it to whatever URL was
Jochen Eisinger8cb28492017-10-04 10:58:131282 // passed. We also don't need to consume user gestures to protect against
1283 // multiple windows being opened, because, well, the app doesn't support
1284 // multiple windows.
Daniel Cheng8bb30c62017-10-23 20:40:471285 // TODO(dcheng): It's awkward that this is plumbed into Blink but not really
Kent Tamura21d1de62018-12-10 04:45:201286 // used much in Blink, except to enable web testing... perhaps this should
Daniel Cheng8bb30c62017-10-23 20:40:471287 // be checked directly in the browser side.
1288 if (status == mojom::CreateNewWindowStatus::kReuse)
Jochen Eisinger515337a2017-05-26 14:12:521289 return webview();
1290
Daniel Cheng8bb30c62017-10-23 20:40:471291 DCHECK(reply);
1292 DCHECK_NE(MSG_ROUTING_NONE, reply->route_id);
1293 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_route_id);
1294 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_widget_route_id);
1295
Mustaq Ahmed76c2f4312018-06-07 20:48:011296 // The browser allowed creation of a new window and consumed the user
Mustaq Ahmede5f12562019-10-30 18:02:031297 // activation.
Mustaq Ahmed4baa9a6e82019-12-20 23:43:461298 bool was_consumed = creator->ConsumeTransientUserActivation(
1299 blink::UserActivationUpdateSource::kBrowser);
Jochen Eisinger8cb28492017-10-04 10:58:131300
[email protected]7912e822014-04-16 02:37:031301 // While this view may be a background extension page, it can spawn a visible
1302 // render view. So we just assume that the new one is not another background
1303 // page instead of passing on our own value.
1304 // TODO(vangelis): Can we tell if the new view will be a background page?
danakj77eb7e82020-01-09 19:38:461305 bool never_composited = false;
[email protected]9115d5f2013-03-24 04:37:411306
[email protected]d6fa88f2013-10-18 16:00:431307 // The initial hidden state for the RenderViewImpl here has to match what the
1308 // browser will eventually decide for the given disposition. Since we have to
1309 // return from this call synchronously, we just have to make our best guess
1310 // and rely on the browser sending a WasHidden / WasShown message if it
1311 // disagrees.
Balazs Engedyba034e72017-10-27 22:26:281312 mojom::CreateViewParamsPtr view_params = mojom::CreateViewParams::New();
alexmos5ac402d2015-07-09 07:51:101313
Balazs Engedyba034e72017-10-27 22:26:281314 view_params->opener_frame_route_id = creator_frame->GetRoutingID();
avia3dca182016-03-19 01:09:521315 DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID());
alexmos5ac402d2015-07-09 07:51:101316
Balazs Engedyba034e72017-10-27 22:26:281317 view_params->window_was_created_with_opener = true;
Leon Han2c81b5d2019-01-25 01:58:331318 view_params->renderer_preferences = renderer_preferences_.Clone();
Balazs Engedyba034e72017-10-27 22:26:281319 view_params->web_preferences = webkit_preferences_;
1320 view_params->view_id = reply->route_id;
1321 view_params->main_frame_routing_id = reply->main_frame_route_id;
Oksana Zhuravlovafee097c2019-07-26 17:01:301322 view_params
1323 ->main_frame_interface_bundle = mojom::DocumentScopedInterfaceBundle::New(
1324 std::move(reply->main_frame_interface_bundle->interface_provider),
Oksana Zhuravlovafee097c2019-07-26 17:01:301325 std::move(reply->main_frame_interface_bundle->browser_interface_broker));
Balazs Engedyba034e72017-10-27 22:26:281326 view_params->main_frame_widget_routing_id = reply->main_frame_widget_route_id;
1327 view_params->session_storage_namespace_id =
rockot5c478a72016-09-28 23:14:181328 reply->cloned_session_storage_namespace_id;
Daniel Murphy95792ef2018-10-04 01:29:551329 DCHECK(!view_params->session_storage_namespace_id.empty())
1330 << "Session storage namespace must be populated.";
Balazs Engedyba034e72017-10-27 22:26:281331 view_params->replicated_frame_state.frame_policy.sandbox_flags =
1332 sandbox_flags;
Ehsan Karamad39407082019-02-19 23:38:191333 view_params->replicated_frame_state.opener_feature_state =
1334 opener_feature_state;
Balazs Engedyba034e72017-10-27 22:26:281335 view_params->replicated_frame_state.name = frame_name_utf8;
1336 view_params->devtools_main_frame_token = reply->devtools_main_frame_token;
Balazs Engedyba034e72017-10-27 22:26:281337 view_params->hidden = is_background_tab;
danakj77eb7e82020-01-09 19:38:461338 view_params->never_composited = never_composited;
danakjbe56b8132019-10-12 00:57:411339 view_params->visual_properties = reply->visual_properties;
naskobd911332014-11-25 01:13:361340
nick5ae4d2d2017-01-06 01:18:351341 // Unretained() is safe here because our calling function will also call
1342 // show().
nickf7b38222016-11-22 21:59:351343 RenderWidget::ShowCallback show_callback =
danakjdf1ceb72018-07-18 20:02:251344 base::BindOnce(&RenderFrameImpl::ShowCreatedWindow,
Mustaq Ahmede5f12562019-10-30 18:02:031345 base::Unretained(creator_frame), was_consumed);
nickf7b38222016-11-22 21:59:351346
Balazs Engedyba034e72017-10-27 22:26:281347 RenderViewImpl* view = RenderViewImpl::Create(
danakj4b8a2d9a2019-10-15 15:53:591348 compositor_deps_, std::move(view_params), std::move(show_callback),
Hajime Hoshi6fc91142018-05-11 08:21:171349 creator->GetTaskRunner(blink::TaskType::kInternalDefault));
[email protected]48c9cf2d2009-09-16 16:47:521350
[email protected]48c9cf2d2009-09-16 16:47:521351 return view->webview();
1352}
1353
danakj19f3e512018-12-14 21:02:051354blink::WebPagePopup* RenderViewImpl::CreatePopup(
1355 blink::WebLocalFrame* creator) {
Julie Jeongeun Kimcaacf9102019-09-12 02:13:051356 mojo::PendingRemote<mojom::Widget> widget_channel;
1357 mojo::PendingReceiver<mojom::Widget> widget_channel_receiver =
1358 widget_channel.InitWithNewPipeAndPassReceiver();
danakj25ec6e2b2018-09-26 17:01:311359
1360 // Do a synchronous IPC to obtain a routing ID.
1361 int32_t widget_routing_id = MSG_ROUTING_NONE;
1362 bool success =
1363 RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
1364 GetRoutingID(), std::move(widget_channel), &widget_routing_id);
1365 if (!success) {
1366 // When the renderer is being killed the mojo message will fail.
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281367 return nullptr;
danakj25ec6e2b2018-09-26 17:01:311368 }
1369
1370 RenderWidget::ShowCallback opener_callback = base::BindOnce(
1371 &RenderViewImpl::ShowCreatedPopupWidget, weak_ptr_factory_.GetWeakPtr());
1372
danakj93593972019-10-11 00:02:491373 RenderWidget* opener_render_widget =
Erik Chen6bc8da02019-09-20 15:51:381374 RenderFrameImpl::FromWebFrame(creator)->GetLocalRootRenderWidget();
danakj25ec6e2b2018-09-26 17:01:311375
Erik Chen3433ee02019-08-05 20:14:261376 RenderWidget* popup_widget = RenderWidget::CreateForPopup(
danakj93593972019-10-11 00:02:491377 widget_routing_id, opener_render_widget->compositor_deps(),
danakj4b8a2d9a2019-10-15 15:53:591378 blink::mojom::DisplayMode::kUndefined,
danakj25ec6e2b2018-09-26 17:01:311379 /*hidden=*/false,
danakj77eb7e82020-01-09 19:38:461380 /*never_composited=*/false, std::move(widget_channel_receiver));
danakj25ec6e2b2018-09-26 17:01:311381
1382 // The returned WebPagePopup is self-referencing, so the pointer here is not
danakj45e4a4f2019-03-12 22:50:421383 // an owning pointer. It is de-referenced by calling Close().
danakj25ec6e2b2018-09-26 17:01:311384 blink::WebPagePopup* popup_web_widget =
Erik Chen3433ee02019-08-05 20:14:261385 blink::WebPagePopup::Create(popup_widget);
danakj25ec6e2b2018-09-26 17:01:311386
1387 // Adds a self-reference on the |popup_widget| so it will not be destroyed
1388 // when leaving scope. The WebPagePopup takes responsibility for Close()ing
1389 // and thus destroying the RenderWidget.
danakj93593972019-10-11 00:02:491390 popup_widget->InitForPopup(std::move(opener_callback), opener_render_widget,
1391 popup_web_widget,
1392 opener_render_widget->GetOriginalScreenInfo());
danakj25ec6e2b2018-09-26 17:01:311393 return popup_web_widget;
[email protected]48c9cf2d2009-09-16 16:47:521394}
1395
danakj295c43f182019-03-13 16:37:171396void RenderViewImpl::DoDeferredClose() {
1397 // The main widget is currently not active. The active main frame widget is
1398 // in a different process. Have the browser route the close request to the
1399 // active widget instead, so that the correct unload handlers are run.
1400 Send(new ViewHostMsg_RouteCloseEvent(GetRoutingID()));
1401}
1402
danakj45e4a4f2019-03-12 22:50:421403void RenderViewImpl::CloseWindowSoon() {
Avi Drissman07d22452019-03-25 17:56:391404 DCHECK(RenderThread::IsMainThread());
danakjd330a8b2020-01-16 20:59:141405 if (!main_render_frame_) {
danakj295c43f182019-03-13 16:37:171406 // Ask the RenderViewHost with a local main frame to initiate close. We
1407 // could be called from deep in Javascript. If we ask the RenderViewHost to
1408 // close now, the window could be closed before the JS finishes executing,
danakjbd1a86a2019-09-06 17:24:311409 // thanks to nested message loops running and handling the resulting Close
danakj295c43f182019-03-13 16:37:171410 // IPC. So instead, post a message back to the message loop, which won't run
1411 // until the JS is complete, and then the Close request can be sent.
1412 GetCleanupTaskRunner()->PostTask(
1413 FROM_HERE, base::BindOnce(&RenderViewImpl::DoDeferredClose,
1414 weak_ptr_factory_.GetWeakPtr()));
danakj45e4a4f2019-03-12 22:50:421415 return;
1416 }
1417
danakj50b37032020-01-15 22:44:001418 // If the main frame is in this RenderView's frame tree, then the Close
danakjd330a8b2020-01-16 20:59:141419 // request gets routed through the RenderWidget since non-frame RenderWidgets
1420 // share the code path.
danakjee8f4902020-01-17 18:06:101421 main_render_frame_->GetLocalRootRenderWidget()->CloseWidgetSoon();
danakj45e4a4f2019-03-12 22:50:421422}
1423
Daniel Murphy31bbb8b12018-02-07 21:44:101424base::StringPiece RenderViewImpl::GetSessionStorageNamespaceId() {
1425 CHECK(!session_storage_namespace_id_.empty());
Daniel Murphy0ce6e2c2017-11-21 01:54:261426 return session_storage_namespace_id_;
[email protected]bd92c3a2010-01-13 05:02:341427}
1428
Blink Reformat1c4d759e2017-04-09 16:34:541429void RenderViewImpl::PrintPage(WebLocalFrame* frame) {
Erik Chenfaa928c2019-09-20 23:41:151430 RenderFrameImpl* render_frame = RenderFrameImpl::FromWebFrame(frame);
1431 RenderWidget* render_widget = render_frame->GetLocalRootRenderWidget();
1432
1433 render_frame->ScriptedPrint(
1434 render_widget->input_handler().handling_input_event());
[email protected]48c9cf2d2009-09-16 16:47:521435}
1436
danakjcf409aa2019-09-20 15:22:301437bool RenderViewImpl::SetZoomLevel(double zoom_level) {
1438 if (zoom_level == page_zoom_level_)
1439 return false;
1440
wjmaclean64951902016-04-29 20:59:121441 // If we change the zoom level for the view, make sure any subsequent subframe
1442 // loads reflect the current zoom level.
1443 page_zoom_level_ = zoom_level;
Blink Reformat1c4d759e2017-04-09 16:34:541444 webview()->SetZoomLevel(zoom_level);
ericwilligers88e69742016-10-17 19:29:551445 for (auto& observer : observers_)
1446 observer.OnZoomLevelChanged();
danakjcf409aa2019-09-20 15:22:301447 return true;
1448}
1449
1450void RenderViewImpl::SetPreferCompositingToLCDTextEnabled(bool prefer) {
1451 webview()->GetSettings()->SetPreferCompositingToLCDTextEnabled(prefer);
1452}
1453
1454void RenderViewImpl::SetDeviceScaleFactor(bool use_zoom_for_dsf,
1455 float device_scale_factor) {
1456 if (use_zoom_for_dsf)
1457 webview()->SetZoomFactorForDeviceScaleFactor(device_scale_factor);
1458 else
1459 webview()->SetDeviceScaleFactor(device_scale_factor);
1460}
1461
danakj748ef9092019-10-17 23:40:531462void RenderViewImpl::SetVisibleViewportSize(
1463 const gfx::Size& visible_viewport_size) {
1464 if (main_render_frame_) {
1465 // A local main frame controls the size of the WebView through
1466 // ResizeWebWidgetForWidget(). The VisualViewport is updated independently
1467 // here.
1468 webview()->ResizeVisualViewport(visible_viewport_size);
1469 } else {
1470 // RenderWidgets in a RenderView's frame tree without a local main frame
1471 // set the size of the WebView to be the |visible_viewport_size|, in order
1472 // to limit compositing in (out of process) child frames to what is visible.
1473 //
1474 // Note that child frames in the same process/RenderView frame tree as the
1475 // main frame do not benefit from this.
1476 webview()->Resize(visible_viewport_size);
1477 }
1478}
1479
danakjcf409aa2019-09-20 15:22:301480void RenderViewImpl::PropagatePageZoomToNewlyAttachedFrame(
1481 bool use_zoom_for_dsf,
1482 float device_scale_factor) {
1483 if (use_zoom_for_dsf)
1484 webview()->SetZoomFactorForDeviceScaleFactor(device_scale_factor);
1485 else
1486 webview()->SetZoomLevel(page_zoom_level_);
tommycli8aad3ba2015-08-12 17:57:591487}
1488
habib.virji597255e2014-09-09 00:30:181489void RenderViewImpl::SetValidationMessageDirection(
1490 base::string16* wrapped_main_text,
Miyoung Shin8dabef32020-02-19 16:25:251491 base::i18n::TextDirection main_text_hint,
habib.virji597255e2014-09-09 00:30:181492 base::string16* wrapped_sub_text,
Miyoung Shin8dabef32020-02-19 16:25:251493 base::i18n::TextDirection sub_text_hint) {
1494 if (main_text_hint == base::i18n::LEFT_TO_RIGHT) {
habib.virji597255e2014-09-09 00:30:181495 *wrapped_main_text =
1496 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
Miyoung Shin8dabef32020-02-19 16:25:251497 } else if (main_text_hint == base::i18n::RIGHT_TO_LEFT &&
habib.virji597255e2014-09-09 00:30:181498 !base::i18n::IsRTL()) {
1499 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
1500 }
1501
1502 if (!wrapped_sub_text->empty()) {
Miyoung Shin8dabef32020-02-19 16:25:251503 if (sub_text_hint == base::i18n::RIGHT_TO_LEFT) {
habib.virji597255e2014-09-09 00:30:181504 *wrapped_sub_text =
1505 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
Miyoung Shin8dabef32020-02-19 16:25:251506 } else if (sub_text_hint == base::i18n::LEFT_TO_RIGHT) {
habib.virji597255e2014-09-09 00:30:181507 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
1508 }
1509 }
1510}
1511
[email protected]310ebd6302011-10-10 19:06:281512void RenderViewImpl::UpdateTargetURL(const GURL& url,
1513 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581514 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521515 if (latest_url == target_url_)
1516 return;
[email protected]163f8242009-10-30 20:19:551517
[email protected]48c9cf2d2009-09-16 16:47:521518 // Tell the browser to display a destination link.
1519 if (target_url_status_ == TARGET_INFLIGHT ||
1520 target_url_status_ == TARGET_PENDING) {
1521 // If we have a request in-flight, save the URL to be sent when we
1522 // receive an ACK to the in-flight request. We can happily overwrite
1523 // any existing pending sends.
1524 pending_target_url_ = latest_url;
1525 target_url_status_ = TARGET_PENDING;
1526 } else {
mnaganovbf087422015-12-16 05:10:031527 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411528 // see |ParamTraits<GURL>|.
markdittmer67b71ea2016-03-03 22:40:031529 if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:411530 latest_url = GURL();
avia3dca182016-03-19 01:09:521531 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), latest_url));
[email protected]48c9cf2d2009-09-16 16:47:521532 target_url_ = latest_url;
1533 target_url_status_ = TARGET_INFLIGHT;
1534 }
1535}
1536
creis69b184a472015-11-26 05:29:511537void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) {
creisce0ef3572017-01-26 17:53:081538 // Keep track of which frames have pending updates.
1539 frames_with_pending_state_.insert(frame->GetRoutingID());
creis8eb8ef22015-11-04 22:51:381540
[email protected]882daa92009-11-05 16:31:311541 int delay;
avif937e1d2014-11-02 18:13:071542 if (send_content_state_immediately_)
[email protected]882daa92009-11-05 16:31:311543 delay = 0;
Collin Baker98457b52019-11-06 21:34:291544 else if (GetWebView()->GetVisibilityState() != PageVisibilityState::kVisible)
avif937e1d2014-11-02 18:13:071545 delay = kDelaySecondsForContentStateSyncHidden;
[email protected]882daa92009-11-05 16:31:311546 else
avif937e1d2014-11-02 18:13:071547 delay = kDelaySecondsForContentStateSync;
[email protected]882daa92009-11-05 16:31:311548
avif937e1d2014-11-02 18:13:071549 if (nav_state_sync_timer_.IsRunning()) {
[email protected]882daa92009-11-05 16:31:311550 // The timer is already running. If the delay of the timer maches the amount
1551 // we want to delay by, then return. Otherwise stop the timer so that it
1552 // gets started with the right delay.
avif937e1d2014-11-02 18:13:071553 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
[email protected]882daa92009-11-05 16:31:311554 return;
avif937e1d2014-11-02 18:13:071555 nav_state_sync_timer_.Stop();
[email protected]882daa92009-11-05 16:31:311556 }
1557
creisce0ef3572017-01-26 17:53:081558 // Tell each frame with pending state to inform the browser.
danakj19f3e512018-12-14 21:02:051559 nav_state_sync_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay),
1560 this, &RenderViewImpl::SendFrameStateUpdates);
[email protected]882daa92009-11-05 16:31:311561}
1562
Blink Reformat1c4d759e2017-04-09 16:34:541563void RenderViewImpl::SetMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551564 mouse_over_url_ = GURL(url);
1565 UpdateTargetURL(mouse_over_url_, focus_url_);
1566}
1567
Blink Reformat1c4d759e2017-04-09 16:34:541568void RenderViewImpl::SetKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551569 focus_url_ = GURL(url);
1570 UpdateTargetURL(focus_url_, mouse_over_url_);
1571}
1572
Blink Reformat1c4d759e2017-04-09 16:34:541573bool RenderViewImpl::AcceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451574 return renderer_preferences_.can_accept_load_drops;
1575}
1576
Blink Reformat1c4d759e2017-04-09 16:34:541577void RenderViewImpl::FocusNext() {
avia3dca182016-03-19 01:09:521578 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false));
[email protected]48c9cf2d2009-09-16 16:47:521579}
1580
Blink Reformat1c4d759e2017-04-09 16:34:541581void RenderViewImpl::FocusPrevious() {
avia3dca182016-03-19 01:09:521582 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true));
[email protected]48c9cf2d2009-09-16 16:47:521583}
1584
Kent Tamura69d143e2019-05-22 00:31:451585void RenderViewImpl::FocusedElementChanged(const WebElement& from_element,
1586 const WebElement& to_element) {
estade31c54342015-01-23 03:34:361587 RenderFrameImpl* previous_frame = nullptr;
Kent Tamura69d143e2019-05-22 00:31:451588 if (!from_element.IsNull())
Blink Reformat1c4d759e2017-04-09 16:34:541589 previous_frame =
Kent Tamura69d143e2019-05-22 00:31:451590 RenderFrameImpl::FromWebFrame(from_element.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361591 RenderFrameImpl* new_frame = nullptr;
Kent Tamura69d143e2019-05-22 00:31:451592 if (!to_element.IsNull())
1593 new_frame =
1594 RenderFrameImpl::FromWebFrame(to_element.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361595
1596 if (previous_frame && previous_frame != new_frame)
Kent Tamura69d143e2019-05-22 00:31:451597 previous_frame->FocusedElementChanged(WebElement());
estade31c54342015-01-23 03:34:361598 if (new_frame)
Kent Tamura69d143e2019-05-22 00:31:451599 new_frame->FocusedElementChanged(to_element);
[email protected]08e9e132010-06-01 16:58:491600}
1601
Philip Rogers079658812018-08-01 23:19:091602void RenderViewImpl::DidUpdateMainFrameLayout() {
ericwilligers88e69742016-10-17 19:29:551603 for (auto& observer : observers_)
Philip Rogers079658812018-08-01 23:19:091604 observer.DidUpdateMainFrameLayout();
[email protected]d01b2a62013-09-18 23:21:331605
Philip Rogers33cd2bcc2018-08-13 21:29:291606 // The main frame may have changed size.
1607 needs_preferred_size_update_ = true;
[email protected]169d4282011-11-30 19:33:591608}
1609
Michael Martis2415478f2019-04-17 07:35:001610void RenderViewImpl::RegisterRendererPreferenceWatcher(
Julie Jeongeun Kim6d8b7492019-08-20 19:24:111611 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
1612 renderer_preference_watchers_.Add(std::move(watcher));
Makoto Shimazuc3c730e2018-08-15 09:51:111613}
1614
Blink Reformat1c4d759e2017-04-09 16:34:541615int RenderViewImpl::HistoryBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001616 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521617}
1618
Blink Reformat1c4d759e2017-04-09 16:34:541619int RenderViewImpl::HistoryForwardListCount() {
1620 return history_list_length_ - HistoryBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521621}
1622
[email protected]180ef242013-11-07 06:50:461623// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:511624
Blink Reformat1c4d759e2017-04-09 16:34:541625bool RenderViewImpl::CanHandleGestureEvent() {
slangley1a6375e62017-03-29 06:03:231626 return true;
1627}
1628
Avi Drissman4a800482019-12-12 15:03:281629// TODO(https://crbug.com/937569): Remove this in Chrome 88.
Avi Drissmanfb961262019-03-05 22:50:291630bool RenderViewImpl::AllowPopupsDuringPageUnload() {
Avi Drissman16dfa1c2019-10-09 21:41:131631 // The switch version is for enabling via enterprise policy. The feature
1632 // version is for enabling via about:flags and Finch policy.
Avi Drissmanfb961262019-03-05 22:50:291633 const base::CommandLine& command_line =
1634 *base::CommandLine::ForCurrentProcess();
Avi Drissman7e5079f2019-09-30 14:06:401635 return command_line.HasSwitch(switches::kAllowPopupsDuringPageUnload) ||
1636 base::FeatureList::IsEnabled(features::kAllowPopupsDuringPageUnload);
Avi Drissmanfb961262019-03-05 22:50:291637}
1638
Blink Reformat1c4d759e2017-04-09 16:34:541639bool RenderViewImpl::CanUpdateLayout() {
slangley1a6375e62017-03-29 06:03:231640 return true;
1641}
1642
[email protected]b2324b092012-11-01 10:34:111643void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
1644 const std::string& value) {
Erik Chenf2772802019-10-04 22:16:251645 // This is test-only code. Only propagate the command if there is a main
1646 // render frame.
danakjee8f4902020-01-17 18:06:101647 if (main_render_frame_) {
1648 RenderWidget* widget = main_render_frame_->GetLocalRootRenderWidget();
1649 widget->SetEditCommandForNextKeyEvent(name, value);
1650 }
[email protected]b2324b092012-11-01 10:34:111651}
1652
1653void RenderViewImpl::ClearEditCommands() {
Erik Chenf2772802019-10-04 22:16:251654 // This is test-only code. Only propagate the command if there is a main
1655 // render frame.
danakjee8f4902020-01-17 18:06:101656 if (main_render_frame_) {
1657 RenderWidget* widget = main_render_frame_->GetLocalRootRenderWidget();
1658 widget->ClearEditCommands();
1659 }
[email protected]b2324b092012-11-01 10:34:111660}
1661
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491662const std::string& RenderViewImpl::GetAcceptLanguages() {
[email protected]b38806a2013-10-04 16:01:381663 return renderer_preferences_.accept_languages;
1664}
1665
Philip Rogers601fd072018-08-07 22:58:221666void RenderViewImpl::UpdatePreferredSize() {
[email protected]d812fd12011-05-27 23:05:071667 // We don't always want to send the change messages over IPC, only if we've
1668 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1669 // message.
danakj3dcceba2019-10-09 22:16:231670 if (!send_preferred_size_changes_ || !webview() || !main_render_frame_)
[email protected]d812fd12011-05-27 23:05:071671 return;
Philip Rogers33cd2bcc2018-08-13 21:29:291672
1673 if (!needs_preferred_size_update_)
1674 return;
1675 needs_preferred_size_update_ = false;
1676
danakj3dcceba2019-10-09 22:16:231677 blink::WebSize web_size = webview()->ContentsPreferredMinimumSize();
1678 blink::WebRect web_rect(0, 0, web_size.width, web_size.height);
danakjee8f4902020-01-17 18:06:101679 main_render_frame_->GetLocalRootRenderWidget()->ConvertViewportToWindow(
1680 &web_rect);
danakj3dcceba2019-10-09 22:16:231681 gfx::Size size(web_rect.width, web_rect.height);
[email protected]c27324b2009-11-19 22:44:291682
danakj3dcceba2019-10-09 22:16:231683 if (size != preferred_size_) {
1684 preferred_size_ = size;
1685 Send(new ViewHostMsg_DidContentsPreferredSizeChange(GetRoutingID(), size));
1686 }
[email protected]3d9689372009-09-10 04:29:171687}
1688
Blink Reformat1c4d759e2017-04-09 16:34:541689blink::WebString RenderViewImpl::AcceptLanguages() {
1690 return WebString::FromUTF8(renderer_preferences_.accept_languages);
[email protected]9982c802013-06-12 15:22:061691}
1692
[email protected]e9ff79c2012-10-19 21:31:261693// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:311694
[email protected]310ebd6302011-10-10 19:06:281695bool RenderViewImpl::Send(IPC::Message* message) {
danakj3130f122019-07-16 17:49:471696 // No messages sent through RenderView come without a routing id, yay. Let's
1697 // keep that up.
1698 CHECK_NE(message->routing_id(), MSG_ROUTING_NONE);
danakj3130f122019-07-16 17:49:471699 return RenderThread::Get()->Send(message);
[email protected]a2ef54c2011-10-10 16:20:311700}
1701
mostynbc33353232014-09-12 09:38:311702RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() {
nasko77de2312015-05-12 03:09:161703 return main_render_frame_;
[email protected]b849847b2013-12-10 21:57:581704}
1705
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491706int RenderViewImpl::GetRoutingID() {
Albert J. Wongcb004632018-07-10 22:58:251707 return routing_id_;
[email protected]a2ef54c2011-10-10 16:20:311708}
1709
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491710float RenderViewImpl::GetZoomLevel() {
Marc Treib06d66032017-10-19 08:43:201711 return page_zoom_level_;
1712}
1713
thestig8a8fdfd32017-05-06 18:46:541714const WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:311715 return webkit_preferences_;
1716}
1717
[email protected]324825d2012-11-30 12:37:151718void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
1719 OnUpdateWebPreferences(preferences);
1720}
1721
[email protected]180ef242013-11-07 06:50:461722blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:311723 return webview();
1724}
1725
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491726bool RenderViewImpl::GetContentStateImmediately() {
avif937e1d2014-11-02 18:13:071727 return send_content_state_immediately_;
[email protected]a2ef54c2011-10-10 16:20:311728}
1729
Collin Baker98457b52019-11-06 21:34:291730void RenderViewImpl::ApplyPageVisibilityState(
1731 PageVisibilityState visibility_state,
1732 bool initial_setting) {
1733 webview()->SetVisibilityState(visibility_state, initial_setting);
Collin Bakerc5259962019-11-14 17:51:581734 for (auto& observer : observers_)
1735 observer.OnPageVisibilityChanged(visibility_state);
danakj78744912018-11-30 23:46:421736 // Note: RenderWidget visibility is separately set from the IPC handlers, and
1737 // does not change when tests override the visibility of the Page.
danakj1b35e9d2018-11-07 19:09:281738}
1739
[email protected]310ebd6302011-10-10 19:06:281740void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:591741 webkit_preferences_ = prefs;
danakjfd0c7f42018-10-12 18:01:081742 ApplyWebPreferences(webkit_preferences_, webview());
initial.commit09911bf2008-07-26 23:55:291743}
1744
[email protected]2bf834f2011-11-17 20:02:211745void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:241746 if (send_preferred_size_changes_)
1747 return;
[email protected]9fb325e2010-05-06 18:23:241748 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:391749
Philip Rogers601fd072018-08-07 22:58:221750 if (!webview())
1751 return;
1752
Philip Rogers33cd2bcc2018-08-13 21:29:291753 needs_preferred_size_update_ = true;
1754
Philip Rogers601fd072018-08-07 22:58:221755 // We need to ensure |UpdatePreferredSize| gets called. If a layout is needed,
1756 // force an update here which will call |DidUpdateMainFrameLayout|.
Erik Chenab7ed492019-08-28 01:34:491757 if (webview()->MainFrameWidget()) {
1758 webview()->MainFrameWidget()->UpdateLifecycle(
1759 WebWidget::LifecycleUpdate::kLayout,
Stephen Chenneyd4b0f8a12020-01-31 22:55:451760 blink::DocumentUpdateReason::kSizeChange);
Erik Chenab7ed492019-08-28 01:34:491761 }
Philip Rogers601fd072018-08-07 22:58:221762
1763 // If a layout was not needed, |DidUpdateMainFrameLayout| will not be called.
1764 // We explicitly update the preferred size here to ensure the preferred size
1765 // notification is sent.
1766 UpdatePreferredSize();
[email protected]0666aef2009-05-13 19:48:081767}
1768
[email protected]310ebd6302011-10-10 19:06:281769void RenderViewImpl::OnSetRendererPrefs(
Leon Hanc819dc62019-01-28 04:30:191770 const blink::mojom::RendererPreferences& renderer_prefs) {
[email protected]ebd5ea52014-05-28 14:51:151771 std::string old_accept_languages = renderer_preferences_.accept_languages;
1772
[email protected]80d96fa2009-06-10 22:34:511773 renderer_preferences_ = renderer_prefs;
ananta59b9fe72015-04-07 01:33:261774
Julie Jeongeun Kim6d8b7492019-08-20 19:24:111775 for (auto& watcher : renderer_preference_watchers_)
1776 watcher->NotifyUpdate(renderer_prefs.Clone());
Makoto Shimazuc3c730e2018-08-15 09:51:111777
[email protected]6e282c92009-07-24 01:19:371778 UpdateFontRenderingFromRendererPrefs();
scottmgb92365e2016-08-30 20:54:401779 UpdateThemePrefs();
Leon Han2c81b5d2019-01-25 01:58:331780 blink::SetCaretBlinkInterval(
1781 renderer_prefs.caret_blink_interval.has_value()
1782 ? renderer_prefs.caret_blink_interval.value()
1783 : base::TimeDelta::FromMilliseconds(
Leon Hanc819dc62019-01-28 04:30:191784 blink::mojom::kDefaultCaretBlinkIntervalInMilliseconds));
[email protected]38a85712013-01-02 22:45:021785
Christopher Cameronf8e279d32019-05-15 18:50:561786#if defined(USE_AURA)
[email protected]1596efb2013-01-17 22:13:011787 if (renderer_prefs.use_custom_colors) {
Blink Reformat1c4d759e2017-04-09 16:34:541788 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
Christopher Cameronf6fc7ec2019-05-13 18:52:531789 blink::SetSelectionColors(renderer_prefs.active_selection_bg_color,
1790 renderer_prefs.active_selection_fg_color,
1791 renderer_prefs.inactive_selection_bg_color,
1792 renderer_prefs.inactive_selection_fg_color);
Erik Chenab7ed492019-08-28 01:34:491793 if (webview() && webview()->MainFrameWidget())
danakj763c2402018-11-09 02:46:221794 webview()->MainFrameWidget()->ThemeChanged();
[email protected]644d77e2010-01-27 01:03:101795 }
Christopher Cameronf8e279d32019-05-15 18:50:561796#endif
[email protected]d299d972012-03-23 02:26:551797
Ionel Popescu2649f2f2020-01-10 10:06:591798 if (features::IsFormControlsRefreshEnabled() &&
1799 renderer_prefs.use_custom_colors) {
1800 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
1801 }
1802
[email protected]ebd5ea52014-05-28 14:51:151803 if (webview() &&
1804 old_accept_languages != renderer_preferences_.accept_languages) {
Blink Reformat1c4d759e2017-04-09 16:34:541805 webview()->AcceptLanguagesChanged();
[email protected]ebd5ea52014-05-28 14:51:151806 }
[email protected]80d96fa2009-06-10 22:34:511807}
1808
[email protected]81375e872012-01-11 21:40:361809void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
Sergio Villar Senineb8c252452019-10-04 17:18:281810 const PluginAction& action) {
[email protected]81375e872012-01-11 21:40:361811 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:541812 webview()->PerformPluginAction(action, location);
[email protected]81375e872012-01-11 21:40:361813}
1814
[email protected]310ebd6302011-10-10 19:06:281815void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:001816 if (webview())
danakja5c39d52018-12-13 22:20:561817 webview()->CancelPagePopup();
[email protected]30f75e62009-02-25 22:01:001818}
1819
Collin Baker98457b52019-11-06 21:34:291820void RenderViewImpl::OnPageVisibilityChanged(
1821 PageVisibilityState visibility_state) {
braveyao1d8ee7b2017-03-29 21:10:041822#if defined(OS_ANDROID)
Collin Baker98457b52019-11-06 21:34:291823 SuspendVideoCaptureDevices(visibility_state != PageVisibilityState::kVisible);
braveyao1d8ee7b2017-03-29 21:10:041824#endif
[email protected]2d7b82c2012-06-01 05:57:501825
Collin Baker98457b52019-11-06 21:34:291826 ApplyPageVisibilityState(visibility_state,
1827 /*initial_setting=*/false);
[email protected]a6939ca42011-02-18 17:58:071828}
[email protected]1e6e3c992010-02-08 15:52:131829
Francois Doray47f759d2018-06-11 18:13:511830void RenderViewImpl::SetPageFrozen(bool frozen) {
1831 if (webview())
1832 webview()->SetPageFrozen(frozen);
Fadi Meawada6573e02018-03-10 00:52:111833}
1834
Yuzu Saijodfba8fa62019-08-27 02:15:221835void RenderViewImpl::PutPageIntoBackForwardCache() {
1836 if (webview())
1837 webview()->PutPageIntoBackForwardCache();
1838}
1839
Fergal Daly87f79d62019-11-11 01:24:041840void RenderViewImpl::RestorePageFromBackForwardCache(
1841 base::TimeTicks navigation_start) {
Yuzu Saijodfba8fa62019-08-27 02:15:221842 if (webview())
Fergal Daly87f79d62019-11-11 01:24:041843 webview()->RestorePageFromBackForwardCache(navigation_start);
Yuzu Saijodfba8fa62019-08-27 02:15:221844}
1845
W. James MacLean62198672019-06-04 16:46:101846// This function receives TextAutosizerPageInfo from the main frame's renderer
1847// and makes it available to other renderers with frames on the same page.
1848void RenderViewImpl::OnTextAutosizerPageInfoChanged(
1849 const blink::WebTextAutosizerPageInfo& page_info) {
1850 // Only propagate the remote page info if our main frame is remote. It's
1851 // possible a main frame renderer may receive this message, as SendPageMessage
1852 // in RenderFrameHostManager may send to a speculative RenderFrameHost that
1853 // corresponds to a local main frame. Since a local main frame will generate
1854 // these values for itself, we shouldn't override them with values from
1855 // another renderer.
1856 if (!webview()->MainFrame()->IsWebLocalFrame())
1857 webview()->SetTextAutosizePageInfo(page_info);
1858}
1859
Adithya Srinivasan11af2c52019-12-16 22:52:551860void RenderViewImpl::OnSetInsidePortal(bool inside_portal) {
1861 webview()->SetInsidePortal(inside_portal);
1862}
1863
W. James MacLean62198672019-06-04 16:46:101864void RenderViewImpl::DidUpdateTextAutosizerPageInfo(
1865 const blink::WebTextAutosizerPageInfo& page_info) {
1866 DCHECK(webview()->MainFrame()->IsWebLocalFrame());
1867 Send(new ViewHostMsg_NotifyTextAutosizerPageInfoChangedInLocalMainFrame(
1868 GetRoutingID(), page_info));
1869}
1870
danakj9a8a9cf2018-07-17 23:52:121871void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) {
Erik Chene4ae6b42019-10-01 12:06:281872 // Auto resize should only happen on local main frames.
danakjee8f4902020-01-17 18:06:101873 DCHECK(main_render_frame_);
1874 main_render_frame_->GetLocalRootRenderWidget()->DidAutoResize(newSize);
danakj9a8a9cf2018-07-17 23:52:121875}
1876
danakja2c9d0a92018-07-25 20:01:181877void RenderViewImpl::DidFocus(blink::WebLocalFrame* calling_frame) {
1878 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1879 // we won't have to test for user gesture anymore and we can
1880 // move that code back to render_widget.cc
Mustaq Ahmed4baa9a6e82019-12-20 23:43:461881 if (calling_frame && calling_frame->HasTransientUserActivation() &&
Kent Tamura2eab5b12018-12-07 04:31:231882 !RenderThreadImpl::current()->web_test_mode()) {
danakja2c9d0a92018-07-25 20:01:181883 Send(new ViewHostMsg_Focus(GetRoutingID()));
1884
1885 // Tattle on the frame that called |window.focus()|.
1886 RenderFrameImpl* calling_render_frame =
1887 RenderFrameImpl::FromWebFrame(calling_frame);
1888 if (calling_render_frame)
1889 calling_render_frame->FrameDidCallFocus();
1890 }
1891}
1892
[email protected]20657a82012-08-21 20:23:031893#if defined(OS_ANDROID)
braveyao1d8ee7b2017-03-29 21:10:041894void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) {
1895 if (!main_render_frame_)
1896 return;
1897
Guido Urdanetadc7090372019-07-29 17:59:541898 blink::WebMediaStreamDeviceObserver* media_stream_device_observer =
Antonio Gomes32f24faf2019-08-18 16:41:361899 main_render_frame_->MediaStreamDeviceObserver();
Chandan Padhi26dbd9b32017-11-27 11:13:351900 if (!media_stream_device_observer)
braveyao1d8ee7b2017-03-29 21:10:041901 return;
1902
Guido Urdaneta73fa6632019-01-14 18:46:261903 blink::MediaStreamDevices video_devices =
Chandan Padhi26dbd9b32017-11-27 11:13:351904 media_stream_device_observer->GetNonScreenCaptureDevices();
braveyao1d8ee7b2017-03-29 21:10:041905 RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices(
Chandan Padhi6dbfb732017-09-01 16:08:491906 video_devices, suspend);
braveyao1d8ee7b2017-03-29 21:10:041907}
estade6b9696bd2016-05-04 23:51:361908#endif // defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:031909
[email protected]b283d292013-02-21 08:40:341910unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
1911 return history_list_length_;
1912}
1913
[email protected]cc290f902013-03-04 20:06:021914void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
Nasko Oskova463a052018-05-08 16:42:141915 // If the main frame is remote, return immediately. Page level focus
1916 // should be set from the browser process, so if needed by tests it should
1917 // be properly supported.
danakjee8f4902020-01-17 18:06:101918 if (!main_render_frame_)
Nasko Oskova463a052018-05-08 16:42:141919 return;
1920
danakjee8f4902020-01-17 18:06:101921 RenderWidget* render_widget = main_render_frame_->GetLocalRootRenderWidget();
1922
1923 if (enable == render_widget->has_focus())
danakja2c9d0a92018-07-25 20:01:181924 return;
1925
[email protected]cc290f902013-03-04 20:06:021926 if (enable) {
danakja2c9d0a92018-07-25 20:01:181927 SetActiveForWidget(true);
1928 // Fake an IPC message so go through the IPC handler.
danakjee8f4902020-01-17 18:06:101929 render_widget->OnSetFocus(true);
[email protected]cc290f902013-03-04 20:06:021930 } else {
danakja2c9d0a92018-07-25 20:01:181931 // Fake an IPC message so go through the IPC handler.
danakjee8f4902020-01-17 18:06:101932 render_widget->OnSetFocus(false);
danakja2c9d0a92018-07-25 20:01:181933 SetActiveForWidget(false);
[email protected]cc290f902013-03-04 20:06:021934 }
1935}
1936
W. James MacLeand973a55b2018-11-29 21:39:131937void RenderViewImpl::OnAnimateDoubleTapZoomInMainFrame(
Dave Tapuskaff7b0612020-01-21 19:51:251938 const gfx::Point& point,
W. James MacLeand973a55b2018-11-29 21:39:131939 const blink::WebRect& bound) {
1940 webview()->AnimateDoubleTapZoom(point, bound);
1941}
1942
W. James MacLean5372eb72018-12-19 12:56:361943void RenderViewImpl::OnZoomToFindInPageRect(
1944 const blink::WebRect& rect_to_zoom) {
1945 webview()->ZoomToFindInPageRect(rect_to_zoom);
1946}
1947
danakjd51fd53d2018-12-21 23:06:091948void RenderViewImpl::OnSetBackgroundOpaque(bool opaque) {
1949 if (!webview())
1950 return;
1951
1952 if (opaque) {
1953 webview()->ClearBaseBackgroundColorOverride();
1954 webview()->ClearBackgroundColorOverride();
1955 } else {
1956 webview()->SetBaseBackgroundColorOverride(SK_ColorTRANSPARENT);
1957 webview()->SetBackgroundColorOverride(SK_ColorTRANSPARENT);
1958 }
1959}
1960
danakj295c43f182019-03-13 16:37:171961// static
1962scoped_refptr<base::SingleThreadTaskRunner>
1963RenderViewImpl::GetCleanupTaskRunner() {
1964 return RenderThreadImpl::current_blink_platform_impl()
1965 ->main_thread_scheduler()
1966 ->CleanupTaskRunner();
1967}
1968
[email protected]e9ff79c2012-10-19 21:31:261969} // namespace content