blob: 55120e6b1864fdf4a85ebd445358d902822f3fe3 [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"
dchengcedca5612016-04-09 01:40:1524#include "base/memory/ptr_util.h"
[email protected]f29efe6b2014-06-09 05:01:5125#include "base/metrics/field_trial.h"
asvitkine8d51e9d2016-09-02 23:55:4326#include "base/metrics/histogram_macros.h"
[email protected]d3b4ee22013-07-24 22:50:0627#include "base/process/kill.h"
[email protected]7d08a9352013-10-15 08:24:5628#include "base/process/process.h"
fdoray7a8954a42016-06-07 04:28:3829#include "base/single_thread_task_runner.h"
[email protected]21aa99682013-06-11 07:17:0130#include "base/strings/string_number_conversions.h"
[email protected]b9e7c479f2013-04-12 04:33:2431#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4932#include "base/strings/string_split.h"
[email protected]21aa99682013-06-11 07:17:0133#include "base/strings/string_util.h"
[email protected]40d11e02013-03-28 17:43:1434#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0035#include "base/strings/utf_string_conversions.h"
dalecurtiscd971252016-09-21 16:09:0036#include "base/sys_info.h"
fdoray7a8954a42016-06-07 04:28:3837#include "base/threading/thread_task_runner_handle.h"
[email protected]abb522162013-06-28 01:54:1638#include "base/time/time.h"
primiano9e38d552015-01-28 04:18:0139#include "base/trace_event/trace_event.h"
avi1023d012015-12-25 02:39:1440#include "build/build_config.h"
dongseong.hwange095dfa2016-02-04 11:21:3941#include "cc/base/switches.h"
enne98c9f8052017-03-15 19:38:2242#include "cc/paint/skia_paint_canvas.h"
jinho.bang632a1a722014-09-18 03:02:5643#include "content/common/content_constants_internal.h"
Daniel Murphye3eec92c2018-02-23 19:09:1544#include "content/common/dom_storage/dom_storage_namespace_ids.h"
[email protected]5f2aa722013-08-07 16:59:4145#include "content/common/dom_storage/dom_storage_types.h"
[email protected]59f4f2fa2011-03-23 01:00:5546#include "content/common/drag_messages.h"
[email protected]c6bc20332014-02-28 18:30:3947#include "content/common/frame_messages.h"
alexmosbc7eafa2014-12-06 01:38:0948#include "content/common/frame_replication_state.h"
[email protected]c084330e02013-04-27 01:08:1549#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0750#include "content/common/page_messages.h"
rockot5c478a72016-09-28 23:14:1851#include "content/common/render_message_filter.mojom.h"
[email protected]778574e2011-03-21 22:03:5052#include "content/common/view_messages.h"
arthursonzognic517fc32016-08-11 11:04:2453#include "content/public/common/browser_side_navigation_policy.h"
[email protected]744c2a22012-03-15 18:42:0454#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4855#include "content/public/common/content_constants.h"
Tarun Bansal73dd2ff82017-10-03 05:29:3456#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2957#include "content/public/common/content_switches.h"
kouhei40f03cb2015-09-24 07:47:0158#include "content/public/common/page_importance_signals.h"
clamyda97e8322014-10-07 21:57:2559#include "content/public/common/page_state.h"
[email protected]7940b8e2013-07-25 23:08:4960#include "content/public/common/page_zoom.h"
[email protected]818915cd2012-11-20 13:14:1161#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0362#include "content/public/common/url_constants.h"
Jaebaek Seo53ab80a662018-01-29 04:50:4663#include "content/public/common/use_zoom_for_dsf_policy.h"
[email protected]b3a97b52014-07-09 06:25:0564#include "content/public/common/web_preferences.h"
[email protected]d344114c2011-10-01 01:24:3465#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0766#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3267#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4468#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3669#include "content/public/renderer/render_view_visitor.h"
scottmg8e6c6082017-02-13 23:15:4870#include "content/public/renderer/window_features_converter.h"
John Abd-El-Malekdcf1d1372017-10-22 06:39:4171#include "content/renderer/appcache/appcache_dispatcher.h"
72#include "content/renderer/appcache/web_application_cache_host_impl.h"
[email protected]e6e56752012-08-10 00:46:0673#include "content/renderer/browser_plugin/browser_plugin.h"
74#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]dc293a72013-07-01 11:11:2275#include "content/renderer/drop_data_builder.h"
[email protected]ba91a792013-02-06 09:48:2876#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]dc064352014-04-25 08:36:3877#include "content/renderer/history_serialization.h"
[email protected]1784b2f2011-11-24 10:53:4878#include "content/renderer/idle_user_detector.h"
[email protected]66fca5bc2013-05-23 06:58:2979#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1380#include "content/renderer/input/input_handler_manager.h"
[email protected]92d457802013-04-01 19:18:4981#include "content/renderer/internal_document_state_data.h"
John Abd-El-Malek6b56ef712017-10-21 22:52:4682#include "content/renderer/loader/request_extra_data.h"
[email protected]4a914882013-01-10 00:43:4883#include "content/renderer/media/audio_device_factory.h"
Miguel Casasa8c2c5a2018-02-12 18:51:0384#include "content/renderer/media/stream/media_stream_device_observer.h"
[email protected]6392d982013-04-16 16:59:2285#include "content/renderer/media/video_capture_impl_manager.h"
clamy5f342202015-03-18 13:47:5686#include "content/renderer/navigation_state_impl.h"
[email protected]227692c52013-05-31 22:43:0487#include "content/renderer/render_frame_impl.h"
[email protected]5a7100d2014-05-19 01:29:0488#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0589#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4490#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4491#include "content/renderer/render_widget_fullscreen_pepper.h"
Daniel Murphye3eec92c2018-02-23 19:09:1592#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]663bd9e2011-03-21 01:07:0193#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]5b45ad42013-10-25 00:42:0494#include "content/renderer/resizing_mode_selector.h"
[email protected]12a936d2013-05-15 04:55:4995#include "content/renderer/savable_resources.h"
John Abd-El-Malek312a30bb2017-10-23 19:51:5296#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:2197#include "content/renderer/web_ui_extension_data.h"
[email protected]f5961142013-04-17 23:09:4298#include "media/audio/audio_output_device.h"
[email protected]ee68378a2010-08-10 01:05:4199#include "media/base/media_switches.h"
Brett Wilson0748bf412016-11-22 17:55:46100#include "media/media_features.h"
servolkf54f5c8f2015-02-24 20:32:39101#include "media/renderers/audio_renderer_impl.h"
Dale Curtis863022e2017-08-19 02:05:34102#include "media/video/gpu_video_accelerator_factories.h"
[email protected]d1ef81d2012-07-24 11:39:36103#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29104#include "net/base/escape.h"
105#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09106#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04107#include "net/http/http_util.h"
Tarun Bansal73d67f02018-01-17 05:56:25108#include "net/nqe/effective_connection_type.h"
brettw4b461082016-11-19 18:55:16109#include "ppapi/features/features.h"
lukenb171b532014-09-24 05:50:38110#include "skia/ext/platform_canvas.h"
Kinuko Yasuda9260b3c2018-02-12 17:14:43111#include "third_party/WebKit/public/common/associated_interfaces/associated_interface_provider.h"
Kinuko Yasuda0c56d072018-02-27 17:21:31112#include "third_party/WebKit/public/mojom/page/page_visibility_state.mojom.h"
kinukob473f002016-02-22 05:23:19113#include "third_party/WebKit/public/platform/FilePathConversion.h"
brettwdfbcc3b2016-01-20 01:49:17114#include "third_party/WebKit/public/platform/URLConversion.h"
[email protected]b3a97b52014-07-09 06:25:05115#include "third_party/WebKit/public/platform/WebConnectionType.h"
Tarun Bansal73d67f02018-01-17 05:56:25116#include "third_party/WebKit/public/platform/WebEffectiveConnectionType.h"
[email protected]d0fcff72013-07-23 02:45:43117#include "third_party/WebKit/public/platform/WebHTTPBody.h"
118#include "third_party/WebKit/public/platform/WebImage.h"
dtapuska836e1f92016-11-15 00:38:06119#include "third_party/WebKit/public/platform/WebInputEvent.h"
skyostilcff62882017-01-28 13:18:04120#include "third_party/WebKit/public/platform/WebInputEventResult.h"
Tarun Bansalabd3ef02017-11-03 15:19:20121#include "third_party/WebKit/public/platform/WebNetworkStateNotifier.h"
[email protected]d0fcff72013-07-23 02:45:43122#include "third_party/WebKit/public/platform/WebPoint.h"
123#include "third_party/WebKit/public/platform/WebRect.h"
nverne61d2da872017-05-24 10:15:30124#include "third_party/WebKit/public/platform/WebRuntimeFeatures.h"
[email protected]d0fcff72013-07-23 02:45:43125#include "third_party/WebKit/public/platform/WebSize.h"
[email protected]d0fcff72013-07-23 02:45:43126#include "third_party/WebKit/public/platform/WebString.h"
127#include "third_party/WebKit/public/platform/WebURL.h"
128#include "third_party/WebKit/public/platform/WebURLError.h"
129#include "third_party/WebKit/public/platform/WebURLRequest.h"
130#include "third_party/WebKit/public/platform/WebURLResponse.h"
131#include "third_party/WebKit/public/platform/WebVector.h"
brettw8a274fa2016-11-15 00:20:40132#include "third_party/WebKit/public/public_features.h"
[email protected]10760e4a2013-09-04 23:32:20133#include "third_party/WebKit/public/web/WebAXObject.h"
ekaramad27ca69b12017-04-20 18:34:29134#include "third_party/WebKit/public/web/WebAutofillClient.h"
[email protected]2255a9332013-06-17 05:12:31135#include "third_party/WebKit/public/web/WebDOMEvent.h"
136#include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
[email protected]2255a9332013-06-17 05:12:31137#include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h"
138#include "third_party/WebKit/public/web/WebDateTimeChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31139#include "third_party/WebKit/public/web/WebDocument.h"
140#include "third_party/WebKit/public/web/WebElement.h"
141#include "third_party/WebKit/public/web/WebFileChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31142#include "third_party/WebKit/public/web/WebFormControlElement.h"
143#include "third_party/WebKit/public/web/WebFormElement.h"
144#include "third_party/WebKit/public/web/WebFrame.h"
dglazkov03223492016-02-08 22:16:03145#include "third_party/WebKit/public/web/WebFrameContentDumper.h"
lfgcaab5142016-02-26 19:06:52146#include "third_party/WebKit/public/web/WebFrameWidget.h"
[email protected]2255a9332013-06-17 05:12:31147#include "third_party/WebKit/public/web/WebHistoryItem.h"
[email protected]91dcc6d32014-07-30 00:01:33148#include "third_party/WebKit/public/web/WebHitTestResult.h"
[email protected]2255a9332013-06-17 05:12:31149#include "third_party/WebKit/public/web/WebInputElement.h"
[email protected]35b2a972014-04-04 15:50:22150#include "third_party/WebKit/public/web/WebLocalFrame.h"
[email protected]2255a9332013-06-17 05:12:31151#include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
152#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
kouhei40f03cb2015-09-24 07:47:01153#include "third_party/WebKit/public/web/WebPageImportanceSignals.h"
[email protected]2255a9332013-06-17 05:12:31154#include "third_party/WebKit/public/web/WebPlugin.h"
155#include "third_party/WebKit/public/web/WebPluginAction.h"
[email protected]2255a9332013-06-17 05:12:31156#include "third_party/WebKit/public/web/WebRange.h"
ellyjones8ae17692016-08-05 15:19:21157#include "third_party/WebKit/public/web/WebRenderTheme.h"
[email protected]2255a9332013-06-17 05:12:31158#include "third_party/WebKit/public/web/WebScriptSource.h"
159#include "third_party/WebKit/public/web/WebSearchableFormData.h"
[email protected]2255a9332013-06-17 05:12:31160#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
[email protected]2255a9332013-06-17 05:12:31161#include "third_party/WebKit/public/web/WebSettings.h"
[email protected]2255a9332013-06-17 05:12:31162#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
[email protected]2255a9332013-06-17 05:12:31163#include "third_party/WebKit/public/web/WebView.h"
164#include "third_party/WebKit/public/web/WebWindowFeatures.h"
[email protected]b3a97b52014-07-09 06:25:05165#include "third_party/icu/source/common/unicode/uchar.h"
166#include "third_party/icu/source/common/unicode/uscript.h"
esecklerf2bd55f72017-03-31 09:11:57167#include "third_party/skia/include/core/SkColor.h"
[email protected]1400e6dc2013-04-27 02:36:27168#include "ui/base/ui_base_switches_util.h"
tfarina655f81d2014-12-23 02:38:50169#include "ui/gfx/geometry/point.h"
tfarina3b0452d2014-12-31 15:20:09170#include "ui/gfx/geometry/rect.h"
171#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32172#include "ui/gfx/geometry/size_conversions.h"
[email protected]08397d52011-02-05 01:53:38173#include "ui/gfx/native_widget_types.h"
ccameron772317d2017-06-04 18:35:03174#include "ui/gfx/switches.h"
mfomitchev3ba450ad2017-04-03 18:20:40175#include "ui/latency/latency_info.h"
csharrisond88f9752016-10-26 23:56:36176#include "url/origin.h"
markdittmer67b71ea2016-03-03 22:40:03177#include "url/url_constants.h"
[email protected]c4a9e932011-03-05 04:05:55178#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:29179
[email protected]25fb9b32012-04-27 03:21:55180#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25181#include <cpu-features.h>
182
dalecurtiscd971252016-09-21 16:09:00183#include "base/android/build_info.h"
kylechare7d8d5c72018-01-05 19:06:28184#include "base/memory/shared_memory.h"
185#include "content/child/child_thread_impl.h"
estade6b9696bd2016-05-04 23:51:36186#include "content/renderer/android/disambiguation_popup_helper.h"
tfarina3b0452d2014-12-31 15:20:09187#include "ui/gfx/geometry/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40188
[email protected]78043bdd2010-04-05 18:45:33189#elif defined(OS_MACOSX)
190#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57191#endif
192
brettw4b461082016-11-19 18:55:16193#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]ea2fb972013-08-07 05:44:26194#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
195#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26196#endif
197
Brett Wilson0748bf412016-11-22 17:55:46198#if BUILDFLAG(ENABLE_WEBRTC)
[email protected]22fe91d2014-08-12 17:07:12199#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
Miguel Casasee42e702018-02-09 19:07:03200#include "content/renderer/media/webrtc/rtc_peer_connection_handler.h"
[email protected]9ac667e2013-09-09 12:49:21201#endif
202
[email protected]180ef242013-11-07 06:50:46203using blink::WebAXObject;
204using blink::WebApplicationCacheHost;
205using blink::WebApplicationCacheHostClient;
[email protected]180ef242013-11-07 06:50:46206using blink::WebColor;
[email protected]180ef242013-11-07 06:50:46207using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46208using blink::WebData;
[email protected]180ef242013-11-07 06:50:46209using blink::WebDocument;
[email protected]180ef242013-11-07 06:50:46210using blink::WebDragOperation;
[email protected]180ef242013-11-07 06:50:46211using blink::WebElement;
[email protected]180ef242013-11-07 06:50:46212using blink::WebFileChooserCompletion;
[email protected]180ef242013-11-07 06:50:46213using blink::WebFormControlElement;
214using blink::WebFormElement;
215using blink::WebFrame;
dglazkov03223492016-02-08 22:16:03216using blink::WebFrameContentDumper;
[email protected]180ef242013-11-07 06:50:46217using blink::WebGestureEvent;
218using blink::WebHistoryItem;
219using blink::WebHTTPBody;
dglazkov8d0c21dd2016-08-06 15:56:36220using blink::WebHitTestResult;
[email protected]180ef242013-11-07 06:50:46221using blink::WebImage;
222using blink::WebInputElement;
223using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22224using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46225using blink::WebMediaPlayerAction;
[email protected]180ef242013-11-07 06:50:46226using blink::WebMouseEvent;
227using blink::WebNavigationPolicy;
228using blink::WebNavigationType;
229using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46230using blink::WebPluginAction;
[email protected]180ef242013-11-07 06:50:46231using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46232using blink::WebRect;
233using blink::WebReferrerPolicy;
Daniel Chengd5e56ff2017-06-24 07:44:02234using blink::WebSandboxFlags;
[email protected]180ef242013-11-07 06:50:46235using blink::WebScriptSource;
236using blink::WebSearchableFormData;
237using blink::WebSecurityOrigin;
238using blink::WebSecurityPolicy;
[email protected]180ef242013-11-07 06:50:46239using blink::WebSettings;
240using blink::WebSize;
[email protected]180ef242013-11-07 06:50:46241using blink::WebString;
Donn Denman3c1267c62018-03-08 22:08:59242using blink::WebTappedInfo;
[email protected]180ef242013-11-07 06:50:46243using blink::WebTextDirection;
244using blink::WebTouchEvent;
245using blink::WebURL;
246using blink::WebURLError;
247using blink::WebURLRequest;
248using blink::WebURLResponse;
249using blink::WebUserGestureIndicator;
250using blink::WebVector;
251using blink::WebView;
252using blink::WebWidget;
253using blink::WebWindowFeatures;
[email protected]b3a97b52014-07-09 06:25:05254using blink::WebRuntimeFeatures;
[email protected]6fdd4182010-10-14 23:59:26255using base::TimeDelta;
[email protected]e1acf6f2008-10-27 20:43:33256
[email protected]20657a82012-08-21 20:23:03257
[email protected]e9ff79c2012-10-19 21:31:26258namespace content {
259
initial.commit09911bf2008-07-26 23:55:29260//-----------------------------------------------------------------------------
261
[email protected]180ef242013-11-07 06:50:46262typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
jbroman8319b232017-03-08 22:53:29263static base::LazyInstance<ViewMap>::Leaky g_view_map =
[email protected]058561b2012-12-03 06:48:22264 LAZY_INSTANCE_INITIALIZER;
scottmg5e65e3a2017-03-08 08:48:46265typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap;
jbroman8319b232017-03-08 22:53:29266static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map =
267 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02268
[email protected]882daa92009-11-05 16:31:31269// Time, in seconds, we delay before sending content state changes (such as form
270// state and scroll position) to the browser. We delay sending changes to avoid
271// spamming the browser.
272// To avoid having tab/session restore require sending a message to get the
273// current content state during tab closing we use a shorter timeout for the
274// foreground renderer. This means there is a small window of time from which
275// content state is modified and not sent to session restore, but this is
276// better than having to wake up all renderers during shutdown.
avif937e1d2014-11-02 18:13:07277const int kDelaySecondsForContentStateSyncHidden = 5;
278const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29279
dcheng35d31c112015-07-22 00:17:36280static RenderViewImpl* (*g_create_render_view_impl)(
281 CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15282 const mojom::CreateViewParams&) = nullptr;
[email protected]8d41d7612012-11-14 20:32:19283
[email protected]c6bc20332014-02-28 18:30:39284// static
[email protected]e507045d2013-07-24 15:23:44285Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56286 WebFrame* frame,
287 const WebURLRequest& request) {
Blink Reformat1c4d759e2017-04-09 16:34:54288 return Referrer(blink::WebStringToGURL(
289 request.HttpHeaderField(WebString::FromUTF8("Referer"))),
290 request.GetReferrerPolicy());
[email protected]44e55b012013-07-23 14:21:56291}
292
[email protected]c6bc20332014-02-28 18:30:39293// static
[email protected]65920f332014-03-04 21:14:18294WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32295 WebNavigationPolicy policy) {
296 switch (policy) {
Blink Reformat1c4d759e2017-04-09 16:34:54297 case blink::kWebNavigationPolicyIgnore:
nick3b04f322016-08-31 19:29:19298 return WindowOpenDisposition::IGNORE_ACTION;
Blink Reformat1c4d759e2017-04-09 16:34:54299 case blink::kWebNavigationPolicyDownload:
nick3b04f322016-08-31 19:29:19300 return WindowOpenDisposition::SAVE_TO_DISK;
Blink Reformat1c4d759e2017-04-09 16:34:54301 case blink::kWebNavigationPolicyCurrentTab:
nick3b04f322016-08-31 19:29:19302 return WindowOpenDisposition::CURRENT_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54303 case blink::kWebNavigationPolicyNewBackgroundTab:
nick3b04f322016-08-31 19:29:19304 return WindowOpenDisposition::NEW_BACKGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54305 case blink::kWebNavigationPolicyNewForegroundTab:
nick3b04f322016-08-31 19:29:19306 return WindowOpenDisposition::NEW_FOREGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54307 case blink::kWebNavigationPolicyNewWindow:
nick3b04f322016-08-31 19:29:19308 return WindowOpenDisposition::NEW_WINDOW;
Blink Reformat1c4d759e2017-04-09 16:34:54309 case blink::kWebNavigationPolicyNewPopup:
nick3b04f322016-08-31 19:29:19310 return WindowOpenDisposition::NEW_POPUP;
[email protected]48861e22013-01-09 00:27:32311 default:
312 NOTREACHED() << "Unexpected WebNavigationPolicy";
nick3b04f322016-08-31 19:29:19313 return WindowOpenDisposition::IGNORE_ACTION;
[email protected]48861e22013-01-09 00:27:32314 }
315}
316
initial.commit09911bf2008-07-26 23:55:29317///////////////////////////////////////////////////////////////////////////////
318
[email protected]217690d2012-01-27 07:33:11319namespace {
320
[email protected]b3a97b52014-07-09 06:25:05321typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
322 const base::string16&,
323 UScriptCode);
324
325void SetStandardFontFamilyWrapper(WebSettings* settings,
326 const base::string16& font,
327 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54328 settings->SetStandardFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05329}
330
331void SetFixedFontFamilyWrapper(WebSettings* settings,
332 const base::string16& font,
333 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54334 settings->SetFixedFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05335}
336
337void SetSerifFontFamilyWrapper(WebSettings* settings,
338 const base::string16& font,
339 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54340 settings->SetSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05341}
342
343void SetSansSerifFontFamilyWrapper(WebSettings* settings,
344 const base::string16& font,
345 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54346 settings->SetSansSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05347}
348
349void SetCursiveFontFamilyWrapper(WebSettings* settings,
350 const base::string16& font,
351 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54352 settings->SetCursiveFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05353}
354
355void SetFantasyFontFamilyWrapper(WebSettings* settings,
356 const base::string16& font,
357 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54358 settings->SetFantasyFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05359}
360
361void SetPictographFontFamilyWrapper(WebSettings* settings,
362 const base::string16& font,
363 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54364 settings->SetPictographFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05365}
366
367// If |scriptCode| is a member of a family of "similar" script codes, returns
368// the script code in that family that is used by WebKit for font selection
369// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
370// considered equivalent for the purposes of font selection. WebKit uses the
371// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
372// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
373// uses different scripts than the ones in Chrome pref names because the version
374// of ICU included on certain ports does not have some of the newer scripts. If
375// |scriptCode| is not a member of such a family, returns |scriptCode|.
376UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
377 switch (scriptCode) {
378 case USCRIPT_HIRAGANA:
379 case USCRIPT_KATAKANA:
380 case USCRIPT_JAPANESE:
381 return USCRIPT_KATAKANA_OR_HIRAGANA;
382 case USCRIPT_KOREAN:
383 return USCRIPT_HANGUL;
384 default:
385 return scriptCode;
386 }
387}
388
389void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
390 SetFontFamilyWrapper setter,
391 WebSettings* settings) {
392 for (ScriptFontFamilyMap::const_iterator it = map.begin(); it != map.end();
393 ++it) {
avi1023d012015-12-25 02:39:14394 int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
[email protected]b3a97b52014-07-09 06:25:05395 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
396 UScriptCode code = static_cast<UScriptCode>(script);
397 (*setter)(settings, it->second, GetScriptForWebSettings(code));
398 }
399 }
400}
401
wangxianzhu3bf39be52015-04-10 23:56:41402void ApplyBlinkSettings(const base::CommandLine& command_line,
403 WebSettings* settings) {
404 if (!command_line.HasSwitch(switches::kBlinkSettings))
405 return;
406
brettw26dab8f02015-08-08 00:28:47407 std::vector<std::string> blink_settings = base::SplitString(
408 command_line.GetSwitchValueASCII(switches::kBlinkSettings),
409 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
wangxianzhu3bf39be52015-04-10 23:56:41410 for (const std::string& setting : blink_settings) {
411 size_t pos = setting.find('=');
Blink Reformat1c4d759e2017-04-09 16:34:54412 settings->SetFromStrings(
413 blink::WebString::FromLatin1(setting.substr(0, pos)),
414 blink::WebString::FromLatin1(
wangxianzhu3bf39be52015-04-10 23:56:41415 pos == std::string::npos ? "" : setting.substr(pos + 1)));
416 }
417}
418
svartmetal751af1f92016-08-13 11:47:33419// This class represents promise which is robust to (will not be broken by)
420// |DidNotSwapReason::SWAP_FAILS| events.
421class AlwaysDrawSwapPromise : public cc::SwapPromise {
422 public:
423 explicit AlwaysDrawSwapPromise(const ui::LatencyInfo& latency_info)
424 : latency_info_(latency_info) {}
425
426 ~AlwaysDrawSwapPromise() override = default;
427
428 void DidActivate() override {}
429
jonross7244a4a2018-03-08 19:05:35430 void WillSwap(viz::CompositorFrameMetadata* metadata,
431 cc::FrameTokenAllocator* frame_token_allocator) override {
svartmetal751af1f92016-08-13 11:47:33432 DCHECK(!latency_info_.terminated());
jonross7c62fcb2018-02-21 16:35:46433 metadata->latency_info.push_back(latency_info_);
svartmetal751af1f92016-08-13 11:47:33434 }
435
samanse7345c82016-12-16 02:51:16436 void DidSwap() override {}
437
svartmetal751af1f92016-08-13 11:47:33438 DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override {
439 return reason == DidNotSwapReason::SWAP_FAILS
440 ? DidNotSwapAction::KEEP_ACTIVE
441 : DidNotSwapAction::BREAK_PROMISE;
442 }
443
444 void OnCommit() override {}
445
446 int64_t TraceId() const override { return latency_info_.trace_id(); }
447
448 private:
449 ui::LatencyInfo latency_info_;
450};
451
scottmgde42fb92017-02-10 17:56:03452content::mojom::WindowContainerType WindowFeaturesToContainerType(
scottmg05324cb2017-02-09 23:46:04453 const blink::WebWindowFeatures& window_features) {
japhetbfc47892017-06-02 23:01:19454 if (window_features.background) {
455 if (window_features.persistent)
scottmgde42fb92017-02-10 17:56:03456 return content::mojom::WindowContainerType::PERSISTENT;
scottmg05324cb2017-02-09 23:46:04457 else
scottmgde42fb92017-02-10 17:56:03458 return content::mojom::WindowContainerType::BACKGROUND;
scottmg05324cb2017-02-09 23:46:04459 } else {
scottmgde42fb92017-02-10 17:56:03460 return content::mojom::WindowContainerType::NORMAL;
scottmg05324cb2017-02-09 23:46:04461 }
462}
463
[email protected]217690d2012-01-27 07:33:11464} // namespace
465
Hajime Hoshiabb3c8f2017-12-04 18:41:39466RenderViewImpl::RenderViewImpl(
467 CompositorDependencies* compositor_deps,
468 const mojom::CreateViewParams& params,
469 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
nick8331f8ad2016-11-15 20:42:45470 : RenderWidget(params.view_id,
471 compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54472 blink::kWebPopupTypeNone,
naskobd911332014-11-25 01:13:36473 params.initial_size.screen_info,
474 params.swapped_out,
475 params.hidden,
Hajime Hoshiabb3c8f2017-12-04 18:41:39476 params.never_visible,
477 task_runner),
naskobd911332014-11-25 01:13:36478 webkit_preferences_(params.web_preferences),
avif937e1d2014-11-02 18:13:07479 send_content_state_immediately_(false),
[email protected]3354d3e2010-06-10 19:53:02480 send_preferred_size_changes_(false),
[email protected]e75cb49e2009-01-05 23:13:21481 navigation_gesture_(NavigationGestureUnknown),
[email protected]3cc72b12010-03-18 23:03:00482 history_list_offset_(-1),
483 history_list_length_(0),
[email protected]7e9523b2014-03-25 03:02:42484 frames_in_progress_(0),
[email protected]3354d3e2010-06-10 19:53:02485 target_url_status_(TARGET_NONE),
[email protected]d42bf472014-06-14 01:49:38486 uses_temporary_zoom_level_(false),
[email protected]bbc8856d2013-06-14 10:37:04487#if defined(OS_ANDROID)
mdjones2ee41afd2016-10-27 16:50:20488 top_controls_constraints_(BROWSER_CONTROLS_STATE_BOTH),
[email protected]bbc8856d2013-06-14 10:37:04489#endif
mdjones2ee41afd2016-10-27 16:50:20490 browser_controls_shrink_blink_size_(false),
bokanc63441c2016-04-27 15:49:12491 top_controls_height_(0.f),
Matthew Jones7e156182017-07-21 22:21:33492 bottom_controls_height_(0.f),
lfg4fa48da2016-05-09 18:25:13493 webview_(nullptr),
wjmaclean64951902016-04-29 20:59:12494 page_zoom_level_(params.page_zoom_level),
nasko4c0feb62015-06-05 18:37:06495 main_render_frame_(nullptr),
dcheng3ce04b62015-10-26 23:30:55496 frame_widget_(nullptr),
[email protected]20657a82012-08-21 20:23:03497#if defined(OS_ANDROID)
nickf7b38222016-11-22 21:59:35498 was_created_by_renderer_(false),
[email protected]a7564272013-04-19 14:24:46499#endif
[email protected]8a67aa352013-02-20 02:58:29500 enumeration_completion_id_(0),
changwand659e202016-06-13 02:39:12501 session_storage_namespace_id_(params.session_storage_namespace_id),
Lukasz Anforowiczaf2f33572018-01-17 14:05:08502 renderer_wide_named_frame_lookup_(false),
wjmaclean1d970622017-01-21 22:28:24503 weak_ptr_factory_(this) {
avi40b5be7a2016-03-03 21:13:44504 GetWidget()->set_owner_delegate(this);
[email protected]075366912013-02-18 07:13:24505}
506
nickf7b38222016-11-22 21:59:35507void RenderViewImpl::Initialize(
Balazs Engedyba034e72017-10-27 22:26:28508 mojom::CreateViewParamsPtr params,
Hajime Hoshif34374412018-03-05 14:32:54509 const RenderWidget::ShowCallback& show_callback,
510 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
nickf7b38222016-11-22 21:59:35511 bool was_created_by_renderer = !show_callback.is_null();
512#if defined(OS_ANDROID)
513 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated
514 // HandleNavigation codepath.
515 was_created_by_renderer_ = was_created_by_renderer;
516#endif
Lukasz Anforowiczaf2f33572018-01-17 14:05:08517 renderer_wide_named_frame_lookup_ = params->renderer_wide_named_frame_lookup;
Balazs Engedyba034e72017-10-27 22:26:28518 display_mode_ = params->initial_size.display_mode;
[email protected]676126f72011-01-15 00:03:51519
Lukasz Anforowiczaf2f33572018-01-17 14:05:08520 WebFrame* opener_frame =
521 RenderFrameImpl::ResolveOpener(params->opener_frame_route_id);
522
523 webview_ =
524 WebView::Create(this,
525 is_hidden() ? blink::mojom::PageVisibilityState::kHidden
526 : blink::mojom::PageVisibilityState::kVisible,
527 opener_frame ? opener_frame->View() : nullptr);
Blink Reformat1c4d759e2017-04-09 16:34:54528 RenderWidget::Init(show_callback, webview_->GetWidget());
[email protected]11fee2332011-03-29 20:36:35529
nasko4c0feb62015-06-05 18:37:06530 g_view_map.Get().insert(std::make_pair(webview(), this));
avia3dca182016-03-19 01:09:52531 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this));
nasko4c0feb62015-06-05 18:37:06532
avi83883c82014-12-23 00:08:49533 const base::CommandLine& command_line =
534 *base::CommandLine::ForCurrentProcess();
[email protected]20657a82012-08-21 20:23:03535
[email protected]27c521a2013-05-29 20:44:32536 if (command_line.HasSwitch(switches::kStatsCollectionController))
537 stats_collection_observer_.reset(new StatsCollectionObserver(this));
538
Blink Reformat1c4d759e2017-04-09 16:34:54539 webview()->SetDisplayMode(display_mode_);
Blink Reformat1c4d759e2017-04-09 16:34:54540 webview()->GetSettings()->SetThreadedScrollingEnabled(
dcheng0ff94cfc2016-03-15 21:50:51541 !command_line.HasSwitch(switches::kDisableThreadedScrolling));
Blink Reformat1c4d759e2017-04-09 16:34:54542 webview()->SetShowFPSCounter(
dcheng0ff94cfc2016-03-15 21:50:51543 command_line.HasSwitch(cc::switches::kShowFPSCounter));
544
545 ApplyWebPreferencesInternal(webkit_preferences_, webview(), compositor_deps_);
546
547 if (switches::IsTouchDragDropEnabled())
Blink Reformat1c4d759e2017-04-09 16:34:54548 webview()->GetSettings()->SetTouchDragDropEnabled(true);
dcheng0ff94cfc2016-03-15 21:50:51549
Blink Reformat1c4d759e2017-04-09 16:34:54550 webview()->GetSettings()->SetBrowserSideNavigationEnabled(
arthursonzognic517fc32016-08-11 11:04:24551 IsBrowserSideNavigationEnabled());
552
dcheng0ff94cfc2016-03-15 21:50:51553 WebSettings::SelectionStrategyType selection_strategy =
Blink Reformat1c4d759e2017-04-09 16:34:54554 WebSettings::SelectionStrategyType::kCharacter;
dcheng0ff94cfc2016-03-15 21:50:51555 const std::string selection_strategy_str =
556 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
557 switches::kTouchTextSelectionStrategy);
558 if (selection_strategy_str == "direction")
Blink Reformat1c4d759e2017-04-09 16:34:54559 selection_strategy = WebSettings::SelectionStrategyType::kDirection;
560 webview()->GetSettings()->SetSelectionStrategy(selection_strategy);
dcheng0ff94cfc2016-03-15 21:50:51561
dtapuskaf65650b2016-05-13 17:21:34562 std::string passiveListenersDefault =
563 command_line.GetSwitchValueASCII(switches::kPassiveListenersDefault);
564 if (!passiveListenersDefault.empty()) {
565 WebSettings::PassiveEventListenerDefault passiveDefault =
Blink Reformat1c4d759e2017-04-09 16:34:54566 WebSettings::PassiveEventListenerDefault::kFalse;
dtapuskaacc2fb22016-07-06 23:26:23567 if (passiveListenersDefault == "true")
Blink Reformat1c4d759e2017-04-09 16:34:54568 passiveDefault = WebSettings::PassiveEventListenerDefault::kTrue;
dtapuskaf65650b2016-05-13 17:21:34569 else if (passiveListenersDefault == "forcealltrue")
Blink Reformat1c4d759e2017-04-09 16:34:54570 passiveDefault = WebSettings::PassiveEventListenerDefault::kForceAllTrue;
571 webview()->GetSettings()->SetPassiveEventListenerDefault(passiveDefault);
dtapuskaf65650b2016-05-13 17:21:34572 }
573
Blink Reformat1c4d759e2017-04-09 16:34:54574 ApplyBlinkSettings(command_line, webview()->GetSettings());
dcheng0ff94cfc2016-03-15 21:50:51575
Balazs Engedyba034e72017-10-27 22:26:28576 if (params->main_frame_routing_id != MSG_ROUTING_NONE) {
Ken Rockot26efbd62017-11-16 04:39:49577 CHECK(params->main_frame_interface_provider.is_valid());
578 service_manager::mojom::InterfaceProviderPtr main_frame_interface_provider(
579 std::move(params->main_frame_interface_provider));
dcheng3ce04b62015-10-26 23:30:55580 main_render_frame_ = RenderFrameImpl::CreateMainFrame(
Balazs Engedyba034e72017-10-27 22:26:28581 this, params->main_frame_routing_id,
Ken Rockot26efbd62017-11-16 04:39:49582 std::move(main_frame_interface_provider),
Fady Samuela863f152018-03-09 16:10:03583 params->main_frame_widget_routing_id, params->hidden,
584 GetWebScreenInfo(), compositor_deps_, opener_frame,
585 params->devtools_main_frame_token, params->replicated_frame_state,
586 params->has_committed_real_load);
dchengc5ef1a52015-08-26 20:58:30587 }
588
Daniel Chengd5e56ff2017-06-24 07:44:02589 // TODO(dcheng): Shouldn't these be mutually exclusive at this point? See
590 // https://crbug.com/720116 where the browser is apparently sending both
591 // routing IDs...
Balazs Engedyba034e72017-10-27 22:26:28592 if (params->proxy_routing_id != MSG_ROUTING_NONE) {
593 CHECK(params->swapped_out);
594 RenderFrameProxy::CreateFrameProxy(params->proxy_routing_id, GetRoutingID(),
nick3b5a21f2016-11-22 23:07:11595 opener_frame, MSG_ROUTING_NONE,
Dmitry Gozman89361212018-02-13 16:10:44596 params->replicated_frame_state,
597 params->devtools_main_frame_token);
nasko4c0feb62015-06-05 18:37:06598 }
599
nasko4c0feb62015-06-05 18:37:06600 if (main_render_frame_)
601 main_render_frame_->Initialize();
602
nickf7b38222016-11-22 21:59:35603 // If this RenderView's creation was initiated by an opener page in this
604 // process, (e.g. window.open()), we won't be visible until we ask the opener,
605 // via show_callback, to make us visible. Otherwise, we went through a
606 // browser-initiated creation, and show() won't be called.
607 if (!was_created_by_renderer)
[email protected]676126f72011-01-15 00:03:51608 did_show_ = true;
mfomitchev5ad034ec2015-04-24 21:57:27609
[email protected]c7c0d822014-04-16 20:19:49610 // TODO(davidben): Move this state from Blink into content.
Balazs Engedyba034e72017-10-27 22:26:28611 if (params->window_was_created_with_opener)
Blink Reformat1c4d759e2017-04-09 16:34:54612 webview()->SetOpenedByDOM();
[email protected]c7c0d822014-04-16 20:19:49613
dcheng0ff94cfc2016-03-15 21:50:51614 UpdateWebViewWithDeviceScaleFactor();
Balazs Engedyba034e72017-10-27 22:26:28615 OnSetRendererPrefs(params->renderer_preferences);
[email protected]34c61bd52011-05-02 19:38:33616
Balazs Engedyba034e72017-10-27 22:26:28617 if (!params->enable_auto_resize) {
618 OnResize(params->initial_size);
mkosiba58fa72f02014-11-12 01:21:36619 } else {
Balazs Engedyba034e72017-10-27 22:26:28620 OnEnableAutoResize(params->min_size, params->max_size);
mkosiba58fa72f02014-11-12 01:21:36621 }
622
dtapuska9ec1a912017-04-21 15:18:31623 idle_user_detector_.reset(new IdleUserDetector(this));
[email protected]1784b2f2011-11-24 10:53:48624
[email protected]e9ff79c2012-10-19 21:31:26625 GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44626
Balazs Engedyba034e72017-10-27 22:26:28627 page_zoom_level_ = params->page_zoom_level;
Hajime Hoshif34374412018-03-05 14:32:54628
629 nav_state_sync_timer_.SetTaskRunner(task_runner);
630 check_preferred_size_timer_.SetTaskRunner(std::move(task_runner));
initial.commit09911bf2008-07-26 23:55:29631}
632
[email protected]310ebd6302011-10-10 19:06:28633RenderViewImpl::~RenderViewImpl() {
dcheng3ce04b62015-10-26 23:30:55634 DCHECK(!frame_widget_);
635
[email protected]8ed1d3f2013-02-20 11:45:55636#if defined(OS_ANDROID)
davve17e025e12016-05-23 15:30:20637 // The date/time picker client is both a std::unique_ptr member of this class
638 // and a RenderViewObserver. Reset it to prevent double deletion.
[email protected]8ed1d3f2013-02-20 11:45:55639 date_time_picker_client_.reset();
640#endif
641
[email protected]60c42a8c72009-10-09 04:08:59642#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22643 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49644 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59645 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
646 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22647 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
648 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
649 it != routing_id_views->end(); ++it)
650 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59651#endif
[email protected]676126f72011-01-15 00:03:51652
dtapuska9ec1a912017-04-21 15:18:31653 idle_user_detector_.reset();
ericwilligers88e69742016-10-17 19:29:55654 for (auto& observer : observers_)
655 observer.RenderViewGone();
656 for (auto& observer : observers_)
657 observer.OnDestruct();
[email protected]60c42a8c72009-10-09 04:08:59658}
659
660/*static*/
[email protected]310ebd6302011-10-10 19:06:28661RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31662 ViewMap* views = g_view_map.Pointer();
663 ViewMap::iterator it = views->find(webview);
664 return it == views->end() ? NULL : it->second;
665}
666
667/*static*/
[email protected]180ef242013-11-07 06:50:46668RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28669 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31670}
671
672/*static*/
avi1023d012015-12-25 02:39:14673RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) {
[email protected]640e303c2012-12-05 01:36:07674 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
675 RoutingIDViewMap::iterator it = views->find(routing_id);
676 return it == views->end() ? NULL : it->second;
677}
678
679/*static*/
680RenderView* RenderView::FromRoutingID(int routing_id) {
681 return RenderViewImpl::FromRoutingID(routing_id);
682}
683
[email protected]f3a95312014-06-12 16:46:58684/* static */
jochen9c7b8f242015-06-01 15:32:02685size_t RenderView::GetRenderViewCount() {
[email protected]f3a95312014-06-12 16:46:58686 return g_view_map.Get().size();
687}
688
[email protected]640e303c2012-12-05 01:36:07689/*static*/
[email protected]e9ff79c2012-10-19 21:31:26690void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49691 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59692 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
693 if (!visitor->Visit(it->second))
694 return;
695 }
696}
697
698/*static*/
[email protected]b3a97b52014-07-09 06:25:05699void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
700 WebView* web_view) {
Blink Reformat1c4d759e2017-04-09 16:34:54701 WebSettings* settings = web_view->GetSettings();
[email protected]b3a97b52014-07-09 06:25:05702 ApplyFontsFromMap(prefs.standard_font_family_map,
703 SetStandardFontFamilyWrapper, settings);
704 ApplyFontsFromMap(prefs.fixed_font_family_map,
705 SetFixedFontFamilyWrapper, settings);
706 ApplyFontsFromMap(prefs.serif_font_family_map,
707 SetSerifFontFamilyWrapper, settings);
708 ApplyFontsFromMap(prefs.sans_serif_font_family_map,
709 SetSansSerifFontFamilyWrapper, settings);
710 ApplyFontsFromMap(prefs.cursive_font_family_map,
711 SetCursiveFontFamilyWrapper, settings);
712 ApplyFontsFromMap(prefs.fantasy_font_family_map,
713 SetFantasyFontFamilyWrapper, settings);
714 ApplyFontsFromMap(prefs.pictograph_font_family_map,
715 SetPictographFontFamilyWrapper, settings);
Blink Reformat1c4d759e2017-04-09 16:34:54716 settings->SetDefaultFontSize(prefs.default_font_size);
717 settings->SetDefaultFixedFontSize(prefs.default_fixed_font_size);
718 settings->SetMinimumFontSize(prefs.minimum_font_size);
719 settings->SetMinimumLogicalFontSize(prefs.minimum_logical_font_size);
720 settings->SetDefaultTextEncodingName(
721 WebString::FromASCII(prefs.default_encoding));
722 settings->SetJavaScriptEnabled(prefs.javascript_enabled);
723 settings->SetWebSecurityEnabled(prefs.web_security_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54724 settings->SetLoadsImagesAutomatically(prefs.loads_images_automatically);
725 settings->SetImagesEnabled(prefs.images_enabled);
726 settings->SetPluginsEnabled(prefs.plugins_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54727 settings->SetDOMPasteAllowed(prefs.dom_paste_enabled);
728 settings->SetTextAreasAreResizable(prefs.text_areas_are_resizable);
729 settings->SetAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
730 settings->SetDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
731 settings->SetJavaScriptCanAccessClipboard(
[email protected]b3a97b52014-07-09 06:25:05732 prefs.javascript_can_access_clipboard);
Blink Reformat1c4d759e2017-04-09 16:34:54733 WebRuntimeFeatures::EnableXSLT(prefs.xslt_enabled);
734 settings->SetXSSAuditorEnabled(prefs.xss_auditor_enabled);
735 settings->SetDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
Tarun Bansalabd3ef02017-11-03 15:19:20736 blink::WebNetworkStateNotifier::SetSaveDataEnabled(
Tarun Bansal73dd2ff82017-10-03 05:29:34737 prefs.data_saver_enabled &&
738 !base::FeatureList::IsEnabled(features::kDataSaverHoldback));
Blink Reformat1c4d759e2017-04-09 16:34:54739 settings->SetLocalStorageEnabled(prefs.local_storage_enabled);
740 settings->SetSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
741 WebRuntimeFeatures::EnableDatabase(prefs.databases_enabled);
742 settings->SetOfflineWebApplicationCacheEnabled(
[email protected]b3a97b52014-07-09 06:25:05743 prefs.application_cache_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54744 settings->SetHistoryEntryRequiresUserGesture(
japhet5018fe62016-09-14 19:14:04745 prefs.history_entry_requires_user_gesture);
Blink Reformat1c4d759e2017-04-09 16:34:54746 settings->SetHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
747 settings->SetCookieEnabled(prefs.cookie_enabled);
748 settings->SetNavigateOnDragDrop(prefs.navigate_on_drag_drop);
[email protected]b3a97b52014-07-09 06:25:05749
[email protected]b3a97b52014-07-09 06:25:05750 // By default, allow_universal_access_from_file_urls is set to false and thus
751 // we mitigate attacks from local HTML files by not granting file:// URLs
752 // universal access. Only test shell will enable this.
Blink Reformat1c4d759e2017-04-09 16:34:54753 settings->SetAllowUniversalAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05754 prefs.allow_universal_access_from_file_urls);
Blink Reformat1c4d759e2017-04-09 16:34:54755 settings->SetAllowFileAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05756 prefs.allow_file_access_from_file_urls);
757
Zhenyao Moa3fda9972017-09-16 01:34:40758 settings->SetWebGL1Enabled(prefs.webgl1_enabled);
759 settings->SetWebGL2Enabled(prefs.webgl2_enabled);
[email protected]b3a97b52014-07-09 06:25:05760
[email protected]b3a97b52014-07-09 06:25:05761 // Enable WebGL errors to the JS console if requested.
Blink Reformat1c4d759e2017-04-09 16:34:54762 settings->SetWebGLErrorsToConsoleEnabled(
[email protected]b3a97b52014-07-09 06:25:05763 prefs.webgl_errors_to_console_enabled);
764
765 // Uses the mock theme engine for scrollbars.
Blink Reformat1c4d759e2017-04-09 16:34:54766 settings->SetMockScrollbarsEnabled(prefs.mock_scrollbars_enabled);
[email protected]b3a97b52014-07-09 06:25:05767
Blink Reformat1c4d759e2017-04-09 16:34:54768 settings->SetHideScrollbars(prefs.hide_scrollbars);
eseckler61ff9142016-09-23 22:57:59769
[email protected]b3a97b52014-07-09 06:25:05770 // Enable gpu-accelerated 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54771 WebRuntimeFeatures::EnableAccelerated2dCanvas(
junov524668f22016-08-08 20:16:52772 prefs.accelerated_2d_canvas_enabled);
[email protected]b3a97b52014-07-09 06:25:05773
Blink Reformat1c4d759e2017-04-09 16:34:54774 settings->SetMinimumAccelerated2dCanvasSize(
[email protected]b3a97b52014-07-09 06:25:05775 prefs.minimum_accelerated_2d_canvas_size);
776
777 // Disable antialiasing for 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54778 settings->SetAntialiased2dCanvasEnabled(
[email protected]b3a97b52014-07-09 06:25:05779 !prefs.antialiased_2d_canvas_disabled);
780
zakerinasab20ebca02016-09-27 14:22:34781 // Disable antialiasing of clips for 2d canvas if requested on the command
robertphillipse25137b2014-10-20 13:44:34782 // line.
Blink Reformat1c4d759e2017-04-09 16:34:54783 settings->SetAntialiasedClips2dCanvasEnabled(
robertphillipse25137b2014-10-20 13:44:34784 prefs.antialiased_clips_2d_canvas_enabled);
785
[email protected]b3a97b52014-07-09 06:25:05786 // Set MSAA sample count for 2d canvas if requested on the command line (or
787 // default value if not).
Blink Reformat1c4d759e2017-04-09 16:34:54788 settings->SetAccelerated2dCanvasMSAASampleCount(
[email protected]b3a97b52014-07-09 06:25:05789 prefs.accelerated_2d_canvas_msaa_sample_count);
790
[email protected]b3a97b52014-07-09 06:25:05791 // Tabs to link is not part of the settings. WebCore calls
792 // ChromeClient::tabsToLinks which is part of the glue code.
Blink Reformat1c4d759e2017-04-09 16:34:54793 web_view->SetTabsToLinks(prefs.tabs_to_links);
[email protected]b3a97b52014-07-09 06:25:05794
Blink Reformat1c4d759e2017-04-09 16:34:54795 settings->SetAllowRunningOfInsecureContent(
[email protected]b3a97b52014-07-09 06:25:05796 prefs.allow_running_insecure_content);
Blink Reformat1c4d759e2017-04-09 16:34:54797 settings->SetDisableReadingFromCanvas(prefs.disable_reading_from_canvas);
798 settings->SetStrictMixedContentChecking(prefs.strict_mixed_content_checking);
mkwst2384c8222015-07-30 07:26:47799
Blink Reformat1c4d759e2017-04-09 16:34:54800 settings->SetStrictlyBlockBlockableMixedContent(
mkwst2384c8222015-07-30 07:26:47801 prefs.strictly_block_blockable_mixed_content);
802
Blink Reformat1c4d759e2017-04-09 16:34:54803 settings->SetStrictMixedContentCheckingForPlugin(
mkwst0d233e52015-08-10 09:33:14804 prefs.block_mixed_plugin_content);
805
Blink Reformat1c4d759e2017-04-09 16:34:54806 settings->SetStrictPowerfulFeatureRestrictions(
mkwst673a452f2015-01-10 14:41:50807 prefs.strict_powerful_feature_restrictions);
Blink Reformat1c4d759e2017-04-09 16:34:54808 settings->SetAllowGeolocationOnInsecureOrigins(
jww9d4ca2d2016-01-19 20:58:59809 prefs.allow_geolocation_on_insecure_origins);
Blink Reformat1c4d759e2017-04-09 16:34:54810 settings->SetPasswordEchoEnabled(prefs.password_echo_enabled);
811 settings->SetShouldPrintBackgrounds(prefs.should_print_backgrounds);
812 settings->SetShouldClearDocumentBackground(
[email protected]b3a97b52014-07-09 06:25:05813 prefs.should_clear_document_background);
Blink Reformat1c4d759e2017-04-09 16:34:54814 settings->SetEnableScrollAnimator(prefs.enable_scroll_animator);
[email protected]b3a97b52014-07-09 06:25:05815
Blink Reformat1c4d759e2017-04-09 16:34:54816 WebRuntimeFeatures::EnableTouchEventFeatureDetection(
sunyunjiafa6a8afc2016-12-09 04:25:47817 prefs.touch_event_feature_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54818 settings->SetMaxTouchPoints(prefs.pointer_events_max_touch_points);
819 settings->SetAvailablePointerTypes(prefs.available_pointer_types);
820 settings->SetPrimaryPointerType(
nzolghadrc0d1663c2015-11-26 21:15:24821 static_cast<blink::PointerType>(prefs.primary_pointer_type));
Blink Reformat1c4d759e2017-04-09 16:34:54822 settings->SetAvailableHoverTypes(prefs.available_hover_types);
823 settings->SetPrimaryHoverType(
nzolghadrc0d1663c2015-11-26 21:15:24824 static_cast<blink::HoverType>(prefs.primary_hover_type));
Blink Reformat1c4d759e2017-04-09 16:34:54825 settings->SetEnableTouchAdjustment(prefs.touch_adjustment_enabled);
Dave Tapuskaa59fdb62017-08-23 16:28:27826 settings->SetBarrelButtonForDragEnabled(prefs.barrel_button_for_drag_enabled);
[email protected]b3a97b52014-07-09 06:25:05827
Blink Reformat1c4d759e2017-04-09 16:34:54828 settings->SetShouldRespectImageOrientation(
[email protected]b3a97b52014-07-09 06:25:05829 prefs.should_respect_image_orientation);
830
Blink Reformat1c4d759e2017-04-09 16:34:54831 settings->SetEditingBehavior(
[email protected]b3a97b52014-07-09 06:25:05832 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
833
Blink Reformat1c4d759e2017-04-09 16:34:54834 settings->SetSupportsMultipleWindows(prefs.supports_multiple_windows);
[email protected]b3a97b52014-07-09 06:25:05835
Blink Reformat1c4d759e2017-04-09 16:34:54836 settings->SetMainFrameClipsContent(!prefs.record_whole_document);
khushalsagar2da2b232016-03-23 22:11:35837
Blink Reformat1c4d759e2017-04-09 16:34:54838 settings->SetSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
[email protected]b3a97b52014-07-09 06:25:05839
Blink Reformat1c4d759e2017-04-09 16:34:54840 settings->SetSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
[email protected]b3a97b52014-07-09 06:25:05841
Blink Reformat1c4d759e2017-04-09 16:34:54842 settings->SetSelectionIncludesAltImageText(true);
[email protected]b3a97b52014-07-09 06:25:05843
Blink Reformat1c4d759e2017-04-09 16:34:54844 settings->SetV8CacheOptions(
[email protected]35103c02014-08-12 15:08:47845 static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options));
846
Blink Reformat1c4d759e2017-04-09 16:34:54847 settings->SetImageAnimationPolicy(
je_julie.kim7fbb5a1a2015-02-09 17:26:05848 static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy));
849
Blink Reformat1c4d759e2017-04-09 16:34:54850 settings->SetPresentationRequiresUserGesture(
zqzhang1215ad422016-02-10 13:27:22851 prefs.user_gesture_required_for_presentation);
852
Blink Reformat1c4d759e2017-04-09 16:34:54853 settings->SetTextTrackMarginPercentage(prefs.text_track_margin_percentage);
halliwell4002be42016-03-18 18:33:40854
dcheng5ae8ca362015-02-05 04:03:47855 // Needs to happen before setIgnoreVIewportTagScaleLimits below.
Blink Reformat1c4d759e2017-04-09 16:34:54856 web_view->SetDefaultPageScaleLimits(prefs.default_minimum_page_scale_factor,
857 prefs.default_maximum_page_scale_factor);
dcheng5ae8ca362015-02-05 04:03:47858
Nate Chapin9638e7102017-09-20 22:11:01859 settings->SetSavePreviousDocumentResources(
860 static_cast<WebSettings::SavePreviousDocumentResources>(
861 prefs.save_previous_document_resources));
862
[email protected]b3a97b52014-07-09 06:25:05863#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:54864 settings->SetAllowCustomScrollbarInMainFrame(false);
865 settings->SetTextAutosizingEnabled(prefs.text_autosizing_enabled);
866 settings->SetAccessibilityFontScaleFactor(prefs.font_scale_factor);
867 settings->SetDeviceScaleAdjustment(prefs.device_scale_adjustment);
868 settings->SetFullscreenSupported(prefs.fullscreen_supported);
869 web_view->SetIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
870 settings->SetAutoZoomFocusedNodeToLegibleScale(true);
871 settings->SetDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54872 settings->SetMediaPlaybackGestureWhitelistScope(
873 blink::WebString::FromUTF8(prefs.media_playback_gesture_whitelist_scope));
874 settings->SetDefaultVideoPosterURL(
875 WebString::FromASCII(prefs.default_video_poster_url.spec()));
876 settings->SetSupportDeprecatedTargetDensityDPI(
[email protected]b3a97b52014-07-09 06:25:05877 prefs.support_deprecated_target_density_dpi);
Blink Reformat1c4d759e2017-04-09 16:34:54878 settings->SetUseLegacyBackgroundSizeShorthandBehavior(
[email protected]b3a97b52014-07-09 06:25:05879 prefs.use_legacy_background_size_shorthand_behavior);
Blink Reformat1c4d759e2017-04-09 16:34:54880 settings->SetWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
881 settings->SetUseWideViewport(prefs.use_wide_viewport);
882 settings->SetForceZeroLayoutHeight(prefs.force_zero_layout_height);
883 settings->SetViewportMetaLayoutSizeQuirk(
[email protected]b3a97b52014-07-09 06:25:05884 prefs.viewport_meta_layout_size_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54885 settings->SetViewportMetaMergeContentQuirk(
[email protected]b3a97b52014-07-09 06:25:05886 prefs.viewport_meta_merge_content_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54887 settings->SetViewportMetaNonUserScalableQuirk(
[email protected]b3a97b52014-07-09 06:25:05888 prefs.viewport_meta_non_user_scalable_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54889 settings->SetViewportMetaZeroValuesQuirk(
[email protected]b3a97b52014-07-09 06:25:05890 prefs.viewport_meta_zero_values_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54891 settings->SetClobberUserAgentInitialScaleQuirk(
[email protected]b3a97b52014-07-09 06:25:05892 prefs.clobber_user_agent_initial_scale_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54893 settings->SetIgnoreMainFrameOverflowHiddenQuirk(
[email protected]b3a97b52014-07-09 06:25:05894 prefs.ignore_main_frame_overflow_hidden_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54895 settings->SetReportScreenSizeInPhysicalPixelsQuirk(
[email protected]b3a97b52014-07-09 06:25:05896 prefs.report_screen_size_in_physical_pixels_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54897 settings->SetShouldReuseGlobalForUnownedMainFrame(
boliu1a00f262016-04-06 19:08:46898 prefs.resue_global_for_unowned_main_frame);
Blink Reformat1c4d759e2017-04-09 16:34:54899 settings->SetPreferHiddenVolumeControls(true);
900 settings->SetSpellCheckEnabledByDefault(prefs.spellcheck_enabled_by_default);
dalecurtiscd971252016-09-21 16:09:00901
aeliase678aa42017-04-14 22:41:04902 // Force preload=none and disable autoplay on older Android
dalecurtiscd971252016-09-21 16:09:00903 // platforms because their media pipelines are not stable enough to handle
904 // concurrent elements. See http://crbug.com/612909, http://crbug.com/622826.
aeliase678aa42017-04-14 22:41:04905 const bool is_jelly_bean =
dalecurtiscd971252016-09-21 16:09:00906 base::android::BuildInfo::GetInstance()->sdk_int() <=
aeliase678aa42017-04-14 22:41:04907 base::android::SDK_VERSION_JELLY_BEAN_MR2;
908 settings->SetForcePreloadNoneForMediaElements(is_jelly_bean);
mlamouri1d266bf2016-12-05 17:42:36909
Blink Reformat1c4d759e2017-04-09 16:34:54910 WebRuntimeFeatures::EnableVideoFullscreenOrientationLock(
mlamouri1d266bf2016-12-05 17:42:36911 prefs.video_fullscreen_orientation_lock_enabled);
johnme913ee5f2017-04-28 21:36:16912 WebRuntimeFeatures::EnableVideoRotateToFullscreen(
913 prefs.video_rotate_to_fullscreen_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54914 WebRuntimeFeatures::EnableVideoFullscreenDetection(
zqzhang93e959d12017-03-16 13:10:20915 prefs.video_fullscreen_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54916 settings->SetEmbeddedMediaExperienceEnabled(
shaktisahuf97f7532017-02-24 22:46:13917 prefs.embedded_media_experience_enabled);
Ian Vollickeeca1d82018-02-07 02:43:42918 settings->SetImmersiveModeEnabled(prefs.immersive_mode_enabled);
khushalsagarc5447db22017-08-22 17:53:01919 settings->SetMediaDownloadInProductHelpEnabled(
920 prefs.enable_media_download_in_product_help);
Blink Reformat1c4d759e2017-04-09 16:34:54921 settings->SetDoNotUpdateSelectionOnMutatingSelectionRange(
changwane54ccdb92017-04-05 19:20:54922 prefs.do_not_update_selection_on_mutating_selection_range);
Noel Gordonf311a842017-07-27 00:10:07923 WebRuntimeFeatures::EnableCSSHexAlphaColor(prefs.css_hex_alpha_color_enabled);
Tobias Sargeant416174f2017-09-01 01:18:09924 WebRuntimeFeatures::EnableScrollTopLeftInterop(
925 prefs.scroll_top_left_interop_enabled);
zqzhangdf72ed082016-12-08 16:07:55926#endif // defined(OS_ANDROID)
liberato9e934892016-05-03 19:00:27927
mlamouri55a0543c2017-05-11 10:34:07928 switch (prefs.autoplay_policy) {
929 case AutoplayPolicy::kNoUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28930 settings->SetAutoplayPolicy(
931 WebSettings::AutoplayPolicy::kNoUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07932 break;
933 case AutoplayPolicy::kUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28934 settings->SetAutoplayPolicy(
935 WebSettings::AutoplayPolicy::kUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07936 break;
937 case AutoplayPolicy::kUserGestureRequiredForCrossOrigin:
mlamouri276a6f32017-05-12 09:24:28938 settings->SetAutoplayPolicy(
939 WebSettings::AutoplayPolicy::kUserGestureRequiredForCrossOrigin);
mlamouri55a0543c2017-05-11 10:34:07940 break;
mlamouri431bb4e2017-06-06 08:54:24941 case AutoplayPolicy::kDocumentUserActivationRequired:
942 settings->SetAutoplayPolicy(
943 WebSettings::AutoplayPolicy::kDocumentUserActivationRequired);
944 break;
mlamouri55a0543c2017-05-11 10:34:07945 }
946
Blink Reformat1c4d759e2017-04-09 16:34:54947 settings->SetViewportEnabled(prefs.viewport_enabled);
948 settings->SetViewportMetaEnabled(prefs.viewport_meta_enabled);
949 settings->SetShrinksViewportContentToFit(
950 prefs.shrinks_viewport_contents_to_fit);
951 settings->SetViewportStyle(
alokp5d566962016-04-19 00:54:16952 static_cast<blink::WebViewportStyle>(prefs.viewport_style));
953
Blink Reformat1c4d759e2017-04-09 16:34:54954 settings->SetLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
955 settings->SetMainFrameResizesAreOrientationChanges(
yoava1a508b42015-10-20 12:03:21956 prefs.main_frame_resizes_are_orientation_changes);
957
Blink Reformat1c4d759e2017-04-09 16:34:54958 settings->SetUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
jinho.bang8f11ffa2014-12-04 06:03:03959
Blink Reformat1c4d759e2017-04-09 16:34:54960 settings->SetShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up);
961 settings->SetAlwaysShowContextMenuOnTouch(
amaralp547e4192016-06-03 19:17:35962 prefs.always_show_context_menu_on_touch);
ccameron2fd70de72015-02-19 00:40:40963
Blink Reformat1c4d759e2017-04-09 16:34:54964 settings->SetHideDownloadUI(prefs.hide_download_ui);
965 WebRuntimeFeatures::EnableBackgroundVideoTrackOptimization(
avayvod39c102402016-11-23 21:43:13966 prefs.background_video_track_optimization_enabled);
avayvod232757942017-04-29 04:12:34967 WebRuntimeFeatures::EnableNewRemotePlaybackPipeline(
968 base::FeatureList::IsEnabled(media::kNewRemotePlaybackPipeline));
qinmin72e8bd02016-10-21 19:35:37969
Blink Reformat1c4d759e2017-04-09 16:34:54970 settings->SetPresentationReceiver(prefs.presentation_receiver);
mlamouri57359d912016-11-29 20:11:50971
Blink Reformat1c4d759e2017-04-09 16:34:54972 settings->SetMediaControlsEnabled(prefs.media_controls_enabled);
mlamouri5cd9ae82017-02-18 11:05:09973
Tarun Bansal73d67f02018-01-17 05:56:25974 settings->SetLowPriorityIframesThreshold(
975 static_cast<blink::WebEffectiveConnectionType>(
976 prefs.low_priority_iframes_threshold));
977
François Beaufort8c08979fc2018-03-05 13:06:31978 settings->SetPictureInPictureEnabled(prefs.picture_in_picture_enabled);
979
ccameron2fd70de72015-02-19 00:40:40980#if defined(OS_MACOSX)
Blink Reformat1c4d759e2017-04-09 16:34:54981 settings->SetDoubleTapToZoomEnabled(true);
982 web_view->SetMaximumLegibleScale(prefs.default_maximum_page_scale_factor);
ccameron2fd70de72015-02-19 00:40:40983#endif
sunyunjia87f287b2016-09-09 00:38:13984
985#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:54986 WebRuntimeFeatures::EnableMiddleClickAutoscroll(true);
sunyunjia87f287b2016-09-09 00:38:13987#endif
[email protected]b3a97b52014-07-09 06:25:05988}
989
990/*static*/
nickf7b38222016-11-22 21:59:35991RenderViewImpl* RenderViewImpl::Create(
992 CompositorDependencies* compositor_deps,
Balazs Engedyba034e72017-10-27 22:26:28993 mojom::CreateViewParamsPtr params,
Hajime Hoshiabb3c8f2017-12-04 18:41:39994 const RenderWidget::ShowCallback& show_callback,
995 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Balazs Engedyba034e72017-10-27 22:26:28996 DCHECK(params->view_id != MSG_ROUTING_NONE);
Lei Zhang88f23ba2017-10-27 05:56:26997 RenderViewImpl* render_view;
[email protected]8d41d7612012-11-14 20:32:19998 if (g_create_render_view_impl)
Balazs Engedyba034e72017-10-27 22:26:28999 render_view = g_create_render_view_impl(compositor_deps, *params);
[email protected]075366912013-02-18 07:13:241000 else
Hajime Hoshiabb3c8f2017-12-04 18:41:391001 render_view = new RenderViewImpl(compositor_deps, *params, task_runner);
[email protected]0287e762014-04-11 13:07:581002
Hajime Hoshif34374412018-03-05 14:32:541003 render_view->Initialize(std::move(params), show_callback,
1004 std::move(task_runner));
[email protected]075366912013-02-18 07:13:241005 return render_view;
[email protected]8d41d7612012-11-14 20:32:191006}
1007
1008// static
dcheng35d31c112015-07-22 00:17:361009void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
1010 *create_render_view_impl)(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:151011 const mojom::CreateViewParams&)) {
[email protected]8d41d7612012-11-14 20:32:191012 CHECK(!g_create_render_view_impl);
1013 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291014}
1015
[email protected]310ebd6302011-10-10 19:06:281016void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511017 observers_.AddObserver(observer);
1018}
1019
[email protected]310ebd6302011-10-10 19:06:281020void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1021 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511022 observers_.RemoveObserver(observer);
1023}
1024
Peter Kastinga4a3ed12018-01-31 04:07:591025blink::WebView* RenderViewImpl::webview() {
1026 return webview_;
1027}
1028
1029const blink::WebView* RenderViewImpl::webview() const {
lfg4fa48da2016-05-09 18:25:131030 return webview_;
[email protected]4d51d5bf2010-07-26 18:48:261031}
1032
brettw4b461082016-11-19 18:55:161033#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:571034
[email protected]784ea1ab2010-09-18 00:02:341035#if defined(OS_MACOSX)
[email protected]7411a3c2014-08-15 05:20:191036void RenderViewImpl::OnGetRenderedText() {
1037 if (!webview())
1038 return;
dglazkov03223492016-02-08 22:16:031039
Blink Reformat1c4d759e2017-04-09 16:34:541040 if (!webview()->MainFrame()->IsWebLocalFrame())
dglazkov03223492016-02-08 22:16:031041 return;
1042
[email protected]7411a3c2014-08-15 05:20:191043 // Get rendered text from WebLocalFrame.
1044 // TODO: Currently IPC truncates any data that has a
1045 // size > kMaximumMessageSize. May be split the text into smaller chunks and
1046 // send back using multiple IPC. See http://crbug.com/393444.
1047 static const size_t kMaximumMessageSize = 8 * 1024 * 1024;
dglazkov03223492016-02-08 22:16:031048 // TODO(dglazkov): Using this API is wrong. It's not OOPIF-compatible and
1049 // sends text in the wrong order. See http://crbug.com/584798.
1050 // TODO(dglazkov): WebFrameContentDumper should only be used for
1051 // testing purposes. See http://crbug.com/585164.
1052 std::string text =
Blink Reformat1c4d759e2017-04-09 16:34:541053 WebFrameContentDumper::DumpWebViewAsText(webview(), kMaximumMessageSize)
1054 .Utf8();
[email protected]7411a3c2014-08-15 05:20:191055
avia3dca182016-03-19 01:09:521056 Send(new ViewMsg_GetRenderedTextCompleted(GetRoutingID(), text));
[email protected]7411a3c2014-08-15 05:20:191057}
[email protected]a80af12e2013-08-07 23:36:131058#endif // defined(OS_MACOSX)
1059
1060#endif // ENABLE_PLUGINS
1061
fsamuel72464894f2015-12-15 06:59:311062// RenderWidgetInputHandlerDelegate -----------------------------------------
1063
avid7d6b2e2016-03-04 19:41:171064bool RenderViewImpl::RenderWidgetWillHandleMouseEvent(
1065 const blink::WebMouseEvent& event) {
fsamuel72464894f2015-12-15 06:59:311066 // If the mouse is locked, only the current owner of the mouse lock can
1067 // process mouse events.
1068 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
1069}
1070
1071// IPC::Listener implementation ----------------------------------------------
1072
[email protected]310ebd6302011-10-10 19:06:281073bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281074 WebFrame* main_frame = webview() ? webview()->MainFrame() : nullptr;
Avi Drissmanb5f8e242017-12-12 05:21:561075 if (main_frame) {
1076 GURL active_url;
1077 if (main_frame->IsWebLocalFrame())
1078 active_url = main_frame->ToWebLocalFrame()->GetDocument().Url();
lukaszabedb4b22017-06-23 00:00:131079 GetContentClient()->SetActiveURL(
Avi Drissmanb5f8e242017-12-12 05:21:561080 active_url, main_frame->Top()->GetSecurityOrigin().ToString().Utf8());
1081 }
[email protected]f8b6b6f2009-03-10 16:48:261082
naskoc6edf7e2015-10-16 01:48:451083 // Input IPC messages must not be processed if the RenderView is in
1084 // swapped out state.
dtapuska1b0fcc322016-10-28 18:08:281085 if (is_swapped_out_ &&
1086 IPC_MESSAGE_ID_CLASS(message.type()) == InputMsgStart) {
dtapuska1b0fcc322016-10-28 18:08:281087 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
1088 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnDiscardInputEvent)
1089 IPC_END_MESSAGE_MAP()
naskoc6edf7e2015-10-16 01:48:451090 return false;
dtapuska1b0fcc322016-10-28 18:08:281091 }
naskoc6edf7e2015-10-16 01:48:451092
dchenga2d442c22016-10-13 15:39:211093 for (auto& observer : observers_) {
1094 if (observer.OnMessageReceived(message))
[email protected]676126f72011-01-15 00:03:511095 return true;
dchenga2d442c22016-10-13 15:39:211096 }
[email protected]b2abac72009-02-26 12:39:281097
[email protected]a95986a82010-12-24 06:19:281098 bool handled = true;
[email protected]e44d1342014-05-16 21:29:331099 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
mcnee432e47d2015-11-09 19:37:461100 IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale)
initial.commit09911bf2008-07-26 23:55:291101 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291102 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1103 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]600ea402011-04-12 00:01:511104 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
1105 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:291106 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
[email protected]30f75e62009-02-25 22:01:001107 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]61f91832014-05-13 01:24:421108 IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque, OnSetBackgroundOpaque)
[email protected]ab32b16c2009-10-16 14:57:251109 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1110 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:471111 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:341112 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
Fady Samuel69b33b52017-11-08 22:01:521113 IPC_MESSAGE_HANDLER(ViewMsg_SetLocalSurfaceIdForAutoResize,
1114 OnSetLocalSurfaceIdForAutoResize)
[email protected]cda45c02010-02-25 19:28:101115 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1116 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511117 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:561118 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:361119 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:341120 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
aelias1b55156e52017-04-01 00:46:051121 IPC_MESSAGE_HANDLER(ViewMsg_ResolveTapDisambiguation,
1122 OnResolveTapDisambiguation)
[email protected]506563d2014-06-23 12:22:411123 IPC_MESSAGE_HANDLER(ViewMsg_ForceRedraw, OnForceRedraw)
[email protected]4dda6a6c2014-05-17 15:35:041124 IPC_MESSAGE_HANDLER(ViewMsg_SelectWordAroundCaret, OnSelectWordAroundCaret)
wjmaclean64951902016-04-29 20:59:121125
1126 // Page messages.
lfgdb5c4ed2016-03-04 23:09:071127 IPC_MESSAGE_HANDLER(PageMsg_UpdateWindowScreenRect,
1128 OnUpdateWindowScreenRect)
wjmaclean64951902016-04-29 20:59:121129 IPC_MESSAGE_HANDLER(PageMsg_SetZoomLevel, OnSetZoomLevel)
lfg717154072016-06-30 15:04:161130 IPC_MESSAGE_HANDLER(PageMsg_WasHidden, OnPageWasHidden)
1131 IPC_MESSAGE_HANDLER(PageMsg_WasShown, OnPageWasShown)
alexmos136fd6e62016-08-15 20:58:411132 IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength,
1133 OnSetHistoryOffsetAndLength)
altimind8bd26c2016-11-04 11:44:541134 IPC_MESSAGE_HANDLER(PageMsg_AudioStateChanged, OnAudioStateChanged)
lfg8d649cc2017-04-28 18:04:301135 IPC_MESSAGE_HANDLER(PageMsg_UpdateScreenInfo, OnUpdateScreenInfo)
Fadi Meawada6573e02018-03-10 00:52:111136 IPC_MESSAGE_HANDLER(PageMsg_FreezePage, OnFreezePage)
lfg717154072016-06-30 15:04:161137
Matthew Jonesb4456421b2018-02-22 20:29:411138#if defined(OS_MACOSX)
[email protected]7411a3c2014-08-15 05:20:191139 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedText,
1140 OnGetRenderedText)
naskoc288745f2015-05-01 22:54:211141 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]55750b32012-09-21 14:05:031142#endif
[email protected]a794f3a2013-10-30 17:00:321143 // Adding a new message? Add platform independent ones first, then put the
1144 // platform specific ones at the end.
[email protected]9e1ad4b2011-08-14 16:49:191145
initial.commit09911bf2008-07-26 23:55:291146 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281147 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291148 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401149
[email protected]a95986a82010-12-24 06:19:281150 return handled;
initial.commit09911bf2008-07-26 23:55:291151}
1152
[email protected]4dda6a6c2014-05-17 15:35:041153void RenderViewImpl::OnSelectWordAroundCaret() {
donnd701cc202017-05-17 23:11:201154 // Set default values for the ACK
1155 bool did_select = false;
1156 int start_adjust = 0;
1157 int end_adjust = 0;
[email protected]4dda6a6c2014-05-17 15:35:041158
donnd701cc202017-05-17 23:11:201159 if (webview()) {
1160 WebLocalFrame* focused_frame = GetWebView()->FocusedFrame();
1161 if (focused_frame) {
1162 input_handler_->set_handling_input_event(true);
1163 blink::WebRange initial_range = focused_frame->SelectionRange();
donndbde109ff2017-05-26 20:20:011164 if (!initial_range.IsNull())
1165 did_select = focused_frame->SelectWordAroundCaret();
donnd701cc202017-05-17 23:11:201166 if (did_select) {
1167 blink::WebRange adjusted_range = focused_frame->SelectionRange();
1168 start_adjust =
1169 adjusted_range.StartOffset() - initial_range.StartOffset();
1170 end_adjust = adjusted_range.EndOffset() - initial_range.EndOffset();
1171 }
1172 input_handler_->set_handling_input_event(false);
1173 }
1174 }
1175 Send(new ViewHostMsg_SelectWordAroundCaretAck(GetRoutingID(), did_select,
1176 start_adjust, end_adjust));
[email protected]4dda6a6c2014-05-17 15:35:041177}
1178
[email protected]310ebd6302011-10-10 19:06:281179void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291180 // Check if there is a targeturl waiting to be sent.
avi450ce00e2014-09-24 01:58:521181 if (target_url_status_ == TARGET_PENDING)
avia3dca182016-03-19 01:09:521182 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), pending_target_url_));
initial.commit09911bf2008-07-26 23:55:291183
1184 target_url_status_ = TARGET_NONE;
1185}
1186
avi2b177592014-12-10 02:08:021187void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset,
1188 int history_length) {
arthursonzogni841b1d42018-01-31 08:42:291189 // -1 <= history_offset < history_length <= kMaxSessionHistoryEntries(50).
1190 DCHECK_LE(-1, history_offset);
1191 DCHECK_LT(history_offset, history_length);
1192 DCHECK_LE(history_length, kMaxSessionHistoryEntries);
[email protected]9e1ad4b2011-08-14 16:49:191193
avi2b177592014-12-10 02:08:021194 history_list_offset_ = history_offset;
1195 history_list_length_ = history_length;
[email protected]9e1ad4b2011-08-14 16:49:191196}
1197
[email protected]310ebd6302011-10-10 19:06:281198void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291199 if (!webview())
1200 return;
Blink Reformat1c4d759e2017-04-09 16:34:541201 webview()->SetInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291202}
1203
lfgdb5c4ed2016-03-04 23:09:071204void RenderViewImpl::OnUpdateWindowScreenRect(gfx::Rect window_screen_rect) {
1205 RenderWidget::OnUpdateWindowScreenRect(window_screen_rect);
1206}
1207
altimind8bd26c2016-11-04 11:44:541208void RenderViewImpl::OnAudioStateChanged(bool is_audio_playing) {
Blink Reformat1c4d759e2017-04-09 16:34:541209 webview()->AudioStateChanged(is_audio_playing);
altimind8bd26c2016-11-04 11:44:541210}
1211
initial.commit09911bf2008-07-26 23:55:291212///////////////////////////////////////////////////////////////////////////////
1213
nickf7b38222016-11-22 21:59:351214void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget,
1215 WebNavigationPolicy policy,
1216 const gfx::Rect& initial_rect) {
1217 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(),
1218 initial_rect));
1219}
1220
1221void RenderViewImpl::ShowCreatedFullscreenWidget(
1222 RenderWidget* fullscreen_widget,
1223 WebNavigationPolicy policy,
1224 const gfx::Rect& initial_rect) {
1225 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(),
1226 fullscreen_widget->routing_id()));
1227}
1228
creis69b184a472015-11-26 05:29:511229void RenderViewImpl::SendFrameStateUpdates() {
creis69b184a472015-11-26 05:29:511230 // Tell each frame with pending state to send its UpdateState message.
1231 for (int render_frame_routing_id : frames_with_pending_state_) {
1232 RenderFrameImpl* frame =
1233 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
1234 if (frame)
1235 frame->SendUpdateState();
1236 }
1237 frames_with_pending_state_.clear();
1238}
1239
sataya.mf405d0e2015-07-07 16:51:111240void RenderViewImpl::ApplyWebPreferencesInternal(
1241 const WebPreferences& prefs,
1242 blink::WebView* web_view,
1243 CompositorDependencies* compositor_deps) {
1244 ApplyWebPreferences(prefs, web_view);
sataya.mf405d0e2015-07-07 16:51:111245}
1246
svartmetal751af1f92016-08-13 11:47:331247void RenderViewImpl::OnForceRedraw(const ui::LatencyInfo& latency_info) {
[email protected]7d08a9352013-10-15 08:24:561248 if (RenderWidgetCompositor* rwc = compositor()) {
svartmetal751af1f92016-08-13 11:47:331249 rwc->QueueSwapPromise(
Jeremy Roman04f27c372017-10-27 15:20:551250 std::make_unique<AlwaysDrawSwapPromise>(latency_info));
danakj87fbafb2017-04-04 16:54:111251 rwc->SetNeedsForcedRedraw();
[email protected]7d08a9352013-10-15 08:24:561252 }
[email protected]c9bc8f12012-12-15 22:20:091253}
1254
[email protected]180ef242013-11-07 06:50:461255// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521256
csharrison95f01e922017-04-24 18:52:351257// TODO(csharrison): Migrate this method to WebFrameClient / RenderFrameImpl, as
1258// it is now serviced by a mojo interface scoped to the opener frame.
Blink Reformat1c4d759e2017-04-09 16:34:541259WebView* RenderViewImpl::CreateView(WebLocalFrame* creator,
[email protected]35b2a972014-04-04 15:50:221260 const WebURLRequest& request,
1261 const WebWindowFeatures& features,
1262 const WebString& frame_name,
1263 WebNavigationPolicy policy,
Daniel Chengd5e56ff2017-06-24 07:44:021264 bool suppress_opener,
1265 WebSandboxFlags sandbox_flags) {
nick5ae4d2d2017-01-06 01:18:351266 RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator);
rockot5c478a72016-09-28 23:14:181267 mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New();
Mustaq Ahmede473e4352017-11-04 01:04:251268 params->user_gesture =
1269 WebUserGestureIndicator::IsProcessingUserGesture(creator);
[email protected]00323f02013-07-24 15:47:411270 if (GetContentClient()->renderer()->AllowPopup())
rockot5c478a72016-09-28 23:14:181271 params->user_gesture = true;
1272 params->window_container_type = WindowFeaturesToContainerType(features);
Daniel Murphye3eec92c2018-02-23 19:09:151273
1274 params->session_storage_namespace_id = AllocateSessionStorageNamespaceId();
1275 params->clone_from_session_storage_namespace_id =
1276 session_storage_namespace_id_;
1277 if (base::FeatureList::IsEnabled(features::kMojoSessionStorage)) {
1278 RenderThreadImpl::current_blink_platform_impl()
1279 ->CloneSessionStorageNamespace(session_storage_namespace_id_,
1280 params->session_storage_namespace_id);
1281 }
1282
Daniel Chengd5e56ff2017-06-24 07:44:021283 const std::string& frame_name_utf8 = frame_name.Utf8(
1284 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
1285 params->frame_name = frame_name_utf8;
rockot5c478a72016-09-28 23:14:181286 params->opener_suppressed = suppress_opener;
1287 params->disposition = NavigationPolicyToDisposition(policy);
Blink Reformat1c4d759e2017-04-09 16:34:541288 if (!request.IsNull()) {
1289 params->target_url = request.Url();
rockot5c478a72016-09-28 23:14:181290 params->referrer = GetReferrerFromRequest(creator, request);
[email protected]44e55b012013-07-23 14:21:561291 }
scottmg8e6c6082017-02-13 23:15:481292 params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
[email protected]8ab04652010-06-12 02:47:261293
rockot5c478a72016-09-28 23:14:181294 // We preserve this information before sending the message since |params| is
1295 // moved on send.
1296 bool is_background_tab =
1297 params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB;
1298 bool opened_by_user_gesture = params->user_gesture;
[email protected]22217ed32013-11-18 18:40:231299
Daniel Cheng8bb30c62017-10-23 20:40:471300 mojom::CreateNewWindowStatus status;
rockot5c478a72016-09-28 23:14:181301 mojom::CreateNewWindowReplyPtr reply;
Balazs Engedya40712f2017-09-15 15:01:111302 auto* frame_host = creator_frame->GetFrameHost();
Daniel Cheng8bb30c62017-10-23 20:40:471303 bool err = !frame_host->CreateNewWindow(std::move(params), &status, &reply);
1304 if (err || status == mojom::CreateNewWindowStatus::kIgnore)
rockot5c478a72016-09-28 23:14:181305 return nullptr;
[email protected]48c9cf2d2009-09-16 16:47:521306
Jochen Eisinger515337a2017-05-26 14:12:521307 // For Android WebView, we support a pop-up like behavior for window.open()
1308 // even if the embedding app doesn't support multiple windows. In this case,
1309 // window.open() will return "window" and navigate it to whatever URL was
Jochen Eisinger8cb28492017-10-04 10:58:131310 // passed. We also don't need to consume user gestures to protect against
1311 // multiple windows being opened, because, well, the app doesn't support
1312 // multiple windows.
Daniel Cheng8bb30c62017-10-23 20:40:471313 // TODO(dcheng): It's awkward that this is plumbed into Blink but not really
1314 // used much in Blink, except to enable layout testing... perhaps this should
1315 // be checked directly in the browser side.
1316 if (status == mojom::CreateNewWindowStatus::kReuse)
Jochen Eisinger515337a2017-05-26 14:12:521317 return webview();
1318
Daniel Cheng8bb30c62017-10-23 20:40:471319 DCHECK(reply);
1320 DCHECK_NE(MSG_ROUTING_NONE, reply->route_id);
1321 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_route_id);
1322 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_widget_route_id);
1323
Mustaq Ahmede473e4352017-11-04 01:04:251324 WebUserGestureIndicator::ConsumeUserGesture(creator);
Jochen Eisinger8cb28492017-10-04 10:58:131325
[email protected]7912e822014-04-16 02:37:031326 // While this view may be a background extension page, it can spawn a visible
1327 // render view. So we just assume that the new one is not another background
1328 // page instead of passing on our own value.
1329 // TODO(vangelis): Can we tell if the new view will be a background page?
1330 bool never_visible = false;
[email protected]9115d5f2013-03-24 04:37:411331
fsamuel664e8b62016-01-20 19:54:011332 ResizeParams initial_size = ResizeParams();
mkosiba58fa72f02014-11-12 01:21:361333 initial_size.screen_info = screen_info_;
1334
[email protected]d6fa88f2013-10-18 16:00:431335 // The initial hidden state for the RenderViewImpl here has to match what the
1336 // browser will eventually decide for the given disposition. Since we have to
1337 // return from this call synchronously, we just have to make our best guess
1338 // and rely on the browser sending a WasHidden / WasShown message if it
1339 // disagrees.
Balazs Engedyba034e72017-10-27 22:26:281340 mojom::CreateViewParamsPtr view_params = mojom::CreateViewParams::New();
alexmos5ac402d2015-07-09 07:51:101341
Balazs Engedyba034e72017-10-27 22:26:281342 view_params->opener_frame_route_id = creator_frame->GetRoutingID();
avia3dca182016-03-19 01:09:521343 DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID());
alexmos5ac402d2015-07-09 07:51:101344
Balazs Engedyba034e72017-10-27 22:26:281345 view_params->window_was_created_with_opener = true;
1346 view_params->renderer_preferences = renderer_preferences_;
1347 view_params->web_preferences = webkit_preferences_;
1348 view_params->view_id = reply->route_id;
1349 view_params->main_frame_routing_id = reply->main_frame_route_id;
1350 view_params->main_frame_interface_provider =
1351 std::move(reply->main_frame_interface_provider);
1352 view_params->main_frame_widget_routing_id = reply->main_frame_widget_route_id;
1353 view_params->session_storage_namespace_id =
rockot5c478a72016-09-28 23:14:181354 reply->cloned_session_storage_namespace_id;
Balazs Engedyba034e72017-10-27 22:26:281355 view_params->swapped_out = false;
1356 view_params->replicated_frame_state.frame_policy.sandbox_flags =
1357 sandbox_flags;
1358 view_params->replicated_frame_state.name = frame_name_utf8;
1359 view_params->devtools_main_frame_token = reply->devtools_main_frame_token;
Daniel Chengd5e56ff2017-06-24 07:44:021360 // Even if the main frame has a name, the main frame's unique name is always
1361 // the empty string.
Balazs Engedyba034e72017-10-27 22:26:281362 view_params->hidden = is_background_tab;
1363 view_params->never_visible = never_visible;
1364 view_params->initial_size = initial_size;
1365 view_params->enable_auto_resize = false;
1366 view_params->min_size = gfx::Size();
1367 view_params->max_size = gfx::Size();
1368 view_params->page_zoom_level = page_zoom_level_;
naskobd911332014-11-25 01:13:361369
nick5ae4d2d2017-01-06 01:18:351370 // Unretained() is safe here because our calling function will also call
1371 // show().
nickf7b38222016-11-22 21:59:351372 RenderWidget::ShowCallback show_callback =
nick5ae4d2d2017-01-06 01:18:351373 base::Bind(&RenderFrameImpl::ShowCreatedWindow,
1374 base::Unretained(creator_frame), opened_by_user_gesture);
nickf7b38222016-11-22 21:59:351375
Balazs Engedyba034e72017-10-27 22:26:281376 RenderViewImpl* view = RenderViewImpl::Create(
Hajime Hoshiabb3c8f2017-12-04 18:41:391377 compositor_deps_, std::move(view_params), show_callback,
1378 creator->GetTaskRunner(blink::TaskType::kUnthrottled));
[email protected]48c9cf2d2009-09-16 16:47:521379
[email protected]48c9cf2d2009-09-16 16:47:521380 return view->webview();
1381}
1382
Hajime Hoshiabb3c8f2017-12-04 18:41:391383WebWidget* RenderViewImpl::CreatePopup(blink::WebLocalFrame* creator,
1384 blink::WebPopupType popup_type) {
1385 RenderWidget* widget = RenderWidget::CreateForPopup(
1386 this, compositor_deps_, popup_type, screen_info_,
1387 creator->GetTaskRunner(blink::TaskType::kUnthrottled));
[email protected]3b78ec12014-03-04 05:18:281388 if (!widget)
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281389 return nullptr;
[email protected]b2e4c70132013-10-03 02:07:511390 if (screen_metrics_emulator_) {
1391 widget->SetPopupOriginAdjustmentsForEmulation(
1392 screen_metrics_emulator_.get());
1393 }
lfg8ff33912016-09-13 20:59:211394 return widget->GetWebWidget();
[email protected]48c9cf2d2009-09-16 16:47:521395}
1396
Daniel Murphy31bbb8b12018-02-07 21:44:101397base::StringPiece RenderViewImpl::GetSessionStorageNamespaceId() {
1398 CHECK(!session_storage_namespace_id_.empty());
Daniel Murphy0ce6e2c2017-11-21 01:54:261399 return session_storage_namespace_id_;
[email protected]bd92c3a2010-01-13 05:02:341400}
1401
Blink Reformat1c4d759e2017-04-09 16:34:541402void RenderViewImpl::PrintPage(WebLocalFrame* frame) {
naskoe440d8c2016-10-12 23:07:561403 UMA_HISTOGRAM_BOOLEAN("PrintPreview.InitiatedByScript",
Blink Reformat1c4d759e2017-04-09 16:34:541404 frame->Top() == frame);
naskoe440d8c2016-10-12 23:07:561405
1406 // Logging whether the top frame is remote is sufficient in this case. If
1407 // the top frame is local, the printing code will function correctly and
1408 // the frame itself will be printed, so the cases this histogram tracks is
1409 // where printing of a subframe will fail as of now.
1410 UMA_HISTOGRAM_BOOLEAN("PrintPreview.OutOfProcessSubframe",
Blink Reformat1c4d759e2017-04-09 16:34:541411 frame->Top()->IsWebRemoteFrame());
naskoe440d8c2016-10-12 23:07:561412
thestigcb959ce2016-11-17 05:56:321413 RenderFrameImpl::FromWebFrame(frame)->ScriptedPrint(
1414 input_handler().handling_input_event());
[email protected]48c9cf2d2009-09-16 16:47:521415}
1416
Blink Reformat1c4d759e2017-04-09 16:34:541417bool RenderViewImpl::EnumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121418 const WebString& path,
1419 WebFileChooserCompletion* chooser_completion) {
1420 int id = enumeration_completion_id_++;
1421 enumeration_completions_[id] = chooser_completion;
1422 return Send(new ViewHostMsg_EnumerateDirectory(
avia3dca182016-03-19 01:09:521423 GetRoutingID(), id, blink::WebStringToFilePath(path)));
[email protected]8a58c1c2011-04-19 18:40:121424}
1425
[email protected]7e9523b2014-03-25 03:02:421426void RenderViewImpl::FrameDidStartLoading(WebFrame* frame) {
[email protected]7e9523b2014-03-25 03:02:421427 DCHECK_GE(frames_in_progress_, 0);
ericwilligers88e69742016-10-17 19:29:551428 if (frames_in_progress_ == 0) {
1429 for (auto& observer : observers_)
1430 observer.DidStartLoading();
1431 }
[email protected]7e9523b2014-03-25 03:02:421432 frames_in_progress_++;
[email protected]6dd5c322014-03-12 07:58:461433}
1434
[email protected]7e9523b2014-03-25 03:02:421435void RenderViewImpl::FrameDidStopLoading(WebFrame* frame) {
[email protected]eb473772014-04-11 20:54:331436 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
1437 // calls DidStopLoading() without a matching DidStartLoading().
1438 if (frames_in_progress_ == 0)
1439 return;
[email protected]7e9523b2014-03-25 03:02:421440 frames_in_progress_--;
[email protected]7e9523b2014-03-25 03:02:421441 if (frames_in_progress_ == 0) {
ericwilligers88e69742016-10-17 19:29:551442 for (auto& observer : observers_)
1443 observer.DidStopLoading();
[email protected]7e9523b2014-03-25 03:02:421444 }
[email protected]48c9cf2d2009-09-16 16:47:521445}
1446
lfgcaab5142016-02-26 19:06:521447void RenderViewImpl::AttachWebFrameWidget(blink::WebFrameWidget* frame_widget) {
dcheng3ce04b62015-10-26 23:30:551448 // The previous WebFrameWidget must already be detached by CloseForFrame().
1449 DCHECK(!frame_widget_);
1450 frame_widget_ = frame_widget;
1451}
1452
tommycli8aad3ba2015-08-12 17:57:591453void RenderViewImpl::SetZoomLevel(double zoom_level) {
wjmaclean64951902016-04-29 20:59:121454 // If we change the zoom level for the view, make sure any subsequent subframe
1455 // loads reflect the current zoom level.
1456 page_zoom_level_ = zoom_level;
1457
Blink Reformat1c4d759e2017-04-09 16:34:541458 webview()->SetZoomLevel(zoom_level);
ericwilligers88e69742016-10-17 19:29:551459 for (auto& observer : observers_)
1460 observer.OnZoomLevelChanged();
tommycli8aad3ba2015-08-12 17:57:591461}
1462
habib.virji597255e2014-09-09 00:30:181463void RenderViewImpl::SetValidationMessageDirection(
1464 base::string16* wrapped_main_text,
1465 blink::WebTextDirection main_text_hint,
1466 base::string16* wrapped_sub_text,
1467 blink::WebTextDirection sub_text_hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541468 if (main_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181469 *wrapped_main_text =
1470 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
Blink Reformat1c4d759e2017-04-09 16:34:541471 } else if (main_text_hint == blink::kWebTextDirectionRightToLeft &&
habib.virji597255e2014-09-09 00:30:181472 !base::i18n::IsRTL()) {
1473 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
1474 }
1475
1476 if (!wrapped_sub_text->empty()) {
Blink Reformat1c4d759e2017-04-09 16:34:541477 if (sub_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181478 *wrapped_sub_text =
1479 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
Blink Reformat1c4d759e2017-04-09 16:34:541480 } else if (sub_text_hint == blink::kWebTextDirectionRightToLeft) {
habib.virji597255e2014-09-09 00:30:181481 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
1482 }
1483 }
1484}
1485
[email protected]310ebd6302011-10-10 19:06:281486void RenderViewImpl::UpdateTargetURL(const GURL& url,
1487 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581488 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521489 if (latest_url == target_url_)
1490 return;
[email protected]163f8242009-10-30 20:19:551491
[email protected]48c9cf2d2009-09-16 16:47:521492 // Tell the browser to display a destination link.
1493 if (target_url_status_ == TARGET_INFLIGHT ||
1494 target_url_status_ == TARGET_PENDING) {
1495 // If we have a request in-flight, save the URL to be sent when we
1496 // receive an ACK to the in-flight request. We can happily overwrite
1497 // any existing pending sends.
1498 pending_target_url_ = latest_url;
1499 target_url_status_ = TARGET_PENDING;
1500 } else {
mnaganovbf087422015-12-16 05:10:031501 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411502 // see |ParamTraits<GURL>|.
markdittmer67b71ea2016-03-03 22:40:031503 if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:411504 latest_url = GURL();
avia3dca182016-03-19 01:09:521505 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), latest_url));
[email protected]48c9cf2d2009-09-16 16:47:521506 target_url_ = latest_url;
1507 target_url_status_ = TARGET_INFLIGHT;
1508 }
1509}
1510
creis69b184a472015-11-26 05:29:511511void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) {
creisce0ef3572017-01-26 17:53:081512 // Keep track of which frames have pending updates.
1513 frames_with_pending_state_.insert(frame->GetRoutingID());
creis8eb8ef22015-11-04 22:51:381514
[email protected]882daa92009-11-05 16:31:311515 int delay;
avif937e1d2014-11-02 18:13:071516 if (send_content_state_immediately_)
[email protected]882daa92009-11-05 16:31:311517 delay = 0;
1518 else if (is_hidden())
avif937e1d2014-11-02 18:13:071519 delay = kDelaySecondsForContentStateSyncHidden;
[email protected]882daa92009-11-05 16:31:311520 else
avif937e1d2014-11-02 18:13:071521 delay = kDelaySecondsForContentStateSync;
[email protected]882daa92009-11-05 16:31:311522
avif937e1d2014-11-02 18:13:071523 if (nav_state_sync_timer_.IsRunning()) {
[email protected]882daa92009-11-05 16:31:311524 // The timer is already running. If the delay of the timer maches the amount
1525 // we want to delay by, then return. Otherwise stop the timer so that it
1526 // gets started with the right delay.
avif937e1d2014-11-02 18:13:071527 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
[email protected]882daa92009-11-05 16:31:311528 return;
avif937e1d2014-11-02 18:13:071529 nav_state_sync_timer_.Stop();
[email protected]882daa92009-11-05 16:31:311530 }
1531
creisce0ef3572017-01-26 17:53:081532 // Tell each frame with pending state to inform the browser.
1533 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
1534 &RenderViewImpl::SendFrameStateUpdates);
[email protected]882daa92009-11-05 16:31:311535}
1536
Blink Reformat1c4d759e2017-04-09 16:34:541537void RenderViewImpl::SetMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551538 mouse_over_url_ = GURL(url);
1539 UpdateTargetURL(mouse_over_url_, focus_url_);
1540}
1541
Blink Reformat1c4d759e2017-04-09 16:34:541542void RenderViewImpl::SetKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551543 focus_url_ = GURL(url);
1544 UpdateTargetURL(focus_url_, mouse_over_url_);
1545}
1546
Blink Reformat1c4d759e2017-04-09 16:34:541547bool RenderViewImpl::AcceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451548 return renderer_preferences_.can_accept_load_drops;
1549}
1550
Blink Reformat1c4d759e2017-04-09 16:34:541551void RenderViewImpl::FocusNext() {
avia3dca182016-03-19 01:09:521552 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false));
[email protected]48c9cf2d2009-09-16 16:47:521553}
1554
Blink Reformat1c4d759e2017-04-09 16:34:541555void RenderViewImpl::FocusPrevious() {
avia3dca182016-03-19 01:09:521556 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true));
[email protected]48c9cf2d2009-09-16 16:47:521557}
1558
esprehn3d4471a2015-09-17 07:13:201559// TODO(esprehn): Blink only ever passes Elements, this should take WebElement.
Blink Reformat1c4d759e2017-04-09 16:34:541560void RenderViewImpl::FocusedNodeChanged(const WebNode& fromNode,
estade31c54342015-01-23 03:34:361561 const WebNode& toNode) {
estade31c54342015-01-23 03:34:361562 RenderFrameImpl* previous_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541563 if (!fromNode.IsNull())
1564 previous_frame =
1565 RenderFrameImpl::FromWebFrame(fromNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361566 RenderFrameImpl* new_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541567 if (!toNode.IsNull())
1568 new_frame = RenderFrameImpl::FromWebFrame(toNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361569
1570 if (previous_frame && previous_frame != new_frame)
1571 previous_frame->FocusedNodeChanged(WebNode());
1572 if (new_frame)
1573 new_frame->FocusedNodeChanged(toNode);
1574
1575 // TODO(dmazzoni): remove once there's a separate a11y tree per frame.
naskoe8d115752015-08-07 00:43:131576 if (main_render_frame_)
1577 main_render_frame_->FocusedNodeChangedForAccessibility(toNode);
[email protected]08e9e132010-06-01 16:58:491578}
1579
Blink Reformat1c4d759e2017-04-09 16:34:541580void RenderViewImpl::DidUpdateLayout() {
ericwilligers88e69742016-10-17 19:29:551581 for (auto& observer : observers_)
1582 observer.DidUpdateLayout();
[email protected]d01b2a62013-09-18 23:21:331583
[email protected]169d4282011-11-30 19:33:591584 // We don't always want to set up a timer, only if we've been put in that
1585 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1586 // message.
1587 if (!send_preferred_size_changes_ || !webview())
1588 return;
1589
1590 if (check_preferred_size_timer_.IsRunning())
1591 return;
1592 check_preferred_size_timer_.Start(FROM_HERE,
1593 TimeDelta::FromMilliseconds(0), this,
1594 &RenderViewImpl::CheckPreferredSize);
1595}
1596
Blink Reformat1c4d759e2017-04-09 16:34:541597void RenderViewImpl::NavigateBackForwardSoon(int offset) {
Alex Clarkebf3dceb2017-11-24 12:27:431598 history_navigation_virtual_time_pauser_ =
1599 RenderThreadImpl::current()
1600 ->GetRendererScheduler()
Alex Clarkeb28db542018-02-07 12:53:131601 ->CreateWebScopedVirtualTimePauser(
1602 blink::WebScopedVirtualTimePauser::VirtualTaskDuration::kInstant);
Alex Clarkebf3dceb2017-11-24 12:27:431603 history_navigation_virtual_time_pauser_.PauseVirtualTime(true);
avia3dca182016-03-19 01:09:521604 Send(new ViewHostMsg_GoToEntryAtOffset(GetRoutingID(), offset));
[email protected]48c9cf2d2009-09-16 16:47:521605}
1606
Alex Clarkebf3dceb2017-11-24 12:27:431607void RenderViewImpl::DidCommitProvisionalHistoryLoad() {
1608 history_navigation_virtual_time_pauser_.PauseVirtualTime(false);
1609}
1610
Blink Reformat1c4d759e2017-04-09 16:34:541611int RenderViewImpl::HistoryBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001612 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521613}
1614
Blink Reformat1c4d759e2017-04-09 16:34:541615int RenderViewImpl::HistoryForwardListCount() {
1616 return history_list_length_ - HistoryBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521617}
1618
[email protected]180ef242013-11-07 06:50:461619// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:511620
Avi Drissman36f801f2018-02-01 20:06:041621void RenderViewImpl::DidFocus(blink::WebLocalFrame* calling_frame) {
[email protected]ea42e7782010-08-23 23:58:121622 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1623 // we won't have to test for user gesture anymore and we can
1624 // move that code back to render_widget.cc
Mustaq Ahmede473e4352017-11-04 01:04:251625 WebFrame* main_frame = webview() ? webview()->MainFrame() : nullptr;
1626 bool is_processing_user_gesture =
1627 WebUserGestureIndicator::IsProcessingUserGesture(
1628 main_frame && main_frame->IsWebLocalFrame()
1629 ? main_frame->ToWebLocalFrame()
1630 : nullptr);
1631 if (is_processing_user_gesture &&
[email protected]70dee7e2013-05-29 18:28:301632 !RenderThreadImpl::current()->layout_test_mode()) {
avia3dca182016-03-19 01:09:521633 Send(new ViewHostMsg_Focus(GetRoutingID()));
Avi Drissman36f801f2018-02-01 20:06:041634
1635 // Tattle on the frame that called |window.focus()|.
1636 RenderFrameImpl* calling_render_frame =
1637 RenderFrameImpl::FromWebFrame(calling_frame);
1638 if (calling_render_frame)
1639 calling_render_frame->FrameDidCallFocus();
[email protected]ea42e7782010-08-23 23:58:121640 }
1641}
1642
nickf7b38222016-11-22 21:59:351643// We are supposed to get a single call to show() for a newly created RenderView
1644// that was created via RenderViewImpl::createView. We wait until this point to
1645// run |show_callback|, which is bound to our opener's ShowCreatedViewWidget()
1646// method.
initial.commit09911bf2008-07-26 23:55:291647//
1648// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281649// created RenderView (i.e., as a blocked popup or as a new tab).
Blink Reformat1c4d759e2017-04-09 16:34:541650void RenderViewImpl::Show(WebNavigationPolicy policy) {
nickf7b38222016-11-22 21:59:351651 if (did_show_ && !webkit_preferences_.supports_multiple_windows) {
[email protected]b2142e962012-10-30 13:59:251652 // When supports_multiple_windows is disabled, popups are reusing
1653 // the same view. In some scenarios, this makes WebKit to call show() twice.
initial.commit09911bf2008-07-26 23:55:291654 return;
[email protected]b2142e962012-10-30 13:59:251655 }
initial.commit09911bf2008-07-26 23:55:291656
Blink Reformat1c4d759e2017-04-09 16:34:541657 RenderWidget::Show(policy);
initial.commit09911bf2008-07-26 23:55:291658}
1659
miletuse8d28ba2015-06-19 04:52:041660
Blink Reformat1c4d759e2017-04-09 16:34:541661bool RenderViewImpl::CanHandleGestureEvent() {
slangley1a6375e62017-03-29 06:03:231662 return true;
1663}
1664
Blink Reformat1c4d759e2017-04-09 16:34:541665bool RenderViewImpl::CanUpdateLayout() {
slangley1a6375e62017-03-29 06:03:231666 return true;
1667}
1668
Blink Reformat1c4d759e2017-04-09 16:34:541669void RenderViewImpl::DidHandleGestureEvent(const WebGestureEvent& event,
1670 bool event_cancelled) {
1671 RenderWidget::DidHandleGestureEvent(event, event_cancelled);
[email protected]bb37b652013-11-27 23:47:111672
[email protected]91dcc6d32014-07-30 00:01:331673 if (!event_cancelled) {
ericwilligers88e69742016-10-17 19:29:551674 for (auto& observer : observers_)
1675 observer.DidHandleGestureEvent(event);
[email protected]91dcc6d32014-07-30 00:01:331676 }
[email protected]c68c3e4e2013-01-24 00:36:561677}
1678
Blink Reformat1c4d759e2017-04-09 16:34:541679blink::WebLayerTreeView* RenderViewImpl::InitializeLayerTreeView() {
wjmaclean1d970622017-01-21 22:28:241680 // TODO(!wjmaclean): We should be able to just remove this function, and
1681 // expect the RenderWidget version of the function to be called instead.
1682 // However, we have a diamond inheritance pattern going on:
1683 // WebWidgetClient
1684 // | |
1685 // RenderWidget WebViewClient
1686 // | |
1687 // RenderViewImpl
1688 //
1689 // and this seems to prefer calling the empty version in WebWidgetClient
1690 // or WebViewClient over the non-empty one in RenderWidget.
Blink Reformat1c4d759e2017-04-09 16:34:541691 return RenderWidget::InitializeLayerTreeView();
[email protected]6e89eb72013-07-23 13:28:221692}
1693
Blink Reformat1c4d759e2017-04-09 16:34:541694void RenderViewImpl::CloseWidgetSoon() {
1695 RenderWidget::CloseWidgetSoon();
lfg2230bce2016-04-28 18:37:041696}
1697
Blink Reformat1c4d759e2017-04-09 16:34:541698void RenderViewImpl::ConvertViewportToWindow(blink::WebRect* rect) {
1699 RenderWidget::ConvertViewportToWindow(rect);
lfg2230bce2016-04-28 18:37:041700}
1701
Blink Reformat1c4d759e2017-04-09 16:34:541702void RenderViewImpl::ConvertWindowToViewport(blink::WebFloatRect* rect) {
1703 RenderWidget::ConvertWindowToViewport(rect);
lfg2230bce2016-04-28 18:37:041704}
1705
Blink Reformat1c4d759e2017-04-09 16:34:541706void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) {
lfgb00fcad2016-07-14 14:16:331707 RenderWidget::DidAutoResize(newSize);
lfg2230bce2016-04-28 18:37:041708}
1709
Blink Reformat1c4d759e2017-04-09 16:34:541710void RenderViewImpl::DidOverscroll(
lfg2230bce2016-04-28 18:37:041711 const blink::WebFloatSize& overscrollDelta,
1712 const blink::WebFloatSize& accumulatedOverscroll,
1713 const blink::WebFloatPoint& positionInViewport,
sunyunjiabbea8a92017-08-31 11:18:541714 const blink::WebFloatSize& velocityInViewport,
Sandra Sun2288e8532017-11-30 22:50:161715 const blink::WebOverscrollBehavior& behavior) {
Blink Reformat1c4d759e2017-04-09 16:34:541716 RenderWidget::DidOverscroll(overscrollDelta, accumulatedOverscroll,
sunyunjiabbea8a92017-08-31 11:18:541717 positionInViewport, velocityInViewport, behavior);
lfg2230bce2016-04-28 18:37:041718}
1719
Blink Reformat1c4d759e2017-04-09 16:34:541720void RenderViewImpl::HasTouchEventHandlers(bool has_handlers) {
1721 RenderWidget::HasTouchEventHandlers(has_handlers);
lfg2230bce2016-04-28 18:37:041722}
1723
Blink Reformat1c4d759e2017-04-09 16:34:541724blink::WebRect RenderViewImpl::RootWindowRect() {
1725 return RenderWidget::WindowRect();
lfg2230bce2016-04-28 18:37:041726}
1727
Blink Reformat1c4d759e2017-04-09 16:34:541728blink::WebScreenInfo RenderViewImpl::GetScreenInfo() {
1729 return RenderWidget::GetScreenInfo();
lfg2230bce2016-04-28 18:37:041730}
1731
Blink Reformat1c4d759e2017-04-09 16:34:541732void RenderViewImpl::SetToolTipText(const blink::WebString& text,
lfg2230bce2016-04-28 18:37:041733 blink::WebTextDirection hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541734 RenderWidget::SetToolTipText(text, hint);
lfg2230bce2016-04-28 18:37:041735}
1736
Blink Reformat1c4d759e2017-04-09 16:34:541737void RenderViewImpl::SetTouchAction(blink::WebTouchAction touchAction) {
1738 RenderWidget::SetTouchAction(touchAction);
lfg2230bce2016-04-28 18:37:041739}
1740
Donn Denman3c1267c62018-03-08 22:08:591741void RenderViewImpl::ShowUnhandledTapUIIfNeeded(
1742 const blink::WebTappedInfo& tappedInfo) {
1743 RenderWidget::ShowUnhandledTapUIIfNeeded(tappedInfo);
1744}
1745
Blink Reformat1c4d759e2017-04-09 16:34:541746blink::WebWidgetClient* RenderViewImpl::WidgetClient() {
lfg0f440622016-07-20 04:27:141747 return static_cast<RenderWidget*>(this);
1748}
1749
[email protected]180ef242013-11-07 06:50:461750// blink::WebFrameClient -----------------------------------------------------
[email protected]3d9689372009-09-10 04:29:171751
[email protected]5e92282f2012-08-17 08:11:571752void RenderViewImpl::Repaint(const gfx::Size& size) {
[email protected]3d9ec5052013-01-02 22:05:251753 OnRepaint(size);
[email protected]5e92282f2012-08-17 08:11:571754}
1755
[email protected]b2324b092012-11-01 10:34:111756void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
1757 const std::string& value) {
alexmos56567492016-09-13 00:52:461758 GetWidget()->SetEditCommandForNextKeyEvent(name, value);
[email protected]b2324b092012-11-01 10:34:111759}
1760
1761void RenderViewImpl::ClearEditCommands() {
alexmos56567492016-09-13 00:52:461762 GetWidget()->ClearEditCommands();
[email protected]b2324b092012-11-01 10:34:111763}
1764
[email protected]b38806a2013-10-04 16:01:381765const std::string& RenderViewImpl::GetAcceptLanguages() const {
1766 return renderer_preferences_.accept_languages;
1767}
1768
danakjdea2efb2016-03-10 19:13:171769void RenderViewImpl::ConvertViewportToWindowViaWidget(blink::WebRect* rect) {
Blink Reformat1c4d759e2017-04-09 16:34:541770 ConvertViewportToWindow(rect);
oshimae2b3b402015-12-04 04:27:241771}
1772
huangs2a342352015-12-15 16:59:241773gfx::RectF RenderViewImpl::ElementBoundsInWindow(
1774 const blink::WebElement& element) {
Blink Reformat1c4d759e2017-04-09 16:34:541775 blink::WebRect bounding_box_in_window = element.BoundsInViewport();
danakjdea2efb2016-03-10 19:13:171776 ConvertViewportToWindowViaWidget(&bounding_box_in_window);
huangs2a342352015-12-15 16:59:241777 return gfx::RectF(bounding_box_in_window);
1778}
1779
changwand659e202016-06-13 02:39:121780bool RenderViewImpl::HasAddedInputHandler() const {
1781 return has_added_input_handler_;
1782}
1783
[email protected]310ebd6302011-10-10 19:06:281784void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:071785 // We don't always want to send the change messages over IPC, only if we've
1786 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1787 // message.
1788 if (!send_preferred_size_changes_ || !webview())
1789 return;
oshima1a688b5c2017-06-16 19:00:131790 blink::WebSize tmp_size = webview()->ContentsPreferredMinimumSize();
1791 blink::WebRect tmp_rect(0, 0, tmp_size.width, tmp_size.height);
1792 ConvertViewportToWindow(&tmp_rect);
1793 gfx::Size size(tmp_rect.width, tmp_rect.height);
[email protected]705243f2010-05-05 19:58:071794 if (size == preferred_size_)
1795 return;
[email protected]c27324b2009-11-19 22:44:291796
[email protected]705243f2010-05-05 19:58:071797 preferred_size_ = size;
avia3dca182016-03-19 01:09:521798 Send(new ViewHostMsg_DidContentsPreferredSizeChange(GetRoutingID(),
[email protected]705243f2010-05-05 19:58:071799 preferred_size_));
[email protected]3d9689372009-09-10 04:29:171800}
1801
Blink Reformat1c4d759e2017-04-09 16:34:541802blink::WebString RenderViewImpl::AcceptLanguages() {
1803 return WebString::FromUTF8(renderer_preferences_.accept_languages);
[email protected]9982c802013-06-12 15:22:061804}
1805
[email protected]e9ff79c2012-10-19 21:31:261806// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:311807
[email protected]310ebd6302011-10-10 19:06:281808bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:311809 return RenderWidget::Send(message);
1810}
1811
Peter Kastinga4a3ed12018-01-31 04:07:591812RenderWidget* RenderViewImpl::GetWidget() {
1813 return this;
avi8a45c1092016-03-01 16:12:341814}
1815
mostynbc33353232014-09-12 09:38:311816RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() {
nasko77de2312015-05-12 03:09:161817 return main_render_frame_;
[email protected]b849847b2013-12-10 21:57:581818}
1819
[email protected]82114f52012-03-20 22:53:411820int RenderViewImpl::GetRoutingID() const {
fsamuele8326c742016-01-12 00:49:391821 return routing_id();
[email protected]a2ef54c2011-10-10 16:20:311822}
1823
[email protected]82114f52012-03-20 22:53:411824gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:311825 return size();
1826}
1827
oshima129b75e2016-01-14 09:15:141828float RenderViewImpl::GetDeviceScaleFactor() const {
Fady Samuela863f152018-03-09 16:10:031829 return GetWebScreenInfo().device_scale_factor;
oshima129b75e2016-01-14 09:15:141830}
1831
Marc Treib06d66032017-10-19 08:43:201832float RenderViewImpl::GetZoomLevel() const {
1833 return page_zoom_level_;
1834}
1835
thestig8a8fdfd32017-05-06 18:46:541836const WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:311837 return webkit_preferences_;
1838}
1839
[email protected]324825d2012-11-30 12:37:151840void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
1841 OnUpdateWebPreferences(preferences);
1842}
1843
[email protected]180ef242013-11-07 06:50:461844blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:311845 return webview();
1846}
1847
lfgcaab5142016-02-26 19:06:521848blink::WebFrameWidget* RenderViewImpl::GetWebFrameWidget() {
1849 return frame_widget_;
1850}
1851
[email protected]310ebd6302011-10-10 19:06:281852bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:311853 return (!send_preferred_size_changes_ ||
1854 (disable_scrollbars_size_limit_.width() <= width ||
1855 disable_scrollbars_size_limit_.height() <= height));
1856}
1857
avif937e1d2014-11-02 18:13:071858bool RenderViewImpl::GetContentStateImmediately() const {
1859 return send_content_state_immediately_;
[email protected]a2ef54c2011-10-10 16:20:311860}
1861
mcnee432e47d2015-11-09 19:37:461862void RenderViewImpl::OnSetPageScale(float page_scale_factor) {
ccameronb7c1d6c2015-03-09 17:08:241863 if (!webview())
1864 return;
Blink Reformat1c4d759e2017-04-09 16:34:541865 webview()->SetPageScaleFactor(page_scale_factor);
ccameronb7c1d6c2015-03-09 17:08:241866}
1867
wjmaclean64951902016-04-29 20:59:121868void RenderViewImpl::OnSetZoomLevel(
1869 PageMsg_SetZoomLevel_Command command,
1870 double zoom_level) {
1871 switch (command) {
1872 case PageMsg_SetZoomLevel_Command::CLEAR_TEMPORARY:
1873 uses_temporary_zoom_level_ = false;
1874 break;
1875 case PageMsg_SetZoomLevel_Command::SET_TEMPORARY:
1876 uses_temporary_zoom_level_ = true;
1877 break;
1878 case PageMsg_SetZoomLevel_Command::USE_CURRENT_TEMPORARY_MODE:
1879 // Don't override a temporary zoom level without an explicit SET.
1880 if (uses_temporary_zoom_level_)
1881 return;
1882 break;
1883 default:
1884 NOTIMPLEMENTED();
1885 }
Blink Reformat1c4d759e2017-04-09 16:34:541886 webview()->HidePopups();
wjmaclean64951902016-04-29 20:59:121887 SetZoomLevel(zoom_level);
[email protected]d42bf472014-06-14 01:49:381888}
1889
[email protected]310ebd6302011-10-10 19:06:281890void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:591891 webkit_preferences_ = prefs;
sataya.mf405d0e2015-07-07 16:51:111892 ApplyWebPreferencesInternal(webkit_preferences_, webview(), compositor_deps_);
initial.commit09911bf2008-07-26 23:55:291893}
1894
[email protected]310ebd6302011-10-10 19:06:281895void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:511896 int id,
[email protected]c42de732013-02-16 06:26:311897 const std::vector<base::FilePath>& paths) {
[email protected]600ea402011-04-12 00:01:511898 if (!enumeration_completions_[id])
1899 return;
1900
1901 WebVector<WebString> ws_file_names(paths.size());
1902 for (size_t i = 0; i < paths.size(); ++i)
kinukoa4293022017-01-27 06:43:251903 ws_file_names[i] = blink::FilePathToWebString(paths[i]);
[email protected]600ea402011-04-12 00:01:511904
Blink Reformat1c4d759e2017-04-09 16:34:541905 enumeration_completions_[id]->DidChooseFile(ws_file_names);
[email protected]600ea402011-04-12 00:01:511906 enumeration_completions_.erase(id);
1907}
1908
[email protected]244ac1892011-12-02 17:04:471909void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
1910 const gfx::Size& max_size) {
1911 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
1912 if (!webview())
1913 return;
oshima33ec97cd2015-12-14 19:40:241914
[email protected]97e1bf72013-03-06 14:06:051915 auto_resize_mode_ = true;
Fady Samuel319e429c2017-10-02 18:31:551916
oshima33ec97cd2015-12-14 19:40:241917 if (IsUseZoomForDSFEnabled()) {
Blink Reformat1c4d759e2017-04-09 16:34:541918 webview()->EnableAutoResizeMode(
Fady Samuela863f152018-03-09 16:10:031919 gfx::ScaleToCeiledSize(min_size,
1920 GetWebScreenInfo().device_scale_factor),
1921 gfx::ScaleToCeiledSize(max_size,
1922 GetWebScreenInfo().device_scale_factor));
oshima33ec97cd2015-12-14 19:40:241923 } else {
Blink Reformat1c4d759e2017-04-09 16:34:541924 webview()->EnableAutoResizeMode(min_size, max_size);
oshima33ec97cd2015-12-14 19:40:241925 }
[email protected]61e2b3cc2012-03-02 16:13:341926}
1927
1928void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
1929 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
1930 if (!webview())
1931 return;
[email protected]97e1bf72013-03-06 14:06:051932 auto_resize_mode_ = false;
Fady Samuel1ee6fb5c2018-02-16 03:27:461933 auto_resize_ack_callback_.Cancel();
1934 need_resize_ack_for_auto_resize_ = false;
Blink Reformat1c4d759e2017-04-09 16:34:541935 webview()->DisableAutoResizeMode();
[email protected]61e2b3cc2012-03-02 16:13:341936
[email protected]eac2b362013-05-22 07:01:451937 if (!new_size.IsEmpty()) {
mfomitchev2600fd7c2016-02-17 20:53:391938 ResizeParams resize_params;
jbroman5ff10302016-07-22 03:36:261939 resize_params.screen_info = screen_info_;
mfomitchev2600fd7c2016-02-17 20:53:391940 resize_params.new_size = new_size;
Christopher Cameronaad15a0d2018-03-09 03:47:331941 resize_params.compositor_viewport_pixel_size =
1942 compositor_viewport_pixel_size_;
mdjones2ee41afd2016-10-27 16:50:201943 resize_params.browser_controls_shrink_blink_size =
1944 browser_controls_shrink_blink_size_;
mfomitchev2600fd7c2016-02-17 20:53:391945 resize_params.top_controls_height = top_controls_height_;
1946 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:391947 resize_params.is_fullscreen_granted = is_fullscreen_granted();
1948 resize_params.display_mode = display_mode_;
1949 resize_params.needs_resize_ack = false;
1950 Resize(resize_params);
[email protected]eac2b362013-05-22 07:01:451951 }
[email protected]244ac1892011-12-02 17:04:471952}
1953
Fady Samuel69b33b52017-11-08 22:01:521954void RenderViewImpl::OnSetLocalSurfaceIdForAutoResize(
1955 uint64_t sequence_number,
1956 const gfx::Size& min_size,
1957 const gfx::Size& max_size,
1958 const content::ScreenInfo& screen_info,
Saman Samif7731342018-01-24 22:18:441959 uint32_t content_source_id,
Fady Samuel69b33b52017-11-08 22:01:521960 const viz::LocalSurfaceId& local_surface_id) {
Fady Samuel1ee6fb5c2018-02-16 03:27:461961 if (!auto_resize_mode_ || resize_or_repaint_ack_num_ != sequence_number) {
1962 DidResizeOrRepaintAck();
Fady Samuel69b33b52017-11-08 22:01:521963 return;
Fady Samuel1ee6fb5c2018-02-16 03:27:461964 }
Fady Samuel69b33b52017-11-08 22:01:521965
1966 SetLocalSurfaceIdForAutoResize(sequence_number, screen_info,
Saman Samif7731342018-01-24 22:18:441967 content_source_id, local_surface_id);
Fady Samuel69b33b52017-11-08 22:01:521968
1969 if (IsUseZoomForDSFEnabled()) {
1970 webview()->EnableAutoResizeMode(
Fady Samuela863f152018-03-09 16:10:031971 gfx::ScaleToCeiledSize(min_size,
1972 GetWebScreenInfo().device_scale_factor),
1973 gfx::ScaleToCeiledSize(max_size,
1974 GetWebScreenInfo().device_scale_factor));
Fady Samuel69b33b52017-11-08 22:01:521975 } else {
1976 webview()->EnableAutoResizeMode(min_size, max_size);
1977 }
1978}
1979
[email protected]2bf834f2011-11-17 20:02:211980void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:241981 if (send_preferred_size_changes_)
1982 return;
[email protected]9fb325e2010-05-06 18:23:241983 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:391984
[email protected]d812fd12011-05-27 23:05:071985 // Start off with an initial preferred size notification (in case
1986 // |didUpdateLayout| was already called).
Blink Reformat1c4d759e2017-04-09 16:34:541987 DidUpdateLayout();
[email protected]0666aef2009-05-13 19:48:081988}
1989
[email protected]310ebd6302011-10-10 19:06:281990void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:101991 const gfx::Size& disable_scrollbar_size_limit) {
1992 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
1993}
1994
[email protected]310ebd6302011-10-10 19:06:281995void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:261996 const RendererPreferences& renderer_prefs) {
[email protected]ebd5ea52014-05-28 14:51:151997 std::string old_accept_languages = renderer_preferences_.accept_languages;
1998
[email protected]80d96fa2009-06-10 22:34:511999 renderer_preferences_ = renderer_prefs;
ananta59b9fe72015-04-07 01:33:262000
[email protected]6e282c92009-07-24 01:19:372001 UpdateFontRenderingFromRendererPrefs();
scottmgb92365e2016-08-30 20:54:402002 UpdateThemePrefs();
Blink Reformat1c4d759e2017-04-09 16:34:542003 blink::SetCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]38a85712013-01-02 22:45:022004
brettw8a274fa2016-11-15 00:20:402005#if BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]1596efb2013-01-17 22:13:012006 if (renderer_prefs.use_custom_colors) {
Blink Reformat1c4d759e2017-04-09 16:34:542007 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
[email protected]1596efb2013-01-17 22:13:012008
2009 if (webview()) {
Blink Reformat1c4d759e2017-04-09 16:34:542010 webview()->SetSelectionColors(renderer_prefs.active_selection_bg_color,
2011 renderer_prefs.active_selection_fg_color,
2012 renderer_prefs.inactive_selection_bg_color,
2013 renderer_prefs.inactive_selection_fg_color);
2014 webview()->ThemeChanged();
[email protected]1596efb2013-01-17 22:13:012015 }
[email protected]644d77e2010-01-27 01:03:102016 }
brettw8a274fa2016-11-15 00:20:402017#endif // BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]d299d972012-03-23 02:26:552018
[email protected]ebd5ea52014-05-28 14:51:152019 if (webview() &&
2020 old_accept_languages != renderer_preferences_.accept_languages) {
Blink Reformat1c4d759e2017-04-09 16:34:542021 webview()->AcceptLanguagesChanged();
[email protected]ebd5ea52014-05-28 14:51:152022 }
[email protected]80d96fa2009-06-10 22:34:512023}
2024
[email protected]310ebd6302011-10-10 19:06:282025void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
2026 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:282027 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542028 webview()->PerformMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:562029}
2030
[email protected]81375e872012-01-11 21:40:362031void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
2032 const WebPluginAction& action) {
2033 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542034 webview()->PerformPluginAction(action, location);
[email protected]81375e872012-01-11 21:40:362035}
2036
[email protected]310ebd6302011-10-10 19:06:282037void RenderViewImpl::OnClosePage() {
lukasza5d0dee42017-06-14 21:57:372038 // ViewMsg_ClosePage should only be sent to active, non-swapped-out views.
2039 DCHECK(webview()->MainFrame()->IsWebLocalFrame());
2040
initial.commit09911bf2008-07-26 23:55:292041 // TODO(creis): We'd rather use webview()->Close() here, but that currently
2042 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
2043 // in the onunload handler from appearing. For now, we're bypassing that and
2044 // calling the FrameLoader's CloseURL method directly. This should be
2045 // revisited to avoid having two ways to close a page. Having a single way
2046 // to close that can run onunload is also useful for fixing
2047 // http://b/issue?id=753080.
lukasza5d0dee42017-06-14 21:57:372048 webview()->MainFrame()->ToWebLocalFrame()->DispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:292049
avia3dca182016-03-19 01:09:522050 Send(new ViewHostMsg_ClosePage_ACK(GetRoutingID()));
initial.commit09911bf2008-07-26 23:55:292051}
2052
naskoc288745f2015-05-01 22:54:212053void RenderViewImpl::OnClose() {
2054 if (closing_)
avia3dca182016-03-19 01:09:522055 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(GetRoutingID()));
naskoc288745f2015-05-01 22:54:212056 RenderWidget::OnClose();
2057}
2058
[email protected]310ebd6302011-10-10 19:06:282059void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:002060 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542061 webview()->HidePopups();
[email protected]30f75e62009-02-25 22:01:002062}
2063
bokanc63441c2016-04-27 15:49:122064void RenderViewImpl::ResizeWebWidget() {
Matthew Jones7e156182017-07-21 22:21:332065 webview()->ResizeWithBrowserControls(
2066 GetSizeForWebWidget(), top_controls_height_, bottom_controls_height_,
2067 browser_controls_shrink_blink_size_);
bokanc63441c2016-04-27 15:49:122068}
2069
fsamuel664e8b62016-01-20 19:54:012070void RenderViewImpl::OnResize(const ResizeParams& params) {
[email protected]189a8862014-07-18 00:27:532071 TRACE_EVENT0("renderer", "RenderViewImpl::OnResize");
Saman Samif7731342018-01-24 22:18:442072
[email protected]cda45c02010-02-25 19:28:102073 if (webview()) {
Darren Shen36f4d5442018-02-12 04:45:152074 // Only hide popups when the size changes. There are situations (e.g. hiding
2075 // the ChromeOS virtual keyboard) where we send a resize message with no
2076 // change in size, but we don't want to close popups.
2077 // See https://crbug.com/761908.
2078 if (params.new_size != GetSize())
2079 webview()->HidePopups();
2080
kenrb5fd60fb82016-06-10 17:27:572081 if (send_preferred_size_changes_ &&
Blink Reformat1c4d759e2017-04-09 16:34:542082 webview()->MainFrame()->IsWebLocalFrame()) {
lukasza302fcdd2017-06-02 20:40:352083 webview()->MainFrame()->ToWebLocalFrame()->SetCanHaveScrollbars(
2084 ShouldDisplayScrollbars(params.new_size.width(),
2085 params.new_size.height()));
[email protected]cda45c02010-02-25 19:28:102086 }
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122087 if (display_mode_ != params.display_mode) {
2088 display_mode_ = params.display_mode;
Blink Reformat1c4d759e2017-04-09 16:34:542089 webview()->SetDisplayMode(display_mode_);
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122090 }
[email protected]cda45c02010-02-25 19:28:102091 }
2092
mdjones2ee41afd2016-10-27 16:50:202093 browser_controls_shrink_blink_size_ =
2094 params.browser_controls_shrink_blink_size;
bokanc63441c2016-04-27 15:49:122095 top_controls_height_ = params.top_controls_height;
Matthew Jones7e156182017-07-21 22:21:332096 bottom_controls_height_ = params.bottom_controls_height;
bokanc63441c2016-04-27 15:49:122097
Saman Samif7731342018-01-24 22:18:442098 if (device_scale_factor_for_testing_) {
2099 ResizeParams p(params);
2100 p.screen_info.device_scale_factor = *device_scale_factor_for_testing_;
Christopher Cameronaad15a0d2018-03-09 03:47:332101 p.compositor_viewport_pixel_size =
Saman Samif7731342018-01-24 22:18:442102 gfx::ScaleToCeiledSize(p.new_size, p.screen_info.device_scale_factor);
2103 RenderWidget::OnResize(p);
2104 } else {
2105 RenderWidget::OnResize(params);
2106 }
Dave Tapuska73697492018-01-12 22:02:102107
2108 if (params.scroll_focused_node_into_view)
2109 webview()->ScrollFocusedEditableElementIntoView();
[email protected]30f75e62009-02-25 22:01:002110}
[email protected]0aa477bd2009-03-23 22:21:432111
[email protected]61f91832014-05-13 01:24:422112void RenderViewImpl::OnSetBackgroundOpaque(bool opaque) {
esecklerf2bd55f72017-03-31 09:11:572113 if (!frame_widget_)
2114 return;
2115
2116 if (opaque) {
Blink Reformat1c4d759e2017-04-09 16:34:542117 frame_widget_->ClearBaseBackgroundColorOverride();
2118 frame_widget_->ClearBackgroundColorOverride();
esecklerf2bd55f72017-03-31 09:11:572119 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542120 frame_widget_->SetBaseBackgroundColorOverride(SK_ColorTRANSPARENT);
2121 frame_widget_->SetBackgroundColorOverride(SK_ColorTRANSPARENT);
esecklerf2bd55f72017-03-31 09:11:572122 }
[email protected]699ab0d2009-04-23 23:19:142123}
2124
[email protected]310ebd6302011-10-10 19:06:282125void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:342126 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542127 webview()->SetIsActive(active);
[email protected]8c66c5a2009-07-22 17:26:342128}
2129
lfg8ff33912016-09-13 20:59:212130blink::WebWidget* RenderViewImpl::GetWebWidget() const {
2131 if (frame_widget_)
2132 return frame_widget_;
2133
2134 return RenderWidget::GetWebWidget();
2135}
2136
dcheng3ce04b62015-10-26 23:30:552137void RenderViewImpl::CloseForFrame() {
2138 DCHECK(frame_widget_);
Blink Reformat1c4d759e2017-04-09 16:34:542139 frame_widget_->Close();
dcheng3ce04b62015-10-26 23:30:552140 frame_widget_ = nullptr;
2141}
2142
[email protected]310ebd6302011-10-10 19:06:282143void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:592144 // We need to grab a pointer to the doomed WebView before we destroy it.
lfg4fa48da2016-05-09 18:25:132145 WebView* doomed = webview_;
[email protected]60c42a8c72009-10-09 04:08:592146 RenderWidget::Close();
lfg4fa48da2016-05-09 18:25:132147 webview_ = nullptr;
[email protected]625332e02010-12-14 07:48:492148 g_view_map.Get().erase(doomed);
avia3dca182016-03-19 01:09:522149 g_routing_id_view_map.Get().erase(GetRoutingID());
2150 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(GetRoutingID()));
[email protected]60c42a8c72009-10-09 04:08:592151}
2152
lfg717154072016-06-30 15:04:162153void RenderViewImpl::OnPageWasHidden() {
braveyao1d8ee7b2017-03-29 21:10:042154#if defined(OS_ANDROID)
2155 SuspendVideoCaptureDevices(true);
braveyao1d8ee7b2017-03-29 21:10:042156#endif
[email protected]2d7b82c2012-06-01 05:57:502157
lfg717154072016-06-30 15:04:162158 if (webview()) {
2159 // TODO(lfg): It's not correct to defer the page visibility to the main
2160 // frame. Currently, this is done because the main frame may override the
2161 // visibility of the page when prerendering. In order to fix this,
2162 // prerendering must be made aware of OOPIFs. https://crbug.com/440544
xzhan96cf0a3c542017-11-17 04:33:012163 blink::mojom::PageVisibilityState visibilityState =
Blink Reformat1c4d759e2017-04-09 16:34:542164 GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState()
xzhan96cf0a3c542017-11-17 04:33:012165 : blink::mojom::PageVisibilityState::kHidden;
Blink Reformat1c4d759e2017-04-09 16:34:542166 webview()->SetVisibilityState(visibilityState, false);
lfg717154072016-06-30 15:04:162167 }
[email protected]941e4552010-02-01 21:23:432168}
2169
lfg717154072016-06-30 15:04:162170void RenderViewImpl::OnPageWasShown() {
braveyao1d8ee7b2017-03-29 21:10:042171#if defined(OS_ANDROID)
2172 SuspendVideoCaptureDevices(false);
[email protected]6392d982013-04-16 16:59:222173#endif
2174
lfg717154072016-06-30 15:04:162175 if (webview()) {
xzhan96cf0a3c542017-11-17 04:33:012176 blink::mojom::PageVisibilityState visibilityState =
Blink Reformat1c4d759e2017-04-09 16:34:542177 GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState()
xzhan96cf0a3c542017-11-17 04:33:012178 : blink::mojom::PageVisibilityState::kVisible;
Blink Reformat1c4d759e2017-04-09 16:34:542179 webview()->SetVisibilityState(visibilityState, false);
lfg717154072016-06-30 15:04:162180 }
[email protected]a6939ca42011-02-18 17:58:072181}
[email protected]1e6e3c992010-02-08 15:52:132182
lfg8d649cc2017-04-28 18:04:302183void RenderViewImpl::OnUpdateScreenInfo(const ScreenInfo& screen_info) {
2184 // This IPC only updates the screen info on RenderViews that have a remote
2185 // main frame. For local main frames, the ScreenInfo is updated in
2186 // ViewMsg_Resize.
2187 if (!main_render_frame_)
2188 screen_info_ = screen_info;
2189}
2190
Fadi Meawada6573e02018-03-10 00:52:112191void RenderViewImpl::OnFreezePage() {
2192 if (webview()) {
2193 webview()->FreezePage();
2194 }
2195}
2196
[email protected]ed7defa2013-03-12 21:29:592197GURL RenderViewImpl::GetURLForGraphicsContext3D() {
2198 DCHECK(webview());
Lukasz Anforowiczc33ac1692017-12-12 21:59:472199 WebFrame* main_frame = webview()->MainFrame();
2200 if (main_frame && main_frame->IsWebLocalFrame())
2201 return GURL(main_frame->ToWebLocalFrame()->GetDocument().Url());
[email protected]ed7defa2013-03-12 21:29:592202 else
2203 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]65225772011-05-12 21:10:242204}
2205
[email protected]310ebd6302011-10-10 19:06:282206void RenderViewImpl::OnSetFocus(bool enable) {
naskoc6edf7e2015-10-16 01:48:452207 // This message must always be received when the main frame is a
2208 // WebLocalFrame.
Blink Reformat1c4d759e2017-04-09 16:34:542209 CHECK(webview()->MainFrame()->IsWebLocalFrame());
alexmos3fcd0ca2015-10-23 18:18:332210 SetFocus(enable);
2211}
alexmos7fac9aeb2015-10-16 22:39:492212
alexmos3fcd0ca2015-10-23 18:18:332213void RenderViewImpl::SetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:132214 RenderWidget::OnSetFocus(enable);
2215
[email protected]321032992012-11-08 01:01:272216 // Notify all BrowserPlugins of the RenderView's focus state.
fsamuel6c1dfeb2014-12-18 19:21:332217 if (BrowserPluginManager::Get())
2218 BrowserPluginManager::Get()->UpdateFocusState();
[email protected]1e6e3c992010-02-08 15:52:132219}
[email protected]941e4552010-02-01 21:23:432220
rouslanf7ebd8832015-01-22 01:54:142221void RenderViewImpl::DidCompletePageScaleAnimation() {
ekaramad27ca69b12017-04-20 18:34:292222 if (auto* focused_frame = GetWebView()->FocusedFrame()) {
2223 if (focused_frame->AutofillClient())
2224 focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame();
2225 }
rouslanf7ebd8832015-01-22 01:54:142226}
2227
[email protected]b2e4c70132013-10-03 02:07:512228void RenderViewImpl::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:202229 bool enabled,
2230 const blink::WebDeviceEmulationParams& params) {
[email protected]404630b2014-07-03 19:33:032231 if (webview() && compositor()) {
dgozman9260b0a12015-03-16 13:45:202232 if (enabled)
Blink Reformat1c4d759e2017-04-09 16:34:542233 webview()->EnableDeviceEmulation(params);
dgozman9260b0a12015-03-16 13:45:202234 else
Blink Reformat1c4d759e2017-04-09 16:34:542235 webview()->DisableDeviceEmulation();
[email protected]b2e4c70132013-10-03 02:07:512236 }
2237}
2238
Blink Reformat1c4d759e2017-04-09 16:34:542239void RenderViewImpl::ZoomLimitsChanged(double minimum_level,
[email protected]310ebd6302011-10-10 19:06:282240 double maximum_level) {
a.sarkar.arundaadc712015-02-26 05:39:082241 // Round the double to avoid returning incorrect minimum/maximum zoom
2242 // percentages.
2243 int minimum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492244 ZoomLevelToZoomFactor(minimum_level) * 100);
a.sarkar.arundaadc712015-02-26 05:39:082245 int maximum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492246 ZoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:252247
avia3dca182016-03-19 01:09:522248 Send(new ViewHostMsg_UpdateZoomLimits(GetRoutingID(), minimum_percent,
fsamuele8326c742016-01-12 00:49:392249 maximum_percent));
[email protected]b75b8292010-10-01 07:28:252250}
2251
Blink Reformat1c4d759e2017-04-09 16:34:542252void RenderViewImpl::PageScaleFactorChanged() {
ccameronb7c1d6c2015-03-09 17:08:242253 if (!webview())
2254 return;
mcnee432e47d2015-11-09 19:37:462255
avia3dca182016-03-19 01:09:522256 Send(new ViewHostMsg_PageScaleFactorChanged(GetRoutingID(),
Blink Reformat1c4d759e2017-04-09 16:34:542257 webview()->PageScaleFactor()));
ccameronb7c1d6c2015-03-09 17:08:242258}
2259
[email protected]7940b8e2013-07-25 23:08:492260double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const {
2261 return ZoomLevelToZoomFactor(zoom_level);
2262}
2263
2264double RenderViewImpl::zoomFactorToZoomLevel(double factor) const {
2265 return ZoomFactorToZoomLevel(factor);
2266}
2267
Blink Reformat1c4d759e2017-04-09 16:34:542268void RenderViewImpl::PageImportanceSignalsChanged() {
kouhei40f03cb2015-09-24 07:47:012269 if (!webview() || !main_render_frame_)
2270 return;
2271
Blink Reformat1c4d759e2017-04-09 16:34:542272 auto* web_signals = webview()->PageImportanceSignals();
kouhei40f03cb2015-09-24 07:47:012273
2274 PageImportanceSignals signals;
Blink Reformat1c4d759e2017-04-09 16:34:542275 signals.had_form_interaction = web_signals->HadFormInteraction();
kouhei40f03cb2015-09-24 07:47:012276
2277 main_render_frame_->Send(new FrameHostMsg_UpdatePageImportanceSignals(
2278 main_render_frame_->GetRoutingID(), signals));
2279}
2280
[email protected]20657a82012-08-21 20:23:032281#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:542282bool RenderViewImpl::OpenDateTimeChooser(
[email protected]180ef242013-11-07 06:50:462283 const blink::WebDateTimeChooserParams& params,
2284 blink::WebDateTimeChooserCompletion* completion) {
[email protected]e8072562013-12-04 06:04:132285 // JavaScript may try to open a date time chooser while one is already open.
2286 if (date_time_picker_client_)
2287 return false;
[email protected]b18583c2012-12-18 06:55:272288 date_time_picker_client_.reset(
2289 new RendererDateTimePicker(this, params, completion));
2290 return date_time_picker_client_->Open();
2291}
2292
[email protected]e8072562013-12-04 06:04:132293void RenderViewImpl::DismissDateTimeDialog() {
2294 DCHECK(date_time_picker_client_);
Lei Zhang88f23ba2017-10-27 05:56:262295 date_time_picker_client_.reset();
[email protected]e8072562013-12-04 06:04:132296}
[email protected]e8072562013-12-04 06:04:132297
Blink Reformat1c4d759e2017-04-09 16:34:542298bool RenderViewImpl::DidTapMultipleTargets(
timav29a8d0f62014-09-25 20:45:532299 const WebSize& inner_viewport_offset,
2300 const WebRect& touch_rect,
[email protected]f9526d12012-10-18 01:55:032301 const WebVector<WebRect>& target_rects) {
[email protected]8d3dfee62013-06-19 05:50:332302 // Never show a disambiguation popup when accessibility is enabled,
2303 // as this interferes with "touch exploration".
Doug Turner63f3c7b2017-07-29 05:10:012304 ui::AXMode accessibility_mode = GetMainRenderFrame()->accessibility_mode();
2305 if (accessibility_mode == ui::kAXModeComplete)
[email protected]8d3dfee62013-06-19 05:50:332306 return false;
2307
timav29a8d0f62014-09-25 20:45:532308 // The touch_rect, target_rects and zoom_rect are in the outer viewport
2309 // reference frame.
Fady Samuela863f152018-03-09 16:10:032310 float to_pix =
2311 IsUseZoomForDSFEnabled() ? 1 : GetWebScreenInfo().device_scale_factor;
[email protected]f9526d12012-10-18 01:55:032312 gfx::Rect zoom_rect;
[email protected]70221f02013-01-31 22:17:072313 float new_total_scale =
2314 DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
timav29a8d0f62014-09-25 20:45:532315 touch_rect, target_rects, GetSize(),
Blink Reformat1c4d759e2017-04-09 16:34:542316 gfx::Rect(webview()->MainFrame()->VisibleContentRect()).size(),
Jaebaek Seo6de124a2018-02-15 03:34:032317 to_pix * webview()->PageScaleFactor(), &zoom_rect);
jbauman0ed09182015-01-30 22:33:492318 if (!new_total_scale || zoom_rect.IsEmpty())
[email protected]f9526d12012-10-18 01:55:032319 return false;
2320
[email protected]4ded1dbf2013-08-28 21:11:032321 bool handled = false;
2322 switch (renderer_preferences_.tap_multiple_targets_strategy) {
2323 case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM:
Blink Reformat1c4d759e2017-04-09 16:34:542324 handled = webview()->ZoomToMultipleTargetsRect(zoom_rect);
[email protected]4ded1dbf2013-08-28 21:11:032325 break;
2326 case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: {
[email protected]bc2804d2013-08-06 07:45:492327 gfx::Size canvas_size =
danakjddaec912015-09-25 19:38:402328 gfx::ScaleToCeiledSize(zoom_rect.size(), new_total_scale);
kylechare7d8d5c72018-01-05 19:06:282329
2330 SkImageInfo info =
2331 SkImageInfo::MakeN32Premul(canvas_size.width(), canvas_size.height());
2332 size_t shm_size = info.computeMinByteSize();
2333
2334 if (shm_size == 0) {
2335 DLOG(ERROR) << "Invalid size for SharedMemory";
2336 return false;
2337 }
2338
2339 auto shm = ChildThreadImpl::AllocateSharedMemory(shm_size);
2340 if (!shm || !shm->Map(shm_size)) {
2341 DLOG(ERROR) << "SharedMemory allocate/map failed";
2342 return false;
2343 }
2344
[email protected]bc2804d2013-08-06 07:45:492345 {
[email protected]cb189e062014-04-23 00:57:012346 SkBitmap bitmap;
kylechare7d8d5c72018-01-05 19:06:282347 bitmap.installPixels(info, shm->memory(), info.minRowBytes());
enne98c9f8052017-03-15 19:38:222348 cc::SkiaPaintCanvas canvas(bitmap);
[email protected]f9526d12012-10-18 01:55:032349
[email protected]bc2804d2013-08-06 07:45:492350 // TODO(trchen): Cleanup the device scale factor mess.
2351 // device scale will be applied in WebKit
2352 // --> zoom_rect doesn't include device scale,
Christopher Camerone9a30c12018-03-07 08:23:382353 // but WebKit will still draw on zoom_rect *
Fady Samuela863f152018-03-09 16:10:032354 // GetWebScreenInfo().device_scale_factor
Jaebaek Seo6de124a2018-02-15 03:34:032355 canvas.scale(new_total_scale / to_pix, new_total_scale / to_pix);
2356 canvas.translate(-zoom_rect.x() * to_pix, -zoom_rect.y() * to_pix);
[email protected]f9526d12012-10-18 01:55:032357
Blink Reformat1c4d759e2017-04-09 16:34:542358 DCHECK(webview_->IsAcceleratedCompositingActive());
Chris Harrelsonc5b48e22018-01-27 03:48:062359 webview_->UpdateAllLifecyclePhases();
Blink Reformat1c4d759e2017-04-09 16:34:542360 webview_->PaintIgnoringCompositing(&canvas, zoom_rect);
[email protected]bc2804d2013-08-06 07:45:492361 }
2362
timav29a8d0f62014-09-25 20:45:532363 gfx::Rect zoom_rect_in_screen =
2364 zoom_rect - gfx::Vector2d(inner_viewport_offset.width,
2365 inner_viewport_offset.height);
2366
[email protected]bc2804d2013-08-06 07:45:492367 gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect(
Jaebaek Seo6de124a2018-02-15 03:34:032368 gfx::ScaleRect(gfx::RectF(zoom_rect_in_screen),
2369 to_pix * webview()->PageScaleFactor()));
timav29a8d0f62014-09-25 20:45:532370
kylechare7d8d5c72018-01-05 19:06:282371 // A SharedMemoryHandle is sent to the browser process, which is
2372 // responsible for freeing the shared memory when no longer needed.
fsamuele8326c742016-01-12 00:49:392373 Send(new ViewHostMsg_ShowDisambiguationPopup(
avia3dca182016-03-19 01:09:522374 GetRoutingID(), physical_window_zoom_rect, canvas_size,
kylechare7d8d5c72018-01-05 19:06:282375 shm->TakeHandle()));
2376
[email protected]4ded1dbf2013-08-28 21:11:032377 handled = true;
2378 break;
2379 }
2380 case TAP_MULTIPLE_TARGETS_STRATEGY_NONE:
2381 // No-op.
2382 break;
[email protected]f9526d12012-10-18 01:55:032383 }
[email protected]70221f02013-01-31 22:17:072384
[email protected]4ded1dbf2013-08-28 21:11:032385 return handled;
[email protected]f9526d12012-10-18 01:55:032386}
braveyao1d8ee7b2017-03-29 21:10:042387
2388void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) {
tsunghunga86cde72017-04-10 22:27:132389#if BUILDFLAG(ENABLE_WEBRTC)
braveyao1d8ee7b2017-03-29 21:10:042390 if (!main_render_frame_)
2391 return;
2392
Chandan Padhi26dbd9b32017-11-27 11:13:352393 MediaStreamDeviceObserver* media_stream_device_observer =
2394 main_render_frame_->GetMediaStreamDeviceObserver();
2395 if (!media_stream_device_observer)
braveyao1d8ee7b2017-03-29 21:10:042396 return;
2397
Chandan Padhi6dbfb732017-09-01 16:08:492398 MediaStreamDevices video_devices =
Chandan Padhi26dbd9b32017-11-27 11:13:352399 media_stream_device_observer->GetNonScreenCaptureDevices();
braveyao1d8ee7b2017-03-29 21:10:042400 RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices(
Chandan Padhi6dbfb732017-09-01 16:08:492401 video_devices, suspend);
tsunghunga86cde72017-04-10 22:27:132402#endif // BUILDFLAG(ENABLE_WEBRTC)
braveyao1d8ee7b2017-03-29 21:10:042403}
estade6b9696bd2016-05-04 23:51:362404#endif // defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:032405
[email protected]b283d292013-02-21 08:40:342406unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
2407 return history_list_length_;
2408}
2409
[email protected]cc290f902013-03-04 20:06:022410void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
2411 if (enable) {
2412 if (has_focus())
2413 return;
2414 OnSetActive(true);
2415 OnSetFocus(true);
2416 } else {
2417 if (!has_focus())
2418 return;
2419 OnSetFocus(false);
2420 OnSetActive(false);
2421 }
2422}
2423
[email protected]3a1c8a8032013-03-18 22:35:322424void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) {
Saman Samif7731342018-01-24 22:18:442425 device_scale_factor_for_testing_ = factor;
2426
fsamuel664e8b62016-01-20 19:54:012427 ResizeParams params;
[email protected]b54fe452013-06-07 14:01:532428 params.screen_info = screen_info_;
ccameron2f451532016-09-07 21:49:272429 params.screen_info.device_scale_factor = factor;
[email protected]b54fe452013-06-07 14:01:532430 params.new_size = size();
bokanf0fd2412014-10-30 15:28:552431 params.visible_viewport_size = visible_viewport_size_;
Christopher Cameronaad15a0d2018-03-09 03:47:332432 params.compositor_viewport_pixel_size =
2433 gfx::ScaleToCeiledSize(size(), factor);
mdjones2ee41afd2016-10-27 16:50:202434 params.browser_controls_shrink_blink_size = false;
dtrainorcb7779b82014-12-04 01:08:022435 params.top_controls_height = 0.f;
mikhail.pozdnyakovf2c902a2015-04-14 08:09:122436 params.is_fullscreen_granted = is_fullscreen_granted();
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122437 params.display_mode = display_mode_;
Saman Samif7731342018-01-24 22:18:442438 params.content_source_id = GetContentSourceId();
[email protected]b54fe452013-06-07 14:01:532439 OnResize(params);
[email protected]3a1c8a8032013-03-18 22:35:322440}
2441
ccameron39b1cbc2017-07-06 00:23:552442void RenderViewImpl::SetDeviceColorSpaceForTesting(
2443 const gfx::ColorSpace& color_space) {
mlamouriafca06dd2017-01-27 23:35:182444 ResizeParams params;
2445 params.screen_info = screen_info_;
ccameron39b1cbc2017-07-06 00:23:552446 params.screen_info.color_space = color_space;
mlamouriafca06dd2017-01-27 23:35:182447 params.new_size = size();
2448 params.visible_viewport_size = visible_viewport_size_;
Christopher Cameronaad15a0d2018-03-09 03:47:332449 params.compositor_viewport_pixel_size = compositor_viewport_pixel_size_;
mlamouriafca06dd2017-01-27 23:35:182450 params.browser_controls_shrink_blink_size = false;
2451 params.top_controls_height = 0.f;
2452 params.is_fullscreen_granted = is_fullscreen_granted();
2453 params.display_mode = display_mode_;
2454 OnResize(params);
2455}
2456
[email protected]92650162013-10-30 03:31:022457void RenderViewImpl::ForceResizeForTesting(const gfx::Size& new_size) {
Blink Reformat1c4d759e2017-04-09 16:34:542458 gfx::Rect new_window_rect(RootWindowRect().x, RootWindowRect().y,
2459 new_size.width(), new_size.height());
bokanc007c3a2015-02-03 07:15:562460 SetWindowRectSynchronously(new_window_rect);
[email protected]92650162013-10-30 03:31:022461}
2462
[email protected]5b45ad42013-10-25 00:42:042463void RenderViewImpl::UseSynchronousResizeModeForTesting(bool enable) {
2464 resizing_mode_selector_->set_is_synchronous_mode(enable);
2465}
2466
[email protected]eac2b362013-05-22 07:01:452467void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size,
2468 const gfx::Size& max_size) {
2469 OnEnableAutoResize(min_size, max_size);
2470}
2471
2472void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) {
2473 OnDisableAutoResize(new_size);
2474}
2475
aelias1b55156e52017-04-01 00:46:052476void RenderViewImpl::OnResolveTapDisambiguation(double timestamp_seconds,
2477 gfx::Point tap_viewport_offset,
2478 bool is_long_press) {
Blink Reformat1c4d759e2017-04-09 16:34:542479 webview()->ResolveTapDisambiguation(timestamp_seconds, tap_viewport_offset,
aelias1b55156e52017-04-01 00:46:052480 is_long_press);
2481}
2482
[email protected]6fceb912013-02-15 06:24:152483void RenderViewImpl::DidCommitCompositorFrame() {
2484 RenderWidget::DidCommitCompositorFrame();
ericwilligers88e69742016-10-17 19:29:552485 for (auto& observer : observers_)
2486 observer.DidCommitCompositorFrame();
[email protected]6fceb912013-02-15 06:24:152487}
2488
dtapuska1b0fcc322016-10-28 18:08:282489void RenderViewImpl::OnDiscardInputEvent(
2490 const blink::WebInputEvent* input_event,
nzolghadr5d8596502017-01-23 22:59:352491 const std::vector<const blink::WebInputEvent*>& coalesced_events,
dtapuska1b0fcc322016-10-28 18:08:282492 const ui::LatencyInfo& latency_info,
2493 InputEventDispatchType dispatch_type) {
dtapuska9ec1a912017-04-21 15:18:312494 if (!input_event || dispatch_type == DISPATCH_TYPE_NON_BLOCKING) {
dtapuska1b0fcc322016-10-28 18:08:282495 return;
2496 }
2497
Dave Tapuskaea83d3bd2017-06-13 16:14:552498 InputEventAck ack(InputEventAckSource::MAIN_THREAD, input_event->GetType(),
2499 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2500 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
dtapuska1b0fcc322016-10-28 18:08:282501}
2502
Dave Tapuskaea83d3bd2017-06-13 16:14:552503void RenderViewImpl::HandleInputEvent(
dtapuska9ec1a912017-04-21 15:18:312504 const blink::WebCoalescedInputEvent& input_event,
2505 const ui::LatencyInfo& latency_info,
Dave Tapuskaea83d3bd2017-06-13 16:14:552506 HandledEventCallback callback) {
dtapuska9ec1a912017-04-21 15:18:312507 if (is_swapped_out_) {
Dave Tapuskaea83d3bd2017-06-13 16:14:552508 std::move(callback).Run(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, latency_info,
Dave Tapuskab28a1082017-08-30 15:37:262509 nullptr, base::nullopt);
Dave Tapuskaea83d3bd2017-06-13 16:14:552510 return;
dtapuska9ec1a912017-04-21 15:18:312511 }
2512 idle_user_detector_->ActivityDetected();
Dave Tapuskaea83d3bd2017-06-13 16:14:552513 RenderWidget::HandleInputEvent(input_event, latency_info,
2514 std::move(callback));
dtapuska9ec1a912017-04-21 15:18:312515}
2516
[email protected]e9ff79c2012-10-19 21:31:262517} // namespace content