blob: 6f874fd7c36579005beeee83e5615b87b8f93f2f [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"
[email protected]e7ca2892012-09-01 00:52:1516#include "base/debug/trace_event.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]7ccb7072013-06-10 20:56:2822#include "base/message_loop/message_loop_proxy.h"
[email protected]f29efe6b2014-06-09 05:01:5123#include "base/metrics/field_trial.h"
[email protected]835d7c82010-10-14 04:38:3824#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2825#include "base/path_service.h"
[email protected]d3b4ee22013-07-24 22:50:0626#include "base/process/kill.h"
[email protected]7d08a9352013-10-15 08:24:5627#include "base/process/process.h"
[email protected]21aa99682013-06-11 07:17:0128#include "base/strings/string_number_conversions.h"
[email protected]b9e7c479f2013-04-12 04:33:2429#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4930#include "base/strings/string_split.h"
[email protected]21aa99682013-06-11 07:17:0131#include "base/strings/string_util.h"
[email protected]40d11e02013-03-28 17:43:1432#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0033#include "base/strings/utf_string_conversions.h"
[email protected]abb522162013-06-28 01:54:1634#include "base/time/time.h"
[email protected]e3415902013-10-17 15:00:4635#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]10208ea2013-06-06 20:08:0339#include "content/child/child_thread.h"
[email protected]29e2fb42013-07-19 01:13:4740#include "content/child/npapi/webplugin_delegate_impl.h"
[email protected]541b7b02013-06-07 00:59:3441#include "content/child/request_extra_data.h"
[email protected]10208ea2013-06-06 20:08:0342#include "content/child/webmessageportchannel_impl.h"
[email protected]37666cf2011-03-13 21:51:4243#include "content/common/database_messages.h"
[email protected]5f2aa722013-08-07 16:59:4144#include "content/common/dom_storage/dom_storage_types.h"
[email protected]59f4f2fa2011-03-23 01:00:5545#include "content/common/drag_messages.h"
[email protected]c6bc20332014-02-28 18:30:3946#include "content/common/frame_messages.h"
[email protected]c26ad882012-02-07 06:41:2047#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]c084330e02013-04-27 01:08:1548#include "content/common/input_messages.h"
[email protected]127dd582011-03-16 21:32:1049#include "content/common/pepper_messages.h"
[email protected]5fa3a062012-03-21 15:39:3450#include "content/common/socket_stream_handle_data.h"
[email protected]e4495212012-12-06 03:09:1251#include "content/common/ssl_status_serialization.h"
[email protected]778574e2011-03-21 22:03:5052#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2153#include "content/public/common/bindings_policy.h"
[email protected]744c2a22012-03-15 18:42:0454#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4855#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2956#include "content/public/common/content_switches.h"
[email protected]dc293a72013-07-01 11:11:2257#include "content/public/common/drop_data.h"
[email protected]41225fe2013-03-29 05:32:0258#include "content/public/common/favicon_url.h"
[email protected]8caadeb2011-11-22 02:45:2359#include "content/public/common/file_chooser_params.h"
[email protected]7940b8e2013-07-25 23:08:4960#include "content/public/common/page_zoom.h"
[email protected]e4495212012-12-06 03:09:1261#include "content/public/common/ssl_status.h"
[email protected]818915cd2012-11-20 13:14:1162#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0363#include "content/public/common/url_constants.h"
[email protected]3b366ae2013-05-17 21:16:5864#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:0565#include "content/public/common/web_preferences.h"
[email protected]d344114c2011-10-01 01:24:3466#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0767#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3268#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4469#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3670#include "content/public/renderer/render_view_visitor.h"
[email protected]4e4646a52013-02-08 07:23:4171#include "content/renderer/accessibility/renderer_accessibility.h"
72#include "content/renderer/accessibility/renderer_accessibility_complete.h"
73#include "content/renderer/accessibility/renderer_accessibility_focus_only.h"
[email protected]e6e56752012-08-10 00:46:0674#include "content/renderer/browser_plugin/browser_plugin.h"
75#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]fb325d122012-11-20 23:58:0576#include "content/renderer/browser_plugin/browser_plugin_manager_impl.h"
[email protected]70019152012-12-19 11:44:1977#include "content/renderer/devtools/devtools_agent.h"
[email protected]f9526d12012-10-18 01:55:0378#include "content/renderer/disambiguation_popup_helper.h"
[email protected]1910fe82012-05-10 00:04:1079#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]dc293a72013-07-01 11:11:2280#include "content/renderer/drop_data_builder.h"
[email protected]ba91a792013-02-06 09:48:2881#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]d4734982014-04-15 02:05:5582#include "content/renderer/history_controller.h"
[email protected]dc064352014-04-25 08:36:3883#include "content/renderer/history_serialization.h"
[email protected]1784b2f2011-11-24 10:53:4884#include "content/renderer/idle_user_detector.h"
[email protected]66fca5bc2013-05-23 06:58:2985#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1386#include "content/renderer/input/input_handler_manager.h"
[email protected]92d457802013-04-01 19:18:4987#include "content/renderer/internal_document_state_data.h"
[email protected]4a914882013-01-10 00:43:4888#include "content/renderer/media/audio_device_factory.h"
[email protected]6392d982013-04-16 16:59:2289#include "content/renderer/media/video_capture_impl_manager.h"
[email protected]3fad220d2014-01-23 11:30:0690#include "content/renderer/memory_benchmarking_extension.h"
[email protected]4a19be92011-09-22 14:25:0291#include "content/renderer/mhtml_generator.h"
[email protected]b3a97b52014-07-09 06:25:0592#include "content/renderer/net_info_helper.h"
[email protected]227692c52013-05-31 22:43:0493#include "content/renderer/render_frame_impl.h"
[email protected]5a7100d2014-05-19 01:29:0494#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0595#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4496#include "content/renderer/render_thread_impl.h"
[email protected]8d41d7612012-11-14 20:32:1997#include "content/renderer/render_view_impl_params.h"
[email protected]89054502012-06-03 10:29:2498#include "content/renderer/render_view_mouse_lock_dispatcher.h"
[email protected]2cff0052011-03-18 16:51:4499#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]663bd9e2011-03-21 01:07:01100#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]5b45ad42013-10-25 00:42:04101#include "content/renderer/resizing_mode_selector.h"
[email protected]12a936d2013-05-15 04:55:49102#include "content/renderer/savable_resources.h"
[email protected]cdb6b1e2014-01-23 00:06:49103#include "content/renderer/skia_benchmarking_extension.h"
[email protected]64d09222012-05-25 10:10:34104#include "content/renderer/speech_recognition_dispatcher.h"
[email protected]27c521a2013-05-29 20:44:32105#include "content/renderer/stats_collection_controller.h"
106#include "content/renderer/stats_collection_observer.h"
[email protected]86a7d3c2011-09-12 16:45:32107#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:19108#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:21109#include "content/renderer/web_ui_extension.h"
110#include "content/renderer/web_ui_extension_data.h"
[email protected]1c142a52014-04-05 20:14:17111#include "content/renderer/web_ui_mojo.h"
[email protected]6f516082011-03-17 19:15:35112#include "content/renderer/websharedworker_proxy.h"
[email protected]f5961142013-04-17 23:09:42113#include "media/audio/audio_output_device.h"
[email protected]ee68378a2010-08-10 01:05:41114#include "media/base/media_switches.h"
[email protected]37136d162012-04-09 23:39:19115#include "media/filters/audio_renderer_impl.h"
[email protected]1cad8802013-08-13 16:54:32116#include "media/filters/gpu_video_accelerator_factories.h"
[email protected]d1ef81d2012-07-24 11:39:36117#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29118#include "net/base/escape.h"
119#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09120#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04121#include "net/http/http_util.h"
[email protected]d0fcff72013-07-23 02:45:43122#include "third_party/WebKit/public/platform/WebCString.h"
[email protected]b3a97b52014-07-09 06:25:05123#include "third_party/WebKit/public/platform/WebConnectionType.h"
[email protected]d0fcff72013-07-23 02:45:43124#include "third_party/WebKit/public/platform/WebDragData.h"
[email protected]d0fcff72013-07-23 02:45:43125#include "third_party/WebKit/public/platform/WebHTTPBody.h"
126#include "third_party/WebKit/public/platform/WebImage.h"
127#include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
128#include "third_party/WebKit/public/platform/WebPoint.h"
129#include "third_party/WebKit/public/platform/WebRect.h"
130#include "third_party/WebKit/public/platform/WebSize.h"
131#include "third_party/WebKit/public/platform/WebSocketStreamHandle.h"
[email protected]ec173b522013-11-14 11:01:18132#include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h"
[email protected]d0fcff72013-07-23 02:45:43133#include "third_party/WebKit/public/platform/WebString.h"
134#include "third_party/WebKit/public/platform/WebURL.h"
135#include "third_party/WebKit/public/platform/WebURLError.h"
136#include "third_party/WebKit/public/platform/WebURLRequest.h"
137#include "third_party/WebKit/public/platform/WebURLResponse.h"
138#include "third_party/WebKit/public/platform/WebVector.h"
[email protected]10760e4a2013-09-04 23:32:20139#include "third_party/WebKit/public/web/WebAXObject.h"
[email protected]2255a9332013-06-17 05:12:31140#include "third_party/WebKit/public/web/WebColorName.h"
[email protected]8bc5ff02013-11-29 06:34:03141#include "third_party/WebKit/public/web/WebColorSuggestion.h"
[email protected]2255a9332013-06-17 05:12:31142#include "third_party/WebKit/public/web/WebDOMEvent.h"
143#include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
144#include "third_party/WebKit/public/web/WebDataSource.h"
145#include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h"
146#include "third_party/WebKit/public/web/WebDateTimeChooserParams.h"
147#include "third_party/WebKit/public/web/WebDevToolsAgent.h"
148#include "third_party/WebKit/public/web/WebDocument.h"
149#include "third_party/WebKit/public/web/WebElement.h"
150#include "third_party/WebKit/public/web/WebFileChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31151#include "third_party/WebKit/public/web/WebFindOptions.h"
152#include "third_party/WebKit/public/web/WebFormControlElement.h"
153#include "third_party/WebKit/public/web/WebFormElement.h"
154#include "third_party/WebKit/public/web/WebFrame.h"
[email protected]6bd867b2013-07-24 22:10:20155#include "third_party/WebKit/public/web/WebGlyphCache.h"
[email protected]2255a9332013-06-17 05:12:31156#include "third_party/WebKit/public/web/WebHistoryItem.h"
[email protected]91dcc6d32014-07-30 00:01:33157#include "third_party/WebKit/public/web/WebHitTestResult.h"
[email protected]2255a9332013-06-17 05:12:31158#include "third_party/WebKit/public/web/WebInputElement.h"
159#include "third_party/WebKit/public/web/WebInputEvent.h"
[email protected]afe7d90d2014-07-19 05:10:22160#include "third_party/WebKit/public/web/WebKit.h"
[email protected]35b2a972014-04-04 15:50:22161#include "third_party/WebKit/public/web/WebLocalFrame.h"
[email protected]2255a9332013-06-17 05:12:31162#include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
163#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
[email protected]b3a97b52014-07-09 06:25:05164#include "third_party/WebKit/public/web/WebNetworkStateNotifier.h"
[email protected]2255a9332013-06-17 05:12:31165#include "third_party/WebKit/public/web/WebNodeList.h"
166#include "third_party/WebKit/public/web/WebPageSerializer.h"
167#include "third_party/WebKit/public/web/WebPlugin.h"
168#include "third_party/WebKit/public/web/WebPluginAction.h"
169#include "third_party/WebKit/public/web/WebPluginContainer.h"
170#include "third_party/WebKit/public/web/WebPluginDocument.h"
[email protected]2255a9332013-06-17 05:12:31171#include "third_party/WebKit/public/web/WebRange.h"
[email protected]b3a97b52014-07-09 06:25:05172#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
[email protected]2255a9332013-06-17 05:12:31173#include "third_party/WebKit/public/web/WebScriptSource.h"
174#include "third_party/WebKit/public/web/WebSearchableFormData.h"
175#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
176#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
177#include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
178#include "third_party/WebKit/public/web/WebSettings.h"
[email protected]2255a9332013-06-17 05:12:31179#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
[email protected]2255a9332013-06-17 05:12:31180#include "third_party/WebKit/public/web/WebView.h"
181#include "third_party/WebKit/public/web/WebWindowFeatures.h"
182#include "third_party/WebKit/public/web/default/WebRenderTheme.h"
[email protected]b3a97b52014-07-09 06:25:05183#include "third_party/icu/source/common/unicode/uchar.h"
184#include "third_party/icu/source/common/unicode/uscript.h"
[email protected]4ee64622014-03-21 22:34:15185#include "ui/base/clipboard/clipboard.h"
[email protected]1400e6dc2013-04-27 02:36:27186#include "ui/base/ui_base_switches_util.h"
[email protected]7d08a9352013-10-15 08:24:56187#include "ui/events/latency_info.h"
[email protected]08397d52011-02-05 01:53:38188#include "ui/gfx/native_widget_types.h"
189#include "ui/gfx/point.h"
190#include "ui/gfx/rect.h"
[email protected]70221f02013-01-31 22:17:07191#include "ui/gfx/rect_conversions.h"
[email protected]f9526d12012-10-18 01:55:03192#include "ui/gfx/size_conversions.h"
[email protected]4344a3c2013-01-17 23:49:20193#include "ui/shell_dialogs/selected_file_info.h"
[email protected]c4a9e932011-03-05 04:05:55194#include "v8/include/v8.h"
initial.commit09911bf2008-07-26 23:55:29195
[email protected]25fb9b32012-04-27 03:21:55196#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25197#include <cpu-features.h>
198
[email protected]20657a82012-08-21 20:23:03199#include "content/renderer/android/address_detector.h"
200#include "content/renderer/android/content_detector.h"
201#include "content/renderer/android/email_detector.h"
202#include "content/renderer/android/phone_number_detector.h"
[email protected]74d9c5242014-05-01 05:10:03203#include "net/android/network_library.h"
[email protected]c277d3c2013-07-15 21:49:37204#include "skia/ext/platform_canvas.h"
[email protected]5c30b5e02013-05-30 03:46:08205#include "third_party/WebKit/public/platform/WebFloatPoint.h"
206#include "third_party/WebKit/public/platform/WebFloatRect.h"
[email protected]59363fc92012-09-05 03:46:31207#include "ui/gfx/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40208
[email protected]25fb9b32012-04-27 03:21:55209#elif defined(OS_WIN)
[email protected]6c8afae52009-01-22 02:24:57210// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57211// * theming
[email protected]990e6222012-11-16 13:31:18212#include "ui/native_theme/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03213#elif defined(USE_X11)
[email protected]990e6222012-11-16 13:31:18214#include "ui/native_theme/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33215#elif defined(OS_MACOSX)
216#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57217#endif
218
[email protected]ea2fb972013-08-07 05:44:26219#if defined(ENABLE_PLUGINS)
[email protected]a80af12e2013-08-07 23:36:13220#include "content/renderer/npapi/webplugin_delegate_proxy.h"
[email protected]ea2fb972013-08-07 05:44:26221#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
222#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26223#endif
224
[email protected]9ac667e2013-09-09 12:49:21225#if defined(ENABLE_WEBRTC)
226#include "content/renderer/media/rtc_peer_connection_handler.h"
[email protected]22fe91d2014-08-12 17:07:12227#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
[email protected]9ac667e2013-09-09 12:49:21228#endif
229
[email protected]180ef242013-11-07 06:50:46230using blink::WebAXObject;
231using blink::WebApplicationCacheHost;
232using blink::WebApplicationCacheHostClient;
233using blink::WebCString;
234using blink::WebColor;
235using blink::WebColorName;
236using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46237using blink::WebData;
238using blink::WebDataSource;
239using blink::WebDocument;
240using blink::WebDOMEvent;
241using blink::WebDOMMessageEvent;
242using blink::WebDragData;
243using blink::WebDragOperation;
244using blink::WebDragOperationsMask;
245using blink::WebElement;
[email protected]180ef242013-11-07 06:50:46246using blink::WebFileChooserCompletion;
247using blink::WebFindOptions;
248using blink::WebFormControlElement;
249using blink::WebFormElement;
250using blink::WebFrame;
251using blink::WebGestureEvent;
252using blink::WebHistoryItem;
253using blink::WebHTTPBody;
254using blink::WebIconURL;
255using blink::WebImage;
256using blink::WebInputElement;
257using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22258using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46259using blink::WebMediaPlayerAction;
[email protected]180ef242013-11-07 06:50:46260using blink::WebMouseEvent;
261using blink::WebNavigationPolicy;
262using blink::WebNavigationType;
263using blink::WebNode;
264using blink::WebPageSerializer;
265using blink::WebPageSerializerClient;
266using blink::WebPeerConnection00Handler;
267using blink::WebPeerConnection00HandlerClient;
268using blink::WebPeerConnectionHandler;
269using blink::WebPeerConnectionHandlerClient;
270using blink::WebPluginAction;
271using blink::WebPluginContainer;
272using blink::WebPluginDocument;
[email protected]180ef242013-11-07 06:50:46273using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46274using blink::WebRange;
275using blink::WebRect;
276using blink::WebReferrerPolicy;
[email protected]180ef242013-11-07 06:50:46277using blink::WebScriptSource;
278using blink::WebSearchableFormData;
279using blink::WebSecurityOrigin;
280using blink::WebSecurityPolicy;
281using blink::WebSerializedScriptValue;
282using blink::WebSettings;
283using blink::WebSize;
284using blink::WebSocketStreamHandle;
285using blink::WebStorageNamespace;
286using blink::WebStorageQuotaCallbacks;
287using blink::WebStorageQuotaError;
288using blink::WebStorageQuotaType;
289using blink::WebString;
290using blink::WebTextAffinity;
291using blink::WebTextDirection;
292using blink::WebTouchEvent;
293using blink::WebURL;
294using blink::WebURLError;
295using blink::WebURLRequest;
296using blink::WebURLResponse;
297using blink::WebUserGestureIndicator;
298using blink::WebVector;
299using blink::WebView;
300using blink::WebWidget;
301using blink::WebWindowFeatures;
[email protected]b3a97b52014-07-09 06:25:05302using blink::WebNetworkStateNotifier;
303using blink::WebRuntimeFeatures;
[email protected]6fdd4182010-10-14 23:59:26304using base::Time;
305using base::TimeDelta;
[email protected]e1acf6f2008-10-27 20:43:33306
[email protected]20657a82012-08-21 20:23:03307#if defined(OS_ANDROID)
[email protected]180ef242013-11-07 06:50:46308using blink::WebContentDetectionResult;
309using blink::WebFloatPoint;
310using blink::WebFloatRect;
311using blink::WebHitTestResult;
[email protected]20657a82012-08-21 20:23:03312#endif
313
[email protected]e9ff79c2012-10-19 21:31:26314namespace content {
315
initial.commit09911bf2008-07-26 23:55:29316//-----------------------------------------------------------------------------
317
[email protected]180ef242013-11-07 06:50:46318typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49319static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]058561b2012-12-03 06:48:22320typedef std::map<int32, RenderViewImpl*> RoutingIDViewMap;
321static base::LazyInstance<RoutingIDViewMap> g_routing_id_view_map =
322 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02323
[email protected]882daa92009-11-05 16:31:31324// Time, in seconds, we delay before sending content state changes (such as form
325// state and scroll position) to the browser. We delay sending changes to avoid
326// spamming the browser.
327// To avoid having tab/session restore require sending a message to get the
328// current content state during tab closing we use a shorter timeout for the
329// foreground renderer. This means there is a small window of time from which
330// content state is modified and not sent to session restore, but this is
331// better than having to wake up all renderers during shutdown.
[email protected]9afc14e22013-09-25 22:34:14332const int kDelaySecondsForContentStateSyncHidden = 5;
333const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29334
[email protected]20657a82012-08-21 20:23:03335#if defined(OS_ANDROID)
336// Delay between tapping in content and launching the associated android intent.
337// Used to allow users see what has been recognized as content.
[email protected]9afc14e22013-09-25 22:34:14338const size_t kContentIntentDelayMilliseconds = 700;
[email protected]20657a82012-08-21 20:23:03339#endif
340
[email protected]8d41d7612012-11-14 20:32:19341static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) =
342 NULL;
343
[email protected]c6bc20332014-02-28 18:30:39344// static
345bool RenderViewImpl::IsReload(const FrameMsg_Navigate_Params& params) {
[email protected]007733c2011-11-17 00:34:07346 return
[email protected]c6bc20332014-02-28 18:30:39347 params.navigation_type == FrameMsg_Navigate_Type::RELOAD ||
348 params.navigation_type == FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE ||
[email protected]7c16976c2012-08-04 02:38:23349 params.navigation_type ==
[email protected]c6bc20332014-02-28 18:30:39350 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]007733c2011-11-17 00:34:07351}
352
[email protected]e507045d2013-07-24 15:23:44353// static
[email protected]e507045d2013-07-24 15:23:44354Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56355 WebFrame* frame,
356 const WebURLRequest& request) {
357 return Referrer(GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]cacbd7a2014-02-04 01:26:02358 request.referrerPolicy());
[email protected]44e55b012013-07-23 14:21:56359}
360
[email protected]c6bc20332014-02-28 18:30:39361// static
[email protected]65920f332014-03-04 21:14:18362WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32363 WebNavigationPolicy policy) {
364 switch (policy) {
[email protected]180ef242013-11-07 06:50:46365 case blink::WebNavigationPolicyIgnore:
[email protected]48861e22013-01-09 00:27:32366 return IGNORE_ACTION;
[email protected]180ef242013-11-07 06:50:46367 case blink::WebNavigationPolicyDownload:
[email protected]48861e22013-01-09 00:27:32368 return SAVE_TO_DISK;
[email protected]180ef242013-11-07 06:50:46369 case blink::WebNavigationPolicyCurrentTab:
[email protected]48861e22013-01-09 00:27:32370 return CURRENT_TAB;
[email protected]180ef242013-11-07 06:50:46371 case blink::WebNavigationPolicyNewBackgroundTab:
[email protected]48861e22013-01-09 00:27:32372 return NEW_BACKGROUND_TAB;
[email protected]180ef242013-11-07 06:50:46373 case blink::WebNavigationPolicyNewForegroundTab:
[email protected]48861e22013-01-09 00:27:32374 return NEW_FOREGROUND_TAB;
[email protected]180ef242013-11-07 06:50:46375 case blink::WebNavigationPolicyNewWindow:
[email protected]48861e22013-01-09 00:27:32376 return NEW_WINDOW;
[email protected]180ef242013-11-07 06:50:46377 case blink::WebNavigationPolicyNewPopup:
[email protected]48861e22013-01-09 00:27:32378 return NEW_POPUP;
379 default:
380 NOTREACHED() << "Unexpected WebNavigationPolicy";
381 return IGNORE_ACTION;
382 }
383}
384
[email protected]d8221b22013-05-23 05:35:43385// Returns true if the device scale is high enough that losing subpixel
386// antialiasing won't have a noticeable effect on text quality.
387static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
388#if defined(OS_ANDROID)
389 // On Android, we never have subpixel antialiasing.
390 return true;
391#else
392 return device_scale_factor > 1.5f;
393#endif
394
395}
396
[email protected]b8ec1112014-08-17 20:09:10397static bool PreferCompositingToLCDText(float device_scale_factor) {
[email protected]fb854192013-02-06 01:30:04398 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b8ec1112014-08-17 20:09:10399 if (command_line.HasSwitch(switches::kDisablePreferCompositingToLCDText))
[email protected]fb854192013-02-06 01:30:04400 return false;
[email protected]b8ec1112014-08-17 20:09:10401 if (command_line.HasSwitch(switches::kEnablePreferCompositingToLCDText))
[email protected]fb854192013-02-06 01:30:04402 return true;
[email protected]10c19732014-08-18 19:39:23403 if (RenderThreadImpl::current() &&
404 !RenderThreadImpl::current()->is_lcd_text_enabled())
405 return true;
[email protected]d8221b22013-05-23 05:35:43406 return DeviceScaleEnsuresTextQuality(device_scale_factor);
407}
408
409static bool ShouldUseTransitionCompositing(float device_scale_factor) {
410 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
411
412 if (command_line.HasSwitch(switches::kDisableCompositingForTransition))
413 return false;
414
415 if (command_line.HasSwitch(switches::kEnableCompositingForTransition))
[email protected]fb854192013-02-06 01:30:04416 return true;
417
[email protected]9a7f6e12013-06-11 07:05:13418 // TODO(ajuma): Re-enable this by default for high-DPI once the problem
419 // of excessive layer promotion caused by overlap has been addressed.
420 // http://crbug.com/178119.
421 return false;
[email protected]fb854192013-02-06 01:30:04422}
423
[email protected]180ef242013-11-07 06:50:46424static FaviconURL::IconType ToFaviconType(blink::WebIconURL::Type type) {
[email protected]41225fe2013-03-29 05:32:02425 switch (type) {
[email protected]180ef242013-11-07 06:50:46426 case blink::WebIconURL::TypeFavicon:
[email protected]41225fe2013-03-29 05:32:02427 return FaviconURL::FAVICON;
[email protected]180ef242013-11-07 06:50:46428 case blink::WebIconURL::TypeTouch:
[email protected]41225fe2013-03-29 05:32:02429 return FaviconURL::TOUCH_ICON;
[email protected]180ef242013-11-07 06:50:46430 case blink::WebIconURL::TypeTouchPrecomposed:
[email protected]41225fe2013-03-29 05:32:02431 return FaviconURL::TOUCH_PRECOMPOSED_ICON;
[email protected]180ef242013-11-07 06:50:46432 case blink::WebIconURL::TypeInvalid:
[email protected]41225fe2013-03-29 05:32:02433 return FaviconURL::INVALID_ICON;
434 }
435 return FaviconURL::INVALID_ICON;
436}
437
[email protected]f34ac132014-03-20 23:02:05438static void ConvertToFaviconSizes(
439 const blink::WebVector<blink::WebSize>& web_sizes,
440 std::vector<gfx::Size>* sizes) {
[email protected]2bd262b2014-04-16 05:31:23441 DCHECK(sizes->empty());
442 sizes->reserve(web_sizes.size());
[email protected]f34ac132014-03-20 23:02:05443 for (size_t i = 0; i < web_sizes.size(); ++i)
444 sizes->push_back(gfx::Size(web_sizes[i]));
445}
446
initial.commit09911bf2008-07-26 23:55:29447///////////////////////////////////////////////////////////////////////////////
448
[email protected]310ebd6302011-10-10 19:06:28449struct RenderViewImpl::PendingFileChooser {
[email protected]e9ff79c2012-10-19 21:31:26450 PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c)
[email protected]cdaf8d02010-03-30 19:52:47451 : params(p),
452 completion(c) {
453 }
[email protected]e9ff79c2012-10-19 21:31:26454 FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47455 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
456};
457
[email protected]217690d2012-01-27 07:33:11458namespace {
459
460class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
461 public:
[email protected]180ef242013-11-07 06:50:46462 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
[email protected]217690d2012-01-27 07:33:11463 : webwidget_(webwidget) {}
464
465 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
466 if (succeeded)
467 webwidget_->didAcquirePointerLock();
468 else
469 webwidget_->didNotAcquirePointerLock();
470 }
471
472 virtual void OnMouseLockLost() OVERRIDE {
473 webwidget_->didLosePointerLock();
474 }
475
476 virtual bool HandleMouseLockedInputEvent(
[email protected]180ef242013-11-07 06:50:46477 const blink::WebMouseEvent &event) OVERRIDE {
[email protected]217690d2012-01-27 07:33:11478 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
479 return false;
480 }
481
482 private:
[email protected]180ef242013-11-07 06:50:46483 blink::WebWidget* webwidget_;
[email protected]217690d2012-01-27 07:33:11484};
485
[email protected]41225fe2013-03-29 05:32:02486bool TouchEnabled() {
487// Based on the definition of chrome::kEnableTouchIcon.
488#if defined(OS_ANDROID)
489 return true;
490#else
491 return false;
492#endif
493}
494
[email protected]dc293a72013-07-01 11:11:22495WebDragData DropDataToWebDragData(const DropData& drop_data) {
[email protected]c10680312013-05-31 15:22:05496 std::vector<WebDragData::Item> item_list;
497
498 // These fields are currently unused when dragging into WebKit.
499 DCHECK(drop_data.download_metadata.empty());
500 DCHECK(drop_data.file_contents.empty());
501 DCHECK(drop_data.file_description_filename.empty());
502
503 if (!drop_data.text.is_null()) {
504 WebDragData::Item item;
505 item.storageType = WebDragData::Item::StorageTypeString;
506 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText);
507 item.stringData = drop_data.text.string();
508 item_list.push_back(item);
509 }
510
511 // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it
512 // meaningful to write an empty URL to the clipboard?
513 if (!drop_data.url.is_empty()) {
514 WebDragData::Item item;
515 item.storageType = WebDragData::Item::StorageTypeString;
516 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList);
517 item.stringData = WebString::fromUTF8(drop_data.url.spec());
518 item.title = drop_data.url_title;
519 item_list.push_back(item);
520 }
521
522 if (!drop_data.html.is_null()) {
523 WebDragData::Item item;
524 item.storageType = WebDragData::Item::StorageTypeString;
525 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML);
526 item.stringData = drop_data.html.string();
527 item.baseURL = drop_data.html_base_url;
528 item_list.push_back(item);
529 }
530
[email protected]17ea0ae22014-03-28 21:54:46531 for (std::vector<ui::FileInfo>::const_iterator it =
[email protected]c10680312013-05-31 15:22:05532 drop_data.filenames.begin();
533 it != drop_data.filenames.end();
534 ++it) {
535 WebDragData::Item item;
536 item.storageType = WebDragData::Item::StorageTypeFilename;
[email protected]17ea0ae22014-03-28 21:54:46537 item.filenameData = it->path.AsUTF16Unsafe();
538 item.displayNameData = it->display_name.AsUTF16Unsafe();
[email protected]c10680312013-05-31 15:22:05539 item_list.push_back(item);
540 }
541
[email protected]60ed95f2014-04-23 12:19:48542 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it =
543 drop_data.file_system_files.begin();
544 it != drop_data.file_system_files.end();
545 ++it) {
546 WebDragData::Item item;
547 item.storageType = WebDragData::Item::StorageTypeFileSystemFile;
548 item.fileSystemURL = it->url;
549 item.fileSystemFileSize = it->size;
550 item_list.push_back(item);
551 }
552
[email protected]c10680312013-05-31 15:22:05553 for (std::map<base::string16, base::string16>::const_iterator it =
554 drop_data.custom_data.begin();
555 it != drop_data.custom_data.end();
556 ++it) {
557 WebDragData::Item item;
558 item.storageType = WebDragData::Item::StorageTypeString;
559 item.stringType = it->first;
560 item.stringData = it->second;
561 item_list.push_back(item);
562 }
563
564 WebDragData result;
565 result.initialize();
566 result.setItems(item_list);
567 result.setFilesystemId(drop_data.filesystem_id);
568 return result;
569}
570
[email protected]b3a97b52014-07-09 06:25:05571typedef void (*SetFontFamilyWrapper)(blink::WebSettings*,
572 const base::string16&,
573 UScriptCode);
574
575void SetStandardFontFamilyWrapper(WebSettings* settings,
576 const base::string16& font,
577 UScriptCode script) {
578 settings->setStandardFontFamily(font, script);
579}
580
581void SetFixedFontFamilyWrapper(WebSettings* settings,
582 const base::string16& font,
583 UScriptCode script) {
584 settings->setFixedFontFamily(font, script);
585}
586
587void SetSerifFontFamilyWrapper(WebSettings* settings,
588 const base::string16& font,
589 UScriptCode script) {
590 settings->setSerifFontFamily(font, script);
591}
592
593void SetSansSerifFontFamilyWrapper(WebSettings* settings,
594 const base::string16& font,
595 UScriptCode script) {
596 settings->setSansSerifFontFamily(font, script);
597}
598
599void SetCursiveFontFamilyWrapper(WebSettings* settings,
600 const base::string16& font,
601 UScriptCode script) {
602 settings->setCursiveFontFamily(font, script);
603}
604
605void SetFantasyFontFamilyWrapper(WebSettings* settings,
606 const base::string16& font,
607 UScriptCode script) {
608 settings->setFantasyFontFamily(font, script);
609}
610
611void SetPictographFontFamilyWrapper(WebSettings* settings,
612 const base::string16& font,
613 UScriptCode script) {
614 settings->setPictographFontFamily(font, script);
615}
616
617// If |scriptCode| is a member of a family of "similar" script codes, returns
618// the script code in that family that is used by WebKit for font selection
619// purposes. For example, USCRIPT_KATAKANA_OR_HIRAGANA and USCRIPT_JAPANESE are
620// considered equivalent for the purposes of font selection. WebKit uses the
621// script code USCRIPT_KATAKANA_OR_HIRAGANA. So, if |scriptCode| is
622// USCRIPT_JAPANESE, the function returns USCRIPT_KATAKANA_OR_HIRAGANA. WebKit
623// uses different scripts than the ones in Chrome pref names because the version
624// of ICU included on certain ports does not have some of the newer scripts. If
625// |scriptCode| is not a member of such a family, returns |scriptCode|.
626UScriptCode GetScriptForWebSettings(UScriptCode scriptCode) {
627 switch (scriptCode) {
628 case USCRIPT_HIRAGANA:
629 case USCRIPT_KATAKANA:
630 case USCRIPT_JAPANESE:
631 return USCRIPT_KATAKANA_OR_HIRAGANA;
632 case USCRIPT_KOREAN:
633 return USCRIPT_HANGUL;
634 default:
635 return scriptCode;
636 }
637}
638
639void ApplyFontsFromMap(const ScriptFontFamilyMap& map,
640 SetFontFamilyWrapper setter,
641 WebSettings* settings) {
642 for (ScriptFontFamilyMap::const_iterator it = map.begin(); it != map.end();
643 ++it) {
644 int32 script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
645 if (script >= 0 && script < USCRIPT_CODE_LIMIT) {
646 UScriptCode code = static_cast<UScriptCode>(script);
647 (*setter)(settings, it->second, GetScriptForWebSettings(code));
648 }
649 }
650}
651
[email protected]217690d2012-01-27 07:33:11652} // namespace
653
[email protected]8d41d7612012-11-14 20:32:19654RenderViewImpl::RenderViewImpl(RenderViewImplParams* params)
[email protected]180ef242013-11-07 06:50:46655 : RenderWidget(blink::WebPopupTypeNone,
[email protected]8d41d7612012-11-14 20:32:19656 params->screen_info,
[email protected]1ac10dca2013-08-20 20:47:04657 params->swapped_out,
[email protected]7912e822014-04-16 02:37:03658 params->hidden,
659 params->never_visible),
[email protected]8d41d7612012-11-14 20:32:19660 webkit_preferences_(params->webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02661 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09662 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02663 send_preferred_size_changes_(false),
[email protected]e75cb49e2009-01-05 23:13:21664 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02665 opened_by_user_gesture_(true),
666 opener_suppressed_(false),
[email protected]88f10a22013-11-06 21:22:12667 suppress_dialogs_until_swap_out_(false),
[email protected]81a34412009-01-05 19:17:24668 page_id_(-1),
669 last_page_id_sent_to_browser_(-1),
[email protected]8d41d7612012-11-14 20:32:19670 next_page_id_(params->next_page_id),
[email protected]3cc72b12010-03-18 23:03:00671 history_list_offset_(-1),
672 history_list_length_(0),
[email protected]7e9523b2014-03-25 03:02:42673 frames_in_progress_(0),
[email protected]3354d3e2010-06-10 19:53:02674 target_url_status_(TARGET_NONE),
[email protected]d42bf472014-06-14 01:49:38675 uses_temporary_zoom_level_(false),
[email protected]bbc8856d2013-06-14 10:37:04676#if defined(OS_ANDROID)
677 top_controls_constraints_(cc::BOTH),
678#endif
[email protected]1875bc02014-03-14 06:33:59679 has_scrolled_focused_editable_node_into_rect_(false),
[email protected]64d09222012-05-25 10:10:34680 speech_recognition_dispatcher_(NULL),
[email protected]fb325d122012-11-20 23:58:05681 browser_plugin_manager_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41682 devtools_agent_(NULL),
[email protected]217690d2012-01-27 07:33:11683 mouse_lock_dispatcher_(NULL),
[email protected]20657a82012-08-21 20:23:03684#if defined(OS_ANDROID)
685 expected_content_intent_id_(0),
[email protected]a7564272013-04-19 14:24:46686#endif
687#if defined(OS_WIN)
688 focused_plugin_id_(-1),
689#endif
[email protected]e16c7a12013-12-05 16:30:08690#if defined(ENABLE_PLUGINS)
[email protected]54ea9ff2014-03-20 00:27:54691 plugin_find_handler_(NULL),
[email protected]e16c7a12013-12-05 16:30:08692 focused_pepper_plugin_(NULL),
693 pepper_last_mouse_event_target_(NULL),
694#endif
[email protected]8a67aa352013-02-20 02:58:29695 enumeration_completion_id_(0),
[email protected]8d41d7612012-11-14 20:32:19696 session_storage_namespace_id_(params->session_storage_namespace_id),
[email protected]f2c530d2014-02-20 20:15:30697 next_snapshot_id_(0) {
[email protected]075366912013-02-18 07:13:24698}
699
[email protected]34f288c2014-04-28 16:25:37700void RenderViewImpl::Initialize(RenderViewImplParams* params) {
[email protected]8d41d7612012-11-14 20:32:19701 routing_id_ = params->routing_id;
702 surface_id_ = params->surface_id;
703 if (params->opener_id != MSG_ROUTING_NONE && params->is_renderer_created)
704 opener_id_ = params->opener_id;
[email protected]676126f72011-01-15 00:03:51705
[email protected]74ce1ad2011-12-16 21:51:46706 // Ensure we start with a valid next_page_id_ from the browser.
707 DCHECK_GE(next_page_id_, 0);
708
[email protected]8eae0802014-06-02 21:35:55709 main_render_frame_.reset(RenderFrameImpl::Create(
710 this, params->main_frame_routing_id));
[email protected]34f288c2014-04-28 16:25:37711 // The main frame WebLocalFrame object is closed by
712 // RenderFrameImpl::frameDetached().
[email protected]8eae0802014-06-02 21:35:55713 WebLocalFrame* web_frame = WebLocalFrame::create(main_render_frame_.get());
714 main_render_frame_->SetWebFrame(web_frame);
[email protected]34f288c2014-04-28 16:25:37715
[email protected]11fee2332011-03-29 20:36:35716 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11717 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35718
[email protected]20657a82012-08-21 20:23:03719 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
720
[email protected]27c521a2013-05-29 20:44:32721 if (command_line.HasSwitch(switches::kStatsCollectionController))
722 stats_collection_observer_.reset(new StatsCollectionObserver(this));
723
[email protected]20657a82012-08-21 20:23:03724#if defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:03725 const std::string region_code =
726 command_line.HasSwitch(switches::kNetworkCountryIso)
727 ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso)
[email protected]74d9c5242014-05-01 05:10:03728 : net::android::GetTelephonyNetworkOperator();
[email protected]20657a82012-08-21 20:23:03729 content_detectors_.push_back(linked_ptr<ContentDetector>(
730 new AddressDetector()));
731 content_detectors_.push_back(linked_ptr<ContentDetector>(
732 new PhoneNumberDetector(region_code)));
733 content_detectors_.push_back(linked_ptr<ContentDetector>(
734 new EmailDetector()));
735#endif
736
[email protected]380244092011-10-07 17:26:27737 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51738 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47739 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51740 AddRef();
[email protected]b2db9272014-01-10 17:42:00741 if (RenderThreadImpl::current()) {
742 RenderThreadImpl::current()->WidgetCreated();
743 if (is_hidden_)
744 RenderThreadImpl::current()->WidgetHidden();
745 }
[email protected]676126f72011-01-15 00:03:51746
747 // If this is a popup, we must wait for the CreatingNew_ACK message before
748 // completing initialization. Otherwise, we can finish it now.
[email protected]6cd7c6b2012-10-25 03:26:23749 if (opener_id_ == MSG_ROUTING_NONE) {
[email protected]676126f72011-01-15 00:03:51750 did_show_ = true;
[email protected]fc4404d2012-11-07 19:53:30751 CompleteInit();
[email protected]676126f72011-01-15 00:03:51752 }
753
[email protected]34c61bd52011-05-02 19:38:33754 g_view_map.Get().insert(std::make_pair(webview(), this));
[email protected]058561b2012-12-03 06:48:22755 g_routing_id_view_map.Get().insert(std::make_pair(routing_id_, this));
[email protected]60051ec2012-06-08 22:40:57756 webview()->setDeviceScaleFactor(device_scale_factor_);
[email protected]b8ec1112014-08-17 20:09:10757 webview()->settings()->setPreferCompositingToLCDTextEnabled(
758 PreferCompositingToLCDText(device_scale_factor_));
[email protected]d8221b22013-05-23 05:35:43759 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
760 ShouldUseTransitionCompositing(device_scale_factor_));
[email protected]fb854192013-02-06 01:30:04761
[email protected]49a20002013-08-18 12:43:31762 ApplyWebPreferences(webkit_preferences_, webview());
[email protected]9b159a52013-10-03 17:24:55763
[email protected]7fe71f02014-04-26 00:47:56764 webview()->settings()->setAllowConnectingInsecureWebSocket(
765 command_line.HasSwitch(switches::kAllowInsecureWebSocketFromHttpsOrigin));
766
[email protected]82307f6b2014-08-07 03:30:12767 RenderFrameProxy* proxy = NULL;
768 if (params->proxy_routing_id != MSG_ROUTING_NONE) {
769 CHECK(params->swapped_out);
770 proxy = RenderFrameProxy::CreateProxyToReplaceFrame(
771 main_render_frame_.get(), params->proxy_routing_id);
772 main_render_frame_->set_render_frame_proxy(proxy);
773 }
774
775 // In --site-per-process, just use the WebRemoteFrame as the main frame.
776 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
777 proxy) {
778 webview()->setMainFrame(proxy->web_frame());
779 } else {
780 webview()->setMainFrame(main_render_frame_->GetWebFrame());
781 }
[email protected]0287e762014-04-11 13:07:58782 main_render_frame_->Initialize();
[email protected]edbea622012-11-28 20:39:38783
[email protected]1400e6dc2013-04-27 02:36:27784 if (switches::IsTouchDragDropEnabled())
[email protected]edbea622012-11-28 20:39:38785 webview()->settings()->setTouchDragDropEnabled(true);
786
[email protected]1400e6dc2013-04-27 02:36:27787 if (switches::IsTouchEditingEnabled())
[email protected]47822262013-04-23 17:22:36788 webview()->settings()->setTouchEditingEnabled(true);
789
[email protected]8d41d7612012-11-14 20:32:19790 if (!params->frame_name.empty())
791 webview()->mainFrame()->setName(params->frame_name);
[email protected]34c61bd52011-05-02 19:38:33792
[email protected]c7c0d822014-04-16 20:19:49793 // TODO(davidben): Move this state from Blink into content.
794 if (params->window_was_created_with_opener)
795 webview()->setOpenedByDOM();
796
[email protected]8d41d7612012-11-14 20:32:19797 OnSetRendererPrefs(params->renderer_prefs);
[email protected]34c61bd52011-05-02 19:38:33798
[email protected]8f6a3b852011-07-19 16:48:56799 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32800#if defined(OS_MACOSX)
801 new TextInputClientObserver(this);
802#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56803
[email protected]217690d2012-01-27 07:33:11804 // The next group of objects all implement RenderViewObserver, so are deleted
805 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41806 devtools_agent_ = new DevToolsAgent(this);
[email protected]6e89eb72013-07-23 13:28:22807 if (RenderWidgetCompositor* rwc = compositor()) {
808 webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId());
809 }
[email protected]89054502012-06-03 10:29:24810 mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
[email protected]063afcb2011-09-29 07:54:32811
[email protected]d4734982014-04-15 02:05:55812 history_controller_.reset(new HistoryController(this));
813
[email protected]1784b2f2011-11-24 10:53:48814 new IdleUserDetector(this);
815
[email protected]766a7082012-02-03 23:39:15816 if (command_line.HasSwitch(switches::kDomAutomationController))
[email protected]e9ff79c2012-10-19 21:31:26817 enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION;
[email protected]27c521a2013-05-29 20:44:32818 if (command_line.HasSwitch(switches::kStatsCollectionController))
819 enabled_bindings_ |= BINDINGS_POLICY_STATS_COLLECTION;
[email protected]766a7082012-02-03 23:39:15820
[email protected]5b52cd2f712012-03-28 02:12:48821 ProcessViewLayoutFlags(command_line);
[email protected]7ddea9802012-02-22 23:08:05822
[email protected]e9ff79c2012-10-19 21:31:26823 GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44824
825 // If we have an opener_id but we weren't created by a renderer, then
826 // it's the browser asking us to set our opener to another RenderView.
[email protected]8d41d7612012-11-14 20:32:19827 if (params->opener_id != MSG_ROUTING_NONE && !params->is_renderer_created) {
828 RenderViewImpl* opener_view = FromRoutingID(params->opener_id);
[email protected]f546640b2012-05-15 00:03:49829 if (opener_view)
830 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
[email protected]14392a52012-05-02 20:28:44831 }
832
833 // If we are initially swapped out, navigate to kSwappedOutURL.
834 // This ensures we are in a unique origin that others cannot script.
[email protected]82307f6b2014-08-07 03:30:12835 if (is_swapped_out_ && webview()->mainFrame()->isWebLocalFrame())
[email protected]0720b532012-08-28 19:23:37836 NavigateToSwappedOutURL(webview()->mainFrame());
initial.commit09911bf2008-07-26 23:55:29837}
838
[email protected]310ebd6302011-10-10 19:06:28839RenderViewImpl::~RenderViewImpl() {
[email protected]cb189e062014-04-23 00:57:01840 for (BitmapMap::iterator it = disambiguation_bitmaps_.begin();
841 it != disambiguation_bitmaps_.end();
842 ++it)
843 delete it->second;
[email protected]d466b8a2011-07-15 21:48:03844 history_page_ids_.clear();
845
[email protected]91a2aea2013-07-08 23:14:39846 base::debug::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_);
847
[email protected]a1128322009-10-06 18:38:46848 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47849 while (!file_chooser_completions_.empty()) {
850 if (file_chooser_completions_.front()->completion) {
851 file_chooser_completions_.front()->completion->didChooseFile(
852 WebVector<WebString>());
853 }
854 file_chooser_completions_.pop_front();
855 }
[email protected]a1128322009-10-06 18:38:46856
[email protected]8ed1d3f2013-02-20 11:45:55857#if defined(OS_ANDROID)
858 // The date/time picker client is both a scoped_ptr member of this class and
859 // a RenderViewObserver. Reset it to prevent double deletion.
860 date_time_picker_client_.reset();
861#endif
862
[email protected]60c42a8c72009-10-09 04:08:59863#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22864 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49865 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59866 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
867 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22868 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
869 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
870 it != routing_id_views->end(); ++it)
871 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59872#endif
[email protected]676126f72011-01-15 00:03:51873
[email protected]310ebd6302011-10-10 19:06:28874 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51875 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59876}
877
878/*static*/
[email protected]310ebd6302011-10-10 19:06:28879RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31880 ViewMap* views = g_view_map.Pointer();
881 ViewMap::iterator it = views->find(webview);
882 return it == views->end() ? NULL : it->second;
883}
884
885/*static*/
[email protected]180ef242013-11-07 06:50:46886RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28887 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31888}
889
890/*static*/
[email protected]640e303c2012-12-05 01:36:07891RenderViewImpl* RenderViewImpl::FromRoutingID(int32 routing_id) {
892 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
893 RoutingIDViewMap::iterator it = views->find(routing_id);
894 return it == views->end() ? NULL : it->second;
895}
896
897/*static*/
898RenderView* RenderView::FromRoutingID(int routing_id) {
899 return RenderViewImpl::FromRoutingID(routing_id);
900}
901
[email protected]f3a95312014-06-12 16:46:58902/* static */
903size_t RenderViewImpl::GetRenderViewCount() {
904 return g_view_map.Get().size();
905}
906
[email protected]640e303c2012-12-05 01:36:07907/*static*/
[email protected]e9ff79c2012-10-19 21:31:26908void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49909 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59910 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
911 if (!visitor->Visit(it->second))
912 return;
913 }
914}
915
916/*static*/
[email protected]b3a97b52014-07-09 06:25:05917void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
918 WebView* web_view) {
919 WebSettings* settings = web_view->settings();
920 ApplyFontsFromMap(prefs.standard_font_family_map,
921 SetStandardFontFamilyWrapper, settings);
922 ApplyFontsFromMap(prefs.fixed_font_family_map,
923 SetFixedFontFamilyWrapper, settings);
924 ApplyFontsFromMap(prefs.serif_font_family_map,
925 SetSerifFontFamilyWrapper, settings);
926 ApplyFontsFromMap(prefs.sans_serif_font_family_map,
927 SetSansSerifFontFamilyWrapper, settings);
928 ApplyFontsFromMap(prefs.cursive_font_family_map,
929 SetCursiveFontFamilyWrapper, settings);
930 ApplyFontsFromMap(prefs.fantasy_font_family_map,
931 SetFantasyFontFamilyWrapper, settings);
932 ApplyFontsFromMap(prefs.pictograph_font_family_map,
933 SetPictographFontFamilyWrapper, settings);
934 settings->setDefaultFontSize(prefs.default_font_size);
935 settings->setDefaultFixedFontSize(prefs.default_fixed_font_size);
936 settings->setMinimumFontSize(prefs.minimum_font_size);
937 settings->setMinimumLogicalFontSize(prefs.minimum_logical_font_size);
938 settings->setDefaultTextEncodingName(
939 base::ASCIIToUTF16(prefs.default_encoding));
940 settings->setJavaScriptEnabled(prefs.javascript_enabled);
941 settings->setWebSecurityEnabled(prefs.web_security_enabled);
942 settings->setJavaScriptCanOpenWindowsAutomatically(
943 prefs.javascript_can_open_windows_automatically);
944 settings->setLoadsImagesAutomatically(prefs.loads_images_automatically);
945 settings->setImagesEnabled(prefs.images_enabled);
946 settings->setPluginsEnabled(prefs.plugins_enabled);
947 settings->setDOMPasteAllowed(prefs.dom_paste_enabled);
[email protected]b3a97b52014-07-09 06:25:05948 settings->setShrinksStandaloneImagesToFit(
949 prefs.shrinks_standalone_images_to_fit);
950 settings->setUsesEncodingDetector(prefs.uses_universal_detector);
951 settings->setTextAreasAreResizable(prefs.text_areas_are_resizable);
952 settings->setAllowScriptsToCloseWindows(prefs.allow_scripts_to_close_windows);
953 settings->setDownloadableBinaryFontsEnabled(prefs.remote_fonts_enabled);
954 settings->setJavaScriptCanAccessClipboard(
955 prefs.javascript_can_access_clipboard);
956 WebRuntimeFeatures::enableXSLT(prefs.xslt_enabled);
957 settings->setXSSAuditorEnabled(prefs.xss_auditor_enabled);
958 settings->setDNSPrefetchingEnabled(prefs.dns_prefetching_enabled);
959 settings->setLocalStorageEnabled(prefs.local_storage_enabled);
960 settings->setSyncXHRInDocumentsEnabled(prefs.sync_xhr_in_documents_enabled);
961 WebRuntimeFeatures::enableDatabase(prefs.databases_enabled);
962 settings->setOfflineWebApplicationCacheEnabled(
963 prefs.application_cache_enabled);
964 settings->setCaretBrowsingEnabled(prefs.caret_browsing_enabled);
965 settings->setHyperlinkAuditingEnabled(prefs.hyperlink_auditing_enabled);
966 settings->setCookieEnabled(prefs.cookie_enabled);
967 settings->setNavigateOnDragDrop(prefs.navigate_on_drag_drop);
968
969 settings->setJavaEnabled(prefs.java_enabled);
970
971 // By default, allow_universal_access_from_file_urls is set to false and thus
972 // we mitigate attacks from local HTML files by not granting file:// URLs
973 // universal access. Only test shell will enable this.
974 settings->setAllowUniversalAccessFromFileURLs(
975 prefs.allow_universal_access_from_file_urls);
976 settings->setAllowFileAccessFromFileURLs(
977 prefs.allow_file_access_from_file_urls);
978
979 // Enable the web audio API if requested on the command line.
980 settings->setWebAudioEnabled(prefs.webaudio_enabled);
981
982 // Enable experimental WebGL support if requested on command line
983 // and support is compiled in.
984 settings->setExperimentalWebGLEnabled(prefs.experimental_webgl_enabled);
985
986 // Disable GL multisampling if requested on command line.
987 settings->setOpenGLMultisamplingEnabled(prefs.gl_multisampling_enabled);
988
989 // Enable WebGL errors to the JS console if requested.
990 settings->setWebGLErrorsToConsoleEnabled(
991 prefs.webgl_errors_to_console_enabled);
992
993 // Uses the mock theme engine for scrollbars.
994 settings->setMockScrollbarsEnabled(prefs.mock_scrollbars_enabled);
995
996 settings->setLayerSquashingEnabled(prefs.layer_squashing_enabled);
997
[email protected]b3a97b52014-07-09 06:25:05998 // Enable gpu-accelerated 2d canvas if requested on the command line.
999 settings->setAccelerated2dCanvasEnabled(prefs.accelerated_2d_canvas_enabled);
1000
1001 settings->setMinimumAccelerated2dCanvasSize(
1002 prefs.minimum_accelerated_2d_canvas_size);
1003
1004 // Disable antialiasing for 2d canvas if requested on the command line.
1005 settings->setAntialiased2dCanvasEnabled(
1006 !prefs.antialiased_2d_canvas_disabled);
1007
1008 // Set MSAA sample count for 2d canvas if requested on the command line (or
1009 // default value if not).
1010 settings->setAccelerated2dCanvasMSAASampleCount(
1011 prefs.accelerated_2d_canvas_msaa_sample_count);
1012
1013 // Enable deferred filter rendering if requested on the command line.
1014 settings->setDeferredFiltersEnabled(prefs.deferred_filters_enabled);
1015
1016 // Enable container culling if requested on the command line.
1017 settings->setContainerCullingEnabled(prefs.container_culling_enabled);
1018
[email protected]b3a97b52014-07-09 06:25:051019 settings->setAsynchronousSpellCheckingEnabled(
1020 prefs.asynchronous_spell_checking_enabled);
1021 settings->setUnifiedTextCheckerEnabled(prefs.unified_textchecker_enabled);
1022
[email protected]b3a97b52014-07-09 06:25:051023 // Tabs to link is not part of the settings. WebCore calls
1024 // ChromeClient::tabsToLinks which is part of the glue code.
1025 web_view->setTabsToLinks(prefs.tabs_to_links);
1026
1027 settings->setAllowDisplayOfInsecureContent(
1028 prefs.allow_displaying_insecure_content);
1029 settings->setAllowRunningOfInsecureContent(
1030 prefs.allow_running_insecure_content);
1031 settings->setPasswordEchoEnabled(prefs.password_echo_enabled);
1032 settings->setShouldPrintBackgrounds(prefs.should_print_backgrounds);
1033 settings->setShouldClearDocumentBackground(
1034 prefs.should_clear_document_background);
1035 settings->setEnableScrollAnimator(prefs.enable_scroll_animator);
1036
1037 settings->setRegionBasedColumnsEnabled(prefs.region_based_columns_enabled);
1038
1039 WebRuntimeFeatures::enableTouch(prefs.touch_enabled);
1040 settings->setMaxTouchPoints(prefs.pointer_events_max_touch_points);
1041 settings->setDeviceSupportsTouch(prefs.device_supports_touch);
1042 settings->setDeviceSupportsMouse(prefs.device_supports_mouse);
1043 settings->setEnableTouchAdjustment(prefs.touch_adjustment_enabled);
1044
1045 settings->setDeferredImageDecodingEnabled(
1046 prefs.deferred_image_decoding_enabled);
1047 settings->setShouldRespectImageOrientation(
1048 prefs.should_respect_image_orientation);
1049
1050 settings->setUnsafePluginPastingEnabled(false);
1051 settings->setEditingBehavior(
1052 static_cast<WebSettings::EditingBehavior>(prefs.editing_behavior));
1053
1054 settings->setSupportsMultipleWindows(prefs.supports_multiple_windows);
1055
1056 settings->setViewportEnabled(prefs.viewport_enabled);
1057 settings->setLoadWithOverviewMode(prefs.initialize_at_minimum_page_scale);
1058 settings->setViewportMetaEnabled(prefs.viewport_meta_enabled);
1059 settings->setMainFrameResizesAreOrientationChanges(
1060 prefs.main_frame_resizes_are_orientation_changes);
1061
1062 settings->setSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
1063
1064 settings->setSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
1065
1066 settings->setSelectionIncludesAltImageText(true);
1067
[email protected]35103c02014-08-12 15:08:471068 settings->setV8CacheOptions(
1069 static_cast<WebSettings::V8CacheOptions>(prefs.v8_cache_options));
1070
[email protected]b3a97b52014-07-09 06:25:051071#if defined(OS_ANDROID)
1072 settings->setAllowCustomScrollbarInMainFrame(false);
1073 settings->setTextAutosizingEnabled(prefs.text_autosizing_enabled);
1074 settings->setAccessibilityFontScaleFactor(prefs.font_scale_factor);
1075 settings->setDeviceScaleAdjustment(prefs.device_scale_adjustment);
[email protected]9f1418ca2014-07-29 14:03:241076 settings->setDisallowFullscreenForNonMediaElements(
1077 prefs.disallow_fullscreen_for_non_media_elements);
[email protected]023fed312014-08-11 16:13:051078 settings->setFullscreenSupported(prefs.fullscreen_supported);
[email protected]b3a97b52014-07-09 06:25:051079 web_view->setIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
1080 settings->setAutoZoomFocusedNodeToLegibleScale(true);
1081 settings->setDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
1082 settings->setMediaControlsOverlayPlayButtonEnabled(true);
1083 settings->setMediaPlaybackRequiresUserGesture(
1084 prefs.user_gesture_required_for_media_playback);
1085 settings->setDefaultVideoPosterURL(
1086 base::ASCIIToUTF16(prefs.default_video_poster_url.spec()));
1087 settings->setSupportDeprecatedTargetDensityDPI(
1088 prefs.support_deprecated_target_density_dpi);
1089 settings->setUseLegacyBackgroundSizeShorthandBehavior(
1090 prefs.use_legacy_background_size_shorthand_behavior);
1091 settings->setWideViewportQuirkEnabled(prefs.wide_viewport_quirk);
1092 settings->setUseWideViewport(prefs.use_wide_viewport);
[email protected]9954ea92014-08-12 15:48:451093 settings->setForceZeroLayoutHeight(prefs.force_zero_layout_height);
[email protected]b3a97b52014-07-09 06:25:051094 settings->setViewportMetaLayoutSizeQuirk(
1095 prefs.viewport_meta_layout_size_quirk);
1096 settings->setViewportMetaMergeContentQuirk(
1097 prefs.viewport_meta_merge_content_quirk);
1098 settings->setViewportMetaNonUserScalableQuirk(
1099 prefs.viewport_meta_non_user_scalable_quirk);
1100 settings->setViewportMetaZeroValuesQuirk(
1101 prefs.viewport_meta_zero_values_quirk);
1102 settings->setClobberUserAgentInitialScaleQuirk(
1103 prefs.clobber_user_agent_initial_scale_quirk);
1104 settings->setIgnoreMainFrameOverflowHiddenQuirk(
1105 prefs.ignore_main_frame_overflow_hidden_quirk);
1106 settings->setReportScreenSizeInPhysicalPixelsQuirk(
1107 prefs.report_screen_size_in_physical_pixels_quirk);
1108 settings->setMainFrameClipsContent(false);
1109 settings->setShrinksStandaloneImagesToFit(false);
1110 settings->setShrinksViewportContentToFit(true);
1111#endif
1112
1113 WebNetworkStateNotifier::setOnLine(prefs.is_online);
1114 WebNetworkStateNotifier::setWebConnectionType(
1115 NetConnectionTypeToWebConnectionType(prefs.connection_type));
1116 settings->setPinchVirtualViewportEnabled(
1117 prefs.pinch_virtual_viewport_enabled);
1118
1119 settings->setPinchOverlayScrollbarThickness(
1120 prefs.pinch_overlay_scrollbar_thickness);
1121 settings->setUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
[email protected]b3a97b52014-07-09 06:25:051122}
1123
1124/*static*/
[email protected]310ebd6302011-10-10 19:06:281125RenderViewImpl* RenderViewImpl::Create(
[email protected]0aa55312008-10-17 21:53:081126 int32 opener_id,
[email protected]c7c0d822014-04-16 20:19:491127 bool window_was_created_with_opener,
[email protected]e9ff79c2012-10-19 21:31:261128 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:081129 const WebPreferences& webkit_prefs,
[email protected]4e6419c2010-01-15 04:50:341130 int32 routing_id,
[email protected]227692c52013-05-31 22:43:041131 int32 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:561132 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:261133 int64 session_storage_namespace_id,
[email protected]fcf75d42013-12-03 20:11:261134 const base::string16& frame_name,
[email protected]14392a52012-05-02 20:28:441135 bool is_renderer_created,
1136 bool swapped_out,
[email protected]5a7100d2014-05-19 01:29:041137 int32 proxy_routing_id,
[email protected]1ac10dca2013-08-20 20:47:041138 bool hidden,
[email protected]7912e822014-04-16 02:37:031139 bool never_visible,
[email protected]6fd35b72012-03-01 19:46:411140 int32 next_page_id,
[email protected]95640212014-07-26 18:14:301141 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:291142 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]f2c530d2014-02-20 20:15:301143 RenderViewImplParams params(opener_id,
[email protected]c7c0d822014-04-16 20:19:491144 window_was_created_with_opener,
[email protected]f2c530d2014-02-20 20:15:301145 renderer_prefs,
1146 webkit_prefs,
1147 routing_id,
1148 main_frame_routing_id,
1149 surface_id,
1150 session_storage_namespace_id,
1151 frame_name,
1152 is_renderer_created,
1153 swapped_out,
[email protected]5a7100d2014-05-19 01:29:041154 proxy_routing_id,
[email protected]f2c530d2014-02-20 20:15:301155 hidden,
[email protected]7912e822014-04-16 02:37:031156 never_visible,
[email protected]f2c530d2014-02-20 20:15:301157 next_page_id,
[email protected]95640212014-07-26 18:14:301158 screen_info);
[email protected]075366912013-02-18 07:13:241159 RenderViewImpl* render_view = NULL;
[email protected]8d41d7612012-11-14 20:32:191160 if (g_create_render_view_impl)
[email protected]075366912013-02-18 07:13:241161 render_view = g_create_render_view_impl(&params);
1162 else
1163 render_view = new RenderViewImpl(&params);
[email protected]0287e762014-04-11 13:07:581164
[email protected]34f288c2014-04-28 16:25:371165 render_view->Initialize(&params);
[email protected]075366912013-02-18 07:13:241166 return render_view;
[email protected]8d41d7612012-11-14 20:32:191167}
1168
1169// static
1170void RenderViewImpl::InstallCreateHook(
1171 RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*)) {
1172 CHECK(!g_create_render_view_impl);
1173 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291174}
1175
[email protected]310ebd6302011-10-10 19:06:281176void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511177 observers_.AddObserver(observer);
1178}
1179
[email protected]310ebd6302011-10-10 19:06:281180void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1181 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511182 observers_.RemoveObserver(observer);
1183}
1184
[email protected]180ef242013-11-07 06:50:461185blink::WebView* RenderViewImpl::webview() const {
1186 return static_cast<blink::WebView*>(webwidget());
[email protected]4d51d5bf2010-07-26 18:48:261187}
1188
[email protected]ea2fb972013-08-07 05:44:261189#if defined(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:571190void RenderViewImpl::PepperInstanceCreated(
1191 PepperPluginInstanceImpl* instance) {
1192 active_pepper_instances_.insert(instance);
1193}
1194
1195void RenderViewImpl::PepperInstanceDeleted(
1196 PepperPluginInstanceImpl* instance) {
1197 active_pepper_instances_.erase(instance);
1198
1199 if (pepper_last_mouse_event_target_ == instance)
1200 pepper_last_mouse_event_target_ = NULL;
1201 if (focused_pepper_plugin_ == instance)
1202 PepperFocusChanged(instance, false);
1203}
1204
1205void RenderViewImpl::PepperFocusChanged(PepperPluginInstanceImpl* instance,
1206 bool focused) {
1207 if (focused)
1208 focused_pepper_plugin_ = instance;
1209 else if (focused_pepper_plugin_ == instance)
1210 focused_pepper_plugin_ = NULL;
1211
[email protected]2dd467c52014-06-12 14:26:431212 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
[email protected]a99a38802014-01-14 15:46:571213 UpdateSelectionBounds();
1214}
1215
[email protected]310ebd6302011-10-10 19:06:281216void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:261217 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:301218 // If the renderer is visible, set initial visibility and focus state.
1219 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:341220#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:301221 delegate->SetContainerVisibility(true);
1222 if (webview() && webview()->isActive())
1223 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:341224#endif
[email protected]49232292010-09-03 19:07:301225 }
[email protected]784ea1ab2010-09-18 00:02:341226 // Plugins start assuming the content has focus (so that they work in
1227 // environments where RenderView isn't hosting them), so we always have to
1228 // set the initial state. See webplugin_delegate_impl.h for details.
1229 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:261230}
1231
[email protected]310ebd6302011-10-10 19:06:281232void RenderViewImpl::UnregisterPluginDelegate(
1233 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:261234 plugin_delegates_.erase(delegate);
1235}
[email protected]d8fd6fa2010-02-01 15:54:261236
[email protected]a80af12e2013-08-07 23:36:131237#if defined(OS_WIN)
1238void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
1239 if (focused)
1240 focused_plugin_id_ = plugin_id;
1241 else
1242 focused_plugin_id_ = -1;
1243}
1244#endif
1245
1246#if defined(OS_MACOSX)
1247void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
1248 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
1249}
1250
[email protected]7411a3c2014-08-15 05:20:191251void RenderViewImpl::OnGetRenderedText() {
1252 if (!webview())
1253 return;
1254 // Get rendered text from WebLocalFrame.
1255 // TODO: Currently IPC truncates any data that has a
1256 // size > kMaximumMessageSize. May be split the text into smaller chunks and
1257 // send back using multiple IPC. See http://crbug.com/393444.
1258 static const size_t kMaximumMessageSize = 8 * 1024 * 1024;
1259 std::string text = webview()->mainFrame()->contentAsText(
1260 kMaximumMessageSize).utf8();
1261
1262 Send(new ViewMsg_GetRenderedTextCompleted(routing_id(), text));
1263}
1264
[email protected]a80af12e2013-08-07 23:36:131265void RenderViewImpl::StartPluginIme() {
1266 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
1267 // This message can be sent during event-handling, and needs to be delivered
1268 // within that context.
1269 msg->set_unblock(true);
1270 Send(msg);
1271}
1272#endif // defined(OS_MACOSX)
1273
1274#endif // ENABLE_PLUGINS
1275
[email protected]7a1ec28a2012-03-28 21:10:241276void RenderViewImpl::TransferActiveWheelFlingAnimation(
[email protected]180ef242013-11-07 06:50:461277 const blink::WebActiveWheelFlingParameters& params) {
[email protected]7a1ec28a2012-03-28 21:10:241278 if (webview())
1279 webview()->transferActiveWheelFlingAnimation(params);
1280}
1281
[email protected]8fe8f742012-06-14 00:36:081282bool RenderViewImpl::HasIMETextFocus() {
1283 return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
1284}
1285
[email protected]310ebd6302011-10-10 19:06:281286bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:271287 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]82307f6b2014-08-07 03:30:121288 if (main_frame && main_frame->isWebLocalFrame())
[email protected]e9ff79c2012-10-19 21:31:261289 GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:261290
[email protected]676126f72011-01-15 00:03:511291 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
1292 RenderViewObserver* observer;
1293 while ((observer = it.GetNext()) != NULL)
1294 if (observer->OnMessageReceived(message))
1295 return true;
[email protected]b2abac72009-02-26 12:39:281296
[email protected]a95986a82010-12-24 06:19:281297 bool handled = true;
[email protected]e44d1342014-05-16 21:29:331298 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
[email protected]c084330e02013-04-27 01:08:151299 IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand)
1300 IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret)
[email protected]c084330e02013-04-27 01:08:151301 IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect,
1302 OnScrollFocusedEditableNodeIntoRect)
[email protected]c084330e02013-04-27 01:08:151303 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
1304 OnSetEditCommandsForNextKeyEvent)
initial.commit09911bf2008-07-26 23:55:291305 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]6a6fa3e2014-05-09 06:57:181306 IPC_MESSAGE_HANDLER(ViewMsg_SaveImageAt, OnSaveImageAt)
initial.commit09911bf2008-07-26 23:55:291307 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:491308 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
[email protected]630e26b2008-10-14 22:55:171309 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:541310 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1311 OnSetZoomLevelForLoadingURL)
[email protected]d42bf472014-06-14 01:49:381312 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForView,
1313 OnSetZoomLevelForView)
initial.commit09911bf2008-07-26 23:55:291314 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:181315 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1316 OnResetPageEncodingToDefault)
[email protected]f546640b2012-05-15 00:03:491317 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
[email protected]59f4f2fa2011-03-23 01:00:551318 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
1319 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
1320 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
1321 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
[email protected]7a6d773f2014-04-04 01:25:091322 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
[email protected]59f4f2fa2011-03-23 01:00:551323 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
1324 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:451325 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:291326 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291327 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1328 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]600ea402011-04-12 00:01:511329 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
1330 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:291331 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]88f10a22013-11-06 21:22:121332 IPC_MESSAGE_HANDLER(ViewMsg_SuppressDialogsUntilSwapOut,
1333 OnSuppressDialogsUntilSwapOut)
initial.commit09911bf2008-07-26 23:55:291334 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1335 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]30f75e62009-02-25 22:01:001336 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]ab6c9112014-02-27 00:20:581337 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedElement, OnClearFocusedElement)
[email protected]61f91832014-05-13 01:24:421338 IPC_MESSAGE_HANDLER(ViewMsg_SetBackgroundOpaque, OnSetBackgroundOpaque)
[email protected]ab32b16c2009-10-16 14:57:251339 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1340 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:471341 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:341342 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:101343 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1344 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511345 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:561346 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:361347 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:341348 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]18d5be92011-07-25 18:00:191349 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1350 OnGetAllSavableResourceLinksForCurrentPage)
1351 IPC_MESSAGE_HANDLER(
1352 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1353 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]47822262013-04-23 17:22:361354 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
[email protected]f0557932011-01-25 20:20:511355 // TODO(viettrungluu): Move to a separate message filter.
[email protected]9e1ad4b2011-08-14 16:49:191356 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
1357 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:181358 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]cb189e062014-04-23 00:57:011359 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupBitmap,
1360 OnReleaseDisambiguationPopupBitmap)
[email protected]a794f3a2013-10-30 17:00:321361 IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted,
1362 OnWindowSnapshotCompleted)
[email protected]506563d2014-06-23 12:22:411363 IPC_MESSAGE_HANDLER(ViewMsg_ForceRedraw, OnForceRedraw)
[email protected]4dda6a6c2014-05-17 15:35:041364 IPC_MESSAGE_HANDLER(ViewMsg_SelectWordAroundCaret, OnSelectWordAroundCaret)
[email protected]55750b32012-09-21 14:05:031365#if defined(OS_ANDROID)
[email protected]c084330e02013-04-27 01:08:151366 IPC_MESSAGE_HANDLER(InputMsg_ActivateNearestFindResult,
[email protected]55750b32012-09-21 14:05:031367 OnActivateNearestFindResult)
1368 IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects)
[email protected]452b4a92013-03-28 21:24:381369 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState,
1370 OnUpdateTopControlsState)
[email protected]c4790dcb2013-12-27 22:08:021371 IPC_MESSAGE_HANDLER(ViewMsg_ExtractSmartClipData, OnExtractSmartClipData)
[email protected]55750b32012-09-21 14:05:031372#elif defined(OS_MACOSX)
[email protected]7411a3c2014-08-15 05:20:191373 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedText,
1374 OnGetRenderedText)
[email protected]55750b32012-09-21 14:05:031375 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1376 OnPluginImeCompositionCompleted)
[email protected]55750b32012-09-21 14:05:031377 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
1378 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
1379 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
1380#endif
[email protected]a794f3a2013-10-30 17:00:321381 // Adding a new message? Add platform independent ones first, then put the
1382 // platform specific ones at the end.
[email protected]9e1ad4b2011-08-14 16:49:191383
initial.commit09911bf2008-07-26 23:55:291384 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281385 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291386 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401387
[email protected]a95986a82010-12-24 06:19:281388 return handled;
initial.commit09911bf2008-07-26 23:55:291389}
1390
[email protected]4dda6a6c2014-05-17 15:35:041391void RenderViewImpl::OnSelectWordAroundCaret() {
1392 if (!webview())
1393 return;
1394
1395 handling_input_event_ = true;
1396 webview()->focusedFrame()->selectWordAroundCaret();
1397 handling_input_event_ = false;
1398}
1399
[email protected]310ebd6302011-10-10 19:06:281400bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]c6bc20332014-02-28 18:30:391401 const FrameMsg_Navigate_Params& params,
[email protected]d466b8a2011-07-15 21:48:031402 bool is_reload) {
1403 // Make sure this isn't a back/forward to an entry we have already cropped
1404 // or replaced from our history, before the browser knew about it. If so,
1405 // a new navigation has committed in the mean time, and we can ignore this.
[email protected]691aa2f2013-05-28 22:52:041406 bool is_back_forward = !is_reload && params.page_state.IsValid();
[email protected]d466b8a2011-07-15 21:48:031407
1408 // Note: if the history_list_length_ is 0 for a back/forward, we must be
1409 // restoring from a previous session. We'll update our state in OnNavigate.
1410 if (!is_back_forward || history_list_length_ <= 0)
1411 return false;
1412
1413 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
1414
1415 // Check for whether the forward history has been cropped due to a recent
1416 // navigation the browser didn't know about.
1417 if (params.pending_history_list_offset >= history_list_length_)
1418 return true;
1419
1420 // Check for whether this entry has been replaced with a new one.
1421 int expected_page_id =
1422 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:441423 if (expected_page_id > 0 && params.page_id != expected_page_id) {
1424 if (params.page_id < expected_page_id)
1425 return true;
1426
1427 // Otherwise we've removed an earlier entry and should have shifted all
1428 // entries left. For now, it's ok to lazily update the list.
1429 // TODO(creis): Notify all live renderers when we remove entries from
1430 // the front of the list, so that we don't hit this case.
1431 history_page_ids_[params.pending_history_list_offset] = params.page_id;
1432 }
[email protected]d466b8a2011-07-15 21:48:031433
1434 return false;
1435}
1436
[email protected]310ebd6302011-10-10 19:06:281437void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271438 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291439}
1440
[email protected]6a6fa3e2014-05-09 06:57:181441void RenderViewImpl::OnSaveImageAt(int x, int y) {
1442 webview()->saveImageAt(WebPoint(x, y));
1443}
1444
[email protected]310ebd6302011-10-10 19:06:281445void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291446 // Check if there is a targeturl waiting to be sent.
1447 if (target_url_status_ == TARGET_PENDING) {
1448 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1449 pending_target_url_));
1450 }
1451
1452 target_url_status_ = TARGET_NONE;
1453}
1454
[email protected]c084330e02013-04-27 01:08:151455void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
1456 const std::string& value) {
1457 if (!webview() || !webview()->focusedFrame())
1458 return;
1459
1460 webview()->focusedFrame()->executeCommand(
1461 WebString::fromUTF8(name), WebString::fromUTF8(value));
1462}
1463
1464void RenderViewImpl::OnMoveCaret(const gfx::Point& point) {
1465 if (!webview())
1466 return;
1467
1468 Send(new ViewHostMsg_MoveCaret_ACK(routing_id_));
1469
[email protected]b74d4064d2013-11-27 01:45:091470 webview()->focusedFrame()->moveCaretSelection(point);
[email protected]c084330e02013-04-27 01:08:151471}
[email protected]a954bf72009-09-12 07:30:351472
[email protected]c084330e02013-04-27 01:08:151473void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1474 const gfx::Rect& rect) {
[email protected]1875bc02014-03-14 06:33:591475 if (has_scrolled_focused_editable_node_into_rect_ &&
1476 rect == rect_for_scrolled_focused_editable_node_) {
1477 return;
1478 }
1479
[email protected]c39f7442014-02-27 03:33:171480 blink::WebElement element = GetFocusedElement();
[email protected]1875bc02014-03-14 06:33:591481 if (!element.isNull() && IsEditableNode(element)) {
1482 rect_for_scrolled_focused_editable_node_ = rect;
1483 has_scrolled_focused_editable_node_into_rect_ = true;
1484 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]c084330e02013-04-27 01:08:151485 }
[email protected]25bcc8f2013-01-09 02:49:251486}
1487
[email protected]c084330e02013-04-27 01:08:151488void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
1489 const EditCommands& edit_commands) {
1490 edit_commands_ = edit_commands;
1491}
1492
[email protected]310ebd6302011-10-10 19:06:281493void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1494 int32 minimum_page_id) {
[email protected]e1ed5a12012-08-08 19:57:441495 DCHECK_GE(history_length, 0);
[email protected]9e1ad4b2011-08-14 16:49:191496 DCHECK(history_list_offset_ == history_list_length_ - 1);
[email protected]e1ed5a12012-08-08 19:57:441497 DCHECK_GE(minimum_page_id, -1);
[email protected]9e1ad4b2011-08-14 16:49:191498
1499 // Generate the new list.
1500 std::vector<int32> new_history_page_ids(history_length, -1);
1501 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1502 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1503 continue;
1504 new_history_page_ids.push_back(history_page_ids_[i]);
1505 }
1506 new_history_page_ids.swap(history_page_ids_);
1507
1508 // Update indexes.
1509 history_list_length_ = history_page_ids_.size();
1510 history_list_offset_ = history_list_length_ - 1;
1511}
1512
1513
[email protected]310ebd6302011-10-10 19:06:281514void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291515 if (!webview())
1516 return;
[email protected]26aa0482009-09-30 16:55:271517 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291518}
1519
[email protected]54ca3ca892011-06-07 21:14:541520#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281521void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331522 if (!webview())
1523 return;
1524 if (in_live_resize)
1525 webview()->willStartLiveResize();
1526 else
1527 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541528}
1529#endif
1530
initial.commit09911bf2008-07-26 23:55:291531///////////////////////////////////////////////////////////////////////////////
1532
[email protected]b4c0aec2014-05-17 16:02:481533// Sends the current history state to the browser so it will be saved before we
1534// navigate to a new page.
[email protected]310ebd6302011-10-10 19:06:281535void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291536 // If we have a valid page ID at this point, then it corresponds to the page
1537 // we are navigating away from. Otherwise, this is the first navigation, so
1538 // there is no past session history to record.
1539 if (page_id_ == -1)
1540 return;
[email protected]b4c0aec2014-05-17 16:02:481541 SendUpdateState(history_controller_->GetCurrentEntry());
[email protected]6459800a2012-03-27 23:57:051542}
1543
[email protected]9cd14ef2014-04-30 18:26:031544void RenderViewImpl::SendUpdateState(HistoryEntry* entry) {
1545 if (!entry)
initial.commit09911bf2008-07-26 23:55:291546 return;
[email protected]ca948a22009-06-25 19:36:171547
[email protected]e9ff79c2012-10-19 21:31:261548 // Don't send state updates for kSwappedOutURL.
[email protected]9cd14ef2014-04-30 18:26:031549 if (entry->root().urlString() == WebString::fromUTF8(kSwappedOutURL))
[email protected]6459800a2012-03-27 23:57:051550 return;
1551
[email protected]ca948a22009-06-25 19:36:171552 Send(new ViewHostMsg_UpdateState(
[email protected]9cd14ef2014-04-30 18:26:031553 routing_id_, page_id_, HistoryEntryToPageState(entry)));
initial.commit09911bf2008-07-26 23:55:291554}
1555
[email protected]310ebd6302011-10-10 19:06:281556bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571557 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1558 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1559 // it is particularly important that we do not call willEnterModalLoop as
1560 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441561 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1562 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571563
1564 message->EnableMessagePumping(); // Runs a nested message loop.
1565 return Send(message);
1566}
1567
[email protected]c9bc8f12012-12-15 22:20:091568void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) {
1569 int id = next_snapshot_id_++;
1570 pending_snapshots_.insert(std::make_pair(id, callback));
[email protected]7d08a9352013-10-15 08:24:561571 ui::LatencyInfo latency_info;
[email protected]506563d2014-06-23 12:22:411572 latency_info.AddLatencyNumber(ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT,
1573 0,
1574 id);
1575 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
1576 if (RenderWidgetCompositor* rwc = compositor()) {
1577 latency_info_swap_promise_monitor =
1578 rwc->CreateLatencyInfoSwapPromiseMonitor(&latency_info).Pass();
1579 }
1580 ScheduleCompositeWithForcedRedraw();
1581}
1582
1583void RenderViewImpl::OnForceRedraw(int id) {
1584 ui::LatencyInfo latency_info;
[email protected]f9f3fac2014-08-05 00:47:591585 if (id) {
1586 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
1587 0,
1588 id);
1589 }
[email protected]6be422b2013-12-08 06:47:311590 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]7d08a9352013-10-15 08:24:561591 if (RenderWidgetCompositor* rwc = compositor()) {
[email protected]6be422b2013-12-08 06:47:311592 latency_info_swap_promise_monitor =
1593 rwc->CreateLatencyInfoSwapPromiseMonitor(&latency_info).Pass();
[email protected]7d08a9352013-10-15 08:24:561594 }
1595 ScheduleCompositeWithForcedRedraw();
[email protected]c9bc8f12012-12-15 22:20:091596}
1597
1598void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id,
1599 const gfx::Size& size, const std::vector<unsigned char>& png) {
[email protected]7d08a9352013-10-15 08:24:561600
1601 // Any pending snapshots with a lower ID than the one received are considered
1602 // to be implicitly complete, and returned the same snapshot data.
1603 PendingSnapshotMap::iterator it = pending_snapshots_.begin();
1604 while(it != pending_snapshots_.end()) {
1605 if (it->first <= snapshot_id) {
1606 it->second.Run(size, png);
1607 pending_snapshots_.erase(it++);
1608 } else {
1609 ++it;
1610 }
1611 }
[email protected]c9bc8f12012-12-15 22:20:091612}
1613
[email protected]180ef242013-11-07 06:50:461614// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521615
[email protected]35b2a972014-04-04 15:50:221616WebView* RenderViewImpl::createView(WebLocalFrame* creator,
1617 const WebURLRequest& request,
1618 const WebWindowFeatures& features,
1619 const WebString& frame_name,
1620 WebNavigationPolicy policy,
1621 bool suppress_opener) {
[email protected]8ab04652010-06-12 02:47:261622 ViewHostMsg_CreateWindow_Params params;
1623 params.opener_id = routing_id_;
[email protected]af15bf22013-03-08 01:18:171624 params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]00323f02013-07-24 15:47:411625 if (GetContentClient()->renderer()->AllowPopup())
1626 params.user_gesture = true;
[email protected]8ab04652010-06-12 02:47:261627 params.window_container_type = WindowFeaturesToContainerType(features);
1628 params.session_storage_namespace_id = session_storage_namespace_id_;
[email protected]5cef23d2013-02-27 13:11:211629 if (frame_name != "_blank")
1630 params.frame_name = frame_name;
[email protected]a7531d772014-03-25 16:15:071631 params.opener_render_frame_id =
[email protected]501052ff2014-02-21 22:19:071632 RenderFrameImpl::FromWebFrame(creator)->GetRoutingID();
[email protected]b6cb3a842011-06-24 18:28:411633 params.opener_url = creator->document().url();
[email protected]931bc922013-09-11 21:42:571634 params.opener_top_level_frame_url = creator->top()->document().url();
[email protected]6c53a7f2014-03-31 16:56:281635 GURL security_url(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
[email protected]48c9cf2d2009-09-16 16:47:521650 int32 routing_id = MSG_ROUTING_NONE;
[email protected]227692c52013-05-31 22:43:041651 int32 main_frame_routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561652 int32 surface_id = 0;
[email protected]176fe9a2014-07-08 02:31:531653 int64 cloned_session_storage_namespace_id = 0;
[email protected]48c9cf2d2009-09-16 16:47:521654
[email protected]380244092011-10-07 17:26:271655 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261656 new ViewHostMsg_CreateWindow(params,
1657 &routing_id,
[email protected]227692c52013-05-31 22:43:041658 &main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:561659 &surface_id,
[email protected]8ab04652010-06-12 02:47:261660 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211661 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521662 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521663
[email protected]af15bf22013-03-08 01:18:171664 WebUserGestureIndicator::consumeUserGesture();
[email protected]c59262422012-11-30 21:20:521665
[email protected]7912e822014-04-16 02:37:031666 // While this view may be a background extension page, it can spawn a visible
1667 // render view. So we just assume that the new one is not another background
1668 // page instead of passing on our own value.
1669 // TODO(vangelis): Can we tell if the new view will be a background page?
1670 bool never_visible = false;
[email protected]9115d5f2013-03-24 04:37:411671
[email protected]d6fa88f2013-10-18 16:00:431672 // The initial hidden state for the RenderViewImpl here has to match what the
1673 // browser will eventually decide for the given disposition. Since we have to
1674 // return from this call synchronously, we just have to make our best guess
1675 // and rely on the browser sending a WasHidden / WasShown message if it
1676 // disagrees.
[email protected]310ebd6302011-10-10 19:06:281677 RenderViewImpl* view = RenderViewImpl::Create(
[email protected]310ebd6302011-10-10 19:06:281678 routing_id_,
[email protected]c7c0d822014-04-16 20:19:491679 true, // window_was_created_with_opener
[email protected]310ebd6302011-10-10 19:06:281680 renderer_preferences_,
[email protected]7912e822014-04-16 02:37:031681 webkit_preferences_,
[email protected]310ebd6302011-10-10 19:06:281682 routing_id,
[email protected]227692c52013-05-31 22:43:041683 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:561684 surface_id,
[email protected]310ebd6302011-10-10 19:06:281685 cloned_session_storage_namespace_id,
[email protected]fcf75d42013-12-03 20:11:261686 base::string16(), // WebCore will take care of setting the correct name.
[email protected]f2c530d2014-02-20 20:15:301687 true, // is_renderer_created
1688 false, // swapped_out
[email protected]5a7100d2014-05-19 01:29:041689 MSG_ROUTING_NONE, // proxy_routing_id
[email protected]f2c530d2014-02-20 20:15:301690 params.disposition == NEW_BACKGROUND_TAB, // hidden
[email protected]7912e822014-04-16 02:37:031691 never_visible,
1692 1, // next_page_id
[email protected]95640212014-07-26 18:14:301693 screen_info_);
[email protected]8ab04652010-06-12 02:47:261694 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521695
[email protected]007a848b2009-10-26 15:55:461696 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:591697 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:461698
[email protected]48c9cf2d2009-09-16 16:47:521699 return view->webview();
1700}
1701
[email protected]180ef242013-11-07 06:50:461702WebWidget* RenderViewImpl::createPopupMenu(blink::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:411703 RenderWidget* widget =
[email protected]842f10652012-06-06 01:54:041704 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]3b78ec12014-03-04 05:18:281705 if (!widget)
1706 return NULL;
[email protected]b2e4c70132013-10-03 02:07:511707 if (screen_metrics_emulator_) {
1708 widget->SetPopupOriginAdjustmentsForEmulation(
1709 screen_metrics_emulator_.get());
1710 }
[email protected]48c9cf2d2009-09-16 16:47:521711 return widget->webwidget();
1712}
1713
[email protected]23367482013-06-27 21:06:541714WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() {
[email protected]5f2aa722013-08-07 16:59:411715 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:101716 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341717}
1718
[email protected]35b2a972014-04-04 15:50:221719void RenderViewImpl::printPage(WebLocalFrame* frame) {
[email protected]b0553c7e2012-09-19 21:36:111720 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
1721 PrintPage(frame, handling_input_event_));
[email protected]48c9cf2d2009-09-16 16:47:521722}
1723
[email protected]310ebd6302011-10-10 19:06:281724bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121725 const WebString& path,
1726 WebFileChooserCompletion* chooser_completion) {
1727 int id = enumeration_completion_id_++;
1728 enumeration_completions_[id] = chooser_completion;
1729 return Send(new ViewHostMsg_EnumerateDirectory(
1730 routing_id_,
1731 id,
[email protected]728c2ee2013-06-25 04:01:071732 base::FilePath::FromUTF16Unsafe(path)));
[email protected]8a58c1c2011-04-19 18:40:121733}
1734
[email protected]7e9523b2014-03-25 03:02:421735void RenderViewImpl::FrameDidStartLoading(WebFrame* frame) {
[email protected]7e9523b2014-03-25 03:02:421736 DCHECK_GE(frames_in_progress_, 0);
1737 if (frames_in_progress_ == 0)
1738 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
1739 frames_in_progress_++;
[email protected]6dd5c322014-03-12 07:58:461740}
1741
[email protected]7e9523b2014-03-25 03:02:421742void RenderViewImpl::FrameDidStopLoading(WebFrame* frame) {
[email protected]eb473772014-04-11 20:54:331743 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
1744 // calls DidStopLoading() without a matching DidStartLoading().
1745 if (frames_in_progress_ == 0)
1746 return;
[email protected]7e9523b2014-03-25 03:02:421747 frames_in_progress_--;
[email protected]7e9523b2014-03-25 03:02:421748 if (frames_in_progress_ == 0) {
1749 DidStopLoadingIcons();
1750 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
1751 }
[email protected]48c9cf2d2009-09-16 16:47:521752}
1753
[email protected]550b0c92013-02-04 05:09:151754void RenderViewImpl::didCancelCompositionOnSelectionChange() {
[email protected]a2214eb2014-06-23 18:31:221755 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]550b0c92013-02-04 05:09:151756}
1757
[email protected]310ebd6302011-10-10 19:06:281758bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101759 if (edit_commands_.empty())
1760 return false;
1761
[email protected]26aa0482009-09-30 16:55:271762 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101763 if (!frame)
1764 return false;
1765
1766 EditCommands::iterator it = edit_commands_.begin();
1767 EditCommands::iterator end = edit_commands_.end();
1768
[email protected]507b33ea2009-09-29 03:56:511769 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101770 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331771 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1772 // key (but it's the exception). Once one edit command is not executed, it
1773 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101774 if (!frame->executeCommand(WebString::fromUTF8(it->name),
[email protected]b77fac52013-06-01 01:03:461775 WebString::fromUTF8(it->value),
[email protected]c39f7442014-02-27 03:33:171776 GetFocusedElement()))
[email protected]b2528b72009-09-24 06:57:101777 break;
[email protected]507b33ea2009-09-29 03:56:511778 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101779 }
1780
[email protected]507b33ea2009-09-29 03:56:511781 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101782}
1783
[email protected]310ebd6302011-10-10 19:06:281784bool RenderViewImpl::runFileChooser(
[email protected]180ef242013-11-07 06:50:461785 const blink::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471786 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351787 // Do not open the file dialog in a hidden RenderView.
1788 if (is_hidden())
1789 return false;
[email protected]e9ff79c2012-10-19 21:31:261790 FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261791 if (params.directory)
[email protected]6bedbef2013-07-31 06:33:491792 ipc_params.mode = FileChooserParams::UploadFolder;
[email protected]b5977a0c2010-08-24 19:46:261793 else if (params.multiSelect)
[email protected]e9ff79c2012-10-19 21:31:261794 ipc_params.mode = FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501795 else if (params.saveAs)
[email protected]e9ff79c2012-10-19 21:31:261796 ipc_params.mode = FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261797 else
[email protected]e9ff79c2012-10-19 21:31:261798 ipc_params.mode = FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471799 ipc_params.title = params.title;
1800 ipc_params.default_file_name =
[email protected]728c2ee2013-06-25 04:01:071801 base::FilePath::FromUTF16Unsafe(params.initialValue);
[email protected]f9a4c41a2012-05-30 00:05:321802 ipc_params.accept_types.reserve(params.acceptTypes.size());
1803 for (size_t i = 0; i < params.acceptTypes.size(); ++i)
1804 ipc_params.accept_types.push_back(params.acceptTypes[i]);
[email protected]2fdf2352012-11-01 19:23:021805#if defined(OS_ANDROID)
[email protected]b7b4beb2013-07-09 14:06:501806 ipc_params.capture = params.useMediaCapture;
[email protected]2fdf2352012-11-01 19:23:021807#endif
[email protected]cdaf8d02010-03-30 19:52:471808
1809 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461810}
1811
habib.virji597255e2014-09-09 00:30:181812void RenderViewImpl::SetValidationMessageDirection(
1813 base::string16* wrapped_main_text,
1814 blink::WebTextDirection main_text_hint,
1815 base::string16* wrapped_sub_text,
1816 blink::WebTextDirection sub_text_hint) {
1817 if (main_text_hint == blink::WebTextDirectionLeftToRight) {
1818 *wrapped_main_text =
1819 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_main_text);
1820 } else if (main_text_hint == blink::WebTextDirectionRightToLeft &&
1821 !base::i18n::IsRTL()) {
1822 base::i18n::WrapStringWithRTLFormatting(wrapped_main_text);
1823 }
1824
1825 if (!wrapped_sub_text->empty()) {
1826 if (sub_text_hint == blink::WebTextDirectionLeftToRight) {
1827 *wrapped_sub_text =
1828 base::i18n::GetDisplayStringInLTRDirectionality(*wrapped_sub_text);
1829 } else if (sub_text_hint == blink::WebTextDirectionRightToLeft) {
1830 base::i18n::WrapStringWithRTLFormatting(wrapped_sub_text);
1831 }
1832 }
1833}
1834
[email protected]edc3af82013-12-12 21:24:071835void RenderViewImpl::showValidationMessage(
1836 const blink::WebRect& anchor_in_root_view,
1837 const blink::WebString& main_text,
habib.virji597255e2014-09-09 00:30:181838 blink::WebTextDirection main_text_hint,
[email protected]edc3af82013-12-12 21:24:071839 const blink::WebString& sub_text,
habib.virji597255e2014-09-09 00:30:181840 blink::WebTextDirection sub_text_hint) {
[email protected]edc3af82013-12-12 21:24:071841 base::string16 wrapped_main_text = main_text;
1842 base::string16 wrapped_sub_text = sub_text;
habib.virji597255e2014-09-09 00:30:181843
1844 SetValidationMessageDirection(
1845 &wrapped_main_text, main_text_hint, &wrapped_sub_text, sub_text_hint);
1846
[email protected]edc3af82013-12-12 21:24:071847 Send(new ViewHostMsg_ShowValidationMessage(
[email protected]2d6836f42014-07-02 17:25:311848 routing_id(), AdjustValidationMessageAnchor(anchor_in_root_view),
1849 wrapped_main_text, wrapped_sub_text));
[email protected]edc3af82013-12-12 21:24:071850}
1851
1852void RenderViewImpl::hideValidationMessage() {
1853 Send(new ViewHostMsg_HideValidationMessage(routing_id()));
1854}
1855
1856void RenderViewImpl::moveValidationMessage(
1857 const blink::WebRect& anchor_in_root_view) {
[email protected]2d6836f42014-07-02 17:25:311858 Send(new ViewHostMsg_MoveValidationMessage(
1859 routing_id(), AdjustValidationMessageAnchor(anchor_in_root_view)));
[email protected]edc3af82013-12-12 21:24:071860}
1861
[email protected]310ebd6302011-10-10 19:06:281862void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521863}
1864
[email protected]310ebd6302011-10-10 19:06:281865void RenderViewImpl::UpdateTargetURL(const GURL& url,
1866 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581867 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521868 if (latest_url == target_url_)
1869 return;
[email protected]163f8242009-10-30 20:19:551870
[email protected]48c9cf2d2009-09-16 16:47:521871 // Tell the browser to display a destination link.
1872 if (target_url_status_ == TARGET_INFLIGHT ||
1873 target_url_status_ == TARGET_PENDING) {
1874 // If we have a request in-flight, save the URL to be sent when we
1875 // receive an ACK to the in-flight request. We can happily overwrite
1876 // any existing pending sends.
1877 pending_target_url_ = latest_url;
1878 target_url_status_ = TARGET_PENDING;
1879 } else {
[email protected]f16cc6782013-12-16 23:42:571880 // URLs larger than |MaxURLChars()| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411881 // see |ParamTraits<GURL>|.
[email protected]f16cc6782013-12-16 23:42:571882 if (latest_url.possibly_invalid_spec().size() > GetMaxURLChars())
[email protected]c85f0212011-11-04 16:54:411883 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:521884 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1885 target_url_ = latest_url;
1886 target_url_status_ = TARGET_INFLIGHT;
1887 }
1888}
1889
[email protected]70221f02013-01-31 22:17:071890gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect(
1891 const gfx::RectF& rect) const {
1892 gfx::RectF window_rect = rect;
1893 window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor());
1894 return window_rect;
1895}
1896
[email protected]310ebd6302011-10-10 19:06:281897void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]a183fb82012-12-14 04:46:221898 // No need to update state if no page has committed yet.
1899 if (page_id_ == -1)
1900 return;
1901
[email protected]882daa92009-11-05 16:31:311902 int delay;
1903 if (send_content_state_immediately_)
1904 delay = 0;
1905 else if (is_hidden())
1906 delay = kDelaySecondsForContentStateSyncHidden;
1907 else
1908 delay = kDelaySecondsForContentStateSync;
1909
1910 if (nav_state_sync_timer_.IsRunning()) {
1911 // The timer is already running. If the delay of the timer maches the amount
1912 // we want to delay by, then return. Otherwise stop the timer so that it
1913 // gets started with the right delay.
1914 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1915 return;
1916 nav_state_sync_timer_.Stop();
1917 }
1918
[email protected]d323a172011-09-02 18:23:021919 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:281920 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311921}
1922
[email protected]310ebd6302011-10-10 19:06:281923void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551924 mouse_over_url_ = GURL(url);
1925 UpdateTargetURL(mouse_over_url_, focus_url_);
1926}
1927
[email protected]310ebd6302011-10-10 19:06:281928void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551929 focus_url_ = GURL(url);
1930 UpdateTargetURL(focus_url_, mouse_over_url_);
1931}
1932
[email protected]35b2a972014-04-04 15:50:221933void RenderViewImpl::startDragging(WebLocalFrame* frame,
[email protected]0407e422012-05-18 19:51:251934 const WebDragData& data,
[email protected]310ebd6302011-10-10 19:06:281935 WebDragOperationsMask mask,
1936 const WebImage& image,
[email protected]ceb36f7d2012-10-31 18:33:241937 const WebPoint& webImageOffset) {
[email protected]dc293a72013-07-01 11:11:221938 DropData drop_data(DropDataBuilder::Build(data));
[email protected]b67151d2012-05-25 23:23:241939 drop_data.referrer_policy = frame->document().referrerPolicy();
[email protected]ceb36f7d2012-10-31 18:33:241940 gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y);
[email protected]59f4f2fa2011-03-23 01:00:551941 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]b67151d2012-05-25 23:23:241942 drop_data,
[email protected]c27ae592010-03-18 15:24:411943 mask,
[email protected]976127072012-05-10 20:08:111944 image.getSkBitmap(),
[email protected]41d86852012-11-07 12:23:241945 imageOffset,
1946 possible_drag_event_info_));
[email protected]48c9cf2d2009-09-16 16:47:521947}
1948
[email protected]310ebd6302011-10-10 19:06:281949bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451950 return renderer_preferences_.can_accept_load_drops;
1951}
1952
[email protected]310ebd6302011-10-10 19:06:281953void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:521954 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1955}
1956
[email protected]310ebd6302011-10-10 19:06:281957void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:521958 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1959}
1960
[email protected]310ebd6302011-10-10 19:06:281961void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]1875bc02014-03-14 06:33:591962 has_scrolled_focused_editable_node_into_rect_ = false;
1963
[email protected]9b66f34bf2010-10-27 20:45:511964 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071965
[email protected]38b592902011-04-16 02:08:421966 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]95640212014-07-26 18:14:301967
1968 // TODO(dmazzoni): this should be part of RenderFrameObserver.
1969 main_render_frame()->FocusedNodeChanged(node);
[email protected]08e9e132010-06-01 16:58:491970}
1971
[email protected]169d4282011-11-30 19:33:591972void RenderViewImpl::didUpdateLayout() {
[email protected]d01b2a62013-09-18 23:21:331973 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidUpdateLayout());
1974
[email protected]169d4282011-11-30 19:33:591975 // We don't always want to set up a timer, only if we've been put in that
1976 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1977 // message.
1978 if (!send_preferred_size_changes_ || !webview())
1979 return;
1980
1981 if (check_preferred_size_timer_.IsRunning())
1982 return;
1983 check_preferred_size_timer_.Start(FROM_HERE,
1984 TimeDelta::FromMilliseconds(0), this,
1985 &RenderViewImpl::CheckPreferredSize);
1986}
1987
[email protected]310ebd6302011-10-10 19:06:281988void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521989 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1990}
1991
[email protected]310ebd6302011-10-10 19:06:281992int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001993 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521994}
1995
[email protected]310ebd6302011-10-10 19:06:281996int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001997 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521998}
1999
[email protected]10760e4a2013-09-04 23:32:202000void RenderViewImpl::postAccessibilityEvent(
[email protected]180ef242013-11-07 06:50:462001 const WebAXObject& obj, blink::WebAXEvent event) {
[email protected]95640212014-07-26 18:14:302002 main_render_frame()->HandleWebAccessibilityEvent(obj, event);
[email protected]063afcb2011-09-29 07:54:322003}
2004
[email protected]180ef242013-11-07 06:50:462005// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:512006
[email protected]310ebd6302011-10-10 19:06:282007void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122008 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2009 // we won't have to test for user gesture anymore and we can
2010 // move that code back to render_widget.cc
[email protected]af15bf22013-03-08 01:18:172011 if (WebUserGestureIndicator::isProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:302012 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]e1176152013-03-06 09:16:442013 Send(new ViewHostMsg_Focus(routing_id_));
[email protected]ea42e7782010-08-23 23:58:122014 }
2015}
2016
[email protected]310ebd6302011-10-10 19:06:282017void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122018 // TODO(jcivelli): see TODO above in didFocus().
[email protected]af15bf22013-03-08 01:18:172019 if (WebUserGestureIndicator::isProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:302020 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]e1176152013-03-06 09:16:442021 Send(new ViewHostMsg_Blur(routing_id_));
[email protected]ea42e7782010-08-23 23:58:122022 }
2023}
2024
initial.commit09911bf2008-07-26 23:55:292025// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282026// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292027// point to dispatch the ShowView message.
2028//
2029// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282030// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292031//
[email protected]310ebd6302011-10-10 19:06:282032void RenderViewImpl::show(WebNavigationPolicy policy) {
[email protected]b2142e962012-10-30 13:59:252033 if (did_show_) {
[email protected]b2142e962012-10-30 13:59:252034 // When supports_multiple_windows is disabled, popups are reusing
2035 // the same view. In some scenarios, this makes WebKit to call show() twice.
[email protected]c9edabd2013-05-23 13:56:242036 if (webkit_preferences_.supports_multiple_windows)
2037 NOTREACHED() << "received extraneous Show call";
initial.commit09911bf2008-07-26 23:55:292038 return;
[email protected]b2142e962012-10-30 13:59:252039 }
initial.commit09911bf2008-07-26 23:55:292040 did_show_ = true;
2041
[email protected]b2142e962012-10-30 13:59:252042 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2043
initial.commit09911bf2008-07-26 23:55:292044 // NOTE: initial_pos_ may still have its default values at this point, but
2045 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2046 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282047 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2048 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292049 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242050 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292051}
2052
[email protected]dd48d492014-03-16 05:04:392053void RenderViewImpl::runModal() {
2054 DCHECK(did_show_) << "should already have shown the view";
2055
2056 // Don't allow further dialogs if we are waiting to swap out, since the
2057 // PageGroupLoadDeferrer in our stack prevents it.
2058 if (suppress_dialogs_until_swap_out_)
2059 return;
2060
2061 // We must keep WebKit's shared timer running in this case in order to allow
2062 // showModalDialog to function properly.
2063 //
2064 // TODO(darin): WebKit should really be smarter about suppressing events and
2065 // timers so that we do not need to manage the shared timer in such a heavy
2066 // handed manner.
2067 //
2068 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2069 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
2070
2071 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
2072 routing_id_, opener_id_));
2073}
2074
[email protected]2b624c562011-10-27 22:58:262075bool RenderViewImpl::enterFullScreen() {
2076 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2077 return true;
2078}
2079
2080void RenderViewImpl::exitFullScreen() {
2081 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2082}
2083
[email protected]217690d2012-01-27 07:33:112084bool RenderViewImpl::requestPointerLock() {
2085 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2086}
2087
2088void RenderViewImpl::requestPointerUnlock() {
2089 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2090}
2091
2092bool RenderViewImpl::isPointerLocked() {
2093 return mouse_lock_dispatcher_->IsMouseLockedTo(
2094 webwidget_mouse_lock_target_.get());
2095}
2096
[email protected]c68c3e4e2013-01-24 00:36:562097void RenderViewImpl::didHandleGestureEvent(
2098 const WebGestureEvent& event,
2099 bool event_cancelled) {
2100 RenderWidget::didHandleGestureEvent(event, event_cancelled);
[email protected]bb37b652013-11-27 23:47:112101
[email protected]91dcc6d32014-07-30 00:01:332102 if (!event_cancelled) {
2103 FOR_EACH_OBSERVER(
2104 RenderViewObserver, observers_, DidHandleGestureEvent(event));
2105 }
2106
[email protected]bb37b652013-11-27 23:47:112107 if (event.type != blink::WebGestureEvent::GestureTap)
2108 return;
2109
[email protected]91dcc6d32014-07-30 00:01:332110 // TODO(estade): hit test the event against focused node to make sure
2111 // the tap actually hit the focused node.
[email protected]bb37b652013-11-27 23:47:112112 blink::WebTextInputType text_input_type =
2113 GetWebView()->textInputInfo().type;
2114
2115 Send(new ViewHostMsg_FocusedNodeTouched(
2116 routing_id(), text_input_type != blink::WebTextInputTypeNone));
[email protected]c68c3e4e2013-01-24 00:36:562117}
2118
[email protected]6e89eb72013-07-23 13:28:222119void RenderViewImpl::initializeLayerTreeView() {
2120 RenderWidget::initializeLayerTreeView();
2121 RenderWidgetCompositor* rwc = compositor();
[email protected]9f7638f42014-05-30 01:51:162122 if (!rwc)
[email protected]6e89eb72013-07-23 13:28:222123 return;
[email protected]9f7638f42014-05-30 01:51:162124 if (webview() && webview()->devToolsAgent())
2125 webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId());
2126
2127#if !defined(OS_MACOSX) // many events are unhandled - http://crbug.com/138003
2128 RenderThreadImpl* render_thread = RenderThreadImpl::current();
2129 // render_thread may be NULL in tests.
2130 InputHandlerManager* input_handler_manager =
2131 render_thread ? render_thread->input_handler_manager() : NULL;
2132 if (input_handler_manager) {
2133 input_handler_manager->AddInputHandler(
2134 routing_id_, rwc->GetInputHandler(), AsWeakPtr());
2135 }
2136#endif
[email protected]6e89eb72013-07-23 13:28:222137}
2138
[email protected]180ef242013-11-07 06:50:462139// blink::WebFrameClient -----------------------------------------------------
[email protected]3d9689372009-09-10 04:29:172140
[email protected]5e92282f2012-08-17 08:11:572141void RenderViewImpl::Repaint(const gfx::Size& size) {
[email protected]3d9ec5052013-01-02 22:05:252142 OnRepaint(size);
[email protected]5e92282f2012-08-17 08:11:572143}
2144
[email protected]b2324b092012-11-01 10:34:112145void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
2146 const std::string& value) {
2147 EditCommands edit_commands;
2148 edit_commands.push_back(EditCommand(name, value));
2149 OnSetEditCommandsForNextKeyEvent(edit_commands);
2150}
2151
2152void RenderViewImpl::ClearEditCommands() {
2153 edit_commands_.clear();
2154}
2155
[email protected]180ef242013-11-07 06:50:462156SSLStatus RenderViewImpl::GetSSLStatusOfFrame(blink::WebFrame* frame) const {
[email protected]83c0abca2013-07-23 20:09:422157 std::string security_info;
2158 if (frame && frame->dataSource())
2159 security_info = frame->dataSource()->response().securityInfo();
2160
2161 SSLStatus ssl_status;
2162 DeserializeSecurityInfo(security_info,
2163 &ssl_status.cert_id,
2164 &ssl_status.cert_status,
2165 &ssl_status.security_bits,
[email protected]0bbd63b2013-11-29 00:02:122166 &ssl_status.connection_status,
2167 &ssl_status.signed_certificate_timestamp_ids);
[email protected]83c0abca2013-07-23 20:09:422168 return ssl_status;
[email protected]e4495212012-12-06 03:09:122169}
2170
[email protected]b38806a2013-10-04 16:01:382171const std::string& RenderViewImpl::GetAcceptLanguages() const {
2172 return renderer_preferences_.accept_languages;
2173}
2174
[email protected]35b2a972014-04-04 15:50:222175void RenderViewImpl::didCreateDataSource(WebLocalFrame* frame,
2176 WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:572177 bool content_initiated = !pending_navigation_params_.get();
2178
[email protected]f8872902013-10-30 03:18:572179 // Make sure any previous redirect URLs end up in our new data source.
2180 if (pending_navigation_params_.get()) {
2181 for (std::vector<GURL>::const_iterator i =
2182 pending_navigation_params_->redirects.begin();
2183 i != pending_navigation_params_->redirects.end(); ++i) {
2184 ds->appendRedirect(*i);
2185 }
2186 }
2187
[email protected]007733c2011-11-17 00:34:072188 DocumentState* document_state = DocumentState::FromDataSource(ds);
2189 if (!document_state) {
2190 document_state = new DocumentState;
2191 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:572192 if (!content_initiated)
2193 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:072194 }
2195
[email protected]bf70edce2012-06-20 22:32:222196 // Carry over the user agent override flag, if it exists.
2197 if (content_initiated && webview() && webview()->mainFrame() &&
[email protected]82307f6b2014-08-07 03:30:122198 webview()->mainFrame()->isWebLocalFrame() &&
[email protected]bf70edce2012-06-20 22:32:222199 webview()->mainFrame()->dataSource()) {
2200 DocumentState* old_document_state =
2201 DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
2202 if (old_document_state) {
[email protected]e20b88d2013-04-09 15:28:372203 InternalDocumentStateData* internal_data =
2204 InternalDocumentStateData::FromDocumentState(document_state);
2205 InternalDocumentStateData* old_internal_data =
2206 InternalDocumentStateData::FromDocumentState(old_document_state);
2207 internal_data->set_is_overriding_user_agent(
2208 old_internal_data->is_overriding_user_agent());
[email protected]bf70edce2012-06-20 22:32:222209 }
2210 }
2211
[email protected]3d9689372009-09-10 04:29:172212 // The rest of RenderView assumes that a WebDataSource will always have a
2213 // non-null NavigationState.
[email protected]e1ed5a12012-08-08 19:57:442214 if (content_initiated) {
[email protected]007733c2011-11-17 00:34:072215 document_state->set_navigation_state(
2216 NavigationState::CreateContentInitiated());
[email protected]e1ed5a12012-08-08 19:57:442217 } else {
[email protected]45d83a12012-04-06 22:57:572218 document_state->set_navigation_state(CreateNavigationStateFromPending());
2219 pending_navigation_params_.reset();
2220 }
[email protected]8a3125a712010-08-09 18:58:512221
[email protected]007733c2011-11-17 00:34:072222 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512223 // navigating from a page that used prefetching using a link on that
2224 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072225 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512226 // this value appropriately.
2227 // TODO(gavinp): catch the important case of navigation in a new
2228 // renderer process.
2229 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302230 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522231 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512232 const GURL referrer(
2233 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]82307f6b2014-08-07 03:30:122234 if (!referrer.is_empty() && old_frame->isWebLocalFrame() &&
2235 DocumentState::FromDataSource(old_frame->dataSource())
2236 ->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:412237 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:512238 WebDataSource* old_frame_ds = old_frame->dataSource();
2239 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072240 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512241 break;
2242 }
2243 }
2244 }
2245 }
2246 }
2247
[email protected]4c1b6f0b2010-02-07 16:38:182248 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522249 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512250 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182251 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072252 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182253 break;
2254 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]22492062014-06-04 13:31:172255 case WebURLRequest::ReloadBypassingCache: // end-to-end reload.
[email protected]007733c2011-11-17 00:34:072256 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182257 break;
2258 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072259 document_state->set_load_type(
2260 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182261 break;
2262 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072263 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182264 break;
[email protected]82f0e6c2014-06-02 08:18:392265 default:
2266 NOTREACHED();
[email protected]4c1b6f0b2010-02-07 16:38:182267 }
2268 }
[email protected]fa7b6b542009-11-03 05:02:302269
[email protected]946a0032011-03-31 18:42:282270 FOR_EACH_OBSERVER(
2271 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172272}
2273
[email protected]45d83a12012-04-06 22:57:572274void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:072275 DocumentState* document_state) {
[email protected]c6bc20332014-02-28 18:30:392276 const FrameMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:572277 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:072278
[email protected]e20b88d2013-04-09 15:28:372279 InternalDocumentStateData* internal_data =
2280 InternalDocumentStateData::FromDocumentState(document_state);
2281
[email protected]cca6f392014-05-28 21:32:262282 if (!params.url.SchemeIs(url::kJavaScriptScheme) &&
[email protected]c6bc20332014-02-28 18:30:392283 params.navigation_type == FrameMsg_Navigate_Type::RESTORE) {
[email protected]45d83a12012-04-06 22:57:572284 // We're doing a load of a page that was restored from the last session. By
2285 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
2286 // can result in stale data for pages that are set to expire. We explicitly
2287 // override that by setting the policy here so that as necessary we load
2288 // from the network.
[email protected]a8ff8ed2014-01-09 07:32:262289 //
2290 // TODO(davidben): Remove this in favor of passing a cache policy to the
2291 // loadHistoryItem call in OnNavigate. That requires not overloading
2292 // UseProtocolCachePolicy to mean both "normal load" and "determine cache
2293 // policy based on load type, etc".
[email protected]e20b88d2013-04-09 15:28:372294 internal_data->set_cache_policy_override(
[email protected]45d83a12012-04-06 22:57:572295 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:072296 }
2297
2298 if (IsReload(params))
2299 document_state->set_load_type(DocumentState::RELOAD);
[email protected]691aa2f2013-05-28 22:52:042300 else if (params.page_state.IsValid())
[email protected]007733c2011-11-17 00:34:072301 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2302 else
2303 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]ca662822012-05-11 17:53:592304
[email protected]e20b88d2013-04-09 15:28:372305 internal_data->set_is_overriding_user_agent(params.is_overriding_user_agent);
2306 internal_data->set_must_reset_scroll_and_scale_state(
[email protected]a3a5397d2012-09-12 06:50:342307 params.navigation_type ==
[email protected]c6bc20332014-02-28 18:30:392308 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]951a64832012-10-11 16:26:372309 document_state->set_can_load_local_resources(params.can_load_local_resources);
[email protected]45d83a12012-04-06 22:57:572310}
[email protected]007733c2011-11-17 00:34:072311
[email protected]45d83a12012-04-06 22:57:572312NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
[email protected]c6bc20332014-02-28 18:30:392313 const FrameMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:572314 NavigationState* navigation_state = NULL;
2315
2316 // A navigation resulting from loading a javascript URL should not be treated
2317 // as a browser initiated event. Instead, we want it to look as if the page
2318 // initiated any load resulting from JS execution.
[email protected]cca6f392014-05-28 21:32:262319 if (!params.url.SchemeIs(url::kJavaScriptScheme)) {
[email protected]45d83a12012-04-06 22:57:572320 navigation_state = NavigationState::CreateBrowserInitiated(
2321 params.page_id,
2322 params.pending_history_list_offset,
[email protected]60d6cca2013-04-30 08:47:132323 params.should_clear_history_list,
[email protected]45d83a12012-04-06 22:57:572324 params.transition);
[email protected]4972fc82013-11-19 04:33:422325 navigation_state->set_should_replace_current_entry(
2326 params.should_replace_current_entry);
[email protected]45d83a12012-04-06 22:57:572327 navigation_state->set_transferred_request_child_id(
2328 params.transferred_request_child_id);
2329 navigation_state->set_transferred_request_request_id(
2330 params.transferred_request_request_id);
[email protected]80744782012-05-04 01:47:002331 navigation_state->set_allow_download(params.allow_download);
[email protected]f050fde2013-03-21 00:40:452332 navigation_state->set_extra_headers(params.extra_headers);
[email protected]45d83a12012-04-06 22:57:572333 } else {
2334 navigation_state = NavigationState::CreateContentInitiated();
2335 }
2336 return navigation_state;
[email protected]007733c2011-11-17 00:34:072337}
2338
[email protected]5b52cd2f712012-03-28 02:12:482339void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
2340 bool enable_viewport =
[email protected]a41f8f602013-11-12 20:15:282341 command_line.HasSwitch(switches::kEnableViewport) ||
2342 command_line.HasSwitch(switches::kEnableViewportMeta);
[email protected]5b52cd2f712012-03-28 02:12:482343
[email protected]47e932da2013-03-07 00:11:242344 // If viewport tag is enabled, then the WebKit side will take care
2345 // of setting the fixed layout size and page scale limits.
2346 if (enable_viewport)
2347 return;
2348
[email protected]a02a0c92013-08-12 20:18:582349 // When navigating to a new page, reset the page scale factor to be 1.0.
2350 webview()->setInitialPageScaleOverride(1.f);
2351
[email protected]e4cd82e2013-04-10 15:20:382352 float maxPageScaleFactor =
2353 command_line.HasSwitch(switches::kEnablePinch) ? 4.f : 1.f ;
2354 webview()->setPageScaleFactorLimits(1, maxPageScaleFactor);
[email protected]5b52cd2f712012-03-28 02:12:482355}
2356
[email protected]06181e52014-05-10 11:59:092357void RenderViewImpl::didClearWindowObject(WebLocalFrame* frame) {
2358 FOR_EACH_OBSERVER(
2359 RenderViewObserver, observers_, DidClearWindowObject(frame));
[email protected]29043082014-01-22 21:53:512360
[email protected]f5c9f0882014-02-16 22:19:322361 if (enabled_bindings_& BINDINGS_POLICY_WEB_UI)
2362 WebUIExtension::Install(frame);
2363
[email protected]caa8dc042014-01-13 12:07:582364 if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION)
2365 StatsCollectionController::Install(frame);
[email protected]cdb6b1e2014-01-23 00:06:492366
2367 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2368
2369 if (command_line.HasSwitch(switches::kEnableSkiaBenchmarking))
2370 SkiaBenchmarking::Install(frame);
[email protected]3fad220d2014-01-23 11:30:062371
2372 if (command_line.HasSwitch(switches::kEnableMemoryBenchmarking))
2373 MemoryBenchmarkingExtension::Install(frame);
[email protected]3d9689372009-09-10 04:29:172374}
2375
[email protected]35b2a972014-04-04 15:50:222376void RenderViewImpl::didChangeIcon(WebLocalFrame* frame,
[email protected]41225fe2013-03-29 05:32:022377 WebIconURL::Type icon_type) {
2378 if (frame->parent())
2379 return;
2380
2381 if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon)
2382 return;
2383
2384 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type);
2385 std::vector<FaviconURL> urls;
2386 for (size_t i = 0; i < icon_urls.size(); i++) {
[email protected]2bd262b2014-04-16 05:31:232387 std::vector<gfx::Size> sizes;
[email protected]f34ac132014-03-20 23:02:052388 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
2389 urls.push_back(FaviconURL(
2390 icon_urls[i].iconURL(), ToFaviconType(icon_urls[i].iconType()), sizes));
[email protected]41225fe2013-03-29 05:32:022391 }
2392 SendUpdateFaviconURL(urls);
[email protected]5019ef12010-04-27 17:26:582393}
2394
[email protected]35b2a972014-04-04 15:50:222395void RenderViewImpl::didUpdateCurrentHistoryItem(WebLocalFrame* frame) {
[email protected]882daa92009-11-05 16:31:312396 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592397}
2398
[email protected]310ebd6302011-10-10 19:06:282399void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:072400 // We don't always want to send the change messages over IPC, only if we've
2401 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2402 // message.
2403 if (!send_preferred_size_changes_ || !webview())
2404 return;
2405
[email protected]e76b7972013-06-06 02:58:482406 gfx::Size size = webview()->contentsPreferredMinimumSize();
[email protected]8205d742010-10-22 23:51:532407
[email protected]7940b8e2013-07-25 23:08:492408 // In the presence of zoom, these sizes are still reported as if unzoomed,
2409 // so we need to adjust.
2410 double zoom_factor = ZoomLevelToZoomFactor(webview()->zoomLevel());
2411 size.set_width(static_cast<int>(size.width() * zoom_factor));
2412 size.set_height(static_cast<int>(size.height() * zoom_factor));
2413
[email protected]705243f2010-05-05 19:58:072414 if (size == preferred_size_)
2415 return;
[email protected]c27324b2009-11-19 22:44:292416
[email protected]705243f2010-05-05 19:58:072417 preferred_size_ = size;
2418 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2419 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172420}
2421
[email protected]caaf2482013-05-01 20:33:322422BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() {
[email protected]fc72bb12013-06-02 21:13:462423 if (!browser_plugin_manager_.get())
[email protected]fb325d122012-11-20 23:58:052424 browser_plugin_manager_ = BrowserPluginManager::Create(this);
[email protected]fc72bb12013-06-02 21:13:462425 return browser_plugin_manager_.get();
[email protected]fb325d122012-11-20 23:58:052426}
2427
[email protected]35b2a972014-04-04 15:50:222428void RenderViewImpl::didChangeScrollOffset(WebLocalFrame* frame) {
[email protected]143dcd592009-11-06 21:33:492429 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:312430
[email protected]2b942c332012-04-25 16:26:262431 FOR_EACH_OBSERVER(
2432 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]dd6afca2011-08-13 03:44:312433}
2434
[email protected]55750b32012-09-21 14:05:032435void RenderViewImpl::SendFindReply(int request_id,
2436 int match_count,
2437 int ordinal,
2438 const WebRect& selection_rect,
2439 bool final_status_update) {
[email protected]55750b32012-09-21 14:05:032440 Send(new ViewHostMsg_Find_Reply(routing_id_,
2441 request_id,
2442 match_count,
2443 selection_rect,
2444 ordinal,
2445 final_status_update));
2446}
2447
[email protected]180ef242013-11-07 06:50:462448blink::WebString RenderViewImpl::acceptLanguages() {
[email protected]9982c802013-06-12 15:22:062449 return WebString::fromUTF8(renderer_preferences_.accept_languages);
2450}
2451
[email protected]180ef242013-11-07 06:50:462452// blink::WebPageSerializerClient implementation ------------------------------
[email protected]18d5be92011-07-25 18:00:192453
[email protected]310ebd6302011-10-10 19:06:282454void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:192455 const WebURL& frame_url,
2456 const WebCString& data,
2457 WebPageSerializerClient::PageSerializationStatus status) {
2458 Send(new ViewHostMsg_SendSerializedHtmlData(
2459 routing_id(),
2460 frame_url,
2461 data.data(),
2462 static_cast<int32>(status)));
2463}
2464
[email protected]e9ff79c2012-10-19 21:31:262465// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:312466
[email protected]310ebd6302011-10-10 19:06:282467bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:312468 return RenderWidget::Send(message);
2469}
2470
[email protected]b849847b2013-12-10 21:57:582471RenderFrame* RenderViewImpl::GetMainRenderFrame() {
2472 return main_render_frame_.get();
2473}
2474
[email protected]82114f52012-03-20 22:53:412475int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:312476 return routing_id_;
2477}
2478
[email protected]82114f52012-03-20 22:53:412479gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:312480 return size();
2481}
2482
[email protected]82114f52012-03-20 22:53:412483WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:312484 return webkit_preferences_;
2485}
2486
[email protected]324825d2012-11-30 12:37:152487void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
2488 OnUpdateWebPreferences(preferences);
2489}
2490
[email protected]180ef242013-11-07 06:50:462491blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:312492 return webview();
2493}
2494
[email protected]c39f7442014-02-27 03:33:172495blink::WebElement RenderViewImpl::GetFocusedElement() const {
[email protected]a2ef54c2011-10-10 16:20:312496 if (!webview())
[email protected]c39f7442014-02-27 03:33:172497 return WebElement();
[email protected]a2ef54c2011-10-10 16:20:312498 WebFrame* focused_frame = webview()->focusedFrame();
2499 if (focused_frame) {
2500 WebDocument doc = focused_frame->document();
2501 if (!doc.isNull())
[email protected]c39f7442014-02-27 03:33:172502 return doc.focusedElement();
[email protected]a2ef54c2011-10-10 16:20:312503 }
2504
[email protected]c39f7442014-02-27 03:33:172505 return WebElement();
[email protected]a2ef54c2011-10-10 16:20:312506}
2507
[email protected]2a84f9d2012-06-05 21:50:432508bool RenderViewImpl::IsEditableNode(const WebNode& node) const {
2509 if (node.isNull())
2510 return false;
2511
2512 if (node.isContentEditable())
2513 return true;
2514
2515 if (node.isElementNode()) {
2516 const WebElement& element = node.toConst<WebElement>();
2517 if (element.isTextFormControlElement())
2518 return true;
2519
2520 // Also return true if it has an ARIA role of 'textbox'.
2521 for (unsigned i = 0; i < element.attributeCount(); ++i) {
[email protected]df807042014-08-13 16:48:412522 if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) {
2523 if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox"))
[email protected]2a84f9d2012-06-05 21:50:432524 return true;
2525 break;
2526 }
[email protected]a2ef54c2011-10-10 16:20:312527 }
2528 }
[email protected]2a84f9d2012-06-05 21:50:432529
2530 return false;
[email protected]a2ef54c2011-10-10 16:20:312531}
2532
[email protected]91dcc6d32014-07-30 00:01:332533bool RenderViewImpl::NodeContainsPoint(const WebNode& node,
2534 const gfx::Point& point) const {
2535 blink::WebHitTestResult hit_test =
2536 webview()->hitTestResultAt(WebPoint(point.x(), point.y()));
2537 return node.containsIncludingShadowDOM(hit_test.node());
2538}
2539
[email protected]310ebd6302011-10-10 19:06:282540bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:312541 return (!send_preferred_size_changes_ ||
2542 (disable_scrollbars_size_limit_.width() <= width ||
2543 disable_scrollbars_size_limit_.height() <= height));
2544}
2545
[email protected]82114f52012-03-20 22:53:412546int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:312547 return enabled_bindings_;
2548}
2549
[email protected]82114f52012-03-20 22:53:412550bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:312551 return send_content_state_immediately_;
2552}
2553
[email protected]180ef242013-11-07 06:50:462554blink::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:312555 return visibilityState();
2556}
2557
[email protected]3c71576ce2013-07-23 02:00:012558void RenderViewImpl::DidStartLoading() {
[email protected]6dd5c322014-03-12 07:58:462559 main_render_frame_->didStartLoading(true);
[email protected]3c71576ce2013-07-23 02:00:012560}
2561
2562void RenderViewImpl::DidStopLoading() {
[email protected]6dd5c322014-03-12 07:58:462563 main_render_frame_->didStopLoading();
[email protected]3c71576ce2013-07-23 02:00:012564}
2565
[email protected]310ebd6302011-10-10 19:06:282566void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:292567 if (!webview())
2568 return;
[email protected]9cd14ef2014-04-30 18:26:032569 SendUpdateState(history_controller_->GetCurrentEntry());
initial.commit09911bf2008-07-26 23:55:292570}
2571
[email protected]54ea9ff2014-03-20 00:27:542572blink::WebPlugin* RenderViewImpl::GetWebPluginForFind() {
2573 if (!webview())
2574 return NULL;
2575
2576 WebFrame* main_frame = webview()->mainFrame();
[email protected]82307f6b2014-08-07 03:30:122577 if (main_frame->isWebLocalFrame() &&
2578 main_frame->document().isPluginDocument())
[email protected]54ea9ff2014-03-20 00:27:542579 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
2580
2581#if defined(ENABLE_PLUGINS)
2582 if (plugin_find_handler_)
2583 return plugin_find_handler_->container()->plugin();
2584#endif
2585
2586 return NULL;
[email protected]24a7f3c2010-03-25 08:26:492587}
2588
[email protected]55750b32012-09-21 14:05:032589void RenderViewImpl::OnFind(int request_id,
[email protected]fcf75d42013-12-03 20:11:262590 const base::string16& search_text,
[email protected]310ebd6302011-10-10 19:06:282591 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:272592 WebFrame* main_frame = webview()->mainFrame();
[email protected]54ea9ff2014-03-20 00:27:542593 blink::WebPlugin* plugin = GetWebPluginForFind();
[email protected]872542532011-06-23 00:43:162594 // Check if the plugin still exists in the document.
[email protected]54ea9ff2014-03-20 00:27:542595 if (plugin) {
[email protected]24a7f3c2010-03-25 08:26:492596 if (options.findNext) {
2597 // Just navigate back/forward.
[email protected]54ea9ff2014-03-20 00:27:542598 plugin->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:492599 } else {
[email protected]54ea9ff2014-03-20 00:27:542600 if (!plugin->startFind(
[email protected]afdbd142010-07-10 08:01:232601 search_text, options.matchCase, request_id)) {
[email protected]e7c58a32010-08-13 19:47:112602 // Send "no results".
[email protected]55750b32012-09-21 14:05:032603 SendFindReply(request_id, 0, 0, gfx::Rect(), true);
[email protected]24a7f3c2010-03-25 08:26:492604 }
2605 }
2606 return;
2607 }
2608
[email protected]b4bb2502009-10-01 22:35:272609 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:272610 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:292611 WebFrame* search_frame = focused_frame; // start searching focused frame.
2612
2613 bool multi_frame = (frame_after_main != main_frame);
2614
2615 // If we have multiple frames, we don't want to wrap the search within the
2616 // frame, so we check here if we only have main_frame in the chain.
2617 bool wrap_within_frame = !multi_frame;
2618
[email protected]b3f2b912009-04-09 16:18:522619 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:292620 bool result = false;
2621
[email protected]7830da3e2009-11-06 16:27:262622 // If something is selected when we start searching it means we cannot just
2623 // increment the current match ordinal; we need to re-generate it.
2624 WebRange current_selection = focused_frame->selectionRange();
2625
initial.commit09911bf2008-07-26 23:55:292626 do {
[email protected]dd7daa82009-08-10 05:46:452627 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592628 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:292629
2630 if (!result) {
2631 // don't leave text selected as you move to the next frame.
[email protected]6dd17a8a2013-05-01 05:50:102632 search_frame->executeCommand(WebString::fromUTF8("Unselect"),
[email protected]c39f7442014-02-27 03:33:172633 GetFocusedElement());
initial.commit09911bf2008-07-26 23:55:292634
2635 // Find the next frame, but skip the invisible ones.
2636 do {
2637 // What is the next frame to search? (we might be going backwards). Note
2638 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:592639 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:272640 search_frame->traverseNext(true) :
2641 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:452642 } while (!search_frame->hasVisibleContent() &&
2643 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:292644
[email protected]884db412008-11-24 23:46:502645 // Make sure selection doesn't affect the search operation in new frame.
[email protected]6dd17a8a2013-05-01 05:50:102646 search_frame->executeCommand(WebString::fromUTF8("Unselect"),
[email protected]c39f7442014-02-27 03:33:172647 GetFocusedElement());
initial.commit09911bf2008-07-26 23:55:292648
2649 // If we have multiple frames and we have wrapped back around to the
2650 // focused frame, we need to search it once more allowing wrap within
2651 // the frame, otherwise it will report 'no match' if the focused frame has
2652 // reported matches, but no frames after the focused_frame contain a
2653 // match for the search word(s).
2654 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:452655 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592656 request_id, search_text, options, true, // Force wrapping.
2657 &selection_rect);
initial.commit09911bf2008-07-26 23:55:292658 }
2659 }
2660
[email protected]26aa0482009-09-30 16:55:272661 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:292662 } while (!result && search_frame != focused_frame);
2663
[email protected]7830da3e2009-11-06 16:27:262664 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:292665 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:452666 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:292667 } else {
2668 // If nothing is found, set result to "0 of 0", otherwise, set it to
2669 // "-1 of 1" to indicate that we found at least one item, but we don't know
2670 // yet what is active.
2671 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
2672 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:292673
[email protected]4f3dc372009-02-24 00:10:292674 // If we find no matches then this will be our last status update.
2675 // Otherwise the scoping effort will send more results.
2676 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:292677
[email protected]55750b32012-09-21 14:05:032678 SendFindReply(request_id, match_count, ordinal, selection_rect,
2679 final_status_update);
initial.commit09911bf2008-07-26 23:55:292680
initial.commit09911bf2008-07-26 23:55:292681 // Scoping effort begins, starting with the mainframe.
2682 search_frame = main_frame;
2683
[email protected]dd7daa82009-08-10 05:46:452684 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:292685
2686 do {
2687 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:452688 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:292689
2690 // We don't start another scoping effort unless at least one match has
2691 // been found.
2692 if (result) {
2693 // Start new scoping request. If the scoping function determines that it
2694 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:452695 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:592696 search_text,
2697 options,
initial.commit09911bf2008-07-26 23:55:292698 true); // reset the tickmarks
2699 }
2700
2701 // Iterate to the next frame. The frame will not necessarily scope, for
2702 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:272703 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:292704 } while (search_frame != main_frame);
2705 }
2706}
2707
[email protected]e9ff79c2012-10-19 21:31:262708void RenderViewImpl::OnStopFinding(StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:492709 WebView* view = webview();
2710 if (!view)
2711 return;
2712
[email protected]54ea9ff2014-03-20 00:27:542713 blink::WebPlugin* plugin = GetWebPluginForFind();
2714 if (plugin) {
2715 plugin->stopFind();
[email protected]24a7f3c2010-03-25 08:26:492716 return;
2717 }
2718
[email protected]e9ff79c2012-10-19 21:31:262719 bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]6dd17a8a2013-05-01 05:50:102720 if (clear_selection) {
2721 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
[email protected]c39f7442014-02-27 03:33:172722 GetFocusedElement());
[email protected]6dd17a8a2013-05-01 05:50:102723 }
[email protected]24a7f3c2010-03-25 08:26:492724
2725 WebFrame* frame = view->mainFrame();
2726 while (frame) {
2727 frame->stopFinding(clear_selection);
2728 frame = frame->traverseNext(false);
2729 }
2730
[email protected]e9ff79c2012-10-19 21:31:262731 if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:492732 WebFrame* focused_frame = view->focusedFrame();
2733 if (focused_frame) {
2734 WebDocument doc = focused_frame->document();
2735 if (!doc.isNull()) {
[email protected]c39f7442014-02-27 03:33:172736 WebElement element = doc.focusedElement();
2737 if (!element.isNull())
2738 element.simulateClick();
[email protected]24a7f3c2010-03-25 08:26:492739 }
2740 }
2741 }
2742}
2743
[email protected]59363fc92012-09-05 03:46:312744#if defined(OS_ANDROID)
2745void RenderViewImpl::OnActivateNearestFindResult(int request_id,
2746 float x, float y) {
2747 if (!webview())
2748 return;
2749
2750 WebFrame* main_frame = webview()->mainFrame();
2751 WebRect selection_rect;
2752 int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y),
2753 &selection_rect);
2754 if (ordinal == -1) {
2755 // Something went wrong, so send a no-op reply (force the main_frame to
2756 // report the current match count) in case the host is waiting for a
2757 // response due to rate-limiting).
2758 main_frame->increaseMatchCount(0, request_id);
2759 return;
2760 }
2761
[email protected]55750b32012-09-21 14:05:032762 SendFindReply(request_id,
2763 -1 /* number_of_matches */,
2764 ordinal,
2765 selection_rect,
2766 true /* final_update */);
[email protected]59363fc92012-09-05 03:46:312767}
2768
2769void RenderViewImpl::OnFindMatchRects(int current_version) {
2770 if (!webview())
2771 return;
2772
2773 WebFrame* main_frame = webview()->mainFrame();
2774 std::vector<gfx::RectF> match_rects;
2775
2776 int rects_version = main_frame->findMatchMarkersVersion();
2777 if (current_version != rects_version) {
2778 WebVector<WebFloatRect> web_match_rects;
2779 main_frame->findMatchRects(web_match_rects);
2780 match_rects.reserve(web_match_rects.size());
2781 for (size_t i = 0; i < web_match_rects.size(); ++i)
2782 match_rects.push_back(gfx::RectF(web_match_rects[i]));
2783 }
2784
2785 gfx::RectF active_rect = main_frame->activeFindMatchRect();
2786 Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_,
2787 rects_version,
2788 match_rects,
2789 active_rect));
2790}
2791#endif
2792
[email protected]e9ff79c2012-10-19 21:31:262793void RenderViewImpl::OnZoom(PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:512794 if (!webview()) // Not sure if this can happen, but no harm in being safe.
2795 return;
2796
[email protected]258d31122010-05-09 10:59:412797 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:102798
[email protected]b75b8292010-10-01 07:28:252799 double old_zoom_level = webview()->zoomLevel();
2800 double zoom_level;
[email protected]e9ff79c2012-10-19 21:31:262801 if (zoom == PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:252802 zoom_level = 0;
2803 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
2804 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:482805 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:252806 } else {
2807 // Either the user hit the zoom factor limit and thus the zoom level is now
2808 // not a whole number, or a plugin changed it to a custom value. We want
2809 // to go to the next whole number so that the user can always get back to
2810 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:482811 if ((old_zoom_level > 1 && zoom > 0) ||
2812 (old_zoom_level < 1 && zoom < 0)) {
2813 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:252814 } else {
2815 // We're going towards 100%, so first go to the next whole number.
2816 zoom_level = static_cast<int>(old_zoom_level);
2817 }
2818 }
[email protected]91219702013-09-18 07:33:512819 webview()->setZoomLevel(zoom_level);
[email protected]47578fa02011-11-02 19:34:412820 zoomLevelChanged();
2821}
2822
[email protected]310ebd6302011-10-10 19:06:282823void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
2824 double zoom_level) {
[email protected]cbe55d22013-02-14 17:04:332825#if !defined(OS_ANDROID)
2826 // On Android, page zoom isn't used, and in case of WebView, text zoom is used
2827 // for legacy WebView text scaling emulation. Thus, the code that resets
2828 // the zoom level from this map will be effectively resetting text zoom level.
[email protected]9d797f32010-04-23 07:17:542829 host_zoom_levels_[url] = zoom_level;
[email protected]cbe55d22013-02-14 17:04:332830#endif
initial.commit09911bf2008-07-26 23:55:292831}
2832
[email protected]d42bf472014-06-14 01:49:382833void RenderViewImpl::OnSetZoomLevelForView(bool uses_temporary_zoom_level,
2834 double level) {
2835 uses_temporary_zoom_level_ = uses_temporary_zoom_level;
2836
2837 webview()->hidePopups();
2838 webview()->setZoomLevel(level);
2839}
2840
[email protected]310ebd6302011-10-10 19:06:282841void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:272842 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:292843}
2844
[email protected]310ebd6302011-10-10 19:06:282845void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:272846 WebString no_encoding;
2847 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:182848}
2849
[email protected]f546640b2012-05-15 00:03:492850void RenderViewImpl::OnPostMessageEvent(
2851 const ViewMsg_PostMessage_Params& params) {
[email protected]bf4a2312013-04-23 00:32:112852 // TODO(nasko): Support sending to subframes.
[email protected]e12dbe6f2012-10-04 22:11:192853 WebFrame* frame = webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:492854
2855 // Find the source frame if it exists.
[email protected]f546640b2012-05-15 00:03:492856 WebFrame* source_frame = NULL;
2857 if (params.source_routing_id != MSG_ROUTING_NONE) {
2858 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
2859 if (source_view)
[email protected]e12dbe6f2012-10-04 22:11:192860 source_frame = source_view->webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:492861 }
2862
[email protected]0bc7f3542013-10-21 15:05:532863 // If the message contained MessagePorts, create the corresponding endpoints.
2864 DCHECK_EQ(params.message_port_ids.size(), params.new_routing_ids.size());
[email protected]180ef242013-11-07 06:50:462865 blink::WebMessagePortChannelArray channels(params.message_port_ids.size());
[email protected]0bc7f3542013-10-21 15:05:532866 for (size_t i = 0;
2867 i < params.message_port_ids.size() && i < params.new_routing_ids.size();
2868 ++i) {
2869 channels[i] =
2870 new WebMessagePortChannelImpl(params.new_routing_ids[i],
2871 params.message_port_ids[i],
2872 base::MessageLoopProxy::current().get());
2873 }
2874
[email protected]afe7d90d2014-07-19 05:10:222875 WebSerializedScriptValue serialized_script_value;
2876 if (params.is_data_raw_string) {
2877 v8::HandleScope handle_scope(blink::mainThreadIsolate());
2878 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
2879 v8::Context::Scope context_scope(context);
2880 V8ValueConverterImpl converter;
2881 converter.SetDateAllowed(true);
2882 converter.SetRegExpAllowed(true);
2883 scoped_ptr<base::Value> value(new base::StringValue(params.data));
2884 v8::Handle<v8::Value> result_value = converter.ToV8Value(value.get(),
2885 context);
2886 serialized_script_value = WebSerializedScriptValue::serialize(result_value);
2887 } else {
2888 serialized_script_value = WebSerializedScriptValue::fromString(params.data);
2889 }
2890
[email protected]f546640b2012-05-15 00:03:492891 // Create an event with the message. The final parameter to initMessageEvent
2892 // is the last event ID, which is not used with postMessage.
2893 WebDOMEvent event = frame->document().createEvent("MessageEvent");
2894 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
2895 msg_event.initMessageEvent("message",
2896 // |canBubble| and |cancellable| are always false
2897 false, false,
[email protected]afe7d90d2014-07-19 05:10:222898 serialized_script_value,
[email protected]0bc7f3542013-10-21 15:05:532899 params.source_origin, source_frame, "", channels);
[email protected]f546640b2012-05-15 00:03:492900
2901 // We must pass in the target_origin to do the security check on this side,
2902 // since it may have changed since the original postMessage call was made.
2903 WebSecurityOrigin target_origin;
2904 if (!params.target_origin.empty()) {
2905 target_origin =
2906 WebSecurityOrigin::createFromString(WebString(params.target_origin));
2907 }
2908 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
2909}
2910
[email protected]310ebd6302011-10-10 19:06:282911void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]940ed1d2012-11-27 21:03:212912 if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) &&
2913 !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) {
[email protected]69a0a132014-03-26 16:45:022914 // WebUIExtensionData deletes itself when we're destroyed.
[email protected]940ed1d2012-11-27 21:03:212915 new WebUIExtensionData(this);
[email protected]69a0a132014-03-26 16:45:022916 // WebUIMojo deletes itself when we're destroyed.
2917 new WebUIMojo(this);
[email protected]940ed1d2012-11-27 21:03:212918 }
2919
[email protected]81e63782009-02-27 19:35:092920 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:042921
2922 // Keep track of the total bindings accumulated in this process.
2923 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:292924}
2925
[email protected]dc293a72013-07-01 11:11:222926void RenderViewImpl::OnDragTargetDragEnter(const DropData& drop_data,
[email protected]310ebd6302011-10-10 19:06:282927 const gfx::Point& client_point,
2928 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:422929 WebDragOperationsMask ops,
2930 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:552931 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]dc293a72013-07-01 11:11:222932 DropDataToWebDragData(drop_data),
[email protected]59f4f2fa2011-03-23 01:00:552933 client_point,
2934 screen_point,
[email protected]1f2230b2012-05-17 23:43:422935 ops,
2936 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:552937
2938 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
2939}
2940
[email protected]310ebd6302011-10-10 19:06:282941void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
2942 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:422943 WebDragOperationsMask ops,
2944 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:552945 WebDragOperation operation = webview()->dragTargetDragOver(
2946 client_point,
2947 screen_point,
[email protected]1f2230b2012-05-17 23:43:422948 ops,
2949 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:552950
2951 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
2952}
2953
[email protected]310ebd6302011-10-10 19:06:282954void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:552955 webview()->dragTargetDragLeave();
2956}
2957
[email protected]310ebd6302011-10-10 19:06:282958void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
[email protected]1f2230b2012-05-17 23:43:422959 const gfx::Point& screen_point,
2960 int key_modifiers) {
2961 webview()->dragTargetDrop(client_point, screen_point, key_modifiers);
[email protected]fcad49452011-06-28 17:11:572962
2963 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:552964}
2965
[email protected]7a6d773f2014-04-04 01:25:092966void RenderViewImpl::OnDragSourceEnded(const gfx::Point& client_point,
2967 const gfx::Point& screen_point,
2968 WebDragOperation op) {
2969 webview()->dragSourceEndedAt(client_point, screen_point, op);
initial.commit09911bf2008-07-26 23:55:292970}
2971
[email protected]310ebd6302011-10-10 19:06:282972void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:272973 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:292974}
2975
[email protected]310ebd6302011-10-10 19:06:282976void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:592977 webkit_preferences_ = prefs;
[email protected]49a20002013-08-18 12:43:312978 ApplyWebPreferences(webkit_preferences_, webview());
initial.commit09911bf2008-07-26 23:55:292979}
2980
[email protected]310ebd6302011-10-10 19:06:282981void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:512982 int id,
[email protected]c42de732013-02-16 06:26:312983 const std::vector<base::FilePath>& paths) {
[email protected]600ea402011-04-12 00:01:512984 if (!enumeration_completions_[id])
2985 return;
2986
2987 WebVector<WebString> ws_file_names(paths.size());
2988 for (size_t i = 0; i < paths.size(); ++i)
[email protected]728c2ee2013-06-25 04:01:072989 ws_file_names[i] = paths[i].AsUTF16Unsafe();
[email protected]600ea402011-04-12 00:01:512990
2991 enumeration_completions_[id]->didChooseFile(ws_file_names);
2992 enumeration_completions_.erase(id);
2993}
2994
[email protected]fb11b6a42012-03-14 07:25:122995void RenderViewImpl::OnFileChooserResponse(
[email protected]ddb034b2012-06-26 20:31:392996 const std::vector<ui::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:362997 // This could happen if we navigated to a different page before the user
2998 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:472999 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363000 return;
3001
[email protected]b5188522012-03-15 00:18:043002 // Convert Chrome's SelectedFileInfo list to WebKit's.
3003 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
3004 files.size());
3005 for (size_t i = 0; i < files.size(); ++i) {
3006 WebFileChooserCompletion::SelectedFileInfo selected_file;
[email protected]728c2ee2013-06-25 04:01:073007 selected_file.path = files[i].local_path.AsUTF16Unsafe();
3008 selected_file.displayName =
3009 base::FilePath(files[i].display_name).AsUTF16Unsafe();
[email protected]b5188522012-03-15 00:18:043010 selected_files[i] = selected_file;
3011 }
[email protected]a1128322009-10-06 18:38:463012
[email protected]cdaf8d02010-03-30 19:52:473013 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:043014 file_chooser_completions_.front()->completion->didChooseFile(
3015 selected_files);
[email protected]cdaf8d02010-03-30 19:52:473016 file_chooser_completions_.pop_front();
3017
3018 // If there are more pending file chooser requests, schedule one now.
3019 if (!file_chooser_completions_.empty()) {
3020 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3021 file_chooser_completions_.front()->params));
3022 }
initial.commit09911bf2008-07-26 23:55:293023}
3024
[email protected]244ac1892011-12-02 17:04:473025void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
3026 const gfx::Size& max_size) {
3027 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
3028 if (!webview())
3029 return;
[email protected]97e1bf72013-03-06 14:06:053030 auto_resize_mode_ = true;
[email protected]61e2b3cc2012-03-02 16:13:343031 webview()->enableAutoResizeMode(min_size, max_size);
3032}
3033
3034void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
3035 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
3036 if (!webview())
3037 return;
[email protected]97e1bf72013-03-06 14:06:053038 auto_resize_mode_ = false;
[email protected]61e2b3cc2012-03-02 16:13:343039 webview()->disableAutoResizeMode();
3040
[email protected]eac2b362013-05-22 07:01:453041 if (!new_size.IsEmpty()) {
3042 Resize(new_size,
3043 physical_backing_size_,
[email protected]587941d2014-08-22 01:40:013044 top_controls_layout_height_,
[email protected]bb6378fe2014-04-28 21:19:443045 visible_viewport_size_,
[email protected]eac2b362013-05-22 07:01:453046 resizer_rect_,
3047 is_fullscreen_,
3048 NO_RESIZE_ACK);
3049 }
[email protected]244ac1892011-12-02 17:04:473050}
3051
[email protected]2bf834f2011-11-17 20:02:213052void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:243053 if (send_preferred_size_changes_)
3054 return;
[email protected]9fb325e2010-05-06 18:23:243055 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393056
[email protected]d812fd12011-05-27 23:05:073057 // Start off with an initial preferred size notification (in case
3058 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:593059 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:083060}
3061
[email protected]310ebd6302011-10-10 19:06:283062void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:103063 const gfx::Size& disable_scrollbar_size_limit) {
3064 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3065}
3066
[email protected]310ebd6302011-10-10 19:06:283067void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:263068 const RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:503069 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]ebd5ea52014-05-28 14:51:153070 std::string old_accept_languages = renderer_preferences_.accept_languages;
3071
[email protected]80d96fa2009-06-10 22:34:513072 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373073 UpdateFontRenderingFromRendererPrefs();
[email protected]38a85712013-01-02 22:45:023074
[email protected]dcc297772014-04-10 22:20:523075#if defined(USE_DEFAULT_RENDER_THEME)
[email protected]1596efb2013-01-17 22:13:013076 if (renderer_prefs.use_custom_colors) {
[email protected]180ef242013-11-07 06:50:463077 WebColorName name = blink::WebColorWebkitFocusRingColor;
3078 blink::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
3079 blink::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]1596efb2013-01-17 22:13:013080
3081 if (webview()) {
[email protected]1596efb2013-01-17 22:13:013082 webview()->setSelectionColors(
3083 renderer_prefs.active_selection_bg_color,
3084 renderer_prefs.active_selection_fg_color,
3085 renderer_prefs.inactive_selection_bg_color,
3086 renderer_prefs.inactive_selection_fg_color);
3087 webview()->themeChanged();
3088 }
[email protected]644d77e2010-01-27 01:03:103089 }
[email protected]c997bc42014-04-11 18:25:583090#endif // defined(USE_DEFAULT_RENDER_THEME)
[email protected]d299d972012-03-23 02:26:553091
[email protected]107c0532013-02-06 02:34:093092 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
3093 RenderThreadImpl::current()->SetFlingCurveParameters(
3094 renderer_prefs.touchpad_fling_profile,
3095 renderer_prefs.touchscreen_fling_profile);
3096
[email protected]d051d9a2011-12-10 02:02:503097 // If the zoom level for this page matches the old zoom default, and this
3098 // is not a plugin, update the zoom level to match the new default.
[email protected]82307f6b2014-08-07 03:30:123099 if (webview() && webview()->mainFrame()->isWebLocalFrame() &&
3100 !webview()->mainFrame()->document().isPluginDocument() &&
[email protected]cbe55d22013-02-14 17:04:333101 !ZoomValuesEqual(old_zoom_level,
3102 renderer_preferences_.default_zoom_level) &&
[email protected]e9ff79c2012-10-19 21:31:263103 ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
[email protected]91219702013-09-18 07:33:513104 webview()->setZoomLevel(renderer_preferences_.default_zoom_level);
[email protected]d051d9a2011-12-10 02:02:503105 zoomLevelChanged();
3106 }
[email protected]ebd5ea52014-05-28 14:51:153107
3108 if (webview() &&
3109 old_accept_languages != renderer_preferences_.accept_languages) {
3110 webview()->acceptLanguagesChanged();
3111 }
[email protected]80d96fa2009-06-10 22:34:513112}
3113
[email protected]310ebd6302011-10-10 19:06:283114void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
3115 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:283116 if (webview())
3117 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563118}
3119
[email protected]fcdc5642014-05-09 14:32:243120void RenderViewImpl::OnOrientationChange() {
3121 // TODO(mlamouri): consumers of that event should be using DisplayObserver.
[email protected]652ad832013-08-16 11:47:043122 FOR_EACH_OBSERVER(RenderViewObserver,
3123 observers_,
[email protected]fcdc5642014-05-09 14:32:243124 OrientationChangeEvent());
3125
3126 webview()->mainFrame()->sendOrientationChangeEvent();
[email protected]77829642012-05-15 14:47:173127}
3128
[email protected]81375e872012-01-11 21:40:363129void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
3130 const WebPluginAction& action) {
3131 if (webview())
3132 webview()->performPluginAction(action, location);
3133}
3134
[email protected]310ebd6302011-10-10 19:06:283135void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:193136 const GURL& page_url) {
3137 // Prepare list to storage all savable resource links.
3138 std::vector<GURL> resources_list;
[email protected]c2d986512012-05-12 00:22:463139 std::vector<GURL> referrer_urls_list;
[email protected]180ef242013-11-07 06:50:463140 std::vector<blink::WebReferrerPolicy> referrer_policies_list;
[email protected]18d5be92011-07-25 18:00:193141 std::vector<GURL> frames_list;
[email protected]12a936d2013-05-15 04:55:493142 SavableResourcesResult result(&resources_list,
3143 &referrer_urls_list,
3144 &referrer_policies_list,
3145 &frames_list);
[email protected]18d5be92011-07-25 18:00:193146
[email protected]e9ff79c2012-10-19 21:31:263147 // webkit/ doesn't know about Referrer.
[email protected]12a936d2013-05-15 04:55:493148 if (!GetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:193149 webview(),
3150 page_url,
3151 &result,
[email protected]e9ff79c2012-10-19 21:31:263152 const_cast<const char**>(GetSavableSchemes()))) {
[email protected]18d5be92011-07-25 18:00:193153 // If something is wrong when collecting all savable resource links,
3154 // send empty list to embedder(browser) to tell it failed.
[email protected]c2d986512012-05-12 00:22:463155 referrer_urls_list.clear();
3156 referrer_policies_list.clear();
[email protected]18d5be92011-07-25 18:00:193157 resources_list.clear();
3158 frames_list.clear();
3159 }
3160
[email protected]e9ff79c2012-10-19 21:31:263161 std::vector<Referrer> referrers_list;
[email protected]c2d986512012-05-12 00:22:463162 CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size());
3163 for (unsigned i = 0; i < referrer_urls_list.size(); ++i) {
3164 referrers_list.push_back(
[email protected]e9ff79c2012-10-19 21:31:263165 Referrer(referrer_urls_list[i], referrer_policies_list[i]));
[email protected]c2d986512012-05-12 00:22:463166 }
3167
[email protected]18d5be92011-07-25 18:00:193168 // Send result of all savable resource links to embedder.
3169 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
3170 resources_list,
3171 referrers_list,
3172 frames_list));
3173}
3174
[email protected]310ebd6302011-10-10 19:06:283175void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:193176 const std::vector<GURL>& links,
[email protected]c42de732013-02-16 06:26:313177 const std::vector<base::FilePath>& local_paths,
3178 const base::FilePath& local_directory_name) {
[email protected]18d5be92011-07-25 18:00:193179
3180 // Convert std::vector of GURLs to WebVector<WebURL>
3181 WebVector<WebURL> weburl_links(links);
3182
[email protected]728c2ee2013-06-25 04:01:073183 // Convert std::vector of base::FilePath to WebVector<WebString>
[email protected]18d5be92011-07-25 18:00:193184 WebVector<WebString> webstring_paths(local_paths.size());
3185 for (size_t i = 0; i < local_paths.size(); i++)
[email protected]728c2ee2013-06-25 04:01:073186 webstring_paths[i] = local_paths[i].AsUTF16Unsafe();
[email protected]18d5be92011-07-25 18:00:193187
[email protected]35b2a972014-04-04 15:50:223188 WebPageSerializer::serialize(webview()->mainFrame()->toWebLocalFrame(),
3189 true,
3190 this,
3191 weburl_links,
[email protected]18d5be92011-07-25 18:00:193192 webstring_paths,
[email protected]728c2ee2013-06-25 04:01:073193 local_directory_name.AsUTF16Unsafe());
[email protected]18d5be92011-07-25 18:00:193194}
3195
[email protected]88f10a22013-11-06 21:22:123196void RenderViewImpl::OnSuppressDialogsUntilSwapOut() {
3197 // Don't show any more dialogs until we finish OnSwapOut.
3198 suppress_dialogs_until_swap_out_ = true;
3199}
3200
[email protected]180ef242013-11-07 06:50:463201void RenderViewImpl::NavigateToSwappedOutURL(blink::WebFrame* frame) {
[email protected]14392a52012-05-02 20:28:443202 // We use loadRequest instead of loadHTMLString because the former commits
3203 // synchronously. Otherwise a new navigation can interrupt the navigation
[email protected]e9ff79c2012-10-19 21:31:263204 // to kSwappedOutURL. If that happens to be to the page we had been
[email protected]14392a52012-05-02 20:28:443205 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]b70da4c2014-01-06 19:57:093206 // TODO(creis): Until we move this to RenderFrame, we may call this from a
3207 // swapped out RenderFrame while our own is_swapped_out_ is false.
[email protected]a5ac6dc2014-01-15 07:02:143208 RenderFrameImpl* rf = RenderFrameImpl::FromWebFrame(frame);
[email protected]b70da4c2014-01-06 19:57:093209 CHECK(is_swapped_out_ || rf->is_swapped_out());
[email protected]e9ff79c2012-10-19 21:31:263210 GURL swappedOutURL(kSwappedOutURL);
[email protected]14392a52012-05-02 20:28:443211 WebURLRequest request(swappedOutURL);
[email protected]82307f6b2014-08-07 03:30:123212 if (frame->isWebLocalFrame())
3213 frame->loadRequest(request);
[email protected]14392a52012-05-02 20:28:443214}
3215
[email protected]310ebd6302011-10-10 19:06:283216void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:373217 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:293218 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3219 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3220 // in the onunload handler from appearing. For now, we're bypassing that and
3221 // calling the FrameLoader's CloseURL method directly. This should be
3222 // revisited to avoid having two ways to close a page. Having a single way
3223 // to close that can run onunload is also useful for fixing
3224 // http://b/issue?id=753080.
[email protected]11fd5db2014-04-02 03:49:463225 webview()->mainFrame()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293226
[email protected]992db4c2011-05-12 15:37:153227 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:293228}
3229
[email protected]310ebd6302011-10-10 19:06:283230void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:023231#if defined(USE_AURA)
3232 // Aura doesn't care if we switch themes.
3233#elif defined(OS_WIN)
[email protected]f78452f2012-05-15 02:07:523234 ui::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:463235 if (webview())
3236 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:573237#else // defined(OS_WIN)
3238 // TODO(port): we don't support theming on non-Windows platforms yet
3239 NOTIMPLEMENTED();
3240#endif
initial.commit09911bf2008-07-26 23:55:293241}
3242
[email protected]310ebd6302011-10-10 19:06:283243void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:003244 if (webview())
[email protected]a72a1fa2010-05-03 22:18:473245 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:003246}
3247
[email protected]0fdd5012013-05-29 08:05:563248void RenderViewImpl::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]189a8862014-07-18 00:27:533249 TRACE_EVENT0("renderer", "RenderViewImpl::OnResize");
[email protected]cda45c02010-02-25 19:28:103250 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:473251 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:103252 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:203253 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]0fdd5012013-05-29 08:05:563254 ShouldDisplayScrollbars(params.new_size.width(),
3255 params.new_size.height()));
[email protected]cda45c02010-02-25 19:28:103256 }
3257 }
3258
[email protected]cbbdeef2014-05-26 15:57:363259 gfx::Size old_visible_viewport_size = visible_viewport_size_;
3260
[email protected]0fdd5012013-05-29 08:05:563261 RenderWidget::OnResize(params);
[email protected]cbbdeef2014-05-26 15:57:363262
3263 if (old_visible_viewport_size != visible_viewport_size_)
3264 has_scrolled_focused_editable_node_into_rect_ = false;
estade48c85882014-08-25 18:26:503265
3266 FOR_EACH_OBSERVER(RenderViewObserver,
3267 observers_,
3268 Resized());
[email protected]30f75e62009-02-25 22:01:003269}
[email protected]0aa477bd2009-03-23 22:21:433270
[email protected]310ebd6302011-10-10 19:06:283271void RenderViewImpl::DidInitiatePaint() {
[email protected]ea2fb972013-08-07 05:44:263272#if defined(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:573273 // Notify all instances that we painted. The same caveats apply as for
3274 // ViewFlushedPaint regarding instances closing themselves, so we take
3275 // similar precautions.
3276 PepperPluginSet plugins = active_pepper_instances_;
3277 for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) {
3278 if (active_pepper_instances_.find(*i) != active_pepper_instances_.end())
3279 (*i)->ViewInitiatedPaint();
3280 }
[email protected]ea2fb972013-08-07 05:44:263281#endif
[email protected]00c39612010-03-06 02:53:283282}
3283
[email protected]310ebd6302011-10-10 19:06:283284void RenderViewImpl::DidFlushPaint() {
[email protected]ea2fb972013-08-07 05:44:263285#if defined(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:573286 // Notify all instances that we flushed. This will call into the plugin, and
3287 // we it may ask to close itself as a result. This will, in turn, modify our
3288 // set, possibly invalidating the iterator. So we iterate on a copy that
3289 // won't change out from under us.
3290 PepperPluginSet plugins = active_pepper_instances_;
3291 for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) {
3292 // The copy above makes sure our iterator is never invalid if some plugins
3293 // are destroyed. But some plugin may decide to close all of its views in
3294 // response to a paint in one of them, so we need to make sure each one is
3295 // still "current" before using it.
3296 //
3297 // It's possible that a plugin was destroyed, but another one was created
3298 // with the same address. In this case, we'll call ViewFlushedPaint on that
3299 // new plugin. But that's OK for this particular case since we're just
3300 // notifying all of our instances that the view flushed, and the new one is
3301 // one of our instances.
3302 //
3303 // What about the case where a new one is created in a callback at a new
3304 // address and we don't issue the callback? We're still OK since this
3305 // callback is used for flush callbacks and we could not have possibly
3306 // started a new paint for the new plugin while processing a previous paint
3307 // for an existing one.
3308 if (active_pepper_instances_.find(*i) != active_pepper_instances_.end())
3309 (*i)->ViewFlushedPaint();
3310 }
[email protected]ea2fb972013-08-07 05:44:263311#endif
[email protected]53900d52010-06-16 04:25:013312
[email protected]5b1dec8c2012-02-07 04:35:383313 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
3314 // See crbug.com/112921.
3315 if (!webview())
3316 return;
3317
[email protected]00c39612010-03-06 02:53:283318 WebFrame* main_frame = webview()->mainFrame();
[email protected]82307f6b2014-08-07 03:30:123319 for (WebFrame* frame = main_frame; frame;
3320 frame = frame->traverseNext(false)) {
3321 if (frame->isWebLocalFrame())
3322 main_frame = frame;
3323 }
[email protected]00c39612010-03-06 02:53:283324
3325 // If we have a provisional frame we are between the start and commit stages
3326 // of loading and we don't want to save stats.
3327 if (!main_frame->provisionalDataSource()) {
3328 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:073329 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]92d457802013-04-01 19:18:493330
[email protected]05c8e502010-08-15 15:13:523331 // TODO(jar): The following code should all be inside a method, probably in
3332 // NavigatorState.
[email protected]00c39612010-03-06 02:53:283333 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:073334 if (document_state->first_paint_time().is_null()) {
3335 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:283336 }
[email protected]007733c2011-11-17 00:34:073337 if (document_state->first_paint_after_load_time().is_null() &&
3338 !document_state->finish_load_time().is_null()) {
3339 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:283340 }
3341 }
3342}
3343
[email protected]ceb36f7d2012-10-31 18:33:243344gfx::Vector2d RenderViewImpl::GetScrollOffset() {
[email protected]82307f6b2014-08-07 03:30:123345 WebFrame* main_frame = webview()->mainFrame();
3346 for (WebFrame* frame = main_frame; frame;
3347 frame = frame->traverseNext(false)) {
3348 // TODO(nasko): This is a hack for the case in which the top-level
3349 // frame is being rendered in another process. It will not
3350 // behave correctly for out of process iframes.
3351 if (frame->isWebLocalFrame()) {
3352 main_frame = frame;
3353 break;
3354 }
3355 }
3356
3357 WebSize scroll_offset = main_frame->scrollOffset();
[email protected]ceb36f7d2012-10-31 18:33:243358 return gfx::Vector2d(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:523359}
3360
[email protected]ab6c9112014-02-27 00:20:583361void RenderViewImpl::OnClearFocusedElement() {
[email protected]05d478752009-04-08 23:38:163362 if (webview())
[email protected]ab6c9112014-02-27 00:20:583363 webview()->clearFocusedElement();
[email protected]05d478752009-04-08 23:38:163364}
3365
[email protected]61f91832014-05-13 01:24:423366void RenderViewImpl::OnSetBackgroundOpaque(bool opaque) {
[email protected]699ab0d2009-04-23 23:19:143367 if (webview())
[email protected]61f91832014-05-13 01:24:423368 webview()->setIsTransparent(!opaque);
[email protected]ba91a792013-02-06 09:48:283369 if (compositor_)
[email protected]61f91832014-05-13 01:24:423370 compositor_->setHasTransparentBackground(!opaque);
[email protected]699ab0d2009-04-23 23:19:143371}
3372
[email protected]310ebd6302011-10-10 19:06:283373void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:343374 if (webview())
[email protected]b4bb2502009-10-01 22:35:273375 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:263376
[email protected]a80af12e2013-08-07 23:36:133377#if defined(ENABLE_PLUGINS) && defined(OS_MACOSX)
[email protected]d8fd6fa2010-02-01 15:54:263378 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3379 for (plugin_it = plugin_delegates_.begin();
3380 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3381 (*plugin_it)->SetWindowFocus(active);
3382 }
3383#endif
[email protected]8c66c5a2009-07-22 17:26:343384}
3385
[email protected]6ce7abc52010-02-02 18:40:143386#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:283387void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]a80af12e2013-08-07 23:36:133388#if defined(ENABLE_PLUGINS)
[email protected]6ce7abc52010-02-02 18:40:143389 // Inform plugins that their container has changed visibility.
3390 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3391 for (plugin_it = plugin_delegates_.begin();
3392 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3393 (*plugin_it)->SetContainerVisibility(visible);
3394 }
[email protected]a80af12e2013-08-07 23:36:133395#endif
[email protected]6ce7abc52010-02-02 18:40:143396}
[email protected]1e6e3c992010-02-08 15:52:133397
[email protected]310ebd6302011-10-10 19:06:283398void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
3399 const gfx::Rect& view_frame) {
[email protected]a80af12e2013-08-07 23:36:133400#if defined(ENABLE_PLUGINS)
[email protected]1e6e3c992010-02-08 15:52:133401 // Inform plugins that their window's frame has changed.
3402 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3403 for (plugin_it = plugin_delegates_.begin();
3404 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3405 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
3406 }
[email protected]a80af12e2013-08-07 23:36:133407#endif
[email protected]1e6e3c992010-02-08 15:52:133408}
[email protected]935d63d2010-10-15 23:31:553409
[email protected]fcf75d42013-12-03 20:11:263410void RenderViewImpl::OnPluginImeCompositionCompleted(const base::string16& text,
[email protected]310ebd6302011-10-10 19:06:283411 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:133412 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:553413 // applies to it or not, so inform all the delegates.
3414 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3415 for (plugin_it = plugin_delegates_.begin();
3416 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:133417 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:553418 }
3419}
[email protected]6ce7abc52010-02-02 18:40:143420#endif // OS_MACOSX
3421
[email protected]6de7fc482014-06-06 10:46:443422void RenderViewImpl::OnClose() {
3423 if (closing_)
3424 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(routing_id_));
3425 RenderWidget::OnClose();
3426}
3427
[email protected]310ebd6302011-10-10 19:06:283428void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:593429 // We need to grab a pointer to the doomed WebView before we destroy it.
3430 WebView* doomed = webview();
3431 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:493432 g_view_map.Get().erase(doomed);
[email protected]058561b2012-12-03 06:48:223433 g_routing_id_view_map.Get().erase(routing_id_);
[email protected]6de7fc482014-06-06 10:46:443434 RenderThread::Get()->Send(new ViewHostMsg_Close_ACK(routing_id_));
[email protected]60c42a8c72009-10-09 04:08:593435}
3436
[email protected]310ebd6302011-10-10 19:06:283437void RenderViewImpl::DidHandleKeyEvent() {
[email protected]b2324b092012-11-01 10:34:113438 ClearEditCommands();
[email protected]446705872009-09-10 07:22:483439}
3440
[email protected]180ef242013-11-07 06:50:463441bool RenderViewImpl::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]41d86852012-11-07 12:23:243442 possible_drag_event_info_.event_source =
3443 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
3444 possible_drag_event_info_.event_location =
3445 gfx::Point(event.globalX, event.globalY);
[email protected]ea2fb972013-08-07 05:44:263446
3447#if defined(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:573448 // This method is called for every mouse event that the render view receives.
3449 // And then the mouse event is forwarded to WebKit, which dispatches it to the
3450 // event target. Potentially a Pepper plugin will receive the event.
3451 // In order to tell whether a plugin gets the last mouse event and which it
3452 // is, we set |pepper_last_mouse_event_target_| to NULL here. If a plugin gets
3453 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
3454 // |pepper_last_mouse_event_target_|.
3455 pepper_last_mouse_event_target_ = NULL;
[email protected]ea2fb972013-08-07 05:44:263456#endif
[email protected]217690d2012-01-27 07:33:113457
3458 // If the mouse is locked, only the current owner of the mouse lock can
3459 // process mouse events.
3460 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:373461}
3462
[email protected]41d86852012-11-07 12:23:243463bool RenderViewImpl::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:463464 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:243465 possible_drag_event_info_.event_source =
3466 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
3467 possible_drag_event_info_.event_location =
3468 gfx::Point(event.globalX, event.globalY);
3469 return false;
3470}
3471
[email protected]2b942c332012-04-25 16:26:263472void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:513473 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:063474}
3475
[email protected]310ebd6302011-10-10 19:06:283476void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:243477 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
3478}
3479
[email protected]3d5c243b2012-11-30 00:26:013480bool RenderViewImpl::HasTouchEventHandlersAt(const gfx::Point& point) const {
3481 if (!webview())
3482 return false;
3483 return webview()->hasTouchEventHandlersAt(point);
3484}
3485
[email protected]310ebd6302011-10-10 19:06:283486void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:433487 RenderWidget::OnWasHidden();
3488
[email protected]68877c282013-09-20 05:52:423489#if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
[email protected]6392d982013-04-16 16:59:223490 RenderThreadImpl::current()->video_capture_impl_manager()->
3491 SuspendDevices(true);
[email protected]e976c3c52014-07-24 17:41:553492 if (speech_recognition_dispatcher_)
3493 speech_recognition_dispatcher_->AbortAllRecognitions();
[email protected]6392d982013-04-16 16:59:223494#endif
[email protected]2d7b82c2012-06-01 05:57:503495
[email protected]8869d392013-05-07 15:34:263496 if (webview())
[email protected]f59203a2011-06-07 10:01:443497 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:073498
[email protected]ea2fb972013-08-07 05:44:263499#if defined(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:573500 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
3501 i != active_pepper_instances_.end(); ++i)
3502 (*i)->PageVisibilityChanged(false);
[email protected]204f1df2012-01-04 20:21:133503
[email protected]a6939ca42011-02-18 17:58:073504#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:133505 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:433506 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3507 for (plugin_it = plugin_delegates_.begin();
3508 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3509 (*plugin_it)->SetContainerVisibility(false);
3510 }
[email protected]a6939ca42011-02-18 17:58:073511#endif // OS_MACOSX
[email protected]a80af12e2013-08-07 23:36:133512#endif // ENABLE_PLUGINS
[email protected]941e4552010-02-01 21:23:433513}
3514
[email protected]3399dd822014-08-09 11:14:243515void RenderViewImpl::OnWasShown(bool needs_repainting,
3516 const ui::LatencyInfo& latency_info) {
3517 RenderWidget::OnWasShown(needs_repainting, latency_info);
[email protected]941e4552010-02-01 21:23:433518
[email protected]6392d982013-04-16 16:59:223519#if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
3520 RenderThreadImpl::current()->video_capture_impl_manager()->
3521 SuspendDevices(false);
3522#endif
3523
[email protected]8869d392013-05-07 15:34:263524 if (webview())
[email protected]f59203a2011-06-07 10:01:443525 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:073526
[email protected]ea2fb972013-08-07 05:44:263527#if defined(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:573528 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
3529 i != active_pepper_instances_.end(); ++i)
3530 (*i)->PageVisibilityChanged(true);
[email protected]204f1df2012-01-04 20:21:133531
[email protected]a6939ca42011-02-18 17:58:073532#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:133533 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:433534 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3535 for (plugin_it = plugin_delegates_.begin();
3536 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3537 (*plugin_it)->SetContainerVisibility(true);
3538 }
[email protected]784ea1ab2010-09-18 00:02:343539#endif // OS_MACOSX
[email protected]a80af12e2013-08-07 23:36:133540#endif // ENABLE_PLUGINS
[email protected]a6939ca42011-02-18 17:58:073541}
[email protected]1e6e3c992010-02-08 15:52:133542
[email protected]ed7defa2013-03-12 21:29:593543GURL RenderViewImpl::GetURLForGraphicsContext3D() {
3544 DCHECK(webview());
[email protected]82307f6b2014-08-07 03:30:123545 if (webview()->mainFrame()->isWebLocalFrame())
[email protected]ed7defa2013-03-12 21:29:593546 return GURL(webview()->mainFrame()->document().url());
3547 else
3548 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]65225772011-05-12 21:10:243549}
3550
[email protected]310ebd6302011-10-10 19:06:283551void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:133552 RenderWidget::OnSetFocus(enable);
3553
[email protected]a80af12e2013-08-07 23:36:133554#if defined(ENABLE_PLUGINS)
[email protected]7d3c02c2010-05-05 23:10:313555 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:073556 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:133557 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3558 for (plugin_it = plugin_delegates_.begin();
3559 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:343560#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:313561 // RenderWidget's call to setFocus can cause the underlying webview's
3562 // activation state to change just like a call to setIsActive.
3563 if (enable)
3564 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:343565#endif
[email protected]7d3c02c2010-05-05 23:10:313566 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:133567 }
3568 }
[email protected]a99a38802014-01-14 15:46:573569 // Notify all Pepper plugins.
3570 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
3571 i != active_pepper_instances_.end(); ++i)
3572 (*i)->SetContentAreaFocus(enable);
[email protected]ea2fb972013-08-07 05:44:263573#endif
[email protected]321032992012-11-08 01:01:273574 // Notify all BrowserPlugins of the RenderView's focus state.
[email protected]fc72bb12013-06-02 21:13:463575 if (browser_plugin_manager_.get())
[email protected]caaf2482013-05-01 20:33:323576 browser_plugin_manager_->UpdateFocusState();
[email protected]1e6e3c992010-02-08 15:52:133577}
[email protected]941e4552010-02-01 21:23:433578
[email protected]310ebd6302011-10-10 19:06:283579void RenderViewImpl::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:263580 const base::string16& text,
[email protected]180ef242013-11-07 06:50:463581 const std::vector<blink::WebCompositionUnderline>& underlines,
[email protected]56ea1a62011-05-30 07:05:573582 int selection_start,
3583 int selection_end) {
[email protected]ea2fb972013-08-07 05:44:263584#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083585 if (focused_pepper_plugin_) {
3586 focused_pepper_plugin_->render_frame()->OnImeSetComposition(
[email protected]7a4e2532013-12-02 21:30:023587 text, underlines, selection_start, selection_end);
[email protected]ea2fb972013-08-07 05:44:263588 return;
[email protected]56ea1a62011-05-30 07:05:573589 }
[email protected]ea2fb972013-08-07 05:44:263590
3591#if defined(OS_WIN)
3592 // When a plug-in has focus, we create platform-specific IME data used by
3593 // our IME emulator and send it directly to the focused plug-in, i.e. we
3594 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
3595 // instance ID is the same one as the specified ID.)
3596 if (focused_plugin_id_ >= 0) {
3597 std::vector<int> clauses;
3598 std::vector<int> target;
3599 for (size_t i = 0; i < underlines.size(); ++i) {
3600 clauses.push_back(underlines[i].startOffset);
3601 clauses.push_back(underlines[i].endOffset);
3602 if (underlines[i].thick) {
3603 target.clear();
3604 target.push_back(underlines[i].startOffset);
3605 target.push_back(underlines[i].endOffset);
3606 }
3607 }
3608 std::set<WebPluginDelegateProxy*>::iterator it;
3609 for (it = plugin_delegates_.begin(); it != plugin_delegates_.end(); ++it) {
3610 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
3611 focused_plugin_id_);
3612 }
3613 return;
3614 }
[email protected]a80af12e2013-08-07 23:36:133615#endif // OS_WIN
3616#endif // ENABLE_PLUGINS
[email protected]ea2fb972013-08-07 05:44:263617 RenderWidget::OnImeSetComposition(text,
3618 underlines,
3619 selection_start,
3620 selection_end);
[email protected]56ea1a62011-05-30 07:05:573621}
3622
[email protected]db4fc1e2013-09-06 20:01:513623void RenderViewImpl::OnImeConfirmComposition(
[email protected]fcf75d42013-12-03 20:11:263624 const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:513625 const gfx::Range& replacement_range,
3626 bool keep_selection) {
[email protected]ea2fb972013-08-07 05:44:263627#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083628 if (focused_pepper_plugin_) {
3629 focused_pepper_plugin_->render_frame()->OnImeConfirmComposition(
[email protected]7a4e2532013-12-02 21:30:023630 text, replacement_range, keep_selection);
[email protected]ea2fb972013-08-07 05:44:263631 return;
[email protected]56ea1a62011-05-30 07:05:573632 }
[email protected]ea2fb972013-08-07 05:44:263633#if defined(OS_WIN)
3634 // Same as OnImeSetComposition(), we send the text from IMEs directly to
3635 // plug-ins. When we send IME text directly to plug-ins, we should not send
3636 // it to WebKit to prevent WebKit from controlling IMEs.
3637 // TODO(thakis): Honor |replacement_range| for plugins?
3638 if (focused_plugin_id_ >= 0) {
3639 std::set<WebPluginDelegateProxy*>::iterator it;
3640 for (it = plugin_delegates_.begin();
3641 it != plugin_delegates_.end(); ++it) {
3642 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
3643 }
3644 return;
3645 }
[email protected]a80af12e2013-08-07 23:36:133646#endif // OS_WIN
3647#endif // ENABLE_PLUGINS
[email protected]ea2fb972013-08-07 05:44:263648 if (replacement_range.IsValid() && webview()) {
3649 // Select the text in |replacement_range|, it will then be replaced by
3650 // text added by the call to RenderWidget::OnImeConfirmComposition().
[email protected]35b2a972014-04-04 15:50:223651 if (WebLocalFrame* frame = webview()->focusedFrame()->toWebLocalFrame()) {
[email protected]ea2fb972013-08-07 05:44:263652 WebRange webrange = WebRange::fromDocumentRange(
3653 frame, replacement_range.start(), replacement_range.length());
3654 if (!webrange.isNull())
3655 frame->selectRange(webrange);
3656 }
3657 }
3658 RenderWidget::OnImeConfirmComposition(text,
3659 replacement_range,
3660 keep_selection);
[email protected]56ea1a62011-05-30 07:05:573661}
3662
[email protected]468ac582012-11-20 00:53:193663void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor) {
3664 RenderWidget::SetDeviceScaleFactor(device_scale_factor);
[email protected]fb854192013-02-06 01:30:043665 if (webview()) {
[email protected]dea5e7682012-06-14 05:21:243666 webview()->setDeviceScaleFactor(device_scale_factor);
[email protected]b8ec1112014-08-17 20:09:103667 webview()->settings()->setPreferCompositingToLCDTextEnabled(
3668 PreferCompositingToLCDText(device_scale_factor_));
[email protected]d8221b22013-05-23 05:35:433669 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
3670 ShouldUseTransitionCompositing(device_scale_factor_));
[email protected]fb854192013-02-06 01:30:043671 }
[email protected]3a1c8a8032013-03-18 22:35:323672 if (auto_resize_mode_)
3673 AutoResizeCompositor();
[email protected]caaf2482013-05-01 20:33:323674
[email protected]fc72bb12013-06-02 21:13:463675 if (browser_plugin_manager_.get())
fsamuel2f5c8d62014-09-03 21:02:323676 browser_plugin_manager_->UpdateDeviceScaleFactor();
[email protected]dea5e7682012-06-14 05:21:243677}
3678
[email protected]28ed6b32014-06-08 02:16:273679bool RenderViewImpl::SetDeviceColorProfile(
3680 const std::vector<char>& profile) {
3681 bool changed = RenderWidget::SetDeviceColorProfile(profile);
3682 if (changed && webview()) {
3683 // TODO(noel): notify the webview() of the color profile change so it
3684 // can update and repaint all color profiled page elements.
3685 }
3686 return changed;
3687}
3688
[email protected]310ebd6302011-10-10 19:06:283689ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]ea2fb972013-08-07 05:44:263690#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083691 if (focused_pepper_plugin_)
3692 return focused_pepper_plugin_->text_input_type();
[email protected]ea2fb972013-08-07 05:44:263693#endif
3694 return RenderWidget::GetTextInputType();
[email protected]73bf95812011-10-12 11:38:323695}
3696
[email protected]3f783362011-10-21 22:40:503697void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
[email protected]ea2fb972013-08-07 05:44:263698#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083699 if (focused_pepper_plugin_) {
[email protected]3f783362011-10-21 22:40:503700 // TODO(kinaba) http://crbug.com/101101
3701 // Current Pepper IME API does not handle selection bounds. So we simply
3702 // use the caret position as an empty range for now. It will be updated
3703 // after Pepper API equips features related to surrounding text retrieval.
[email protected]e16c7a12013-12-05 16:30:083704 gfx::Rect caret = focused_pepper_plugin_->GetCaretBounds();
[email protected]3f783362011-10-21 22:40:503705 *start = caret;
3706 *end = caret;
3707 return;
3708 }
[email protected]ea2fb972013-08-07 05:44:263709#endif
[email protected]3f783362011-10-21 22:40:503710 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:453711}
3712
[email protected]f9db7d2d2014-04-11 16:07:113713#if defined(OS_MACOSX) || defined(USE_AURA)
[email protected]58b48a0d2012-06-13 07:01:353714void RenderViewImpl::GetCompositionCharacterBounds(
3715 std::vector<gfx::Rect>* bounds) {
3716 DCHECK(bounds);
3717 bounds->clear();
3718
[email protected]ea2fb972013-08-07 05:44:263719#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083720 if (focused_pepper_plugin_) {
[email protected]88dbe32f2013-06-20 23:31:363721 return;
3722 }
[email protected]ea2fb972013-08-07 05:44:263723#endif
3724
[email protected]58b48a0d2012-06-13 07:01:353725 if (!webview())
3726 return;
3727 size_t start_offset = 0;
3728 size_t character_count = 0;
3729 if (!webview()->compositionRange(&start_offset, &character_count))
3730 return;
3731 if (character_count == 0)
3732 return;
3733
[email protected]180ef242013-11-07 06:50:463734 blink::WebFrame* frame = webview()->focusedFrame();
[email protected]58b48a0d2012-06-13 07:01:353735 if (!frame)
3736 return;
3737
3738 bounds->reserve(character_count);
[email protected]180ef242013-11-07 06:50:463739 blink::WebRect webrect;
[email protected]58b48a0d2012-06-13 07:01:353740 for (size_t i = 0; i < character_count; ++i) {
3741 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
3742 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
3743 bounds->clear();
3744 return;
3745 }
3746 bounds->push_back(webrect);
3747 }
3748}
3749
[email protected]db4fc1e2013-09-06 20:01:513750void RenderViewImpl::GetCompositionRange(gfx::Range* range) {
[email protected]ea2fb972013-08-07 05:44:263751#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083752 if (focused_pepper_plugin_) {
[email protected]88dbe32f2013-06-20 23:31:363753 return;
3754 }
[email protected]ea2fb972013-08-07 05:44:263755#endif
[email protected]88dbe32f2013-06-20 23:31:363756 RenderWidget::GetCompositionRange(range);
3757}
[email protected]501ea13d2013-07-09 17:03:293758#endif
[email protected]88dbe32f2013-06-20 23:31:363759
[email protected]310ebd6302011-10-10 19:06:283760bool RenderViewImpl::CanComposeInline() {
[email protected]ea2fb972013-08-07 05:44:263761#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083762 if (focused_pepper_plugin_)
3763 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
[email protected]ea2fb972013-08-07 05:44:263764#endif
3765 return true;
[email protected]56ea1a62011-05-30 07:05:573766}
3767
[email protected]33004772013-11-12 09:49:233768void RenderViewImpl::InstrumentWillBeginFrame(int frame_id) {
[email protected]35134e12013-02-22 20:07:403769 if (!webview())
3770 return;
3771 if (!webview()->devToolsAgent())
3772 return;
[email protected]33004772013-11-12 09:49:233773 webview()->devToolsAgent()->didBeginFrame(frame_id);
[email protected]35134e12013-02-22 20:07:403774}
3775
3776void RenderViewImpl::InstrumentDidBeginFrame() {
3777 if (!webview())
3778 return;
3779 if (!webview()->devToolsAgent())
3780 return;
3781 // TODO(jamesr/caseq): Decide if this needs to be renamed.
3782 webview()->devToolsAgent()->didComposite();
3783}
3784
3785void RenderViewImpl::InstrumentDidCancelFrame() {
3786 if (!webview())
3787 return;
3788 if (!webview()->devToolsAgent())
3789 return;
3790 webview()->devToolsAgent()->didCancelFrame();
3791}
3792
3793void RenderViewImpl::InstrumentWillComposite() {
3794 if (!webview())
3795 return;
3796 if (!webview()->devToolsAgent())
3797 return;
3798 webview()->devToolsAgent()->willComposite();
3799}
3800
[email protected]b2e4c70132013-10-03 02:07:513801void RenderViewImpl::SetScreenMetricsEmulationParameters(
[email protected]7f99fc22013-11-08 14:05:583802 float device_scale_factor,
3803 const gfx::Point& root_layer_offset,
3804 float root_layer_scale) {
[email protected]404630b2014-07-03 19:33:033805 if (webview() && compositor()) {
[email protected]b2e4c70132013-10-03 02:07:513806 webview()->setCompositorDeviceScaleFactorOverride(device_scale_factor);
[email protected]7f99fc22013-11-08 14:05:583807 webview()->setRootLayerTransform(
3808 blink::WebSize(root_layer_offset.x(), root_layer_offset.y()),
3809 root_layer_scale);
[email protected]b2e4c70132013-10-03 02:07:513810 }
3811}
3812
[email protected]310ebd6302011-10-10 19:06:283813bool RenderViewImpl::ScheduleFileChooser(
[email protected]e9ff79c2012-10-19 21:31:263814 const FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:473815 WebFileChooserCompletion* completion) {
3816 static const size_t kMaximumPendingFileChooseRequests = 4;
3817 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
3818 // This sanity check prevents too many file choose requests from getting
3819 // queued which could DoS the user. Getting these is most likely a
3820 // programming error (there are many ways to DoS the user so it's not
3821 // considered a "real" security check), either in JS requesting many file
3822 // choosers to pop up, or in a plugin.
3823 //
3824 // TODO(brettw) we might possibly want to require a user gesture to open
3825 // a file picker, which will address this issue in a better way.
3826 return false;
3827 }
3828
3829 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
3830 new PendingFileChooser(params, completion)));
3831 if (file_chooser_completions_.size() == 1) {
3832 // Actually show the browse dialog when this is the first request.
3833 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
3834 }
3835 return true;
3836}
3837
[email protected]180ef242013-11-07 06:50:463838blink::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
[email protected]64d09222012-05-25 10:10:343839 if (!speech_recognition_dispatcher_)
3840 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
[email protected]64d09222012-05-25 10:10:343841 return speech_recognition_dispatcher_;
3842}
3843
[email protected]310ebd6302011-10-10 19:06:283844void RenderViewImpl::zoomLimitsChanged(double minimum_level,
3845 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:253846 int minimum_percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:493847 ZoomLevelToZoomFactor(minimum_level) * 100);
[email protected]b75b8292010-10-01 07:28:253848 int maximum_percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:493849 ZoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:253850
3851 Send(new ViewHostMsg_UpdateZoomLimits(
[email protected]fce823222014-05-30 16:24:303852 routing_id_, minimum_percent, maximum_percent));
[email protected]b75b8292010-10-01 07:28:253853}
3854
[email protected]310ebd6302011-10-10 19:06:283855void RenderViewImpl::zoomLevelChanged() {
[email protected]54b8e182014-05-02 18:08:293856 double zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:263857
[email protected]54b8e182014-05-02 18:08:293858 // Do not send empty URLs to the browser when we are just setting the default
3859 // zoom level (from RendererPreferences) before the first navigation.
3860 if (!webview()->mainFrame()->document().url().isEmpty()) {
3861 // Tell the browser which url got zoomed so it can update the menu and the
3862 // saved values if necessary
3863 Send(new ViewHostMsg_DidZoomURL(
[email protected]fce823222014-05-30 16:24:303864 routing_id_, zoom_level,
[email protected]54b8e182014-05-02 18:08:293865 GURL(webview()->mainFrame()->document().url())));
3866 }
[email protected]b75b8292010-10-01 07:28:253867}
3868
[email protected]7940b8e2013-07-25 23:08:493869double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const {
3870 return ZoomLevelToZoomFactor(zoom_level);
3871}
3872
3873double RenderViewImpl::zoomFactorToZoomLevel(double factor) const {
3874 return ZoomFactorToZoomLevel(factor);
3875}
3876
[email protected]f29bc5e2014-08-22 10:34:063877// TODO(sanjoy.pal): Remove once blink patch lands. http://crbug.com/406236.
[email protected]310ebd6302011-10-10 19:06:283878void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
[email protected]5958c6bc2014-01-22 14:48:053879 const WebURL& base_url,
3880 const WebURL& url,
[email protected]310ebd6302011-10-10 19:06:283881 const WebString& title) {
[email protected]af15bf22013-03-08 01:18:173882 bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]a6d36cc2011-02-23 00:39:483883 GURL base(base_url);
[email protected]5958c6bc2014-01-22 14:48:053884 GURL absolute_url = base.Resolve(base::UTF16ToUTF8(url.string()));
[email protected]a6d36cc2011-02-23 00:39:483885 if (base.GetOrigin() != absolute_url.GetOrigin()) {
3886 return;
3887 }
[email protected]f1a29a02011-10-06 23:08:443888 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
[email protected]32956122013-12-25 07:29:243889 base::UTF16ToUTF8(scheme),
[email protected]f1a29a02011-10-06 23:08:443890 absolute_url,
[email protected]3a3b75a2012-06-01 08:38:363891 title,
3892 user_gesture));
[email protected]a6d36cc2011-02-23 00:39:483893}
3894
[email protected]f5273e52014-07-14 16:30:203895void RenderViewImpl::unregisterProtocolHandler(const WebString& scheme,
3896 const WebURL& base_url,
3897 const WebURL& url) {
3898 bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
3899 GURL base(base_url);
3900 GURL absolute_url = base.Resolve(base::UTF16ToUTF8(url.string()));
3901 if (base.GetOrigin() != absolute_url.GetOrigin())
3902 return;
3903 Send(new ViewHostMsg_UnregisterProtocolHandler(routing_id_,
3904 base::UTF16ToUTF8(scheme),
3905 absolute_url,
3906 user_gesture));
3907}
3908
[email protected]f29bc5e2014-08-22 10:34:063909void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
3910 const WebURL& url,
3911 const WebString& title) {
3912 bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
3913 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
3914 base::UTF16ToUTF8(scheme),
3915 url,
3916 title,
3917 user_gesture));
3918}
3919
3920void RenderViewImpl::unregisterProtocolHandler(const WebString& scheme,
3921 const WebURL& url) {
3922 bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
3923 Send(new ViewHostMsg_UnregisterProtocolHandler(routing_id_,
3924 base::UTF16ToUTF8(scheme),
3925 url,
3926 user_gesture));
3927}
3928
[email protected]180ef242013-11-07 06:50:463929blink::WebPageVisibilityState RenderViewImpl::visibilityState() const {
3930 blink::WebPageVisibilityState current_state = is_hidden() ?
3931 blink::WebPageVisibilityStateHidden :
3932 blink::WebPageVisibilityStateVisible;
3933 blink::WebPageVisibilityState override_state = current_state;
[email protected]b849847b2013-12-10 21:57:583934 // TODO(jam): move this method to WebFrameClient.
[email protected]e9ff79c2012-10-19 21:31:263935 if (GetContentClient()->renderer()->
[email protected]b849847b2013-12-10 21:57:583936 ShouldOverridePageVisibilityState(main_render_frame_.get(),
[email protected]f59203a2011-06-07 10:01:443937 &override_state))
3938 return override_state;
3939 return current_state;
[email protected]94dec932011-05-26 20:04:213940}
3941
[email protected]e1c174162014-04-08 15:39:313942blink::WebPushClient* RenderViewImpl::webPushClient() {
[email protected]45920862014-07-02 12:53:023943 // TODO(mvanouwerkerk): Remove this method once the Push API code in Blink
3944 // has also switched over to Frame.
3945 return main_render_frame_->pushClient();
[email protected]e1c174162014-04-08 15:39:313946}
3947
[email protected]a0629af92012-08-08 00:39:373948void RenderViewImpl::draggableRegionsChanged() {
3949 FOR_EACH_OBSERVER(
3950 RenderViewObserver,
3951 observers_,
3952 DraggableRegionsChanged(webview()->mainFrame()));
3953}
3954
[email protected]20657a82012-08-21 20:23:033955#if defined(OS_ANDROID)
3956WebContentDetectionResult RenderViewImpl::detectContentAround(
3957 const WebHitTestResult& touch_hit) {
3958 DCHECK(!touch_hit.isNull());
3959 DCHECK(!touch_hit.node().isNull());
3960 DCHECK(touch_hit.node().isTextNode());
3961
3962 // Process the position with all the registered content detectors until
3963 // a match is found. Priority is provided by their relative order.
3964 for (ContentDetectorList::const_iterator it = content_detectors_.begin();
3965 it != content_detectors_.end(); ++it) {
3966 ContentDetector::Result content = (*it)->FindTappedContent(touch_hit);
3967 if (content.valid) {
3968 return WebContentDetectionResult(content.content_boundaries,
[email protected]32956122013-12-25 07:29:243969 base::UTF8ToUTF16(content.text), content.intent_url);
[email protected]20657a82012-08-21 20:23:033970 }
3971 }
3972 return WebContentDetectionResult();
3973}
3974
3975void RenderViewImpl::scheduleContentIntent(const WebURL& intent) {
3976 // Introduce a short delay so that the user can notice the content.
[email protected]dd32b1272013-05-04 14:17:113977 base::MessageLoop::current()->PostDelayedTask(
[email protected]20657a82012-08-21 20:23:033978 FROM_HERE,
[email protected]dd32b1272013-05-04 14:17:113979 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent,
3980 AsWeakPtr(),
3981 intent,
3982 expected_content_intent_id_),
[email protected]20657a82012-08-21 20:23:033983 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds));
3984}
3985
3986void RenderViewImpl::cancelScheduledContentIntents() {
3987 ++expected_content_intent_id_;
3988}
3989
3990void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent,
3991 size_t request_id) {
3992 if (request_id != expected_content_intent_id_)
3993 return;
3994
3995 // Remove the content highlighting if any.
[email protected]8b9e52b2014-01-17 16:35:313996 scheduleComposite();
[email protected]20657a82012-08-21 20:23:033997
3998 if (!intent.is_empty())
3999 Send(new ViewHostMsg_StartContentIntent(routing_id_, intent));
4000}
[email protected]b18583c2012-12-18 06:55:274001
4002bool RenderViewImpl::openDateTimeChooser(
[email protected]180ef242013-11-07 06:50:464003 const blink::WebDateTimeChooserParams& params,
4004 blink::WebDateTimeChooserCompletion* completion) {
[email protected]e8072562013-12-04 06:04:134005 // JavaScript may try to open a date time chooser while one is already open.
4006 if (date_time_picker_client_)
4007 return false;
[email protected]b18583c2012-12-18 06:55:274008 date_time_picker_client_.reset(
4009 new RendererDateTimePicker(this, params, completion));
4010 return date_time_picker_client_->Open();
4011}
4012
[email protected]e8072562013-12-04 06:04:134013void RenderViewImpl::DismissDateTimeDialog() {
4014 DCHECK(date_time_picker_client_);
4015 date_time_picker_client_.reset(NULL);
4016}
[email protected]e8072562013-12-04 06:04:134017
[email protected]6d17f6392012-12-05 05:24:544018#endif // defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:034019
[email protected]be1af0662014-07-29 19:55:514020void RenderViewImpl::OnShowContextMenu(
4021 ui::MenuSourceType source_type, const gfx::Point& location) {
4022 context_menu_source_type_ = source_type;
4023 has_host_context_menu_location_ = true;
4024 host_context_menu_location_ = location;
[email protected]47822262013-04-23 17:22:364025 if (webview())
4026 webview()->showContextMenu();
[email protected]be1af0662014-07-29 19:55:514027 has_host_context_menu_location_ = false;
[email protected]47822262013-04-23 17:22:364028}
4029
[email protected]310ebd6302011-10-10 19:06:284030void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:184031 if (!webview())
4032 return;
4033 WebFrame* main_frame = webview()->mainFrame();
4034 if (!main_frame)
4035 return;
4036 main_frame->enableViewSourceMode(true);
4037}
[email protected]67bfb83f2011-09-22 03:36:374038
[email protected]efd7e47f2012-10-19 20:37:514039#if defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:034040bool RenderViewImpl::didTapMultipleTargets(
[email protected]180ef242013-11-07 06:50:464041 const blink::WebGestureEvent& event,
[email protected]f9526d12012-10-18 01:55:034042 const WebVector<WebRect>& target_rects) {
[email protected]8d3dfee62013-06-19 05:50:334043 // Never show a disambiguation popup when accessibility is enabled,
4044 // as this interferes with "touch exploration".
[email protected]95640212014-07-26 18:14:304045 AccessibilityMode accessibility_mode =
4046 main_render_frame()->accessibility_mode();
4047 bool matches_accessibility_mode_complete =
4048 (accessibility_mode & AccessibilityModeComplete) ==
4049 AccessibilityModeComplete;
4050 if (matches_accessibility_mode_complete)
[email protected]8d3dfee62013-06-19 05:50:334051 return false;
4052
[email protected]f9526d12012-10-18 01:55:034053 gfx::Rect finger_rect(
4054 event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2,
4055 event.data.tap.width, event.data.tap.height);
4056 gfx::Rect zoom_rect;
[email protected]70221f02013-01-31 22:17:074057 float new_total_scale =
4058 DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
4059 finger_rect, target_rects, GetSize(),
4060 gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(),
4061 device_scale_factor_ * webview()->pageScaleFactor(), &zoom_rect);
4062 if (!new_total_scale)
[email protected]f9526d12012-10-18 01:55:034063 return false;
4064
[email protected]4ded1dbf2013-08-28 21:11:034065 bool handled = false;
4066 switch (renderer_preferences_.tap_multiple_targets_strategy) {
4067 case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM:
4068 handled = webview()->zoomToMultipleTargetsRect(zoom_rect);
4069 break;
4070 case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: {
[email protected]bc2804d2013-08-06 07:45:494071 gfx::Size canvas_size =
4072 gfx::ToCeiledSize(gfx::ScaleSize(zoom_rect.size(), new_total_scale));
[email protected]cb189e062014-04-23 00:57:014073 cc::SharedBitmapManager* manager =
4074 RenderThreadImpl::current()->shared_bitmap_manager();
4075 scoped_ptr<cc::SharedBitmap> shared_bitmap =
4076 manager->AllocateSharedBitmap(canvas_size);
[email protected]bc2804d2013-08-06 07:45:494077 {
[email protected]cb189e062014-04-23 00:57:014078 SkBitmap bitmap;
4079 SkImageInfo info = SkImageInfo::MakeN32Premul(canvas_size.width(),
4080 canvas_size.height());
4081 bitmap.installPixels(info, shared_bitmap->pixels(), info.minRowBytes());
4082 SkCanvas canvas(bitmap);
[email protected]f9526d12012-10-18 01:55:034083
[email protected]bc2804d2013-08-06 07:45:494084 // TODO(trchen): Cleanup the device scale factor mess.
4085 // device scale will be applied in WebKit
4086 // --> zoom_rect doesn't include device scale,
4087 // but WebKit will still draw on zoom_rect * device_scale_factor_
[email protected]cb189e062014-04-23 00:57:014088 canvas.scale(new_total_scale / device_scale_factor_,
4089 new_total_scale / device_scale_factor_);
4090 canvas.translate(-zoom_rect.x() * device_scale_factor_,
4091 -zoom_rect.y() * device_scale_factor_);
[email protected]f9526d12012-10-18 01:55:034092
[email protected]bcb1f022014-05-06 01:54:174093 DCHECK(webwidget_->isAcceleratedCompositingActive());
4094 // TODO(aelias): The disambiguation popup should be composited so we
4095 // don't have to call this method.
4096 webwidget_->paintCompositedDeprecated(&canvas, zoom_rect);
[email protected]bc2804d2013-08-06 07:45:494097 }
4098
4099 gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect(
4100 ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect)));
4101 Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_,
4102 physical_window_zoom_rect,
4103 canvas_size,
[email protected]cb189e062014-04-23 00:57:014104 shared_bitmap->id()));
4105 cc::SharedBitmapId id = shared_bitmap->id();
4106 disambiguation_bitmaps_[id] = shared_bitmap.release();
[email protected]4ded1dbf2013-08-28 21:11:034107 handled = true;
4108 break;
4109 }
4110 case TAP_MULTIPLE_TARGETS_STRATEGY_NONE:
4111 // No-op.
4112 break;
[email protected]f9526d12012-10-18 01:55:034113 }
[email protected]70221f02013-01-31 22:17:074114
[email protected]4ded1dbf2013-08-28 21:11:034115 return handled;
[email protected]f9526d12012-10-18 01:55:034116}
[email protected]efd7e47f2012-10-19 20:37:514117#endif
[email protected]f9526d12012-10-18 01:55:034118
[email protected]b283d292013-02-21 08:40:344119unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
4120 return history_list_length_;
4121}
4122
[email protected]cc290f902013-03-04 20:06:024123void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
4124 if (enable) {
4125 if (has_focus())
4126 return;
4127 OnSetActive(true);
4128 OnSetFocus(true);
4129 } else {
4130 if (!has_focus())
4131 return;
4132 OnSetFocus(false);
4133 OnSetActive(false);
4134 }
4135}
4136
[email protected]3a1c8a8032013-03-18 22:35:324137void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) {
[email protected]b54fe452013-06-07 14:01:534138 ViewMsg_Resize_Params params;
4139 params.screen_info = screen_info_;
4140 params.screen_info.deviceScaleFactor = factor;
4141 params.new_size = size();
4142 params.physical_backing_size =
4143 gfx::ToCeiledSize(gfx::ScaleSize(size(), factor));
[email protected]587941d2014-08-22 01:40:014144 params.top_controls_layout_height = 0.f;
[email protected]b54fe452013-06-07 14:01:534145 params.resizer_rect = WebRect();
4146 params.is_fullscreen = is_fullscreen();
4147 OnResize(params);
[email protected]3a1c8a8032013-03-18 22:35:324148}
4149
[email protected]71e652302014-05-09 14:20:134150void RenderViewImpl::SetDeviceColorProfileForTesting(
4151 const std::vector<char>& color_profile) {
[email protected]28ed6b32014-06-08 02:16:274152 SetDeviceColorProfile(color_profile);
[email protected]71e652302014-05-09 14:20:134153}
4154
[email protected]92650162013-10-30 03:31:024155void RenderViewImpl::ForceResizeForTesting(const gfx::Size& new_size) {
4156 gfx::Rect new_position(rootWindowRect().x,
4157 rootWindowRect().y,
4158 new_size.width(),
4159 new_size.height());
4160 ResizeSynchronously(new_position);
4161}
4162
[email protected]5b45ad42013-10-25 00:42:044163void RenderViewImpl::UseSynchronousResizeModeForTesting(bool enable) {
4164 resizing_mode_selector_->set_is_synchronous_mode(enable);
4165}
4166
[email protected]eac2b362013-05-22 07:01:454167void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size,
4168 const gfx::Size& max_size) {
4169 OnEnableAutoResize(min_size, max_size);
4170}
4171
4172void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) {
4173 OnDisableAutoResize(new_size);
4174}
4175
[email protected]cb189e062014-04-23 00:57:014176void RenderViewImpl::OnReleaseDisambiguationPopupBitmap(
4177 const cc::SharedBitmapId& id) {
4178 BitmapMap::iterator it = disambiguation_bitmaps_.find(id);
4179 DCHECK(it != disambiguation_bitmaps_.end());
4180 delete it->second;
4181 disambiguation_bitmaps_.erase(it);
[email protected]f9526d12012-10-18 01:55:034182}
[email protected]e9ff79c2012-10-19 21:31:264183
[email protected]6fceb912013-02-15 06:24:154184void RenderViewImpl::DidCommitCompositorFrame() {
4185 RenderWidget::DidCommitCompositorFrame();
4186 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame());
4187}
4188
[email protected]41225fe2013-03-29 05:32:024189void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) {
4190 if (!urls.empty())
[email protected]50279492014-05-05 23:24:294191 Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, urls));
[email protected]41225fe2013-03-29 05:32:024192}
4193
4194void RenderViewImpl::DidStopLoadingIcons() {
4195 int icon_types = WebIconURL::TypeFavicon;
4196 if (TouchEnabled())
4197 icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch;
4198
4199 WebVector<WebIconURL> icon_urls =
4200 webview()->mainFrame()->iconURLs(icon_types);
4201
4202 std::vector<FaviconURL> urls;
4203 for (size_t i = 0; i < icon_urls.size(); i++) {
4204 WebURL url = icon_urls[i].iconURL();
[email protected]2bd262b2014-04-16 05:31:234205 std::vector<gfx::Size> sizes;
[email protected]f34ac132014-03-20 23:02:054206 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
[email protected]41225fe2013-03-29 05:32:024207 if (!url.isEmpty())
[email protected]f34ac132014-03-20 23:02:054208 urls.push_back(
4209 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes));
[email protected]41225fe2013-03-29 05:32:024210 }
4211 SendUpdateFaviconURL(urls);
4212}
4213
[email protected]e9ff79c2012-10-19 21:31:264214} // namespace content