blob: 600c2a1fa7b87a6fd916adb2478465d6188daff5 [file] [log] [blame]
[email protected]b553edd52012-01-10 12:15:231// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]310ebd6302011-10-10 19:06:285#include "content/renderer/render_view_impl.h"
initial.commit09911bf2008-07-26 23:55:296
7#include <algorithm>
[email protected]b75b8292010-10-01 07:28:258#include <cmath>
dchengcedca5612016-04-09 01:40:159#include <memory>
lukasza5d0dee42017-06-14 21:57:3710#include <utility>
initial.commit09911bf2008-07-26 23:55:2911
[email protected]5d4e36d2013-02-15 15:18:2012#include "base/auto_reset.h"
[email protected]6e806822011-11-19 01:51:0813#include "base/bind.h"
14#include "base/bind_helpers.h"
initial.commit09911bf2008-07-26 23:55:2915#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5016#include "base/compiler_specific.h"
[email protected]2132d6b2013-06-05 00:15:4317#include "base/debug/alias.h"
avayvod232757942017-04-29 04:12:3418#include "base/feature_list.h"
[email protected]728c2ee2013-06-25 04:01:0719#include "base/files/file_path.h"
[email protected]edc3af82013-12-12 21:24:0720#include "base/i18n/rtl.h"
[email protected]b1cf3372011-04-20 21:28:1021#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4922#include "base/lazy_instance.h"
fdoray7a8954a42016-06-07 04:28:3823#include "base/location.h"
[email protected]f29efe6b2014-06-09 05:01:5124#include "base/metrics/field_trial.h"
asvitkine8d51e9d2016-09-02 23:55:4325#include "base/metrics/histogram_macros.h"
[email protected]d3b4ee22013-07-24 22:50:0626#include "base/process/kill.h"
[email protected]7d08a9352013-10-15 08:24:5627#include "base/process/process.h"
fdoray7a8954a42016-06-07 04:28:3828#include "base/single_thread_task_runner.h"
[email protected]21aa99682013-06-11 07:17:0129#include "base/strings/string_number_conversions.h"
[email protected]b9e7c479f2013-04-12 04:33:2430#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4931#include "base/strings/string_split.h"
[email protected]21aa99682013-06-11 07:17:0132#include "base/strings/string_util.h"
[email protected]40d11e02013-03-28 17:43:1433#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0034#include "base/strings/utf_string_conversions.h"
dalecurtiscd971252016-09-21 16:09:0035#include "base/sys_info.h"
fdoray7a8954a42016-06-07 04:28:3836#include "base/threading/thread_task_runner_handle.h"
[email protected]abb522162013-06-28 01:54:1637#include "base/time/time.h"
primiano9e38d552015-01-28 04:18:0138#include "base/trace_event/trace_event.h"
avi1023d012015-12-25 02:39:1439#include "build/build_config.h"
dongseong.hwange095dfa2016-02-04 11:21:3940#include "cc/base/switches.h"
enne98c9f8052017-03-15 19:38:2241#include "cc/paint/skia_paint_canvas.h"
danakj4c987652018-07-05 15:49:4142#include "cc/trees/layer_tree_host.h"
jinho.bang632a1a722014-09-18 03:02:5643#include "content/common/content_constants_internal.h"
[email protected]5f2aa722013-08-07 16:59:4144#include "content/common/dom_storage/dom_storage_types.h"
[email protected]59f4f2fa2011-03-23 01:00:5545#include "content/common/drag_messages.h"
[email protected]c6bc20332014-02-28 18:30:3946#include "content/common/frame_messages.h"
alexmosbc7eafa2014-12-06 01:38:0947#include "content/common/frame_replication_state.h"
[email protected]c084330e02013-04-27 01:08:1548#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0749#include "content/common/page_messages.h"
rockot5c478a72016-09-28 23:14:1850#include "content/common/render_message_filter.mojom.h"
[email protected]778574e2011-03-21 22:03:5051#include "content/common/view_messages.h"
[email protected]744c2a22012-03-15 18:42:0452#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4853#include "content/public/common/content_constants.h"
Tarun Bansal73dd2ff82017-10-03 05:29:3454#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2955#include "content/public/common/content_switches.h"
kouhei40f03cb2015-09-24 07:47:0156#include "content/public/common/page_importance_signals.h"
clamyda97e8322014-10-07 21:57:2557#include "content/public/common/page_state.h"
[email protected]7940b8e2013-07-25 23:08:4958#include "content/public/common/page_zoom.h"
Leon Han963dc182018-11-06 05:41:4859#include "content/public/common/referrer_type_converters.h"
[email protected]818915cd2012-11-20 13:14:1160#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0361#include "content/public/common/url_constants.h"
Jaebaek Seo53ab80a662018-01-29 04:50:4662#include "content/public/common/use_zoom_for_dsf_policy.h"
[email protected]b3a97b52014-07-09 06:25:0563#include "content/public/common/web_preferences.h"
[email protected]d344114c2011-10-01 01:24:3464#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0765#include "content/public/renderer/document_state.h"
[email protected]3a034ebb2011-10-03 19:19:4466#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3667#include "content/public/renderer/render_view_visitor.h"
scottmg8e6c6082017-02-13 23:15:4868#include "content/public/renderer/window_features_converter.h"
John Abd-El-Malekdcf1d1372017-10-22 06:39:4169#include "content/renderer/appcache/appcache_dispatcher.h"
70#include "content/renderer/appcache/web_application_cache_host_impl.h"
[email protected]e6e56752012-08-10 00:46:0671#include "content/renderer/browser_plugin/browser_plugin.h"
72#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]dc293a72013-07-01 11:11:2273#include "content/renderer/drop_data_builder.h"
danakja6c10012018-07-06 14:25:3674#include "content/renderer/gpu/layer_tree_view.h"
[email protected]dc064352014-04-25 08:36:3875#include "content/renderer/history_serialization.h"
[email protected]66fca5bc2013-05-23 06:58:2976#include "content/renderer/ime_event_guard.h"
[email protected]92d457802013-04-01 19:18:4977#include "content/renderer/internal_document_state_data.h"
John Abd-El-Malek6b56ef712017-10-21 22:52:4678#include "content/renderer/loader/request_extra_data.h"
Amos Limbcc710e2018-06-08 05:51:1779#include "content/renderer/media/audio/audio_device_factory.h"
Miguel Casasa8c2c5a2018-02-12 18:51:0380#include "content/renderer/media/stream/media_stream_device_observer.h"
[email protected]6392d982013-04-16 16:59:2281#include "content/renderer/media/video_capture_impl_manager.h"
Patrik Höglundb564859b2018-05-17 11:17:1682#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
83#include "content/renderer/media/webrtc/rtc_peer_connection_handler.h"
[email protected]227692c52013-05-31 22:43:0484#include "content/renderer/render_frame_impl.h"
[email protected]5a7100d2014-05-19 01:29:0485#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0586#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4487#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4488#include "content/renderer/render_widget_fullscreen_pepper.h"
Daniel Murphye3eec92c2018-02-23 19:09:1589#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]663bd9e2011-03-21 01:07:0190#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]5b45ad42013-10-25 00:42:0491#include "content/renderer/resizing_mode_selector.h"
[email protected]12a936d2013-05-15 04:55:4992#include "content/renderer/savable_resources.h"
John Abd-El-Malek312a30bb2017-10-23 19:51:5293#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:2194#include "content/renderer/web_ui_extension_data.h"
[email protected]f5961142013-04-17 23:09:4295#include "media/audio/audio_output_device.h"
[email protected]ee68378a2010-08-10 01:05:4196#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:4497#include "media/media_buildflags.h"
servolkf54f5c8f2015-02-24 20:32:3998#include "media/renderers/audio_renderer_impl.h"
Dale Curtis863022e2017-08-19 02:05:3499#include "media/video/gpu_video_accelerator_factories.h"
[email protected]d1ef81d2012-07-24 11:39:36100#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29101#include "net/base/escape.h"
102#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09103#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04104#include "net/http/http_util.h"
Tarun Bansal73d67f02018-01-17 05:56:25105#include "net/nqe/effective_connection_type.h"
Scott Violet02e38b92018-03-27 23:42:14106#include "ppapi/buildflags/buildflags.h"
lukenb171b532014-09-24 05:50:38107#include "skia/ext/platform_canvas.h"
Blink Reformata30d4232018-04-07 15:31:06108#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
Daniel Murphy95792ef2018-10-04 01:29:55109#include "third_party/blink/public/common/dom_storage/session_storage_namespace_id.h"
Mustaq Ahmed76c2f4312018-06-07 20:48:01110#include "third_party/blink/public/common/frame/user_activation_update_source.h"
Blink Reformata30d4232018-04-07 15:31:06111#include "third_party/blink/public/mojom/page/page_visibility_state.mojom.h"
112#include "third_party/blink/public/platform/file_path_conversion.h"
113#include "third_party/blink/public/platform/url_conversion.h"
114#include "third_party/blink/public/platform/web_connection_type.h"
115#include "third_party/blink/public/platform/web_effective_connection_type.h"
116#include "third_party/blink/public/platform/web_http_body.h"
117#include "third_party/blink/public/platform/web_image.h"
118#include "third_party/blink/public/platform/web_input_event.h"
119#include "third_party/blink/public/platform/web_input_event_result.h"
120#include "third_party/blink/public/platform/web_network_state_notifier.h"
121#include "third_party/blink/public/platform/web_point.h"
122#include "third_party/blink/public/platform/web_rect.h"
123#include "third_party/blink/public/platform/web_runtime_features.h"
124#include "third_party/blink/public/platform/web_size.h"
125#include "third_party/blink/public/platform/web_string.h"
126#include "third_party/blink/public/platform/web_url.h"
127#include "third_party/blink/public/platform/web_url_error.h"
128#include "third_party/blink/public/platform/web_url_request.h"
129#include "third_party/blink/public/platform/web_url_response.h"
130#include "third_party/blink/public/platform/web_vector.h"
131#include "third_party/blink/public/public_buildflags.h"
132#include "third_party/blink/public/web/web_autofill_client.h"
133#include "third_party/blink/public/web/web_ax_object.h"
134#include "third_party/blink/public/web/web_date_time_chooser_completion.h"
135#include "third_party/blink/public/web/web_date_time_chooser_params.h"
136#include "third_party/blink/public/web/web_document.h"
137#include "third_party/blink/public/web/web_dom_event.h"
138#include "third_party/blink/public/web/web_dom_message_event.h"
139#include "third_party/blink/public/web/web_element.h"
Blink Reformata30d4232018-04-07 15:31:06140#include "third_party/blink/public/web/web_form_control_element.h"
141#include "third_party/blink/public/web/web_form_element.h"
142#include "third_party/blink/public/web/web_frame.h"
143#include "third_party/blink/public/web/web_frame_content_dumper.h"
144#include "third_party/blink/public/web/web_frame_widget.h"
145#include "third_party/blink/public/web/web_history_item.h"
146#include "third_party/blink/public/web/web_hit_test_result.h"
147#include "third_party/blink/public/web/web_input_element.h"
148#include "third_party/blink/public/web/web_local_frame.h"
Blink Reformata30d4232018-04-07 15:31:06149#include "third_party/blink/public/web/web_navigation_policy.h"
150#include "third_party/blink/public/web/web_page_importance_signals.h"
danakj25ec6e2b2018-09-26 17:01:31151#include "third_party/blink/public/web/web_page_popup.h"
Blink Reformata30d4232018-04-07 15:31:06152#include "third_party/blink/public/web/web_plugin.h"
153#include "third_party/blink/public/web/web_plugin_action.h"
154#include "third_party/blink/public/web/web_range.h"
155#include "third_party/blink/public/web/web_render_theme.h"
156#include "third_party/blink/public/web/web_script_source.h"
157#include "third_party/blink/public/web/web_searchable_form_data.h"
158#include "third_party/blink/public/web/web_security_policy.h"
159#include "third_party/blink/public/web/web_settings.h"
160#include "third_party/blink/public/web/web_user_gesture_indicator.h"
161#include "third_party/blink/public/web/web_view.h"
162#include "third_party/blink/public/web/web_window_features.h"
[email protected]b3a97b52014-07-09 06:25:05163#include "third_party/icu/source/common/unicode/uchar.h"
164#include "third_party/icu/source/common/unicode/uscript.h"
esecklerf2bd55f72017-03-31 09:11:57165#include "third_party/skia/include/core/SkColor.h"
[email protected]1400e6dc2013-04-27 02:36:27166#include "ui/base/ui_base_switches_util.h"
tfarina655f81d2014-12-23 02:38:50167#include "ui/gfx/geometry/point.h"
tfarina3b0452d2014-12-31 15:20:09168#include "ui/gfx/geometry/rect.h"
169#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32170#include "ui/gfx/geometry/size_conversions.h"
[email protected]08397d52011-02-05 01:53:38171#include "ui/gfx/native_widget_types.h"
ccameron772317d2017-06-04 18:35:03172#include "ui/gfx/switches.h"
mfomitchev3ba450ad2017-04-03 18:20:40173#include "ui/latency/latency_info.h"
csharrisond88f9752016-10-26 23:56:36174#include "url/origin.h"
markdittmer67b71ea2016-03-03 22:40:03175#include "url/url_constants.h"
[email protected]c4a9e932011-03-05 04:05:55176#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:29177
[email protected]25fb9b32012-04-27 03:21:55178#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25179#include <cpu-features.h>
180
dalecurtiscd971252016-09-21 16:09:00181#include "base/android/build_info.h"
kylechare7d8d5c72018-01-05 19:06:28182#include "base/memory/shared_memory.h"
183#include "content/child/child_thread_impl.h"
tfarina3b0452d2014-12-31 15:20:09184#include "ui/gfx/geometry/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40185
[email protected]78043bdd2010-04-05 18:45:33186#elif defined(OS_MACOSX)
187#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57188#endif
189
brettw4b461082016-11-19 18:55:16190#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]ea2fb972013-08-07 05:44:26191#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
192#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26193#endif
194
[email protected]180ef242013-11-07 06:50:46195using blink::WebAXObject;
196using blink::WebApplicationCacheHost;
197using blink::WebApplicationCacheHostClient;
[email protected]180ef242013-11-07 06:50:46198using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46199using blink::WebData;
[email protected]180ef242013-11-07 06:50:46200using blink::WebDocument;
[email protected]180ef242013-11-07 06:50:46201using blink::WebDragOperation;
[email protected]180ef242013-11-07 06:50:46202using blink::WebElement;
[email protected]180ef242013-11-07 06:50:46203using blink::WebFormControlElement;
204using blink::WebFormElement;
205using blink::WebFrame;
dglazkov03223492016-02-08 22:16:03206using blink::WebFrameContentDumper;
[email protected]180ef242013-11-07 06:50:46207using blink::WebGestureEvent;
208using blink::WebHistoryItem;
209using blink::WebHTTPBody;
dglazkov8d0c21dd2016-08-06 15:56:36210using blink::WebHitTestResult;
[email protected]180ef242013-11-07 06:50:46211using blink::WebImage;
212using blink::WebInputElement;
213using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22214using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46215using blink::WebMouseEvent;
216using blink::WebNavigationPolicy;
217using blink::WebNavigationType;
218using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46219using blink::WebPluginAction;
[email protected]180ef242013-11-07 06:50:46220using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46221using blink::WebRect;
Daniel Chengd5e56ff2017-06-24 07:44:02222using blink::WebSandboxFlags;
[email protected]180ef242013-11-07 06:50:46223using blink::WebScriptSource;
224using blink::WebSearchableFormData;
225using blink::WebSecurityOrigin;
226using blink::WebSecurityPolicy;
[email protected]180ef242013-11-07 06:50:46227using blink::WebSettings;
228using blink::WebSize;
[email protected]180ef242013-11-07 06:50:46229using blink::WebString;
[email protected]180ef242013-11-07 06:50:46230using blink::WebTextDirection;
231using blink::WebTouchEvent;
232using blink::WebURL;
233using blink::WebURLError;
234using blink::WebURLRequest;
235using blink::WebURLResponse;
236using blink::WebUserGestureIndicator;
237using blink::WebVector;
238using blink::WebView;
239using blink::WebWidget;
240using blink::WebWindowFeatures;
[email protected]b3a97b52014-07-09 06:25:05241using blink::WebRuntimeFeatures;
[email protected]6fdd4182010-10-14 23:59:26242using base::TimeDelta;
[email protected]e1acf6f2008-10-27 20:43:33243
[email protected]e9ff79c2012-10-19 21:31:26244namespace content {
245
initial.commit09911bf2008-07-26 23:55:29246//-----------------------------------------------------------------------------
247
[email protected]180ef242013-11-07 06:50:46248typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
jbroman8319b232017-03-08 22:53:29249static base::LazyInstance<ViewMap>::Leaky g_view_map =
[email protected]058561b2012-12-03 06:48:22250 LAZY_INSTANCE_INITIALIZER;
scottmg5e65e3a2017-03-08 08:48:46251typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap;
jbroman8319b232017-03-08 22:53:29252static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map =
253 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02254
[email protected]882daa92009-11-05 16:31:31255// Time, in seconds, we delay before sending content state changes (such as form
256// state and scroll position) to the browser. We delay sending changes to avoid
257// spamming the browser.
258// To avoid having tab/session restore require sending a message to get the
259// current content state during tab closing we use a shorter timeout for the
260// foreground renderer. This means there is a small window of time from which
261// content state is modified and not sent to session restore, but this is
262// better than having to wake up all renderers during shutdown.
avif937e1d2014-11-02 18:13:07263const int kDelaySecondsForContentStateSyncHidden = 5;
264const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29265
dcheng35d31c112015-07-22 00:17:36266static RenderViewImpl* (*g_create_render_view_impl)(
267 CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15268 const mojom::CreateViewParams&) = nullptr;
[email protected]8d41d7612012-11-14 20:32:19269
[email protected]c6bc20332014-02-28 18:30:39270// static
[email protected]e507045d2013-07-24 15:23:44271Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56272 WebFrame* frame,
273 const WebURLRequest& request) {
Blink Reformat1c4d759e2017-04-09 16:34:54274 return Referrer(blink::WebStringToGURL(
275 request.HttpHeaderField(WebString::FromUTF8("Referer"))),
276 request.GetReferrerPolicy());
[email protected]44e55b012013-07-23 14:21:56277}
278
[email protected]c6bc20332014-02-28 18:30:39279// static
[email protected]65920f332014-03-04 21:14:18280WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32281 WebNavigationPolicy policy) {
282 switch (policy) {
Blink Reformat1c4d759e2017-04-09 16:34:54283 case blink::kWebNavigationPolicyIgnore:
nick3b04f322016-08-31 19:29:19284 return WindowOpenDisposition::IGNORE_ACTION;
Blink Reformat1c4d759e2017-04-09 16:34:54285 case blink::kWebNavigationPolicyDownload:
nick3b04f322016-08-31 19:29:19286 return WindowOpenDisposition::SAVE_TO_DISK;
Blink Reformat1c4d759e2017-04-09 16:34:54287 case blink::kWebNavigationPolicyCurrentTab:
nick3b04f322016-08-31 19:29:19288 return WindowOpenDisposition::CURRENT_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54289 case blink::kWebNavigationPolicyNewBackgroundTab:
nick3b04f322016-08-31 19:29:19290 return WindowOpenDisposition::NEW_BACKGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54291 case blink::kWebNavigationPolicyNewForegroundTab:
nick3b04f322016-08-31 19:29:19292 return WindowOpenDisposition::NEW_FOREGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54293 case blink::kWebNavigationPolicyNewWindow:
nick3b04f322016-08-31 19:29:19294 return WindowOpenDisposition::NEW_WINDOW;
Blink Reformat1c4d759e2017-04-09 16:34:54295 case blink::kWebNavigationPolicyNewPopup:
nick3b04f322016-08-31 19:29:19296 return WindowOpenDisposition::NEW_POPUP;
[email protected]48861e22013-01-09 00:27:32297 default:
298 NOTREACHED() << "Unexpected WebNavigationPolicy";
nick3b04f322016-08-31 19:29:19299 return WindowOpenDisposition::IGNORE_ACTION;
[email protected]48861e22013-01-09 00:27:32300 }
301}
302
initial.commit09911bf2008-07-26 23:55:29303///////////////////////////////////////////////////////////////////////////////
304
[email protected]217690d2012-01-27 07:33:11305namespace {
306
[email protected]b3a97b52014-07-09 06:25:05307typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
308 const base::string16&,
309 UScriptCode);
310
311void SetStandardFontFamilyWrapper(WebSettings* settings,
312 const base::string16& font,
313 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54314 settings->SetStandardFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05315}
316
317void SetFixedFontFamilyWrapper(WebSettings* settings,
318 const base::string16& font,
319 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54320 settings->SetFixedFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05321}
322
323void SetSerifFontFamilyWrapper(WebSettings* settings,
324 const base::string16& font,
325 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54326 settings->SetSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05327}
328
329void SetSansSerifFontFamilyWrapper(WebSettings* settings,
330 const base::string16& font,
331 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54332 settings->SetSansSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05333}
334
335void SetCursiveFontFamilyWrapper(WebSettings* settings,
336 const base::string16& font,
337 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54338 settings->SetCursiveFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05339}
340
341void SetFantasyFontFamilyWrapper(WebSettings* settings,
342 const base::string16& font,
343 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54344 settings->SetFantasyFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05345}
346
347void SetPictographFontFamilyWrapper(WebSettings* settings,
348 const base::string16& font,
349 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54350 settings->SetPictographFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05351}
352
353// If |scriptCode| is a member of a family of "similar" script codes, returns
354// the script code in that family that is used by WebKit for font selection
355// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
356// considered equivalent for the purposes of font selection. WebKit uses the
357// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
358// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
359// uses different scripts than the ones in Chrome pref names because the version
360// of ICU included on certain ports does not have some of the newer scripts. If
361// |scriptCode| is not a member of such a family, returns |scriptCode|.
362UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
363 switch (scriptCode) {
364 case USCRIPT_HIRAGANA:
365 case USCRIPT_KATAKANA:
366 case USCRIPT_JAPANESE:
367 return USCRIPT_KATAKANA_OR_HIRAGANA;
368 case USCRIPT_KOREAN:
369 return USCRIPT_HANGUL;
370 default:
371 return scriptCode;
372 }
373}
374
375void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
376 SetFontFamilyWrapper setter,
377 WebSettings* settings) {
jdoerrie5a73d0fa2018-10-02 23:54:05378 for (auto it = map.begin(); it != map.end(); ++it) {
avi1023d012015-12-25 02:39:14379 int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
[email protected]b3a97b52014-07-09 06:25:05380 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
381 UScriptCode code = static_cast<UScriptCode>(script);
382 (*setter)(settings, it->second, GetScriptForWebSettings(code));
383 }
384 }
385}
386
wangxianzhu3bf39be52015-04-10 23:56:41387void ApplyBlinkSettings(const base::CommandLine& command_line,
388 WebSettings* settings) {
389 if (!command_line.HasSwitch(switches::kBlinkSettings))
390 return;
391
brettw26dab8f02015-08-08 00:28:47392 std::vector<std::string> blink_settings = base::SplitString(
393 command_line.GetSwitchValueASCII(switches::kBlinkSettings),
394 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
wangxianzhu3bf39be52015-04-10 23:56:41395 for (const std::string& setting : blink_settings) {
396 size_t pos = setting.find('=');
Blink Reformat1c4d759e2017-04-09 16:34:54397 settings->SetFromStrings(
398 blink::WebString::FromLatin1(setting.substr(0, pos)),
399 blink::WebString::FromLatin1(
wangxianzhu3bf39be52015-04-10 23:56:41400 pos == std::string::npos ? "" : setting.substr(pos + 1)));
401 }
402}
403
scottmgde42fb92017-02-10 17:56:03404content::mojom::WindowContainerType WindowFeaturesToContainerType(
scottmg05324cb2017-02-09 23:46:04405 const blink::WebWindowFeatures& window_features) {
japhetbfc47892017-06-02 23:01:19406 if (window_features.background) {
407 if (window_features.persistent)
scottmgde42fb92017-02-10 17:56:03408 return content::mojom::WindowContainerType::PERSISTENT;
scottmg05324cb2017-02-09 23:46:04409 else
scottmgde42fb92017-02-10 17:56:03410 return content::mojom::WindowContainerType::BACKGROUND;
scottmg05324cb2017-02-09 23:46:04411 } else {
scottmgde42fb92017-02-10 17:56:03412 return content::mojom::WindowContainerType::NORMAL;
scottmg05324cb2017-02-09 23:46:04413 }
414}
415
Ahmed Fakhry58e6ef542018-09-04 18:05:38416// Check content::BrowserControlsState, and cc::BrowserControlsState
417// are kept in sync.
418static_assert(int(BROWSER_CONTROLS_STATE_SHOWN) ==
419 int(cc::BrowserControlsState::kShown),
420 "mismatching enums: SHOWN");
421static_assert(int(BROWSER_CONTROLS_STATE_HIDDEN) ==
422 int(cc::BrowserControlsState::kHidden),
423 "mismatching enums: HIDDEN");
424static_assert(int(BROWSER_CONTROLS_STATE_BOTH) ==
425 int(cc::BrowserControlsState::kBoth),
426 "mismatching enums: BOTH");
427
428cc::BrowserControlsState ContentToCc(BrowserControlsState state) {
429 return static_cast<cc::BrowserControlsState>(state);
430}
Ahmed Fakhry58e6ef542018-09-04 18:05:38431
[email protected]217690d2012-01-27 07:33:11432} // namespace
433
Hajime Hoshi315a61f2018-08-14 17:27:28434RenderViewImpl::RenderViewImpl(CompositorDependencies* compositor_deps,
435 const mojom::CreateViewParams& params)
Albert J. Wongcb004632018-07-10 22:58:25436 : RenderWidget(params.main_frame_widget_routing_id,
nick8331f8ad2016-11-15 20:42:45437 compositor_deps,
danakj829cdd142018-09-14 21:13:27438 WidgetType::kFrame,
Scott Violetae08f332018-07-27 17:37:23439 params.visual_properties.screen_info,
danakj73dd3032018-07-28 17:49:53440 params.visual_properties.display_mode,
naskobd911332014-11-25 01:13:36441 params.swapped_out,
442 params.hidden,
Hajime Hoshi315a61f2018-08-14 17:27:28443 params.never_visible),
Albert J. Wongcb004632018-07-10 22:58:25444 routing_id_(params.view_id),
danakj73dd3032018-07-28 17:49:53445 renderer_wide_named_frame_lookup_(
446 params.renderer_wide_named_frame_lookup),
naskobd911332014-11-25 01:13:36447 webkit_preferences_(params.web_preferences),
changwand659e202016-06-13 02:39:12448 session_storage_namespace_id_(params.session_storage_namespace_id),
wjmaclean1d970622017-01-21 22:28:24449 weak_ptr_factory_(this) {
Daniel Murphy95792ef2018-10-04 01:29:55450 DCHECK(!session_storage_namespace_id_.empty())
451 << "Session storage namespace must be populated.";
avi40b5be7a2016-03-03 21:13:44452 GetWidget()->set_owner_delegate(this);
Albert J. Wongcb004632018-07-10 22:58:25453 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]075366912013-02-18 07:13:24454}
455
nickf7b38222016-11-22 21:59:35456void RenderViewImpl::Initialize(
Balazs Engedyba034e72017-10-27 22:26:28457 mojom::CreateViewParamsPtr params,
danakjdf1ceb72018-07-18 20:02:25458 RenderWidget::ShowCallback show_callback,
Hajime Hoshif34374412018-03-05 14:32:54459 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
nickf7b38222016-11-22 21:59:35460#if defined(OS_ANDROID)
danakjc87bfede2018-10-10 22:32:49461 bool has_show_callback = !!show_callback;
nickf7b38222016-11-22 21:59:35462#endif
[email protected]676126f72011-01-15 00:03:51463
Lukasz Anforowiczaf2f33572018-01-17 14:05:08464 WebFrame* opener_frame =
465 RenderFrameImpl::ResolveOpener(params->opener_frame_route_id);
466
danakj9a8a9cf2018-07-17 23:52:12467 // Pass WidgetClient(), not |this|, as the WebWidgetClient. The method may
468 // be overridden in layout tests to inject a test-only WebWidgetClient.
Lukasz Anforowiczaf2f33572018-01-17 14:05:08469 webview_ =
danakj9a8a9cf2018-07-17 23:52:12470 WebView::Create(this, WidgetClient(),
Lukasz Anforowiczaf2f33572018-01-17 14:05:08471 is_hidden() ? blink::mojom::PageVisibilityState::kHidden
472 : blink::mojom::PageVisibilityState::kVisible,
473 opener_frame ? opener_frame->View() : nullptr);
danakj763c2402018-11-09 02:46:22474 RenderWidget::Init(std::move(show_callback), webview_->MainFrameWidget());
[email protected]11fee2332011-03-29 20:36:35475
nasko4c0feb62015-06-05 18:37:06476 g_view_map.Get().insert(std::make_pair(webview(), this));
avia3dca182016-03-19 01:09:52477 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this));
nasko4c0feb62015-06-05 18:37:06478
avi83883c82014-12-23 00:08:49479 const base::CommandLine& command_line =
480 *base::CommandLine::ForCurrentProcess();
[email protected]20657a82012-08-21 20:23:03481
danakj53802692018-07-25 21:46:44482 webview()->SetDisplayMode(GetWidget()->display_mode());
Blink Reformat1c4d759e2017-04-09 16:34:54483 webview()->GetSettings()->SetThreadedScrollingEnabled(
dcheng0ff94cfc2016-03-15 21:50:51484 !command_line.HasSwitch(switches::kDisableThreadedScrolling));
Blink Reformat1c4d759e2017-04-09 16:34:54485 webview()->SetShowFPSCounter(
dcheng0ff94cfc2016-03-15 21:50:51486 command_line.HasSwitch(cc::switches::kShowFPSCounter));
487
danakjfd0c7f42018-10-12 18:01:08488 ApplyWebPreferences(webkit_preferences_, webview());
dcheng0ff94cfc2016-03-15 21:50:51489
490 if (switches::IsTouchDragDropEnabled())
Blink Reformat1c4d759e2017-04-09 16:34:54491 webview()->GetSettings()->SetTouchDragDropEnabled(true);
dcheng0ff94cfc2016-03-15 21:50:51492
493 WebSettings::SelectionStrategyType selection_strategy =
Blink Reformat1c4d759e2017-04-09 16:34:54494 WebSettings::SelectionStrategyType::kCharacter;
dcheng0ff94cfc2016-03-15 21:50:51495 const std::string selection_strategy_str =
Gyuyoung Kim63abad22018-06-15 03:16:55496 command_line.GetSwitchValueASCII(switches::kTouchTextSelectionStrategy);
dcheng0ff94cfc2016-03-15 21:50:51497 if (selection_strategy_str == "direction")
Blink Reformat1c4d759e2017-04-09 16:34:54498 selection_strategy = WebSettings::SelectionStrategyType::kDirection;
499 webview()->GetSettings()->SetSelectionStrategy(selection_strategy);
dcheng0ff94cfc2016-03-15 21:50:51500
Gyuyoung Kim63abad22018-06-15 03:16:55501 std::string passive_listeners_default =
dtapuskaf65650b2016-05-13 17:21:34502 command_line.GetSwitchValueASCII(switches::kPassiveListenersDefault);
Gyuyoung Kim63abad22018-06-15 03:16:55503 if (!passive_listeners_default.empty()) {
dtapuskaf65650b2016-05-13 17:21:34504 WebSettings::PassiveEventListenerDefault passiveDefault =
Blink Reformat1c4d759e2017-04-09 16:34:54505 WebSettings::PassiveEventListenerDefault::kFalse;
Gyuyoung Kim63abad22018-06-15 03:16:55506 if (passive_listeners_default == "true")
Blink Reformat1c4d759e2017-04-09 16:34:54507 passiveDefault = WebSettings::PassiveEventListenerDefault::kTrue;
Gyuyoung Kim63abad22018-06-15 03:16:55508 else if (passive_listeners_default == "forcealltrue")
Blink Reformat1c4d759e2017-04-09 16:34:54509 passiveDefault = WebSettings::PassiveEventListenerDefault::kForceAllTrue;
510 webview()->GetSettings()->SetPassiveEventListenerDefault(passiveDefault);
dtapuskaf65650b2016-05-13 17:21:34511 }
512
Kunihiko Sakamoto208565992018-08-07 03:15:17513 std::string network_quiet_timeout =
514 command_line.GetSwitchValueASCII(switches::kNetworkQuietTimeout);
515 if (!network_quiet_timeout.empty()) {
516 double network_quiet_timeout_seconds = 0.0;
517 if (base::StringToDouble(network_quiet_timeout,
518 &network_quiet_timeout_seconds)) {
519 webview()->GetSettings()->SetNetworkQuietTimeout(
520 network_quiet_timeout_seconds);
Gyuyoung Kim63abad22018-06-15 03:16:55521 }
522 }
523
Blink Reformat1c4d759e2017-04-09 16:34:54524 ApplyBlinkSettings(command_line, webview()->GetSettings());
dcheng0ff94cfc2016-03-15 21:50:51525
danakjaf29226f2018-09-25 17:56:57526 // We have either a main frame or a proxy routing id.
527 DCHECK_NE(params->main_frame_routing_id != MSG_ROUTING_NONE,
528 params->proxy_routing_id != MSG_ROUTING_NONE);
529
Balazs Engedyba034e72017-10-27 22:26:28530 if (params->main_frame_routing_id != MSG_ROUTING_NONE) {
Ken Rockot26efbd62017-11-16 04:39:49531 CHECK(params->main_frame_interface_provider.is_valid());
532 service_manager::mojom::InterfaceProviderPtr main_frame_interface_provider(
533 std::move(params->main_frame_interface_provider));
dcheng3ce04b62015-10-26 23:30:55534 main_render_frame_ = RenderFrameImpl::CreateMainFrame(
Balazs Engedyba034e72017-10-27 22:26:28535 this, params->main_frame_routing_id,
Ken Rockot26efbd62017-11-16 04:39:49536 std::move(main_frame_interface_provider),
Fady Samuela863f152018-03-09 16:10:03537 params->main_frame_widget_routing_id, params->hidden,
danakj53802692018-07-25 21:46:44538 GetWidget()->GetWebScreenInfo(), GetWidget()->compositor_deps(),
539 opener_frame, params->devtools_main_frame_token,
540 params->replicated_frame_state, params->has_committed_real_load);
danakjaf29226f2018-09-25 17:56:57541 } else {
Balazs Engedyba034e72017-10-27 22:26:28542 CHECK(params->swapped_out);
543 RenderFrameProxy::CreateFrameProxy(params->proxy_routing_id, GetRoutingID(),
nick3b5a21f2016-11-22 23:07:11544 opener_frame, MSG_ROUTING_NONE,
Dmitry Gozman89361212018-02-13 16:10:44545 params->replicated_frame_state,
546 params->devtools_main_frame_token);
nasko4c0feb62015-06-05 18:37:06547 }
548
[email protected]c7c0d822014-04-16 20:19:49549 // TODO(davidben): Move this state from Blink into content.
Balazs Engedyba034e72017-10-27 22:26:28550 if (params->window_was_created_with_opener)
Blink Reformat1c4d759e2017-04-09 16:34:54551 webview()->SetOpenedByDOM();
[email protected]c7c0d822014-04-16 20:19:49552
dcheng0ff94cfc2016-03-15 21:50:51553 UpdateWebViewWithDeviceScaleFactor();
Balazs Engedyba034e72017-10-27 22:26:28554 OnSetRendererPrefs(params->renderer_preferences);
Fady Samuelff5b6eb562018-05-01 16:16:08555 OnSynchronizeVisualProperties(params->visual_properties);
[email protected]1784b2f2011-11-24 10:53:48556
[email protected]e9ff79c2012-10-19 21:31:26557 GetContentClient()->renderer()->RenderViewCreated(this);
akabac6bd1212018-06-25 20:10:48558 page_zoom_level_ = 0;
Hajime Hoshif34374412018-03-05 14:32:54559
560 nav_state_sync_timer_.SetTaskRunner(task_runner);
danakjc87bfede2018-10-10 22:32:49561
562#if defined(OS_ANDROID)
563 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated
564 // HandleNavigation codepath.
565 // Renderer-created RenderViews have a ShowCallback because they send a Show
566 // request (ViewHostMsg_ShowWidget, ViewHostMsg_ShowFullscreenWidget, or
567 // FrameHostMsg_ShowCreatedWindow) to the browser to attach them to the UI
568 // there. Browser-created RenderViews do not send a Show request to the
569 // browser, so have no such callback.
570 was_created_by_renderer_ = has_show_callback;
571#endif
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();
jdoerrie5a73d0fa2018-10-02 23:54:05604 auto it = views->find(webview);
[email protected]a2ef54c2011-10-10 16:20:31605 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();
jdoerrie5a73d0fa2018-10-02 23:54:05616 auto it = views->find(routing_id);
[email protected]640e303c2012-12-05 01:36:07617 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();
jdoerrie5a73d0fa2018-10-02 23:54:05633 for (auto it = views->begin(); it != views->end(); ++it) {
[email protected]60c42a8c72009-10-09 04:08:59634 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);
Arthur Sonzogni721f48e2018-10-31 17:10:02685 settings->SetShouldProtectAgainstIpcFlooding(
686 !prefs.disable_ipc_flooding_protection);
Blink Reformat1c4d759e2017-04-09 16:34:54687 settings->SetHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
688 settings->SetCookieEnabled(prefs.cookie_enabled);
689 settings->SetNavigateOnDragDrop(prefs.navigate_on_drag_drop);
[email protected]b3a97b52014-07-09 06:25:05690
[email protected]b3a97b52014-07-09 06:25:05691 // By default, allow_universal_access_from_file_urls is set to false and thus
692 // we mitigate attacks from local HTML files by not granting file:// URLs
693 // universal access. Only test shell will enable this.
Blink Reformat1c4d759e2017-04-09 16:34:54694 settings->SetAllowUniversalAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05695 prefs.allow_universal_access_from_file_urls);
Blink Reformat1c4d759e2017-04-09 16:34:54696 settings->SetAllowFileAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05697 prefs.allow_file_access_from_file_urls);
698
Zhenyao Moa3fda9972017-09-16 01:34:40699 settings->SetWebGL1Enabled(prefs.webgl1_enabled);
700 settings->SetWebGL2Enabled(prefs.webgl2_enabled);
[email protected]b3a97b52014-07-09 06:25:05701
[email protected]b3a97b52014-07-09 06:25:05702 // Enable WebGL errors to the JS console if requested.
Blink Reformat1c4d759e2017-04-09 16:34:54703 settings->SetWebGLErrorsToConsoleEnabled(
[email protected]b3a97b52014-07-09 06:25:05704 prefs.webgl_errors_to_console_enabled);
705
706 // Uses the mock theme engine for scrollbars.
Blink Reformat1c4d759e2017-04-09 16:34:54707 settings->SetMockScrollbarsEnabled(prefs.mock_scrollbars_enabled);
[email protected]b3a97b52014-07-09 06:25:05708
Blink Reformat1c4d759e2017-04-09 16:34:54709 settings->SetHideScrollbars(prefs.hide_scrollbars);
eseckler61ff9142016-09-23 22:57:59710
[email protected]b3a97b52014-07-09 06:25:05711 // Enable gpu-accelerated 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54712 WebRuntimeFeatures::EnableAccelerated2dCanvas(
junov524668f22016-08-08 20:16:52713 prefs.accelerated_2d_canvas_enabled);
[email protected]b3a97b52014-07-09 06:25:05714
Blink Reformat1c4d759e2017-04-09 16:34:54715 settings->SetMinimumAccelerated2dCanvasSize(
[email protected]b3a97b52014-07-09 06:25:05716 prefs.minimum_accelerated_2d_canvas_size);
717
718 // Disable antialiasing for 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54719 settings->SetAntialiased2dCanvasEnabled(
[email protected]b3a97b52014-07-09 06:25:05720 !prefs.antialiased_2d_canvas_disabled);
721
zakerinasab20ebca02016-09-27 14:22:34722 // Disable antialiasing of clips for 2d canvas if requested on the command
robertphillipse25137b2014-10-20 13:44:34723 // line.
Blink Reformat1c4d759e2017-04-09 16:34:54724 settings->SetAntialiasedClips2dCanvasEnabled(
robertphillipse25137b2014-10-20 13:44:34725 prefs.antialiased_clips_2d_canvas_enabled);
726
[email protected]b3a97b52014-07-09 06:25:05727 // Set MSAA sample count for 2d canvas if requested on the command line (or
728 // default value if not).
Blink Reformat1c4d759e2017-04-09 16:34:54729 settings->SetAccelerated2dCanvasMSAASampleCount(
[email protected]b3a97b52014-07-09 06:25:05730 prefs.accelerated_2d_canvas_msaa_sample_count);
731
[email protected]b3a97b52014-07-09 06:25:05732 // Tabs to link is not part of the settings. WebCore calls
733 // ChromeClient::tabsToLinks which is part of the glue code.
Blink Reformat1c4d759e2017-04-09 16:34:54734 web_view->SetTabsToLinks(prefs.tabs_to_links);
[email protected]b3a97b52014-07-09 06:25:05735
Blink Reformat1c4d759e2017-04-09 16:34:54736 settings->SetAllowRunningOfInsecureContent(
[email protected]b3a97b52014-07-09 06:25:05737 prefs.allow_running_insecure_content);
Blink Reformat1c4d759e2017-04-09 16:34:54738 settings->SetDisableReadingFromCanvas(prefs.disable_reading_from_canvas);
739 settings->SetStrictMixedContentChecking(prefs.strict_mixed_content_checking);
mkwst2384c8222015-07-30 07:26:47740
Blink Reformat1c4d759e2017-04-09 16:34:54741 settings->SetStrictlyBlockBlockableMixedContent(
mkwst2384c8222015-07-30 07:26:47742 prefs.strictly_block_blockable_mixed_content);
743
Blink Reformat1c4d759e2017-04-09 16:34:54744 settings->SetStrictMixedContentCheckingForPlugin(
mkwst0d233e52015-08-10 09:33:14745 prefs.block_mixed_plugin_content);
746
Blink Reformat1c4d759e2017-04-09 16:34:54747 settings->SetStrictPowerfulFeatureRestrictions(
mkwst673a452f2015-01-10 14:41:50748 prefs.strict_powerful_feature_restrictions);
Blink Reformat1c4d759e2017-04-09 16:34:54749 settings->SetAllowGeolocationOnInsecureOrigins(
jww9d4ca2d2016-01-19 20:58:59750 prefs.allow_geolocation_on_insecure_origins);
Blink Reformat1c4d759e2017-04-09 16:34:54751 settings->SetPasswordEchoEnabled(prefs.password_echo_enabled);
752 settings->SetShouldPrintBackgrounds(prefs.should_print_backgrounds);
753 settings->SetShouldClearDocumentBackground(
[email protected]b3a97b52014-07-09 06:25:05754 prefs.should_clear_document_background);
Blink Reformat1c4d759e2017-04-09 16:34:54755 settings->SetEnableScrollAnimator(prefs.enable_scroll_animator);
[email protected]b3a97b52014-07-09 06:25:05756
Blink Reformat1c4d759e2017-04-09 16:34:54757 WebRuntimeFeatures::EnableTouchEventFeatureDetection(
sunyunjiafa6a8afc2016-12-09 04:25:47758 prefs.touch_event_feature_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54759 settings->SetMaxTouchPoints(prefs.pointer_events_max_touch_points);
760 settings->SetAvailablePointerTypes(prefs.available_pointer_types);
761 settings->SetPrimaryPointerType(
nzolghadrc0d1663c2015-11-26 21:15:24762 static_cast<blink::PointerType>(prefs.primary_pointer_type));
Blink Reformat1c4d759e2017-04-09 16:34:54763 settings->SetAvailableHoverTypes(prefs.available_hover_types);
764 settings->SetPrimaryHoverType(
nzolghadrc0d1663c2015-11-26 21:15:24765 static_cast<blink::HoverType>(prefs.primary_hover_type));
Blink Reformat1c4d759e2017-04-09 16:34:54766 settings->SetEnableTouchAdjustment(prefs.touch_adjustment_enabled);
Dave Tapuskaa59fdb62017-08-23 16:28:27767 settings->SetBarrelButtonForDragEnabled(prefs.barrel_button_for_drag_enabled);
[email protected]b3a97b52014-07-09 06:25:05768
Blink Reformat1c4d759e2017-04-09 16:34:54769 settings->SetShouldRespectImageOrientation(
[email protected]b3a97b52014-07-09 06:25:05770 prefs.should_respect_image_orientation);
771
Blink Reformat1c4d759e2017-04-09 16:34:54772 settings->SetEditingBehavior(
[email protected]b3a97b52014-07-09 06:25:05773 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
774
Blink Reformat1c4d759e2017-04-09 16:34:54775 settings->SetSupportsMultipleWindows(prefs.supports_multiple_windows);
[email protected]b3a97b52014-07-09 06:25:05776
Blink Reformat1c4d759e2017-04-09 16:34:54777 settings->SetMainFrameClipsContent(!prefs.record_whole_document);
khushalsagar2da2b232016-03-23 22:11:35778
Blink Reformat1c4d759e2017-04-09 16:34:54779 settings->SetSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
[email protected]b3a97b52014-07-09 06:25:05780
Blink Reformat1c4d759e2017-04-09 16:34:54781 settings->SetSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
[email protected]b3a97b52014-07-09 06:25:05782
Blink Reformat1c4d759e2017-04-09 16:34:54783 settings->SetSelectionIncludesAltImageText(true);
[email protected]b3a97b52014-07-09 06:25:05784
Blink Reformat1c4d759e2017-04-09 16:34:54785 settings->SetV8CacheOptions(
[email protected]35103c02014-08-12 15:08:47786 static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options));
787
Blink Reformat1c4d759e2017-04-09 16:34:54788 settings->SetImageAnimationPolicy(
je_julie.kim7fbb5a1a2015-02-09 17:26:05789 static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy));
790
Blink Reformat1c4d759e2017-04-09 16:34:54791 settings->SetPresentationRequiresUserGesture(
zqzhang1215ad422016-02-10 13:27:22792 prefs.user_gesture_required_for_presentation);
793
Blink Reformat1c4d759e2017-04-09 16:34:54794 settings->SetTextTrackMarginPercentage(prefs.text_track_margin_percentage);
halliwell4002be42016-03-18 18:33:40795
David Bokana03511a92018-09-13 04:25:24796 // Needs to happen before SetDefaultPageScaleLimits below since that'll
797 // recalculate the final page scale limits and that depends on this setting.
798 settings->SetShrinksViewportContentToFit(
799 prefs.shrinks_viewport_contents_to_fit);
800
801 // Needs to happen before SetIgnoreViewportTagScaleLimits below.
Blink Reformat1c4d759e2017-04-09 16:34:54802 web_view->SetDefaultPageScaleLimits(prefs.default_minimum_page_scale_factor,
803 prefs.default_maximum_page_scale_factor);
dcheng5ae8ca362015-02-05 04:03:47804
Nate Chapin9638e7102017-09-20 22:11:01805 settings->SetSavePreviousDocumentResources(
806 static_cast<WebSettings::SavePreviousDocumentResources>(
807 prefs.save_previous_document_resources));
808
Ahmed Fakhry42221452018-05-30 01:18:39809 settings->SetTextAutosizingEnabled(prefs.text_autosizing_enabled);
810 settings->SetDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
Tarun Bansald10f17a02018-09-13 00:23:17811 blink::WebNetworkStateNotifier::SetNetworkQualityWebHoldback(
812 static_cast<blink::WebEffectiveConnectionType>(
813 prefs.network_quality_estimator_web_holdback));
Ahmed Fakhry42221452018-05-30 01:18:39814
[email protected]b3a97b52014-07-09 06:25:05815#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:54816 settings->SetAllowCustomScrollbarInMainFrame(false);
Blink Reformat1c4d759e2017-04-09 16:34:54817 settings->SetAccessibilityFontScaleFactor(prefs.font_scale_factor);
818 settings->SetDeviceScaleAdjustment(prefs.device_scale_adjustment);
819 settings->SetFullscreenSupported(prefs.fullscreen_supported);
820 web_view->SetIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
821 settings->SetAutoZoomFocusedNodeToLegibleScale(true);
Peter Kotwicz2372030b2018-10-21 03:55:52822 settings->SetMediaPlaybackGestureWhitelistScope(blink::WebString::FromASCII(
823 prefs.media_playback_gesture_whitelist_scope.spec()));
Blink Reformat1c4d759e2017-04-09 16:34:54824 settings->SetDefaultVideoPosterURL(
825 WebString::FromASCII(prefs.default_video_poster_url.spec()));
826 settings->SetSupportDeprecatedTargetDensityDPI(
[email protected]b3a97b52014-07-09 06:25:05827 prefs.support_deprecated_target_density_dpi);
Blink Reformat1c4d759e2017-04-09 16:34:54828 settings->SetUseLegacyBackgroundSizeShorthandBehavior(
[email protected]b3a97b52014-07-09 06:25:05829 prefs.use_legacy_background_size_shorthand_behavior);
Blink Reformat1c4d759e2017-04-09 16:34:54830 settings->SetWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
831 settings->SetUseWideViewport(prefs.use_wide_viewport);
832 settings->SetForceZeroLayoutHeight(prefs.force_zero_layout_height);
833 settings->SetViewportMetaLayoutSizeQuirk(
[email protected]b3a97b52014-07-09 06:25:05834 prefs.viewport_meta_layout_size_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54835 settings->SetViewportMetaMergeContentQuirk(
[email protected]b3a97b52014-07-09 06:25:05836 prefs.viewport_meta_merge_content_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54837 settings->SetViewportMetaNonUserScalableQuirk(
[email protected]b3a97b52014-07-09 06:25:05838 prefs.viewport_meta_non_user_scalable_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54839 settings->SetViewportMetaZeroValuesQuirk(
[email protected]b3a97b52014-07-09 06:25:05840 prefs.viewport_meta_zero_values_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54841 settings->SetClobberUserAgentInitialScaleQuirk(
[email protected]b3a97b52014-07-09 06:25:05842 prefs.clobber_user_agent_initial_scale_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54843 settings->SetIgnoreMainFrameOverflowHiddenQuirk(
[email protected]b3a97b52014-07-09 06:25:05844 prefs.ignore_main_frame_overflow_hidden_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54845 settings->SetReportScreenSizeInPhysicalPixelsQuirk(
[email protected]b3a97b52014-07-09 06:25:05846 prefs.report_screen_size_in_physical_pixels_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54847 settings->SetShouldReuseGlobalForUnownedMainFrame(
tzik30eb52c2018-03-27 06:55:18848 prefs.reuse_global_for_unowned_main_frame);
Blink Reformat1c4d759e2017-04-09 16:34:54849 settings->SetPreferHiddenVolumeControls(true);
850 settings->SetSpellCheckEnabledByDefault(prefs.spellcheck_enabled_by_default);
dalecurtiscd971252016-09-21 16:09:00851
aeliase678aa42017-04-14 22:41:04852 // Force preload=none and disable autoplay on older Android
dalecurtiscd971252016-09-21 16:09:00853 // platforms because their media pipelines are not stable enough to handle
854 // concurrent elements. See http://crbug.com/612909, http://crbug.com/622826.
aeliase678aa42017-04-14 22:41:04855 const bool is_jelly_bean =
dalecurtiscd971252016-09-21 16:09:00856 base::android::BuildInfo::GetInstance()->sdk_int() <=
aeliase678aa42017-04-14 22:41:04857 base::android::SDK_VERSION_JELLY_BEAN_MR2;
858 settings->SetForcePreloadNoneForMediaElements(is_jelly_bean);
mlamouri1d266bf2016-12-05 17:42:36859
Blink Reformat1c4d759e2017-04-09 16:34:54860 WebRuntimeFeatures::EnableVideoFullscreenOrientationLock(
mlamouri1d266bf2016-12-05 17:42:36861 prefs.video_fullscreen_orientation_lock_enabled);
johnme913ee5f2017-04-28 21:36:16862 WebRuntimeFeatures::EnableVideoRotateToFullscreen(
863 prefs.video_rotate_to_fullscreen_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54864 WebRuntimeFeatures::EnableVideoFullscreenDetection(
zqzhang93e959d12017-03-16 13:10:20865 prefs.video_fullscreen_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54866 settings->SetEmbeddedMediaExperienceEnabled(
shaktisahuf97f7532017-02-24 22:46:13867 prefs.embedded_media_experience_enabled);
Ian Vollickeeca1d82018-02-07 02:43:42868 settings->SetImmersiveModeEnabled(prefs.immersive_mode_enabled);
khushalsagarc5447db22017-08-22 17:53:01869 settings->SetMediaDownloadInProductHelpEnabled(
870 prefs.enable_media_download_in_product_help);
Blink Reformat1c4d759e2017-04-09 16:34:54871 settings->SetDoNotUpdateSelectionOnMutatingSelectionRange(
changwane54ccdb92017-04-05 19:20:54872 prefs.do_not_update_selection_on_mutating_selection_range);
Noel Gordonf311a842017-07-27 00:10:07873 WebRuntimeFeatures::EnableCSSHexAlphaColor(prefs.css_hex_alpha_color_enabled);
Tobias Sargeant416174f2017-09-01 01:18:09874 WebRuntimeFeatures::EnableScrollTopLeftInterop(
875 prefs.scroll_top_left_interop_enabled);
zqzhangdf72ed082016-12-08 16:07:55876#endif // defined(OS_ANDROID)
liberato9e934892016-05-03 19:00:27877
mlamouri55a0543c2017-05-11 10:34:07878 switch (prefs.autoplay_policy) {
879 case AutoplayPolicy::kNoUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28880 settings->SetAutoplayPolicy(
881 WebSettings::AutoplayPolicy::kNoUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07882 break;
883 case AutoplayPolicy::kUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28884 settings->SetAutoplayPolicy(
885 WebSettings::AutoplayPolicy::kUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07886 break;
887 case AutoplayPolicy::kUserGestureRequiredForCrossOrigin:
mlamouri276a6f32017-05-12 09:24:28888 settings->SetAutoplayPolicy(
889 WebSettings::AutoplayPolicy::kUserGestureRequiredForCrossOrigin);
mlamouri55a0543c2017-05-11 10:34:07890 break;
mlamouri431bb4e2017-06-06 08:54:24891 case AutoplayPolicy::kDocumentUserActivationRequired:
892 settings->SetAutoplayPolicy(
893 WebSettings::AutoplayPolicy::kDocumentUserActivationRequired);
894 break;
mlamouri55a0543c2017-05-11 10:34:07895 }
896
Blink Reformat1c4d759e2017-04-09 16:34:54897 settings->SetViewportEnabled(prefs.viewport_enabled);
898 settings->SetViewportMetaEnabled(prefs.viewport_meta_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54899 settings->SetViewportStyle(
alokp5d566962016-04-19 00:54:16900 static_cast<blink::WebViewportStyle>(prefs.viewport_style));
901
Blink Reformat1c4d759e2017-04-09 16:34:54902 settings->SetLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
903 settings->SetMainFrameResizesAreOrientationChanges(
yoava1a508b42015-10-20 12:03:21904 prefs.main_frame_resizes_are_orientation_changes);
905
Blink Reformat1c4d759e2017-04-09 16:34:54906 settings->SetUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
jinho.bang8f11ffa2014-12-04 06:03:03907
Blink Reformat1c4d759e2017-04-09 16:34:54908 settings->SetShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up);
909 settings->SetAlwaysShowContextMenuOnTouch(
amaralp547e4192016-06-03 19:17:35910 prefs.always_show_context_menu_on_touch);
Sandra Sunc79fc93a2018-04-10 15:22:23911 settings->SetSmoothScrollForFindEnabled(prefs.smooth_scroll_for_find_enabled);
ccameron2fd70de72015-02-19 00:40:40912
Blink Reformat1c4d759e2017-04-09 16:34:54913 settings->SetHideDownloadUI(prefs.hide_download_ui);
avayvod232757942017-04-29 04:12:34914 WebRuntimeFeatures::EnableNewRemotePlaybackPipeline(
915 base::FeatureList::IsEnabled(media::kNewRemotePlaybackPipeline));
qinmin72e8bd02016-10-21 19:35:37916
Blink Reformat1c4d759e2017-04-09 16:34:54917 settings->SetPresentationReceiver(prefs.presentation_receiver);
mlamouri57359d912016-11-29 20:11:50918
Blink Reformat1c4d759e2017-04-09 16:34:54919 settings->SetMediaControlsEnabled(prefs.media_controls_enabled);
mlamouri5cd9ae82017-02-18 11:05:09920
Tarun Bansal73d67f02018-01-17 05:56:25921 settings->SetLowPriorityIframesThreshold(
922 static_cast<blink::WebEffectiveConnectionType>(
923 prefs.low_priority_iframes_threshold));
924
Mounir Lamouri9c99a1602018-07-05 15:01:44925 settings->SetPictureInPictureEnabled(
926 prefs.picture_in_picture_enabled &&
[email protected]69db58f2018-09-26 20:27:56927 MediaFactory::GetVideoSurfaceLayerMode() !=
CJ DiMeglio89240472018-10-18 18:21:10928 blink::WebMediaPlayer::SurfaceLayerMode::kNever);
François Beaufort8c08979fc2018-03-05 13:06:31929
Tarun Bansal333819e2018-05-15 16:38:42930 settings->SetDataSaverHoldbackWebApi(
931 prefs.data_saver_holdback_web_api_enabled);
932 settings->SetDataSaverHoldbackMediaApi(
933 prefs.data_saver_holdback_media_api_enabled);
934
Scott Little878f7d6702018-05-31 22:09:06935 for (const auto& ect_distance_pair :
936 prefs.lazy_frame_loading_distance_thresholds_px) {
937 switch (ect_distance_pair.first) {
938 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
939 settings->SetLazyFrameLoadingDistanceThresholdPxUnknown(
940 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39941 continue;
Scott Little878f7d6702018-05-31 22:09:06942 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
943 settings->SetLazyFrameLoadingDistanceThresholdPxOffline(
944 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39945 continue;
Scott Little878f7d6702018-05-31 22:09:06946 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
947 settings->SetLazyFrameLoadingDistanceThresholdPxSlow2G(
948 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39949 continue;
Scott Little878f7d6702018-05-31 22:09:06950 case net::EFFECTIVE_CONNECTION_TYPE_2G:
951 settings->SetLazyFrameLoadingDistanceThresholdPx2G(
952 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39953 continue;
Scott Little878f7d6702018-05-31 22:09:06954 case net::EFFECTIVE_CONNECTION_TYPE_3G:
955 settings->SetLazyFrameLoadingDistanceThresholdPx3G(
956 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39957 continue;
Scott Little878f7d6702018-05-31 22:09:06958 case net::EFFECTIVE_CONNECTION_TYPE_4G:
959 settings->SetLazyFrameLoadingDistanceThresholdPx4G(
960 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39961 continue;
962 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
963 continue;
Scott Little878f7d6702018-05-31 22:09:06964 }
rajendrantd8026342018-08-29 08:08:39965 NOTREACHED();
966 }
967
968 for (const auto& ect_distance_pair :
969 prefs.lazy_image_loading_distance_thresholds_px) {
970 switch (ect_distance_pair.first) {
971 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
972 settings->SetLazyImageLoadingDistanceThresholdPxUnknown(
973 ect_distance_pair.second);
974 continue;
975 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
976 settings->SetLazyImageLoadingDistanceThresholdPxOffline(
977 ect_distance_pair.second);
978 continue;
979 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
980 settings->SetLazyImageLoadingDistanceThresholdPxSlow2G(
981 ect_distance_pair.second);
982 continue;
983 case net::EFFECTIVE_CONNECTION_TYPE_2G:
984 settings->SetLazyImageLoadingDistanceThresholdPx2G(
985 ect_distance_pair.second);
986 continue;
987 case net::EFFECTIVE_CONNECTION_TYPE_3G:
988 settings->SetLazyImageLoadingDistanceThresholdPx3G(
989 ect_distance_pair.second);
990 continue;
991 case net::EFFECTIVE_CONNECTION_TYPE_4G:
992 settings->SetLazyImageLoadingDistanceThresholdPx4G(
993 ect_distance_pair.second);
994 continue;
995 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
996 continue;
997 }
998 NOTREACHED();
Scott Little878f7d6702018-05-31 22:09:06999 }
1000
ccameron2fd70de72015-02-19 00:40:401001#if defined(OS_MACOSX)
Blink Reformat1c4d759e2017-04-09 16:34:541002 web_view->SetMaximumLegibleScale(prefs.default_maximum_page_scale_factor);
ccameron2fd70de72015-02-19 00:40:401003#endif
sunyunjia87f287b2016-09-09 00:38:131004
1005#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:541006 WebRuntimeFeatures::EnableMiddleClickAutoscroll(true);
sunyunjia87f287b2016-09-09 00:38:131007#endif
Dave Tapuskac6627e12018-08-30 15:07:191008
1009 // Only enable href translate if we have the experimental web platform
1010 // flag on and the translation service is available.
1011 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1012 switches::kEnableExperimentalWebPlatformFeatures)) {
1013 WebRuntimeFeatures::EnableHrefTranslate(prefs.translate_service_available);
1014 }
[email protected]b3a97b52014-07-09 06:25:051015}
1016
1017/*static*/
nickf7b38222016-11-22 21:59:351018RenderViewImpl* RenderViewImpl::Create(
1019 CompositorDependencies* compositor_deps,
Balazs Engedyba034e72017-10-27 22:26:281020 mojom::CreateViewParamsPtr params,
danakjdf1ceb72018-07-18 20:02:251021 RenderWidget::ShowCallback show_callback,
Hajime Hoshiabb3c8f2017-12-04 18:41:391022 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Balazs Engedyba034e72017-10-27 22:26:281023 DCHECK(params->view_id != MSG_ROUTING_NONE);
Albert J. Wongcb004632018-07-10 22:58:251024 DCHECK(params->main_frame_widget_routing_id != MSG_ROUTING_NONE);
Lei Zhang88f23ba2017-10-27 05:56:261025 RenderViewImpl* render_view;
[email protected]8d41d7612012-11-14 20:32:191026 if (g_create_render_view_impl)
Balazs Engedyba034e72017-10-27 22:26:281027 render_view = g_create_render_view_impl(compositor_deps, *params);
[email protected]075366912013-02-18 07:13:241028 else
Hajime Hoshi315a61f2018-08-14 17:27:281029 render_view = new RenderViewImpl(compositor_deps, *params);
[email protected]0287e762014-04-11 13:07:581030
danakjdf1ceb72018-07-18 20:02:251031 render_view->Initialize(std::move(params), std::move(show_callback),
Hajime Hoshif34374412018-03-05 14:32:541032 std::move(task_runner));
[email protected]075366912013-02-18 07:13:241033 return render_view;
[email protected]8d41d7612012-11-14 20:32:191034}
1035
1036// static
dcheng35d31c112015-07-22 00:17:361037void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
1038 *create_render_view_impl)(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:151039 const mojom::CreateViewParams&)) {
[email protected]8d41d7612012-11-14 20:32:191040 CHECK(!g_create_render_view_impl);
1041 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291042}
1043
[email protected]310ebd6302011-10-10 19:06:281044void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511045 observers_.AddObserver(observer);
1046}
1047
[email protected]310ebd6302011-10-10 19:06:281048void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1049 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511050 observers_.RemoveObserver(observer);
1051}
1052
Peter Kastinga4a3ed12018-01-31 04:07:591053blink::WebView* RenderViewImpl::webview() {
1054 return webview_;
1055}
1056
1057const blink::WebView* RenderViewImpl::webview() const {
lfg4fa48da2016-05-09 18:25:131058 return webview_;
[email protected]4d51d5bf2010-07-26 18:48:261059}
1060
danakja2c9d0a92018-07-25 20:01:181061// RenderWidgetOwnerDelegate -----------------------------------------
fsamuel72464894f2015-12-15 06:59:311062
danakja2c9d0a92018-07-25 20:01:181063blink::WebWidget* RenderViewImpl::GetWebWidgetForWidget() const {
1064 return frame_widget_;
1065}
1066
1067bool RenderViewImpl::RenderWidgetWillHandleMouseEventForWidget(
avid7d6b2e2016-03-04 19:41:171068 const blink::WebMouseEvent& event) {
fsamuel72464894f2015-12-15 06:59:311069 // If the mouse is locked, only the current owner of the mouse lock can
1070 // process mouse events.
danakja2c9d0a92018-07-25 20:01:181071 return GetWidget()->mouse_lock_dispatcher()->WillHandleMouseEvent(event);
fsamuel72464894f2015-12-15 06:59:311072}
1073
danakja2c9d0a92018-07-25 20:01:181074void RenderViewImpl::SetActiveForWidget(bool active) {
Albert J. Wongcb004632018-07-10 22:58:251075 if (webview())
1076 webview()->SetIsActive(active);
1077}
1078
danakja2c9d0a92018-07-25 20:01:181079bool RenderViewImpl::SupportsMultipleWindowsForWidget() {
1080 return webkit_preferences_.supports_multiple_windows;
1081}
1082
1083void RenderViewImpl::DidHandleGestureEventForWidget(
1084 const WebGestureEvent& event) {
1085 for (auto& observer : observers_)
1086 observer.DidHandleGestureEvent(event);
1087}
1088
danakja2c9d0a92018-07-25 20:01:181089void RenderViewImpl::DidCloseWidget() {
1090 // The webview_ is already destroyed by the time we get here, remove any
1091 // references to it.
1092 g_view_map.Get().erase(webview_);
1093 webview_ = nullptr;
1094 g_routing_id_view_map.Get().erase(GetRoutingID());
danakja2c9d0a92018-07-25 20:01:181095}
1096
1097void RenderViewImpl::ApplyNewSizeForWidget(const gfx::Size& old_size,
1098 const gfx::Size& new_size) {
danakj1ab8faf2018-10-12 18:24:281099 if (new_size != old_size) {
danakja2c9d0a92018-07-25 20:01:181100 // Only hide popups when the size changes. There are situations (e.g. hiding
1101 // the ChromeOS virtual keyboard) where we send a resize message with no
1102 // change in size, but we don't want to close popups.
1103 // See https://crbug.com/761908.
danakje26bef02018-10-12 17:21:241104 webview()->HidePopups();
danakja2c9d0a92018-07-25 20:01:181105 }
1106}
1107
1108void RenderViewImpl::ApplyNewDisplayModeForWidget(
1109 const blink::WebDisplayMode& new_display_mode) {
danakj1ab8faf2018-10-12 18:24:281110 webview()->SetDisplayMode(new_display_mode);
danakja2c9d0a92018-07-25 20:01:181111}
1112
1113void RenderViewImpl::ApplyAutoResizeLimitsForWidget(const gfx::Size& min_size,
1114 const gfx::Size& max_size) {
1115 webview()->EnableAutoResizeMode(min_size, max_size);
1116}
1117
1118void RenderViewImpl::DisableAutoResizeForWidget() {
1119 webview()->DisableAutoResizeMode();
1120}
1121
1122void RenderViewImpl::ScrollFocusedNodeIntoViewForWidget() {
1123 if (WebLocalFrame* focused_frame = GetWebView()->FocusedFrame()) {
1124 auto* frame_widget = focused_frame->LocalRoot()->FrameWidget();
1125 frame_widget->ScrollFocusedEditableElementIntoView();
1126 }
1127}
1128
1129void RenderViewImpl::DidReceiveSetFocusEventForWidget() {
1130 // This message must always be received when the main frame is a
1131 // WebLocalFrame.
1132 // TODO(ajwong): Can this be removed and just check |owner_delegate_| in
1133 // RenderWidget instead?
1134 CHECK(webview()->MainFrame()->IsWebLocalFrame());
1135}
1136
1137void RenderViewImpl::DidChangeFocusForWidget() {
1138 // Notify all BrowserPlugins of the RenderView's focus state.
1139 if (BrowserPluginManager::Get())
1140 BrowserPluginManager::Get()->UpdateFocusState();
1141}
1142
danakja2c9d0a92018-07-25 20:01:181143void RenderViewImpl::DidCommitCompositorFrameForWidget() {
1144 for (auto& observer : observers_)
1145 observer.DidCommitCompositorFrame();
Philip Rogers33cd2bcc2018-08-13 21:29:291146 UpdatePreferredSize();
danakja2c9d0a92018-07-25 20:01:181147}
1148
1149void RenderViewImpl::DidCompletePageScaleAnimationForWidget() {
1150 if (auto* focused_frame = GetWebView()->FocusedFrame()) {
1151 if (focused_frame->AutofillClient())
1152 focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame();
1153 }
1154}
1155
1156void RenderViewImpl::ResizeWebWidgetForWidget(
1157 const gfx::Size& size,
1158 float top_controls_height,
1159 float bottom_controls_height,
1160 bool browser_controls_shrink_blink_size) {
1161 webview()->ResizeWithBrowserControls(size, top_controls_height,
1162 bottom_controls_height,
1163 browser_controls_shrink_blink_size);
1164}
1165
1166void RenderViewImpl::RequestScheduleAnimationForWidget() {
1167 // Schedule the animation on the WidgetClient() which may not be the
1168 // RenderWidget directly in layout tests.
1169 WidgetClient()->ScheduleAnimation();
1170}
1171
1172void RenderViewImpl::SetScreenMetricsEmulationParametersForWidget(
1173 bool enabled,
1174 const blink::WebDeviceEmulationParams& params) {
danakj1ab8faf2018-10-12 18:24:281175 if (enabled)
1176 webview()->EnableDeviceEmulation(params);
1177 else
1178 webview()->DisableDeviceEmulation();
danakja2c9d0a92018-07-25 20:01:181179}
1180
1181// IPC message handlers -----------------------------------------
1182
danakja2c9d0a92018-07-25 20:01:181183void RenderViewImpl::OnUpdateTargetURLAck() {
1184 // Check if there is a targeturl waiting to be sent.
1185 if (target_url_status_ == TARGET_PENDING)
1186 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), pending_target_url_));
1187
1188 target_url_status_ = TARGET_NONE;
1189}
1190
1191void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset,
1192 int history_length) {
1193 // -1 <= history_offset < history_length <= kMaxSessionHistoryEntries(50).
1194 DCHECK_LE(-1, history_offset);
1195 DCHECK_LT(history_offset, history_length);
1196 DCHECK_LE(history_length, kMaxSessionHistoryEntries);
1197
1198 history_list_offset_ = history_offset;
1199 history_list_length_ = history_length;
1200}
1201
1202void RenderViewImpl::OnSetInitialFocus(bool reverse) {
1203 if (!webview())
1204 return;
1205 webview()->SetInitialFocus(reverse);
1206}
1207
1208void RenderViewImpl::OnUpdateWindowScreenRect(gfx::Rect window_screen_rect) {
1209 // Defers to the RenderWidget message handler.
danakj53802692018-07-25 21:46:441210 GetWidget()->SetWindowScreenRect(window_screen_rect);
danakja2c9d0a92018-07-25 20:01:181211}
1212
1213void RenderViewImpl::OnAudioStateChanged(bool is_audio_playing) {
1214 webview()->AudioStateChanged(is_audio_playing);
1215}
1216
1217void RenderViewImpl::OnPausePageScheduledTasks(bool paused) {
1218 webview()->PausePageScheduledTasks(paused);
1219}
1220
1221///////////////////////////////////////////////////////////////////////////////
1222
1223void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget,
1224 WebNavigationPolicy policy,
1225 const gfx::Rect& initial_rect) {
1226 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(),
1227 initial_rect));
1228}
1229
1230void RenderViewImpl::ShowCreatedFullscreenWidget(
1231 RenderWidget* fullscreen_widget,
1232 WebNavigationPolicy policy,
1233 const gfx::Rect& initial_rect) {
1234 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(),
1235 fullscreen_widget->routing_id()));
1236}
1237
1238void RenderViewImpl::SendFrameStateUpdates() {
1239 // Tell each frame with pending state to send its UpdateState message.
1240 for (int render_frame_routing_id : frames_with_pending_state_) {
1241 RenderFrameImpl* frame =
1242 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
1243 if (frame)
1244 frame->SendUpdateState();
1245 }
1246 frames_with_pending_state_.clear();
1247}
1248
danakja2c9d0a92018-07-25 20:01:181249// IPC::Listener -------------------------------------------------------------
fsamuel72464894f2015-12-15 06:59:311250
[email protected]310ebd6302011-10-10 19:06:281251bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281252 WebFrame* main_frame = webview() ? webview()->MainFrame() : nullptr;
Avi Drissmanb5f8e242017-12-12 05:21:561253 if (main_frame) {
1254 GURL active_url;
1255 if (main_frame->IsWebLocalFrame())
1256 active_url = main_frame->ToWebLocalFrame()->GetDocument().Url();
lukaszabedb4b22017-06-23 00:00:131257 GetContentClient()->SetActiveURL(
Avi Drissmanb5f8e242017-12-12 05:21:561258 active_url, main_frame->Top()->GetSecurityOrigin().ToString().Utf8());
1259 }
[email protected]f8b6b6f2009-03-10 16:48:261260
dchenga2d442c22016-10-13 15:39:211261 for (auto& observer : observers_) {
1262 if (observer.OnMessageReceived(message))
[email protected]676126f72011-01-15 00:03:511263 return true;
dchenga2d442c22016-10-13 15:39:211264 }
[email protected]b2abac72009-02-26 12:39:281265
[email protected]a95986a82010-12-24 06:19:281266 bool handled = true;
[email protected]e44d1342014-05-16 21:29:331267 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
mcnee432e47d2015-11-09 19:37:461268 IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale)
initial.commit09911bf2008-07-26 23:55:291269 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291270 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1271 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
initial.commit09911bf2008-07-26 23:55:291272 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
[email protected]30f75e62009-02-25 22:01:001273 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]ab32b16c2009-10-16 14:57:251274 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1275 OnEnablePreferredSizeChangedMode)
[email protected]80d96fa2009-06-10 22:34:511276 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]81375e872012-01-11 21:40:361277 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
wjmaclean64951902016-04-29 20:59:121278
1279 // Page messages.
lfgdb5c4ed2016-03-04 23:09:071280 IPC_MESSAGE_HANDLER(PageMsg_UpdateWindowScreenRect,
1281 OnUpdateWindowScreenRect)
lfg717154072016-06-30 15:04:161282 IPC_MESSAGE_HANDLER(PageMsg_WasHidden, OnPageWasHidden)
1283 IPC_MESSAGE_HANDLER(PageMsg_WasShown, OnPageWasShown)
alexmos136fd6e62016-08-15 20:58:411284 IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength,
1285 OnSetHistoryOffsetAndLength)
altimind8bd26c2016-11-04 11:44:541286 IPC_MESSAGE_HANDLER(PageMsg_AudioStateChanged, OnAudioStateChanged)
Gyuyoung Kim80143f5e2018-04-02 02:40:251287 IPC_MESSAGE_HANDLER(PageMsg_PausePageScheduledTasks,
1288 OnPausePageScheduledTasks)
lfg8d649cc2017-04-28 18:04:301289 IPC_MESSAGE_HANDLER(PageMsg_UpdateScreenInfo, OnUpdateScreenInfo)
Francois Doray47f759d2018-06-11 18:13:511290 IPC_MESSAGE_HANDLER(PageMsg_SetPageFrozen, SetPageFrozen)
lfg717154072016-06-30 15:04:161291
[email protected]a794f3a2013-10-30 17:00:321292 // Adding a new message? Add platform independent ones first, then put the
1293 // platform specific ones at the end.
[email protected]9e1ad4b2011-08-14 16:49:191294
initial.commit09911bf2008-07-26 23:55:291295 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281296 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291297 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401298
[email protected]a95986a82010-12-24 06:19:281299 return handled;
initial.commit09911bf2008-07-26 23:55:291300}
1301
[email protected]180ef242013-11-07 06:50:461302// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521303
Mustaq Ahmed55944cb2018-05-25 20:44:271304// TODO(csharrison): Migrate this method to WebLocalFrameClient /
1305// RenderFrameImpl, as it is now serviced by a mojo interface scoped to the
1306// opener frame.
Daniel Murphyc8e991a2018-10-12 22:09:031307WebView* RenderViewImpl::CreateView(
1308 WebLocalFrame* creator,
1309 const WebURLRequest& request,
1310 const WebWindowFeatures& features,
1311 const WebString& frame_name,
1312 WebNavigationPolicy policy,
1313 bool suppress_opener,
1314 WebSandboxFlags sandbox_flags,
1315 const blink::SessionStorageNamespaceId& session_storage_namespace_id) {
nick5ae4d2d2017-01-06 01:18:351316 RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator);
rockot5c478a72016-09-28 23:14:181317 mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New();
Mustaq Ahmedc4cb7162018-06-05 16:28:361318
1319 // User Activation v2 moves user gesture checks to the browser process, with
1320 // the exception of the extensions case handled through the following |if|.
1321 params->mimic_user_gesture =
1322 base::FeatureList::IsEnabled(features::kUserActivationV2)
1323 ? false
1324 : WebUserGestureIndicator::IsProcessingUserGesture(creator);
[email protected]00323f02013-07-24 15:47:411325 if (GetContentClient()->renderer()->AllowPopup())
Mustaq Ahmedc4cb7162018-06-05 16:28:361326 params->mimic_user_gesture = true;
1327
rockot5c478a72016-09-28 23:14:181328 params->window_container_type = WindowFeaturesToContainerType(features);
Daniel Murphye3eec92c2018-02-23 19:09:151329
Daniel Murphyc8e991a2018-10-12 22:09:031330 params->session_storage_namespace_id = session_storage_namespace_id;
1331 // TODO(dmurph): Don't copy session storage when features.noopener is true:
1332 // https://html.spec.whatwg.org/multipage/browsers.html#copy-session-storage
1333 // https://crbug.com/771959
Daniel Murphye3eec92c2018-02-23 19:09:151334 params->clone_from_session_storage_namespace_id =
1335 session_storage_namespace_id_;
Daniel Murphye3eec92c2018-02-23 19:09:151336
Daniel Chengd5e56ff2017-06-24 07:44:021337 const std::string& frame_name_utf8 = frame_name.Utf8(
1338 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
1339 params->frame_name = frame_name_utf8;
rockot5c478a72016-09-28 23:14:181340 params->opener_suppressed = suppress_opener;
1341 params->disposition = NavigationPolicyToDisposition(policy);
Blink Reformat1c4d759e2017-04-09 16:34:541342 if (!request.IsNull()) {
1343 params->target_url = request.Url();
Leon Han963dc182018-11-06 05:41:481344 params->referrer =
1345 blink::mojom::Referrer::From(GetReferrerFromRequest(creator, request));
[email protected]44e55b012013-07-23 14:21:561346 }
scottmg8e6c6082017-02-13 23:15:481347 params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
[email protected]8ab04652010-06-12 02:47:261348
rockot5c478a72016-09-28 23:14:181349 // We preserve this information before sending the message since |params| is
1350 // moved on send.
1351 bool is_background_tab =
1352 params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB;
Mustaq Ahmedc4cb7162018-06-05 16:28:361353 bool opened_by_user_gesture = params->mimic_user_gesture;
[email protected]22217ed32013-11-18 18:40:231354
Daniel Cheng8bb30c62017-10-23 20:40:471355 mojom::CreateNewWindowStatus status;
rockot5c478a72016-09-28 23:14:181356 mojom::CreateNewWindowReplyPtr reply;
Balazs Engedya40712f2017-09-15 15:01:111357 auto* frame_host = creator_frame->GetFrameHost();
Daniel Cheng8bb30c62017-10-23 20:40:471358 bool err = !frame_host->CreateNewWindow(std::move(params), &status, &reply);
1359 if (err || status == mojom::CreateNewWindowStatus::kIgnore)
rockot5c478a72016-09-28 23:14:181360 return nullptr;
[email protected]48c9cf2d2009-09-16 16:47:521361
Jochen Eisinger515337a2017-05-26 14:12:521362 // For Android WebView, we support a pop-up like behavior for window.open()
1363 // even if the embedding app doesn't support multiple windows. In this case,
1364 // window.open() will return "window" and navigate it to whatever URL was
Jochen Eisinger8cb28492017-10-04 10:58:131365 // passed. We also don't need to consume user gestures to protect against
1366 // multiple windows being opened, because, well, the app doesn't support
1367 // multiple windows.
Daniel Cheng8bb30c62017-10-23 20:40:471368 // TODO(dcheng): It's awkward that this is plumbed into Blink but not really
1369 // used much in Blink, except to enable layout testing... perhaps this should
1370 // be checked directly in the browser side.
1371 if (status == mojom::CreateNewWindowStatus::kReuse)
Jochen Eisinger515337a2017-05-26 14:12:521372 return webview();
1373
Daniel Cheng8bb30c62017-10-23 20:40:471374 DCHECK(reply);
1375 DCHECK_NE(MSG_ROUTING_NONE, reply->route_id);
1376 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_route_id);
1377 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_widget_route_id);
1378
Mustaq Ahmed76c2f4312018-06-07 20:48:011379 // The browser allowed creation of a new window and consumed the user
1380 // activation (UAv2 only).
1381 WebUserGestureIndicator::ConsumeUserGesture(
1382 creator, blink::UserActivationUpdateSource::kBrowser);
Jochen Eisinger8cb28492017-10-04 10:58:131383
[email protected]7912e822014-04-16 02:37:031384 // While this view may be a background extension page, it can spawn a visible
1385 // render view. So we just assume that the new one is not another background
1386 // page instead of passing on our own value.
1387 // TODO(vangelis): Can we tell if the new view will be a background page?
1388 bool never_visible = false;
[email protected]9115d5f2013-03-24 04:37:411389
Fady Samuelff5b6eb562018-05-01 16:16:081390 VisualProperties visual_properties = VisualProperties();
danakj53802692018-07-25 21:46:441391 visual_properties.screen_info = GetWidget()->screen_info();
mkosiba58fa72f02014-11-12 01:21:361392
[email protected]d6fa88f2013-10-18 16:00:431393 // The initial hidden state for the RenderViewImpl here has to match what the
1394 // browser will eventually decide for the given disposition. Since we have to
1395 // return from this call synchronously, we just have to make our best guess
1396 // and rely on the browser sending a WasHidden / WasShown message if it
1397 // disagrees.
Balazs Engedyba034e72017-10-27 22:26:281398 mojom::CreateViewParamsPtr view_params = mojom::CreateViewParams::New();
alexmos5ac402d2015-07-09 07:51:101399
Balazs Engedyba034e72017-10-27 22:26:281400 view_params->opener_frame_route_id = creator_frame->GetRoutingID();
avia3dca182016-03-19 01:09:521401 DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID());
alexmos5ac402d2015-07-09 07:51:101402
Balazs Engedyba034e72017-10-27 22:26:281403 view_params->window_was_created_with_opener = true;
1404 view_params->renderer_preferences = renderer_preferences_;
1405 view_params->web_preferences = webkit_preferences_;
1406 view_params->view_id = reply->route_id;
1407 view_params->main_frame_routing_id = reply->main_frame_route_id;
1408 view_params->main_frame_interface_provider =
1409 std::move(reply->main_frame_interface_provider);
1410 view_params->main_frame_widget_routing_id = reply->main_frame_widget_route_id;
1411 view_params->session_storage_namespace_id =
rockot5c478a72016-09-28 23:14:181412 reply->cloned_session_storage_namespace_id;
Daniel Murphy95792ef2018-10-04 01:29:551413 DCHECK(!view_params->session_storage_namespace_id.empty())
1414 << "Session storage namespace must be populated.";
Balazs Engedyba034e72017-10-27 22:26:281415 view_params->swapped_out = false;
1416 view_params->replicated_frame_state.frame_policy.sandbox_flags =
1417 sandbox_flags;
1418 view_params->replicated_frame_state.name = frame_name_utf8;
1419 view_params->devtools_main_frame_token = reply->devtools_main_frame_token;
Daniel Chengd5e56ff2017-06-24 07:44:021420 // Even if the main frame has a name, the main frame's unique name is always
1421 // the empty string.
Balazs Engedyba034e72017-10-27 22:26:281422 view_params->hidden = is_background_tab;
1423 view_params->never_visible = never_visible;
Fady Samuelff5b6eb562018-05-01 16:16:081424 view_params->visual_properties = visual_properties;
naskobd911332014-11-25 01:13:361425
nick5ae4d2d2017-01-06 01:18:351426 // Unretained() is safe here because our calling function will also call
1427 // show().
nickf7b38222016-11-22 21:59:351428 RenderWidget::ShowCallback show_callback =
danakjdf1ceb72018-07-18 20:02:251429 base::BindOnce(&RenderFrameImpl::ShowCreatedWindow,
1430 base::Unretained(creator_frame), opened_by_user_gesture);
nickf7b38222016-11-22 21:59:351431
Balazs Engedyba034e72017-10-27 22:26:281432 RenderViewImpl* view = RenderViewImpl::Create(
danakj53802692018-07-25 21:46:441433 GetWidget()->compositor_deps(), std::move(view_params),
1434 std::move(show_callback),
Hajime Hoshi6fc91142018-05-11 08:21:171435 creator->GetTaskRunner(blink::TaskType::kInternalDefault));
[email protected]48c9cf2d2009-09-16 16:47:521436
[email protected]48c9cf2d2009-09-16 16:47:521437 return view->webview();
1438}
1439
danakj829cdd142018-09-14 21:13:271440WebWidget* RenderViewImpl::CreatePopup(blink::WebLocalFrame* creator) {
danakj25ec6e2b2018-09-26 17:01:311441 mojom::WidgetPtr widget_channel;
1442 mojom::WidgetRequest widget_channel_request =
1443 mojo::MakeRequest(&widget_channel);
1444
1445 // Do a synchronous IPC to obtain a routing ID.
1446 int32_t widget_routing_id = MSG_ROUTING_NONE;
1447 bool success =
1448 RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
1449 GetRoutingID(), std::move(widget_channel), &widget_routing_id);
1450 if (!success) {
1451 // When the renderer is being killed the mojo message will fail.
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281452 return nullptr;
danakj25ec6e2b2018-09-26 17:01:311453 }
1454
1455 RenderWidget::ShowCallback opener_callback = base::BindOnce(
1456 &RenderViewImpl::ShowCreatedPopupWidget, weak_ptr_factory_.GetWeakPtr());
1457
1458 // The RenderWidget associated with the RenderView. This should be the
1459 // RenderWidget for the main frame, but may be a zombie RenderWidget when
1460 // the main frame is remote (we don't need a RenderWidget for it then).
1461 // However for now (https://crbug.com/419087) we know it exists and grab
1462 // state off it for the popup.
1463 // TODO(crbug.com/419087): This should probably be using the local root's
1464 // RenderWidget for the frame making the popup.
1465 RenderWidget* view_render_widget = GetWidget();
1466
1467 auto popup_widget = base::MakeRefCounted<RenderWidget>(
1468 widget_routing_id, view_render_widget->compositor_deps(),
1469 WidgetType::kPopup, view_render_widget->screen_info(),
1470 blink::kWebDisplayModeUndefined,
1471 /*swapped_out=*/false,
1472 /*hidden=*/false,
1473 /*never_visible=*/false, std::move(widget_channel_request));
1474
1475 // The returned WebPagePopup is self-referencing, so the pointer here is not
1476 // an owning pointer.
1477 blink::WebPagePopup* popup_web_widget =
1478 blink::WebPagePopup::Create(popup_widget.get());
1479
1480 // Adds a self-reference on the |popup_widget| so it will not be destroyed
1481 // when leaving scope. The WebPagePopup takes responsibility for Close()ing
1482 // and thus destroying the RenderWidget.
1483 popup_widget->InitForPopup(std::move(opener_callback), popup_web_widget);
1484 // TODO(crbug.com/419087): RenderWidget has some weird logic for picking a
1485 // WebWidget which doesn't apply to this case. So we verify. This can go away
1486 // when RenderWidget::GetWebWidget() is just a simple accessor.
1487 DCHECK_EQ(popup_widget->GetWebWidget(), popup_web_widget);
1488
1489 // Devtools emulation, which may be currently applied to the
1490 // |view_render_widget|, should also apply to the new popup. This doesn't
1491 // happen automatically.
1492 popup_widget->ApplyEmulatedScreenMetricsForPopupWidget(view_render_widget);
1493
1494 return popup_web_widget;
[email protected]48c9cf2d2009-09-16 16:47:521495}
1496
Daniel Murphy31bbb8b12018-02-07 21:44:101497base::StringPiece RenderViewImpl::GetSessionStorageNamespaceId() {
1498 CHECK(!session_storage_namespace_id_.empty());
Daniel Murphy0ce6e2c2017-11-21 01:54:261499 return session_storage_namespace_id_;
[email protected]bd92c3a2010-01-13 05:02:341500}
1501
Blink Reformat1c4d759e2017-04-09 16:34:541502void RenderViewImpl::PrintPage(WebLocalFrame* frame) {
naskoe440d8c2016-10-12 23:07:561503 UMA_HISTOGRAM_BOOLEAN("PrintPreview.InitiatedByScript",
Blink Reformat1c4d759e2017-04-09 16:34:541504 frame->Top() == frame);
naskoe440d8c2016-10-12 23:07:561505
1506 // Logging whether the top frame is remote is sufficient in this case. If
1507 // the top frame is local, the printing code will function correctly and
1508 // the frame itself will be printed, so the cases this histogram tracks is
1509 // where printing of a subframe will fail as of now.
1510 UMA_HISTOGRAM_BOOLEAN("PrintPreview.OutOfProcessSubframe",
Blink Reformat1c4d759e2017-04-09 16:34:541511 frame->Top()->IsWebRemoteFrame());
naskoe440d8c2016-10-12 23:07:561512
thestigcb959ce2016-11-17 05:56:321513 RenderFrameImpl::FromWebFrame(frame)->ScriptedPrint(
danakj53802692018-07-25 21:46:441514 GetWidget()->input_handler().handling_input_event());
[email protected]48c9cf2d2009-09-16 16:47:521515}
1516
lfgcaab5142016-02-26 19:06:521517void RenderViewImpl::AttachWebFrameWidget(blink::WebFrameWidget* frame_widget) {
dcheng3ce04b62015-10-26 23:30:551518 // The previous WebFrameWidget must already be detached by CloseForFrame().
1519 DCHECK(!frame_widget_);
1520 frame_widget_ = frame_widget;
1521}
1522
danakj8f4465b2018-11-07 20:11:281523void RenderViewImpl::DetachWebFrameWidget() {
1524 DCHECK(frame_widget_);
danakj8f4465b2018-11-07 20:11:281525 frame_widget_->Close();
1526 frame_widget_ = nullptr;
1527}
1528
tommycli8aad3ba2015-08-12 17:57:591529void RenderViewImpl::SetZoomLevel(double zoom_level) {
wjmaclean64951902016-04-29 20:59:121530 // If we change the zoom level for the view, make sure any subsequent subframe
1531 // loads reflect the current zoom level.
1532 page_zoom_level_ = zoom_level;
1533
Blink Reformat1c4d759e2017-04-09 16:34:541534 webview()->SetZoomLevel(zoom_level);
ericwilligers88e69742016-10-17 19:29:551535 for (auto& observer : observers_)
1536 observer.OnZoomLevelChanged();
tommycli8aad3ba2015-08-12 17:57:591537}
1538
habib.virji597255e2014-09-09 00:30:181539void RenderViewImpl::SetValidationMessageDirection(
1540 base::string16* wrapped_main_text,
1541 blink::WebTextDirection main_text_hint,
1542 base::string16* wrapped_sub_text,
1543 blink::WebTextDirection sub_text_hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541544 if (main_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181545 *wrapped_main_text =
1546 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
Blink Reformat1c4d759e2017-04-09 16:34:541547 } else if (main_text_hint == blink::kWebTextDirectionRightToLeft &&
habib.virji597255e2014-09-09 00:30:181548 !base::i18n::IsRTL()) {
1549 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
1550 }
1551
1552 if (!wrapped_sub_text->empty()) {
Blink Reformat1c4d759e2017-04-09 16:34:541553 if (sub_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181554 *wrapped_sub_text =
1555 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
Blink Reformat1c4d759e2017-04-09 16:34:541556 } else if (sub_text_hint == blink::kWebTextDirectionRightToLeft) {
habib.virji597255e2014-09-09 00:30:181557 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
1558 }
1559 }
1560}
1561
[email protected]310ebd6302011-10-10 19:06:281562void RenderViewImpl::UpdateTargetURL(const GURL& url,
1563 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581564 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521565 if (latest_url == target_url_)
1566 return;
[email protected]163f8242009-10-30 20:19:551567
[email protected]48c9cf2d2009-09-16 16:47:521568 // Tell the browser to display a destination link.
1569 if (target_url_status_ == TARGET_INFLIGHT ||
1570 target_url_status_ == TARGET_PENDING) {
1571 // If we have a request in-flight, save the URL to be sent when we
1572 // receive an ACK to the in-flight request. We can happily overwrite
1573 // any existing pending sends.
1574 pending_target_url_ = latest_url;
1575 target_url_status_ = TARGET_PENDING;
1576 } else {
mnaganovbf087422015-12-16 05:10:031577 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411578 // see |ParamTraits<GURL>|.
markdittmer67b71ea2016-03-03 22:40:031579 if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:411580 latest_url = GURL();
avia3dca182016-03-19 01:09:521581 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), latest_url));
[email protected]48c9cf2d2009-09-16 16:47:521582 target_url_ = latest_url;
1583 target_url_status_ = TARGET_INFLIGHT;
1584 }
1585}
1586
creis69b184a472015-11-26 05:29:511587void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) {
creisce0ef3572017-01-26 17:53:081588 // Keep track of which frames have pending updates.
1589 frames_with_pending_state_.insert(frame->GetRoutingID());
creis8eb8ef22015-11-04 22:51:381590
[email protected]882daa92009-11-05 16:31:311591 int delay;
avif937e1d2014-11-02 18:13:071592 if (send_content_state_immediately_)
[email protected]882daa92009-11-05 16:31:311593 delay = 0;
1594 else if (is_hidden())
avif937e1d2014-11-02 18:13:071595 delay = kDelaySecondsForContentStateSyncHidden;
[email protected]882daa92009-11-05 16:31:311596 else
avif937e1d2014-11-02 18:13:071597 delay = kDelaySecondsForContentStateSync;
[email protected]882daa92009-11-05 16:31:311598
avif937e1d2014-11-02 18:13:071599 if (nav_state_sync_timer_.IsRunning()) {
[email protected]882daa92009-11-05 16:31:311600 // The timer is already running. If the delay of the timer maches the amount
1601 // we want to delay by, then return. Otherwise stop the timer so that it
1602 // gets started with the right delay.
avif937e1d2014-11-02 18:13:071603 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
[email protected]882daa92009-11-05 16:31:311604 return;
avif937e1d2014-11-02 18:13:071605 nav_state_sync_timer_.Stop();
[email protected]882daa92009-11-05 16:31:311606 }
1607
creisce0ef3572017-01-26 17:53:081608 // Tell each frame with pending state to inform the browser.
1609 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
1610 &RenderViewImpl::SendFrameStateUpdates);
[email protected]882daa92009-11-05 16:31:311611}
1612
Blink Reformat1c4d759e2017-04-09 16:34:541613void RenderViewImpl::SetMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551614 mouse_over_url_ = GURL(url);
1615 UpdateTargetURL(mouse_over_url_, focus_url_);
1616}
1617
Blink Reformat1c4d759e2017-04-09 16:34:541618void RenderViewImpl::SetKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551619 focus_url_ = GURL(url);
1620 UpdateTargetURL(focus_url_, mouse_over_url_);
1621}
1622
Blink Reformat1c4d759e2017-04-09 16:34:541623bool RenderViewImpl::AcceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451624 return renderer_preferences_.can_accept_load_drops;
1625}
1626
Blink Reformat1c4d759e2017-04-09 16:34:541627void RenderViewImpl::FocusNext() {
avia3dca182016-03-19 01:09:521628 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false));
[email protected]48c9cf2d2009-09-16 16:47:521629}
1630
Blink Reformat1c4d759e2017-04-09 16:34:541631void RenderViewImpl::FocusPrevious() {
avia3dca182016-03-19 01:09:521632 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true));
[email protected]48c9cf2d2009-09-16 16:47:521633}
1634
esprehn3d4471a2015-09-17 07:13:201635// TODO(esprehn): Blink only ever passes Elements, this should take WebElement.
Blink Reformat1c4d759e2017-04-09 16:34:541636void RenderViewImpl::FocusedNodeChanged(const WebNode& fromNode,
estade31c54342015-01-23 03:34:361637 const WebNode& toNode) {
estade31c54342015-01-23 03:34:361638 RenderFrameImpl* previous_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541639 if (!fromNode.IsNull())
1640 previous_frame =
1641 RenderFrameImpl::FromWebFrame(fromNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361642 RenderFrameImpl* new_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541643 if (!toNode.IsNull())
1644 new_frame = RenderFrameImpl::FromWebFrame(toNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361645
1646 if (previous_frame && previous_frame != new_frame)
1647 previous_frame->FocusedNodeChanged(WebNode());
1648 if (new_frame)
1649 new_frame->FocusedNodeChanged(toNode);
1650
1651 // TODO(dmazzoni): remove once there's a separate a11y tree per frame.
naskoe8d115752015-08-07 00:43:131652 if (main_render_frame_)
1653 main_render_frame_->FocusedNodeChangedForAccessibility(toNode);
[email protected]08e9e132010-06-01 16:58:491654}
1655
Philip Rogers079658812018-08-01 23:19:091656void RenderViewImpl::DidUpdateMainFrameLayout() {
ericwilligers88e69742016-10-17 19:29:551657 for (auto& observer : observers_)
Philip Rogers079658812018-08-01 23:19:091658 observer.DidUpdateMainFrameLayout();
[email protected]d01b2a62013-09-18 23:21:331659
Philip Rogers33cd2bcc2018-08-13 21:29:291660 // The main frame may have changed size.
1661 needs_preferred_size_update_ = true;
[email protected]169d4282011-11-30 19:33:591662}
1663
Arthur Sonzognia7d715a2018-09-20 16:11:131664void RenderViewImpl::NavigateBackForwardSoon(int offset,
1665 bool has_user_gesture) {
Alex Clarkebf3dceb2017-11-24 12:27:431666 history_navigation_virtual_time_pauser_ =
1667 RenderThreadImpl::current()
Yuta Kitamura3331f5c2018-04-05 11:12:251668 ->GetWebMainThreadScheduler()
Alex Clarkeb28db542018-02-07 12:53:131669 ->CreateWebScopedVirtualTimePauser(
Alex Clarkeaaf006b2018-04-05 18:35:241670 "NavigateBackForwardSoon",
Alex Clarkeb28db542018-02-07 12:53:131671 blink::WebScopedVirtualTimePauser::VirtualTaskDuration::kInstant);
Alex Clarkeaaf006b2018-04-05 18:35:241672 history_navigation_virtual_time_pauser_.PauseVirtualTime();
Arthur Sonzognia7d715a2018-09-20 16:11:131673 Send(new ViewHostMsg_GoToEntryAtOffset(GetRoutingID(), offset,
1674 has_user_gesture));
[email protected]48c9cf2d2009-09-16 16:47:521675}
1676
Alex Clarkebf3dceb2017-11-24 12:27:431677void RenderViewImpl::DidCommitProvisionalHistoryLoad() {
Alex Clarkeaaf006b2018-04-05 18:35:241678 history_navigation_virtual_time_pauser_.UnpauseVirtualTime();
Alex Clarkebf3dceb2017-11-24 12:27:431679}
1680
Makoto Shimazuc3c730e2018-08-15 09:51:111681void RenderViewImpl::RegisterRendererPreferenceWatcherForWorker(
1682 mojom::RendererPreferenceWatcherPtr watcher) {
1683 renderer_preference_watchers_.AddPtr(std::move(watcher));
1684}
1685
Blink Reformat1c4d759e2017-04-09 16:34:541686int RenderViewImpl::HistoryBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001687 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521688}
1689
Blink Reformat1c4d759e2017-04-09 16:34:541690int RenderViewImpl::HistoryForwardListCount() {
1691 return history_list_length_ - HistoryBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521692}
1693
[email protected]180ef242013-11-07 06:50:461694// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:511695
Blink Reformat1c4d759e2017-04-09 16:34:541696bool RenderViewImpl::CanHandleGestureEvent() {
slangley1a6375e62017-03-29 06:03:231697 return true;
1698}
1699
Blink Reformat1c4d759e2017-04-09 16:34:541700bool RenderViewImpl::CanUpdateLayout() {
slangley1a6375e62017-03-29 06:03:231701 return true;
1702}
1703
Blink Reformat1c4d759e2017-04-09 16:34:541704blink::WebWidgetClient* RenderViewImpl::WidgetClient() {
danakj9a8a9cf2018-07-17 23:52:121705 return this;
lfg0f440622016-07-20 04:27:141706}
1707
Mustaq Ahmed55944cb2018-05-25 20:44:271708// blink::WebLocalFrameClient
1709// -----------------------------------------------------
[email protected]3d9689372009-09-10 04:29:171710
[email protected]b2324b092012-11-01 10:34:111711void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
1712 const std::string& value) {
alexmos56567492016-09-13 00:52:461713 GetWidget()->SetEditCommandForNextKeyEvent(name, value);
[email protected]b2324b092012-11-01 10:34:111714}
1715
1716void RenderViewImpl::ClearEditCommands() {
alexmos56567492016-09-13 00:52:461717 GetWidget()->ClearEditCommands();
[email protected]b2324b092012-11-01 10:34:111718}
1719
[email protected]b38806a2013-10-04 16:01:381720const std::string& RenderViewImpl::GetAcceptLanguages() const {
1721 return renderer_preferences_.accept_languages;
1722}
1723
Ahmed Fakhry58e6ef542018-09-04 18:05:381724void RenderViewImpl::UpdateBrowserControlsState(
1725 BrowserControlsState constraints,
1726 BrowserControlsState current,
1727 bool animate) {
David Bokan3746d2c2018-10-29 20:21:351728 TRACE_EVENT2("renderer", "RenderViewImpl::UpdateBrowserControlsState",
1729 "Constraint", static_cast<int>(constraints), "Current",
1730 static_cast<int>(current));
1731 TRACE_EVENT_INSTANT1("renderer", "is_animated", TRACE_EVENT_SCOPE_THREAD,
1732 "animated", animate);
1733
David Bokan1e37ebf2018-10-16 13:53:371734 if (GetWidget() && GetWidget()->layer_tree_view()) {
1735 GetWidget()->layer_tree_view()->UpdateBrowserControlsState(
1736 ContentToCc(constraints), ContentToCc(current), animate);
Ahmed Fakhry58e6ef542018-09-04 18:05:381737 }
1738
1739 top_controls_constraints_ = constraints;
1740}
1741
David Bokan1e37ebf2018-10-16 13:53:371742#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
1743
Ahmed Fakhry58e6ef542018-09-04 18:05:381744void RenderViewImpl::didScrollWithKeyboard(const blink::WebSize& delta) {
1745 if (delta.height == 0)
1746 return;
1747
1748 BrowserControlsState current = delta.height < 0
1749 ? BROWSER_CONTROLS_STATE_SHOWN
1750 : BROWSER_CONTROLS_STATE_HIDDEN;
1751
1752 UpdateBrowserControlsState(top_controls_constraints_, current, true);
1753}
1754
1755#endif
1756
danakjdea2efb2016-03-10 19:13:171757void RenderViewImpl::ConvertViewportToWindowViaWidget(blink::WebRect* rect) {
danakj9a8a9cf2018-07-17 23:52:121758 WidgetClient()->ConvertViewportToWindow(rect);
oshimae2b3b402015-12-04 04:27:241759}
1760
huangs2a342352015-12-15 16:59:241761gfx::RectF RenderViewImpl::ElementBoundsInWindow(
1762 const blink::WebElement& element) {
Blink Reformat1c4d759e2017-04-09 16:34:541763 blink::WebRect bounding_box_in_window = element.BoundsInViewport();
danakj9a8a9cf2018-07-17 23:52:121764 WidgetClient()->ConvertViewportToWindow(&bounding_box_in_window);
huangs2a342352015-12-15 16:59:241765 return gfx::RectF(bounding_box_in_window);
1766}
1767
Philip Rogers601fd072018-08-07 22:58:221768void RenderViewImpl::UpdatePreferredSize() {
[email protected]d812fd12011-05-27 23:05:071769 // We don't always want to send the change messages over IPC, only if we've
1770 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1771 // message.
1772 if (!send_preferred_size_changes_ || !webview())
1773 return;
Philip Rogers33cd2bcc2018-08-13 21:29:291774
1775 if (!needs_preferred_size_update_)
1776 return;
1777 needs_preferred_size_update_ = false;
1778
oshima1a688b5c2017-06-16 19:00:131779 blink::WebSize tmp_size = webview()->ContentsPreferredMinimumSize();
1780 blink::WebRect tmp_rect(0, 0, tmp_size.width, tmp_size.height);
danakj9a8a9cf2018-07-17 23:52:121781 WidgetClient()->ConvertViewportToWindow(&tmp_rect);
oshima1a688b5c2017-06-16 19:00:131782 gfx::Size size(tmp_rect.width, tmp_rect.height);
[email protected]705243f2010-05-05 19:58:071783 if (size == preferred_size_)
1784 return;
[email protected]c27324b2009-11-19 22:44:291785
[email protected]705243f2010-05-05 19:58:071786 preferred_size_ = size;
avia3dca182016-03-19 01:09:521787 Send(new ViewHostMsg_DidContentsPreferredSizeChange(GetRoutingID(),
[email protected]705243f2010-05-05 19:58:071788 preferred_size_));
[email protected]3d9689372009-09-10 04:29:171789}
1790
Blink Reformat1c4d759e2017-04-09 16:34:541791blink::WebString RenderViewImpl::AcceptLanguages() {
1792 return WebString::FromUTF8(renderer_preferences_.accept_languages);
[email protected]9982c802013-06-12 15:22:061793}
1794
[email protected]e9ff79c2012-10-19 21:31:261795// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:311796
[email protected]310ebd6302011-10-10 19:06:281797bool RenderViewImpl::Send(IPC::Message* message) {
danakja2c9d0a92018-07-25 20:01:181798 // This method is an override of IPC::Sender, but RenderWidget also has an
1799 // override of IPC::Sender, so this method also overrides RenderWidget. Thus
1800 // we must call to the base class, not via an upcast or virtual dispatch would
1801 // go back here.
[email protected]a2ef54c2011-10-10 16:20:311802 return RenderWidget::Send(message);
1803}
1804
Peter Kastinga4a3ed12018-01-31 04:07:591805RenderWidget* RenderViewImpl::GetWidget() {
1806 return this;
avi8a45c1092016-03-01 16:12:341807}
1808
mostynbc33353232014-09-12 09:38:311809RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() {
nasko77de2312015-05-12 03:09:161810 return main_render_frame_;
[email protected]b849847b2013-12-10 21:57:581811}
1812
[email protected]82114f52012-03-20 22:53:411813int RenderViewImpl::GetRoutingID() const {
Albert J. Wongcb004632018-07-10 22:58:251814 return routing_id_;
[email protected]a2ef54c2011-10-10 16:20:311815}
1816
[email protected]82114f52012-03-20 22:53:411817gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:311818 return size();
1819}
1820
oshima129b75e2016-01-14 09:15:141821float RenderViewImpl::GetDeviceScaleFactor() const {
Fady Samuela863f152018-03-09 16:10:031822 return GetWebScreenInfo().device_scale_factor;
oshima129b75e2016-01-14 09:15:141823}
1824
Marc Treib06d66032017-10-19 08:43:201825float RenderViewImpl::GetZoomLevel() const {
1826 return page_zoom_level_;
1827}
1828
thestig8a8fdfd32017-05-06 18:46:541829const WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:311830 return webkit_preferences_;
1831}
1832
[email protected]324825d2012-11-30 12:37:151833void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
1834 OnUpdateWebPreferences(preferences);
1835}
1836
[email protected]180ef242013-11-07 06:50:461837blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:311838 return webview();
1839}
1840
lfgcaab5142016-02-26 19:06:521841blink::WebFrameWidget* RenderViewImpl::GetWebFrameWidget() {
1842 return frame_widget_;
1843}
1844
avif937e1d2014-11-02 18:13:071845bool RenderViewImpl::GetContentStateImmediately() const {
1846 return send_content_state_immediately_;
[email protected]a2ef54c2011-10-10 16:20:311847}
1848
mcnee432e47d2015-11-09 19:37:461849void RenderViewImpl::OnSetPageScale(float page_scale_factor) {
ccameronb7c1d6c2015-03-09 17:08:241850 if (!webview())
1851 return;
Blink Reformat1c4d759e2017-04-09 16:34:541852 webview()->SetPageScaleFactor(page_scale_factor);
ccameronb7c1d6c2015-03-09 17:08:241853}
1854
akaba3483d8f2018-07-10 21:43:091855void RenderViewImpl::UpdateZoomLevel(double zoom_level) {
Blink Reformat1c4d759e2017-04-09 16:34:541856 webview()->HidePopups();
wjmaclean64951902016-04-29 20:59:121857 SetZoomLevel(zoom_level);
[email protected]d42bf472014-06-14 01:49:381858}
1859
danakj1b35e9d2018-11-07 19:09:281860void RenderViewImpl::ApplyPageVisibility(
1861 blink::mojom::PageVisibilityState visibility_state,
1862 bool initial_setting) {
danakj1b35e9d2018-11-07 19:09:281863 webview()->SetVisibilityState(visibility_state, initial_setting);
1864 // Note: RenderWidget visibility is controlled independently by the browser,
1865 // so there's no need to set visibility on the main frame's RenderWidget (or
1866 // any other RenderWidget) here.
1867}
1868
[email protected]310ebd6302011-10-10 19:06:281869void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:591870 webkit_preferences_ = prefs;
danakjfd0c7f42018-10-12 18:01:081871 ApplyWebPreferences(webkit_preferences_, webview());
initial.commit09911bf2008-07-26 23:55:291872}
1873
[email protected]2bf834f2011-11-17 20:02:211874void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:241875 if (send_preferred_size_changes_)
1876 return;
[email protected]9fb325e2010-05-06 18:23:241877 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:391878
Philip Rogers601fd072018-08-07 22:58:221879 if (!webview())
1880 return;
1881
Philip Rogers33cd2bcc2018-08-13 21:29:291882 needs_preferred_size_update_ = true;
1883
Philip Rogers601fd072018-08-07 22:58:221884 // We need to ensure |UpdatePreferredSize| gets called. If a layout is needed,
1885 // force an update here which will call |DidUpdateMainFrameLayout|.
danakj763c2402018-11-09 02:46:221886 webview()->MainFrameWidget()->UpdateLifecycle(
1887 WebWidget::LifecycleUpdate::kLayout);
Philip Rogers601fd072018-08-07 22:58:221888
1889 // If a layout was not needed, |DidUpdateMainFrameLayout| will not be called.
1890 // We explicitly update the preferred size here to ensure the preferred size
1891 // notification is sent.
1892 UpdatePreferredSize();
[email protected]0666aef2009-05-13 19:48:081893}
1894
[email protected]310ebd6302011-10-10 19:06:281895void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:261896 const RendererPreferences& renderer_prefs) {
[email protected]ebd5ea52014-05-28 14:51:151897 std::string old_accept_languages = renderer_preferences_.accept_languages;
1898
[email protected]80d96fa2009-06-10 22:34:511899 renderer_preferences_ = renderer_prefs;
ananta59b9fe72015-04-07 01:33:261900
Makoto Shimazuc3c730e2018-08-15 09:51:111901 renderer_preference_watchers_.ForAllPtrs(
1902 [&renderer_prefs](mojom::RendererPreferenceWatcher* watcher) {
1903 watcher->NotifyUpdate(renderer_prefs);
1904 });
1905
[email protected]6e282c92009-07-24 01:19:371906 UpdateFontRenderingFromRendererPrefs();
scottmgb92365e2016-08-30 20:54:401907 UpdateThemePrefs();
Blink Reformat1c4d759e2017-04-09 16:34:541908 blink::SetCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]38a85712013-01-02 22:45:021909
brettw8a274fa2016-11-15 00:20:401910#if BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]1596efb2013-01-17 22:13:011911 if (renderer_prefs.use_custom_colors) {
Blink Reformat1c4d759e2017-04-09 16:34:541912 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
[email protected]1596efb2013-01-17 22:13:011913
1914 if (webview()) {
Blink Reformat1c4d759e2017-04-09 16:34:541915 webview()->SetSelectionColors(renderer_prefs.active_selection_bg_color,
1916 renderer_prefs.active_selection_fg_color,
1917 renderer_prefs.inactive_selection_bg_color,
1918 renderer_prefs.inactive_selection_fg_color);
danakj763c2402018-11-09 02:46:221919 webview()->MainFrameWidget()->ThemeChanged();
[email protected]1596efb2013-01-17 22:13:011920 }
[email protected]644d77e2010-01-27 01:03:101921 }
brettw8a274fa2016-11-15 00:20:401922#endif // BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]d299d972012-03-23 02:26:551923
[email protected]ebd5ea52014-05-28 14:51:151924 if (webview() &&
1925 old_accept_languages != renderer_preferences_.accept_languages) {
Blink Reformat1c4d759e2017-04-09 16:34:541926 webview()->AcceptLanguagesChanged();
[email protected]ebd5ea52014-05-28 14:51:151927 }
[email protected]80d96fa2009-06-10 22:34:511928}
1929
[email protected]81375e872012-01-11 21:40:361930void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
1931 const WebPluginAction& action) {
1932 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:541933 webview()->PerformPluginAction(action, location);
[email protected]81375e872012-01-11 21:40:361934}
1935
[email protected]310ebd6302011-10-10 19:06:281936void RenderViewImpl::OnClosePage() {
lukasza5d0dee42017-06-14 21:57:371937 // ViewMsg_ClosePage should only be sent to active, non-swapped-out views.
1938 DCHECK(webview()->MainFrame()->IsWebLocalFrame());
1939
initial.commit09911bf2008-07-26 23:55:291940 // TODO(creis): We'd rather use webview()->Close() here, but that currently
1941 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
1942 // in the onunload handler from appearing. For now, we're bypassing that and
1943 // calling the FrameLoader's CloseURL method directly. This should be
1944 // revisited to avoid having two ways to close a page. Having a single way
1945 // to close that can run onunload is also useful for fixing
1946 // http://b/issue?id=753080.
lukasza5d0dee42017-06-14 21:57:371947 webview()->MainFrame()->ToWebLocalFrame()->DispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:291948
avia3dca182016-03-19 01:09:521949 Send(new ViewHostMsg_ClosePage_ACK(GetRoutingID()));
initial.commit09911bf2008-07-26 23:55:291950}
1951
[email protected]310ebd6302011-10-10 19:06:281952void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:001953 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:541954 webview()->HidePopups();
[email protected]30f75e62009-02-25 22:01:001955}
1956
lfg717154072016-06-30 15:04:161957void RenderViewImpl::OnPageWasHidden() {
braveyao1d8ee7b2017-03-29 21:10:041958#if defined(OS_ANDROID)
1959 SuspendVideoCaptureDevices(true);
braveyao1d8ee7b2017-03-29 21:10:041960#endif
[email protected]2d7b82c2012-06-01 05:57:501961
danakj1b35e9d2018-11-07 19:09:281962 // TODO(lfg): It's not correct to defer the page visibility to the main
1963 // frame. Currently, this is done because the main frame may override the
1964 // visibility of the page when prerendering. In order to fix this,
1965 // prerendering must be made aware of OOPIFs. https://crbug.com/440544
1966 blink::mojom::PageVisibilityState visibility_state =
1967 GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState()
1968 : blink::mojom::PageVisibilityState::kHidden;
1969 ApplyPageVisibility(visibility_state, /*initial_setting=*/false);
[email protected]941e4552010-02-01 21:23:431970}
1971
lfg717154072016-06-30 15:04:161972void RenderViewImpl::OnPageWasShown() {
braveyao1d8ee7b2017-03-29 21:10:041973#if defined(OS_ANDROID)
1974 SuspendVideoCaptureDevices(false);
[email protected]6392d982013-04-16 16:59:221975#endif
1976
danakj1b35e9d2018-11-07 19:09:281977 blink::mojom::PageVisibilityState visibility_state =
1978 GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState()
1979 : blink::mojom::PageVisibilityState::kVisible;
1980 ApplyPageVisibility(visibility_state, /*initial_setting=*/false);
[email protected]a6939ca42011-02-18 17:58:071981}
[email protected]1e6e3c992010-02-08 15:52:131982
lfg8d649cc2017-04-28 18:04:301983void RenderViewImpl::OnUpdateScreenInfo(const ScreenInfo& screen_info) {
1984 // This IPC only updates the screen info on RenderViews that have a remote
1985 // main frame. For local main frames, the ScreenInfo is updated in
1986 // ViewMsg_Resize.
danakj53802692018-07-25 21:46:441987 // TODO(danakj): Move this message to RenderWidget?
lfg8d649cc2017-04-28 18:04:301988 if (!main_render_frame_)
danakj53802692018-07-25 21:46:441989 GetWidget()->set_screen_info(screen_info);
lfg8d649cc2017-04-28 18:04:301990}
1991
Francois Doray47f759d2018-06-11 18:13:511992void RenderViewImpl::SetPageFrozen(bool frozen) {
1993 if (webview())
1994 webview()->SetPageFrozen(frozen);
Fadi Meawada6573e02018-03-10 00:52:111995}
1996
alexmos3fcd0ca2015-10-23 18:18:331997void RenderViewImpl::SetFocus(bool enable) {
danakja2c9d0a92018-07-25 20:01:181998 // This is not an IPC message, don't go through the IPC handler. This is used
1999 // in cases where the IPC message should not happen.
2000 GetWidget()->SetFocus(enable);
[email protected]b2e4c70132013-10-03 02:07:512001}
2002
Blink Reformat1c4d759e2017-04-09 16:34:542003void RenderViewImpl::ZoomLimitsChanged(double minimum_level,
[email protected]310ebd6302011-10-10 19:06:282004 double maximum_level) {
a.sarkar.arundaadc712015-02-26 05:39:082005 // Round the double to avoid returning incorrect minimum/maximum zoom
2006 // percentages.
2007 int minimum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492008 ZoomLevelToZoomFactor(minimum_level) * 100);
a.sarkar.arundaadc712015-02-26 05:39:082009 int maximum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492010 ZoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:252011
avia3dca182016-03-19 01:09:522012 Send(new ViewHostMsg_UpdateZoomLimits(GetRoutingID(), minimum_percent,
fsamuele8326c742016-01-12 00:49:392013 maximum_percent));
[email protected]b75b8292010-10-01 07:28:252014}
2015
Blink Reformat1c4d759e2017-04-09 16:34:542016void RenderViewImpl::PageScaleFactorChanged() {
ccameronb7c1d6c2015-03-09 17:08:242017 if (!webview())
2018 return;
mcnee432e47d2015-11-09 19:37:462019
avia3dca182016-03-19 01:09:522020 Send(new ViewHostMsg_PageScaleFactorChanged(GetRoutingID(),
Blink Reformat1c4d759e2017-04-09 16:34:542021 webview()->PageScaleFactor()));
W. James MacLean2a90bff2018-11-05 20:52:472022 GetWidget()->PageScaleFactorChanged(webview()->PageScaleFactor());
ccameronb7c1d6c2015-03-09 17:08:242023}
2024
[email protected]7940b8e2013-07-25 23:08:492025double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const {
2026 return ZoomLevelToZoomFactor(zoom_level);
2027}
2028
2029double RenderViewImpl::zoomFactorToZoomLevel(double factor) const {
2030 return ZoomFactorToZoomLevel(factor);
2031}
2032
Blink Reformat1c4d759e2017-04-09 16:34:542033void RenderViewImpl::PageImportanceSignalsChanged() {
kouhei40f03cb2015-09-24 07:47:012034 if (!webview() || !main_render_frame_)
2035 return;
2036
Blink Reformat1c4d759e2017-04-09 16:34:542037 auto* web_signals = webview()->PageImportanceSignals();
kouhei40f03cb2015-09-24 07:47:012038
2039 PageImportanceSignals signals;
Blink Reformat1c4d759e2017-04-09 16:34:542040 signals.had_form_interaction = web_signals->HadFormInteraction();
kouhei40f03cb2015-09-24 07:47:012041
2042 main_render_frame_->Send(new FrameHostMsg_UpdatePageImportanceSignals(
2043 main_render_frame_->GetRoutingID(), signals));
2044}
2045
danakj9a8a9cf2018-07-17 23:52:122046void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) {
danakja2c9d0a92018-07-25 20:01:182047 GetWidget()->DidAutoResize(newSize);
danakj9a8a9cf2018-07-17 23:52:122048}
2049
2050blink::WebRect RenderViewImpl::RootWindowRect() {
2051 return WidgetClient()->WindowRect();
2052}
2053
danakja2c9d0a92018-07-25 20:01:182054void RenderViewImpl::DidFocus(blink::WebLocalFrame* calling_frame) {
2055 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2056 // we won't have to test for user gesture anymore and we can
2057 // move that code back to render_widget.cc
2058 if (WebUserGestureIndicator::IsProcessingUserGesture(calling_frame) &&
2059 !RenderThreadImpl::current()->layout_test_mode()) {
2060 Send(new ViewHostMsg_Focus(GetRoutingID()));
2061
2062 // Tattle on the frame that called |window.focus()|.
2063 RenderFrameImpl* calling_render_frame =
2064 RenderFrameImpl::FromWebFrame(calling_frame);
2065 if (calling_render_frame)
2066 calling_render_frame->FrameDidCallFocus();
2067 }
2068}
2069
danakj46b3dde2018-10-18 16:12:172070blink::WebScreenInfo RenderViewImpl::GetScreenInfo() {
2071 const ScreenInfo& info = GetWidget()->screen_info();
2072
2073 blink::WebScreenInfo web_screen_info;
2074 web_screen_info.device_scale_factor = info.device_scale_factor;
2075 web_screen_info.color_space = info.color_space;
2076 web_screen_info.depth = info.depth;
2077 web_screen_info.depth_per_component = info.depth_per_component;
2078 web_screen_info.is_monochrome = info.is_monochrome;
2079 web_screen_info.rect = blink::WebRect(info.rect);
2080 web_screen_info.available_rect = blink::WebRect(info.available_rect);
2081 switch (info.orientation_type) {
2082 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
2083 web_screen_info.orientation_type =
2084 blink::kWebScreenOrientationPortraitPrimary;
2085 break;
2086 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
2087 web_screen_info.orientation_type =
2088 blink::kWebScreenOrientationPortraitSecondary;
2089 break;
2090 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
2091 web_screen_info.orientation_type =
2092 blink::kWebScreenOrientationLandscapePrimary;
2093 break;
2094 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
2095 web_screen_info.orientation_type =
2096 blink::kWebScreenOrientationLandscapeSecondary;
2097 break;
2098 default:
2099 web_screen_info.orientation_type = blink::kWebScreenOrientationUndefined;
2100 break;
2101 }
2102 web_screen_info.orientation_angle = info.orientation_angle;
2103
2104 return web_screen_info;
2105}
2106
[email protected]20657a82012-08-21 20:23:032107#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:542108bool RenderViewImpl::OpenDateTimeChooser(
[email protected]180ef242013-11-07 06:50:462109 const blink::WebDateTimeChooserParams& params,
2110 blink::WebDateTimeChooserCompletion* completion) {
[email protected]e8072562013-12-04 06:04:132111 // JavaScript may try to open a date time chooser while one is already open.
2112 if (date_time_picker_client_)
2113 return false;
[email protected]b18583c2012-12-18 06:55:272114 date_time_picker_client_.reset(
2115 new RendererDateTimePicker(this, params, completion));
2116 return date_time_picker_client_->Open();
2117}
2118
[email protected]e8072562013-12-04 06:04:132119void RenderViewImpl::DismissDateTimeDialog() {
2120 DCHECK(date_time_picker_client_);
Lei Zhang88f23ba2017-10-27 05:56:262121 date_time_picker_client_.reset();
[email protected]e8072562013-12-04 06:04:132122}
[email protected]e8072562013-12-04 06:04:132123
braveyao1d8ee7b2017-03-29 21:10:042124void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) {
2125 if (!main_render_frame_)
2126 return;
2127
Chandan Padhi26dbd9b32017-11-27 11:13:352128 MediaStreamDeviceObserver* media_stream_device_observer =
2129 main_render_frame_->GetMediaStreamDeviceObserver();
2130 if (!media_stream_device_observer)
braveyao1d8ee7b2017-03-29 21:10:042131 return;
2132
Chandan Padhi6dbfb732017-09-01 16:08:492133 MediaStreamDevices video_devices =
Chandan Padhi26dbd9b32017-11-27 11:13:352134 media_stream_device_observer->GetNonScreenCaptureDevices();
braveyao1d8ee7b2017-03-29 21:10:042135 RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices(
Chandan Padhi6dbfb732017-09-01 16:08:492136 video_devices, suspend);
braveyao1d8ee7b2017-03-29 21:10:042137}
estade6b9696bd2016-05-04 23:51:362138#endif // defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:032139
[email protected]b283d292013-02-21 08:40:342140unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
2141 return history_list_length_;
2142}
2143
[email protected]cc290f902013-03-04 20:06:022144void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
Nasko Oskova463a052018-05-08 16:42:142145 // If the main frame is remote, return immediately. Page level focus
2146 // should be set from the browser process, so if needed by tests it should
2147 // be properly supported.
2148 if (webview()->MainFrame()->IsWebRemoteFrame())
2149 return;
2150
danakja2c9d0a92018-07-25 20:01:182151 if (enable == has_focus())
2152 return;
2153
[email protected]cc290f902013-03-04 20:06:022154 if (enable) {
danakja2c9d0a92018-07-25 20:01:182155 SetActiveForWidget(true);
2156 // Fake an IPC message so go through the IPC handler.
[email protected]cc290f902013-03-04 20:06:022157 OnSetFocus(true);
2158 } else {
danakja2c9d0a92018-07-25 20:01:182159 // Fake an IPC message so go through the IPC handler.
[email protected]cc290f902013-03-04 20:06:022160 OnSetFocus(false);
danakja2c9d0a92018-07-25 20:01:182161 SetActiveForWidget(false);
[email protected]cc290f902013-03-04 20:06:022162 }
2163}
2164
[email protected]e9ff79c2012-10-19 21:31:262165} // namespace content