blob: 1a46a29c51cb94c162d29da0408507e9763b0127 [file] [log] [blame]
[email protected]b553edd52012-01-10 12:15:231// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]310ebd6302011-10-10 19:06:285#include "content/renderer/render_view_impl.h"
initial.commit09911bf2008-07-26 23:55:296
7#include <algorithm>
[email protected]b75b8292010-10-01 07:28:258#include <cmath>
dchengcedca5612016-04-09 01:40:159#include <memory>
lukasza5d0dee42017-06-14 21:57:3710#include <utility>
initial.commit09911bf2008-07-26 23:55:2911
[email protected]5d4e36d2013-02-15 15:18:2012#include "base/auto_reset.h"
[email protected]6e806822011-11-19 01:51:0813#include "base/bind.h"
14#include "base/bind_helpers.h"
initial.commit09911bf2008-07-26 23:55:2915#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5016#include "base/compiler_specific.h"
[email protected]2132d6b2013-06-05 00:15:4317#include "base/debug/alias.h"
avayvod232757942017-04-29 04:12:3418#include "base/feature_list.h"
[email protected]728c2ee2013-06-25 04:01:0719#include "base/files/file_path.h"
[email protected]edc3af82013-12-12 21:24:0720#include "base/i18n/rtl.h"
[email protected]b1cf3372011-04-20 21:28:1021#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4922#include "base/lazy_instance.h"
fdoray7a8954a42016-06-07 04:28:3823#include "base/location.h"
dchengcedca5612016-04-09 01:40:1524#include "base/memory/ptr_util.h"
[email protected]f29efe6b2014-06-09 05:01:5125#include "base/metrics/field_trial.h"
asvitkine8d51e9d2016-09-02 23:55:4326#include "base/metrics/histogram_macros.h"
[email protected]d3b4ee22013-07-24 22:50:0627#include "base/process/kill.h"
[email protected]7d08a9352013-10-15 08:24:5628#include "base/process/process.h"
fdoray7a8954a42016-06-07 04:28:3829#include "base/single_thread_task_runner.h"
[email protected]21aa99682013-06-11 07:17:0130#include "base/strings/string_number_conversions.h"
[email protected]b9e7c479f2013-04-12 04:33:2431#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4932#include "base/strings/string_split.h"
[email protected]21aa99682013-06-11 07:17:0133#include "base/strings/string_util.h"
[email protected]40d11e02013-03-28 17:43:1434#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0035#include "base/strings/utf_string_conversions.h"
dalecurtiscd971252016-09-21 16:09:0036#include "base/sys_info.h"
fdoray7a8954a42016-06-07 04:28:3837#include "base/threading/thread_task_runner_handle.h"
[email protected]abb522162013-06-28 01:54:1638#include "base/time/time.h"
primiano9e38d552015-01-28 04:18:0139#include "base/trace_event/trace_event.h"
avi1023d012015-12-25 02:39:1440#include "build/build_config.h"
dongseong.hwange095dfa2016-02-04 11:21:3941#include "cc/base/switches.h"
enne98c9f8052017-03-15 19:38:2242#include "cc/paint/skia_paint_canvas.h"
danakj92429852017-06-29 00:19:0343#include "components/viz/client/client_shared_bitmap_manager.h"
jinho.bang632a1a722014-09-18 03:02:5644#include "content/common/content_constants_internal.h"
oshima750cb4342015-10-31 00:59:0145#include "content/common/content_switches_internal.h"
[email protected]5f2aa722013-08-07 16:59:4146#include "content/common/dom_storage/dom_storage_types.h"
[email protected]59f4f2fa2011-03-23 01:00:5547#include "content/common/drag_messages.h"
[email protected]c6bc20332014-02-28 18:30:3948#include "content/common/frame_messages.h"
alexmosbc7eafa2014-12-06 01:38:0949#include "content/common/frame_replication_state.h"
[email protected]c084330e02013-04-27 01:08:1550#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0751#include "content/common/page_messages.h"
rockot5c478a72016-09-28 23:14:1852#include "content/common/render_message_filter.mojom.h"
[email protected]778574e2011-03-21 22:03:5053#include "content/common/view_messages.h"
arthursonzognic517fc32016-08-11 11:04:2454#include "content/public/common/browser_side_navigation_policy.h"
[email protected]744c2a22012-03-15 18:42:0455#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4856#include "content/public/common/content_constants.h"
Tarun Bansal73dd2ff82017-10-03 05:29:3457#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2958#include "content/public/common/content_switches.h"
kouhei40f03cb2015-09-24 07:47:0159#include "content/public/common/page_importance_signals.h"
clamyda97e8322014-10-07 21:57:2560#include "content/public/common/page_state.h"
[email protected]7940b8e2013-07-25 23:08:4961#include "content/public/common/page_zoom.h"
[email protected]818915cd2012-11-20 13:14:1162#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0363#include "content/public/common/url_constants.h"
[email protected]b3a97b52014-07-09 06:25:0564#include "content/public/common/web_preferences.h"
[email protected]d344114c2011-10-01 01:24:3465#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0766#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3267#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4468#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3669#include "content/public/renderer/render_view_visitor.h"
scottmg8e6c6082017-02-13 23:15:4870#include "content/public/renderer/window_features_converter.h"
John Abd-El-Malekdcf1d1372017-10-22 06:39:4171#include "content/renderer/appcache/appcache_dispatcher.h"
72#include "content/renderer/appcache/web_application_cache_host_impl.h"
[email protected]e6e56752012-08-10 00:46:0673#include "content/renderer/browser_plugin/browser_plugin.h"
74#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]dc293a72013-07-01 11:11:2275#include "content/renderer/drop_data_builder.h"
[email protected]ba91a792013-02-06 09:48:2876#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]dc064352014-04-25 08:36:3877#include "content/renderer/history_serialization.h"
[email protected]1784b2f2011-11-24 10:53:4878#include "content/renderer/idle_user_detector.h"
[email protected]66fca5bc2013-05-23 06:58:2979#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1380#include "content/renderer/input/input_handler_manager.h"
[email protected]92d457802013-04-01 19:18:4981#include "content/renderer/internal_document_state_data.h"
John Abd-El-Malek6b56ef712017-10-21 22:52:4682#include "content/renderer/loader/request_extra_data.h"
[email protected]4a914882013-01-10 00:43:4883#include "content/renderer/media/audio_device_factory.h"
Chandan Padhi26dbd9b32017-11-27 11:13:3584#include "content/renderer/media/media_stream_device_observer.h"
[email protected]6392d982013-04-16 16:59:2285#include "content/renderer/media/video_capture_impl_manager.h"
clamy5f342202015-03-18 13:47:5686#include "content/renderer/navigation_state_impl.h"
[email protected]227692c52013-05-31 22:43:0487#include "content/renderer/render_frame_impl.h"
[email protected]5a7100d2014-05-19 01:29:0488#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0589#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4490#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4491#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]663bd9e2011-03-21 01:07:0192#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]5b45ad42013-10-25 00:42:0493#include "content/renderer/resizing_mode_selector.h"
[email protected]12a936d2013-05-15 04:55:4994#include "content/renderer/savable_resources.h"
[email protected]64d09222012-05-25 10:10:3495#include "content/renderer/speech_recognition_dispatcher.h"
John Abd-El-Malek312a30bb2017-10-23 19:51:5296#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:2197#include "content/renderer/web_ui_extension_data.h"
[email protected]f5961142013-04-17 23:09:4298#include "media/audio/audio_output_device.h"
[email protected]ee68378a2010-08-10 01:05:4199#include "media/base/media_switches.h"
Brett Wilson0748bf412016-11-22 17:55:46100#include "media/media_features.h"
servolkf54f5c8f2015-02-24 20:32:39101#include "media/renderers/audio_renderer_impl.h"
Dale Curtis863022e2017-08-19 02:05:34102#include "media/video/gpu_video_accelerator_factories.h"
[email protected]d1ef81d2012-07-24 11:39:36103#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29104#include "net/base/escape.h"
105#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09106#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04107#include "net/http/http_util.h"
brettw4b461082016-11-19 18:55:16108#include "ppapi/features/features.h"
lukenb171b532014-09-24 05:50:38109#include "skia/ext/platform_canvas.h"
Sam McNally52e50282017-11-29 00:54:02110#include "third_party/WebKit/common/associated_interfaces/associated_interface_provider.h"
xzhan96cf0a3c542017-11-17 04:33:01111#include "third_party/WebKit/common/page/page_visibility_state.mojom.h"
kinukob473f002016-02-22 05:23:19112#include "third_party/WebKit/public/platform/FilePathConversion.h"
brettwdfbcc3b2016-01-20 01:49:17113#include "third_party/WebKit/public/platform/URLConversion.h"
[email protected]b3a97b52014-07-09 06:25:05114#include "third_party/WebKit/public/platform/WebConnectionType.h"
[email protected]d0fcff72013-07-23 02:45:43115#include "third_party/WebKit/public/platform/WebHTTPBody.h"
116#include "third_party/WebKit/public/platform/WebImage.h"
dtapuska836e1f92016-11-15 00:38:06117#include "third_party/WebKit/public/platform/WebInputEvent.h"
skyostilcff62882017-01-28 13:18:04118#include "third_party/WebKit/public/platform/WebInputEventResult.h"
Tarun Bansalabd3ef02017-11-03 15:19:20119#include "third_party/WebKit/public/platform/WebNetworkStateNotifier.h"
[email protected]d0fcff72013-07-23 02:45:43120#include "third_party/WebKit/public/platform/WebPoint.h"
121#include "third_party/WebKit/public/platform/WebRect.h"
nverne61d2da872017-05-24 10:15:30122#include "third_party/WebKit/public/platform/WebRuntimeFeatures.h"
[email protected]d0fcff72013-07-23 02:45:43123#include "third_party/WebKit/public/platform/WebSize.h"
[email protected]ec173b522013-11-14 11:01:18124#include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h"
[email protected]d0fcff72013-07-23 02:45:43125#include "third_party/WebKit/public/platform/WebString.h"
126#include "third_party/WebKit/public/platform/WebURL.h"
127#include "third_party/WebKit/public/platform/WebURLError.h"
128#include "third_party/WebKit/public/platform/WebURLRequest.h"
129#include "third_party/WebKit/public/platform/WebURLResponse.h"
130#include "third_party/WebKit/public/platform/WebVector.h"
brettw8a274fa2016-11-15 00:20:40131#include "third_party/WebKit/public/public_features.h"
[email protected]10760e4a2013-09-04 23:32:20132#include "third_party/WebKit/public/web/WebAXObject.h"
ekaramad27ca69b12017-04-20 18:34:29133#include "third_party/WebKit/public/web/WebAutofillClient.h"
[email protected]8bc5ff02013-11-29 06:34:03134#include "third_party/WebKit/public/web/WebColorSuggestion.h"
[email protected]2255a9332013-06-17 05:12:31135#include "third_party/WebKit/public/web/WebDOMEvent.h"
136#include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
[email protected]2255a9332013-06-17 05:12:31137#include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h"
138#include "third_party/WebKit/public/web/WebDateTimeChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31139#include "third_party/WebKit/public/web/WebDocument.h"
140#include "third_party/WebKit/public/web/WebElement.h"
141#include "third_party/WebKit/public/web/WebFileChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31142#include "third_party/WebKit/public/web/WebFormControlElement.h"
143#include "third_party/WebKit/public/web/WebFormElement.h"
144#include "third_party/WebKit/public/web/WebFrame.h"
dglazkov03223492016-02-08 22:16:03145#include "third_party/WebKit/public/web/WebFrameContentDumper.h"
lfgcaab5142016-02-26 19:06:52146#include "third_party/WebKit/public/web/WebFrameWidget.h"
[email protected]2255a9332013-06-17 05:12:31147#include "third_party/WebKit/public/web/WebHistoryItem.h"
[email protected]91dcc6d32014-07-30 00:01:33148#include "third_party/WebKit/public/web/WebHitTestResult.h"
[email protected]2255a9332013-06-17 05:12:31149#include "third_party/WebKit/public/web/WebInputElement.h"
[email protected]35b2a972014-04-04 15:50:22150#include "third_party/WebKit/public/web/WebLocalFrame.h"
[email protected]2255a9332013-06-17 05:12:31151#include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
152#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
kouhei40f03cb2015-09-24 07:47:01153#include "third_party/WebKit/public/web/WebPageImportanceSignals.h"
[email protected]2255a9332013-06-17 05:12:31154#include "third_party/WebKit/public/web/WebPlugin.h"
155#include "third_party/WebKit/public/web/WebPluginAction.h"
[email protected]2255a9332013-06-17 05:12:31156#include "third_party/WebKit/public/web/WebRange.h"
ellyjones8ae17692016-08-05 15:19:21157#include "third_party/WebKit/public/web/WebRenderTheme.h"
[email protected]2255a9332013-06-17 05:12:31158#include "third_party/WebKit/public/web/WebScriptSource.h"
159#include "third_party/WebKit/public/web/WebSearchableFormData.h"
[email protected]2255a9332013-06-17 05:12:31160#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
[email protected]2255a9332013-06-17 05:12:31161#include "third_party/WebKit/public/web/WebSettings.h"
[email protected]2255a9332013-06-17 05:12:31162#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
[email protected]2255a9332013-06-17 05:12:31163#include "third_party/WebKit/public/web/WebView.h"
164#include "third_party/WebKit/public/web/WebWindowFeatures.h"
[email protected]b3a97b52014-07-09 06:25:05165#include "third_party/icu/source/common/unicode/uchar.h"
166#include "third_party/icu/source/common/unicode/uscript.h"
esecklerf2bd55f72017-03-31 09:11:57167#include "third_party/skia/include/core/SkColor.h"
[email protected]1400e6dc2013-04-27 02:36:27168#include "ui/base/ui_base_switches_util.h"
tfarina655f81d2014-12-23 02:38:50169#include "ui/gfx/geometry/point.h"
tfarina3b0452d2014-12-31 15:20:09170#include "ui/gfx/geometry/rect.h"
171#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32172#include "ui/gfx/geometry/size_conversions.h"
[email protected]08397d52011-02-05 01:53:38173#include "ui/gfx/native_widget_types.h"
ccameron772317d2017-06-04 18:35:03174#include "ui/gfx/switches.h"
mfomitchev3ba450ad2017-04-03 18:20:40175#include "ui/latency/latency_info.h"
csharrisond88f9752016-10-26 23:56:36176#include "url/origin.h"
markdittmer67b71ea2016-03-03 22:40:03177#include "url/url_constants.h"
[email protected]c4a9e932011-03-05 04:05:55178#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:29179
[email protected]25fb9b32012-04-27 03:21:55180#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25181#include <cpu-features.h>
182
dalecurtiscd971252016-09-21 16:09:00183#include "base/android/build_info.h"
estade6b9696bd2016-05-04 23:51:36184#include "content/renderer/android/disambiguation_popup_helper.h"
tfarina3b0452d2014-12-31 15:20:09185#include "ui/gfx/geometry/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40186
[email protected]78043bdd2010-04-05 18:45:33187#elif defined(OS_MACOSX)
188#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57189#endif
190
brettw4b461082016-11-19 18:55:16191#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]ea2fb972013-08-07 05:44:26192#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
193#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26194#endif
195
Brett Wilson0748bf412016-11-22 17:55:46196#if BUILDFLAG(ENABLE_WEBRTC)
[email protected]9ac667e2013-09-09 12:49:21197#include "content/renderer/media/rtc_peer_connection_handler.h"
[email protected]22fe91d2014-08-12 17:07:12198#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
[email protected]9ac667e2013-09-09 12:49:21199#endif
200
[email protected]180ef242013-11-07 06:50:46201using blink::WebAXObject;
202using blink::WebApplicationCacheHost;
203using blink::WebApplicationCacheHostClient;
[email protected]180ef242013-11-07 06:50:46204using blink::WebColor;
[email protected]180ef242013-11-07 06:50:46205using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46206using blink::WebData;
[email protected]180ef242013-11-07 06:50:46207using blink::WebDocument;
[email protected]180ef242013-11-07 06:50:46208using blink::WebDragOperation;
[email protected]180ef242013-11-07 06:50:46209using blink::WebElement;
[email protected]180ef242013-11-07 06:50:46210using blink::WebFileChooserCompletion;
[email protected]180ef242013-11-07 06:50:46211using blink::WebFormControlElement;
212using blink::WebFormElement;
213using blink::WebFrame;
dglazkov03223492016-02-08 22:16:03214using blink::WebFrameContentDumper;
[email protected]180ef242013-11-07 06:50:46215using blink::WebGestureEvent;
216using blink::WebHistoryItem;
217using blink::WebHTTPBody;
dglazkov8d0c21dd2016-08-06 15:56:36218using blink::WebHitTestResult;
[email protected]180ef242013-11-07 06:50:46219using blink::WebImage;
220using blink::WebInputElement;
221using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22222using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46223using blink::WebMediaPlayerAction;
[email protected]180ef242013-11-07 06:50:46224using blink::WebMouseEvent;
225using blink::WebNavigationPolicy;
226using blink::WebNavigationType;
227using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46228using blink::WebPluginAction;
[email protected]180ef242013-11-07 06:50:46229using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46230using blink::WebRect;
231using blink::WebReferrerPolicy;
Daniel Chengd5e56ff2017-06-24 07:44:02232using blink::WebSandboxFlags;
[email protected]180ef242013-11-07 06:50:46233using blink::WebScriptSource;
234using blink::WebSearchableFormData;
235using blink::WebSecurityOrigin;
236using blink::WebSecurityPolicy;
[email protected]180ef242013-11-07 06:50:46237using blink::WebSettings;
238using blink::WebSize;
[email protected]180ef242013-11-07 06:50:46239using blink::WebStorageQuotaCallbacks;
240using blink::WebStorageQuotaError;
241using blink::WebStorageQuotaType;
242using blink::WebString;
Donn Denman43a439e2017-08-29 04:20:45243using blink::WebTappedInfo;
[email protected]180ef242013-11-07 06:50:46244using blink::WebTextDirection;
245using blink::WebTouchEvent;
246using blink::WebURL;
247using blink::WebURLError;
248using blink::WebURLRequest;
249using blink::WebURLResponse;
250using blink::WebUserGestureIndicator;
251using blink::WebVector;
252using blink::WebView;
253using blink::WebWidget;
254using blink::WebWindowFeatures;
[email protected]b3a97b52014-07-09 06:25:05255using blink::WebRuntimeFeatures;
[email protected]6fdd4182010-10-14 23:59:26256using base::TimeDelta;
[email protected]e1acf6f2008-10-27 20:43:33257
[email protected]20657a82012-08-21 20:23:03258
[email protected]e9ff79c2012-10-19 21:31:26259namespace content {
260
initial.commit09911bf2008-07-26 23:55:29261//-----------------------------------------------------------------------------
262
[email protected]180ef242013-11-07 06:50:46263typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
jbroman8319b232017-03-08 22:53:29264static base::LazyInstance<ViewMap>::Leaky g_view_map =
[email protected]058561b2012-12-03 06:48:22265 LAZY_INSTANCE_INITIALIZER;
scottmg5e65e3a2017-03-08 08:48:46266typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap;
jbroman8319b232017-03-08 22:53:29267static base::LazyInstance<RoutingIDViewMap>::Leaky g_routing_id_view_map =
268 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02269
[email protected]882daa92009-11-05 16:31:31270// Time, in seconds, we delay before sending content state changes (such as form
271// state and scroll position) to the browser. We delay sending changes to avoid
272// spamming the browser.
273// To avoid having tab/session restore require sending a message to get the
274// current content state during tab closing we use a shorter timeout for the
275// foreground renderer. This means there is a small window of time from which
276// content state is modified and not sent to session restore, but this is
277// better than having to wake up all renderers during shutdown.
avif937e1d2014-11-02 18:13:07278const int kDelaySecondsForContentStateSyncHidden = 5;
279const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29280
dcheng35d31c112015-07-22 00:17:36281static RenderViewImpl* (*g_create_render_view_impl)(
282 CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:15283 const mojom::CreateViewParams&) = nullptr;
[email protected]8d41d7612012-11-14 20:32:19284
[email protected]c6bc20332014-02-28 18:30:39285// static
[email protected]e507045d2013-07-24 15:23:44286Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56287 WebFrame* frame,
288 const WebURLRequest& request) {
Blink Reformat1c4d759e2017-04-09 16:34:54289 return Referrer(blink::WebStringToGURL(
290 request.HttpHeaderField(WebString::FromUTF8("Referer"))),
291 request.GetReferrerPolicy());
[email protected]44e55b012013-07-23 14:21:56292}
293
[email protected]c6bc20332014-02-28 18:30:39294// static
[email protected]65920f332014-03-04 21:14:18295WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32296 WebNavigationPolicy policy) {
297 switch (policy) {
Blink Reformat1c4d759e2017-04-09 16:34:54298 case blink::kWebNavigationPolicyIgnore:
nick3b04f322016-08-31 19:29:19299 return WindowOpenDisposition::IGNORE_ACTION;
Blink Reformat1c4d759e2017-04-09 16:34:54300 case blink::kWebNavigationPolicyDownload:
nick3b04f322016-08-31 19:29:19301 return WindowOpenDisposition::SAVE_TO_DISK;
Blink Reformat1c4d759e2017-04-09 16:34:54302 case blink::kWebNavigationPolicyCurrentTab:
nick3b04f322016-08-31 19:29:19303 return WindowOpenDisposition::CURRENT_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54304 case blink::kWebNavigationPolicyNewBackgroundTab:
nick3b04f322016-08-31 19:29:19305 return WindowOpenDisposition::NEW_BACKGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54306 case blink::kWebNavigationPolicyNewForegroundTab:
nick3b04f322016-08-31 19:29:19307 return WindowOpenDisposition::NEW_FOREGROUND_TAB;
Blink Reformat1c4d759e2017-04-09 16:34:54308 case blink::kWebNavigationPolicyNewWindow:
nick3b04f322016-08-31 19:29:19309 return WindowOpenDisposition::NEW_WINDOW;
Blink Reformat1c4d759e2017-04-09 16:34:54310 case blink::kWebNavigationPolicyNewPopup:
nick3b04f322016-08-31 19:29:19311 return WindowOpenDisposition::NEW_POPUP;
[email protected]48861e22013-01-09 00:27:32312 default:
313 NOTREACHED() << "Unexpected WebNavigationPolicy";
nick3b04f322016-08-31 19:29:19314 return WindowOpenDisposition::IGNORE_ACTION;
[email protected]48861e22013-01-09 00:27:32315 }
316}
317
[email protected]d8221b22013-05-23 05:35:43318// Returns true if the device scale is high enough that losing subpixel
319// antialiasing won't have a noticeable effect on text quality.
320static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
bokane6e68ae2017-03-24 00:54:44321#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
322 // On Android, we never have subpixel antialiasing. On Chrome OS we prefer to
323 // composite all scrollers so that we get animated overlay scrollbars.
[email protected]d8221b22013-05-23 05:35:43324 return true;
325#else
jdduke7d452b4a2015-08-19 21:25:21326 // 1.5 is a common touchscreen tablet device scale factor. For such
327 // devices main thread antialiasing is a heavy burden.
328 return device_scale_factor >= 1.5f;
[email protected]d8221b22013-05-23 05:35:43329#endif
[email protected]d8221b22013-05-23 05:35:43330}
331
danakj6e3bf8012014-12-16 18:27:53332static bool PreferCompositingToLCDText(CompositorDependencies* compositor_deps,
333 float device_scale_factor) {
avi83883c82014-12-23 00:08:49334 const base::CommandLine& command_line =
335 *base::CommandLine::ForCurrentProcess();
[email protected]b8ec1112014-08-17 20:09:10336 if (command_line.HasSwitch(switches::kDisablePreferCompositingToLCDText))
[email protected]fb854192013-02-06 01:30:04337 return false;
[email protected]b8ec1112014-08-17 20:09:10338 if (command_line.HasSwitch(switches::kEnablePreferCompositingToLCDText))
[email protected]fb854192013-02-06 01:30:04339 return true;
danakj6e3bf8012014-12-16 18:27:53340 if (!compositor_deps->IsLcdTextEnabled())
[email protected]10c19732014-08-18 19:39:23341 return true;
[email protected]d8221b22013-05-23 05:35:43342 return DeviceScaleEnsuresTextQuality(device_scale_factor);
343}
344
initial.commit09911bf2008-07-26 23:55:29345///////////////////////////////////////////////////////////////////////////////
346
[email protected]217690d2012-01-27 07:33:11347namespace {
348
[email protected]b3a97b52014-07-09 06:25:05349typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
350 const base::string16&,
351 UScriptCode);
352
353void SetStandardFontFamilyWrapper(WebSettings* settings,
354 const base::string16& font,
355 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54356 settings->SetStandardFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05357}
358
359void SetFixedFontFamilyWrapper(WebSettings* settings,
360 const base::string16& font,
361 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54362 settings->SetFixedFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05363}
364
365void SetSerifFontFamilyWrapper(WebSettings* settings,
366 const base::string16& font,
367 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54368 settings->SetSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05369}
370
371void SetSansSerifFontFamilyWrapper(WebSettings* settings,
372 const base::string16& font,
373 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54374 settings->SetSansSerifFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05375}
376
377void SetCursiveFontFamilyWrapper(WebSettings* settings,
378 const base::string16& font,
379 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54380 settings->SetCursiveFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05381}
382
383void SetFantasyFontFamilyWrapper(WebSettings* settings,
384 const base::string16& font,
385 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54386 settings->SetFantasyFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05387}
388
389void SetPictographFontFamilyWrapper(WebSettings* settings,
390 const base::string16& font,
391 UScriptCode script) {
Blink Reformat1c4d759e2017-04-09 16:34:54392 settings->SetPictographFontFamily(WebString::FromUTF16(font), script);
[email protected]b3a97b52014-07-09 06:25:05393}
394
395// If |scriptCode| is a member of a family of "similar" script codes, returns
396// the script code in that family that is used by WebKit for font selection
397// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
398// considered equivalent for the purposes of font selection. WebKit uses the
399// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
400// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
401// uses different scripts than the ones in Chrome pref names because the version
402// of ICU included on certain ports does not have some of the newer scripts. If
403// |scriptCode| is not a member of such a family, returns |scriptCode|.
404UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
405 switch (scriptCode) {
406 case USCRIPT_HIRAGANA:
407 case USCRIPT_KATAKANA:
408 case USCRIPT_JAPANESE:
409 return USCRIPT_KATAKANA_OR_HIRAGANA;
410 case USCRIPT_KOREAN:
411 return USCRIPT_HANGUL;
412 default:
413 return scriptCode;
414 }
415}
416
417void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
418 SetFontFamilyWrapper setter,
419 WebSettings* settings) {
420 for (ScriptFontFamilyMap::const_iterator it = map.begin(); it != map.end();
421 ++it) {
avi1023d012015-12-25 02:39:14422 int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
[email protected]b3a97b52014-07-09 06:25:05423 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
424 UScriptCode code = static_cast<UScriptCode>(script);
425 (*setter)(settings, it->second, GetScriptForWebSettings(code));
426 }
427 }
428}
429
wangxianzhu3bf39be52015-04-10 23:56:41430void ApplyBlinkSettings(const base::CommandLine& command_line,
431 WebSettings* settings) {
432 if (!command_line.HasSwitch(switches::kBlinkSettings))
433 return;
434
brettw26dab8f02015-08-08 00:28:47435 std::vector<std::string> blink_settings = base::SplitString(
436 command_line.GetSwitchValueASCII(switches::kBlinkSettings),
437 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
wangxianzhu3bf39be52015-04-10 23:56:41438 for (const std::string& setting : blink_settings) {
439 size_t pos = setting.find('=');
Blink Reformat1c4d759e2017-04-09 16:34:54440 settings->SetFromStrings(
441 blink::WebString::FromLatin1(setting.substr(0, pos)),
442 blink::WebString::FromLatin1(
wangxianzhu3bf39be52015-04-10 23:56:41443 pos == std::string::npos ? "" : setting.substr(pos + 1)));
444 }
445}
446
svartmetal751af1f92016-08-13 11:47:33447// This class represents promise which is robust to (will not be broken by)
448// |DidNotSwapReason::SWAP_FAILS| events.
449class AlwaysDrawSwapPromise : public cc::SwapPromise {
450 public:
451 explicit AlwaysDrawSwapPromise(const ui::LatencyInfo& latency_info)
452 : latency_info_(latency_info) {}
453
454 ~AlwaysDrawSwapPromise() override = default;
455
456 void DidActivate() override {}
457
danakj5e0a12b2017-09-25 17:26:49458 void WillSwap(viz::CompositorFrameMetadata* metadata) override {
svartmetal751af1f92016-08-13 11:47:33459 DCHECK(!latency_info_.terminated());
460 metadata->latency_info.push_back(latency_info_);
461 }
462
samanse7345c82016-12-16 02:51:16463 void DidSwap() override {}
464
svartmetal751af1f92016-08-13 11:47:33465 DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override {
466 return reason == DidNotSwapReason::SWAP_FAILS
467 ? DidNotSwapAction::KEEP_ACTIVE
468 : DidNotSwapAction::BREAK_PROMISE;
469 }
470
471 void OnCommit() override {}
472
473 int64_t TraceId() const override { return latency_info_.trace_id(); }
474
475 private:
476 ui::LatencyInfo latency_info_;
477};
478
scottmgde42fb92017-02-10 17:56:03479content::mojom::WindowContainerType WindowFeaturesToContainerType(
scottmg05324cb2017-02-09 23:46:04480 const blink::WebWindowFeatures& window_features) {
japhetbfc47892017-06-02 23:01:19481 if (window_features.background) {
482 if (window_features.persistent)
scottmgde42fb92017-02-10 17:56:03483 return content::mojom::WindowContainerType::PERSISTENT;
scottmg05324cb2017-02-09 23:46:04484 else
scottmgde42fb92017-02-10 17:56:03485 return content::mojom::WindowContainerType::BACKGROUND;
scottmg05324cb2017-02-09 23:46:04486 } else {
scottmgde42fb92017-02-10 17:56:03487 return content::mojom::WindowContainerType::NORMAL;
scottmg05324cb2017-02-09 23:46:04488 }
489}
490
[email protected]217690d2012-01-27 07:33:11491} // namespace
492
Hajime Hoshiabb3c8f2017-12-04 18:41:39493RenderViewImpl::RenderViewImpl(
494 CompositorDependencies* compositor_deps,
495 const mojom::CreateViewParams& params,
496 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
nick8331f8ad2016-11-15 20:42:45497 : RenderWidget(params.view_id,
498 compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54499 blink::kWebPopupTypeNone,
naskobd911332014-11-25 01:13:36500 params.initial_size.screen_info,
501 params.swapped_out,
502 params.hidden,
Hajime Hoshiabb3c8f2017-12-04 18:41:39503 params.never_visible,
504 task_runner),
naskobd911332014-11-25 01:13:36505 webkit_preferences_(params.web_preferences),
avif937e1d2014-11-02 18:13:07506 send_content_state_immediately_(false),
[email protected]3354d3e2010-06-10 19:53:02507 send_preferred_size_changes_(false),
[email protected]e75cb49e2009-01-05 23:13:21508 navigation_gesture_(NavigationGestureUnknown),
[email protected]3cc72b12010-03-18 23:03:00509 history_list_offset_(-1),
510 history_list_length_(0),
[email protected]7e9523b2014-03-25 03:02:42511 frames_in_progress_(0),
[email protected]3354d3e2010-06-10 19:53:02512 target_url_status_(TARGET_NONE),
[email protected]d42bf472014-06-14 01:49:38513 uses_temporary_zoom_level_(false),
[email protected]bbc8856d2013-06-14 10:37:04514#if defined(OS_ANDROID)
mdjones2ee41afd2016-10-27 16:50:20515 top_controls_constraints_(BROWSER_CONTROLS_STATE_BOTH),
[email protected]bbc8856d2013-06-14 10:37:04516#endif
mdjones2ee41afd2016-10-27 16:50:20517 browser_controls_shrink_blink_size_(false),
bokanc63441c2016-04-27 15:49:12518 top_controls_height_(0.f),
Matthew Jones7e156182017-07-21 22:21:33519 bottom_controls_height_(0.f),
lfg4fa48da2016-05-09 18:25:13520 webview_(nullptr),
wjmaclean64951902016-04-29 20:59:12521 page_zoom_level_(params.page_zoom_level),
nasko4c0feb62015-06-05 18:37:06522 main_render_frame_(nullptr),
dcheng3ce04b62015-10-26 23:30:55523 frame_widget_(nullptr),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28524 speech_recognition_dispatcher_(nullptr),
[email protected]20657a82012-08-21 20:23:03525#if defined(OS_ANDROID)
nickf7b38222016-11-22 21:59:35526 was_created_by_renderer_(false),
[email protected]a7564272013-04-19 14:24:46527#endif
[email protected]8a67aa352013-02-20 02:58:29528 enumeration_completion_id_(0),
changwand659e202016-06-13 02:39:12529 session_storage_namespace_id_(params.session_storage_namespace_id),
wjmaclean1d970622017-01-21 22:28:24530 weak_ptr_factory_(this) {
avi40b5be7a2016-03-03 21:13:44531 GetWidget()->set_owner_delegate(this);
[email protected]075366912013-02-18 07:13:24532}
533
nickf7b38222016-11-22 21:59:35534void RenderViewImpl::Initialize(
Balazs Engedyba034e72017-10-27 22:26:28535 mojom::CreateViewParamsPtr params,
nickf7b38222016-11-22 21:59:35536 const RenderWidget::ShowCallback& show_callback) {
537 bool was_created_by_renderer = !show_callback.is_null();
538#if defined(OS_ANDROID)
539 // TODO(sgurun): crbug.com/325351 Needed only for android webview's deprecated
540 // HandleNavigation codepath.
541 was_created_by_renderer_ = was_created_by_renderer;
542#endif
Balazs Engedyba034e72017-10-27 22:26:28543 display_mode_ = params->initial_size.display_mode;
[email protected]676126f72011-01-15 00:03:51544
Lukasz Anforowicz1c9509062017-12-06 00:38:17545 WebFrame* opener_frame =
546 RenderFrameImpl::ResolveOpener(params->opener_frame_route_id);
547
548 webview_ =
549 WebView::Create(this,
550 is_hidden() ? blink::mojom::PageVisibilityState::kHidden
551 : blink::mojom::PageVisibilityState::kVisible,
552 opener_frame ? opener_frame->View() : nullptr);
Blink Reformat1c4d759e2017-04-09 16:34:54553 RenderWidget::Init(show_callback, webview_->GetWidget());
[email protected]11fee2332011-03-29 20:36:35554
nasko4c0feb62015-06-05 18:37:06555 g_view_map.Get().insert(std::make_pair(webview(), this));
avia3dca182016-03-19 01:09:52556 g_routing_id_view_map.Get().insert(std::make_pair(GetRoutingID(), this));
nasko4c0feb62015-06-05 18:37:06557
avi83883c82014-12-23 00:08:49558 const base::CommandLine& command_line =
559 *base::CommandLine::ForCurrentProcess();
[email protected]20657a82012-08-21 20:23:03560
[email protected]27c521a2013-05-29 20:44:32561 if (command_line.HasSwitch(switches::kStatsCollectionController))
562 stats_collection_observer_.reset(new StatsCollectionObserver(this));
563
Blink Reformat1c4d759e2017-04-09 16:34:54564 webview()->SetDisplayMode(display_mode_);
565 webview()->GetSettings()->SetPreferCompositingToLCDTextEnabled(
dcheng0ff94cfc2016-03-15 21:50:51566 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_));
Blink Reformat1c4d759e2017-04-09 16:34:54567 webview()->GetSettings()->SetThreadedScrollingEnabled(
dcheng0ff94cfc2016-03-15 21:50:51568 !command_line.HasSwitch(switches::kDisableThreadedScrolling));
Blink Reformat1c4d759e2017-04-09 16:34:54569 webview()->SetShowFPSCounter(
dcheng0ff94cfc2016-03-15 21:50:51570 command_line.HasSwitch(cc::switches::kShowFPSCounter));
571
572 ApplyWebPreferencesInternal(webkit_preferences_, webview(), compositor_deps_);
573
574 if (switches::IsTouchDragDropEnabled())
Blink Reformat1c4d759e2017-04-09 16:34:54575 webview()->GetSettings()->SetTouchDragDropEnabled(true);
dcheng0ff94cfc2016-03-15 21:50:51576
Blink Reformat1c4d759e2017-04-09 16:34:54577 webview()->GetSettings()->SetBrowserSideNavigationEnabled(
arthursonzognic517fc32016-08-11 11:04:24578 IsBrowserSideNavigationEnabled());
579
dcheng0ff94cfc2016-03-15 21:50:51580 WebSettings::SelectionStrategyType selection_strategy =
Blink Reformat1c4d759e2017-04-09 16:34:54581 WebSettings::SelectionStrategyType::kCharacter;
dcheng0ff94cfc2016-03-15 21:50:51582 const std::string selection_strategy_str =
583 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
584 switches::kTouchTextSelectionStrategy);
585 if (selection_strategy_str == "direction")
Blink Reformat1c4d759e2017-04-09 16:34:54586 selection_strategy = WebSettings::SelectionStrategyType::kDirection;
587 webview()->GetSettings()->SetSelectionStrategy(selection_strategy);
dcheng0ff94cfc2016-03-15 21:50:51588
dtapuskaf65650b2016-05-13 17:21:34589 std::string passiveListenersDefault =
590 command_line.GetSwitchValueASCII(switches::kPassiveListenersDefault);
591 if (!passiveListenersDefault.empty()) {
592 WebSettings::PassiveEventListenerDefault passiveDefault =
Blink Reformat1c4d759e2017-04-09 16:34:54593 WebSettings::PassiveEventListenerDefault::kFalse;
dtapuskaacc2fb22016-07-06 23:26:23594 if (passiveListenersDefault == "true")
Blink Reformat1c4d759e2017-04-09 16:34:54595 passiveDefault = WebSettings::PassiveEventListenerDefault::kTrue;
dtapuskaf65650b2016-05-13 17:21:34596 else if (passiveListenersDefault == "forcealltrue")
Blink Reformat1c4d759e2017-04-09 16:34:54597 passiveDefault = WebSettings::PassiveEventListenerDefault::kForceAllTrue;
598 webview()->GetSettings()->SetPassiveEventListenerDefault(passiveDefault);
dtapuskaf65650b2016-05-13 17:21:34599 }
600
Blink Reformat1c4d759e2017-04-09 16:34:54601 ApplyBlinkSettings(command_line, webview()->GetSettings());
dcheng0ff94cfc2016-03-15 21:50:51602
Balazs Engedyba034e72017-10-27 22:26:28603 if (params->main_frame_routing_id != MSG_ROUTING_NONE) {
Ken Rockot26efbd62017-11-16 04:39:49604 CHECK(params->main_frame_interface_provider.is_valid());
605 service_manager::mojom::InterfaceProviderPtr main_frame_interface_provider(
606 std::move(params->main_frame_interface_provider));
dcheng3ce04b62015-10-26 23:30:55607 main_render_frame_ = RenderFrameImpl::CreateMainFrame(
Balazs Engedyba034e72017-10-27 22:26:28608 this, params->main_frame_routing_id,
Ken Rockot26efbd62017-11-16 04:39:49609 std::move(main_frame_interface_provider),
Balazs Engedyba034e72017-10-27 22:26:28610 params->main_frame_widget_routing_id, params->hidden, screen_info(),
611 compositor_deps_, opener_frame, params->devtools_main_frame_token,
612 params->replicated_frame_state);
dchengc5ef1a52015-08-26 20:58:30613 }
614
Daniel Chengd5e56ff2017-06-24 07:44:02615 // TODO(dcheng): Shouldn't these be mutually exclusive at this point? See
616 // https://crbug.com/720116 where the browser is apparently sending both
617 // routing IDs...
Balazs Engedyba034e72017-10-27 22:26:28618 if (params->proxy_routing_id != MSG_ROUTING_NONE) {
619 CHECK(params->swapped_out);
620 RenderFrameProxy::CreateFrameProxy(params->proxy_routing_id, GetRoutingID(),
nick3b5a21f2016-11-22 23:07:11621 opener_frame, MSG_ROUTING_NONE,
Balazs Engedyba034e72017-10-27 22:26:28622 params->replicated_frame_state);
nasko4c0feb62015-06-05 18:37:06623 }
624
nasko4c0feb62015-06-05 18:37:06625 if (main_render_frame_)
626 main_render_frame_->Initialize();
627
nickf7b38222016-11-22 21:59:35628 // If this RenderView's creation was initiated by an opener page in this
629 // process, (e.g. window.open()), we won't be visible until we ask the opener,
630 // via show_callback, to make us visible. Otherwise, we went through a
631 // browser-initiated creation, and show() won't be called.
632 if (!was_created_by_renderer)
[email protected]676126f72011-01-15 00:03:51633 did_show_ = true;
mfomitchev5ad034ec2015-04-24 21:57:27634
[email protected]c7c0d822014-04-16 20:19:49635 // TODO(davidben): Move this state from Blink into content.
Balazs Engedyba034e72017-10-27 22:26:28636 if (params->window_was_created_with_opener)
Blink Reformat1c4d759e2017-04-09 16:34:54637 webview()->SetOpenedByDOM();
[email protected]c7c0d822014-04-16 20:19:49638
dcheng0ff94cfc2016-03-15 21:50:51639 UpdateWebViewWithDeviceScaleFactor();
Balazs Engedyba034e72017-10-27 22:26:28640 OnSetRendererPrefs(params->renderer_preferences);
[email protected]34c61bd52011-05-02 19:38:33641
Balazs Engedyba034e72017-10-27 22:26:28642 if (!params->enable_auto_resize) {
643 OnResize(params->initial_size);
mkosiba58fa72f02014-11-12 01:21:36644 } else {
Balazs Engedyba034e72017-10-27 22:26:28645 OnEnableAutoResize(params->min_size, params->max_size);
mkosiba58fa72f02014-11-12 01:21:36646 }
647
dtapuska9ec1a912017-04-21 15:18:31648 idle_user_detector_.reset(new IdleUserDetector(this));
[email protected]1784b2f2011-11-24 10:53:48649
[email protected]e9ff79c2012-10-19 21:31:26650 GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44651
Balazs Engedyba034e72017-10-27 22:26:28652 page_zoom_level_ = params->page_zoom_level;
initial.commit09911bf2008-07-26 23:55:29653}
654
[email protected]310ebd6302011-10-10 19:06:28655RenderViewImpl::~RenderViewImpl() {
dcheng3ce04b62015-10-26 23:30:55656 DCHECK(!frame_widget_);
657
Lei Zhang88f23ba2017-10-27 05:56:26658 disambiguation_bitmaps_.clear();
[email protected]91a2aea2013-07-08 23:14:39659
[email protected]8ed1d3f2013-02-20 11:45:55660#if defined(OS_ANDROID)
davve17e025e12016-05-23 15:30:20661 // The date/time picker client is both a std::unique_ptr member of this class
662 // and a RenderViewObserver. Reset it to prevent double deletion.
[email protected]8ed1d3f2013-02-20 11:45:55663 date_time_picker_client_.reset();
664#endif
665
[email protected]60c42a8c72009-10-09 04:08:59666#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22667 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49668 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59669 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
670 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22671 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
672 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
673 it != routing_id_views->end(); ++it)
674 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59675#endif
[email protected]676126f72011-01-15 00:03:51676
dtapuska9ec1a912017-04-21 15:18:31677 idle_user_detector_.reset();
ericwilligers88e69742016-10-17 19:29:55678 for (auto& observer : observers_)
679 observer.RenderViewGone();
680 for (auto& observer : observers_)
681 observer.OnDestruct();
[email protected]60c42a8c72009-10-09 04:08:59682}
683
684/*static*/
[email protected]310ebd6302011-10-10 19:06:28685RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31686 ViewMap* views = g_view_map.Pointer();
687 ViewMap::iterator it = views->find(webview);
688 return it == views->end() ? NULL : it->second;
689}
690
691/*static*/
[email protected]180ef242013-11-07 06:50:46692RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28693 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31694}
695
696/*static*/
avi1023d012015-12-25 02:39:14697RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) {
[email protected]640e303c2012-12-05 01:36:07698 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
699 RoutingIDViewMap::iterator it = views->find(routing_id);
700 return it == views->end() ? NULL : it->second;
701}
702
703/*static*/
704RenderView* RenderView::FromRoutingID(int routing_id) {
705 return RenderViewImpl::FromRoutingID(routing_id);
706}
707
[email protected]f3a95312014-06-12 16:46:58708/* static */
jochen9c7b8f242015-06-01 15:32:02709size_t RenderView::GetRenderViewCount() {
[email protected]f3a95312014-06-12 16:46:58710 return g_view_map.Get().size();
711}
712
[email protected]640e303c2012-12-05 01:36:07713/*static*/
[email protected]e9ff79c2012-10-19 21:31:26714void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49715 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59716 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
717 if (!visitor->Visit(it->second))
718 return;
719 }
720}
721
722/*static*/
[email protected]b3a97b52014-07-09 06:25:05723void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
724 WebView* web_view) {
Blink Reformat1c4d759e2017-04-09 16:34:54725 WebSettings* settings = web_view->GetSettings();
[email protected]b3a97b52014-07-09 06:25:05726 ApplyFontsFromMap(prefs.standard_font_family_map,
727 SetStandardFontFamilyWrapper, settings);
728 ApplyFontsFromMap(prefs.fixed_font_family_map,
729 SetFixedFontFamilyWrapper, settings);
730 ApplyFontsFromMap(prefs.serif_font_family_map,
731 SetSerifFontFamilyWrapper, settings);
732 ApplyFontsFromMap(prefs.sans_serif_font_family_map,
733 SetSansSerifFontFamilyWrapper, settings);
734 ApplyFontsFromMap(prefs.cursive_font_family_map,
735 SetCursiveFontFamilyWrapper, settings);
736 ApplyFontsFromMap(prefs.fantasy_font_family_map,
737 SetFantasyFontFamilyWrapper, settings);
738 ApplyFontsFromMap(prefs.pictograph_font_family_map,
739 SetPictographFontFamilyWrapper, settings);
Blink Reformat1c4d759e2017-04-09 16:34:54740 settings->SetDefaultFontSize(prefs.default_font_size);
741 settings->SetDefaultFixedFontSize(prefs.default_fixed_font_size);
742 settings->SetMinimumFontSize(prefs.minimum_font_size);
743 settings->SetMinimumLogicalFontSize(prefs.minimum_logical_font_size);
744 settings->SetDefaultTextEncodingName(
745 WebString::FromASCII(prefs.default_encoding));
746 settings->SetJavaScriptEnabled(prefs.javascript_enabled);
747 settings->SetWebSecurityEnabled(prefs.web_security_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54748 settings->SetLoadsImagesAutomatically(prefs.loads_images_automatically);
749 settings->SetImagesEnabled(prefs.images_enabled);
750 settings->SetPluginsEnabled(prefs.plugins_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54751 settings->SetDOMPasteAllowed(prefs.dom_paste_enabled);
752 settings->SetTextAreasAreResizable(prefs.text_areas_are_resizable);
753 settings->SetAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
754 settings->SetDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
755 settings->SetJavaScriptCanAccessClipboard(
[email protected]b3a97b52014-07-09 06:25:05756 prefs.javascript_can_access_clipboard);
Blink Reformat1c4d759e2017-04-09 16:34:54757 WebRuntimeFeatures::EnableXSLT(prefs.xslt_enabled);
758 settings->SetXSSAuditorEnabled(prefs.xss_auditor_enabled);
759 settings->SetDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
Tarun Bansalabd3ef02017-11-03 15:19:20760 blink::WebNetworkStateNotifier::SetSaveDataEnabled(
Tarun Bansal73dd2ff82017-10-03 05:29:34761 prefs.data_saver_enabled &&
762 !base::FeatureList::IsEnabled(features::kDataSaverHoldback));
Blink Reformat1c4d759e2017-04-09 16:34:54763 settings->SetLocalStorageEnabled(prefs.local_storage_enabled);
764 settings->SetSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
765 WebRuntimeFeatures::EnableDatabase(prefs.databases_enabled);
766 settings->SetOfflineWebApplicationCacheEnabled(
[email protected]b3a97b52014-07-09 06:25:05767 prefs.application_cache_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54768 settings->SetHistoryEntryRequiresUserGesture(
japhet5018fe62016-09-14 19:14:04769 prefs.history_entry_requires_user_gesture);
Blink Reformat1c4d759e2017-04-09 16:34:54770 settings->SetHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
771 settings->SetCookieEnabled(prefs.cookie_enabled);
772 settings->SetNavigateOnDragDrop(prefs.navigate_on_drag_drop);
[email protected]b3a97b52014-07-09 06:25:05773
[email protected]b3a97b52014-07-09 06:25:05774 // By default, allow_universal_access_from_file_urls is set to false and thus
775 // we mitigate attacks from local HTML files by not granting file:// URLs
776 // universal access. Only test shell will enable this.
Blink Reformat1c4d759e2017-04-09 16:34:54777 settings->SetAllowUniversalAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05778 prefs.allow_universal_access_from_file_urls);
Blink Reformat1c4d759e2017-04-09 16:34:54779 settings->SetAllowFileAccessFromFileURLs(
[email protected]b3a97b52014-07-09 06:25:05780 prefs.allow_file_access_from_file_urls);
781
Zhenyao Moa3fda9972017-09-16 01:34:40782 settings->SetWebGL1Enabled(prefs.webgl1_enabled);
783 settings->SetWebGL2Enabled(prefs.webgl2_enabled);
[email protected]b3a97b52014-07-09 06:25:05784
[email protected]b3a97b52014-07-09 06:25:05785 // Enable WebGL errors to the JS console if requested.
Blink Reformat1c4d759e2017-04-09 16:34:54786 settings->SetWebGLErrorsToConsoleEnabled(
[email protected]b3a97b52014-07-09 06:25:05787 prefs.webgl_errors_to_console_enabled);
788
789 // Uses the mock theme engine for scrollbars.
Blink Reformat1c4d759e2017-04-09 16:34:54790 settings->SetMockScrollbarsEnabled(prefs.mock_scrollbars_enabled);
[email protected]b3a97b52014-07-09 06:25:05791
Blink Reformat1c4d759e2017-04-09 16:34:54792 settings->SetHideScrollbars(prefs.hide_scrollbars);
eseckler61ff9142016-09-23 22:57:59793
[email protected]b3a97b52014-07-09 06:25:05794 // Enable gpu-accelerated 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54795 WebRuntimeFeatures::EnableAccelerated2dCanvas(
junov524668f22016-08-08 20:16:52796 prefs.accelerated_2d_canvas_enabled);
[email protected]b3a97b52014-07-09 06:25:05797
Blink Reformat1c4d759e2017-04-09 16:34:54798 settings->SetMinimumAccelerated2dCanvasSize(
[email protected]b3a97b52014-07-09 06:25:05799 prefs.minimum_accelerated_2d_canvas_size);
800
801 // Disable antialiasing for 2d canvas if requested on the command line.
Blink Reformat1c4d759e2017-04-09 16:34:54802 settings->SetAntialiased2dCanvasEnabled(
[email protected]b3a97b52014-07-09 06:25:05803 !prefs.antialiased_2d_canvas_disabled);
804
zakerinasab20ebca02016-09-27 14:22:34805 // Disable antialiasing of clips for 2d canvas if requested on the command
robertphillipse25137b2014-10-20 13:44:34806 // line.
Blink Reformat1c4d759e2017-04-09 16:34:54807 settings->SetAntialiasedClips2dCanvasEnabled(
robertphillipse25137b2014-10-20 13:44:34808 prefs.antialiased_clips_2d_canvas_enabled);
809
[email protected]b3a97b52014-07-09 06:25:05810 // Set MSAA sample count for 2d canvas if requested on the command line (or
811 // default value if not).
Blink Reformat1c4d759e2017-04-09 16:34:54812 settings->SetAccelerated2dCanvasMSAASampleCount(
[email protected]b3a97b52014-07-09 06:25:05813 prefs.accelerated_2d_canvas_msaa_sample_count);
814
[email protected]b3a97b52014-07-09 06:25:05815 // Tabs to link is not part of the settings. WebCore calls
816 // ChromeClient::tabsToLinks which is part of the glue code.
Blink Reformat1c4d759e2017-04-09 16:34:54817 web_view->SetTabsToLinks(prefs.tabs_to_links);
[email protected]b3a97b52014-07-09 06:25:05818
Blink Reformat1c4d759e2017-04-09 16:34:54819 settings->SetAllowRunningOfInsecureContent(
[email protected]b3a97b52014-07-09 06:25:05820 prefs.allow_running_insecure_content);
Blink Reformat1c4d759e2017-04-09 16:34:54821 settings->SetDisableReadingFromCanvas(prefs.disable_reading_from_canvas);
822 settings->SetStrictMixedContentChecking(prefs.strict_mixed_content_checking);
mkwst2384c8222015-07-30 07:26:47823
Blink Reformat1c4d759e2017-04-09 16:34:54824 settings->SetStrictlyBlockBlockableMixedContent(
mkwst2384c8222015-07-30 07:26:47825 prefs.strictly_block_blockable_mixed_content);
826
Blink Reformat1c4d759e2017-04-09 16:34:54827 settings->SetStrictMixedContentCheckingForPlugin(
mkwst0d233e52015-08-10 09:33:14828 prefs.block_mixed_plugin_content);
829
Blink Reformat1c4d759e2017-04-09 16:34:54830 settings->SetStrictPowerfulFeatureRestrictions(
mkwst673a452f2015-01-10 14:41:50831 prefs.strict_powerful_feature_restrictions);
Blink Reformat1c4d759e2017-04-09 16:34:54832 settings->SetAllowGeolocationOnInsecureOrigins(
jww9d4ca2d2016-01-19 20:58:59833 prefs.allow_geolocation_on_insecure_origins);
Blink Reformat1c4d759e2017-04-09 16:34:54834 settings->SetPasswordEchoEnabled(prefs.password_echo_enabled);
835 settings->SetShouldPrintBackgrounds(prefs.should_print_backgrounds);
836 settings->SetShouldClearDocumentBackground(
[email protected]b3a97b52014-07-09 06:25:05837 prefs.should_clear_document_background);
Blink Reformat1c4d759e2017-04-09 16:34:54838 settings->SetEnableScrollAnimator(prefs.enable_scroll_animator);
[email protected]b3a97b52014-07-09 06:25:05839
Blink Reformat1c4d759e2017-04-09 16:34:54840 WebRuntimeFeatures::EnableTouchEventFeatureDetection(
sunyunjiafa6a8afc2016-12-09 04:25:47841 prefs.touch_event_feature_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54842 settings->SetMaxTouchPoints(prefs.pointer_events_max_touch_points);
843 settings->SetAvailablePointerTypes(prefs.available_pointer_types);
844 settings->SetPrimaryPointerType(
nzolghadrc0d1663c2015-11-26 21:15:24845 static_cast<blink::PointerType>(prefs.primary_pointer_type));
Blink Reformat1c4d759e2017-04-09 16:34:54846 settings->SetAvailableHoverTypes(prefs.available_hover_types);
847 settings->SetPrimaryHoverType(
nzolghadrc0d1663c2015-11-26 21:15:24848 static_cast<blink::HoverType>(prefs.primary_hover_type));
Blink Reformat1c4d759e2017-04-09 16:34:54849 settings->SetEnableTouchAdjustment(prefs.touch_adjustment_enabled);
Dave Tapuskaa59fdb62017-08-23 16:28:27850 settings->SetBarrelButtonForDragEnabled(prefs.barrel_button_for_drag_enabled);
[email protected]b3a97b52014-07-09 06:25:05851
Blink Reformat1c4d759e2017-04-09 16:34:54852 settings->SetShouldRespectImageOrientation(
[email protected]b3a97b52014-07-09 06:25:05853 prefs.should_respect_image_orientation);
854
Blink Reformat1c4d759e2017-04-09 16:34:54855 settings->SetEditingBehavior(
[email protected]b3a97b52014-07-09 06:25:05856 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
857
Blink Reformat1c4d759e2017-04-09 16:34:54858 settings->SetSupportsMultipleWindows(prefs.supports_multiple_windows);
[email protected]b3a97b52014-07-09 06:25:05859
Blink Reformat1c4d759e2017-04-09 16:34:54860 settings->SetMainFrameClipsContent(!prefs.record_whole_document);
khushalsagar2da2b232016-03-23 22:11:35861
Blink Reformat1c4d759e2017-04-09 16:34:54862 settings->SetSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
[email protected]b3a97b52014-07-09 06:25:05863
Blink Reformat1c4d759e2017-04-09 16:34:54864 settings->SetSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
[email protected]b3a97b52014-07-09 06:25:05865
Blink Reformat1c4d759e2017-04-09 16:34:54866 settings->SetSelectionIncludesAltImageText(true);
[email protected]b3a97b52014-07-09 06:25:05867
Blink Reformat1c4d759e2017-04-09 16:34:54868 settings->SetV8CacheOptions(
[email protected]35103c02014-08-12 15:08:47869 static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options));
870
Blink Reformat1c4d759e2017-04-09 16:34:54871 settings->SetImageAnimationPolicy(
je_julie.kim7fbb5a1a2015-02-09 17:26:05872 static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy));
873
Blink Reformat1c4d759e2017-04-09 16:34:54874 settings->SetPresentationRequiresUserGesture(
zqzhang1215ad422016-02-10 13:27:22875 prefs.user_gesture_required_for_presentation);
876
Blink Reformat1c4d759e2017-04-09 16:34:54877 settings->SetTextTrackMarginPercentage(prefs.text_track_margin_percentage);
halliwell4002be42016-03-18 18:33:40878
dcheng5ae8ca362015-02-05 04:03:47879 // Needs to happen before setIgnoreVIewportTagScaleLimits below.
Blink Reformat1c4d759e2017-04-09 16:34:54880 web_view->SetDefaultPageScaleLimits(prefs.default_minimum_page_scale_factor,
881 prefs.default_maximum_page_scale_factor);
dcheng5ae8ca362015-02-05 04:03:47882
Nate Chapin9638e7102017-09-20 22:11:01883 settings->SetSavePreviousDocumentResources(
884 static_cast<WebSettings::SavePreviousDocumentResources>(
885 prefs.save_previous_document_resources));
886
[email protected]b3a97b52014-07-09 06:25:05887#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:54888 settings->SetAllowCustomScrollbarInMainFrame(false);
889 settings->SetTextAutosizingEnabled(prefs.text_autosizing_enabled);
890 settings->SetAccessibilityFontScaleFactor(prefs.font_scale_factor);
891 settings->SetDeviceScaleAdjustment(prefs.device_scale_adjustment);
892 settings->SetFullscreenSupported(prefs.fullscreen_supported);
893 web_view->SetIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
894 settings->SetAutoZoomFocusedNodeToLegibleScale(true);
895 settings->SetDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54896 settings->SetMediaPlaybackGestureWhitelistScope(
897 blink::WebString::FromUTF8(prefs.media_playback_gesture_whitelist_scope));
898 settings->SetDefaultVideoPosterURL(
899 WebString::FromASCII(prefs.default_video_poster_url.spec()));
900 settings->SetSupportDeprecatedTargetDensityDPI(
[email protected]b3a97b52014-07-09 06:25:05901 prefs.support_deprecated_target_density_dpi);
Blink Reformat1c4d759e2017-04-09 16:34:54902 settings->SetUseLegacyBackgroundSizeShorthandBehavior(
[email protected]b3a97b52014-07-09 06:25:05903 prefs.use_legacy_background_size_shorthand_behavior);
Blink Reformat1c4d759e2017-04-09 16:34:54904 settings->SetWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
905 settings->SetUseWideViewport(prefs.use_wide_viewport);
906 settings->SetForceZeroLayoutHeight(prefs.force_zero_layout_height);
907 settings->SetViewportMetaLayoutSizeQuirk(
[email protected]b3a97b52014-07-09 06:25:05908 prefs.viewport_meta_layout_size_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54909 settings->SetViewportMetaMergeContentQuirk(
[email protected]b3a97b52014-07-09 06:25:05910 prefs.viewport_meta_merge_content_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54911 settings->SetViewportMetaNonUserScalableQuirk(
[email protected]b3a97b52014-07-09 06:25:05912 prefs.viewport_meta_non_user_scalable_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54913 settings->SetViewportMetaZeroValuesQuirk(
[email protected]b3a97b52014-07-09 06:25:05914 prefs.viewport_meta_zero_values_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54915 settings->SetClobberUserAgentInitialScaleQuirk(
[email protected]b3a97b52014-07-09 06:25:05916 prefs.clobber_user_agent_initial_scale_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54917 settings->SetIgnoreMainFrameOverflowHiddenQuirk(
[email protected]b3a97b52014-07-09 06:25:05918 prefs.ignore_main_frame_overflow_hidden_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54919 settings->SetReportScreenSizeInPhysicalPixelsQuirk(
[email protected]b3a97b52014-07-09 06:25:05920 prefs.report_screen_size_in_physical_pixels_quirk);
Blink Reformat1c4d759e2017-04-09 16:34:54921 settings->SetShouldReuseGlobalForUnownedMainFrame(
boliu1a00f262016-04-06 19:08:46922 prefs.resue_global_for_unowned_main_frame);
Blink Reformat1c4d759e2017-04-09 16:34:54923 settings->SetProgressBarCompletion(
japhet98e9bd82016-06-28 23:48:45924 static_cast<WebSettings::ProgressBarCompletion>(
925 prefs.progress_bar_completion));
Blink Reformat1c4d759e2017-04-09 16:34:54926 settings->SetPreferHiddenVolumeControls(true);
927 settings->SetSpellCheckEnabledByDefault(prefs.spellcheck_enabled_by_default);
dalecurtiscd971252016-09-21 16:09:00928
aeliase678aa42017-04-14 22:41:04929 // Force preload=none and disable autoplay on older Android
dalecurtiscd971252016-09-21 16:09:00930 // platforms because their media pipelines are not stable enough to handle
931 // concurrent elements. See http://crbug.com/612909, http://crbug.com/622826.
aeliase678aa42017-04-14 22:41:04932 const bool is_jelly_bean =
dalecurtiscd971252016-09-21 16:09:00933 base::android::BuildInfo::GetInstance()->sdk_int() <=
aeliase678aa42017-04-14 22:41:04934 base::android::SDK_VERSION_JELLY_BEAN_MR2;
935 settings->SetForcePreloadNoneForMediaElements(is_jelly_bean);
mlamouri1d266bf2016-12-05 17:42:36936
Blink Reformat1c4d759e2017-04-09 16:34:54937 WebRuntimeFeatures::EnableVideoFullscreenOrientationLock(
mlamouri1d266bf2016-12-05 17:42:36938 prefs.video_fullscreen_orientation_lock_enabled);
johnme913ee5f2017-04-28 21:36:16939 WebRuntimeFeatures::EnableVideoRotateToFullscreen(
940 prefs.video_rotate_to_fullscreen_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54941 WebRuntimeFeatures::EnableVideoFullscreenDetection(
zqzhang93e959d12017-03-16 13:10:20942 prefs.video_fullscreen_detection_enabled);
Blink Reformat1c4d759e2017-04-09 16:34:54943 settings->SetEmbeddedMediaExperienceEnabled(
shaktisahuf97f7532017-02-24 22:46:13944 prefs.embedded_media_experience_enabled);
vollick8921b242017-05-25 02:48:15945 settings->SetPagePopupsSuppressed(prefs.page_popups_suppressed);
khushalsagarc5447db22017-08-22 17:53:01946 settings->SetMediaDownloadInProductHelpEnabled(
947 prefs.enable_media_download_in_product_help);
Blink Reformat1c4d759e2017-04-09 16:34:54948 settings->SetDoNotUpdateSelectionOnMutatingSelectionRange(
changwane54ccdb92017-04-05 19:20:54949 prefs.do_not_update_selection_on_mutating_selection_range);
Noel Gordonf311a842017-07-27 00:10:07950 WebRuntimeFeatures::EnableCSSHexAlphaColor(prefs.css_hex_alpha_color_enabled);
Tobias Sargeant416174f2017-09-01 01:18:09951 WebRuntimeFeatures::EnableScrollTopLeftInterop(
952 prefs.scroll_top_left_interop_enabled);
zqzhangdf72ed082016-12-08 16:07:55953#endif // defined(OS_ANDROID)
liberato9e934892016-05-03 19:00:27954
mlamouri55a0543c2017-05-11 10:34:07955 switch (prefs.autoplay_policy) {
956 case AutoplayPolicy::kNoUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28957 settings->SetAutoplayPolicy(
958 WebSettings::AutoplayPolicy::kNoUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07959 break;
960 case AutoplayPolicy::kUserGestureRequired:
mlamouri276a6f32017-05-12 09:24:28961 settings->SetAutoplayPolicy(
962 WebSettings::AutoplayPolicy::kUserGestureRequired);
mlamouri55a0543c2017-05-11 10:34:07963 break;
964 case AutoplayPolicy::kUserGestureRequiredForCrossOrigin:
mlamouri276a6f32017-05-12 09:24:28965 settings->SetAutoplayPolicy(
966 WebSettings::AutoplayPolicy::kUserGestureRequiredForCrossOrigin);
mlamouri55a0543c2017-05-11 10:34:07967 break;
mlamouri431bb4e2017-06-06 08:54:24968 case AutoplayPolicy::kDocumentUserActivationRequired:
969 settings->SetAutoplayPolicy(
970 WebSettings::AutoplayPolicy::kDocumentUserActivationRequired);
971 break;
mlamouri55a0543c2017-05-11 10:34:07972 }
973
Blink Reformat1c4d759e2017-04-09 16:34:54974 settings->SetViewportEnabled(prefs.viewport_enabled);
975 settings->SetViewportMetaEnabled(prefs.viewport_meta_enabled);
976 settings->SetShrinksViewportContentToFit(
977 prefs.shrinks_viewport_contents_to_fit);
978 settings->SetViewportStyle(
alokp5d566962016-04-19 00:54:16979 static_cast<blink::WebViewportStyle>(prefs.viewport_style));
980
Blink Reformat1c4d759e2017-04-09 16:34:54981 settings->SetLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
982 settings->SetMainFrameResizesAreOrientationChanges(
yoava1a508b42015-10-20 12:03:21983 prefs.main_frame_resizes_are_orientation_changes);
984
Blink Reformat1c4d759e2017-04-09 16:34:54985 settings->SetUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
jinho.bang8f11ffa2014-12-04 06:03:03986
Blink Reformat1c4d759e2017-04-09 16:34:54987 settings->SetShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up);
988 settings->SetAlwaysShowContextMenuOnTouch(
amaralp547e4192016-06-03 19:17:35989 prefs.always_show_context_menu_on_touch);
ccameron2fd70de72015-02-19 00:40:40990
Blink Reformat1c4d759e2017-04-09 16:34:54991 settings->SetHideDownloadUI(prefs.hide_download_ui);
992 WebRuntimeFeatures::EnableBackgroundVideoTrackOptimization(
avayvod39c102402016-11-23 21:43:13993 prefs.background_video_track_optimization_enabled);
avayvod232757942017-04-29 04:12:34994 WebRuntimeFeatures::EnableNewRemotePlaybackPipeline(
995 base::FeatureList::IsEnabled(media::kNewRemotePlaybackPipeline));
qinmin72e8bd02016-10-21 19:35:37996
Blink Reformat1c4d759e2017-04-09 16:34:54997 settings->SetPresentationReceiver(prefs.presentation_receiver);
mlamouri57359d912016-11-29 20:11:50998
Blink Reformat1c4d759e2017-04-09 16:34:54999 settings->SetMediaControlsEnabled(prefs.media_controls_enabled);
mlamouri5cd9ae82017-02-18 11:05:091000
ccameron2fd70de72015-02-19 00:40:401001#if defined(OS_MACOSX)
Blink Reformat1c4d759e2017-04-09 16:34:541002 settings->SetDoubleTapToZoomEnabled(true);
1003 web_view->SetMaximumLegibleScale(prefs.default_maximum_page_scale_factor);
ccameron2fd70de72015-02-19 00:40:401004#endif
sunyunjia87f287b2016-09-09 00:38:131005
1006#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:541007 WebRuntimeFeatures::EnableMiddleClickAutoscroll(true);
sunyunjia87f287b2016-09-09 00:38:131008#endif
[email protected]b3a97b52014-07-09 06:25:051009}
1010
1011/*static*/
nickf7b38222016-11-22 21:59:351012RenderViewImpl* RenderViewImpl::Create(
1013 CompositorDependencies* compositor_deps,
Balazs Engedyba034e72017-10-27 22:26:281014 mojom::CreateViewParamsPtr params,
Hajime Hoshiabb3c8f2017-12-04 18:41:391015 const RenderWidget::ShowCallback& show_callback,
1016 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Balazs Engedyba034e72017-10-27 22:26:281017 DCHECK(params->view_id != MSG_ROUTING_NONE);
Lei Zhang88f23ba2017-10-27 05:56:261018 RenderViewImpl* render_view;
[email protected]8d41d7612012-11-14 20:32:191019 if (g_create_render_view_impl)
Balazs Engedyba034e72017-10-27 22:26:281020 render_view = g_create_render_view_impl(compositor_deps, *params);
[email protected]075366912013-02-18 07:13:241021 else
Hajime Hoshiabb3c8f2017-12-04 18:41:391022 render_view = new RenderViewImpl(compositor_deps, *params, task_runner);
[email protected]0287e762014-04-11 13:07:581023
Balazs Engedyba034e72017-10-27 22:26:281024 render_view->Initialize(std::move(params), show_callback);
[email protected]075366912013-02-18 07:13:241025 return render_view;
[email protected]8d41d7612012-11-14 20:32:191026}
1027
1028// static
dcheng35d31c112015-07-22 00:17:361029void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
1030 *create_render_view_impl)(CompositorDependencies* compositor_deps,
rockot067ca55f2016-09-30 22:00:151031 const mojom::CreateViewParams&)) {
[email protected]8d41d7612012-11-14 20:32:191032 CHECK(!g_create_render_view_impl);
1033 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291034}
1035
[email protected]310ebd6302011-10-10 19:06:281036void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511037 observers_.AddObserver(observer);
1038}
1039
[email protected]310ebd6302011-10-10 19:06:281040void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1041 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511042 observers_.RemoveObserver(observer);
1043}
1044
[email protected]180ef242013-11-07 06:50:461045blink::WebView* RenderViewImpl::webview() const {
lfg4fa48da2016-05-09 18:25:131046 return webview_;
[email protected]4d51d5bf2010-07-26 18:48:261047}
1048
brettw4b461082016-11-19 18:55:161049#if BUILDFLAG(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:571050
[email protected]784ea1ab2010-09-18 00:02:341051#if defined(OS_MACOSX)
[email protected]7411a3c2014-08-15 05:20:191052void RenderViewImpl::OnGetRenderedText() {
1053 if (!webview())
1054 return;
dglazkov03223492016-02-08 22:16:031055
Blink Reformat1c4d759e2017-04-09 16:34:541056 if (!webview()->MainFrame()->IsWebLocalFrame())
dglazkov03223492016-02-08 22:16:031057 return;
1058
[email protected]7411a3c2014-08-15 05:20:191059 // Get rendered text from WebLocalFrame.
1060 // TODO: Currently IPC truncates any data that has a
1061 // size > kMaximumMessageSize. May be split the text into smaller chunks and
1062 // send back using multiple IPC. See http://crbug.com/393444.
1063 static const size_t kMaximumMessageSize = 8 * 1024 * 1024;
dglazkov03223492016-02-08 22:16:031064 // TODO(dglazkov): Using this API is wrong. It's not OOPIF-compatible and
1065 // sends text in the wrong order. See http://crbug.com/584798.
1066 // TODO(dglazkov): WebFrameContentDumper should only be used for
1067 // testing purposes. See http://crbug.com/585164.
1068 std::string text =
Blink Reformat1c4d759e2017-04-09 16:34:541069 WebFrameContentDumper::DumpWebViewAsText(webview(), kMaximumMessageSize)
1070 .Utf8();
[email protected]7411a3c2014-08-15 05:20:191071
avia3dca182016-03-19 01:09:521072 Send(new ViewMsg_GetRenderedTextCompleted(GetRoutingID(), text));
[email protected]7411a3c2014-08-15 05:20:191073}
[email protected]a80af12e2013-08-07 23:36:131074#endif // defined(OS_MACOSX)
1075
1076#endif // ENABLE_PLUGINS
1077
fsamuel72464894f2015-12-15 06:59:311078// RenderWidgetInputHandlerDelegate -----------------------------------------
1079
avid7d6b2e2016-03-04 19:41:171080bool RenderViewImpl::RenderWidgetWillHandleMouseEvent(
1081 const blink::WebMouseEvent& event) {
fsamuel72464894f2015-12-15 06:59:311082 // If the mouse is locked, only the current owner of the mouse lock can
1083 // process mouse events.
1084 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
1085}
1086
1087// IPC::Listener implementation ----------------------------------------------
1088
[email protected]310ebd6302011-10-10 19:06:281089bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281090 WebFrame* main_frame = webview() ? webview()->MainFrame() : nullptr;
Avi Drissmanb5f8e242017-12-12 05:21:561091 if (main_frame) {
1092 GURL active_url;
1093 if (main_frame->IsWebLocalFrame())
1094 active_url = main_frame->ToWebLocalFrame()->GetDocument().Url();
lukaszabedb4b22017-06-23 00:00:131095 GetContentClient()->SetActiveURL(
Avi Drissmanb5f8e242017-12-12 05:21:561096 active_url, main_frame->Top()->GetSecurityOrigin().ToString().Utf8());
1097 }
[email protected]f8b6b6f2009-03-10 16:48:261098
naskoc6edf7e2015-10-16 01:48:451099 // Input IPC messages must not be processed if the RenderView is in
1100 // swapped out state.
dtapuska1b0fcc322016-10-28 18:08:281101 if (is_swapped_out_ &&
1102 IPC_MESSAGE_ID_CLASS(message.type()) == InputMsgStart) {
dtapuska1b0fcc322016-10-28 18:08:281103 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
1104 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnDiscardInputEvent)
1105 IPC_END_MESSAGE_MAP()
naskoc6edf7e2015-10-16 01:48:451106 return false;
dtapuska1b0fcc322016-10-28 18:08:281107 }
naskoc6edf7e2015-10-16 01:48:451108
dchenga2d442c22016-10-13 15:39:211109 for (auto& observer : observers_) {
1110 if (observer.OnMessageReceived(message))
[email protected]676126f72011-01-15 00:03:511111 return true;
dchenga2d442c22016-10-13 15:39:211112 }
[email protected]b2abac72009-02-26 12:39:281113
[email protected]a95986a82010-12-24 06:19:281114 bool handled = true;
[email protected]e44d1342014-05-16 21:29:331115 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
mcnee432e47d2015-11-09 19:37:461116 IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale)
initial.commit09911bf2008-07-26 23:55:291117 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291118 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1119 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]600ea402011-04-12 00:01:511120 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
1121 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:291122 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
[email protected]30f75e62009-02-25 22:01:001123 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]61f91832014-05-13 01:24:421124 IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque, OnSetBackgroundOpaque)
[email protected]ab32b16c2009-10-16 14:57:251125 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1126 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:471127 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:341128 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
Fady Samuel69b33b52017-11-08 22:01:521129 IPC_MESSAGE_HANDLER(ViewMsg_SetLocalSurfaceIdForAutoResize,
1130 OnSetLocalSurfaceIdForAutoResize)
[email protected]cda45c02010-02-25 19:28:101131 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1132 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511133 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:561134 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:361135 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:341136 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]cb189e062014-04-23 00:57:011137 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupBitmap,
1138 OnReleaseDisambiguationPopupBitmap)
aelias1b55156e52017-04-01 00:46:051139 IPC_MESSAGE_HANDLER(ViewMsg_ResolveTapDisambiguation,
1140 OnResolveTapDisambiguation)
[email protected]506563d2014-06-23 12:22:411141 IPC_MESSAGE_HANDLER(ViewMsg_ForceRedraw, OnForceRedraw)
[email protected]4dda6a6c2014-05-17 15:35:041142 IPC_MESSAGE_HANDLER(ViewMsg_SelectWordAroundCaret, OnSelectWordAroundCaret)
wjmaclean64951902016-04-29 20:59:121143
1144 // Page messages.
lfgdb5c4ed2016-03-04 23:09:071145 IPC_MESSAGE_HANDLER(PageMsg_UpdateWindowScreenRect,
1146 OnUpdateWindowScreenRect)
wjmaclean64951902016-04-29 20:59:121147 IPC_MESSAGE_HANDLER(PageMsg_SetZoomLevel, OnSetZoomLevel)
lfg717154072016-06-30 15:04:161148 IPC_MESSAGE_HANDLER(PageMsg_WasHidden, OnPageWasHidden)
1149 IPC_MESSAGE_HANDLER(PageMsg_WasShown, OnPageWasShown)
alexmos136fd6e62016-08-15 20:58:411150 IPC_MESSAGE_HANDLER(PageMsg_SetHistoryOffsetAndLength,
1151 OnSetHistoryOffsetAndLength)
altimind8bd26c2016-11-04 11:44:541152 IPC_MESSAGE_HANDLER(PageMsg_AudioStateChanged, OnAudioStateChanged)
lfg8d649cc2017-04-28 18:04:301153 IPC_MESSAGE_HANDLER(PageMsg_UpdateScreenInfo, OnUpdateScreenInfo)
lfg717154072016-06-30 15:04:161154
[email protected]55750b32012-09-21 14:05:031155#if defined(OS_ANDROID)
mdjones2ee41afd2016-10-27 16:50:201156 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserControlsState,
1157 OnUpdateBrowserControlsState)
[email protected]55750b32012-09-21 14:05:031158#elif defined(OS_MACOSX)
[email protected]7411a3c2014-08-15 05:20:191159 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedText,
1160 OnGetRenderedText)
naskoc288745f2015-05-01 22:54:211161 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]55750b32012-09-21 14:05:031162#endif
[email protected]a794f3a2013-10-30 17:00:321163 // Adding a new message? Add platform independent ones first, then put the
1164 // platform specific ones at the end.
[email protected]9e1ad4b2011-08-14 16:49:191165
initial.commit09911bf2008-07-26 23:55:291166 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281167 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291168 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401169
[email protected]a95986a82010-12-24 06:19:281170 return handled;
initial.commit09911bf2008-07-26 23:55:291171}
1172
[email protected]4dda6a6c2014-05-17 15:35:041173void RenderViewImpl::OnSelectWordAroundCaret() {
donnd701cc202017-05-17 23:11:201174 // Set default values for the ACK
1175 bool did_select = false;
1176 int start_adjust = 0;
1177 int end_adjust = 0;
[email protected]4dda6a6c2014-05-17 15:35:041178
donnd701cc202017-05-17 23:11:201179 if (webview()) {
1180 WebLocalFrame* focused_frame = GetWebView()->FocusedFrame();
1181 if (focused_frame) {
1182 input_handler_->set_handling_input_event(true);
1183 blink::WebRange initial_range = focused_frame->SelectionRange();
donndbde109ff2017-05-26 20:20:011184 if (!initial_range.IsNull())
1185 did_select = focused_frame->SelectWordAroundCaret();
donnd701cc202017-05-17 23:11:201186 if (did_select) {
1187 blink::WebRange adjusted_range = focused_frame->SelectionRange();
1188 start_adjust =
1189 adjusted_range.StartOffset() - initial_range.StartOffset();
1190 end_adjust = adjusted_range.EndOffset() - initial_range.EndOffset();
1191 }
1192 input_handler_->set_handling_input_event(false);
1193 }
1194 }
1195 Send(new ViewHostMsg_SelectWordAroundCaretAck(GetRoutingID(), did_select,
1196 start_adjust, end_adjust));
[email protected]4dda6a6c2014-05-17 15:35:041197}
1198
[email protected]310ebd6302011-10-10 19:06:281199void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291200 // Check if there is a targeturl waiting to be sent.
avi450ce00e2014-09-24 01:58:521201 if (target_url_status_ == TARGET_PENDING)
avia3dca182016-03-19 01:09:521202 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), pending_target_url_));
initial.commit09911bf2008-07-26 23:55:291203
1204 target_url_status_ = TARGET_NONE;
1205}
1206
avi2b177592014-12-10 02:08:021207void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset,
1208 int history_length) {
1209 DCHECK_GE(history_offset, -1);
[email protected]e1ed5a12012-08-08 19:57:441210 DCHECK_GE(history_length, 0);
[email protected]9e1ad4b2011-08-14 16:49:191211
avi2b177592014-12-10 02:08:021212 history_list_offset_ = history_offset;
1213 history_list_length_ = history_length;
[email protected]9e1ad4b2011-08-14 16:49:191214}
1215
[email protected]310ebd6302011-10-10 19:06:281216void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291217 if (!webview())
1218 return;
Blink Reformat1c4d759e2017-04-09 16:34:541219 webview()->SetInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291220}
1221
lfgdb5c4ed2016-03-04 23:09:071222void RenderViewImpl::OnUpdateWindowScreenRect(gfx::Rect window_screen_rect) {
1223 RenderWidget::OnUpdateWindowScreenRect(window_screen_rect);
1224}
1225
altimind8bd26c2016-11-04 11:44:541226void RenderViewImpl::OnAudioStateChanged(bool is_audio_playing) {
Blink Reformat1c4d759e2017-04-09 16:34:541227 webview()->AudioStateChanged(is_audio_playing);
altimind8bd26c2016-11-04 11:44:541228}
1229
initial.commit09911bf2008-07-26 23:55:291230///////////////////////////////////////////////////////////////////////////////
1231
nickf7b38222016-11-22 21:59:351232void RenderViewImpl::ShowCreatedPopupWidget(RenderWidget* popup_widget,
1233 WebNavigationPolicy policy,
1234 const gfx::Rect& initial_rect) {
1235 Send(new ViewHostMsg_ShowWidget(GetRoutingID(), popup_widget->routing_id(),
1236 initial_rect));
1237}
1238
1239void RenderViewImpl::ShowCreatedFullscreenWidget(
1240 RenderWidget* fullscreen_widget,
1241 WebNavigationPolicy policy,
1242 const gfx::Rect& initial_rect) {
1243 Send(new ViewHostMsg_ShowFullscreenWidget(GetRoutingID(),
1244 fullscreen_widget->routing_id()));
1245}
1246
creis69b184a472015-11-26 05:29:511247void RenderViewImpl::SendFrameStateUpdates() {
creis69b184a472015-11-26 05:29:511248 // Tell each frame with pending state to send its UpdateState message.
1249 for (int render_frame_routing_id : frames_with_pending_state_) {
1250 RenderFrameImpl* frame =
1251 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
1252 if (frame)
1253 frame->SendUpdateState();
1254 }
1255 frames_with_pending_state_.clear();
1256}
1257
sataya.mf405d0e2015-07-07 16:51:111258void RenderViewImpl::ApplyWebPreferencesInternal(
1259 const WebPreferences& prefs,
1260 blink::WebView* web_view,
1261 CompositorDependencies* compositor_deps) {
1262 ApplyWebPreferences(prefs, web_view);
sataya.mf405d0e2015-07-07 16:51:111263}
1264
svartmetal751af1f92016-08-13 11:47:331265void RenderViewImpl::OnForceRedraw(const ui::LatencyInfo& latency_info) {
[email protected]7d08a9352013-10-15 08:24:561266 if (RenderWidgetCompositor* rwc = compositor()) {
svartmetal751af1f92016-08-13 11:47:331267 rwc->QueueSwapPromise(
Jeremy Roman04f27c372017-10-27 15:20:551268 std::make_unique<AlwaysDrawSwapPromise>(latency_info));
danakj87fbafb2017-04-04 16:54:111269 rwc->SetNeedsForcedRedraw();
[email protected]7d08a9352013-10-15 08:24:561270 }
[email protected]c9bc8f12012-12-15 22:20:091271}
1272
[email protected]180ef242013-11-07 06:50:461273// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521274
csharrison95f01e922017-04-24 18:52:351275// TODO(csharrison): Migrate this method to WebFrameClient / RenderFrameImpl, as
1276// it is now serviced by a mojo interface scoped to the opener frame.
Blink Reformat1c4d759e2017-04-09 16:34:541277WebView* RenderViewImpl::CreateView(WebLocalFrame* creator,
[email protected]35b2a972014-04-04 15:50:221278 const WebURLRequest& request,
1279 const WebWindowFeatures& features,
1280 const WebString& frame_name,
1281 WebNavigationPolicy policy,
Daniel Chengd5e56ff2017-06-24 07:44:021282 bool suppress_opener,
1283 WebSandboxFlags sandbox_flags) {
nick5ae4d2d2017-01-06 01:18:351284 RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator);
rockot5c478a72016-09-28 23:14:181285 mojom::CreateNewWindowParamsPtr params = mojom::CreateNewWindowParams::New();
Mustaq Ahmede473e4352017-11-04 01:04:251286 params->user_gesture =
1287 WebUserGestureIndicator::IsProcessingUserGesture(creator);
[email protected]00323f02013-07-24 15:47:411288 if (GetContentClient()->renderer()->AllowPopup())
rockot5c478a72016-09-28 23:14:181289 params->user_gesture = true;
1290 params->window_container_type = WindowFeaturesToContainerType(features);
1291 params->session_storage_namespace_id = session_storage_namespace_id_;
Daniel Chengd5e56ff2017-06-24 07:44:021292 const std::string& frame_name_utf8 = frame_name.Utf8(
1293 WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
1294 params->frame_name = frame_name_utf8;
rockot5c478a72016-09-28 23:14:181295 params->opener_suppressed = suppress_opener;
1296 params->disposition = NavigationPolicyToDisposition(policy);
Blink Reformat1c4d759e2017-04-09 16:34:541297 if (!request.IsNull()) {
1298 params->target_url = request.Url();
rockot5c478a72016-09-28 23:14:181299 params->referrer = GetReferrerFromRequest(creator, request);
[email protected]44e55b012013-07-23 14:21:561300 }
scottmg8e6c6082017-02-13 23:15:481301 params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
[email protected]8ab04652010-06-12 02:47:261302
rockot5c478a72016-09-28 23:14:181303 // We preserve this information before sending the message since |params| is
1304 // moved on send.
1305 bool is_background_tab =
1306 params->disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB;
1307 bool opened_by_user_gesture = params->user_gesture;
[email protected]22217ed32013-11-18 18:40:231308
Daniel Cheng8bb30c62017-10-23 20:40:471309 mojom::CreateNewWindowStatus status;
rockot5c478a72016-09-28 23:14:181310 mojom::CreateNewWindowReplyPtr reply;
Balazs Engedya40712f2017-09-15 15:01:111311 auto* frame_host = creator_frame->GetFrameHost();
Daniel Cheng8bb30c62017-10-23 20:40:471312 bool err = !frame_host->CreateNewWindow(std::move(params), &status, &reply);
1313 if (err || status == mojom::CreateNewWindowStatus::kIgnore)
rockot5c478a72016-09-28 23:14:181314 return nullptr;
[email protected]48c9cf2d2009-09-16 16:47:521315
Jochen Eisinger515337a2017-05-26 14:12:521316 // For Android WebView, we support a pop-up like behavior for window.open()
1317 // even if the embedding app doesn't support multiple windows. In this case,
1318 // window.open() will return "window" and navigate it to whatever URL was
Jochen Eisinger8cb28492017-10-04 10:58:131319 // passed. We also don't need to consume user gestures to protect against
1320 // multiple windows being opened, because, well, the app doesn't support
1321 // multiple windows.
Daniel Cheng8bb30c62017-10-23 20:40:471322 // TODO(dcheng): It's awkward that this is plumbed into Blink but not really
1323 // used much in Blink, except to enable layout testing... perhaps this should
1324 // be checked directly in the browser side.
1325 if (status == mojom::CreateNewWindowStatus::kReuse)
Jochen Eisinger515337a2017-05-26 14:12:521326 return webview();
1327
Daniel Cheng8bb30c62017-10-23 20:40:471328 DCHECK(reply);
1329 DCHECK_NE(MSG_ROUTING_NONE, reply->route_id);
1330 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_route_id);
1331 DCHECK_NE(MSG_ROUTING_NONE, reply->main_frame_widget_route_id);
1332
Mustaq Ahmede473e4352017-11-04 01:04:251333 WebUserGestureIndicator::ConsumeUserGesture(creator);
Jochen Eisinger8cb28492017-10-04 10:58:131334
[email protected]7912e822014-04-16 02:37:031335 // While this view may be a background extension page, it can spawn a visible
1336 // render view. So we just assume that the new one is not another background
1337 // page instead of passing on our own value.
1338 // TODO(vangelis): Can we tell if the new view will be a background page?
1339 bool never_visible = false;
[email protected]9115d5f2013-03-24 04:37:411340
fsamuel664e8b62016-01-20 19:54:011341 ResizeParams initial_size = ResizeParams();
mkosiba58fa72f02014-11-12 01:21:361342 initial_size.screen_info = screen_info_;
1343
[email protected]d6fa88f2013-10-18 16:00:431344 // The initial hidden state for the RenderViewImpl here has to match what the
1345 // browser will eventually decide for the given disposition. Since we have to
1346 // return from this call synchronously, we just have to make our best guess
1347 // and rely on the browser sending a WasHidden / WasShown message if it
1348 // disagrees.
Balazs Engedyba034e72017-10-27 22:26:281349 mojom::CreateViewParamsPtr view_params = mojom::CreateViewParams::New();
alexmos5ac402d2015-07-09 07:51:101350
Balazs Engedyba034e72017-10-27 22:26:281351 view_params->opener_frame_route_id = creator_frame->GetRoutingID();
avia3dca182016-03-19 01:09:521352 DCHECK_EQ(GetRoutingID(), creator_frame->render_view()->GetRoutingID());
alexmos5ac402d2015-07-09 07:51:101353
Balazs Engedyba034e72017-10-27 22:26:281354 view_params->window_was_created_with_opener = true;
1355 view_params->renderer_preferences = renderer_preferences_;
1356 view_params->web_preferences = webkit_preferences_;
1357 view_params->view_id = reply->route_id;
1358 view_params->main_frame_routing_id = reply->main_frame_route_id;
1359 view_params->main_frame_interface_provider =
1360 std::move(reply->main_frame_interface_provider);
1361 view_params->main_frame_widget_routing_id = reply->main_frame_widget_route_id;
1362 view_params->session_storage_namespace_id =
rockot5c478a72016-09-28 23:14:181363 reply->cloned_session_storage_namespace_id;
Balazs Engedyba034e72017-10-27 22:26:281364 view_params->swapped_out = false;
1365 view_params->replicated_frame_state.frame_policy.sandbox_flags =
1366 sandbox_flags;
1367 view_params->replicated_frame_state.name = frame_name_utf8;
1368 view_params->devtools_main_frame_token = reply->devtools_main_frame_token;
Daniel Chengd5e56ff2017-06-24 07:44:021369 // Even if the main frame has a name, the main frame's unique name is always
1370 // the empty string.
Balazs Engedyba034e72017-10-27 22:26:281371 view_params->hidden = is_background_tab;
1372 view_params->never_visible = never_visible;
1373 view_params->initial_size = initial_size;
1374 view_params->enable_auto_resize = false;
1375 view_params->min_size = gfx::Size();
1376 view_params->max_size = gfx::Size();
1377 view_params->page_zoom_level = page_zoom_level_;
naskobd911332014-11-25 01:13:361378
nick5ae4d2d2017-01-06 01:18:351379 // Unretained() is safe here because our calling function will also call
1380 // show().
nickf7b38222016-11-22 21:59:351381 RenderWidget::ShowCallback show_callback =
nick5ae4d2d2017-01-06 01:18:351382 base::Bind(&RenderFrameImpl::ShowCreatedWindow,
1383 base::Unretained(creator_frame), opened_by_user_gesture);
nickf7b38222016-11-22 21:59:351384
Balazs Engedyba034e72017-10-27 22:26:281385 RenderViewImpl* view = RenderViewImpl::Create(
Hajime Hoshiabb3c8f2017-12-04 18:41:391386 compositor_deps_, std::move(view_params), show_callback,
1387 creator->GetTaskRunner(blink::TaskType::kUnthrottled));
[email protected]48c9cf2d2009-09-16 16:47:521388
[email protected]48c9cf2d2009-09-16 16:47:521389 return view->webview();
1390}
1391
Hajime Hoshiabb3c8f2017-12-04 18:41:391392WebWidget* RenderViewImpl::CreatePopup(blink::WebLocalFrame* creator,
1393 blink::WebPopupType popup_type) {
1394 RenderWidget* widget = RenderWidget::CreateForPopup(
1395 this, compositor_deps_, popup_type, screen_info_,
1396 creator->GetTaskRunner(blink::TaskType::kUnthrottled));
[email protected]3b78ec12014-03-04 05:18:281397 if (!widget)
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281398 return nullptr;
[email protected]b2e4c70132013-10-03 02:07:511399 if (screen_metrics_emulator_) {
1400 widget->SetPopupOriginAdjustmentsForEmulation(
1401 screen_metrics_emulator_.get());
1402 }
lfg8ff33912016-09-13 20:59:211403 return widget->GetWebWidget();
[email protected]48c9cf2d2009-09-16 16:47:521404}
1405
Daniel Murphy0ce6e2c2017-11-21 01:54:261406int64_t RenderViewImpl::GetSessionStorageNamespaceId() {
[email protected]5f2aa722013-08-07 16:59:411407 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
Daniel Murphy0ce6e2c2017-11-21 01:54:261408 return session_storage_namespace_id_;
[email protected]bd92c3a2010-01-13 05:02:341409}
1410
Blink Reformat1c4d759e2017-04-09 16:34:541411void RenderViewImpl::PrintPage(WebLocalFrame* frame) {
naskoe440d8c2016-10-12 23:07:561412 UMA_HISTOGRAM_BOOLEAN("PrintPreview.InitiatedByScript",
Blink Reformat1c4d759e2017-04-09 16:34:541413 frame->Top() == frame);
naskoe440d8c2016-10-12 23:07:561414
1415 // Logging whether the top frame is remote is sufficient in this case. If
1416 // the top frame is local, the printing code will function correctly and
1417 // the frame itself will be printed, so the cases this histogram tracks is
1418 // where printing of a subframe will fail as of now.
1419 UMA_HISTOGRAM_BOOLEAN("PrintPreview.OutOfProcessSubframe",
Blink Reformat1c4d759e2017-04-09 16:34:541420 frame->Top()->IsWebRemoteFrame());
naskoe440d8c2016-10-12 23:07:561421
thestigcb959ce2016-11-17 05:56:321422 RenderFrameImpl::FromWebFrame(frame)->ScriptedPrint(
1423 input_handler().handling_input_event());
[email protected]48c9cf2d2009-09-16 16:47:521424}
1425
Blink Reformat1c4d759e2017-04-09 16:34:541426bool RenderViewImpl::EnumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121427 const WebString& path,
1428 WebFileChooserCompletion* chooser_completion) {
1429 int id = enumeration_completion_id_++;
1430 enumeration_completions_[id] = chooser_completion;
1431 return Send(new ViewHostMsg_EnumerateDirectory(
avia3dca182016-03-19 01:09:521432 GetRoutingID(), id, blink::WebStringToFilePath(path)));
[email protected]8a58c1c2011-04-19 18:40:121433}
1434
[email protected]7e9523b2014-03-25 03:02:421435void RenderViewImpl::FrameDidStartLoading(WebFrame* frame) {
[email protected]7e9523b2014-03-25 03:02:421436 DCHECK_GE(frames_in_progress_, 0);
ericwilligers88e69742016-10-17 19:29:551437 if (frames_in_progress_ == 0) {
1438 for (auto& observer : observers_)
1439 observer.DidStartLoading();
1440 }
[email protected]7e9523b2014-03-25 03:02:421441 frames_in_progress_++;
[email protected]6dd5c322014-03-12 07:58:461442}
1443
[email protected]7e9523b2014-03-25 03:02:421444void RenderViewImpl::FrameDidStopLoading(WebFrame* frame) {
[email protected]eb473772014-04-11 20:54:331445 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
1446 // calls DidStopLoading() without a matching DidStartLoading().
1447 if (frames_in_progress_ == 0)
1448 return;
[email protected]7e9523b2014-03-25 03:02:421449 frames_in_progress_--;
[email protected]7e9523b2014-03-25 03:02:421450 if (frames_in_progress_ == 0) {
ericwilligers88e69742016-10-17 19:29:551451 for (auto& observer : observers_)
1452 observer.DidStopLoading();
[email protected]7e9523b2014-03-25 03:02:421453 }
[email protected]48c9cf2d2009-09-16 16:47:521454}
1455
lfgcaab5142016-02-26 19:06:521456void RenderViewImpl::AttachWebFrameWidget(blink::WebFrameWidget* frame_widget) {
dcheng3ce04b62015-10-26 23:30:551457 // The previous WebFrameWidget must already be detached by CloseForFrame().
1458 DCHECK(!frame_widget_);
1459 frame_widget_ = frame_widget;
1460}
1461
tommycli8aad3ba2015-08-12 17:57:591462void RenderViewImpl::SetZoomLevel(double zoom_level) {
wjmaclean64951902016-04-29 20:59:121463 // If we change the zoom level for the view, make sure any subsequent subframe
1464 // loads reflect the current zoom level.
1465 page_zoom_level_ = zoom_level;
1466
Blink Reformat1c4d759e2017-04-09 16:34:541467 webview()->SetZoomLevel(zoom_level);
ericwilligers88e69742016-10-17 19:29:551468 for (auto& observer : observers_)
1469 observer.OnZoomLevelChanged();
tommycli8aad3ba2015-08-12 17:57:591470}
1471
habib.virji597255e2014-09-09 00:30:181472void RenderViewImpl::SetValidationMessageDirection(
1473 base::string16* wrapped_main_text,
1474 blink::WebTextDirection main_text_hint,
1475 base::string16* wrapped_sub_text,
1476 blink::WebTextDirection sub_text_hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541477 if (main_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181478 *wrapped_main_text =
1479 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
Blink Reformat1c4d759e2017-04-09 16:34:541480 } else if (main_text_hint == blink::kWebTextDirectionRightToLeft &&
habib.virji597255e2014-09-09 00:30:181481 !base::i18n::IsRTL()) {
1482 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
1483 }
1484
1485 if (!wrapped_sub_text->empty()) {
Blink Reformat1c4d759e2017-04-09 16:34:541486 if (sub_text_hint == blink::kWebTextDirectionLeftToRight) {
habib.virji597255e2014-09-09 00:30:181487 *wrapped_sub_text =
1488 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
Blink Reformat1c4d759e2017-04-09 16:34:541489 } else if (sub_text_hint == blink::kWebTextDirectionRightToLeft) {
habib.virji597255e2014-09-09 00:30:181490 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
1491 }
1492 }
1493}
1494
[email protected]310ebd6302011-10-10 19:06:281495void RenderViewImpl::UpdateTargetURL(const GURL& url,
1496 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581497 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521498 if (latest_url == target_url_)
1499 return;
[email protected]163f8242009-10-30 20:19:551500
[email protected]48c9cf2d2009-09-16 16:47:521501 // Tell the browser to display a destination link.
1502 if (target_url_status_ == TARGET_INFLIGHT ||
1503 target_url_status_ == TARGET_PENDING) {
1504 // If we have a request in-flight, save the URL to be sent when we
1505 // receive an ACK to the in-flight request. We can happily overwrite
1506 // any existing pending sends.
1507 pending_target_url_ = latest_url;
1508 target_url_status_ = TARGET_PENDING;
1509 } else {
mnaganovbf087422015-12-16 05:10:031510 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411511 // see |ParamTraits<GURL>|.
markdittmer67b71ea2016-03-03 22:40:031512 if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:411513 latest_url = GURL();
avia3dca182016-03-19 01:09:521514 Send(new ViewHostMsg_UpdateTargetURL(GetRoutingID(), latest_url));
[email protected]48c9cf2d2009-09-16 16:47:521515 target_url_ = latest_url;
1516 target_url_status_ = TARGET_INFLIGHT;
1517 }
1518}
1519
[email protected]70221f02013-01-31 22:17:071520gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect(
1521 const gfx::RectF& rect) const {
1522 gfx::RectF window_rect = rect;
Blink Reformat1c4d759e2017-04-09 16:34:541523 window_rect.Scale(device_scale_factor_ * webview()->PageScaleFactor());
[email protected]70221f02013-01-31 22:17:071524 return window_rect;
1525}
1526
creis69b184a472015-11-26 05:29:511527void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) {
creisce0ef3572017-01-26 17:53:081528 // Keep track of which frames have pending updates.
1529 frames_with_pending_state_.insert(frame->GetRoutingID());
creis8eb8ef22015-11-04 22:51:381530
[email protected]882daa92009-11-05 16:31:311531 int delay;
avif937e1d2014-11-02 18:13:071532 if (send_content_state_immediately_)
[email protected]882daa92009-11-05 16:31:311533 delay = 0;
1534 else if (is_hidden())
avif937e1d2014-11-02 18:13:071535 delay = kDelaySecondsForContentStateSyncHidden;
[email protected]882daa92009-11-05 16:31:311536 else
avif937e1d2014-11-02 18:13:071537 delay = kDelaySecondsForContentStateSync;
[email protected]882daa92009-11-05 16:31:311538
avif937e1d2014-11-02 18:13:071539 if (nav_state_sync_timer_.IsRunning()) {
[email protected]882daa92009-11-05 16:31:311540 // The timer is already running. If the delay of the timer maches the amount
1541 // we want to delay by, then return. Otherwise stop the timer so that it
1542 // gets started with the right delay.
avif937e1d2014-11-02 18:13:071543 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
[email protected]882daa92009-11-05 16:31:311544 return;
avif937e1d2014-11-02 18:13:071545 nav_state_sync_timer_.Stop();
[email protected]882daa92009-11-05 16:31:311546 }
1547
creisce0ef3572017-01-26 17:53:081548 // Tell each frame with pending state to inform the browser.
1549 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
1550 &RenderViewImpl::SendFrameStateUpdates);
[email protected]882daa92009-11-05 16:31:311551}
1552
Blink Reformat1c4d759e2017-04-09 16:34:541553void RenderViewImpl::SetMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551554 mouse_over_url_ = GURL(url);
1555 UpdateTargetURL(mouse_over_url_, focus_url_);
1556}
1557
Blink Reformat1c4d759e2017-04-09 16:34:541558void RenderViewImpl::SetKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551559 focus_url_ = GURL(url);
1560 UpdateTargetURL(focus_url_, mouse_over_url_);
1561}
1562
Blink Reformat1c4d759e2017-04-09 16:34:541563bool RenderViewImpl::AcceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451564 return renderer_preferences_.can_accept_load_drops;
1565}
1566
Blink Reformat1c4d759e2017-04-09 16:34:541567void RenderViewImpl::FocusNext() {
avia3dca182016-03-19 01:09:521568 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), false));
[email protected]48c9cf2d2009-09-16 16:47:521569}
1570
Blink Reformat1c4d759e2017-04-09 16:34:541571void RenderViewImpl::FocusPrevious() {
avia3dca182016-03-19 01:09:521572 Send(new ViewHostMsg_TakeFocus(GetRoutingID(), true));
[email protected]48c9cf2d2009-09-16 16:47:521573}
1574
esprehn3d4471a2015-09-17 07:13:201575// TODO(esprehn): Blink only ever passes Elements, this should take WebElement.
Blink Reformat1c4d759e2017-04-09 16:34:541576void RenderViewImpl::FocusedNodeChanged(const WebNode& fromNode,
estade31c54342015-01-23 03:34:361577 const WebNode& toNode) {
estade31c54342015-01-23 03:34:361578 RenderFrameImpl* previous_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541579 if (!fromNode.IsNull())
1580 previous_frame =
1581 RenderFrameImpl::FromWebFrame(fromNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361582 RenderFrameImpl* new_frame = nullptr;
Blink Reformat1c4d759e2017-04-09 16:34:541583 if (!toNode.IsNull())
1584 new_frame = RenderFrameImpl::FromWebFrame(toNode.GetDocument().GetFrame());
estade31c54342015-01-23 03:34:361585
1586 if (previous_frame && previous_frame != new_frame)
1587 previous_frame->FocusedNodeChanged(WebNode());
1588 if (new_frame)
1589 new_frame->FocusedNodeChanged(toNode);
1590
1591 // TODO(dmazzoni): remove once there's a separate a11y tree per frame.
naskoe8d115752015-08-07 00:43:131592 if (main_render_frame_)
1593 main_render_frame_->FocusedNodeChangedForAccessibility(toNode);
[email protected]08e9e132010-06-01 16:58:491594}
1595
Blink Reformat1c4d759e2017-04-09 16:34:541596void RenderViewImpl::DidUpdateLayout() {
ericwilligers88e69742016-10-17 19:29:551597 for (auto& observer : observers_)
1598 observer.DidUpdateLayout();
[email protected]d01b2a62013-09-18 23:21:331599
[email protected]169d4282011-11-30 19:33:591600 // We don't always want to set up a timer, only if we've been put in that
1601 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1602 // message.
1603 if (!send_preferred_size_changes_ || !webview())
1604 return;
1605
1606 if (check_preferred_size_timer_.IsRunning())
1607 return;
1608 check_preferred_size_timer_.Start(FROM_HERE,
1609 TimeDelta::FromMilliseconds(0), this,
1610 &RenderViewImpl::CheckPreferredSize);
1611}
1612
Blink Reformat1c4d759e2017-04-09 16:34:541613void RenderViewImpl::NavigateBackForwardSoon(int offset) {
Alex Clarkebf3dceb2017-11-24 12:27:431614 history_navigation_virtual_time_pauser_ =
1615 RenderThreadImpl::current()
1616 ->GetRendererScheduler()
1617 ->CreateWebScopedVirtualTimePauser();
1618 history_navigation_virtual_time_pauser_.PauseVirtualTime(true);
avia3dca182016-03-19 01:09:521619 Send(new ViewHostMsg_GoToEntryAtOffset(GetRoutingID(), offset));
[email protected]48c9cf2d2009-09-16 16:47:521620}
1621
Alex Clarkebf3dceb2017-11-24 12:27:431622void RenderViewImpl::DidCommitProvisionalHistoryLoad() {
1623 history_navigation_virtual_time_pauser_.PauseVirtualTime(false);
1624}
1625
Blink Reformat1c4d759e2017-04-09 16:34:541626int RenderViewImpl::HistoryBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001627 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521628}
1629
Blink Reformat1c4d759e2017-04-09 16:34:541630int RenderViewImpl::HistoryForwardListCount() {
1631 return history_list_length_ - HistoryBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521632}
1633
[email protected]180ef242013-11-07 06:50:461634// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:511635
Blink Reformat1c4d759e2017-04-09 16:34:541636void RenderViewImpl::DidFocus() {
[email protected]ea42e7782010-08-23 23:58:121637 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1638 // we won't have to test for user gesture anymore and we can
1639 // move that code back to render_widget.cc
Mustaq Ahmede473e4352017-11-04 01:04:251640 WebFrame* main_frame = webview() ? webview()->MainFrame() : nullptr;
1641 bool is_processing_user_gesture =
1642 WebUserGestureIndicator::IsProcessingUserGesture(
1643 main_frame && main_frame->IsWebLocalFrame()
1644 ? main_frame->ToWebLocalFrame()
1645 : nullptr);
1646 if (is_processing_user_gesture &&
[email protected]70dee7e2013-05-29 18:28:301647 !RenderThreadImpl::current()->layout_test_mode()) {
avia3dca182016-03-19 01:09:521648 Send(new ViewHostMsg_Focus(GetRoutingID()));
[email protected]ea42e7782010-08-23 23:58:121649 }
1650}
1651
nickf7b38222016-11-22 21:59:351652// We are supposed to get a single call to show() for a newly created RenderView
1653// that was created via RenderViewImpl::createView. We wait until this point to
1654// run |show_callback|, which is bound to our opener's ShowCreatedViewWidget()
1655// method.
initial.commit09911bf2008-07-26 23:55:291656//
1657// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281658// created RenderView (i.e., as a blocked popup or as a new tab).
Blink Reformat1c4d759e2017-04-09 16:34:541659void RenderViewImpl::Show(WebNavigationPolicy policy) {
nickf7b38222016-11-22 21:59:351660 if (did_show_ && !webkit_preferences_.supports_multiple_windows) {
[email protected]b2142e962012-10-30 13:59:251661 // When supports_multiple_windows is disabled, popups are reusing
1662 // the same view. In some scenarios, this makes WebKit to call show() twice.
initial.commit09911bf2008-07-26 23:55:291663 return;
[email protected]b2142e962012-10-30 13:59:251664 }
initial.commit09911bf2008-07-26 23:55:291665
Blink Reformat1c4d759e2017-04-09 16:34:541666 RenderWidget::Show(policy);
initial.commit09911bf2008-07-26 23:55:291667}
1668
miletuse8d28ba2015-06-19 04:52:041669
Blink Reformat1c4d759e2017-04-09 16:34:541670bool RenderViewImpl::CanHandleGestureEvent() {
slangley1a6375e62017-03-29 06:03:231671 return true;
1672}
1673
Blink Reformat1c4d759e2017-04-09 16:34:541674bool RenderViewImpl::CanUpdateLayout() {
slangley1a6375e62017-03-29 06:03:231675 return true;
1676}
1677
Blink Reformat1c4d759e2017-04-09 16:34:541678void RenderViewImpl::DidHandleGestureEvent(const WebGestureEvent& event,
1679 bool event_cancelled) {
1680 RenderWidget::DidHandleGestureEvent(event, event_cancelled);
[email protected]bb37b652013-11-27 23:47:111681
[email protected]91dcc6d32014-07-30 00:01:331682 if (!event_cancelled) {
ericwilligers88e69742016-10-17 19:29:551683 for (auto& observer : observers_)
1684 observer.DidHandleGestureEvent(event);
[email protected]91dcc6d32014-07-30 00:01:331685 }
[email protected]c68c3e4e2013-01-24 00:36:561686}
1687
Blink Reformat1c4d759e2017-04-09 16:34:541688blink::WebLayerTreeView* RenderViewImpl::InitializeLayerTreeView() {
wjmaclean1d970622017-01-21 22:28:241689 // TODO(!wjmaclean): We should be able to just remove this function, and
1690 // expect the RenderWidget version of the function to be called instead.
1691 // However, we have a diamond inheritance pattern going on:
1692 // WebWidgetClient
1693 // | |
1694 // RenderWidget WebViewClient
1695 // | |
1696 // RenderViewImpl
1697 //
1698 // and this seems to prefer calling the empty version in WebWidgetClient
1699 // or WebViewClient over the non-empty one in RenderWidget.
Blink Reformat1c4d759e2017-04-09 16:34:541700 return RenderWidget::InitializeLayerTreeView();
[email protected]6e89eb72013-07-23 13:28:221701}
1702
Blink Reformat1c4d759e2017-04-09 16:34:541703void RenderViewImpl::CloseWidgetSoon() {
1704 RenderWidget::CloseWidgetSoon();
lfg2230bce2016-04-28 18:37:041705}
1706
Blink Reformat1c4d759e2017-04-09 16:34:541707void RenderViewImpl::ConvertViewportToWindow(blink::WebRect* rect) {
1708 RenderWidget::ConvertViewportToWindow(rect);
lfg2230bce2016-04-28 18:37:041709}
1710
Blink Reformat1c4d759e2017-04-09 16:34:541711void RenderViewImpl::ConvertWindowToViewport(blink::WebFloatRect* rect) {
1712 RenderWidget::ConvertWindowToViewport(rect);
lfg2230bce2016-04-28 18:37:041713}
1714
Blink Reformat1c4d759e2017-04-09 16:34:541715void RenderViewImpl::DidAutoResize(const blink::WebSize& newSize) {
lfgb00fcad2016-07-14 14:16:331716 RenderWidget::DidAutoResize(newSize);
lfg2230bce2016-04-28 18:37:041717}
1718
Blink Reformat1c4d759e2017-04-09 16:34:541719void RenderViewImpl::DidOverscroll(
lfg2230bce2016-04-28 18:37:041720 const blink::WebFloatSize& overscrollDelta,
1721 const blink::WebFloatSize& accumulatedOverscroll,
1722 const blink::WebFloatPoint& positionInViewport,
sunyunjiabbea8a92017-08-31 11:18:541723 const blink::WebFloatSize& velocityInViewport,
Sandra Sun2288e8532017-11-30 22:50:161724 const blink::WebOverscrollBehavior& behavior) {
Blink Reformat1c4d759e2017-04-09 16:34:541725 RenderWidget::DidOverscroll(overscrollDelta, accumulatedOverscroll,
sunyunjiabbea8a92017-08-31 11:18:541726 positionInViewport, velocityInViewport, behavior);
lfg2230bce2016-04-28 18:37:041727}
1728
Blink Reformat1c4d759e2017-04-09 16:34:541729void RenderViewImpl::HasTouchEventHandlers(bool has_handlers) {
1730 RenderWidget::HasTouchEventHandlers(has_handlers);
lfg2230bce2016-04-28 18:37:041731}
1732
Blink Reformat1c4d759e2017-04-09 16:34:541733blink::WebRect RenderViewImpl::RootWindowRect() {
1734 return RenderWidget::WindowRect();
lfg2230bce2016-04-28 18:37:041735}
1736
Blink Reformat1c4d759e2017-04-09 16:34:541737blink::WebScreenInfo RenderViewImpl::GetScreenInfo() {
1738 return RenderWidget::GetScreenInfo();
lfg2230bce2016-04-28 18:37:041739}
1740
Blink Reformat1c4d759e2017-04-09 16:34:541741void RenderViewImpl::SetToolTipText(const blink::WebString& text,
lfg2230bce2016-04-28 18:37:041742 blink::WebTextDirection hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541743 RenderWidget::SetToolTipText(text, hint);
lfg2230bce2016-04-28 18:37:041744}
1745
Blink Reformat1c4d759e2017-04-09 16:34:541746void RenderViewImpl::SetTouchAction(blink::WebTouchAction touchAction) {
1747 RenderWidget::SetTouchAction(touchAction);
lfg2230bce2016-04-28 18:37:041748}
1749
Blink Reformat1c4d759e2017-04-09 16:34:541750void RenderViewImpl::ShowUnhandledTapUIIfNeeded(
Donn Denman43a439e2017-08-29 04:20:451751 const blink::WebTappedInfo& tappedInfo) {
1752 RenderWidget::ShowUnhandledTapUIIfNeeded(tappedInfo);
lfg2230bce2016-04-28 18:37:041753}
1754
Blink Reformat1c4d759e2017-04-09 16:34:541755blink::WebWidgetClient* RenderViewImpl::WidgetClient() {
lfg0f440622016-07-20 04:27:141756 return static_cast<RenderWidget*>(this);
1757}
1758
[email protected]180ef242013-11-07 06:50:461759// blink::WebFrameClient -----------------------------------------------------
[email protected]3d9689372009-09-10 04:29:171760
[email protected]5e92282f2012-08-17 08:11:571761void RenderViewImpl::Repaint(const gfx::Size& size) {
[email protected]3d9ec5052013-01-02 22:05:251762 OnRepaint(size);
[email protected]5e92282f2012-08-17 08:11:571763}
1764
[email protected]b2324b092012-11-01 10:34:111765void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
1766 const std::string& value) {
alexmos56567492016-09-13 00:52:461767 GetWidget()->SetEditCommandForNextKeyEvent(name, value);
[email protected]b2324b092012-11-01 10:34:111768}
1769
1770void RenderViewImpl::ClearEditCommands() {
alexmos56567492016-09-13 00:52:461771 GetWidget()->ClearEditCommands();
[email protected]b2324b092012-11-01 10:34:111772}
1773
[email protected]b38806a2013-10-04 16:01:381774const std::string& RenderViewImpl::GetAcceptLanguages() const {
1775 return renderer_preferences_.accept_languages;
1776}
1777
danakjdea2efb2016-03-10 19:13:171778void RenderViewImpl::ConvertViewportToWindowViaWidget(blink::WebRect* rect) {
Blink Reformat1c4d759e2017-04-09 16:34:541779 ConvertViewportToWindow(rect);
oshimae2b3b402015-12-04 04:27:241780}
1781
huangs2a342352015-12-15 16:59:241782gfx::RectF RenderViewImpl::ElementBoundsInWindow(
1783 const blink::WebElement& element) {
Blink Reformat1c4d759e2017-04-09 16:34:541784 blink::WebRect bounding_box_in_window = element.BoundsInViewport();
danakjdea2efb2016-03-10 19:13:171785 ConvertViewportToWindowViaWidget(&bounding_box_in_window);
huangs2a342352015-12-15 16:59:241786 return gfx::RectF(bounding_box_in_window);
1787}
1788
changwand659e202016-06-13 02:39:121789bool RenderViewImpl::HasAddedInputHandler() const {
1790 return has_added_input_handler_;
1791}
1792
[email protected]310ebd6302011-10-10 19:06:281793void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:071794 // We don't always want to send the change messages over IPC, only if we've
1795 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1796 // message.
1797 if (!send_preferred_size_changes_ || !webview())
1798 return;
oshima1a688b5c2017-06-16 19:00:131799 blink::WebSize tmp_size = webview()->ContentsPreferredMinimumSize();
1800 blink::WebRect tmp_rect(0, 0, tmp_size.width, tmp_size.height);
1801 ConvertViewportToWindow(&tmp_rect);
1802 gfx::Size size(tmp_rect.width, tmp_rect.height);
[email protected]705243f2010-05-05 19:58:071803 if (size == preferred_size_)
1804 return;
[email protected]c27324b2009-11-19 22:44:291805
[email protected]705243f2010-05-05 19:58:071806 preferred_size_ = size;
avia3dca182016-03-19 01:09:521807 Send(new ViewHostMsg_DidContentsPreferredSizeChange(GetRoutingID(),
[email protected]705243f2010-05-05 19:58:071808 preferred_size_));
[email protected]3d9689372009-09-10 04:29:171809}
1810
Blink Reformat1c4d759e2017-04-09 16:34:541811blink::WebString RenderViewImpl::AcceptLanguages() {
1812 return WebString::FromUTF8(renderer_preferences_.accept_languages);
[email protected]9982c802013-06-12 15:22:061813}
1814
[email protected]e9ff79c2012-10-19 21:31:261815// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:311816
[email protected]310ebd6302011-10-10 19:06:281817bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:311818 return RenderWidget::Send(message);
1819}
1820
avi8a45c1092016-03-01 16:12:341821RenderWidget* RenderViewImpl::GetWidget() const {
1822 return const_cast<RenderWidget*>(static_cast<const RenderWidget*>(this));
1823}
1824
mostynbc33353232014-09-12 09:38:311825RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() {
nasko77de2312015-05-12 03:09:161826 return main_render_frame_;
[email protected]b849847b2013-12-10 21:57:581827}
1828
[email protected]82114f52012-03-20 22:53:411829int RenderViewImpl::GetRoutingID() const {
fsamuele8326c742016-01-12 00:49:391830 return routing_id();
[email protected]a2ef54c2011-10-10 16:20:311831}
1832
[email protected]82114f52012-03-20 22:53:411833gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:311834 return size();
1835}
1836
oshima129b75e2016-01-14 09:15:141837float RenderViewImpl::GetDeviceScaleFactor() const {
1838 return device_scale_factor_;
1839}
1840
Marc Treib06d66032017-10-19 08:43:201841float RenderViewImpl::GetZoomLevel() const {
1842 return page_zoom_level_;
1843}
1844
thestig8a8fdfd32017-05-06 18:46:541845const WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:311846 return webkit_preferences_;
1847}
1848
[email protected]324825d2012-11-30 12:37:151849void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
1850 OnUpdateWebPreferences(preferences);
1851}
1852
[email protected]180ef242013-11-07 06:50:461853blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:311854 return webview();
1855}
1856
lfgcaab5142016-02-26 19:06:521857blink::WebFrameWidget* RenderViewImpl::GetWebFrameWidget() {
1858 return frame_widget_;
1859}
1860
[email protected]310ebd6302011-10-10 19:06:281861bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:311862 return (!send_preferred_size_changes_ ||
1863 (disable_scrollbars_size_limit_.width() <= width ||
1864 disable_scrollbars_size_limit_.height() <= height));
1865}
1866
avif937e1d2014-11-02 18:13:071867bool RenderViewImpl::GetContentStateImmediately() const {
1868 return send_content_state_immediately_;
[email protected]a2ef54c2011-10-10 16:20:311869}
1870
mcnee432e47d2015-11-09 19:37:461871void RenderViewImpl::OnSetPageScale(float page_scale_factor) {
ccameronb7c1d6c2015-03-09 17:08:241872 if (!webview())
1873 return;
Blink Reformat1c4d759e2017-04-09 16:34:541874 webview()->SetPageScaleFactor(page_scale_factor);
ccameronb7c1d6c2015-03-09 17:08:241875}
1876
wjmaclean64951902016-04-29 20:59:121877void RenderViewImpl::OnSetZoomLevel(
1878 PageMsg_SetZoomLevel_Command command,
1879 double zoom_level) {
1880 switch (command) {
1881 case PageMsg_SetZoomLevel_Command::CLEAR_TEMPORARY:
1882 uses_temporary_zoom_level_ = false;
1883 break;
1884 case PageMsg_SetZoomLevel_Command::SET_TEMPORARY:
1885 uses_temporary_zoom_level_ = true;
1886 break;
1887 case PageMsg_SetZoomLevel_Command::USE_CURRENT_TEMPORARY_MODE:
1888 // Don't override a temporary zoom level without an explicit SET.
1889 if (uses_temporary_zoom_level_)
1890 return;
1891 break;
1892 default:
1893 NOTIMPLEMENTED();
1894 }
Blink Reformat1c4d759e2017-04-09 16:34:541895 webview()->HidePopups();
wjmaclean64951902016-04-29 20:59:121896 SetZoomLevel(zoom_level);
[email protected]d42bf472014-06-14 01:49:381897}
1898
[email protected]310ebd6302011-10-10 19:06:281899void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:591900 webkit_preferences_ = prefs;
sataya.mf405d0e2015-07-07 16:51:111901 ApplyWebPreferencesInternal(webkit_preferences_, webview(), compositor_deps_);
initial.commit09911bf2008-07-26 23:55:291902}
1903
[email protected]310ebd6302011-10-10 19:06:281904void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:511905 int id,
[email protected]c42de732013-02-16 06:26:311906 const std::vector<base::FilePath>& paths) {
[email protected]600ea402011-04-12 00:01:511907 if (!enumeration_completions_[id])
1908 return;
1909
1910 WebVector<WebString> ws_file_names(paths.size());
1911 for (size_t i = 0; i < paths.size(); ++i)
kinukoa4293022017-01-27 06:43:251912 ws_file_names[i] = blink::FilePathToWebString(paths[i]);
[email protected]600ea402011-04-12 00:01:511913
Blink Reformat1c4d759e2017-04-09 16:34:541914 enumeration_completions_[id]->DidChooseFile(ws_file_names);
[email protected]600ea402011-04-12 00:01:511915 enumeration_completions_.erase(id);
1916}
1917
[email protected]244ac1892011-12-02 17:04:471918void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
1919 const gfx::Size& max_size) {
1920 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
1921 if (!webview())
1922 return;
oshima33ec97cd2015-12-14 19:40:241923
[email protected]97e1bf72013-03-06 14:06:051924 auto_resize_mode_ = true;
Fady Samuel319e429c2017-10-02 18:31:551925
oshima33ec97cd2015-12-14 19:40:241926 if (IsUseZoomForDSFEnabled()) {
Blink Reformat1c4d759e2017-04-09 16:34:541927 webview()->EnableAutoResizeMode(
oshima33ec97cd2015-12-14 19:40:241928 gfx::ScaleToCeiledSize(min_size, device_scale_factor_),
1929 gfx::ScaleToCeiledSize(max_size, device_scale_factor_));
1930 } else {
Blink Reformat1c4d759e2017-04-09 16:34:541931 webview()->EnableAutoResizeMode(min_size, max_size);
oshima33ec97cd2015-12-14 19:40:241932 }
[email protected]61e2b3cc2012-03-02 16:13:341933}
1934
1935void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
1936 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
1937 if (!webview())
1938 return;
[email protected]97e1bf72013-03-06 14:06:051939 auto_resize_mode_ = false;
Blink Reformat1c4d759e2017-04-09 16:34:541940 webview()->DisableAutoResizeMode();
[email protected]61e2b3cc2012-03-02 16:13:341941
[email protected]eac2b362013-05-22 07:01:451942 if (!new_size.IsEmpty()) {
mfomitchev2600fd7c2016-02-17 20:53:391943 ResizeParams resize_params;
jbroman5ff10302016-07-22 03:36:261944 resize_params.screen_info = screen_info_;
mfomitchev2600fd7c2016-02-17 20:53:391945 resize_params.new_size = new_size;
1946 resize_params.physical_backing_size = physical_backing_size_;
mdjones2ee41afd2016-10-27 16:50:201947 resize_params.browser_controls_shrink_blink_size =
1948 browser_controls_shrink_blink_size_;
mfomitchev2600fd7c2016-02-17 20:53:391949 resize_params.top_controls_height = top_controls_height_;
1950 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:391951 resize_params.is_fullscreen_granted = is_fullscreen_granted();
1952 resize_params.display_mode = display_mode_;
1953 resize_params.needs_resize_ack = false;
1954 Resize(resize_params);
[email protected]eac2b362013-05-22 07:01:451955 }
[email protected]244ac1892011-12-02 17:04:471956}
1957
Fady Samuel69b33b52017-11-08 22:01:521958void RenderViewImpl::OnSetLocalSurfaceIdForAutoResize(
1959 uint64_t sequence_number,
1960 const gfx::Size& min_size,
1961 const gfx::Size& max_size,
1962 const content::ScreenInfo& screen_info,
1963 const viz::LocalSurfaceId& local_surface_id) {
1964 if (!auto_resize_mode_ || resize_or_repaint_ack_num_ != sequence_number)
1965 return;
1966
1967 SetLocalSurfaceIdForAutoResize(sequence_number, screen_info,
1968 local_surface_id);
1969
1970 if (IsUseZoomForDSFEnabled()) {
1971 webview()->EnableAutoResizeMode(
1972 gfx::ScaleToCeiledSize(min_size, device_scale_factor_),
1973 gfx::ScaleToCeiledSize(max_size, device_scale_factor_));
1974 } else {
1975 webview()->EnableAutoResizeMode(min_size, max_size);
1976 }
1977}
1978
[email protected]2bf834f2011-11-17 20:02:211979void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:241980 if (send_preferred_size_changes_)
1981 return;
[email protected]9fb325e2010-05-06 18:23:241982 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:391983
[email protected]d812fd12011-05-27 23:05:071984 // Start off with an initial preferred size notification (in case
1985 // |didUpdateLayout| was already called).
Blink Reformat1c4d759e2017-04-09 16:34:541986 DidUpdateLayout();
[email protected]0666aef2009-05-13 19:48:081987}
1988
[email protected]310ebd6302011-10-10 19:06:281989void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:101990 const gfx::Size& disable_scrollbar_size_limit) {
1991 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
1992}
1993
[email protected]310ebd6302011-10-10 19:06:281994void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:261995 const RendererPreferences& renderer_prefs) {
[email protected]ebd5ea52014-05-28 14:51:151996 std::string old_accept_languages = renderer_preferences_.accept_languages;
1997
[email protected]80d96fa2009-06-10 22:34:511998 renderer_preferences_ = renderer_prefs;
ananta59b9fe72015-04-07 01:33:261999
[email protected]6e282c92009-07-24 01:19:372000 UpdateFontRenderingFromRendererPrefs();
scottmgb92365e2016-08-30 20:54:402001 UpdateThemePrefs();
Blink Reformat1c4d759e2017-04-09 16:34:542002 blink::SetCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]38a85712013-01-02 22:45:022003
brettw8a274fa2016-11-15 00:20:402004#if BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]1596efb2013-01-17 22:13:012005 if (renderer_prefs.use_custom_colors) {
Blink Reformat1c4d759e2017-04-09 16:34:542006 blink::SetFocusRingColor(renderer_prefs.focus_ring_color);
[email protected]1596efb2013-01-17 22:13:012007
2008 if (webview()) {
Blink Reformat1c4d759e2017-04-09 16:34:542009 webview()->SetSelectionColors(renderer_prefs.active_selection_bg_color,
2010 renderer_prefs.active_selection_fg_color,
2011 renderer_prefs.inactive_selection_bg_color,
2012 renderer_prefs.inactive_selection_fg_color);
2013 webview()->ThemeChanged();
[email protected]1596efb2013-01-17 22:13:012014 }
[email protected]644d77e2010-01-27 01:03:102015 }
brettw8a274fa2016-11-15 00:20:402016#endif // BUILDFLAG(USE_DEFAULT_RENDER_THEME)
[email protected]d299d972012-03-23 02:26:552017
[email protected]ebd5ea52014-05-28 14:51:152018 if (webview() &&
2019 old_accept_languages != renderer_preferences_.accept_languages) {
Blink Reformat1c4d759e2017-04-09 16:34:542020 webview()->AcceptLanguagesChanged();
[email protected]ebd5ea52014-05-28 14:51:152021 }
[email protected]80d96fa2009-06-10 22:34:512022}
2023
[email protected]310ebd6302011-10-10 19:06:282024void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
2025 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:282026 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542027 webview()->PerformMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:562028}
2029
[email protected]81375e872012-01-11 21:40:362030void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
2031 const WebPluginAction& action) {
2032 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542033 webview()->PerformPluginAction(action, location);
[email protected]81375e872012-01-11 21:40:362034}
2035
[email protected]310ebd6302011-10-10 19:06:282036void RenderViewImpl::OnClosePage() {
lukasza5d0dee42017-06-14 21:57:372037 // ViewMsg_ClosePage should only be sent to active, non-swapped-out views.
2038 DCHECK(webview()->MainFrame()->IsWebLocalFrame());
2039
initial.commit09911bf2008-07-26 23:55:292040 // TODO(creis): We'd rather use webview()->Close() here, but that currently
2041 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
2042 // in the onunload handler from appearing. For now, we're bypassing that and
2043 // calling the FrameLoader's CloseURL method directly. This should be
2044 // revisited to avoid having two ways to close a page. Having a single way
2045 // to close that can run onunload is also useful for fixing
2046 // http://b/issue?id=753080.
lukasza5d0dee42017-06-14 21:57:372047 webview()->MainFrame()->ToWebLocalFrame()->DispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:292048
avia3dca182016-03-19 01:09:522049 Send(new ViewHostMsg_ClosePage_ACK(GetRoutingID()));
initial.commit09911bf2008-07-26 23:55:292050}
2051
naskoc288745f2015-05-01 22:54:212052void RenderViewImpl::OnClose() {
2053 if (closing_)
avia3dca182016-03-19 01:09:522054 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(GetRoutingID()));
naskoc288745f2015-05-01 22:54:212055 RenderWidget::OnClose();
2056}
2057
[email protected]310ebd6302011-10-10 19:06:282058void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:002059 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542060 webview()->HidePopups();
[email protected]30f75e62009-02-25 22:01:002061}
2062
bokanc63441c2016-04-27 15:49:122063void RenderViewImpl::ResizeWebWidget() {
Matthew Jones7e156182017-07-21 22:21:332064 webview()->ResizeWithBrowserControls(
2065 GetSizeForWebWidget(), top_controls_height_, bottom_controls_height_,
2066 browser_controls_shrink_blink_size_);
bokanc63441c2016-04-27 15:49:122067}
2068
fsamuel664e8b62016-01-20 19:54:012069void RenderViewImpl::OnResize(const ResizeParams& params) {
[email protected]189a8862014-07-18 00:27:532070 TRACE_EVENT0("renderer", "RenderViewImpl::OnResize");
[email protected]cda45c02010-02-25 19:28:102071 if (webview()) {
Blink Reformat1c4d759e2017-04-09 16:34:542072 webview()->HidePopups();
kenrb5fd60fb82016-06-10 17:27:572073 if (send_preferred_size_changes_ &&
Blink Reformat1c4d759e2017-04-09 16:34:542074 webview()->MainFrame()->IsWebLocalFrame()) {
lukasza302fcdd2017-06-02 20:40:352075 webview()->MainFrame()->ToWebLocalFrame()->SetCanHaveScrollbars(
2076 ShouldDisplayScrollbars(params.new_size.width(),
2077 params.new_size.height()));
[email protected]cda45c02010-02-25 19:28:102078 }
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122079 if (display_mode_ != params.display_mode) {
2080 display_mode_ = params.display_mode;
Blink Reformat1c4d759e2017-04-09 16:34:542081 webview()->SetDisplayMode(display_mode_);
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122082 }
[email protected]cda45c02010-02-25 19:28:102083 }
2084
mdjones2ee41afd2016-10-27 16:50:202085 browser_controls_shrink_blink_size_ =
2086 params.browser_controls_shrink_blink_size;
bokanc63441c2016-04-27 15:49:122087 top_controls_height_ = params.top_controls_height;
Matthew Jones7e156182017-07-21 22:21:332088 bottom_controls_height_ = params.bottom_controls_height;
bokanc63441c2016-04-27 15:49:122089
[email protected]0fdd5012013-05-29 08:05:562090 RenderWidget::OnResize(params);
[email protected]30f75e62009-02-25 22:01:002091}
[email protected]0aa477bd2009-03-23 22:21:432092
[email protected]61f91832014-05-13 01:24:422093void RenderViewImpl::OnSetBackgroundOpaque(bool opaque) {
esecklerf2bd55f72017-03-31 09:11:572094 if (!frame_widget_)
2095 return;
2096
2097 if (opaque) {
Blink Reformat1c4d759e2017-04-09 16:34:542098 frame_widget_->ClearBaseBackgroundColorOverride();
2099 frame_widget_->ClearBackgroundColorOverride();
esecklerf2bd55f72017-03-31 09:11:572100 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542101 frame_widget_->SetBaseBackgroundColorOverride(SK_ColorTRANSPARENT);
2102 frame_widget_->SetBackgroundColorOverride(SK_ColorTRANSPARENT);
esecklerf2bd55f72017-03-31 09:11:572103 }
[email protected]699ab0d2009-04-23 23:19:142104}
2105
[email protected]310ebd6302011-10-10 19:06:282106void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:342107 if (webview())
Blink Reformat1c4d759e2017-04-09 16:34:542108 webview()->SetIsActive(active);
[email protected]8c66c5a2009-07-22 17:26:342109}
2110
lfg8ff33912016-09-13 20:59:212111blink::WebWidget* RenderViewImpl::GetWebWidget() const {
2112 if (frame_widget_)
2113 return frame_widget_;
2114
2115 return RenderWidget::GetWebWidget();
2116}
2117
dcheng3ce04b62015-10-26 23:30:552118void RenderViewImpl::CloseForFrame() {
2119 DCHECK(frame_widget_);
Blink Reformat1c4d759e2017-04-09 16:34:542120 frame_widget_->Close();
dcheng3ce04b62015-10-26 23:30:552121 frame_widget_ = nullptr;
2122}
2123
[email protected]310ebd6302011-10-10 19:06:282124void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:592125 // We need to grab a pointer to the doomed WebView before we destroy it.
lfg4fa48da2016-05-09 18:25:132126 WebView* doomed = webview_;
[email protected]60c42a8c72009-10-09 04:08:592127 RenderWidget::Close();
lfg4fa48da2016-05-09 18:25:132128 webview_ = nullptr;
[email protected]625332e02010-12-14 07:48:492129 g_view_map.Get().erase(doomed);
avia3dca182016-03-19 01:09:522130 g_routing_id_view_map.Get().erase(GetRoutingID());
2131 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(GetRoutingID()));
[email protected]60c42a8c72009-10-09 04:08:592132}
2133
lfg717154072016-06-30 15:04:162134void RenderViewImpl::OnPageWasHidden() {
braveyao1d8ee7b2017-03-29 21:10:042135#if defined(OS_ANDROID)
2136 SuspendVideoCaptureDevices(true);
2137#if BUILDFLAG(ENABLE_WEBRTC)
[email protected]e976c3c52014-07-24 17:41:552138 if (speech_recognition_dispatcher_)
2139 speech_recognition_dispatcher_->AbortAllRecognitions();
[email protected]6392d982013-04-16 16:59:222140#endif
braveyao1d8ee7b2017-03-29 21:10:042141#endif
[email protected]2d7b82c2012-06-01 05:57:502142
lfg717154072016-06-30 15:04:162143 if (webview()) {
2144 // TODO(lfg): It's not correct to defer the page visibility to the main
2145 // frame. Currently, this is done because the main frame may override the
2146 // visibility of the page when prerendering. In order to fix this,
2147 // prerendering must be made aware of OOPIFs. https://crbug.com/440544
xzhan96cf0a3c542017-11-17 04:33:012148 blink::mojom::PageVisibilityState visibilityState =
Blink Reformat1c4d759e2017-04-09 16:34:542149 GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState()
xzhan96cf0a3c542017-11-17 04:33:012150 : blink::mojom::PageVisibilityState::kHidden;
Blink Reformat1c4d759e2017-04-09 16:34:542151 webview()->SetVisibilityState(visibilityState, false);
lfg717154072016-06-30 15:04:162152 }
[email protected]941e4552010-02-01 21:23:432153}
2154
lfg717154072016-06-30 15:04:162155void RenderViewImpl::OnPageWasShown() {
braveyao1d8ee7b2017-03-29 21:10:042156#if defined(OS_ANDROID)
2157 SuspendVideoCaptureDevices(false);
[email protected]6392d982013-04-16 16:59:222158#endif
2159
lfg717154072016-06-30 15:04:162160 if (webview()) {
xzhan96cf0a3c542017-11-17 04:33:012161 blink::mojom::PageVisibilityState visibilityState =
Blink Reformat1c4d759e2017-04-09 16:34:542162 GetMainRenderFrame() ? GetMainRenderFrame()->VisibilityState()
xzhan96cf0a3c542017-11-17 04:33:012163 : blink::mojom::PageVisibilityState::kVisible;
Blink Reformat1c4d759e2017-04-09 16:34:542164 webview()->SetVisibilityState(visibilityState, false);
lfg717154072016-06-30 15:04:162165 }
[email protected]a6939ca42011-02-18 17:58:072166}
[email protected]1e6e3c992010-02-08 15:52:132167
lfg8d649cc2017-04-28 18:04:302168void RenderViewImpl::OnUpdateScreenInfo(const ScreenInfo& screen_info) {
2169 // This IPC only updates the screen info on RenderViews that have a remote
2170 // main frame. For local main frames, the ScreenInfo is updated in
2171 // ViewMsg_Resize.
2172 if (!main_render_frame_)
2173 screen_info_ = screen_info;
2174}
2175
[email protected]ed7defa2013-03-12 21:29:592176GURL RenderViewImpl::GetURLForGraphicsContext3D() {
2177 DCHECK(webview());
Blink Reformat1c4d759e2017-04-09 16:34:542178 if (webview()->MainFrame()->IsWebLocalFrame())
lukaszabedb4b22017-06-23 00:00:132179 return GURL(webview()->MainFrame()->ToWebLocalFrame()->GetDocument().Url());
[email protected]ed7defa2013-03-12 21:29:592180 else
2181 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]65225772011-05-12 21:10:242182}
2183
[email protected]310ebd6302011-10-10 19:06:282184void RenderViewImpl::OnSetFocus(bool enable) {
naskoc6edf7e2015-10-16 01:48:452185 // This message must always be received when the main frame is a
2186 // WebLocalFrame.
Blink Reformat1c4d759e2017-04-09 16:34:542187 CHECK(webview()->MainFrame()->IsWebLocalFrame());
alexmos3fcd0ca2015-10-23 18:18:332188 SetFocus(enable);
2189}
alexmos7fac9aeb2015-10-16 22:39:492190
alexmos3fcd0ca2015-10-23 18:18:332191void RenderViewImpl::SetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:132192 RenderWidget::OnSetFocus(enable);
2193
[email protected]321032992012-11-08 01:01:272194 // Notify all BrowserPlugins of the RenderView's focus state.
fsamuel6c1dfeb2014-12-18 19:21:332195 if (BrowserPluginManager::Get())
2196 BrowserPluginManager::Get()->UpdateFocusState();
[email protected]1e6e3c992010-02-08 15:52:132197}
[email protected]941e4552010-02-01 21:23:432198
rouslanf7ebd8832015-01-22 01:54:142199void RenderViewImpl::DidCompletePageScaleAnimation() {
ekaramad27ca69b12017-04-20 18:34:292200 if (auto* focused_frame = GetWebView()->FocusedFrame()) {
2201 if (focused_frame->AutofillClient())
2202 focused_frame->AutofillClient()->DidCompleteFocusChangeInFrame();
2203 }
rouslanf7ebd8832015-01-22 01:54:142204}
2205
oshimad5279032015-12-16 18:22:332206void RenderViewImpl::OnDeviceScaleFactorChanged() {
2207 RenderWidget::OnDeviceScaleFactorChanged();
2208 UpdateWebViewWithDeviceScaleFactor();
2209 if (auto_resize_mode_)
Fady Samueld10aadd82017-11-03 18:23:572210 AutoResizeCompositor(viz::LocalSurfaceId());
oshimad5279032015-12-16 18:22:332211}
2212
[email protected]b2e4c70132013-10-03 02:07:512213void RenderViewImpl::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:202214 bool enabled,
2215 const blink::WebDeviceEmulationParams& params) {
[email protected]404630b2014-07-03 19:33:032216 if (webview() && compositor()) {
dgozman9260b0a12015-03-16 13:45:202217 if (enabled)
Blink Reformat1c4d759e2017-04-09 16:34:542218 webview()->EnableDeviceEmulation(params);
dgozman9260b0a12015-03-16 13:45:202219 else
Blink Reformat1c4d759e2017-04-09 16:34:542220 webview()->DisableDeviceEmulation();
[email protected]b2e4c70132013-10-03 02:07:512221 }
2222}
2223
Blink Reformat1c4d759e2017-04-09 16:34:542224blink::WebSpeechRecognizer* RenderViewImpl::SpeechRecognizer() {
[email protected]64d09222012-05-25 10:10:342225 if (!speech_recognition_dispatcher_)
2226 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
[email protected]64d09222012-05-25 10:10:342227 return speech_recognition_dispatcher_;
2228}
2229
Blink Reformat1c4d759e2017-04-09 16:34:542230void RenderViewImpl::ZoomLimitsChanged(double minimum_level,
[email protected]310ebd6302011-10-10 19:06:282231 double maximum_level) {
a.sarkar.arundaadc712015-02-26 05:39:082232 // Round the double to avoid returning incorrect minimum/maximum zoom
2233 // percentages.
2234 int minimum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492235 ZoomLevelToZoomFactor(minimum_level) * 100);
a.sarkar.arundaadc712015-02-26 05:39:082236 int maximum_percent = round(
[email protected]7940b8e2013-07-25 23:08:492237 ZoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:252238
avia3dca182016-03-19 01:09:522239 Send(new ViewHostMsg_UpdateZoomLimits(GetRoutingID(), minimum_percent,
fsamuele8326c742016-01-12 00:49:392240 maximum_percent));
[email protected]b75b8292010-10-01 07:28:252241}
2242
Blink Reformat1c4d759e2017-04-09 16:34:542243void RenderViewImpl::PageScaleFactorChanged() {
ccameronb7c1d6c2015-03-09 17:08:242244 if (!webview())
2245 return;
mcnee432e47d2015-11-09 19:37:462246
avia3dca182016-03-19 01:09:522247 Send(new ViewHostMsg_PageScaleFactorChanged(GetRoutingID(),
Blink Reformat1c4d759e2017-04-09 16:34:542248 webview()->PageScaleFactor()));
ccameronb7c1d6c2015-03-09 17:08:242249}
2250
[email protected]7940b8e2013-07-25 23:08:492251double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const {
2252 return ZoomLevelToZoomFactor(zoom_level);
2253}
2254
2255double RenderViewImpl::zoomFactorToZoomLevel(double factor) const {
2256 return ZoomFactorToZoomLevel(factor);
2257}
2258
Blink Reformat1c4d759e2017-04-09 16:34:542259void RenderViewImpl::PageImportanceSignalsChanged() {
kouhei40f03cb2015-09-24 07:47:012260 if (!webview() || !main_render_frame_)
2261 return;
2262
Blink Reformat1c4d759e2017-04-09 16:34:542263 auto* web_signals = webview()->PageImportanceSignals();
kouhei40f03cb2015-09-24 07:47:012264
2265 PageImportanceSignals signals;
Blink Reformat1c4d759e2017-04-09 16:34:542266 signals.had_form_interaction = web_signals->HadFormInteraction();
kouhei40f03cb2015-09-24 07:47:012267
2268 main_render_frame_->Send(new FrameHostMsg_UpdatePageImportanceSignals(
2269 main_render_frame_->GetRoutingID(), signals));
2270}
2271
[email protected]20657a82012-08-21 20:23:032272#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:542273bool RenderViewImpl::OpenDateTimeChooser(
[email protected]180ef242013-11-07 06:50:462274 const blink::WebDateTimeChooserParams& params,
2275 blink::WebDateTimeChooserCompletion* completion) {
[email protected]e8072562013-12-04 06:04:132276 // JavaScript may try to open a date time chooser while one is already open.
2277 if (date_time_picker_client_)
2278 return false;
[email protected]b18583c2012-12-18 06:55:272279 date_time_picker_client_.reset(
2280 new RendererDateTimePicker(this, params, completion));
2281 return date_time_picker_client_->Open();
2282}
2283
[email protected]e8072562013-12-04 06:04:132284void RenderViewImpl::DismissDateTimeDialog() {
2285 DCHECK(date_time_picker_client_);
Lei Zhang88f23ba2017-10-27 05:56:262286 date_time_picker_client_.reset();
[email protected]e8072562013-12-04 06:04:132287}
[email protected]e8072562013-12-04 06:04:132288
Blink Reformat1c4d759e2017-04-09 16:34:542289bool RenderViewImpl::DidTapMultipleTargets(
timav29a8d0f62014-09-25 20:45:532290 const WebSize& inner_viewport_offset,
2291 const WebRect& touch_rect,
[email protected]f9526d12012-10-18 01:55:032292 const WebVector<WebRect>& target_rects) {
[email protected]8d3dfee62013-06-19 05:50:332293 // Never show a disambiguation popup when accessibility is enabled,
2294 // as this interferes with "touch exploration".
Doug Turner63f3c7b2017-07-29 05:10:012295 ui::AXMode accessibility_mode = GetMainRenderFrame()->accessibility_mode();
2296 if (accessibility_mode == ui::kAXModeComplete)
[email protected]8d3dfee62013-06-19 05:50:332297 return false;
2298
timav29a8d0f62014-09-25 20:45:532299 // The touch_rect, target_rects and zoom_rect are in the outer viewport
2300 // reference frame.
[email protected]f9526d12012-10-18 01:55:032301 gfx::Rect zoom_rect;
[email protected]70221f02013-01-31 22:17:072302 float new_total_scale =
2303 DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
timav29a8d0f62014-09-25 20:45:532304 touch_rect, target_rects, GetSize(),
Blink Reformat1c4d759e2017-04-09 16:34:542305 gfx::Rect(webview()->MainFrame()->VisibleContentRect()).size(),
2306 device_scale_factor_ * webview()->PageScaleFactor(), &zoom_rect);
jbauman0ed09182015-01-30 22:33:492307 if (!new_total_scale || zoom_rect.IsEmpty())
[email protected]f9526d12012-10-18 01:55:032308 return false;
2309
[email protected]4ded1dbf2013-08-28 21:11:032310 bool handled = false;
2311 switch (renderer_preferences_.tap_multiple_targets_strategy) {
2312 case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM:
Blink Reformat1c4d759e2017-04-09 16:34:542313 handled = webview()->ZoomToMultipleTargetsRect(zoom_rect);
[email protected]4ded1dbf2013-08-28 21:11:032314 break;
2315 case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: {
[email protected]bc2804d2013-08-06 07:45:492316 gfx::Size canvas_size =
danakjddaec912015-09-25 19:38:402317 gfx::ScaleToCeiledSize(zoom_rect.size(), new_total_scale);
Fady Samuel4b5f9862017-07-11 05:27:202318 viz::SharedBitmapManager* manager =
[email protected]cb189e062014-04-23 00:57:012319 RenderThreadImpl::current()->shared_bitmap_manager();
Fady Samuel4b5f9862017-07-11 05:27:202320 std::unique_ptr<viz::SharedBitmap> shared_bitmap =
[email protected]cb189e062014-04-23 00:57:012321 manager->AllocateSharedBitmap(canvas_size);
Lei Zhang88f23ba2017-10-27 05:56:262322 CHECK(shared_bitmap);
[email protected]bc2804d2013-08-06 07:45:492323 {
[email protected]cb189e062014-04-23 00:57:012324 SkBitmap bitmap;
2325 SkImageInfo info = SkImageInfo::MakeN32Premul(canvas_size.width(),
2326 canvas_size.height());
2327 bitmap.installPixels(info, shared_bitmap->pixels(), info.minRowBytes());
enne98c9f8052017-03-15 19:38:222328 cc::SkiaPaintCanvas canvas(bitmap);
[email protected]f9526d12012-10-18 01:55:032329
[email protected]bc2804d2013-08-06 07:45:492330 // TODO(trchen): Cleanup the device scale factor mess.
2331 // device scale will be applied in WebKit
2332 // --> zoom_rect doesn't include device scale,
2333 // but WebKit will still draw on zoom_rect * device_scale_factor_
[email protected]cb189e062014-04-23 00:57:012334 canvas.scale(new_total_scale / device_scale_factor_,
2335 new_total_scale / device_scale_factor_);
2336 canvas.translate(-zoom_rect.x() * device_scale_factor_,
2337 -zoom_rect.y() * device_scale_factor_);
[email protected]f9526d12012-10-18 01:55:032338
Blink Reformat1c4d759e2017-04-09 16:34:542339 DCHECK(webview_->IsAcceleratedCompositingActive());
2340 webview_->PaintIgnoringCompositing(&canvas, zoom_rect);
[email protected]bc2804d2013-08-06 07:45:492341 }
2342
timav29a8d0f62014-09-25 20:45:532343 gfx::Rect zoom_rect_in_screen =
2344 zoom_rect - gfx::Vector2d(inner_viewport_offset.width,
2345 inner_viewport_offset.height);
2346
[email protected]bc2804d2013-08-06 07:45:492347 gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect(
timav29a8d0f62014-09-25 20:45:532348 ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect_in_screen)));
2349
fsamuele8326c742016-01-12 00:49:392350 Send(new ViewHostMsg_ShowDisambiguationPopup(
avia3dca182016-03-19 01:09:522351 GetRoutingID(), physical_window_zoom_rect, canvas_size,
fsamuele8326c742016-01-12 00:49:392352 shared_bitmap->id()));
Fady Samuel4b5f9862017-07-11 05:27:202353 viz::SharedBitmapId id = shared_bitmap->id();
Lei Zhang88f23ba2017-10-27 05:56:262354 disambiguation_bitmaps_[id] = std::move(shared_bitmap);
[email protected]4ded1dbf2013-08-28 21:11:032355 handled = true;
2356 break;
2357 }
2358 case TAP_MULTIPLE_TARGETS_STRATEGY_NONE:
2359 // No-op.
2360 break;
[email protected]f9526d12012-10-18 01:55:032361 }
[email protected]70221f02013-01-31 22:17:072362
[email protected]4ded1dbf2013-08-28 21:11:032363 return handled;
[email protected]f9526d12012-10-18 01:55:032364}
braveyao1d8ee7b2017-03-29 21:10:042365
2366void RenderViewImpl::SuspendVideoCaptureDevices(bool suspend) {
tsunghunga86cde72017-04-10 22:27:132367#if BUILDFLAG(ENABLE_WEBRTC)
braveyao1d8ee7b2017-03-29 21:10:042368 if (!main_render_frame_)
2369 return;
2370
Chandan Padhi26dbd9b32017-11-27 11:13:352371 MediaStreamDeviceObserver* media_stream_device_observer =
2372 main_render_frame_->GetMediaStreamDeviceObserver();
2373 if (!media_stream_device_observer)
braveyao1d8ee7b2017-03-29 21:10:042374 return;
2375
Chandan Padhi6dbfb732017-09-01 16:08:492376 MediaStreamDevices video_devices =
Chandan Padhi26dbd9b32017-11-27 11:13:352377 media_stream_device_observer->GetNonScreenCaptureDevices();
braveyao1d8ee7b2017-03-29 21:10:042378 RenderThreadImpl::current()->video_capture_impl_manager()->SuspendDevices(
Chandan Padhi6dbfb732017-09-01 16:08:492379 video_devices, suspend);
tsunghunga86cde72017-04-10 22:27:132380#endif // BUILDFLAG(ENABLE_WEBRTC)
braveyao1d8ee7b2017-03-29 21:10:042381}
estade6b9696bd2016-05-04 23:51:362382#endif // defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:032383
[email protected]b283d292013-02-21 08:40:342384unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
2385 return history_list_length_;
2386}
2387
[email protected]cc290f902013-03-04 20:06:022388void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
2389 if (enable) {
2390 if (has_focus())
2391 return;
2392 OnSetActive(true);
2393 OnSetFocus(true);
2394 } else {
2395 if (!has_focus())
2396 return;
2397 OnSetFocus(false);
2398 OnSetActive(false);
2399 }
2400}
2401
[email protected]3a1c8a8032013-03-18 22:35:322402void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) {
fsamuel664e8b62016-01-20 19:54:012403 ResizeParams params;
[email protected]b54fe452013-06-07 14:01:532404 params.screen_info = screen_info_;
ccameron2f451532016-09-07 21:49:272405 params.screen_info.device_scale_factor = factor;
[email protected]b54fe452013-06-07 14:01:532406 params.new_size = size();
bokanf0fd2412014-10-30 15:28:552407 params.visible_viewport_size = visible_viewport_size_;
danakjddaec912015-09-25 19:38:402408 params.physical_backing_size = gfx::ScaleToCeiledSize(size(), factor);
mdjones2ee41afd2016-10-27 16:50:202409 params.browser_controls_shrink_blink_size = false;
dtrainorcb7779b82014-12-04 01:08:022410 params.top_controls_height = 0.f;
mikhail.pozdnyakovf2c902a2015-04-14 08:09:122411 params.is_fullscreen_granted = is_fullscreen_granted();
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122412 params.display_mode = display_mode_;
[email protected]b54fe452013-06-07 14:01:532413 OnResize(params);
[email protected]3a1c8a8032013-03-18 22:35:322414}
2415
ccameron39b1cbc2017-07-06 00:23:552416void RenderViewImpl::SetDeviceColorSpaceForTesting(
2417 const gfx::ColorSpace& color_space) {
mlamouriafca06dd2017-01-27 23:35:182418 ResizeParams params;
2419 params.screen_info = screen_info_;
ccameron39b1cbc2017-07-06 00:23:552420 params.screen_info.color_space = color_space;
mlamouriafca06dd2017-01-27 23:35:182421 params.new_size = size();
2422 params.visible_viewport_size = visible_viewport_size_;
2423 params.physical_backing_size = physical_backing_size_;
2424 params.browser_controls_shrink_blink_size = false;
2425 params.top_controls_height = 0.f;
2426 params.is_fullscreen_granted = is_fullscreen_granted();
2427 params.display_mode = display_mode_;
2428 OnResize(params);
2429}
2430
[email protected]92650162013-10-30 03:31:022431void RenderViewImpl::ForceResizeForTesting(const gfx::Size& new_size) {
Blink Reformat1c4d759e2017-04-09 16:34:542432 gfx::Rect new_window_rect(RootWindowRect().x, RootWindowRect().y,
2433 new_size.width(), new_size.height());
bokanc007c3a2015-02-03 07:15:562434 SetWindowRectSynchronously(new_window_rect);
[email protected]92650162013-10-30 03:31:022435}
2436
[email protected]5b45ad42013-10-25 00:42:042437void RenderViewImpl::UseSynchronousResizeModeForTesting(bool enable) {
2438 resizing_mode_selector_->set_is_synchronous_mode(enable);
2439}
2440
[email protected]eac2b362013-05-22 07:01:452441void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size,
2442 const gfx::Size& max_size) {
2443 OnEnableAutoResize(min_size, max_size);
2444}
2445
2446void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) {
2447 OnDisableAutoResize(new_size);
2448}
2449
[email protected]cb189e062014-04-23 00:57:012450void RenderViewImpl::OnReleaseDisambiguationPopupBitmap(
Fady Samuel4b5f9862017-07-11 05:27:202451 const viz::SharedBitmapId& id) {
Lei Zhang88f23ba2017-10-27 05:56:262452 size_t erased_count = disambiguation_bitmaps_.erase(id);
2453 DCHECK_EQ(1U, erased_count);
[email protected]f9526d12012-10-18 01:55:032454}
[email protected]e9ff79c2012-10-19 21:31:262455
aelias1b55156e52017-04-01 00:46:052456void RenderViewImpl::OnResolveTapDisambiguation(double timestamp_seconds,
2457 gfx::Point tap_viewport_offset,
2458 bool is_long_press) {
Blink Reformat1c4d759e2017-04-09 16:34:542459 webview()->ResolveTapDisambiguation(timestamp_seconds, tap_viewport_offset,
aelias1b55156e52017-04-01 00:46:052460 is_long_press);
2461}
2462
[email protected]6fceb912013-02-15 06:24:152463void RenderViewImpl::DidCommitCompositorFrame() {
2464 RenderWidget::DidCommitCompositorFrame();
ericwilligers88e69742016-10-17 19:29:552465 for (auto& observer : observers_)
2466 observer.DidCommitCompositorFrame();
[email protected]6fceb912013-02-15 06:24:152467}
2468
oshimad5279032015-12-16 18:22:332469void RenderViewImpl::UpdateWebViewWithDeviceScaleFactor() {
2470 if (!webview())
2471 return;
oshima750cb4342015-10-31 00:59:012472 if (IsUseZoomForDSFEnabled()) {
Blink Reformat1c4d759e2017-04-09 16:34:542473 webview()->SetZoomFactorForDeviceScaleFactor(device_scale_factor_);
oshima750cb4342015-10-31 00:59:012474 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542475 webview()->SetDeviceScaleFactor(device_scale_factor_);
oshima750cb4342015-10-31 00:59:012476 }
Blink Reformat1c4d759e2017-04-09 16:34:542477 webview()->GetSettings()->SetPreferCompositingToLCDTextEnabled(
oshimad5279032015-12-16 18:22:332478 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_));
oshima750cb4342015-10-31 00:59:012479}
2480
dtapuska1b0fcc322016-10-28 18:08:282481void RenderViewImpl::OnDiscardInputEvent(
2482 const blink::WebInputEvent* input_event,
nzolghadr5d8596502017-01-23 22:59:352483 const std::vector<const blink::WebInputEvent*>& coalesced_events,
dtapuska1b0fcc322016-10-28 18:08:282484 const ui::LatencyInfo& latency_info,
2485 InputEventDispatchType dispatch_type) {
dtapuska9ec1a912017-04-21 15:18:312486 if (!input_event || dispatch_type == DISPATCH_TYPE_NON_BLOCKING) {
dtapuska1b0fcc322016-10-28 18:08:282487 return;
2488 }
2489
Dave Tapuskaea83d3bd2017-06-13 16:14:552490 InputEventAck ack(InputEventAckSource::MAIN_THREAD, input_event->GetType(),
2491 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2492 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
dtapuska1b0fcc322016-10-28 18:08:282493}
2494
Dave Tapuskaea83d3bd2017-06-13 16:14:552495void RenderViewImpl::HandleInputEvent(
dtapuska9ec1a912017-04-21 15:18:312496 const blink::WebCoalescedInputEvent& input_event,
2497 const ui::LatencyInfo& latency_info,
Dave Tapuskaea83d3bd2017-06-13 16:14:552498 HandledEventCallback callback) {
dtapuska9ec1a912017-04-21 15:18:312499 if (is_swapped_out_) {
Dave Tapuskaea83d3bd2017-06-13 16:14:552500 std::move(callback).Run(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, latency_info,
Dave Tapuskab28a1082017-08-30 15:37:262501 nullptr, base::nullopt);
Dave Tapuskaea83d3bd2017-06-13 16:14:552502 return;
dtapuska9ec1a912017-04-21 15:18:312503 }
2504 idle_user_detector_->ActivityDetected();
Dave Tapuskaea83d3bd2017-06-13 16:14:552505 RenderWidget::HandleInputEvent(input_event, latency_info,
2506 std::move(callback));
dtapuska9ec1a912017-04-21 15:18:312507}
2508
[email protected]e9ff79c2012-10-19 21:31:262509} // namespace content