blob: 1e736bbe2615e4875a9defd9653b93398b6c88b5 [file] [log] [blame]
[email protected]b553edd52012-01-10 12:15:231// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]310ebd6302011-10-10 19:06:285#include "content/renderer/render_view_impl.h"
initial.commit09911bf2008-07-26 23:55:296
7#include <algorithm>
[email protected]b75b8292010-10-01 07:28:258#include <cmath>
dchengcedca5612016-04-09 01:40:159#include <memory>
lukasza5d0dee42017-06-14 21:57:3710#include <utility>
initial.commit09911bf2008-07-26 23:55:2911
[email protected]5d4e36d2013-02-15 15:18:2012#include "base/auto_reset.h"
[email protected]6e806822011-11-19 01:51:0813#include "base/bind.h"
14#include "base/bind_helpers.h"
initial.commit09911bf2008-07-26 23:55:2915#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5016#include "base/compiler_specific.h"
[email protected]2132d6b2013-06-05 00:15:4317#include "base/debug/alias.h"
avayvod232757942017-04-29 04:12:3418#include "base/feature_list.h"
[email protected]728c2ee2013-06-25 04:01:0719#include "base/files/file_path.h"
[email protected]edc3af82013-12-12 21:24:0720#include "base/i18n/rtl.h"
[email protected]b1cf3372011-04-20 21:28:1021#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4922#include "base/lazy_instance.h"
fdoray7a8954a42016-06-07 04:28:3823#include "base/location.h"
[email protected]f29efe6b2014-06-09 05:01:5124#include "base/metrics/field_trial.h"
asvitkine8d51e9d2016-09-02 23:55:4325#include "base/metrics/histogram_macros.h"
[email protected]d3b4ee22013-07-24 22:50:0626#include "base/process/kill.h"
[email protected]7d08a9352013-10-15 08:24:5627#include "base/process/process.h"
fdoray7a8954a42016-06-07 04:28:3828#include "base/single_thread_task_runner.h"
danakja4ba7e52018-11-29 23:04:3129#include "base/stl_util.h"
[email protected]21aa99682013-06-11 07:17:0130#include "base/strings/string_number_conversions.h"
[email protected]b9e7c479f2013-04-12 04:33:2431#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4932#include "base/strings/string_split.h"
[email protected]21aa99682013-06-11 07:17:0133#include "base/strings/string_util.h"
[email protected]40d11e02013-03-28 17:43:1434#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0035#include "base/strings/utf_string_conversions.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0336#include "base/system/sys_info.h"
fdoray7a8954a42016-06-07 04:28:3837#include "base/threading/thread_task_runner_handle.h"
[email protected]abb522162013-06-28 01:54:1638#include "base/time/time.h"
primiano9e38d552015-01-28 04:18:0139#include "base/trace_event/trace_event.h"
avi1023d012015-12-25 02:39:1440#include "build/build_config.h"
dongseong.hwange095dfa2016-02-04 11:21:3941#include "cc/base/switches.h"
enne98c9f8052017-03-15 19:38:2242#include "cc/paint/skia_paint_canvas.h"
danakj4c987652018-07-05 15:49:4143#include "cc/trees/layer_tree_host.h"
jinho.bang632a1a722014-09-18 03:02:5644#include "content/common/content_constants_internal.h"
[email protected]5f2aa722013-08-07 16:59:4145#include "content/common/dom_storage/dom_storage_types.h"
[email protected]59f4f2fa2011-03-23 01:00:5546#include "content/common/drag_messages.h"
[email protected]c6bc20332014-02-28 18:30:3947#include "content/common/frame_messages.h"
alexmosbc7eafa2014-12-06 01:38:0948#include "content/common/frame_replication_state.h"
[email protected]c084330e02013-04-27 01:08:1549#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0750#include "content/common/page_messages.h"
rockot5c478a72016-09-28 23:14:1851#include "content/common/render_message_filter.mojom.h"
[email protected]778574e2011-03-21 22:03:5052#include "content/common/view_messages.h"
[email protected]744c2a22012-03-15 18:42:0453#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4854#include "content/public/common/content_constants.h"
Tarun Bansal73dd2ff82017-10-03 05:29:3455#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2956#include "content/public/common/content_switches.h"
kouhei40f03cb2015-09-24 07:47:0157#include "content/public/common/page_importance_signals.h"
clamyda97e8322014-10-07 21:57:2558#include "content/public/common/page_state.h"
[email protected]7940b8e2013-07-25 23:08:4959#include "content/public/common/page_zoom.h"
Leon Han963dc182018-11-06 05:41:4860#include "content/public/common/referrer_type_converters.h"
[email protected]818915cd2012-11-20 13:14:1161#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0362#include "content/public/common/url_constants.h"
Jaebaek Seo53ab80a662018-01-29 04:50:4663#include "content/public/common/use_zoom_for_dsf_policy.h"
[email protected]b3a97b52014-07-09 06:25:0564#include "content/public/common/web_preferences.h"
[email protected]d344114c2011-10-01 01:24:3465#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0766#include "content/public/renderer/document_state.h"
Avi Drissman07d22452019-03-25 17:56:3967#include "content/public/renderer/render_thread.h"
[email protected]3a034ebb2011-10-03 19:19:4468#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3669#include "content/public/renderer/render_view_visitor.h"
scottmg8e6c6082017-02-13 23:15:4870#include "content/public/renderer/window_features_converter.h"
[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"
Sadrul Habib Chowdhury31c98712018-12-11 04:15:1373#include "content/renderer/compositor/layer_tree_view.h"
[email protected]dc293a72013-07-01 11:11:2274#include "content/renderer/drop_data_builder.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"
Guido Urdanetabd7f0962019-03-25 17:52:0281#include "content/renderer/media/video_capture/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]12a936d2013-05-15 04:55:4990#include "content/renderer/savable_resources.h"
John Abd-El-Malek312a30bb2017-10-23 19:51:5291#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:2192#include "content/renderer/web_ui_extension_data.h"
[email protected]f5961142013-04-17 23:09:4293#include "media/audio/audio_output_device.h"
[email protected]ee68378a2010-08-10 01:05:4194#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:4495#include "media/media_buildflags.h"
servolkf54f5c8f2015-02-24 20:32:3996#include "media/renderers/audio_renderer_impl.h"
Dale Curtis863022e2017-08-19 02:05:3497#include "media/video/gpu_video_accelerator_factories.h"
[email protected]d1ef81d2012-07-24 11:39:3698#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2999#include "net/base/escape.h"
100#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09101#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04102#include "net/http/http_util.h"
Tarun Bansal73d67f02018-01-17 05:56:25103#include "net/nqe/effective_connection_type.h"
Scott Violet02e38b92018-03-27 23:42:14104#include "ppapi/buildflags/buildflags.h"
lukenb171b532014-09-24 05:50:38105#include "skia/ext/platform_canvas.h"
Blink Reformata30d4232018-04-07 15:31:06106#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
Daniel Murphy95792ef2018-10-04 01:29:55107#include "third_party/blink/public/common/dom_storage/session_storage_namespace_id.h"
Mustaq Ahmed76c2f4312018-06-07 20:48:01108#include "third_party/blink/public/common/frame/user_activation_update_source.h"
Blink Reformata30d4232018-04-07 15:31:06109#include "third_party/blink/public/platform/file_path_conversion.h"
110#include "third_party/blink/public/platform/url_conversion.h"
111#include "third_party/blink/public/platform/web_connection_type.h"
112#include "third_party/blink/public/platform/web_effective_connection_type.h"
113#include "third_party/blink/public/platform/web_http_body.h"
114#include "third_party/blink/public/platform/web_image.h"
115#include "third_party/blink/public/platform/web_input_event.h"
116#include "third_party/blink/public/platform/web_input_event_result.h"
117#include "third_party/blink/public/platform/web_network_state_notifier.h"
118#include "third_party/blink/public/platform/web_point.h"
119#include "third_party/blink/public/platform/web_rect.h"
120#include "third_party/blink/public/platform/web_runtime_features.h"
121#include "third_party/blink/public/platform/web_size.h"
122#include "third_party/blink/public/platform/web_string.h"
W. James MacLean62198672019-06-04 16:46:10123#include "third_party/blink/public/platform/web_text_autosizer_page_info.h"
Blink Reformata30d4232018-04-07 15:31:06124#include "third_party/blink/public/platform/web_url.h"
125#include "third_party/blink/public/platform/web_url_error.h"
126#include "third_party/blink/public/platform/web_url_request.h"
127#include "third_party/blink/public/platform/web_url_response.h"
128#include "third_party/blink/public/platform/web_vector.h"
129#include "third_party/blink/public/public_buildflags.h"
130#include "third_party/blink/public/web/web_autofill_client.h"
131#include "third_party/blink/public/web/web_ax_object.h"
Blink Reformata30d4232018-04-07 15:31:06132#include "third_party/blink/public/web/web_document.h"
133#include "third_party/blink/public/web/web_dom_event.h"
134#include "third_party/blink/public/web/web_dom_message_event.h"
135#include "third_party/blink/public/web/web_element.h"
Blink Reformata30d4232018-04-07 15:31:06136#include "third_party/blink/public/web/web_form_control_element.h"
137#include "third_party/blink/public/web/web_form_element.h"
138#include "third_party/blink/public/web/web_frame.h"
139#include "third_party/blink/public/web/web_frame_content_dumper.h"
140#include "third_party/blink/public/web/web_frame_widget.h"
141#include "third_party/blink/public/web/web_history_item.h"
142#include "third_party/blink/public/web/web_hit_test_result.h"
143#include "third_party/blink/public/web/web_input_element.h"
144#include "third_party/blink/public/web/web_local_frame.h"
Blink Reformata30d4232018-04-07 15:31:06145#include "third_party/blink/public/web/web_navigation_policy.h"
146#include "third_party/blink/public/web/web_page_importance_signals.h"
danakj25ec6e2b2018-09-26 17:01:31147#include "third_party/blink/public/web/web_page_popup.h"
Blink Reformata30d4232018-04-07 15:31:06148#include "third_party/blink/public/web/web_plugin.h"
149#include "third_party/blink/public/web/web_plugin_action.h"
150#include "third_party/blink/public/web/web_range.h"
151#include "third_party/blink/public/web/web_render_theme.h"
152#include "third_party/blink/public/web/web_script_source.h"
153#include "third_party/blink/public/web/web_searchable_form_data.h"
154#include "third_party/blink/public/web/web_security_policy.h"
155#include "third_party/blink/public/web/web_settings.h"
156#include "third_party/blink/public/web/web_user_gesture_indicator.h"
157#include "third_party/blink/public/web/web_view.h"
158#include "third_party/blink/public/web/web_window_features.h"
[email protected]b3a97b52014-07-09 06:25:05159#include "third_party/icu/source/common/unicode/uchar.h"
160#include "third_party/icu/source/common/unicode/uscript.h"
esecklerf2bd55f72017-03-31 09:11:57161#include "third_party/skia/include/core/SkColor.h"
[email protected]1400e6dc2013-04-27 02:36:27162#include "ui/base/ui_base_switches_util.h"
tfarina655f81d2014-12-23 02:38:50163#include "ui/gfx/geometry/point.h"
tfarina3b0452d2014-12-31 15:20:09164#include "ui/gfx/geometry/rect.h"
165#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32166#include "ui/gfx/geometry/size_conversions.h"
[email protected]08397d52011-02-05 01:53:38167#include "ui/gfx/native_widget_types.h"
ccameron772317d2017-06-04 18:35:03168#include "ui/gfx/switches.h"
mfomitchev3ba450ad2017-04-03 18:20:40169#include "ui/latency/latency_info.h"
csharrisond88f9752016-10-26 23:56:36170#include "url/origin.h"
markdittmer67b71ea2016-03-03 22:40:03171#include "url/url_constants.h"
[email protected]c4a9e932011-03-05 04:05:55172#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:29173
[email protected]25fb9b32012-04-27 03:21:55174#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25175#include <cpu-features.h>
176
dalecurtiscd971252016-09-21 16:09:00177#include "base/android/build_info.h"
kylechare7d8d5c72018-01-05 19:06:28178#include "base/memory/shared_memory.h"
179#include "content/child/child_thread_impl.h"
tfarina3b0452d2014-12-31 15:20:09180#include "ui/gfx/geometry/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40181
[email protected]78043bdd2010-04-05 18:45:33182#elif defined(OS_MACOSX)
183#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57184#endif
185
brettw4b461082016-11-19 18:55:16186#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]ea2fb972013-08-07 05:44:26187#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
188#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26189#endif
190
[email protected]180ef242013-11-07 06:50:46191using blink::WebAXObject;
192using blink::WebApplicationCacheHost;
193using blink::WebApplicationCacheHostClient;
[email protected]180ef242013-11-07 06:50:46194using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46195using blink::WebData;
[email protected]180ef242013-11-07 06:50:46196using blink::WebDocument;
[email protected]180ef242013-11-07 06:50:46197using blink::WebDragOperation;
[email protected]180ef242013-11-07 06:50:46198using blink::WebElement;
[email protected]180ef242013-11-07 06:50:46199using blink::WebFormControlElement;
200using blink::WebFormElement;
201using blink::WebFrame;
dglazkov03223492016-02-08 22:16:03202using blink::WebFrameContentDumper;
[email protected]180ef242013-11-07 06:50:46203using blink::WebGestureEvent;
204using blink::WebHistoryItem;
205using blink::WebHTTPBody;
dglazkov8d0c21dd2016-08-06 15:56:36206using blink::WebHitTestResult;
[email protected]180ef242013-11-07 06:50:46207using blink::WebImage;
208using blink::WebInputElement;
209using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22210using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46211using blink::WebMouseEvent;
212using blink::WebNavigationPolicy;
213using blink::WebNavigationType;
214using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46215using blink::WebPluginAction;
[email protected]180ef242013-11-07 06:50:46216using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46217using blink::WebRect;
Daniel Chengd5e56ff2017-06-24 07:44:02218using blink::WebSandboxFlags;
[email protected]180ef242013-11-07 06:50:46219using blink::WebScriptSource;
220using blink::WebSearchableFormData;
221using blink::WebSecurityOrigin;
222using blink::WebSecurityPolicy;
[email protected]180ef242013-11-07 06:50:46223using blink::WebSettings;
224using blink::WebSize;
[email protected]180ef242013-11-07 06:50:46225using blink::WebString;
[email protected]180ef242013-11-07 06:50:46226using blink::WebTextDirection;
227using blink::WebTouchEvent;
228using blink::WebURL;
229using blink::WebURLError;
230using blink::WebURLRequest;
231using blink::WebURLResponse;
232using blink::WebUserGestureIndicator;
233using blink::WebVector;
234using blink::WebView;
235using blink::WebWidget;
236using blink::WebWindowFeatures;
[email protected]b3a97b52014-07-09 06:25:05237using blink::WebRuntimeFeatures;
[email protected]e1acf6f2008-10-27 20:43:33238
[email protected]e9ff79c2012-10-19 21:31:26239namespace content {
240
initial.commit09911bf2008-07-26 23:55:29241//-----------------------------------------------------------------------------
242
[email protected]180ef242013-11-07 06:50:46243typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
jbroman8319b232017-03-08 22:53:29244static base::LazyInstance<ViewMap>::Leaky g_view_map =
[email protected]058561b2012-12-03 06:48:22245 LAZY_INSTANCE_INITIALIZER;
scottmg5e65e3a2017-03-08 08:48:46246typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap;
jbroman8319b232017-03-08 22:53:29247static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map =
248 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02249
[email protected]882daa92009-11-05 16:31:31250// Time, in seconds, we delay before sending content state changes (such as form
251// state and scroll position) to the browser. We delay sending changes to avoid
252// spamming the browser.
253// To avoid having tab/session restore require sending a message to get the
254// current content state during tab closing we use a shorter timeout for the
255// foreground renderer. This means there is a small window of time from which
256// content state is modified and not sent to session restore, but this is
257// better than having to wake up all renderers during shutdown.
avif937e1d2014-11-02 18:13:07258const int kDelaySecondsForContentStateSyncHidden = 5;
259const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29260
dcheng35d31c112015-07-22 00:17:36261static RenderViewImpl* (*g_create_render_view_impl)(
262 CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15263 const mojom::CreateViewParams&) = nullptr;
[email protected]8d41d7612012-11-14 20:32:19264
[email protected]c6bc20332014-02-28 18:30:39265// static
[email protected]e507045d2013-07-24 15:23:44266Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56267 WebFrame* frame,
268 const WebURLRequest& request) {
Blink Reformat1c4d759e2017-04-09 16:34:54269 return Referrer(blink::WebStringToGURL(
270 request.HttpHeaderField(WebString::FromUTF8("Referer"))),
271 request.GetReferrerPolicy());
[email protected]44e55b012013-07-23 14:21:56272}
273
[email protected]c6bc20332014-02-28 18:30:39274// static
[email protected]65920f332014-03-04 21:14:18275WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32276 WebNavigationPolicy policy) {
277 switch (policy) {
Blink Reformat1c4d759e2017-04-09 16:34:54278 case blink::kWebNavigationPolicyDownload:
nick3b04f322016-08-31 19:29:19279 return WindowOpenDisposition::SAVE_TO_DISK;
Blink Reformat1c4d759e2017-04-09 16:34:54280 case blink::kWebNavigationPolicyCurrentTab:
nick3b04f322016-08-31 19:29:19281 return WindowOpenDisposition::CURRENT_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54282 case blink::kWebNavigationPolicyNewBackgroundTab:
nick3b04f322016-08-31 19:29:19283 return WindowOpenDisposition::NEW_BACKGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54284 case blink::kWebNavigationPolicyNewForegroundTab:
nick3b04f322016-08-31 19:29:19285 return WindowOpenDisposition::NEW_FOREGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54286 case blink::kWebNavigationPolicyNewWindow:
nick3b04f322016-08-31 19:29:19287 return WindowOpenDisposition::NEW_WINDOW;
Blink Reformat1c4d759e2017-04-09 16:34:54288 case blink::kWebNavigationPolicyNewPopup:
nick3b04f322016-08-31 19:29:19289 return WindowOpenDisposition::NEW_POPUP;
[email protected]48861e22013-01-09 00:27:32290 default:
291 NOTREACHED() << "Unexpected WebNavigationPolicy";
nick3b04f322016-08-31 19:29:19292 return WindowOpenDisposition::IGNORE_ACTION;
[email protected]48861e22013-01-09 00:27:32293 }
294}
295
initial.commit09911bf2008-07-26 23:55:29296///////////////////////////////////////////////////////////////////////////////
297
[email protected]217690d2012-01-27 07:33:11298namespace {
299
[email protected]b3a97b52014-07-09 06:25:05300typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
301 const base::string16&,
302 UScriptCode);
303
304void SetStandardFontFamilyWrapper(WebSettings* settings,
305 const base::string16& font,
306 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54307 settings->SetStandardFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05308}
309
310void SetFixedFontFamilyWrapper(WebSettings* settings,
311 const base::string16& font,
312 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54313 settings->SetFixedFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05314}
315
316void SetSerifFontFamilyWrapper(WebSettings* settings,
317 const base::string16& font,
318 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54319 settings->SetSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05320}
321
322void SetSansSerifFontFamilyWrapper(WebSettings* settings,
323 const base::string16& font,
324 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54325 settings->SetSansSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05326}
327
328void SetCursiveFontFamilyWrapper(WebSettings* settings,
329 const base::string16& font,
330 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54331 settings->SetCursiveFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05332}
333
334void SetFantasyFontFamilyWrapper(WebSettings* settings,
335 const base::string16& font,
336 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54337 settings->SetFantasyFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05338}
339
340void SetPictographFontFamilyWrapper(WebSettings* settings,
341 const base::string16& font,
342 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54343 settings->SetPictographFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05344}
345
346// If |scriptCode| is a member of a family of "similar" script codes, returns
347// the script code in that family that is used by WebKit for font selection
348// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
349// considered equivalent for the purposes of font selection. WebKit uses the
350// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
351// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
352// uses different scripts than the ones in Chrome pref names because the version
353// of ICU included on certain ports does not have some of the newer scripts. If
354// |scriptCode| is not a member of such a family, returns |scriptCode|.
355UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
356 switch (scriptCode) {
357 case USCRIPT_HIRAGANA:
358 case USCRIPT_KATAKANA:
359 case USCRIPT_JAPANESE:
360 return USCRIPT_KATAKANA_OR_HIRAGANA;
361 case USCRIPT_KOREAN:
362 return USCRIPT_HANGUL;
363 default:
364 return scriptCode;
365 }
366}
367
368void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
369 SetFontFamilyWrapper setter,
370 WebSettings* settings) {
jdoerrie5a73d0fa2018-10-02 23:54:05371 for (auto it = map.begin(); it != map.end(); ++it) {
avi1023d012015-12-25 02:39:14372 int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
[email protected]b3a97b52014-07-09 06:25:05373 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
374 UScriptCode code = static_cast<UScriptCode>(script);
375 (*setter)(settings, it->second, GetScriptForWebSettings(code));
376 }
377 }
378}
379
danakjefcb8432019-01-16 18:47:14380void ApplyCommandLineToSettings(WebSettings* settings) {
381 const base::CommandLine& command_line =
382 *base::CommandLine::ForCurrentProcess();
383
danakjed9464612019-01-16 00:00:59384 settings->SetThreadedScrollingEnabled(
385 !command_line.HasSwitch(switches::kDisableThreadedScrolling));
wangxianzhu3bf39be52015-04-10 23:56:41386
danakjed9464612019-01-16 00:00:59387 if (switches::IsTouchDragDropEnabled())
388 settings->SetTouchDragDropEnabled(true);
389
390 WebSettings::SelectionStrategyType selection_strategy;
391 if (command_line.GetSwitchValueASCII(switches::kTouchTextSelectionStrategy) ==
392 "direction")
393 selection_strategy = WebSettings::SelectionStrategyType::kDirection;
394 else
395 selection_strategy = WebSettings::SelectionStrategyType::kCharacter;
396 settings->SetSelectionStrategy(selection_strategy);
397
398 std::string passive_listeners_default =
399 command_line.GetSwitchValueASCII(switches::kPassiveListenersDefault);
400 if (!passive_listeners_default.empty()) {
401 WebSettings::PassiveEventListenerDefault passive_default =
402 WebSettings::PassiveEventListenerDefault::kFalse;
403 if (passive_listeners_default == "true")
404 passive_default = WebSettings::PassiveEventListenerDefault::kTrue;
405 else if (passive_listeners_default == "forcealltrue")
406 passive_default = WebSettings::PassiveEventListenerDefault::kForceAllTrue;
407 settings->SetPassiveEventListenerDefault(passive_default);
408 }
409
410 std::string network_quiet_timeout =
411 command_line.GetSwitchValueASCII(switches::kNetworkQuietTimeout);
412 if (!network_quiet_timeout.empty()) {
413 double network_quiet_timeout_seconds = 0.0;
414 if (base::StringToDouble(network_quiet_timeout,
415 &network_quiet_timeout_seconds))
416 settings->SetNetworkQuietTimeout(network_quiet_timeout_seconds);
417 }
418
419 if (command_line.HasSwitch(switches::kBlinkSettings)) {
420 std::vector<std::string> blink_settings = base::SplitString(
421 command_line.GetSwitchValueASCII(switches::kBlinkSettings), ",",
422 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
423 for (const std::string& setting : blink_settings) {
424 size_t pos = setting.find('=');
425 settings->SetFromStrings(
426 blink::WebString::FromLatin1(setting.substr(0, pos)),
427 blink::WebString::FromLatin1(
428 pos == std::string::npos ? "" : setting.substr(pos + 1)));
429 }
wangxianzhu3bf39be52015-04-10 23:56:41430 }
431}
432
scottmgde42fb92017-02-10 17:56:03433content::mojom::WindowContainerType WindowFeaturesToContainerType(
scottmg05324cb2017-02-09 23:46:04434 const blink::WebWindowFeatures& window_features) {
japhetbfc47892017-06-02 23:01:19435 if (window_features.background) {
436 if (window_features.persistent)
scottmgde42fb92017-02-10 17:56:03437 return content::mojom::WindowContainerType::PERSISTENT;
scottmg05324cb2017-02-09 23:46:04438 else
scottmgde42fb92017-02-10 17:56:03439 return content::mojom::WindowContainerType::BACKGROUND;
scottmg05324cb2017-02-09 23:46:04440 } else {
scottmgde42fb92017-02-10 17:56:03441 return content::mojom::WindowContainerType::NORMAL;
scottmg05324cb2017-02-09 23:46:04442 }
443}
444
Ahmed Fakhry58e6ef542018-09-04 18:05:38445// Check content::BrowserControlsState, and cc::BrowserControlsState
446// are kept in sync.
447static_assert(int(BROWSER_CONTROLS_STATE_SHOWN) ==
448 int(cc::BrowserControlsState::kShown),
449 "mismatching enums: SHOWN");
450static_assert(int(BROWSER_CONTROLS_STATE_HIDDEN) ==
451 int(cc::BrowserControlsState::kHidden),
452 "mismatching enums: HIDDEN");
453static_assert(int(BROWSER_CONTROLS_STATE_BOTH) ==
454 int(cc::BrowserControlsState::kBoth),
455 "mismatching enums: BOTH");
456
457cc::BrowserControlsState ContentToCc(BrowserControlsState state) {
458 return static_cast<cc::BrowserControlsState>(state);
459}
Ahmed Fakhry58e6ef542018-09-04 18:05:38460
[email protected]217690d2012-01-27 07:33:11461} // namespace
462
Hajime Hoshi315a61f2018-08-14 17:27:28463RenderViewImpl::RenderViewImpl(CompositorDependencies* compositor_deps,
464 const mojom::CreateViewParams& params)
Albert J. Wong7faa3da2019-03-21 20:43:43465 : routing_id_(params.view_id),
danakj73dd3032018-07-28 17:49:53466 renderer_wide_named_frame_lookup_(
467 params.renderer_wide_named_frame_lookup),
naskobd911332014-11-25 01:13:36468 webkit_preferences_(params.web_preferences),
changwand659e202016-06-13 02:39:12469 session_storage_namespace_id_(params.session_storage_namespace_id),
wjmaclean1d970622017-01-21 22:28:24470 weak_ptr_factory_(this) {
Daniel Murphy95792ef2018-10-04 01:29:55471 DCHECK(!session_storage_namespace_id_.empty())
472 << "Session storage namespace must be populated.";
Albert J. Wong7faa3da2019-03-21 20:43:43473 // Please put all logic in RenderViewImpl::Initialize().
474}
Albert J. Wong7bbf22d2018-12-20 00:27:27475
Albert J. Wong7faa3da2019-03-21 20:43:43476void RenderViewImpl::Initialize(
477 RenderWidget* render_widget,
478 mojom::CreateViewParamsPtr params,
479 RenderWidget::ShowCallback show_callback,
480 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Avi Drissman07d22452019-03-25 17:56:39481 DCHECK(RenderThread::IsMainThread());
482
Albert J. Wong7bbf22d2018-12-20 00:27:27483 // RenderView used to inherit from RenderWidget. Creating a delegate
484 // interface and explicitly passing ownership of ourselves to the
485 // RenderWidget preserves the lifetime semantics. This is a stepping
486 // stone to having RenderWidget creation taken out of the RenderViewImpl
487 // constructor. See the corresponding explicit reset() of the delegate
488 // in the ~RenderWidget(). Also, I hate inheritance.
Albert J. Wong7faa3da2019-03-21 20:43:43489 render_widget_ = render_widget;
Albert J. Wong7bbf22d2018-12-20 00:27:27490 GetWidget()->set_delegate(base::WrapUnique(this));
Albert J. Wongcb004632018-07-10 22:58:25491 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]075366912013-02-18 07:13:24492
nickf7b38222016-11-22 21:59:35493#if defined(OS_ANDROID)
danakjc87bfede2018-10-10 22:32:49494 bool has_show_callback = !!show_callback;
nickf7b38222016-11-22 21:59:35495#endif
[email protected]676126f72011-01-15 00:03:51496
Lukasz Anforowiczaf2f33572018-01-17 14:05:08497 WebFrame* opener_frame =
498 RenderFrameImpl::ResolveOpener(params->opener_frame_route_id);
499
danakj9a8a9cf2018-07-17 23:52:12500 // Pass WidgetClient(), not |this|, as the WebWidgetClient. The method may
Kent Tamura21d1de62018-12-10 04:45:20501 // be overridden in web tests to inject a test-only WebWidgetClient.
danakj284d557d2019-01-16 17:00:26502 webview_ = WebView::Create(this, params->hidden,
Sadrul Habib Chowdhury042a4712018-12-06 00:16:56503 /*compositing_enabled=*/true,
danakja4ba7e52018-11-29 23:04:31504 opener_frame ? opener_frame->View() : nullptr);
Albert J. Wong2727e8a82019-02-15 16:56:11505
Albert J. Wong7faa3da2019-03-21 20:43:43506 // Note: The GetWidget->Init() call causes an AddRef() to itself meaning that
507 // IPC system has taken conceptual ownership of the object. Though it is
508 // tempting to have RenderView retain the RenderWidget(), this lifecycle
509 // only requires single ownership and adding scoped_refptr<RenderWidget>
510 // muddies this unnecessarily -- especially since this RenderWidget should
511 // ultimately be own by the main frame.
Albert J. Wong7bbf22d2018-12-20 00:27:27512 GetWidget()->Init(std::move(show_callback), webview_->MainFrameWidget());
[email protected]11fee2332011-03-29 20:36:35513
nasko4c0feb62015-06-05 18:37:06514 g_view_map.Get().insert(std::make_pair(webview(), this));
avia3dca182016-03-19 01:09:52515 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this));
nasko4c0feb62015-06-05 18:37:06516
danakj505476792019-01-11 23:53:46517 webview()->SetDisplayMode(params->visual_properties.display_mode);
dcheng0ff94cfc2016-03-15 21:50:51518
danakjfd0c7f42018-10-12 18:01:08519 ApplyWebPreferences(webkit_preferences_, webview());
danakjefcb8432019-01-16 18:47:14520 ApplyCommandLineToSettings(webview()->GetSettings());
dcheng0ff94cfc2016-03-15 21:50:51521
danakjaf29226f2018-09-25 17:56:57522 // We have either a main frame or a proxy routing id.
523 DCHECK_NE(params->main_frame_routing_id != MSG_ROUTING_NONE,
524 params->proxy_routing_id != MSG_ROUTING_NONE);
525
Balazs Engedyba034e72017-10-27 22:26:28526 if (params->main_frame_routing_id != MSG_ROUTING_NONE) {
Oksana Zhuravlova8b88e572019-01-07 21:54:00527 CHECK(params->main_frame_interface_bundle);
Ken Rockot26efbd62017-11-16 04:39:49528 service_manager::mojom::InterfaceProviderPtr main_frame_interface_provider(
Oksana Zhuravlova8b88e572019-01-07 21:54:00529 std::move(params->main_frame_interface_bundle->interface_provider));
530
dcheng3ce04b62015-10-26 23:30:55531 main_render_frame_ = RenderFrameImpl::CreateMainFrame(
Balazs Engedyba034e72017-10-27 22:26:28532 this, params->main_frame_routing_id,
Ken Rockot26efbd62017-11-16 04:39:49533 std::move(main_frame_interface_provider),
Oksana Zhuravlova8b88e572019-01-07 21:54:00534 blink::mojom::DocumentInterfaceBrokerPtr(
535 std::move(params->main_frame_interface_bundle
536 ->document_interface_broker_content)),
537 blink::mojom::DocumentInterfaceBrokerPtr(
538 std::move(params->main_frame_interface_bundle
539 ->document_interface_broker_blink)),
Fady Samuela863f152018-03-09 16:10:03540 params->main_frame_widget_routing_id, params->hidden,
danakj53802692018-07-25 21:46:44541 GetWidget()->GetWebScreenInfo(), GetWidget()->compositor_deps(),
542 opener_frame, params->devtools_main_frame_token,
543 params->replicated_frame_state, params->has_committed_real_load);
danakjaf29226f2018-09-25 17:56:57544 } else {
Balazs Engedyba034e72017-10-27 22:26:28545 RenderFrameProxy::CreateFrameProxy(params->proxy_routing_id, GetRoutingID(),
nick3b5a21f2016-11-22 23:07:11546 opener_frame, MSG_ROUTING_NONE,
Dmitry Gozman89361212018-02-13 16:10:44547 params->replicated_frame_state,
548 params->devtools_main_frame_token);
danakjb08b3712019-01-16 18:59:56549 // TODO(danakj): Make WebViewImpl not need a WebWidgetClient when there is a
550 // remote main frame (when the RenderWidget is frozen).
danakj40d07932019-02-28 18:07:10551 webview_->DidAttachRemoteMainFrame(render_widget_);
nasko4c0feb62015-06-05 18:37:06552 }
553
[email protected]c7c0d822014-04-16 20:19:49554 // TODO(davidben): Move this state from Blink into content.
Balazs Engedyba034e72017-10-27 22:26:28555 if (params->window_was_created_with_opener)
Blink Reformat1c4d759e2017-04-09 16:34:54556 webview()->SetOpenedByDOM();
[email protected]c7c0d822014-04-16 20:19:49557
Albert J. Wong7bbf22d2018-12-20 00:27:27558 GetWidget()->UpdateWebViewWithDeviceScaleFactor();
Leon Han2c81b5d2019-01-25 01:58:33559 OnSetRendererPrefs(*params->renderer_preferences);
Albert J. Wong7bbf22d2018-12-20 00:27:27560 GetWidget()->OnSynchronizeVisualProperties(params->visual_properties);
[email protected]1784b2f2011-11-24 10:53:48561
[email protected]e9ff79c2012-10-19 21:31:26562 GetContentClient()->renderer()->RenderViewCreated(this);
akabac6bd1212018-06-25 20:10:48563 page_zoom_level_ = 0;
Hajime Hoshif34374412018-03-05 14:32:54564
565 nav_state_sync_timer_.SetTaskRunner(task_runner);
danakjc87bfede2018-10-10 22:32:49566
Adithya Srinivasan46b8a792019-02-01 14:47:23567 // We pass this state to Page, but it's only used by the main frame in the
568 // page.
569 if (params->inside_portal)
570 webview()->SetInsidePortal(true);
571
danakjc87bfede2018-10-10 22:32:49572#if defined(OS_ANDROID)
573 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated
574 // HandleNavigation codepath.
575 // Renderer-created RenderViews have a ShowCallback because they send a Show
576 // request (ViewHostMsg_ShowWidget, ViewHostMsg_ShowFullscreenWidget, or
577 // FrameHostMsg_ShowCreatedWindow) to the browser to attach them to the UI
578 // there. Browser-created RenderViews do not send a Show request to the
579 // browser, so have no such callback.
580 was_created_by_renderer_ = has_show_callback;
581#endif
initial.commit09911bf2008-07-26 23:55:29582}
583
[email protected]310ebd6302011-10-10 19:06:28584RenderViewImpl::~RenderViewImpl() {
dcheng3ce04b62015-10-26 23:30:55585 DCHECK(!frame_widget_);
Albert J. Wongcb004632018-07-10 22:58:25586 RenderThread::Get()->RemoveRoute(routing_id_);
dcheng3ce04b62015-10-26 23:30:55587
[email protected]60c42a8c72009-10-09 04:08:59588#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22589 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49590 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59591 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
592 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22593 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
594 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
595 it != routing_id_views->end(); ++it)
596 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59597#endif
[email protected]676126f72011-01-15 00:03:51598
ericwilligers88e69742016-10-17 19:29:55599 for (auto& observer : observers_)
600 observer.RenderViewGone();
601 for (auto& observer : observers_)
602 observer.OnDestruct();
[email protected]60c42a8c72009-10-09 04:08:59603}
604
605/*static*/
[email protected]310ebd6302011-10-10 19:06:28606RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
Avi Drissman07d22452019-03-25 17:56:39607 DCHECK(RenderThread::IsMainThread());
[email protected]a2ef54c2011-10-10 16:20:31608 ViewMap* views = g_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05609 auto it = views->find(webview);
[email protected]a2ef54c2011-10-10 16:20:31610 return it == views->end() ? NULL : it->second;
611}
612
613/*static*/
[email protected]180ef242013-11-07 06:50:46614RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28615 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31616}
617
618/*static*/
avi1023d012015-12-25 02:39:14619RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) {
Avi Drissman07d22452019-03-25 17:56:39620 DCHECK(RenderThread::IsMainThread());
[email protected]640e303c2012-12-05 01:36:07621 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05622 auto it = views->find(routing_id);
[email protected]640e303c2012-12-05 01:36:07623 return it == views->end() ? NULL : it->second;
624}
625
626/*static*/
627RenderView* RenderView::FromRoutingID(int routing_id) {
628 return RenderViewImpl::FromRoutingID(routing_id);
629}
630
[email protected]f3a95312014-06-12 16:46:58631/* static */
jochen9c7b8f242015-06-01 15:32:02632size_t RenderView::GetRenderViewCount() {
[email protected]f3a95312014-06-12 16:46:58633 return g_view_map.Get().size();
634}
635
[email protected]640e303c2012-12-05 01:36:07636/*static*/
[email protected]e9ff79c2012-10-19 21:31:26637void RenderView::ForEach(RenderViewVisitor* visitor) {
Avi Drissman07d22452019-03-25 17:56:39638 DCHECK(RenderThread::IsMainThread());
[email protected]625332e02010-12-14 07:48:49639 ViewMap* views = g_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05640 for (auto it = views->begin(); it != views->end(); ++it) {
[email protected]60c42a8c72009-10-09 04:08:59641 if (!visitor->Visit(it->second))
642 return;
643 }
644}
645
646/*static*/
[email protected]b3a97b52014-07-09 06:25:05647void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
648 WebView* web_view) {
Blink Reformat1c4d759e2017-04-09 16:34:54649 WebSettings* settings = web_view->GetSettings();
[email protected]b3a97b52014-07-09 06:25:05650 ApplyFontsFromMap(prefs.standard_font_family_map,
651 SetStandardFontFamilyWrapper, settings);
652 ApplyFontsFromMap(prefs.fixed_font_family_map,
653 SetFixedFontFamilyWrapper, settings);
654 ApplyFontsFromMap(prefs.serif_font_family_map,
655 SetSerifFontFamilyWrapper, settings);
656 ApplyFontsFromMap(prefs.sans_serif_font_family_map,
657 SetSansSerifFontFamilyWrapper, settings);
658 ApplyFontsFromMap(prefs.cursive_font_family_map,
659 SetCursiveFontFamilyWrapper, settings);
660 ApplyFontsFromMap(prefs.fantasy_font_family_map,
661 SetFantasyFontFamilyWrapper, settings);
662 ApplyFontsFromMap(prefs.pictograph_font_family_map,
663 SetPictographFontFamilyWrapper, settings);
Blink Reformat1c4d759e2017-04-09 16:34:54664 settings->SetDefaultFontSize(prefs.default_font_size);
665 settings->SetDefaultFixedFontSize(prefs.default_fixed_font_size);
666 settings->SetMinimumFontSize(prefs.minimum_font_size);
667 settings->SetMinimumLogicalFontSize(prefs.minimum_logical_font_size);
668 settings->SetDefaultTextEncodingName(
669 WebString::FromASCII(prefs.default_encoding));
670 settings->SetJavaScriptEnabled(prefs.javascript_enabled);
671 settings->SetWebSecurityEnabled(prefs.web_security_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54672 settings->SetLoadsImagesAutomatically(prefs.loads_images_automatically);
673 settings->SetImagesEnabled(prefs.images_enabled);
674 settings->SetPluginsEnabled(prefs.plugins_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54675 settings->SetDOMPasteAllowed(prefs.dom_paste_enabled);
676 settings->SetTextAreasAreResizable(prefs.text_areas_are_resizable);
677 settings->SetAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
678 settings->SetDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
679 settings->SetJavaScriptCanAccessClipboard(
[email protected]b3a97b52014-07-09 06:25:05680 prefs.javascript_can_access_clipboard);
Chris Cunninghame9b5ad742019-04-23 19:40:38681 WebRuntimeFeatures::EnableXSLT(prefs.xslt_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54682 settings->SetXSSAuditorEnabled(prefs.xss_auditor_enabled);
683 settings->SetDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
Tarun Bansal333819e2018-05-15 16:38:42684 blink::WebNetworkStateNotifier::SetSaveDataEnabled(prefs.data_saver_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54685 settings->SetLocalStorageEnabled(prefs.local_storage_enabled);
686 settings->SetSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
687 WebRuntimeFeatures::EnableDatabase(prefs.databases_enabled);
688 settings->SetOfflineWebApplicationCacheEnabled(
[email protected]b3a97b52014-07-09 06:25:05689 prefs.application_cache_enabled);
Arthur Sonzogni721f48e2018-10-31 17:10:02690 settings->SetShouldProtectAgainstIpcFlooding(
691 !prefs.disable_ipc_flooding_protection);
Blink Reformat1c4d759e2017-04-09 16:34:54692 settings->SetHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
693 settings->SetCookieEnabled(prefs.cookie_enabled);
694 settings->SetNavigateOnDragDrop(prefs.navigate_on_drag_drop);
[email protected]b3a97b52014-07-09 06:25:05695
[email protected]b3a97b52014-07-09 06:25:05696 // By default, allow_universal_access_from_file_urls is set to false and thus
697 // we mitigate attacks from local HTML files by not granting file:// URLs
698 // universal access. Only test shell will enable this.
Blink Reformat1c4d759e2017-04-09 16:34:54699 settings->SetAllowUniversalAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05700 prefs.allow_universal_access_from_file_urls);
Blink Reformat1c4d759e2017-04-09 16:34:54701 settings->SetAllowFileAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05702 prefs.allow_file_access_from_file_urls);
703
Zhenyao Moa3fda9972017-09-16 01:34:40704 settings->SetWebGL1Enabled(prefs.webgl1_enabled);
705 settings->SetWebGL2Enabled(prefs.webgl2_enabled);
[email protected]b3a97b52014-07-09 06:25:05706
[email protected]b3a97b52014-07-09 06:25:05707 // Enable WebGL errors to the JS console if requested.
Blink Reformat1c4d759e2017-04-09 16:34:54708 settings->SetWebGLErrorsToConsoleEnabled(
[email protected]b3a97b52014-07-09 06:25:05709 prefs.webgl_errors_to_console_enabled);
710
711 // Uses the mock theme engine for scrollbars.
Blink Reformat1c4d759e2017-04-09 16:34:54712 settings->SetMockScrollbarsEnabled(prefs.mock_scrollbars_enabled);
[email protected]b3a97b52014-07-09 06:25:05713
Blink Reformat1c4d759e2017-04-09 16:34:54714 settings->SetHideScrollbars(prefs.hide_scrollbars);
eseckler61ff9142016-09-23 22:57:59715
[email protected]b3a97b52014-07-09 06:25:05716 // Enable gpu-accelerated 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54717 WebRuntimeFeatures::EnableAccelerated2dCanvas(
junov524668f22016-08-08 20:16:52718 prefs.accelerated_2d_canvas_enabled);
[email protected]b3a97b52014-07-09 06:25:05719
Blink Reformat1c4d759e2017-04-09 16:34:54720 settings->SetMinimumAccelerated2dCanvasSize(
[email protected]b3a97b52014-07-09 06:25:05721 prefs.minimum_accelerated_2d_canvas_size);
722
723 // Disable antialiasing for 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54724 settings->SetAntialiased2dCanvasEnabled(
[email protected]b3a97b52014-07-09 06:25:05725 !prefs.antialiased_2d_canvas_disabled);
726
zakerinasab20ebca02016-09-27 14:22:34727 // Disable antialiasing of clips for 2d canvas if requested on the command
robertphillipse25137b2014-10-20 13:44:34728 // line.
Blink Reformat1c4d759e2017-04-09 16:34:54729 settings->SetAntialiasedClips2dCanvasEnabled(
robertphillipse25137b2014-10-20 13:44:34730 prefs.antialiased_clips_2d_canvas_enabled);
731
[email protected]b3a97b52014-07-09 06:25:05732 // Set MSAA sample count for 2d canvas if requested on the command line (or
733 // default value if not).
Blink Reformat1c4d759e2017-04-09 16:34:54734 settings->SetAccelerated2dCanvasMSAASampleCount(
[email protected]b3a97b52014-07-09 06:25:05735 prefs.accelerated_2d_canvas_msaa_sample_count);
736
[email protected]b3a97b52014-07-09 06:25:05737 // Tabs to link is not part of the settings. WebCore calls
738 // ChromeClient::tabsToLinks which is part of the glue code.
Blink Reformat1c4d759e2017-04-09 16:34:54739 web_view->SetTabsToLinks(prefs.tabs_to_links);
[email protected]b3a97b52014-07-09 06:25:05740
Blink Reformat1c4d759e2017-04-09 16:34:54741 settings->SetAllowRunningOfInsecureContent(
[email protected]b3a97b52014-07-09 06:25:05742 prefs.allow_running_insecure_content);
Blink Reformat1c4d759e2017-04-09 16:34:54743 settings->SetDisableReadingFromCanvas(prefs.disable_reading_from_canvas);
744 settings->SetStrictMixedContentChecking(prefs.strict_mixed_content_checking);
mkwst2384c8222015-07-30 07:26:47745
Blink Reformat1c4d759e2017-04-09 16:34:54746 settings->SetStrictlyBlockBlockableMixedContent(
mkwst2384c8222015-07-30 07:26:47747 prefs.strictly_block_blockable_mixed_content);
748
Blink Reformat1c4d759e2017-04-09 16:34:54749 settings->SetStrictMixedContentCheckingForPlugin(
mkwst0d233e52015-08-10 09:33:14750 prefs.block_mixed_plugin_content);
751
Blink Reformat1c4d759e2017-04-09 16:34:54752 settings->SetStrictPowerfulFeatureRestrictions(
mkwst673a452f2015-01-10 14:41:50753 prefs.strict_powerful_feature_restrictions);
Blink Reformat1c4d759e2017-04-09 16:34:54754 settings->SetAllowGeolocationOnInsecureOrigins(
jww9d4ca2d2016-01-19 20:58:59755 prefs.allow_geolocation_on_insecure_origins);
Blink Reformat1c4d759e2017-04-09 16:34:54756 settings->SetPasswordEchoEnabled(prefs.password_echo_enabled);
757 settings->SetShouldPrintBackgrounds(prefs.should_print_backgrounds);
758 settings->SetShouldClearDocumentBackground(
[email protected]b3a97b52014-07-09 06:25:05759 prefs.should_clear_document_background);
Blink Reformat1c4d759e2017-04-09 16:34:54760 settings->SetEnableScrollAnimator(prefs.enable_scroll_animator);
Stephen McGruerbc3d0e62019-01-23 17:40:19761 settings->SetPrefersReducedMotion(prefs.prefers_reduced_motion);
[email protected]b3a97b52014-07-09 06:25:05762
Blink Reformat1c4d759e2017-04-09 16:34:54763 WebRuntimeFeatures::EnableTouchEventFeatureDetection(
sunyunjiafa6a8afc2016-12-09 04:25:47764 prefs.touch_event_feature_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54765 settings->SetMaxTouchPoints(prefs.pointer_events_max_touch_points);
766 settings->SetAvailablePointerTypes(prefs.available_pointer_types);
767 settings->SetPrimaryPointerType(
nzolghadrc0d1663c2015-11-26 21:15:24768 static_cast<blink::PointerType>(prefs.primary_pointer_type));
Blink Reformat1c4d759e2017-04-09 16:34:54769 settings->SetAvailableHoverTypes(prefs.available_hover_types);
770 settings->SetPrimaryHoverType(
nzolghadrc0d1663c2015-11-26 21:15:24771 static_cast<blink::HoverType>(prefs.primary_hover_type));
Blink Reformat1c4d759e2017-04-09 16:34:54772 settings->SetEnableTouchAdjustment(prefs.touch_adjustment_enabled);
Dave Tapuskaa59fdb62017-08-23 16:28:27773 settings->SetBarrelButtonForDragEnabled(prefs.barrel_button_for_drag_enabled);
[email protected]b3a97b52014-07-09 06:25:05774
Blink Reformat1c4d759e2017-04-09 16:34:54775 settings->SetShouldRespectImageOrientation(
[email protected]b3a97b52014-07-09 06:25:05776 prefs.should_respect_image_orientation);
777
Blink Reformat1c4d759e2017-04-09 16:34:54778 settings->SetEditingBehavior(
[email protected]b3a97b52014-07-09 06:25:05779 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
780
Blink Reformat1c4d759e2017-04-09 16:34:54781 settings->SetSupportsMultipleWindows(prefs.supports_multiple_windows);
[email protected]b3a97b52014-07-09 06:25:05782
Blink Reformat1c4d759e2017-04-09 16:34:54783 settings->SetMainFrameClipsContent(!prefs.record_whole_document);
khushalsagar2da2b232016-03-23 22:11:35784
Blink Reformat1c4d759e2017-04-09 16:34:54785 settings->SetSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
[email protected]b3a97b52014-07-09 06:25:05786
Blink Reformat1c4d759e2017-04-09 16:34:54787 settings->SetSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
Hugo Holgersson943ae692019-01-10 10:04:14788 // Spatnav depends on KeyboardFocusableScrollers. The WebUI team has
789 // disabled KFS because they need more time to update their custom elements,
790 // crbug.com/907284. Meanwhile, we pre-ship KFS to spatnav users.
791 if (prefs.spatial_navigation_enabled)
792 WebRuntimeFeatures::EnableKeyboardFocusableScrollers(true);
[email protected]b3a97b52014-07-09 06:25:05793
Blink Reformat1c4d759e2017-04-09 16:34:54794 settings->SetSelectionIncludesAltImageText(true);
[email protected]b3a97b52014-07-09 06:25:05795
Blink Reformat1c4d759e2017-04-09 16:34:54796 settings->SetV8CacheOptions(
[email protected]35103c02014-08-12 15:08:47797 static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options));
798
Blink Reformat1c4d759e2017-04-09 16:34:54799 settings->SetImageAnimationPolicy(
je_julie.kim7fbb5a1a2015-02-09 17:26:05800 static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy));
801
Blink Reformat1c4d759e2017-04-09 16:34:54802 settings->SetPresentationRequiresUserGesture(
zqzhang1215ad422016-02-10 13:27:22803 prefs.user_gesture_required_for_presentation);
804
Elly Fong-Jonesf92897392019-01-24 16:05:49805 settings->SetTextTrackBackgroundColor(
806 WebString::FromASCII(prefs.text_track_background_color));
807 settings->SetTextTrackTextColor(
808 WebString::FromASCII(prefs.text_track_text_color));
Rahul Singh1862faa92019-03-06 22:41:43809 settings->SetTextTrackTextSize(
810 WebString::FromASCII(prefs.text_track_text_size));
811 settings->SetTextTrackTextShadow(
812 WebString::FromASCII(prefs.text_track_text_shadow));
813 settings->SetTextTrackFontFamily(
814 WebString::FromASCII(prefs.text_track_font_family));
815 settings->SetTextTrackFontVariant(
816 WebString::FromASCII(prefs.text_track_font_variant));
Blink Reformat1c4d759e2017-04-09 16:34:54817 settings->SetTextTrackMarginPercentage(prefs.text_track_margin_percentage);
halliwell4002be42016-03-18 18:33:40818
David Bokana03511a92018-09-13 04:25:24819 // Needs to happen before SetDefaultPageScaleLimits below since that'll
820 // recalculate the final page scale limits and that depends on this setting.
821 settings->SetShrinksViewportContentToFit(
822 prefs.shrinks_viewport_contents_to_fit);
823
824 // Needs to happen before SetIgnoreViewportTagScaleLimits below.
Blink Reformat1c4d759e2017-04-09 16:34:54825 web_view->SetDefaultPageScaleLimits(prefs.default_minimum_page_scale_factor,
826 prefs.default_maximum_page_scale_factor);
dcheng5ae8ca362015-02-05 04:03:47827
Allan Sandfeld Jensene35337092019-05-15 13:56:09828 settings->SetFullscreenSupported(prefs.fullscreen_supported);
Ahmed Fakhry42221452018-05-30 01:18:39829 settings->SetTextAutosizingEnabled(prefs.text_autosizing_enabled);
830 settings->SetDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
Tarun Bansald10f17a02018-09-13 00:23:17831 blink::WebNetworkStateNotifier::SetNetworkQualityWebHoldback(
832 static_cast<blink::WebEffectiveConnectionType>(
833 prefs.network_quality_estimator_web_holdback));
Ahmed Fakhry42221452018-05-30 01:18:39834
chaopeng7e8fb352019-03-26 03:34:49835 settings->SetDontSendKeyEventsToJavascript(
836 prefs.dont_send_key_events_to_javascript);
Mounir Lamouri6926107f2019-01-31 18:17:43837 settings->SetWebAppScope(WebString::FromASCII(prefs.web_app_scope.spec()));
838
[email protected]b3a97b52014-07-09 06:25:05839#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:54840 settings->SetAllowCustomScrollbarInMainFrame(false);
Blink Reformat1c4d759e2017-04-09 16:34:54841 settings->SetAccessibilityFontScaleFactor(prefs.font_scale_factor);
842 settings->SetDeviceScaleAdjustment(prefs.device_scale_adjustment);
Blink Reformat1c4d759e2017-04-09 16:34:54843 web_view->SetIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
844 settings->SetAutoZoomFocusedNodeToLegibleScale(true);
Blink Reformat1c4d759e2017-04-09 16:34:54845 settings->SetDefaultVideoPosterURL(
846 WebString::FromASCII(prefs.default_video_poster_url.spec()));
847 settings->SetSupportDeprecatedTargetDensityDPI(
[email protected]b3a97b52014-07-09 06:25:05848 prefs.support_deprecated_target_density_dpi);
Blink Reformat1c4d759e2017-04-09 16:34:54849 settings->SetUseLegacyBackgroundSizeShorthandBehavior(
[email protected]b3a97b52014-07-09 06:25:05850 prefs.use_legacy_background_size_shorthand_behavior);
Blink Reformat1c4d759e2017-04-09 16:34:54851 settings->SetWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
852 settings->SetUseWideViewport(prefs.use_wide_viewport);
853 settings->SetForceZeroLayoutHeight(prefs.force_zero_layout_height);
Blink Reformat1c4d759e2017-04-09 16:34:54854 settings->SetViewportMetaMergeContentQuirk(
[email protected]b3a97b52014-07-09 06:25:05855 prefs.viewport_meta_merge_content_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54856 settings->SetViewportMetaNonUserScalableQuirk(
[email protected]b3a97b52014-07-09 06:25:05857 prefs.viewport_meta_non_user_scalable_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54858 settings->SetViewportMetaZeroValuesQuirk(
[email protected]b3a97b52014-07-09 06:25:05859 prefs.viewport_meta_zero_values_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54860 settings->SetClobberUserAgentInitialScaleQuirk(
[email protected]b3a97b52014-07-09 06:25:05861 prefs.clobber_user_agent_initial_scale_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54862 settings->SetIgnoreMainFrameOverflowHiddenQuirk(
[email protected]b3a97b52014-07-09 06:25:05863 prefs.ignore_main_frame_overflow_hidden_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54864 settings->SetReportScreenSizeInPhysicalPixelsQuirk(
[email protected]b3a97b52014-07-09 06:25:05865 prefs.report_screen_size_in_physical_pixels_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54866 settings->SetShouldReuseGlobalForUnownedMainFrame(
tzik30eb52c2018-03-27 06:55:18867 prefs.reuse_global_for_unowned_main_frame);
Blink Reformat1c4d759e2017-04-09 16:34:54868 settings->SetPreferHiddenVolumeControls(true);
869 settings->SetSpellCheckEnabledByDefault(prefs.spellcheck_enabled_by_default);
dalecurtiscd971252016-09-21 16:09:00870
Blink Reformat1c4d759e2017-04-09 16:34:54871 WebRuntimeFeatures::EnableVideoFullscreenOrientationLock(
mlamouri1d266bf2016-12-05 17:42:36872 prefs.video_fullscreen_orientation_lock_enabled);
johnme913ee5f2017-04-28 21:36:16873 WebRuntimeFeatures::EnableVideoRotateToFullscreen(
874 prefs.video_rotate_to_fullscreen_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54875 WebRuntimeFeatures::EnableVideoFullscreenDetection(
zqzhang93e959d12017-03-16 13:10:20876 prefs.video_fullscreen_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54877 settings->SetEmbeddedMediaExperienceEnabled(
shaktisahuf97f7532017-02-24 22:46:13878 prefs.embedded_media_experience_enabled);
Ian Vollickeeca1d82018-02-07 02:43:42879 settings->SetImmersiveModeEnabled(prefs.immersive_mode_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54880 settings->SetDoNotUpdateSelectionOnMutatingSelectionRange(
changwane54ccdb92017-04-05 19:20:54881 prefs.do_not_update_selection_on_mutating_selection_range);
Noel Gordonf311a842017-07-27 00:10:07882 WebRuntimeFeatures::EnableCSSHexAlphaColor(prefs.css_hex_alpha_color_enabled);
Tobias Sargeant416174f2017-09-01 01:18:09883 WebRuntimeFeatures::EnableScrollTopLeftInterop(
884 prefs.scroll_top_left_interop_enabled);
zqzhangdf72ed082016-12-08 16:07:55885#endif // defined(OS_ANDROID)
liberato9e934892016-05-03 19:00:27886
Rune Lillesveenb46bb482019-04-02 07:36:29887 settings->SetForceDarkModeEnabled(prefs.force_dark_mode_enabled);
888
mlamouri55a0543c2017-05-11 10:34:07889 switch (prefs.autoplay_policy) {
890 case AutoplayPolicy::kNoUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28891 settings->SetAutoplayPolicy(
892 WebSettings::AutoplayPolicy::kNoUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07893 break;
894 case AutoplayPolicy::kUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28895 settings->SetAutoplayPolicy(
896 WebSettings::AutoplayPolicy::kUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07897 break;
mlamouri431bb4e2017-06-06 08:54:24898 case AutoplayPolicy::kDocumentUserActivationRequired:
899 settings->SetAutoplayPolicy(
900 WebSettings::AutoplayPolicy::kDocumentUserActivationRequired);
901 break;
mlamouri55a0543c2017-05-11 10:34:07902 }
903
Blink Reformat1c4d759e2017-04-09 16:34:54904 settings->SetViewportEnabled(prefs.viewport_enabled);
905 settings->SetViewportMetaEnabled(prefs.viewport_meta_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54906 settings->SetViewportStyle(
alokp5d566962016-04-19 00:54:16907 static_cast<blink::WebViewportStyle>(prefs.viewport_style));
908
Blink Reformat1c4d759e2017-04-09 16:34:54909 settings->SetLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
910 settings->SetMainFrameResizesAreOrientationChanges(
yoava1a508b42015-10-20 12:03:21911 prefs.main_frame_resizes_are_orientation_changes);
912
Blink Reformat1c4d759e2017-04-09 16:34:54913 settings->SetUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
jinho.bang8f11ffa2014-12-04 06:03:03914
Blink Reformat1c4d759e2017-04-09 16:34:54915 settings->SetShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up);
916 settings->SetAlwaysShowContextMenuOnTouch(
amaralp547e4192016-06-03 19:17:35917 prefs.always_show_context_menu_on_touch);
Sandra Sunc79fc93a2018-04-10 15:22:23918 settings->SetSmoothScrollForFindEnabled(prefs.smooth_scroll_for_find_enabled);
ccameron2fd70de72015-02-19 00:40:40919
Blink Reformat1c4d759e2017-04-09 16:34:54920 settings->SetHideDownloadUI(prefs.hide_download_ui);
qinmin72e8bd02016-10-21 19:35:37921
Blink Reformat1c4d759e2017-04-09 16:34:54922 settings->SetPresentationReceiver(prefs.presentation_receiver);
mlamouri57359d912016-11-29 20:11:50923
Blink Reformat1c4d759e2017-04-09 16:34:54924 settings->SetMediaControlsEnabled(prefs.media_controls_enabled);
mlamouri5cd9ae82017-02-18 11:05:09925
Tarun Bansal73d67f02018-01-17 05:56:25926 settings->SetLowPriorityIframesThreshold(
927 static_cast<blink::WebEffectiveConnectionType>(
928 prefs.low_priority_iframes_threshold));
929
Mounir Lamouri9c99a1602018-07-05 15:01:44930 settings->SetPictureInPictureEnabled(
931 prefs.picture_in_picture_enabled &&
[email protected]69db58f2018-09-26 20:27:56932 MediaFactory::GetVideoSurfaceLayerMode() !=
CJ DiMeglio89240472018-10-18 18:21:10933 blink::WebMediaPlayer::SurfaceLayerMode::kNever);
François Beaufort8c08979fc2018-03-05 13:06:31934
Tarun Bansal333819e2018-05-15 16:38:42935 settings->SetDataSaverHoldbackWebApi(
936 prefs.data_saver_holdback_web_api_enabled);
Tarun Bansal333819e2018-05-15 16:38:42937
rajendrante87ed712018-11-30 01:55:00938 settings->SetLazyLoadEnabled(prefs.lazy_load_enabled);
Rune Lillesveene17fb702019-03-15 07:26:14939 settings->SetPreferredColorScheme(prefs.preferred_color_scheme);
rajendrante87ed712018-11-30 01:55:00940
Scott Little878f7d6702018-05-31 22:09:06941 for (const auto& ect_distance_pair :
942 prefs.lazy_frame_loading_distance_thresholds_px) {
943 switch (ect_distance_pair.first) {
944 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
945 settings->SetLazyFrameLoadingDistanceThresholdPxUnknown(
946 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39947 continue;
Scott Little878f7d6702018-05-31 22:09:06948 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
949 settings->SetLazyFrameLoadingDistanceThresholdPxOffline(
950 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39951 continue;
Scott Little878f7d6702018-05-31 22:09:06952 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
953 settings->SetLazyFrameLoadingDistanceThresholdPxSlow2G(
954 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39955 continue;
Scott Little878f7d6702018-05-31 22:09:06956 case net::EFFECTIVE_CONNECTION_TYPE_2G:
957 settings->SetLazyFrameLoadingDistanceThresholdPx2G(
958 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39959 continue;
Scott Little878f7d6702018-05-31 22:09:06960 case net::EFFECTIVE_CONNECTION_TYPE_3G:
961 settings->SetLazyFrameLoadingDistanceThresholdPx3G(
962 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39963 continue;
Scott Little878f7d6702018-05-31 22:09:06964 case net::EFFECTIVE_CONNECTION_TYPE_4G:
965 settings->SetLazyFrameLoadingDistanceThresholdPx4G(
966 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39967 continue;
968 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
969 continue;
Scott Little878f7d6702018-05-31 22:09:06970 }
rajendrantd8026342018-08-29 08:08:39971 NOTREACHED();
972 }
973
974 for (const auto& ect_distance_pair :
975 prefs.lazy_image_loading_distance_thresholds_px) {
976 switch (ect_distance_pair.first) {
977 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
978 settings->SetLazyImageLoadingDistanceThresholdPxUnknown(
979 ect_distance_pair.second);
980 continue;
981 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
982 settings->SetLazyImageLoadingDistanceThresholdPxOffline(
983 ect_distance_pair.second);
984 continue;
985 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
986 settings->SetLazyImageLoadingDistanceThresholdPxSlow2G(
987 ect_distance_pair.second);
988 continue;
989 case net::EFFECTIVE_CONNECTION_TYPE_2G:
990 settings->SetLazyImageLoadingDistanceThresholdPx2G(
991 ect_distance_pair.second);
992 continue;
993 case net::EFFECTIVE_CONNECTION_TYPE_3G:
994 settings->SetLazyImageLoadingDistanceThresholdPx3G(
995 ect_distance_pair.second);
996 continue;
997 case net::EFFECTIVE_CONNECTION_TYPE_4G:
998 settings->SetLazyImageLoadingDistanceThresholdPx4G(
999 ect_distance_pair.second);
1000 continue;
1001 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
1002 continue;
1003 }
1004 NOTREACHED();
Scott Little878f7d6702018-05-31 22:09:061005 }
1006
ccameron2fd70de72015-02-19 00:40:401007#if defined(OS_MACOSX)
Blink Reformat1c4d759e2017-04-09 16:34:541008 web_view->SetMaximumLegibleScale(prefs.default_maximum_page_scale_factor);
ccameron2fd70de72015-02-19 00:40:401009#endif
sunyunjia87f287b2016-09-09 00:38:131010
1011#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:541012 WebRuntimeFeatures::EnableMiddleClickAutoscroll(true);
sunyunjia87f287b2016-09-09 00:38:131013#endif
Dave Tapuskac6627e12018-08-30 15:07:191014
Dave Tapuskaa38e3252018-11-13 03:01:171015 WebRuntimeFeatures::EnableTranslateService(prefs.translate_service_available);
[email protected]b3a97b52014-07-09 06:25:051016}
1017
1018/*static*/
nickf7b38222016-11-22 21:59:351019RenderViewImpl* RenderViewImpl::Create(
1020 CompositorDependencies* compositor_deps,
Balazs Engedyba034e72017-10-27 22:26:281021 mojom::CreateViewParamsPtr params,
danakjdf1ceb72018-07-18 20:02:251022 RenderWidget::ShowCallback show_callback,
Hajime Hoshiabb3c8f2017-12-04 18:41:391023 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Balazs Engedyba034e72017-10-27 22:26:281024 DCHECK(params->view_id != MSG_ROUTING_NONE);
Albert J. Wongcb004632018-07-10 22:58:251025 DCHECK(params->main_frame_widget_routing_id != MSG_ROUTING_NONE);
Lei Zhang88f23ba2017-10-27 05:56:261026 RenderViewImpl* render_view;
[email protected]0287e762014-04-11 13:07:581027
Albert J. Wong7faa3da2019-03-21 20:43:431028 auto render_widget = RenderWidget::CreateForFrame(
1029 params->main_frame_widget_routing_id, compositor_deps,
1030 params->visual_properties.screen_info,
1031 params->visual_properties.display_mode,
1032 /*is_frozen=*/params->main_frame_routing_id == MSG_ROUTING_NONE,
1033 params->hidden, params->never_visible,
1034 /*widget_request=*/nullptr);
1035
1036 if (g_create_render_view_impl) {
1037 render_view = g_create_render_view_impl(compositor_deps, *params);
1038 } else {
1039 render_view = new RenderViewImpl(compositor_deps, *params);
1040 }
1041
1042 // After this call, the |render_widget| will be self-owning.
1043 //
1044 // TODO(http://crbug.com/419087): This refcoutning is messy. get the
1045 // RenderWidget initialization out of the render_view::Initialize() function.
1046 render_view->Initialize(render_widget.get(), std::move(params),
1047 std::move(show_callback), std::move(task_runner));
[email protected]075366912013-02-18 07:13:241048 return render_view;
[email protected]8d41d7612012-11-14 20:32:191049}
1050
1051// static
dcheng35d31c112015-07-22 00:17:361052void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
1053 *create_render_view_impl)(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:151054 const mojom::CreateViewParams&)) {
[email protected]8d41d7612012-11-14 20:32:191055 CHECK(!g_create_render_view_impl);
1056 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291057}
1058
[email protected]310ebd6302011-10-10 19:06:281059void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511060 observers_.AddObserver(observer);
1061}
1062
[email protected]310ebd6302011-10-10 19:06:281063void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1064 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511065 observers_.RemoveObserver(observer);
1066}
1067
Peter Kastinga4a3ed12018-01-31 04:07:591068blink::WebView* RenderViewImpl::webview() {
1069 return webview_;
1070}
1071
1072const blink::WebView* RenderViewImpl::webview() const {
lfg4fa48da2016-05-09 18:25:131073 return webview_;
[email protected]4d51d5bf2010-07-26 18:48:261074}
1075
danakja2c9d0a92018-07-25 20:01:181076// RenderWidgetOwnerDelegate -----------------------------------------
fsamuel72464894f2015-12-15 06:59:311077
danakja2c9d0a92018-07-25 20:01:181078blink::WebWidget* RenderViewImpl::GetWebWidgetForWidget() const {
1079 return frame_widget_;
1080}
1081
1082bool RenderViewImpl::RenderWidgetWillHandleMouseEventForWidget(
avid7d6b2e2016-03-04 19:41:171083 const blink::WebMouseEvent& event) {
fsamuel72464894f2015-12-15 06:59:311084 // If the mouse is locked, only the current owner of the mouse lock can
1085 // process mouse events.
danakja2c9d0a92018-07-25 20:01:181086 return GetWidget()->mouse_lock_dispatcher()->WillHandleMouseEvent(event);
fsamuel72464894f2015-12-15 06:59:311087}
1088
danakja2c9d0a92018-07-25 20:01:181089void RenderViewImpl::SetActiveForWidget(bool active) {
Albert J. Wongcb004632018-07-10 22:58:251090 if (webview())
1091 webview()->SetIsActive(active);
1092}
1093
danakja2c9d0a92018-07-25 20:01:181094bool RenderViewImpl::SupportsMultipleWindowsForWidget() {
1095 return webkit_preferences_.supports_multiple_windows;
1096}
1097
1098void RenderViewImpl::DidHandleGestureEventForWidget(
1099 const WebGestureEvent& event) {
1100 for (auto& observer : observers_)
1101 observer.DidHandleGestureEvent(event);
1102}
1103
David Bokan11f6ef482019-03-18 17:47:271104bool RenderViewImpl::ShouldAckSyntheticInputImmediately() {
1105 // TODO(bokan): The RequestPresentation API appears not to function in VR. As
1106 // a short term workaround for https://crbug.com/940063, ACK input
1107 // immediately rather than using RequestPresentation.
1108 if (webkit_preferences_.immersive_mode_enabled)
1109 return true;
1110 return false;
1111}
1112
danakja2c9d0a92018-07-25 20:01:181113void RenderViewImpl::DidCloseWidget() {
1114 // The webview_ is already destroyed by the time we get here, remove any
1115 // references to it.
1116 g_view_map.Get().erase(webview_);
1117 webview_ = nullptr;
1118 g_routing_id_view_map.Get().erase(GetRoutingID());
Albert J. Wong2727e8a82019-02-15 16:56:111119
1120 // The |render_widget_| is deleted after DidCloseWidget() returns. Drop the
1121 // reference to it to avoid a UaF.
1122 render_widget_ = nullptr;
danakja2c9d0a92018-07-25 20:01:181123}
1124
danakj84bbf552019-01-21 21:33:311125void RenderViewImpl::CancelPagePopupForWidget() {
1126 webview()->CancelPagePopup();
danakja2c9d0a92018-07-25 20:01:181127}
1128
1129void RenderViewImpl::ApplyNewDisplayModeForWidget(
1130 const blink::WebDisplayMode& new_display_mode) {
danakj1ab8faf2018-10-12 18:24:281131 webview()->SetDisplayMode(new_display_mode);
danakja2c9d0a92018-07-25 20:01:181132}
1133
1134void RenderViewImpl::ApplyAutoResizeLimitsForWidget(const gfx::Size& min_size,
1135 const gfx::Size& max_size) {
1136 webview()->EnableAutoResizeMode(min_size, max_size);
1137}
1138
1139void RenderViewImpl::DisableAutoResizeForWidget() {
1140 webview()->DisableAutoResizeMode();
1141}
1142
1143void RenderViewImpl::ScrollFocusedNodeIntoViewForWidget() {
1144 if (WebLocalFrame* focused_frame = GetWebView()->FocusedFrame()) {
1145 auto* frame_widget = focused_frame->LocalRoot()->FrameWidget();
1146 frame_widget->ScrollFocusedEditableElementIntoView();
1147 }
1148}
1149
1150void RenderViewImpl::DidReceiveSetFocusEventForWidget() {
1151 // This message must always be received when the main frame is a
1152 // WebLocalFrame.
Albert J. Wong7bbf22d2018-12-20 00:27:271153 // TODO(ajwong): Can this be removed and just check |delegate_| in
danakja2c9d0a92018-07-25 20:01:181154 // RenderWidget instead?
1155 CHECK(webview()->MainFrame()->IsWebLocalFrame());
1156}
1157
1158void RenderViewImpl::DidChangeFocusForWidget() {
1159 // Notify all BrowserPlugins of the RenderView's focus state.
1160 if (BrowserPluginManager::Get())
1161 BrowserPluginManager::Get()->UpdateFocusState();
1162}
1163
danakja2c9d0a92018-07-25 20:01:181164void RenderViewImpl::DidCommitCompositorFrameForWidget() {
1165 for (auto& observer : observers_)
1166 observer.DidCommitCompositorFrame();
Philip Rogers33cd2bcc2018-08-13 21:29:291167 UpdatePreferredSize();
danakja2c9d0a92018-07-25 20:01:181168}
1169
1170void RenderViewImpl::DidCompletePageScaleAnimationForWidget() {
1171 if (auto* focused_frame = GetWebView()->FocusedFrame()) {
1172 if (focused_frame->AutofillClient())
1173 focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame();
1174 }
1175}
1176
1177void RenderViewImpl::ResizeWebWidgetForWidget(
1178 const gfx::Size& size,
1179 float top_controls_height,
1180 float bottom_controls_height,
1181 bool browser_controls_shrink_blink_size) {
1182 webview()->ResizeWithBrowserControls(size, top_controls_height,
1183 bottom_controls_height,
1184 browser_controls_shrink_blink_size);
1185}
1186
danakja2c9d0a92018-07-25 20:01:181187void RenderViewImpl::SetScreenMetricsEmulationParametersForWidget(
1188 bool enabled,
1189 const blink::WebDeviceEmulationParams& params) {
danakj1ab8faf2018-10-12 18:24:281190 if (enabled)
1191 webview()->EnableDeviceEmulation(params);
1192 else
1193 webview()->DisableDeviceEmulation();
danakja2c9d0a92018-07-25 20:01:181194}
1195
1196// IPC message handlers -----------------------------------------
1197
danakja2c9d0a92018-07-25 20:01:181198void RenderViewImpl::OnUpdateTargetURLAck() {
1199 // Check if there is a targeturl waiting to be sent.
1200 if (target_url_status_ == TARGET_PENDING)
1201 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), pending_target_url_));
1202
1203 target_url_status_ = TARGET_NONE;
1204}
1205
1206void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset,
1207 int history_length) {
1208 // -1 <= history_offset < history_length <= kMaxSessionHistoryEntries(50).
1209 DCHECK_LE(-1, history_offset);
1210 DCHECK_LT(history_offset, history_length);
1211 DCHECK_LE(history_length, kMaxSessionHistoryEntries);
1212
1213 history_list_offset_ = history_offset;
1214 history_list_length_ = history_length;
1215}
1216
1217void RenderViewImpl::OnSetInitialFocus(bool reverse) {
1218 if (!webview())
1219 return;
1220 webview()->SetInitialFocus(reverse);
1221}
1222
danakja2c9d0a92018-07-25 20:01:181223void RenderViewImpl::OnAudioStateChanged(bool is_audio_playing) {
1224 webview()->AudioStateChanged(is_audio_playing);
1225}
1226
danakja2c9d0a92018-07-25 20:01:181227///////////////////////////////////////////////////////////////////////////////
1228
1229void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget,
1230 WebNavigationPolicy policy,
1231 const gfx::Rect& initial_rect) {
1232 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(),
1233 initial_rect));
1234}
1235
1236void RenderViewImpl::ShowCreatedFullscreenWidget(
1237 RenderWidget* fullscreen_widget,
1238 WebNavigationPolicy policy,
1239 const gfx::Rect& initial_rect) {
1240 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(),
1241 fullscreen_widget->routing_id()));
1242}
1243
1244void RenderViewImpl::SendFrameStateUpdates() {
1245 // Tell each frame with pending state to send its UpdateState message.
1246 for (int render_frame_routing_id : frames_with_pending_state_) {
1247 RenderFrameImpl* frame =
1248 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
1249 if (frame)
1250 frame->SendUpdateState();
1251 }
1252 frames_with_pending_state_.clear();
1253}
1254
danakja2c9d0a92018-07-25 20:01:181255// IPC::Listener -------------------------------------------------------------
fsamuel72464894f2015-12-15 06:59:311256
[email protected]310ebd6302011-10-10 19:06:281257bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281258 WebFrame* main_frame = webview() ? webview()->MainFrame() : nullptr;
Avi Drissmanb5f8e242017-12-12 05:21:561259 if (main_frame) {
1260 GURL active_url;
1261 if (main_frame->IsWebLocalFrame())
1262 active_url = main_frame->ToWebLocalFrame()->GetDocument().Url();
lukaszabedb4b22017-06-23 00:00:131263 GetContentClient()->SetActiveURL(
Avi Drissmanb5f8e242017-12-12 05:21:561264 active_url, main_frame->Top()->GetSecurityOrigin().ToString().Utf8());
1265 }
[email protected]f8b6b6f2009-03-10 16:48:261266
dchenga2d442c22016-10-13 15:39:211267 for (auto& observer : observers_) {
1268 if (observer.OnMessageReceived(message))
[email protected]676126f72011-01-15 00:03:511269 return true;
dchenga2d442c22016-10-13 15:39:211270 }
[email protected]b2abac72009-02-26 12:39:281271
[email protected]a95986a82010-12-24 06:19:281272 bool handled = true;
[email protected]e44d1342014-05-16 21:29:331273 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
mcnee432e47d2015-11-09 19:37:461274 IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale)
initial.commit09911bf2008-07-26 23:55:291275 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291276 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1277 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
initial.commit09911bf2008-07-26 23:55:291278 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
[email protected]30f75e62009-02-25 22:01:001279 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]ab32b16c2009-10-16 14:57:251280 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1281 OnEnablePreferredSizeChangedMode)
[email protected]80d96fa2009-06-10 22:34:511282 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]81375e872012-01-11 21:40:361283 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
W. James MacLeand973a55b2018-11-29 21:39:131284 IPC_MESSAGE_HANDLER(ViewMsg_AnimateDoubleTapZoom,
1285 OnAnimateDoubleTapZoomInMainFrame)
W. James MacLean5372eb72018-12-19 12:56:361286 IPC_MESSAGE_HANDLER(ViewMsg_ZoomToFindInPageRect, OnZoomToFindInPageRect)
danakjd51fd53d2018-12-21 23:06:091287 IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque, OnSetBackgroundOpaque)
wjmaclean64951902016-04-29 20:59:121288
1289 // Page messages.
lfg717154072016-06-30 15:04:161290 IPC_MESSAGE_HANDLER(PageMsg_WasHidden, OnPageWasHidden)
1291 IPC_MESSAGE_HANDLER(PageMsg_WasShown, OnPageWasShown)
alexmos136fd6e62016-08-15 20:58:411292 IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength,
1293 OnSetHistoryOffsetAndLength)
altimind8bd26c2016-11-04 11:44:541294 IPC_MESSAGE_HANDLER(PageMsg_AudioStateChanged, OnAudioStateChanged)
lfg8d649cc2017-04-28 18:04:301295 IPC_MESSAGE_HANDLER(PageMsg_UpdateScreenInfo, OnUpdateScreenInfo)
Francois Doray47f759d2018-06-11 18:13:511296 IPC_MESSAGE_HANDLER(PageMsg_SetPageFrozen, SetPageFrozen)
W. James MacLean62198672019-06-04 16:46:101297 IPC_MESSAGE_HANDLER(PageMsg_UpdateTextAutosizerPageInfoForRemoteMainFrames,
1298 OnTextAutosizerPageInfoChanged)
lfg717154072016-06-30 15:04:161299
[email protected]a794f3a2013-10-30 17:00:321300 // Adding a new message? Add platform independent ones first, then put the
1301 // platform specific ones at the end.
[email protected]9e1ad4b2011-08-14 16:49:191302
Albert J. Wong7bbf22d2018-12-20 00:27:271303 // Have the widget handle all other messages.
1304 // TODO(ajwong): Remove this cross-object dispatch.
1305 IPC_MESSAGE_UNHANDLED(handled = GetWidget()->OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291306 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401307
[email protected]a95986a82010-12-24 06:19:281308 return handled;
initial.commit09911bf2008-07-26 23:55:291309}
1310
[email protected]180ef242013-11-07 06:50:461311// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521312
Mustaq Ahmed55944cb2018-05-25 20:44:271313// TODO(csharrison): Migrate this method to WebLocalFrameClient /
1314// RenderFrameImpl, as it is now serviced by a mojo interface scoped to the
1315// opener frame.
Daniel Murphyc8e991a2018-10-12 22:09:031316WebView* RenderViewImpl::CreateView(
1317 WebLocalFrame* creator,
1318 const WebURLRequest& request,
1319 const WebWindowFeatures& features,
1320 const WebString& frame_name,
1321 WebNavigationPolicy policy,
Daniel Murphyc8e991a2018-10-12 22:09:031322 WebSandboxFlags sandbox_flags,
Ehsan Karamad39407082019-02-19 23:38:191323 const blink::FeaturePolicy::FeatureState& opener_feature_state,
Daniel Murphyc8e991a2018-10-12 22:09:031324 const blink::SessionStorageNamespaceId& session_storage_namespace_id) {
nick5ae4d2d2017-01-06 01:18:351325 RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator);
rockot5c478a72016-09-28 23:14:181326 mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New();
Mustaq Ahmedc4cb7162018-06-05 16:28:361327
1328 // User Activation v2 moves user gesture checks to the browser process, with
1329 // the exception of the extensions case handled through the following |if|.
1330 params->mimic_user_gesture =
1331 base::FeatureList::IsEnabled(features::kUserActivationV2)
1332 ? false
1333 : WebUserGestureIndicator::IsProcessingUserGesture(creator);
Sergey Kuznetsov32257a22019-02-11 20:26:501334 // TODO(mustaq): Investigate if mimic_user_gesture can wrongly expose presence
1335 // of user activation w/o any user interaction, e.g. through
1336 // |WebChromeClient#onCreateWindow|. One case to deep-dive: disabling popup
1337 // blocker then calling window.open at onload event. crbug.com/929729
[email protected]00323f02013-07-24 15:47:411338 if (GetContentClient()->renderer()->AllowPopup())
Mustaq Ahmedc4cb7162018-06-05 16:28:361339 params->mimic_user_gesture = true;
1340
rockot5c478a72016-09-28 23:14:181341 params->window_container_type = WindowFeaturesToContainerType(features);
Daniel Murphye3eec92c2018-02-23 19:09:151342
Daniel Murphyc8e991a2018-10-12 22:09:031343 params->session_storage_namespace_id = session_storage_namespace_id;
1344 // TODO(dmurph): Don't copy session storage when features.noopener is true:
1345 // https://html.spec.whatwg.org/multipage/browsers.html#copy-session-storage
1346 // https://crbug.com/771959
Daniel Murphye3eec92c2018-02-23 19:09:151347 params->clone_from_session_storage_namespace_id =
1348 session_storage_namespace_id_;
Daniel Murphye3eec92c2018-02-23 19:09:151349
Daniel Chengd5e56ff2017-06-24 07:44:021350 const std::string& frame_name_utf8 = frame_name.Utf8(
1351 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
1352 params->frame_name = frame_name_utf8;
Nate Chapin43f307d2019-04-15 21:04:411353 params->opener_suppressed = features.noopener;
rockot5c478a72016-09-28 23:14:181354 params->disposition = NavigationPolicyToDisposition(policy);
Blink Reformat1c4d759e2017-04-09 16:34:541355 if (!request.IsNull()) {
1356 params->target_url = request.Url();
Leon Han963dc182018-11-06 05:41:481357 params->referrer =
1358 blink::mojom::Referrer::From(GetReferrerFromRequest(creator, request));
[email protected]44e55b012013-07-23 14:21:561359 }
scottmg8e6c6082017-02-13 23:15:481360 params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
[email protected]8ab04652010-06-12 02:47:261361
rockot5c478a72016-09-28 23:14:181362 // We preserve this information before sending the message since |params| is
1363 // moved on send.
1364 bool is_background_tab =
1365 params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB;
Mustaq Ahmedc4cb7162018-06-05 16:28:361366 bool opened_by_user_gesture = params->mimic_user_gesture;
[email protected]22217ed32013-11-18 18:40:231367
Daniel Cheng8bb30c62017-10-23 20:40:471368 mojom::CreateNewWindowStatus status;
rockot5c478a72016-09-28 23:14:181369 mojom::CreateNewWindowReplyPtr reply;
Balazs Engedya40712f2017-09-15 15:01:111370 auto* frame_host = creator_frame->GetFrameHost();
Daniel Cheng8bb30c62017-10-23 20:40:471371 bool err = !frame_host->CreateNewWindow(std::move(params), &status, &reply);
1372 if (err || status == mojom::CreateNewWindowStatus::kIgnore)
rockot5c478a72016-09-28 23:14:181373 return nullptr;
[email protected]48c9cf2d2009-09-16 16:47:521374
Jochen Eisinger515337a2017-05-26 14:12:521375 // For Android WebView, we support a pop-up like behavior for window.open()
1376 // even if the embedding app doesn't support multiple windows. In this case,
1377 // window.open() will return "window" and navigate it to whatever URL was
Jochen Eisinger8cb28492017-10-04 10:58:131378 // passed. We also don't need to consume user gestures to protect against
1379 // multiple windows being opened, because, well, the app doesn't support
1380 // multiple windows.
Daniel Cheng8bb30c62017-10-23 20:40:471381 // TODO(dcheng): It's awkward that this is plumbed into Blink but not really
Kent Tamura21d1de62018-12-10 04:45:201382 // used much in Blink, except to enable web testing... perhaps this should
Daniel Cheng8bb30c62017-10-23 20:40:471383 // be checked directly in the browser side.
1384 if (status == mojom::CreateNewWindowStatus::kReuse)
Jochen Eisinger515337a2017-05-26 14:12:521385 return webview();
1386
Daniel Cheng8bb30c62017-10-23 20:40:471387 DCHECK(reply);
1388 DCHECK_NE(MSG_ROUTING_NONE, reply->route_id);
1389 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_route_id);
1390 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_widget_route_id);
1391
Mustaq Ahmed76c2f4312018-06-07 20:48:011392 // The browser allowed creation of a new window and consumed the user
1393 // activation (UAv2 only).
Sergey Kuznetsov32257a22019-02-11 20:26:501394 bool was_consumed = WebUserGestureIndicator::ConsumeUserGesture(
Mustaq Ahmed76c2f4312018-06-07 20:48:011395 creator, blink::UserActivationUpdateSource::kBrowser);
Sergey Kuznetsov32257a22019-02-11 20:26:501396 if (base::FeatureList::IsEnabled(features::kUserActivationV2))
1397 opened_by_user_gesture = was_consumed;
Jochen Eisinger8cb28492017-10-04 10:58:131398
[email protected]7912e822014-04-16 02:37:031399 // While this view may be a background extension page, it can spawn a visible
1400 // render view. So we just assume that the new one is not another background
1401 // page instead of passing on our own value.
1402 // TODO(vangelis): Can we tell if the new view will be a background page?
1403 bool never_visible = false;
[email protected]9115d5f2013-03-24 04:37:411404
Fady Samuelff5b6eb562018-05-01 16:16:081405 VisualProperties visual_properties = VisualProperties();
danakj53802692018-07-25 21:46:441406 visual_properties.screen_info = GetWidget()->screen_info();
mkosiba58fa72f02014-11-12 01:21:361407
[email protected]d6fa88f2013-10-18 16:00:431408 // The initial hidden state for the RenderViewImpl here has to match what the
1409 // browser will eventually decide for the given disposition. Since we have to
1410 // return from this call synchronously, we just have to make our best guess
1411 // and rely on the browser sending a WasHidden / WasShown message if it
1412 // disagrees.
Balazs Engedyba034e72017-10-27 22:26:281413 mojom::CreateViewParamsPtr view_params = mojom::CreateViewParams::New();
alexmos5ac402d2015-07-09 07:51:101414
Balazs Engedyba034e72017-10-27 22:26:281415 view_params->opener_frame_route_id = creator_frame->GetRoutingID();
avia3dca182016-03-19 01:09:521416 DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID());
alexmos5ac402d2015-07-09 07:51:101417
Balazs Engedyba034e72017-10-27 22:26:281418 view_params->window_was_created_with_opener = true;
Leon Han2c81b5d2019-01-25 01:58:331419 view_params->renderer_preferences = renderer_preferences_.Clone();
Balazs Engedyba034e72017-10-27 22:26:281420 view_params->web_preferences = webkit_preferences_;
1421 view_params->view_id = reply->route_id;
1422 view_params->main_frame_routing_id = reply->main_frame_route_id;
Oksana Zhuravlova8b88e572019-01-07 21:54:001423 view_params->main_frame_interface_bundle =
1424 mojom::DocumentScopedInterfaceBundle::New(
1425 std::move(reply->main_frame_interface_bundle->interface_provider),
1426 std::move(reply->main_frame_interface_bundle
1427 ->document_interface_broker_content),
1428 std::move(reply->main_frame_interface_bundle
1429 ->document_interface_broker_blink));
Balazs Engedyba034e72017-10-27 22:26:281430 view_params->main_frame_widget_routing_id = reply->main_frame_widget_route_id;
1431 view_params->session_storage_namespace_id =
rockot5c478a72016-09-28 23:14:181432 reply->cloned_session_storage_namespace_id;
Daniel Murphy95792ef2018-10-04 01:29:551433 DCHECK(!view_params->session_storage_namespace_id.empty())
1434 << "Session storage namespace must be populated.";
Balazs Engedyba034e72017-10-27 22:26:281435 view_params->replicated_frame_state.frame_policy.sandbox_flags =
1436 sandbox_flags;
Ehsan Karamad39407082019-02-19 23:38:191437 view_params->replicated_frame_state.opener_feature_state =
1438 opener_feature_state;
Balazs Engedyba034e72017-10-27 22:26:281439 view_params->replicated_frame_state.name = frame_name_utf8;
1440 view_params->devtools_main_frame_token = reply->devtools_main_frame_token;
Daniel Chengd5e56ff2017-06-24 07:44:021441 // Even if the main frame has a name, the main frame's unique name is always
1442 // the empty string.
Balazs Engedyba034e72017-10-27 22:26:281443 view_params->hidden = is_background_tab;
1444 view_params->never_visible = never_visible;
Fady Samuelff5b6eb562018-05-01 16:16:081445 view_params->visual_properties = visual_properties;
naskobd911332014-11-25 01:13:361446
nick5ae4d2d2017-01-06 01:18:351447 // Unretained() is safe here because our calling function will also call
1448 // show().
nickf7b38222016-11-22 21:59:351449 RenderWidget::ShowCallback show_callback =
danakjdf1ceb72018-07-18 20:02:251450 base::BindOnce(&RenderFrameImpl::ShowCreatedWindow,
1451 base::Unretained(creator_frame), opened_by_user_gesture);
nickf7b38222016-11-22 21:59:351452
Balazs Engedyba034e72017-10-27 22:26:281453 RenderViewImpl* view = RenderViewImpl::Create(
danakj53802692018-07-25 21:46:441454 GetWidget()->compositor_deps(), std::move(view_params),
1455 std::move(show_callback),
Hajime Hoshi6fc91142018-05-11 08:21:171456 creator->GetTaskRunner(blink::TaskType::kInternalDefault));
[email protected]48c9cf2d2009-09-16 16:47:521457
[email protected]48c9cf2d2009-09-16 16:47:521458 return view->webview();
1459}
1460
danakj19f3e512018-12-14 21:02:051461blink::WebPagePopup* RenderViewImpl::CreatePopup(
1462 blink::WebLocalFrame* creator) {
danakj25ec6e2b2018-09-26 17:01:311463 mojom::WidgetPtr widget_channel;
1464 mojom::WidgetRequest widget_channel_request =
1465 mojo::MakeRequest(&widget_channel);
1466
1467 // Do a synchronous IPC to obtain a routing ID.
1468 int32_t widget_routing_id = MSG_ROUTING_NONE;
1469 bool success =
1470 RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
1471 GetRoutingID(), std::move(widget_channel), &widget_routing_id);
1472 if (!success) {
1473 // When the renderer is being killed the mojo message will fail.
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281474 return nullptr;
danakj25ec6e2b2018-09-26 17:01:311475 }
1476
1477 RenderWidget::ShowCallback opener_callback = base::BindOnce(
1478 &RenderViewImpl::ShowCreatedPopupWidget, weak_ptr_factory_.GetWeakPtr());
1479
1480 // The RenderWidget associated with the RenderView. This should be the
1481 // RenderWidget for the main frame, but may be a zombie RenderWidget when
1482 // the main frame is remote (we don't need a RenderWidget for it then).
1483 // However for now (https://crbug.com/419087) we know it exists and grab
1484 // state off it for the popup.
1485 // TODO(crbug.com/419087): This should probably be using the local root's
1486 // RenderWidget for the frame making the popup.
1487 RenderWidget* view_render_widget = GetWidget();
1488
Albert J. Wong2727e8a82019-02-15 16:56:111489 auto popup_widget = RenderWidget::CreateForPopup(
danakj25ec6e2b2018-09-26 17:01:311490 widget_routing_id, view_render_widget->compositor_deps(),
danakj89ae4532018-12-12 22:52:551491 view_render_widget->screen_info(), blink::kWebDisplayModeUndefined,
danakj6dcbc5962018-11-16 16:45:421492 /*is_frozen=*/false,
danakj25ec6e2b2018-09-26 17:01:311493 /*hidden=*/false,
1494 /*never_visible=*/false, std::move(widget_channel_request));
1495
1496 // The returned WebPagePopup is self-referencing, so the pointer here is not
danakj45e4a4f2019-03-12 22:50:421497 // an owning pointer. It is de-referenced by calling Close().
danakj25ec6e2b2018-09-26 17:01:311498 blink::WebPagePopup* popup_web_widget =
1499 blink::WebPagePopup::Create(popup_widget.get());
1500
1501 // Adds a self-reference on the |popup_widget| so it will not be destroyed
1502 // when leaving scope. The WebPagePopup takes responsibility for Close()ing
1503 // and thus destroying the RenderWidget.
1504 popup_widget->InitForPopup(std::move(opener_callback), popup_web_widget);
1505 // TODO(crbug.com/419087): RenderWidget has some weird logic for picking a
1506 // WebWidget which doesn't apply to this case. So we verify. This can go away
1507 // when RenderWidget::GetWebWidget() is just a simple accessor.
1508 DCHECK_EQ(popup_widget->GetWebWidget(), popup_web_widget);
1509
1510 // Devtools emulation, which may be currently applied to the
1511 // |view_render_widget|, should also apply to the new popup. This doesn't
1512 // happen automatically.
1513 popup_widget->ApplyEmulatedScreenMetricsForPopupWidget(view_render_widget);
1514
1515 return popup_web_widget;
[email protected]48c9cf2d2009-09-16 16:47:521516}
1517
danakj295c43f182019-03-13 16:37:171518void RenderViewImpl::DoDeferredClose() {
1519 // The main widget is currently not active. The active main frame widget is
1520 // in a different process. Have the browser route the close request to the
1521 // active widget instead, so that the correct unload handlers are run.
1522 Send(new ViewHostMsg_RouteCloseEvent(GetRoutingID()));
1523}
1524
danakj45e4a4f2019-03-12 22:50:421525void RenderViewImpl::CloseWindowSoon() {
Avi Drissman07d22452019-03-25 17:56:391526 DCHECK(RenderThread::IsMainThread());
danakj45e4a4f2019-03-12 22:50:421527 if (render_widget_->is_frozen()) {
danakj295c43f182019-03-13 16:37:171528 // Ask the RenderViewHost with a local main frame to initiate close. We
1529 // could be called from deep in Javascript. If we ask the RenderViewHost to
1530 // close now, the window could be closed before the JS finishes executing,
1531 // thanks to nested message loops running and handling the resuliting Close
1532 // IPC. So instead, post a message back to the message loop, which won't run
1533 // until the JS is complete, and then the Close request can be sent.
1534 GetCleanupTaskRunner()->PostTask(
1535 FROM_HERE, base::BindOnce(&RenderViewImpl::DoDeferredClose,
1536 weak_ptr_factory_.GetWeakPtr()));
danakj45e4a4f2019-03-12 22:50:421537 return;
1538 }
1539
1540 // If the main widget is not frozen then the Close request goes directly
1541 // through it, because the RenderWidget ultimately owns the RenderViewImpl.
1542 render_widget_->CloseWidgetSoon();
1543}
1544
Daniel Murphy31bbb8b12018-02-07 21:44:101545base::StringPiece RenderViewImpl::GetSessionStorageNamespaceId() {
1546 CHECK(!session_storage_namespace_id_.empty());
Daniel Murphy0ce6e2c2017-11-21 01:54:261547 return session_storage_namespace_id_;
[email protected]bd92c3a2010-01-13 05:02:341548}
1549
Blink Reformat1c4d759e2017-04-09 16:34:541550void RenderViewImpl::PrintPage(WebLocalFrame* frame) {
naskoe440d8c2016-10-12 23:07:561551 UMA_HISTOGRAM_BOOLEAN("PrintPreview.InitiatedByScript",
Blink Reformat1c4d759e2017-04-09 16:34:541552 frame->Top() == frame);
naskoe440d8c2016-10-12 23:07:561553
1554 // Logging whether the top frame is remote is sufficient in this case. If
1555 // the top frame is local, the printing code will function correctly and
1556 // the frame itself will be printed, so the cases this histogram tracks is
1557 // where printing of a subframe will fail as of now.
1558 UMA_HISTOGRAM_BOOLEAN("PrintPreview.OutOfProcessSubframe",
Blink Reformat1c4d759e2017-04-09 16:34:541559 frame->Top()->IsWebRemoteFrame());
naskoe440d8c2016-10-12 23:07:561560
thestigcb959ce2016-11-17 05:56:321561 RenderFrameImpl::FromWebFrame(frame)->ScriptedPrint(
danakj53802692018-07-25 21:46:441562 GetWidget()->input_handler().handling_input_event());
[email protected]48c9cf2d2009-09-16 16:47:521563}
1564
lfgcaab5142016-02-26 19:06:521565void RenderViewImpl::AttachWebFrameWidget(blink::WebFrameWidget* frame_widget) {
dcheng3ce04b62015-10-26 23:30:551566 // The previous WebFrameWidget must already be detached by CloseForFrame().
1567 DCHECK(!frame_widget_);
1568 frame_widget_ = frame_widget;
danakjefcb8432019-01-16 18:47:141569
1570 // Initialization for the WebFrameWidget that should only occur for the main
1571 // frame, and that uses types not allowed in blink. This should maybe be
1572 // passed to the creation of the WebFrameWidget or the main RenderFrame.
1573 const base::CommandLine& command_line =
1574 *base::CommandLine::ForCurrentProcess();
danakj175a17a2019-03-15 23:10:381575 render_widget_->SetShowFPSCounter(
danakjefcb8432019-01-16 18:47:141576 command_line.HasSwitch(cc::switches::kShowFPSCounter));
dcheng3ce04b62015-10-26 23:30:551577}
1578
danakj8f4465b2018-11-07 20:11:281579void RenderViewImpl::DetachWebFrameWidget() {
danakjb08b3712019-01-16 18:59:561580 DCHECK(GetWidget()->is_frozen() || GetWidget()->is_closing());
danakj8f4465b2018-11-07 20:11:281581 DCHECK(frame_widget_);
danakj8f4465b2018-11-07 20:11:281582 frame_widget_->Close();
1583 frame_widget_ = nullptr;
1584}
1585
tommycli8aad3ba2015-08-12 17:57:591586void RenderViewImpl::SetZoomLevel(double zoom_level) {
wjmaclean64951902016-04-29 20:59:121587 // If we change the zoom level for the view, make sure any subsequent subframe
1588 // loads reflect the current zoom level.
1589 page_zoom_level_ = zoom_level;
1590
Blink Reformat1c4d759e2017-04-09 16:34:541591 webview()->SetZoomLevel(zoom_level);
ericwilligers88e69742016-10-17 19:29:551592 for (auto& observer : observers_)
1593 observer.OnZoomLevelChanged();
tommycli8aad3ba2015-08-12 17:57:591594}
1595
habib.virji597255e2014-09-09 00:30:181596void RenderViewImpl::SetValidationMessageDirection(
1597 base::string16* wrapped_main_text,
1598 blink::WebTextDirection main_text_hint,
1599 base::string16* wrapped_sub_text,
1600 blink::WebTextDirection sub_text_hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541601 if (main_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181602 *wrapped_main_text =
1603 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
Blink Reformat1c4d759e2017-04-09 16:34:541604 } else if (main_text_hint == blink::kWebTextDirectionRightToLeft &&
habib.virji597255e2014-09-09 00:30:181605 !base::i18n::IsRTL()) {
1606 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
1607 }
1608
1609 if (!wrapped_sub_text->empty()) {
Blink Reformat1c4d759e2017-04-09 16:34:541610 if (sub_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181611 *wrapped_sub_text =
1612 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
Blink Reformat1c4d759e2017-04-09 16:34:541613 } else if (sub_text_hint == blink::kWebTextDirectionRightToLeft) {
habib.virji597255e2014-09-09 00:30:181614 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
1615 }
1616 }
1617}
1618
[email protected]310ebd6302011-10-10 19:06:281619void RenderViewImpl::UpdateTargetURL(const GURL& url,
1620 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581621 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521622 if (latest_url == target_url_)
1623 return;
[email protected]163f8242009-10-30 20:19:551624
[email protected]48c9cf2d2009-09-16 16:47:521625 // Tell the browser to display a destination link.
1626 if (target_url_status_ == TARGET_INFLIGHT ||
1627 target_url_status_ == TARGET_PENDING) {
1628 // If we have a request in-flight, save the URL to be sent when we
1629 // receive an ACK to the in-flight request. We can happily overwrite
1630 // any existing pending sends.
1631 pending_target_url_ = latest_url;
1632 target_url_status_ = TARGET_PENDING;
1633 } else {
mnaganovbf087422015-12-16 05:10:031634 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411635 // see |ParamTraits<GURL>|.
markdittmer67b71ea2016-03-03 22:40:031636 if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:411637 latest_url = GURL();
avia3dca182016-03-19 01:09:521638 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), latest_url));
[email protected]48c9cf2d2009-09-16 16:47:521639 target_url_ = latest_url;
1640 target_url_status_ = TARGET_INFLIGHT;
1641 }
1642}
1643
creis69b184a472015-11-26 05:29:511644void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) {
creisce0ef3572017-01-26 17:53:081645 // Keep track of which frames have pending updates.
1646 frames_with_pending_state_.insert(frame->GetRoutingID());
creis8eb8ef22015-11-04 22:51:381647
[email protected]882daa92009-11-05 16:31:311648 int delay;
avif937e1d2014-11-02 18:13:071649 if (send_content_state_immediately_)
[email protected]882daa92009-11-05 16:31:311650 delay = 0;
danakj78744912018-11-30 23:46:421651 else if (GetWebView()->IsHidden())
avif937e1d2014-11-02 18:13:071652 delay = kDelaySecondsForContentStateSyncHidden;
[email protected]882daa92009-11-05 16:31:311653 else
avif937e1d2014-11-02 18:13:071654 delay = kDelaySecondsForContentStateSync;
[email protected]882daa92009-11-05 16:31:311655
avif937e1d2014-11-02 18:13:071656 if (nav_state_sync_timer_.IsRunning()) {
[email protected]882daa92009-11-05 16:31:311657 // The timer is already running. If the delay of the timer maches the amount
1658 // we want to delay by, then return. Otherwise stop the timer so that it
1659 // gets started with the right delay.
avif937e1d2014-11-02 18:13:071660 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
[email protected]882daa92009-11-05 16:31:311661 return;
avif937e1d2014-11-02 18:13:071662 nav_state_sync_timer_.Stop();
[email protected]882daa92009-11-05 16:31:311663 }
1664
creisce0ef3572017-01-26 17:53:081665 // Tell each frame with pending state to inform the browser.
danakj19f3e512018-12-14 21:02:051666 nav_state_sync_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay),
1667 this, &RenderViewImpl::SendFrameStateUpdates);
[email protected]882daa92009-11-05 16:31:311668}
1669
Blink Reformat1c4d759e2017-04-09 16:34:541670void RenderViewImpl::SetMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551671 mouse_over_url_ = GURL(url);
1672 UpdateTargetURL(mouse_over_url_, focus_url_);
1673}
1674
Blink Reformat1c4d759e2017-04-09 16:34:541675void RenderViewImpl::SetKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551676 focus_url_ = GURL(url);
1677 UpdateTargetURL(focus_url_, mouse_over_url_);
1678}
1679
Blink Reformat1c4d759e2017-04-09 16:34:541680bool RenderViewImpl::AcceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451681 return renderer_preferences_.can_accept_load_drops;
1682}
1683
Blink Reformat1c4d759e2017-04-09 16:34:541684void RenderViewImpl::FocusNext() {
avia3dca182016-03-19 01:09:521685 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false));
[email protected]48c9cf2d2009-09-16 16:47:521686}
1687
Blink Reformat1c4d759e2017-04-09 16:34:541688void RenderViewImpl::FocusPrevious() {
avia3dca182016-03-19 01:09:521689 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true));
[email protected]48c9cf2d2009-09-16 16:47:521690}
1691
Kent Tamura69d143e2019-05-22 00:31:451692void RenderViewImpl::FocusedElementChanged(const WebElement& from_element,
1693 const WebElement& to_element) {
estade31c54342015-01-23 03:34:361694 RenderFrameImpl* previous_frame = nullptr;
Kent Tamura69d143e2019-05-22 00:31:451695 if (!from_element.IsNull())
Blink Reformat1c4d759e2017-04-09 16:34:541696 previous_frame =
Kent Tamura69d143e2019-05-22 00:31:451697 RenderFrameImpl::FromWebFrame(from_element.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361698 RenderFrameImpl* new_frame = nullptr;
Kent Tamura69d143e2019-05-22 00:31:451699 if (!to_element.IsNull())
1700 new_frame =
1701 RenderFrameImpl::FromWebFrame(to_element.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361702
1703 if (previous_frame && previous_frame != new_frame)
Kent Tamura69d143e2019-05-22 00:31:451704 previous_frame->FocusedElementChanged(WebElement());
estade31c54342015-01-23 03:34:361705 if (new_frame)
Kent Tamura69d143e2019-05-22 00:31:451706 new_frame->FocusedElementChanged(to_element);
estade31c54342015-01-23 03:34:361707
1708 // TODO(dmazzoni): remove once there's a separate a11y tree per frame.
naskoe8d115752015-08-07 00:43:131709 if (main_render_frame_)
Kent Tamura69d143e2019-05-22 00:31:451710 main_render_frame_->FocusedElementChangedForAccessibility(to_element);
[email protected]08e9e132010-06-01 16:58:491711}
1712
Philip Rogers079658812018-08-01 23:19:091713void RenderViewImpl::DidUpdateMainFrameLayout() {
ericwilligers88e69742016-10-17 19:29:551714 for (auto& observer : observers_)
Philip Rogers079658812018-08-01 23:19:091715 observer.DidUpdateMainFrameLayout();
[email protected]d01b2a62013-09-18 23:21:331716
Philip Rogers33cd2bcc2018-08-13 21:29:291717 // The main frame may have changed size.
1718 needs_preferred_size_update_ = true;
[email protected]169d4282011-11-30 19:33:591719}
1720
Arthur Sonzognia7d715a2018-09-20 16:11:131721void RenderViewImpl::NavigateBackForwardSoon(int offset,
1722 bool has_user_gesture) {
Alex Clarkebf3dceb2017-11-24 12:27:431723 history_navigation_virtual_time_pauser_ =
1724 RenderThreadImpl::current()
Yuta Kitamura3331f5c2018-04-05 11:12:251725 ->GetWebMainThreadScheduler()
Alex Clarkeb28db542018-02-07 12:53:131726 ->CreateWebScopedVirtualTimePauser(
Alex Clarkeaaf006b2018-04-05 18:35:241727 "NavigateBackForwardSoon",
Alex Clarkeb28db542018-02-07 12:53:131728 blink::WebScopedVirtualTimePauser::VirtualTaskDuration::kInstant);
Alex Clarkeaaf006b2018-04-05 18:35:241729 history_navigation_virtual_time_pauser_.PauseVirtualTime();
[email protected]48c9cf2d2009-09-16 16:47:521730}
1731
Alex Clarkebf3dceb2017-11-24 12:27:431732void RenderViewImpl::DidCommitProvisionalHistoryLoad() {
Alex Clarkeaaf006b2018-04-05 18:35:241733 history_navigation_virtual_time_pauser_.UnpauseVirtualTime();
Alex Clarkebf3dceb2017-11-24 12:27:431734}
1735
Michael Martis2415478f2019-04-17 07:35:001736void RenderViewImpl::RegisterRendererPreferenceWatcher(
Leon Hanf4003a162019-01-28 05:31:581737 blink::mojom::RendererPreferenceWatcherPtr watcher) {
Makoto Shimazuc3c730e2018-08-15 09:51:111738 renderer_preference_watchers_.AddPtr(std::move(watcher));
1739}
1740
Blink Reformat1c4d759e2017-04-09 16:34:541741int RenderViewImpl::HistoryBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001742 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521743}
1744
Blink Reformat1c4d759e2017-04-09 16:34:541745int RenderViewImpl::HistoryForwardListCount() {
1746 return history_list_length_ - HistoryBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521747}
1748
[email protected]180ef242013-11-07 06:50:461749// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:511750
Blink Reformat1c4d759e2017-04-09 16:34:541751bool RenderViewImpl::CanHandleGestureEvent() {
slangley1a6375e62017-03-29 06:03:231752 return true;
1753}
1754
Avi Drissmanfb961262019-03-05 22:50:291755// TODO(https://crbug.com/937569): Remove this in Chrome 82.
1756bool RenderViewImpl::AllowPopupsDuringPageUnload() {
1757 const base::CommandLine& command_line =
1758 *base::CommandLine::ForCurrentProcess();
1759 return command_line.HasSwitch(switches::kAllowPopupsDuringPageUnload);
1760}
1761
Blink Reformat1c4d759e2017-04-09 16:34:541762bool RenderViewImpl::CanUpdateLayout() {
slangley1a6375e62017-03-29 06:03:231763 return true;
1764}
1765
Mustaq Ahmed55944cb2018-05-25 20:44:271766// blink::WebLocalFrameClient
1767// -----------------------------------------------------
[email protected]3d9689372009-09-10 04:29:171768
[email protected]b2324b092012-11-01 10:34:111769void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
1770 const std::string& value) {
alexmos56567492016-09-13 00:52:461771 GetWidget()->SetEditCommandForNextKeyEvent(name, value);
[email protected]b2324b092012-11-01 10:34:111772}
1773
1774void RenderViewImpl::ClearEditCommands() {
alexmos56567492016-09-13 00:52:461775 GetWidget()->ClearEditCommands();
[email protected]b2324b092012-11-01 10:34:111776}
1777
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491778const std::string& RenderViewImpl::GetAcceptLanguages() {
[email protected]b38806a2013-10-04 16:01:381779 return renderer_preferences_.accept_languages;
1780}
1781
Ahmed Fakhry58e6ef542018-09-04 18:05:381782void RenderViewImpl::UpdateBrowserControlsState(
1783 BrowserControlsState constraints,
1784 BrowserControlsState current,
1785 bool animate) {
David Bokan3746d2c2018-10-29 20:21:351786 TRACE_EVENT2("renderer", "RenderViewImpl::UpdateBrowserControlsState",
1787 "Constraint", static_cast<int>(constraints), "Current",
1788 static_cast<int>(current));
1789 TRACE_EVENT_INSTANT1("renderer", "is_animated", TRACE_EVENT_SCOPE_THREAD,
1790 "animated", animate);
1791
David Bokan1e37ebf2018-10-16 13:53:371792 if (GetWidget() && GetWidget()->layer_tree_view()) {
1793 GetWidget()->layer_tree_view()->UpdateBrowserControlsState(
1794 ContentToCc(constraints), ContentToCc(current), animate);
Ahmed Fakhry58e6ef542018-09-04 18:05:381795 }
1796
1797 top_controls_constraints_ = constraints;
1798}
1799
David Bokan1e37ebf2018-10-16 13:53:371800#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
1801
Ahmed Fakhry58e6ef542018-09-04 18:05:381802void RenderViewImpl::didScrollWithKeyboard(const blink::WebSize& delta) {
1803 if (delta.height == 0)
1804 return;
1805
1806 BrowserControlsState current = delta.height < 0
1807 ? BROWSER_CONTROLS_STATE_SHOWN
1808 : BROWSER_CONTROLS_STATE_HIDDEN;
1809
1810 UpdateBrowserControlsState(top_controls_constraints_, current, true);
1811}
1812
1813#endif
1814
danakjdea2efb2016-03-10 19:13:171815void RenderViewImpl::ConvertViewportToWindowViaWidget(blink::WebRect* rect) {
danakj175a17a2019-03-15 23:10:381816 render_widget_->ConvertViewportToWindow(rect);
oshimae2b3b402015-12-04 04:27:241817}
1818
huangs2a342352015-12-15 16:59:241819gfx::RectF RenderViewImpl::ElementBoundsInWindow(
1820 const blink::WebElement& element) {
Blink Reformat1c4d759e2017-04-09 16:34:541821 blink::WebRect bounding_box_in_window = element.BoundsInViewport();
danakj175a17a2019-03-15 23:10:381822 render_widget_->ConvertViewportToWindow(&bounding_box_in_window);
huangs2a342352015-12-15 16:59:241823 return gfx::RectF(bounding_box_in_window);
1824}
1825
Philip Rogers601fd072018-08-07 22:58:221826void RenderViewImpl::UpdatePreferredSize() {
[email protected]d812fd12011-05-27 23:05:071827 // We don't always want to send the change messages over IPC, only if we've
1828 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1829 // message.
1830 if (!send_preferred_size_changes_ || !webview())
1831 return;
Philip Rogers33cd2bcc2018-08-13 21:29:291832
1833 if (!needs_preferred_size_update_)
1834 return;
1835 needs_preferred_size_update_ = false;
1836
oshima1a688b5c2017-06-16 19:00:131837 blink::WebSize tmp_size = webview()->ContentsPreferredMinimumSize();
1838 blink::WebRect tmp_rect(0, 0, tmp_size.width, tmp_size.height);
danakj175a17a2019-03-15 23:10:381839 render_widget_->ConvertViewportToWindow(&tmp_rect);
oshima1a688b5c2017-06-16 19:00:131840 gfx::Size size(tmp_rect.width, tmp_rect.height);
[email protected]705243f2010-05-05 19:58:071841 if (size == preferred_size_)
1842 return;
[email protected]c27324b2009-11-19 22:44:291843
[email protected]705243f2010-05-05 19:58:071844 preferred_size_ = size;
avia3dca182016-03-19 01:09:521845 Send(new ViewHostMsg_DidContentsPreferredSizeChange(GetRoutingID(),
[email protected]705243f2010-05-05 19:58:071846 preferred_size_));
[email protected]3d9689372009-09-10 04:29:171847}
1848
Blink Reformat1c4d759e2017-04-09 16:34:541849blink::WebString RenderViewImpl::AcceptLanguages() {
1850 return WebString::FromUTF8(renderer_preferences_.accept_languages);
[email protected]9982c802013-06-12 15:22:061851}
1852
[email protected]e9ff79c2012-10-19 21:31:261853// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:311854
[email protected]310ebd6302011-10-10 19:06:281855bool RenderViewImpl::Send(IPC::Message* message) {
danakja2c9d0a92018-07-25 20:01:181856 // This method is an override of IPC::Sender, but RenderWidget also has an
1857 // override of IPC::Sender, so this method also overrides RenderWidget. Thus
1858 // we must call to the base class, not via an upcast or virtual dispatch would
1859 // go back here.
Albert J. Wong7bbf22d2018-12-20 00:27:271860 CHECK(message->routing_id() != MSG_ROUTING_NONE);
1861
1862 // TODO(ajwong): Don't delegate to render widget. Filter here.
1863 return GetWidget()->Send(message);
[email protected]a2ef54c2011-10-10 16:20:311864}
1865
Peter Kastinga4a3ed12018-01-31 04:07:591866RenderWidget* RenderViewImpl::GetWidget() {
Albert J. Wong7bbf22d2018-12-20 00:27:271867 return render_widget_;
1868}
1869
1870const RenderWidget* RenderViewImpl::GetWidget() const {
1871 return render_widget_;
avi8a45c1092016-03-01 16:12:341872}
1873
mostynbc33353232014-09-12 09:38:311874RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() {
nasko77de2312015-05-12 03:09:161875 return main_render_frame_;
[email protected]b849847b2013-12-10 21:57:581876}
1877
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491878int RenderViewImpl::GetRoutingID() {
Albert J. Wongcb004632018-07-10 22:58:251879 return routing_id_;
[email protected]a2ef54c2011-10-10 16:20:311880}
1881
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491882gfx::Size RenderViewImpl::GetSize() {
Albert J. Wong7bbf22d2018-12-20 00:27:271883 return GetWidget()->size();
[email protected]a2ef54c2011-10-10 16:20:311884}
1885
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491886float RenderViewImpl::GetDeviceScaleFactor() {
Albert J. Wong7bbf22d2018-12-20 00:27:271887 return GetWidget()->GetWebScreenInfo().device_scale_factor;
oshima129b75e2016-01-14 09:15:141888}
1889
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491890float RenderViewImpl::GetZoomLevel() {
Marc Treib06d66032017-10-19 08:43:201891 return page_zoom_level_;
1892}
1893
thestig8a8fdfd32017-05-06 18:46:541894const WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:311895 return webkit_preferences_;
1896}
1897
[email protected]324825d2012-11-30 12:37:151898void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
1899 OnUpdateWebPreferences(preferences);
1900}
1901
[email protected]180ef242013-11-07 06:50:461902blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:311903 return webview();
1904}
1905
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491906bool RenderViewImpl::GetContentStateImmediately() {
avif937e1d2014-11-02 18:13:071907 return send_content_state_immediately_;
[email protected]a2ef54c2011-10-10 16:20:311908}
1909
mcnee432e47d2015-11-09 19:37:461910void RenderViewImpl::OnSetPageScale(float page_scale_factor) {
ccameronb7c1d6c2015-03-09 17:08:241911 if (!webview())
1912 return;
Blink Reformat1c4d759e2017-04-09 16:34:541913 webview()->SetPageScaleFactor(page_scale_factor);
ccameronb7c1d6c2015-03-09 17:08:241914}
1915
akaba3483d8f2018-07-10 21:43:091916void RenderViewImpl::UpdateZoomLevel(double zoom_level) {
danakja5c39d52018-12-13 22:20:561917 webview()->CancelPagePopup();
wjmaclean64951902016-04-29 20:59:121918 SetZoomLevel(zoom_level);
[email protected]d42bf472014-06-14 01:49:381919}
1920
danakj78744912018-11-30 23:46:421921void RenderViewImpl::ApplyPageHidden(bool hidden, bool initial_setting) {
1922 webview()->SetIsHidden(hidden, initial_setting);
1923 // Note: RenderWidget visibility is separately set from the IPC handlers, and
1924 // does not change when tests override the visibility of the Page.
danakj1b35e9d2018-11-07 19:09:281925}
1926
[email protected]310ebd6302011-10-10 19:06:281927void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:591928 webkit_preferences_ = prefs;
danakjfd0c7f42018-10-12 18:01:081929 ApplyWebPreferences(webkit_preferences_, webview());
initial.commit09911bf2008-07-26 23:55:291930}
1931
[email protected]2bf834f2011-11-17 20:02:211932void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:241933 if (send_preferred_size_changes_)
1934 return;
[email protected]9fb325e2010-05-06 18:23:241935 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:391936
Philip Rogers601fd072018-08-07 22:58:221937 if (!webview())
1938 return;
1939
Philip Rogers33cd2bcc2018-08-13 21:29:291940 needs_preferred_size_update_ = true;
1941
Philip Rogers601fd072018-08-07 22:58:221942 // We need to ensure |UpdatePreferredSize| gets called. If a layout is needed,
1943 // force an update here which will call |DidUpdateMainFrameLayout|.
danakj763c2402018-11-09 02:46:221944 webview()->MainFrameWidget()->UpdateLifecycle(
Stephen Chenneyec4312612018-11-21 12:40:161945 WebWidget::LifecycleUpdate::kLayout,
1946 WebWidget::LifecycleUpdateReason::kOther);
Philip Rogers601fd072018-08-07 22:58:221947
1948 // If a layout was not needed, |DidUpdateMainFrameLayout| will not be called.
1949 // We explicitly update the preferred size here to ensure the preferred size
1950 // notification is sent.
1951 UpdatePreferredSize();
[email protected]0666aef2009-05-13 19:48:081952}
1953
[email protected]310ebd6302011-10-10 19:06:281954void RenderViewImpl::OnSetRendererPrefs(
Leon Hanc819dc62019-01-28 04:30:191955 const blink::mojom::RendererPreferences& renderer_prefs) {
[email protected]ebd5ea52014-05-28 14:51:151956 std::string old_accept_languages = renderer_preferences_.accept_languages;
1957
[email protected]80d96fa2009-06-10 22:34:511958 renderer_preferences_ = renderer_prefs;
ananta59b9fe72015-04-07 01:33:261959
Makoto Shimazuc3c730e2018-08-15 09:51:111960 renderer_preference_watchers_.ForAllPtrs(
Leon Hanf4003a162019-01-28 05:31:581961 [&renderer_prefs](blink::mojom::RendererPreferenceWatcher* watcher) {
Leon Han2c81b5d2019-01-25 01:58:331962 watcher->NotifyUpdate(renderer_prefs.Clone());
Makoto Shimazuc3c730e2018-08-15 09:51:111963 });
1964
[email protected]6e282c92009-07-24 01:19:371965 UpdateFontRenderingFromRendererPrefs();
scottmgb92365e2016-08-30 20:54:401966 UpdateThemePrefs();
Leon Han2c81b5d2019-01-25 01:58:331967 blink::SetCaretBlinkInterval(
1968 renderer_prefs.caret_blink_interval.has_value()
1969 ? renderer_prefs.caret_blink_interval.value()
1970 : base::TimeDelta::FromMilliseconds(
Leon Hanc819dc62019-01-28 04:30:191971 blink::mojom::kDefaultCaretBlinkIntervalInMilliseconds));
[email protected]38a85712013-01-02 22:45:021972
Christopher Cameronf8e279d32019-05-15 18:50:561973#if defined(USE_AURA)
[email protected]1596efb2013-01-17 22:13:011974 if (renderer_prefs.use_custom_colors) {
Blink Reformat1c4d759e2017-04-09 16:34:541975 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
Christopher Cameronf6fc7ec2019-05-13 18:52:531976 blink::SetSelectionColors(renderer_prefs.active_selection_bg_color,
1977 renderer_prefs.active_selection_fg_color,
1978 renderer_prefs.inactive_selection_bg_color,
1979 renderer_prefs.inactive_selection_fg_color);
1980 if (webview())
danakj763c2402018-11-09 02:46:221981 webview()->MainFrameWidget()->ThemeChanged();
[email protected]644d77e2010-01-27 01:03:101982 }
Christopher Cameronf8e279d32019-05-15 18:50:561983#endif
[email protected]d299d972012-03-23 02:26:551984
[email protected]ebd5ea52014-05-28 14:51:151985 if (webview() &&
1986 old_accept_languages != renderer_preferences_.accept_languages) {
Blink Reformat1c4d759e2017-04-09 16:34:541987 webview()->AcceptLanguagesChanged();
[email protected]ebd5ea52014-05-28 14:51:151988 }
[email protected]80d96fa2009-06-10 22:34:511989}
1990
[email protected]81375e872012-01-11 21:40:361991void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
1992 const WebPluginAction& action) {
1993 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:541994 webview()->PerformPluginAction(action, location);
[email protected]81375e872012-01-11 21:40:361995}
1996
[email protected]310ebd6302011-10-10 19:06:281997void RenderViewImpl::OnClosePage() {
lukasza5d0dee42017-06-14 21:57:371998 // ViewMsg_ClosePage should only be sent to active, non-swapped-out views.
1999 DCHECK(webview()->MainFrame()->IsWebLocalFrame());
2000
initial.commit09911bf2008-07-26 23:55:292001 // TODO(creis): We'd rather use webview()->Close() here, but that currently
2002 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
2003 // in the onunload handler from appearing. For now, we're bypassing that and
2004 // calling the FrameLoader's CloseURL method directly. This should be
2005 // revisited to avoid having two ways to close a page. Having a single way
2006 // to close that can run onunload is also useful for fixing
2007 // http://b/issue?id=753080.
lukasza5d0dee42017-06-14 21:57:372008 webview()->MainFrame()->ToWebLocalFrame()->DispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:292009
avia3dca182016-03-19 01:09:522010 Send(new ViewHostMsg_ClosePage_ACK(GetRoutingID()));
initial.commit09911bf2008-07-26 23:55:292011}
2012
[email protected]310ebd6302011-10-10 19:06:282013void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:002014 if (webview())
danakja5c39d52018-12-13 22:20:562015 webview()->CancelPagePopup();
[email protected]30f75e62009-02-25 22:01:002016}
2017
lfg717154072016-06-30 15:04:162018void RenderViewImpl::OnPageWasHidden() {
braveyao1d8ee7b2017-03-29 21:10:042019#if defined(OS_ANDROID)
2020 SuspendVideoCaptureDevices(true);
braveyao1d8ee7b2017-03-29 21:10:042021#endif
[email protected]2d7b82c2012-06-01 05:57:502022
danakj78744912018-11-30 23:46:422023 ApplyPageHidden(/*hidden=*/true, /*initial_setting=*/false);
[email protected]941e4552010-02-01 21:23:432024}
2025
lfg717154072016-06-30 15:04:162026void RenderViewImpl::OnPageWasShown() {
braveyao1d8ee7b2017-03-29 21:10:042027#if defined(OS_ANDROID)
2028 SuspendVideoCaptureDevices(false);
[email protected]6392d982013-04-16 16:59:222029#endif
2030
danakj78744912018-11-30 23:46:422031 ApplyPageHidden(/*hidden=*/false, /*initial_setting=*/false);
[email protected]a6939ca42011-02-18 17:58:072032}
[email protected]1e6e3c992010-02-08 15:52:132033
lfg8d649cc2017-04-28 18:04:302034void RenderViewImpl::OnUpdateScreenInfo(const ScreenInfo& screen_info) {
2035 // This IPC only updates the screen info on RenderViews that have a remote
2036 // main frame. For local main frames, the ScreenInfo is updated in
2037 // ViewMsg_Resize.
danakj53802692018-07-25 21:46:442038 // TODO(danakj): Move this message to RenderWidget?
lfg8d649cc2017-04-28 18:04:302039 if (!main_render_frame_)
danakj53802692018-07-25 21:46:442040 GetWidget()->set_screen_info(screen_info);
lfg8d649cc2017-04-28 18:04:302041}
2042
Francois Doray47f759d2018-06-11 18:13:512043void RenderViewImpl::SetPageFrozen(bool frozen) {
2044 if (webview())
2045 webview()->SetPageFrozen(frozen);
Fadi Meawada6573e02018-03-10 00:52:112046}
2047
W. James MacLean62198672019-06-04 16:46:102048// This function receives TextAutosizerPageInfo from the main frame's renderer
2049// and makes it available to other renderers with frames on the same page.
2050void RenderViewImpl::OnTextAutosizerPageInfoChanged(
2051 const blink::WebTextAutosizerPageInfo& page_info) {
2052 // Only propagate the remote page info if our main frame is remote. It's
2053 // possible a main frame renderer may receive this message, as SendPageMessage
2054 // in RenderFrameHostManager may send to a speculative RenderFrameHost that
2055 // corresponds to a local main frame. Since a local main frame will generate
2056 // these values for itself, we shouldn't override them with values from
2057 // another renderer.
2058 if (!webview()->MainFrame()->IsWebLocalFrame())
2059 webview()->SetTextAutosizePageInfo(page_info);
2060}
2061
alexmos3fcd0ca2015-10-23 18:18:332062void RenderViewImpl::SetFocus(bool enable) {
danakja2c9d0a92018-07-25 20:01:182063 // This is not an IPC message, don't go through the IPC handler. This is used
2064 // in cases where the IPC message should not happen.
2065 GetWidget()->SetFocus(enable);
[email protected]b2e4c70132013-10-03 02:07:512066}
2067
Blink Reformat1c4d759e2017-04-09 16:34:542068void RenderViewImpl::ZoomLimitsChanged(double minimum_level,
[email protected]310ebd6302011-10-10 19:06:282069 double maximum_level) {
a.sarkar.arundaadc712015-02-26 05:39:082070 // Round the double to avoid returning incorrect minimum/maximum zoom
2071 // percentages.
2072 int minimum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492073 ZoomLevelToZoomFactor(minimum_level) * 100);
a.sarkar.arundaadc712015-02-26 05:39:082074 int maximum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492075 ZoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:252076
avia3dca182016-03-19 01:09:522077 Send(new ViewHostMsg_UpdateZoomLimits(GetRoutingID(), minimum_percent,
fsamuele8326c742016-01-12 00:49:392078 maximum_percent));
[email protected]b75b8292010-10-01 07:28:252079}
2080
W. James MacLean233a64ff2019-05-18 16:18:492081void RenderViewImpl::PageScaleFactorChanged(float page_scale_factor) {
ccameronb7c1d6c2015-03-09 17:08:242082 if (!webview())
2083 return;
mcnee432e47d2015-11-09 19:37:462084
avia3dca182016-03-19 01:09:522085 Send(new ViewHostMsg_PageScaleFactorChanged(GetRoutingID(),
W. James MacLeanf40603e2019-03-25 17:23:062086 page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:242087}
2088
W. James MacLean62198672019-06-04 16:46:102089void RenderViewImpl::DidUpdateTextAutosizerPageInfo(
2090 const blink::WebTextAutosizerPageInfo& page_info) {
2091 DCHECK(webview()->MainFrame()->IsWebLocalFrame());
2092 Send(new ViewHostMsg_NotifyTextAutosizerPageInfoChangedInLocalMainFrame(
2093 GetRoutingID(), page_info));
2094}
2095
Blink Reformat1c4d759e2017-04-09 16:34:542096void RenderViewImpl::PageImportanceSignalsChanged() {
kouhei40f03cb2015-09-24 07:47:012097 if (!webview() || !main_render_frame_)
2098 return;
2099
Blink Reformat1c4d759e2017-04-09 16:34:542100 auto* web_signals = webview()->PageImportanceSignals();
kouhei40f03cb2015-09-24 07:47:012101
2102 PageImportanceSignals signals;
Blink Reformat1c4d759e2017-04-09 16:34:542103 signals.had_form_interaction = web_signals->HadFormInteraction();
kouhei40f03cb2015-09-24 07:47:012104
2105 main_render_frame_->Send(new FrameHostMsg_UpdatePageImportanceSignals(
2106 main_render_frame_->GetRoutingID(), signals));
2107}
2108
danakj9a8a9cf2018-07-17 23:52:122109void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) {
danakja2c9d0a92018-07-25 20:01:182110 GetWidget()->DidAutoResize(newSize);
danakj9a8a9cf2018-07-17 23:52:122111}
2112
danakja2c9d0a92018-07-25 20:01:182113void RenderViewImpl::DidFocus(blink::WebLocalFrame* calling_frame) {
2114 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2115 // we won't have to test for user gesture anymore and we can
2116 // move that code back to render_widget.cc
2117 if (WebUserGestureIndicator::IsProcessingUserGesture(calling_frame) &&
Kent Tamura2eab5b12018-12-07 04:31:232118 !RenderThreadImpl::current()->web_test_mode()) {
danakja2c9d0a92018-07-25 20:01:182119 Send(new ViewHostMsg_Focus(GetRoutingID()));
2120
2121 // Tattle on the frame that called |window.focus()|.
2122 RenderFrameImpl* calling_render_frame =
2123 RenderFrameImpl::FromWebFrame(calling_frame);
2124 if (calling_render_frame)
2125 calling_render_frame->FrameDidCallFocus();
2126 }
2127}
2128
danakj46b3dde2018-10-18 16:12:172129blink::WebScreenInfo RenderViewImpl::GetScreenInfo() {
2130 const ScreenInfo& info = GetWidget()->screen_info();
2131
2132 blink::WebScreenInfo web_screen_info;
2133 web_screen_info.device_scale_factor = info.device_scale_factor;
2134 web_screen_info.color_space = info.color_space;
2135 web_screen_info.depth = info.depth;
2136 web_screen_info.depth_per_component = info.depth_per_component;
2137 web_screen_info.is_monochrome = info.is_monochrome;
2138 web_screen_info.rect = blink::WebRect(info.rect);
2139 web_screen_info.available_rect = blink::WebRect(info.available_rect);
2140 switch (info.orientation_type) {
2141 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
2142 web_screen_info.orientation_type =
2143 blink::kWebScreenOrientationPortraitPrimary;
2144 break;
2145 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
2146 web_screen_info.orientation_type =
2147 blink::kWebScreenOrientationPortraitSecondary;
2148 break;
2149 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
2150 web_screen_info.orientation_type =
2151 blink::kWebScreenOrientationLandscapePrimary;
2152 break;
2153 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
2154 web_screen_info.orientation_type =
2155 blink::kWebScreenOrientationLandscapeSecondary;
2156 break;
2157 default:
2158 web_screen_info.orientation_type = blink::kWebScreenOrientationUndefined;
2159 break;
2160 }
2161 web_screen_info.orientation_angle = info.orientation_angle;
2162
2163 return web_screen_info;
2164}
2165
[email protected]20657a82012-08-21 20:23:032166#if defined(OS_ANDROID)
braveyao1d8ee7b2017-03-29 21:10:042167void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) {
2168 if (!main_render_frame_)
2169 return;
2170
Chandan Padhi26dbd9b32017-11-27 11:13:352171 MediaStreamDeviceObserver* media_stream_device_observer =
2172 main_render_frame_->GetMediaStreamDeviceObserver();
2173 if (!media_stream_device_observer)
braveyao1d8ee7b2017-03-29 21:10:042174 return;
2175
Guido Urdaneta73fa6632019-01-14 18:46:262176 blink::MediaStreamDevices video_devices =
Chandan Padhi26dbd9b32017-11-27 11:13:352177 media_stream_device_observer->GetNonScreenCaptureDevices();
braveyao1d8ee7b2017-03-29 21:10:042178 RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices(
Chandan Padhi6dbfb732017-09-01 16:08:492179 video_devices, suspend);
braveyao1d8ee7b2017-03-29 21:10:042180}
estade6b9696bd2016-05-04 23:51:362181#endif // defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:032182
[email protected]b283d292013-02-21 08:40:342183unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
2184 return history_list_length_;
2185}
2186
[email protected]cc290f902013-03-04 20:06:022187void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
Nasko Oskova463a052018-05-08 16:42:142188 // If the main frame is remote, return immediately. Page level focus
2189 // should be set from the browser process, so if needed by tests it should
2190 // be properly supported.
2191 if (webview()->MainFrame()->IsWebRemoteFrame())
2192 return;
2193
Albert J. Wong7bbf22d2018-12-20 00:27:272194 if (enable == GetWidget()->has_focus())
danakja2c9d0a92018-07-25 20:01:182195 return;
2196
[email protected]cc290f902013-03-04 20:06:022197 if (enable) {
danakja2c9d0a92018-07-25 20:01:182198 SetActiveForWidget(true);
2199 // Fake an IPC message so go through the IPC handler.
Albert J. Wong7bbf22d2018-12-20 00:27:272200 GetWidget()->OnSetFocus(true);
[email protected]cc290f902013-03-04 20:06:022201 } else {
danakja2c9d0a92018-07-25 20:01:182202 // Fake an IPC message so go through the IPC handler.
Albert J. Wong7bbf22d2018-12-20 00:27:272203 GetWidget()->OnSetFocus(false);
danakja2c9d0a92018-07-25 20:01:182204 SetActiveForWidget(false);
[email protected]cc290f902013-03-04 20:06:022205 }
2206}
2207
W. James MacLeand973a55b2018-11-29 21:39:132208void RenderViewImpl::OnAnimateDoubleTapZoomInMainFrame(
2209 const blink::WebPoint& point,
2210 const blink::WebRect& bound) {
2211 webview()->AnimateDoubleTapZoom(point, bound);
2212}
2213
W. James MacLean5372eb72018-12-19 12:56:362214void RenderViewImpl::OnZoomToFindInPageRect(
2215 const blink::WebRect& rect_to_zoom) {
2216 webview()->ZoomToFindInPageRect(rect_to_zoom);
2217}
2218
danakjd51fd53d2018-12-21 23:06:092219void RenderViewImpl::OnSetBackgroundOpaque(bool opaque) {
2220 if (!webview())
2221 return;
2222
2223 if (opaque) {
2224 webview()->ClearBaseBackgroundColorOverride();
2225 webview()->ClearBackgroundColorOverride();
2226 } else {
2227 webview()->SetBaseBackgroundColorOverride(SK_ColorTRANSPARENT);
2228 webview()->SetBackgroundColorOverride(SK_ColorTRANSPARENT);
2229 }
2230}
2231
danakj295c43f182019-03-13 16:37:172232// static
2233scoped_refptr<base::SingleThreadTaskRunner>
2234RenderViewImpl::GetCleanupTaskRunner() {
2235 return RenderThreadImpl::current_blink_platform_impl()
2236 ->main_thread_scheduler()
2237 ->CleanupTaskRunner();
2238}
2239
[email protected]e9ff79c2012-10-19 21:31:262240} // namespace content