blob: f18ab1f55173ccc008da67b5ce529065b2cd53b2 [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>
initial.commit09911bf2008-07-26 23:55:299
[email protected]5d4e36d2013-02-15 15:18:2010#include "base/auto_reset.h"
[email protected]6e806822011-11-19 01:51:0811#include "base/bind.h"
12#include "base/bind_helpers.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5014#include "base/compiler_specific.h"
[email protected]2132d6b2013-06-05 00:15:4315#include "base/debug/alias.h"
creis9f7248b2016-01-27 20:27:3916#include "base/debug/crash_logging.h"
[email protected]728c2ee2013-06-25 04:01:0717#include "base/files/file_path.h"
[email protected]edc3af82013-12-12 21:24:0718#include "base/i18n/rtl.h"
[email protected]b1cf3372011-04-20 21:28:1019#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4920#include "base/lazy_instance.h"
[email protected]cffd7522012-10-23 19:10:5821#include "base/memory/scoped_ptr.h"
[email protected]f29efe6b2014-06-09 05:01:5122#include "base/metrics/field_trial.h"
[email protected]835d7c82010-10-14 04:38:3823#include "base/metrics/histogram.h"
[email protected]d3b4ee22013-07-24 22:50:0624#include "base/process/kill.h"
[email protected]7d08a9352013-10-15 08:24:5625#include "base/process/process.h"
[email protected]21aa99682013-06-11 07:17:0126#include "base/strings/string_number_conversions.h"
[email protected]b9e7c479f2013-04-12 04:33:2427#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4928#include "base/strings/string_split.h"
[email protected]21aa99682013-06-11 07:17:0129#include "base/strings/string_util.h"
[email protected]40d11e02013-03-28 17:43:1430#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0031#include "base/strings/utf_string_conversions.h"
[email protected]abb522162013-06-28 01:54:1632#include "base/time/time.h"
primiano9e38d552015-01-28 04:18:0133#include "base/trace_event/trace_event.h"
avi1023d012015-12-25 02:39:1434#include "build/build_config.h"
dongseong.hwange095dfa2016-02-04 11:21:3935#include "cc/base/switches.h"
[email protected]a8cb3b73b2013-08-12 05:50:5036#include "content/child/appcache/appcache_dispatcher.h"
37#include "content/child/appcache/web_application_cache_host_impl.h"
[email protected]cb189e062014-04-23 00:57:0138#include "content/child/child_shared_bitmap_manager.h"
[email protected]29e2fb42013-07-19 01:13:4739#include "content/child/npapi/webplugin_delegate_impl.h"
[email protected]541b7b02013-06-07 00:59:3440#include "content/child/request_extra_data.h"
mek87e0ab52015-02-13 01:18:2641#include "content/child/v8_value_converter_impl.h"
[email protected]10208ea2013-06-06 20:08:0342#include "content/child/webmessageportchannel_impl.h"
jinho.bang632a1a722014-09-18 03:02:5643#include "content/common/content_constants_internal.h"
oshima750cb4342015-10-31 00:59:0144#include "content/common/content_switches_internal.h"
[email protected]37666cf2011-03-13 21:51:4245#include "content/common/database_messages.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]c26ad882012-02-07 06:41:2050#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
dtapuska0bd451a2016-02-18 17:08:1051#include "content/common/input/input_event_utils.h"
[email protected]c084330e02013-04-27 01:08:1552#include "content/common/input_messages.h"
[email protected]127dd582011-03-16 21:32:1053#include "content/common/pepper_messages.h"
nickac60e75472015-07-31 00:44:3554#include "content/common/site_isolation_policy.h"
[email protected]e4495212012-12-06 03:09:1255#include "content/common/ssl_status_serialization.h"
[email protected]778574e2011-03-21 22:03:5056#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2157#include "content/public/common/bindings_policy.h"
[email protected]744c2a22012-03-15 18:42:0458#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4859#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2960#include "content/public/common/content_switches.h"
[email protected]dc293a72013-07-01 11:11:2261#include "content/public/common/drop_data.h"
[email protected]41225fe2013-03-29 05:32:0262#include "content/public/common/favicon_url.h"
hirono570357bd2014-10-08 12:39:2763#include "content/public/common/file_chooser_file_info.h"
[email protected]8caadeb2011-11-22 02:45:2364#include "content/public/common/file_chooser_params.h"
kouhei40f03cb2015-09-24 07:47:0165#include "content/public/common/page_importance_signals.h"
clamyda97e8322014-10-07 21:57:2566#include "content/public/common/page_state.h"
[email protected]7940b8e2013-07-25 23:08:4967#include "content/public/common/page_zoom.h"
[email protected]e4495212012-12-06 03:09:1268#include "content/public/common/ssl_status.h"
[email protected]818915cd2012-11-20 13:14:1169#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0370#include "content/public/common/url_constants.h"
[email protected]b3a97b52014-07-09 06:25:0571#include "content/public/common/web_preferences.h"
[email protected]d344114c2011-10-01 01:24:3472#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0773#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3274#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4475#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3676#include "content/public/renderer/render_view_visitor.h"
[email protected]e6e56752012-08-10 00:46:0677#include "content/renderer/browser_plugin/browser_plugin.h"
78#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]f9526d12012-10-18 01:55:0379#include "content/renderer/disambiguation_popup_helper.h"
[email protected]1910fe82012-05-10 00:04:1080#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]dc293a72013-07-01 11:11:2281#include "content/renderer/drop_data_builder.h"
[email protected]ba91a792013-02-06 09:48:2882#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]d4734982014-04-15 02:05:5583#include "content/renderer/history_controller.h"
[email protected]dc064352014-04-25 08:36:3884#include "content/renderer/history_serialization.h"
[email protected]1784b2f2011-11-24 10:53:4885#include "content/renderer/idle_user_detector.h"
[email protected]66fca5bc2013-05-23 06:58:2986#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1387#include "content/renderer/input/input_handler_manager.h"
[email protected]92d457802013-04-01 19:18:4988#include "content/renderer/internal_document_state_data.h"
[email protected]4a914882013-01-10 00:43:4889#include "content/renderer/media/audio_device_factory.h"
[email protected]6392d982013-04-16 16:59:2290#include "content/renderer/media/video_capture_impl_manager.h"
clamy5f342202015-03-18 13:47:5691#include "content/renderer/navigation_state_impl.h"
[email protected]227692c52013-05-31 22:43:0492#include "content/renderer/render_frame_impl.h"
[email protected]5a7100d2014-05-19 01:29:0493#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0594#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4495#include "content/renderer/render_thread_impl.h"
[email protected]89054502012-06-03 10:29:2496#include "content/renderer/render_view_mouse_lock_dispatcher.h"
[email protected]2cff0052011-03-18 16:51:4497#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]663bd9e2011-03-21 01:07:0198#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]5b45ad42013-10-25 00:42:0499#include "content/renderer/resizing_mode_selector.h"
[email protected]12a936d2013-05-15 04:55:49100#include "content/renderer/savable_resources.h"
[email protected]64d09222012-05-25 10:10:34101#include "content/renderer/speech_recognition_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:32102#include "content/renderer/text_input_client_observer.h"
[email protected]940ed1d2012-11-27 21:03:21103#include "content/renderer/web_ui_extension_data.h"
[email protected]6f516082011-03-17 19:15:35104#include "content/renderer/websharedworker_proxy.h"
[email protected]f5961142013-04-17 23:09:42105#include "media/audio/audio_output_device.h"
[email protected]ee68378a2010-08-10 01:05:41106#include "media/base/media_switches.h"
servolkf54f5c8f2015-02-24 20:32:39107#include "media/renderers/audio_renderer_impl.h"
servolk8b3b39b2015-03-03 19:08:18108#include "media/renderers/gpu_video_accelerator_factories.h"
[email protected]d1ef81d2012-07-24 11:39:36109#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29110#include "net/base/escape.h"
111#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09112#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04113#include "net/http/http_util.h"
lukenb171b532014-09-24 05:50:38114#include "skia/ext/platform_canvas.h"
kinukob473f002016-02-22 05:23:19115#include "third_party/WebKit/public/platform/FilePathConversion.h"
brettwdfbcc3b2016-01-20 01:49:17116#include "third_party/WebKit/public/platform/URLConversion.h"
[email protected]d0fcff72013-07-23 02:45:43117#include "third_party/WebKit/public/platform/WebCString.h"
[email protected]b3a97b52014-07-09 06:25:05118#include "third_party/WebKit/public/platform/WebConnectionType.h"
[email protected]d0fcff72013-07-23 02:45:43119#include "third_party/WebKit/public/platform/WebDragData.h"
[email protected]d0fcff72013-07-23 02:45:43120#include "third_party/WebKit/public/platform/WebHTTPBody.h"
121#include "third_party/WebKit/public/platform/WebImage.h"
122#include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
123#include "third_party/WebKit/public/platform/WebPoint.h"
124#include "third_party/WebKit/public/platform/WebRect.h"
125#include "third_party/WebKit/public/platform/WebSize.h"
[email protected]ec173b522013-11-14 11:01:18126#include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h"
[email protected]d0fcff72013-07-23 02:45:43127#include "third_party/WebKit/public/platform/WebString.h"
128#include "third_party/WebKit/public/platform/WebURL.h"
129#include "third_party/WebKit/public/platform/WebURLError.h"
130#include "third_party/WebKit/public/platform/WebURLRequest.h"
131#include "third_party/WebKit/public/platform/WebURLResponse.h"
132#include "third_party/WebKit/public/platform/WebVector.h"
[email protected]10760e4a2013-09-04 23:32:20133#include "third_party/WebKit/public/web/WebAXObject.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"
137#include "third_party/WebKit/public/web/WebDataSource.h"
138#include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h"
139#include "third_party/WebKit/public/web/WebDateTimeChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31140#include "third_party/WebKit/public/web/WebDocument.h"
141#include "third_party/WebKit/public/web/WebElement.h"
142#include "third_party/WebKit/public/web/WebFileChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31143#include "third_party/WebKit/public/web/WebFormControlElement.h"
144#include "third_party/WebKit/public/web/WebFormElement.h"
145#include "third_party/WebKit/public/web/WebFrame.h"
dglazkov03223492016-02-08 22:16:03146#include "third_party/WebKit/public/web/WebFrameContentDumper.h"
lfgcaab5142016-02-26 19:06:52147#include "third_party/WebKit/public/web/WebFrameWidget.h"
[email protected]2255a9332013-06-17 05:12:31148#include "third_party/WebKit/public/web/WebHistoryItem.h"
[email protected]91dcc6d32014-07-30 00:01:33149#include "third_party/WebKit/public/web/WebHitTestResult.h"
[email protected]2255a9332013-06-17 05:12:31150#include "third_party/WebKit/public/web/WebInputElement.h"
151#include "third_party/WebKit/public/web/WebInputEvent.h"
[email protected]35b2a972014-04-04 15:50:22152#include "third_party/WebKit/public/web/WebLocalFrame.h"
[email protected]2255a9332013-06-17 05:12:31153#include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
154#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
kouhei40f03cb2015-09-24 07:47:01155#include "third_party/WebKit/public/web/WebPageImportanceSignals.h"
[email protected]2255a9332013-06-17 05:12:31156#include "third_party/WebKit/public/web/WebPlugin.h"
157#include "third_party/WebKit/public/web/WebPluginAction.h"
[email protected]2255a9332013-06-17 05:12:31158#include "third_party/WebKit/public/web/WebRange.h"
[email protected]b3a97b52014-07-09 06:25:05159#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
[email protected]2255a9332013-06-17 05:12:31160#include "third_party/WebKit/public/web/WebScriptSource.h"
161#include "third_party/WebKit/public/web/WebSearchableFormData.h"
[email protected]2255a9332013-06-17 05:12:31162#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
[email protected]2255a9332013-06-17 05:12:31163#include "third_party/WebKit/public/web/WebSettings.h"
[email protected]2255a9332013-06-17 05:12:31164#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
[email protected]2255a9332013-06-17 05:12:31165#include "third_party/WebKit/public/web/WebView.h"
166#include "third_party/WebKit/public/web/WebWindowFeatures.h"
167#include "third_party/WebKit/public/web/default/WebRenderTheme.h"
[email protected]b3a97b52014-07-09 06:25:05168#include "third_party/icu/source/common/unicode/uchar.h"
169#include "third_party/icu/source/common/unicode/uscript.h"
[email protected]4ee64622014-03-21 22:34:15170#include "ui/base/clipboard/clipboard.h"
[email protected]1400e6dc2013-04-27 02:36:27171#include "ui/base/ui_base_switches_util.h"
[email protected]7d08a9352013-10-15 08:24:56172#include "ui/events/latency_info.h"
tfarina655f81d2014-12-23 02:38:50173#include "ui/gfx/geometry/point.h"
tfarina3b0452d2014-12-31 15:20:09174#include "ui/gfx/geometry/rect.h"
175#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32176#include "ui/gfx/geometry/size_conversions.h"
[email protected]08397d52011-02-05 01:53:38177#include "ui/gfx/native_widget_types.h"
markdittmer67b71ea2016-03-03 22:40:03178#include "url/url_constants.h"
[email protected]c4a9e932011-03-05 04:05:55179#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:29180
[email protected]25fb9b32012-04-27 03:21:55181#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25182#include <cpu-features.h>
183
[email protected]20657a82012-08-21 20:23:03184#include "content/renderer/android/address_detector.h"
185#include "content/renderer/android/content_detector.h"
186#include "content/renderer/android/email_detector.h"
187#include "content/renderer/android/phone_number_detector.h"
tfarina3b0452d2014-12-31 15:20:09188#include "ui/gfx/geometry/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40189
[email protected]25fb9b32012-04-27 03:21:55190#elif defined(OS_WIN)
[email protected]6c8afae52009-01-22 02:24:57191// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57192// * theming
[email protected]990e6222012-11-16 13:31:18193#include "ui/native_theme/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03194#elif defined(USE_X11)
[email protected]990e6222012-11-16 13:31:18195#include "ui/native_theme/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33196#elif defined(OS_MACOSX)
197#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57198#endif
199
[email protected]ea2fb972013-08-07 05:44:26200#if defined(ENABLE_PLUGINS)
[email protected]a80af12e2013-08-07 23:36:13201#include "content/renderer/npapi/webplugin_delegate_proxy.h"
[email protected]ea2fb972013-08-07 05:44:26202#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
203#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26204#endif
205
[email protected]9ac667e2013-09-09 12:49:21206#if defined(ENABLE_WEBRTC)
207#include "content/renderer/media/rtc_peer_connection_handler.h"
[email protected]22fe91d2014-08-12 17:07:12208#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
[email protected]9ac667e2013-09-09 12:49:21209#endif
210
[email protected]180ef242013-11-07 06:50:46211using blink::WebAXObject;
212using blink::WebApplicationCacheHost;
213using blink::WebApplicationCacheHostClient;
214using blink::WebCString;
215using blink::WebColor;
[email protected]180ef242013-11-07 06:50:46216using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46217using blink::WebData;
218using blink::WebDataSource;
219using blink::WebDocument;
[email protected]180ef242013-11-07 06:50:46220using blink::WebDragData;
221using blink::WebDragOperation;
222using blink::WebDragOperationsMask;
223using blink::WebElement;
[email protected]180ef242013-11-07 06:50:46224using blink::WebFileChooserCompletion;
[email protected]180ef242013-11-07 06:50:46225using blink::WebFormControlElement;
226using blink::WebFormElement;
227using blink::WebFrame;
dglazkov03223492016-02-08 22:16:03228using blink::WebFrameContentDumper;
[email protected]180ef242013-11-07 06:50:46229using blink::WebGestureEvent;
230using blink::WebHistoryItem;
231using blink::WebHTTPBody;
232using blink::WebIconURL;
233using blink::WebImage;
234using blink::WebInputElement;
235using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22236using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46237using blink::WebMediaPlayerAction;
[email protected]180ef242013-11-07 06:50:46238using blink::WebMouseEvent;
239using blink::WebNavigationPolicy;
240using blink::WebNavigationType;
241using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46242using blink::WebPeerConnection00Handler;
243using blink::WebPeerConnection00HandlerClient;
244using blink::WebPeerConnectionHandler;
245using blink::WebPeerConnectionHandlerClient;
246using blink::WebPluginAction;
[email protected]180ef242013-11-07 06:50:46247using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46248using blink::WebRange;
249using blink::WebRect;
250using blink::WebReferrerPolicy;
[email protected]180ef242013-11-07 06:50:46251using blink::WebScriptSource;
252using blink::WebSearchableFormData;
253using blink::WebSecurityOrigin;
254using blink::WebSecurityPolicy;
[email protected]180ef242013-11-07 06:50:46255using blink::WebSettings;
256using blink::WebSize;
[email protected]180ef242013-11-07 06:50:46257using blink::WebStorageNamespace;
258using blink::WebStorageQuotaCallbacks;
259using blink::WebStorageQuotaError;
260using blink::WebStorageQuotaType;
261using blink::WebString;
[email protected]180ef242013-11-07 06:50:46262using blink::WebTextDirection;
263using blink::WebTouchEvent;
264using blink::WebURL;
265using blink::WebURLError;
266using blink::WebURLRequest;
267using blink::WebURLResponse;
268using blink::WebUserGestureIndicator;
269using blink::WebVector;
270using blink::WebView;
271using blink::WebWidget;
272using blink::WebWindowFeatures;
[email protected]b3a97b52014-07-09 06:25:05273using blink::WebRuntimeFeatures;
[email protected]6fdd4182010-10-14 23:59:26274using base::Time;
275using base::TimeDelta;
[email protected]e1acf6f2008-10-27 20:43:33276
[email protected]20657a82012-08-21 20:23:03277#if defined(OS_ANDROID)
[email protected]180ef242013-11-07 06:50:46278using blink::WebContentDetectionResult;
[email protected]180ef242013-11-07 06:50:46279using blink::WebHitTestResult;
[email protected]20657a82012-08-21 20:23:03280#endif
281
[email protected]e9ff79c2012-10-19 21:31:26282namespace content {
283
initial.commit09911bf2008-07-26 23:55:29284//-----------------------------------------------------------------------------
285
[email protected]180ef242013-11-07 06:50:46286typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49287static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
avi1023d012015-12-25 02:39:14288typedef std::map<int32_t, RenderViewImpl*> RoutingIDViewMap;
[email protected]058561b2012-12-03 06:48:22289static base::LazyInstance<RoutingIDViewMap> g_routing_id_view_map =
290 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02291
[email protected]882daa92009-11-05 16:31:31292// Time, in seconds, we delay before sending content state changes (such as form
293// state and scroll position) to the browser. We delay sending changes to avoid
294// spamming the browser.
295// To avoid having tab/session restore require sending a message to get the
296// current content state during tab closing we use a shorter timeout for the
297// foreground renderer. This means there is a small window of time from which
298// content state is modified and not sent to session restore, but this is
299// better than having to wake up all renderers during shutdown.
avif937e1d2014-11-02 18:13:07300const int kDelaySecondsForContentStateSyncHidden = 5;
301const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29302
[email protected]20657a82012-08-21 20:23:03303#if defined(OS_ANDROID)
304// Delay between tapping in content and launching the associated android intent.
305// Used to allow users see what has been recognized as content.
[email protected]9afc14e22013-09-25 22:34:14306const size_t kContentIntentDelayMilliseconds = 700;
[email protected]20657a82012-08-21 20:23:03307#endif
308
dcheng35d31c112015-07-22 00:17:36309static RenderViewImpl* (*g_create_render_view_impl)(
310 CompositorDependencies* compositor_deps,
311 const ViewMsg_New_Params&) = nullptr;
[email protected]8d41d7612012-11-14 20:32:19312
[email protected]c6bc20332014-02-28 18:30:39313// static
[email protected]e507045d2013-07-24 15:23:44314Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56315 WebFrame* frame,
316 const WebURLRequest& request) {
brettwdfbcc3b2016-01-20 01:49:17317 return Referrer(
318 blink::WebStringToGURL(request.httpHeaderField(
319 WebString::fromUTF8("Referer"))),
320 request.referrerPolicy());
[email protected]44e55b012013-07-23 14:21:56321}
322
[email protected]c6bc20332014-02-28 18:30:39323// static
[email protected]65920f332014-03-04 21:14:18324WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32325 WebNavigationPolicy policy) {
326 switch (policy) {
[email protected]180ef242013-11-07 06:50:46327 case blink::WebNavigationPolicyIgnore:
[email protected]48861e22013-01-09 00:27:32328 return IGNORE_ACTION;
[email protected]180ef242013-11-07 06:50:46329 case blink::WebNavigationPolicyDownload:
[email protected]48861e22013-01-09 00:27:32330 return SAVE_TO_DISK;
[email protected]180ef242013-11-07 06:50:46331 case blink::WebNavigationPolicyCurrentTab:
[email protected]48861e22013-01-09 00:27:32332 return CURRENT_TAB;
[email protected]180ef242013-11-07 06:50:46333 case blink::WebNavigationPolicyNewBackgroundTab:
[email protected]48861e22013-01-09 00:27:32334 return NEW_BACKGROUND_TAB;
[email protected]180ef242013-11-07 06:50:46335 case blink::WebNavigationPolicyNewForegroundTab:
[email protected]48861e22013-01-09 00:27:32336 return NEW_FOREGROUND_TAB;
[email protected]180ef242013-11-07 06:50:46337 case blink::WebNavigationPolicyNewWindow:
[email protected]48861e22013-01-09 00:27:32338 return NEW_WINDOW;
[email protected]180ef242013-11-07 06:50:46339 case blink::WebNavigationPolicyNewPopup:
[email protected]48861e22013-01-09 00:27:32340 return NEW_POPUP;
341 default:
342 NOTREACHED() << "Unexpected WebNavigationPolicy";
343 return IGNORE_ACTION;
344 }
345}
346
[email protected]d8221b22013-05-23 05:35:43347// Returns true if the device scale is high enough that losing subpixel
348// antialiasing won't have a noticeable effect on text quality.
349static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
350#if defined(OS_ANDROID)
351 // On Android, we never have subpixel antialiasing.
352 return true;
353#else
jdduke7d452b4a2015-08-19 21:25:21354 // 1.5 is a common touchscreen tablet device scale factor. For such
355 // devices main thread antialiasing is a heavy burden.
356 return device_scale_factor >= 1.5f;
[email protected]d8221b22013-05-23 05:35:43357#endif
[email protected]d8221b22013-05-23 05:35:43358}
359
danakj6e3bf8012014-12-16 18:27:53360static bool PreferCompositingToLCDText(CompositorDependencies* compositor_deps,
361 float device_scale_factor) {
avi83883c82014-12-23 00:08:49362 const base::CommandLine& command_line =
363 *base::CommandLine::ForCurrentProcess();
[email protected]b8ec1112014-08-17 20:09:10364 if (command_line.HasSwitch(switches::kDisablePreferCompositingToLCDText))
[email protected]fb854192013-02-06 01:30:04365 return false;
[email protected]b8ec1112014-08-17 20:09:10366 if (command_line.HasSwitch(switches::kEnablePreferCompositingToLCDText))
[email protected]fb854192013-02-06 01:30:04367 return true;
danakj6e3bf8012014-12-16 18:27:53368 if (!compositor_deps->IsLcdTextEnabled())
[email protected]10c19732014-08-18 19:39:23369 return true;
[email protected]d8221b22013-05-23 05:35:43370 return DeviceScaleEnsuresTextQuality(device_scale_factor);
371}
372
[email protected]180ef242013-11-07 06:50:46373static FaviconURL::IconType ToFaviconType(blink::WebIconURL::Type type) {
[email protected]41225fe2013-03-29 05:32:02374 switch (type) {
[email protected]180ef242013-11-07 06:50:46375 case blink::WebIconURL::TypeFavicon:
[email protected]41225fe2013-03-29 05:32:02376 return FaviconURL::FAVICON;
[email protected]180ef242013-11-07 06:50:46377 case blink::WebIconURL::TypeTouch:
[email protected]41225fe2013-03-29 05:32:02378 return FaviconURL::TOUCH_ICON;
[email protected]180ef242013-11-07 06:50:46379 case blink::WebIconURL::TypeTouchPrecomposed:
[email protected]41225fe2013-03-29 05:32:02380 return FaviconURL::TOUCH_PRECOMPOSED_ICON;
[email protected]180ef242013-11-07 06:50:46381 case blink::WebIconURL::TypeInvalid:
[email protected]41225fe2013-03-29 05:32:02382 return FaviconURL::INVALID_ICON;
383 }
384 return FaviconURL::INVALID_ICON;
385}
386
[email protected]f34ac132014-03-20 23:02:05387static void ConvertToFaviconSizes(
388 const blink::WebVector<blink::WebSize>& web_sizes,
389 std::vector<gfx::Size>* sizes) {
[email protected]2bd262b2014-04-16 05:31:23390 DCHECK(sizes->empty());
391 sizes->reserve(web_sizes.size());
[email protected]f34ac132014-03-20 23:02:05392 for (size_t i = 0; i < web_sizes.size(); ++i)
393 sizes->push_back(gfx::Size(web_sizes[i]));
394}
395
initial.commit09911bf2008-07-26 23:55:29396///////////////////////////////////////////////////////////////////////////////
397
[email protected]310ebd6302011-10-10 19:06:28398struct RenderViewImpl::PendingFileChooser {
[email protected]e9ff79c2012-10-19 21:31:26399 PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c)
[email protected]cdaf8d02010-03-30 19:52:47400 : params(p),
401 completion(c) {
402 }
[email protected]e9ff79c2012-10-19 21:31:26403 FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47404 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
405};
406
[email protected]217690d2012-01-27 07:33:11407namespace {
408
409class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
410 public:
[email protected]180ef242013-11-07 06:50:46411 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
[email protected]217690d2012-01-27 07:33:11412 : webwidget_(webwidget) {}
413
dcheng6d18e402014-10-21 12:32:52414 void OnLockMouseACK(bool succeeded) override {
[email protected]217690d2012-01-27 07:33:11415 if (succeeded)
416 webwidget_->didAcquirePointerLock();
417 else
418 webwidget_->didNotAcquirePointerLock();
419 }
420
dcheng6d18e402014-10-21 12:32:52421 void OnMouseLockLost() override { webwidget_->didLosePointerLock(); }
[email protected]217690d2012-01-27 07:33:11422
dcheng6d18e402014-10-21 12:32:52423 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
[email protected]217690d2012-01-27 07:33:11424 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
425 return false;
426 }
427
428 private:
[email protected]180ef242013-11-07 06:50:46429 blink::WebWidget* webwidget_;
[email protected]217690d2012-01-27 07:33:11430};
431
[email protected]dc293a72013-07-01 11:11:22432WebDragData DropDataToWebDragData(const DropData& drop_data) {
[email protected]c10680312013-05-31 15:22:05433 std::vector<WebDragData::Item> item_list;
434
435 // These fields are currently unused when dragging into WebKit.
436 DCHECK(drop_data.download_metadata.empty());
437 DCHECK(drop_data.file_contents.empty());
438 DCHECK(drop_data.file_description_filename.empty());
439
440 if (!drop_data.text.is_null()) {
441 WebDragData::Item item;
442 item.storageType = WebDragData::Item::StorageTypeString;
443 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText);
444 item.stringData = drop_data.text.string();
445 item_list.push_back(item);
446 }
447
448 // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it
449 // meaningful to write an empty URL to the clipboard?
450 if (!drop_data.url.is_empty()) {
451 WebDragData::Item item;
452 item.storageType = WebDragData::Item::StorageTypeString;
453 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList);
454 item.stringData = WebString::fromUTF8(drop_data.url.spec());
455 item.title = drop_data.url_title;
456 item_list.push_back(item);
457 }
458
459 if (!drop_data.html.is_null()) {
460 WebDragData::Item item;
461 item.storageType = WebDragData::Item::StorageTypeString;
462 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML);
463 item.stringData = drop_data.html.string();
464 item.baseURL = drop_data.html_base_url;
465 item_list.push_back(item);
466 }
467
[email protected]17ea0ae22014-03-28 21:54:46468 for (std::vector<ui::FileInfo>::const_iterator it =
[email protected]c10680312013-05-31 15:22:05469 drop_data.filenames.begin();
470 it != drop_data.filenames.end();
471 ++it) {
472 WebDragData::Item item;
473 item.storageType = WebDragData::Item::StorageTypeFilename;
[email protected]17ea0ae22014-03-28 21:54:46474 item.filenameData = it->path.AsUTF16Unsafe();
475 item.displayNameData = it->display_name.AsUTF16Unsafe();
[email protected]c10680312013-05-31 15:22:05476 item_list.push_back(item);
477 }
478
[email protected]60ed95f2014-04-23 12:19:48479 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it =
480 drop_data.file_system_files.begin();
481 it != drop_data.file_system_files.end();
482 ++it) {
483 WebDragData::Item item;
484 item.storageType = WebDragData::Item::StorageTypeFileSystemFile;
485 item.fileSystemURL = it->url;
486 item.fileSystemFileSize = it->size;
487 item_list.push_back(item);
488 }
489
[email protected]c10680312013-05-31 15:22:05490 for (std::map<base::string16, base::string16>::const_iterator it =
491 drop_data.custom_data.begin();
492 it != drop_data.custom_data.end();
493 ++it) {
494 WebDragData::Item item;
495 item.storageType = WebDragData::Item::StorageTypeString;
496 item.stringType = it->first;
497 item.stringData = it->second;
498 item_list.push_back(item);
499 }
500
501 WebDragData result;
502 result.initialize();
503 result.setItems(item_list);
504 result.setFilesystemId(drop_data.filesystem_id);
505 return result;
506}
507
[email protected]b3a97b52014-07-09 06:25:05508typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
509 const base::string16&,
510 UScriptCode);
511
512void SetStandardFontFamilyWrapper(WebSettings* settings,
513 const base::string16& font,
514 UScriptCode script) {
515 settings->setStandardFontFamily(font, script);
516}
517
518void SetFixedFontFamilyWrapper(WebSettings* settings,
519 const base::string16& font,
520 UScriptCode script) {
521 settings->setFixedFontFamily(font, script);
522}
523
524void SetSerifFontFamilyWrapper(WebSettings* settings,
525 const base::string16& font,
526 UScriptCode script) {
527 settings->setSerifFontFamily(font, script);
528}
529
530void SetSansSerifFontFamilyWrapper(WebSettings* settings,
531 const base::string16& font,
532 UScriptCode script) {
533 settings->setSansSerifFontFamily(font, script);
534}
535
536void SetCursiveFontFamilyWrapper(WebSettings* settings,
537 const base::string16& font,
538 UScriptCode script) {
539 settings->setCursiveFontFamily(font, script);
540}
541
542void SetFantasyFontFamilyWrapper(WebSettings* settings,
543 const base::string16& font,
544 UScriptCode script) {
545 settings->setFantasyFontFamily(font, script);
546}
547
548void SetPictographFontFamilyWrapper(WebSettings* settings,
549 const base::string16& font,
550 UScriptCode script) {
551 settings->setPictographFontFamily(font, script);
552}
553
554// If |scriptCode| is a member of a family of "similar" script codes, returns
555// the script code in that family that is used by WebKit for font selection
556// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
557// considered equivalent for the purposes of font selection. WebKit uses the
558// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
559// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
560// uses different scripts than the ones in Chrome pref names because the version
561// of ICU included on certain ports does not have some of the newer scripts. If
562// |scriptCode| is not a member of such a family, returns |scriptCode|.
563UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
564 switch (scriptCode) {
565 case USCRIPT_HIRAGANA:
566 case USCRIPT_KATAKANA:
567 case USCRIPT_JAPANESE:
568 return USCRIPT_KATAKANA_OR_HIRAGANA;
569 case USCRIPT_KOREAN:
570 return USCRIPT_HANGUL;
571 default:
572 return scriptCode;
573 }
574}
575
576void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
577 SetFontFamilyWrapper setter,
578 WebSettings* settings) {
579 for (ScriptFontFamilyMap::const_iterator it = map.begin(); it != map.end();
580 ++it) {
avi1023d012015-12-25 02:39:14581 int32_t script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
[email protected]b3a97b52014-07-09 06:25:05582 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
583 UScriptCode code = static_cast<UScriptCode>(script);
584 (*setter)(settings, it->second, GetScriptForWebSettings(code));
585 }
586 }
587}
588
wangxianzhu3bf39be52015-04-10 23:56:41589void ApplyBlinkSettings(const base::CommandLine& command_line,
590 WebSettings* settings) {
591 if (!command_line.HasSwitch(switches::kBlinkSettings))
592 return;
593
brettw26dab8f02015-08-08 00:28:47594 std::vector<std::string> blink_settings = base::SplitString(
595 command_line.GetSwitchValueASCII(switches::kBlinkSettings),
596 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
wangxianzhu3bf39be52015-04-10 23:56:41597 for (const std::string& setting : blink_settings) {
598 size_t pos = setting.find('=');
599 settings->setFromStrings(
600 blink::WebString::fromLatin1(setting.substr(0, pos)),
601 blink::WebString::fromLatin1(
602 pos == std::string::npos ? "" : setting.substr(pos + 1)));
603 }
604}
605
[email protected]217690d2012-01-27 07:33:11606} // namespace
607
dcheng35d31c112015-07-22 00:17:36608RenderViewImpl::RenderViewImpl(CompositorDependencies* compositor_deps,
609 const ViewMsg_New_Params& params)
610 : RenderWidget(compositor_deps,
611 blink::WebPopupTypeNone,
naskobd911332014-11-25 01:13:36612 params.initial_size.screen_info,
613 params.swapped_out,
614 params.hidden,
615 params.never_visible),
616 webkit_preferences_(params.web_preferences),
avif937e1d2014-11-02 18:13:07617 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09618 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02619 send_preferred_size_changes_(false),
[email protected]e75cb49e2009-01-05 23:13:21620 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02621 opened_by_user_gesture_(true),
[email protected]88f10a22013-11-06 21:22:12622 suppress_dialogs_until_swap_out_(false),
[email protected]81a34412009-01-05 19:17:24623 page_id_(-1),
naskobd911332014-11-25 01:13:36624 next_page_id_(params.next_page_id),
[email protected]3cc72b12010-03-18 23:03:00625 history_list_offset_(-1),
626 history_list_length_(0),
[email protected]7e9523b2014-03-25 03:02:42627 frames_in_progress_(0),
[email protected]3354d3e2010-06-10 19:53:02628 target_url_status_(TARGET_NONE),
[email protected]d42bf472014-06-14 01:49:38629 uses_temporary_zoom_level_(false),
[email protected]bbc8856d2013-06-14 10:37:04630#if defined(OS_ANDROID)
majidvpfb80e432015-02-23 14:15:50631 top_controls_constraints_(TOP_CONTROLS_STATE_BOTH),
[email protected]bbc8856d2013-06-14 10:37:04632#endif
alexmos7fac9aeb2015-10-16 22:39:49633 has_focus_(false),
[email protected]1875bc02014-03-14 06:33:59634 has_scrolled_focused_editable_node_into_rect_(false),
nasko4c0feb62015-06-05 18:37:06635 main_render_frame_(nullptr),
dcheng3ce04b62015-10-26 23:30:55636 frame_widget_(nullptr),
[email protected]64d09222012-05-25 10:10:34637 speech_recognition_dispatcher_(NULL),
[email protected]217690d2012-01-27 07:33:11638 mouse_lock_dispatcher_(NULL),
[email protected]20657a82012-08-21 20:23:03639#if defined(OS_ANDROID)
640 expected_content_intent_id_(0),
[email protected]a7564272013-04-19 14:24:46641#endif
642#if defined(OS_WIN)
643 focused_plugin_id_(-1),
644#endif
[email protected]e16c7a12013-12-05 16:30:08645#if defined(ENABLE_PLUGINS)
646 focused_pepper_plugin_(NULL),
647 pepper_last_mouse_event_target_(NULL),
648#endif
[email protected]8a67aa352013-02-20 02:58:29649 enumeration_completion_id_(0),
mcnee432e47d2015-11-09 19:37:46650 session_storage_namespace_id_(params.session_storage_namespace_id) {
avi40b5be7a2016-03-03 21:13:44651 GetWidget()->set_owner_delegate(this);
[email protected]075366912013-02-18 07:13:24652}
653
danakj6e3bf8012014-12-16 18:27:53654void RenderViewImpl::Initialize(const ViewMsg_New_Params& params,
danakj6e3bf8012014-12-16 18:27:53655 bool was_created_by_renderer) {
fsamuele8326c742016-01-12 00:49:39656 SetRoutingID(params.view_id);
alexmos5ac402d2015-07-09 07:51:10657
658 int opener_view_routing_id;
alexmos95733002015-08-24 16:38:09659 WebFrame* opener_frame = RenderFrameImpl::ResolveOpener(
660 params.opener_frame_route_id, &opener_view_routing_id);
alexmos5ac402d2015-07-09 07:51:10661 if (opener_view_routing_id != MSG_ROUTING_NONE && was_created_by_renderer)
662 opener_id_ = opener_view_routing_id;
663
thestig6057a6b22015-11-12 23:01:33664 display_mode_ = params.initial_size.display_mode;
[email protected]676126f72011-01-15 00:03:51665
[email protected]74ce1ad2011-12-16 21:51:46666 // Ensure we start with a valid next_page_id_ from the browser.
667 DCHECK_GE(next_page_id_, 0);
668
[email protected]11fee2332011-03-29 20:36:35669 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11670 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35671
nasko4c0feb62015-06-05 18:37:06672 g_view_map.Get().insert(std::make_pair(webview(), this));
fsamuele8326c742016-01-12 00:49:39673 g_routing_id_view_map.Get().insert(std::make_pair(routing_id(), this));
nasko4c0feb62015-06-05 18:37:06674
avi83883c82014-12-23 00:08:49675 const base::CommandLine& command_line =
676 *base::CommandLine::ForCurrentProcess();
[email protected]20657a82012-08-21 20:23:03677
[email protected]27c521a2013-05-29 20:44:32678 if (command_line.HasSwitch(switches::kStatsCollectionController))
679 stats_collection_observer_.reset(new StatsCollectionObserver(this));
680
creis9f7248b2016-01-27 20:27:39681 // Debug cases of https://crbug.com/575245.
682 base::debug::SetCrashKeyValue("rvinit_view_id",
683 base::IntToString(routing_id()));
684 base::debug::SetCrashKeyValue("rvinit_proxy_id",
685 base::IntToString(params.proxy_routing_id));
686 base::debug::SetCrashKeyValue(
687 "rvinit_main_frame_id", base::IntToString(params.main_frame_routing_id));
688
dchengc5ef1a52015-08-26 20:58:30689 if (params.main_frame_routing_id != MSG_ROUTING_NONE) {
dcheng3ce04b62015-10-26 23:30:55690 main_render_frame_ = RenderFrameImpl::CreateMainFrame(
691 this, params.main_frame_routing_id, params.main_frame_widget_routing_id,
dcheng9e24bd352016-03-01 19:15:51692 params.hidden, screen_info(), compositor_deps_, opener_frame);
dchengc5ef1a52015-08-26 20:58:30693 }
694
nasko4c0feb62015-06-05 18:37:06695 if (params.proxy_routing_id != MSG_ROUTING_NONE) {
696 CHECK(params.swapped_out);
697 if (main_render_frame_) {
creisd03d2262016-01-22 19:36:00698 CHECK(!SiteIsolationPolicy::IsSwappedOutStateForbidden());
dchengc5ef1a52015-08-26 20:58:30699 RenderFrameProxy* proxy = RenderFrameProxy::CreateProxyToReplaceFrame(
nasko4c0feb62015-06-05 18:37:06700 main_render_frame_, params.proxy_routing_id,
701 blink::WebTreeScopeType::Document);
702 main_render_frame_->set_render_frame_proxy(proxy);
703 } else {
creisd03d2262016-01-22 19:36:00704 CHECK(SiteIsolationPolicy::IsSwappedOutStateForbidden());
dcheng9e24bd352016-03-01 19:15:51705 RenderFrameProxy::CreateFrameProxy(
706 params.proxy_routing_id, routing_id(), params.opener_frame_route_id,
707 MSG_ROUTING_NONE, params.replicated_frame_state);
nasko4c0feb62015-06-05 18:37:06708 }
709 }
710
nasko4c0feb62015-06-05 18:37:06711 if (main_render_frame_)
712 main_render_frame_->Initialize();
713
[email protected]20657a82012-08-21 20:23:03714#if defined(OS_ANDROID)
limasdf81d962e2015-11-20 08:39:18715 content_detectors_.push_back(make_scoped_ptr(new AddressDetector()));
qinminc6a739f92015-03-31 17:46:11716 const std::string& contry_iso =
717 params.renderer_preferences.network_contry_iso;
718 if (!contry_iso.empty()) {
limasdf81d962e2015-11-20 08:39:18719 content_detectors_.push_back(
720 make_scoped_ptr(new PhoneNumberDetector(contry_iso)));
qinmin0d5560df2014-11-12 19:03:39721 }
limasdf81d962e2015-11-20 08:39:18722 content_detectors_.push_back(make_scoped_ptr(new EmailDetector()));
[email protected]20657a82012-08-21 20:23:03723#endif
724
fsamuele8326c742016-01-12 00:49:39725 RenderThread::Get()->AddRoute(routing_id(), this);
[email protected]676126f72011-01-15 00:03:51726 // Take a reference on behalf of the RenderThread. This will be balanced
lfge208fa42015-04-17 20:29:18727 // when we receive ViewMsg_Close in the RenderWidget (which RenderView
728 // inherits from).
[email protected]676126f72011-01-15 00:03:51729 AddRef();
[email protected]b2db9272014-01-10 17:42:00730 if (RenderThreadImpl::current()) {
731 RenderThreadImpl::current()->WidgetCreated();
732 if (is_hidden_)
733 RenderThreadImpl::current()->WidgetHidden();
734 }
[email protected]676126f72011-01-15 00:03:51735
736 // If this is a popup, we must wait for the CreatingNew_ACK message before
737 // completing initialization. Otherwise, we can finish it now.
pimanc4af3072015-10-02 03:45:59738 if (opener_id_ == MSG_ROUTING_NONE)
[email protected]676126f72011-01-15 00:03:51739 did_show_ = true;
oshimad5279032015-12-16 18:22:33740 UpdateWebViewWithDeviceScaleFactor();
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12741 webview()->setDisplayMode(display_mode_);
[email protected]b8ec1112014-08-17 20:09:10742 webview()->settings()->setPreferCompositingToLCDTextEnabled(
danakj6e3bf8012014-12-16 18:27:53743 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_));
jdduke2eee6cb2014-09-25 17:02:21744 webview()->settings()->setThreadedScrollingEnabled(
745 !command_line.HasSwitch(switches::kDisableThreadedScrolling));
skobes92ed7d462014-11-05 22:05:23746 webview()->settings()->setRootLayerScrolls(
747 command_line.HasSwitch(switches::kRootLayerScrolls));
dongseong.hwange095dfa2016-02-04 11:21:39748 webview()->setShowFPSCounter(
749 command_line.HasSwitch(cc::switches::kShowFPSCounter));
[email protected]fb854192013-02-06 01:30:04750
sataya.mf405d0e2015-07-07 16:51:11751 ApplyWebPreferencesInternal(webkit_preferences_, webview(), compositor_deps_);
[email protected]9b159a52013-10-03 17:24:55752
[email protected]1400e6dc2013-04-27 02:36:27753 if (switches::IsTouchDragDropEnabled())
[email protected]edbea622012-11-28 20:39:38754 webview()->settings()->setTouchDragDropEnabled(true);
755
mfomitchev5ad034ec2015-04-24 21:57:27756 WebSettings::SelectionStrategyType selection_strategy =
jdduke9a6cbec2015-05-13 22:00:03757 WebSettings::SelectionStrategyType::Character;
mfomitchev5ad034ec2015-04-24 21:57:27758 const std::string selection_strategy_str =
759 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
760 switches::kTouchTextSelectionStrategy);
jdduke9a6cbec2015-05-13 22:00:03761 if (selection_strategy_str == "direction")
mfomitchev5ad034ec2015-04-24 21:57:27762 selection_strategy = WebSettings::SelectionStrategyType::Direction;
763 webview()->settings()->setSelectionStrategy(selection_strategy);
764
alexmos35799be2015-07-02 08:59:50765 // Set the main frame's name. Only needs to be done for WebLocalFrames,
766 // since the remote case was handled as part of SetReplicatedState on the
767 // proxy above.
768 if (!params.replicated_frame_state.name.empty() &&
769 webview()->mainFrame()->isWebLocalFrame()) {
alexmos3448b552015-06-26 07:49:13770 webview()->mainFrame()->setName(
771 blink::WebString::fromUTF8(params.replicated_frame_state.name));
772 }
[email protected]34c61bd52011-05-02 19:38:33773
[email protected]c7c0d822014-04-16 20:19:49774 // TODO(davidben): Move this state from Blink into content.
naskobd911332014-11-25 01:13:36775 if (params.window_was_created_with_opener)
[email protected]c7c0d822014-04-16 20:19:49776 webview()->setOpenedByDOM();
777
naskobd911332014-11-25 01:13:36778 OnSetRendererPrefs(params.renderer_preferences);
[email protected]34c61bd52011-05-02 19:38:33779
wangxianzhu3bf39be52015-04-10 23:56:41780 ApplyBlinkSettings(command_line, webview()->settings());
781
naskobd911332014-11-25 01:13:36782 if (!params.enable_auto_resize) {
783 OnResize(params.initial_size);
mkosiba58fa72f02014-11-12 01:21:36784 } else {
naskobd911332014-11-25 01:13:36785 OnEnableAutoResize(params.min_size, params.max_size);
mkosiba58fa72f02014-11-12 01:21:36786 }
787
[email protected]86a7d3c2011-09-12 16:45:32788#if defined(OS_MACOSX)
789 new TextInputClientObserver(this);
790#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56791
dgozman358ba322015-03-26 15:05:30792 // The next group of objects all implement RenderViewObserver, so are deleted
793 // along with the RenderView automatically.
[email protected]89054502012-06-03 10:29:24794 mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
[email protected]063afcb2011-09-29 07:54:32795
creis8eb8ef22015-11-04 22:51:38796 // We don't use HistoryController in OOPIF-enabled modes.
797 if (!SiteIsolationPolicy::UseSubframeNavigationEntries())
798 history_controller_.reset(new HistoryController(this));
[email protected]d4734982014-04-15 02:05:55799
[email protected]1784b2f2011-11-24 10:53:48800 new IdleUserDetector(this);
801
[email protected]766a7082012-02-03 23:39:15802 if (command_line.HasSwitch(switches::kDomAutomationController))
[email protected]e9ff79c2012-10-19 21:31:26803 enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION;
[email protected]27c521a2013-05-29 20:44:32804 if (command_line.HasSwitch(switches::kStatsCollectionController))
805 enabled_bindings_ |= BINDINGS_POLICY_STATS_COLLECTION;
[email protected]766a7082012-02-03 23:39:15806
[email protected]e9ff79c2012-10-19 21:31:26807 GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44808
dcheng9e24bd352016-03-01 19:15:51809 // Ensure that sandbox flags are inherited from an opener in a different
810 // process. In that case, the browser process will set any inherited sandbox
811 // flags in |replicated_frame_state|, so apply them here.
812 if (opener_frame && !was_created_by_renderer &&
813 webview()->mainFrame()->isWebLocalFrame()) {
814 webview()->mainFrame()->toWebLocalFrame()->forceSandboxFlags(
815 params.replicated_frame_state.sandbox_flags);
alexmosaedfc6f2016-01-21 23:57:38816 }
817
[email protected]14392a52012-05-02 20:28:44818 // If we are initially swapped out, navigate to kSwappedOutURL.
819 // This ensures we are in a unique origin that others cannot script.
[email protected]82307f6b2014-08-07 03:30:12820 if (is_swapped_out_ && webview()->mainFrame()->isWebLocalFrame())
nasko78f06bc2014-11-18 18:18:57821 main_render_frame_->NavigateToSwappedOutURL();
initial.commit09911bf2008-07-26 23:55:29822}
823
[email protected]310ebd6302011-10-10 19:06:28824RenderViewImpl::~RenderViewImpl() {
dcheng3ce04b62015-10-26 23:30:55825 DCHECK(!frame_widget_);
826
[email protected]cb189e062014-04-23 00:57:01827 for (BitmapMap::iterator it = disambiguation_bitmaps_.begin();
828 it != disambiguation_bitmaps_.end();
829 ++it)
830 delete it->second;
[email protected]91a2aea2013-07-08 23:14:39831
[email protected]a1128322009-10-06 18:38:46832 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47833 while (!file_chooser_completions_.empty()) {
834 if (file_chooser_completions_.front()->completion) {
835 file_chooser_completions_.front()->completion->didChooseFile(
836 WebVector<WebString>());
837 }
838 file_chooser_completions_.pop_front();
839 }
[email protected]a1128322009-10-06 18:38:46840
[email protected]8ed1d3f2013-02-20 11:45:55841#if defined(OS_ANDROID)
842 // The date/time picker client is both a scoped_ptr member of this class and
843 // a RenderViewObserver. Reset it to prevent double deletion.
844 date_time_picker_client_.reset();
845#endif
846
[email protected]60c42a8c72009-10-09 04:08:59847#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22848 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49849 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59850 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
851 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22852 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
853 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
854 it != routing_id_views->end(); ++it)
855 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59856#endif
[email protected]676126f72011-01-15 00:03:51857
[email protected]310ebd6302011-10-10 19:06:28858 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51859 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59860}
861
862/*static*/
[email protected]310ebd6302011-10-10 19:06:28863RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31864 ViewMap* views = g_view_map.Pointer();
865 ViewMap::iterator it = views->find(webview);
866 return it == views->end() ? NULL : it->second;
867}
868
869/*static*/
[email protected]180ef242013-11-07 06:50:46870RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28871 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31872}
873
874/*static*/
avi1023d012015-12-25 02:39:14875RenderViewImpl* RenderViewImpl::FromRoutingID(int32_t routing_id) {
[email protected]640e303c2012-12-05 01:36:07876 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
877 RoutingIDViewMap::iterator it = views->find(routing_id);
878 return it == views->end() ? NULL : it->second;
879}
880
881/*static*/
882RenderView* RenderView::FromRoutingID(int routing_id) {
883 return RenderViewImpl::FromRoutingID(routing_id);
884}
885
[email protected]f3a95312014-06-12 16:46:58886/* static */
jochen9c7b8f242015-06-01 15:32:02887size_t RenderView::GetRenderViewCount() {
[email protected]f3a95312014-06-12 16:46:58888 return g_view_map.Get().size();
889}
890
[email protected]640e303c2012-12-05 01:36:07891/*static*/
[email protected]e9ff79c2012-10-19 21:31:26892void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49893 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59894 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
895 if (!visitor->Visit(it->second))
896 return;
897 }
898}
899
900/*static*/
[email protected]b3a97b52014-07-09 06:25:05901void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
902 WebView* web_view) {
903 WebSettings* settings = web_view->settings();
904 ApplyFontsFromMap(prefs.standard_font_family_map,
905 SetStandardFontFamilyWrapper, settings);
906 ApplyFontsFromMap(prefs.fixed_font_family_map,
907 SetFixedFontFamilyWrapper, settings);
908 ApplyFontsFromMap(prefs.serif_font_family_map,
909 SetSerifFontFamilyWrapper, settings);
910 ApplyFontsFromMap(prefs.sans_serif_font_family_map,
911 SetSansSerifFontFamilyWrapper, settings);
912 ApplyFontsFromMap(prefs.cursive_font_family_map,
913 SetCursiveFontFamilyWrapper, settings);
914 ApplyFontsFromMap(prefs.fantasy_font_family_map,
915 SetFantasyFontFamilyWrapper, settings);
916 ApplyFontsFromMap(prefs.pictograph_font_family_map,
917 SetPictographFontFamilyWrapper, settings);
918 settings->setDefaultFontSize(prefs.default_font_size);
919 settings->setDefaultFixedFontSize(prefs.default_fixed_font_size);
920 settings->setMinimumFontSize(prefs.minimum_font_size);
921 settings->setMinimumLogicalFontSize(prefs.minimum_logical_font_size);
922 settings->setDefaultTextEncodingName(
923 base::ASCIIToUTF16(prefs.default_encoding));
924 settings->setJavaScriptEnabled(prefs.javascript_enabled);
925 settings->setWebSecurityEnabled(prefs.web_security_enabled);
926 settings->setJavaScriptCanOpenWindowsAutomatically(
927 prefs.javascript_can_open_windows_automatically);
928 settings->setLoadsImagesAutomatically(prefs.loads_images_automatically);
929 settings->setImagesEnabled(prefs.images_enabled);
930 settings->setPluginsEnabled(prefs.plugins_enabled);
931 settings->setDOMPasteAllowed(prefs.dom_paste_enabled);
[email protected]b3a97b52014-07-09 06:25:05932 settings->setUsesEncodingDetector(prefs.uses_universal_detector);
933 settings->setTextAreasAreResizable(prefs.text_areas_are_resizable);
934 settings->setAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
935 settings->setDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
936 settings->setJavaScriptCanAccessClipboard(
937 prefs.javascript_can_access_clipboard);
938 WebRuntimeFeatures::enableXSLT(prefs.xslt_enabled);
939 settings->setXSSAuditorEnabled(prefs.xss_auditor_enabled);
940 settings->setDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
Ben Greenstein49878f52015-12-18 19:13:21941 settings->setDataSaverEnabled(prefs.data_saver_enabled);
[email protected]b3a97b52014-07-09 06:25:05942 settings->setLocalStorageEnabled(prefs.local_storage_enabled);
943 settings->setSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
944 WebRuntimeFeatures::enableDatabase(prefs.databases_enabled);
945 settings->setOfflineWebApplicationCacheEnabled(
946 prefs.application_cache_enabled);
947 settings->setCaretBrowsingEnabled(prefs.caret_browsing_enabled);
948 settings->setHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
949 settings->setCookieEnabled(prefs.cookie_enabled);
950 settings->setNavigateOnDragDrop(prefs.navigate_on_drag_drop);
951
[email protected]b3a97b52014-07-09 06:25:05952 // By default, allow_universal_access_from_file_urls is set to false and thus
953 // we mitigate attacks from local HTML files by not granting file:// URLs
954 // universal access. Only test shell will enable this.
955 settings->setAllowUniversalAccessFromFileURLs(
956 prefs.allow_universal_access_from_file_urls);
957 settings->setAllowFileAccessFromFileURLs(
958 prefs.allow_file_access_from_file_urls);
959
[email protected]b3a97b52014-07-09 06:25:05960 // Enable experimental WebGL support if requested on command line
961 // and support is compiled in.
962 settings->setExperimentalWebGLEnabled(prefs.experimental_webgl_enabled);
963
964 // Disable GL multisampling if requested on command line.
965 settings->setOpenGLMultisamplingEnabled(prefs.gl_multisampling_enabled);
966
967 // Enable WebGL errors to the JS console if requested.
968 settings->setWebGLErrorsToConsoleEnabled(
969 prefs.webgl_errors_to_console_enabled);
970
971 // Uses the mock theme engine for scrollbars.
972 settings->setMockScrollbarsEnabled(prefs.mock_scrollbars_enabled);
973
[email protected]b3a97b52014-07-09 06:25:05974 // Enable gpu-accelerated 2d canvas if requested on the command line.
975 settings->setAccelerated2dCanvasEnabled(prefs.accelerated_2d_canvas_enabled);
976
977 settings->setMinimumAccelerated2dCanvasSize(
978 prefs.minimum_accelerated_2d_canvas_size);
979
980 // Disable antialiasing for 2d canvas if requested on the command line.
981 settings->setAntialiased2dCanvasEnabled(
982 !prefs.antialiased_2d_canvas_disabled);
boliucfcae412016-02-11 22:16:38983 WebRuntimeFeatures::forceDisable2dCanvasCopyOnWrite(
984 prefs.disable_2d_canvas_copy_on_write);
[email protected]b3a97b52014-07-09 06:25:05985
robertphillipse25137b2014-10-20 13:44:34986 // Enabled antialiasing of clips for 2d canvas if requested on the command
987 // line.
988 settings->setAntialiasedClips2dCanvasEnabled(
989 prefs.antialiased_clips_2d_canvas_enabled);
990
[email protected]b3a97b52014-07-09 06:25:05991 // Set MSAA sample count for 2d canvas if requested on the command line (or
992 // default value if not).
993 settings->setAccelerated2dCanvasMSAASampleCount(
994 prefs.accelerated_2d_canvas_msaa_sample_count);
995
[email protected]b3a97b52014-07-09 06:25:05996 settings->setUnifiedTextCheckerEnabled(prefs.unified_textchecker_enabled);
997
[email protected]b3a97b52014-07-09 06:25:05998 // Tabs to link is not part of the settings. WebCore calls
999 // ChromeClient::tabsToLinks which is part of the glue code.
1000 web_view->setTabsToLinks(prefs.tabs_to_links);
1001
1002 settings->setAllowDisplayOfInsecureContent(
1003 prefs.allow_displaying_insecure_content);
1004 settings->setAllowRunningOfInsecureContent(
1005 prefs.allow_running_insecure_content);
mkwst772ce8142015-01-16 13:28:071006 settings->setDisableReadingFromCanvas(prefs.disable_reading_from_canvas);
mkwst2fc2c4f2015-01-08 08:29:181007 settings->setStrictMixedContentChecking(prefs.strict_mixed_content_checking);
mkwst2384c8222015-07-30 07:26:471008
1009 settings->setStrictlyBlockBlockableMixedContent(
1010 prefs.strictly_block_blockable_mixed_content);
1011
mkwst0d233e52015-08-10 09:33:141012 settings->setStrictMixedContentCheckingForPlugin(
1013 prefs.block_mixed_plugin_content);
1014
mkwst673a452f2015-01-10 14:41:501015 settings->setStrictPowerfulFeatureRestrictions(
1016 prefs.strict_powerful_feature_restrictions);
jww9d4ca2d2016-01-19 20:58:591017 settings->setAllowGeolocationOnInsecureOrigins(
1018 prefs.allow_geolocation_on_insecure_origins);
[email protected]b3a97b52014-07-09 06:25:051019 settings->setPasswordEchoEnabled(prefs.password_echo_enabled);
1020 settings->setShouldPrintBackgrounds(prefs.should_print_backgrounds);
1021 settings->setShouldClearDocumentBackground(
1022 prefs.should_clear_document_background);
1023 settings->setEnableScrollAnimator(prefs.enable_scroll_animator);
1024
[email protected]b3a97b52014-07-09 06:25:051025 WebRuntimeFeatures::enableTouch(prefs.touch_enabled);
1026 settings->setMaxTouchPoints(prefs.pointer_events_max_touch_points);
mustaq29eb7092014-11-14 00:32:121027 settings->setAvailablePointerTypes(prefs.available_pointer_types);
1028 settings->setPrimaryPointerType(
nzolghadrc0d1663c2015-11-26 21:15:241029 static_cast<blink::PointerType>(prefs.primary_pointer_type));
mustaq29eb7092014-11-14 00:32:121030 settings->setAvailableHoverTypes(prefs.available_hover_types);
1031 settings->setPrimaryHoverType(
nzolghadrc0d1663c2015-11-26 21:15:241032 static_cast<blink::HoverType>(prefs.primary_hover_type));
[email protected]b3a97b52014-07-09 06:25:051033 settings->setDeviceSupportsTouch(prefs.device_supports_touch);
1034 settings->setDeviceSupportsMouse(prefs.device_supports_mouse);
1035 settings->setEnableTouchAdjustment(prefs.touch_adjustment_enabled);
mustaq35bb250b2015-05-06 21:22:391036 settings->setMultiTargetTapNotificationEnabled(
1037 switches::IsLinkDisambiguationPopupEnabled());
[email protected]b3a97b52014-07-09 06:25:051038
noelf552c5172014-11-05 22:53:211039 WebRuntimeFeatures::enableImageColorProfiles(
1040 prefs.image_color_profiles_enabled);
[email protected]b3a97b52014-07-09 06:25:051041 settings->setShouldRespectImageOrientation(
1042 prefs.should_respect_image_orientation);
1043
1044 settings->setUnsafePluginPastingEnabled(false);
1045 settings->setEditingBehavior(
1046 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
1047
1048 settings->setSupportsMultipleWindows(prefs.supports_multiple_windows);
1049
ymalik835268c22016-02-22 16:28:121050 settings->setInertVisualViewport(prefs.inert_visual_viewport);
1051
[email protected]b3a97b52014-07-09 06:25:051052 settings->setSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
1053
1054 settings->setSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
1055
1056 settings->setSelectionIncludesAltImageText(true);
1057
[email protected]35103c02014-08-12 15:08:471058 settings->setV8CacheOptions(
1059 static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options));
1060
je_julie.kim7fbb5a1a2015-02-09 17:26:051061 settings->setImageAnimationPolicy(
1062 static_cast<WebSettings::ImageAnimationPolicy>(prefs.animation_policy));
1063
zqzhang1215ad422016-02-10 13:27:221064 settings->setPresentationRequiresUserGesture(
1065 prefs.user_gesture_required_for_presentation);
1066
dcheng5ae8ca362015-02-05 04:03:471067 // Needs to happen before setIgnoreVIewportTagScaleLimits below.
1068 web_view->setDefaultPageScaleLimits(
1069 prefs.default_minimum_page_scale_factor,
1070 prefs.default_maximum_page_scale_factor);
1071
[email protected]b3a97b52014-07-09 06:25:051072#if defined(OS_ANDROID)
1073 settings->setAllowCustomScrollbarInMainFrame(false);
1074 settings->setTextAutosizingEnabled(prefs.text_autosizing_enabled);
1075 settings->setAccessibilityFontScaleFactor(prefs.font_scale_factor);
1076 settings->setDeviceScaleAdjustment(prefs.device_scale_adjustment);
[email protected]023fed312014-08-11 16:13:051077 settings->setFullscreenSupported(prefs.fullscreen_supported);
[email protected]b3a97b52014-07-09 06:25:051078 web_view->setIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
1079 settings->setAutoZoomFocusedNodeToLegibleScale(true);
1080 settings->setDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
1081 settings->setMediaControlsOverlayPlayButtonEnabled(true);
1082 settings->setMediaPlaybackRequiresUserGesture(
1083 prefs.user_gesture_required_for_media_playback);
1084 settings->setDefaultVideoPosterURL(
1085 base::ASCIIToUTF16(prefs.default_video_poster_url.spec()));
1086 settings->setSupportDeprecatedTargetDensityDPI(
1087 prefs.support_deprecated_target_density_dpi);
1088 settings->setUseLegacyBackgroundSizeShorthandBehavior(
1089 prefs.use_legacy_background_size_shorthand_behavior);
1090 settings->setWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
1091 settings->setUseWideViewport(prefs.use_wide_viewport);
[email protected]9954ea92014-08-12 15:48:451092 settings->setForceZeroLayoutHeight(prefs.force_zero_layout_height);
[email protected]b3a97b52014-07-09 06:25:051093 settings->setViewportMetaLayoutSizeQuirk(
1094 prefs.viewport_meta_layout_size_quirk);
1095 settings->setViewportMetaMergeContentQuirk(
1096 prefs.viewport_meta_merge_content_quirk);
1097 settings->setViewportMetaNonUserScalableQuirk(
1098 prefs.viewport_meta_non_user_scalable_quirk);
1099 settings->setViewportMetaZeroValuesQuirk(
1100 prefs.viewport_meta_zero_values_quirk);
1101 settings->setClobberUserAgentInitialScaleQuirk(
1102 prefs.clobber_user_agent_initial_scale_quirk);
1103 settings->setIgnoreMainFrameOverflowHiddenQuirk(
1104 prefs.ignore_main_frame_overflow_hidden_quirk);
1105 settings->setReportScreenSizeInPhysicalPixelsQuirk(
1106 prefs.report_screen_size_in_physical_pixels_quirk);
liberato2f1a7e02015-08-10 16:01:411107 settings->setPreferHiddenVolumeControls(true);
boliu15ca2652015-09-04 23:33:401108 settings->setMainFrameClipsContent(!prefs.record_whole_document);
[email protected]b3a97b52014-07-09 06:25:051109 settings->setShrinksViewportContentToFit(true);
runed1677fd2015-03-12 09:01:531110 settings->setUseMobileViewportStyle(true);
liberato6524fa42015-09-14 23:26:081111 settings->setAutoplayExperimentMode(
1112 blink::WebString::fromUTF8(prefs.autoplay_experiment_mode));
[email protected]b3a97b52014-07-09 06:25:051113#endif
1114
yoava1a508b42015-10-20 12:03:211115 settings->setViewportEnabled(prefs.viewport_enabled);
1116 settings->setLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
1117 settings->setViewportMetaEnabled(prefs.viewport_meta_enabled);
1118 settings->setMainFrameResizesAreOrientationChanges(
1119 prefs.main_frame_resizes_are_orientation_changes);
1120
[email protected]b3a97b52014-07-09 06:25:051121 settings->setPinchOverlayScrollbarThickness(
1122 prefs.pinch_overlay_scrollbar_thickness);
1123 settings->setUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
jinho.bang8f11ffa2014-12-04 06:03:031124
arjanl98804912015-03-04 09:23:041125 settings->setShowContextMenuOnMouseUp(prefs.context_menu_on_mouse_up);
ccameron2fd70de72015-02-19 00:40:401126
1127#if defined(OS_MACOSX)
1128 settings->setDoubleTapToZoomEnabled(true);
ccameronf29a7802015-02-20 22:11:251129 web_view->setMaximumLegibleScale(prefs.default_maximum_page_scale_factor);
ccameron2fd70de72015-02-19 00:40:401130#endif
[email protected]b3a97b52014-07-09 06:25:051131}
1132
1133/*static*/
dcheng35d31c112015-07-22 00:17:361134RenderViewImpl* RenderViewImpl::Create(CompositorDependencies* compositor_deps,
1135 const ViewMsg_New_Params& params,
danakj6e3bf8012014-12-16 18:27:531136 bool was_created_by_renderer) {
naskobd911332014-11-25 01:13:361137 DCHECK(params.view_id != MSG_ROUTING_NONE);
[email protected]075366912013-02-18 07:13:241138 RenderViewImpl* render_view = NULL;
[email protected]8d41d7612012-11-14 20:32:191139 if (g_create_render_view_impl)
dcheng35d31c112015-07-22 00:17:361140 render_view = g_create_render_view_impl(compositor_deps, params);
[email protected]075366912013-02-18 07:13:241141 else
dcheng35d31c112015-07-22 00:17:361142 render_view = new RenderViewImpl(compositor_deps, params);
[email protected]0287e762014-04-11 13:07:581143
dcheng35d31c112015-07-22 00:17:361144 render_view->Initialize(params, was_created_by_renderer);
[email protected]075366912013-02-18 07:13:241145 return render_view;
[email protected]8d41d7612012-11-14 20:32:191146}
1147
1148// static
dcheng35d31c112015-07-22 00:17:361149void RenderViewImpl::InstallCreateHook(RenderViewImpl* (
1150 *create_render_view_impl)(CompositorDependencies* compositor_deps,
1151 const ViewMsg_New_Params&)) {
[email protected]8d41d7612012-11-14 20:32:191152 CHECK(!g_create_render_view_impl);
1153 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291154}
1155
[email protected]310ebd6302011-10-10 19:06:281156void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511157 observers_.AddObserver(observer);
1158}
1159
[email protected]310ebd6302011-10-10 19:06:281160void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1161 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511162 observers_.RemoveObserver(observer);
1163}
1164
[email protected]180ef242013-11-07 06:50:461165blink::WebView* RenderViewImpl::webview() const {
1166 return static_cast<blink::WebView*>(webwidget());
[email protected]4d51d5bf2010-07-26 18:48:261167}
1168
[email protected]ea2fb972013-08-07 05:44:261169#if defined(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:571170void RenderViewImpl::PepperInstanceCreated(
1171 PepperPluginInstanceImpl* instance) {
1172 active_pepper_instances_.insert(instance);
emaxxe70f5e12015-05-29 11:26:001173
1174 RenderFrameImpl* const render_frame = instance->render_frame();
1175 render_frame->Send(
1176 new FrameHostMsg_PepperInstanceCreated(render_frame->GetRoutingID()));
[email protected]a99a38802014-01-14 15:46:571177}
1178
1179void RenderViewImpl::PepperInstanceDeleted(
1180 PepperPluginInstanceImpl* instance) {
1181 active_pepper_instances_.erase(instance);
1182
1183 if (pepper_last_mouse_event_target_ == instance)
1184 pepper_last_mouse_event_target_ = NULL;
1185 if (focused_pepper_plugin_ == instance)
1186 PepperFocusChanged(instance, false);
emaxxe70f5e12015-05-29 11:26:001187
1188 RenderFrameImpl* const render_frame = instance->render_frame();
1189 if (render_frame)
1190 render_frame->Send(
1191 new FrameHostMsg_PepperInstanceDeleted(render_frame->GetRoutingID()));
[email protected]a99a38802014-01-14 15:46:571192}
1193
1194void RenderViewImpl::PepperFocusChanged(PepperPluginInstanceImpl* instance,
1195 bool focused) {
1196 if (focused)
1197 focused_pepper_plugin_ = instance;
1198 else if (focused_pepper_plugin_ == instance)
1199 focused_pepper_plugin_ = NULL;
1200
fsamuel72464894f2015-12-15 06:59:311201 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]a99a38802014-01-14 15:46:571202 UpdateSelectionBounds();
1203}
1204
[email protected]310ebd6302011-10-10 19:06:281205void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:261206 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:301207 // If the renderer is visible, set initial visibility and focus state.
1208 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:341209#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:301210 delegate->SetContainerVisibility(true);
1211 if (webview() && webview()->isActive())
1212 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:341213#endif
[email protected]49232292010-09-03 19:07:301214 }
[email protected]784ea1ab2010-09-18 00:02:341215 // Plugins start assuming the content has focus (so that they work in
1216 // environments where RenderView isn't hosting them), so we always have to
1217 // set the initial state. See webplugin_delegate_impl.h for details.
1218 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:261219}
1220
[email protected]310ebd6302011-10-10 19:06:281221void RenderViewImpl::UnregisterPluginDelegate(
1222 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:261223 plugin_delegates_.erase(delegate);
1224}
[email protected]d8fd6fa2010-02-01 15:54:261225
[email protected]a80af12e2013-08-07 23:36:131226#if defined(OS_WIN)
1227void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
1228 if (focused)
1229 focused_plugin_id_ = plugin_id;
1230 else
1231 focused_plugin_id_ = -1;
1232}
1233#endif
1234
1235#if defined(OS_MACOSX)
1236void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
1237 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
1238}
1239
[email protected]7411a3c2014-08-15 05:20:191240void RenderViewImpl::OnGetRenderedText() {
1241 if (!webview())
1242 return;
dglazkov03223492016-02-08 22:16:031243
1244 if (!webview()->mainFrame()->isWebLocalFrame())
1245 return;
1246
[email protected]7411a3c2014-08-15 05:20:191247 // Get rendered text from WebLocalFrame.
1248 // TODO: Currently IPC truncates any data that has a
1249 // size > kMaximumMessageSize. May be split the text into smaller chunks and
1250 // send back using multiple IPC. See http://crbug.com/393444.
1251 static const size_t kMaximumMessageSize = 8 * 1024 * 1024;
dglazkov03223492016-02-08 22:16:031252 // TODO(dglazkov): Using this API is wrong. It's not OOPIF-compatible and
1253 // sends text in the wrong order. See http://crbug.com/584798.
1254 // TODO(dglazkov): WebFrameContentDumper should only be used for
1255 // testing purposes. See http://crbug.com/585164.
1256 std::string text =
1257 WebFrameContentDumper::dumpFrameTreeAsText(
1258 webview()->mainFrame()->toWebLocalFrame(), kMaximumMessageSize)
1259 .utf8();
[email protected]7411a3c2014-08-15 05:20:191260
1261 Send(new ViewMsg_GetRenderedTextCompleted(routing_id(), text));
1262}
1263
[email protected]a80af12e2013-08-07 23:36:131264void RenderViewImpl::StartPluginIme() {
1265 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
1266 // This message can be sent during event-handling, and needs to be delivered
1267 // within that context.
1268 msg->set_unblock(true);
1269 Send(msg);
1270}
1271#endif // defined(OS_MACOSX)
1272
1273#endif // ENABLE_PLUGINS
1274
[email protected]7a1ec28a2012-03-28 21:10:241275void RenderViewImpl::TransferActiveWheelFlingAnimation(
[email protected]180ef242013-11-07 06:50:461276 const blink::WebActiveWheelFlingParameters& params) {
[email protected]7a1ec28a2012-03-28 21:10:241277 if (webview())
1278 webview()->transferActiveWheelFlingAnimation(params);
1279}
1280
fsamuel72464894f2015-12-15 06:59:311281// RenderWidgetInputHandlerDelegate -----------------------------------------
1282
avid7d6b2e2016-03-04 19:41:171283void RenderViewImpl::RenderWidgetFocusChangeComplete() {
fsamuel72464894f2015-12-15 06:59:311284 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusChangeComplete());
1285}
1286
avid7d6b2e2016-03-04 19:41:171287bool RenderViewImpl::DoesRenderWidgetHaveTouchEventHandlersAt(
1288 const gfx::Point& point) const {
fsamuel72464894f2015-12-15 06:59:311289 if (!webview())
1290 return false;
1291 return webview()->hasTouchEventHandlersAt(point);
1292}
1293
avid7d6b2e2016-03-04 19:41:171294void RenderViewImpl::RenderWidgetDidHandleKeyEvent() {
fsamuel72464894f2015-12-15 06:59:311295 ClearEditCommands();
1296}
1297
avid7d6b2e2016-03-04 19:41:171298bool RenderViewImpl::RenderWidgetWillHandleGestureEvent(
fsamuel72464894f2015-12-15 06:59:311299 const blink::WebGestureEvent& event) {
1300 possible_drag_event_info_.event_source =
1301 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
1302 possible_drag_event_info_.event_location =
1303 gfx::Point(event.globalX, event.globalY);
1304 return false;
1305}
1306
avid7d6b2e2016-03-04 19:41:171307bool RenderViewImpl::RenderWidgetWillHandleMouseEvent(
1308 const blink::WebMouseEvent& event) {
fsamuel72464894f2015-12-15 06:59:311309 possible_drag_event_info_.event_source =
1310 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
1311 possible_drag_event_info_.event_location =
1312 gfx::Point(event.globalX, event.globalY);
1313
1314#if defined(ENABLE_PLUGINS)
1315 // This method is called for every mouse event that the render view receives.
1316 // And then the mouse event is forwarded to WebKit, which dispatches it to the
1317 // event target. Potentially a Pepper plugin will receive the event.
1318 // In order to tell whether a plugin gets the last mouse event and which it
1319 // is, we set |pepper_last_mouse_event_target_| to NULL here. If a plugin gets
1320 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
1321 // |pepper_last_mouse_event_target_|.
1322 pepper_last_mouse_event_target_ = NULL;
1323#endif
1324
1325 // If the mouse is locked, only the current owner of the mouse lock can
1326 // process mouse events.
1327 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
1328}
1329
1330// IPC::Listener implementation ----------------------------------------------
1331
[email protected]310ebd6302011-10-10 19:06:281332bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:271333 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]82307f6b2014-08-07 03:30:121334 if (main_frame && main_frame->isWebLocalFrame())
[email protected]e9ff79c2012-10-19 21:31:261335 GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:261336
naskoc6edf7e2015-10-16 01:48:451337 // Input IPC messages must not be processed if the RenderView is in
1338 // swapped out state.
1339 if (is_swapped_out_ && IPC_MESSAGE_ID_CLASS(message.type()) == InputMsgStart)
1340 return false;
1341
brettw5a1613dc2015-06-02 05:34:431342 base::ObserverListBase<RenderViewObserver>::Iterator it(&observers_);
[email protected]676126f72011-01-15 00:03:511343 RenderViewObserver* observer;
1344 while ((observer = it.GetNext()) != NULL)
1345 if (observer->OnMessageReceived(message))
1346 return true;
[email protected]b2abac72009-02-26 12:39:281347
[email protected]a95986a82010-12-24 06:19:281348 bool handled = true;
[email protected]e44d1342014-05-16 21:29:331349 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
[email protected]c084330e02013-04-27 01:08:151350 IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand)
1351 IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret)
[email protected]c084330e02013-04-27 01:08:151352 IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect,
1353 OnScrollFocusedEditableNodeIntoRect)
[email protected]c084330e02013-04-27 01:08:151354 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
1355 OnSetEditCommandsForNextKeyEvent)
initial.commit09911bf2008-07-26 23:55:291356 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]6a6fa3e2014-05-09 06:57:181357 IPC_MESSAGE_HANDLER(ViewMsg_SaveImageAt, OnSaveImageAt)
mcnee432e47d2015-11-09 19:37:461358 IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale)
[email protected]630e26b2008-10-14 22:55:171359 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:541360 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1361 OnSetZoomLevelForLoadingURL)
[email protected]d42bf472014-06-14 01:49:381362 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForView,
1363 OnSetZoomLevelForView)
initial.commit09911bf2008-07-26 23:55:291364 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:181365 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1366 OnResetPageEncodingToDefault)
[email protected]59f4f2fa2011-03-23 01:00:551367 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
1368 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
1369 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
1370 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
[email protected]7a6d773f2014-04-04 01:25:091371 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
[email protected]59f4f2fa2011-03-23 01:00:551372 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
1373 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:451374 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:291375 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291376 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1377 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]600ea402011-04-12 00:01:511378 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
1379 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:291380 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]88f10a22013-11-06 21:22:121381 IPC_MESSAGE_HANDLER(ViewMsg_SuppressDialogsUntilSwapOut,
1382 OnSuppressDialogsUntilSwapOut)
initial.commit09911bf2008-07-26 23:55:291383 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1384 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]30f75e62009-02-25 22:01:001385 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]ab6c9112014-02-27 00:20:581386 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedElement, OnClearFocusedElement)
[email protected]61f91832014-05-13 01:24:421387 IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque, OnSetBackgroundOpaque)
[email protected]ab32b16c2009-10-16 14:57:251388 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1389 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:471390 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:341391 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:101392 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1393 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511394 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:561395 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:361396 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:341397 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]47822262013-04-23 17:22:361398 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
[email protected]f0557932011-01-25 20:20:511399 // TODO(viettrungluu): Move to a separate message filter.
avi2b177592014-12-10 02:08:021400 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryOffsetAndLength,
1401 OnSetHistoryOffsetAndLength)
[email protected]5a7b15a2011-08-22 22:48:181402 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]cb189e062014-04-23 00:57:011403 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupBitmap,
1404 OnReleaseDisambiguationPopupBitmap)
[email protected]506563d2014-06-23 12:22:411405 IPC_MESSAGE_HANDLER(ViewMsg_ForceRedraw, OnForceRedraw)
[email protected]4dda6a6c2014-05-17 15:35:041406 IPC_MESSAGE_HANDLER(ViewMsg_SelectWordAroundCaret, OnSelectWordAroundCaret)
[email protected]55750b32012-09-21 14:05:031407#if defined(OS_ANDROID)
[email protected]452b4a92013-03-28 21:24:381408 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState,
1409 OnUpdateTopControlsState)
[email protected]c4790dcb2013-12-27 22:08:021410 IPC_MESSAGE_HANDLER(ViewMsg_ExtractSmartClipData, OnExtractSmartClipData)
[email protected]55750b32012-09-21 14:05:031411#elif defined(OS_MACOSX)
[email protected]7411a3c2014-08-15 05:20:191412 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedText,
1413 OnGetRenderedText)
[email protected]55750b32012-09-21 14:05:031414 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1415 OnPluginImeCompositionCompleted)
naskoc288745f2015-05-01 22:54:211416 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]55750b32012-09-21 14:05:031417 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
1418 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
1419 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
1420#endif
[email protected]a794f3a2013-10-30 17:00:321421 // Adding a new message? Add platform independent ones first, then put the
1422 // platform specific ones at the end.
[email protected]9e1ad4b2011-08-14 16:49:191423
initial.commit09911bf2008-07-26 23:55:291424 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281425 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291426 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401427
[email protected]a95986a82010-12-24 06:19:281428 return handled;
initial.commit09911bf2008-07-26 23:55:291429}
1430
[email protected]4dda6a6c2014-05-17 15:35:041431void RenderViewImpl::OnSelectWordAroundCaret() {
1432 if (!webview())
1433 return;
1434
fsamuele8326c742016-01-12 00:49:391435 input_handler_->set_handling_input_event(true);
[email protected]4dda6a6c2014-05-17 15:35:041436 webview()->focusedFrame()->selectWordAroundCaret();
fsamuele8326c742016-01-12 00:49:391437 input_handler_->set_handling_input_event(false);
[email protected]4dda6a6c2014-05-17 15:35:041438}
1439
[email protected]310ebd6302011-10-10 19:06:281440void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271441 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291442}
1443
[email protected]6a6fa3e2014-05-09 06:57:181444void RenderViewImpl::OnSaveImageAt(int x, int y) {
1445 webview()->saveImageAt(WebPoint(x, y));
1446}
1447
[email protected]310ebd6302011-10-10 19:06:281448void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291449 // Check if there is a targeturl waiting to be sent.
avi450ce00e2014-09-24 01:58:521450 if (target_url_status_ == TARGET_PENDING)
fsamuele8326c742016-01-12 00:49:391451 Send(new ViewHostMsg_UpdateTargetURL(routing_id(), pending_target_url_));
initial.commit09911bf2008-07-26 23:55:291452
1453 target_url_status_ = TARGET_NONE;
1454}
1455
[email protected]c084330e02013-04-27 01:08:151456void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
1457 const std::string& value) {
1458 if (!webview() || !webview()->focusedFrame())
1459 return;
1460
1461 webview()->focusedFrame()->executeCommand(
1462 WebString::fromUTF8(name), WebString::fromUTF8(value));
1463}
1464
1465void RenderViewImpl::OnMoveCaret(const gfx::Point& point) {
1466 if (!webview())
1467 return;
1468
fsamuele8326c742016-01-12 00:49:391469 Send(new InputHostMsg_MoveCaret_ACK(routing_id()));
oshima93b827d92016-03-01 18:58:411470 webview()->focusedFrame()->moveCaretSelection(
1471 ConvertWindowPointToViewport(point));
[email protected]c084330e02013-04-27 01:08:151472}
[email protected]a954bf72009-09-12 07:30:351473
[email protected]c084330e02013-04-27 01:08:151474void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1475 const gfx::Rect& rect) {
[email protected]1875bc02014-03-14 06:33:591476 if (has_scrolled_focused_editable_node_into_rect_ &&
1477 rect == rect_for_scrolled_focused_editable_node_) {
avid7d6b2e2016-03-04 19:41:171478 GetWidget()->FocusChangeComplete();
[email protected]1875bc02014-03-14 06:33:591479 return;
1480 }
1481
[email protected]c39f7442014-02-27 03:33:171482 blink::WebElement element = GetFocusedElement();
rouslanf7ebd8832015-01-22 01:54:141483 bool will_animate = false;
esprehn3d4471a2015-09-17 07:13:201484 if (!element.isNull() && element.isEditable()) {
[email protected]1875bc02014-03-14 06:33:591485 rect_for_scrolled_focused_editable_node_ = rect;
1486 has_scrolled_focused_editable_node_into_rect_ = true;
rouslanf7ebd8832015-01-22 01:54:141487 will_animate = webview()->scrollFocusedNodeIntoRect(rect);
[email protected]c084330e02013-04-27 01:08:151488 }
rouslanf7ebd8832015-01-22 01:54:141489
1490 if (!will_animate)
avid7d6b2e2016-03-04 19:41:171491 GetWidget()->FocusChangeComplete();
[email protected]25bcc8f2013-01-09 02:49:251492}
1493
[email protected]c084330e02013-04-27 01:08:151494void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
1495 const EditCommands& edit_commands) {
1496 edit_commands_ = edit_commands;
1497}
1498
avi2b177592014-12-10 02:08:021499void RenderViewImpl::OnSetHistoryOffsetAndLength(int history_offset,
1500 int history_length) {
1501 DCHECK_GE(history_offset, -1);
[email protected]e1ed5a12012-08-08 19:57:441502 DCHECK_GE(history_length, 0);
[email protected]9e1ad4b2011-08-14 16:49:191503
avi2b177592014-12-10 02:08:021504 history_list_offset_ = history_offset;
1505 history_list_length_ = history_length;
[email protected]9e1ad4b2011-08-14 16:49:191506}
1507
[email protected]310ebd6302011-10-10 19:06:281508void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291509 if (!webview())
1510 return;
[email protected]26aa0482009-09-30 16:55:271511 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291512}
1513
[email protected]54ca3ca892011-06-07 21:14:541514#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281515void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331516 if (!webview())
1517 return;
1518 if (in_live_resize)
1519 webview()->willStartLiveResize();
1520 else
1521 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541522}
1523#endif
1524
initial.commit09911bf2008-07-26 23:55:291525///////////////////////////////////////////////////////////////////////////////
1526
avi137dc952015-07-24 23:19:141527void RenderViewImpl::SendUpdateState() {
creis8eb8ef22015-11-04 22:51:381528 // We don't use this path in OOPIF-enabled modes.
1529 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
creisae7ce9a2015-11-02 20:52:191530
avi137dc952015-07-24 23:19:141531 HistoryEntry* entry = history_controller_->GetCurrentEntry();
avif937e1d2014-11-02 18:13:071532 if (!entry)
1533 return;
1534
1535 // Don't send state updates for kSwappedOutURL.
esprehnaf92a8f92015-12-12 05:08:011536 if (entry->root().urlString() == kSwappedOutURL)
avif937e1d2014-11-02 18:13:071537 return;
1538
fsamuele8326c742016-01-12 00:49:391539 Send(new ViewHostMsg_UpdateState(routing_id(), page_id_,
1540 HistoryEntryToPageState(entry)));
avif937e1d2014-11-02 18:13:071541}
1542
creis69b184a472015-11-26 05:29:511543void RenderViewImpl::SendFrameStateUpdates() {
1544 // We only use this path in OOPIF-enabled modes.
1545 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
1546
1547 // Tell each frame with pending state to send its UpdateState message.
1548 for (int render_frame_routing_id : frames_with_pending_state_) {
1549 RenderFrameImpl* frame =
1550 RenderFrameImpl::FromRoutingID(render_frame_routing_id);
1551 if (frame)
1552 frame->SendUpdateState();
1553 }
1554 frames_with_pending_state_.clear();
1555}
1556
sataya.mf405d0e2015-07-07 16:51:111557void RenderViewImpl::ApplyWebPreferencesInternal(
1558 const WebPreferences& prefs,
1559 blink::WebView* web_view,
1560 CompositorDependencies* compositor_deps) {
1561 ApplyWebPreferences(prefs, web_view);
1562#if defined(OS_MACOSX) && !defined(OS_IOS)
1563 DCHECK(compositor_deps);
1564 bool is_elastic_overscroll_enabled =
1565 compositor_deps->IsElasticOverscrollEnabled();
1566 web_view->settings()->setReportWheelOverscroll(is_elastic_overscroll_enabled);
1567#endif
1568}
1569
[email protected]310ebd6302011-10-10 19:06:281570bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571571 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1572 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1573 // it is particularly important that we do not call willEnterModalLoop as
1574 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441575 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1576 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571577
1578 message->EnableMessagePumping(); // Runs a nested message loop.
1579 return Send(message);
1580}
1581
[email protected]506563d2014-06-23 12:22:411582void RenderViewImpl::OnForceRedraw(int id) {
1583 ui::LatencyInfo latency_info;
[email protected]f9f3fac2014-08-05 00:47:591584 if (id) {
1585 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
1586 0,
1587 id);
1588 }
[email protected]6be422b2013-12-08 06:47:311589 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]7d08a9352013-10-15 08:24:561590 if (RenderWidgetCompositor* rwc = compositor()) {
[email protected]6be422b2013-12-08 06:47:311591 latency_info_swap_promise_monitor =
dcheng07945f632015-12-26 07:59:321592 rwc->CreateLatencyInfoSwapPromiseMonitor(&latency_info);
[email protected]7d08a9352013-10-15 08:24:561593 }
1594 ScheduleCompositeWithForcedRedraw();
[email protected]c9bc8f12012-12-15 22:20:091595}
1596
[email protected]180ef242013-11-07 06:50:461597// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521598
[email protected]35b2a972014-04-04 15:50:221599WebView* RenderViewImpl::createView(WebLocalFrame* creator,
1600 const WebURLRequest& request,
1601 const WebWindowFeatures& features,
1602 const WebString& frame_name,
1603 WebNavigationPolicy policy,
1604 bool suppress_opener) {
[email protected]8ab04652010-06-12 02:47:261605 ViewHostMsg_CreateWindow_Params params;
fsamuele8326c742016-01-12 00:49:391606 params.opener_id = routing_id();
[email protected]af15bf22013-03-08 01:18:171607 params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]00323f02013-07-24 15:47:411608 if (GetContentClient()->renderer()->AllowPopup())
1609 params.user_gesture = true;
[email protected]8ab04652010-06-12 02:47:261610 params.window_container_type = WindowFeaturesToContainerType(features);
1611 params.session_storage_namespace_id = session_storage_namespace_id_;
[email protected]5cef23d2013-02-27 13:11:211612 if (frame_name != "_blank")
brettw717861b62015-07-24 19:09:091613 params.frame_name = base::UTF16ToUTF8(base::StringPiece16(frame_name));
[email protected]a7531d772014-03-25 16:15:071614 params.opener_render_frame_id =
[email protected]501052ff2014-02-21 22:19:071615 RenderFrameImpl::FromWebFrame(creator)->GetRoutingID();
[email protected]b6cb3a842011-06-24 18:28:411616 params.opener_url = creator->document().url();
alexmosa97d5c52015-06-19 22:19:091617
1618 // The browser process uses the top frame's URL for a content settings check
1619 // to determine whether the popup is allowed. If the top frame is remote,
1620 // its URL is not available, so use its replicated origin instead.
1621 //
1622 // TODO(alexmos): This works fine for regular origins but may break path
1623 // matching for file URLs with OOP subframes that open popups. This should
1624 // be fixed by either moving this lookup to the browser process or removing
1625 // path-based matching for file URLs from content settings. See
1626 // https://crbug.com/466297.
1627 if (creator->top()->isWebLocalFrame()) {
1628 params.opener_top_level_frame_url = creator->top()->document().url();
1629 } else {
1630 params.opener_top_level_frame_url =
brettwdfbcc3b2016-01-20 01:49:171631 blink::WebStringToGURL(creator->top()->securityOrigin().toString());
alexmosa97d5c52015-06-19 22:19:091632 }
1633
brettwdfbcc3b2016-01-20 01:49:171634 GURL security_url(blink::WebStringToGURL(
1635 creator->document().securityOrigin().toString()));
[email protected]7f48b712013-01-25 01:48:301636 if (!security_url.is_valid())
1637 security_url = GURL();
1638 params.opener_security_origin = security_url;
[email protected]147b2bf2013-11-05 04:00:041639 params.opener_suppressed = suppress_opener;
[email protected]f92ce2b2012-03-06 18:02:591640 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]44e55b012013-07-23 14:21:561641 if (!request.isNull()) {
[email protected]41e65502011-01-21 09:29:111642 params.target_url = request.url();
[email protected]44e55b012013-07-23 14:21:561643 params.referrer = GetReferrerFromRequest(creator, request);
1644 }
[email protected]453c1b22013-07-23 09:31:481645 params.features = features;
[email protected]8ab04652010-06-12 02:47:261646
[email protected]22217ed32013-11-18 18:40:231647 for (size_t i = 0; i < features.additionalFeatures.size(); ++i)
1648 params.additional_features.push_back(features.additionalFeatures[i]);
1649
dcheng3ce04b62015-10-26 23:30:551650 ViewHostMsg_CreateWindow_Reply reply;
1651 RenderThread::Get()->Send(new ViewHostMsg_CreateWindow(params, &reply));
1652 if (reply.route_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521653 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521654
[email protected]af15bf22013-03-08 01:18:171655 WebUserGestureIndicator::consumeUserGesture();
[email protected]c59262422012-11-30 21:20:521656
[email protected]7912e822014-04-16 02:37:031657 // While this view may be a background extension page, it can spawn a visible
1658 // render view. So we just assume that the new one is not another background
1659 // page instead of passing on our own value.
1660 // TODO(vangelis): Can we tell if the new view will be a background page?
1661 bool never_visible = false;
[email protected]9115d5f2013-03-24 04:37:411662
fsamuel664e8b62016-01-20 19:54:011663 ResizeParams initial_size = ResizeParams();
mkosiba58fa72f02014-11-12 01:21:361664 initial_size.screen_info = screen_info_;
1665
[email protected]d6fa88f2013-10-18 16:00:431666 // The initial hidden state for the RenderViewImpl here has to match what the
1667 // browser will eventually decide for the given disposition. Since we have to
1668 // return from this call synchronously, we just have to make our best guess
1669 // and rely on the browser sending a WasHidden / WasShown message if it
1670 // disagrees.
naskobd911332014-11-25 01:13:361671 ViewMsg_New_Params view_params;
alexmos5ac402d2015-07-09 07:51:101672
1673 RenderFrameImpl* creator_frame = RenderFrameImpl::FromWebFrame(creator);
1674 view_params.opener_frame_route_id = creator_frame->GetRoutingID();
fsamuele8326c742016-01-12 00:49:391675 DCHECK_EQ(routing_id(), creator_frame->render_view()->GetRoutingID());
alexmos5ac402d2015-07-09 07:51:101676
naskobd911332014-11-25 01:13:361677 view_params.window_was_created_with_opener = true;
1678 view_params.renderer_preferences = renderer_preferences_;
1679 view_params.web_preferences = webkit_preferences_;
dcheng3ce04b62015-10-26 23:30:551680 view_params.view_id = reply.route_id;
1681 view_params.main_frame_routing_id = reply.main_frame_route_id;
1682 view_params.main_frame_widget_routing_id = reply.main_frame_widget_route_id;
naskobd911332014-11-25 01:13:361683 view_params.session_storage_namespace_id =
dcheng3ce04b62015-10-26 23:30:551684 reply.cloned_session_storage_namespace_id;
naskobd911332014-11-25 01:13:361685 view_params.swapped_out = false;
alexmos3448b552015-06-26 07:49:131686 // WebCore will take care of setting the correct name.
alexmosbc7eafa2014-12-06 01:38:091687 view_params.replicated_frame_state = FrameReplicationState();
naskobd911332014-11-25 01:13:361688 view_params.hidden = (params.disposition == NEW_BACKGROUND_TAB);
1689 view_params.never_visible = never_visible;
1690 view_params.next_page_id = 1;
1691 view_params.initial_size = initial_size;
1692 view_params.enable_auto_resize = false;
1693 view_params.min_size = gfx::Size();
1694 view_params.max_size = gfx::Size();
1695
danakj6e3bf8012014-12-16 18:27:531696 RenderViewImpl* view =
dcheng35d31c112015-07-22 00:17:361697 RenderViewImpl::Create(compositor_deps_, view_params, true);
[email protected]8ab04652010-06-12 02:47:261698 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521699
[email protected]48c9cf2d2009-09-16 16:47:521700 return view->webview();
1701}
1702
[email protected]180ef242013-11-07 06:50:461703WebWidget* RenderViewImpl::createPopupMenu(blink::WebPopupType popup_type) {
fsamuele8326c742016-01-12 00:49:391704 RenderWidget* widget = RenderWidget::Create(routing_id(), compositor_deps_,
danakj6e3bf8012014-12-16 18:27:531705 popup_type, screen_info_);
[email protected]3b78ec12014-03-04 05:18:281706 if (!widget)
1707 return NULL;
[email protected]b2e4c70132013-10-03 02:07:511708 if (screen_metrics_emulator_) {
1709 widget->SetPopupOriginAdjustmentsForEmulation(
1710 screen_metrics_emulator_.get());
1711 }
[email protected]48c9cf2d2009-09-16 16:47:521712 return widget->webwidget();
1713}
1714
[email protected]23367482013-06-27 21:06:541715WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() {
[email protected]5f2aa722013-08-07 16:59:411716 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:101717 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341718}
1719
[email protected]35b2a972014-04-04 15:50:221720void RenderViewImpl::printPage(WebLocalFrame* frame) {
[email protected]b0553c7e2012-09-19 21:36:111721 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
fsamuel72464894f2015-12-15 06:59:311722 PrintPage(frame, input_handler().handling_input_event()));
[email protected]48c9cf2d2009-09-16 16:47:521723}
1724
jinho.bang632a1a722014-09-18 03:02:561725void RenderViewImpl::saveImageFromDataURL(const blink::WebString& data_url) {
1726 // Note: We should basically send GURL but we use size-limited string instead
1727 // in order to send a larger data url to save a image for <canvas> or <img>.
1728 if (data_url.length() < kMaxLengthOfDataURLString)
rdsmith6e60c082015-08-24 19:43:481729 Send(new ViewHostMsg_SaveImageFromDataURL(
fsamuele8326c742016-01-12 00:49:391730 routing_id(), GetMainRenderFrame()->GetRoutingID(), data_url.utf8()));
jinho.bang632a1a722014-09-18 03:02:561731}
1732
[email protected]310ebd6302011-10-10 19:06:281733bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121734 const WebString& path,
1735 WebFileChooserCompletion* chooser_completion) {
1736 int id = enumeration_completion_id_++;
1737 enumeration_completions_[id] = chooser_completion;
1738 return Send(new ViewHostMsg_EnumerateDirectory(
kinukob473f002016-02-22 05:23:191739 routing_id(), id, blink::WebStringToFilePath(path)));
[email protected]8a58c1c2011-04-19 18:40:121740}
1741
[email protected]7e9523b2014-03-25 03:02:421742void RenderViewImpl::FrameDidStartLoading(WebFrame* frame) {
[email protected]7e9523b2014-03-25 03:02:421743 DCHECK_GE(frames_in_progress_, 0);
1744 if (frames_in_progress_ == 0)
1745 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
1746 frames_in_progress_++;
[email protected]6dd5c322014-03-12 07:58:461747}
1748
[email protected]7e9523b2014-03-25 03:02:421749void RenderViewImpl::FrameDidStopLoading(WebFrame* frame) {
[email protected]eb473772014-04-11 20:54:331750 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
1751 // calls DidStopLoading() without a matching DidStartLoading().
1752 if (frames_in_progress_ == 0)
1753 return;
[email protected]7e9523b2014-03-25 03:02:421754 frames_in_progress_--;
[email protected]7e9523b2014-03-25 03:02:421755 if (frames_in_progress_ == 0) {
1756 DidStopLoadingIcons();
1757 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
1758 }
[email protected]48c9cf2d2009-09-16 16:47:521759}
1760
lfgcaab5142016-02-26 19:06:521761void RenderViewImpl::AttachWebFrameWidget(blink::WebFrameWidget* frame_widget) {
dcheng3ce04b62015-10-26 23:30:551762 // The previous WebFrameWidget must already be detached by CloseForFrame().
1763 DCHECK(!frame_widget_);
1764 frame_widget_ = frame_widget;
1765}
1766
tommycli8aad3ba2015-08-12 17:57:591767void RenderViewImpl::SetZoomLevel(double zoom_level) {
1768 webview()->setZoomLevel(zoom_level);
1769 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnZoomLevelChanged());
1770}
1771
[email protected]550b0c92013-02-04 05:09:151772void RenderViewImpl::didCancelCompositionOnSelectionChange() {
[email protected]a2214eb2014-06-23 18:31:221773 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]550b0c92013-02-04 05:09:151774}
1775
[email protected]310ebd6302011-10-10 19:06:281776bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101777 if (edit_commands_.empty())
1778 return false;
1779
[email protected]26aa0482009-09-30 16:55:271780 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101781 if (!frame)
1782 return false;
1783
1784 EditCommands::iterator it = edit_commands_.begin();
1785 EditCommands::iterator end = edit_commands_.end();
1786
[email protected]507b33ea2009-09-29 03:56:511787 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101788 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331789 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1790 // key (but it's the exception). Once one edit command is not executed, it
1791 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101792 if (!frame->executeCommand(WebString::fromUTF8(it->name),
[email protected]b77fac52013-06-01 01:03:461793 WebString::fromUTF8(it->value),
[email protected]c39f7442014-02-27 03:33:171794 GetFocusedElement()))
[email protected]b2528b72009-09-24 06:57:101795 break;
[email protected]507b33ea2009-09-29 03:56:511796 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101797 }
1798
[email protected]507b33ea2009-09-29 03:56:511799 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101800}
1801
[email protected]310ebd6302011-10-10 19:06:281802bool RenderViewImpl::runFileChooser(
[email protected]180ef242013-11-07 06:50:461803 const blink::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471804 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351805 // Do not open the file dialog in a hidden RenderView.
1806 if (is_hidden())
1807 return false;
[email protected]e9ff79c2012-10-19 21:31:261808 FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261809 if (params.directory)
[email protected]6bedbef2013-07-31 06:33:491810 ipc_params.mode = FileChooserParams::UploadFolder;
[email protected]b5977a0c2010-08-24 19:46:261811 else if (params.multiSelect)
[email protected]e9ff79c2012-10-19 21:31:261812 ipc_params.mode = FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501813 else if (params.saveAs)
[email protected]e9ff79c2012-10-19 21:31:261814 ipc_params.mode = FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261815 else
[email protected]e9ff79c2012-10-19 21:31:261816 ipc_params.mode = FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471817 ipc_params.title = params.title;
1818 ipc_params.default_file_name =
kinukob473f002016-02-22 05:23:191819 blink::WebStringToFilePath(params.initialValue).BaseName();
[email protected]f9a4c41a2012-05-30 00:05:321820 ipc_params.accept_types.reserve(params.acceptTypes.size());
1821 for (size_t i = 0; i < params.acceptTypes.size(); ++i)
1822 ipc_params.accept_types.push_back(params.acceptTypes[i]);
hironoe9f2732b2014-10-22 08:06:411823 ipc_params.need_local_path = params.needLocalPath;
[email protected]2fdf2352012-11-01 19:23:021824#if defined(OS_ANDROID)
[email protected]b7b4beb2013-07-09 14:06:501825 ipc_params.capture = params.useMediaCapture;
[email protected]2fdf2352012-11-01 19:23:021826#endif
asanka1cbf49812015-11-03 18:28:151827 ipc_params.requestor = params.requestor;
[email protected]cdaf8d02010-03-30 19:52:471828
1829 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461830}
1831
habib.virji597255e2014-09-09 00:30:181832void RenderViewImpl::SetValidationMessageDirection(
1833 base::string16* wrapped_main_text,
1834 blink::WebTextDirection main_text_hint,
1835 base::string16* wrapped_sub_text,
1836 blink::WebTextDirection sub_text_hint) {
1837 if (main_text_hint == blink::WebTextDirectionLeftToRight) {
1838 *wrapped_main_text =
1839 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
1840 } else if (main_text_hint == blink::WebTextDirectionRightToLeft &&
1841 !base::i18n::IsRTL()) {
1842 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
1843 }
1844
1845 if (!wrapped_sub_text->empty()) {
1846 if (sub_text_hint == blink::WebTextDirectionLeftToRight) {
1847 *wrapped_sub_text =
1848 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
1849 } else if (sub_text_hint == blink::WebTextDirectionRightToLeft) {
1850 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
1851 }
1852 }
1853}
1854
[email protected]edc3af82013-12-12 21:24:071855void RenderViewImpl::showValidationMessage(
bokan72a7e342015-12-03 15:46:281856 const blink::WebRect& anchor_in_viewport,
[email protected]edc3af82013-12-12 21:24:071857 const blink::WebString& main_text,
habib.virji597255e2014-09-09 00:30:181858 blink::WebTextDirection main_text_hint,
[email protected]edc3af82013-12-12 21:24:071859 const blink::WebString& sub_text,
habib.virji597255e2014-09-09 00:30:181860 blink::WebTextDirection sub_text_hint) {
[email protected]edc3af82013-12-12 21:24:071861 base::string16 wrapped_main_text = main_text;
1862 base::string16 wrapped_sub_text = sub_text;
habib.virji597255e2014-09-09 00:30:181863
1864 SetValidationMessageDirection(
1865 &wrapped_main_text, main_text_hint, &wrapped_sub_text, sub_text_hint);
1866
[email protected]edc3af82013-12-12 21:24:071867 Send(new ViewHostMsg_ShowValidationMessage(
bokan72a7e342015-12-03 15:46:281868 routing_id(), AdjustValidationMessageAnchor(anchor_in_viewport),
[email protected]2d6836f42014-07-02 17:25:311869 wrapped_main_text, wrapped_sub_text));
[email protected]edc3af82013-12-12 21:24:071870}
1871
1872void RenderViewImpl::hideValidationMessage() {
1873 Send(new ViewHostMsg_HideValidationMessage(routing_id()));
1874}
1875
1876void RenderViewImpl::moveValidationMessage(
bokan72a7e342015-12-03 15:46:281877 const blink::WebRect& anchor_in_viewport) {
[email protected]2d6836f42014-07-02 17:25:311878 Send(new ViewHostMsg_MoveValidationMessage(
bokan72a7e342015-12-03 15:46:281879 routing_id(), AdjustValidationMessageAnchor(anchor_in_viewport)));
[email protected]edc3af82013-12-12 21:24:071880}
1881
[email protected]310ebd6302011-10-10 19:06:281882void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521883}
1884
[email protected]310ebd6302011-10-10 19:06:281885void RenderViewImpl::UpdateTargetURL(const GURL& url,
1886 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581887 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521888 if (latest_url == target_url_)
1889 return;
[email protected]163f8242009-10-30 20:19:551890
[email protected]48c9cf2d2009-09-16 16:47:521891 // Tell the browser to display a destination link.
1892 if (target_url_status_ == TARGET_INFLIGHT ||
1893 target_url_status_ == TARGET_PENDING) {
1894 // If we have a request in-flight, save the URL to be sent when we
1895 // receive an ACK to the in-flight request. We can happily overwrite
1896 // any existing pending sends.
1897 pending_target_url_ = latest_url;
1898 target_url_status_ = TARGET_PENDING;
1899 } else {
mnaganovbf087422015-12-16 05:10:031900 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411901 // see |ParamTraits<GURL>|.
markdittmer67b71ea2016-03-03 22:40:031902 if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:411903 latest_url = GURL();
fsamuele8326c742016-01-12 00:49:391904 Send(new ViewHostMsg_UpdateTargetURL(routing_id(), latest_url));
[email protected]48c9cf2d2009-09-16 16:47:521905 target_url_ = latest_url;
1906 target_url_status_ = TARGET_INFLIGHT;
1907 }
1908}
1909
[email protected]70221f02013-01-31 22:17:071910gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect(
1911 const gfx::RectF& rect) const {
1912 gfx::RectF window_rect = rect;
1913 window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor());
1914 return window_rect;
1915}
1916
creis69b184a472015-11-26 05:29:511917void RenderViewImpl::StartNavStateSyncTimerIfNecessary(RenderFrameImpl* frame) {
1918 // In OOPIF modes, keep track of which frames have pending updates.
creis8eb8ef22015-11-04 22:51:381919 if (SiteIsolationPolicy::UseSubframeNavigationEntries())
creis69b184a472015-11-26 05:29:511920 frames_with_pending_state_.insert(frame->GetRoutingID());
creis8eb8ef22015-11-04 22:51:381921
[email protected]882daa92009-11-05 16:31:311922 int delay;
avif937e1d2014-11-02 18:13:071923 if (send_content_state_immediately_)
[email protected]882daa92009-11-05 16:31:311924 delay = 0;
1925 else if (is_hidden())
avif937e1d2014-11-02 18:13:071926 delay = kDelaySecondsForContentStateSyncHidden;
[email protected]882daa92009-11-05 16:31:311927 else
avif937e1d2014-11-02 18:13:071928 delay = kDelaySecondsForContentStateSync;
[email protected]882daa92009-11-05 16:31:311929
avif937e1d2014-11-02 18:13:071930 if (nav_state_sync_timer_.IsRunning()) {
[email protected]882daa92009-11-05 16:31:311931 // The timer is already running. If the delay of the timer maches the amount
1932 // we want to delay by, then return. Otherwise stop the timer so that it
1933 // gets started with the right delay.
avif937e1d2014-11-02 18:13:071934 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
[email protected]882daa92009-11-05 16:31:311935 return;
avif937e1d2014-11-02 18:13:071936 nav_state_sync_timer_.Stop();
[email protected]882daa92009-11-05 16:31:311937 }
1938
creis69b184a472015-11-26 05:29:511939 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
1940 // In OOPIF modes, tell each frame with pending state to inform the browser.
1941 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
1942 &RenderViewImpl::SendFrameStateUpdates);
1943 } else {
1944 // By default, send an UpdateState for the current history item.
1945 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
1946 &RenderViewImpl::SendUpdateState);
1947 }
[email protected]882daa92009-11-05 16:31:311948}
1949
[email protected]310ebd6302011-10-10 19:06:281950void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551951 mouse_over_url_ = GURL(url);
1952 UpdateTargetURL(mouse_over_url_, focus_url_);
1953}
1954
[email protected]310ebd6302011-10-10 19:06:281955void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551956 focus_url_ = GURL(url);
1957 UpdateTargetURL(focus_url_, mouse_over_url_);
1958}
1959
[email protected]35b2a972014-04-04 15:50:221960void RenderViewImpl::startDragging(WebLocalFrame* frame,
[email protected]0407e422012-05-18 19:51:251961 const WebDragData& data,
[email protected]310ebd6302011-10-10 19:06:281962 WebDragOperationsMask mask,
1963 const WebImage& image,
[email protected]ceb36f7d2012-10-31 18:33:241964 const WebPoint& webImageOffset) {
oshimab3313232016-01-28 01:13:221965 blink::WebRect offset_in_window(webImageOffset.x, webImageOffset.y, 0, 0);
1966 convertViewportToWindow(&offset_in_window);
[email protected]dc293a72013-07-01 11:11:221967 DropData drop_data(DropDataBuilder::Build(data));
[email protected]b67151d2012-05-25 23:23:241968 drop_data.referrer_policy = frame->document().referrerPolicy();
oshimab3313232016-01-28 01:13:221969 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y);
fsamuele8326c742016-01-12 00:49:391970 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask,
1971 image.getSkBitmap(), imageOffset,
[email protected]41d86852012-11-07 12:23:241972 possible_drag_event_info_));
[email protected]48c9cf2d2009-09-16 16:47:521973}
1974
[email protected]310ebd6302011-10-10 19:06:281975bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451976 return renderer_preferences_.can_accept_load_drops;
1977}
1978
[email protected]310ebd6302011-10-10 19:06:281979void RenderViewImpl::focusNext() {
fsamuele8326c742016-01-12 00:49:391980 Send(new ViewHostMsg_TakeFocus(routing_id(), false));
[email protected]48c9cf2d2009-09-16 16:47:521981}
1982
[email protected]310ebd6302011-10-10 19:06:281983void RenderViewImpl::focusPrevious() {
fsamuele8326c742016-01-12 00:49:391984 Send(new ViewHostMsg_TakeFocus(routing_id(), true));
[email protected]48c9cf2d2009-09-16 16:47:521985}
1986
esprehn3d4471a2015-09-17 07:13:201987// TODO(esprehn): Blink only ever passes Elements, this should take WebElement.
estade31c54342015-01-23 03:34:361988void RenderViewImpl::focusedNodeChanged(const WebNode& fromNode,
1989 const WebNode& toNode) {
[email protected]1875bc02014-03-14 06:33:591990 has_scrolled_focused_editable_node_into_rect_ = false;
1991
jennyz399d6e62014-12-16 01:40:051992 gfx::Rect node_bounds;
esprehn3d4471a2015-09-17 07:13:201993 bool is_editable = false;
estade31c54342015-01-23 03:34:361994 if (!toNode.isNull() && toNode.isElementNode()) {
esprehn3d4471a2015-09-17 07:13:201995 WebElement element = const_cast<WebNode&>(toNode).to<WebElement>();
oshimae2b3b402015-12-04 04:27:241996 blink::WebRect rect = element.boundsInViewport();
1997 convertViewportToWindow(&rect);
1998 node_bounds = gfx::Rect(rect);
esprehn3d4471a2015-09-17 07:13:201999 is_editable = element.isEditable();
jennyz399d6e62014-12-16 01:40:052000 }
fsamuele8326c742016-01-12 00:49:392001 Send(new ViewHostMsg_FocusedNodeChanged(routing_id(), is_editable,
jennyz399d6e62014-12-16 01:40:052002 node_bounds));
[email protected]a4b103b2010-10-05 18:46:072003
estade31c54342015-01-23 03:34:362004 // TODO(estade): remove.
2005 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(toNode));
[email protected]95640212014-07-26 18:14:302006
estade31c54342015-01-23 03:34:362007 RenderFrameImpl* previous_frame = nullptr;
2008 if (!fromNode.isNull())
2009 previous_frame = RenderFrameImpl::FromWebFrame(fromNode.document().frame());
2010 RenderFrameImpl* new_frame = nullptr;
2011 if (!toNode.isNull())
2012 new_frame = RenderFrameImpl::FromWebFrame(toNode.document().frame());
2013
2014 if (previous_frame && previous_frame != new_frame)
2015 previous_frame->FocusedNodeChanged(WebNode());
2016 if (new_frame)
2017 new_frame->FocusedNodeChanged(toNode);
2018
2019 // TODO(dmazzoni): remove once there's a separate a11y tree per frame.
naskoe8d115752015-08-07 00:43:132020 if (main_render_frame_)
2021 main_render_frame_->FocusedNodeChangedForAccessibility(toNode);
[email protected]08e9e132010-06-01 16:58:492022}
2023
[email protected]169d4282011-11-30 19:33:592024void RenderViewImpl::didUpdateLayout() {
[email protected]d01b2a62013-09-18 23:21:332025 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidUpdateLayout());
2026
[email protected]169d4282011-11-30 19:33:592027 // We don't always want to set up a timer, only if we've been put in that
2028 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2029 // message.
2030 if (!send_preferred_size_changes_ || !webview())
2031 return;
2032
2033 if (check_preferred_size_timer_.IsRunning())
2034 return;
2035 check_preferred_size_timer_.Start(FROM_HERE,
2036 TimeDelta::FromMilliseconds(0), this,
2037 &RenderViewImpl::CheckPreferredSize);
2038}
2039
[email protected]310ebd6302011-10-10 19:06:282040void RenderViewImpl::navigateBackForwardSoon(int offset) {
fsamuele8326c742016-01-12 00:49:392041 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id(), offset));
[email protected]48c9cf2d2009-09-16 16:47:522042}
2043
[email protected]310ebd6302011-10-10 19:06:282044int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002045 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522046}
2047
[email protected]310ebd6302011-10-10 19:06:282048int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002049 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522050}
2051
[email protected]180ef242013-11-07 06:50:462052// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:512053
[email protected]310ebd6302011-10-10 19:06:282054void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122055 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2056 // we won't have to test for user gesture anymore and we can
2057 // move that code back to render_widget.cc
[email protected]af15bf22013-03-08 01:18:172058 if (WebUserGestureIndicator::isProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:302059 !RenderThreadImpl::current()->layout_test_mode()) {
fsamuele8326c742016-01-12 00:49:392060 Send(new ViewHostMsg_Focus(routing_id()));
[email protected]ea42e7782010-08-23 23:58:122061 }
2062}
2063
initial.commit09911bf2008-07-26 23:55:292064// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282065// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292066// point to dispatch the ShowView message.
2067//
2068// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282069// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292070//
[email protected]310ebd6302011-10-10 19:06:282071void RenderViewImpl::show(WebNavigationPolicy policy) {
[email protected]b2142e962012-10-30 13:59:252072 if (did_show_) {
[email protected]b2142e962012-10-30 13:59:252073 // When supports_multiple_windows is disabled, popups are reusing
2074 // the same view. In some scenarios, this makes WebKit to call show() twice.
[email protected]c9edabd2013-05-23 13:56:242075 if (webkit_preferences_.supports_multiple_windows)
2076 NOTREACHED() << "received extraneous Show call";
initial.commit09911bf2008-07-26 23:55:292077 return;
[email protected]b2142e962012-10-30 13:59:252078 }
initial.commit09911bf2008-07-26 23:55:292079 did_show_ = true;
2080
[email protected]b2142e962012-10-30 13:59:252081 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2082
bokanc007c3a2015-02-03 07:15:562083 // NOTE: initial_rect_ may still have its default values at this point, but
initial.commit09911bf2008-07-26 23:55:292084 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2085 // browser process will impose a default position otherwise.
fsamuele8326c742016-01-12 00:49:392086 Send(new ViewHostMsg_ShowView(opener_id_, routing_id(),
2087 NavigationPolicyToDisposition(policy),
2088 initial_rect_, opened_by_user_gesture_));
bokanc007c3a2015-02-03 07:15:562089 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:292090}
2091
[email protected]217690d2012-01-27 07:33:112092bool RenderViewImpl::requestPointerLock() {
2093 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2094}
2095
2096void RenderViewImpl::requestPointerUnlock() {
2097 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2098}
2099
2100bool RenderViewImpl::isPointerLocked() {
2101 return mouse_lock_dispatcher_->IsMouseLockedTo(
2102 webwidget_mouse_lock_target_.get());
2103}
2104
miletuse8d28ba2015-06-19 04:52:042105void RenderViewImpl::onMouseDown(const WebNode& mouse_down_node) {
2106 FOR_EACH_OBSERVER(
2107 RenderViewObserver, observers_, OnMouseDown(mouse_down_node));
2108}
2109
[email protected]c68c3e4e2013-01-24 00:36:562110void RenderViewImpl::didHandleGestureEvent(
2111 const WebGestureEvent& event,
2112 bool event_cancelled) {
2113 RenderWidget::didHandleGestureEvent(event, event_cancelled);
[email protected]bb37b652013-11-27 23:47:112114
[email protected]91dcc6d32014-07-30 00:01:332115 if (!event_cancelled) {
2116 FOR_EACH_OBSERVER(
2117 RenderViewObserver, observers_, DidHandleGestureEvent(event));
2118 }
2119
jdduke45762d22014-10-07 04:19:082120 // TODO(ananta): Piggyback off existing IPCs to communicate this information,
2121 // crbug/420130.
2122#if defined(OS_WIN)
[email protected]bb37b652013-11-27 23:47:112123 if (event.type != blink::WebGestureEvent::GestureTap)
2124 return;
2125
[email protected]91dcc6d32014-07-30 00:01:332126 // TODO(estade): hit test the event against focused node to make sure
2127 // the tap actually hit the focused node.
jdduke3bf083fe2015-09-29 23:40:532128 blink::WebTextInputType text_input_type = GetWebView()->textInputType();
[email protected]bb37b652013-11-27 23:47:112129
2130 Send(new ViewHostMsg_FocusedNodeTouched(
2131 routing_id(), text_input_type != blink::WebTextInputTypeNone));
jdduke45762d22014-10-07 04:19:082132#endif
[email protected]c68c3e4e2013-01-24 00:36:562133}
2134
[email protected]6e89eb72013-07-23 13:28:222135void RenderViewImpl::initializeLayerTreeView() {
2136 RenderWidget::initializeLayerTreeView();
2137 RenderWidgetCompositor* rwc = compositor();
[email protected]9f7638f42014-05-30 01:51:162138 if (!rwc)
[email protected]6e89eb72013-07-23 13:28:222139 return;
[email protected]9f7638f42014-05-30 01:51:162140
ccameron1f89c002014-10-21 06:19:052141 bool use_threaded_event_handling = true;
2142#if defined(OS_MACOSX) && !defined(OS_IOS)
ccamerona7644752014-12-30 01:16:312143 // Disable threaded event handling if content is not handling the elastic
2144 // overscroll effect. This includes the cases where the elastic overscroll
2145 // effect is being handled by Blink (because of command line flags) and older
2146 // operating system versions which do not have an elastic overscroll effect
2147 // (SnowLeopard, which has Aqua scrollbars which need synchronous updates).
2148 use_threaded_event_handling = compositor_deps_->IsElasticOverscrollEnabled();
[email protected]9f7638f42014-05-30 01:51:162149#endif
ccameron1f89c002014-10-21 06:19:052150 if (use_threaded_event_handling) {
2151 RenderThreadImpl* render_thread = RenderThreadImpl::current();
2152 // render_thread may be NULL in tests.
2153 InputHandlerManager* input_handler_manager =
2154 render_thread ? render_thread->input_handler_manager() : NULL;
2155 if (input_handler_manager) {
2156 input_handler_manager->AddInputHandler(
ymalikfb8b9642016-01-12 05:24:222157 routing_id(), rwc->GetInputHandler(), AsWeakPtr(),
dtapuska0bd451a2016-02-18 17:08:102158 webkit_preferences_.enable_scroll_animator,
2159 UseGestureBasedWheelScrolling());
ccameron1f89c002014-10-21 06:19:052160 }
2161 }
[email protected]6e89eb72013-07-23 13:28:222162}
2163
[email protected]180ef242013-11-07 06:50:462164// blink::WebFrameClient -----------------------------------------------------
[email protected]3d9689372009-09-10 04:29:172165
[email protected]5e92282f2012-08-17 08:11:572166void RenderViewImpl::Repaint(const gfx::Size& size) {
[email protected]3d9ec5052013-01-02 22:05:252167 OnRepaint(size);
[email protected]5e92282f2012-08-17 08:11:572168}
2169
[email protected]b2324b092012-11-01 10:34:112170void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
2171 const std::string& value) {
2172 EditCommands edit_commands;
2173 edit_commands.push_back(EditCommand(name, value));
2174 OnSetEditCommandsForNextKeyEvent(edit_commands);
2175}
2176
2177void RenderViewImpl::ClearEditCommands() {
2178 edit_commands_.clear();
2179}
2180
[email protected]180ef242013-11-07 06:50:462181SSLStatus RenderViewImpl::GetSSLStatusOfFrame(blink::WebFrame* frame) const {
[email protected]83c0abca2013-07-23 20:09:422182 std::string security_info;
2183 if (frame && frame->dataSource())
2184 security_info = frame->dataSource()->response().securityInfo();
2185
estarka5635c42015-07-14 00:06:532186 SSLStatus result;
2187 CHECK(DeserializeSecurityInfo(security_info, &result));
2188 return result;
[email protected]e4495212012-12-06 03:09:122189}
2190
[email protected]b38806a2013-10-04 16:01:382191const std::string& RenderViewImpl::GetAcceptLanguages() const {
2192 return renderer_preferences_.accept_languages;
2193}
2194
oshimae2b3b402015-12-04 04:27:242195void RenderViewImpl::convertViewportToWindow(blink::WebRect* rect) {
oshimaf866dab2015-12-05 00:41:542196 RenderWidget::convertViewportToWindow(rect);
oshimae2b3b402015-12-04 04:27:242197}
2198
huangs2a342352015-12-15 16:59:242199gfx::RectF RenderViewImpl::ElementBoundsInWindow(
2200 const blink::WebElement& element) {
2201 blink::WebRect bounding_box_in_window = element.boundsInViewport();
2202 convertViewportToWindow(&bounding_box_in_window);
2203 return gfx::RectF(bounding_box_in_window);
2204}
2205
oshimac059194c2016-01-12 19:40:152206float RenderViewImpl::GetDeviceScaleFactorForTest() const {
2207 return device_scale_factor_;
2208}
2209
oshima4300f52e92016-02-18 21:51:042210gfx::Point RenderViewImpl::ConvertWindowPointToViewport(
2211 const gfx::Point& point) {
2212 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0);
2213 convertWindowToViewport(&point_in_viewport);
2214 return gfx::Point(point_in_viewport.x, point_in_viewport.y);
2215}
2216
[email protected]35b2a972014-04-04 15:50:222217void RenderViewImpl::didChangeIcon(WebLocalFrame* frame,
[email protected]41225fe2013-03-29 05:32:022218 WebIconURL::Type icon_type) {
2219 if (frame->parent())
2220 return;
2221
[email protected]41225fe2013-03-29 05:32:022222 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type);
2223 std::vector<FaviconURL> urls;
2224 for (size_t i = 0; i < icon_urls.size(); i++) {
[email protected]2bd262b2014-04-16 05:31:232225 std::vector<gfx::Size> sizes;
[email protected]f34ac132014-03-20 23:02:052226 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
2227 urls.push_back(FaviconURL(
2228 icon_urls[i].iconURL(), ToFaviconType(icon_urls[i].iconType()), sizes));
[email protected]41225fe2013-03-29 05:32:022229 }
2230 SendUpdateFaviconURL(urls);
[email protected]5019ef12010-04-27 17:26:582231}
2232
[email protected]310ebd6302011-10-10 19:06:282233void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:072234 // We don't always want to send the change messages over IPC, only if we've
2235 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2236 // message.
2237 if (!send_preferred_size_changes_ || !webview())
2238 return;
2239
[email protected]e76b7972013-06-06 02:58:482240 gfx::Size size = webview()->contentsPreferredMinimumSize();
[email protected]705243f2010-05-05 19:58:072241 if (size == preferred_size_)
2242 return;
[email protected]c27324b2009-11-19 22:44:292243
[email protected]705243f2010-05-05 19:58:072244 preferred_size_ = size;
fsamuele8326c742016-01-12 00:49:392245 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id(),
[email protected]705243f2010-05-05 19:58:072246 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172247}
2248
[email protected]180ef242013-11-07 06:50:462249blink::WebString RenderViewImpl::acceptLanguages() {
[email protected]9982c802013-06-12 15:22:062250 return WebString::fromUTF8(renderer_preferences_.accept_languages);
2251}
2252
[email protected]e9ff79c2012-10-19 21:31:262253// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:312254
[email protected]310ebd6302011-10-10 19:06:282255bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:312256 return RenderWidget::Send(message);
2257}
2258
avi8a45c1092016-03-01 16:12:342259RenderWidget* RenderViewImpl::GetWidget() const {
2260 return const_cast<RenderWidget*>(static_cast<const RenderWidget*>(this));
2261}
2262
mostynbc33353232014-09-12 09:38:312263RenderFrameImpl* RenderViewImpl::GetMainRenderFrame() {
nasko77de2312015-05-12 03:09:162264 return main_render_frame_;
[email protected]b849847b2013-12-10 21:57:582265}
2266
[email protected]82114f52012-03-20 22:53:412267int RenderViewImpl::GetRoutingID() const {
fsamuele8326c742016-01-12 00:49:392268 return routing_id();
[email protected]a2ef54c2011-10-10 16:20:312269}
2270
[email protected]82114f52012-03-20 22:53:412271gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:312272 return size();
2273}
2274
oshima129b75e2016-01-14 09:15:142275float RenderViewImpl::GetDeviceScaleFactor() const {
2276 return device_scale_factor_;
2277}
2278
[email protected]82114f52012-03-20 22:53:412279WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:312280 return webkit_preferences_;
2281}
2282
[email protected]324825d2012-11-30 12:37:152283void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
2284 OnUpdateWebPreferences(preferences);
2285}
2286
[email protected]180ef242013-11-07 06:50:462287blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:312288 return webview();
2289}
2290
lfgcaab5142016-02-26 19:06:522291blink::WebFrameWidget* RenderViewImpl::GetWebFrameWidget() {
2292 return frame_widget_;
2293}
2294
[email protected]310ebd6302011-10-10 19:06:282295bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:312296 return (!send_preferred_size_changes_ ||
2297 (disable_scrollbars_size_limit_.width() <= width ||
2298 disable_scrollbars_size_limit_.height() <= height));
2299}
2300
[email protected]82114f52012-03-20 22:53:412301int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:312302 return enabled_bindings_;
2303}
2304
avif937e1d2014-11-02 18:13:072305bool RenderViewImpl::GetContentStateImmediately() const {
2306 return send_content_state_immediately_;
[email protected]a2ef54c2011-10-10 16:20:312307}
2308
[email protected]180ef242013-11-07 06:50:462309blink::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:312310 return visibilityState();
2311}
2312
[email protected]3c71576ce2013-07-23 02:00:012313void RenderViewImpl::DidStartLoading() {
[email protected]6dd5c322014-03-12 07:58:462314 main_render_frame_->didStartLoading(true);
[email protected]3c71576ce2013-07-23 02:00:012315}
2316
2317void RenderViewImpl::DidStopLoading() {
[email protected]6dd5c322014-03-12 07:58:462318 main_render_frame_->didStopLoading();
[email protected]3c71576ce2013-07-23 02:00:012319}
2320
estade78d655f82015-01-30 01:55:082321blink::WebElement RenderViewImpl::GetFocusedElement() const {
2322 if (!webview())
2323 return WebElement();
2324 WebFrame* focused_frame = webview()->focusedFrame();
2325 if (focused_frame) {
2326 WebDocument doc = focused_frame->document();
2327 if (!doc.isNull())
2328 return doc.focusedElement();
2329 }
2330
2331 return WebElement();
2332}
2333
mcnee432e47d2015-11-09 19:37:462334void RenderViewImpl::OnSetPageScale(float page_scale_factor) {
ccameronb7c1d6c2015-03-09 17:08:242335 if (!webview())
2336 return;
mcnee432e47d2015-11-09 19:37:462337 webview()->setPageScaleFactor(page_scale_factor);
ccameronb7c1d6c2015-03-09 17:08:242338}
2339
[email protected]e9ff79c2012-10-19 21:31:262340void RenderViewImpl::OnZoom(PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:512341 if (!webview()) // Not sure if this can happen, but no harm in being safe.
2342 return;
2343
[email protected]258d31122010-05-09 10:59:412344 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:102345
[email protected]b75b8292010-10-01 07:28:252346 double old_zoom_level = webview()->zoomLevel();
2347 double zoom_level;
[email protected]e9ff79c2012-10-19 21:31:262348 if (zoom == PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:252349 zoom_level = 0;
2350 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
2351 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:482352 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:252353 } else {
2354 // Either the user hit the zoom factor limit and thus the zoom level is now
2355 // not a whole number, or a plugin changed it to a custom value. We want
2356 // to go to the next whole number so that the user can always get back to
2357 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:482358 if ((old_zoom_level > 1 && zoom > 0) ||
2359 (old_zoom_level < 1 && zoom < 0)) {
2360 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:252361 } else {
2362 // We're going towards 100%, so first go to the next whole number.
2363 zoom_level = static_cast<int>(old_zoom_level);
2364 }
2365 }
tommycli8aad3ba2015-08-12 17:57:592366 SetZoomLevel(zoom_level);
[email protected]47578fa02011-11-02 19:34:412367 zoomLevelChanged();
2368}
2369
[email protected]310ebd6302011-10-10 19:06:282370void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
2371 double zoom_level) {
[email protected]cbe55d22013-02-14 17:04:332372#if !defined(OS_ANDROID)
2373 // On Android, page zoom isn't used, and in case of WebView, text zoom is used
2374 // for legacy WebView text scaling emulation. Thus, the code that resets
2375 // the zoom level from this map will be effectively resetting text zoom level.
[email protected]9d797f32010-04-23 07:17:542376 host_zoom_levels_[url] = zoom_level;
[email protected]cbe55d22013-02-14 17:04:332377#endif
initial.commit09911bf2008-07-26 23:55:292378}
2379
[email protected]d42bf472014-06-14 01:49:382380void RenderViewImpl::OnSetZoomLevelForView(bool uses_temporary_zoom_level,
2381 double level) {
2382 uses_temporary_zoom_level_ = uses_temporary_zoom_level;
2383
2384 webview()->hidePopups();
tommycli8aad3ba2015-08-12 17:57:592385 SetZoomLevel(level);
[email protected]d42bf472014-06-14 01:49:382386}
2387
[email protected]310ebd6302011-10-10 19:06:282388void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:272389 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:292390}
2391
[email protected]310ebd6302011-10-10 19:06:282392void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:272393 WebString no_encoding;
2394 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:182395}
2396
[email protected]310ebd6302011-10-10 19:06:282397void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]940ed1d2012-11-27 21:03:212398 if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) &&
2399 !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) {
[email protected]69a0a132014-03-26 16:45:022400 // WebUIExtensionData deletes itself when we're destroyed.
[email protected]940ed1d2012-11-27 21:03:212401 new WebUIExtensionData(this);
nasko1fa0fb62015-12-09 01:49:572402
2403 if (main_render_frame_)
rockot8df5c722016-01-26 07:15:142404 main_render_frame_->EnableMojoBindings(false /* for_layout_tests */);
2405 }
2406
2407 if ((enabled_bindings_flags & BINDINGS_POLICY_MOJO) &&
2408 !(enabled_bindings_ & BINDINGS_POLICY_MOJO) &&
2409 main_render_frame_) {
2410 main_render_frame_->EnableMojoBindings(true /* for_layout_tests */);
[email protected]940ed1d2012-11-27 21:03:212411 }
2412
[email protected]81e63782009-02-27 19:35:092413 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:042414
2415 // Keep track of the total bindings accumulated in this process.
2416 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:292417}
2418
[email protected]dc293a72013-07-01 11:11:222419void RenderViewImpl::OnDragTargetDragEnter(const DropData& drop_data,
[email protected]310ebd6302011-10-10 19:06:282420 const gfx::Point& client_point,
2421 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:422422 WebDragOperationsMask ops,
2423 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:552424 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]dc293a72013-07-01 11:11:222425 DropDataToWebDragData(drop_data),
oshima4300f52e92016-02-18 21:51:042426 ConvertWindowPointToViewport(client_point),
[email protected]59f4f2fa2011-03-23 01:00:552427 screen_point,
[email protected]1f2230b2012-05-17 23:43:422428 ops,
2429 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:552430
fsamuele8326c742016-01-12 00:49:392431 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
[email protected]59f4f2fa2011-03-23 01:00:552432}
2433
[email protected]310ebd6302011-10-10 19:06:282434void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
2435 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:422436 WebDragOperationsMask ops,
2437 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:552438 WebDragOperation operation = webview()->dragTargetDragOver(
oshima4300f52e92016-02-18 21:51:042439 ConvertWindowPointToViewport(client_point),
[email protected]59f4f2fa2011-03-23 01:00:552440 screen_point,
[email protected]1f2230b2012-05-17 23:43:422441 ops,
2442 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:552443
fsamuele8326c742016-01-12 00:49:392444 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
[email protected]59f4f2fa2011-03-23 01:00:552445}
2446
[email protected]310ebd6302011-10-10 19:06:282447void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:552448 webview()->dragTargetDragLeave();
2449}
2450
[email protected]310ebd6302011-10-10 19:06:282451void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
[email protected]1f2230b2012-05-17 23:43:422452 const gfx::Point& screen_point,
2453 int key_modifiers) {
oshima4300f52e92016-02-18 21:51:042454 webview()->dragTargetDrop(
2455 ConvertWindowPointToViewport(client_point), screen_point, key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:552456}
2457
[email protected]7a6d773f2014-04-04 01:25:092458void RenderViewImpl::OnDragSourceEnded(const gfx::Point& client_point,
2459 const gfx::Point& screen_point,
2460 WebDragOperation op) {
oshima4300f52e92016-02-18 21:51:042461 webview()->dragSourceEndedAt(
2462 ConvertWindowPointToViewport(client_point), screen_point, op);
initial.commit09911bf2008-07-26 23:55:292463}
2464
[email protected]310ebd6302011-10-10 19:06:282465void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:272466 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:292467}
2468
[email protected]310ebd6302011-10-10 19:06:282469void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:592470 webkit_preferences_ = prefs;
sataya.mf405d0e2015-07-07 16:51:112471 ApplyWebPreferencesInternal(webkit_preferences_, webview(), compositor_deps_);
initial.commit09911bf2008-07-26 23:55:292472}
2473
[email protected]310ebd6302011-10-10 19:06:282474void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:512475 int id,
[email protected]c42de732013-02-16 06:26:312476 const std::vector<base::FilePath>& paths) {
[email protected]600ea402011-04-12 00:01:512477 if (!enumeration_completions_[id])
2478 return;
2479
2480 WebVector<WebString> ws_file_names(paths.size());
2481 for (size_t i = 0; i < paths.size(); ++i)
[email protected]728c2ee2013-06-25 04:01:072482 ws_file_names[i] = paths[i].AsUTF16Unsafe();
[email protected]600ea402011-04-12 00:01:512483
2484 enumeration_completions_[id]->didChooseFile(ws_file_names);
2485 enumeration_completions_.erase(id);
2486}
2487
[email protected]fb11b6a42012-03-14 07:25:122488void RenderViewImpl::OnFileChooserResponse(
hirono570357bd2014-10-08 12:39:272489 const std::vector<content::FileChooserFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:362490 // This could happen if we navigated to a different page before the user
2491 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:472492 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:362493 return;
2494
[email protected]b5188522012-03-15 00:18:042495 // Convert Chrome's SelectedFileInfo list to WebKit's.
2496 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
2497 files.size());
2498 for (size_t i = 0; i < files.size(); ++i) {
2499 WebFileChooserCompletion::SelectedFileInfo selected_file;
hirono570357bd2014-10-08 12:39:272500 selected_file.path = files[i].file_path.AsUTF16Unsafe();
[email protected]728c2ee2013-06-25 04:01:072501 selected_file.displayName =
2502 base::FilePath(files[i].display_name).AsUTF16Unsafe();
hironoe9f2732b2014-10-22 08:06:412503 if (files[i].file_system_url.is_valid()) {
2504 selected_file.fileSystemURL = files[i].file_system_url;
2505 selected_file.length = files[i].length;
2506 selected_file.modificationTime = files[i].modification_time.ToDoubleT();
2507 selected_file.isDirectory = files[i].is_directory;
2508 }
[email protected]b5188522012-03-15 00:18:042509 selected_files[i] = selected_file;
2510 }
[email protected]a1128322009-10-06 18:38:462511
[email protected]cdaf8d02010-03-30 19:52:472512 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:042513 file_chooser_completions_.front()->completion->didChooseFile(
2514 selected_files);
[email protected]cdaf8d02010-03-30 19:52:472515 file_chooser_completions_.pop_front();
2516
2517 // If there are more pending file chooser requests, schedule one now.
2518 if (!file_chooser_completions_.empty()) {
fsamuele8326c742016-01-12 00:49:392519 Send(new ViewHostMsg_RunFileChooser(
2520 routing_id(), file_chooser_completions_.front()->params));
[email protected]cdaf8d02010-03-30 19:52:472521 }
initial.commit09911bf2008-07-26 23:55:292522}
2523
[email protected]244ac1892011-12-02 17:04:472524void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
2525 const gfx::Size& max_size) {
2526 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
2527 if (!webview())
2528 return;
oshima33ec97cd2015-12-14 19:40:242529
[email protected]97e1bf72013-03-06 14:06:052530 auto_resize_mode_ = true;
oshima33ec97cd2015-12-14 19:40:242531 if (IsUseZoomForDSFEnabled()) {
2532 webview()->enableAutoResizeMode(
2533 gfx::ScaleToCeiledSize(min_size, device_scale_factor_),
2534 gfx::ScaleToCeiledSize(max_size, device_scale_factor_));
2535 } else {
2536 webview()->enableAutoResizeMode(min_size, max_size);
2537 }
[email protected]61e2b3cc2012-03-02 16:13:342538}
2539
2540void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
2541 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
2542 if (!webview())
2543 return;
[email protected]97e1bf72013-03-06 14:06:052544 auto_resize_mode_ = false;
[email protected]61e2b3cc2012-03-02 16:13:342545 webview()->disableAutoResizeMode();
2546
[email protected]eac2b362013-05-22 07:01:452547 if (!new_size.IsEmpty()) {
mfomitchev2600fd7c2016-02-17 20:53:392548 ResizeParams resize_params;
2549 resize_params.new_size = new_size;
2550 resize_params.physical_backing_size = physical_backing_size_;
2551 resize_params.top_controls_shrink_blink_size =
2552 top_controls_shrink_blink_size_;
2553 resize_params.top_controls_height = top_controls_height_;
2554 resize_params.visible_viewport_size = visible_viewport_size_;
2555 resize_params.resizer_rect = resizer_rect_;
2556 resize_params.is_fullscreen_granted = is_fullscreen_granted();
2557 resize_params.display_mode = display_mode_;
2558 resize_params.needs_resize_ack = false;
2559 Resize(resize_params);
[email protected]eac2b362013-05-22 07:01:452560 }
[email protected]244ac1892011-12-02 17:04:472561}
2562
[email protected]2bf834f2011-11-17 20:02:212563void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:242564 if (send_preferred_size_changes_)
2565 return;
[email protected]9fb325e2010-05-06 18:23:242566 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:392567
[email protected]d812fd12011-05-27 23:05:072568 // Start off with an initial preferred size notification (in case
2569 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:592570 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:082571}
2572
[email protected]310ebd6302011-10-10 19:06:282573void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:102574 const gfx::Size& disable_scrollbar_size_limit) {
2575 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
2576}
2577
[email protected]310ebd6302011-10-10 19:06:282578void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:262579 const RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:502580 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]ebd5ea52014-05-28 14:51:152581 std::string old_accept_languages = renderer_preferences_.accept_languages;
2582
[email protected]80d96fa2009-06-10 22:34:512583 renderer_preferences_ = renderer_prefs;
ananta59b9fe72015-04-07 01:33:262584
[email protected]6e282c92009-07-24 01:19:372585 UpdateFontRenderingFromRendererPrefs();
ananta59b9fe72015-04-07 01:33:262586 UpdateThemePrefs();
[email protected]38a85712013-01-02 22:45:022587
[email protected]dcc297772014-04-10 22:20:522588#if defined(USE_DEFAULT_RENDER_THEME)
[email protected]1596efb2013-01-17 22:13:012589 if (renderer_prefs.use_custom_colors) {
esprehn021507d2015-11-13 23:35:012590 blink::setFocusRingColor(renderer_prefs.focus_ring_color);
[email protected]180ef242013-11-07 06:50:462591 blink::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]1596efb2013-01-17 22:13:012592
2593 if (webview()) {
[email protected]1596efb2013-01-17 22:13:012594 webview()->setSelectionColors(
2595 renderer_prefs.active_selection_bg_color,
2596 renderer_prefs.active_selection_fg_color,
2597 renderer_prefs.inactive_selection_bg_color,
2598 renderer_prefs.inactive_selection_fg_color);
2599 webview()->themeChanged();
2600 }
[email protected]644d77e2010-01-27 01:03:102601 }
[email protected]c997bc42014-04-11 18:25:582602#endif // defined(USE_DEFAULT_RENDER_THEME)
[email protected]d299d972012-03-23 02:26:552603
[email protected]d051d9a2011-12-10 02:02:502604 // If the zoom level for this page matches the old zoom default, and this
2605 // is not a plugin, update the zoom level to match the new default.
[email protected]82307f6b2014-08-07 03:30:122606 if (webview() && webview()->mainFrame()->isWebLocalFrame() &&
2607 !webview()->mainFrame()->document().isPluginDocument() &&
[email protected]cbe55d22013-02-14 17:04:332608 !ZoomValuesEqual(old_zoom_level,
2609 renderer_preferences_.default_zoom_level) &&
[email protected]e9ff79c2012-10-19 21:31:262610 ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
tommycli8aad3ba2015-08-12 17:57:592611 SetZoomLevel(renderer_preferences_.default_zoom_level);
[email protected]d051d9a2011-12-10 02:02:502612 zoomLevelChanged();
2613 }
[email protected]ebd5ea52014-05-28 14:51:152614
2615 if (webview() &&
2616 old_accept_languages != renderer_preferences_.accept_languages) {
2617 webview()->acceptLanguagesChanged();
2618 }
[email protected]80d96fa2009-06-10 22:34:512619}
2620
[email protected]310ebd6302011-10-10 19:06:282621void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
2622 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:282623 if (webview())
2624 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:562625}
2626
[email protected]fcdc5642014-05-09 14:32:242627void RenderViewImpl::OnOrientationChange() {
japhete20ec7c2015-03-18 19:16:182628 if (webview() && webview()->mainFrame()->isWebLocalFrame())
2629 webview()->mainFrame()->toWebLocalFrame()->sendOrientationChangeEvent();
[email protected]77829642012-05-15 14:47:172630}
2631
[email protected]81375e872012-01-11 21:40:362632void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
2633 const WebPluginAction& action) {
2634 if (webview())
2635 webview()->performPluginAction(action, location);
2636}
2637
[email protected]88f10a22013-11-06 21:22:122638void RenderViewImpl::OnSuppressDialogsUntilSwapOut() {
2639 // Don't show any more dialogs until we finish OnSwapOut.
2640 suppress_dialogs_until_swap_out_ = true;
2641}
2642
[email protected]310ebd6302011-10-10 19:06:282643void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:372644 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:292645 // TODO(creis): We'd rather use webview()->Close() here, but that currently
2646 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
2647 // in the onunload handler from appearing. For now, we're bypassing that and
2648 // calling the FrameLoader's CloseURL method directly. This should be
2649 // revisited to avoid having two ways to close a page. Having a single way
2650 // to close that can run onunload is also useful for fixing
2651 // http://b/issue?id=753080.
[email protected]11fd5db2014-04-02 03:49:462652 webview()->mainFrame()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:292653
fsamuele8326c742016-01-12 00:49:392654 Send(new ViewHostMsg_ClosePage_ACK(routing_id()));
initial.commit09911bf2008-07-26 23:55:292655}
2656
naskoc288745f2015-05-01 22:54:212657void RenderViewImpl::OnClose() {
2658 if (closing_)
fsamuele8326c742016-01-12 00:49:392659 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(routing_id()));
naskoc288745f2015-05-01 22:54:212660 RenderWidget::OnClose();
2661}
2662
[email protected]310ebd6302011-10-10 19:06:282663void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:022664#if defined(USE_AURA)
2665 // Aura doesn't care if we switch themes.
2666#elif defined(OS_WIN)
[email protected]f78452f2012-05-15 02:07:522667 ui::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:462668 if (webview())
2669 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:572670#else // defined(OS_WIN)
2671 // TODO(port): we don't support theming on non-Windows platforms yet
2672 NOTIMPLEMENTED();
2673#endif
initial.commit09911bf2008-07-26 23:55:292674}
2675
[email protected]310ebd6302011-10-10 19:06:282676void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:002677 if (webview())
[email protected]a72a1fa2010-05-03 22:18:472678 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:002679}
2680
fsamuel664e8b62016-01-20 19:54:012681void RenderViewImpl::OnResize(const ResizeParams& params) {
[email protected]189a8862014-07-18 00:27:532682 TRACE_EVENT0("renderer", "RenderViewImpl::OnResize");
[email protected]cda45c02010-02-25 19:28:102683 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:472684 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:102685 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:202686 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]0fdd5012013-05-29 08:05:562687 ShouldDisplayScrollbars(params.new_size.width(),
2688 params.new_size.height()));
[email protected]cda45c02010-02-25 19:28:102689 }
mikhail.pozdnyakovc0e251b2015-04-15 06:51:122690 if (display_mode_ != params.display_mode) {
2691 display_mode_ = params.display_mode;
2692 webview()->setDisplayMode(display_mode_);
2693 }
[email protected]cda45c02010-02-25 19:28:102694 }
2695
[email protected]cbbdeef2014-05-26 15:57:362696 gfx::Size old_visible_viewport_size = visible_viewport_size_;
2697
[email protected]0fdd5012013-05-29 08:05:562698 RenderWidget::OnResize(params);
[email protected]cbbdeef2014-05-26 15:57:362699
2700 if (old_visible_viewport_size != visible_viewport_size_)
2701 has_scrolled_focused_editable_node_into_rect_ = false;
[email protected]30f75e62009-02-25 22:01:002702}
[email protected]0aa477bd2009-03-23 22:21:432703
[email protected]310ebd6302011-10-10 19:06:282704void RenderViewImpl::DidInitiatePaint() {
[email protected]ea2fb972013-08-07 05:44:262705#if defined(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:572706 // Notify all instances that we painted. The same caveats apply as for
2707 // ViewFlushedPaint regarding instances closing themselves, so we take
2708 // similar precautions.
2709 PepperPluginSet plugins = active_pepper_instances_;
2710 for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) {
2711 if (active_pepper_instances_.find(*i) != active_pepper_instances_.end())
2712 (*i)->ViewInitiatedPaint();
2713 }
[email protected]ea2fb972013-08-07 05:44:262714#endif
[email protected]00c39612010-03-06 02:53:282715}
2716
[email protected]310ebd6302011-10-10 19:06:282717void RenderViewImpl::DidFlushPaint() {
[email protected]5b1dec8c2012-02-07 04:35:382718 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
2719 // See crbug.com/112921.
2720 if (!webview())
2721 return;
2722
[email protected]00c39612010-03-06 02:53:282723 WebFrame* main_frame = webview()->mainFrame();
[email protected]82307f6b2014-08-07 03:30:122724 for (WebFrame* frame = main_frame; frame;
2725 frame = frame->traverseNext(false)) {
pmeenandcc725b2014-10-22 18:04:112726 // TODO(nasko): This is a hack for the case in which the top-level
2727 // frame is being rendered in another process. It will not
2728 // behave correctly for out of process iframes.
2729 if (frame->isWebLocalFrame()) {
[email protected]82307f6b2014-08-07 03:30:122730 main_frame = frame;
pmeenandcc725b2014-10-22 18:04:112731 break;
2732 }
[email protected]82307f6b2014-08-07 03:30:122733 }
[email protected]00c39612010-03-06 02:53:282734
alexmos6806d182015-07-28 00:04:192735 // There's nothing to do if there are no local frames in this RenderView's
2736 // frame tree. This can happen if DidFlushPaint is called after the
2737 // RenderView's local main frame is swapped to a remote frame. See
2738 // http://crbug.com/513552.
2739 if (main_frame->isWebRemoteFrame())
2740 return;
2741
[email protected]00c39612010-03-06 02:53:282742 // If we have a provisional frame we are between the start and commit stages
2743 // of loading and we don't want to save stats.
2744 if (!main_frame->provisionalDataSource()) {
2745 WebDataSource* ds = main_frame->dataSource();
enne95486602015-04-30 23:41:102746 if (!ds)
2747 return;
2748
[email protected]007733c2011-11-17 00:34:072749 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]92d457802013-04-01 19:18:492750
[email protected]05c8e502010-08-15 15:13:522751 // TODO(jar): The following code should all be inside a method, probably in
2752 // NavigatorState.
[email protected]00c39612010-03-06 02:53:282753 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:072754 if (document_state->first_paint_time().is_null()) {
2755 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:282756 }
[email protected]007733c2011-11-17 00:34:072757 if (document_state->first_paint_after_load_time().is_null() &&
2758 !document_state->finish_load_time().is_null()) {
2759 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:282760 }
2761 }
2762}
2763
[email protected]ceb36f7d2012-10-31 18:33:242764gfx::Vector2d RenderViewImpl::GetScrollOffset() {
[email protected]82307f6b2014-08-07 03:30:122765 WebFrame* main_frame = webview()->mainFrame();
2766 for (WebFrame* frame = main_frame; frame;
2767 frame = frame->traverseNext(false)) {
2768 // TODO(nasko): This is a hack for the case in which the top-level
2769 // frame is being rendered in another process. It will not
2770 // behave correctly for out of process iframes.
2771 if (frame->isWebLocalFrame()) {
2772 main_frame = frame;
2773 break;
2774 }
2775 }
2776
2777 WebSize scroll_offset = main_frame->scrollOffset();
[email protected]ceb36f7d2012-10-31 18:33:242778 return gfx::Vector2d(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:522779}
2780
[email protected]ab6c9112014-02-27 00:20:582781void RenderViewImpl::OnClearFocusedElement() {
[email protected]05d478752009-04-08 23:38:162782 if (webview())
[email protected]ab6c9112014-02-27 00:20:582783 webview()->clearFocusedElement();
[email protected]05d478752009-04-08 23:38:162784}
2785
[email protected]61f91832014-05-13 01:24:422786void RenderViewImpl::OnSetBackgroundOpaque(bool opaque) {
lfgcaab5142016-02-26 19:06:522787 if (frame_widget_)
2788 frame_widget_->setIsTransparent(!opaque);
[email protected]ba91a792013-02-06 09:48:282789 if (compositor_)
[email protected]61f91832014-05-13 01:24:422790 compositor_->setHasTransparentBackground(!opaque);
[email protected]699ab0d2009-04-23 23:19:142791}
2792
[email protected]310ebd6302011-10-10 19:06:282793void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:342794 if (webview())
[email protected]b4bb2502009-10-01 22:35:272795 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:262796
[email protected]a80af12e2013-08-07 23:36:132797#if defined(ENABLE_PLUGINS) && defined(OS_MACOSX)
[email protected]d8fd6fa2010-02-01 15:54:262798 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
2799 for (plugin_it = plugin_delegates_.begin();
2800 plugin_it != plugin_delegates_.end(); ++plugin_it) {
2801 (*plugin_it)->SetWindowFocus(active);
2802 }
2803#endif
[email protected]8c66c5a2009-07-22 17:26:342804}
2805
[email protected]6ce7abc52010-02-02 18:40:142806#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:282807void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]a80af12e2013-08-07 23:36:132808#if defined(ENABLE_PLUGINS)
[email protected]6ce7abc52010-02-02 18:40:142809 // Inform plugins that their container has changed visibility.
2810 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
2811 for (plugin_it = plugin_delegates_.begin();
2812 plugin_it != plugin_delegates_.end(); ++plugin_it) {
2813 (*plugin_it)->SetContainerVisibility(visible);
2814 }
[email protected]a80af12e2013-08-07 23:36:132815#endif
[email protected]6ce7abc52010-02-02 18:40:142816}
[email protected]1e6e3c992010-02-08 15:52:132817
[email protected]310ebd6302011-10-10 19:06:282818void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
2819 const gfx::Rect& view_frame) {
[email protected]a80af12e2013-08-07 23:36:132820#if defined(ENABLE_PLUGINS)
[email protected]1e6e3c992010-02-08 15:52:132821 // Inform plugins that their window's frame has changed.
2822 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
2823 for (plugin_it = plugin_delegates_.begin();
2824 plugin_it != plugin_delegates_.end(); ++plugin_it) {
2825 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
2826 }
[email protected]a80af12e2013-08-07 23:36:132827#endif
[email protected]1e6e3c992010-02-08 15:52:132828}
[email protected]935d63d2010-10-15 23:31:552829
[email protected]fcf75d42013-12-03 20:11:262830void RenderViewImpl::OnPluginImeCompositionCompleted(const base::string16& text,
[email protected]310ebd6302011-10-10 19:06:282831 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:132832 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:552833 // applies to it or not, so inform all the delegates.
2834 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
2835 for (plugin_it = plugin_delegates_.begin();
2836 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:132837 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:552838 }
2839}
[email protected]6ce7abc52010-02-02 18:40:142840#endif // OS_MACOSX
2841
dcheng3ce04b62015-10-26 23:30:552842void RenderViewImpl::CloseForFrame() {
2843 DCHECK(frame_widget_);
2844 frame_widget_->close();
2845 frame_widget_ = nullptr;
2846}
2847
[email protected]310ebd6302011-10-10 19:06:282848void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:592849 // We need to grab a pointer to the doomed WebView before we destroy it.
2850 WebView* doomed = webview();
2851 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:492852 g_view_map.Get().erase(doomed);
fsamuele8326c742016-01-12 00:49:392853 g_routing_id_view_map.Get().erase(routing_id());
2854 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(routing_id()));
[email protected]60c42a8c72009-10-09 04:08:592855}
2856
[email protected]310ebd6302011-10-10 19:06:282857void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:432858 RenderWidget::OnWasHidden();
2859
[email protected]68877c282013-09-20 05:52:422860#if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
[email protected]6392d982013-04-16 16:59:222861 RenderThreadImpl::current()->video_capture_impl_manager()->
2862 SuspendDevices(true);
[email protected]e976c3c52014-07-24 17:41:552863 if (speech_recognition_dispatcher_)
2864 speech_recognition_dispatcher_->AbortAllRecognitions();
[email protected]6392d982013-04-16 16:59:222865#endif
[email protected]2d7b82c2012-06-01 05:57:502866
[email protected]8869d392013-05-07 15:34:262867 if (webview())
[email protected]f59203a2011-06-07 10:01:442868 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:072869
[email protected]ea2fb972013-08-07 05:44:262870#if defined(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:572871 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
2872 i != active_pepper_instances_.end(); ++i)
2873 (*i)->PageVisibilityChanged(false);
[email protected]204f1df2012-01-04 20:21:132874
[email protected]a6939ca42011-02-18 17:58:072875#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:132876 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:432877 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
2878 for (plugin_it = plugin_delegates_.begin();
2879 plugin_it != plugin_delegates_.end(); ++plugin_it) {
2880 (*plugin_it)->SetContainerVisibility(false);
2881 }
[email protected]a6939ca42011-02-18 17:58:072882#endif // OS_MACOSX
thestig6057a6b22015-11-12 23:01:332883#endif // ENABLE_PLUGINS
[email protected]941e4552010-02-01 21:23:432884}
2885
[email protected]3399dd822014-08-09 11:14:242886void RenderViewImpl::OnWasShown(bool needs_repainting,
2887 const ui::LatencyInfo& latency_info) {
2888 RenderWidget::OnWasShown(needs_repainting, latency_info);
[email protected]941e4552010-02-01 21:23:432889
[email protected]6392d982013-04-16 16:59:222890#if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
2891 RenderThreadImpl::current()->video_capture_impl_manager()->
2892 SuspendDevices(false);
2893#endif
2894
[email protected]8869d392013-05-07 15:34:262895 if (webview())
[email protected]f59203a2011-06-07 10:01:442896 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:072897
[email protected]ea2fb972013-08-07 05:44:262898#if defined(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:572899 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
2900 i != active_pepper_instances_.end(); ++i)
2901 (*i)->PageVisibilityChanged(true);
[email protected]204f1df2012-01-04 20:21:132902
[email protected]a6939ca42011-02-18 17:58:072903#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:132904 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:432905 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
2906 for (plugin_it = plugin_delegates_.begin();
2907 plugin_it != plugin_delegates_.end(); ++plugin_it) {
2908 (*plugin_it)->SetContainerVisibility(true);
2909 }
[email protected]784ea1ab2010-09-18 00:02:342910#endif // OS_MACOSX
[email protected]a80af12e2013-08-07 23:36:132911#endif // ENABLE_PLUGINS
[email protected]a6939ca42011-02-18 17:58:072912}
[email protected]1e6e3c992010-02-08 15:52:132913
[email protected]ed7defa2013-03-12 21:29:592914GURL RenderViewImpl::GetURLForGraphicsContext3D() {
2915 DCHECK(webview());
[email protected]82307f6b2014-08-07 03:30:122916 if (webview()->mainFrame()->isWebLocalFrame())
[email protected]ed7defa2013-03-12 21:29:592917 return GURL(webview()->mainFrame()->document().url());
2918 else
2919 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]65225772011-05-12 21:10:242920}
2921
[email protected]310ebd6302011-10-10 19:06:282922void RenderViewImpl::OnSetFocus(bool enable) {
naskoc6edf7e2015-10-16 01:48:452923 // This message must always be received when the main frame is a
2924 // WebLocalFrame.
2925 CHECK(webview()->mainFrame()->isWebLocalFrame());
alexmos3fcd0ca2015-10-23 18:18:332926 SetFocus(enable);
2927}
alexmos7fac9aeb2015-10-16 22:39:492928
alexmos3fcd0ca2015-10-23 18:18:332929void RenderViewImpl::SetFocus(bool enable) {
alexmos7fac9aeb2015-10-16 22:39:492930 has_focus_ = enable;
[email protected]1e6e3c992010-02-08 15:52:132931 RenderWidget::OnSetFocus(enable);
2932
[email protected]a80af12e2013-08-07 23:36:132933#if defined(ENABLE_PLUGINS)
[email protected]7d3c02c2010-05-05 23:10:312934 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:072935 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:132936 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
2937 for (plugin_it = plugin_delegates_.begin();
2938 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:342939#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:312940 // RenderWidget's call to setFocus can cause the underlying webview's
2941 // activation state to change just like a call to setIsActive.
2942 if (enable)
2943 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:342944#endif
[email protected]7d3c02c2010-05-05 23:10:312945 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:132946 }
2947 }
[email protected]a99a38802014-01-14 15:46:572948 // Notify all Pepper plugins.
2949 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
2950 i != active_pepper_instances_.end(); ++i)
2951 (*i)->SetContentAreaFocus(enable);
[email protected]ea2fb972013-08-07 05:44:262952#endif
[email protected]321032992012-11-08 01:01:272953 // Notify all BrowserPlugins of the RenderView's focus state.
fsamuel6c1dfeb2014-12-18 19:21:332954 if (BrowserPluginManager::Get())
2955 BrowserPluginManager::Get()->UpdateFocusState();
[email protected]1e6e3c992010-02-08 15:52:132956}
[email protected]941e4552010-02-01 21:23:432957
[email protected]310ebd6302011-10-10 19:06:282958void RenderViewImpl::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:262959 const base::string16& text,
[email protected]180ef242013-11-07 06:50:462960 const std::vector<blink::WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:072961 const gfx::Range& replacement_range,
[email protected]56ea1a62011-05-30 07:05:572962 int selection_start,
2963 int selection_end) {
[email protected]ea2fb972013-08-07 05:44:262964#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:082965 if (focused_pepper_plugin_) {
2966 focused_pepper_plugin_->render_frame()->OnImeSetComposition(
[email protected]7a4e2532013-12-02 21:30:022967 text, underlines, selection_start, selection_end);
[email protected]ea2fb972013-08-07 05:44:262968 return;
[email protected]56ea1a62011-05-30 07:05:572969 }
[email protected]ea2fb972013-08-07 05:44:262970
2971#if defined(OS_WIN)
tommyclie86b2982015-03-16 20:16:452972 // When a plugin has focus, we create platform-specific IME data used by
2973 // our IME emulator and send it directly to the focused plugin, i.e. we
[email protected]ea2fb972013-08-07 05:44:262974 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
2975 // instance ID is the same one as the specified ID.)
2976 if (focused_plugin_id_ >= 0) {
2977 std::vector<int> clauses;
2978 std::vector<int> target;
2979 for (size_t i = 0; i < underlines.size(); ++i) {
2980 clauses.push_back(underlines[i].startOffset);
2981 clauses.push_back(underlines[i].endOffset);
2982 if (underlines[i].thick) {
2983 target.clear();
2984 target.push_back(underlines[i].startOffset);
2985 target.push_back(underlines[i].endOffset);
2986 }
2987 }
2988 std::set<WebPluginDelegateProxy*>::iterator it;
2989 for (it = plugin_delegates_.begin(); it != plugin_delegates_.end(); ++it) {
2990 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
2991 focused_plugin_id_);
2992 }
2993 return;
2994 }
[email protected]a80af12e2013-08-07 23:36:132995#endif // OS_WIN
2996#endif // ENABLE_PLUGINS
chongz7eb752802016-01-27 21:28:072997 if (replacement_range.IsValid() && webview()) {
2998 // Select the text in |replacement_range|, it will then be replaced by
2999 // text added by the call to RenderWidget::OnImeSetComposition().
3000 if (WebLocalFrame* frame = webview()->focusedFrame()->toWebLocalFrame()) {
3001 WebRange webrange = WebRange::fromDocumentRange(
3002 frame, replacement_range.start(), replacement_range.length());
3003 if (!webrange.isNull())
3004 frame->selectRange(webrange);
3005 }
3006 }
[email protected]ea2fb972013-08-07 05:44:263007 RenderWidget::OnImeSetComposition(text,
3008 underlines,
chongz7eb752802016-01-27 21:28:073009 replacement_range,
[email protected]ea2fb972013-08-07 05:44:263010 selection_start,
3011 selection_end);
[email protected]56ea1a62011-05-30 07:05:573012}
3013
[email protected]db4fc1e2013-09-06 20:01:513014void RenderViewImpl::OnImeConfirmComposition(
[email protected]fcf75d42013-12-03 20:11:263015 const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:513016 const gfx::Range& replacement_range,
3017 bool keep_selection) {
[email protected]ea2fb972013-08-07 05:44:263018#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083019 if (focused_pepper_plugin_) {
3020 focused_pepper_plugin_->render_frame()->OnImeConfirmComposition(
[email protected]7a4e2532013-12-02 21:30:023021 text, replacement_range, keep_selection);
[email protected]ea2fb972013-08-07 05:44:263022 return;
[email protected]56ea1a62011-05-30 07:05:573023 }
[email protected]ea2fb972013-08-07 05:44:263024#if defined(OS_WIN)
3025 // Same as OnImeSetComposition(), we send the text from IMEs directly to
tommyclie86b2982015-03-16 20:16:453026 // plugins. When we send IME text directly to plugins, we should not send
[email protected]ea2fb972013-08-07 05:44:263027 // it to WebKit to prevent WebKit from controlling IMEs.
3028 // TODO(thakis): Honor |replacement_range| for plugins?
3029 if (focused_plugin_id_ >= 0) {
3030 std::set<WebPluginDelegateProxy*>::iterator it;
3031 for (it = plugin_delegates_.begin();
3032 it != plugin_delegates_.end(); ++it) {
3033 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
3034 }
3035 return;
3036 }
[email protected]a80af12e2013-08-07 23:36:133037#endif // OS_WIN
3038#endif // ENABLE_PLUGINS
[email protected]ea2fb972013-08-07 05:44:263039 if (replacement_range.IsValid() && webview()) {
3040 // Select the text in |replacement_range|, it will then be replaced by
3041 // text added by the call to RenderWidget::OnImeConfirmComposition().
[email protected]35b2a972014-04-04 15:50:223042 if (WebLocalFrame* frame = webview()->focusedFrame()->toWebLocalFrame()) {
[email protected]ea2fb972013-08-07 05:44:263043 WebRange webrange = WebRange::fromDocumentRange(
3044 frame, replacement_range.start(), replacement_range.length());
3045 if (!webrange.isNull())
3046 frame->selectRange(webrange);
3047 }
3048 }
3049 RenderWidget::OnImeConfirmComposition(text,
3050 replacement_range,
3051 keep_selection);
[email protected]56ea1a62011-05-30 07:05:573052}
3053
avi40b5be7a2016-03-03 21:13:443054void RenderViewImpl::RenderWidgetDidSetColorProfile(
[email protected]28ed6b32014-06-08 02:16:273055 const std::vector<char>& profile) {
avi40b5be7a2016-03-03 21:13:443056 if (webview()) {
3057 bool was_reset = (profile.size() == 1 && profile[0] == '0');
[email protected]28ed6b32014-06-08 02:16:273058
avi40b5be7a2016-03-03 21:13:443059 if (was_reset) {
3060 webview()->resetDeviceColorProfileForTesting();
3061 } else {
3062 WebVector<char> colorProfile = profile;
3063 webview()->setDeviceColorProfile(colorProfile);
3064 }
3065 }
noeldb4df152014-09-16 17:45:203066}
3067
[email protected]310ebd6302011-10-10 19:06:283068ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]ea2fb972013-08-07 05:44:263069#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083070 if (focused_pepper_plugin_)
3071 return focused_pepper_plugin_->text_input_type();
[email protected]ea2fb972013-08-07 05:44:263072#endif
3073 return RenderWidget::GetTextInputType();
[email protected]73bf95812011-10-12 11:38:323074}
3075
[email protected]3f783362011-10-21 22:40:503076void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
[email protected]ea2fb972013-08-07 05:44:263077#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083078 if (focused_pepper_plugin_) {
[email protected]3f783362011-10-21 22:40:503079 // TODO(kinaba) http://crbug.com/101101
3080 // Current Pepper IME API does not handle selection bounds. So we simply
3081 // use the caret position as an empty range for now. It will be updated
3082 // after Pepper API equips features related to surrounding text retrieval.
oshima33ec97cd2015-12-14 19:40:243083 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds());
3084 convertViewportToWindow(&caret);
[email protected]3f783362011-10-21 22:40:503085 *start = caret;
3086 *end = caret;
3087 return;
3088 }
[email protected]ea2fb972013-08-07 05:44:263089#endif
[email protected]3f783362011-10-21 22:40:503090 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:453091}
3092
[email protected]58b48a0d2012-06-13 07:01:353093void RenderViewImpl::GetCompositionCharacterBounds(
oshima33ec97cd2015-12-14 19:40:243094 std::vector<gfx::Rect>* bounds_in_window) {
3095 DCHECK(bounds_in_window);
3096 bounds_in_window->clear();
[email protected]58b48a0d2012-06-13 07:01:353097
[email protected]ea2fb972013-08-07 05:44:263098#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083099 if (focused_pepper_plugin_) {
[email protected]88dbe32f2013-06-20 23:31:363100 return;
3101 }
[email protected]ea2fb972013-08-07 05:44:263102#endif
3103
[email protected]58b48a0d2012-06-13 07:01:353104 if (!webview())
3105 return;
3106 size_t start_offset = 0;
3107 size_t character_count = 0;
3108 if (!webview()->compositionRange(&start_offset, &character_count))
3109 return;
3110 if (character_count == 0)
3111 return;
3112
[email protected]180ef242013-11-07 06:50:463113 blink::WebFrame* frame = webview()->focusedFrame();
[email protected]58b48a0d2012-06-13 07:01:353114 if (!frame)
3115 return;
3116
oshima33ec97cd2015-12-14 19:40:243117 bounds_in_window->reserve(character_count);
[email protected]180ef242013-11-07 06:50:463118 blink::WebRect webrect;
[email protected]58b48a0d2012-06-13 07:01:353119 for (size_t i = 0; i < character_count; ++i) {
3120 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
3121 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
oshima33ec97cd2015-12-14 19:40:243122 bounds_in_window->clear();
[email protected]58b48a0d2012-06-13 07:01:353123 return;
3124 }
oshima33ec97cd2015-12-14 19:40:243125 convertViewportToWindow(&webrect);
3126 bounds_in_window->push_back(webrect);
[email protected]58b48a0d2012-06-13 07:01:353127 }
3128}
3129
[email protected]db4fc1e2013-09-06 20:01:513130void RenderViewImpl::GetCompositionRange(gfx::Range* range) {
[email protected]ea2fb972013-08-07 05:44:263131#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083132 if (focused_pepper_plugin_) {
[email protected]88dbe32f2013-06-20 23:31:363133 return;
3134 }
[email protected]ea2fb972013-08-07 05:44:263135#endif
[email protected]88dbe32f2013-06-20 23:31:363136 RenderWidget::GetCompositionRange(range);
3137}
3138
[email protected]310ebd6302011-10-10 19:06:283139bool RenderViewImpl::CanComposeInline() {
[email protected]ea2fb972013-08-07 05:44:263140#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083141 if (focused_pepper_plugin_)
3142 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
[email protected]ea2fb972013-08-07 05:44:263143#endif
3144 return true;
[email protected]56ea1a62011-05-30 07:05:573145}
3146
rouslanf7ebd8832015-01-22 01:54:143147void RenderViewImpl::DidCompletePageScaleAnimation() {
avid7d6b2e2016-03-04 19:41:173148 GetWidget()->FocusChangeComplete();
rouslanf7ebd8832015-01-22 01:54:143149}
3150
oshimad5279032015-12-16 18:22:333151void RenderViewImpl::OnDeviceScaleFactorChanged() {
3152 RenderWidget::OnDeviceScaleFactorChanged();
3153 UpdateWebViewWithDeviceScaleFactor();
3154 if (auto_resize_mode_)
3155 AutoResizeCompositor();
3156}
3157
[email protected]b2e4c70132013-10-03 02:07:513158void RenderViewImpl::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:203159 bool enabled,
3160 const blink::WebDeviceEmulationParams& params) {
[email protected]404630b2014-07-03 19:33:033161 if (webview() && compositor()) {
dgozman9260b0a12015-03-16 13:45:203162 if (enabled)
3163 webview()->enableDeviceEmulation(params);
3164 else
3165 webview()->disableDeviceEmulation();
[email protected]b2e4c70132013-10-03 02:07:513166 }
3167}
3168
[email protected]310ebd6302011-10-10 19:06:283169bool RenderViewImpl::ScheduleFileChooser(
[email protected]e9ff79c2012-10-19 21:31:263170 const FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:473171 WebFileChooserCompletion* completion) {
3172 static const size_t kMaximumPendingFileChooseRequests = 4;
3173 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
3174 // This sanity check prevents too many file choose requests from getting
3175 // queued which could DoS the user. Getting these is most likely a
3176 // programming error (there are many ways to DoS the user so it's not
3177 // considered a "real" security check), either in JS requesting many file
3178 // choosers to pop up, or in a plugin.
3179 //
3180 // TODO(brettw) we might possibly want to require a user gesture to open
3181 // a file picker, which will address this issue in a better way.
3182 return false;
3183 }
3184
limasdf81d962e2015-11-20 08:39:183185 file_chooser_completions_.push_back(
3186 make_scoped_ptr(new PendingFileChooser(params, completion)));
[email protected]cdaf8d02010-03-30 19:52:473187 if (file_chooser_completions_.size() == 1) {
3188 // Actually show the browse dialog when this is the first request.
fsamuele8326c742016-01-12 00:49:393189 Send(new ViewHostMsg_RunFileChooser(routing_id(), params));
[email protected]cdaf8d02010-03-30 19:52:473190 }
3191 return true;
3192}
3193
[email protected]180ef242013-11-07 06:50:463194blink::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
[email protected]64d09222012-05-25 10:10:343195 if (!speech_recognition_dispatcher_)
3196 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
[email protected]64d09222012-05-25 10:10:343197 return speech_recognition_dispatcher_;
3198}
3199
[email protected]310ebd6302011-10-10 19:06:283200void RenderViewImpl::zoomLimitsChanged(double minimum_level,
3201 double maximum_level) {
a.sarkar.arundaadc712015-02-26 05:39:083202 // Round the double to avoid returning incorrect minimum/maximum zoom
3203 // percentages.
3204 int minimum_percent = round(
[email protected]7940b8e2013-07-25 23:08:493205 ZoomLevelToZoomFactor(minimum_level) * 100);
a.sarkar.arundaadc712015-02-26 05:39:083206 int maximum_percent = round(
[email protected]7940b8e2013-07-25 23:08:493207 ZoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:253208
fsamuele8326c742016-01-12 00:49:393209 Send(new ViewHostMsg_UpdateZoomLimits(routing_id(), minimum_percent,
3210 maximum_percent));
[email protected]b75b8292010-10-01 07:28:253211}
3212
[email protected]310ebd6302011-10-10 19:06:283213void RenderViewImpl::zoomLevelChanged() {
[email protected]54b8e182014-05-02 18:08:293214 double zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:263215
[email protected]54b8e182014-05-02 18:08:293216 // Do not send empty URLs to the browser when we are just setting the default
3217 // zoom level (from RendererPreferences) before the first navigation.
3218 if (!webview()->mainFrame()->document().url().isEmpty()) {
3219 // Tell the browser which url got zoomed so it can update the menu and the
3220 // saved values if necessary
3221 Send(new ViewHostMsg_DidZoomURL(
fsamuele8326c742016-01-12 00:49:393222 routing_id(), zoom_level,
[email protected]54b8e182014-05-02 18:08:293223 GURL(webview()->mainFrame()->document().url())));
3224 }
[email protected]b75b8292010-10-01 07:28:253225}
3226
ccameronb7c1d6c2015-03-09 17:08:243227void RenderViewImpl::pageScaleFactorChanged() {
3228 if (!webview())
3229 return;
mcnee432e47d2015-11-09 19:37:463230
fsamuele8326c742016-01-12 00:49:393231 Send(new ViewHostMsg_PageScaleFactorChanged(routing_id(),
mcnee432e47d2015-11-09 19:37:463232 webview()->pageScaleFactor()));
ccameronb7c1d6c2015-03-09 17:08:243233}
3234
[email protected]7940b8e2013-07-25 23:08:493235double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const {
3236 return ZoomLevelToZoomFactor(zoom_level);
3237}
3238
3239double RenderViewImpl::zoomFactorToZoomLevel(double factor) const {
3240 return ZoomFactorToZoomLevel(factor);
3241}
3242
[email protected]180ef242013-11-07 06:50:463243blink::WebPageVisibilityState RenderViewImpl::visibilityState() const {
3244 blink::WebPageVisibilityState current_state = is_hidden() ?
3245 blink::WebPageVisibilityStateHidden :
3246 blink::WebPageVisibilityStateVisible;
3247 blink::WebPageVisibilityState override_state = current_state;
[email protected]b849847b2013-12-10 21:57:583248 // TODO(jam): move this method to WebFrameClient.
[email protected]e9ff79c2012-10-19 21:31:263249 if (GetContentClient()->renderer()->
nasko77de2312015-05-12 03:09:163250 ShouldOverridePageVisibilityState(main_render_frame_,
[email protected]f59203a2011-06-07 10:01:443251 &override_state))
3252 return override_state;
3253 return current_state;
[email protected]94dec932011-05-26 20:04:213254}
3255
[email protected]a0629af92012-08-08 00:39:373256void RenderViewImpl::draggableRegionsChanged() {
3257 FOR_EACH_OBSERVER(
3258 RenderViewObserver,
3259 observers_,
3260 DraggableRegionsChanged(webview()->mainFrame()));
3261}
3262
kouhei40f03cb2015-09-24 07:47:013263void RenderViewImpl::pageImportanceSignalsChanged() {
3264 if (!webview() || !main_render_frame_)
3265 return;
3266
3267 const auto& web_signals = webview()->pageImportanceSignals();
3268
3269 PageImportanceSignals signals;
3270 signals.had_form_interaction = web_signals->hadFormInteraction();
3271
3272 main_render_frame_->Send(new FrameHostMsg_UpdatePageImportanceSignals(
3273 main_render_frame_->GetRoutingID(), signals));
3274}
3275
[email protected]20657a82012-08-21 20:23:033276#if defined(OS_ANDROID)
3277WebContentDetectionResult RenderViewImpl::detectContentAround(
3278 const WebHitTestResult& touch_hit) {
[email protected]20657a82012-08-21 20:23:033279 DCHECK(touch_hit.node().isTextNode());
3280
3281 // Process the position with all the registered content detectors until
3282 // a match is found. Priority is provided by their relative order.
limasdf81d962e2015-11-20 08:39:183283 for (const auto& detector : content_detectors_) {
3284 ContentDetector::Result content = detector->FindTappedContent(touch_hit);
[email protected]20657a82012-08-21 20:23:033285 if (content.valid) {
3286 return WebContentDetectionResult(content.content_boundaries,
[email protected]32956122013-12-25 07:29:243287 base::UTF8ToUTF16(content.text), content.intent_url);
[email protected]20657a82012-08-21 20:23:033288 }
3289 }
3290 return WebContentDetectionResult();
3291}
3292
mnaganov42d9e372015-11-02 23:27:413293void RenderViewImpl::scheduleContentIntent(const WebURL& intent,
3294 bool is_main_frame) {
[email protected]20657a82012-08-21 20:23:033295 // Introduce a short delay so that the user can notice the content.
[email protected]dd32b1272013-05-04 14:17:113296 base::MessageLoop::current()->PostDelayedTask(
[email protected]20657a82012-08-21 20:23:033297 FROM_HERE,
mnaganov42d9e372015-11-02 23:27:413298 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, AsWeakPtr(),
3299 intent, expected_content_intent_id_, is_main_frame),
[email protected]20657a82012-08-21 20:23:033300 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds));
3301}
3302
3303void RenderViewImpl::cancelScheduledContentIntents() {
3304 ++expected_content_intent_id_;
3305}
3306
3307void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent,
mnaganov42d9e372015-11-02 23:27:413308 size_t request_id,
3309 bool is_main_frame) {
[email protected]20657a82012-08-21 20:23:033310 if (request_id != expected_content_intent_id_)
qinmin0d5560df2014-11-12 19:03:393311 return;
[email protected]20657a82012-08-21 20:23:033312
3313 // Remove the content highlighting if any.
jdduke491a3f0c2015-06-15 23:30:263314 ScheduleComposite();
[email protected]20657a82012-08-21 20:23:033315
mnaganov42d9e372015-11-02 23:27:413316 if (!intent.is_empty()) {
fsamuele8326c742016-01-12 00:49:393317 Send(new ViewHostMsg_StartContentIntent(routing_id(), intent,
3318 is_main_frame));
mnaganov42d9e372015-11-02 23:27:413319 }
[email protected]20657a82012-08-21 20:23:033320}
[email protected]b18583c2012-12-18 06:55:273321
3322bool RenderViewImpl::openDateTimeChooser(
[email protected]180ef242013-11-07 06:50:463323 const blink::WebDateTimeChooserParams& params,
3324 blink::WebDateTimeChooserCompletion* completion) {
[email protected]e8072562013-12-04 06:04:133325 // JavaScript may try to open a date time chooser while one is already open.
3326 if (date_time_picker_client_)
3327 return false;
[email protected]b18583c2012-12-18 06:55:273328 date_time_picker_client_.reset(
3329 new RendererDateTimePicker(this, params, completion));
3330 return date_time_picker_client_->Open();
3331}
3332
[email protected]e8072562013-12-04 06:04:133333void RenderViewImpl::DismissDateTimeDialog() {
3334 DCHECK(date_time_picker_client_);
3335 date_time_picker_client_.reset(NULL);
3336}
[email protected]e8072562013-12-04 06:04:133337
[email protected]6d17f6392012-12-05 05:24:543338#endif // defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:033339
[email protected]be1af0662014-07-29 19:55:513340void RenderViewImpl::OnShowContextMenu(
3341 ui::MenuSourceType source_type, const gfx::Point& location) {
fsamuele8326c742016-01-12 00:49:393342 input_handler_->set_context_menu_source_type(source_type);
[email protected]be1af0662014-07-29 19:55:513343 has_host_context_menu_location_ = true;
3344 host_context_menu_location_ = location;
[email protected]47822262013-04-23 17:22:363345 if (webview())
3346 webview()->showContextMenu();
[email protected]be1af0662014-07-29 19:55:513347 has_host_context_menu_location_ = false;
[email protected]47822262013-04-23 17:22:363348}
3349
[email protected]310ebd6302011-10-10 19:06:283350void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:183351 if (!webview())
3352 return;
3353 WebFrame* main_frame = webview()->mainFrame();
3354 if (!main_frame)
3355 return;
3356 main_frame->enableViewSourceMode(true);
3357}
[email protected]67bfb83f2011-09-22 03:36:373358
sadrul90f88a9b2015-06-16 16:22:043359#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]f9526d12012-10-18 01:55:033360bool RenderViewImpl::didTapMultipleTargets(
timav29a8d0f62014-09-25 20:45:533361 const WebSize& inner_viewport_offset,
3362 const WebRect& touch_rect,
[email protected]f9526d12012-10-18 01:55:033363 const WebVector<WebRect>& target_rects) {
mustaq35bb250b2015-05-06 21:22:393364 DCHECK(switches::IsLinkDisambiguationPopupEnabled());
lukene23094a2014-11-23 14:12:313365
[email protected]8d3dfee62013-06-19 05:50:333366 // Never show a disambiguation popup when accessibility is enabled,
3367 // as this interferes with "touch exploration".
[email protected]95640212014-07-26 18:14:303368 AccessibilityMode accessibility_mode =
mostynbc33353232014-09-12 09:38:313369 GetMainRenderFrame()->accessibility_mode();
[email protected]95640212014-07-26 18:14:303370 bool matches_accessibility_mode_complete =
3371 (accessibility_mode & AccessibilityModeComplete) ==
3372 AccessibilityModeComplete;
3373 if (matches_accessibility_mode_complete)
[email protected]8d3dfee62013-06-19 05:50:333374 return false;
3375
timav29a8d0f62014-09-25 20:45:533376 // The touch_rect, target_rects and zoom_rect are in the outer viewport
3377 // reference frame.
[email protected]f9526d12012-10-18 01:55:033378 gfx::Rect zoom_rect;
[email protected]70221f02013-01-31 22:17:073379 float new_total_scale =
3380 DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
timav29a8d0f62014-09-25 20:45:533381 touch_rect, target_rects, GetSize(),
[email protected]70221f02013-01-31 22:17:073382 gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(),
3383 device_scale_factor_ * webview()->pageScaleFactor(), &zoom_rect);
jbauman0ed09182015-01-30 22:33:493384 if (!new_total_scale || zoom_rect.IsEmpty())
[email protected]f9526d12012-10-18 01:55:033385 return false;
3386
[email protected]4ded1dbf2013-08-28 21:11:033387 bool handled = false;
3388 switch (renderer_preferences_.tap_multiple_targets_strategy) {
3389 case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM:
3390 handled = webview()->zoomToMultipleTargetsRect(zoom_rect);
3391 break;
3392 case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: {
[email protected]bc2804d2013-08-06 07:45:493393 gfx::Size canvas_size =
danakjddaec912015-09-25 19:38:403394 gfx::ScaleToCeiledSize(zoom_rect.size(), new_total_scale);
[email protected]cb189e062014-04-23 00:57:013395 cc::SharedBitmapManager* manager =
3396 RenderThreadImpl::current()->shared_bitmap_manager();
3397 scoped_ptr<cc::SharedBitmap> shared_bitmap =
3398 manager->AllocateSharedBitmap(canvas_size);
jbauman0ed09182015-01-30 22:33:493399 CHECK(!!shared_bitmap);
[email protected]bc2804d2013-08-06 07:45:493400 {
[email protected]cb189e062014-04-23 00:57:013401 SkBitmap bitmap;
3402 SkImageInfo info = SkImageInfo::MakeN32Premul(canvas_size.width(),
3403 canvas_size.height());
3404 bitmap.installPixels(info, shared_bitmap->pixels(), info.minRowBytes());
3405 SkCanvas canvas(bitmap);
[email protected]f9526d12012-10-18 01:55:033406
[email protected]bc2804d2013-08-06 07:45:493407 // TODO(trchen): Cleanup the device scale factor mess.
3408 // device scale will be applied in WebKit
3409 // --> zoom_rect doesn't include device scale,
3410 // but WebKit will still draw on zoom_rect * device_scale_factor_
[email protected]cb189e062014-04-23 00:57:013411 canvas.scale(new_total_scale / device_scale_factor_,
3412 new_total_scale / device_scale_factor_);
3413 canvas.translate(-zoom_rect.x() * device_scale_factor_,
3414 -zoom_rect.y() * device_scale_factor_);
[email protected]f9526d12012-10-18 01:55:033415
[email protected]bcb1f022014-05-06 01:54:173416 DCHECK(webwidget_->isAcceleratedCompositingActive());
3417 // TODO(aelias): The disambiguation popup should be composited so we
3418 // don't have to call this method.
3419 webwidget_->paintCompositedDeprecated(&canvas, zoom_rect);
[email protected]bc2804d2013-08-06 07:45:493420 }
3421
timav29a8d0f62014-09-25 20:45:533422 gfx::Rect zoom_rect_in_screen =
3423 zoom_rect - gfx::Vector2d(inner_viewport_offset.width,
3424 inner_viewport_offset.height);
3425
[email protected]bc2804d2013-08-06 07:45:493426 gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect(
timav29a8d0f62014-09-25 20:45:533427 ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect_in_screen)));
3428
fsamuele8326c742016-01-12 00:49:393429 Send(new ViewHostMsg_ShowDisambiguationPopup(
3430 routing_id(), physical_window_zoom_rect, canvas_size,
3431 shared_bitmap->id()));
[email protected]cb189e062014-04-23 00:57:013432 cc::SharedBitmapId id = shared_bitmap->id();
3433 disambiguation_bitmaps_[id] = shared_bitmap.release();
[email protected]4ded1dbf2013-08-28 21:11:033434 handled = true;
3435 break;
3436 }
3437 case TAP_MULTIPLE_TARGETS_STRATEGY_NONE:
3438 // No-op.
3439 break;
[email protected]f9526d12012-10-18 01:55:033440 }
[email protected]70221f02013-01-31 22:17:073441
[email protected]4ded1dbf2013-08-28 21:11:033442 return handled;
[email protected]f9526d12012-10-18 01:55:033443}
sadrul90f88a9b2015-06-16 16:22:043444#endif // defined(OS_ANDROID) || defined(USE_AURA)
[email protected]f9526d12012-10-18 01:55:033445
[email protected]b283d292013-02-21 08:40:343446unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
3447 return history_list_length_;
3448}
3449
[email protected]cc290f902013-03-04 20:06:023450void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
3451 if (enable) {
3452 if (has_focus())
3453 return;
3454 OnSetActive(true);
3455 OnSetFocus(true);
3456 } else {
3457 if (!has_focus())
3458 return;
3459 OnSetFocus(false);
3460 OnSetActive(false);
3461 }
3462}
3463
[email protected]3a1c8a8032013-03-18 22:35:323464void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) {
fsamuel664e8b62016-01-20 19:54:013465 ResizeParams params;
[email protected]b54fe452013-06-07 14:01:533466 params.screen_info = screen_info_;
3467 params.screen_info.deviceScaleFactor = factor;
3468 params.new_size = size();
bokanf0fd2412014-10-30 15:28:553469 params.visible_viewport_size = visible_viewport_size_;
danakjddaec912015-09-25 19:38:403470 params.physical_backing_size = gfx::ScaleToCeiledSize(size(), factor);
dtrainorcb7779b82014-12-04 01:08:023471 params.top_controls_shrink_blink_size = false;
3472 params.top_controls_height = 0.f;
[email protected]b54fe452013-06-07 14:01:533473 params.resizer_rect = WebRect();
mikhail.pozdnyakovf2c902a2015-04-14 08:09:123474 params.is_fullscreen_granted = is_fullscreen_granted();
mikhail.pozdnyakovc0e251b2015-04-15 06:51:123475 params.display_mode = display_mode_;
[email protected]b54fe452013-06-07 14:01:533476 OnResize(params);
[email protected]3a1c8a8032013-03-18 22:35:323477}
3478
[email protected]92650162013-10-30 03:31:023479void RenderViewImpl::ForceResizeForTesting(const gfx::Size& new_size) {
bokanc007c3a2015-02-03 07:15:563480 gfx::Rect new_window_rect(rootWindowRect().x,
3481 rootWindowRect().y,
3482 new_size.width(),
3483 new_size.height());
3484 SetWindowRectSynchronously(new_window_rect);
[email protected]92650162013-10-30 03:31:023485}
3486
[email protected]5b45ad42013-10-25 00:42:043487void RenderViewImpl::UseSynchronousResizeModeForTesting(bool enable) {
3488 resizing_mode_selector_->set_is_synchronous_mode(enable);
3489}
3490
[email protected]eac2b362013-05-22 07:01:453491void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size,
3492 const gfx::Size& max_size) {
3493 OnEnableAutoResize(min_size, max_size);
3494}
3495
3496void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) {
3497 OnDisableAutoResize(new_size);
3498}
3499
[email protected]cb189e062014-04-23 00:57:013500void RenderViewImpl::OnReleaseDisambiguationPopupBitmap(
3501 const cc::SharedBitmapId& id) {
3502 BitmapMap::iterator it = disambiguation_bitmaps_.find(id);
3503 DCHECK(it != disambiguation_bitmaps_.end());
3504 delete it->second;
3505 disambiguation_bitmaps_.erase(it);
[email protected]f9526d12012-10-18 01:55:033506}
[email protected]e9ff79c2012-10-19 21:31:263507
[email protected]6fceb912013-02-15 06:24:153508void RenderViewImpl::DidCommitCompositorFrame() {
3509 RenderWidget::DidCommitCompositorFrame();
3510 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame());
3511}
3512
[email protected]41225fe2013-03-29 05:32:023513void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) {
3514 if (!urls.empty())
fsamuele8326c742016-01-12 00:49:393515 Send(new ViewHostMsg_UpdateFaviconURL(routing_id(), urls));
[email protected]41225fe2013-03-29 05:32:023516}
3517
3518void RenderViewImpl::DidStopLoadingIcons() {
huangsdde9aceb2015-03-17 21:26:163519 int icon_types = WebIconURL::TypeFavicon | WebIconURL::TypeTouchPrecomposed |
3520 WebIconURL::TypeTouch;
[email protected]41225fe2013-03-29 05:32:023521
nasko2411ba372014-10-13 17:45:413522 // Favicons matter only for the top-level frame. If it is a WebRemoteFrame,
3523 // just return early.
3524 if (webview()->mainFrame()->isWebRemoteFrame())
3525 return;
3526
[email protected]41225fe2013-03-29 05:32:023527 WebVector<WebIconURL> icon_urls =
3528 webview()->mainFrame()->iconURLs(icon_types);
3529
3530 std::vector<FaviconURL> urls;
3531 for (size_t i = 0; i < icon_urls.size(); i++) {
3532 WebURL url = icon_urls[i].iconURL();
[email protected]2bd262b2014-04-16 05:31:233533 std::vector<gfx::Size> sizes;
[email protected]f34ac132014-03-20 23:02:053534 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
[email protected]41225fe2013-03-29 05:32:023535 if (!url.isEmpty())
[email protected]f34ac132014-03-20 23:02:053536 urls.push_back(
3537 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes));
[email protected]41225fe2013-03-29 05:32:023538 }
3539 SendUpdateFaviconURL(urls);
3540}
3541
oshimad5279032015-12-16 18:22:333542void RenderViewImpl::UpdateWebViewWithDeviceScaleFactor() {
3543 if (!webview())
3544 return;
oshima750cb4342015-10-31 00:59:013545 if (IsUseZoomForDSFEnabled()) {
oshimad5279032015-12-16 18:22:333546 webview()->setZoomFactorForDeviceScaleFactor(device_scale_factor_);
oshima750cb4342015-10-31 00:59:013547 } else {
3548 webview()->setDeviceScaleFactor(device_scale_factor_);
3549 }
oshimad5279032015-12-16 18:22:333550 webview()->settings()->setPreferCompositingToLCDTextEnabled(
3551 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_));
oshima750cb4342015-10-31 00:59:013552}
3553
[email protected]e9ff79c2012-10-19 21:31:263554} // namespace content