blob: 16b6279b2228f637fbcc51d0f8e95c4c9b6d9f4f [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"
kouhei40f03cb2015-09-24 07:47:0155#include "content/public/common/page_importance_signals.h"
clamyda97e8322014-10-07 21:57:2556#include "content/public/common/page_state.h"
Leon Han963dc182018-11-06 05:41:4857#include "content/public/common/referrer_type_converters.h"
[email protected]818915cd2012-11-20 13:14:1158#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0359#include "content/public/common/url_constants.h"
[email protected]b3a97b52014-07-09 06:25:0560#include "content/public/common/web_preferences.h"
[email protected]d344114c2011-10-01 01:24:3461#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0762#include "content/public/renderer/document_state.h"
Avi Drissman07d22452019-03-25 17:56:3963#include "content/public/renderer/render_thread.h"
[email protected]3a034ebb2011-10-03 19:19:4464#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3665#include "content/public/renderer/render_view_visitor.h"
scottmg8e6c6082017-02-13 23:15:4866#include "content/public/renderer/window_features_converter.h"
[email protected]e6e56752012-08-10 00:46:0667#include "content/renderer/browser_plugin/browser_plugin.h"
Sadrul Habib Chowdhury31c98712018-12-11 04:15:1368#include "content/renderer/compositor/layer_tree_view.h"
[email protected]dc293a72013-07-01 11:11:2269#include "content/renderer/drop_data_builder.h"
[email protected]dc064352014-04-25 08:36:3870#include "content/renderer/history_serialization.h"
[email protected]66fca5bc2013-05-23 06:58:2971#include "content/renderer/ime_event_guard.h"
[email protected]92d457802013-04-01 19:18:4972#include "content/renderer/internal_document_state_data.h"
John Abd-El-Malek6b56ef712017-10-21 22:52:4673#include "content/renderer/loader/request_extra_data.h"
Amos Limbcc710e2018-06-08 05:51:1774#include "content/renderer/media/audio/audio_device_factory.h"
Patrik Höglundb564859b2018-05-17 11:17:1675#include "content/renderer/media/webrtc/rtc_peer_connection_handler.h"
[email protected]227692c52013-05-31 22:43:0476#include "content/renderer/render_frame_impl.h"
[email protected]5a7100d2014-05-19 01:29:0477#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0578#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4479#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4480#include "content/renderer/render_widget_fullscreen_pepper.h"
Daniel Murphye3eec92c2018-02-23 19:09:1581#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]12a936d2013-05-15 04:55:4982#include "content/renderer/savable_resources.h"
John Abd-El-Malek312a30bb2017-10-23 19:51:5283#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:2184#include "content/renderer/web_ui_extension_data.h"
[email protected]f5961142013-04-17 23:09:4285#include "media/audio/audio_output_device.h"
[email protected]ee68378a2010-08-10 01:05:4186#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:4487#include "media/media_buildflags.h"
servolkf54f5c8f2015-02-24 20:32:3988#include "media/renderers/audio_renderer_impl.h"
Dale Curtis863022e2017-08-19 02:05:3489#include "media/video/gpu_video_accelerator_factories.h"
Julie Jeongeun Kimcaacf9102019-09-12 02:13:0590#include "mojo/public/cpp/bindings/pending_receiver.h"
[email protected]d1ef81d2012-07-24 11:39:3691#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2992#include "net/base/escape.h"
93#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:0994#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:0495#include "net/http/http_util.h"
Tarun Bansal73d67f02018-01-17 05:56:2596#include "net/nqe/effective_connection_type.h"
Scott Violet02e38b92018-03-27 23:42:1497#include "ppapi/buildflags/buildflags.h"
lukenb171b532014-09-24 05:50:3898#include "skia/ext/platform_canvas.h"
Blink Reformata30d4232018-04-07 15:31:0699#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
Daniel Murphy95792ef2018-10-04 01:29:55100#include "third_party/blink/public/common/dom_storage/session_storage_namespace_id.h"
Mustaq Ahmed76c2f4312018-06-07 20:48:01101#include "third_party/blink/public/common/frame/user_activation_update_source.h"
Sergio Villar Senineb8c252452019-10-04 17:18:28102#include "third_party/blink/public/common/plugin/plugin_action.h"
Blink Reformata30d4232018-04-07 15:31:06103#include "third_party/blink/public/platform/file_path_conversion.h"
Antonio Gomes925f9b92019-07-30 23:23:23104#include "third_party/blink/public/platform/modules/video_capture/web_video_capture_impl_manager.h"
Blink Reformata30d4232018-04-07 15:31:06105#include "third_party/blink/public/platform/url_conversion.h"
106#include "third_party/blink/public/platform/web_connection_type.h"
107#include "third_party/blink/public/platform/web_effective_connection_type.h"
108#include "third_party/blink/public/platform/web_http_body.h"
109#include "third_party/blink/public/platform/web_image.h"
110#include "third_party/blink/public/platform/web_input_event.h"
111#include "third_party/blink/public/platform/web_input_event_result.h"
112#include "third_party/blink/public/platform/web_network_state_notifier.h"
113#include "third_party/blink/public/platform/web_point.h"
114#include "third_party/blink/public/platform/web_rect.h"
115#include "third_party/blink/public/platform/web_runtime_features.h"
116#include "third_party/blink/public/platform/web_size.h"
117#include "third_party/blink/public/platform/web_string.h"
W. James MacLean62198672019-06-04 16:46:10118#include "third_party/blink/public/platform/web_text_autosizer_page_info.h"
Blink Reformata30d4232018-04-07 15:31:06119#include "third_party/blink/public/platform/web_url.h"
120#include "third_party/blink/public/platform/web_url_error.h"
121#include "third_party/blink/public/platform/web_url_request.h"
122#include "third_party/blink/public/platform/web_url_response.h"
123#include "third_party/blink/public/platform/web_vector.h"
124#include "third_party/blink/public/public_buildflags.h"
Guido Urdanetadc7090372019-07-29 17:59:54125#include "third_party/blink/public/web/modules/mediastream/web_media_stream_device_observer.h"
Blink Reformata30d4232018-04-07 15:31:06126#include "third_party/blink/public/web/web_autofill_client.h"
127#include "third_party/blink/public/web/web_ax_object.h"
Blink Reformata30d4232018-04-07 15:31:06128#include "third_party/blink/public/web/web_document.h"
129#include "third_party/blink/public/web/web_dom_event.h"
130#include "third_party/blink/public/web/web_dom_message_event.h"
131#include "third_party/blink/public/web/web_element.h"
Blink Reformata30d4232018-04-07 15:31:06132#include "third_party/blink/public/web/web_form_control_element.h"
133#include "third_party/blink/public/web/web_form_element.h"
134#include "third_party/blink/public/web/web_frame.h"
135#include "third_party/blink/public/web/web_frame_content_dumper.h"
136#include "third_party/blink/public/web/web_frame_widget.h"
137#include "third_party/blink/public/web/web_history_item.h"
138#include "third_party/blink/public/web/web_hit_test_result.h"
139#include "third_party/blink/public/web/web_input_element.h"
140#include "third_party/blink/public/web/web_local_frame.h"
Blink Reformata30d4232018-04-07 15:31:06141#include "third_party/blink/public/web/web_navigation_policy.h"
142#include "third_party/blink/public/web/web_page_importance_signals.h"
danakj25ec6e2b2018-09-26 17:01:31143#include "third_party/blink/public/web/web_page_popup.h"
Blink Reformata30d4232018-04-07 15:31:06144#include "third_party/blink/public/web/web_plugin.h"
Blink Reformata30d4232018-04-07 15:31:06145#include "third_party/blink/public/web/web_range.h"
146#include "third_party/blink/public/web/web_render_theme.h"
147#include "third_party/blink/public/web/web_script_source.h"
148#include "third_party/blink/public/web/web_searchable_form_data.h"
149#include "third_party/blink/public/web/web_security_policy.h"
150#include "third_party/blink/public/web/web_settings.h"
151#include "third_party/blink/public/web/web_user_gesture_indicator.h"
152#include "third_party/blink/public/web/web_view.h"
153#include "third_party/blink/public/web/web_window_features.h"
[email protected]b3a97b52014-07-09 06:25:05154#include "third_party/icu/source/common/unicode/uchar.h"
155#include "third_party/icu/source/common/unicode/uscript.h"
esecklerf2bd55f72017-03-31 09:11:57156#include "third_party/skia/include/core/SkColor.h"
[email protected]1400e6dc2013-04-27 02:36:27157#include "ui/base/ui_base_switches_util.h"
tfarina655f81d2014-12-23 02:38:50158#include "ui/gfx/geometry/point.h"
tfarina3b0452d2014-12-31 15:20:09159#include "ui/gfx/geometry/rect.h"
160#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32161#include "ui/gfx/geometry/size_conversions.h"
[email protected]08397d52011-02-05 01:53:38162#include "ui/gfx/native_widget_types.h"
ccameron772317d2017-06-04 18:35:03163#include "ui/gfx/switches.h"
mfomitchev3ba450ad2017-04-03 18:20:40164#include "ui/latency/latency_info.h"
csharrisond88f9752016-10-26 23:56:36165#include "url/origin.h"
markdittmer67b71ea2016-03-03 22:40:03166#include "url/url_constants.h"
[email protected]c4a9e932011-03-05 04:05:55167#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:29168
[email protected]25fb9b32012-04-27 03:21:55169#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25170#include <cpu-features.h>
171
dalecurtiscd971252016-09-21 16:09:00172#include "base/android/build_info.h"
kylechare7d8d5c72018-01-05 19:06:28173#include "base/memory/shared_memory.h"
174#include "content/child/child_thread_impl.h"
tfarina3b0452d2014-12-31 15:20:09175#include "ui/gfx/geometry/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40176
[email protected]78043bdd2010-04-05 18:45:33177#elif defined(OS_MACOSX)
178#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57179#endif
180
brettw4b461082016-11-19 18:55:16181#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]ea2fb972013-08-07 05:44:26182#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
183#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26184#endif
185
Sergio Villar Senineb8c252452019-10-04 17:18:28186using blink::PluginAction;
[email protected]180ef242013-11-07 06:50:46187using blink::WebAXObject;
[email protected]180ef242013-11-07 06:50:46188using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46189using blink::WebData;
[email protected]180ef242013-11-07 06:50:46190using blink::WebDocument;
[email protected]180ef242013-11-07 06:50:46191using blink::WebDragOperation;
[email protected]180ef242013-11-07 06:50:46192using blink::WebElement;
[email protected]180ef242013-11-07 06:50:46193using blink::WebFormControlElement;
194using blink::WebFormElement;
195using blink::WebFrame;
dglazkov03223492016-02-08 22:16:03196using blink::WebFrameContentDumper;
[email protected]180ef242013-11-07 06:50:46197using blink::WebGestureEvent;
198using blink::WebHistoryItem;
dglazkov8d0c21dd2016-08-06 15:56:36199using blink::WebHitTestResult;
Sergio Villar Senineb8c252452019-10-04 17:18:28200using blink::WebHTTPBody;
[email protected]180ef242013-11-07 06:50:46201using blink::WebImage;
202using blink::WebInputElement;
203using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22204using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46205using blink::WebMouseEvent;
206using blink::WebNavigationPolicy;
207using blink::WebNavigationType;
208using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46209using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46210using blink::WebRect;
Sergio Villar Senineb8c252452019-10-04 17:18:28211using blink::WebRuntimeFeatures;
Daniel Chengd5e56ff2017-06-24 07:44:02212using blink::WebSandboxFlags;
[email protected]180ef242013-11-07 06:50:46213using blink::WebScriptSource;
214using blink::WebSearchableFormData;
215using blink::WebSecurityOrigin;
216using blink::WebSecurityPolicy;
[email protected]180ef242013-11-07 06:50:46217using blink::WebSettings;
218using blink::WebSize;
[email protected]180ef242013-11-07 06:50:46219using blink::WebString;
[email protected]180ef242013-11-07 06:50:46220using blink::WebTextDirection;
221using blink::WebTouchEvent;
222using blink::WebURL;
223using blink::WebURLError;
224using blink::WebURLRequest;
225using blink::WebURLResponse;
226using blink::WebUserGestureIndicator;
227using blink::WebVector;
228using blink::WebView;
229using blink::WebWidget;
230using blink::WebWindowFeatures;
[email protected]e1acf6f2008-10-27 20:43:33231
[email protected]e9ff79c2012-10-19 21:31:26232namespace content {
233
initial.commit09911bf2008-07-26 23:55:29234//-----------------------------------------------------------------------------
235
[email protected]180ef242013-11-07 06:50:46236typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
jbroman8319b232017-03-08 22:53:29237static base::LazyInstance<ViewMap>::Leaky g_view_map =
[email protected]058561b2012-12-03 06:48:22238 LAZY_INSTANCE_INITIALIZER;
scottmg5e65e3a2017-03-08 08:48:46239typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap;
jbroman8319b232017-03-08 22:53:29240static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map =
241 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02242
[email protected]882daa92009-11-05 16:31:31243// Time, in seconds, we delay before sending content state changes (such as form
244// state and scroll position) to the browser. We delay sending changes to avoid
245// spamming the browser.
246// To avoid having tab/session restore require sending a message to get the
247// current content state during tab closing we use a shorter timeout for the
248// foreground renderer. This means there is a small window of time from which
249// content state is modified and not sent to session restore, but this is
250// better than having to wake up all renderers during shutdown.
avif937e1d2014-11-02 18:13:07251const int kDelaySecondsForContentStateSyncHidden = 5;
252const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29253
dcheng35d31c112015-07-22 00:17:36254static RenderViewImpl* (*g_create_render_view_impl)(
255 CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15256 const mojom::CreateViewParams&) = nullptr;
[email protected]8d41d7612012-11-14 20:32:19257
[email protected]c6bc20332014-02-28 18:30:39258// static
[email protected]e507045d2013-07-24 15:23:44259Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56260 WebFrame* frame,
261 const WebURLRequest& request) {
Blink Reformat1c4d759e2017-04-09 16:34:54262 return Referrer(blink::WebStringToGURL(
263 request.HttpHeaderField(WebString::FromUTF8("Referer"))),
264 request.GetReferrerPolicy());
[email protected]44e55b012013-07-23 14:21:56265}
266
[email protected]c6bc20332014-02-28 18:30:39267// static
[email protected]65920f332014-03-04 21:14:18268WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32269 WebNavigationPolicy policy) {
270 switch (policy) {
Blink Reformat1c4d759e2017-04-09 16:34:54271 case blink::kWebNavigationPolicyDownload:
nick3b04f322016-08-31 19:29:19272 return WindowOpenDisposition::SAVE_TO_DISK;
Blink Reformat1c4d759e2017-04-09 16:34:54273 case blink::kWebNavigationPolicyCurrentTab:
nick3b04f322016-08-31 19:29:19274 return WindowOpenDisposition::CURRENT_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54275 case blink::kWebNavigationPolicyNewBackgroundTab:
nick3b04f322016-08-31 19:29:19276 return WindowOpenDisposition::NEW_BACKGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54277 case blink::kWebNavigationPolicyNewForegroundTab:
nick3b04f322016-08-31 19:29:19278 return WindowOpenDisposition::NEW_FOREGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54279 case blink::kWebNavigationPolicyNewWindow:
nick3b04f322016-08-31 19:29:19280 return WindowOpenDisposition::NEW_WINDOW;
Blink Reformat1c4d759e2017-04-09 16:34:54281 case blink::kWebNavigationPolicyNewPopup:
nick3b04f322016-08-31 19:29:19282 return WindowOpenDisposition::NEW_POPUP;
[email protected]48861e22013-01-09 00:27:32283 default:
284 NOTREACHED() << "Unexpected WebNavigationPolicy";
nick3b04f322016-08-31 19:29:19285 return WindowOpenDisposition::IGNORE_ACTION;
[email protected]48861e22013-01-09 00:27:32286 }
287}
288
initial.commit09911bf2008-07-26 23:55:29289///////////////////////////////////////////////////////////////////////////////
290
[email protected]217690d2012-01-27 07:33:11291namespace {
292
[email protected]b3a97b52014-07-09 06:25:05293typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
294 const base::string16&,
295 UScriptCode);
296
297void SetStandardFontFamilyWrapper(WebSettings* settings,
298 const base::string16& font,
299 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54300 settings->SetStandardFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05301}
302
303void SetFixedFontFamilyWrapper(WebSettings* settings,
304 const base::string16& font,
305 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54306 settings->SetFixedFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05307}
308
309void SetSerifFontFamilyWrapper(WebSettings* settings,
310 const base::string16& font,
311 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54312 settings->SetSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05313}
314
315void SetSansSerifFontFamilyWrapper(WebSettings* settings,
316 const base::string16& font,
317 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54318 settings->SetSansSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05319}
320
321void SetCursiveFontFamilyWrapper(WebSettings* settings,
322 const base::string16& font,
323 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54324 settings->SetCursiveFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05325}
326
327void SetFantasyFontFamilyWrapper(WebSettings* settings,
328 const base::string16& font,
329 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54330 settings->SetFantasyFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05331}
332
333void SetPictographFontFamilyWrapper(WebSettings* settings,
334 const base::string16& font,
335 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54336 settings->SetPictographFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05337}
338
339// If |scriptCode| is a member of a family of "similar" script codes, returns
340// the script code in that family that is used by WebKit for font selection
341// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
342// considered equivalent for the purposes of font selection. WebKit uses the
343// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
344// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
345// uses different scripts than the ones in Chrome pref names because the version
346// of ICU included on certain ports does not have some of the newer scripts. If
347// |scriptCode| is not a member of such a family, returns |scriptCode|.
348UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
349 switch (scriptCode) {
350 case USCRIPT_HIRAGANA:
351 case USCRIPT_KATAKANA:
352 case USCRIPT_JAPANESE:
353 return USCRIPT_KATAKANA_OR_HIRAGANA;
354 case USCRIPT_KOREAN:
355 return USCRIPT_HANGUL;
356 default:
357 return scriptCode;
358 }
359}
360
361void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
362 SetFontFamilyWrapper setter,
363 WebSettings* settings) {
jdoerrie5a73d0fa2018-10-02 23:54:05364 for (auto it = map.begin(); it != map.end(); ++it) {
avi1023d012015-12-25 02:39:14365 int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
[email protected]b3a97b52014-07-09 06:25:05366 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
367 UScriptCode code = static_cast<UScriptCode>(script);
368 (*setter)(settings, it->second, GetScriptForWebSettings(code));
369 }
370 }
371}
372
danakjefcb8432019-01-16 18:47:14373void ApplyCommandLineToSettings(WebSettings* settings) {
374 const base::CommandLine& command_line =
375 *base::CommandLine::ForCurrentProcess();
376
danakjed9464612019-01-16 00:00:59377 settings->SetThreadedScrollingEnabled(
378 !command_line.HasSwitch(switches::kDisableThreadedScrolling));
wangxianzhu3bf39be52015-04-10 23:56:41379
danakjed9464612019-01-16 00:00:59380 if (switches::IsTouchDragDropEnabled())
381 settings->SetTouchDragDropEnabled(true);
382
383 WebSettings::SelectionStrategyType selection_strategy;
384 if (command_line.GetSwitchValueASCII(switches::kTouchTextSelectionStrategy) ==
385 "direction")
386 selection_strategy = WebSettings::SelectionStrategyType::kDirection;
387 else
388 selection_strategy = WebSettings::SelectionStrategyType::kCharacter;
389 settings->SetSelectionStrategy(selection_strategy);
390
391 std::string passive_listeners_default =
392 command_line.GetSwitchValueASCII(switches::kPassiveListenersDefault);
393 if (!passive_listeners_default.empty()) {
394 WebSettings::PassiveEventListenerDefault passive_default =
395 WebSettings::PassiveEventListenerDefault::kFalse;
396 if (passive_listeners_default == "true")
397 passive_default = WebSettings::PassiveEventListenerDefault::kTrue;
398 else if (passive_listeners_default == "forcealltrue")
399 passive_default = WebSettings::PassiveEventListenerDefault::kForceAllTrue;
400 settings->SetPassiveEventListenerDefault(passive_default);
401 }
402
403 std::string network_quiet_timeout =
404 command_line.GetSwitchValueASCII(switches::kNetworkQuietTimeout);
405 if (!network_quiet_timeout.empty()) {
406 double network_quiet_timeout_seconds = 0.0;
407 if (base::StringToDouble(network_quiet_timeout,
408 &network_quiet_timeout_seconds))
409 settings->SetNetworkQuietTimeout(network_quiet_timeout_seconds);
410 }
411
412 if (command_line.HasSwitch(switches::kBlinkSettings)) {
413 std::vector<std::string> blink_settings = base::SplitString(
414 command_line.GetSwitchValueASCII(switches::kBlinkSettings), ",",
415 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
416 for (const std::string& setting : blink_settings) {
417 size_t pos = setting.find('=');
418 settings->SetFromStrings(
419 blink::WebString::FromLatin1(setting.substr(0, pos)),
420 blink::WebString::FromLatin1(
421 pos == std::string::npos ? "" : setting.substr(pos + 1)));
422 }
wangxianzhu3bf39be52015-04-10 23:56:41423 }
424}
425
scottmgde42fb92017-02-10 17:56:03426content::mojom::WindowContainerType WindowFeaturesToContainerType(
scottmg05324cb2017-02-09 23:46:04427 const blink::WebWindowFeatures& window_features) {
japhetbfc47892017-06-02 23:01:19428 if (window_features.background) {
429 if (window_features.persistent)
scottmgde42fb92017-02-10 17:56:03430 return content::mojom::WindowContainerType::PERSISTENT;
scottmg05324cb2017-02-09 23:46:04431 else
scottmgde42fb92017-02-10 17:56:03432 return content::mojom::WindowContainerType::BACKGROUND;
scottmg05324cb2017-02-09 23:46:04433 } else {
scottmgde42fb92017-02-10 17:56:03434 return content::mojom::WindowContainerType::NORMAL;
scottmg05324cb2017-02-09 23:46:04435 }
436}
437
Ahmed Fakhry58e6ef542018-09-04 18:05:38438// Check content::BrowserControlsState, and cc::BrowserControlsState
439// are kept in sync.
440static_assert(int(BROWSER_CONTROLS_STATE_SHOWN) ==
441 int(cc::BrowserControlsState::kShown),
442 "mismatching enums: SHOWN");
443static_assert(int(BROWSER_CONTROLS_STATE_HIDDEN) ==
444 int(cc::BrowserControlsState::kHidden),
445 "mismatching enums: HIDDEN");
446static_assert(int(BROWSER_CONTROLS_STATE_BOTH) ==
447 int(cc::BrowserControlsState::kBoth),
448 "mismatching enums: BOTH");
449
450cc::BrowserControlsState ContentToCc(BrowserControlsState state) {
451 return static_cast<cc::BrowserControlsState>(state);
452}
Ahmed Fakhry58e6ef542018-09-04 18:05:38453
[email protected]217690d2012-01-27 07:33:11454} // namespace
455
Hajime Hoshi315a61f2018-08-14 17:27:28456RenderViewImpl::RenderViewImpl(CompositorDependencies* compositor_deps,
457 const mojom::CreateViewParams& params)
Albert J. Wong7faa3da2019-03-21 20:43:43458 : routing_id_(params.view_id),
danakj73dd3032018-07-28 17:49:53459 renderer_wide_named_frame_lookup_(
460 params.renderer_wide_named_frame_lookup),
danakj4b8a2d9a2019-10-15 15:53:59461 compositor_deps_(compositor_deps),
naskobd911332014-11-25 01:13:36462 webkit_preferences_(params.web_preferences),
Jeremy Roman3bca4bf2019-07-11 03:41:25463 session_storage_namespace_id_(params.session_storage_namespace_id) {
Daniel Murphy95792ef2018-10-04 01:29:55464 DCHECK(!session_storage_namespace_id_.empty())
465 << "Session storage namespace must be populated.";
Albert J. Wong7faa3da2019-03-21 20:43:43466 // Please put all logic in RenderViewImpl::Initialize().
467}
Albert J. Wong7bbf22d2018-12-20 00:27:27468
Albert J. Wong7faa3da2019-03-21 20:43:43469void RenderViewImpl::Initialize(
Erik Chen10e9b022019-08-21 23:33:23470 CompositorDependencies* compositor_deps,
Albert J. Wong7faa3da2019-03-21 20:43:43471 mojom::CreateViewParamsPtr params,
472 RenderWidget::ShowCallback show_callback,
473 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Avi Drissman07d22452019-03-25 17:56:39474 DCHECK(RenderThread::IsMainThread());
danakj242c2e12019-10-08 16:34:15475 // We have either a main frame or a proxy routing id.
476 DCHECK_NE(params->main_frame_routing_id != MSG_ROUTING_NONE,
477 params->proxy_routing_id != MSG_ROUTING_NONE);
Avi Drissman07d22452019-03-25 17:56:39478
Albert J. Wongcb004632018-07-10 22:58:25479 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]075366912013-02-18 07:13:24480
nickf7b38222016-11-22 21:59:35481#if defined(OS_ANDROID)
danakjc87bfede2018-10-10 22:32:49482 bool has_show_callback = !!show_callback;
nickf7b38222016-11-22 21:59:35483#endif
[email protected]676126f72011-01-15 00:03:51484
Lukasz Anforowiczaf2f33572018-01-17 14:05:08485 WebFrame* opener_frame =
486 RenderFrameImpl::ResolveOpener(params->opener_frame_route_id);
487
Erik Chen562ca42b2019-08-22 19:46:06488 // The newly created webview_ is owned by this instance.
danakj284d557d2019-01-16 17:00:26489 webview_ = WebView::Create(this, params->hidden,
Sadrul Habib Chowdhury042a4712018-12-06 00:16:56490 /*compositing_enabled=*/true,
danakja4ba7e52018-11-29 23:04:31491 opener_frame ? opener_frame->View() : nullptr);
Albert J. Wong2727e8a82019-02-15 16:56:11492
nasko4c0feb62015-06-05 18:37:06493 g_view_map.Get().insert(std::make_pair(webview(), this));
avia3dca182016-03-19 01:09:52494 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this));
nasko4c0feb62015-06-05 18:37:06495
danakj242c2e12019-10-08 16:34:15496 bool local_main_frame = params->main_frame_routing_id != MSG_ROUTING_NONE;
497
498 // TODO(danakj): Put this in with making the RenderFrame? Does order matter?
499 if (local_main_frame)
500 webview()->SetDisplayMode(params->visual_properties.display_mode);
dcheng0ff94cfc2016-03-15 21:50:51501
danakjfd0c7f42018-10-12 18:01:08502 ApplyWebPreferences(webkit_preferences_, webview());
danakjefcb8432019-01-16 18:47:14503 ApplyCommandLineToSettings(webview()->GetSettings());
dcheng0ff94cfc2016-03-15 21:50:51504
danakj242c2e12019-10-08 16:34:15505 if (local_main_frame) {
dcheng3ce04b62015-10-26 23:30:55506 main_render_frame_ = RenderFrameImpl::CreateMainFrame(
Erik Chen10e9b022019-08-21 23:33:23507 this, compositor_deps, opener_frame, &params, std::move(show_callback));
danakjaf29226f2018-09-25 17:56:57508 } else {
Erik Chen10e9b022019-08-21 23:33:23509 // TODO(https://crbug.com/995981): We should not need to create a
510 // RenderWidget for a remote main frame.
Erik Chencf679e02019-10-07 20:52:42511 undead_render_widget_ = RenderWidget::CreateForFrame(
Erik Chen10e9b022019-08-21 23:33:23512 params->main_frame_widget_routing_id, compositor_deps,
danakj4b8a2d9a2019-10-15 15:53:59513 params->visual_properties.display_mode,
danakj872a96a12019-09-18 21:53:14514 /*is_undead=*/true, params->never_visible);
Erik Chencf679e02019-10-07 20:52:42515 undead_render_widget_->set_delegate(this);
danakj8ba029b2019-10-10 20:41:54516 // We intentionally pass in a null webwidget since it is not needed
517 // for remote frames, and we don't have one or a ScreenInfo until we have
518 // a local main frame.
519 undead_render_widget_->InitForMainFrame(std::move(show_callback),
520 /*web_frame_widget=*/nullptr,
521 /*screen_info=*/nullptr);
Erik Chen10e9b022019-08-21 23:33:23522
Balazs Engedyba034e72017-10-27 22:26:28523 RenderFrameProxy::CreateFrameProxy(params->proxy_routing_id, GetRoutingID(),
nick3b5a21f2016-11-22 23:07:11524 opener_frame, MSG_ROUTING_NONE,
Dmitry Gozman89361212018-02-13 16:10:44525 params->replicated_frame_state,
526 params->devtools_main_frame_token);
nasko4c0feb62015-06-05 18:37:06527 }
528
[email protected]c7c0d822014-04-16 20:19:49529 // TODO(davidben): Move this state from Blink into content.
Balazs Engedyba034e72017-10-27 22:26:28530 if (params->window_was_created_with_opener)
Blink Reformat1c4d759e2017-04-09 16:34:54531 webview()->SetOpenedByDOM();
[email protected]c7c0d822014-04-16 20:19:49532
Leon Han2c81b5d2019-01-25 01:58:33533 OnSetRendererPrefs(*params->renderer_preferences);
[email protected]1784b2f2011-11-24 10:53:48534
[email protected]e9ff79c2012-10-19 21:31:26535 GetContentClient()->renderer()->RenderViewCreated(this);
Hajime Hoshif34374412018-03-05 14:32:54536
537 nav_state_sync_timer_.SetTaskRunner(task_runner);
danakjc87bfede2018-10-10 22:32:49538
Adithya Srinivasan46b8a792019-02-01 14:47:23539 // We pass this state to Page, but it's only used by the main frame in the
540 // page.
541 if (params->inside_portal)
542 webview()->SetInsidePortal(true);
543
danakjc87bfede2018-10-10 22:32:49544#if defined(OS_ANDROID)
545 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated
546 // HandleNavigation codepath.
547 // Renderer-created RenderViews have a ShowCallback because they send a Show
548 // request (ViewHostMsg_ShowWidget, ViewHostMsg_ShowFullscreenWidget, or
549 // FrameHostMsg_ShowCreatedWindow) to the browser to attach them to the UI
550 // there. Browser-created RenderViews do not send a Show request to the
551 // browser, so have no such callback.
552 was_created_by_renderer_ = has_show_callback;
553#endif
initial.commit09911bf2008-07-26 23:55:29554}
555
[email protected]310ebd6302011-10-10 19:06:28556RenderViewImpl::~RenderViewImpl() {
danakjcdfc4262019-10-01 20:09:48557 DCHECK(destroying_); // Always deleted through Destroy().
danakjcdfc4262019-10-01 20:09:48558
559 g_routing_id_view_map.Get().erase(routing_id_);
Albert J. Wongcb004632018-07-10 22:58:25560 RenderThread::Get()->RemoveRoute(routing_id_);
dcheng3ce04b62015-10-26 23:30:55561
[email protected]60c42a8c72009-10-09 04:08:59562#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22563 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49564 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59565 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
566 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22567 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
568 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
569 it != routing_id_views->end(); ++it)
570 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59571#endif
[email protected]676126f72011-01-15 00:03:51572
ericwilligers88e69742016-10-17 19:29:55573 for (auto& observer : observers_)
574 observer.RenderViewGone();
575 for (auto& observer : observers_)
576 observer.OnDestruct();
[email protected]60c42a8c72009-10-09 04:08:59577}
578
579/*static*/
[email protected]310ebd6302011-10-10 19:06:28580RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
Avi Drissman07d22452019-03-25 17:56:39581 DCHECK(RenderThread::IsMainThread());
[email protected]a2ef54c2011-10-10 16:20:31582 ViewMap* views = g_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05583 auto it = views->find(webview);
[email protected]a2ef54c2011-10-10 16:20:31584 return it == views->end() ? NULL : it->second;
585}
586
587/*static*/
[email protected]180ef242013-11-07 06:50:46588RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28589 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31590}
591
592/*static*/
avi1023d012015-12-25 02:39:14593RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) {
Avi Drissman07d22452019-03-25 17:56:39594 DCHECK(RenderThread::IsMainThread());
[email protected]640e303c2012-12-05 01:36:07595 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05596 auto it = views->find(routing_id);
[email protected]640e303c2012-12-05 01:36:07597 return it == views->end() ? NULL : it->second;
598}
599
600/*static*/
601RenderView* RenderView::FromRoutingID(int routing_id) {
602 return RenderViewImpl::FromRoutingID(routing_id);
603}
604
[email protected]f3a95312014-06-12 16:46:58605/* static */
jochen9c7b8f242015-06-01 15:32:02606size_t RenderView::GetRenderViewCount() {
[email protected]f3a95312014-06-12 16:46:58607 return g_view_map.Get().size();
608}
609
[email protected]640e303c2012-12-05 01:36:07610/*static*/
[email protected]e9ff79c2012-10-19 21:31:26611void RenderView::ForEach(RenderViewVisitor* visitor) {
Avi Drissman07d22452019-03-25 17:56:39612 DCHECK(RenderThread::IsMainThread());
[email protected]625332e02010-12-14 07:48:49613 ViewMap* views = g_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05614 for (auto it = views->begin(); it != views->end(); ++it) {
[email protected]60c42a8c72009-10-09 04:08:59615 if (!visitor->Visit(it->second))
616 return;
617 }
618}
619
620/*static*/
[email protected]b3a97b52014-07-09 06:25:05621void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
622 WebView* web_view) {
Blink Reformat1c4d759e2017-04-09 16:34:54623 WebSettings* settings = web_view->GetSettings();
[email protected]b3a97b52014-07-09 06:25:05624 ApplyFontsFromMap(prefs.standard_font_family_map,
625 SetStandardFontFamilyWrapper, settings);
626 ApplyFontsFromMap(prefs.fixed_font_family_map,
627 SetFixedFontFamilyWrapper, settings);
628 ApplyFontsFromMap(prefs.serif_font_family_map,
629 SetSerifFontFamilyWrapper, settings);
630 ApplyFontsFromMap(prefs.sans_serif_font_family_map,
631 SetSansSerifFontFamilyWrapper, settings);
632 ApplyFontsFromMap(prefs.cursive_font_family_map,
633 SetCursiveFontFamilyWrapper, settings);
634 ApplyFontsFromMap(prefs.fantasy_font_family_map,
635 SetFantasyFontFamilyWrapper, settings);
636 ApplyFontsFromMap(prefs.pictograph_font_family_map,
637 SetPictographFontFamilyWrapper, settings);
Blink Reformat1c4d759e2017-04-09 16:34:54638 settings->SetDefaultFontSize(prefs.default_font_size);
639 settings->SetDefaultFixedFontSize(prefs.default_fixed_font_size);
640 settings->SetMinimumFontSize(prefs.minimum_font_size);
641 settings->SetMinimumLogicalFontSize(prefs.minimum_logical_font_size);
642 settings->SetDefaultTextEncodingName(
643 WebString::FromASCII(prefs.default_encoding));
644 settings->SetJavaScriptEnabled(prefs.javascript_enabled);
645 settings->SetWebSecurityEnabled(prefs.web_security_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54646 settings->SetLoadsImagesAutomatically(prefs.loads_images_automatically);
647 settings->SetImagesEnabled(prefs.images_enabled);
648 settings->SetPluginsEnabled(prefs.plugins_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54649 settings->SetDOMPasteAllowed(prefs.dom_paste_enabled);
650 settings->SetTextAreasAreResizable(prefs.text_areas_are_resizable);
651 settings->SetAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
652 settings->SetDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
653 settings->SetJavaScriptCanAccessClipboard(
[email protected]b3a97b52014-07-09 06:25:05654 prefs.javascript_can_access_clipboard);
Chris Cunninghame9b5ad742019-04-23 19:40:38655 WebRuntimeFeatures::EnableXSLT(prefs.xslt_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54656 settings->SetDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
Tarun Bansal333819e2018-05-15 16:38:42657 blink::WebNetworkStateNotifier::SetSaveDataEnabled(prefs.data_saver_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54658 settings->SetLocalStorageEnabled(prefs.local_storage_enabled);
659 settings->SetSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
660 WebRuntimeFeatures::EnableDatabase(prefs.databases_enabled);
661 settings->SetOfflineWebApplicationCacheEnabled(
[email protected]b3a97b52014-07-09 06:25:05662 prefs.application_cache_enabled);
Arthur Sonzogni721f48e2018-10-31 17:10:02663 settings->SetShouldProtectAgainstIpcFlooding(
664 !prefs.disable_ipc_flooding_protection);
Blink Reformat1c4d759e2017-04-09 16:34:54665 settings->SetHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
666 settings->SetCookieEnabled(prefs.cookie_enabled);
667 settings->SetNavigateOnDragDrop(prefs.navigate_on_drag_drop);
[email protected]b3a97b52014-07-09 06:25:05668
[email protected]b3a97b52014-07-09 06:25:05669 // By default, allow_universal_access_from_file_urls is set to false and thus
670 // we mitigate attacks from local HTML files by not granting file:// URLs
671 // universal access. Only test shell will enable this.
Blink Reformat1c4d759e2017-04-09 16:34:54672 settings->SetAllowUniversalAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05673 prefs.allow_universal_access_from_file_urls);
Blink Reformat1c4d759e2017-04-09 16:34:54674 settings->SetAllowFileAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05675 prefs.allow_file_access_from_file_urls);
676
Zhenyao Moa3fda9972017-09-16 01:34:40677 settings->SetWebGL1Enabled(prefs.webgl1_enabled);
678 settings->SetWebGL2Enabled(prefs.webgl2_enabled);
[email protected]b3a97b52014-07-09 06:25:05679
[email protected]b3a97b52014-07-09 06:25:05680 // Enable WebGL errors to the JS console if requested.
Blink Reformat1c4d759e2017-04-09 16:34:54681 settings->SetWebGLErrorsToConsoleEnabled(
[email protected]b3a97b52014-07-09 06:25:05682 prefs.webgl_errors_to_console_enabled);
683
684 // Uses the mock theme engine for scrollbars.
Blink Reformat1c4d759e2017-04-09 16:34:54685 settings->SetMockScrollbarsEnabled(prefs.mock_scrollbars_enabled);
[email protected]b3a97b52014-07-09 06:25:05686
Blink Reformat1c4d759e2017-04-09 16:34:54687 settings->SetHideScrollbars(prefs.hide_scrollbars);
eseckler61ff9142016-09-23 22:57:59688
[email protected]b3a97b52014-07-09 06:25:05689 // Enable gpu-accelerated 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54690 WebRuntimeFeatures::EnableAccelerated2dCanvas(
junov524668f22016-08-08 20:16:52691 prefs.accelerated_2d_canvas_enabled);
[email protected]b3a97b52014-07-09 06:25:05692
[email protected]b3a97b52014-07-09 06:25:05693 // Disable antialiasing for 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54694 settings->SetAntialiased2dCanvasEnabled(
[email protected]b3a97b52014-07-09 06:25:05695 !prefs.antialiased_2d_canvas_disabled);
696
zakerinasab20ebca02016-09-27 14:22:34697 // Disable antialiasing of clips for 2d canvas if requested on the command
robertphillipse25137b2014-10-20 13:44:34698 // line.
Blink Reformat1c4d759e2017-04-09 16:34:54699 settings->SetAntialiasedClips2dCanvasEnabled(
robertphillipse25137b2014-10-20 13:44:34700 prefs.antialiased_clips_2d_canvas_enabled);
701
[email protected]b3a97b52014-07-09 06:25:05702 // Set MSAA sample count for 2d canvas if requested on the command line (or
703 // default value if not).
Blink Reformat1c4d759e2017-04-09 16:34:54704 settings->SetAccelerated2dCanvasMSAASampleCount(
[email protected]b3a97b52014-07-09 06:25:05705 prefs.accelerated_2d_canvas_msaa_sample_count);
706
[email protected]b3a97b52014-07-09 06:25:05707 // Tabs to link is not part of the settings. WebCore calls
708 // ChromeClient::tabsToLinks which is part of the glue code.
Blink Reformat1c4d759e2017-04-09 16:34:54709 web_view->SetTabsToLinks(prefs.tabs_to_links);
[email protected]b3a97b52014-07-09 06:25:05710
Blink Reformat1c4d759e2017-04-09 16:34:54711 settings->SetAllowRunningOfInsecureContent(
[email protected]b3a97b52014-07-09 06:25:05712 prefs.allow_running_insecure_content);
Blink Reformat1c4d759e2017-04-09 16:34:54713 settings->SetDisableReadingFromCanvas(prefs.disable_reading_from_canvas);
714 settings->SetStrictMixedContentChecking(prefs.strict_mixed_content_checking);
mkwst2384c8222015-07-30 07:26:47715
Blink Reformat1c4d759e2017-04-09 16:34:54716 settings->SetStrictlyBlockBlockableMixedContent(
mkwst2384c8222015-07-30 07:26:47717 prefs.strictly_block_blockable_mixed_content);
718
Blink Reformat1c4d759e2017-04-09 16:34:54719 settings->SetStrictMixedContentCheckingForPlugin(
mkwst0d233e52015-08-10 09:33:14720 prefs.block_mixed_plugin_content);
721
Blink Reformat1c4d759e2017-04-09 16:34:54722 settings->SetStrictPowerfulFeatureRestrictions(
mkwst673a452f2015-01-10 14:41:50723 prefs.strict_powerful_feature_restrictions);
Blink Reformat1c4d759e2017-04-09 16:34:54724 settings->SetAllowGeolocationOnInsecureOrigins(
jww9d4ca2d2016-01-19 20:58:59725 prefs.allow_geolocation_on_insecure_origins);
Blink Reformat1c4d759e2017-04-09 16:34:54726 settings->SetPasswordEchoEnabled(prefs.password_echo_enabled);
727 settings->SetShouldPrintBackgrounds(prefs.should_print_backgrounds);
728 settings->SetShouldClearDocumentBackground(
[email protected]b3a97b52014-07-09 06:25:05729 prefs.should_clear_document_background);
Blink Reformat1c4d759e2017-04-09 16:34:54730 settings->SetEnableScrollAnimator(prefs.enable_scroll_animator);
Stephen McGruerbc3d0e62019-01-23 17:40:19731 settings->SetPrefersReducedMotion(prefs.prefers_reduced_motion);
[email protected]b3a97b52014-07-09 06:25:05732
Blink Reformat1c4d759e2017-04-09 16:34:54733 WebRuntimeFeatures::EnableTouchEventFeatureDetection(
sunyunjiafa6a8afc2016-12-09 04:25:47734 prefs.touch_event_feature_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54735 settings->SetMaxTouchPoints(prefs.pointer_events_max_touch_points);
736 settings->SetAvailablePointerTypes(prefs.available_pointer_types);
737 settings->SetPrimaryPointerType(
nzolghadrc0d1663c2015-11-26 21:15:24738 static_cast<blink::PointerType>(prefs.primary_pointer_type));
Blink Reformat1c4d759e2017-04-09 16:34:54739 settings->SetAvailableHoverTypes(prefs.available_hover_types);
740 settings->SetPrimaryHoverType(
nzolghadrc0d1663c2015-11-26 21:15:24741 static_cast<blink::HoverType>(prefs.primary_hover_type));
Blink Reformat1c4d759e2017-04-09 16:34:54742 settings->SetEnableTouchAdjustment(prefs.touch_adjustment_enabled);
Dave Tapuskaa59fdb62017-08-23 16:28:27743 settings->SetBarrelButtonForDragEnabled(prefs.barrel_button_for_drag_enabled);
[email protected]b3a97b52014-07-09 06:25:05744
Blink Reformat1c4d759e2017-04-09 16:34:54745 settings->SetShouldRespectImageOrientation(
[email protected]b3a97b52014-07-09 06:25:05746 prefs.should_respect_image_orientation);
747
Blink Reformat1c4d759e2017-04-09 16:34:54748 settings->SetEditingBehavior(
[email protected]b3a97b52014-07-09 06:25:05749 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
750
Blink Reformat1c4d759e2017-04-09 16:34:54751 settings->SetSupportsMultipleWindows(prefs.supports_multiple_windows);
[email protected]b3a97b52014-07-09 06:25:05752
Blink Reformat1c4d759e2017-04-09 16:34:54753 settings->SetMainFrameClipsContent(!prefs.record_whole_document);
khushalsagar2da2b232016-03-23 22:11:35754
Blink Reformat1c4d759e2017-04-09 16:34:54755 settings->SetSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
[email protected]b3a97b52014-07-09 06:25:05756
Blink Reformat1c4d759e2017-04-09 16:34:54757 settings->SetSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
Hugo Holgersson943ae692019-01-10 10:04:14758 // Spatnav depends on KeyboardFocusableScrollers. The WebUI team has
759 // disabled KFS because they need more time to update their custom elements,
760 // crbug.com/907284. Meanwhile, we pre-ship KFS to spatnav users.
761 if (prefs.spatial_navigation_enabled)
762 WebRuntimeFeatures::EnableKeyboardFocusableScrollers(true);
[email protected]b3a97b52014-07-09 06:25:05763
Bruce Long015d96f2019-07-12 22:59:10764 settings->SetCaretBrowsingEnabled(prefs.caret_browsing_enabled);
765
Blink Reformat1c4d759e2017-04-09 16:34:54766 settings->SetSelectionIncludesAltImageText(true);
[email protected]b3a97b52014-07-09 06:25:05767
Blink Reformat1c4d759e2017-04-09 16:34:54768 settings->SetV8CacheOptions(
[email protected]35103c02014-08-12 15:08:47769 static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options));
770
Blink Reformat1c4d759e2017-04-09 16:34:54771 settings->SetImageAnimationPolicy(
je_julie.kim7fbb5a1a2015-02-09 17:26:05772 static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy));
773
Blink Reformat1c4d759e2017-04-09 16:34:54774 settings->SetPresentationRequiresUserGesture(
zqzhang1215ad422016-02-10 13:27:22775 prefs.user_gesture_required_for_presentation);
776
Elly Fong-Jonesf92897392019-01-24 16:05:49777 settings->SetTextTrackBackgroundColor(
778 WebString::FromASCII(prefs.text_track_background_color));
779 settings->SetTextTrackTextColor(
780 WebString::FromASCII(prefs.text_track_text_color));
Rahul Singh1862faa92019-03-06 22:41:43781 settings->SetTextTrackTextSize(
782 WebString::FromASCII(prefs.text_track_text_size));
783 settings->SetTextTrackTextShadow(
784 WebString::FromASCII(prefs.text_track_text_shadow));
785 settings->SetTextTrackFontFamily(
786 WebString::FromASCII(prefs.text_track_font_family));
787 settings->SetTextTrackFontVariant(
788 WebString::FromASCII(prefs.text_track_font_variant));
Blink Reformat1c4d759e2017-04-09 16:34:54789 settings->SetTextTrackMarginPercentage(prefs.text_track_margin_percentage);
Abigail Klein74de85bd2019-07-11 19:11:56790 settings->SetTextTrackWindowColor(
791 WebString::FromASCII(prefs.text_track_window_color));
792 settings->SetTextTrackWindowPadding(
793 WebString::FromASCII(prefs.text_track_window_padding));
794 settings->SetTextTrackWindowRadius(
795 WebString::FromASCII(prefs.text_track_window_radius));
halliwell4002be42016-03-18 18:33:40796
David Bokana03511a92018-09-13 04:25:24797 // Needs to happen before SetDefaultPageScaleLimits below since that'll
798 // recalculate the final page scale limits and that depends on this setting.
799 settings->SetShrinksViewportContentToFit(
800 prefs.shrinks_viewport_contents_to_fit);
801
802 // Needs to happen before SetIgnoreViewportTagScaleLimits below.
Blink Reformat1c4d759e2017-04-09 16:34:54803 web_view->SetDefaultPageScaleLimits(prefs.default_minimum_page_scale_factor,
804 prefs.default_maximum_page_scale_factor);
dcheng5ae8ca362015-02-05 04:03:47805
Allan Sandfeld Jensene35337092019-05-15 13:56:09806 settings->SetFullscreenSupported(prefs.fullscreen_supported);
Ahmed Fakhry42221452018-05-30 01:18:39807 settings->SetTextAutosizingEnabled(prefs.text_autosizing_enabled);
808 settings->SetDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
Tarun Bansald10f17a02018-09-13 00:23:17809 blink::WebNetworkStateNotifier::SetNetworkQualityWebHoldback(
810 static_cast<blink::WebEffectiveConnectionType>(
811 prefs.network_quality_estimator_web_holdback));
Ahmed Fakhry42221452018-05-30 01:18:39812
chaopeng7e8fb352019-03-26 03:34:49813 settings->SetDontSendKeyEventsToJavascript(
814 prefs.dont_send_key_events_to_javascript);
Mounir Lamouri6926107f2019-01-31 18:17:43815 settings->SetWebAppScope(WebString::FromASCII(prefs.web_app_scope.spec()));
816
[email protected]b3a97b52014-07-09 06:25:05817#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:54818 settings->SetAllowCustomScrollbarInMainFrame(false);
Blink Reformat1c4d759e2017-04-09 16:34:54819 settings->SetAccessibilityFontScaleFactor(prefs.font_scale_factor);
820 settings->SetDeviceScaleAdjustment(prefs.device_scale_adjustment);
Blink Reformat1c4d759e2017-04-09 16:34:54821 web_view->SetIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
822 settings->SetAutoZoomFocusedNodeToLegibleScale(true);
Blink Reformat1c4d759e2017-04-09 16:34:54823 settings->SetDefaultVideoPosterURL(
824 WebString::FromASCII(prefs.default_video_poster_url.spec()));
825 settings->SetSupportDeprecatedTargetDensityDPI(
[email protected]b3a97b52014-07-09 06:25:05826 prefs.support_deprecated_target_density_dpi);
Blink Reformat1c4d759e2017-04-09 16:34:54827 settings->SetUseLegacyBackgroundSizeShorthandBehavior(
[email protected]b3a97b52014-07-09 06:25:05828 prefs.use_legacy_background_size_shorthand_behavior);
Blink Reformat1c4d759e2017-04-09 16:34:54829 settings->SetWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
830 settings->SetUseWideViewport(prefs.use_wide_viewport);
831 settings->SetForceZeroLayoutHeight(prefs.force_zero_layout_height);
Blink Reformat1c4d759e2017-04-09 16:34:54832 settings->SetViewportMetaMergeContentQuirk(
[email protected]b3a97b52014-07-09 06:25:05833 prefs.viewport_meta_merge_content_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54834 settings->SetViewportMetaNonUserScalableQuirk(
[email protected]b3a97b52014-07-09 06:25:05835 prefs.viewport_meta_non_user_scalable_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54836 settings->SetViewportMetaZeroValuesQuirk(
[email protected]b3a97b52014-07-09 06:25:05837 prefs.viewport_meta_zero_values_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54838 settings->SetClobberUserAgentInitialScaleQuirk(
[email protected]b3a97b52014-07-09 06:25:05839 prefs.clobber_user_agent_initial_scale_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54840 settings->SetIgnoreMainFrameOverflowHiddenQuirk(
[email protected]b3a97b52014-07-09 06:25:05841 prefs.ignore_main_frame_overflow_hidden_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54842 settings->SetReportScreenSizeInPhysicalPixelsQuirk(
[email protected]b3a97b52014-07-09 06:25:05843 prefs.report_screen_size_in_physical_pixels_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54844 settings->SetShouldReuseGlobalForUnownedMainFrame(
tzik30eb52c2018-03-27 06:55:18845 prefs.reuse_global_for_unowned_main_frame);
Blink Reformat1c4d759e2017-04-09 16:34:54846 settings->SetPreferHiddenVolumeControls(true);
847 settings->SetSpellCheckEnabledByDefault(prefs.spellcheck_enabled_by_default);
dalecurtiscd971252016-09-21 16:09:00848
Blink Reformat1c4d759e2017-04-09 16:34:54849 WebRuntimeFeatures::EnableVideoFullscreenOrientationLock(
mlamouri1d266bf2016-12-05 17:42:36850 prefs.video_fullscreen_orientation_lock_enabled);
johnme913ee5f2017-04-28 21:36:16851 WebRuntimeFeatures::EnableVideoRotateToFullscreen(
852 prefs.video_rotate_to_fullscreen_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54853 WebRuntimeFeatures::EnableVideoFullscreenDetection(
zqzhang93e959d12017-03-16 13:10:20854 prefs.video_fullscreen_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54855 settings->SetEmbeddedMediaExperienceEnabled(
shaktisahuf97f7532017-02-24 22:46:13856 prefs.embedded_media_experience_enabled);
Ian Vollickeeca1d82018-02-07 02:43:42857 settings->SetImmersiveModeEnabled(prefs.immersive_mode_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54858 settings->SetDoNotUpdateSelectionOnMutatingSelectionRange(
changwane54ccdb92017-04-05 19:20:54859 prefs.do_not_update_selection_on_mutating_selection_range);
Noel Gordonf311a842017-07-27 00:10:07860 WebRuntimeFeatures::EnableCSSHexAlphaColor(prefs.css_hex_alpha_color_enabled);
Tobias Sargeant416174f2017-09-01 01:18:09861 WebRuntimeFeatures::EnableScrollTopLeftInterop(
862 prefs.scroll_top_left_interop_enabled);
Fernando Serboncini1fb12a82019-08-08 20:46:01863 WebRuntimeFeatures::EnableSurfaceEmbeddingFeatures(
864 !prefs.disable_features_depending_on_viz);
Aaron Krajeski0fb51282019-09-17 15:01:27865 WebRuntimeFeatures::EnableAcceleratedSmallCanvases(
866 !prefs.disable_accelerated_small_canvases);
zqzhangdf72ed082016-12-08 16:07:55867#endif // defined(OS_ANDROID)
liberato9e934892016-05-03 19:00:27868
Rune Lillesveenb46bb482019-04-02 07:36:29869 settings->SetForceDarkModeEnabled(prefs.force_dark_mode_enabled);
870
mlamouri55a0543c2017-05-11 10:34:07871 switch (prefs.autoplay_policy) {
872 case AutoplayPolicy::kNoUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28873 settings->SetAutoplayPolicy(
874 WebSettings::AutoplayPolicy::kNoUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07875 break;
876 case AutoplayPolicy::kUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28877 settings->SetAutoplayPolicy(
878 WebSettings::AutoplayPolicy::kUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07879 break;
mlamouri431bb4e2017-06-06 08:54:24880 case AutoplayPolicy::kDocumentUserActivationRequired:
881 settings->SetAutoplayPolicy(
882 WebSettings::AutoplayPolicy::kDocumentUserActivationRequired);
883 break;
mlamouri55a0543c2017-05-11 10:34:07884 }
885
Blink Reformat1c4d759e2017-04-09 16:34:54886 settings->SetViewportEnabled(prefs.viewport_enabled);
887 settings->SetViewportMetaEnabled(prefs.viewport_meta_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54888 settings->SetViewportStyle(
alokp5d566962016-04-19 00:54:16889 static_cast<blink::WebViewportStyle>(prefs.viewport_style));
890
Blink Reformat1c4d759e2017-04-09 16:34:54891 settings->SetLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
892 settings->SetMainFrameResizesAreOrientationChanges(
yoava1a508b42015-10-20 12:03:21893 prefs.main_frame_resizes_are_orientation_changes);
894
Blink Reformat1c4d759e2017-04-09 16:34:54895 settings->SetUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
jinho.bang8f11ffa2014-12-04 06:03:03896
Blink Reformat1c4d759e2017-04-09 16:34:54897 settings->SetShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up);
898 settings->SetAlwaysShowContextMenuOnTouch(
amaralp547e4192016-06-03 19:17:35899 prefs.always_show_context_menu_on_touch);
Sandra Sunc79fc93a2018-04-10 15:22:23900 settings->SetSmoothScrollForFindEnabled(prefs.smooth_scroll_for_find_enabled);
ccameron2fd70de72015-02-19 00:40:40901
Blink Reformat1c4d759e2017-04-09 16:34:54902 settings->SetHideDownloadUI(prefs.hide_download_ui);
qinmin72e8bd02016-10-21 19:35:37903
Blink Reformat1c4d759e2017-04-09 16:34:54904 settings->SetPresentationReceiver(prefs.presentation_receiver);
mlamouri57359d912016-11-29 20:11:50905
Blink Reformat1c4d759e2017-04-09 16:34:54906 settings->SetMediaControlsEnabled(prefs.media_controls_enabled);
mlamouri5cd9ae82017-02-18 11:05:09907
Tarun Bansal73d67f02018-01-17 05:56:25908 settings->SetLowPriorityIframesThreshold(
909 static_cast<blink::WebEffectiveConnectionType>(
910 prefs.low_priority_iframes_threshold));
911
Mounir Lamouri9c99a1602018-07-05 15:01:44912 settings->SetPictureInPictureEnabled(
913 prefs.picture_in_picture_enabled &&
[email protected]69db58f2018-09-26 20:27:56914 MediaFactory::GetVideoSurfaceLayerMode() !=
CJ DiMeglio89240472018-10-18 18:21:10915 blink::WebMediaPlayer::SurfaceLayerMode::kNever);
François Beaufort8c08979fc2018-03-05 13:06:31916
Tarun Bansal333819e2018-05-15 16:38:42917 settings->SetDataSaverHoldbackWebApi(
918 prefs.data_saver_holdback_web_api_enabled);
Tarun Bansal333819e2018-05-15 16:38:42919
rajendrante87ed712018-11-30 01:55:00920 settings->SetLazyLoadEnabled(prefs.lazy_load_enabled);
Rune Lillesveene17fb702019-03-15 07:26:14921 settings->SetPreferredColorScheme(prefs.preferred_color_scheme);
rajendrante87ed712018-11-30 01:55:00922
Scott Little878f7d6702018-05-31 22:09:06923 for (const auto& ect_distance_pair :
924 prefs.lazy_frame_loading_distance_thresholds_px) {
925 switch (ect_distance_pair.first) {
926 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
927 settings->SetLazyFrameLoadingDistanceThresholdPxUnknown(
928 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39929 continue;
Scott Little878f7d6702018-05-31 22:09:06930 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
931 settings->SetLazyFrameLoadingDistanceThresholdPxOffline(
932 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39933 continue;
Scott Little878f7d6702018-05-31 22:09:06934 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
935 settings->SetLazyFrameLoadingDistanceThresholdPxSlow2G(
936 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39937 continue;
Scott Little878f7d6702018-05-31 22:09:06938 case net::EFFECTIVE_CONNECTION_TYPE_2G:
939 settings->SetLazyFrameLoadingDistanceThresholdPx2G(
940 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39941 continue;
Scott Little878f7d6702018-05-31 22:09:06942 case net::EFFECTIVE_CONNECTION_TYPE_3G:
943 settings->SetLazyFrameLoadingDistanceThresholdPx3G(
944 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39945 continue;
Scott Little878f7d6702018-05-31 22:09:06946 case net::EFFECTIVE_CONNECTION_TYPE_4G:
947 settings->SetLazyFrameLoadingDistanceThresholdPx4G(
948 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39949 continue;
950 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
951 continue;
Scott Little878f7d6702018-05-31 22:09:06952 }
rajendrantd8026342018-08-29 08:08:39953 NOTREACHED();
954 }
955
956 for (const auto& ect_distance_pair :
957 prefs.lazy_image_loading_distance_thresholds_px) {
958 switch (ect_distance_pair.first) {
959 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
960 settings->SetLazyImageLoadingDistanceThresholdPxUnknown(
961 ect_distance_pair.second);
962 continue;
963 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
964 settings->SetLazyImageLoadingDistanceThresholdPxOffline(
965 ect_distance_pair.second);
966 continue;
967 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
968 settings->SetLazyImageLoadingDistanceThresholdPxSlow2G(
969 ect_distance_pair.second);
970 continue;
971 case net::EFFECTIVE_CONNECTION_TYPE_2G:
972 settings->SetLazyImageLoadingDistanceThresholdPx2G(
973 ect_distance_pair.second);
974 continue;
975 case net::EFFECTIVE_CONNECTION_TYPE_3G:
976 settings->SetLazyImageLoadingDistanceThresholdPx3G(
977 ect_distance_pair.second);
978 continue;
979 case net::EFFECTIVE_CONNECTION_TYPE_4G:
980 settings->SetLazyImageLoadingDistanceThresholdPx4G(
981 ect_distance_pair.second);
982 continue;
983 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
984 continue;
985 }
986 NOTREACHED();
Scott Little878f7d6702018-05-31 22:09:06987 }
988
rajendrant3daeae292019-09-20 07:57:54989 for (const auto& fully_load_k_pair : prefs.lazy_image_first_k_fully_load) {
990 switch (fully_load_k_pair.first) {
991 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
992 continue;
993 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
994 settings->SetLazyImageFirstKFullyLoadUnknown(fully_load_k_pair.second);
995 continue;
996 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
997 settings->SetLazyImageFirstKFullyLoadSlow2G(fully_load_k_pair.second);
998 continue;
999 case net::EFFECTIVE_CONNECTION_TYPE_2G:
1000 settings->SetLazyImageFirstKFullyLoad2G(fully_load_k_pair.second);
1001 continue;
1002 case net::EFFECTIVE_CONNECTION_TYPE_3G:
1003 settings->SetLazyImageFirstKFullyLoad3G(fully_load_k_pair.second);
1004 continue;
1005 case net::EFFECTIVE_CONNECTION_TYPE_4G:
1006 settings->SetLazyImageFirstKFullyLoad4G(fully_load_k_pair.second);
1007 continue;
1008 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
1009 continue;
1010 }
1011 NOTREACHED();
1012 }
1013
ccameron2fd70de72015-02-19 00:40:401014#if defined(OS_MACOSX)
Blink Reformat1c4d759e2017-04-09 16:34:541015 web_view->SetMaximumLegibleScale(prefs.default_maximum_page_scale_factor);
ccameron2fd70de72015-02-19 00:40:401016#endif
sunyunjia87f287b2016-09-09 00:38:131017
1018#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:541019 WebRuntimeFeatures::EnableMiddleClickAutoscroll(true);
sunyunjia87f287b2016-09-09 00:38:131020#endif
Dave Tapuskac6627e12018-08-30 15:07:191021
Dave Tapuskaa38e3252018-11-13 03:01:171022 WebRuntimeFeatures::EnableTranslateService(prefs.translate_service_available);
[email protected]b3a97b52014-07-09 06:25:051023}
1024
1025/*static*/
nickf7b38222016-11-22 21:59:351026RenderViewImpl* RenderViewImpl::Create(
1027 CompositorDependencies* compositor_deps,
Balazs Engedyba034e72017-10-27 22:26:281028 mojom::CreateViewParamsPtr params,
danakjdf1ceb72018-07-18 20:02:251029 RenderWidget::ShowCallback show_callback,
Hajime Hoshiabb3c8f2017-12-04 18:41:391030 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Balazs Engedyba034e72017-10-27 22:26:281031 DCHECK(params->view_id != MSG_ROUTING_NONE);
Albert J. Wongcb004632018-07-10 22:58:251032 DCHECK(params->main_frame_widget_routing_id != MSG_ROUTING_NONE);
Lei Zhang88f23ba2017-10-27 05:56:261033 RenderViewImpl* render_view;
[email protected]0287e762014-04-11 13:07:581034
Albert J. Wong7faa3da2019-03-21 20:43:431035 if (g_create_render_view_impl) {
1036 render_view = g_create_render_view_impl(compositor_deps, *params);
1037 } else {
1038 render_view = new RenderViewImpl(compositor_deps, *params);
1039 }
1040
Erik Chen10e9b022019-08-21 23:33:231041 render_view->Initialize(compositor_deps, std::move(params),
Albert J. Wong7faa3da2019-03-21 20:43:431042 std::move(show_callback), std::move(task_runner));
[email protected]075366912013-02-18 07:13:241043 return render_view;
[email protected]8d41d7612012-11-14 20:32:191044}
1045
Erik Chen3433ee02019-08-05 20:14:261046void RenderViewImpl::Destroy() {
danakjcdfc4262019-10-01 20:09:481047 destroying_ = true;
1048
1049 // If there is no local main frame, then destroying the WebView will not
1050 // detach anything, and the RenderWidget will not be destroyed. So we have
1051 // to do it here.
1052 bool close_render_widget_here = !main_render_frame_;
1053
Erik Chen562ca42b2019-08-22 19:46:061054 webview_->Close();
Erik Chen3433ee02019-08-05 20:14:261055 // The webview_ is already destroyed by the time we get here, remove any
1056 // references to it.
1057 g_view_map.Get().erase(webview_);
1058 webview_ = nullptr;
Erik Chen562ca42b2019-08-22 19:46:061059
danakjcdfc4262019-10-01 20:09:481060 // We do this after WebView has closed, though it should not matter. WebView
1061 // only uses the RenderWidget through WebWidgetClient that it accesses through
1062 // a main frame. So it should not be able to see this happening when there is
1063 // no local main frame.
1064 if (close_render_widget_here) {
danakj971038842019-10-09 23:07:181065 RenderWidget* closing_widget = undead_render_widget_.get();
1066 closing_widget->CloseForFrame(std::move(undead_render_widget_));
danakjcdfc4262019-10-01 20:09:481067 }
Erik Chen3433ee02019-08-05 20:14:261068
1069 delete this;
1070}
1071
[email protected]8d41d7612012-11-14 20:32:191072// static
dcheng35d31c112015-07-22 00:17:361073void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
1074 *create_render_view_impl)(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:151075 const mojom::CreateViewParams&)) {
[email protected]8d41d7612012-11-14 20:32:191076 CHECK(!g_create_render_view_impl);
1077 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291078}
1079
[email protected]310ebd6302011-10-10 19:06:281080void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511081 observers_.AddObserver(observer);
1082}
1083
[email protected]310ebd6302011-10-10 19:06:281084void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1085 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511086 observers_.RemoveObserver(observer);
1087}
1088
Peter Kastinga4a3ed12018-01-31 04:07:591089blink::WebView* RenderViewImpl::webview() {
1090 return webview_;
1091}
1092
1093const blink::WebView* RenderViewImpl::webview() const {
lfg4fa48da2016-05-09 18:25:131094 return webview_;
[email protected]4d51d5bf2010-07-26 18:48:261095}
1096
danakja2c9d0a92018-07-25 20:01:181097// RenderWidgetOwnerDelegate -----------------------------------------
fsamuel72464894f2015-12-15 06:59:311098
danakja2c9d0a92018-07-25 20:01:181099void RenderViewImpl::SetActiveForWidget(bool active) {
Albert J. Wongcb004632018-07-10 22:58:251100 if (webview())
1101 webview()->SetIsActive(active);
1102}
1103
danakja2c9d0a92018-07-25 20:01:181104bool RenderViewImpl::SupportsMultipleWindowsForWidget() {
1105 return webkit_preferences_.supports_multiple_windows;
1106}
1107
David Bokan11f6ef482019-03-18 17:47:271108bool RenderViewImpl::ShouldAckSyntheticInputImmediately() {
1109 // TODO(bokan): The RequestPresentation API appears not to function in VR. As
1110 // a short term workaround for https://crbug.com/940063, ACK input
1111 // immediately rather than using RequestPresentation.
1112 if (webkit_preferences_.immersive_mode_enabled)
1113 return true;
1114 return false;
1115}
1116
danakj84bbf552019-01-21 21:33:311117void RenderViewImpl::CancelPagePopupForWidget() {
1118 webview()->CancelPagePopup();
danakja2c9d0a92018-07-25 20:01:181119}
1120
1121void RenderViewImpl::ApplyNewDisplayModeForWidget(
Eric Willigers052f0432019-10-04 04:06:571122 blink::mojom::DisplayMode new_display_mode) {
danakj1ab8faf2018-10-12 18:24:281123 webview()->SetDisplayMode(new_display_mode);
danakja2c9d0a92018-07-25 20:01:181124}
1125
1126void RenderViewImpl::ApplyAutoResizeLimitsForWidget(const gfx::Size& min_size,
1127 const gfx::Size& max_size) {
1128 webview()->EnableAutoResizeMode(min_size, max_size);
1129}
1130
1131void RenderViewImpl::DisableAutoResizeForWidget() {
1132 webview()->DisableAutoResizeMode();
1133}
1134
1135void RenderViewImpl::ScrollFocusedNodeIntoViewForWidget() {
1136 if (WebLocalFrame* focused_frame = GetWebView()->FocusedFrame()) {
danakj5f069012019-10-09 23:14:171137 blink::WebFrameWidget* frame_widget =
1138 focused_frame->LocalRoot()->FrameWidget();
danakja2c9d0a92018-07-25 20:01:181139 frame_widget->ScrollFocusedEditableElementIntoView();
1140 }
1141}
1142
1143void RenderViewImpl::DidReceiveSetFocusEventForWidget() {
1144 // This message must always be received when the main frame is a
1145 // WebLocalFrame.
Albert J. Wong7bbf22d2018-12-20 00:27:271146 // TODO(ajwong): Can this be removed and just check |delegate_| in
danakja2c9d0a92018-07-25 20:01:181147 // RenderWidget instead?
1148 CHECK(webview()->MainFrame()->IsWebLocalFrame());
1149}
1150
danakja2c9d0a92018-07-25 20:01:181151void RenderViewImpl::DidCommitCompositorFrameForWidget() {
1152 for (auto& observer : observers_)
1153 observer.DidCommitCompositorFrame();
Philip Rogers33cd2bcc2018-08-13 21:29:291154 UpdatePreferredSize();
danakja2c9d0a92018-07-25 20:01:181155}
1156
1157void RenderViewImpl::DidCompletePageScaleAnimationForWidget() {
1158 if (auto* focused_frame = GetWebView()->FocusedFrame()) {
1159 if (focused_frame->AutofillClient())
1160 focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame();
1161 }
1162}
1163
1164void RenderViewImpl::ResizeWebWidgetForWidget(
1165 const gfx::Size& size,
1166 float top_controls_height,
1167 float bottom_controls_height,
1168 bool browser_controls_shrink_blink_size) {
1169 webview()->ResizeWithBrowserControls(size, top_controls_height,
1170 bottom_controls_height,
1171 browser_controls_shrink_blink_size);
1172}
1173
danakja2c9d0a92018-07-25 20:01:181174void RenderViewImpl::SetScreenMetricsEmulationParametersForWidget(
1175 bool enabled,
1176 const blink::WebDeviceEmulationParams& params) {
danakj1ab8faf2018-10-12 18:24:281177 if (enabled)
1178 webview()->EnableDeviceEmulation(params);
1179 else
1180 webview()->DisableDeviceEmulation();
danakja2c9d0a92018-07-25 20:01:181181}
1182
1183// IPC message handlers -----------------------------------------
1184
danakja2c9d0a92018-07-25 20:01:181185void RenderViewImpl::OnUpdateTargetURLAck() {
1186 // Check if there is a targeturl waiting to be sent.
1187 if (target_url_status_ == TARGET_PENDING)
1188 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), pending_target_url_));
1189
1190 target_url_status_ = TARGET_NONE;
1191}
1192
1193void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset,
1194 int history_length) {
1195 // -1 <= history_offset < history_length <= kMaxSessionHistoryEntries(50).
1196 DCHECK_LE(-1, history_offset);
1197 DCHECK_LT(history_offset, history_length);
1198 DCHECK_LE(history_length, kMaxSessionHistoryEntries);
1199
1200 history_list_offset_ = history_offset;
1201 history_list_length_ = history_length;
1202}
1203
1204void RenderViewImpl::OnSetInitialFocus(bool reverse) {
1205 if (!webview())
1206 return;
1207 webview()->SetInitialFocus(reverse);
1208}
1209
danakja2c9d0a92018-07-25 20:01:181210void RenderViewImpl::OnAudioStateChanged(bool is_audio_playing) {
1211 webview()->AudioStateChanged(is_audio_playing);
1212}
1213
danakja2c9d0a92018-07-25 20:01:181214///////////////////////////////////////////////////////////////////////////////
1215
1216void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget,
1217 WebNavigationPolicy policy,
1218 const gfx::Rect& initial_rect) {
1219 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(),
1220 initial_rect));
1221}
1222
1223void RenderViewImpl::ShowCreatedFullscreenWidget(
1224 RenderWidget* fullscreen_widget,
1225 WebNavigationPolicy policy,
1226 const gfx::Rect& initial_rect) {
1227 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(),
1228 fullscreen_widget->routing_id()));
1229}
1230
1231void RenderViewImpl::SendFrameStateUpdates() {
1232 // Tell each frame with pending state to send its UpdateState message.
1233 for (int render_frame_routing_id : frames_with_pending_state_) {
1234 RenderFrameImpl* frame =
1235 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
1236 if (frame)
1237 frame->SendUpdateState();
1238 }
1239 frames_with_pending_state_.clear();
1240}
1241
danakja2c9d0a92018-07-25 20:01:181242// IPC::Listener -------------------------------------------------------------
fsamuel72464894f2015-12-15 06:59:311243
[email protected]310ebd6302011-10-10 19:06:281244bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281245 WebFrame* main_frame = webview() ? webview()->MainFrame() : nullptr;
Avi Drissmanb5f8e242017-12-12 05:21:561246 if (main_frame) {
1247 GURL active_url;
1248 if (main_frame->IsWebLocalFrame())
1249 active_url = main_frame->ToWebLocalFrame()->GetDocument().Url();
lukaszabedb4b22017-06-23 00:00:131250 GetContentClient()->SetActiveURL(
Avi Drissmanb5f8e242017-12-12 05:21:561251 active_url, main_frame->Top()->GetSecurityOrigin().ToString().Utf8());
1252 }
[email protected]f8b6b6f2009-03-10 16:48:261253
dchenga2d442c22016-10-13 15:39:211254 for (auto& observer : observers_) {
1255 if (observer.OnMessageReceived(message))
[email protected]676126f72011-01-15 00:03:511256 return true;
dchenga2d442c22016-10-13 15:39:211257 }
[email protected]b2abac72009-02-26 12:39:281258
[email protected]a95986a82010-12-24 06:19:281259 bool handled = true;
[email protected]e44d1342014-05-16 21:29:331260 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
mcnee432e47d2015-11-09 19:37:461261 IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale)
initial.commit09911bf2008-07-26 23:55:291262 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291263 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1264 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
initial.commit09911bf2008-07-26 23:55:291265 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
[email protected]30f75e62009-02-25 22:01:001266 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]ab32b16c2009-10-16 14:57:251267 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1268 OnEnablePreferredSizeChangedMode)
[email protected]81375e872012-01-11 21:40:361269 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
W. James MacLeand973a55b2018-11-29 21:39:131270 IPC_MESSAGE_HANDLER(ViewMsg_AnimateDoubleTapZoom,
1271 OnAnimateDoubleTapZoomInMainFrame)
W. James MacLean5372eb72018-12-19 12:56:361272 IPC_MESSAGE_HANDLER(ViewMsg_ZoomToFindInPageRect, OnZoomToFindInPageRect)
danakjd51fd53d2018-12-21 23:06:091273 IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque, OnSetBackgroundOpaque)
wjmaclean64951902016-04-29 20:59:121274
1275 // Page messages.
lfg717154072016-06-30 15:04:161276 IPC_MESSAGE_HANDLER(PageMsg_WasHidden, OnPageWasHidden)
1277 IPC_MESSAGE_HANDLER(PageMsg_WasShown, OnPageWasShown)
alexmos136fd6e62016-08-15 20:58:411278 IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength,
1279 OnSetHistoryOffsetAndLength)
altimind8bd26c2016-11-04 11:44:541280 IPC_MESSAGE_HANDLER(PageMsg_AudioStateChanged, OnAudioStateChanged)
W. James MacLean7c8581072019-06-18 18:07:531281 IPC_MESSAGE_HANDLER(PageMsg_UpdatePageVisualProperties,
1282 OnUpdatePageVisualProperties)
Francois Doray47f759d2018-06-11 18:13:511283 IPC_MESSAGE_HANDLER(PageMsg_SetPageFrozen, SetPageFrozen)
Yuzu Saijodfba8fa62019-08-27 02:15:221284 IPC_MESSAGE_HANDLER(PageMsg_PutPageIntoBackForwardCache,
1285 PutPageIntoBackForwardCache)
1286 IPC_MESSAGE_HANDLER(PageMsg_RestorePageFromBackForwardCache,
1287 RestorePageFromBackForwardCache)
W. James MacLean62198672019-06-04 16:46:101288 IPC_MESSAGE_HANDLER(PageMsg_UpdateTextAutosizerPageInfoForRemoteMainFrames,
1289 OnTextAutosizerPageInfoChanged)
Bruce Long1e3e1f542019-10-16 17:56:281290 IPC_MESSAGE_HANDLER(PageMsg_SetRendererPrefs, OnSetRendererPrefs)
lfg717154072016-06-30 15:04:161291
[email protected]a794f3a2013-10-30 17:00:321292 // Adding a new message? Add platform independent ones first, then put the
1293 // platform specific ones at the end.
initial.commit09911bf2008-07-26 23:55:291294 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401295
[email protected]a95986a82010-12-24 06:19:281296 return handled;
initial.commit09911bf2008-07-26 23:55:291297}
1298
[email protected]180ef242013-11-07 06:50:461299// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521300
Mustaq Ahmed55944cb2018-05-25 20:44:271301// TODO(csharrison): Migrate this method to WebLocalFrameClient /
1302// RenderFrameImpl, as it is now serviced by a mojo interface scoped to the
1303// opener frame.
Daniel Murphyc8e991a2018-10-12 22:09:031304WebView* RenderViewImpl::CreateView(
1305 WebLocalFrame* creator,
1306 const WebURLRequest& request,
1307 const WebWindowFeatures& features,
1308 const WebString& frame_name,
1309 WebNavigationPolicy policy,
Daniel Murphyc8e991a2018-10-12 22:09:031310 WebSandboxFlags sandbox_flags,
Ehsan Karamad39407082019-02-19 23:38:191311 const blink::FeaturePolicy::FeatureState& opener_feature_state,
Daniel Murphyc8e991a2018-10-12 22:09:031312 const blink::SessionStorageNamespaceId& session_storage_namespace_id) {
nick5ae4d2d2017-01-06 01:18:351313 RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator);
rockot5c478a72016-09-28 23:14:181314 mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New();
Mustaq Ahmedc4cb7162018-06-05 16:28:361315
1316 // User Activation v2 moves user gesture checks to the browser process, with
1317 // the exception of the extensions case handled through the following |if|.
1318 params->mimic_user_gesture =
1319 base::FeatureList::IsEnabled(features::kUserActivationV2)
1320 ? false
1321 : WebUserGestureIndicator::IsProcessingUserGesture(creator);
Sergey Kuznetsov32257a22019-02-11 20:26:501322 // TODO(mustaq): Investigate if mimic_user_gesture can wrongly expose presence
1323 // of user activation w/o any user interaction, e.g. through
1324 // |WebChromeClient#onCreateWindow|. One case to deep-dive: disabling popup
1325 // blocker then calling window.open at onload event. crbug.com/929729
[email protected]00323f02013-07-24 15:47:411326 if (GetContentClient()->renderer()->AllowPopup())
Mustaq Ahmedc4cb7162018-06-05 16:28:361327 params->mimic_user_gesture = true;
1328
rockot5c478a72016-09-28 23:14:181329 params->window_container_type = WindowFeaturesToContainerType(features);
Daniel Murphye3eec92c2018-02-23 19:09:151330
Daniel Murphyc8e991a2018-10-12 22:09:031331 params->session_storage_namespace_id = session_storage_namespace_id;
1332 // TODO(dmurph): Don't copy session storage when features.noopener is true:
1333 // https://html.spec.whatwg.org/multipage/browsers.html#copy-session-storage
1334 // https://crbug.com/771959
Daniel Murphye3eec92c2018-02-23 19:09:151335 params->clone_from_session_storage_namespace_id =
1336 session_storage_namespace_id_;
Daniel Murphye3eec92c2018-02-23 19:09:151337
Daniel Chengd5e56ff2017-06-24 07:44:021338 const std::string& frame_name_utf8 = frame_name.Utf8(
1339 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
1340 params->frame_name = frame_name_utf8;
Nate Chapin43f307d2019-04-15 21:04:411341 params->opener_suppressed = features.noopener;
rockot5c478a72016-09-28 23:14:181342 params->disposition = NavigationPolicyToDisposition(policy);
Blink Reformat1c4d759e2017-04-09 16:34:541343 if (!request.IsNull()) {
1344 params->target_url = request.Url();
Leon Han963dc182018-11-06 05:41:481345 params->referrer =
1346 blink::mojom::Referrer::From(GetReferrerFromRequest(creator, request));
[email protected]44e55b012013-07-23 14:21:561347 }
scottmg8e6c6082017-02-13 23:15:481348 params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
[email protected]8ab04652010-06-12 02:47:261349
rockot5c478a72016-09-28 23:14:181350 // We preserve this information before sending the message since |params| is
1351 // moved on send.
1352 bool is_background_tab =
1353 params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB;
Mustaq Ahmedc4cb7162018-06-05 16:28:361354 bool opened_by_user_gesture = params->mimic_user_gesture;
[email protected]22217ed32013-11-18 18:40:231355
Daniel Cheng8bb30c62017-10-23 20:40:471356 mojom::CreateNewWindowStatus status;
rockot5c478a72016-09-28 23:14:181357 mojom::CreateNewWindowReplyPtr reply;
Balazs Engedya40712f2017-09-15 15:01:111358 auto* frame_host = creator_frame->GetFrameHost();
Daniel Cheng8bb30c62017-10-23 20:40:471359 bool err = !frame_host->CreateNewWindow(std::move(params), &status, &reply);
1360 if (err || status == mojom::CreateNewWindowStatus::kIgnore)
rockot5c478a72016-09-28 23:14:181361 return nullptr;
[email protected]48c9cf2d2009-09-16 16:47:521362
Jochen Eisinger515337a2017-05-26 14:12:521363 // For Android WebView, we support a pop-up like behavior for window.open()
1364 // even if the embedding app doesn't support multiple windows. In this case,
1365 // window.open() will return "window" and navigate it to whatever URL was
Jochen Eisinger8cb28492017-10-04 10:58:131366 // passed. We also don't need to consume user gestures to protect against
1367 // multiple windows being opened, because, well, the app doesn't support
1368 // multiple windows.
Daniel Cheng8bb30c62017-10-23 20:40:471369 // TODO(dcheng): It's awkward that this is plumbed into Blink but not really
Kent Tamura21d1de62018-12-10 04:45:201370 // used much in Blink, except to enable web testing... perhaps this should
Daniel Cheng8bb30c62017-10-23 20:40:471371 // be checked directly in the browser side.
1372 if (status == mojom::CreateNewWindowStatus::kReuse)
Jochen Eisinger515337a2017-05-26 14:12:521373 return webview();
1374
Daniel Cheng8bb30c62017-10-23 20:40:471375 DCHECK(reply);
1376 DCHECK_NE(MSG_ROUTING_NONE, reply->route_id);
1377 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_route_id);
1378 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_widget_route_id);
1379
Mustaq Ahmed76c2f4312018-06-07 20:48:011380 // The browser allowed creation of a new window and consumed the user
1381 // activation (UAv2 only).
Sergey Kuznetsov32257a22019-02-11 20:26:501382 bool was_consumed = WebUserGestureIndicator::ConsumeUserGesture(
Mustaq Ahmed76c2f4312018-06-07 20:48:011383 creator, blink::UserActivationUpdateSource::kBrowser);
Sergey Kuznetsov32257a22019-02-11 20:26:501384 if (base::FeatureList::IsEnabled(features::kUserActivationV2))
1385 opened_by_user_gesture = was_consumed;
Jochen Eisinger8cb28492017-10-04 10:58:131386
[email protected]7912e822014-04-16 02:37:031387 // While this view may be a background extension page, it can spawn a visible
1388 // render view. So we just assume that the new one is not another background
1389 // page instead of passing on our own value.
1390 // TODO(vangelis): Can we tell if the new view will be a background page?
1391 bool never_visible = false;
[email protected]9115d5f2013-03-24 04:37:411392
[email protected]d6fa88f2013-10-18 16:00:431393 // The initial hidden state for the RenderViewImpl here has to match what the
1394 // browser will eventually decide for the given disposition. Since we have to
1395 // return from this call synchronously, we just have to make our best guess
1396 // and rely on the browser sending a WasHidden / WasShown message if it
1397 // disagrees.
Balazs Engedyba034e72017-10-27 22:26:281398 mojom::CreateViewParamsPtr view_params = mojom::CreateViewParams::New();
alexmos5ac402d2015-07-09 07:51:101399
Balazs Engedyba034e72017-10-27 22:26:281400 view_params->opener_frame_route_id = creator_frame->GetRoutingID();
avia3dca182016-03-19 01:09:521401 DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID());
alexmos5ac402d2015-07-09 07:51:101402
Balazs Engedyba034e72017-10-27 22:26:281403 view_params->window_was_created_with_opener = true;
Leon Han2c81b5d2019-01-25 01:58:331404 view_params->renderer_preferences = renderer_preferences_.Clone();
Balazs Engedyba034e72017-10-27 22:26:281405 view_params->web_preferences = webkit_preferences_;
1406 view_params->view_id = reply->route_id;
1407 view_params->main_frame_routing_id = reply->main_frame_route_id;
Oksana Zhuravlovafee097c2019-07-26 17:01:301408 view_params
1409 ->main_frame_interface_bundle = mojom::DocumentScopedInterfaceBundle::New(
1410 std::move(reply->main_frame_interface_bundle->interface_provider),
1411 std::move(reply->main_frame_interface_bundle
1412 ->document_interface_broker_content),
1413 std::move(
1414 reply->main_frame_interface_bundle->document_interface_broker_blink),
1415 std::move(reply->main_frame_interface_bundle->browser_interface_broker));
Balazs Engedyba034e72017-10-27 22:26:281416 view_params->main_frame_widget_routing_id = reply->main_frame_widget_route_id;
1417 view_params->session_storage_namespace_id =
rockot5c478a72016-09-28 23:14:181418 reply->cloned_session_storage_namespace_id;
Daniel Murphy95792ef2018-10-04 01:29:551419 DCHECK(!view_params->session_storage_namespace_id.empty())
1420 << "Session storage namespace must be populated.";
Balazs Engedyba034e72017-10-27 22:26:281421 view_params->replicated_frame_state.frame_policy.sandbox_flags =
1422 sandbox_flags;
Ehsan Karamad39407082019-02-19 23:38:191423 view_params->replicated_frame_state.opener_feature_state =
1424 opener_feature_state;
Balazs Engedyba034e72017-10-27 22:26:281425 view_params->replicated_frame_state.name = frame_name_utf8;
1426 view_params->devtools_main_frame_token = reply->devtools_main_frame_token;
Balazs Engedyba034e72017-10-27 22:26:281427 view_params->hidden = is_background_tab;
1428 view_params->never_visible = never_visible;
danakjbe56b8132019-10-12 00:57:411429 view_params->visual_properties = reply->visual_properties;
naskobd911332014-11-25 01:13:361430
nick5ae4d2d2017-01-06 01:18:351431 // Unretained() is safe here because our calling function will also call
1432 // show().
nickf7b38222016-11-22 21:59:351433 RenderWidget::ShowCallback show_callback =
danakjdf1ceb72018-07-18 20:02:251434 base::BindOnce(&RenderFrameImpl::ShowCreatedWindow,
1435 base::Unretained(creator_frame), opened_by_user_gesture);
nickf7b38222016-11-22 21:59:351436
Balazs Engedyba034e72017-10-27 22:26:281437 RenderViewImpl* view = RenderViewImpl::Create(
danakj4b8a2d9a2019-10-15 15:53:591438 compositor_deps_, std::move(view_params), std::move(show_callback),
Hajime Hoshi6fc91142018-05-11 08:21:171439 creator->GetTaskRunner(blink::TaskType::kInternalDefault));
[email protected]48c9cf2d2009-09-16 16:47:521440
[email protected]48c9cf2d2009-09-16 16:47:521441 return view->webview();
1442}
1443
danakj19f3e512018-12-14 21:02:051444blink::WebPagePopup* RenderViewImpl::CreatePopup(
1445 blink::WebLocalFrame* creator) {
Julie Jeongeun Kimcaacf9102019-09-12 02:13:051446 mojo::PendingRemote<mojom::Widget> widget_channel;
1447 mojo::PendingReceiver<mojom::Widget> widget_channel_receiver =
1448 widget_channel.InitWithNewPipeAndPassReceiver();
danakj25ec6e2b2018-09-26 17:01:311449
1450 // Do a synchronous IPC to obtain a routing ID.
1451 int32_t widget_routing_id = MSG_ROUTING_NONE;
1452 bool success =
1453 RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
1454 GetRoutingID(), std::move(widget_channel), &widget_routing_id);
1455 if (!success) {
1456 // When the renderer is being killed the mojo message will fail.
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281457 return nullptr;
danakj25ec6e2b2018-09-26 17:01:311458 }
1459
1460 RenderWidget::ShowCallback opener_callback = base::BindOnce(
1461 &RenderViewImpl::ShowCreatedPopupWidget, weak_ptr_factory_.GetWeakPtr());
1462
danakj93593972019-10-11 00:02:491463 RenderWidget* opener_render_widget =
Erik Chen6bc8da02019-09-20 15:51:381464 RenderFrameImpl::FromWebFrame(creator)->GetLocalRootRenderWidget();
danakj25ec6e2b2018-09-26 17:01:311465
Erik Chen3433ee02019-08-05 20:14:261466 RenderWidget* popup_widget = RenderWidget::CreateForPopup(
danakj93593972019-10-11 00:02:491467 widget_routing_id, opener_render_widget->compositor_deps(),
danakj4b8a2d9a2019-10-15 15:53:591468 blink::mojom::DisplayMode::kUndefined,
danakj25ec6e2b2018-09-26 17:01:311469 /*hidden=*/false,
Julie Jeongeun Kimcaacf9102019-09-12 02:13:051470 /*never_visible=*/false, std::move(widget_channel_receiver));
danakj25ec6e2b2018-09-26 17:01:311471
1472 // The returned WebPagePopup is self-referencing, so the pointer here is not
danakj45e4a4f2019-03-12 22:50:421473 // an owning pointer. It is de-referenced by calling Close().
danakj25ec6e2b2018-09-26 17:01:311474 blink::WebPagePopup* popup_web_widget =
Erik Chen3433ee02019-08-05 20:14:261475 blink::WebPagePopup::Create(popup_widget);
danakj25ec6e2b2018-09-26 17:01:311476
1477 // Adds a self-reference on the |popup_widget| so it will not be destroyed
1478 // when leaving scope. The WebPagePopup takes responsibility for Close()ing
1479 // and thus destroying the RenderWidget.
danakj93593972019-10-11 00:02:491480 popup_widget->InitForPopup(std::move(opener_callback), opener_render_widget,
1481 popup_web_widget,
1482 opener_render_widget->GetOriginalScreenInfo());
danakj25ec6e2b2018-09-26 17:01:311483 // TODO(crbug.com/419087): RenderWidget has some weird logic for picking a
1484 // WebWidget which doesn't apply to this case. So we verify. This can go away
1485 // when RenderWidget::GetWebWidget() is just a simple accessor.
1486 DCHECK_EQ(popup_widget->GetWebWidget(), popup_web_widget);
1487
danakj25ec6e2b2018-09-26 17:01:311488 return popup_web_widget;
[email protected]48c9cf2d2009-09-16 16:47:521489}
1490
danakj295c43f182019-03-13 16:37:171491void RenderViewImpl::DoDeferredClose() {
1492 // The main widget is currently not active. The active main frame widget is
1493 // in a different process. Have the browser route the close request to the
1494 // active widget instead, so that the correct unload handlers are run.
1495 Send(new ViewHostMsg_RouteCloseEvent(GetRoutingID()));
1496}
1497
danakj45e4a4f2019-03-12 22:50:421498void RenderViewImpl::CloseWindowSoon() {
Avi Drissman07d22452019-03-25 17:56:391499 DCHECK(RenderThread::IsMainThread());
Erik Chen496b8342019-09-20 15:51:111500 if (!render_widget_ || render_widget_->IsUndeadOrProvisional()) {
danakj295c43f182019-03-13 16:37:171501 // Ask the RenderViewHost with a local main frame to initiate close. We
1502 // could be called from deep in Javascript. If we ask the RenderViewHost to
1503 // close now, the window could be closed before the JS finishes executing,
danakjbd1a86a2019-09-06 17:24:311504 // thanks to nested message loops running and handling the resulting Close
danakj295c43f182019-03-13 16:37:171505 // IPC. So instead, post a message back to the message loop, which won't run
1506 // until the JS is complete, and then the Close request can be sent.
1507 GetCleanupTaskRunner()->PostTask(
1508 FROM_HERE, base::BindOnce(&RenderViewImpl::DoDeferredClose,
1509 weak_ptr_factory_.GetWeakPtr()));
danakj45e4a4f2019-03-12 22:50:421510 return;
1511 }
1512
danakjbd1a86a2019-09-06 17:24:311513 // If the main widget is not undead then the Close request goes directly
danakj45e4a4f2019-03-12 22:50:421514 // through it, because the RenderWidget ultimately owns the RenderViewImpl.
1515 render_widget_->CloseWidgetSoon();
1516}
1517
Daniel Murphy31bbb8b12018-02-07 21:44:101518base::StringPiece RenderViewImpl::GetSessionStorageNamespaceId() {
1519 CHECK(!session_storage_namespace_id_.empty());
Daniel Murphy0ce6e2c2017-11-21 01:54:261520 return session_storage_namespace_id_;
[email protected]bd92c3a2010-01-13 05:02:341521}
1522
Blink Reformat1c4d759e2017-04-09 16:34:541523void RenderViewImpl::PrintPage(WebLocalFrame* frame) {
Erik Chenfaa928c2019-09-20 23:41:151524 RenderFrameImpl* render_frame = RenderFrameImpl::FromWebFrame(frame);
1525 RenderWidget* render_widget = render_frame->GetLocalRootRenderWidget();
1526
1527 render_frame->ScriptedPrint(
1528 render_widget->input_handler().handling_input_event());
[email protected]48c9cf2d2009-09-16 16:47:521529}
1530
danakjcf409aa2019-09-20 15:22:301531bool RenderViewImpl::SetZoomLevel(double zoom_level) {
1532 if (zoom_level == page_zoom_level_)
1533 return false;
1534
wjmaclean64951902016-04-29 20:59:121535 // If we change the zoom level for the view, make sure any subsequent subframe
1536 // loads reflect the current zoom level.
1537 page_zoom_level_ = zoom_level;
Blink Reformat1c4d759e2017-04-09 16:34:541538 webview()->SetZoomLevel(zoom_level);
ericwilligers88e69742016-10-17 19:29:551539 for (auto& observer : observers_)
1540 observer.OnZoomLevelChanged();
danakjcf409aa2019-09-20 15:22:301541 return true;
1542}
1543
1544void RenderViewImpl::SetPreferCompositingToLCDTextEnabled(bool prefer) {
1545 webview()->GetSettings()->SetPreferCompositingToLCDTextEnabled(prefer);
1546}
1547
1548void RenderViewImpl::SetDeviceScaleFactor(bool use_zoom_for_dsf,
1549 float device_scale_factor) {
1550 if (use_zoom_for_dsf)
1551 webview()->SetZoomFactorForDeviceScaleFactor(device_scale_factor);
1552 else
1553 webview()->SetDeviceScaleFactor(device_scale_factor);
1554}
1555
1556void RenderViewImpl::PropagatePageZoomToNewlyAttachedFrame(
1557 bool use_zoom_for_dsf,
1558 float device_scale_factor) {
1559 if (use_zoom_for_dsf)
1560 webview()->SetZoomFactorForDeviceScaleFactor(device_scale_factor);
1561 else
1562 webview()->SetZoomLevel(page_zoom_level_);
tommycli8aad3ba2015-08-12 17:57:591563}
1564
habib.virji597255e2014-09-09 00:30:181565void RenderViewImpl::SetValidationMessageDirection(
1566 base::string16* wrapped_main_text,
1567 blink::WebTextDirection main_text_hint,
1568 base::string16* wrapped_sub_text,
1569 blink::WebTextDirection sub_text_hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541570 if (main_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181571 *wrapped_main_text =
1572 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
Blink Reformat1c4d759e2017-04-09 16:34:541573 } else if (main_text_hint == blink::kWebTextDirectionRightToLeft &&
habib.virji597255e2014-09-09 00:30:181574 !base::i18n::IsRTL()) {
1575 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
1576 }
1577
1578 if (!wrapped_sub_text->empty()) {
Blink Reformat1c4d759e2017-04-09 16:34:541579 if (sub_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181580 *wrapped_sub_text =
1581 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
Blink Reformat1c4d759e2017-04-09 16:34:541582 } else if (sub_text_hint == blink::kWebTextDirectionRightToLeft) {
habib.virji597255e2014-09-09 00:30:181583 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
1584 }
1585 }
1586}
1587
[email protected]310ebd6302011-10-10 19:06:281588void RenderViewImpl::UpdateTargetURL(const GURL& url,
1589 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581590 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521591 if (latest_url == target_url_)
1592 return;
[email protected]163f8242009-10-30 20:19:551593
[email protected]48c9cf2d2009-09-16 16:47:521594 // Tell the browser to display a destination link.
1595 if (target_url_status_ == TARGET_INFLIGHT ||
1596 target_url_status_ == TARGET_PENDING) {
1597 // If we have a request in-flight, save the URL to be sent when we
1598 // receive an ACK to the in-flight request. We can happily overwrite
1599 // any existing pending sends.
1600 pending_target_url_ = latest_url;
1601 target_url_status_ = TARGET_PENDING;
1602 } else {
mnaganovbf087422015-12-16 05:10:031603 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411604 // see |ParamTraits<GURL>|.
markdittmer67b71ea2016-03-03 22:40:031605 if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:411606 latest_url = GURL();
avia3dca182016-03-19 01:09:521607 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), latest_url));
[email protected]48c9cf2d2009-09-16 16:47:521608 target_url_ = latest_url;
1609 target_url_status_ = TARGET_INFLIGHT;
1610 }
1611}
1612
creis69b184a472015-11-26 05:29:511613void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) {
creisce0ef3572017-01-26 17:53:081614 // Keep track of which frames have pending updates.
1615 frames_with_pending_state_.insert(frame->GetRoutingID());
creis8eb8ef22015-11-04 22:51:381616
[email protected]882daa92009-11-05 16:31:311617 int delay;
avif937e1d2014-11-02 18:13:071618 if (send_content_state_immediately_)
[email protected]882daa92009-11-05 16:31:311619 delay = 0;
danakj78744912018-11-30 23:46:421620 else if (GetWebView()->IsHidden())
avif937e1d2014-11-02 18:13:071621 delay = kDelaySecondsForContentStateSyncHidden;
[email protected]882daa92009-11-05 16:31:311622 else
avif937e1d2014-11-02 18:13:071623 delay = kDelaySecondsForContentStateSync;
[email protected]882daa92009-11-05 16:31:311624
avif937e1d2014-11-02 18:13:071625 if (nav_state_sync_timer_.IsRunning()) {
[email protected]882daa92009-11-05 16:31:311626 // The timer is already running. If the delay of the timer maches the amount
1627 // we want to delay by, then return. Otherwise stop the timer so that it
1628 // gets started with the right delay.
avif937e1d2014-11-02 18:13:071629 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
[email protected]882daa92009-11-05 16:31:311630 return;
avif937e1d2014-11-02 18:13:071631 nav_state_sync_timer_.Stop();
[email protected]882daa92009-11-05 16:31:311632 }
1633
creisce0ef3572017-01-26 17:53:081634 // Tell each frame with pending state to inform the browser.
danakj19f3e512018-12-14 21:02:051635 nav_state_sync_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay),
1636 this, &RenderViewImpl::SendFrameStateUpdates);
[email protected]882daa92009-11-05 16:31:311637}
1638
Blink Reformat1c4d759e2017-04-09 16:34:541639void RenderViewImpl::SetMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551640 mouse_over_url_ = GURL(url);
1641 UpdateTargetURL(mouse_over_url_, focus_url_);
1642}
1643
Blink Reformat1c4d759e2017-04-09 16:34:541644void RenderViewImpl::SetKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551645 focus_url_ = GURL(url);
1646 UpdateTargetURL(focus_url_, mouse_over_url_);
1647}
1648
Blink Reformat1c4d759e2017-04-09 16:34:541649bool RenderViewImpl::AcceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451650 return renderer_preferences_.can_accept_load_drops;
1651}
1652
Blink Reformat1c4d759e2017-04-09 16:34:541653void RenderViewImpl::FocusNext() {
avia3dca182016-03-19 01:09:521654 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false));
[email protected]48c9cf2d2009-09-16 16:47:521655}
1656
Blink Reformat1c4d759e2017-04-09 16:34:541657void RenderViewImpl::FocusPrevious() {
avia3dca182016-03-19 01:09:521658 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true));
[email protected]48c9cf2d2009-09-16 16:47:521659}
1660
Kent Tamura69d143e2019-05-22 00:31:451661void RenderViewImpl::FocusedElementChanged(const WebElement& from_element,
1662 const WebElement& to_element) {
estade31c54342015-01-23 03:34:361663 RenderFrameImpl* previous_frame = nullptr;
Kent Tamura69d143e2019-05-22 00:31:451664 if (!from_element.IsNull())
Blink Reformat1c4d759e2017-04-09 16:34:541665 previous_frame =
Kent Tamura69d143e2019-05-22 00:31:451666 RenderFrameImpl::FromWebFrame(from_element.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361667 RenderFrameImpl* new_frame = nullptr;
Kent Tamura69d143e2019-05-22 00:31:451668 if (!to_element.IsNull())
1669 new_frame =
1670 RenderFrameImpl::FromWebFrame(to_element.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361671
1672 if (previous_frame && previous_frame != new_frame)
Kent Tamura69d143e2019-05-22 00:31:451673 previous_frame->FocusedElementChanged(WebElement());
estade31c54342015-01-23 03:34:361674 if (new_frame)
Kent Tamura69d143e2019-05-22 00:31:451675 new_frame->FocusedElementChanged(to_element);
estade31c54342015-01-23 03:34:361676
1677 // TODO(dmazzoni): remove once there's a separate a11y tree per frame.
naskoe8d115752015-08-07 00:43:131678 if (main_render_frame_)
Kent Tamura69d143e2019-05-22 00:31:451679 main_render_frame_->FocusedElementChangedForAccessibility(to_element);
[email protected]08e9e132010-06-01 16:58:491680}
1681
Philip Rogers079658812018-08-01 23:19:091682void RenderViewImpl::DidUpdateMainFrameLayout() {
ericwilligers88e69742016-10-17 19:29:551683 for (auto& observer : observers_)
Philip Rogers079658812018-08-01 23:19:091684 observer.DidUpdateMainFrameLayout();
[email protected]d01b2a62013-09-18 23:21:331685
Philip Rogers33cd2bcc2018-08-13 21:29:291686 // The main frame may have changed size.
1687 needs_preferred_size_update_ = true;
[email protected]169d4282011-11-30 19:33:591688}
1689
Andrey Kosyakov87b7a252019-10-15 18:12:421690void RenderViewImpl::NavigateBackForwardSoon(int offset,
1691 bool has_user_gesture) {
1692 history_navigation_virtual_time_pauser_ =
1693 RenderThreadImpl::current()
1694 ->GetWebMainThreadScheduler()
1695 ->CreateWebScopedVirtualTimePauser(
1696 "NavigateBackForwardSoon",
1697 blink::WebScopedVirtualTimePauser::VirtualTaskDuration::kInstant);
1698 history_navigation_virtual_time_pauser_.PauseVirtualTime();
1699}
1700
1701void RenderViewImpl::DidCommitProvisionalHistoryLoad() {
1702 history_navigation_virtual_time_pauser_.UnpauseVirtualTime();
1703}
1704
Scott Violet0de3837c2019-09-06 22:51:541705void RenderViewImpl::UpdateBrowserControlsState(
1706 BrowserControlsState constraints,
1707 BrowserControlsState current,
1708 bool animate) {
1709 TRACE_EVENT2("renderer", "RenderViewImpl::UpdateBrowserControlsState",
1710 "Constraint", static_cast<int>(constraints), "Current",
1711 static_cast<int>(current));
1712 TRACE_EVENT_INSTANT1("renderer", "is_animated", TRACE_EVENT_SCOPE_THREAD,
1713 "animated", animate);
1714
danakj872a96a12019-09-18 21:53:141715 if (render_widget_ && render_widget_->layer_tree_view()) {
1716 render_widget_->layer_tree_view()
Scott Violet0de3837c2019-09-06 22:51:541717 ->layer_tree_host()
1718 ->UpdateBrowserControlsState(ContentToCc(constraints),
1719 ContentToCc(current), animate);
1720 }
1721
1722 top_controls_constraints_ = constraints;
1723}
1724
Michael Martis2415478f2019-04-17 07:35:001725void RenderViewImpl::RegisterRendererPreferenceWatcher(
Julie Jeongeun Kim6d8b7492019-08-20 19:24:111726 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
1727 renderer_preference_watchers_.Add(std::move(watcher));
Makoto Shimazuc3c730e2018-08-15 09:51:111728}
1729
Blink Reformat1c4d759e2017-04-09 16:34:541730int RenderViewImpl::HistoryBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001731 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521732}
1733
Blink Reformat1c4d759e2017-04-09 16:34:541734int RenderViewImpl::HistoryForwardListCount() {
1735 return history_list_length_ - HistoryBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521736}
1737
[email protected]180ef242013-11-07 06:50:461738// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:511739
Blink Reformat1c4d759e2017-04-09 16:34:541740bool RenderViewImpl::CanHandleGestureEvent() {
slangley1a6375e62017-03-29 06:03:231741 return true;
1742}
1743
Avi Drissmanfb961262019-03-05 22:50:291744// TODO(https://crbug.com/937569): Remove this in Chrome 82.
1745bool RenderViewImpl::AllowPopupsDuringPageUnload() {
Avi Drissman16dfa1c2019-10-09 21:41:131746 // The switch version is for enabling via enterprise policy. The feature
1747 // version is for enabling via about:flags and Finch policy.
Avi Drissmanfb961262019-03-05 22:50:291748 const base::CommandLine& command_line =
1749 *base::CommandLine::ForCurrentProcess();
Avi Drissman7e5079f2019-09-30 14:06:401750 return command_line.HasSwitch(switches::kAllowPopupsDuringPageUnload) ||
1751 base::FeatureList::IsEnabled(features::kAllowPopupsDuringPageUnload);
Avi Drissmanfb961262019-03-05 22:50:291752}
1753
Blink Reformat1c4d759e2017-04-09 16:34:541754bool RenderViewImpl::CanUpdateLayout() {
slangley1a6375e62017-03-29 06:03:231755 return true;
1756}
1757
[email protected]b2324b092012-11-01 10:34:111758void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
1759 const std::string& value) {
Erik Chenf2772802019-10-04 22:16:251760 // This is test-only code. Only propagate the command if there is a main
1761 // render frame.
1762 if (main_render_frame_)
1763 render_widget_->SetEditCommandForNextKeyEvent(name, value);
[email protected]b2324b092012-11-01 10:34:111764}
1765
1766void RenderViewImpl::ClearEditCommands() {
Erik Chenf2772802019-10-04 22:16:251767 // This is test-only code. Only propagate the command if there is a main
1768 // render frame.
1769 if (main_render_frame_)
1770 render_widget_->ClearEditCommands();
[email protected]b2324b092012-11-01 10:34:111771}
1772
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491773const std::string& RenderViewImpl::GetAcceptLanguages() {
[email protected]b38806a2013-10-04 16:01:381774 return renderer_preferences_.accept_languages;
1775}
1776
David Bokan1e37ebf2018-10-16 13:53:371777#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
1778
Ahmed Fakhry58e6ef542018-09-04 18:05:381779void RenderViewImpl::didScrollWithKeyboard(const blink::WebSize& delta) {
1780 if (delta.height == 0)
1781 return;
1782
1783 BrowserControlsState current = delta.height < 0
1784 ? BROWSER_CONTROLS_STATE_SHOWN
1785 : BROWSER_CONTROLS_STATE_HIDDEN;
1786
1787 UpdateBrowserControlsState(top_controls_constraints_, current, true);
1788}
1789
1790#endif
1791
Philip Rogers601fd072018-08-07 22:58:221792void RenderViewImpl::UpdatePreferredSize() {
[email protected]d812fd12011-05-27 23:05:071793 // We don't always want to send the change messages over IPC, only if we've
1794 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1795 // message.
danakj3dcceba2019-10-09 22:16:231796 if (!send_preferred_size_changes_ || !webview() || !main_render_frame_)
[email protected]d812fd12011-05-27 23:05:071797 return;
Philip Rogers33cd2bcc2018-08-13 21:29:291798
1799 if (!needs_preferred_size_update_)
1800 return;
1801 needs_preferred_size_update_ = false;
1802
danakj3dcceba2019-10-09 22:16:231803 blink::WebSize web_size = webview()->ContentsPreferredMinimumSize();
1804 blink::WebRect web_rect(0, 0, web_size.width, web_size.height);
1805 render_widget_->ConvertViewportToWindow(&web_rect);
1806 gfx::Size size(web_rect.width, web_rect.height);
[email protected]c27324b2009-11-19 22:44:291807
danakj3dcceba2019-10-09 22:16:231808 if (size != preferred_size_) {
1809 preferred_size_ = size;
1810 Send(new ViewHostMsg_DidContentsPreferredSizeChange(GetRoutingID(), size));
1811 }
[email protected]3d9689372009-09-10 04:29:171812}
1813
Blink Reformat1c4d759e2017-04-09 16:34:541814blink::WebString RenderViewImpl::AcceptLanguages() {
1815 return WebString::FromUTF8(renderer_preferences_.accept_languages);
[email protected]9982c802013-06-12 15:22:061816}
1817
[email protected]e9ff79c2012-10-19 21:31:261818// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:311819
[email protected]310ebd6302011-10-10 19:06:281820bool RenderViewImpl::Send(IPC::Message* message) {
danakj3130f122019-07-16 17:49:471821 // No messages sent through RenderView come without a routing id, yay. Let's
1822 // keep that up.
1823 CHECK_NE(message->routing_id(), MSG_ROUTING_NONE);
danakj3130f122019-07-16 17:49:471824 return RenderThread::Get()->Send(message);
[email protected]a2ef54c2011-10-10 16:20:311825}
1826
Peter Kastinga4a3ed12018-01-31 04:07:591827RenderWidget* RenderViewImpl::GetWidget() {
Erik Chen3433ee02019-08-05 20:14:261828 return render_widget_.get();
Albert J. Wong7bbf22d2018-12-20 00:27:271829}
1830
mostynbc33353232014-09-12 09:38:311831RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() {
nasko77de2312015-05-12 03:09:161832 return main_render_frame_;
[email protected]b849847b2013-12-10 21:57:581833}
1834
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491835int RenderViewImpl::GetRoutingID() {
Albert J. Wongcb004632018-07-10 22:58:251836 return routing_id_;
[email protected]a2ef54c2011-10-10 16:20:311837}
1838
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491839float RenderViewImpl::GetZoomLevel() {
Marc Treib06d66032017-10-19 08:43:201840 return page_zoom_level_;
1841}
1842
thestig8a8fdfd32017-05-06 18:46:541843const WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:311844 return webkit_preferences_;
1845}
1846
[email protected]324825d2012-11-30 12:37:151847void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
1848 OnUpdateWebPreferences(preferences);
1849}
1850
[email protected]180ef242013-11-07 06:50:461851blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:311852 return webview();
1853}
1854
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491855bool RenderViewImpl::GetContentStateImmediately() {
avif937e1d2014-11-02 18:13:071856 return send_content_state_immediately_;
[email protected]a2ef54c2011-10-10 16:20:311857}
1858
mcnee432e47d2015-11-09 19:37:461859void RenderViewImpl::OnSetPageScale(float page_scale_factor) {
ccameronb7c1d6c2015-03-09 17:08:241860 if (!webview())
1861 return;
Blink Reformat1c4d759e2017-04-09 16:34:541862 webview()->SetPageScaleFactor(page_scale_factor);
ccameronb7c1d6c2015-03-09 17:08:241863}
1864
danakj78744912018-11-30 23:46:421865void RenderViewImpl::ApplyPageHidden(bool hidden, bool initial_setting) {
1866 webview()->SetIsHidden(hidden, initial_setting);
1867 // Note: RenderWidget visibility is separately set from the IPC handlers, and
1868 // does not change when tests override the visibility of the Page.
danakj1b35e9d2018-11-07 19:09:281869}
1870
danakj760d7d92019-10-11 17:25:321871RenderWidget* RenderViewImpl::ReviveUndeadMainFrameRenderWidget() {
Erik Chencf679e02019-10-07 20:52:421872 render_widget_ = std::move(undead_render_widget_);
danakj760d7d92019-10-11 17:25:321873 render_widget_->SetIsUndead(false);
1874 return render_widget_.get();
1875}
1876
1877void RenderViewImpl::CloseMainFrameRenderWidget() {
1878 // There is a WebFrameWidget previously attached by AttachWebFrameWidget().
1879 DCHECK(render_widget_->GetWebWidget());
1880
1881 if (destroying_) {
1882 // We are inside RenderViewImpl::Destroy() and the main frame is being
1883 // detached as part of shutdown. So we can destroy the RenderWidget.
1884
1885 // We pass ownership of |render_widget_| to itself. Grab a raw pointer to
1886 // call the Close() method on so we don't have to be a C++ expert to know
1887 // whether we will end up with a nullptr where we didn't intend due to order
1888 // of execution.
1889 RenderWidget* closing_widget = render_widget_.get();
1890 closing_widget->CloseForFrame(std::move(render_widget_));
1891 } else {
1892 // We are not inside RenderViewImpl::Destroy(), the main frame is being
1893 // detached and replaced with a remote frame proxy. We can't close the
1894 // RenderWidget, and it is marked undead instead.
1895 render_widget_->SetIsUndead(true);
1896
1897 undead_render_widget_ = std::move(render_widget_);
1898 }
Erik Chencf679e02019-10-07 20:52:421899}
1900
[email protected]310ebd6302011-10-10 19:06:281901void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:591902 webkit_preferences_ = prefs;
danakjfd0c7f42018-10-12 18:01:081903 ApplyWebPreferences(webkit_preferences_, webview());
initial.commit09911bf2008-07-26 23:55:291904}
1905
[email protected]2bf834f2011-11-17 20:02:211906void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:241907 if (send_preferred_size_changes_)
1908 return;
[email protected]9fb325e2010-05-06 18:23:241909 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:391910
Philip Rogers601fd072018-08-07 22:58:221911 if (!webview())
1912 return;
1913
Philip Rogers33cd2bcc2018-08-13 21:29:291914 needs_preferred_size_update_ = true;
1915
Philip Rogers601fd072018-08-07 22:58:221916 // We need to ensure |UpdatePreferredSize| gets called. If a layout is needed,
1917 // force an update here which will call |DidUpdateMainFrameLayout|.
Erik Chenab7ed492019-08-28 01:34:491918 if (webview()->MainFrameWidget()) {
1919 webview()->MainFrameWidget()->UpdateLifecycle(
1920 WebWidget::LifecycleUpdate::kLayout,
1921 WebWidget::LifecycleUpdateReason::kOther);
1922 }
Philip Rogers601fd072018-08-07 22:58:221923
1924 // If a layout was not needed, |DidUpdateMainFrameLayout| will not be called.
1925 // We explicitly update the preferred size here to ensure the preferred size
1926 // notification is sent.
1927 UpdatePreferredSize();
[email protected]0666aef2009-05-13 19:48:081928}
1929
[email protected]310ebd6302011-10-10 19:06:281930void RenderViewImpl::OnSetRendererPrefs(
Leon Hanc819dc62019-01-28 04:30:191931 const blink::mojom::RendererPreferences& renderer_prefs) {
[email protected]ebd5ea52014-05-28 14:51:151932 std::string old_accept_languages = renderer_preferences_.accept_languages;
1933
[email protected]80d96fa2009-06-10 22:34:511934 renderer_preferences_ = renderer_prefs;
ananta59b9fe72015-04-07 01:33:261935
Julie Jeongeun Kim6d8b7492019-08-20 19:24:111936 for (auto& watcher : renderer_preference_watchers_)
1937 watcher->NotifyUpdate(renderer_prefs.Clone());
Makoto Shimazuc3c730e2018-08-15 09:51:111938
[email protected]6e282c92009-07-24 01:19:371939 UpdateFontRenderingFromRendererPrefs();
scottmgb92365e2016-08-30 20:54:401940 UpdateThemePrefs();
Leon Han2c81b5d2019-01-25 01:58:331941 blink::SetCaretBlinkInterval(
1942 renderer_prefs.caret_blink_interval.has_value()
1943 ? renderer_prefs.caret_blink_interval.value()
1944 : base::TimeDelta::FromMilliseconds(
Leon Hanc819dc62019-01-28 04:30:191945 blink::mojom::kDefaultCaretBlinkIntervalInMilliseconds));
[email protected]38a85712013-01-02 22:45:021946
Christopher Cameronf8e279d32019-05-15 18:50:561947#if defined(USE_AURA)
[email protected]1596efb2013-01-17 22:13:011948 if (renderer_prefs.use_custom_colors) {
Blink Reformat1c4d759e2017-04-09 16:34:541949 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
Christopher Cameronf6fc7ec2019-05-13 18:52:531950 blink::SetSelectionColors(renderer_prefs.active_selection_bg_color,
1951 renderer_prefs.active_selection_fg_color,
1952 renderer_prefs.inactive_selection_bg_color,
1953 renderer_prefs.inactive_selection_fg_color);
Erik Chenab7ed492019-08-28 01:34:491954 if (webview() && webview()->MainFrameWidget())
danakj763c2402018-11-09 02:46:221955 webview()->MainFrameWidget()->ThemeChanged();
[email protected]644d77e2010-01-27 01:03:101956 }
Christopher Cameronf8e279d32019-05-15 18:50:561957#endif
[email protected]d299d972012-03-23 02:26:551958
[email protected]ebd5ea52014-05-28 14:51:151959 if (webview() &&
1960 old_accept_languages != renderer_preferences_.accept_languages) {
Blink Reformat1c4d759e2017-04-09 16:34:541961 webview()->AcceptLanguagesChanged();
[email protected]ebd5ea52014-05-28 14:51:151962 }
[email protected]80d96fa2009-06-10 22:34:511963}
1964
[email protected]81375e872012-01-11 21:40:361965void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
Sergio Villar Senineb8c252452019-10-04 17:18:281966 const PluginAction& action) {
[email protected]81375e872012-01-11 21:40:361967 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:541968 webview()->PerformPluginAction(action, location);
[email protected]81375e872012-01-11 21:40:361969}
1970
[email protected]310ebd6302011-10-10 19:06:281971void RenderViewImpl::OnClosePage() {
lukasza5d0dee42017-06-14 21:57:371972 // ViewMsg_ClosePage should only be sent to active, non-swapped-out views.
1973 DCHECK(webview()->MainFrame()->IsWebLocalFrame());
1974
initial.commit09911bf2008-07-26 23:55:291975 // TODO(creis): We'd rather use webview()->Close() here, but that currently
1976 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
1977 // in the onunload handler from appearing. For now, we're bypassing that and
1978 // calling the FrameLoader's CloseURL method directly. This should be
1979 // revisited to avoid having two ways to close a page. Having a single way
1980 // to close that can run onunload is also useful for fixing
1981 // http://b/issue?id=753080.
lukasza5d0dee42017-06-14 21:57:371982 webview()->MainFrame()->ToWebLocalFrame()->DispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:291983
avia3dca182016-03-19 01:09:521984 Send(new ViewHostMsg_ClosePage_ACK(GetRoutingID()));
initial.commit09911bf2008-07-26 23:55:291985}
1986
[email protected]310ebd6302011-10-10 19:06:281987void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:001988 if (webview())
danakja5c39d52018-12-13 22:20:561989 webview()->CancelPagePopup();
[email protected]30f75e62009-02-25 22:01:001990}
1991
lfg717154072016-06-30 15:04:161992void RenderViewImpl::OnPageWasHidden() {
braveyao1d8ee7b2017-03-29 21:10:041993#if defined(OS_ANDROID)
1994 SuspendVideoCaptureDevices(true);
braveyao1d8ee7b2017-03-29 21:10:041995#endif
[email protected]2d7b82c2012-06-01 05:57:501996
danakj78744912018-11-30 23:46:421997 ApplyPageHidden(/*hidden=*/true, /*initial_setting=*/false);
[email protected]941e4552010-02-01 21:23:431998}
1999
lfg717154072016-06-30 15:04:162000void RenderViewImpl::OnPageWasShown() {
braveyao1d8ee7b2017-03-29 21:10:042001#if defined(OS_ANDROID)
2002 SuspendVideoCaptureDevices(false);
[email protected]6392d982013-04-16 16:59:222003#endif
2004
danakj78744912018-11-30 23:46:422005 ApplyPageHidden(/*hidden=*/false, /*initial_setting=*/false);
[email protected]a6939ca42011-02-18 17:58:072006}
[email protected]1e6e3c992010-02-08 15:52:132007
W. James MacLean7c8581072019-06-18 18:07:532008void RenderViewImpl::OnUpdatePageVisualProperties(
danakjffc8baf2019-10-10 23:49:422009 const gfx::Size& viewport_size_for_blink) {
Erik Chena515bf32019-09-09 21:53:032010 // TODO(https://crbug.com/998273): Handle visual_properties appropriately.
W. James MacLean7c8581072019-06-18 18:07:532011 // Using this pathway to update the visual viewport should only happen for
2012 // remote main frames. Local main frames will update the viewport size by
2013 // RenderWidget calling RenderViewImpl::ResizeVisualViewport() directly.
danakjffc8baf2019-10-10 23:49:422014 // TODO(danakj): This should be part of VisualProperties and walk down the
2015 // RenderWidget tree like other VisualProperties do, in order to set the
2016 // value in each WebView holds a part of the local frame tree.
2017 if (!main_render_frame_)
2018 webview()->Resize(viewport_size_for_blink);
W. James MacLean7c8581072019-06-18 18:07:532019}
2020
2021void RenderViewImpl::ResizeVisualViewportForWidget(
2022 const gfx::Size& scaled_viewport_size) {
2023 // This function is currently only called for local main frames. Once remote
2024 // main frames no longer have a RenderWidget, they may also route through
Erik Chena515bf32019-09-09 21:53:032025 // here via RenderViewImpl::OnUpdateLocalMainFramePageVisualProperties(). In
2026 // that case, WebViewImpl will need to implement its Size() function based on
2027 // something other than the widget size.
W. James MacLean7c8581072019-06-18 18:07:532028 webview()->ResizeVisualViewport(scaled_viewport_size);
2029}
2030
Francois Doray47f759d2018-06-11 18:13:512031void RenderViewImpl::SetPageFrozen(bool frozen) {
2032 if (webview())
2033 webview()->SetPageFrozen(frozen);
Fadi Meawada6573e02018-03-10 00:52:112034}
2035
Yuzu Saijodfba8fa62019-08-27 02:15:222036void RenderViewImpl::PutPageIntoBackForwardCache() {
2037 if (webview())
2038 webview()->PutPageIntoBackForwardCache();
2039}
2040
2041void RenderViewImpl::RestorePageFromBackForwardCache() {
2042 if (webview())
2043 webview()->RestorePageFromBackForwardCache();
2044}
2045
W. James MacLean62198672019-06-04 16:46:102046// This function receives TextAutosizerPageInfo from the main frame's renderer
2047// and makes it available to other renderers with frames on the same page.
2048void RenderViewImpl::OnTextAutosizerPageInfoChanged(
2049 const blink::WebTextAutosizerPageInfo& page_info) {
2050 // Only propagate the remote page info if our main frame is remote. It's
2051 // possible a main frame renderer may receive this message, as SendPageMessage
2052 // in RenderFrameHostManager may send to a speculative RenderFrameHost that
2053 // corresponds to a local main frame. Since a local main frame will generate
2054 // these values for itself, we shouldn't override them with values from
2055 // another renderer.
2056 if (!webview()->MainFrame()->IsWebLocalFrame())
2057 webview()->SetTextAutosizePageInfo(page_info);
2058}
2059
alexmos3fcd0ca2015-10-23 18:18:332060void RenderViewImpl::SetFocus(bool enable) {
Erik Chena2819852019-08-28 01:02:282061 // This is only called from RenderFrameProxy.
2062 CHECK(!webview()->MainFrame()->IsWebLocalFrame());
2063 webview()->SetFocus(enable);
[email protected]b2e4c70132013-10-03 02:07:512064}
2065
W. James MacLean233a64ff2019-05-18 16:18:492066void RenderViewImpl::PageScaleFactorChanged(float page_scale_factor) {
ccameronb7c1d6c2015-03-09 17:08:242067 if (!webview())
2068 return;
mcnee432e47d2015-11-09 19:37:462069
avia3dca182016-03-19 01:09:522070 Send(new ViewHostMsg_PageScaleFactorChanged(GetRoutingID(),
W. James MacLeanf40603e2019-03-25 17:23:062071 page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:242072}
2073
W. James MacLean62198672019-06-04 16:46:102074void RenderViewImpl::DidUpdateTextAutosizerPageInfo(
2075 const blink::WebTextAutosizerPageInfo& page_info) {
2076 DCHECK(webview()->MainFrame()->IsWebLocalFrame());
2077 Send(new ViewHostMsg_NotifyTextAutosizerPageInfoChangedInLocalMainFrame(
2078 GetRoutingID(), page_info));
2079}
2080
Blink Reformat1c4d759e2017-04-09 16:34:542081void RenderViewImpl::PageImportanceSignalsChanged() {
kouhei40f03cb2015-09-24 07:47:012082 if (!webview() || !main_render_frame_)
2083 return;
2084
Blink Reformat1c4d759e2017-04-09 16:34:542085 auto* web_signals = webview()->PageImportanceSignals();
kouhei40f03cb2015-09-24 07:47:012086
2087 PageImportanceSignals signals;
Blink Reformat1c4d759e2017-04-09 16:34:542088 signals.had_form_interaction = web_signals->HadFormInteraction();
kouhei40f03cb2015-09-24 07:47:012089
2090 main_render_frame_->Send(new FrameHostMsg_UpdatePageImportanceSignals(
2091 main_render_frame_->GetRoutingID(), signals));
2092}
2093
danakj9a8a9cf2018-07-17 23:52:122094void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) {
Erik Chene4ae6b42019-10-01 12:06:282095 // Auto resize should only happen on local main frames.
2096 DCHECK(render_widget_);
danakj872a96a12019-09-18 21:53:142097 render_widget_->DidAutoResize(newSize);
danakj9a8a9cf2018-07-17 23:52:122098}
2099
danakja2c9d0a92018-07-25 20:01:182100void RenderViewImpl::DidFocus(blink::WebLocalFrame* calling_frame) {
2101 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2102 // we won't have to test for user gesture anymore and we can
2103 // move that code back to render_widget.cc
2104 if (WebUserGestureIndicator::IsProcessingUserGesture(calling_frame) &&
Kent Tamura2eab5b12018-12-07 04:31:232105 !RenderThreadImpl::current()->web_test_mode()) {
danakja2c9d0a92018-07-25 20:01:182106 Send(new ViewHostMsg_Focus(GetRoutingID()));
2107
2108 // Tattle on the frame that called |window.focus()|.
2109 RenderFrameImpl* calling_render_frame =
2110 RenderFrameImpl::FromWebFrame(calling_frame);
2111 if (calling_render_frame)
2112 calling_render_frame->FrameDidCallFocus();
2113 }
2114}
2115
[email protected]20657a82012-08-21 20:23:032116#if defined(OS_ANDROID)
braveyao1d8ee7b2017-03-29 21:10:042117void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) {
2118 if (!main_render_frame_)
2119 return;
2120
Guido Urdanetadc7090372019-07-29 17:59:542121 blink::WebMediaStreamDeviceObserver* media_stream_device_observer =
Antonio Gomes32f24faf2019-08-18 16:41:362122 main_render_frame_->MediaStreamDeviceObserver();
Chandan Padhi26dbd9b32017-11-27 11:13:352123 if (!media_stream_device_observer)
braveyao1d8ee7b2017-03-29 21:10:042124 return;
2125
Guido Urdaneta73fa6632019-01-14 18:46:262126 blink::MediaStreamDevices video_devices =
Chandan Padhi26dbd9b32017-11-27 11:13:352127 media_stream_device_observer->GetNonScreenCaptureDevices();
braveyao1d8ee7b2017-03-29 21:10:042128 RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices(
Chandan Padhi6dbfb732017-09-01 16:08:492129 video_devices, suspend);
braveyao1d8ee7b2017-03-29 21:10:042130}
estade6b9696bd2016-05-04 23:51:362131#endif // defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:032132
[email protected]b283d292013-02-21 08:40:342133unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
2134 return history_list_length_;
2135}
2136
[email protected]cc290f902013-03-04 20:06:022137void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
Nasko Oskova463a052018-05-08 16:42:142138 // If the main frame is remote, return immediately. Page level focus
2139 // should be set from the browser process, so if needed by tests it should
2140 // be properly supported.
2141 if (webview()->MainFrame()->IsWebRemoteFrame())
2142 return;
2143
danakj872a96a12019-09-18 21:53:142144 if (enable == render_widget_->has_focus())
danakja2c9d0a92018-07-25 20:01:182145 return;
2146
[email protected]cc290f902013-03-04 20:06:022147 if (enable) {
danakja2c9d0a92018-07-25 20:01:182148 SetActiveForWidget(true);
2149 // Fake an IPC message so go through the IPC handler.
danakj872a96a12019-09-18 21:53:142150 render_widget_->OnSetFocus(true);
[email protected]cc290f902013-03-04 20:06:022151 } else {
danakja2c9d0a92018-07-25 20:01:182152 // Fake an IPC message so go through the IPC handler.
danakj872a96a12019-09-18 21:53:142153 render_widget_->OnSetFocus(false);
danakja2c9d0a92018-07-25 20:01:182154 SetActiveForWidget(false);
[email protected]cc290f902013-03-04 20:06:022155 }
2156}
2157
W. James MacLeand973a55b2018-11-29 21:39:132158void RenderViewImpl::OnAnimateDoubleTapZoomInMainFrame(
2159 const blink::WebPoint& point,
2160 const blink::WebRect& bound) {
2161 webview()->AnimateDoubleTapZoom(point, bound);
2162}
2163
W. James MacLean5372eb72018-12-19 12:56:362164void RenderViewImpl::OnZoomToFindInPageRect(
2165 const blink::WebRect& rect_to_zoom) {
2166 webview()->ZoomToFindInPageRect(rect_to_zoom);
2167}
2168
danakjd51fd53d2018-12-21 23:06:092169void RenderViewImpl::OnSetBackgroundOpaque(bool opaque) {
2170 if (!webview())
2171 return;
2172
2173 if (opaque) {
2174 webview()->ClearBaseBackgroundColorOverride();
2175 webview()->ClearBackgroundColorOverride();
2176 } else {
2177 webview()->SetBaseBackgroundColorOverride(SK_ColorTRANSPARENT);
2178 webview()->SetBackgroundColorOverride(SK_ColorTRANSPARENT);
2179 }
2180}
2181
danakj295c43f182019-03-13 16:37:172182// static
2183scoped_refptr<base::SingleThreadTaskRunner>
2184RenderViewImpl::GetCleanupTaskRunner() {
2185 return RenderThreadImpl::current_blink_platform_impl()
2186 ->main_thread_scheduler()
2187 ->CleanupTaskRunner();
2188}
2189
[email protected]e9ff79c2012-10-19 21:31:262190} // namespace content