blob: 2cec6d9592482f086df2d5f70a2b0ddd0a7a3b37 [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>
initial.commit09911bf2008-07-26 23:55:2910
[email protected]5d4e36d2013-02-15 15:18:2011#include "base/auto_reset.h"
[email protected]6e806822011-11-19 01:51:0812#include "base/bind.h"
13#include "base/bind_helpers.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5015#include "base/compiler_specific.h"
[email protected]2132d6b2013-06-05 00:15:4316#include "base/debug/alias.h"
avayvod232757942017-04-29 04:12:3417#include "base/feature_list.h"
[email protected]728c2ee2013-06-25 04:01:0718#include "base/files/file_path.h"
[email protected]edc3af82013-12-12 21:24:0719#include "base/i18n/rtl.h"
[email protected]b1cf3372011-04-20 21:28:1020#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4921#include "base/lazy_instance.h"
fdoray7a8954a42016-06-07 04:28:3822#include "base/location.h"
dchengcedca5612016-04-09 01:40:1523#include "base/memory/ptr_util.h"
[email protected]f29efe6b2014-06-09 05:01:5124#include "base/metrics/field_trial.h"
asvitkine8d51e9d2016-09-02 23:55:4325#include "base/metrics/histogram_macros.h"
[email protected]d3b4ee22013-07-24 22:50:0626#include "base/process/kill.h"
[email protected]7d08a9352013-10-15 08:24:5627#include "base/process/process.h"
fdoray7a8954a42016-06-07 04:28:3828#include "base/single_thread_task_runner.h"
[email protected]21aa99682013-06-11 07:17:0129#include "base/strings/string_number_conversions.h"
[email protected]b9e7c479f2013-04-12 04:33:2430#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4931#include "base/strings/string_split.h"
[email protected]21aa99682013-06-11 07:17:0132#include "base/strings/string_util.h"
[email protected]40d11e02013-03-28 17:43:1433#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0034#include "base/strings/utf_string_conversions.h"
dalecurtiscd971252016-09-21 16:09:0035#include "base/sys_info.h"
fdoray7a8954a42016-06-07 04:28:3836#include "base/threading/thread_task_runner_handle.h"
[email protected]abb522162013-06-28 01:54:1637#include "base/time/time.h"
primiano9e38d552015-01-28 04:18:0138#include "base/trace_event/trace_event.h"
avi1023d012015-12-25 02:39:1439#include "build/build_config.h"
dongseong.hwange095dfa2016-02-04 11:21:3940#include "cc/base/switches.h"
enne98c9f8052017-03-15 19:38:2241#include "cc/paint/skia_paint_canvas.h"
[email protected]a8cb3b73b2013-08-12 05:50:5042#include "content/child/appcache/appcache_dispatcher.h"
43#include "content/child/appcache/web_application_cache_host_impl.h"
[email protected]541b7b02013-06-07 00:59:3444#include "content/child/request_extra_data.h"
mek87e0ab52015-02-13 01:18:2645#include "content/child/v8_value_converter_impl.h"
[email protected]10208ea2013-06-06 20:08:0346#include "content/child/webmessageportchannel_impl.h"
jinho.bang632a1a722014-09-18 03:02:5647#include "content/common/content_constants_internal.h"
oshima750cb4342015-10-31 00:59:0148#include "content/common/content_switches_internal.h"
[email protected]5f2aa722013-08-07 16:59:4149#include "content/common/dom_storage/dom_storage_types.h"
[email protected]59f4f2fa2011-03-23 01:00:5550#include "content/common/drag_messages.h"
[email protected]c6bc20332014-02-28 18:30:3951#include "content/common/frame_messages.h"
alexmosbc7eafa2014-12-06 01:38:0952#include "content/common/frame_replication_state.h"
[email protected]c084330e02013-04-27 01:08:1553#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0754#include "content/common/page_messages.h"
rockot5c478a72016-09-28 23:14:1855#include "content/common/render_message_filter.mojom.h"
[email protected]778574e2011-03-21 22:03:5056#include "content/common/view_messages.h"
csharrison95f01e922017-04-24 18:52:3557#include "content/public/common/associated_interface_provider.h"
[email protected]e091df82011-10-11 18:13:2158#include "content/public/common/bindings_policy.h"
arthursonzognic517fc32016-08-11 11:04:2459#include "content/public/common/browser_side_navigation_policy.h"
[email protected]744c2a22012-03-15 18:42:0460#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4861#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2962#include "content/public/common/content_switches.h"
kouhei40f03cb2015-09-24 07:47:0163#include "content/public/common/page_importance_signals.h"
clamyda97e8322014-10-07 21:57:2564#include "content/public/common/page_state.h"
[email protected]7940b8e2013-07-25 23:08:4965#include "content/public/common/page_zoom.h"
[email protected]818915cd2012-11-20 13:14:1166#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0367#include "content/public/common/url_constants.h"
[email protected]b3a97b52014-07-09 06:25:0568#include "content/public/common/web_preferences.h"
[email protected]d344114c2011-10-01 01:24:3469#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0770#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3271#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4472#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3673#include "content/public/renderer/render_view_visitor.h"
scottmg8e6c6082017-02-13 23:15:4874#include "content/public/renderer/window_features_converter.h"
[email protected]e6e56752012-08-10 00:46:0675#include "content/renderer/browser_plugin/browser_plugin.h"
76#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]1910fe82012-05-10 00:04:1077#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]dc293a72013-07-01 11:11:2278#include "content/renderer/drop_data_builder.h"
[email protected]ba91a792013-02-06 09:48:2879#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]dc064352014-04-25 08:36:3880#include "content/renderer/history_serialization.h"
[email protected]1784b2f2011-11-24 10:53:4881#include "content/renderer/idle_user_detector.h"
[email protected]66fca5bc2013-05-23 06:58:2982#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1383#include "content/renderer/input/input_handler_manager.h"
[email protected]92d457802013-04-01 19:18:4984#include "content/renderer/internal_document_state_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"
nhiroki2820b8b2017-01-10 08:13:3097#include "content/renderer/shared_worker/websharedworker_proxy.h"
[email protected]64d09222012-05-25 10:10:3498#include "content/renderer/speech_recognition_dispatcher.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"
servolk8b3b39b2015-03-03 19:08:18104#include "media/renderers/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"
xlai11ac7802017-04-07 20:13:18111#include "services/ui/public/cpp/bitmap/child_shared_bitmap_manager.h"
lukenb171b532014-09-24 05:50:38112#include "skia/ext/platform_canvas.h"
kinukob473f002016-02-22 05:23:19113#include "third_party/WebKit/public/platform/FilePathConversion.h"
brettwdfbcc3b2016-01-20 01:49:17114#include "third_party/WebKit/public/platform/URLConversion.h"
[email protected]b3a97b52014-07-09 06:25:05115#include "third_party/WebKit/public/platform/WebConnectionType.h"
[email protected]d0fcff72013-07-23 02:45:43116#include "third_party/WebKit/public/platform/WebHTTPBody.h"
117#include "third_party/WebKit/public/platform/WebImage.h"
dtapuska836e1f92016-11-15 00:38:06118#include "third_party/WebKit/public/platform/WebInputEvent.h"
skyostilcff62882017-01-28 13:18:04119#include "third_party/WebKit/public/platform/WebInputEventResult.h"
[email protected]d0fcff72013-07-23 02:45:43120#include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
121#include "third_party/WebKit/public/platform/WebPoint.h"
122#include "third_party/WebKit/public/platform/WebRect.h"
nverne61d2da872017-05-24 10:15:30123#include "third_party/WebKit/public/platform/WebRuntimeFeatures.h"
[email protected]d0fcff72013-07-23 02:45:43124#include "third_party/WebKit/public/platform/WebSize.h"
[email protected]ec173b522013-11-14 11:01:18125#include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h"
[email protected]d0fcff72013-07-23 02:45:43126#include "third_party/WebKit/public/platform/WebString.h"
127#include "third_party/WebKit/public/platform/WebURL.h"
128#include "third_party/WebKit/public/platform/WebURLError.h"
129#include "third_party/WebKit/public/platform/WebURLRequest.h"
130#include "third_party/WebKit/public/platform/WebURLResponse.h"
131#include "third_party/WebKit/public/platform/WebVector.h"
brettw8a274fa2016-11-15 00:20:40132#include "third_party/WebKit/public/public_features.h"
[email protected]10760e4a2013-09-04 23:32:20133#include "third_party/WebKit/public/web/WebAXObject.h"
ekaramad27ca69b12017-04-20 18:34:29134#include "third_party/WebKit/public/web/WebAutofillClient.h"
[email protected]8bc5ff02013-11-29 06:34:03135#include "third_party/WebKit/public/web/WebColorSuggestion.h"
[email protected]2255a9332013-06-17 05:12:31136#include "third_party/WebKit/public/web/WebDOMEvent.h"
137#include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
138#include "third_party/WebKit/public/web/WebDataSource.h"
139#include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h"
140#include "third_party/WebKit/public/web/WebDateTimeChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31141#include "third_party/WebKit/public/web/WebDocument.h"
142#include "third_party/WebKit/public/web/WebElement.h"
143#include "third_party/WebKit/public/web/WebFileChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31144#include "third_party/WebKit/public/web/WebFormControlElement.h"
145#include "third_party/WebKit/public/web/WebFormElement.h"
146#include "third_party/WebKit/public/web/WebFrame.h"
dglazkov03223492016-02-08 22:16:03147#include "third_party/WebKit/public/web/WebFrameContentDumper.h"
lfgcaab5142016-02-26 19:06:52148#include "third_party/WebKit/public/web/WebFrameWidget.h"
[email protected]2255a9332013-06-17 05:12:31149#include "third_party/WebKit/public/web/WebHistoryItem.h"
[email protected]91dcc6d32014-07-30 00:01:33150#include "third_party/WebKit/public/web/WebHitTestResult.h"
[email protected]2255a9332013-06-17 05:12:31151#include "third_party/WebKit/public/web/WebInputElement.h"
[email protected]35b2a972014-04-04 15:50:22152#include "third_party/WebKit/public/web/WebLocalFrame.h"
[email protected]2255a9332013-06-17 05:12:31153#include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
154#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
kouhei40f03cb2015-09-24 07:47:01155#include "third_party/WebKit/public/web/WebPageImportanceSignals.h"
[email protected]2255a9332013-06-17 05:12:31156#include "third_party/WebKit/public/web/WebPlugin.h"
157#include "third_party/WebKit/public/web/WebPluginAction.h"
[email protected]2255a9332013-06-17 05:12:31158#include "third_party/WebKit/public/web/WebRange.h"
ellyjones8ae17692016-08-05 15:19:21159#include "third_party/WebKit/public/web/WebRenderTheme.h"
[email protected]2255a9332013-06-17 05:12:31160#include "third_party/WebKit/public/web/WebScriptSource.h"
161#include "third_party/WebKit/public/web/WebSearchableFormData.h"
[email protected]2255a9332013-06-17 05:12:31162#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
[email protected]2255a9332013-06-17 05:12:31163#include "third_party/WebKit/public/web/WebSettings.h"
[email protected]2255a9332013-06-17 05:12:31164#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
[email protected]2255a9332013-06-17 05:12:31165#include "third_party/WebKit/public/web/WebView.h"
166#include "third_party/WebKit/public/web/WebWindowFeatures.h"
[email protected]b3a97b52014-07-09 06:25:05167#include "third_party/icu/source/common/unicode/uchar.h"
168#include "third_party/icu/source/common/unicode/uscript.h"
esecklerf2bd55f72017-03-31 09:11:57169#include "third_party/skia/include/core/SkColor.h"
[email protected]1400e6dc2013-04-27 02:36:27170#include "ui/base/ui_base_switches_util.h"
tfarina655f81d2014-12-23 02:38:50171#include "ui/gfx/geometry/point.h"
tfarina3b0452d2014-12-31 15:20:09172#include "ui/gfx/geometry/rect.h"
173#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32174#include "ui/gfx/geometry/size_conversions.h"
[email protected]08397d52011-02-05 01:53:38175#include "ui/gfx/native_widget_types.h"
ccameron772317d2017-06-04 18:35:03176#include "ui/gfx/switches.h"
mfomitchev3ba450ad2017-04-03 18:20:40177#include "ui/latency/latency_info.h"
csharrisond88f9752016-10-26 23:56:36178#include "url/origin.h"
markdittmer67b71ea2016-03-03 22:40:03179#include "url/url_constants.h"
[email protected]c4a9e932011-03-05 04:05:55180#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:29181
[email protected]25fb9b32012-04-27 03:21:55182#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25183#include <cpu-features.h>
184
dalecurtiscd971252016-09-21 16:09:00185#include "base/android/build_info.h"
estade6b9696bd2016-05-04 23:51:36186#include "content/renderer/android/disambiguation_popup_helper.h"
tfarina3b0452d2014-12-31 15:20:09187#include "ui/gfx/geometry/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40188
[email protected]78043bdd2010-04-05 18:45:33189#elif defined(OS_MACOSX)
190#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57191#endif
192
brettw4b461082016-11-19 18:55:16193#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]ea2fb972013-08-07 05:44:26194#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
195#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26196#endif
197
Brett Wilson0748bf412016-11-22 17:55:46198#if BUILDFLAG(ENABLE_WEBRTC)
[email protected]9ac667e2013-09-09 12:49:21199#include "content/renderer/media/rtc_peer_connection_handler.h"
[email protected]22fe91d2014-08-12 17:07:12200#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
[email protected]9ac667e2013-09-09 12:49:21201#endif
202
[email protected]180ef242013-11-07 06:50:46203using blink::WebAXObject;
204using blink::WebApplicationCacheHost;
205using blink::WebApplicationCacheHostClient;
[email protected]180ef242013-11-07 06:50:46206using blink::WebColor;
[email protected]180ef242013-11-07 06:50:46207using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46208using blink::WebData;
209using blink::WebDataSource;
210using blink::WebDocument;
[email protected]180ef242013-11-07 06:50:46211using blink::WebDragOperation;
[email protected]180ef242013-11-07 06:50:46212using blink::WebElement;
[email protected]180ef242013-11-07 06:50:46213using blink::WebFileChooserCompletion;
[email protected]180ef242013-11-07 06:50:46214using blink::WebFormControlElement;
215using blink::WebFormElement;
216using blink::WebFrame;
dglazkov03223492016-02-08 22:16:03217using blink::WebFrameContentDumper;
[email protected]180ef242013-11-07 06:50:46218using blink::WebGestureEvent;
219using blink::WebHistoryItem;
220using blink::WebHTTPBody;
dglazkov8d0c21dd2016-08-06 15:56:36221using blink::WebHitTestResult;
[email protected]180ef242013-11-07 06:50:46222using blink::WebImage;
223using blink::WebInputElement;
224using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22225using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46226using blink::WebMediaPlayerAction;
[email protected]180ef242013-11-07 06:50:46227using blink::WebMouseEvent;
228using blink::WebNavigationPolicy;
229using blink::WebNavigationType;
230using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46231using blink::WebPluginAction;
[email protected]180ef242013-11-07 06:50:46232using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46233using blink::WebRect;
234using blink::WebReferrerPolicy;
[email protected]180ef242013-11-07 06:50:46235using blink::WebScriptSource;
236using blink::WebSearchableFormData;
237using blink::WebSecurityOrigin;
238using blink::WebSecurityPolicy;
[email protected]180ef242013-11-07 06:50:46239using blink::WebSettings;
240using blink::WebSize;
[email protected]180ef242013-11-07 06:50:46241using blink::WebStorageNamespace;
242using blink::WebStorageQuotaCallbacks;
243using blink::WebStorageQuotaError;
244using blink::WebStorageQuotaType;
245using blink::WebString;
[email protected]180ef242013-11-07 06:50:46246using blink::WebTextDirection;
247using blink::WebTouchEvent;
248using blink::WebURL;
249using blink::WebURLError;
250using blink::WebURLRequest;
251using blink::WebURLResponse;
252using blink::WebUserGestureIndicator;
253using blink::WebVector;
254using blink::WebView;
255using blink::WebWidget;
256using blink::WebWindowFeatures;
[email protected]b3a97b52014-07-09 06:25:05257using blink::WebRuntimeFeatures;
[email protected]6fdd4182010-10-14 23:59:26258using base::Time;
259using base::TimeDelta;
[email protected]e1acf6f2008-10-27 20:43:33260
[email protected]20657a82012-08-21 20:23:03261
[email protected]e9ff79c2012-10-19 21:31:26262namespace content {
263
initial.commit09911bf2008-07-26 23:55:29264//-----------------------------------------------------------------------------
265
[email protected]180ef242013-11-07 06:50:46266typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
jbroman8319b232017-03-08 22:53:29267static base::LazyInstance<ViewMap>::Leaky g_view_map =
[email protected]058561b2012-12-03 06:48:22268 LAZY_INSTANCE_INITIALIZER;
scottmg5e65e3a2017-03-08 08:48:46269typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap;
jbroman8319b232017-03-08 22:53:29270static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map =
271 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02272
[email protected]882daa92009-11-05 16:31:31273// Time, in seconds, we delay before sending content state changes (such as form
274// state and scroll position) to the browser. We delay sending changes to avoid
275// spamming the browser.
276// To avoid having tab/session restore require sending a message to get the
277// current content state during tab closing we use a shorter timeout for the
278// foreground renderer. This means there is a small window of time from which
279// content state is modified and not sent to session restore, but this is
280// better than having to wake up all renderers during shutdown.
avif937e1d2014-11-02 18:13:07281const int kDelaySecondsForContentStateSyncHidden = 5;
282const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29283
dcheng35d31c112015-07-22 00:17:36284static RenderViewImpl* (*g_create_render_view_impl)(
285 CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15286 const mojom::CreateViewParams&) = nullptr;
[email protected]8d41d7612012-11-14 20:32:19287
[email protected]c6bc20332014-02-28 18:30:39288// static
[email protected]e507045d2013-07-24 15:23:44289Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56290 WebFrame* frame,
291 const WebURLRequest& request) {
Blink Reformat1c4d759e2017-04-09 16:34:54292 return Referrer(blink::WebStringToGURL(
293 request.HttpHeaderField(WebString::FromUTF8("Referer"))),
294 request.GetReferrerPolicy());
[email protected]44e55b012013-07-23 14:21:56295}
296
[email protected]c6bc20332014-02-28 18:30:39297// static
[email protected]65920f332014-03-04 21:14:18298WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32299 WebNavigationPolicy policy) {
300 switch (policy) {
Blink Reformat1c4d759e2017-04-09 16:34:54301 case blink::kWebNavigationPolicyIgnore:
nick3b04f322016-08-31 19:29:19302 return WindowOpenDisposition::IGNORE_ACTION;
Blink Reformat1c4d759e2017-04-09 16:34:54303 case blink::kWebNavigationPolicyDownload:
nick3b04f322016-08-31 19:29:19304 return WindowOpenDisposition::SAVE_TO_DISK;
Blink Reformat1c4d759e2017-04-09 16:34:54305 case blink::kWebNavigationPolicyCurrentTab:
nick3b04f322016-08-31 19:29:19306 return WindowOpenDisposition::CURRENT_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54307 case blink::kWebNavigationPolicyNewBackgroundTab:
nick3b04f322016-08-31 19:29:19308 return WindowOpenDisposition::NEW_BACKGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54309 case blink::kWebNavigationPolicyNewForegroundTab:
nick3b04f322016-08-31 19:29:19310 return WindowOpenDisposition::NEW_FOREGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54311 case blink::kWebNavigationPolicyNewWindow:
nick3b04f322016-08-31 19:29:19312 return WindowOpenDisposition::NEW_WINDOW;
Blink Reformat1c4d759e2017-04-09 16:34:54313 case blink::kWebNavigationPolicyNewPopup:
nick3b04f322016-08-31 19:29:19314 return WindowOpenDisposition::NEW_POPUP;
[email protected]48861e22013-01-09 00:27:32315 default:
316 NOTREACHED() << "Unexpected WebNavigationPolicy";
nick3b04f322016-08-31 19:29:19317 return WindowOpenDisposition::IGNORE_ACTION;
[email protected]48861e22013-01-09 00:27:32318 }
319}
320
[email protected]d8221b22013-05-23 05:35:43321// Returns true if the device scale is high enough that losing subpixel
322// antialiasing won't have a noticeable effect on text quality.
323static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
bokane6e68ae2017-03-24 00:54:44324#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
325 // On Android, we never have subpixel antialiasing. On Chrome OS we prefer to
326 // composite all scrollers so that we get animated overlay scrollbars.
[email protected]d8221b22013-05-23 05:35:43327 return true;
328#else
jdduke7d452b4a2015-08-19 21:25:21329 // 1.5 is a common touchscreen tablet device scale factor. For such
330 // devices main thread antialiasing is a heavy burden.
331 return device_scale_factor >= 1.5f;
[email protected]d8221b22013-05-23 05:35:43332#endif
[email protected]d8221b22013-05-23 05:35:43333}
334
danakj6e3bf8012014-12-16 18:27:53335static bool PreferCompositingToLCDText(CompositorDependencies* compositor_deps,
336 float device_scale_factor) {
avi83883c82014-12-23 00:08:49337 const base::CommandLine& command_line =
338 *base::CommandLine::ForCurrentProcess();
[email protected]b8ec1112014-08-17 20:09:10339 if (command_line.HasSwitch(switches::kDisablePreferCompositingToLCDText))
[email protected]fb854192013-02-06 01:30:04340 return false;
[email protected]b8ec1112014-08-17 20:09:10341 if (command_line.HasSwitch(switches::kEnablePreferCompositingToLCDText))
[email protected]fb854192013-02-06 01:30:04342 return true;
danakj6e3bf8012014-12-16 18:27:53343 if (!compositor_deps->IsLcdTextEnabled())
[email protected]10c19732014-08-18 19:39:23344 return true;
[email protected]d8221b22013-05-23 05:35:43345 return DeviceScaleEnsuresTextQuality(device_scale_factor);
346}
347
initial.commit09911bf2008-07-26 23:55:29348///////////////////////////////////////////////////////////////////////////////
349
[email protected]217690d2012-01-27 07:33:11350namespace {
351
[email protected]b3a97b52014-07-09 06:25:05352typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
353 const base::string16&,
354 UScriptCode);
355
356void SetStandardFontFamilyWrapper(WebSettings* settings,
357 const base::string16& font,
358 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54359 settings->SetStandardFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05360}
361
362void SetFixedFontFamilyWrapper(WebSettings* settings,
363 const base::string16& font,
364 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54365 settings->SetFixedFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05366}
367
368void SetSerifFontFamilyWrapper(WebSettings* settings,
369 const base::string16& font,
370 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54371 settings->SetSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05372}
373
374void SetSansSerifFontFamilyWrapper(WebSettings* settings,
375 const base::string16& font,
376 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54377 settings->SetSansSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05378}
379
380void SetCursiveFontFamilyWrapper(WebSettings* settings,
381 const base::string16& font,
382 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54383 settings->SetCursiveFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05384}
385
386void SetFantasyFontFamilyWrapper(WebSettings* settings,
387 const base::string16& font,
388 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54389 settings->SetFantasyFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05390}
391
392void SetPictographFontFamilyWrapper(WebSettings* settings,
393 const base::string16& font,
394 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54395 settings->SetPictographFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05396}
397
398// If |scriptCode| is a member of a family of "similar" script codes, returns
399// the script code in that family that is used by WebKit for font selection
400// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
401// considered equivalent for the purposes of font selection. WebKit uses the
402// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
403// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
404// uses different scripts than the ones in Chrome pref names because the version
405// of ICU included on certain ports does not have some of the newer scripts. If
406// |scriptCode| is not a member of such a family, returns |scriptCode|.
407UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
408 switch (scriptCode) {
409 case USCRIPT_HIRAGANA:
410 case USCRIPT_KATAKANA:
411 case USCRIPT_JAPANESE:
412 return USCRIPT_KATAKANA_OR_HIRAGANA;
413 case USCRIPT_KOREAN:
414 return USCRIPT_HANGUL;
415 default:
416 return scriptCode;
417 }
418}
419
420void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
421 SetFontFamilyWrapper setter,
422 WebSettings* settings) {
423 for (ScriptFontFamilyMap::const_iterator it = map.begin(); it != map.end();
424 ++it) {
avi1023d012015-12-25 02:39:14425 int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
[email protected]b3a97b52014-07-09 06:25:05426 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
427 UScriptCode code = static_cast<UScriptCode>(script);
428 (*setter)(settings, it->second, GetScriptForWebSettings(code));
429 }
430 }
431}
432
wangxianzhu3bf39be52015-04-10 23:56:41433void ApplyBlinkSettings(const base::CommandLine& command_line,
434 WebSettings* settings) {
435 if (!command_line.HasSwitch(switches::kBlinkSettings))
436 return;
437
brettw26dab8f02015-08-08 00:28:47438 std::vector<std::string> blink_settings = base::SplitString(
439 command_line.GetSwitchValueASCII(switches::kBlinkSettings),
440 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
wangxianzhu3bf39be52015-04-10 23:56:41441 for (const std::string& setting : blink_settings) {
442 size_t pos = setting.find('=');
Blink Reformat1c4d759e2017-04-09 16:34:54443 settings->SetFromStrings(
444 blink::WebString::FromLatin1(setting.substr(0, pos)),
445 blink::WebString::FromLatin1(
wangxianzhu3bf39be52015-04-10 23:56:41446 pos == std::string::npos ? "" : setting.substr(pos + 1)));
447 }
448}
449
horodbcbef42016-05-10 17:02:47450WebSettings::V8CacheStrategiesForCacheStorage
451GetV8CacheStrategiesForCacheStorage() {
452 const base::CommandLine& command_line =
453 *base::CommandLine::ForCurrentProcess();
454 std::string v8_cache_strategies = command_line.GetSwitchValueASCII(
455 switches::kV8CacheStrategiesForCacheStorage);
horoe0ff13d2016-05-27 14:47:22456 if (v8_cache_strategies.empty()) {
horodbcbef42016-05-10 17:02:47457 v8_cache_strategies =
458 base::FieldTrialList::FindFullName("V8CacheStrategiesForCacheStorage");
horoe0ff13d2016-05-27 14:47:22459 }
460
461 if (base::StartsWith(v8_cache_strategies, "none",
462 base::CompareCase::SENSITIVE)) {
Blink Reformat1c4d759e2017-04-09 16:34:54463 return WebSettings::V8CacheStrategiesForCacheStorage::kNone;
horoe0ff13d2016-05-27 14:47:22464 } else if (base::StartsWith(v8_cache_strategies, "normal",
465 base::CompareCase::SENSITIVE)) {
Blink Reformat1c4d759e2017-04-09 16:34:54466 return WebSettings::V8CacheStrategiesForCacheStorage::kNormal;
horoe0ff13d2016-05-27 14:47:22467 } else if (base::StartsWith(v8_cache_strategies, "aggressive",
468 base::CompareCase::SENSITIVE)) {
Blink Reformat1c4d759e2017-04-09 16:34:54469 return WebSettings::V8CacheStrategiesForCacheStorage::kAggressive;
horodbcbef42016-05-10 17:02:47470 } else {
Blink Reformat1c4d759e2017-04-09 16:34:54471 return WebSettings::V8CacheStrategiesForCacheStorage::kDefault;
horodbcbef42016-05-10 17:02:47472 }
473}
474
svartmetal751af1f92016-08-13 11:47:33475// This class represents promise which is robust to (will not be broken by)
476// |DidNotSwapReason::SWAP_FAILS| events.
477class AlwaysDrawSwapPromise : public cc::SwapPromise {
478 public:
479 explicit AlwaysDrawSwapPromise(const ui::LatencyInfo& latency_info)
480 : latency_info_(latency_info) {}
481
482 ~AlwaysDrawSwapPromise() override = default;
483
484 void DidActivate() override {}
485
samanse7345c82016-12-16 02:51:16486 void WillSwap(cc::CompositorFrameMetadata* metadata) override {
svartmetal751af1f92016-08-13 11:47:33487 DCHECK(!latency_info_.terminated());
488 metadata->latency_info.push_back(latency_info_);
489 }
490
samanse7345c82016-12-16 02:51:16491 void DidSwap() override {}
492
svartmetal751af1f92016-08-13 11:47:33493 DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override {
494 return reason == DidNotSwapReason::SWAP_FAILS
495 ? DidNotSwapAction::KEEP_ACTIVE
496 : DidNotSwapAction::BREAK_PROMISE;
497 }
498
499 void OnCommit() override {}
500
501 int64_t TraceId() const override { return latency_info_.trace_id(); }
502
503 private:
504 ui::LatencyInfo latency_info_;
505};
506
scottmgde42fb92017-02-10 17:56:03507content::mojom::WindowContainerType WindowFeaturesToContainerType(
scottmg05324cb2017-02-09 23:46:04508 const blink::WebWindowFeatures& window_features) {
japhetbfc47892017-06-02 23:01:19509 if (window_features.background) {
510 if (window_features.persistent)
scottmgde42fb92017-02-10 17:56:03511 return content::mojom::WindowContainerType::PERSISTENT;
scottmg05324cb2017-02-09 23:46:04512 else
scottmgde42fb92017-02-10 17:56:03513 return content::mojom::WindowContainerType::BACKGROUND;
scottmg05324cb2017-02-09 23:46:04514 } else {
scottmgde42fb92017-02-10 17:56:03515 return content::mojom::WindowContainerType::NORMAL;
scottmg05324cb2017-02-09 23:46:04516 }
517}
518
[email protected]217690d2012-01-27 07:33:11519} // namespace
520
dcheng35d31c112015-07-22 00:17:36521RenderViewImpl::RenderViewImpl(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15522 const mojom::CreateViewParams& params)
nick8331f8ad2016-11-15 20:42:45523 : RenderWidget(params.view_id,
524 compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54525 blink::kWebPopupTypeNone,
naskobd911332014-11-25 01:13:36526 params.initial_size.screen_info,
527 params.swapped_out,
528 params.hidden,
529 params.never_visible),
530 webkit_preferences_(params.web_preferences),
avif937e1d2014-11-02 18:13:07531 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09532 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02533 send_preferred_size_changes_(false),
[email protected]e75cb49e2009-01-05 23:13:21534 navigation_gesture_(NavigationGestureUnknown),
[email protected]3cc72b12010-03-18 23:03:00535 history_list_offset_(-1),
536 history_list_length_(0),
[email protected]7e9523b2014-03-25 03:02:42537 frames_in_progress_(0),
[email protected]3354d3e2010-06-10 19:53:02538 target_url_status_(TARGET_NONE),
[email protected]d42bf472014-06-14 01:49:38539 uses_temporary_zoom_level_(false),
[email protected]bbc8856d2013-06-14 10:37:04540#if defined(OS_ANDROID)
mdjones2ee41afd2016-10-27 16:50:20541 top_controls_constraints_(BROWSER_CONTROLS_STATE_BOTH),
[email protected]bbc8856d2013-06-14 10:37:04542#endif
mdjones2ee41afd2016-10-27 16:50:20543 browser_controls_shrink_blink_size_(false),
bokanc63441c2016-04-27 15:49:12544 top_controls_height_(0.f),
lfg4fa48da2016-05-09 18:25:13545 webview_(nullptr),
[email protected]1875bc02014-03-14 06:33:59546 has_scrolled_focused_editable_node_into_rect_(false),
wjmaclean64951902016-04-29 20:59:12547 page_zoom_level_(params.page_zoom_level),
nasko4c0feb62015-06-05 18:37:06548 main_render_frame_(nullptr),
dcheng3ce04b62015-10-26 23:30:55549 frame_widget_(nullptr),
[email protected]64d09222012-05-25 10:10:34550 speech_recognition_dispatcher_(NULL),
[email protected]20657a82012-08-21 20:23:03551#if defined(OS_ANDROID)
nickf7b38222016-11-22 21:59:35552 was_created_by_renderer_(false),
[email protected]a7564272013-04-19 14:24:46553#endif
[email protected]8a67aa352013-02-20 02:58:29554 enumeration_completion_id_(0),
changwand659e202016-06-13 02:39:12555 session_storage_namespace_id_(params.session_storage_namespace_id),
wjmaclean1d970622017-01-21 22:28:24556 weak_ptr_factory_(this) {
avi40b5be7a2016-03-03 21:13:44557 GetWidget()->set_owner_delegate(this);
[email protected]075366912013-02-18 07:13:24558}
559
nickf7b38222016-11-22 21:59:35560void RenderViewImpl::Initialize(
561 const mojom::CreateViewParams& params,
562 const RenderWidget::ShowCallback& show_callback) {
563 bool was_created_by_renderer = !show_callback.is_null();
564#if defined(OS_ANDROID)
565 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated
566 // HandleNavigation codepath.
567 was_created_by_renderer_ = was_created_by_renderer;
568#endif
thestig6057a6b22015-11-12 23:01:33569 display_mode_ = params.initial_size.display_mode;
[email protected]676126f72011-01-15 00:03:51570
Blink Reformat1c4d759e2017-04-09 16:34:54571 webview_ = WebView::Create(this, is_hidden()
572 ? blink::kWebPageVisibilityStateHidden
573 : blink::kWebPageVisibilityStateVisible);
574 RenderWidget::Init(show_callback, webview_->GetWidget());
[email protected]11fee2332011-03-29 20:36:35575
nasko4c0feb62015-06-05 18:37:06576 g_view_map.Get().insert(std::make_pair(webview(), this));
avia3dca182016-03-19 01:09:52577 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this));
nasko4c0feb62015-06-05 18:37:06578
avi83883c82014-12-23 00:08:49579 const base::CommandLine& command_line =
580 *base::CommandLine::ForCurrentProcess();
[email protected]20657a82012-08-21 20:23:03581
[email protected]27c521a2013-05-29 20:44:32582 if (command_line.HasSwitch(switches::kStatsCollectionController))
583 stats_collection_observer_.reset(new StatsCollectionObserver(this));
584
Blink Reformat1c4d759e2017-04-09 16:34:54585 webview()->SetDisplayMode(display_mode_);
586 webview()->GetSettings()->SetPreferCompositingToLCDTextEnabled(
dcheng0ff94cfc2016-03-15 21:50:51587 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_));
Blink Reformat1c4d759e2017-04-09 16:34:54588 webview()->GetSettings()->SetThreadedScrollingEnabled(
dcheng0ff94cfc2016-03-15 21:50:51589 !command_line.HasSwitch(switches::kDisableThreadedScrolling));
Blink Reformat1c4d759e2017-04-09 16:34:54590 webview()->SetShowFPSCounter(
dcheng0ff94cfc2016-03-15 21:50:51591 command_line.HasSwitch(cc::switches::kShowFPSCounter));
ccameron009667d2017-05-15 04:14:49592 webview()->SetDeviceColorProfile(params.image_decode_color_space);
dcheng0ff94cfc2016-03-15 21:50:51593
594 ApplyWebPreferencesInternal(webkit_preferences_, webview(), compositor_deps_);
595
596 if (switches::IsTouchDragDropEnabled())
Blink Reformat1c4d759e2017-04-09 16:34:54597 webview()->GetSettings()->SetTouchDragDropEnabled(true);
dcheng0ff94cfc2016-03-15 21:50:51598
Blink Reformat1c4d759e2017-04-09 16:34:54599 webview()->GetSettings()->SetBrowserSideNavigationEnabled(
arthursonzognic517fc32016-08-11 11:04:24600 IsBrowserSideNavigationEnabled());
601
dcheng0ff94cfc2016-03-15 21:50:51602 WebSettings::SelectionStrategyType selection_strategy =
Blink Reformat1c4d759e2017-04-09 16:34:54603 WebSettings::SelectionStrategyType::kCharacter;
dcheng0ff94cfc2016-03-15 21:50:51604 const std::string selection_strategy_str =
605 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
606 switches::kTouchTextSelectionStrategy);
607 if (selection_strategy_str == "direction")
Blink Reformat1c4d759e2017-04-09 16:34:54608 selection_strategy = WebSettings::SelectionStrategyType::kDirection;
609 webview()->GetSettings()->SetSelectionStrategy(selection_strategy);
dcheng0ff94cfc2016-03-15 21:50:51610
dtapuskaf65650b2016-05-13 17:21:34611 std::string passiveListenersDefault =
612 command_line.GetSwitchValueASCII(switches::kPassiveListenersDefault);
613 if (!passiveListenersDefault.empty()) {
614 WebSettings::PassiveEventListenerDefault passiveDefault =
Blink Reformat1c4d759e2017-04-09 16:34:54615 WebSettings::PassiveEventListenerDefault::kFalse;
dtapuskaacc2fb22016-07-06 23:26:23616 if (passiveListenersDefault == "true")
Blink Reformat1c4d759e2017-04-09 16:34:54617 passiveDefault = WebSettings::PassiveEventListenerDefault::kTrue;
dtapuskaf65650b2016-05-13 17:21:34618 else if (passiveListenersDefault == "forcealltrue")
Blink Reformat1c4d759e2017-04-09 16:34:54619 passiveDefault = WebSettings::PassiveEventListenerDefault::kForceAllTrue;
620 webview()->GetSettings()->SetPassiveEventListenerDefault(passiveDefault);
dtapuskaf65650b2016-05-13 17:21:34621 }
622
Blink Reformat1c4d759e2017-04-09 16:34:54623 ApplyBlinkSettings(command_line, webview()->GetSettings());
dcheng0ff94cfc2016-03-15 21:50:51624
nick3b5a21f2016-11-22 23:07:11625 WebFrame* opener_frame =
626 RenderFrameImpl::ResolveOpener(params.opener_frame_route_id);
627
dchengc5ef1a52015-08-26 20:58:30628 if (params.main_frame_routing_id != MSG_ROUTING_NONE) {
dcheng3ce04b62015-10-26 23:30:55629 main_render_frame_ = RenderFrameImpl::CreateMainFrame(
630 this, params.main_frame_routing_id, params.main_frame_widget_routing_id,
dcheng9e24bd352016-03-01 19:15:51631 params.hidden, screen_info(), compositor_deps_, opener_frame);
dchengc5ef1a52015-08-26 20:58:30632 }
633
nasko4c0feb62015-06-05 18:37:06634 if (params.proxy_routing_id != MSG_ROUTING_NONE) {
635 CHECK(params.swapped_out);
nick3b5a21f2016-11-22 23:07:11636 RenderFrameProxy::CreateFrameProxy(params.proxy_routing_id, GetRoutingID(),
637 opener_frame, MSG_ROUTING_NONE,
638 params.replicated_frame_state);
nasko4c0feb62015-06-05 18:37:06639 }
640
nasko4c0feb62015-06-05 18:37:06641 if (main_render_frame_)
642 main_render_frame_->Initialize();
643
nickf7b38222016-11-22 21:59:35644 // If this RenderView's creation was initiated by an opener page in this
645 // process, (e.g. window.open()), we won't be visible until we ask the opener,
646 // via show_callback, to make us visible. Otherwise, we went through a
647 // browser-initiated creation, and show() won't be called.
648 if (!was_created_by_renderer)
[email protected]676126f72011-01-15 00:03:51649 did_show_ = true;
mfomitchev5ad034ec2015-04-24 21:57:27650
alexmos35799be2015-07-02 08:59:50651 // Set the main frame's name. Only needs to be done for WebLocalFrames,
652 // since the remote case was handled as part of SetReplicatedState on the
653 // proxy above.
654 if (!params.replicated_frame_state.name.empty() &&
Blink Reformat1c4d759e2017-04-09 16:34:54655 webview()->MainFrame()->IsWebLocalFrame()) {
656 webview()->MainFrame()->SetName(
657 blink::WebString::FromUTF8(params.replicated_frame_state.name));
alexmos3448b552015-06-26 07:49:13658 }
[email protected]34c61bd52011-05-02 19:38:33659
[email protected]c7c0d822014-04-16 20:19:49660 // TODO(davidben): Move this state from Blink into content.
naskobd911332014-11-25 01:13:36661 if (params.window_was_created_with_opener)
Blink Reformat1c4d759e2017-04-09 16:34:54662 webview()->SetOpenedByDOM();
[email protected]c7c0d822014-04-16 20:19:49663
dcheng0ff94cfc2016-03-15 21:50:51664 UpdateWebViewWithDeviceScaleFactor();
naskobd911332014-11-25 01:13:36665 OnSetRendererPrefs(params.renderer_preferences);
[email protected]34c61bd52011-05-02 19:38:33666
naskobd911332014-11-25 01:13:36667 if (!params.enable_auto_resize) {
668 OnResize(params.initial_size);
mkosiba58fa72f02014-11-12 01:21:36669 } else {
naskobd911332014-11-25 01:13:36670 OnEnableAutoResize(params.min_size, params.max_size);
mkosiba58fa72f02014-11-12 01:21:36671 }
672
dtapuska9ec1a912017-04-21 15:18:31673 idle_user_detector_.reset(new IdleUserDetector(this));
[email protected]1784b2f2011-11-24 10:53:48674
[email protected]e9ff79c2012-10-19 21:31:26675 GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44676
dcheng9e24bd352016-03-01 19:15:51677 // Ensure that sandbox flags are inherited from an opener in a different
678 // process. In that case, the browser process will set any inherited sandbox
679 // flags in |replicated_frame_state|, so apply them here.
Blink Reformat1c4d759e2017-04-09 16:34:54680 if (!was_created_by_renderer && webview()->MainFrame()->IsWebLocalFrame()) {
681 webview()->MainFrame()->ToWebLocalFrame()->ForceSandboxFlags(
dcheng9e24bd352016-03-01 19:15:51682 params.replicated_frame_state.sandbox_flags);
alexmosaedfc6f2016-01-21 23:57:38683 }
wjmaclean64951902016-04-29 20:59:12684
685 page_zoom_level_ = params.page_zoom_level;
initial.commit09911bf2008-07-26 23:55:29686}
687
[email protected]310ebd6302011-10-10 19:06:28688RenderViewImpl::~RenderViewImpl() {
dcheng3ce04b62015-10-26 23:30:55689 DCHECK(!frame_widget_);
690
[email protected]cb189e062014-04-23 00:57:01691 for (BitmapMap::iterator it = disambiguation_bitmaps_.begin();
692 it != disambiguation_bitmaps_.end();
693 ++it)
694 delete it->second;
[email protected]91a2aea2013-07-08 23:14:39695
[email protected]8ed1d3f2013-02-20 11:45:55696#if defined(OS_ANDROID)
davve17e025e12016-05-23 15:30:20697 // The date/time picker client is both a std::unique_ptr member of this class
698 // and a RenderViewObserver. Reset it to prevent double deletion.
[email protected]8ed1d3f2013-02-20 11:45:55699 date_time_picker_client_.reset();
700#endif
701
[email protected]60c42a8c72009-10-09 04:08:59702#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22703 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49704 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59705 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
706 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22707 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
708 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
709 it != routing_id_views->end(); ++it)
710 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59711#endif
[email protected]676126f72011-01-15 00:03:51712
dtapuska9ec1a912017-04-21 15:18:31713 idle_user_detector_.reset();
ericwilligers88e69742016-10-17 19:29:55714 for (auto& observer : observers_)
715 observer.RenderViewGone();
716 for (auto& observer : observers_)
717 observer.OnDestruct();
[email protected]60c42a8c72009-10-09 04:08:59718}
719
720/*static*/
[email protected]310ebd6302011-10-10 19:06:28721RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31722 ViewMap* views = g_view_map.Pointer();
723 ViewMap::iterator it = views->find(webview);
724 return it == views->end() ? NULL : it->second;
725}
726
727/*static*/
[email protected]180ef242013-11-07 06:50:46728RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28729 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31730}
731
732/*static*/
avi1023d012015-12-25 02:39:14733RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) {
[email protected]640e303c2012-12-05 01:36:07734 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
735 RoutingIDViewMap::iterator it = views->find(routing_id);
736 return it == views->end() ? NULL : it->second;
737}
738
739/*static*/
740RenderView* RenderView::FromRoutingID(int routing_id) {
741 return RenderViewImpl::FromRoutingID(routing_id);
742}
743
[email protected]f3a95312014-06-12 16:46:58744/* static */
jochen9c7b8f242015-06-01 15:32:02745size_t RenderView::GetRenderViewCount() {
[email protected]f3a95312014-06-12 16:46:58746 return g_view_map.Get().size();
747}
748
[email protected]640e303c2012-12-05 01:36:07749/*static*/
[email protected]e9ff79c2012-10-19 21:31:26750void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49751 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59752 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
753 if (!visitor->Visit(it->second))
754 return;
755 }
756}
757
758/*static*/
[email protected]b3a97b52014-07-09 06:25:05759void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
760 WebView* web_view) {
Blink Reformat1c4d759e2017-04-09 16:34:54761 WebSettings* settings = web_view->GetSettings();
[email protected]b3a97b52014-07-09 06:25:05762 ApplyFontsFromMap(prefs.standard_font_family_map,
763 SetStandardFontFamilyWrapper, settings);
764 ApplyFontsFromMap(prefs.fixed_font_family_map,
765 SetFixedFontFamilyWrapper, settings);
766 ApplyFontsFromMap(prefs.serif_font_family_map,
767 SetSerifFontFamilyWrapper, settings);
768 ApplyFontsFromMap(prefs.sans_serif_font_family_map,
769 SetSansSerifFontFamilyWrapper, settings);
770 ApplyFontsFromMap(prefs.cursive_font_family_map,
771 SetCursiveFontFamilyWrapper, settings);
772 ApplyFontsFromMap(prefs.fantasy_font_family_map,
773 SetFantasyFontFamilyWrapper, settings);
774 ApplyFontsFromMap(prefs.pictograph_font_family_map,
775 SetPictographFontFamilyWrapper, settings);
Blink Reformat1c4d759e2017-04-09 16:34:54776 settings->SetDefaultFontSize(prefs.default_font_size);
777 settings->SetDefaultFixedFontSize(prefs.default_fixed_font_size);
778 settings->SetMinimumFontSize(prefs.minimum_font_size);
779 settings->SetMinimumLogicalFontSize(prefs.minimum_logical_font_size);
780 settings->SetDefaultTextEncodingName(
781 WebString::FromASCII(prefs.default_encoding));
782 settings->SetJavaScriptEnabled(prefs.javascript_enabled);
783 settings->SetWebSecurityEnabled(prefs.web_security_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54784 settings->SetLoadsImagesAutomatically(prefs.loads_images_automatically);
785 settings->SetImagesEnabled(prefs.images_enabled);
786 settings->SetPluginsEnabled(prefs.plugins_enabled);
787 settings->SetEncryptedMediaEnabled(prefs.encrypted_media_enabled);
788 settings->SetDOMPasteAllowed(prefs.dom_paste_enabled);
789 settings->SetTextAreasAreResizable(prefs.text_areas_are_resizable);
790 settings->SetAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
791 settings->SetDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
792 settings->SetJavaScriptCanAccessClipboard(
[email protected]b3a97b52014-07-09 06:25:05793 prefs.javascript_can_access_clipboard);
Blink Reformat1c4d759e2017-04-09 16:34:54794 WebRuntimeFeatures::EnableXSLT(prefs.xslt_enabled);
795 settings->SetXSSAuditorEnabled(prefs.xss_auditor_enabled);
796 settings->SetDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
797 settings->SetDataSaverEnabled(prefs.data_saver_enabled);
798 settings->SetLocalStorageEnabled(prefs.local_storage_enabled);
799 settings->SetSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
800 WebRuntimeFeatures::EnableDatabase(prefs.databases_enabled);
801 settings->SetOfflineWebApplicationCacheEnabled(
[email protected]b3a97b52014-07-09 06:25:05802 prefs.application_cache_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54803 settings->SetHistoryEntryRequiresUserGesture(
japhet5018fe62016-09-14 19:14:04804 prefs.history_entry_requires_user_gesture);
Blink Reformat1c4d759e2017-04-09 16:34:54805 settings->SetHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
806 settings->SetCookieEnabled(prefs.cookie_enabled);
807 settings->SetNavigateOnDragDrop(prefs.navigate_on_drag_drop);
[email protected]b3a97b52014-07-09 06:25:05808
[email protected]b3a97b52014-07-09 06:25:05809 // By default, allow_universal_access_from_file_urls is set to false and thus
810 // we mitigate attacks from local HTML files by not granting file:// URLs
811 // universal access. Only test shell will enable this.
Blink Reformat1c4d759e2017-04-09 16:34:54812 settings->SetAllowUniversalAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05813 prefs.allow_universal_access_from_file_urls);
Blink Reformat1c4d759e2017-04-09 16:34:54814 settings->SetAllowFileAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05815 prefs.allow_file_access_from_file_urls);
816
[email protected]b3a97b52014-07-09 06:25:05817 // Enable experimental WebGL support if requested on command line
818 // and support is compiled in.
Blink Reformat1c4d759e2017-04-09 16:34:54819 settings->SetExperimentalWebGLEnabled(prefs.experimental_webgl_enabled);
[email protected]b3a97b52014-07-09 06:25:05820
[email protected]b3a97b52014-07-09 06:25:05821 // Enable WebGL errors to the JS console if requested.
Blink Reformat1c4d759e2017-04-09 16:34:54822 settings->SetWebGLErrorsToConsoleEnabled(
[email protected]b3a97b52014-07-09 06:25:05823 prefs.webgl_errors_to_console_enabled);
824
825 // Uses the mock theme engine for scrollbars.
Blink Reformat1c4d759e2017-04-09 16:34:54826 settings->SetMockScrollbarsEnabled(prefs.mock_scrollbars_enabled);
[email protected]b3a97b52014-07-09 06:25:05827
Blink Reformat1c4d759e2017-04-09 16:34:54828 settings->SetHideScrollbars(prefs.hide_scrollbars);
eseckler61ff9142016-09-23 22:57:59829
[email protected]b3a97b52014-07-09 06:25:05830 // Enable gpu-accelerated 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54831 WebRuntimeFeatures::EnableAccelerated2dCanvas(
junov524668f22016-08-08 20:16:52832 prefs.accelerated_2d_canvas_enabled);
[email protected]b3a97b52014-07-09 06:25:05833
Blink Reformat1c4d759e2017-04-09 16:34:54834 settings->SetMinimumAccelerated2dCanvasSize(
[email protected]b3a97b52014-07-09 06:25:05835 prefs.minimum_accelerated_2d_canvas_size);
836
837 // Disable antialiasing for 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54838 settings->SetAntialiased2dCanvasEnabled(
[email protected]b3a97b52014-07-09 06:25:05839 !prefs.antialiased_2d_canvas_disabled);
Blink Reformat1c4d759e2017-04-09 16:34:54840 WebRuntimeFeatures::ForceDisable2dCanvasCopyOnWrite(
boliucfcae412016-02-11 22:16:38841 prefs.disable_2d_canvas_copy_on_write);
[email protected]b3a97b52014-07-09 06:25:05842
zakerinasab20ebca02016-09-27 14:22:34843 // Disable antialiasing of clips for 2d canvas if requested on the command
robertphillipse25137b2014-10-20 13:44:34844 // line.
Blink Reformat1c4d759e2017-04-09 16:34:54845 settings->SetAntialiasedClips2dCanvasEnabled(
robertphillipse25137b2014-10-20 13:44:34846 prefs.antialiased_clips_2d_canvas_enabled);
847
[email protected]b3a97b52014-07-09 06:25:05848 // Set MSAA sample count for 2d canvas if requested on the command line (or
849 // default value if not).
Blink Reformat1c4d759e2017-04-09 16:34:54850 settings->SetAccelerated2dCanvasMSAASampleCount(
[email protected]b3a97b52014-07-09 06:25:05851 prefs.accelerated_2d_canvas_msaa_sample_count);
852
[email protected]b3a97b52014-07-09 06:25:05853 // Tabs to link is not part of the settings. WebCore calls
854 // ChromeClient::tabsToLinks which is part of the glue code.
Blink Reformat1c4d759e2017-04-09 16:34:54855 web_view->SetTabsToLinks(prefs.tabs_to_links);
[email protected]b3a97b52014-07-09 06:25:05856
Blink Reformat1c4d759e2017-04-09 16:34:54857 settings->SetAllowRunningOfInsecureContent(
[email protected]b3a97b52014-07-09 06:25:05858 prefs.allow_running_insecure_content);
Blink Reformat1c4d759e2017-04-09 16:34:54859 settings->SetDisableReadingFromCanvas(prefs.disable_reading_from_canvas);
860 settings->SetStrictMixedContentChecking(prefs.strict_mixed_content_checking);
mkwst2384c8222015-07-30 07:26:47861
Blink Reformat1c4d759e2017-04-09 16:34:54862 settings->SetStrictlyBlockBlockableMixedContent(
mkwst2384c8222015-07-30 07:26:47863 prefs.strictly_block_blockable_mixed_content);
864
Blink Reformat1c4d759e2017-04-09 16:34:54865 settings->SetStrictMixedContentCheckingForPlugin(
mkwst0d233e52015-08-10 09:33:14866 prefs.block_mixed_plugin_content);
867
Blink Reformat1c4d759e2017-04-09 16:34:54868 settings->SetStrictPowerfulFeatureRestrictions(
mkwst673a452f2015-01-10 14:41:50869 prefs.strict_powerful_feature_restrictions);
Blink Reformat1c4d759e2017-04-09 16:34:54870 settings->SetAllowGeolocationOnInsecureOrigins(
jww9d4ca2d2016-01-19 20:58:59871 prefs.allow_geolocation_on_insecure_origins);
Blink Reformat1c4d759e2017-04-09 16:34:54872 settings->SetPasswordEchoEnabled(prefs.password_echo_enabled);
873 settings->SetShouldPrintBackgrounds(prefs.should_print_backgrounds);
874 settings->SetShouldClearDocumentBackground(
[email protected]b3a97b52014-07-09 06:25:05875 prefs.should_clear_document_background);
Blink Reformat1c4d759e2017-04-09 16:34:54876 settings->SetEnableScrollAnimator(prefs.enable_scroll_animator);
[email protected]b3a97b52014-07-09 06:25:05877
Blink Reformat1c4d759e2017-04-09 16:34:54878 WebRuntimeFeatures::EnableTouchEventFeatureDetection(
sunyunjiafa6a8afc2016-12-09 04:25:47879 prefs.touch_event_feature_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54880 settings->SetMaxTouchPoints(prefs.pointer_events_max_touch_points);
881 settings->SetAvailablePointerTypes(prefs.available_pointer_types);
882 settings->SetPrimaryPointerType(
nzolghadrc0d1663c2015-11-26 21:15:24883 static_cast<blink::PointerType>(prefs.primary_pointer_type));
Blink Reformat1c4d759e2017-04-09 16:34:54884 settings->SetAvailableHoverTypes(prefs.available_hover_types);
885 settings->SetPrimaryHoverType(
nzolghadrc0d1663c2015-11-26 21:15:24886 static_cast<blink::HoverType>(prefs.primary_hover_type));
Blink Reformat1c4d759e2017-04-09 16:34:54887 settings->SetEnableTouchAdjustment(prefs.touch_adjustment_enabled);
[email protected]b3a97b52014-07-09 06:25:05888
Blink Reformat1c4d759e2017-04-09 16:34:54889 WebRuntimeFeatures::EnableColorCorrectRendering(
ccameron7c4df6c22016-08-11 03:03:15890 prefs.color_correct_rendering_enabled);
ccameron41530d892016-11-29 06:12:33891
Blink Reformat1c4d759e2017-04-09 16:34:54892 settings->SetShouldRespectImageOrientation(
[email protected]b3a97b52014-07-09 06:25:05893 prefs.should_respect_image_orientation);
894
Blink Reformat1c4d759e2017-04-09 16:34:54895 settings->SetEditingBehavior(
[email protected]b3a97b52014-07-09 06:25:05896 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
897
Blink Reformat1c4d759e2017-04-09 16:34:54898 settings->SetSupportsMultipleWindows(prefs.supports_multiple_windows);
[email protected]b3a97b52014-07-09 06:25:05899
Blink Reformat1c4d759e2017-04-09 16:34:54900 settings->SetInertVisualViewport(prefs.inert_visual_viewport);
ymalik835268c22016-02-22 16:28:12901
Blink Reformat1c4d759e2017-04-09 16:34:54902 settings->SetMainFrameClipsContent(!prefs.record_whole_document);
khushalsagar2da2b232016-03-23 22:11:35903
Blink Reformat1c4d759e2017-04-09 16:34:54904 settings->SetSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
[email protected]b3a97b52014-07-09 06:25:05905
Blink Reformat1c4d759e2017-04-09 16:34:54906 settings->SetSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
[email protected]b3a97b52014-07-09 06:25:05907
Blink Reformat1c4d759e2017-04-09 16:34:54908 settings->SetSelectionIncludesAltImageText(true);
[email protected]b3a97b52014-07-09 06:25:05909
Blink Reformat1c4d759e2017-04-09 16:34:54910 settings->SetV8CacheOptions(
[email protected]35103c02014-08-12 15:08:47911 static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options));
912
Blink Reformat1c4d759e2017-04-09 16:34:54913 settings->SetV8CacheStrategiesForCacheStorage(
horodbcbef42016-05-10 17:02:47914 GetV8CacheStrategiesForCacheStorage());
915
Blink Reformat1c4d759e2017-04-09 16:34:54916 settings->SetImageAnimationPolicy(
je_julie.kim7fbb5a1a2015-02-09 17:26:05917 static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy));
918
Blink Reformat1c4d759e2017-04-09 16:34:54919 settings->SetPresentationRequiresUserGesture(
zqzhang1215ad422016-02-10 13:27:22920 prefs.user_gesture_required_for_presentation);
921
Blink Reformat1c4d759e2017-04-09 16:34:54922 settings->SetTextTrackMarginPercentage(prefs.text_track_margin_percentage);
halliwell4002be42016-03-18 18:33:40923
dcheng5ae8ca362015-02-05 04:03:47924 // Needs to happen before setIgnoreVIewportTagScaleLimits below.
Blink Reformat1c4d759e2017-04-09 16:34:54925 web_view->SetDefaultPageScaleLimits(prefs.default_minimum_page_scale_factor,
926 prefs.default_maximum_page_scale_factor);
dcheng5ae8ca362015-02-05 04:03:47927
[email protected]b3a97b52014-07-09 06:25:05928#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:54929 settings->SetAllowCustomScrollbarInMainFrame(false);
930 settings->SetTextAutosizingEnabled(prefs.text_autosizing_enabled);
931 settings->SetAccessibilityFontScaleFactor(prefs.font_scale_factor);
932 settings->SetDeviceScaleAdjustment(prefs.device_scale_adjustment);
933 settings->SetFullscreenSupported(prefs.fullscreen_supported);
934 web_view->SetIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
935 settings->SetAutoZoomFocusedNodeToLegibleScale(true);
936 settings->SetDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54937 settings->SetMediaPlaybackGestureWhitelistScope(
938 blink::WebString::FromUTF8(prefs.media_playback_gesture_whitelist_scope));
939 settings->SetDefaultVideoPosterURL(
940 WebString::FromASCII(prefs.default_video_poster_url.spec()));
941 settings->SetSupportDeprecatedTargetDensityDPI(
[email protected]b3a97b52014-07-09 06:25:05942 prefs.support_deprecated_target_density_dpi);
Blink Reformat1c4d759e2017-04-09 16:34:54943 settings->SetUseLegacyBackgroundSizeShorthandBehavior(
[email protected]b3a97b52014-07-09 06:25:05944 prefs.use_legacy_background_size_shorthand_behavior);
Blink Reformat1c4d759e2017-04-09 16:34:54945 settings->SetWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
946 settings->SetUseWideViewport(prefs.use_wide_viewport);
947 settings->SetForceZeroLayoutHeight(prefs.force_zero_layout_height);
948 settings->SetViewportMetaLayoutSizeQuirk(
[email protected]b3a97b52014-07-09 06:25:05949 prefs.viewport_meta_layout_size_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54950 settings->SetViewportMetaMergeContentQuirk(
[email protected]b3a97b52014-07-09 06:25:05951 prefs.viewport_meta_merge_content_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54952 settings->SetViewportMetaNonUserScalableQuirk(
[email protected]b3a97b52014-07-09 06:25:05953 prefs.viewport_meta_non_user_scalable_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54954 settings->SetViewportMetaZeroValuesQuirk(
[email protected]b3a97b52014-07-09 06:25:05955 prefs.viewport_meta_zero_values_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54956 settings->SetClobberUserAgentInitialScaleQuirk(
[email protected]b3a97b52014-07-09 06:25:05957 prefs.clobber_user_agent_initial_scale_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54958 settings->SetIgnoreMainFrameOverflowHiddenQuirk(
[email protected]b3a97b52014-07-09 06:25:05959 prefs.ignore_main_frame_overflow_hidden_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54960 settings->SetReportScreenSizeInPhysicalPixelsQuirk(
[email protected]b3a97b52014-07-09 06:25:05961 prefs.report_screen_size_in_physical_pixels_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54962 settings->SetShouldReuseGlobalForUnownedMainFrame(
boliu1a00f262016-04-06 19:08:46963 prefs.resue_global_for_unowned_main_frame);
Blink Reformat1c4d759e2017-04-09 16:34:54964 settings->SetProgressBarCompletion(
japhet98e9bd82016-06-28 23:48:45965 static_cast<WebSettings::ProgressBarCompletion>(
966 prefs.progress_bar_completion));
Blink Reformat1c4d759e2017-04-09 16:34:54967 settings->SetPreferHiddenVolumeControls(true);
968 settings->SetSpellCheckEnabledByDefault(prefs.spellcheck_enabled_by_default);
dalecurtiscd971252016-09-21 16:09:00969
aeliase678aa42017-04-14 22:41:04970 // Force preload=none and disable autoplay on older Android
dalecurtiscd971252016-09-21 16:09:00971 // platforms because their media pipelines are not stable enough to handle
972 // concurrent elements. See http://crbug.com/612909, http://crbug.com/622826.
aeliase678aa42017-04-14 22:41:04973 const bool is_jelly_bean =
dalecurtiscd971252016-09-21 16:09:00974 base::android::BuildInfo::GetInstance()->sdk_int() <=
aeliase678aa42017-04-14 22:41:04975 base::android::SDK_VERSION_JELLY_BEAN_MR2;
976 settings->SetForcePreloadNoneForMediaElements(is_jelly_bean);
mlamouri1d266bf2016-12-05 17:42:36977
Blink Reformat1c4d759e2017-04-09 16:34:54978 WebRuntimeFeatures::EnableVideoFullscreenOrientationLock(
mlamouri1d266bf2016-12-05 17:42:36979 prefs.video_fullscreen_orientation_lock_enabled);
johnme913ee5f2017-04-28 21:36:16980 WebRuntimeFeatures::EnableVideoRotateToFullscreen(
981 prefs.video_rotate_to_fullscreen_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54982 WebRuntimeFeatures::EnableVideoFullscreenDetection(
zqzhang93e959d12017-03-16 13:10:20983 prefs.video_fullscreen_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54984 settings->SetEmbeddedMediaExperienceEnabled(
shaktisahuf97f7532017-02-24 22:46:13985 prefs.embedded_media_experience_enabled);
vollick8921b242017-05-25 02:48:15986 settings->SetPagePopupsSuppressed(prefs.page_popups_suppressed);
Blink Reformat1c4d759e2017-04-09 16:34:54987 settings->SetDoNotUpdateSelectionOnMutatingSelectionRange(
changwane54ccdb92017-04-05 19:20:54988 prefs.do_not_update_selection_on_mutating_selection_range);
zqzhangdf72ed082016-12-08 16:07:55989#endif // defined(OS_ANDROID)
liberato9e934892016-05-03 19:00:27990
mlamouri55a0543c2017-05-11 10:34:07991 switch (prefs.autoplay_policy) {
992 case AutoplayPolicy::kNoUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28993 settings->SetAutoplayPolicy(
994 WebSettings::AutoplayPolicy::kNoUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07995 break;
996 case AutoplayPolicy::kUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28997 settings->SetAutoplayPolicy(
998 WebSettings::AutoplayPolicy::kUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07999 break;
1000 case AutoplayPolicy::kUserGestureRequiredForCrossOrigin:
mlamouri276a6f32017-05-12 09:24:281001 settings->SetAutoplayPolicy(
1002 WebSettings::AutoplayPolicy::kUserGestureRequiredForCrossOrigin);
mlamouri55a0543c2017-05-11 10:34:071003 break;
mlamouri431bb4e2017-06-06 08:54:241004 case AutoplayPolicy::kDocumentUserActivationRequired:
1005 settings->SetAutoplayPolicy(
1006 WebSettings::AutoplayPolicy::kDocumentUserActivationRequired);
1007 break;
mlamouri55a0543c2017-05-11 10:34:071008 }
1009
Blink Reformat1c4d759e2017-04-09 16:34:541010 settings->SetViewportEnabled(prefs.viewport_enabled);
1011 settings->SetViewportMetaEnabled(prefs.viewport_meta_enabled);
1012 settings->SetShrinksViewportContentToFit(
1013 prefs.shrinks_viewport_contents_to_fit);
1014 settings->SetViewportStyle(
alokp5d566962016-04-19 00:54:161015 static_cast<blink::WebViewportStyle>(prefs.viewport_style));
1016
Blink Reformat1c4d759e2017-04-09 16:34:541017 settings->SetLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
1018 settings->SetMainFrameResizesAreOrientationChanges(
yoava1a508b42015-10-20 12:03:211019 prefs.main_frame_resizes_are_orientation_changes);
1020
Blink Reformat1c4d759e2017-04-09 16:34:541021 settings->SetUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
jinho.bang8f11ffa2014-12-04 06:03:031022
Blink Reformat1c4d759e2017-04-09 16:34:541023 settings->SetShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up);
1024 settings->SetAlwaysShowContextMenuOnTouch(
amaralp547e4192016-06-03 19:17:351025 prefs.always_show_context_menu_on_touch);
ccameron2fd70de72015-02-19 00:40:401026
Blink Reformat1c4d759e2017-04-09 16:34:541027 settings->SetHideDownloadUI(prefs.hide_download_ui);
1028 WebRuntimeFeatures::EnableBackgroundVideoTrackOptimization(
avayvod39c102402016-11-23 21:43:131029 prefs.background_video_track_optimization_enabled);
avayvod232757942017-04-29 04:12:341030 WebRuntimeFeatures::EnableNewRemotePlaybackPipeline(
1031 base::FeatureList::IsEnabled(media::kNewRemotePlaybackPipeline));
qinmin72e8bd02016-10-21 19:35:371032
Blink Reformat1c4d759e2017-04-09 16:34:541033 settings->SetPresentationReceiver(prefs.presentation_receiver);
mlamouri57359d912016-11-29 20:11:501034
Blink Reformat1c4d759e2017-04-09 16:34:541035 settings->SetMediaControlsEnabled(prefs.media_controls_enabled);
mlamouri5cd9ae82017-02-18 11:05:091036
ccameron2fd70de72015-02-19 00:40:401037#if defined(OS_MACOSX)
Blink Reformat1c4d759e2017-04-09 16:34:541038 settings->SetDoubleTapToZoomEnabled(true);
1039 web_view->SetMaximumLegibleScale(prefs.default_maximum_page_scale_factor);
ccameron2fd70de72015-02-19 00:40:401040#endif
sunyunjia87f287b2016-09-09 00:38:131041
1042#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:541043 WebRuntimeFeatures::EnableMiddleClickAutoscroll(true);
sunyunjia87f287b2016-09-09 00:38:131044#endif
[email protected]b3a97b52014-07-09 06:25:051045}
1046
1047/*static*/
nickf7b38222016-11-22 21:59:351048RenderViewImpl* RenderViewImpl::Create(
1049 CompositorDependencies* compositor_deps,
1050 const mojom::CreateViewParams& params,
1051 const RenderWidget::ShowCallback& show_callback) {
naskobd911332014-11-25 01:13:361052 DCHECK(params.view_id != MSG_ROUTING_NONE);
[email protected]075366912013-02-18 07:13:241053 RenderViewImpl* render_view = NULL;
[email protected]8d41d7612012-11-14 20:32:191054 if (g_create_render_view_impl)
dcheng35d31c112015-07-22 00:17:361055 render_view = g_create_render_view_impl(compositor_deps, params);
[email protected]075366912013-02-18 07:13:241056 else
dcheng35d31c112015-07-22 00:17:361057 render_view = new RenderViewImpl(compositor_deps, params);
[email protected]0287e762014-04-11 13:07:581058
nickf7b38222016-11-22 21:59:351059 render_view->Initialize(params, show_callback);
[email protected]075366912013-02-18 07:13:241060 return render_view;
[email protected]8d41d7612012-11-14 20:32:191061}
1062
1063// static
dcheng35d31c112015-07-22 00:17:361064void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
1065 *create_render_view_impl)(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:151066 const mojom::CreateViewParams&)) {
[email protected]8d41d7612012-11-14 20:32:191067 CHECK(!g_create_render_view_impl);
1068 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291069}
1070
[email protected]310ebd6302011-10-10 19:06:281071void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511072 observers_.AddObserver(observer);
1073}
1074
[email protected]310ebd6302011-10-10 19:06:281075void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1076 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511077 observers_.RemoveObserver(observer);
1078}
1079
[email protected]180ef242013-11-07 06:50:461080blink::WebView* RenderViewImpl::webview() const {
lfg4fa48da2016-05-09 18:25:131081 return webview_;
[email protected]4d51d5bf2010-07-26 18:48:261082}
1083
brettw4b461082016-11-19 18:55:161084#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:571085
[email protected]784ea1ab2010-09-18 00:02:341086#if defined(OS_MACOSX)
[email protected]7411a3c2014-08-15 05:20:191087void RenderViewImpl::OnGetRenderedText() {
1088 if (!webview())
1089 return;
dglazkov03223492016-02-08 22:16:031090
Blink Reformat1c4d759e2017-04-09 16:34:541091 if (!webview()->MainFrame()->IsWebLocalFrame())
dglazkov03223492016-02-08 22:16:031092 return;
1093
[email protected]7411a3c2014-08-15 05:20:191094 // Get rendered text from WebLocalFrame.
1095 // TODO: Currently IPC truncates any data that has a
1096 // size > kMaximumMessageSize. May be split the text into smaller chunks and
1097 // send back using multiple IPC. See http://crbug.com/393444.
1098 static const size_t kMaximumMessageSize = 8 * 1024 * 1024;
dglazkov03223492016-02-08 22:16:031099 // TODO(dglazkov): Using this API is wrong. It's not OOPIF-compatible and
1100 // sends text in the wrong order. See http://crbug.com/584798.
1101 // TODO(dglazkov): WebFrameContentDumper should only be used for
1102 // testing purposes. See http://crbug.com/585164.
1103 std::string text =
Blink Reformat1c4d759e2017-04-09 16:34:541104 WebFrameContentDumper::DumpWebViewAsText(webview(), kMaximumMessageSize)
1105 .Utf8();
[email protected]7411a3c2014-08-15 05:20:191106
avia3dca182016-03-19 01:09:521107 Send(new ViewMsg_GetRenderedTextCompleted(GetRoutingID(), text));
[email protected]7411a3c2014-08-15 05:20:191108}
[email protected]a80af12e2013-08-07 23:36:131109#endif // defined(OS_MACOSX)
1110
1111#endif // ENABLE_PLUGINS
1112
[email protected]7a1ec28a2012-03-28 21:10:241113void RenderViewImpl::TransferActiveWheelFlingAnimation(
[email protected]180ef242013-11-07 06:50:461114 const blink::WebActiveWheelFlingParameters& params) {
[email protected]7a1ec28a2012-03-28 21:10:241115 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:541116 webview()->TransferActiveWheelFlingAnimation(params);
[email protected]7a1ec28a2012-03-28 21:10:241117}
1118
fsamuel72464894f2015-12-15 06:59:311119// RenderWidgetInputHandlerDelegate -----------------------------------------
1120
avid7d6b2e2016-03-04 19:41:171121bool RenderViewImpl::DoesRenderWidgetHaveTouchEventHandlersAt(
1122 const gfx::Point& point) const {
fsamuel72464894f2015-12-15 06:59:311123 if (!webview())
1124 return false;
Blink Reformat1c4d759e2017-04-09 16:34:541125 return webview()->HasTouchEventHandlersAt(point);
fsamuel72464894f2015-12-15 06:59:311126}
1127
avid7d6b2e2016-03-04 19:41:171128bool RenderViewImpl::RenderWidgetWillHandleMouseEvent(
1129 const blink::WebMouseEvent& event) {
fsamuel72464894f2015-12-15 06:59:311130 // If the mouse is locked, only the current owner of the mouse lock can
1131 // process mouse events.
1132 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
1133}
1134
1135// IPC::Listener implementation ----------------------------------------------
1136
[email protected]310ebd6302011-10-10 19:06:281137bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
Blink Reformat1c4d759e2017-04-09 16:34:541138 WebFrame* main_frame = webview() ? webview()->MainFrame() : NULL;
1139 if (main_frame && main_frame->IsWebLocalFrame())
1140 GetContentClient()->SetActiveURL(main_frame->GetDocument().Url());
[email protected]f8b6b6f2009-03-10 16:48:261141
naskoc6edf7e2015-10-16 01:48:451142 // Input IPC messages must not be processed if the RenderView is in
1143 // swapped out state.
dtapuska1b0fcc322016-10-28 18:08:281144 if (is_swapped_out_ &&
1145 IPC_MESSAGE_ID_CLASS(message.type()) == InputMsgStart) {
1146 // TODO(dtapuska): Remove this histogram once we have seen that it actually
1147 // produces results true. See crbug.com/615090
1148 UMA_HISTOGRAM_BOOLEAN("Event.RenderView.DiscardInput", true);
1149 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
1150 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnDiscardInputEvent)
1151 IPC_END_MESSAGE_MAP()
naskoc6edf7e2015-10-16 01:48:451152 return false;
dtapuska1b0fcc322016-10-28 18:08:281153 }
naskoc6edf7e2015-10-16 01:48:451154
dchenga2d442c22016-10-13 15:39:211155 for (auto& observer : observers_) {
1156 if (observer.OnMessageReceived(message))
[email protected]676126f72011-01-15 00:03:511157 return true;
dchenga2d442c22016-10-13 15:39:211158 }
[email protected]b2abac72009-02-26 12:39:281159
[email protected]a95986a82010-12-24 06:19:281160 bool handled = true;
[email protected]e44d1342014-05-16 21:29:331161 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
[email protected]c084330e02013-04-27 01:08:151162 IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand)
1163 IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret)
[email protected]c084330e02013-04-27 01:08:151164 IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect,
1165 OnScrollFocusedEditableNodeIntoRect)
mcnee432e47d2015-11-09 19:37:461166 IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale)
initial.commit09911bf2008-07-26 23:55:291167 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291168 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1169 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]600ea402011-04-12 00:01:511170 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
1171 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:291172 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
[email protected]30f75e62009-02-25 22:01:001173 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]61f91832014-05-13 01:24:421174 IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque, OnSetBackgroundOpaque)
[email protected]ab32b16c2009-10-16 14:57:251175 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1176 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:471177 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:341178 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:101179 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1180 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511181 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:561182 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:361183 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:341184 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]cb189e062014-04-23 00:57:011185 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupBitmap,
1186 OnReleaseDisambiguationPopupBitmap)
aelias1b55156e52017-04-01 00:46:051187 IPC_MESSAGE_HANDLER(ViewMsg_ResolveTapDisambiguation,
1188 OnResolveTapDisambiguation)
[email protected]506563d2014-06-23 12:22:411189 IPC_MESSAGE_HANDLER(ViewMsg_ForceRedraw, OnForceRedraw)
[email protected]4dda6a6c2014-05-17 15:35:041190 IPC_MESSAGE_HANDLER(ViewMsg_SelectWordAroundCaret, OnSelectWordAroundCaret)
wjmaclean64951902016-04-29 20:59:121191
1192 // Page messages.
lfgdb5c4ed2016-03-04 23:09:071193 IPC_MESSAGE_HANDLER(PageMsg_UpdateWindowScreenRect,
1194 OnUpdateWindowScreenRect)
wjmaclean64951902016-04-29 20:59:121195 IPC_MESSAGE_HANDLER(PageMsg_SetZoomLevel, OnSetZoomLevel)
wjmaclean8a795f32016-08-11 23:49:581196 IPC_MESSAGE_HANDLER(PageMsg_SetDeviceScaleFactor, OnSetDeviceScaleFactor);
lfg717154072016-06-30 15:04:161197 IPC_MESSAGE_HANDLER(PageMsg_WasHidden, OnPageWasHidden)
1198 IPC_MESSAGE_HANDLER(PageMsg_WasShown, OnPageWasShown)
alexmos136fd6e62016-08-15 20:58:411199 IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength,
1200 OnSetHistoryOffsetAndLength)
altimind8bd26c2016-11-04 11:44:541201 IPC_MESSAGE_HANDLER(PageMsg_AudioStateChanged, OnAudioStateChanged)
lfg8d649cc2017-04-28 18:04:301202 IPC_MESSAGE_HANDLER(PageMsg_UpdateScreenInfo, OnUpdateScreenInfo)
lfg717154072016-06-30 15:04:161203
[email protected]55750b32012-09-21 14:05:031204#if defined(OS_ANDROID)
mdjones2ee41afd2016-10-27 16:50:201205 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserControlsState,
1206 OnUpdateBrowserControlsState)
[email protected]55750b32012-09-21 14:05:031207#elif defined(OS_MACOSX)
[email protected]7411a3c2014-08-15 05:20:191208 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedText,
1209 OnGetRenderedText)
naskoc288745f2015-05-01 22:54:211210 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]55750b32012-09-21 14:05:031211#endif
[email protected]a794f3a2013-10-30 17:00:321212 // Adding a new message? Add platform independent ones first, then put the
1213 // platform specific ones at the end.
[email protected]9e1ad4b2011-08-14 16:49:191214
initial.commit09911bf2008-07-26 23:55:291215 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281216 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291217 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401218
[email protected]a95986a82010-12-24 06:19:281219 return handled;
initial.commit09911bf2008-07-26 23:55:291220}
1221
[email protected]4dda6a6c2014-05-17 15:35:041222void RenderViewImpl::OnSelectWordAroundCaret() {
donnd701cc202017-05-17 23:11:201223 // Set default values for the ACK
1224 bool did_select = false;
1225 int start_adjust = 0;
1226 int end_adjust = 0;
[email protected]4dda6a6c2014-05-17 15:35:041227
donnd701cc202017-05-17 23:11:201228 if (webview()) {
1229 WebLocalFrame* focused_frame = GetWebView()->FocusedFrame();
1230 if (focused_frame) {
1231 input_handler_->set_handling_input_event(true);
1232 blink::WebRange initial_range = focused_frame->SelectionRange();
donndbde109ff2017-05-26 20:20:011233 if (!initial_range.IsNull())
1234 did_select = focused_frame->SelectWordAroundCaret();
donnd701cc202017-05-17 23:11:201235 if (did_select) {
1236 blink::WebRange adjusted_range = focused_frame->SelectionRange();
1237 start_adjust =
1238 adjusted_range.StartOffset() - initial_range.StartOffset();
1239 end_adjust = adjusted_range.EndOffset() - initial_range.EndOffset();
1240 }
1241 input_handler_->set_handling_input_event(false);
1242 }
1243 }
1244 Send(new ViewHostMsg_SelectWordAroundCaretAck(GetRoutingID(), did_select,
1245 start_adjust, end_adjust));
[email protected]4dda6a6c2014-05-17 15:35:041246}
1247
[email protected]310ebd6302011-10-10 19:06:281248void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291249 // Check if there is a targeturl waiting to be sent.
avi450ce00e2014-09-24 01:58:521250 if (target_url_status_ == TARGET_PENDING)
avia3dca182016-03-19 01:09:521251 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), pending_target_url_));
initial.commit09911bf2008-07-26 23:55:291252
1253 target_url_status_ = TARGET_NONE;
1254}
1255
[email protected]c084330e02013-04-27 01:08:151256void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
1257 const std::string& value) {
Blink Reformat1c4d759e2017-04-09 16:34:541258 if (!webview() || !webview()->FocusedFrame())
[email protected]c084330e02013-04-27 01:08:151259 return;
1260
Blink Reformat1c4d759e2017-04-09 16:34:541261 webview()->FocusedFrame()->ExecuteCommand(WebString::FromUTF8(name),
1262 WebString::FromUTF8(value));
[email protected]c084330e02013-04-27 01:08:151263}
1264
1265void RenderViewImpl::OnMoveCaret(const gfx::Point& point) {
1266 if (!webview())
1267 return;
1268
avia3dca182016-03-19 01:09:521269 Send(new InputHostMsg_MoveCaret_ACK(GetRoutingID()));
Blink Reformat1c4d759e2017-04-09 16:34:541270 webview()->FocusedFrame()->MoveCaretSelection(
oshima93b827d92016-03-01 18:58:411271 ConvertWindowPointToViewport(point));
[email protected]c084330e02013-04-27 01:08:151272}
[email protected]a954bf72009-09-12 07:30:351273
[email protected]c084330e02013-04-27 01:08:151274void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1275 const gfx::Rect& rect) {
ekaramad27ca69b12017-04-20 18:34:291276 blink::WebAutofillClient* autofill_client = nullptr;
1277 if (auto* focused_frame = GetWebView()->FocusedFrame())
1278 autofill_client = focused_frame->AutofillClient();
1279
[email protected]1875bc02014-03-14 06:33:591280 if (has_scrolled_focused_editable_node_into_rect_ &&
ekaramad27ca69b12017-04-20 18:34:291281 rect == rect_for_scrolled_focused_editable_node_ && autofill_client) {
1282 autofill_client->DidCompleteFocusChangeInFrame();
[email protected]1875bc02014-03-14 06:33:591283 return;
1284 }
1285
Blink Reformat1c4d759e2017-04-09 16:34:541286 if (!webview()->ScrollFocusedEditableElementIntoRect(rect))
dglazkov4969a3e2016-05-20 21:13:511287 return;
rouslanf7ebd8832015-01-22 01:54:141288
dglazkov4969a3e2016-05-20 21:13:511289 rect_for_scrolled_focused_editable_node_ = rect;
1290 has_scrolled_focused_editable_node_into_rect_ = true;
ekaramad27ca69b12017-04-20 18:34:291291 if (!compositor()->HasPendingPageScaleAnimation() && autofill_client)
1292 autofill_client->DidCompleteFocusChangeInFrame();
[email protected]25bcc8f2013-01-09 02:49:251293}
1294
avi2b177592014-12-10 02:08:021295void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset,
1296 int history_length) {
1297 DCHECK_GE(history_offset, -1);
[email protected]e1ed5a12012-08-08 19:57:441298 DCHECK_GE(history_length, 0);
[email protected]9e1ad4b2011-08-14 16:49:191299
avi2b177592014-12-10 02:08:021300 history_list_offset_ = history_offset;
1301 history_list_length_ = history_length;
[email protected]9e1ad4b2011-08-14 16:49:191302}
1303
[email protected]310ebd6302011-10-10 19:06:281304void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291305 if (!webview())
1306 return;
Blink Reformat1c4d759e2017-04-09 16:34:541307 webview()->SetInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291308}
1309
lfgdb5c4ed2016-03-04 23:09:071310void RenderViewImpl::OnUpdateWindowScreenRect(gfx::Rect window_screen_rect) {
1311 RenderWidget::OnUpdateWindowScreenRect(window_screen_rect);
1312}
1313
altimind8bd26c2016-11-04 11:44:541314void RenderViewImpl::OnAudioStateChanged(bool is_audio_playing) {
Blink Reformat1c4d759e2017-04-09 16:34:541315 webview()->AudioStateChanged(is_audio_playing);
altimind8bd26c2016-11-04 11:44:541316}
1317
initial.commit09911bf2008-07-26 23:55:291318///////////////////////////////////////////////////////////////////////////////
1319
nickf7b38222016-11-22 21:59:351320void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget,
1321 WebNavigationPolicy policy,
1322 const gfx::Rect& initial_rect) {
1323 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(),
1324 initial_rect));
1325}
1326
1327void RenderViewImpl::ShowCreatedFullscreenWidget(
1328 RenderWidget* fullscreen_widget,
1329 WebNavigationPolicy policy,
1330 const gfx::Rect& initial_rect) {
1331 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(),
1332 fullscreen_widget->routing_id()));
1333}
1334
creis69b184a472015-11-26 05:29:511335void RenderViewImpl::SendFrameStateUpdates() {
creis69b184a472015-11-26 05:29:511336 // Tell each frame with pending state to send its UpdateState message.
1337 for (int render_frame_routing_id : frames_with_pending_state_) {
1338 RenderFrameImpl* frame =
1339 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
1340 if (frame)
1341 frame->SendUpdateState();
1342 }
1343 frames_with_pending_state_.clear();
1344}
1345
sataya.mf405d0e2015-07-07 16:51:111346void RenderViewImpl::ApplyWebPreferencesInternal(
1347 const WebPreferences& prefs,
1348 blink::WebView* web_view,
1349 CompositorDependencies* compositor_deps) {
1350 ApplyWebPreferences(prefs, web_view);
sataya.mf405d0e2015-07-07 16:51:111351}
1352
svartmetal751af1f92016-08-13 11:47:331353void RenderViewImpl::OnForceRedraw(const ui::LatencyInfo& latency_info) {
[email protected]7d08a9352013-10-15 08:24:561354 if (RenderWidgetCompositor* rwc = compositor()) {
svartmetal751af1f92016-08-13 11:47:331355 rwc->QueueSwapPromise(
1356 base::MakeUnique<AlwaysDrawSwapPromise>(latency_info));
danakj87fbafb2017-04-04 16:54:111357 rwc->SetNeedsForcedRedraw();
[email protected]7d08a9352013-10-15 08:24:561358 }
[email protected]c9bc8f12012-12-15 22:20:091359}
1360
[email protected]180ef242013-11-07 06:50:461361// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521362
csharrison95f01e922017-04-24 18:52:351363// TODO(csharrison): Migrate this method to WebFrameClient / RenderFrameImpl, as
1364// it is now serviced by a mojo interface scoped to the opener frame.
Blink Reformat1c4d759e2017-04-09 16:34:541365WebView* RenderViewImpl::CreateView(WebLocalFrame* creator,
[email protected]35b2a972014-04-04 15:50:221366 const WebURLRequest& request,
1367 const WebWindowFeatures& features,
1368 const WebString& frame_name,
1369 WebNavigationPolicy policy,
1370 bool suppress_opener) {
nick5ae4d2d2017-01-06 01:18:351371 RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator);
rockot5c478a72016-09-28 23:14:181372 mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New();
Blink Reformat1c4d759e2017-04-09 16:34:541373 params->user_gesture = WebUserGestureIndicator::IsProcessingUserGesture();
[email protected]00323f02013-07-24 15:47:411374 if (GetContentClient()->renderer()->AllowPopup())
rockot5c478a72016-09-28 23:14:181375 params->user_gesture = true;
1376 params->window_container_type = WindowFeaturesToContainerType(features);
1377 params->session_storage_namespace_id = session_storage_namespace_id_;
[email protected]5cef23d2013-02-27 13:11:211378 if (frame_name != "_blank")
Blink Reformat1c4d759e2017-04-09 16:34:541379 params->frame_name = frame_name.Utf8(
kinukoa4293022017-01-27 06:43:251380 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
alexmosa97d5c52015-06-19 22:19:091381
rockot5c478a72016-09-28 23:14:181382 params->opener_suppressed = suppress_opener;
1383 params->disposition = NavigationPolicyToDisposition(policy);
Blink Reformat1c4d759e2017-04-09 16:34:541384 if (!request.IsNull()) {
1385 params->target_url = request.Url();
rockot5c478a72016-09-28 23:14:181386 params->referrer = GetReferrerFromRequest(creator, request);
[email protected]44e55b012013-07-23 14:21:561387 }
scottmg8e6c6082017-02-13 23:15:481388 params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
[email protected]8ab04652010-06-12 02:47:261389
rockot5c478a72016-09-28 23:14:181390 // We preserve this information before sending the message since |params| is
1391 // moved on send.
1392 bool is_background_tab =
1393 params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB;
1394 bool opened_by_user_gesture = params->user_gesture;
[email protected]22217ed32013-11-18 18:40:231395
rockot5c478a72016-09-28 23:14:181396 mojom::CreateNewWindowReplyPtr reply;
csharrison95f01e922017-04-24 18:52:351397 mojom::FrameHostAssociatedPtr frame_host_ptr = creator_frame->GetFrameHost();
Charles Harrisonf95354a72017-05-31 23:07:561398 bool err = !frame_host_ptr->CreateNewWindow(std::move(params), &reply);
1399 if (err || reply->route_id == MSG_ROUTING_NONE)
rockot5c478a72016-09-28 23:14:181400 return nullptr;
[email protected]48c9cf2d2009-09-16 16:47:521401
Blink Reformat1c4d759e2017-04-09 16:34:541402 WebUserGestureIndicator::ConsumeUserGesture();
[email protected]c59262422012-11-30 21:20:521403
Jochen Eisinger515337a2017-05-26 14:12:521404 // For Android WebView, we support a pop-up like behavior for window.open()
1405 // even if the embedding app doesn't support multiple windows. In this case,
1406 // window.open() will return "window" and navigate it to whatever URL was
1407 // passed.
1408 if (reply->route_id == GetRoutingID())
1409 return webview();
1410
[email protected]7912e822014-04-16 02:37:031411 // While this view may be a background extension page, it can spawn a visible
1412 // render view. So we just assume that the new one is not another background
1413 // page instead of passing on our own value.
1414 // TODO(vangelis): Can we tell if the new view will be a background page?
1415 bool never_visible = false;
[email protected]9115d5f2013-03-24 04:37:411416
fsamuel664e8b62016-01-20 19:54:011417 ResizeParams initial_size = ResizeParams();
mkosiba58fa72f02014-11-12 01:21:361418 initial_size.screen_info = screen_info_;
1419
[email protected]d6fa88f2013-10-18 16:00:431420 // The initial hidden state for the RenderViewImpl here has to match what the
1421 // browser will eventually decide for the given disposition. Since we have to
1422 // return from this call synchronously, we just have to make our best guess
1423 // and rely on the browser sending a WasHidden / WasShown message if it
1424 // disagrees.
rockot067ca55f2016-09-30 22:00:151425 mojom::CreateViewParams view_params;
alexmos5ac402d2015-07-09 07:51:101426
alexmos5ac402d2015-07-09 07:51:101427 view_params.opener_frame_route_id = creator_frame->GetRoutingID();
avia3dca182016-03-19 01:09:521428 DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID());
alexmos5ac402d2015-07-09 07:51:101429
naskobd911332014-11-25 01:13:361430 view_params.window_was_created_with_opener = true;
1431 view_params.renderer_preferences = renderer_preferences_;
1432 view_params.web_preferences = webkit_preferences_;
rockot5c478a72016-09-28 23:14:181433 view_params.view_id = reply->route_id;
1434 view_params.main_frame_routing_id = reply->main_frame_route_id;
1435 view_params.main_frame_widget_routing_id = reply->main_frame_widget_route_id;
naskobd911332014-11-25 01:13:361436 view_params.session_storage_namespace_id =
rockot5c478a72016-09-28 23:14:181437 reply->cloned_session_storage_namespace_id;
naskobd911332014-11-25 01:13:361438 view_params.swapped_out = false;
alexmos3448b552015-06-26 07:49:131439 // WebCore will take care of setting the correct name.
alexmosbc7eafa2014-12-06 01:38:091440 view_params.replicated_frame_state = FrameReplicationState();
rockot5c478a72016-09-28 23:14:181441 view_params.hidden = is_background_tab;
naskobd911332014-11-25 01:13:361442 view_params.never_visible = never_visible;
naskobd911332014-11-25 01:13:361443 view_params.initial_size = initial_size;
1444 view_params.enable_auto_resize = false;
1445 view_params.min_size = gfx::Size();
1446 view_params.max_size = gfx::Size();
wjmaclean64951902016-04-29 20:59:121447 view_params.page_zoom_level = page_zoom_level_;
naskobd911332014-11-25 01:13:361448
nick5ae4d2d2017-01-06 01:18:351449 // Unretained() is safe here because our calling function will also call
1450 // show().
nickf7b38222016-11-22 21:59:351451 RenderWidget::ShowCallback show_callback =
nick5ae4d2d2017-01-06 01:18:351452 base::Bind(&RenderFrameImpl::ShowCreatedWindow,
1453 base::Unretained(creator_frame), opened_by_user_gesture);
nickf7b38222016-11-22 21:59:351454
danakj6e3bf8012014-12-16 18:27:531455 RenderViewImpl* view =
nickf7b38222016-11-22 21:59:351456 RenderViewImpl::Create(compositor_deps_, view_params, show_callback);
[email protected]48c9cf2d2009-09-16 16:47:521457
[email protected]48c9cf2d2009-09-16 16:47:521458 return view->webview();
1459}
1460
Blink Reformat1c4d759e2017-04-09 16:34:541461WebWidget* RenderViewImpl::CreatePopupMenu(blink::WebPopupType popup_type) {
nickf7b38222016-11-22 21:59:351462 RenderWidget* widget = RenderWidget::CreateForPopup(this, compositor_deps_,
1463 popup_type, screen_info_);
[email protected]3b78ec12014-03-04 05:18:281464 if (!widget)
1465 return NULL;
[email protected]b2e4c70132013-10-03 02:07:511466 if (screen_metrics_emulator_) {
1467 widget->SetPopupOriginAdjustmentsForEmulation(
1468 screen_metrics_emulator_.get());
1469 }
lfg8ff33912016-09-13 20:59:211470 return widget->GetWebWidget();
[email protected]48c9cf2d2009-09-16 16:47:521471}
1472
Blink Reformat1c4d759e2017-04-09 16:34:541473WebStorageNamespace* RenderViewImpl::CreateSessionStorageNamespace() {
[email protected]5f2aa722013-08-07 16:59:411474 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:101475 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341476}
1477
Blink Reformat1c4d759e2017-04-09 16:34:541478void RenderViewImpl::PrintPage(WebLocalFrame* frame) {
naskoe440d8c2016-10-12 23:07:561479 UMA_HISTOGRAM_BOOLEAN("PrintPreview.InitiatedByScript",
Blink Reformat1c4d759e2017-04-09 16:34:541480 frame->Top() == frame);
naskoe440d8c2016-10-12 23:07:561481
1482 // Logging whether the top frame is remote is sufficient in this case. If
1483 // the top frame is local, the printing code will function correctly and
1484 // the frame itself will be printed, so the cases this histogram tracks is
1485 // where printing of a subframe will fail as of now.
1486 UMA_HISTOGRAM_BOOLEAN("PrintPreview.OutOfProcessSubframe",
Blink Reformat1c4d759e2017-04-09 16:34:541487 frame->Top()->IsWebRemoteFrame());
naskoe440d8c2016-10-12 23:07:561488
thestigcb959ce2016-11-17 05:56:321489 RenderFrameImpl::FromWebFrame(frame)->ScriptedPrint(
1490 input_handler().handling_input_event());
[email protected]48c9cf2d2009-09-16 16:47:521491}
1492
Blink Reformat1c4d759e2017-04-09 16:34:541493bool RenderViewImpl::EnumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121494 const WebString& path,
1495 WebFileChooserCompletion* chooser_completion) {
1496 int id = enumeration_completion_id_++;
1497 enumeration_completions_[id] = chooser_completion;
1498 return Send(new ViewHostMsg_EnumerateDirectory(
avia3dca182016-03-19 01:09:521499 GetRoutingID(), id, blink::WebStringToFilePath(path)));
[email protected]8a58c1c2011-04-19 18:40:121500}
1501
[email protected]7e9523b2014-03-25 03:02:421502void RenderViewImpl::FrameDidStartLoading(WebFrame* frame) {
[email protected]7e9523b2014-03-25 03:02:421503 DCHECK_GE(frames_in_progress_, 0);
ericwilligers88e69742016-10-17 19:29:551504 if (frames_in_progress_ == 0) {
1505 for (auto& observer : observers_)
1506 observer.DidStartLoading();
1507 }
[email protected]7e9523b2014-03-25 03:02:421508 frames_in_progress_++;
[email protected]6dd5c322014-03-12 07:58:461509}
1510
[email protected]7e9523b2014-03-25 03:02:421511void RenderViewImpl::FrameDidStopLoading(WebFrame* frame) {
[email protected]eb473772014-04-11 20:54:331512 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
1513 // calls DidStopLoading() without a matching DidStartLoading().
1514 if (frames_in_progress_ == 0)
1515 return;
[email protected]7e9523b2014-03-25 03:02:421516 frames_in_progress_--;
[email protected]7e9523b2014-03-25 03:02:421517 if (frames_in_progress_ == 0) {
ericwilligers88e69742016-10-17 19:29:551518 for (auto& observer : observers_)
1519 observer.DidStopLoading();
[email protected]7e9523b2014-03-25 03:02:421520 }
[email protected]48c9cf2d2009-09-16 16:47:521521}
1522
lfgcaab5142016-02-26 19:06:521523void RenderViewImpl::AttachWebFrameWidget(blink::WebFrameWidget* frame_widget) {
dcheng3ce04b62015-10-26 23:30:551524 // The previous WebFrameWidget must already be detached by CloseForFrame().
1525 DCHECK(!frame_widget_);
1526 frame_widget_ = frame_widget;
1527}
1528
tommycli8aad3ba2015-08-12 17:57:591529void RenderViewImpl::SetZoomLevel(double zoom_level) {
wjmaclean64951902016-04-29 20:59:121530 // If we change the zoom level for the view, make sure any subsequent subframe
1531 // loads reflect the current zoom level.
1532 page_zoom_level_ = zoom_level;
1533
Blink Reformat1c4d759e2017-04-09 16:34:541534 webview()->SetZoomLevel(zoom_level);
ericwilligers88e69742016-10-17 19:29:551535 for (auto& observer : observers_)
1536 observer.OnZoomLevelChanged();
tommycli8aad3ba2015-08-12 17:57:591537}
1538
habib.virji597255e2014-09-09 00:30:181539void RenderViewImpl::SetValidationMessageDirection(
1540 base::string16* wrapped_main_text,
1541 blink::WebTextDirection main_text_hint,
1542 base::string16* wrapped_sub_text,
1543 blink::WebTextDirection sub_text_hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541544 if (main_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181545 *wrapped_main_text =
1546 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
Blink Reformat1c4d759e2017-04-09 16:34:541547 } else if (main_text_hint == blink::kWebTextDirectionRightToLeft &&
habib.virji597255e2014-09-09 00:30:181548 !base::i18n::IsRTL()) {
1549 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
1550 }
1551
1552 if (!wrapped_sub_text->empty()) {
Blink Reformat1c4d759e2017-04-09 16:34:541553 if (sub_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181554 *wrapped_sub_text =
1555 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
Blink Reformat1c4d759e2017-04-09 16:34:541556 } else if (sub_text_hint == blink::kWebTextDirectionRightToLeft) {
habib.virji597255e2014-09-09 00:30:181557 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
1558 }
1559 }
1560}
1561
Blink Reformat1c4d759e2017-04-09 16:34:541562void RenderViewImpl::ShowValidationMessage(
bokan72a7e342015-12-03 15:46:281563 const blink::WebRect& anchor_in_viewport,
[email protected]edc3af82013-12-12 21:24:071564 const blink::WebString& main_text,
habib.virji597255e2014-09-09 00:30:181565 blink::WebTextDirection main_text_hint,
[email protected]edc3af82013-12-12 21:24:071566 const blink::WebString& sub_text,
habib.virji597255e2014-09-09 00:30:181567 blink::WebTextDirection sub_text_hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541568 base::string16 wrapped_main_text = main_text.Utf16();
1569 base::string16 wrapped_sub_text = sub_text.Utf16();
habib.virji597255e2014-09-09 00:30:181570
1571 SetValidationMessageDirection(
1572 &wrapped_main_text, main_text_hint, &wrapped_sub_text, sub_text_hint);
1573
[email protected]edc3af82013-12-12 21:24:071574 Send(new ViewHostMsg_ShowValidationMessage(
avia3dca182016-03-19 01:09:521575 GetRoutingID(), AdjustValidationMessageAnchor(anchor_in_viewport),
[email protected]2d6836f42014-07-02 17:25:311576 wrapped_main_text, wrapped_sub_text));
[email protected]edc3af82013-12-12 21:24:071577}
1578
Blink Reformat1c4d759e2017-04-09 16:34:541579void RenderViewImpl::HideValidationMessage() {
avia3dca182016-03-19 01:09:521580 Send(new ViewHostMsg_HideValidationMessage(GetRoutingID()));
[email protected]edc3af82013-12-12 21:24:071581}
1582
Blink Reformat1c4d759e2017-04-09 16:34:541583void RenderViewImpl::MoveValidationMessage(
bokan72a7e342015-12-03 15:46:281584 const blink::WebRect& anchor_in_viewport) {
[email protected]2d6836f42014-07-02 17:25:311585 Send(new ViewHostMsg_MoveValidationMessage(
avia3dca182016-03-19 01:09:521586 GetRoutingID(), AdjustValidationMessageAnchor(anchor_in_viewport)));
[email protected]edc3af82013-12-12 21:24:071587}
1588
[email protected]310ebd6302011-10-10 19:06:281589void RenderViewImpl::UpdateTargetURL(const GURL& url,
1590 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581591 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521592 if (latest_url == target_url_)
1593 return;
[email protected]163f8242009-10-30 20:19:551594
[email protected]48c9cf2d2009-09-16 16:47:521595 // Tell the browser to display a destination link.
1596 if (target_url_status_ == TARGET_INFLIGHT ||
1597 target_url_status_ == TARGET_PENDING) {
1598 // If we have a request in-flight, save the URL to be sent when we
1599 // receive an ACK to the in-flight request. We can happily overwrite
1600 // any existing pending sends.
1601 pending_target_url_ = latest_url;
1602 target_url_status_ = TARGET_PENDING;
1603 } else {
mnaganovbf087422015-12-16 05:10:031604 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411605 // see |ParamTraits<GURL>|.
markdittmer67b71ea2016-03-03 22:40:031606 if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:411607 latest_url = GURL();
avia3dca182016-03-19 01:09:521608 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), latest_url));
[email protected]48c9cf2d2009-09-16 16:47:521609 target_url_ = latest_url;
1610 target_url_status_ = TARGET_INFLIGHT;
1611 }
1612}
1613
[email protected]70221f02013-01-31 22:17:071614gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect(
1615 const gfx::RectF& rect) const {
1616 gfx::RectF window_rect = rect;
Blink Reformat1c4d759e2017-04-09 16:34:541617 window_rect.Scale(device_scale_factor_ * webview()->PageScaleFactor());
[email protected]70221f02013-01-31 22:17:071618 return window_rect;
1619}
1620
creis69b184a472015-11-26 05:29:511621void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) {
creisce0ef3572017-01-26 17:53:081622 // Keep track of which frames have pending updates.
1623 frames_with_pending_state_.insert(frame->GetRoutingID());
creis8eb8ef22015-11-04 22:51:381624
[email protected]882daa92009-11-05 16:31:311625 int delay;
avif937e1d2014-11-02 18:13:071626 if (send_content_state_immediately_)
[email protected]882daa92009-11-05 16:31:311627 delay = 0;
1628 else if (is_hidden())
avif937e1d2014-11-02 18:13:071629 delay = kDelaySecondsForContentStateSyncHidden;
[email protected]882daa92009-11-05 16:31:311630 else
avif937e1d2014-11-02 18:13:071631 delay = kDelaySecondsForContentStateSync;
[email protected]882daa92009-11-05 16:31:311632
avif937e1d2014-11-02 18:13:071633 if (nav_state_sync_timer_.IsRunning()) {
[email protected]882daa92009-11-05 16:31:311634 // The timer is already running. If the delay of the timer maches the amount
1635 // we want to delay by, then return. Otherwise stop the timer so that it
1636 // gets started with the right delay.
avif937e1d2014-11-02 18:13:071637 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
[email protected]882daa92009-11-05 16:31:311638 return;
avif937e1d2014-11-02 18:13:071639 nav_state_sync_timer_.Stop();
[email protected]882daa92009-11-05 16:31:311640 }
1641
creisce0ef3572017-01-26 17:53:081642 // Tell each frame with pending state to inform the browser.
1643 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
1644 &RenderViewImpl::SendFrameStateUpdates);
[email protected]882daa92009-11-05 16:31:311645}
1646
Blink Reformat1c4d759e2017-04-09 16:34:541647void RenderViewImpl::SetMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551648 mouse_over_url_ = GURL(url);
1649 UpdateTargetURL(mouse_over_url_, focus_url_);
1650}
1651
Blink Reformat1c4d759e2017-04-09 16:34:541652void RenderViewImpl::SetKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551653 focus_url_ = GURL(url);
1654 UpdateTargetURL(focus_url_, mouse_over_url_);
1655}
1656
Blink Reformat1c4d759e2017-04-09 16:34:541657bool RenderViewImpl::AcceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451658 return renderer_preferences_.can_accept_load_drops;
1659}
1660
Blink Reformat1c4d759e2017-04-09 16:34:541661void RenderViewImpl::FocusNext() {
avia3dca182016-03-19 01:09:521662 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false));
[email protected]48c9cf2d2009-09-16 16:47:521663}
1664
Blink Reformat1c4d759e2017-04-09 16:34:541665void RenderViewImpl::FocusPrevious() {
avia3dca182016-03-19 01:09:521666 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true));
[email protected]48c9cf2d2009-09-16 16:47:521667}
1668
esprehn3d4471a2015-09-17 07:13:201669// TODO(esprehn): Blink only ever passes Elements, this should take WebElement.
Blink Reformat1c4d759e2017-04-09 16:34:541670void RenderViewImpl::FocusedNodeChanged(const WebNode& fromNode,
estade31c54342015-01-23 03:34:361671 const WebNode& toNode) {
[email protected]1875bc02014-03-14 06:33:591672 has_scrolled_focused_editable_node_into_rect_ = false;
1673
estade31c54342015-01-23 03:34:361674 RenderFrameImpl* previous_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541675 if (!fromNode.IsNull())
1676 previous_frame =
1677 RenderFrameImpl::FromWebFrame(fromNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361678 RenderFrameImpl* new_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541679 if (!toNode.IsNull())
1680 new_frame = RenderFrameImpl::FromWebFrame(toNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361681
1682 if (previous_frame && previous_frame != new_frame)
1683 previous_frame->FocusedNodeChanged(WebNode());
1684 if (new_frame)
1685 new_frame->FocusedNodeChanged(toNode);
1686
1687 // TODO(dmazzoni): remove once there's a separate a11y tree per frame.
naskoe8d115752015-08-07 00:43:131688 if (main_render_frame_)
1689 main_render_frame_->FocusedNodeChangedForAccessibility(toNode);
[email protected]08e9e132010-06-01 16:58:491690}
1691
Blink Reformat1c4d759e2017-04-09 16:34:541692void RenderViewImpl::DidUpdateLayout() {
ericwilligers88e69742016-10-17 19:29:551693 for (auto& observer : observers_)
1694 observer.DidUpdateLayout();
[email protected]d01b2a62013-09-18 23:21:331695
[email protected]169d4282011-11-30 19:33:591696 // We don't always want to set up a timer, only if we've been put in that
1697 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1698 // message.
1699 if (!send_preferred_size_changes_ || !webview())
1700 return;
1701
1702 if (check_preferred_size_timer_.IsRunning())
1703 return;
1704 check_preferred_size_timer_.Start(FROM_HERE,
1705 TimeDelta::FromMilliseconds(0), this,
1706 &RenderViewImpl::CheckPreferredSize);
1707}
1708
Blink Reformat1c4d759e2017-04-09 16:34:541709void RenderViewImpl::NavigateBackForwardSoon(int offset) {
avia3dca182016-03-19 01:09:521710 Send(new ViewHostMsg_GoToEntryAtOffset(GetRoutingID(), offset));
[email protected]48c9cf2d2009-09-16 16:47:521711}
1712
Blink Reformat1c4d759e2017-04-09 16:34:541713int RenderViewImpl::HistoryBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001714 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521715}
1716
Blink Reformat1c4d759e2017-04-09 16:34:541717int RenderViewImpl::HistoryForwardListCount() {
1718 return history_list_length_ - HistoryBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521719}
1720
[email protected]180ef242013-11-07 06:50:461721// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:511722
Blink Reformat1c4d759e2017-04-09 16:34:541723void RenderViewImpl::DidFocus() {
[email protected]ea42e7782010-08-23 23:58:121724 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1725 // we won't have to test for user gesture anymore and we can
1726 // move that code back to render_widget.cc
Blink Reformat1c4d759e2017-04-09 16:34:541727 if (WebUserGestureIndicator::IsProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:301728 !RenderThreadImpl::current()->layout_test_mode()) {
avia3dca182016-03-19 01:09:521729 Send(new ViewHostMsg_Focus(GetRoutingID()));
[email protected]ea42e7782010-08-23 23:58:121730 }
1731}
1732
nickf7b38222016-11-22 21:59:351733// We are supposed to get a single call to show() for a newly created RenderView
1734// that was created via RenderViewImpl::createView. We wait until this point to
1735// run |show_callback|, which is bound to our opener's ShowCreatedViewWidget()
1736// method.
initial.commit09911bf2008-07-26 23:55:291737//
1738// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281739// created RenderView (i.e., as a blocked popup or as a new tab).
Blink Reformat1c4d759e2017-04-09 16:34:541740void RenderViewImpl::Show(WebNavigationPolicy policy) {
nickf7b38222016-11-22 21:59:351741 if (did_show_ && !webkit_preferences_.supports_multiple_windows) {
[email protected]b2142e962012-10-30 13:59:251742 // When supports_multiple_windows is disabled, popups are reusing
1743 // the same view. In some scenarios, this makes WebKit to call show() twice.
initial.commit09911bf2008-07-26 23:55:291744 return;
[email protected]b2142e962012-10-30 13:59:251745 }
initial.commit09911bf2008-07-26 23:55:291746
Blink Reformat1c4d759e2017-04-09 16:34:541747 RenderWidget::Show(policy);
initial.commit09911bf2008-07-26 23:55:291748}
1749
miletuse8d28ba2015-06-19 04:52:041750
Blink Reformat1c4d759e2017-04-09 16:34:541751bool RenderViewImpl::CanHandleGestureEvent() {
slangley1a6375e62017-03-29 06:03:231752 return true;
1753}
1754
Blink Reformat1c4d759e2017-04-09 16:34:541755bool RenderViewImpl::CanUpdateLayout() {
slangley1a6375e62017-03-29 06:03:231756 return true;
1757}
1758
Blink Reformat1c4d759e2017-04-09 16:34:541759void RenderViewImpl::DidHandleGestureEvent(const WebGestureEvent& event,
1760 bool event_cancelled) {
1761 RenderWidget::DidHandleGestureEvent(event, event_cancelled);
[email protected]bb37b652013-11-27 23:47:111762
[email protected]91dcc6d32014-07-30 00:01:331763 if (!event_cancelled) {
ericwilligers88e69742016-10-17 19:29:551764 for (auto& observer : observers_)
1765 observer.DidHandleGestureEvent(event);
[email protected]91dcc6d32014-07-30 00:01:331766 }
[email protected]c68c3e4e2013-01-24 00:36:561767}
1768
Blink Reformat1c4d759e2017-04-09 16:34:541769blink::WebLayerTreeView* RenderViewImpl::InitializeLayerTreeView() {
wjmaclean1d970622017-01-21 22:28:241770 // TODO(!wjmaclean): We should be able to just remove this function, and
1771 // expect the RenderWidget version of the function to be called instead.
1772 // However, we have a diamond inheritance pattern going on:
1773 // WebWidgetClient
1774 // | |
1775 // RenderWidget WebViewClient
1776 // | |
1777 // RenderViewImpl
1778 //
1779 // and this seems to prefer calling the empty version in WebWidgetClient
1780 // or WebViewClient over the non-empty one in RenderWidget.
Blink Reformat1c4d759e2017-04-09 16:34:541781 return RenderWidget::InitializeLayerTreeView();
[email protected]6e89eb72013-07-23 13:28:221782}
1783
Blink Reformat1c4d759e2017-04-09 16:34:541784void RenderViewImpl::CloseWidgetSoon() {
1785 RenderWidget::CloseWidgetSoon();
lfg2230bce2016-04-28 18:37:041786}
1787
Blink Reformat1c4d759e2017-04-09 16:34:541788void RenderViewImpl::ConvertViewportToWindow(blink::WebRect* rect) {
1789 RenderWidget::ConvertViewportToWindow(rect);
lfg2230bce2016-04-28 18:37:041790}
1791
Blink Reformat1c4d759e2017-04-09 16:34:541792void RenderViewImpl::ConvertWindowToViewport(blink::WebFloatRect* rect) {
1793 RenderWidget::ConvertWindowToViewport(rect);
lfg2230bce2016-04-28 18:37:041794}
1795
Blink Reformat1c4d759e2017-04-09 16:34:541796void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) {
lfgb00fcad2016-07-14 14:16:331797 RenderWidget::DidAutoResize(newSize);
lfg2230bce2016-04-28 18:37:041798}
1799
Blink Reformat1c4d759e2017-04-09 16:34:541800void RenderViewImpl::DidOverscroll(
lfg2230bce2016-04-28 18:37:041801 const blink::WebFloatSize& overscrollDelta,
1802 const blink::WebFloatSize& accumulatedOverscroll,
1803 const blink::WebFloatPoint& positionInViewport,
1804 const blink::WebFloatSize& velocityInViewport) {
Blink Reformat1c4d759e2017-04-09 16:34:541805 RenderWidget::DidOverscroll(overscrollDelta, accumulatedOverscroll,
lfg2230bce2016-04-28 18:37:041806 positionInViewport, velocityInViewport);
1807}
1808
Blink Reformat1c4d759e2017-04-09 16:34:541809void RenderViewImpl::HasTouchEventHandlers(bool has_handlers) {
1810 RenderWidget::HasTouchEventHandlers(has_handlers);
lfg2230bce2016-04-28 18:37:041811}
1812
Blink Reformat1c4d759e2017-04-09 16:34:541813blink::WebRect RenderViewImpl::RootWindowRect() {
1814 return RenderWidget::WindowRect();
lfg2230bce2016-04-28 18:37:041815}
1816
Blink Reformat1c4d759e2017-04-09 16:34:541817blink::WebScreenInfo RenderViewImpl::GetScreenInfo() {
1818 return RenderWidget::GetScreenInfo();
lfg2230bce2016-04-28 18:37:041819}
1820
Blink Reformat1c4d759e2017-04-09 16:34:541821void RenderViewImpl::SetToolTipText(const blink::WebString& text,
lfg2230bce2016-04-28 18:37:041822 blink::WebTextDirection hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541823 RenderWidget::SetToolTipText(text, hint);
lfg2230bce2016-04-28 18:37:041824}
1825
Blink Reformat1c4d759e2017-04-09 16:34:541826void RenderViewImpl::SetTouchAction(blink::WebTouchAction touchAction) {
1827 RenderWidget::SetTouchAction(touchAction);
lfg2230bce2016-04-28 18:37:041828}
1829
Blink Reformat1c4d759e2017-04-09 16:34:541830void RenderViewImpl::ShowUnhandledTapUIIfNeeded(
lfg2230bce2016-04-28 18:37:041831 const blink::WebPoint& tappedPosition,
1832 const blink::WebNode& tappedNode,
1833 bool pageChanged) {
Blink Reformat1c4d759e2017-04-09 16:34:541834 RenderWidget::ShowUnhandledTapUIIfNeeded(tappedPosition, tappedNode,
lfg2230bce2016-04-28 18:37:041835 pageChanged);
1836}
1837
Blink Reformat1c4d759e2017-04-09 16:34:541838blink::WebWidgetClient* RenderViewImpl::WidgetClient() {
lfg0f440622016-07-20 04:27:141839 return static_cast<RenderWidget*>(this);
1840}
1841
[email protected]180ef242013-11-07 06:50:461842// blink::WebFrameClient -----------------------------------------------------
[email protected]3d9689372009-09-10 04:29:171843
[email protected]5e92282f2012-08-17 08:11:571844void RenderViewImpl::Repaint(const gfx::Size& size) {
[email protected]3d9ec5052013-01-02 22:05:251845 OnRepaint(size);
[email protected]5e92282f2012-08-17 08:11:571846}
1847
[email protected]b2324b092012-11-01 10:34:111848void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
1849 const std::string& value) {
alexmos56567492016-09-13 00:52:461850 GetWidget()->SetEditCommandForNextKeyEvent(name, value);
[email protected]b2324b092012-11-01 10:34:111851}
1852
1853void RenderViewImpl::ClearEditCommands() {
alexmos56567492016-09-13 00:52:461854 GetWidget()->ClearEditCommands();
[email protected]b2324b092012-11-01 10:34:111855}
1856
[email protected]b38806a2013-10-04 16:01:381857const std::string& RenderViewImpl::GetAcceptLanguages() const {
1858 return renderer_preferences_.accept_languages;
1859}
1860
danakjdea2efb2016-03-10 19:13:171861void RenderViewImpl::ConvertViewportToWindowViaWidget(blink::WebRect* rect) {
Blink Reformat1c4d759e2017-04-09 16:34:541862 ConvertViewportToWindow(rect);
oshimae2b3b402015-12-04 04:27:241863}
1864
huangs2a342352015-12-15 16:59:241865gfx::RectF RenderViewImpl::ElementBoundsInWindow(
1866 const blink::WebElement& element) {
Blink Reformat1c4d759e2017-04-09 16:34:541867 blink::WebRect bounding_box_in_window = element.BoundsInViewport();
danakjdea2efb2016-03-10 19:13:171868 ConvertViewportToWindowViaWidget(&bounding_box_in_window);
huangs2a342352015-12-15 16:59:241869 return gfx::RectF(bounding_box_in_window);
1870}
1871
changwand659e202016-06-13 02:39:121872bool RenderViewImpl::HasAddedInputHandler() const {
1873 return has_added_input_handler_;
1874}
1875
[email protected]310ebd6302011-10-10 19:06:281876void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:071877 // We don't always want to send the change messages over IPC, only if we've
1878 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1879 // message.
1880 if (!send_preferred_size_changes_ || !webview())
1881 return;
1882
Blink Reformat1c4d759e2017-04-09 16:34:541883 gfx::Size size = webview()->ContentsPreferredMinimumSize();
[email protected]705243f2010-05-05 19:58:071884 if (size == preferred_size_)
1885 return;
[email protected]c27324b2009-11-19 22:44:291886
[email protected]705243f2010-05-05 19:58:071887 preferred_size_ = size;
avia3dca182016-03-19 01:09:521888 Send(new ViewHostMsg_DidContentsPreferredSizeChange(GetRoutingID(),
[email protected]705243f2010-05-05 19:58:071889 preferred_size_));
[email protected]3d9689372009-09-10 04:29:171890}
1891
Blink Reformat1c4d759e2017-04-09 16:34:541892blink::WebString RenderViewImpl::AcceptLanguages() {
1893 return WebString::FromUTF8(renderer_preferences_.accept_languages);
[email protected]9982c802013-06-12 15:22:061894}
1895
[email protected]e9ff79c2012-10-19 21:31:261896// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:311897
[email protected]310ebd6302011-10-10 19:06:281898bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:311899 return RenderWidget::Send(message);
1900}
1901
avi8a45c1092016-03-01 16:12:341902RenderWidget* RenderViewImpl::GetWidget() const {
1903 return const_cast<RenderWidget*>(static_cast<const RenderWidget*>(this));
1904}
1905
mostynbc33353232014-09-12 09:38:311906RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() {
nasko77de2312015-05-12 03:09:161907 return main_render_frame_;
[email protected]b849847b2013-12-10 21:57:581908}
1909
[email protected]82114f52012-03-20 22:53:411910int RenderViewImpl::GetRoutingID() const {
fsamuele8326c742016-01-12 00:49:391911 return routing_id();
[email protected]a2ef54c2011-10-10 16:20:311912}
1913
[email protected]82114f52012-03-20 22:53:411914gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:311915 return size();
1916}
1917
oshima129b75e2016-01-14 09:15:141918float RenderViewImpl::GetDeviceScaleFactor() const {
1919 return device_scale_factor_;
1920}
1921
thestig8a8fdfd32017-05-06 18:46:541922const WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:311923 return webkit_preferences_;
1924}
1925
[email protected]324825d2012-11-30 12:37:151926void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
1927 OnUpdateWebPreferences(preferences);
1928}
1929
[email protected]180ef242013-11-07 06:50:461930blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:311931 return webview();
1932}
1933
lfgcaab5142016-02-26 19:06:521934blink::WebFrameWidget* RenderViewImpl::GetWebFrameWidget() {
1935 return frame_widget_;
1936}
1937
[email protected]310ebd6302011-10-10 19:06:281938bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:311939 return (!send_preferred_size_changes_ ||
1940 (disable_scrollbars_size_limit_.width() <= width ||
1941 disable_scrollbars_size_limit_.height() <= height));
1942}
1943
avif937e1d2014-11-02 18:13:071944bool RenderViewImpl::GetContentStateImmediately() const {
1945 return send_content_state_immediately_;
[email protected]a2ef54c2011-10-10 16:20:311946}
1947
mcnee432e47d2015-11-09 19:37:461948void RenderViewImpl::OnSetPageScale(float page_scale_factor) {
ccameronb7c1d6c2015-03-09 17:08:241949 if (!webview())
1950 return;
Blink Reformat1c4d759e2017-04-09 16:34:541951 webview()->SetPageScaleFactor(page_scale_factor);
ccameronb7c1d6c2015-03-09 17:08:241952}
1953
wjmaclean64951902016-04-29 20:59:121954void RenderViewImpl::OnSetZoomLevel(
1955 PageMsg_SetZoomLevel_Command command,
1956 double zoom_level) {
1957 switch (command) {
1958 case PageMsg_SetZoomLevel_Command::CLEAR_TEMPORARY:
1959 uses_temporary_zoom_level_ = false;
1960 break;
1961 case PageMsg_SetZoomLevel_Command::SET_TEMPORARY:
1962 uses_temporary_zoom_level_ = true;
1963 break;
1964 case PageMsg_SetZoomLevel_Command::USE_CURRENT_TEMPORARY_MODE:
1965 // Don't override a temporary zoom level without an explicit SET.
1966 if (uses_temporary_zoom_level_)
1967 return;
1968 break;
1969 default:
1970 NOTIMPLEMENTED();
1971 }
Blink Reformat1c4d759e2017-04-09 16:34:541972 webview()->HidePopups();
wjmaclean64951902016-04-29 20:59:121973 SetZoomLevel(zoom_level);
[email protected]d42bf472014-06-14 01:49:381974}
1975
[email protected]310ebd6302011-10-10 19:06:281976void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:591977 webkit_preferences_ = prefs;
sataya.mf405d0e2015-07-07 16:51:111978 ApplyWebPreferencesInternal(webkit_preferences_, webview(), compositor_deps_);
initial.commit09911bf2008-07-26 23:55:291979}
1980
[email protected]310ebd6302011-10-10 19:06:281981void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:511982 int id,
[email protected]c42de732013-02-16 06:26:311983 const std::vector<base::FilePath>& paths) {
[email protected]600ea402011-04-12 00:01:511984 if (!enumeration_completions_[id])
1985 return;
1986
1987 WebVector<WebString> ws_file_names(paths.size());
1988 for (size_t i = 0; i < paths.size(); ++i)
kinukoa4293022017-01-27 06:43:251989 ws_file_names[i] = blink::FilePathToWebString(paths[i]);
[email protected]600ea402011-04-12 00:01:511990
Blink Reformat1c4d759e2017-04-09 16:34:541991 enumeration_completions_[id]->DidChooseFile(ws_file_names);
[email protected]600ea402011-04-12 00:01:511992 enumeration_completions_.erase(id);
1993}
1994
[email protected]244ac1892011-12-02 17:04:471995void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
1996 const gfx::Size& max_size) {
1997 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
1998 if (!webview())
1999 return;
oshima33ec97cd2015-12-14 19:40:242000
[email protected]97e1bf72013-03-06 14:06:052001 auto_resize_mode_ = true;
oshima33ec97cd2015-12-14 19:40:242002 if (IsUseZoomForDSFEnabled()) {
Blink Reformat1c4d759e2017-04-09 16:34:542003 webview()->EnableAutoResizeMode(
oshima33ec97cd2015-12-14 19:40:242004 gfx::ScaleToCeiledSize(min_size, device_scale_factor_),
2005 gfx::ScaleToCeiledSize(max_size, device_scale_factor_));
2006 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542007 webview()->EnableAutoResizeMode(min_size, max_size);
oshima33ec97cd2015-12-14 19:40:242008 }
[email protected]61e2b3cc2012-03-02 16:13:342009}
2010
2011void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
2012 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
2013 if (!webview())
2014 return;
[email protected]97e1bf72013-03-06 14:06:052015 auto_resize_mode_ = false;
Blink Reformat1c4d759e2017-04-09 16:34:542016 webview()->DisableAutoResizeMode();
[email protected]61e2b3cc2012-03-02 16:13:342017
[email protected]eac2b362013-05-22 07:01:452018 if (!new_size.IsEmpty()) {
mfomitchev2600fd7c2016-02-17 20:53:392019 ResizeParams resize_params;
jbroman5ff10302016-07-22 03:36:262020 resize_params.screen_info = screen_info_;
mfomitchev2600fd7c2016-02-17 20:53:392021 resize_params.new_size = new_size;
2022 resize_params.physical_backing_size = physical_backing_size_;
mdjones2ee41afd2016-10-27 16:50:202023 resize_params.browser_controls_shrink_blink_size =
2024 browser_controls_shrink_blink_size_;
mfomitchev2600fd7c2016-02-17 20:53:392025 resize_params.top_controls_height = top_controls_height_;
2026 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:392027 resize_params.is_fullscreen_granted = is_fullscreen_granted();
2028 resize_params.display_mode = display_mode_;
2029 resize_params.needs_resize_ack = false;
2030 Resize(resize_params);
[email protected]eac2b362013-05-22 07:01:452031 }
[email protected]244ac1892011-12-02 17:04:472032}
2033
[email protected]2bf834f2011-11-17 20:02:212034void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:242035 if (send_preferred_size_changes_)
2036 return;
[email protected]9fb325e2010-05-06 18:23:242037 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:392038
[email protected]d812fd12011-05-27 23:05:072039 // Start off with an initial preferred size notification (in case
2040 // |didUpdateLayout| was already called).
Blink Reformat1c4d759e2017-04-09 16:34:542041 DidUpdateLayout();
[email protected]0666aef2009-05-13 19:48:082042}
2043
[email protected]310ebd6302011-10-10 19:06:282044void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:102045 const gfx::Size& disable_scrollbar_size_limit) {
2046 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
2047}
2048
[email protected]310ebd6302011-10-10 19:06:282049void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:262050 const RendererPreferences& renderer_prefs) {
[email protected]ebd5ea52014-05-28 14:51:152051 std::string old_accept_languages = renderer_preferences_.accept_languages;
2052
[email protected]80d96fa2009-06-10 22:34:512053 renderer_preferences_ = renderer_prefs;
ananta59b9fe72015-04-07 01:33:262054
[email protected]6e282c92009-07-24 01:19:372055 UpdateFontRenderingFromRendererPrefs();
scottmgb92365e2016-08-30 20:54:402056 UpdateThemePrefs();
Blink Reformat1c4d759e2017-04-09 16:34:542057 blink::SetCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]38a85712013-01-02 22:45:022058
brettw8a274fa2016-11-15 00:20:402059#if BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]1596efb2013-01-17 22:13:012060 if (renderer_prefs.use_custom_colors) {
Blink Reformat1c4d759e2017-04-09 16:34:542061 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
[email protected]1596efb2013-01-17 22:13:012062
2063 if (webview()) {
Blink Reformat1c4d759e2017-04-09 16:34:542064 webview()->SetSelectionColors(renderer_prefs.active_selection_bg_color,
2065 renderer_prefs.active_selection_fg_color,
2066 renderer_prefs.inactive_selection_bg_color,
2067 renderer_prefs.inactive_selection_fg_color);
2068 webview()->ThemeChanged();
[email protected]1596efb2013-01-17 22:13:012069 }
[email protected]644d77e2010-01-27 01:03:102070 }
brettw8a274fa2016-11-15 00:20:402071#endif // BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]d299d972012-03-23 02:26:552072
[email protected]ebd5ea52014-05-28 14:51:152073 if (webview() &&
2074 old_accept_languages != renderer_preferences_.accept_languages) {
Blink Reformat1c4d759e2017-04-09 16:34:542075 webview()->AcceptLanguagesChanged();
[email protected]ebd5ea52014-05-28 14:51:152076 }
[email protected]80d96fa2009-06-10 22:34:512077}
2078
[email protected]310ebd6302011-10-10 19:06:282079void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
2080 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:282081 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542082 webview()->PerformMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:562083}
2084
[email protected]81375e872012-01-11 21:40:362085void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
2086 const WebPluginAction& action) {
2087 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542088 webview()->PerformPluginAction(action, location);
[email protected]81375e872012-01-11 21:40:362089}
2090
[email protected]310ebd6302011-10-10 19:06:282091void RenderViewImpl::OnClosePage() {
initial.commit09911bf2008-07-26 23:55:292092 // TODO(creis): We'd rather use webview()->Close() here, but that currently
2093 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
2094 // in the onunload handler from appearing. For now, we're bypassing that and
2095 // calling the FrameLoader's CloseURL method directly. This should be
2096 // revisited to avoid having two ways to close a page. Having a single way
2097 // to close that can run onunload is also useful for fixing
2098 // http://b/issue?id=753080.
Blink Reformat1c4d759e2017-04-09 16:34:542099 webview()->MainFrame()->DispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:292100
avia3dca182016-03-19 01:09:522101 Send(new ViewHostMsg_ClosePage_ACK(GetRoutingID()));
initial.commit09911bf2008-07-26 23:55:292102}
2103
naskoc288745f2015-05-01 22:54:212104void RenderViewImpl::OnClose() {
2105 if (closing_)
avia3dca182016-03-19 01:09:522106 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(GetRoutingID()));
naskoc288745f2015-05-01 22:54:212107 RenderWidget::OnClose();
2108}
2109
[email protected]310ebd6302011-10-10 19:06:282110void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:002111 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542112 webview()->HidePopups();
[email protected]30f75e62009-02-25 22:01:002113}
2114
bokanc63441c2016-04-27 15:49:122115void RenderViewImpl::ResizeWebWidget() {
Blink Reformat1c4d759e2017-04-09 16:34:542116 webview()->ResizeWithBrowserControls(GetSizeForWebWidget(),
mdjones2ee41afd2016-10-27 16:50:202117 top_controls_height_,
2118 browser_controls_shrink_blink_size_);
bokanc63441c2016-04-27 15:49:122119}
2120
fsamuel664e8b62016-01-20 19:54:012121void RenderViewImpl::OnResize(const ResizeParams& params) {
[email protected]189a8862014-07-18 00:27:532122 TRACE_EVENT0("renderer", "RenderViewImpl::OnResize");
[email protected]cda45c02010-02-25 19:28:102123 if (webview()) {
Blink Reformat1c4d759e2017-04-09 16:34:542124 webview()->HidePopups();
kenrb5fd60fb82016-06-10 17:27:572125 if (send_preferred_size_changes_ &&
Blink Reformat1c4d759e2017-04-09 16:34:542126 webview()->MainFrame()->IsWebLocalFrame()) {
lukasza302fcdd2017-06-02 20:40:352127 webview()->MainFrame()->ToWebLocalFrame()->SetCanHaveScrollbars(
2128 ShouldDisplayScrollbars(params.new_size.width(),
2129 params.new_size.height()));
[email protected]cda45c02010-02-25 19:28:102130 }
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122131 if (display_mode_ != params.display_mode) {
2132 display_mode_ = params.display_mode;
Blink Reformat1c4d759e2017-04-09 16:34:542133 webview()->SetDisplayMode(display_mode_);
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122134 }
[email protected]cda45c02010-02-25 19:28:102135 }
2136
[email protected]cbbdeef2014-05-26 15:57:362137 gfx::Size old_visible_viewport_size = visible_viewport_size_;
2138
mdjones2ee41afd2016-10-27 16:50:202139 browser_controls_shrink_blink_size_ =
2140 params.browser_controls_shrink_blink_size;
bokanc63441c2016-04-27 15:49:122141 top_controls_height_ = params.top_controls_height;
2142
[email protected]0fdd5012013-05-29 08:05:562143 RenderWidget::OnResize(params);
[email protected]cbbdeef2014-05-26 15:57:362144
2145 if (old_visible_viewport_size != visible_viewport_size_)
2146 has_scrolled_focused_editable_node_into_rect_ = false;
[email protected]30f75e62009-02-25 22:01:002147}
[email protected]0aa477bd2009-03-23 22:21:432148
[email protected]61f91832014-05-13 01:24:422149void RenderViewImpl::OnSetBackgroundOpaque(bool opaque) {
esecklerf2bd55f72017-03-31 09:11:572150 if (!frame_widget_)
2151 return;
2152
2153 if (opaque) {
Blink Reformat1c4d759e2017-04-09 16:34:542154 frame_widget_->ClearBaseBackgroundColorOverride();
2155 frame_widget_->ClearBackgroundColorOverride();
esecklerf2bd55f72017-03-31 09:11:572156 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542157 frame_widget_->SetBaseBackgroundColorOverride(SK_ColorTRANSPARENT);
2158 frame_widget_->SetBackgroundColorOverride(SK_ColorTRANSPARENT);
esecklerf2bd55f72017-03-31 09:11:572159 }
[email protected]699ab0d2009-04-23 23:19:142160}
2161
[email protected]310ebd6302011-10-10 19:06:282162void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:342163 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542164 webview()->SetIsActive(active);
[email protected]8c66c5a2009-07-22 17:26:342165}
2166
lfg8ff33912016-09-13 20:59:212167blink::WebWidget* RenderViewImpl::GetWebWidget() const {
2168 if (frame_widget_)
2169 return frame_widget_;
2170
2171 return RenderWidget::GetWebWidget();
2172}
2173
dcheng3ce04b62015-10-26 23:30:552174void RenderViewImpl::CloseForFrame() {
2175 DCHECK(frame_widget_);
Blink Reformat1c4d759e2017-04-09 16:34:542176 frame_widget_->Close();
dcheng3ce04b62015-10-26 23:30:552177 frame_widget_ = nullptr;
2178}
2179
[email protected]310ebd6302011-10-10 19:06:282180void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:592181 // We need to grab a pointer to the doomed WebView before we destroy it.
lfg4fa48da2016-05-09 18:25:132182 WebView* doomed = webview_;
[email protected]60c42a8c72009-10-09 04:08:592183 RenderWidget::Close();
lfg4fa48da2016-05-09 18:25:132184 webview_ = nullptr;
[email protected]625332e02010-12-14 07:48:492185 g_view_map.Get().erase(doomed);
avia3dca182016-03-19 01:09:522186 g_routing_id_view_map.Get().erase(GetRoutingID());
2187 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(GetRoutingID()));
[email protected]60c42a8c72009-10-09 04:08:592188}
2189
lfg717154072016-06-30 15:04:162190void RenderViewImpl::OnPageWasHidden() {
braveyao1d8ee7b2017-03-29 21:10:042191#if defined(OS_ANDROID)
2192 SuspendVideoCaptureDevices(true);
2193#if BUILDFLAG(ENABLE_WEBRTC)
[email protected]e976c3c52014-07-24 17:41:552194 if (speech_recognition_dispatcher_)
2195 speech_recognition_dispatcher_->AbortAllRecognitions();
[email protected]6392d982013-04-16 16:59:222196#endif
braveyao1d8ee7b2017-03-29 21:10:042197#endif
[email protected]2d7b82c2012-06-01 05:57:502198
lfg717154072016-06-30 15:04:162199 if (webview()) {
2200 // TODO(lfg): It's not correct to defer the page visibility to the main
2201 // frame. Currently, this is done because the main frame may override the
2202 // visibility of the page when prerendering. In order to fix this,
2203 // prerendering must be made aware of OOPIFs. https://crbug.com/440544
2204 blink::WebPageVisibilityState visibilityState =
Blink Reformat1c4d759e2017-04-09 16:34:542205 GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState()
2206 : blink::kWebPageVisibilityStateHidden;
2207 webview()->SetVisibilityState(visibilityState, false);
lfg717154072016-06-30 15:04:162208 }
[email protected]941e4552010-02-01 21:23:432209}
2210
lfg717154072016-06-30 15:04:162211void RenderViewImpl::OnPageWasShown() {
braveyao1d8ee7b2017-03-29 21:10:042212#if defined(OS_ANDROID)
2213 SuspendVideoCaptureDevices(false);
[email protected]6392d982013-04-16 16:59:222214#endif
2215
lfg717154072016-06-30 15:04:162216 if (webview()) {
2217 blink::WebPageVisibilityState visibilityState =
Blink Reformat1c4d759e2017-04-09 16:34:542218 GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState()
2219 : blink::kWebPageVisibilityStateVisible;
2220 webview()->SetVisibilityState(visibilityState, false);
lfg717154072016-06-30 15:04:162221 }
[email protected]a6939ca42011-02-18 17:58:072222}
[email protected]1e6e3c992010-02-08 15:52:132223
lfg8d649cc2017-04-28 18:04:302224void RenderViewImpl::OnUpdateScreenInfo(const ScreenInfo& screen_info) {
2225 // This IPC only updates the screen info on RenderViews that have a remote
2226 // main frame. For local main frames, the ScreenInfo is updated in
2227 // ViewMsg_Resize.
2228 if (!main_render_frame_)
2229 screen_info_ = screen_info;
2230}
2231
[email protected]ed7defa2013-03-12 21:29:592232GURL RenderViewImpl::GetURLForGraphicsContext3D() {
2233 DCHECK(webview());
Blink Reformat1c4d759e2017-04-09 16:34:542234 if (webview()->MainFrame()->IsWebLocalFrame())
2235 return GURL(webview()->MainFrame()->GetDocument().Url());
[email protected]ed7defa2013-03-12 21:29:592236 else
2237 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]65225772011-05-12 21:10:242238}
2239
[email protected]310ebd6302011-10-10 19:06:282240void RenderViewImpl::OnSetFocus(bool enable) {
naskoc6edf7e2015-10-16 01:48:452241 // This message must always be received when the main frame is a
2242 // WebLocalFrame.
Blink Reformat1c4d759e2017-04-09 16:34:542243 CHECK(webview()->MainFrame()->IsWebLocalFrame());
alexmos3fcd0ca2015-10-23 18:18:332244 SetFocus(enable);
2245}
alexmos7fac9aeb2015-10-16 22:39:492246
alexmos3fcd0ca2015-10-23 18:18:332247void RenderViewImpl::SetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:132248 RenderWidget::OnSetFocus(enable);
2249
[email protected]321032992012-11-08 01:01:272250 // Notify all BrowserPlugins of the RenderView's focus state.
fsamuel6c1dfeb2014-12-18 19:21:332251 if (BrowserPluginManager::Get())
2252 BrowserPluginManager::Get()->UpdateFocusState();
[email protected]1e6e3c992010-02-08 15:52:132253}
[email protected]941e4552010-02-01 21:23:432254
rouslanf7ebd8832015-01-22 01:54:142255void RenderViewImpl::DidCompletePageScaleAnimation() {
ekaramad27ca69b12017-04-20 18:34:292256 if (auto* focused_frame = GetWebView()->FocusedFrame()) {
2257 if (focused_frame->AutofillClient())
2258 focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame();
2259 }
rouslanf7ebd8832015-01-22 01:54:142260}
2261
oshimad5279032015-12-16 18:22:332262void RenderViewImpl::OnDeviceScaleFactorChanged() {
2263 RenderWidget::OnDeviceScaleFactorChanged();
2264 UpdateWebViewWithDeviceScaleFactor();
2265 if (auto_resize_mode_)
2266 AutoResizeCompositor();
2267}
2268
[email protected]b2e4c70132013-10-03 02:07:512269void RenderViewImpl::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:202270 bool enabled,
2271 const blink::WebDeviceEmulationParams& params) {
[email protected]404630b2014-07-03 19:33:032272 if (webview() && compositor()) {
dgozman9260b0a12015-03-16 13:45:202273 if (enabled)
Blink Reformat1c4d759e2017-04-09 16:34:542274 webview()->EnableDeviceEmulation(params);
dgozman9260b0a12015-03-16 13:45:202275 else
Blink Reformat1c4d759e2017-04-09 16:34:542276 webview()->DisableDeviceEmulation();
[email protected]b2e4c70132013-10-03 02:07:512277 }
2278}
2279
Blink Reformat1c4d759e2017-04-09 16:34:542280blink::WebSpeechRecognizer* RenderViewImpl::SpeechRecognizer() {
[email protected]64d09222012-05-25 10:10:342281 if (!speech_recognition_dispatcher_)
2282 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
[email protected]64d09222012-05-25 10:10:342283 return speech_recognition_dispatcher_;
2284}
2285
Blink Reformat1c4d759e2017-04-09 16:34:542286void RenderViewImpl::ZoomLimitsChanged(double minimum_level,
[email protected]310ebd6302011-10-10 19:06:282287 double maximum_level) {
a.sarkar.arundaadc712015-02-26 05:39:082288 // Round the double to avoid returning incorrect minimum/maximum zoom
2289 // percentages.
2290 int minimum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492291 ZoomLevelToZoomFactor(minimum_level) * 100);
a.sarkar.arundaadc712015-02-26 05:39:082292 int maximum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492293 ZoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:252294
avia3dca182016-03-19 01:09:522295 Send(new ViewHostMsg_UpdateZoomLimits(GetRoutingID(), minimum_percent,
fsamuele8326c742016-01-12 00:49:392296 maximum_percent));
[email protected]b75b8292010-10-01 07:28:252297}
2298
Blink Reformat1c4d759e2017-04-09 16:34:542299void RenderViewImpl::PageScaleFactorChanged() {
ccameronb7c1d6c2015-03-09 17:08:242300 if (!webview())
2301 return;
mcnee432e47d2015-11-09 19:37:462302
avia3dca182016-03-19 01:09:522303 Send(new ViewHostMsg_PageScaleFactorChanged(GetRoutingID(),
Blink Reformat1c4d759e2017-04-09 16:34:542304 webview()->PageScaleFactor()));
ccameronb7c1d6c2015-03-09 17:08:242305}
2306
[email protected]7940b8e2013-07-25 23:08:492307double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const {
2308 return ZoomLevelToZoomFactor(zoom_level);
2309}
2310
2311double RenderViewImpl::zoomFactorToZoomLevel(double factor) const {
2312 return ZoomFactorToZoomLevel(factor);
2313}
2314
Blink Reformat1c4d759e2017-04-09 16:34:542315void RenderViewImpl::DraggableRegionsChanged() {
ericwilligers88e69742016-10-17 19:29:552316 for (auto& observer : observers_)
Blink Reformat1c4d759e2017-04-09 16:34:542317 observer.DraggableRegionsChanged(webview()->MainFrame());
[email protected]a0629af92012-08-08 00:39:372318}
2319
Blink Reformat1c4d759e2017-04-09 16:34:542320void RenderViewImpl::PageImportanceSignalsChanged() {
kouhei40f03cb2015-09-24 07:47:012321 if (!webview() || !main_render_frame_)
2322 return;
2323
Blink Reformat1c4d759e2017-04-09 16:34:542324 auto* web_signals = webview()->PageImportanceSignals();
kouhei40f03cb2015-09-24 07:47:012325
2326 PageImportanceSignals signals;
Blink Reformat1c4d759e2017-04-09 16:34:542327 signals.had_form_interaction = web_signals->HadFormInteraction();
kouhei40f03cb2015-09-24 07:47:012328
2329 main_render_frame_->Send(new FrameHostMsg_UpdatePageImportanceSignals(
2330 main_render_frame_->GetRoutingID(), signals));
2331}
2332
[email protected]20657a82012-08-21 20:23:032333#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:542334bool RenderViewImpl::OpenDateTimeChooser(
[email protected]180ef242013-11-07 06:50:462335 const blink::WebDateTimeChooserParams& params,
2336 blink::WebDateTimeChooserCompletion* completion) {
[email protected]e8072562013-12-04 06:04:132337 // JavaScript may try to open a date time chooser while one is already open.
2338 if (date_time_picker_client_)
2339 return false;
[email protected]b18583c2012-12-18 06:55:272340 date_time_picker_client_.reset(
2341 new RendererDateTimePicker(this, params, completion));
2342 return date_time_picker_client_->Open();
2343}
2344
[email protected]e8072562013-12-04 06:04:132345void RenderViewImpl::DismissDateTimeDialog() {
2346 DCHECK(date_time_picker_client_);
2347 date_time_picker_client_.reset(NULL);
2348}
[email protected]e8072562013-12-04 06:04:132349
Blink Reformat1c4d759e2017-04-09 16:34:542350bool RenderViewImpl::DidTapMultipleTargets(
timav29a8d0f62014-09-25 20:45:532351 const WebSize& inner_viewport_offset,
2352 const WebRect& touch_rect,
[email protected]f9526d12012-10-18 01:55:032353 const WebVector<WebRect>& target_rects) {
[email protected]8d3dfee62013-06-19 05:50:332354 // Never show a disambiguation popup when accessibility is enabled,
2355 // as this interferes with "touch exploration".
[email protected]95640212014-07-26 18:14:302356 AccessibilityMode accessibility_mode =
mostynbc33353232014-09-12 09:38:312357 GetMainRenderFrame()->accessibility_mode();
dougtcd3dad732017-03-14 03:26:232358 if (accessibility_mode == kAccessibilityModeComplete)
[email protected]8d3dfee62013-06-19 05:50:332359 return false;
2360
timav29a8d0f62014-09-25 20:45:532361 // The touch_rect, target_rects and zoom_rect are in the outer viewport
2362 // reference frame.
[email protected]f9526d12012-10-18 01:55:032363 gfx::Rect zoom_rect;
[email protected]70221f02013-01-31 22:17:072364 float new_total_scale =
2365 DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
timav29a8d0f62014-09-25 20:45:532366 touch_rect, target_rects, GetSize(),
Blink Reformat1c4d759e2017-04-09 16:34:542367 gfx::Rect(webview()->MainFrame()->VisibleContentRect()).size(),
2368 device_scale_factor_ * webview()->PageScaleFactor(), &zoom_rect);
jbauman0ed09182015-01-30 22:33:492369 if (!new_total_scale || zoom_rect.IsEmpty())
[email protected]f9526d12012-10-18 01:55:032370 return false;
2371
[email protected]4ded1dbf2013-08-28 21:11:032372 bool handled = false;
2373 switch (renderer_preferences_.tap_multiple_targets_strategy) {
2374 case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM:
Blink Reformat1c4d759e2017-04-09 16:34:542375 handled = webview()->ZoomToMultipleTargetsRect(zoom_rect);
[email protected]4ded1dbf2013-08-28 21:11:032376 break;
2377 case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: {
[email protected]bc2804d2013-08-06 07:45:492378 gfx::Size canvas_size =
danakjddaec912015-09-25 19:38:402379 gfx::ScaleToCeiledSize(zoom_rect.size(), new_total_scale);
[email protected]cb189e062014-04-23 00:57:012380 cc::SharedBitmapManager* manager =
2381 RenderThreadImpl::current()->shared_bitmap_manager();
dchengcedca5612016-04-09 01:40:152382 std::unique_ptr<cc::SharedBitmap> shared_bitmap =
[email protected]cb189e062014-04-23 00:57:012383 manager->AllocateSharedBitmap(canvas_size);
jbauman0ed09182015-01-30 22:33:492384 CHECK(!!shared_bitmap);
[email protected]bc2804d2013-08-06 07:45:492385 {
[email protected]cb189e062014-04-23 00:57:012386 SkBitmap bitmap;
2387 SkImageInfo info = SkImageInfo::MakeN32Premul(canvas_size.width(),
2388 canvas_size.height());
2389 bitmap.installPixels(info, shared_bitmap->pixels(), info.minRowBytes());
enne98c9f8052017-03-15 19:38:222390 cc::SkiaPaintCanvas canvas(bitmap);
[email protected]f9526d12012-10-18 01:55:032391
[email protected]bc2804d2013-08-06 07:45:492392 // TODO(trchen): Cleanup the device scale factor mess.
2393 // device scale will be applied in WebKit
2394 // --> zoom_rect doesn't include device scale,
2395 // but WebKit will still draw on zoom_rect * device_scale_factor_
[email protected]cb189e062014-04-23 00:57:012396 canvas.scale(new_total_scale / device_scale_factor_,
2397 new_total_scale / device_scale_factor_);
2398 canvas.translate(-zoom_rect.x() * device_scale_factor_,
2399 -zoom_rect.y() * device_scale_factor_);
[email protected]f9526d12012-10-18 01:55:032400
Blink Reformat1c4d759e2017-04-09 16:34:542401 DCHECK(webview_->IsAcceleratedCompositingActive());
2402 webview_->PaintIgnoringCompositing(&canvas, zoom_rect);
[email protected]bc2804d2013-08-06 07:45:492403 }
2404
timav29a8d0f62014-09-25 20:45:532405 gfx::Rect zoom_rect_in_screen =
2406 zoom_rect - gfx::Vector2d(inner_viewport_offset.width,
2407 inner_viewport_offset.height);
2408
[email protected]bc2804d2013-08-06 07:45:492409 gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect(
timav29a8d0f62014-09-25 20:45:532410 ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect_in_screen)));
2411
fsamuele8326c742016-01-12 00:49:392412 Send(new ViewHostMsg_ShowDisambiguationPopup(
avia3dca182016-03-19 01:09:522413 GetRoutingID(), physical_window_zoom_rect, canvas_size,
fsamuele8326c742016-01-12 00:49:392414 shared_bitmap->id()));
[email protected]cb189e062014-04-23 00:57:012415 cc::SharedBitmapId id = shared_bitmap->id();
2416 disambiguation_bitmaps_[id] = shared_bitmap.release();
[email protected]4ded1dbf2013-08-28 21:11:032417 handled = true;
2418 break;
2419 }
2420 case TAP_MULTIPLE_TARGETS_STRATEGY_NONE:
2421 // No-op.
2422 break;
[email protected]f9526d12012-10-18 01:55:032423 }
[email protected]70221f02013-01-31 22:17:072424
[email protected]4ded1dbf2013-08-28 21:11:032425 return handled;
[email protected]f9526d12012-10-18 01:55:032426}
braveyao1d8ee7b2017-03-29 21:10:042427
2428void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) {
tsunghunga86cde72017-04-10 22:27:132429#if BUILDFLAG(ENABLE_WEBRTC)
braveyao1d8ee7b2017-03-29 21:10:042430 if (!main_render_frame_)
2431 return;
2432
2433 MediaStreamDispatcher* media_stream_dispatcher =
2434 main_render_frame_->GetMediaStreamDispatcher();
2435 if (!media_stream_dispatcher)
2436 return;
2437
2438 StreamDeviceInfoArray video_array =
2439 media_stream_dispatcher->GetNonScreenCaptureDevices();
2440 RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices(
2441 video_array, suspend);
tsunghunga86cde72017-04-10 22:27:132442#endif // BUILDFLAG(ENABLE_WEBRTC)
braveyao1d8ee7b2017-03-29 21:10:042443}
estade6b9696bd2016-05-04 23:51:362444#endif // defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:032445
[email protected]b283d292013-02-21 08:40:342446unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
2447 return history_list_length_;
2448}
2449
[email protected]cc290f902013-03-04 20:06:022450void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
2451 if (enable) {
2452 if (has_focus())
2453 return;
2454 OnSetActive(true);
2455 OnSetFocus(true);
2456 } else {
2457 if (!has_focus())
2458 return;
2459 OnSetFocus(false);
2460 OnSetActive(false);
2461 }
2462}
2463
[email protected]3a1c8a8032013-03-18 22:35:322464void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) {
fsamuel664e8b62016-01-20 19:54:012465 ResizeParams params;
[email protected]b54fe452013-06-07 14:01:532466 params.screen_info = screen_info_;
ccameron2f451532016-09-07 21:49:272467 params.screen_info.device_scale_factor = factor;
[email protected]b54fe452013-06-07 14:01:532468 params.new_size = size();
bokanf0fd2412014-10-30 15:28:552469 params.visible_viewport_size = visible_viewport_size_;
danakjddaec912015-09-25 19:38:402470 params.physical_backing_size = gfx::ScaleToCeiledSize(size(), factor);
mdjones2ee41afd2016-10-27 16:50:202471 params.browser_controls_shrink_blink_size = false;
dtrainorcb7779b82014-12-04 01:08:022472 params.top_controls_height = 0.f;
mikhail.pozdnyakovf2c902a2015-04-14 08:09:122473 params.is_fullscreen_granted = is_fullscreen_granted();
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122474 params.display_mode = display_mode_;
[email protected]b54fe452013-06-07 14:01:532475 OnResize(params);
[email protected]3a1c8a8032013-03-18 22:35:322476}
2477
mlamouriafca06dd2017-01-27 23:35:182478void RenderViewImpl::SetDeviceColorProfileForTesting(
2479 const gfx::ICCProfile& icc_profile) {
ccameron772317d2017-06-04 18:35:032480 // TODO(ccameron): Remove this call when color correct rendering is the
2481 // default.
2482 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2483 switches::kEnableColorCorrectRendering)) {
2484 return;
2485 }
2486
mlamouriafca06dd2017-01-27 23:35:182487 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542488 webview()->SetDeviceColorProfile(icc_profile);
mlamouriafca06dd2017-01-27 23:35:182489
2490 ResizeParams params;
2491 params.screen_info = screen_info_;
2492 params.screen_info.icc_profile = icc_profile;
2493 params.new_size = size();
2494 params.visible_viewport_size = visible_viewport_size_;
2495 params.physical_backing_size = physical_backing_size_;
2496 params.browser_controls_shrink_blink_size = false;
2497 params.top_controls_height = 0.f;
2498 params.is_fullscreen_granted = is_fullscreen_granted();
2499 params.display_mode = display_mode_;
2500 OnResize(params);
2501}
2502
[email protected]92650162013-10-30 03:31:022503void RenderViewImpl::ForceResizeForTesting(const gfx::Size& new_size) {
Blink Reformat1c4d759e2017-04-09 16:34:542504 gfx::Rect new_window_rect(RootWindowRect().x, RootWindowRect().y,
2505 new_size.width(), new_size.height());
bokanc007c3a2015-02-03 07:15:562506 SetWindowRectSynchronously(new_window_rect);
[email protected]92650162013-10-30 03:31:022507}
2508
[email protected]5b45ad42013-10-25 00:42:042509void RenderViewImpl::UseSynchronousResizeModeForTesting(bool enable) {
2510 resizing_mode_selector_->set_is_synchronous_mode(enable);
2511}
2512
[email protected]eac2b362013-05-22 07:01:452513void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size,
2514 const gfx::Size& max_size) {
2515 OnEnableAutoResize(min_size, max_size);
2516}
2517
2518void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) {
2519 OnDisableAutoResize(new_size);
2520}
2521
[email protected]cb189e062014-04-23 00:57:012522void RenderViewImpl::OnReleaseDisambiguationPopupBitmap(
2523 const cc::SharedBitmapId& id) {
2524 BitmapMap::iterator it = disambiguation_bitmaps_.find(id);
2525 DCHECK(it != disambiguation_bitmaps_.end());
2526 delete it->second;
2527 disambiguation_bitmaps_.erase(it);
[email protected]f9526d12012-10-18 01:55:032528}
[email protected]e9ff79c2012-10-19 21:31:262529
aelias1b55156e52017-04-01 00:46:052530void RenderViewImpl::OnResolveTapDisambiguation(double timestamp_seconds,
2531 gfx::Point tap_viewport_offset,
2532 bool is_long_press) {
Blink Reformat1c4d759e2017-04-09 16:34:542533 webview()->ResolveTapDisambiguation(timestamp_seconds, tap_viewport_offset,
aelias1b55156e52017-04-01 00:46:052534 is_long_press);
2535}
2536
[email protected]6fceb912013-02-15 06:24:152537void RenderViewImpl::DidCommitCompositorFrame() {
2538 RenderWidget::DidCommitCompositorFrame();
ericwilligers88e69742016-10-17 19:29:552539 for (auto& observer : observers_)
2540 observer.DidCommitCompositorFrame();
[email protected]6fceb912013-02-15 06:24:152541}
2542
oshimad5279032015-12-16 18:22:332543void RenderViewImpl::UpdateWebViewWithDeviceScaleFactor() {
2544 if (!webview())
2545 return;
oshima750cb4342015-10-31 00:59:012546 if (IsUseZoomForDSFEnabled()) {
Blink Reformat1c4d759e2017-04-09 16:34:542547 webview()->SetZoomFactorForDeviceScaleFactor(device_scale_factor_);
oshima750cb4342015-10-31 00:59:012548 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542549 webview()->SetDeviceScaleFactor(device_scale_factor_);
oshima750cb4342015-10-31 00:59:012550 }
Blink Reformat1c4d759e2017-04-09 16:34:542551 webview()->GetSettings()->SetPreferCompositingToLCDTextEnabled(
oshimad5279032015-12-16 18:22:332552 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_));
oshima750cb4342015-10-31 00:59:012553}
2554
dtapuska1b0fcc322016-10-28 18:08:282555void RenderViewImpl::OnDiscardInputEvent(
2556 const blink::WebInputEvent* input_event,
nzolghadr5d8596502017-01-23 22:59:352557 const std::vector<const blink::WebInputEvent*>& coalesced_events,
dtapuska1b0fcc322016-10-28 18:08:282558 const ui::LatencyInfo& latency_info,
2559 InputEventDispatchType dispatch_type) {
dtapuska9ec1a912017-04-21 15:18:312560 if (!input_event || dispatch_type == DISPATCH_TYPE_NON_BLOCKING) {
dtapuska1b0fcc322016-10-28 18:08:282561 return;
2562 }
2563
Blink Reformat1c4d759e2017-04-09 16:34:542564 std::unique_ptr<InputEventAck> ack(new InputEventAck(
2565 InputEventAckSource::MAIN_THREAD, input_event->GetType(),
2566 INPUT_EVENT_ACK_STATE_NOT_CONSUMED));
dtapuska1b0fcc322016-10-28 18:08:282567 OnInputEventAck(std::move(ack));
2568}
2569
dtapuska9ec1a912017-04-21 15:18:312570InputEventAckState RenderViewImpl::HandleInputEvent(
2571 const blink::WebCoalescedInputEvent& input_event,
2572 const ui::LatencyInfo& latency_info,
2573 InputEventDispatchType dispatch_type) {
2574 if (is_swapped_out_) {
2575 OnDiscardInputEvent(&input_event.Event(),
2576 input_event.GetCoalescedEventsPointers(), latency_info,
2577 dispatch_type);
2578 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
2579 }
2580 idle_user_detector_->ActivityDetected();
2581 return RenderWidget::HandleInputEvent(input_event, latency_info,
2582 dispatch_type);
2583}
2584
[email protected]e9ff79c2012-10-19 21:31:262585} // namespace content