blob: 203c5969f7f86a96f60a81675e176a8959db2908 [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"
[email protected]21aa99682013-06-11 07:17:0129#include "base/strings/string_number_conversions.h"
[email protected]b9e7c479f2013-04-12 04:33:2430#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4931#include "base/strings/string_split.h"
[email protected]21aa99682013-06-11 07:17:0132#include "base/strings/string_util.h"
[email protected]40d11e02013-03-28 17:43:1433#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0034#include "base/strings/utf_string_conversions.h"
dalecurtiscd971252016-09-21 16:09:0035#include "base/sys_info.h"
fdoray7a8954a42016-06-07 04:28:3836#include "base/threading/thread_task_runner_handle.h"
[email protected]abb522162013-06-28 01:54:1637#include "base/time/time.h"
primiano9e38d552015-01-28 04:18:0138#include "base/trace_event/trace_event.h"
avi1023d012015-12-25 02:39:1439#include "build/build_config.h"
dongseong.hwange095dfa2016-02-04 11:21:3940#include "cc/base/switches.h"
enne98c9f8052017-03-15 19:38:2241#include "cc/paint/skia_paint_canvas.h"
danakj4c987652018-07-05 15:49:4142#include "cc/trees/layer_tree_host.h"
jinho.bang632a1a722014-09-18 03:02:5643#include "content/common/content_constants_internal.h"
[email protected]5f2aa722013-08-07 16:59:4144#include "content/common/dom_storage/dom_storage_types.h"
[email protected]59f4f2fa2011-03-23 01:00:5545#include "content/common/drag_messages.h"
[email protected]c6bc20332014-02-28 18:30:3946#include "content/common/frame_messages.h"
alexmosbc7eafa2014-12-06 01:38:0947#include "content/common/frame_replication_state.h"
[email protected]c084330e02013-04-27 01:08:1548#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0749#include "content/common/page_messages.h"
rockot5c478a72016-09-28 23:14:1850#include "content/common/render_message_filter.mojom.h"
[email protected]778574e2011-03-21 22:03:5051#include "content/common/view_messages.h"
arthursonzognic517fc32016-08-11 11:04:2452#include "content/public/common/browser_side_navigation_policy.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"
[email protected]818915cd2012-11-20 13:14:1160#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0361#include "content/public/common/url_constants.h"
Jaebaek Seo53ab80a662018-01-29 04:50:4662#include "content/public/common/use_zoom_for_dsf_policy.h"
[email protected]b3a97b52014-07-09 06:25:0563#include "content/public/common/web_preferences.h"
[email protected]d344114c2011-10-01 01:24:3464#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0765#include "content/public/renderer/document_state.h"
[email protected]3a034ebb2011-10-03 19:19:4466#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3667#include "content/public/renderer/render_view_visitor.h"
scottmg8e6c6082017-02-13 23:15:4868#include "content/public/renderer/window_features_converter.h"
John Abd-El-Malekdcf1d1372017-10-22 06:39:4169#include "content/renderer/appcache/appcache_dispatcher.h"
70#include "content/renderer/appcache/web_application_cache_host_impl.h"
[email protected]e6e56752012-08-10 00:46:0671#include "content/renderer/browser_plugin/browser_plugin.h"
72#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]dc293a72013-07-01 11:11:2273#include "content/renderer/drop_data_builder.h"
danakja6c10012018-07-06 14:25:3674#include "content/renderer/gpu/layer_tree_view.h"
[email protected]dc064352014-04-25 08:36:3875#include "content/renderer/history_serialization.h"
[email protected]66fca5bc2013-05-23 06:58:2976#include "content/renderer/ime_event_guard.h"
[email protected]92d457802013-04-01 19:18:4977#include "content/renderer/internal_document_state_data.h"
John Abd-El-Malek6b56ef712017-10-21 22:52:4678#include "content/renderer/loader/request_extra_data.h"
Amos Limbcc710e2018-06-08 05:51:1779#include "content/renderer/media/audio/audio_device_factory.h"
Miguel Casasa8c2c5a2018-02-12 18:51:0380#include "content/renderer/media/stream/media_stream_device_observer.h"
[email protected]6392d982013-04-16 16:59:2281#include "content/renderer/media/video_capture_impl_manager.h"
Patrik Höglundb564859b2018-05-17 11:17:1682#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
83#include "content/renderer/media/webrtc/rtc_peer_connection_handler.h"
[email protected]227692c52013-05-31 22:43:0484#include "content/renderer/render_frame_impl.h"
[email protected]5a7100d2014-05-19 01:29:0485#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0586#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4487#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4488#include "content/renderer/render_widget_fullscreen_pepper.h"
Daniel Murphye3eec92c2018-02-23 19:09:1589#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]663bd9e2011-03-21 01:07:0190#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]5b45ad42013-10-25 00:42:0491#include "content/renderer/resizing_mode_selector.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/mojom/page/page_visibility_state.mojom.h"
112#include "third_party/blink/public/platform/file_path_conversion.h"
113#include "third_party/blink/public/platform/url_conversion.h"
114#include "third_party/blink/public/platform/web_connection_type.h"
115#include "third_party/blink/public/platform/web_effective_connection_type.h"
116#include "third_party/blink/public/platform/web_http_body.h"
117#include "third_party/blink/public/platform/web_image.h"
118#include "third_party/blink/public/platform/web_input_event.h"
119#include "third_party/blink/public/platform/web_input_event_result.h"
120#include "third_party/blink/public/platform/web_network_state_notifier.h"
121#include "third_party/blink/public/platform/web_point.h"
122#include "third_party/blink/public/platform/web_rect.h"
123#include "third_party/blink/public/platform/web_runtime_features.h"
124#include "third_party/blink/public/platform/web_size.h"
125#include "third_party/blink/public/platform/web_string.h"
126#include "third_party/blink/public/platform/web_url.h"
127#include "third_party/blink/public/platform/web_url_error.h"
128#include "third_party/blink/public/platform/web_url_request.h"
129#include "third_party/blink/public/platform/web_url_response.h"
130#include "third_party/blink/public/platform/web_vector.h"
131#include "third_party/blink/public/public_buildflags.h"
132#include "third_party/blink/public/web/web_autofill_client.h"
133#include "third_party/blink/public/web/web_ax_object.h"
134#include "third_party/blink/public/web/web_date_time_chooser_completion.h"
135#include "third_party/blink/public/web/web_date_time_chooser_params.h"
136#include "third_party/blink/public/web/web_document.h"
137#include "third_party/blink/public/web/web_dom_event.h"
138#include "third_party/blink/public/web/web_dom_message_event.h"
139#include "third_party/blink/public/web/web_element.h"
Kent Tamura79516b32018-08-01 07:42:59140#include "third_party/blink/public/web/web_file_chooser_completion.h"
Blink Reformata30d4232018-04-07 15:31:06141#include "third_party/blink/public/web/web_file_chooser_params.h"
142#include "third_party/blink/public/web/web_form_control_element.h"
143#include "third_party/blink/public/web/web_form_element.h"
144#include "third_party/blink/public/web/web_frame.h"
145#include "third_party/blink/public/web/web_frame_content_dumper.h"
146#include "third_party/blink/public/web/web_frame_widget.h"
147#include "third_party/blink/public/web/web_history_item.h"
148#include "third_party/blink/public/web/web_hit_test_result.h"
149#include "third_party/blink/public/web/web_input_element.h"
150#include "third_party/blink/public/web/web_local_frame.h"
Blink Reformata30d4232018-04-07 15:31:06151#include "third_party/blink/public/web/web_navigation_policy.h"
152#include "third_party/blink/public/web/web_page_importance_signals.h"
danakj25ec6e2b2018-09-26 17:01:31153#include "third_party/blink/public/web/web_page_popup.h"
Blink Reformata30d4232018-04-07 15:31:06154#include "third_party/blink/public/web/web_plugin.h"
155#include "third_party/blink/public/web/web_plugin_action.h"
156#include "third_party/blink/public/web/web_range.h"
157#include "third_party/blink/public/web/web_render_theme.h"
158#include "third_party/blink/public/web/web_script_source.h"
159#include "third_party/blink/public/web/web_searchable_form_data.h"
160#include "third_party/blink/public/web/web_security_policy.h"
161#include "third_party/blink/public/web/web_settings.h"
162#include "third_party/blink/public/web/web_user_gesture_indicator.h"
163#include "third_party/blink/public/web/web_view.h"
164#include "third_party/blink/public/web/web_window_features.h"
[email protected]b3a97b52014-07-09 06:25:05165#include "third_party/icu/source/common/unicode/uchar.h"
166#include "third_party/icu/source/common/unicode/uscript.h"
esecklerf2bd55f72017-03-31 09:11:57167#include "third_party/skia/include/core/SkColor.h"
[email protected]1400e6dc2013-04-27 02:36:27168#include "ui/base/ui_base_switches_util.h"
tfarina655f81d2014-12-23 02:38:50169#include "ui/gfx/geometry/point.h"
tfarina3b0452d2014-12-31 15:20:09170#include "ui/gfx/geometry/rect.h"
171#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32172#include "ui/gfx/geometry/size_conversions.h"
[email protected]08397d52011-02-05 01:53:38173#include "ui/gfx/native_widget_types.h"
ccameron772317d2017-06-04 18:35:03174#include "ui/gfx/switches.h"
mfomitchev3ba450ad2017-04-03 18:20:40175#include "ui/latency/latency_info.h"
csharrisond88f9752016-10-26 23:56:36176#include "url/origin.h"
markdittmer67b71ea2016-03-03 22:40:03177#include "url/url_constants.h"
[email protected]c4a9e932011-03-05 04:05:55178#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:29179
[email protected]25fb9b32012-04-27 03:21:55180#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25181#include <cpu-features.h>
182
dalecurtiscd971252016-09-21 16:09:00183#include "base/android/build_info.h"
kylechare7d8d5c72018-01-05 19:06:28184#include "base/memory/shared_memory.h"
185#include "content/child/child_thread_impl.h"
tfarina3b0452d2014-12-31 15:20:09186#include "ui/gfx/geometry/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40187
[email protected]78043bdd2010-04-05 18:45:33188#elif defined(OS_MACOSX)
189#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57190#endif
191
brettw4b461082016-11-19 18:55:16192#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]ea2fb972013-08-07 05:44:26193#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
194#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26195#endif
196
[email protected]180ef242013-11-07 06:50:46197using blink::WebAXObject;
198using blink::WebApplicationCacheHost;
199using blink::WebApplicationCacheHostClient;
[email protected]180ef242013-11-07 06:50:46200using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46201using blink::WebData;
[email protected]180ef242013-11-07 06:50:46202using blink::WebDocument;
[email protected]180ef242013-11-07 06:50:46203using blink::WebDragOperation;
[email protected]180ef242013-11-07 06:50:46204using blink::WebElement;
[email protected]180ef242013-11-07 06:50:46205using blink::WebFileChooserCompletion;
[email protected]180ef242013-11-07 06:50:46206using blink::WebFormControlElement;
207using blink::WebFormElement;
208using blink::WebFrame;
dglazkov03223492016-02-08 22:16:03209using blink::WebFrameContentDumper;
[email protected]180ef242013-11-07 06:50:46210using blink::WebGestureEvent;
211using blink::WebHistoryItem;
212using blink::WebHTTPBody;
dglazkov8d0c21dd2016-08-06 15:56:36213using blink::WebHitTestResult;
[email protected]180ef242013-11-07 06:50:46214using blink::WebImage;
215using blink::WebInputElement;
216using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22217using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46218using blink::WebMouseEvent;
219using blink::WebNavigationPolicy;
220using blink::WebNavigationType;
221using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46222using blink::WebPluginAction;
[email protected]180ef242013-11-07 06:50:46223using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46224using blink::WebRect;
225using blink::WebReferrerPolicy;
Daniel Chengd5e56ff2017-06-24 07:44:02226using blink::WebSandboxFlags;
[email protected]180ef242013-11-07 06:50:46227using blink::WebScriptSource;
228using blink::WebSearchableFormData;
229using blink::WebSecurityOrigin;
230using blink::WebSecurityPolicy;
[email protected]180ef242013-11-07 06:50:46231using blink::WebSettings;
232using blink::WebSize;
[email protected]180ef242013-11-07 06:50:46233using blink::WebString;
[email protected]180ef242013-11-07 06:50:46234using blink::WebTextDirection;
235using blink::WebTouchEvent;
236using blink::WebURL;
237using blink::WebURLError;
238using blink::WebURLRequest;
239using blink::WebURLResponse;
240using blink::WebUserGestureIndicator;
241using blink::WebVector;
242using blink::WebView;
243using blink::WebWidget;
244using blink::WebWindowFeatures;
[email protected]b3a97b52014-07-09 06:25:05245using blink::WebRuntimeFeatures;
[email protected]6fdd4182010-10-14 23:59:26246using base::TimeDelta;
[email protected]e1acf6f2008-10-27 20:43:33247
[email protected]20657a82012-08-21 20:23:03248
[email protected]e9ff79c2012-10-19 21:31:26249namespace content {
250
initial.commit09911bf2008-07-26 23:55:29251//-----------------------------------------------------------------------------
252
[email protected]180ef242013-11-07 06:50:46253typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
jbroman8319b232017-03-08 22:53:29254static base::LazyInstance<ViewMap>::Leaky g_view_map =
[email protected]058561b2012-12-03 06:48:22255 LAZY_INSTANCE_INITIALIZER;
scottmg5e65e3a2017-03-08 08:48:46256typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap;
jbroman8319b232017-03-08 22:53:29257static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map =
258 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02259
[email protected]882daa92009-11-05 16:31:31260// Time, in seconds, we delay before sending content state changes (such as form
261// state and scroll position) to the browser. We delay sending changes to avoid
262// spamming the browser.
263// To avoid having tab/session restore require sending a message to get the
264// current content state during tab closing we use a shorter timeout for the
265// foreground renderer. This means there is a small window of time from which
266// content state is modified and not sent to session restore, but this is
267// better than having to wake up all renderers during shutdown.
avif937e1d2014-11-02 18:13:07268const int kDelaySecondsForContentStateSyncHidden = 5;
269const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29270
dcheng35d31c112015-07-22 00:17:36271static RenderViewImpl* (*g_create_render_view_impl)(
272 CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15273 const mojom::CreateViewParams&) = nullptr;
[email protected]8d41d7612012-11-14 20:32:19274
[email protected]c6bc20332014-02-28 18:30:39275// static
[email protected]e507045d2013-07-24 15:23:44276Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56277 WebFrame* frame,
278 const WebURLRequest& request) {
Blink Reformat1c4d759e2017-04-09 16:34:54279 return Referrer(blink::WebStringToGURL(
280 request.HttpHeaderField(WebString::FromUTF8("Referer"))),
281 request.GetReferrerPolicy());
[email protected]44e55b012013-07-23 14:21:56282}
283
[email protected]c6bc20332014-02-28 18:30:39284// static
[email protected]65920f332014-03-04 21:14:18285WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32286 WebNavigationPolicy policy) {
287 switch (policy) {
Blink Reformat1c4d759e2017-04-09 16:34:54288 case blink::kWebNavigationPolicyIgnore:
nick3b04f322016-08-31 19:29:19289 return WindowOpenDisposition::IGNORE_ACTION;
Blink Reformat1c4d759e2017-04-09 16:34:54290 case blink::kWebNavigationPolicyDownload:
nick3b04f322016-08-31 19:29:19291 return WindowOpenDisposition::SAVE_TO_DISK;
Blink Reformat1c4d759e2017-04-09 16:34:54292 case blink::kWebNavigationPolicyCurrentTab:
nick3b04f322016-08-31 19:29:19293 return WindowOpenDisposition::CURRENT_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54294 case blink::kWebNavigationPolicyNewBackgroundTab:
nick3b04f322016-08-31 19:29:19295 return WindowOpenDisposition::NEW_BACKGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54296 case blink::kWebNavigationPolicyNewForegroundTab:
nick3b04f322016-08-31 19:29:19297 return WindowOpenDisposition::NEW_FOREGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54298 case blink::kWebNavigationPolicyNewWindow:
nick3b04f322016-08-31 19:29:19299 return WindowOpenDisposition::NEW_WINDOW;
Blink Reformat1c4d759e2017-04-09 16:34:54300 case blink::kWebNavigationPolicyNewPopup:
nick3b04f322016-08-31 19:29:19301 return WindowOpenDisposition::NEW_POPUP;
[email protected]48861e22013-01-09 00:27:32302 default:
303 NOTREACHED() << "Unexpected WebNavigationPolicy";
nick3b04f322016-08-31 19:29:19304 return WindowOpenDisposition::IGNORE_ACTION;
[email protected]48861e22013-01-09 00:27:32305 }
306}
307
initial.commit09911bf2008-07-26 23:55:29308///////////////////////////////////////////////////////////////////////////////
309
[email protected]217690d2012-01-27 07:33:11310namespace {
311
[email protected]b3a97b52014-07-09 06:25:05312typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
313 const base::string16&,
314 UScriptCode);
315
316void SetStandardFontFamilyWrapper(WebSettings* settings,
317 const base::string16& font,
318 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54319 settings->SetStandardFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05320}
321
322void SetFixedFontFamilyWrapper(WebSettings* settings,
323 const base::string16& font,
324 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54325 settings->SetFixedFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05326}
327
328void SetSerifFontFamilyWrapper(WebSettings* settings,
329 const base::string16& font,
330 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54331 settings->SetSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05332}
333
334void SetSansSerifFontFamilyWrapper(WebSettings* settings,
335 const base::string16& font,
336 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54337 settings->SetSansSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05338}
339
340void SetCursiveFontFamilyWrapper(WebSettings* settings,
341 const base::string16& font,
342 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54343 settings->SetCursiveFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05344}
345
346void SetFantasyFontFamilyWrapper(WebSettings* settings,
347 const base::string16& font,
348 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54349 settings->SetFantasyFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05350}
351
352void SetPictographFontFamilyWrapper(WebSettings* settings,
353 const base::string16& font,
354 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54355 settings->SetPictographFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05356}
357
358// If |scriptCode| is a member of a family of "similar" script codes, returns
359// the script code in that family that is used by WebKit for font selection
360// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
361// considered equivalent for the purposes of font selection. WebKit uses the
362// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
363// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
364// uses different scripts than the ones in Chrome pref names because the version
365// of ICU included on certain ports does not have some of the newer scripts. If
366// |scriptCode| is not a member of such a family, returns |scriptCode|.
367UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
368 switch (scriptCode) {
369 case USCRIPT_HIRAGANA:
370 case USCRIPT_KATAKANA:
371 case USCRIPT_JAPANESE:
372 return USCRIPT_KATAKANA_OR_HIRAGANA;
373 case USCRIPT_KOREAN:
374 return USCRIPT_HANGUL;
375 default:
376 return scriptCode;
377 }
378}
379
380void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
381 SetFontFamilyWrapper setter,
382 WebSettings* settings) {
jdoerrie5a73d0fa2018-10-02 23:54:05383 for (auto it = map.begin(); it != map.end(); ++it) {
avi1023d012015-12-25 02:39:14384 int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
[email protected]b3a97b52014-07-09 06:25:05385 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
386 UScriptCode code = static_cast<UScriptCode>(script);
387 (*setter)(settings, it->second, GetScriptForWebSettings(code));
388 }
389 }
390}
391
wangxianzhu3bf39be52015-04-10 23:56:41392void ApplyBlinkSettings(const base::CommandLine& command_line,
393 WebSettings* settings) {
394 if (!command_line.HasSwitch(switches::kBlinkSettings))
395 return;
396
brettw26dab8f02015-08-08 00:28:47397 std::vector<std::string> blink_settings = base::SplitString(
398 command_line.GetSwitchValueASCII(switches::kBlinkSettings),
399 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
wangxianzhu3bf39be52015-04-10 23:56:41400 for (const std::string& setting : blink_settings) {
401 size_t pos = setting.find('=');
Blink Reformat1c4d759e2017-04-09 16:34:54402 settings->SetFromStrings(
403 blink::WebString::FromLatin1(setting.substr(0, pos)),
404 blink::WebString::FromLatin1(
wangxianzhu3bf39be52015-04-10 23:56:41405 pos == std::string::npos ? "" : setting.substr(pos + 1)));
406 }
407}
408
scottmgde42fb92017-02-10 17:56:03409content::mojom::WindowContainerType WindowFeaturesToContainerType(
scottmg05324cb2017-02-09 23:46:04410 const blink::WebWindowFeatures& window_features) {
japhetbfc47892017-06-02 23:01:19411 if (window_features.background) {
412 if (window_features.persistent)
scottmgde42fb92017-02-10 17:56:03413 return content::mojom::WindowContainerType::PERSISTENT;
scottmg05324cb2017-02-09 23:46:04414 else
scottmgde42fb92017-02-10 17:56:03415 return content::mojom::WindowContainerType::BACKGROUND;
scottmg05324cb2017-02-09 23:46:04416 } else {
scottmgde42fb92017-02-10 17:56:03417 return content::mojom::WindowContainerType::NORMAL;
scottmg05324cb2017-02-09 23:46:04418 }
419}
420
Ahmed Fakhry58e6ef542018-09-04 18:05:38421// Check content::BrowserControlsState, and cc::BrowserControlsState
422// are kept in sync.
423static_assert(int(BROWSER_CONTROLS_STATE_SHOWN) ==
424 int(cc::BrowserControlsState::kShown),
425 "mismatching enums: SHOWN");
426static_assert(int(BROWSER_CONTROLS_STATE_HIDDEN) ==
427 int(cc::BrowserControlsState::kHidden),
428 "mismatching enums: HIDDEN");
429static_assert(int(BROWSER_CONTROLS_STATE_BOTH) ==
430 int(cc::BrowserControlsState::kBoth),
431 "mismatching enums: BOTH");
432
433cc::BrowserControlsState ContentToCc(BrowserControlsState state) {
434 return static_cast<cc::BrowserControlsState>(state);
435}
Ahmed Fakhry58e6ef542018-09-04 18:05:38436
[email protected]217690d2012-01-27 07:33:11437} // namespace
438
Hajime Hoshi315a61f2018-08-14 17:27:28439RenderViewImpl::RenderViewImpl(CompositorDependencies* compositor_deps,
440 const mojom::CreateViewParams& params)
Albert J. Wongcb004632018-07-10 22:58:25441 : RenderWidget(params.main_frame_widget_routing_id,
nick8331f8ad2016-11-15 20:42:45442 compositor_deps,
danakj829cdd142018-09-14 21:13:27443 WidgetType::kFrame,
Scott Violetae08f332018-07-27 17:37:23444 params.visual_properties.screen_info,
danakj73dd3032018-07-28 17:49:53445 params.visual_properties.display_mode,
naskobd911332014-11-25 01:13:36446 params.swapped_out,
447 params.hidden,
Hajime Hoshi315a61f2018-08-14 17:27:28448 params.never_visible),
Albert J. Wongcb004632018-07-10 22:58:25449 routing_id_(params.view_id),
danakj73dd3032018-07-28 17:49:53450 renderer_wide_named_frame_lookup_(
451 params.renderer_wide_named_frame_lookup),
naskobd911332014-11-25 01:13:36452 webkit_preferences_(params.web_preferences),
changwand659e202016-06-13 02:39:12453 session_storage_namespace_id_(params.session_storage_namespace_id),
wjmaclean1d970622017-01-21 22:28:24454 weak_ptr_factory_(this) {
Daniel Murphy95792ef2018-10-04 01:29:55455 DCHECK(!session_storage_namespace_id_.empty())
456 << "Session storage namespace must be populated.";
avi40b5be7a2016-03-03 21:13:44457 GetWidget()->set_owner_delegate(this);
Albert J. Wongcb004632018-07-10 22:58:25458 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]075366912013-02-18 07:13:24459}
460
nickf7b38222016-11-22 21:59:35461void RenderViewImpl::Initialize(
Balazs Engedyba034e72017-10-27 22:26:28462 mojom::CreateViewParamsPtr params,
danakjdf1ceb72018-07-18 20:02:25463 RenderWidget::ShowCallback show_callback,
Hajime Hoshif34374412018-03-05 14:32:54464 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
nickf7b38222016-11-22 21:59:35465#if defined(OS_ANDROID)
danakjc87bfede2018-10-10 22:32:49466 bool has_show_callback = !!show_callback;
nickf7b38222016-11-22 21:59:35467#endif
[email protected]676126f72011-01-15 00:03:51468
Lukasz Anforowiczaf2f33572018-01-17 14:05:08469 WebFrame* opener_frame =
470 RenderFrameImpl::ResolveOpener(params->opener_frame_route_id);
471
danakj9a8a9cf2018-07-17 23:52:12472 // Pass WidgetClient(), not |this|, as the WebWidgetClient. The method may
473 // be overridden in layout tests to inject a test-only WebWidgetClient.
Lukasz Anforowiczaf2f33572018-01-17 14:05:08474 webview_ =
danakj9a8a9cf2018-07-17 23:52:12475 WebView::Create(this, WidgetClient(),
Lukasz Anforowiczaf2f33572018-01-17 14:05:08476 is_hidden() ? blink::mojom::PageVisibilityState::kHidden
477 : blink::mojom::PageVisibilityState::kVisible,
478 opener_frame ? opener_frame->View() : nullptr);
Scott Violetae08f332018-07-27 17:37:23479 RenderWidget::Init(std::move(show_callback), webview_->GetWidget());
[email protected]11fee2332011-03-29 20:36:35480
nasko4c0feb62015-06-05 18:37:06481 g_view_map.Get().insert(std::make_pair(webview(), this));
avia3dca182016-03-19 01:09:52482 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this));
nasko4c0feb62015-06-05 18:37:06483
avi83883c82014-12-23 00:08:49484 const base::CommandLine& command_line =
485 *base::CommandLine::ForCurrentProcess();
[email protected]20657a82012-08-21 20:23:03486
danakj53802692018-07-25 21:46:44487 webview()->SetDisplayMode(GetWidget()->display_mode());
Blink Reformat1c4d759e2017-04-09 16:34:54488 webview()->GetSettings()->SetThreadedScrollingEnabled(
dcheng0ff94cfc2016-03-15 21:50:51489 !command_line.HasSwitch(switches::kDisableThreadedScrolling));
Blink Reformat1c4d759e2017-04-09 16:34:54490 webview()->SetShowFPSCounter(
dcheng0ff94cfc2016-03-15 21:50:51491 command_line.HasSwitch(cc::switches::kShowFPSCounter));
492
danakjfd0c7f42018-10-12 18:01:08493 ApplyWebPreferences(webkit_preferences_, webview());
dcheng0ff94cfc2016-03-15 21:50:51494
495 if (switches::IsTouchDragDropEnabled())
Blink Reformat1c4d759e2017-04-09 16:34:54496 webview()->GetSettings()->SetTouchDragDropEnabled(true);
dcheng0ff94cfc2016-03-15 21:50:51497
498 WebSettings::SelectionStrategyType selection_strategy =
Blink Reformat1c4d759e2017-04-09 16:34:54499 WebSettings::SelectionStrategyType::kCharacter;
dcheng0ff94cfc2016-03-15 21:50:51500 const std::string selection_strategy_str =
Gyuyoung Kim63abad22018-06-15 03:16:55501 command_line.GetSwitchValueASCII(switches::kTouchTextSelectionStrategy);
dcheng0ff94cfc2016-03-15 21:50:51502 if (selection_strategy_str == "direction")
Blink Reformat1c4d759e2017-04-09 16:34:54503 selection_strategy = WebSettings::SelectionStrategyType::kDirection;
504 webview()->GetSettings()->SetSelectionStrategy(selection_strategy);
dcheng0ff94cfc2016-03-15 21:50:51505
Gyuyoung Kim63abad22018-06-15 03:16:55506 std::string passive_listeners_default =
dtapuskaf65650b2016-05-13 17:21:34507 command_line.GetSwitchValueASCII(switches::kPassiveListenersDefault);
Gyuyoung Kim63abad22018-06-15 03:16:55508 if (!passive_listeners_default.empty()) {
dtapuskaf65650b2016-05-13 17:21:34509 WebSettings::PassiveEventListenerDefault passiveDefault =
Blink Reformat1c4d759e2017-04-09 16:34:54510 WebSettings::PassiveEventListenerDefault::kFalse;
Gyuyoung Kim63abad22018-06-15 03:16:55511 if (passive_listeners_default == "true")
Blink Reformat1c4d759e2017-04-09 16:34:54512 passiveDefault = WebSettings::PassiveEventListenerDefault::kTrue;
Gyuyoung Kim63abad22018-06-15 03:16:55513 else if (passive_listeners_default == "forcealltrue")
Blink Reformat1c4d759e2017-04-09 16:34:54514 passiveDefault = WebSettings::PassiveEventListenerDefault::kForceAllTrue;
515 webview()->GetSettings()->SetPassiveEventListenerDefault(passiveDefault);
dtapuskaf65650b2016-05-13 17:21:34516 }
517
Kunihiko Sakamoto208565992018-08-07 03:15:17518 std::string network_quiet_timeout =
519 command_line.GetSwitchValueASCII(switches::kNetworkQuietTimeout);
520 if (!network_quiet_timeout.empty()) {
521 double network_quiet_timeout_seconds = 0.0;
522 if (base::StringToDouble(network_quiet_timeout,
523 &network_quiet_timeout_seconds)) {
524 webview()->GetSettings()->SetNetworkQuietTimeout(
525 network_quiet_timeout_seconds);
Gyuyoung Kim63abad22018-06-15 03:16:55526 }
527 }
528
Blink Reformat1c4d759e2017-04-09 16:34:54529 ApplyBlinkSettings(command_line, webview()->GetSettings());
dcheng0ff94cfc2016-03-15 21:50:51530
danakjaf29226f2018-09-25 17:56:57531 // We have either a main frame or a proxy routing id.
532 DCHECK_NE(params->main_frame_routing_id != MSG_ROUTING_NONE,
533 params->proxy_routing_id != MSG_ROUTING_NONE);
534
Balazs Engedyba034e72017-10-27 22:26:28535 if (params->main_frame_routing_id != MSG_ROUTING_NONE) {
Ken Rockot26efbd62017-11-16 04:39:49536 CHECK(params->main_frame_interface_provider.is_valid());
537 service_manager::mojom::InterfaceProviderPtr main_frame_interface_provider(
538 std::move(params->main_frame_interface_provider));
dcheng3ce04b62015-10-26 23:30:55539 main_render_frame_ = RenderFrameImpl::CreateMainFrame(
Balazs Engedyba034e72017-10-27 22:26:28540 this, params->main_frame_routing_id,
Ken Rockot26efbd62017-11-16 04:39:49541 std::move(main_frame_interface_provider),
Fady Samuela863f152018-03-09 16:10:03542 params->main_frame_widget_routing_id, params->hidden,
danakj53802692018-07-25 21:46:44543 GetWidget()->GetWebScreenInfo(), GetWidget()->compositor_deps(),
544 opener_frame, params->devtools_main_frame_token,
545 params->replicated_frame_state, params->has_committed_real_load);
dchengc5ef1a52015-08-26 20:58:30546
danakjaf29226f2018-09-25 17:56:57547 main_render_frame_->Initialize();
548 } else {
Balazs Engedyba034e72017-10-27 22:26:28549 CHECK(params->swapped_out);
550 RenderFrameProxy::CreateFrameProxy(params->proxy_routing_id, GetRoutingID(),
nick3b5a21f2016-11-22 23:07:11551 opener_frame, MSG_ROUTING_NONE,
Dmitry Gozman89361212018-02-13 16:10:44552 params->replicated_frame_state,
553 params->devtools_main_frame_token);
nasko4c0feb62015-06-05 18:37:06554 }
555
[email protected]c7c0d822014-04-16 20:19:49556 // TODO(davidben): Move this state from Blink into content.
Balazs Engedyba034e72017-10-27 22:26:28557 if (params->window_was_created_with_opener)
Blink Reformat1c4d759e2017-04-09 16:34:54558 webview()->SetOpenedByDOM();
[email protected]c7c0d822014-04-16 20:19:49559
dcheng0ff94cfc2016-03-15 21:50:51560 UpdateWebViewWithDeviceScaleFactor();
Balazs Engedyba034e72017-10-27 22:26:28561 OnSetRendererPrefs(params->renderer_preferences);
Fady Samuelff5b6eb562018-05-01 16:16:08562 OnSynchronizeVisualProperties(params->visual_properties);
[email protected]1784b2f2011-11-24 10:53:48563
[email protected]e9ff79c2012-10-19 21:31:26564 GetContentClient()->renderer()->RenderViewCreated(this);
akabac6bd1212018-06-25 20:10:48565 page_zoom_level_ = 0;
Hajime Hoshif34374412018-03-05 14:32:54566
567 nav_state_sync_timer_.SetTaskRunner(task_runner);
danakjc87bfede2018-10-10 22:32:49568
569#if defined(OS_ANDROID)
570 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated
571 // HandleNavigation codepath.
572 // Renderer-created RenderViews have a ShowCallback because they send a Show
573 // request (ViewHostMsg_ShowWidget, ViewHostMsg_ShowFullscreenWidget, or
574 // FrameHostMsg_ShowCreatedWindow) to the browser to attach them to the UI
575 // there. Browser-created RenderViews do not send a Show request to the
576 // browser, so have no such callback.
577 was_created_by_renderer_ = has_show_callback;
578#endif
initial.commit09911bf2008-07-26 23:55:29579}
580
[email protected]310ebd6302011-10-10 19:06:28581RenderViewImpl::~RenderViewImpl() {
dcheng3ce04b62015-10-26 23:30:55582 DCHECK(!frame_widget_);
Albert J. Wongcb004632018-07-10 22:58:25583 RenderThread::Get()->RemoveRoute(routing_id_);
dcheng3ce04b62015-10-26 23:30:55584
[email protected]8ed1d3f2013-02-20 11:45:55585#if defined(OS_ANDROID)
davve17e025e12016-05-23 15:30:20586 // The date/time picker client is both a std::unique_ptr member of this class
587 // and a RenderViewObserver. Reset it to prevent double deletion.
[email protected]8ed1d3f2013-02-20 11:45:55588 date_time_picker_client_.reset();
589#endif
590
[email protected]60c42a8c72009-10-09 04:08:59591#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22592 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49593 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59594 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
595 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22596 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
597 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
598 it != routing_id_views->end(); ++it)
599 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59600#endif
[email protected]676126f72011-01-15 00:03:51601
ericwilligers88e69742016-10-17 19:29:55602 for (auto& observer : observers_)
603 observer.RenderViewGone();
604 for (auto& observer : observers_)
605 observer.OnDestruct();
[email protected]60c42a8c72009-10-09 04:08:59606}
607
608/*static*/
[email protected]310ebd6302011-10-10 19:06:28609RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31610 ViewMap* views = g_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05611 auto it = views->find(webview);
[email protected]a2ef54c2011-10-10 16:20:31612 return it == views->end() ? NULL : it->second;
613}
614
615/*static*/
[email protected]180ef242013-11-07 06:50:46616RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28617 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31618}
619
620/*static*/
avi1023d012015-12-25 02:39:14621RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) {
[email protected]640e303c2012-12-05 01:36:07622 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05623 auto it = views->find(routing_id);
[email protected]640e303c2012-12-05 01:36:07624 return it == views->end() ? NULL : it->second;
625}
626
627/*static*/
628RenderView* RenderView::FromRoutingID(int routing_id) {
629 return RenderViewImpl::FromRoutingID(routing_id);
630}
631
[email protected]f3a95312014-06-12 16:46:58632/* static */
jochen9c7b8f242015-06-01 15:32:02633size_t RenderView::GetRenderViewCount() {
[email protected]f3a95312014-06-12 16:46:58634 return g_view_map.Get().size();
635}
636
[email protected]640e303c2012-12-05 01:36:07637/*static*/
[email protected]e9ff79c2012-10-19 21:31:26638void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49639 ViewMap* views = g_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05640 for (auto it = views->begin(); it != views->end(); ++it) {
[email protected]60c42a8c72009-10-09 04:08:59641 if (!visitor->Visit(it->second))
642 return;
643 }
644}
645
646/*static*/
[email protected]b3a97b52014-07-09 06:25:05647void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
648 WebView* web_view) {
Blink Reformat1c4d759e2017-04-09 16:34:54649 WebSettings* settings = web_view->GetSettings();
[email protected]b3a97b52014-07-09 06:25:05650 ApplyFontsFromMap(prefs.standard_font_family_map,
651 SetStandardFontFamilyWrapper, settings);
652 ApplyFontsFromMap(prefs.fixed_font_family_map,
653 SetFixedFontFamilyWrapper, settings);
654 ApplyFontsFromMap(prefs.serif_font_family_map,
655 SetSerifFontFamilyWrapper, settings);
656 ApplyFontsFromMap(prefs.sans_serif_font_family_map,
657 SetSansSerifFontFamilyWrapper, settings);
658 ApplyFontsFromMap(prefs.cursive_font_family_map,
659 SetCursiveFontFamilyWrapper, settings);
660 ApplyFontsFromMap(prefs.fantasy_font_family_map,
661 SetFantasyFontFamilyWrapper, settings);
662 ApplyFontsFromMap(prefs.pictograph_font_family_map,
663 SetPictographFontFamilyWrapper, settings);
Blink Reformat1c4d759e2017-04-09 16:34:54664 settings->SetDefaultFontSize(prefs.default_font_size);
665 settings->SetDefaultFixedFontSize(prefs.default_fixed_font_size);
666 settings->SetMinimumFontSize(prefs.minimum_font_size);
667 settings->SetMinimumLogicalFontSize(prefs.minimum_logical_font_size);
668 settings->SetDefaultTextEncodingName(
669 WebString::FromASCII(prefs.default_encoding));
670 settings->SetJavaScriptEnabled(prefs.javascript_enabled);
671 settings->SetWebSecurityEnabled(prefs.web_security_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54672 settings->SetLoadsImagesAutomatically(prefs.loads_images_automatically);
673 settings->SetImagesEnabled(prefs.images_enabled);
674 settings->SetPluginsEnabled(prefs.plugins_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54675 settings->SetDOMPasteAllowed(prefs.dom_paste_enabled);
676 settings->SetTextAreasAreResizable(prefs.text_areas_are_resizable);
677 settings->SetAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
678 settings->SetDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
679 settings->SetJavaScriptCanAccessClipboard(
[email protected]b3a97b52014-07-09 06:25:05680 prefs.javascript_can_access_clipboard);
Blink Reformat1c4d759e2017-04-09 16:34:54681 WebRuntimeFeatures::EnableXSLT(prefs.xslt_enabled);
682 settings->SetXSSAuditorEnabled(prefs.xss_auditor_enabled);
683 settings->SetDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
Tarun Bansal333819e2018-05-15 16:38:42684 blink::WebNetworkStateNotifier::SetSaveDataEnabled(prefs.data_saver_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54685 settings->SetLocalStorageEnabled(prefs.local_storage_enabled);
686 settings->SetSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
687 WebRuntimeFeatures::EnableDatabase(prefs.databases_enabled);
688 settings->SetOfflineWebApplicationCacheEnabled(
[email protected]b3a97b52014-07-09 06:25:05689 prefs.application_cache_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54690 settings->SetHistoryEntryRequiresUserGesture(
japhet5018fe62016-09-14 19:14:04691 prefs.history_entry_requires_user_gesture);
Marijn Kruisselbrink7099444b2018-10-05 16:59:49692 settings->SetShouldThrottlePushState(!prefs.disable_pushstate_throttle);
Blink Reformat1c4d759e2017-04-09 16:34:54693 settings->SetHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
694 settings->SetCookieEnabled(prefs.cookie_enabled);
695 settings->SetNavigateOnDragDrop(prefs.navigate_on_drag_drop);
[email protected]b3a97b52014-07-09 06:25:05696
[email protected]b3a97b52014-07-09 06:25:05697 // By default, allow_universal_access_from_file_urls is set to false and thus
698 // we mitigate attacks from local HTML files by not granting file:// URLs
699 // universal access. Only test shell will enable this.
Blink Reformat1c4d759e2017-04-09 16:34:54700 settings->SetAllowUniversalAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05701 prefs.allow_universal_access_from_file_urls);
Blink Reformat1c4d759e2017-04-09 16:34:54702 settings->SetAllowFileAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05703 prefs.allow_file_access_from_file_urls);
704
Zhenyao Moa3fda9972017-09-16 01:34:40705 settings->SetWebGL1Enabled(prefs.webgl1_enabled);
706 settings->SetWebGL2Enabled(prefs.webgl2_enabled);
[email protected]b3a97b52014-07-09 06:25:05707
[email protected]b3a97b52014-07-09 06:25:05708 // Enable WebGL errors to the JS console if requested.
Blink Reformat1c4d759e2017-04-09 16:34:54709 settings->SetWebGLErrorsToConsoleEnabled(
[email protected]b3a97b52014-07-09 06:25:05710 prefs.webgl_errors_to_console_enabled);
711
712 // Uses the mock theme engine for scrollbars.
Blink Reformat1c4d759e2017-04-09 16:34:54713 settings->SetMockScrollbarsEnabled(prefs.mock_scrollbars_enabled);
[email protected]b3a97b52014-07-09 06:25:05714
Blink Reformat1c4d759e2017-04-09 16:34:54715 settings->SetHideScrollbars(prefs.hide_scrollbars);
eseckler61ff9142016-09-23 22:57:59716
[email protected]b3a97b52014-07-09 06:25:05717 // Enable gpu-accelerated 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54718 WebRuntimeFeatures::EnableAccelerated2dCanvas(
junov524668f22016-08-08 20:16:52719 prefs.accelerated_2d_canvas_enabled);
[email protected]b3a97b52014-07-09 06:25:05720
Blink Reformat1c4d759e2017-04-09 16:34:54721 settings->SetMinimumAccelerated2dCanvasSize(
[email protected]b3a97b52014-07-09 06:25:05722 prefs.minimum_accelerated_2d_canvas_size);
723
724 // Disable antialiasing for 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54725 settings->SetAntialiased2dCanvasEnabled(
[email protected]b3a97b52014-07-09 06:25:05726 !prefs.antialiased_2d_canvas_disabled);
727
zakerinasab20ebca02016-09-27 14:22:34728 // Disable antialiasing of clips for 2d canvas if requested on the command
robertphillipse25137b2014-10-20 13:44:34729 // line.
Blink Reformat1c4d759e2017-04-09 16:34:54730 settings->SetAntialiasedClips2dCanvasEnabled(
robertphillipse25137b2014-10-20 13:44:34731 prefs.antialiased_clips_2d_canvas_enabled);
732
[email protected]b3a97b52014-07-09 06:25:05733 // Set MSAA sample count for 2d canvas if requested on the command line (or
734 // default value if not).
Blink Reformat1c4d759e2017-04-09 16:34:54735 settings->SetAccelerated2dCanvasMSAASampleCount(
[email protected]b3a97b52014-07-09 06:25:05736 prefs.accelerated_2d_canvas_msaa_sample_count);
737
[email protected]b3a97b52014-07-09 06:25:05738 // Tabs to link is not part of the settings. WebCore calls
739 // ChromeClient::tabsToLinks which is part of the glue code.
Blink Reformat1c4d759e2017-04-09 16:34:54740 web_view->SetTabsToLinks(prefs.tabs_to_links);
[email protected]b3a97b52014-07-09 06:25:05741
Blink Reformat1c4d759e2017-04-09 16:34:54742 settings->SetAllowRunningOfInsecureContent(
[email protected]b3a97b52014-07-09 06:25:05743 prefs.allow_running_insecure_content);
Blink Reformat1c4d759e2017-04-09 16:34:54744 settings->SetDisableReadingFromCanvas(prefs.disable_reading_from_canvas);
745 settings->SetStrictMixedContentChecking(prefs.strict_mixed_content_checking);
mkwst2384c8222015-07-30 07:26:47746
Blink Reformat1c4d759e2017-04-09 16:34:54747 settings->SetStrictlyBlockBlockableMixedContent(
mkwst2384c8222015-07-30 07:26:47748 prefs.strictly_block_blockable_mixed_content);
749
Blink Reformat1c4d759e2017-04-09 16:34:54750 settings->SetStrictMixedContentCheckingForPlugin(
mkwst0d233e52015-08-10 09:33:14751 prefs.block_mixed_plugin_content);
752
Blink Reformat1c4d759e2017-04-09 16:34:54753 settings->SetStrictPowerfulFeatureRestrictions(
mkwst673a452f2015-01-10 14:41:50754 prefs.strict_powerful_feature_restrictions);
Blink Reformat1c4d759e2017-04-09 16:34:54755 settings->SetAllowGeolocationOnInsecureOrigins(
jww9d4ca2d2016-01-19 20:58:59756 prefs.allow_geolocation_on_insecure_origins);
Blink Reformat1c4d759e2017-04-09 16:34:54757 settings->SetPasswordEchoEnabled(prefs.password_echo_enabled);
758 settings->SetShouldPrintBackgrounds(prefs.should_print_backgrounds);
759 settings->SetShouldClearDocumentBackground(
[email protected]b3a97b52014-07-09 06:25:05760 prefs.should_clear_document_background);
Blink Reformat1c4d759e2017-04-09 16:34:54761 settings->SetEnableScrollAnimator(prefs.enable_scroll_animator);
[email protected]b3a97b52014-07-09 06:25:05762
Blink Reformat1c4d759e2017-04-09 16:34:54763 WebRuntimeFeatures::EnableTouchEventFeatureDetection(
sunyunjiafa6a8afc2016-12-09 04:25:47764 prefs.touch_event_feature_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54765 settings->SetMaxTouchPoints(prefs.pointer_events_max_touch_points);
766 settings->SetAvailablePointerTypes(prefs.available_pointer_types);
767 settings->SetPrimaryPointerType(
nzolghadrc0d1663c2015-11-26 21:15:24768 static_cast<blink::PointerType>(prefs.primary_pointer_type));
Blink Reformat1c4d759e2017-04-09 16:34:54769 settings->SetAvailableHoverTypes(prefs.available_hover_types);
770 settings->SetPrimaryHoverType(
nzolghadrc0d1663c2015-11-26 21:15:24771 static_cast<blink::HoverType>(prefs.primary_hover_type));
Blink Reformat1c4d759e2017-04-09 16:34:54772 settings->SetEnableTouchAdjustment(prefs.touch_adjustment_enabled);
Dave Tapuskaa59fdb62017-08-23 16:28:27773 settings->SetBarrelButtonForDragEnabled(prefs.barrel_button_for_drag_enabled);
[email protected]b3a97b52014-07-09 06:25:05774
Blink Reformat1c4d759e2017-04-09 16:34:54775 settings->SetShouldRespectImageOrientation(
[email protected]b3a97b52014-07-09 06:25:05776 prefs.should_respect_image_orientation);
777
Blink Reformat1c4d759e2017-04-09 16:34:54778 settings->SetEditingBehavior(
[email protected]b3a97b52014-07-09 06:25:05779 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
780
Blink Reformat1c4d759e2017-04-09 16:34:54781 settings->SetSupportsMultipleWindows(prefs.supports_multiple_windows);
[email protected]b3a97b52014-07-09 06:25:05782
Blink Reformat1c4d759e2017-04-09 16:34:54783 settings->SetMainFrameClipsContent(!prefs.record_whole_document);
khushalsagar2da2b232016-03-23 22:11:35784
Blink Reformat1c4d759e2017-04-09 16:34:54785 settings->SetSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
[email protected]b3a97b52014-07-09 06:25:05786
Blink Reformat1c4d759e2017-04-09 16:34:54787 settings->SetSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
[email protected]b3a97b52014-07-09 06:25:05788
Blink Reformat1c4d759e2017-04-09 16:34:54789 settings->SetSelectionIncludesAltImageText(true);
[email protected]b3a97b52014-07-09 06:25:05790
Blink Reformat1c4d759e2017-04-09 16:34:54791 settings->SetV8CacheOptions(
[email protected]35103c02014-08-12 15:08:47792 static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options));
793
Blink Reformat1c4d759e2017-04-09 16:34:54794 settings->SetImageAnimationPolicy(
je_julie.kim7fbb5a1a2015-02-09 17:26:05795 static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy));
796
Blink Reformat1c4d759e2017-04-09 16:34:54797 settings->SetPresentationRequiresUserGesture(
zqzhang1215ad422016-02-10 13:27:22798 prefs.user_gesture_required_for_presentation);
799
Blink Reformat1c4d759e2017-04-09 16:34:54800 settings->SetTextTrackMarginPercentage(prefs.text_track_margin_percentage);
halliwell4002be42016-03-18 18:33:40801
David Bokana03511a92018-09-13 04:25:24802 // Needs to happen before SetDefaultPageScaleLimits below since that'll
803 // recalculate the final page scale limits and that depends on this setting.
804 settings->SetShrinksViewportContentToFit(
805 prefs.shrinks_viewport_contents_to_fit);
806
807 // Needs to happen before SetIgnoreViewportTagScaleLimits below.
Blink Reformat1c4d759e2017-04-09 16:34:54808 web_view->SetDefaultPageScaleLimits(prefs.default_minimum_page_scale_factor,
809 prefs.default_maximum_page_scale_factor);
dcheng5ae8ca362015-02-05 04:03:47810
Nate Chapin9638e7102017-09-20 22:11:01811 settings->SetSavePreviousDocumentResources(
812 static_cast<WebSettings::SavePreviousDocumentResources>(
813 prefs.save_previous_document_resources));
814
Ahmed Fakhry42221452018-05-30 01:18:39815 settings->SetTextAutosizingEnabled(prefs.text_autosizing_enabled);
816 settings->SetDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
Tarun Bansald10f17a02018-09-13 00:23:17817 blink::WebNetworkStateNotifier::SetNetworkQualityWebHoldback(
818 static_cast<blink::WebEffectiveConnectionType>(
819 prefs.network_quality_estimator_web_holdback));
Ahmed Fakhry42221452018-05-30 01:18:39820
[email protected]b3a97b52014-07-09 06:25:05821#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:54822 settings->SetAllowCustomScrollbarInMainFrame(false);
Blink Reformat1c4d759e2017-04-09 16:34:54823 settings->SetAccessibilityFontScaleFactor(prefs.font_scale_factor);
824 settings->SetDeviceScaleAdjustment(prefs.device_scale_adjustment);
825 settings->SetFullscreenSupported(prefs.fullscreen_supported);
826 web_view->SetIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
827 settings->SetAutoZoomFocusedNodeToLegibleScale(true);
Peter Kotwicz2372030b2018-10-21 03:55:52828 settings->SetMediaPlaybackGestureWhitelistScope(blink::WebString::FromASCII(
829 prefs.media_playback_gesture_whitelist_scope.spec()));
Blink Reformat1c4d759e2017-04-09 16:34:54830 settings->SetDefaultVideoPosterURL(
831 WebString::FromASCII(prefs.default_video_poster_url.spec()));
832 settings->SetSupportDeprecatedTargetDensityDPI(
[email protected]b3a97b52014-07-09 06:25:05833 prefs.support_deprecated_target_density_dpi);
Blink Reformat1c4d759e2017-04-09 16:34:54834 settings->SetUseLegacyBackgroundSizeShorthandBehavior(
[email protected]b3a97b52014-07-09 06:25:05835 prefs.use_legacy_background_size_shorthand_behavior);
Blink Reformat1c4d759e2017-04-09 16:34:54836 settings->SetWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
837 settings->SetUseWideViewport(prefs.use_wide_viewport);
838 settings->SetForceZeroLayoutHeight(prefs.force_zero_layout_height);
839 settings->SetViewportMetaLayoutSizeQuirk(
[email protected]b3a97b52014-07-09 06:25:05840 prefs.viewport_meta_layout_size_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54841 settings->SetViewportMetaMergeContentQuirk(
[email protected]b3a97b52014-07-09 06:25:05842 prefs.viewport_meta_merge_content_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54843 settings->SetViewportMetaNonUserScalableQuirk(
[email protected]b3a97b52014-07-09 06:25:05844 prefs.viewport_meta_non_user_scalable_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54845 settings->SetViewportMetaZeroValuesQuirk(
[email protected]b3a97b52014-07-09 06:25:05846 prefs.viewport_meta_zero_values_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54847 settings->SetClobberUserAgentInitialScaleQuirk(
[email protected]b3a97b52014-07-09 06:25:05848 prefs.clobber_user_agent_initial_scale_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54849 settings->SetIgnoreMainFrameOverflowHiddenQuirk(
[email protected]b3a97b52014-07-09 06:25:05850 prefs.ignore_main_frame_overflow_hidden_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54851 settings->SetReportScreenSizeInPhysicalPixelsQuirk(
[email protected]b3a97b52014-07-09 06:25:05852 prefs.report_screen_size_in_physical_pixels_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54853 settings->SetShouldReuseGlobalForUnownedMainFrame(
tzik30eb52c2018-03-27 06:55:18854 prefs.reuse_global_for_unowned_main_frame);
Blink Reformat1c4d759e2017-04-09 16:34:54855 settings->SetPreferHiddenVolumeControls(true);
856 settings->SetSpellCheckEnabledByDefault(prefs.spellcheck_enabled_by_default);
dalecurtiscd971252016-09-21 16:09:00857
aeliase678aa42017-04-14 22:41:04858 // Force preload=none and disable autoplay on older Android
dalecurtiscd971252016-09-21 16:09:00859 // platforms because their media pipelines are not stable enough to handle
860 // concurrent elements. See http://crbug.com/612909, http://crbug.com/622826.
aeliase678aa42017-04-14 22:41:04861 const bool is_jelly_bean =
dalecurtiscd971252016-09-21 16:09:00862 base::android::BuildInfo::GetInstance()->sdk_int() <=
aeliase678aa42017-04-14 22:41:04863 base::android::SDK_VERSION_JELLY_BEAN_MR2;
864 settings->SetForcePreloadNoneForMediaElements(is_jelly_bean);
mlamouri1d266bf2016-12-05 17:42:36865
Blink Reformat1c4d759e2017-04-09 16:34:54866 WebRuntimeFeatures::EnableVideoFullscreenOrientationLock(
mlamouri1d266bf2016-12-05 17:42:36867 prefs.video_fullscreen_orientation_lock_enabled);
johnme913ee5f2017-04-28 21:36:16868 WebRuntimeFeatures::EnableVideoRotateToFullscreen(
869 prefs.video_rotate_to_fullscreen_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54870 WebRuntimeFeatures::EnableVideoFullscreenDetection(
zqzhang93e959d12017-03-16 13:10:20871 prefs.video_fullscreen_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54872 settings->SetEmbeddedMediaExperienceEnabled(
shaktisahuf97f7532017-02-24 22:46:13873 prefs.embedded_media_experience_enabled);
Ian Vollickeeca1d82018-02-07 02:43:42874 settings->SetImmersiveModeEnabled(prefs.immersive_mode_enabled);
khushalsagarc5447db22017-08-22 17:53:01875 settings->SetMediaDownloadInProductHelpEnabled(
876 prefs.enable_media_download_in_product_help);
Blink Reformat1c4d759e2017-04-09 16:34:54877 settings->SetDoNotUpdateSelectionOnMutatingSelectionRange(
changwane54ccdb92017-04-05 19:20:54878 prefs.do_not_update_selection_on_mutating_selection_range);
Noel Gordonf311a842017-07-27 00:10:07879 WebRuntimeFeatures::EnableCSSHexAlphaColor(prefs.css_hex_alpha_color_enabled);
Tobias Sargeant416174f2017-09-01 01:18:09880 WebRuntimeFeatures::EnableScrollTopLeftInterop(
881 prefs.scroll_top_left_interop_enabled);
zqzhangdf72ed082016-12-08 16:07:55882#endif // defined(OS_ANDROID)
liberato9e934892016-05-03 19:00:27883
mlamouri55a0543c2017-05-11 10:34:07884 switch (prefs.autoplay_policy) {
885 case AutoplayPolicy::kNoUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28886 settings->SetAutoplayPolicy(
887 WebSettings::AutoplayPolicy::kNoUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07888 break;
889 case AutoplayPolicy::kUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28890 settings->SetAutoplayPolicy(
891 WebSettings::AutoplayPolicy::kUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07892 break;
893 case AutoplayPolicy::kUserGestureRequiredForCrossOrigin:
mlamouri276a6f32017-05-12 09:24:28894 settings->SetAutoplayPolicy(
895 WebSettings::AutoplayPolicy::kUserGestureRequiredForCrossOrigin);
mlamouri55a0543c2017-05-11 10:34:07896 break;
mlamouri431bb4e2017-06-06 08:54:24897 case AutoplayPolicy::kDocumentUserActivationRequired:
898 settings->SetAutoplayPolicy(
899 WebSettings::AutoplayPolicy::kDocumentUserActivationRequired);
900 break;
mlamouri55a0543c2017-05-11 10:34:07901 }
902
Blink Reformat1c4d759e2017-04-09 16:34:54903 settings->SetViewportEnabled(prefs.viewport_enabled);
904 settings->SetViewportMetaEnabled(prefs.viewport_meta_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54905 settings->SetViewportStyle(
alokp5d566962016-04-19 00:54:16906 static_cast<blink::WebViewportStyle>(prefs.viewport_style));
907
Blink Reformat1c4d759e2017-04-09 16:34:54908 settings->SetLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
909 settings->SetMainFrameResizesAreOrientationChanges(
yoava1a508b42015-10-20 12:03:21910 prefs.main_frame_resizes_are_orientation_changes);
911
Blink Reformat1c4d759e2017-04-09 16:34:54912 settings->SetUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
jinho.bang8f11ffa2014-12-04 06:03:03913
Blink Reformat1c4d759e2017-04-09 16:34:54914 settings->SetShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up);
915 settings->SetAlwaysShowContextMenuOnTouch(
amaralp547e4192016-06-03 19:17:35916 prefs.always_show_context_menu_on_touch);
Sandra Sunc79fc93a2018-04-10 15:22:23917 settings->SetSmoothScrollForFindEnabled(prefs.smooth_scroll_for_find_enabled);
ccameron2fd70de72015-02-19 00:40:40918
Blink Reformat1c4d759e2017-04-09 16:34:54919 settings->SetHideDownloadUI(prefs.hide_download_ui);
avayvod232757942017-04-29 04:12:34920 WebRuntimeFeatures::EnableNewRemotePlaybackPipeline(
921 base::FeatureList::IsEnabled(media::kNewRemotePlaybackPipeline));
qinmin72e8bd02016-10-21 19:35:37922
Blink Reformat1c4d759e2017-04-09 16:34:54923 settings->SetPresentationReceiver(prefs.presentation_receiver);
mlamouri57359d912016-11-29 20:11:50924
Blink Reformat1c4d759e2017-04-09 16:34:54925 settings->SetMediaControlsEnabled(prefs.media_controls_enabled);
mlamouri5cd9ae82017-02-18 11:05:09926
Tarun Bansal73d67f02018-01-17 05:56:25927 settings->SetLowPriorityIframesThreshold(
928 static_cast<blink::WebEffectiveConnectionType>(
929 prefs.low_priority_iframes_threshold));
930
Mounir Lamouri9c99a1602018-07-05 15:01:44931 settings->SetPictureInPictureEnabled(
932 prefs.picture_in_picture_enabled &&
[email protected]69db58f2018-09-26 20:27:56933 MediaFactory::GetVideoSurfaceLayerMode() !=
CJ DiMeglio89240472018-10-18 18:21:10934 blink::WebMediaPlayer::SurfaceLayerMode::kNever);
François Beaufort8c08979fc2018-03-05 13:06:31935
Tarun Bansal333819e2018-05-15 16:38:42936 settings->SetDataSaverHoldbackWebApi(
937 prefs.data_saver_holdback_web_api_enabled);
938 settings->SetDataSaverHoldbackMediaApi(
939 prefs.data_saver_holdback_media_api_enabled);
940
Scott Little878f7d6702018-05-31 22:09:06941 for (const auto& ect_distance_pair :
942 prefs.lazy_frame_loading_distance_thresholds_px) {
943 switch (ect_distance_pair.first) {
944 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
945 settings->SetLazyFrameLoadingDistanceThresholdPxUnknown(
946 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39947 continue;
Scott Little878f7d6702018-05-31 22:09:06948 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
949 settings->SetLazyFrameLoadingDistanceThresholdPxOffline(
950 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39951 continue;
Scott Little878f7d6702018-05-31 22:09:06952 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
953 settings->SetLazyFrameLoadingDistanceThresholdPxSlow2G(
954 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39955 continue;
Scott Little878f7d6702018-05-31 22:09:06956 case net::EFFECTIVE_CONNECTION_TYPE_2G:
957 settings->SetLazyFrameLoadingDistanceThresholdPx2G(
958 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39959 continue;
Scott Little878f7d6702018-05-31 22:09:06960 case net::EFFECTIVE_CONNECTION_TYPE_3G:
961 settings->SetLazyFrameLoadingDistanceThresholdPx3G(
962 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39963 continue;
Scott Little878f7d6702018-05-31 22:09:06964 case net::EFFECTIVE_CONNECTION_TYPE_4G:
965 settings->SetLazyFrameLoadingDistanceThresholdPx4G(
966 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39967 continue;
968 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
969 continue;
Scott Little878f7d6702018-05-31 22:09:06970 }
rajendrantd8026342018-08-29 08:08:39971 NOTREACHED();
972 }
973
974 for (const auto& ect_distance_pair :
975 prefs.lazy_image_loading_distance_thresholds_px) {
976 switch (ect_distance_pair.first) {
977 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
978 settings->SetLazyImageLoadingDistanceThresholdPxUnknown(
979 ect_distance_pair.second);
980 continue;
981 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
982 settings->SetLazyImageLoadingDistanceThresholdPxOffline(
983 ect_distance_pair.second);
984 continue;
985 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
986 settings->SetLazyImageLoadingDistanceThresholdPxSlow2G(
987 ect_distance_pair.second);
988 continue;
989 case net::EFFECTIVE_CONNECTION_TYPE_2G:
990 settings->SetLazyImageLoadingDistanceThresholdPx2G(
991 ect_distance_pair.second);
992 continue;
993 case net::EFFECTIVE_CONNECTION_TYPE_3G:
994 settings->SetLazyImageLoadingDistanceThresholdPx3G(
995 ect_distance_pair.second);
996 continue;
997 case net::EFFECTIVE_CONNECTION_TYPE_4G:
998 settings->SetLazyImageLoadingDistanceThresholdPx4G(
999 ect_distance_pair.second);
1000 continue;
1001 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
1002 continue;
1003 }
1004 NOTREACHED();
Scott Little878f7d6702018-05-31 22:09:061005 }
1006
ccameron2fd70de72015-02-19 00:40:401007#if defined(OS_MACOSX)
Blink Reformat1c4d759e2017-04-09 16:34:541008 web_view->SetMaximumLegibleScale(prefs.default_maximum_page_scale_factor);
ccameron2fd70de72015-02-19 00:40:401009#endif
sunyunjia87f287b2016-09-09 00:38:131010
1011#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:541012 WebRuntimeFeatures::EnableMiddleClickAutoscroll(true);
sunyunjia87f287b2016-09-09 00:38:131013#endif
Dave Tapuskac6627e12018-08-30 15:07:191014
1015 // Only enable href translate if we have the experimental web platform
1016 // flag on and the translation service is available.
1017 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1018 switches::kEnableExperimentalWebPlatformFeatures)) {
1019 WebRuntimeFeatures::EnableHrefTranslate(prefs.translate_service_available);
1020 }
[email protected]b3a97b52014-07-09 06:25:051021}
1022
1023/*static*/
nickf7b38222016-11-22 21:59:351024RenderViewImpl* RenderViewImpl::Create(
1025 CompositorDependencies* compositor_deps,
Balazs Engedyba034e72017-10-27 22:26:281026 mojom::CreateViewParamsPtr params,
danakjdf1ceb72018-07-18 20:02:251027 RenderWidget::ShowCallback show_callback,
Hajime Hoshiabb3c8f2017-12-04 18:41:391028 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Balazs Engedyba034e72017-10-27 22:26:281029 DCHECK(params->view_id != MSG_ROUTING_NONE);
Albert J. Wongcb004632018-07-10 22:58:251030 DCHECK(params->main_frame_widget_routing_id != MSG_ROUTING_NONE);
Lei Zhang88f23ba2017-10-27 05:56:261031 RenderViewImpl* render_view;
[email protected]8d41d7612012-11-14 20:32:191032 if (g_create_render_view_impl)
Balazs Engedyba034e72017-10-27 22:26:281033 render_view = g_create_render_view_impl(compositor_deps, *params);
[email protected]075366912013-02-18 07:13:241034 else
Hajime Hoshi315a61f2018-08-14 17:27:281035 render_view = new RenderViewImpl(compositor_deps, *params);
[email protected]0287e762014-04-11 13:07:581036
danakjdf1ceb72018-07-18 20:02:251037 render_view->Initialize(std::move(params), std::move(show_callback),
Hajime Hoshif34374412018-03-05 14:32:541038 std::move(task_runner));
[email protected]075366912013-02-18 07:13:241039 return render_view;
[email protected]8d41d7612012-11-14 20:32:191040}
1041
1042// static
dcheng35d31c112015-07-22 00:17:361043void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
1044 *create_render_view_impl)(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:151045 const mojom::CreateViewParams&)) {
[email protected]8d41d7612012-11-14 20:32:191046 CHECK(!g_create_render_view_impl);
1047 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291048}
1049
[email protected]310ebd6302011-10-10 19:06:281050void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511051 observers_.AddObserver(observer);
1052}
1053
[email protected]310ebd6302011-10-10 19:06:281054void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1055 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511056 observers_.RemoveObserver(observer);
1057}
1058
Peter Kastinga4a3ed12018-01-31 04:07:591059blink::WebView* RenderViewImpl::webview() {
1060 return webview_;
1061}
1062
1063const blink::WebView* RenderViewImpl::webview() const {
lfg4fa48da2016-05-09 18:25:131064 return webview_;
[email protected]4d51d5bf2010-07-26 18:48:261065}
1066
danakja2c9d0a92018-07-25 20:01:181067// RenderWidgetOwnerDelegate -----------------------------------------
fsamuel72464894f2015-12-15 06:59:311068
danakja2c9d0a92018-07-25 20:01:181069blink::WebWidget* RenderViewImpl::GetWebWidgetForWidget() const {
1070 return frame_widget_;
1071}
1072
1073bool RenderViewImpl::RenderWidgetWillHandleMouseEventForWidget(
avid7d6b2e2016-03-04 19:41:171074 const blink::WebMouseEvent& event) {
fsamuel72464894f2015-12-15 06:59:311075 // If the mouse is locked, only the current owner of the mouse lock can
1076 // process mouse events.
danakja2c9d0a92018-07-25 20:01:181077 return GetWidget()->mouse_lock_dispatcher()->WillHandleMouseEvent(event);
fsamuel72464894f2015-12-15 06:59:311078}
1079
danakja2c9d0a92018-07-25 20:01:181080void RenderViewImpl::SetActiveForWidget(bool active) {
Albert J. Wongcb004632018-07-10 22:58:251081 if (webview())
1082 webview()->SetIsActive(active);
1083}
1084
danakja2c9d0a92018-07-25 20:01:181085bool RenderViewImpl::SupportsMultipleWindowsForWidget() {
1086 return webkit_preferences_.supports_multiple_windows;
1087}
1088
1089void RenderViewImpl::DidHandleGestureEventForWidget(
1090 const WebGestureEvent& event) {
1091 for (auto& observer : observers_)
1092 observer.DidHandleGestureEvent(event);
1093}
1094
1095void RenderViewImpl::OverrideCloseForWidget() {
1096 DCHECK(frame_widget_);
1097 frame_widget_->Close();
1098 frame_widget_ = nullptr;
1099}
1100
1101void RenderViewImpl::DidCloseWidget() {
1102 // The webview_ is already destroyed by the time we get here, remove any
1103 // references to it.
1104 g_view_map.Get().erase(webview_);
1105 webview_ = nullptr;
1106 g_routing_id_view_map.Get().erase(GetRoutingID());
danakja2c9d0a92018-07-25 20:01:181107}
1108
1109void RenderViewImpl::ApplyNewSizeForWidget(const gfx::Size& old_size,
1110 const gfx::Size& new_size) {
danakj1ab8faf2018-10-12 18:24:281111 if (new_size != old_size) {
danakja2c9d0a92018-07-25 20:01:181112 // Only hide popups when the size changes. There are situations (e.g. hiding
1113 // the ChromeOS virtual keyboard) where we send a resize message with no
1114 // change in size, but we don't want to close popups.
1115 // See https://crbug.com/761908.
danakje26bef02018-10-12 17:21:241116 webview()->HidePopups();
danakja2c9d0a92018-07-25 20:01:181117 }
1118}
1119
1120void RenderViewImpl::ApplyNewDisplayModeForWidget(
1121 const blink::WebDisplayMode& new_display_mode) {
danakj1ab8faf2018-10-12 18:24:281122 webview()->SetDisplayMode(new_display_mode);
danakja2c9d0a92018-07-25 20:01:181123}
1124
1125void RenderViewImpl::ApplyAutoResizeLimitsForWidget(const gfx::Size& min_size,
1126 const gfx::Size& max_size) {
1127 webview()->EnableAutoResizeMode(min_size, max_size);
1128}
1129
1130void RenderViewImpl::DisableAutoResizeForWidget() {
1131 webview()->DisableAutoResizeMode();
1132}
1133
1134void RenderViewImpl::ScrollFocusedNodeIntoViewForWidget() {
1135 if (WebLocalFrame* focused_frame = GetWebView()->FocusedFrame()) {
1136 auto* frame_widget = focused_frame->LocalRoot()->FrameWidget();
1137 frame_widget->ScrollFocusedEditableElementIntoView();
1138 }
1139}
1140
1141void RenderViewImpl::DidReceiveSetFocusEventForWidget() {
1142 // This message must always be received when the main frame is a
1143 // WebLocalFrame.
1144 // TODO(ajwong): Can this be removed and just check |owner_delegate_| in
1145 // RenderWidget instead?
1146 CHECK(webview()->MainFrame()->IsWebLocalFrame());
1147}
1148
1149void RenderViewImpl::DidChangeFocusForWidget() {
1150 // Notify all BrowserPlugins of the RenderView's focus state.
1151 if (BrowserPluginManager::Get())
1152 BrowserPluginManager::Get()->UpdateFocusState();
1153}
1154
danakja2c9d0a92018-07-25 20:01:181155void RenderViewImpl::DidCommitCompositorFrameForWidget() {
1156 for (auto& observer : observers_)
1157 observer.DidCommitCompositorFrame();
Philip Rogers33cd2bcc2018-08-13 21:29:291158 UpdatePreferredSize();
danakja2c9d0a92018-07-25 20:01:181159}
1160
1161void RenderViewImpl::DidCompletePageScaleAnimationForWidget() {
1162 if (auto* focused_frame = GetWebView()->FocusedFrame()) {
1163 if (focused_frame->AutofillClient())
1164 focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame();
1165 }
1166}
1167
1168void RenderViewImpl::ResizeWebWidgetForWidget(
1169 const gfx::Size& size,
1170 float top_controls_height,
1171 float bottom_controls_height,
1172 bool browser_controls_shrink_blink_size) {
1173 webview()->ResizeWithBrowserControls(size, top_controls_height,
1174 bottom_controls_height,
1175 browser_controls_shrink_blink_size);
1176}
1177
1178void RenderViewImpl::RequestScheduleAnimationForWidget() {
1179 // Schedule the animation on the WidgetClient() which may not be the
1180 // RenderWidget directly in layout tests.
1181 WidgetClient()->ScheduleAnimation();
1182}
1183
1184void RenderViewImpl::SetScreenMetricsEmulationParametersForWidget(
1185 bool enabled,
1186 const blink::WebDeviceEmulationParams& params) {
danakj1ab8faf2018-10-12 18:24:281187 if (enabled)
1188 webview()->EnableDeviceEmulation(params);
1189 else
1190 webview()->DisableDeviceEmulation();
danakja2c9d0a92018-07-25 20:01:181191}
1192
1193// IPC message handlers -----------------------------------------
1194
danakja2c9d0a92018-07-25 20:01:181195void RenderViewImpl::OnUpdateTargetURLAck() {
1196 // Check if there is a targeturl waiting to be sent.
1197 if (target_url_status_ == TARGET_PENDING)
1198 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), pending_target_url_));
1199
1200 target_url_status_ = TARGET_NONE;
1201}
1202
1203void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset,
1204 int history_length) {
1205 // -1 <= history_offset < history_length <= kMaxSessionHistoryEntries(50).
1206 DCHECK_LE(-1, history_offset);
1207 DCHECK_LT(history_offset, history_length);
1208 DCHECK_LE(history_length, kMaxSessionHistoryEntries);
1209
1210 history_list_offset_ = history_offset;
1211 history_list_length_ = history_length;
1212}
1213
1214void RenderViewImpl::OnSetInitialFocus(bool reverse) {
1215 if (!webview())
1216 return;
1217 webview()->SetInitialFocus(reverse);
1218}
1219
1220void RenderViewImpl::OnUpdateWindowScreenRect(gfx::Rect window_screen_rect) {
1221 // Defers to the RenderWidget message handler.
danakj53802692018-07-25 21:46:441222 GetWidget()->SetWindowScreenRect(window_screen_rect);
danakja2c9d0a92018-07-25 20:01:181223}
1224
1225void RenderViewImpl::OnAudioStateChanged(bool is_audio_playing) {
1226 webview()->AudioStateChanged(is_audio_playing);
1227}
1228
1229void RenderViewImpl::OnPausePageScheduledTasks(bool paused) {
1230 webview()->PausePageScheduledTasks(paused);
1231}
1232
1233///////////////////////////////////////////////////////////////////////////////
1234
1235void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget,
1236 WebNavigationPolicy policy,
1237 const gfx::Rect& initial_rect) {
1238 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(),
1239 initial_rect));
1240}
1241
1242void RenderViewImpl::ShowCreatedFullscreenWidget(
1243 RenderWidget* fullscreen_widget,
1244 WebNavigationPolicy policy,
1245 const gfx::Rect& initial_rect) {
1246 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(),
1247 fullscreen_widget->routing_id()));
1248}
1249
1250void RenderViewImpl::SendFrameStateUpdates() {
1251 // Tell each frame with pending state to send its UpdateState message.
1252 for (int render_frame_routing_id : frames_with_pending_state_) {
1253 RenderFrameImpl* frame =
1254 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
1255 if (frame)
1256 frame->SendUpdateState();
1257 }
1258 frames_with_pending_state_.clear();
1259}
1260
danakja2c9d0a92018-07-25 20:01:181261// IPC::Listener -------------------------------------------------------------
fsamuel72464894f2015-12-15 06:59:311262
[email protected]310ebd6302011-10-10 19:06:281263bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281264 WebFrame* main_frame = webview() ? webview()->MainFrame() : nullptr;
Avi Drissmanb5f8e242017-12-12 05:21:561265 if (main_frame) {
1266 GURL active_url;
1267 if (main_frame->IsWebLocalFrame())
1268 active_url = main_frame->ToWebLocalFrame()->GetDocument().Url();
lukaszabedb4b22017-06-23 00:00:131269 GetContentClient()->SetActiveURL(
Avi Drissmanb5f8e242017-12-12 05:21:561270 active_url, main_frame->Top()->GetSecurityOrigin().ToString().Utf8());
1271 }
[email protected]f8b6b6f2009-03-10 16:48:261272
dchenga2d442c22016-10-13 15:39:211273 for (auto& observer : observers_) {
1274 if (observer.OnMessageReceived(message))
[email protected]676126f72011-01-15 00:03:511275 return true;
dchenga2d442c22016-10-13 15:39:211276 }
[email protected]b2abac72009-02-26 12:39:281277
[email protected]a95986a82010-12-24 06:19:281278 bool handled = true;
[email protected]e44d1342014-05-16 21:29:331279 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
mcnee432e47d2015-11-09 19:37:461280 IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale)
initial.commit09911bf2008-07-26 23:55:291281 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291282 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1283 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]600ea402011-04-12 00:01:511284 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
1285 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:291286 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
[email protected]30f75e62009-02-25 22:01:001287 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]ab32b16c2009-10-16 14:57:251288 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1289 OnEnablePreferredSizeChangedMode)
[email protected]80d96fa2009-06-10 22:34:511290 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]81375e872012-01-11 21:40:361291 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
wjmaclean64951902016-04-29 20:59:121292
1293 // Page messages.
lfgdb5c4ed2016-03-04 23:09:071294 IPC_MESSAGE_HANDLER(PageMsg_UpdateWindowScreenRect,
1295 OnUpdateWindowScreenRect)
lfg717154072016-06-30 15:04:161296 IPC_MESSAGE_HANDLER(PageMsg_WasHidden, OnPageWasHidden)
1297 IPC_MESSAGE_HANDLER(PageMsg_WasShown, OnPageWasShown)
alexmos136fd6e62016-08-15 20:58:411298 IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength,
1299 OnSetHistoryOffsetAndLength)
altimind8bd26c2016-11-04 11:44:541300 IPC_MESSAGE_HANDLER(PageMsg_AudioStateChanged, OnAudioStateChanged)
Gyuyoung Kim80143f5e2018-04-02 02:40:251301 IPC_MESSAGE_HANDLER(PageMsg_PausePageScheduledTasks,
1302 OnPausePageScheduledTasks)
lfg8d649cc2017-04-28 18:04:301303 IPC_MESSAGE_HANDLER(PageMsg_UpdateScreenInfo, OnUpdateScreenInfo)
Francois Doray47f759d2018-06-11 18:13:511304 IPC_MESSAGE_HANDLER(PageMsg_SetPageFrozen, SetPageFrozen)
lfg717154072016-06-30 15:04:161305
[email protected]a794f3a2013-10-30 17:00:321306 // Adding a new message? Add platform independent ones first, then put the
1307 // platform specific ones at the end.
[email protected]9e1ad4b2011-08-14 16:49:191308
initial.commit09911bf2008-07-26 23:55:291309 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281310 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291311 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401312
[email protected]a95986a82010-12-24 06:19:281313 return handled;
initial.commit09911bf2008-07-26 23:55:291314}
1315
[email protected]180ef242013-11-07 06:50:461316// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521317
Mustaq Ahmed55944cb2018-05-25 20:44:271318// TODO(csharrison): Migrate this method to WebLocalFrameClient /
1319// RenderFrameImpl, as it is now serviced by a mojo interface scoped to the
1320// opener frame.
Daniel Murphyc8e991a2018-10-12 22:09:031321WebView* RenderViewImpl::CreateView(
1322 WebLocalFrame* creator,
1323 const WebURLRequest& request,
1324 const WebWindowFeatures& features,
1325 const WebString& frame_name,
1326 WebNavigationPolicy policy,
1327 bool suppress_opener,
1328 WebSandboxFlags sandbox_flags,
1329 const blink::SessionStorageNamespaceId& session_storage_namespace_id) {
nick5ae4d2d2017-01-06 01:18:351330 RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator);
rockot5c478a72016-09-28 23:14:181331 mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New();
Mustaq Ahmedc4cb7162018-06-05 16:28:361332
1333 // User Activation v2 moves user gesture checks to the browser process, with
1334 // the exception of the extensions case handled through the following |if|.
1335 params->mimic_user_gesture =
1336 base::FeatureList::IsEnabled(features::kUserActivationV2)
1337 ? false
1338 : WebUserGestureIndicator::IsProcessingUserGesture(creator);
[email protected]00323f02013-07-24 15:47:411339 if (GetContentClient()->renderer()->AllowPopup())
Mustaq Ahmedc4cb7162018-06-05 16:28:361340 params->mimic_user_gesture = true;
1341
rockot5c478a72016-09-28 23:14:181342 params->window_container_type = WindowFeaturesToContainerType(features);
Daniel Murphye3eec92c2018-02-23 19:09:151343
Daniel Murphyc8e991a2018-10-12 22:09:031344 params->session_storage_namespace_id = session_storage_namespace_id;
1345 // TODO(dmurph): Don't copy session storage when features.noopener is true:
1346 // https://html.spec.whatwg.org/multipage/browsers.html#copy-session-storage
1347 // https://crbug.com/771959
Daniel Murphye3eec92c2018-02-23 19:09:151348 params->clone_from_session_storage_namespace_id =
1349 session_storage_namespace_id_;
Daniel Murphye3eec92c2018-02-23 19:09:151350
Daniel Chengd5e56ff2017-06-24 07:44:021351 const std::string& frame_name_utf8 = frame_name.Utf8(
1352 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
1353 params->frame_name = frame_name_utf8;
rockot5c478a72016-09-28 23:14:181354 params->opener_suppressed = suppress_opener;
1355 params->disposition = NavigationPolicyToDisposition(policy);
Blink Reformat1c4d759e2017-04-09 16:34:541356 if (!request.IsNull()) {
1357 params->target_url = request.Url();
rockot5c478a72016-09-28 23:14:181358 params->referrer = GetReferrerFromRequest(creator, request);
[email protected]44e55b012013-07-23 14:21:561359 }
scottmg8e6c6082017-02-13 23:15:481360 params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
[email protected]8ab04652010-06-12 02:47:261361
rockot5c478a72016-09-28 23:14:181362 // We preserve this information before sending the message since |params| is
1363 // moved on send.
1364 bool is_background_tab =
1365 params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB;
Mustaq Ahmedc4cb7162018-06-05 16:28:361366 bool opened_by_user_gesture = params->mimic_user_gesture;
[email protected]22217ed32013-11-18 18:40:231367
Daniel Cheng8bb30c62017-10-23 20:40:471368 mojom::CreateNewWindowStatus status;
rockot5c478a72016-09-28 23:14:181369 mojom::CreateNewWindowReplyPtr reply;
Balazs Engedya40712f2017-09-15 15:01:111370 auto* frame_host = creator_frame->GetFrameHost();
Daniel Cheng8bb30c62017-10-23 20:40:471371 bool err = !frame_host->CreateNewWindow(std::move(params), &status, &reply);
1372 if (err || status == mojom::CreateNewWindowStatus::kIgnore)
rockot5c478a72016-09-28 23:14:181373 return nullptr;
[email protected]48c9cf2d2009-09-16 16:47:521374
Jochen Eisinger515337a2017-05-26 14:12:521375 // For Android WebView, we support a pop-up like behavior for window.open()
1376 // even if the embedding app doesn't support multiple windows. In this case,
1377 // window.open() will return "window" and navigate it to whatever URL was
Jochen Eisinger8cb28492017-10-04 10:58:131378 // passed. We also don't need to consume user gestures to protect against
1379 // multiple windows being opened, because, well, the app doesn't support
1380 // multiple windows.
Daniel Cheng8bb30c62017-10-23 20:40:471381 // TODO(dcheng): It's awkward that this is plumbed into Blink but not really
1382 // used much in Blink, except to enable layout testing... perhaps this should
1383 // be checked directly in the browser side.
1384 if (status == mojom::CreateNewWindowStatus::kReuse)
Jochen Eisinger515337a2017-05-26 14:12:521385 return webview();
1386
Daniel Cheng8bb30c62017-10-23 20:40:471387 DCHECK(reply);
1388 DCHECK_NE(MSG_ROUTING_NONE, reply->route_id);
1389 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_route_id);
1390 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_widget_route_id);
1391
Mustaq Ahmed76c2f4312018-06-07 20:48:011392 // The browser allowed creation of a new window and consumed the user
1393 // activation (UAv2 only).
1394 WebUserGestureIndicator::ConsumeUserGesture(
1395 creator, blink::UserActivationUpdateSource::kBrowser);
Jochen Eisinger8cb28492017-10-04 10:58:131396
[email protected]7912e822014-04-16 02:37:031397 // While this view may be a background extension page, it can spawn a visible
1398 // render view. So we just assume that the new one is not another background
1399 // page instead of passing on our own value.
1400 // TODO(vangelis): Can we tell if the new view will be a background page?
1401 bool never_visible = false;
[email protected]9115d5f2013-03-24 04:37:411402
Fady Samuelff5b6eb562018-05-01 16:16:081403 VisualProperties visual_properties = VisualProperties();
danakj53802692018-07-25 21:46:441404 visual_properties.screen_info = GetWidget()->screen_info();
mkosiba58fa72f02014-11-12 01:21:361405
[email protected]d6fa88f2013-10-18 16:00:431406 // The initial hidden state for the RenderViewImpl here has to match what the
1407 // browser will eventually decide for the given disposition. Since we have to
1408 // return from this call synchronously, we just have to make our best guess
1409 // and rely on the browser sending a WasHidden / WasShown message if it
1410 // disagrees.
Balazs Engedyba034e72017-10-27 22:26:281411 mojom::CreateViewParamsPtr view_params = mojom::CreateViewParams::New();
alexmos5ac402d2015-07-09 07:51:101412
Balazs Engedyba034e72017-10-27 22:26:281413 view_params->opener_frame_route_id = creator_frame->GetRoutingID();
avia3dca182016-03-19 01:09:521414 DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID());
alexmos5ac402d2015-07-09 07:51:101415
Balazs Engedyba034e72017-10-27 22:26:281416 view_params->window_was_created_with_opener = true;
1417 view_params->renderer_preferences = renderer_preferences_;
1418 view_params->web_preferences = webkit_preferences_;
1419 view_params->view_id = reply->route_id;
1420 view_params->main_frame_routing_id = reply->main_frame_route_id;
1421 view_params->main_frame_interface_provider =
1422 std::move(reply->main_frame_interface_provider);
1423 view_params->main_frame_widget_routing_id = reply->main_frame_widget_route_id;
1424 view_params->session_storage_namespace_id =
rockot5c478a72016-09-28 23:14:181425 reply->cloned_session_storage_namespace_id;
Daniel Murphy95792ef2018-10-04 01:29:551426 DCHECK(!view_params->session_storage_namespace_id.empty())
1427 << "Session storage namespace must be populated.";
Balazs Engedyba034e72017-10-27 22:26:281428 view_params->swapped_out = false;
1429 view_params->replicated_frame_state.frame_policy.sandbox_flags =
1430 sandbox_flags;
1431 view_params->replicated_frame_state.name = frame_name_utf8;
1432 view_params->devtools_main_frame_token = reply->devtools_main_frame_token;
Daniel Chengd5e56ff2017-06-24 07:44:021433 // Even if the main frame has a name, the main frame's unique name is always
1434 // the empty string.
Balazs Engedyba034e72017-10-27 22:26:281435 view_params->hidden = is_background_tab;
1436 view_params->never_visible = never_visible;
Fady Samuelff5b6eb562018-05-01 16:16:081437 view_params->visual_properties = visual_properties;
naskobd911332014-11-25 01:13:361438
nick5ae4d2d2017-01-06 01:18:351439 // Unretained() is safe here because our calling function will also call
1440 // show().
nickf7b38222016-11-22 21:59:351441 RenderWidget::ShowCallback show_callback =
danakjdf1ceb72018-07-18 20:02:251442 base::BindOnce(&RenderFrameImpl::ShowCreatedWindow,
1443 base::Unretained(creator_frame), opened_by_user_gesture);
nickf7b38222016-11-22 21:59:351444
Balazs Engedyba034e72017-10-27 22:26:281445 RenderViewImpl* view = RenderViewImpl::Create(
danakj53802692018-07-25 21:46:441446 GetWidget()->compositor_deps(), std::move(view_params),
1447 std::move(show_callback),
Hajime Hoshi6fc91142018-05-11 08:21:171448 creator->GetTaskRunner(blink::TaskType::kInternalDefault));
[email protected]48c9cf2d2009-09-16 16:47:521449
[email protected]48c9cf2d2009-09-16 16:47:521450 return view->webview();
1451}
1452
danakj829cdd142018-09-14 21:13:271453WebWidget* RenderViewImpl::CreatePopup(blink::WebLocalFrame* creator) {
danakj25ec6e2b2018-09-26 17:01:311454 mojom::WidgetPtr widget_channel;
1455 mojom::WidgetRequest widget_channel_request =
1456 mojo::MakeRequest(&widget_channel);
1457
1458 // Do a synchronous IPC to obtain a routing ID.
1459 int32_t widget_routing_id = MSG_ROUTING_NONE;
1460 bool success =
1461 RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
1462 GetRoutingID(), std::move(widget_channel), &widget_routing_id);
1463 if (!success) {
1464 // When the renderer is being killed the mojo message will fail.
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281465 return nullptr;
danakj25ec6e2b2018-09-26 17:01:311466 }
1467
1468 RenderWidget::ShowCallback opener_callback = base::BindOnce(
1469 &RenderViewImpl::ShowCreatedPopupWidget, weak_ptr_factory_.GetWeakPtr());
1470
1471 // The RenderWidget associated with the RenderView. This should be the
1472 // RenderWidget for the main frame, but may be a zombie RenderWidget when
1473 // the main frame is remote (we don't need a RenderWidget for it then).
1474 // However for now (https://crbug.com/419087) we know it exists and grab
1475 // state off it for the popup.
1476 // TODO(crbug.com/419087): This should probably be using the local root's
1477 // RenderWidget for the frame making the popup.
1478 RenderWidget* view_render_widget = GetWidget();
1479
1480 auto popup_widget = base::MakeRefCounted<RenderWidget>(
1481 widget_routing_id, view_render_widget->compositor_deps(),
1482 WidgetType::kPopup, view_render_widget->screen_info(),
1483 blink::kWebDisplayModeUndefined,
1484 /*swapped_out=*/false,
1485 /*hidden=*/false,
1486 /*never_visible=*/false, std::move(widget_channel_request));
1487
1488 // The returned WebPagePopup is self-referencing, so the pointer here is not
1489 // an owning pointer.
1490 blink::WebPagePopup* popup_web_widget =
1491 blink::WebPagePopup::Create(popup_widget.get());
1492
1493 // Adds a self-reference on the |popup_widget| so it will not be destroyed
1494 // when leaving scope. The WebPagePopup takes responsibility for Close()ing
1495 // and thus destroying the RenderWidget.
1496 popup_widget->InitForPopup(std::move(opener_callback), popup_web_widget);
1497 // TODO(crbug.com/419087): RenderWidget has some weird logic for picking a
1498 // WebWidget which doesn't apply to this case. So we verify. This can go away
1499 // when RenderWidget::GetWebWidget() is just a simple accessor.
1500 DCHECK_EQ(popup_widget->GetWebWidget(), popup_web_widget);
1501
1502 // Devtools emulation, which may be currently applied to the
1503 // |view_render_widget|, should also apply to the new popup. This doesn't
1504 // happen automatically.
1505 popup_widget->ApplyEmulatedScreenMetricsForPopupWidget(view_render_widget);
1506
1507 return popup_web_widget;
[email protected]48c9cf2d2009-09-16 16:47:521508}
1509
Daniel Murphy31bbb8b12018-02-07 21:44:101510base::StringPiece RenderViewImpl::GetSessionStorageNamespaceId() {
1511 CHECK(!session_storage_namespace_id_.empty());
Daniel Murphy0ce6e2c2017-11-21 01:54:261512 return session_storage_namespace_id_;
[email protected]bd92c3a2010-01-13 05:02:341513}
1514
Blink Reformat1c4d759e2017-04-09 16:34:541515void RenderViewImpl::PrintPage(WebLocalFrame* frame) {
naskoe440d8c2016-10-12 23:07:561516 UMA_HISTOGRAM_BOOLEAN("PrintPreview.InitiatedByScript",
Blink Reformat1c4d759e2017-04-09 16:34:541517 frame->Top() == frame);
naskoe440d8c2016-10-12 23:07:561518
1519 // Logging whether the top frame is remote is sufficient in this case. If
1520 // the top frame is local, the printing code will function correctly and
1521 // the frame itself will be printed, so the cases this histogram tracks is
1522 // where printing of a subframe will fail as of now.
1523 UMA_HISTOGRAM_BOOLEAN("PrintPreview.OutOfProcessSubframe",
Blink Reformat1c4d759e2017-04-09 16:34:541524 frame->Top()->IsWebRemoteFrame());
naskoe440d8c2016-10-12 23:07:561525
thestigcb959ce2016-11-17 05:56:321526 RenderFrameImpl::FromWebFrame(frame)->ScriptedPrint(
danakj53802692018-07-25 21:46:441527 GetWidget()->input_handler().handling_input_event());
[email protected]48c9cf2d2009-09-16 16:47:521528}
1529
Blink Reformat1c4d759e2017-04-09 16:34:541530bool RenderViewImpl::EnumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121531 const WebString& path,
1532 WebFileChooserCompletion* chooser_completion) {
1533 int id = enumeration_completion_id_++;
1534 enumeration_completions_[id] = chooser_completion;
1535 return Send(new ViewHostMsg_EnumerateDirectory(
avia3dca182016-03-19 01:09:521536 GetRoutingID(), id, blink::WebStringToFilePath(path)));
[email protected]8a58c1c2011-04-19 18:40:121537}
1538
lfgcaab5142016-02-26 19:06:521539void RenderViewImpl::AttachWebFrameWidget(blink::WebFrameWidget* frame_widget) {
dcheng3ce04b62015-10-26 23:30:551540 // The previous WebFrameWidget must already be detached by CloseForFrame().
1541 DCHECK(!frame_widget_);
1542 frame_widget_ = frame_widget;
1543}
1544
tommycli8aad3ba2015-08-12 17:57:591545void RenderViewImpl::SetZoomLevel(double zoom_level) {
wjmaclean64951902016-04-29 20:59:121546 // If we change the zoom level for the view, make sure any subsequent subframe
1547 // loads reflect the current zoom level.
1548 page_zoom_level_ = zoom_level;
1549
Blink Reformat1c4d759e2017-04-09 16:34:541550 webview()->SetZoomLevel(zoom_level);
ericwilligers88e69742016-10-17 19:29:551551 for (auto& observer : observers_)
1552 observer.OnZoomLevelChanged();
tommycli8aad3ba2015-08-12 17:57:591553}
1554
habib.virji597255e2014-09-09 00:30:181555void RenderViewImpl::SetValidationMessageDirection(
1556 base::string16* wrapped_main_text,
1557 blink::WebTextDirection main_text_hint,
1558 base::string16* wrapped_sub_text,
1559 blink::WebTextDirection sub_text_hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541560 if (main_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181561 *wrapped_main_text =
1562 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
Blink Reformat1c4d759e2017-04-09 16:34:541563 } else if (main_text_hint == blink::kWebTextDirectionRightToLeft &&
habib.virji597255e2014-09-09 00:30:181564 !base::i18n::IsRTL()) {
1565 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
1566 }
1567
1568 if (!wrapped_sub_text->empty()) {
Blink Reformat1c4d759e2017-04-09 16:34:541569 if (sub_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181570 *wrapped_sub_text =
1571 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
Blink Reformat1c4d759e2017-04-09 16:34:541572 } else if (sub_text_hint == blink::kWebTextDirectionRightToLeft) {
habib.virji597255e2014-09-09 00:30:181573 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
1574 }
1575 }
1576}
1577
[email protected]310ebd6302011-10-10 19:06:281578void RenderViewImpl::UpdateTargetURL(const GURL& url,
1579 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581580 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521581 if (latest_url == target_url_)
1582 return;
[email protected]163f8242009-10-30 20:19:551583
[email protected]48c9cf2d2009-09-16 16:47:521584 // Tell the browser to display a destination link.
1585 if (target_url_status_ == TARGET_INFLIGHT ||
1586 target_url_status_ == TARGET_PENDING) {
1587 // If we have a request in-flight, save the URL to be sent when we
1588 // receive an ACK to the in-flight request. We can happily overwrite
1589 // any existing pending sends.
1590 pending_target_url_ = latest_url;
1591 target_url_status_ = TARGET_PENDING;
1592 } else {
mnaganovbf087422015-12-16 05:10:031593 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411594 // see |ParamTraits<GURL>|.
markdittmer67b71ea2016-03-03 22:40:031595 if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:411596 latest_url = GURL();
avia3dca182016-03-19 01:09:521597 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), latest_url));
[email protected]48c9cf2d2009-09-16 16:47:521598 target_url_ = latest_url;
1599 target_url_status_ = TARGET_INFLIGHT;
1600 }
1601}
1602
creis69b184a472015-11-26 05:29:511603void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) {
creisce0ef3572017-01-26 17:53:081604 // Keep track of which frames have pending updates.
1605 frames_with_pending_state_.insert(frame->GetRoutingID());
creis8eb8ef22015-11-04 22:51:381606
[email protected]882daa92009-11-05 16:31:311607 int delay;
avif937e1d2014-11-02 18:13:071608 if (send_content_state_immediately_)
[email protected]882daa92009-11-05 16:31:311609 delay = 0;
1610 else if (is_hidden())
avif937e1d2014-11-02 18:13:071611 delay = kDelaySecondsForContentStateSyncHidden;
[email protected]882daa92009-11-05 16:31:311612 else
avif937e1d2014-11-02 18:13:071613 delay = kDelaySecondsForContentStateSync;
[email protected]882daa92009-11-05 16:31:311614
avif937e1d2014-11-02 18:13:071615 if (nav_state_sync_timer_.IsRunning()) {
[email protected]882daa92009-11-05 16:31:311616 // The timer is already running. If the delay of the timer maches the amount
1617 // we want to delay by, then return. Otherwise stop the timer so that it
1618 // gets started with the right delay.
avif937e1d2014-11-02 18:13:071619 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
[email protected]882daa92009-11-05 16:31:311620 return;
avif937e1d2014-11-02 18:13:071621 nav_state_sync_timer_.Stop();
[email protected]882daa92009-11-05 16:31:311622 }
1623
creisce0ef3572017-01-26 17:53:081624 // Tell each frame with pending state to inform the browser.
1625 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
1626 &RenderViewImpl::SendFrameStateUpdates);
[email protected]882daa92009-11-05 16:31:311627}
1628
Blink Reformat1c4d759e2017-04-09 16:34:541629void RenderViewImpl::SetMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551630 mouse_over_url_ = GURL(url);
1631 UpdateTargetURL(mouse_over_url_, focus_url_);
1632}
1633
Blink Reformat1c4d759e2017-04-09 16:34:541634void RenderViewImpl::SetKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551635 focus_url_ = GURL(url);
1636 UpdateTargetURL(focus_url_, mouse_over_url_);
1637}
1638
Blink Reformat1c4d759e2017-04-09 16:34:541639bool RenderViewImpl::AcceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451640 return renderer_preferences_.can_accept_load_drops;
1641}
1642
Blink Reformat1c4d759e2017-04-09 16:34:541643void RenderViewImpl::FocusNext() {
avia3dca182016-03-19 01:09:521644 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false));
[email protected]48c9cf2d2009-09-16 16:47:521645}
1646
Blink Reformat1c4d759e2017-04-09 16:34:541647void RenderViewImpl::FocusPrevious() {
avia3dca182016-03-19 01:09:521648 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true));
[email protected]48c9cf2d2009-09-16 16:47:521649}
1650
esprehn3d4471a2015-09-17 07:13:201651// TODO(esprehn): Blink only ever passes Elements, this should take WebElement.
Blink Reformat1c4d759e2017-04-09 16:34:541652void RenderViewImpl::FocusedNodeChanged(const WebNode& fromNode,
estade31c54342015-01-23 03:34:361653 const WebNode& toNode) {
estade31c54342015-01-23 03:34:361654 RenderFrameImpl* previous_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541655 if (!fromNode.IsNull())
1656 previous_frame =
1657 RenderFrameImpl::FromWebFrame(fromNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361658 RenderFrameImpl* new_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541659 if (!toNode.IsNull())
1660 new_frame = RenderFrameImpl::FromWebFrame(toNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361661
1662 if (previous_frame && previous_frame != new_frame)
1663 previous_frame->FocusedNodeChanged(WebNode());
1664 if (new_frame)
1665 new_frame->FocusedNodeChanged(toNode);
1666
1667 // TODO(dmazzoni): remove once there's a separate a11y tree per frame.
naskoe8d115752015-08-07 00:43:131668 if (main_render_frame_)
1669 main_render_frame_->FocusedNodeChangedForAccessibility(toNode);
[email protected]08e9e132010-06-01 16:58:491670}
1671
Philip Rogers079658812018-08-01 23:19:091672void RenderViewImpl::DidUpdateMainFrameLayout() {
ericwilligers88e69742016-10-17 19:29:551673 for (auto& observer : observers_)
Philip Rogers079658812018-08-01 23:19:091674 observer.DidUpdateMainFrameLayout();
[email protected]d01b2a62013-09-18 23:21:331675
Philip Rogers33cd2bcc2018-08-13 21:29:291676 // The main frame may have changed size.
1677 needs_preferred_size_update_ = true;
[email protected]169d4282011-11-30 19:33:591678}
1679
Arthur Sonzognia7d715a2018-09-20 16:11:131680void RenderViewImpl::NavigateBackForwardSoon(int offset,
1681 bool has_user_gesture) {
Alex Clarkebf3dceb2017-11-24 12:27:431682 history_navigation_virtual_time_pauser_ =
1683 RenderThreadImpl::current()
Yuta Kitamura3331f5c2018-04-05 11:12:251684 ->GetWebMainThreadScheduler()
Alex Clarkeb28db542018-02-07 12:53:131685 ->CreateWebScopedVirtualTimePauser(
Alex Clarkeaaf006b2018-04-05 18:35:241686 "NavigateBackForwardSoon",
Alex Clarkeb28db542018-02-07 12:53:131687 blink::WebScopedVirtualTimePauser::VirtualTaskDuration::kInstant);
Alex Clarkeaaf006b2018-04-05 18:35:241688 history_navigation_virtual_time_pauser_.PauseVirtualTime();
Arthur Sonzognia7d715a2018-09-20 16:11:131689 Send(new ViewHostMsg_GoToEntryAtOffset(GetRoutingID(), offset,
1690 has_user_gesture));
[email protected]48c9cf2d2009-09-16 16:47:521691}
1692
Alex Clarkebf3dceb2017-11-24 12:27:431693void RenderViewImpl::DidCommitProvisionalHistoryLoad() {
Alex Clarkeaaf006b2018-04-05 18:35:241694 history_navigation_virtual_time_pauser_.UnpauseVirtualTime();
Alex Clarkebf3dceb2017-11-24 12:27:431695}
1696
Makoto Shimazuc3c730e2018-08-15 09:51:111697void RenderViewImpl::RegisterRendererPreferenceWatcherForWorker(
1698 mojom::RendererPreferenceWatcherPtr watcher) {
1699 renderer_preference_watchers_.AddPtr(std::move(watcher));
1700}
1701
Blink Reformat1c4d759e2017-04-09 16:34:541702int RenderViewImpl::HistoryBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001703 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521704}
1705
Blink Reformat1c4d759e2017-04-09 16:34:541706int RenderViewImpl::HistoryForwardListCount() {
1707 return history_list_length_ - HistoryBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521708}
1709
[email protected]180ef242013-11-07 06:50:461710// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:511711
Blink Reformat1c4d759e2017-04-09 16:34:541712bool RenderViewImpl::CanHandleGestureEvent() {
slangley1a6375e62017-03-29 06:03:231713 return true;
1714}
1715
Blink Reformat1c4d759e2017-04-09 16:34:541716bool RenderViewImpl::CanUpdateLayout() {
slangley1a6375e62017-03-29 06:03:231717 return true;
1718}
1719
Blink Reformat1c4d759e2017-04-09 16:34:541720blink::WebWidgetClient* RenderViewImpl::WidgetClient() {
danakj9a8a9cf2018-07-17 23:52:121721 return this;
lfg0f440622016-07-20 04:27:141722}
1723
Mustaq Ahmed55944cb2018-05-25 20:44:271724// blink::WebLocalFrameClient
1725// -----------------------------------------------------
[email protected]3d9689372009-09-10 04:29:171726
[email protected]b2324b092012-11-01 10:34:111727void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
1728 const std::string& value) {
alexmos56567492016-09-13 00:52:461729 GetWidget()->SetEditCommandForNextKeyEvent(name, value);
[email protected]b2324b092012-11-01 10:34:111730}
1731
1732void RenderViewImpl::ClearEditCommands() {
alexmos56567492016-09-13 00:52:461733 GetWidget()->ClearEditCommands();
[email protected]b2324b092012-11-01 10:34:111734}
1735
[email protected]b38806a2013-10-04 16:01:381736const std::string& RenderViewImpl::GetAcceptLanguages() const {
1737 return renderer_preferences_.accept_languages;
1738}
1739
Ahmed Fakhry58e6ef542018-09-04 18:05:381740void RenderViewImpl::UpdateBrowserControlsState(
1741 BrowserControlsState constraints,
1742 BrowserControlsState current,
1743 bool animate) {
David Bokan1e37ebf2018-10-16 13:53:371744 if (GetWidget() && GetWidget()->layer_tree_view()) {
1745 GetWidget()->layer_tree_view()->UpdateBrowserControlsState(
1746 ContentToCc(constraints), ContentToCc(current), animate);
Ahmed Fakhry58e6ef542018-09-04 18:05:381747 }
1748
1749 top_controls_constraints_ = constraints;
1750}
1751
David Bokan1e37ebf2018-10-16 13:53:371752#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
1753
Ahmed Fakhry58e6ef542018-09-04 18:05:381754void RenderViewImpl::didScrollWithKeyboard(const blink::WebSize& delta) {
1755 if (delta.height == 0)
1756 return;
1757
1758 BrowserControlsState current = delta.height < 0
1759 ? BROWSER_CONTROLS_STATE_SHOWN
1760 : BROWSER_CONTROLS_STATE_HIDDEN;
1761
1762 UpdateBrowserControlsState(top_controls_constraints_, current, true);
1763}
1764
1765#endif
1766
danakjdea2efb2016-03-10 19:13:171767void RenderViewImpl::ConvertViewportToWindowViaWidget(blink::WebRect* rect) {
danakj9a8a9cf2018-07-17 23:52:121768 WidgetClient()->ConvertViewportToWindow(rect);
oshimae2b3b402015-12-04 04:27:241769}
1770
huangs2a342352015-12-15 16:59:241771gfx::RectF RenderViewImpl::ElementBoundsInWindow(
1772 const blink::WebElement& element) {
Blink Reformat1c4d759e2017-04-09 16:34:541773 blink::WebRect bounding_box_in_window = element.BoundsInViewport();
danakj9a8a9cf2018-07-17 23:52:121774 WidgetClient()->ConvertViewportToWindow(&bounding_box_in_window);
huangs2a342352015-12-15 16:59:241775 return gfx::RectF(bounding_box_in_window);
1776}
1777
Philip Rogers601fd072018-08-07 22:58:221778void RenderViewImpl::UpdatePreferredSize() {
[email protected]d812fd12011-05-27 23:05:071779 // We don't always want to send the change messages over IPC, only if we've
1780 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1781 // message.
1782 if (!send_preferred_size_changes_ || !webview())
1783 return;
Philip Rogers33cd2bcc2018-08-13 21:29:291784
1785 if (!needs_preferred_size_update_)
1786 return;
1787 needs_preferred_size_update_ = false;
1788
oshima1a688b5c2017-06-16 19:00:131789 blink::WebSize tmp_size = webview()->ContentsPreferredMinimumSize();
1790 blink::WebRect tmp_rect(0, 0, tmp_size.width, tmp_size.height);
danakj9a8a9cf2018-07-17 23:52:121791 WidgetClient()->ConvertViewportToWindow(&tmp_rect);
oshima1a688b5c2017-06-16 19:00:131792 gfx::Size size(tmp_rect.width, tmp_rect.height);
[email protected]705243f2010-05-05 19:58:071793 if (size == preferred_size_)
1794 return;
[email protected]c27324b2009-11-19 22:44:291795
[email protected]705243f2010-05-05 19:58:071796 preferred_size_ = size;
avia3dca182016-03-19 01:09:521797 Send(new ViewHostMsg_DidContentsPreferredSizeChange(GetRoutingID(),
[email protected]705243f2010-05-05 19:58:071798 preferred_size_));
[email protected]3d9689372009-09-10 04:29:171799}
1800
Blink Reformat1c4d759e2017-04-09 16:34:541801blink::WebString RenderViewImpl::AcceptLanguages() {
1802 return WebString::FromUTF8(renderer_preferences_.accept_languages);
[email protected]9982c802013-06-12 15:22:061803}
1804
[email protected]e9ff79c2012-10-19 21:31:261805// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:311806
[email protected]310ebd6302011-10-10 19:06:281807bool RenderViewImpl::Send(IPC::Message* message) {
danakja2c9d0a92018-07-25 20:01:181808 // This method is an override of IPC::Sender, but RenderWidget also has an
1809 // override of IPC::Sender, so this method also overrides RenderWidget. Thus
1810 // we must call to the base class, not via an upcast or virtual dispatch would
1811 // go back here.
[email protected]a2ef54c2011-10-10 16:20:311812 return RenderWidget::Send(message);
1813}
1814
Peter Kastinga4a3ed12018-01-31 04:07:591815RenderWidget* RenderViewImpl::GetWidget() {
1816 return this;
avi8a45c1092016-03-01 16:12:341817}
1818
mostynbc33353232014-09-12 09:38:311819RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() {
nasko77de2312015-05-12 03:09:161820 return main_render_frame_;
[email protected]b849847b2013-12-10 21:57:581821}
1822
[email protected]82114f52012-03-20 22:53:411823int RenderViewImpl::GetRoutingID() const {
Albert J. Wongcb004632018-07-10 22:58:251824 return routing_id_;
[email protected]a2ef54c2011-10-10 16:20:311825}
1826
[email protected]82114f52012-03-20 22:53:411827gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:311828 return size();
1829}
1830
oshima129b75e2016-01-14 09:15:141831float RenderViewImpl::GetDeviceScaleFactor() const {
Fady Samuela863f152018-03-09 16:10:031832 return GetWebScreenInfo().device_scale_factor;
oshima129b75e2016-01-14 09:15:141833}
1834
Marc Treib06d66032017-10-19 08:43:201835float RenderViewImpl::GetZoomLevel() const {
1836 return page_zoom_level_;
1837}
1838
thestig8a8fdfd32017-05-06 18:46:541839const WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:311840 return webkit_preferences_;
1841}
1842
[email protected]324825d2012-11-30 12:37:151843void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
1844 OnUpdateWebPreferences(preferences);
1845}
1846
[email protected]180ef242013-11-07 06:50:461847blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:311848 return webview();
1849}
1850
lfgcaab5142016-02-26 19:06:521851blink::WebFrameWidget* RenderViewImpl::GetWebFrameWidget() {
1852 return frame_widget_;
1853}
1854
avif937e1d2014-11-02 18:13:071855bool RenderViewImpl::GetContentStateImmediately() const {
1856 return send_content_state_immediately_;
[email protected]a2ef54c2011-10-10 16:20:311857}
1858
mcnee432e47d2015-11-09 19:37:461859void RenderViewImpl::OnSetPageScale(float page_scale_factor) {
ccameronb7c1d6c2015-03-09 17:08:241860 if (!webview())
1861 return;
Blink Reformat1c4d759e2017-04-09 16:34:541862 webview()->SetPageScaleFactor(page_scale_factor);
ccameronb7c1d6c2015-03-09 17:08:241863}
1864
akaba3483d8f2018-07-10 21:43:091865void RenderViewImpl::UpdateZoomLevel(double zoom_level) {
Blink Reformat1c4d759e2017-04-09 16:34:541866 webview()->HidePopups();
wjmaclean64951902016-04-29 20:59:121867 SetZoomLevel(zoom_level);
[email protected]d42bf472014-06-14 01:49:381868}
1869
[email protected]310ebd6302011-10-10 19:06:281870void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:591871 webkit_preferences_ = prefs;
danakjfd0c7f42018-10-12 18:01:081872 ApplyWebPreferences(webkit_preferences_, webview());
initial.commit09911bf2008-07-26 23:55:291873}
1874
[email protected]310ebd6302011-10-10 19:06:281875void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:511876 int id,
[email protected]c42de732013-02-16 06:26:311877 const std::vector<base::FilePath>& paths) {
[email protected]600ea402011-04-12 00:01:511878 if (!enumeration_completions_[id])
1879 return;
1880
1881 WebVector<WebString> ws_file_names(paths.size());
1882 for (size_t i = 0; i < paths.size(); ++i)
kinukoa4293022017-01-27 06:43:251883 ws_file_names[i] = blink::FilePathToWebString(paths[i]);
[email protected]600ea402011-04-12 00:01:511884
Blink Reformat1c4d759e2017-04-09 16:34:541885 enumeration_completions_[id]->DidChooseFile(ws_file_names);
[email protected]600ea402011-04-12 00:01:511886 enumeration_completions_.erase(id);
1887}
1888
[email protected]2bf834f2011-11-17 20:02:211889void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:241890 if (send_preferred_size_changes_)
1891 return;
[email protected]9fb325e2010-05-06 18:23:241892 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:391893
Philip Rogers601fd072018-08-07 22:58:221894 if (!webview())
1895 return;
1896
Philip Rogers33cd2bcc2018-08-13 21:29:291897 needs_preferred_size_update_ = true;
1898
Philip Rogers601fd072018-08-07 22:58:221899 // We need to ensure |UpdatePreferredSize| gets called. If a layout is needed,
1900 // force an update here which will call |DidUpdateMainFrameLayout|.
1901 webview()->UpdateLifecycle(WebWidget::LifecycleUpdate::kLayout);
1902
1903 // If a layout was not needed, |DidUpdateMainFrameLayout| will not be called.
1904 // We explicitly update the preferred size here to ensure the preferred size
1905 // notification is sent.
1906 UpdatePreferredSize();
[email protected]0666aef2009-05-13 19:48:081907}
1908
[email protected]310ebd6302011-10-10 19:06:281909void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:261910 const RendererPreferences& renderer_prefs) {
[email protected]ebd5ea52014-05-28 14:51:151911 std::string old_accept_languages = renderer_preferences_.accept_languages;
1912
[email protected]80d96fa2009-06-10 22:34:511913 renderer_preferences_ = renderer_prefs;
ananta59b9fe72015-04-07 01:33:261914
Makoto Shimazuc3c730e2018-08-15 09:51:111915 renderer_preference_watchers_.ForAllPtrs(
1916 [&renderer_prefs](mojom::RendererPreferenceWatcher* watcher) {
1917 watcher->NotifyUpdate(renderer_prefs);
1918 });
1919
[email protected]6e282c92009-07-24 01:19:371920 UpdateFontRenderingFromRendererPrefs();
scottmgb92365e2016-08-30 20:54:401921 UpdateThemePrefs();
Blink Reformat1c4d759e2017-04-09 16:34:541922 blink::SetCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]38a85712013-01-02 22:45:021923
brettw8a274fa2016-11-15 00:20:401924#if BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]1596efb2013-01-17 22:13:011925 if (renderer_prefs.use_custom_colors) {
Blink Reformat1c4d759e2017-04-09 16:34:541926 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
[email protected]1596efb2013-01-17 22:13:011927
1928 if (webview()) {
Blink Reformat1c4d759e2017-04-09 16:34:541929 webview()->SetSelectionColors(renderer_prefs.active_selection_bg_color,
1930 renderer_prefs.active_selection_fg_color,
1931 renderer_prefs.inactive_selection_bg_color,
1932 renderer_prefs.inactive_selection_fg_color);
1933 webview()->ThemeChanged();
[email protected]1596efb2013-01-17 22:13:011934 }
[email protected]644d77e2010-01-27 01:03:101935 }
brettw8a274fa2016-11-15 00:20:401936#endif // BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]d299d972012-03-23 02:26:551937
[email protected]ebd5ea52014-05-28 14:51:151938 if (webview() &&
1939 old_accept_languages != renderer_preferences_.accept_languages) {
Blink Reformat1c4d759e2017-04-09 16:34:541940 webview()->AcceptLanguagesChanged();
[email protected]ebd5ea52014-05-28 14:51:151941 }
[email protected]80d96fa2009-06-10 22:34:511942}
1943
[email protected]81375e872012-01-11 21:40:361944void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
1945 const WebPluginAction& action) {
1946 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:541947 webview()->PerformPluginAction(action, location);
[email protected]81375e872012-01-11 21:40:361948}
1949
[email protected]310ebd6302011-10-10 19:06:281950void RenderViewImpl::OnClosePage() {
lukasza5d0dee42017-06-14 21:57:371951 // ViewMsg_ClosePage should only be sent to active, non-swapped-out views.
1952 DCHECK(webview()->MainFrame()->IsWebLocalFrame());
1953
initial.commit09911bf2008-07-26 23:55:291954 // TODO(creis): We'd rather use webview()->Close() here, but that currently
1955 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
1956 // in the onunload handler from appearing. For now, we're bypassing that and
1957 // calling the FrameLoader's CloseURL method directly. This should be
1958 // revisited to avoid having two ways to close a page. Having a single way
1959 // to close that can run onunload is also useful for fixing
1960 // http://b/issue?id=753080.
lukasza5d0dee42017-06-14 21:57:371961 webview()->MainFrame()->ToWebLocalFrame()->DispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:291962
avia3dca182016-03-19 01:09:521963 Send(new ViewHostMsg_ClosePage_ACK(GetRoutingID()));
initial.commit09911bf2008-07-26 23:55:291964}
1965
[email protected]310ebd6302011-10-10 19:06:281966void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:001967 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:541968 webview()->HidePopups();
[email protected]30f75e62009-02-25 22:01:001969}
1970
lfg717154072016-06-30 15:04:161971void RenderViewImpl::OnPageWasHidden() {
braveyao1d8ee7b2017-03-29 21:10:041972#if defined(OS_ANDROID)
1973 SuspendVideoCaptureDevices(true);
braveyao1d8ee7b2017-03-29 21:10:041974#endif
[email protected]2d7b82c2012-06-01 05:57:501975
lfg717154072016-06-30 15:04:161976 if (webview()) {
1977 // TODO(lfg): It's not correct to defer the page visibility to the main
1978 // frame. Currently, this is done because the main frame may override the
1979 // visibility of the page when prerendering. In order to fix this,
1980 // prerendering must be made aware of OOPIFs. https://crbug.com/440544
xzhan96cf0a3c542017-11-17 04:33:011981 blink::mojom::PageVisibilityState visibilityState =
Blink Reformat1c4d759e2017-04-09 16:34:541982 GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState()
xzhan96cf0a3c542017-11-17 04:33:011983 : blink::mojom::PageVisibilityState::kHidden;
Blink Reformat1c4d759e2017-04-09 16:34:541984 webview()->SetVisibilityState(visibilityState, false);
lfg717154072016-06-30 15:04:161985 }
[email protected]941e4552010-02-01 21:23:431986}
1987
lfg717154072016-06-30 15:04:161988void RenderViewImpl::OnPageWasShown() {
braveyao1d8ee7b2017-03-29 21:10:041989#if defined(OS_ANDROID)
1990 SuspendVideoCaptureDevices(false);
[email protected]6392d982013-04-16 16:59:221991#endif
1992
lfg717154072016-06-30 15:04:161993 if (webview()) {
xzhan96cf0a3c542017-11-17 04:33:011994 blink::mojom::PageVisibilityState visibilityState =
Blink Reformat1c4d759e2017-04-09 16:34:541995 GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState()
xzhan96cf0a3c542017-11-17 04:33:011996 : blink::mojom::PageVisibilityState::kVisible;
Blink Reformat1c4d759e2017-04-09 16:34:541997 webview()->SetVisibilityState(visibilityState, false);
lfg717154072016-06-30 15:04:161998 }
[email protected]a6939ca42011-02-18 17:58:071999}
[email protected]1e6e3c992010-02-08 15:52:132000
lfg8d649cc2017-04-28 18:04:302001void RenderViewImpl::OnUpdateScreenInfo(const ScreenInfo& screen_info) {
2002 // This IPC only updates the screen info on RenderViews that have a remote
2003 // main frame. For local main frames, the ScreenInfo is updated in
2004 // ViewMsg_Resize.
danakj53802692018-07-25 21:46:442005 // TODO(danakj): Move this message to RenderWidget?
lfg8d649cc2017-04-28 18:04:302006 if (!main_render_frame_)
danakj53802692018-07-25 21:46:442007 GetWidget()->set_screen_info(screen_info);
lfg8d649cc2017-04-28 18:04:302008}
2009
Francois Doray47f759d2018-06-11 18:13:512010void RenderViewImpl::SetPageFrozen(bool frozen) {
2011 if (webview())
2012 webview()->SetPageFrozen(frozen);
Fadi Meawada6573e02018-03-10 00:52:112013}
2014
alexmos3fcd0ca2015-10-23 18:18:332015void RenderViewImpl::SetFocus(bool enable) {
danakja2c9d0a92018-07-25 20:01:182016 // This is not an IPC message, don't go through the IPC handler. This is used
2017 // in cases where the IPC message should not happen.
2018 GetWidget()->SetFocus(enable);
[email protected]b2e4c70132013-10-03 02:07:512019}
2020
Blink Reformat1c4d759e2017-04-09 16:34:542021void RenderViewImpl::ZoomLimitsChanged(double minimum_level,
[email protected]310ebd6302011-10-10 19:06:282022 double maximum_level) {
a.sarkar.arundaadc712015-02-26 05:39:082023 // Round the double to avoid returning incorrect minimum/maximum zoom
2024 // percentages.
2025 int minimum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492026 ZoomLevelToZoomFactor(minimum_level) * 100);
a.sarkar.arundaadc712015-02-26 05:39:082027 int maximum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492028 ZoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:252029
avia3dca182016-03-19 01:09:522030 Send(new ViewHostMsg_UpdateZoomLimits(GetRoutingID(), minimum_percent,
fsamuele8326c742016-01-12 00:49:392031 maximum_percent));
[email protected]b75b8292010-10-01 07:28:252032}
2033
Blink Reformat1c4d759e2017-04-09 16:34:542034void RenderViewImpl::PageScaleFactorChanged() {
ccameronb7c1d6c2015-03-09 17:08:242035 if (!webview())
2036 return;
mcnee432e47d2015-11-09 19:37:462037
avia3dca182016-03-19 01:09:522038 Send(new ViewHostMsg_PageScaleFactorChanged(GetRoutingID(),
Blink Reformat1c4d759e2017-04-09 16:34:542039 webview()->PageScaleFactor()));
ccameronb7c1d6c2015-03-09 17:08:242040}
2041
[email protected]7940b8e2013-07-25 23:08:492042double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const {
2043 return ZoomLevelToZoomFactor(zoom_level);
2044}
2045
2046double RenderViewImpl::zoomFactorToZoomLevel(double factor) const {
2047 return ZoomFactorToZoomLevel(factor);
2048}
2049
Blink Reformat1c4d759e2017-04-09 16:34:542050void RenderViewImpl::PageImportanceSignalsChanged() {
kouhei40f03cb2015-09-24 07:47:012051 if (!webview() || !main_render_frame_)
2052 return;
2053
Blink Reformat1c4d759e2017-04-09 16:34:542054 auto* web_signals = webview()->PageImportanceSignals();
kouhei40f03cb2015-09-24 07:47:012055
2056 PageImportanceSignals signals;
Blink Reformat1c4d759e2017-04-09 16:34:542057 signals.had_form_interaction = web_signals->HadFormInteraction();
kouhei40f03cb2015-09-24 07:47:012058
2059 main_render_frame_->Send(new FrameHostMsg_UpdatePageImportanceSignals(
2060 main_render_frame_->GetRoutingID(), signals));
2061}
2062
danakj9a8a9cf2018-07-17 23:52:122063void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) {
danakja2c9d0a92018-07-25 20:01:182064 GetWidget()->DidAutoResize(newSize);
danakj9a8a9cf2018-07-17 23:52:122065}
2066
2067blink::WebRect RenderViewImpl::RootWindowRect() {
2068 return WidgetClient()->WindowRect();
2069}
2070
danakja2c9d0a92018-07-25 20:01:182071void RenderViewImpl::DidFocus(blink::WebLocalFrame* calling_frame) {
2072 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2073 // we won't have to test for user gesture anymore and we can
2074 // move that code back to render_widget.cc
2075 if (WebUserGestureIndicator::IsProcessingUserGesture(calling_frame) &&
2076 !RenderThreadImpl::current()->layout_test_mode()) {
2077 Send(new ViewHostMsg_Focus(GetRoutingID()));
2078
2079 // Tattle on the frame that called |window.focus()|.
2080 RenderFrameImpl* calling_render_frame =
2081 RenderFrameImpl::FromWebFrame(calling_frame);
2082 if (calling_render_frame)
2083 calling_render_frame->FrameDidCallFocus();
2084 }
2085}
2086
danakj46b3dde2018-10-18 16:12:172087blink::WebScreenInfo RenderViewImpl::GetScreenInfo() {
2088 const ScreenInfo& info = GetWidget()->screen_info();
2089
2090 blink::WebScreenInfo web_screen_info;
2091 web_screen_info.device_scale_factor = info.device_scale_factor;
2092 web_screen_info.color_space = info.color_space;
2093 web_screen_info.depth = info.depth;
2094 web_screen_info.depth_per_component = info.depth_per_component;
2095 web_screen_info.is_monochrome = info.is_monochrome;
2096 web_screen_info.rect = blink::WebRect(info.rect);
2097 web_screen_info.available_rect = blink::WebRect(info.available_rect);
2098 switch (info.orientation_type) {
2099 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
2100 web_screen_info.orientation_type =
2101 blink::kWebScreenOrientationPortraitPrimary;
2102 break;
2103 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
2104 web_screen_info.orientation_type =
2105 blink::kWebScreenOrientationPortraitSecondary;
2106 break;
2107 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
2108 web_screen_info.orientation_type =
2109 blink::kWebScreenOrientationLandscapePrimary;
2110 break;
2111 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
2112 web_screen_info.orientation_type =
2113 blink::kWebScreenOrientationLandscapeSecondary;
2114 break;
2115 default:
2116 web_screen_info.orientation_type = blink::kWebScreenOrientationUndefined;
2117 break;
2118 }
2119 web_screen_info.orientation_angle = info.orientation_angle;
2120
2121 return web_screen_info;
2122}
2123
[email protected]20657a82012-08-21 20:23:032124#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:542125bool RenderViewImpl::OpenDateTimeChooser(
[email protected]180ef242013-11-07 06:50:462126 const blink::WebDateTimeChooserParams& params,
2127 blink::WebDateTimeChooserCompletion* completion) {
[email protected]e8072562013-12-04 06:04:132128 // JavaScript may try to open a date time chooser while one is already open.
2129 if (date_time_picker_client_)
2130 return false;
[email protected]b18583c2012-12-18 06:55:272131 date_time_picker_client_.reset(
2132 new RendererDateTimePicker(this, params, completion));
2133 return date_time_picker_client_->Open();
2134}
2135
[email protected]e8072562013-12-04 06:04:132136void RenderViewImpl::DismissDateTimeDialog() {
2137 DCHECK(date_time_picker_client_);
Lei Zhang88f23ba2017-10-27 05:56:262138 date_time_picker_client_.reset();
[email protected]e8072562013-12-04 06:04:132139}
[email protected]e8072562013-12-04 06:04:132140
braveyao1d8ee7b2017-03-29 21:10:042141void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) {
2142 if (!main_render_frame_)
2143 return;
2144
Chandan Padhi26dbd9b32017-11-27 11:13:352145 MediaStreamDeviceObserver* media_stream_device_observer =
2146 main_render_frame_->GetMediaStreamDeviceObserver();
2147 if (!media_stream_device_observer)
braveyao1d8ee7b2017-03-29 21:10:042148 return;
2149
Chandan Padhi6dbfb732017-09-01 16:08:492150 MediaStreamDevices video_devices =
Chandan Padhi26dbd9b32017-11-27 11:13:352151 media_stream_device_observer->GetNonScreenCaptureDevices();
braveyao1d8ee7b2017-03-29 21:10:042152 RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices(
Chandan Padhi6dbfb732017-09-01 16:08:492153 video_devices, suspend);
braveyao1d8ee7b2017-03-29 21:10:042154}
estade6b9696bd2016-05-04 23:51:362155#endif // defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:032156
[email protected]b283d292013-02-21 08:40:342157unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
2158 return history_list_length_;
2159}
2160
[email protected]cc290f902013-03-04 20:06:022161void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
Nasko Oskova463a052018-05-08 16:42:142162 // If the main frame is remote, return immediately. Page level focus
2163 // should be set from the browser process, so if needed by tests it should
2164 // be properly supported.
2165 if (webview()->MainFrame()->IsWebRemoteFrame())
2166 return;
2167
danakja2c9d0a92018-07-25 20:01:182168 if (enable == has_focus())
2169 return;
2170
[email protected]cc290f902013-03-04 20:06:022171 if (enable) {
danakja2c9d0a92018-07-25 20:01:182172 SetActiveForWidget(true);
2173 // Fake an IPC message so go through the IPC handler.
[email protected]cc290f902013-03-04 20:06:022174 OnSetFocus(true);
2175 } else {
danakja2c9d0a92018-07-25 20:01:182176 // Fake an IPC message so go through the IPC handler.
[email protected]cc290f902013-03-04 20:06:022177 OnSetFocus(false);
danakja2c9d0a92018-07-25 20:01:182178 SetActiveForWidget(false);
[email protected]cc290f902013-03-04 20:06:022179 }
2180}
2181
[email protected]e9ff79c2012-10-19 21:31:262182} // namespace content