blob: d43a6a7d0ede9bd11ef6018f4b927e4c7a829678 [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"
clamyda97e8322014-10-07 21:57:2555#include "content/public/common/page_state.h"
Leon Han963dc182018-11-06 05:41:4856#include "content/public/common/referrer_type_converters.h"
[email protected]818915cd2012-11-20 13:14:1157#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0358#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3459#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0760#include "content/public/renderer/document_state.h"
Avi Drissman07d22452019-03-25 17:56:3961#include "content/public/renderer/render_thread.h"
[email protected]3a034ebb2011-10-03 19:19:4462#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3663#include "content/public/renderer/render_view_visitor.h"
scottmg8e6c6082017-02-13 23:15:4864#include "content/public/renderer/window_features_converter.h"
[email protected]dc293a72013-07-01 11:11:2265#include "content/renderer/drop_data_builder.h"
[email protected]dc064352014-04-25 08:36:3866#include "content/renderer/history_serialization.h"
[email protected]92d457802013-04-01 19:18:4967#include "content/renderer/internal_document_state_data.h"
John Abd-El-Malek6b56ef712017-10-21 22:52:4668#include "content/renderer/loader/request_extra_data.h"
Amos Limbcc710e2018-06-08 05:51:1769#include "content/renderer/media/audio/audio_device_factory.h"
[email protected]227692c52013-05-31 22:43:0470#include "content/renderer/render_frame_impl.h"
[email protected]5a7100d2014-05-19 01:29:0471#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0572#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4473#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4474#include "content/renderer/render_widget_fullscreen_pepper.h"
Daniel Murphye3eec92c2018-02-23 19:09:1575#include "content/renderer/renderer_blink_platform_impl.h"
John Abd-El-Malek312a30bb2017-10-23 19:51:5276#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:2177#include "content/renderer/web_ui_extension_data.h"
[email protected]f5961142013-04-17 23:09:4278#include "media/audio/audio_output_device.h"
[email protected]ee68378a2010-08-10 01:05:4179#include "media/base/media_switches.h"
Scott Violeta35f9a42018-03-22 22:00:4480#include "media/media_buildflags.h"
servolkf54f5c8f2015-02-24 20:32:3981#include "media/renderers/audio_renderer_impl.h"
Dale Curtis863022e2017-08-19 02:05:3482#include "media/video/gpu_video_accelerator_factories.h"
Julie Jeongeun Kimcaacf9102019-09-12 02:13:0583#include "mojo/public/cpp/bindings/pending_receiver.h"
[email protected]d1ef81d2012-07-24 11:39:3684#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2985#include "net/base/escape.h"
86#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:0987#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:0488#include "net/http/http_util.h"
Tarun Bansal73d67f02018-01-17 05:56:2589#include "net/nqe/effective_connection_type.h"
Scott Violet02e38b92018-03-27 23:42:1490#include "ppapi/buildflags/buildflags.h"
lukenb171b532014-09-24 05:50:3891#include "skia/ext/platform_canvas.h"
Blink Reformata30d4232018-04-07 15:31:0692#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
Daniel Murphy95792ef2018-10-04 01:29:5593#include "third_party/blink/public/common/dom_storage/session_storage_namespace_id.h"
Mustaq Ahmed76c2f4312018-06-07 20:48:0194#include "third_party/blink/public/common/frame/user_activation_update_source.h"
Dave Tapuska129cef82019-12-19 16:36:4895#include "third_party/blink/public/common/input/web_input_event.h"
Gyuyoung Kima252d4a2020-09-16 07:20:3196#include "third_party/blink/public/common/switches.h"
Gyuyoung Kim1ac4ca782020-09-11 03:32:5197#include "third_party/blink/public/common/web_preferences/web_preferences.h"
Blink Reformata30d4232018-04-07 15:31:0698#include "third_party/blink/public/platform/file_path_conversion.h"
Antonio Gomes925f9b92019-07-30 23:23:2399#include "third_party/blink/public/platform/modules/video_capture/web_video_capture_impl_manager.h"
Blink Reformata30d4232018-04-07 15:31:06100#include "third_party/blink/public/platform/url_conversion.h"
101#include "third_party/blink/public/platform/web_connection_type.h"
102#include "third_party/blink/public/platform/web_effective_connection_type.h"
103#include "third_party/blink/public/platform/web_http_body.h"
Blink Reformata30d4232018-04-07 15:31:06104#include "third_party/blink/public/platform/web_input_event_result.h"
105#include "third_party/blink/public/platform/web_network_state_notifier.h"
Blink Reformata30d4232018-04-07 15:31:06106#include "third_party/blink/public/platform/web_rect.h"
107#include "third_party/blink/public/platform/web_runtime_features.h"
108#include "third_party/blink/public/platform/web_size.h"
109#include "third_party/blink/public/platform/web_string.h"
110#include "third_party/blink/public/platform/web_url.h"
111#include "third_party/blink/public/platform/web_url_error.h"
112#include "third_party/blink/public/platform/web_url_request.h"
113#include "third_party/blink/public/platform/web_url_response.h"
114#include "third_party/blink/public/platform/web_vector.h"
115#include "third_party/blink/public/public_buildflags.h"
Guido Urdanetadc7090372019-07-29 17:59:54116#include "third_party/blink/public/web/modules/mediastream/web_media_stream_device_observer.h"
Blink Reformata30d4232018-04-07 15:31:06117#include "third_party/blink/public/web/web_autofill_client.h"
118#include "third_party/blink/public/web/web_ax_object.h"
Blink Reformata30d4232018-04-07 15:31:06119#include "third_party/blink/public/web/web_document.h"
120#include "third_party/blink/public/web/web_dom_event.h"
121#include "third_party/blink/public/web/web_dom_message_event.h"
122#include "third_party/blink/public/web/web_element.h"
Blink Reformata30d4232018-04-07 15:31:06123#include "third_party/blink/public/web/web_form_control_element.h"
124#include "third_party/blink/public/web/web_form_element.h"
125#include "third_party/blink/public/web/web_frame.h"
126#include "third_party/blink/public/web/web_frame_content_dumper.h"
127#include "third_party/blink/public/web/web_frame_widget.h"
128#include "third_party/blink/public/web/web_history_item.h"
129#include "third_party/blink/public/web/web_hit_test_result.h"
130#include "third_party/blink/public/web/web_input_element.h"
131#include "third_party/blink/public/web/web_local_frame.h"
Blink Reformata30d4232018-04-07 15:31:06132#include "third_party/blink/public/web/web_navigation_policy.h"
danakj25ec6e2b2018-09-26 17:01:31133#include "third_party/blink/public/web/web_page_popup.h"
Blink Reformata30d4232018-04-07 15:31:06134#include "third_party/blink/public/web/web_plugin.h"
Blink Reformata30d4232018-04-07 15:31:06135#include "third_party/blink/public/web/web_range.h"
136#include "third_party/blink/public/web/web_render_theme.h"
137#include "third_party/blink/public/web/web_script_source.h"
138#include "third_party/blink/public/web/web_searchable_form_data.h"
139#include "third_party/blink/public/web/web_security_policy.h"
140#include "third_party/blink/public/web/web_settings.h"
Blink Reformata30d4232018-04-07 15:31:06141#include "third_party/blink/public/web/web_view.h"
142#include "third_party/blink/public/web/web_window_features.h"
[email protected]b3a97b52014-07-09 06:25:05143#include "third_party/icu/source/common/unicode/uchar.h"
144#include "third_party/icu/source/common/unicode/uscript.h"
esecklerf2bd55f72017-03-31 09:11:57145#include "third_party/skia/include/core/SkColor.h"
Ionel Popescu2649f2f2020-01-10 10:06:59146#include "ui/base/ui_base_features.h"
[email protected]1400e6dc2013-04-27 02:36:27147#include "ui/base/ui_base_switches_util.h"
tfarina655f81d2014-12-23 02:38:50148#include "ui/gfx/geometry/point.h"
tfarina3b0452d2014-12-31 15:20:09149#include "ui/gfx/geometry/rect.h"
150#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32151#include "ui/gfx/geometry/size_conversions.h"
[email protected]08397d52011-02-05 01:53:38152#include "ui/gfx/native_widget_types.h"
ccameron772317d2017-06-04 18:35:03153#include "ui/gfx/switches.h"
mfomitchev3ba450ad2017-04-03 18:20:40154#include "ui/latency/latency_info.h"
csharrisond88f9752016-10-26 23:56:36155#include "url/origin.h"
markdittmer67b71ea2016-03-03 22:40:03156#include "url/url_constants.h"
[email protected]c4a9e932011-03-05 04:05:55157#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:29158
[email protected]25fb9b32012-04-27 03:21:55159#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25160#include <cpu-features.h>
161
dalecurtiscd971252016-09-21 16:09:00162#include "base/android/build_info.h"
kylechare7d8d5c72018-01-05 19:06:28163#include "content/child/child_thread_impl.h"
tfarina3b0452d2014-12-31 15:20:09164#include "ui/gfx/geometry/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40165
Avi Drissman7c57be72020-07-29 20:09:46166#elif defined(OS_MAC)
[email protected]78043bdd2010-04-05 18:45:33167#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57168#endif
169
brettw4b461082016-11-19 18:55:16170#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]ea2fb972013-08-07 05:44:26171#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
172#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26173#endif
174
[email protected]180ef242013-11-07 06:50:46175using blink::WebAXObject;
[email protected]180ef242013-11-07 06:50:46176using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46177using blink::WebData;
[email protected]180ef242013-11-07 06:50:46178using blink::WebDocument;
[email protected]180ef242013-11-07 06:50:46179using blink::WebDragOperation;
[email protected]180ef242013-11-07 06:50:46180using blink::WebElement;
[email protected]180ef242013-11-07 06:50:46181using blink::WebFormControlElement;
182using blink::WebFormElement;
183using blink::WebFrame;
dglazkov03223492016-02-08 22:16:03184using blink::WebFrameContentDumper;
[email protected]180ef242013-11-07 06:50:46185using blink::WebGestureEvent;
186using blink::WebHistoryItem;
dglazkov8d0c21dd2016-08-06 15:56:36187using blink::WebHitTestResult;
Sergio Villar Senineb8c252452019-10-04 17:18:28188using blink::WebHTTPBody;
[email protected]180ef242013-11-07 06:50:46189using blink::WebInputElement;
190using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22191using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46192using blink::WebMouseEvent;
193using blink::WebNavigationPolicy;
194using blink::WebNavigationType;
195using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46196using blink::WebRect;
Sergio Villar Senineb8c252452019-10-04 17:18:28197using blink::WebRuntimeFeatures;
[email protected]180ef242013-11-07 06:50:46198using blink::WebScriptSource;
199using blink::WebSearchableFormData;
200using blink::WebSecurityOrigin;
201using blink::WebSecurityPolicy;
[email protected]180ef242013-11-07 06:50:46202using blink::WebSettings;
203using blink::WebSize;
[email protected]180ef242013-11-07 06:50:46204using blink::WebString;
[email protected]180ef242013-11-07 06:50:46205using blink::WebTouchEvent;
206using blink::WebURL;
207using blink::WebURLError;
208using blink::WebURLRequest;
209using blink::WebURLResponse;
[email protected]180ef242013-11-07 06:50:46210using blink::WebVector;
211using blink::WebView;
212using blink::WebWidget;
213using blink::WebWindowFeatures;
[email protected]e1acf6f2008-10-27 20:43:33214
[email protected]e9ff79c2012-10-19 21:31:26215namespace content {
216
initial.commit09911bf2008-07-26 23:55:29217//-----------------------------------------------------------------------------
218
[email protected]180ef242013-11-07 06:50:46219typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
jbroman8319b232017-03-08 22:53:29220static base::LazyInstance<ViewMap>::Leaky g_view_map =
[email protected]058561b2012-12-03 06:48:22221 LAZY_INSTANCE_INITIALIZER;
scottmg5e65e3a2017-03-08 08:48:46222typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap;
jbroman8319b232017-03-08 22:53:29223static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map =
224 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02225
[email protected]882daa92009-11-05 16:31:31226// Time, in seconds, we delay before sending content state changes (such as form
227// state and scroll position) to the browser. We delay sending changes to avoid
228// spamming the browser.
229// To avoid having tab/session restore require sending a message to get the
230// current content state during tab closing we use a shorter timeout for the
231// foreground renderer. This means there is a small window of time from which
232// content state is modified and not sent to session restore, but this is
233// better than having to wake up all renderers during shutdown.
avif937e1d2014-11-02 18:13:07234const int kDelaySecondsForContentStateSyncHidden = 5;
235const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29236
dcheng35d31c112015-07-22 00:17:36237static RenderViewImpl* (*g_create_render_view_impl)(
238 CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15239 const mojom::CreateViewParams&) = nullptr;
[email protected]8d41d7612012-11-14 20:32:19240
[email protected]c6bc20332014-02-28 18:30:39241// static
[email protected]65920f332014-03-04 21:14:18242WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32243 WebNavigationPolicy policy) {
244 switch (policy) {
Blink Reformat1c4d759e2017-04-09 16:34:54245 case blink::kWebNavigationPolicyDownload:
nick3b04f322016-08-31 19:29:19246 return WindowOpenDisposition::SAVE_TO_DISK;
Blink Reformat1c4d759e2017-04-09 16:34:54247 case blink::kWebNavigationPolicyCurrentTab:
nick3b04f322016-08-31 19:29:19248 return WindowOpenDisposition::CURRENT_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54249 case blink::kWebNavigationPolicyNewBackgroundTab:
nick3b04f322016-08-31 19:29:19250 return WindowOpenDisposition::NEW_BACKGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54251 case blink::kWebNavigationPolicyNewForegroundTab:
nick3b04f322016-08-31 19:29:19252 return WindowOpenDisposition::NEW_FOREGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54253 case blink::kWebNavigationPolicyNewWindow:
nick3b04f322016-08-31 19:29:19254 return WindowOpenDisposition::NEW_WINDOW;
Blink Reformat1c4d759e2017-04-09 16:34:54255 case blink::kWebNavigationPolicyNewPopup:
nick3b04f322016-08-31 19:29:19256 return WindowOpenDisposition::NEW_POPUP;
[email protected]48861e22013-01-09 00:27:32257 default:
258 NOTREACHED() << "Unexpected WebNavigationPolicy";
nick3b04f322016-08-31 19:29:19259 return WindowOpenDisposition::IGNORE_ACTION;
[email protected]48861e22013-01-09 00:27:32260 }
261}
262
initial.commit09911bf2008-07-26 23:55:29263///////////////////////////////////////////////////////////////////////////////
264
[email protected]217690d2012-01-27 07:33:11265namespace {
266
scottmgde42fb92017-02-10 17:56:03267content::mojom::WindowContainerType WindowFeaturesToContainerType(
scottmg05324cb2017-02-09 23:46:04268 const blink::WebWindowFeatures& window_features) {
japhetbfc47892017-06-02 23:01:19269 if (window_features.background) {
270 if (window_features.persistent)
scottmgde42fb92017-02-10 17:56:03271 return content::mojom::WindowContainerType::PERSISTENT;
scottmg05324cb2017-02-09 23:46:04272 else
scottmgde42fb92017-02-10 17:56:03273 return content::mojom::WindowContainerType::BACKGROUND;
scottmg05324cb2017-02-09 23:46:04274 } else {
scottmgde42fb92017-02-10 17:56:03275 return content::mojom::WindowContainerType::NORMAL;
scottmg05324cb2017-02-09 23:46:04276 }
277}
278
[email protected]217690d2012-01-27 07:33:11279} // namespace
280
Hajime Hoshi315a61f2018-08-14 17:27:28281RenderViewImpl::RenderViewImpl(CompositorDependencies* compositor_deps,
282 const mojom::CreateViewParams& params)
Albert J. Wong7faa3da2019-03-21 20:43:43283 : routing_id_(params.view_id),
danakj73dd3032018-07-28 17:49:53284 renderer_wide_named_frame_lookup_(
285 params.renderer_wide_named_frame_lookup),
danakj77eb7e82020-01-09 19:38:46286 widgets_never_composited_(params.never_composited),
danakj4b8a2d9a2019-10-15 15:53:59287 compositor_deps_(compositor_deps),
Jeremy Roman3bca4bf2019-07-11 03:41:25288 session_storage_namespace_id_(params.session_storage_namespace_id) {
Daniel Murphy95792ef2018-10-04 01:29:55289 DCHECK(!session_storage_namespace_id_.empty())
290 << "Session storage namespace must be populated.";
Albert J. Wong7faa3da2019-03-21 20:43:43291 // Please put all logic in RenderViewImpl::Initialize().
292}
Albert J. Wong7bbf22d2018-12-20 00:27:27293
Albert J. Wong7faa3da2019-03-21 20:43:43294void RenderViewImpl::Initialize(
Erik Chen10e9b022019-08-21 23:33:23295 CompositorDependencies* compositor_deps,
Albert J. Wong7faa3da2019-03-21 20:43:43296 mojom::CreateViewParamsPtr params,
297 RenderWidget::ShowCallback show_callback,
298 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Avi Drissman07d22452019-03-25 17:56:39299 DCHECK(RenderThread::IsMainThread());
300
Albert J. Wongcb004632018-07-10 22:58:25301 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]075366912013-02-18 07:13:24302
nickf7b38222016-11-22 21:59:35303#if defined(OS_ANDROID)
danakjc87bfede2018-10-10 22:32:49304 bool has_show_callback = !!show_callback;
nickf7b38222016-11-22 21:59:35305#endif
[email protected]676126f72011-01-15 00:03:51306
Antonio Gomesde8657a452020-05-25 17:14:47307 auto opener_frame_token =
Antonio Gomesb3dd5fc2020-05-25 22:53:27308 params->opener_frame_token.value_or(base::UnguessableToken());
309 auto* opener_frame = WebFrame::FromFrameToken(opener_frame_token);
Lukasz Anforowiczaf2f33572018-01-17 14:05:08310
Erik Chen562ca42b2019-08-22 19:46:06311 // The newly created webview_ is owned by this instance.
Gyuyoung Kim1c029712020-07-22 09:21:06312 webview_ = WebView::Create(
313 this, params->hidden,
314 params->type == mojom::ViewWidgetType::kPortal ? true : false,
315 /*compositing_enabled=*/true,
316 opener_frame ? opener_frame->View() : nullptr,
317 std::move(params->blink_page_broadcast));
Albert J. Wong2727e8a82019-02-15 16:56:11318
Antonio Gomes778a0f72020-02-24 13:52:44319 g_view_map.Get().insert(std::make_pair(GetWebView(), this));
avia3dca182016-03-19 01:09:52320 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this));
nasko4c0feb62015-06-05 18:37:06321
danakj242c2e12019-10-08 16:34:15322 bool local_main_frame = params->main_frame_routing_id != MSG_ROUTING_NONE;
323
Gyuyoung Kima252d4a2020-09-16 07:20:31324 webview_->SetWebPreferences(params->web_preferences);
dcheng0ff94cfc2016-03-15 21:50:51325
danakj242c2e12019-10-08 16:34:15326 if (local_main_frame) {
dcheng3ce04b62015-10-26 23:30:55327 main_render_frame_ = RenderFrameImpl::CreateMainFrame(
Erik Chen10e9b022019-08-21 23:33:23328 this, compositor_deps, opener_frame, &params, std::move(show_callback));
danakjaf29226f2018-09-25 17:56:57329 } else {
Dave Tapuska84449382020-05-01 00:39:04330 RenderFrameProxy::CreateFrameProxy(
Antonio Gomesde8657a452020-05-25 17:14:47331 params->proxy_routing_id, GetRoutingID(), opener_frame_token,
Dave Tapuska84449382020-05-01 00:39:04332 MSG_ROUTING_NONE, params->replicated_frame_state,
333 params->main_frame_frame_token, params->devtools_main_frame_token);
nasko4c0feb62015-06-05 18:37:06334 }
335
[email protected]c7c0d822014-04-16 20:19:49336 // TODO(davidben): Move this state from Blink into content.
Balazs Engedyba034e72017-10-27 22:26:28337 if (params->window_was_created_with_opener)
Antonio Gomes778a0f72020-02-24 13:52:44338 GetWebView()->SetOpenedByDOM();
[email protected]c7c0d822014-04-16 20:19:49339
Leon Han2c81b5d2019-01-25 01:58:33340 OnSetRendererPrefs(*params->renderer_preferences);
[email protected]1784b2f2011-11-24 10:53:48341
[email protected]e9ff79c2012-10-19 21:31:26342 GetContentClient()->renderer()->RenderViewCreated(this);
Hajime Hoshif34374412018-03-05 14:32:54343
344 nav_state_sync_timer_.SetTaskRunner(task_runner);
danakjc87bfede2018-10-10 22:32:49345
346#if defined(OS_ANDROID)
347 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated
348 // HandleNavigation codepath.
349 // Renderer-created RenderViews have a ShowCallback because they send a Show
350 // request (ViewHostMsg_ShowWidget, ViewHostMsg_ShowFullscreenWidget, or
351 // FrameHostMsg_ShowCreatedWindow) to the browser to attach them to the UI
352 // there. Browser-created RenderViews do not send a Show request to the
353 // browser, so have no such callback.
354 was_created_by_renderer_ = has_show_callback;
355#endif
initial.commit09911bf2008-07-26 23:55:29356}
357
[email protected]310ebd6302011-10-10 19:06:28358RenderViewImpl::~RenderViewImpl() {
danakjcdfc4262019-10-01 20:09:48359 DCHECK(destroying_); // Always deleted through Destroy().
danakjcdfc4262019-10-01 20:09:48360
361 g_routing_id_view_map.Get().erase(routing_id_);
Albert J. Wongcb004632018-07-10 22:58:25362 RenderThread::Get()->RemoveRoute(routing_id_);
dcheng3ce04b62015-10-26 23:30:55363
[email protected]60c42a8c72009-10-09 04:08:59364#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22365 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49366 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59367 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
368 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22369 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
370 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
371 it != routing_id_views->end(); ++it)
372 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59373#endif
[email protected]676126f72011-01-15 00:03:51374
ericwilligers88e69742016-10-17 19:29:55375 for (auto& observer : observers_)
376 observer.RenderViewGone();
377 for (auto& observer : observers_)
378 observer.OnDestruct();
[email protected]60c42a8c72009-10-09 04:08:59379}
380
381/*static*/
Johann6e6d97582020-07-31 07:54:26382RenderView* RenderView::FromWebView(blink::WebView* webview) {
Avi Drissman07d22452019-03-25 17:56:39383 DCHECK(RenderThread::IsMainThread());
[email protected]a2ef54c2011-10-10 16:20:31384 ViewMap* views = g_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05385 auto it = views->find(webview);
[email protected]a2ef54c2011-10-10 16:20:31386 return it == views->end() ? NULL : it->second;
387}
388
389/*static*/
avi1023d012015-12-25 02:39:14390RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) {
Avi Drissman07d22452019-03-25 17:56:39391 DCHECK(RenderThread::IsMainThread());
[email protected]640e303c2012-12-05 01:36:07392 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05393 auto it = views->find(routing_id);
[email protected]640e303c2012-12-05 01:36:07394 return it == views->end() ? NULL : it->second;
395}
396
397/*static*/
398RenderView* RenderView::FromRoutingID(int routing_id) {
399 return RenderViewImpl::FromRoutingID(routing_id);
400}
401
[email protected]f3a95312014-06-12 16:46:58402/* static */
jochen9c7b8f242015-06-01 15:32:02403size_t RenderView::GetRenderViewCount() {
[email protected]f3a95312014-06-12 16:46:58404 return g_view_map.Get().size();
405}
406
[email protected]640e303c2012-12-05 01:36:07407/*static*/
[email protected]e9ff79c2012-10-19 21:31:26408void RenderView::ForEach(RenderViewVisitor* visitor) {
Avi Drissman07d22452019-03-25 17:56:39409 DCHECK(RenderThread::IsMainThread());
[email protected]625332e02010-12-14 07:48:49410 ViewMap* views = g_view_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05411 for (auto it = views->begin(); it != views->end(); ++it) {
[email protected]60c42a8c72009-10-09 04:08:59412 if (!visitor->Visit(it->second))
413 return;
414 }
415}
416
417/*static*/
nickf7b38222016-11-22 21:59:35418RenderViewImpl* RenderViewImpl::Create(
419 CompositorDependencies* compositor_deps,
Balazs Engedyba034e72017-10-27 22:26:28420 mojom::CreateViewParamsPtr params,
danakjdf1ceb72018-07-18 20:02:25421 RenderWidget::ShowCallback show_callback,
Hajime Hoshiabb3c8f2017-12-04 18:41:39422 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Balazs Engedyba034e72017-10-27 22:26:28423 DCHECK(params->view_id != MSG_ROUTING_NONE);
danakjd434db42020-01-07 22:27:39424 // Frame and widget routing ids come together.
425 DCHECK_EQ(params->main_frame_routing_id == MSG_ROUTING_NONE,
426 params->main_frame_widget_routing_id == MSG_ROUTING_NONE);
427 // We have either a main frame or a proxy routing id.
428 DCHECK_NE(params->main_frame_routing_id != MSG_ROUTING_NONE,
429 params->proxy_routing_id != MSG_ROUTING_NONE);
[email protected]0287e762014-04-11 13:07:58430
danakjd434db42020-01-07 22:27:39431 RenderViewImpl* render_view;
Albert J. Wong7faa3da2019-03-21 20:43:43432 if (g_create_render_view_impl) {
433 render_view = g_create_render_view_impl(compositor_deps, *params);
434 } else {
435 render_view = new RenderViewImpl(compositor_deps, *params);
436 }
437
Erik Chen10e9b022019-08-21 23:33:23438 render_view->Initialize(compositor_deps, std::move(params),
Albert J. Wong7faa3da2019-03-21 20:43:43439 std::move(show_callback), std::move(task_runner));
[email protected]075366912013-02-18 07:13:24440 return render_view;
[email protected]8d41d7612012-11-14 20:32:19441}
442
Erik Chen3433ee02019-08-05 20:14:26443void RenderViewImpl::Destroy() {
danakjcdfc4262019-10-01 20:09:48444 destroying_ = true;
445
Erik Chen562ca42b2019-08-22 19:46:06446 webview_->Close();
Erik Chen3433ee02019-08-05 20:14:26447 // The webview_ is already destroyed by the time we get here, remove any
448 // references to it.
449 g_view_map.Get().erase(webview_);
450 webview_ = nullptr;
Erik Chen562ca42b2019-08-22 19:46:06451
Erik Chen3433ee02019-08-05 20:14:26452 delete this;
453}
454
[email protected]8d41d7612012-11-14 20:32:19455// static
dcheng35d31c112015-07-22 00:17:36456void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
457 *create_render_view_impl)(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15458 const mojom::CreateViewParams&)) {
[email protected]8d41d7612012-11-14 20:32:19459 CHECK(!g_create_render_view_impl);
460 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:29461}
462
[email protected]310ebd6302011-10-10 19:06:28463void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51464 observers_.AddObserver(observer);
465}
466
[email protected]310ebd6302011-10-10 19:06:28467void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
468 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51469 observers_.RemoveObserver(observer);
470}
471
danakja2c9d0a92018-07-25 20:01:18472// RenderWidgetOwnerDelegate -----------------------------------------
fsamuel72464894f2015-12-15 06:59:31473
danakja2c9d0a92018-07-25 20:01:18474void RenderViewImpl::SetActiveForWidget(bool active) {
Antonio Gomes778a0f72020-02-24 13:52:44475 if (GetWebView())
476 GetWebView()->SetIsActive(active);
Albert J. Wongcb004632018-07-10 22:58:25477}
478
danakja2c9d0a92018-07-25 20:01:18479bool RenderViewImpl::SupportsMultipleWindowsForWidget() {
Gyuyoung Kima252d4a2020-09-16 07:20:31480 return webview_->GetWebPreferences().supports_multiple_windows;
danakja2c9d0a92018-07-25 20:01:18481}
482
David Bokan11f6ef482019-03-18 17:47:27483bool RenderViewImpl::ShouldAckSyntheticInputImmediately() {
484 // TODO(bokan): The RequestPresentation API appears not to function in VR. As
485 // a short term workaround for https://crbug.com/940063, ACK input
486 // immediately rather than using RequestPresentation.
Gyuyoung Kima252d4a2020-09-16 07:20:31487 if (webview_->GetWebPreferences().immersive_mode_enabled)
David Bokan11f6ef482019-03-18 17:47:27488 return true;
489 return false;
490}
491
Dave Tapuska49470782020-08-11 19:48:33492bool RenderViewImpl::AutoResizeMode() {
493 return GetWebView()->AutoResizeMode();
danakja2c9d0a92018-07-25 20:01:18494}
495
danakja2c9d0a92018-07-25 20:01:18496void RenderViewImpl::DidReceiveSetFocusEventForWidget() {
497 // This message must always be received when the main frame is a
498 // WebLocalFrame.
Albert J. Wong7bbf22d2018-12-20 00:27:27499 // TODO(ajwong): Can this be removed and just check |delegate_| in
danakja2c9d0a92018-07-25 20:01:18500 // RenderWidget instead?
Antonio Gomes778a0f72020-02-24 13:52:44501 CHECK(GetWebView()->MainFrame()->IsWebLocalFrame());
danakja2c9d0a92018-07-25 20:01:18502}
503
danakja2c9d0a92018-07-25 20:01:18504void RenderViewImpl::DidCommitCompositorFrameForWidget() {
505 for (auto& observer : observers_)
506 observer.DidCommitCompositorFrame();
Antonio Gomesbc5ef252020-03-05 10:37:01507
508 if (GetWebView())
509 GetWebView()->UpdatePreferredSize();
danakja2c9d0a92018-07-25 20:01:18510}
511
512void RenderViewImpl::DidCompletePageScaleAnimationForWidget() {
513 if (auto* focused_frame = GetWebView()->FocusedFrame()) {
514 if (focused_frame->AutofillClient())
515 focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame();
516 }
517}
518
519void RenderViewImpl::ResizeWebWidgetForWidget(
danakj748ef9092019-10-17 23:40:53520 const gfx::Size& widget_size,
danakjd4533c72020-03-11 13:07:10521 const gfx::Size& visible_viewport_size,
Sinan Sahin92a360bc2019-12-05 19:20:45522 cc::BrowserControlsParams browser_controls_params) {
danakjd4533c72020-03-11 13:07:10523 GetWebView()->ResizeWithBrowserControls(widget_size, visible_viewport_size,
524 browser_controls_params);
danakja2c9d0a92018-07-25 20:01:18525}
526
danakja2c9d0a92018-07-25 20:01:18527// IPC message handlers -----------------------------------------
528
danakja2c9d0a92018-07-25 20:01:18529void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset,
530 int history_length) {
531 // -1 <= history_offset < history_length <= kMaxSessionHistoryEntries(50).
532 DCHECK_LE(-1, history_offset);
533 DCHECK_LT(history_offset, history_length);
534 DCHECK_LE(history_length, kMaxSessionHistoryEntries);
535
536 history_list_offset_ = history_offset;
537 history_list_length_ = history_length;
538}
539
danakja2c9d0a92018-07-25 20:01:18540///////////////////////////////////////////////////////////////////////////////
541
542void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget,
543 WebNavigationPolicy policy,
544 const gfx::Rect& initial_rect) {
545 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(),
546 initial_rect));
547}
548
549void RenderViewImpl::ShowCreatedFullscreenWidget(
550 RenderWidget* fullscreen_widget,
551 WebNavigationPolicy policy,
552 const gfx::Rect& initial_rect) {
553 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(),
554 fullscreen_widget->routing_id()));
555}
556
557void RenderViewImpl::SendFrameStateUpdates() {
558 // Tell each frame with pending state to send its UpdateState message.
559 for (int render_frame_routing_id : frames_with_pending_state_) {
560 RenderFrameImpl* frame =
561 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
562 if (frame)
563 frame->SendUpdateState();
564 }
565 frames_with_pending_state_.clear();
566}
567
danakja2c9d0a92018-07-25 20:01:18568// IPC::Listener -------------------------------------------------------------
fsamuel72464894f2015-12-15 06:59:31569
[email protected]310ebd6302011-10-10 19:06:28570bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
Antonio Gomes778a0f72020-02-24 13:52:44571 WebFrame* main_frame = GetWebView() ? GetWebView()->MainFrame() : nullptr;
Avi Drissmanb5f8e242017-12-12 05:21:56572 if (main_frame) {
573 GURL active_url;
574 if (main_frame->IsWebLocalFrame())
575 active_url = main_frame->ToWebLocalFrame()->GetDocument().Url();
lukaszabedb4b22017-06-23 00:00:13576 GetContentClient()->SetActiveURL(
Avi Drissmanb5f8e242017-12-12 05:21:56577 active_url, main_frame->Top()->GetSecurityOrigin().ToString().Utf8());
578 }
[email protected]f8b6b6f2009-03-10 16:48:26579
dchenga2d442c22016-10-13 15:39:21580 for (auto& observer : observers_) {
581 if (observer.OnMessageReceived(message))
[email protected]676126f72011-01-15 00:03:51582 return true;
dchenga2d442c22016-10-13 15:39:21583 }
[email protected]b2abac72009-02-26 12:39:28584
[email protected]a95986a82010-12-24 06:19:28585 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33586 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
initial.commit09911bf2008-07-26 23:55:29587 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]30f75e62009-02-25 22:01:00588 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
wjmaclean64951902016-04-29 20:59:12589
590 // Page messages.
alexmos136fd6e62016-08-15 20:58:41591 IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength,
592 OnSetHistoryOffsetAndLength)
Bruce Long1e3e1f542019-10-16 17:56:28593 IPC_MESSAGE_HANDLER(PageMsg_SetRendererPrefs, OnSetRendererPrefs)
lfg717154072016-06-30 15:04:16594
[email protected]a794f3a2013-10-30 17:00:32595 // Adding a new message? Add platform independent ones first, then put the
596 // platform specific ones at the end.
initial.commit09911bf2008-07-26 23:55:29597 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40598
[email protected]a95986a82010-12-24 06:19:28599 return handled;
initial.commit09911bf2008-07-26 23:55:29600}
601
[email protected]180ef242013-11-07 06:50:46602// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:52603
Mustaq Ahmed55944cb2018-05-25 20:44:27604// TODO(csharrison): Migrate this method to WebLocalFrameClient /
605// RenderFrameImpl, as it is now serviced by a mojo interface scoped to the
606// opener frame.
Daniel Murphyc8e991a2018-10-12 22:09:03607WebView* RenderViewImpl::CreateView(
608 WebLocalFrame* creator,
609 const WebURLRequest& request,
610 const WebWindowFeatures& features,
611 const WebString& frame_name,
612 WebNavigationPolicy policy,
arthursonzognib93a4472020-04-10 07:38:00613 network::mojom::WebSandboxFlags sandbox_flags,
Kent Tamura326c2db2020-07-20 06:28:05614 const blink::FeaturePolicyFeatureState& opener_feature_state,
Daniel Murphyc8e991a2018-10-12 22:09:03615 const blink::SessionStorageNamespaceId& session_storage_namespace_id) {
nick5ae4d2d2017-01-06 01:18:35616 RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator);
rockot5c478a72016-09-28 23:14:18617 mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New();
Mustaq Ahmedc4cb7162018-06-05 16:28:36618
Mustaq Ahmede5f12562019-10-30 18:02:03619 // The user activation check is done at the browser process through
620 // |frame_host->CreateNewWindow()| call below. But the extensions case
621 // handled through the following |if| is an exception.
Mustaq Ahmed8601a562020-01-31 18:05:52622 params->allow_popup = false;
[email protected]00323f02013-07-24 15:47:41623 if (GetContentClient()->renderer()->AllowPopup())
Mustaq Ahmed8601a562020-01-31 18:05:52624 params->allow_popup = true;
Mustaq Ahmedc4cb7162018-06-05 16:28:36625
rockot5c478a72016-09-28 23:14:18626 params->window_container_type = WindowFeaturesToContainerType(features);
Daniel Murphye3eec92c2018-02-23 19:09:15627
Daniel Murphyc8e991a2018-10-12 22:09:03628 params->session_storage_namespace_id = session_storage_namespace_id;
629 // TODO(dmurph): Don't copy session storage when features.noopener is true:
630 // https://html.spec.whatwg.org/multipage/browsers.html#copy-session-storage
631 // https://crbug.com/771959
Daniel Murphye3eec92c2018-02-23 19:09:15632 params->clone_from_session_storage_namespace_id =
633 session_storage_namespace_id_;
Daniel Murphye3eec92c2018-02-23 19:09:15634
Daniel Chengd5e56ff2017-06-24 07:44:02635 const std::string& frame_name_utf8 = frame_name.Utf8(
636 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
637 params->frame_name = frame_name_utf8;
Nate Chapin43f307d2019-04-15 21:04:41638 params->opener_suppressed = features.noopener;
rockot5c478a72016-09-28 23:14:18639 params->disposition = NavigationPolicyToDisposition(policy);
Blink Reformat1c4d759e2017-04-09 16:34:54640 if (!request.IsNull()) {
641 params->target_url = request.Url();
Dominic Farolinoaee9c1b82019-12-18 03:20:10642 params->referrer = blink::mojom::Referrer::New(
643 blink::WebStringToGURL(request.ReferrerString()),
644 request.GetReferrerPolicy());
[email protected]44e55b012013-07-23 14:21:56645 }
scottmg8e6c6082017-02-13 23:15:48646 params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
[email protected]8ab04652010-06-12 02:47:26647
rockot5c478a72016-09-28 23:14:18648 // We preserve this information before sending the message since |params| is
649 // moved on send.
650 bool is_background_tab =
651 params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB;
[email protected]22217ed32013-11-18 18:40:23652
Daniel Cheng8bb30c62017-10-23 20:40:47653 mojom::CreateNewWindowStatus status;
rockot5c478a72016-09-28 23:14:18654 mojom::CreateNewWindowReplyPtr reply;
Balazs Engedya40712f2017-09-15 15:01:11655 auto* frame_host = creator_frame->GetFrameHost();
Daniel Cheng8bb30c62017-10-23 20:40:47656 bool err = !frame_host->CreateNewWindow(std::move(params), &status, &reply);
657 if (err || status == mojom::CreateNewWindowStatus::kIgnore)
rockot5c478a72016-09-28 23:14:18658 return nullptr;
[email protected]48c9cf2d2009-09-16 16:47:52659
Jochen Eisinger515337a2017-05-26 14:12:52660 // For Android WebView, we support a pop-up like behavior for window.open()
661 // even if the embedding app doesn't support multiple windows. In this case,
662 // window.open() will return "window" and navigate it to whatever URL was
Jochen Eisinger8cb28492017-10-04 10:58:13663 // passed. We also don't need to consume user gestures to protect against
664 // multiple windows being opened, because, well, the app doesn't support
665 // multiple windows.
Daniel Cheng8bb30c62017-10-23 20:40:47666 // TODO(dcheng): It's awkward that this is plumbed into Blink but not really
Kent Tamura21d1de62018-12-10 04:45:20667 // used much in Blink, except to enable web testing... perhaps this should
Daniel Cheng8bb30c62017-10-23 20:40:47668 // be checked directly in the browser side.
669 if (status == mojom::CreateNewWindowStatus::kReuse)
Antonio Gomes778a0f72020-02-24 13:52:44670 return GetWebView();
Jochen Eisinger515337a2017-05-26 14:12:52671
Daniel Cheng8bb30c62017-10-23 20:40:47672 DCHECK(reply);
673 DCHECK_NE(MSG_ROUTING_NONE, reply->route_id);
674 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_route_id);
675 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_widget_route_id);
676
Mustaq Ahmed76c2f4312018-06-07 20:48:01677 // The browser allowed creation of a new window and consumed the user
Mustaq Ahmede5f12562019-10-30 18:02:03678 // activation.
Mustaq Ahmed4baa9a6e82019-12-20 23:43:46679 bool was_consumed = creator->ConsumeTransientUserActivation(
680 blink::UserActivationUpdateSource::kBrowser);
Jochen Eisinger8cb28492017-10-04 10:58:13681
[email protected]7912e822014-04-16 02:37:03682 // While this view may be a background extension page, it can spawn a visible
683 // render view. So we just assume that the new one is not another background
684 // page instead of passing on our own value.
685 // TODO(vangelis): Can we tell if the new view will be a background page?
danakj77eb7e82020-01-09 19:38:46686 bool never_composited = false;
[email protected]9115d5f2013-03-24 04:37:41687
[email protected]d6fa88f2013-10-18 16:00:43688 // The initial hidden state for the RenderViewImpl here has to match what the
689 // browser will eventually decide for the given disposition. Since we have to
690 // return from this call synchronously, we just have to make our best guess
691 // and rely on the browser sending a WasHidden / WasShown message if it
692 // disagrees.
Balazs Engedyba034e72017-10-27 22:26:28693 mojom::CreateViewParamsPtr view_params = mojom::CreateViewParams::New();
alexmos5ac402d2015-07-09 07:51:10694
Antonio Gomesb3dd5fc2020-05-25 22:53:27695 view_params->opener_frame_token = creator->GetFrameToken();
avia3dca182016-03-19 01:09:52696 DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID());
alexmos5ac402d2015-07-09 07:51:10697
Balazs Engedyba034e72017-10-27 22:26:28698 view_params->window_was_created_with_opener = true;
Leon Han2c81b5d2019-01-25 01:58:33699 view_params->renderer_preferences = renderer_preferences_.Clone();
Gyuyoung Kima252d4a2020-09-16 07:20:31700 view_params->web_preferences = webview_->GetWebPreferences();
Balazs Engedyba034e72017-10-27 22:26:28701 view_params->view_id = reply->route_id;
Dave Tapuska84449382020-05-01 00:39:04702 view_params->main_frame_frame_token = reply->main_frame_frame_token;
Balazs Engedyba034e72017-10-27 22:26:28703 view_params->main_frame_routing_id = reply->main_frame_route_id;
Dave Tapuska8499eec2020-03-16 17:54:30704 view_params->frame_widget_host = std::move(reply->frame_widget_host);
705 view_params->frame_widget = std::move(reply->frame_widget);
706 view_params->widget_host = std::move(reply->widget_host);
707 view_params->widget = std::move(reply->widget),
Yuzu Saijod46f498a2020-08-04 02:56:22708 view_params->blink_page_broadcast = std::move(reply->page_broadcast);
Dave Tapuska8499eec2020-03-16 17:54:30709 view_params->main_frame_interface_bundle =
710 mojom::DocumentScopedInterfaceBundle::New(
711 std::move(reply->main_frame_interface_bundle->interface_provider),
712 std::move(
713 reply->main_frame_interface_bundle->browser_interface_broker));
Balazs Engedyba034e72017-10-27 22:26:28714 view_params->main_frame_widget_routing_id = reply->main_frame_widget_route_id;
715 view_params->session_storage_namespace_id =
rockot5c478a72016-09-28 23:14:18716 reply->cloned_session_storage_namespace_id;
Daniel Murphy95792ef2018-10-04 01:29:55717 DCHECK(!view_params->session_storage_namespace_id.empty())
718 << "Session storage namespace must be populated.";
Balazs Engedyba034e72017-10-27 22:26:28719 view_params->replicated_frame_state.frame_policy.sandbox_flags =
720 sandbox_flags;
Ehsan Karamad39407082019-02-19 23:38:19721 view_params->replicated_frame_state.opener_feature_state =
722 opener_feature_state;
Balazs Engedyba034e72017-10-27 22:26:28723 view_params->replicated_frame_state.name = frame_name_utf8;
724 view_params->devtools_main_frame_token = reply->devtools_main_frame_token;
Balazs Engedyba034e72017-10-27 22:26:28725 view_params->hidden = is_background_tab;
danakj77eb7e82020-01-09 19:38:46726 view_params->never_composited = never_composited;
danakjbe56b8132019-10-12 00:57:41727 view_params->visual_properties = reply->visual_properties;
naskobd911332014-11-25 01:13:36728
nick5ae4d2d2017-01-06 01:18:35729 // Unretained() is safe here because our calling function will also call
730 // show().
nickf7b38222016-11-22 21:59:35731 RenderWidget::ShowCallback show_callback =
danakjdf1ceb72018-07-18 20:02:25732 base::BindOnce(&RenderFrameImpl::ShowCreatedWindow,
Mustaq Ahmede5f12562019-10-30 18:02:03733 base::Unretained(creator_frame), was_consumed);
nickf7b38222016-11-22 21:59:35734
Balazs Engedyba034e72017-10-27 22:26:28735 RenderViewImpl* view = RenderViewImpl::Create(
danakj4b8a2d9a2019-10-15 15:53:59736 compositor_deps_, std::move(view_params), std::move(show_callback),
Hajime Hoshi6fc91142018-05-11 08:21:17737 creator->GetTaskRunner(blink::TaskType::kInternalDefault));
[email protected]48c9cf2d2009-09-16 16:47:52738
Yury Semikhatsky82730ff2020-02-25 22:29:26739 if (reply->wait_for_debugger) {
danakjd370dbb2020-05-21 17:54:38740 blink::WebFrameWidget* frame_widget =
741 view->GetMainRenderFrame()->GetLocalRootWebFrameWidget();
742 frame_widget->WaitForDebuggerWhenShown();
Yury Semikhatsky82730ff2020-02-25 22:29:26743 }
744
Antonio Gomes778a0f72020-02-24 13:52:44745 return view->GetWebView();
[email protected]48c9cf2d2009-09-16 16:47:52746}
747
danakj19f3e512018-12-14 21:02:05748blink::WebPagePopup* RenderViewImpl::CreatePopup(
749 blink::WebLocalFrame* creator) {
Dave Tapuska8499eec2020-03-16 17:54:30750 mojo::PendingAssociatedRemote<blink::mojom::Widget> blink_widget;
751 mojo::PendingAssociatedReceiver<blink::mojom::Widget> blink_widget_receiver =
752 blink_widget.InitWithNewEndpointAndPassReceiver();
753
754 mojo::PendingAssociatedRemote<blink::mojom::WidgetHost> blink_widget_host;
755 mojo::PendingAssociatedReceiver<blink::mojom::WidgetHost>
756 blink_widget_host_receiver =
757 blink_widget_host.InitWithNewEndpointAndPassReceiver();
758
danakj25ec6e2b2018-09-26 17:01:31759 // Do a synchronous IPC to obtain a routing ID.
760 int32_t widget_routing_id = MSG_ROUTING_NONE;
761 bool success =
Dave Tapuskad9835622020-03-10 17:32:31762 RenderFrameImpl::FromWebFrame(creator)->GetFrameHost()->CreateNewWidget(
Dave Tapuskab686c1b2020-06-09 00:40:23763 std::move(blink_widget_host_receiver), std::move(blink_widget),
764 &widget_routing_id);
danakj25ec6e2b2018-09-26 17:01:31765 if (!success) {
766 // When the renderer is being killed the mojo message will fail.
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28767 return nullptr;
danakj25ec6e2b2018-09-26 17:01:31768 }
769
770 RenderWidget::ShowCallback opener_callback = base::BindOnce(
771 &RenderViewImpl::ShowCreatedPopupWidget, weak_ptr_factory_.GetWeakPtr());
772
danakj93593972019-10-11 00:02:49773 RenderWidget* opener_render_widget =
Erik Chen6bc8da02019-09-20 15:51:38774 RenderFrameImpl::FromWebFrame(creator)->GetLocalRootRenderWidget();
danakj25ec6e2b2018-09-26 17:01:31775
Erik Chen3433ee02019-08-05 20:14:26776 RenderWidget* popup_widget = RenderWidget::CreateForPopup(
danakj93593972019-10-11 00:02:49777 widget_routing_id, opener_render_widget->compositor_deps(),
danakj25ec6e2b2018-09-26 17:01:31778 /*hidden=*/false,
Dave Tapuskab686c1b2020-06-09 00:40:23779 /*never_composited=*/false);
danakj25ec6e2b2018-09-26 17:01:31780
781 // The returned WebPagePopup is self-referencing, so the pointer here is not
danakj45e4a4f2019-03-12 22:50:42782 // an owning pointer. It is de-referenced by calling Close().
danakj25ec6e2b2018-09-26 17:01:31783 blink::WebPagePopup* popup_web_widget =
Dave Tapuska8499eec2020-03-16 17:54:30784 blink::WebPagePopup::Create(popup_widget, std::move(blink_widget_host),
785 std::move(blink_widget_receiver));
danakj25ec6e2b2018-09-26 17:01:31786
787 // Adds a self-reference on the |popup_widget| so it will not be destroyed
788 // when leaving scope. The WebPagePopup takes responsibility for Close()ing
789 // and thus destroying the RenderWidget.
Dave Tapuska4fde1672020-08-26 19:53:46790 popup_widget->InitForPopup(
791 std::move(opener_callback), opener_render_widget, popup_web_widget,
792 opener_render_widget->GetWebWidget()->GetOriginalScreenInfo());
danakj25ec6e2b2018-09-26 17:01:31793 return popup_web_widget;
[email protected]48c9cf2d2009-09-16 16:47:52794}
795
Daniel Murphy31bbb8b12018-02-07 21:44:10796base::StringPiece RenderViewImpl::GetSessionStorageNamespaceId() {
797 CHECK(!session_storage_namespace_id_.empty());
Daniel Murphy0ce6e2c2017-11-21 01:54:26798 return session_storage_namespace_id_;
[email protected]bd92c3a2010-01-13 05:02:34799}
800
Blink Reformat1c4d759e2017-04-09 16:34:54801void RenderViewImpl::PrintPage(WebLocalFrame* frame) {
Erik Chenfaa928c2019-09-20 23:41:15802 RenderFrameImpl* render_frame = RenderFrameImpl::FromWebFrame(frame);
803 RenderWidget* render_widget = render_frame->GetLocalRootRenderWidget();
804
805 render_frame->ScriptedPrint(
Dave Tapuska11acff82020-05-27 16:14:04806 render_widget->GetWebWidget()->HandlingInputEvent());
[email protected]48c9cf2d2009-09-16 16:47:52807}
808
Dave Tapuskafd01e9d2020-07-29 16:38:19809void RenderViewImpl::ZoomLevelChanged() {
ericwilligers88e69742016-10-17 19:29:55810 for (auto& observer : observers_)
811 observer.OnZoomLevelChanged();
danakjcf409aa2019-09-20 15:22:30812}
813
danakjcf409aa2019-09-20 15:22:30814void RenderViewImpl::SetDeviceScaleFactor(bool use_zoom_for_dsf,
815 float device_scale_factor) {
816 if (use_zoom_for_dsf)
Antonio Gomes778a0f72020-02-24 13:52:44817 GetWebView()->SetZoomFactorForDeviceScaleFactor(device_scale_factor);
danakjcf409aa2019-09-20 15:22:30818 else
Antonio Gomes778a0f72020-02-24 13:52:44819 GetWebView()->SetDeviceScaleFactor(device_scale_factor);
danakjcf409aa2019-09-20 15:22:30820}
821
danakjd4533c72020-03-11 13:07:10822void RenderViewImpl::SetVisibleViewportSizeForChildLocalRoot(
823 const gfx::Size& visible_viewport_size) {
824 // The main frame is updated on a different path. If we're in the same frame
825 // tree as it, there's nothing to do for child local roots.
826 if (main_render_frame_)
827 return;
828
829 // RenderWidgets in a RenderView's frame tree without a local main frame
830 // set the size of the WebView to be the |visible_viewport_size|, in order
831 // to limit compositing in (out of process) child frames to what is visible.
832 //
833 // Note that child frames in the same process/RenderView frame tree as the
834 // main frame do not do this in order to not clobber the source of truth in
835 // the main frame.
836 GetWebView()->Resize(visible_viewport_size);
837}
838
danakjcf409aa2019-09-20 15:22:30839void RenderViewImpl::PropagatePageZoomToNewlyAttachedFrame(
840 bool use_zoom_for_dsf,
841 float device_scale_factor) {
842 if (use_zoom_for_dsf)
Antonio Gomes778a0f72020-02-24 13:52:44843 GetWebView()->SetZoomFactorForDeviceScaleFactor(device_scale_factor);
danakjcf409aa2019-09-20 15:22:30844 else
Dave Tapuskafd01e9d2020-07-29 16:38:19845 GetWebView()->SetZoomLevel(GetWebView()->ZoomLevel());
tommycli8aad3ba2015-08-12 17:57:59846}
847
habib.virji597255e2014-09-09 00:30:18848void RenderViewImpl::SetValidationMessageDirection(
849 base::string16* wrapped_main_text,
Miyoung Shin8dabef32020-02-19 16:25:25850 base::i18n::TextDirection main_text_hint,
habib.virji597255e2014-09-09 00:30:18851 base::string16* wrapped_sub_text,
Miyoung Shin8dabef32020-02-19 16:25:25852 base::i18n::TextDirection sub_text_hint) {
853 if (main_text_hint == base::i18n::LEFT_TO_RIGHT) {
habib.virji597255e2014-09-09 00:30:18854 *wrapped_main_text =
855 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
Miyoung Shin8dabef32020-02-19 16:25:25856 } else if (main_text_hint == base::i18n::RIGHT_TO_LEFT &&
habib.virji597255e2014-09-09 00:30:18857 !base::i18n::IsRTL()) {
858 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
859 }
860
861 if (!wrapped_sub_text->empty()) {
Miyoung Shin8dabef32020-02-19 16:25:25862 if (sub_text_hint == base::i18n::RIGHT_TO_LEFT) {
habib.virji597255e2014-09-09 00:30:18863 *wrapped_sub_text =
864 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
Miyoung Shin8dabef32020-02-19 16:25:25865 } else if (sub_text_hint == base::i18n::LEFT_TO_RIGHT) {
habib.virji597255e2014-09-09 00:30:18866 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
867 }
868 }
869}
870
creis69b184a472015-11-26 05:29:51871void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) {
creisce0ef3572017-01-26 17:53:08872 // Keep track of which frames have pending updates.
873 frames_with_pending_state_.insert(frame->GetRoutingID());
creis8eb8ef22015-11-04 22:51:38874
[email protected]882daa92009-11-05 16:31:31875 int delay;
avif937e1d2014-11-02 18:13:07876 if (send_content_state_immediately_)
[email protected]882daa92009-11-05 16:31:31877 delay = 0;
Collin Baker98457b52019-11-06 21:34:29878 else if (GetWebView()->GetVisibilityState() != PageVisibilityState::kVisible)
avif937e1d2014-11-02 18:13:07879 delay = kDelaySecondsForContentStateSyncHidden;
[email protected]882daa92009-11-05 16:31:31880 else
avif937e1d2014-11-02 18:13:07881 delay = kDelaySecondsForContentStateSync;
[email protected]882daa92009-11-05 16:31:31882
avif937e1d2014-11-02 18:13:07883 if (nav_state_sync_timer_.IsRunning()) {
[email protected]882daa92009-11-05 16:31:31884 // The timer is already running. If the delay of the timer maches the amount
885 // we want to delay by, then return. Otherwise stop the timer so that it
886 // gets started with the right delay.
avif937e1d2014-11-02 18:13:07887 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
[email protected]882daa92009-11-05 16:31:31888 return;
avif937e1d2014-11-02 18:13:07889 nav_state_sync_timer_.Stop();
[email protected]882daa92009-11-05 16:31:31890 }
891
creisce0ef3572017-01-26 17:53:08892 // Tell each frame with pending state to inform the browser.
danakj19f3e512018-12-14 21:02:05893 nav_state_sync_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay),
894 this, &RenderViewImpl::SendFrameStateUpdates);
[email protected]882daa92009-11-05 16:31:31895}
896
Blink Reformat1c4d759e2017-04-09 16:34:54897bool RenderViewImpl::AcceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:45898 return renderer_preferences_.can_accept_load_drops;
899}
900
Blink Reformat1c4d759e2017-04-09 16:34:54901void RenderViewImpl::FocusNext() {
avia3dca182016-03-19 01:09:52902 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false));
[email protected]48c9cf2d2009-09-16 16:47:52903}
904
Blink Reformat1c4d759e2017-04-09 16:34:54905void RenderViewImpl::FocusPrevious() {
avia3dca182016-03-19 01:09:52906 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true));
[email protected]48c9cf2d2009-09-16 16:47:52907}
908
Philip Rogers079658812018-08-01 23:19:09909void RenderViewImpl::DidUpdateMainFrameLayout() {
ericwilligers88e69742016-10-17 19:29:55910 for (auto& observer : observers_)
Philip Rogers079658812018-08-01 23:19:09911 observer.DidUpdateMainFrameLayout();
[email protected]169d4282011-11-30 19:33:59912}
913
Michael Martis2415478f2019-04-17 07:35:00914void RenderViewImpl::RegisterRendererPreferenceWatcher(
Julie Jeongeun Kim6d8b7492019-08-20 19:24:11915 mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) {
916 renderer_preference_watchers_.Add(std::move(watcher));
Makoto Shimazuc3c730e2018-08-15 09:51:11917}
918
Blink Reformat1c4d759e2017-04-09 16:34:54919int RenderViewImpl::HistoryBackListCount() {
[email protected]3cc72b12010-03-18 23:03:00920 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:52921}
922
Blink Reformat1c4d759e2017-04-09 16:34:54923int RenderViewImpl::HistoryForwardListCount() {
924 return history_list_length_ - HistoryBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:52925}
926
[email protected]180ef242013-11-07 06:50:46927// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:51928
Blink Reformat1c4d759e2017-04-09 16:34:54929bool RenderViewImpl::CanHandleGestureEvent() {
slangley1a6375e62017-03-29 06:03:23930 return true;
931}
932
Avi Drissman4a800482019-12-12 15:03:28933// TODO(https://crbug.com/937569): Remove this in Chrome 88.
Avi Drissmanfb961262019-03-05 22:50:29934bool RenderViewImpl::AllowPopupsDuringPageUnload() {
Avi Drissman16dfa1c2019-10-09 21:41:13935 // The switch version is for enabling via enterprise policy. The feature
936 // version is for enabling via about:flags and Finch policy.
Avi Drissmanfb961262019-03-05 22:50:29937 const base::CommandLine& command_line =
938 *base::CommandLine::ForCurrentProcess();
Avi Drissman7e5079f2019-09-30 14:06:40939 return command_line.HasSwitch(switches::kAllowPopupsDuringPageUnload) ||
940 base::FeatureList::IsEnabled(features::kAllowPopupsDuringPageUnload);
Avi Drissmanfb961262019-03-05 22:50:29941}
942
Yuzu Saijobe024af02020-05-11 07:35:56943void RenderViewImpl::OnPageVisibilityChanged(PageVisibilityState visibility) {
944#if defined(OS_ANDROID)
945 SuspendVideoCaptureDevices(visibility != PageVisibilityState::kVisible);
946#endif
947 for (auto& observer : observers_)
948 observer.OnPageVisibilityChanged(visibility);
949}
950
Carlos Caballero7934eb62020-08-05 13:24:53951void RenderViewImpl::OnPageFrozenChanged(bool frozen) {
952 if (frozen) {
953 // Make sure browser has the latest info before the page is frozen. If the
954 // page goes into the back-forward cache it could be evicted and some of the
955 // updates lost.
956 nav_state_sync_timer_.Stop();
957 SendFrameStateUpdates();
958 }
959}
960
Blink Reformat1c4d759e2017-04-09 16:34:54961bool RenderViewImpl::CanUpdateLayout() {
slangley1a6375e62017-03-29 06:03:23962 return true;
963}
964
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:49965const std::string& RenderViewImpl::GetAcceptLanguages() {
[email protected]b38806a2013-10-04 16:01:38966 return renderer_preferences_.accept_languages;
967}
968
Blink Reformat1c4d759e2017-04-09 16:34:54969blink::WebString RenderViewImpl::AcceptLanguages() {
970 return WebString::FromUTF8(renderer_preferences_.accept_languages);
[email protected]9982c802013-06-12 15:22:06971}
972
[email protected]e9ff79c2012-10-19 21:31:26973// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:31974
[email protected]310ebd6302011-10-10 19:06:28975bool RenderViewImpl::Send(IPC::Message* message) {
danakj3130f122019-07-16 17:49:47976 // No messages sent through RenderView come without a routing id, yay. Let's
977 // keep that up.
978 CHECK_NE(message->routing_id(), MSG_ROUTING_NONE);
danakj3130f122019-07-16 17:49:47979 return RenderThread::Get()->Send(message);
[email protected]a2ef54c2011-10-10 16:20:31980}
981
mostynbc33353232014-09-12 09:38:31982RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() {
nasko77de2312015-05-12 03:09:16983 return main_render_frame_;
[email protected]b849847b2013-12-10 21:57:58984}
985
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:49986int RenderViewImpl::GetRoutingID() {
Albert J. Wongcb004632018-07-10 22:58:25987 return routing_id_;
[email protected]a2ef54c2011-10-10 16:20:31988}
989
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:49990float RenderViewImpl::GetZoomLevel() {
Dave Tapuskafd01e9d2020-07-29 16:38:19991 return webview_->ZoomLevel();
Marc Treib06d66032017-10-19 08:43:20992}
993
Gyuyoung Kima252d4a2020-09-16 07:20:31994const blink::web_pref::WebPreferences& RenderViewImpl::GetBlinkPreferences() {
995 return webview_->GetWebPreferences();
[email protected]a2ef54c2011-10-10 16:20:31996}
997
Gyuyoung Kima252d4a2020-09-16 07:20:31998void RenderViewImpl::SetBlinkPreferences(
Gyuyoung Kim1ac4ca782020-09-11 03:32:51999 const blink::web_pref::WebPreferences& preferences) {
[email protected]324825d2012-11-30 12:37:151000 OnUpdateWebPreferences(preferences);
1001}
1002
[email protected]180ef242013-11-07 06:50:461003blink::WebView* RenderViewImpl::GetWebView() {
Antonio Gomes778a0f72020-02-24 13:52:441004 return webview_;
[email protected]a2ef54c2011-10-10 16:20:311005}
1006
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:491007bool RenderViewImpl::GetContentStateImmediately() {
avif937e1d2014-11-02 18:13:071008 return send_content_state_immediately_;
[email protected]a2ef54c2011-10-10 16:20:311009}
1010
Gyuyoung Kim1ac4ca782020-09-11 03:32:511011void RenderViewImpl::OnUpdateWebPreferences(
1012 const blink::web_pref::WebPreferences& prefs) {
Gyuyoung Kima252d4a2020-09-16 07:20:311013 webview_->SetWebPreferences(prefs);
initial.commit09911bf2008-07-26 23:55:291014}
1015
[email protected]310ebd6302011-10-10 19:06:281016void RenderViewImpl::OnSetRendererPrefs(
Leon Hanc819dc62019-01-28 04:30:191017 const blink::mojom::RendererPreferences& renderer_prefs) {
[email protected]ebd5ea52014-05-28 14:51:151018 std::string old_accept_languages = renderer_preferences_.accept_languages;
1019
[email protected]80d96fa2009-06-10 22:34:511020 renderer_preferences_ = renderer_prefs;
ananta59b9fe72015-04-07 01:33:261021
Julie Jeongeun Kim6d8b7492019-08-20 19:24:111022 for (auto& watcher : renderer_preference_watchers_)
1023 watcher->NotifyUpdate(renderer_prefs.Clone());
Makoto Shimazuc3c730e2018-08-15 09:51:111024
[email protected]6e282c92009-07-24 01:19:371025 UpdateFontRenderingFromRendererPrefs();
scottmgb92365e2016-08-30 20:54:401026 UpdateThemePrefs();
Leon Han2c81b5d2019-01-25 01:58:331027 blink::SetCaretBlinkInterval(
1028 renderer_prefs.caret_blink_interval.has_value()
1029 ? renderer_prefs.caret_blink_interval.value()
1030 : base::TimeDelta::FromMilliseconds(
Leon Hanc819dc62019-01-28 04:30:191031 blink::mojom::kDefaultCaretBlinkIntervalInMilliseconds));
[email protected]38a85712013-01-02 22:45:021032
Christopher Cameronf8e279d32019-05-15 18:50:561033#if defined(USE_AURA)
[email protected]1596efb2013-01-17 22:13:011034 if (renderer_prefs.use_custom_colors) {
Blink Reformat1c4d759e2017-04-09 16:34:541035 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
Christopher Cameronf6fc7ec2019-05-13 18:52:531036 blink::SetSelectionColors(renderer_prefs.active_selection_bg_color,
1037 renderer_prefs.active_selection_fg_color,
1038 renderer_prefs.inactive_selection_bg_color,
1039 renderer_prefs.inactive_selection_fg_color);
Antonio Gomes778a0f72020-02-24 13:52:441040 if (GetWebView() && GetWebView()->MainFrameWidget())
1041 GetWebView()->MainFrameWidget()->ThemeChanged();
[email protected]644d77e2010-01-27 01:03:101042 }
Christopher Cameronf8e279d32019-05-15 18:50:561043#endif
[email protected]d299d972012-03-23 02:26:551044
Ionel Popescu2649f2f2020-01-10 10:06:591045 if (features::IsFormControlsRefreshEnabled() &&
1046 renderer_prefs.use_custom_colors) {
1047 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
1048 }
1049
Dominic Mazzoni554089e2020-07-31 22:12:041050 if (GetWebView()) {
1051 if (old_accept_languages != renderer_preferences_.accept_languages)
1052 GetWebView()->AcceptLanguagesChanged();
1053
1054 GetWebView()->GetSettings()->SetCaretBrowsingEnabled(
1055 renderer_preferences_.caret_browsing_enabled);
[email protected]ebd5ea52014-05-28 14:51:151056 }
Alexander Dunaev5baa6d642020-08-10 13:39:071057
1058#if defined(USE_X11) || defined(USE_OZONE)
1059 GetWebView()->GetSettings()->SetSelectionClipboardBufferAvailable(
1060 renderer_preferences_.selection_clipboard_buffer_available);
1061#endif // defined(USE_X11) || defined(USE_OZONE)
[email protected]80d96fa2009-06-10 22:34:511062}
1063
[email protected]310ebd6302011-10-10 19:06:281064void RenderViewImpl::OnMoveOrResizeStarted() {
Antonio Gomes778a0f72020-02-24 13:52:441065 if (GetWebView())
1066 GetWebView()->CancelPagePopup();
[email protected]30f75e62009-02-25 22:01:001067}
1068
Francois Doray47f759d2018-06-11 18:13:511069void RenderViewImpl::SetPageFrozen(bool frozen) {
Antonio Gomes778a0f72020-02-24 13:52:441070 if (GetWebView())
1071 GetWebView()->SetPageFrozen(frozen);
Fadi Meawada6573e02018-03-10 00:52:111072}
1073
danakj9a8a9cf2018-07-17 23:52:121074void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) {
Erik Chene4ae6b42019-10-01 12:06:281075 // Auto resize should only happen on local main frames.
danakjee8f4902020-01-17 18:06:101076 DCHECK(main_render_frame_);
1077 main_render_frame_->GetLocalRootRenderWidget()->DidAutoResize(newSize);
danakj9a8a9cf2018-07-17 23:52:121078}
1079
[email protected]20657a82012-08-21 20:23:031080#if defined(OS_ANDROID)
braveyao1d8ee7b2017-03-29 21:10:041081void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) {
1082 if (!main_render_frame_)
1083 return;
1084
Guido Urdanetadc7090372019-07-29 17:59:541085 blink::WebMediaStreamDeviceObserver* media_stream_device_observer =
Antonio Gomes32f24faf2019-08-18 16:41:361086 main_render_frame_->MediaStreamDeviceObserver();
Chandan Padhi26dbd9b32017-11-27 11:13:351087 if (!media_stream_device_observer)
braveyao1d8ee7b2017-03-29 21:10:041088 return;
1089
Guido Urdaneta73fa6632019-01-14 18:46:261090 blink::MediaStreamDevices video_devices =
Chandan Padhi26dbd9b32017-11-27 11:13:351091 media_stream_device_observer->GetNonScreenCaptureDevices();
braveyao1d8ee7b2017-03-29 21:10:041092 RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices(
Chandan Padhi6dbfb732017-09-01 16:08:491093 video_devices, suspend);
braveyao1d8ee7b2017-03-29 21:10:041094}
estade6b9696bd2016-05-04 23:51:361095#endif // defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:031096
[email protected]b283d292013-02-21 08:40:341097unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
1098 return history_list_length_;
1099}
1100
[email protected]e9ff79c2012-10-19 21:31:261101} // namespace content