blob: 7a450ad61a662c625cc1c2b925e8583dafe677be [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"
asvitkine8d51e9d2016-09-02 23:55:4325#include "base/metrics/histogram_macros.h"
[email protected]d3b4ee22013-07-24 22:50:0626#include "base/process/kill.h"
[email protected]7d08a9352013-10-15 08:24:5627#include "base/process/process.h"
fdoray7a8954a42016-06-07 04:28:3828#include "base/single_thread_task_runner.h"
danakja4ba7e52018-11-29 23:04:3129#include "base/stl_util.h"
[email protected]21aa99682013-06-11 07:17:0130#include "base/strings/string_number_conversions.h"
[email protected]b9e7c479f2013-04-12 04:33:2431#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4932#include "base/strings/string_split.h"
[email protected]21aa99682013-06-11 07:17:0133#include "base/strings/string_util.h"
[email protected]40d11e02013-03-28 17:43:1434#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0035#include "base/strings/utf_string_conversions.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0336#include "base/system/sys_info.h"
fdoray7a8954a42016-06-07 04:28:3837#include "base/threading/thread_task_runner_handle.h"
[email protected]abb522162013-06-28 01:54:1638#include "base/time/time.h"
primiano9e38d552015-01-28 04:18:0139#include "base/trace_event/trace_event.h"
avi1023d012015-12-25 02:39:1440#include "build/build_config.h"
dongseong.hwange095dfa2016-02-04 11:21:3941#include "cc/base/switches.h"
enne98c9f8052017-03-15 19:38:2242#include "cc/paint/skia_paint_canvas.h"
danakj4c987652018-07-05 15:49:4143#include "cc/trees/layer_tree_host.h"
jinho.bang632a1a722014-09-18 03:02:5644#include "content/common/content_constants_internal.h"
[email protected]5f2aa722013-08-07 16:59:4145#include "content/common/dom_storage/dom_storage_types.h"
[email protected]59f4f2fa2011-03-23 01:00:5546#include "content/common/drag_messages.h"
[email protected]c6bc20332014-02-28 18:30:3947#include "content/common/frame_messages.h"
alexmosbc7eafa2014-12-06 01:38:0948#include "content/common/frame_replication_state.h"
[email protected]c084330e02013-04-27 01:08:1549#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0750#include "content/common/page_messages.h"
rockot5c478a72016-09-28 23:14:1851#include "content/common/render_message_filter.mojom.h"
[email protected]778574e2011-03-21 22:03:5052#include "content/common/view_messages.h"
[email protected]744c2a22012-03-15 18:42:0453#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4854#include "content/public/common/content_constants.h"
Tarun Bansal73dd2ff82017-10-03 05:29:3455#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2956#include "content/public/common/content_switches.h"
kouhei40f03cb2015-09-24 07:47:0157#include "content/public/common/page_importance_signals.h"
clamyda97e8322014-10-07 21:57:2558#include "content/public/common/page_state.h"
[email protected]7940b8e2013-07-25 23:08:4959#include "content/public/common/page_zoom.h"
Leon Han963dc182018-11-06 05:41:4860#include "content/public/common/referrer_type_converters.h"
[email protected]818915cd2012-11-20 13:14:1161#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0362#include "content/public/common/url_constants.h"
Jaebaek Seo53ab80a662018-01-29 04:50:4663#include "content/public/common/use_zoom_for_dsf_policy.h"
[email protected]b3a97b52014-07-09 06:25:0564#include "content/public/common/web_preferences.h"
[email protected]d344114c2011-10-01 01:24:3465#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0766#include "content/public/renderer/document_state.h"
Avi Drissman07d22452019-03-25 17:56:3967#include "content/public/renderer/render_thread.h"
[email protected]3a034ebb2011-10-03 19:19:4468#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3669#include "content/public/renderer/render_view_visitor.h"
scottmg8e6c6082017-02-13 23:15:4870#include "content/public/renderer/window_features_converter.h"
John Abd-El-Malekdcf1d1372017-10-22 06:39:4171#include "content/renderer/appcache/web_application_cache_host_impl.h"
[email protected]e6e56752012-08-10 00:46:0672#include "content/renderer/browser_plugin/browser_plugin.h"
73#include "content/renderer/browser_plugin/browser_plugin_manager.h"
Sadrul Habib Chowdhury31c98712018-12-11 04:15:1374#include "content/renderer/compositor/layer_tree_view.h"
[email protected]dc293a72013-07-01 11:11:2275#include "content/renderer/drop_data_builder.h"
[email protected]dc064352014-04-25 08:36:3876#include "content/renderer/history_serialization.h"
[email protected]66fca5bc2013-05-23 06:58:2977#include "content/renderer/ime_event_guard.h"
[email protected]92d457802013-04-01 19:18:4978#include "content/renderer/internal_document_state_data.h"
John Abd-El-Malek6b56ef712017-10-21 22:52:4679#include "content/renderer/loader/request_extra_data.h"
Amos Limbcc710e2018-06-08 05:51:1780#include "content/renderer/media/audio/audio_device_factory.h"
Miguel Casasa8c2c5a2018-02-12 18:51:0381#include "content/renderer/media/stream/media_stream_device_observer.h"
Guido Urdanetabd7f0962019-03-25 17:52:0282#include "content/renderer/media/video_capture/video_capture_impl_manager.h"
Patrik Höglundb564859b2018-05-17 11:17:1683#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
84#include "content/renderer/media/webrtc/rtc_peer_connection_handler.h"
[email protected]227692c52013-05-31 22:43:0485#include "content/renderer/render_frame_impl.h"
[email protected]5a7100d2014-05-19 01:29:0486#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0587#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4488#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4489#include "content/renderer/render_widget_fullscreen_pepper.h"
Daniel Murphye3eec92c2018-02-23 19:09:1590#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]663bd9e2011-03-21 01:07:0191#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]12a936d2013-05-15 04:55:4992#include "content/renderer/savable_resources.h"
John Abd-El-Malek312a30bb2017-10-23 19:51:5293#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:2194#include "content/renderer/web_ui_extension_data.h"
[email protected]f5961142013-04-17 23:09:4295#include "media/audio/audio_output_device.h"
[email protected]ee68378a2010-08-10 01:05:4196#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:4497#include "media/media_buildflags.h"
servolkf54f5c8f2015-02-24 20:32:3998#include "media/renderers/audio_renderer_impl.h"
Dale Curtis863022e2017-08-19 02:05:3499#include "media/video/gpu_video_accelerator_factories.h"
[email protected]d1ef81d2012-07-24 11:39:36100#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29101#include "net/base/escape.h"
102#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09103#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04104#include "net/http/http_util.h"
Tarun Bansal73d67f02018-01-17 05:56:25105#include "net/nqe/effective_connection_type.h"
Scott Violet02e38b92018-03-27 23:42:14106#include "ppapi/buildflags/buildflags.h"
lukenb171b532014-09-24 05:50:38107#include "skia/ext/platform_canvas.h"
Blink Reformata30d4232018-04-07 15:31:06108#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
Daniel Murphy95792ef2018-10-04 01:29:55109#include "third_party/blink/public/common/dom_storage/session_storage_namespace_id.h"
Mustaq Ahmed76c2f4312018-06-07 20:48:01110#include "third_party/blink/public/common/frame/user_activation_update_source.h"
Blink Reformata30d4232018-04-07 15:31:06111#include "third_party/blink/public/platform/file_path_conversion.h"
112#include "third_party/blink/public/platform/url_conversion.h"
113#include "third_party/blink/public/platform/web_connection_type.h"
114#include "third_party/blink/public/platform/web_effective_connection_type.h"
115#include "third_party/blink/public/platform/web_http_body.h"
116#include "third_party/blink/public/platform/web_image.h"
117#include "third_party/blink/public/platform/web_input_event.h"
118#include "third_party/blink/public/platform/web_input_event_result.h"
119#include "third_party/blink/public/platform/web_network_state_notifier.h"
120#include "third_party/blink/public/platform/web_point.h"
121#include "third_party/blink/public/platform/web_rect.h"
122#include "third_party/blink/public/platform/web_runtime_features.h"
123#include "third_party/blink/public/platform/web_size.h"
124#include "third_party/blink/public/platform/web_string.h"
125#include "third_party/blink/public/platform/web_url.h"
126#include "third_party/blink/public/platform/web_url_error.h"
127#include "third_party/blink/public/platform/web_url_request.h"
128#include "third_party/blink/public/platform/web_url_response.h"
129#include "third_party/blink/public/platform/web_vector.h"
130#include "third_party/blink/public/public_buildflags.h"
131#include "third_party/blink/public/web/web_autofill_client.h"
132#include "third_party/blink/public/web/web_ax_object.h"
133#include "third_party/blink/public/web/web_date_time_chooser_completion.h"
134#include "third_party/blink/public/web/web_date_time_chooser_params.h"
135#include "third_party/blink/public/web/web_document.h"
136#include "third_party/blink/public/web/web_dom_event.h"
137#include "third_party/blink/public/web/web_dom_message_event.h"
138#include "third_party/blink/public/web/web_element.h"
Blink Reformata30d4232018-04-07 15:31:06139#include "third_party/blink/public/web/web_form_control_element.h"
140#include "third_party/blink/public/web/web_form_element.h"
141#include "third_party/blink/public/web/web_frame.h"
142#include "third_party/blink/public/web/web_frame_content_dumper.h"
143#include "third_party/blink/public/web/web_frame_widget.h"
144#include "third_party/blink/public/web/web_history_item.h"
145#include "third_party/blink/public/web/web_hit_test_result.h"
146#include "third_party/blink/public/web/web_input_element.h"
147#include "third_party/blink/public/web/web_local_frame.h"
Blink Reformata30d4232018-04-07 15:31:06148#include "third_party/blink/public/web/web_navigation_policy.h"
149#include "third_party/blink/public/web/web_page_importance_signals.h"
danakj25ec6e2b2018-09-26 17:01:31150#include "third_party/blink/public/web/web_page_popup.h"
Blink Reformata30d4232018-04-07 15:31:06151#include "third_party/blink/public/web/web_plugin.h"
152#include "third_party/blink/public/web/web_plugin_action.h"
153#include "third_party/blink/public/web/web_range.h"
154#include "third_party/blink/public/web/web_render_theme.h"
155#include "third_party/blink/public/web/web_script_source.h"
156#include "third_party/blink/public/web/web_searchable_form_data.h"
157#include "third_party/blink/public/web/web_security_policy.h"
158#include "third_party/blink/public/web/web_settings.h"
159#include "third_party/blink/public/web/web_user_gesture_indicator.h"
160#include "third_party/blink/public/web/web_view.h"
161#include "third_party/blink/public/web/web_window_features.h"
[email protected]b3a97b52014-07-09 06:25:05162#include "third_party/icu/source/common/unicode/uchar.h"
163#include "third_party/icu/source/common/unicode/uscript.h"
esecklerf2bd55f72017-03-31 09:11:57164#include "third_party/skia/include/core/SkColor.h"
[email protected]1400e6dc2013-04-27 02:36:27165#include "ui/base/ui_base_switches_util.h"
tfarina655f81d2014-12-23 02:38:50166#include "ui/gfx/geometry/point.h"
tfarina3b0452d2014-12-31 15:20:09167#include "ui/gfx/geometry/rect.h"
168#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32169#include "ui/gfx/geometry/size_conversions.h"
[email protected]08397d52011-02-05 01:53:38170#include "ui/gfx/native_widget_types.h"
ccameron772317d2017-06-04 18:35:03171#include "ui/gfx/switches.h"
mfomitchev3ba450ad2017-04-03 18:20:40172#include "ui/latency/latency_info.h"
csharrisond88f9752016-10-26 23:56:36173#include "url/origin.h"
markdittmer67b71ea2016-03-03 22:40:03174#include "url/url_constants.h"
[email protected]c4a9e932011-03-05 04:05:55175#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:29176
[email protected]25fb9b32012-04-27 03:21:55177#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25178#include <cpu-features.h>
179
dalecurtiscd971252016-09-21 16:09:00180#include "base/android/build_info.h"
kylechare7d8d5c72018-01-05 19:06:28181#include "base/memory/shared_memory.h"
182#include "content/child/child_thread_impl.h"
tfarina3b0452d2014-12-31 15:20:09183#include "ui/gfx/geometry/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40184
[email protected]78043bdd2010-04-05 18:45:33185#elif defined(OS_MACOSX)
186#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57187#endif
188
brettw4b461082016-11-19 18:55:16189#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]ea2fb972013-08-07 05:44:26190#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
191#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26192#endif
193
[email protected]180ef242013-11-07 06:50:46194using blink::WebAXObject;
195using blink::WebApplicationCacheHost;
196using blink::WebApplicationCacheHostClient;
[email protected]180ef242013-11-07 06:50:46197using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46198using blink::WebData;
[email protected]180ef242013-11-07 06:50:46199using blink::WebDocument;
[email protected]180ef242013-11-07 06:50:46200using blink::WebDragOperation;
[email protected]180ef242013-11-07 06:50:46201using blink::WebElement;
[email protected]180ef242013-11-07 06:50:46202using blink::WebFormControlElement;
203using blink::WebFormElement;
204using blink::WebFrame;
dglazkov03223492016-02-08 22:16:03205using blink::WebFrameContentDumper;
[email protected]180ef242013-11-07 06:50:46206using blink::WebGestureEvent;
207using blink::WebHistoryItem;
208using blink::WebHTTPBody;
dglazkov8d0c21dd2016-08-06 15:56:36209using blink::WebHitTestResult;
[email protected]180ef242013-11-07 06:50:46210using blink::WebImage;
211using blink::WebInputElement;
212using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22213using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46214using blink::WebMouseEvent;
215using blink::WebNavigationPolicy;
216using blink::WebNavigationType;
217using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46218using blink::WebPluginAction;
[email protected]180ef242013-11-07 06:50:46219using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46220using blink::WebRect;
Daniel Chengd5e56ff2017-06-24 07:44:02221using blink::WebSandboxFlags;
[email protected]180ef242013-11-07 06:50:46222using blink::WebScriptSource;
223using blink::WebSearchableFormData;
224using blink::WebSecurityOrigin;
225using blink::WebSecurityPolicy;
[email protected]180ef242013-11-07 06:50:46226using blink::WebSettings;
227using blink::WebSize;
[email protected]180ef242013-11-07 06:50:46228using blink::WebString;
[email protected]180ef242013-11-07 06:50:46229using blink::WebTextDirection;
230using blink::WebTouchEvent;
231using blink::WebURL;
232using blink::WebURLError;
233using blink::WebURLRequest;
234using blink::WebURLResponse;
235using blink::WebUserGestureIndicator;
236using blink::WebVector;
237using blink::WebView;
238using blink::WebWidget;
239using blink::WebWindowFeatures;
[email protected]b3a97b52014-07-09 06:25:05240using blink::WebRuntimeFeatures;
[email protected]e1acf6f2008-10-27 20:43:33241
[email protected]e9ff79c2012-10-19 21:31:26242namespace content {
243
initial.commit09911bf2008-07-26 23:55:29244//-----------------------------------------------------------------------------
245
[email protected]180ef242013-11-07 06:50:46246typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
jbroman8319b232017-03-08 22:53:29247static base::LazyInstance<ViewMap>::Leaky g_view_map =
[email protected]058561b2012-12-03 06:48:22248 LAZY_INSTANCE_INITIALIZER;
scottmg5e65e3a2017-03-08 08:48:46249typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap;
jbroman8319b232017-03-08 22:53:29250static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map =
251 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02252
[email protected]882daa92009-11-05 16:31:31253// Time, in seconds, we delay before sending content state changes (such as form
254// state and scroll position) to the browser. We delay sending changes to avoid
255// spamming the browser.
256// To avoid having tab/session restore require sending a message to get the
257// current content state during tab closing we use a shorter timeout for the
258// foreground renderer. This means there is a small window of time from which
259// content state is modified and not sent to session restore, but this is
260// better than having to wake up all renderers during shutdown.
avif937e1d2014-11-02 18:13:07261const int kDelaySecondsForContentStateSyncHidden = 5;
262const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29263
dcheng35d31c112015-07-22 00:17:36264static RenderViewImpl* (*g_create_render_view_impl)(
265 CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15266 const mojom::CreateViewParams&) = nullptr;
[email protected]8d41d7612012-11-14 20:32:19267
[email protected]c6bc20332014-02-28 18:30:39268// static
[email protected]e507045d2013-07-24 15:23:44269Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56270 WebFrame* frame,
271 const WebURLRequest& request) {
Blink Reformat1c4d759e2017-04-09 16:34:54272 return Referrer(blink::WebStringToGURL(
273 request.HttpHeaderField(WebString::FromUTF8("Referer"))),
274 request.GetReferrerPolicy());
[email protected]44e55b012013-07-23 14:21:56275}
276
[email protected]c6bc20332014-02-28 18:30:39277// static
[email protected]65920f332014-03-04 21:14:18278WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32279 WebNavigationPolicy policy) {
280 switch (policy) {
Blink Reformat1c4d759e2017-04-09 16:34:54281 case blink::kWebNavigationPolicyDownload:
nick3b04f322016-08-31 19:29:19282 return WindowOpenDisposition::SAVE_TO_DISK;
Blink Reformat1c4d759e2017-04-09 16:34:54283 case blink::kWebNavigationPolicyCurrentTab:
nick3b04f322016-08-31 19:29:19284 return WindowOpenDisposition::CURRENT_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54285 case blink::kWebNavigationPolicyNewBackgroundTab:
nick3b04f322016-08-31 19:29:19286 return WindowOpenDisposition::NEW_BACKGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54287 case blink::kWebNavigationPolicyNewForegroundTab:
nick3b04f322016-08-31 19:29:19288 return WindowOpenDisposition::NEW_FOREGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54289 case blink::kWebNavigationPolicyNewWindow:
nick3b04f322016-08-31 19:29:19290 return WindowOpenDisposition::NEW_WINDOW;
Blink Reformat1c4d759e2017-04-09 16:34:54291 case blink::kWebNavigationPolicyNewPopup:
nick3b04f322016-08-31 19:29:19292 return WindowOpenDisposition::NEW_POPUP;
[email protected]48861e22013-01-09 00:27:32293 default:
294 NOTREACHED() << "Unexpected WebNavigationPolicy";
nick3b04f322016-08-31 19:29:19295 return WindowOpenDisposition::IGNORE_ACTION;
[email protected]48861e22013-01-09 00:27:32296 }
297}
298
initial.commit09911bf2008-07-26 23:55:29299///////////////////////////////////////////////////////////////////////////////
300
[email protected]217690d2012-01-27 07:33:11301namespace {
302
[email protected]b3a97b52014-07-09 06:25:05303typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
304 const base::string16&,
305 UScriptCode);
306
307void SetStandardFontFamilyWrapper(WebSettings* settings,
308 const base::string16& font,
309 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54310 settings->SetStandardFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05311}
312
313void SetFixedFontFamilyWrapper(WebSettings* settings,
314 const base::string16& font,
315 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54316 settings->SetFixedFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05317}
318
319void SetSerifFontFamilyWrapper(WebSettings* settings,
320 const base::string16& font,
321 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54322 settings->SetSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05323}
324
325void SetSansSerifFontFamilyWrapper(WebSettings* settings,
326 const base::string16& font,
327 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54328 settings->SetSansSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05329}
330
331void SetCursiveFontFamilyWrapper(WebSettings* settings,
332 const base::string16& font,
333 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54334 settings->SetCursiveFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05335}
336
337void SetFantasyFontFamilyWrapper(WebSettings* settings,
338 const base::string16& font,
339 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54340 settings->SetFantasyFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05341}
342
343void SetPictographFontFamilyWrapper(WebSettings* settings,
344 const base::string16& font,
345 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54346 settings->SetPictographFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05347}
348
349// If |scriptCode| is a member of a family of "similar" script codes, returns
350// the script code in that family that is used by WebKit for font selection
351// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
352// considered equivalent for the purposes of font selection. WebKit uses the
353// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
354// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
355// uses different scripts than the ones in Chrome pref names because the version
356// of ICU included on certain ports does not have some of the newer scripts. If
357// |scriptCode| is not a member of such a family, returns |scriptCode|.
358UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
359 switch (scriptCode) {
360 case USCRIPT_HIRAGANA:
361 case USCRIPT_KATAKANA:
362 case USCRIPT_JAPANESE:
363 return USCRIPT_KATAKANA_OR_HIRAGANA;
364 case USCRIPT_KOREAN:
365 return USCRIPT_HANGUL;
366 default:
367 return scriptCode;
368 }
369}
370
371void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
372 SetFontFamilyWrapper setter,
373 WebSettings* settings) {
jdoerrie5a73d0fa2018-10-02 23:54:05374 for (auto it = map.begin(); it != map.end(); ++it) {
avi1023d012015-12-25 02:39:14375 int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
[email protected]b3a97b52014-07-09 06:25:05376 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
377 UScriptCode code = static_cast<UScriptCode>(script);
378 (*setter)(settings, it->second, GetScriptForWebSettings(code));
379 }
380 }
381}
382
danakjefcb8432019-01-16 18:47:14383void ApplyCommandLineToSettings(WebSettings* settings) {
384 const base::CommandLine& command_line =
385 *base::CommandLine::ForCurrentProcess();
386
danakjed9464612019-01-16 00:00:59387 settings->SetThreadedScrollingEnabled(
388 !command_line.HasSwitch(switches::kDisableThreadedScrolling));
wangxianzhu3bf39be52015-04-10 23:56:41389
danakjed9464612019-01-16 00:00:59390 if (switches::IsTouchDragDropEnabled())
391 settings->SetTouchDragDropEnabled(true);
392
393 WebSettings::SelectionStrategyType selection_strategy;
394 if (command_line.GetSwitchValueASCII(switches::kTouchTextSelectionStrategy) ==
395 "direction")
396 selection_strategy = WebSettings::SelectionStrategyType::kDirection;
397 else
398 selection_strategy = WebSettings::SelectionStrategyType::kCharacter;
399 settings->SetSelectionStrategy(selection_strategy);
400
401 std::string passive_listeners_default =
402 command_line.GetSwitchValueASCII(switches::kPassiveListenersDefault);
403 if (!passive_listeners_default.empty()) {
404 WebSettings::PassiveEventListenerDefault passive_default =
405 WebSettings::PassiveEventListenerDefault::kFalse;
406 if (passive_listeners_default == "true")
407 passive_default = WebSettings::PassiveEventListenerDefault::kTrue;
408 else if (passive_listeners_default == "forcealltrue")
409 passive_default = WebSettings::PassiveEventListenerDefault::kForceAllTrue;
410 settings->SetPassiveEventListenerDefault(passive_default);
411 }
412
413 std::string network_quiet_timeout =
414 command_line.GetSwitchValueASCII(switches::kNetworkQuietTimeout);
415 if (!network_quiet_timeout.empty()) {
416 double network_quiet_timeout_seconds = 0.0;
417 if (base::StringToDouble(network_quiet_timeout,
418 &network_quiet_timeout_seconds))
419 settings->SetNetworkQuietTimeout(network_quiet_timeout_seconds);
420 }
421
422 if (command_line.HasSwitch(switches::kBlinkSettings)) {
423 std::vector<std::string> blink_settings = base::SplitString(
424 command_line.GetSwitchValueASCII(switches::kBlinkSettings), ",",
425 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
426 for (const std::string& setting : blink_settings) {
427 size_t pos = setting.find('=');
428 settings->SetFromStrings(
429 blink::WebString::FromLatin1(setting.substr(0, pos)),
430 blink::WebString::FromLatin1(
431 pos == std::string::npos ? "" : setting.substr(pos + 1)));
432 }
wangxianzhu3bf39be52015-04-10 23:56:41433 }
434}
435
scottmgde42fb92017-02-10 17:56:03436content::mojom::WindowContainerType WindowFeaturesToContainerType(
scottmg05324cb2017-02-09 23:46:04437 const blink::WebWindowFeatures& window_features) {
japhetbfc47892017-06-02 23:01:19438 if (window_features.background) {
439 if (window_features.persistent)
scottmgde42fb92017-02-10 17:56:03440 return content::mojom::WindowContainerType::PERSISTENT;
scottmg05324cb2017-02-09 23:46:04441 else
scottmgde42fb92017-02-10 17:56:03442 return content::mojom::WindowContainerType::BACKGROUND;
scottmg05324cb2017-02-09 23:46:04443 } else {
scottmgde42fb92017-02-10 17:56:03444 return content::mojom::WindowContainerType::NORMAL;
scottmg05324cb2017-02-09 23:46:04445 }
446}
447
Ahmed Fakhry58e6ef542018-09-04 18:05:38448// Check content::BrowserControlsState, and cc::BrowserControlsState
449// are kept in sync.
450static_assert(int(BROWSER_CONTROLS_STATE_SHOWN) ==
451 int(cc::BrowserControlsState::kShown),
452 "mismatching enums: SHOWN");
453static_assert(int(BROWSER_CONTROLS_STATE_HIDDEN) ==
454 int(cc::BrowserControlsState::kHidden),
455 "mismatching enums: HIDDEN");
456static_assert(int(BROWSER_CONTROLS_STATE_BOTH) ==
457 int(cc::BrowserControlsState::kBoth),
458 "mismatching enums: BOTH");
459
460cc::BrowserControlsState ContentToCc(BrowserControlsState state) {
461 return static_cast<cc::BrowserControlsState>(state);
462}
Ahmed Fakhry58e6ef542018-09-04 18:05:38463
[email protected]217690d2012-01-27 07:33:11464} // namespace
465
Hajime Hoshi315a61f2018-08-14 17:27:28466RenderViewImpl::RenderViewImpl(CompositorDependencies* compositor_deps,
467 const mojom::CreateViewParams& params)
Albert J. Wong7faa3da2019-03-21 20:43:43468 : routing_id_(params.view_id),
danakj73dd3032018-07-28 17:49:53469 renderer_wide_named_frame_lookup_(
470 params.renderer_wide_named_frame_lookup),
naskobd911332014-11-25 01:13:36471 webkit_preferences_(params.web_preferences),
changwand659e202016-06-13 02:39:12472 session_storage_namespace_id_(params.session_storage_namespace_id),
wjmaclean1d970622017-01-21 22:28:24473 weak_ptr_factory_(this) {
Daniel Murphy95792ef2018-10-04 01:29:55474 DCHECK(!session_storage_namespace_id_.empty())
475 << "Session storage namespace must be populated.";
Albert J. Wong7faa3da2019-03-21 20:43:43476 // Please put all logic in RenderViewImpl::Initialize().
477}
Albert J. Wong7bbf22d2018-12-20 00:27:27478
Albert J. Wong7faa3da2019-03-21 20:43:43479void RenderViewImpl::Initialize(
480 RenderWidget* render_widget,
481 mojom::CreateViewParamsPtr params,
482 RenderWidget::ShowCallback show_callback,
483 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Avi Drissman07d22452019-03-25 17:56:39484 DCHECK(RenderThread::IsMainThread());
485
Albert J. Wong7bbf22d2018-12-20 00:27:27486 // RenderView used to inherit from RenderWidget. Creating a delegate
487 // interface and explicitly passing ownership of ourselves to the
488 // RenderWidget preserves the lifetime semantics. This is a stepping
489 // stone to having RenderWidget creation taken out of the RenderViewImpl
490 // constructor. See the corresponding explicit reset() of the delegate
491 // in the ~RenderWidget(). Also, I hate inheritance.
Albert J. Wong7faa3da2019-03-21 20:43:43492 render_widget_ = render_widget;
Albert J. Wong7bbf22d2018-12-20 00:27:27493 GetWidget()->set_delegate(base::WrapUnique(this));
Albert J. Wongcb004632018-07-10 22:58:25494 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]075366912013-02-18 07:13:24495
nickf7b38222016-11-22 21:59:35496#if defined(OS_ANDROID)
danakjc87bfede2018-10-10 22:32:49497 bool has_show_callback = !!show_callback;
nickf7b38222016-11-22 21:59:35498#endif
[email protected]676126f72011-01-15 00:03:51499
Lukasz Anforowiczaf2f33572018-01-17 14:05:08500 WebFrame* opener_frame =
501 RenderFrameImpl::ResolveOpener(params->opener_frame_route_id);
502
danakj9a8a9cf2018-07-17 23:52:12503 // Pass WidgetClient(), not |this|, as the WebWidgetClient. The method may
Kent Tamura21d1de62018-12-10 04:45:20504 // be overridden in web tests to inject a test-only WebWidgetClient.
danakj284d557d2019-01-16 17:00:26505 webview_ = WebView::Create(this, params->hidden,
Sadrul Habib Chowdhury042a4712018-12-06 00:16:56506 /*compositing_enabled=*/true,
danakja4ba7e52018-11-29 23:04:31507 opener_frame ? opener_frame->View() : nullptr);
Albert J. Wong2727e8a82019-02-15 16:56:11508
Albert J. Wong7faa3da2019-03-21 20:43:43509 // Note: The GetWidget->Init() call causes an AddRef() to itself meaning that
510 // IPC system has taken conceptual ownership of the object. Though it is
511 // tempting to have RenderView retain the RenderWidget(), this lifecycle
512 // only requires single ownership and adding scoped_refptr<RenderWidget>
513 // muddies this unnecessarily -- especially since this RenderWidget should
514 // ultimately be own by the main frame.
Albert J. Wong7bbf22d2018-12-20 00:27:27515 GetWidget()->Init(std::move(show_callback), webview_->MainFrameWidget());
[email protected]11fee2332011-03-29 20:36:35516
nasko4c0feb62015-06-05 18:37:06517 g_view_map.Get().insert(std::make_pair(webview(), this));
avia3dca182016-03-19 01:09:52518 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this));
nasko4c0feb62015-06-05 18:37:06519
danakj505476792019-01-11 23:53:46520 webview()->SetDisplayMode(params->visual_properties.display_mode);
dcheng0ff94cfc2016-03-15 21:50:51521
danakjfd0c7f42018-10-12 18:01:08522 ApplyWebPreferences(webkit_preferences_, webview());
danakjefcb8432019-01-16 18:47:14523 ApplyCommandLineToSettings(webview()->GetSettings());
dcheng0ff94cfc2016-03-15 21:50:51524
danakjaf29226f2018-09-25 17:56:57525 // We have either a main frame or a proxy routing id.
526 DCHECK_NE(params->main_frame_routing_id != MSG_ROUTING_NONE,
527 params->proxy_routing_id != MSG_ROUTING_NONE);
528
Balazs Engedyba034e72017-10-27 22:26:28529 if (params->main_frame_routing_id != MSG_ROUTING_NONE) {
Oksana Zhuravlova8b88e572019-01-07 21:54:00530 CHECK(params->main_frame_interface_bundle);
Ken Rockot26efbd62017-11-16 04:39:49531 service_manager::mojom::InterfaceProviderPtr main_frame_interface_provider(
Oksana Zhuravlova8b88e572019-01-07 21:54:00532 std::move(params->main_frame_interface_bundle->interface_provider));
533
dcheng3ce04b62015-10-26 23:30:55534 main_render_frame_ = RenderFrameImpl::CreateMainFrame(
Balazs Engedyba034e72017-10-27 22:26:28535 this, params->main_frame_routing_id,
Ken Rockot26efbd62017-11-16 04:39:49536 std::move(main_frame_interface_provider),
Oksana Zhuravlova8b88e572019-01-07 21:54:00537 blink::mojom::DocumentInterfaceBrokerPtr(
538 std::move(params->main_frame_interface_bundle
539 ->document_interface_broker_content)),
540 blink::mojom::DocumentInterfaceBrokerPtr(
541 std::move(params->main_frame_interface_bundle
542 ->document_interface_broker_blink)),
Fady Samuela863f152018-03-09 16:10:03543 params->main_frame_widget_routing_id, params->hidden,
danakj53802692018-07-25 21:46:44544 GetWidget()->GetWebScreenInfo(), GetWidget()->compositor_deps(),
545 opener_frame, params->devtools_main_frame_token,
546 params->replicated_frame_state, params->has_committed_real_load);
danakjaf29226f2018-09-25 17:56:57547 } else {
Balazs Engedyba034e72017-10-27 22:26:28548 RenderFrameProxy::CreateFrameProxy(params->proxy_routing_id, GetRoutingID(),
nick3b5a21f2016-11-22 23:07:11549 opener_frame, MSG_ROUTING_NONE,
Dmitry Gozman89361212018-02-13 16:10:44550 params->replicated_frame_state,
551 params->devtools_main_frame_token);
danakjb08b3712019-01-16 18:59:56552 // TODO(danakj): Make WebViewImpl not need a WebWidgetClient when there is a
553 // remote main frame (when the RenderWidget is frozen).
danakj40d07932019-02-28 18:07:10554 webview_->DidAttachRemoteMainFrame(render_widget_);
nasko4c0feb62015-06-05 18:37:06555 }
556
[email protected]c7c0d822014-04-16 20:19:49557 // TODO(davidben): Move this state from Blink into content.
Balazs Engedyba034e72017-10-27 22:26:28558 if (params->window_was_created_with_opener)
Blink Reformat1c4d759e2017-04-09 16:34:54559 webview()->SetOpenedByDOM();
[email protected]c7c0d822014-04-16 20:19:49560
Albert J. Wong7bbf22d2018-12-20 00:27:27561 GetWidget()->UpdateWebViewWithDeviceScaleFactor();
Leon Han2c81b5d2019-01-25 01:58:33562 OnSetRendererPrefs(*params->renderer_preferences);
Albert J. Wong7bbf22d2018-12-20 00:27:27563 GetWidget()->OnSynchronizeVisualProperties(params->visual_properties);
[email protected]1784b2f2011-11-24 10:53:48564
[email protected]e9ff79c2012-10-19 21:31:26565 GetContentClient()->renderer()->RenderViewCreated(this);
akabac6bd1212018-06-25 20:10:48566 page_zoom_level_ = 0;
Hajime Hoshif34374412018-03-05 14:32:54567
568 nav_state_sync_timer_.SetTaskRunner(task_runner);
danakjc87bfede2018-10-10 22:32:49569
Adithya Srinivasan46b8a792019-02-01 14:47:23570 // We pass this state to Page, but it's only used by the main frame in the
571 // page.
572 if (params->inside_portal)
573 webview()->SetInsidePortal(true);
574
danakjc87bfede2018-10-10 22:32:49575#if defined(OS_ANDROID)
576 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated
577 // HandleNavigation codepath.
578 // Renderer-created RenderViews have a ShowCallback because they send a Show
579 // request (ViewHostMsg_ShowWidget, ViewHostMsg_ShowFullscreenWidget, or
580 // FrameHostMsg_ShowCreatedWindow) to the browser to attach them to the UI
581 // there. Browser-created RenderViews do not send a Show request to the
582 // browser, so have no such callback.
583 was_created_by_renderer_ = has_show_callback;
584#endif
initial.commit09911bf2008-07-26 23:55:29585}
586
[email protected]310ebd6302011-10-10 19:06:28587RenderViewImpl::~RenderViewImpl() {
dcheng3ce04b62015-10-26 23:30:55588 DCHECK(!frame_widget_);
Albert J. Wongcb004632018-07-10 22:58:25589 RenderThread::Get()->RemoveRoute(routing_id_);
dcheng3ce04b62015-10-26 23:30:55590
[email protected]8ed1d3f2013-02-20 11:45:55591#if defined(OS_ANDROID)
davve17e025e12016-05-23 15:30:20592 // The date/time picker client is both a std::unique_ptr member of this class
593 // and a RenderViewObserver. Reset it to prevent double deletion.
[email protected]8ed1d3f2013-02-20 11:45:55594 date_time_picker_client_.reset();
595#endif
596
[email protected]60c42a8c72009-10-09 04:08:59597#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22598 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49599 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59600 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
601 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22602 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
603 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
604 it != routing_id_views->end(); ++it)
605 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59606#endif
[email protected]676126f72011-01-15 00:03:51607
ericwilligers88e69742016-10-17 19:29:55608 for (auto& observer : observers_)
609 observer.RenderViewGone();
610 for (auto& observer : observers_)
611 observer.OnDestruct();
[email protected]60c42a8c72009-10-09 04:08:59612}
613
614/*static*/
[email protected]310ebd6302011-10-10 19:06:28615RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
Avi Drissman07d22452019-03-25 17:56:39616 DCHECK(RenderThread::IsMainThread());
[email protected]a2ef54c2011-10-10 16:20:31617 ViewMap* views = g_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05618 auto it = views->find(webview);
[email protected]a2ef54c2011-10-10 16:20:31619 return it == views->end() ? NULL : it->second;
620}
621
622/*static*/
[email protected]180ef242013-11-07 06:50:46623RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28624 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31625}
626
627/*static*/
avi1023d012015-12-25 02:39:14628RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) {
Avi Drissman07d22452019-03-25 17:56:39629 DCHECK(RenderThread::IsMainThread());
[email protected]640e303c2012-12-05 01:36:07630 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05631 auto it = views->find(routing_id);
[email protected]640e303c2012-12-05 01:36:07632 return it == views->end() ? NULL : it->second;
633}
634
635/*static*/
636RenderView* RenderView::FromRoutingID(int routing_id) {
637 return RenderViewImpl::FromRoutingID(routing_id);
638}
639
[email protected]f3a95312014-06-12 16:46:58640/* static */
jochen9c7b8f242015-06-01 15:32:02641size_t RenderView::GetRenderViewCount() {
[email protected]f3a95312014-06-12 16:46:58642 return g_view_map.Get().size();
643}
644
[email protected]640e303c2012-12-05 01:36:07645/*static*/
[email protected]e9ff79c2012-10-19 21:31:26646void RenderView::ForEach(RenderViewVisitor* visitor) {
Avi Drissman07d22452019-03-25 17:56:39647 DCHECK(RenderThread::IsMainThread());
[email protected]625332e02010-12-14 07:48:49648 ViewMap* views = g_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05649 for (auto it = views->begin(); it != views->end(); ++it) {
[email protected]60c42a8c72009-10-09 04:08:59650 if (!visitor->Visit(it->second))
651 return;
652 }
653}
654
655/*static*/
[email protected]b3a97b52014-07-09 06:25:05656void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
657 WebView* web_view) {
Blink Reformat1c4d759e2017-04-09 16:34:54658 WebSettings* settings = web_view->GetSettings();
[email protected]b3a97b52014-07-09 06:25:05659 ApplyFontsFromMap(prefs.standard_font_family_map,
660 SetStandardFontFamilyWrapper, settings);
661 ApplyFontsFromMap(prefs.fixed_font_family_map,
662 SetFixedFontFamilyWrapper, settings);
663 ApplyFontsFromMap(prefs.serif_font_family_map,
664 SetSerifFontFamilyWrapper, settings);
665 ApplyFontsFromMap(prefs.sans_serif_font_family_map,
666 SetSansSerifFontFamilyWrapper, settings);
667 ApplyFontsFromMap(prefs.cursive_font_family_map,
668 SetCursiveFontFamilyWrapper, settings);
669 ApplyFontsFromMap(prefs.fantasy_font_family_map,
670 SetFantasyFontFamilyWrapper, settings);
671 ApplyFontsFromMap(prefs.pictograph_font_family_map,
672 SetPictographFontFamilyWrapper, settings);
Blink Reformat1c4d759e2017-04-09 16:34:54673 settings->SetDefaultFontSize(prefs.default_font_size);
674 settings->SetDefaultFixedFontSize(prefs.default_fixed_font_size);
675 settings->SetMinimumFontSize(prefs.minimum_font_size);
676 settings->SetMinimumLogicalFontSize(prefs.minimum_logical_font_size);
677 settings->SetDefaultTextEncodingName(
678 WebString::FromASCII(prefs.default_encoding));
679 settings->SetJavaScriptEnabled(prefs.javascript_enabled);
680 settings->SetWebSecurityEnabled(prefs.web_security_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54681 settings->SetLoadsImagesAutomatically(prefs.loads_images_automatically);
682 settings->SetImagesEnabled(prefs.images_enabled);
683 settings->SetPluginsEnabled(prefs.plugins_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54684 settings->SetDOMPasteAllowed(prefs.dom_paste_enabled);
685 settings->SetTextAreasAreResizable(prefs.text_areas_are_resizable);
686 settings->SetAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
687 settings->SetDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
688 settings->SetJavaScriptCanAccessClipboard(
[email protected]b3a97b52014-07-09 06:25:05689 prefs.javascript_can_access_clipboard);
Blink Reformat1c4d759e2017-04-09 16:34:54690 WebRuntimeFeatures::EnableXSLT(prefs.xslt_enabled);
691 settings->SetXSSAuditorEnabled(prefs.xss_auditor_enabled);
692 settings->SetDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
Tarun Bansal333819e2018-05-15 16:38:42693 blink::WebNetworkStateNotifier::SetSaveDataEnabled(prefs.data_saver_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54694 settings->SetLocalStorageEnabled(prefs.local_storage_enabled);
695 settings->SetSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
696 WebRuntimeFeatures::EnableDatabase(prefs.databases_enabled);
697 settings->SetOfflineWebApplicationCacheEnabled(
[email protected]b3a97b52014-07-09 06:25:05698 prefs.application_cache_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54699 settings->SetHistoryEntryRequiresUserGesture(
japhet5018fe62016-09-14 19:14:04700 prefs.history_entry_requires_user_gesture);
Arthur Sonzogni721f48e2018-10-31 17:10:02701 settings->SetShouldProtectAgainstIpcFlooding(
702 !prefs.disable_ipc_flooding_protection);
Blink Reformat1c4d759e2017-04-09 16:34:54703 settings->SetHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
704 settings->SetCookieEnabled(prefs.cookie_enabled);
705 settings->SetNavigateOnDragDrop(prefs.navigate_on_drag_drop);
[email protected]b3a97b52014-07-09 06:25:05706
[email protected]b3a97b52014-07-09 06:25:05707 // By default, allow_universal_access_from_file_urls is set to false and thus
708 // we mitigate attacks from local HTML files by not granting file:// URLs
709 // universal access. Only test shell will enable this.
Blink Reformat1c4d759e2017-04-09 16:34:54710 settings->SetAllowUniversalAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05711 prefs.allow_universal_access_from_file_urls);
Blink Reformat1c4d759e2017-04-09 16:34:54712 settings->SetAllowFileAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05713 prefs.allow_file_access_from_file_urls);
714
Zhenyao Moa3fda9972017-09-16 01:34:40715 settings->SetWebGL1Enabled(prefs.webgl1_enabled);
716 settings->SetWebGL2Enabled(prefs.webgl2_enabled);
[email protected]b3a97b52014-07-09 06:25:05717
[email protected]b3a97b52014-07-09 06:25:05718 // Enable WebGL errors to the JS console if requested.
Blink Reformat1c4d759e2017-04-09 16:34:54719 settings->SetWebGLErrorsToConsoleEnabled(
[email protected]b3a97b52014-07-09 06:25:05720 prefs.webgl_errors_to_console_enabled);
721
722 // Uses the mock theme engine for scrollbars.
Blink Reformat1c4d759e2017-04-09 16:34:54723 settings->SetMockScrollbarsEnabled(prefs.mock_scrollbars_enabled);
[email protected]b3a97b52014-07-09 06:25:05724
Blink Reformat1c4d759e2017-04-09 16:34:54725 settings->SetHideScrollbars(prefs.hide_scrollbars);
eseckler61ff9142016-09-23 22:57:59726
[email protected]b3a97b52014-07-09 06:25:05727 // Enable gpu-accelerated 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54728 WebRuntimeFeatures::EnableAccelerated2dCanvas(
junov524668f22016-08-08 20:16:52729 prefs.accelerated_2d_canvas_enabled);
[email protected]b3a97b52014-07-09 06:25:05730
Blink Reformat1c4d759e2017-04-09 16:34:54731 settings->SetMinimumAccelerated2dCanvasSize(
[email protected]b3a97b52014-07-09 06:25:05732 prefs.minimum_accelerated_2d_canvas_size);
733
734 // Disable antialiasing for 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54735 settings->SetAntialiased2dCanvasEnabled(
[email protected]b3a97b52014-07-09 06:25:05736 !prefs.antialiased_2d_canvas_disabled);
737
zakerinasab20ebca02016-09-27 14:22:34738 // Disable antialiasing of clips for 2d canvas if requested on the command
robertphillipse25137b2014-10-20 13:44:34739 // line.
Blink Reformat1c4d759e2017-04-09 16:34:54740 settings->SetAntialiasedClips2dCanvasEnabled(
robertphillipse25137b2014-10-20 13:44:34741 prefs.antialiased_clips_2d_canvas_enabled);
742
[email protected]b3a97b52014-07-09 06:25:05743 // Set MSAA sample count for 2d canvas if requested on the command line (or
744 // default value if not).
Blink Reformat1c4d759e2017-04-09 16:34:54745 settings->SetAccelerated2dCanvasMSAASampleCount(
[email protected]b3a97b52014-07-09 06:25:05746 prefs.accelerated_2d_canvas_msaa_sample_count);
747
[email protected]b3a97b52014-07-09 06:25:05748 // Tabs to link is not part of the settings. WebCore calls
749 // ChromeClient::tabsToLinks which is part of the glue code.
Blink Reformat1c4d759e2017-04-09 16:34:54750 web_view->SetTabsToLinks(prefs.tabs_to_links);
[email protected]b3a97b52014-07-09 06:25:05751
Blink Reformat1c4d759e2017-04-09 16:34:54752 settings->SetAllowRunningOfInsecureContent(
[email protected]b3a97b52014-07-09 06:25:05753 prefs.allow_running_insecure_content);
Blink Reformat1c4d759e2017-04-09 16:34:54754 settings->SetDisableReadingFromCanvas(prefs.disable_reading_from_canvas);
755 settings->SetStrictMixedContentChecking(prefs.strict_mixed_content_checking);
mkwst2384c8222015-07-30 07:26:47756
Blink Reformat1c4d759e2017-04-09 16:34:54757 settings->SetStrictlyBlockBlockableMixedContent(
mkwst2384c8222015-07-30 07:26:47758 prefs.strictly_block_blockable_mixed_content);
759
Blink Reformat1c4d759e2017-04-09 16:34:54760 settings->SetStrictMixedContentCheckingForPlugin(
mkwst0d233e52015-08-10 09:33:14761 prefs.block_mixed_plugin_content);
762
Blink Reformat1c4d759e2017-04-09 16:34:54763 settings->SetStrictPowerfulFeatureRestrictions(
mkwst673a452f2015-01-10 14:41:50764 prefs.strict_powerful_feature_restrictions);
Blink Reformat1c4d759e2017-04-09 16:34:54765 settings->SetAllowGeolocationOnInsecureOrigins(
jww9d4ca2d2016-01-19 20:58:59766 prefs.allow_geolocation_on_insecure_origins);
Blink Reformat1c4d759e2017-04-09 16:34:54767 settings->SetPasswordEchoEnabled(prefs.password_echo_enabled);
768 settings->SetShouldPrintBackgrounds(prefs.should_print_backgrounds);
769 settings->SetShouldClearDocumentBackground(
[email protected]b3a97b52014-07-09 06:25:05770 prefs.should_clear_document_background);
Blink Reformat1c4d759e2017-04-09 16:34:54771 settings->SetEnableScrollAnimator(prefs.enable_scroll_animator);
Stephen McGruerbc3d0e62019-01-23 17:40:19772 settings->SetPrefersReducedMotion(prefs.prefers_reduced_motion);
[email protected]b3a97b52014-07-09 06:25:05773
Blink Reformat1c4d759e2017-04-09 16:34:54774 WebRuntimeFeatures::EnableTouchEventFeatureDetection(
sunyunjiafa6a8afc2016-12-09 04:25:47775 prefs.touch_event_feature_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54776 settings->SetMaxTouchPoints(prefs.pointer_events_max_touch_points);
777 settings->SetAvailablePointerTypes(prefs.available_pointer_types);
778 settings->SetPrimaryPointerType(
nzolghadrc0d1663c2015-11-26 21:15:24779 static_cast<blink::PointerType>(prefs.primary_pointer_type));
Blink Reformat1c4d759e2017-04-09 16:34:54780 settings->SetAvailableHoverTypes(prefs.available_hover_types);
781 settings->SetPrimaryHoverType(
nzolghadrc0d1663c2015-11-26 21:15:24782 static_cast<blink::HoverType>(prefs.primary_hover_type));
Blink Reformat1c4d759e2017-04-09 16:34:54783 settings->SetEnableTouchAdjustment(prefs.touch_adjustment_enabled);
Dave Tapuskaa59fdb62017-08-23 16:28:27784 settings->SetBarrelButtonForDragEnabled(prefs.barrel_button_for_drag_enabled);
[email protected]b3a97b52014-07-09 06:25:05785
Blink Reformat1c4d759e2017-04-09 16:34:54786 settings->SetShouldRespectImageOrientation(
[email protected]b3a97b52014-07-09 06:25:05787 prefs.should_respect_image_orientation);
788
Blink Reformat1c4d759e2017-04-09 16:34:54789 settings->SetEditingBehavior(
[email protected]b3a97b52014-07-09 06:25:05790 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
791
Blink Reformat1c4d759e2017-04-09 16:34:54792 settings->SetSupportsMultipleWindows(prefs.supports_multiple_windows);
[email protected]b3a97b52014-07-09 06:25:05793
Blink Reformat1c4d759e2017-04-09 16:34:54794 settings->SetMainFrameClipsContent(!prefs.record_whole_document);
khushalsagar2da2b232016-03-23 22:11:35795
Blink Reformat1c4d759e2017-04-09 16:34:54796 settings->SetSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
[email protected]b3a97b52014-07-09 06:25:05797
Blink Reformat1c4d759e2017-04-09 16:34:54798 settings->SetSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
Hugo Holgersson943ae692019-01-10 10:04:14799 // Spatnav depends on KeyboardFocusableScrollers. The WebUI team has
800 // disabled KFS because they need more time to update their custom elements,
801 // crbug.com/907284. Meanwhile, we pre-ship KFS to spatnav users.
802 if (prefs.spatial_navigation_enabled)
803 WebRuntimeFeatures::EnableKeyboardFocusableScrollers(true);
[email protected]b3a97b52014-07-09 06:25:05804
Blink Reformat1c4d759e2017-04-09 16:34:54805 settings->SetSelectionIncludesAltImageText(true);
[email protected]b3a97b52014-07-09 06:25:05806
Blink Reformat1c4d759e2017-04-09 16:34:54807 settings->SetV8CacheOptions(
[email protected]35103c02014-08-12 15:08:47808 static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options));
809
Blink Reformat1c4d759e2017-04-09 16:34:54810 settings->SetImageAnimationPolicy(
je_julie.kim7fbb5a1a2015-02-09 17:26:05811 static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy));
812
Blink Reformat1c4d759e2017-04-09 16:34:54813 settings->SetPresentationRequiresUserGesture(
zqzhang1215ad422016-02-10 13:27:22814 prefs.user_gesture_required_for_presentation);
815
Elly Fong-Jonesf92897392019-01-24 16:05:49816 settings->SetTextTrackBackgroundColor(
817 WebString::FromASCII(prefs.text_track_background_color));
818 settings->SetTextTrackTextColor(
819 WebString::FromASCII(prefs.text_track_text_color));
Rahul Singh1862faa92019-03-06 22:41:43820 settings->SetTextTrackTextSize(
821 WebString::FromASCII(prefs.text_track_text_size));
822 settings->SetTextTrackTextShadow(
823 WebString::FromASCII(prefs.text_track_text_shadow));
824 settings->SetTextTrackFontFamily(
825 WebString::FromASCII(prefs.text_track_font_family));
826 settings->SetTextTrackFontVariant(
827 WebString::FromASCII(prefs.text_track_font_variant));
Blink Reformat1c4d759e2017-04-09 16:34:54828 settings->SetTextTrackMarginPercentage(prefs.text_track_margin_percentage);
halliwell4002be42016-03-18 18:33:40829
David Bokana03511a92018-09-13 04:25:24830 // Needs to happen before SetDefaultPageScaleLimits below since that'll
831 // recalculate the final page scale limits and that depends on this setting.
832 settings->SetShrinksViewportContentToFit(
833 prefs.shrinks_viewport_contents_to_fit);
834
835 // Needs to happen before SetIgnoreViewportTagScaleLimits below.
Blink Reformat1c4d759e2017-04-09 16:34:54836 web_view->SetDefaultPageScaleLimits(prefs.default_minimum_page_scale_factor,
837 prefs.default_maximum_page_scale_factor);
dcheng5ae8ca362015-02-05 04:03:47838
Ahmed Fakhry42221452018-05-30 01:18:39839 settings->SetTextAutosizingEnabled(prefs.text_autosizing_enabled);
840 settings->SetDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
Tarun Bansald10f17a02018-09-13 00:23:17841 blink::WebNetworkStateNotifier::SetNetworkQualityWebHoldback(
842 static_cast<blink::WebEffectiveConnectionType>(
843 prefs.network_quality_estimator_web_holdback));
Ahmed Fakhry42221452018-05-30 01:18:39844
chaopeng7e8fb352019-03-26 03:34:49845 settings->SetDontSendKeyEventsToJavascript(
846 prefs.dont_send_key_events_to_javascript);
Mounir Lamouri6926107f2019-01-31 18:17:43847 settings->SetWebAppScope(WebString::FromASCII(prefs.web_app_scope.spec()));
848
[email protected]b3a97b52014-07-09 06:25:05849#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:54850 settings->SetAllowCustomScrollbarInMainFrame(false);
Blink Reformat1c4d759e2017-04-09 16:34:54851 settings->SetAccessibilityFontScaleFactor(prefs.font_scale_factor);
852 settings->SetDeviceScaleAdjustment(prefs.device_scale_adjustment);
853 settings->SetFullscreenSupported(prefs.fullscreen_supported);
854 web_view->SetIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
855 settings->SetAutoZoomFocusedNodeToLegibleScale(true);
Blink Reformat1c4d759e2017-04-09 16:34:54856 settings->SetDefaultVideoPosterURL(
857 WebString::FromASCII(prefs.default_video_poster_url.spec()));
858 settings->SetSupportDeprecatedTargetDensityDPI(
[email protected]b3a97b52014-07-09 06:25:05859 prefs.support_deprecated_target_density_dpi);
Blink Reformat1c4d759e2017-04-09 16:34:54860 settings->SetUseLegacyBackgroundSizeShorthandBehavior(
[email protected]b3a97b52014-07-09 06:25:05861 prefs.use_legacy_background_size_shorthand_behavior);
Blink Reformat1c4d759e2017-04-09 16:34:54862 settings->SetWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
863 settings->SetUseWideViewport(prefs.use_wide_viewport);
864 settings->SetForceZeroLayoutHeight(prefs.force_zero_layout_height);
865 settings->SetViewportMetaLayoutSizeQuirk(
[email protected]b3a97b52014-07-09 06:25:05866 prefs.viewport_meta_layout_size_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54867 settings->SetViewportMetaMergeContentQuirk(
[email protected]b3a97b52014-07-09 06:25:05868 prefs.viewport_meta_merge_content_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54869 settings->SetViewportMetaNonUserScalableQuirk(
[email protected]b3a97b52014-07-09 06:25:05870 prefs.viewport_meta_non_user_scalable_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54871 settings->SetViewportMetaZeroValuesQuirk(
[email protected]b3a97b52014-07-09 06:25:05872 prefs.viewport_meta_zero_values_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54873 settings->SetClobberUserAgentInitialScaleQuirk(
[email protected]b3a97b52014-07-09 06:25:05874 prefs.clobber_user_agent_initial_scale_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54875 settings->SetIgnoreMainFrameOverflowHiddenQuirk(
[email protected]b3a97b52014-07-09 06:25:05876 prefs.ignore_main_frame_overflow_hidden_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54877 settings->SetReportScreenSizeInPhysicalPixelsQuirk(
[email protected]b3a97b52014-07-09 06:25:05878 prefs.report_screen_size_in_physical_pixels_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54879 settings->SetShouldReuseGlobalForUnownedMainFrame(
tzik30eb52c2018-03-27 06:55:18880 prefs.reuse_global_for_unowned_main_frame);
Blink Reformat1c4d759e2017-04-09 16:34:54881 settings->SetPreferHiddenVolumeControls(true);
882 settings->SetSpellCheckEnabledByDefault(prefs.spellcheck_enabled_by_default);
dalecurtiscd971252016-09-21 16:09:00883
Blink Reformat1c4d759e2017-04-09 16:34:54884 WebRuntimeFeatures::EnableVideoFullscreenOrientationLock(
mlamouri1d266bf2016-12-05 17:42:36885 prefs.video_fullscreen_orientation_lock_enabled);
johnme913ee5f2017-04-28 21:36:16886 WebRuntimeFeatures::EnableVideoRotateToFullscreen(
887 prefs.video_rotate_to_fullscreen_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54888 WebRuntimeFeatures::EnableVideoFullscreenDetection(
zqzhang93e959d12017-03-16 13:10:20889 prefs.video_fullscreen_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54890 settings->SetEmbeddedMediaExperienceEnabled(
shaktisahuf97f7532017-02-24 22:46:13891 prefs.embedded_media_experience_enabled);
Ian Vollickeeca1d82018-02-07 02:43:42892 settings->SetImmersiveModeEnabled(prefs.immersive_mode_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54893 settings->SetDoNotUpdateSelectionOnMutatingSelectionRange(
changwane54ccdb92017-04-05 19:20:54894 prefs.do_not_update_selection_on_mutating_selection_range);
Noel Gordonf311a842017-07-27 00:10:07895 WebRuntimeFeatures::EnableCSSHexAlphaColor(prefs.css_hex_alpha_color_enabled);
Tobias Sargeant416174f2017-09-01 01:18:09896 WebRuntimeFeatures::EnableScrollTopLeftInterop(
897 prefs.scroll_top_left_interop_enabled);
zqzhangdf72ed082016-12-08 16:07:55898#endif // defined(OS_ANDROID)
liberato9e934892016-05-03 19:00:27899
Rune Lillesveenb46bb482019-04-02 07:36:29900 settings->SetForceDarkModeEnabled(prefs.force_dark_mode_enabled);
901
mlamouri55a0543c2017-05-11 10:34:07902 switch (prefs.autoplay_policy) {
903 case AutoplayPolicy::kNoUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28904 settings->SetAutoplayPolicy(
905 WebSettings::AutoplayPolicy::kNoUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07906 break;
907 case AutoplayPolicy::kUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28908 settings->SetAutoplayPolicy(
909 WebSettings::AutoplayPolicy::kUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07910 break;
mlamouri431bb4e2017-06-06 08:54:24911 case AutoplayPolicy::kDocumentUserActivationRequired:
912 settings->SetAutoplayPolicy(
913 WebSettings::AutoplayPolicy::kDocumentUserActivationRequired);
914 break;
mlamouri55a0543c2017-05-11 10:34:07915 }
916
Blink Reformat1c4d759e2017-04-09 16:34:54917 settings->SetViewportEnabled(prefs.viewport_enabled);
918 settings->SetViewportMetaEnabled(prefs.viewport_meta_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54919 settings->SetViewportStyle(
alokp5d566962016-04-19 00:54:16920 static_cast<blink::WebViewportStyle>(prefs.viewport_style));
921
Blink Reformat1c4d759e2017-04-09 16:34:54922 settings->SetLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
923 settings->SetMainFrameResizesAreOrientationChanges(
yoava1a508b42015-10-20 12:03:21924 prefs.main_frame_resizes_are_orientation_changes);
925
Blink Reformat1c4d759e2017-04-09 16:34:54926 settings->SetUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
jinho.bang8f11ffa2014-12-04 06:03:03927
Blink Reformat1c4d759e2017-04-09 16:34:54928 settings->SetShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up);
929 settings->SetAlwaysShowContextMenuOnTouch(
amaralp547e4192016-06-03 19:17:35930 prefs.always_show_context_menu_on_touch);
Sandra Sunc79fc93a2018-04-10 15:22:23931 settings->SetSmoothScrollForFindEnabled(prefs.smooth_scroll_for_find_enabled);
ccameron2fd70de72015-02-19 00:40:40932
Blink Reformat1c4d759e2017-04-09 16:34:54933 settings->SetHideDownloadUI(prefs.hide_download_ui);
qinmin72e8bd02016-10-21 19:35:37934
Blink Reformat1c4d759e2017-04-09 16:34:54935 settings->SetPresentationReceiver(prefs.presentation_receiver);
mlamouri57359d912016-11-29 20:11:50936
Blink Reformat1c4d759e2017-04-09 16:34:54937 settings->SetMediaControlsEnabled(prefs.media_controls_enabled);
mlamouri5cd9ae82017-02-18 11:05:09938
Tarun Bansal73d67f02018-01-17 05:56:25939 settings->SetLowPriorityIframesThreshold(
940 static_cast<blink::WebEffectiveConnectionType>(
941 prefs.low_priority_iframes_threshold));
942
Mounir Lamouri9c99a1602018-07-05 15:01:44943 settings->SetPictureInPictureEnabled(
944 prefs.picture_in_picture_enabled &&
[email protected]69db58f2018-09-26 20:27:56945 MediaFactory::GetVideoSurfaceLayerMode() !=
CJ DiMeglio89240472018-10-18 18:21:10946 blink::WebMediaPlayer::SurfaceLayerMode::kNever);
François Beaufort8c08979fc2018-03-05 13:06:31947
Tarun Bansal333819e2018-05-15 16:38:42948 settings->SetDataSaverHoldbackWebApi(
949 prefs.data_saver_holdback_web_api_enabled);
Tarun Bansal333819e2018-05-15 16:38:42950
rajendrante87ed712018-11-30 01:55:00951 settings->SetLazyLoadEnabled(prefs.lazy_load_enabled);
Rune Lillesveene17fb702019-03-15 07:26:14952 settings->SetPreferredColorScheme(prefs.preferred_color_scheme);
rajendrante87ed712018-11-30 01:55:00953
Scott Little878f7d6702018-05-31 22:09:06954 for (const auto& ect_distance_pair :
955 prefs.lazy_frame_loading_distance_thresholds_px) {
956 switch (ect_distance_pair.first) {
957 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
958 settings->SetLazyFrameLoadingDistanceThresholdPxUnknown(
959 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39960 continue;
Scott Little878f7d6702018-05-31 22:09:06961 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
962 settings->SetLazyFrameLoadingDistanceThresholdPxOffline(
963 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39964 continue;
Scott Little878f7d6702018-05-31 22:09:06965 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
966 settings->SetLazyFrameLoadingDistanceThresholdPxSlow2G(
967 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39968 continue;
Scott Little878f7d6702018-05-31 22:09:06969 case net::EFFECTIVE_CONNECTION_TYPE_2G:
970 settings->SetLazyFrameLoadingDistanceThresholdPx2G(
971 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39972 continue;
Scott Little878f7d6702018-05-31 22:09:06973 case net::EFFECTIVE_CONNECTION_TYPE_3G:
974 settings->SetLazyFrameLoadingDistanceThresholdPx3G(
975 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39976 continue;
Scott Little878f7d6702018-05-31 22:09:06977 case net::EFFECTIVE_CONNECTION_TYPE_4G:
978 settings->SetLazyFrameLoadingDistanceThresholdPx4G(
979 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39980 continue;
981 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
982 continue;
Scott Little878f7d6702018-05-31 22:09:06983 }
rajendrantd8026342018-08-29 08:08:39984 NOTREACHED();
985 }
986
987 for (const auto& ect_distance_pair :
988 prefs.lazy_image_loading_distance_thresholds_px) {
989 switch (ect_distance_pair.first) {
990 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
991 settings->SetLazyImageLoadingDistanceThresholdPxUnknown(
992 ect_distance_pair.second);
993 continue;
994 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
995 settings->SetLazyImageLoadingDistanceThresholdPxOffline(
996 ect_distance_pair.second);
997 continue;
998 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
999 settings->SetLazyImageLoadingDistanceThresholdPxSlow2G(
1000 ect_distance_pair.second);
1001 continue;
1002 case net::EFFECTIVE_CONNECTION_TYPE_2G:
1003 settings->SetLazyImageLoadingDistanceThresholdPx2G(
1004 ect_distance_pair.second);
1005 continue;
1006 case net::EFFECTIVE_CONNECTION_TYPE_3G:
1007 settings->SetLazyImageLoadingDistanceThresholdPx3G(
1008 ect_distance_pair.second);
1009 continue;
1010 case net::EFFECTIVE_CONNECTION_TYPE_4G:
1011 settings->SetLazyImageLoadingDistanceThresholdPx4G(
1012 ect_distance_pair.second);
1013 continue;
1014 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
1015 continue;
1016 }
1017 NOTREACHED();
Scott Little878f7d6702018-05-31 22:09:061018 }
1019
ccameron2fd70de72015-02-19 00:40:401020#if defined(OS_MACOSX)
Blink Reformat1c4d759e2017-04-09 16:34:541021 web_view->SetMaximumLegibleScale(prefs.default_maximum_page_scale_factor);
ccameron2fd70de72015-02-19 00:40:401022#endif
sunyunjia87f287b2016-09-09 00:38:131023
1024#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:541025 WebRuntimeFeatures::EnableMiddleClickAutoscroll(true);
sunyunjia87f287b2016-09-09 00:38:131026#endif
Dave Tapuskac6627e12018-08-30 15:07:191027
Dave Tapuskaa38e3252018-11-13 03:01:171028 WebRuntimeFeatures::EnableTranslateService(prefs.translate_service_available);
[email protected]b3a97b52014-07-09 06:25:051029}
1030
1031/*static*/
nickf7b38222016-11-22 21:59:351032RenderViewImpl* RenderViewImpl::Create(
1033 CompositorDependencies* compositor_deps,
Balazs Engedyba034e72017-10-27 22:26:281034 mojom::CreateViewParamsPtr params,
danakjdf1ceb72018-07-18 20:02:251035 RenderWidget::ShowCallback show_callback,
Hajime Hoshiabb3c8f2017-12-04 18:41:391036 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Balazs Engedyba034e72017-10-27 22:26:281037 DCHECK(params->view_id != MSG_ROUTING_NONE);
Albert J. Wongcb004632018-07-10 22:58:251038 DCHECK(params->main_frame_widget_routing_id != MSG_ROUTING_NONE);
Lei Zhang88f23ba2017-10-27 05:56:261039 RenderViewImpl* render_view;
[email protected]0287e762014-04-11 13:07:581040
Albert J. Wong7faa3da2019-03-21 20:43:431041 auto render_widget = RenderWidget::CreateForFrame(
1042 params->main_frame_widget_routing_id, compositor_deps,
1043 params->visual_properties.screen_info,
1044 params->visual_properties.display_mode,
1045 /*is_frozen=*/params->main_frame_routing_id == MSG_ROUTING_NONE,
1046 params->hidden, params->never_visible,
1047 /*widget_request=*/nullptr);
1048
1049 if (g_create_render_view_impl) {
1050 render_view = g_create_render_view_impl(compositor_deps, *params);
1051 } else {
1052 render_view = new RenderViewImpl(compositor_deps, *params);
1053 }
1054
1055 // After this call, the |render_widget| will be self-owning.
1056 //
1057 // TODO(http://crbug.com/419087): This refcoutning is messy. get the
1058 // RenderWidget initialization out of the render_view::Initialize() function.
1059 render_view->Initialize(render_widget.get(), std::move(params),
1060 std::move(show_callback), std::move(task_runner));
[email protected]075366912013-02-18 07:13:241061 return render_view;
[email protected]8d41d7612012-11-14 20:32:191062}
1063
1064// static
dcheng35d31c112015-07-22 00:17:361065void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
1066 *create_render_view_impl)(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:151067 const mojom::CreateViewParams&)) {
[email protected]8d41d7612012-11-14 20:32:191068 CHECK(!g_create_render_view_impl);
1069 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291070}
1071
[email protected]310ebd6302011-10-10 19:06:281072void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511073 observers_.AddObserver(observer);
1074}
1075
[email protected]310ebd6302011-10-10 19:06:281076void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1077 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511078 observers_.RemoveObserver(observer);
1079}
1080
Peter Kastinga4a3ed12018-01-31 04:07:591081blink::WebView* RenderViewImpl::webview() {
1082 return webview_;
1083}
1084
1085const blink::WebView* RenderViewImpl::webview() const {
lfg4fa48da2016-05-09 18:25:131086 return webview_;
[email protected]4d51d5bf2010-07-26 18:48:261087}
1088
danakja2c9d0a92018-07-25 20:01:181089// RenderWidgetOwnerDelegate -----------------------------------------
fsamuel72464894f2015-12-15 06:59:311090
danakja2c9d0a92018-07-25 20:01:181091blink::WebWidget* RenderViewImpl::GetWebWidgetForWidget() const {
1092 return frame_widget_;
1093}
1094
1095bool RenderViewImpl::RenderWidgetWillHandleMouseEventForWidget(
avid7d6b2e2016-03-04 19:41:171096 const blink::WebMouseEvent& event) {
fsamuel72464894f2015-12-15 06:59:311097 // If the mouse is locked, only the current owner of the mouse lock can
1098 // process mouse events.
danakja2c9d0a92018-07-25 20:01:181099 return GetWidget()->mouse_lock_dispatcher()->WillHandleMouseEvent(event);
fsamuel72464894f2015-12-15 06:59:311100}
1101
danakja2c9d0a92018-07-25 20:01:181102void RenderViewImpl::SetActiveForWidget(bool active) {
Albert J. Wongcb004632018-07-10 22:58:251103 if (webview())
1104 webview()->SetIsActive(active);
1105}
1106
danakja2c9d0a92018-07-25 20:01:181107bool RenderViewImpl::SupportsMultipleWindowsForWidget() {
1108 return webkit_preferences_.supports_multiple_windows;
1109}
1110
1111void RenderViewImpl::DidHandleGestureEventForWidget(
1112 const WebGestureEvent& event) {
1113 for (auto& observer : observers_)
1114 observer.DidHandleGestureEvent(event);
1115}
1116
David Bokan11f6ef482019-03-18 17:47:271117bool RenderViewImpl::ShouldAckSyntheticInputImmediately() {
1118 // TODO(bokan): The RequestPresentation API appears not to function in VR. As
1119 // a short term workaround for https://crbug.com/940063, ACK input
1120 // immediately rather than using RequestPresentation.
1121 if (webkit_preferences_.immersive_mode_enabled)
1122 return true;
1123 return false;
1124}
1125
danakja2c9d0a92018-07-25 20:01:181126void RenderViewImpl::DidCloseWidget() {
1127 // The webview_ is already destroyed by the time we get here, remove any
1128 // references to it.
1129 g_view_map.Get().erase(webview_);
1130 webview_ = nullptr;
1131 g_routing_id_view_map.Get().erase(GetRoutingID());
Albert J. Wong2727e8a82019-02-15 16:56:111132
1133 // The |render_widget_| is deleted after DidCloseWidget() returns. Drop the
1134 // reference to it to avoid a UaF.
1135 render_widget_ = nullptr;
danakja2c9d0a92018-07-25 20:01:181136}
1137
danakj84bbf552019-01-21 21:33:311138void RenderViewImpl::CancelPagePopupForWidget() {
1139 webview()->CancelPagePopup();
danakja2c9d0a92018-07-25 20:01:181140}
1141
1142void RenderViewImpl::ApplyNewDisplayModeForWidget(
1143 const blink::WebDisplayMode& new_display_mode) {
danakj1ab8faf2018-10-12 18:24:281144 webview()->SetDisplayMode(new_display_mode);
danakja2c9d0a92018-07-25 20:01:181145}
1146
1147void RenderViewImpl::ApplyAutoResizeLimitsForWidget(const gfx::Size& min_size,
1148 const gfx::Size& max_size) {
1149 webview()->EnableAutoResizeMode(min_size, max_size);
1150}
1151
1152void RenderViewImpl::DisableAutoResizeForWidget() {
1153 webview()->DisableAutoResizeMode();
1154}
1155
1156void RenderViewImpl::ScrollFocusedNodeIntoViewForWidget() {
1157 if (WebLocalFrame* focused_frame = GetWebView()->FocusedFrame()) {
1158 auto* frame_widget = focused_frame->LocalRoot()->FrameWidget();
1159 frame_widget->ScrollFocusedEditableElementIntoView();
1160 }
1161}
1162
1163void RenderViewImpl::DidReceiveSetFocusEventForWidget() {
1164 // This message must always be received when the main frame is a
1165 // WebLocalFrame.
Albert J. Wong7bbf22d2018-12-20 00:27:271166 // TODO(ajwong): Can this be removed and just check |delegate_| in
danakja2c9d0a92018-07-25 20:01:181167 // RenderWidget instead?
1168 CHECK(webview()->MainFrame()->IsWebLocalFrame());
1169}
1170
1171void RenderViewImpl::DidChangeFocusForWidget() {
1172 // Notify all BrowserPlugins of the RenderView's focus state.
1173 if (BrowserPluginManager::Get())
1174 BrowserPluginManager::Get()->UpdateFocusState();
1175}
1176
danakja2c9d0a92018-07-25 20:01:181177void RenderViewImpl::DidCommitCompositorFrameForWidget() {
1178 for (auto& observer : observers_)
1179 observer.DidCommitCompositorFrame();
Philip Rogers33cd2bcc2018-08-13 21:29:291180 UpdatePreferredSize();
danakja2c9d0a92018-07-25 20:01:181181}
1182
1183void RenderViewImpl::DidCompletePageScaleAnimationForWidget() {
1184 if (auto* focused_frame = GetWebView()->FocusedFrame()) {
1185 if (focused_frame->AutofillClient())
1186 focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame();
1187 }
1188}
1189
1190void RenderViewImpl::ResizeWebWidgetForWidget(
1191 const gfx::Size& size,
1192 float top_controls_height,
1193 float bottom_controls_height,
1194 bool browser_controls_shrink_blink_size) {
1195 webview()->ResizeWithBrowserControls(size, top_controls_height,
1196 bottom_controls_height,
1197 browser_controls_shrink_blink_size);
1198}
1199
danakja2c9d0a92018-07-25 20:01:181200void RenderViewImpl::SetScreenMetricsEmulationParametersForWidget(
1201 bool enabled,
1202 const blink::WebDeviceEmulationParams& params) {
danakj1ab8faf2018-10-12 18:24:281203 if (enabled)
1204 webview()->EnableDeviceEmulation(params);
1205 else
1206 webview()->DisableDeviceEmulation();
danakja2c9d0a92018-07-25 20:01:181207}
1208
1209// IPC message handlers -----------------------------------------
1210
danakja2c9d0a92018-07-25 20:01:181211void RenderViewImpl::OnUpdateTargetURLAck() {
1212 // Check if there is a targeturl waiting to be sent.
1213 if (target_url_status_ == TARGET_PENDING)
1214 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), pending_target_url_));
1215
1216 target_url_status_ = TARGET_NONE;
1217}
1218
1219void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset,
1220 int history_length) {
1221 // -1 <= history_offset < history_length <= kMaxSessionHistoryEntries(50).
1222 DCHECK_LE(-1, history_offset);
1223 DCHECK_LT(history_offset, history_length);
1224 DCHECK_LE(history_length, kMaxSessionHistoryEntries);
1225
1226 history_list_offset_ = history_offset;
1227 history_list_length_ = history_length;
1228}
1229
1230void RenderViewImpl::OnSetInitialFocus(bool reverse) {
1231 if (!webview())
1232 return;
1233 webview()->SetInitialFocus(reverse);
1234}
1235
danakja2c9d0a92018-07-25 20:01:181236void RenderViewImpl::OnAudioStateChanged(bool is_audio_playing) {
1237 webview()->AudioStateChanged(is_audio_playing);
1238}
1239
danakja2c9d0a92018-07-25 20:01:181240///////////////////////////////////////////////////////////////////////////////
1241
1242void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget,
1243 WebNavigationPolicy policy,
1244 const gfx::Rect& initial_rect) {
1245 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(),
1246 initial_rect));
1247}
1248
1249void RenderViewImpl::ShowCreatedFullscreenWidget(
1250 RenderWidget* fullscreen_widget,
1251 WebNavigationPolicy policy,
1252 const gfx::Rect& initial_rect) {
1253 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(),
1254 fullscreen_widget->routing_id()));
1255}
1256
1257void RenderViewImpl::SendFrameStateUpdates() {
1258 // Tell each frame with pending state to send its UpdateState message.
1259 for (int render_frame_routing_id : frames_with_pending_state_) {
1260 RenderFrameImpl* frame =
1261 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
1262 if (frame)
1263 frame->SendUpdateState();
1264 }
1265 frames_with_pending_state_.clear();
1266}
1267
danakja2c9d0a92018-07-25 20:01:181268// IPC::Listener -------------------------------------------------------------
fsamuel72464894f2015-12-15 06:59:311269
[email protected]310ebd6302011-10-10 19:06:281270bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281271 WebFrame* main_frame = webview() ? webview()->MainFrame() : nullptr;
Avi Drissmanb5f8e242017-12-12 05:21:561272 if (main_frame) {
1273 GURL active_url;
1274 if (main_frame->IsWebLocalFrame())
1275 active_url = main_frame->ToWebLocalFrame()->GetDocument().Url();
lukaszabedb4b22017-06-23 00:00:131276 GetContentClient()->SetActiveURL(
Avi Drissmanb5f8e242017-12-12 05:21:561277 active_url, main_frame->Top()->GetSecurityOrigin().ToString().Utf8());
1278 }
[email protected]f8b6b6f2009-03-10 16:48:261279
dchenga2d442c22016-10-13 15:39:211280 for (auto& observer : observers_) {
1281 if (observer.OnMessageReceived(message))
[email protected]676126f72011-01-15 00:03:511282 return true;
dchenga2d442c22016-10-13 15:39:211283 }
[email protected]b2abac72009-02-26 12:39:281284
[email protected]a95986a82010-12-24 06:19:281285 bool handled = true;
[email protected]e44d1342014-05-16 21:29:331286 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
mcnee432e47d2015-11-09 19:37:461287 IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale)
initial.commit09911bf2008-07-26 23:55:291288 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291289 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1290 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
initial.commit09911bf2008-07-26 23:55:291291 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
[email protected]30f75e62009-02-25 22:01:001292 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]ab32b16c2009-10-16 14:57:251293 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1294 OnEnablePreferredSizeChangedMode)
[email protected]80d96fa2009-06-10 22:34:511295 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]81375e872012-01-11 21:40:361296 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
W. James MacLeand973a55b2018-11-29 21:39:131297 IPC_MESSAGE_HANDLER(ViewMsg_AnimateDoubleTapZoom,
1298 OnAnimateDoubleTapZoomInMainFrame)
W. James MacLean5372eb72018-12-19 12:56:361299 IPC_MESSAGE_HANDLER(ViewMsg_ZoomToFindInPageRect, OnZoomToFindInPageRect)
danakjd51fd53d2018-12-21 23:06:091300 IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque, OnSetBackgroundOpaque)
wjmaclean64951902016-04-29 20:59:121301
1302 // Page messages.
lfg717154072016-06-30 15:04:161303 IPC_MESSAGE_HANDLER(PageMsg_WasHidden, OnPageWasHidden)
1304 IPC_MESSAGE_HANDLER(PageMsg_WasShown, OnPageWasShown)
alexmos136fd6e62016-08-15 20:58:411305 IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength,
1306 OnSetHistoryOffsetAndLength)
altimind8bd26c2016-11-04 11:44:541307 IPC_MESSAGE_HANDLER(PageMsg_AudioStateChanged, OnAudioStateChanged)
lfg8d649cc2017-04-28 18:04:301308 IPC_MESSAGE_HANDLER(PageMsg_UpdateScreenInfo, OnUpdateScreenInfo)
Francois Doray47f759d2018-06-11 18:13:511309 IPC_MESSAGE_HANDLER(PageMsg_SetPageFrozen, SetPageFrozen)
lfg717154072016-06-30 15:04:161310
[email protected]a794f3a2013-10-30 17:00:321311 // Adding a new message? Add platform independent ones first, then put the
1312 // platform specific ones at the end.
[email protected]9e1ad4b2011-08-14 16:49:191313
Albert J. Wong7bbf22d2018-12-20 00:27:271314 // Have the widget handle all other messages.
1315 // TODO(ajwong): Remove this cross-object dispatch.
1316 IPC_MESSAGE_UNHANDLED(handled = GetWidget()->OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291317 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401318
[email protected]a95986a82010-12-24 06:19:281319 return handled;
initial.commit09911bf2008-07-26 23:55:291320}
1321
[email protected]180ef242013-11-07 06:50:461322// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521323
Mustaq Ahmed55944cb2018-05-25 20:44:271324// TODO(csharrison): Migrate this method to WebLocalFrameClient /
1325// RenderFrameImpl, as it is now serviced by a mojo interface scoped to the
1326// opener frame.
Daniel Murphyc8e991a2018-10-12 22:09:031327WebView* RenderViewImpl::CreateView(
1328 WebLocalFrame* creator,
1329 const WebURLRequest& request,
1330 const WebWindowFeatures& features,
1331 const WebString& frame_name,
1332 WebNavigationPolicy policy,
1333 bool suppress_opener,
1334 WebSandboxFlags sandbox_flags,
Ehsan Karamad39407082019-02-19 23:38:191335 const blink::FeaturePolicy::FeatureState& opener_feature_state,
Daniel Murphyc8e991a2018-10-12 22:09:031336 const blink::SessionStorageNamespaceId& session_storage_namespace_id) {
nick5ae4d2d2017-01-06 01:18:351337 RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator);
rockot5c478a72016-09-28 23:14:181338 mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New();
Mustaq Ahmedc4cb7162018-06-05 16:28:361339
1340 // User Activation v2 moves user gesture checks to the browser process, with
1341 // the exception of the extensions case handled through the following |if|.
1342 params->mimic_user_gesture =
1343 base::FeatureList::IsEnabled(features::kUserActivationV2)
1344 ? false
1345 : WebUserGestureIndicator::IsProcessingUserGesture(creator);
Sergey Kuznetsov32257a22019-02-11 20:26:501346 // TODO(mustaq): Investigate if mimic_user_gesture can wrongly expose presence
1347 // of user activation w/o any user interaction, e.g. through
1348 // |WebChromeClient#onCreateWindow|. One case to deep-dive: disabling popup
1349 // blocker then calling window.open at onload event. crbug.com/929729
[email protected]00323f02013-07-24 15:47:411350 if (GetContentClient()->renderer()->AllowPopup())
Mustaq Ahmedc4cb7162018-06-05 16:28:361351 params->mimic_user_gesture = true;
1352
rockot5c478a72016-09-28 23:14:181353 params->window_container_type = WindowFeaturesToContainerType(features);
Daniel Murphye3eec92c2018-02-23 19:09:151354
Daniel Murphyc8e991a2018-10-12 22:09:031355 params->session_storage_namespace_id = session_storage_namespace_id;
1356 // TODO(dmurph): Don't copy session storage when features.noopener is true:
1357 // https://html.spec.whatwg.org/multipage/browsers.html#copy-session-storage
1358 // https://crbug.com/771959
Daniel Murphye3eec92c2018-02-23 19:09:151359 params->clone_from_session_storage_namespace_id =
1360 session_storage_namespace_id_;
Daniel Murphye3eec92c2018-02-23 19:09:151361
Daniel Chengd5e56ff2017-06-24 07:44:021362 const std::string& frame_name_utf8 = frame_name.Utf8(
1363 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
1364 params->frame_name = frame_name_utf8;
rockot5c478a72016-09-28 23:14:181365 params->opener_suppressed = suppress_opener;
1366 params->disposition = NavigationPolicyToDisposition(policy);
Blink Reformat1c4d759e2017-04-09 16:34:541367 if (!request.IsNull()) {
1368 params->target_url = request.Url();
Leon Han963dc182018-11-06 05:41:481369 params->referrer =
1370 blink::mojom::Referrer::From(GetReferrerFromRequest(creator, request));
[email protected]44e55b012013-07-23 14:21:561371 }
scottmg8e6c6082017-02-13 23:15:481372 params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
[email protected]8ab04652010-06-12 02:47:261373
rockot5c478a72016-09-28 23:14:181374 // We preserve this information before sending the message since |params| is
1375 // moved on send.
1376 bool is_background_tab =
1377 params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB;
Mustaq Ahmedc4cb7162018-06-05 16:28:361378 bool opened_by_user_gesture = params->mimic_user_gesture;
[email protected]22217ed32013-11-18 18:40:231379
Daniel Cheng8bb30c62017-10-23 20:40:471380 mojom::CreateNewWindowStatus status;
rockot5c478a72016-09-28 23:14:181381 mojom::CreateNewWindowReplyPtr reply;
Balazs Engedya40712f2017-09-15 15:01:111382 auto* frame_host = creator_frame->GetFrameHost();
Daniel Cheng8bb30c62017-10-23 20:40:471383 bool err = !frame_host->CreateNewWindow(std::move(params), &status, &reply);
1384 if (err || status == mojom::CreateNewWindowStatus::kIgnore)
rockot5c478a72016-09-28 23:14:181385 return nullptr;
[email protected]48c9cf2d2009-09-16 16:47:521386
Jochen Eisinger515337a2017-05-26 14:12:521387 // For Android WebView, we support a pop-up like behavior for window.open()
1388 // even if the embedding app doesn't support multiple windows. In this case,
1389 // window.open() will return "window" and navigate it to whatever URL was
Jochen Eisinger8cb28492017-10-04 10:58:131390 // passed. We also don't need to consume user gestures to protect against
1391 // multiple windows being opened, because, well, the app doesn't support
1392 // multiple windows.
Daniel Cheng8bb30c62017-10-23 20:40:471393 // TODO(dcheng): It's awkward that this is plumbed into Blink but not really
Kent Tamura21d1de62018-12-10 04:45:201394 // used much in Blink, except to enable web testing... perhaps this should
Daniel Cheng8bb30c62017-10-23 20:40:471395 // be checked directly in the browser side.
1396 if (status == mojom::CreateNewWindowStatus::kReuse)
Jochen Eisinger515337a2017-05-26 14:12:521397 return webview();
1398
Daniel Cheng8bb30c62017-10-23 20:40:471399 DCHECK(reply);
1400 DCHECK_NE(MSG_ROUTING_NONE, reply->route_id);
1401 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_route_id);
1402 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_widget_route_id);
1403
Mustaq Ahmed76c2f4312018-06-07 20:48:011404 // The browser allowed creation of a new window and consumed the user
1405 // activation (UAv2 only).
Sergey Kuznetsov32257a22019-02-11 20:26:501406 bool was_consumed = WebUserGestureIndicator::ConsumeUserGesture(
Mustaq Ahmed76c2f4312018-06-07 20:48:011407 creator, blink::UserActivationUpdateSource::kBrowser);
Sergey Kuznetsov32257a22019-02-11 20:26:501408 if (base::FeatureList::IsEnabled(features::kUserActivationV2))
1409 opened_by_user_gesture = was_consumed;
Jochen Eisinger8cb28492017-10-04 10:58:131410
[email protected]7912e822014-04-16 02:37:031411 // While this view may be a background extension page, it can spawn a visible
1412 // render view. So we just assume that the new one is not another background
1413 // page instead of passing on our own value.
1414 // TODO(vangelis): Can we tell if the new view will be a background page?
1415 bool never_visible = false;
[email protected]9115d5f2013-03-24 04:37:411416
Fady Samuelff5b6eb562018-05-01 16:16:081417 VisualProperties visual_properties = VisualProperties();
danakj53802692018-07-25 21:46:441418 visual_properties.screen_info = GetWidget()->screen_info();
mkosiba58fa72f02014-11-12 01:21:361419
[email protected]d6fa88f2013-10-18 16:00:431420 // The initial hidden state for the RenderViewImpl here has to match what the
1421 // browser will eventually decide for the given disposition. Since we have to
1422 // return from this call synchronously, we just have to make our best guess
1423 // and rely on the browser sending a WasHidden / WasShown message if it
1424 // disagrees.
Balazs Engedyba034e72017-10-27 22:26:281425 mojom::CreateViewParamsPtr view_params = mojom::CreateViewParams::New();
alexmos5ac402d2015-07-09 07:51:101426
Balazs Engedyba034e72017-10-27 22:26:281427 view_params->opener_frame_route_id = creator_frame->GetRoutingID();
avia3dca182016-03-19 01:09:521428 DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID());
alexmos5ac402d2015-07-09 07:51:101429
Balazs Engedyba034e72017-10-27 22:26:281430 view_params->window_was_created_with_opener = true;
Leon Han2c81b5d2019-01-25 01:58:331431 view_params->renderer_preferences = renderer_preferences_.Clone();
Balazs Engedyba034e72017-10-27 22:26:281432 view_params->web_preferences = webkit_preferences_;
1433 view_params->view_id = reply->route_id;
1434 view_params->main_frame_routing_id = reply->main_frame_route_id;
Oksana Zhuravlova8b88e572019-01-07 21:54:001435 view_params->main_frame_interface_bundle =
1436 mojom::DocumentScopedInterfaceBundle::New(
1437 std::move(reply->main_frame_interface_bundle->interface_provider),
1438 std::move(reply->main_frame_interface_bundle
1439 ->document_interface_broker_content),
1440 std::move(reply->main_frame_interface_bundle
1441 ->document_interface_broker_blink));
Balazs Engedyba034e72017-10-27 22:26:281442 view_params->main_frame_widget_routing_id = reply->main_frame_widget_route_id;
1443 view_params->session_storage_namespace_id =
rockot5c478a72016-09-28 23:14:181444 reply->cloned_session_storage_namespace_id;
Daniel Murphy95792ef2018-10-04 01:29:551445 DCHECK(!view_params->session_storage_namespace_id.empty())
1446 << "Session storage namespace must be populated.";
Balazs Engedyba034e72017-10-27 22:26:281447 view_params->replicated_frame_state.frame_policy.sandbox_flags =
1448 sandbox_flags;
Ehsan Karamad39407082019-02-19 23:38:191449 view_params->replicated_frame_state.opener_feature_state =
1450 opener_feature_state;
Balazs Engedyba034e72017-10-27 22:26:281451 view_params->replicated_frame_state.name = frame_name_utf8;
1452 view_params->devtools_main_frame_token = reply->devtools_main_frame_token;
Daniel Chengd5e56ff2017-06-24 07:44:021453 // Even if the main frame has a name, the main frame's unique name is always
1454 // the empty string.
Balazs Engedyba034e72017-10-27 22:26:281455 view_params->hidden = is_background_tab;
1456 view_params->never_visible = never_visible;
Fady Samuelff5b6eb562018-05-01 16:16:081457 view_params->visual_properties = visual_properties;
naskobd911332014-11-25 01:13:361458
nick5ae4d2d2017-01-06 01:18:351459 // Unretained() is safe here because our calling function will also call
1460 // show().
nickf7b38222016-11-22 21:59:351461 RenderWidget::ShowCallback show_callback =
danakjdf1ceb72018-07-18 20:02:251462 base::BindOnce(&RenderFrameImpl::ShowCreatedWindow,
1463 base::Unretained(creator_frame), opened_by_user_gesture);
nickf7b38222016-11-22 21:59:351464
Balazs Engedyba034e72017-10-27 22:26:281465 RenderViewImpl* view = RenderViewImpl::Create(
danakj53802692018-07-25 21:46:441466 GetWidget()->compositor_deps(), std::move(view_params),
1467 std::move(show_callback),
Hajime Hoshi6fc91142018-05-11 08:21:171468 creator->GetTaskRunner(blink::TaskType::kInternalDefault));
[email protected]48c9cf2d2009-09-16 16:47:521469
[email protected]48c9cf2d2009-09-16 16:47:521470 return view->webview();
1471}
1472
danakj19f3e512018-12-14 21:02:051473blink::WebPagePopup* RenderViewImpl::CreatePopup(
1474 blink::WebLocalFrame* creator) {
danakj25ec6e2b2018-09-26 17:01:311475 mojom::WidgetPtr widget_channel;
1476 mojom::WidgetRequest widget_channel_request =
1477 mojo::MakeRequest(&widget_channel);
1478
1479 // Do a synchronous IPC to obtain a routing ID.
1480 int32_t widget_routing_id = MSG_ROUTING_NONE;
1481 bool success =
1482 RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
1483 GetRoutingID(), std::move(widget_channel), &widget_routing_id);
1484 if (!success) {
1485 // When the renderer is being killed the mojo message will fail.
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281486 return nullptr;
danakj25ec6e2b2018-09-26 17:01:311487 }
1488
1489 RenderWidget::ShowCallback opener_callback = base::BindOnce(
1490 &RenderViewImpl::ShowCreatedPopupWidget, weak_ptr_factory_.GetWeakPtr());
1491
1492 // The RenderWidget associated with the RenderView. This should be the
1493 // RenderWidget for the main frame, but may be a zombie RenderWidget when
1494 // the main frame is remote (we don't need a RenderWidget for it then).
1495 // However for now (https://crbug.com/419087) we know it exists and grab
1496 // state off it for the popup.
1497 // TODO(crbug.com/419087): This should probably be using the local root's
1498 // RenderWidget for the frame making the popup.
1499 RenderWidget* view_render_widget = GetWidget();
1500
Albert J. Wong2727e8a82019-02-15 16:56:111501 auto popup_widget = RenderWidget::CreateForPopup(
danakj25ec6e2b2018-09-26 17:01:311502 widget_routing_id, view_render_widget->compositor_deps(),
danakj89ae4532018-12-12 22:52:551503 view_render_widget->screen_info(), blink::kWebDisplayModeUndefined,
danakj6dcbc5962018-11-16 16:45:421504 /*is_frozen=*/false,
danakj25ec6e2b2018-09-26 17:01:311505 /*hidden=*/false,
1506 /*never_visible=*/false, std::move(widget_channel_request));
1507
1508 // The returned WebPagePopup is self-referencing, so the pointer here is not
danakj45e4a4f2019-03-12 22:50:421509 // an owning pointer. It is de-referenced by calling Close().
danakj25ec6e2b2018-09-26 17:01:311510 blink::WebPagePopup* popup_web_widget =
1511 blink::WebPagePopup::Create(popup_widget.get());
1512
1513 // Adds a self-reference on the |popup_widget| so it will not be destroyed
1514 // when leaving scope. The WebPagePopup takes responsibility for Close()ing
1515 // and thus destroying the RenderWidget.
1516 popup_widget->InitForPopup(std::move(opener_callback), popup_web_widget);
1517 // TODO(crbug.com/419087): RenderWidget has some weird logic for picking a
1518 // WebWidget which doesn't apply to this case. So we verify. This can go away
1519 // when RenderWidget::GetWebWidget() is just a simple accessor.
1520 DCHECK_EQ(popup_widget->GetWebWidget(), popup_web_widget);
1521
1522 // Devtools emulation, which may be currently applied to the
1523 // |view_render_widget|, should also apply to the new popup. This doesn't
1524 // happen automatically.
1525 popup_widget->ApplyEmulatedScreenMetricsForPopupWidget(view_render_widget);
1526
1527 return popup_web_widget;
[email protected]48c9cf2d2009-09-16 16:47:521528}
1529
danakj295c43f182019-03-13 16:37:171530void RenderViewImpl::DoDeferredClose() {
1531 // The main widget is currently not active. The active main frame widget is
1532 // in a different process. Have the browser route the close request to the
1533 // active widget instead, so that the correct unload handlers are run.
1534 Send(new ViewHostMsg_RouteCloseEvent(GetRoutingID()));
1535}
1536
danakj45e4a4f2019-03-12 22:50:421537void RenderViewImpl::CloseWindowSoon() {
Avi Drissman07d22452019-03-25 17:56:391538 DCHECK(RenderThread::IsMainThread());
danakj45e4a4f2019-03-12 22:50:421539 if (render_widget_->is_frozen()) {
danakj295c43f182019-03-13 16:37:171540 // Ask the RenderViewHost with a local main frame to initiate close. We
1541 // could be called from deep in Javascript. If we ask the RenderViewHost to
1542 // close now, the window could be closed before the JS finishes executing,
1543 // thanks to nested message loops running and handling the resuliting Close
1544 // IPC. So instead, post a message back to the message loop, which won't run
1545 // until the JS is complete, and then the Close request can be sent.
1546 GetCleanupTaskRunner()->PostTask(
1547 FROM_HERE, base::BindOnce(&RenderViewImpl::DoDeferredClose,
1548 weak_ptr_factory_.GetWeakPtr()));
danakj45e4a4f2019-03-12 22:50:421549 return;
1550 }
1551
1552 // If the main widget is not frozen then the Close request goes directly
1553 // through it, because the RenderWidget ultimately owns the RenderViewImpl.
1554 render_widget_->CloseWidgetSoon();
1555}
1556
Daniel Murphy31bbb8b12018-02-07 21:44:101557base::StringPiece RenderViewImpl::GetSessionStorageNamespaceId() {
1558 CHECK(!session_storage_namespace_id_.empty());
Daniel Murphy0ce6e2c2017-11-21 01:54:261559 return session_storage_namespace_id_;
[email protected]bd92c3a2010-01-13 05:02:341560}
1561
Blink Reformat1c4d759e2017-04-09 16:34:541562void RenderViewImpl::PrintPage(WebLocalFrame* frame) {
naskoe440d8c2016-10-12 23:07:561563 UMA_HISTOGRAM_BOOLEAN("PrintPreview.InitiatedByScript",
Blink Reformat1c4d759e2017-04-09 16:34:541564 frame->Top() == frame);
naskoe440d8c2016-10-12 23:07:561565
1566 // Logging whether the top frame is remote is sufficient in this case. If
1567 // the top frame is local, the printing code will function correctly and
1568 // the frame itself will be printed, so the cases this histogram tracks is
1569 // where printing of a subframe will fail as of now.
1570 UMA_HISTOGRAM_BOOLEAN("PrintPreview.OutOfProcessSubframe",
Blink Reformat1c4d759e2017-04-09 16:34:541571 frame->Top()->IsWebRemoteFrame());
naskoe440d8c2016-10-12 23:07:561572
thestigcb959ce2016-11-17 05:56:321573 RenderFrameImpl::FromWebFrame(frame)->ScriptedPrint(
danakj53802692018-07-25 21:46:441574 GetWidget()->input_handler().handling_input_event());
[email protected]48c9cf2d2009-09-16 16:47:521575}
1576
lfgcaab5142016-02-26 19:06:521577void RenderViewImpl::AttachWebFrameWidget(blink::WebFrameWidget* frame_widget) {
dcheng3ce04b62015-10-26 23:30:551578 // The previous WebFrameWidget must already be detached by CloseForFrame().
1579 DCHECK(!frame_widget_);
1580 frame_widget_ = frame_widget;
danakjefcb8432019-01-16 18:47:141581
1582 // Initialization for the WebFrameWidget that should only occur for the main
1583 // frame, and that uses types not allowed in blink. This should maybe be
1584 // passed to the creation of the WebFrameWidget or the main RenderFrame.
1585 const base::CommandLine& command_line =
1586 *base::CommandLine::ForCurrentProcess();
danakj175a17a2019-03-15 23:10:381587 render_widget_->SetShowFPSCounter(
danakjefcb8432019-01-16 18:47:141588 command_line.HasSwitch(cc::switches::kShowFPSCounter));
dcheng3ce04b62015-10-26 23:30:551589}
1590
danakj8f4465b2018-11-07 20:11:281591void RenderViewImpl::DetachWebFrameWidget() {
danakjb08b3712019-01-16 18:59:561592 DCHECK(GetWidget()->is_frozen() || GetWidget()->is_closing());
danakj8f4465b2018-11-07 20:11:281593 DCHECK(frame_widget_);
danakj8f4465b2018-11-07 20:11:281594 frame_widget_->Close();
1595 frame_widget_ = nullptr;
1596}
1597
tommycli8aad3ba2015-08-12 17:57:591598void RenderViewImpl::SetZoomLevel(double zoom_level) {
wjmaclean64951902016-04-29 20:59:121599 // If we change the zoom level for the view, make sure any subsequent subframe
1600 // loads reflect the current zoom level.
1601 page_zoom_level_ = zoom_level;
1602
Blink Reformat1c4d759e2017-04-09 16:34:541603 webview()->SetZoomLevel(zoom_level);
ericwilligers88e69742016-10-17 19:29:551604 for (auto& observer : observers_)
1605 observer.OnZoomLevelChanged();
tommycli8aad3ba2015-08-12 17:57:591606}
1607
habib.virji597255e2014-09-09 00:30:181608void RenderViewImpl::SetValidationMessageDirection(
1609 base::string16* wrapped_main_text,
1610 blink::WebTextDirection main_text_hint,
1611 base::string16* wrapped_sub_text,
1612 blink::WebTextDirection sub_text_hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541613 if (main_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181614 *wrapped_main_text =
1615 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
Blink Reformat1c4d759e2017-04-09 16:34:541616 } else if (main_text_hint == blink::kWebTextDirectionRightToLeft &&
habib.virji597255e2014-09-09 00:30:181617 !base::i18n::IsRTL()) {
1618 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
1619 }
1620
1621 if (!wrapped_sub_text->empty()) {
Blink Reformat1c4d759e2017-04-09 16:34:541622 if (sub_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181623 *wrapped_sub_text =
1624 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
Blink Reformat1c4d759e2017-04-09 16:34:541625 } else if (sub_text_hint == blink::kWebTextDirectionRightToLeft) {
habib.virji597255e2014-09-09 00:30:181626 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
1627 }
1628 }
1629}
1630
[email protected]310ebd6302011-10-10 19:06:281631void RenderViewImpl::UpdateTargetURL(const GURL& url,
1632 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581633 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521634 if (latest_url == target_url_)
1635 return;
[email protected]163f8242009-10-30 20:19:551636
[email protected]48c9cf2d2009-09-16 16:47:521637 // Tell the browser to display a destination link.
1638 if (target_url_status_ == TARGET_INFLIGHT ||
1639 target_url_status_ == TARGET_PENDING) {
1640 // If we have a request in-flight, save the URL to be sent when we
1641 // receive an ACK to the in-flight request. We can happily overwrite
1642 // any existing pending sends.
1643 pending_target_url_ = latest_url;
1644 target_url_status_ = TARGET_PENDING;
1645 } else {
mnaganovbf087422015-12-16 05:10:031646 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411647 // see |ParamTraits<GURL>|.
markdittmer67b71ea2016-03-03 22:40:031648 if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:411649 latest_url = GURL();
avia3dca182016-03-19 01:09:521650 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), latest_url));
[email protected]48c9cf2d2009-09-16 16:47:521651 target_url_ = latest_url;
1652 target_url_status_ = TARGET_INFLIGHT;
1653 }
1654}
1655
creis69b184a472015-11-26 05:29:511656void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) {
creisce0ef3572017-01-26 17:53:081657 // Keep track of which frames have pending updates.
1658 frames_with_pending_state_.insert(frame->GetRoutingID());
creis8eb8ef22015-11-04 22:51:381659
[email protected]882daa92009-11-05 16:31:311660 int delay;
avif937e1d2014-11-02 18:13:071661 if (send_content_state_immediately_)
[email protected]882daa92009-11-05 16:31:311662 delay = 0;
danakj78744912018-11-30 23:46:421663 else if (GetWebView()->IsHidden())
avif937e1d2014-11-02 18:13:071664 delay = kDelaySecondsForContentStateSyncHidden;
[email protected]882daa92009-11-05 16:31:311665 else
avif937e1d2014-11-02 18:13:071666 delay = kDelaySecondsForContentStateSync;
[email protected]882daa92009-11-05 16:31:311667
avif937e1d2014-11-02 18:13:071668 if (nav_state_sync_timer_.IsRunning()) {
[email protected]882daa92009-11-05 16:31:311669 // The timer is already running. If the delay of the timer maches the amount
1670 // we want to delay by, then return. Otherwise stop the timer so that it
1671 // gets started with the right delay.
avif937e1d2014-11-02 18:13:071672 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
[email protected]882daa92009-11-05 16:31:311673 return;
avif937e1d2014-11-02 18:13:071674 nav_state_sync_timer_.Stop();
[email protected]882daa92009-11-05 16:31:311675 }
1676
creisce0ef3572017-01-26 17:53:081677 // Tell each frame with pending state to inform the browser.
danakj19f3e512018-12-14 21:02:051678 nav_state_sync_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay),
1679 this, &RenderViewImpl::SendFrameStateUpdates);
[email protected]882daa92009-11-05 16:31:311680}
1681
Blink Reformat1c4d759e2017-04-09 16:34:541682void RenderViewImpl::SetMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551683 mouse_over_url_ = GURL(url);
1684 UpdateTargetURL(mouse_over_url_, focus_url_);
1685}
1686
Blink Reformat1c4d759e2017-04-09 16:34:541687void RenderViewImpl::SetKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551688 focus_url_ = GURL(url);
1689 UpdateTargetURL(focus_url_, mouse_over_url_);
1690}
1691
Blink Reformat1c4d759e2017-04-09 16:34:541692bool RenderViewImpl::AcceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451693 return renderer_preferences_.can_accept_load_drops;
1694}
1695
Blink Reformat1c4d759e2017-04-09 16:34:541696void RenderViewImpl::FocusNext() {
avia3dca182016-03-19 01:09:521697 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false));
[email protected]48c9cf2d2009-09-16 16:47:521698}
1699
Blink Reformat1c4d759e2017-04-09 16:34:541700void RenderViewImpl::FocusPrevious() {
avia3dca182016-03-19 01:09:521701 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true));
[email protected]48c9cf2d2009-09-16 16:47:521702}
1703
esprehn3d4471a2015-09-17 07:13:201704// TODO(esprehn): Blink only ever passes Elements, this should take WebElement.
Blink Reformat1c4d759e2017-04-09 16:34:541705void RenderViewImpl::FocusedNodeChanged(const WebNode& fromNode,
estade31c54342015-01-23 03:34:361706 const WebNode& toNode) {
estade31c54342015-01-23 03:34:361707 RenderFrameImpl* previous_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541708 if (!fromNode.IsNull())
1709 previous_frame =
1710 RenderFrameImpl::FromWebFrame(fromNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361711 RenderFrameImpl* new_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541712 if (!toNode.IsNull())
1713 new_frame = RenderFrameImpl::FromWebFrame(toNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361714
1715 if (previous_frame && previous_frame != new_frame)
1716 previous_frame->FocusedNodeChanged(WebNode());
1717 if (new_frame)
1718 new_frame->FocusedNodeChanged(toNode);
1719
1720 // TODO(dmazzoni): remove once there's a separate a11y tree per frame.
naskoe8d115752015-08-07 00:43:131721 if (main_render_frame_)
1722 main_render_frame_->FocusedNodeChangedForAccessibility(toNode);
[email protected]08e9e132010-06-01 16:58:491723}
1724
Philip Rogers079658812018-08-01 23:19:091725void RenderViewImpl::DidUpdateMainFrameLayout() {
ericwilligers88e69742016-10-17 19:29:551726 for (auto& observer : observers_)
Philip Rogers079658812018-08-01 23:19:091727 observer.DidUpdateMainFrameLayout();
[email protected]d01b2a62013-09-18 23:21:331728
Philip Rogers33cd2bcc2018-08-13 21:29:291729 // The main frame may have changed size.
1730 needs_preferred_size_update_ = true;
[email protected]169d4282011-11-30 19:33:591731}
1732
Arthur Sonzognia7d715a2018-09-20 16:11:131733void RenderViewImpl::NavigateBackForwardSoon(int offset,
1734 bool has_user_gesture) {
Alex Clarkebf3dceb2017-11-24 12:27:431735 history_navigation_virtual_time_pauser_ =
1736 RenderThreadImpl::current()
Yuta Kitamura3331f5c2018-04-05 11:12:251737 ->GetWebMainThreadScheduler()
Alex Clarkeb28db542018-02-07 12:53:131738 ->CreateWebScopedVirtualTimePauser(
Alex Clarkeaaf006b2018-04-05 18:35:241739 "NavigateBackForwardSoon",
Alex Clarkeb28db542018-02-07 12:53:131740 blink::WebScopedVirtualTimePauser::VirtualTaskDuration::kInstant);
Alex Clarkeaaf006b2018-04-05 18:35:241741 history_navigation_virtual_time_pauser_.PauseVirtualTime();
[email protected]48c9cf2d2009-09-16 16:47:521742}
1743
Alex Clarkebf3dceb2017-11-24 12:27:431744void RenderViewImpl::DidCommitProvisionalHistoryLoad() {
Alex Clarkeaaf006b2018-04-05 18:35:241745 history_navigation_virtual_time_pauser_.UnpauseVirtualTime();
Alex Clarkebf3dceb2017-11-24 12:27:431746}
1747
Makoto Shimazuc3c730e2018-08-15 09:51:111748void RenderViewImpl::RegisterRendererPreferenceWatcherForWorker(
Leon Hanf4003a162019-01-28 05:31:581749 blink::mojom::RendererPreferenceWatcherPtr watcher) {
Makoto Shimazuc3c730e2018-08-15 09:51:111750 renderer_preference_watchers_.AddPtr(std::move(watcher));
1751}
1752
Blink Reformat1c4d759e2017-04-09 16:34:541753int RenderViewImpl::HistoryBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001754 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521755}
1756
Blink Reformat1c4d759e2017-04-09 16:34:541757int RenderViewImpl::HistoryForwardListCount() {
1758 return history_list_length_ - HistoryBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521759}
1760
[email protected]180ef242013-11-07 06:50:461761// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:511762
Blink Reformat1c4d759e2017-04-09 16:34:541763bool RenderViewImpl::CanHandleGestureEvent() {
slangley1a6375e62017-03-29 06:03:231764 return true;
1765}
1766
Avi Drissmanfb961262019-03-05 22:50:291767// TODO(https://crbug.com/937569): Remove this in Chrome 82.
1768bool RenderViewImpl::AllowPopupsDuringPageUnload() {
1769 const base::CommandLine& command_line =
1770 *base::CommandLine::ForCurrentProcess();
1771 return command_line.HasSwitch(switches::kAllowPopupsDuringPageUnload);
1772}
1773
Blink Reformat1c4d759e2017-04-09 16:34:541774bool RenderViewImpl::CanUpdateLayout() {
slangley1a6375e62017-03-29 06:03:231775 return true;
1776}
1777
Mustaq Ahmed55944cb2018-05-25 20:44:271778// blink::WebLocalFrameClient
1779// -----------------------------------------------------
[email protected]3d9689372009-09-10 04:29:171780
[email protected]b2324b092012-11-01 10:34:111781void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
1782 const std::string& value) {
alexmos56567492016-09-13 00:52:461783 GetWidget()->SetEditCommandForNextKeyEvent(name, value);
[email protected]b2324b092012-11-01 10:34:111784}
1785
1786void RenderViewImpl::ClearEditCommands() {
alexmos56567492016-09-13 00:52:461787 GetWidget()->ClearEditCommands();
[email protected]b2324b092012-11-01 10:34:111788}
1789
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491790const std::string& RenderViewImpl::GetAcceptLanguages() {
[email protected]b38806a2013-10-04 16:01:381791 return renderer_preferences_.accept_languages;
1792}
1793
Ahmed Fakhry58e6ef542018-09-04 18:05:381794void RenderViewImpl::UpdateBrowserControlsState(
1795 BrowserControlsState constraints,
1796 BrowserControlsState current,
1797 bool animate) {
David Bokan3746d2c2018-10-29 20:21:351798 TRACE_EVENT2("renderer", "RenderViewImpl::UpdateBrowserControlsState",
1799 "Constraint", static_cast<int>(constraints), "Current",
1800 static_cast<int>(current));
1801 TRACE_EVENT_INSTANT1("renderer", "is_animated", TRACE_EVENT_SCOPE_THREAD,
1802 "animated", animate);
1803
David Bokan1e37ebf2018-10-16 13:53:371804 if (GetWidget() && GetWidget()->layer_tree_view()) {
1805 GetWidget()->layer_tree_view()->UpdateBrowserControlsState(
1806 ContentToCc(constraints), ContentToCc(current), animate);
Ahmed Fakhry58e6ef542018-09-04 18:05:381807 }
1808
1809 top_controls_constraints_ = constraints;
1810}
1811
David Bokan1e37ebf2018-10-16 13:53:371812#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
1813
Ahmed Fakhry58e6ef542018-09-04 18:05:381814void RenderViewImpl::didScrollWithKeyboard(const blink::WebSize& delta) {
1815 if (delta.height == 0)
1816 return;
1817
1818 BrowserControlsState current = delta.height < 0
1819 ? BROWSER_CONTROLS_STATE_SHOWN
1820 : BROWSER_CONTROLS_STATE_HIDDEN;
1821
1822 UpdateBrowserControlsState(top_controls_constraints_, current, true);
1823}
1824
1825#endif
1826
danakjdea2efb2016-03-10 19:13:171827void RenderViewImpl::ConvertViewportToWindowViaWidget(blink::WebRect* rect) {
danakj175a17a2019-03-15 23:10:381828 render_widget_->ConvertViewportToWindow(rect);
oshimae2b3b402015-12-04 04:27:241829}
1830
huangs2a342352015-12-15 16:59:241831gfx::RectF RenderViewImpl::ElementBoundsInWindow(
1832 const blink::WebElement& element) {
Blink Reformat1c4d759e2017-04-09 16:34:541833 blink::WebRect bounding_box_in_window = element.BoundsInViewport();
danakj175a17a2019-03-15 23:10:381834 render_widget_->ConvertViewportToWindow(&bounding_box_in_window);
huangs2a342352015-12-15 16:59:241835 return gfx::RectF(bounding_box_in_window);
1836}
1837
Philip Rogers601fd072018-08-07 22:58:221838void RenderViewImpl::UpdatePreferredSize() {
[email protected]d812fd12011-05-27 23:05:071839 // We don't always want to send the change messages over IPC, only if we've
1840 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1841 // message.
1842 if (!send_preferred_size_changes_ || !webview())
1843 return;
Philip Rogers33cd2bcc2018-08-13 21:29:291844
1845 if (!needs_preferred_size_update_)
1846 return;
1847 needs_preferred_size_update_ = false;
1848
oshima1a688b5c2017-06-16 19:00:131849 blink::WebSize tmp_size = webview()->ContentsPreferredMinimumSize();
1850 blink::WebRect tmp_rect(0, 0, tmp_size.width, tmp_size.height);
danakj175a17a2019-03-15 23:10:381851 render_widget_->ConvertViewportToWindow(&tmp_rect);
oshima1a688b5c2017-06-16 19:00:131852 gfx::Size size(tmp_rect.width, tmp_rect.height);
[email protected]705243f2010-05-05 19:58:071853 if (size == preferred_size_)
1854 return;
[email protected]c27324b2009-11-19 22:44:291855
[email protected]705243f2010-05-05 19:58:071856 preferred_size_ = size;
avia3dca182016-03-19 01:09:521857 Send(new ViewHostMsg_DidContentsPreferredSizeChange(GetRoutingID(),
[email protected]705243f2010-05-05 19:58:071858 preferred_size_));
[email protected]3d9689372009-09-10 04:29:171859}
1860
Blink Reformat1c4d759e2017-04-09 16:34:541861blink::WebString RenderViewImpl::AcceptLanguages() {
1862 return WebString::FromUTF8(renderer_preferences_.accept_languages);
[email protected]9982c802013-06-12 15:22:061863}
1864
[email protected]e9ff79c2012-10-19 21:31:261865// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:311866
[email protected]310ebd6302011-10-10 19:06:281867bool RenderViewImpl::Send(IPC::Message* message) {
danakja2c9d0a92018-07-25 20:01:181868 // This method is an override of IPC::Sender, but RenderWidget also has an
1869 // override of IPC::Sender, so this method also overrides RenderWidget. Thus
1870 // we must call to the base class, not via an upcast or virtual dispatch would
1871 // go back here.
Albert J. Wong7bbf22d2018-12-20 00:27:271872 CHECK(message->routing_id() != MSG_ROUTING_NONE);
1873
1874 // TODO(ajwong): Don't delegate to render widget. Filter here.
1875 return GetWidget()->Send(message);
[email protected]a2ef54c2011-10-10 16:20:311876}
1877
Peter Kastinga4a3ed12018-01-31 04:07:591878RenderWidget* RenderViewImpl::GetWidget() {
Albert J. Wong7bbf22d2018-12-20 00:27:271879 return render_widget_;
1880}
1881
1882const RenderWidget* RenderViewImpl::GetWidget() const {
1883 return render_widget_;
avi8a45c1092016-03-01 16:12:341884}
1885
mostynbc33353232014-09-12 09:38:311886RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() {
nasko77de2312015-05-12 03:09:161887 return main_render_frame_;
[email protected]b849847b2013-12-10 21:57:581888}
1889
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491890int RenderViewImpl::GetRoutingID() {
Albert J. Wongcb004632018-07-10 22:58:251891 return routing_id_;
[email protected]a2ef54c2011-10-10 16:20:311892}
1893
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491894gfx::Size RenderViewImpl::GetSize() {
Albert J. Wong7bbf22d2018-12-20 00:27:271895 return GetWidget()->size();
[email protected]a2ef54c2011-10-10 16:20:311896}
1897
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491898float RenderViewImpl::GetDeviceScaleFactor() {
Albert J. Wong7bbf22d2018-12-20 00:27:271899 return GetWidget()->GetWebScreenInfo().device_scale_factor;
oshima129b75e2016-01-14 09:15:141900}
1901
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491902float RenderViewImpl::GetZoomLevel() {
Marc Treib06d66032017-10-19 08:43:201903 return page_zoom_level_;
1904}
1905
thestig8a8fdfd32017-05-06 18:46:541906const WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:311907 return webkit_preferences_;
1908}
1909
[email protected]324825d2012-11-30 12:37:151910void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
1911 OnUpdateWebPreferences(preferences);
1912}
1913
[email protected]180ef242013-11-07 06:50:461914blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:311915 return webview();
1916}
1917
lfgcaab5142016-02-26 19:06:521918blink::WebFrameWidget* RenderViewImpl::GetWebFrameWidget() {
1919 return frame_widget_;
1920}
1921
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491922bool RenderViewImpl::GetContentStateImmediately() {
avif937e1d2014-11-02 18:13:071923 return send_content_state_immediately_;
[email protected]a2ef54c2011-10-10 16:20:311924}
1925
mcnee432e47d2015-11-09 19:37:461926void RenderViewImpl::OnSetPageScale(float page_scale_factor) {
ccameronb7c1d6c2015-03-09 17:08:241927 if (!webview())
1928 return;
Blink Reformat1c4d759e2017-04-09 16:34:541929 webview()->SetPageScaleFactor(page_scale_factor);
ccameronb7c1d6c2015-03-09 17:08:241930}
1931
akaba3483d8f2018-07-10 21:43:091932void RenderViewImpl::UpdateZoomLevel(double zoom_level) {
danakja5c39d52018-12-13 22:20:561933 webview()->CancelPagePopup();
wjmaclean64951902016-04-29 20:59:121934 SetZoomLevel(zoom_level);
[email protected]d42bf472014-06-14 01:49:381935}
1936
danakj78744912018-11-30 23:46:421937void RenderViewImpl::ApplyPageHidden(bool hidden, bool initial_setting) {
1938 webview()->SetIsHidden(hidden, initial_setting);
1939 // Note: RenderWidget visibility is separately set from the IPC handlers, and
1940 // does not change when tests override the visibility of the Page.
danakj1b35e9d2018-11-07 19:09:281941}
1942
[email protected]310ebd6302011-10-10 19:06:281943void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:591944 webkit_preferences_ = prefs;
danakjfd0c7f42018-10-12 18:01:081945 ApplyWebPreferences(webkit_preferences_, webview());
initial.commit09911bf2008-07-26 23:55:291946}
1947
[email protected]2bf834f2011-11-17 20:02:211948void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:241949 if (send_preferred_size_changes_)
1950 return;
[email protected]9fb325e2010-05-06 18:23:241951 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:391952
Philip Rogers601fd072018-08-07 22:58:221953 if (!webview())
1954 return;
1955
Philip Rogers33cd2bcc2018-08-13 21:29:291956 needs_preferred_size_update_ = true;
1957
Philip Rogers601fd072018-08-07 22:58:221958 // We need to ensure |UpdatePreferredSize| gets called. If a layout is needed,
1959 // force an update here which will call |DidUpdateMainFrameLayout|.
danakj763c2402018-11-09 02:46:221960 webview()->MainFrameWidget()->UpdateLifecycle(
Stephen Chenneyec4312612018-11-21 12:40:161961 WebWidget::LifecycleUpdate::kLayout,
1962 WebWidget::LifecycleUpdateReason::kOther);
Philip Rogers601fd072018-08-07 22:58:221963
1964 // If a layout was not needed, |DidUpdateMainFrameLayout| will not be called.
1965 // We explicitly update the preferred size here to ensure the preferred size
1966 // notification is sent.
1967 UpdatePreferredSize();
[email protected]0666aef2009-05-13 19:48:081968}
1969
[email protected]310ebd6302011-10-10 19:06:281970void RenderViewImpl::OnSetRendererPrefs(
Leon Hanc819dc62019-01-28 04:30:191971 const blink::mojom::RendererPreferences& renderer_prefs) {
[email protected]ebd5ea52014-05-28 14:51:151972 std::string old_accept_languages = renderer_preferences_.accept_languages;
1973
[email protected]80d96fa2009-06-10 22:34:511974 renderer_preferences_ = renderer_prefs;
ananta59b9fe72015-04-07 01:33:261975
Makoto Shimazuc3c730e2018-08-15 09:51:111976 renderer_preference_watchers_.ForAllPtrs(
Leon Hanf4003a162019-01-28 05:31:581977 [&renderer_prefs](blink::mojom::RendererPreferenceWatcher* watcher) {
Leon Han2c81b5d2019-01-25 01:58:331978 watcher->NotifyUpdate(renderer_prefs.Clone());
Makoto Shimazuc3c730e2018-08-15 09:51:111979 });
1980
[email protected]6e282c92009-07-24 01:19:371981 UpdateFontRenderingFromRendererPrefs();
scottmgb92365e2016-08-30 20:54:401982 UpdateThemePrefs();
Leon Han2c81b5d2019-01-25 01:58:331983 blink::SetCaretBlinkInterval(
1984 renderer_prefs.caret_blink_interval.has_value()
1985 ? renderer_prefs.caret_blink_interval.value()
1986 : base::TimeDelta::FromMilliseconds(
Leon Hanc819dc62019-01-28 04:30:191987 blink::mojom::kDefaultCaretBlinkIntervalInMilliseconds));
[email protected]38a85712013-01-02 22:45:021988
brettw8a274fa2016-11-15 00:20:401989#if BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]1596efb2013-01-17 22:13:011990 if (renderer_prefs.use_custom_colors) {
Blink Reformat1c4d759e2017-04-09 16:34:541991 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
[email protected]1596efb2013-01-17 22:13:011992
1993 if (webview()) {
Blink Reformat1c4d759e2017-04-09 16:34:541994 webview()->SetSelectionColors(renderer_prefs.active_selection_bg_color,
1995 renderer_prefs.active_selection_fg_color,
1996 renderer_prefs.inactive_selection_bg_color,
1997 renderer_prefs.inactive_selection_fg_color);
danakj763c2402018-11-09 02:46:221998 webview()->MainFrameWidget()->ThemeChanged();
[email protected]1596efb2013-01-17 22:13:011999 }
[email protected]644d77e2010-01-27 01:03:102000 }
brettw8a274fa2016-11-15 00:20:402001#endif // BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]d299d972012-03-23 02:26:552002
Ian Vollick0c34a072019-02-15 03:40:272003#if defined(OS_ANDROID)
2004 if (renderer_prefs.use_custom_colors)
2005 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
2006
2007 blink::SetMinimumStrokeWidthForFocusRing(
2008 renderer_prefs.minimum_stroke_width_for_focus_ring);
2009
2010 blink::SetIsFocusRingOutset(renderer_prefs.is_focus_ring_outset);
2011#endif
2012
[email protected]ebd5ea52014-05-28 14:51:152013 if (webview() &&
2014 old_accept_languages != renderer_preferences_.accept_languages) {
Blink Reformat1c4d759e2017-04-09 16:34:542015 webview()->AcceptLanguagesChanged();
[email protected]ebd5ea52014-05-28 14:51:152016 }
[email protected]80d96fa2009-06-10 22:34:512017}
2018
[email protected]81375e872012-01-11 21:40:362019void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
2020 const WebPluginAction& action) {
2021 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542022 webview()->PerformPluginAction(action, location);
[email protected]81375e872012-01-11 21:40:362023}
2024
[email protected]310ebd6302011-10-10 19:06:282025void RenderViewImpl::OnClosePage() {
lukasza5d0dee42017-06-14 21:57:372026 // ViewMsg_ClosePage should only be sent to active, non-swapped-out views.
2027 DCHECK(webview()->MainFrame()->IsWebLocalFrame());
2028
initial.commit09911bf2008-07-26 23:55:292029 // TODO(creis): We'd rather use webview()->Close() here, but that currently
2030 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
2031 // in the onunload handler from appearing. For now, we're bypassing that and
2032 // calling the FrameLoader's CloseURL method directly. This should be
2033 // revisited to avoid having two ways to close a page. Having a single way
2034 // to close that can run onunload is also useful for fixing
2035 // http://b/issue?id=753080.
lukasza5d0dee42017-06-14 21:57:372036 webview()->MainFrame()->ToWebLocalFrame()->DispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:292037
avia3dca182016-03-19 01:09:522038 Send(new ViewHostMsg_ClosePage_ACK(GetRoutingID()));
initial.commit09911bf2008-07-26 23:55:292039}
2040
[email protected]310ebd6302011-10-10 19:06:282041void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:002042 if (webview())
danakja5c39d52018-12-13 22:20:562043 webview()->CancelPagePopup();
[email protected]30f75e62009-02-25 22:01:002044}
2045
lfg717154072016-06-30 15:04:162046void RenderViewImpl::OnPageWasHidden() {
braveyao1d8ee7b2017-03-29 21:10:042047#if defined(OS_ANDROID)
2048 SuspendVideoCaptureDevices(true);
braveyao1d8ee7b2017-03-29 21:10:042049#endif
[email protected]2d7b82c2012-06-01 05:57:502050
danakj78744912018-11-30 23:46:422051 ApplyPageHidden(/*hidden=*/true, /*initial_setting=*/false);
[email protected]941e4552010-02-01 21:23:432052}
2053
lfg717154072016-06-30 15:04:162054void RenderViewImpl::OnPageWasShown() {
braveyao1d8ee7b2017-03-29 21:10:042055#if defined(OS_ANDROID)
2056 SuspendVideoCaptureDevices(false);
[email protected]6392d982013-04-16 16:59:222057#endif
2058
danakj78744912018-11-30 23:46:422059 ApplyPageHidden(/*hidden=*/false, /*initial_setting=*/false);
[email protected]a6939ca42011-02-18 17:58:072060}
[email protected]1e6e3c992010-02-08 15:52:132061
lfg8d649cc2017-04-28 18:04:302062void RenderViewImpl::OnUpdateScreenInfo(const ScreenInfo& screen_info) {
2063 // This IPC only updates the screen info on RenderViews that have a remote
2064 // main frame. For local main frames, the ScreenInfo is updated in
2065 // ViewMsg_Resize.
danakj53802692018-07-25 21:46:442066 // TODO(danakj): Move this message to RenderWidget?
lfg8d649cc2017-04-28 18:04:302067 if (!main_render_frame_)
danakj53802692018-07-25 21:46:442068 GetWidget()->set_screen_info(screen_info);
lfg8d649cc2017-04-28 18:04:302069}
2070
Francois Doray47f759d2018-06-11 18:13:512071void RenderViewImpl::SetPageFrozen(bool frozen) {
2072 if (webview())
2073 webview()->SetPageFrozen(frozen);
Fadi Meawada6573e02018-03-10 00:52:112074}
2075
alexmos3fcd0ca2015-10-23 18:18:332076void RenderViewImpl::SetFocus(bool enable) {
danakja2c9d0a92018-07-25 20:01:182077 // This is not an IPC message, don't go through the IPC handler. This is used
2078 // in cases where the IPC message should not happen.
2079 GetWidget()->SetFocus(enable);
[email protected]b2e4c70132013-10-03 02:07:512080}
2081
Blink Reformat1c4d759e2017-04-09 16:34:542082void RenderViewImpl::ZoomLimitsChanged(double minimum_level,
[email protected]310ebd6302011-10-10 19:06:282083 double maximum_level) {
a.sarkar.arundaadc712015-02-26 05:39:082084 // Round the double to avoid returning incorrect minimum/maximum zoom
2085 // percentages.
2086 int minimum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492087 ZoomLevelToZoomFactor(minimum_level) * 100);
a.sarkar.arundaadc712015-02-26 05:39:082088 int maximum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492089 ZoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:252090
avia3dca182016-03-19 01:09:522091 Send(new ViewHostMsg_UpdateZoomLimits(GetRoutingID(), minimum_percent,
fsamuele8326c742016-01-12 00:49:392092 maximum_percent));
[email protected]b75b8292010-10-01 07:28:252093}
2094
W. James MacLeanf40603e2019-03-25 17:23:062095void RenderViewImpl::PageScaleFactorChanged(float page_scale_factor,
2096 bool is_pinch_gesture_active) {
ccameronb7c1d6c2015-03-09 17:08:242097 if (!webview())
2098 return;
mcnee432e47d2015-11-09 19:37:462099
avia3dca182016-03-19 01:09:522100 Send(new ViewHostMsg_PageScaleFactorChanged(GetRoutingID(),
W. James MacLeanf40603e2019-03-25 17:23:062101 page_scale_factor));
danakj77821e252019-03-27 19:58:042102 // TODO(wjmaclean): Merge this into RenderWidget's
2103 // SetPageScaleFactorAndLimits().
W. James MacLeanf40603e2019-03-25 17:23:062104 GetWidget()->PageScaleFactorChanged(page_scale_factor,
2105 is_pinch_gesture_active);
ccameronb7c1d6c2015-03-09 17:08:242106}
2107
Blink Reformat1c4d759e2017-04-09 16:34:542108void RenderViewImpl::PageImportanceSignalsChanged() {
kouhei40f03cb2015-09-24 07:47:012109 if (!webview() || !main_render_frame_)
2110 return;
2111
Blink Reformat1c4d759e2017-04-09 16:34:542112 auto* web_signals = webview()->PageImportanceSignals();
kouhei40f03cb2015-09-24 07:47:012113
2114 PageImportanceSignals signals;
Blink Reformat1c4d759e2017-04-09 16:34:542115 signals.had_form_interaction = web_signals->HadFormInteraction();
kouhei40f03cb2015-09-24 07:47:012116
2117 main_render_frame_->Send(new FrameHostMsg_UpdatePageImportanceSignals(
2118 main_render_frame_->GetRoutingID(), signals));
2119}
2120
danakj9a8a9cf2018-07-17 23:52:122121void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) {
danakja2c9d0a92018-07-25 20:01:182122 GetWidget()->DidAutoResize(newSize);
danakj9a8a9cf2018-07-17 23:52:122123}
2124
danakja2c9d0a92018-07-25 20:01:182125void RenderViewImpl::DidFocus(blink::WebLocalFrame* calling_frame) {
2126 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2127 // we won't have to test for user gesture anymore and we can
2128 // move that code back to render_widget.cc
2129 if (WebUserGestureIndicator::IsProcessingUserGesture(calling_frame) &&
Kent Tamura2eab5b12018-12-07 04:31:232130 !RenderThreadImpl::current()->web_test_mode()) {
danakja2c9d0a92018-07-25 20:01:182131 Send(new ViewHostMsg_Focus(GetRoutingID()));
2132
2133 // Tattle on the frame that called |window.focus()|.
2134 RenderFrameImpl* calling_render_frame =
2135 RenderFrameImpl::FromWebFrame(calling_frame);
2136 if (calling_render_frame)
2137 calling_render_frame->FrameDidCallFocus();
2138 }
2139}
2140
danakj46b3dde2018-10-18 16:12:172141blink::WebScreenInfo RenderViewImpl::GetScreenInfo() {
2142 const ScreenInfo& info = GetWidget()->screen_info();
2143
2144 blink::WebScreenInfo web_screen_info;
2145 web_screen_info.device_scale_factor = info.device_scale_factor;
2146 web_screen_info.color_space = info.color_space;
2147 web_screen_info.depth = info.depth;
2148 web_screen_info.depth_per_component = info.depth_per_component;
2149 web_screen_info.is_monochrome = info.is_monochrome;
2150 web_screen_info.rect = blink::WebRect(info.rect);
2151 web_screen_info.available_rect = blink::WebRect(info.available_rect);
2152 switch (info.orientation_type) {
2153 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
2154 web_screen_info.orientation_type =
2155 blink::kWebScreenOrientationPortraitPrimary;
2156 break;
2157 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
2158 web_screen_info.orientation_type =
2159 blink::kWebScreenOrientationPortraitSecondary;
2160 break;
2161 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
2162 web_screen_info.orientation_type =
2163 blink::kWebScreenOrientationLandscapePrimary;
2164 break;
2165 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
2166 web_screen_info.orientation_type =
2167 blink::kWebScreenOrientationLandscapeSecondary;
2168 break;
2169 default:
2170 web_screen_info.orientation_type = blink::kWebScreenOrientationUndefined;
2171 break;
2172 }
2173 web_screen_info.orientation_angle = info.orientation_angle;
2174
2175 return web_screen_info;
2176}
2177
[email protected]20657a82012-08-21 20:23:032178#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:542179bool RenderViewImpl::OpenDateTimeChooser(
[email protected]180ef242013-11-07 06:50:462180 const blink::WebDateTimeChooserParams& params,
2181 blink::WebDateTimeChooserCompletion* completion) {
[email protected]e8072562013-12-04 06:04:132182 // JavaScript may try to open a date time chooser while one is already open.
2183 if (date_time_picker_client_)
2184 return false;
[email protected]b18583c2012-12-18 06:55:272185 date_time_picker_client_.reset(
2186 new RendererDateTimePicker(this, params, completion));
2187 return date_time_picker_client_->Open();
2188}
2189
[email protected]e8072562013-12-04 06:04:132190void RenderViewImpl::DismissDateTimeDialog() {
2191 DCHECK(date_time_picker_client_);
Lei Zhang88f23ba2017-10-27 05:56:262192 date_time_picker_client_.reset();
[email protected]e8072562013-12-04 06:04:132193}
[email protected]e8072562013-12-04 06:04:132194
braveyao1d8ee7b2017-03-29 21:10:042195void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) {
2196 if (!main_render_frame_)
2197 return;
2198
Chandan Padhi26dbd9b32017-11-27 11:13:352199 MediaStreamDeviceObserver* media_stream_device_observer =
2200 main_render_frame_->GetMediaStreamDeviceObserver();
2201 if (!media_stream_device_observer)
braveyao1d8ee7b2017-03-29 21:10:042202 return;
2203
Guido Urdaneta73fa6632019-01-14 18:46:262204 blink::MediaStreamDevices video_devices =
Chandan Padhi26dbd9b32017-11-27 11:13:352205 media_stream_device_observer->GetNonScreenCaptureDevices();
braveyao1d8ee7b2017-03-29 21:10:042206 RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices(
Chandan Padhi6dbfb732017-09-01 16:08:492207 video_devices, suspend);
braveyao1d8ee7b2017-03-29 21:10:042208}
estade6b9696bd2016-05-04 23:51:362209#endif // defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:032210
[email protected]b283d292013-02-21 08:40:342211unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
2212 return history_list_length_;
2213}
2214
[email protected]cc290f902013-03-04 20:06:022215void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
Nasko Oskova463a052018-05-08 16:42:142216 // If the main frame is remote, return immediately. Page level focus
2217 // should be set from the browser process, so if needed by tests it should
2218 // be properly supported.
2219 if (webview()->MainFrame()->IsWebRemoteFrame())
2220 return;
2221
Albert J. Wong7bbf22d2018-12-20 00:27:272222 if (enable == GetWidget()->has_focus())
danakja2c9d0a92018-07-25 20:01:182223 return;
2224
[email protected]cc290f902013-03-04 20:06:022225 if (enable) {
danakja2c9d0a92018-07-25 20:01:182226 SetActiveForWidget(true);
2227 // Fake an IPC message so go through the IPC handler.
Albert J. Wong7bbf22d2018-12-20 00:27:272228 GetWidget()->OnSetFocus(true);
[email protected]cc290f902013-03-04 20:06:022229 } else {
danakja2c9d0a92018-07-25 20:01:182230 // Fake an IPC message so go through the IPC handler.
Albert J. Wong7bbf22d2018-12-20 00:27:272231 GetWidget()->OnSetFocus(false);
danakja2c9d0a92018-07-25 20:01:182232 SetActiveForWidget(false);
[email protected]cc290f902013-03-04 20:06:022233 }
2234}
2235
W. James MacLeand973a55b2018-11-29 21:39:132236void RenderViewImpl::OnAnimateDoubleTapZoomInMainFrame(
2237 const blink::WebPoint& point,
2238 const blink::WebRect& bound) {
2239 webview()->AnimateDoubleTapZoom(point, bound);
2240}
2241
W. James MacLean5372eb72018-12-19 12:56:362242void RenderViewImpl::OnZoomToFindInPageRect(
2243 const blink::WebRect& rect_to_zoom) {
2244 webview()->ZoomToFindInPageRect(rect_to_zoom);
2245}
2246
danakjd51fd53d2018-12-21 23:06:092247void RenderViewImpl::OnSetBackgroundOpaque(bool opaque) {
2248 if (!webview())
2249 return;
2250
2251 if (opaque) {
2252 webview()->ClearBaseBackgroundColorOverride();
2253 webview()->ClearBackgroundColorOverride();
2254 } else {
2255 webview()->SetBaseBackgroundColorOverride(SK_ColorTRANSPARENT);
2256 webview()->SetBackgroundColorOverride(SK_ColorTRANSPARENT);
2257 }
2258}
2259
danakj295c43f182019-03-13 16:37:172260// static
2261scoped_refptr<base::SingleThreadTaskRunner>
2262RenderViewImpl::GetCleanupTaskRunner() {
2263 return RenderThreadImpl::current_blink_platform_impl()
2264 ->main_thread_scheduler()
2265 ->CleanupTaskRunner();
2266}
2267
[email protected]e9ff79c2012-10-19 21:31:262268} // namespace content