blob: 85880a99a861a5e1207dd28a6824fecce73b5a25 [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"
Daniel Murphye3eec92c2018-02-23 19:09:1544#include "content/common/dom_storage/dom_storage_namespace_ids.h"
[email protected]5f2aa722013-08-07 16:59:4145#include "content/common/dom_storage/dom_storage_types.h"
[email protected]59f4f2fa2011-03-23 01:00:5546#include "content/common/drag_messages.h"
[email protected]c6bc20332014-02-28 18:30:3947#include "content/common/frame_messages.h"
alexmosbc7eafa2014-12-06 01:38:0948#include "content/common/frame_replication_state.h"
[email protected]c084330e02013-04-27 01:08:1549#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0750#include "content/common/page_messages.h"
rockot5c478a72016-09-28 23:14:1851#include "content/common/render_message_filter.mojom.h"
[email protected]778574e2011-03-21 22:03:5052#include "content/common/view_messages.h"
arthursonzognic517fc32016-08-11 11:04:2453#include "content/public/common/browser_side_navigation_policy.h"
[email protected]744c2a22012-03-15 18:42:0454#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4855#include "content/public/common/content_constants.h"
Tarun Bansal73dd2ff82017-10-03 05:29:3456#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2957#include "content/public/common/content_switches.h"
kouhei40f03cb2015-09-24 07:47:0158#include "content/public/common/page_importance_signals.h"
clamyda97e8322014-10-07 21:57:2559#include "content/public/common/page_state.h"
[email protected]7940b8e2013-07-25 23:08:4960#include "content/public/common/page_zoom.h"
[email protected]818915cd2012-11-20 13:14:1161#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0362#include "content/public/common/url_constants.h"
Jaebaek Seo53ab80a662018-01-29 04:50:4663#include "content/public/common/use_zoom_for_dsf_policy.h"
[email protected]b3a97b52014-07-09 06:25:0564#include "content/public/common/web_preferences.h"
[email protected]d344114c2011-10-01 01:24:3465#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0766#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3267#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4468#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3669#include "content/public/renderer/render_view_visitor.h"
scottmg8e6c6082017-02-13 23:15:4870#include "content/public/renderer/window_features_converter.h"
John Abd-El-Malekdcf1d1372017-10-22 06:39:4171#include "content/renderer/appcache/appcache_dispatcher.h"
72#include "content/renderer/appcache/web_application_cache_host_impl.h"
[email protected]e6e56752012-08-10 00:46:0673#include "content/renderer/browser_plugin/browser_plugin.h"
74#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]dc293a72013-07-01 11:11:2275#include "content/renderer/drop_data_builder.h"
danakja6c10012018-07-06 14:25:3676#include "content/renderer/gpu/layer_tree_view.h"
[email protected]dc064352014-04-25 08:36:3877#include "content/renderer/history_serialization.h"
[email protected]66fca5bc2013-05-23 06:58:2978#include "content/renderer/ime_event_guard.h"
[email protected]92d457802013-04-01 19:18:4979#include "content/renderer/internal_document_state_data.h"
John Abd-El-Malek6b56ef712017-10-21 22:52:4680#include "content/renderer/loader/request_extra_data.h"
Amos Limbcc710e2018-06-08 05:51:1781#include "content/renderer/media/audio/audio_device_factory.h"
Miguel Casasa8c2c5a2018-02-12 18:51:0382#include "content/renderer/media/stream/media_stream_device_observer.h"
[email protected]6392d982013-04-16 16:59:2283#include "content/renderer/media/video_capture_impl_manager.h"
Patrik Höglundb564859b2018-05-17 11:17:1684#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
85#include "content/renderer/media/webrtc/rtc_peer_connection_handler.h"
clamy5f342202015-03-18 13:47:5686#include "content/renderer/navigation_state_impl.h"
[email protected]227692c52013-05-31 22:43:0487#include "content/renderer/render_frame_impl.h"
[email protected]5a7100d2014-05-19 01:29:0488#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0589#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4490#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4491#include "content/renderer/render_widget_fullscreen_pepper.h"
Daniel Murphye3eec92c2018-02-23 19:09:1592#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]663bd9e2011-03-21 01:07:0193#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]5b45ad42013-10-25 00:42:0494#include "content/renderer/resizing_mode_selector.h"
[email protected]12a936d2013-05-15 04:55:4995#include "content/renderer/savable_resources.h"
John Abd-El-Malek312a30bb2017-10-23 19:51:5296#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:2197#include "content/renderer/web_ui_extension_data.h"
[email protected]f5961142013-04-17 23:09:4298#include "media/audio/audio_output_device.h"
[email protected]ee68378a2010-08-10 01:05:4199#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:44100#include "media/media_buildflags.h"
servolkf54f5c8f2015-02-24 20:32:39101#include "media/renderers/audio_renderer_impl.h"
Dale Curtis863022e2017-08-19 02:05:34102#include "media/video/gpu_video_accelerator_factories.h"
[email protected]d1ef81d2012-07-24 11:39:36103#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29104#include "net/base/escape.h"
105#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09106#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04107#include "net/http/http_util.h"
Tarun Bansal73d67f02018-01-17 05:56:25108#include "net/nqe/effective_connection_type.h"
Scott Violet02e38b92018-03-27 23:42:14109#include "ppapi/buildflags/buildflags.h"
lukenb171b532014-09-24 05:50:38110#include "skia/ext/platform_canvas.h"
Blink Reformata30d4232018-04-07 15:31:06111#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
Mustaq Ahmed76c2f4312018-06-07 20:48:01112#include "third_party/blink/public/common/frame/user_activation_update_source.h"
Blink Reformata30d4232018-04-07 15:31:06113#include "third_party/blink/public/mojom/page/page_visibility_state.mojom.h"
114#include "third_party/blink/public/platform/file_path_conversion.h"
115#include "third_party/blink/public/platform/url_conversion.h"
116#include "third_party/blink/public/platform/web_connection_type.h"
117#include "third_party/blink/public/platform/web_effective_connection_type.h"
118#include "third_party/blink/public/platform/web_http_body.h"
119#include "third_party/blink/public/platform/web_image.h"
120#include "third_party/blink/public/platform/web_input_event.h"
121#include "third_party/blink/public/platform/web_input_event_result.h"
122#include "third_party/blink/public/platform/web_network_state_notifier.h"
123#include "third_party/blink/public/platform/web_point.h"
124#include "third_party/blink/public/platform/web_rect.h"
125#include "third_party/blink/public/platform/web_runtime_features.h"
126#include "third_party/blink/public/platform/web_size.h"
127#include "third_party/blink/public/platform/web_string.h"
128#include "third_party/blink/public/platform/web_url.h"
129#include "third_party/blink/public/platform/web_url_error.h"
130#include "third_party/blink/public/platform/web_url_request.h"
131#include "third_party/blink/public/platform/web_url_response.h"
132#include "third_party/blink/public/platform/web_vector.h"
133#include "third_party/blink/public/public_buildflags.h"
134#include "third_party/blink/public/web/web_autofill_client.h"
135#include "third_party/blink/public/web/web_ax_object.h"
136#include "third_party/blink/public/web/web_date_time_chooser_completion.h"
137#include "third_party/blink/public/web/web_date_time_chooser_params.h"
138#include "third_party/blink/public/web/web_document.h"
139#include "third_party/blink/public/web/web_dom_event.h"
140#include "third_party/blink/public/web/web_dom_message_event.h"
141#include "third_party/blink/public/web/web_element.h"
142#include "third_party/blink/public/web/web_file_chooser_params.h"
143#include "third_party/blink/public/web/web_form_control_element.h"
144#include "third_party/blink/public/web/web_form_element.h"
145#include "third_party/blink/public/web/web_frame.h"
146#include "third_party/blink/public/web/web_frame_content_dumper.h"
147#include "third_party/blink/public/web/web_frame_widget.h"
148#include "third_party/blink/public/web/web_history_item.h"
149#include "third_party/blink/public/web/web_hit_test_result.h"
150#include "third_party/blink/public/web/web_input_element.h"
151#include "third_party/blink/public/web/web_local_frame.h"
Blink Reformata30d4232018-04-07 15:31:06152#include "third_party/blink/public/web/web_navigation_policy.h"
153#include "third_party/blink/public/web/web_page_importance_signals.h"
154#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"
estade6b9696bd2016-05-04 23:51:36186#include "content/renderer/android/disambiguation_popup_helper.h"
tfarina3b0452d2014-12-31 15:20:09187#include "ui/gfx/geometry/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40188
[email protected]78043bdd2010-04-05 18:45:33189#elif defined(OS_MACOSX)
190#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57191#endif
192
brettw4b461082016-11-19 18:55:16193#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]ea2fb972013-08-07 05:44:26194#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
195#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26196#endif
197
[email protected]180ef242013-11-07 06:50:46198using blink::WebAXObject;
199using blink::WebApplicationCacheHost;
200using blink::WebApplicationCacheHostClient;
[email protected]180ef242013-11-07 06:50:46201using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46202using blink::WebData;
[email protected]180ef242013-11-07 06:50:46203using blink::WebDocument;
[email protected]180ef242013-11-07 06:50:46204using blink::WebDragOperation;
[email protected]180ef242013-11-07 06:50:46205using blink::WebElement;
[email protected]180ef242013-11-07 06:50:46206using blink::WebFileChooserCompletion;
[email protected]180ef242013-11-07 06:50:46207using blink::WebFormControlElement;
208using blink::WebFormElement;
209using blink::WebFrame;
dglazkov03223492016-02-08 22:16:03210using blink::WebFrameContentDumper;
[email protected]180ef242013-11-07 06:50:46211using blink::WebGestureEvent;
212using blink::WebHistoryItem;
213using blink::WebHTTPBody;
dglazkov8d0c21dd2016-08-06 15:56:36214using blink::WebHitTestResult;
[email protected]180ef242013-11-07 06:50:46215using blink::WebImage;
216using blink::WebInputElement;
217using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22218using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46219using blink::WebMouseEvent;
220using blink::WebNavigationPolicy;
221using blink::WebNavigationType;
222using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46223using blink::WebPluginAction;
[email protected]180ef242013-11-07 06:50:46224using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46225using blink::WebRect;
226using blink::WebReferrerPolicy;
Daniel Chengd5e56ff2017-06-24 07:44:02227using blink::WebSandboxFlags;
[email protected]180ef242013-11-07 06:50:46228using blink::WebScriptSource;
229using blink::WebSearchableFormData;
230using blink::WebSecurityOrigin;
231using blink::WebSecurityPolicy;
[email protected]180ef242013-11-07 06:50:46232using blink::WebSettings;
233using blink::WebSize;
[email protected]180ef242013-11-07 06:50:46234using blink::WebString;
[email protected]180ef242013-11-07 06:50:46235using blink::WebTextDirection;
236using blink::WebTouchEvent;
237using blink::WebURL;
238using blink::WebURLError;
239using blink::WebURLRequest;
240using blink::WebURLResponse;
241using blink::WebUserGestureIndicator;
242using blink::WebVector;
243using blink::WebView;
244using blink::WebWidget;
245using blink::WebWindowFeatures;
[email protected]b3a97b52014-07-09 06:25:05246using blink::WebRuntimeFeatures;
[email protected]6fdd4182010-10-14 23:59:26247using base::TimeDelta;
[email protected]e1acf6f2008-10-27 20:43:33248
[email protected]20657a82012-08-21 20:23:03249
[email protected]e9ff79c2012-10-19 21:31:26250namespace content {
251
initial.commit09911bf2008-07-26 23:55:29252//-----------------------------------------------------------------------------
253
[email protected]180ef242013-11-07 06:50:46254typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
jbroman8319b232017-03-08 22:53:29255static base::LazyInstance<ViewMap>::Leaky g_view_map =
[email protected]058561b2012-12-03 06:48:22256 LAZY_INSTANCE_INITIALIZER;
scottmg5e65e3a2017-03-08 08:48:46257typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap;
jbroman8319b232017-03-08 22:53:29258static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map =
259 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02260
[email protected]882daa92009-11-05 16:31:31261// Time, in seconds, we delay before sending content state changes (such as form
262// state and scroll position) to the browser. We delay sending changes to avoid
263// spamming the browser.
264// To avoid having tab/session restore require sending a message to get the
265// current content state during tab closing we use a shorter timeout for the
266// foreground renderer. This means there is a small window of time from which
267// content state is modified and not sent to session restore, but this is
268// better than having to wake up all renderers during shutdown.
avif937e1d2014-11-02 18:13:07269const int kDelaySecondsForContentStateSyncHidden = 5;
270const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29271
dcheng35d31c112015-07-22 00:17:36272static RenderViewImpl* (*g_create_render_view_impl)(
273 CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15274 const mojom::CreateViewParams&) = nullptr;
[email protected]8d41d7612012-11-14 20:32:19275
[email protected]c6bc20332014-02-28 18:30:39276// static
[email protected]e507045d2013-07-24 15:23:44277Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56278 WebFrame* frame,
279 const WebURLRequest& request) {
Blink Reformat1c4d759e2017-04-09 16:34:54280 return Referrer(blink::WebStringToGURL(
281 request.HttpHeaderField(WebString::FromUTF8("Referer"))),
282 request.GetReferrerPolicy());
[email protected]44e55b012013-07-23 14:21:56283}
284
[email protected]c6bc20332014-02-28 18:30:39285// static
[email protected]65920f332014-03-04 21:14:18286WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32287 WebNavigationPolicy policy) {
288 switch (policy) {
Blink Reformat1c4d759e2017-04-09 16:34:54289 case blink::kWebNavigationPolicyIgnore:
nick3b04f322016-08-31 19:29:19290 return WindowOpenDisposition::IGNORE_ACTION;
Blink Reformat1c4d759e2017-04-09 16:34:54291 case blink::kWebNavigationPolicyDownload:
nick3b04f322016-08-31 19:29:19292 return WindowOpenDisposition::SAVE_TO_DISK;
Blink Reformat1c4d759e2017-04-09 16:34:54293 case blink::kWebNavigationPolicyCurrentTab:
nick3b04f322016-08-31 19:29:19294 return WindowOpenDisposition::CURRENT_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54295 case blink::kWebNavigationPolicyNewBackgroundTab:
nick3b04f322016-08-31 19:29:19296 return WindowOpenDisposition::NEW_BACKGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54297 case blink::kWebNavigationPolicyNewForegroundTab:
nick3b04f322016-08-31 19:29:19298 return WindowOpenDisposition::NEW_FOREGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54299 case blink::kWebNavigationPolicyNewWindow:
nick3b04f322016-08-31 19:29:19300 return WindowOpenDisposition::NEW_WINDOW;
Blink Reformat1c4d759e2017-04-09 16:34:54301 case blink::kWebNavigationPolicyNewPopup:
nick3b04f322016-08-31 19:29:19302 return WindowOpenDisposition::NEW_POPUP;
[email protected]48861e22013-01-09 00:27:32303 default:
304 NOTREACHED() << "Unexpected WebNavigationPolicy";
nick3b04f322016-08-31 19:29:19305 return WindowOpenDisposition::IGNORE_ACTION;
[email protected]48861e22013-01-09 00:27:32306 }
307}
308
initial.commit09911bf2008-07-26 23:55:29309///////////////////////////////////////////////////////////////////////////////
310
[email protected]217690d2012-01-27 07:33:11311namespace {
312
[email protected]b3a97b52014-07-09 06:25:05313typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
314 const base::string16&,
315 UScriptCode);
316
317void SetStandardFontFamilyWrapper(WebSettings* settings,
318 const base::string16& font,
319 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54320 settings->SetStandardFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05321}
322
323void SetFixedFontFamilyWrapper(WebSettings* settings,
324 const base::string16& font,
325 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54326 settings->SetFixedFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05327}
328
329void SetSerifFontFamilyWrapper(WebSettings* settings,
330 const base::string16& font,
331 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54332 settings->SetSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05333}
334
335void SetSansSerifFontFamilyWrapper(WebSettings* settings,
336 const base::string16& font,
337 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54338 settings->SetSansSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05339}
340
341void SetCursiveFontFamilyWrapper(WebSettings* settings,
342 const base::string16& font,
343 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54344 settings->SetCursiveFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05345}
346
347void SetFantasyFontFamilyWrapper(WebSettings* settings,
348 const base::string16& font,
349 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54350 settings->SetFantasyFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05351}
352
353void SetPictographFontFamilyWrapper(WebSettings* settings,
354 const base::string16& font,
355 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54356 settings->SetPictographFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05357}
358
359// If |scriptCode| is a member of a family of "similar" script codes, returns
360// the script code in that family that is used by WebKit for font selection
361// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
362// considered equivalent for the purposes of font selection. WebKit uses the
363// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
364// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
365// uses different scripts than the ones in Chrome pref names because the version
366// of ICU included on certain ports does not have some of the newer scripts. If
367// |scriptCode| is not a member of such a family, returns |scriptCode|.
368UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
369 switch (scriptCode) {
370 case USCRIPT_HIRAGANA:
371 case USCRIPT_KATAKANA:
372 case USCRIPT_JAPANESE:
373 return USCRIPT_KATAKANA_OR_HIRAGANA;
374 case USCRIPT_KOREAN:
375 return USCRIPT_HANGUL;
376 default:
377 return scriptCode;
378 }
379}
380
381void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
382 SetFontFamilyWrapper setter,
383 WebSettings* settings) {
384 for (ScriptFontFamilyMap::const_iterator it = map.begin(); it != map.end();
385 ++it) {
avi1023d012015-12-25 02:39:14386 int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
[email protected]b3a97b52014-07-09 06:25:05387 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
388 UScriptCode code = static_cast<UScriptCode>(script);
389 (*setter)(settings, it->second, GetScriptForWebSettings(code));
390 }
391 }
392}
393
wangxianzhu3bf39be52015-04-10 23:56:41394void ApplyBlinkSettings(const base::CommandLine& command_line,
395 WebSettings* settings) {
396 if (!command_line.HasSwitch(switches::kBlinkSettings))
397 return;
398
brettw26dab8f02015-08-08 00:28:47399 std::vector<std::string> blink_settings = base::SplitString(
400 command_line.GetSwitchValueASCII(switches::kBlinkSettings),
401 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
wangxianzhu3bf39be52015-04-10 23:56:41402 for (const std::string& setting : blink_settings) {
403 size_t pos = setting.find('=');
Blink Reformat1c4d759e2017-04-09 16:34:54404 settings->SetFromStrings(
405 blink::WebString::FromLatin1(setting.substr(0, pos)),
406 blink::WebString::FromLatin1(
wangxianzhu3bf39be52015-04-10 23:56:41407 pos == std::string::npos ? "" : setting.substr(pos + 1)));
408 }
409}
410
scottmgde42fb92017-02-10 17:56:03411content::mojom::WindowContainerType WindowFeaturesToContainerType(
scottmg05324cb2017-02-09 23:46:04412 const blink::WebWindowFeatures& window_features) {
japhetbfc47892017-06-02 23:01:19413 if (window_features.background) {
414 if (window_features.persistent)
scottmgde42fb92017-02-10 17:56:03415 return content::mojom::WindowContainerType::PERSISTENT;
scottmg05324cb2017-02-09 23:46:04416 else
scottmgde42fb92017-02-10 17:56:03417 return content::mojom::WindowContainerType::BACKGROUND;
scottmg05324cb2017-02-09 23:46:04418 } else {
scottmgde42fb92017-02-10 17:56:03419 return content::mojom::WindowContainerType::NORMAL;
scottmg05324cb2017-02-09 23:46:04420 }
421}
422
[email protected]217690d2012-01-27 07:33:11423} // namespace
424
Hajime Hoshiabb3c8f2017-12-04 18:41:39425RenderViewImpl::RenderViewImpl(
426 CompositorDependencies* compositor_deps,
427 const mojom::CreateViewParams& params,
428 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
Albert J. Wongcb004632018-07-10 22:58:25429 : RenderWidget(params.main_frame_widget_routing_id,
nick8331f8ad2016-11-15 20:42:45430 compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54431 blink::kWebPopupTypeNone,
Fady Samuelff5b6eb562018-05-01 16:16:08432 params.visual_properties.screen_info,
naskobd911332014-11-25 01:13:36433 params.swapped_out,
434 params.hidden,
Hajime Hoshiabb3c8f2017-12-04 18:41:39435 params.never_visible,
436 task_runner),
Albert J. Wongcb004632018-07-10 22:58:25437 routing_id_(params.view_id),
naskobd911332014-11-25 01:13:36438 webkit_preferences_(params.web_preferences),
changwand659e202016-06-13 02:39:12439 session_storage_namespace_id_(params.session_storage_namespace_id),
wjmaclean1d970622017-01-21 22:28:24440 weak_ptr_factory_(this) {
avi40b5be7a2016-03-03 21:13:44441 GetWidget()->set_owner_delegate(this);
Albert J. Wongcb004632018-07-10 22:58:25442 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]075366912013-02-18 07:13:24443}
444
nickf7b38222016-11-22 21:59:35445void RenderViewImpl::Initialize(
Balazs Engedyba034e72017-10-27 22:26:28446 mojom::CreateViewParamsPtr params,
danakjdf1ceb72018-07-18 20:02:25447 RenderWidget::ShowCallback show_callback,
Hajime Hoshif34374412018-03-05 14:32:54448 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
danakj53802692018-07-25 21:46:44449 bool has_show_callback = !!show_callback;
nickf7b38222016-11-22 21:59:35450#if defined(OS_ANDROID)
451 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated
452 // HandleNavigation codepath.
danakj53802692018-07-25 21:46:44453 was_created_by_renderer_ = has_show_callback;
nickf7b38222016-11-22 21:59:35454#endif
Lukasz Anforowiczaf2f33572018-01-17 14:05:08455 renderer_wide_named_frame_lookup_ = params->renderer_wide_named_frame_lookup;
danakj53802692018-07-25 21:46:44456 RenderWidget::set_display_mode(params->visual_properties.display_mode);
[email protected]676126f72011-01-15 00:03:51457
Lukasz Anforowiczaf2f33572018-01-17 14:05:08458 WebFrame* opener_frame =
459 RenderFrameImpl::ResolveOpener(params->opener_frame_route_id);
460
danakj9a8a9cf2018-07-17 23:52:12461 // Pass WidgetClient(), not |this|, as the WebWidgetClient. The method may
462 // be overridden in layout tests to inject a test-only WebWidgetClient.
Lukasz Anforowiczaf2f33572018-01-17 14:05:08463 webview_ =
danakj9a8a9cf2018-07-17 23:52:12464 WebView::Create(this, WidgetClient(),
Lukasz Anforowiczaf2f33572018-01-17 14:05:08465 is_hidden() ? blink::mojom::PageVisibilityState::kHidden
466 : blink::mojom::PageVisibilityState::kVisible,
467 opener_frame ? opener_frame->View() : nullptr);
danakjdf1ceb72018-07-18 20:02:25468 RenderWidget::Init(std::move(show_callback), webview_->GetWidget());
[email protected]11fee2332011-03-29 20:36:35469
nasko4c0feb62015-06-05 18:37:06470 g_view_map.Get().insert(std::make_pair(webview(), this));
avia3dca182016-03-19 01:09:52471 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this));
nasko4c0feb62015-06-05 18:37:06472
avi83883c82014-12-23 00:08:49473 const base::CommandLine& command_line =
474 *base::CommandLine::ForCurrentProcess();
[email protected]20657a82012-08-21 20:23:03475
[email protected]27c521a2013-05-29 20:44:32476 if (command_line.HasSwitch(switches::kStatsCollectionController))
477 stats_collection_observer_.reset(new StatsCollectionObserver(this));
478
danakj53802692018-07-25 21:46:44479 webview()->SetDisplayMode(GetWidget()->display_mode());
Blink Reformat1c4d759e2017-04-09 16:34:54480 webview()->GetSettings()->SetThreadedScrollingEnabled(
dcheng0ff94cfc2016-03-15 21:50:51481 !command_line.HasSwitch(switches::kDisableThreadedScrolling));
Blink Reformat1c4d759e2017-04-09 16:34:54482 webview()->SetShowFPSCounter(
dcheng0ff94cfc2016-03-15 21:50:51483 command_line.HasSwitch(cc::switches::kShowFPSCounter));
484
danakj39f68122018-07-16 20:11:46485 ApplyWebPreferencesInternal(webkit_preferences_, webview());
dcheng0ff94cfc2016-03-15 21:50:51486
487 if (switches::IsTouchDragDropEnabled())
Blink Reformat1c4d759e2017-04-09 16:34:54488 webview()->GetSettings()->SetTouchDragDropEnabled(true);
dcheng0ff94cfc2016-03-15 21:50:51489
490 WebSettings::SelectionStrategyType selection_strategy =
Blink Reformat1c4d759e2017-04-09 16:34:54491 WebSettings::SelectionStrategyType::kCharacter;
dcheng0ff94cfc2016-03-15 21:50:51492 const std::string selection_strategy_str =
Gyuyoung Kim63abad22018-06-15 03:16:55493 command_line.GetSwitchValueASCII(switches::kTouchTextSelectionStrategy);
dcheng0ff94cfc2016-03-15 21:50:51494 if (selection_strategy_str == "direction")
Blink Reformat1c4d759e2017-04-09 16:34:54495 selection_strategy = WebSettings::SelectionStrategyType::kDirection;
496 webview()->GetSettings()->SetSelectionStrategy(selection_strategy);
dcheng0ff94cfc2016-03-15 21:50:51497
Gyuyoung Kim63abad22018-06-15 03:16:55498 std::string passive_listeners_default =
dtapuskaf65650b2016-05-13 17:21:34499 command_line.GetSwitchValueASCII(switches::kPassiveListenersDefault);
Gyuyoung Kim63abad22018-06-15 03:16:55500 if (!passive_listeners_default.empty()) {
dtapuskaf65650b2016-05-13 17:21:34501 WebSettings::PassiveEventListenerDefault passiveDefault =
Blink Reformat1c4d759e2017-04-09 16:34:54502 WebSettings::PassiveEventListenerDefault::kFalse;
Gyuyoung Kim63abad22018-06-15 03:16:55503 if (passive_listeners_default == "true")
Blink Reformat1c4d759e2017-04-09 16:34:54504 passiveDefault = WebSettings::PassiveEventListenerDefault::kTrue;
Gyuyoung Kim63abad22018-06-15 03:16:55505 else if (passive_listeners_default == "forcealltrue")
Blink Reformat1c4d759e2017-04-09 16:34:54506 passiveDefault = WebSettings::PassiveEventListenerDefault::kForceAllTrue;
507 webview()->GetSettings()->SetPassiveEventListenerDefault(passiveDefault);
dtapuskaf65650b2016-05-13 17:21:34508 }
509
Gyuyoung Kim63abad22018-06-15 03:16:55510 std::string fmp_network_quiet_timeout =
511 command_line.GetSwitchValueASCII(switches::kFMPNetworkQuietTimeout);
512 if (!fmp_network_quiet_timeout.empty()) {
513 double fmp_network_quiet_timeout_seconds = 0.0;
514 if (base::StringToDouble(fmp_network_quiet_timeout,
515 &fmp_network_quiet_timeout_seconds)) {
516 webview()->GetSettings()->SetFMPNetworkQuietTimeout(
517 fmp_network_quiet_timeout_seconds);
518 }
519 }
520
Blink Reformat1c4d759e2017-04-09 16:34:54521 ApplyBlinkSettings(command_line, webview()->GetSettings());
dcheng0ff94cfc2016-03-15 21:50:51522
Balazs Engedyba034e72017-10-27 22:26:28523 if (params->main_frame_routing_id != MSG_ROUTING_NONE) {
Ken Rockot26efbd62017-11-16 04:39:49524 CHECK(params->main_frame_interface_provider.is_valid());
525 service_manager::mojom::InterfaceProviderPtr main_frame_interface_provider(
526 std::move(params->main_frame_interface_provider));
dcheng3ce04b62015-10-26 23:30:55527 main_render_frame_ = RenderFrameImpl::CreateMainFrame(
Balazs Engedyba034e72017-10-27 22:26:28528 this, params->main_frame_routing_id,
Ken Rockot26efbd62017-11-16 04:39:49529 std::move(main_frame_interface_provider),
Fady Samuela863f152018-03-09 16:10:03530 params->main_frame_widget_routing_id, params->hidden,
danakj53802692018-07-25 21:46:44531 GetWidget()->GetWebScreenInfo(), GetWidget()->compositor_deps(),
532 opener_frame, params->devtools_main_frame_token,
533 params->replicated_frame_state, params->has_committed_real_load);
dchengc5ef1a52015-08-26 20:58:30534 }
535
Daniel Chengd5e56ff2017-06-24 07:44:02536 // TODO(dcheng): Shouldn't these be mutually exclusive at this point? See
537 // https://crbug.com/720116 where the browser is apparently sending both
538 // routing IDs...
Balazs Engedyba034e72017-10-27 22:26:28539 if (params->proxy_routing_id != MSG_ROUTING_NONE) {
540 CHECK(params->swapped_out);
541 RenderFrameProxy::CreateFrameProxy(params->proxy_routing_id, GetRoutingID(),
nick3b5a21f2016-11-22 23:07:11542 opener_frame, MSG_ROUTING_NONE,
Dmitry Gozman89361212018-02-13 16:10:44543 params->replicated_frame_state,
544 params->devtools_main_frame_token);
nasko4c0feb62015-06-05 18:37:06545 }
546
nasko4c0feb62015-06-05 18:37:06547 if (main_render_frame_)
548 main_render_frame_->Initialize();
549
nickf7b38222016-11-22 21:59:35550 // If this RenderView's creation was initiated by an opener page in this
551 // process, (e.g. window.open()), we won't be visible until we ask the opener,
danakj53802692018-07-25 21:46:44552 // via |show_callback|, to make us visible. Otherwise, we went through a
553 // browser-initiated creation, and Show() won't be called. In this case, no
554 // |show_callback| is given to inform that Show() won't be called.
555 if (!has_show_callback)
556 RenderWidget::set_did_show();
mfomitchev5ad034ec2015-04-24 21:57:27557
[email protected]c7c0d822014-04-16 20:19:49558 // TODO(davidben): Move this state from Blink into content.
Balazs Engedyba034e72017-10-27 22:26:28559 if (params->window_was_created_with_opener)
Blink Reformat1c4d759e2017-04-09 16:34:54560 webview()->SetOpenedByDOM();
[email protected]c7c0d822014-04-16 20:19:49561
dcheng0ff94cfc2016-03-15 21:50:51562 UpdateWebViewWithDeviceScaleFactor();
Balazs Engedyba034e72017-10-27 22:26:28563 OnSetRendererPrefs(params->renderer_preferences);
Fady Samuelff5b6eb562018-05-01 16:16:08564 OnSynchronizeVisualProperties(params->visual_properties);
danakja2c9d0a92018-07-25 20:01:18565 RenderWidget::SetUpIdleUserDetector();
[email protected]1784b2f2011-11-24 10:53:48566
[email protected]e9ff79c2012-10-19 21:31:26567 GetContentClient()->renderer()->RenderViewCreated(this);
akabac6bd1212018-06-25 20:10:48568 page_zoom_level_ = 0;
Hajime Hoshif34374412018-03-05 14:32:54569
570 nav_state_sync_timer_.SetTaskRunner(task_runner);
571 check_preferred_size_timer_.SetTaskRunner(std::move(task_runner));
initial.commit09911bf2008-07-26 23:55:29572}
573
[email protected]310ebd6302011-10-10 19:06:28574RenderViewImpl::~RenderViewImpl() {
dcheng3ce04b62015-10-26 23:30:55575 DCHECK(!frame_widget_);
Albert J. Wongcb004632018-07-10 22:58:25576 RenderThread::Get()->RemoveRoute(routing_id_);
dcheng3ce04b62015-10-26 23:30:55577
[email protected]8ed1d3f2013-02-20 11:45:55578#if defined(OS_ANDROID)
davve17e025e12016-05-23 15:30:20579 // The date/time picker client is both a std::unique_ptr member of this class
580 // and a RenderViewObserver. Reset it to prevent double deletion.
[email protected]8ed1d3f2013-02-20 11:45:55581 date_time_picker_client_.reset();
582#endif
583
[email protected]60c42a8c72009-10-09 04:08:59584#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22585 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49586 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59587 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
588 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22589 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
590 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
591 it != routing_id_views->end(); ++it)
592 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59593#endif
[email protected]676126f72011-01-15 00:03:51594
ericwilligers88e69742016-10-17 19:29:55595 for (auto& observer : observers_)
596 observer.RenderViewGone();
597 for (auto& observer : observers_)
598 observer.OnDestruct();
[email protected]60c42a8c72009-10-09 04:08:59599}
600
601/*static*/
[email protected]310ebd6302011-10-10 19:06:28602RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31603 ViewMap* views = g_view_map.Pointer();
604 ViewMap::iterator it = views->find(webview);
605 return it == views->end() ? NULL : it->second;
606}
607
608/*static*/
[email protected]180ef242013-11-07 06:50:46609RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28610 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31611}
612
613/*static*/
avi1023d012015-12-25 02:39:14614RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) {
[email protected]640e303c2012-12-05 01:36:07615 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
616 RoutingIDViewMap::iterator it = views->find(routing_id);
617 return it == views->end() ? NULL : it->second;
618}
619
620/*static*/
621RenderView* RenderView::FromRoutingID(int routing_id) {
622 return RenderViewImpl::FromRoutingID(routing_id);
623}
624
[email protected]f3a95312014-06-12 16:46:58625/* static */
jochen9c7b8f242015-06-01 15:32:02626size_t RenderView::GetRenderViewCount() {
[email protected]f3a95312014-06-12 16:46:58627 return g_view_map.Get().size();
628}
629
[email protected]640e303c2012-12-05 01:36:07630/*static*/
[email protected]e9ff79c2012-10-19 21:31:26631void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49632 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59633 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
634 if (!visitor->Visit(it->second))
635 return;
636 }
637}
638
639/*static*/
[email protected]b3a97b52014-07-09 06:25:05640void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
641 WebView* web_view) {
Blink Reformat1c4d759e2017-04-09 16:34:54642 WebSettings* settings = web_view->GetSettings();
[email protected]b3a97b52014-07-09 06:25:05643 ApplyFontsFromMap(prefs.standard_font_family_map,
644 SetStandardFontFamilyWrapper, settings);
645 ApplyFontsFromMap(prefs.fixed_font_family_map,
646 SetFixedFontFamilyWrapper, settings);
647 ApplyFontsFromMap(prefs.serif_font_family_map,
648 SetSerifFontFamilyWrapper, settings);
649 ApplyFontsFromMap(prefs.sans_serif_font_family_map,
650 SetSansSerifFontFamilyWrapper, settings);
651 ApplyFontsFromMap(prefs.cursive_font_family_map,
652 SetCursiveFontFamilyWrapper, settings);
653 ApplyFontsFromMap(prefs.fantasy_font_family_map,
654 SetFantasyFontFamilyWrapper, settings);
655 ApplyFontsFromMap(prefs.pictograph_font_family_map,
656 SetPictographFontFamilyWrapper, settings);
Blink Reformat1c4d759e2017-04-09 16:34:54657 settings->SetDefaultFontSize(prefs.default_font_size);
658 settings->SetDefaultFixedFontSize(prefs.default_fixed_font_size);
659 settings->SetMinimumFontSize(prefs.minimum_font_size);
660 settings->SetMinimumLogicalFontSize(prefs.minimum_logical_font_size);
661 settings->SetDefaultTextEncodingName(
662 WebString::FromASCII(prefs.default_encoding));
663 settings->SetJavaScriptEnabled(prefs.javascript_enabled);
664 settings->SetWebSecurityEnabled(prefs.web_security_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54665 settings->SetLoadsImagesAutomatically(prefs.loads_images_automatically);
666 settings->SetImagesEnabled(prefs.images_enabled);
667 settings->SetPluginsEnabled(prefs.plugins_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54668 settings->SetDOMPasteAllowed(prefs.dom_paste_enabled);
669 settings->SetTextAreasAreResizable(prefs.text_areas_are_resizable);
670 settings->SetAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
671 settings->SetDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
672 settings->SetJavaScriptCanAccessClipboard(
[email protected]b3a97b52014-07-09 06:25:05673 prefs.javascript_can_access_clipboard);
Blink Reformat1c4d759e2017-04-09 16:34:54674 WebRuntimeFeatures::EnableXSLT(prefs.xslt_enabled);
675 settings->SetXSSAuditorEnabled(prefs.xss_auditor_enabled);
676 settings->SetDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
Tarun Bansal333819e2018-05-15 16:38:42677 blink::WebNetworkStateNotifier::SetSaveDataEnabled(prefs.data_saver_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54678 settings->SetLocalStorageEnabled(prefs.local_storage_enabled);
679 settings->SetSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
680 WebRuntimeFeatures::EnableDatabase(prefs.databases_enabled);
681 settings->SetOfflineWebApplicationCacheEnabled(
[email protected]b3a97b52014-07-09 06:25:05682 prefs.application_cache_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54683 settings->SetHistoryEntryRequiresUserGesture(
japhet5018fe62016-09-14 19:14:04684 prefs.history_entry_requires_user_gesture);
Chris Palmer917bc052018-03-14 19:28:31685 settings->SetShouldThrottlePushState(!prefs.disable_pushstate_throttle);
Blink Reformat1c4d759e2017-04-09 16:34:54686 settings->SetHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
687 settings->SetCookieEnabled(prefs.cookie_enabled);
688 settings->SetNavigateOnDragDrop(prefs.navigate_on_drag_drop);
[email protected]b3a97b52014-07-09 06:25:05689
[email protected]b3a97b52014-07-09 06:25:05690 // By default, allow_universal_access_from_file_urls is set to false and thus
691 // we mitigate attacks from local HTML files by not granting file:// URLs
692 // universal access. Only test shell will enable this.
Blink Reformat1c4d759e2017-04-09 16:34:54693 settings->SetAllowUniversalAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05694 prefs.allow_universal_access_from_file_urls);
Blink Reformat1c4d759e2017-04-09 16:34:54695 settings->SetAllowFileAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05696 prefs.allow_file_access_from_file_urls);
697
Zhenyao Moa3fda9972017-09-16 01:34:40698 settings->SetWebGL1Enabled(prefs.webgl1_enabled);
699 settings->SetWebGL2Enabled(prefs.webgl2_enabled);
[email protected]b3a97b52014-07-09 06:25:05700
[email protected]b3a97b52014-07-09 06:25:05701 // Enable WebGL errors to the JS console if requested.
Blink Reformat1c4d759e2017-04-09 16:34:54702 settings->SetWebGLErrorsToConsoleEnabled(
[email protected]b3a97b52014-07-09 06:25:05703 prefs.webgl_errors_to_console_enabled);
704
705 // Uses the mock theme engine for scrollbars.
Blink Reformat1c4d759e2017-04-09 16:34:54706 settings->SetMockScrollbarsEnabled(prefs.mock_scrollbars_enabled);
[email protected]b3a97b52014-07-09 06:25:05707
Blink Reformat1c4d759e2017-04-09 16:34:54708 settings->SetHideScrollbars(prefs.hide_scrollbars);
eseckler61ff9142016-09-23 22:57:59709
[email protected]b3a97b52014-07-09 06:25:05710 // Enable gpu-accelerated 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54711 WebRuntimeFeatures::EnableAccelerated2dCanvas(
junov524668f22016-08-08 20:16:52712 prefs.accelerated_2d_canvas_enabled);
[email protected]b3a97b52014-07-09 06:25:05713
Blink Reformat1c4d759e2017-04-09 16:34:54714 settings->SetMinimumAccelerated2dCanvasSize(
[email protected]b3a97b52014-07-09 06:25:05715 prefs.minimum_accelerated_2d_canvas_size);
716
717 // Disable antialiasing for 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54718 settings->SetAntialiased2dCanvasEnabled(
[email protected]b3a97b52014-07-09 06:25:05719 !prefs.antialiased_2d_canvas_disabled);
720
zakerinasab20ebca02016-09-27 14:22:34721 // Disable antialiasing of clips for 2d canvas if requested on the command
robertphillipse25137b2014-10-20 13:44:34722 // line.
Blink Reformat1c4d759e2017-04-09 16:34:54723 settings->SetAntialiasedClips2dCanvasEnabled(
robertphillipse25137b2014-10-20 13:44:34724 prefs.antialiased_clips_2d_canvas_enabled);
725
[email protected]b3a97b52014-07-09 06:25:05726 // Set MSAA sample count for 2d canvas if requested on the command line (or
727 // default value if not).
Blink Reformat1c4d759e2017-04-09 16:34:54728 settings->SetAccelerated2dCanvasMSAASampleCount(
[email protected]b3a97b52014-07-09 06:25:05729 prefs.accelerated_2d_canvas_msaa_sample_count);
730
[email protected]b3a97b52014-07-09 06:25:05731 // Tabs to link is not part of the settings. WebCore calls
732 // ChromeClient::tabsToLinks which is part of the glue code.
Blink Reformat1c4d759e2017-04-09 16:34:54733 web_view->SetTabsToLinks(prefs.tabs_to_links);
[email protected]b3a97b52014-07-09 06:25:05734
Blink Reformat1c4d759e2017-04-09 16:34:54735 settings->SetAllowRunningOfInsecureContent(
[email protected]b3a97b52014-07-09 06:25:05736 prefs.allow_running_insecure_content);
Blink Reformat1c4d759e2017-04-09 16:34:54737 settings->SetDisableReadingFromCanvas(prefs.disable_reading_from_canvas);
738 settings->SetStrictMixedContentChecking(prefs.strict_mixed_content_checking);
mkwst2384c8222015-07-30 07:26:47739
Blink Reformat1c4d759e2017-04-09 16:34:54740 settings->SetStrictlyBlockBlockableMixedContent(
mkwst2384c8222015-07-30 07:26:47741 prefs.strictly_block_blockable_mixed_content);
742
Blink Reformat1c4d759e2017-04-09 16:34:54743 settings->SetStrictMixedContentCheckingForPlugin(
mkwst0d233e52015-08-10 09:33:14744 prefs.block_mixed_plugin_content);
745
Blink Reformat1c4d759e2017-04-09 16:34:54746 settings->SetStrictPowerfulFeatureRestrictions(
mkwst673a452f2015-01-10 14:41:50747 prefs.strict_powerful_feature_restrictions);
Blink Reformat1c4d759e2017-04-09 16:34:54748 settings->SetAllowGeolocationOnInsecureOrigins(
jww9d4ca2d2016-01-19 20:58:59749 prefs.allow_geolocation_on_insecure_origins);
Blink Reformat1c4d759e2017-04-09 16:34:54750 settings->SetPasswordEchoEnabled(prefs.password_echo_enabled);
751 settings->SetShouldPrintBackgrounds(prefs.should_print_backgrounds);
752 settings->SetShouldClearDocumentBackground(
[email protected]b3a97b52014-07-09 06:25:05753 prefs.should_clear_document_background);
Blink Reformat1c4d759e2017-04-09 16:34:54754 settings->SetEnableScrollAnimator(prefs.enable_scroll_animator);
[email protected]b3a97b52014-07-09 06:25:05755
Blink Reformat1c4d759e2017-04-09 16:34:54756 WebRuntimeFeatures::EnableTouchEventFeatureDetection(
sunyunjiafa6a8afc2016-12-09 04:25:47757 prefs.touch_event_feature_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54758 settings->SetMaxTouchPoints(prefs.pointer_events_max_touch_points);
759 settings->SetAvailablePointerTypes(prefs.available_pointer_types);
760 settings->SetPrimaryPointerType(
nzolghadrc0d1663c2015-11-26 21:15:24761 static_cast<blink::PointerType>(prefs.primary_pointer_type));
Blink Reformat1c4d759e2017-04-09 16:34:54762 settings->SetAvailableHoverTypes(prefs.available_hover_types);
763 settings->SetPrimaryHoverType(
nzolghadrc0d1663c2015-11-26 21:15:24764 static_cast<blink::HoverType>(prefs.primary_hover_type));
Blink Reformat1c4d759e2017-04-09 16:34:54765 settings->SetEnableTouchAdjustment(prefs.touch_adjustment_enabled);
Dave Tapuskaa59fdb62017-08-23 16:28:27766 settings->SetBarrelButtonForDragEnabled(prefs.barrel_button_for_drag_enabled);
[email protected]b3a97b52014-07-09 06:25:05767
Blink Reformat1c4d759e2017-04-09 16:34:54768 settings->SetShouldRespectImageOrientation(
[email protected]b3a97b52014-07-09 06:25:05769 prefs.should_respect_image_orientation);
770
Blink Reformat1c4d759e2017-04-09 16:34:54771 settings->SetEditingBehavior(
[email protected]b3a97b52014-07-09 06:25:05772 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
773
Blink Reformat1c4d759e2017-04-09 16:34:54774 settings->SetSupportsMultipleWindows(prefs.supports_multiple_windows);
[email protected]b3a97b52014-07-09 06:25:05775
Blink Reformat1c4d759e2017-04-09 16:34:54776 settings->SetMainFrameClipsContent(!prefs.record_whole_document);
khushalsagar2da2b232016-03-23 22:11:35777
Blink Reformat1c4d759e2017-04-09 16:34:54778 settings->SetSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
[email protected]b3a97b52014-07-09 06:25:05779
Blink Reformat1c4d759e2017-04-09 16:34:54780 settings->SetSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
[email protected]b3a97b52014-07-09 06:25:05781
Blink Reformat1c4d759e2017-04-09 16:34:54782 settings->SetSelectionIncludesAltImageText(true);
[email protected]b3a97b52014-07-09 06:25:05783
Blink Reformat1c4d759e2017-04-09 16:34:54784 settings->SetV8CacheOptions(
[email protected]35103c02014-08-12 15:08:47785 static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options));
786
Blink Reformat1c4d759e2017-04-09 16:34:54787 settings->SetImageAnimationPolicy(
je_julie.kim7fbb5a1a2015-02-09 17:26:05788 static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy));
789
Blink Reformat1c4d759e2017-04-09 16:34:54790 settings->SetPresentationRequiresUserGesture(
zqzhang1215ad422016-02-10 13:27:22791 prefs.user_gesture_required_for_presentation);
792
Blink Reformat1c4d759e2017-04-09 16:34:54793 settings->SetTextTrackMarginPercentage(prefs.text_track_margin_percentage);
halliwell4002be42016-03-18 18:33:40794
dcheng5ae8ca362015-02-05 04:03:47795 // Needs to happen before setIgnoreVIewportTagScaleLimits below.
Blink Reformat1c4d759e2017-04-09 16:34:54796 web_view->SetDefaultPageScaleLimits(prefs.default_minimum_page_scale_factor,
797 prefs.default_maximum_page_scale_factor);
dcheng5ae8ca362015-02-05 04:03:47798
Nate Chapin9638e7102017-09-20 22:11:01799 settings->SetSavePreviousDocumentResources(
800 static_cast<WebSettings::SavePreviousDocumentResources>(
801 prefs.save_previous_document_resources));
802
Ahmed Fakhry42221452018-05-30 01:18:39803 settings->SetTextAutosizingEnabled(prefs.text_autosizing_enabled);
804 settings->SetDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
805
[email protected]b3a97b52014-07-09 06:25:05806#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:54807 settings->SetAllowCustomScrollbarInMainFrame(false);
Blink Reformat1c4d759e2017-04-09 16:34:54808 settings->SetAccessibilityFontScaleFactor(prefs.font_scale_factor);
809 settings->SetDeviceScaleAdjustment(prefs.device_scale_adjustment);
810 settings->SetFullscreenSupported(prefs.fullscreen_supported);
811 web_view->SetIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
812 settings->SetAutoZoomFocusedNodeToLegibleScale(true);
Blink Reformat1c4d759e2017-04-09 16:34:54813 settings->SetMediaPlaybackGestureWhitelistScope(
814 blink::WebString::FromUTF8(prefs.media_playback_gesture_whitelist_scope));
815 settings->SetDefaultVideoPosterURL(
816 WebString::FromASCII(prefs.default_video_poster_url.spec()));
817 settings->SetSupportDeprecatedTargetDensityDPI(
[email protected]b3a97b52014-07-09 06:25:05818 prefs.support_deprecated_target_density_dpi);
Blink Reformat1c4d759e2017-04-09 16:34:54819 settings->SetUseLegacyBackgroundSizeShorthandBehavior(
[email protected]b3a97b52014-07-09 06:25:05820 prefs.use_legacy_background_size_shorthand_behavior);
Blink Reformat1c4d759e2017-04-09 16:34:54821 settings->SetWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
822 settings->SetUseWideViewport(prefs.use_wide_viewport);
823 settings->SetForceZeroLayoutHeight(prefs.force_zero_layout_height);
824 settings->SetViewportMetaLayoutSizeQuirk(
[email protected]b3a97b52014-07-09 06:25:05825 prefs.viewport_meta_layout_size_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54826 settings->SetViewportMetaMergeContentQuirk(
[email protected]b3a97b52014-07-09 06:25:05827 prefs.viewport_meta_merge_content_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54828 settings->SetViewportMetaNonUserScalableQuirk(
[email protected]b3a97b52014-07-09 06:25:05829 prefs.viewport_meta_non_user_scalable_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54830 settings->SetViewportMetaZeroValuesQuirk(
[email protected]b3a97b52014-07-09 06:25:05831 prefs.viewport_meta_zero_values_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54832 settings->SetClobberUserAgentInitialScaleQuirk(
[email protected]b3a97b52014-07-09 06:25:05833 prefs.clobber_user_agent_initial_scale_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54834 settings->SetIgnoreMainFrameOverflowHiddenQuirk(
[email protected]b3a97b52014-07-09 06:25:05835 prefs.ignore_main_frame_overflow_hidden_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54836 settings->SetReportScreenSizeInPhysicalPixelsQuirk(
[email protected]b3a97b52014-07-09 06:25:05837 prefs.report_screen_size_in_physical_pixels_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54838 settings->SetShouldReuseGlobalForUnownedMainFrame(
tzik30eb52c2018-03-27 06:55:18839 prefs.reuse_global_for_unowned_main_frame);
Blink Reformat1c4d759e2017-04-09 16:34:54840 settings->SetPreferHiddenVolumeControls(true);
841 settings->SetSpellCheckEnabledByDefault(prefs.spellcheck_enabled_by_default);
dalecurtiscd971252016-09-21 16:09:00842
aeliase678aa42017-04-14 22:41:04843 // Force preload=none and disable autoplay on older Android
dalecurtiscd971252016-09-21 16:09:00844 // platforms because their media pipelines are not stable enough to handle
845 // concurrent elements. See http://crbug.com/612909, http://crbug.com/622826.
aeliase678aa42017-04-14 22:41:04846 const bool is_jelly_bean =
dalecurtiscd971252016-09-21 16:09:00847 base::android::BuildInfo::GetInstance()->sdk_int() <=
aeliase678aa42017-04-14 22:41:04848 base::android::SDK_VERSION_JELLY_BEAN_MR2;
849 settings->SetForcePreloadNoneForMediaElements(is_jelly_bean);
mlamouri1d266bf2016-12-05 17:42:36850
Blink Reformat1c4d759e2017-04-09 16:34:54851 WebRuntimeFeatures::EnableVideoFullscreenOrientationLock(
mlamouri1d266bf2016-12-05 17:42:36852 prefs.video_fullscreen_orientation_lock_enabled);
johnme913ee5f2017-04-28 21:36:16853 WebRuntimeFeatures::EnableVideoRotateToFullscreen(
854 prefs.video_rotate_to_fullscreen_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54855 WebRuntimeFeatures::EnableVideoFullscreenDetection(
zqzhang93e959d12017-03-16 13:10:20856 prefs.video_fullscreen_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54857 settings->SetEmbeddedMediaExperienceEnabled(
shaktisahuf97f7532017-02-24 22:46:13858 prefs.embedded_media_experience_enabled);
Ian Vollickeeca1d82018-02-07 02:43:42859 settings->SetImmersiveModeEnabled(prefs.immersive_mode_enabled);
khushalsagarc5447db22017-08-22 17:53:01860 settings->SetMediaDownloadInProductHelpEnabled(
861 prefs.enable_media_download_in_product_help);
Blink Reformat1c4d759e2017-04-09 16:34:54862 settings->SetDoNotUpdateSelectionOnMutatingSelectionRange(
changwane54ccdb92017-04-05 19:20:54863 prefs.do_not_update_selection_on_mutating_selection_range);
Noel Gordonf311a842017-07-27 00:10:07864 WebRuntimeFeatures::EnableCSSHexAlphaColor(prefs.css_hex_alpha_color_enabled);
Tobias Sargeant416174f2017-09-01 01:18:09865 WebRuntimeFeatures::EnableScrollTopLeftInterop(
866 prefs.scroll_top_left_interop_enabled);
zqzhangdf72ed082016-12-08 16:07:55867#endif // defined(OS_ANDROID)
liberato9e934892016-05-03 19:00:27868
mlamouri55a0543c2017-05-11 10:34:07869 switch (prefs.autoplay_policy) {
870 case AutoplayPolicy::kNoUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28871 settings->SetAutoplayPolicy(
872 WebSettings::AutoplayPolicy::kNoUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07873 break;
874 case AutoplayPolicy::kUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28875 settings->SetAutoplayPolicy(
876 WebSettings::AutoplayPolicy::kUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07877 break;
878 case AutoplayPolicy::kUserGestureRequiredForCrossOrigin:
mlamouri276a6f32017-05-12 09:24:28879 settings->SetAutoplayPolicy(
880 WebSettings::AutoplayPolicy::kUserGestureRequiredForCrossOrigin);
mlamouri55a0543c2017-05-11 10:34:07881 break;
mlamouri431bb4e2017-06-06 08:54:24882 case AutoplayPolicy::kDocumentUserActivationRequired:
883 settings->SetAutoplayPolicy(
884 WebSettings::AutoplayPolicy::kDocumentUserActivationRequired);
885 break;
mlamouri55a0543c2017-05-11 10:34:07886 }
887
Blink Reformat1c4d759e2017-04-09 16:34:54888 settings->SetViewportEnabled(prefs.viewport_enabled);
889 settings->SetViewportMetaEnabled(prefs.viewport_meta_enabled);
890 settings->SetShrinksViewportContentToFit(
891 prefs.shrinks_viewport_contents_to_fit);
892 settings->SetViewportStyle(
alokp5d566962016-04-19 00:54:16893 static_cast<blink::WebViewportStyle>(prefs.viewport_style));
894
Blink Reformat1c4d759e2017-04-09 16:34:54895 settings->SetLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
896 settings->SetMainFrameResizesAreOrientationChanges(
yoava1a508b42015-10-20 12:03:21897 prefs.main_frame_resizes_are_orientation_changes);
898
Blink Reformat1c4d759e2017-04-09 16:34:54899 settings->SetUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
jinho.bang8f11ffa2014-12-04 06:03:03900
Blink Reformat1c4d759e2017-04-09 16:34:54901 settings->SetShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up);
902 settings->SetAlwaysShowContextMenuOnTouch(
amaralp547e4192016-06-03 19:17:35903 prefs.always_show_context_menu_on_touch);
Sandra Sunc79fc93a2018-04-10 15:22:23904 settings->SetSmoothScrollForFindEnabled(prefs.smooth_scroll_for_find_enabled);
ccameron2fd70de72015-02-19 00:40:40905
Blink Reformat1c4d759e2017-04-09 16:34:54906 settings->SetHideDownloadUI(prefs.hide_download_ui);
907 WebRuntimeFeatures::EnableBackgroundVideoTrackOptimization(
avayvod39c102402016-11-23 21:43:13908 prefs.background_video_track_optimization_enabled);
avayvod232757942017-04-29 04:12:34909 WebRuntimeFeatures::EnableNewRemotePlaybackPipeline(
910 base::FeatureList::IsEnabled(media::kNewRemotePlaybackPipeline));
qinmin72e8bd02016-10-21 19:35:37911
Blink Reformat1c4d759e2017-04-09 16:34:54912 settings->SetPresentationReceiver(prefs.presentation_receiver);
mlamouri57359d912016-11-29 20:11:50913
Blink Reformat1c4d759e2017-04-09 16:34:54914 settings->SetMediaControlsEnabled(prefs.media_controls_enabled);
mlamouri5cd9ae82017-02-18 11:05:09915
Tarun Bansal73d67f02018-01-17 05:56:25916 settings->SetLowPriorityIframesThreshold(
917 static_cast<blink::WebEffectiveConnectionType>(
918 prefs.low_priority_iframes_threshold));
919
Mounir Lamouri9c99a1602018-07-05 15:01:44920 settings->SetPictureInPictureEnabled(
921 prefs.picture_in_picture_enabled &&
922 MediaFactory::VideoSurfaceLayerEnabled());
François Beaufort8c08979fc2018-03-05 13:06:31923
Tarun Bansal333819e2018-05-15 16:38:42924 settings->SetDataSaverHoldbackWebApi(
925 prefs.data_saver_holdback_web_api_enabled);
926 settings->SetDataSaverHoldbackMediaApi(
927 prefs.data_saver_holdback_media_api_enabled);
928
Scott Little878f7d6702018-05-31 22:09:06929 for (const auto& ect_distance_pair :
930 prefs.lazy_frame_loading_distance_thresholds_px) {
931 switch (ect_distance_pair.first) {
932 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
933 settings->SetLazyFrameLoadingDistanceThresholdPxUnknown(
934 ect_distance_pair.second);
935 break;
936 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
937 settings->SetLazyFrameLoadingDistanceThresholdPxOffline(
938 ect_distance_pair.second);
939 break;
940 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
941 settings->SetLazyFrameLoadingDistanceThresholdPxSlow2G(
942 ect_distance_pair.second);
943 break;
944 case net::EFFECTIVE_CONNECTION_TYPE_2G:
945 settings->SetLazyFrameLoadingDistanceThresholdPx2G(
946 ect_distance_pair.second);
947 break;
948 case net::EFFECTIVE_CONNECTION_TYPE_3G:
949 settings->SetLazyFrameLoadingDistanceThresholdPx3G(
950 ect_distance_pair.second);
951 break;
952 case net::EFFECTIVE_CONNECTION_TYPE_4G:
953 settings->SetLazyFrameLoadingDistanceThresholdPx4G(
954 ect_distance_pair.second);
955 break;
956 default:
957 NOTREACHED();
958 }
959 }
960
ccameron2fd70de72015-02-19 00:40:40961#if defined(OS_MACOSX)
Blink Reformat1c4d759e2017-04-09 16:34:54962 settings->SetDoubleTapToZoomEnabled(true);
963 web_view->SetMaximumLegibleScale(prefs.default_maximum_page_scale_factor);
ccameron2fd70de72015-02-19 00:40:40964#endif
sunyunjia87f287b2016-09-09 00:38:13965
966#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:54967 WebRuntimeFeatures::EnableMiddleClickAutoscroll(true);
sunyunjia87f287b2016-09-09 00:38:13968#endif
[email protected]b3a97b52014-07-09 06:25:05969}
970
971/*static*/
nickf7b38222016-11-22 21:59:35972RenderViewImpl* RenderViewImpl::Create(
973 CompositorDependencies* compositor_deps,
Balazs Engedyba034e72017-10-27 22:26:28974 mojom::CreateViewParamsPtr params,
danakjdf1ceb72018-07-18 20:02:25975 RenderWidget::ShowCallback show_callback,
Hajime Hoshiabb3c8f2017-12-04 18:41:39976 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Balazs Engedyba034e72017-10-27 22:26:28977 DCHECK(params->view_id != MSG_ROUTING_NONE);
Albert J. Wongcb004632018-07-10 22:58:25978 DCHECK(params->main_frame_widget_routing_id != MSG_ROUTING_NONE);
Lei Zhang88f23ba2017-10-27 05:56:26979 RenderViewImpl* render_view;
[email protected]8d41d7612012-11-14 20:32:19980 if (g_create_render_view_impl)
Balazs Engedyba034e72017-10-27 22:26:28981 render_view = g_create_render_view_impl(compositor_deps, *params);
[email protected]075366912013-02-18 07:13:24982 else
Hajime Hoshiabb3c8f2017-12-04 18:41:39983 render_view = new RenderViewImpl(compositor_deps, *params, task_runner);
[email protected]0287e762014-04-11 13:07:58984
danakjdf1ceb72018-07-18 20:02:25985 render_view->Initialize(std::move(params), std::move(show_callback),
Hajime Hoshif34374412018-03-05 14:32:54986 std::move(task_runner));
[email protected]075366912013-02-18 07:13:24987 return render_view;
[email protected]8d41d7612012-11-14 20:32:19988}
989
990// static
dcheng35d31c112015-07-22 00:17:36991void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
992 *create_render_view_impl)(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15993 const mojom::CreateViewParams&)) {
[email protected]8d41d7612012-11-14 20:32:19994 CHECK(!g_create_render_view_impl);
995 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:29996}
997
[email protected]310ebd6302011-10-10 19:06:28998void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51999 observers_.AddObserver(observer);
1000}
1001
[email protected]310ebd6302011-10-10 19:06:281002void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1003 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511004 observers_.RemoveObserver(observer);
1005}
1006
Peter Kastinga4a3ed12018-01-31 04:07:591007blink::WebView* RenderViewImpl::webview() {
1008 return webview_;
1009}
1010
1011const blink::WebView* RenderViewImpl::webview() const {
lfg4fa48da2016-05-09 18:25:131012 return webview_;
[email protected]4d51d5bf2010-07-26 18:48:261013}
1014
danakja2c9d0a92018-07-25 20:01:181015// RenderWidgetOwnerDelegate -----------------------------------------
fsamuel72464894f2015-12-15 06:59:311016
danakja2c9d0a92018-07-25 20:01:181017blink::WebWidget* RenderViewImpl::GetWebWidgetForWidget() const {
1018 return frame_widget_;
1019}
1020
1021bool RenderViewImpl::RenderWidgetWillHandleMouseEventForWidget(
avid7d6b2e2016-03-04 19:41:171022 const blink::WebMouseEvent& event) {
fsamuel72464894f2015-12-15 06:59:311023 // If the mouse is locked, only the current owner of the mouse lock can
1024 // process mouse events.
danakja2c9d0a92018-07-25 20:01:181025 return GetWidget()->mouse_lock_dispatcher()->WillHandleMouseEvent(event);
fsamuel72464894f2015-12-15 06:59:311026}
1027
danakja2c9d0a92018-07-25 20:01:181028void RenderViewImpl::SetActiveForWidget(bool active) {
Albert J. Wongcb004632018-07-10 22:58:251029 if (webview())
1030 webview()->SetIsActive(active);
1031}
1032
danakja2c9d0a92018-07-25 20:01:181033void RenderViewImpl::SetBackgroundOpaqueForWidget(bool opaque) {
Albert J. Wongcb004632018-07-10 22:58:251034 if (!frame_widget_)
1035 return;
1036
1037 if (opaque) {
1038 frame_widget_->ClearBaseBackgroundColorOverride();
1039 frame_widget_->ClearBackgroundColorOverride();
1040 } else {
1041 frame_widget_->SetBaseBackgroundColorOverride(SK_ColorTRANSPARENT);
1042 frame_widget_->SetBackgroundColorOverride(SK_ColorTRANSPARENT);
1043 }
1044}
1045
danakja2c9d0a92018-07-25 20:01:181046bool RenderViewImpl::SupportsMultipleWindowsForWidget() {
1047 return webkit_preferences_.supports_multiple_windows;
1048}
1049
1050void RenderViewImpl::DidHandleGestureEventForWidget(
1051 const WebGestureEvent& event) {
1052 for (auto& observer : observers_)
1053 observer.DidHandleGestureEvent(event);
1054}
1055
1056void RenderViewImpl::OverrideCloseForWidget() {
1057 DCHECK(frame_widget_);
1058 frame_widget_->Close();
1059 frame_widget_ = nullptr;
1060}
1061
1062void RenderViewImpl::DidCloseWidget() {
1063 // The webview_ is already destroyed by the time we get here, remove any
1064 // references to it.
1065 g_view_map.Get().erase(webview_);
1066 webview_ = nullptr;
1067 g_routing_id_view_map.Get().erase(GetRoutingID());
1068 // TODO(ajwong): Does this message actually get sent?
1069 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(GetRoutingID()));
1070}
1071
1072void RenderViewImpl::ApplyNewSizeForWidget(const gfx::Size& old_size,
1073 const gfx::Size& new_size) {
1074 if (webview()) {
1075 // Only hide popups when the size changes. There are situations (e.g. hiding
1076 // the ChromeOS virtual keyboard) where we send a resize message with no
1077 // change in size, but we don't want to close popups.
1078 // See https://crbug.com/761908.
1079 if (new_size != old_size)
1080 webview()->HidePopups();
1081
1082 if (send_preferred_size_changes_ &&
1083 webview()->MainFrame()->IsWebLocalFrame()) {
1084 webview()->MainFrame()->ToWebLocalFrame()->SetCanHaveScrollbars(
1085 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
1086 }
1087 }
1088}
1089
1090void RenderViewImpl::ApplyNewDisplayModeForWidget(
1091 const blink::WebDisplayMode& new_display_mode) {
1092 if (webview())
1093 webview()->SetDisplayMode(new_display_mode);
1094}
1095
1096void RenderViewImpl::ApplyAutoResizeLimitsForWidget(const gfx::Size& min_size,
1097 const gfx::Size& max_size) {
1098 webview()->EnableAutoResizeMode(min_size, max_size);
1099}
1100
1101void RenderViewImpl::DisableAutoResizeForWidget() {
1102 webview()->DisableAutoResizeMode();
1103}
1104
1105void RenderViewImpl::ScrollFocusedNodeIntoViewForWidget() {
1106 if (WebLocalFrame* focused_frame = GetWebView()->FocusedFrame()) {
1107 auto* frame_widget = focused_frame->LocalRoot()->FrameWidget();
1108 frame_widget->ScrollFocusedEditableElementIntoView();
1109 }
1110}
1111
1112void RenderViewImpl::DidReceiveSetFocusEventForWidget() {
1113 // This message must always be received when the main frame is a
1114 // WebLocalFrame.
1115 // TODO(ajwong): Can this be removed and just check |owner_delegate_| in
1116 // RenderWidget instead?
1117 CHECK(webview()->MainFrame()->IsWebLocalFrame());
1118}
1119
1120void RenderViewImpl::DidChangeFocusForWidget() {
1121 // Notify all BrowserPlugins of the RenderView's focus state.
1122 if (BrowserPluginManager::Get())
1123 BrowserPluginManager::Get()->UpdateFocusState();
1124}
1125
1126GURL RenderViewImpl::GetURLForGraphicsContext3DForWidget() {
1127 DCHECK(webview());
1128 WebFrame* main_frame = webview()->MainFrame();
1129 if (main_frame && main_frame->IsWebLocalFrame())
1130 return GURL(main_frame->ToWebLocalFrame()->GetDocument().Url());
1131 else
1132 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
1133}
1134
1135void RenderViewImpl::DidCommitCompositorFrameForWidget() {
1136 for (auto& observer : observers_)
1137 observer.DidCommitCompositorFrame();
1138}
1139
1140void RenderViewImpl::DidCompletePageScaleAnimationForWidget() {
1141 if (auto* focused_frame = GetWebView()->FocusedFrame()) {
1142 if (focused_frame->AutofillClient())
1143 focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame();
1144 }
1145}
1146
1147void RenderViewImpl::ResizeWebWidgetForWidget(
1148 const gfx::Size& size,
1149 float top_controls_height,
1150 float bottom_controls_height,
1151 bool browser_controls_shrink_blink_size) {
1152 webview()->ResizeWithBrowserControls(size, top_controls_height,
1153 bottom_controls_height,
1154 browser_controls_shrink_blink_size);
1155}
1156
1157void RenderViewImpl::RequestScheduleAnimationForWidget() {
1158 // Schedule the animation on the WidgetClient() which may not be the
1159 // RenderWidget directly in layout tests.
1160 WidgetClient()->ScheduleAnimation();
1161}
1162
1163void RenderViewImpl::SetScreenMetricsEmulationParametersForWidget(
1164 bool enabled,
1165 const blink::WebDeviceEmulationParams& params) {
1166 if (webview() && GetWidget()->layer_tree_view()) {
1167 if (enabled)
1168 webview()->EnableDeviceEmulation(params);
1169 else
1170 webview()->DisableDeviceEmulation();
1171 }
1172}
1173
1174// IPC message handlers -----------------------------------------
1175
1176void RenderViewImpl::OnSelectWordAroundCaret() {
1177 // TODO(ajwong): Move this into RenderWidget. http://crbug.com/545684
1178 // Set default values for the ACK
1179 bool did_select = false;
1180 int start_adjust = 0;
1181 int end_adjust = 0;
1182
1183 if (webview()) {
1184 WebLocalFrame* focused_frame = GetWebView()->FocusedFrame();
1185 if (focused_frame) {
danakj53802692018-07-25 21:46:441186 GetWidget()->SetHandlingInputEvent(true);
danakja2c9d0a92018-07-25 20:01:181187 blink::WebRange initial_range = focused_frame->SelectionRange();
1188 if (!initial_range.IsNull())
1189 did_select = focused_frame->SelectWordAroundCaret();
1190 if (did_select) {
1191 blink::WebRange adjusted_range = focused_frame->SelectionRange();
1192 start_adjust =
1193 adjusted_range.StartOffset() - initial_range.StartOffset();
1194 end_adjust = adjusted_range.EndOffset() - initial_range.EndOffset();
1195 }
danakj53802692018-07-25 21:46:441196 GetWidget()->SetHandlingInputEvent(false);
danakja2c9d0a92018-07-25 20:01:181197 }
1198 }
1199 Send(new ViewHostMsg_SelectWordAroundCaretAck(
1200 GetWidget()->routing_id(), did_select, start_adjust, end_adjust));
1201}
1202
1203void RenderViewImpl::OnUpdateTargetURLAck() {
1204 // Check if there is a targeturl waiting to be sent.
1205 if (target_url_status_ == TARGET_PENDING)
1206 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), pending_target_url_));
1207
1208 target_url_status_ = TARGET_NONE;
1209}
1210
1211void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset,
1212 int history_length) {
1213 // -1 <= history_offset < history_length <= kMaxSessionHistoryEntries(50).
1214 DCHECK_LE(-1, history_offset);
1215 DCHECK_LT(history_offset, history_length);
1216 DCHECK_LE(history_length, kMaxSessionHistoryEntries);
1217
1218 history_list_offset_ = history_offset;
1219 history_list_length_ = history_length;
1220}
1221
1222void RenderViewImpl::OnSetInitialFocus(bool reverse) {
1223 if (!webview())
1224 return;
1225 webview()->SetInitialFocus(reverse);
1226}
1227
1228void RenderViewImpl::OnUpdateWindowScreenRect(gfx::Rect window_screen_rect) {
1229 // Defers to the RenderWidget message handler.
danakj53802692018-07-25 21:46:441230 GetWidget()->SetWindowScreenRect(window_screen_rect);
danakja2c9d0a92018-07-25 20:01:181231}
1232
1233void RenderViewImpl::OnAudioStateChanged(bool is_audio_playing) {
1234 webview()->AudioStateChanged(is_audio_playing);
1235}
1236
1237void RenderViewImpl::OnPausePageScheduledTasks(bool paused) {
1238 webview()->PausePageScheduledTasks(paused);
1239}
1240
1241///////////////////////////////////////////////////////////////////////////////
1242
1243void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget,
1244 WebNavigationPolicy policy,
1245 const gfx::Rect& initial_rect) {
1246 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(),
1247 initial_rect));
1248}
1249
1250void RenderViewImpl::ShowCreatedFullscreenWidget(
1251 RenderWidget* fullscreen_widget,
1252 WebNavigationPolicy policy,
1253 const gfx::Rect& initial_rect) {
1254 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(),
1255 fullscreen_widget->routing_id()));
1256}
1257
1258void RenderViewImpl::SendFrameStateUpdates() {
1259 // Tell each frame with pending state to send its UpdateState message.
1260 for (int render_frame_routing_id : frames_with_pending_state_) {
1261 RenderFrameImpl* frame =
1262 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
1263 if (frame)
1264 frame->SendUpdateState();
1265 }
1266 frames_with_pending_state_.clear();
1267}
1268
1269void RenderViewImpl::ApplyWebPreferencesInternal(const WebPreferences& prefs,
1270 blink::WebView* web_view) {
1271 ApplyWebPreferences(prefs, web_view);
1272}
1273
1274// IPC::Listener -------------------------------------------------------------
fsamuel72464894f2015-12-15 06:59:311275
[email protected]310ebd6302011-10-10 19:06:281276bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281277 WebFrame* main_frame = webview() ? webview()->MainFrame() : nullptr;
Avi Drissmanb5f8e242017-12-12 05:21:561278 if (main_frame) {
1279 GURL active_url;
1280 if (main_frame->IsWebLocalFrame())
1281 active_url = main_frame->ToWebLocalFrame()->GetDocument().Url();
lukaszabedb4b22017-06-23 00:00:131282 GetContentClient()->SetActiveURL(
Avi Drissmanb5f8e242017-12-12 05:21:561283 active_url, main_frame->Top()->GetSecurityOrigin().ToString().Utf8());
1284 }
[email protected]f8b6b6f2009-03-10 16:48:261285
dchenga2d442c22016-10-13 15:39:211286 for (auto& observer : observers_) {
1287 if (observer.OnMessageReceived(message))
[email protected]676126f72011-01-15 00:03:511288 return true;
dchenga2d442c22016-10-13 15:39:211289 }
[email protected]b2abac72009-02-26 12:39:281290
[email protected]a95986a82010-12-24 06:19:281291 bool handled = true;
[email protected]e44d1342014-05-16 21:29:331292 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
mcnee432e47d2015-11-09 19:37:461293 IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale)
initial.commit09911bf2008-07-26 23:55:291294 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291295 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1296 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]600ea402011-04-12 00:01:511297 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
1298 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:291299 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
[email protected]30f75e62009-02-25 22:01:001300 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]ab32b16c2009-10-16 14:57:251301 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1302 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:101303 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1304 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511305 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]81375e872012-01-11 21:40:361306 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
aelias1b55156e52017-04-01 00:46:051307 IPC_MESSAGE_HANDLER(ViewMsg_ResolveTapDisambiguation,
1308 OnResolveTapDisambiguation)
[email protected]4dda6a6c2014-05-17 15:35:041309 IPC_MESSAGE_HANDLER(ViewMsg_SelectWordAroundCaret, OnSelectWordAroundCaret)
wjmaclean64951902016-04-29 20:59:121310
1311 // Page messages.
lfgdb5c4ed2016-03-04 23:09:071312 IPC_MESSAGE_HANDLER(PageMsg_UpdateWindowScreenRect,
1313 OnUpdateWindowScreenRect)
lfg717154072016-06-30 15:04:161314 IPC_MESSAGE_HANDLER(PageMsg_WasHidden, OnPageWasHidden)
1315 IPC_MESSAGE_HANDLER(PageMsg_WasShown, OnPageWasShown)
alexmos136fd6e62016-08-15 20:58:411316 IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength,
1317 OnSetHistoryOffsetAndLength)
altimind8bd26c2016-11-04 11:44:541318 IPC_MESSAGE_HANDLER(PageMsg_AudioStateChanged, OnAudioStateChanged)
Gyuyoung Kim80143f5e2018-04-02 02:40:251319 IPC_MESSAGE_HANDLER(PageMsg_PausePageScheduledTasks,
1320 OnPausePageScheduledTasks)
lfg8d649cc2017-04-28 18:04:301321 IPC_MESSAGE_HANDLER(PageMsg_UpdateScreenInfo, OnUpdateScreenInfo)
Francois Doray47f759d2018-06-11 18:13:511322 IPC_MESSAGE_HANDLER(PageMsg_SetPageFrozen, SetPageFrozen)
lfg717154072016-06-30 15:04:161323
Matthew Jonesb4456421b2018-02-22 20:29:411324#if defined(OS_MACOSX)
naskoc288745f2015-05-01 22:54:211325 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]55750b32012-09-21 14:05:031326#endif
[email protected]a794f3a2013-10-30 17:00:321327 // Adding a new message? Add platform independent ones first, then put the
1328 // platform specific ones at the end.
[email protected]9e1ad4b2011-08-14 16:49:191329
initial.commit09911bf2008-07-26 23:55:291330 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281331 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291332 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401333
[email protected]a95986a82010-12-24 06:19:281334 return handled;
initial.commit09911bf2008-07-26 23:55:291335}
1336
[email protected]180ef242013-11-07 06:50:461337// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521338
Mustaq Ahmed55944cb2018-05-25 20:44:271339// TODO(csharrison): Migrate this method to WebLocalFrameClient /
1340// RenderFrameImpl, as it is now serviced by a mojo interface scoped to the
1341// opener frame.
Blink Reformat1c4d759e2017-04-09 16:34:541342WebView* RenderViewImpl::CreateView(WebLocalFrame* creator,
[email protected]35b2a972014-04-04 15:50:221343 const WebURLRequest& request,
1344 const WebWindowFeatures& features,
1345 const WebString& frame_name,
1346 WebNavigationPolicy policy,
Daniel Chengd5e56ff2017-06-24 07:44:021347 bool suppress_opener,
1348 WebSandboxFlags sandbox_flags) {
nick5ae4d2d2017-01-06 01:18:351349 RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator);
rockot5c478a72016-09-28 23:14:181350 mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New();
Mustaq Ahmedc4cb7162018-06-05 16:28:361351
1352 // User Activation v2 moves user gesture checks to the browser process, with
1353 // the exception of the extensions case handled through the following |if|.
1354 params->mimic_user_gesture =
1355 base::FeatureList::IsEnabled(features::kUserActivationV2)
1356 ? false
1357 : WebUserGestureIndicator::IsProcessingUserGesture(creator);
[email protected]00323f02013-07-24 15:47:411358 if (GetContentClient()->renderer()->AllowPopup())
Mustaq Ahmedc4cb7162018-06-05 16:28:361359 params->mimic_user_gesture = true;
1360
rockot5c478a72016-09-28 23:14:181361 params->window_container_type = WindowFeaturesToContainerType(features);
Daniel Murphye3eec92c2018-02-23 19:09:151362
1363 params->session_storage_namespace_id = AllocateSessionStorageNamespaceId();
1364 params->clone_from_session_storage_namespace_id =
1365 session_storage_namespace_id_;
1366 if (base::FeatureList::IsEnabled(features::kMojoSessionStorage)) {
1367 RenderThreadImpl::current_blink_platform_impl()
1368 ->CloneSessionStorageNamespace(session_storage_namespace_id_,
1369 params->session_storage_namespace_id);
1370 }
1371
Daniel Chengd5e56ff2017-06-24 07:44:021372 const std::string& frame_name_utf8 = frame_name.Utf8(
1373 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
1374 params->frame_name = frame_name_utf8;
rockot5c478a72016-09-28 23:14:181375 params->opener_suppressed = suppress_opener;
1376 params->disposition = NavigationPolicyToDisposition(policy);
Blink Reformat1c4d759e2017-04-09 16:34:541377 if (!request.IsNull()) {
1378 params->target_url = request.Url();
rockot5c478a72016-09-28 23:14:181379 params->referrer = GetReferrerFromRequest(creator, request);
[email protected]44e55b012013-07-23 14:21:561380 }
scottmg8e6c6082017-02-13 23:15:481381 params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
[email protected]8ab04652010-06-12 02:47:261382
rockot5c478a72016-09-28 23:14:181383 // We preserve this information before sending the message since |params| is
1384 // moved on send.
1385 bool is_background_tab =
1386 params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB;
Mustaq Ahmedc4cb7162018-06-05 16:28:361387 bool opened_by_user_gesture = params->mimic_user_gesture;
[email protected]22217ed32013-11-18 18:40:231388
Daniel Cheng8bb30c62017-10-23 20:40:471389 mojom::CreateNewWindowStatus status;
rockot5c478a72016-09-28 23:14:181390 mojom::CreateNewWindowReplyPtr reply;
Balazs Engedya40712f2017-09-15 15:01:111391 auto* frame_host = creator_frame->GetFrameHost();
Daniel Cheng8bb30c62017-10-23 20:40:471392 bool err = !frame_host->CreateNewWindow(std::move(params), &status, &reply);
1393 if (err || status == mojom::CreateNewWindowStatus::kIgnore)
rockot5c478a72016-09-28 23:14:181394 return nullptr;
[email protected]48c9cf2d2009-09-16 16:47:521395
Jochen Eisinger515337a2017-05-26 14:12:521396 // For Android WebView, we support a pop-up like behavior for window.open()
1397 // even if the embedding app doesn't support multiple windows. In this case,
1398 // window.open() will return "window" and navigate it to whatever URL was
Jochen Eisinger8cb28492017-10-04 10:58:131399 // passed. We also don't need to consume user gestures to protect against
1400 // multiple windows being opened, because, well, the app doesn't support
1401 // multiple windows.
Daniel Cheng8bb30c62017-10-23 20:40:471402 // TODO(dcheng): It's awkward that this is plumbed into Blink but not really
1403 // used much in Blink, except to enable layout testing... perhaps this should
1404 // be checked directly in the browser side.
1405 if (status == mojom::CreateNewWindowStatus::kReuse)
Jochen Eisinger515337a2017-05-26 14:12:521406 return webview();
1407
Daniel Cheng8bb30c62017-10-23 20:40:471408 DCHECK(reply);
1409 DCHECK_NE(MSG_ROUTING_NONE, reply->route_id);
1410 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_route_id);
1411 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_widget_route_id);
1412
Mustaq Ahmed76c2f4312018-06-07 20:48:011413 // The browser allowed creation of a new window and consumed the user
1414 // activation (UAv2 only).
1415 WebUserGestureIndicator::ConsumeUserGesture(
1416 creator, blink::UserActivationUpdateSource::kBrowser);
Jochen Eisinger8cb28492017-10-04 10:58:131417
[email protected]7912e822014-04-16 02:37:031418 // While this view may be a background extension page, it can spawn a visible
1419 // render view. So we just assume that the new one is not another background
1420 // page instead of passing on our own value.
1421 // TODO(vangelis): Can we tell if the new view will be a background page?
1422 bool never_visible = false;
[email protected]9115d5f2013-03-24 04:37:411423
Fady Samuelff5b6eb562018-05-01 16:16:081424 VisualProperties visual_properties = VisualProperties();
danakj53802692018-07-25 21:46:441425 visual_properties.screen_info = GetWidget()->screen_info();
mkosiba58fa72f02014-11-12 01:21:361426
[email protected]d6fa88f2013-10-18 16:00:431427 // The initial hidden state for the RenderViewImpl here has to match what the
1428 // browser will eventually decide for the given disposition. Since we have to
1429 // return from this call synchronously, we just have to make our best guess
1430 // and rely on the browser sending a WasHidden / WasShown message if it
1431 // disagrees.
Balazs Engedyba034e72017-10-27 22:26:281432 mojom::CreateViewParamsPtr view_params = mojom::CreateViewParams::New();
alexmos5ac402d2015-07-09 07:51:101433
Balazs Engedyba034e72017-10-27 22:26:281434 view_params->opener_frame_route_id = creator_frame->GetRoutingID();
avia3dca182016-03-19 01:09:521435 DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID());
alexmos5ac402d2015-07-09 07:51:101436
Balazs Engedyba034e72017-10-27 22:26:281437 view_params->window_was_created_with_opener = true;
1438 view_params->renderer_preferences = renderer_preferences_;
1439 view_params->web_preferences = webkit_preferences_;
1440 view_params->view_id = reply->route_id;
1441 view_params->main_frame_routing_id = reply->main_frame_route_id;
1442 view_params->main_frame_interface_provider =
1443 std::move(reply->main_frame_interface_provider);
1444 view_params->main_frame_widget_routing_id = reply->main_frame_widget_route_id;
1445 view_params->session_storage_namespace_id =
rockot5c478a72016-09-28 23:14:181446 reply->cloned_session_storage_namespace_id;
Balazs Engedyba034e72017-10-27 22:26:281447 view_params->swapped_out = false;
1448 view_params->replicated_frame_state.frame_policy.sandbox_flags =
1449 sandbox_flags;
1450 view_params->replicated_frame_state.name = frame_name_utf8;
1451 view_params->devtools_main_frame_token = reply->devtools_main_frame_token;
Daniel Chengd5e56ff2017-06-24 07:44:021452 // Even if the main frame has a name, the main frame's unique name is always
1453 // the empty string.
Balazs Engedyba034e72017-10-27 22:26:281454 view_params->hidden = is_background_tab;
1455 view_params->never_visible = never_visible;
Fady Samuelff5b6eb562018-05-01 16:16:081456 view_params->visual_properties = visual_properties;
naskobd911332014-11-25 01:13:361457
nick5ae4d2d2017-01-06 01:18:351458 // Unretained() is safe here because our calling function will also call
1459 // show().
nickf7b38222016-11-22 21:59:351460 RenderWidget::ShowCallback show_callback =
danakjdf1ceb72018-07-18 20:02:251461 base::BindOnce(&RenderFrameImpl::ShowCreatedWindow,
1462 base::Unretained(creator_frame), opened_by_user_gesture);
nickf7b38222016-11-22 21:59:351463
Balazs Engedyba034e72017-10-27 22:26:281464 RenderViewImpl* view = RenderViewImpl::Create(
danakj53802692018-07-25 21:46:441465 GetWidget()->compositor_deps(), std::move(view_params),
1466 std::move(show_callback),
Hajime Hoshi6fc91142018-05-11 08:21:171467 creator->GetTaskRunner(blink::TaskType::kInternalDefault));
[email protected]48c9cf2d2009-09-16 16:47:521468
[email protected]48c9cf2d2009-09-16 16:47:521469 return view->webview();
1470}
1471
Hajime Hoshiabb3c8f2017-12-04 18:41:391472WebWidget* RenderViewImpl::CreatePopup(blink::WebLocalFrame* creator,
1473 blink::WebPopupType popup_type) {
danakj53802692018-07-25 21:46:441474 RenderWidget* popup_widget = RenderWidget::CreateForPopup(
1475 this, GetWidget()->compositor_deps(), popup_type,
1476 GetWidget()->screen_info(),
Hajime Hoshi6fc91142018-05-11 08:21:171477 creator->GetTaskRunner(blink::TaskType::kInternalDefault));
danakj53802692018-07-25 21:46:441478 if (!popup_widget)
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281479 return nullptr;
danakj53802692018-07-25 21:46:441480 popup_widget->ApplyEmulatedScreenMetricsForPopupWidget(GetWidget());
1481 return popup_widget->GetWebWidget();
[email protected]48c9cf2d2009-09-16 16:47:521482}
1483
Daniel Murphy31bbb8b12018-02-07 21:44:101484base::StringPiece RenderViewImpl::GetSessionStorageNamespaceId() {
1485 CHECK(!session_storage_namespace_id_.empty());
Daniel Murphy0ce6e2c2017-11-21 01:54:261486 return session_storage_namespace_id_;
[email protected]bd92c3a2010-01-13 05:02:341487}
1488
Blink Reformat1c4d759e2017-04-09 16:34:541489void RenderViewImpl::PrintPage(WebLocalFrame* frame) {
naskoe440d8c2016-10-12 23:07:561490 UMA_HISTOGRAM_BOOLEAN("PrintPreview.InitiatedByScript",
Blink Reformat1c4d759e2017-04-09 16:34:541491 frame->Top() == frame);
naskoe440d8c2016-10-12 23:07:561492
1493 // Logging whether the top frame is remote is sufficient in this case. If
1494 // the top frame is local, the printing code will function correctly and
1495 // the frame itself will be printed, so the cases this histogram tracks is
1496 // where printing of a subframe will fail as of now.
1497 UMA_HISTOGRAM_BOOLEAN("PrintPreview.OutOfProcessSubframe",
Blink Reformat1c4d759e2017-04-09 16:34:541498 frame->Top()->IsWebRemoteFrame());
naskoe440d8c2016-10-12 23:07:561499
thestigcb959ce2016-11-17 05:56:321500 RenderFrameImpl::FromWebFrame(frame)->ScriptedPrint(
danakj53802692018-07-25 21:46:441501 GetWidget()->input_handler().handling_input_event());
[email protected]48c9cf2d2009-09-16 16:47:521502}
1503
Blink Reformat1c4d759e2017-04-09 16:34:541504bool RenderViewImpl::EnumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121505 const WebString& path,
1506 WebFileChooserCompletion* chooser_completion) {
1507 int id = enumeration_completion_id_++;
1508 enumeration_completions_[id] = chooser_completion;
1509 return Send(new ViewHostMsg_EnumerateDirectory(
avia3dca182016-03-19 01:09:521510 GetRoutingID(), id, blink::WebStringToFilePath(path)));
[email protected]8a58c1c2011-04-19 18:40:121511}
1512
[email protected]7e9523b2014-03-25 03:02:421513void RenderViewImpl::FrameDidStartLoading(WebFrame* frame) {
[email protected]7e9523b2014-03-25 03:02:421514 DCHECK_GE(frames_in_progress_, 0);
ericwilligers88e69742016-10-17 19:29:551515 if (frames_in_progress_ == 0) {
1516 for (auto& observer : observers_)
1517 observer.DidStartLoading();
1518 }
[email protected]7e9523b2014-03-25 03:02:421519 frames_in_progress_++;
[email protected]6dd5c322014-03-12 07:58:461520}
1521
[email protected]7e9523b2014-03-25 03:02:421522void RenderViewImpl::FrameDidStopLoading(WebFrame* frame) {
[email protected]eb473772014-04-11 20:54:331523 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
1524 // calls DidStopLoading() without a matching DidStartLoading().
1525 if (frames_in_progress_ == 0)
1526 return;
[email protected]7e9523b2014-03-25 03:02:421527 frames_in_progress_--;
[email protected]7e9523b2014-03-25 03:02:421528 if (frames_in_progress_ == 0) {
ericwilligers88e69742016-10-17 19:29:551529 for (auto& observer : observers_)
1530 observer.DidStopLoading();
[email protected]7e9523b2014-03-25 03:02:421531 }
[email protected]48c9cf2d2009-09-16 16:47:521532}
1533
lfgcaab5142016-02-26 19:06:521534void RenderViewImpl::AttachWebFrameWidget(blink::WebFrameWidget* frame_widget) {
dcheng3ce04b62015-10-26 23:30:551535 // The previous WebFrameWidget must already be detached by CloseForFrame().
1536 DCHECK(!frame_widget_);
1537 frame_widget_ = frame_widget;
1538}
1539
tommycli8aad3ba2015-08-12 17:57:591540void RenderViewImpl::SetZoomLevel(double zoom_level) {
wjmaclean64951902016-04-29 20:59:121541 // If we change the zoom level for the view, make sure any subsequent subframe
1542 // loads reflect the current zoom level.
1543 page_zoom_level_ = zoom_level;
1544
Blink Reformat1c4d759e2017-04-09 16:34:541545 webview()->SetZoomLevel(zoom_level);
ericwilligers88e69742016-10-17 19:29:551546 for (auto& observer : observers_)
1547 observer.OnZoomLevelChanged();
tommycli8aad3ba2015-08-12 17:57:591548}
1549
habib.virji597255e2014-09-09 00:30:181550void RenderViewImpl::SetValidationMessageDirection(
1551 base::string16* wrapped_main_text,
1552 blink::WebTextDirection main_text_hint,
1553 base::string16* wrapped_sub_text,
1554 blink::WebTextDirection sub_text_hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541555 if (main_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181556 *wrapped_main_text =
1557 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
Blink Reformat1c4d759e2017-04-09 16:34:541558 } else if (main_text_hint == blink::kWebTextDirectionRightToLeft &&
habib.virji597255e2014-09-09 00:30:181559 !base::i18n::IsRTL()) {
1560 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
1561 }
1562
1563 if (!wrapped_sub_text->empty()) {
Blink Reformat1c4d759e2017-04-09 16:34:541564 if (sub_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181565 *wrapped_sub_text =
1566 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
Blink Reformat1c4d759e2017-04-09 16:34:541567 } else if (sub_text_hint == blink::kWebTextDirectionRightToLeft) {
habib.virji597255e2014-09-09 00:30:181568 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
1569 }
1570 }
1571}
1572
[email protected]310ebd6302011-10-10 19:06:281573void RenderViewImpl::UpdateTargetURL(const GURL& url,
1574 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581575 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521576 if (latest_url == target_url_)
1577 return;
[email protected]163f8242009-10-30 20:19:551578
[email protected]48c9cf2d2009-09-16 16:47:521579 // Tell the browser to display a destination link.
1580 if (target_url_status_ == TARGET_INFLIGHT ||
1581 target_url_status_ == TARGET_PENDING) {
1582 // If we have a request in-flight, save the URL to be sent when we
1583 // receive an ACK to the in-flight request. We can happily overwrite
1584 // any existing pending sends.
1585 pending_target_url_ = latest_url;
1586 target_url_status_ = TARGET_PENDING;
1587 } else {
mnaganovbf087422015-12-16 05:10:031588 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411589 // see |ParamTraits<GURL>|.
markdittmer67b71ea2016-03-03 22:40:031590 if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:411591 latest_url = GURL();
avia3dca182016-03-19 01:09:521592 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), latest_url));
[email protected]48c9cf2d2009-09-16 16:47:521593 target_url_ = latest_url;
1594 target_url_status_ = TARGET_INFLIGHT;
1595 }
1596}
1597
creis69b184a472015-11-26 05:29:511598void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) {
creisce0ef3572017-01-26 17:53:081599 // Keep track of which frames have pending updates.
1600 frames_with_pending_state_.insert(frame->GetRoutingID());
creis8eb8ef22015-11-04 22:51:381601
[email protected]882daa92009-11-05 16:31:311602 int delay;
avif937e1d2014-11-02 18:13:071603 if (send_content_state_immediately_)
[email protected]882daa92009-11-05 16:31:311604 delay = 0;
1605 else if (is_hidden())
avif937e1d2014-11-02 18:13:071606 delay = kDelaySecondsForContentStateSyncHidden;
[email protected]882daa92009-11-05 16:31:311607 else
avif937e1d2014-11-02 18:13:071608 delay = kDelaySecondsForContentStateSync;
[email protected]882daa92009-11-05 16:31:311609
avif937e1d2014-11-02 18:13:071610 if (nav_state_sync_timer_.IsRunning()) {
[email protected]882daa92009-11-05 16:31:311611 // The timer is already running. If the delay of the timer maches the amount
1612 // we want to delay by, then return. Otherwise stop the timer so that it
1613 // gets started with the right delay.
avif937e1d2014-11-02 18:13:071614 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
[email protected]882daa92009-11-05 16:31:311615 return;
avif937e1d2014-11-02 18:13:071616 nav_state_sync_timer_.Stop();
[email protected]882daa92009-11-05 16:31:311617 }
1618
creisce0ef3572017-01-26 17:53:081619 // Tell each frame with pending state to inform the browser.
1620 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
1621 &RenderViewImpl::SendFrameStateUpdates);
[email protected]882daa92009-11-05 16:31:311622}
1623
Blink Reformat1c4d759e2017-04-09 16:34:541624void RenderViewImpl::SetMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551625 mouse_over_url_ = GURL(url);
1626 UpdateTargetURL(mouse_over_url_, focus_url_);
1627}
1628
Blink Reformat1c4d759e2017-04-09 16:34:541629void RenderViewImpl::SetKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551630 focus_url_ = GURL(url);
1631 UpdateTargetURL(focus_url_, mouse_over_url_);
1632}
1633
Blink Reformat1c4d759e2017-04-09 16:34:541634bool RenderViewImpl::AcceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451635 return renderer_preferences_.can_accept_load_drops;
1636}
1637
Blink Reformat1c4d759e2017-04-09 16:34:541638void RenderViewImpl::FocusNext() {
avia3dca182016-03-19 01:09:521639 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false));
[email protected]48c9cf2d2009-09-16 16:47:521640}
1641
Blink Reformat1c4d759e2017-04-09 16:34:541642void RenderViewImpl::FocusPrevious() {
avia3dca182016-03-19 01:09:521643 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true));
[email protected]48c9cf2d2009-09-16 16:47:521644}
1645
esprehn3d4471a2015-09-17 07:13:201646// TODO(esprehn): Blink only ever passes Elements, this should take WebElement.
Blink Reformat1c4d759e2017-04-09 16:34:541647void RenderViewImpl::FocusedNodeChanged(const WebNode& fromNode,
estade31c54342015-01-23 03:34:361648 const WebNode& toNode) {
estade31c54342015-01-23 03:34:361649 RenderFrameImpl* previous_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541650 if (!fromNode.IsNull())
1651 previous_frame =
1652 RenderFrameImpl::FromWebFrame(fromNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361653 RenderFrameImpl* new_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541654 if (!toNode.IsNull())
1655 new_frame = RenderFrameImpl::FromWebFrame(toNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361656
1657 if (previous_frame && previous_frame != new_frame)
1658 previous_frame->FocusedNodeChanged(WebNode());
1659 if (new_frame)
1660 new_frame->FocusedNodeChanged(toNode);
1661
1662 // TODO(dmazzoni): remove once there's a separate a11y tree per frame.
naskoe8d115752015-08-07 00:43:131663 if (main_render_frame_)
1664 main_render_frame_->FocusedNodeChangedForAccessibility(toNode);
[email protected]08e9e132010-06-01 16:58:491665}
1666
Blink Reformat1c4d759e2017-04-09 16:34:541667void RenderViewImpl::DidUpdateLayout() {
ericwilligers88e69742016-10-17 19:29:551668 for (auto& observer : observers_)
1669 observer.DidUpdateLayout();
[email protected]d01b2a62013-09-18 23:21:331670
[email protected]169d4282011-11-30 19:33:591671 // We don't always want to set up a timer, only if we've been put in that
1672 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1673 // message.
1674 if (!send_preferred_size_changes_ || !webview())
1675 return;
1676
1677 if (check_preferred_size_timer_.IsRunning())
1678 return;
1679 check_preferred_size_timer_.Start(FROM_HERE,
1680 TimeDelta::FromMilliseconds(0), this,
1681 &RenderViewImpl::CheckPreferredSize);
1682}
1683
Blink Reformat1c4d759e2017-04-09 16:34:541684void RenderViewImpl::NavigateBackForwardSoon(int offset) {
Alex Clarkebf3dceb2017-11-24 12:27:431685 history_navigation_virtual_time_pauser_ =
1686 RenderThreadImpl::current()
Yuta Kitamura3331f5c2018-04-05 11:12:251687 ->GetWebMainThreadScheduler()
Alex Clarkeb28db542018-02-07 12:53:131688 ->CreateWebScopedVirtualTimePauser(
Alex Clarkeaaf006b2018-04-05 18:35:241689 "NavigateBackForwardSoon",
Alex Clarkeb28db542018-02-07 12:53:131690 blink::WebScopedVirtualTimePauser::VirtualTaskDuration::kInstant);
Alex Clarkeaaf006b2018-04-05 18:35:241691 history_navigation_virtual_time_pauser_.PauseVirtualTime();
avia3dca182016-03-19 01:09:521692 Send(new ViewHostMsg_GoToEntryAtOffset(GetRoutingID(), offset));
[email protected]48c9cf2d2009-09-16 16:47:521693}
1694
Alex Clarkebf3dceb2017-11-24 12:27:431695void RenderViewImpl::DidCommitProvisionalHistoryLoad() {
Alex Clarkeaaf006b2018-04-05 18:35:241696 history_navigation_virtual_time_pauser_.UnpauseVirtualTime();
Alex Clarkebf3dceb2017-11-24 12:27:431697}
1698
Blink Reformat1c4d759e2017-04-09 16:34:541699int RenderViewImpl::HistoryBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001700 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521701}
1702
Blink Reformat1c4d759e2017-04-09 16:34:541703int RenderViewImpl::HistoryForwardListCount() {
1704 return history_list_length_ - HistoryBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521705}
1706
[email protected]180ef242013-11-07 06:50:461707// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:511708
Blink Reformat1c4d759e2017-04-09 16:34:541709bool RenderViewImpl::CanHandleGestureEvent() {
slangley1a6375e62017-03-29 06:03:231710 return true;
1711}
1712
Blink Reformat1c4d759e2017-04-09 16:34:541713bool RenderViewImpl::CanUpdateLayout() {
slangley1a6375e62017-03-29 06:03:231714 return true;
1715}
1716
Blink Reformat1c4d759e2017-04-09 16:34:541717blink::WebWidgetClient* RenderViewImpl::WidgetClient() {
danakj9a8a9cf2018-07-17 23:52:121718 return this;
lfg0f440622016-07-20 04:27:141719}
1720
Mustaq Ahmed55944cb2018-05-25 20:44:271721// blink::WebLocalFrameClient
1722// -----------------------------------------------------
[email protected]3d9689372009-09-10 04:29:171723
[email protected]b2324b092012-11-01 10:34:111724void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
1725 const std::string& value) {
alexmos56567492016-09-13 00:52:461726 GetWidget()->SetEditCommandForNextKeyEvent(name, value);
[email protected]b2324b092012-11-01 10:34:111727}
1728
1729void RenderViewImpl::ClearEditCommands() {
alexmos56567492016-09-13 00:52:461730 GetWidget()->ClearEditCommands();
[email protected]b2324b092012-11-01 10:34:111731}
1732
[email protected]b38806a2013-10-04 16:01:381733const std::string& RenderViewImpl::GetAcceptLanguages() const {
1734 return renderer_preferences_.accept_languages;
1735}
1736
danakjdea2efb2016-03-10 19:13:171737void RenderViewImpl::ConvertViewportToWindowViaWidget(blink::WebRect* rect) {
danakj9a8a9cf2018-07-17 23:52:121738 WidgetClient()->ConvertViewportToWindow(rect);
oshimae2b3b402015-12-04 04:27:241739}
1740
huangs2a342352015-12-15 16:59:241741gfx::RectF RenderViewImpl::ElementBoundsInWindow(
1742 const blink::WebElement& element) {
Blink Reformat1c4d759e2017-04-09 16:34:541743 blink::WebRect bounding_box_in_window = element.BoundsInViewport();
danakj9a8a9cf2018-07-17 23:52:121744 WidgetClient()->ConvertViewportToWindow(&bounding_box_in_window);
huangs2a342352015-12-15 16:59:241745 return gfx::RectF(bounding_box_in_window);
1746}
1747
[email protected]310ebd6302011-10-10 19:06:281748void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:071749 // We don't always want to send the change messages over IPC, only if we've
1750 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1751 // message.
1752 if (!send_preferred_size_changes_ || !webview())
1753 return;
oshima1a688b5c2017-06-16 19:00:131754 blink::WebSize tmp_size = webview()->ContentsPreferredMinimumSize();
1755 blink::WebRect tmp_rect(0, 0, tmp_size.width, tmp_size.height);
danakj9a8a9cf2018-07-17 23:52:121756 WidgetClient()->ConvertViewportToWindow(&tmp_rect);
oshima1a688b5c2017-06-16 19:00:131757 gfx::Size size(tmp_rect.width, tmp_rect.height);
[email protected]705243f2010-05-05 19:58:071758 if (size == preferred_size_)
1759 return;
[email protected]c27324b2009-11-19 22:44:291760
[email protected]705243f2010-05-05 19:58:071761 preferred_size_ = size;
avia3dca182016-03-19 01:09:521762 Send(new ViewHostMsg_DidContentsPreferredSizeChange(GetRoutingID(),
[email protected]705243f2010-05-05 19:58:071763 preferred_size_));
[email protected]3d9689372009-09-10 04:29:171764}
1765
Blink Reformat1c4d759e2017-04-09 16:34:541766blink::WebString RenderViewImpl::AcceptLanguages() {
1767 return WebString::FromUTF8(renderer_preferences_.accept_languages);
[email protected]9982c802013-06-12 15:22:061768}
1769
[email protected]e9ff79c2012-10-19 21:31:261770// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:311771
[email protected]310ebd6302011-10-10 19:06:281772bool RenderViewImpl::Send(IPC::Message* message) {
danakja2c9d0a92018-07-25 20:01:181773 // This method is an override of IPC::Sender, but RenderWidget also has an
1774 // override of IPC::Sender, so this method also overrides RenderWidget. Thus
1775 // we must call to the base class, not via an upcast or virtual dispatch would
1776 // go back here.
[email protected]a2ef54c2011-10-10 16:20:311777 return RenderWidget::Send(message);
1778}
1779
Peter Kastinga4a3ed12018-01-31 04:07:591780RenderWidget* RenderViewImpl::GetWidget() {
1781 return this;
avi8a45c1092016-03-01 16:12:341782}
1783
mostynbc33353232014-09-12 09:38:311784RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() {
nasko77de2312015-05-12 03:09:161785 return main_render_frame_;
[email protected]b849847b2013-12-10 21:57:581786}
1787
[email protected]82114f52012-03-20 22:53:411788int RenderViewImpl::GetRoutingID() const {
Albert J. Wongcb004632018-07-10 22:58:251789 return routing_id_;
[email protected]a2ef54c2011-10-10 16:20:311790}
1791
[email protected]82114f52012-03-20 22:53:411792gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:311793 return size();
1794}
1795
oshima129b75e2016-01-14 09:15:141796float RenderViewImpl::GetDeviceScaleFactor() const {
Fady Samuela863f152018-03-09 16:10:031797 return GetWebScreenInfo().device_scale_factor;
oshima129b75e2016-01-14 09:15:141798}
1799
Marc Treib06d66032017-10-19 08:43:201800float RenderViewImpl::GetZoomLevel() const {
1801 return page_zoom_level_;
1802}
1803
thestig8a8fdfd32017-05-06 18:46:541804const WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:311805 return webkit_preferences_;
1806}
1807
[email protected]324825d2012-11-30 12:37:151808void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
1809 OnUpdateWebPreferences(preferences);
1810}
1811
[email protected]180ef242013-11-07 06:50:461812blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:311813 return webview();
1814}
1815
lfgcaab5142016-02-26 19:06:521816blink::WebFrameWidget* RenderViewImpl::GetWebFrameWidget() {
1817 return frame_widget_;
1818}
1819
[email protected]310ebd6302011-10-10 19:06:281820bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:311821 return (!send_preferred_size_changes_ ||
1822 (disable_scrollbars_size_limit_.width() <= width ||
1823 disable_scrollbars_size_limit_.height() <= height));
1824}
1825
avif937e1d2014-11-02 18:13:071826bool RenderViewImpl::GetContentStateImmediately() const {
1827 return send_content_state_immediately_;
[email protected]a2ef54c2011-10-10 16:20:311828}
1829
mcnee432e47d2015-11-09 19:37:461830void RenderViewImpl::OnSetPageScale(float page_scale_factor) {
ccameronb7c1d6c2015-03-09 17:08:241831 if (!webview())
1832 return;
Blink Reformat1c4d759e2017-04-09 16:34:541833 webview()->SetPageScaleFactor(page_scale_factor);
ccameronb7c1d6c2015-03-09 17:08:241834}
1835
akaba3483d8f2018-07-10 21:43:091836void RenderViewImpl::UpdateZoomLevel(double zoom_level) {
Blink Reformat1c4d759e2017-04-09 16:34:541837 webview()->HidePopups();
wjmaclean64951902016-04-29 20:59:121838 SetZoomLevel(zoom_level);
[email protected]d42bf472014-06-14 01:49:381839}
1840
[email protected]310ebd6302011-10-10 19:06:281841void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:591842 webkit_preferences_ = prefs;
danakj39f68122018-07-16 20:11:461843 ApplyWebPreferencesInternal(webkit_preferences_, webview());
initial.commit09911bf2008-07-26 23:55:291844}
1845
[email protected]310ebd6302011-10-10 19:06:281846void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:511847 int id,
[email protected]c42de732013-02-16 06:26:311848 const std::vector<base::FilePath>& paths) {
[email protected]600ea402011-04-12 00:01:511849 if (!enumeration_completions_[id])
1850 return;
1851
1852 WebVector<WebString> ws_file_names(paths.size());
1853 for (size_t i = 0; i < paths.size(); ++i)
kinukoa4293022017-01-27 06:43:251854 ws_file_names[i] = blink::FilePathToWebString(paths[i]);
[email protected]600ea402011-04-12 00:01:511855
Blink Reformat1c4d759e2017-04-09 16:34:541856 enumeration_completions_[id]->DidChooseFile(ws_file_names);
[email protected]600ea402011-04-12 00:01:511857 enumeration_completions_.erase(id);
1858}
1859
[email protected]2bf834f2011-11-17 20:02:211860void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:241861 if (send_preferred_size_changes_)
1862 return;
[email protected]9fb325e2010-05-06 18:23:241863 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:391864
[email protected]d812fd12011-05-27 23:05:071865 // Start off with an initial preferred size notification (in case
1866 // |didUpdateLayout| was already called).
Blink Reformat1c4d759e2017-04-09 16:34:541867 DidUpdateLayout();
[email protected]0666aef2009-05-13 19:48:081868}
1869
[email protected]310ebd6302011-10-10 19:06:281870void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:101871 const gfx::Size& disable_scrollbar_size_limit) {
1872 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
1873}
1874
[email protected]310ebd6302011-10-10 19:06:281875void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:261876 const RendererPreferences& renderer_prefs) {
[email protected]ebd5ea52014-05-28 14:51:151877 std::string old_accept_languages = renderer_preferences_.accept_languages;
1878
[email protected]80d96fa2009-06-10 22:34:511879 renderer_preferences_ = renderer_prefs;
ananta59b9fe72015-04-07 01:33:261880
[email protected]6e282c92009-07-24 01:19:371881 UpdateFontRenderingFromRendererPrefs();
scottmgb92365e2016-08-30 20:54:401882 UpdateThemePrefs();
Blink Reformat1c4d759e2017-04-09 16:34:541883 blink::SetCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]38a85712013-01-02 22:45:021884
brettw8a274fa2016-11-15 00:20:401885#if BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]1596efb2013-01-17 22:13:011886 if (renderer_prefs.use_custom_colors) {
Blink Reformat1c4d759e2017-04-09 16:34:541887 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
[email protected]1596efb2013-01-17 22:13:011888
1889 if (webview()) {
Blink Reformat1c4d759e2017-04-09 16:34:541890 webview()->SetSelectionColors(renderer_prefs.active_selection_bg_color,
1891 renderer_prefs.active_selection_fg_color,
1892 renderer_prefs.inactive_selection_bg_color,
1893 renderer_prefs.inactive_selection_fg_color);
1894 webview()->ThemeChanged();
[email protected]1596efb2013-01-17 22:13:011895 }
[email protected]644d77e2010-01-27 01:03:101896 }
brettw8a274fa2016-11-15 00:20:401897#endif // BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]d299d972012-03-23 02:26:551898
[email protected]ebd5ea52014-05-28 14:51:151899 if (webview() &&
1900 old_accept_languages != renderer_preferences_.accept_languages) {
Blink Reformat1c4d759e2017-04-09 16:34:541901 webview()->AcceptLanguagesChanged();
[email protected]ebd5ea52014-05-28 14:51:151902 }
[email protected]80d96fa2009-06-10 22:34:511903}
1904
[email protected]81375e872012-01-11 21:40:361905void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
1906 const WebPluginAction& action) {
1907 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:541908 webview()->PerformPluginAction(action, location);
[email protected]81375e872012-01-11 21:40:361909}
1910
[email protected]310ebd6302011-10-10 19:06:281911void RenderViewImpl::OnClosePage() {
lukasza5d0dee42017-06-14 21:57:371912 // ViewMsg_ClosePage should only be sent to active, non-swapped-out views.
1913 DCHECK(webview()->MainFrame()->IsWebLocalFrame());
1914
initial.commit09911bf2008-07-26 23:55:291915 // TODO(creis): We'd rather use webview()->Close() here, but that currently
1916 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
1917 // in the onunload handler from appearing. For now, we're bypassing that and
1918 // calling the FrameLoader's CloseURL method directly. This should be
1919 // revisited to avoid having two ways to close a page. Having a single way
1920 // to close that can run onunload is also useful for fixing
1921 // http://b/issue?id=753080.
lukasza5d0dee42017-06-14 21:57:371922 webview()->MainFrame()->ToWebLocalFrame()->DispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:291923
avia3dca182016-03-19 01:09:521924 Send(new ViewHostMsg_ClosePage_ACK(GetRoutingID()));
initial.commit09911bf2008-07-26 23:55:291925}
1926
Albert J. Wongcb004632018-07-10 22:58:251927#if defined(OS_MACOSX)
naskoc288745f2015-05-01 22:54:211928void RenderViewImpl::OnClose() {
danakj53802692018-07-25 21:46:441929 if (GetWidget()->closing())
avia3dca182016-03-19 01:09:521930 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(GetRoutingID()));
danakj53802692018-07-25 21:46:441931 // This method is protected for OS_MACOSX only, because the message gets sent
1932 // to the RenderViewImpl instead of to the RenderWidget.
1933 // TODO(danakj): Move this message to RenderWidget?
naskoc288745f2015-05-01 22:54:211934 RenderWidget::OnClose();
1935}
Albert J. Wongcb004632018-07-10 22:58:251936#endif
naskoc288745f2015-05-01 22:54:211937
[email protected]310ebd6302011-10-10 19:06:281938void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:001939 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:541940 webview()->HidePopups();
[email protected]30f75e62009-02-25 22:01:001941}
1942
lfg717154072016-06-30 15:04:161943void RenderViewImpl::OnPageWasHidden() {
braveyao1d8ee7b2017-03-29 21:10:041944#if defined(OS_ANDROID)
1945 SuspendVideoCaptureDevices(true);
braveyao1d8ee7b2017-03-29 21:10:041946#endif
[email protected]2d7b82c2012-06-01 05:57:501947
lfg717154072016-06-30 15:04:161948 if (webview()) {
1949 // TODO(lfg): It's not correct to defer the page visibility to the main
1950 // frame. Currently, this is done because the main frame may override the
1951 // visibility of the page when prerendering. In order to fix this,
1952 // prerendering must be made aware of OOPIFs. https://crbug.com/440544
xzhan96cf0a3c542017-11-17 04:33:011953 blink::mojom::PageVisibilityState visibilityState =
Blink Reformat1c4d759e2017-04-09 16:34:541954 GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState()
xzhan96cf0a3c542017-11-17 04:33:011955 : blink::mojom::PageVisibilityState::kHidden;
Blink Reformat1c4d759e2017-04-09 16:34:541956 webview()->SetVisibilityState(visibilityState, false);
lfg717154072016-06-30 15:04:161957 }
[email protected]941e4552010-02-01 21:23:431958}
1959
lfg717154072016-06-30 15:04:161960void RenderViewImpl::OnPageWasShown() {
braveyao1d8ee7b2017-03-29 21:10:041961#if defined(OS_ANDROID)
1962 SuspendVideoCaptureDevices(false);
[email protected]6392d982013-04-16 16:59:221963#endif
1964
lfg717154072016-06-30 15:04:161965 if (webview()) {
xzhan96cf0a3c542017-11-17 04:33:011966 blink::mojom::PageVisibilityState visibilityState =
Blink Reformat1c4d759e2017-04-09 16:34:541967 GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState()
xzhan96cf0a3c542017-11-17 04:33:011968 : blink::mojom::PageVisibilityState::kVisible;
Blink Reformat1c4d759e2017-04-09 16:34:541969 webview()->SetVisibilityState(visibilityState, false);
lfg717154072016-06-30 15:04:161970 }
[email protected]a6939ca42011-02-18 17:58:071971}
[email protected]1e6e3c992010-02-08 15:52:131972
lfg8d649cc2017-04-28 18:04:301973void RenderViewImpl::OnUpdateScreenInfo(const ScreenInfo& screen_info) {
1974 // This IPC only updates the screen info on RenderViews that have a remote
1975 // main frame. For local main frames, the ScreenInfo is updated in
1976 // ViewMsg_Resize.
danakj53802692018-07-25 21:46:441977 // TODO(danakj): Move this message to RenderWidget?
lfg8d649cc2017-04-28 18:04:301978 if (!main_render_frame_)
danakj53802692018-07-25 21:46:441979 GetWidget()->set_screen_info(screen_info);
lfg8d649cc2017-04-28 18:04:301980}
1981
Francois Doray47f759d2018-06-11 18:13:511982void RenderViewImpl::SetPageFrozen(bool frozen) {
1983 if (webview())
1984 webview()->SetPageFrozen(frozen);
Fadi Meawada6573e02018-03-10 00:52:111985}
1986
alexmos3fcd0ca2015-10-23 18:18:331987void RenderViewImpl::SetFocus(bool enable) {
danakja2c9d0a92018-07-25 20:01:181988 // This is not an IPC message, don't go through the IPC handler. This is used
1989 // in cases where the IPC message should not happen.
1990 GetWidget()->SetFocus(enable);
[email protected]b2e4c70132013-10-03 02:07:511991}
1992
Blink Reformat1c4d759e2017-04-09 16:34:541993void RenderViewImpl::ZoomLimitsChanged(double minimum_level,
[email protected]310ebd6302011-10-10 19:06:281994 double maximum_level) {
a.sarkar.arundaadc712015-02-26 05:39:081995 // Round the double to avoid returning incorrect minimum/maximum zoom
1996 // percentages.
1997 int minimum_percent = round(
[email protected]7940b8e2013-07-25 23:08:491998 ZoomLevelToZoomFactor(minimum_level) * 100);
a.sarkar.arundaadc712015-02-26 05:39:081999 int maximum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492000 ZoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:252001
avia3dca182016-03-19 01:09:522002 Send(new ViewHostMsg_UpdateZoomLimits(GetRoutingID(), minimum_percent,
fsamuele8326c742016-01-12 00:49:392003 maximum_percent));
[email protected]b75b8292010-10-01 07:28:252004}
2005
Blink Reformat1c4d759e2017-04-09 16:34:542006void RenderViewImpl::PageScaleFactorChanged() {
ccameronb7c1d6c2015-03-09 17:08:242007 if (!webview())
2008 return;
mcnee432e47d2015-11-09 19:37:462009
avia3dca182016-03-19 01:09:522010 Send(new ViewHostMsg_PageScaleFactorChanged(GetRoutingID(),
Blink Reformat1c4d759e2017-04-09 16:34:542011 webview()->PageScaleFactor()));
ccameronb7c1d6c2015-03-09 17:08:242012}
2013
[email protected]7940b8e2013-07-25 23:08:492014double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const {
2015 return ZoomLevelToZoomFactor(zoom_level);
2016}
2017
2018double RenderViewImpl::zoomFactorToZoomLevel(double factor) const {
2019 return ZoomFactorToZoomLevel(factor);
2020}
2021
Blink Reformat1c4d759e2017-04-09 16:34:542022void RenderViewImpl::PageImportanceSignalsChanged() {
kouhei40f03cb2015-09-24 07:47:012023 if (!webview() || !main_render_frame_)
2024 return;
2025
Blink Reformat1c4d759e2017-04-09 16:34:542026 auto* web_signals = webview()->PageImportanceSignals();
kouhei40f03cb2015-09-24 07:47:012027
2028 PageImportanceSignals signals;
Blink Reformat1c4d759e2017-04-09 16:34:542029 signals.had_form_interaction = web_signals->HadFormInteraction();
kouhei40f03cb2015-09-24 07:47:012030
2031 main_render_frame_->Send(new FrameHostMsg_UpdatePageImportanceSignals(
2032 main_render_frame_->GetRoutingID(), signals));
2033}
2034
danakj9a8a9cf2018-07-17 23:52:122035void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) {
danakja2c9d0a92018-07-25 20:01:182036 GetWidget()->DidAutoResize(newSize);
danakj9a8a9cf2018-07-17 23:52:122037}
2038
2039blink::WebRect RenderViewImpl::RootWindowRect() {
2040 return WidgetClient()->WindowRect();
2041}
2042
danakja2c9d0a92018-07-25 20:01:182043void RenderViewImpl::DidFocus(blink::WebLocalFrame* calling_frame) {
2044 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2045 // we won't have to test for user gesture anymore and we can
2046 // move that code back to render_widget.cc
2047 if (WebUserGestureIndicator::IsProcessingUserGesture(calling_frame) &&
2048 !RenderThreadImpl::current()->layout_test_mode()) {
2049 Send(new ViewHostMsg_Focus(GetRoutingID()));
2050
2051 // Tattle on the frame that called |window.focus()|.
2052 RenderFrameImpl* calling_render_frame =
2053 RenderFrameImpl::FromWebFrame(calling_frame);
2054 if (calling_render_frame)
2055 calling_render_frame->FrameDidCallFocus();
2056 }
2057}
2058
[email protected]20657a82012-08-21 20:23:032059#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:542060bool RenderViewImpl::OpenDateTimeChooser(
[email protected]180ef242013-11-07 06:50:462061 const blink::WebDateTimeChooserParams& params,
2062 blink::WebDateTimeChooserCompletion* completion) {
[email protected]e8072562013-12-04 06:04:132063 // JavaScript may try to open a date time chooser while one is already open.
2064 if (date_time_picker_client_)
2065 return false;
[email protected]b18583c2012-12-18 06:55:272066 date_time_picker_client_.reset(
2067 new RendererDateTimePicker(this, params, completion));
2068 return date_time_picker_client_->Open();
2069}
2070
[email protected]e8072562013-12-04 06:04:132071void RenderViewImpl::DismissDateTimeDialog() {
2072 DCHECK(date_time_picker_client_);
Lei Zhang88f23ba2017-10-27 05:56:262073 date_time_picker_client_.reset();
[email protected]e8072562013-12-04 06:04:132074}
[email protected]e8072562013-12-04 06:04:132075
Blink Reformat1c4d759e2017-04-09 16:34:542076bool RenderViewImpl::DidTapMultipleTargets(
timav29a8d0f62014-09-25 20:45:532077 const WebSize& inner_viewport_offset,
2078 const WebRect& touch_rect,
[email protected]f9526d12012-10-18 01:55:032079 const WebVector<WebRect>& target_rects) {
[email protected]8d3dfee62013-06-19 05:50:332080 // Never show a disambiguation popup when accessibility is enabled,
2081 // as this interferes with "touch exploration".
Doug Turner63f3c7b2017-07-29 05:10:012082 ui::AXMode accessibility_mode = GetMainRenderFrame()->accessibility_mode();
2083 if (accessibility_mode == ui::kAXModeComplete)
[email protected]8d3dfee62013-06-19 05:50:332084 return false;
2085
timav29a8d0f62014-09-25 20:45:532086 // The touch_rect, target_rects and zoom_rect are in the outer viewport
2087 // reference frame.
Fady Samuela863f152018-03-09 16:10:032088 float to_pix =
2089 IsUseZoomForDSFEnabled() ? 1 : GetWebScreenInfo().device_scale_factor;
[email protected]f9526d12012-10-18 01:55:032090 gfx::Rect zoom_rect;
[email protected]70221f02013-01-31 22:17:072091 float new_total_scale =
2092 DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
timav29a8d0f62014-09-25 20:45:532093 touch_rect, target_rects, GetSize(),
Blink Reformat1c4d759e2017-04-09 16:34:542094 gfx::Rect(webview()->MainFrame()->VisibleContentRect()).size(),
Jaebaek Seo6de124a2018-02-15 03:34:032095 to_pix * webview()->PageScaleFactor(), &zoom_rect);
jbauman0ed09182015-01-30 22:33:492096 if (!new_total_scale || zoom_rect.IsEmpty())
[email protected]f9526d12012-10-18 01:55:032097 return false;
2098
[email protected]4ded1dbf2013-08-28 21:11:032099 bool handled = false;
2100 switch (renderer_preferences_.tap_multiple_targets_strategy) {
2101 case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM:
Blink Reformat1c4d759e2017-04-09 16:34:542102 handled = webview()->ZoomToMultipleTargetsRect(zoom_rect);
[email protected]4ded1dbf2013-08-28 21:11:032103 break;
2104 case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: {
[email protected]bc2804d2013-08-06 07:45:492105 gfx::Size canvas_size =
danakjddaec912015-09-25 19:38:402106 gfx::ScaleToCeiledSize(zoom_rect.size(), new_total_scale);
kylechare7d8d5c72018-01-05 19:06:282107
2108 SkImageInfo info =
2109 SkImageInfo::MakeN32Premul(canvas_size.width(), canvas_size.height());
2110 size_t shm_size = info.computeMinByteSize();
2111
2112 if (shm_size == 0) {
2113 DLOG(ERROR) << "Invalid size for SharedMemory";
2114 return false;
2115 }
2116
2117 auto shm = ChildThreadImpl::AllocateSharedMemory(shm_size);
2118 if (!shm || !shm->Map(shm_size)) {
2119 DLOG(ERROR) << "SharedMemory allocate/map failed";
2120 return false;
2121 }
2122
[email protected]bc2804d2013-08-06 07:45:492123 {
[email protected]cb189e062014-04-23 00:57:012124 SkBitmap bitmap;
kylechare7d8d5c72018-01-05 19:06:282125 bitmap.installPixels(info, shm->memory(), info.minRowBytes());
enne98c9f8052017-03-15 19:38:222126 cc::SkiaPaintCanvas canvas(bitmap);
[email protected]f9526d12012-10-18 01:55:032127
[email protected]bc2804d2013-08-06 07:45:492128 // TODO(trchen): Cleanup the device scale factor mess.
2129 // device scale will be applied in WebKit
2130 // --> zoom_rect doesn't include device scale,
Christopher Camerone9a30c12018-03-07 08:23:382131 // but WebKit will still draw on zoom_rect *
Fady Samuela863f152018-03-09 16:10:032132 // GetWebScreenInfo().device_scale_factor
Jaebaek Seo6de124a2018-02-15 03:34:032133 canvas.scale(new_total_scale / to_pix, new_total_scale / to_pix);
2134 canvas.translate(-zoom_rect.x() * to_pix, -zoom_rect.y() * to_pix);
[email protected]f9526d12012-10-18 01:55:032135
Blink Reformat1c4d759e2017-04-09 16:34:542136 DCHECK(webview_->IsAcceleratedCompositingActive());
Chris Harrelsonc5b48e22018-01-27 03:48:062137 webview_->UpdateAllLifecyclePhases();
David Bokanc9294862018-07-17 18:39:062138 webview_->PaintContentIgnoringCompositing(&canvas, zoom_rect);
[email protected]bc2804d2013-08-06 07:45:492139 }
2140
timav29a8d0f62014-09-25 20:45:532141 gfx::Rect zoom_rect_in_screen =
2142 zoom_rect - gfx::Vector2d(inner_viewport_offset.width,
2143 inner_viewport_offset.height);
2144
[email protected]bc2804d2013-08-06 07:45:492145 gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect(
Jaebaek Seo6de124a2018-02-15 03:34:032146 gfx::ScaleRect(gfx::RectF(zoom_rect_in_screen),
2147 to_pix * webview()->PageScaleFactor()));
timav29a8d0f62014-09-25 20:45:532148
kylechare7d8d5c72018-01-05 19:06:282149 // A SharedMemoryHandle is sent to the browser process, which is
2150 // responsible for freeing the shared memory when no longer needed.
fsamuele8326c742016-01-12 00:49:392151 Send(new ViewHostMsg_ShowDisambiguationPopup(
Albert J. Wongcb004632018-07-10 22:58:252152 GetWidget()->routing_id(), physical_window_zoom_rect, canvas_size,
kylechare7d8d5c72018-01-05 19:06:282153 shm->TakeHandle()));
2154
[email protected]4ded1dbf2013-08-28 21:11:032155 handled = true;
2156 break;
2157 }
2158 case TAP_MULTIPLE_TARGETS_STRATEGY_NONE:
2159 // No-op.
2160 break;
[email protected]f9526d12012-10-18 01:55:032161 }
[email protected]70221f02013-01-31 22:17:072162
[email protected]4ded1dbf2013-08-28 21:11:032163 return handled;
[email protected]f9526d12012-10-18 01:55:032164}
braveyao1d8ee7b2017-03-29 21:10:042165
2166void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) {
2167 if (!main_render_frame_)
2168 return;
2169
Chandan Padhi26dbd9b32017-11-27 11:13:352170 MediaStreamDeviceObserver* media_stream_device_observer =
2171 main_render_frame_->GetMediaStreamDeviceObserver();
2172 if (!media_stream_device_observer)
braveyao1d8ee7b2017-03-29 21:10:042173 return;
2174
Chandan Padhi6dbfb732017-09-01 16:08:492175 MediaStreamDevices video_devices =
Chandan Padhi26dbd9b32017-11-27 11:13:352176 media_stream_device_observer->GetNonScreenCaptureDevices();
braveyao1d8ee7b2017-03-29 21:10:042177 RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices(
Chandan Padhi6dbfb732017-09-01 16:08:492178 video_devices, suspend);
braveyao1d8ee7b2017-03-29 21:10:042179}
estade6b9696bd2016-05-04 23:51:362180#endif // defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:032181
[email protected]b283d292013-02-21 08:40:342182unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
2183 return history_list_length_;
2184}
2185
[email protected]cc290f902013-03-04 20:06:022186void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
Nasko Oskova463a052018-05-08 16:42:142187 // If the main frame is remote, return immediately. Page level focus
2188 // should be set from the browser process, so if needed by tests it should
2189 // be properly supported.
2190 if (webview()->MainFrame()->IsWebRemoteFrame())
2191 return;
2192
danakja2c9d0a92018-07-25 20:01:182193 if (enable == has_focus())
2194 return;
2195
[email protected]cc290f902013-03-04 20:06:022196 if (enable) {
danakja2c9d0a92018-07-25 20:01:182197 SetActiveForWidget(true);
2198 // Fake an IPC message so go through the IPC handler.
[email protected]cc290f902013-03-04 20:06:022199 OnSetFocus(true);
2200 } else {
danakja2c9d0a92018-07-25 20:01:182201 // Fake an IPC message so go through the IPC handler.
[email protected]cc290f902013-03-04 20:06:022202 OnSetFocus(false);
danakja2c9d0a92018-07-25 20:01:182203 SetActiveForWidget(false);
[email protected]cc290f902013-03-04 20:06:022204 }
2205}
2206
Daniel Cheng224569ee2018-04-25 05:45:062207void RenderViewImpl::OnResolveTapDisambiguation(
2208 base::TimeTicks timestamp,
2209 const gfx::Point& tap_viewport_offset,
2210 bool is_long_press) {
2211 webview()->ResolveTapDisambiguation(timestamp, tap_viewport_offset,
aelias1b55156e52017-04-01 00:46:052212 is_long_press);
2213}
2214
[email protected]e9ff79c2012-10-19 21:31:262215} // namespace content