blob: 95165bd76c0189c5ebca837d0e77e9d385c2abbc [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"
danakj92429852017-06-29 00:19:0343#include "components/viz/client/client_shared_bitmap_manager.h"
jinho.bang632a1a722014-09-18 03:02:5644#include "content/common/content_constants_internal.h"
oshima750cb4342015-10-31 00:59:0145#include "content/common/content_switches_internal.h"
[email protected]5f2aa722013-08-07 16:59:4146#include "content/common/dom_storage/dom_storage_types.h"
[email protected]59f4f2fa2011-03-23 01:00:5547#include "content/common/drag_messages.h"
[email protected]c6bc20332014-02-28 18:30:3948#include "content/common/frame_messages.h"
alexmosbc7eafa2014-12-06 01:38:0949#include "content/common/frame_replication_state.h"
[email protected]c084330e02013-04-27 01:08:1550#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0751#include "content/common/page_messages.h"
rockot5c478a72016-09-28 23:14:1852#include "content/common/render_message_filter.mojom.h"
[email protected]778574e2011-03-21 22:03:5053#include "content/common/view_messages.h"
csharrison95f01e922017-04-24 18:52:3554#include "content/public/common/associated_interface_provider.h"
arthursonzognic517fc32016-08-11 11:04:2455#include "content/public/common/browser_side_navigation_policy.h"
[email protected]744c2a22012-03-15 18:42:0456#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4857#include "content/public/common/content_constants.h"
Tarun Bansal73dd2ff82017-10-03 05:29:3458#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2959#include "content/public/common/content_switches.h"
kouhei40f03cb2015-09-24 07:47:0160#include "content/public/common/page_importance_signals.h"
clamyda97e8322014-10-07 21:57:2561#include "content/public/common/page_state.h"
[email protected]7940b8e2013-07-25 23:08:4962#include "content/public/common/page_zoom.h"
[email protected]818915cd2012-11-20 13:14:1163#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0364#include "content/public/common/url_constants.h"
[email protected]b3a97b52014-07-09 06:25:0565#include "content/public/common/web_preferences.h"
[email protected]d344114c2011-10-01 01:24:3466#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0767#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3268#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4469#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3670#include "content/public/renderer/render_view_visitor.h"
scottmg8e6c6082017-02-13 23:15:4871#include "content/public/renderer/window_features_converter.h"
John Abd-El-Malekdcf1d1372017-10-22 06:39:4172#include "content/renderer/appcache/appcache_dispatcher.h"
73#include "content/renderer/appcache/web_application_cache_host_impl.h"
[email protected]e6e56752012-08-10 00:46:0674#include "content/renderer/browser_plugin/browser_plugin.h"
75#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]1910fe82012-05-10 00:04:1076#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]dc293a72013-07-01 11:11:2277#include "content/renderer/drop_data_builder.h"
[email protected]ba91a792013-02-06 09:48:2878#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]dc064352014-04-25 08:36:3879#include "content/renderer/history_serialization.h"
[email protected]1784b2f2011-11-24 10:53:4880#include "content/renderer/idle_user_detector.h"
[email protected]66fca5bc2013-05-23 06:58:2981#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1382#include "content/renderer/input/input_handler_manager.h"
[email protected]92d457802013-04-01 19:18:4983#include "content/renderer/internal_document_state_data.h"
John Abd-El-Malek6b56ef712017-10-21 22:52:4684#include "content/renderer/loader/request_extra_data.h"
[email protected]4a914882013-01-10 00:43:4885#include "content/renderer/media/audio_device_factory.h"
braveyao1d8ee7b2017-03-29 21:10:0486#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]6392d982013-04-16 16:59:2287#include "content/renderer/media/video_capture_impl_manager.h"
clamy5f342202015-03-18 13:47:5688#include "content/renderer/navigation_state_impl.h"
[email protected]227692c52013-05-31 22:43:0489#include "content/renderer/render_frame_impl.h"
[email protected]5a7100d2014-05-19 01:29:0490#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0591#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4492#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4493#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]663bd9e2011-03-21 01:07:0194#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]5b45ad42013-10-25 00:42:0495#include "content/renderer/resizing_mode_selector.h"
[email protected]12a936d2013-05-15 04:55:4996#include "content/renderer/savable_resources.h"
[email protected]64d09222012-05-25 10:10:3497#include "content/renderer/speech_recognition_dispatcher.h"
John Abd-El-Malek312a30bb2017-10-23 19:51:5298#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:2199#include "content/renderer/web_ui_extension_data.h"
[email protected]f5961142013-04-17 23:09:42100#include "media/audio/audio_output_device.h"
[email protected]ee68378a2010-08-10 01:05:41101#include "media/base/media_switches.h"
Brett Wilson0748bf412016-11-22 17:55:46102#include "media/media_features.h"
servolkf54f5c8f2015-02-24 20:32:39103#include "media/renderers/audio_renderer_impl.h"
Dale Curtis863022e2017-08-19 02:05:34104#include "media/video/gpu_video_accelerator_factories.h"
[email protected]d1ef81d2012-07-24 11:39:36105#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29106#include "net/base/escape.h"
107#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09108#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04109#include "net/http/http_util.h"
brettw4b461082016-11-19 18:55:16110#include "ppapi/features/features.h"
lukenb171b532014-09-24 05:50:38111#include "skia/ext/platform_canvas.h"
kinukob473f002016-02-22 05:23:19112#include "third_party/WebKit/public/platform/FilePathConversion.h"
brettwdfbcc3b2016-01-20 01:49:17113#include "third_party/WebKit/public/platform/URLConversion.h"
[email protected]b3a97b52014-07-09 06:25:05114#include "third_party/WebKit/public/platform/WebConnectionType.h"
[email protected]d0fcff72013-07-23 02:45:43115#include "third_party/WebKit/public/platform/WebHTTPBody.h"
116#include "third_party/WebKit/public/platform/WebImage.h"
dtapuska836e1f92016-11-15 00:38:06117#include "third_party/WebKit/public/platform/WebInputEvent.h"
skyostilcff62882017-01-28 13:18:04118#include "third_party/WebKit/public/platform/WebInputEventResult.h"
[email protected]d0fcff72013-07-23 02:45:43119#include "third_party/WebKit/public/platform/WebPoint.h"
120#include "third_party/WebKit/public/platform/WebRect.h"
nverne61d2da872017-05-24 10:15:30121#include "third_party/WebKit/public/platform/WebRuntimeFeatures.h"
[email protected]d0fcff72013-07-23 02:45:43122#include "third_party/WebKit/public/platform/WebSize.h"
[email protected]ec173b522013-11-14 11:01:18123#include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h"
[email protected]d0fcff72013-07-23 02:45:43124#include "third_party/WebKit/public/platform/WebString.h"
125#include "third_party/WebKit/public/platform/WebURL.h"
126#include "third_party/WebKit/public/platform/WebURLError.h"
127#include "third_party/WebKit/public/platform/WebURLRequest.h"
128#include "third_party/WebKit/public/platform/WebURLResponse.h"
129#include "third_party/WebKit/public/platform/WebVector.h"
brettw8a274fa2016-11-15 00:20:40130#include "third_party/WebKit/public/public_features.h"
[email protected]10760e4a2013-09-04 23:32:20131#include "third_party/WebKit/public/web/WebAXObject.h"
ekaramad27ca69b12017-04-20 18:34:29132#include "third_party/WebKit/public/web/WebAutofillClient.h"
[email protected]8bc5ff02013-11-29 06:34:03133#include "third_party/WebKit/public/web/WebColorSuggestion.h"
[email protected]2255a9332013-06-17 05:12:31134#include "third_party/WebKit/public/web/WebDOMEvent.h"
135#include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
[email protected]2255a9332013-06-17 05:12:31136#include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h"
137#include "third_party/WebKit/public/web/WebDateTimeChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31138#include "third_party/WebKit/public/web/WebDocument.h"
139#include "third_party/WebKit/public/web/WebElement.h"
140#include "third_party/WebKit/public/web/WebFileChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31141#include "third_party/WebKit/public/web/WebFormControlElement.h"
142#include "third_party/WebKit/public/web/WebFormElement.h"
143#include "third_party/WebKit/public/web/WebFrame.h"
dglazkov03223492016-02-08 22:16:03144#include "third_party/WebKit/public/web/WebFrameContentDumper.h"
lfgcaab5142016-02-26 19:06:52145#include "third_party/WebKit/public/web/WebFrameWidget.h"
[email protected]2255a9332013-06-17 05:12:31146#include "third_party/WebKit/public/web/WebHistoryItem.h"
[email protected]91dcc6d32014-07-30 00:01:33147#include "third_party/WebKit/public/web/WebHitTestResult.h"
[email protected]2255a9332013-06-17 05:12:31148#include "third_party/WebKit/public/web/WebInputElement.h"
[email protected]35b2a972014-04-04 15:50:22149#include "third_party/WebKit/public/web/WebLocalFrame.h"
[email protected]2255a9332013-06-17 05:12:31150#include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
151#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
kouhei40f03cb2015-09-24 07:47:01152#include "third_party/WebKit/public/web/WebPageImportanceSignals.h"
[email protected]2255a9332013-06-17 05:12:31153#include "third_party/WebKit/public/web/WebPlugin.h"
154#include "third_party/WebKit/public/web/WebPluginAction.h"
[email protected]2255a9332013-06-17 05:12:31155#include "third_party/WebKit/public/web/WebRange.h"
ellyjones8ae17692016-08-05 15:19:21156#include "third_party/WebKit/public/web/WebRenderTheme.h"
[email protected]2255a9332013-06-17 05:12:31157#include "third_party/WebKit/public/web/WebScriptSource.h"
158#include "third_party/WebKit/public/web/WebSearchableFormData.h"
[email protected]2255a9332013-06-17 05:12:31159#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
[email protected]2255a9332013-06-17 05:12:31160#include "third_party/WebKit/public/web/WebSettings.h"
[email protected]2255a9332013-06-17 05:12:31161#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
[email protected]2255a9332013-06-17 05:12:31162#include "third_party/WebKit/public/web/WebView.h"
163#include "third_party/WebKit/public/web/WebWindowFeatures.h"
[email protected]b3a97b52014-07-09 06:25:05164#include "third_party/icu/source/common/unicode/uchar.h"
165#include "third_party/icu/source/common/unicode/uscript.h"
esecklerf2bd55f72017-03-31 09:11:57166#include "third_party/skia/include/core/SkColor.h"
[email protected]1400e6dc2013-04-27 02:36:27167#include "ui/base/ui_base_switches_util.h"
tfarina655f81d2014-12-23 02:38:50168#include "ui/gfx/geometry/point.h"
tfarina3b0452d2014-12-31 15:20:09169#include "ui/gfx/geometry/rect.h"
170#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32171#include "ui/gfx/geometry/size_conversions.h"
[email protected]08397d52011-02-05 01:53:38172#include "ui/gfx/native_widget_types.h"
ccameron772317d2017-06-04 18:35:03173#include "ui/gfx/switches.h"
mfomitchev3ba450ad2017-04-03 18:20:40174#include "ui/latency/latency_info.h"
csharrisond88f9752016-10-26 23:56:36175#include "url/origin.h"
markdittmer67b71ea2016-03-03 22:40:03176#include "url/url_constants.h"
[email protected]c4a9e932011-03-05 04:05:55177#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:29178
[email protected]25fb9b32012-04-27 03:21:55179#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25180#include <cpu-features.h>
181
dalecurtiscd971252016-09-21 16:09:00182#include "base/android/build_info.h"
estade6b9696bd2016-05-04 23:51:36183#include "content/renderer/android/disambiguation_popup_helper.h"
tfarina3b0452d2014-12-31 15:20:09184#include "ui/gfx/geometry/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40185
[email protected]78043bdd2010-04-05 18:45:33186#elif defined(OS_MACOSX)
187#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57188#endif
189
brettw4b461082016-11-19 18:55:16190#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]ea2fb972013-08-07 05:44:26191#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
192#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26193#endif
194
Brett Wilson0748bf412016-11-22 17:55:46195#if BUILDFLAG(ENABLE_WEBRTC)
[email protected]9ac667e2013-09-09 12:49:21196#include "content/renderer/media/rtc_peer_connection_handler.h"
[email protected]22fe91d2014-08-12 17:07:12197#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
[email protected]9ac667e2013-09-09 12:49:21198#endif
199
[email protected]180ef242013-11-07 06:50:46200using blink::WebAXObject;
201using blink::WebApplicationCacheHost;
202using blink::WebApplicationCacheHostClient;
[email protected]180ef242013-11-07 06:50:46203using blink::WebColor;
[email protected]180ef242013-11-07 06:50:46204using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46205using blink::WebData;
[email protected]180ef242013-11-07 06:50:46206using blink::WebDocument;
[email protected]180ef242013-11-07 06:50:46207using blink::WebDragOperation;
[email protected]180ef242013-11-07 06:50:46208using blink::WebElement;
[email protected]180ef242013-11-07 06:50:46209using blink::WebFileChooserCompletion;
[email protected]180ef242013-11-07 06:50:46210using blink::WebFormControlElement;
211using blink::WebFormElement;
212using blink::WebFrame;
dglazkov03223492016-02-08 22:16:03213using blink::WebFrameContentDumper;
[email protected]180ef242013-11-07 06:50:46214using blink::WebGestureEvent;
215using blink::WebHistoryItem;
216using blink::WebHTTPBody;
dglazkov8d0c21dd2016-08-06 15:56:36217using blink::WebHitTestResult;
[email protected]180ef242013-11-07 06:50:46218using blink::WebImage;
219using blink::WebInputElement;
220using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22221using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46222using blink::WebMediaPlayerAction;
[email protected]180ef242013-11-07 06:50:46223using blink::WebMouseEvent;
224using blink::WebNavigationPolicy;
225using blink::WebNavigationType;
226using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46227using blink::WebPluginAction;
[email protected]180ef242013-11-07 06:50:46228using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46229using blink::WebRect;
230using blink::WebReferrerPolicy;
Daniel Chengd5e56ff2017-06-24 07:44:02231using blink::WebSandboxFlags;
[email protected]180ef242013-11-07 06:50:46232using blink::WebScriptSource;
233using blink::WebSearchableFormData;
234using blink::WebSecurityOrigin;
235using blink::WebSecurityPolicy;
[email protected]180ef242013-11-07 06:50:46236using blink::WebSettings;
237using blink::WebSize;
[email protected]180ef242013-11-07 06:50:46238using blink::WebStorageNamespace;
239using blink::WebStorageQuotaCallbacks;
240using blink::WebStorageQuotaError;
241using blink::WebStorageQuotaType;
242using blink::WebString;
Donn Denman43a439e2017-08-29 04:20:45243using blink::WebTappedInfo;
[email protected]180ef242013-11-07 06:50:46244using blink::WebTextDirection;
245using blink::WebTouchEvent;
246using blink::WebURL;
247using blink::WebURLError;
248using blink::WebURLRequest;
249using blink::WebURLResponse;
250using blink::WebUserGestureIndicator;
251using blink::WebVector;
252using blink::WebView;
253using blink::WebWidget;
254using blink::WebWindowFeatures;
[email protected]b3a97b52014-07-09 06:25:05255using blink::WebRuntimeFeatures;
[email protected]6fdd4182010-10-14 23:59:26256using base::Time;
257using base::TimeDelta;
[email protected]e1acf6f2008-10-27 20:43:33258
[email protected]20657a82012-08-21 20:23:03259
[email protected]e9ff79c2012-10-19 21:31:26260namespace content {
261
initial.commit09911bf2008-07-26 23:55:29262//-----------------------------------------------------------------------------
263
[email protected]180ef242013-11-07 06:50:46264typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
jbroman8319b232017-03-08 22:53:29265static base::LazyInstance<ViewMap>::Leaky g_view_map =
[email protected]058561b2012-12-03 06:48:22266 LAZY_INSTANCE_INITIALIZER;
scottmg5e65e3a2017-03-08 08:48:46267typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap;
jbroman8319b232017-03-08 22:53:29268static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map =
269 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02270
[email protected]882daa92009-11-05 16:31:31271// Time, in seconds, we delay before sending content state changes (such as form
272// state and scroll position) to the browser. We delay sending changes to avoid
273// spamming the browser.
274// To avoid having tab/session restore require sending a message to get the
275// current content state during tab closing we use a shorter timeout for the
276// foreground renderer. This means there is a small window of time from which
277// content state is modified and not sent to session restore, but this is
278// better than having to wake up all renderers during shutdown.
avif937e1d2014-11-02 18:13:07279const int kDelaySecondsForContentStateSyncHidden = 5;
280const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29281
dcheng35d31c112015-07-22 00:17:36282static RenderViewImpl* (*g_create_render_view_impl)(
283 CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15284 const mojom::CreateViewParams&) = nullptr;
[email protected]8d41d7612012-11-14 20:32:19285
[email protected]c6bc20332014-02-28 18:30:39286// static
[email protected]e507045d2013-07-24 15:23:44287Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56288 WebFrame* frame,
289 const WebURLRequest& request) {
Blink Reformat1c4d759e2017-04-09 16:34:54290 return Referrer(blink::WebStringToGURL(
291 request.HttpHeaderField(WebString::FromUTF8("Referer"))),
292 request.GetReferrerPolicy());
[email protected]44e55b012013-07-23 14:21:56293}
294
[email protected]c6bc20332014-02-28 18:30:39295// static
[email protected]65920f332014-03-04 21:14:18296WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32297 WebNavigationPolicy policy) {
298 switch (policy) {
Blink Reformat1c4d759e2017-04-09 16:34:54299 case blink::kWebNavigationPolicyIgnore:
nick3b04f322016-08-31 19:29:19300 return WindowOpenDisposition::IGNORE_ACTION;
Blink Reformat1c4d759e2017-04-09 16:34:54301 case blink::kWebNavigationPolicyDownload:
nick3b04f322016-08-31 19:29:19302 return WindowOpenDisposition::SAVE_TO_DISK;
Blink Reformat1c4d759e2017-04-09 16:34:54303 case blink::kWebNavigationPolicyCurrentTab:
nick3b04f322016-08-31 19:29:19304 return WindowOpenDisposition::CURRENT_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54305 case blink::kWebNavigationPolicyNewBackgroundTab:
nick3b04f322016-08-31 19:29:19306 return WindowOpenDisposition::NEW_BACKGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54307 case blink::kWebNavigationPolicyNewForegroundTab:
nick3b04f322016-08-31 19:29:19308 return WindowOpenDisposition::NEW_FOREGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54309 case blink::kWebNavigationPolicyNewWindow:
nick3b04f322016-08-31 19:29:19310 return WindowOpenDisposition::NEW_WINDOW;
Blink Reformat1c4d759e2017-04-09 16:34:54311 case blink::kWebNavigationPolicyNewPopup:
nick3b04f322016-08-31 19:29:19312 return WindowOpenDisposition::NEW_POPUP;
[email protected]48861e22013-01-09 00:27:32313 default:
314 NOTREACHED() << "Unexpected WebNavigationPolicy";
nick3b04f322016-08-31 19:29:19315 return WindowOpenDisposition::IGNORE_ACTION;
[email protected]48861e22013-01-09 00:27:32316 }
317}
318
[email protected]d8221b22013-05-23 05:35:43319// Returns true if the device scale is high enough that losing subpixel
320// antialiasing won't have a noticeable effect on text quality.
321static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
bokane6e68ae2017-03-24 00:54:44322#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
323 // On Android, we never have subpixel antialiasing. On Chrome OS we prefer to
324 // composite all scrollers so that we get animated overlay scrollbars.
[email protected]d8221b22013-05-23 05:35:43325 return true;
326#else
jdduke7d452b4a2015-08-19 21:25:21327 // 1.5 is a common touchscreen tablet device scale factor. For such
328 // devices main thread antialiasing is a heavy burden.
329 return device_scale_factor >= 1.5f;
[email protected]d8221b22013-05-23 05:35:43330#endif
[email protected]d8221b22013-05-23 05:35:43331}
332
danakj6e3bf8012014-12-16 18:27:53333static bool PreferCompositingToLCDText(CompositorDependencies* compositor_deps,
334 float device_scale_factor) {
avi83883c82014-12-23 00:08:49335 const base::CommandLine& command_line =
336 *base::CommandLine::ForCurrentProcess();
[email protected]b8ec1112014-08-17 20:09:10337 if (command_line.HasSwitch(switches::kDisablePreferCompositingToLCDText))
[email protected]fb854192013-02-06 01:30:04338 return false;
[email protected]b8ec1112014-08-17 20:09:10339 if (command_line.HasSwitch(switches::kEnablePreferCompositingToLCDText))
[email protected]fb854192013-02-06 01:30:04340 return true;
danakj6e3bf8012014-12-16 18:27:53341 if (!compositor_deps->IsLcdTextEnabled())
[email protected]10c19732014-08-18 19:39:23342 return true;
[email protected]d8221b22013-05-23 05:35:43343 return DeviceScaleEnsuresTextQuality(device_scale_factor);
344}
345
initial.commit09911bf2008-07-26 23:55:29346///////////////////////////////////////////////////////////////////////////////
347
[email protected]217690d2012-01-27 07:33:11348namespace {
349
[email protected]b3a97b52014-07-09 06:25:05350typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
351 const base::string16&,
352 UScriptCode);
353
354void SetStandardFontFamilyWrapper(WebSettings* settings,
355 const base::string16& font,
356 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54357 settings->SetStandardFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05358}
359
360void SetFixedFontFamilyWrapper(WebSettings* settings,
361 const base::string16& font,
362 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54363 settings->SetFixedFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05364}
365
366void SetSerifFontFamilyWrapper(WebSettings* settings,
367 const base::string16& font,
368 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54369 settings->SetSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05370}
371
372void SetSansSerifFontFamilyWrapper(WebSettings* settings,
373 const base::string16& font,
374 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54375 settings->SetSansSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05376}
377
378void SetCursiveFontFamilyWrapper(WebSettings* settings,
379 const base::string16& font,
380 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54381 settings->SetCursiveFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05382}
383
384void SetFantasyFontFamilyWrapper(WebSettings* settings,
385 const base::string16& font,
386 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54387 settings->SetFantasyFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05388}
389
390void SetPictographFontFamilyWrapper(WebSettings* settings,
391 const base::string16& font,
392 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54393 settings->SetPictographFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05394}
395
396// If |scriptCode| is a member of a family of "similar" script codes, returns
397// the script code in that family that is used by WebKit for font selection
398// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
399// considered equivalent for the purposes of font selection. WebKit uses the
400// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
401// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
402// uses different scripts than the ones in Chrome pref names because the version
403// of ICU included on certain ports does not have some of the newer scripts. If
404// |scriptCode| is not a member of such a family, returns |scriptCode|.
405UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
406 switch (scriptCode) {
407 case USCRIPT_HIRAGANA:
408 case USCRIPT_KATAKANA:
409 case USCRIPT_JAPANESE:
410 return USCRIPT_KATAKANA_OR_HIRAGANA;
411 case USCRIPT_KOREAN:
412 return USCRIPT_HANGUL;
413 default:
414 return scriptCode;
415 }
416}
417
418void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
419 SetFontFamilyWrapper setter,
420 WebSettings* settings) {
421 for (ScriptFontFamilyMap::const_iterator it = map.begin(); it != map.end();
422 ++it) {
avi1023d012015-12-25 02:39:14423 int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
[email protected]b3a97b52014-07-09 06:25:05424 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
425 UScriptCode code = static_cast<UScriptCode>(script);
426 (*setter)(settings, it->second, GetScriptForWebSettings(code));
427 }
428 }
429}
430
wangxianzhu3bf39be52015-04-10 23:56:41431void ApplyBlinkSettings(const base::CommandLine& command_line,
432 WebSettings* settings) {
433 if (!command_line.HasSwitch(switches::kBlinkSettings))
434 return;
435
brettw26dab8f02015-08-08 00:28:47436 std::vector<std::string> blink_settings = base::SplitString(
437 command_line.GetSwitchValueASCII(switches::kBlinkSettings),
438 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
wangxianzhu3bf39be52015-04-10 23:56:41439 for (const std::string& setting : blink_settings) {
440 size_t pos = setting.find('=');
Blink Reformat1c4d759e2017-04-09 16:34:54441 settings->SetFromStrings(
442 blink::WebString::FromLatin1(setting.substr(0, pos)),
443 blink::WebString::FromLatin1(
wangxianzhu3bf39be52015-04-10 23:56:41444 pos == std::string::npos ? "" : setting.substr(pos + 1)));
445 }
446}
447
horodbcbef42016-05-10 17:02:47448WebSettings::V8CacheStrategiesForCacheStorage
449GetV8CacheStrategiesForCacheStorage() {
450 const base::CommandLine& command_line =
451 *base::CommandLine::ForCurrentProcess();
452 std::string v8_cache_strategies = command_line.GetSwitchValueASCII(
453 switches::kV8CacheStrategiesForCacheStorage);
horoe0ff13d2016-05-27 14:47:22454 if (v8_cache_strategies.empty()) {
horodbcbef42016-05-10 17:02:47455 v8_cache_strategies =
456 base::FieldTrialList::FindFullName("V8CacheStrategiesForCacheStorage");
horoe0ff13d2016-05-27 14:47:22457 }
458
459 if (base::StartsWith(v8_cache_strategies, "none",
460 base::CompareCase::SENSITIVE)) {
Blink Reformat1c4d759e2017-04-09 16:34:54461 return WebSettings::V8CacheStrategiesForCacheStorage::kNone;
horoe0ff13d2016-05-27 14:47:22462 } else if (base::StartsWith(v8_cache_strategies, "normal",
463 base::CompareCase::SENSITIVE)) {
Blink Reformat1c4d759e2017-04-09 16:34:54464 return WebSettings::V8CacheStrategiesForCacheStorage::kNormal;
horoe0ff13d2016-05-27 14:47:22465 } else if (base::StartsWith(v8_cache_strategies, "aggressive",
466 base::CompareCase::SENSITIVE)) {
Blink Reformat1c4d759e2017-04-09 16:34:54467 return WebSettings::V8CacheStrategiesForCacheStorage::kAggressive;
horodbcbef42016-05-10 17:02:47468 } else {
Blink Reformat1c4d759e2017-04-09 16:34:54469 return WebSettings::V8CacheStrategiesForCacheStorage::kDefault;
horodbcbef42016-05-10 17:02:47470 }
471}
472
svartmetal751af1f92016-08-13 11:47:33473// This class represents promise which is robust to (will not be broken by)
474// |DidNotSwapReason::SWAP_FAILS| events.
475class AlwaysDrawSwapPromise : public cc::SwapPromise {
476 public:
477 explicit AlwaysDrawSwapPromise(const ui::LatencyInfo& latency_info)
478 : latency_info_(latency_info) {}
479
480 ~AlwaysDrawSwapPromise() override = default;
481
482 void DidActivate() override {}
483
danakj5e0a12b2017-09-25 17:26:49484 void WillSwap(viz::CompositorFrameMetadata* metadata) override {
svartmetal751af1f92016-08-13 11:47:33485 DCHECK(!latency_info_.terminated());
486 metadata->latency_info.push_back(latency_info_);
487 }
488
samanse7345c82016-12-16 02:51:16489 void DidSwap() override {}
490
svartmetal751af1f92016-08-13 11:47:33491 DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override {
492 return reason == DidNotSwapReason::SWAP_FAILS
493 ? DidNotSwapAction::KEEP_ACTIVE
494 : DidNotSwapAction::BREAK_PROMISE;
495 }
496
497 void OnCommit() override {}
498
499 int64_t TraceId() const override { return latency_info_.trace_id(); }
500
501 private:
502 ui::LatencyInfo latency_info_;
503};
504
scottmgde42fb92017-02-10 17:56:03505content::mojom::WindowContainerType WindowFeaturesToContainerType(
scottmg05324cb2017-02-09 23:46:04506 const blink::WebWindowFeatures& window_features) {
japhetbfc47892017-06-02 23:01:19507 if (window_features.background) {
508 if (window_features.persistent)
scottmgde42fb92017-02-10 17:56:03509 return content::mojom::WindowContainerType::PERSISTENT;
scottmg05324cb2017-02-09 23:46:04510 else
scottmgde42fb92017-02-10 17:56:03511 return content::mojom::WindowContainerType::BACKGROUND;
scottmg05324cb2017-02-09 23:46:04512 } else {
scottmgde42fb92017-02-10 17:56:03513 return content::mojom::WindowContainerType::NORMAL;
scottmg05324cb2017-02-09 23:46:04514 }
515}
516
[email protected]217690d2012-01-27 07:33:11517} // namespace
518
dcheng35d31c112015-07-22 00:17:36519RenderViewImpl::RenderViewImpl(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15520 const mojom::CreateViewParams& params)
nick8331f8ad2016-11-15 20:42:45521 : RenderWidget(params.view_id,
522 compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54523 blink::kWebPopupTypeNone,
naskobd911332014-11-25 01:13:36524 params.initial_size.screen_info,
525 params.swapped_out,
526 params.hidden,
527 params.never_visible),
528 webkit_preferences_(params.web_preferences),
avif937e1d2014-11-02 18:13:07529 send_content_state_immediately_(false),
[email protected]3354d3e2010-06-10 19:53:02530 send_preferred_size_changes_(false),
[email protected]e75cb49e2009-01-05 23:13:21531 navigation_gesture_(NavigationGestureUnknown),
[email protected]3cc72b12010-03-18 23:03:00532 history_list_offset_(-1),
533 history_list_length_(0),
[email protected]7e9523b2014-03-25 03:02:42534 frames_in_progress_(0),
[email protected]3354d3e2010-06-10 19:53:02535 target_url_status_(TARGET_NONE),
[email protected]d42bf472014-06-14 01:49:38536 uses_temporary_zoom_level_(false),
[email protected]bbc8856d2013-06-14 10:37:04537#if defined(OS_ANDROID)
mdjones2ee41afd2016-10-27 16:50:20538 top_controls_constraints_(BROWSER_CONTROLS_STATE_BOTH),
[email protected]bbc8856d2013-06-14 10:37:04539#endif
mdjones2ee41afd2016-10-27 16:50:20540 browser_controls_shrink_blink_size_(false),
bokanc63441c2016-04-27 15:49:12541 top_controls_height_(0.f),
Matthew Jones7e156182017-07-21 22:21:33542 bottom_controls_height_(0.f),
lfg4fa48da2016-05-09 18:25:13543 webview_(nullptr),
[email protected]1875bc02014-03-14 06:33:59544 has_scrolled_focused_editable_node_into_rect_(false),
wjmaclean64951902016-04-29 20:59:12545 page_zoom_level_(params.page_zoom_level),
nasko4c0feb62015-06-05 18:37:06546 main_render_frame_(nullptr),
dcheng3ce04b62015-10-26 23:30:55547 frame_widget_(nullptr),
[email protected]64d09222012-05-25 10:10:34548 speech_recognition_dispatcher_(NULL),
[email protected]20657a82012-08-21 20:23:03549#if defined(OS_ANDROID)
nickf7b38222016-11-22 21:59:35550 was_created_by_renderer_(false),
[email protected]a7564272013-04-19 14:24:46551#endif
[email protected]8a67aa352013-02-20 02:58:29552 enumeration_completion_id_(0),
changwand659e202016-06-13 02:39:12553 session_storage_namespace_id_(params.session_storage_namespace_id),
wjmaclean1d970622017-01-21 22:28:24554 weak_ptr_factory_(this) {
avi40b5be7a2016-03-03 21:13:44555 GetWidget()->set_owner_delegate(this);
[email protected]075366912013-02-18 07:13:24556}
557
nickf7b38222016-11-22 21:59:35558void RenderViewImpl::Initialize(
559 const mojom::CreateViewParams& params,
560 const RenderWidget::ShowCallback& show_callback) {
561 bool was_created_by_renderer = !show_callback.is_null();
562#if defined(OS_ANDROID)
563 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated
564 // HandleNavigation codepath.
565 was_created_by_renderer_ = was_created_by_renderer;
566#endif
thestig6057a6b22015-11-12 23:01:33567 display_mode_ = params.initial_size.display_mode;
[email protected]676126f72011-01-15 00:03:51568
Blink Reformat1c4d759e2017-04-09 16:34:54569 webview_ = WebView::Create(this, is_hidden()
570 ? blink::kWebPageVisibilityStateHidden
571 : blink::kWebPageVisibilityStateVisible);
572 RenderWidget::Init(show_callback, webview_->GetWidget());
[email protected]11fee2332011-03-29 20:36:35573
nasko4c0feb62015-06-05 18:37:06574 g_view_map.Get().insert(std::make_pair(webview(), this));
avia3dca182016-03-19 01:09:52575 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this));
nasko4c0feb62015-06-05 18:37:06576
avi83883c82014-12-23 00:08:49577 const base::CommandLine& command_line =
578 *base::CommandLine::ForCurrentProcess();
[email protected]20657a82012-08-21 20:23:03579
[email protected]27c521a2013-05-29 20:44:32580 if (command_line.HasSwitch(switches::kStatsCollectionController))
581 stats_collection_observer_.reset(new StatsCollectionObserver(this));
582
Blink Reformat1c4d759e2017-04-09 16:34:54583 webview()->SetDisplayMode(display_mode_);
584 webview()->GetSettings()->SetPreferCompositingToLCDTextEnabled(
dcheng0ff94cfc2016-03-15 21:50:51585 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_));
Blink Reformat1c4d759e2017-04-09 16:34:54586 webview()->GetSettings()->SetThreadedScrollingEnabled(
dcheng0ff94cfc2016-03-15 21:50:51587 !command_line.HasSwitch(switches::kDisableThreadedScrolling));
Blink Reformat1c4d759e2017-04-09 16:34:54588 webview()->SetShowFPSCounter(
dcheng0ff94cfc2016-03-15 21:50:51589 command_line.HasSwitch(cc::switches::kShowFPSCounter));
590
591 ApplyWebPreferencesInternal(webkit_preferences_, webview(), compositor_deps_);
592
593 if (switches::IsTouchDragDropEnabled())
Blink Reformat1c4d759e2017-04-09 16:34:54594 webview()->GetSettings()->SetTouchDragDropEnabled(true);
dcheng0ff94cfc2016-03-15 21:50:51595
Blink Reformat1c4d759e2017-04-09 16:34:54596 webview()->GetSettings()->SetBrowserSideNavigationEnabled(
arthursonzognic517fc32016-08-11 11:04:24597 IsBrowserSideNavigationEnabled());
598
dcheng0ff94cfc2016-03-15 21:50:51599 WebSettings::SelectionStrategyType selection_strategy =
Blink Reformat1c4d759e2017-04-09 16:34:54600 WebSettings::SelectionStrategyType::kCharacter;
dcheng0ff94cfc2016-03-15 21:50:51601 const std::string selection_strategy_str =
602 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
603 switches::kTouchTextSelectionStrategy);
604 if (selection_strategy_str == "direction")
Blink Reformat1c4d759e2017-04-09 16:34:54605 selection_strategy = WebSettings::SelectionStrategyType::kDirection;
606 webview()->GetSettings()->SetSelectionStrategy(selection_strategy);
dcheng0ff94cfc2016-03-15 21:50:51607
dtapuskaf65650b2016-05-13 17:21:34608 std::string passiveListenersDefault =
609 command_line.GetSwitchValueASCII(switches::kPassiveListenersDefault);
610 if (!passiveListenersDefault.empty()) {
611 WebSettings::PassiveEventListenerDefault passiveDefault =
Blink Reformat1c4d759e2017-04-09 16:34:54612 WebSettings::PassiveEventListenerDefault::kFalse;
dtapuskaacc2fb22016-07-06 23:26:23613 if (passiveListenersDefault == "true")
Blink Reformat1c4d759e2017-04-09 16:34:54614 passiveDefault = WebSettings::PassiveEventListenerDefault::kTrue;
dtapuskaf65650b2016-05-13 17:21:34615 else if (passiveListenersDefault == "forcealltrue")
Blink Reformat1c4d759e2017-04-09 16:34:54616 passiveDefault = WebSettings::PassiveEventListenerDefault::kForceAllTrue;
617 webview()->GetSettings()->SetPassiveEventListenerDefault(passiveDefault);
dtapuskaf65650b2016-05-13 17:21:34618 }
619
Blink Reformat1c4d759e2017-04-09 16:34:54620 ApplyBlinkSettings(command_line, webview()->GetSettings());
dcheng0ff94cfc2016-03-15 21:50:51621
nick3b5a21f2016-11-22 23:07:11622 WebFrame* opener_frame =
623 RenderFrameImpl::ResolveOpener(params.opener_frame_route_id);
624
dchengc5ef1a52015-08-26 20:58:30625 if (params.main_frame_routing_id != MSG_ROUTING_NONE) {
dcheng3ce04b62015-10-26 23:30:55626 main_render_frame_ = RenderFrameImpl::CreateMainFrame(
627 this, params.main_frame_routing_id, params.main_frame_widget_routing_id,
Daniel Chengd5e56ff2017-06-24 07:44:02628 params.hidden, screen_info(), compositor_deps_, opener_frame,
Pavel Feldman25234722017-10-11 02:49:06629 params.devtools_main_frame_token, params.replicated_frame_state);
dchengc5ef1a52015-08-26 20:58:30630 }
631
Daniel Chengd5e56ff2017-06-24 07:44:02632 // TODO(dcheng): Shouldn't these be mutually exclusive at this point? See
633 // https://crbug.com/720116 where the browser is apparently sending both
634 // routing IDs...
nasko4c0feb62015-06-05 18:37:06635 if (params.proxy_routing_id != MSG_ROUTING_NONE) {
636 CHECK(params.swapped_out);
nick3b5a21f2016-11-22 23:07:11637 RenderFrameProxy::CreateFrameProxy(params.proxy_routing_id, GetRoutingID(),
638 opener_frame, MSG_ROUTING_NONE,
639 params.replicated_frame_state);
nasko4c0feb62015-06-05 18:37:06640 }
641
nasko4c0feb62015-06-05 18:37:06642 if (main_render_frame_)
643 main_render_frame_->Initialize();
644
nickf7b38222016-11-22 21:59:35645 // If this RenderView's creation was initiated by an opener page in this
646 // process, (e.g. window.open()), we won't be visible until we ask the opener,
647 // via show_callback, to make us visible. Otherwise, we went through a
648 // browser-initiated creation, and show() won't be called.
649 if (!was_created_by_renderer)
[email protected]676126f72011-01-15 00:03:51650 did_show_ = true;
mfomitchev5ad034ec2015-04-24 21:57:27651
[email protected]c7c0d822014-04-16 20:19:49652 // TODO(davidben): Move this state from Blink into content.
naskobd911332014-11-25 01:13:36653 if (params.window_was_created_with_opener)
Blink Reformat1c4d759e2017-04-09 16:34:54654 webview()->SetOpenedByDOM();
[email protected]c7c0d822014-04-16 20:19:49655
dcheng0ff94cfc2016-03-15 21:50:51656 UpdateWebViewWithDeviceScaleFactor();
naskobd911332014-11-25 01:13:36657 OnSetRendererPrefs(params.renderer_preferences);
[email protected]34c61bd52011-05-02 19:38:33658
naskobd911332014-11-25 01:13:36659 if (!params.enable_auto_resize) {
660 OnResize(params.initial_size);
mkosiba58fa72f02014-11-12 01:21:36661 } else {
naskobd911332014-11-25 01:13:36662 OnEnableAutoResize(params.min_size, params.max_size);
mkosiba58fa72f02014-11-12 01:21:36663 }
664
dtapuska9ec1a912017-04-21 15:18:31665 idle_user_detector_.reset(new IdleUserDetector(this));
[email protected]1784b2f2011-11-24 10:53:48666
[email protected]e9ff79c2012-10-19 21:31:26667 GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44668
wjmaclean64951902016-04-29 20:59:12669 page_zoom_level_ = params.page_zoom_level;
initial.commit09911bf2008-07-26 23:55:29670}
671
[email protected]310ebd6302011-10-10 19:06:28672RenderViewImpl::~RenderViewImpl() {
dcheng3ce04b62015-10-26 23:30:55673 DCHECK(!frame_widget_);
674
Lei Zhang88f23ba2017-10-27 05:56:26675 disambiguation_bitmaps_.clear();
[email protected]91a2aea2013-07-08 23:14:39676
[email protected]8ed1d3f2013-02-20 11:45:55677#if defined(OS_ANDROID)
davve17e025e12016-05-23 15:30:20678 // The date/time picker client is both a std::unique_ptr member of this class
679 // and a RenderViewObserver. Reset it to prevent double deletion.
[email protected]8ed1d3f2013-02-20 11:45:55680 date_time_picker_client_.reset();
681#endif
682
[email protected]60c42a8c72009-10-09 04:08:59683#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22684 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49685 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59686 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
687 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22688 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
689 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
690 it != routing_id_views->end(); ++it)
691 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59692#endif
[email protected]676126f72011-01-15 00:03:51693
dtapuska9ec1a912017-04-21 15:18:31694 idle_user_detector_.reset();
ericwilligers88e69742016-10-17 19:29:55695 for (auto& observer : observers_)
696 observer.RenderViewGone();
697 for (auto& observer : observers_)
698 observer.OnDestruct();
[email protected]60c42a8c72009-10-09 04:08:59699}
700
701/*static*/
[email protected]310ebd6302011-10-10 19:06:28702RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31703 ViewMap* views = g_view_map.Pointer();
704 ViewMap::iterator it = views->find(webview);
705 return it == views->end() ? NULL : it->second;
706}
707
708/*static*/
[email protected]180ef242013-11-07 06:50:46709RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28710 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31711}
712
713/*static*/
avi1023d012015-12-25 02:39:14714RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) {
[email protected]640e303c2012-12-05 01:36:07715 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
716 RoutingIDViewMap::iterator it = views->find(routing_id);
717 return it == views->end() ? NULL : it->second;
718}
719
720/*static*/
721RenderView* RenderView::FromRoutingID(int routing_id) {
722 return RenderViewImpl::FromRoutingID(routing_id);
723}
724
[email protected]f3a95312014-06-12 16:46:58725/* static */
jochen9c7b8f242015-06-01 15:32:02726size_t RenderView::GetRenderViewCount() {
[email protected]f3a95312014-06-12 16:46:58727 return g_view_map.Get().size();
728}
729
[email protected]640e303c2012-12-05 01:36:07730/*static*/
[email protected]e9ff79c2012-10-19 21:31:26731void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49732 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59733 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
734 if (!visitor->Visit(it->second))
735 return;
736 }
737}
738
739/*static*/
[email protected]b3a97b52014-07-09 06:25:05740void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
741 WebView* web_view) {
Blink Reformat1c4d759e2017-04-09 16:34:54742 WebSettings* settings = web_view->GetSettings();
[email protected]b3a97b52014-07-09 06:25:05743 ApplyFontsFromMap(prefs.standard_font_family_map,
744 SetStandardFontFamilyWrapper, settings);
745 ApplyFontsFromMap(prefs.fixed_font_family_map,
746 SetFixedFontFamilyWrapper, settings);
747 ApplyFontsFromMap(prefs.serif_font_family_map,
748 SetSerifFontFamilyWrapper, settings);
749 ApplyFontsFromMap(prefs.sans_serif_font_family_map,
750 SetSansSerifFontFamilyWrapper, settings);
751 ApplyFontsFromMap(prefs.cursive_font_family_map,
752 SetCursiveFontFamilyWrapper, settings);
753 ApplyFontsFromMap(prefs.fantasy_font_family_map,
754 SetFantasyFontFamilyWrapper, settings);
755 ApplyFontsFromMap(prefs.pictograph_font_family_map,
756 SetPictographFontFamilyWrapper, settings);
Blink Reformat1c4d759e2017-04-09 16:34:54757 settings->SetDefaultFontSize(prefs.default_font_size);
758 settings->SetDefaultFixedFontSize(prefs.default_fixed_font_size);
759 settings->SetMinimumFontSize(prefs.minimum_font_size);
760 settings->SetMinimumLogicalFontSize(prefs.minimum_logical_font_size);
761 settings->SetDefaultTextEncodingName(
762 WebString::FromASCII(prefs.default_encoding));
763 settings->SetJavaScriptEnabled(prefs.javascript_enabled);
764 settings->SetWebSecurityEnabled(prefs.web_security_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54765 settings->SetLoadsImagesAutomatically(prefs.loads_images_automatically);
766 settings->SetImagesEnabled(prefs.images_enabled);
767 settings->SetPluginsEnabled(prefs.plugins_enabled);
768 settings->SetEncryptedMediaEnabled(prefs.encrypted_media_enabled);
769 settings->SetDOMPasteAllowed(prefs.dom_paste_enabled);
770 settings->SetTextAreasAreResizable(prefs.text_areas_are_resizable);
771 settings->SetAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
772 settings->SetDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
773 settings->SetJavaScriptCanAccessClipboard(
[email protected]b3a97b52014-07-09 06:25:05774 prefs.javascript_can_access_clipboard);
Blink Reformat1c4d759e2017-04-09 16:34:54775 WebRuntimeFeatures::EnableXSLT(prefs.xslt_enabled);
776 settings->SetXSSAuditorEnabled(prefs.xss_auditor_enabled);
777 settings->SetDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
Tarun Bansal73dd2ff82017-10-03 05:29:34778 settings->SetDataSaverEnabled(
779 prefs.data_saver_enabled &&
780 !base::FeatureList::IsEnabled(features::kDataSaverHoldback));
Blink Reformat1c4d759e2017-04-09 16:34:54781 settings->SetLocalStorageEnabled(prefs.local_storage_enabled);
782 settings->SetSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
783 WebRuntimeFeatures::EnableDatabase(prefs.databases_enabled);
784 settings->SetOfflineWebApplicationCacheEnabled(
[email protected]b3a97b52014-07-09 06:25:05785 prefs.application_cache_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54786 settings->SetHistoryEntryRequiresUserGesture(
japhet5018fe62016-09-14 19:14:04787 prefs.history_entry_requires_user_gesture);
Blink Reformat1c4d759e2017-04-09 16:34:54788 settings->SetHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
789 settings->SetCookieEnabled(prefs.cookie_enabled);
790 settings->SetNavigateOnDragDrop(prefs.navigate_on_drag_drop);
[email protected]b3a97b52014-07-09 06:25:05791
[email protected]b3a97b52014-07-09 06:25:05792 // By default, allow_universal_access_from_file_urls is set to false and thus
793 // we mitigate attacks from local HTML files by not granting file:// URLs
794 // universal access. Only test shell will enable this.
Blink Reformat1c4d759e2017-04-09 16:34:54795 settings->SetAllowUniversalAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05796 prefs.allow_universal_access_from_file_urls);
Blink Reformat1c4d759e2017-04-09 16:34:54797 settings->SetAllowFileAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05798 prefs.allow_file_access_from_file_urls);
799
Zhenyao Moa3fda9972017-09-16 01:34:40800 settings->SetWebGL1Enabled(prefs.webgl1_enabled);
801 settings->SetWebGL2Enabled(prefs.webgl2_enabled);
[email protected]b3a97b52014-07-09 06:25:05802
[email protected]b3a97b52014-07-09 06:25:05803 // Enable WebGL errors to the JS console if requested.
Blink Reformat1c4d759e2017-04-09 16:34:54804 settings->SetWebGLErrorsToConsoleEnabled(
[email protected]b3a97b52014-07-09 06:25:05805 prefs.webgl_errors_to_console_enabled);
806
807 // Uses the mock theme engine for scrollbars.
Blink Reformat1c4d759e2017-04-09 16:34:54808 settings->SetMockScrollbarsEnabled(prefs.mock_scrollbars_enabled);
[email protected]b3a97b52014-07-09 06:25:05809
Blink Reformat1c4d759e2017-04-09 16:34:54810 settings->SetHideScrollbars(prefs.hide_scrollbars);
eseckler61ff9142016-09-23 22:57:59811
[email protected]b3a97b52014-07-09 06:25:05812 // Enable gpu-accelerated 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54813 WebRuntimeFeatures::EnableAccelerated2dCanvas(
junov524668f22016-08-08 20:16:52814 prefs.accelerated_2d_canvas_enabled);
[email protected]b3a97b52014-07-09 06:25:05815
Blink Reformat1c4d759e2017-04-09 16:34:54816 settings->SetMinimumAccelerated2dCanvasSize(
[email protected]b3a97b52014-07-09 06:25:05817 prefs.minimum_accelerated_2d_canvas_size);
818
819 // Disable antialiasing for 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54820 settings->SetAntialiased2dCanvasEnabled(
[email protected]b3a97b52014-07-09 06:25:05821 !prefs.antialiased_2d_canvas_disabled);
822
zakerinasab20ebca02016-09-27 14:22:34823 // Disable antialiasing of clips for 2d canvas if requested on the command
robertphillipse25137b2014-10-20 13:44:34824 // line.
Blink Reformat1c4d759e2017-04-09 16:34:54825 settings->SetAntialiasedClips2dCanvasEnabled(
robertphillipse25137b2014-10-20 13:44:34826 prefs.antialiased_clips_2d_canvas_enabled);
827
[email protected]b3a97b52014-07-09 06:25:05828 // Set MSAA sample count for 2d canvas if requested on the command line (or
829 // default value if not).
Blink Reformat1c4d759e2017-04-09 16:34:54830 settings->SetAccelerated2dCanvasMSAASampleCount(
[email protected]b3a97b52014-07-09 06:25:05831 prefs.accelerated_2d_canvas_msaa_sample_count);
832
[email protected]b3a97b52014-07-09 06:25:05833 // Tabs to link is not part of the settings. WebCore calls
834 // ChromeClient::tabsToLinks which is part of the glue code.
Blink Reformat1c4d759e2017-04-09 16:34:54835 web_view->SetTabsToLinks(prefs.tabs_to_links);
[email protected]b3a97b52014-07-09 06:25:05836
Blink Reformat1c4d759e2017-04-09 16:34:54837 settings->SetAllowRunningOfInsecureContent(
[email protected]b3a97b52014-07-09 06:25:05838 prefs.allow_running_insecure_content);
Blink Reformat1c4d759e2017-04-09 16:34:54839 settings->SetDisableReadingFromCanvas(prefs.disable_reading_from_canvas);
840 settings->SetStrictMixedContentChecking(prefs.strict_mixed_content_checking);
mkwst2384c8222015-07-30 07:26:47841
Blink Reformat1c4d759e2017-04-09 16:34:54842 settings->SetStrictlyBlockBlockableMixedContent(
mkwst2384c8222015-07-30 07:26:47843 prefs.strictly_block_blockable_mixed_content);
844
Blink Reformat1c4d759e2017-04-09 16:34:54845 settings->SetStrictMixedContentCheckingForPlugin(
mkwst0d233e52015-08-10 09:33:14846 prefs.block_mixed_plugin_content);
847
Blink Reformat1c4d759e2017-04-09 16:34:54848 settings->SetStrictPowerfulFeatureRestrictions(
mkwst673a452f2015-01-10 14:41:50849 prefs.strict_powerful_feature_restrictions);
Blink Reformat1c4d759e2017-04-09 16:34:54850 settings->SetAllowGeolocationOnInsecureOrigins(
jww9d4ca2d2016-01-19 20:58:59851 prefs.allow_geolocation_on_insecure_origins);
Blink Reformat1c4d759e2017-04-09 16:34:54852 settings->SetPasswordEchoEnabled(prefs.password_echo_enabled);
853 settings->SetShouldPrintBackgrounds(prefs.should_print_backgrounds);
854 settings->SetShouldClearDocumentBackground(
[email protected]b3a97b52014-07-09 06:25:05855 prefs.should_clear_document_background);
Blink Reformat1c4d759e2017-04-09 16:34:54856 settings->SetEnableScrollAnimator(prefs.enable_scroll_animator);
[email protected]b3a97b52014-07-09 06:25:05857
Blink Reformat1c4d759e2017-04-09 16:34:54858 WebRuntimeFeatures::EnableTouchEventFeatureDetection(
sunyunjiafa6a8afc2016-12-09 04:25:47859 prefs.touch_event_feature_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54860 settings->SetMaxTouchPoints(prefs.pointer_events_max_touch_points);
861 settings->SetAvailablePointerTypes(prefs.available_pointer_types);
862 settings->SetPrimaryPointerType(
nzolghadrc0d1663c2015-11-26 21:15:24863 static_cast<blink::PointerType>(prefs.primary_pointer_type));
Blink Reformat1c4d759e2017-04-09 16:34:54864 settings->SetAvailableHoverTypes(prefs.available_hover_types);
865 settings->SetPrimaryHoverType(
nzolghadrc0d1663c2015-11-26 21:15:24866 static_cast<blink::HoverType>(prefs.primary_hover_type));
Blink Reformat1c4d759e2017-04-09 16:34:54867 settings->SetEnableTouchAdjustment(prefs.touch_adjustment_enabled);
Dave Tapuskaa59fdb62017-08-23 16:28:27868 settings->SetBarrelButtonForDragEnabled(prefs.barrel_button_for_drag_enabled);
[email protected]b3a97b52014-07-09 06:25:05869
Blink Reformat1c4d759e2017-04-09 16:34:54870 settings->SetShouldRespectImageOrientation(
[email protected]b3a97b52014-07-09 06:25:05871 prefs.should_respect_image_orientation);
872
Blink Reformat1c4d759e2017-04-09 16:34:54873 settings->SetEditingBehavior(
[email protected]b3a97b52014-07-09 06:25:05874 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
875
Blink Reformat1c4d759e2017-04-09 16:34:54876 settings->SetSupportsMultipleWindows(prefs.supports_multiple_windows);
[email protected]b3a97b52014-07-09 06:25:05877
Blink Reformat1c4d759e2017-04-09 16:34:54878 settings->SetMainFrameClipsContent(!prefs.record_whole_document);
khushalsagar2da2b232016-03-23 22:11:35879
Blink Reformat1c4d759e2017-04-09 16:34:54880 settings->SetSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
[email protected]b3a97b52014-07-09 06:25:05881
Blink Reformat1c4d759e2017-04-09 16:34:54882 settings->SetSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
[email protected]b3a97b52014-07-09 06:25:05883
Blink Reformat1c4d759e2017-04-09 16:34:54884 settings->SetSelectionIncludesAltImageText(true);
[email protected]b3a97b52014-07-09 06:25:05885
Blink Reformat1c4d759e2017-04-09 16:34:54886 settings->SetV8CacheOptions(
[email protected]35103c02014-08-12 15:08:47887 static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options));
888
Blink Reformat1c4d759e2017-04-09 16:34:54889 settings->SetV8CacheStrategiesForCacheStorage(
horodbcbef42016-05-10 17:02:47890 GetV8CacheStrategiesForCacheStorage());
891
Blink Reformat1c4d759e2017-04-09 16:34:54892 settings->SetImageAnimationPolicy(
je_julie.kim7fbb5a1a2015-02-09 17:26:05893 static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy));
894
Blink Reformat1c4d759e2017-04-09 16:34:54895 settings->SetPresentationRequiresUserGesture(
zqzhang1215ad422016-02-10 13:27:22896 prefs.user_gesture_required_for_presentation);
897
Blink Reformat1c4d759e2017-04-09 16:34:54898 settings->SetTextTrackMarginPercentage(prefs.text_track_margin_percentage);
halliwell4002be42016-03-18 18:33:40899
dcheng5ae8ca362015-02-05 04:03:47900 // Needs to happen before setIgnoreVIewportTagScaleLimits below.
Blink Reformat1c4d759e2017-04-09 16:34:54901 web_view->SetDefaultPageScaleLimits(prefs.default_minimum_page_scale_factor,
902 prefs.default_maximum_page_scale_factor);
dcheng5ae8ca362015-02-05 04:03:47903
Nate Chapin9638e7102017-09-20 22:11:01904 settings->SetSavePreviousDocumentResources(
905 static_cast<WebSettings::SavePreviousDocumentResources>(
906 prefs.save_previous_document_resources));
907
[email protected]b3a97b52014-07-09 06:25:05908#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:54909 settings->SetAllowCustomScrollbarInMainFrame(false);
910 settings->SetTextAutosizingEnabled(prefs.text_autosizing_enabled);
911 settings->SetAccessibilityFontScaleFactor(prefs.font_scale_factor);
912 settings->SetDeviceScaleAdjustment(prefs.device_scale_adjustment);
913 settings->SetFullscreenSupported(prefs.fullscreen_supported);
914 web_view->SetIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
915 settings->SetAutoZoomFocusedNodeToLegibleScale(true);
916 settings->SetDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54917 settings->SetMediaPlaybackGestureWhitelistScope(
918 blink::WebString::FromUTF8(prefs.media_playback_gesture_whitelist_scope));
919 settings->SetDefaultVideoPosterURL(
920 WebString::FromASCII(prefs.default_video_poster_url.spec()));
921 settings->SetSupportDeprecatedTargetDensityDPI(
[email protected]b3a97b52014-07-09 06:25:05922 prefs.support_deprecated_target_density_dpi);
Blink Reformat1c4d759e2017-04-09 16:34:54923 settings->SetUseLegacyBackgroundSizeShorthandBehavior(
[email protected]b3a97b52014-07-09 06:25:05924 prefs.use_legacy_background_size_shorthand_behavior);
Blink Reformat1c4d759e2017-04-09 16:34:54925 settings->SetWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
926 settings->SetUseWideViewport(prefs.use_wide_viewport);
927 settings->SetForceZeroLayoutHeight(prefs.force_zero_layout_height);
928 settings->SetViewportMetaLayoutSizeQuirk(
[email protected]b3a97b52014-07-09 06:25:05929 prefs.viewport_meta_layout_size_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54930 settings->SetViewportMetaMergeContentQuirk(
[email protected]b3a97b52014-07-09 06:25:05931 prefs.viewport_meta_merge_content_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54932 settings->SetViewportMetaNonUserScalableQuirk(
[email protected]b3a97b52014-07-09 06:25:05933 prefs.viewport_meta_non_user_scalable_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54934 settings->SetViewportMetaZeroValuesQuirk(
[email protected]b3a97b52014-07-09 06:25:05935 prefs.viewport_meta_zero_values_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54936 settings->SetClobberUserAgentInitialScaleQuirk(
[email protected]b3a97b52014-07-09 06:25:05937 prefs.clobber_user_agent_initial_scale_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54938 settings->SetIgnoreMainFrameOverflowHiddenQuirk(
[email protected]b3a97b52014-07-09 06:25:05939 prefs.ignore_main_frame_overflow_hidden_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54940 settings->SetReportScreenSizeInPhysicalPixelsQuirk(
[email protected]b3a97b52014-07-09 06:25:05941 prefs.report_screen_size_in_physical_pixels_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54942 settings->SetShouldReuseGlobalForUnownedMainFrame(
boliu1a00f262016-04-06 19:08:46943 prefs.resue_global_for_unowned_main_frame);
Blink Reformat1c4d759e2017-04-09 16:34:54944 settings->SetProgressBarCompletion(
japhet98e9bd82016-06-28 23:48:45945 static_cast<WebSettings::ProgressBarCompletion>(
946 prefs.progress_bar_completion));
Blink Reformat1c4d759e2017-04-09 16:34:54947 settings->SetPreferHiddenVolumeControls(true);
948 settings->SetSpellCheckEnabledByDefault(prefs.spellcheck_enabled_by_default);
dalecurtiscd971252016-09-21 16:09:00949
aeliase678aa42017-04-14 22:41:04950 // Force preload=none and disable autoplay on older Android
dalecurtiscd971252016-09-21 16:09:00951 // platforms because their media pipelines are not stable enough to handle
952 // concurrent elements. See http://crbug.com/612909, http://crbug.com/622826.
aeliase678aa42017-04-14 22:41:04953 const bool is_jelly_bean =
dalecurtiscd971252016-09-21 16:09:00954 base::android::BuildInfo::GetInstance()->sdk_int() <=
aeliase678aa42017-04-14 22:41:04955 base::android::SDK_VERSION_JELLY_BEAN_MR2;
956 settings->SetForcePreloadNoneForMediaElements(is_jelly_bean);
mlamouri1d266bf2016-12-05 17:42:36957
Blink Reformat1c4d759e2017-04-09 16:34:54958 WebRuntimeFeatures::EnableVideoFullscreenOrientationLock(
mlamouri1d266bf2016-12-05 17:42:36959 prefs.video_fullscreen_orientation_lock_enabled);
johnme913ee5f2017-04-28 21:36:16960 WebRuntimeFeatures::EnableVideoRotateToFullscreen(
961 prefs.video_rotate_to_fullscreen_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54962 WebRuntimeFeatures::EnableVideoFullscreenDetection(
zqzhang93e959d12017-03-16 13:10:20963 prefs.video_fullscreen_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54964 settings->SetEmbeddedMediaExperienceEnabled(
shaktisahuf97f7532017-02-24 22:46:13965 prefs.embedded_media_experience_enabled);
vollick8921b242017-05-25 02:48:15966 settings->SetPagePopupsSuppressed(prefs.page_popups_suppressed);
khushalsagarc5447db22017-08-22 17:53:01967 settings->SetMediaDownloadInProductHelpEnabled(
968 prefs.enable_media_download_in_product_help);
Blink Reformat1c4d759e2017-04-09 16:34:54969 settings->SetDoNotUpdateSelectionOnMutatingSelectionRange(
changwane54ccdb92017-04-05 19:20:54970 prefs.do_not_update_selection_on_mutating_selection_range);
Noel Gordonf311a842017-07-27 00:10:07971 WebRuntimeFeatures::EnableCSSHexAlphaColor(prefs.css_hex_alpha_color_enabled);
Tobias Sargeant416174f2017-09-01 01:18:09972 WebRuntimeFeatures::EnableScrollTopLeftInterop(
973 prefs.scroll_top_left_interop_enabled);
zqzhangdf72ed082016-12-08 16:07:55974#endif // defined(OS_ANDROID)
liberato9e934892016-05-03 19:00:27975
mlamouri55a0543c2017-05-11 10:34:07976 switch (prefs.autoplay_policy) {
977 case AutoplayPolicy::kNoUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28978 settings->SetAutoplayPolicy(
979 WebSettings::AutoplayPolicy::kNoUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07980 break;
981 case AutoplayPolicy::kUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28982 settings->SetAutoplayPolicy(
983 WebSettings::AutoplayPolicy::kUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07984 break;
985 case AutoplayPolicy::kUserGestureRequiredForCrossOrigin:
mlamouri276a6f32017-05-12 09:24:28986 settings->SetAutoplayPolicy(
987 WebSettings::AutoplayPolicy::kUserGestureRequiredForCrossOrigin);
mlamouri55a0543c2017-05-11 10:34:07988 break;
mlamouri431bb4e2017-06-06 08:54:24989 case AutoplayPolicy::kDocumentUserActivationRequired:
990 settings->SetAutoplayPolicy(
991 WebSettings::AutoplayPolicy::kDocumentUserActivationRequired);
992 break;
mlamouri55a0543c2017-05-11 10:34:07993 }
994
Blink Reformat1c4d759e2017-04-09 16:34:54995 settings->SetViewportEnabled(prefs.viewport_enabled);
996 settings->SetViewportMetaEnabled(prefs.viewport_meta_enabled);
997 settings->SetShrinksViewportContentToFit(
998 prefs.shrinks_viewport_contents_to_fit);
999 settings->SetViewportStyle(
alokp5d566962016-04-19 00:54:161000 static_cast<blink::WebViewportStyle>(prefs.viewport_style));
1001
Blink Reformat1c4d759e2017-04-09 16:34:541002 settings->SetLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
1003 settings->SetMainFrameResizesAreOrientationChanges(
yoava1a508b42015-10-20 12:03:211004 prefs.main_frame_resizes_are_orientation_changes);
1005
Blink Reformat1c4d759e2017-04-09 16:34:541006 settings->SetUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
jinho.bang8f11ffa2014-12-04 06:03:031007
Blink Reformat1c4d759e2017-04-09 16:34:541008 settings->SetShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up);
1009 settings->SetAlwaysShowContextMenuOnTouch(
amaralp547e4192016-06-03 19:17:351010 prefs.always_show_context_menu_on_touch);
ccameron2fd70de72015-02-19 00:40:401011
Blink Reformat1c4d759e2017-04-09 16:34:541012 settings->SetHideDownloadUI(prefs.hide_download_ui);
1013 WebRuntimeFeatures::EnableBackgroundVideoTrackOptimization(
avayvod39c102402016-11-23 21:43:131014 prefs.background_video_track_optimization_enabled);
avayvod232757942017-04-29 04:12:341015 WebRuntimeFeatures::EnableNewRemotePlaybackPipeline(
1016 base::FeatureList::IsEnabled(media::kNewRemotePlaybackPipeline));
qinmin72e8bd02016-10-21 19:35:371017
Blink Reformat1c4d759e2017-04-09 16:34:541018 settings->SetPresentationReceiver(prefs.presentation_receiver);
mlamouri57359d912016-11-29 20:11:501019
Blink Reformat1c4d759e2017-04-09 16:34:541020 settings->SetMediaControlsEnabled(prefs.media_controls_enabled);
mlamouri5cd9ae82017-02-18 11:05:091021
ccameron2fd70de72015-02-19 00:40:401022#if defined(OS_MACOSX)
Blink Reformat1c4d759e2017-04-09 16:34:541023 settings->SetDoubleTapToZoomEnabled(true);
1024 web_view->SetMaximumLegibleScale(prefs.default_maximum_page_scale_factor);
ccameron2fd70de72015-02-19 00:40:401025#endif
sunyunjia87f287b2016-09-09 00:38:131026
1027#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:541028 WebRuntimeFeatures::EnableMiddleClickAutoscroll(true);
sunyunjia87f287b2016-09-09 00:38:131029#endif
[email protected]b3a97b52014-07-09 06:25:051030}
1031
1032/*static*/
nickf7b38222016-11-22 21:59:351033RenderViewImpl* RenderViewImpl::Create(
1034 CompositorDependencies* compositor_deps,
1035 const mojom::CreateViewParams& params,
1036 const RenderWidget::ShowCallback& show_callback) {
naskobd911332014-11-25 01:13:361037 DCHECK(params.view_id != MSG_ROUTING_NONE);
Lei Zhang88f23ba2017-10-27 05:56:261038 RenderViewImpl* render_view;
[email protected]8d41d7612012-11-14 20:32:191039 if (g_create_render_view_impl)
dcheng35d31c112015-07-22 00:17:361040 render_view = g_create_render_view_impl(compositor_deps, params);
[email protected]075366912013-02-18 07:13:241041 else
dcheng35d31c112015-07-22 00:17:361042 render_view = new RenderViewImpl(compositor_deps, params);
[email protected]0287e762014-04-11 13:07:581043
nickf7b38222016-11-22 21:59:351044 render_view->Initialize(params, show_callback);
[email protected]075366912013-02-18 07:13:241045 return render_view;
[email protected]8d41d7612012-11-14 20:32:191046}
1047
1048// static
dcheng35d31c112015-07-22 00:17:361049void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
1050 *create_render_view_impl)(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:151051 const mojom::CreateViewParams&)) {
[email protected]8d41d7612012-11-14 20:32:191052 CHECK(!g_create_render_view_impl);
1053 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291054}
1055
[email protected]310ebd6302011-10-10 19:06:281056void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511057 observers_.AddObserver(observer);
1058}
1059
[email protected]310ebd6302011-10-10 19:06:281060void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1061 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511062 observers_.RemoveObserver(observer);
1063}
1064
[email protected]180ef242013-11-07 06:50:461065blink::WebView* RenderViewImpl::webview() const {
lfg4fa48da2016-05-09 18:25:131066 return webview_;
[email protected]4d51d5bf2010-07-26 18:48:261067}
1068
brettw4b461082016-11-19 18:55:161069#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:571070
[email protected]784ea1ab2010-09-18 00:02:341071#if defined(OS_MACOSX)
[email protected]7411a3c2014-08-15 05:20:191072void RenderViewImpl::OnGetRenderedText() {
1073 if (!webview())
1074 return;
dglazkov03223492016-02-08 22:16:031075
Blink Reformat1c4d759e2017-04-09 16:34:541076 if (!webview()->MainFrame()->IsWebLocalFrame())
dglazkov03223492016-02-08 22:16:031077 return;
1078
[email protected]7411a3c2014-08-15 05:20:191079 // Get rendered text from WebLocalFrame.
1080 // TODO: Currently IPC truncates any data that has a
1081 // size > kMaximumMessageSize. May be split the text into smaller chunks and
1082 // send back using multiple IPC. See http://crbug.com/393444.
1083 static const size_t kMaximumMessageSize = 8 * 1024 * 1024;
dglazkov03223492016-02-08 22:16:031084 // TODO(dglazkov): Using this API is wrong. It's not OOPIF-compatible and
1085 // sends text in the wrong order. See http://crbug.com/584798.
1086 // TODO(dglazkov): WebFrameContentDumper should only be used for
1087 // testing purposes. See http://crbug.com/585164.
1088 std::string text =
Blink Reformat1c4d759e2017-04-09 16:34:541089 WebFrameContentDumper::DumpWebViewAsText(webview(), kMaximumMessageSize)
1090 .Utf8();
[email protected]7411a3c2014-08-15 05:20:191091
avia3dca182016-03-19 01:09:521092 Send(new ViewMsg_GetRenderedTextCompleted(GetRoutingID(), text));
[email protected]7411a3c2014-08-15 05:20:191093}
[email protected]a80af12e2013-08-07 23:36:131094#endif // defined(OS_MACOSX)
1095
1096#endif // ENABLE_PLUGINS
1097
fsamuel72464894f2015-12-15 06:59:311098// RenderWidgetInputHandlerDelegate -----------------------------------------
1099
avid7d6b2e2016-03-04 19:41:171100bool RenderViewImpl::DoesRenderWidgetHaveTouchEventHandlersAt(
1101 const gfx::Point& point) const {
fsamuel72464894f2015-12-15 06:59:311102 if (!webview())
1103 return false;
Blink Reformat1c4d759e2017-04-09 16:34:541104 return webview()->HasTouchEventHandlersAt(point);
fsamuel72464894f2015-12-15 06:59:311105}
1106
avid7d6b2e2016-03-04 19:41:171107bool RenderViewImpl::RenderWidgetWillHandleMouseEvent(
1108 const blink::WebMouseEvent& event) {
fsamuel72464894f2015-12-15 06:59:311109 // If the mouse is locked, only the current owner of the mouse lock can
1110 // process mouse events.
1111 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
1112}
1113
1114// IPC::Listener implementation ----------------------------------------------
1115
[email protected]310ebd6302011-10-10 19:06:281116bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
Blink Reformat1c4d759e2017-04-09 16:34:541117 WebFrame* main_frame = webview() ? webview()->MainFrame() : NULL;
1118 if (main_frame && main_frame->IsWebLocalFrame())
lukaszabedb4b22017-06-23 00:00:131119 GetContentClient()->SetActiveURL(
1120 main_frame->ToWebLocalFrame()->GetDocument().Url());
[email protected]f8b6b6f2009-03-10 16:48:261121
naskoc6edf7e2015-10-16 01:48:451122 // Input IPC messages must not be processed if the RenderView is in
1123 // swapped out state.
dtapuska1b0fcc322016-10-28 18:08:281124 if (is_swapped_out_ &&
1125 IPC_MESSAGE_ID_CLASS(message.type()) == InputMsgStart) {
dtapuska1b0fcc322016-10-28 18:08:281126 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
1127 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnDiscardInputEvent)
1128 IPC_END_MESSAGE_MAP()
naskoc6edf7e2015-10-16 01:48:451129 return false;
dtapuska1b0fcc322016-10-28 18:08:281130 }
naskoc6edf7e2015-10-16 01:48:451131
dchenga2d442c22016-10-13 15:39:211132 for (auto& observer : observers_) {
1133 if (observer.OnMessageReceived(message))
[email protected]676126f72011-01-15 00:03:511134 return true;
dchenga2d442c22016-10-13 15:39:211135 }
[email protected]b2abac72009-02-26 12:39:281136
[email protected]a95986a82010-12-24 06:19:281137 bool handled = true;
[email protected]e44d1342014-05-16 21:29:331138 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
mcnee432e47d2015-11-09 19:37:461139 IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale)
initial.commit09911bf2008-07-26 23:55:291140 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291141 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1142 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]600ea402011-04-12 00:01:511143 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
1144 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:291145 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
[email protected]30f75e62009-02-25 22:01:001146 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]61f91832014-05-13 01:24:421147 IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque, OnSetBackgroundOpaque)
[email protected]ab32b16c2009-10-16 14:57:251148 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1149 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:471150 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:341151 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:101152 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1153 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511154 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:561155 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:361156 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:341157 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]cb189e062014-04-23 00:57:011158 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupBitmap,
1159 OnReleaseDisambiguationPopupBitmap)
aelias1b55156e52017-04-01 00:46:051160 IPC_MESSAGE_HANDLER(ViewMsg_ResolveTapDisambiguation,
1161 OnResolveTapDisambiguation)
[email protected]506563d2014-06-23 12:22:411162 IPC_MESSAGE_HANDLER(ViewMsg_ForceRedraw, OnForceRedraw)
[email protected]4dda6a6c2014-05-17 15:35:041163 IPC_MESSAGE_HANDLER(ViewMsg_SelectWordAroundCaret, OnSelectWordAroundCaret)
wjmaclean64951902016-04-29 20:59:121164
1165 // Page messages.
lfgdb5c4ed2016-03-04 23:09:071166 IPC_MESSAGE_HANDLER(PageMsg_UpdateWindowScreenRect,
1167 OnUpdateWindowScreenRect)
wjmaclean64951902016-04-29 20:59:121168 IPC_MESSAGE_HANDLER(PageMsg_SetZoomLevel, OnSetZoomLevel)
lfg717154072016-06-30 15:04:161169 IPC_MESSAGE_HANDLER(PageMsg_WasHidden, OnPageWasHidden)
1170 IPC_MESSAGE_HANDLER(PageMsg_WasShown, OnPageWasShown)
alexmos136fd6e62016-08-15 20:58:411171 IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength,
1172 OnSetHistoryOffsetAndLength)
altimind8bd26c2016-11-04 11:44:541173 IPC_MESSAGE_HANDLER(PageMsg_AudioStateChanged, OnAudioStateChanged)
lfg8d649cc2017-04-28 18:04:301174 IPC_MESSAGE_HANDLER(PageMsg_UpdateScreenInfo, OnUpdateScreenInfo)
lfg717154072016-06-30 15:04:161175
[email protected]55750b32012-09-21 14:05:031176#if defined(OS_ANDROID)
mdjones2ee41afd2016-10-27 16:50:201177 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserControlsState,
1178 OnUpdateBrowserControlsState)
[email protected]55750b32012-09-21 14:05:031179#elif defined(OS_MACOSX)
[email protected]7411a3c2014-08-15 05:20:191180 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedText,
1181 OnGetRenderedText)
naskoc288745f2015-05-01 22:54:211182 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]55750b32012-09-21 14:05:031183#endif
[email protected]a794f3a2013-10-30 17:00:321184 // Adding a new message? Add platform independent ones first, then put the
1185 // platform specific ones at the end.
[email protected]9e1ad4b2011-08-14 16:49:191186
initial.commit09911bf2008-07-26 23:55:291187 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281188 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291189 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401190
[email protected]a95986a82010-12-24 06:19:281191 return handled;
initial.commit09911bf2008-07-26 23:55:291192}
1193
[email protected]4dda6a6c2014-05-17 15:35:041194void RenderViewImpl::OnSelectWordAroundCaret() {
donnd701cc202017-05-17 23:11:201195 // Set default values for the ACK
1196 bool did_select = false;
1197 int start_adjust = 0;
1198 int end_adjust = 0;
[email protected]4dda6a6c2014-05-17 15:35:041199
donnd701cc202017-05-17 23:11:201200 if (webview()) {
1201 WebLocalFrame* focused_frame = GetWebView()->FocusedFrame();
1202 if (focused_frame) {
1203 input_handler_->set_handling_input_event(true);
1204 blink::WebRange initial_range = focused_frame->SelectionRange();
donndbde109ff2017-05-26 20:20:011205 if (!initial_range.IsNull())
1206 did_select = focused_frame->SelectWordAroundCaret();
donnd701cc202017-05-17 23:11:201207 if (did_select) {
1208 blink::WebRange adjusted_range = focused_frame->SelectionRange();
1209 start_adjust =
1210 adjusted_range.StartOffset() - initial_range.StartOffset();
1211 end_adjust = adjusted_range.EndOffset() - initial_range.EndOffset();
1212 }
1213 input_handler_->set_handling_input_event(false);
1214 }
1215 }
1216 Send(new ViewHostMsg_SelectWordAroundCaretAck(GetRoutingID(), did_select,
1217 start_adjust, end_adjust));
[email protected]4dda6a6c2014-05-17 15:35:041218}
1219
[email protected]310ebd6302011-10-10 19:06:281220void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291221 // Check if there is a targeturl waiting to be sent.
avi450ce00e2014-09-24 01:58:521222 if (target_url_status_ == TARGET_PENDING)
avia3dca182016-03-19 01:09:521223 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), pending_target_url_));
initial.commit09911bf2008-07-26 23:55:291224
1225 target_url_status_ = TARGET_NONE;
1226}
1227
Dave Tapuskab336b922017-07-06 19:24:051228void RenderViewImpl::ScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect) {
ekaramad27ca69b12017-04-20 18:34:291229 blink::WebAutofillClient* autofill_client = nullptr;
1230 if (auto* focused_frame = GetWebView()->FocusedFrame())
1231 autofill_client = focused_frame->AutofillClient();
1232
[email protected]1875bc02014-03-14 06:33:591233 if (has_scrolled_focused_editable_node_into_rect_ &&
ekaramad27ca69b12017-04-20 18:34:291234 rect == rect_for_scrolled_focused_editable_node_ && autofill_client) {
1235 autofill_client->DidCompleteFocusChangeInFrame();
[email protected]1875bc02014-03-14 06:33:591236 return;
1237 }
1238
Blink Reformat1c4d759e2017-04-09 16:34:541239 if (!webview()->ScrollFocusedEditableElementIntoRect(rect))
dglazkov4969a3e2016-05-20 21:13:511240 return;
rouslanf7ebd8832015-01-22 01:54:141241
dglazkov4969a3e2016-05-20 21:13:511242 rect_for_scrolled_focused_editable_node_ = rect;
1243 has_scrolled_focused_editable_node_into_rect_ = true;
ekaramad27ca69b12017-04-20 18:34:291244 if (!compositor()->HasPendingPageScaleAnimation() && autofill_client)
1245 autofill_client->DidCompleteFocusChangeInFrame();
[email protected]25bcc8f2013-01-09 02:49:251246}
1247
avi2b177592014-12-10 02:08:021248void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset,
1249 int history_length) {
1250 DCHECK_GE(history_offset, -1);
[email protected]e1ed5a12012-08-08 19:57:441251 DCHECK_GE(history_length, 0);
[email protected]9e1ad4b2011-08-14 16:49:191252
avi2b177592014-12-10 02:08:021253 history_list_offset_ = history_offset;
1254 history_list_length_ = history_length;
[email protected]9e1ad4b2011-08-14 16:49:191255}
1256
[email protected]310ebd6302011-10-10 19:06:281257void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291258 if (!webview())
1259 return;
Blink Reformat1c4d759e2017-04-09 16:34:541260 webview()->SetInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291261}
1262
lfgdb5c4ed2016-03-04 23:09:071263void RenderViewImpl::OnUpdateWindowScreenRect(gfx::Rect window_screen_rect) {
1264 RenderWidget::OnUpdateWindowScreenRect(window_screen_rect);
1265}
1266
altimind8bd26c2016-11-04 11:44:541267void RenderViewImpl::OnAudioStateChanged(bool is_audio_playing) {
Blink Reformat1c4d759e2017-04-09 16:34:541268 webview()->AudioStateChanged(is_audio_playing);
altimind8bd26c2016-11-04 11:44:541269}
1270
initial.commit09911bf2008-07-26 23:55:291271///////////////////////////////////////////////////////////////////////////////
1272
nickf7b38222016-11-22 21:59:351273void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget,
1274 WebNavigationPolicy policy,
1275 const gfx::Rect& initial_rect) {
1276 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(),
1277 initial_rect));
1278}
1279
1280void RenderViewImpl::ShowCreatedFullscreenWidget(
1281 RenderWidget* fullscreen_widget,
1282 WebNavigationPolicy policy,
1283 const gfx::Rect& initial_rect) {
1284 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(),
1285 fullscreen_widget->routing_id()));
1286}
1287
creis69b184a472015-11-26 05:29:511288void RenderViewImpl::SendFrameStateUpdates() {
creis69b184a472015-11-26 05:29:511289 // Tell each frame with pending state to send its UpdateState message.
1290 for (int render_frame_routing_id : frames_with_pending_state_) {
1291 RenderFrameImpl* frame =
1292 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
1293 if (frame)
1294 frame->SendUpdateState();
1295 }
1296 frames_with_pending_state_.clear();
1297}
1298
sataya.mf405d0e2015-07-07 16:51:111299void RenderViewImpl::ApplyWebPreferencesInternal(
1300 const WebPreferences& prefs,
1301 blink::WebView* web_view,
1302 CompositorDependencies* compositor_deps) {
1303 ApplyWebPreferences(prefs, web_view);
sataya.mf405d0e2015-07-07 16:51:111304}
1305
svartmetal751af1f92016-08-13 11:47:331306void RenderViewImpl::OnForceRedraw(const ui::LatencyInfo& latency_info) {
[email protected]7d08a9352013-10-15 08:24:561307 if (RenderWidgetCompositor* rwc = compositor()) {
svartmetal751af1f92016-08-13 11:47:331308 rwc->QueueSwapPromise(
1309 base::MakeUnique<AlwaysDrawSwapPromise>(latency_info));
danakj87fbafb2017-04-04 16:54:111310 rwc->SetNeedsForcedRedraw();
[email protected]7d08a9352013-10-15 08:24:561311 }
[email protected]c9bc8f12012-12-15 22:20:091312}
1313
[email protected]180ef242013-11-07 06:50:461314// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521315
csharrison95f01e922017-04-24 18:52:351316// TODO(csharrison): Migrate this method to WebFrameClient / RenderFrameImpl, as
1317// it is now serviced by a mojo interface scoped to the opener frame.
Blink Reformat1c4d759e2017-04-09 16:34:541318WebView* RenderViewImpl::CreateView(WebLocalFrame* creator,
[email protected]35b2a972014-04-04 15:50:221319 const WebURLRequest& request,
1320 const WebWindowFeatures& features,
1321 const WebString& frame_name,
1322 WebNavigationPolicy policy,
Daniel Chengd5e56ff2017-06-24 07:44:021323 bool suppress_opener,
1324 WebSandboxFlags sandbox_flags) {
nick5ae4d2d2017-01-06 01:18:351325 RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator);
rockot5c478a72016-09-28 23:14:181326 mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New();
Blink Reformat1c4d759e2017-04-09 16:34:541327 params->user_gesture = WebUserGestureIndicator::IsProcessingUserGesture();
[email protected]00323f02013-07-24 15:47:411328 if (GetContentClient()->renderer()->AllowPopup())
rockot5c478a72016-09-28 23:14:181329 params->user_gesture = true;
1330 params->window_container_type = WindowFeaturesToContainerType(features);
1331 params->session_storage_namespace_id = session_storage_namespace_id_;
Daniel Chengd5e56ff2017-06-24 07:44:021332 const std::string& frame_name_utf8 = frame_name.Utf8(
1333 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
1334 params->frame_name = frame_name_utf8;
rockot5c478a72016-09-28 23:14:181335 params->opener_suppressed = suppress_opener;
1336 params->disposition = NavigationPolicyToDisposition(policy);
Blink Reformat1c4d759e2017-04-09 16:34:541337 if (!request.IsNull()) {
1338 params->target_url = request.Url();
rockot5c478a72016-09-28 23:14:181339 params->referrer = GetReferrerFromRequest(creator, request);
[email protected]44e55b012013-07-23 14:21:561340 }
scottmg8e6c6082017-02-13 23:15:481341 params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
[email protected]8ab04652010-06-12 02:47:261342
rockot5c478a72016-09-28 23:14:181343 // We preserve this information before sending the message since |params| is
1344 // moved on send.
1345 bool is_background_tab =
1346 params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB;
1347 bool opened_by_user_gesture = params->user_gesture;
[email protected]22217ed32013-11-18 18:40:231348
Daniel Cheng8bb30c62017-10-23 20:40:471349 mojom::CreateNewWindowStatus status;
rockot5c478a72016-09-28 23:14:181350 mojom::CreateNewWindowReplyPtr reply;
Balazs Engedya40712f2017-09-15 15:01:111351 auto* frame_host = creator_frame->GetFrameHost();
Daniel Cheng8bb30c62017-10-23 20:40:471352 bool err = !frame_host->CreateNewWindow(std::move(params), &status, &reply);
1353 if (err || status == mojom::CreateNewWindowStatus::kIgnore)
rockot5c478a72016-09-28 23:14:181354 return nullptr;
[email protected]48c9cf2d2009-09-16 16:47:521355
Jochen Eisinger515337a2017-05-26 14:12:521356 // For Android WebView, we support a pop-up like behavior for window.open()
1357 // even if the embedding app doesn't support multiple windows. In this case,
1358 // window.open() will return "window" and navigate it to whatever URL was
Jochen Eisinger8cb28492017-10-04 10:58:131359 // passed. We also don't need to consume user gestures to protect against
1360 // multiple windows being opened, because, well, the app doesn't support
1361 // multiple windows.
Daniel Cheng8bb30c62017-10-23 20:40:471362 // TODO(dcheng): It's awkward that this is plumbed into Blink but not really
1363 // used much in Blink, except to enable layout testing... perhaps this should
1364 // be checked directly in the browser side.
1365 if (status == mojom::CreateNewWindowStatus::kReuse)
Jochen Eisinger515337a2017-05-26 14:12:521366 return webview();
1367
Daniel Cheng8bb30c62017-10-23 20:40:471368 DCHECK(reply);
1369 DCHECK_NE(MSG_ROUTING_NONE, reply->route_id);
1370 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_route_id);
1371 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_widget_route_id);
1372
Jochen Eisinger8cb28492017-10-04 10:58:131373 WebUserGestureIndicator::ConsumeUserGesture();
1374
[email protected]7912e822014-04-16 02:37:031375 // While this view may be a background extension page, it can spawn a visible
1376 // render view. So we just assume that the new one is not another background
1377 // page instead of passing on our own value.
1378 // TODO(vangelis): Can we tell if the new view will be a background page?
1379 bool never_visible = false;
[email protected]9115d5f2013-03-24 04:37:411380
fsamuel664e8b62016-01-20 19:54:011381 ResizeParams initial_size = ResizeParams();
mkosiba58fa72f02014-11-12 01:21:361382 initial_size.screen_info = screen_info_;
1383
[email protected]d6fa88f2013-10-18 16:00:431384 // The initial hidden state for the RenderViewImpl here has to match what the
1385 // browser will eventually decide for the given disposition. Since we have to
1386 // return from this call synchronously, we just have to make our best guess
1387 // and rely on the browser sending a WasHidden / WasShown message if it
1388 // disagrees.
rockot067ca55f2016-09-30 22:00:151389 mojom::CreateViewParams view_params;
alexmos5ac402d2015-07-09 07:51:101390
alexmos5ac402d2015-07-09 07:51:101391 view_params.opener_frame_route_id = creator_frame->GetRoutingID();
avia3dca182016-03-19 01:09:521392 DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID());
alexmos5ac402d2015-07-09 07:51:101393
naskobd911332014-11-25 01:13:361394 view_params.window_was_created_with_opener = true;
1395 view_params.renderer_preferences = renderer_preferences_;
1396 view_params.web_preferences = webkit_preferences_;
rockot5c478a72016-09-28 23:14:181397 view_params.view_id = reply->route_id;
1398 view_params.main_frame_routing_id = reply->main_frame_route_id;
1399 view_params.main_frame_widget_routing_id = reply->main_frame_widget_route_id;
naskobd911332014-11-25 01:13:361400 view_params.session_storage_namespace_id =
rockot5c478a72016-09-28 23:14:181401 reply->cloned_session_storage_namespace_id;
naskobd911332014-11-25 01:13:361402 view_params.swapped_out = false;
Ian Clellandcdc4f312017-10-13 22:24:121403 view_params.replicated_frame_state.frame_policy.sandbox_flags = sandbox_flags;
Daniel Chengd5e56ff2017-06-24 07:44:021404 view_params.replicated_frame_state.name = frame_name_utf8;
Pavel Feldman08beed7842017-10-17 19:18:111405 view_params.devtools_main_frame_token = reply->devtools_main_frame_token;
Daniel Chengd5e56ff2017-06-24 07:44:021406 // Even if the main frame has a name, the main frame's unique name is always
1407 // the empty string.
rockot5c478a72016-09-28 23:14:181408 view_params.hidden = is_background_tab;
naskobd911332014-11-25 01:13:361409 view_params.never_visible = never_visible;
naskobd911332014-11-25 01:13:361410 view_params.initial_size = initial_size;
1411 view_params.enable_auto_resize = false;
1412 view_params.min_size = gfx::Size();
1413 view_params.max_size = gfx::Size();
wjmaclean64951902016-04-29 20:59:121414 view_params.page_zoom_level = page_zoom_level_;
naskobd911332014-11-25 01:13:361415
nick5ae4d2d2017-01-06 01:18:351416 // Unretained() is safe here because our calling function will also call
1417 // show().
nickf7b38222016-11-22 21:59:351418 RenderWidget::ShowCallback show_callback =
nick5ae4d2d2017-01-06 01:18:351419 base::Bind(&RenderFrameImpl::ShowCreatedWindow,
1420 base::Unretained(creator_frame), opened_by_user_gesture);
nickf7b38222016-11-22 21:59:351421
danakj6e3bf8012014-12-16 18:27:531422 RenderViewImpl* view =
nickf7b38222016-11-22 21:59:351423 RenderViewImpl::Create(compositor_deps_, view_params, show_callback);
[email protected]48c9cf2d2009-09-16 16:47:521424
[email protected]48c9cf2d2009-09-16 16:47:521425 return view->webview();
1426}
1427
Blink Reformat1c4d759e2017-04-09 16:34:541428WebWidget* RenderViewImpl::CreatePopupMenu(blink::WebPopupType popup_type) {
nickf7b38222016-11-22 21:59:351429 RenderWidget* widget = RenderWidget::CreateForPopup(this, compositor_deps_,
1430 popup_type, screen_info_);
[email protected]3b78ec12014-03-04 05:18:281431 if (!widget)
1432 return NULL;
[email protected]b2e4c70132013-10-03 02:07:511433 if (screen_metrics_emulator_) {
1434 widget->SetPopupOriginAdjustmentsForEmulation(
1435 screen_metrics_emulator_.get());
1436 }
lfg8ff33912016-09-13 20:59:211437 return widget->GetWebWidget();
[email protected]48c9cf2d2009-09-16 16:47:521438}
1439
Blink Reformat1c4d759e2017-04-09 16:34:541440WebStorageNamespace* RenderViewImpl::CreateSessionStorageNamespace() {
[email protected]5f2aa722013-08-07 16:59:411441 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:101442 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341443}
1444
Blink Reformat1c4d759e2017-04-09 16:34:541445void RenderViewImpl::PrintPage(WebLocalFrame* frame) {
naskoe440d8c2016-10-12 23:07:561446 UMA_HISTOGRAM_BOOLEAN("PrintPreview.InitiatedByScript",
Blink Reformat1c4d759e2017-04-09 16:34:541447 frame->Top() == frame);
naskoe440d8c2016-10-12 23:07:561448
1449 // Logging whether the top frame is remote is sufficient in this case. If
1450 // the top frame is local, the printing code will function correctly and
1451 // the frame itself will be printed, so the cases this histogram tracks is
1452 // where printing of a subframe will fail as of now.
1453 UMA_HISTOGRAM_BOOLEAN("PrintPreview.OutOfProcessSubframe",
Blink Reformat1c4d759e2017-04-09 16:34:541454 frame->Top()->IsWebRemoteFrame());
naskoe440d8c2016-10-12 23:07:561455
thestigcb959ce2016-11-17 05:56:321456 RenderFrameImpl::FromWebFrame(frame)->ScriptedPrint(
1457 input_handler().handling_input_event());
[email protected]48c9cf2d2009-09-16 16:47:521458}
1459
Blink Reformat1c4d759e2017-04-09 16:34:541460bool RenderViewImpl::EnumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121461 const WebString& path,
1462 WebFileChooserCompletion* chooser_completion) {
1463 int id = enumeration_completion_id_++;
1464 enumeration_completions_[id] = chooser_completion;
1465 return Send(new ViewHostMsg_EnumerateDirectory(
avia3dca182016-03-19 01:09:521466 GetRoutingID(), id, blink::WebStringToFilePath(path)));
[email protected]8a58c1c2011-04-19 18:40:121467}
1468
[email protected]7e9523b2014-03-25 03:02:421469void RenderViewImpl::FrameDidStartLoading(WebFrame* frame) {
[email protected]7e9523b2014-03-25 03:02:421470 DCHECK_GE(frames_in_progress_, 0);
ericwilligers88e69742016-10-17 19:29:551471 if (frames_in_progress_ == 0) {
1472 for (auto& observer : observers_)
1473 observer.DidStartLoading();
1474 }
[email protected]7e9523b2014-03-25 03:02:421475 frames_in_progress_++;
[email protected]6dd5c322014-03-12 07:58:461476}
1477
[email protected]7e9523b2014-03-25 03:02:421478void RenderViewImpl::FrameDidStopLoading(WebFrame* frame) {
[email protected]eb473772014-04-11 20:54:331479 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
1480 // calls DidStopLoading() without a matching DidStartLoading().
1481 if (frames_in_progress_ == 0)
1482 return;
[email protected]7e9523b2014-03-25 03:02:421483 frames_in_progress_--;
[email protected]7e9523b2014-03-25 03:02:421484 if (frames_in_progress_ == 0) {
ericwilligers88e69742016-10-17 19:29:551485 for (auto& observer : observers_)
1486 observer.DidStopLoading();
[email protected]7e9523b2014-03-25 03:02:421487 }
[email protected]48c9cf2d2009-09-16 16:47:521488}
1489
lfgcaab5142016-02-26 19:06:521490void RenderViewImpl::AttachWebFrameWidget(blink::WebFrameWidget* frame_widget) {
dcheng3ce04b62015-10-26 23:30:551491 // The previous WebFrameWidget must already be detached by CloseForFrame().
1492 DCHECK(!frame_widget_);
1493 frame_widget_ = frame_widget;
1494}
1495
tommycli8aad3ba2015-08-12 17:57:591496void RenderViewImpl::SetZoomLevel(double zoom_level) {
wjmaclean64951902016-04-29 20:59:121497 // If we change the zoom level for the view, make sure any subsequent subframe
1498 // loads reflect the current zoom level.
1499 page_zoom_level_ = zoom_level;
1500
Blink Reformat1c4d759e2017-04-09 16:34:541501 webview()->SetZoomLevel(zoom_level);
ericwilligers88e69742016-10-17 19:29:551502 for (auto& observer : observers_)
1503 observer.OnZoomLevelChanged();
tommycli8aad3ba2015-08-12 17:57:591504}
1505
habib.virji597255e2014-09-09 00:30:181506void RenderViewImpl::SetValidationMessageDirection(
1507 base::string16* wrapped_main_text,
1508 blink::WebTextDirection main_text_hint,
1509 base::string16* wrapped_sub_text,
1510 blink::WebTextDirection sub_text_hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541511 if (main_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181512 *wrapped_main_text =
1513 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
Blink Reformat1c4d759e2017-04-09 16:34:541514 } else if (main_text_hint == blink::kWebTextDirectionRightToLeft &&
habib.virji597255e2014-09-09 00:30:181515 !base::i18n::IsRTL()) {
1516 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
1517 }
1518
1519 if (!wrapped_sub_text->empty()) {
Blink Reformat1c4d759e2017-04-09 16:34:541520 if (sub_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181521 *wrapped_sub_text =
1522 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
Blink Reformat1c4d759e2017-04-09 16:34:541523 } else if (sub_text_hint == blink::kWebTextDirectionRightToLeft) {
habib.virji597255e2014-09-09 00:30:181524 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
1525 }
1526 }
1527}
1528
[email protected]310ebd6302011-10-10 19:06:281529void RenderViewImpl::UpdateTargetURL(const GURL& url,
1530 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581531 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521532 if (latest_url == target_url_)
1533 return;
[email protected]163f8242009-10-30 20:19:551534
[email protected]48c9cf2d2009-09-16 16:47:521535 // Tell the browser to display a destination link.
1536 if (target_url_status_ == TARGET_INFLIGHT ||
1537 target_url_status_ == TARGET_PENDING) {
1538 // If we have a request in-flight, save the URL to be sent when we
1539 // receive an ACK to the in-flight request. We can happily overwrite
1540 // any existing pending sends.
1541 pending_target_url_ = latest_url;
1542 target_url_status_ = TARGET_PENDING;
1543 } else {
mnaganovbf087422015-12-16 05:10:031544 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411545 // see |ParamTraits<GURL>|.
markdittmer67b71ea2016-03-03 22:40:031546 if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:411547 latest_url = GURL();
avia3dca182016-03-19 01:09:521548 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), latest_url));
[email protected]48c9cf2d2009-09-16 16:47:521549 target_url_ = latest_url;
1550 target_url_status_ = TARGET_INFLIGHT;
1551 }
1552}
1553
[email protected]70221f02013-01-31 22:17:071554gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect(
1555 const gfx::RectF& rect) const {
1556 gfx::RectF window_rect = rect;
Blink Reformat1c4d759e2017-04-09 16:34:541557 window_rect.Scale(device_scale_factor_ * webview()->PageScaleFactor());
[email protected]70221f02013-01-31 22:17:071558 return window_rect;
1559}
1560
creis69b184a472015-11-26 05:29:511561void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) {
creisce0ef3572017-01-26 17:53:081562 // Keep track of which frames have pending updates.
1563 frames_with_pending_state_.insert(frame->GetRoutingID());
creis8eb8ef22015-11-04 22:51:381564
[email protected]882daa92009-11-05 16:31:311565 int delay;
avif937e1d2014-11-02 18:13:071566 if (send_content_state_immediately_)
[email protected]882daa92009-11-05 16:31:311567 delay = 0;
1568 else if (is_hidden())
avif937e1d2014-11-02 18:13:071569 delay = kDelaySecondsForContentStateSyncHidden;
[email protected]882daa92009-11-05 16:31:311570 else
avif937e1d2014-11-02 18:13:071571 delay = kDelaySecondsForContentStateSync;
[email protected]882daa92009-11-05 16:31:311572
avif937e1d2014-11-02 18:13:071573 if (nav_state_sync_timer_.IsRunning()) {
[email protected]882daa92009-11-05 16:31:311574 // The timer is already running. If the delay of the timer maches the amount
1575 // we want to delay by, then return. Otherwise stop the timer so that it
1576 // gets started with the right delay.
avif937e1d2014-11-02 18:13:071577 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
[email protected]882daa92009-11-05 16:31:311578 return;
avif937e1d2014-11-02 18:13:071579 nav_state_sync_timer_.Stop();
[email protected]882daa92009-11-05 16:31:311580 }
1581
creisce0ef3572017-01-26 17:53:081582 // Tell each frame with pending state to inform the browser.
1583 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
1584 &RenderViewImpl::SendFrameStateUpdates);
[email protected]882daa92009-11-05 16:31:311585}
1586
Blink Reformat1c4d759e2017-04-09 16:34:541587void RenderViewImpl::SetMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551588 mouse_over_url_ = GURL(url);
1589 UpdateTargetURL(mouse_over_url_, focus_url_);
1590}
1591
Blink Reformat1c4d759e2017-04-09 16:34:541592void RenderViewImpl::SetKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551593 focus_url_ = GURL(url);
1594 UpdateTargetURL(focus_url_, mouse_over_url_);
1595}
1596
Blink Reformat1c4d759e2017-04-09 16:34:541597bool RenderViewImpl::AcceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451598 return renderer_preferences_.can_accept_load_drops;
1599}
1600
Blink Reformat1c4d759e2017-04-09 16:34:541601void RenderViewImpl::FocusNext() {
avia3dca182016-03-19 01:09:521602 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false));
[email protected]48c9cf2d2009-09-16 16:47:521603}
1604
Blink Reformat1c4d759e2017-04-09 16:34:541605void RenderViewImpl::FocusPrevious() {
avia3dca182016-03-19 01:09:521606 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true));
[email protected]48c9cf2d2009-09-16 16:47:521607}
1608
esprehn3d4471a2015-09-17 07:13:201609// TODO(esprehn): Blink only ever passes Elements, this should take WebElement.
Blink Reformat1c4d759e2017-04-09 16:34:541610void RenderViewImpl::FocusedNodeChanged(const WebNode& fromNode,
estade31c54342015-01-23 03:34:361611 const WebNode& toNode) {
[email protected]1875bc02014-03-14 06:33:591612 has_scrolled_focused_editable_node_into_rect_ = false;
1613
estade31c54342015-01-23 03:34:361614 RenderFrameImpl* previous_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541615 if (!fromNode.IsNull())
1616 previous_frame =
1617 RenderFrameImpl::FromWebFrame(fromNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361618 RenderFrameImpl* new_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541619 if (!toNode.IsNull())
1620 new_frame = RenderFrameImpl::FromWebFrame(toNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361621
1622 if (previous_frame && previous_frame != new_frame)
1623 previous_frame->FocusedNodeChanged(WebNode());
1624 if (new_frame)
1625 new_frame->FocusedNodeChanged(toNode);
1626
1627 // TODO(dmazzoni): remove once there's a separate a11y tree per frame.
naskoe8d115752015-08-07 00:43:131628 if (main_render_frame_)
1629 main_render_frame_->FocusedNodeChangedForAccessibility(toNode);
[email protected]08e9e132010-06-01 16:58:491630}
1631
Blink Reformat1c4d759e2017-04-09 16:34:541632void RenderViewImpl::DidUpdateLayout() {
ericwilligers88e69742016-10-17 19:29:551633 for (auto& observer : observers_)
1634 observer.DidUpdateLayout();
[email protected]d01b2a62013-09-18 23:21:331635
[email protected]169d4282011-11-30 19:33:591636 // We don't always want to set up a timer, only if we've been put in that
1637 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1638 // message.
1639 if (!send_preferred_size_changes_ || !webview())
1640 return;
1641
1642 if (check_preferred_size_timer_.IsRunning())
1643 return;
1644 check_preferred_size_timer_.Start(FROM_HERE,
1645 TimeDelta::FromMilliseconds(0), this,
1646 &RenderViewImpl::CheckPreferredSize);
1647}
1648
Blink Reformat1c4d759e2017-04-09 16:34:541649void RenderViewImpl::NavigateBackForwardSoon(int offset) {
avia3dca182016-03-19 01:09:521650 Send(new ViewHostMsg_GoToEntryAtOffset(GetRoutingID(), offset));
[email protected]48c9cf2d2009-09-16 16:47:521651}
1652
Blink Reformat1c4d759e2017-04-09 16:34:541653int RenderViewImpl::HistoryBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001654 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521655}
1656
Blink Reformat1c4d759e2017-04-09 16:34:541657int RenderViewImpl::HistoryForwardListCount() {
1658 return history_list_length_ - HistoryBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521659}
1660
[email protected]180ef242013-11-07 06:50:461661// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:511662
Blink Reformat1c4d759e2017-04-09 16:34:541663void RenderViewImpl::DidFocus() {
[email protected]ea42e7782010-08-23 23:58:121664 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1665 // we won't have to test for user gesture anymore and we can
1666 // move that code back to render_widget.cc
Blink Reformat1c4d759e2017-04-09 16:34:541667 if (WebUserGestureIndicator::IsProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:301668 !RenderThreadImpl::current()->layout_test_mode()) {
avia3dca182016-03-19 01:09:521669 Send(new ViewHostMsg_Focus(GetRoutingID()));
[email protected]ea42e7782010-08-23 23:58:121670 }
1671}
1672
nickf7b38222016-11-22 21:59:351673// We are supposed to get a single call to show() for a newly created RenderView
1674// that was created via RenderViewImpl::createView. We wait until this point to
1675// run |show_callback|, which is bound to our opener's ShowCreatedViewWidget()
1676// method.
initial.commit09911bf2008-07-26 23:55:291677//
1678// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281679// created RenderView (i.e., as a blocked popup or as a new tab).
Blink Reformat1c4d759e2017-04-09 16:34:541680void RenderViewImpl::Show(WebNavigationPolicy policy) {
nickf7b38222016-11-22 21:59:351681 if (did_show_ && !webkit_preferences_.supports_multiple_windows) {
[email protected]b2142e962012-10-30 13:59:251682 // When supports_multiple_windows is disabled, popups are reusing
1683 // the same view. In some scenarios, this makes WebKit to call show() twice.
initial.commit09911bf2008-07-26 23:55:291684 return;
[email protected]b2142e962012-10-30 13:59:251685 }
initial.commit09911bf2008-07-26 23:55:291686
Blink Reformat1c4d759e2017-04-09 16:34:541687 RenderWidget::Show(policy);
initial.commit09911bf2008-07-26 23:55:291688}
1689
miletuse8d28ba2015-06-19 04:52:041690
Blink Reformat1c4d759e2017-04-09 16:34:541691bool RenderViewImpl::CanHandleGestureEvent() {
slangley1a6375e62017-03-29 06:03:231692 return true;
1693}
1694
Blink Reformat1c4d759e2017-04-09 16:34:541695bool RenderViewImpl::CanUpdateLayout() {
slangley1a6375e62017-03-29 06:03:231696 return true;
1697}
1698
Blink Reformat1c4d759e2017-04-09 16:34:541699void RenderViewImpl::DidHandleGestureEvent(const WebGestureEvent& event,
1700 bool event_cancelled) {
1701 RenderWidget::DidHandleGestureEvent(event, event_cancelled);
[email protected]bb37b652013-11-27 23:47:111702
[email protected]91dcc6d32014-07-30 00:01:331703 if (!event_cancelled) {
ericwilligers88e69742016-10-17 19:29:551704 for (auto& observer : observers_)
1705 observer.DidHandleGestureEvent(event);
[email protected]91dcc6d32014-07-30 00:01:331706 }
[email protected]c68c3e4e2013-01-24 00:36:561707}
1708
Blink Reformat1c4d759e2017-04-09 16:34:541709blink::WebLayerTreeView* RenderViewImpl::InitializeLayerTreeView() {
wjmaclean1d970622017-01-21 22:28:241710 // TODO(!wjmaclean): We should be able to just remove this function, and
1711 // expect the RenderWidget version of the function to be called instead.
1712 // However, we have a diamond inheritance pattern going on:
1713 // WebWidgetClient
1714 // | |
1715 // RenderWidget WebViewClient
1716 // | |
1717 // RenderViewImpl
1718 //
1719 // and this seems to prefer calling the empty version in WebWidgetClient
1720 // or WebViewClient over the non-empty one in RenderWidget.
Blink Reformat1c4d759e2017-04-09 16:34:541721 return RenderWidget::InitializeLayerTreeView();
[email protected]6e89eb72013-07-23 13:28:221722}
1723
Blink Reformat1c4d759e2017-04-09 16:34:541724void RenderViewImpl::CloseWidgetSoon() {
1725 RenderWidget::CloseWidgetSoon();
lfg2230bce2016-04-28 18:37:041726}
1727
Blink Reformat1c4d759e2017-04-09 16:34:541728void RenderViewImpl::ConvertViewportToWindow(blink::WebRect* rect) {
1729 RenderWidget::ConvertViewportToWindow(rect);
lfg2230bce2016-04-28 18:37:041730}
1731
Blink Reformat1c4d759e2017-04-09 16:34:541732void RenderViewImpl::ConvertWindowToViewport(blink::WebFloatRect* rect) {
1733 RenderWidget::ConvertWindowToViewport(rect);
lfg2230bce2016-04-28 18:37:041734}
1735
Blink Reformat1c4d759e2017-04-09 16:34:541736void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) {
lfgb00fcad2016-07-14 14:16:331737 RenderWidget::DidAutoResize(newSize);
lfg2230bce2016-04-28 18:37:041738}
1739
Blink Reformat1c4d759e2017-04-09 16:34:541740void RenderViewImpl::DidOverscroll(
lfg2230bce2016-04-28 18:37:041741 const blink::WebFloatSize& overscrollDelta,
1742 const blink::WebFloatSize& accumulatedOverscroll,
1743 const blink::WebFloatPoint& positionInViewport,
sunyunjiabbea8a92017-08-31 11:18:541744 const blink::WebFloatSize& velocityInViewport,
1745 const blink::WebScrollBoundaryBehavior& behavior) {
Blink Reformat1c4d759e2017-04-09 16:34:541746 RenderWidget::DidOverscroll(overscrollDelta, accumulatedOverscroll,
sunyunjiabbea8a92017-08-31 11:18:541747 positionInViewport, velocityInViewport, behavior);
lfg2230bce2016-04-28 18:37:041748}
1749
Blink Reformat1c4d759e2017-04-09 16:34:541750void RenderViewImpl::HasTouchEventHandlers(bool has_handlers) {
1751 RenderWidget::HasTouchEventHandlers(has_handlers);
lfg2230bce2016-04-28 18:37:041752}
1753
Blink Reformat1c4d759e2017-04-09 16:34:541754blink::WebRect RenderViewImpl::RootWindowRect() {
1755 return RenderWidget::WindowRect();
lfg2230bce2016-04-28 18:37:041756}
1757
Blink Reformat1c4d759e2017-04-09 16:34:541758blink::WebScreenInfo RenderViewImpl::GetScreenInfo() {
1759 return RenderWidget::GetScreenInfo();
lfg2230bce2016-04-28 18:37:041760}
1761
Blink Reformat1c4d759e2017-04-09 16:34:541762void RenderViewImpl::SetToolTipText(const blink::WebString& text,
lfg2230bce2016-04-28 18:37:041763 blink::WebTextDirection hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541764 RenderWidget::SetToolTipText(text, hint);
lfg2230bce2016-04-28 18:37:041765}
1766
Blink Reformat1c4d759e2017-04-09 16:34:541767void RenderViewImpl::SetTouchAction(blink::WebTouchAction touchAction) {
1768 RenderWidget::SetTouchAction(touchAction);
lfg2230bce2016-04-28 18:37:041769}
1770
Blink Reformat1c4d759e2017-04-09 16:34:541771void RenderViewImpl::ShowUnhandledTapUIIfNeeded(
Donn Denman43a439e2017-08-29 04:20:451772 const blink::WebTappedInfo& tappedInfo) {
1773 RenderWidget::ShowUnhandledTapUIIfNeeded(tappedInfo);
lfg2230bce2016-04-28 18:37:041774}
1775
Blink Reformat1c4d759e2017-04-09 16:34:541776blink::WebWidgetClient* RenderViewImpl::WidgetClient() {
lfg0f440622016-07-20 04:27:141777 return static_cast<RenderWidget*>(this);
1778}
1779
[email protected]180ef242013-11-07 06:50:461780// blink::WebFrameClient -----------------------------------------------------
[email protected]3d9689372009-09-10 04:29:171781
[email protected]5e92282f2012-08-17 08:11:571782void RenderViewImpl::Repaint(const gfx::Size& size) {
[email protected]3d9ec5052013-01-02 22:05:251783 OnRepaint(size);
[email protected]5e92282f2012-08-17 08:11:571784}
1785
[email protected]b2324b092012-11-01 10:34:111786void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
1787 const std::string& value) {
alexmos56567492016-09-13 00:52:461788 GetWidget()->SetEditCommandForNextKeyEvent(name, value);
[email protected]b2324b092012-11-01 10:34:111789}
1790
1791void RenderViewImpl::ClearEditCommands() {
alexmos56567492016-09-13 00:52:461792 GetWidget()->ClearEditCommands();
[email protected]b2324b092012-11-01 10:34:111793}
1794
[email protected]b38806a2013-10-04 16:01:381795const std::string& RenderViewImpl::GetAcceptLanguages() const {
1796 return renderer_preferences_.accept_languages;
1797}
1798
danakjdea2efb2016-03-10 19:13:171799void RenderViewImpl::ConvertViewportToWindowViaWidget(blink::WebRect* rect) {
Blink Reformat1c4d759e2017-04-09 16:34:541800 ConvertViewportToWindow(rect);
oshimae2b3b402015-12-04 04:27:241801}
1802
huangs2a342352015-12-15 16:59:241803gfx::RectF RenderViewImpl::ElementBoundsInWindow(
1804 const blink::WebElement& element) {
Blink Reformat1c4d759e2017-04-09 16:34:541805 blink::WebRect bounding_box_in_window = element.BoundsInViewport();
danakjdea2efb2016-03-10 19:13:171806 ConvertViewportToWindowViaWidget(&bounding_box_in_window);
huangs2a342352015-12-15 16:59:241807 return gfx::RectF(bounding_box_in_window);
1808}
1809
changwand659e202016-06-13 02:39:121810bool RenderViewImpl::HasAddedInputHandler() const {
1811 return has_added_input_handler_;
1812}
1813
[email protected]310ebd6302011-10-10 19:06:281814void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:071815 // We don't always want to send the change messages over IPC, only if we've
1816 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1817 // message.
1818 if (!send_preferred_size_changes_ || !webview())
1819 return;
oshima1a688b5c2017-06-16 19:00:131820 blink::WebSize tmp_size = webview()->ContentsPreferredMinimumSize();
1821 blink::WebRect tmp_rect(0, 0, tmp_size.width, tmp_size.height);
1822 ConvertViewportToWindow(&tmp_rect);
1823 gfx::Size size(tmp_rect.width, tmp_rect.height);
[email protected]705243f2010-05-05 19:58:071824 if (size == preferred_size_)
1825 return;
[email protected]c27324b2009-11-19 22:44:291826
[email protected]705243f2010-05-05 19:58:071827 preferred_size_ = size;
avia3dca182016-03-19 01:09:521828 Send(new ViewHostMsg_DidContentsPreferredSizeChange(GetRoutingID(),
[email protected]705243f2010-05-05 19:58:071829 preferred_size_));
[email protected]3d9689372009-09-10 04:29:171830}
1831
Blink Reformat1c4d759e2017-04-09 16:34:541832blink::WebString RenderViewImpl::AcceptLanguages() {
1833 return WebString::FromUTF8(renderer_preferences_.accept_languages);
[email protected]9982c802013-06-12 15:22:061834}
1835
[email protected]e9ff79c2012-10-19 21:31:261836// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:311837
[email protected]310ebd6302011-10-10 19:06:281838bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:311839 return RenderWidget::Send(message);
1840}
1841
avi8a45c1092016-03-01 16:12:341842RenderWidget* RenderViewImpl::GetWidget() const {
1843 return const_cast<RenderWidget*>(static_cast<const RenderWidget*>(this));
1844}
1845
mostynbc33353232014-09-12 09:38:311846RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() {
nasko77de2312015-05-12 03:09:161847 return main_render_frame_;
[email protected]b849847b2013-12-10 21:57:581848}
1849
[email protected]82114f52012-03-20 22:53:411850int RenderViewImpl::GetRoutingID() const {
fsamuele8326c742016-01-12 00:49:391851 return routing_id();
[email protected]a2ef54c2011-10-10 16:20:311852}
1853
[email protected]82114f52012-03-20 22:53:411854gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:311855 return size();
1856}
1857
oshima129b75e2016-01-14 09:15:141858float RenderViewImpl::GetDeviceScaleFactor() const {
1859 return device_scale_factor_;
1860}
1861
Marc Treib06d66032017-10-19 08:43:201862float RenderViewImpl::GetZoomLevel() const {
1863 return page_zoom_level_;
1864}
1865
thestig8a8fdfd32017-05-06 18:46:541866const WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:311867 return webkit_preferences_;
1868}
1869
[email protected]324825d2012-11-30 12:37:151870void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
1871 OnUpdateWebPreferences(preferences);
1872}
1873
[email protected]180ef242013-11-07 06:50:461874blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:311875 return webview();
1876}
1877
lfgcaab5142016-02-26 19:06:521878blink::WebFrameWidget* RenderViewImpl::GetWebFrameWidget() {
1879 return frame_widget_;
1880}
1881
[email protected]310ebd6302011-10-10 19:06:281882bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:311883 return (!send_preferred_size_changes_ ||
1884 (disable_scrollbars_size_limit_.width() <= width ||
1885 disable_scrollbars_size_limit_.height() <= height));
1886}
1887
avif937e1d2014-11-02 18:13:071888bool RenderViewImpl::GetContentStateImmediately() const {
1889 return send_content_state_immediately_;
[email protected]a2ef54c2011-10-10 16:20:311890}
1891
mcnee432e47d2015-11-09 19:37:461892void RenderViewImpl::OnSetPageScale(float page_scale_factor) {
ccameronb7c1d6c2015-03-09 17:08:241893 if (!webview())
1894 return;
Blink Reformat1c4d759e2017-04-09 16:34:541895 webview()->SetPageScaleFactor(page_scale_factor);
ccameronb7c1d6c2015-03-09 17:08:241896}
1897
wjmaclean64951902016-04-29 20:59:121898void RenderViewImpl::OnSetZoomLevel(
1899 PageMsg_SetZoomLevel_Command command,
1900 double zoom_level) {
1901 switch (command) {
1902 case PageMsg_SetZoomLevel_Command::CLEAR_TEMPORARY:
1903 uses_temporary_zoom_level_ = false;
1904 break;
1905 case PageMsg_SetZoomLevel_Command::SET_TEMPORARY:
1906 uses_temporary_zoom_level_ = true;
1907 break;
1908 case PageMsg_SetZoomLevel_Command::USE_CURRENT_TEMPORARY_MODE:
1909 // Don't override a temporary zoom level without an explicit SET.
1910 if (uses_temporary_zoom_level_)
1911 return;
1912 break;
1913 default:
1914 NOTIMPLEMENTED();
1915 }
Blink Reformat1c4d759e2017-04-09 16:34:541916 webview()->HidePopups();
wjmaclean64951902016-04-29 20:59:121917 SetZoomLevel(zoom_level);
[email protected]d42bf472014-06-14 01:49:381918}
1919
[email protected]310ebd6302011-10-10 19:06:281920void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:591921 webkit_preferences_ = prefs;
sataya.mf405d0e2015-07-07 16:51:111922 ApplyWebPreferencesInternal(webkit_preferences_, webview(), compositor_deps_);
initial.commit09911bf2008-07-26 23:55:291923}
1924
[email protected]310ebd6302011-10-10 19:06:281925void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:511926 int id,
[email protected]c42de732013-02-16 06:26:311927 const std::vector<base::FilePath>& paths) {
[email protected]600ea402011-04-12 00:01:511928 if (!enumeration_completions_[id])
1929 return;
1930
1931 WebVector<WebString> ws_file_names(paths.size());
1932 for (size_t i = 0; i < paths.size(); ++i)
kinukoa4293022017-01-27 06:43:251933 ws_file_names[i] = blink::FilePathToWebString(paths[i]);
[email protected]600ea402011-04-12 00:01:511934
Blink Reformat1c4d759e2017-04-09 16:34:541935 enumeration_completions_[id]->DidChooseFile(ws_file_names);
[email protected]600ea402011-04-12 00:01:511936 enumeration_completions_.erase(id);
1937}
1938
[email protected]244ac1892011-12-02 17:04:471939void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
1940 const gfx::Size& max_size) {
1941 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
1942 if (!webview())
1943 return;
oshima33ec97cd2015-12-14 19:40:241944
[email protected]97e1bf72013-03-06 14:06:051945 auto_resize_mode_ = true;
Fady Samuel319e429c2017-10-02 18:31:551946 AutoResizeCompositor();
1947
oshima33ec97cd2015-12-14 19:40:241948 if (IsUseZoomForDSFEnabled()) {
Blink Reformat1c4d759e2017-04-09 16:34:541949 webview()->EnableAutoResizeMode(
oshima33ec97cd2015-12-14 19:40:241950 gfx::ScaleToCeiledSize(min_size, device_scale_factor_),
1951 gfx::ScaleToCeiledSize(max_size, device_scale_factor_));
1952 } else {
Blink Reformat1c4d759e2017-04-09 16:34:541953 webview()->EnableAutoResizeMode(min_size, max_size);
oshima33ec97cd2015-12-14 19:40:241954 }
[email protected]61e2b3cc2012-03-02 16:13:341955}
1956
1957void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
1958 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
1959 if (!webview())
1960 return;
[email protected]97e1bf72013-03-06 14:06:051961 auto_resize_mode_ = false;
Blink Reformat1c4d759e2017-04-09 16:34:541962 webview()->DisableAutoResizeMode();
[email protected]61e2b3cc2012-03-02 16:13:341963
[email protected]eac2b362013-05-22 07:01:451964 if (!new_size.IsEmpty()) {
mfomitchev2600fd7c2016-02-17 20:53:391965 ResizeParams resize_params;
jbroman5ff10302016-07-22 03:36:261966 resize_params.screen_info = screen_info_;
mfomitchev2600fd7c2016-02-17 20:53:391967 resize_params.new_size = new_size;
1968 resize_params.physical_backing_size = physical_backing_size_;
mdjones2ee41afd2016-10-27 16:50:201969 resize_params.browser_controls_shrink_blink_size =
1970 browser_controls_shrink_blink_size_;
mfomitchev2600fd7c2016-02-17 20:53:391971 resize_params.top_controls_height = top_controls_height_;
1972 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:391973 resize_params.is_fullscreen_granted = is_fullscreen_granted();
1974 resize_params.display_mode = display_mode_;
1975 resize_params.needs_resize_ack = false;
1976 Resize(resize_params);
[email protected]eac2b362013-05-22 07:01:451977 }
[email protected]244ac1892011-12-02 17:04:471978}
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");
[email protected]cda45c02010-02-25 19:28:102072 if (webview()) {
Blink Reformat1c4d759e2017-04-09 16:34:542073 webview()->HidePopups();
kenrb5fd60fb82016-06-10 17:27:572074 if (send_preferred_size_changes_ &&
Blink Reformat1c4d759e2017-04-09 16:34:542075 webview()->MainFrame()->IsWebLocalFrame()) {
lukasza302fcdd2017-06-02 20:40:352076 webview()->MainFrame()->ToWebLocalFrame()->SetCanHaveScrollbars(
2077 ShouldDisplayScrollbars(params.new_size.width(),
2078 params.new_size.height()));
[email protected]cda45c02010-02-25 19:28:102079 }
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122080 if (display_mode_ != params.display_mode) {
2081 display_mode_ = params.display_mode;
Blink Reformat1c4d759e2017-04-09 16:34:542082 webview()->SetDisplayMode(display_mode_);
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122083 }
[email protected]cda45c02010-02-25 19:28:102084 }
2085
[email protected]cbbdeef2014-05-26 15:57:362086 gfx::Size old_visible_viewport_size = visible_viewport_size_;
2087
mdjones2ee41afd2016-10-27 16:50:202088 browser_controls_shrink_blink_size_ =
2089 params.browser_controls_shrink_blink_size;
bokanc63441c2016-04-27 15:49:122090 top_controls_height_ = params.top_controls_height;
Matthew Jones7e156182017-07-21 22:21:332091 bottom_controls_height_ = params.bottom_controls_height;
bokanc63441c2016-04-27 15:49:122092
[email protected]0fdd5012013-05-29 08:05:562093 RenderWidget::OnResize(params);
[email protected]cbbdeef2014-05-26 15:57:362094
2095 if (old_visible_viewport_size != visible_viewport_size_)
2096 has_scrolled_focused_editable_node_into_rect_ = false;
[email protected]30f75e62009-02-25 22:01:002097}
[email protected]0aa477bd2009-03-23 22:21:432098
[email protected]61f91832014-05-13 01:24:422099void RenderViewImpl::OnSetBackgroundOpaque(bool opaque) {
esecklerf2bd55f72017-03-31 09:11:572100 if (!frame_widget_)
2101 return;
2102
2103 if (opaque) {
Blink Reformat1c4d759e2017-04-09 16:34:542104 frame_widget_->ClearBaseBackgroundColorOverride();
2105 frame_widget_->ClearBackgroundColorOverride();
esecklerf2bd55f72017-03-31 09:11:572106 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542107 frame_widget_->SetBaseBackgroundColorOverride(SK_ColorTRANSPARENT);
2108 frame_widget_->SetBackgroundColorOverride(SK_ColorTRANSPARENT);
esecklerf2bd55f72017-03-31 09:11:572109 }
[email protected]699ab0d2009-04-23 23:19:142110}
2111
[email protected]310ebd6302011-10-10 19:06:282112void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:342113 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542114 webview()->SetIsActive(active);
[email protected]8c66c5a2009-07-22 17:26:342115}
2116
lfg8ff33912016-09-13 20:59:212117blink::WebWidget* RenderViewImpl::GetWebWidget() const {
2118 if (frame_widget_)
2119 return frame_widget_;
2120
2121 return RenderWidget::GetWebWidget();
2122}
2123
dcheng3ce04b62015-10-26 23:30:552124void RenderViewImpl::CloseForFrame() {
2125 DCHECK(frame_widget_);
Blink Reformat1c4d759e2017-04-09 16:34:542126 frame_widget_->Close();
dcheng3ce04b62015-10-26 23:30:552127 frame_widget_ = nullptr;
2128}
2129
[email protected]310ebd6302011-10-10 19:06:282130void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:592131 // We need to grab a pointer to the doomed WebView before we destroy it.
lfg4fa48da2016-05-09 18:25:132132 WebView* doomed = webview_;
[email protected]60c42a8c72009-10-09 04:08:592133 RenderWidget::Close();
lfg4fa48da2016-05-09 18:25:132134 webview_ = nullptr;
[email protected]625332e02010-12-14 07:48:492135 g_view_map.Get().erase(doomed);
avia3dca182016-03-19 01:09:522136 g_routing_id_view_map.Get().erase(GetRoutingID());
2137 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(GetRoutingID()));
[email protected]60c42a8c72009-10-09 04:08:592138}
2139
lfg717154072016-06-30 15:04:162140void RenderViewImpl::OnPageWasHidden() {
braveyao1d8ee7b2017-03-29 21:10:042141#if defined(OS_ANDROID)
2142 SuspendVideoCaptureDevices(true);
2143#if BUILDFLAG(ENABLE_WEBRTC)
[email protected]e976c3c52014-07-24 17:41:552144 if (speech_recognition_dispatcher_)
2145 speech_recognition_dispatcher_->AbortAllRecognitions();
[email protected]6392d982013-04-16 16:59:222146#endif
braveyao1d8ee7b2017-03-29 21:10:042147#endif
[email protected]2d7b82c2012-06-01 05:57:502148
lfg717154072016-06-30 15:04:162149 if (webview()) {
2150 // TODO(lfg): It's not correct to defer the page visibility to the main
2151 // frame. Currently, this is done because the main frame may override the
2152 // visibility of the page when prerendering. In order to fix this,
2153 // prerendering must be made aware of OOPIFs. https://crbug.com/440544
2154 blink::WebPageVisibilityState visibilityState =
Blink Reformat1c4d759e2017-04-09 16:34:542155 GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState()
2156 : blink::kWebPageVisibilityStateHidden;
2157 webview()->SetVisibilityState(visibilityState, false);
lfg717154072016-06-30 15:04:162158 }
[email protected]941e4552010-02-01 21:23:432159}
2160
lfg717154072016-06-30 15:04:162161void RenderViewImpl::OnPageWasShown() {
braveyao1d8ee7b2017-03-29 21:10:042162#if defined(OS_ANDROID)
2163 SuspendVideoCaptureDevices(false);
[email protected]6392d982013-04-16 16:59:222164#endif
2165
lfg717154072016-06-30 15:04:162166 if (webview()) {
2167 blink::WebPageVisibilityState visibilityState =
Blink Reformat1c4d759e2017-04-09 16:34:542168 GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState()
2169 : blink::kWebPageVisibilityStateVisible;
2170 webview()->SetVisibilityState(visibilityState, false);
lfg717154072016-06-30 15:04:162171 }
[email protected]a6939ca42011-02-18 17:58:072172}
[email protected]1e6e3c992010-02-08 15:52:132173
lfg8d649cc2017-04-28 18:04:302174void RenderViewImpl::OnUpdateScreenInfo(const ScreenInfo& screen_info) {
2175 // This IPC only updates the screen info on RenderViews that have a remote
2176 // main frame. For local main frames, the ScreenInfo is updated in
2177 // ViewMsg_Resize.
2178 if (!main_render_frame_)
2179 screen_info_ = screen_info;
2180}
2181
[email protected]ed7defa2013-03-12 21:29:592182GURL RenderViewImpl::GetURLForGraphicsContext3D() {
2183 DCHECK(webview());
Blink Reformat1c4d759e2017-04-09 16:34:542184 if (webview()->MainFrame()->IsWebLocalFrame())
lukaszabedb4b22017-06-23 00:00:132185 return GURL(webview()->MainFrame()->ToWebLocalFrame()->GetDocument().Url());
[email protected]ed7defa2013-03-12 21:29:592186 else
2187 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]65225772011-05-12 21:10:242188}
2189
[email protected]310ebd6302011-10-10 19:06:282190void RenderViewImpl::OnSetFocus(bool enable) {
naskoc6edf7e2015-10-16 01:48:452191 // This message must always be received when the main frame is a
2192 // WebLocalFrame.
Blink Reformat1c4d759e2017-04-09 16:34:542193 CHECK(webview()->MainFrame()->IsWebLocalFrame());
alexmos3fcd0ca2015-10-23 18:18:332194 SetFocus(enable);
2195}
alexmos7fac9aeb2015-10-16 22:39:492196
alexmos3fcd0ca2015-10-23 18:18:332197void RenderViewImpl::SetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:132198 RenderWidget::OnSetFocus(enable);
2199
[email protected]321032992012-11-08 01:01:272200 // Notify all BrowserPlugins of the RenderView's focus state.
fsamuel6c1dfeb2014-12-18 19:21:332201 if (BrowserPluginManager::Get())
2202 BrowserPluginManager::Get()->UpdateFocusState();
[email protected]1e6e3c992010-02-08 15:52:132203}
[email protected]941e4552010-02-01 21:23:432204
rouslanf7ebd8832015-01-22 01:54:142205void RenderViewImpl::DidCompletePageScaleAnimation() {
ekaramad27ca69b12017-04-20 18:34:292206 if (auto* focused_frame = GetWebView()->FocusedFrame()) {
2207 if (focused_frame->AutofillClient())
2208 focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame();
2209 }
rouslanf7ebd8832015-01-22 01:54:142210}
2211
oshimad5279032015-12-16 18:22:332212void RenderViewImpl::OnDeviceScaleFactorChanged() {
2213 RenderWidget::OnDeviceScaleFactorChanged();
2214 UpdateWebViewWithDeviceScaleFactor();
2215 if (auto_resize_mode_)
2216 AutoResizeCompositor();
2217}
2218
[email protected]b2e4c70132013-10-03 02:07:512219void RenderViewImpl::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:202220 bool enabled,
2221 const blink::WebDeviceEmulationParams& params) {
[email protected]404630b2014-07-03 19:33:032222 if (webview() && compositor()) {
dgozman9260b0a12015-03-16 13:45:202223 if (enabled)
Blink Reformat1c4d759e2017-04-09 16:34:542224 webview()->EnableDeviceEmulation(params);
dgozman9260b0a12015-03-16 13:45:202225 else
Blink Reformat1c4d759e2017-04-09 16:34:542226 webview()->DisableDeviceEmulation();
[email protected]b2e4c70132013-10-03 02:07:512227 }
2228}
2229
Blink Reformat1c4d759e2017-04-09 16:34:542230blink::WebSpeechRecognizer* RenderViewImpl::SpeechRecognizer() {
[email protected]64d09222012-05-25 10:10:342231 if (!speech_recognition_dispatcher_)
2232 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
[email protected]64d09222012-05-25 10:10:342233 return speech_recognition_dispatcher_;
2234}
2235
Blink Reformat1c4d759e2017-04-09 16:34:542236void RenderViewImpl::ZoomLimitsChanged(double minimum_level,
[email protected]310ebd6302011-10-10 19:06:282237 double maximum_level) {
a.sarkar.arundaadc712015-02-26 05:39:082238 // Round the double to avoid returning incorrect minimum/maximum zoom
2239 // percentages.
2240 int minimum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492241 ZoomLevelToZoomFactor(minimum_level) * 100);
a.sarkar.arundaadc712015-02-26 05:39:082242 int maximum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492243 ZoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:252244
avia3dca182016-03-19 01:09:522245 Send(new ViewHostMsg_UpdateZoomLimits(GetRoutingID(), minimum_percent,
fsamuele8326c742016-01-12 00:49:392246 maximum_percent));
[email protected]b75b8292010-10-01 07:28:252247}
2248
Blink Reformat1c4d759e2017-04-09 16:34:542249void RenderViewImpl::PageScaleFactorChanged() {
ccameronb7c1d6c2015-03-09 17:08:242250 if (!webview())
2251 return;
mcnee432e47d2015-11-09 19:37:462252
avia3dca182016-03-19 01:09:522253 Send(new ViewHostMsg_PageScaleFactorChanged(GetRoutingID(),
Blink Reformat1c4d759e2017-04-09 16:34:542254 webview()->PageScaleFactor()));
ccameronb7c1d6c2015-03-09 17:08:242255}
2256
[email protected]7940b8e2013-07-25 23:08:492257double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const {
2258 return ZoomLevelToZoomFactor(zoom_level);
2259}
2260
2261double RenderViewImpl::zoomFactorToZoomLevel(double factor) const {
2262 return ZoomFactorToZoomLevel(factor);
2263}
2264
Blink Reformat1c4d759e2017-04-09 16:34:542265void RenderViewImpl::PageImportanceSignalsChanged() {
kouhei40f03cb2015-09-24 07:47:012266 if (!webview() || !main_render_frame_)
2267 return;
2268
Blink Reformat1c4d759e2017-04-09 16:34:542269 auto* web_signals = webview()->PageImportanceSignals();
kouhei40f03cb2015-09-24 07:47:012270
2271 PageImportanceSignals signals;
Blink Reformat1c4d759e2017-04-09 16:34:542272 signals.had_form_interaction = web_signals->HadFormInteraction();
kouhei40f03cb2015-09-24 07:47:012273
2274 main_render_frame_->Send(new FrameHostMsg_UpdatePageImportanceSignals(
2275 main_render_frame_->GetRoutingID(), signals));
2276}
2277
[email protected]20657a82012-08-21 20:23:032278#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:542279bool RenderViewImpl::OpenDateTimeChooser(
[email protected]180ef242013-11-07 06:50:462280 const blink::WebDateTimeChooserParams& params,
2281 blink::WebDateTimeChooserCompletion* completion) {
[email protected]e8072562013-12-04 06:04:132282 // JavaScript may try to open a date time chooser while one is already open.
2283 if (date_time_picker_client_)
2284 return false;
[email protected]b18583c2012-12-18 06:55:272285 date_time_picker_client_.reset(
2286 new RendererDateTimePicker(this, params, completion));
2287 return date_time_picker_client_->Open();
2288}
2289
[email protected]e8072562013-12-04 06:04:132290void RenderViewImpl::DismissDateTimeDialog() {
2291 DCHECK(date_time_picker_client_);
Lei Zhang88f23ba2017-10-27 05:56:262292 date_time_picker_client_.reset();
[email protected]e8072562013-12-04 06:04:132293}
[email protected]e8072562013-12-04 06:04:132294
Blink Reformat1c4d759e2017-04-09 16:34:542295bool RenderViewImpl::DidTapMultipleTargets(
timav29a8d0f62014-09-25 20:45:532296 const WebSize& inner_viewport_offset,
2297 const WebRect& touch_rect,
[email protected]f9526d12012-10-18 01:55:032298 const WebVector<WebRect>& target_rects) {
[email protected]8d3dfee62013-06-19 05:50:332299 // Never show a disambiguation popup when accessibility is enabled,
2300 // as this interferes with "touch exploration".
Doug Turner63f3c7b2017-07-29 05:10:012301 ui::AXMode accessibility_mode = GetMainRenderFrame()->accessibility_mode();
2302 if (accessibility_mode == ui::kAXModeComplete)
[email protected]8d3dfee62013-06-19 05:50:332303 return false;
2304
timav29a8d0f62014-09-25 20:45:532305 // The touch_rect, target_rects and zoom_rect are in the outer viewport
2306 // reference frame.
[email protected]f9526d12012-10-18 01:55:032307 gfx::Rect zoom_rect;
[email protected]70221f02013-01-31 22:17:072308 float new_total_scale =
2309 DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
timav29a8d0f62014-09-25 20:45:532310 touch_rect, target_rects, GetSize(),
Blink Reformat1c4d759e2017-04-09 16:34:542311 gfx::Rect(webview()->MainFrame()->VisibleContentRect()).size(),
2312 device_scale_factor_ * webview()->PageScaleFactor(), &zoom_rect);
jbauman0ed09182015-01-30 22:33:492313 if (!new_total_scale || zoom_rect.IsEmpty())
[email protected]f9526d12012-10-18 01:55:032314 return false;
2315
[email protected]4ded1dbf2013-08-28 21:11:032316 bool handled = false;
2317 switch (renderer_preferences_.tap_multiple_targets_strategy) {
2318 case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM:
Blink Reformat1c4d759e2017-04-09 16:34:542319 handled = webview()->ZoomToMultipleTargetsRect(zoom_rect);
[email protected]4ded1dbf2013-08-28 21:11:032320 break;
2321 case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: {
[email protected]bc2804d2013-08-06 07:45:492322 gfx::Size canvas_size =
danakjddaec912015-09-25 19:38:402323 gfx::ScaleToCeiledSize(zoom_rect.size(), new_total_scale);
Fady Samuel4b5f9862017-07-11 05:27:202324 viz::SharedBitmapManager* manager =
[email protected]cb189e062014-04-23 00:57:012325 RenderThreadImpl::current()->shared_bitmap_manager();
Fady Samuel4b5f9862017-07-11 05:27:202326 std::unique_ptr<viz::SharedBitmap> shared_bitmap =
[email protected]cb189e062014-04-23 00:57:012327 manager->AllocateSharedBitmap(canvas_size);
Lei Zhang88f23ba2017-10-27 05:56:262328 CHECK(shared_bitmap);
[email protected]bc2804d2013-08-06 07:45:492329 {
[email protected]cb189e062014-04-23 00:57:012330 SkBitmap bitmap;
2331 SkImageInfo info = SkImageInfo::MakeN32Premul(canvas_size.width(),
2332 canvas_size.height());
2333 bitmap.installPixels(info, shared_bitmap->pixels(), info.minRowBytes());
enne98c9f8052017-03-15 19:38:222334 cc::SkiaPaintCanvas canvas(bitmap);
[email protected]f9526d12012-10-18 01:55:032335
[email protected]bc2804d2013-08-06 07:45:492336 // TODO(trchen): Cleanup the device scale factor mess.
2337 // device scale will be applied in WebKit
2338 // --> zoom_rect doesn't include device scale,
2339 // but WebKit will still draw on zoom_rect * device_scale_factor_
[email protected]cb189e062014-04-23 00:57:012340 canvas.scale(new_total_scale / device_scale_factor_,
2341 new_total_scale / device_scale_factor_);
2342 canvas.translate(-zoom_rect.x() * device_scale_factor_,
2343 -zoom_rect.y() * device_scale_factor_);
[email protected]f9526d12012-10-18 01:55:032344
Blink Reformat1c4d759e2017-04-09 16:34:542345 DCHECK(webview_->IsAcceleratedCompositingActive());
2346 webview_->PaintIgnoringCompositing(&canvas, zoom_rect);
[email protected]bc2804d2013-08-06 07:45:492347 }
2348
timav29a8d0f62014-09-25 20:45:532349 gfx::Rect zoom_rect_in_screen =
2350 zoom_rect - gfx::Vector2d(inner_viewport_offset.width,
2351 inner_viewport_offset.height);
2352
[email protected]bc2804d2013-08-06 07:45:492353 gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect(
timav29a8d0f62014-09-25 20:45:532354 ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect_in_screen)));
2355
fsamuele8326c742016-01-12 00:49:392356 Send(new ViewHostMsg_ShowDisambiguationPopup(
avia3dca182016-03-19 01:09:522357 GetRoutingID(), physical_window_zoom_rect, canvas_size,
fsamuele8326c742016-01-12 00:49:392358 shared_bitmap->id()));
Fady Samuel4b5f9862017-07-11 05:27:202359 viz::SharedBitmapId id = shared_bitmap->id();
Lei Zhang88f23ba2017-10-27 05:56:262360 disambiguation_bitmaps_[id] = std::move(shared_bitmap);
[email protected]4ded1dbf2013-08-28 21:11:032361 handled = true;
2362 break;
2363 }
2364 case TAP_MULTIPLE_TARGETS_STRATEGY_NONE:
2365 // No-op.
2366 break;
[email protected]f9526d12012-10-18 01:55:032367 }
[email protected]70221f02013-01-31 22:17:072368
[email protected]4ded1dbf2013-08-28 21:11:032369 return handled;
[email protected]f9526d12012-10-18 01:55:032370}
braveyao1d8ee7b2017-03-29 21:10:042371
2372void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) {
tsunghunga86cde72017-04-10 22:27:132373#if BUILDFLAG(ENABLE_WEBRTC)
braveyao1d8ee7b2017-03-29 21:10:042374 if (!main_render_frame_)
2375 return;
2376
2377 MediaStreamDispatcher* media_stream_dispatcher =
2378 main_render_frame_->GetMediaStreamDispatcher();
2379 if (!media_stream_dispatcher)
2380 return;
2381
Chandan Padhi6dbfb732017-09-01 16:08:492382 MediaStreamDevices video_devices =
braveyao1d8ee7b2017-03-29 21:10:042383 media_stream_dispatcher->GetNonScreenCaptureDevices();
2384 RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices(
Chandan Padhi6dbfb732017-09-01 16:08:492385 video_devices, suspend);
tsunghunga86cde72017-04-10 22:27:132386#endif // BUILDFLAG(ENABLE_WEBRTC)
braveyao1d8ee7b2017-03-29 21:10:042387}
estade6b9696bd2016-05-04 23:51:362388#endif // defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:032389
[email protected]b283d292013-02-21 08:40:342390unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
2391 return history_list_length_;
2392}
2393
[email protected]cc290f902013-03-04 20:06:022394void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
2395 if (enable) {
2396 if (has_focus())
2397 return;
2398 OnSetActive(true);
2399 OnSetFocus(true);
2400 } else {
2401 if (!has_focus())
2402 return;
2403 OnSetFocus(false);
2404 OnSetActive(false);
2405 }
2406}
2407
[email protected]3a1c8a8032013-03-18 22:35:322408void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) {
fsamuel664e8b62016-01-20 19:54:012409 ResizeParams params;
[email protected]b54fe452013-06-07 14:01:532410 params.screen_info = screen_info_;
ccameron2f451532016-09-07 21:49:272411 params.screen_info.device_scale_factor = factor;
[email protected]b54fe452013-06-07 14:01:532412 params.new_size = size();
bokanf0fd2412014-10-30 15:28:552413 params.visible_viewport_size = visible_viewport_size_;
danakjddaec912015-09-25 19:38:402414 params.physical_backing_size = gfx::ScaleToCeiledSize(size(), factor);
mdjones2ee41afd2016-10-27 16:50:202415 params.browser_controls_shrink_blink_size = false;
dtrainorcb7779b82014-12-04 01:08:022416 params.top_controls_height = 0.f;
mikhail.pozdnyakovf2c902a2015-04-14 08:09:122417 params.is_fullscreen_granted = is_fullscreen_granted();
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122418 params.display_mode = display_mode_;
[email protected]b54fe452013-06-07 14:01:532419 OnResize(params);
[email protected]3a1c8a8032013-03-18 22:35:322420}
2421
ccameron39b1cbc2017-07-06 00:23:552422void RenderViewImpl::SetDeviceColorSpaceForTesting(
2423 const gfx::ColorSpace& color_space) {
mlamouriafca06dd2017-01-27 23:35:182424 ResizeParams params;
2425 params.screen_info = screen_info_;
ccameron39b1cbc2017-07-06 00:23:552426 params.screen_info.color_space = color_space;
mlamouriafca06dd2017-01-27 23:35:182427 params.new_size = size();
2428 params.visible_viewport_size = visible_viewport_size_;
2429 params.physical_backing_size = physical_backing_size_;
2430 params.browser_controls_shrink_blink_size = false;
2431 params.top_controls_height = 0.f;
2432 params.is_fullscreen_granted = is_fullscreen_granted();
2433 params.display_mode = display_mode_;
2434 OnResize(params);
2435}
2436
[email protected]92650162013-10-30 03:31:022437void RenderViewImpl::ForceResizeForTesting(const gfx::Size& new_size) {
Blink Reformat1c4d759e2017-04-09 16:34:542438 gfx::Rect new_window_rect(RootWindowRect().x, RootWindowRect().y,
2439 new_size.width(), new_size.height());
bokanc007c3a2015-02-03 07:15:562440 SetWindowRectSynchronously(new_window_rect);
[email protected]92650162013-10-30 03:31:022441}
2442
[email protected]5b45ad42013-10-25 00:42:042443void RenderViewImpl::UseSynchronousResizeModeForTesting(bool enable) {
2444 resizing_mode_selector_->set_is_synchronous_mode(enable);
2445}
2446
[email protected]eac2b362013-05-22 07:01:452447void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size,
2448 const gfx::Size& max_size) {
2449 OnEnableAutoResize(min_size, max_size);
2450}
2451
2452void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) {
2453 OnDisableAutoResize(new_size);
2454}
2455
[email protected]cb189e062014-04-23 00:57:012456void RenderViewImpl::OnReleaseDisambiguationPopupBitmap(
Fady Samuel4b5f9862017-07-11 05:27:202457 const viz::SharedBitmapId& id) {
Lei Zhang88f23ba2017-10-27 05:56:262458 size_t erased_count = disambiguation_bitmaps_.erase(id);
2459 DCHECK_EQ(1U, erased_count);
[email protected]f9526d12012-10-18 01:55:032460}
[email protected]e9ff79c2012-10-19 21:31:262461
aelias1b55156e52017-04-01 00:46:052462void RenderViewImpl::OnResolveTapDisambiguation(double timestamp_seconds,
2463 gfx::Point tap_viewport_offset,
2464 bool is_long_press) {
Blink Reformat1c4d759e2017-04-09 16:34:542465 webview()->ResolveTapDisambiguation(timestamp_seconds, tap_viewport_offset,
aelias1b55156e52017-04-01 00:46:052466 is_long_press);
2467}
2468
[email protected]6fceb912013-02-15 06:24:152469void RenderViewImpl::DidCommitCompositorFrame() {
2470 RenderWidget::DidCommitCompositorFrame();
ericwilligers88e69742016-10-17 19:29:552471 for (auto& observer : observers_)
2472 observer.DidCommitCompositorFrame();
[email protected]6fceb912013-02-15 06:24:152473}
2474
oshimad5279032015-12-16 18:22:332475void RenderViewImpl::UpdateWebViewWithDeviceScaleFactor() {
2476 if (!webview())
2477 return;
oshima750cb4342015-10-31 00:59:012478 if (IsUseZoomForDSFEnabled()) {
Blink Reformat1c4d759e2017-04-09 16:34:542479 webview()->SetZoomFactorForDeviceScaleFactor(device_scale_factor_);
oshima750cb4342015-10-31 00:59:012480 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542481 webview()->SetDeviceScaleFactor(device_scale_factor_);
oshima750cb4342015-10-31 00:59:012482 }
Blink Reformat1c4d759e2017-04-09 16:34:542483 webview()->GetSettings()->SetPreferCompositingToLCDTextEnabled(
oshimad5279032015-12-16 18:22:332484 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_));
oshima750cb4342015-10-31 00:59:012485}
2486
dtapuska1b0fcc322016-10-28 18:08:282487void RenderViewImpl::OnDiscardInputEvent(
2488 const blink::WebInputEvent* input_event,
nzolghadr5d8596502017-01-23 22:59:352489 const std::vector<const blink::WebInputEvent*>& coalesced_events,
dtapuska1b0fcc322016-10-28 18:08:282490 const ui::LatencyInfo& latency_info,
2491 InputEventDispatchType dispatch_type) {
dtapuska9ec1a912017-04-21 15:18:312492 if (!input_event || dispatch_type == DISPATCH_TYPE_NON_BLOCKING) {
dtapuska1b0fcc322016-10-28 18:08:282493 return;
2494 }
2495
Dave Tapuskaea83d3bd2017-06-13 16:14:552496 InputEventAck ack(InputEventAckSource::MAIN_THREAD, input_event->GetType(),
2497 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2498 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
dtapuska1b0fcc322016-10-28 18:08:282499}
2500
Dave Tapuskaea83d3bd2017-06-13 16:14:552501void RenderViewImpl::HandleInputEvent(
dtapuska9ec1a912017-04-21 15:18:312502 const blink::WebCoalescedInputEvent& input_event,
2503 const ui::LatencyInfo& latency_info,
Dave Tapuskaea83d3bd2017-06-13 16:14:552504 HandledEventCallback callback) {
dtapuska9ec1a912017-04-21 15:18:312505 if (is_swapped_out_) {
Dave Tapuskaea83d3bd2017-06-13 16:14:552506 std::move(callback).Run(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, latency_info,
Dave Tapuskab28a1082017-08-30 15:37:262507 nullptr, base::nullopt);
Dave Tapuskaea83d3bd2017-06-13 16:14:552508 return;
dtapuska9ec1a912017-04-21 15:18:312509 }
2510 idle_user_detector_->ActivityDetected();
Dave Tapuskaea83d3bd2017-06-13 16:14:552511 RenderWidget::HandleInputEvent(input_event, latency_info,
2512 std::move(callback));
dtapuska9ec1a912017-04-21 15:18:312513}
2514
[email protected]e9ff79c2012-10-19 21:31:262515} // namespace content