blob: afd133a40c4f41e3cd54aa510658a05d2113af68 [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"
[email protected]41225fe2013-03-29 05:32:0263#include "content/public/common/favicon_url.h"
kouhei40f03cb2015-09-24 07:47:0164#include "content/public/common/page_importance_signals.h"
clamyda97e8322014-10-07 21:57:2565#include "content/public/common/page_state.h"
[email protected]7940b8e2013-07-25 23:08:4966#include "content/public/common/page_zoom.h"
[email protected]818915cd2012-11-20 13:14:1167#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0368#include "content/public/common/url_constants.h"
[email protected]b3a97b52014-07-09 06:25:0569#include "content/public/common/web_preferences.h"
[email protected]d344114c2011-10-01 01:24:3470#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0771#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3272#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4473#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3674#include "content/public/renderer/render_view_visitor.h"
scottmg8e6c6082017-02-13 23:15:4875#include "content/public/renderer/window_features_converter.h"
[email protected]e6e56752012-08-10 00:46:0676#include "content/renderer/browser_plugin/browser_plugin.h"
77#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]1910fe82012-05-10 00:04:1078#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]dc293a72013-07-01 11:11:2279#include "content/renderer/drop_data_builder.h"
[email protected]ba91a792013-02-06 09:48:2880#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]dc064352014-04-25 08:36:3881#include "content/renderer/history_serialization.h"
[email protected]1784b2f2011-11-24 10:53:4882#include "content/renderer/idle_user_detector.h"
[email protected]66fca5bc2013-05-23 06:58:2983#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1384#include "content/renderer/input/input_handler_manager.h"
[email protected]92d457802013-04-01 19:18:4985#include "content/renderer/internal_document_state_data.h"
[email protected]4a914882013-01-10 00:43:4886#include "content/renderer/media/audio_device_factory.h"
braveyao1d8ee7b2017-03-29 21:10:0487#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]6392d982013-04-16 16:59:2288#include "content/renderer/media/video_capture_impl_manager.h"
clamy5f342202015-03-18 13:47:5689#include "content/renderer/navigation_state_impl.h"
[email protected]227692c52013-05-31 22:43:0490#include "content/renderer/render_frame_impl.h"
[email protected]5a7100d2014-05-19 01:29:0491#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0592#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4493#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4494#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]663bd9e2011-03-21 01:07:0195#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]5b45ad42013-10-25 00:42:0496#include "content/renderer/resizing_mode_selector.h"
[email protected]12a936d2013-05-15 04:55:4997#include "content/renderer/savable_resources.h"
nhiroki2820b8b2017-01-10 08:13:3098#include "content/renderer/shared_worker/websharedworker_proxy.h"
[email protected]64d09222012-05-25 10:10:3499#include "content/renderer/speech_recognition_dispatcher.h"
[email protected]940ed1d2012-11-27 21:03:21100#include "content/renderer/web_ui_extension_data.h"
[email protected]f5961142013-04-17 23:09:42101#include "media/audio/audio_output_device.h"
[email protected]ee68378a2010-08-10 01:05:41102#include "media/base/media_switches.h"
Brett Wilson0748bf412016-11-22 17:55:46103#include "media/media_features.h"
servolkf54f5c8f2015-02-24 20:32:39104#include "media/renderers/audio_renderer_impl.h"
servolk8b3b39b2015-03-03 19:08:18105#include "media/renderers/gpu_video_accelerator_factories.h"
[email protected]d1ef81d2012-07-24 11:39:36106#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29107#include "net/base/escape.h"
108#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09109#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04110#include "net/http/http_util.h"
brettw4b461082016-11-19 18:55:16111#include "ppapi/features/features.h"
xlai11ac7802017-04-07 20:13:18112#include "services/ui/public/cpp/bitmap/child_shared_bitmap_manager.h"
lukenb171b532014-09-24 05:50:38113#include "skia/ext/platform_canvas.h"
kinukob473f002016-02-22 05:23:19114#include "third_party/WebKit/public/platform/FilePathConversion.h"
brettwdfbcc3b2016-01-20 01:49:17115#include "third_party/WebKit/public/platform/URLConversion.h"
[email protected]b3a97b52014-07-09 06:25:05116#include "third_party/WebKit/public/platform/WebConnectionType.h"
[email protected]d0fcff72013-07-23 02:45:43117#include "third_party/WebKit/public/platform/WebHTTPBody.h"
118#include "third_party/WebKit/public/platform/WebImage.h"
dtapuska836e1f92016-11-15 00:38:06119#include "third_party/WebKit/public/platform/WebInputEvent.h"
skyostilcff62882017-01-28 13:18:04120#include "third_party/WebKit/public/platform/WebInputEventResult.h"
[email protected]d0fcff72013-07-23 02:45:43121#include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
122#include "third_party/WebKit/public/platform/WebPoint.h"
123#include "third_party/WebKit/public/platform/WebRect.h"
nverne61d2da872017-05-24 10:15:30124#include "third_party/WebKit/public/platform/WebRuntimeFeatures.h"
[email protected]d0fcff72013-07-23 02:45:43125#include "third_party/WebKit/public/platform/WebSize.h"
[email protected]ec173b522013-11-14 11:01:18126#include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h"
[email protected]d0fcff72013-07-23 02:45:43127#include "third_party/WebKit/public/platform/WebString.h"
128#include "third_party/WebKit/public/platform/WebURL.h"
129#include "third_party/WebKit/public/platform/WebURLError.h"
130#include "third_party/WebKit/public/platform/WebURLRequest.h"
131#include "third_party/WebKit/public/platform/WebURLResponse.h"
132#include "third_party/WebKit/public/platform/WebVector.h"
brettw8a274fa2016-11-15 00:20:40133#include "third_party/WebKit/public/public_features.h"
[email protected]10760e4a2013-09-04 23:32:20134#include "third_party/WebKit/public/web/WebAXObject.h"
ekaramad27ca69b12017-04-20 18:34:29135#include "third_party/WebKit/public/web/WebAutofillClient.h"
[email protected]8bc5ff02013-11-29 06:34:03136#include "third_party/WebKit/public/web/WebColorSuggestion.h"
[email protected]2255a9332013-06-17 05:12:31137#include "third_party/WebKit/public/web/WebDOMEvent.h"
138#include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
139#include "third_party/WebKit/public/web/WebDataSource.h"
140#include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h"
141#include "third_party/WebKit/public/web/WebDateTimeChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31142#include "third_party/WebKit/public/web/WebDocument.h"
143#include "third_party/WebKit/public/web/WebElement.h"
144#include "third_party/WebKit/public/web/WebFileChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31145#include "third_party/WebKit/public/web/WebFormControlElement.h"
146#include "third_party/WebKit/public/web/WebFormElement.h"
147#include "third_party/WebKit/public/web/WebFrame.h"
dglazkov03223492016-02-08 22:16:03148#include "third_party/WebKit/public/web/WebFrameContentDumper.h"
lfgcaab5142016-02-26 19:06:52149#include "third_party/WebKit/public/web/WebFrameWidget.h"
[email protected]2255a9332013-06-17 05:12:31150#include "third_party/WebKit/public/web/WebHistoryItem.h"
[email protected]91dcc6d32014-07-30 00:01:33151#include "third_party/WebKit/public/web/WebHitTestResult.h"
[email protected]2255a9332013-06-17 05:12:31152#include "third_party/WebKit/public/web/WebInputElement.h"
[email protected]35b2a972014-04-04 15:50:22153#include "third_party/WebKit/public/web/WebLocalFrame.h"
[email protected]2255a9332013-06-17 05:12:31154#include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
155#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
kouhei40f03cb2015-09-24 07:47:01156#include "third_party/WebKit/public/web/WebPageImportanceSignals.h"
[email protected]2255a9332013-06-17 05:12:31157#include "third_party/WebKit/public/web/WebPlugin.h"
158#include "third_party/WebKit/public/web/WebPluginAction.h"
[email protected]2255a9332013-06-17 05:12:31159#include "third_party/WebKit/public/web/WebRange.h"
ellyjones8ae17692016-08-05 15:19:21160#include "third_party/WebKit/public/web/WebRenderTheme.h"
[email protected]2255a9332013-06-17 05:12:31161#include "third_party/WebKit/public/web/WebScriptSource.h"
162#include "third_party/WebKit/public/web/WebSearchableFormData.h"
[email protected]2255a9332013-06-17 05:12:31163#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
[email protected]2255a9332013-06-17 05:12:31164#include "third_party/WebKit/public/web/WebSettings.h"
[email protected]2255a9332013-06-17 05:12:31165#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
[email protected]2255a9332013-06-17 05:12:31166#include "third_party/WebKit/public/web/WebView.h"
167#include "third_party/WebKit/public/web/WebWindowFeatures.h"
[email protected]b3a97b52014-07-09 06:25:05168#include "third_party/icu/source/common/unicode/uchar.h"
169#include "third_party/icu/source/common/unicode/uscript.h"
esecklerf2bd55f72017-03-31 09:11:57170#include "third_party/skia/include/core/SkColor.h"
[email protected]1400e6dc2013-04-27 02:36:27171#include "ui/base/ui_base_switches_util.h"
tfarina655f81d2014-12-23 02:38:50172#include "ui/gfx/geometry/point.h"
tfarina3b0452d2014-12-31 15:20:09173#include "ui/gfx/geometry/rect.h"
174#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32175#include "ui/gfx/geometry/size_conversions.h"
[email protected]08397d52011-02-05 01:53:38176#include "ui/gfx/native_widget_types.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::WebIconURL;
223using blink::WebImage;
224using blink::WebInputElement;
225using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22226using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46227using blink::WebMediaPlayerAction;
[email protected]180ef242013-11-07 06:50:46228using blink::WebMouseEvent;
229using blink::WebNavigationPolicy;
230using blink::WebNavigationType;
231using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46232using blink::WebPluginAction;
[email protected]180ef242013-11-07 06:50:46233using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46234using blink::WebRect;
235using blink::WebReferrerPolicy;
[email protected]180ef242013-11-07 06:50:46236using blink::WebScriptSource;
237using blink::WebSearchableFormData;
238using blink::WebSecurityOrigin;
239using blink::WebSecurityPolicy;
[email protected]180ef242013-11-07 06:50:46240using blink::WebSettings;
241using blink::WebSize;
[email protected]180ef242013-11-07 06:50:46242using blink::WebStorageNamespace;
243using blink::WebStorageQuotaCallbacks;
244using blink::WebStorageQuotaError;
245using blink::WebStorageQuotaType;
246using blink::WebString;
[email protected]180ef242013-11-07 06:50:46247using blink::WebTextDirection;
248using blink::WebTouchEvent;
249using blink::WebURL;
250using blink::WebURLError;
251using blink::WebURLRequest;
252using blink::WebURLResponse;
253using blink::WebUserGestureIndicator;
254using blink::WebVector;
255using blink::WebView;
256using blink::WebWidget;
257using blink::WebWindowFeatures;
[email protected]b3a97b52014-07-09 06:25:05258using blink::WebRuntimeFeatures;
[email protected]6fdd4182010-10-14 23:59:26259using base::Time;
260using base::TimeDelta;
[email protected]e1acf6f2008-10-27 20:43:33261
[email protected]20657a82012-08-21 20:23:03262
[email protected]e9ff79c2012-10-19 21:31:26263namespace content {
264
initial.commit09911bf2008-07-26 23:55:29265//-----------------------------------------------------------------------------
266
[email protected]180ef242013-11-07 06:50:46267typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
jbroman8319b232017-03-08 22:53:29268static base::LazyInstance<ViewMap>::Leaky g_view_map =
[email protected]058561b2012-12-03 06:48:22269 LAZY_INSTANCE_INITIALIZER;
scottmg5e65e3a2017-03-08 08:48:46270typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap;
jbroman8319b232017-03-08 22:53:29271static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map =
272 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02273
[email protected]882daa92009-11-05 16:31:31274// Time, in seconds, we delay before sending content state changes (such as form
275// state and scroll position) to the browser. We delay sending changes to avoid
276// spamming the browser.
277// To avoid having tab/session restore require sending a message to get the
278// current content state during tab closing we use a shorter timeout for the
279// foreground renderer. This means there is a small window of time from which
280// content state is modified and not sent to session restore, but this is
281// better than having to wake up all renderers during shutdown.
avif937e1d2014-11-02 18:13:07282const int kDelaySecondsForContentStateSyncHidden = 5;
283const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29284
dcheng35d31c112015-07-22 00:17:36285static RenderViewImpl* (*g_create_render_view_impl)(
286 CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15287 const mojom::CreateViewParams&) = nullptr;
[email protected]8d41d7612012-11-14 20:32:19288
[email protected]c6bc20332014-02-28 18:30:39289// static
[email protected]e507045d2013-07-24 15:23:44290Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56291 WebFrame* frame,
292 const WebURLRequest& request) {
Blink Reformat1c4d759e2017-04-09 16:34:54293 return Referrer(blink::WebStringToGURL(
294 request.HttpHeaderField(WebString::FromUTF8("Referer"))),
295 request.GetReferrerPolicy());
[email protected]44e55b012013-07-23 14:21:56296}
297
[email protected]c6bc20332014-02-28 18:30:39298// static
[email protected]65920f332014-03-04 21:14:18299WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32300 WebNavigationPolicy policy) {
301 switch (policy) {
Blink Reformat1c4d759e2017-04-09 16:34:54302 case blink::kWebNavigationPolicyIgnore:
nick3b04f322016-08-31 19:29:19303 return WindowOpenDisposition::IGNORE_ACTION;
Blink Reformat1c4d759e2017-04-09 16:34:54304 case blink::kWebNavigationPolicyDownload:
nick3b04f322016-08-31 19:29:19305 return WindowOpenDisposition::SAVE_TO_DISK;
Blink Reformat1c4d759e2017-04-09 16:34:54306 case blink::kWebNavigationPolicyCurrentTab:
nick3b04f322016-08-31 19:29:19307 return WindowOpenDisposition::CURRENT_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54308 case blink::kWebNavigationPolicyNewBackgroundTab:
nick3b04f322016-08-31 19:29:19309 return WindowOpenDisposition::NEW_BACKGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54310 case blink::kWebNavigationPolicyNewForegroundTab:
nick3b04f322016-08-31 19:29:19311 return WindowOpenDisposition::NEW_FOREGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54312 case blink::kWebNavigationPolicyNewWindow:
nick3b04f322016-08-31 19:29:19313 return WindowOpenDisposition::NEW_WINDOW;
Blink Reformat1c4d759e2017-04-09 16:34:54314 case blink::kWebNavigationPolicyNewPopup:
nick3b04f322016-08-31 19:29:19315 return WindowOpenDisposition::NEW_POPUP;
[email protected]48861e22013-01-09 00:27:32316 default:
317 NOTREACHED() << "Unexpected WebNavigationPolicy";
nick3b04f322016-08-31 19:29:19318 return WindowOpenDisposition::IGNORE_ACTION;
[email protected]48861e22013-01-09 00:27:32319 }
320}
321
[email protected]d8221b22013-05-23 05:35:43322// Returns true if the device scale is high enough that losing subpixel
323// antialiasing won't have a noticeable effect on text quality.
324static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
bokane6e68ae2017-03-24 00:54:44325#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
326 // On Android, we never have subpixel antialiasing. On Chrome OS we prefer to
327 // composite all scrollers so that we get animated overlay scrollbars.
[email protected]d8221b22013-05-23 05:35:43328 return true;
329#else
jdduke7d452b4a2015-08-19 21:25:21330 // 1.5 is a common touchscreen tablet device scale factor. For such
331 // devices main thread antialiasing is a heavy burden.
332 return device_scale_factor >= 1.5f;
[email protected]d8221b22013-05-23 05:35:43333#endif
[email protected]d8221b22013-05-23 05:35:43334}
335
danakj6e3bf8012014-12-16 18:27:53336static bool PreferCompositingToLCDText(CompositorDependencies* compositor_deps,
337 float device_scale_factor) {
avi83883c82014-12-23 00:08:49338 const base::CommandLine& command_line =
339 *base::CommandLine::ForCurrentProcess();
[email protected]b8ec1112014-08-17 20:09:10340 if (command_line.HasSwitch(switches::kDisablePreferCompositingToLCDText))
[email protected]fb854192013-02-06 01:30:04341 return false;
[email protected]b8ec1112014-08-17 20:09:10342 if (command_line.HasSwitch(switches::kEnablePreferCompositingToLCDText))
[email protected]fb854192013-02-06 01:30:04343 return true;
danakj6e3bf8012014-12-16 18:27:53344 if (!compositor_deps->IsLcdTextEnabled())
[email protected]10c19732014-08-18 19:39:23345 return true;
[email protected]d8221b22013-05-23 05:35:43346 return DeviceScaleEnsuresTextQuality(device_scale_factor);
347}
348
[email protected]180ef242013-11-07 06:50:46349static FaviconURL::IconType ToFaviconType(blink::WebIconURL::Type type) {
[email protected]41225fe2013-03-29 05:32:02350 switch (type) {
Blink Reformat1c4d759e2017-04-09 16:34:54351 case blink::WebIconURL::kTypeFavicon:
[email protected]41225fe2013-03-29 05:32:02352 return FaviconURL::FAVICON;
Blink Reformat1c4d759e2017-04-09 16:34:54353 case blink::WebIconURL::kTypeTouch:
[email protected]41225fe2013-03-29 05:32:02354 return FaviconURL::TOUCH_ICON;
Blink Reformat1c4d759e2017-04-09 16:34:54355 case blink::WebIconURL::kTypeTouchPrecomposed:
[email protected]41225fe2013-03-29 05:32:02356 return FaviconURL::TOUCH_PRECOMPOSED_ICON;
Blink Reformat1c4d759e2017-04-09 16:34:54357 case blink::WebIconURL::kTypeInvalid:
[email protected]41225fe2013-03-29 05:32:02358 return FaviconURL::INVALID_ICON;
359 }
360 return FaviconURL::INVALID_ICON;
361}
362
[email protected]f34ac132014-03-20 23:02:05363static void ConvertToFaviconSizes(
364 const blink::WebVector<blink::WebSize>& web_sizes,
365 std::vector<gfx::Size>* sizes) {
[email protected]2bd262b2014-04-16 05:31:23366 DCHECK(sizes->empty());
367 sizes->reserve(web_sizes.size());
[email protected]f34ac132014-03-20 23:02:05368 for (size_t i = 0; i < web_sizes.size(); ++i)
369 sizes->push_back(gfx::Size(web_sizes[i]));
370}
371
initial.commit09911bf2008-07-26 23:55:29372///////////////////////////////////////////////////////////////////////////////
373
[email protected]217690d2012-01-27 07:33:11374namespace {
375
[email protected]b3a97b52014-07-09 06:25:05376typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
377 const base::string16&,
378 UScriptCode);
379
380void SetStandardFontFamilyWrapper(WebSettings* settings,
381 const base::string16& font,
382 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54383 settings->SetStandardFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05384}
385
386void SetFixedFontFamilyWrapper(WebSettings* settings,
387 const base::string16& font,
388 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54389 settings->SetFixedFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05390}
391
392void SetSerifFontFamilyWrapper(WebSettings* settings,
393 const base::string16& font,
394 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54395 settings->SetSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05396}
397
398void SetSansSerifFontFamilyWrapper(WebSettings* settings,
399 const base::string16& font,
400 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54401 settings->SetSansSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05402}
403
404void SetCursiveFontFamilyWrapper(WebSettings* settings,
405 const base::string16& font,
406 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54407 settings->SetCursiveFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05408}
409
410void SetFantasyFontFamilyWrapper(WebSettings* settings,
411 const base::string16& font,
412 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54413 settings->SetFantasyFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05414}
415
416void SetPictographFontFamilyWrapper(WebSettings* settings,
417 const base::string16& font,
418 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54419 settings->SetPictographFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05420}
421
422// If |scriptCode| is a member of a family of "similar" script codes, returns
423// the script code in that family that is used by WebKit for font selection
424// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
425// considered equivalent for the purposes of font selection. WebKit uses the
426// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
427// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
428// uses different scripts than the ones in Chrome pref names because the version
429// of ICU included on certain ports does not have some of the newer scripts. If
430// |scriptCode| is not a member of such a family, returns |scriptCode|.
431UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
432 switch (scriptCode) {
433 case USCRIPT_HIRAGANA:
434 case USCRIPT_KATAKANA:
435 case USCRIPT_JAPANESE:
436 return USCRIPT_KATAKANA_OR_HIRAGANA;
437 case USCRIPT_KOREAN:
438 return USCRIPT_HANGUL;
439 default:
440 return scriptCode;
441 }
442}
443
444void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
445 SetFontFamilyWrapper setter,
446 WebSettings* settings) {
447 for (ScriptFontFamilyMap::const_iterator it = map.begin(); it != map.end();
448 ++it) {
avi1023d012015-12-25 02:39:14449 int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
[email protected]b3a97b52014-07-09 06:25:05450 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
451 UScriptCode code = static_cast<UScriptCode>(script);
452 (*setter)(settings, it->second, GetScriptForWebSettings(code));
453 }
454 }
455}
456
wangxianzhu3bf39be52015-04-10 23:56:41457void ApplyBlinkSettings(const base::CommandLine& command_line,
458 WebSettings* settings) {
459 if (!command_line.HasSwitch(switches::kBlinkSettings))
460 return;
461
brettw26dab8f02015-08-08 00:28:47462 std::vector<std::string> blink_settings = base::SplitString(
463 command_line.GetSwitchValueASCII(switches::kBlinkSettings),
464 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
wangxianzhu3bf39be52015-04-10 23:56:41465 for (const std::string& setting : blink_settings) {
466 size_t pos = setting.find('=');
Blink Reformat1c4d759e2017-04-09 16:34:54467 settings->SetFromStrings(
468 blink::WebString::FromLatin1(setting.substr(0, pos)),
469 blink::WebString::FromLatin1(
wangxianzhu3bf39be52015-04-10 23:56:41470 pos == std::string::npos ? "" : setting.substr(pos + 1)));
471 }
472}
473
horodbcbef42016-05-10 17:02:47474WebSettings::V8CacheStrategiesForCacheStorage
475GetV8CacheStrategiesForCacheStorage() {
476 const base::CommandLine& command_line =
477 *base::CommandLine::ForCurrentProcess();
478 std::string v8_cache_strategies = command_line.GetSwitchValueASCII(
479 switches::kV8CacheStrategiesForCacheStorage);
horoe0ff13d2016-05-27 14:47:22480 if (v8_cache_strategies.empty()) {
horodbcbef42016-05-10 17:02:47481 v8_cache_strategies =
482 base::FieldTrialList::FindFullName("V8CacheStrategiesForCacheStorage");
horoe0ff13d2016-05-27 14:47:22483 }
484
485 if (base::StartsWith(v8_cache_strategies, "none",
486 base::CompareCase::SENSITIVE)) {
Blink Reformat1c4d759e2017-04-09 16:34:54487 return WebSettings::V8CacheStrategiesForCacheStorage::kNone;
horoe0ff13d2016-05-27 14:47:22488 } else if (base::StartsWith(v8_cache_strategies, "normal",
489 base::CompareCase::SENSITIVE)) {
Blink Reformat1c4d759e2017-04-09 16:34:54490 return WebSettings::V8CacheStrategiesForCacheStorage::kNormal;
horoe0ff13d2016-05-27 14:47:22491 } else if (base::StartsWith(v8_cache_strategies, "aggressive",
492 base::CompareCase::SENSITIVE)) {
Blink Reformat1c4d759e2017-04-09 16:34:54493 return WebSettings::V8CacheStrategiesForCacheStorage::kAggressive;
horodbcbef42016-05-10 17:02:47494 } else {
Blink Reformat1c4d759e2017-04-09 16:34:54495 return WebSettings::V8CacheStrategiesForCacheStorage::kDefault;
horodbcbef42016-05-10 17:02:47496 }
497}
498
svartmetal751af1f92016-08-13 11:47:33499// This class represents promise which is robust to (will not be broken by)
500// |DidNotSwapReason::SWAP_FAILS| events.
501class AlwaysDrawSwapPromise : public cc::SwapPromise {
502 public:
503 explicit AlwaysDrawSwapPromise(const ui::LatencyInfo& latency_info)
504 : latency_info_(latency_info) {}
505
506 ~AlwaysDrawSwapPromise() override = default;
507
508 void DidActivate() override {}
509
samanse7345c82016-12-16 02:51:16510 void WillSwap(cc::CompositorFrameMetadata* metadata) override {
svartmetal751af1f92016-08-13 11:47:33511 DCHECK(!latency_info_.terminated());
512 metadata->latency_info.push_back(latency_info_);
513 }
514
samanse7345c82016-12-16 02:51:16515 void DidSwap() override {}
516
svartmetal751af1f92016-08-13 11:47:33517 DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override {
518 return reason == DidNotSwapReason::SWAP_FAILS
519 ? DidNotSwapAction::KEEP_ACTIVE
520 : DidNotSwapAction::BREAK_PROMISE;
521 }
522
523 void OnCommit() override {}
524
525 int64_t TraceId() const override { return latency_info_.trace_id(); }
526
527 private:
528 ui::LatencyInfo latency_info_;
529};
530
scottmgde42fb92017-02-10 17:56:03531content::mojom::WindowContainerType WindowFeaturesToContainerType(
scottmg05324cb2017-02-09 23:46:04532 const blink::WebWindowFeatures& window_features) {
japhetbfc47892017-06-02 23:01:19533 if (window_features.background) {
534 if (window_features.persistent)
scottmgde42fb92017-02-10 17:56:03535 return content::mojom::WindowContainerType::PERSISTENT;
scottmg05324cb2017-02-09 23:46:04536 else
scottmgde42fb92017-02-10 17:56:03537 return content::mojom::WindowContainerType::BACKGROUND;
scottmg05324cb2017-02-09 23:46:04538 } else {
scottmgde42fb92017-02-10 17:56:03539 return content::mojom::WindowContainerType::NORMAL;
scottmg05324cb2017-02-09 23:46:04540 }
541}
542
[email protected]217690d2012-01-27 07:33:11543} // namespace
544
dcheng35d31c112015-07-22 00:17:36545RenderViewImpl::RenderViewImpl(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15546 const mojom::CreateViewParams& params)
nick8331f8ad2016-11-15 20:42:45547 : RenderWidget(params.view_id,
548 compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54549 blink::kWebPopupTypeNone,
naskobd911332014-11-25 01:13:36550 params.initial_size.screen_info,
551 params.swapped_out,
552 params.hidden,
553 params.never_visible),
554 webkit_preferences_(params.web_preferences),
avif937e1d2014-11-02 18:13:07555 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09556 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02557 send_preferred_size_changes_(false),
[email protected]e75cb49e2009-01-05 23:13:21558 navigation_gesture_(NavigationGestureUnknown),
[email protected]3cc72b12010-03-18 23:03:00559 history_list_offset_(-1),
560 history_list_length_(0),
[email protected]7e9523b2014-03-25 03:02:42561 frames_in_progress_(0),
[email protected]3354d3e2010-06-10 19:53:02562 target_url_status_(TARGET_NONE),
[email protected]d42bf472014-06-14 01:49:38563 uses_temporary_zoom_level_(false),
[email protected]bbc8856d2013-06-14 10:37:04564#if defined(OS_ANDROID)
mdjones2ee41afd2016-10-27 16:50:20565 top_controls_constraints_(BROWSER_CONTROLS_STATE_BOTH),
[email protected]bbc8856d2013-06-14 10:37:04566#endif
mdjones2ee41afd2016-10-27 16:50:20567 browser_controls_shrink_blink_size_(false),
bokanc63441c2016-04-27 15:49:12568 top_controls_height_(0.f),
lfg4fa48da2016-05-09 18:25:13569 webview_(nullptr),
[email protected]1875bc02014-03-14 06:33:59570 has_scrolled_focused_editable_node_into_rect_(false),
wjmaclean64951902016-04-29 20:59:12571 page_zoom_level_(params.page_zoom_level),
nasko4c0feb62015-06-05 18:37:06572 main_render_frame_(nullptr),
dcheng3ce04b62015-10-26 23:30:55573 frame_widget_(nullptr),
[email protected]64d09222012-05-25 10:10:34574 speech_recognition_dispatcher_(NULL),
[email protected]20657a82012-08-21 20:23:03575#if defined(OS_ANDROID)
nickf7b38222016-11-22 21:59:35576 was_created_by_renderer_(false),
[email protected]a7564272013-04-19 14:24:46577#endif
[email protected]8a67aa352013-02-20 02:58:29578 enumeration_completion_id_(0),
changwand659e202016-06-13 02:39:12579 session_storage_namespace_id_(params.session_storage_namespace_id),
wjmaclean1d970622017-01-21 22:28:24580 weak_ptr_factory_(this) {
avi40b5be7a2016-03-03 21:13:44581 GetWidget()->set_owner_delegate(this);
[email protected]075366912013-02-18 07:13:24582}
583
nickf7b38222016-11-22 21:59:35584void RenderViewImpl::Initialize(
585 const mojom::CreateViewParams& params,
586 const RenderWidget::ShowCallback& show_callback) {
587 bool was_created_by_renderer = !show_callback.is_null();
588#if defined(OS_ANDROID)
589 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated
590 // HandleNavigation codepath.
591 was_created_by_renderer_ = was_created_by_renderer;
592#endif
thestig6057a6b22015-11-12 23:01:33593 display_mode_ = params.initial_size.display_mode;
[email protected]676126f72011-01-15 00:03:51594
Blink Reformat1c4d759e2017-04-09 16:34:54595 webview_ = WebView::Create(this, is_hidden()
596 ? blink::kWebPageVisibilityStateHidden
597 : blink::kWebPageVisibilityStateVisible);
598 RenderWidget::Init(show_callback, webview_->GetWidget());
[email protected]11fee2332011-03-29 20:36:35599
nasko4c0feb62015-06-05 18:37:06600 g_view_map.Get().insert(std::make_pair(webview(), this));
avia3dca182016-03-19 01:09:52601 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this));
nasko4c0feb62015-06-05 18:37:06602
avi83883c82014-12-23 00:08:49603 const base::CommandLine& command_line =
604 *base::CommandLine::ForCurrentProcess();
[email protected]20657a82012-08-21 20:23:03605
[email protected]27c521a2013-05-29 20:44:32606 if (command_line.HasSwitch(switches::kStatsCollectionController))
607 stats_collection_observer_.reset(new StatsCollectionObserver(this));
608
Blink Reformat1c4d759e2017-04-09 16:34:54609 webview()->SetDisplayMode(display_mode_);
610 webview()->GetSettings()->SetPreferCompositingToLCDTextEnabled(
dcheng0ff94cfc2016-03-15 21:50:51611 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_));
Blink Reformat1c4d759e2017-04-09 16:34:54612 webview()->GetSettings()->SetThreadedScrollingEnabled(
dcheng0ff94cfc2016-03-15 21:50:51613 !command_line.HasSwitch(switches::kDisableThreadedScrolling));
Blink Reformat1c4d759e2017-04-09 16:34:54614 webview()->SetShowFPSCounter(
dcheng0ff94cfc2016-03-15 21:50:51615 command_line.HasSwitch(cc::switches::kShowFPSCounter));
ccameron009667d2017-05-15 04:14:49616 webview()->SetDeviceColorProfile(params.image_decode_color_space);
dcheng0ff94cfc2016-03-15 21:50:51617
618 ApplyWebPreferencesInternal(webkit_preferences_, webview(), compositor_deps_);
619
620 if (switches::IsTouchDragDropEnabled())
Blink Reformat1c4d759e2017-04-09 16:34:54621 webview()->GetSettings()->SetTouchDragDropEnabled(true);
dcheng0ff94cfc2016-03-15 21:50:51622
Blink Reformat1c4d759e2017-04-09 16:34:54623 webview()->GetSettings()->SetBrowserSideNavigationEnabled(
arthursonzognic517fc32016-08-11 11:04:24624 IsBrowserSideNavigationEnabled());
625
dcheng0ff94cfc2016-03-15 21:50:51626 WebSettings::SelectionStrategyType selection_strategy =
Blink Reformat1c4d759e2017-04-09 16:34:54627 WebSettings::SelectionStrategyType::kCharacter;
dcheng0ff94cfc2016-03-15 21:50:51628 const std::string selection_strategy_str =
629 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
630 switches::kTouchTextSelectionStrategy);
631 if (selection_strategy_str == "direction")
Blink Reformat1c4d759e2017-04-09 16:34:54632 selection_strategy = WebSettings::SelectionStrategyType::kDirection;
633 webview()->GetSettings()->SetSelectionStrategy(selection_strategy);
dcheng0ff94cfc2016-03-15 21:50:51634
dtapuskaf65650b2016-05-13 17:21:34635 std::string passiveListenersDefault =
636 command_line.GetSwitchValueASCII(switches::kPassiveListenersDefault);
637 if (!passiveListenersDefault.empty()) {
638 WebSettings::PassiveEventListenerDefault passiveDefault =
Blink Reformat1c4d759e2017-04-09 16:34:54639 WebSettings::PassiveEventListenerDefault::kFalse;
dtapuskaacc2fb22016-07-06 23:26:23640 if (passiveListenersDefault == "true")
Blink Reformat1c4d759e2017-04-09 16:34:54641 passiveDefault = WebSettings::PassiveEventListenerDefault::kTrue;
dtapuskaf65650b2016-05-13 17:21:34642 else if (passiveListenersDefault == "forcealltrue")
Blink Reformat1c4d759e2017-04-09 16:34:54643 passiveDefault = WebSettings::PassiveEventListenerDefault::kForceAllTrue;
644 webview()->GetSettings()->SetPassiveEventListenerDefault(passiveDefault);
dtapuskaf65650b2016-05-13 17:21:34645 }
646
Blink Reformat1c4d759e2017-04-09 16:34:54647 ApplyBlinkSettings(command_line, webview()->GetSettings());
dcheng0ff94cfc2016-03-15 21:50:51648
nick3b5a21f2016-11-22 23:07:11649 WebFrame* opener_frame =
650 RenderFrameImpl::ResolveOpener(params.opener_frame_route_id);
651
dchengc5ef1a52015-08-26 20:58:30652 if (params.main_frame_routing_id != MSG_ROUTING_NONE) {
dcheng3ce04b62015-10-26 23:30:55653 main_render_frame_ = RenderFrameImpl::CreateMainFrame(
654 this, params.main_frame_routing_id, params.main_frame_widget_routing_id,
dcheng9e24bd352016-03-01 19:15:51655 params.hidden, screen_info(), compositor_deps_, opener_frame);
dchengc5ef1a52015-08-26 20:58:30656 }
657
nasko4c0feb62015-06-05 18:37:06658 if (params.proxy_routing_id != MSG_ROUTING_NONE) {
659 CHECK(params.swapped_out);
nick3b5a21f2016-11-22 23:07:11660 RenderFrameProxy::CreateFrameProxy(params.proxy_routing_id, GetRoutingID(),
661 opener_frame, MSG_ROUTING_NONE,
662 params.replicated_frame_state);
nasko4c0feb62015-06-05 18:37:06663 }
664
nasko4c0feb62015-06-05 18:37:06665 if (main_render_frame_)
666 main_render_frame_->Initialize();
667
nickf7b38222016-11-22 21:59:35668 // If this RenderView's creation was initiated by an opener page in this
669 // process, (e.g. window.open()), we won't be visible until we ask the opener,
670 // via show_callback, to make us visible. Otherwise, we went through a
671 // browser-initiated creation, and show() won't be called.
672 if (!was_created_by_renderer)
[email protected]676126f72011-01-15 00:03:51673 did_show_ = true;
mfomitchev5ad034ec2015-04-24 21:57:27674
alexmos35799be2015-07-02 08:59:50675 // Set the main frame's name. Only needs to be done for WebLocalFrames,
676 // since the remote case was handled as part of SetReplicatedState on the
677 // proxy above.
678 if (!params.replicated_frame_state.name.empty() &&
Blink Reformat1c4d759e2017-04-09 16:34:54679 webview()->MainFrame()->IsWebLocalFrame()) {
680 webview()->MainFrame()->SetName(
681 blink::WebString::FromUTF8(params.replicated_frame_state.name));
alexmos3448b552015-06-26 07:49:13682 }
[email protected]34c61bd52011-05-02 19:38:33683
[email protected]c7c0d822014-04-16 20:19:49684 // TODO(davidben): Move this state from Blink into content.
naskobd911332014-11-25 01:13:36685 if (params.window_was_created_with_opener)
Blink Reformat1c4d759e2017-04-09 16:34:54686 webview()->SetOpenedByDOM();
[email protected]c7c0d822014-04-16 20:19:49687
dcheng0ff94cfc2016-03-15 21:50:51688 UpdateWebViewWithDeviceScaleFactor();
naskobd911332014-11-25 01:13:36689 OnSetRendererPrefs(params.renderer_preferences);
[email protected]34c61bd52011-05-02 19:38:33690
naskobd911332014-11-25 01:13:36691 if (!params.enable_auto_resize) {
692 OnResize(params.initial_size);
mkosiba58fa72f02014-11-12 01:21:36693 } else {
naskobd911332014-11-25 01:13:36694 OnEnableAutoResize(params.min_size, params.max_size);
mkosiba58fa72f02014-11-12 01:21:36695 }
696
dtapuska9ec1a912017-04-21 15:18:31697 idle_user_detector_.reset(new IdleUserDetector(this));
[email protected]1784b2f2011-11-24 10:53:48698
[email protected]e9ff79c2012-10-19 21:31:26699 GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44700
dcheng9e24bd352016-03-01 19:15:51701 // Ensure that sandbox flags are inherited from an opener in a different
702 // process. In that case, the browser process will set any inherited sandbox
703 // flags in |replicated_frame_state|, so apply them here.
Blink Reformat1c4d759e2017-04-09 16:34:54704 if (!was_created_by_renderer && webview()->MainFrame()->IsWebLocalFrame()) {
705 webview()->MainFrame()->ToWebLocalFrame()->ForceSandboxFlags(
dcheng9e24bd352016-03-01 19:15:51706 params.replicated_frame_state.sandbox_flags);
alexmosaedfc6f2016-01-21 23:57:38707 }
wjmaclean64951902016-04-29 20:59:12708
709 page_zoom_level_ = params.page_zoom_level;
initial.commit09911bf2008-07-26 23:55:29710}
711
[email protected]310ebd6302011-10-10 19:06:28712RenderViewImpl::~RenderViewImpl() {
dcheng3ce04b62015-10-26 23:30:55713 DCHECK(!frame_widget_);
714
[email protected]cb189e062014-04-23 00:57:01715 for (BitmapMap::iterator it = disambiguation_bitmaps_.begin();
716 it != disambiguation_bitmaps_.end();
717 ++it)
718 delete it->second;
[email protected]91a2aea2013-07-08 23:14:39719
[email protected]8ed1d3f2013-02-20 11:45:55720#if defined(OS_ANDROID)
davve17e025e12016-05-23 15:30:20721 // The date/time picker client is both a std::unique_ptr member of this class
722 // and a RenderViewObserver. Reset it to prevent double deletion.
[email protected]8ed1d3f2013-02-20 11:45:55723 date_time_picker_client_.reset();
724#endif
725
[email protected]60c42a8c72009-10-09 04:08:59726#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22727 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49728 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59729 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
730 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22731 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
732 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
733 it != routing_id_views->end(); ++it)
734 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59735#endif
[email protected]676126f72011-01-15 00:03:51736
dtapuska9ec1a912017-04-21 15:18:31737 idle_user_detector_.reset();
ericwilligers88e69742016-10-17 19:29:55738 for (auto& observer : observers_)
739 observer.RenderViewGone();
740 for (auto& observer : observers_)
741 observer.OnDestruct();
[email protected]60c42a8c72009-10-09 04:08:59742}
743
744/*static*/
[email protected]310ebd6302011-10-10 19:06:28745RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31746 ViewMap* views = g_view_map.Pointer();
747 ViewMap::iterator it = views->find(webview);
748 return it == views->end() ? NULL : it->second;
749}
750
751/*static*/
[email protected]180ef242013-11-07 06:50:46752RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28753 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31754}
755
756/*static*/
avi1023d012015-12-25 02:39:14757RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) {
[email protected]640e303c2012-12-05 01:36:07758 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
759 RoutingIDViewMap::iterator it = views->find(routing_id);
760 return it == views->end() ? NULL : it->second;
761}
762
763/*static*/
764RenderView* RenderView::FromRoutingID(int routing_id) {
765 return RenderViewImpl::FromRoutingID(routing_id);
766}
767
[email protected]f3a95312014-06-12 16:46:58768/* static */
jochen9c7b8f242015-06-01 15:32:02769size_t RenderView::GetRenderViewCount() {
[email protected]f3a95312014-06-12 16:46:58770 return g_view_map.Get().size();
771}
772
[email protected]640e303c2012-12-05 01:36:07773/*static*/
[email protected]e9ff79c2012-10-19 21:31:26774void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49775 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59776 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
777 if (!visitor->Visit(it->second))
778 return;
779 }
780}
781
782/*static*/
[email protected]b3a97b52014-07-09 06:25:05783void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
784 WebView* web_view) {
Blink Reformat1c4d759e2017-04-09 16:34:54785 WebSettings* settings = web_view->GetSettings();
[email protected]b3a97b52014-07-09 06:25:05786 ApplyFontsFromMap(prefs.standard_font_family_map,
787 SetStandardFontFamilyWrapper, settings);
788 ApplyFontsFromMap(prefs.fixed_font_family_map,
789 SetFixedFontFamilyWrapper, settings);
790 ApplyFontsFromMap(prefs.serif_font_family_map,
791 SetSerifFontFamilyWrapper, settings);
792 ApplyFontsFromMap(prefs.sans_serif_font_family_map,
793 SetSansSerifFontFamilyWrapper, settings);
794 ApplyFontsFromMap(prefs.cursive_font_family_map,
795 SetCursiveFontFamilyWrapper, settings);
796 ApplyFontsFromMap(prefs.fantasy_font_family_map,
797 SetFantasyFontFamilyWrapper, settings);
798 ApplyFontsFromMap(prefs.pictograph_font_family_map,
799 SetPictographFontFamilyWrapper, settings);
Blink Reformat1c4d759e2017-04-09 16:34:54800 settings->SetDefaultFontSize(prefs.default_font_size);
801 settings->SetDefaultFixedFontSize(prefs.default_fixed_font_size);
802 settings->SetMinimumFontSize(prefs.minimum_font_size);
803 settings->SetMinimumLogicalFontSize(prefs.minimum_logical_font_size);
804 settings->SetDefaultTextEncodingName(
805 WebString::FromASCII(prefs.default_encoding));
806 settings->SetJavaScriptEnabled(prefs.javascript_enabled);
807 settings->SetWebSecurityEnabled(prefs.web_security_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54808 settings->SetLoadsImagesAutomatically(prefs.loads_images_automatically);
809 settings->SetImagesEnabled(prefs.images_enabled);
810 settings->SetPluginsEnabled(prefs.plugins_enabled);
811 settings->SetEncryptedMediaEnabled(prefs.encrypted_media_enabled);
812 settings->SetDOMPasteAllowed(prefs.dom_paste_enabled);
813 settings->SetTextAreasAreResizable(prefs.text_areas_are_resizable);
814 settings->SetAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
815 settings->SetDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
816 settings->SetJavaScriptCanAccessClipboard(
[email protected]b3a97b52014-07-09 06:25:05817 prefs.javascript_can_access_clipboard);
Blink Reformat1c4d759e2017-04-09 16:34:54818 WebRuntimeFeatures::EnableXSLT(prefs.xslt_enabled);
819 settings->SetXSSAuditorEnabled(prefs.xss_auditor_enabled);
820 settings->SetDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
821 settings->SetDataSaverEnabled(prefs.data_saver_enabled);
822 settings->SetLocalStorageEnabled(prefs.local_storage_enabled);
823 settings->SetSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
824 WebRuntimeFeatures::EnableDatabase(prefs.databases_enabled);
825 settings->SetOfflineWebApplicationCacheEnabled(
[email protected]b3a97b52014-07-09 06:25:05826 prefs.application_cache_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54827 settings->SetHistoryEntryRequiresUserGesture(
japhet5018fe62016-09-14 19:14:04828 prefs.history_entry_requires_user_gesture);
Blink Reformat1c4d759e2017-04-09 16:34:54829 settings->SetHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
830 settings->SetCookieEnabled(prefs.cookie_enabled);
831 settings->SetNavigateOnDragDrop(prefs.navigate_on_drag_drop);
[email protected]b3a97b52014-07-09 06:25:05832
[email protected]b3a97b52014-07-09 06:25:05833 // By default, allow_universal_access_from_file_urls is set to false and thus
834 // we mitigate attacks from local HTML files by not granting file:// URLs
835 // universal access. Only test shell will enable this.
Blink Reformat1c4d759e2017-04-09 16:34:54836 settings->SetAllowUniversalAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05837 prefs.allow_universal_access_from_file_urls);
Blink Reformat1c4d759e2017-04-09 16:34:54838 settings->SetAllowFileAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05839 prefs.allow_file_access_from_file_urls);
840
[email protected]b3a97b52014-07-09 06:25:05841 // Enable experimental WebGL support if requested on command line
842 // and support is compiled in.
Blink Reformat1c4d759e2017-04-09 16:34:54843 settings->SetExperimentalWebGLEnabled(prefs.experimental_webgl_enabled);
[email protected]b3a97b52014-07-09 06:25:05844
[email protected]b3a97b52014-07-09 06:25:05845 // Enable WebGL errors to the JS console if requested.
Blink Reformat1c4d759e2017-04-09 16:34:54846 settings->SetWebGLErrorsToConsoleEnabled(
[email protected]b3a97b52014-07-09 06:25:05847 prefs.webgl_errors_to_console_enabled);
848
849 // Uses the mock theme engine for scrollbars.
Blink Reformat1c4d759e2017-04-09 16:34:54850 settings->SetMockScrollbarsEnabled(prefs.mock_scrollbars_enabled);
[email protected]b3a97b52014-07-09 06:25:05851
Blink Reformat1c4d759e2017-04-09 16:34:54852 settings->SetHideScrollbars(prefs.hide_scrollbars);
eseckler61ff9142016-09-23 22:57:59853
[email protected]b3a97b52014-07-09 06:25:05854 // Enable gpu-accelerated 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54855 WebRuntimeFeatures::EnableAccelerated2dCanvas(
junov524668f22016-08-08 20:16:52856 prefs.accelerated_2d_canvas_enabled);
[email protected]b3a97b52014-07-09 06:25:05857
Blink Reformat1c4d759e2017-04-09 16:34:54858 settings->SetMinimumAccelerated2dCanvasSize(
[email protected]b3a97b52014-07-09 06:25:05859 prefs.minimum_accelerated_2d_canvas_size);
860
861 // Disable antialiasing for 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54862 settings->SetAntialiased2dCanvasEnabled(
[email protected]b3a97b52014-07-09 06:25:05863 !prefs.antialiased_2d_canvas_disabled);
Blink Reformat1c4d759e2017-04-09 16:34:54864 WebRuntimeFeatures::ForceDisable2dCanvasCopyOnWrite(
boliucfcae412016-02-11 22:16:38865 prefs.disable_2d_canvas_copy_on_write);
[email protected]b3a97b52014-07-09 06:25:05866
zakerinasab20ebca02016-09-27 14:22:34867 // Disable antialiasing of clips for 2d canvas if requested on the command
robertphillipse25137b2014-10-20 13:44:34868 // line.
Blink Reformat1c4d759e2017-04-09 16:34:54869 settings->SetAntialiasedClips2dCanvasEnabled(
robertphillipse25137b2014-10-20 13:44:34870 prefs.antialiased_clips_2d_canvas_enabled);
871
[email protected]b3a97b52014-07-09 06:25:05872 // Set MSAA sample count for 2d canvas if requested on the command line (or
873 // default value if not).
Blink Reformat1c4d759e2017-04-09 16:34:54874 settings->SetAccelerated2dCanvasMSAASampleCount(
[email protected]b3a97b52014-07-09 06:25:05875 prefs.accelerated_2d_canvas_msaa_sample_count);
876
[email protected]b3a97b52014-07-09 06:25:05877 // Tabs to link is not part of the settings. WebCore calls
878 // ChromeClient::tabsToLinks which is part of the glue code.
Blink Reformat1c4d759e2017-04-09 16:34:54879 web_view->SetTabsToLinks(prefs.tabs_to_links);
[email protected]b3a97b52014-07-09 06:25:05880
Blink Reformat1c4d759e2017-04-09 16:34:54881 settings->SetAllowRunningOfInsecureContent(
[email protected]b3a97b52014-07-09 06:25:05882 prefs.allow_running_insecure_content);
Blink Reformat1c4d759e2017-04-09 16:34:54883 settings->SetDisableReadingFromCanvas(prefs.disable_reading_from_canvas);
884 settings->SetStrictMixedContentChecking(prefs.strict_mixed_content_checking);
mkwst2384c8222015-07-30 07:26:47885
Blink Reformat1c4d759e2017-04-09 16:34:54886 settings->SetStrictlyBlockBlockableMixedContent(
mkwst2384c8222015-07-30 07:26:47887 prefs.strictly_block_blockable_mixed_content);
888
Blink Reformat1c4d759e2017-04-09 16:34:54889 settings->SetStrictMixedContentCheckingForPlugin(
mkwst0d233e52015-08-10 09:33:14890 prefs.block_mixed_plugin_content);
891
Blink Reformat1c4d759e2017-04-09 16:34:54892 settings->SetStrictPowerfulFeatureRestrictions(
mkwst673a452f2015-01-10 14:41:50893 prefs.strict_powerful_feature_restrictions);
Blink Reformat1c4d759e2017-04-09 16:34:54894 settings->SetAllowGeolocationOnInsecureOrigins(
jww9d4ca2d2016-01-19 20:58:59895 prefs.allow_geolocation_on_insecure_origins);
Blink Reformat1c4d759e2017-04-09 16:34:54896 settings->SetPasswordEchoEnabled(prefs.password_echo_enabled);
897 settings->SetShouldPrintBackgrounds(prefs.should_print_backgrounds);
898 settings->SetShouldClearDocumentBackground(
[email protected]b3a97b52014-07-09 06:25:05899 prefs.should_clear_document_background);
Blink Reformat1c4d759e2017-04-09 16:34:54900 settings->SetEnableScrollAnimator(prefs.enable_scroll_animator);
[email protected]b3a97b52014-07-09 06:25:05901
Blink Reformat1c4d759e2017-04-09 16:34:54902 WebRuntimeFeatures::EnableTouchEventFeatureDetection(
sunyunjiafa6a8afc2016-12-09 04:25:47903 prefs.touch_event_feature_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54904 settings->SetMaxTouchPoints(prefs.pointer_events_max_touch_points);
905 settings->SetAvailablePointerTypes(prefs.available_pointer_types);
906 settings->SetPrimaryPointerType(
nzolghadrc0d1663c2015-11-26 21:15:24907 static_cast<blink::PointerType>(prefs.primary_pointer_type));
Blink Reformat1c4d759e2017-04-09 16:34:54908 settings->SetAvailableHoverTypes(prefs.available_hover_types);
909 settings->SetPrimaryHoverType(
nzolghadrc0d1663c2015-11-26 21:15:24910 static_cast<blink::HoverType>(prefs.primary_hover_type));
Blink Reformat1c4d759e2017-04-09 16:34:54911 settings->SetEnableTouchAdjustment(prefs.touch_adjustment_enabled);
[email protected]b3a97b52014-07-09 06:25:05912
Blink Reformat1c4d759e2017-04-09 16:34:54913 WebRuntimeFeatures::EnableColorCorrectRendering(
ccameron7c4df6c22016-08-11 03:03:15914 prefs.color_correct_rendering_enabled);
ccameron41530d892016-11-29 06:12:33915
Blink Reformat1c4d759e2017-04-09 16:34:54916 settings->SetShouldRespectImageOrientation(
[email protected]b3a97b52014-07-09 06:25:05917 prefs.should_respect_image_orientation);
918
Blink Reformat1c4d759e2017-04-09 16:34:54919 settings->SetEditingBehavior(
[email protected]b3a97b52014-07-09 06:25:05920 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
921
Blink Reformat1c4d759e2017-04-09 16:34:54922 settings->SetSupportsMultipleWindows(prefs.supports_multiple_windows);
[email protected]b3a97b52014-07-09 06:25:05923
Blink Reformat1c4d759e2017-04-09 16:34:54924 settings->SetInertVisualViewport(prefs.inert_visual_viewport);
ymalik835268c22016-02-22 16:28:12925
Blink Reformat1c4d759e2017-04-09 16:34:54926 settings->SetMainFrameClipsContent(!prefs.record_whole_document);
khushalsagar2da2b232016-03-23 22:11:35927
Blink Reformat1c4d759e2017-04-09 16:34:54928 settings->SetSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
[email protected]b3a97b52014-07-09 06:25:05929
Blink Reformat1c4d759e2017-04-09 16:34:54930 settings->SetSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
[email protected]b3a97b52014-07-09 06:25:05931
Blink Reformat1c4d759e2017-04-09 16:34:54932 settings->SetSelectionIncludesAltImageText(true);
[email protected]b3a97b52014-07-09 06:25:05933
Blink Reformat1c4d759e2017-04-09 16:34:54934 settings->SetV8CacheOptions(
[email protected]35103c02014-08-12 15:08:47935 static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options));
936
Blink Reformat1c4d759e2017-04-09 16:34:54937 settings->SetV8CacheStrategiesForCacheStorage(
horodbcbef42016-05-10 17:02:47938 GetV8CacheStrategiesForCacheStorage());
939
Blink Reformat1c4d759e2017-04-09 16:34:54940 settings->SetImageAnimationPolicy(
je_julie.kim7fbb5a1a2015-02-09 17:26:05941 static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy));
942
Blink Reformat1c4d759e2017-04-09 16:34:54943 settings->SetPresentationRequiresUserGesture(
zqzhang1215ad422016-02-10 13:27:22944 prefs.user_gesture_required_for_presentation);
945
Blink Reformat1c4d759e2017-04-09 16:34:54946 settings->SetTextTrackMarginPercentage(prefs.text_track_margin_percentage);
halliwell4002be42016-03-18 18:33:40947
dcheng5ae8ca362015-02-05 04:03:47948 // Needs to happen before setIgnoreVIewportTagScaleLimits below.
Blink Reformat1c4d759e2017-04-09 16:34:54949 web_view->SetDefaultPageScaleLimits(prefs.default_minimum_page_scale_factor,
950 prefs.default_maximum_page_scale_factor);
dcheng5ae8ca362015-02-05 04:03:47951
Blink Reformat1c4d759e2017-04-09 16:34:54952 settings->SetExpensiveBackgroundThrottlingCPUBudget(
altimin56bb594b2016-11-09 19:45:17953 prefs.expensive_background_throttling_cpu_budget);
Blink Reformat1c4d759e2017-04-09 16:34:54954 settings->SetExpensiveBackgroundThrottlingInitialBudget(
altimin56bb594b2016-11-09 19:45:17955 prefs.expensive_background_throttling_initial_budget);
Blink Reformat1c4d759e2017-04-09 16:34:54956 settings->SetExpensiveBackgroundThrottlingMaxBudget(
altimin56bb594b2016-11-09 19:45:17957 prefs.expensive_background_throttling_max_budget);
Blink Reformat1c4d759e2017-04-09 16:34:54958 settings->SetExpensiveBackgroundThrottlingMaxDelay(
altimin56bb594b2016-11-09 19:45:17959 prefs.expensive_background_throttling_max_delay);
960
[email protected]b3a97b52014-07-09 06:25:05961#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:54962 settings->SetAllowCustomScrollbarInMainFrame(false);
963 settings->SetTextAutosizingEnabled(prefs.text_autosizing_enabled);
964 settings->SetAccessibilityFontScaleFactor(prefs.font_scale_factor);
965 settings->SetDeviceScaleAdjustment(prefs.device_scale_adjustment);
966 settings->SetFullscreenSupported(prefs.fullscreen_supported);
967 web_view->SetIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
968 settings->SetAutoZoomFocusedNodeToLegibleScale(true);
969 settings->SetDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54970 settings->SetMediaPlaybackGestureWhitelistScope(
971 blink::WebString::FromUTF8(prefs.media_playback_gesture_whitelist_scope));
972 settings->SetDefaultVideoPosterURL(
973 WebString::FromASCII(prefs.default_video_poster_url.spec()));
974 settings->SetSupportDeprecatedTargetDensityDPI(
[email protected]b3a97b52014-07-09 06:25:05975 prefs.support_deprecated_target_density_dpi);
Blink Reformat1c4d759e2017-04-09 16:34:54976 settings->SetUseLegacyBackgroundSizeShorthandBehavior(
[email protected]b3a97b52014-07-09 06:25:05977 prefs.use_legacy_background_size_shorthand_behavior);
Blink Reformat1c4d759e2017-04-09 16:34:54978 settings->SetWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
979 settings->SetUseWideViewport(prefs.use_wide_viewport);
980 settings->SetForceZeroLayoutHeight(prefs.force_zero_layout_height);
981 settings->SetViewportMetaLayoutSizeQuirk(
[email protected]b3a97b52014-07-09 06:25:05982 prefs.viewport_meta_layout_size_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54983 settings->SetViewportMetaMergeContentQuirk(
[email protected]b3a97b52014-07-09 06:25:05984 prefs.viewport_meta_merge_content_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54985 settings->SetViewportMetaNonUserScalableQuirk(
[email protected]b3a97b52014-07-09 06:25:05986 prefs.viewport_meta_non_user_scalable_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54987 settings->SetViewportMetaZeroValuesQuirk(
[email protected]b3a97b52014-07-09 06:25:05988 prefs.viewport_meta_zero_values_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54989 settings->SetClobberUserAgentInitialScaleQuirk(
[email protected]b3a97b52014-07-09 06:25:05990 prefs.clobber_user_agent_initial_scale_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54991 settings->SetIgnoreMainFrameOverflowHiddenQuirk(
[email protected]b3a97b52014-07-09 06:25:05992 prefs.ignore_main_frame_overflow_hidden_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54993 settings->SetReportScreenSizeInPhysicalPixelsQuirk(
[email protected]b3a97b52014-07-09 06:25:05994 prefs.report_screen_size_in_physical_pixels_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54995 settings->SetShouldReuseGlobalForUnownedMainFrame(
boliu1a00f262016-04-06 19:08:46996 prefs.resue_global_for_unowned_main_frame);
Blink Reformat1c4d759e2017-04-09 16:34:54997 settings->SetProgressBarCompletion(
japhet98e9bd82016-06-28 23:48:45998 static_cast<WebSettings::ProgressBarCompletion>(
999 prefs.progress_bar_completion));
Blink Reformat1c4d759e2017-04-09 16:34:541000 settings->SetPreferHiddenVolumeControls(true);
1001 settings->SetSpellCheckEnabledByDefault(prefs.spellcheck_enabled_by_default);
dalecurtiscd971252016-09-21 16:09:001002
aeliase678aa42017-04-14 22:41:041003 // Force preload=none and disable autoplay on older Android
dalecurtiscd971252016-09-21 16:09:001004 // platforms because their media pipelines are not stable enough to handle
1005 // concurrent elements. See http://crbug.com/612909, http://crbug.com/622826.
aeliase678aa42017-04-14 22:41:041006 const bool is_jelly_bean =
dalecurtiscd971252016-09-21 16:09:001007 base::android::BuildInfo::GetInstance()->sdk_int() <=
aeliase678aa42017-04-14 22:41:041008 base::android::SDK_VERSION_JELLY_BEAN_MR2;
1009 settings->SetForcePreloadNoneForMediaElements(is_jelly_bean);
mlamouri1d266bf2016-12-05 17:42:361010
Blink Reformat1c4d759e2017-04-09 16:34:541011 WebRuntimeFeatures::EnableVideoFullscreenOrientationLock(
mlamouri1d266bf2016-12-05 17:42:361012 prefs.video_fullscreen_orientation_lock_enabled);
johnme913ee5f2017-04-28 21:36:161013 WebRuntimeFeatures::EnableVideoRotateToFullscreen(
1014 prefs.video_rotate_to_fullscreen_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:541015 WebRuntimeFeatures::EnableVideoFullscreenDetection(
zqzhang93e959d12017-03-16 13:10:201016 prefs.video_fullscreen_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:541017 settings->SetEmbeddedMediaExperienceEnabled(
shaktisahuf97f7532017-02-24 22:46:131018 prefs.embedded_media_experience_enabled);
vollick8921b242017-05-25 02:48:151019 settings->SetPagePopupsSuppressed(prefs.page_popups_suppressed);
Blink Reformat1c4d759e2017-04-09 16:34:541020 settings->SetDoNotUpdateSelectionOnMutatingSelectionRange(
changwane54ccdb92017-04-05 19:20:541021 prefs.do_not_update_selection_on_mutating_selection_range);
zqzhangdf72ed082016-12-08 16:07:551022#endif // defined(OS_ANDROID)
liberato9e934892016-05-03 19:00:271023
mlamouri55a0543c2017-05-11 10:34:071024 switch (prefs.autoplay_policy) {
1025 case AutoplayPolicy::kNoUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:281026 settings->SetAutoplayPolicy(
1027 WebSettings::AutoplayPolicy::kNoUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:071028 break;
1029 case AutoplayPolicy::kUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:281030 settings->SetAutoplayPolicy(
1031 WebSettings::AutoplayPolicy::kUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:071032 break;
1033 case AutoplayPolicy::kUserGestureRequiredForCrossOrigin:
mlamouri276a6f32017-05-12 09:24:281034 settings->SetAutoplayPolicy(
1035 WebSettings::AutoplayPolicy::kUserGestureRequiredForCrossOrigin);
mlamouri55a0543c2017-05-11 10:34:071036 break;
1037 }
1038
Blink Reformat1c4d759e2017-04-09 16:34:541039 settings->SetViewportEnabled(prefs.viewport_enabled);
1040 settings->SetViewportMetaEnabled(prefs.viewport_meta_enabled);
1041 settings->SetShrinksViewportContentToFit(
1042 prefs.shrinks_viewport_contents_to_fit);
1043 settings->SetViewportStyle(
alokp5d566962016-04-19 00:54:161044 static_cast<blink::WebViewportStyle>(prefs.viewport_style));
1045
Blink Reformat1c4d759e2017-04-09 16:34:541046 settings->SetLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
1047 settings->SetMainFrameResizesAreOrientationChanges(
yoava1a508b42015-10-20 12:03:211048 prefs.main_frame_resizes_are_orientation_changes);
1049
Blink Reformat1c4d759e2017-04-09 16:34:541050 settings->SetUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
jinho.bang8f11ffa2014-12-04 06:03:031051
Blink Reformat1c4d759e2017-04-09 16:34:541052 settings->SetShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up);
1053 settings->SetAlwaysShowContextMenuOnTouch(
amaralp547e4192016-06-03 19:17:351054 prefs.always_show_context_menu_on_touch);
ccameron2fd70de72015-02-19 00:40:401055
Blink Reformat1c4d759e2017-04-09 16:34:541056 settings->SetHideDownloadUI(prefs.hide_download_ui);
1057 WebRuntimeFeatures::EnableBackgroundVideoTrackOptimization(
avayvod39c102402016-11-23 21:43:131058 prefs.background_video_track_optimization_enabled);
avayvod232757942017-04-29 04:12:341059 WebRuntimeFeatures::EnableNewRemotePlaybackPipeline(
1060 base::FeatureList::IsEnabled(media::kNewRemotePlaybackPipeline));
qinmin72e8bd02016-10-21 19:35:371061
Blink Reformat1c4d759e2017-04-09 16:34:541062 settings->SetPresentationReceiver(prefs.presentation_receiver);
mlamouri57359d912016-11-29 20:11:501063
Blink Reformat1c4d759e2017-04-09 16:34:541064 settings->SetMediaControlsEnabled(prefs.media_controls_enabled);
mlamouri5cd9ae82017-02-18 11:05:091065
ccameron2fd70de72015-02-19 00:40:401066#if defined(OS_MACOSX)
Blink Reformat1c4d759e2017-04-09 16:34:541067 settings->SetDoubleTapToZoomEnabled(true);
1068 web_view->SetMaximumLegibleScale(prefs.default_maximum_page_scale_factor);
ccameron2fd70de72015-02-19 00:40:401069#endif
sunyunjia87f287b2016-09-09 00:38:131070
1071#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:541072 WebRuntimeFeatures::EnableMiddleClickAutoscroll(true);
sunyunjia87f287b2016-09-09 00:38:131073#endif
[email protected]b3a97b52014-07-09 06:25:051074}
1075
1076/*static*/
nickf7b38222016-11-22 21:59:351077RenderViewImpl* RenderViewImpl::Create(
1078 CompositorDependencies* compositor_deps,
1079 const mojom::CreateViewParams& params,
1080 const RenderWidget::ShowCallback& show_callback) {
naskobd911332014-11-25 01:13:361081 DCHECK(params.view_id != MSG_ROUTING_NONE);
[email protected]075366912013-02-18 07:13:241082 RenderViewImpl* render_view = NULL;
[email protected]8d41d7612012-11-14 20:32:191083 if (g_create_render_view_impl)
dcheng35d31c112015-07-22 00:17:361084 render_view = g_create_render_view_impl(compositor_deps, params);
[email protected]075366912013-02-18 07:13:241085 else
dcheng35d31c112015-07-22 00:17:361086 render_view = new RenderViewImpl(compositor_deps, params);
[email protected]0287e762014-04-11 13:07:581087
nickf7b38222016-11-22 21:59:351088 render_view->Initialize(params, show_callback);
[email protected]075366912013-02-18 07:13:241089 return render_view;
[email protected]8d41d7612012-11-14 20:32:191090}
1091
1092// static
dcheng35d31c112015-07-22 00:17:361093void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
1094 *create_render_view_impl)(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:151095 const mojom::CreateViewParams&)) {
[email protected]8d41d7612012-11-14 20:32:191096 CHECK(!g_create_render_view_impl);
1097 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291098}
1099
[email protected]310ebd6302011-10-10 19:06:281100void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511101 observers_.AddObserver(observer);
1102}
1103
[email protected]310ebd6302011-10-10 19:06:281104void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1105 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511106 observers_.RemoveObserver(observer);
1107}
1108
[email protected]180ef242013-11-07 06:50:461109blink::WebView* RenderViewImpl::webview() const {
lfg4fa48da2016-05-09 18:25:131110 return webview_;
[email protected]4d51d5bf2010-07-26 18:48:261111}
1112
brettw4b461082016-11-19 18:55:161113#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:571114
[email protected]784ea1ab2010-09-18 00:02:341115#if defined(OS_MACOSX)
[email protected]7411a3c2014-08-15 05:20:191116void RenderViewImpl::OnGetRenderedText() {
1117 if (!webview())
1118 return;
dglazkov03223492016-02-08 22:16:031119
Blink Reformat1c4d759e2017-04-09 16:34:541120 if (!webview()->MainFrame()->IsWebLocalFrame())
dglazkov03223492016-02-08 22:16:031121 return;
1122
[email protected]7411a3c2014-08-15 05:20:191123 // Get rendered text from WebLocalFrame.
1124 // TODO: Currently IPC truncates any data that has a
1125 // size > kMaximumMessageSize. May be split the text into smaller chunks and
1126 // send back using multiple IPC. See http://crbug.com/393444.
1127 static const size_t kMaximumMessageSize = 8 * 1024 * 1024;
dglazkov03223492016-02-08 22:16:031128 // TODO(dglazkov): Using this API is wrong. It's not OOPIF-compatible and
1129 // sends text in the wrong order. See http://crbug.com/584798.
1130 // TODO(dglazkov): WebFrameContentDumper should only be used for
1131 // testing purposes. See http://crbug.com/585164.
1132 std::string text =
Blink Reformat1c4d759e2017-04-09 16:34:541133 WebFrameContentDumper::DumpWebViewAsText(webview(), kMaximumMessageSize)
1134 .Utf8();
[email protected]7411a3c2014-08-15 05:20:191135
avia3dca182016-03-19 01:09:521136 Send(new ViewMsg_GetRenderedTextCompleted(GetRoutingID(), text));
[email protected]7411a3c2014-08-15 05:20:191137}
[email protected]a80af12e2013-08-07 23:36:131138#endif // defined(OS_MACOSX)
1139
1140#endif // ENABLE_PLUGINS
1141
[email protected]7a1ec28a2012-03-28 21:10:241142void RenderViewImpl::TransferActiveWheelFlingAnimation(
[email protected]180ef242013-11-07 06:50:461143 const blink::WebActiveWheelFlingParameters& params) {
[email protected]7a1ec28a2012-03-28 21:10:241144 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:541145 webview()->TransferActiveWheelFlingAnimation(params);
[email protected]7a1ec28a2012-03-28 21:10:241146}
1147
fsamuel72464894f2015-12-15 06:59:311148// RenderWidgetInputHandlerDelegate -----------------------------------------
1149
avid7d6b2e2016-03-04 19:41:171150bool RenderViewImpl::DoesRenderWidgetHaveTouchEventHandlersAt(
1151 const gfx::Point& point) const {
fsamuel72464894f2015-12-15 06:59:311152 if (!webview())
1153 return false;
Blink Reformat1c4d759e2017-04-09 16:34:541154 return webview()->HasTouchEventHandlersAt(point);
fsamuel72464894f2015-12-15 06:59:311155}
1156
avid7d6b2e2016-03-04 19:41:171157bool RenderViewImpl::RenderWidgetWillHandleMouseEvent(
1158 const blink::WebMouseEvent& event) {
fsamuel72464894f2015-12-15 06:59:311159 // If the mouse is locked, only the current owner of the mouse lock can
1160 // process mouse events.
1161 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
1162}
1163
1164// IPC::Listener implementation ----------------------------------------------
1165
[email protected]310ebd6302011-10-10 19:06:281166bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
Blink Reformat1c4d759e2017-04-09 16:34:541167 WebFrame* main_frame = webview() ? webview()->MainFrame() : NULL;
1168 if (main_frame && main_frame->IsWebLocalFrame())
1169 GetContentClient()->SetActiveURL(main_frame->GetDocument().Url());
[email protected]f8b6b6f2009-03-10 16:48:261170
naskoc6edf7e2015-10-16 01:48:451171 // Input IPC messages must not be processed if the RenderView is in
1172 // swapped out state.
dtapuska1b0fcc322016-10-28 18:08:281173 if (is_swapped_out_ &&
1174 IPC_MESSAGE_ID_CLASS(message.type()) == InputMsgStart) {
1175 // TODO(dtapuska): Remove this histogram once we have seen that it actually
1176 // produces results true. See crbug.com/615090
1177 UMA_HISTOGRAM_BOOLEAN("Event.RenderView.DiscardInput", true);
1178 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
1179 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnDiscardInputEvent)
1180 IPC_END_MESSAGE_MAP()
naskoc6edf7e2015-10-16 01:48:451181 return false;
dtapuska1b0fcc322016-10-28 18:08:281182 }
naskoc6edf7e2015-10-16 01:48:451183
dchenga2d442c22016-10-13 15:39:211184 for (auto& observer : observers_) {
1185 if (observer.OnMessageReceived(message))
[email protected]676126f72011-01-15 00:03:511186 return true;
dchenga2d442c22016-10-13 15:39:211187 }
[email protected]b2abac72009-02-26 12:39:281188
[email protected]a95986a82010-12-24 06:19:281189 bool handled = true;
[email protected]e44d1342014-05-16 21:29:331190 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
[email protected]c084330e02013-04-27 01:08:151191 IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand)
1192 IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret)
[email protected]c084330e02013-04-27 01:08:151193 IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect,
1194 OnScrollFocusedEditableNodeIntoRect)
mcnee432e47d2015-11-09 19:37:461195 IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale)
initial.commit09911bf2008-07-26 23:55:291196 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291197 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1198 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]600ea402011-04-12 00:01:511199 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
1200 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:291201 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
[email protected]30f75e62009-02-25 22:01:001202 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]61f91832014-05-13 01:24:421203 IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque, OnSetBackgroundOpaque)
[email protected]ab32b16c2009-10-16 14:57:251204 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1205 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:471206 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:341207 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:101208 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1209 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511210 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:561211 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:361212 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:341213 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]cb189e062014-04-23 00:57:011214 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupBitmap,
1215 OnReleaseDisambiguationPopupBitmap)
aelias1b55156e52017-04-01 00:46:051216 IPC_MESSAGE_HANDLER(ViewMsg_ResolveTapDisambiguation,
1217 OnResolveTapDisambiguation)
[email protected]506563d2014-06-23 12:22:411218 IPC_MESSAGE_HANDLER(ViewMsg_ForceRedraw, OnForceRedraw)
[email protected]4dda6a6c2014-05-17 15:35:041219 IPC_MESSAGE_HANDLER(ViewMsg_SelectWordAroundCaret, OnSelectWordAroundCaret)
wjmaclean64951902016-04-29 20:59:121220
1221 // Page messages.
lfgdb5c4ed2016-03-04 23:09:071222 IPC_MESSAGE_HANDLER(PageMsg_UpdateWindowScreenRect,
1223 OnUpdateWindowScreenRect)
wjmaclean64951902016-04-29 20:59:121224 IPC_MESSAGE_HANDLER(PageMsg_SetZoomLevel, OnSetZoomLevel)
wjmaclean8a795f32016-08-11 23:49:581225 IPC_MESSAGE_HANDLER(PageMsg_SetDeviceScaleFactor, OnSetDeviceScaleFactor);
lfg717154072016-06-30 15:04:161226 IPC_MESSAGE_HANDLER(PageMsg_WasHidden, OnPageWasHidden)
1227 IPC_MESSAGE_HANDLER(PageMsg_WasShown, OnPageWasShown)
alexmos136fd6e62016-08-15 20:58:411228 IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength,
1229 OnSetHistoryOffsetAndLength)
altimind8bd26c2016-11-04 11:44:541230 IPC_MESSAGE_HANDLER(PageMsg_AudioStateChanged, OnAudioStateChanged)
lfg8d649cc2017-04-28 18:04:301231 IPC_MESSAGE_HANDLER(PageMsg_UpdateScreenInfo, OnUpdateScreenInfo)
lfg717154072016-06-30 15:04:161232
[email protected]55750b32012-09-21 14:05:031233#if defined(OS_ANDROID)
mdjones2ee41afd2016-10-27 16:50:201234 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserControlsState,
1235 OnUpdateBrowserControlsState)
[email protected]55750b32012-09-21 14:05:031236#elif defined(OS_MACOSX)
[email protected]7411a3c2014-08-15 05:20:191237 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedText,
1238 OnGetRenderedText)
naskoc288745f2015-05-01 22:54:211239 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]55750b32012-09-21 14:05:031240#endif
[email protected]a794f3a2013-10-30 17:00:321241 // Adding a new message? Add platform independent ones first, then put the
1242 // platform specific ones at the end.
[email protected]9e1ad4b2011-08-14 16:49:191243
initial.commit09911bf2008-07-26 23:55:291244 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281245 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291246 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401247
[email protected]a95986a82010-12-24 06:19:281248 return handled;
initial.commit09911bf2008-07-26 23:55:291249}
1250
[email protected]4dda6a6c2014-05-17 15:35:041251void RenderViewImpl::OnSelectWordAroundCaret() {
donnd701cc202017-05-17 23:11:201252 // Set default values for the ACK
1253 bool did_select = false;
1254 int start_adjust = 0;
1255 int end_adjust = 0;
[email protected]4dda6a6c2014-05-17 15:35:041256
donnd701cc202017-05-17 23:11:201257 if (webview()) {
1258 WebLocalFrame* focused_frame = GetWebView()->FocusedFrame();
1259 if (focused_frame) {
1260 input_handler_->set_handling_input_event(true);
1261 blink::WebRange initial_range = focused_frame->SelectionRange();
donndbde109ff2017-05-26 20:20:011262 if (!initial_range.IsNull())
1263 did_select = focused_frame->SelectWordAroundCaret();
donnd701cc202017-05-17 23:11:201264 if (did_select) {
1265 blink::WebRange adjusted_range = focused_frame->SelectionRange();
1266 start_adjust =
1267 adjusted_range.StartOffset() - initial_range.StartOffset();
1268 end_adjust = adjusted_range.EndOffset() - initial_range.EndOffset();
1269 }
1270 input_handler_->set_handling_input_event(false);
1271 }
1272 }
1273 Send(new ViewHostMsg_SelectWordAroundCaretAck(GetRoutingID(), did_select,
1274 start_adjust, end_adjust));
[email protected]4dda6a6c2014-05-17 15:35:041275}
1276
[email protected]310ebd6302011-10-10 19:06:281277void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291278 // Check if there is a targeturl waiting to be sent.
avi450ce00e2014-09-24 01:58:521279 if (target_url_status_ == TARGET_PENDING)
avia3dca182016-03-19 01:09:521280 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), pending_target_url_));
initial.commit09911bf2008-07-26 23:55:291281
1282 target_url_status_ = TARGET_NONE;
1283}
1284
[email protected]c084330e02013-04-27 01:08:151285void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
1286 const std::string& value) {
Blink Reformat1c4d759e2017-04-09 16:34:541287 if (!webview() || !webview()->FocusedFrame())
[email protected]c084330e02013-04-27 01:08:151288 return;
1289
Blink Reformat1c4d759e2017-04-09 16:34:541290 webview()->FocusedFrame()->ExecuteCommand(WebString::FromUTF8(name),
1291 WebString::FromUTF8(value));
[email protected]c084330e02013-04-27 01:08:151292}
1293
1294void RenderViewImpl::OnMoveCaret(const gfx::Point& point) {
1295 if (!webview())
1296 return;
1297
avia3dca182016-03-19 01:09:521298 Send(new InputHostMsg_MoveCaret_ACK(GetRoutingID()));
Blink Reformat1c4d759e2017-04-09 16:34:541299 webview()->FocusedFrame()->MoveCaretSelection(
oshima93b827d92016-03-01 18:58:411300 ConvertWindowPointToViewport(point));
[email protected]c084330e02013-04-27 01:08:151301}
[email protected]a954bf72009-09-12 07:30:351302
[email protected]c084330e02013-04-27 01:08:151303void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1304 const gfx::Rect& rect) {
ekaramad27ca69b12017-04-20 18:34:291305 blink::WebAutofillClient* autofill_client = nullptr;
1306 if (auto* focused_frame = GetWebView()->FocusedFrame())
1307 autofill_client = focused_frame->AutofillClient();
1308
[email protected]1875bc02014-03-14 06:33:591309 if (has_scrolled_focused_editable_node_into_rect_ &&
ekaramad27ca69b12017-04-20 18:34:291310 rect == rect_for_scrolled_focused_editable_node_ && autofill_client) {
1311 autofill_client->DidCompleteFocusChangeInFrame();
[email protected]1875bc02014-03-14 06:33:591312 return;
1313 }
1314
Blink Reformat1c4d759e2017-04-09 16:34:541315 if (!webview()->ScrollFocusedEditableElementIntoRect(rect))
dglazkov4969a3e2016-05-20 21:13:511316 return;
rouslanf7ebd8832015-01-22 01:54:141317
dglazkov4969a3e2016-05-20 21:13:511318 rect_for_scrolled_focused_editable_node_ = rect;
1319 has_scrolled_focused_editable_node_into_rect_ = true;
ekaramad27ca69b12017-04-20 18:34:291320 if (!compositor()->HasPendingPageScaleAnimation() && autofill_client)
1321 autofill_client->DidCompleteFocusChangeInFrame();
[email protected]25bcc8f2013-01-09 02:49:251322}
1323
avi2b177592014-12-10 02:08:021324void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset,
1325 int history_length) {
1326 DCHECK_GE(history_offset, -1);
[email protected]e1ed5a12012-08-08 19:57:441327 DCHECK_GE(history_length, 0);
[email protected]9e1ad4b2011-08-14 16:49:191328
avi2b177592014-12-10 02:08:021329 history_list_offset_ = history_offset;
1330 history_list_length_ = history_length;
[email protected]9e1ad4b2011-08-14 16:49:191331}
1332
[email protected]310ebd6302011-10-10 19:06:281333void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291334 if (!webview())
1335 return;
Blink Reformat1c4d759e2017-04-09 16:34:541336 webview()->SetInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291337}
1338
lfgdb5c4ed2016-03-04 23:09:071339void RenderViewImpl::OnUpdateWindowScreenRect(gfx::Rect window_screen_rect) {
1340 RenderWidget::OnUpdateWindowScreenRect(window_screen_rect);
1341}
1342
altimind8bd26c2016-11-04 11:44:541343void RenderViewImpl::OnAudioStateChanged(bool is_audio_playing) {
Blink Reformat1c4d759e2017-04-09 16:34:541344 webview()->AudioStateChanged(is_audio_playing);
altimind8bd26c2016-11-04 11:44:541345}
1346
initial.commit09911bf2008-07-26 23:55:291347///////////////////////////////////////////////////////////////////////////////
1348
nickf7b38222016-11-22 21:59:351349void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget,
1350 WebNavigationPolicy policy,
1351 const gfx::Rect& initial_rect) {
1352 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(),
1353 initial_rect));
1354}
1355
1356void RenderViewImpl::ShowCreatedFullscreenWidget(
1357 RenderWidget* fullscreen_widget,
1358 WebNavigationPolicy policy,
1359 const gfx::Rect& initial_rect) {
1360 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(),
1361 fullscreen_widget->routing_id()));
1362}
1363
creis69b184a472015-11-26 05:29:511364void RenderViewImpl::SendFrameStateUpdates() {
creis69b184a472015-11-26 05:29:511365 // Tell each frame with pending state to send its UpdateState message.
1366 for (int render_frame_routing_id : frames_with_pending_state_) {
1367 RenderFrameImpl* frame =
1368 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
1369 if (frame)
1370 frame->SendUpdateState();
1371 }
1372 frames_with_pending_state_.clear();
1373}
1374
sataya.mf405d0e2015-07-07 16:51:111375void RenderViewImpl::ApplyWebPreferencesInternal(
1376 const WebPreferences& prefs,
1377 blink::WebView* web_view,
1378 CompositorDependencies* compositor_deps) {
1379 ApplyWebPreferences(prefs, web_view);
sataya.mf405d0e2015-07-07 16:51:111380}
1381
svartmetal751af1f92016-08-13 11:47:331382void RenderViewImpl::OnForceRedraw(const ui::LatencyInfo& latency_info) {
[email protected]7d08a9352013-10-15 08:24:561383 if (RenderWidgetCompositor* rwc = compositor()) {
svartmetal751af1f92016-08-13 11:47:331384 rwc->QueueSwapPromise(
1385 base::MakeUnique<AlwaysDrawSwapPromise>(latency_info));
danakj87fbafb2017-04-04 16:54:111386 rwc->SetNeedsForcedRedraw();
[email protected]7d08a9352013-10-15 08:24:561387 }
[email protected]c9bc8f12012-12-15 22:20:091388}
1389
[email protected]180ef242013-11-07 06:50:461390// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521391
csharrison95f01e922017-04-24 18:52:351392// TODO(csharrison): Migrate this method to WebFrameClient / RenderFrameImpl, as
1393// it is now serviced by a mojo interface scoped to the opener frame.
Blink Reformat1c4d759e2017-04-09 16:34:541394WebView* RenderViewImpl::CreateView(WebLocalFrame* creator,
[email protected]35b2a972014-04-04 15:50:221395 const WebURLRequest& request,
1396 const WebWindowFeatures& features,
1397 const WebString& frame_name,
1398 WebNavigationPolicy policy,
1399 bool suppress_opener) {
nick5ae4d2d2017-01-06 01:18:351400 RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator);
rockot5c478a72016-09-28 23:14:181401 mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New();
Blink Reformat1c4d759e2017-04-09 16:34:541402 params->user_gesture = WebUserGestureIndicator::IsProcessingUserGesture();
[email protected]00323f02013-07-24 15:47:411403 if (GetContentClient()->renderer()->AllowPopup())
rockot5c478a72016-09-28 23:14:181404 params->user_gesture = true;
1405 params->window_container_type = WindowFeaturesToContainerType(features);
1406 params->session_storage_namespace_id = session_storage_namespace_id_;
[email protected]5cef23d2013-02-27 13:11:211407 if (frame_name != "_blank")
Blink Reformat1c4d759e2017-04-09 16:34:541408 params->frame_name = frame_name.Utf8(
kinukoa4293022017-01-27 06:43:251409 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
alexmosa97d5c52015-06-19 22:19:091410
rockot5c478a72016-09-28 23:14:181411 params->opener_suppressed = suppress_opener;
1412 params->disposition = NavigationPolicyToDisposition(policy);
Blink Reformat1c4d759e2017-04-09 16:34:541413 if (!request.IsNull()) {
1414 params->target_url = request.Url();
rockot5c478a72016-09-28 23:14:181415 params->referrer = GetReferrerFromRequest(creator, request);
[email protected]44e55b012013-07-23 14:21:561416 }
scottmg8e6c6082017-02-13 23:15:481417 params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
[email protected]8ab04652010-06-12 02:47:261418
rockot5c478a72016-09-28 23:14:181419 // We preserve this information before sending the message since |params| is
1420 // moved on send.
1421 bool is_background_tab =
1422 params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB;
1423 bool opened_by_user_gesture = params->user_gesture;
[email protected]22217ed32013-11-18 18:40:231424
rockot5c478a72016-09-28 23:14:181425 mojom::CreateNewWindowReplyPtr reply;
csharrison95f01e922017-04-24 18:52:351426 mojom::FrameHostAssociatedPtr frame_host_ptr = creator_frame->GetFrameHost();
Charles Harrisonf95354a72017-05-31 23:07:561427 bool err = !frame_host_ptr->CreateNewWindow(std::move(params), &reply);
1428 if (err || reply->route_id == MSG_ROUTING_NONE)
rockot5c478a72016-09-28 23:14:181429 return nullptr;
[email protected]48c9cf2d2009-09-16 16:47:521430
Blink Reformat1c4d759e2017-04-09 16:34:541431 WebUserGestureIndicator::ConsumeUserGesture();
[email protected]c59262422012-11-30 21:20:521432
Jochen Eisinger515337a2017-05-26 14:12:521433 // For Android WebView, we support a pop-up like behavior for window.open()
1434 // even if the embedding app doesn't support multiple windows. In this case,
1435 // window.open() will return "window" and navigate it to whatever URL was
1436 // passed.
1437 if (reply->route_id == GetRoutingID())
1438 return webview();
1439
[email protected]7912e822014-04-16 02:37:031440 // While this view may be a background extension page, it can spawn a visible
1441 // render view. So we just assume that the new one is not another background
1442 // page instead of passing on our own value.
1443 // TODO(vangelis): Can we tell if the new view will be a background page?
1444 bool never_visible = false;
[email protected]9115d5f2013-03-24 04:37:411445
fsamuel664e8b62016-01-20 19:54:011446 ResizeParams initial_size = ResizeParams();
mkosiba58fa72f02014-11-12 01:21:361447 initial_size.screen_info = screen_info_;
1448
[email protected]d6fa88f2013-10-18 16:00:431449 // The initial hidden state for the RenderViewImpl here has to match what the
1450 // browser will eventually decide for the given disposition. Since we have to
1451 // return from this call synchronously, we just have to make our best guess
1452 // and rely on the browser sending a WasHidden / WasShown message if it
1453 // disagrees.
rockot067ca55f2016-09-30 22:00:151454 mojom::CreateViewParams view_params;
alexmos5ac402d2015-07-09 07:51:101455
alexmos5ac402d2015-07-09 07:51:101456 view_params.opener_frame_route_id = creator_frame->GetRoutingID();
avia3dca182016-03-19 01:09:521457 DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID());
alexmos5ac402d2015-07-09 07:51:101458
naskobd911332014-11-25 01:13:361459 view_params.window_was_created_with_opener = true;
1460 view_params.renderer_preferences = renderer_preferences_;
1461 view_params.web_preferences = webkit_preferences_;
rockot5c478a72016-09-28 23:14:181462 view_params.view_id = reply->route_id;
1463 view_params.main_frame_routing_id = reply->main_frame_route_id;
1464 view_params.main_frame_widget_routing_id = reply->main_frame_widget_route_id;
naskobd911332014-11-25 01:13:361465 view_params.session_storage_namespace_id =
rockot5c478a72016-09-28 23:14:181466 reply->cloned_session_storage_namespace_id;
naskobd911332014-11-25 01:13:361467 view_params.swapped_out = false;
alexmos3448b552015-06-26 07:49:131468 // WebCore will take care of setting the correct name.
alexmosbc7eafa2014-12-06 01:38:091469 view_params.replicated_frame_state = FrameReplicationState();
rockot5c478a72016-09-28 23:14:181470 view_params.hidden = is_background_tab;
naskobd911332014-11-25 01:13:361471 view_params.never_visible = never_visible;
naskobd911332014-11-25 01:13:361472 view_params.initial_size = initial_size;
1473 view_params.enable_auto_resize = false;
1474 view_params.min_size = gfx::Size();
1475 view_params.max_size = gfx::Size();
wjmaclean64951902016-04-29 20:59:121476 view_params.page_zoom_level = page_zoom_level_;
naskobd911332014-11-25 01:13:361477
nick5ae4d2d2017-01-06 01:18:351478 // Unretained() is safe here because our calling function will also call
1479 // show().
nickf7b38222016-11-22 21:59:351480 RenderWidget::ShowCallback show_callback =
nick5ae4d2d2017-01-06 01:18:351481 base::Bind(&RenderFrameImpl::ShowCreatedWindow,
1482 base::Unretained(creator_frame), opened_by_user_gesture);
nickf7b38222016-11-22 21:59:351483
danakj6e3bf8012014-12-16 18:27:531484 RenderViewImpl* view =
nickf7b38222016-11-22 21:59:351485 RenderViewImpl::Create(compositor_deps_, view_params, show_callback);
[email protected]48c9cf2d2009-09-16 16:47:521486
[email protected]48c9cf2d2009-09-16 16:47:521487 return view->webview();
1488}
1489
Blink Reformat1c4d759e2017-04-09 16:34:541490WebWidget* RenderViewImpl::CreatePopupMenu(blink::WebPopupType popup_type) {
nickf7b38222016-11-22 21:59:351491 RenderWidget* widget = RenderWidget::CreateForPopup(this, compositor_deps_,
1492 popup_type, screen_info_);
[email protected]3b78ec12014-03-04 05:18:281493 if (!widget)
1494 return NULL;
[email protected]b2e4c70132013-10-03 02:07:511495 if (screen_metrics_emulator_) {
1496 widget->SetPopupOriginAdjustmentsForEmulation(
1497 screen_metrics_emulator_.get());
1498 }
lfg8ff33912016-09-13 20:59:211499 return widget->GetWebWidget();
[email protected]48c9cf2d2009-09-16 16:47:521500}
1501
Blink Reformat1c4d759e2017-04-09 16:34:541502WebStorageNamespace* RenderViewImpl::CreateSessionStorageNamespace() {
[email protected]5f2aa722013-08-07 16:59:411503 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:101504 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341505}
1506
Blink Reformat1c4d759e2017-04-09 16:34:541507void RenderViewImpl::PrintPage(WebLocalFrame* frame) {
naskoe440d8c2016-10-12 23:07:561508 UMA_HISTOGRAM_BOOLEAN("PrintPreview.InitiatedByScript",
Blink Reformat1c4d759e2017-04-09 16:34:541509 frame->Top() == frame);
naskoe440d8c2016-10-12 23:07:561510
1511 // Logging whether the top frame is remote is sufficient in this case. If
1512 // the top frame is local, the printing code will function correctly and
1513 // the frame itself will be printed, so the cases this histogram tracks is
1514 // where printing of a subframe will fail as of now.
1515 UMA_HISTOGRAM_BOOLEAN("PrintPreview.OutOfProcessSubframe",
Blink Reformat1c4d759e2017-04-09 16:34:541516 frame->Top()->IsWebRemoteFrame());
naskoe440d8c2016-10-12 23:07:561517
thestigcb959ce2016-11-17 05:56:321518 RenderFrameImpl::FromWebFrame(frame)->ScriptedPrint(
1519 input_handler().handling_input_event());
[email protected]48c9cf2d2009-09-16 16:47:521520}
1521
Blink Reformat1c4d759e2017-04-09 16:34:541522bool RenderViewImpl::EnumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121523 const WebString& path,
1524 WebFileChooserCompletion* chooser_completion) {
1525 int id = enumeration_completion_id_++;
1526 enumeration_completions_[id] = chooser_completion;
1527 return Send(new ViewHostMsg_EnumerateDirectory(
avia3dca182016-03-19 01:09:521528 GetRoutingID(), id, blink::WebStringToFilePath(path)));
[email protected]8a58c1c2011-04-19 18:40:121529}
1530
[email protected]7e9523b2014-03-25 03:02:421531void RenderViewImpl::FrameDidStartLoading(WebFrame* frame) {
[email protected]7e9523b2014-03-25 03:02:421532 DCHECK_GE(frames_in_progress_, 0);
ericwilligers88e69742016-10-17 19:29:551533 if (frames_in_progress_ == 0) {
1534 for (auto& observer : observers_)
1535 observer.DidStartLoading();
1536 }
[email protected]7e9523b2014-03-25 03:02:421537 frames_in_progress_++;
[email protected]6dd5c322014-03-12 07:58:461538}
1539
[email protected]7e9523b2014-03-25 03:02:421540void RenderViewImpl::FrameDidStopLoading(WebFrame* frame) {
[email protected]eb473772014-04-11 20:54:331541 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
1542 // calls DidStopLoading() without a matching DidStartLoading().
1543 if (frames_in_progress_ == 0)
1544 return;
[email protected]7e9523b2014-03-25 03:02:421545 frames_in_progress_--;
[email protected]7e9523b2014-03-25 03:02:421546 if (frames_in_progress_ == 0) {
1547 DidStopLoadingIcons();
ericwilligers88e69742016-10-17 19:29:551548 for (auto& observer : observers_)
1549 observer.DidStopLoading();
[email protected]7e9523b2014-03-25 03:02:421550 }
[email protected]48c9cf2d2009-09-16 16:47:521551}
1552
lfgcaab5142016-02-26 19:06:521553void RenderViewImpl::AttachWebFrameWidget(blink::WebFrameWidget* frame_widget) {
dcheng3ce04b62015-10-26 23:30:551554 // The previous WebFrameWidget must already be detached by CloseForFrame().
1555 DCHECK(!frame_widget_);
1556 frame_widget_ = frame_widget;
1557}
1558
tommycli8aad3ba2015-08-12 17:57:591559void RenderViewImpl::SetZoomLevel(double zoom_level) {
wjmaclean64951902016-04-29 20:59:121560 // If we change the zoom level for the view, make sure any subsequent subframe
1561 // loads reflect the current zoom level.
1562 page_zoom_level_ = zoom_level;
1563
Blink Reformat1c4d759e2017-04-09 16:34:541564 webview()->SetZoomLevel(zoom_level);
ericwilligers88e69742016-10-17 19:29:551565 for (auto& observer : observers_)
1566 observer.OnZoomLevelChanged();
tommycli8aad3ba2015-08-12 17:57:591567}
1568
habib.virji597255e2014-09-09 00:30:181569void RenderViewImpl::SetValidationMessageDirection(
1570 base::string16* wrapped_main_text,
1571 blink::WebTextDirection main_text_hint,
1572 base::string16* wrapped_sub_text,
1573 blink::WebTextDirection sub_text_hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541574 if (main_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181575 *wrapped_main_text =
1576 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
Blink Reformat1c4d759e2017-04-09 16:34:541577 } else if (main_text_hint == blink::kWebTextDirectionRightToLeft &&
habib.virji597255e2014-09-09 00:30:181578 !base::i18n::IsRTL()) {
1579 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
1580 }
1581
1582 if (!wrapped_sub_text->empty()) {
Blink Reformat1c4d759e2017-04-09 16:34:541583 if (sub_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181584 *wrapped_sub_text =
1585 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
Blink Reformat1c4d759e2017-04-09 16:34:541586 } else if (sub_text_hint == blink::kWebTextDirectionRightToLeft) {
habib.virji597255e2014-09-09 00:30:181587 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
1588 }
1589 }
1590}
1591
Blink Reformat1c4d759e2017-04-09 16:34:541592void RenderViewImpl::ShowValidationMessage(
bokan72a7e342015-12-03 15:46:281593 const blink::WebRect& anchor_in_viewport,
[email protected]edc3af82013-12-12 21:24:071594 const blink::WebString& main_text,
habib.virji597255e2014-09-09 00:30:181595 blink::WebTextDirection main_text_hint,
[email protected]edc3af82013-12-12 21:24:071596 const blink::WebString& sub_text,
habib.virji597255e2014-09-09 00:30:181597 blink::WebTextDirection sub_text_hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541598 base::string16 wrapped_main_text = main_text.Utf16();
1599 base::string16 wrapped_sub_text = sub_text.Utf16();
habib.virji597255e2014-09-09 00:30:181600
1601 SetValidationMessageDirection(
1602 &wrapped_main_text, main_text_hint, &wrapped_sub_text, sub_text_hint);
1603
[email protected]edc3af82013-12-12 21:24:071604 Send(new ViewHostMsg_ShowValidationMessage(
avia3dca182016-03-19 01:09:521605 GetRoutingID(), AdjustValidationMessageAnchor(anchor_in_viewport),
[email protected]2d6836f42014-07-02 17:25:311606 wrapped_main_text, wrapped_sub_text));
[email protected]edc3af82013-12-12 21:24:071607}
1608
Blink Reformat1c4d759e2017-04-09 16:34:541609void RenderViewImpl::HideValidationMessage() {
avia3dca182016-03-19 01:09:521610 Send(new ViewHostMsg_HideValidationMessage(GetRoutingID()));
[email protected]edc3af82013-12-12 21:24:071611}
1612
Blink Reformat1c4d759e2017-04-09 16:34:541613void RenderViewImpl::MoveValidationMessage(
bokan72a7e342015-12-03 15:46:281614 const blink::WebRect& anchor_in_viewport) {
[email protected]2d6836f42014-07-02 17:25:311615 Send(new ViewHostMsg_MoveValidationMessage(
avia3dca182016-03-19 01:09:521616 GetRoutingID(), AdjustValidationMessageAnchor(anchor_in_viewport)));
[email protected]edc3af82013-12-12 21:24:071617}
1618
[email protected]310ebd6302011-10-10 19:06:281619void RenderViewImpl::UpdateTargetURL(const GURL& url,
1620 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581621 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521622 if (latest_url == target_url_)
1623 return;
[email protected]163f8242009-10-30 20:19:551624
[email protected]48c9cf2d2009-09-16 16:47:521625 // Tell the browser to display a destination link.
1626 if (target_url_status_ == TARGET_INFLIGHT ||
1627 target_url_status_ == TARGET_PENDING) {
1628 // If we have a request in-flight, save the URL to be sent when we
1629 // receive an ACK to the in-flight request. We can happily overwrite
1630 // any existing pending sends.
1631 pending_target_url_ = latest_url;
1632 target_url_status_ = TARGET_PENDING;
1633 } else {
mnaganovbf087422015-12-16 05:10:031634 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411635 // see |ParamTraits<GURL>|.
markdittmer67b71ea2016-03-03 22:40:031636 if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:411637 latest_url = GURL();
avia3dca182016-03-19 01:09:521638 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), latest_url));
[email protected]48c9cf2d2009-09-16 16:47:521639 target_url_ = latest_url;
1640 target_url_status_ = TARGET_INFLIGHT;
1641 }
1642}
1643
[email protected]70221f02013-01-31 22:17:071644gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect(
1645 const gfx::RectF& rect) const {
1646 gfx::RectF window_rect = rect;
Blink Reformat1c4d759e2017-04-09 16:34:541647 window_rect.Scale(device_scale_factor_ * webview()->PageScaleFactor());
[email protected]70221f02013-01-31 22:17:071648 return window_rect;
1649}
1650
creis69b184a472015-11-26 05:29:511651void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) {
creisce0ef3572017-01-26 17:53:081652 // Keep track of which frames have pending updates.
1653 frames_with_pending_state_.insert(frame->GetRoutingID());
creis8eb8ef22015-11-04 22:51:381654
[email protected]882daa92009-11-05 16:31:311655 int delay;
avif937e1d2014-11-02 18:13:071656 if (send_content_state_immediately_)
[email protected]882daa92009-11-05 16:31:311657 delay = 0;
1658 else if (is_hidden())
avif937e1d2014-11-02 18:13:071659 delay = kDelaySecondsForContentStateSyncHidden;
[email protected]882daa92009-11-05 16:31:311660 else
avif937e1d2014-11-02 18:13:071661 delay = kDelaySecondsForContentStateSync;
[email protected]882daa92009-11-05 16:31:311662
avif937e1d2014-11-02 18:13:071663 if (nav_state_sync_timer_.IsRunning()) {
[email protected]882daa92009-11-05 16:31:311664 // The timer is already running. If the delay of the timer maches the amount
1665 // we want to delay by, then return. Otherwise stop the timer so that it
1666 // gets started with the right delay.
avif937e1d2014-11-02 18:13:071667 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
[email protected]882daa92009-11-05 16:31:311668 return;
avif937e1d2014-11-02 18:13:071669 nav_state_sync_timer_.Stop();
[email protected]882daa92009-11-05 16:31:311670 }
1671
creisce0ef3572017-01-26 17:53:081672 // Tell each frame with pending state to inform the browser.
1673 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
1674 &RenderViewImpl::SendFrameStateUpdates);
[email protected]882daa92009-11-05 16:31:311675}
1676
Blink Reformat1c4d759e2017-04-09 16:34:541677void RenderViewImpl::SetMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551678 mouse_over_url_ = GURL(url);
1679 UpdateTargetURL(mouse_over_url_, focus_url_);
1680}
1681
Blink Reformat1c4d759e2017-04-09 16:34:541682void RenderViewImpl::SetKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551683 focus_url_ = GURL(url);
1684 UpdateTargetURL(focus_url_, mouse_over_url_);
1685}
1686
Blink Reformat1c4d759e2017-04-09 16:34:541687bool RenderViewImpl::AcceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451688 return renderer_preferences_.can_accept_load_drops;
1689}
1690
Blink Reformat1c4d759e2017-04-09 16:34:541691void RenderViewImpl::FocusNext() {
avia3dca182016-03-19 01:09:521692 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false));
[email protected]48c9cf2d2009-09-16 16:47:521693}
1694
Blink Reformat1c4d759e2017-04-09 16:34:541695void RenderViewImpl::FocusPrevious() {
avia3dca182016-03-19 01:09:521696 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true));
[email protected]48c9cf2d2009-09-16 16:47:521697}
1698
esprehn3d4471a2015-09-17 07:13:201699// TODO(esprehn): Blink only ever passes Elements, this should take WebElement.
Blink Reformat1c4d759e2017-04-09 16:34:541700void RenderViewImpl::FocusedNodeChanged(const WebNode& fromNode,
estade31c54342015-01-23 03:34:361701 const WebNode& toNode) {
[email protected]1875bc02014-03-14 06:33:591702 has_scrolled_focused_editable_node_into_rect_ = false;
1703
estade31c54342015-01-23 03:34:361704 RenderFrameImpl* previous_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541705 if (!fromNode.IsNull())
1706 previous_frame =
1707 RenderFrameImpl::FromWebFrame(fromNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361708 RenderFrameImpl* new_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541709 if (!toNode.IsNull())
1710 new_frame = RenderFrameImpl::FromWebFrame(toNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361711
1712 if (previous_frame && previous_frame != new_frame)
1713 previous_frame->FocusedNodeChanged(WebNode());
1714 if (new_frame)
1715 new_frame->FocusedNodeChanged(toNode);
1716
1717 // TODO(dmazzoni): remove once there's a separate a11y tree per frame.
naskoe8d115752015-08-07 00:43:131718 if (main_render_frame_)
1719 main_render_frame_->FocusedNodeChangedForAccessibility(toNode);
[email protected]08e9e132010-06-01 16:58:491720}
1721
Blink Reformat1c4d759e2017-04-09 16:34:541722void RenderViewImpl::DidUpdateLayout() {
ericwilligers88e69742016-10-17 19:29:551723 for (auto& observer : observers_)
1724 observer.DidUpdateLayout();
[email protected]d01b2a62013-09-18 23:21:331725
[email protected]169d4282011-11-30 19:33:591726 // We don't always want to set up a timer, only if we've been put in that
1727 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1728 // message.
1729 if (!send_preferred_size_changes_ || !webview())
1730 return;
1731
1732 if (check_preferred_size_timer_.IsRunning())
1733 return;
1734 check_preferred_size_timer_.Start(FROM_HERE,
1735 TimeDelta::FromMilliseconds(0), this,
1736 &RenderViewImpl::CheckPreferredSize);
1737}
1738
Blink Reformat1c4d759e2017-04-09 16:34:541739void RenderViewImpl::NavigateBackForwardSoon(int offset) {
avia3dca182016-03-19 01:09:521740 Send(new ViewHostMsg_GoToEntryAtOffset(GetRoutingID(), offset));
[email protected]48c9cf2d2009-09-16 16:47:521741}
1742
Blink Reformat1c4d759e2017-04-09 16:34:541743int RenderViewImpl::HistoryBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001744 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521745}
1746
Blink Reformat1c4d759e2017-04-09 16:34:541747int RenderViewImpl::HistoryForwardListCount() {
1748 return history_list_length_ - HistoryBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521749}
1750
[email protected]180ef242013-11-07 06:50:461751// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:511752
Blink Reformat1c4d759e2017-04-09 16:34:541753void RenderViewImpl::DidFocus() {
[email protected]ea42e7782010-08-23 23:58:121754 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1755 // we won't have to test for user gesture anymore and we can
1756 // move that code back to render_widget.cc
Blink Reformat1c4d759e2017-04-09 16:34:541757 if (WebUserGestureIndicator::IsProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:301758 !RenderThreadImpl::current()->layout_test_mode()) {
avia3dca182016-03-19 01:09:521759 Send(new ViewHostMsg_Focus(GetRoutingID()));
[email protected]ea42e7782010-08-23 23:58:121760 }
1761}
1762
nickf7b38222016-11-22 21:59:351763// We are supposed to get a single call to show() for a newly created RenderView
1764// that was created via RenderViewImpl::createView. We wait until this point to
1765// run |show_callback|, which is bound to our opener's ShowCreatedViewWidget()
1766// method.
initial.commit09911bf2008-07-26 23:55:291767//
1768// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281769// created RenderView (i.e., as a blocked popup or as a new tab).
Blink Reformat1c4d759e2017-04-09 16:34:541770void RenderViewImpl::Show(WebNavigationPolicy policy) {
nickf7b38222016-11-22 21:59:351771 if (did_show_ && !webkit_preferences_.supports_multiple_windows) {
[email protected]b2142e962012-10-30 13:59:251772 // When supports_multiple_windows is disabled, popups are reusing
1773 // the same view. In some scenarios, this makes WebKit to call show() twice.
initial.commit09911bf2008-07-26 23:55:291774 return;
[email protected]b2142e962012-10-30 13:59:251775 }
initial.commit09911bf2008-07-26 23:55:291776
Blink Reformat1c4d759e2017-04-09 16:34:541777 RenderWidget::Show(policy);
initial.commit09911bf2008-07-26 23:55:291778}
1779
miletuse8d28ba2015-06-19 04:52:041780
Blink Reformat1c4d759e2017-04-09 16:34:541781bool RenderViewImpl::CanHandleGestureEvent() {
slangley1a6375e62017-03-29 06:03:231782 return true;
1783}
1784
Blink Reformat1c4d759e2017-04-09 16:34:541785bool RenderViewImpl::CanUpdateLayout() {
slangley1a6375e62017-03-29 06:03:231786 return true;
1787}
1788
Blink Reformat1c4d759e2017-04-09 16:34:541789void RenderViewImpl::DidHandleGestureEvent(const WebGestureEvent& event,
1790 bool event_cancelled) {
1791 RenderWidget::DidHandleGestureEvent(event, event_cancelled);
[email protected]bb37b652013-11-27 23:47:111792
[email protected]91dcc6d32014-07-30 00:01:331793 if (!event_cancelled) {
ericwilligers88e69742016-10-17 19:29:551794 for (auto& observer : observers_)
1795 observer.DidHandleGestureEvent(event);
[email protected]91dcc6d32014-07-30 00:01:331796 }
[email protected]c68c3e4e2013-01-24 00:36:561797}
1798
Blink Reformat1c4d759e2017-04-09 16:34:541799blink::WebLayerTreeView* RenderViewImpl::InitializeLayerTreeView() {
wjmaclean1d970622017-01-21 22:28:241800 // TODO(!wjmaclean): We should be able to just remove this function, and
1801 // expect the RenderWidget version of the function to be called instead.
1802 // However, we have a diamond inheritance pattern going on:
1803 // WebWidgetClient
1804 // | |
1805 // RenderWidget WebViewClient
1806 // | |
1807 // RenderViewImpl
1808 //
1809 // and this seems to prefer calling the empty version in WebWidgetClient
1810 // or WebViewClient over the non-empty one in RenderWidget.
Blink Reformat1c4d759e2017-04-09 16:34:541811 return RenderWidget::InitializeLayerTreeView();
[email protected]6e89eb72013-07-23 13:28:221812}
1813
Blink Reformat1c4d759e2017-04-09 16:34:541814void RenderViewImpl::CloseWidgetSoon() {
1815 RenderWidget::CloseWidgetSoon();
lfg2230bce2016-04-28 18:37:041816}
1817
Blink Reformat1c4d759e2017-04-09 16:34:541818void RenderViewImpl::ConvertViewportToWindow(blink::WebRect* rect) {
1819 RenderWidget::ConvertViewportToWindow(rect);
lfg2230bce2016-04-28 18:37:041820}
1821
Blink Reformat1c4d759e2017-04-09 16:34:541822void RenderViewImpl::ConvertWindowToViewport(blink::WebFloatRect* rect) {
1823 RenderWidget::ConvertWindowToViewport(rect);
lfg2230bce2016-04-28 18:37:041824}
1825
Blink Reformat1c4d759e2017-04-09 16:34:541826void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) {
lfgb00fcad2016-07-14 14:16:331827 RenderWidget::DidAutoResize(newSize);
lfg2230bce2016-04-28 18:37:041828}
1829
Blink Reformat1c4d759e2017-04-09 16:34:541830void RenderViewImpl::DidOverscroll(
lfg2230bce2016-04-28 18:37:041831 const blink::WebFloatSize& overscrollDelta,
1832 const blink::WebFloatSize& accumulatedOverscroll,
1833 const blink::WebFloatPoint& positionInViewport,
1834 const blink::WebFloatSize& velocityInViewport) {
Blink Reformat1c4d759e2017-04-09 16:34:541835 RenderWidget::DidOverscroll(overscrollDelta, accumulatedOverscroll,
lfg2230bce2016-04-28 18:37:041836 positionInViewport, velocityInViewport);
1837}
1838
Blink Reformat1c4d759e2017-04-09 16:34:541839void RenderViewImpl::HasTouchEventHandlers(bool has_handlers) {
1840 RenderWidget::HasTouchEventHandlers(has_handlers);
lfg2230bce2016-04-28 18:37:041841}
1842
Blink Reformat1c4d759e2017-04-09 16:34:541843blink::WebRect RenderViewImpl::RootWindowRect() {
1844 return RenderWidget::WindowRect();
lfg2230bce2016-04-28 18:37:041845}
1846
Blink Reformat1c4d759e2017-04-09 16:34:541847blink::WebScreenInfo RenderViewImpl::GetScreenInfo() {
1848 return RenderWidget::GetScreenInfo();
lfg2230bce2016-04-28 18:37:041849}
1850
Blink Reformat1c4d759e2017-04-09 16:34:541851void RenderViewImpl::SetToolTipText(const blink::WebString& text,
lfg2230bce2016-04-28 18:37:041852 blink::WebTextDirection hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541853 RenderWidget::SetToolTipText(text, hint);
lfg2230bce2016-04-28 18:37:041854}
1855
Blink Reformat1c4d759e2017-04-09 16:34:541856void RenderViewImpl::SetTouchAction(blink::WebTouchAction touchAction) {
1857 RenderWidget::SetTouchAction(touchAction);
lfg2230bce2016-04-28 18:37:041858}
1859
Blink Reformat1c4d759e2017-04-09 16:34:541860void RenderViewImpl::ShowUnhandledTapUIIfNeeded(
lfg2230bce2016-04-28 18:37:041861 const blink::WebPoint& tappedPosition,
1862 const blink::WebNode& tappedNode,
1863 bool pageChanged) {
Blink Reformat1c4d759e2017-04-09 16:34:541864 RenderWidget::ShowUnhandledTapUIIfNeeded(tappedPosition, tappedNode,
lfg2230bce2016-04-28 18:37:041865 pageChanged);
1866}
1867
Blink Reformat1c4d759e2017-04-09 16:34:541868blink::WebWidgetClient* RenderViewImpl::WidgetClient() {
lfg0f440622016-07-20 04:27:141869 return static_cast<RenderWidget*>(this);
1870}
1871
[email protected]180ef242013-11-07 06:50:461872// blink::WebFrameClient -----------------------------------------------------
[email protected]3d9689372009-09-10 04:29:171873
[email protected]5e92282f2012-08-17 08:11:571874void RenderViewImpl::Repaint(const gfx::Size& size) {
[email protected]3d9ec5052013-01-02 22:05:251875 OnRepaint(size);
[email protected]5e92282f2012-08-17 08:11:571876}
1877
[email protected]b2324b092012-11-01 10:34:111878void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
1879 const std::string& value) {
alexmos56567492016-09-13 00:52:461880 GetWidget()->SetEditCommandForNextKeyEvent(name, value);
[email protected]b2324b092012-11-01 10:34:111881}
1882
1883void RenderViewImpl::ClearEditCommands() {
alexmos56567492016-09-13 00:52:461884 GetWidget()->ClearEditCommands();
[email protected]b2324b092012-11-01 10:34:111885}
1886
[email protected]b38806a2013-10-04 16:01:381887const std::string& RenderViewImpl::GetAcceptLanguages() const {
1888 return renderer_preferences_.accept_languages;
1889}
1890
danakjdea2efb2016-03-10 19:13:171891void RenderViewImpl::ConvertViewportToWindowViaWidget(blink::WebRect* rect) {
Blink Reformat1c4d759e2017-04-09 16:34:541892 ConvertViewportToWindow(rect);
oshimae2b3b402015-12-04 04:27:241893}
1894
huangs2a342352015-12-15 16:59:241895gfx::RectF RenderViewImpl::ElementBoundsInWindow(
1896 const blink::WebElement& element) {
Blink Reformat1c4d759e2017-04-09 16:34:541897 blink::WebRect bounding_box_in_window = element.BoundsInViewport();
danakjdea2efb2016-03-10 19:13:171898 ConvertViewportToWindowViaWidget(&bounding_box_in_window);
huangs2a342352015-12-15 16:59:241899 return gfx::RectF(bounding_box_in_window);
1900}
1901
changwand659e202016-06-13 02:39:121902bool RenderViewImpl::HasAddedInputHandler() const {
1903 return has_added_input_handler_;
1904}
1905
[email protected]35b2a972014-04-04 15:50:221906void RenderViewImpl::didChangeIcon(WebLocalFrame* frame,
[email protected]41225fe2013-03-29 05:32:021907 WebIconURL::Type icon_type) {
Blink Reformat1c4d759e2017-04-09 16:34:541908 if (frame->Parent())
[email protected]41225fe2013-03-29 05:32:021909 return;
1910
Blink Reformat1c4d759e2017-04-09 16:34:541911 WebVector<WebIconURL> icon_urls = frame->IconURLs(icon_type);
[email protected]41225fe2013-03-29 05:32:021912 std::vector<FaviconURL> urls;
1913 for (size_t i = 0; i < icon_urls.size(); i++) {
[email protected]2bd262b2014-04-16 05:31:231914 std::vector<gfx::Size> sizes;
Blink Reformat1c4d759e2017-04-09 16:34:541915 ConvertToFaviconSizes(icon_urls[i].Sizes(), &sizes);
1916 urls.push_back(FaviconURL(icon_urls[i].GetIconURL(),
1917 ToFaviconType(icon_urls[i].IconType()), sizes));
[email protected]41225fe2013-03-29 05:32:021918 }
1919 SendUpdateFaviconURL(urls);
[email protected]5019ef12010-04-27 17:26:581920}
1921
[email protected]310ebd6302011-10-10 19:06:281922void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:071923 // We don't always want to send the change messages over IPC, only if we've
1924 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1925 // message.
1926 if (!send_preferred_size_changes_ || !webview())
1927 return;
1928
Blink Reformat1c4d759e2017-04-09 16:34:541929 gfx::Size size = webview()->ContentsPreferredMinimumSize();
[email protected]705243f2010-05-05 19:58:071930 if (size == preferred_size_)
1931 return;
[email protected]c27324b2009-11-19 22:44:291932
[email protected]705243f2010-05-05 19:58:071933 preferred_size_ = size;
avia3dca182016-03-19 01:09:521934 Send(new ViewHostMsg_DidContentsPreferredSizeChange(GetRoutingID(),
[email protected]705243f2010-05-05 19:58:071935 preferred_size_));
[email protected]3d9689372009-09-10 04:29:171936}
1937
Blink Reformat1c4d759e2017-04-09 16:34:541938blink::WebString RenderViewImpl::AcceptLanguages() {
1939 return WebString::FromUTF8(renderer_preferences_.accept_languages);
[email protected]9982c802013-06-12 15:22:061940}
1941
[email protected]e9ff79c2012-10-19 21:31:261942// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:311943
[email protected]310ebd6302011-10-10 19:06:281944bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:311945 return RenderWidget::Send(message);
1946}
1947
avi8a45c1092016-03-01 16:12:341948RenderWidget* RenderViewImpl::GetWidget() const {
1949 return const_cast<RenderWidget*>(static_cast<const RenderWidget*>(this));
1950}
1951
mostynbc33353232014-09-12 09:38:311952RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() {
nasko77de2312015-05-12 03:09:161953 return main_render_frame_;
[email protected]b849847b2013-12-10 21:57:581954}
1955
[email protected]82114f52012-03-20 22:53:411956int RenderViewImpl::GetRoutingID() const {
fsamuele8326c742016-01-12 00:49:391957 return routing_id();
[email protected]a2ef54c2011-10-10 16:20:311958}
1959
[email protected]82114f52012-03-20 22:53:411960gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:311961 return size();
1962}
1963
oshima129b75e2016-01-14 09:15:141964float RenderViewImpl::GetDeviceScaleFactor() const {
1965 return device_scale_factor_;
1966}
1967
thestig8a8fdfd32017-05-06 18:46:541968const WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:311969 return webkit_preferences_;
1970}
1971
[email protected]324825d2012-11-30 12:37:151972void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
1973 OnUpdateWebPreferences(preferences);
1974}
1975
[email protected]180ef242013-11-07 06:50:461976blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:311977 return webview();
1978}
1979
lfgcaab5142016-02-26 19:06:521980blink::WebFrameWidget* RenderViewImpl::GetWebFrameWidget() {
1981 return frame_widget_;
1982}
1983
[email protected]310ebd6302011-10-10 19:06:281984bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:311985 return (!send_preferred_size_changes_ ||
1986 (disable_scrollbars_size_limit_.width() <= width ||
1987 disable_scrollbars_size_limit_.height() <= height));
1988}
1989
avif937e1d2014-11-02 18:13:071990bool RenderViewImpl::GetContentStateImmediately() const {
1991 return send_content_state_immediately_;
[email protected]a2ef54c2011-10-10 16:20:311992}
1993
mcnee432e47d2015-11-09 19:37:461994void RenderViewImpl::OnSetPageScale(float page_scale_factor) {
ccameronb7c1d6c2015-03-09 17:08:241995 if (!webview())
1996 return;
Blink Reformat1c4d759e2017-04-09 16:34:541997 webview()->SetPageScaleFactor(page_scale_factor);
ccameronb7c1d6c2015-03-09 17:08:241998}
1999
wjmaclean64951902016-04-29 20:59:122000void RenderViewImpl::OnSetZoomLevel(
2001 PageMsg_SetZoomLevel_Command command,
2002 double zoom_level) {
2003 switch (command) {
2004 case PageMsg_SetZoomLevel_Command::CLEAR_TEMPORARY:
2005 uses_temporary_zoom_level_ = false;
2006 break;
2007 case PageMsg_SetZoomLevel_Command::SET_TEMPORARY:
2008 uses_temporary_zoom_level_ = true;
2009 break;
2010 case PageMsg_SetZoomLevel_Command::USE_CURRENT_TEMPORARY_MODE:
2011 // Don't override a temporary zoom level without an explicit SET.
2012 if (uses_temporary_zoom_level_)
2013 return;
2014 break;
2015 default:
2016 NOTIMPLEMENTED();
2017 }
Blink Reformat1c4d759e2017-04-09 16:34:542018 webview()->HidePopups();
wjmaclean64951902016-04-29 20:59:122019 SetZoomLevel(zoom_level);
[email protected]d42bf472014-06-14 01:49:382020}
2021
[email protected]310ebd6302011-10-10 19:06:282022void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:592023 webkit_preferences_ = prefs;
sataya.mf405d0e2015-07-07 16:51:112024 ApplyWebPreferencesInternal(webkit_preferences_, webview(), compositor_deps_);
initial.commit09911bf2008-07-26 23:55:292025}
2026
[email protected]310ebd6302011-10-10 19:06:282027void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:512028 int id,
[email protected]c42de732013-02-16 06:26:312029 const std::vector<base::FilePath>& paths) {
[email protected]600ea402011-04-12 00:01:512030 if (!enumeration_completions_[id])
2031 return;
2032
2033 WebVector<WebString> ws_file_names(paths.size());
2034 for (size_t i = 0; i < paths.size(); ++i)
kinukoa4293022017-01-27 06:43:252035 ws_file_names[i] = blink::FilePathToWebString(paths[i]);
[email protected]600ea402011-04-12 00:01:512036
Blink Reformat1c4d759e2017-04-09 16:34:542037 enumeration_completions_[id]->DidChooseFile(ws_file_names);
[email protected]600ea402011-04-12 00:01:512038 enumeration_completions_.erase(id);
2039}
2040
[email protected]244ac1892011-12-02 17:04:472041void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
2042 const gfx::Size& max_size) {
2043 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
2044 if (!webview())
2045 return;
oshima33ec97cd2015-12-14 19:40:242046
[email protected]97e1bf72013-03-06 14:06:052047 auto_resize_mode_ = true;
oshima33ec97cd2015-12-14 19:40:242048 if (IsUseZoomForDSFEnabled()) {
Blink Reformat1c4d759e2017-04-09 16:34:542049 webview()->EnableAutoResizeMode(
oshima33ec97cd2015-12-14 19:40:242050 gfx::ScaleToCeiledSize(min_size, device_scale_factor_),
2051 gfx::ScaleToCeiledSize(max_size, device_scale_factor_));
2052 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542053 webview()->EnableAutoResizeMode(min_size, max_size);
oshima33ec97cd2015-12-14 19:40:242054 }
[email protected]61e2b3cc2012-03-02 16:13:342055}
2056
2057void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
2058 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
2059 if (!webview())
2060 return;
[email protected]97e1bf72013-03-06 14:06:052061 auto_resize_mode_ = false;
Blink Reformat1c4d759e2017-04-09 16:34:542062 webview()->DisableAutoResizeMode();
[email protected]61e2b3cc2012-03-02 16:13:342063
[email protected]eac2b362013-05-22 07:01:452064 if (!new_size.IsEmpty()) {
mfomitchev2600fd7c2016-02-17 20:53:392065 ResizeParams resize_params;
jbroman5ff10302016-07-22 03:36:262066 resize_params.screen_info = screen_info_;
mfomitchev2600fd7c2016-02-17 20:53:392067 resize_params.new_size = new_size;
2068 resize_params.physical_backing_size = physical_backing_size_;
mdjones2ee41afd2016-10-27 16:50:202069 resize_params.browser_controls_shrink_blink_size =
2070 browser_controls_shrink_blink_size_;
mfomitchev2600fd7c2016-02-17 20:53:392071 resize_params.top_controls_height = top_controls_height_;
2072 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:392073 resize_params.is_fullscreen_granted = is_fullscreen_granted();
2074 resize_params.display_mode = display_mode_;
2075 resize_params.needs_resize_ack = false;
2076 Resize(resize_params);
[email protected]eac2b362013-05-22 07:01:452077 }
[email protected]244ac1892011-12-02 17:04:472078}
2079
[email protected]2bf834f2011-11-17 20:02:212080void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:242081 if (send_preferred_size_changes_)
2082 return;
[email protected]9fb325e2010-05-06 18:23:242083 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:392084
[email protected]d812fd12011-05-27 23:05:072085 // Start off with an initial preferred size notification (in case
2086 // |didUpdateLayout| was already called).
Blink Reformat1c4d759e2017-04-09 16:34:542087 DidUpdateLayout();
[email protected]0666aef2009-05-13 19:48:082088}
2089
[email protected]310ebd6302011-10-10 19:06:282090void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:102091 const gfx::Size& disable_scrollbar_size_limit) {
2092 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
2093}
2094
[email protected]310ebd6302011-10-10 19:06:282095void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:262096 const RendererPreferences& renderer_prefs) {
[email protected]ebd5ea52014-05-28 14:51:152097 std::string old_accept_languages = renderer_preferences_.accept_languages;
2098
[email protected]80d96fa2009-06-10 22:34:512099 renderer_preferences_ = renderer_prefs;
ananta59b9fe72015-04-07 01:33:262100
[email protected]6e282c92009-07-24 01:19:372101 UpdateFontRenderingFromRendererPrefs();
scottmgb92365e2016-08-30 20:54:402102 UpdateThemePrefs();
Blink Reformat1c4d759e2017-04-09 16:34:542103 blink::SetCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]38a85712013-01-02 22:45:022104
brettw8a274fa2016-11-15 00:20:402105#if BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]1596efb2013-01-17 22:13:012106 if (renderer_prefs.use_custom_colors) {
Blink Reformat1c4d759e2017-04-09 16:34:542107 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
[email protected]1596efb2013-01-17 22:13:012108
2109 if (webview()) {
Blink Reformat1c4d759e2017-04-09 16:34:542110 webview()->SetSelectionColors(renderer_prefs.active_selection_bg_color,
2111 renderer_prefs.active_selection_fg_color,
2112 renderer_prefs.inactive_selection_bg_color,
2113 renderer_prefs.inactive_selection_fg_color);
2114 webview()->ThemeChanged();
[email protected]1596efb2013-01-17 22:13:012115 }
[email protected]644d77e2010-01-27 01:03:102116 }
brettw8a274fa2016-11-15 00:20:402117#endif // BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]d299d972012-03-23 02:26:552118
[email protected]ebd5ea52014-05-28 14:51:152119 if (webview() &&
2120 old_accept_languages != renderer_preferences_.accept_languages) {
Blink Reformat1c4d759e2017-04-09 16:34:542121 webview()->AcceptLanguagesChanged();
[email protected]ebd5ea52014-05-28 14:51:152122 }
[email protected]80d96fa2009-06-10 22:34:512123}
2124
[email protected]310ebd6302011-10-10 19:06:282125void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
2126 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:282127 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542128 webview()->PerformMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:562129}
2130
[email protected]81375e872012-01-11 21:40:362131void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
2132 const WebPluginAction& action) {
2133 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542134 webview()->PerformPluginAction(action, location);
[email protected]81375e872012-01-11 21:40:362135}
2136
[email protected]310ebd6302011-10-10 19:06:282137void RenderViewImpl::OnClosePage() {
initial.commit09911bf2008-07-26 23:55:292138 // TODO(creis): We'd rather use webview()->Close() here, but that currently
2139 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
2140 // in the onunload handler from appearing. For now, we're bypassing that and
2141 // calling the FrameLoader's CloseURL method directly. This should be
2142 // revisited to avoid having two ways to close a page. Having a single way
2143 // to close that can run onunload is also useful for fixing
2144 // http://b/issue?id=753080.
Blink Reformat1c4d759e2017-04-09 16:34:542145 webview()->MainFrame()->DispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:292146
avia3dca182016-03-19 01:09:522147 Send(new ViewHostMsg_ClosePage_ACK(GetRoutingID()));
initial.commit09911bf2008-07-26 23:55:292148}
2149
naskoc288745f2015-05-01 22:54:212150void RenderViewImpl::OnClose() {
2151 if (closing_)
avia3dca182016-03-19 01:09:522152 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(GetRoutingID()));
naskoc288745f2015-05-01 22:54:212153 RenderWidget::OnClose();
2154}
2155
[email protected]310ebd6302011-10-10 19:06:282156void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:002157 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542158 webview()->HidePopups();
[email protected]30f75e62009-02-25 22:01:002159}
2160
bokanc63441c2016-04-27 15:49:122161void RenderViewImpl::ResizeWebWidget() {
Blink Reformat1c4d759e2017-04-09 16:34:542162 webview()->ResizeWithBrowserControls(GetSizeForWebWidget(),
mdjones2ee41afd2016-10-27 16:50:202163 top_controls_height_,
2164 browser_controls_shrink_blink_size_);
bokanc63441c2016-04-27 15:49:122165}
2166
fsamuel664e8b62016-01-20 19:54:012167void RenderViewImpl::OnResize(const ResizeParams& params) {
[email protected]189a8862014-07-18 00:27:532168 TRACE_EVENT0("renderer", "RenderViewImpl::OnResize");
[email protected]cda45c02010-02-25 19:28:102169 if (webview()) {
Blink Reformat1c4d759e2017-04-09 16:34:542170 webview()->HidePopups();
kenrb5fd60fb82016-06-10 17:27:572171 if (send_preferred_size_changes_ &&
Blink Reformat1c4d759e2017-04-09 16:34:542172 webview()->MainFrame()->IsWebLocalFrame()) {
lukasza302fcdd2017-06-02 20:40:352173 webview()->MainFrame()->ToWebLocalFrame()->SetCanHaveScrollbars(
2174 ShouldDisplayScrollbars(params.new_size.width(),
2175 params.new_size.height()));
[email protected]cda45c02010-02-25 19:28:102176 }
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122177 if (display_mode_ != params.display_mode) {
2178 display_mode_ = params.display_mode;
Blink Reformat1c4d759e2017-04-09 16:34:542179 webview()->SetDisplayMode(display_mode_);
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122180 }
[email protected]cda45c02010-02-25 19:28:102181 }
2182
[email protected]cbbdeef2014-05-26 15:57:362183 gfx::Size old_visible_viewport_size = visible_viewport_size_;
2184
mdjones2ee41afd2016-10-27 16:50:202185 browser_controls_shrink_blink_size_ =
2186 params.browser_controls_shrink_blink_size;
bokanc63441c2016-04-27 15:49:122187 top_controls_height_ = params.top_controls_height;
2188
[email protected]0fdd5012013-05-29 08:05:562189 RenderWidget::OnResize(params);
[email protected]cbbdeef2014-05-26 15:57:362190
2191 if (old_visible_viewport_size != visible_viewport_size_)
2192 has_scrolled_focused_editable_node_into_rect_ = false;
[email protected]30f75e62009-02-25 22:01:002193}
[email protected]0aa477bd2009-03-23 22:21:432194
[email protected]61f91832014-05-13 01:24:422195void RenderViewImpl::OnSetBackgroundOpaque(bool opaque) {
esecklerf2bd55f72017-03-31 09:11:572196 if (!frame_widget_)
2197 return;
2198
2199 if (opaque) {
Blink Reformat1c4d759e2017-04-09 16:34:542200 frame_widget_->ClearBaseBackgroundColorOverride();
2201 frame_widget_->ClearBackgroundColorOverride();
esecklerf2bd55f72017-03-31 09:11:572202 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542203 frame_widget_->SetBaseBackgroundColorOverride(SK_ColorTRANSPARENT);
2204 frame_widget_->SetBackgroundColorOverride(SK_ColorTRANSPARENT);
esecklerf2bd55f72017-03-31 09:11:572205 }
[email protected]699ab0d2009-04-23 23:19:142206}
2207
[email protected]310ebd6302011-10-10 19:06:282208void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:342209 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542210 webview()->SetIsActive(active);
[email protected]8c66c5a2009-07-22 17:26:342211}
2212
lfg8ff33912016-09-13 20:59:212213blink::WebWidget* RenderViewImpl::GetWebWidget() const {
2214 if (frame_widget_)
2215 return frame_widget_;
2216
2217 return RenderWidget::GetWebWidget();
2218}
2219
dcheng3ce04b62015-10-26 23:30:552220void RenderViewImpl::CloseForFrame() {
2221 DCHECK(frame_widget_);
Blink Reformat1c4d759e2017-04-09 16:34:542222 frame_widget_->Close();
dcheng3ce04b62015-10-26 23:30:552223 frame_widget_ = nullptr;
2224}
2225
[email protected]310ebd6302011-10-10 19:06:282226void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:592227 // We need to grab a pointer to the doomed WebView before we destroy it.
lfg4fa48da2016-05-09 18:25:132228 WebView* doomed = webview_;
[email protected]60c42a8c72009-10-09 04:08:592229 RenderWidget::Close();
lfg4fa48da2016-05-09 18:25:132230 webview_ = nullptr;
[email protected]625332e02010-12-14 07:48:492231 g_view_map.Get().erase(doomed);
avia3dca182016-03-19 01:09:522232 g_routing_id_view_map.Get().erase(GetRoutingID());
2233 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(GetRoutingID()));
[email protected]60c42a8c72009-10-09 04:08:592234}
2235
lfg717154072016-06-30 15:04:162236void RenderViewImpl::OnPageWasHidden() {
braveyao1d8ee7b2017-03-29 21:10:042237#if defined(OS_ANDROID)
2238 SuspendVideoCaptureDevices(true);
2239#if BUILDFLAG(ENABLE_WEBRTC)
[email protected]e976c3c52014-07-24 17:41:552240 if (speech_recognition_dispatcher_)
2241 speech_recognition_dispatcher_->AbortAllRecognitions();
[email protected]6392d982013-04-16 16:59:222242#endif
braveyao1d8ee7b2017-03-29 21:10:042243#endif
[email protected]2d7b82c2012-06-01 05:57:502244
lfg717154072016-06-30 15:04:162245 if (webview()) {
2246 // TODO(lfg): It's not correct to defer the page visibility to the main
2247 // frame. Currently, this is done because the main frame may override the
2248 // visibility of the page when prerendering. In order to fix this,
2249 // prerendering must be made aware of OOPIFs. https://crbug.com/440544
2250 blink::WebPageVisibilityState visibilityState =
Blink Reformat1c4d759e2017-04-09 16:34:542251 GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState()
2252 : blink::kWebPageVisibilityStateHidden;
2253 webview()->SetVisibilityState(visibilityState, false);
lfg717154072016-06-30 15:04:162254 }
[email protected]941e4552010-02-01 21:23:432255}
2256
lfg717154072016-06-30 15:04:162257void RenderViewImpl::OnPageWasShown() {
braveyao1d8ee7b2017-03-29 21:10:042258#if defined(OS_ANDROID)
2259 SuspendVideoCaptureDevices(false);
[email protected]6392d982013-04-16 16:59:222260#endif
2261
lfg717154072016-06-30 15:04:162262 if (webview()) {
2263 blink::WebPageVisibilityState visibilityState =
Blink Reformat1c4d759e2017-04-09 16:34:542264 GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState()
2265 : blink::kWebPageVisibilityStateVisible;
2266 webview()->SetVisibilityState(visibilityState, false);
lfg717154072016-06-30 15:04:162267 }
[email protected]a6939ca42011-02-18 17:58:072268}
[email protected]1e6e3c992010-02-08 15:52:132269
lfg8d649cc2017-04-28 18:04:302270void RenderViewImpl::OnUpdateScreenInfo(const ScreenInfo& screen_info) {
2271 // This IPC only updates the screen info on RenderViews that have a remote
2272 // main frame. For local main frames, the ScreenInfo is updated in
2273 // ViewMsg_Resize.
2274 if (!main_render_frame_)
2275 screen_info_ = screen_info;
2276}
2277
[email protected]ed7defa2013-03-12 21:29:592278GURL RenderViewImpl::GetURLForGraphicsContext3D() {
2279 DCHECK(webview());
Blink Reformat1c4d759e2017-04-09 16:34:542280 if (webview()->MainFrame()->IsWebLocalFrame())
2281 return GURL(webview()->MainFrame()->GetDocument().Url());
[email protected]ed7defa2013-03-12 21:29:592282 else
2283 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]65225772011-05-12 21:10:242284}
2285
[email protected]310ebd6302011-10-10 19:06:282286void RenderViewImpl::OnSetFocus(bool enable) {
naskoc6edf7e2015-10-16 01:48:452287 // This message must always be received when the main frame is a
2288 // WebLocalFrame.
Blink Reformat1c4d759e2017-04-09 16:34:542289 CHECK(webview()->MainFrame()->IsWebLocalFrame());
alexmos3fcd0ca2015-10-23 18:18:332290 SetFocus(enable);
2291}
alexmos7fac9aeb2015-10-16 22:39:492292
alexmos3fcd0ca2015-10-23 18:18:332293void RenderViewImpl::SetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:132294 RenderWidget::OnSetFocus(enable);
2295
[email protected]321032992012-11-08 01:01:272296 // Notify all BrowserPlugins of the RenderView's focus state.
fsamuel6c1dfeb2014-12-18 19:21:332297 if (BrowserPluginManager::Get())
2298 BrowserPluginManager::Get()->UpdateFocusState();
[email protected]1e6e3c992010-02-08 15:52:132299}
[email protected]941e4552010-02-01 21:23:432300
rouslanf7ebd8832015-01-22 01:54:142301void RenderViewImpl::DidCompletePageScaleAnimation() {
ekaramad27ca69b12017-04-20 18:34:292302 if (auto* focused_frame = GetWebView()->FocusedFrame()) {
2303 if (focused_frame->AutofillClient())
2304 focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame();
2305 }
rouslanf7ebd8832015-01-22 01:54:142306}
2307
oshimad5279032015-12-16 18:22:332308void RenderViewImpl::OnDeviceScaleFactorChanged() {
2309 RenderWidget::OnDeviceScaleFactorChanged();
2310 UpdateWebViewWithDeviceScaleFactor();
2311 if (auto_resize_mode_)
2312 AutoResizeCompositor();
2313}
2314
[email protected]b2e4c70132013-10-03 02:07:512315void RenderViewImpl::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:202316 bool enabled,
2317 const blink::WebDeviceEmulationParams& params) {
[email protected]404630b2014-07-03 19:33:032318 if (webview() && compositor()) {
dgozman9260b0a12015-03-16 13:45:202319 if (enabled)
Blink Reformat1c4d759e2017-04-09 16:34:542320 webview()->EnableDeviceEmulation(params);
dgozman9260b0a12015-03-16 13:45:202321 else
Blink Reformat1c4d759e2017-04-09 16:34:542322 webview()->DisableDeviceEmulation();
[email protected]b2e4c70132013-10-03 02:07:512323 }
2324}
2325
Blink Reformat1c4d759e2017-04-09 16:34:542326blink::WebSpeechRecognizer* RenderViewImpl::SpeechRecognizer() {
[email protected]64d09222012-05-25 10:10:342327 if (!speech_recognition_dispatcher_)
2328 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
[email protected]64d09222012-05-25 10:10:342329 return speech_recognition_dispatcher_;
2330}
2331
Blink Reformat1c4d759e2017-04-09 16:34:542332void RenderViewImpl::ZoomLimitsChanged(double minimum_level,
[email protected]310ebd6302011-10-10 19:06:282333 double maximum_level) {
a.sarkar.arundaadc712015-02-26 05:39:082334 // Round the double to avoid returning incorrect minimum/maximum zoom
2335 // percentages.
2336 int minimum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492337 ZoomLevelToZoomFactor(minimum_level) * 100);
a.sarkar.arundaadc712015-02-26 05:39:082338 int maximum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492339 ZoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:252340
avia3dca182016-03-19 01:09:522341 Send(new ViewHostMsg_UpdateZoomLimits(GetRoutingID(), minimum_percent,
fsamuele8326c742016-01-12 00:49:392342 maximum_percent));
[email protected]b75b8292010-10-01 07:28:252343}
2344
Blink Reformat1c4d759e2017-04-09 16:34:542345void RenderViewImpl::PageScaleFactorChanged() {
ccameronb7c1d6c2015-03-09 17:08:242346 if (!webview())
2347 return;
mcnee432e47d2015-11-09 19:37:462348
avia3dca182016-03-19 01:09:522349 Send(new ViewHostMsg_PageScaleFactorChanged(GetRoutingID(),
Blink Reformat1c4d759e2017-04-09 16:34:542350 webview()->PageScaleFactor()));
ccameronb7c1d6c2015-03-09 17:08:242351}
2352
[email protected]7940b8e2013-07-25 23:08:492353double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const {
2354 return ZoomLevelToZoomFactor(zoom_level);
2355}
2356
2357double RenderViewImpl::zoomFactorToZoomLevel(double factor) const {
2358 return ZoomFactorToZoomLevel(factor);
2359}
2360
Blink Reformat1c4d759e2017-04-09 16:34:542361void RenderViewImpl::DraggableRegionsChanged() {
ericwilligers88e69742016-10-17 19:29:552362 for (auto& observer : observers_)
Blink Reformat1c4d759e2017-04-09 16:34:542363 observer.DraggableRegionsChanged(webview()->MainFrame());
[email protected]a0629af92012-08-08 00:39:372364}
2365
Blink Reformat1c4d759e2017-04-09 16:34:542366void RenderViewImpl::PageImportanceSignalsChanged() {
kouhei40f03cb2015-09-24 07:47:012367 if (!webview() || !main_render_frame_)
2368 return;
2369
Blink Reformat1c4d759e2017-04-09 16:34:542370 auto* web_signals = webview()->PageImportanceSignals();
kouhei40f03cb2015-09-24 07:47:012371
2372 PageImportanceSignals signals;
Blink Reformat1c4d759e2017-04-09 16:34:542373 signals.had_form_interaction = web_signals->HadFormInteraction();
kouhei40f03cb2015-09-24 07:47:012374
2375 main_render_frame_->Send(new FrameHostMsg_UpdatePageImportanceSignals(
2376 main_render_frame_->GetRoutingID(), signals));
2377}
2378
[email protected]20657a82012-08-21 20:23:032379#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:542380bool RenderViewImpl::OpenDateTimeChooser(
[email protected]180ef242013-11-07 06:50:462381 const blink::WebDateTimeChooserParams& params,
2382 blink::WebDateTimeChooserCompletion* completion) {
[email protected]e8072562013-12-04 06:04:132383 // JavaScript may try to open a date time chooser while one is already open.
2384 if (date_time_picker_client_)
2385 return false;
[email protected]b18583c2012-12-18 06:55:272386 date_time_picker_client_.reset(
2387 new RendererDateTimePicker(this, params, completion));
2388 return date_time_picker_client_->Open();
2389}
2390
[email protected]e8072562013-12-04 06:04:132391void RenderViewImpl::DismissDateTimeDialog() {
2392 DCHECK(date_time_picker_client_);
2393 date_time_picker_client_.reset(NULL);
2394}
[email protected]e8072562013-12-04 06:04:132395
Blink Reformat1c4d759e2017-04-09 16:34:542396bool RenderViewImpl::DidTapMultipleTargets(
timav29a8d0f62014-09-25 20:45:532397 const WebSize& inner_viewport_offset,
2398 const WebRect& touch_rect,
[email protected]f9526d12012-10-18 01:55:032399 const WebVector<WebRect>& target_rects) {
[email protected]8d3dfee62013-06-19 05:50:332400 // Never show a disambiguation popup when accessibility is enabled,
2401 // as this interferes with "touch exploration".
[email protected]95640212014-07-26 18:14:302402 AccessibilityMode accessibility_mode =
mostynbc33353232014-09-12 09:38:312403 GetMainRenderFrame()->accessibility_mode();
dougtcd3dad732017-03-14 03:26:232404 if (accessibility_mode == kAccessibilityModeComplete)
[email protected]8d3dfee62013-06-19 05:50:332405 return false;
2406
timav29a8d0f62014-09-25 20:45:532407 // The touch_rect, target_rects and zoom_rect are in the outer viewport
2408 // reference frame.
[email protected]f9526d12012-10-18 01:55:032409 gfx::Rect zoom_rect;
[email protected]70221f02013-01-31 22:17:072410 float new_total_scale =
2411 DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
timav29a8d0f62014-09-25 20:45:532412 touch_rect, target_rects, GetSize(),
Blink Reformat1c4d759e2017-04-09 16:34:542413 gfx::Rect(webview()->MainFrame()->VisibleContentRect()).size(),
2414 device_scale_factor_ * webview()->PageScaleFactor(), &zoom_rect);
jbauman0ed09182015-01-30 22:33:492415 if (!new_total_scale || zoom_rect.IsEmpty())
[email protected]f9526d12012-10-18 01:55:032416 return false;
2417
[email protected]4ded1dbf2013-08-28 21:11:032418 bool handled = false;
2419 switch (renderer_preferences_.tap_multiple_targets_strategy) {
2420 case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM:
Blink Reformat1c4d759e2017-04-09 16:34:542421 handled = webview()->ZoomToMultipleTargetsRect(zoom_rect);
[email protected]4ded1dbf2013-08-28 21:11:032422 break;
2423 case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: {
[email protected]bc2804d2013-08-06 07:45:492424 gfx::Size canvas_size =
danakjddaec912015-09-25 19:38:402425 gfx::ScaleToCeiledSize(zoom_rect.size(), new_total_scale);
[email protected]cb189e062014-04-23 00:57:012426 cc::SharedBitmapManager* manager =
2427 RenderThreadImpl::current()->shared_bitmap_manager();
dchengcedca5612016-04-09 01:40:152428 std::unique_ptr<cc::SharedBitmap> shared_bitmap =
[email protected]cb189e062014-04-23 00:57:012429 manager->AllocateSharedBitmap(canvas_size);
jbauman0ed09182015-01-30 22:33:492430 CHECK(!!shared_bitmap);
[email protected]bc2804d2013-08-06 07:45:492431 {
[email protected]cb189e062014-04-23 00:57:012432 SkBitmap bitmap;
2433 SkImageInfo info = SkImageInfo::MakeN32Premul(canvas_size.width(),
2434 canvas_size.height());
2435 bitmap.installPixels(info, shared_bitmap->pixels(), info.minRowBytes());
enne98c9f8052017-03-15 19:38:222436 cc::SkiaPaintCanvas canvas(bitmap);
[email protected]f9526d12012-10-18 01:55:032437
[email protected]bc2804d2013-08-06 07:45:492438 // TODO(trchen): Cleanup the device scale factor mess.
2439 // device scale will be applied in WebKit
2440 // --> zoom_rect doesn't include device scale,
2441 // but WebKit will still draw on zoom_rect * device_scale_factor_
[email protected]cb189e062014-04-23 00:57:012442 canvas.scale(new_total_scale / device_scale_factor_,
2443 new_total_scale / device_scale_factor_);
2444 canvas.translate(-zoom_rect.x() * device_scale_factor_,
2445 -zoom_rect.y() * device_scale_factor_);
[email protected]f9526d12012-10-18 01:55:032446
Blink Reformat1c4d759e2017-04-09 16:34:542447 DCHECK(webview_->IsAcceleratedCompositingActive());
2448 webview_->PaintIgnoringCompositing(&canvas, zoom_rect);
[email protected]bc2804d2013-08-06 07:45:492449 }
2450
timav29a8d0f62014-09-25 20:45:532451 gfx::Rect zoom_rect_in_screen =
2452 zoom_rect - gfx::Vector2d(inner_viewport_offset.width,
2453 inner_viewport_offset.height);
2454
[email protected]bc2804d2013-08-06 07:45:492455 gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect(
timav29a8d0f62014-09-25 20:45:532456 ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect_in_screen)));
2457
fsamuele8326c742016-01-12 00:49:392458 Send(new ViewHostMsg_ShowDisambiguationPopup(
avia3dca182016-03-19 01:09:522459 GetRoutingID(), physical_window_zoom_rect, canvas_size,
fsamuele8326c742016-01-12 00:49:392460 shared_bitmap->id()));
[email protected]cb189e062014-04-23 00:57:012461 cc::SharedBitmapId id = shared_bitmap->id();
2462 disambiguation_bitmaps_[id] = shared_bitmap.release();
[email protected]4ded1dbf2013-08-28 21:11:032463 handled = true;
2464 break;
2465 }
2466 case TAP_MULTIPLE_TARGETS_STRATEGY_NONE:
2467 // No-op.
2468 break;
[email protected]f9526d12012-10-18 01:55:032469 }
[email protected]70221f02013-01-31 22:17:072470
[email protected]4ded1dbf2013-08-28 21:11:032471 return handled;
[email protected]f9526d12012-10-18 01:55:032472}
braveyao1d8ee7b2017-03-29 21:10:042473
2474void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) {
tsunghunga86cde72017-04-10 22:27:132475#if BUILDFLAG(ENABLE_WEBRTC)
braveyao1d8ee7b2017-03-29 21:10:042476 if (!main_render_frame_)
2477 return;
2478
2479 MediaStreamDispatcher* media_stream_dispatcher =
2480 main_render_frame_->GetMediaStreamDispatcher();
2481 if (!media_stream_dispatcher)
2482 return;
2483
2484 StreamDeviceInfoArray video_array =
2485 media_stream_dispatcher->GetNonScreenCaptureDevices();
2486 RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices(
2487 video_array, suspend);
tsunghunga86cde72017-04-10 22:27:132488#endif // BUILDFLAG(ENABLE_WEBRTC)
braveyao1d8ee7b2017-03-29 21:10:042489}
estade6b9696bd2016-05-04 23:51:362490#endif // defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:032491
[email protected]b283d292013-02-21 08:40:342492unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
2493 return history_list_length_;
2494}
2495
[email protected]cc290f902013-03-04 20:06:022496void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
2497 if (enable) {
2498 if (has_focus())
2499 return;
2500 OnSetActive(true);
2501 OnSetFocus(true);
2502 } else {
2503 if (!has_focus())
2504 return;
2505 OnSetFocus(false);
2506 OnSetActive(false);
2507 }
2508}
2509
[email protected]3a1c8a8032013-03-18 22:35:322510void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) {
fsamuel664e8b62016-01-20 19:54:012511 ResizeParams params;
[email protected]b54fe452013-06-07 14:01:532512 params.screen_info = screen_info_;
ccameron2f451532016-09-07 21:49:272513 params.screen_info.device_scale_factor = factor;
[email protected]b54fe452013-06-07 14:01:532514 params.new_size = size();
bokanf0fd2412014-10-30 15:28:552515 params.visible_viewport_size = visible_viewport_size_;
danakjddaec912015-09-25 19:38:402516 params.physical_backing_size = gfx::ScaleToCeiledSize(size(), factor);
mdjones2ee41afd2016-10-27 16:50:202517 params.browser_controls_shrink_blink_size = false;
dtrainorcb7779b82014-12-04 01:08:022518 params.top_controls_height = 0.f;
mikhail.pozdnyakovf2c902a2015-04-14 08:09:122519 params.is_fullscreen_granted = is_fullscreen_granted();
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122520 params.display_mode = display_mode_;
[email protected]b54fe452013-06-07 14:01:532521 OnResize(params);
[email protected]3a1c8a8032013-03-18 22:35:322522}
2523
mlamouriafca06dd2017-01-27 23:35:182524void RenderViewImpl::SetDeviceColorProfileForTesting(
2525 const gfx::ICCProfile& icc_profile) {
2526 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542527 webview()->SetDeviceColorProfile(icc_profile);
mlamouriafca06dd2017-01-27 23:35:182528
2529 ResizeParams params;
2530 params.screen_info = screen_info_;
2531 params.screen_info.icc_profile = icc_profile;
2532 params.new_size = size();
2533 params.visible_viewport_size = visible_viewport_size_;
2534 params.physical_backing_size = physical_backing_size_;
2535 params.browser_controls_shrink_blink_size = false;
2536 params.top_controls_height = 0.f;
2537 params.is_fullscreen_granted = is_fullscreen_granted();
2538 params.display_mode = display_mode_;
2539 OnResize(params);
2540}
2541
[email protected]92650162013-10-30 03:31:022542void RenderViewImpl::ForceResizeForTesting(const gfx::Size& new_size) {
Blink Reformat1c4d759e2017-04-09 16:34:542543 gfx::Rect new_window_rect(RootWindowRect().x, RootWindowRect().y,
2544 new_size.width(), new_size.height());
bokanc007c3a2015-02-03 07:15:562545 SetWindowRectSynchronously(new_window_rect);
[email protected]92650162013-10-30 03:31:022546}
2547
[email protected]5b45ad42013-10-25 00:42:042548void RenderViewImpl::UseSynchronousResizeModeForTesting(bool enable) {
2549 resizing_mode_selector_->set_is_synchronous_mode(enable);
2550}
2551
[email protected]eac2b362013-05-22 07:01:452552void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size,
2553 const gfx::Size& max_size) {
2554 OnEnableAutoResize(min_size, max_size);
2555}
2556
2557void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) {
2558 OnDisableAutoResize(new_size);
2559}
2560
[email protected]cb189e062014-04-23 00:57:012561void RenderViewImpl::OnReleaseDisambiguationPopupBitmap(
2562 const cc::SharedBitmapId& id) {
2563 BitmapMap::iterator it = disambiguation_bitmaps_.find(id);
2564 DCHECK(it != disambiguation_bitmaps_.end());
2565 delete it->second;
2566 disambiguation_bitmaps_.erase(it);
[email protected]f9526d12012-10-18 01:55:032567}
[email protected]e9ff79c2012-10-19 21:31:262568
aelias1b55156e52017-04-01 00:46:052569void RenderViewImpl::OnResolveTapDisambiguation(double timestamp_seconds,
2570 gfx::Point tap_viewport_offset,
2571 bool is_long_press) {
Blink Reformat1c4d759e2017-04-09 16:34:542572 webview()->ResolveTapDisambiguation(timestamp_seconds, tap_viewport_offset,
aelias1b55156e52017-04-01 00:46:052573 is_long_press);
2574}
2575
[email protected]6fceb912013-02-15 06:24:152576void RenderViewImpl::DidCommitCompositorFrame() {
2577 RenderWidget::DidCommitCompositorFrame();
ericwilligers88e69742016-10-17 19:29:552578 for (auto& observer : observers_)
2579 observer.DidCommitCompositorFrame();
[email protected]6fceb912013-02-15 06:24:152580}
2581
[email protected]41225fe2013-03-29 05:32:022582void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) {
2583 if (!urls.empty())
avia3dca182016-03-19 01:09:522584 Send(new ViewHostMsg_UpdateFaviconURL(GetRoutingID(), urls));
[email protected]41225fe2013-03-29 05:32:022585}
2586
2587void RenderViewImpl::DidStopLoadingIcons() {
Blink Reformat1c4d759e2017-04-09 16:34:542588 int icon_types = WebIconURL::kTypeFavicon |
2589 WebIconURL::kTypeTouchPrecomposed | WebIconURL::kTypeTouch;
[email protected]41225fe2013-03-29 05:32:022590
nasko2411ba372014-10-13 17:45:412591 // Favicons matter only for the top-level frame. If it is a WebRemoteFrame,
2592 // just return early.
Blink Reformat1c4d759e2017-04-09 16:34:542593 if (webview()->MainFrame()->IsWebRemoteFrame())
nasko2411ba372014-10-13 17:45:412594 return;
2595
[email protected]41225fe2013-03-29 05:32:022596 WebVector<WebIconURL> icon_urls =
Blink Reformat1c4d759e2017-04-09 16:34:542597 webview()->MainFrame()->IconURLs(icon_types);
[email protected]41225fe2013-03-29 05:32:022598
2599 std::vector<FaviconURL> urls;
2600 for (size_t i = 0; i < icon_urls.size(); i++) {
Blink Reformat1c4d759e2017-04-09 16:34:542601 WebURL url = icon_urls[i].GetIconURL();
[email protected]2bd262b2014-04-16 05:31:232602 std::vector<gfx::Size> sizes;
Blink Reformat1c4d759e2017-04-09 16:34:542603 ConvertToFaviconSizes(icon_urls[i].Sizes(), &sizes);
2604 if (!url.IsEmpty())
[email protected]f34ac132014-03-20 23:02:052605 urls.push_back(
Blink Reformat1c4d759e2017-04-09 16:34:542606 FaviconURL(url, ToFaviconType(icon_urls[i].IconType()), sizes));
[email protected]41225fe2013-03-29 05:32:022607 }
2608 SendUpdateFaviconURL(urls);
2609}
2610
oshimad5279032015-12-16 18:22:332611void RenderViewImpl::UpdateWebViewWithDeviceScaleFactor() {
2612 if (!webview())
2613 return;
oshima750cb4342015-10-31 00:59:012614 if (IsUseZoomForDSFEnabled()) {
Blink Reformat1c4d759e2017-04-09 16:34:542615 webview()->SetZoomFactorForDeviceScaleFactor(device_scale_factor_);
oshima750cb4342015-10-31 00:59:012616 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542617 webview()->SetDeviceScaleFactor(device_scale_factor_);
oshima750cb4342015-10-31 00:59:012618 }
Blink Reformat1c4d759e2017-04-09 16:34:542619 webview()->GetSettings()->SetPreferCompositingToLCDTextEnabled(
oshimad5279032015-12-16 18:22:332620 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_));
oshima750cb4342015-10-31 00:59:012621}
2622
dtapuska1b0fcc322016-10-28 18:08:282623void RenderViewImpl::OnDiscardInputEvent(
2624 const blink::WebInputEvent* input_event,
nzolghadr5d8596502017-01-23 22:59:352625 const std::vector<const blink::WebInputEvent*>& coalesced_events,
dtapuska1b0fcc322016-10-28 18:08:282626 const ui::LatencyInfo& latency_info,
2627 InputEventDispatchType dispatch_type) {
dtapuska9ec1a912017-04-21 15:18:312628 if (!input_event || dispatch_type == DISPATCH_TYPE_NON_BLOCKING) {
dtapuska1b0fcc322016-10-28 18:08:282629 return;
2630 }
2631
Blink Reformat1c4d759e2017-04-09 16:34:542632 std::unique_ptr<InputEventAck> ack(new InputEventAck(
2633 InputEventAckSource::MAIN_THREAD, input_event->GetType(),
2634 INPUT_EVENT_ACK_STATE_NOT_CONSUMED));
dtapuska1b0fcc322016-10-28 18:08:282635 OnInputEventAck(std::move(ack));
2636}
2637
dtapuska9ec1a912017-04-21 15:18:312638InputEventAckState RenderViewImpl::HandleInputEvent(
2639 const blink::WebCoalescedInputEvent& input_event,
2640 const ui::LatencyInfo& latency_info,
2641 InputEventDispatchType dispatch_type) {
2642 if (is_swapped_out_) {
2643 OnDiscardInputEvent(&input_event.Event(),
2644 input_event.GetCoalescedEventsPointers(), latency_info,
2645 dispatch_type);
2646 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
2647 }
2648 idle_user_detector_->ActivityDetected();
2649 return RenderWidget::HandleInputEvent(input_event, latency_info,
2650 dispatch_type);
2651}
2652
[email protected]e9ff79c2012-10-19 21:31:262653} // namespace content