blob: a67945577c297b27ac6af1c0238dea9a0b2d79a5 [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"
[email protected]dc293a72013-07-01 11:11:2266#include "content/renderer/drop_data_builder.h"
[email protected]dc064352014-04-25 08:36:3867#include "content/renderer/history_serialization.h"
[email protected]66fca5bc2013-05-23 06:58:2968#include "content/renderer/ime_event_guard.h"
[email protected]92d457802013-04-01 19:18:4969#include "content/renderer/internal_document_state_data.h"
John Abd-El-Malek6b56ef712017-10-21 22:52:4670#include "content/renderer/loader/request_extra_data.h"
Amos Limbcc710e2018-06-08 05:51:1771#include "content/renderer/media/audio/audio_device_factory.h"
[email protected]227692c52013-05-31 22:43:0472#include "content/renderer/render_frame_impl.h"
[email protected]5a7100d2014-05-19 01:29:0473#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0574#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4475#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4476#include "content/renderer/render_widget_fullscreen_pepper.h"
Daniel Murphye3eec92c2018-02-23 19:09:1577#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]12a936d2013-05-15 04:55:4978#include "content/renderer/savable_resources.h"
John Abd-El-Malek312a30bb2017-10-23 19:51:5279#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:2180#include "content/renderer/web_ui_extension_data.h"
[email protected]f5961142013-04-17 23:09:4281#include "media/audio/audio_output_device.h"
[email protected]ee68378a2010-08-10 01:05:4182#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:4483#include "media/media_buildflags.h"
servolkf54f5c8f2015-02-24 20:32:3984#include "media/renderers/audio_renderer_impl.h"
Dale Curtis863022e2017-08-19 02:05:3485#include "media/video/gpu_video_accelerator_factories.h"
Julie Jeongeun Kimcaacf9102019-09-12 02:13:0586#include "mojo/public/cpp/bindings/pending_receiver.h"
[email protected]d1ef81d2012-07-24 11:39:3687#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2988#include "net/base/escape.h"
89#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:0990#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:0491#include "net/http/http_util.h"
Tarun Bansal73d67f02018-01-17 05:56:2592#include "net/nqe/effective_connection_type.h"
Scott Violet02e38b92018-03-27 23:42:1493#include "ppapi/buildflags/buildflags.h"
lukenb171b532014-09-24 05:50:3894#include "skia/ext/platform_canvas.h"
Blink Reformata30d4232018-04-07 15:31:0695#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
Daniel Murphy95792ef2018-10-04 01:29:5596#include "third_party/blink/public/common/dom_storage/session_storage_namespace_id.h"
Mustaq Ahmed76c2f4312018-06-07 20:48:0197#include "third_party/blink/public/common/frame/user_activation_update_source.h"
Dave Tapuska129cef82019-12-19 16:36:4898#include "third_party/blink/public/common/input/web_input_event.h"
Blink Reformata30d4232018-04-07 15:31:0699#include "third_party/blink/public/platform/file_path_conversion.h"
Antonio Gomes925f9b92019-07-30 23:23:23100#include "third_party/blink/public/platform/modules/video_capture/web_video_capture_impl_manager.h"
Blink Reformata30d4232018-04-07 15:31:06101#include "third_party/blink/public/platform/url_conversion.h"
102#include "third_party/blink/public/platform/web_connection_type.h"
103#include "third_party/blink/public/platform/web_effective_connection_type.h"
104#include "third_party/blink/public/platform/web_http_body.h"
Blink Reformata30d4232018-04-07 15:31:06105#include "third_party/blink/public/platform/web_input_event_result.h"
106#include "third_party/blink/public/platform/web_network_state_notifier.h"
Blink Reformata30d4232018-04-07 15:31:06107#include "third_party/blink/public/platform/web_rect.h"
108#include "third_party/blink/public/platform/web_runtime_features.h"
109#include "third_party/blink/public/platform/web_size.h"
110#include "third_party/blink/public/platform/web_string.h"
W. James MacLean62198672019-06-04 16:46:10111#include "third_party/blink/public/platform/web_text_autosizer_page_info.h"
Blink Reformata30d4232018-04-07 15:31:06112#include "third_party/blink/public/platform/web_url.h"
113#include "third_party/blink/public/platform/web_url_error.h"
114#include "third_party/blink/public/platform/web_url_request.h"
115#include "third_party/blink/public/platform/web_url_response.h"
116#include "third_party/blink/public/platform/web_vector.h"
117#include "third_party/blink/public/public_buildflags.h"
Guido Urdanetadc7090372019-07-29 17:59:54118#include "third_party/blink/public/web/modules/mediastream/web_media_stream_device_observer.h"
Blink Reformata30d4232018-04-07 15:31:06119#include "third_party/blink/public/web/web_autofill_client.h"
120#include "third_party/blink/public/web/web_ax_object.h"
Blink Reformata30d4232018-04-07 15:31:06121#include "third_party/blink/public/web/web_document.h"
122#include "third_party/blink/public/web/web_dom_event.h"
123#include "third_party/blink/public/web/web_dom_message_event.h"
124#include "third_party/blink/public/web/web_element.h"
Blink Reformata30d4232018-04-07 15:31:06125#include "third_party/blink/public/web/web_form_control_element.h"
126#include "third_party/blink/public/web/web_form_element.h"
127#include "third_party/blink/public/web/web_frame.h"
128#include "third_party/blink/public/web/web_frame_content_dumper.h"
129#include "third_party/blink/public/web/web_frame_widget.h"
130#include "third_party/blink/public/web/web_history_item.h"
131#include "third_party/blink/public/web/web_hit_test_result.h"
132#include "third_party/blink/public/web/web_input_element.h"
133#include "third_party/blink/public/web/web_local_frame.h"
Blink Reformata30d4232018-04-07 15:31:06134#include "third_party/blink/public/web/web_navigation_policy.h"
danakj25ec6e2b2018-09-26 17:01:31135#include "third_party/blink/public/web/web_page_popup.h"
Blink Reformata30d4232018-04-07 15:31:06136#include "third_party/blink/public/web/web_plugin.h"
Blink Reformata30d4232018-04-07 15:31:06137#include "third_party/blink/public/web/web_range.h"
138#include "third_party/blink/public/web/web_render_theme.h"
139#include "third_party/blink/public/web/web_script_source.h"
140#include "third_party/blink/public/web/web_searchable_form_data.h"
141#include "third_party/blink/public/web/web_security_policy.h"
142#include "third_party/blink/public/web/web_settings.h"
Blink Reformata30d4232018-04-07 15:31:06143#include "third_party/blink/public/web/web_view.h"
144#include "third_party/blink/public/web/web_window_features.h"
[email protected]b3a97b52014-07-09 06:25:05145#include "third_party/icu/source/common/unicode/uchar.h"
146#include "third_party/icu/source/common/unicode/uscript.h"
esecklerf2bd55f72017-03-31 09:11:57147#include "third_party/skia/include/core/SkColor.h"
Ionel Popescu2649f2f2020-01-10 10:06:59148#include "ui/base/ui_base_features.h"
[email protected]1400e6dc2013-04-27 02:36:27149#include "ui/base/ui_base_switches_util.h"
tfarina655f81d2014-12-23 02:38:50150#include "ui/gfx/geometry/point.h"
tfarina3b0452d2014-12-31 15:20:09151#include "ui/gfx/geometry/rect.h"
152#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32153#include "ui/gfx/geometry/size_conversions.h"
[email protected]08397d52011-02-05 01:53:38154#include "ui/gfx/native_widget_types.h"
ccameron772317d2017-06-04 18:35:03155#include "ui/gfx/switches.h"
mfomitchev3ba450ad2017-04-03 18:20:40156#include "ui/latency/latency_info.h"
csharrisond88f9752016-10-26 23:56:36157#include "url/origin.h"
markdittmer67b71ea2016-03-03 22:40:03158#include "url/url_constants.h"
[email protected]c4a9e932011-03-05 04:05:55159#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:29160
[email protected]25fb9b32012-04-27 03:21:55161#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25162#include <cpu-features.h>
163
dalecurtiscd971252016-09-21 16:09:00164#include "base/android/build_info.h"
kylechare7d8d5c72018-01-05 19:06:28165#include "content/child/child_thread_impl.h"
tfarina3b0452d2014-12-31 15:20:09166#include "ui/gfx/geometry/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40167
[email protected]78043bdd2010-04-05 18:45:33168#elif defined(OS_MACOSX)
169#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57170#endif
171
brettw4b461082016-11-19 18:55:16172#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]ea2fb972013-08-07 05:44:26173#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
174#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26175#endif
176
[email protected]180ef242013-11-07 06:50:46177using blink::WebAXObject;
[email protected]180ef242013-11-07 06:50:46178using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46179using blink::WebData;
[email protected]180ef242013-11-07 06:50:46180using blink::WebDocument;
[email protected]180ef242013-11-07 06:50:46181using blink::WebDragOperation;
[email protected]180ef242013-11-07 06:50:46182using blink::WebElement;
[email protected]180ef242013-11-07 06:50:46183using blink::WebFormControlElement;
184using blink::WebFormElement;
185using blink::WebFrame;
dglazkov03223492016-02-08 22:16:03186using blink::WebFrameContentDumper;
[email protected]180ef242013-11-07 06:50:46187using blink::WebGestureEvent;
188using blink::WebHistoryItem;
dglazkov8d0c21dd2016-08-06 15:56:36189using blink::WebHitTestResult;
Sergio Villar Senineb8c252452019-10-04 17:18:28190using blink::WebHTTPBody;
[email protected]180ef242013-11-07 06:50:46191using blink::WebInputElement;
192using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22193using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46194using blink::WebMouseEvent;
195using blink::WebNavigationPolicy;
196using blink::WebNavigationType;
197using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46198using blink::WebRect;
Sergio Villar Senineb8c252452019-10-04 17:18:28199using blink::WebRuntimeFeatures;
[email protected]180ef242013-11-07 06:50:46200using blink::WebScriptSource;
201using blink::WebSearchableFormData;
202using blink::WebSecurityOrigin;
203using blink::WebSecurityPolicy;
[email protected]180ef242013-11-07 06:50:46204using blink::WebSettings;
205using blink::WebSize;
[email protected]180ef242013-11-07 06:50:46206using blink::WebString;
[email protected]180ef242013-11-07 06:50:46207using blink::WebTouchEvent;
208using blink::WebURL;
209using blink::WebURLError;
210using blink::WebURLRequest;
211using blink::WebURLResponse;
[email protected]180ef242013-11-07 06:50:46212using blink::WebVector;
213using blink::WebView;
214using blink::WebWidget;
215using blink::WebWindowFeatures;
[email protected]e1acf6f2008-10-27 20:43:33216
[email protected]e9ff79c2012-10-19 21:31:26217namespace content {
218
initial.commit09911bf2008-07-26 23:55:29219//-----------------------------------------------------------------------------
220
[email protected]180ef242013-11-07 06:50:46221typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
jbroman8319b232017-03-08 22:53:29222static base::LazyInstance<ViewMap>::Leaky g_view_map =
[email protected]058561b2012-12-03 06:48:22223 LAZY_INSTANCE_INITIALIZER;
scottmg5e65e3a2017-03-08 08:48:46224typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap;
jbroman8319b232017-03-08 22:53:29225static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map =
226 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02227
[email protected]882daa92009-11-05 16:31:31228// Time, in seconds, we delay before sending content state changes (such as form
229// state and scroll position) to the browser. We delay sending changes to avoid
230// spamming the browser.
231// To avoid having tab/session restore require sending a message to get the
232// current content state during tab closing we use a shorter timeout for the
233// foreground renderer. This means there is a small window of time from which
234// content state is modified and not sent to session restore, but this is
235// better than having to wake up all renderers during shutdown.
avif937e1d2014-11-02 18:13:07236const int kDelaySecondsForContentStateSyncHidden = 5;
237const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29238
dcheng35d31c112015-07-22 00:17:36239static RenderViewImpl* (*g_create_render_view_impl)(
240 CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15241 const mojom::CreateViewParams&) = nullptr;
[email protected]8d41d7612012-11-14 20:32:19242
[email protected]c6bc20332014-02-28 18:30:39243// static
[email protected]65920f332014-03-04 21:14:18244WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32245 WebNavigationPolicy policy) {
246 switch (policy) {
Blink Reformat1c4d759e2017-04-09 16:34:54247 case blink::kWebNavigationPolicyDownload:
nick3b04f322016-08-31 19:29:19248 return WindowOpenDisposition::SAVE_TO_DISK;
Blink Reformat1c4d759e2017-04-09 16:34:54249 case blink::kWebNavigationPolicyCurrentTab:
nick3b04f322016-08-31 19:29:19250 return WindowOpenDisposition::CURRENT_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54251 case blink::kWebNavigationPolicyNewBackgroundTab:
nick3b04f322016-08-31 19:29:19252 return WindowOpenDisposition::NEW_BACKGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54253 case blink::kWebNavigationPolicyNewForegroundTab:
nick3b04f322016-08-31 19:29:19254 return WindowOpenDisposition::NEW_FOREGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54255 case blink::kWebNavigationPolicyNewWindow:
nick3b04f322016-08-31 19:29:19256 return WindowOpenDisposition::NEW_WINDOW;
Blink Reformat1c4d759e2017-04-09 16:34:54257 case blink::kWebNavigationPolicyNewPopup:
nick3b04f322016-08-31 19:29:19258 return WindowOpenDisposition::NEW_POPUP;
[email protected]48861e22013-01-09 00:27:32259 default:
260 NOTREACHED() << "Unexpected WebNavigationPolicy";
nick3b04f322016-08-31 19:29:19261 return WindowOpenDisposition::IGNORE_ACTION;
[email protected]48861e22013-01-09 00:27:32262 }
263}
264
initial.commit09911bf2008-07-26 23:55:29265///////////////////////////////////////////////////////////////////////////////
266
[email protected]217690d2012-01-27 07:33:11267namespace {
268
[email protected]b3a97b52014-07-09 06:25:05269typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
270 const base::string16&,
271 UScriptCode);
272
273void SetStandardFontFamilyWrapper(WebSettings* settings,
274 const base::string16& font,
275 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54276 settings->SetStandardFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05277}
278
279void SetFixedFontFamilyWrapper(WebSettings* settings,
280 const base::string16& font,
281 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54282 settings->SetFixedFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05283}
284
285void SetSerifFontFamilyWrapper(WebSettings* settings,
286 const base::string16& font,
287 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54288 settings->SetSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05289}
290
291void SetSansSerifFontFamilyWrapper(WebSettings* settings,
292 const base::string16& font,
293 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54294 settings->SetSansSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05295}
296
297void SetCursiveFontFamilyWrapper(WebSettings* settings,
298 const base::string16& font,
299 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54300 settings->SetCursiveFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05301}
302
303void SetFantasyFontFamilyWrapper(WebSettings* settings,
304 const base::string16& font,
305 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54306 settings->SetFantasyFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05307}
308
309void SetPictographFontFamilyWrapper(WebSettings* settings,
310 const base::string16& font,
311 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54312 settings->SetPictographFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05313}
314
315// If |scriptCode| is a member of a family of "similar" script codes, returns
316// the script code in that family that is used by WebKit for font selection
317// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
318// considered equivalent for the purposes of font selection. WebKit uses the
319// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
320// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
321// uses different scripts than the ones in Chrome pref names because the version
322// of ICU included on certain ports does not have some of the newer scripts. If
323// |scriptCode| is not a member of such a family, returns |scriptCode|.
324UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
325 switch (scriptCode) {
326 case USCRIPT_HIRAGANA:
327 case USCRIPT_KATAKANA:
328 case USCRIPT_JAPANESE:
329 return USCRIPT_KATAKANA_OR_HIRAGANA;
330 case USCRIPT_KOREAN:
331 return USCRIPT_HANGUL;
332 default:
333 return scriptCode;
334 }
335}
336
337void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
338 SetFontFamilyWrapper setter,
339 WebSettings* settings) {
jdoerrie5a73d0fa2018-10-02 23:54:05340 for (auto it = map.begin(); it != map.end(); ++it) {
avi1023d012015-12-25 02:39:14341 int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
[email protected]b3a97b52014-07-09 06:25:05342 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
343 UScriptCode code = static_cast<UScriptCode>(script);
344 (*setter)(settings, it->second, GetScriptForWebSettings(code));
345 }
346 }
347}
348
danakjefcb8432019-01-16 18:47:14349void ApplyCommandLineToSettings(WebSettings* settings) {
350 const base::CommandLine& command_line =
351 *base::CommandLine::ForCurrentProcess();
352
danakjed9464612019-01-16 00:00:59353 settings->SetThreadedScrollingEnabled(
354 !command_line.HasSwitch(switches::kDisableThreadedScrolling));
wangxianzhu3bf39be52015-04-10 23:56:41355
danakjed9464612019-01-16 00:00:59356 if (switches::IsTouchDragDropEnabled())
357 settings->SetTouchDragDropEnabled(true);
358
359 WebSettings::SelectionStrategyType selection_strategy;
360 if (command_line.GetSwitchValueASCII(switches::kTouchTextSelectionStrategy) ==
361 "direction")
362 selection_strategy = WebSettings::SelectionStrategyType::kDirection;
363 else
364 selection_strategy = WebSettings::SelectionStrategyType::kCharacter;
365 settings->SetSelectionStrategy(selection_strategy);
366
367 std::string passive_listeners_default =
368 command_line.GetSwitchValueASCII(switches::kPassiveListenersDefault);
369 if (!passive_listeners_default.empty()) {
370 WebSettings::PassiveEventListenerDefault passive_default =
371 WebSettings::PassiveEventListenerDefault::kFalse;
372 if (passive_listeners_default == "true")
373 passive_default = WebSettings::PassiveEventListenerDefault::kTrue;
374 else if (passive_listeners_default == "forcealltrue")
375 passive_default = WebSettings::PassiveEventListenerDefault::kForceAllTrue;
376 settings->SetPassiveEventListenerDefault(passive_default);
377 }
378
379 std::string network_quiet_timeout =
380 command_line.GetSwitchValueASCII(switches::kNetworkQuietTimeout);
381 if (!network_quiet_timeout.empty()) {
382 double network_quiet_timeout_seconds = 0.0;
383 if (base::StringToDouble(network_quiet_timeout,
384 &network_quiet_timeout_seconds))
385 settings->SetNetworkQuietTimeout(network_quiet_timeout_seconds);
386 }
387
388 if (command_line.HasSwitch(switches::kBlinkSettings)) {
389 std::vector<std::string> blink_settings = base::SplitString(
390 command_line.GetSwitchValueASCII(switches::kBlinkSettings), ",",
391 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
392 for (const std::string& setting : blink_settings) {
393 size_t pos = setting.find('=');
394 settings->SetFromStrings(
395 blink::WebString::FromLatin1(setting.substr(0, pos)),
396 blink::WebString::FromLatin1(
397 pos == std::string::npos ? "" : setting.substr(pos + 1)));
398 }
wangxianzhu3bf39be52015-04-10 23:56:41399 }
400}
401
scottmgde42fb92017-02-10 17:56:03402content::mojom::WindowContainerType WindowFeaturesToContainerType(
scottmg05324cb2017-02-09 23:46:04403 const blink::WebWindowFeatures& window_features) {
japhetbfc47892017-06-02 23:01:19404 if (window_features.background) {
405 if (window_features.persistent)
scottmgde42fb92017-02-10 17:56:03406 return content::mojom::WindowContainerType::PERSISTENT;
scottmg05324cb2017-02-09 23:46:04407 else
scottmgde42fb92017-02-10 17:56:03408 return content::mojom::WindowContainerType::BACKGROUND;
scottmg05324cb2017-02-09 23:46:04409 } else {
scottmgde42fb92017-02-10 17:56:03410 return content::mojom::WindowContainerType::NORMAL;
scottmg05324cb2017-02-09 23:46:04411 }
412}
413
[email protected]217690d2012-01-27 07:33:11414} // namespace
415
Hajime Hoshi315a61f2018-08-14 17:27:28416RenderViewImpl::RenderViewImpl(CompositorDependencies* compositor_deps,
417 const mojom::CreateViewParams& params)
Albert J. Wong7faa3da2019-03-21 20:43:43418 : routing_id_(params.view_id),
danakj73dd3032018-07-28 17:49:53419 renderer_wide_named_frame_lookup_(
420 params.renderer_wide_named_frame_lookup),
danakj77eb7e82020-01-09 19:38:46421 widgets_never_composited_(params.never_composited),
danakj4b8a2d9a2019-10-15 15:53:59422 compositor_deps_(compositor_deps),
naskobd911332014-11-25 01:13:36423 webkit_preferences_(params.web_preferences),
Jeremy Roman3bca4bf2019-07-11 03:41:25424 session_storage_namespace_id_(params.session_storage_namespace_id) {
Daniel Murphy95792ef2018-10-04 01:29:55425 DCHECK(!session_storage_namespace_id_.empty())
426 << "Session storage namespace must be populated.";
Albert J. Wong7faa3da2019-03-21 20:43:43427 // Please put all logic in RenderViewImpl::Initialize().
428}
Albert J. Wong7bbf22d2018-12-20 00:27:27429
Albert J. Wong7faa3da2019-03-21 20:43:43430void RenderViewImpl::Initialize(
Erik Chen10e9b022019-08-21 23:33:23431 CompositorDependencies* compositor_deps,
Albert J. Wong7faa3da2019-03-21 20:43:43432 mojom::CreateViewParamsPtr params,
433 RenderWidget::ShowCallback show_callback,
434 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Avi Drissman07d22452019-03-25 17:56:39435 DCHECK(RenderThread::IsMainThread());
436
Albert J. Wongcb004632018-07-10 22:58:25437 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]075366912013-02-18 07:13:24438
nickf7b38222016-11-22 21:59:35439#if defined(OS_ANDROID)
danakjc87bfede2018-10-10 22:32:49440 bool has_show_callback = !!show_callback;
nickf7b38222016-11-22 21:59:35441#endif
[email protected]676126f72011-01-15 00:03:51442
Antonio Gomesde8657a452020-05-25 17:14:47443 auto opener_frame_token =
Antonio Gomesb3dd5fc2020-05-25 22:53:27444 params->opener_frame_token.value_or(base::UnguessableToken());
445 auto* opener_frame = WebFrame::FromFrameToken(opener_frame_token);
Lukasz Anforowiczaf2f33572018-01-17 14:05:08446
Erik Chen562ca42b2019-08-22 19:46:06447 // The newly created webview_ is owned by this instance.
danakj284d557d2019-01-16 17:00:26448 webview_ = WebView::Create(this, params->hidden,
Sadrul Habib Chowdhury042a4712018-12-06 00:16:56449 /*compositing_enabled=*/true,
Yuzu Saijo797151f2020-02-28 09:08:27450 opener_frame ? opener_frame->View() : nullptr,
Daniel Cheng9a7c6c82020-04-25 04:58:17451 std::move(params->blink_page_broadcast));
Albert J. Wong2727e8a82019-02-15 16:56:11452
Antonio Gomes778a0f72020-02-24 13:52:44453 g_view_map.Get().insert(std::make_pair(GetWebView(), this));
avia3dca182016-03-19 01:09:52454 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this));
nasko4c0feb62015-06-05 18:37:06455
danakj242c2e12019-10-08 16:34:15456 bool local_main_frame = params->main_frame_routing_id != MSG_ROUTING_NONE;
457
Antonio Gomes778a0f72020-02-24 13:52:44458 ApplyWebPreferences(webkit_preferences_, GetWebView());
459 ApplyCommandLineToSettings(GetWebView()->GetSettings());
dcheng0ff94cfc2016-03-15 21:50:51460
danakj242c2e12019-10-08 16:34:15461 if (local_main_frame) {
dcheng3ce04b62015-10-26 23:30:55462 main_render_frame_ = RenderFrameImpl::CreateMainFrame(
Erik Chen10e9b022019-08-21 23:33:23463 this, compositor_deps, opener_frame, &params, std::move(show_callback));
danakjaf29226f2018-09-25 17:56:57464 } else {
Dave Tapuska84449382020-05-01 00:39:04465 RenderFrameProxy::CreateFrameProxy(
Antonio Gomesde8657a452020-05-25 17:14:47466 params->proxy_routing_id, GetRoutingID(), opener_frame_token,
Dave Tapuska84449382020-05-01 00:39:04467 MSG_ROUTING_NONE, params->replicated_frame_state,
468 params->main_frame_frame_token, params->devtools_main_frame_token);
nasko4c0feb62015-06-05 18:37:06469 }
470
[email protected]c7c0d822014-04-16 20:19:49471 // TODO(davidben): Move this state from Blink into content.
Balazs Engedyba034e72017-10-27 22:26:28472 if (params->window_was_created_with_opener)
Antonio Gomes778a0f72020-02-24 13:52:44473 GetWebView()->SetOpenedByDOM();
[email protected]c7c0d822014-04-16 20:19:49474
Leon Han2c81b5d2019-01-25 01:58:33475 OnSetRendererPrefs(*params->renderer_preferences);
[email protected]1784b2f2011-11-24 10:53:48476
[email protected]e9ff79c2012-10-19 21:31:26477 GetContentClient()->renderer()->RenderViewCreated(this);
Hajime Hoshif34374412018-03-05 14:32:54478
479 nav_state_sync_timer_.SetTaskRunner(task_runner);
danakjc87bfede2018-10-10 22:32:49480
Adithya Srinivasan46b8a792019-02-01 14:47:23481 // We pass this state to Page, but it's only used by the main frame in the
482 // page.
483 if (params->inside_portal)
Antonio Gomes778a0f72020-02-24 13:52:44484 GetWebView()->SetInsidePortal(true);
Adithya Srinivasan46b8a792019-02-01 14:47:23485
danakjc87bfede2018-10-10 22:32:49486#if defined(OS_ANDROID)
487 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated
488 // HandleNavigation codepath.
489 // Renderer-created RenderViews have a ShowCallback because they send a Show
490 // request (ViewHostMsg_ShowWidget, ViewHostMsg_ShowFullscreenWidget, or
491 // FrameHostMsg_ShowCreatedWindow) to the browser to attach them to the UI
492 // there. Browser-created RenderViews do not send a Show request to the
493 // browser, so have no such callback.
494 was_created_by_renderer_ = has_show_callback;
495#endif
initial.commit09911bf2008-07-26 23:55:29496}
497
[email protected]310ebd6302011-10-10 19:06:28498RenderViewImpl::~RenderViewImpl() {
danakjcdfc4262019-10-01 20:09:48499 DCHECK(destroying_); // Always deleted through Destroy().
danakjcdfc4262019-10-01 20:09:48500
501 g_routing_id_view_map.Get().erase(routing_id_);
Albert J. Wongcb004632018-07-10 22:58:25502 RenderThread::Get()->RemoveRoute(routing_id_);
dcheng3ce04b62015-10-26 23:30:55503
[email protected]60c42a8c72009-10-09 04:08:59504#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22505 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49506 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59507 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
508 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22509 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
510 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
511 it != routing_id_views->end(); ++it)
512 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59513#endif
[email protected]676126f72011-01-15 00:03:51514
ericwilligers88e69742016-10-17 19:29:55515 for (auto& observer : observers_)
516 observer.RenderViewGone();
517 for (auto& observer : observers_)
518 observer.OnDestruct();
[email protected]60c42a8c72009-10-09 04:08:59519}
520
521/*static*/
[email protected]310ebd6302011-10-10 19:06:28522RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
Avi Drissman07d22452019-03-25 17:56:39523 DCHECK(RenderThread::IsMainThread());
[email protected]a2ef54c2011-10-10 16:20:31524 ViewMap* views = g_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05525 auto it = views->find(webview);
[email protected]a2ef54c2011-10-10 16:20:31526 return it == views->end() ? NULL : it->second;
527}
528
529/*static*/
[email protected]180ef242013-11-07 06:50:46530RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28531 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31532}
533
534/*static*/
avi1023d012015-12-25 02:39:14535RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) {
Avi Drissman07d22452019-03-25 17:56:39536 DCHECK(RenderThread::IsMainThread());
[email protected]640e303c2012-12-05 01:36:07537 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05538 auto it = views->find(routing_id);
[email protected]640e303c2012-12-05 01:36:07539 return it == views->end() ? NULL : it->second;
540}
541
542/*static*/
543RenderView* RenderView::FromRoutingID(int routing_id) {
544 return RenderViewImpl::FromRoutingID(routing_id);
545}
546
[email protected]f3a95312014-06-12 16:46:58547/* static */
jochen9c7b8f242015-06-01 15:32:02548size_t RenderView::GetRenderViewCount() {
[email protected]f3a95312014-06-12 16:46:58549 return g_view_map.Get().size();
550}
551
[email protected]640e303c2012-12-05 01:36:07552/*static*/
[email protected]e9ff79c2012-10-19 21:31:26553void RenderView::ForEach(RenderViewVisitor* visitor) {
Avi Drissman07d22452019-03-25 17:56:39554 DCHECK(RenderThread::IsMainThread());
[email protected]625332e02010-12-14 07:48:49555 ViewMap* views = g_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05556 for (auto it = views->begin(); it != views->end(); ++it) {
[email protected]60c42a8c72009-10-09 04:08:59557 if (!visitor->Visit(it->second))
558 return;
559 }
560}
561
562/*static*/
[email protected]b3a97b52014-07-09 06:25:05563void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
564 WebView* web_view) {
Blink Reformat1c4d759e2017-04-09 16:34:54565 WebSettings* settings = web_view->GetSettings();
[email protected]b3a97b52014-07-09 06:25:05566 ApplyFontsFromMap(prefs.standard_font_family_map,
567 SetStandardFontFamilyWrapper, settings);
568 ApplyFontsFromMap(prefs.fixed_font_family_map,
569 SetFixedFontFamilyWrapper, settings);
570 ApplyFontsFromMap(prefs.serif_font_family_map,
571 SetSerifFontFamilyWrapper, settings);
572 ApplyFontsFromMap(prefs.sans_serif_font_family_map,
573 SetSansSerifFontFamilyWrapper, settings);
574 ApplyFontsFromMap(prefs.cursive_font_family_map,
575 SetCursiveFontFamilyWrapper, settings);
576 ApplyFontsFromMap(prefs.fantasy_font_family_map,
577 SetFantasyFontFamilyWrapper, settings);
578 ApplyFontsFromMap(prefs.pictograph_font_family_map,
579 SetPictographFontFamilyWrapper, settings);
Blink Reformat1c4d759e2017-04-09 16:34:54580 settings->SetDefaultFontSize(prefs.default_font_size);
581 settings->SetDefaultFixedFontSize(prefs.default_fixed_font_size);
582 settings->SetMinimumFontSize(prefs.minimum_font_size);
583 settings->SetMinimumLogicalFontSize(prefs.minimum_logical_font_size);
584 settings->SetDefaultTextEncodingName(
585 WebString::FromASCII(prefs.default_encoding));
586 settings->SetJavaScriptEnabled(prefs.javascript_enabled);
587 settings->SetWebSecurityEnabled(prefs.web_security_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54588 settings->SetLoadsImagesAutomatically(prefs.loads_images_automatically);
589 settings->SetImagesEnabled(prefs.images_enabled);
590 settings->SetPluginsEnabled(prefs.plugins_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54591 settings->SetDOMPasteAllowed(prefs.dom_paste_enabled);
592 settings->SetTextAreasAreResizable(prefs.text_areas_are_resizable);
593 settings->SetAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
594 settings->SetDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
595 settings->SetJavaScriptCanAccessClipboard(
[email protected]b3a97b52014-07-09 06:25:05596 prefs.javascript_can_access_clipboard);
Chris Cunninghame9b5ad742019-04-23 19:40:38597 WebRuntimeFeatures::EnableXSLT(prefs.xslt_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54598 settings->SetDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
Tarun Bansal333819e2018-05-15 16:38:42599 blink::WebNetworkStateNotifier::SetSaveDataEnabled(prefs.data_saver_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54600 settings->SetLocalStorageEnabled(prefs.local_storage_enabled);
601 settings->SetSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
602 WebRuntimeFeatures::EnableDatabase(prefs.databases_enabled);
603 settings->SetOfflineWebApplicationCacheEnabled(
[email protected]b3a97b52014-07-09 06:25:05604 prefs.application_cache_enabled);
Arthur Sonzogni721f48e2018-10-31 17:10:02605 settings->SetShouldProtectAgainstIpcFlooding(
606 !prefs.disable_ipc_flooding_protection);
Blink Reformat1c4d759e2017-04-09 16:34:54607 settings->SetHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
608 settings->SetCookieEnabled(prefs.cookie_enabled);
609 settings->SetNavigateOnDragDrop(prefs.navigate_on_drag_drop);
[email protected]b3a97b52014-07-09 06:25:05610
[email protected]b3a97b52014-07-09 06:25:05611 // By default, allow_universal_access_from_file_urls is set to false and thus
612 // we mitigate attacks from local HTML files by not granting file:// URLs
613 // universal access. Only test shell will enable this.
Blink Reformat1c4d759e2017-04-09 16:34:54614 settings->SetAllowUniversalAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05615 prefs.allow_universal_access_from_file_urls);
Blink Reformat1c4d759e2017-04-09 16:34:54616 settings->SetAllowFileAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05617 prefs.allow_file_access_from_file_urls);
618
Zhenyao Moa3fda9972017-09-16 01:34:40619 settings->SetWebGL1Enabled(prefs.webgl1_enabled);
620 settings->SetWebGL2Enabled(prefs.webgl2_enabled);
[email protected]b3a97b52014-07-09 06:25:05621
[email protected]b3a97b52014-07-09 06:25:05622 // Enable WebGL errors to the JS console if requested.
Blink Reformat1c4d759e2017-04-09 16:34:54623 settings->SetWebGLErrorsToConsoleEnabled(
[email protected]b3a97b52014-07-09 06:25:05624 prefs.webgl_errors_to_console_enabled);
625
Blink Reformat1c4d759e2017-04-09 16:34:54626 settings->SetHideScrollbars(prefs.hide_scrollbars);
eseckler61ff9142016-09-23 22:57:59627
[email protected]b3a97b52014-07-09 06:25:05628 // Enable gpu-accelerated 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54629 WebRuntimeFeatures::EnableAccelerated2dCanvas(
junov524668f22016-08-08 20:16:52630 prefs.accelerated_2d_canvas_enabled);
[email protected]b3a97b52014-07-09 06:25:05631
Aaron Krajeski229cffd2020-05-11 22:30:33632 // Enable new canvas 2d api features
633 WebRuntimeFeatures::EnableNewCanvas2DAPI(prefs.new_canvas_2d_api_enabled);
634
[email protected]b3a97b52014-07-09 06:25:05635 // Disable antialiasing for 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54636 settings->SetAntialiased2dCanvasEnabled(
[email protected]b3a97b52014-07-09 06:25:05637 !prefs.antialiased_2d_canvas_disabled);
638
zakerinasab20ebca02016-09-27 14:22:34639 // Disable antialiasing of clips for 2d canvas if requested on the command
robertphillipse25137b2014-10-20 13:44:34640 // line.
Blink Reformat1c4d759e2017-04-09 16:34:54641 settings->SetAntialiasedClips2dCanvasEnabled(
robertphillipse25137b2014-10-20 13:44:34642 prefs.antialiased_clips_2d_canvas_enabled);
643
[email protected]b3a97b52014-07-09 06:25:05644 // Set MSAA sample count for 2d canvas if requested on the command line (or
645 // default value if not).
Blink Reformat1c4d759e2017-04-09 16:34:54646 settings->SetAccelerated2dCanvasMSAASampleCount(
[email protected]b3a97b52014-07-09 06:25:05647 prefs.accelerated_2d_canvas_msaa_sample_count);
648
[email protected]b3a97b52014-07-09 06:25:05649 // Tabs to link is not part of the settings. WebCore calls
650 // ChromeClient::tabsToLinks which is part of the glue code.
Blink Reformat1c4d759e2017-04-09 16:34:54651 web_view->SetTabsToLinks(prefs.tabs_to_links);
[email protected]b3a97b52014-07-09 06:25:05652
Blink Reformat1c4d759e2017-04-09 16:34:54653 settings->SetAllowRunningOfInsecureContent(
[email protected]b3a97b52014-07-09 06:25:05654 prefs.allow_running_insecure_content);
Blink Reformat1c4d759e2017-04-09 16:34:54655 settings->SetDisableReadingFromCanvas(prefs.disable_reading_from_canvas);
656 settings->SetStrictMixedContentChecking(prefs.strict_mixed_content_checking);
mkwst2384c8222015-07-30 07:26:47657
Blink Reformat1c4d759e2017-04-09 16:34:54658 settings->SetStrictlyBlockBlockableMixedContent(
mkwst2384c8222015-07-30 07:26:47659 prefs.strictly_block_blockable_mixed_content);
660
Blink Reformat1c4d759e2017-04-09 16:34:54661 settings->SetStrictMixedContentCheckingForPlugin(
mkwst0d233e52015-08-10 09:33:14662 prefs.block_mixed_plugin_content);
663
Blink Reformat1c4d759e2017-04-09 16:34:54664 settings->SetStrictPowerfulFeatureRestrictions(
mkwst673a452f2015-01-10 14:41:50665 prefs.strict_powerful_feature_restrictions);
Blink Reformat1c4d759e2017-04-09 16:34:54666 settings->SetAllowGeolocationOnInsecureOrigins(
jww9d4ca2d2016-01-19 20:58:59667 prefs.allow_geolocation_on_insecure_origins);
Blink Reformat1c4d759e2017-04-09 16:34:54668 settings->SetPasswordEchoEnabled(prefs.password_echo_enabled);
669 settings->SetShouldPrintBackgrounds(prefs.should_print_backgrounds);
670 settings->SetShouldClearDocumentBackground(
[email protected]b3a97b52014-07-09 06:25:05671 prefs.should_clear_document_background);
Blink Reformat1c4d759e2017-04-09 16:34:54672 settings->SetEnableScrollAnimator(prefs.enable_scroll_animator);
Stephen McGruerbc3d0e62019-01-23 17:40:19673 settings->SetPrefersReducedMotion(prefs.prefers_reduced_motion);
[email protected]b3a97b52014-07-09 06:25:05674
Blink Reformat1c4d759e2017-04-09 16:34:54675 WebRuntimeFeatures::EnableTouchEventFeatureDetection(
sunyunjiafa6a8afc2016-12-09 04:25:47676 prefs.touch_event_feature_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54677 settings->SetMaxTouchPoints(prefs.pointer_events_max_touch_points);
678 settings->SetAvailablePointerTypes(prefs.available_pointer_types);
679 settings->SetPrimaryPointerType(
nzolghadrc0d1663c2015-11-26 21:15:24680 static_cast<blink::PointerType>(prefs.primary_pointer_type));
Blink Reformat1c4d759e2017-04-09 16:34:54681 settings->SetAvailableHoverTypes(prefs.available_hover_types);
682 settings->SetPrimaryHoverType(
nzolghadrc0d1663c2015-11-26 21:15:24683 static_cast<blink::HoverType>(prefs.primary_hover_type));
Blink Reformat1c4d759e2017-04-09 16:34:54684 settings->SetEnableTouchAdjustment(prefs.touch_adjustment_enabled);
Dave Tapuskaa59fdb62017-08-23 16:28:27685 settings->SetBarrelButtonForDragEnabled(prefs.barrel_button_for_drag_enabled);
[email protected]b3a97b52014-07-09 06:25:05686
Blink Reformat1c4d759e2017-04-09 16:34:54687 settings->SetShouldRespectImageOrientation(
[email protected]b3a97b52014-07-09 06:25:05688 prefs.should_respect_image_orientation);
689
Blink Reformat1c4d759e2017-04-09 16:34:54690 settings->SetEditingBehavior(
[email protected]b3a97b52014-07-09 06:25:05691 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
692
Blink Reformat1c4d759e2017-04-09 16:34:54693 settings->SetSupportsMultipleWindows(prefs.supports_multiple_windows);
[email protected]b3a97b52014-07-09 06:25:05694
Blink Reformat1c4d759e2017-04-09 16:34:54695 settings->SetMainFrameClipsContent(!prefs.record_whole_document);
khushalsagar2da2b232016-03-23 22:11:35696
Blink Reformat1c4d759e2017-04-09 16:34:54697 settings->SetSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
[email protected]b3a97b52014-07-09 06:25:05698
Blink Reformat1c4d759e2017-04-09 16:34:54699 settings->SetSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
Hugo Holgersson943ae692019-01-10 10:04:14700 // Spatnav depends on KeyboardFocusableScrollers. The WebUI team has
701 // disabled KFS because they need more time to update their custom elements,
702 // crbug.com/907284. Meanwhile, we pre-ship KFS to spatnav users.
703 if (prefs.spatial_navigation_enabled)
704 WebRuntimeFeatures::EnableKeyboardFocusableScrollers(true);
[email protected]b3a97b52014-07-09 06:25:05705
Bruce Long015d96f2019-07-12 22:59:10706 settings->SetCaretBrowsingEnabled(prefs.caret_browsing_enabled);
707
Blink Reformat1c4d759e2017-04-09 16:34:54708 settings->SetSelectionIncludesAltImageText(true);
[email protected]b3a97b52014-07-09 06:25:05709
Blink Reformat1c4d759e2017-04-09 16:34:54710 settings->SetV8CacheOptions(
[email protected]35103c02014-08-12 15:08:47711 static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options));
712
Blink Reformat1c4d759e2017-04-09 16:34:54713 settings->SetImageAnimationPolicy(
je_julie.kim7fbb5a1a2015-02-09 17:26:05714 static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy));
715
Blink Reformat1c4d759e2017-04-09 16:34:54716 settings->SetPresentationRequiresUserGesture(
zqzhang1215ad422016-02-10 13:27:22717 prefs.user_gesture_required_for_presentation);
718
Miyoung Shin3bcd82c2020-03-13 00:34:38719 if (prefs.text_tracks_enabled) {
720 settings->SetTextTrackKindUserPreference(
721 WebSettings::TextTrackKindUserPreference::kCaptions);
722 } else {
723 settings->SetTextTrackKindUserPreference(
724 WebSettings::TextTrackKindUserPreference::kDefault);
725 }
Elly Fong-Jonesf92897392019-01-24 16:05:49726 settings->SetTextTrackBackgroundColor(
727 WebString::FromASCII(prefs.text_track_background_color));
728 settings->SetTextTrackTextColor(
729 WebString::FromASCII(prefs.text_track_text_color));
Rahul Singh1862faa92019-03-06 22:41:43730 settings->SetTextTrackTextSize(
731 WebString::FromASCII(prefs.text_track_text_size));
732 settings->SetTextTrackTextShadow(
733 WebString::FromASCII(prefs.text_track_text_shadow));
734 settings->SetTextTrackFontFamily(
735 WebString::FromASCII(prefs.text_track_font_family));
Miyoung Shin3bcd82c2020-03-13 00:34:38736 settings->SetTextTrackFontStyle(
737 WebString::FromASCII(prefs.text_track_font_style));
Rahul Singh1862faa92019-03-06 22:41:43738 settings->SetTextTrackFontVariant(
739 WebString::FromASCII(prefs.text_track_font_variant));
Blink Reformat1c4d759e2017-04-09 16:34:54740 settings->SetTextTrackMarginPercentage(prefs.text_track_margin_percentage);
Abigail Klein74de85bd2019-07-11 19:11:56741 settings->SetTextTrackWindowColor(
742 WebString::FromASCII(prefs.text_track_window_color));
743 settings->SetTextTrackWindowPadding(
744 WebString::FromASCII(prefs.text_track_window_padding));
745 settings->SetTextTrackWindowRadius(
746 WebString::FromASCII(prefs.text_track_window_radius));
halliwell4002be42016-03-18 18:33:40747
David Bokana03511a92018-09-13 04:25:24748 // Needs to happen before SetDefaultPageScaleLimits below since that'll
749 // recalculate the final page scale limits and that depends on this setting.
750 settings->SetShrinksViewportContentToFit(
751 prefs.shrinks_viewport_contents_to_fit);
752
753 // Needs to happen before SetIgnoreViewportTagScaleLimits below.
Blink Reformat1c4d759e2017-04-09 16:34:54754 web_view->SetDefaultPageScaleLimits(prefs.default_minimum_page_scale_factor,
755 prefs.default_maximum_page_scale_factor);
dcheng5ae8ca362015-02-05 04:03:47756
Allan Sandfeld Jensene35337092019-05-15 13:56:09757 settings->SetFullscreenSupported(prefs.fullscreen_supported);
Ahmed Fakhry42221452018-05-30 01:18:39758 settings->SetTextAutosizingEnabled(prefs.text_autosizing_enabled);
759 settings->SetDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
Tarun Bansald10f17a02018-09-13 00:23:17760 blink::WebNetworkStateNotifier::SetNetworkQualityWebHoldback(
761 static_cast<blink::WebEffectiveConnectionType>(
762 prefs.network_quality_estimator_web_holdback));
Ahmed Fakhry42221452018-05-30 01:18:39763
chaopeng7e8fb352019-03-26 03:34:49764 settings->SetDontSendKeyEventsToJavascript(
765 prefs.dont_send_key_events_to_javascript);
Mounir Lamouri6926107f2019-01-31 18:17:43766 settings->SetWebAppScope(WebString::FromASCII(prefs.web_app_scope.spec()));
767
[email protected]b3a97b52014-07-09 06:25:05768#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:54769 settings->SetAllowCustomScrollbarInMainFrame(false);
Blink Reformat1c4d759e2017-04-09 16:34:54770 settings->SetAccessibilityFontScaleFactor(prefs.font_scale_factor);
771 settings->SetDeviceScaleAdjustment(prefs.device_scale_adjustment);
Blink Reformat1c4d759e2017-04-09 16:34:54772 web_view->SetIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
773 settings->SetAutoZoomFocusedNodeToLegibleScale(true);
Blink Reformat1c4d759e2017-04-09 16:34:54774 settings->SetDefaultVideoPosterURL(
775 WebString::FromASCII(prefs.default_video_poster_url.spec()));
776 settings->SetSupportDeprecatedTargetDensityDPI(
[email protected]b3a97b52014-07-09 06:25:05777 prefs.support_deprecated_target_density_dpi);
Blink Reformat1c4d759e2017-04-09 16:34:54778 settings->SetUseLegacyBackgroundSizeShorthandBehavior(
[email protected]b3a97b52014-07-09 06:25:05779 prefs.use_legacy_background_size_shorthand_behavior);
Blink Reformat1c4d759e2017-04-09 16:34:54780 settings->SetWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
781 settings->SetUseWideViewport(prefs.use_wide_viewport);
782 settings->SetForceZeroLayoutHeight(prefs.force_zero_layout_height);
Blink Reformat1c4d759e2017-04-09 16:34:54783 settings->SetViewportMetaMergeContentQuirk(
[email protected]b3a97b52014-07-09 06:25:05784 prefs.viewport_meta_merge_content_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54785 settings->SetViewportMetaNonUserScalableQuirk(
[email protected]b3a97b52014-07-09 06:25:05786 prefs.viewport_meta_non_user_scalable_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54787 settings->SetViewportMetaZeroValuesQuirk(
[email protected]b3a97b52014-07-09 06:25:05788 prefs.viewport_meta_zero_values_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54789 settings->SetClobberUserAgentInitialScaleQuirk(
[email protected]b3a97b52014-07-09 06:25:05790 prefs.clobber_user_agent_initial_scale_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54791 settings->SetIgnoreMainFrameOverflowHiddenQuirk(
[email protected]b3a97b52014-07-09 06:25:05792 prefs.ignore_main_frame_overflow_hidden_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54793 settings->SetReportScreenSizeInPhysicalPixelsQuirk(
[email protected]b3a97b52014-07-09 06:25:05794 prefs.report_screen_size_in_physical_pixels_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54795 settings->SetShouldReuseGlobalForUnownedMainFrame(
tzik30eb52c2018-03-27 06:55:18796 prefs.reuse_global_for_unowned_main_frame);
Blink Reformat1c4d759e2017-04-09 16:34:54797 settings->SetPreferHiddenVolumeControls(true);
798 settings->SetSpellCheckEnabledByDefault(prefs.spellcheck_enabled_by_default);
dalecurtiscd971252016-09-21 16:09:00799
Blink Reformat1c4d759e2017-04-09 16:34:54800 WebRuntimeFeatures::EnableVideoFullscreenOrientationLock(
mlamouri1d266bf2016-12-05 17:42:36801 prefs.video_fullscreen_orientation_lock_enabled);
johnme913ee5f2017-04-28 21:36:16802 WebRuntimeFeatures::EnableVideoRotateToFullscreen(
803 prefs.video_rotate_to_fullscreen_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54804 settings->SetEmbeddedMediaExperienceEnabled(
shaktisahuf97f7532017-02-24 22:46:13805 prefs.embedded_media_experience_enabled);
Ian Vollickeeca1d82018-02-07 02:43:42806 settings->SetImmersiveModeEnabled(prefs.immersive_mode_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54807 settings->SetDoNotUpdateSelectionOnMutatingSelectionRange(
changwane54ccdb92017-04-05 19:20:54808 prefs.do_not_update_selection_on_mutating_selection_range);
Noel Gordonf311a842017-07-27 00:10:07809 WebRuntimeFeatures::EnableCSSHexAlphaColor(prefs.css_hex_alpha_color_enabled);
Tobias Sargeant416174f2017-09-01 01:18:09810 WebRuntimeFeatures::EnableScrollTopLeftInterop(
811 prefs.scroll_top_left_interop_enabled);
Fernando Serboncini1fb12a82019-08-08 20:46:01812 WebRuntimeFeatures::EnableSurfaceEmbeddingFeatures(
813 !prefs.disable_features_depending_on_viz);
Aaron Krajeski0fb51282019-09-17 15:01:27814 WebRuntimeFeatures::EnableAcceleratedSmallCanvases(
815 !prefs.disable_accelerated_small_canvases);
Mason Freed8cbef172019-11-07 19:42:41816 if (prefs.reenable_web_components_v0) {
817 WebRuntimeFeatures::EnableShadowDOMV0(true);
818 WebRuntimeFeatures::EnableCustomElementsV0(true);
819 WebRuntimeFeatures::EnableHTMLImports(true);
820 }
zqzhangdf72ed082016-12-08 16:07:55821#endif // defined(OS_ANDROID)
Rune Lillesveenb46bb482019-04-02 07:36:29822 settings->SetForceDarkModeEnabled(prefs.force_dark_mode_enabled);
823
Alice Boxhallda2659142020-05-14 06:04:37824 settings->SetAccessibilityAlwaysShowFocus(prefs.always_show_focus);
825
mlamouri55a0543c2017-05-11 10:34:07826 switch (prefs.autoplay_policy) {
827 case AutoplayPolicy::kNoUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28828 settings->SetAutoplayPolicy(
829 WebSettings::AutoplayPolicy::kNoUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07830 break;
831 case AutoplayPolicy::kUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28832 settings->SetAutoplayPolicy(
833 WebSettings::AutoplayPolicy::kUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07834 break;
mlamouri431bb4e2017-06-06 08:54:24835 case AutoplayPolicy::kDocumentUserActivationRequired:
836 settings->SetAutoplayPolicy(
837 WebSettings::AutoplayPolicy::kDocumentUserActivationRequired);
838 break;
mlamouri55a0543c2017-05-11 10:34:07839 }
840
Blink Reformat1c4d759e2017-04-09 16:34:54841 settings->SetViewportEnabled(prefs.viewport_enabled);
842 settings->SetViewportMetaEnabled(prefs.viewport_meta_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54843 settings->SetViewportStyle(
alokp5d566962016-04-19 00:54:16844 static_cast<blink::WebViewportStyle>(prefs.viewport_style));
845
Blink Reformat1c4d759e2017-04-09 16:34:54846 settings->SetLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
847 settings->SetMainFrameResizesAreOrientationChanges(
yoava1a508b42015-10-20 12:03:21848 prefs.main_frame_resizes_are_orientation_changes);
849
Blink Reformat1c4d759e2017-04-09 16:34:54850 settings->SetShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up);
851 settings->SetAlwaysShowContextMenuOnTouch(
amaralp547e4192016-06-03 19:17:35852 prefs.always_show_context_menu_on_touch);
Sandra Sunc79fc93a2018-04-10 15:22:23853 settings->SetSmoothScrollForFindEnabled(prefs.smooth_scroll_for_find_enabled);
ccameron2fd70de72015-02-19 00:40:40854
Blink Reformat1c4d759e2017-04-09 16:34:54855 settings->SetHideDownloadUI(prefs.hide_download_ui);
qinmin72e8bd02016-10-21 19:35:37856
Blink Reformat1c4d759e2017-04-09 16:34:54857 settings->SetPresentationReceiver(prefs.presentation_receiver);
mlamouri57359d912016-11-29 20:11:50858
Blink Reformat1c4d759e2017-04-09 16:34:54859 settings->SetMediaControlsEnabled(prefs.media_controls_enabled);
mlamouri5cd9ae82017-02-18 11:05:09860
Tarun Bansal73d67f02018-01-17 05:56:25861 settings->SetLowPriorityIframesThreshold(
862 static_cast<blink::WebEffectiveConnectionType>(
863 prefs.low_priority_iframes_threshold));
864
Mounir Lamouri9c99a1602018-07-05 15:01:44865 settings->SetPictureInPictureEnabled(
866 prefs.picture_in_picture_enabled &&
[email protected]69db58f2018-09-26 20:27:56867 MediaFactory::GetVideoSurfaceLayerMode() !=
CJ DiMeglio89240472018-10-18 18:21:10868 blink::WebMediaPlayer::SurfaceLayerMode::kNever);
François Beaufort8c08979fc2018-03-05 13:06:31869
Tarun Bansal333819e2018-05-15 16:38:42870 settings->SetDataSaverHoldbackWebApi(
871 prefs.data_saver_holdback_web_api_enabled);
Tarun Bansal333819e2018-05-15 16:38:42872
rajendrante87ed712018-11-30 01:55:00873 settings->SetLazyLoadEnabled(prefs.lazy_load_enabled);
Alison Maher7f366dc62020-03-03 19:46:00874 settings->SetPreferredColorScheme(prefs.preferred_color_scheme);
rajendrante87ed712018-11-30 01:55:00875
Scott Little878f7d6702018-05-31 22:09:06876 for (const auto& ect_distance_pair :
877 prefs.lazy_frame_loading_distance_thresholds_px) {
878 switch (ect_distance_pair.first) {
879 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
880 settings->SetLazyFrameLoadingDistanceThresholdPxUnknown(
881 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39882 continue;
Scott Little878f7d6702018-05-31 22:09:06883 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
884 settings->SetLazyFrameLoadingDistanceThresholdPxOffline(
885 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39886 continue;
Scott Little878f7d6702018-05-31 22:09:06887 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
888 settings->SetLazyFrameLoadingDistanceThresholdPxSlow2G(
889 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39890 continue;
Scott Little878f7d6702018-05-31 22:09:06891 case net::EFFECTIVE_CONNECTION_TYPE_2G:
892 settings->SetLazyFrameLoadingDistanceThresholdPx2G(
893 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39894 continue;
Scott Little878f7d6702018-05-31 22:09:06895 case net::EFFECTIVE_CONNECTION_TYPE_3G:
896 settings->SetLazyFrameLoadingDistanceThresholdPx3G(
897 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39898 continue;
Scott Little878f7d6702018-05-31 22:09:06899 case net::EFFECTIVE_CONNECTION_TYPE_4G:
900 settings->SetLazyFrameLoadingDistanceThresholdPx4G(
901 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39902 continue;
903 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
904 continue;
Scott Little878f7d6702018-05-31 22:09:06905 }
rajendrantd8026342018-08-29 08:08:39906 NOTREACHED();
907 }
908
909 for (const auto& ect_distance_pair :
910 prefs.lazy_image_loading_distance_thresholds_px) {
911 switch (ect_distance_pair.first) {
912 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
913 settings->SetLazyImageLoadingDistanceThresholdPxUnknown(
914 ect_distance_pair.second);
915 continue;
916 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
917 settings->SetLazyImageLoadingDistanceThresholdPxOffline(
918 ect_distance_pair.second);
919 continue;
920 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
921 settings->SetLazyImageLoadingDistanceThresholdPxSlow2G(
922 ect_distance_pair.second);
923 continue;
924 case net::EFFECTIVE_CONNECTION_TYPE_2G:
925 settings->SetLazyImageLoadingDistanceThresholdPx2G(
926 ect_distance_pair.second);
927 continue;
928 case net::EFFECTIVE_CONNECTION_TYPE_3G:
929 settings->SetLazyImageLoadingDistanceThresholdPx3G(
930 ect_distance_pair.second);
931 continue;
932 case net::EFFECTIVE_CONNECTION_TYPE_4G:
933 settings->SetLazyImageLoadingDistanceThresholdPx4G(
934 ect_distance_pair.second);
935 continue;
936 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
937 continue;
938 }
939 NOTREACHED();
Scott Little878f7d6702018-05-31 22:09:06940 }
941
rajendrant3daeae292019-09-20 07:57:54942 for (const auto& fully_load_k_pair : prefs.lazy_image_first_k_fully_load) {
943 switch (fully_load_k_pair.first) {
944 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
945 continue;
946 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
947 settings->SetLazyImageFirstKFullyLoadUnknown(fully_load_k_pair.second);
948 continue;
949 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
950 settings->SetLazyImageFirstKFullyLoadSlow2G(fully_load_k_pair.second);
951 continue;
952 case net::EFFECTIVE_CONNECTION_TYPE_2G:
953 settings->SetLazyImageFirstKFullyLoad2G(fully_load_k_pair.second);
954 continue;
955 case net::EFFECTIVE_CONNECTION_TYPE_3G:
956 settings->SetLazyImageFirstKFullyLoad3G(fully_load_k_pair.second);
957 continue;
958 case net::EFFECTIVE_CONNECTION_TYPE_4G:
959 settings->SetLazyImageFirstKFullyLoad4G(fully_load_k_pair.second);
960 continue;
961 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
962 continue;
963 }
964 NOTREACHED();
965 }
966
ccameron2fd70de72015-02-19 00:40:40967#if defined(OS_MACOSX)
Blink Reformat1c4d759e2017-04-09 16:34:54968 web_view->SetMaximumLegibleScale(prefs.default_maximum_page_scale_factor);
ccameron2fd70de72015-02-19 00:40:40969#endif
sunyunjia87f287b2016-09-09 00:38:13970
971#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:54972 WebRuntimeFeatures::EnableMiddleClickAutoscroll(true);
sunyunjia87f287b2016-09-09 00:38:13973#endif
Dave Tapuskac6627e12018-08-30 15:07:19974
Dave Tapuskaa38e3252018-11-13 03:01:17975 WebRuntimeFeatures::EnableTranslateService(prefs.translate_service_available);
[email protected]b3a97b52014-07-09 06:25:05976}
977
978/*static*/
nickf7b38222016-11-22 21:59:35979RenderViewImpl* RenderViewImpl::Create(
980 CompositorDependencies* compositor_deps,
Balazs Engedyba034e72017-10-27 22:26:28981 mojom::CreateViewParamsPtr params,
danakjdf1ceb72018-07-18 20:02:25982 RenderWidget::ShowCallback show_callback,
Hajime Hoshiabb3c8f2017-12-04 18:41:39983 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Balazs Engedyba034e72017-10-27 22:26:28984 DCHECK(params->view_id != MSG_ROUTING_NONE);
danakjd434db42020-01-07 22:27:39985 // Frame and widget routing ids come together.
986 DCHECK_EQ(params->main_frame_routing_id == MSG_ROUTING_NONE,
987 params->main_frame_widget_routing_id == MSG_ROUTING_NONE);
988 // We have either a main frame or a proxy routing id.
989 DCHECK_NE(params->main_frame_routing_id != MSG_ROUTING_NONE,
990 params->proxy_routing_id != MSG_ROUTING_NONE);
[email protected]0287e762014-04-11 13:07:58991
danakjd434db42020-01-07 22:27:39992 RenderViewImpl* render_view;
Albert J. Wong7faa3da2019-03-21 20:43:43993 if (g_create_render_view_impl) {
994 render_view = g_create_render_view_impl(compositor_deps, *params);
995 } else {
996 render_view = new RenderViewImpl(compositor_deps, *params);
997 }
998
Erik Chen10e9b022019-08-21 23:33:23999 render_view->Initialize(compositor_deps, std::move(params),
Albert J. Wong7faa3da2019-03-21 20:43:431000 std::move(show_callback), std::move(task_runner));
[email protected]075366912013-02-18 07:13:241001 return render_view;
[email protected]8d41d7612012-11-14 20:32:191002}
1003
Erik Chen3433ee02019-08-05 20:14:261004void RenderViewImpl::Destroy() {
danakjcdfc4262019-10-01 20:09:481005 destroying_ = true;
1006
Erik Chen562ca42b2019-08-22 19:46:061007 webview_->Close();
Erik Chen3433ee02019-08-05 20:14:261008 // The webview_ is already destroyed by the time we get here, remove any
1009 // references to it.
1010 g_view_map.Get().erase(webview_);
1011 webview_ = nullptr;
Erik Chen562ca42b2019-08-22 19:46:061012
Erik Chen3433ee02019-08-05 20:14:261013 delete this;
1014}
1015
[email protected]8d41d7612012-11-14 20:32:191016// static
dcheng35d31c112015-07-22 00:17:361017void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
1018 *create_render_view_impl)(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:151019 const mojom::CreateViewParams&)) {
[email protected]8d41d7612012-11-14 20:32:191020 CHECK(!g_create_render_view_impl);
1021 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291022}
1023
[email protected]310ebd6302011-10-10 19:06:281024void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511025 observers_.AddObserver(observer);
1026}
1027
[email protected]310ebd6302011-10-10 19:06:281028void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1029 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511030 observers_.RemoveObserver(observer);
1031}
1032
danakja2c9d0a92018-07-25 20:01:181033// RenderWidgetOwnerDelegate -----------------------------------------
fsamuel72464894f2015-12-15 06:59:311034
danakja2c9d0a92018-07-25 20:01:181035void RenderViewImpl::SetActiveForWidget(bool active) {
Antonio Gomes778a0f72020-02-24 13:52:441036 if (GetWebView())
1037 GetWebView()->SetIsActive(active);
Albert J. Wongcb004632018-07-10 22:58:251038}
1039
danakja2c9d0a92018-07-25 20:01:181040bool RenderViewImpl::SupportsMultipleWindowsForWidget() {
1041 return webkit_preferences_.supports_multiple_windows;
1042}
1043
David Bokan11f6ef482019-03-18 17:47:271044bool RenderViewImpl::ShouldAckSyntheticInputImmediately() {
1045 // TODO(bokan): The RequestPresentation API appears not to function in VR. As
1046 // a short term workaround for https://crbug.com/940063, ACK input
1047 // immediately rather than using RequestPresentation.
1048 if (webkit_preferences_.immersive_mode_enabled)
1049 return true;
1050 return false;
1051}
1052
danakja2c9d0a92018-07-25 20:01:181053void RenderViewImpl::ApplyAutoResizeLimitsForWidget(const gfx::Size& min_size,
1054 const gfx::Size& max_size) {
Antonio Gomes778a0f72020-02-24 13:52:441055 GetWebView()->EnableAutoResizeMode(min_size, max_size);
danakja2c9d0a92018-07-25 20:01:181056}
1057
1058void RenderViewImpl::DisableAutoResizeForWidget() {
Antonio Gomes778a0f72020-02-24 13:52:441059 GetWebView()->DisableAutoResizeMode();
danakja2c9d0a92018-07-25 20:01:181060}
1061
1062void RenderViewImpl::ScrollFocusedNodeIntoViewForWidget() {
1063 if (WebLocalFrame* focused_frame = GetWebView()->FocusedFrame()) {
danakj5f069012019-10-09 23:14:171064 blink::WebFrameWidget* frame_widget =
1065 focused_frame->LocalRoot()->FrameWidget();
danakja2c9d0a92018-07-25 20:01:181066 frame_widget->ScrollFocusedEditableElementIntoView();
1067 }
1068}
1069
1070void RenderViewImpl::DidReceiveSetFocusEventForWidget() {
1071 // This message must always be received when the main frame is a
1072 // WebLocalFrame.
Albert J. Wong7bbf22d2018-12-20 00:27:271073 // TODO(ajwong): Can this be removed and just check |delegate_| in
danakja2c9d0a92018-07-25 20:01:181074 // RenderWidget instead?
Antonio Gomes778a0f72020-02-24 13:52:441075 CHECK(GetWebView()->MainFrame()->IsWebLocalFrame());
danakja2c9d0a92018-07-25 20:01:181076}
1077
danakja2c9d0a92018-07-25 20:01:181078void RenderViewImpl::DidCommitCompositorFrameForWidget() {
1079 for (auto& observer : observers_)
1080 observer.DidCommitCompositorFrame();
Antonio Gomesbc5ef252020-03-05 10:37:011081
1082 if (GetWebView())
1083 GetWebView()->UpdatePreferredSize();
danakja2c9d0a92018-07-25 20:01:181084}
1085
1086void RenderViewImpl::DidCompletePageScaleAnimationForWidget() {
1087 if (auto* focused_frame = GetWebView()->FocusedFrame()) {
1088 if (focused_frame->AutofillClient())
1089 focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame();
1090 }
1091}
1092
1093void RenderViewImpl::ResizeWebWidgetForWidget(
danakj748ef9092019-10-17 23:40:531094 const gfx::Size& widget_size,
danakjd4533c72020-03-11 13:07:101095 const gfx::Size& visible_viewport_size,
Sinan Sahin92a360bc2019-12-05 19:20:451096 cc::BrowserControlsParams browser_controls_params) {
danakjd4533c72020-03-11 13:07:101097 GetWebView()->ResizeWithBrowserControls(widget_size, visible_viewport_size,
1098 browser_controls_params);
danakja2c9d0a92018-07-25 20:01:181099}
1100
danakja2c9d0a92018-07-25 20:01:181101void RenderViewImpl::SetScreenMetricsEmulationParametersForWidget(
Andrey Kosyakov5bb020f2020-03-19 17:28:191102 bool enabled,
1103 const blink::WebDeviceEmulationParams& params) {
1104 if (enabled)
1105 GetWebView()->EnableDeviceEmulation(params);
1106 else
1107 GetWebView()->DisableDeviceEmulation();
danakja2c9d0a92018-07-25 20:01:181108}
1109
1110// IPC message handlers -----------------------------------------
1111
danakja2c9d0a92018-07-25 20:01:181112void RenderViewImpl::OnUpdateTargetURLAck() {
1113 // Check if there is a targeturl waiting to be sent.
1114 if (target_url_status_ == TARGET_PENDING)
1115 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), pending_target_url_));
1116
1117 target_url_status_ = TARGET_NONE;
1118}
1119
1120void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset,
1121 int history_length) {
1122 // -1 <= history_offset < history_length <= kMaxSessionHistoryEntries(50).
1123 DCHECK_LE(-1, history_offset);
1124 DCHECK_LT(history_offset, history_length);
1125 DCHECK_LE(history_length, kMaxSessionHistoryEntries);
1126
1127 history_list_offset_ = history_offset;
1128 history_list_length_ = history_length;
1129}
1130
danakja2c9d0a92018-07-25 20:01:181131void RenderViewImpl::OnAudioStateChanged(bool is_audio_playing) {
Antonio Gomes778a0f72020-02-24 13:52:441132 GetWebView()->AudioStateChanged(is_audio_playing);
danakja2c9d0a92018-07-25 20:01:181133}
1134
danakja2c9d0a92018-07-25 20:01:181135///////////////////////////////////////////////////////////////////////////////
1136
1137void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget,
1138 WebNavigationPolicy policy,
1139 const gfx::Rect& initial_rect) {
1140 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(),
1141 initial_rect));
1142}
1143
1144void RenderViewImpl::ShowCreatedFullscreenWidget(
1145 RenderWidget* fullscreen_widget,
1146 WebNavigationPolicy policy,
1147 const gfx::Rect& initial_rect) {
1148 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(),
1149 fullscreen_widget->routing_id()));
1150}
1151
1152void RenderViewImpl::SendFrameStateUpdates() {
1153 // Tell each frame with pending state to send its UpdateState message.
1154 for (int render_frame_routing_id : frames_with_pending_state_) {
1155 RenderFrameImpl* frame =
1156 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
1157 if (frame)
1158 frame->SendUpdateState();
1159 }
1160 frames_with_pending_state_.clear();
1161}
1162
danakja2c9d0a92018-07-25 20:01:181163// IPC::Listener -------------------------------------------------------------
fsamuel72464894f2015-12-15 06:59:311164
[email protected]310ebd6302011-10-10 19:06:281165bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
Antonio Gomes778a0f72020-02-24 13:52:441166 WebFrame* main_frame = GetWebView() ? GetWebView()->MainFrame() : nullptr;
Avi Drissmanb5f8e242017-12-12 05:21:561167 if (main_frame) {
1168 GURL active_url;
1169 if (main_frame->IsWebLocalFrame())
1170 active_url = main_frame->ToWebLocalFrame()->GetDocument().Url();
lukaszabedb4b22017-06-23 00:00:131171 GetContentClient()->SetActiveURL(
Avi Drissmanb5f8e242017-12-12 05:21:561172 active_url, main_frame->Top()->GetSecurityOrigin().ToString().Utf8());
1173 }
[email protected]f8b6b6f2009-03-10 16:48:261174
dchenga2d442c22016-10-13 15:39:211175 for (auto& observer : observers_) {
1176 if (observer.OnMessageReceived(message))
[email protected]676126f72011-01-15 00:03:511177 return true;
dchenga2d442c22016-10-13 15:39:211178 }
[email protected]b2abac72009-02-26 12:39:281179
[email protected]a95986a82010-12-24 06:19:281180 bool handled = true;
[email protected]e44d1342014-05-16 21:29:331181 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
initial.commit09911bf2008-07-26 23:55:291182 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1183 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]30f75e62009-02-25 22:01:001184 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
wjmaclean64951902016-04-29 20:59:121185
1186 // Page messages.
alexmos136fd6e62016-08-15 20:58:411187 IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength,
1188 OnSetHistoryOffsetAndLength)
altimind8bd26c2016-11-04 11:44:541189 IPC_MESSAGE_HANDLER(PageMsg_AudioStateChanged, OnAudioStateChanged)
Yuzu Saijodfba8fa62019-08-27 02:15:221190 IPC_MESSAGE_HANDLER(PageMsg_PutPageIntoBackForwardCache,
1191 PutPageIntoBackForwardCache)
1192 IPC_MESSAGE_HANDLER(PageMsg_RestorePageFromBackForwardCache,
1193 RestorePageFromBackForwardCache)
W. James MacLean62198672019-06-04 16:46:101194 IPC_MESSAGE_HANDLER(PageMsg_UpdateTextAutosizerPageInfoForRemoteMainFrames,
1195 OnTextAutosizerPageInfoChanged)
Bruce Long1e3e1f542019-10-16 17:56:281196 IPC_MESSAGE_HANDLER(PageMsg_SetRendererPrefs, OnSetRendererPrefs)
Adithya Srinivasan11af2c52019-12-16 22:52:551197 IPC_MESSAGE_HANDLER(PageMsg_SetInsidePortal, OnSetInsidePortal)
lfg717154072016-06-30 15:04:161198
[email protected]a794f3a2013-10-30 17:00:321199 // Adding a new message? Add platform independent ones first, then put the
1200 // platform specific ones at the end.
initial.commit09911bf2008-07-26 23:55:291201 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401202
[email protected]a95986a82010-12-24 06:19:281203 return handled;
initial.commit09911bf2008-07-26 23:55:291204}
1205
[email protected]180ef242013-11-07 06:50:461206// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521207
Mustaq Ahmed55944cb2018-05-25 20:44:271208// TODO(csharrison): Migrate this method to WebLocalFrameClient /
1209// RenderFrameImpl, as it is now serviced by a mojo interface scoped to the
1210// opener frame.
Daniel Murphyc8e991a2018-10-12 22:09:031211WebView* RenderViewImpl::CreateView(
1212 WebLocalFrame* creator,
1213 const WebURLRequest& request,
1214 const WebWindowFeatures& features,
1215 const WebString& frame_name,
1216 WebNavigationPolicy policy,
arthursonzognib93a4472020-04-10 07:38:001217 network::mojom::WebSandboxFlags sandbox_flags,
Ehsan Karamad39407082019-02-19 23:38:191218 const blink::FeaturePolicy::FeatureState& opener_feature_state,
Daniel Murphyc8e991a2018-10-12 22:09:031219 const blink::SessionStorageNamespaceId& session_storage_namespace_id) {
nick5ae4d2d2017-01-06 01:18:351220 RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator);
rockot5c478a72016-09-28 23:14:181221 mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New();
Mustaq Ahmedc4cb7162018-06-05 16:28:361222
Mustaq Ahmede5f12562019-10-30 18:02:031223 // The user activation check is done at the browser process through
1224 // |frame_host->CreateNewWindow()| call below. But the extensions case
1225 // handled through the following |if| is an exception.
Mustaq Ahmed8601a562020-01-31 18:05:521226 params->allow_popup = false;
[email protected]00323f02013-07-24 15:47:411227 if (GetContentClient()->renderer()->AllowPopup())
Mustaq Ahmed8601a562020-01-31 18:05:521228 params->allow_popup = true;
Mustaq Ahmedc4cb7162018-06-05 16:28:361229
rockot5c478a72016-09-28 23:14:181230 params->window_container_type = WindowFeaturesToContainerType(features);
Daniel Murphye3eec92c2018-02-23 19:09:151231
Daniel Murphyc8e991a2018-10-12 22:09:031232 params->session_storage_namespace_id = session_storage_namespace_id;
1233 // TODO(dmurph): Don't copy session storage when features.noopener is true:
1234 // https://html.spec.whatwg.org/multipage/browsers.html#copy-session-storage
1235 // https://crbug.com/771959
Daniel Murphye3eec92c2018-02-23 19:09:151236 params->clone_from_session_storage_namespace_id =
1237 session_storage_namespace_id_;
Daniel Murphye3eec92c2018-02-23 19:09:151238
Daniel Chengd5e56ff2017-06-24 07:44:021239 const std::string& frame_name_utf8 = frame_name.Utf8(
1240 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
1241 params->frame_name = frame_name_utf8;
Nate Chapin43f307d2019-04-15 21:04:411242 params->opener_suppressed = features.noopener;
rockot5c478a72016-09-28 23:14:181243 params->disposition = NavigationPolicyToDisposition(policy);
Blink Reformat1c4d759e2017-04-09 16:34:541244 if (!request.IsNull()) {
1245 params->target_url = request.Url();
Dominic Farolinoaee9c1b82019-12-18 03:20:101246 params->referrer = blink::mojom::Referrer::New(
1247 blink::WebStringToGURL(request.ReferrerString()),
1248 request.GetReferrerPolicy());
[email protected]44e55b012013-07-23 14:21:561249 }
scottmg8e6c6082017-02-13 23:15:481250 params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
[email protected]8ab04652010-06-12 02:47:261251
rockot5c478a72016-09-28 23:14:181252 // We preserve this information before sending the message since |params| is
1253 // moved on send.
1254 bool is_background_tab =
1255 params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB;
[email protected]22217ed32013-11-18 18:40:231256
Daniel Cheng8bb30c62017-10-23 20:40:471257 mojom::CreateNewWindowStatus status;
rockot5c478a72016-09-28 23:14:181258 mojom::CreateNewWindowReplyPtr reply;
Balazs Engedya40712f2017-09-15 15:01:111259 auto* frame_host = creator_frame->GetFrameHost();
Daniel Cheng8bb30c62017-10-23 20:40:471260 bool err = !frame_host->CreateNewWindow(std::move(params), &status, &reply);
1261 if (err || status == mojom::CreateNewWindowStatus::kIgnore)
rockot5c478a72016-09-28 23:14:181262 return nullptr;
[email protected]48c9cf2d2009-09-16 16:47:521263
Jochen Eisinger515337a2017-05-26 14:12:521264 // For Android WebView, we support a pop-up like behavior for window.open()
1265 // even if the embedding app doesn't support multiple windows. In this case,
1266 // window.open() will return "window" and navigate it to whatever URL was
Jochen Eisinger8cb28492017-10-04 10:58:131267 // passed. We also don't need to consume user gestures to protect against
1268 // multiple windows being opened, because, well, the app doesn't support
1269 // multiple windows.
Daniel Cheng8bb30c62017-10-23 20:40:471270 // TODO(dcheng): It's awkward that this is plumbed into Blink but not really
Kent Tamura21d1de62018-12-10 04:45:201271 // used much in Blink, except to enable web testing... perhaps this should
Daniel Cheng8bb30c62017-10-23 20:40:471272 // be checked directly in the browser side.
1273 if (status == mojom::CreateNewWindowStatus::kReuse)
Antonio Gomes778a0f72020-02-24 13:52:441274 return GetWebView();
Jochen Eisinger515337a2017-05-26 14:12:521275
Daniel Cheng8bb30c62017-10-23 20:40:471276 DCHECK(reply);
1277 DCHECK_NE(MSG_ROUTING_NONE, reply->route_id);
1278 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_route_id);
1279 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_widget_route_id);
1280
Mustaq Ahmed76c2f4312018-06-07 20:48:011281 // The browser allowed creation of a new window and consumed the user
Mustaq Ahmede5f12562019-10-30 18:02:031282 // activation.
Mustaq Ahmed4baa9a6e82019-12-20 23:43:461283 bool was_consumed = creator->ConsumeTransientUserActivation(
1284 blink::UserActivationUpdateSource::kBrowser);
Jochen Eisinger8cb28492017-10-04 10:58:131285
[email protected]7912e822014-04-16 02:37:031286 // While this view may be a background extension page, it can spawn a visible
1287 // render view. So we just assume that the new one is not another background
1288 // page instead of passing on our own value.
1289 // TODO(vangelis): Can we tell if the new view will be a background page?
danakj77eb7e82020-01-09 19:38:461290 bool never_composited = false;
[email protected]9115d5f2013-03-24 04:37:411291
[email protected]d6fa88f2013-10-18 16:00:431292 // The initial hidden state for the RenderViewImpl here has to match what the
1293 // browser will eventually decide for the given disposition. Since we have to
1294 // return from this call synchronously, we just have to make our best guess
1295 // and rely on the browser sending a WasHidden / WasShown message if it
1296 // disagrees.
Balazs Engedyba034e72017-10-27 22:26:281297 mojom::CreateViewParamsPtr view_params = mojom::CreateViewParams::New();
alexmos5ac402d2015-07-09 07:51:101298
Antonio Gomesb3dd5fc2020-05-25 22:53:271299 view_params->opener_frame_token = creator->GetFrameToken();
avia3dca182016-03-19 01:09:521300 DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID());
alexmos5ac402d2015-07-09 07:51:101301
Balazs Engedyba034e72017-10-27 22:26:281302 view_params->window_was_created_with_opener = true;
Leon Han2c81b5d2019-01-25 01:58:331303 view_params->renderer_preferences = renderer_preferences_.Clone();
Balazs Engedyba034e72017-10-27 22:26:281304 view_params->web_preferences = webkit_preferences_;
1305 view_params->view_id = reply->route_id;
Dave Tapuska84449382020-05-01 00:39:041306 view_params->main_frame_frame_token = reply->main_frame_frame_token;
Balazs Engedyba034e72017-10-27 22:26:281307 view_params->main_frame_routing_id = reply->main_frame_route_id;
Dave Tapuska8499eec2020-03-16 17:54:301308 view_params->frame_widget_host = std::move(reply->frame_widget_host);
1309 view_params->frame_widget = std::move(reply->frame_widget);
1310 view_params->widget_host = std::move(reply->widget_host);
1311 view_params->widget = std::move(reply->widget),
1312 view_params->main_frame_interface_bundle =
1313 mojom::DocumentScopedInterfaceBundle::New(
1314 std::move(reply->main_frame_interface_bundle->interface_provider),
1315 std::move(
1316 reply->main_frame_interface_bundle->browser_interface_broker));
Balazs Engedyba034e72017-10-27 22:26:281317 view_params->main_frame_widget_routing_id = reply->main_frame_widget_route_id;
1318 view_params->session_storage_namespace_id =
rockot5c478a72016-09-28 23:14:181319 reply->cloned_session_storage_namespace_id;
Daniel Murphy95792ef2018-10-04 01:29:551320 DCHECK(!view_params->session_storage_namespace_id.empty())
1321 << "Session storage namespace must be populated.";
Balazs Engedyba034e72017-10-27 22:26:281322 view_params->replicated_frame_state.frame_policy.sandbox_flags =
1323 sandbox_flags;
Ehsan Karamad39407082019-02-19 23:38:191324 view_params->replicated_frame_state.opener_feature_state =
1325 opener_feature_state;
Balazs Engedyba034e72017-10-27 22:26:281326 view_params->replicated_frame_state.name = frame_name_utf8;
1327 view_params->devtools_main_frame_token = reply->devtools_main_frame_token;
Balazs Engedyba034e72017-10-27 22:26:281328 view_params->hidden = is_background_tab;
danakj77eb7e82020-01-09 19:38:461329 view_params->never_composited = never_composited;
danakjbe56b8132019-10-12 00:57:411330 view_params->visual_properties = reply->visual_properties;
naskobd911332014-11-25 01:13:361331
nick5ae4d2d2017-01-06 01:18:351332 // Unretained() is safe here because our calling function will also call
1333 // show().
nickf7b38222016-11-22 21:59:351334 RenderWidget::ShowCallback show_callback =
danakjdf1ceb72018-07-18 20:02:251335 base::BindOnce(&RenderFrameImpl::ShowCreatedWindow,
Mustaq Ahmede5f12562019-10-30 18:02:031336 base::Unretained(creator_frame), was_consumed);
nickf7b38222016-11-22 21:59:351337
Balazs Engedyba034e72017-10-27 22:26:281338 RenderViewImpl* view = RenderViewImpl::Create(
danakj4b8a2d9a2019-10-15 15:53:591339 compositor_deps_, std::move(view_params), std::move(show_callback),
Hajime Hoshi6fc91142018-05-11 08:21:171340 creator->GetTaskRunner(blink::TaskType::kInternalDefault));
[email protected]48c9cf2d2009-09-16 16:47:521341
Yury Semikhatsky82730ff2020-02-25 22:29:261342 if (reply->wait_for_debugger) {
danakjd370dbb2020-05-21 17:54:381343 blink::WebFrameWidget* frame_widget =
1344 view->GetMainRenderFrame()->GetLocalRootWebFrameWidget();
1345 frame_widget->WaitForDebuggerWhenShown();
Yury Semikhatsky82730ff2020-02-25 22:29:261346 }
1347
Antonio Gomes778a0f72020-02-24 13:52:441348 return view->GetWebView();
[email protected]48c9cf2d2009-09-16 16:47:521349}
1350
danakj19f3e512018-12-14 21:02:051351blink::WebPagePopup* RenderViewImpl::CreatePopup(
1352 blink::WebLocalFrame* creator) {
Julie Jeongeun Kimcaacf9102019-09-12 02:13:051353 mojo::PendingRemote<mojom::Widget> widget_channel;
1354 mojo::PendingReceiver<mojom::Widget> widget_channel_receiver =
1355 widget_channel.InitWithNewPipeAndPassReceiver();
danakj25ec6e2b2018-09-26 17:01:311356
Dave Tapuska8499eec2020-03-16 17:54:301357 mojo::PendingAssociatedRemote<blink::mojom::Widget> blink_widget;
1358 mojo::PendingAssociatedReceiver<blink::mojom::Widget> blink_widget_receiver =
1359 blink_widget.InitWithNewEndpointAndPassReceiver();
1360
1361 mojo::PendingAssociatedRemote<blink::mojom::WidgetHost> blink_widget_host;
1362 mojo::PendingAssociatedReceiver<blink::mojom::WidgetHost>
1363 blink_widget_host_receiver =
1364 blink_widget_host.InitWithNewEndpointAndPassReceiver();
1365
danakj25ec6e2b2018-09-26 17:01:311366 // Do a synchronous IPC to obtain a routing ID.
1367 int32_t widget_routing_id = MSG_ROUTING_NONE;
1368 bool success =
Dave Tapuskad9835622020-03-10 17:32:311369 RenderFrameImpl::FromWebFrame(creator)->GetFrameHost()->CreateNewWidget(
Dave Tapuska8499eec2020-03-16 17:54:301370 std::move(widget_channel), std::move(blink_widget_host_receiver),
1371 std::move(blink_widget), &widget_routing_id);
danakj25ec6e2b2018-09-26 17:01:311372 if (!success) {
1373 // When the renderer is being killed the mojo message will fail.
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281374 return nullptr;
danakj25ec6e2b2018-09-26 17:01:311375 }
1376
1377 RenderWidget::ShowCallback opener_callback = base::BindOnce(
1378 &RenderViewImpl::ShowCreatedPopupWidget, weak_ptr_factory_.GetWeakPtr());
1379
danakj93593972019-10-11 00:02:491380 RenderWidget* opener_render_widget =
Erik Chen6bc8da02019-09-20 15:51:381381 RenderFrameImpl::FromWebFrame(creator)->GetLocalRootRenderWidget();
danakj25ec6e2b2018-09-26 17:01:311382
Erik Chen3433ee02019-08-05 20:14:261383 RenderWidget* popup_widget = RenderWidget::CreateForPopup(
danakj93593972019-10-11 00:02:491384 widget_routing_id, opener_render_widget->compositor_deps(),
danakj25ec6e2b2018-09-26 17:01:311385 /*hidden=*/false,
danakj77eb7e82020-01-09 19:38:461386 /*never_composited=*/false, std::move(widget_channel_receiver));
danakj25ec6e2b2018-09-26 17:01:311387
1388 // The returned WebPagePopup is self-referencing, so the pointer here is not
danakj45e4a4f2019-03-12 22:50:421389 // an owning pointer. It is de-referenced by calling Close().
danakj25ec6e2b2018-09-26 17:01:311390 blink::WebPagePopup* popup_web_widget =
Dave Tapuska8499eec2020-03-16 17:54:301391 blink::WebPagePopup::Create(popup_widget, std::move(blink_widget_host),
1392 std::move(blink_widget_receiver));
danakj25ec6e2b2018-09-26 17:01:311393
1394 // Adds a self-reference on the |popup_widget| so it will not be destroyed
1395 // when leaving scope. The WebPagePopup takes responsibility for Close()ing
1396 // and thus destroying the RenderWidget.
danakj93593972019-10-11 00:02:491397 popup_widget->InitForPopup(std::move(opener_callback), opener_render_widget,
1398 popup_web_widget,
1399 opener_render_widget->GetOriginalScreenInfo());
danakj25ec6e2b2018-09-26 17:01:311400 return popup_web_widget;
[email protected]48c9cf2d2009-09-16 16:47:521401}
1402
danakj295c43f182019-03-13 16:37:171403void RenderViewImpl::DoDeferredClose() {
1404 // The main widget is currently not active. The active main frame widget is
1405 // in a different process. Have the browser route the close request to the
1406 // active widget instead, so that the correct unload handlers are run.
1407 Send(new ViewHostMsg_RouteCloseEvent(GetRoutingID()));
1408}
1409
danakj45e4a4f2019-03-12 22:50:421410void RenderViewImpl::CloseWindowSoon() {
Avi Drissman07d22452019-03-25 17:56:391411 DCHECK(RenderThread::IsMainThread());
danakjd330a8b2020-01-16 20:59:141412 if (!main_render_frame_) {
danakj295c43f182019-03-13 16:37:171413 // Ask the RenderViewHost with a local main frame to initiate close. We
1414 // could be called from deep in Javascript. If we ask the RenderViewHost to
1415 // close now, the window could be closed before the JS finishes executing,
danakjbd1a86a2019-09-06 17:24:311416 // thanks to nested message loops running and handling the resulting Close
danakj295c43f182019-03-13 16:37:171417 // IPC. So instead, post a message back to the message loop, which won't run
1418 // until the JS is complete, and then the Close request can be sent.
1419 GetCleanupTaskRunner()->PostTask(
1420 FROM_HERE, base::BindOnce(&RenderViewImpl::DoDeferredClose,
1421 weak_ptr_factory_.GetWeakPtr()));
danakj45e4a4f2019-03-12 22:50:421422 return;
1423 }
1424
danakj50b37032020-01-15 22:44:001425 // If the main frame is in this RenderView's frame tree, then the Close
danakjd330a8b2020-01-16 20:59:141426 // request gets routed through the RenderWidget since non-frame RenderWidgets
1427 // share the code path.
danakjee8f4902020-01-17 18:06:101428 main_render_frame_->GetLocalRootRenderWidget()->CloseWidgetSoon();
danakj45e4a4f2019-03-12 22:50:421429}
1430
Daniel Murphy31bbb8b12018-02-07 21:44:101431base::StringPiece RenderViewImpl::GetSessionStorageNamespaceId() {
1432 CHECK(!session_storage_namespace_id_.empty());
Daniel Murphy0ce6e2c2017-11-21 01:54:261433 return session_storage_namespace_id_;
[email protected]bd92c3a2010-01-13 05:02:341434}
1435
Blink Reformat1c4d759e2017-04-09 16:34:541436void RenderViewImpl::PrintPage(WebLocalFrame* frame) {
Erik Chenfaa928c2019-09-20 23:41:151437 RenderFrameImpl* render_frame = RenderFrameImpl::FromWebFrame(frame);
1438 RenderWidget* render_widget = render_frame->GetLocalRootRenderWidget();
1439
1440 render_frame->ScriptedPrint(
1441 render_widget->input_handler().handling_input_event());
[email protected]48c9cf2d2009-09-16 16:47:521442}
1443
danakjcf409aa2019-09-20 15:22:301444bool RenderViewImpl::SetZoomLevel(double zoom_level) {
1445 if (zoom_level == page_zoom_level_)
1446 return false;
1447
wjmaclean64951902016-04-29 20:59:121448 // If we change the zoom level for the view, make sure any subsequent subframe
1449 // loads reflect the current zoom level.
1450 page_zoom_level_ = zoom_level;
Antonio Gomes778a0f72020-02-24 13:52:441451 GetWebView()->SetZoomLevel(zoom_level);
ericwilligers88e69742016-10-17 19:29:551452 for (auto& observer : observers_)
1453 observer.OnZoomLevelChanged();
danakjcf409aa2019-09-20 15:22:301454 return true;
1455}
1456
1457void RenderViewImpl::SetPreferCompositingToLCDTextEnabled(bool prefer) {
Antonio Gomes778a0f72020-02-24 13:52:441458 GetWebView()->GetSettings()->SetPreferCompositingToLCDTextEnabled(prefer);
danakjcf409aa2019-09-20 15:22:301459}
1460
1461void RenderViewImpl::SetDeviceScaleFactor(bool use_zoom_for_dsf,
1462 float device_scale_factor) {
1463 if (use_zoom_for_dsf)
Antonio Gomes778a0f72020-02-24 13:52:441464 GetWebView()->SetZoomFactorForDeviceScaleFactor(device_scale_factor);
danakjcf409aa2019-09-20 15:22:301465 else
Antonio Gomes778a0f72020-02-24 13:52:441466 GetWebView()->SetDeviceScaleFactor(device_scale_factor);
danakjcf409aa2019-09-20 15:22:301467}
1468
danakjd4533c72020-03-11 13:07:101469void RenderViewImpl::SetVisibleViewportSizeForChildLocalRoot(
1470 const gfx::Size& visible_viewport_size) {
1471 // The main frame is updated on a different path. If we're in the same frame
1472 // tree as it, there's nothing to do for child local roots.
1473 if (main_render_frame_)
1474 return;
1475
1476 // RenderWidgets in a RenderView's frame tree without a local main frame
1477 // set the size of the WebView to be the |visible_viewport_size|, in order
1478 // to limit compositing in (out of process) child frames to what is visible.
1479 //
1480 // Note that child frames in the same process/RenderView frame tree as the
1481 // main frame do not do this in order to not clobber the source of truth in
1482 // the main frame.
1483 GetWebView()->Resize(visible_viewport_size);
1484}
1485
danakjcf409aa2019-09-20 15:22:301486void RenderViewImpl::PropagatePageZoomToNewlyAttachedFrame(
1487 bool use_zoom_for_dsf,
1488 float device_scale_factor) {
1489 if (use_zoom_for_dsf)
Antonio Gomes778a0f72020-02-24 13:52:441490 GetWebView()->SetZoomFactorForDeviceScaleFactor(device_scale_factor);
danakjcf409aa2019-09-20 15:22:301491 else
Antonio Gomes778a0f72020-02-24 13:52:441492 GetWebView()->SetZoomLevel(page_zoom_level_);
tommycli8aad3ba2015-08-12 17:57:591493}
1494
habib.virji597255e2014-09-09 00:30:181495void RenderViewImpl::SetValidationMessageDirection(
1496 base::string16* wrapped_main_text,
Miyoung Shin8dabef32020-02-19 16:25:251497 base::i18n::TextDirection main_text_hint,
habib.virji597255e2014-09-09 00:30:181498 base::string16* wrapped_sub_text,
Miyoung Shin8dabef32020-02-19 16:25:251499 base::i18n::TextDirection sub_text_hint) {
1500 if (main_text_hint == base::i18n::LEFT_TO_RIGHT) {
habib.virji597255e2014-09-09 00:30:181501 *wrapped_main_text =
1502 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
Miyoung Shin8dabef32020-02-19 16:25:251503 } else if (main_text_hint == base::i18n::RIGHT_TO_LEFT &&
habib.virji597255e2014-09-09 00:30:181504 !base::i18n::IsRTL()) {
1505 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
1506 }
1507
1508 if (!wrapped_sub_text->empty()) {
Miyoung Shin8dabef32020-02-19 16:25:251509 if (sub_text_hint == base::i18n::RIGHT_TO_LEFT) {
habib.virji597255e2014-09-09 00:30:181510 *wrapped_sub_text =
1511 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
Miyoung Shin8dabef32020-02-19 16:25:251512 } else if (sub_text_hint == base::i18n::LEFT_TO_RIGHT) {
habib.virji597255e2014-09-09 00:30:181513 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
1514 }
1515 }
1516}
1517
[email protected]310ebd6302011-10-10 19:06:281518void RenderViewImpl::UpdateTargetURL(const GURL& url,
1519 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581520 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521521 if (latest_url == target_url_)
1522 return;
[email protected]163f8242009-10-30 20:19:551523
[email protected]48c9cf2d2009-09-16 16:47:521524 // Tell the browser to display a destination link.
1525 if (target_url_status_ == TARGET_INFLIGHT ||
1526 target_url_status_ == TARGET_PENDING) {
1527 // If we have a request in-flight, save the URL to be sent when we
1528 // receive an ACK to the in-flight request. We can happily overwrite
1529 // any existing pending sends.
1530 pending_target_url_ = latest_url;
1531 target_url_status_ = TARGET_PENDING;
1532 } else {
mnaganovbf087422015-12-16 05:10:031533 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411534 // see |ParamTraits<GURL>|.
markdittmer67b71ea2016-03-03 22:40:031535 if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:411536 latest_url = GURL();
avia3dca182016-03-19 01:09:521537 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), latest_url));
[email protected]48c9cf2d2009-09-16 16:47:521538 target_url_ = latest_url;
1539 target_url_status_ = TARGET_INFLIGHT;
1540 }
1541}
1542
creis69b184a472015-11-26 05:29:511543void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) {
creisce0ef3572017-01-26 17:53:081544 // Keep track of which frames have pending updates.
1545 frames_with_pending_state_.insert(frame->GetRoutingID());
creis8eb8ef22015-11-04 22:51:381546
[email protected]882daa92009-11-05 16:31:311547 int delay;
avif937e1d2014-11-02 18:13:071548 if (send_content_state_immediately_)
[email protected]882daa92009-11-05 16:31:311549 delay = 0;
Collin Baker98457b52019-11-06 21:34:291550 else if (GetWebView()->GetVisibilityState() != PageVisibilityState::kVisible)
avif937e1d2014-11-02 18:13:071551 delay = kDelaySecondsForContentStateSyncHidden;
[email protected]882daa92009-11-05 16:31:311552 else
avif937e1d2014-11-02 18:13:071553 delay = kDelaySecondsForContentStateSync;
[email protected]882daa92009-11-05 16:31:311554
avif937e1d2014-11-02 18:13:071555 if (nav_state_sync_timer_.IsRunning()) {
[email protected]882daa92009-11-05 16:31:311556 // The timer is already running. If the delay of the timer maches the amount
1557 // we want to delay by, then return. Otherwise stop the timer so that it
1558 // gets started with the right delay.
avif937e1d2014-11-02 18:13:071559 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
[email protected]882daa92009-11-05 16:31:311560 return;
avif937e1d2014-11-02 18:13:071561 nav_state_sync_timer_.Stop();
[email protected]882daa92009-11-05 16:31:311562 }
1563
creisce0ef3572017-01-26 17:53:081564 // Tell each frame with pending state to inform the browser.
danakj19f3e512018-12-14 21:02:051565 nav_state_sync_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay),
1566 this, &RenderViewImpl::SendFrameStateUpdates);
[email protected]882daa92009-11-05 16:31:311567}
1568
Blink Reformat1c4d759e2017-04-09 16:34:541569void RenderViewImpl::SetMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551570 mouse_over_url_ = GURL(url);
1571 UpdateTargetURL(mouse_over_url_, focus_url_);
1572}
1573
Blink Reformat1c4d759e2017-04-09 16:34:541574void RenderViewImpl::SetKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551575 focus_url_ = GURL(url);
1576 UpdateTargetURL(focus_url_, mouse_over_url_);
1577}
1578
Blink Reformat1c4d759e2017-04-09 16:34:541579bool RenderViewImpl::AcceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451580 return renderer_preferences_.can_accept_load_drops;
1581}
1582
Blink Reformat1c4d759e2017-04-09 16:34:541583void RenderViewImpl::FocusNext() {
avia3dca182016-03-19 01:09:521584 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false));
[email protected]48c9cf2d2009-09-16 16:47:521585}
1586
Blink Reformat1c4d759e2017-04-09 16:34:541587void RenderViewImpl::FocusPrevious() {
avia3dca182016-03-19 01:09:521588 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true));
[email protected]48c9cf2d2009-09-16 16:47:521589}
1590
Philip Rogers079658812018-08-01 23:19:091591void RenderViewImpl::DidUpdateMainFrameLayout() {
ericwilligers88e69742016-10-17 19:29:551592 for (auto& observer : observers_)
Philip Rogers079658812018-08-01 23:19:091593 observer.DidUpdateMainFrameLayout();
[email protected]169d4282011-11-30 19:33:591594}
1595
Michael Martis2415478f2019-04-17 07:35:001596void RenderViewImpl::RegisterRendererPreferenceWatcher(
Julie Jeongeun Kim6d8b7492019-08-20 19:24:111597 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
1598 renderer_preference_watchers_.Add(std::move(watcher));
Makoto Shimazuc3c730e2018-08-15 09:51:111599}
1600
Blink Reformat1c4d759e2017-04-09 16:34:541601int RenderViewImpl::HistoryBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001602 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521603}
1604
Blink Reformat1c4d759e2017-04-09 16:34:541605int RenderViewImpl::HistoryForwardListCount() {
1606 return history_list_length_ - HistoryBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521607}
1608
[email protected]180ef242013-11-07 06:50:461609// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:511610
Blink Reformat1c4d759e2017-04-09 16:34:541611bool RenderViewImpl::CanHandleGestureEvent() {
slangley1a6375e62017-03-29 06:03:231612 return true;
1613}
1614
Avi Drissman4a800482019-12-12 15:03:281615// TODO(https://crbug.com/937569): Remove this in Chrome 88.
Avi Drissmanfb961262019-03-05 22:50:291616bool RenderViewImpl::AllowPopupsDuringPageUnload() {
Avi Drissman16dfa1c2019-10-09 21:41:131617 // The switch version is for enabling via enterprise policy. The feature
1618 // version is for enabling via about:flags and Finch policy.
Avi Drissmanfb961262019-03-05 22:50:291619 const base::CommandLine& command_line =
1620 *base::CommandLine::ForCurrentProcess();
Avi Drissman7e5079f2019-09-30 14:06:401621 return command_line.HasSwitch(switches::kAllowPopupsDuringPageUnload) ||
1622 base::FeatureList::IsEnabled(features::kAllowPopupsDuringPageUnload);
Avi Drissmanfb961262019-03-05 22:50:291623}
1624
Yuzu Saijobe024af02020-05-11 07:35:561625void RenderViewImpl::OnPageVisibilityChanged(PageVisibilityState visibility) {
1626#if defined(OS_ANDROID)
1627 SuspendVideoCaptureDevices(visibility != PageVisibilityState::kVisible);
1628#endif
1629 for (auto& observer : observers_)
1630 observer.OnPageVisibilityChanged(visibility);
1631}
1632
Blink Reformat1c4d759e2017-04-09 16:34:541633bool RenderViewImpl::CanUpdateLayout() {
slangley1a6375e62017-03-29 06:03:231634 return true;
1635}
1636
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491637const std::string& RenderViewImpl::GetAcceptLanguages() {
[email protected]b38806a2013-10-04 16:01:381638 return renderer_preferences_.accept_languages;
1639}
1640
Blink Reformat1c4d759e2017-04-09 16:34:541641blink::WebString RenderViewImpl::AcceptLanguages() {
1642 return WebString::FromUTF8(renderer_preferences_.accept_languages);
[email protected]9982c802013-06-12 15:22:061643}
1644
[email protected]e9ff79c2012-10-19 21:31:261645// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:311646
[email protected]310ebd6302011-10-10 19:06:281647bool RenderViewImpl::Send(IPC::Message* message) {
danakj3130f122019-07-16 17:49:471648 // No messages sent through RenderView come without a routing id, yay. Let's
1649 // keep that up.
1650 CHECK_NE(message->routing_id(), MSG_ROUTING_NONE);
danakj3130f122019-07-16 17:49:471651 return RenderThread::Get()->Send(message);
[email protected]a2ef54c2011-10-10 16:20:311652}
1653
mostynbc33353232014-09-12 09:38:311654RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() {
nasko77de2312015-05-12 03:09:161655 return main_render_frame_;
[email protected]b849847b2013-12-10 21:57:581656}
1657
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491658int RenderViewImpl::GetRoutingID() {
Albert J. Wongcb004632018-07-10 22:58:251659 return routing_id_;
[email protected]a2ef54c2011-10-10 16:20:311660}
1661
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491662float RenderViewImpl::GetZoomLevel() {
Marc Treib06d66032017-10-19 08:43:201663 return page_zoom_level_;
1664}
1665
thestig8a8fdfd32017-05-06 18:46:541666const WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:311667 return webkit_preferences_;
1668}
1669
[email protected]324825d2012-11-30 12:37:151670void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
1671 OnUpdateWebPreferences(preferences);
1672}
1673
[email protected]180ef242013-11-07 06:50:461674blink::WebView* RenderViewImpl::GetWebView() {
Antonio Gomes778a0f72020-02-24 13:52:441675 return webview_;
[email protected]a2ef54c2011-10-10 16:20:311676}
1677
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491678bool RenderViewImpl::GetContentStateImmediately() {
avif937e1d2014-11-02 18:13:071679 return send_content_state_immediately_;
[email protected]a2ef54c2011-10-10 16:20:311680}
1681
[email protected]310ebd6302011-10-10 19:06:281682void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:591683 webkit_preferences_ = prefs;
Antonio Gomes778a0f72020-02-24 13:52:441684 ApplyWebPreferences(webkit_preferences_, GetWebView());
v.paturi8f6ed962020-03-17 18:03:101685 ApplyCommandLineToSettings(GetWebView()->GetSettings());
initial.commit09911bf2008-07-26 23:55:291686}
1687
[email protected]310ebd6302011-10-10 19:06:281688void RenderViewImpl::OnSetRendererPrefs(
Leon Hanc819dc62019-01-28 04:30:191689 const blink::mojom::RendererPreferences& renderer_prefs) {
[email protected]ebd5ea52014-05-28 14:51:151690 std::string old_accept_languages = renderer_preferences_.accept_languages;
1691
[email protected]80d96fa2009-06-10 22:34:511692 renderer_preferences_ = renderer_prefs;
ananta59b9fe72015-04-07 01:33:261693
Julie Jeongeun Kim6d8b7492019-08-20 19:24:111694 for (auto& watcher : renderer_preference_watchers_)
1695 watcher->NotifyUpdate(renderer_prefs.Clone());
Makoto Shimazuc3c730e2018-08-15 09:51:111696
[email protected]6e282c92009-07-24 01:19:371697 UpdateFontRenderingFromRendererPrefs();
scottmgb92365e2016-08-30 20:54:401698 UpdateThemePrefs();
Leon Han2c81b5d2019-01-25 01:58:331699 blink::SetCaretBlinkInterval(
1700 renderer_prefs.caret_blink_interval.has_value()
1701 ? renderer_prefs.caret_blink_interval.value()
1702 : base::TimeDelta::FromMilliseconds(
Leon Hanc819dc62019-01-28 04:30:191703 blink::mojom::kDefaultCaretBlinkIntervalInMilliseconds));
[email protected]38a85712013-01-02 22:45:021704
Christopher Cameronf8e279d32019-05-15 18:50:561705#if defined(USE_AURA)
[email protected]1596efb2013-01-17 22:13:011706 if (renderer_prefs.use_custom_colors) {
Blink Reformat1c4d759e2017-04-09 16:34:541707 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
Christopher Cameronf6fc7ec2019-05-13 18:52:531708 blink::SetSelectionColors(renderer_prefs.active_selection_bg_color,
1709 renderer_prefs.active_selection_fg_color,
1710 renderer_prefs.inactive_selection_bg_color,
1711 renderer_prefs.inactive_selection_fg_color);
Antonio Gomes778a0f72020-02-24 13:52:441712 if (GetWebView() && GetWebView()->MainFrameWidget())
1713 GetWebView()->MainFrameWidget()->ThemeChanged();
[email protected]644d77e2010-01-27 01:03:101714 }
Christopher Cameronf8e279d32019-05-15 18:50:561715#endif
[email protected]d299d972012-03-23 02:26:551716
Ionel Popescu2649f2f2020-01-10 10:06:591717 if (features::IsFormControlsRefreshEnabled() &&
1718 renderer_prefs.use_custom_colors) {
1719 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
1720 }
1721
Antonio Gomes778a0f72020-02-24 13:52:441722 if (GetWebView() &&
[email protected]ebd5ea52014-05-28 14:51:151723 old_accept_languages != renderer_preferences_.accept_languages) {
Antonio Gomes778a0f72020-02-24 13:52:441724 GetWebView()->AcceptLanguagesChanged();
[email protected]ebd5ea52014-05-28 14:51:151725 }
[email protected]80d96fa2009-06-10 22:34:511726}
1727
[email protected]310ebd6302011-10-10 19:06:281728void RenderViewImpl::OnMoveOrResizeStarted() {
Antonio Gomes778a0f72020-02-24 13:52:441729 if (GetWebView())
1730 GetWebView()->CancelPagePopup();
[email protected]30f75e62009-02-25 22:01:001731}
1732
Francois Doray47f759d2018-06-11 18:13:511733void RenderViewImpl::SetPageFrozen(bool frozen) {
Antonio Gomes778a0f72020-02-24 13:52:441734 if (GetWebView())
1735 GetWebView()->SetPageFrozen(frozen);
Fadi Meawada6573e02018-03-10 00:52:111736}
1737
Yuzu Saijodfba8fa62019-08-27 02:15:221738void RenderViewImpl::PutPageIntoBackForwardCache() {
Antonio Gomes778a0f72020-02-24 13:52:441739 if (GetWebView())
1740 GetWebView()->PutPageIntoBackForwardCache();
Yuzu Saijodfba8fa62019-08-27 02:15:221741}
1742
Fergal Daly87f79d62019-11-11 01:24:041743void RenderViewImpl::RestorePageFromBackForwardCache(
1744 base::TimeTicks navigation_start) {
Antonio Gomes778a0f72020-02-24 13:52:441745 if (GetWebView())
1746 GetWebView()->RestorePageFromBackForwardCache(navigation_start);
Yuzu Saijodfba8fa62019-08-27 02:15:221747}
1748
W. James MacLean62198672019-06-04 16:46:101749// This function receives TextAutosizerPageInfo from the main frame's renderer
1750// and makes it available to other renderers with frames on the same page.
1751void RenderViewImpl::OnTextAutosizerPageInfoChanged(
1752 const blink::WebTextAutosizerPageInfo& page_info) {
1753 // Only propagate the remote page info if our main frame is remote. It's
1754 // possible a main frame renderer may receive this message, as SendPageMessage
1755 // in RenderFrameHostManager may send to a speculative RenderFrameHost that
1756 // corresponds to a local main frame. Since a local main frame will generate
1757 // these values for itself, we shouldn't override them with values from
1758 // another renderer.
Antonio Gomes778a0f72020-02-24 13:52:441759 if (!GetWebView()->MainFrame()->IsWebLocalFrame())
Henrique Ferreiro6e80e25c2020-03-02 12:01:521760 GetWebView()->SetTextAutosizerPageInfo(page_info);
W. James MacLean62198672019-06-04 16:46:101761}
1762
Adithya Srinivasan11af2c52019-12-16 22:52:551763void RenderViewImpl::OnSetInsidePortal(bool inside_portal) {
Antonio Gomes778a0f72020-02-24 13:52:441764 GetWebView()->SetInsidePortal(inside_portal);
Adithya Srinivasan11af2c52019-12-16 22:52:551765}
1766
danakj9a8a9cf2018-07-17 23:52:121767void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) {
Erik Chene4ae6b42019-10-01 12:06:281768 // Auto resize should only happen on local main frames.
danakjee8f4902020-01-17 18:06:101769 DCHECK(main_render_frame_);
1770 main_render_frame_->GetLocalRootRenderWidget()->DidAutoResize(newSize);
danakj9a8a9cf2018-07-17 23:52:121771}
1772
danakja2c9d0a92018-07-25 20:01:181773void RenderViewImpl::DidFocus(blink::WebLocalFrame* calling_frame) {
danakj674bf1c02020-05-01 18:37:511774 // We only allow focus to move to this RenderView when the request comes from
1775 // a user gesture. (See also https://bugs.webkit.org/show_bug.cgi?id=33389.)
1776 if (calling_frame && calling_frame->HasTransientUserActivation()) {
danakja2c9d0a92018-07-25 20:01:181777 Send(new ViewHostMsg_Focus(GetRoutingID()));
1778
1779 // Tattle on the frame that called |window.focus()|.
1780 RenderFrameImpl* calling_render_frame =
1781 RenderFrameImpl::FromWebFrame(calling_frame);
1782 if (calling_render_frame)
1783 calling_render_frame->FrameDidCallFocus();
1784 }
1785}
1786
[email protected]20657a82012-08-21 20:23:031787#if defined(OS_ANDROID)
braveyao1d8ee7b2017-03-29 21:10:041788void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) {
1789 if (!main_render_frame_)
1790 return;
1791
Guido Urdanetadc7090372019-07-29 17:59:541792 blink::WebMediaStreamDeviceObserver* media_stream_device_observer =
Antonio Gomes32f24faf2019-08-18 16:41:361793 main_render_frame_->MediaStreamDeviceObserver();
Chandan Padhi26dbd9b32017-11-27 11:13:351794 if (!media_stream_device_observer)
braveyao1d8ee7b2017-03-29 21:10:041795 return;
1796
Guido Urdaneta73fa6632019-01-14 18:46:261797 blink::MediaStreamDevices video_devices =
Chandan Padhi26dbd9b32017-11-27 11:13:351798 media_stream_device_observer->GetNonScreenCaptureDevices();
braveyao1d8ee7b2017-03-29 21:10:041799 RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices(
Chandan Padhi6dbfb732017-09-01 16:08:491800 video_devices, suspend);
braveyao1d8ee7b2017-03-29 21:10:041801}
estade6b9696bd2016-05-04 23:51:361802#endif // defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:031803
[email protected]b283d292013-02-21 08:40:341804unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
1805 return history_list_length_;
1806}
1807
danakj295c43f182019-03-13 16:37:171808// static
1809scoped_refptr<base::SingleThreadTaskRunner>
1810RenderViewImpl::GetCleanupTaskRunner() {
1811 return RenderThreadImpl::current_blink_platform_impl()
1812 ->main_thread_scheduler()
1813 ->CleanupTaskRunner();
1814}
1815
[email protected]e9ff79c2012-10-19 21:31:261816} // namespace content