blob: bfb88ea01d1914f5714001ccfd760db3e8861376 [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]835d7c82010-10-14 04:38:3823#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2824#include "base/path_service.h"
[email protected]d3b4ee22013-07-24 22:50:0625#include "base/process/kill.h"
[email protected]7d08a9352013-10-15 08:24:5626#include "base/process/process.h"
[email protected]21aa99682013-06-11 07:17:0127#include "base/strings/string_number_conversions.h"
[email protected]b9e7c479f2013-04-12 04:33:2428#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4929#include "base/strings/string_split.h"
[email protected]21aa99682013-06-11 07:17:0130#include "base/strings/string_util.h"
[email protected]40d11e02013-03-28 17:43:1431#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0032#include "base/strings/utf_string_conversions.h"
[email protected]abb522162013-06-28 01:54:1633#include "base/time/time.h"
[email protected]e3415902013-10-17 15:00:4634#include "cc/base/switches.h"
[email protected]a8cb3b73b2013-08-12 05:50:5035#include "content/child/appcache/appcache_dispatcher.h"
36#include "content/child/appcache/web_application_cache_host_impl.h"
[email protected]10208ea2013-06-06 20:08:0337#include "content/child/child_thread.h"
[email protected]29e2fb42013-07-19 01:13:4738#include "content/child/npapi/webplugin_delegate_impl.h"
[email protected]541b7b02013-06-07 00:59:3439#include "content/child/request_extra_data.h"
[email protected]10208ea2013-06-06 20:08:0340#include "content/child/webmessageportchannel_impl.h"
[email protected]37666cf2011-03-13 21:51:4241#include "content/common/database_messages.h"
[email protected]5f2aa722013-08-07 16:59:4142#include "content/common/dom_storage/dom_storage_types.h"
[email protected]59f4f2fa2011-03-23 01:00:5543#include "content/common/drag_messages.h"
[email protected]c6bc20332014-02-28 18:30:3944#include "content/common/frame_messages.h"
[email protected]c26ad882012-02-07 06:41:2045#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]c084330e02013-04-27 01:08:1546#include "content/common/input_messages.h"
[email protected]127dd582011-03-16 21:32:1047#include "content/common/pepper_messages.h"
[email protected]5fa3a062012-03-21 15:39:3448#include "content/common/socket_stream_handle_data.h"
[email protected]e4495212012-12-06 03:09:1249#include "content/common/ssl_status_serialization.h"
[email protected]778574e2011-03-21 22:03:5050#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2151#include "content/public/common/bindings_policy.h"
[email protected]744c2a22012-03-15 18:42:0452#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4853#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2954#include "content/public/common/content_switches.h"
[email protected]dc293a72013-07-01 11:11:2255#include "content/public/common/drop_data.h"
[email protected]41225fe2013-03-29 05:32:0256#include "content/public/common/favicon_url.h"
[email protected]8caadeb2011-11-22 02:45:2357#include "content/public/common/file_chooser_params.h"
[email protected]7940b8e2013-07-25 23:08:4958#include "content/public/common/page_zoom.h"
[email protected]e4495212012-12-06 03:09:1259#include "content/public/common/ssl_status.h"
[email protected]818915cd2012-11-20 13:14:1160#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0361#include "content/public/common/url_constants.h"
[email protected]3b366ae2013-05-17 21:16:5862#include "content/public/common/url_utils.h"
[email protected]d344114c2011-10-01 01:24:3463#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0764#include "content/public/renderer/document_state.h"
[email protected]691aa2f2013-05-28 22:52:0465#include "content/public/renderer/history_item_serialization.h"
[email protected]82ddba1c2011-10-04 00:15:3266#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4467#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3668#include "content/public/renderer/render_view_visitor.h"
[email protected]49a20002013-08-18 12:43:3169#include "content/public/renderer/web_preferences.h"
[email protected]4e4646a52013-02-08 07:23:4170#include "content/renderer/accessibility/renderer_accessibility.h"
71#include "content/renderer/accessibility/renderer_accessibility_complete.h"
72#include "content/renderer/accessibility/renderer_accessibility_focus_only.h"
[email protected]e6e56752012-08-10 00:46:0673#include "content/renderer/browser_plugin/browser_plugin.h"
74#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]fb325d122012-11-20 23:58:0575#include "content/renderer/browser_plugin/browser_plugin_manager_impl.h"
[email protected]70019152012-12-19 11:44:1976#include "content/renderer/devtools/devtools_agent.h"
[email protected]f9526d12012-10-18 01:55:0377#include "content/renderer/disambiguation_popup_helper.h"
[email protected]1910fe82012-05-10 00:04:1078#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]dc293a72013-07-01 11:11:2279#include "content/renderer/drop_data_builder.h"
[email protected]55722152011-03-22 01:33:5380#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1981#include "content/renderer/geolocation_dispatcher.h"
[email protected]ba91a792013-02-06 09:48:2882#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]1784b2f2011-11-24 10:53:4883#include "content/renderer/idle_user_detector.h"
[email protected]66fca5bc2013-05-23 06:58:2984#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1385#include "content/renderer/input/input_handler_manager.h"
[email protected]c52b2892012-03-07 11:01:0286#include "content/renderer/input_tag_speech_dispatcher.h"
[email protected]92d457802013-04-01 19:18:4987#include "content/renderer/internal_document_state_data.h"
[email protected]921f1592011-03-18 00:41:0288#include "content/renderer/load_progress_tracker.h"
[email protected]4a914882013-01-10 00:43:4889#include "content/renderer/media/audio_device_factory.h"
90#include "content/renderer/media/audio_renderer_mixer_manager.h"
[email protected]273558fb2012-01-12 15:03:5191#include "content/renderer/media/media_stream_dependency_factory.h"
92#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:4093#include "content/renderer/media/media_stream_impl.h"
[email protected]7b77f6cb2013-07-25 16:23:1494#include "content/renderer/media/midi_dispatcher.h"
[email protected]090f7312011-08-05 23:26:4095#include "content/renderer/media/render_media_log.h"
[email protected]6392d982013-04-16 16:59:2296#include "content/renderer/media/video_capture_impl_manager.h"
[email protected]5e35a8d2013-07-10 19:37:2197#include "content/renderer/media/webmediaplayer_impl.h"
98#include "content/renderer/media/webmediaplayer_ms.h"
99#include "content/renderer/media/webmediaplayer_params.h"
[email protected]3fad220d2014-01-23 11:30:06100#include "content/renderer/memory_benchmarking_extension.h"
[email protected]4a19be92011-09-22 14:25:02101#include "content/renderer/mhtml_generator.h"
[email protected]230b7ef2011-03-16 22:30:19102#include "content/renderer/notification_provider.h"
[email protected]e1c174162014-04-08 15:39:31103#include "content/renderer/push_messaging_dispatcher.h"
[email protected]227692c52013-05-31 22:43:04104#include "content/renderer/render_frame_impl.h"
[email protected]8704f89b2011-04-15 00:30:05105#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:44106#include "content/renderer/render_thread_impl.h"
[email protected]8d41d7612012-11-14 20:32:19107#include "content/renderer/render_view_impl_params.h"
[email protected]89054502012-06-03 10:29:24108#include "content/renderer/render_view_mouse_lock_dispatcher.h"
[email protected]2cff0052011-03-18 16:51:44109#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]663bd9e2011-03-21 01:07:01110#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]da8543762012-03-20 08:52:20111#include "content/renderer/renderer_webcolorchooser_impl.h"
[email protected]5b45ad42013-10-25 00:42:04112#include "content/renderer/resizing_mode_selector.h"
[email protected]12a936d2013-05-15 04:55:49113#include "content/renderer/savable_resources.h"
[email protected]cdb6b1e2014-01-23 00:06:49114#include "content/renderer/skia_benchmarking_extension.h"
[email protected]64d09222012-05-25 10:10:34115#include "content/renderer/speech_recognition_dispatcher.h"
[email protected]27c521a2013-05-29 20:44:32116#include "content/renderer/stats_collection_controller.h"
117#include "content/renderer/stats_collection_observer.h"
[email protected]86a7d3c2011-09-12 16:45:32118#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:19119#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:21120#include "content/renderer/web_ui_extension.h"
121#include "content/renderer/web_ui_extension_data.h"
[email protected]1c142a52014-04-05 20:14:17122#include "content/renderer/web_ui_mojo.h"
[email protected]6f516082011-03-17 19:15:35123#include "content/renderer/websharedworker_proxy.h"
[email protected]f5961142013-04-17 23:09:42124#include "media/audio/audio_output_device.h"
[email protected]4a914882013-01-10 00:43:48125#include "media/base/audio_renderer_mixer_input.h"
[email protected]f8db8132010-12-03 00:27:49126#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41127#include "media/base/media_switches.h"
[email protected]37136d162012-04-09 23:39:19128#include "media/filters/audio_renderer_impl.h"
[email protected]1cad8802013-08-13 16:54:32129#include "media/filters/gpu_video_accelerator_factories.h"
[email protected]d1ef81d2012-07-24 11:39:36130#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29131#include "net/base/escape.h"
132#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09133#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04134#include "net/http/http_util.h"
[email protected]d0fcff72013-07-23 02:45:43135#include "third_party/WebKit/public/platform/WebCString.h"
136#include "third_party/WebKit/public/platform/WebDragData.h"
[email protected]d0fcff72013-07-23 02:45:43137#include "third_party/WebKit/public/platform/WebHTTPBody.h"
138#include "third_party/WebKit/public/platform/WebImage.h"
139#include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
140#include "third_party/WebKit/public/platform/WebPoint.h"
141#include "third_party/WebKit/public/platform/WebRect.h"
142#include "third_party/WebKit/public/platform/WebSize.h"
143#include "third_party/WebKit/public/platform/WebSocketStreamHandle.h"
[email protected]ec173b522013-11-14 11:01:18144#include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h"
[email protected]d0fcff72013-07-23 02:45:43145#include "third_party/WebKit/public/platform/WebString.h"
146#include "third_party/WebKit/public/platform/WebURL.h"
147#include "third_party/WebKit/public/platform/WebURLError.h"
148#include "third_party/WebKit/public/platform/WebURLRequest.h"
149#include "third_party/WebKit/public/platform/WebURLResponse.h"
150#include "third_party/WebKit/public/platform/WebVector.h"
[email protected]10760e4a2013-09-04 23:32:20151#include "third_party/WebKit/public/web/WebAXObject.h"
[email protected]2255a9332013-06-17 05:12:31152#include "third_party/WebKit/public/web/WebColorName.h"
[email protected]8bc5ff02013-11-29 06:34:03153#include "third_party/WebKit/public/web/WebColorSuggestion.h"
[email protected]2255a9332013-06-17 05:12:31154#include "third_party/WebKit/public/web/WebDOMEvent.h"
155#include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
156#include "third_party/WebKit/public/web/WebDataSource.h"
157#include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h"
158#include "third_party/WebKit/public/web/WebDateTimeChooserParams.h"
159#include "third_party/WebKit/public/web/WebDevToolsAgent.h"
160#include "third_party/WebKit/public/web/WebDocument.h"
161#include "third_party/WebKit/public/web/WebElement.h"
162#include "third_party/WebKit/public/web/WebFileChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31163#include "third_party/WebKit/public/web/WebFindOptions.h"
164#include "third_party/WebKit/public/web/WebFormControlElement.h"
165#include "third_party/WebKit/public/web/WebFormElement.h"
166#include "third_party/WebKit/public/web/WebFrame.h"
[email protected]6bd867b2013-07-24 22:10:20167#include "third_party/WebKit/public/web/WebGlyphCache.h"
[email protected]2255a9332013-06-17 05:12:31168#include "third_party/WebKit/public/web/WebHistoryItem.h"
169#include "third_party/WebKit/public/web/WebInputElement.h"
170#include "third_party/WebKit/public/web/WebInputEvent.h"
[email protected]35b2a972014-04-04 15:50:22171#include "third_party/WebKit/public/web/WebLocalFrame.h"
[email protected]2255a9332013-06-17 05:12:31172#include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
173#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
174#include "third_party/WebKit/public/web/WebNodeList.h"
175#include "third_party/WebKit/public/web/WebPageSerializer.h"
176#include "third_party/WebKit/public/web/WebPlugin.h"
177#include "third_party/WebKit/public/web/WebPluginAction.h"
178#include "third_party/WebKit/public/web/WebPluginContainer.h"
179#include "third_party/WebKit/public/web/WebPluginDocument.h"
[email protected]2255a9332013-06-17 05:12:31180#include "third_party/WebKit/public/web/WebRange.h"
181#include "third_party/WebKit/public/web/WebScriptSource.h"
182#include "third_party/WebKit/public/web/WebSearchableFormData.h"
183#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
184#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
185#include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
186#include "third_party/WebKit/public/web/WebSettings.h"
[email protected]2255a9332013-06-17 05:12:31187#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
188#include "third_party/WebKit/public/web/WebUserMediaClient.h"
189#include "third_party/WebKit/public/web/WebView.h"
190#include "third_party/WebKit/public/web/WebWindowFeatures.h"
191#include "third_party/WebKit/public/web/default/WebRenderTheme.h"
[email protected]4ee64622014-03-21 22:34:15192#include "ui/base/clipboard/clipboard.h"
[email protected]1400e6dc2013-04-27 02:36:27193#include "ui/base/ui_base_switches_util.h"
[email protected]7d08a9352013-10-15 08:24:56194#include "ui/events/latency_info.h"
[email protected]08397d52011-02-05 01:53:38195#include "ui/gfx/native_widget_types.h"
196#include "ui/gfx/point.h"
197#include "ui/gfx/rect.h"
[email protected]70221f02013-01-31 22:17:07198#include "ui/gfx/rect_conversions.h"
[email protected]f9526d12012-10-18 01:55:03199#include "ui/gfx/size_conversions.h"
[email protected]4344a3c2013-01-17 23:49:20200#include "ui/shell_dialogs/selected_file_info.h"
[email protected]c4a9e932011-03-05 04:05:55201#include "v8/include/v8.h"
[email protected]d0fcff72013-07-23 02:45:43202#include "webkit/child/weburlresponse_extradata_impl.h"
initial.commit09911bf2008-07-26 23:55:29203
[email protected]25fb9b32012-04-27 03:21:55204#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25205#include <cpu-features.h>
206
[email protected]276e8a322013-01-24 01:50:11207#include "content/common/android/device_telephony_info.h"
[email protected]a45c46e2013-03-07 01:04:46208#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]20657a82012-08-21 20:23:03209#include "content/renderer/android/address_detector.h"
210#include "content/renderer/android/content_detector.h"
211#include "content/renderer/android/email_detector.h"
212#include "content/renderer/android/phone_number_detector.h"
[email protected]3a59bb92013-08-22 18:54:08213#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]bc427442013-07-13 02:53:08214#include "content/renderer/media/android/renderer_media_player_manager.h"
[email protected]2bd4e7712014-04-03 00:14:37215#include "content/renderer/media/android/stream_texture_factory_impl.h"
[email protected]be580992013-06-22 14:32:44216#include "content/renderer/media/android/webmediaplayer_android.h"
[email protected]c277d3c2013-07-15 21:49:37217#include "skia/ext/platform_canvas.h"
[email protected]5c30b5e02013-05-30 03:46:08218#include "third_party/WebKit/public/platform/WebFloatPoint.h"
219#include "third_party/WebKit/public/platform/WebFloatRect.h"
[email protected]d0fcff72013-07-23 02:45:43220#include "third_party/WebKit/public/web/WebHitTestResult.h"
[email protected]59363fc92012-09-05 03:46:31221#include "ui/gfx/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40222
[email protected]25fb9b32012-04-27 03:21:55223#elif defined(OS_WIN)
[email protected]6c8afae52009-01-22 02:24:57224// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57225// * theming
[email protected]990e6222012-11-16 13:31:18226#include "ui/native_theme/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03227#elif defined(USE_X11)
[email protected]990e6222012-11-16 13:31:18228#include "ui/native_theme/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33229#elif defined(OS_MACOSX)
230#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57231#endif
232
[email protected]ea2fb972013-08-07 05:44:26233#if defined(ENABLE_PLUGINS)
[email protected]a80af12e2013-08-07 23:36:13234#include "content/renderer/npapi/webplugin_delegate_proxy.h"
[email protected]ea2fb972013-08-07 05:44:26235#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
236#include "content/renderer/pepper/pepper_plugin_registry.h"
[email protected]ea2fb972013-08-07 05:44:26237#endif
238
[email protected]9ac667e2013-09-09 12:49:21239#if defined(ENABLE_WEBRTC)
240#include "content/renderer/media/rtc_peer_connection_handler.h"
241#endif
242
[email protected]180ef242013-11-07 06:50:46243using blink::WebAXObject;
244using blink::WebApplicationCacheHost;
245using blink::WebApplicationCacheHostClient;
246using blink::WebCString;
247using blink::WebColor;
248using blink::WebColorName;
249using blink::WebConsoleMessage;
[email protected]180ef242013-11-07 06:50:46250using blink::WebData;
251using blink::WebDataSource;
252using blink::WebDocument;
253using blink::WebDOMEvent;
254using blink::WebDOMMessageEvent;
255using blink::WebDragData;
256using blink::WebDragOperation;
257using blink::WebDragOperationsMask;
258using blink::WebElement;
259using blink::WebExternalPopupMenu;
260using blink::WebExternalPopupMenuClient;
261using blink::WebFileChooserCompletion;
262using blink::WebFindOptions;
263using blink::WebFormControlElement;
264using blink::WebFormElement;
265using blink::WebFrame;
266using blink::WebGestureEvent;
267using blink::WebHistoryItem;
268using blink::WebHTTPBody;
269using blink::WebIconURL;
270using blink::WebImage;
271using blink::WebInputElement;
272using blink::WebInputEvent;
[email protected]35b2a972014-04-04 15:50:22273using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46274using blink::WebMediaPlayer;
275using blink::WebMediaPlayerAction;
276using blink::WebMediaPlayerClient;
277using blink::WebMouseEvent;
278using blink::WebNavigationPolicy;
279using blink::WebNavigationType;
280using blink::WebNode;
281using blink::WebPageSerializer;
282using blink::WebPageSerializerClient;
283using blink::WebPeerConnection00Handler;
284using blink::WebPeerConnection00HandlerClient;
285using blink::WebPeerConnectionHandler;
286using blink::WebPeerConnectionHandlerClient;
287using blink::WebPluginAction;
288using blink::WebPluginContainer;
289using blink::WebPluginDocument;
[email protected]180ef242013-11-07 06:50:46290using blink::WebPoint;
291using blink::WebPopupMenuInfo;
292using blink::WebRange;
293using blink::WebRect;
294using blink::WebReferrerPolicy;
[email protected]180ef242013-11-07 06:50:46295using blink::WebScriptSource;
296using blink::WebSearchableFormData;
297using blink::WebSecurityOrigin;
298using blink::WebSecurityPolicy;
299using blink::WebSerializedScriptValue;
300using blink::WebSettings;
301using blink::WebSize;
302using blink::WebSocketStreamHandle;
303using blink::WebStorageNamespace;
304using blink::WebStorageQuotaCallbacks;
305using blink::WebStorageQuotaError;
306using blink::WebStorageQuotaType;
307using blink::WebString;
308using blink::WebTextAffinity;
309using blink::WebTextDirection;
310using blink::WebTouchEvent;
311using blink::WebURL;
312using blink::WebURLError;
313using blink::WebURLRequest;
314using blink::WebURLResponse;
315using blink::WebUserGestureIndicator;
316using blink::WebVector;
317using blink::WebView;
318using blink::WebWidget;
319using blink::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26320using base::Time;
321using base::TimeDelta;
[email protected]b9fd01ba2012-02-28 01:50:40322using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33323
[email protected]20657a82012-08-21 20:23:03324#if defined(OS_ANDROID)
[email protected]180ef242013-11-07 06:50:46325using blink::WebContentDetectionResult;
326using blink::WebFloatPoint;
327using blink::WebFloatRect;
328using blink::WebHitTestResult;
[email protected]20657a82012-08-21 20:23:03329#endif
330
[email protected]e9ff79c2012-10-19 21:31:26331namespace content {
332
initial.commit09911bf2008-07-26 23:55:29333//-----------------------------------------------------------------------------
334
[email protected]180ef242013-11-07 06:50:46335typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49336static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]058561b2012-12-03 06:48:22337typedef std::map<int32, RenderViewImpl*> RoutingIDViewMap;
338static base::LazyInstance<RoutingIDViewMap> g_routing_id_view_map =
339 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02340
[email protected]882daa92009-11-05 16:31:31341// Time, in seconds, we delay before sending content state changes (such as form
342// state and scroll position) to the browser. We delay sending changes to avoid
343// spamming the browser.
344// To avoid having tab/session restore require sending a message to get the
345// current content state during tab closing we use a shorter timeout for the
346// foreground renderer. This means there is a small window of time from which
347// content state is modified and not sent to session restore, but this is
348// better than having to wake up all renderers during shutdown.
[email protected]9afc14e22013-09-25 22:34:14349const int kDelaySecondsForContentStateSyncHidden = 5;
350const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29351
[email protected]20657a82012-08-21 20:23:03352#if defined(OS_ANDROID)
353// Delay between tapping in content and launching the associated android intent.
354// Used to allow users see what has been recognized as content.
[email protected]9afc14e22013-09-25 22:34:14355const size_t kContentIntentDelayMilliseconds = 700;
[email protected]20657a82012-08-21 20:23:03356#endif
357
[email protected]8d41d7612012-11-14 20:32:19358static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) =
359 NULL;
360
[email protected]c6bc20332014-02-28 18:30:39361// static
362bool RenderViewImpl::IsReload(const FrameMsg_Navigate_Params& params) {
[email protected]007733c2011-11-17 00:34:07363 return
[email protected]c6bc20332014-02-28 18:30:39364 params.navigation_type == FrameMsg_Navigate_Type::RELOAD ||
365 params.navigation_type == FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE ||
[email protected]7c16976c2012-08-04 02:38:23366 params.navigation_type ==
[email protected]c6bc20332014-02-28 18:30:39367 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]007733c2011-11-17 00:34:07368}
369
[email protected]e507045d2013-07-24 15:23:44370// static
[email protected]e507045d2013-07-24 15:23:44371Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56372 WebFrame* frame,
373 const WebURLRequest& request) {
374 return Referrer(GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]cacbd7a2014-02-04 01:26:02375 request.referrerPolicy());
[email protected]44e55b012013-07-23 14:21:56376}
377
[email protected]c6bc20332014-02-28 18:30:39378// static
[email protected]65920f332014-03-04 21:14:18379WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
[email protected]48861e22013-01-09 00:27:32380 WebNavigationPolicy policy) {
381 switch (policy) {
[email protected]180ef242013-11-07 06:50:46382 case blink::WebNavigationPolicyIgnore:
[email protected]48861e22013-01-09 00:27:32383 return IGNORE_ACTION;
[email protected]180ef242013-11-07 06:50:46384 case blink::WebNavigationPolicyDownload:
[email protected]48861e22013-01-09 00:27:32385 return SAVE_TO_DISK;
[email protected]180ef242013-11-07 06:50:46386 case blink::WebNavigationPolicyCurrentTab:
[email protected]48861e22013-01-09 00:27:32387 return CURRENT_TAB;
[email protected]180ef242013-11-07 06:50:46388 case blink::WebNavigationPolicyNewBackgroundTab:
[email protected]48861e22013-01-09 00:27:32389 return NEW_BACKGROUND_TAB;
[email protected]180ef242013-11-07 06:50:46390 case blink::WebNavigationPolicyNewForegroundTab:
[email protected]48861e22013-01-09 00:27:32391 return NEW_FOREGROUND_TAB;
[email protected]180ef242013-11-07 06:50:46392 case blink::WebNavigationPolicyNewWindow:
[email protected]48861e22013-01-09 00:27:32393 return NEW_WINDOW;
[email protected]180ef242013-11-07 06:50:46394 case blink::WebNavigationPolicyNewPopup:
[email protected]48861e22013-01-09 00:27:32395 return NEW_POPUP;
396 default:
397 NOTREACHED() << "Unexpected WebNavigationPolicy";
398 return IGNORE_ACTION;
399 }
400}
401
[email protected]d8221b22013-05-23 05:35:43402// Returns true if the device scale is high enough that losing subpixel
403// antialiasing won't have a noticeable effect on text quality.
404static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
405#if defined(OS_ANDROID)
406 // On Android, we never have subpixel antialiasing.
407 return true;
408#else
409 return device_scale_factor > 1.5f;
410#endif
411
412}
413
[email protected]fb854192013-02-06 01:30:04414static bool ShouldUseFixedPositionCompositing(float device_scale_factor) {
415 // Compositing for fixed-position elements is dependent on
[email protected]d8221b22013-05-23 05:35:43416 // device_scale_factor if no flag is set. http://crbug.com/172738
[email protected]fb854192013-02-06 01:30:04417 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
418
419 if (command_line.HasSwitch(switches::kDisableCompositingForFixedPosition))
420 return false;
421
422 if (command_line.HasSwitch(switches::kEnableCompositingForFixedPosition))
423 return true;
424
[email protected]d8221b22013-05-23 05:35:43425 return DeviceScaleEnsuresTextQuality(device_scale_factor);
426}
427
[email protected]c162ced82013-06-29 01:24:53428static bool ShouldUseAcceleratedCompositingForOverflowScroll(
429 float device_scale_factor) {
430 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
431
[email protected]7d20c7c2013-10-15 13:55:46432 if (command_line.HasSwitch(switches::kDisableAcceleratedOverflowScroll))
433 return false;
434
[email protected]c162ced82013-06-29 01:24:53435 if (command_line.HasSwitch(switches::kEnableAcceleratedOverflowScroll))
436 return true;
437
438 return DeviceScaleEnsuresTextQuality(device_scale_factor);
439}
440
[email protected]e3415902013-10-17 15:00:46441static bool ShouldUseAcceleratedCompositingForScrollableFrames(
442 float device_scale_factor) {
[email protected]a23530d2014-03-11 06:04:14443 if (RenderThreadImpl::current() &&
444 !RenderThreadImpl::current()->is_lcd_text_enabled())
[email protected]e3415902013-10-17 15:00:46445 return true;
446
447 return DeviceScaleEnsuresTextQuality(device_scale_factor);
448}
449
450static bool ShouldUseCompositedScrollingForFrames(
451 float device_scale_factor) {
[email protected]a23530d2014-03-11 06:04:14452 if (RenderThreadImpl::current() &&
453 !RenderThreadImpl::current()->is_lcd_text_enabled())
[email protected]e3415902013-10-17 15:00:46454 return true;
455
456 return DeviceScaleEnsuresTextQuality(device_scale_factor);
457}
458
[email protected]f388a5d2013-11-04 20:19:13459static bool ShouldUseUniversalAcceleratedCompositingForOverflowScroll() {
[email protected]44de7492013-10-18 15:14:59460 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
461
462 if (command_line.HasSwitch(
463 switches::kDisableUniversalAcceleratedOverflowScroll))
464 return false;
465
466 if (command_line.HasSwitch(
467 switches::kEnableUniversalAcceleratedOverflowScroll))
468 return true;
469
[email protected]f388a5d2013-11-04 20:19:13470 return false;
[email protected]44de7492013-10-18 15:14:59471}
472
[email protected]d8221b22013-05-23 05:35:43473static bool ShouldUseTransitionCompositing(float device_scale_factor) {
474 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
475
476 if (command_line.HasSwitch(switches::kDisableCompositingForTransition))
477 return false;
478
479 if (command_line.HasSwitch(switches::kEnableCompositingForTransition))
[email protected]fb854192013-02-06 01:30:04480 return true;
481
[email protected]9a7f6e12013-06-11 07:05:13482 // TODO(ajuma): Re-enable this by default for high-DPI once the problem
483 // of excessive layer promotion caused by overlap has been addressed.
484 // http://crbug.com/178119.
485 return false;
[email protected]fb854192013-02-06 01:30:04486}
487
[email protected]06fc4d3b2013-07-08 21:07:24488static bool ShouldUseAcceleratedFixedRootBackground(float device_scale_factor) {
489 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
490
491 if (command_line.HasSwitch(switches::kDisableAcceleratedFixedRootBackground))
492 return false;
493
494 if (command_line.HasSwitch(switches::kEnableAcceleratedFixedRootBackground))
495 return true;
496
497 return DeviceScaleEnsuresTextQuality(device_scale_factor);
498}
499
[email protected]41d04932014-03-13 15:05:45500static bool ShouldUseCompositingForGpuRasterizationHint() {
501 return RenderThreadImpl::current() &&
502 RenderThreadImpl::current()->is_gpu_rasterization_enabled();
503}
504
[email protected]180ef242013-11-07 06:50:46505static FaviconURL::IconType ToFaviconType(blink::WebIconURL::Type type) {
[email protected]41225fe2013-03-29 05:32:02506 switch (type) {
[email protected]180ef242013-11-07 06:50:46507 case blink::WebIconURL::TypeFavicon:
[email protected]41225fe2013-03-29 05:32:02508 return FaviconURL::FAVICON;
[email protected]180ef242013-11-07 06:50:46509 case blink::WebIconURL::TypeTouch:
[email protected]41225fe2013-03-29 05:32:02510 return FaviconURL::TOUCH_ICON;
[email protected]180ef242013-11-07 06:50:46511 case blink::WebIconURL::TypeTouchPrecomposed:
[email protected]41225fe2013-03-29 05:32:02512 return FaviconURL::TOUCH_PRECOMPOSED_ICON;
[email protected]180ef242013-11-07 06:50:46513 case blink::WebIconURL::TypeInvalid:
[email protected]41225fe2013-03-29 05:32:02514 return FaviconURL::INVALID_ICON;
515 }
516 return FaviconURL::INVALID_ICON;
517}
518
[email protected]f34ac132014-03-20 23:02:05519static void ConvertToFaviconSizes(
520 const blink::WebVector<blink::WebSize>& web_sizes,
521 std::vector<gfx::Size>* sizes) {
522 for (size_t i = 0; i < web_sizes.size(); ++i)
523 sizes->push_back(gfx::Size(web_sizes[i]));
524}
525
initial.commit09911bf2008-07-26 23:55:29526///////////////////////////////////////////////////////////////////////////////
527
[email protected]310ebd6302011-10-10 19:06:28528struct RenderViewImpl::PendingFileChooser {
[email protected]e9ff79c2012-10-19 21:31:26529 PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c)
[email protected]cdaf8d02010-03-30 19:52:47530 : params(p),
531 completion(c) {
532 }
[email protected]e9ff79c2012-10-19 21:31:26533 FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47534 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
535};
536
[email protected]217690d2012-01-27 07:33:11537namespace {
538
539class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
540 public:
[email protected]180ef242013-11-07 06:50:46541 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
[email protected]217690d2012-01-27 07:33:11542 : webwidget_(webwidget) {}
543
544 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
545 if (succeeded)
546 webwidget_->didAcquirePointerLock();
547 else
548 webwidget_->didNotAcquirePointerLock();
549 }
550
551 virtual void OnMouseLockLost() OVERRIDE {
552 webwidget_->didLosePointerLock();
553 }
554
555 virtual bool HandleMouseLockedInputEvent(
[email protected]180ef242013-11-07 06:50:46556 const blink::WebMouseEvent &event) OVERRIDE {
[email protected]217690d2012-01-27 07:33:11557 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
558 return false;
559 }
560
561 private:
[email protected]180ef242013-11-07 06:50:46562 blink::WebWidget* webwidget_;
[email protected]217690d2012-01-27 07:33:11563};
564
[email protected]41225fe2013-03-29 05:32:02565bool TouchEnabled() {
566// Based on the definition of chrome::kEnableTouchIcon.
567#if defined(OS_ANDROID)
568 return true;
569#else
570 return false;
571#endif
572}
573
[email protected]dc293a72013-07-01 11:11:22574WebDragData DropDataToWebDragData(const DropData& drop_data) {
[email protected]c10680312013-05-31 15:22:05575 std::vector<WebDragData::Item> item_list;
576
577 // These fields are currently unused when dragging into WebKit.
578 DCHECK(drop_data.download_metadata.empty());
579 DCHECK(drop_data.file_contents.empty());
580 DCHECK(drop_data.file_description_filename.empty());
581
582 if (!drop_data.text.is_null()) {
583 WebDragData::Item item;
584 item.storageType = WebDragData::Item::StorageTypeString;
585 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText);
586 item.stringData = drop_data.text.string();
587 item_list.push_back(item);
588 }
589
590 // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it
591 // meaningful to write an empty URL to the clipboard?
592 if (!drop_data.url.is_empty()) {
593 WebDragData::Item item;
594 item.storageType = WebDragData::Item::StorageTypeString;
595 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList);
596 item.stringData = WebString::fromUTF8(drop_data.url.spec());
597 item.title = drop_data.url_title;
598 item_list.push_back(item);
599 }
600
601 if (!drop_data.html.is_null()) {
602 WebDragData::Item item;
603 item.storageType = WebDragData::Item::StorageTypeString;
604 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML);
605 item.stringData = drop_data.html.string();
606 item.baseURL = drop_data.html_base_url;
607 item_list.push_back(item);
608 }
609
[email protected]17ea0ae22014-03-28 21:54:46610 for (std::vector<ui::FileInfo>::const_iterator it =
[email protected]c10680312013-05-31 15:22:05611 drop_data.filenames.begin();
612 it != drop_data.filenames.end();
613 ++it) {
614 WebDragData::Item item;
615 item.storageType = WebDragData::Item::StorageTypeFilename;
[email protected]17ea0ae22014-03-28 21:54:46616 item.filenameData = it->path.AsUTF16Unsafe();
617 item.displayNameData = it->display_name.AsUTF16Unsafe();
[email protected]c10680312013-05-31 15:22:05618 item_list.push_back(item);
619 }
620
621 for (std::map<base::string16, base::string16>::const_iterator it =
622 drop_data.custom_data.begin();
623 it != drop_data.custom_data.end();
624 ++it) {
625 WebDragData::Item item;
626 item.storageType = WebDragData::Item::StorageTypeString;
627 item.stringType = it->first;
628 item.stringData = it->second;
629 item_list.push_back(item);
630 }
631
632 WebDragData result;
633 result.initialize();
634 result.setItems(item_list);
635 result.setFilesystemId(drop_data.filesystem_id);
636 return result;
637}
638
[email protected]217690d2012-01-27 07:33:11639} // namespace
640
[email protected]8d41d7612012-11-14 20:32:19641RenderViewImpl::RenderViewImpl(RenderViewImplParams* params)
[email protected]180ef242013-11-07 06:50:46642 : RenderWidget(blink::WebPopupTypeNone,
[email protected]8d41d7612012-11-14 20:32:19643 params->screen_info,
[email protected]1ac10dca2013-08-20 20:47:04644 params->swapped_out,
645 params->hidden),
[email protected]8d41d7612012-11-14 20:32:19646 webkit_preferences_(params->webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02647 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09648 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02649 send_preferred_size_changes_(false),
[email protected]e75cb49e2009-01-05 23:13:21650 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02651 opened_by_user_gesture_(true),
652 opener_suppressed_(false),
[email protected]88f10a22013-11-06 21:22:12653 suppress_dialogs_until_swap_out_(false),
[email protected]81a34412009-01-05 19:17:24654 page_id_(-1),
655 last_page_id_sent_to_browser_(-1),
[email protected]8d41d7612012-11-14 20:32:19656 next_page_id_(params->next_page_id),
[email protected]3cc72b12010-03-18 23:03:00657 history_list_offset_(-1),
658 history_list_length_(0),
[email protected]7e9523b2014-03-25 03:02:42659 frames_in_progress_(0),
[email protected]3354d3e2010-06-10 19:53:02660 target_url_status_(TARGET_NONE),
[email protected]bbc8856d2013-06-14 10:37:04661#if defined(OS_ANDROID)
662 top_controls_constraints_(cc::BOTH),
663#endif
[email protected]dd6afca2011-08-13 03:44:31664 cached_is_main_frame_pinned_to_left_(false),
665 cached_is_main_frame_pinned_to_right_(false),
666 cached_has_main_frame_horizontal_scrollbar_(false),
667 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]1875bc02014-03-14 06:33:59668 has_scrolled_focused_editable_node_into_rect_(false),
[email protected]8a67aa352013-02-20 02:58:29669 notification_provider_(NULL),
[email protected]e1c174162014-04-08 15:39:31670 push_messaging_dispatcher_(NULL),
[email protected]676126f72011-01-15 00:03:51671 geolocation_dispatcher_(NULL),
[email protected]c52b2892012-03-07 11:01:02672 input_tag_speech_dispatcher_(NULL),
[email protected]64d09222012-05-25 10:10:34673 speech_recognition_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51674 media_stream_dispatcher_(NULL),
[email protected]fb325d122012-11-20 23:58:05675 browser_plugin_manager_(NULL),
[email protected]c3bdce152013-07-10 04:56:34676 media_stream_client_(NULL),
677 web_user_media_client_(NULL),
[email protected]f39b9d52013-07-28 08:03:44678 midi_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41679 devtools_agent_(NULL),
[email protected]2a84f9d2012-06-05 21:50:43680 accessibility_mode_(AccessibilityModeOff),
[email protected]063afcb2011-09-29 07:54:32681 renderer_accessibility_(NULL),
[email protected]217690d2012-01-27 07:33:11682 mouse_lock_dispatcher_(NULL),
[email protected]20657a82012-08-21 20:23:03683#if defined(OS_ANDROID)
[email protected]4d0f8182012-10-19 23:14:47684 body_background_color_(SK_ColorWHITE),
[email protected]20657a82012-08-21 20:23:03685 expected_content_intent_id_(0),
[email protected]305ecfc72013-10-31 00:35:48686 media_player_manager_(NULL),
[email protected]a7564272013-04-19 14:24:46687#endif
688#if defined(OS_WIN)
689 focused_plugin_id_(-1),
690#endif
[email protected]e16c7a12013-12-05 16:30:08691#if defined(ENABLE_PLUGINS)
[email protected]54ea9ff2014-03-20 00:27:54692 plugin_find_handler_(NULL),
[email protected]e16c7a12013-12-05 16:30:08693 focused_pepper_plugin_(NULL),
694 pepper_last_mouse_event_target_(NULL),
695#endif
[email protected]8a67aa352013-02-20 02:58:29696 enumeration_completion_id_(0),
[email protected]69e797f2013-04-30 01:10:22697 load_progress_tracker_(new LoadProgressTracker(this)),
[email protected]8d41d7612012-11-14 20:32:19698 session_storage_namespace_id_(params->session_storage_namespace_id),
[email protected]f2c530d2014-02-20 20:15:30699 next_snapshot_id_(0) {
[email protected]075366912013-02-18 07:13:24700}
701
[email protected]0287e762014-04-11 13:07:58702void RenderViewImpl::Initialize(
703 RenderViewImplParams* params,
704 RenderFrameImpl* main_render_frame) {
[email protected]8d41d7612012-11-14 20:32:19705 routing_id_ = params->routing_id;
706 surface_id_ = params->surface_id;
707 if (params->opener_id != MSG_ROUTING_NONE && params->is_renderer_created)
708 opener_id_ = params->opener_id;
[email protected]676126f72011-01-15 00:03:51709
[email protected]74ce1ad2011-12-16 21:51:46710 // Ensure we start with a valid next_page_id_ from the browser.
711 DCHECK_GE(next_page_id_, 0);
712
[email protected]21b3a6ae2011-11-30 00:45:29713#if defined(ENABLE_NOTIFICATIONS)
714 notification_provider_ = new NotificationProvider(this);
715#else
716 notification_provider_ = NULL;
717#endif
718
[email protected]11fee2332011-03-29 20:36:35719 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11720 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35721
[email protected]20657a82012-08-21 20:23:03722 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
723
[email protected]27c521a2013-05-29 20:44:32724 if (command_line.HasSwitch(switches::kStatsCollectionController))
725 stats_collection_observer_.reset(new StatsCollectionObserver(this));
726
[email protected]20657a82012-08-21 20:23:03727#if defined(OS_ANDROID)
[email protected]276e8a322013-01-24 01:50:11728 content::DeviceTelephonyInfo device_info;
[email protected]20657a82012-08-21 20:23:03729
730 const std::string region_code =
731 command_line.HasSwitch(switches::kNetworkCountryIso)
732 ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso)
[email protected]276e8a322013-01-24 01:50:11733 : device_info.GetNetworkCountryIso();
[email protected]20657a82012-08-21 20:23:03734 content_detectors_.push_back(linked_ptr<ContentDetector>(
735 new AddressDetector()));
736 content_detectors_.push_back(linked_ptr<ContentDetector>(
737 new PhoneNumberDetector(region_code)));
738 content_detectors_.push_back(linked_ptr<ContentDetector>(
739 new EmailDetector()));
740#endif
741
[email protected]380244092011-10-07 17:26:27742 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51743 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47744 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51745 AddRef();
[email protected]b2db9272014-01-10 17:42:00746 if (RenderThreadImpl::current()) {
747 RenderThreadImpl::current()->WidgetCreated();
748 if (is_hidden_)
749 RenderThreadImpl::current()->WidgetHidden();
750 }
[email protected]676126f72011-01-15 00:03:51751
752 // If this is a popup, we must wait for the CreatingNew_ACK message before
753 // completing initialization. Otherwise, we can finish it now.
[email protected]6cd7c6b2012-10-25 03:26:23754 if (opener_id_ == MSG_ROUTING_NONE) {
[email protected]676126f72011-01-15 00:03:51755 did_show_ = true;
[email protected]fc4404d2012-11-07 19:53:30756 CompleteInit();
[email protected]676126f72011-01-15 00:03:51757 }
758
[email protected]34c61bd52011-05-02 19:38:33759 g_view_map.Get().insert(std::make_pair(webview(), this));
[email protected]058561b2012-12-03 06:48:22760 g_routing_id_view_map.Get().insert(std::make_pair(routing_id_, this));
[email protected]60051ec2012-06-08 22:40:57761 webview()->setDeviceScaleFactor(device_scale_factor_);
[email protected]fb854192013-02-06 01:30:04762 webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled(
763 ShouldUseFixedPositionCompositing(device_scale_factor_));
[email protected]c162ced82013-06-29 01:24:53764 webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled(
765 ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_));
[email protected]44de7492013-10-18 15:14:59766 webview()->settings()->setCompositorDrivenAcceleratedScrollingEnabled(
[email protected]f388a5d2013-11-04 20:19:13767 ShouldUseUniversalAcceleratedCompositingForOverflowScroll());
[email protected]d8221b22013-05-23 05:35:43768 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
769 ShouldUseTransitionCompositing(device_scale_factor_));
[email protected]06fc4d3b2013-07-08 21:07:24770 webview()->settings()->setAcceleratedCompositingForFixedRootBackgroundEnabled(
771 ShouldUseAcceleratedFixedRootBackground(device_scale_factor_));
[email protected]e3415902013-10-17 15:00:46772 webview()->settings()->setAcceleratedCompositingForScrollableFramesEnabled(
773 ShouldUseAcceleratedCompositingForScrollableFrames(device_scale_factor_));
774 webview()->settings()->setCompositedScrollingForFramesEnabled(
775 ShouldUseCompositedScrollingForFrames(device_scale_factor_));
[email protected]41d04932014-03-13 15:05:45776 webview()->settings()
777 ->setAcceleratedCompositingForGpuRasterizationHintEnabled(
778 ShouldUseCompositingForGpuRasterizationHint());
[email protected]fb854192013-02-06 01:30:04779
[email protected]49a20002013-08-18 12:43:31780 ApplyWebPreferences(webkit_preferences_, webview());
[email protected]9b159a52013-10-03 17:24:55781
[email protected]0287e762014-04-11 13:07:58782 main_render_frame_.reset(main_render_frame);
783 webview()->setMainFrame(main_render_frame_->GetWebFrame());
784 main_render_frame_->Initialize();
[email protected]edbea622012-11-28 20:39:38785
[email protected]1400e6dc2013-04-27 02:36:27786 if (switches::IsTouchDragDropEnabled())
[email protected]edbea622012-11-28 20:39:38787 webview()->settings()->setTouchDragDropEnabled(true);
788
[email protected]1400e6dc2013-04-27 02:36:27789 if (switches::IsTouchEditingEnabled())
[email protected]47822262013-04-23 17:22:36790 webview()->settings()->setTouchEditingEnabled(true);
791
[email protected]8d41d7612012-11-14 20:32:19792 if (!params->frame_name.empty())
793 webview()->mainFrame()->setName(params->frame_name);
[email protected]34c61bd52011-05-02 19:38:33794
[email protected]8d41d7612012-11-14 20:32:19795 OnSetRendererPrefs(params->renderer_prefs);
[email protected]34c61bd52011-05-02 19:38:33796
[email protected]4fb0f202012-05-30 22:44:53797#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02798 if (!media_stream_dispatcher_)
799 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32800#endif
[email protected]735873d2012-01-25 23:31:02801
[email protected]8f6a3b852011-07-19 16:48:56802 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32803#if defined(OS_MACOSX)
804 new TextInputClientObserver(this);
805#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56806
[email protected]2d7b82c2012-06-01 05:57:50807#if defined(OS_ANDROID)
[email protected]305ecfc72013-10-31 00:35:48808 media_player_manager_ = new RendererMediaPlayerManager(this);
[email protected]2d7b82c2012-06-01 05:57:50809#endif
810
[email protected]217690d2012-01-27 07:33:11811 // The next group of objects all implement RenderViewObserver, so are deleted
812 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41813 devtools_agent_ = new DevToolsAgent(this);
[email protected]6e89eb72013-07-23 13:28:22814 if (RenderWidgetCompositor* rwc = compositor()) {
815 webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId());
816 }
[email protected]89054502012-06-03 10:29:24817 mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
[email protected]063afcb2011-09-29 07:54:32818
[email protected]2a84f9d2012-06-05 21:50:43819 // Create renderer_accessibility_ if needed.
[email protected]8d41d7612012-11-14 20:32:19820 OnSetAccessibilityMode(params->accessibility_mode);
[email protected]2a84f9d2012-06-05 21:50:43821
[email protected]1784b2f2011-11-24 10:53:48822 new IdleUserDetector(this);
823
[email protected]766a7082012-02-03 23:39:15824 if (command_line.HasSwitch(switches::kDomAutomationController))
[email protected]e9ff79c2012-10-19 21:31:26825 enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION;
[email protected]27c521a2013-05-29 20:44:32826 if (command_line.HasSwitch(switches::kStatsCollectionController))
827 enabled_bindings_ |= BINDINGS_POLICY_STATS_COLLECTION;
[email protected]766a7082012-02-03 23:39:15828
[email protected]5b52cd2f712012-03-28 02:12:48829 ProcessViewLayoutFlags(command_line);
[email protected]7ddea9802012-02-22 23:08:05830
[email protected]e9ff79c2012-10-19 21:31:26831 GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44832
833 // If we have an opener_id but we weren't created by a renderer, then
834 // it's the browser asking us to set our opener to another RenderView.
[email protected]8d41d7612012-11-14 20:32:19835 if (params->opener_id != MSG_ROUTING_NONE && !params->is_renderer_created) {
836 RenderViewImpl* opener_view = FromRoutingID(params->opener_id);
[email protected]f546640b2012-05-15 00:03:49837 if (opener_view)
838 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
[email protected]14392a52012-05-02 20:28:44839 }
840
841 // If we are initially swapped out, navigate to kSwappedOutURL.
842 // This ensures we are in a unique origin that others cannot script.
843 if (is_swapped_out_)
[email protected]0720b532012-08-28 19:23:37844 NavigateToSwappedOutURL(webview()->mainFrame());
initial.commit09911bf2008-07-26 23:55:29845}
846
[email protected]310ebd6302011-10-10 19:06:28847RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03848 history_page_ids_.clear();
849
[email protected]91a2aea2013-07-08 23:14:39850 base::debug::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_);
851
[email protected]a1128322009-10-06 18:38:46852 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47853 while (!file_chooser_completions_.empty()) {
854 if (file_chooser_completions_.front()->completion) {
855 file_chooser_completions_.front()->completion->didChooseFile(
856 WebVector<WebString>());
857 }
858 file_chooser_completions_.pop_front();
859 }
[email protected]a1128322009-10-06 18:38:46860
[email protected]8ed1d3f2013-02-20 11:45:55861#if defined(OS_ANDROID)
862 // The date/time picker client is both a scoped_ptr member of this class and
863 // a RenderViewObserver. Reset it to prevent double deletion.
864 date_time_picker_client_.reset();
865#endif
866
[email protected]60c42a8c72009-10-09 04:08:59867#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22868 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49869 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59870 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
871 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:22872 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
873 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
874 it != routing_id_views->end(); ++it)
875 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:59876#endif
[email protected]676126f72011-01-15 00:03:51877
[email protected]310ebd6302011-10-10 19:06:28878 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51879 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59880}
881
882/*static*/
[email protected]310ebd6302011-10-10 19:06:28883RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31884 ViewMap* views = g_view_map.Pointer();
885 ViewMap::iterator it = views->find(webview);
886 return it == views->end() ? NULL : it->second;
887}
888
889/*static*/
[email protected]180ef242013-11-07 06:50:46890RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28891 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31892}
893
894/*static*/
[email protected]640e303c2012-12-05 01:36:07895RenderViewImpl* RenderViewImpl::FromRoutingID(int32 routing_id) {
896 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
897 RoutingIDViewMap::iterator it = views->find(routing_id);
898 return it == views->end() ? NULL : it->second;
899}
900
901/*static*/
902RenderView* RenderView::FromRoutingID(int routing_id) {
903 return RenderViewImpl::FromRoutingID(routing_id);
904}
905
906/*static*/
[email protected]e9ff79c2012-10-19 21:31:26907void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49908 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59909 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
910 if (!visitor->Visit(it->second))
911 return;
912 }
913}
914
915/*static*/
[email protected]310ebd6302011-10-10 19:06:28916RenderViewImpl* RenderViewImpl::Create(
[email protected]0aa55312008-10-17 21:53:08917 int32 opener_id,
[email protected]e9ff79c2012-10-19 21:31:26918 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08919 const WebPreferences& webkit_prefs,
[email protected]4e6419c2010-01-15 04:50:34920 int32 routing_id,
[email protected]227692c52013-05-31 22:43:04921 int32 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:56922 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26923 int64 session_storage_namespace_id,
[email protected]fcf75d42013-12-03 20:11:26924 const base::string16& frame_name,
[email protected]14392a52012-05-02 20:28:44925 bool is_renderer_created,
926 bool swapped_out,
[email protected]1ac10dca2013-08-20 20:47:04927 bool hidden,
[email protected]6fd35b72012-03-01 19:46:41928 int32 next_page_id,
[email protected]180ef242013-11-07 06:50:46929 const blink::WebScreenInfo& screen_info,
[email protected]bfa71242014-03-27 21:10:24930 AccessibilityMode accessibility_mode) {
initial.commit09911bf2008-07-26 23:55:29931 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]f2c530d2014-02-20 20:15:30932 RenderViewImplParams params(opener_id,
933 renderer_prefs,
934 webkit_prefs,
935 routing_id,
936 main_frame_routing_id,
937 surface_id,
938 session_storage_namespace_id,
939 frame_name,
940 is_renderer_created,
941 swapped_out,
942 hidden,
943 next_page_id,
944 screen_info,
945 accessibility_mode);
[email protected]075366912013-02-18 07:13:24946 RenderViewImpl* render_view = NULL;
[email protected]8d41d7612012-11-14 20:32:19947 if (g_create_render_view_impl)
[email protected]075366912013-02-18 07:13:24948 render_view = g_create_render_view_impl(&params);
949 else
950 render_view = new RenderViewImpl(&params);
[email protected]0287e762014-04-11 13:07:58951
952 RenderFrameImpl* main_frame = RenderFrameImpl::Create(
953 render_view, main_frame_routing_id);
954 // The main frame WebLocalFrame object is closed by
955 // RenderFrameImpl::frameDetached().
956 WebLocalFrame* web_frame = WebLocalFrame::create(main_frame);
957 main_frame->SetWebFrame(web_frame);
958
959 render_view->Initialize(&params, main_frame);
[email protected]075366912013-02-18 07:13:24960 return render_view;
[email protected]8d41d7612012-11-14 20:32:19961}
962
963// static
964void RenderViewImpl::InstallCreateHook(
965 RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*)) {
966 CHECK(!g_create_render_view_impl);
967 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:29968}
969
[email protected]310ebd6302011-10-10 19:06:28970void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51971 observers_.AddObserver(observer);
972}
973
[email protected]310ebd6302011-10-10 19:06:28974void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
975 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51976 observers_.RemoveObserver(observer);
977}
978
[email protected]180ef242013-11-07 06:50:46979blink::WebView* RenderViewImpl::webview() const {
980 return static_cast<blink::WebView*>(webwidget());
[email protected]4d51d5bf2010-07-26 18:48:26981}
982
[email protected]ea2fb972013-08-07 05:44:26983#if defined(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:57984void RenderViewImpl::PepperInstanceCreated(
985 PepperPluginInstanceImpl* instance) {
986 active_pepper_instances_.insert(instance);
987}
988
989void RenderViewImpl::PepperInstanceDeleted(
990 PepperPluginInstanceImpl* instance) {
991 active_pepper_instances_.erase(instance);
992
993 if (pepper_last_mouse_event_target_ == instance)
994 pepper_last_mouse_event_target_ = NULL;
995 if (focused_pepper_plugin_ == instance)
996 PepperFocusChanged(instance, false);
997}
998
999void RenderViewImpl::PepperFocusChanged(PepperPluginInstanceImpl* instance,
1000 bool focused) {
1001 if (focused)
1002 focused_pepper_plugin_ = instance;
1003 else if (focused_pepper_plugin_ == instance)
1004 focused_pepper_plugin_ = NULL;
1005
1006 UpdateTextInputType();
1007 UpdateSelectionBounds();
1008}
1009
[email protected]310ebd6302011-10-10 19:06:281010void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:261011 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:301012 // If the renderer is visible, set initial visibility and focus state.
1013 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:341014#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:301015 delegate->SetContainerVisibility(true);
1016 if (webview() && webview()->isActive())
1017 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:341018#endif
[email protected]49232292010-09-03 19:07:301019 }
[email protected]784ea1ab2010-09-18 00:02:341020 // Plugins start assuming the content has focus (so that they work in
1021 // environments where RenderView isn't hosting them), so we always have to
1022 // set the initial state. See webplugin_delegate_impl.h for details.
1023 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:261024}
1025
[email protected]310ebd6302011-10-10 19:06:281026void RenderViewImpl::UnregisterPluginDelegate(
1027 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:261028 plugin_delegates_.erase(delegate);
1029}
[email protected]d8fd6fa2010-02-01 15:54:261030
[email protected]a80af12e2013-08-07 23:36:131031#if defined(OS_WIN)
1032void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
1033 if (focused)
1034 focused_plugin_id_ = plugin_id;
1035 else
1036 focused_plugin_id_ = -1;
1037}
1038#endif
1039
1040#if defined(OS_MACOSX)
1041void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
1042 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
1043}
1044
1045void RenderViewImpl::StartPluginIme() {
1046 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
1047 // This message can be sent during event-handling, and needs to be delivered
1048 // within that context.
1049 msg->set_unblock(true);
1050 Send(msg);
1051}
1052#endif // defined(OS_MACOSX)
1053
1054#endif // ENABLE_PLUGINS
1055
[email protected]7a1ec28a2012-03-28 21:10:241056void RenderViewImpl::TransferActiveWheelFlingAnimation(
[email protected]180ef242013-11-07 06:50:461057 const blink::WebActiveWheelFlingParameters& params) {
[email protected]7a1ec28a2012-03-28 21:10:241058 if (webview())
1059 webview()->transferActiveWheelFlingAnimation(params);
1060}
1061
[email protected]8fe8f742012-06-14 00:36:081062bool RenderViewImpl::HasIMETextFocus() {
1063 return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
1064}
1065
[email protected]310ebd6302011-10-10 19:06:281066bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:271067 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:271068 if (main_frame)
[email protected]e9ff79c2012-10-19 21:31:261069 GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:261070
[email protected]676126f72011-01-15 00:03:511071 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
1072 RenderViewObserver* observer;
1073 while ((observer = it.GetNext()) != NULL)
1074 if (observer->OnMessageReceived(message))
1075 return true;
[email protected]b2abac72009-02-26 12:39:281076
[email protected]a95986a82010-12-24 06:19:281077 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:401078 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:281079 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
[email protected]c084330e02013-04-27 01:08:151080 IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand)
1081 IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret)
[email protected]c084330e02013-04-27 01:08:151082 IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect,
1083 OnScrollFocusedEditableNodeIntoRect)
[email protected]c084330e02013-04-27 01:08:151084 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
1085 OnSetEditCommandsForNextKeyEvent)
[email protected]c6bc20332014-02-28 18:30:391086 IPC_MESSAGE_HANDLER(FrameMsg_Navigate, OnNavigate)
initial.commit09911bf2008-07-26 23:55:291087 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]25bcc8f2013-01-09 02:49:251088 IPC_MESSAGE_HANDLER(ViewMsg_SetName, OnSetName)
initial.commit09911bf2008-07-26 23:55:291089 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
1090 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:491091 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
[email protected]630e26b2008-10-14 22:55:171092 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:171093 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:541094 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1095 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:291096 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:181097 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1098 OnResetPageEncodingToDefault)
[email protected]f546640b2012-05-15 00:03:491099 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
[email protected]59f4f2fa2011-03-23 01:00:551100 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
1101 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
1102 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
1103 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
[email protected]7a6d773f2014-04-04 01:25:091104 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
[email protected]59f4f2fa2011-03-23 01:00:551105 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
1106 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:451107 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:291108 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291109 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1110 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]600ea402011-04-12 00:01:511111 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
1112 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:291113 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]88f10a22013-11-06 21:22:121114 IPC_MESSAGE_HANDLER(ViewMsg_SuppressDialogsUntilSwapOut,
1115 OnSuppressDialogsUntilSwapOut)
initial.commit09911bf2008-07-26 23:55:291116 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1117 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]30f75e62009-02-25 22:01:001118 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]ab6c9112014-02-27 00:20:581119 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedElement, OnClearFocusedElement)
[email protected]699ab0d2009-04-23 23:19:141120 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:251121 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1122 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:471123 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:341124 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:101125 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1126 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511127 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:561128 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]77829642012-05-15 14:47:171129 IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent,
1130 OnOrientationChangeEvent)
[email protected]81375e872012-01-11 21:40:361131 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:341132 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]18d5be92011-07-25 18:00:191133 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1134 OnGetAllSavableResourceLinksForCurrentPage)
1135 IPC_MESSAGE_HANDLER(
1136 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1137 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]47822262013-04-23 17:22:361138 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
[email protected]f0557932011-01-25 20:20:511139 // TODO(viettrungluu): Move to a separate message filter.
[email protected]9e1ad4b2011-08-14 16:49:191140 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
1141 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:181142 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]2a84f9d2012-06-05 21:50:431143 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode)
[email protected]7cc78902012-12-06 02:32:261144 IPC_MESSAGE_HANDLER(ViewMsg_DisownOpener, OnDisownOpener)
[email protected]a794f3a2013-10-30 17:00:321145 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB,
1146 OnReleaseDisambiguationPopupDIB)
1147 IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted,
1148 OnWindowSnapshotCompleted)
[email protected]55750b32012-09-21 14:05:031149#if defined(OS_ANDROID)
[email protected]c084330e02013-04-27 01:08:151150 IPC_MESSAGE_HANDLER(InputMsg_ActivateNearestFindResult,
[email protected]55750b32012-09-21 14:05:031151 OnActivateNearestFindResult)
1152 IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects)
1153 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
[email protected]452b4a92013-03-28 21:24:381154 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState,
1155 OnUpdateTopControlsState)
[email protected]68877c282013-09-20 05:52:421156 IPC_MESSAGE_HANDLER(ViewMsg_PauseVideo, OnPauseVideo)
[email protected]c4790dcb2013-12-27 22:08:021157 IPC_MESSAGE_HANDLER(ViewMsg_ExtractSmartClipData, OnExtractSmartClipData)
[email protected]55750b32012-09-21 14:05:031158#elif defined(OS_MACOSX)
[email protected]55750b32012-09-21 14:05:031159 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1160 OnPluginImeCompositionCompleted)
1161 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1162 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
1163 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
1164 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
1165#endif
[email protected]a794f3a2013-10-30 17:00:321166 // Adding a new message? Add platform independent ones first, then put the
1167 // platform specific ones at the end.
[email protected]9e1ad4b2011-08-14 16:49:191168
initial.commit09911bf2008-07-26 23:55:291169 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281170 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291171 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401172
1173 if (!msg_is_ok) {
1174 // The message had a handler, but its deserialization failed.
1175 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:281176 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:401177 }
1178
[email protected]a95986a82010-12-24 06:19:281179 return handled;
initial.commit09911bf2008-07-26 23:55:291180}
1181
[email protected]c6bc20332014-02-28 18:30:391182void RenderViewImpl::OnNavigate(const FrameMsg_Navigate_Params& params) {
[email protected]440a0e52011-09-13 17:38:581183 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
initial.commit09911bf2008-07-26 23:55:291184}
1185
[email protected]310ebd6302011-10-10 19:06:281186bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]c6bc20332014-02-28 18:30:391187 const FrameMsg_Navigate_Params& params,
[email protected]d466b8a2011-07-15 21:48:031188 bool is_reload) {
1189 // Make sure this isn't a back/forward to an entry we have already cropped
1190 // or replaced from our history, before the browser knew about it. If so,
1191 // a new navigation has committed in the mean time, and we can ignore this.
[email protected]691aa2f2013-05-28 22:52:041192 bool is_back_forward = !is_reload && params.page_state.IsValid();
[email protected]d466b8a2011-07-15 21:48:031193
1194 // Note: if the history_list_length_ is 0 for a back/forward, we must be
1195 // restoring from a previous session. We'll update our state in OnNavigate.
1196 if (!is_back_forward || history_list_length_ <= 0)
1197 return false;
1198
1199 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
1200
1201 // Check for whether the forward history has been cropped due to a recent
1202 // navigation the browser didn't know about.
1203 if (params.pending_history_list_offset >= history_list_length_)
1204 return true;
1205
1206 // Check for whether this entry has been replaced with a new one.
1207 int expected_page_id =
1208 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:441209 if (expected_page_id > 0 && params.page_id != expected_page_id) {
1210 if (params.page_id < expected_page_id)
1211 return true;
1212
1213 // Otherwise we've removed an earlier entry and should have shifted all
1214 // entries left. For now, it's ok to lazily update the list.
1215 // TODO(creis): Notify all live renderers when we remove entries from
1216 // the front of the list, so that we don't hit this case.
1217 history_page_ids_[params.pending_history_list_offset] = params.page_id;
1218 }
[email protected]d466b8a2011-07-15 21:48:031219
1220 return false;
1221}
1222
[email protected]3d612f52014-01-13 23:48:291223// Stop loading the current page.
[email protected]310ebd6302011-10-10 19:06:281224void RenderViewImpl::OnStop() {
[email protected]3d612f52014-01-13 23:48:291225 if (webview())
1226 webview()->mainFrame()->stopLoading();
1227 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnStop());
[email protected]5815cf52014-01-29 17:45:051228 main_render_frame_->OnStop();
initial.commit09911bf2008-07-26 23:55:291229}
1230
[email protected]310ebd6302011-10-10 19:06:281231void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271232 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291233}
1234
[email protected]310ebd6302011-10-10 19:06:281235void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291236 // Check if there is a targeturl waiting to be sent.
1237 if (target_url_status_ == TARGET_PENDING) {
1238 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1239 pending_target_url_));
1240 }
1241
1242 target_url_status_ = TARGET_NONE;
1243}
1244
[email protected]c084330e02013-04-27 01:08:151245void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
1246 const std::string& value) {
1247 if (!webview() || !webview()->focusedFrame())
1248 return;
1249
1250 webview()->focusedFrame()->executeCommand(
1251 WebString::fromUTF8(name), WebString::fromUTF8(value));
1252}
1253
1254void RenderViewImpl::OnMoveCaret(const gfx::Point& point) {
1255 if (!webview())
1256 return;
1257
1258 Send(new ViewHostMsg_MoveCaret_ACK(routing_id_));
1259
[email protected]b74d4064d2013-11-27 01:45:091260 webview()->focusedFrame()->moveCaretSelection(point);
[email protected]c084330e02013-04-27 01:08:151261}
[email protected]a954bf72009-09-12 07:30:351262
[email protected]c084330e02013-04-27 01:08:151263void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1264 const gfx::Rect& rect) {
[email protected]1875bc02014-03-14 06:33:591265 if (has_scrolled_focused_editable_node_into_rect_ &&
1266 rect == rect_for_scrolled_focused_editable_node_) {
1267 return;
1268 }
1269
[email protected]c39f7442014-02-27 03:33:171270 blink::WebElement element = GetFocusedElement();
[email protected]1875bc02014-03-14 06:33:591271 if (!element.isNull() && IsEditableNode(element)) {
1272 rect_for_scrolled_focused_editable_node_ = rect;
1273 has_scrolled_focused_editable_node_into_rect_ = true;
1274 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]c084330e02013-04-27 01:08:151275 }
[email protected]25bcc8f2013-01-09 02:49:251276}
1277
[email protected]c084330e02013-04-27 01:08:151278void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
1279 const EditCommands& edit_commands) {
1280 edit_commands_ = edit_commands;
1281}
1282
[email protected]c084330e02013-04-27 01:08:151283void RenderViewImpl::OnSetName(const std::string& name) {
1284 if (!webview())
1285 return;
1286
1287 webview()->mainFrame()->setName(WebString::fromUTF8(name));
1288}
1289
[email protected]310ebd6302011-10-10 19:06:281290void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1291 int32 minimum_page_id) {
[email protected]e1ed5a12012-08-08 19:57:441292 DCHECK_GE(history_length, 0);
[email protected]9e1ad4b2011-08-14 16:49:191293 DCHECK(history_list_offset_ == history_list_length_ - 1);
[email protected]e1ed5a12012-08-08 19:57:441294 DCHECK_GE(minimum_page_id, -1);
[email protected]9e1ad4b2011-08-14 16:49:191295
1296 // Generate the new list.
1297 std::vector<int32> new_history_page_ids(history_length, -1);
1298 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1299 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1300 continue;
1301 new_history_page_ids.push_back(history_page_ids_[i]);
1302 }
1303 new_history_page_ids.swap(history_page_ids_);
1304
1305 // Update indexes.
1306 history_list_length_ = history_page_ids_.size();
1307 history_list_offset_ = history_list_length_ - 1;
1308}
1309
1310
[email protected]310ebd6302011-10-10 19:06:281311void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291312 if (!webview())
1313 return;
[email protected]26aa0482009-09-30 16:55:271314 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291315}
1316
[email protected]54ca3ca892011-06-07 21:14:541317#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281318void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331319 if (!webview())
1320 return;
1321 if (in_live_resize)
1322 webview()->willStartLiveResize();
1323 else
1324 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541325}
1326#endif
1327
[email protected]9b7d11e2012-10-08 19:24:141328#if defined(OS_ANDROID)
[email protected]68877c282013-09-20 05:52:421329void RenderViewImpl::OnPauseVideo() {
1330 // Inform RendererMediaPlayerManager to release all video player resources.
1331 // If something is in progress the resource will not be freed, it will
1332 // only be freed once the tab is destroyed or if the user navigates away
1333 // via WebMediaPlayerAndroid::Destroy.
1334 media_player_manager_->ReleaseVideoResources();
1335}
[email protected]9b7d11e2012-10-08 19:24:141336#endif
1337
initial.commit09911bf2008-07-26 23:55:291338///////////////////////////////////////////////////////////////////////////////
1339
initial.commit09911bf2008-07-26 23:55:291340// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281341void RenderViewImpl::UpdateTitle(WebFrame* frame,
[email protected]fcf75d42013-12-03 20:11:261342 const base::string16& title,
[email protected]310ebd6302011-10-10 19:06:281343 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461344 // Ignore all but top level navigations.
1345 if (frame->parent())
1346 return;
1347
[email protected]91a2aea2013-07-08 23:14:391348 base::debug::TraceLog::GetInstance()->UpdateProcessLabel(
[email protected]32956122013-12-25 07:29:241349 routing_id_, base::UTF16ToUTF8(title));
[email protected]91a2aea2013-07-08 23:14:391350
[email protected]fcf75d42013-12-03 20:11:261351 base::string16 shortened_title = title.substr(0, kMaxTitleChars);
[email protected]a49e10b2011-08-01 23:57:461352 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1353 title_direction));
initial.commit09911bf2008-07-26 23:55:291354}
1355
[email protected]310ebd6302011-10-10 19:06:281356void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1357 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291358 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271359 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291360 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301361 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291362 last_encoding_name_ = encoding_name;
1363
[email protected]e38f40152008-09-12 23:08:301364 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291365 }
1366}
1367
[email protected]e15f680732010-11-23 22:30:201368// Sends the last committed session history state to the browser so it will be
1369// saved before we navigate to a new page. This must be called *before* the
1370// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281371void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291372 // If we have a valid page ID at this point, then it corresponds to the page
1373 // we are navigating away from. Otherwise, this is the first navigation, so
1374 // there is no past session history to record.
1375 if (page_id_ == -1)
1376 return;
1377
[email protected]ca948a22009-06-25 19:36:171378 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271379 webview()->mainFrame()->previousHistoryItem();
[email protected]6459800a2012-03-27 23:57:051380 SendUpdateState(item);
1381}
1382
1383void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
[email protected]ca948a22009-06-25 19:36:171384 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291385 return;
[email protected]ca948a22009-06-25 19:36:171386
[email protected]e9ff79c2012-10-19 21:31:261387 // Don't send state updates for kSwappedOutURL.
1388 if (item.urlString() == WebString::fromUTF8(kSwappedOutURL))
[email protected]6459800a2012-03-27 23:57:051389 return;
1390
[email protected]ca948a22009-06-25 19:36:171391 Send(new ViewHostMsg_UpdateState(
[email protected]691aa2f2013-05-28 22:52:041392 routing_id_, page_id_, HistoryItemToPageState(item)));
initial.commit09911bf2008-07-26 23:55:291393}
1394
[email protected]79dbc662009-09-04 05:42:511395// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291396
[email protected]310ebd6302011-10-10 19:06:281397void RenderViewImpl::LoadNavigationErrorPage(
1398 WebFrame* frame,
1399 const WebURLRequest& failed_request,
1400 const WebURLError& error,
[email protected]310ebd6302011-10-10 19:06:281401 bool replace) {
[email protected]3d612f52014-01-13 23:48:291402 std::string error_html;
1403 GetContentClient()->renderer()->GetNavigationErrorStrings(
1404 this, frame, failed_request, error, &error_html, NULL);
[email protected]d7b175e2011-10-11 15:31:581405
[email protected]3d612f52014-01-13 23:48:291406 frame->loadHTMLString(error_html,
[email protected]e9ff79c2012-10-19 21:31:261407 GURL(kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251408 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551409 replace);
initial.commit09911bf2008-07-26 23:55:291410}
1411
[email protected]310ebd6302011-10-10 19:06:281412bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571413 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1414 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1415 // it is particularly important that we do not call willEnterModalLoop as
1416 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441417 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1418 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571419
1420 message->EnableMessagePumping(); // Runs a nested message loop.
1421 return Send(message);
1422}
1423
[email protected]c9bc8f12012-12-15 22:20:091424void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) {
1425 int id = next_snapshot_id_++;
1426 pending_snapshots_.insert(std::make_pair(id, callback));
[email protected]7d08a9352013-10-15 08:24:561427 ui::LatencyInfo latency_info;
1428 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
[email protected]8a784592014-01-21 23:01:241429 0,
[email protected]7d08a9352013-10-15 08:24:561430 id);
[email protected]6be422b2013-12-08 06:47:311431 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]7d08a9352013-10-15 08:24:561432 if (RenderWidgetCompositor* rwc = compositor()) {
[email protected]6be422b2013-12-08 06:47:311433 latency_info_swap_promise_monitor =
1434 rwc->CreateLatencyInfoSwapPromiseMonitor(&latency_info).Pass();
[email protected]7d08a9352013-10-15 08:24:561435 } else {
[email protected]98a04472013-12-23 20:42:501436 latency_info_.push_back(latency_info);
[email protected]7d08a9352013-10-15 08:24:561437 }
1438 ScheduleCompositeWithForcedRedraw();
[email protected]c9bc8f12012-12-15 22:20:091439}
1440
1441void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id,
1442 const gfx::Size& size, const std::vector<unsigned char>& png) {
[email protected]7d08a9352013-10-15 08:24:561443
1444 // Any pending snapshots with a lower ID than the one received are considered
1445 // to be implicitly complete, and returned the same snapshot data.
1446 PendingSnapshotMap::iterator it = pending_snapshots_.begin();
1447 while(it != pending_snapshots_.end()) {
1448 if (it->first <= snapshot_id) {
1449 it->second.Run(size, png);
1450 pending_snapshots_.erase(it++);
1451 } else {
1452 ++it;
1453 }
1454 }
[email protected]c9bc8f12012-12-15 22:20:091455}
1456
[email protected]180ef242013-11-07 06:50:461457// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:521458
[email protected]35b2a972014-04-04 15:50:221459WebView* RenderViewImpl::createView(WebLocalFrame* creator,
1460 const WebURLRequest& request,
1461 const WebWindowFeatures& features,
1462 const WebString& frame_name,
1463 WebNavigationPolicy policy,
1464 bool suppress_opener) {
[email protected]8ab04652010-06-12 02:47:261465 ViewHostMsg_CreateWindow_Params params;
1466 params.opener_id = routing_id_;
[email protected]af15bf22013-03-08 01:18:171467 params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]00323f02013-07-24 15:47:411468 if (GetContentClient()->renderer()->AllowPopup())
1469 params.user_gesture = true;
[email protected]8ab04652010-06-12 02:47:261470 params.window_container_type = WindowFeaturesToContainerType(features);
1471 params.session_storage_namespace_id = session_storage_namespace_id_;
[email protected]5cef23d2013-02-27 13:11:211472 if (frame_name != "_blank")
1473 params.frame_name = frame_name;
[email protected]a7531d772014-03-25 16:15:071474 params.opener_render_frame_id =
[email protected]501052ff2014-02-21 22:19:071475 RenderFrameImpl::FromWebFrame(creator)->GetRoutingID();
[email protected]b6cb3a842011-06-24 18:28:411476 params.opener_url = creator->document().url();
[email protected]931bc922013-09-11 21:42:571477 params.opener_top_level_frame_url = creator->top()->document().url();
[email protected]6c53a7f2014-03-31 16:56:281478 GURL security_url(creator->document().securityOrigin().toString());
[email protected]7f48b712013-01-25 01:48:301479 if (!security_url.is_valid())
1480 security_url = GURL();
1481 params.opener_security_origin = security_url;
[email protected]147b2bf2013-11-05 04:00:041482 params.opener_suppressed = suppress_opener;
[email protected]f92ce2b2012-03-06 18:02:591483 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]44e55b012013-07-23 14:21:561484 if (!request.isNull()) {
[email protected]41e65502011-01-21 09:29:111485 params.target_url = request.url();
[email protected]44e55b012013-07-23 14:21:561486 params.referrer = GetReferrerFromRequest(creator, request);
1487 }
[email protected]453c1b22013-07-23 09:31:481488 params.features = features;
[email protected]8ab04652010-06-12 02:47:261489
[email protected]22217ed32013-11-18 18:40:231490 for (size_t i = 0; i < features.additionalFeatures.size(); ++i)
1491 params.additional_features.push_back(features.additionalFeatures[i]);
1492
[email protected]48c9cf2d2009-09-16 16:47:521493 int32 routing_id = MSG_ROUTING_NONE;
[email protected]227692c52013-05-31 22:43:041494 int32 main_frame_routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561495 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341496 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521497
[email protected]380244092011-10-07 17:26:271498 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261499 new ViewHostMsg_CreateWindow(params,
1500 &routing_id,
[email protected]227692c52013-05-31 22:43:041501 &main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:561502 &surface_id,
[email protected]8ab04652010-06-12 02:47:261503 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211504 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521505 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521506
[email protected]af15bf22013-03-08 01:18:171507 WebUserGestureIndicator::consumeUserGesture();
[email protected]c59262422012-11-30 21:20:521508
[email protected]3184f90b2013-05-01 18:17:531509 WebPreferences transferred_preferences = webkit_preferences_;
[email protected]9115d5f2013-03-24 04:37:411510
1511 // Unless accelerated compositing has been explicitly disabled from the
1512 // command line (e.g. via the blacklist or about:flags) re-enable it for
1513 // new views that get spawned by this view. This gets around the issue that
1514 // background extension pages disable accelerated compositing via web prefs
1515 // but can themselves spawn a visible render view which should be allowed
1516 // use gpu acceleration.
1517 if (!webkit_preferences_.accelerated_compositing_enabled) {
1518 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1519 if (!command_line.HasSwitch(switches::kDisableAcceleratedCompositing))
1520 transferred_preferences.accelerated_compositing_enabled = true;
1521 }
1522
[email protected]d6fa88f2013-10-18 16:00:431523 // The initial hidden state for the RenderViewImpl here has to match what the
1524 // browser will eventually decide for the given disposition. Since we have to
1525 // return from this call synchronously, we just have to make our best guess
1526 // and rely on the browser sending a WasHidden / WasShown message if it
1527 // disagrees.
[email protected]310ebd6302011-10-10 19:06:281528 RenderViewImpl* view = RenderViewImpl::Create(
[email protected]310ebd6302011-10-10 19:06:281529 routing_id_,
1530 renderer_preferences_,
[email protected]9115d5f2013-03-24 04:37:411531 transferred_preferences,
[email protected]310ebd6302011-10-10 19:06:281532 routing_id,
[email protected]227692c52013-05-31 22:43:041533 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:561534 surface_id,
[email protected]310ebd6302011-10-10 19:06:281535 cloned_session_storage_namespace_id,
[email protected]fcf75d42013-12-03 20:11:261536 base::string16(), // WebCore will take care of setting the correct name.
[email protected]f2c530d2014-02-20 20:15:301537 true, // is_renderer_created
1538 false, // swapped_out
1539 params.disposition == NEW_BACKGROUND_TAB, // hidden
1540 1, // next_page_id
[email protected]842f10652012-06-06 01:54:041541 screen_info_,
[email protected]f2c530d2014-02-20 20:15:301542 accessibility_mode_);
[email protected]8ab04652010-06-12 02:47:261543 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521544
[email protected]007a848b2009-10-26 15:55:461545 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:591546 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:461547
[email protected]48c9cf2d2009-09-16 16:47:521548 return view->webview();
1549}
1550
[email protected]180ef242013-11-07 06:50:461551WebWidget* RenderViewImpl::createPopupMenu(blink::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:411552 RenderWidget* widget =
[email protected]842f10652012-06-06 01:54:041553 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]3b78ec12014-03-04 05:18:281554 if (!widget)
1555 return NULL;
[email protected]b2e4c70132013-10-03 02:07:511556 if (screen_metrics_emulator_) {
1557 widget->SetPopupOriginAdjustmentsForEmulation(
1558 screen_metrics_emulator_.get());
1559 }
[email protected]48c9cf2d2009-09-16 16:47:521560 return widget->webwidget();
1561}
1562
[email protected]310ebd6302011-10-10 19:06:281563WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081564 const WebPopupMenuInfo& popup_menu_info,
1565 WebExternalPopupMenuClient* popup_menu_client) {
[email protected]53907862014-03-25 15:42:401566#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]8de2f882012-05-30 00:32:271567 // An IPC message is sent to the browser to build and display the actual
1568 // popup. The user could have time to click a different select by the time
1569 // the popup is shown. In that case external_popup_menu_ is non NULL.
1570 // By returning NULL in that case, we instruct WebKit to cancel that new
1571 // popup. So from the user perspective, only the first one will show, and
1572 // will have to close the first one before another one can be shown.
[email protected]59383c782013-04-17 16:43:271573 if (external_popup_menu_)
[email protected]8de2f882012-05-30 00:32:271574 return NULL;
[email protected]caf706f2010-10-26 17:54:081575 external_popup_menu_.reset(
1576 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
[email protected]b2e4c70132013-10-03 02:07:511577 if (screen_metrics_emulator_) {
1578 SetExternalPopupOriginAdjustmentsForEmulation(
1579 external_popup_menu_.get(), screen_metrics_emulator_.get());
1580 }
[email protected]caf706f2010-10-26 17:54:081581 return external_popup_menu_.get();
[email protected]53907862014-03-25 15:42:401582#else
1583 return NULL;
1584#endif
[email protected]caf706f2010-10-26 17:54:081585}
1586
[email protected]23367482013-06-27 21:06:541587WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() {
[email protected]5f2aa722013-08-07 16:59:411588 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:101589 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341590}
1591
[email protected]35b2a972014-04-04 15:50:221592void RenderViewImpl::printPage(WebLocalFrame* frame) {
[email protected]b0553c7e2012-09-19 21:36:111593 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
1594 PrintPage(frame, handling_input_event_));
[email protected]48c9cf2d2009-09-16 16:47:521595}
1596
[email protected]180ef242013-11-07 06:50:461597blink::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511598 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021599}
1600
[email protected]310ebd6302011-10-10 19:06:281601bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121602 const WebString& path,
1603 WebFileChooserCompletion* chooser_completion) {
1604 int id = enumeration_completion_id_++;
1605 enumeration_completions_[id] = chooser_completion;
1606 return Send(new ViewHostMsg_EnumerateDirectory(
1607 routing_id_,
1608 id,
[email protected]728c2ee2013-06-25 04:01:071609 base::FilePath::FromUTF16Unsafe(path)));
[email protected]8a58c1c2011-04-19 18:40:121610}
1611
[email protected]7e9523b2014-03-25 03:02:421612void RenderViewImpl::FrameDidStartLoading(WebFrame* frame) {
[email protected]6dd5c322014-03-12 07:58:461613 if (load_progress_tracker_ != NULL) {
1614 load_progress_tracker_->DidStartLoading(
1615 RenderFrameImpl::FromWebFrame(frame)->GetRoutingID());
1616 }
[email protected]7e9523b2014-03-25 03:02:421617 DCHECK_GE(frames_in_progress_, 0);
1618 if (frames_in_progress_ == 0)
1619 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
1620 frames_in_progress_++;
[email protected]6dd5c322014-03-12 07:58:461621}
1622
[email protected]7e9523b2014-03-25 03:02:421623void RenderViewImpl::FrameDidStopLoading(WebFrame* frame) {
[email protected]6dd5c322014-03-12 07:58:461624 if (load_progress_tracker_ != NULL) {
1625 load_progress_tracker_->DidStopLoading(
1626 RenderFrameImpl::FromWebFrame(frame)->GetRoutingID());
1627 }
[email protected]7e9523b2014-03-25 03:02:421628 frames_in_progress_--;
1629 DCHECK_GE(frames_in_progress_, 0);
1630 if (frames_in_progress_ == 0) {
1631 DidStopLoadingIcons();
1632 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
1633 }
[email protected]48c9cf2d2009-09-16 16:47:521634}
1635
[email protected]7e9523b2014-03-25 03:02:421636void RenderViewImpl::FrameDidChangeLoadProgress(WebFrame* frame,
1637 double load_progress) {
[email protected]6dd5c322014-03-12 07:58:461638 if (load_progress_tracker_ != NULL) {
1639 load_progress_tracker_->DidChangeLoadProgress(
1640 RenderFrameImpl::FromWebFrame(frame)->GetRoutingID(), load_progress);
1641 }
[email protected]90109412010-12-15 17:14:241642}
1643
[email protected]550b0c92013-02-04 05:09:151644void RenderViewImpl::didCancelCompositionOnSelectionChange() {
1645 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
1646}
1647
[email protected]310ebd6302011-10-10 19:06:281648void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]32956122013-12-25 07:29:241649 const std::string& name = base::UTF16ToUTF8(command_name);
[email protected]afe3a1672009-11-17 19:04:121650 if (StartsWithASCII(name, "Move", true) ||
1651 StartsWithASCII(name, "Insert", true) ||
1652 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031653 return;
[email protected]97880c82013-12-04 07:09:211654 RenderThreadImpl::current()->RecordComputedAction(name);
[email protected]04fc9482009-09-18 22:13:031655}
1656
[email protected]310ebd6302011-10-10 19:06:281657bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101658 if (edit_commands_.empty())
1659 return false;
1660
[email protected]26aa0482009-09-30 16:55:271661 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101662 if (!frame)
1663 return false;
1664
1665 EditCommands::iterator it = edit_commands_.begin();
1666 EditCommands::iterator end = edit_commands_.end();
1667
[email protected]507b33ea2009-09-29 03:56:511668 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101669 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331670 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1671 // key (but it's the exception). Once one edit command is not executed, it
1672 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101673 if (!frame->executeCommand(WebString::fromUTF8(it->name),
[email protected]b77fac52013-06-01 01:03:461674 WebString::fromUTF8(it->value),
[email protected]c39f7442014-02-27 03:33:171675 GetFocusedElement()))
[email protected]b2528b72009-09-24 06:57:101676 break;
[email protected]507b33ea2009-09-29 03:56:511677 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101678 }
1679
[email protected]507b33ea2009-09-29 03:56:511680 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101681}
1682
[email protected]180ef242013-11-07 06:50:461683blink::WebColorChooser* RenderViewImpl::createColorChooser(
1684 blink::WebColorChooserClient* client,
[email protected]8bc5ff02013-11-29 06:34:031685 const blink::WebColor& initial_color,
1686 const blink::WebVector<blink::WebColorSuggestion>& suggestions) {
[email protected]da8543762012-03-20 08:52:201687 RendererWebColorChooserImpl* color_chooser =
1688 new RendererWebColorChooserImpl(this, client);
[email protected]8bc5ff02013-11-29 06:34:031689 std::vector<content::ColorSuggestion> color_suggestions;
1690 for (size_t i = 0; i < suggestions.size(); i++) {
1691 color_suggestions.push_back(content::ColorSuggestion(suggestions[i]));
1692 }
1693 color_chooser->Open(static_cast<SkColor>(initial_color), color_suggestions);
[email protected]da8543762012-03-20 08:52:201694 return color_chooser;
1695}
1696
[email protected]310ebd6302011-10-10 19:06:281697bool RenderViewImpl::runFileChooser(
[email protected]180ef242013-11-07 06:50:461698 const blink::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471699 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351700 // Do not open the file dialog in a hidden RenderView.
1701 if (is_hidden())
1702 return false;
[email protected]e9ff79c2012-10-19 21:31:261703 FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261704 if (params.directory)
[email protected]6bedbef2013-07-31 06:33:491705 ipc_params.mode = FileChooserParams::UploadFolder;
[email protected]b5977a0c2010-08-24 19:46:261706 else if (params.multiSelect)
[email protected]e9ff79c2012-10-19 21:31:261707 ipc_params.mode = FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501708 else if (params.saveAs)
[email protected]e9ff79c2012-10-19 21:31:261709 ipc_params.mode = FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261710 else
[email protected]e9ff79c2012-10-19 21:31:261711 ipc_params.mode = FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471712 ipc_params.title = params.title;
1713 ipc_params.default_file_name =
[email protected]728c2ee2013-06-25 04:01:071714 base::FilePath::FromUTF16Unsafe(params.initialValue);
[email protected]f9a4c41a2012-05-30 00:05:321715 ipc_params.accept_types.reserve(params.acceptTypes.size());
1716 for (size_t i = 0; i < params.acceptTypes.size(); ++i)
1717 ipc_params.accept_types.push_back(params.acceptTypes[i]);
[email protected]2fdf2352012-11-01 19:23:021718#if defined(OS_ANDROID)
[email protected]b7b4beb2013-07-09 14:06:501719 ipc_params.capture = params.useMediaCapture;
[email protected]2fdf2352012-11-01 19:23:021720#endif
[email protected]cdaf8d02010-03-30 19:52:471721
1722 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461723}
1724
[email protected]edc3af82013-12-12 21:24:071725void RenderViewImpl::showValidationMessage(
1726 const blink::WebRect& anchor_in_root_view,
1727 const blink::WebString& main_text,
1728 const blink::WebString& sub_text,
1729 blink::WebTextDirection hint) {
1730 base::string16 wrapped_main_text = main_text;
1731 base::string16 wrapped_sub_text = sub_text;
1732 if (hint == blink::WebTextDirectionLeftToRight) {
1733 wrapped_main_text =
1734 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_main_text);
1735 if (!wrapped_sub_text.empty()) {
1736 wrapped_sub_text =
1737 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_sub_text);
1738 }
1739 } else if (hint == blink::WebTextDirectionRightToLeft
1740 && !base::i18n::IsRTL()) {
1741 base::i18n::WrapStringWithRTLFormatting(&wrapped_main_text);
1742 if (!wrapped_sub_text.empty()) {
1743 base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text);
1744 }
1745 }
1746 Send(new ViewHostMsg_ShowValidationMessage(
1747 routing_id(), anchor_in_root_view, wrapped_main_text, wrapped_sub_text));
1748}
1749
1750void RenderViewImpl::hideValidationMessage() {
1751 Send(new ViewHostMsg_HideValidationMessage(routing_id()));
1752}
1753
1754void RenderViewImpl::moveValidationMessage(
1755 const blink::WebRect& anchor_in_root_view) {
1756 Send(new ViewHostMsg_MoveValidationMessage(routing_id(),
1757 anchor_in_root_view));
1758}
1759
[email protected]310ebd6302011-10-10 19:06:281760void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521761}
1762
[email protected]310ebd6302011-10-10 19:06:281763void RenderViewImpl::UpdateTargetURL(const GURL& url,
1764 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581765 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521766 if (latest_url == target_url_)
1767 return;
[email protected]163f8242009-10-30 20:19:551768
[email protected]48c9cf2d2009-09-16 16:47:521769 // Tell the browser to display a destination link.
1770 if (target_url_status_ == TARGET_INFLIGHT ||
1771 target_url_status_ == TARGET_PENDING) {
1772 // If we have a request in-flight, save the URL to be sent when we
1773 // receive an ACK to the in-flight request. We can happily overwrite
1774 // any existing pending sends.
1775 pending_target_url_ = latest_url;
1776 target_url_status_ = TARGET_PENDING;
1777 } else {
[email protected]f16cc6782013-12-16 23:42:571778 // URLs larger than |MaxURLChars()| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:411779 // see |ParamTraits<GURL>|.
[email protected]f16cc6782013-12-16 23:42:571780 if (latest_url.possibly_invalid_spec().size() > GetMaxURLChars())
[email protected]c85f0212011-11-04 16:54:411781 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:521782 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1783 target_url_ = latest_url;
1784 target_url_status_ = TARGET_INFLIGHT;
1785 }
1786}
1787
[email protected]70221f02013-01-31 22:17:071788gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect(
1789 const gfx::RectF& rect) const {
1790 gfx::RectF window_rect = rect;
1791 window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor());
1792 return window_rect;
1793}
1794
[email protected]310ebd6302011-10-10 19:06:281795void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]a183fb82012-12-14 04:46:221796 // No need to update state if no page has committed yet.
1797 if (page_id_ == -1)
1798 return;
1799
[email protected]882daa92009-11-05 16:31:311800 int delay;
1801 if (send_content_state_immediately_)
1802 delay = 0;
1803 else if (is_hidden())
1804 delay = kDelaySecondsForContentStateSyncHidden;
1805 else
1806 delay = kDelaySecondsForContentStateSync;
1807
1808 if (nav_state_sync_timer_.IsRunning()) {
1809 // The timer is already running. If the delay of the timer maches the amount
1810 // we want to delay by, then return. Otherwise stop the timer so that it
1811 // gets started with the right delay.
1812 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1813 return;
1814 nav_state_sync_timer_.Stop();
1815 }
1816
[email protected]d323a172011-09-02 18:23:021817 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:281818 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311819}
1820
[email protected]310ebd6302011-10-10 19:06:281821void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551822 mouse_over_url_ = GURL(url);
1823 UpdateTargetURL(mouse_over_url_, focus_url_);
1824}
1825
[email protected]310ebd6302011-10-10 19:06:281826void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551827 focus_url_ = GURL(url);
1828 UpdateTargetURL(focus_url_, mouse_over_url_);
1829}
1830
[email protected]35b2a972014-04-04 15:50:221831void RenderViewImpl::startDragging(WebLocalFrame* frame,
[email protected]0407e422012-05-18 19:51:251832 const WebDragData& data,
[email protected]310ebd6302011-10-10 19:06:281833 WebDragOperationsMask mask,
1834 const WebImage& image,
[email protected]ceb36f7d2012-10-31 18:33:241835 const WebPoint& webImageOffset) {
[email protected]dc293a72013-07-01 11:11:221836 DropData drop_data(DropDataBuilder::Build(data));
[email protected]b67151d2012-05-25 23:23:241837 drop_data.referrer_policy = frame->document().referrerPolicy();
[email protected]ceb36f7d2012-10-31 18:33:241838 gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y);
[email protected]59f4f2fa2011-03-23 01:00:551839 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]b67151d2012-05-25 23:23:241840 drop_data,
[email protected]c27ae592010-03-18 15:24:411841 mask,
[email protected]976127072012-05-10 20:08:111842 image.getSkBitmap(),
[email protected]41d86852012-11-07 12:23:241843 imageOffset,
1844 possible_drag_event_info_));
[email protected]48c9cf2d2009-09-16 16:47:521845}
1846
[email protected]310ebd6302011-10-10 19:06:281847bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451848 return renderer_preferences_.can_accept_load_drops;
1849}
1850
[email protected]310ebd6302011-10-10 19:06:281851void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:521852 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1853}
1854
[email protected]310ebd6302011-10-10 19:06:281855void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:521856 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1857}
1858
[email protected]310ebd6302011-10-10 19:06:281859void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]1875bc02014-03-14 06:33:591860 has_scrolled_focused_editable_node_into_rect_ = false;
1861
[email protected]9b66f34bf2010-10-27 20:45:511862 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071863
[email protected]38b592902011-04-16 02:08:421864 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491865}
1866
[email protected]572a6ca2012-10-11 19:38:011867void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
1868 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
1869}
1870
[email protected]169d4282011-11-30 19:33:591871void RenderViewImpl::didUpdateLayout() {
[email protected]d01b2a62013-09-18 23:21:331872 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidUpdateLayout());
1873
[email protected]169d4282011-11-30 19:33:591874 // We don't always want to set up a timer, only if we've been put in that
1875 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1876 // message.
1877 if (!send_preferred_size_changes_ || !webview())
1878 return;
1879
1880 if (check_preferred_size_timer_.IsRunning())
1881 return;
1882 check_preferred_size_timer_.Start(FROM_HERE,
1883 TimeDelta::FromMilliseconds(0), this,
1884 &RenderViewImpl::CheckPreferredSize);
1885}
1886
[email protected]310ebd6302011-10-10 19:06:281887void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521888 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1889}
1890
[email protected]310ebd6302011-10-10 19:06:281891int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001892 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521893}
1894
[email protected]310ebd6302011-10-10 19:06:281895int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001896 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521897}
1898
[email protected]10760e4a2013-09-04 23:32:201899void RenderViewImpl::postAccessibilityEvent(
[email protected]180ef242013-11-07 06:50:461900 const WebAXObject& obj, blink::WebAXEvent event) {
[email protected]2a84f9d2012-06-05 21:50:431901 if (renderer_accessibility_) {
[email protected]10760e4a2013-09-04 23:32:201902 renderer_accessibility_->HandleWebAccessibilityEvent(obj, event);
[email protected]2a84f9d2012-06-05 21:50:431903 }
[email protected]063afcb2011-09-29 07:54:321904}
1905
[email protected]310ebd6302011-10-10 19:06:281906void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:141907 const WebString& value) {
1908 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1909 key.utf8(),
1910 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261911}
1912
[email protected]180ef242013-11-07 06:50:461913// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:511914
[email protected]310ebd6302011-10-10 19:06:281915void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:121916 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1917 // we won't have to test for user gesture anymore and we can
1918 // move that code back to render_widget.cc
[email protected]af15bf22013-03-08 01:18:171919 if (WebUserGestureIndicator::isProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:301920 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]e1176152013-03-06 09:16:441921 Send(new ViewHostMsg_Focus(routing_id_));
[email protected]ea42e7782010-08-23 23:58:121922 }
1923}
1924
[email protected]310ebd6302011-10-10 19:06:281925void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:121926 // TODO(jcivelli): see TODO above in didFocus().
[email protected]af15bf22013-03-08 01:18:171927 if (WebUserGestureIndicator::isProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:301928 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]e1176152013-03-06 09:16:441929 Send(new ViewHostMsg_Blur(routing_id_));
[email protected]ea42e7782010-08-23 23:58:121930 }
1931}
1932
initial.commit09911bf2008-07-26 23:55:291933// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:281934// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:291935// point to dispatch the ShowView message.
1936//
1937// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281938// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291939//
[email protected]310ebd6302011-10-10 19:06:281940void RenderViewImpl::show(WebNavigationPolicy policy) {
[email protected]b2142e962012-10-30 13:59:251941 if (did_show_) {
[email protected]b2142e962012-10-30 13:59:251942 // When supports_multiple_windows is disabled, popups are reusing
1943 // the same view. In some scenarios, this makes WebKit to call show() twice.
[email protected]c9edabd2013-05-23 13:56:241944 if (webkit_preferences_.supports_multiple_windows)
1945 NOTREACHED() << "received extraneous Show call";
initial.commit09911bf2008-07-26 23:55:291946 return;
[email protected]b2142e962012-10-30 13:59:251947 }
initial.commit09911bf2008-07-26 23:55:291948 did_show_ = true;
1949
[email protected]b2142e962012-10-30 13:59:251950 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1951
[email protected]28295ec2009-10-16 05:34:331952 // Force new windows to a popup if they were not opened with a user gesture.
1953 if (!opened_by_user_gesture_) {
1954 // We exempt background tabs for compat with older versions of Chrome.
1955 // TODO(darin): This seems bogus. These should have a user gesture, so
1956 // we probably don't need this check.
[email protected]180ef242013-11-07 06:50:461957 if (policy != blink::WebNavigationPolicyNewBackgroundTab)
1958 policy = blink::WebNavigationPolicyNewPopup;
[email protected]28295ec2009-10-16 05:34:331959 }
1960
initial.commit09911bf2008-07-26 23:55:291961 // NOTE: initial_pos_ may still have its default values at this point, but
1962 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1963 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281964 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1965 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291966 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241967 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291968}
1969
[email protected]dd48d492014-03-16 05:04:391970void RenderViewImpl::runModal() {
1971 DCHECK(did_show_) << "should already have shown the view";
1972
1973 // Don't allow further dialogs if we are waiting to swap out, since the
1974 // PageGroupLoadDeferrer in our stack prevents it.
1975 if (suppress_dialogs_until_swap_out_)
1976 return;
1977
1978 // We must keep WebKit's shared timer running in this case in order to allow
1979 // showModalDialog to function properly.
1980 //
1981 // TODO(darin): WebKit should really be smarter about suppressing events and
1982 // timers so that we do not need to manage the shared timer in such a heavy
1983 // handed manner.
1984 //
1985 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1986 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
1987
1988 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
1989 routing_id_, opener_id_));
1990}
1991
[email protected]2b624c562011-10-27 22:58:261992bool RenderViewImpl::enterFullScreen() {
1993 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
1994 return true;
1995}
1996
1997void RenderViewImpl::exitFullScreen() {
1998 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
1999}
2000
[email protected]217690d2012-01-27 07:33:112001bool RenderViewImpl::requestPointerLock() {
2002 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2003}
2004
2005void RenderViewImpl::requestPointerUnlock() {
2006 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2007}
2008
2009bool RenderViewImpl::isPointerLocked() {
2010 return mouse_lock_dispatcher_->IsMouseLockedTo(
2011 webwidget_mouse_lock_target_.get());
2012}
2013
[email protected]c0b0bd12014-03-13 00:39:582014// FIXME: To be removed as soon as chromium and blink side changes land
2015// didActivateCompositor with parameters is still kept in order to land
2016// these changes s-chromium - https://codereview.chromium.org/137893025/.
2017// s-blink - https://codereview.chromium.org/138523003/
[email protected]7a1ec28a2012-03-28 21:10:242018void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
[email protected]0cd50aa2013-02-12 22:28:012019#if !defined(OS_MACOSX) // many events are unhandled - http://crbug.com/138003
[email protected]ea5f70a2013-03-07 12:30:362020 InputHandlerManager* input_handler_manager =
2021 RenderThreadImpl::current()->input_handler_manager();
[email protected]200a9c062013-05-20 04:34:372022 if (input_handler_manager) {
2023 input_handler_manager->AddInputHandler(
2024 routing_id_,
2025 compositor_->GetInputHandler(),
2026 AsWeakPtr());
2027 }
[email protected]70cff27502013-01-17 09:16:492028#endif
[email protected]7a1ec28a2012-03-28 21:10:242029
2030 RenderWidget::didActivateCompositor(input_handler_identifier);
2031}
2032
[email protected]c0b0bd12014-03-13 00:39:582033void RenderViewImpl::didActivateCompositor() {
2034#if !defined(OS_MACOSX) // many events are unhandled - http://crbug.com/138003
2035 InputHandlerManager* input_handler_manager =
2036 RenderThreadImpl::current()->input_handler_manager();
2037 if (input_handler_manager) {
2038 input_handler_manager->AddInputHandler(
2039 routing_id_,
2040 compositor_->GetInputHandler(),
2041 AsWeakPtr());
2042 }
2043#endif
2044
2045 RenderWidget::didActivateCompositor();
2046}
2047
[email protected]c68c3e4e2013-01-24 00:36:562048void RenderViewImpl::didHandleGestureEvent(
2049 const WebGestureEvent& event,
2050 bool event_cancelled) {
2051 RenderWidget::didHandleGestureEvent(event, event_cancelled);
[email protected]bb37b652013-11-27 23:47:112052
2053 if (event.type != blink::WebGestureEvent::GestureTap)
2054 return;
2055
2056 blink::WebTextInputType text_input_type =
2057 GetWebView()->textInputInfo().type;
2058
2059 Send(new ViewHostMsg_FocusedNodeTouched(
2060 routing_id(), text_input_type != blink::WebTextInputTypeNone));
[email protected]c68c3e4e2013-01-24 00:36:562061}
2062
[email protected]6e89eb72013-07-23 13:28:222063void RenderViewImpl::initializeLayerTreeView() {
2064 RenderWidget::initializeLayerTreeView();
2065 RenderWidgetCompositor* rwc = compositor();
2066 if (!rwc || !webview() || !webview()->devToolsAgent())
2067 return;
2068 webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId());
2069}
2070
[email protected]180ef242013-11-07 06:50:462071// blink::WebFrameClient -----------------------------------------------------
[email protected]3d9689372009-09-10 04:29:172072
[email protected]b849847b2013-12-10 21:57:582073blink::WebMediaPlayer* RenderViewImpl::CreateMediaPlayer(
2074 RenderFrame* render_frame,
[email protected]35b2a972014-04-04 15:50:222075 blink::WebLocalFrame* frame,
[email protected]b849847b2013-12-10 21:57:582076 const blink::WebURL& url,
2077 blink::WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442078 FOR_EACH_OBSERVER(
2079 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172080
[email protected]40bed812013-11-05 06:59:152081 WebMediaPlayer* player = CreateWebMediaPlayerForMediaStream(frame, url,
2082 client);
2083 if (player)
2084 return player;
[email protected]d05e2162012-11-16 22:21:462085
[email protected]25fb9b32012-04-27 03:21:552086#if defined(OS_ANDROID)
[email protected]40bed812013-11-05 06:59:152087 return CreateAndroidWebMediaPlayer(frame, url, client);
2088#else
[email protected]5e35a8d2013-07-10 19:37:212089 WebMediaPlayerParams params(
[email protected]d726eddc2013-07-02 22:25:552090 base::Bind(&ContentRendererClient::DeferMediaLoad,
2091 base::Unretained(GetContentClient()->renderer()),
[email protected]b849847b2013-12-10 21:57:582092 static_cast<RenderFrame*>(render_frame)),
[email protected]c6a04ba2014-03-07 11:47:042093 RenderThreadImpl::current()->GetAudioRendererMixerManager()->CreateInput(
2094 routing_id_, render_frame->GetRoutingID()));
[email protected]1dd0bb752014-02-01 01:16:262095 return new WebMediaPlayerImpl(frame, client, AsWeakPtr(), params);
[email protected]40bed812013-11-05 06:59:152096#endif // defined(OS_ANDROID)
[email protected]3d9689372009-09-10 04:29:172097}
2098
[email protected]35b2a972014-04-04 15:50:222099void RenderViewImpl::didAccessInitialDocument(WebLocalFrame* frame) {
[email protected]59167c22013-06-03 18:07:322100 // Notify the browser process that it is no longer safe to show the pending
2101 // URL of the main frame, since a URL spoof is now possible.
2102 if (!frame->parent() && page_id_ == -1)
2103 Send(new ViewHostMsg_DidAccessInitialDocument(routing_id_));
2104}
2105
[email protected]35b2a972014-04-04 15:50:222106void RenderViewImpl::didDisownOpener(blink::WebLocalFrame* frame) {
[email protected]29ece2e2013-04-03 04:53:522107 // We only need to notify the browser if the active, top-level frame clears
2108 // its opener. We can ignore cases where a swapped out frame clears its
2109 // opener after hearing about it from the browser, and the browser does not
2110 // (yet) care about subframe openers.
2111 if (is_swapped_out_ || frame->parent())
[email protected]7cc78902012-12-06 02:32:262112 return;
2113
2114 // Notify WebContents and all its swapped out RenderViews.
2115 Send(new ViewHostMsg_DidDisownOpener(routing_id_));
2116}
2117
[email protected]310ebd6302011-10-10 19:06:282118void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]5f96f5a62014-01-10 00:05:112119 // NOTE: We may get here for either the main frame or for subframes. The
2120 // RenderFrameImpl will be deleted immediately after this call for subframes
2121 // but not for the main frame, which is owned by |main_render_frame_|.
2122
[email protected]676126f72011-01-15 00:03:512123 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452124}
2125
[email protected]310ebd6302011-10-10 19:06:282126void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512127 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172128}
2129
[email protected]f5b6dd1122013-10-04 02:42:502130void RenderViewImpl::didMatchCSS(
[email protected]35b2a972014-04-04 15:50:222131 WebLocalFrame* frame,
[email protected]f5b6dd1122013-10-04 02:42:502132 const WebVector<WebString>& newly_matching_selectors,
2133 const WebVector<WebString>& stopped_matching_selectors) {
2134 FOR_EACH_OBSERVER(
2135 RenderViewObserver, observers_,
2136 DidMatchCSS(frame, newly_matching_selectors, stopped_matching_selectors));
2137}
2138
[email protected]5e92282f2012-08-17 08:11:572139void RenderViewImpl::Repaint(const gfx::Size& size) {
[email protected]3d9ec5052013-01-02 22:05:252140 OnRepaint(size);
[email protected]5e92282f2012-08-17 08:11:572141}
2142
[email protected]b2324b092012-11-01 10:34:112143void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
2144 const std::string& value) {
2145 EditCommands edit_commands;
2146 edit_commands.push_back(EditCommand(name, value));
2147 OnSetEditCommandsForNextKeyEvent(edit_commands);
2148}
2149
2150void RenderViewImpl::ClearEditCommands() {
2151 edit_commands_.clear();
2152}
2153
[email protected]180ef242013-11-07 06:50:462154SSLStatus RenderViewImpl::GetSSLStatusOfFrame(blink::WebFrame* frame) const {
[email protected]83c0abca2013-07-23 20:09:422155 std::string security_info;
2156 if (frame && frame->dataSource())
2157 security_info = frame->dataSource()->response().securityInfo();
2158
2159 SSLStatus ssl_status;
2160 DeserializeSecurityInfo(security_info,
2161 &ssl_status.cert_id,
2162 &ssl_status.cert_status,
2163 &ssl_status.security_bits,
[email protected]0bbd63b2013-11-29 00:02:122164 &ssl_status.connection_status,
2165 &ssl_status.signed_certificate_timestamp_ids);
[email protected]83c0abca2013-07-23 20:09:422166 return ssl_status;
[email protected]e4495212012-12-06 03:09:122167}
2168
[email protected]b38806a2013-10-04 16:01:382169const std::string& RenderViewImpl::GetAcceptLanguages() const {
2170 return renderer_preferences_.accept_languages;
2171}
2172
[email protected]35b2a972014-04-04 15:50:222173void RenderViewImpl::willSendSubmitEvent(blink::WebLocalFrame* frame,
2174 const blink::WebFormElement& form) {
[email protected]0660a8c2013-08-16 01:09:122175 FOR_EACH_OBSERVER(
2176 RenderViewObserver, observers_, WillSendSubmitEvent(frame, form));
[email protected]90eeddb2010-05-06 21:06:432177}
2178
[email protected]35b2a972014-04-04 15:50:222179void RenderViewImpl::willSubmitForm(WebLocalFrame* frame,
[email protected]310ebd6302011-10-10 19:06:282180 const WebFormElement& form) {
[email protected]2a5b1732011-04-01 23:55:552181 FOR_EACH_OBSERVER(
2182 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172183}
2184
[email protected]35b2a972014-04-04 15:50:222185void RenderViewImpl::didCreateDataSource(WebLocalFrame* frame,
2186 WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:572187 bool content_initiated = !pending_navigation_params_.get();
2188
[email protected]f8872902013-10-30 03:18:572189 // Make sure any previous redirect URLs end up in our new data source.
2190 if (pending_navigation_params_.get()) {
2191 for (std::vector<GURL>::const_iterator i =
2192 pending_navigation_params_->redirects.begin();
2193 i != pending_navigation_params_->redirects.end(); ++i) {
2194 ds->appendRedirect(*i);
2195 }
2196 }
2197
[email protected]007733c2011-11-17 00:34:072198 DocumentState* document_state = DocumentState::FromDataSource(ds);
2199 if (!document_state) {
2200 document_state = new DocumentState;
2201 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:572202 if (!content_initiated)
2203 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:072204 }
2205
[email protected]bf70edce2012-06-20 22:32:222206 // Carry over the user agent override flag, if it exists.
2207 if (content_initiated && webview() && webview()->mainFrame() &&
2208 webview()->mainFrame()->dataSource()) {
2209 DocumentState* old_document_state =
2210 DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
2211 if (old_document_state) {
[email protected]e20b88d2013-04-09 15:28:372212 InternalDocumentStateData* internal_data =
2213 InternalDocumentStateData::FromDocumentState(document_state);
2214 InternalDocumentStateData* old_internal_data =
2215 InternalDocumentStateData::FromDocumentState(old_document_state);
2216 internal_data->set_is_overriding_user_agent(
2217 old_internal_data->is_overriding_user_agent());
[email protected]bf70edce2012-06-20 22:32:222218 }
2219 }
2220
[email protected]3d9689372009-09-10 04:29:172221 // The rest of RenderView assumes that a WebDataSource will always have a
2222 // non-null NavigationState.
[email protected]e1ed5a12012-08-08 19:57:442223 if (content_initiated) {
[email protected]007733c2011-11-17 00:34:072224 document_state->set_navigation_state(
2225 NavigationState::CreateContentInitiated());
[email protected]e1ed5a12012-08-08 19:57:442226 } else {
[email protected]45d83a12012-04-06 22:57:572227 document_state->set_navigation_state(CreateNavigationStateFromPending());
2228 pending_navigation_params_.reset();
2229 }
[email protected]8a3125a712010-08-09 18:58:512230
[email protected]007733c2011-11-17 00:34:072231 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512232 // navigating from a page that used prefetching using a link on that
2233 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072234 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512235 // this value appropriately.
2236 // TODO(gavinp): catch the important case of navigation in a new
2237 // renderer process.
2238 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302239 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522240 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512241 const GURL referrer(
2242 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2243 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072244 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512245 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:412246 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:512247 WebDataSource* old_frame_ds = old_frame->dataSource();
2248 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072249 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512250 break;
2251 }
2252 }
2253 }
2254 }
2255 }
2256
[email protected]4c1b6f0b2010-02-07 16:38:182257 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522258 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512259 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182260 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072261 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182262 break;
2263 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072264 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182265 break;
2266 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072267 document_state->set_load_type(
2268 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182269 break;
2270 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072271 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182272 break;
2273 }
2274 }
[email protected]fa7b6b542009-11-03 05:02:302275
[email protected]946a0032011-03-31 18:42:282276 FOR_EACH_OBSERVER(
2277 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172278}
2279
[email protected]45d83a12012-04-06 22:57:572280void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:072281 DocumentState* document_state) {
[email protected]c6bc20332014-02-28 18:30:392282 const FrameMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:572283 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:072284
[email protected]e20b88d2013-04-09 15:28:372285 InternalDocumentStateData* internal_data =
2286 InternalDocumentStateData::FromDocumentState(document_state);
2287
[email protected]44b05812013-08-19 07:59:352288 if (!params.url.SchemeIs(kJavaScriptScheme) &&
[email protected]c6bc20332014-02-28 18:30:392289 params.navigation_type == FrameMsg_Navigate_Type::RESTORE) {
[email protected]45d83a12012-04-06 22:57:572290 // We're doing a load of a page that was restored from the last session. By
2291 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
2292 // can result in stale data for pages that are set to expire. We explicitly
2293 // override that by setting the policy here so that as necessary we load
2294 // from the network.
[email protected]a8ff8ed2014-01-09 07:32:262295 //
2296 // TODO(davidben): Remove this in favor of passing a cache policy to the
2297 // loadHistoryItem call in OnNavigate. That requires not overloading
2298 // UseProtocolCachePolicy to mean both "normal load" and "determine cache
2299 // policy based on load type, etc".
[email protected]e20b88d2013-04-09 15:28:372300 internal_data->set_cache_policy_override(
[email protected]45d83a12012-04-06 22:57:572301 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:072302 }
2303
2304 if (IsReload(params))
2305 document_state->set_load_type(DocumentState::RELOAD);
[email protected]691aa2f2013-05-28 22:52:042306 else if (params.page_state.IsValid())
[email protected]007733c2011-11-17 00:34:072307 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2308 else
2309 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]ca662822012-05-11 17:53:592310
[email protected]e20b88d2013-04-09 15:28:372311 internal_data->set_is_overriding_user_agent(params.is_overriding_user_agent);
2312 internal_data->set_must_reset_scroll_and_scale_state(
[email protected]a3a5397d2012-09-12 06:50:342313 params.navigation_type ==
[email protected]c6bc20332014-02-28 18:30:392314 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]951a64832012-10-11 16:26:372315 document_state->set_can_load_local_resources(params.can_load_local_resources);
[email protected]45d83a12012-04-06 22:57:572316}
[email protected]007733c2011-11-17 00:34:072317
[email protected]45d83a12012-04-06 22:57:572318NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
[email protected]c6bc20332014-02-28 18:30:392319 const FrameMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:572320 NavigationState* navigation_state = NULL;
2321
2322 // A navigation resulting from loading a javascript URL should not be treated
2323 // as a browser initiated event. Instead, we want it to look as if the page
2324 // initiated any load resulting from JS execution.
[email protected]44b05812013-08-19 07:59:352325 if (!params.url.SchemeIs(kJavaScriptScheme)) {
[email protected]45d83a12012-04-06 22:57:572326 navigation_state = NavigationState::CreateBrowserInitiated(
2327 params.page_id,
2328 params.pending_history_list_offset,
[email protected]60d6cca2013-04-30 08:47:132329 params.should_clear_history_list,
[email protected]45d83a12012-04-06 22:57:572330 params.transition);
[email protected]4972fc82013-11-19 04:33:422331 navigation_state->set_should_replace_current_entry(
2332 params.should_replace_current_entry);
[email protected]45d83a12012-04-06 22:57:572333 navigation_state->set_transferred_request_child_id(
2334 params.transferred_request_child_id);
2335 navigation_state->set_transferred_request_request_id(
2336 params.transferred_request_request_id);
[email protected]80744782012-05-04 01:47:002337 navigation_state->set_allow_download(params.allow_download);
[email protected]f050fde2013-03-21 00:40:452338 navigation_state->set_extra_headers(params.extra_headers);
[email protected]45d83a12012-04-06 22:57:572339 } else {
2340 navigation_state = NavigationState::CreateContentInitiated();
2341 }
2342 return navigation_state;
[email protected]007733c2011-11-17 00:34:072343}
2344
[email protected]5b52cd2f712012-03-28 02:12:482345void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
2346 bool enable_viewport =
[email protected]a41f8f602013-11-12 20:15:282347 command_line.HasSwitch(switches::kEnableViewport) ||
2348 command_line.HasSwitch(switches::kEnableViewportMeta);
[email protected]5b52cd2f712012-03-28 02:12:482349
[email protected]47e932da2013-03-07 00:11:242350 // If viewport tag is enabled, then the WebKit side will take care
2351 // of setting the fixed layout size and page scale limits.
2352 if (enable_viewport)
2353 return;
2354
[email protected]a02a0c92013-08-12 20:18:582355 // When navigating to a new page, reset the page scale factor to be 1.0.
2356 webview()->setInitialPageScaleOverride(1.f);
2357
[email protected]e4cd82e2013-04-10 15:20:382358 float maxPageScaleFactor =
2359 command_line.HasSwitch(switches::kEnablePinch) ? 4.f : 1.f ;
2360 webview()->setPageScaleFactorLimits(1, maxPageScaleFactor);
[email protected]5b52cd2f712012-03-28 02:12:482361}
2362
[email protected]8672bbf2013-10-22 13:37:082363// TODO(nasko): Remove this method once WebTestProxy in Blink is fixed.
[email protected]35b2a972014-04-04 15:50:222364void RenderViewImpl::didStartProvisionalLoad(WebLocalFrame* frame) {}
[email protected]3d9689372009-09-10 04:29:172365
[email protected]35b2a972014-04-04 15:50:222366void RenderViewImpl::didFailProvisionalLoad(WebLocalFrame* frame,
[email protected]310ebd6302011-10-10 19:06:282367 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172368 // Notify the browser that we failed a provisional load with an error.
2369 //
2370 // Note: It is important this notification occur before DidStopLoading so the
2371 // SSL manager can react to the provisional load failure before being
2372 // notified the load stopped.
2373 //
[email protected]28685da92011-02-07 21:49:172374 FOR_EACH_OBSERVER(
2375 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:172376}
2377
[email protected]934a2012014-04-08 22:42:382378void RenderViewImpl::FrameDidCommitProvisionalLoad(WebLocalFrame* frame,
[email protected]5d5471b2014-04-04 22:17:522379 bool is_new_navigation) {
[email protected]28685da92011-02-07 21:49:172380 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2381 DidCommitProvisionalLoad(frame, is_new_navigation));
2382
[email protected]37567b432014-02-12 01:12:222383 // TODO(nasko): Transition this code to RenderFrameImpl, since g_view_map is
2384 // not accessible from there.
[email protected]b2d98762012-09-03 17:04:062385 if (!frame->parent()) { // Only for top frames.
2386 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
2387 if (render_thread_impl) { // Can be NULL in tests.
2388 render_thread_impl->histogram_customizer()->
2389 RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(),
2390 g_view_map.Get().size());
2391 }
2392 }
[email protected]3d9689372009-09-10 04:29:172393}
2394
[email protected]35b2a972014-04-04 15:50:222395void RenderViewImpl::didClearWindowObject(WebLocalFrame* frame, int world_id) {
[email protected]9966325b2011-04-18 05:00:102396 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
[email protected]c4f80f72014-01-13 11:24:122397 DidClearWindowObject(frame, world_id));
[email protected]9966325b2011-04-18 05:00:102398
[email protected]29043082014-01-22 21:53:512399 // Only install controllers into the main world.
2400 if (world_id)
2401 return;
2402
[email protected]f5c9f0882014-02-16 22:19:322403 if (enabled_bindings_& BINDINGS_POLICY_WEB_UI)
2404 WebUIExtension::Install(frame);
2405
[email protected]caa8dc042014-01-13 12:07:582406 if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION)
2407 StatsCollectionController::Install(frame);
[email protected]cdb6b1e2014-01-23 00:06:492408
2409 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2410
2411 if (command_line.HasSwitch(switches::kEnableSkiaBenchmarking))
2412 SkiaBenchmarking::Install(frame);
[email protected]3fad220d2014-01-23 11:30:062413
2414 if (command_line.HasSwitch(switches::kEnableMemoryBenchmarking))
2415 MemoryBenchmarkingExtension::Install(frame);
[email protected]3d9689372009-09-10 04:29:172416}
2417
[email protected]35b2a972014-04-04 15:50:222418void RenderViewImpl::didCreateDocumentElement(WebLocalFrame* frame) {
[email protected]e48869a2011-04-01 19:56:032419 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2420 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172421}
2422
[email protected]35b2a972014-04-04 15:50:222423void RenderViewImpl::didReceiveTitle(WebLocalFrame* frame,
2424 const WebString& title,
[email protected]310ebd6302011-10-10 19:06:282425 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462426 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172427
2428 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272429 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172430}
2431
[email protected]35b2a972014-04-04 15:50:222432void RenderViewImpl::didChangeIcon(WebLocalFrame* frame,
[email protected]41225fe2013-03-29 05:32:022433 WebIconURL::Type icon_type) {
2434 if (frame->parent())
2435 return;
2436
2437 if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon)
2438 return;
2439
2440 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type);
2441 std::vector<FaviconURL> urls;
2442 for (size_t i = 0; i < icon_urls.size(); i++) {
[email protected]f34ac132014-03-20 23:02:052443 std::vector<gfx::Size> sizes(icon_urls[i].sizes().size());
2444 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
2445 urls.push_back(FaviconURL(
2446 icon_urls[i].iconURL(), ToFaviconType(icon_urls[i].iconType()), sizes));
[email protected]41225fe2013-03-29 05:32:022447 }
2448 SendUpdateFaviconURL(urls);
[email protected]5019ef12010-04-27 17:26:582449}
2450
[email protected]35b2a972014-04-04 15:50:222451void RenderViewImpl::didFinishDocumentLoad(WebLocalFrame* frame) {
[email protected]28685da92011-02-07 21:49:172452 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2453 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172454}
2455
[email protected]35b2a972014-04-04 15:50:222456void RenderViewImpl::didHandleOnloadEvents(WebLocalFrame* frame) {
[email protected]25497492010-09-11 15:15:082457 if (webview()->mainFrame() == frame) {
2458 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2459 page_id_));
2460 }
[email protected]3d9689372009-09-10 04:29:172461}
2462
[email protected]35b2a972014-04-04 15:50:222463void RenderViewImpl::didFailLoad(WebLocalFrame* frame,
2464 const WebURLError& error) {
[email protected]28685da92011-02-07 21:49:172465 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:172466}
2467
[email protected]35b2a972014-04-04 15:50:222468void RenderViewImpl::didFinishLoad(WebLocalFrame* frame) {
[email protected]676126f72011-01-15 00:03:512469 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]3d9689372009-09-10 04:29:172470}
2471
[email protected]35b2a972014-04-04 15:50:222472void RenderViewImpl::didUpdateCurrentHistoryItem(WebLocalFrame* frame) {
[email protected]882daa92009-11-05 16:31:312473 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592474}
2475
[email protected]35b2a972014-04-04 15:50:222476void RenderViewImpl::didFinishResourceLoad(WebLocalFrame* frame,
2477 unsigned identifier) {
[email protected]e20b88d2013-04-09 15:28:372478 InternalDocumentStateData* internal_data =
2479 InternalDocumentStateData::FromDataSource(frame->dataSource());
2480 if (!internal_data->use_error_page())
[email protected]3d9689372009-09-10 04:29:172481 return;
2482
[email protected]7bfc153f2011-09-23 22:00:202483 // Do not show error page when DevTools is attached.
2484 if (devtools_agent_->IsAttached())
2485 return;
2486
[email protected]06333afe2011-02-24 14:55:092487 // Display error page, if appropriate.
[email protected]3d612f52014-01-13 23:48:292488 std::string error_domain = "http";
[email protected]e20b88d2013-04-09 15:28:372489 int http_status_code = internal_data->http_status_code();
[email protected]e9ff79c2012-10-19 21:31:262490 if (GetContentClient()->renderer()->HasErrorPage(
[email protected]e6a2ce52011-10-08 01:40:132491 http_status_code, &error_domain)) {
2492 WebURLError error;
2493 error.unreachableURL = frame->document().url();
2494 error.domain = WebString::fromUTF8(error_domain);
2495 error.reason = http_status_code;
[email protected]3d612f52014-01-13 23:48:292496 LoadNavigationErrorPage(frame, frame->dataSource()->request(), error, true);
[email protected]e6a2ce52011-10-08 01:40:132497 }
[email protected]3d9689372009-09-10 04:29:172498}
2499
[email protected]310ebd6302011-10-10 19:06:282500void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:072501 // We don't always want to send the change messages over IPC, only if we've
2502 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2503 // message.
2504 if (!send_preferred_size_changes_ || !webview())
2505 return;
2506
[email protected]e76b7972013-06-06 02:58:482507 gfx::Size size = webview()->contentsPreferredMinimumSize();
[email protected]8205d742010-10-22 23:51:532508
[email protected]7940b8e2013-07-25 23:08:492509 // In the presence of zoom, these sizes are still reported as if unzoomed,
2510 // so we need to adjust.
2511 double zoom_factor = ZoomLevelToZoomFactor(webview()->zoomLevel());
2512 size.set_width(static_cast<int>(size.width() * zoom_factor));
2513 size.set_height(static_cast<int>(size.height() * zoom_factor));
2514
[email protected]705243f2010-05-05 19:58:072515 if (size == preferred_size_)
2516 return;
[email protected]c27324b2009-11-19 22:44:292517
[email protected]705243f2010-05-05 19:58:072518 preferred_size_ = size;
2519 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2520 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172521}
2522
[email protected]caaf2482013-05-01 20:33:322523BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() {
[email protected]fc72bb12013-06-02 21:13:462524 if (!browser_plugin_manager_.get())
[email protected]fb325d122012-11-20 23:58:052525 browser_plugin_manager_ = BrowserPluginManager::Create(this);
[email protected]fc72bb12013-06-02 21:13:462526 return browser_plugin_manager_.get();
[email protected]fb325d122012-11-20 23:58:052527}
2528
[email protected]60ee79f2013-09-11 13:49:552529bool RenderViewImpl::InitializeMediaStreamClient() {
2530 if (media_stream_client_)
2531 return true;
2532
[email protected]7082fb942012-05-16 23:44:592533 if (!RenderThreadImpl::current()) // Will be NULL during unit tests.
[email protected]60ee79f2013-09-11 13:49:552534 return false;
[email protected]08381562012-05-15 20:55:402535
[email protected]d9da9582013-01-31 04:59:052536#if defined(OS_ANDROID)
[email protected]ce585bf2013-03-14 16:25:162537 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableWebRTC))
[email protected]60ee79f2013-09-11 13:49:552538 return false;
[email protected]d9da9582013-01-31 04:59:052539#endif
2540
[email protected]4fb0f202012-05-30 22:44:532541#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:512542 if (!media_stream_dispatcher_)
2543 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
2544
[email protected]60ee79f2013-09-11 13:49:552545 MediaStreamImpl* media_stream_impl = new MediaStreamImpl(
2546 this,
2547 media_stream_dispatcher_,
2548 RenderThreadImpl::current()->GetMediaStreamDependencyFactory());
2549 media_stream_client_ = media_stream_impl;
2550 web_user_media_client_ = media_stream_impl;
2551 return true;
2552#else
2553 return false;
[email protected]5b87e782012-02-09 18:19:322554#endif
[email protected]273558fb2012-01-12 15:03:512555}
2556
[email protected]35b2a972014-04-04 15:50:222557void RenderViewImpl::didChangeContentsSize(WebLocalFrame* frame,
[email protected]310ebd6302011-10-10 19:06:282558 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:312559 if (webview()->mainFrame() != frame)
2560 return;
2561 WebView* frameView = frame->view();
2562 if (!frameView)
2563 return;
2564
2565 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
2566 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
2567
2568 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
2569 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
2570 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
2571 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
2572
2573 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
2574 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
2575 }
2576}
2577
[email protected]310ebd6302011-10-10 19:06:282578void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:312579 WebSize offset = frame->scrollOffset();
2580 WebSize minimum_offset = frame->minimumScrollOffset();
2581 WebSize maximum_offset = frame->maximumScrollOffset();
2582
2583 bool is_pinned_to_left = offset.width <= minimum_offset.width;
2584 bool is_pinned_to_right = offset.width >= maximum_offset.width;
2585
2586 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
2587 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
2588 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
2589 routing_id_, is_pinned_to_left, is_pinned_to_right));
2590
2591 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
2592 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
2593 }
[email protected]4e721742013-02-04 21:39:302594
2595 Send(new ViewHostMsg_DidChangeScrollOffset(routing_id_));
[email protected]dd6afca2011-08-13 03:44:312596}
2597
[email protected]35b2a972014-04-04 15:50:222598void RenderViewImpl::didChangeScrollOffset(WebLocalFrame* frame) {
[email protected]143dcd592009-11-06 21:33:492599 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:312600
2601 if (webview()->mainFrame() == frame)
2602 UpdateScrollState(frame);
[email protected]2b942c332012-04-25 16:26:262603
2604 FOR_EACH_OBSERVER(
2605 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]dd6afca2011-08-13 03:44:312606}
2607
[email protected]35b2a972014-04-04 15:50:222608void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebLocalFrame* frame) {
[email protected]4d0f8182012-10-19 23:14:472609 if (frame != webview()->mainFrame())
2610 return;
2611
[email protected]92d457802013-04-01 19:18:492612 InternalDocumentStateData* data =
2613 InternalDocumentStateData::FromDataSource(frame->dataSource());
2614 data->set_did_first_visually_non_empty_layout(true);
2615
2616#if defined(OS_ANDROID)
[email protected]4d0f8182012-10-19 23:14:472617 // Update body background color if necessary.
2618 SkColor bg_color = webwidget_->backgroundColor();
2619
2620 // If not initialized, default to white. Note that 0 is different from black
2621 // as black still has alpha 0xFF.
2622 if (!bg_color)
2623 bg_color = SK_ColorWHITE;
2624
2625 if (bg_color != body_background_color_) {
2626 body_background_color_ = bg_color;
[email protected]e507045d2013-07-24 15:23:442627 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(
2628 GetRoutingID(), bg_color));
[email protected]4d0f8182012-10-19 23:14:472629 }
[email protected]4d0f8182012-10-19 23:14:472630#endif
[email protected]92d457802013-04-01 19:18:492631}
[email protected]4d0f8182012-10-19 23:14:472632
[email protected]55750b32012-09-21 14:05:032633void RenderViewImpl::SendFindReply(int request_id,
2634 int match_count,
2635 int ordinal,
2636 const WebRect& selection_rect,
2637 bool final_status_update) {
[email protected]55750b32012-09-21 14:05:032638 Send(new ViewHostMsg_Find_Reply(routing_id_,
2639 request_id,
2640 match_count,
2641 selection_rect,
2642 ordinal,
2643 final_status_update));
2644}
2645
[email protected]f546640b2012-05-15 00:03:492646bool RenderViewImpl::willCheckAndDispatchMessageEvent(
[email protected]35b2a972014-04-04 15:50:222647 blink::WebLocalFrame* sourceFrame,
[email protected]180ef242013-11-07 06:50:462648 blink::WebFrame* targetFrame,
2649 blink::WebSecurityOrigin target_origin,
2650 blink::WebDOMMessageEvent event) {
[email protected]f546640b2012-05-15 00:03:492651 if (!is_swapped_out_)
2652 return false;
2653
2654 ViewMsg_PostMessage_Params params;
2655 params.data = event.data().toString();
2656 params.source_origin = event.origin();
2657 if (!target_origin.isNull())
2658 params.target_origin = target_origin.toString();
2659
[email protected]180ef242013-11-07 06:50:462660 blink::WebMessagePortChannelArray channels = event.releaseChannels();
[email protected]0bc7f3542013-10-21 15:05:532661 if (!channels.isEmpty()) {
2662 std::vector<int> message_port_ids(channels.size());
2663 // Extract the port IDs from the channel array.
2664 for (size_t i = 0; i < channels.size(); ++i) {
2665 WebMessagePortChannelImpl* webchannel =
2666 static_cast<WebMessagePortChannelImpl*>(channels[i]);
2667 message_port_ids[i] = webchannel->message_port_id();
2668 webchannel->QueueMessages();
2669 DCHECK_NE(message_port_ids[i], MSG_ROUTING_NONE);
2670 }
2671 params.message_port_ids = message_port_ids;
2672 }
2673
[email protected]2bb45f52013-11-02 02:15:082674 // Include the routing ID for the source frame (if one exists), which the
2675 // browser process will translate into the routing ID for the equivalent
2676 // frame in the target process.
[email protected]f546640b2012-05-15 00:03:492677 params.source_routing_id = MSG_ROUTING_NONE;
[email protected]2bb45f52013-11-02 02:15:082678 if (sourceFrame) {
2679 RenderViewImpl* source_view = FromWebView(sourceFrame->view());
2680 if (source_view)
2681 params.source_routing_id = source_view->routing_id();
2682 }
[email protected]f546640b2012-05-15 00:03:492683
2684 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params));
2685 return true;
2686}
2687
[email protected]180ef242013-11-07 06:50:462688blink::WebString RenderViewImpl::acceptLanguages() {
[email protected]9982c802013-06-12 15:22:062689 return WebString::fromUTF8(renderer_preferences_.accept_languages);
2690}
2691
[email protected]180ef242013-11-07 06:50:462692// blink::WebPageSerializerClient implementation ------------------------------
[email protected]18d5be92011-07-25 18:00:192693
[email protected]310ebd6302011-10-10 19:06:282694void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:192695 const WebURL& frame_url,
2696 const WebCString& data,
2697 WebPageSerializerClient::PageSerializationStatus status) {
2698 Send(new ViewHostMsg_SendSerializedHtmlData(
2699 routing_id(),
2700 frame_url,
2701 data.data(),
2702 static_cast<int32>(status)));
2703}
2704
[email protected]e9ff79c2012-10-19 21:31:262705// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:312706
[email protected]310ebd6302011-10-10 19:06:282707bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:312708 return RenderWidget::Send(message);
2709}
2710
[email protected]b849847b2013-12-10 21:57:582711RenderFrame* RenderViewImpl::GetMainRenderFrame() {
2712 return main_render_frame_.get();
2713}
2714
[email protected]82114f52012-03-20 22:53:412715int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:312716 return routing_id_;
2717}
2718
[email protected]82114f52012-03-20 22:53:412719int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:312720 return page_id_;
2721}
2722
[email protected]82114f52012-03-20 22:53:412723gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:312724 return size();
2725}
2726
[email protected]82114f52012-03-20 22:53:412727WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:312728 return webkit_preferences_;
2729}
2730
[email protected]324825d2012-11-30 12:37:152731void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
2732 OnUpdateWebPreferences(preferences);
2733}
2734
[email protected]180ef242013-11-07 06:50:462735blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:312736 return webview();
2737}
2738
[email protected]c39f7442014-02-27 03:33:172739blink::WebElement RenderViewImpl::GetFocusedElement() const {
[email protected]a2ef54c2011-10-10 16:20:312740 if (!webview())
[email protected]c39f7442014-02-27 03:33:172741 return WebElement();
[email protected]a2ef54c2011-10-10 16:20:312742 WebFrame* focused_frame = webview()->focusedFrame();
2743 if (focused_frame) {
2744 WebDocument doc = focused_frame->document();
2745 if (!doc.isNull())
[email protected]c39f7442014-02-27 03:33:172746 return doc.focusedElement();
[email protected]a2ef54c2011-10-10 16:20:312747 }
2748
[email protected]c39f7442014-02-27 03:33:172749 return WebElement();
[email protected]a2ef54c2011-10-10 16:20:312750}
2751
[email protected]2a84f9d2012-06-05 21:50:432752bool RenderViewImpl::IsEditableNode(const WebNode& node) const {
2753 if (node.isNull())
2754 return false;
2755
2756 if (node.isContentEditable())
2757 return true;
2758
2759 if (node.isElementNode()) {
2760 const WebElement& element = node.toConst<WebElement>();
2761 if (element.isTextFormControlElement())
2762 return true;
2763
2764 // Also return true if it has an ARIA role of 'textbox'.
2765 for (unsigned i = 0; i < element.attributeCount(); ++i) {
2766 if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) {
2767 if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox"))
2768 return true;
2769 break;
2770 }
[email protected]a2ef54c2011-10-10 16:20:312771 }
2772 }
[email protected]2a84f9d2012-06-05 21:50:432773
2774 return false;
[email protected]a2ef54c2011-10-10 16:20:312775}
2776
[email protected]310ebd6302011-10-10 19:06:282777bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:312778 return (!send_preferred_size_changes_ ||
2779 (disable_scrollbars_size_limit_.width() <= width ||
2780 disable_scrollbars_size_limit_.height() <= height));
2781}
2782
[email protected]82114f52012-03-20 22:53:412783int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:312784 return enabled_bindings_;
2785}
2786
[email protected]82114f52012-03-20 22:53:412787bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:312788 return send_content_state_immediately_;
2789}
2790
[email protected]82114f52012-03-20 22:53:412791float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:312792 return filtered_time_per_frame();
2793}
2794
[email protected]180ef242013-11-07 06:50:462795blink::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:312796 return visibilityState();
2797}
2798
[email protected]3c71576ce2013-07-23 02:00:012799void RenderViewImpl::DidStartLoading() {
[email protected]6dd5c322014-03-12 07:58:462800 main_render_frame_->didStartLoading(true);
[email protected]3c71576ce2013-07-23 02:00:012801}
2802
2803void RenderViewImpl::DidStopLoading() {
[email protected]6dd5c322014-03-12 07:58:462804 main_render_frame_->didStopLoading();
[email protected]3c71576ce2013-07-23 02:00:012805}
2806
[email protected]180ef242013-11-07 06:50:462807void RenderViewImpl::DidPlay(blink::WebMediaPlayer* player) {
[email protected]1dd0bb752014-02-01 01:16:262808 Send(new ViewHostMsg_MediaPlayingNotification(routing_id_,
2809 reinterpret_cast<int64>(player),
2810 player->hasVideo(),
2811 player->hasAudio()));
[email protected]baff4512011-10-19 18:21:072812}
2813
[email protected]180ef242013-11-07 06:50:462814void RenderViewImpl::DidPause(blink::WebMediaPlayer* player) {
[email protected]1dd0bb752014-02-01 01:16:262815 Send(new ViewHostMsg_MediaPausedNotification(
2816 routing_id_, reinterpret_cast<int64>(player)));
[email protected]baff4512011-10-19 18:21:072817}
2818
[email protected]180ef242013-11-07 06:50:462819void RenderViewImpl::PlayerGone(blink::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:072820 DidPause(player);
2821}
2822
[email protected]310ebd6302011-10-10 19:06:282823void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:292824 if (!webview())
2825 return;
2826
[email protected]26aa0482009-09-30 16:55:272827 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:052828 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:292829}
2830
[email protected]180ef242013-11-07 06:50:462831GURL RenderViewImpl::GetLoadingUrl(blink::WebFrame* frame) const {
[email protected]69ddf852012-02-21 23:21:312832 WebDataSource* ds = frame->dataSource();
2833 if (ds->hasUnreachableURL())
2834 return ds->unreachableURL();
2835
2836 const WebURLRequest& request = ds->request();
2837 return request.url();
2838}
2839
[email protected]54ea9ff2014-03-20 00:27:542840blink::WebPlugin* RenderViewImpl::GetWebPluginForFind() {
2841 if (!webview())
2842 return NULL;
2843
2844 WebFrame* main_frame = webview()->mainFrame();
2845 if (main_frame->document().isPluginDocument())
2846 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
2847
2848#if defined(ENABLE_PLUGINS)
2849 if (plugin_find_handler_)
2850 return plugin_find_handler_->container()->plugin();
2851#endif
2852
2853 return NULL;
[email protected]24a7f3c2010-03-25 08:26:492854}
2855
[email protected]55750b32012-09-21 14:05:032856void RenderViewImpl::OnFind(int request_id,
[email protected]fcf75d42013-12-03 20:11:262857 const base::string16& search_text,
[email protected]310ebd6302011-10-10 19:06:282858 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:272859 WebFrame* main_frame = webview()->mainFrame();
[email protected]54ea9ff2014-03-20 00:27:542860 blink::WebPlugin* plugin = GetWebPluginForFind();
[email protected]872542532011-06-23 00:43:162861 // Check if the plugin still exists in the document.
[email protected]54ea9ff2014-03-20 00:27:542862 if (plugin) {
[email protected]24a7f3c2010-03-25 08:26:492863 if (options.findNext) {
2864 // Just navigate back/forward.
[email protected]54ea9ff2014-03-20 00:27:542865 plugin->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:492866 } else {
[email protected]54ea9ff2014-03-20 00:27:542867 if (!plugin->startFind(
[email protected]afdbd142010-07-10 08:01:232868 search_text, options.matchCase, request_id)) {
[email protected]e7c58a32010-08-13 19:47:112869 // Send "no results".
[email protected]55750b32012-09-21 14:05:032870 SendFindReply(request_id, 0, 0, gfx::Rect(), true);
[email protected]24a7f3c2010-03-25 08:26:492871 }
2872 }
2873 return;
2874 }
2875
[email protected]b4bb2502009-10-01 22:35:272876 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:272877 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:292878 WebFrame* search_frame = focused_frame; // start searching focused frame.
2879
2880 bool multi_frame = (frame_after_main != main_frame);
2881
2882 // If we have multiple frames, we don't want to wrap the search within the
2883 // frame, so we check here if we only have main_frame in the chain.
2884 bool wrap_within_frame = !multi_frame;
2885
[email protected]b3f2b912009-04-09 16:18:522886 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:292887 bool result = false;
2888
[email protected]7830da3e2009-11-06 16:27:262889 // If something is selected when we start searching it means we cannot just
2890 // increment the current match ordinal; we need to re-generate it.
2891 WebRange current_selection = focused_frame->selectionRange();
2892
initial.commit09911bf2008-07-26 23:55:292893 do {
[email protected]dd7daa82009-08-10 05:46:452894 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592895 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:292896
2897 if (!result) {
2898 // don't leave text selected as you move to the next frame.
[email protected]6dd17a8a2013-05-01 05:50:102899 search_frame->executeCommand(WebString::fromUTF8("Unselect"),
[email protected]c39f7442014-02-27 03:33:172900 GetFocusedElement());
initial.commit09911bf2008-07-26 23:55:292901
2902 // Find the next frame, but skip the invisible ones.
2903 do {
2904 // What is the next frame to search? (we might be going backwards). Note
2905 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:592906 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:272907 search_frame->traverseNext(true) :
2908 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:452909 } while (!search_frame->hasVisibleContent() &&
2910 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:292911
[email protected]884db412008-11-24 23:46:502912 // Make sure selection doesn't affect the search operation in new frame.
[email protected]6dd17a8a2013-05-01 05:50:102913 search_frame->executeCommand(WebString::fromUTF8("Unselect"),
[email protected]c39f7442014-02-27 03:33:172914 GetFocusedElement());
initial.commit09911bf2008-07-26 23:55:292915
2916 // If we have multiple frames and we have wrapped back around to the
2917 // focused frame, we need to search it once more allowing wrap within
2918 // the frame, otherwise it will report 'no match' if the focused frame has
2919 // reported matches, but no frames after the focused_frame contain a
2920 // match for the search word(s).
2921 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:452922 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:592923 request_id, search_text, options, true, // Force wrapping.
2924 &selection_rect);
initial.commit09911bf2008-07-26 23:55:292925 }
2926 }
2927
[email protected]26aa0482009-09-30 16:55:272928 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:292929 } while (!result && search_frame != focused_frame);
2930
[email protected]7830da3e2009-11-06 16:27:262931 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:292932 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:452933 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:292934 } else {
2935 // If nothing is found, set result to "0 of 0", otherwise, set it to
2936 // "-1 of 1" to indicate that we found at least one item, but we don't know
2937 // yet what is active.
2938 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
2939 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:292940
[email protected]4f3dc372009-02-24 00:10:292941 // If we find no matches then this will be our last status update.
2942 // Otherwise the scoping effort will send more results.
2943 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:292944
[email protected]55750b32012-09-21 14:05:032945 SendFindReply(request_id, match_count, ordinal, selection_rect,
2946 final_status_update);
initial.commit09911bf2008-07-26 23:55:292947
initial.commit09911bf2008-07-26 23:55:292948 // Scoping effort begins, starting with the mainframe.
2949 search_frame = main_frame;
2950
[email protected]dd7daa82009-08-10 05:46:452951 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:292952
2953 do {
2954 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:452955 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:292956
2957 // We don't start another scoping effort unless at least one match has
2958 // been found.
2959 if (result) {
2960 // Start new scoping request. If the scoping function determines that it
2961 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:452962 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:592963 search_text,
2964 options,
initial.commit09911bf2008-07-26 23:55:292965 true); // reset the tickmarks
2966 }
2967
2968 // Iterate to the next frame. The frame will not necessarily scope, for
2969 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:272970 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:292971 } while (search_frame != main_frame);
2972 }
2973}
2974
[email protected]e9ff79c2012-10-19 21:31:262975void RenderViewImpl::OnStopFinding(StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:492976 WebView* view = webview();
2977 if (!view)
2978 return;
2979
[email protected]54ea9ff2014-03-20 00:27:542980 blink::WebPlugin* plugin = GetWebPluginForFind();
2981 if (plugin) {
2982 plugin->stopFind();
[email protected]24a7f3c2010-03-25 08:26:492983 return;
2984 }
2985
[email protected]e9ff79c2012-10-19 21:31:262986 bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]6dd17a8a2013-05-01 05:50:102987 if (clear_selection) {
2988 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
[email protected]c39f7442014-02-27 03:33:172989 GetFocusedElement());
[email protected]6dd17a8a2013-05-01 05:50:102990 }
[email protected]24a7f3c2010-03-25 08:26:492991
2992 WebFrame* frame = view->mainFrame();
2993 while (frame) {
2994 frame->stopFinding(clear_selection);
2995 frame = frame->traverseNext(false);
2996 }
2997
[email protected]e9ff79c2012-10-19 21:31:262998 if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:492999 WebFrame* focused_frame = view->focusedFrame();
3000 if (focused_frame) {
3001 WebDocument doc = focused_frame->document();
3002 if (!doc.isNull()) {
[email protected]c39f7442014-02-27 03:33:173003 WebElement element = doc.focusedElement();
3004 if (!element.isNull())
3005 element.simulateClick();
[email protected]24a7f3c2010-03-25 08:26:493006 }
3007 }
3008 }
3009}
3010
[email protected]59363fc92012-09-05 03:46:313011#if defined(OS_ANDROID)
3012void RenderViewImpl::OnActivateNearestFindResult(int request_id,
3013 float x, float y) {
3014 if (!webview())
3015 return;
3016
3017 WebFrame* main_frame = webview()->mainFrame();
3018 WebRect selection_rect;
3019 int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y),
3020 &selection_rect);
3021 if (ordinal == -1) {
3022 // Something went wrong, so send a no-op reply (force the main_frame to
3023 // report the current match count) in case the host is waiting for a
3024 // response due to rate-limiting).
3025 main_frame->increaseMatchCount(0, request_id);
3026 return;
3027 }
3028
[email protected]55750b32012-09-21 14:05:033029 SendFindReply(request_id,
3030 -1 /* number_of_matches */,
3031 ordinal,
3032 selection_rect,
3033 true /* final_update */);
[email protected]59363fc92012-09-05 03:46:313034}
3035
3036void RenderViewImpl::OnFindMatchRects(int current_version) {
3037 if (!webview())
3038 return;
3039
3040 WebFrame* main_frame = webview()->mainFrame();
3041 std::vector<gfx::RectF> match_rects;
3042
3043 int rects_version = main_frame->findMatchMarkersVersion();
3044 if (current_version != rects_version) {
3045 WebVector<WebFloatRect> web_match_rects;
3046 main_frame->findMatchRects(web_match_rects);
3047 match_rects.reserve(web_match_rects.size());
3048 for (size_t i = 0; i < web_match_rects.size(); ++i)
3049 match_rects.push_back(gfx::RectF(web_match_rects[i]));
3050 }
3051
3052 gfx::RectF active_rect = main_frame->activeFindMatchRect();
3053 Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_,
3054 rects_version,
3055 match_rects,
3056 active_rect));
3057}
3058#endif
3059
[email protected]e9ff79c2012-10-19 21:31:263060void RenderViewImpl::OnZoom(PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:513061 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3062 return;
3063
[email protected]258d31122010-05-09 10:59:413064 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:103065
[email protected]b75b8292010-10-01 07:28:253066 double old_zoom_level = webview()->zoomLevel();
3067 double zoom_level;
[email protected]e9ff79c2012-10-19 21:31:263068 if (zoom == PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:253069 zoom_level = 0;
3070 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3071 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:483072 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:253073 } else {
3074 // Either the user hit the zoom factor limit and thus the zoom level is now
3075 // not a whole number, or a plugin changed it to a custom value. We want
3076 // to go to the next whole number so that the user can always get back to
3077 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:483078 if ((old_zoom_level > 1 && zoom > 0) ||
3079 (old_zoom_level < 1 && zoom < 0)) {
3080 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:253081 } else {
3082 // We're going towards 100%, so first go to the next whole number.
3083 zoom_level = static_cast<int>(old_zoom_level);
3084 }
3085 }
[email protected]91219702013-09-18 07:33:513086 webview()->setZoomLevel(zoom_level);
[email protected]47578fa02011-11-02 19:34:413087 zoomLevelChanged();
3088}
3089
[email protected]310ebd6302011-10-10 19:06:283090void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:173091 webview()->hidePopups();
[email protected]91219702013-09-18 07:33:513092 webview()->setZoomLevel(zoom_level);
[email protected]d0b8d092010-10-25 04:05:173093 zoomLevelChanged();
3094}
3095
[email protected]310ebd6302011-10-10 19:06:283096void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
3097 double zoom_level) {
[email protected]cbe55d22013-02-14 17:04:333098#if !defined(OS_ANDROID)
3099 // On Android, page zoom isn't used, and in case of WebView, text zoom is used
3100 // for legacy WebView text scaling emulation. Thus, the code that resets
3101 // the zoom level from this map will be effectively resetting text zoom level.
[email protected]9d797f32010-04-23 07:17:543102 host_zoom_levels_[url] = zoom_level;
[email protected]cbe55d22013-02-14 17:04:333103#endif
initial.commit09911bf2008-07-26 23:55:293104}
3105
[email protected]310ebd6302011-10-10 19:06:283106void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273107 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293108}
3109
[email protected]310ebd6302011-10-10 19:06:283110void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273111 WebString no_encoding;
3112 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183113}
3114
[email protected]f546640b2012-05-15 00:03:493115void RenderViewImpl::OnPostMessageEvent(
3116 const ViewMsg_PostMessage_Params& params) {
[email protected]bf4a2312013-04-23 00:32:113117 // TODO(nasko): Support sending to subframes.
[email protected]e12dbe6f2012-10-04 22:11:193118 WebFrame* frame = webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:493119
3120 // Find the source frame if it exists.
[email protected]f546640b2012-05-15 00:03:493121 WebFrame* source_frame = NULL;
3122 if (params.source_routing_id != MSG_ROUTING_NONE) {
3123 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
3124 if (source_view)
[email protected]e12dbe6f2012-10-04 22:11:193125 source_frame = source_view->webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:493126 }
3127
[email protected]0bc7f3542013-10-21 15:05:533128 // If the message contained MessagePorts, create the corresponding endpoints.
3129 DCHECK_EQ(params.message_port_ids.size(), params.new_routing_ids.size());
[email protected]180ef242013-11-07 06:50:463130 blink::WebMessagePortChannelArray channels(params.message_port_ids.size());
[email protected]0bc7f3542013-10-21 15:05:533131 for (size_t i = 0;
3132 i < params.message_port_ids.size() && i < params.new_routing_ids.size();
3133 ++i) {
3134 channels[i] =
3135 new WebMessagePortChannelImpl(params.new_routing_ids[i],
3136 params.message_port_ids[i],
3137 base::MessageLoopProxy::current().get());
3138 }
3139
[email protected]f546640b2012-05-15 00:03:493140 // Create an event with the message. The final parameter to initMessageEvent
3141 // is the last event ID, which is not used with postMessage.
3142 WebDOMEvent event = frame->document().createEvent("MessageEvent");
3143 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
3144 msg_event.initMessageEvent("message",
3145 // |canBubble| and |cancellable| are always false
3146 false, false,
3147 WebSerializedScriptValue::fromString(params.data),
[email protected]0bc7f3542013-10-21 15:05:533148 params.source_origin, source_frame, "", channels);
[email protected]f546640b2012-05-15 00:03:493149
3150 // We must pass in the target_origin to do the security check on this side,
3151 // since it may have changed since the original postMessage call was made.
3152 WebSecurityOrigin target_origin;
3153 if (!params.target_origin.empty()) {
3154 target_origin =
3155 WebSecurityOrigin::createFromString(WebString(params.target_origin));
3156 }
3157 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
3158}
3159
[email protected]310ebd6302011-10-10 19:06:283160void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]940ed1d2012-11-27 21:03:213161 if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) &&
3162 !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) {
[email protected]69a0a132014-03-26 16:45:023163 // WebUIExtensionData deletes itself when we're destroyed.
[email protected]940ed1d2012-11-27 21:03:213164 new WebUIExtensionData(this);
[email protected]69a0a132014-03-26 16:45:023165 // WebUIMojo deletes itself when we're destroyed.
3166 new WebUIMojo(this);
[email protected]940ed1d2012-11-27 21:03:213167 }
3168
[email protected]81e63782009-02-27 19:35:093169 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:043170
3171 // Keep track of the total bindings accumulated in this process.
3172 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:293173}
3174
[email protected]dc293a72013-07-01 11:11:223175void RenderViewImpl::OnDragTargetDragEnter(const DropData& drop_data,
[email protected]310ebd6302011-10-10 19:06:283176 const gfx::Point& client_point,
3177 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:423178 WebDragOperationsMask ops,
3179 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:553180 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]dc293a72013-07-01 11:11:223181 DropDataToWebDragData(drop_data),
[email protected]59f4f2fa2011-03-23 01:00:553182 client_point,
3183 screen_point,
[email protected]1f2230b2012-05-17 23:43:423184 ops,
3185 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:553186
3187 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3188}
3189
[email protected]310ebd6302011-10-10 19:06:283190void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
3191 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:423192 WebDragOperationsMask ops,
3193 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:553194 WebDragOperation operation = webview()->dragTargetDragOver(
3195 client_point,
3196 screen_point,
[email protected]1f2230b2012-05-17 23:43:423197 ops,
3198 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:553199
3200 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3201}
3202
[email protected]310ebd6302011-10-10 19:06:283203void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:553204 webview()->dragTargetDragLeave();
3205}
3206
[email protected]310ebd6302011-10-10 19:06:283207void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
[email protected]1f2230b2012-05-17 23:43:423208 const gfx::Point& screen_point,
3209 int key_modifiers) {
3210 webview()->dragTargetDrop(client_point, screen_point, key_modifiers);
[email protected]fcad49452011-06-28 17:11:573211
3212 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:553213}
3214
[email protected]7a6d773f2014-04-04 01:25:093215void RenderViewImpl::OnDragSourceEnded(const gfx::Point& client_point,
3216 const gfx::Point& screen_point,
3217 WebDragOperation op) {
3218 webview()->dragSourceEndedAt(client_point, screen_point, op);
initial.commit09911bf2008-07-26 23:55:293219}
3220
[email protected]310ebd6302011-10-10 19:06:283221void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273222 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293223}
3224
[email protected]310ebd6302011-10-10 19:06:283225void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593226 webkit_preferences_ = prefs;
[email protected]49a20002013-08-18 12:43:313227 ApplyWebPreferences(webkit_preferences_, webview());
initial.commit09911bf2008-07-26 23:55:293228}
3229
[email protected]310ebd6302011-10-10 19:06:283230void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:513231 int id,
[email protected]c42de732013-02-16 06:26:313232 const std::vector<base::FilePath>& paths) {
[email protected]600ea402011-04-12 00:01:513233 if (!enumeration_completions_[id])
3234 return;
3235
3236 WebVector<WebString> ws_file_names(paths.size());
3237 for (size_t i = 0; i < paths.size(); ++i)
[email protected]728c2ee2013-06-25 04:01:073238 ws_file_names[i] = paths[i].AsUTF16Unsafe();
[email protected]600ea402011-04-12 00:01:513239
3240 enumeration_completions_[id]->didChooseFile(ws_file_names);
3241 enumeration_completions_.erase(id);
3242}
3243
[email protected]fb11b6a42012-03-14 07:25:123244void RenderViewImpl::OnFileChooserResponse(
[email protected]ddb034b2012-06-26 20:31:393245 const std::vector<ui::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:363246 // This could happen if we navigated to a different page before the user
3247 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473248 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363249 return;
3250
[email protected]b5188522012-03-15 00:18:043251 // Convert Chrome's SelectedFileInfo list to WebKit's.
3252 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
3253 files.size());
3254 for (size_t i = 0; i < files.size(); ++i) {
3255 WebFileChooserCompletion::SelectedFileInfo selected_file;
[email protected]728c2ee2013-06-25 04:01:073256 selected_file.path = files[i].local_path.AsUTF16Unsafe();
3257 selected_file.displayName =
3258 base::FilePath(files[i].display_name).AsUTF16Unsafe();
[email protected]b5188522012-03-15 00:18:043259 selected_files[i] = selected_file;
3260 }
[email protected]a1128322009-10-06 18:38:463261
[email protected]cdaf8d02010-03-30 19:52:473262 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:043263 file_chooser_completions_.front()->completion->didChooseFile(
3264 selected_files);
[email protected]cdaf8d02010-03-30 19:52:473265 file_chooser_completions_.pop_front();
3266
3267 // If there are more pending file chooser requests, schedule one now.
3268 if (!file_chooser_completions_.empty()) {
3269 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3270 file_chooser_completions_.front()->params));
3271 }
initial.commit09911bf2008-07-26 23:55:293272}
3273
[email protected]244ac1892011-12-02 17:04:473274void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
3275 const gfx::Size& max_size) {
3276 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
3277 if (!webview())
3278 return;
[email protected]97e1bf72013-03-06 14:06:053279 auto_resize_mode_ = true;
[email protected]61e2b3cc2012-03-02 16:13:343280 webview()->enableAutoResizeMode(min_size, max_size);
3281}
3282
3283void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
3284 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
3285 if (!webview())
3286 return;
[email protected]97e1bf72013-03-06 14:06:053287 auto_resize_mode_ = false;
[email protected]61e2b3cc2012-03-02 16:13:343288 webview()->disableAutoResizeMode();
3289
[email protected]eac2b362013-05-22 07:01:453290 if (!new_size.IsEmpty()) {
3291 Resize(new_size,
3292 physical_backing_size_,
3293 overdraw_bottom_height_,
3294 resizer_rect_,
3295 is_fullscreen_,
3296 NO_RESIZE_ACK);
3297 }
[email protected]244ac1892011-12-02 17:04:473298}
3299
[email protected]2bf834f2011-11-17 20:02:213300void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:243301 if (send_preferred_size_changes_)
3302 return;
[email protected]9fb325e2010-05-06 18:23:243303 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393304
[email protected]d812fd12011-05-27 23:05:073305 // Start off with an initial preferred size notification (in case
3306 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:593307 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:083308}
3309
[email protected]310ebd6302011-10-10 19:06:283310void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:103311 const gfx::Size& disable_scrollbar_size_limit) {
3312 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3313}
3314
[email protected]310ebd6302011-10-10 19:06:283315void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:263316 const RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:503317 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:513318 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373319 UpdateFontRenderingFromRendererPrefs();
[email protected]38a85712013-01-02 22:45:023320
[email protected]dcc297772014-04-10 22:20:523321#if defined(USE_DEFAULT_RENDER_THEME)
[email protected]1596efb2013-01-17 22:13:013322 if (renderer_prefs.use_custom_colors) {
[email protected]180ef242013-11-07 06:50:463323 WebColorName name = blink::WebColorWebkitFocusRingColor;
3324 blink::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
3325 blink::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]1596efb2013-01-17 22:13:013326
3327 if (webview()) {
[email protected]1596efb2013-01-17 22:13:013328 webview()->setSelectionColors(
3329 renderer_prefs.active_selection_bg_color,
3330 renderer_prefs.active_selection_fg_color,
3331 renderer_prefs.inactive_selection_bg_color,
3332 renderer_prefs.inactive_selection_fg_color);
3333 webview()->themeChanged();
3334 }
[email protected]644d77e2010-01-27 01:03:103335 }
[email protected]38a85712013-01-02 22:45:023336#endif // defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK)
[email protected]d299d972012-03-23 02:26:553337
[email protected]107c0532013-02-06 02:34:093338 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
3339 RenderThreadImpl::current()->SetFlingCurveParameters(
3340 renderer_prefs.touchpad_fling_profile,
3341 renderer_prefs.touchscreen_fling_profile);
3342
[email protected]d051d9a2011-12-10 02:02:503343 // If the zoom level for this page matches the old zoom default, and this
3344 // is not a plugin, update the zoom level to match the new default.
3345 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
[email protected]cbe55d22013-02-14 17:04:333346 !ZoomValuesEqual(old_zoom_level,
3347 renderer_preferences_.default_zoom_level) &&
[email protected]e9ff79c2012-10-19 21:31:263348 ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
[email protected]91219702013-09-18 07:33:513349 webview()->setZoomLevel(renderer_preferences_.default_zoom_level);
[email protected]d051d9a2011-12-10 02:02:503350 zoomLevelChanged();
3351 }
[email protected]80d96fa2009-06-10 22:34:513352}
3353
[email protected]310ebd6302011-10-10 19:06:283354void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
3355 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:283356 if (webview())
3357 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563358}
3359
[email protected]77829642012-05-15 14:47:173360void RenderViewImpl::OnOrientationChangeEvent(int orientation) {
[email protected]a794f3a2013-10-30 17:00:323361 // Screen has rotated. 0 = default (portrait), 90 = one turn right, and so on.
[email protected]652ad832013-08-16 11:47:043362 FOR_EACH_OBSERVER(RenderViewObserver,
3363 observers_,
3364 OrientationChangeEvent(orientation));
[email protected]77829642012-05-15 14:47:173365 webview()->mainFrame()->sendOrientationChangeEvent(orientation);
3366}
3367
[email protected]81375e872012-01-11 21:40:363368void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
3369 const WebPluginAction& action) {
3370 if (webview())
3371 webview()->performPluginAction(action, location);
3372}
3373
[email protected]310ebd6302011-10-10 19:06:283374void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:193375 const GURL& page_url) {
3376 // Prepare list to storage all savable resource links.
3377 std::vector<GURL> resources_list;
[email protected]c2d986512012-05-12 00:22:463378 std::vector<GURL> referrer_urls_list;
[email protected]180ef242013-11-07 06:50:463379 std::vector<blink::WebReferrerPolicy> referrer_policies_list;
[email protected]18d5be92011-07-25 18:00:193380 std::vector<GURL> frames_list;
[email protected]12a936d2013-05-15 04:55:493381 SavableResourcesResult result(&resources_list,
3382 &referrer_urls_list,
3383 &referrer_policies_list,
3384 &frames_list);
[email protected]18d5be92011-07-25 18:00:193385
[email protected]e9ff79c2012-10-19 21:31:263386 // webkit/ doesn't know about Referrer.
[email protected]12a936d2013-05-15 04:55:493387 if (!GetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:193388 webview(),
3389 page_url,
3390 &result,
[email protected]e9ff79c2012-10-19 21:31:263391 const_cast<const char**>(GetSavableSchemes()))) {
[email protected]18d5be92011-07-25 18:00:193392 // If something is wrong when collecting all savable resource links,
3393 // send empty list to embedder(browser) to tell it failed.
[email protected]c2d986512012-05-12 00:22:463394 referrer_urls_list.clear();
3395 referrer_policies_list.clear();
[email protected]18d5be92011-07-25 18:00:193396 resources_list.clear();
3397 frames_list.clear();
3398 }
3399
[email protected]e9ff79c2012-10-19 21:31:263400 std::vector<Referrer> referrers_list;
[email protected]c2d986512012-05-12 00:22:463401 CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size());
3402 for (unsigned i = 0; i < referrer_urls_list.size(); ++i) {
3403 referrers_list.push_back(
[email protected]e9ff79c2012-10-19 21:31:263404 Referrer(referrer_urls_list[i], referrer_policies_list[i]));
[email protected]c2d986512012-05-12 00:22:463405 }
3406
[email protected]18d5be92011-07-25 18:00:193407 // Send result of all savable resource links to embedder.
3408 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
3409 resources_list,
3410 referrers_list,
3411 frames_list));
3412}
3413
[email protected]310ebd6302011-10-10 19:06:283414void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:193415 const std::vector<GURL>& links,
[email protected]c42de732013-02-16 06:26:313416 const std::vector<base::FilePath>& local_paths,
3417 const base::FilePath& local_directory_name) {
[email protected]18d5be92011-07-25 18:00:193418
3419 // Convert std::vector of GURLs to WebVector<WebURL>
3420 WebVector<WebURL> weburl_links(links);
3421
[email protected]728c2ee2013-06-25 04:01:073422 // Convert std::vector of base::FilePath to WebVector<WebString>
[email protected]18d5be92011-07-25 18:00:193423 WebVector<WebString> webstring_paths(local_paths.size());
3424 for (size_t i = 0; i < local_paths.size(); i++)
[email protected]728c2ee2013-06-25 04:01:073425 webstring_paths[i] = local_paths[i].AsUTF16Unsafe();
[email protected]18d5be92011-07-25 18:00:193426
[email protected]35b2a972014-04-04 15:50:223427 WebPageSerializer::serialize(webview()->mainFrame()->toWebLocalFrame(),
3428 true,
3429 this,
3430 weburl_links,
[email protected]18d5be92011-07-25 18:00:193431 webstring_paths,
[email protected]728c2ee2013-06-25 04:01:073432 local_directory_name.AsUTF16Unsafe());
[email protected]18d5be92011-07-25 18:00:193433}
3434
[email protected]88f10a22013-11-06 21:22:123435void RenderViewImpl::OnSuppressDialogsUntilSwapOut() {
3436 // Don't show any more dialogs until we finish OnSwapOut.
3437 suppress_dialogs_until_swap_out_ = true;
3438}
3439
[email protected]180ef242013-11-07 06:50:463440void RenderViewImpl::NavigateToSwappedOutURL(blink::WebFrame* frame) {
[email protected]14392a52012-05-02 20:28:443441 // We use loadRequest instead of loadHTMLString because the former commits
3442 // synchronously. Otherwise a new navigation can interrupt the navigation
[email protected]e9ff79c2012-10-19 21:31:263443 // to kSwappedOutURL. If that happens to be to the page we had been
[email protected]14392a52012-05-02 20:28:443444 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]b70da4c2014-01-06 19:57:093445 // TODO(creis): Until we move this to RenderFrame, we may call this from a
3446 // swapped out RenderFrame while our own is_swapped_out_ is false.
[email protected]a5ac6dc2014-01-15 07:02:143447 RenderFrameImpl* rf = RenderFrameImpl::FromWebFrame(frame);
[email protected]b70da4c2014-01-06 19:57:093448 CHECK(is_swapped_out_ || rf->is_swapped_out());
[email protected]e9ff79c2012-10-19 21:31:263449 GURL swappedOutURL(kSwappedOutURL);
[email protected]14392a52012-05-02 20:28:443450 WebURLRequest request(swappedOutURL);
[email protected]0720b532012-08-28 19:23:373451 frame->loadRequest(request);
[email protected]14392a52012-05-02 20:28:443452}
3453
[email protected]310ebd6302011-10-10 19:06:283454void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:373455 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:293456 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3457 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3458 // in the onunload handler from appearing. For now, we're bypassing that and
3459 // calling the FrameLoader's CloseURL method directly. This should be
3460 // revisited to avoid having two ways to close a page. Having a single way
3461 // to close that can run onunload is also useful for fixing
3462 // http://b/issue?id=753080.
[email protected]11fd5db2014-04-02 03:49:463463 webview()->mainFrame()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293464
[email protected]992db4c2011-05-12 15:37:153465 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:293466}
3467
[email protected]310ebd6302011-10-10 19:06:283468void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:023469#if defined(USE_AURA)
3470 // Aura doesn't care if we switch themes.
3471#elif defined(OS_WIN)
[email protected]f78452f2012-05-15 02:07:523472 ui::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:463473 if (webview())
3474 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:573475#else // defined(OS_WIN)
3476 // TODO(port): we don't support theming on non-Windows platforms yet
3477 NOTIMPLEMENTED();
3478#endif
initial.commit09911bf2008-07-26 23:55:293479}
3480
[email protected]310ebd6302011-10-10 19:06:283481void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:003482 if (webview())
[email protected]a72a1fa2010-05-03 22:18:473483 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:003484}
3485
[email protected]0fdd5012013-05-29 08:05:563486void RenderViewImpl::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]cda45c02010-02-25 19:28:103487 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:473488 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:103489 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:203490 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]0fdd5012013-05-29 08:05:563491 ShouldDisplayScrollbars(params.new_size.width(),
3492 params.new_size.height()));
[email protected]cda45c02010-02-25 19:28:103493 }
[email protected]dd6afca2011-08-13 03:44:313494 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:103495 }
3496
[email protected]0fdd5012013-05-29 08:05:563497 RenderWidget::OnResize(params);
[email protected]30f75e62009-02-25 22:01:003498}
[email protected]0aa477bd2009-03-23 22:21:433499
[email protected]310ebd6302011-10-10 19:06:283500void RenderViewImpl::DidInitiatePaint() {
[email protected]ea2fb972013-08-07 05:44:263501#if defined(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:573502 // Notify all instances that we painted. The same caveats apply as for
3503 // ViewFlushedPaint regarding instances closing themselves, so we take
3504 // similar precautions.
3505 PepperPluginSet plugins = active_pepper_instances_;
3506 for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) {
3507 if (active_pepper_instances_.find(*i) != active_pepper_instances_.end())
3508 (*i)->ViewInitiatedPaint();
3509 }
[email protected]ea2fb972013-08-07 05:44:263510#endif
[email protected]00c39612010-03-06 02:53:283511}
3512
[email protected]310ebd6302011-10-10 19:06:283513void RenderViewImpl::DidFlushPaint() {
[email protected]ea2fb972013-08-07 05:44:263514#if defined(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:573515 // Notify all instances that we flushed. This will call into the plugin, and
3516 // we it may ask to close itself as a result. This will, in turn, modify our
3517 // set, possibly invalidating the iterator. So we iterate on a copy that
3518 // won't change out from under us.
3519 PepperPluginSet plugins = active_pepper_instances_;
3520 for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) {
3521 // The copy above makes sure our iterator is never invalid if some plugins
3522 // are destroyed. But some plugin may decide to close all of its views in
3523 // response to a paint in one of them, so we need to make sure each one is
3524 // still "current" before using it.
3525 //
3526 // It's possible that a plugin was destroyed, but another one was created
3527 // with the same address. In this case, we'll call ViewFlushedPaint on that
3528 // new plugin. But that's OK for this particular case since we're just
3529 // notifying all of our instances that the view flushed, and the new one is
3530 // one of our instances.
3531 //
3532 // What about the case where a new one is created in a callback at a new
3533 // address and we don't issue the callback? We're still OK since this
3534 // callback is used for flush callbacks and we could not have possibly
3535 // started a new paint for the new plugin while processing a previous paint
3536 // for an existing one.
3537 if (active_pepper_instances_.find(*i) != active_pepper_instances_.end())
3538 (*i)->ViewFlushedPaint();
3539 }
[email protected]ea2fb972013-08-07 05:44:263540#endif
[email protected]53900d52010-06-16 04:25:013541
[email protected]5b1dec8c2012-02-07 04:35:383542 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
3543 // See crbug.com/112921.
3544 if (!webview())
3545 return;
3546
[email protected]00c39612010-03-06 02:53:283547 WebFrame* main_frame = webview()->mainFrame();
3548
3549 // If we have a provisional frame we are between the start and commit stages
3550 // of loading and we don't want to save stats.
3551 if (!main_frame->provisionalDataSource()) {
3552 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:073553 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]92d457802013-04-01 19:18:493554 InternalDocumentStateData* data =
[email protected]e20b88d2013-04-09 15:28:373555 InternalDocumentStateData::FromDocumentState(document_state);
[email protected]92d457802013-04-01 19:18:493556 if (data->did_first_visually_non_empty_layout() &&
3557 !data->did_first_visually_non_empty_paint()) {
3558 data->set_did_first_visually_non_empty_paint(true);
3559 Send(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_,
3560 page_id_));
3561 }
3562
[email protected]05c8e502010-08-15 15:13:523563 // TODO(jar): The following code should all be inside a method, probably in
3564 // NavigatorState.
[email protected]00c39612010-03-06 02:53:283565 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:073566 if (document_state->first_paint_time().is_null()) {
3567 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:283568 }
[email protected]007733c2011-11-17 00:34:073569 if (document_state->first_paint_after_load_time().is_null() &&
3570 !document_state->finish_load_time().is_null()) {
3571 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:283572 }
3573 }
3574}
3575
[email protected]ceb36f7d2012-10-31 18:33:243576gfx::Vector2d RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:073577 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]ceb36f7d2012-10-31 18:33:243578 return gfx::Vector2d(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:523579}
3580
[email protected]ab6c9112014-02-27 00:20:583581void RenderViewImpl::OnClearFocusedElement() {
[email protected]05d478752009-04-08 23:38:163582 if (webview())
[email protected]ab6c9112014-02-27 00:20:583583 webview()->clearFocusedElement();
[email protected]05d478752009-04-08 23:38:163584}
3585
[email protected]310ebd6302011-10-10 19:06:283586void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:143587 if (webview())
[email protected]b4bb2502009-10-01 22:35:273588 webview()->setIsTransparent(!background.empty());
[email protected]ba91a792013-02-06 09:48:283589 if (compositor_)
3590 compositor_->setHasTransparentBackground(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143591
3592 SetBackground(background);
3593}
3594
[email protected]bfa71242014-03-27 21:10:243595void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) {
[email protected]2a84f9d2012-06-05 21:50:433596 if (accessibility_mode_ == new_mode)
3597 return;
3598 accessibility_mode_ = new_mode;
3599 if (renderer_accessibility_) {
3600 delete renderer_accessibility_;
3601 renderer_accessibility_ = NULL;
3602 }
[email protected]1e558fa2014-02-12 23:28:523603 if (accessibility_mode_ == AccessibilityModeOff)
3604 return;
3605
[email protected]bfa71242014-03-27 21:10:243606 if (accessibility_mode_ & AccessibilityModeFlagFullTree)
[email protected]2a84f9d2012-06-05 21:50:433607 renderer_accessibility_ = new RendererAccessibilityComplete(this);
[email protected]8d3dfee62013-06-19 05:50:333608#if !defined(OS_ANDROID)
[email protected]1e558fa2014-02-12 23:28:523609 else
[email protected]2a84f9d2012-06-05 21:50:433610 renderer_accessibility_ = new RendererAccessibilityFocusOnly(this);
[email protected]8d3dfee62013-06-19 05:50:333611#endif
[email protected]2a84f9d2012-06-05 21:50:433612}
3613
[email protected]310ebd6302011-10-10 19:06:283614void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:343615 if (webview())
[email protected]b4bb2502009-10-01 22:35:273616 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:263617
[email protected]a80af12e2013-08-07 23:36:133618#if defined(ENABLE_PLUGINS) && defined(OS_MACOSX)
[email protected]d8fd6fa2010-02-01 15:54:263619 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3620 for (plugin_it = plugin_delegates_.begin();
3621 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3622 (*plugin_it)->SetWindowFocus(active);
3623 }
3624#endif
[email protected]8c66c5a2009-07-22 17:26:343625}
3626
[email protected]6ce7abc52010-02-02 18:40:143627#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:283628void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]a80af12e2013-08-07 23:36:133629#if defined(ENABLE_PLUGINS)
[email protected]6ce7abc52010-02-02 18:40:143630 // Inform plugins that their container has changed visibility.
3631 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3632 for (plugin_it = plugin_delegates_.begin();
3633 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3634 (*plugin_it)->SetContainerVisibility(visible);
3635 }
[email protected]a80af12e2013-08-07 23:36:133636#endif
[email protected]6ce7abc52010-02-02 18:40:143637}
[email protected]1e6e3c992010-02-08 15:52:133638
[email protected]310ebd6302011-10-10 19:06:283639void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
3640 const gfx::Rect& view_frame) {
[email protected]a80af12e2013-08-07 23:36:133641#if defined(ENABLE_PLUGINS)
[email protected]1e6e3c992010-02-08 15:52:133642 // Inform plugins that their window's frame has changed.
3643 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3644 for (plugin_it = plugin_delegates_.begin();
3645 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3646 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
3647 }
[email protected]a80af12e2013-08-07 23:36:133648#endif
[email protected]1e6e3c992010-02-08 15:52:133649}
[email protected]935d63d2010-10-15 23:31:553650
[email protected]fcf75d42013-12-03 20:11:263651void RenderViewImpl::OnPluginImeCompositionCompleted(const base::string16& text,
[email protected]310ebd6302011-10-10 19:06:283652 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:133653 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:553654 // applies to it or not, so inform all the delegates.
3655 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3656 for (plugin_it = plugin_delegates_.begin();
3657 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:133658 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:553659 }
3660}
[email protected]6ce7abc52010-02-02 18:40:143661#endif // OS_MACOSX
3662
[email protected]310ebd6302011-10-10 19:06:283663void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:593664 // We need to grab a pointer to the doomed WebView before we destroy it.
3665 WebView* doomed = webview();
3666 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:493667 g_view_map.Get().erase(doomed);
[email protected]058561b2012-12-03 06:48:223668 g_routing_id_view_map.Get().erase(routing_id_);
[email protected]60c42a8c72009-10-09 04:08:593669}
3670
[email protected]310ebd6302011-10-10 19:06:283671void RenderViewImpl::DidHandleKeyEvent() {
[email protected]b2324b092012-11-01 10:34:113672 ClearEditCommands();
[email protected]446705872009-09-10 07:22:483673}
3674
[email protected]72aee842014-02-20 19:41:413675void RenderViewImpl::WillProcessUserGesture() {
3676 FOR_EACH_OBSERVER(
3677 RenderViewObserver, observers_, WillProcessUserGesture());
3678}
3679
[email protected]180ef242013-11-07 06:50:463680bool RenderViewImpl::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]41d86852012-11-07 12:23:243681 possible_drag_event_info_.event_source =
3682 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
3683 possible_drag_event_info_.event_location =
3684 gfx::Point(event.globalX, event.globalY);
[email protected]ea2fb972013-08-07 05:44:263685
3686#if defined(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:573687 // This method is called for every mouse event that the render view receives.
3688 // And then the mouse event is forwarded to WebKit, which dispatches it to the
3689 // event target. Potentially a Pepper plugin will receive the event.
3690 // In order to tell whether a plugin gets the last mouse event and which it
3691 // is, we set |pepper_last_mouse_event_target_| to NULL here. If a plugin gets
3692 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
3693 // |pepper_last_mouse_event_target_|.
3694 pepper_last_mouse_event_target_ = NULL;
[email protected]ea2fb972013-08-07 05:44:263695#endif
[email protected]217690d2012-01-27 07:33:113696
3697 // If the mouse is locked, only the current owner of the mouse lock can
3698 // process mouse events.
3699 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:373700}
3701
[email protected]41d86852012-11-07 12:23:243702bool RenderViewImpl::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:463703 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:243704 possible_drag_event_info_.event_source =
3705 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
3706 possible_drag_event_info_.event_location =
3707 gfx::Point(event.globalX, event.globalY);
3708 return false;
3709}
3710
[email protected]2b942c332012-04-25 16:26:263711void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:513712 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:063713}
3714
[email protected]310ebd6302011-10-10 19:06:283715void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:243716 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
3717}
3718
[email protected]3d5c243b2012-11-30 00:26:013719bool RenderViewImpl::HasTouchEventHandlersAt(const gfx::Point& point) const {
3720 if (!webview())
3721 return false;
3722 return webview()->hasTouchEventHandlersAt(point);
3723}
3724
[email protected]310ebd6302011-10-10 19:06:283725void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:433726 RenderWidget::OnWasHidden();
3727
[email protected]68877c282013-09-20 05:52:423728#if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
[email protected]6392d982013-04-16 16:59:223729 RenderThreadImpl::current()->video_capture_impl_manager()->
3730 SuspendDevices(true);
3731#endif
[email protected]2d7b82c2012-06-01 05:57:503732
[email protected]8869d392013-05-07 15:34:263733 if (webview())
[email protected]f59203a2011-06-07 10:01:443734 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:073735
[email protected]ea2fb972013-08-07 05:44:263736#if defined(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:573737 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
3738 i != active_pepper_instances_.end(); ++i)
3739 (*i)->PageVisibilityChanged(false);
[email protected]204f1df2012-01-04 20:21:133740
[email protected]a6939ca42011-02-18 17:58:073741#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:133742 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:433743 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3744 for (plugin_it = plugin_delegates_.begin();
3745 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3746 (*plugin_it)->SetContainerVisibility(false);
3747 }
[email protected]a6939ca42011-02-18 17:58:073748#endif // OS_MACOSX
[email protected]a80af12e2013-08-07 23:36:133749#endif // ENABLE_PLUGINS
[email protected]941e4552010-02-01 21:23:433750}
3751
[email protected]9e2e4632012-07-27 16:38:413752void RenderViewImpl::OnWasShown(bool needs_repainting) {
3753 RenderWidget::OnWasShown(needs_repainting);
[email protected]941e4552010-02-01 21:23:433754
[email protected]6392d982013-04-16 16:59:223755#if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
3756 RenderThreadImpl::current()->video_capture_impl_manager()->
3757 SuspendDevices(false);
3758#endif
3759
[email protected]8869d392013-05-07 15:34:263760 if (webview())
[email protected]f59203a2011-06-07 10:01:443761 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:073762
[email protected]ea2fb972013-08-07 05:44:263763#if defined(ENABLE_PLUGINS)
[email protected]a99a38802014-01-14 15:46:573764 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
3765 i != active_pepper_instances_.end(); ++i)
3766 (*i)->PageVisibilityChanged(true);
[email protected]204f1df2012-01-04 20:21:133767
[email protected]a6939ca42011-02-18 17:58:073768#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:133769 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:433770 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3771 for (plugin_it = plugin_delegates_.begin();
3772 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3773 (*plugin_it)->SetContainerVisibility(true);
3774 }
[email protected]784ea1ab2010-09-18 00:02:343775#endif // OS_MACOSX
[email protected]a80af12e2013-08-07 23:36:133776#endif // ENABLE_PLUGINS
[email protected]a6939ca42011-02-18 17:58:073777}
[email protected]1e6e3c992010-02-08 15:52:133778
[email protected]ed7defa2013-03-12 21:29:593779GURL RenderViewImpl::GetURLForGraphicsContext3D() {
3780 DCHECK(webview());
3781 if (webview()->mainFrame())
3782 return GURL(webview()->mainFrame()->document().url());
3783 else
3784 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]65225772011-05-12 21:10:243785}
3786
[email protected]479b0172012-10-29 19:27:093787bool RenderViewImpl::ForceCompositingModeEnabled() {
3788 return webkit_preferences_.force_compositing_mode;
3789}
3790
[email protected]310ebd6302011-10-10 19:06:283791void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:133792 RenderWidget::OnSetFocus(enable);
3793
[email protected]a80af12e2013-08-07 23:36:133794#if defined(ENABLE_PLUGINS)
[email protected]7d3c02c2010-05-05 23:10:313795 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:073796 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:133797 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3798 for (plugin_it = plugin_delegates_.begin();
3799 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:343800#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:313801 // RenderWidget's call to setFocus can cause the underlying webview's
3802 // activation state to change just like a call to setIsActive.
3803 if (enable)
3804 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:343805#endif
[email protected]7d3c02c2010-05-05 23:10:313806 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:133807 }
3808 }
[email protected]a99a38802014-01-14 15:46:573809 // Notify all Pepper plugins.
3810 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
3811 i != active_pepper_instances_.end(); ++i)
3812 (*i)->SetContentAreaFocus(enable);
[email protected]ea2fb972013-08-07 05:44:263813#endif
[email protected]321032992012-11-08 01:01:273814 // Notify all BrowserPlugins of the RenderView's focus state.
[email protected]fc72bb12013-06-02 21:13:463815 if (browser_plugin_manager_.get())
[email protected]caaf2482013-05-01 20:33:323816 browser_plugin_manager_->UpdateFocusState();
[email protected]1e6e3c992010-02-08 15:52:133817}
[email protected]941e4552010-02-01 21:23:433818
[email protected]310ebd6302011-10-10 19:06:283819void RenderViewImpl::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:263820 const base::string16& text,
[email protected]180ef242013-11-07 06:50:463821 const std::vector<blink::WebCompositionUnderline>& underlines,
[email protected]56ea1a62011-05-30 07:05:573822 int selection_start,
3823 int selection_end) {
[email protected]ea2fb972013-08-07 05:44:263824#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083825 if (focused_pepper_plugin_) {
3826 focused_pepper_plugin_->render_frame()->OnImeSetComposition(
[email protected]7a4e2532013-12-02 21:30:023827 text, underlines, selection_start, selection_end);
[email protected]ea2fb972013-08-07 05:44:263828 return;
[email protected]56ea1a62011-05-30 07:05:573829 }
[email protected]ea2fb972013-08-07 05:44:263830
3831#if defined(OS_WIN)
3832 // When a plug-in has focus, we create platform-specific IME data used by
3833 // our IME emulator and send it directly to the focused plug-in, i.e. we
3834 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
3835 // instance ID is the same one as the specified ID.)
3836 if (focused_plugin_id_ >= 0) {
3837 std::vector<int> clauses;
3838 std::vector<int> target;
3839 for (size_t i = 0; i < underlines.size(); ++i) {
3840 clauses.push_back(underlines[i].startOffset);
3841 clauses.push_back(underlines[i].endOffset);
3842 if (underlines[i].thick) {
3843 target.clear();
3844 target.push_back(underlines[i].startOffset);
3845 target.push_back(underlines[i].endOffset);
3846 }
3847 }
3848 std::set<WebPluginDelegateProxy*>::iterator it;
3849 for (it = plugin_delegates_.begin(); it != plugin_delegates_.end(); ++it) {
3850 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
3851 focused_plugin_id_);
3852 }
3853 return;
3854 }
[email protected]a80af12e2013-08-07 23:36:133855#endif // OS_WIN
3856#endif // ENABLE_PLUGINS
[email protected]ea2fb972013-08-07 05:44:263857 RenderWidget::OnImeSetComposition(text,
3858 underlines,
3859 selection_start,
3860 selection_end);
[email protected]56ea1a62011-05-30 07:05:573861}
3862
[email protected]db4fc1e2013-09-06 20:01:513863void RenderViewImpl::OnImeConfirmComposition(
[email protected]fcf75d42013-12-03 20:11:263864 const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:513865 const gfx::Range& replacement_range,
3866 bool keep_selection) {
[email protected]ea2fb972013-08-07 05:44:263867#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083868 if (focused_pepper_plugin_) {
3869 focused_pepper_plugin_->render_frame()->OnImeConfirmComposition(
[email protected]7a4e2532013-12-02 21:30:023870 text, replacement_range, keep_selection);
[email protected]ea2fb972013-08-07 05:44:263871 return;
[email protected]56ea1a62011-05-30 07:05:573872 }
[email protected]ea2fb972013-08-07 05:44:263873#if defined(OS_WIN)
3874 // Same as OnImeSetComposition(), we send the text from IMEs directly to
3875 // plug-ins. When we send IME text directly to plug-ins, we should not send
3876 // it to WebKit to prevent WebKit from controlling IMEs.
3877 // TODO(thakis): Honor |replacement_range| for plugins?
3878 if (focused_plugin_id_ >= 0) {
3879 std::set<WebPluginDelegateProxy*>::iterator it;
3880 for (it = plugin_delegates_.begin();
3881 it != plugin_delegates_.end(); ++it) {
3882 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
3883 }
3884 return;
3885 }
[email protected]a80af12e2013-08-07 23:36:133886#endif // OS_WIN
3887#endif // ENABLE_PLUGINS
[email protected]ea2fb972013-08-07 05:44:263888 if (replacement_range.IsValid() && webview()) {
3889 // Select the text in |replacement_range|, it will then be replaced by
3890 // text added by the call to RenderWidget::OnImeConfirmComposition().
[email protected]35b2a972014-04-04 15:50:223891 if (WebLocalFrame* frame = webview()->focusedFrame()->toWebLocalFrame()) {
[email protected]ea2fb972013-08-07 05:44:263892 WebRange webrange = WebRange::fromDocumentRange(
3893 frame, replacement_range.start(), replacement_range.length());
3894 if (!webrange.isNull())
3895 frame->selectRange(webrange);
3896 }
3897 }
3898 RenderWidget::OnImeConfirmComposition(text,
3899 replacement_range,
3900 keep_selection);
[email protected]56ea1a62011-05-30 07:05:573901}
3902
[email protected]468ac582012-11-20 00:53:193903void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor) {
3904 RenderWidget::SetDeviceScaleFactor(device_scale_factor);
[email protected]fb854192013-02-06 01:30:043905 if (webview()) {
[email protected]dea5e7682012-06-14 05:21:243906 webview()->setDeviceScaleFactor(device_scale_factor);
[email protected]fb854192013-02-06 01:30:043907 webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled(
3908 ShouldUseFixedPositionCompositing(device_scale_factor_));
[email protected]c162ced82013-06-29 01:24:533909 webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled(
3910 ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_));
[email protected]d8221b22013-05-23 05:35:433911 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
3912 ShouldUseTransitionCompositing(device_scale_factor_));
[email protected]06fc4d3b2013-07-08 21:07:243913 webview()->settings()->
3914 setAcceleratedCompositingForFixedRootBackgroundEnabled(
3915 ShouldUseAcceleratedFixedRootBackground(device_scale_factor_));
[email protected]e3415902013-10-17 15:00:463916 webview()->settings()->setAcceleratedCompositingForScrollableFramesEnabled(
3917 ShouldUseAcceleratedCompositingForScrollableFrames(
3918 device_scale_factor_));
3919 webview()->settings()->setCompositedScrollingForFramesEnabled(
3920 ShouldUseCompositedScrollingForFrames(device_scale_factor_));
[email protected]fb854192013-02-06 01:30:043921 }
[email protected]3a1c8a8032013-03-18 22:35:323922 if (auto_resize_mode_)
3923 AutoResizeCompositor();
[email protected]caaf2482013-05-01 20:33:323924
[email protected]fc72bb12013-06-02 21:13:463925 if (browser_plugin_manager_.get())
[email protected]caaf2482013-05-01 20:33:323926 browser_plugin_manager_->UpdateDeviceScaleFactor(device_scale_factor_);
[email protected]dea5e7682012-06-14 05:21:243927}
3928
[email protected]310ebd6302011-10-10 19:06:283929ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]ea2fb972013-08-07 05:44:263930#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083931 if (focused_pepper_plugin_)
3932 return focused_pepper_plugin_->text_input_type();
[email protected]ea2fb972013-08-07 05:44:263933#endif
3934 return RenderWidget::GetTextInputType();
[email protected]73bf95812011-10-12 11:38:323935}
3936
[email protected]3f783362011-10-21 22:40:503937void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
[email protected]ea2fb972013-08-07 05:44:263938#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083939 if (focused_pepper_plugin_) {
[email protected]3f783362011-10-21 22:40:503940 // TODO(kinaba) http://crbug.com/101101
3941 // Current Pepper IME API does not handle selection bounds. So we simply
3942 // use the caret position as an empty range for now. It will be updated
3943 // after Pepper API equips features related to surrounding text retrieval.
[email protected]e16c7a12013-12-05 16:30:083944 gfx::Rect caret = focused_pepper_plugin_->GetCaretBounds();
[email protected]3f783362011-10-21 22:40:503945 *start = caret;
3946 *end = caret;
3947 return;
3948 }
[email protected]ea2fb972013-08-07 05:44:263949#endif
[email protected]3f783362011-10-21 22:40:503950 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:453951}
3952
[email protected]501ea13d2013-07-09 17:03:293953#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
[email protected]58b48a0d2012-06-13 07:01:353954void RenderViewImpl::GetCompositionCharacterBounds(
3955 std::vector<gfx::Rect>* bounds) {
3956 DCHECK(bounds);
3957 bounds->clear();
3958
[email protected]ea2fb972013-08-07 05:44:263959#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083960 if (focused_pepper_plugin_) {
[email protected]88dbe32f2013-06-20 23:31:363961 return;
3962 }
[email protected]ea2fb972013-08-07 05:44:263963#endif
3964
[email protected]58b48a0d2012-06-13 07:01:353965 if (!webview())
3966 return;
3967 size_t start_offset = 0;
3968 size_t character_count = 0;
3969 if (!webview()->compositionRange(&start_offset, &character_count))
3970 return;
3971 if (character_count == 0)
3972 return;
3973
[email protected]180ef242013-11-07 06:50:463974 blink::WebFrame* frame = webview()->focusedFrame();
[email protected]58b48a0d2012-06-13 07:01:353975 if (!frame)
3976 return;
3977
3978 bounds->reserve(character_count);
[email protected]180ef242013-11-07 06:50:463979 blink::WebRect webrect;
[email protected]58b48a0d2012-06-13 07:01:353980 for (size_t i = 0; i < character_count; ++i) {
3981 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
3982 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
3983 bounds->clear();
3984 return;
3985 }
3986 bounds->push_back(webrect);
3987 }
3988}
3989
[email protected]db4fc1e2013-09-06 20:01:513990void RenderViewImpl::GetCompositionRange(gfx::Range* range) {
[email protected]ea2fb972013-08-07 05:44:263991#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:083992 if (focused_pepper_plugin_) {
[email protected]88dbe32f2013-06-20 23:31:363993 return;
3994 }
[email protected]ea2fb972013-08-07 05:44:263995#endif
[email protected]88dbe32f2013-06-20 23:31:363996 RenderWidget::GetCompositionRange(range);
3997}
[email protected]501ea13d2013-07-09 17:03:293998#endif
[email protected]88dbe32f2013-06-20 23:31:363999
[email protected]310ebd6302011-10-10 19:06:284000bool RenderViewImpl::CanComposeInline() {
[email protected]ea2fb972013-08-07 05:44:264001#if defined(ENABLE_PLUGINS)
[email protected]e16c7a12013-12-05 16:30:084002 if (focused_pepper_plugin_)
4003 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
[email protected]ea2fb972013-08-07 05:44:264004#endif
4005 return true;
[email protected]56ea1a62011-05-30 07:05:574006}
4007
[email protected]33004772013-11-12 09:49:234008void RenderViewImpl::InstrumentWillBeginFrame(int frame_id) {
[email protected]35134e12013-02-22 20:07:404009 if (!webview())
4010 return;
4011 if (!webview()->devToolsAgent())
4012 return;
[email protected]33004772013-11-12 09:49:234013 webview()->devToolsAgent()->didBeginFrame(frame_id);
[email protected]35134e12013-02-22 20:07:404014}
4015
4016void RenderViewImpl::InstrumentDidBeginFrame() {
4017 if (!webview())
4018 return;
4019 if (!webview()->devToolsAgent())
4020 return;
4021 // TODO(jamesr/caseq): Decide if this needs to be renamed.
4022 webview()->devToolsAgent()->didComposite();
4023}
4024
4025void RenderViewImpl::InstrumentDidCancelFrame() {
4026 if (!webview())
4027 return;
4028 if (!webview()->devToolsAgent())
4029 return;
4030 webview()->devToolsAgent()->didCancelFrame();
4031}
4032
4033void RenderViewImpl::InstrumentWillComposite() {
4034 if (!webview())
4035 return;
4036 if (!webview()->devToolsAgent())
4037 return;
4038 webview()->devToolsAgent()->willComposite();
4039}
4040
[email protected]b2e4c70132013-10-03 02:07:514041void RenderViewImpl::SetScreenMetricsEmulationParameters(
[email protected]7f99fc22013-11-08 14:05:584042 float device_scale_factor,
4043 const gfx::Point& root_layer_offset,
4044 float root_layer_scale) {
[email protected]b2e4c70132013-10-03 02:07:514045 if (webview()) {
4046 webview()->setCompositorDeviceScaleFactorOverride(device_scale_factor);
[email protected]7f99fc22013-11-08 14:05:584047 webview()->setRootLayerTransform(
4048 blink::WebSize(root_layer_offset.x(), root_layer_offset.y()),
4049 root_layer_scale);
[email protected]b2e4c70132013-10-03 02:07:514050 }
4051}
4052
[email protected]310ebd6302011-10-10 19:06:284053bool RenderViewImpl::ScheduleFileChooser(
[email protected]e9ff79c2012-10-19 21:31:264054 const FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:474055 WebFileChooserCompletion* completion) {
4056 static const size_t kMaximumPendingFileChooseRequests = 4;
4057 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4058 // This sanity check prevents too many file choose requests from getting
4059 // queued which could DoS the user. Getting these is most likely a
4060 // programming error (there are many ways to DoS the user so it's not
4061 // considered a "real" security check), either in JS requesting many file
4062 // choosers to pop up, or in a plugin.
4063 //
4064 // TODO(brettw) we might possibly want to require a user gesture to open
4065 // a file picker, which will address this issue in a better way.
4066 return false;
4067 }
4068
4069 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4070 new PendingFileChooser(params, completion)));
4071 if (file_chooser_completions_.size() == 1) {
4072 // Actually show the browse dialog when this is the first request.
4073 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4074 }
4075 return true;
4076}
4077
[email protected]180ef242013-11-07 06:50:464078blink::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514079 if (!geolocation_dispatcher_)
4080 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4081 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254082}
[email protected]61c9f032010-03-31 23:04:194083
[email protected]180ef242013-11-07 06:50:464084blink::WebSpeechInputController* RenderViewImpl::speechInputController(
4085 blink::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:224086#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:024087 if (!input_tag_speech_dispatcher_)
4088 input_tag_speech_dispatcher_ =
4089 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:224090#endif
[email protected]c52b2892012-03-07 11:01:024091 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:114092}
4093
[email protected]180ef242013-11-07 06:50:464094blink::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
[email protected]64d09222012-05-25 10:10:344095 if (!speech_recognition_dispatcher_)
4096 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
[email protected]64d09222012-05-25 10:10:344097 return speech_recognition_dispatcher_;
4098}
4099
[email protected]310ebd6302011-10-10 19:06:284100void RenderViewImpl::zoomLimitsChanged(double minimum_level,
4101 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:254102 // For now, don't remember plugin zoom values. We don't want to mix them with
4103 // normal web content (i.e. a fixed layout plugin would usually want them
4104 // different).
4105 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4106
[email protected]b75b8292010-10-01 07:28:254107 int minimum_percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:494108 ZoomLevelToZoomFactor(minimum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254109 int maximum_percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:494110 ZoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254111
4112 Send(new ViewHostMsg_UpdateZoomLimits(
4113 routing_id_, minimum_percent, maximum_percent, remember));
4114}
4115
[email protected]310ebd6302011-10-10 19:06:284116void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:254117 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:084118 float zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:264119
4120 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
4121
[email protected]b75b8292010-10-01 07:28:254122 // Tell the browser which url got zoomed so it can update the menu and the
4123 // saved values if necessary
4124 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:084125 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:414126 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254127}
4128
[email protected]7940b8e2013-07-25 23:08:494129double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const {
4130 return ZoomLevelToZoomFactor(zoom_level);
4131}
4132
4133double RenderViewImpl::zoomFactorToZoomLevel(double factor) const {
4134 return ZoomFactorToZoomLevel(factor);
4135}
4136
[email protected]310ebd6302011-10-10 19:06:284137void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
[email protected]5958c6bc2014-01-22 14:48:054138 const WebURL& base_url,
4139 const WebURL& url,
[email protected]310ebd6302011-10-10 19:06:284140 const WebString& title) {
[email protected]af15bf22013-03-08 01:18:174141 bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]a6d36cc2011-02-23 00:39:484142 GURL base(base_url);
[email protected]5958c6bc2014-01-22 14:48:054143 GURL absolute_url = base.Resolve(base::UTF16ToUTF8(url.string()));
[email protected]a6d36cc2011-02-23 00:39:484144 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4145 return;
4146 }
[email protected]f1a29a02011-10-06 23:08:444147 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
[email protected]32956122013-12-25 07:29:244148 base::UTF16ToUTF8(scheme),
[email protected]f1a29a02011-10-06 23:08:444149 absolute_url,
[email protected]3a3b75a2012-06-01 08:38:364150 title,
4151 user_gesture));
[email protected]a6d36cc2011-02-23 00:39:484152}
4153
[email protected]180ef242013-11-07 06:50:464154blink::WebPageVisibilityState RenderViewImpl::visibilityState() const {
4155 blink::WebPageVisibilityState current_state = is_hidden() ?
4156 blink::WebPageVisibilityStateHidden :
4157 blink::WebPageVisibilityStateVisible;
4158 blink::WebPageVisibilityState override_state = current_state;
[email protected]b849847b2013-12-10 21:57:584159 // TODO(jam): move this method to WebFrameClient.
[email protected]e9ff79c2012-10-19 21:31:264160 if (GetContentClient()->renderer()->
[email protected]b849847b2013-12-10 21:57:584161 ShouldOverridePageVisibilityState(main_render_frame_.get(),
[email protected]f59203a2011-06-07 10:01:444162 &override_state))
4163 return override_state;
4164 return current_state;
[email protected]94dec932011-05-26 20:04:214165}
4166
[email protected]180ef242013-11-07 06:50:464167blink::WebUserMediaClient* RenderViewImpl::userMediaClient() {
[email protected]60ee79f2013-09-11 13:49:554168 // This can happen in tests, in which case it's OK to return NULL.
4169 if (!InitializeMediaStreamClient())
4170 return NULL;
4171
[email protected]c3bdce152013-07-10 04:56:344172 return web_user_media_client_;
[email protected]273558fb2012-01-12 15:03:514173}
4174
[email protected]180ef242013-11-07 06:50:464175blink::WebMIDIClient* RenderViewImpl::webMIDIClient() {
[email protected]7b77f6cb2013-07-25 16:23:144176 if (!midi_dispatcher_)
[email protected]6e068ea2014-02-04 07:05:474177 midi_dispatcher_ = new MidiDispatcher(this);
[email protected]7b77f6cb2013-07-25 16:23:144178 return midi_dispatcher_;
4179}
4180
[email protected]e1c174162014-04-08 15:39:314181blink::WebPushClient* RenderViewImpl::webPushClient() {
4182 if (!push_messaging_dispatcher_)
4183 push_messaging_dispatcher_ = new PushMessagingDispatcher(this);
4184 return push_messaging_dispatcher_;
4185}
4186
[email protected]a0629af92012-08-08 00:39:374187void RenderViewImpl::draggableRegionsChanged() {
4188 FOR_EACH_OBSERVER(
4189 RenderViewObserver,
4190 observers_,
4191 DraggableRegionsChanged(webview()->mainFrame()));
4192}
4193
[email protected]40bed812013-11-05 06:59:154194WebMediaPlayer* RenderViewImpl::CreateWebMediaPlayerForMediaStream(
4195 WebFrame* frame,
[email protected]180ef242013-11-07 06:50:464196 const blink::WebURL& url,
[email protected]40bed812013-11-05 06:59:154197 WebMediaPlayerClient* client) {
4198#if defined(ENABLE_WEBRTC)
4199 if (!InitializeMediaStreamClient()) {
4200 LOG(ERROR) << "Failed to initialize MediaStreamClient";
4201 return NULL;
4202 }
[email protected]40bed812013-11-05 06:59:154203 if (media_stream_client_->IsMediaStream(url)) {
4204#if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
4205 bool found_neon =
4206 (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
4207 UMA_HISTOGRAM_BOOLEAN("Platform.WebRtcNEONFound", found_neon);
4208#endif // defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
4209 return new WebMediaPlayerMS(frame, client, AsWeakPtr(),
4210 media_stream_client_, new RenderMediaLog());
4211 }
[email protected]40bed812013-11-05 06:59:154212#endif // defined(ENABLE_WEBRTC)
4213 return NULL;
4214}
4215
[email protected]20657a82012-08-21 20:23:034216#if defined(OS_ANDROID)
4217WebContentDetectionResult RenderViewImpl::detectContentAround(
4218 const WebHitTestResult& touch_hit) {
4219 DCHECK(!touch_hit.isNull());
4220 DCHECK(!touch_hit.node().isNull());
4221 DCHECK(touch_hit.node().isTextNode());
4222
4223 // Process the position with all the registered content detectors until
4224 // a match is found. Priority is provided by their relative order.
4225 for (ContentDetectorList::const_iterator it = content_detectors_.begin();
4226 it != content_detectors_.end(); ++it) {
4227 ContentDetector::Result content = (*it)->FindTappedContent(touch_hit);
4228 if (content.valid) {
4229 return WebContentDetectionResult(content.content_boundaries,
[email protected]32956122013-12-25 07:29:244230 base::UTF8ToUTF16(content.text), content.intent_url);
[email protected]20657a82012-08-21 20:23:034231 }
4232 }
4233 return WebContentDetectionResult();
4234}
4235
4236void RenderViewImpl::scheduleContentIntent(const WebURL& intent) {
4237 // Introduce a short delay so that the user can notice the content.
[email protected]dd32b1272013-05-04 14:17:114238 base::MessageLoop::current()->PostDelayedTask(
[email protected]20657a82012-08-21 20:23:034239 FROM_HERE,
[email protected]dd32b1272013-05-04 14:17:114240 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent,
4241 AsWeakPtr(),
4242 intent,
4243 expected_content_intent_id_),
[email protected]20657a82012-08-21 20:23:034244 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds));
4245}
4246
4247void RenderViewImpl::cancelScheduledContentIntents() {
4248 ++expected_content_intent_id_;
4249}
4250
4251void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent,
4252 size_t request_id) {
4253 if (request_id != expected_content_intent_id_)
4254 return;
4255
4256 // Remove the content highlighting if any.
[email protected]8b9e52b2014-01-17 16:35:314257 scheduleComposite();
[email protected]20657a82012-08-21 20:23:034258
4259 if (!intent.is_empty())
4260 Send(new ViewHostMsg_StartContentIntent(routing_id_, intent));
4261}
[email protected]b18583c2012-12-18 06:55:274262
4263bool RenderViewImpl::openDateTimeChooser(
[email protected]180ef242013-11-07 06:50:464264 const blink::WebDateTimeChooserParams& params,
4265 blink::WebDateTimeChooserCompletion* completion) {
[email protected]e8072562013-12-04 06:04:134266 // JavaScript may try to open a date time chooser while one is already open.
4267 if (date_time_picker_client_)
4268 return false;
[email protected]b18583c2012-12-18 06:55:274269 date_time_picker_client_.reset(
4270 new RendererDateTimePicker(this, params, completion));
4271 return date_time_picker_client_->Open();
4272}
4273
[email protected]e8072562013-12-04 06:04:134274void RenderViewImpl::DismissDateTimeDialog() {
4275 DCHECK(date_time_picker_client_);
4276 date_time_picker_client_.reset(NULL);
4277}
[email protected]e8072562013-12-04 06:04:134278
[email protected]40bed812013-11-05 06:59:154279WebMediaPlayer* RenderViewImpl::CreateAndroidWebMediaPlayer(
4280 WebFrame* frame,
[email protected]180ef242013-11-07 06:50:464281 const blink::WebURL& url,
[email protected]40bed812013-11-05 06:59:154282 WebMediaPlayerClient* client) {
4283 GpuChannelHost* gpu_channel_host =
4284 RenderThreadImpl::current()->EstablishGpuChannelSync(
4285 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
4286 if (!gpu_channel_host) {
4287 LOG(ERROR) << "Failed to establish GPU channel for media player";
4288 return NULL;
4289 }
4290
[email protected]5448f9b2014-04-01 15:21:204291 scoped_refptr<StreamTextureFactory> stream_texture_factory;
[email protected]40bed812013-11-05 06:59:154292 if (UsingSynchronousRendererCompositor()) {
4293 SynchronousCompositorFactory* factory =
4294 SynchronousCompositorFactory::GetInstance();
4295 stream_texture_factory = factory->CreateStreamTextureFactory(routing_id_);
4296 } else {
[email protected]9cdd7152014-01-14 14:20:434297 scoped_refptr<webkit::gpu::ContextProviderWebContext> context_provider =
[email protected]40bed812013-11-05 06:59:154298 RenderThreadImpl::current()->SharedMainThreadContextProvider();
4299
4300 if (!context_provider.get()) {
4301 LOG(ERROR) << "Failed to get context3d for media player";
4302 return NULL;
4303 }
4304
[email protected]5448f9b2014-04-01 15:21:204305 stream_texture_factory = StreamTextureFactoryImpl::Create(
4306 context_provider, gpu_channel_host, routing_id_);
[email protected]40bed812013-11-05 06:59:154307 }
4308
[email protected]693f63c2014-01-17 06:52:194309 return new WebMediaPlayerAndroid(
[email protected]1dd0bb752014-02-01 01:16:264310 frame,
4311 client,
4312 AsWeakPtr(),
4313 media_player_manager_,
[email protected]5448f9b2014-04-01 15:21:204314 stream_texture_factory,
[email protected]1dd0bb752014-02-01 01:16:264315 RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy(),
4316 new RenderMediaLog());
[email protected]40bed812013-11-05 06:59:154317}
4318
[email protected]6d17f6392012-12-05 05:24:544319#endif // defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:034320
[email protected]caf706f2010-10-26 17:54:084321#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284322void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]8ff26a8c2014-03-24 02:59:404323 if (external_popup_menu_ == NULL)
[email protected]68dc3ba2010-12-06 21:43:154324 return;
[email protected]caf706f2010-10-26 17:54:084325 external_popup_menu_->DidSelectItem(selected_index);
4326 external_popup_menu_.reset();
4327}
4328#endif
[email protected]bb461532010-11-26 21:50:234329
[email protected]24d2b172012-05-26 00:54:124330#if defined(OS_ANDROID)
4331void RenderViewImpl::OnSelectPopupMenuItems(
4332 bool canceled,
4333 const std::vector<int>& selected_indices) {
4334 // It is possible to receive more than one of these calls if the user presses
4335 // a select faster than it takes for the show-select-popup IPC message to make
4336 // it to the browser UI thread. Ignore the extra-messages.
4337 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug.
[email protected]59383c782013-04-17 16:43:274338 if (!external_popup_menu_)
[email protected]24d2b172012-05-26 00:54:124339 return;
4340
4341 external_popup_menu_->DidSelectItems(canceled, selected_indices);
4342 external_popup_menu_.reset();
4343}
4344#endif
4345
[email protected]53907862014-03-25 15:42:404346#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]8ff26a8c2014-03-24 02:59:404347void RenderViewImpl::DidHideExternalPopupMenu() {
4348 // We need to clear external_popup_menu_ as soon as ExternalPopupMenu::close
4349 // is called. Otherwise, createExternalPopupMenu() for new popup will fail.
4350 external_popup_menu_.reset();
4351}
[email protected]53907862014-03-25 15:42:404352#endif
[email protected]8ff26a8c2014-03-24 02:59:404353
[email protected]f56c7872013-06-18 12:31:574354void RenderViewImpl::OnShowContextMenu(const gfx::Point& location) {
[email protected]a14ddcd2013-06-21 22:53:034355 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH_EDIT_MENU;
[email protected]f56c7872013-06-18 12:31:574356 touch_editing_context_menu_location_ = location;
[email protected]47822262013-04-23 17:22:364357 if (webview())
4358 webview()->showContextMenu();
4359}
4360
[email protected]310ebd6302011-10-10 19:06:284361void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:184362 if (!webview())
4363 return;
4364 WebFrame* main_frame = webview()->mainFrame();
4365 if (!main_frame)
4366 return;
4367 main_frame->enableViewSourceMode(true);
4368}
[email protected]67bfb83f2011-09-22 03:36:374369
[email protected]7cc78902012-12-06 02:32:264370void RenderViewImpl::OnDisownOpener() {
4371 if (!webview())
4372 return;
4373
4374 WebFrame* main_frame = webview()->mainFrame();
4375 if (main_frame && main_frame->opener())
4376 main_frame->setOpener(NULL);
4377}
4378
[email protected]efd7e47f2012-10-19 20:37:514379#if defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:034380bool RenderViewImpl::didTapMultipleTargets(
[email protected]180ef242013-11-07 06:50:464381 const blink::WebGestureEvent& event,
[email protected]f9526d12012-10-18 01:55:034382 const WebVector<WebRect>& target_rects) {
[email protected]8d3dfee62013-06-19 05:50:334383 // Never show a disambiguation popup when accessibility is enabled,
4384 // as this interferes with "touch exploration".
[email protected]1e558fa2014-02-12 23:28:524385 bool matchesAccessibilityModeComplete =
4386 (accessibility_mode_ & AccessibilityModeComplete) ==
4387 AccessibilityModeComplete;
4388 if (matchesAccessibilityModeComplete)
[email protected]8d3dfee62013-06-19 05:50:334389 return false;
4390
[email protected]f9526d12012-10-18 01:55:034391 gfx::Rect finger_rect(
4392 event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2,
4393 event.data.tap.width, event.data.tap.height);
4394 gfx::Rect zoom_rect;
[email protected]70221f02013-01-31 22:17:074395 float new_total_scale =
4396 DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
4397 finger_rect, target_rects, GetSize(),
4398 gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(),
4399 device_scale_factor_ * webview()->pageScaleFactor(), &zoom_rect);
4400 if (!new_total_scale)
[email protected]f9526d12012-10-18 01:55:034401 return false;
4402
[email protected]4ded1dbf2013-08-28 21:11:034403 bool handled = false;
4404 switch (renderer_preferences_.tap_multiple_targets_strategy) {
4405 case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM:
4406 handled = webview()->zoomToMultipleTargetsRect(zoom_rect);
4407 break;
4408 case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: {
[email protected]bc2804d2013-08-06 07:45:494409 gfx::Size canvas_size =
4410 gfx::ToCeiledSize(gfx::ScaleSize(zoom_rect.size(), new_total_scale));
4411 TransportDIB* transport_dib = NULL;
4412 {
4413 scoped_ptr<skia::PlatformCanvas> canvas(
4414 RenderProcess::current()->GetDrawingCanvas(&transport_dib,
4415 gfx::Rect(canvas_size)));
[email protected]4ded1dbf2013-08-28 21:11:034416 if (!canvas) {
4417 handled = false;
4418 break;
4419 }
[email protected]f9526d12012-10-18 01:55:034420
[email protected]bc2804d2013-08-06 07:45:494421 // TODO(trchen): Cleanup the device scale factor mess.
4422 // device scale will be applied in WebKit
4423 // --> zoom_rect doesn't include device scale,
4424 // but WebKit will still draw on zoom_rect * device_scale_factor_
4425 canvas->scale(new_total_scale / device_scale_factor_,
4426 new_total_scale / device_scale_factor_);
4427 canvas->translate(-zoom_rect.x() * device_scale_factor_,
4428 -zoom_rect.y() * device_scale_factor_);
[email protected]f9526d12012-10-18 01:55:034429
[email protected]bc2804d2013-08-06 07:45:494430 webwidget_->paint(
4431 canvas.get(),
4432 zoom_rect,
4433 WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent);
4434 }
4435
4436 gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect(
4437 ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect)));
4438 Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_,
4439 physical_window_zoom_rect,
4440 canvas_size,
4441 transport_dib->id()));
[email protected]4ded1dbf2013-08-28 21:11:034442 handled = true;
4443 break;
4444 }
4445 case TAP_MULTIPLE_TARGETS_STRATEGY_NONE:
4446 // No-op.
4447 break;
[email protected]f9526d12012-10-18 01:55:034448 }
[email protected]70221f02013-01-31 22:17:074449
[email protected]4ded1dbf2013-08-28 21:11:034450 return handled;
[email protected]f9526d12012-10-18 01:55:034451}
[email protected]efd7e47f2012-10-19 20:37:514452#endif
[email protected]f9526d12012-10-18 01:55:034453
[email protected]b283d292013-02-21 08:40:344454unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
4455 return history_list_length_;
4456}
4457
[email protected]cc290f902013-03-04 20:06:024458void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
4459 if (enable) {
4460 if (has_focus())
4461 return;
4462 OnSetActive(true);
4463 OnSetFocus(true);
4464 } else {
4465 if (!has_focus())
4466 return;
4467 OnSetFocus(false);
4468 OnSetActive(false);
4469 }
4470}
4471
[email protected]3a1c8a8032013-03-18 22:35:324472void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) {
[email protected]b54fe452013-06-07 14:01:534473 ViewMsg_Resize_Params params;
4474 params.screen_info = screen_info_;
4475 params.screen_info.deviceScaleFactor = factor;
4476 params.new_size = size();
4477 params.physical_backing_size =
4478 gfx::ToCeiledSize(gfx::ScaleSize(size(), factor));
4479 params.overdraw_bottom_height = 0.f;
4480 params.resizer_rect = WebRect();
4481 params.is_fullscreen = is_fullscreen();
4482 OnResize(params);
[email protected]3a1c8a8032013-03-18 22:35:324483}
4484
[email protected]92650162013-10-30 03:31:024485void RenderViewImpl::ForceResizeForTesting(const gfx::Size& new_size) {
4486 gfx::Rect new_position(rootWindowRect().x,
4487 rootWindowRect().y,
4488 new_size.width(),
4489 new_size.height());
4490 ResizeSynchronously(new_position);
4491}
4492
[email protected]5b45ad42013-10-25 00:42:044493void RenderViewImpl::UseSynchronousResizeModeForTesting(bool enable) {
4494 resizing_mode_selector_->set_is_synchronous_mode(enable);
4495}
4496
[email protected]eac2b362013-05-22 07:01:454497void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size,
4498 const gfx::Size& max_size) {
4499 OnEnableAutoResize(min_size, max_size);
4500}
4501
4502void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) {
4503 OnDisableAutoResize(new_size);
4504}
4505
[email protected]c3bdce152013-07-10 04:56:344506void RenderViewImpl::SetMediaStreamClientForTesting(
[email protected]5e35a8d2013-07-10 19:37:214507 MediaStreamClient* media_stream_client) {
[email protected]c3bdce152013-07-10 04:56:344508 DCHECK(!media_stream_client_);
4509 DCHECK(!web_user_media_client_);
4510 media_stream_client_ = media_stream_client;
4511}
4512
[email protected]f9526d12012-10-18 01:55:034513void RenderViewImpl::OnReleaseDisambiguationPopupDIB(
4514 TransportDIB::Handle dib_handle) {
4515 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle);
4516 RenderProcess::current()->ReleaseTransportDIB(dib);
4517}
[email protected]e9ff79c2012-10-19 21:31:264518
[email protected]6fceb912013-02-15 06:24:154519void RenderViewImpl::DidCommitCompositorFrame() {
4520 RenderWidget::DidCommitCompositorFrame();
4521 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame());
4522}
4523
[email protected]41225fe2013-03-29 05:32:024524void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) {
4525 if (!urls.empty())
4526 Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, page_id_, urls));
4527}
4528
4529void RenderViewImpl::DidStopLoadingIcons() {
4530 int icon_types = WebIconURL::TypeFavicon;
4531 if (TouchEnabled())
4532 icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch;
4533
4534 WebVector<WebIconURL> icon_urls =
4535 webview()->mainFrame()->iconURLs(icon_types);
4536
4537 std::vector<FaviconURL> urls;
4538 for (size_t i = 0; i < icon_urls.size(); i++) {
4539 WebURL url = icon_urls[i].iconURL();
[email protected]f34ac132014-03-20 23:02:054540 std::vector<gfx::Size> sizes(icon_urls[i].sizes().size());
4541 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
[email protected]41225fe2013-03-29 05:32:024542 if (!url.isEmpty())
[email protected]f34ac132014-03-20 23:02:054543 urls.push_back(
4544 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes));
[email protected]41225fe2013-03-29 05:32:024545 }
4546 SendUpdateFaviconURL(urls);
4547}
4548
[email protected]e9ff79c2012-10-19 21:31:264549} // namespace content