blob: 4a3c760000fca5f53244a03b9a2074991bc0c382 [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"
[email protected]d3b4ee22013-07-24 22:50:0625#include "base/process/kill.h"
[email protected]7d08a9352013-10-15 08:24:5626#include "base/process/process.h"
fdoray7a8954a42016-06-07 04:28:3827#include "base/single_thread_task_runner.h"
danakja4ba7e52018-11-29 23:04:3128#include "base/stl_util.h"
[email protected]21aa99682013-06-11 07:17:0129#include "base/strings/string_number_conversions.h"
[email protected]b9e7c479f2013-04-12 04:33:2430#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4931#include "base/strings/string_split.h"
[email protected]21aa99682013-06-11 07:17:0132#include "base/strings/string_util.h"
[email protected]40d11e02013-03-28 17:43:1433#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0034#include "base/strings/utf_string_conversions.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0335#include "base/system/sys_info.h"
fdoray7a8954a42016-06-07 04:28:3836#include "base/threading/thread_task_runner_handle.h"
[email protected]abb522162013-06-28 01:54:1637#include "base/time/time.h"
primiano9e38d552015-01-28 04:18:0138#include "base/trace_event/trace_event.h"
avi1023d012015-12-25 02:39:1439#include "build/build_config.h"
dongseong.hwange095dfa2016-02-04 11:21:3940#include "cc/base/switches.h"
enne98c9f8052017-03-15 19:38:2241#include "cc/paint/skia_paint_canvas.h"
danakj4c987652018-07-05 15:49:4142#include "cc/trees/layer_tree_host.h"
jinho.bang632a1a722014-09-18 03:02:5643#include "content/common/content_constants_internal.h"
[email protected]59f4f2fa2011-03-23 01:00:5544#include "content/common/drag_messages.h"
[email protected]c6bc20332014-02-28 18:30:3945#include "content/common/frame_messages.h"
alexmosbc7eafa2014-12-06 01:38:0946#include "content/common/frame_replication_state.h"
[email protected]c084330e02013-04-27 01:08:1547#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0748#include "content/common/page_messages.h"
rockot5c478a72016-09-28 23:14:1849#include "content/common/render_message_filter.mojom.h"
[email protected]778574e2011-03-21 22:03:5050#include "content/common/view_messages.h"
[email protected]744c2a22012-03-15 18:42:0451#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4852#include "content/public/common/content_constants.h"
Tarun Bansal73dd2ff82017-10-03 05:29:3453#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2954#include "content/public/common/content_switches.h"
kouhei40f03cb2015-09-24 07:47:0155#include "content/public/common/page_importance_signals.h"
clamyda97e8322014-10-07 21:57:2556#include "content/public/common/page_state.h"
Leon Han963dc182018-11-06 05:41:4857#include "content/public/common/referrer_type_converters.h"
[email protected]818915cd2012-11-20 13:14:1158#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0359#include "content/public/common/url_constants.h"
[email protected]b3a97b52014-07-09 06:25:0560#include "content/public/common/web_preferences.h"
[email protected]d344114c2011-10-01 01:24:3461#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0762#include "content/public/renderer/document_state.h"
Avi Drissman07d22452019-03-25 17:56:3963#include "content/public/renderer/render_thread.h"
[email protected]3a034ebb2011-10-03 19:19:4464#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3665#include "content/public/renderer/render_view_visitor.h"
scottmg8e6c6082017-02-13 23:15:4866#include "content/public/renderer/window_features_converter.h"
[email protected]e6e56752012-08-10 00:46:0667#include "content/renderer/browser_plugin/browser_plugin.h"
Sadrul Habib Chowdhury31c98712018-12-11 04:15:1368#include "content/renderer/compositor/layer_tree_view.h"
[email protected]dc293a72013-07-01 11:11:2269#include "content/renderer/drop_data_builder.h"
[email protected]dc064352014-04-25 08:36:3870#include "content/renderer/history_serialization.h"
[email protected]66fca5bc2013-05-23 06:58:2971#include "content/renderer/ime_event_guard.h"
[email protected]92d457802013-04-01 19:18:4972#include "content/renderer/internal_document_state_data.h"
John Abd-El-Malek6b56ef712017-10-21 22:52:4673#include "content/renderer/loader/request_extra_data.h"
Amos Limbcc710e2018-06-08 05:51:1774#include "content/renderer/media/audio/audio_device_factory.h"
Antonio Gomes78ad6302019-09-19 17:11:3575#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
Patrik Höglundb564859b2018-05-17 11:17:1676#include "content/renderer/media/webrtc/rtc_peer_connection_handler.h"
[email protected]227692c52013-05-31 22:43:0477#include "content/renderer/render_frame_impl.h"
[email protected]5a7100d2014-05-19 01:29:0478#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0579#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4480#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4481#include "content/renderer/render_widget_fullscreen_pepper.h"
danakjcdfc4262019-10-01 20:09:4882#include "content/renderer/render_widget_screen_metrics_emulator.h"
Daniel Murphye3eec92c2018-02-23 19:09:1583#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]12a936d2013-05-15 04:55:4984#include "content/renderer/savable_resources.h"
John Abd-El-Malek312a30bb2017-10-23 19:51:5285#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:2186#include "content/renderer/web_ui_extension_data.h"
[email protected]f5961142013-04-17 23:09:4287#include "media/audio/audio_output_device.h"
[email protected]ee68378a2010-08-10 01:05:4188#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:4489#include "media/media_buildflags.h"
servolkf54f5c8f2015-02-24 20:32:3990#include "media/renderers/audio_renderer_impl.h"
Dale Curtis863022e2017-08-19 02:05:3491#include "media/video/gpu_video_accelerator_factories.h"
Julie Jeongeun Kimcaacf9102019-09-12 02:13:0592#include "mojo/public/cpp/bindings/pending_receiver.h"
[email protected]d1ef81d2012-07-24 11:39:3693#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2994#include "net/base/escape.h"
95#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:0996#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:0497#include "net/http/http_util.h"
Tarun Bansal73d67f02018-01-17 05:56:2598#include "net/nqe/effective_connection_type.h"
Scott Violet02e38b92018-03-27 23:42:1499#include "ppapi/buildflags/buildflags.h"
lukenb171b532014-09-24 05:50:38100#include "skia/ext/platform_canvas.h"
Blink Reformata30d4232018-04-07 15:31:06101#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
Daniel Murphy95792ef2018-10-04 01:29:55102#include "third_party/blink/public/common/dom_storage/session_storage_namespace_id.h"
Mustaq Ahmed76c2f4312018-06-07 20:48:01103#include "third_party/blink/public/common/frame/user_activation_update_source.h"
Blink Reformata30d4232018-04-07 15:31:06104#include "third_party/blink/public/platform/file_path_conversion.h"
Antonio Gomes925f9b92019-07-30 23:23:23105#include "third_party/blink/public/platform/modules/video_capture/web_video_capture_impl_manager.h"
Blink Reformata30d4232018-04-07 15:31:06106#include "third_party/blink/public/platform/url_conversion.h"
107#include "third_party/blink/public/platform/web_connection_type.h"
108#include "third_party/blink/public/platform/web_effective_connection_type.h"
109#include "third_party/blink/public/platform/web_http_body.h"
110#include "third_party/blink/public/platform/web_image.h"
111#include "third_party/blink/public/platform/web_input_event.h"
112#include "third_party/blink/public/platform/web_input_event_result.h"
113#include "third_party/blink/public/platform/web_network_state_notifier.h"
114#include "third_party/blink/public/platform/web_point.h"
115#include "third_party/blink/public/platform/web_rect.h"
116#include "third_party/blink/public/platform/web_runtime_features.h"
117#include "third_party/blink/public/platform/web_size.h"
118#include "third_party/blink/public/platform/web_string.h"
W. James MacLean62198672019-06-04 16:46:10119#include "third_party/blink/public/platform/web_text_autosizer_page_info.h"
Blink Reformata30d4232018-04-07 15:31:06120#include "third_party/blink/public/platform/web_url.h"
121#include "third_party/blink/public/platform/web_url_error.h"
122#include "third_party/blink/public/platform/web_url_request.h"
123#include "third_party/blink/public/platform/web_url_response.h"
124#include "third_party/blink/public/platform/web_vector.h"
125#include "third_party/blink/public/public_buildflags.h"
Guido Urdanetadc7090372019-07-29 17:59:54126#include "third_party/blink/public/web/modules/mediastream/web_media_stream_device_observer.h"
Blink Reformata30d4232018-04-07 15:31:06127#include "third_party/blink/public/web/web_autofill_client.h"
128#include "third_party/blink/public/web/web_ax_object.h"
Blink Reformata30d4232018-04-07 15:31:06129#include "third_party/blink/public/web/web_document.h"
130#include "third_party/blink/public/web/web_dom_event.h"
131#include "third_party/blink/public/web/web_dom_message_event.h"
132#include "third_party/blink/public/web/web_element.h"
Blink Reformata30d4232018-04-07 15:31:06133#include "third_party/blink/public/web/web_form_control_element.h"
134#include "third_party/blink/public/web/web_form_element.h"
135#include "third_party/blink/public/web/web_frame.h"
136#include "third_party/blink/public/web/web_frame_content_dumper.h"
137#include "third_party/blink/public/web/web_frame_widget.h"
138#include "third_party/blink/public/web/web_history_item.h"
139#include "third_party/blink/public/web/web_hit_test_result.h"
140#include "third_party/blink/public/web/web_input_element.h"
141#include "third_party/blink/public/web/web_local_frame.h"
Blink Reformata30d4232018-04-07 15:31:06142#include "third_party/blink/public/web/web_navigation_policy.h"
143#include "third_party/blink/public/web/web_page_importance_signals.h"
danakj25ec6e2b2018-09-26 17:01:31144#include "third_party/blink/public/web/web_page_popup.h"
Blink Reformata30d4232018-04-07 15:31:06145#include "third_party/blink/public/web/web_plugin.h"
146#include "third_party/blink/public/web/web_plugin_action.h"
147#include "third_party/blink/public/web/web_range.h"
148#include "third_party/blink/public/web/web_render_theme.h"
149#include "third_party/blink/public/web/web_script_source.h"
150#include "third_party/blink/public/web/web_searchable_form_data.h"
151#include "third_party/blink/public/web/web_security_policy.h"
152#include "third_party/blink/public/web/web_settings.h"
153#include "third_party/blink/public/web/web_user_gesture_indicator.h"
154#include "third_party/blink/public/web/web_view.h"
155#include "third_party/blink/public/web/web_window_features.h"
[email protected]b3a97b52014-07-09 06:25:05156#include "third_party/icu/source/common/unicode/uchar.h"
157#include "third_party/icu/source/common/unicode/uscript.h"
esecklerf2bd55f72017-03-31 09:11:57158#include "third_party/skia/include/core/SkColor.h"
[email protected]1400e6dc2013-04-27 02:36:27159#include "ui/base/ui_base_switches_util.h"
tfarina655f81d2014-12-23 02:38:50160#include "ui/gfx/geometry/point.h"
tfarina3b0452d2014-12-31 15:20:09161#include "ui/gfx/geometry/rect.h"
162#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32163#include "ui/gfx/geometry/size_conversions.h"
[email protected]08397d52011-02-05 01:53:38164#include "ui/gfx/native_widget_types.h"
ccameron772317d2017-06-04 18:35:03165#include "ui/gfx/switches.h"
mfomitchev3ba450ad2017-04-03 18:20:40166#include "ui/latency/latency_info.h"
csharrisond88f9752016-10-26 23:56:36167#include "url/origin.h"
markdittmer67b71ea2016-03-03 22:40:03168#include "url/url_constants.h"
[email protected]c4a9e932011-03-05 04:05:55169#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:29170
[email protected]25fb9b32012-04-27 03:21:55171#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25172#include <cpu-features.h>
173
dalecurtiscd971252016-09-21 16:09:00174#include "base/android/build_info.h"
kylechare7d8d5c72018-01-05 19:06:28175#include "base/memory/shared_memory.h"
176#include "content/child/child_thread_impl.h"
tfarina3b0452d2014-12-31 15:20:09177#include "ui/gfx/geometry/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40178
[email protected]78043bdd2010-04-05 18:45:33179#elif defined(OS_MACOSX)
180#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57181#endif
182
brettw4b461082016-11-19 18:55:16183#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]ea2fb972013-08-07 05:44:26184#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
185#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26186#endif
187
[email protected]180ef242013-11-07 06:50:46188using blink::WebAXObject;
[email protected]180ef242013-11-07 06:50:46189using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46190using blink::WebData;
[email protected]180ef242013-11-07 06:50:46191using blink::WebDocument;
[email protected]180ef242013-11-07 06:50:46192using blink::WebDragOperation;
[email protected]180ef242013-11-07 06:50:46193using blink::WebElement;
[email protected]180ef242013-11-07 06:50:46194using blink::WebFormControlElement;
195using blink::WebFormElement;
196using blink::WebFrame;
dglazkov03223492016-02-08 22:16:03197using blink::WebFrameContentDumper;
[email protected]180ef242013-11-07 06:50:46198using blink::WebGestureEvent;
199using blink::WebHistoryItem;
200using blink::WebHTTPBody;
dglazkov8d0c21dd2016-08-06 15:56:36201using blink::WebHitTestResult;
[email protected]180ef242013-11-07 06:50:46202using blink::WebImage;
203using blink::WebInputElement;
204using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22205using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46206using blink::WebMouseEvent;
207using blink::WebNavigationPolicy;
208using blink::WebNavigationType;
209using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46210using blink::WebPluginAction;
[email protected]180ef242013-11-07 06:50:46211using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46212using blink::WebRect;
Daniel Chengd5e56ff2017-06-24 07:44:02213using blink::WebSandboxFlags;
[email protected]180ef242013-11-07 06:50:46214using blink::WebScriptSource;
215using blink::WebSearchableFormData;
216using blink::WebSecurityOrigin;
217using blink::WebSecurityPolicy;
[email protected]180ef242013-11-07 06:50:46218using blink::WebSettings;
219using blink::WebSize;
[email protected]180ef242013-11-07 06:50:46220using blink::WebString;
[email protected]180ef242013-11-07 06:50:46221using blink::WebTextDirection;
222using blink::WebTouchEvent;
223using blink::WebURL;
224using blink::WebURLError;
225using blink::WebURLRequest;
226using blink::WebURLResponse;
227using blink::WebUserGestureIndicator;
228using blink::WebVector;
229using blink::WebView;
230using blink::WebWidget;
231using blink::WebWindowFeatures;
[email protected]b3a97b52014-07-09 06:25:05232using blink::WebRuntimeFeatures;
[email protected]e1acf6f2008-10-27 20:43:33233
[email protected]e9ff79c2012-10-19 21:31:26234namespace content {
235
initial.commit09911bf2008-07-26 23:55:29236//-----------------------------------------------------------------------------
237
[email protected]180ef242013-11-07 06:50:46238typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
jbroman8319b232017-03-08 22:53:29239static base::LazyInstance<ViewMap>::Leaky g_view_map =
[email protected]058561b2012-12-03 06:48:22240 LAZY_INSTANCE_INITIALIZER;
scottmg5e65e3a2017-03-08 08:48:46241typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap;
jbroman8319b232017-03-08 22:53:29242static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map =
243 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02244
[email protected]882daa92009-11-05 16:31:31245// Time, in seconds, we delay before sending content state changes (such as form
246// state and scroll position) to the browser. We delay sending changes to avoid
247// spamming the browser.
248// To avoid having tab/session restore require sending a message to get the
249// current content state during tab closing we use a shorter timeout for the
250// foreground renderer. This means there is a small window of time from which
251// content state is modified and not sent to session restore, but this is
252// better than having to wake up all renderers during shutdown.
avif937e1d2014-11-02 18:13:07253const int kDelaySecondsForContentStateSyncHidden = 5;
254const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29255
dcheng35d31c112015-07-22 00:17:36256static RenderViewImpl* (*g_create_render_view_impl)(
257 CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15258 const mojom::CreateViewParams&) = nullptr;
[email protected]8d41d7612012-11-14 20:32:19259
[email protected]c6bc20332014-02-28 18:30:39260// static
[email protected]e507045d2013-07-24 15:23:44261Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56262 WebFrame* frame,
263 const WebURLRequest& request) {
Blink Reformat1c4d759e2017-04-09 16:34:54264 return Referrer(blink::WebStringToGURL(
265 request.HttpHeaderField(WebString::FromUTF8("Referer"))),
266 request.GetReferrerPolicy());
[email protected]44e55b012013-07-23 14:21:56267}
268
[email protected]c6bc20332014-02-28 18:30:39269// static
[email protected]65920f332014-03-04 21:14:18270WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32271 WebNavigationPolicy policy) {
272 switch (policy) {
Blink Reformat1c4d759e2017-04-09 16:34:54273 case blink::kWebNavigationPolicyDownload:
nick3b04f322016-08-31 19:29:19274 return WindowOpenDisposition::SAVE_TO_DISK;
Blink Reformat1c4d759e2017-04-09 16:34:54275 case blink::kWebNavigationPolicyCurrentTab:
nick3b04f322016-08-31 19:29:19276 return WindowOpenDisposition::CURRENT_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54277 case blink::kWebNavigationPolicyNewBackgroundTab:
nick3b04f322016-08-31 19:29:19278 return WindowOpenDisposition::NEW_BACKGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54279 case blink::kWebNavigationPolicyNewForegroundTab:
nick3b04f322016-08-31 19:29:19280 return WindowOpenDisposition::NEW_FOREGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54281 case blink::kWebNavigationPolicyNewWindow:
nick3b04f322016-08-31 19:29:19282 return WindowOpenDisposition::NEW_WINDOW;
Blink Reformat1c4d759e2017-04-09 16:34:54283 case blink::kWebNavigationPolicyNewPopup:
nick3b04f322016-08-31 19:29:19284 return WindowOpenDisposition::NEW_POPUP;
[email protected]48861e22013-01-09 00:27:32285 default:
286 NOTREACHED() << "Unexpected WebNavigationPolicy";
nick3b04f322016-08-31 19:29:19287 return WindowOpenDisposition::IGNORE_ACTION;
[email protected]48861e22013-01-09 00:27:32288 }
289}
290
initial.commit09911bf2008-07-26 23:55:29291///////////////////////////////////////////////////////////////////////////////
292
[email protected]217690d2012-01-27 07:33:11293namespace {
294
[email protected]b3a97b52014-07-09 06:25:05295typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
296 const base::string16&,
297 UScriptCode);
298
299void SetStandardFontFamilyWrapper(WebSettings* settings,
300 const base::string16& font,
301 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54302 settings->SetStandardFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05303}
304
305void SetFixedFontFamilyWrapper(WebSettings* settings,
306 const base::string16& font,
307 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54308 settings->SetFixedFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05309}
310
311void SetSerifFontFamilyWrapper(WebSettings* settings,
312 const base::string16& font,
313 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54314 settings->SetSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05315}
316
317void SetSansSerifFontFamilyWrapper(WebSettings* settings,
318 const base::string16& font,
319 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54320 settings->SetSansSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05321}
322
323void SetCursiveFontFamilyWrapper(WebSettings* settings,
324 const base::string16& font,
325 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54326 settings->SetCursiveFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05327}
328
329void SetFantasyFontFamilyWrapper(WebSettings* settings,
330 const base::string16& font,
331 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54332 settings->SetFantasyFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05333}
334
335void SetPictographFontFamilyWrapper(WebSettings* settings,
336 const base::string16& font,
337 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54338 settings->SetPictographFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05339}
340
341// If |scriptCode| is a member of a family of "similar" script codes, returns
342// the script code in that family that is used by WebKit for font selection
343// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
344// considered equivalent for the purposes of font selection. WebKit uses the
345// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
346// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
347// uses different scripts than the ones in Chrome pref names because the version
348// of ICU included on certain ports does not have some of the newer scripts. If
349// |scriptCode| is not a member of such a family, returns |scriptCode|.
350UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
351 switch (scriptCode) {
352 case USCRIPT_HIRAGANA:
353 case USCRIPT_KATAKANA:
354 case USCRIPT_JAPANESE:
355 return USCRIPT_KATAKANA_OR_HIRAGANA;
356 case USCRIPT_KOREAN:
357 return USCRIPT_HANGUL;
358 default:
359 return scriptCode;
360 }
361}
362
363void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
364 SetFontFamilyWrapper setter,
365 WebSettings* settings) {
jdoerrie5a73d0fa2018-10-02 23:54:05366 for (auto it = map.begin(); it != map.end(); ++it) {
avi1023d012015-12-25 02:39:14367 int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
[email protected]b3a97b52014-07-09 06:25:05368 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
369 UScriptCode code = static_cast<UScriptCode>(script);
370 (*setter)(settings, it->second, GetScriptForWebSettings(code));
371 }
372 }
373}
374
danakjefcb8432019-01-16 18:47:14375void ApplyCommandLineToSettings(WebSettings* settings) {
376 const base::CommandLine& command_line =
377 *base::CommandLine::ForCurrentProcess();
378
danakjed9464612019-01-16 00:00:59379 settings->SetThreadedScrollingEnabled(
380 !command_line.HasSwitch(switches::kDisableThreadedScrolling));
wangxianzhu3bf39be52015-04-10 23:56:41381
danakjed9464612019-01-16 00:00:59382 if (switches::IsTouchDragDropEnabled())
383 settings->SetTouchDragDropEnabled(true);
384
385 WebSettings::SelectionStrategyType selection_strategy;
386 if (command_line.GetSwitchValueASCII(switches::kTouchTextSelectionStrategy) ==
387 "direction")
388 selection_strategy = WebSettings::SelectionStrategyType::kDirection;
389 else
390 selection_strategy = WebSettings::SelectionStrategyType::kCharacter;
391 settings->SetSelectionStrategy(selection_strategy);
392
393 std::string passive_listeners_default =
394 command_line.GetSwitchValueASCII(switches::kPassiveListenersDefault);
395 if (!passive_listeners_default.empty()) {
396 WebSettings::PassiveEventListenerDefault passive_default =
397 WebSettings::PassiveEventListenerDefault::kFalse;
398 if (passive_listeners_default == "true")
399 passive_default = WebSettings::PassiveEventListenerDefault::kTrue;
400 else if (passive_listeners_default == "forcealltrue")
401 passive_default = WebSettings::PassiveEventListenerDefault::kForceAllTrue;
402 settings->SetPassiveEventListenerDefault(passive_default);
403 }
404
405 std::string network_quiet_timeout =
406 command_line.GetSwitchValueASCII(switches::kNetworkQuietTimeout);
407 if (!network_quiet_timeout.empty()) {
408 double network_quiet_timeout_seconds = 0.0;
409 if (base::StringToDouble(network_quiet_timeout,
410 &network_quiet_timeout_seconds))
411 settings->SetNetworkQuietTimeout(network_quiet_timeout_seconds);
412 }
413
414 if (command_line.HasSwitch(switches::kBlinkSettings)) {
415 std::vector<std::string> blink_settings = base::SplitString(
416 command_line.GetSwitchValueASCII(switches::kBlinkSettings), ",",
417 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
418 for (const std::string& setting : blink_settings) {
419 size_t pos = setting.find('=');
420 settings->SetFromStrings(
421 blink::WebString::FromLatin1(setting.substr(0, pos)),
422 blink::WebString::FromLatin1(
423 pos == std::string::npos ? "" : setting.substr(pos + 1)));
424 }
wangxianzhu3bf39be52015-04-10 23:56:41425 }
426}
427
scottmgde42fb92017-02-10 17:56:03428content::mojom::WindowContainerType WindowFeaturesToContainerType(
scottmg05324cb2017-02-09 23:46:04429 const blink::WebWindowFeatures& window_features) {
japhetbfc47892017-06-02 23:01:19430 if (window_features.background) {
431 if (window_features.persistent)
scottmgde42fb92017-02-10 17:56:03432 return content::mojom::WindowContainerType::PERSISTENT;
scottmg05324cb2017-02-09 23:46:04433 else
scottmgde42fb92017-02-10 17:56:03434 return content::mojom::WindowContainerType::BACKGROUND;
scottmg05324cb2017-02-09 23:46:04435 } else {
scottmgde42fb92017-02-10 17:56:03436 return content::mojom::WindowContainerType::NORMAL;
scottmg05324cb2017-02-09 23:46:04437 }
438}
439
Ahmed Fakhry58e6ef542018-09-04 18:05:38440// Check content::BrowserControlsState, and cc::BrowserControlsState
441// are kept in sync.
442static_assert(int(BROWSER_CONTROLS_STATE_SHOWN) ==
443 int(cc::BrowserControlsState::kShown),
444 "mismatching enums: SHOWN");
445static_assert(int(BROWSER_CONTROLS_STATE_HIDDEN) ==
446 int(cc::BrowserControlsState::kHidden),
447 "mismatching enums: HIDDEN");
448static_assert(int(BROWSER_CONTROLS_STATE_BOTH) ==
449 int(cc::BrowserControlsState::kBoth),
450 "mismatching enums: BOTH");
451
452cc::BrowserControlsState ContentToCc(BrowserControlsState state) {
453 return static_cast<cc::BrowserControlsState>(state);
454}
Ahmed Fakhry58e6ef542018-09-04 18:05:38455
[email protected]217690d2012-01-27 07:33:11456} // namespace
457
Hajime Hoshi315a61f2018-08-14 17:27:28458RenderViewImpl::RenderViewImpl(CompositorDependencies* compositor_deps,
459 const mojom::CreateViewParams& params)
Albert J. Wong7faa3da2019-03-21 20:43:43460 : routing_id_(params.view_id),
danakj73dd3032018-07-28 17:49:53461 renderer_wide_named_frame_lookup_(
462 params.renderer_wide_named_frame_lookup),
naskobd911332014-11-25 01:13:36463 webkit_preferences_(params.web_preferences),
Erik Chena65fa752019-09-21 06:59:40464 page_properties_(compositor_deps),
Jeremy Roman3bca4bf2019-07-11 03:41:25465 session_storage_namespace_id_(params.session_storage_namespace_id) {
Daniel Murphy95792ef2018-10-04 01:29:55466 DCHECK(!session_storage_namespace_id_.empty())
467 << "Session storage namespace must be populated.";
Albert J. Wong7faa3da2019-03-21 20:43:43468 // Please put all logic in RenderViewImpl::Initialize().
469}
Albert J. Wong7bbf22d2018-12-20 00:27:27470
Albert J. Wong7faa3da2019-03-21 20:43:43471void RenderViewImpl::Initialize(
Erik Chen10e9b022019-08-21 23:33:23472 CompositorDependencies* compositor_deps,
Albert J. Wong7faa3da2019-03-21 20:43:43473 mojom::CreateViewParamsPtr params,
474 RenderWidget::ShowCallback show_callback,
475 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Avi Drissman07d22452019-03-25 17:56:39476 DCHECK(RenderThread::IsMainThread());
477
Albert J. Wongcb004632018-07-10 22:58:25478 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]075366912013-02-18 07:13:24479
nickf7b38222016-11-22 21:59:35480#if defined(OS_ANDROID)
danakjc87bfede2018-10-10 22:32:49481 bool has_show_callback = !!show_callback;
nickf7b38222016-11-22 21:59:35482#endif
[email protected]676126f72011-01-15 00:03:51483
Albert J. Wonga3dbd5442019-09-18 10:38:28484 page_properties()->SetScreenInfo(params->visual_properties.screen_info);
485
Lukasz Anforowiczaf2f33572018-01-17 14:05:08486 WebFrame* opener_frame =
487 RenderFrameImpl::ResolveOpener(params->opener_frame_route_id);
488
Erik Chen562ca42b2019-08-22 19:46:06489 // The newly created webview_ is owned by this instance.
danakj284d557d2019-01-16 17:00:26490 webview_ = WebView::Create(this, params->hidden,
Sadrul Habib Chowdhury042a4712018-12-06 00:16:56491 /*compositing_enabled=*/true,
danakja4ba7e52018-11-29 23:04:31492 opener_frame ? opener_frame->View() : nullptr);
Albert J. Wong2727e8a82019-02-15 16:56:11493
nasko4c0feb62015-06-05 18:37:06494 g_view_map.Get().insert(std::make_pair(webview(), this));
avia3dca182016-03-19 01:09:52495 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this));
nasko4c0feb62015-06-05 18:37:06496
danakj505476792019-01-11 23:53:46497 webview()->SetDisplayMode(params->visual_properties.display_mode);
dcheng0ff94cfc2016-03-15 21:50:51498
danakjfd0c7f42018-10-12 18:01:08499 ApplyWebPreferences(webkit_preferences_, webview());
danakjefcb8432019-01-16 18:47:14500 ApplyCommandLineToSettings(webview()->GetSettings());
dcheng0ff94cfc2016-03-15 21:50:51501
danakjaf29226f2018-09-25 17:56:57502 // We have either a main frame or a proxy routing id.
503 DCHECK_NE(params->main_frame_routing_id != MSG_ROUTING_NONE,
504 params->proxy_routing_id != MSG_ROUTING_NONE);
505
Balazs Engedyba034e72017-10-27 22:26:28506 if (params->main_frame_routing_id != MSG_ROUTING_NONE) {
dcheng3ce04b62015-10-26 23:30:55507 main_render_frame_ = RenderFrameImpl::CreateMainFrame(
Erik Chen10e9b022019-08-21 23:33:23508 this, compositor_deps, opener_frame, &params, std::move(show_callback));
danakjaf29226f2018-09-25 17:56:57509 } else {
Erik Chen10e9b022019-08-21 23:33:23510 // TODO(https://crbug.com/995981): We should not need to create a
511 // RenderWidget for a remote main frame.
512 render_widget_ = RenderWidget::CreateForFrame(
513 params->main_frame_widget_routing_id, compositor_deps,
Albert J. Wonga3dbd5442019-09-18 10:38:28514 page_properties(), params->visual_properties.display_mode,
danakj872a96a12019-09-18 21:53:14515 /*is_undead=*/true, params->never_visible);
516 render_widget_->set_delegate(this);
Erik Chena2819852019-08-28 01:02:28517 // We intentionally pass in a null webwidget since it shouldn't be needed
518 // for remote frames.
danakj872a96a12019-09-18 21:53:14519 render_widget_->InitForMainFrame(std::move(show_callback),
520 /*web_frame_widget=*/nullptr);
Erik Chen10e9b022019-08-21 23:33:23521
Balazs Engedyba034e72017-10-27 22:26:28522 RenderFrameProxy::CreateFrameProxy(params->proxy_routing_id, GetRoutingID(),
nick3b5a21f2016-11-22 23:07:11523 opener_frame, MSG_ROUTING_NONE,
Dmitry Gozman89361212018-02-13 16:10:44524 params->replicated_frame_state,
525 params->devtools_main_frame_token);
nasko4c0feb62015-06-05 18:37:06526 }
527
[email protected]c7c0d822014-04-16 20:19:49528 // TODO(davidben): Move this state from Blink into content.
Balazs Engedyba034e72017-10-27 22:26:28529 if (params->window_was_created_with_opener)
Blink Reformat1c4d759e2017-04-09 16:34:54530 webview()->SetOpenedByDOM();
[email protected]c7c0d822014-04-16 20:19:49531
Leon Han2c81b5d2019-01-25 01:58:33532 OnSetRendererPrefs(*params->renderer_preferences);
[email protected]1784b2f2011-11-24 10:53:48533
[email protected]e9ff79c2012-10-19 21:31:26534 GetContentClient()->renderer()->RenderViewCreated(this);
akabac6bd1212018-06-25 20:10:48535 page_zoom_level_ = 0;
Hajime Hoshif34374412018-03-05 14:32:54536
537 nav_state_sync_timer_.SetTaskRunner(task_runner);
danakjc87bfede2018-10-10 22:32:49538
Adithya Srinivasan46b8a792019-02-01 14:47:23539 // We pass this state to Page, but it's only used by the main frame in the
540 // page.
541 if (params->inside_portal)
542 webview()->SetInsidePortal(true);
543
danakjc87bfede2018-10-10 22:32:49544#if defined(OS_ANDROID)
545 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated
546 // HandleNavigation codepath.
547 // Renderer-created RenderViews have a ShowCallback because they send a Show
548 // request (ViewHostMsg_ShowWidget, ViewHostMsg_ShowFullscreenWidget, or
549 // FrameHostMsg_ShowCreatedWindow) to the browser to attach them to the UI
550 // there. Browser-created RenderViews do not send a Show request to the
551 // browser, so have no such callback.
552 was_created_by_renderer_ = has_show_callback;
553#endif
initial.commit09911bf2008-07-26 23:55:29554}
555
[email protected]310ebd6302011-10-10 19:06:28556RenderViewImpl::~RenderViewImpl() {
danakjcdfc4262019-10-01 20:09:48557 DCHECK(destroying_); // Always deleted through Destroy().
dcheng3ce04b62015-10-26 23:30:55558 DCHECK(!frame_widget_);
danakjcdfc4262019-10-01 20:09:48559
560 g_routing_id_view_map.Get().erase(routing_id_);
Albert J. Wongcb004632018-07-10 22:58:25561 RenderThread::Get()->RemoveRoute(routing_id_);
dcheng3ce04b62015-10-26 23:30:55562
[email protected]60c42a8c72009-10-09 04:08:59563#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22564 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49565 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59566 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
567 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22568 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
569 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
570 it != routing_id_views->end(); ++it)
571 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59572#endif
[email protected]676126f72011-01-15 00:03:51573
ericwilligers88e69742016-10-17 19:29:55574 for (auto& observer : observers_)
575 observer.RenderViewGone();
576 for (auto& observer : observers_)
577 observer.OnDestruct();
[email protected]60c42a8c72009-10-09 04:08:59578}
579
580/*static*/
[email protected]310ebd6302011-10-10 19:06:28581RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
Avi Drissman07d22452019-03-25 17:56:39582 DCHECK(RenderThread::IsMainThread());
[email protected]a2ef54c2011-10-10 16:20:31583 ViewMap* views = g_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05584 auto it = views->find(webview);
[email protected]a2ef54c2011-10-10 16:20:31585 return it == views->end() ? NULL : it->second;
586}
587
588/*static*/
[email protected]180ef242013-11-07 06:50:46589RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28590 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31591}
592
593/*static*/
avi1023d012015-12-25 02:39:14594RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) {
Avi Drissman07d22452019-03-25 17:56:39595 DCHECK(RenderThread::IsMainThread());
[email protected]640e303c2012-12-05 01:36:07596 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05597 auto it = views->find(routing_id);
[email protected]640e303c2012-12-05 01:36:07598 return it == views->end() ? NULL : it->second;
599}
600
601/*static*/
602RenderView* RenderView::FromRoutingID(int routing_id) {
603 return RenderViewImpl::FromRoutingID(routing_id);
604}
605
[email protected]f3a95312014-06-12 16:46:58606/* static */
jochen9c7b8f242015-06-01 15:32:02607size_t RenderView::GetRenderViewCount() {
[email protected]f3a95312014-06-12 16:46:58608 return g_view_map.Get().size();
609}
610
[email protected]640e303c2012-12-05 01:36:07611/*static*/
[email protected]e9ff79c2012-10-19 21:31:26612void RenderView::ForEach(RenderViewVisitor* visitor) {
Avi Drissman07d22452019-03-25 17:56:39613 DCHECK(RenderThread::IsMainThread());
[email protected]625332e02010-12-14 07:48:49614 ViewMap* views = g_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05615 for (auto it = views->begin(); it != views->end(); ++it) {
[email protected]60c42a8c72009-10-09 04:08:59616 if (!visitor->Visit(it->second))
617 return;
618 }
619}
620
621/*static*/
[email protected]b3a97b52014-07-09 06:25:05622void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
623 WebView* web_view) {
Blink Reformat1c4d759e2017-04-09 16:34:54624 WebSettings* settings = web_view->GetSettings();
[email protected]b3a97b52014-07-09 06:25:05625 ApplyFontsFromMap(prefs.standard_font_family_map,
626 SetStandardFontFamilyWrapper, settings);
627 ApplyFontsFromMap(prefs.fixed_font_family_map,
628 SetFixedFontFamilyWrapper, settings);
629 ApplyFontsFromMap(prefs.serif_font_family_map,
630 SetSerifFontFamilyWrapper, settings);
631 ApplyFontsFromMap(prefs.sans_serif_font_family_map,
632 SetSansSerifFontFamilyWrapper, settings);
633 ApplyFontsFromMap(prefs.cursive_font_family_map,
634 SetCursiveFontFamilyWrapper, settings);
635 ApplyFontsFromMap(prefs.fantasy_font_family_map,
636 SetFantasyFontFamilyWrapper, settings);
637 ApplyFontsFromMap(prefs.pictograph_font_family_map,
638 SetPictographFontFamilyWrapper, settings);
Blink Reformat1c4d759e2017-04-09 16:34:54639 settings->SetDefaultFontSize(prefs.default_font_size);
640 settings->SetDefaultFixedFontSize(prefs.default_fixed_font_size);
641 settings->SetMinimumFontSize(prefs.minimum_font_size);
642 settings->SetMinimumLogicalFontSize(prefs.minimum_logical_font_size);
643 settings->SetDefaultTextEncodingName(
644 WebString::FromASCII(prefs.default_encoding));
645 settings->SetJavaScriptEnabled(prefs.javascript_enabled);
646 settings->SetWebSecurityEnabled(prefs.web_security_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54647 settings->SetLoadsImagesAutomatically(prefs.loads_images_automatically);
648 settings->SetImagesEnabled(prefs.images_enabled);
649 settings->SetPluginsEnabled(prefs.plugins_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54650 settings->SetDOMPasteAllowed(prefs.dom_paste_enabled);
651 settings->SetTextAreasAreResizable(prefs.text_areas_are_resizable);
652 settings->SetAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
653 settings->SetDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
654 settings->SetJavaScriptCanAccessClipboard(
[email protected]b3a97b52014-07-09 06:25:05655 prefs.javascript_can_access_clipboard);
Chris Cunninghame9b5ad742019-04-23 19:40:38656 WebRuntimeFeatures::EnableXSLT(prefs.xslt_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54657 settings->SetDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
Tarun Bansal333819e2018-05-15 16:38:42658 blink::WebNetworkStateNotifier::SetSaveDataEnabled(prefs.data_saver_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54659 settings->SetLocalStorageEnabled(prefs.local_storage_enabled);
660 settings->SetSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
661 WebRuntimeFeatures::EnableDatabase(prefs.databases_enabled);
662 settings->SetOfflineWebApplicationCacheEnabled(
[email protected]b3a97b52014-07-09 06:25:05663 prefs.application_cache_enabled);
Arthur Sonzogni721f48e2018-10-31 17:10:02664 settings->SetShouldProtectAgainstIpcFlooding(
665 !prefs.disable_ipc_flooding_protection);
Blink Reformat1c4d759e2017-04-09 16:34:54666 settings->SetHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
667 settings->SetCookieEnabled(prefs.cookie_enabled);
668 settings->SetNavigateOnDragDrop(prefs.navigate_on_drag_drop);
[email protected]b3a97b52014-07-09 06:25:05669
[email protected]b3a97b52014-07-09 06:25:05670 // By default, allow_universal_access_from_file_urls is set to false and thus
671 // we mitigate attacks from local HTML files by not granting file:// URLs
672 // universal access. Only test shell will enable this.
Blink Reformat1c4d759e2017-04-09 16:34:54673 settings->SetAllowUniversalAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05674 prefs.allow_universal_access_from_file_urls);
Blink Reformat1c4d759e2017-04-09 16:34:54675 settings->SetAllowFileAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05676 prefs.allow_file_access_from_file_urls);
677
Zhenyao Moa3fda9972017-09-16 01:34:40678 settings->SetWebGL1Enabled(prefs.webgl1_enabled);
679 settings->SetWebGL2Enabled(prefs.webgl2_enabled);
[email protected]b3a97b52014-07-09 06:25:05680
[email protected]b3a97b52014-07-09 06:25:05681 // Enable WebGL errors to the JS console if requested.
Blink Reformat1c4d759e2017-04-09 16:34:54682 settings->SetWebGLErrorsToConsoleEnabled(
[email protected]b3a97b52014-07-09 06:25:05683 prefs.webgl_errors_to_console_enabled);
684
685 // Uses the mock theme engine for scrollbars.
Blink Reformat1c4d759e2017-04-09 16:34:54686 settings->SetMockScrollbarsEnabled(prefs.mock_scrollbars_enabled);
[email protected]b3a97b52014-07-09 06:25:05687
Blink Reformat1c4d759e2017-04-09 16:34:54688 settings->SetHideScrollbars(prefs.hide_scrollbars);
eseckler61ff9142016-09-23 22:57:59689
[email protected]b3a97b52014-07-09 06:25:05690 // Enable gpu-accelerated 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54691 WebRuntimeFeatures::EnableAccelerated2dCanvas(
junov524668f22016-08-08 20:16:52692 prefs.accelerated_2d_canvas_enabled);
[email protected]b3a97b52014-07-09 06:25:05693
[email protected]b3a97b52014-07-09 06:25:05694 // Disable antialiasing for 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54695 settings->SetAntialiased2dCanvasEnabled(
[email protected]b3a97b52014-07-09 06:25:05696 !prefs.antialiased_2d_canvas_disabled);
697
zakerinasab20ebca02016-09-27 14:22:34698 // Disable antialiasing of clips for 2d canvas if requested on the command
robertphillipse25137b2014-10-20 13:44:34699 // line.
Blink Reformat1c4d759e2017-04-09 16:34:54700 settings->SetAntialiasedClips2dCanvasEnabled(
robertphillipse25137b2014-10-20 13:44:34701 prefs.antialiased_clips_2d_canvas_enabled);
702
[email protected]b3a97b52014-07-09 06:25:05703 // Set MSAA sample count for 2d canvas if requested on the command line (or
704 // default value if not).
Blink Reformat1c4d759e2017-04-09 16:34:54705 settings->SetAccelerated2dCanvasMSAASampleCount(
[email protected]b3a97b52014-07-09 06:25:05706 prefs.accelerated_2d_canvas_msaa_sample_count);
707
[email protected]b3a97b52014-07-09 06:25:05708 // Tabs to link is not part of the settings. WebCore calls
709 // ChromeClient::tabsToLinks which is part of the glue code.
Blink Reformat1c4d759e2017-04-09 16:34:54710 web_view->SetTabsToLinks(prefs.tabs_to_links);
[email protected]b3a97b52014-07-09 06:25:05711
Blink Reformat1c4d759e2017-04-09 16:34:54712 settings->SetAllowRunningOfInsecureContent(
[email protected]b3a97b52014-07-09 06:25:05713 prefs.allow_running_insecure_content);
Blink Reformat1c4d759e2017-04-09 16:34:54714 settings->SetDisableReadingFromCanvas(prefs.disable_reading_from_canvas);
715 settings->SetStrictMixedContentChecking(prefs.strict_mixed_content_checking);
mkwst2384c8222015-07-30 07:26:47716
Blink Reformat1c4d759e2017-04-09 16:34:54717 settings->SetStrictlyBlockBlockableMixedContent(
mkwst2384c8222015-07-30 07:26:47718 prefs.strictly_block_blockable_mixed_content);
719
Blink Reformat1c4d759e2017-04-09 16:34:54720 settings->SetStrictMixedContentCheckingForPlugin(
mkwst0d233e52015-08-10 09:33:14721 prefs.block_mixed_plugin_content);
722
Blink Reformat1c4d759e2017-04-09 16:34:54723 settings->SetStrictPowerfulFeatureRestrictions(
mkwst673a452f2015-01-10 14:41:50724 prefs.strict_powerful_feature_restrictions);
Blink Reformat1c4d759e2017-04-09 16:34:54725 settings->SetAllowGeolocationOnInsecureOrigins(
jww9d4ca2d2016-01-19 20:58:59726 prefs.allow_geolocation_on_insecure_origins);
Blink Reformat1c4d759e2017-04-09 16:34:54727 settings->SetPasswordEchoEnabled(prefs.password_echo_enabled);
728 settings->SetShouldPrintBackgrounds(prefs.should_print_backgrounds);
729 settings->SetShouldClearDocumentBackground(
[email protected]b3a97b52014-07-09 06:25:05730 prefs.should_clear_document_background);
Blink Reformat1c4d759e2017-04-09 16:34:54731 settings->SetEnableScrollAnimator(prefs.enable_scroll_animator);
Stephen McGruerbc3d0e62019-01-23 17:40:19732 settings->SetPrefersReducedMotion(prefs.prefers_reduced_motion);
[email protected]b3a97b52014-07-09 06:25:05733
Blink Reformat1c4d759e2017-04-09 16:34:54734 WebRuntimeFeatures::EnableTouchEventFeatureDetection(
sunyunjiafa6a8afc2016-12-09 04:25:47735 prefs.touch_event_feature_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54736 settings->SetMaxTouchPoints(prefs.pointer_events_max_touch_points);
737 settings->SetAvailablePointerTypes(prefs.available_pointer_types);
738 settings->SetPrimaryPointerType(
nzolghadrc0d1663c2015-11-26 21:15:24739 static_cast<blink::PointerType>(prefs.primary_pointer_type));
Blink Reformat1c4d759e2017-04-09 16:34:54740 settings->SetAvailableHoverTypes(prefs.available_hover_types);
741 settings->SetPrimaryHoverType(
nzolghadrc0d1663c2015-11-26 21:15:24742 static_cast<blink::HoverType>(prefs.primary_hover_type));
Blink Reformat1c4d759e2017-04-09 16:34:54743 settings->SetEnableTouchAdjustment(prefs.touch_adjustment_enabled);
Dave Tapuskaa59fdb62017-08-23 16:28:27744 settings->SetBarrelButtonForDragEnabled(prefs.barrel_button_for_drag_enabled);
[email protected]b3a97b52014-07-09 06:25:05745
Blink Reformat1c4d759e2017-04-09 16:34:54746 settings->SetShouldRespectImageOrientation(
[email protected]b3a97b52014-07-09 06:25:05747 prefs.should_respect_image_orientation);
748
Blink Reformat1c4d759e2017-04-09 16:34:54749 settings->SetEditingBehavior(
[email protected]b3a97b52014-07-09 06:25:05750 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
751
Blink Reformat1c4d759e2017-04-09 16:34:54752 settings->SetSupportsMultipleWindows(prefs.supports_multiple_windows);
[email protected]b3a97b52014-07-09 06:25:05753
Blink Reformat1c4d759e2017-04-09 16:34:54754 settings->SetMainFrameClipsContent(!prefs.record_whole_document);
khushalsagar2da2b232016-03-23 22:11:35755
Blink Reformat1c4d759e2017-04-09 16:34:54756 settings->SetSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
[email protected]b3a97b52014-07-09 06:25:05757
Blink Reformat1c4d759e2017-04-09 16:34:54758 settings->SetSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
Hugo Holgersson943ae692019-01-10 10:04:14759 // Spatnav depends on KeyboardFocusableScrollers. The WebUI team has
760 // disabled KFS because they need more time to update their custom elements,
761 // crbug.com/907284. Meanwhile, we pre-ship KFS to spatnav users.
762 if (prefs.spatial_navigation_enabled)
763 WebRuntimeFeatures::EnableKeyboardFocusableScrollers(true);
[email protected]b3a97b52014-07-09 06:25:05764
Bruce Long015d96f2019-07-12 22:59:10765 settings->SetCaretBrowsingEnabled(prefs.caret_browsing_enabled);
766
Blink Reformat1c4d759e2017-04-09 16:34:54767 settings->SetSelectionIncludesAltImageText(true);
[email protected]b3a97b52014-07-09 06:25:05768
Blink Reformat1c4d759e2017-04-09 16:34:54769 settings->SetV8CacheOptions(
[email protected]35103c02014-08-12 15:08:47770 static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options));
771
Blink Reformat1c4d759e2017-04-09 16:34:54772 settings->SetImageAnimationPolicy(
je_julie.kim7fbb5a1a2015-02-09 17:26:05773 static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy));
774
Blink Reformat1c4d759e2017-04-09 16:34:54775 settings->SetPresentationRequiresUserGesture(
zqzhang1215ad422016-02-10 13:27:22776 prefs.user_gesture_required_for_presentation);
777
Elly Fong-Jonesf92897392019-01-24 16:05:49778 settings->SetTextTrackBackgroundColor(
779 WebString::FromASCII(prefs.text_track_background_color));
780 settings->SetTextTrackTextColor(
781 WebString::FromASCII(prefs.text_track_text_color));
Rahul Singh1862faa92019-03-06 22:41:43782 settings->SetTextTrackTextSize(
783 WebString::FromASCII(prefs.text_track_text_size));
784 settings->SetTextTrackTextShadow(
785 WebString::FromASCII(prefs.text_track_text_shadow));
786 settings->SetTextTrackFontFamily(
787 WebString::FromASCII(prefs.text_track_font_family));
788 settings->SetTextTrackFontVariant(
789 WebString::FromASCII(prefs.text_track_font_variant));
Blink Reformat1c4d759e2017-04-09 16:34:54790 settings->SetTextTrackMarginPercentage(prefs.text_track_margin_percentage);
Abigail Klein74de85bd2019-07-11 19:11:56791 settings->SetTextTrackWindowColor(
792 WebString::FromASCII(prefs.text_track_window_color));
793 settings->SetTextTrackWindowPadding(
794 WebString::FromASCII(prefs.text_track_window_padding));
795 settings->SetTextTrackWindowRadius(
796 WebString::FromASCII(prefs.text_track_window_radius));
halliwell4002be42016-03-18 18:33:40797
David Bokana03511a92018-09-13 04:25:24798 // Needs to happen before SetDefaultPageScaleLimits below since that'll
799 // recalculate the final page scale limits and that depends on this setting.
800 settings->SetShrinksViewportContentToFit(
801 prefs.shrinks_viewport_contents_to_fit);
802
803 // Needs to happen before SetIgnoreViewportTagScaleLimits below.
Blink Reformat1c4d759e2017-04-09 16:34:54804 web_view->SetDefaultPageScaleLimits(prefs.default_minimum_page_scale_factor,
805 prefs.default_maximum_page_scale_factor);
dcheng5ae8ca362015-02-05 04:03:47806
Allan Sandfeld Jensene35337092019-05-15 13:56:09807 settings->SetFullscreenSupported(prefs.fullscreen_supported);
Ahmed Fakhry42221452018-05-30 01:18:39808 settings->SetTextAutosizingEnabled(prefs.text_autosizing_enabled);
809 settings->SetDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
Tarun Bansald10f17a02018-09-13 00:23:17810 blink::WebNetworkStateNotifier::SetNetworkQualityWebHoldback(
811 static_cast<blink::WebEffectiveConnectionType>(
812 prefs.network_quality_estimator_web_holdback));
Ahmed Fakhry42221452018-05-30 01:18:39813
chaopeng7e8fb352019-03-26 03:34:49814 settings->SetDontSendKeyEventsToJavascript(
815 prefs.dont_send_key_events_to_javascript);
Mounir Lamouri6926107f2019-01-31 18:17:43816 settings->SetWebAppScope(WebString::FromASCII(prefs.web_app_scope.spec()));
817
[email protected]b3a97b52014-07-09 06:25:05818#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:54819 settings->SetAllowCustomScrollbarInMainFrame(false);
Blink Reformat1c4d759e2017-04-09 16:34:54820 settings->SetAccessibilityFontScaleFactor(prefs.font_scale_factor);
821 settings->SetDeviceScaleAdjustment(prefs.device_scale_adjustment);
Blink Reformat1c4d759e2017-04-09 16:34:54822 web_view->SetIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
823 settings->SetAutoZoomFocusedNodeToLegibleScale(true);
Blink Reformat1c4d759e2017-04-09 16:34:54824 settings->SetDefaultVideoPosterURL(
825 WebString::FromASCII(prefs.default_video_poster_url.spec()));
826 settings->SetSupportDeprecatedTargetDensityDPI(
[email protected]b3a97b52014-07-09 06:25:05827 prefs.support_deprecated_target_density_dpi);
Blink Reformat1c4d759e2017-04-09 16:34:54828 settings->SetUseLegacyBackgroundSizeShorthandBehavior(
[email protected]b3a97b52014-07-09 06:25:05829 prefs.use_legacy_background_size_shorthand_behavior);
Blink Reformat1c4d759e2017-04-09 16:34:54830 settings->SetWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
831 settings->SetUseWideViewport(prefs.use_wide_viewport);
832 settings->SetForceZeroLayoutHeight(prefs.force_zero_layout_height);
Blink Reformat1c4d759e2017-04-09 16:34:54833 settings->SetViewportMetaMergeContentQuirk(
[email protected]b3a97b52014-07-09 06:25:05834 prefs.viewport_meta_merge_content_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54835 settings->SetViewportMetaNonUserScalableQuirk(
[email protected]b3a97b52014-07-09 06:25:05836 prefs.viewport_meta_non_user_scalable_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54837 settings->SetViewportMetaZeroValuesQuirk(
[email protected]b3a97b52014-07-09 06:25:05838 prefs.viewport_meta_zero_values_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54839 settings->SetClobberUserAgentInitialScaleQuirk(
[email protected]b3a97b52014-07-09 06:25:05840 prefs.clobber_user_agent_initial_scale_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54841 settings->SetIgnoreMainFrameOverflowHiddenQuirk(
[email protected]b3a97b52014-07-09 06:25:05842 prefs.ignore_main_frame_overflow_hidden_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54843 settings->SetReportScreenSizeInPhysicalPixelsQuirk(
[email protected]b3a97b52014-07-09 06:25:05844 prefs.report_screen_size_in_physical_pixels_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54845 settings->SetShouldReuseGlobalForUnownedMainFrame(
tzik30eb52c2018-03-27 06:55:18846 prefs.reuse_global_for_unowned_main_frame);
Blink Reformat1c4d759e2017-04-09 16:34:54847 settings->SetPreferHiddenVolumeControls(true);
848 settings->SetSpellCheckEnabledByDefault(prefs.spellcheck_enabled_by_default);
dalecurtiscd971252016-09-21 16:09:00849
Blink Reformat1c4d759e2017-04-09 16:34:54850 WebRuntimeFeatures::EnableVideoFullscreenOrientationLock(
mlamouri1d266bf2016-12-05 17:42:36851 prefs.video_fullscreen_orientation_lock_enabled);
johnme913ee5f2017-04-28 21:36:16852 WebRuntimeFeatures::EnableVideoRotateToFullscreen(
853 prefs.video_rotate_to_fullscreen_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54854 WebRuntimeFeatures::EnableVideoFullscreenDetection(
zqzhang93e959d12017-03-16 13:10:20855 prefs.video_fullscreen_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54856 settings->SetEmbeddedMediaExperienceEnabled(
shaktisahuf97f7532017-02-24 22:46:13857 prefs.embedded_media_experience_enabled);
Ian Vollickeeca1d82018-02-07 02:43:42858 settings->SetImmersiveModeEnabled(prefs.immersive_mode_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54859 settings->SetDoNotUpdateSelectionOnMutatingSelectionRange(
changwane54ccdb92017-04-05 19:20:54860 prefs.do_not_update_selection_on_mutating_selection_range);
Noel Gordonf311a842017-07-27 00:10:07861 WebRuntimeFeatures::EnableCSSHexAlphaColor(prefs.css_hex_alpha_color_enabled);
Tobias Sargeant416174f2017-09-01 01:18:09862 WebRuntimeFeatures::EnableScrollTopLeftInterop(
863 prefs.scroll_top_left_interop_enabled);
Fernando Serboncini1fb12a82019-08-08 20:46:01864 WebRuntimeFeatures::EnableSurfaceEmbeddingFeatures(
865 !prefs.disable_features_depending_on_viz);
Aaron Krajeski0fb51282019-09-17 15:01:27866 WebRuntimeFeatures::EnableAcceleratedSmallCanvases(
867 !prefs.disable_accelerated_small_canvases);
zqzhangdf72ed082016-12-08 16:07:55868#endif // defined(OS_ANDROID)
liberato9e934892016-05-03 19:00:27869
Rune Lillesveenb46bb482019-04-02 07:36:29870 settings->SetForceDarkModeEnabled(prefs.force_dark_mode_enabled);
871
mlamouri55a0543c2017-05-11 10:34:07872 switch (prefs.autoplay_policy) {
873 case AutoplayPolicy::kNoUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28874 settings->SetAutoplayPolicy(
875 WebSettings::AutoplayPolicy::kNoUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07876 break;
877 case AutoplayPolicy::kUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28878 settings->SetAutoplayPolicy(
879 WebSettings::AutoplayPolicy::kUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07880 break;
mlamouri431bb4e2017-06-06 08:54:24881 case AutoplayPolicy::kDocumentUserActivationRequired:
882 settings->SetAutoplayPolicy(
883 WebSettings::AutoplayPolicy::kDocumentUserActivationRequired);
884 break;
mlamouri55a0543c2017-05-11 10:34:07885 }
886
Blink Reformat1c4d759e2017-04-09 16:34:54887 settings->SetViewportEnabled(prefs.viewport_enabled);
888 settings->SetViewportMetaEnabled(prefs.viewport_meta_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54889 settings->SetViewportStyle(
alokp5d566962016-04-19 00:54:16890 static_cast<blink::WebViewportStyle>(prefs.viewport_style));
891
Blink Reformat1c4d759e2017-04-09 16:34:54892 settings->SetLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
893 settings->SetMainFrameResizesAreOrientationChanges(
yoava1a508b42015-10-20 12:03:21894 prefs.main_frame_resizes_are_orientation_changes);
895
Blink Reformat1c4d759e2017-04-09 16:34:54896 settings->SetUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
jinho.bang8f11ffa2014-12-04 06:03:03897
Blink Reformat1c4d759e2017-04-09 16:34:54898 settings->SetShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up);
899 settings->SetAlwaysShowContextMenuOnTouch(
amaralp547e4192016-06-03 19:17:35900 prefs.always_show_context_menu_on_touch);
Sandra Sunc79fc93a2018-04-10 15:22:23901 settings->SetSmoothScrollForFindEnabled(prefs.smooth_scroll_for_find_enabled);
ccameron2fd70de72015-02-19 00:40:40902
Blink Reformat1c4d759e2017-04-09 16:34:54903 settings->SetHideDownloadUI(prefs.hide_download_ui);
qinmin72e8bd02016-10-21 19:35:37904
Blink Reformat1c4d759e2017-04-09 16:34:54905 settings->SetPresentationReceiver(prefs.presentation_receiver);
mlamouri57359d912016-11-29 20:11:50906
Blink Reformat1c4d759e2017-04-09 16:34:54907 settings->SetMediaControlsEnabled(prefs.media_controls_enabled);
mlamouri5cd9ae82017-02-18 11:05:09908
Tarun Bansal73d67f02018-01-17 05:56:25909 settings->SetLowPriorityIframesThreshold(
910 static_cast<blink::WebEffectiveConnectionType>(
911 prefs.low_priority_iframes_threshold));
912
Mounir Lamouri9c99a1602018-07-05 15:01:44913 settings->SetPictureInPictureEnabled(
914 prefs.picture_in_picture_enabled &&
[email protected]69db58f2018-09-26 20:27:56915 MediaFactory::GetVideoSurfaceLayerMode() !=
CJ DiMeglio89240472018-10-18 18:21:10916 blink::WebMediaPlayer::SurfaceLayerMode::kNever);
François Beaufort8c08979fc2018-03-05 13:06:31917
Tarun Bansal333819e2018-05-15 16:38:42918 settings->SetDataSaverHoldbackWebApi(
919 prefs.data_saver_holdback_web_api_enabled);
Tarun Bansal333819e2018-05-15 16:38:42920
rajendrante87ed712018-11-30 01:55:00921 settings->SetLazyLoadEnabled(prefs.lazy_load_enabled);
Rune Lillesveene17fb702019-03-15 07:26:14922 settings->SetPreferredColorScheme(prefs.preferred_color_scheme);
Alison Maherbe15c072019-07-08 18:12:39923 settings->SetForcedColors(prefs.forced_colors);
rajendrante87ed712018-11-30 01:55:00924
Scott Little878f7d6702018-05-31 22:09:06925 for (const auto& ect_distance_pair :
926 prefs.lazy_frame_loading_distance_thresholds_px) {
927 switch (ect_distance_pair.first) {
928 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
929 settings->SetLazyFrameLoadingDistanceThresholdPxUnknown(
930 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39931 continue;
Scott Little878f7d6702018-05-31 22:09:06932 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
933 settings->SetLazyFrameLoadingDistanceThresholdPxOffline(
934 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39935 continue;
Scott Little878f7d6702018-05-31 22:09:06936 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
937 settings->SetLazyFrameLoadingDistanceThresholdPxSlow2G(
938 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39939 continue;
Scott Little878f7d6702018-05-31 22:09:06940 case net::EFFECTIVE_CONNECTION_TYPE_2G:
941 settings->SetLazyFrameLoadingDistanceThresholdPx2G(
942 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39943 continue;
Scott Little878f7d6702018-05-31 22:09:06944 case net::EFFECTIVE_CONNECTION_TYPE_3G:
945 settings->SetLazyFrameLoadingDistanceThresholdPx3G(
946 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39947 continue;
Scott Little878f7d6702018-05-31 22:09:06948 case net::EFFECTIVE_CONNECTION_TYPE_4G:
949 settings->SetLazyFrameLoadingDistanceThresholdPx4G(
950 ect_distance_pair.second);
rajendrantd8026342018-08-29 08:08:39951 continue;
952 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
953 continue;
Scott Little878f7d6702018-05-31 22:09:06954 }
rajendrantd8026342018-08-29 08:08:39955 NOTREACHED();
956 }
957
958 for (const auto& ect_distance_pair :
959 prefs.lazy_image_loading_distance_thresholds_px) {
960 switch (ect_distance_pair.first) {
961 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
962 settings->SetLazyImageLoadingDistanceThresholdPxUnknown(
963 ect_distance_pair.second);
964 continue;
965 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
966 settings->SetLazyImageLoadingDistanceThresholdPxOffline(
967 ect_distance_pair.second);
968 continue;
969 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
970 settings->SetLazyImageLoadingDistanceThresholdPxSlow2G(
971 ect_distance_pair.second);
972 continue;
973 case net::EFFECTIVE_CONNECTION_TYPE_2G:
974 settings->SetLazyImageLoadingDistanceThresholdPx2G(
975 ect_distance_pair.second);
976 continue;
977 case net::EFFECTIVE_CONNECTION_TYPE_3G:
978 settings->SetLazyImageLoadingDistanceThresholdPx3G(
979 ect_distance_pair.second);
980 continue;
981 case net::EFFECTIVE_CONNECTION_TYPE_4G:
982 settings->SetLazyImageLoadingDistanceThresholdPx4G(
983 ect_distance_pair.second);
984 continue;
985 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
986 continue;
987 }
988 NOTREACHED();
Scott Little878f7d6702018-05-31 22:09:06989 }
990
rajendrant3daeae292019-09-20 07:57:54991 for (const auto& fully_load_k_pair : prefs.lazy_image_first_k_fully_load) {
992 switch (fully_load_k_pair.first) {
993 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
994 continue;
995 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
996 settings->SetLazyImageFirstKFullyLoadUnknown(fully_load_k_pair.second);
997 continue;
998 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
999 settings->SetLazyImageFirstKFullyLoadSlow2G(fully_load_k_pair.second);
1000 continue;
1001 case net::EFFECTIVE_CONNECTION_TYPE_2G:
1002 settings->SetLazyImageFirstKFullyLoad2G(fully_load_k_pair.second);
1003 continue;
1004 case net::EFFECTIVE_CONNECTION_TYPE_3G:
1005 settings->SetLazyImageFirstKFullyLoad3G(fully_load_k_pair.second);
1006 continue;
1007 case net::EFFECTIVE_CONNECTION_TYPE_4G:
1008 settings->SetLazyImageFirstKFullyLoad4G(fully_load_k_pair.second);
1009 continue;
1010 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
1011 continue;
1012 }
1013 NOTREACHED();
1014 }
1015
ccameron2fd70de72015-02-19 00:40:401016#if defined(OS_MACOSX)
Blink Reformat1c4d759e2017-04-09 16:34:541017 web_view->SetMaximumLegibleScale(prefs.default_maximum_page_scale_factor);
ccameron2fd70de72015-02-19 00:40:401018#endif
sunyunjia87f287b2016-09-09 00:38:131019
1020#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:541021 WebRuntimeFeatures::EnableMiddleClickAutoscroll(true);
sunyunjia87f287b2016-09-09 00:38:131022#endif
Dave Tapuskac6627e12018-08-30 15:07:191023
Dave Tapuskaa38e3252018-11-13 03:01:171024 WebRuntimeFeatures::EnableTranslateService(prefs.translate_service_available);
[email protected]b3a97b52014-07-09 06:25:051025}
1026
1027/*static*/
nickf7b38222016-11-22 21:59:351028RenderViewImpl* RenderViewImpl::Create(
1029 CompositorDependencies* compositor_deps,
Balazs Engedyba034e72017-10-27 22:26:281030 mojom::CreateViewParamsPtr params,
danakjdf1ceb72018-07-18 20:02:251031 RenderWidget::ShowCallback show_callback,
Hajime Hoshiabb3c8f2017-12-04 18:41:391032 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Balazs Engedyba034e72017-10-27 22:26:281033 DCHECK(params->view_id != MSG_ROUTING_NONE);
Albert J. Wongcb004632018-07-10 22:58:251034 DCHECK(params->main_frame_widget_routing_id != MSG_ROUTING_NONE);
Lei Zhang88f23ba2017-10-27 05:56:261035 RenderViewImpl* render_view;
[email protected]0287e762014-04-11 13:07:581036
Albert J. Wong7faa3da2019-03-21 20:43:431037 if (g_create_render_view_impl) {
1038 render_view = g_create_render_view_impl(compositor_deps, *params);
1039 } else {
1040 render_view = new RenderViewImpl(compositor_deps, *params);
1041 }
1042
Erik Chen10e9b022019-08-21 23:33:231043 render_view->Initialize(compositor_deps, std::move(params),
Albert J. Wong7faa3da2019-03-21 20:43:431044 std::move(show_callback), std::move(task_runner));
[email protected]075366912013-02-18 07:13:241045 return render_view;
[email protected]8d41d7612012-11-14 20:32:191046}
1047
Erik Chen3433ee02019-08-05 20:14:261048void RenderViewImpl::Destroy() {
danakjcdfc4262019-10-01 20:09:481049 destroying_ = true;
1050
1051 // If there is no local main frame, then destroying the WebView will not
1052 // detach anything, and the RenderWidget will not be destroyed. So we have
1053 // to do it here.
1054 bool close_render_widget_here = !main_render_frame_;
1055
1056 // Disable emulation before destroying everything. Turning off emulation
1057 // accesses the WebViewImpl and the main frame (if it exists).
1058 // TODO(danakj): Since we are being destroyed, is there even a reason to turn
1059 // emulation off before closing?
1060 if (page_properties()->ScreenMetricsEmulator()) {
1061 page_properties()->ScreenMetricsEmulator()->DisableAndApply();
1062 page_properties()->SetScreenMetricsEmulator(nullptr);
1063 }
Erik Chen3433ee02019-08-05 20:14:261064
Erik Chen562ca42b2019-08-22 19:46:061065 webview_->Close();
Erik Chen3433ee02019-08-05 20:14:261066 // The webview_ is already destroyed by the time we get here, remove any
1067 // references to it.
1068 g_view_map.Get().erase(webview_);
1069 webview_ = nullptr;
Erik Chen562ca42b2019-08-22 19:46:061070
danakjcdfc4262019-10-01 20:09:481071 // We do this after WebView has closed, though it should not matter. WebView
1072 // only uses the RenderWidget through WebWidgetClient that it accesses through
1073 // a main frame. So it should not be able to see this happening when there is
1074 // no local main frame.
1075 if (close_render_widget_here) {
1076 // TODO(danakj): Go through CloseForFrame()? But we don't need/want to post-
1077 // task the Close step here, do we? Since we're inside RenderViewImpl
1078 // destruction?
1079 render_widget_->PrepareForClose();
1080 // We pass ownership of |render_widget_| to itself. Grab a raw pointer to
1081 // call the Close() method on so we don't have to be a C++ expert to know
1082 // whether we will end up with a nullptr where we didn't intend due to order
1083 // of execution.
1084 RenderWidget* closing_widget = render_widget_.get();
1085 closing_widget->Close(std::move(render_widget_));
1086 }
Erik Chen3433ee02019-08-05 20:14:261087
1088 delete this;
1089}
1090
[email protected]8d41d7612012-11-14 20:32:191091// static
dcheng35d31c112015-07-22 00:17:361092void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
1093 *create_render_view_impl)(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:151094 const mojom::CreateViewParams&)) {
[email protected]8d41d7612012-11-14 20:32:191095 CHECK(!g_create_render_view_impl);
1096 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291097}
1098
[email protected]310ebd6302011-10-10 19:06:281099void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511100 observers_.AddObserver(observer);
1101}
1102
[email protected]310ebd6302011-10-10 19:06:281103void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1104 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511105 observers_.RemoveObserver(observer);
1106}
1107
Peter Kastinga4a3ed12018-01-31 04:07:591108blink::WebView* RenderViewImpl::webview() {
1109 return webview_;
1110}
1111
1112const blink::WebView* RenderViewImpl::webview() const {
lfg4fa48da2016-05-09 18:25:131113 return webview_;
[email protected]4d51d5bf2010-07-26 18:48:261114}
1115
danakja2c9d0a92018-07-25 20:01:181116// RenderWidgetOwnerDelegate -----------------------------------------
fsamuel72464894f2015-12-15 06:59:311117
danakja2c9d0a92018-07-25 20:01:181118void RenderViewImpl::SetActiveForWidget(bool active) {
Albert J. Wongcb004632018-07-10 22:58:251119 if (webview())
1120 webview()->SetIsActive(active);
1121}
1122
danakja2c9d0a92018-07-25 20:01:181123bool RenderViewImpl::SupportsMultipleWindowsForWidget() {
1124 return webkit_preferences_.supports_multiple_windows;
1125}
1126
David Bokan11f6ef482019-03-18 17:47:271127bool RenderViewImpl::ShouldAckSyntheticInputImmediately() {
1128 // TODO(bokan): The RequestPresentation API appears not to function in VR. As
1129 // a short term workaround for https://crbug.com/940063, ACK input
1130 // immediately rather than using RequestPresentation.
1131 if (webkit_preferences_.immersive_mode_enabled)
1132 return true;
1133 return false;
1134}
1135
danakj84bbf552019-01-21 21:33:311136void RenderViewImpl::CancelPagePopupForWidget() {
1137 webview()->CancelPagePopup();
danakja2c9d0a92018-07-25 20:01:181138}
1139
1140void RenderViewImpl::ApplyNewDisplayModeForWidget(
Eric Willigersf4ed80d5f2019-09-18 05:08:551141 blink::WebDisplayMode new_display_mode) {
danakj1ab8faf2018-10-12 18:24:281142 webview()->SetDisplayMode(new_display_mode);
danakja2c9d0a92018-07-25 20:01:181143}
1144
1145void RenderViewImpl::ApplyAutoResizeLimitsForWidget(const gfx::Size& min_size,
1146 const gfx::Size& max_size) {
1147 webview()->EnableAutoResizeMode(min_size, max_size);
1148}
1149
1150void RenderViewImpl::DisableAutoResizeForWidget() {
1151 webview()->DisableAutoResizeMode();
1152}
1153
1154void RenderViewImpl::ScrollFocusedNodeIntoViewForWidget() {
1155 if (WebLocalFrame* focused_frame = GetWebView()->FocusedFrame()) {
1156 auto* frame_widget = focused_frame->LocalRoot()->FrameWidget();
1157 frame_widget->ScrollFocusedEditableElementIntoView();
1158 }
1159}
1160
1161void RenderViewImpl::DidReceiveSetFocusEventForWidget() {
1162 // This message must always be received when the main frame is a
1163 // WebLocalFrame.
Albert J. Wong7bbf22d2018-12-20 00:27:271164 // TODO(ajwong): Can this be removed and just check |delegate_| in
danakja2c9d0a92018-07-25 20:01:181165 // RenderWidget instead?
1166 CHECK(webview()->MainFrame()->IsWebLocalFrame());
1167}
1168
danakja2c9d0a92018-07-25 20:01:181169void RenderViewImpl::DidCommitCompositorFrameForWidget() {
1170 for (auto& observer : observers_)
1171 observer.DidCommitCompositorFrame();
Philip Rogers33cd2bcc2018-08-13 21:29:291172 UpdatePreferredSize();
danakja2c9d0a92018-07-25 20:01:181173}
1174
1175void RenderViewImpl::DidCompletePageScaleAnimationForWidget() {
1176 if (auto* focused_frame = GetWebView()->FocusedFrame()) {
1177 if (focused_frame->AutofillClient())
1178 focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame();
1179 }
1180}
1181
1182void RenderViewImpl::ResizeWebWidgetForWidget(
1183 const gfx::Size& size,
1184 float top_controls_height,
1185 float bottom_controls_height,
1186 bool browser_controls_shrink_blink_size) {
1187 webview()->ResizeWithBrowserControls(size, top_controls_height,
1188 bottom_controls_height,
1189 browser_controls_shrink_blink_size);
1190}
1191
danakja2c9d0a92018-07-25 20:01:181192void RenderViewImpl::SetScreenMetricsEmulationParametersForWidget(
1193 bool enabled,
1194 const blink::WebDeviceEmulationParams& params) {
danakj1ab8faf2018-10-12 18:24:281195 if (enabled)
1196 webview()->EnableDeviceEmulation(params);
1197 else
1198 webview()->DisableDeviceEmulation();
danakja2c9d0a92018-07-25 20:01:181199}
1200
1201// IPC message handlers -----------------------------------------
1202
danakja2c9d0a92018-07-25 20:01:181203void RenderViewImpl::OnUpdateTargetURLAck() {
1204 // Check if there is a targeturl waiting to be sent.
1205 if (target_url_status_ == TARGET_PENDING)
1206 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), pending_target_url_));
1207
1208 target_url_status_ = TARGET_NONE;
1209}
1210
1211void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset,
1212 int history_length) {
1213 // -1 <= history_offset < history_length <= kMaxSessionHistoryEntries(50).
1214 DCHECK_LE(-1, history_offset);
1215 DCHECK_LT(history_offset, history_length);
1216 DCHECK_LE(history_length, kMaxSessionHistoryEntries);
1217
1218 history_list_offset_ = history_offset;
1219 history_list_length_ = history_length;
1220}
1221
1222void RenderViewImpl::OnSetInitialFocus(bool reverse) {
1223 if (!webview())
1224 return;
1225 webview()->SetInitialFocus(reverse);
1226}
1227
danakja2c9d0a92018-07-25 20:01:181228void RenderViewImpl::OnAudioStateChanged(bool is_audio_playing) {
1229 webview()->AudioStateChanged(is_audio_playing);
1230}
1231
danakja2c9d0a92018-07-25 20:01:181232///////////////////////////////////////////////////////////////////////////////
1233
1234void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget,
1235 WebNavigationPolicy policy,
1236 const gfx::Rect& initial_rect) {
1237 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(),
1238 initial_rect));
1239}
1240
1241void RenderViewImpl::ShowCreatedFullscreenWidget(
1242 RenderWidget* fullscreen_widget,
1243 WebNavigationPolicy policy,
1244 const gfx::Rect& initial_rect) {
1245 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(),
1246 fullscreen_widget->routing_id()));
1247}
1248
1249void RenderViewImpl::SendFrameStateUpdates() {
1250 // Tell each frame with pending state to send its UpdateState message.
1251 for (int render_frame_routing_id : frames_with_pending_state_) {
1252 RenderFrameImpl* frame =
1253 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
1254 if (frame)
1255 frame->SendUpdateState();
1256 }
1257 frames_with_pending_state_.clear();
1258}
1259
danakja2c9d0a92018-07-25 20:01:181260// IPC::Listener -------------------------------------------------------------
fsamuel72464894f2015-12-15 06:59:311261
[email protected]310ebd6302011-10-10 19:06:281262bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281263 WebFrame* main_frame = webview() ? webview()->MainFrame() : nullptr;
Avi Drissmanb5f8e242017-12-12 05:21:561264 if (main_frame) {
1265 GURL active_url;
1266 if (main_frame->IsWebLocalFrame())
1267 active_url = main_frame->ToWebLocalFrame()->GetDocument().Url();
lukaszabedb4b22017-06-23 00:00:131268 GetContentClient()->SetActiveURL(
Avi Drissmanb5f8e242017-12-12 05:21:561269 active_url, main_frame->Top()->GetSecurityOrigin().ToString().Utf8());
1270 }
[email protected]f8b6b6f2009-03-10 16:48:261271
dchenga2d442c22016-10-13 15:39:211272 for (auto& observer : observers_) {
1273 if (observer.OnMessageReceived(message))
[email protected]676126f72011-01-15 00:03:511274 return true;
dchenga2d442c22016-10-13 15:39:211275 }
[email protected]b2abac72009-02-26 12:39:281276
[email protected]a95986a82010-12-24 06:19:281277 bool handled = true;
[email protected]e44d1342014-05-16 21:29:331278 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
mcnee432e47d2015-11-09 19:37:461279 IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale)
initial.commit09911bf2008-07-26 23:55:291280 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291281 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1282 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
initial.commit09911bf2008-07-26 23:55:291283 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
[email protected]30f75e62009-02-25 22:01:001284 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]ab32b16c2009-10-16 14:57:251285 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1286 OnEnablePreferredSizeChangedMode)
Erik Chenc71b51fe2019-09-19 21:34:271287 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVisualProperties,
1288 OnUpdateVisualProperties)
[email protected]80d96fa2009-06-10 22:34:511289 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]81375e872012-01-11 21:40:361290 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
W. James MacLeand973a55b2018-11-29 21:39:131291 IPC_MESSAGE_HANDLER(ViewMsg_AnimateDoubleTapZoom,
1292 OnAnimateDoubleTapZoomInMainFrame)
W. James MacLean5372eb72018-12-19 12:56:361293 IPC_MESSAGE_HANDLER(ViewMsg_ZoomToFindInPageRect, OnZoomToFindInPageRect)
danakjd51fd53d2018-12-21 23:06:091294 IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque, OnSetBackgroundOpaque)
wjmaclean64951902016-04-29 20:59:121295
1296 // Page messages.
lfg717154072016-06-30 15:04:161297 IPC_MESSAGE_HANDLER(PageMsg_WasHidden, OnPageWasHidden)
1298 IPC_MESSAGE_HANDLER(PageMsg_WasShown, OnPageWasShown)
alexmos136fd6e62016-08-15 20:58:411299 IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength,
1300 OnSetHistoryOffsetAndLength)
altimind8bd26c2016-11-04 11:44:541301 IPC_MESSAGE_HANDLER(PageMsg_AudioStateChanged, OnAudioStateChanged)
W. James MacLean7c8581072019-06-18 18:07:531302 IPC_MESSAGE_HANDLER(PageMsg_UpdatePageVisualProperties,
1303 OnUpdatePageVisualProperties)
Francois Doray47f759d2018-06-11 18:13:511304 IPC_MESSAGE_HANDLER(PageMsg_SetPageFrozen, SetPageFrozen)
Yuzu Saijodfba8fa62019-08-27 02:15:221305 IPC_MESSAGE_HANDLER(PageMsg_PutPageIntoBackForwardCache,
1306 PutPageIntoBackForwardCache)
1307 IPC_MESSAGE_HANDLER(PageMsg_RestorePageFromBackForwardCache,
1308 RestorePageFromBackForwardCache)
W. James MacLean62198672019-06-04 16:46:101309 IPC_MESSAGE_HANDLER(PageMsg_UpdateTextAutosizerPageInfoForRemoteMainFrames,
1310 OnTextAutosizerPageInfoChanged)
lfg717154072016-06-30 15:04:161311
[email protected]a794f3a2013-10-30 17:00:321312 // Adding a new message? Add platform independent ones first, then put the
1313 // platform specific ones at the end.
initial.commit09911bf2008-07-26 23:55:291314 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401315
[email protected]a95986a82010-12-24 06:19:281316 return handled;
initial.commit09911bf2008-07-26 23:55:291317}
1318
[email protected]180ef242013-11-07 06:50:461319// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521320
Mustaq Ahmed55944cb2018-05-25 20:44:271321// TODO(csharrison): Migrate this method to WebLocalFrameClient /
1322// RenderFrameImpl, as it is now serviced by a mojo interface scoped to the
1323// opener frame.
Daniel Murphyc8e991a2018-10-12 22:09:031324WebView* RenderViewImpl::CreateView(
1325 WebLocalFrame* creator,
1326 const WebURLRequest& request,
1327 const WebWindowFeatures& features,
1328 const WebString& frame_name,
1329 WebNavigationPolicy policy,
Daniel Murphyc8e991a2018-10-12 22:09:031330 WebSandboxFlags sandbox_flags,
Ehsan Karamad39407082019-02-19 23:38:191331 const blink::FeaturePolicy::FeatureState& opener_feature_state,
Daniel Murphyc8e991a2018-10-12 22:09:031332 const blink::SessionStorageNamespaceId& session_storage_namespace_id) {
nick5ae4d2d2017-01-06 01:18:351333 RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator);
rockot5c478a72016-09-28 23:14:181334 mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New();
Mustaq Ahmedc4cb7162018-06-05 16:28:361335
1336 // User Activation v2 moves user gesture checks to the browser process, with
1337 // the exception of the extensions case handled through the following |if|.
1338 params->mimic_user_gesture =
1339 base::FeatureList::IsEnabled(features::kUserActivationV2)
1340 ? false
1341 : WebUserGestureIndicator::IsProcessingUserGesture(creator);
Sergey Kuznetsov32257a22019-02-11 20:26:501342 // TODO(mustaq): Investigate if mimic_user_gesture can wrongly expose presence
1343 // of user activation w/o any user interaction, e.g. through
1344 // |WebChromeClient#onCreateWindow|. One case to deep-dive: disabling popup
1345 // blocker then calling window.open at onload event. crbug.com/929729
[email protected]00323f02013-07-24 15:47:411346 if (GetContentClient()->renderer()->AllowPopup())
Mustaq Ahmedc4cb7162018-06-05 16:28:361347 params->mimic_user_gesture = true;
1348
rockot5c478a72016-09-28 23:14:181349 params->window_container_type = WindowFeaturesToContainerType(features);
Daniel Murphye3eec92c2018-02-23 19:09:151350
Daniel Murphyc8e991a2018-10-12 22:09:031351 params->session_storage_namespace_id = session_storage_namespace_id;
1352 // TODO(dmurph): Don't copy session storage when features.noopener is true:
1353 // https://html.spec.whatwg.org/multipage/browsers.html#copy-session-storage
1354 // https://crbug.com/771959
Daniel Murphye3eec92c2018-02-23 19:09:151355 params->clone_from_session_storage_namespace_id =
1356 session_storage_namespace_id_;
Daniel Murphye3eec92c2018-02-23 19:09:151357
Daniel Chengd5e56ff2017-06-24 07:44:021358 const std::string& frame_name_utf8 = frame_name.Utf8(
1359 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
1360 params->frame_name = frame_name_utf8;
Nate Chapin43f307d2019-04-15 21:04:411361 params->opener_suppressed = features.noopener;
rockot5c478a72016-09-28 23:14:181362 params->disposition = NavigationPolicyToDisposition(policy);
Blink Reformat1c4d759e2017-04-09 16:34:541363 if (!request.IsNull()) {
1364 params->target_url = request.Url();
Leon Han963dc182018-11-06 05:41:481365 params->referrer =
1366 blink::mojom::Referrer::From(GetReferrerFromRequest(creator, request));
[email protected]44e55b012013-07-23 14:21:561367 }
scottmg8e6c6082017-02-13 23:15:481368 params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
[email protected]8ab04652010-06-12 02:47:261369
rockot5c478a72016-09-28 23:14:181370 // We preserve this information before sending the message since |params| is
1371 // moved on send.
1372 bool is_background_tab =
1373 params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB;
Mustaq Ahmedc4cb7162018-06-05 16:28:361374 bool opened_by_user_gesture = params->mimic_user_gesture;
[email protected]22217ed32013-11-18 18:40:231375
Daniel Cheng8bb30c62017-10-23 20:40:471376 mojom::CreateNewWindowStatus status;
rockot5c478a72016-09-28 23:14:181377 mojom::CreateNewWindowReplyPtr reply;
Balazs Engedya40712f2017-09-15 15:01:111378 auto* frame_host = creator_frame->GetFrameHost();
Daniel Cheng8bb30c62017-10-23 20:40:471379 bool err = !frame_host->CreateNewWindow(std::move(params), &status, &reply);
1380 if (err || status == mojom::CreateNewWindowStatus::kIgnore)
rockot5c478a72016-09-28 23:14:181381 return nullptr;
[email protected]48c9cf2d2009-09-16 16:47:521382
Jochen Eisinger515337a2017-05-26 14:12:521383 // For Android WebView, we support a pop-up like behavior for window.open()
1384 // even if the embedding app doesn't support multiple windows. In this case,
1385 // window.open() will return "window" and navigate it to whatever URL was
Jochen Eisinger8cb28492017-10-04 10:58:131386 // passed. We also don't need to consume user gestures to protect against
1387 // multiple windows being opened, because, well, the app doesn't support
1388 // multiple windows.
Daniel Cheng8bb30c62017-10-23 20:40:471389 // TODO(dcheng): It's awkward that this is plumbed into Blink but not really
Kent Tamura21d1de62018-12-10 04:45:201390 // used much in Blink, except to enable web testing... perhaps this should
Daniel Cheng8bb30c62017-10-23 20:40:471391 // be checked directly in the browser side.
1392 if (status == mojom::CreateNewWindowStatus::kReuse)
Jochen Eisinger515337a2017-05-26 14:12:521393 return webview();
1394
Daniel Cheng8bb30c62017-10-23 20:40:471395 DCHECK(reply);
1396 DCHECK_NE(MSG_ROUTING_NONE, reply->route_id);
1397 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_route_id);
1398 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_widget_route_id);
1399
Mustaq Ahmed76c2f4312018-06-07 20:48:011400 // The browser allowed creation of a new window and consumed the user
1401 // activation (UAv2 only).
Sergey Kuznetsov32257a22019-02-11 20:26:501402 bool was_consumed = WebUserGestureIndicator::ConsumeUserGesture(
Mustaq Ahmed76c2f4312018-06-07 20:48:011403 creator, blink::UserActivationUpdateSource::kBrowser);
Sergey Kuznetsov32257a22019-02-11 20:26:501404 if (base::FeatureList::IsEnabled(features::kUserActivationV2))
1405 opened_by_user_gesture = was_consumed;
Jochen Eisinger8cb28492017-10-04 10:58:131406
[email protected]7912e822014-04-16 02:37:031407 // While this view may be a background extension page, it can spawn a visible
1408 // render view. So we just assume that the new one is not another background
1409 // page instead of passing on our own value.
1410 // TODO(vangelis): Can we tell if the new view will be a background page?
1411 bool never_visible = false;
[email protected]9115d5f2013-03-24 04:37:411412
Fady Samuelff5b6eb562018-05-01 16:16:081413 VisualProperties visual_properties = VisualProperties();
Albert J. Wonga3dbd5442019-09-18 10:38:281414 visual_properties.screen_info = page_properties()->GetScreenInfo();
mkosiba58fa72f02014-11-12 01:21:361415
[email protected]d6fa88f2013-10-18 16:00:431416 // The initial hidden state for the RenderViewImpl here has to match what the
1417 // browser will eventually decide for the given disposition. Since we have to
1418 // return from this call synchronously, we just have to make our best guess
1419 // and rely on the browser sending a WasHidden / WasShown message if it
1420 // disagrees.
Balazs Engedyba034e72017-10-27 22:26:281421 mojom::CreateViewParamsPtr view_params = mojom::CreateViewParams::New();
alexmos5ac402d2015-07-09 07:51:101422
Balazs Engedyba034e72017-10-27 22:26:281423 view_params->opener_frame_route_id = creator_frame->GetRoutingID();
avia3dca182016-03-19 01:09:521424 DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID());
alexmos5ac402d2015-07-09 07:51:101425
Balazs Engedyba034e72017-10-27 22:26:281426 view_params->window_was_created_with_opener = true;
Leon Han2c81b5d2019-01-25 01:58:331427 view_params->renderer_preferences = renderer_preferences_.Clone();
Balazs Engedyba034e72017-10-27 22:26:281428 view_params->web_preferences = webkit_preferences_;
1429 view_params->view_id = reply->route_id;
1430 view_params->main_frame_routing_id = reply->main_frame_route_id;
Oksana Zhuravlovafee097c2019-07-26 17:01:301431 view_params
1432 ->main_frame_interface_bundle = mojom::DocumentScopedInterfaceBundle::New(
1433 std::move(reply->main_frame_interface_bundle->interface_provider),
1434 std::move(reply->main_frame_interface_bundle
1435 ->document_interface_broker_content),
1436 std::move(
1437 reply->main_frame_interface_bundle->document_interface_broker_blink),
1438 std::move(reply->main_frame_interface_bundle->browser_interface_broker));
Balazs Engedyba034e72017-10-27 22:26:281439 view_params->main_frame_widget_routing_id = reply->main_frame_widget_route_id;
1440 view_params->session_storage_namespace_id =
rockot5c478a72016-09-28 23:14:181441 reply->cloned_session_storage_namespace_id;
Daniel Murphy95792ef2018-10-04 01:29:551442 DCHECK(!view_params->session_storage_namespace_id.empty())
1443 << "Session storage namespace must be populated.";
Balazs Engedyba034e72017-10-27 22:26:281444 view_params->replicated_frame_state.frame_policy.sandbox_flags =
1445 sandbox_flags;
Ehsan Karamad39407082019-02-19 23:38:191446 view_params->replicated_frame_state.opener_feature_state =
1447 opener_feature_state;
Balazs Engedyba034e72017-10-27 22:26:281448 view_params->replicated_frame_state.name = frame_name_utf8;
1449 view_params->devtools_main_frame_token = reply->devtools_main_frame_token;
Balazs Engedyba034e72017-10-27 22:26:281450 view_params->hidden = is_background_tab;
1451 view_params->never_visible = never_visible;
Fady Samuelff5b6eb562018-05-01 16:16:081452 view_params->visual_properties = visual_properties;
naskobd911332014-11-25 01:13:361453
nick5ae4d2d2017-01-06 01:18:351454 // Unretained() is safe here because our calling function will also call
1455 // show().
nickf7b38222016-11-22 21:59:351456 RenderWidget::ShowCallback show_callback =
danakjdf1ceb72018-07-18 20:02:251457 base::BindOnce(&RenderFrameImpl::ShowCreatedWindow,
1458 base::Unretained(creator_frame), opened_by_user_gesture);
nickf7b38222016-11-22 21:59:351459
Balazs Engedyba034e72017-10-27 22:26:281460 RenderViewImpl* view = RenderViewImpl::Create(
Erik Chen8ecac69b2019-10-01 17:40:291461 page_properties_.GetCompositorDependencies(), std::move(view_params),
danakj53802692018-07-25 21:46:441462 std::move(show_callback),
Hajime Hoshi6fc91142018-05-11 08:21:171463 creator->GetTaskRunner(blink::TaskType::kInternalDefault));
[email protected]48c9cf2d2009-09-16 16:47:521464
[email protected]48c9cf2d2009-09-16 16:47:521465 return view->webview();
1466}
1467
danakj19f3e512018-12-14 21:02:051468blink::WebPagePopup* RenderViewImpl::CreatePopup(
1469 blink::WebLocalFrame* creator) {
Erik Chen2c1622d2019-09-21 01:00:201470 return CreatePopupAndGetWidget(creator, nullptr);
1471}
1472
1473blink::WebPagePopup* RenderViewImpl::CreatePopupAndGetWidget(
1474 blink::WebLocalFrame* creator,
1475 RenderWidget** output_widget) {
Julie Jeongeun Kimcaacf9102019-09-12 02:13:051476 mojo::PendingRemote<mojom::Widget> widget_channel;
1477 mojo::PendingReceiver<mojom::Widget> widget_channel_receiver =
1478 widget_channel.InitWithNewPipeAndPassReceiver();
danakj25ec6e2b2018-09-26 17:01:311479
1480 // Do a synchronous IPC to obtain a routing ID.
1481 int32_t widget_routing_id = MSG_ROUTING_NONE;
1482 bool success =
1483 RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
1484 GetRoutingID(), std::move(widget_channel), &widget_routing_id);
1485 if (!success) {
1486 // When the renderer is being killed the mojo message will fail.
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281487 return nullptr;
danakj25ec6e2b2018-09-26 17:01:311488 }
1489
1490 RenderWidget::ShowCallback opener_callback = base::BindOnce(
1491 &RenderViewImpl::ShowCreatedPopupWidget, weak_ptr_factory_.GetWeakPtr());
1492
Erik Chen6bc8da02019-09-20 15:51:381493 RenderWidget* render_widget =
1494 RenderFrameImpl::FromWebFrame(creator)->GetLocalRootRenderWidget();
danakj25ec6e2b2018-09-26 17:01:311495
Erik Chen3433ee02019-08-05 20:14:261496 RenderWidget* popup_widget = RenderWidget::CreateForPopup(
Erik Chen6bc8da02019-09-20 15:51:381497 widget_routing_id, render_widget->compositor_deps(), page_properties(),
1498 blink::kWebDisplayModeUndefined,
danakj25ec6e2b2018-09-26 17:01:311499 /*hidden=*/false,
Julie Jeongeun Kimcaacf9102019-09-12 02:13:051500 /*never_visible=*/false, std::move(widget_channel_receiver));
danakj25ec6e2b2018-09-26 17:01:311501
1502 // The returned WebPagePopup is self-referencing, so the pointer here is not
danakj45e4a4f2019-03-12 22:50:421503 // an owning pointer. It is de-referenced by calling Close().
danakj25ec6e2b2018-09-26 17:01:311504 blink::WebPagePopup* popup_web_widget =
Erik Chen3433ee02019-08-05 20:14:261505 blink::WebPagePopup::Create(popup_widget);
danakj25ec6e2b2018-09-26 17:01:311506
1507 // Adds a self-reference on the |popup_widget| so it will not be destroyed
1508 // when leaving scope. The WebPagePopup takes responsibility for Close()ing
1509 // and thus destroying the RenderWidget.
1510 popup_widget->InitForPopup(std::move(opener_callback), popup_web_widget);
1511 // TODO(crbug.com/419087): RenderWidget has some weird logic for picking a
1512 // WebWidget which doesn't apply to this case. So we verify. This can go away
1513 // when RenderWidget::GetWebWidget() is just a simple accessor.
1514 DCHECK_EQ(popup_widget->GetWebWidget(), popup_web_widget);
1515
Erik Chen2c1622d2019-09-21 01:00:201516 if (output_widget)
1517 *output_widget = popup_widget;
1518
danakj25ec6e2b2018-09-26 17:01:311519 return popup_web_widget;
[email protected]48c9cf2d2009-09-16 16:47:521520}
1521
danakj295c43f182019-03-13 16:37:171522void RenderViewImpl::DoDeferredClose() {
1523 // The main widget is currently not active. The active main frame widget is
1524 // in a different process. Have the browser route the close request to the
1525 // active widget instead, so that the correct unload handlers are run.
1526 Send(new ViewHostMsg_RouteCloseEvent(GetRoutingID()));
1527}
1528
danakj45e4a4f2019-03-12 22:50:421529void RenderViewImpl::CloseWindowSoon() {
Avi Drissman07d22452019-03-25 17:56:391530 DCHECK(RenderThread::IsMainThread());
Erik Chen496b8342019-09-20 15:51:111531 if (!render_widget_ || render_widget_->IsUndeadOrProvisional()) {
danakj295c43f182019-03-13 16:37:171532 // Ask the RenderViewHost with a local main frame to initiate close. We
1533 // could be called from deep in Javascript. If we ask the RenderViewHost to
1534 // close now, the window could be closed before the JS finishes executing,
danakjbd1a86a2019-09-06 17:24:311535 // thanks to nested message loops running and handling the resulting Close
danakj295c43f182019-03-13 16:37:171536 // IPC. So instead, post a message back to the message loop, which won't run
1537 // until the JS is complete, and then the Close request can be sent.
1538 GetCleanupTaskRunner()->PostTask(
1539 FROM_HERE, base::BindOnce(&RenderViewImpl::DoDeferredClose,
1540 weak_ptr_factory_.GetWeakPtr()));
danakj45e4a4f2019-03-12 22:50:421541 return;
1542 }
1543
danakjbd1a86a2019-09-06 17:24:311544 // If the main widget is not undead then the Close request goes directly
danakj45e4a4f2019-03-12 22:50:421545 // through it, because the RenderWidget ultimately owns the RenderViewImpl.
1546 render_widget_->CloseWidgetSoon();
1547}
1548
Daniel Murphy31bbb8b12018-02-07 21:44:101549base::StringPiece RenderViewImpl::GetSessionStorageNamespaceId() {
1550 CHECK(!session_storage_namespace_id_.empty());
Daniel Murphy0ce6e2c2017-11-21 01:54:261551 return session_storage_namespace_id_;
[email protected]bd92c3a2010-01-13 05:02:341552}
1553
Blink Reformat1c4d759e2017-04-09 16:34:541554void RenderViewImpl::PrintPage(WebLocalFrame* frame) {
Erik Chenfaa928c2019-09-20 23:41:151555 RenderFrameImpl* render_frame = RenderFrameImpl::FromWebFrame(frame);
1556 RenderWidget* render_widget = render_frame->GetLocalRootRenderWidget();
1557
1558 render_frame->ScriptedPrint(
1559 render_widget->input_handler().handling_input_event());
[email protected]48c9cf2d2009-09-16 16:47:521560}
1561
lfgcaab5142016-02-26 19:06:521562void RenderViewImpl::AttachWebFrameWidget(blink::WebFrameWidget* frame_widget) {
dcheng3ce04b62015-10-26 23:30:551563 // The previous WebFrameWidget must already be detached by CloseForFrame().
1564 DCHECK(!frame_widget_);
1565 frame_widget_ = frame_widget;
danakj872a96a12019-09-18 21:53:141566 render_widget_->SetWebWidgetInternal(frame_widget);
danakjefcb8432019-01-16 18:47:141567
1568 // Initialization for the WebFrameWidget that should only occur for the main
1569 // frame, and that uses types not allowed in blink. This should maybe be
1570 // passed to the creation of the WebFrameWidget or the main RenderFrame.
1571 const base::CommandLine& command_line =
1572 *base::CommandLine::ForCurrentProcess();
danakj175a17a2019-03-15 23:10:381573 render_widget_->SetShowFPSCounter(
danakjefcb8432019-01-16 18:47:141574 command_line.HasSwitch(cc::switches::kShowFPSCounter));
dcheng3ce04b62015-10-26 23:30:551575}
1576
danakj8f4465b2018-11-07 20:11:281577void RenderViewImpl::DetachWebFrameWidget() {
danakj8f4465b2018-11-07 20:11:281578 DCHECK(frame_widget_);
Erik Chen7ee377b2019-08-22 23:38:341579
danakjcdfc4262019-10-01 20:09:481580 if (destroying_) {
1581 // We are inside RenderViewImpl::Destroy() and the main frame is being
1582 // detached as part of shutdown. So we can destroy the RenderWidget.
1583
1584 // The RenderWidget is closed and it will close the WebWidget stored in
1585 // |frame_widget_|. We just want to drop raw pointer here.
1586 frame_widget_ = nullptr;
1587 // TODO(danakj): Go through CloseForFrame()? But we don't need/want to post-
1588 // task the Close step here, do we? Since we're inside RenderViewImpl
1589 // destruction?
1590 render_widget_->PrepareForClose();
1591 // We pass ownership of |render_widget_| to itself. Grab a raw pointer to
1592 // call the Close() method on so we don't have to be a C++ expert to know
1593 // whether we will end up with a nullptr where we didn't intend due to order
1594 // of execution.
1595 RenderWidget* closing_widget = render_widget_.get();
1596 closing_widget->Close(std::move(render_widget_));
1597 } else {
1598 // We are not inside RenderViewImpl::Destroy(), the main frame is being
1599 // detached and replaced with a remote frame proxy. We can't close the
1600 // RenderWidget, and it is marked undead instead, but we do need to close
1601 // the WebFrameWidget and remove it from the RenderWidget.
1602
1603 DCHECK(render_widget_->IsUndeadOrProvisional());
1604 // The WebWidget needs to be closed even though the RenderWidget won't be
1605 // here (since it is marked undead instead).
1606 frame_widget_->Close();
1607 frame_widget_ = nullptr;
1608 // This just clears the webwidget_internal_ member from RenderWidget.
1609 render_widget_->SetWebWidgetInternal(nullptr);
1610 }
danakj8f4465b2018-11-07 20:11:281611}
1612
danakjcf409aa2019-09-20 15:22:301613bool RenderViewImpl::SetZoomLevel(double zoom_level) {
1614 if (zoom_level == page_zoom_level_)
1615 return false;
1616
wjmaclean64951902016-04-29 20:59:121617 // If we change the zoom level for the view, make sure any subsequent subframe
1618 // loads reflect the current zoom level.
1619 page_zoom_level_ = zoom_level;
Blink Reformat1c4d759e2017-04-09 16:34:541620 webview()->SetZoomLevel(zoom_level);
ericwilligers88e69742016-10-17 19:29:551621 for (auto& observer : observers_)
1622 observer.OnZoomLevelChanged();
danakjcf409aa2019-09-20 15:22:301623 return true;
1624}
1625
1626void RenderViewImpl::SetPreferCompositingToLCDTextEnabled(bool prefer) {
1627 webview()->GetSettings()->SetPreferCompositingToLCDTextEnabled(prefer);
1628}
1629
1630void RenderViewImpl::SetDeviceScaleFactor(bool use_zoom_for_dsf,
1631 float device_scale_factor) {
1632 if (use_zoom_for_dsf)
1633 webview()->SetZoomFactorForDeviceScaleFactor(device_scale_factor);
1634 else
1635 webview()->SetDeviceScaleFactor(device_scale_factor);
1636}
1637
1638void RenderViewImpl::PropagatePageZoomToNewlyAttachedFrame(
1639 bool use_zoom_for_dsf,
1640 float device_scale_factor) {
1641 if (use_zoom_for_dsf)
1642 webview()->SetZoomFactorForDeviceScaleFactor(device_scale_factor);
1643 else
1644 webview()->SetZoomLevel(page_zoom_level_);
tommycli8aad3ba2015-08-12 17:57:591645}
1646
habib.virji597255e2014-09-09 00:30:181647void RenderViewImpl::SetValidationMessageDirection(
1648 base::string16* wrapped_main_text,
1649 blink::WebTextDirection main_text_hint,
1650 base::string16* wrapped_sub_text,
1651 blink::WebTextDirection sub_text_hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541652 if (main_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181653 *wrapped_main_text =
1654 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
Blink Reformat1c4d759e2017-04-09 16:34:541655 } else if (main_text_hint == blink::kWebTextDirectionRightToLeft &&
habib.virji597255e2014-09-09 00:30:181656 !base::i18n::IsRTL()) {
1657 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
1658 }
1659
1660 if (!wrapped_sub_text->empty()) {
Blink Reformat1c4d759e2017-04-09 16:34:541661 if (sub_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181662 *wrapped_sub_text =
1663 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
Blink Reformat1c4d759e2017-04-09 16:34:541664 } else if (sub_text_hint == blink::kWebTextDirectionRightToLeft) {
habib.virji597255e2014-09-09 00:30:181665 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
1666 }
1667 }
1668}
1669
[email protected]310ebd6302011-10-10 19:06:281670void RenderViewImpl::UpdateTargetURL(const GURL& url,
1671 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581672 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521673 if (latest_url == target_url_)
1674 return;
[email protected]163f8242009-10-30 20:19:551675
[email protected]48c9cf2d2009-09-16 16:47:521676 // Tell the browser to display a destination link.
1677 if (target_url_status_ == TARGET_INFLIGHT ||
1678 target_url_status_ == TARGET_PENDING) {
1679 // If we have a request in-flight, save the URL to be sent when we
1680 // receive an ACK to the in-flight request. We can happily overwrite
1681 // any existing pending sends.
1682 pending_target_url_ = latest_url;
1683 target_url_status_ = TARGET_PENDING;
1684 } else {
mnaganovbf087422015-12-16 05:10:031685 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411686 // see |ParamTraits<GURL>|.
markdittmer67b71ea2016-03-03 22:40:031687 if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:411688 latest_url = GURL();
avia3dca182016-03-19 01:09:521689 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), latest_url));
[email protected]48c9cf2d2009-09-16 16:47:521690 target_url_ = latest_url;
1691 target_url_status_ = TARGET_INFLIGHT;
1692 }
1693}
1694
creis69b184a472015-11-26 05:29:511695void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) {
creisce0ef3572017-01-26 17:53:081696 // Keep track of which frames have pending updates.
1697 frames_with_pending_state_.insert(frame->GetRoutingID());
creis8eb8ef22015-11-04 22:51:381698
[email protected]882daa92009-11-05 16:31:311699 int delay;
avif937e1d2014-11-02 18:13:071700 if (send_content_state_immediately_)
[email protected]882daa92009-11-05 16:31:311701 delay = 0;
danakj78744912018-11-30 23:46:421702 else if (GetWebView()->IsHidden())
avif937e1d2014-11-02 18:13:071703 delay = kDelaySecondsForContentStateSyncHidden;
[email protected]882daa92009-11-05 16:31:311704 else
avif937e1d2014-11-02 18:13:071705 delay = kDelaySecondsForContentStateSync;
[email protected]882daa92009-11-05 16:31:311706
avif937e1d2014-11-02 18:13:071707 if (nav_state_sync_timer_.IsRunning()) {
[email protected]882daa92009-11-05 16:31:311708 // The timer is already running. If the delay of the timer maches the amount
1709 // we want to delay by, then return. Otherwise stop the timer so that it
1710 // gets started with the right delay.
avif937e1d2014-11-02 18:13:071711 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
[email protected]882daa92009-11-05 16:31:311712 return;
avif937e1d2014-11-02 18:13:071713 nav_state_sync_timer_.Stop();
[email protected]882daa92009-11-05 16:31:311714 }
1715
creisce0ef3572017-01-26 17:53:081716 // Tell each frame with pending state to inform the browser.
danakj19f3e512018-12-14 21:02:051717 nav_state_sync_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay),
1718 this, &RenderViewImpl::SendFrameStateUpdates);
[email protected]882daa92009-11-05 16:31:311719}
1720
Blink Reformat1c4d759e2017-04-09 16:34:541721void RenderViewImpl::SetMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551722 mouse_over_url_ = GURL(url);
1723 UpdateTargetURL(mouse_over_url_, focus_url_);
1724}
1725
Blink Reformat1c4d759e2017-04-09 16:34:541726void RenderViewImpl::SetKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551727 focus_url_ = GURL(url);
1728 UpdateTargetURL(focus_url_, mouse_over_url_);
1729}
1730
Blink Reformat1c4d759e2017-04-09 16:34:541731bool RenderViewImpl::AcceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451732 return renderer_preferences_.can_accept_load_drops;
1733}
1734
Blink Reformat1c4d759e2017-04-09 16:34:541735void RenderViewImpl::FocusNext() {
avia3dca182016-03-19 01:09:521736 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false));
[email protected]48c9cf2d2009-09-16 16:47:521737}
1738
Blink Reformat1c4d759e2017-04-09 16:34:541739void RenderViewImpl::FocusPrevious() {
avia3dca182016-03-19 01:09:521740 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true));
[email protected]48c9cf2d2009-09-16 16:47:521741}
1742
Kent Tamura69d143e2019-05-22 00:31:451743void RenderViewImpl::FocusedElementChanged(const WebElement& from_element,
1744 const WebElement& to_element) {
estade31c54342015-01-23 03:34:361745 RenderFrameImpl* previous_frame = nullptr;
Kent Tamura69d143e2019-05-22 00:31:451746 if (!from_element.IsNull())
Blink Reformat1c4d759e2017-04-09 16:34:541747 previous_frame =
Kent Tamura69d143e2019-05-22 00:31:451748 RenderFrameImpl::FromWebFrame(from_element.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361749 RenderFrameImpl* new_frame = nullptr;
Kent Tamura69d143e2019-05-22 00:31:451750 if (!to_element.IsNull())
1751 new_frame =
1752 RenderFrameImpl::FromWebFrame(to_element.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361753
1754 if (previous_frame && previous_frame != new_frame)
Kent Tamura69d143e2019-05-22 00:31:451755 previous_frame->FocusedElementChanged(WebElement());
estade31c54342015-01-23 03:34:361756 if (new_frame)
Kent Tamura69d143e2019-05-22 00:31:451757 new_frame->FocusedElementChanged(to_element);
estade31c54342015-01-23 03:34:361758
1759 // TODO(dmazzoni): remove once there's a separate a11y tree per frame.
naskoe8d115752015-08-07 00:43:131760 if (main_render_frame_)
Kent Tamura69d143e2019-05-22 00:31:451761 main_render_frame_->FocusedElementChangedForAccessibility(to_element);
[email protected]08e9e132010-06-01 16:58:491762}
1763
Philip Rogers079658812018-08-01 23:19:091764void RenderViewImpl::DidUpdateMainFrameLayout() {
ericwilligers88e69742016-10-17 19:29:551765 for (auto& observer : observers_)
Philip Rogers079658812018-08-01 23:19:091766 observer.DidUpdateMainFrameLayout();
[email protected]d01b2a62013-09-18 23:21:331767
Philip Rogers33cd2bcc2018-08-13 21:29:291768 // The main frame may have changed size.
1769 needs_preferred_size_update_ = true;
[email protected]169d4282011-11-30 19:33:591770}
1771
Arthur Sonzognia7d715a2018-09-20 16:11:131772void RenderViewImpl::NavigateBackForwardSoon(int offset,
1773 bool has_user_gesture) {
Alex Clarkebf3dceb2017-11-24 12:27:431774 history_navigation_virtual_time_pauser_ =
1775 RenderThreadImpl::current()
Yuta Kitamura3331f5c2018-04-05 11:12:251776 ->GetWebMainThreadScheduler()
Alex Clarkeb28db542018-02-07 12:53:131777 ->CreateWebScopedVirtualTimePauser(
Alex Clarkeaaf006b2018-04-05 18:35:241778 "NavigateBackForwardSoon",
Alex Clarkeb28db542018-02-07 12:53:131779 blink::WebScopedVirtualTimePauser::VirtualTaskDuration::kInstant);
Alex Clarkeaaf006b2018-04-05 18:35:241780 history_navigation_virtual_time_pauser_.PauseVirtualTime();
[email protected]48c9cf2d2009-09-16 16:47:521781}
1782
Alex Clarkebf3dceb2017-11-24 12:27:431783void RenderViewImpl::DidCommitProvisionalHistoryLoad() {
Alex Clarkeaaf006b2018-04-05 18:35:241784 history_navigation_virtual_time_pauser_.UnpauseVirtualTime();
Alex Clarkebf3dceb2017-11-24 12:27:431785}
1786
Scott Violet0de3837c2019-09-06 22:51:541787void RenderViewImpl::UpdateBrowserControlsState(
1788 BrowserControlsState constraints,
1789 BrowserControlsState current,
1790 bool animate) {
1791 TRACE_EVENT2("renderer", "RenderViewImpl::UpdateBrowserControlsState",
1792 "Constraint", static_cast<int>(constraints), "Current",
1793 static_cast<int>(current));
1794 TRACE_EVENT_INSTANT1("renderer", "is_animated", TRACE_EVENT_SCOPE_THREAD,
1795 "animated", animate);
1796
danakj872a96a12019-09-18 21:53:141797 if (render_widget_ && render_widget_->layer_tree_view()) {
1798 render_widget_->layer_tree_view()
Scott Violet0de3837c2019-09-06 22:51:541799 ->layer_tree_host()
1800 ->UpdateBrowserControlsState(ContentToCc(constraints),
1801 ContentToCc(current), animate);
1802 }
1803
1804 top_controls_constraints_ = constraints;
1805}
1806
Michael Martis2415478f2019-04-17 07:35:001807void RenderViewImpl::RegisterRendererPreferenceWatcher(
Julie Jeongeun Kim6d8b7492019-08-20 19:24:111808 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
1809 renderer_preference_watchers_.Add(std::move(watcher));
Makoto Shimazuc3c730e2018-08-15 09:51:111810}
1811
Blink Reformat1c4d759e2017-04-09 16:34:541812int RenderViewImpl::HistoryBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001813 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521814}
1815
Blink Reformat1c4d759e2017-04-09 16:34:541816int RenderViewImpl::HistoryForwardListCount() {
1817 return history_list_length_ - HistoryBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521818}
1819
[email protected]180ef242013-11-07 06:50:461820// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:511821
Blink Reformat1c4d759e2017-04-09 16:34:541822bool RenderViewImpl::CanHandleGestureEvent() {
slangley1a6375e62017-03-29 06:03:231823 return true;
1824}
1825
Avi Drissmanfb961262019-03-05 22:50:291826// TODO(https://crbug.com/937569): Remove this in Chrome 82.
1827bool RenderViewImpl::AllowPopupsDuringPageUnload() {
1828 const base::CommandLine& command_line =
1829 *base::CommandLine::ForCurrentProcess();
Avi Drissman7e5079f2019-09-30 14:06:401830 return command_line.HasSwitch(switches::kAllowPopupsDuringPageUnload) ||
1831 base::FeatureList::IsEnabled(features::kAllowPopupsDuringPageUnload);
Avi Drissmanfb961262019-03-05 22:50:291832}
1833
Blink Reformat1c4d759e2017-04-09 16:34:541834bool RenderViewImpl::CanUpdateLayout() {
slangley1a6375e62017-03-29 06:03:231835 return true;
1836}
1837
[email protected]b2324b092012-11-01 10:34:111838void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
1839 const std::string& value) {
danakj872a96a12019-09-18 21:53:141840 render_widget_->SetEditCommandForNextKeyEvent(name, value);
[email protected]b2324b092012-11-01 10:34:111841}
1842
1843void RenderViewImpl::ClearEditCommands() {
danakj872a96a12019-09-18 21:53:141844 render_widget_->ClearEditCommands();
[email protected]b2324b092012-11-01 10:34:111845}
1846
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491847const std::string& RenderViewImpl::GetAcceptLanguages() {
[email protected]b38806a2013-10-04 16:01:381848 return renderer_preferences_.accept_languages;
1849}
1850
David Bokan1e37ebf2018-10-16 13:53:371851#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
1852
Ahmed Fakhry58e6ef542018-09-04 18:05:381853void RenderViewImpl::didScrollWithKeyboard(const blink::WebSize& delta) {
1854 if (delta.height == 0)
1855 return;
1856
1857 BrowserControlsState current = delta.height < 0
1858 ? BROWSER_CONTROLS_STATE_SHOWN
1859 : BROWSER_CONTROLS_STATE_HIDDEN;
1860
1861 UpdateBrowserControlsState(top_controls_constraints_, current, true);
1862}
1863
1864#endif
1865
danakjdea2efb2016-03-10 19:13:171866void RenderViewImpl::ConvertViewportToWindowViaWidget(blink::WebRect* rect) {
Erik Chena65fa752019-09-21 06:59:401867 page_properties_.ConvertViewportToWindow(rect);
oshimae2b3b402015-12-04 04:27:241868}
1869
huangs2a342352015-12-15 16:59:241870gfx::RectF RenderViewImpl::ElementBoundsInWindow(
1871 const blink::WebElement& element) {
Blink Reformat1c4d759e2017-04-09 16:34:541872 blink::WebRect bounding_box_in_window = element.BoundsInViewport();
Erik Chena65fa752019-09-21 06:59:401873 page_properties_.ConvertViewportToWindow(&bounding_box_in_window);
huangs2a342352015-12-15 16:59:241874 return gfx::RectF(bounding_box_in_window);
1875}
1876
Philip Rogers601fd072018-08-07 22:58:221877void RenderViewImpl::UpdatePreferredSize() {
[email protected]d812fd12011-05-27 23:05:071878 // We don't always want to send the change messages over IPC, only if we've
1879 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1880 // message.
1881 if (!send_preferred_size_changes_ || !webview())
1882 return;
Philip Rogers33cd2bcc2018-08-13 21:29:291883
1884 if (!needs_preferred_size_update_)
1885 return;
1886 needs_preferred_size_update_ = false;
1887
oshima1a688b5c2017-06-16 19:00:131888 blink::WebSize tmp_size = webview()->ContentsPreferredMinimumSize();
1889 blink::WebRect tmp_rect(0, 0, tmp_size.width, tmp_size.height);
Erik Chena65fa752019-09-21 06:59:401890 page_properties_.ConvertViewportToWindow(&tmp_rect);
oshima1a688b5c2017-06-16 19:00:131891 gfx::Size size(tmp_rect.width, tmp_rect.height);
[email protected]705243f2010-05-05 19:58:071892 if (size == preferred_size_)
1893 return;
[email protected]c27324b2009-11-19 22:44:291894
[email protected]705243f2010-05-05 19:58:071895 preferred_size_ = size;
avia3dca182016-03-19 01:09:521896 Send(new ViewHostMsg_DidContentsPreferredSizeChange(GetRoutingID(),
[email protected]705243f2010-05-05 19:58:071897 preferred_size_));
[email protected]3d9689372009-09-10 04:29:171898}
1899
Blink Reformat1c4d759e2017-04-09 16:34:541900blink::WebString RenderViewImpl::AcceptLanguages() {
1901 return WebString::FromUTF8(renderer_preferences_.accept_languages);
[email protected]9982c802013-06-12 15:22:061902}
1903
[email protected]e9ff79c2012-10-19 21:31:261904// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:311905
[email protected]310ebd6302011-10-10 19:06:281906bool RenderViewImpl::Send(IPC::Message* message) {
danakj3130f122019-07-16 17:49:471907 // No messages sent through RenderView come without a routing id, yay. Let's
1908 // keep that up.
1909 CHECK_NE(message->routing_id(), MSG_ROUTING_NONE);
danakj3130f122019-07-16 17:49:471910 return RenderThread::Get()->Send(message);
[email protected]a2ef54c2011-10-10 16:20:311911}
1912
Peter Kastinga4a3ed12018-01-31 04:07:591913RenderWidget* RenderViewImpl::GetWidget() {
Erik Chen3433ee02019-08-05 20:14:261914 return render_widget_.get();
Albert J. Wong7bbf22d2018-12-20 00:27:271915}
1916
1917const RenderWidget* RenderViewImpl::GetWidget() const {
Erik Chen3433ee02019-08-05 20:14:261918 return render_widget_.get();
avi8a45c1092016-03-01 16:12:341919}
1920
mostynbc33353232014-09-12 09:38:311921RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() {
nasko77de2312015-05-12 03:09:161922 return main_render_frame_;
[email protected]b849847b2013-12-10 21:57:581923}
1924
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491925int RenderViewImpl::GetRoutingID() {
Albert J. Wongcb004632018-07-10 22:58:251926 return routing_id_;
[email protected]a2ef54c2011-10-10 16:20:311927}
1928
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491929float RenderViewImpl::GetDeviceScaleFactor() {
Albert J. Wonga3dbd5442019-09-18 10:38:281930 return page_properties()->GetDeviceScaleFactor();
oshima129b75e2016-01-14 09:15:141931}
1932
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491933float RenderViewImpl::GetZoomLevel() {
Marc Treib06d66032017-10-19 08:43:201934 return page_zoom_level_;
1935}
1936
thestig8a8fdfd32017-05-06 18:46:541937const WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:311938 return webkit_preferences_;
1939}
1940
[email protected]324825d2012-11-30 12:37:151941void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
1942 OnUpdateWebPreferences(preferences);
1943}
1944
[email protected]180ef242013-11-07 06:50:461945blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:311946 return webview();
1947}
1948
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491949bool RenderViewImpl::GetContentStateImmediately() {
avif937e1d2014-11-02 18:13:071950 return send_content_state_immediately_;
[email protected]a2ef54c2011-10-10 16:20:311951}
1952
mcnee432e47d2015-11-09 19:37:461953void RenderViewImpl::OnSetPageScale(float page_scale_factor) {
ccameronb7c1d6c2015-03-09 17:08:241954 if (!webview())
1955 return;
Blink Reformat1c4d759e2017-04-09 16:34:541956 webview()->SetPageScaleFactor(page_scale_factor);
ccameronb7c1d6c2015-03-09 17:08:241957}
1958
danakj78744912018-11-30 23:46:421959void RenderViewImpl::ApplyPageHidden(bool hidden, bool initial_setting) {
1960 webview()->SetIsHidden(hidden, initial_setting);
1961 // Note: RenderWidget visibility is separately set from the IPC handlers, and
1962 // does not change when tests override the visibility of the Page.
danakj1b35e9d2018-11-07 19:09:281963}
1964
[email protected]310ebd6302011-10-10 19:06:281965void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:591966 webkit_preferences_ = prefs;
danakjfd0c7f42018-10-12 18:01:081967 ApplyWebPreferences(webkit_preferences_, webview());
initial.commit09911bf2008-07-26 23:55:291968}
1969
[email protected]2bf834f2011-11-17 20:02:211970void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:241971 if (send_preferred_size_changes_)
1972 return;
[email protected]9fb325e2010-05-06 18:23:241973 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:391974
Philip Rogers601fd072018-08-07 22:58:221975 if (!webview())
1976 return;
1977
Philip Rogers33cd2bcc2018-08-13 21:29:291978 needs_preferred_size_update_ = true;
1979
Philip Rogers601fd072018-08-07 22:58:221980 // We need to ensure |UpdatePreferredSize| gets called. If a layout is needed,
1981 // force an update here which will call |DidUpdateMainFrameLayout|.
Erik Chenab7ed492019-08-28 01:34:491982 if (webview()->MainFrameWidget()) {
1983 webview()->MainFrameWidget()->UpdateLifecycle(
1984 WebWidget::LifecycleUpdate::kLayout,
1985 WebWidget::LifecycleUpdateReason::kOther);
1986 }
Philip Rogers601fd072018-08-07 22:58:221987
1988 // If a layout was not needed, |DidUpdateMainFrameLayout| will not be called.
1989 // We explicitly update the preferred size here to ensure the preferred size
1990 // notification is sent.
1991 UpdatePreferredSize();
[email protected]0666aef2009-05-13 19:48:081992}
1993
[email protected]310ebd6302011-10-10 19:06:281994void RenderViewImpl::OnSetRendererPrefs(
Leon Hanc819dc62019-01-28 04:30:191995 const blink::mojom::RendererPreferences& renderer_prefs) {
[email protected]ebd5ea52014-05-28 14:51:151996 std::string old_accept_languages = renderer_preferences_.accept_languages;
1997
[email protected]80d96fa2009-06-10 22:34:511998 renderer_preferences_ = renderer_prefs;
ananta59b9fe72015-04-07 01:33:261999
Julie Jeongeun Kim6d8b7492019-08-20 19:24:112000 for (auto& watcher : renderer_preference_watchers_)
2001 watcher->NotifyUpdate(renderer_prefs.Clone());
Makoto Shimazuc3c730e2018-08-15 09:51:112002
[email protected]6e282c92009-07-24 01:19:372003 UpdateFontRenderingFromRendererPrefs();
scottmgb92365e2016-08-30 20:54:402004 UpdateThemePrefs();
Leon Han2c81b5d2019-01-25 01:58:332005 blink::SetCaretBlinkInterval(
2006 renderer_prefs.caret_blink_interval.has_value()
2007 ? renderer_prefs.caret_blink_interval.value()
2008 : base::TimeDelta::FromMilliseconds(
Leon Hanc819dc62019-01-28 04:30:192009 blink::mojom::kDefaultCaretBlinkIntervalInMilliseconds));
[email protected]38a85712013-01-02 22:45:022010
Christopher Cameronf8e279d32019-05-15 18:50:562011#if defined(USE_AURA)
[email protected]1596efb2013-01-17 22:13:012012 if (renderer_prefs.use_custom_colors) {
Blink Reformat1c4d759e2017-04-09 16:34:542013 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
Christopher Cameronf6fc7ec2019-05-13 18:52:532014 blink::SetSelectionColors(renderer_prefs.active_selection_bg_color,
2015 renderer_prefs.active_selection_fg_color,
2016 renderer_prefs.inactive_selection_bg_color,
2017 renderer_prefs.inactive_selection_fg_color);
Erik Chenab7ed492019-08-28 01:34:492018 if (webview() && webview()->MainFrameWidget())
danakj763c2402018-11-09 02:46:222019 webview()->MainFrameWidget()->ThemeChanged();
[email protected]644d77e2010-01-27 01:03:102020 }
Christopher Cameronf8e279d32019-05-15 18:50:562021#endif
[email protected]d299d972012-03-23 02:26:552022
[email protected]ebd5ea52014-05-28 14:51:152023 if (webview() &&
2024 old_accept_languages != renderer_preferences_.accept_languages) {
Blink Reformat1c4d759e2017-04-09 16:34:542025 webview()->AcceptLanguagesChanged();
[email protected]ebd5ea52014-05-28 14:51:152026 }
[email protected]80d96fa2009-06-10 22:34:512027}
2028
[email protected]81375e872012-01-11 21:40:362029void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
2030 const WebPluginAction& action) {
2031 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542032 webview()->PerformPluginAction(action, location);
[email protected]81375e872012-01-11 21:40:362033}
2034
[email protected]310ebd6302011-10-10 19:06:282035void RenderViewImpl::OnClosePage() {
lukasza5d0dee42017-06-14 21:57:372036 // ViewMsg_ClosePage should only be sent to active, non-swapped-out views.
2037 DCHECK(webview()->MainFrame()->IsWebLocalFrame());
2038
initial.commit09911bf2008-07-26 23:55:292039 // TODO(creis): We'd rather use webview()->Close() here, but that currently
2040 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
2041 // in the onunload handler from appearing. For now, we're bypassing that and
2042 // calling the FrameLoader's CloseURL method directly. This should be
2043 // revisited to avoid having two ways to close a page. Having a single way
2044 // to close that can run onunload is also useful for fixing
2045 // http://b/issue?id=753080.
lukasza5d0dee42017-06-14 21:57:372046 webview()->MainFrame()->ToWebLocalFrame()->DispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:292047
avia3dca182016-03-19 01:09:522048 Send(new ViewHostMsg_ClosePage_ACK(GetRoutingID()));
initial.commit09911bf2008-07-26 23:55:292049}
2050
[email protected]310ebd6302011-10-10 19:06:282051void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:002052 if (webview())
danakja5c39d52018-12-13 22:20:562053 webview()->CancelPagePopup();
[email protected]30f75e62009-02-25 22:01:002054}
2055
lfg717154072016-06-30 15:04:162056void RenderViewImpl::OnPageWasHidden() {
braveyao1d8ee7b2017-03-29 21:10:042057#if defined(OS_ANDROID)
2058 SuspendVideoCaptureDevices(true);
braveyao1d8ee7b2017-03-29 21:10:042059#endif
[email protected]2d7b82c2012-06-01 05:57:502060
danakj78744912018-11-30 23:46:422061 ApplyPageHidden(/*hidden=*/true, /*initial_setting=*/false);
[email protected]941e4552010-02-01 21:23:432062}
2063
lfg717154072016-06-30 15:04:162064void RenderViewImpl::OnPageWasShown() {
braveyao1d8ee7b2017-03-29 21:10:042065#if defined(OS_ANDROID)
2066 SuspendVideoCaptureDevices(false);
[email protected]6392d982013-04-16 16:59:222067#endif
2068
danakj78744912018-11-30 23:46:422069 ApplyPageHidden(/*hidden=*/false, /*initial_setting=*/false);
[email protected]a6939ca42011-02-18 17:58:072070}
[email protected]1e6e3c992010-02-08 15:52:132071
Erik Chenc71b51fe2019-09-19 21:34:272072void RenderViewImpl::OnUpdateVisualProperties(
2073 const VisualProperties& visual_properties,
2074 int widget_routing_id) {
Erik Chena515bf32019-09-09 21:53:032075 // TODO(https://crbug.com/998273): We should not forward visual properties to
2076 // frozen render widgets.
Erik Chenc71b51fe2019-09-19 21:34:272077 // The widget may have been destroyed while the IPC was in flight.
2078 RenderWidget* widget = RenderWidget::FromRoutingID(widget_routing_id);
2079 if (widget) {
2080 widget->SynchronizeVisualPropertiesFromRenderView(visual_properties);
Erik Chena515bf32019-09-09 21:53:032081 }
2082}
2083
W. James MacLean7c8581072019-06-18 18:07:532084void RenderViewImpl::OnUpdatePageVisualProperties(
2085 const gfx::Size& viewport_size) {
Erik Chena515bf32019-09-09 21:53:032086 // TODO(https://crbug.com/998273): Handle visual_properties appropriately.
W. James MacLean7c8581072019-06-18 18:07:532087 // Using this pathway to update the visual viewport should only happen for
2088 // remote main frames. Local main frames will update the viewport size by
2089 // RenderWidget calling RenderViewImpl::ResizeVisualViewport() directly.
2090 if (!main_render_frame_) {
2091 // Since the viewport size comes directly from the browser, we may
2092 // need to adjust it for device scale factor.
2093 // TODO(wjmaclean): we should look into having the browser apply this scale
2094 // before sending the viewport size.
2095 gfx::Size device_scale_factor_scaled_visual_viewport_size = viewport_size;
2096 if (RenderThreadImpl::current()->IsUseZoomForDSFEnabled()) {
2097 device_scale_factor_scaled_visual_viewport_size = gfx::ScaleToCeiledSize(
2098 viewport_size, GetScreenInfo().device_scale_factor);
2099 }
Erik Chen995c17f2019-08-29 18:29:492100 webview()->Resize(device_scale_factor_scaled_visual_viewport_size);
W. James MacLean7c8581072019-06-18 18:07:532101 }
2102}
2103
2104void RenderViewImpl::ResizeVisualViewportForWidget(
2105 const gfx::Size& scaled_viewport_size) {
2106 // This function is currently only called for local main frames. Once remote
2107 // main frames no longer have a RenderWidget, they may also route through
Erik Chena515bf32019-09-09 21:53:032108 // here via RenderViewImpl::OnUpdateLocalMainFramePageVisualProperties(). In
2109 // that case, WebViewImpl will need to implement its Size() function based on
2110 // something other than the widget size.
W. James MacLean7c8581072019-06-18 18:07:532111 webview()->ResizeVisualViewport(scaled_viewport_size);
2112}
2113
Francois Doray47f759d2018-06-11 18:13:512114void RenderViewImpl::SetPageFrozen(bool frozen) {
2115 if (webview())
2116 webview()->SetPageFrozen(frozen);
Fadi Meawada6573e02018-03-10 00:52:112117}
2118
Yuzu Saijodfba8fa62019-08-27 02:15:222119void RenderViewImpl::PutPageIntoBackForwardCache() {
2120 if (webview())
2121 webview()->PutPageIntoBackForwardCache();
2122}
2123
2124void RenderViewImpl::RestorePageFromBackForwardCache() {
2125 if (webview())
2126 webview()->RestorePageFromBackForwardCache();
2127}
2128
W. James MacLean62198672019-06-04 16:46:102129// This function receives TextAutosizerPageInfo from the main frame's renderer
2130// and makes it available to other renderers with frames on the same page.
2131void RenderViewImpl::OnTextAutosizerPageInfoChanged(
2132 const blink::WebTextAutosizerPageInfo& page_info) {
2133 // Only propagate the remote page info if our main frame is remote. It's
2134 // possible a main frame renderer may receive this message, as SendPageMessage
2135 // in RenderFrameHostManager may send to a speculative RenderFrameHost that
2136 // corresponds to a local main frame. Since a local main frame will generate
2137 // these values for itself, we shouldn't override them with values from
2138 // another renderer.
2139 if (!webview()->MainFrame()->IsWebLocalFrame())
2140 webview()->SetTextAutosizePageInfo(page_info);
2141}
2142
alexmos3fcd0ca2015-10-23 18:18:332143void RenderViewImpl::SetFocus(bool enable) {
Erik Chena2819852019-08-28 01:02:282144 // This is only called from RenderFrameProxy.
2145 CHECK(!webview()->MainFrame()->IsWebLocalFrame());
2146 webview()->SetFocus(enable);
[email protected]b2e4c70132013-10-03 02:07:512147}
2148
W. James MacLean233a64ff2019-05-18 16:18:492149void RenderViewImpl::PageScaleFactorChanged(float page_scale_factor) {
ccameronb7c1d6c2015-03-09 17:08:242150 if (!webview())
2151 return;
mcnee432e47d2015-11-09 19:37:462152
avia3dca182016-03-19 01:09:522153 Send(new ViewHostMsg_PageScaleFactorChanged(GetRoutingID(),
W. James MacLeanf40603e2019-03-25 17:23:062154 page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:242155}
2156
W. James MacLean62198672019-06-04 16:46:102157void RenderViewImpl::DidUpdateTextAutosizerPageInfo(
2158 const blink::WebTextAutosizerPageInfo& page_info) {
2159 DCHECK(webview()->MainFrame()->IsWebLocalFrame());
2160 Send(new ViewHostMsg_NotifyTextAutosizerPageInfoChangedInLocalMainFrame(
2161 GetRoutingID(), page_info));
2162}
2163
Blink Reformat1c4d759e2017-04-09 16:34:542164void RenderViewImpl::PageImportanceSignalsChanged() {
kouhei40f03cb2015-09-24 07:47:012165 if (!webview() || !main_render_frame_)
2166 return;
2167
Blink Reformat1c4d759e2017-04-09 16:34:542168 auto* web_signals = webview()->PageImportanceSignals();
kouhei40f03cb2015-09-24 07:47:012169
2170 PageImportanceSignals signals;
Blink Reformat1c4d759e2017-04-09 16:34:542171 signals.had_form_interaction = web_signals->HadFormInteraction();
kouhei40f03cb2015-09-24 07:47:012172
2173 main_render_frame_->Send(new FrameHostMsg_UpdatePageImportanceSignals(
2174 main_render_frame_->GetRoutingID(), signals));
2175}
2176
danakj9a8a9cf2018-07-17 23:52:122177void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) {
Erik Chene4ae6b42019-10-01 12:06:282178 // Auto resize should only happen on local main frames.
2179 DCHECK(render_widget_);
danakj872a96a12019-09-18 21:53:142180 render_widget_->DidAutoResize(newSize);
danakj9a8a9cf2018-07-17 23:52:122181}
2182
danakja2c9d0a92018-07-25 20:01:182183void RenderViewImpl::DidFocus(blink::WebLocalFrame* calling_frame) {
2184 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2185 // we won't have to test for user gesture anymore and we can
2186 // move that code back to render_widget.cc
2187 if (WebUserGestureIndicator::IsProcessingUserGesture(calling_frame) &&
Kent Tamura2eab5b12018-12-07 04:31:232188 !RenderThreadImpl::current()->web_test_mode()) {
danakja2c9d0a92018-07-25 20:01:182189 Send(new ViewHostMsg_Focus(GetRoutingID()));
2190
2191 // Tattle on the frame that called |window.focus()|.
2192 RenderFrameImpl* calling_render_frame =
2193 RenderFrameImpl::FromWebFrame(calling_frame);
2194 if (calling_render_frame)
2195 calling_render_frame->FrameDidCallFocus();
2196 }
2197}
2198
danakj46b3dde2018-10-18 16:12:172199blink::WebScreenInfo RenderViewImpl::GetScreenInfo() {
Albert J. Wonga3dbd5442019-09-18 10:38:282200 const ScreenInfo& info = page_properties()->GetScreenInfo();
danakj46b3dde2018-10-18 16:12:172201
2202 blink::WebScreenInfo web_screen_info;
2203 web_screen_info.device_scale_factor = info.device_scale_factor;
2204 web_screen_info.color_space = info.color_space;
2205 web_screen_info.depth = info.depth;
2206 web_screen_info.depth_per_component = info.depth_per_component;
2207 web_screen_info.is_monochrome = info.is_monochrome;
2208 web_screen_info.rect = blink::WebRect(info.rect);
2209 web_screen_info.available_rect = blink::WebRect(info.available_rect);
2210 switch (info.orientation_type) {
2211 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
2212 web_screen_info.orientation_type =
2213 blink::kWebScreenOrientationPortraitPrimary;
2214 break;
2215 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
2216 web_screen_info.orientation_type =
2217 blink::kWebScreenOrientationPortraitSecondary;
2218 break;
2219 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
2220 web_screen_info.orientation_type =
2221 blink::kWebScreenOrientationLandscapePrimary;
2222 break;
2223 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
2224 web_screen_info.orientation_type =
2225 blink::kWebScreenOrientationLandscapeSecondary;
2226 break;
2227 default:
2228 web_screen_info.orientation_type = blink::kWebScreenOrientationUndefined;
2229 break;
2230 }
2231 web_screen_info.orientation_angle = info.orientation_angle;
2232
2233 return web_screen_info;
2234}
2235
[email protected]20657a82012-08-21 20:23:032236#if defined(OS_ANDROID)
braveyao1d8ee7b2017-03-29 21:10:042237void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) {
2238 if (!main_render_frame_)
2239 return;
2240
Guido Urdanetadc7090372019-07-29 17:59:542241 blink::WebMediaStreamDeviceObserver* media_stream_device_observer =
Antonio Gomes32f24faf2019-08-18 16:41:362242 main_render_frame_->MediaStreamDeviceObserver();
Chandan Padhi26dbd9b32017-11-27 11:13:352243 if (!media_stream_device_observer)
braveyao1d8ee7b2017-03-29 21:10:042244 return;
2245
Guido Urdaneta73fa6632019-01-14 18:46:262246 blink::MediaStreamDevices video_devices =
Chandan Padhi26dbd9b32017-11-27 11:13:352247 media_stream_device_observer->GetNonScreenCaptureDevices();
braveyao1d8ee7b2017-03-29 21:10:042248 RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices(
Chandan Padhi6dbfb732017-09-01 16:08:492249 video_devices, suspend);
braveyao1d8ee7b2017-03-29 21:10:042250}
estade6b9696bd2016-05-04 23:51:362251#endif // defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:032252
[email protected]b283d292013-02-21 08:40:342253unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
2254 return history_list_length_;
2255}
2256
[email protected]cc290f902013-03-04 20:06:022257void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
Nasko Oskova463a052018-05-08 16:42:142258 // If the main frame is remote, return immediately. Page level focus
2259 // should be set from the browser process, so if needed by tests it should
2260 // be properly supported.
2261 if (webview()->MainFrame()->IsWebRemoteFrame())
2262 return;
2263
danakj872a96a12019-09-18 21:53:142264 if (enable == render_widget_->has_focus())
danakja2c9d0a92018-07-25 20:01:182265 return;
2266
[email protected]cc290f902013-03-04 20:06:022267 if (enable) {
danakja2c9d0a92018-07-25 20:01:182268 SetActiveForWidget(true);
2269 // Fake an IPC message so go through the IPC handler.
danakj872a96a12019-09-18 21:53:142270 render_widget_->OnSetFocus(true);
[email protected]cc290f902013-03-04 20:06:022271 } else {
danakja2c9d0a92018-07-25 20:01:182272 // Fake an IPC message so go through the IPC handler.
danakj872a96a12019-09-18 21:53:142273 render_widget_->OnSetFocus(false);
danakja2c9d0a92018-07-25 20:01:182274 SetActiveForWidget(false);
[email protected]cc290f902013-03-04 20:06:022275 }
2276}
2277
W. James MacLeand973a55b2018-11-29 21:39:132278void RenderViewImpl::OnAnimateDoubleTapZoomInMainFrame(
2279 const blink::WebPoint& point,
2280 const blink::WebRect& bound) {
2281 webview()->AnimateDoubleTapZoom(point, bound);
2282}
2283
W. James MacLean5372eb72018-12-19 12:56:362284void RenderViewImpl::OnZoomToFindInPageRect(
2285 const blink::WebRect& rect_to_zoom) {
2286 webview()->ZoomToFindInPageRect(rect_to_zoom);
2287}
2288
danakjd51fd53d2018-12-21 23:06:092289void RenderViewImpl::OnSetBackgroundOpaque(bool opaque) {
2290 if (!webview())
2291 return;
2292
2293 if (opaque) {
2294 webview()->ClearBaseBackgroundColorOverride();
2295 webview()->ClearBackgroundColorOverride();
2296 } else {
2297 webview()->SetBaseBackgroundColorOverride(SK_ColorTRANSPARENT);
2298 webview()->SetBackgroundColorOverride(SK_ColorTRANSPARENT);
2299 }
2300}
2301
danakj295c43f182019-03-13 16:37:172302// static
2303scoped_refptr<base::SingleThreadTaskRunner>
2304RenderViewImpl::GetCleanupTaskRunner() {
2305 return RenderThreadImpl::current_blink_platform_impl()
2306 ->main_thread_scheduler()
2307 ->CleanupTaskRunner();
2308}
2309
[email protected]e9ff79c2012-10-19 21:31:262310} // namespace content