blob: 3a41dff1c9a3ef1be7be9886e45351afacd185ab [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]28fccb32013-08-29 22:25:4618#include "base/i18n/char_iterator.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]21aa99682013-06-11 07:17:0126#include "base/strings/string_number_conversions.h"
[email protected]b9e7c479f2013-04-12 04:33:2427#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4928#include "base/strings/string_split.h"
[email protected]21aa99682013-06-11 07:17:0129#include "base/strings/string_util.h"
[email protected]40d11e02013-03-28 17:43:1430#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0031#include "base/strings/utf_string_conversions.h"
[email protected]abb522162013-06-28 01:54:1632#include "base/time/time.h"
[email protected]a8cb3b73b2013-08-12 05:50:5033#include "content/child/appcache/appcache_dispatcher.h"
34#include "content/child/appcache/web_application_cache_host_impl.h"
[email protected]10208ea2013-06-06 20:08:0335#include "content/child/child_thread.h"
[email protected]29e2fb42013-07-19 01:13:4736#include "content/child/npapi/webplugin_delegate_impl.h"
[email protected]541b7b02013-06-07 00:59:3437#include "content/child/request_extra_data.h"
[email protected]10208ea2013-06-06 20:08:0338#include "content/child/webmessageportchannel_impl.h"
[email protected]127dd582011-03-16 21:32:1039#include "content/common/clipboard_messages.h"
[email protected]37666cf2011-03-13 21:51:4240#include "content/common/database_messages.h"
[email protected]5f2aa722013-08-07 16:59:4141#include "content/common/dom_storage/dom_storage_types.h"
[email protected]59f4f2fa2011-03-23 01:00:5542#include "content/common/drag_messages.h"
[email protected]c26ad882012-02-07 06:41:2043#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]c084330e02013-04-27 01:08:1544#include "content/common/input_messages.h"
[email protected]7f3c7af2011-10-20 22:52:5145#include "content/common/java_bridge_messages.h"
[email protected]127dd582011-03-16 21:32:1046#include "content/common/pepper_messages.h"
[email protected]5fa3a062012-03-21 15:39:3447#include "content/common/socket_stream_handle_data.h"
[email protected]e4495212012-12-06 03:09:1248#include "content/common/ssl_status_serialization.h"
[email protected]778574e2011-03-21 22:03:5049#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2150#include "content/public/common/bindings_policy.h"
[email protected]744c2a22012-03-15 18:42:0451#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4852#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2953#include "content/public/common/content_switches.h"
[email protected]35be7ec2012-02-12 20:42:5154#include "content/public/common/context_menu_params.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]97f58132012-11-15 20:41:3264#include "content/public/renderer/context_menu_client.h"
[email protected]007733c2011-11-17 00:34:0765#include "content/public/renderer/document_state.h"
[email protected]691aa2f2013-05-28 22:52:0466#include "content/public/renderer/history_item_serialization.h"
[email protected]82ddba1c2011-10-04 00:15:3267#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4468#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3669#include "content/public/renderer/render_view_visitor.h"
[email protected]49a20002013-08-18 12:43:3170#include "content/public/renderer/web_preferences.h"
[email protected]4e4646a52013-02-08 07:23:4171#include "content/renderer/accessibility/renderer_accessibility.h"
72#include "content/renderer/accessibility/renderer_accessibility_complete.h"
73#include "content/renderer/accessibility/renderer_accessibility_focus_only.h"
[email protected]e6e56752012-08-10 00:46:0674#include "content/renderer/browser_plugin/browser_plugin.h"
75#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]fb325d122012-11-20 23:58:0576#include "content/renderer/browser_plugin/browser_plugin_manager_impl.h"
[email protected]3175fea2013-05-16 10:57:4877#include "content/renderer/context_menu_params_builder.h"
[email protected]230b7ef2011-03-16 22:30:1978#include "content/renderer/device_orientation_dispatcher.h"
[email protected]70019152012-12-19 11:44:1979#include "content/renderer/devtools/devtools_agent.h"
[email protected]f9526d12012-10-18 01:55:0380#include "content/renderer/disambiguation_popup_helper.h"
[email protected]766a7082012-02-03 23:39:1581#include "content/renderer/dom_automation_controller.h"
[email protected]1910fe82012-05-10 00:04:1082#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]dc293a72013-07-01 11:11:2283#include "content/renderer/drop_data_builder.h"
[email protected]55722152011-03-22 01:33:5384#include "content/renderer/external_popup_menu.h"
[email protected]f8c700ba2013-05-14 08:25:4985#include "content/renderer/fetchers/alt_error_page_resource_fetcher.h"
[email protected]230b7ef2011-03-16 22:30:1986#include "content/renderer/geolocation_dispatcher.h"
[email protected]ea5f70a2013-03-07 12:30:3687#include "content/renderer/gpu/input_handler_manager.h"
[email protected]ba91a792013-02-06 09:48:2888#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]1784b2f2011-11-24 10:53:4889#include "content/renderer/idle_user_detector.h"
[email protected]41225fe2013-03-29 05:32:0290#include "content/renderer/image_loading_helper.h"
[email protected]66fca5bc2013-05-23 06:58:2991#include "content/renderer/ime_event_guard.h"
[email protected]c52b2892012-03-07 11:01:0292#include "content/renderer/input_tag_speech_dispatcher.h"
[email protected]92d457802013-04-01 19:18:4993#include "content/renderer/internal_document_state_data.h"
[email protected]07161902011-11-11 09:57:4294#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0295#include "content/renderer/load_progress_tracker.h"
[email protected]4a914882013-01-10 00:43:4896#include "content/renderer/media/audio_device_factory.h"
97#include "content/renderer/media/audio_renderer_mixer_manager.h"
[email protected]273558fb2012-01-12 15:03:5198#include "content/renderer/media/media_stream_dependency_factory.h"
99#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:40100#include "content/renderer/media/media_stream_impl.h"
[email protected]7b77f6cb2013-07-25 16:23:14101#include "content/renderer/media/midi_dispatcher.h"
[email protected]090f7312011-08-05 23:26:40102#include "content/renderer/media/render_media_log.h"
[email protected]6392d982013-04-16 16:59:22103#include "content/renderer/media/video_capture_impl_manager.h"
[email protected]5e35a8d2013-07-10 19:37:21104#include "content/renderer/media/webmediaplayer_impl.h"
105#include "content/renderer/media/webmediaplayer_ms.h"
106#include "content/renderer/media/webmediaplayer_params.h"
[email protected]4a19be92011-09-22 14:25:02107#include "content/renderer/mhtml_generator.h"
[email protected]230b7ef2011-03-16 22:30:19108#include "content/renderer/notification_provider.h"
[email protected]227692c52013-05-31 22:43:04109#include "content/renderer/render_frame_impl.h"
[email protected]8704f89b2011-04-15 00:30:05110#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:44111#include "content/renderer/render_thread_impl.h"
[email protected]8d41d7612012-11-14 20:32:19112#include "content/renderer/render_view_impl_params.h"
[email protected]89054502012-06-03 10:29:24113#include "content/renderer/render_view_mouse_lock_dispatcher.h"
[email protected]2cff0052011-03-18 16:51:44114#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]b18583c2012-12-18 06:55:27115#include "content/renderer/renderer_date_time_picker.h"
[email protected]663bd9e2011-03-21 01:07:01116#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]da8543762012-03-20 08:52:20117#include "content/renderer/renderer_webcolorchooser_impl.h"
[email protected]12a936d2013-05-15 04:55:49118#include "content/renderer/savable_resources.h"
[email protected]64d09222012-05-25 10:10:34119#include "content/renderer/speech_recognition_dispatcher.h"
[email protected]27c521a2013-05-29 20:44:32120#include "content/renderer/stats_collection_controller.h"
121#include "content/renderer/stats_collection_observer.h"
[email protected]86a7d3c2011-09-12 16:45:32122#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:19123#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:21124#include "content/renderer/web_ui_extension.h"
125#include "content/renderer/web_ui_extension_data.h"
[email protected]6f516082011-03-17 19:15:35126#include "content/renderer/websharedworker_proxy.h"
[email protected]f5961142013-04-17 23:09:42127#include "media/audio/audio_output_device.h"
[email protected]4a914882013-01-10 00:43:48128#include "media/base/audio_renderer_mixer_input.h"
[email protected]f8db8132010-12-03 00:27:49129#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41130#include "media/base/media_switches.h"
[email protected]37136d162012-04-09 23:39:19131#include "media/filters/audio_renderer_impl.h"
[email protected]1cad8802013-08-13 16:54:32132#include "media/filters/gpu_video_accelerator_factories.h"
[email protected]d1ef81d2012-07-24 11:39:36133#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29134#include "net/base/escape.h"
135#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09136#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04137#include "net/http/http_util.h"
[email protected]d0fcff72013-07-23 02:45:43138#include "third_party/WebKit/public/platform/WebCString.h"
139#include "third_party/WebKit/public/platform/WebDragData.h"
[email protected]d0fcff72013-07-23 02:45:43140#include "third_party/WebKit/public/platform/WebHTTPBody.h"
141#include "third_party/WebKit/public/platform/WebImage.h"
142#include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
143#include "third_party/WebKit/public/platform/WebPoint.h"
144#include "third_party/WebKit/public/platform/WebRect.h"
145#include "third_party/WebKit/public/platform/WebSize.h"
146#include "third_party/WebKit/public/platform/WebSocketStreamHandle.h"
147#include "third_party/WebKit/public/platform/WebString.h"
148#include "third_party/WebKit/public/platform/WebURL.h"
149#include "third_party/WebKit/public/platform/WebURLError.h"
150#include "third_party/WebKit/public/platform/WebURLRequest.h"
151#include "third_party/WebKit/public/platform/WebURLResponse.h"
152#include "third_party/WebKit/public/platform/WebVector.h"
[email protected]10760e4a2013-09-04 23:32:20153#include "third_party/WebKit/public/web/WebAXObject.h"
[email protected]2255a9332013-06-17 05:12:31154#include "third_party/WebKit/public/web/WebColorName.h"
155#include "third_party/WebKit/public/web/WebDOMEvent.h"
156#include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
157#include "third_party/WebKit/public/web/WebDataSource.h"
158#include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h"
159#include "third_party/WebKit/public/web/WebDateTimeChooserParams.h"
160#include "third_party/WebKit/public/web/WebDevToolsAgent.h"
161#include "third_party/WebKit/public/web/WebDocument.h"
162#include "third_party/WebKit/public/web/WebElement.h"
163#include "third_party/WebKit/public/web/WebFileChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31164#include "third_party/WebKit/public/web/WebFindOptions.h"
165#include "third_party/WebKit/public/web/WebFormControlElement.h"
166#include "third_party/WebKit/public/web/WebFormElement.h"
167#include "third_party/WebKit/public/web/WebFrame.h"
[email protected]6bd867b2013-07-24 22:10:20168#include "third_party/WebKit/public/web/WebGlyphCache.h"
[email protected]2255a9332013-06-17 05:12:31169#include "third_party/WebKit/public/web/WebHelperPlugin.h"
170#include "third_party/WebKit/public/web/WebHistoryItem.h"
171#include "third_party/WebKit/public/web/WebInputElement.h"
172#include "third_party/WebKit/public/web/WebInputEvent.h"
173#include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
174#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
175#include "third_party/WebKit/public/web/WebNodeList.h"
176#include "third_party/WebKit/public/web/WebPageSerializer.h"
177#include "third_party/WebKit/public/web/WebPlugin.h"
178#include "third_party/WebKit/public/web/WebPluginAction.h"
179#include "third_party/WebKit/public/web/WebPluginContainer.h"
180#include "third_party/WebKit/public/web/WebPluginDocument.h"
181#include "third_party/WebKit/public/web/WebPluginParams.h"
182#include "third_party/WebKit/public/web/WebRange.h"
[email protected]91f05762013-08-21 02:55:09183#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
[email protected]2255a9332013-06-17 05:12:31184#include "third_party/WebKit/public/web/WebScriptSource.h"
185#include "third_party/WebKit/public/web/WebSearchableFormData.h"
186#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
187#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
188#include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
189#include "third_party/WebKit/public/web/WebSettings.h"
190#include "third_party/WebKit/public/web/WebStorageQuotaCallbacks.h"
191#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
192#include "third_party/WebKit/public/web/WebUserMediaClient.h"
193#include "third_party/WebKit/public/web/WebView.h"
194#include "third_party/WebKit/public/web/WebWindowFeatures.h"
195#include "third_party/WebKit/public/web/default/WebRenderTheme.h"
[email protected]1400e6dc2013-04-27 02:36:27196#include "ui/base/ui_base_switches_util.h"
[email protected]08397d52011-02-05 01:53:38197#include "ui/gfx/native_widget_types.h"
198#include "ui/gfx/point.h"
199#include "ui/gfx/rect.h"
[email protected]70221f02013-01-31 22:17:07200#include "ui/gfx/rect_conversions.h"
[email protected]f9526d12012-10-18 01:55:03201#include "ui/gfx/size_conversions.h"
[email protected]4344a3c2013-01-17 23:49:20202#include "ui/shell_dialogs/selected_file_info.h"
[email protected]c4a9e932011-03-05 04:05:55203#include "v8/include/v8.h"
[email protected]d0fcff72013-07-23 02:45:43204#include "webkit/child/weburlresponse_extradata_impl.h"
initial.commit09911bf2008-07-26 23:55:29205
[email protected]25fb9b32012-04-27 03:21:55206#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25207#include <cpu-features.h>
208
[email protected]276e8a322013-01-24 01:50:11209#include "content/common/android/device_telephony_info.h"
[email protected]a45c46e2013-03-07 01:04:46210#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]20657a82012-08-21 20:23:03211#include "content/renderer/android/address_detector.h"
212#include "content/renderer/android/content_detector.h"
213#include "content/renderer/android/email_detector.h"
214#include "content/renderer/android/phone_number_detector.h"
[email protected]3a59bb92013-08-22 18:54:08215#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]bc427442013-07-13 02:53:08216#include "content/renderer/media/android/renderer_media_player_manager.h"
[email protected]3aaba572013-08-10 15:10:38217#include "content/renderer/media/android/stream_texture_factory_android_impl.h"
[email protected]be580992013-06-22 14:32:44218#include "content/renderer/media/android/webmediaplayer_android.h"
[email protected]be580992013-06-22 14:32:44219#include "content/renderer/media/android/webmediaplayer_proxy_android.h"
[email protected]c277d3c2013-07-15 21:49:37220#include "skia/ext/platform_canvas.h"
[email protected]5c30b5e02013-05-30 03:46:08221#include "third_party/WebKit/public/platform/WebFloatPoint.h"
222#include "third_party/WebKit/public/platform/WebFloatRect.h"
[email protected]d0fcff72013-07-23 02:45:43223#include "third_party/WebKit/public/web/WebHitTestResult.h"
[email protected]59363fc92012-09-05 03:46:31224#include "ui/gfx/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40225
226#if defined(GOOGLE_TV)
227#include "content/renderer/media/rtc_video_decoder_bridge_tv.h"
228#include "content/renderer/media/rtc_video_decoder_factory_tv.h"
229#endif
230
[email protected]25fb9b32012-04-27 03:21:55231#elif defined(OS_WIN)
[email protected]6c8afae52009-01-22 02:24:57232// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57233// * theming
[email protected]990e6222012-11-16 13:31:18234#include "ui/native_theme/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03235#elif defined(USE_X11)
[email protected]990e6222012-11-16 13:31:18236#include "ui/native_theme/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33237#elif defined(OS_MACOSX)
238#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57239#endif
240
[email protected]ea2fb972013-08-07 05:44:26241#if defined(ENABLE_PLUGINS)
[email protected]a80af12e2013-08-07 23:36:13242#include "content/renderer/npapi/webplugin_delegate_proxy.h"
243#include "content/renderer/npapi/webplugin_impl.h"
[email protected]ea2fb972013-08-07 05:44:26244#include "content/renderer/pepper/pepper_browser_connection.h"
245#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
246#include "content/renderer/pepper/pepper_plugin_registry.h"
247#include "content/renderer/pepper/pepper_webplugin_impl.h"
248#include "content/renderer/pepper/plugin_module.h"
249#endif
250
[email protected]9ac667e2013-09-09 12:49:21251#if defined(ENABLE_WEBRTC)
252#include "content/renderer/media/rtc_peer_connection_handler.h"
253#endif
254
[email protected]10760e4a2013-09-04 23:32:20255using WebKit::WebAXObject;
[email protected]035545f2010-04-09 13:10:21256using WebKit::WebApplicationCacheHost;
257using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26258using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41259using WebKit::WebColor;
260using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59261using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44262using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51263using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55264using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28265using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00266using WebKit::WebDocument;
[email protected]f546640b2012-05-15 00:03:49267using WebKit::WebDOMEvent;
268using WebKit::WebDOMMessageEvent;
[email protected]e80c73b2009-04-07 23:24:58269using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25270using WebKit::WebDragOperation;
271using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51272using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51273using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08274using WebKit::WebExternalPopupMenu;
275using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47276using WebKit::WebFileChooserCompletion;
[email protected]6069da8c2009-10-20 20:33:49277using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59278using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48279using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45280using WebKit::WebFrame;
[email protected]3306f262012-09-21 19:20:42281using WebKit::WebGestureEvent;
[email protected]ca948a22009-06-25 19:36:17282using WebKit::WebHistoryItem;
[email protected]132e281a2012-07-31 18:32:44283using WebKit::WebHTTPBody;
[email protected]42054a252011-05-17 18:02:13284using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41285using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50286using WebKit::WebInputElement;
[email protected]3306f262012-09-21 19:20:42287using WebKit::WebInputEvent;
[email protected]3d9689372009-09-10 04:29:17288using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28289using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17290using WebKit::WebMediaPlayerClient;
[email protected]2b942c332012-04-25 16:26:26291using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:28292using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28293using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51294using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19295using WebKit::WebPageSerializer;
296using WebKit::WebPageSerializerClient;
[email protected]50da23d02012-04-13 17:47:48297using WebKit::WebPeerConnection00Handler;
298using WebKit::WebPeerConnection00HandlerClient;
299using WebKit::WebPeerConnectionHandler;
300using WebKit::WebPeerConnectionHandlerClient;
[email protected]81375e872012-01-11 21:40:36301using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40302using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49303using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09304using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52305using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59306using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51307using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52308using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15309using WebKit::WebReferrerPolicy;
[email protected]91f05762013-08-21 02:55:09310using WebKit::WebRuntimeFeatures;
[email protected]4f999132009-03-31 18:08:40311using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35312using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29313using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17314using WebKit::WebSecurityPolicy;
[email protected]f546640b2012-05-15 00:03:49315using WebKit::WebSerializedScriptValue;
[email protected]2fab253a2009-08-17 23:00:59316using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42317using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02318using WebKit::WebSize;
[email protected]5fa3a062012-03-21 15:39:34319using WebKit::WebSocketStreamHandle;
[email protected]bd92c3a2010-01-13 05:02:34320using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40321using WebKit::WebStorageQuotaCallbacks;
322using WebKit::WebStorageQuotaError;
323using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28324using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51325using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52326using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24327using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28328using WebKit::WebURL;
329using WebKit::WebURLError;
330using WebKit::WebURLRequest;
331using WebKit::WebURLResponse;
[email protected]af15bf22013-03-08 01:18:17332using WebKit::WebUserGestureIndicator;
[email protected]4873c7d2009-07-16 06:36:28333using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03334using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28335using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26336using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26337using base::Time;
338using base::TimeDelta;
[email protected]b9fd01ba2012-02-28 01:50:40339using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33340
[email protected]20657a82012-08-21 20:23:03341#if defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:03342using WebKit::WebContentDetectionResult;
[email protected]59363fc92012-09-05 03:46:31343using WebKit::WebFloatPoint;
344using WebKit::WebFloatRect;
[email protected]20657a82012-08-21 20:23:03345using WebKit::WebHitTestResult;
346#endif
347
[email protected]e9ff79c2012-10-19 21:31:26348namespace content {
349
initial.commit09911bf2008-07-26 23:55:29350//-----------------------------------------------------------------------------
351
[email protected]310ebd6302011-10-10 19:06:28352typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49353static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]058561b2012-12-03 06:48:22354typedef std::map<int32, RenderViewImpl*> RoutingIDViewMap;
355static base::LazyInstance<RoutingIDViewMap> g_routing_id_view_map =
356 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02357
[email protected]882daa92009-11-05 16:31:31358// Time, in seconds, we delay before sending content state changes (such as form
359// state and scroll position) to the browser. We delay sending changes to avoid
360// spamming the browser.
361// To avoid having tab/session restore require sending a message to get the
362// current content state during tab closing we use a shorter timeout for the
363// foreground renderer. This means there is a small window of time from which
364// content state is modified and not sent to session restore, but this is
365// better than having to wake up all renderers during shutdown.
366static const int kDelaySecondsForContentStateSyncHidden = 5;
367static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29368
[email protected]e99ef6f2011-10-16 01:13:00369static const size_t kExtraCharsBeforeAndAfterSelection = 100;
370
[email protected]c514d6372011-08-16 22:54:44371static const float kScalingIncrement = 0.1f;
372
[email protected]47578fa02011-11-02 19:34:41373static const float kScalingIncrementForGesture = 0.01f;
374
[email protected]20657a82012-08-21 20:23:03375#if defined(OS_ANDROID)
376// Delay between tapping in content and launching the associated android intent.
377// Used to allow users see what has been recognized as content.
378static const size_t kContentIntentDelayMilliseconds = 700;
379#endif
380
[email protected]8d41d7612012-11-14 20:32:19381static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) =
382 NULL;
383
[email protected]726985e22009-06-18 21:09:28384static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
[email protected]bf692cd2012-11-14 19:10:02385 // Replace any occurrences of swappedout:// with about:blank.
[email protected]081dc522013-05-15 04:59:20386 const WebURL& blank_url = GURL(kAboutBlankURL);
[email protected]726985e22009-06-18 21:09:28387 WebVector<WebURL> urls;
388 ds->redirectChain(urls);
389 result->reserve(urls.size());
[email protected]bf692cd2012-11-14 19:10:02390 for (size_t i = 0; i < urls.size(); ++i) {
391 if (urls[i] != GURL(kSwappedOutURL))
392 result->push_back(urls[i]);
393 else
394 result->push_back(blank_url);
395 }
[email protected]726985e22009-06-18 21:09:28396}
397
[email protected]e20b88d2013-04-09 15:28:37398// If |data_source| is non-null and has an InternalDocumentStateData associated
399// with it, the AltErrorPageResourceFetcher is reset.
[email protected]6a8f5112011-05-13 16:38:44400static void StopAltErrorPageFetcher(WebDataSource* data_source) {
401 if (data_source) {
[email protected]e20b88d2013-04-09 15:28:37402 InternalDocumentStateData* internal_data =
403 InternalDocumentStateData::FromDataSource(data_source);
404 if (internal_data)
405 internal_data->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44406 }
407}
408
[email protected]007733c2011-11-17 00:34:07409static bool IsReload(const ViewMsg_Navigate_Params& params) {
410 return
411 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
[email protected]7c16976c2012-08-04 02:38:23412 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE ||
413 params.navigation_type ==
414 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]007733c2011-11-17 00:34:07415}
416
[email protected]e507045d2013-07-24 15:23:44417// static
418WebReferrerPolicy RenderViewImpl::GetReferrerPolicyFromRequest(
[email protected]ca662822012-05-11 17:53:59419 WebFrame* frame,
[email protected]445e1042011-12-03 21:03:15420 const WebURLRequest& request) {
421 return request.extraData() ?
422 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
[email protected]ca662822012-05-11 17:53:59423 frame->document().referrerPolicy();
[email protected]445e1042011-12-03 21:03:15424}
425
[email protected]e507045d2013-07-24 15:23:44426// static
427Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56428 WebFrame* frame,
429 const WebURLRequest& request) {
430 return Referrer(GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
431 GetReferrerPolicyFromRequest(frame, request));
432}
433
[email protected]e507045d2013-07-24 15:23:44434// static
435WebURLResponseExtraDataImpl* RenderViewImpl::GetExtraDataFromResponse(
[email protected]b9fd01ba2012-02-28 01:50:40436 const WebURLResponse& response) {
437 return static_cast<WebURLResponseExtraDataImpl*>(
438 response.extraData());
439}
440
[email protected]2149cc622012-02-14 01:12:12441NOINLINE static void CrashIntentionally() {
442 // NOTE(shess): Crash directly rather than using NOTREACHED() so
443 // that the signature is easier to triage in crash reports.
444 volatile int* zero = NULL;
445 *zero = 0;
446}
447
[email protected]2132d6b2013-06-05 00:15:43448#if defined(ADDRESS_SANITIZER)
449NOINLINE static void MaybeTriggerAsanError(const GURL& url) {
450 // NOTE(rogerm): We intentionally perform an invalid heap access here in
451 // order to trigger an Address Sanitizer (ASAN) error report.
452 static const char kCrashDomain[] = "crash";
453 static const char kHeapOverflow[] = "/heap-overflow";
454 static const char kHeapUnderflow[] = "/heap-underflow";
455 static const char kUseAfterFree[] = "/use-after-free";
456 static const int kArraySize = 5;
457
458 if (!url.DomainIs(kCrashDomain, sizeof(kCrashDomain) - 1))
459 return;
460
461 if (!url.has_path())
462 return;
463
464 scoped_ptr<int[]> array(new int[kArraySize]);
465 std::string crash_type(url.path());
466 int dummy = 0;
467 if (crash_type == kHeapOverflow) {
468 dummy = array[kArraySize];
469 } else if (crash_type == kHeapUnderflow ) {
470 dummy = array[-1];
471 } else if (crash_type == kUseAfterFree) {
472 int* dangling = array.get();
473 array.reset();
474 dummy = dangling[kArraySize / 2];
475 }
476
477 // Make sure the assignments to the dummy value aren't optimized away.
478 base::debug::Alias(&dummy);
479}
480#endif // ADDRESS_SANITIZER
481
[email protected]8bf1048012012-02-08 01:22:18482static void MaybeHandleDebugURL(const GURL& url) {
483 if (!url.SchemeIs(chrome::kChromeUIScheme))
484 return;
[email protected]f8a6d732013-03-02 22:46:03485 if (url == GURL(kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12486 CrashIntentionally();
[email protected]f8a6d732013-03-02 22:46:03487 } else if (url == GURL(kChromeUIKillURL)) {
[email protected]8bf1048012012-02-08 01:22:18488 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
[email protected]f8a6d732013-03-02 22:46:03489 } else if (url == GURL(kChromeUIHangURL)) {
[email protected]8bf1048012012-02-08 01:22:18490 for (;;) {
491 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
492 }
[email protected]50f86bc2012-11-01 19:59:13493 } else if (url == GURL(kChromeUIShorthangURL)) {
[email protected]8bf1048012012-02-08 01:22:18494 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
495 }
[email protected]2132d6b2013-06-05 00:15:43496
497#if defined(ADDRESS_SANITIZER)
498 MaybeTriggerAsanError(url);
499#endif // ADDRESS_SANITIZER
[email protected]8bf1048012012-02-08 01:22:18500}
501
[email protected]fd3238af2012-05-22 18:55:30502// Returns false unless this is a top-level navigation.
503static bool IsTopLevelNavigation(WebFrame* frame) {
504 return frame->parent() == NULL;
505}
506
507// Returns false unless this is a top-level navigation that crosses origins.
508static bool IsNonLocalTopLevelNavigation(const GURL& url,
509 WebFrame* frame,
[email protected]140a5882013-07-23 19:30:33510 WebNavigationType type,
511 bool is_form_post) {
[email protected]fd3238af2012-05-22 18:55:30512 if (!IsTopLevelNavigation(frame))
513 return false;
514
515 // Navigations initiated within Webkit are not sent out to the external host
516 // in the following cases.
517 // 1. The url scheme is not http/https
518 // 2. The origin of the url and the opener is the same in which case the
519 // opener relationship is maintained.
520 // 3. Reloads/form submits/back forward navigations
[email protected]e9a82042013-09-15 03:38:29521 if (!url.SchemeIs(kHttpScheme) && !url.SchemeIs(kHttpsScheme))
[email protected]fd3238af2012-05-22 18:55:30522 return false;
523
[email protected]fd3238af2012-05-22 18:55:30524 if (type != WebKit::WebNavigationTypeReload &&
[email protected]140a5882013-07-23 19:30:33525 type != WebKit::WebNavigationTypeBackForward && !is_form_post) {
[email protected]fd3238af2012-05-22 18:55:30526 // The opener relationship between the new window and the parent allows the
527 // new window to script the parent and vice versa. This is not allowed if
528 // the origins of the two domains are different. This can be treated as a
529 // top level navigation and routed back to the host.
530 WebKit::WebFrame* opener = frame->opener();
[email protected]140a5882013-07-23 19:30:33531 if (!opener)
[email protected]fd3238af2012-05-22 18:55:30532 return true;
[email protected]fd3238af2012-05-22 18:55:30533
534 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
535 return true;
536 }
537 return false;
538}
539
[email protected]38761452012-10-18 16:31:59540static void NotifyTimezoneChange(WebKit::WebFrame* frame) {
[email protected]e1907b432013-09-04 16:11:14541 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
[email protected]38761452012-10-18 16:31:59542 v8::Context::Scope context_scope(frame->mainWorldScriptContext());
543 v8::Date::DateTimeConfigurationChangeNotification();
544 WebKit::WebFrame* child = frame->firstChild();
545 for (; child; child = child->nextSibling())
546 NotifyTimezoneChange(child);
547}
548
[email protected]48861e22013-01-09 00:27:32549static WindowOpenDisposition NavigationPolicyToDisposition(
550 WebNavigationPolicy policy) {
551 switch (policy) {
552 case WebKit::WebNavigationPolicyIgnore:
553 return IGNORE_ACTION;
554 case WebKit::WebNavigationPolicyDownload:
555 return SAVE_TO_DISK;
556 case WebKit::WebNavigationPolicyCurrentTab:
557 return CURRENT_TAB;
558 case WebKit::WebNavigationPolicyNewBackgroundTab:
559 return NEW_BACKGROUND_TAB;
560 case WebKit::WebNavigationPolicyNewForegroundTab:
561 return NEW_FOREGROUND_TAB;
562 case WebKit::WebNavigationPolicyNewWindow:
563 return NEW_WINDOW;
564 case WebKit::WebNavigationPolicyNewPopup:
565 return NEW_POPUP;
566 default:
567 NOTREACHED() << "Unexpected WebNavigationPolicy";
568 return IGNORE_ACTION;
569 }
570}
571
[email protected]d8221b22013-05-23 05:35:43572// Returns true if the device scale is high enough that losing subpixel
573// antialiasing won't have a noticeable effect on text quality.
574static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
575#if defined(OS_ANDROID)
576 // On Android, we never have subpixel antialiasing.
577 return true;
578#else
579 return device_scale_factor > 1.5f;
580#endif
581
582}
583
[email protected]fb854192013-02-06 01:30:04584static bool ShouldUseFixedPositionCompositing(float device_scale_factor) {
585 // Compositing for fixed-position elements is dependent on
[email protected]d8221b22013-05-23 05:35:43586 // device_scale_factor if no flag is set. http://crbug.com/172738
[email protected]fb854192013-02-06 01:30:04587 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
588
589 if (command_line.HasSwitch(switches::kDisableCompositingForFixedPosition))
590 return false;
591
592 if (command_line.HasSwitch(switches::kEnableCompositingForFixedPosition))
593 return true;
594
[email protected]d8221b22013-05-23 05:35:43595 return DeviceScaleEnsuresTextQuality(device_scale_factor);
596}
597
[email protected]c162ced82013-06-29 01:24:53598static bool ShouldUseAcceleratedCompositingForOverflowScroll(
599 float device_scale_factor) {
600 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
601
602 if (command_line.HasSwitch(switches::kEnableAcceleratedOverflowScroll))
603 return true;
604
605 return DeviceScaleEnsuresTextQuality(device_scale_factor);
606}
607
[email protected]d8221b22013-05-23 05:35:43608static bool ShouldUseTransitionCompositing(float device_scale_factor) {
609 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
610
611 if (command_line.HasSwitch(switches::kDisableCompositingForTransition))
612 return false;
613
614 if (command_line.HasSwitch(switches::kEnableCompositingForTransition))
[email protected]fb854192013-02-06 01:30:04615 return true;
616
[email protected]9a7f6e12013-06-11 07:05:13617 // TODO(ajuma): Re-enable this by default for high-DPI once the problem
618 // of excessive layer promotion caused by overlap has been addressed.
619 // http://crbug.com/178119.
620 return false;
[email protected]fb854192013-02-06 01:30:04621}
622
[email protected]06fc4d3b2013-07-08 21:07:24623static bool ShouldUseAcceleratedFixedRootBackground(float device_scale_factor) {
624 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
625
626 if (command_line.HasSwitch(switches::kDisableAcceleratedFixedRootBackground))
627 return false;
628
629 if (command_line.HasSwitch(switches::kEnableAcceleratedFixedRootBackground))
630 return true;
631
632 return DeviceScaleEnsuresTextQuality(device_scale_factor);
633}
634
[email protected]41225fe2013-03-29 05:32:02635static FaviconURL::IconType ToFaviconType(WebKit::WebIconURL::Type type) {
636 switch (type) {
637 case WebKit::WebIconURL::TypeFavicon:
638 return FaviconURL::FAVICON;
639 case WebKit::WebIconURL::TypeTouch:
640 return FaviconURL::TOUCH_ICON;
641 case WebKit::WebIconURL::TypeTouchPrecomposed:
642 return FaviconURL::TOUCH_PRECOMPOSED_ICON;
643 case WebKit::WebIconURL::TypeInvalid:
644 return FaviconURL::INVALID_ICON;
645 }
646 return FaviconURL::INVALID_ICON;
647}
648
initial.commit09911bf2008-07-26 23:55:29649///////////////////////////////////////////////////////////////////////////////
650
[email protected]310ebd6302011-10-10 19:06:28651struct RenderViewImpl::PendingFileChooser {
[email protected]e9ff79c2012-10-19 21:31:26652 PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c)
[email protected]cdaf8d02010-03-30 19:52:47653 : params(p),
654 completion(c) {
655 }
[email protected]e9ff79c2012-10-19 21:31:26656 FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47657 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
658};
659
[email protected]217690d2012-01-27 07:33:11660namespace {
661
662class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
663 public:
[email protected]82114f52012-03-20 22:53:41664 explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget)
[email protected]217690d2012-01-27 07:33:11665 : webwidget_(webwidget) {}
666
667 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
668 if (succeeded)
669 webwidget_->didAcquirePointerLock();
670 else
671 webwidget_->didNotAcquirePointerLock();
672 }
673
674 virtual void OnMouseLockLost() OVERRIDE {
675 webwidget_->didLosePointerLock();
676 }
677
678 virtual bool HandleMouseLockedInputEvent(
679 const WebKit::WebMouseEvent &event) OVERRIDE {
680 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
681 return false;
682 }
683
684 private:
685 WebKit::WebWidget* webwidget_;
686};
687
[email protected]86cd9472012-02-03 19:51:05688int64 ExtractPostId(const WebHistoryItem& item) {
689 if (item.isNull())
690 return -1;
691
692 if (item.httpBody().isNull())
693 return -1;
694
695 return item.httpBody().identifier();
696}
697
[email protected]41225fe2013-03-29 05:32:02698bool TouchEnabled() {
699// Based on the definition of chrome::kEnableTouchIcon.
700#if defined(OS_ANDROID)
701 return true;
702#else
703 return false;
704#endif
705}
706
[email protected]dc293a72013-07-01 11:11:22707WebDragData DropDataToWebDragData(const DropData& drop_data) {
[email protected]c10680312013-05-31 15:22:05708 std::vector<WebDragData::Item> item_list;
709
710 // These fields are currently unused when dragging into WebKit.
711 DCHECK(drop_data.download_metadata.empty());
712 DCHECK(drop_data.file_contents.empty());
713 DCHECK(drop_data.file_description_filename.empty());
714
715 if (!drop_data.text.is_null()) {
716 WebDragData::Item item;
717 item.storageType = WebDragData::Item::StorageTypeString;
718 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText);
719 item.stringData = drop_data.text.string();
720 item_list.push_back(item);
721 }
722
723 // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it
724 // meaningful to write an empty URL to the clipboard?
725 if (!drop_data.url.is_empty()) {
726 WebDragData::Item item;
727 item.storageType = WebDragData::Item::StorageTypeString;
728 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList);
729 item.stringData = WebString::fromUTF8(drop_data.url.spec());
730 item.title = drop_data.url_title;
731 item_list.push_back(item);
732 }
733
734 if (!drop_data.html.is_null()) {
735 WebDragData::Item item;
736 item.storageType = WebDragData::Item::StorageTypeString;
737 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML);
738 item.stringData = drop_data.html.string();
739 item.baseURL = drop_data.html_base_url;
740 item_list.push_back(item);
741 }
742
[email protected]dc293a72013-07-01 11:11:22743 for (std::vector<DropData::FileInfo>::const_iterator it =
[email protected]c10680312013-05-31 15:22:05744 drop_data.filenames.begin();
745 it != drop_data.filenames.end();
746 ++it) {
747 WebDragData::Item item;
748 item.storageType = WebDragData::Item::StorageTypeFilename;
749 item.filenameData = it->path;
750 item.displayNameData = it->display_name;
751 item_list.push_back(item);
752 }
753
754 for (std::map<base::string16, base::string16>::const_iterator it =
755 drop_data.custom_data.begin();
756 it != drop_data.custom_data.end();
757 ++it) {
758 WebDragData::Item item;
759 item.storageType = WebDragData::Item::StorageTypeString;
760 item.stringType = it->first;
761 item.stringData = it->second;
762 item_list.push_back(item);
763 }
764
765 WebDragData result;
766 result.initialize();
767 result.setItems(item_list);
768 result.setFilesystemId(drop_data.filesystem_id);
769 return result;
770}
771
[email protected]217690d2012-01-27 07:33:11772} // namespace
773
[email protected]8d41d7612012-11-14 20:32:19774RenderViewImpl::RenderViewImpl(RenderViewImplParams* params)
775 : RenderWidget(WebKit::WebPopupTypeNone,
776 params->screen_info,
[email protected]1ac10dca2013-08-20 20:47:04777 params->swapped_out,
778 params->hidden),
[email protected]8d41d7612012-11-14 20:32:19779 webkit_preferences_(params->webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02780 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09781 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02782 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24783 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21784 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02785 opened_by_user_gesture_(true),
786 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24787 page_id_(-1),
788 last_page_id_sent_to_browser_(-1),
[email protected]8d41d7612012-11-14 20:32:19789 next_page_id_(params->next_page_id),
[email protected]3cc72b12010-03-18 23:03:00790 history_list_offset_(-1),
791 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02792 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55793 selection_text_offset_(0),
[email protected]db4fc1e2013-09-06 20:01:51794 selection_range_(gfx::Range::InvalidRange()),
[email protected]bbc8856d2013-06-14 10:37:04795#if defined(OS_ANDROID)
796 top_controls_constraints_(cc::BOTH),
797#endif
[email protected]dd6afca2011-08-13 03:44:31798 cached_is_main_frame_pinned_to_left_(false),
799 cached_is_main_frame_pinned_to_right_(false),
800 cached_has_main_frame_horizontal_scrollbar_(false),
801 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]69e797f2013-04-30 01:10:22802 cookie_jar_(this),
[email protected]8a67aa352013-02-20 02:58:29803 notification_provider_(NULL),
[email protected]676126f72011-01-15 00:03:51804 geolocation_dispatcher_(NULL),
[email protected]c52b2892012-03-07 11:01:02805 input_tag_speech_dispatcher_(NULL),
[email protected]64d09222012-05-25 10:10:34806 speech_recognition_dispatcher_(NULL),
[email protected]676126f72011-01-15 00:03:51807 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51808 media_stream_dispatcher_(NULL),
[email protected]fb325d122012-11-20 23:58:05809 browser_plugin_manager_(NULL),
[email protected]c3bdce152013-07-10 04:56:34810 media_stream_client_(NULL),
811 web_user_media_client_(NULL),
[email protected]f39b9d52013-07-28 08:03:44812 midi_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41813 devtools_agent_(NULL),
[email protected]2a84f9d2012-06-05 21:50:43814 accessibility_mode_(AccessibilityModeOff),
[email protected]063afcb2011-09-29 07:54:32815 renderer_accessibility_(NULL),
[email protected]7e9c5bb02012-05-14 13:58:31816 java_bridge_dispatcher_(NULL),
[email protected]217690d2012-01-27 07:33:11817 mouse_lock_dispatcher_(NULL),
[email protected]20657a82012-08-21 20:23:03818#if defined(OS_ANDROID)
[email protected]4d0f8182012-10-19 23:14:47819 body_background_color_(SK_ColorWHITE),
[email protected]20657a82012-08-21 20:23:03820 expected_content_intent_id_(0),
[email protected]780fc8242012-09-19 20:28:52821 media_player_proxy_(NULL),
[email protected]a7564272013-04-19 14:24:46822#endif
823#if defined(OS_WIN)
824 focused_plugin_id_(-1),
825#endif
[email protected]ea2fb972013-08-07 05:44:26826#if defined(ENABLE_PLUGINS)
827 focused_pepper_plugin_(NULL),
828 pepper_last_mouse_event_target_(NULL),
829#endif
[email protected]8a67aa352013-02-20 02:58:29830 enumeration_completion_id_(0),
[email protected]69e797f2013-04-30 01:10:22831 load_progress_tracker_(new LoadProgressTracker(this)),
[email protected]8d41d7612012-11-14 20:32:19832 session_storage_namespace_id_(params->session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18833 handling_select_range_(false),
[email protected]c9bc8f12012-12-15 22:20:09834 next_snapshot_id_(0),
[email protected]f56c7872013-06-18 12:31:57835 allow_partial_swap_(params->allow_partial_swap),
[email protected]07fb8d52013-08-07 17:03:51836 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) {
[email protected]075366912013-02-18 07:13:24837}
838
839void RenderViewImpl::Initialize(RenderViewImplParams* params) {
[email protected]2f61bdd2013-07-02 18:38:47840 RenderFrameImpl* main_frame = RenderFrameImpl::Create(
841 this, params->main_frame_routing_id);
842 main_render_frame_.reset(main_frame);
[email protected]8d41d7612012-11-14 20:32:19843 routing_id_ = params->routing_id;
844 surface_id_ = params->surface_id;
845 if (params->opener_id != MSG_ROUTING_NONE && params->is_renderer_created)
846 opener_id_ = params->opener_id;
[email protected]676126f72011-01-15 00:03:51847
[email protected]74ce1ad2011-12-16 21:51:46848 // Ensure we start with a valid next_page_id_ from the browser.
849 DCHECK_GE(next_page_id_, 0);
850
[email protected]21b3a6ae2011-11-30 00:45:29851#if defined(ENABLE_NOTIFICATIONS)
852 notification_provider_ = new NotificationProvider(this);
853#else
854 notification_provider_ = NULL;
855#endif
856
[email protected]11fee2332011-03-29 20:36:35857 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11858 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35859
[email protected]20657a82012-08-21 20:23:03860 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
861
[email protected]27c521a2013-05-29 20:44:32862 if (command_line.HasSwitch(switches::kStatsCollectionController))
863 stats_collection_observer_.reset(new StatsCollectionObserver(this));
864
[email protected]20657a82012-08-21 20:23:03865#if defined(OS_ANDROID)
[email protected]276e8a322013-01-24 01:50:11866 content::DeviceTelephonyInfo device_info;
[email protected]20657a82012-08-21 20:23:03867
868 const std::string region_code =
869 command_line.HasSwitch(switches::kNetworkCountryIso)
870 ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso)
[email protected]276e8a322013-01-24 01:50:11871 : device_info.GetNetworkCountryIso();
[email protected]20657a82012-08-21 20:23:03872 content_detectors_.push_back(linked_ptr<ContentDetector>(
873 new AddressDetector()));
874 content_detectors_.push_back(linked_ptr<ContentDetector>(
875 new PhoneNumberDetector(region_code)));
876 content_detectors_.push_back(linked_ptr<ContentDetector>(
877 new EmailDetector()));
878#endif
879
[email protected]380244092011-10-07 17:26:27880 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51881 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47882 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51883 AddRef();
[email protected]1ac10dca2013-08-20 20:47:04884 if (is_hidden_)
885 RenderThread::Get()->WidgetHidden();
[email protected]676126f72011-01-15 00:03:51886
887 // If this is a popup, we must wait for the CreatingNew_ACK message before
888 // completing initialization. Otherwise, we can finish it now.
[email protected]6cd7c6b2012-10-25 03:26:23889 if (opener_id_ == MSG_ROUTING_NONE) {
[email protected]676126f72011-01-15 00:03:51890 did_show_ = true;
[email protected]fc4404d2012-11-07 19:53:30891 CompleteInit();
[email protected]676126f72011-01-15 00:03:51892 }
893
[email protected]34c61bd52011-05-02 19:38:33894 g_view_map.Get().insert(std::make_pair(webview(), this));
[email protected]058561b2012-12-03 06:48:22895 g_routing_id_view_map.Get().insert(std::make_pair(routing_id_, this));
[email protected]60051ec2012-06-08 22:40:57896 webview()->setDeviceScaleFactor(device_scale_factor_);
[email protected]fb854192013-02-06 01:30:04897 webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled(
898 ShouldUseFixedPositionCompositing(device_scale_factor_));
[email protected]c162ced82013-06-29 01:24:53899 webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled(
900 ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_));
[email protected]d8221b22013-05-23 05:35:43901 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
902 ShouldUseTransitionCompositing(device_scale_factor_));
[email protected]06fc4d3b2013-07-08 21:07:24903 webview()->settings()->setAcceleratedCompositingForFixedRootBackgroundEnabled(
904 ShouldUseAcceleratedFixedRootBackground(device_scale_factor_));
[email protected]fb854192013-02-06 01:30:04905
[email protected]49a20002013-08-18 12:43:31906 ApplyWebPreferences(webkit_preferences_, webview());
[email protected]2f61bdd2013-07-02 18:38:47907 webview()->initializeMainFrame(main_render_frame_.get());
[email protected]edbea622012-11-28 20:39:38908
[email protected]1400e6dc2013-04-27 02:36:27909 if (switches::IsTouchDragDropEnabled())
[email protected]edbea622012-11-28 20:39:38910 webview()->settings()->setTouchDragDropEnabled(true);
911
[email protected]1400e6dc2013-04-27 02:36:27912 if (switches::IsTouchEditingEnabled())
[email protected]47822262013-04-23 17:22:36913 webview()->settings()->setTouchEditingEnabled(true);
914
[email protected]8d41d7612012-11-14 20:32:19915 if (!params->frame_name.empty())
916 webview()->mainFrame()->setName(params->frame_name);
[email protected]34c61bd52011-05-02 19:38:33917
[email protected]8d41d7612012-11-14 20:32:19918 OnSetRendererPrefs(params->renderer_prefs);
[email protected]34c61bd52011-05-02 19:38:33919
[email protected]4fb0f202012-05-30 22:44:53920#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02921 if (!media_stream_dispatcher_)
922 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32923#endif
[email protected]735873d2012-01-25 23:31:02924
[email protected]8f6a3b852011-07-19 16:48:56925 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32926#if defined(OS_MACOSX)
927 new TextInputClientObserver(this);
928#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56929
[email protected]2d7b82c2012-06-01 05:57:50930#if defined(OS_ANDROID)
[email protected]bc427442013-07-13 02:53:08931 media_player_manager_.reset(new RendererMediaPlayerManager());
[email protected]2d7b82c2012-06-01 05:57:50932#endif
933
[email protected]217690d2012-01-27 07:33:11934 // The next group of objects all implement RenderViewObserver, so are deleted
935 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41936 devtools_agent_ = new DevToolsAgent(this);
[email protected]6e89eb72013-07-23 13:28:22937 if (RenderWidgetCompositor* rwc = compositor()) {
938 webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId());
939 }
[email protected]89054502012-06-03 10:29:24940 mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
[email protected]41225fe2013-03-29 05:32:02941 new ImageLoadingHelper(this);
[email protected]063afcb2011-09-29 07:54:32942
[email protected]2a84f9d2012-06-05 21:50:43943 // Create renderer_accessibility_ if needed.
[email protected]8d41d7612012-11-14 20:32:19944 OnSetAccessibilityMode(params->accessibility_mode);
[email protected]2a84f9d2012-06-05 21:50:43945
[email protected]1784b2f2011-11-24 10:53:48946 new IdleUserDetector(this);
947
[email protected]766a7082012-02-03 23:39:15948 if (command_line.HasSwitch(switches::kDomAutomationController))
[email protected]e9ff79c2012-10-19 21:31:26949 enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION;
[email protected]27c521a2013-05-29 20:44:32950 if (command_line.HasSwitch(switches::kStatsCollectionController))
951 enabled_bindings_ |= BINDINGS_POLICY_STATS_COLLECTION;
[email protected]766a7082012-02-03 23:39:15952
[email protected]5b52cd2f712012-03-28 02:12:48953 ProcessViewLayoutFlags(command_line);
[email protected]7ddea9802012-02-22 23:08:05954
[email protected]b9bad122013-07-29 20:32:33955#if defined(ENABLE_PLUGINS)
[email protected]ea2fb972013-08-07 05:44:26956 new PepperBrowserConnection(this);
[email protected]b9bad122013-07-29 20:32:33957#endif
958
[email protected]e9ff79c2012-10-19 21:31:26959 GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44960
961 // If we have an opener_id but we weren't created by a renderer, then
962 // it's the browser asking us to set our opener to another RenderView.
[email protected]8d41d7612012-11-14 20:32:19963 if (params->opener_id != MSG_ROUTING_NONE && !params->is_renderer_created) {
964 RenderViewImpl* opener_view = FromRoutingID(params->opener_id);
[email protected]f546640b2012-05-15 00:03:49965 if (opener_view)
966 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
[email protected]14392a52012-05-02 20:28:44967 }
968
969 // If we are initially swapped out, navigate to kSwappedOutURL.
970 // This ensures we are in a unique origin that others cannot script.
971 if (is_swapped_out_)
[email protected]0720b532012-08-28 19:23:37972 NavigateToSwappedOutURL(webview()->mainFrame());
initial.commit09911bf2008-07-26 23:55:29973}
974
[email protected]310ebd6302011-10-10 19:06:28975RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03976 history_page_ids_.clear();
977
[email protected]91a2aea2013-07-08 23:14:39978 base::debug::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_);
979
[email protected]a1128322009-10-06 18:38:46980 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47981 while (!file_chooser_completions_.empty()) {
982 if (file_chooser_completions_.front()->completion) {
983 file_chooser_completions_.front()->completion->didChooseFile(
984 WebVector<WebString>());
985 }
986 file_chooser_completions_.pop_front();
987 }
[email protected]a1128322009-10-06 18:38:46988
[email protected]8ed1d3f2013-02-20 11:45:55989#if defined(OS_ANDROID)
990 // The date/time picker client is both a scoped_ptr member of this class and
991 // a RenderViewObserver. Reset it to prevent double deletion.
992 date_time_picker_client_.reset();
993#endif
994
[email protected]60c42a8c72009-10-09 04:08:59995#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:22996 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:49997 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59998 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
999 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:221000 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
1001 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
1002 it != routing_id_views->end(); ++it)
1003 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:591004#endif
[email protected]676126f72011-01-15 00:03:511005
[email protected]310ebd6302011-10-10 19:06:281006 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:511007 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:591008}
1009
1010/*static*/
[email protected]310ebd6302011-10-10 19:06:281011RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:311012 ViewMap* views = g_view_map.Pointer();
1013 ViewMap::iterator it = views->find(webview);
1014 return it == views->end() ? NULL : it->second;
1015}
1016
1017/*static*/
[email protected]e9ff79c2012-10-19 21:31:261018RenderView* RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:281019 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:311020}
1021
1022/*static*/
[email protected]640e303c2012-12-05 01:36:071023RenderViewImpl* RenderViewImpl::FromRoutingID(int32 routing_id) {
1024 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
1025 RoutingIDViewMap::iterator it = views->find(routing_id);
1026 return it == views->end() ? NULL : it->second;
1027}
1028
1029/*static*/
1030RenderView* RenderView::FromRoutingID(int routing_id) {
1031 return RenderViewImpl::FromRoutingID(routing_id);
1032}
1033
1034/*static*/
[email protected]e9ff79c2012-10-19 21:31:261035void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:491036 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:591037 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
1038 if (!visitor->Visit(it->second))
1039 return;
1040 }
1041}
1042
1043/*static*/
[email protected]310ebd6302011-10-10 19:06:281044RenderViewImpl* RenderViewImpl::Create(
[email protected]0aa55312008-10-17 21:53:081045 int32 opener_id,
[email protected]e9ff79c2012-10-19 21:31:261046 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:081047 const WebPreferences& webkit_prefs,
[email protected]4e6419c2010-01-15 04:50:341048 int32 routing_id,
[email protected]227692c52013-05-31 22:43:041049 int32 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:561050 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:261051 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461052 const string16& frame_name,
[email protected]14392a52012-05-02 20:28:441053 bool is_renderer_created,
1054 bool swapped_out,
[email protected]1ac10dca2013-08-20 20:47:041055 bool hidden,
[email protected]6fd35b72012-03-01 19:46:411056 int32 next_page_id,
[email protected]842f10652012-06-06 01:54:041057 const WebKit::WebScreenInfo& screen_info,
[email protected]34bb3ac2013-03-08 02:41:281058 AccessibilityMode accessibility_mode,
1059 bool allow_partial_swap) {
initial.commit09911bf2008-07-26 23:55:291060 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]8d41d7612012-11-14 20:32:191061 RenderViewImplParams params(
[email protected]676126f72011-01-15 00:03:511062 opener_id,
1063 renderer_prefs,
1064 webkit_prefs,
[email protected]676126f72011-01-15 00:03:511065 routing_id,
[email protected]227692c52013-05-31 22:43:041066 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:561067 surface_id,
[email protected]676126f72011-01-15 00:03:511068 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461069 frame_name,
[email protected]14392a52012-05-02 20:28:441070 is_renderer_created,
1071 swapped_out,
[email protected]1ac10dca2013-08-20 20:47:041072 hidden,
[email protected]6fd35b72012-03-01 19:46:411073 next_page_id,
[email protected]842f10652012-06-06 01:54:041074 screen_info,
[email protected]34bb3ac2013-03-08 02:41:281075 accessibility_mode,
1076 allow_partial_swap);
[email protected]075366912013-02-18 07:13:241077 RenderViewImpl* render_view = NULL;
[email protected]8d41d7612012-11-14 20:32:191078 if (g_create_render_view_impl)
[email protected]075366912013-02-18 07:13:241079 render_view = g_create_render_view_impl(&params);
1080 else
1081 render_view = new RenderViewImpl(&params);
1082 render_view->Initialize(&params);
1083 return render_view;
[email protected]8d41d7612012-11-14 20:32:191084}
1085
1086// static
1087void RenderViewImpl::InstallCreateHook(
1088 RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*)) {
1089 CHECK(!g_create_render_view_impl);
1090 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291091}
1092
[email protected]310ebd6302011-10-10 19:06:281093void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511094 observers_.AddObserver(observer);
1095}
1096
[email protected]310ebd6302011-10-10 19:06:281097void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1098 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511099 observers_.RemoveObserver(observer);
1100}
1101
[email protected]310ebd6302011-10-10 19:06:281102WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:261103 return static_cast<WebKit::WebView*>(webwidget());
1104}
1105
[email protected]ea2fb972013-08-07 05:44:261106#if defined(ENABLE_PLUGINS)
1107void RenderViewImpl::PepperInstanceCreated(PepperPluginInstanceImpl* instance) {
1108 active_pepper_instances_.insert(instance);
1109}
1110
1111void RenderViewImpl::PepperInstanceDeleted(PepperPluginInstanceImpl* instance) {
1112 active_pepper_instances_.erase(instance);
1113
1114 if (pepper_last_mouse_event_target_ == instance)
1115 pepper_last_mouse_event_target_ = NULL;
1116 if (focused_pepper_plugin_ == instance)
1117 PepperFocusChanged(instance, false);
1118}
1119
1120void RenderViewImpl::PepperDidChangeCursor(
1121 PepperPluginInstanceImpl* instance,
1122 const WebKit::WebCursorInfo& cursor) {
1123 // Update the cursor appearance immediately if the requesting plugin is the
1124 // one which receives the last mouse event. Otherwise, the new cursor won't be
1125 // picked up until the plugin gets the next input event. That is bad if, e.g.,
1126 // the plugin would like to set an invisible cursor when there isn't any user
1127 // input for a while.
1128 if (instance == pepper_last_mouse_event_target_)
1129 didChangeCursor(cursor);
1130}
1131
1132void RenderViewImpl::PepperDidReceiveMouseEvent(
1133 PepperPluginInstanceImpl* instance) {
1134 pepper_last_mouse_event_target_ = instance;
1135}
1136
1137void RenderViewImpl::PepperFocusChanged(PepperPluginInstanceImpl* instance,
1138 bool focused) {
1139 if (focused)
1140 focused_pepper_plugin_ = instance;
1141 else if (focused_pepper_plugin_ == instance)
1142 focused_pepper_plugin_ = NULL;
1143
1144 UpdateTextInputType();
1145 UpdateSelectionBounds();
1146}
1147
1148void RenderViewImpl::PepperTextInputTypeChanged(
1149 PepperPluginInstanceImpl* instance) {
1150 if (instance != focused_pepper_plugin_)
1151 return;
1152
1153 UpdateTextInputType();
1154 if (renderer_accessibility_)
1155 renderer_accessibility_->FocusedNodeChanged(WebNode());
1156}
1157
1158void RenderViewImpl::PepperCaretPositionChanged(
1159 PepperPluginInstanceImpl* instance) {
1160 if (instance != focused_pepper_plugin_)
1161 return;
1162 UpdateSelectionBounds();
1163}
1164
1165void RenderViewImpl::PepperCancelComposition(
1166 PepperPluginInstanceImpl* instance) {
1167 if (instance != focused_pepper_plugin_)
1168 return;
1169 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));;
1170#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
1171 UpdateCompositionInfo(true);
1172#endif
1173}
1174
1175void RenderViewImpl::PepperSelectionChanged(
1176 PepperPluginInstanceImpl* instance) {
1177 if (instance != focused_pepper_plugin_)
1178 return;
1179 SyncSelectionIfRequired();
1180}
1181
1182RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
1183 PepperPluginInstanceImpl* plugin) {
1184 GURL active_url;
1185 if (webview() && webview()->mainFrame())
1186 active_url = GURL(webview()->mainFrame()->document().url());
1187 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
1188 routing_id_, plugin, active_url, screen_info_);
1189 widget->show(WebKit::WebNavigationPolicyIgnore);
1190 return widget;
1191}
1192
1193void RenderViewImpl::PepperPluginCreated(RendererPpapiHost* host) {
1194 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
1195 DidCreatePepperPlugin(host));
1196}
1197
1198bool RenderViewImpl::GetPepperCaretBounds(gfx::Rect* rect) {
1199 if (!focused_pepper_plugin_)
1200 return false;
1201 *rect = focused_pepper_plugin_->GetCaretBounds();
1202 return true;
1203}
1204
1205bool RenderViewImpl::IsPepperAcceptingCompositionEvents() const {
1206 if (!focused_pepper_plugin_)
1207 return false;
1208 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
1209}
1210
[email protected]c42de732013-02-16 06:26:311211void RenderViewImpl::PluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:421212 base::ProcessId plugin_pid) {
1213 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path, plugin_pid));
initial.commit09911bf2008-07-26 23:55:291214}
1215
[email protected]310ebd6302011-10-10 19:06:281216void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:261217 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:301218 // If the renderer is visible, set initial visibility and focus state.
1219 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:341220#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:301221 delegate->SetContainerVisibility(true);
1222 if (webview() && webview()->isActive())
1223 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:341224#endif
[email protected]49232292010-09-03 19:07:301225 }
[email protected]784ea1ab2010-09-18 00:02:341226 // Plugins start assuming the content has focus (so that they work in
1227 // environments where RenderView isn't hosting them), so we always have to
1228 // set the initial state. See webplugin_delegate_impl.h for details.
1229 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:261230}
1231
[email protected]310ebd6302011-10-10 19:06:281232void RenderViewImpl::UnregisterPluginDelegate(
1233 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:261234 plugin_delegates_.erase(delegate);
1235}
[email protected]d8fd6fa2010-02-01 15:54:261236
[email protected]310ebd6302011-10-10 19:06:281237bool RenderViewImpl::GetPluginInfo(const GURL& url,
1238 const GURL& page_url,
1239 const std::string& mime_type,
[email protected]d7bd3e52013-07-21 04:29:201240 WebPluginInfo* plugin_info,
[email protected]310ebd6302011-10-10 19:06:281241 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:081242 bool found = false;
1243 Send(new ViewHostMsg_GetPluginInfo(
1244 routing_id_, url, page_url, mime_type, &found, plugin_info,
1245 actual_mime_type));
1246 return found;
1247}
1248
[email protected]a80af12e2013-08-07 23:36:131249void RenderViewImpl::SimulateImeSetComposition(
1250 const string16& text,
1251 const std::vector<WebKit::WebCompositionUnderline>& underlines,
1252 int selection_start,
1253 int selection_end) {
1254 OnImeSetComposition(text, underlines, selection_start, selection_end);
1255}
1256
1257void RenderViewImpl::SimulateImeConfirmComposition(
1258 const string16& text,
[email protected]db4fc1e2013-09-06 20:01:511259 const gfx::Range& replacement_range) {
[email protected]a80af12e2013-08-07 23:36:131260 OnImeConfirmComposition(text, replacement_range, false);
1261}
1262
1263#if defined(OS_WIN)
1264void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
1265 if (focused)
1266 focused_plugin_id_ = plugin_id;
1267 else
1268 focused_plugin_id_ = -1;
1269}
1270#endif
1271
1272#if defined(OS_MACOSX)
1273void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
1274 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
1275}
1276
1277void RenderViewImpl::StartPluginIme() {
1278 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
1279 // This message can be sent during event-handling, and needs to be delivered
1280 // within that context.
1281 msg->set_unblock(true);
1282 Send(msg);
1283}
1284#endif // defined(OS_MACOSX)
1285
1286#endif // ENABLE_PLUGINS
1287
[email protected]7a1ec28a2012-03-28 21:10:241288void RenderViewImpl::TransferActiveWheelFlingAnimation(
1289 const WebKit::WebActiveWheelFlingParameters& params) {
1290 if (webview())
1291 webview()->transferActiveWheelFlingAnimation(params);
1292}
1293
[email protected]8fe8f742012-06-14 00:36:081294bool RenderViewImpl::HasIMETextFocus() {
1295 return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
1296}
1297
[email protected]310ebd6302011-10-10 19:06:281298bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:271299 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:271300 if (main_frame)
[email protected]e9ff79c2012-10-19 21:31:261301 GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:261302
[email protected]676126f72011-01-15 00:03:511303 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
1304 RenderViewObserver* observer;
1305 while ((observer = it.GetNext()) != NULL)
1306 if (observer->OnMessageReceived(message))
1307 return true;
[email protected]b2abac72009-02-26 12:39:281308
[email protected]a95986a82010-12-24 06:19:281309 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:401310 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:281311 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
[email protected]c084330e02013-04-27 01:08:151312 IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy)
1313 IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut)
1314 IPC_MESSAGE_HANDLER(InputMsg_Delete, OnDelete)
1315 IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand)
1316 IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret)
1317 IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste)
1318 IPC_MESSAGE_HANDLER(InputMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
1319 IPC_MESSAGE_HANDLER(InputMsg_Redo, OnRedo)
1320 IPC_MESSAGE_HANDLER(InputMsg_Replace, OnReplace)
1321 IPC_MESSAGE_HANDLER(InputMsg_ReplaceMisspelling, OnReplaceMisspelling)
1322 IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect,
1323 OnScrollFocusedEditableNodeIntoRect)
1324 IPC_MESSAGE_HANDLER(InputMsg_SelectAll, OnSelectAll)
1325 IPC_MESSAGE_HANDLER(InputMsg_SelectRange, OnSelectRange)
1326 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
1327 OnSetEditCommandsForNextKeyEvent)
1328 IPC_MESSAGE_HANDLER(InputMsg_Undo, OnUndo)
1329 IPC_MESSAGE_HANDLER(InputMsg_Unselect, OnUnselect)
initial.commit09911bf2008-07-26 23:55:291330 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
1331 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:561332 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
[email protected]25bcc8f2013-01-09 02:49:251333 IPC_MESSAGE_HANDLER(ViewMsg_SetName, OnSetName)
[email protected]45a599062012-09-07 20:09:061334 IPC_MESSAGE_HANDLER(ViewMsg_SetEditableSelectionOffsets,
1335 OnSetEditableSelectionOffsets)
1336 IPC_MESSAGE_HANDLER(ViewMsg_SetCompositionFromExistingText,
1337 OnSetCompositionFromExistingText)
1338 IPC_MESSAGE_HANDLER(ViewMsg_ExtendSelectionAndDelete,
1339 OnExtendSelectionAndDelete)
initial.commit09911bf2008-07-26 23:55:291340 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
1341 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:491342 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
[email protected]630e26b2008-10-14 22:55:171343 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:171344 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:411345 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:541346 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1347 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:291348 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:181349 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1350 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:291351 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]f546640b2012-05-15 00:03:491352 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
[email protected]1810e132009-03-24 23:35:481353 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:551354 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
1355 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
1356 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
1357 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
1358 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
1359 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
1360 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:451361 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:291362 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291363 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1364 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]38761452012-10-18 16:31:591365 IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone)
initial.commit09911bf2008-07-26 23:55:291366 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:511367 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
1368 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:291369 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:041370 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:151371 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:291372 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1373 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]30f75e62009-02-25 22:01:001374 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:161375 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:141376 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:251377 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1378 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:471379 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:341380 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:101381 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1382 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511383 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:561384 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]77829642012-05-15 14:47:171385 IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent,
1386 OnOrientationChangeEvent)
[email protected]81375e872012-01-11 21:40:361387 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:341388 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]a0c7153e2009-12-09 14:36:331389 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
1390 OnCustomContextMenuAction)
[email protected]18d5be92011-07-25 18:00:191391 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1392 OnGetAllSavableResourceLinksForCurrentPage)
1393 IPC_MESSAGE_HANDLER(
1394 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1395 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]521b2482011-01-15 00:10:101396 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]47822262013-04-23 17:22:361397 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
[email protected]f0557932011-01-25 20:20:511398 // TODO(viettrungluu): Move to a separate message filter.
[email protected]9e1ad4b2011-08-14 16:49:191399 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
1400 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:181401 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]c7654a232013-06-12 21:04:441402#if defined(OS_ANDROID)
[email protected]7f3c7af2011-10-20 22:52:511403 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]da816272013-05-15 21:31:171404#endif
[email protected]2a84f9d2012-06-05 21:50:431405 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode)
[email protected]7cc78902012-12-06 02:32:261406 IPC_MESSAGE_HANDLER(ViewMsg_DisownOpener, OnDisownOpener)
[email protected]55750b32012-09-21 14:05:031407#if defined(OS_ANDROID)
[email protected]c084330e02013-04-27 01:08:151408 IPC_MESSAGE_HANDLER(InputMsg_ActivateNearestFindResult,
[email protected]55750b32012-09-21 14:05:031409 OnActivateNearestFindResult)
1410 IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects)
1411 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
[email protected]9b7d11e2012-10-08 19:24:141412 IPC_MESSAGE_HANDLER(ViewMsg_UndoScrollFocusedEditableNodeIntoView,
1413 OnUndoScrollFocusedEditableNodeIntoRect)
[email protected]452b4a92013-03-28 21:24:381414 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState,
1415 OnUpdateTopControlsState)
[email protected]55750b32012-09-21 14:05:031416#elif defined(OS_MACOSX)
[email protected]c084330e02013-04-27 01:08:151417 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]55750b32012-09-21 14:05:031418 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1419 OnPluginImeCompositionCompleted)
1420 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1421 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
1422 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
1423 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
1424#endif
[email protected]f9526d12012-10-18 01:55:031425 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB,
1426 OnReleaseDisambiguationPopupDIB)
[email protected]c9bc8f12012-12-15 22:20:091427 IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted,
1428 OnWindowSnapshotCompleted)
[email protected]9e1ad4b2011-08-14 16:49:191429
initial.commit09911bf2008-07-26 23:55:291430 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281431 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291432 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401433
1434 if (!msg_is_ok) {
1435 // The message had a handler, but its deserialization failed.
1436 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:281437 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:401438 }
1439
[email protected]a95986a82010-12-24 06:19:281440 return handled;
initial.commit09911bf2008-07-26 23:55:291441}
1442
[email protected]310ebd6302011-10-10 19:06:281443void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]8bf1048012012-02-08 01:22:181444 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:291445 if (!webview())
1446 return;
1447
[email protected]440a0e52011-09-13 17:38:581448 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
1449
[email protected]007733c2011-11-17 00:34:071450 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:031451
1452 // If this is a stale back/forward (due to a recent navigation the browser
1453 // didn't know about), ignore it.
1454 if (IsBackForwardToStaleEntry(params, is_reload))
1455 return;
1456
[email protected]992db4c2011-05-12 15:37:151457 // Swap this renderer back in if necessary.
[email protected]961541a92012-06-01 21:15:281458 if (is_swapped_out_) {
1459 // We marked the view as hidden when swapping the view out, so be sure to
1460 // reset the visibility state before navigating to the new URL.
1461 webview()->setVisibilityState(visibilityState(), false);
[email protected]890b06ca2012-12-13 21:07:361462
1463 // If this is an attempt to reload while we are swapped out, we should not
1464 // reload swappedout://, but the previous page, which is stored in
1465 // params.state. Setting is_reload to false will treat this like a back
1466 // navigation to accomplish that.
1467 is_reload = false;
1468
[email protected]0b059022013-07-03 22:50:091469 // We refresh timezone when a view is swapped in since timezone
1470 // can get out of sync when the system timezone is updated while
1471 // the view is swapped out.
1472 NotifyTimezoneChange(webview()->mainFrame());
1473
[email protected]992db4c2011-05-12 15:37:151474 SetSwappedOut(false);
[email protected]961541a92012-06-01 21:15:281475 }
[email protected]992db4c2011-05-12 15:37:151476
[email protected]60d6cca2013-04-30 08:47:131477 if (params.should_clear_history_list) {
1478 CHECK_EQ(params.pending_history_list_offset, -1);
1479 CHECK_EQ(params.current_history_list_offset, -1);
1480 CHECK_EQ(params.current_history_list_length, 0);
1481 }
[email protected]3cc72b12010-03-18 23:03:001482 history_list_offset_ = params.current_history_list_offset;
1483 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:031484 if (history_list_length_ >= 0)
1485 history_page_ids_.resize(history_list_length_, -1);
1486 if (params.pending_history_list_offset >= 0 &&
1487 params.pending_history_list_offset < history_list_length_)
1488 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:001489
[email protected]e9ff79c2012-10-19 21:31:261490 GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:291491
[email protected]3027cf02013-01-24 08:16:581492 WebFrame* frame = webview()->mainFrame();
1493 if (!params.frame_to_navigate.empty()) {
1494 frame = webview()->findFrameByName(
1495 WebString::fromUTF8(params.frame_to_navigate));
1496 CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate;
1497 }
1498
1499 if (is_reload && frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291500 // We cannot reload if we do not have any history state. This happens, for
1501 // example, when recovering from a crash. Our workaround here is a bit of
1502 // a hack since it means that reload after a crashed tab does not cause an
1503 // end-to-end cache validation.
1504 is_reload = false;
1505 }
1506
[email protected]3d2fd592012-11-30 02:05:501507 pending_navigation_params_.reset(new ViewMsg_Navigate_Params(params));
[email protected]48a5c772011-04-18 23:50:501508
[email protected]04d3c6e2009-05-22 17:00:131509 // If we are reloading, then WebKit will use the history state of the current
1510 // page, so we should just ignore any given history state. Otherwise, if we
1511 // have history state, then we need to navigate to it, which corresponds to a
1512 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551513 if (is_reload) {
[email protected]7c16976c2012-08-04 02:38:231514 bool reload_original_url =
1515 (params.navigation_type ==
1516 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]ecbf10d2010-02-18 13:03:291517 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:021518 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]7c16976c2012-08-04 02:38:231519
1520 if (reload_original_url)
[email protected]3027cf02013-01-24 08:16:581521 frame->reloadWithOverrideURL(params.url, true);
[email protected]7c16976c2012-08-04 02:38:231522 else
[email protected]3027cf02013-01-24 08:16:581523 frame->reload(ignore_cache);
[email protected]691aa2f2013-05-28 22:52:041524 } else if (params.page_state.IsValid()) {
[email protected]04d3c6e2009-05-22 17:00:131525 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581526 DCHECK_NE(params.page_id, -1);
[email protected]691aa2f2013-05-28 22:52:041527 WebHistoryItem item = PageStateToHistoryItem(params.page_state);
[email protected]bf692cd2012-11-14 19:10:021528 if (!item.isNull()) {
1529 // Ensure we didn't save the swapped out URL in UpdateState, since the
1530 // browser should never be telling us to navigate to swappedout://.
1531 CHECK(item.urlString() != WebString::fromUTF8(kSwappedOutURL));
[email protected]3027cf02013-01-24 08:16:581532 frame->loadHistoryItem(item);
[email protected]bf692cd2012-11-14 19:10:021533 }
[email protected]d1ef81d2012-07-24 11:39:361534 } else if (!params.base_url_for_data_url.is_empty()) {
1535 // A loadData request with a specified base URL.
1536 std::string mime_type, charset, data;
1537 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) {
[email protected]3027cf02013-01-24 08:16:581538 frame->loadData(
[email protected]d1ef81d2012-07-24 11:39:361539 WebData(data.c_str(), data.length()),
1540 WebString::fromUTF8(mime_type),
1541 WebString::fromUTF8(charset),
1542 params.base_url_for_data_url,
1543 params.history_url_for_data_url,
1544 false);
1545 } else {
1546 CHECK(false) <<
1547 "Invalid URL passed: " << params.url.possibly_invalid_spec();
1548 }
[email protected]04d3c6e2009-05-22 17:00:131549 } else {
1550 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281551 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291552
[email protected]e6f546c32009-07-01 17:12:551553 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:231554 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131555
[email protected]3027cf02013-01-24 08:16:581556 if (frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551557 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131558
[email protected]445e1042011-12-03 21:03:151559 if (params.referrer.url.is_valid()) {
1560 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
1561 params.referrer.policy,
1562 params.url,
1563 WebString::fromUTF8(params.referrer.url.spec()));
1564 if (!referrer.isEmpty())
1565 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:281566 }
[email protected]04d3c6e2009-05-22 17:00:131567
[email protected]52c68652010-12-07 17:47:041568 if (!params.extra_headers.empty()) {
1569 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1570 params.extra_headers.end(), "\n");
1571 i.GetNext(); ) {
1572 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1573 WebString::fromUTF8(i.values()));
1574 }
1575 }
[email protected]132e281a2012-07-31 18:32:441576
1577 if (params.is_post) {
1578 request.setHTTPMethod(WebString::fromUTF8("POST"));
1579
1580 // Set post data.
1581 WebHTTPBody http_body;
1582 http_body.initialize();
1583 http_body.appendData(WebData(
1584 reinterpret_cast<const char*>(
1585 &params.browser_initiated_post_data.front()),
1586 params.browser_initiated_post_data.size()));
1587 request.setHTTPBody(http_body);
1588 }
1589
[email protected]3027cf02013-01-24 08:16:581590 frame->loadRequest(request);
[email protected]198a95d62013-04-11 00:44:211591
1592 // If this is a cross-process navigation, the browser process will send
1593 // along the proper navigation start value.
1594 if (!params.browser_navigation_start.is_null() &&
1595 frame->provisionalDataSource()) {
1596 // browser_navigation_start is likely before this process existed, so we
1597 // can't use InterProcessTimeTicksConverter. Instead, the best we can do
1598 // is just ensure we don't report a bogus value in the future.
1599 base::TimeTicks navigation_start = std::min(
1600 base::TimeTicks::Now(), params.browser_navigation_start);
1601 double navigation_start_seconds =
1602 (navigation_start - base::TimeTicks()).InSecondsF();
1603 frame->provisionalDataSource()->setNavigationStartTime(
1604 navigation_start_seconds);
1605 }
[email protected]c0588052008-10-27 23:01:501606 }
1607
[email protected]77f17a82009-05-21 04:42:541608 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:071609 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:291610}
1611
[email protected]310ebd6302011-10-10 19:06:281612bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:031613 const ViewMsg_Navigate_Params& params,
1614 bool is_reload) {
1615 // Make sure this isn't a back/forward to an entry we have already cropped
1616 // or replaced from our history, before the browser knew about it. If so,
1617 // a new navigation has committed in the mean time, and we can ignore this.
[email protected]691aa2f2013-05-28 22:52:041618 bool is_back_forward = !is_reload && params.page_state.IsValid();
[email protected]d466b8a2011-07-15 21:48:031619
1620 // Note: if the history_list_length_ is 0 for a back/forward, we must be
1621 // restoring from a previous session. We'll update our state in OnNavigate.
1622 if (!is_back_forward || history_list_length_ <= 0)
1623 return false;
1624
1625 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
1626
1627 // Check for whether the forward history has been cropped due to a recent
1628 // navigation the browser didn't know about.
1629 if (params.pending_history_list_offset >= history_list_length_)
1630 return true;
1631
1632 // Check for whether this entry has been replaced with a new one.
1633 int expected_page_id =
1634 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:441635 if (expected_page_id > 0 && params.page_id != expected_page_id) {
1636 if (params.page_id < expected_page_id)
1637 return true;
1638
1639 // Otherwise we've removed an earlier entry and should have shifted all
1640 // entries left. For now, it's ok to lazily update the list.
1641 // TODO(creis): Notify all live renderers when we remove entries from
1642 // the front of the list, so that we don't hit this case.
1643 history_page_ids_[params.pending_history_list_offset] = params.page_id;
1644 }
[email protected]d466b8a2011-07-15 21:48:031645
1646 return false;
1647}
1648
initial.commit09911bf2008-07-26 23:55:291649// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:281650void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:441651 if (webview()) {
1652 WebFrame* main_frame = webview()->mainFrame();
1653 // Stop the alt error page fetcher. If we let it continue it may complete
1654 // and cause RenderViewHostManager to swap to this RenderView, even though
1655 // it may no longer be active.
1656 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
1657 StopAltErrorPageFetcher(main_frame->dataSource());
1658 main_frame->stopLoading();
1659 }
initial.commit09911bf2008-07-26 23:55:291660}
1661
[email protected]ecbf10d2010-02-18 13:03:291662// Reload current focused frame.
1663// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:281664void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291665 if (webview() && webview()->focusedFrame()) {
1666 // We always obey the cache (ignore_cache=false) here.
1667 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1668 // a cache-ignoring reload of the frame.
1669 webview()->focusedFrame()->reload(false);
1670 }
[email protected]1dda4022010-01-28 18:24:561671}
1672
[email protected]310ebd6302011-10-10 19:06:281673void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271674 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291675}
1676
[email protected]310ebd6302011-10-10 19:06:281677void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291678 // Check if there is a targeturl waiting to be sent.
1679 if (target_url_status_ == TARGET_PENDING) {
1680 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1681 pending_target_url_));
1682 }
1683
1684 target_url_status_ = TARGET_NONE;
1685}
1686
[email protected]310ebd6302011-10-10 19:06:281687void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291688 if (!webview())
1689 return;
1690
[email protected]5d4e36d2013-02-15 15:18:201691 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101692 WebNode current_node = context_menu_node_.isNull() ?
1693 GetFocusedNode() : context_menu_node_;
[email protected]f6b1856b2011-06-29 22:02:531694 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
[email protected]6dd17a8a2013-05-01 05:50:101695 current_node);
initial.commit09911bf2008-07-26 23:55:291696}
1697
[email protected]c084330e02013-04-27 01:08:151698void RenderViewImpl::OnCut() {
[email protected]a954bf72009-09-12 07:30:351699 if (!webview())
1700 return;
1701
[email protected]c084330e02013-04-27 01:08:151702 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101703 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"),
1704 GetFocusedNode());
[email protected]a954bf72009-09-12 07:30:351705}
[email protected]c084330e02013-04-27 01:08:151706
1707void RenderViewImpl::OnDelete() {
1708 if (!webview())
1709 return;
1710
[email protected]6dd17a8a2013-05-01 05:50:101711 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"),
1712 GetFocusedNode());
[email protected]c084330e02013-04-27 01:08:151713}
1714
1715void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
1716 const std::string& value) {
1717 if (!webview() || !webview()->focusedFrame())
1718 return;
1719
1720 webview()->focusedFrame()->executeCommand(
1721 WebString::fromUTF8(name), WebString::fromUTF8(value));
1722}
1723
1724void RenderViewImpl::OnMoveCaret(const gfx::Point& point) {
1725 if (!webview())
1726 return;
1727
1728 Send(new ViewHostMsg_MoveCaret_ACK(routing_id_));
1729
1730 webview()->focusedFrame()->moveCaretSelectionTowardsWindowPoint(point);
1731}
[email protected]a954bf72009-09-12 07:30:351732
[email protected]310ebd6302011-10-10 19:06:281733void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291734 if (!webview())
1735 return;
1736
[email protected]5d4e36d2013-02-15 15:18:201737 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101738 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"),
1739 GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:291740}
1741
[email protected]44bf7002011-10-16 02:46:151742void RenderViewImpl::OnPasteAndMatchStyle() {
1743 if (!webview())
1744 return;
1745
[email protected]5d4e36d2013-02-15 15:18:201746 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]44bf7002011-10-16 02:46:151747 webview()->focusedFrame()->executeCommand(
[email protected]6dd17a8a2013-05-01 05:50:101748 WebString::fromUTF8("PasteAndMatchStyle"), GetFocusedNode());
[email protected]44bf7002011-10-16 02:46:151749}
1750
[email protected]c084330e02013-04-27 01:08:151751void RenderViewImpl::OnRedo() {
1752 if (!webview())
1753 return;
1754
[email protected]6dd17a8a2013-05-01 05:50:101755 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"),
1756 GetFocusedNode());
[email protected]c084330e02013-04-27 01:08:151757}
1758
[email protected]310ebd6302011-10-10 19:06:281759void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291760 if (!webview())
1761 return;
1762
[email protected]1ff7a032010-02-03 02:46:031763 WebFrame* frame = webview()->focusedFrame();
1764 if (!frame->hasSelection())
1765 frame->selectWordAroundCaret();
[email protected]2365c642013-02-12 19:16:471766
[email protected]1ff7a032010-02-03 02:46:031767 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291768}
1769
[email protected]2365c642013-02-12 19:16:471770void RenderViewImpl::OnReplaceMisspelling(const string16& text) {
1771 if (!webview())
1772 return;
1773
1774 WebFrame* frame = webview()->focusedFrame();
1775 if (!frame->hasSelection())
1776 return;
1777
1778 frame->replaceMisspelledRange(text);
1779}
1780
[email protected]c084330e02013-04-27 01:08:151781void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1782 const gfx::Rect& rect) {
1783 WebKit::WebNode node = GetFocusedNode();
1784 if (!node.isNull()) {
1785 if (IsEditableNode(node)) {
1786 webview()->saveScrollAndScaleState();
1787 webview()->scrollFocusedNodeIntoRect(rect);
1788 }
1789 }
[email protected]25bcc8f2013-01-09 02:49:251790}
1791
[email protected]310ebd6302011-10-10 19:06:281792void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291793 if (!webview())
1794 return;
1795
[email protected]5d4e36d2013-02-15 15:18:201796 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]26aa0482009-09-30 16:55:271797 webview()->focusedFrame()->executeCommand(
[email protected]6dd17a8a2013-05-01 05:50:101798 WebString::fromUTF8("SelectAll"), GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:291799}
1800
[email protected]c084330e02013-04-27 01:08:151801void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1802 const gfx::Point& end) {
1803 if (!webview())
1804 return;
1805
1806 Send(new ViewHostMsg_SelectRange_ACK(routing_id_));
1807
1808 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1809 webview()->focusedFrame()->selectRange(start, end);
1810}
1811
1812void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
1813 const EditCommands& edit_commands) {
1814 edit_commands_ = edit_commands;
1815}
1816
1817void RenderViewImpl::OnUndo() {
1818 if (!webview())
1819 return;
1820
[email protected]6dd17a8a2013-05-01 05:50:101821 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"),
1822 GetFocusedNode());
[email protected]c084330e02013-04-27 01:08:151823}
1824
[email protected]45a599062012-09-07 20:09:061825void RenderViewImpl::OnUnselect() {
1826 if (!webview())
1827 return;
1828
[email protected]5d4e36d2013-02-15 15:18:201829 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101830 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
1831 GetFocusedNode());
[email protected]45a599062012-09-07 20:09:061832}
1833
[email protected]c084330e02013-04-27 01:08:151834#if defined(OS_MACOSX)
1835void RenderViewImpl::OnCopyToFindPboard() {
1836 if (!webview())
1837 return;
1838
1839 // Since the find pasteboard supports only plain text, this can be simpler
1840 // than the |OnCopy()| case.
1841 WebFrame* frame = webview()->focusedFrame();
1842 if (frame->hasSelection()) {
1843 string16 selection = frame->selectionAsText();
1844 RenderThread::Get()->Send(
1845 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
1846 }
1847}
1848#endif
1849
1850void RenderViewImpl::OnSetName(const std::string& name) {
1851 if (!webview())
1852 return;
1853
1854 webview()->mainFrame()->setName(WebString::fromUTF8(name));
1855}
1856
[email protected]45a599062012-09-07 20:09:061857void RenderViewImpl::OnSetEditableSelectionOffsets(int start, int end) {
[email protected]5d4e36d2013-02-15 15:18:201858 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]0d1ebed12013-08-05 22:01:131859 if (!ShouldHandleImeEvent())
1860 return;
[email protected]66fca5bc2013-05-23 06:58:291861 ImeEventGuard guard(this);
[email protected]45a599062012-09-07 20:09:061862 webview()->setEditableSelectionOffsets(start, end);
1863}
1864
1865void RenderViewImpl::OnSetCompositionFromExistingText(
1866 int start, int end,
1867 const std::vector<WebKit::WebCompositionUnderline>& underlines) {
[email protected]0d1ebed12013-08-05 22:01:131868 if (!ShouldHandleImeEvent())
[email protected]45a599062012-09-07 20:09:061869 return;
[email protected]66fca5bc2013-05-23 06:58:291870 ImeEventGuard guard(this);
[email protected]45a599062012-09-07 20:09:061871 webview()->setCompositionFromExistingText(start, end, underlines);
1872}
1873
1874void RenderViewImpl::OnExtendSelectionAndDelete(int before, int after) {
[email protected]0d1ebed12013-08-05 22:01:131875 if (!ShouldHandleImeEvent())
[email protected]45a599062012-09-07 20:09:061876 return;
[email protected]66fca5bc2013-05-23 06:58:291877 ImeEventGuard guard(this);
[email protected]45a599062012-09-07 20:09:061878 webview()->extendSelectionAndDelete(before, after);
1879}
1880
[email protected]310ebd6302011-10-10 19:06:281881void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1882 int32 minimum_page_id) {
[email protected]e1ed5a12012-08-08 19:57:441883 DCHECK_GE(history_length, 0);
[email protected]9e1ad4b2011-08-14 16:49:191884 DCHECK(history_list_offset_ == history_list_length_ - 1);
[email protected]e1ed5a12012-08-08 19:57:441885 DCHECK_GE(minimum_page_id, -1);
[email protected]9e1ad4b2011-08-14 16:49:191886
1887 // Generate the new list.
1888 std::vector<int32> new_history_page_ids(history_length, -1);
1889 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1890 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1891 continue;
1892 new_history_page_ids.push_back(history_page_ids_[i]);
1893 }
1894 new_history_page_ids.swap(history_page_ids_);
1895
1896 // Update indexes.
1897 history_list_length_ = history_page_ids_.size();
1898 history_list_offset_ = history_list_length_ - 1;
1899}
1900
1901
[email protected]310ebd6302011-10-10 19:06:281902void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291903 if (!webview())
1904 return;
[email protected]26aa0482009-09-30 16:55:271905 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291906}
1907
[email protected]54ca3ca892011-06-07 21:14:541908#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281909void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331910 if (!webview())
1911 return;
1912 if (in_live_resize)
1913 webview()->willStartLiveResize();
1914 else
1915 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541916}
1917#endif
1918
[email protected]9b7d11e2012-10-08 19:24:141919#if defined(OS_ANDROID)
1920void RenderViewImpl::OnUndoScrollFocusedEditableNodeIntoRect() {
1921 const WebNode node = GetFocusedNode();
1922 if (!node.isNull() && IsEditableNode(node))
1923 webview()->restoreScrollAndScaleState();
1924}
1925#endif
1926
initial.commit09911bf2008-07-26 23:55:291927///////////////////////////////////////////////////////////////////////////////
1928
1929// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281930void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451931 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291932 DCHECK(ds);
1933
[email protected]726985e22009-06-18 21:09:281934 const WebURLRequest& request = ds->request();
1935 const WebURLRequest& original_request = ds->originalRequest();
1936 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291937
[email protected]007733c2011-11-17 00:34:071938 DocumentState* document_state = DocumentState::FromDataSource(ds);
1939 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e20b88d2013-04-09 15:28:371940 InternalDocumentStateData* internal_data =
1941 InternalDocumentStateData::FromDocumentState(document_state);
initial.commit09911bf2008-07-26 23:55:291942
1943 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281944 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291945 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051946 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291947 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071948 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191949 params.socket_address.set_host(response.remoteIPAddress().utf8());
1950 params.socket_address.set_port(response.remotePort());
[email protected]e07ddafe2013-03-05 21:03:361951 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
1952 if (extra_data) {
1953 params.was_fetched_via_proxy = extra_data->was_fetched_via_proxy();
1954 }
[email protected]af15bed2010-08-25 21:12:091955 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e20b88d2013-04-09 15:28:371956 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291957
1958 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:311959 params.url = GetLoadingUrl(frame);
[email protected]809be032013-03-19 01:56:561960 DCHECK(!is_swapped_out_ || params.url == GURL(kSwappedOutURL));
initial.commit09911bf2008-07-26 23:55:291961
[email protected]5f9b8712011-11-23 08:55:571962 if (frame->document().baseURL() != params.url)
1963 params.base_url = frame->document().baseURL();
1964
[email protected]726985e22009-06-18 21:09:281965 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241966 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041967 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291968
[email protected]e20b88d2013-04-09 15:28:371969 params.searchable_form_url = internal_data->searchable_form_url();
1970 params.searchable_form_encoding = internal_data->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291971
initial.commit09911bf2008-07-26 23:55:291972 params.gesture = navigation_gesture_;
1973 navigation_gesture_ = NavigationGestureUnknown;
1974
[email protected]0f38dc4552011-02-25 11:24:001975 // Make navigation state a part of the FrameNavigate message so that commited
1976 // entry had it at all times.
[email protected]691aa2f2013-05-28 22:52:041977 WebHistoryItem item = frame->currentHistoryItem();
1978 if (item.isNull()) {
1979 item.initialize();
1980 item.setURLString(request.url().spec().utf16());
[email protected]0f38dc4552011-02-25 11:24:001981 }
[email protected]691aa2f2013-05-28 22:52:041982 params.page_state = HistoryItemToPageState(item);
[email protected]0f38dc4552011-02-25 11:24:001983
[email protected]dd7daa82009-08-10 05:46:451984 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291985 // Top-level navigation.
1986
[email protected]d00a7972012-08-07 06:09:581987 // Reset the zoom limits in case a plugin had changed them previously. This
1988 // will also call us back which will cause us to send a message to
1989 // update WebContentsImpl.
[email protected]7940b8e2013-07-25 23:08:491990 webview()->zoomLimitsChanged(ZoomFactorToZoomLevel(kMinimumZoomFactor),
1991 ZoomFactorToZoomLevel(kMaximumZoomFactor));
[email protected]d00a7972012-08-07 06:09:581992
[email protected]b75b8292010-10-01 07:28:251993 // Set zoom level, but don't do it for full-page plugin since they don't use
1994 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011995 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541996 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251997 if (webview()->mainFrame()->document().isPluginDocument()) {
1998 // Reset the zoom levels for plugins.
[email protected]91219702013-09-18 07:33:511999 webview()->setZoomLevel(0);
[email protected]b75b8292010-10-01 07:28:252000 } else {
2001 if (host_zoom != host_zoom_levels_.end())
[email protected]91219702013-09-18 07:33:512002 webview()->setZoomLevel(host_zoom->second);
[email protected]b75b8292010-10-01 07:28:252003 }
2004
[email protected]f85f0702010-01-30 09:31:012005 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:512006 // This zoom level was merely recorded transiently for this load. We can
2007 // erase it now. If at some point we reload this page, the browser will
2008 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:012009 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:512010 }
2011
initial.commit09911bf2008-07-26 23:55:292012 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:552013 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:292014
[email protected]daa8c58e2009-06-15 17:21:102015 params.transition = navigation_state->transition_type();
[email protected]e9ff79c2012-10-19 21:31:262016 if (!PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:292017 // If the main frame does a load, it should not be reported as a subframe
2018 // navigation. This can occur in the following case:
2019 // 1. You're on a site with frames.
2020 // 2. You do a subframe navigation. This is stored with transition type
2021 // MANUAL_SUBFRAME.
2022 // 3. You navigate to some non-frame site, say, google.com.
2023 // 4. You navigate back to the page from step 2. Since it was initially
2024 // MANUAL_SUBFRAME, it will be that same transition type here.
2025 // We don't want that, because any navigation that changes the toplevel
2026 // frame should be tracked as a toplevel navigation (this allows us to
2027 // update the URL bar, etc).
[email protected]e9ff79c2012-10-19 21:31:262028 params.transition = PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:292029 }
2030
[email protected]a00a2e32013-07-31 05:08:332031 // If the page contained a client redirect (meta refresh, document.loc...),
2032 // set the referrer and transition appropriately.
2033 if (ds->isClientRedirect()) {
2034 params.referrer = Referrer(params.redirects[0],
2035 GetReferrerPolicyFromRequest(frame, ds->request()));
[email protected]e9ff79c2012-10-19 21:31:262036 params.transition = static_cast<PageTransition>(
2037 params.transition | PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:292038 } else {
2039 // Bug 654101: the referrer will be empty on https->http transitions. It
2040 // would be nice if we could get the real referrer from somewhere.
[email protected]44e55b012013-07-23 14:21:562041 params.referrer = GetReferrerFromRequest(frame, original_request);
initial.commit09911bf2008-07-26 23:55:292042 }
2043
[email protected]726985e22009-06-18 21:09:282044 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:052045 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:292046 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:052047 params.post_id = ExtractPostId(item);
2048 }
initial.commit09911bf2008-07-26 23:55:292049
[email protected]bf70edce2012-06-20 22:32:222050 // Send the user agent override back.
[email protected]e20b88d2013-04-09 15:28:372051 params.is_overriding_user_agent = internal_data->is_overriding_user_agent();
[email protected]bf70edce2012-06-20 22:32:222052
[email protected]7c16976c2012-08-04 02:38:232053 // Track the URL of the original request.
2054 params.original_request_url = original_request.url();
2055
[email protected]60d6cca2013-04-30 08:47:132056 params.history_list_was_cleared =
2057 navigation_state->history_list_was_cleared();
2058
[email protected]c2a797d2009-09-21 16:46:322059 // Save some histogram data so we can compute the average memory used per
2060 // page load of the glyphs.
2061 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
[email protected]6bd867b2013-07-24 22:10:202062 WebKit::WebGlyphCache::pageCount());
[email protected]c2a797d2009-09-21 16:46:322063
[email protected]15cf526b2010-02-12 06:33:492064 // This message needs to be sent before any of allowScripts(),
2065 // allowImages(), allowPlugins() is called for the new page, so that when
2066 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
2067 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:292068 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
2069 } else {
2070 // Subframe navigation: the type depends on whether this navigation
2071 // generated a new session history entry. When they do generate a session
2072 // history entry, it means the user initiated the navigation and we should
2073 // mark it as such. This test checks if this is the first time UpdateURL
2074 // has been called since WillNavigateToURL was called to initiate the load.
2075 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]e9ff79c2012-10-19 21:31:262076 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:292077 else
[email protected]e9ff79c2012-10-19 21:31:262078 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:292079
[email protected]60d6cca2013-04-30 08:47:132080 DCHECK(!navigation_state->history_list_was_cleared());
2081 params.history_list_was_cleared = false;
2082
initial.commit09911bf2008-07-26 23:55:292083 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
2084 }
2085
2086 last_page_id_sent_to_browser_ =
2087 std::max(last_page_id_sent_to_browser_, page_id_);
2088
2089 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:102090 // we don't want the transition type to persist. Just clear it.
[email protected]e9ff79c2012-10-19 21:31:262091 navigation_state->set_transition_type(PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:292092}
2093
2094// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:282095void RenderViewImpl::UpdateTitle(WebFrame* frame,
2096 const string16& title,
2097 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:462098 // Ignore all but top level navigations.
2099 if (frame->parent())
2100 return;
2101
[email protected]91a2aea2013-07-08 23:14:392102 base::debug::TraceLog::GetInstance()->UpdateProcessLabel(
2103 routing_id_, UTF16ToUTF8(title));
2104
[email protected]e9ff79c2012-10-19 21:31:262105 string16 shortened_title = title.substr(0, kMaxTitleChars);
[email protected]a49e10b2011-08-01 23:57:462106 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
2107 title_direction));
initial.commit09911bf2008-07-26 23:55:292108}
2109
[email protected]310ebd6302011-10-10 19:06:282110void RenderViewImpl::UpdateEncoding(WebFrame* frame,
2111 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:292112 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:272113 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:292114 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:302115 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:292116 last_encoding_name_ = encoding_name;
2117
[email protected]e38f40152008-09-12 23:08:302118 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:292119 }
2120}
2121
[email protected]e15f680732010-11-23 22:30:202122// Sends the last committed session history state to the browser so it will be
2123// saved before we navigate to a new page. This must be called *before* the
2124// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:282125void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:292126 // If we have a valid page ID at this point, then it corresponds to the page
2127 // we are navigating away from. Otherwise, this is the first navigation, so
2128 // there is no past session history to record.
2129 if (page_id_ == -1)
2130 return;
2131
[email protected]ca948a22009-06-25 19:36:172132 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:272133 webview()->mainFrame()->previousHistoryItem();
[email protected]6459800a2012-03-27 23:57:052134 SendUpdateState(item);
2135}
2136
2137void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
[email protected]ca948a22009-06-25 19:36:172138 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292139 return;
[email protected]ca948a22009-06-25 19:36:172140
[email protected]e9ff79c2012-10-19 21:31:262141 // Don't send state updates for kSwappedOutURL.
2142 if (item.urlString() == WebString::fromUTF8(kSwappedOutURL))
[email protected]6459800a2012-03-27 23:57:052143 return;
2144
[email protected]ca948a22009-06-25 19:36:172145 Send(new ViewHostMsg_UpdateState(
[email protected]691aa2f2013-05-28 22:52:042146 routing_id_, page_id_, HistoryItemToPageState(item)));
initial.commit09911bf2008-07-26 23:55:292147}
2148
[email protected]310ebd6302011-10-10 19:06:282149void RenderViewImpl::OpenURL(WebFrame* frame,
2150 const GURL& url,
[email protected]445e1042011-12-03 21:03:152151 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:282152 WebNavigationPolicy policy) {
[email protected]e2caa032012-11-15 23:29:182153 ViewHostMsg_OpenURL_Params params;
2154 params.url = url;
2155 params.referrer = referrer;
2156 params.disposition = NavigationPolicyToDisposition(policy);
2157 params.frame_id = frame->identifier();
[email protected]b4c09692012-12-13 19:15:462158 WebDataSource* ds = frame->provisionalDataSource();
2159 if (ds) {
[email protected]866fa2cc2013-07-22 22:19:522160 params.should_replace_current_entry = ds->replacesCurrentHistoryItem();
[email protected]b4c09692012-12-13 19:15:462161 } else {
[email protected]866fa2cc2013-07-22 22:19:522162 params.should_replace_current_entry = false;
[email protected]b4c09692012-12-13 19:15:462163 }
[email protected]e7f2e7c2013-07-15 09:41:302164 params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]00323f02013-07-24 15:47:412165 if (GetContentClient()->renderer()->AllowPopup())
2166 params.user_gesture = true;
[email protected]e7f2e7c2013-07-15 09:41:302167
2168 if (policy == WebKit::WebNavigationPolicyNewBackgroundTab ||
2169 policy == WebKit::WebNavigationPolicyNewForegroundTab ||
2170 policy == WebKit::WebNavigationPolicyNewWindow ||
2171 policy == WebKit::WebNavigationPolicyNewPopup) {
2172 WebUserGestureIndicator::consumeUserGesture();
2173 }
[email protected]e2caa032012-11-15 23:29:182174
2175 Send(new ViewHostMsg_OpenURL(routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172176}
2177
[email protected]79dbc662009-09-04 05:42:512178// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:292179
[email protected]310ebd6302011-10-10 19:06:282180void RenderViewImpl::LoadNavigationErrorPage(
2181 WebFrame* frame,
2182 const WebURLRequest& failed_request,
2183 const WebURLError& error,
2184 const std::string& html,
2185 bool replace) {
[email protected]d7b175e2011-10-11 15:31:582186 std::string alt_html;
2187 const std::string* error_html;
2188
2189 if (!html.empty()) {
2190 error_html = &html;
2191 } else {
[email protected]e9ff79c2012-10-19 21:31:262192 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]8da4d262013-04-23 05:15:532193 frame, failed_request, error, &alt_html, NULL);
[email protected]d7b175e2011-10-11 15:31:582194 error_html = &alt_html;
2195 }
2196
2197 frame->loadHTMLString(*error_html,
[email protected]e9ff79c2012-10-19 21:31:262198 GURL(kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:252199 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:552200 replace);
initial.commit09911bf2008-07-26 23:55:292201}
2202
[email protected]e9ff79c2012-10-19 21:31:262203bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:282204 const string16& message,
2205 const string16& default_value,
2206 const GURL& frame_url,
2207 string16* result) {
initial.commit09911bf2008-07-26 23:55:292208 bool success = false;
[email protected]4f5ce842011-05-27 19:34:412209 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:292210 if (!result)
2211 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:292212
[email protected]12636df2009-09-28 22:32:212213 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
[email protected]688e2ee2013-09-12 20:48:142214 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:292215 return success;
2216}
2217
[email protected]310ebd6302011-10-10 19:06:282218bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:572219 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
2220 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
2221 // it is particularly important that we do not call willEnterModalLoop as
2222 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:442223 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2224 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:572225
2226 message->EnableMessagePumping(); // Runs a nested message loop.
2227 return Send(message);
2228}
2229
[email protected]c9bc8f12012-12-15 22:20:092230void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) {
2231 int id = next_snapshot_id_++;
2232 pending_snapshots_.insert(std::make_pair(id, callback));
2233 Send(new ViewHostMsg_GetWindowSnapshot(routing_id_, id));
2234}
2235
2236void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id,
2237 const gfx::Size& size, const std::vector<unsigned char>& png) {
2238 PendingSnapshotMap::iterator it = pending_snapshots_.find(snapshot_id);
2239 DCHECK(it != pending_snapshots_.end());
2240 it->second.Run(size, png);
2241 pending_snapshots_.erase(it);
2242}
2243
[email protected]48c9cf2d2009-09-16 16:47:522244// WebKit::WebViewClient ------------------------------------------------------
2245
[email protected]916dfb62012-03-05 03:39:372246WebView* RenderViewImpl::createView(
2247 WebFrame* creator,
2248 const WebURLRequest& request,
2249 const WebWindowFeatures& features,
2250 const WebString& frame_name,
2251 WebNavigationPolicy policy) {
[email protected]8ab04652010-06-12 02:47:262252 ViewHostMsg_CreateWindow_Params params;
2253 params.opener_id = routing_id_;
[email protected]af15bf22013-03-08 01:18:172254 params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]00323f02013-07-24 15:47:412255 if (GetContentClient()->renderer()->AllowPopup())
2256 params.user_gesture = true;
[email protected]8ab04652010-06-12 02:47:262257 params.window_container_type = WindowFeaturesToContainerType(features);
2258 params.session_storage_namespace_id = session_storage_namespace_id_;
[email protected]5cef23d2013-02-27 13:11:212259 if (frame_name != "_blank")
2260 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:112261 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:412262 params.opener_url = creator->document().url();
[email protected]931bc922013-09-11 21:42:572263 params.opener_top_level_frame_url = creator->top()->document().url();
[email protected]7f48b712013-01-25 01:48:302264 GURL security_url(creator->document().securityOrigin().toString().utf8());
2265 if (!security_url.is_valid())
2266 security_url = GURL();
2267 params.opener_security_origin = security_url;
[email protected]f92ce2b2012-03-06 18:02:592268 params.opener_suppressed = creator->willSuppressOpenerInNewFrame();
2269 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]44e55b012013-07-23 14:21:562270 if (!request.isNull()) {
[email protected]41e65502011-01-21 09:29:112271 params.target_url = request.url();
[email protected]44e55b012013-07-23 14:21:562272 params.referrer = GetReferrerFromRequest(creator, request);
2273 }
[email protected]453c1b22013-07-23 09:31:482274 params.features = features;
[email protected]8ab04652010-06-12 02:47:262275
[email protected]48c9cf2d2009-09-16 16:47:522276 int32 routing_id = MSG_ROUTING_NONE;
[email protected]227692c52013-05-31 22:43:042277 int32 main_frame_routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:562278 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:342279 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:522280
[email protected]380244092011-10-07 17:26:272281 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:262282 new ViewHostMsg_CreateWindow(params,
2283 &routing_id,
[email protected]227692c52013-05-31 22:43:042284 &main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:562285 &surface_id,
[email protected]8ab04652010-06-12 02:47:262286 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:212287 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:522288 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522289
[email protected]af15bf22013-03-08 01:18:172290 WebUserGestureIndicator::consumeUserGesture();
[email protected]c59262422012-11-30 21:20:522291
[email protected]3184f90b2013-05-01 18:17:532292 WebPreferences transferred_preferences = webkit_preferences_;
[email protected]9115d5f2013-03-24 04:37:412293
2294 // Unless accelerated compositing has been explicitly disabled from the
2295 // command line (e.g. via the blacklist or about:flags) re-enable it for
2296 // new views that get spawned by this view. This gets around the issue that
2297 // background extension pages disable accelerated compositing via web prefs
2298 // but can themselves spawn a visible render view which should be allowed
2299 // use gpu acceleration.
2300 if (!webkit_preferences_.accelerated_compositing_enabled) {
2301 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2302 if (!command_line.HasSwitch(switches::kDisableAcceleratedCompositing))
2303 transferred_preferences.accelerated_compositing_enabled = true;
2304 }
2305
[email protected]310ebd6302011-10-10 19:06:282306 RenderViewImpl* view = RenderViewImpl::Create(
[email protected]310ebd6302011-10-10 19:06:282307 routing_id_,
2308 renderer_preferences_,
[email protected]9115d5f2013-03-24 04:37:412309 transferred_preferences,
[email protected]310ebd6302011-10-10 19:06:282310 routing_id,
[email protected]227692c52013-05-31 22:43:042311 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:562312 surface_id,
[email protected]310ebd6302011-10-10 19:06:282313 cloned_session_storage_namespace_id,
[email protected]5cef23d2013-02-27 13:11:212314 string16(), // WebCore will take care of setting the correct name.
[email protected]1ac10dca2013-08-20 20:47:042315 true, // is_renderer_created
2316 false, // swapped_out
2317 false, // hidden
2318 1, // next_page_id
[email protected]842f10652012-06-06 01:54:042319 screen_info_,
[email protected]34bb3ac2013-03-08 02:41:282320 accessibility_mode_,
2321 allow_partial_swap_);
[email protected]8ab04652010-06-12 02:47:262322 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:522323
[email protected]007a848b2009-10-26 15:55:462324 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:592325 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:462326
[email protected]48c9cf2d2009-09-16 16:47:522327 // Copy over the alternate error page URL so we can have alt error pages in
2328 // the new render view (we don't need the browser to send the URL back down).
2329 view->alternate_error_page_url_ = alternate_error_page_url_;
2330
2331 return view->webview();
2332}
2333
[email protected]310ebd6302011-10-10 19:06:282334WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:412335 RenderWidget* widget =
[email protected]842f10652012-06-06 01:54:042336 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]48c9cf2d2009-09-16 16:47:522337 return widget->webwidget();
2338}
2339
[email protected]310ebd6302011-10-10 19:06:282340WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:082341 const WebPopupMenuInfo& popup_menu_info,
2342 WebExternalPopupMenuClient* popup_menu_client) {
[email protected]8de2f882012-05-30 00:32:272343 // An IPC message is sent to the browser to build and display the actual
2344 // popup. The user could have time to click a different select by the time
2345 // the popup is shown. In that case external_popup_menu_ is non NULL.
2346 // By returning NULL in that case, we instruct WebKit to cancel that new
2347 // popup. So from the user perspective, only the first one will show, and
2348 // will have to close the first one before another one can be shown.
[email protected]59383c782013-04-17 16:43:272349 if (external_popup_menu_)
[email protected]8de2f882012-05-30 00:32:272350 return NULL;
[email protected]caf706f2010-10-26 17:54:082351 external_popup_menu_.reset(
2352 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
2353 return external_popup_menu_.get();
2354}
2355
[email protected]23367482013-06-27 21:06:542356WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() {
[email protected]5f2aa722013-08-07 16:59:412357 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:102358 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:342359}
2360
[email protected]fd8eb742013-08-22 00:42:002361bool RenderViewImpl::shouldReportDetailedMessageForSource(
2362 const WebString& source) {
2363 return GetContentClient()->renderer()->ShouldReportDetailedMessageForSource(
2364 source);
2365}
2366
[email protected]310ebd6302011-10-10 19:06:282367void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:522368 const WebConsoleMessage& message, const WebString& source_name,
[email protected]fd8eb742013-08-22 00:42:002369 unsigned source_line, const WebString& stack_trace) {
[email protected]d09df4b2011-04-11 19:01:082370 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:512371 switch (message.level) {
[email protected]80ac8942013-01-30 22:53:222372 case WebConsoleMessage::LevelDebug:
[email protected]d09df4b2011-04-11 19:01:082373 log_severity = logging::LOG_VERBOSE;
2374 break;
2375 case WebConsoleMessage::LevelLog:
2376 log_severity = logging::LOG_INFO;
2377 break;
2378 case WebConsoleMessage::LevelWarning:
2379 log_severity = logging::LOG_WARNING;
2380 break;
2381 case WebConsoleMessage::LevelError:
2382 log_severity = logging::LOG_ERROR;
2383 break;
2384 default:
2385 NOTREACHED();
2386 }
2387
[email protected]88b50b62013-09-01 23:05:062388 if (shouldReportDetailedMessageForSource(source_name)) {
2389 FOR_EACH_OBSERVER(
2390 RenderViewObserver,
2391 observers_,
2392 DetailedConsoleMessageAdded(message.text,
2393 source_name,
2394 stack_trace,
2395 source_line,
2396 static_cast<int32>(log_severity)));
2397 }
2398
[email protected]07fb8d52013-08-07 17:03:512399 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
2400 static_cast<int32>(log_severity),
2401 message.text,
2402 static_cast<int32>(source_line),
[email protected]88b50b62013-09-01 23:05:062403 source_name));
[email protected]48c9cf2d2009-09-16 16:47:522404}
2405
[email protected]310ebd6302011-10-10 19:06:282406void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]b0553c7e2012-09-19 21:36:112407 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2408 PrintPage(frame, handling_input_event_));
[email protected]48c9cf2d2009-09-16 16:47:522409}
2410
[email protected]310ebd6302011-10-10 19:06:282411WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:512412 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:022413}
2414
[email protected]310ebd6302011-10-10 19:06:282415bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:122416 const WebString& path,
2417 WebFileChooserCompletion* chooser_completion) {
2418 int id = enumeration_completion_id_++;
2419 enumeration_completions_[id] = chooser_completion;
2420 return Send(new ViewHostMsg_EnumerateDirectory(
2421 routing_id_,
2422 id,
[email protected]728c2ee2013-06-25 04:01:072423 base::FilePath::FromUTF16Unsafe(path)));
[email protected]8a58c1c2011-04-19 18:40:122424}
2425
[email protected]4b1146bc2012-07-10 18:46:032426void RenderViewImpl::initializeHelperPluginWebFrame(
2427 WebKit::WebHelperPlugin* plugin) {
[email protected]2f61bdd2013-07-02 18:38:472428 plugin->initializeFrame(main_render_frame_.get());
[email protected]4b1146bc2012-07-10 18:46:032429}
2430
[email protected]310ebd6302011-10-10 19:06:282431void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:522432 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:142433 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:522434 return;
2435 }
2436
2437 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:522438
2439 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:312440
2441 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:522442}
2443
[email protected]310ebd6302011-10-10 19:06:282444void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:522445 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:142446 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:522447 return;
2448 }
2449
2450 is_loading_ = false;
2451
2452 // NOTE: For now we're doing the safest thing, and sending out notification
2453 // when done loading. This currently isn't an issue as the favicon is only
2454 // displayed when done loading. Ideally we would send notification when
2455 // finished parsing the head, but webkit doesn't support that yet.
2456 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:522457 Send(new ViewHostMsg_DidStopLoading(routing_id_));
2458
[email protected]90109412010-12-15 17:14:242459 if (load_progress_tracker_ != NULL)
2460 load_progress_tracker_->DidStopLoading();
2461
[email protected]41225fe2013-03-29 05:32:022462 DidStopLoadingIcons();
2463
[email protected]93b9d692011-04-13 00:44:312464 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:522465}
2466
[email protected]310ebd6302011-10-10 19:06:282467void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
2468 double load_progress) {
[email protected]90109412010-12-15 17:14:242469 if (load_progress_tracker_ != NULL)
2470 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
2471}
2472
[email protected]550b0c92013-02-04 05:09:152473void RenderViewImpl::didCancelCompositionOnSelectionChange() {
2474 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
2475}
2476
[email protected]310ebd6302011-10-10 19:06:282477void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:082478 if (!handling_input_event_ && !handling_select_range_)
[email protected]5d4e36d2013-02-15 15:18:202479 return;
[email protected]d4cff272011-05-02 15:46:012480
[email protected]fca52022012-04-03 17:00:502481 if (is_empty_selection)
2482 selection_text_.clear();
2483
[email protected]b781ff282011-08-20 06:19:362484 SyncSelectionIfRequired();
[email protected]cb9e2632013-06-18 11:26:472485 UpdateTextInputType();
2486#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:132487 UpdateTextInputState(false, true);
[email protected]cb9e2632013-06-18 11:26:472488#endif
[email protected]04fc9482009-09-18 22:13:032489}
2490
[email protected]310ebd6302011-10-10 19:06:282491void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:122492 const std::string& name = UTF16ToUTF8(command_name);
2493 if (StartsWithASCII(name, "Move", true) ||
2494 StartsWithASCII(name, "Insert", true) ||
2495 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:032496 return;
[email protected]f1a29a02011-10-06 23:08:442497 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:032498}
2499
[email protected]310ebd6302011-10-10 19:06:282500bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:102501 if (edit_commands_.empty())
2502 return false;
2503
[email protected]26aa0482009-09-30 16:55:272504 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102505 if (!frame)
2506 return false;
2507
2508 EditCommands::iterator it = edit_commands_.begin();
2509 EditCommands::iterator end = edit_commands_.end();
2510
[email protected]507b33ea2009-09-29 03:56:512511 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102512 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332513 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2514 // key (but it's the exception). Once one edit command is not executed, it
2515 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102516 if (!frame->executeCommand(WebString::fromUTF8(it->name),
[email protected]b77fac52013-06-01 01:03:462517 WebString::fromUTF8(it->value),
2518 GetFocusedNode()))
[email protected]b2528b72009-09-24 06:57:102519 break;
[email protected]507b33ea2009-09-29 03:56:512520 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102521 }
2522
[email protected]507b33ea2009-09-29 03:56:512523 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102524}
2525
[email protected]da8543762012-03-20 08:52:202526WebKit::WebColorChooser* RenderViewImpl::createColorChooser(
2527 WebKit::WebColorChooserClient* client,
2528 const WebKit::WebColor& initial_color) {
2529 RendererWebColorChooserImpl* color_chooser =
2530 new RendererWebColorChooserImpl(this, client);
2531 color_chooser->Open(static_cast<SkColor>(initial_color));
2532 return color_chooser;
2533}
2534
[email protected]310ebd6302011-10-10 19:06:282535bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:352536 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472537 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352538 // Do not open the file dialog in a hidden RenderView.
2539 if (is_hidden())
2540 return false;
[email protected]e9ff79c2012-10-19 21:31:262541 FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262542 if (params.directory)
[email protected]6bedbef2013-07-31 06:33:492543 ipc_params.mode = FileChooserParams::UploadFolder;
[email protected]b5977a0c2010-08-24 19:46:262544 else if (params.multiSelect)
[email protected]e9ff79c2012-10-19 21:31:262545 ipc_params.mode = FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:502546 else if (params.saveAs)
[email protected]e9ff79c2012-10-19 21:31:262547 ipc_params.mode = FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:262548 else
[email protected]e9ff79c2012-10-19 21:31:262549 ipc_params.mode = FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:472550 ipc_params.title = params.title;
2551 ipc_params.default_file_name =
[email protected]728c2ee2013-06-25 04:01:072552 base::FilePath::FromUTF16Unsafe(params.initialValue);
[email protected]f9a4c41a2012-05-30 00:05:322553 ipc_params.accept_types.reserve(params.acceptTypes.size());
2554 for (size_t i = 0; i < params.acceptTypes.size(); ++i)
2555 ipc_params.accept_types.push_back(params.acceptTypes[i]);
[email protected]2fdf2352012-11-01 19:23:022556#if defined(OS_ANDROID)
[email protected]b7b4beb2013-07-09 14:06:502557 ipc_params.capture = params.useMediaCapture;
[email protected]2fdf2352012-11-01 19:23:022558#endif
[email protected]cdaf8d02010-03-30 19:52:472559
2560 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462561}
2562
[email protected]269f86d2011-12-07 02:43:472563void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
2564 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262565 RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:412566 message,
2567 string16(),
[email protected]b6cb3a842011-06-24 18:28:412568 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522569 NULL);
2570}
2571
[email protected]269f86d2011-12-07 02:43:472572bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
2573 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262574 return RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:412575 message,
2576 string16(),
[email protected]b6cb3a842011-06-24 18:28:412577 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522578 NULL);
2579}
2580
[email protected]269f86d2011-12-07 02:43:472581bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
2582 const WebString& message,
2583 const WebString& default_value,
2584 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:412585 string16 result;
[email protected]e9ff79c2012-10-19 21:31:262586 bool ok = RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:412587 message,
2588 default_value,
[email protected]b6cb3a842011-06-24 18:28:412589 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522590 &result);
2591 if (ok)
[email protected]4f5ce842011-05-27 19:34:412592 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:522593 return ok;
2594}
2595
[email protected]310ebd6302011-10-10 19:06:282596bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:522597 WebFrame* frame, const WebString& message) {
[email protected]ab533826b2013-05-10 23:54:562598 bool is_reload = false;
2599 WebDataSource* ds = frame->provisionalDataSource();
2600 if (ds)
2601 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
2602 return runModalBeforeUnloadDialog(frame, is_reload, message);
2603}
2604
2605bool RenderViewImpl::runModalBeforeUnloadDialog(
2606 WebFrame* frame, bool is_reload, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:152607 // If we are swapping out, we have already run the beforeunload handler.
2608 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
2609 // at all, to avoid running it twice.
2610 if (is_swapped_out_)
2611 return true;
2612
[email protected]48c9cf2d2009-09-16 16:47:522613 bool success = false;
2614 // This is an ignored return value, but is included so we can accept the same
2615 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:412616 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:212617 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:322618 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:412619 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522620 return success;
2621}
2622
[email protected]310ebd6302011-10-10 19:06:282623void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:442624 WebFrame* frame, const WebContextMenuData& data) {
[email protected]3175fea2013-05-16 10:57:482625 ContextMenuParams params = ContextMenuParamsBuilder::Build(data);
[email protected]f56c7872013-06-18 12:31:572626 params.source_type = context_menu_source_type_;
[email protected]a14ddcd2013-06-21 22:53:032627 if (context_menu_source_type_ == ui::MENU_SOURCE_TOUCH_EDIT_MENU) {
[email protected]f56c7872013-06-18 12:31:572628 params.x = touch_editing_context_menu_location_.x();
2629 params.y = touch_editing_context_menu_location_.y();
2630 }
[email protected]7fcd9b72011-07-27 16:52:372631
[email protected]329266d2012-09-27 06:20:572632 // Plugins, e.g. PDF, don't currently update the render view when their
2633 // selected text changes, but the context menu params do contain the updated
2634 // selection. If that's the case, update the render view's state just prior
2635 // to showing the context menu.
2636 // TODO(asvitkine): http://crbug.com/152432
[email protected]432c9a72013-02-27 01:51:032637 if (ShouldUpdateSelectionTextFromContextMenuParams(selection_text_,
2638 selection_text_offset_,
2639 selection_range_,
2640 params)) {
[email protected]329266d2012-09-27 06:20:572641 selection_text_ = params.selection_text;
2642 // TODO(asvitkine): Text offset and range is not available in this case.
2643 selection_text_offset_ = 0;
[email protected]db4fc1e2013-09-06 20:01:512644 selection_range_ = gfx::Range(0, selection_text_.length());
[email protected]329266d2012-09-27 06:20:572645 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2646 selection_text_,
2647 selection_text_offset_,
2648 selection_range_));
2649 }
2650
[email protected]7fcd9b72011-07-27 16:52:372651 // frame is NULL if invoked by BlockedPlugin.
2652 if (frame)
2653 params.frame_id = frame->identifier();
2654
[email protected]e9ff79c2012-10-19 21:31:262655 // Serializing a GURL longer than kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:272656 // it. We replace it with an empty GURL so the appropriate items are disabled
2657 // in the context menu.
2658 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2659 // data encoded images. We should have a way to save them.
[email protected]e9ff79c2012-10-19 21:31:262660 if (params.src_url.spec().size() > kMaxURLChars)
[email protected]216932c2010-08-26 21:44:272661 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102662 context_menu_node_ = data.node;
[email protected]44daa3b2012-09-27 19:26:412663
2664#if defined(OS_ANDROID)
2665 gfx::Rect start_rect;
2666 gfx::Rect end_rect;
2667 GetSelectionBounds(&start_rect, &end_rect);
[email protected]326a2342013-02-15 15:47:512668 params.selection_start = gfx::Point(start_rect.x(), start_rect.bottom());
2669 params.selection_end = gfx::Point(end_rect.right(), end_rect.bottom());
[email protected]44daa3b2012-09-27 19:26:412670#endif
2671
[email protected]c27324b2009-11-19 22:44:292672 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]b2324b092012-11-01 10:34:112673
2674 FOR_EACH_OBSERVER(
2675 RenderViewObserver, observers_, DidRequestShowContextMenu(frame, data));
[email protected]79e37442009-10-09 18:17:442676}
2677
[email protected]8b67f78f2013-08-13 12:04:302678void RenderViewImpl::clearContextMenu() {
2679 context_menu_node_.reset();
2680}
2681
[email protected]310ebd6302011-10-10 19:06:282682void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:522683}
2684
[email protected]310ebd6302011-10-10 19:06:282685void RenderViewImpl::UpdateTargetURL(const GURL& url,
2686 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582687 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522688 if (latest_url == target_url_)
2689 return;
[email protected]163f8242009-10-30 20:19:552690
[email protected]48c9cf2d2009-09-16 16:47:522691 // Tell the browser to display a destination link.
2692 if (target_url_status_ == TARGET_INFLIGHT ||
2693 target_url_status_ == TARGET_PENDING) {
2694 // If we have a request in-flight, save the URL to be sent when we
2695 // receive an ACK to the in-flight request. We can happily overwrite
2696 // any existing pending sends.
2697 pending_target_url_ = latest_url;
2698 target_url_status_ = TARGET_PENDING;
2699 } else {
[email protected]e9ff79c2012-10-19 21:31:262700 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:412701 // see |ParamTraits<GURL>|.
[email protected]e9ff79c2012-10-19 21:31:262702 if (latest_url.possibly_invalid_spec().size() > kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:412703 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:522704 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2705 target_url_ = latest_url;
2706 target_url_status_ = TARGET_INFLIGHT;
2707 }
2708}
2709
[email protected]70221f02013-01-31 22:17:072710gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect(
2711 const gfx::RectF& rect) const {
2712 gfx::RectF window_rect = rect;
2713 window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor());
2714 return window_rect;
2715}
2716
[email protected]310ebd6302011-10-10 19:06:282717void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]a183fb82012-12-14 04:46:222718 // No need to update state if no page has committed yet.
2719 if (page_id_ == -1)
2720 return;
2721
[email protected]882daa92009-11-05 16:31:312722 int delay;
2723 if (send_content_state_immediately_)
2724 delay = 0;
2725 else if (is_hidden())
2726 delay = kDelaySecondsForContentStateSyncHidden;
2727 else
2728 delay = kDelaySecondsForContentStateSync;
2729
2730 if (nav_state_sync_timer_.IsRunning()) {
2731 // The timer is already running. If the delay of the timer maches the amount
2732 // we want to delay by, then return. Otherwise stop the timer so that it
2733 // gets started with the right delay.
2734 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2735 return;
2736 nav_state_sync_timer_.Stop();
2737 }
2738
[email protected]d323a172011-09-02 18:23:022739 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:282740 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:312741}
2742
[email protected]310ebd6302011-10-10 19:06:282743void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552744 mouse_over_url_ = GURL(url);
2745 UpdateTargetURL(mouse_over_url_, focus_url_);
2746}
2747
[email protected]310ebd6302011-10-10 19:06:282748void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552749 focus_url_ = GURL(url);
2750 UpdateTargetURL(focus_url_, mouse_over_url_);
2751}
2752
[email protected]0407e422012-05-18 19:51:252753void RenderViewImpl::startDragging(WebFrame* frame,
2754 const WebDragData& data,
[email protected]310ebd6302011-10-10 19:06:282755 WebDragOperationsMask mask,
2756 const WebImage& image,
[email protected]ceb36f7d2012-10-31 18:33:242757 const WebPoint& webImageOffset) {
[email protected]dc293a72013-07-01 11:11:222758 DropData drop_data(DropDataBuilder::Build(data));
[email protected]b67151d2012-05-25 23:23:242759 drop_data.referrer_policy = frame->document().referrerPolicy();
[email protected]ceb36f7d2012-10-31 18:33:242760 gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y);
[email protected]59f4f2fa2011-03-23 01:00:552761 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]b67151d2012-05-25 23:23:242762 drop_data,
[email protected]c27ae592010-03-18 15:24:412763 mask,
[email protected]976127072012-05-10 20:08:112764 image.getSkBitmap(),
[email protected]41d86852012-11-07 12:23:242765 imageOffset,
2766 possible_drag_event_info_));
[email protected]48c9cf2d2009-09-16 16:47:522767}
2768
[email protected]310ebd6302011-10-10 19:06:282769bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:452770 return renderer_preferences_.can_accept_load_drops;
2771}
2772
[email protected]310ebd6302011-10-10 19:06:282773void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:522774 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2775}
2776
[email protected]310ebd6302011-10-10 19:06:282777void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:522778 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2779}
2780
[email protected]310ebd6302011-10-10 19:06:282781void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512782 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072783
[email protected]38b592902011-04-16 02:08:422784 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:492785}
2786
[email protected]572a6ca2012-10-11 19:38:012787void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
2788 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
2789}
2790
[email protected]169d4282011-11-30 19:33:592791void RenderViewImpl::didUpdateLayout() {
[email protected]d01b2a62013-09-18 23:21:332792 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidUpdateLayout());
2793
[email protected]169d4282011-11-30 19:33:592794 // We don't always want to set up a timer, only if we've been put in that
2795 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2796 // message.
2797 if (!send_preferred_size_changes_ || !webview())
2798 return;
2799
2800 if (check_preferred_size_timer_.IsRunning())
2801 return;
2802 check_preferred_size_timer_.Start(FROM_HERE,
2803 TimeDelta::FromMilliseconds(0), this,
2804 &RenderViewImpl::CheckPreferredSize);
2805}
2806
[email protected]310ebd6302011-10-10 19:06:282807void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522808 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2809}
2810
[email protected]310ebd6302011-10-10 19:06:282811int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002812 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522813}
2814
[email protected]310ebd6302011-10-10 19:06:282815int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002816 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522817}
2818
[email protected]10760e4a2013-09-04 23:32:202819void RenderViewImpl::postAccessibilityEvent(
2820 const WebAXObject& obj, WebKit::WebAXEvent event) {
[email protected]2a84f9d2012-06-05 21:50:432821 if (renderer_accessibility_) {
[email protected]10760e4a2013-09-04 23:32:202822 renderer_accessibility_->HandleWebAccessibilityEvent(obj, event);
[email protected]2a84f9d2012-06-05 21:50:432823 }
[email protected]063afcb2011-09-29 07:54:322824}
2825
[email protected]310ebd6302011-10-10 19:06:282826void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:142827 const WebString& value) {
2828 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2829 key.utf8(),
2830 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262831}
2832
[email protected]79dbc662009-09-04 05:42:512833// WebKit::WebWidgetClient ----------------------------------------------------
2834
[email protected]310ebd6302011-10-10 19:06:282835void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122836 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2837 // we won't have to test for user gesture anymore and we can
2838 // move that code back to render_widget.cc
[email protected]af15bf22013-03-08 01:18:172839 if (WebUserGestureIndicator::isProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:302840 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]e1176152013-03-06 09:16:442841 Send(new ViewHostMsg_Focus(routing_id_));
[email protected]ea42e7782010-08-23 23:58:122842 }
2843}
2844
[email protected]310ebd6302011-10-10 19:06:282845void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122846 // TODO(jcivelli): see TODO above in didFocus().
[email protected]af15bf22013-03-08 01:18:172847 if (WebUserGestureIndicator::isProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:302848 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]e1176152013-03-06 09:16:442849 Send(new ViewHostMsg_Blur(routing_id_));
[email protected]ea42e7782010-08-23 23:58:122850 }
2851}
2852
initial.commit09911bf2008-07-26 23:55:292853// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282854// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292855// point to dispatch the ShowView message.
2856//
2857// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282858// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292859//
[email protected]310ebd6302011-10-10 19:06:282860void RenderViewImpl::show(WebNavigationPolicy policy) {
[email protected]b2142e962012-10-30 13:59:252861 if (did_show_) {
[email protected]b2142e962012-10-30 13:59:252862 // When supports_multiple_windows is disabled, popups are reusing
2863 // the same view. In some scenarios, this makes WebKit to call show() twice.
[email protected]c9edabd2013-05-23 13:56:242864 if (webkit_preferences_.supports_multiple_windows)
2865 NOTREACHED() << "received extraneous Show call";
initial.commit09911bf2008-07-26 23:55:292866 return;
[email protected]b2142e962012-10-30 13:59:252867 }
initial.commit09911bf2008-07-26 23:55:292868 did_show_ = true;
2869
[email protected]b2142e962012-10-30 13:59:252870 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2871
[email protected]28295ec2009-10-16 05:34:332872 // Force new windows to a popup if they were not opened with a user gesture.
2873 if (!opened_by_user_gesture_) {
2874 // We exempt background tabs for compat with older versions of Chrome.
2875 // TODO(darin): This seems bogus. These should have a user gesture, so
2876 // we probably don't need this check.
2877 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2878 policy = WebKit::WebNavigationPolicyNewPopup;
2879 }
2880
initial.commit09911bf2008-07-26 23:55:292881 // NOTE: initial_pos_ may still have its default values at this point, but
2882 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2883 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282884 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2885 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292886 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242887 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292888}
2889
[email protected]310ebd6302011-10-10 19:06:282890void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292891 DCHECK(did_show_) << "should already have shown the view";
2892
[email protected]c1f50aa2010-02-18 03:46:572893 // We must keep WebKit's shared timer running in this case in order to allow
2894 // showModalDialog to function properly.
2895 //
2896 // TODO(darin): WebKit should really be smarter about suppressing events and
2897 // timers so that we do not need to manage the shared timer in such a heavy
2898 // handed manner.
2899 //
[email protected]f1a29a02011-10-06 23:08:442900 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2901 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572902
[email protected]08a1c8102012-05-11 23:14:262903 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
2904 routing_id_, opener_id_));
initial.commit09911bf2008-07-26 23:55:292905}
2906
[email protected]2b624c562011-10-27 22:58:262907bool RenderViewImpl::enterFullScreen() {
2908 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2909 return true;
2910}
2911
2912void RenderViewImpl::exitFullScreen() {
2913 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2914}
2915
[email protected]217690d2012-01-27 07:33:112916bool RenderViewImpl::requestPointerLock() {
2917 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2918}
2919
2920void RenderViewImpl::requestPointerUnlock() {
2921 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2922}
2923
2924bool RenderViewImpl::isPointerLocked() {
2925 return mouse_lock_dispatcher_->IsMouseLockedTo(
2926 webwidget_mouse_lock_target_.get());
2927}
2928
[email protected]7a1ec28a2012-03-28 21:10:242929void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
[email protected]0cd50aa2013-02-12 22:28:012930#if !defined(OS_MACOSX) // many events are unhandled - http://crbug.com/138003
[email protected]ea5f70a2013-03-07 12:30:362931 InputHandlerManager* input_handler_manager =
2932 RenderThreadImpl::current()->input_handler_manager();
[email protected]200a9c062013-05-20 04:34:372933 if (input_handler_manager) {
2934 input_handler_manager->AddInputHandler(
2935 routing_id_,
2936 compositor_->GetInputHandler(),
2937 AsWeakPtr());
2938 }
[email protected]70cff27502013-01-17 09:16:492939#endif
[email protected]7a1ec28a2012-03-28 21:10:242940
2941 RenderWidget::didActivateCompositor(input_handler_identifier);
2942}
2943
[email protected]c68c3e4e2013-01-24 00:36:562944void RenderViewImpl::didHandleGestureEvent(
2945 const WebGestureEvent& event,
2946 bool event_cancelled) {
2947 RenderWidget::didHandleGestureEvent(event, event_cancelled);
2948 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2949 DidHandleGestureEvent(event));
2950}
2951
[email protected]6e89eb72013-07-23 13:28:222952void RenderViewImpl::initializeLayerTreeView() {
2953 RenderWidget::initializeLayerTreeView();
2954 RenderWidgetCompositor* rwc = compositor();
2955 if (!rwc || !webview() || !webview()->devToolsAgent())
2956 return;
2957 webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId());
2958}
2959
[email protected]3d9689372009-09-10 04:29:172960// WebKit::WebFrameClient -----------------------------------------------------
2961
[email protected]97b150db2012-08-16 18:26:022962WebMediaPlayer* RenderViewImpl::createMediaPlayer(
2963 WebFrame* frame, const WebKit::WebURL& url, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442964 FOR_EACH_OBSERVER(
2965 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172966
[email protected]780fc8242012-09-19 20:28:522967 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
[email protected]75abf382013-07-09 08:14:192968#if defined(ENABLE_WEBRTC)
[email protected]60ee79f2013-09-11 13:49:552969 if (!InitializeMediaStreamClient())
2970 return NULL;
2971
[email protected]75abf382013-07-09 08:14:192972#if !defined(GOOGLE_TV)
[email protected]60ee79f2013-09-11 13:49:552973 if (media_stream_client_->IsMediaStream(url)) {
[email protected]befe54782013-04-23 00:49:252974#if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
2975 bool found_neon =
2976 (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
2977 UMA_HISTOGRAM_BOOLEAN("Platform.WebRtcNEONFound", found_neon);
2978#endif // defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
[email protected]5e35a8d2013-07-10 19:37:212979 return new WebMediaPlayerMS(
[email protected]c3bdce152013-07-10 04:56:342980 frame, client, AsWeakPtr(), media_stream_client_, new RenderMediaLog());
[email protected]d05e2162012-11-16 22:21:462981 }
[email protected]75abf382013-07-09 08:14:192982#endif // !defined(GOOGLE_TV)
2983#endif // defined(ENABLE_WEBRTC)
[email protected]d05e2162012-11-16 22:21:462984
[email protected]25fb9b32012-04-27 03:21:552985#if defined(OS_ANDROID)
[email protected]855623ed2012-09-24 18:59:552986 GpuChannelHost* gpu_channel_host =
2987 RenderThreadImpl::current()->EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:262988 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
[email protected]855623ed2012-09-24 18:59:552989 if (!gpu_channel_host) {
2990 LOG(ERROR) << "Failed to establish GPU channel for media player";
2991 return NULL;
2992 }
2993
[email protected]a45c46e2013-03-07 01:04:462994 scoped_refptr<cc::ContextProvider> context_provider =
2995 RenderThreadImpl::current()->OffscreenContextProviderForMainThread();
[email protected]3aaba572013-08-10 15:10:382996 scoped_ptr<StreamTextureFactory> stream_texture_factory;
2997 if (UsingSynchronousRendererCompositor()) {
[email protected]3a59bb92013-08-22 18:54:082998 SynchronousCompositorFactory* factory =
2999 SynchronousCompositorFactory::GetInstance();
3000 stream_texture_factory = factory->CreateStreamTextureFactory(routing_id_);
[email protected]3aaba572013-08-10 15:10:383001 } else {
[email protected]76e9cc42013-09-07 01:02:093002 if (!context_provider.get()) {
3003 LOG(ERROR) << "Failed to get context3d for media player";
3004 return NULL;
3005 }
3006
[email protected]3aaba572013-08-10 15:10:383007 stream_texture_factory.reset(new StreamTextureFactoryImpl(
3008 context_provider->Context3d(), gpu_channel_host, routing_id_));
3009 }
3010
[email protected]76e9cc42013-09-07 01:02:093011 if (!media_player_proxy_) {
3012 media_player_proxy_ = new WebMediaPlayerProxyAndroid(
3013 this, media_player_manager_.get());
3014 }
3015
[email protected]be580992013-06-22 14:32:443016 scoped_ptr<WebMediaPlayerAndroid> web_media_player_android(
3017 new WebMediaPlayerAndroid(
[email protected]e69bb062013-06-03 13:05:403018 frame,
3019 client,
[email protected]9aff54d2013-06-18 18:38:503020 AsWeakPtr(),
[email protected]e69bb062013-06-03 13:05:403021 media_player_manager_.get(),
3022 media_player_proxy_,
[email protected]3aaba572013-08-10 15:10:383023 stream_texture_factory.release(),
[email protected]4aec8652013-08-23 05:32:473024 RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy(),
[email protected]e69bb062013-06-03 13:05:403025 new RenderMediaLog()));
3026#if defined(ENABLE_WEBRTC) && defined(GOOGLE_TV)
[email protected]c3bdce152013-07-10 04:56:343027 if (media_stream_client_->IsMediaStream(url)) {
[email protected]e69bb062013-06-03 13:05:403028 RTCVideoDecoderFactoryTv* factory = RenderThreadImpl::current()
3029 ->GetMediaStreamDependencyFactory()->decoder_factory_tv();
[email protected]75abf382013-07-09 08:14:193030 // |media_stream_client| and |factory| outlives |web_media_player_android|.
[email protected]e69bb062013-06-03 13:05:403031 if (!factory->AcquireDemuxer() ||
3032 !web_media_player_android->InjectMediaStream(
[email protected]c3bdce152013-07-10 04:56:343033 media_stream_client_,
[email protected]e69bb062013-06-03 13:05:403034 factory,
3035 base::Bind(
3036 base::IgnoreResult(&RTCVideoDecoderFactoryTv::ReleaseDemuxer),
3037 base::Unretained(factory)))) {
3038 LOG(ERROR) << "Failed to inject media stream.";
3039 return NULL;
3040 }
3041 }
3042#endif // defined(ENABLE_WEBRTC) && defined(GOOGLE_TV)
3043 return web_media_player_android.release();
3044#endif // defined(OS_ANDROID)
[email protected]25fb9b32012-04-27 03:21:553045
[email protected]4a914882013-01-10 00:43:483046 scoped_refptr<media::AudioRendererSink> sink;
[email protected]3d9689372009-09-10 04:29:173047 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]17c4ce62f2013-05-03 19:54:023048 sink = RenderThreadImpl::current()->GetAudioRendererMixerManager()->
3049 CreateInput(routing_id_);
[email protected]fc72bb12013-06-02 21:13:463050 DVLOG(1) << "Using AudioRendererMixerManager-provided sink: " << sink.get();
[email protected]3d9689372009-09-10 04:29:173051 }
3052
[email protected]1cad8802013-08-13 16:54:323053 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories =
[email protected]86e3a702013-07-24 12:22:533054 RenderThreadImpl::current()->GetGpuFactories(
3055 RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy());
[email protected]e1d69d762011-12-13 05:12:183056
[email protected]5e35a8d2013-07-10 19:37:213057 WebMediaPlayerParams params(
[email protected]c1330c82013-06-06 02:23:253058 RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy(),
[email protected]d726eddc2013-07-02 22:25:553059 base::Bind(&ContentRendererClient::DeferMediaLoad,
3060 base::Unretained(GetContentClient()->renderer()),
3061 static_cast<RenderView*>(this)),
3062 sink,
3063 gpu_factories,
3064 new RenderMediaLog());
[email protected]5e35a8d2013-07-10 19:37:213065 return new WebMediaPlayerImpl(frame, client, AsWeakPtr(), params);
[email protected]3d9689372009-09-10 04:29:173066}
3067
[email protected]310ebd6302011-10-10 19:06:283068WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:383069 return &cookie_jar_;
3070}
3071
[email protected]59167c22013-06-03 18:07:323072void RenderViewImpl::didAccessInitialDocument(WebFrame* frame) {
3073 // Notify the browser process that it is no longer safe to show the pending
3074 // URL of the main frame, since a URL spoof is now possible.
3075 if (!frame->parent() && page_id_ == -1)
3076 Send(new ViewHostMsg_DidAccessInitialDocument(routing_id_));
3077}
3078
[email protected]7cc78902012-12-06 02:32:263079void RenderViewImpl::didDisownOpener(WebKit::WebFrame* frame) {
[email protected]29ece2e2013-04-03 04:53:523080 // We only need to notify the browser if the active, top-level frame clears
3081 // its opener. We can ignore cases where a swapped out frame clears its
3082 // opener after hearing about it from the browser, and the browser does not
3083 // (yet) care about subframe openers.
3084 if (is_swapped_out_ || frame->parent())
[email protected]7cc78902012-12-06 02:32:263085 return;
3086
3087 // Notify WebContents and all its swapped out RenderViews.
3088 Send(new ViewHostMsg_DidDisownOpener(routing_id_));
3089}
3090
[email protected]310ebd6302011-10-10 19:06:283091void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:513092 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:453093}
3094
[email protected]310ebd6302011-10-10 19:06:283095void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:513096 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:173097}
3098
[email protected]5e92282f2012-08-17 08:11:573099void RenderViewImpl::Repaint(const gfx::Size& size) {
[email protected]3d9ec5052013-01-02 22:05:253100 OnRepaint(size);
[email protected]5e92282f2012-08-17 08:11:573101}
3102
[email protected]b2324b092012-11-01 10:34:113103void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
3104 const std::string& value) {
3105 EditCommands edit_commands;
3106 edit_commands.push_back(EditCommand(name, value));
3107 OnSetEditCommandsForNextKeyEvent(edit_commands);
3108}
3109
3110void RenderViewImpl::ClearEditCommands() {
3111 edit_commands_.clear();
3112}
3113
[email protected]e4495212012-12-06 03:09:123114SSLStatus RenderViewImpl::GetSSLStatusOfFrame(WebKit::WebFrame* frame) const {
[email protected]83c0abca2013-07-23 20:09:423115 std::string security_info;
3116 if (frame && frame->dataSource())
3117 security_info = frame->dataSource()->response().securityInfo();
3118
3119 SSLStatus ssl_status;
3120 DeserializeSecurityInfo(security_info,
3121 &ssl_status.cert_id,
3122 &ssl_status.cert_status,
3123 &ssl_status.security_bits,
3124 &ssl_status.connection_status);
3125 return ssl_status;
[email protected]e4495212012-12-06 03:09:123126}
3127
[email protected]310ebd6302011-10-10 19:06:283128WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]0d8f04b2013-04-29 20:05:313129 WebFrame* frame, WebDataSource::ExtraData* extraData,
3130 const WebURLRequest& request, WebNavigationType type,
3131 WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]099df81cf2012-11-14 17:44:043132 if (request.url() != GURL(kSwappedOutURL) &&
3133 GetContentClient()->renderer()->HandleNavigation(frame, request, type,
3134 default_policy,
3135 is_redirect)) {
3136 return WebKit::WebNavigationPolicyIgnore;
3137 }
3138
[email protected]44e55b012013-07-23 14:21:563139 Referrer referrer(GetReferrerFromRequest(frame, request));
[email protected]0639c063a2012-03-22 20:55:333140
[email protected]992db4c2011-05-12 15:37:153141 if (is_swapped_out_) {
[email protected]e9ff79c2012-10-19 21:31:263142 if (request.url() != GURL(kSwappedOutURL)) {
[email protected]0639c063a2012-03-22 20:55:333143 // Targeted links may try to navigate a swapped out frame. Allow the
3144 // browser process to navigate the tab instead. Note that it is also
3145 // possible for non-targeted navigations (from this view) to arrive
3146 // here just after we are swapped out. It's ok to send them to the
3147 // browser, as long as they're for the top level frame.
3148 // TODO(creis): Ensure this supports targeted form submissions when
3149 // fixing http://crbug.com/101395.
3150 if (frame->parent() == NULL) {
3151 OpenURL(frame, request.url(), referrer, default_policy);
3152 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
3153 }
3154
3155 // We should otherwise ignore in-process iframe navigations, if they
3156 // arrive just after we are swapped out.
[email protected]73eb2602012-02-09 19:50:553157 return WebKit::WebNavigationPolicyIgnore;
[email protected]0639c063a2012-03-22 20:55:333158 }
[email protected]73eb2602012-02-09 19:50:553159
[email protected]e9ff79c2012-10-19 21:31:263160 // Allow kSwappedOutURL to complete.
[email protected]992db4c2011-05-12 15:37:153161 return default_policy;
3162 }
3163
[email protected]3d9689372009-09-10 04:29:173164 // Webkit is asking whether to navigate to a new URL.
3165 // This is fine normally, except if we're showing UI from one security
3166 // context and they're trying to navigate to a different context.
3167 const GURL& url = request.url();
3168
[email protected]d19ea342011-04-20 20:31:133169 // A content initiated navigation may have originated from a link-click,
3170 // script, drag-n-drop operation, etc.
[email protected]0d8f04b2013-04-29 20:05:313171 bool is_content_initiated = static_cast<DocumentState*>(extraData)->
[email protected]007733c2011-11-17 00:34:073172 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:133173
[email protected]a8c269a2011-10-25 20:17:223174 // Experimental:
[email protected]c6f2e672012-11-15 01:47:023175 // If --enable-strict-site-isolation or --site-per-process is enabled, send
3176 // all top-level navigations to the browser to let it swap processes when
3177 // crossing site boundaries. This is currently expected to break some script
3178 // calls and navigations, such as form submissions.
[email protected]a8c269a2011-10-25 20:17:223179 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]c6f2e672012-11-15 01:47:023180 bool force_swap_due_to_flag =
3181 command_line.HasSwitch(switches::kEnableStrictSiteIsolation) ||
3182 command_line.HasSwitch(switches::kSitePerProcess);
3183 if (force_swap_due_to_flag &&
[email protected]313b80bd2011-11-23 03:49:103184 !frame->parent() && (is_content_initiated || is_redirect)) {
3185 WebString origin_str = frame->document().securityOrigin().toString();
3186 GURL frame_url(origin_str.utf8().data());
[email protected]18fb7a772012-09-20 19:25:093187 // TODO(cevans): revisit whether this site check is still necessary once
[email protected]313b80bd2011-11-23 03:49:103188 // crbug.com/101395 is fixed.
[email protected]ed32c212013-05-14 20:49:293189 bool same_domain_or_host =
3190 net::registry_controlled_domains::SameDomainOrHost(
3191 frame_url,
3192 url,
3193 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
3194 if (!same_domain_or_host || frame_url.scheme() != url.scheme()) {
[email protected]313b80bd2011-11-23 03:49:103195 OpenURL(frame, url, referrer, default_policy);
3196 return WebKit::WebNavigationPolicyIgnore;
3197 }
[email protected]a8c269a2011-10-25 20:17:223198 }
3199
[email protected]fd3238af2012-05-22 18:55:303200 // If the browser is interested, then give it a chance to look at the request.
[email protected]5f000f272012-01-19 05:25:083201 if (is_content_initiated) {
[email protected]140a5882013-07-23 19:30:333202 bool is_form_post = ((type == WebKit::WebNavigationTypeFormSubmitted) ||
3203 (type == WebKit::WebNavigationTypeFormResubmitted)) &&
3204 EqualsASCII(request.httpMethod(), "POST");
[email protected]fd3238af2012-05-22 18:55:303205 bool browser_handles_request =
3206 renderer_preferences_.browser_handles_non_local_top_level_requests &&
[email protected]140a5882013-07-23 19:30:333207 IsNonLocalTopLevelNavigation(url, frame, type, is_form_post);
[email protected]fd3238af2012-05-22 18:55:303208 if (!browser_handles_request) {
3209 browser_handles_request =
3210 renderer_preferences_.browser_handles_all_top_level_requests &&
3211 IsTopLevelNavigation(frame);
3212 }
3213
3214 if (browser_handles_request) {
[email protected]5f000f272012-01-19 05:25:083215 // Reset these counters as the RenderView could be reused for the next
3216 // navigation.
3217 page_id_ = -1;
3218 last_page_id_sent_to_browser_ = -1;
3219 OpenURL(frame, url, referrer, default_policy);
3220 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
3221 }
[email protected]3d9689372009-09-10 04:29:173222 }
3223
[email protected]dc67e1c32012-06-08 00:10:403224 // Use the frame's original request's URL rather than the document's URL for
3225 // subsequent checks. For a popup, the document's URL may become the opener
3226 // window's URL if the opener has called document.write().
3227 // See http://crbug.com/93517.
3228 GURL old_url(frame->dataSource()->request().url());
3229
[email protected]6101c342010-12-16 22:44:373230 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:553231 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:043232 // top-level navigations (not iframes). But we sometimes navigate to
3233 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:373234 //
[email protected]744c2a22012-03-15 18:42:043235 // Note: this is known to break POST submissions when crossing process
3236 // boundaries until http://crbug.com/101395 is fixed. This is better for
3237 // security than loading a WebUI, extension or app page in the wrong process.
3238 // POST requests don't work because this mechanism does not preserve form
3239 // POST data. We will need to send the request's httpBody data up to the
3240 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:573241 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
3242 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:223243 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:043244 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:373245 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:043246
[email protected]0a57375a2013-03-07 22:18:593247 // All navigations to or from WebUI URLs or within WebUI-enabled
3248 // RenderProcesses must be handled by the browser process so that the
3249 // correct bindings and data sources can be registered.
[email protected]744c2a22012-03-15 18:42:043250 // Similarly, navigations to view-source URLs or within ViewSource mode
[email protected]1c210f692012-11-06 22:31:473251 // must be handled by the browser process (except for reloads - those are
3252 // safe to leave within the renderer).
[email protected]dc67e1c32012-06-08 00:10:403253 // Lastly, access to file:// URLs from non-file:// URL pages must be
3254 // handled by the browser so that ordinary renderer processes don't get
3255 // blessed with file permissions.
3256 int cumulative_bindings = RenderProcess::current()->GetEnabledBindings();
3257 bool is_initial_navigation = page_id_ == -1;
[email protected]0a57375a2013-03-07 22:18:593258 bool should_fork = HasWebUIScheme(url) || HasWebUIScheme(old_url) ||
[email protected]e9ff79c2012-10-19 21:31:263259 (cumulative_bindings & BINDINGS_POLICY_WEB_UI) ||
[email protected]dbdda5402013-05-30 22:13:483260 url.SchemeIs(kViewSourceScheme) ||
[email protected]1c210f692012-11-06 22:31:473261 (frame->isViewSourceModeEnabled() &&
3262 type != WebKit::WebNavigationTypeReload);
[email protected]5351dbc2010-08-27 15:22:113263
[email protected]dc67e1c32012-06-08 00:10:403264 if (!should_fork && url.SchemeIs(chrome::kFileScheme)) {
3265 // Fork non-file to file opens. Check the opener URL if this is the
3266 // initial navigation in a newly opened window.
3267 GURL source_url(old_url);
3268 if (is_initial_navigation && source_url.is_empty() && frame->opener())
3269 source_url = frame->opener()->top()->document().url();
3270 DCHECK(!source_url.is_empty());
3271 should_fork = !source_url.SchemeIs(chrome::kFileScheme);
3272 }
3273
[email protected]e48869a2011-04-01 19:56:033274 if (!should_fork) {
3275 // Give the embedder a chance.
[email protected]c5dec6292013-01-25 04:54:523276 should_fork = GetContentClient()->renderer()->ShouldFork(
3277 frame, url, request.httpMethod().utf8(), is_initial_navigation,
[email protected]b0a29f22013-05-30 23:00:093278 is_redirect, &send_referrer);
[email protected]6101c342010-12-16 22:44:373279 }
3280
3281 if (should_fork) {
[email protected]445e1042011-12-03 21:03:153282 OpenURL(
3283 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:113284 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
3285 }
[email protected]3d9689372009-09-10 04:29:173286 }
3287
3288 // Detect when a page is "forking" a new tab that can be safely rendered in
3289 // its own process. This is done by sites like Gmail that try to open links
3290 // in new windows without script connections back to the original page. We
3291 // treat such cases as browser navigations (in which we will create a new
3292 // renderer for a cross-site navigation), rather than WebKit navigations.
3293 //
3294 // We use the following heuristic to decide whether to fork a new page in its
3295 // own process:
3296 // The parent page must open a new tab to about:blank, set the new tab's
3297 // window.opener to null, and then redirect the tab to a cross-site URL using
3298 // JavaScript.
[email protected]007a848b2009-10-26 15:55:463299 //
3300 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
3301 // (see below).
[email protected]3d9689372009-09-10 04:29:173302 bool is_fork =
3303 // Must start from a tab showing about:blank, which is later redirected.
[email protected]081dc522013-05-15 04:59:203304 old_url == GURL(kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:173305 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:523306 historyBackListCount() < 1 &&
3307 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:173308 // The parent page must have set the child's window.opener to null before
3309 // redirecting to the desired URL.
3310 frame->opener() == NULL &&
3311 // Must be a top-level frame.
3312 frame->parent() == NULL &&
3313 // Must not have issued the request from this page.
3314 is_content_initiated &&
3315 // Must be targeted at the current tab.
3316 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3317 // Must be a JavaScript navigation, which appears as "other".
3318 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:463319
[email protected]f92ce2b2012-03-06 18:02:593320 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:173321 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:153322 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:173323 return WebKit::WebNavigationPolicyIgnore;
3324 }
3325
3326 return default_policy;
3327}
3328
[email protected]f4f40a052013-04-19 15:28:113329WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
3330 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]89bc54c62013-04-24 01:51:333331 WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]0d8f04b2013-04-29 20:05:313332 return decidePolicyForNavigation(frame,
3333 frame->provisionalDataSource()->extraData(),
[email protected]89bc54c62013-04-24 01:51:333334 request, type, default_policy, is_redirect);
[email protected]f4f40a052013-04-19 15:28:113335}
3336
[email protected]310ebd6302011-10-10 19:06:283337void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:433338 const WebKit::WebFormElement& form) {
[email protected]0660a8c2013-08-16 01:09:123339 FOR_EACH_OBSERVER(
3340 RenderViewObserver, observers_, WillSendSubmitEvent(frame, form));
[email protected]90eeddb2010-05-06 21:06:433341}
3342
[email protected]310ebd6302011-10-10 19:06:283343void RenderViewImpl::willSubmitForm(WebFrame* frame,
3344 const WebFormElement& form) {
[email protected]2a5b1732011-04-01 23:55:553345 FOR_EACH_OBSERVER(
3346 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:173347}
3348
[email protected]310ebd6302011-10-10 19:06:283349void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:573350 bool content_initiated = !pending_navigation_params_.get();
3351
[email protected]007733c2011-11-17 00:34:073352 DocumentState* document_state = DocumentState::FromDataSource(ds);
3353 if (!document_state) {
3354 document_state = new DocumentState;
3355 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:573356 if (!content_initiated)
3357 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:073358 }
3359
[email protected]bf70edce2012-06-20 22:32:223360 // Carry over the user agent override flag, if it exists.
3361 if (content_initiated && webview() && webview()->mainFrame() &&
3362 webview()->mainFrame()->dataSource()) {
3363 DocumentState* old_document_state =
3364 DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
3365 if (old_document_state) {
[email protected]e20b88d2013-04-09 15:28:373366 InternalDocumentStateData* internal_data =
3367 InternalDocumentStateData::FromDocumentState(document_state);
3368 InternalDocumentStateData* old_internal_data =
3369 InternalDocumentStateData::FromDocumentState(old_document_state);
3370 internal_data->set_is_overriding_user_agent(
3371 old_internal_data->is_overriding_user_agent());
[email protected]bf70edce2012-06-20 22:32:223372 }
3373 }
3374
[email protected]3d9689372009-09-10 04:29:173375 // The rest of RenderView assumes that a WebDataSource will always have a
3376 // non-null NavigationState.
[email protected]e1ed5a12012-08-08 19:57:443377 if (content_initiated) {
[email protected]007733c2011-11-17 00:34:073378 document_state->set_navigation_state(
3379 NavigationState::CreateContentInitiated());
[email protected]e1ed5a12012-08-08 19:57:443380 } else {
[email protected]45d83a12012-04-06 22:57:573381 document_state->set_navigation_state(CreateNavigationStateFromPending());
3382 pending_navigation_params_.reset();
3383 }
[email protected]8a3125a712010-08-09 18:58:513384
[email protected]007733c2011-11-17 00:34:073385 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:513386 // navigating from a page that used prefetching using a link on that
3387 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:073388 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:513389 // this value appropriately.
3390 // TODO(gavinp): catch the important case of navigation in a new
3391 // renderer process.
3392 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303393 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523394 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513395 const GURL referrer(
3396 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3397 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:073398 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:513399 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:413400 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:513401 WebDataSource* old_frame_ds = old_frame->dataSource();
3402 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:073403 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513404 break;
3405 }
3406 }
3407 }
3408 }
3409 }
3410
[email protected]4c1b6f0b2010-02-07 16:38:183411 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523412 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513413 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183414 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:073415 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:183416 break;
3417 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:073418 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:183419 break;
3420 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:073421 document_state->set_load_type(
3422 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:183423 break;
3424 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:073425 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:183426 break;
3427 }
3428 }
[email protected]fa7b6b542009-11-03 05:02:303429
[email protected]946a0032011-03-31 18:42:283430 FOR_EACH_OBSERVER(
3431 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:173432}
3433
[email protected]45d83a12012-04-06 22:57:573434void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:073435 DocumentState* document_state) {
3436 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:573437 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:073438
[email protected]e20b88d2013-04-09 15:28:373439 InternalDocumentStateData* internal_data =
3440 InternalDocumentStateData::FromDocumentState(document_state);
3441
[email protected]44b05812013-08-19 07:59:353442 if (!params.url.SchemeIs(kJavaScriptScheme) &&
[email protected]45d83a12012-04-06 22:57:573443 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
3444 // We're doing a load of a page that was restored from the last session. By
3445 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
3446 // can result in stale data for pages that are set to expire. We explicitly
3447 // override that by setting the policy here so that as necessary we load
3448 // from the network.
[email protected]e20b88d2013-04-09 15:28:373449 internal_data->set_cache_policy_override(
[email protected]45d83a12012-04-06 22:57:573450 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:073451 }
3452
3453 if (IsReload(params))
3454 document_state->set_load_type(DocumentState::RELOAD);
[email protected]691aa2f2013-05-28 22:52:043455 else if (params.page_state.IsValid())
[email protected]007733c2011-11-17 00:34:073456 document_state->set_load_type(DocumentState::HISTORY_LOAD);
3457 else
3458 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]ca662822012-05-11 17:53:593459
[email protected]e20b88d2013-04-09 15:28:373460 internal_data->set_referrer_policy(params.referrer.policy);
3461 internal_data->set_is_overriding_user_agent(params.is_overriding_user_agent);
3462 internal_data->set_must_reset_scroll_and_scale_state(
[email protected]a3a5397d2012-09-12 06:50:343463 params.navigation_type ==
3464 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]951a64832012-10-11 16:26:373465 document_state->set_can_load_local_resources(params.can_load_local_resources);
[email protected]45d83a12012-04-06 22:57:573466}
[email protected]007733c2011-11-17 00:34:073467
[email protected]45d83a12012-04-06 22:57:573468NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
3469 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
3470 NavigationState* navigation_state = NULL;
3471
3472 // A navigation resulting from loading a javascript URL should not be treated
3473 // as a browser initiated event. Instead, we want it to look as if the page
3474 // initiated any load resulting from JS execution.
[email protected]44b05812013-08-19 07:59:353475 if (!params.url.SchemeIs(kJavaScriptScheme)) {
[email protected]45d83a12012-04-06 22:57:573476 navigation_state = NavigationState::CreateBrowserInitiated(
3477 params.page_id,
3478 params.pending_history_list_offset,
[email protected]60d6cca2013-04-30 08:47:133479 params.should_clear_history_list,
[email protected]45d83a12012-04-06 22:57:573480 params.transition);
3481 navigation_state->set_transferred_request_child_id(
3482 params.transferred_request_child_id);
3483 navigation_state->set_transferred_request_request_id(
3484 params.transferred_request_request_id);
[email protected]80744782012-05-04 01:47:003485 navigation_state->set_allow_download(params.allow_download);
[email protected]f050fde2013-03-21 00:40:453486 navigation_state->set_extra_headers(params.extra_headers);
[email protected]45d83a12012-04-06 22:57:573487 } else {
3488 navigation_state = NavigationState::CreateContentInitiated();
3489 }
3490 return navigation_state;
[email protected]007733c2011-11-17 00:34:073491}
3492
[email protected]5b52cd2f712012-03-28 02:12:483493void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
3494 bool enable_viewport =
[email protected]06ea34a2012-05-07 18:52:103495 command_line.HasSwitch(switches::kEnableViewport);
[email protected]5b52cd2f712012-03-28 02:12:483496 bool enable_fixed_layout =
3497 command_line.HasSwitch(switches::kEnableFixedLayout);
3498
3499 webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport);
[email protected]5b52cd2f712012-03-28 02:12:483500
[email protected]47e932da2013-03-07 00:11:243501 // If viewport tag is enabled, then the WebKit side will take care
3502 // of setting the fixed layout size and page scale limits.
3503 if (enable_viewport)
3504 return;
3505
[email protected]a02a0c92013-08-12 20:18:583506 // When navigating to a new page, reset the page scale factor to be 1.0.
3507 webview()->setInitialPageScaleOverride(1.f);
3508
[email protected]47e932da2013-03-07 00:11:243509 if (enable_fixed_layout) {
[email protected]5b52cd2f712012-03-28 02:12:483510 std::string str =
3511 command_line.GetSwitchValueASCII(switches::kEnableFixedLayout);
3512 std::vector<std::string> tokens;
3513 base::SplitString(str, ',', &tokens);
3514 if (tokens.size() == 2) {
3515 int width, height;
3516 if (base::StringToInt(tokens[0], &width) &&
3517 base::StringToInt(tokens[1], &height))
[email protected]e1ed5a12012-08-08 19:57:443518 webview()->setFixedLayoutSize(WebSize(width, height));
[email protected]5b52cd2f712012-03-28 02:12:483519 }
3520 }
[email protected]e4cd82e2013-04-10 15:20:383521 float maxPageScaleFactor =
3522 command_line.HasSwitch(switches::kEnablePinch) ? 4.f : 1.f ;
3523 webview()->setPageScaleFactorLimits(1, maxPageScaleFactor);
[email protected]5b52cd2f712012-03-28 02:12:483524}
3525
[email protected]310ebd6302011-10-10 19:06:283526void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173527 WebDataSource* ds = frame->provisionalDataSource();
[email protected]09c48ef52013-01-09 12:25:073528
3529 // In fast/loader/stop-provisional-loads.html, we abort the load before this
3530 // callback is invoked.
3531 if (!ds)
3532 return;
3533
[email protected]007733c2011-11-17 00:34:073534 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:173535
[email protected]890b06ca2012-12-13 21:07:363536 // We should only navigate to swappedout:// when is_swapped_out_ is true.
3537 CHECK((ds->request().url() != GURL(kSwappedOutURL)) ||
3538 is_swapped_out_) << "Heard swappedout:// when not swapped out.";
3539
[email protected]3d9689372009-09-10 04:29:173540 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:073541 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:173542 double event_time = ds->triggeringEventTime();
3543 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:073544 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:173545 }
3546
[email protected]05c8e502010-08-15 15:13:523547 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:073548 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:523549
[email protected]3d9689372009-09-10 04:29:173550 bool is_top_most = !frame->parent();
3551 if (is_top_most) {
[email protected]af15bf22013-03-08 01:18:173552 navigation_gesture_ = WebUserGestureIndicator::isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133553 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173554 } else if (frame->parent()->isLoading()) {
3555 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003556 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:073557 document_state->navigation_state()->set_transition_type(
[email protected]e9ff79c2012-10-19 21:31:263558 PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:173559 }
3560
[email protected]28685da92011-02-07 21:49:173561 FOR_EACH_OBSERVER(
3562 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
3563
[email protected]3d9689372009-09-10 04:29:173564 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]d37c33e2012-10-12 13:35:133565 routing_id_, frame->identifier(),
3566 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]434bc9b2012-11-27 21:22:143567 is_top_most, ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173568}
3569
[email protected]400992b2012-06-14 00:03:543570void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
3571 WebFrame* frame) {
3572 if (frame->parent())
3573 return;
3574 // Received a redirect on the main frame.
3575 WebDataSource* data_source = frame->provisionalDataSource();
3576 if (!data_source) {
3577 // Should only be invoked when we have a data source.
3578 NOTREACHED();
3579 return;
3580 }
3581 std::vector<GURL> redirects;
3582 GetRedirectChain(data_source, &redirects);
3583 if (redirects.size() >= 2) {
3584 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]434bc9b2012-11-27 21:22:143585 redirects[redirects.size() - 2], redirects.back()));
[email protected]400992b2012-06-14 00:03:543586 }
3587}
3588
[email protected]310ebd6302011-10-10 19:06:283589void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
3590 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173591 // Notify the browser that we failed a provisional load with an error.
3592 //
3593 // Note: It is important this notification occur before DidStopLoading so the
3594 // SSL manager can react to the provisional load failure before being
3595 // notified the load stopped.
3596 //
3597 WebDataSource* ds = frame->provisionalDataSource();
3598 DCHECK(ds);
3599
3600 const WebURLRequest& failed_request = ds->request();
3601
[email protected]28685da92011-02-07 21:49:173602 FOR_EACH_OBSERVER(
3603 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
3604
[email protected]3d9689372009-09-10 04:29:173605 bool show_repost_interstitial =
3606 (error.reason == net::ERR_CACHE_MISS &&
3607 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:583608
3609 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
3610 params.frame_id = frame->identifier();
3611 params.is_main_frame = !frame->parent();
3612 params.error_code = error.reason;
[email protected]e9ff79c2012-10-19 21:31:263613 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]8da4d262013-04-23 05:15:533614 frame,
[email protected]d7b175e2011-10-11 15:31:583615 failed_request,
3616 error,
3617 NULL,
3618 &params.error_description);
3619 params.url = error.unreachableURL;
3620 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:173621 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:583622 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:173623
3624 // Don't display an error page if this is simply a cancelled load. Aside
3625 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3626 if (error.reason == net::ERR_ABORTED)
3627 return;
3628
[email protected]f677288e2013-09-18 02:11:003629 // Don't display "client blocked" error page if browser has asked us not to.
3630 if (error.reason == net::ERR_BLOCKED_BY_CLIENT &&
3631 renderer_preferences_.disable_client_blocked_error_page) {
3632 return;
3633 }
3634
[email protected]70dee7e2013-05-29 18:28:303635 if (RenderThreadImpl::current()->layout_test_mode())
[email protected]ac7f5a02013-03-16 16:14:413636 return;
3637
[email protected]3d9689372009-09-10 04:29:173638 // Make sure we never show errors in view source mode.
3639 frame->enableViewSourceMode(false);
3640
[email protected]007733c2011-11-17 00:34:073641 DocumentState* document_state = DocumentState::FromDataSource(ds);
3642 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173643
3644 // If this is a failed back/forward/reload navigation, then we need to do a
3645 // 'replace' load. This is necessary to avoid messing up session history.
3646 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3647 // as session history is concerned.
3648 //
3649 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3650 // the page id.
3651 //
3652 bool replace =
3653 navigation_state->pending_page_id() != -1 ||
[email protected]026aac22013-07-10 02:09:113654 PageTransitionCoreTypeIs(navigation_state->transition_type(),
3655 PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:173656
3657 // If we failed on a browser initiated request, then make sure that our error
3658 // page load is regarded as the same browser initiated request.
3659 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:073660 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
3661 pending_navigation_params_->page_id =
3662 navigation_state->pending_page_id();
3663 pending_navigation_params_->pending_history_list_offset =
3664 navigation_state->pending_history_list_offset();
[email protected]60d6cca2013-04-30 08:47:133665 pending_navigation_params_->should_clear_history_list =
3666 navigation_state->history_list_was_cleared();
[email protected]007733c2011-11-17 00:34:073667 pending_navigation_params_->transition =
3668 navigation_state->transition_type();
3669 pending_navigation_params_->request_time =
3670 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:173671 }
3672
3673 // Provide the user with a more helpful error page?
3674 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3675 return;
3676
3677 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083678 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173679}
3680
[email protected]310ebd6302011-10-10 19:06:283681void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
3682 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:073683 DocumentState* document_state =
3684 DocumentState::FromDataSource(frame->dataSource());
3685 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e20b88d2013-04-09 15:28:373686 InternalDocumentStateData* internal_data =
3687 InternalDocumentStateData::FromDocumentState(document_state);
[email protected]3d9689372009-09-10 04:29:173688
[email protected]007733c2011-11-17 00:34:073689 if (document_state->commit_load_time().is_null())
3690 document_state->set_commit_load_time(Time::Now());
3691
[email protected]e20b88d2013-04-09 15:28:373692 if (internal_data->must_reset_scroll_and_scale_state()) {
[email protected]06c7ba022012-12-17 19:24:123693 webview()->resetScrollAndScaleState();
[email protected]e20b88d2013-04-09 15:28:373694 internal_data->set_must_reset_scroll_and_scale_state(false);
[email protected]a3a5397d2012-09-12 06:50:343695 }
[email protected]4b9c9e292013-07-18 19:13:283696 internal_data->set_use_error_page(false);
[email protected]a3a5397d2012-09-12 06:50:343697
[email protected]3d9689372009-09-10 04:29:173698 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203699 // When we perform a new navigation, we need to update the last committed
3700 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173701 UpdateSessionHistory(frame);
3702
3703 // We bump our Page ID to correspond with the new session history entry.
3704 page_id_ = next_page_id_++;
3705
[email protected]e9ff79c2012-10-19 21:31:263706 // Don't update history_page_ids_ (etc) for kSwappedOutURL, since
[email protected]58436a12012-03-21 17:10:263707 // we don't want to forget the entry that was there, and since we will
[email protected]e9ff79c2012-10-19 21:31:263708 // never come back to kSwappedOutURL. Note that we have to call
[email protected]69ddf852012-02-21 23:21:313709 // UpdateSessionHistory and update page_id_ even in this case, so that
3710 // the current entry gets a state update and so that we don't send a
3711 // state update to the wrong entry when we swap back in.
[email protected]e9ff79c2012-10-19 21:31:263712 if (GetLoadingUrl(frame) != GURL(kSwappedOutURL)) {
[email protected]69ddf852012-02-21 23:21:313713 // Advance our offset in session history, applying the length limit.
3714 // There is now no forward history.
3715 history_list_offset_++;
[email protected]e9ff79c2012-10-19 21:31:263716 if (history_list_offset_ >= kMaxSessionHistoryEntries)
3717 history_list_offset_ = kMaxSessionHistoryEntries - 1;
[email protected]69ddf852012-02-21 23:21:313718 history_list_length_ = history_list_offset_ + 1;
3719 history_page_ids_.resize(history_list_length_, -1);
3720 history_page_ids_[history_list_offset_] = page_id_;
3721 }
[email protected]3d9689372009-09-10 04:29:173722 } else {
3723 // Inspect the navigation_state on this frame to see if the navigation
3724 // corresponds to a session history navigation... Note: |frame| may or
3725 // may not be the toplevel frame, but for the case of capturing session
3726 // history, the first committed frame suffices. We keep track of whether
3727 // we've seen this commit before so that only capture session history once
3728 // per navigation.
3729 //
3730 // Note that we need to check if the page ID changed. In the case of a
3731 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3732 // previous URL and the current page ID, which would be wrong.
3733 if (navigation_state->pending_page_id() != -1 &&
3734 navigation_state->pending_page_id() != page_id_ &&
3735 !navigation_state->request_committed()) {
3736 // This is a successful session history navigation!
3737 UpdateSessionHistory(frame);
3738 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003739
3740 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:033741
3742 // If the history list is valid, our list of page IDs should be correct.
3743 DCHECK(history_list_length_ <= 0 ||
3744 history_list_offset_ < 0 ||
3745 history_list_offset_ >= history_list_length_ ||
3746 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:173747 }
3748 }
3749
[email protected]28685da92011-02-07 21:49:173750 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3751 DidCommitProvisionalLoad(frame, is_new_navigation));
3752
[email protected]3d9689372009-09-10 04:29:173753 // Remember that we've already processed this request, so we don't update
3754 // the session history again. We do this regardless of whether this is
3755 // a session history navigation, because if we attempted a session history
3756 // navigation without valid HistoryItem state, WebCore will think it is a
3757 // new navigation.
3758 navigation_state->set_request_committed(true);
3759
3760 UpdateURL(frame);
3761
[email protected]3d9689372009-09-10 04:29:173762 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273763 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]b2d98762012-09-03 17:04:063764
3765 if (!frame->parent()) { // Only for top frames.
3766 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
3767 if (render_thread_impl) { // Can be NULL in tests.
3768 render_thread_impl->histogram_customizer()->
3769 RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(),
3770 g_view_map.Get().size());
3771 }
3772 }
[email protected]3d9689372009-09-10 04:29:173773}
3774
[email protected]310ebd6302011-10-10 19:06:283775void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:103776 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3777 DidClearWindowObject(frame));
3778
[email protected]e9ff79c2012-10-19 21:31:263779 if (enabled_bindings_ & BINDINGS_POLICY_DOM_AUTOMATION) {
[email protected]59383c782013-04-17 16:43:273780 if (!dom_automation_controller_)
[email protected]766a7082012-02-03 23:39:153781 dom_automation_controller_.reset(new DomAutomationController());
3782 dom_automation_controller_->set_message_sender(
[email protected]e9ff79c2012-10-19 21:31:263783 static_cast<RenderView*>(this));
[email protected]766a7082012-02-03 23:39:153784 dom_automation_controller_->set_routing_id(routing_id());
3785 dom_automation_controller_->BindToJavascript(frame,
3786 "domAutomationController");
3787 }
[email protected]27c521a2013-05-29 20:44:323788
3789 if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION) {
3790 if (!stats_collection_controller_.get())
3791 stats_collection_controller_.reset(new StatsCollectionController());
3792 stats_collection_controller_->set_message_sender(
3793 static_cast<RenderView*>(this));
3794 stats_collection_controller_->BindToJavascript(frame,
3795 "statsCollectionController");
3796 }
[email protected]3d9689372009-09-10 04:29:173797}
3798
[email protected]310ebd6302011-10-10 19:06:283799void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:033800 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3801 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:173802}
3803
[email protected]310ebd6302011-10-10 19:06:283804void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
3805 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:463806 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:173807
3808 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273809 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173810}
3811
[email protected]41225fe2013-03-29 05:32:023812void RenderViewImpl::didChangeIcon(WebFrame* frame,
3813 WebIconURL::Type icon_type) {
3814 if (frame->parent())
3815 return;
3816
3817 if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon)
3818 return;
3819
3820 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type);
3821 std::vector<FaviconURL> urls;
3822 for (size_t i = 0; i < icon_urls.size(); i++) {
3823 urls.push_back(FaviconURL(icon_urls[i].iconURL(),
3824 ToFaviconType(icon_urls[i].iconType())));
3825 }
3826 SendUpdateFaviconURL(urls);
[email protected]5019ef12010-04-27 17:26:583827}
3828
[email protected]310ebd6302011-10-10 19:06:283829void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173830 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073831 DocumentState* document_state = DocumentState::FromDataSource(ds);
3832 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:173833
[email protected]622474d2010-11-04 09:21:083834 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173835
[email protected]28685da92011-02-07 21:49:173836 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3837 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173838
3839 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273840 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173841}
3842
[email protected]310ebd6302011-10-10 19:06:283843void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083844 if (webview()->mainFrame() == frame) {
3845 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3846 page_id_));
3847 }
[email protected]3d9689372009-09-10 04:29:173848}
3849
[email protected]310ebd6302011-10-10 19:06:283850void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:313851 WebDataSource* ds = frame->dataSource();
3852 DCHECK(ds);
3853
3854
[email protected]28685da92011-02-07 21:49:173855 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:313856
3857 const WebURLRequest& failed_request = ds->request();
3858 string16 error_description;
[email protected]e9ff79c2012-10-19 21:31:263859 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]8da4d262013-04-23 05:15:533860 frame,
[email protected]1a55c5be2011-11-29 11:36:313861 failed_request,
3862 error,
3863 NULL,
3864 &error_description);
3865 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
3866 frame->identifier(),
3867 failed_request.url(),
3868 !frame->parent(),
3869 error.reason,
3870 error_description));
[email protected]3d9689372009-09-10 04:29:173871}
3872
[email protected]310ebd6302011-10-10 19:06:283873void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173874 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073875 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]1ac2ff12013-07-16 20:53:533876 if (document_state->finish_load_time().is_null()) {
3877 if (!frame->parent()) {
3878 TRACE_EVENT_INSTANT0("WebCore", "LoadFinished",
3879 TRACE_EVENT_SCOPE_PROCESS);
3880 }
[email protected]007733c2011-11-17 00:34:073881 document_state->set_finish_load_time(Time::Now());
[email protected]1ac2ff12013-07-16 20:53:533882 }
[email protected]4d44a1c2010-04-28 19:20:413883
[email protected]676126f72011-01-15 00:03:513884 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173885
[email protected]1a55c5be2011-11-29 11:36:313886 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
3887 frame->identifier(),
3888 ds->request().url(),
3889 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:173890}
3891
[email protected]310ebd6302011-10-10 19:06:283892void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173893 WebFrame* frame, bool is_new_navigation) {
3894 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:073895 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:173896 // update the ExtraData on the datasource so that others who read the
3897 // ExtraData will get the new NavigationState. Similarly, if we did not
3898 // initiate this navigation, then we need to take care to reset any pre-
3899 // existing navigation state to a content-initiated navigation state.
3900 // DidCreateDataSource conveniently takes care of this for us.
3901 didCreateDataSource(frame, frame->dataSource());
3902
[email protected]007733c2011-11-17 00:34:073903 DocumentState* document_state =
3904 DocumentState::FromDataSource(frame->dataSource());
3905 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:093906 new_state->set_was_within_same_page(true);
3907
[email protected]3d9689372009-09-10 04:29:173908 didCommitProvisionalLoad(frame, is_new_navigation);
[email protected]3d9689372009-09-10 04:29:173909}
3910
[email protected]310ebd6302011-10-10 19:06:283911void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313912 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593913}
3914
[email protected]310ebd6302011-10-10 19:06:283915void RenderViewImpl::willSendRequest(WebFrame* frame,
3916 unsigned identifier,
3917 WebURLRequest& request,
3918 const WebURLResponse& redirect_response) {
[email protected]e507045d2013-07-24 15:23:443919 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:173920}
3921
[email protected]310ebd6302011-10-10 19:06:283922void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173923 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]e507045d2013-07-24 15:23:443924 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:173925}
3926
[email protected]310ebd6302011-10-10 19:06:283927void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173928 WebFrame* frame, unsigned identifier) {
[email protected]e20b88d2013-04-09 15:28:373929 InternalDocumentStateData* internal_data =
3930 InternalDocumentStateData::FromDataSource(frame->dataSource());
3931 if (!internal_data->use_error_page())
[email protected]3d9689372009-09-10 04:29:173932 return;
3933
[email protected]7bfc153f2011-09-23 22:00:203934 // Do not show error page when DevTools is attached.
3935 if (devtools_agent_->IsAttached())
3936 return;
3937
[email protected]06333afe2011-02-24 14:55:093938 // Display error page, if appropriate.
[email protected]e20b88d2013-04-09 15:28:373939 int http_status_code = internal_data->http_status_code();
[email protected]3f853a52010-09-13 19:15:083940 if (http_status_code == 404) {
3941 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413942 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173943
[email protected]b6cb3a842011-06-24 18:28:413944 const GURL& error_page_url =
3945 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093946 if (error_page_url.is_valid()) {
3947 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473948 original_error.domain = "http";
3949 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413950 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173951
[email protected]e20b88d2013-04-09 15:28:373952 internal_data->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093953 new AltErrorPageResourceFetcher(
[email protected]11a65772013-04-27 00:36:423954 error_page_url, frame, frame->dataSource()->request(),
3955 original_error,
[email protected]6e806822011-11-19 01:51:083956 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3957 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093958 return;
3959 }
3960 }
[email protected]3d9689372009-09-10 04:29:173961
[email protected]e6a2ce52011-10-08 01:40:133962 std::string error_domain;
[email protected]e9ff79c2012-10-19 21:31:263963 if (GetContentClient()->renderer()->HasErrorPage(
[email protected]e6a2ce52011-10-08 01:40:133964 http_status_code, &error_domain)) {
3965 WebURLError error;
3966 error.unreachableURL = frame->document().url();
3967 error.domain = WebString::fromUTF8(error_domain);
3968 error.reason = http_status_code;
3969
3970 LoadNavigationErrorPage(
3971 frame, frame->dataSource()->request(), error, std::string(), true);
3972 }
[email protected]3d9689372009-09-10 04:29:173973}
3974
[email protected]310ebd6302011-10-10 19:06:283975void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173976 WebFrame* frame, const WebURLRequest& request,
3977 const WebURLResponse& response) {
[email protected]e507045d2013-07-24 15:23:443978 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:173979}
3980
[email protected]310ebd6302011-10-10 19:06:283981void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e507045d2013-07-24 15:23:443982 NOTREACHED();
[email protected]e3d60e5d2009-09-25 21:08:293983}
3984
[email protected]310ebd6302011-10-10 19:06:283985void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023986 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e507045d2013-07-24 15:23:443987 NOTREACHED();
[email protected]e3d60e5d2009-09-25 21:08:293988}
3989
[email protected]310ebd6302011-10-10 19:06:283990void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]e507045d2013-07-24 15:23:443991 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:173992}
3993
[email protected]310ebd6302011-10-10 19:06:283994void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3995 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583996 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283997 int world_id) {
[email protected]e507045d2013-07-24 15:23:443998 NOTREACHED();
[email protected]a00fe692012-02-27 05:52:583999}
4000
[email protected]310ebd6302011-10-10 19:06:284001void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
4002 v8::Handle<v8::Context> context,
4003 int world_id) {
[email protected]e507045d2013-07-24 15:23:444004 NOTREACHED();
[email protected]0c882b282009-10-07 17:01:284005}
4006
[email protected]310ebd6302011-10-10 19:06:284007void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:074008 // We don't always want to send the change messages over IPC, only if we've
4009 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
4010 // message.
4011 if (!send_preferred_size_changes_ || !webview())
4012 return;
4013
[email protected]e76b7972013-06-06 02:58:484014 gfx::Size size = webview()->contentsPreferredMinimumSize();
[email protected]8205d742010-10-22 23:51:534015
[email protected]7940b8e2013-07-25 23:08:494016 // In the presence of zoom, these sizes are still reported as if unzoomed,
4017 // so we need to adjust.
4018 double zoom_factor = ZoomLevelToZoomFactor(webview()->zoomLevel());
4019 size.set_width(static_cast<int>(size.width() * zoom_factor));
4020 size.set_height(static_cast<int>(size.height() * zoom_factor));
4021
[email protected]705243f2010-05-05 19:58:074022 if (size == preferred_size_)
4023 return;
[email protected]c27324b2009-11-19 22:44:294024
[email protected]705243f2010-05-05 19:58:074025 preferred_size_ = size;
4026 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
4027 preferred_size_));
[email protected]3d9689372009-09-10 04:29:174028}
4029
[email protected]caaf2482013-05-01 20:33:324030BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() {
[email protected]fc72bb12013-06-02 21:13:464031 if (!browser_plugin_manager_.get())
[email protected]fb325d122012-11-20 23:58:054032 browser_plugin_manager_ = BrowserPluginManager::Create(this);
[email protected]fc72bb12013-06-02 21:13:464033 return browser_plugin_manager_.get();
[email protected]fb325d122012-11-20 23:58:054034}
4035
[email protected]60ee79f2013-09-11 13:49:554036bool RenderViewImpl::InitializeMediaStreamClient() {
4037 if (media_stream_client_)
4038 return true;
4039
[email protected]7082fb942012-05-16 23:44:594040 if (!RenderThreadImpl::current()) // Will be NULL during unit tests.
[email protected]60ee79f2013-09-11 13:49:554041 return false;
[email protected]08381562012-05-15 20:55:404042
[email protected]d9da9582013-01-31 04:59:054043#if defined(OS_ANDROID)
[email protected]ce585bf2013-03-14 16:25:164044 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableWebRTC))
[email protected]60ee79f2013-09-11 13:49:554045 return false;
[email protected]d9da9582013-01-31 04:59:054046#endif
4047
[email protected]4fb0f202012-05-30 22:44:534048#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:514049 if (!media_stream_dispatcher_)
4050 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
4051
[email protected]60ee79f2013-09-11 13:49:554052 MediaStreamImpl* media_stream_impl = new MediaStreamImpl(
4053 this,
4054 media_stream_dispatcher_,
4055 RenderThreadImpl::current()->GetMediaStreamDependencyFactory());
4056 media_stream_client_ = media_stream_impl;
4057 web_user_media_client_ = media_stream_impl;
4058 return true;
4059#else
4060 return false;
[email protected]5b87e782012-02-09 18:19:324061#endif
[email protected]273558fb2012-01-12 15:03:514062}
4063
[email protected]310ebd6302011-10-10 19:06:284064void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
4065 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:314066 if (webview()->mainFrame() != frame)
4067 return;
4068 WebView* frameView = frame->view();
4069 if (!frameView)
4070 return;
4071
4072 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
4073 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
4074
4075 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
4076 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
4077 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
4078 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
4079
4080 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
4081 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
4082 }
4083}
4084
[email protected]310ebd6302011-10-10 19:06:284085void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:314086 WebSize offset = frame->scrollOffset();
4087 WebSize minimum_offset = frame->minimumScrollOffset();
4088 WebSize maximum_offset = frame->maximumScrollOffset();
4089
4090 bool is_pinned_to_left = offset.width <= minimum_offset.width;
4091 bool is_pinned_to_right = offset.width >= maximum_offset.width;
4092
4093 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
4094 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
4095 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
4096 routing_id_, is_pinned_to_left, is_pinned_to_right));
4097
4098 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
4099 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
4100 }
[email protected]4e721742013-02-04 21:39:304101
4102 Send(new ViewHostMsg_DidChangeScrollOffset(routing_id_));
[email protected]dd6afca2011-08-13 03:44:314103}
4104
[email protected]310ebd6302011-10-10 19:06:284105void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:494106 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:314107
4108 if (webview()->mainFrame() == frame)
4109 UpdateScrollState(frame);
[email protected]2b942c332012-04-25 16:26:264110
4111 FOR_EACH_OBSERVER(
4112 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]dd6afca2011-08-13 03:44:314113}
4114
[email protected]a9344092d2013-02-27 00:56:454115void RenderViewImpl::willInsertBody(WebKit::WebFrame* frame) {
[email protected]e507045d2013-07-24 15:23:444116 NOTREACHED();
[email protected]a9344092d2013-02-27 00:56:454117}
4118
[email protected]4d0f8182012-10-19 23:14:474119void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebFrame* frame) {
4120 if (frame != webview()->mainFrame())
4121 return;
4122
[email protected]92d457802013-04-01 19:18:494123 InternalDocumentStateData* data =
4124 InternalDocumentStateData::FromDataSource(frame->dataSource());
4125 data->set_did_first_visually_non_empty_layout(true);
4126
4127#if defined(OS_ANDROID)
[email protected]4d0f8182012-10-19 23:14:474128 // Update body background color if necessary.
4129 SkColor bg_color = webwidget_->backgroundColor();
4130
4131 // If not initialized, default to white. Note that 0 is different from black
4132 // as black still has alpha 0xFF.
4133 if (!bg_color)
4134 bg_color = SK_ColorWHITE;
4135
4136 if (bg_color != body_background_color_) {
4137 body_background_color_ = bg_color;
[email protected]e507045d2013-07-24 15:23:444138 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(
4139 GetRoutingID(), bg_color));
[email protected]4d0f8182012-10-19 23:14:474140 }
[email protected]4d0f8182012-10-19 23:14:474141#endif
[email protected]92d457802013-04-01 19:18:494142}
[email protected]4d0f8182012-10-19 23:14:474143
[email protected]55750b32012-09-21 14:05:034144void RenderViewImpl::SendFindReply(int request_id,
4145 int match_count,
4146 int ordinal,
4147 const WebRect& selection_rect,
4148 bool final_status_update) {
[email protected]55750b32012-09-21 14:05:034149 Send(new ViewHostMsg_Find_Reply(routing_id_,
4150 request_id,
4151 match_count,
4152 selection_rect,
4153 ordinal,
4154 final_status_update));
4155}
4156
[email protected]432c9a72013-02-27 01:51:034157// static
4158bool RenderViewImpl::ShouldUpdateSelectionTextFromContextMenuParams(
4159 const string16& selection_text,
4160 size_t selection_text_offset,
[email protected]db4fc1e2013-09-06 20:01:514161 const gfx::Range& selection_range,
[email protected]432c9a72013-02-27 01:51:034162 const ContextMenuParams& params) {
4163 string16 trimmed_selection_text;
4164 if (!selection_text.empty() && !selection_range.is_empty()) {
4165 const int start = selection_range.GetMin() - selection_text_offset;
4166 const size_t length = selection_range.length();
4167 if (start >= 0 && start + length <= selection_text.length()) {
4168 TrimWhitespace(selection_text.substr(start, length), TRIM_ALL,
4169 &trimmed_selection_text);
4170 }
4171 }
4172 string16 trimmed_params_text;
4173 TrimWhitespace(params.selection_text, TRIM_ALL, &trimmed_params_text);
4174 return trimmed_params_text != trimmed_selection_text;
4175}
4176
[email protected]55750b32012-09-21 14:05:034177void RenderViewImpl::reportFindInPageMatchCount(int request_id,
4178 int count,
[email protected]310ebd6302011-10-10 19:06:284179 bool final_update) {
[email protected]1f35b45e2013-08-29 17:36:464180 // TODO(jam): switch PepperPluginInstanceImpl to take a RenderFrame
4181 main_render_frame_->reportFindInPageMatchCount(
4182 request_id, count, final_update);
[email protected]8922e1f2009-10-03 05:01:264183}
4184
[email protected]310ebd6302011-10-10 19:06:284185void RenderViewImpl::reportFindInPageSelection(int request_id,
4186 int active_match_ordinal,
4187 const WebRect& selection_rect) {
[email protected]1f35b45e2013-08-29 17:36:464188 // TODO(jam): switch PepperPluginInstanceImpl to take a RenderFrame
4189 main_render_frame_->reportFindInPageSelection(
4190 request_id, active_match_ordinal, selection_rect);
[email protected]8922e1f2009-10-03 05:01:264191}
4192
[email protected]310ebd6302011-10-10 19:06:284193void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:404194 WebFrame* frame,
4195 WebStorageQuotaType type,
4196 unsigned long long requested_size,
4197 WebStorageQuotaCallbacks* callbacks) {
[email protected]e507045d2013-07-24 15:23:444198 NOTREACHED();
[email protected]10e5cf12011-04-13 04:10:404199}
4200
[email protected]f546640b2012-05-15 00:03:494201bool RenderViewImpl::willCheckAndDispatchMessageEvent(
[email protected]0720b532012-08-28 19:23:374202 WebKit::WebFrame* sourceFrame,
4203 WebKit::WebFrame* targetFrame,
[email protected]f546640b2012-05-15 00:03:494204 WebKit::WebSecurityOrigin target_origin,
4205 WebKit::WebDOMMessageEvent event) {
4206 if (!is_swapped_out_)
4207 return false;
4208
4209 ViewMsg_PostMessage_Params params;
4210 params.data = event.data().toString();
4211 params.source_origin = event.origin();
4212 if (!target_origin.isNull())
4213 params.target_origin = target_origin.toString();
4214
4215 // Include the routing ID for the source frame, which the browser process
4216 // will translate into the routing ID for the equivalent frame in the target
4217 // process.
[email protected]f546640b2012-05-15 00:03:494218 params.source_routing_id = MSG_ROUTING_NONE;
[email protected]0720b532012-08-28 19:23:374219 RenderViewImpl* source_view = FromWebView(sourceFrame->view());
[email protected]f546640b2012-05-15 00:03:494220 if (source_view)
4221 params.source_routing_id = source_view->routing_id();
4222
4223 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params));
4224 return true;
4225}
4226
[email protected]5fa3a062012-03-21 15:39:344227void RenderViewImpl::willOpenSocketStream(
4228 WebSocketStreamHandle* handle) {
[email protected]e507045d2013-07-24 15:23:444229 NOTREACHED();
[email protected]5fa3a062012-03-21 15:39:344230}
4231
[email protected]ccee4862012-10-03 18:34:264232void RenderViewImpl::willStartUsingPeerConnectionHandler(
4233 WebKit::WebFrame* frame, WebKit::WebRTCPeerConnectionHandler* handler) {
[email protected]e507045d2013-07-24 15:23:444234 NOTREACHED();
[email protected]ccee4862012-10-03 18:34:264235}
4236
[email protected]9982c802013-06-12 15:22:064237WebKit::WebString RenderViewImpl::acceptLanguages() {
4238 return WebString::fromUTF8(renderer_preferences_.accept_languages);
4239}
4240
[email protected]bf70edce2012-06-20 22:32:224241WebKit::WebString RenderViewImpl::userAgentOverride(
4242 WebKit::WebFrame* frame,
4243 const WebKit::WebURL& url) {
[email protected]e507045d2013-07-24 15:23:444244 NOTREACHED();
[email protected]e20b88d2013-04-09 15:28:374245 return WebKit::WebString();
[email protected]bf70edce2012-06-20 22:32:224246}
4247
[email protected]a3e217f2013-04-12 22:38:344248WebString RenderViewImpl::doNotTrackValue(WebFrame* frame) {
[email protected]e507045d2013-07-24 15:23:444249 NOTREACHED();
4250 return WebKit::WebString();
[email protected]a3e217f2013-04-12 22:38:344251}
4252
[email protected]818915cd2012-11-20 13:14:114253bool RenderViewImpl::allowWebGL(WebFrame* frame, bool default_value) {
[email protected]e507045d2013-07-24 15:23:444254 NOTREACHED();
4255 return false;
[email protected]818915cd2012-11-20 13:14:114256}
4257
4258void RenderViewImpl::didLoseWebGLContext(
4259 WebKit::WebFrame* frame,
4260 int arb_robustness_status_code) {
[email protected]e507045d2013-07-24 15:23:444261 NOTREACHED();
[email protected]818915cd2012-11-20 13:14:114262}
4263
[email protected]18d5be92011-07-25 18:00:194264// WebKit::WebPageSerializerClient implementation ------------------------------
4265
[email protected]310ebd6302011-10-10 19:06:284266void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:194267 const WebURL& frame_url,
4268 const WebCString& data,
4269 WebPageSerializerClient::PageSerializationStatus status) {
4270 Send(new ViewHostMsg_SendSerializedHtmlData(
4271 routing_id(),
4272 frame_url,
4273 data.data(),
4274 static_cast<int32>(status)));
4275}
4276
[email protected]e9ff79c2012-10-19 21:31:264277// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:314278
[email protected]310ebd6302011-10-10 19:06:284279bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:314280 return RenderWidget::Send(message);
4281}
4282
[email protected]82114f52012-03-20 22:53:414283int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:314284 return routing_id_;
4285}
4286
[email protected]82114f52012-03-20 22:53:414287int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:314288 return page_id_;
4289}
4290
[email protected]82114f52012-03-20 22:53:414291gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:314292 return size();
4293}
4294
[email protected]82114f52012-03-20 22:53:414295WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:314296 return webkit_preferences_;
4297}
4298
[email protected]324825d2012-11-30 12:37:154299void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
4300 OnUpdateWebPreferences(preferences);
4301}
4302
[email protected]82114f52012-03-20 22:53:414303WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:314304 return webview();
4305}
4306
[email protected]82114f52012-03-20 22:53:414307WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:314308 if (!webview())
4309 return WebNode();
4310 WebFrame* focused_frame = webview()->focusedFrame();
4311 if (focused_frame) {
4312 WebDocument doc = focused_frame->document();
4313 if (!doc.isNull())
4314 return doc.focusedNode();
4315 }
4316
4317 return WebNode();
4318}
4319
[email protected]82114f52012-03-20 22:53:414320WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:314321 return context_menu_node_;
4322}
4323
[email protected]2a84f9d2012-06-05 21:50:434324bool RenderViewImpl::IsEditableNode(const WebNode& node) const {
4325 if (node.isNull())
4326 return false;
4327
4328 if (node.isContentEditable())
4329 return true;
4330
4331 if (node.isElementNode()) {
4332 const WebElement& element = node.toConst<WebElement>();
4333 if (element.isTextFormControlElement())
4334 return true;
4335
4336 // Also return true if it has an ARIA role of 'textbox'.
4337 for (unsigned i = 0; i < element.attributeCount(); ++i) {
4338 if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) {
4339 if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox"))
4340 return true;
4341 break;
4342 }
[email protected]a2ef54c2011-10-10 16:20:314343 }
4344 }
[email protected]2a84f9d2012-06-05 21:50:434345
4346 return false;
[email protected]a2ef54c2011-10-10 16:20:314347}
4348
[email protected]310ebd6302011-10-10 19:06:284349WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:314350 WebKit::WebFrame* frame,
[email protected]d7bd3e52013-07-21 04:29:204351 const WebPluginInfo& info,
[email protected]82114f52012-03-20 22:53:414352 const WebKit::WebPluginParams& params) {
[email protected]ea2fb972013-08-07 05:44:264353#if defined(ENABLE_PLUGINS)
4354 bool pepper_plugin_was_registered = false;
4355 scoped_refptr<PluginModule> pepper_module(PluginModule::Create(
4356 this, info, &pepper_plugin_was_registered));
4357 if (pepper_plugin_was_registered) {
4358 if (pepper_module.get())
4359 return new PepperWebPluginImpl(pepper_module.get(), params, AsWeakPtr());
4360 }
[email protected]a2ef54c2011-10-10 16:20:314361
[email protected]29e2fb42013-07-19 01:13:474362 return new WebPluginImpl(frame, params, info.path, AsWeakPtr());
[email protected]ea2fb972013-08-07 05:44:264363#else
4364 return NULL;
4365#endif
[email protected]a2ef54c2011-10-10 16:20:314366}
4367
[email protected]310ebd6302011-10-10 19:06:284368void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
4369 const string16& jscript,
4370 int id,
4371 bool notify_result) {
[email protected]e1907b432013-09-04 16:11:144372 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
[email protected]a2ef54c2011-10-10 16:20:314373 v8::Handle<v8::Value> result;
4374 WebFrame* web_frame = GetChildFrame(frame_xpath);
4375 if (web_frame)
4376 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
4377 if (notify_result) {
[email protected]0cd50aa2013-02-12 22:28:014378 base::ListValue list;
[email protected]a2ef54c2011-10-10 16:20:314379 if (!result.IsEmpty() && web_frame) {
[email protected]a2ef54c2011-10-10 16:20:314380 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4381 v8::Context::Scope context_scope(context);
4382 V8ValueConverterImpl converter;
[email protected]3de391e82012-05-16 17:50:514383 converter.SetDateAllowed(true);
[email protected]e0658bc2012-09-17 04:05:244384 converter.SetRegExpAllowed(true);
4385 base::Value* result_value = converter.FromV8Value(result, context);
[email protected]0cd50aa2013-02-12 22:28:014386 list.Set(0, result_value ? result_value : base::Value::CreateNullValue());
[email protected]a2ef54c2011-10-10 16:20:314387 } else {
[email protected]0cd50aa2013-02-12 22:28:014388 list.Set(0, base::Value::CreateNullValue());
[email protected]a2ef54c2011-10-10 16:20:314389 }
4390 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
4391 }
4392}
4393
[email protected]310ebd6302011-10-10 19:06:284394bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:314395 return (!send_preferred_size_changes_ ||
4396 (disable_scrollbars_size_limit_.width() <= width ||
4397 disable_scrollbars_size_limit_.height() <= height));
4398}
4399
[email protected]82114f52012-03-20 22:53:414400int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:314401 return enabled_bindings_;
4402}
4403
[email protected]82114f52012-03-20 22:53:414404bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:314405 return send_content_state_immediately_;
4406}
4407
[email protected]82114f52012-03-20 22:53:414408float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:314409 return filtered_time_per_frame();
4410}
4411
[email protected]e9ff79c2012-10-19 21:31:264412int RenderViewImpl::ShowContextMenu(ContextMenuClient* client,
4413 const ContextMenuParams& params) {
[email protected]860ee642012-10-13 03:46:254414 DCHECK(client); // A null client means "internal" when we issue callbacks.
[email protected]e9ff79c2012-10-19 21:31:264415 ContextMenuParams our_params(params);
[email protected]860ee642012-10-13 03:46:254416 our_params.custom_context.request_id = pending_context_menus_.Add(client);
4417 Send(new ViewHostMsg_ContextMenu(routing_id_, our_params));
4418 return our_params.custom_context.request_id;
[email protected]a2ef54c2011-10-10 16:20:314419}
4420
[email protected]e0fd0eb2012-10-17 21:11:464421void RenderViewImpl::CancelContextMenu(int request_id) {
4422 DCHECK(pending_context_menus_.Lookup(request_id));
4423 pending_context_menus_.Remove(request_id);
4424}
4425
[email protected]82114f52012-03-20 22:53:414426WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:314427 return visibilityState();
4428}
4429
[email protected]310ebd6302011-10-10 19:06:284430void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
4431 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:314432 return runModalAlertDialog(frame, message);
4433}
4434
[email protected]310ebd6302011-10-10 19:06:284435void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:314436 WebKit::WebFrame* frame,
4437 const WebKit::WebURLRequest& request,
4438 WebKit::WebNavigationPolicy policy) {
[email protected]e507045d2013-07-24 15:23:444439 main_render_frame_->loadURLExternally(frame, request, policy);
[email protected]a2ef54c2011-10-10 16:20:314440}
4441
[email protected]3c71576ce2013-07-23 02:00:014442void RenderViewImpl::DidStartLoading() {
4443 didStartLoading();
4444}
4445
4446void RenderViewImpl::DidStopLoading() {
4447 didStopLoading();
4448}
4449
[email protected]5d65fe92012-06-02 00:48:554450void RenderViewImpl::DidPlay(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074451 Send(new ViewHostMsg_MediaNotification(routing_id_,
4452 reinterpret_cast<int64>(player),
4453 player->hasVideo(),
4454 player->hasAudio(),
4455 true));
4456}
4457
[email protected]5d65fe92012-06-02 00:48:554458void RenderViewImpl::DidPause(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074459 Send(new ViewHostMsg_MediaNotification(routing_id_,
4460 reinterpret_cast<int64>(player),
4461 player->hasVideo(),
4462 player->hasAudio(),
4463 false));
4464}
4465
[email protected]5d65fe92012-06-02 00:48:554466void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074467 DidPause(player);
4468}
4469
[email protected]310ebd6302011-10-10 19:06:284470void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:294471 if (!webview())
4472 return;
4473
[email protected]26aa0482009-09-30 16:55:274474 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:054475 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:294476}
4477
[email protected]310ebd6302011-10-10 19:06:284478void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:364479 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:004480 if (!frame)
4481 return;
[email protected]b781ff282011-08-20 06:19:364482
[email protected]e99ef6f2011-10-16 01:13:004483 string16 text;
4484 size_t offset;
[email protected]db4fc1e2013-09-06 20:01:514485 gfx::Range range;
[email protected]ea2fb972013-08-07 05:44:264486#if defined(ENABLE_PLUGINS)
4487 if (focused_pepper_plugin_) {
4488 focused_pepper_plugin_->GetSurroundingText(&text, &range);
[email protected]82114f52012-03-20 22:53:414489 offset = 0; // Pepper API does not support offset reporting.
[email protected]3c8c74c2012-03-15 07:34:524490 // TODO(kinaba): cut as needed.
[email protected]ea2fb972013-08-07 05:44:264491 } else
4492#endif
4493 {
[email protected]3c8c74c2012-03-15 07:34:524494 size_t location, length;
4495 if (!webview()->caretOrSelectionRange(&location, &length))
4496 return;
4497
[email protected]db4fc1e2013-09-06 20:01:514498 range = gfx::Range(location, location + length);
[email protected]3c8c74c2012-03-15 07:34:524499
[email protected]61232142013-06-20 16:43:324500 if (webview()->textInputInfo().type != WebKit::WebTextInputTypeNone) {
[email protected]3c8c74c2012-03-15 07:34:524501 // If current focused element is editable, we will send 100 more chars
4502 // before and after selection. It is for input method surrounding text
4503 // feature.
4504 if (location > kExtraCharsBeforeAndAfterSelection)
4505 offset = location - kExtraCharsBeforeAndAfterSelection;
4506 else
4507 offset = 0;
4508 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
4509 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
4510 if (!webrange.isNull())
4511 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
4512 } else {
4513 offset = location;
4514 text = frame->selectionAsText();
4515 // http://crbug.com/101435
4516 // In some case, frame->selectionAsText() returned text's length is not
4517 // equal to the length returned from webview()->caretOrSelectionRange().
4518 // So we have to set the range according to text.length().
4519 range.set_end(range.start() + text.length());
4520 }
[email protected]b781ff282011-08-20 06:19:364521 }
4522
[email protected]b781ff282011-08-20 06:19:364523 // Sometimes we get repeated didChangeSelection calls from webkit when
4524 // the selection hasn't actually changed. We don't want to report these
4525 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:004526 if (selection_text_offset_ != offset ||
4527 selection_range_ != range ||
4528 selection_text_ != text) {
4529 selection_text_ = text;
4530 selection_text_offset_ = offset;
4531 selection_range_ = range;
4532 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
4533 }
[email protected]47822262013-04-23 17:22:364534 UpdateSelectionBounds();
[email protected]b781ff282011-08-20 06:19:364535}
4536
[email protected]310ebd6302011-10-10 19:06:284537GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
4538 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554539 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294540 // If the URL that failed was secure, then the embedding web page was not
4541 // expecting a network attacker to be able to manipulate its contents. As
4542 // we fetch alternate error pages over HTTP, we would be allowing a network
4543 // attacker to manipulate the contents of the response if we tried to use
4544 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154545 return GURL();
initial.commit09911bf2008-07-26 23:55:294546 }
4547
4548 // Grab the base URL from the browser process.
4549 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154550 return GURL();
initial.commit09911bf2008-07-26 23:55:294551
4552 // Strip query params from the failed URL.
4553 GURL::Replacements remove_params;
4554 remove_params.ClearUsername();
4555 remove_params.ClearPassword();
4556 remove_params.ClearQuery();
4557 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554558 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504559 std::string spec_to_send = url_to_send.spec();
4560 // Notify link doctor of the url truncation by sending of "?" at the end.
4561 if (failed_url.has_query())
[email protected]82114f52012-03-20 22:53:414562 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294563
4564 // Construct the query params to send to link doctor.
4565 std::string params(alternate_error_page_url_.query());
4566 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:024567 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294568 params.append("&sourceid=chrome");
4569 params.append("&error=");
4570 switch (error_type) {
4571 case DNS_ERROR:
4572 params.append("dnserror");
4573 break;
4574
4575 case HTTP_404:
4576 params.append("http404");
4577 break;
4578
[email protected]5df266ac2008-10-15 19:50:134579 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334580 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134581 break;
4582
initial.commit09911bf2008-07-26 23:55:294583 default:
4584 NOTREACHED() << "unknown ErrorPageType";
4585 }
4586
4587 // OK, build the final url to return.
4588 GURL::Replacements link_doctor_params;
4589 link_doctor_params.SetQueryStr(params);
4590 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4591 return url;
4592}
4593
[email protected]69ddf852012-02-21 23:21:314594GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
4595 WebDataSource* ds = frame->dataSource();
4596 if (ds->hasUnreachableURL())
4597 return ds->unreachableURL();
4598
4599 const WebURLRequest& request = ds->request();
4600 return request.url();
4601}
4602
[email protected]310ebd6302011-10-10 19:06:284603WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:014604 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494605}
4606
[email protected]55750b32012-09-21 14:05:034607void RenderViewImpl::OnFind(int request_id,
4608 const string16& search_text,
[email protected]310ebd6302011-10-10 19:06:284609 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274610 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494611
[email protected]872542532011-06-23 00:43:164612 // Check if the plugin still exists in the document.
4613 if (main_frame->document().isPluginDocument() &&
4614 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494615 if (options.findNext) {
4616 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014617 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494618 } else {
[email protected]55750b32012-09-21 14:05:034619 if (!GetWebPluginFromPluginDocument()->startFind(
[email protected]afdbd142010-07-10 08:01:234620 search_text, options.matchCase, request_id)) {
[email protected]e7c58a32010-08-13 19:47:114621 // Send "no results".
[email protected]55750b32012-09-21 14:05:034622 SendFindReply(request_id, 0, 0, gfx::Rect(), true);
[email protected]24a7f3c2010-03-25 08:26:494623 }
4624 }
4625 return;
4626 }
4627
[email protected]b4bb2502009-10-01 22:35:274628 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274629 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294630 WebFrame* search_frame = focused_frame; // start searching focused frame.
4631
4632 bool multi_frame = (frame_after_main != main_frame);
4633
4634 // If we have multiple frames, we don't want to wrap the search within the
4635 // frame, so we check here if we only have main_frame in the chain.
4636 bool wrap_within_frame = !multi_frame;
4637
[email protected]b3f2b912009-04-09 16:18:524638 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294639 bool result = false;
4640
[email protected]7830da3e2009-11-06 16:27:264641 // If something is selected when we start searching it means we cannot just
4642 // increment the current match ordinal; we need to re-generate it.
4643 WebRange current_selection = focused_frame->selectionRange();
4644
initial.commit09911bf2008-07-26 23:55:294645 do {
[email protected]dd7daa82009-08-10 05:46:454646 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594647 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294648
4649 if (!result) {
4650 // don't leave text selected as you move to the next frame.
[email protected]6dd17a8a2013-05-01 05:50:104651 search_frame->executeCommand(WebString::fromUTF8("Unselect"),
4652 GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:294653
4654 // Find the next frame, but skip the invisible ones.
4655 do {
4656 // What is the next frame to search? (we might be going backwards). Note
4657 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594658 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274659 search_frame->traverseNext(true) :
4660 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454661 } while (!search_frame->hasVisibleContent() &&
4662 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294663
[email protected]884db412008-11-24 23:46:504664 // Make sure selection doesn't affect the search operation in new frame.
[email protected]6dd17a8a2013-05-01 05:50:104665 search_frame->executeCommand(WebString::fromUTF8("Unselect"),
4666 GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:294667
4668 // If we have multiple frames and we have wrapped back around to the
4669 // focused frame, we need to search it once more allowing wrap within
4670 // the frame, otherwise it will report 'no match' if the focused frame has
4671 // reported matches, but no frames after the focused_frame contain a
4672 // match for the search word(s).
4673 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454674 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594675 request_id, search_text, options, true, // Force wrapping.
4676 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294677 }
4678 }
4679
[email protected]26aa0482009-09-30 16:55:274680 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294681 } while (!result && search_frame != focused_frame);
4682
[email protected]7830da3e2009-11-06 16:27:264683 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294684 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454685 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294686 } else {
4687 // If nothing is found, set result to "0 of 0", otherwise, set it to
4688 // "-1 of 1" to indicate that we found at least one item, but we don't know
4689 // yet what is active.
4690 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4691 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294692
[email protected]4f3dc372009-02-24 00:10:294693 // If we find no matches then this will be our last status update.
4694 // Otherwise the scoping effort will send more results.
4695 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294696
[email protected]55750b32012-09-21 14:05:034697 SendFindReply(request_id, match_count, ordinal, selection_rect,
4698 final_status_update);
initial.commit09911bf2008-07-26 23:55:294699
initial.commit09911bf2008-07-26 23:55:294700 // Scoping effort begins, starting with the mainframe.
4701 search_frame = main_frame;
4702
[email protected]dd7daa82009-08-10 05:46:454703 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294704
4705 do {
4706 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454707 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294708
4709 // We don't start another scoping effort unless at least one match has
4710 // been found.
4711 if (result) {
4712 // Start new scoping request. If the scoping function determines that it
4713 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454714 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594715 search_text,
4716 options,
initial.commit09911bf2008-07-26 23:55:294717 true); // reset the tickmarks
4718 }
4719
4720 // Iterate to the next frame. The frame will not necessarily scope, for
4721 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274722 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294723 } while (search_frame != main_frame);
4724 }
4725}
4726
[email protected]e9ff79c2012-10-19 21:31:264727void RenderViewImpl::OnStopFinding(StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:494728 WebView* view = webview();
4729 if (!view)
4730 return;
4731
4732 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:164733 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014734 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494735 return;
4736 }
4737
[email protected]e9ff79c2012-10-19 21:31:264738 bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]6dd17a8a2013-05-01 05:50:104739 if (clear_selection) {
4740 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
4741 GetFocusedNode());
4742 }
[email protected]24a7f3c2010-03-25 08:26:494743
4744 WebFrame* frame = view->mainFrame();
4745 while (frame) {
4746 frame->stopFinding(clear_selection);
4747 frame = frame->traverseNext(false);
4748 }
4749
[email protected]e9ff79c2012-10-19 21:31:264750 if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:494751 WebFrame* focused_frame = view->focusedFrame();
4752 if (focused_frame) {
4753 WebDocument doc = focused_frame->document();
4754 if (!doc.isNull()) {
4755 WebNode node = doc.focusedNode();
4756 if (!node.isNull())
4757 node.simulateClick();
4758 }
4759 }
4760 }
4761}
4762
[email protected]59363fc92012-09-05 03:46:314763#if defined(OS_ANDROID)
4764void RenderViewImpl::OnActivateNearestFindResult(int request_id,
4765 float x, float y) {
4766 if (!webview())
4767 return;
4768
4769 WebFrame* main_frame = webview()->mainFrame();
4770 WebRect selection_rect;
4771 int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y),
4772 &selection_rect);
4773 if (ordinal == -1) {
4774 // Something went wrong, so send a no-op reply (force the main_frame to
4775 // report the current match count) in case the host is waiting for a
4776 // response due to rate-limiting).
4777 main_frame->increaseMatchCount(0, request_id);
4778 return;
4779 }
4780
[email protected]55750b32012-09-21 14:05:034781 SendFindReply(request_id,
4782 -1 /* number_of_matches */,
4783 ordinal,
4784 selection_rect,
4785 true /* final_update */);
[email protected]59363fc92012-09-05 03:46:314786}
4787
4788void RenderViewImpl::OnFindMatchRects(int current_version) {
4789 if (!webview())
4790 return;
4791
4792 WebFrame* main_frame = webview()->mainFrame();
4793 std::vector<gfx::RectF> match_rects;
4794
4795 int rects_version = main_frame->findMatchMarkersVersion();
4796 if (current_version != rects_version) {
4797 WebVector<WebFloatRect> web_match_rects;
4798 main_frame->findMatchRects(web_match_rects);
4799 match_rects.reserve(web_match_rects.size());
4800 for (size_t i = 0; i < web_match_rects.size(); ++i)
4801 match_rects.push_back(gfx::RectF(web_match_rects[i]));
4802 }
4803
4804 gfx::RectF active_rect = main_frame->activeFindMatchRect();
4805 Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_,
4806 rects_version,
4807 match_rects,
4808 active_rect));
4809}
4810#endif
4811
[email protected]e9ff79c2012-10-19 21:31:264812void RenderViewImpl::OnZoom(PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:514813 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4814 return;
4815
[email protected]258d31122010-05-09 10:59:414816 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:104817
[email protected]b75b8292010-10-01 07:28:254818 double old_zoom_level = webview()->zoomLevel();
4819 double zoom_level;
[email protected]e9ff79c2012-10-19 21:31:264820 if (zoom == PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:254821 zoom_level = 0;
4822 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4823 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:484824 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:254825 } else {
4826 // Either the user hit the zoom factor limit and thus the zoom level is now
4827 // not a whole number, or a plugin changed it to a custom value. We want
4828 // to go to the next whole number so that the user can always get back to
4829 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:484830 if ((old_zoom_level > 1 && zoom > 0) ||
4831 (old_zoom_level < 1 && zoom < 0)) {
4832 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:254833 } else {
4834 // We're going towards 100%, so first go to the next whole number.
4835 zoom_level = static_cast<int>(old_zoom_level);
4836 }
4837 }
[email protected]91219702013-09-18 07:33:514838 webview()->setZoomLevel(zoom_level);
[email protected]47578fa02011-11-02 19:34:414839 zoomLevelChanged();
4840}
4841
[email protected]e9ff79c2012-10-19 21:31:264842void RenderViewImpl::OnZoomFactor(PageZoom zoom, int zoom_center_x,
4843 int zoom_center_y) {
[email protected]47578fa02011-11-02 19:34:414844 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
4845 kScalingIncrementForGesture);
4846}
4847
[email protected]e9ff79c2012-10-19 21:31:264848void RenderViewImpl::ZoomFactorHelper(PageZoom zoom,
[email protected]47578fa02011-11-02 19:34:414849 int zoom_center_x,
4850 int zoom_center_y,
4851 float scaling_increment) {
4852 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4853 return;
4854
[email protected]c514d6372011-08-16 22:54:444855 double old_page_scale_factor = webview()->pageScaleFactor();
4856 double page_scale_factor;
[email protected]e9ff79c2012-10-19 21:31:264857 if (zoom == PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:444858 page_scale_factor = 1.0;
4859 } else {
4860 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:414861 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:444862 }
[email protected]47578fa02011-11-02 19:34:414863 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:094864 webview()->setPageScaleFactor(page_scale_factor,
4865 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:414866 }
[email protected]40bd6582009-12-04 23:49:514867}
4868
[email protected]310ebd6302011-10-10 19:06:284869void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174870 webview()->hidePopups();
[email protected]91219702013-09-18 07:33:514871 webview()->setZoomLevel(zoom_level);
[email protected]d0b8d092010-10-25 04:05:174872 zoomLevelChanged();
4873}
4874
[email protected]310ebd6302011-10-10 19:06:284875void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4876 double zoom_level) {
[email protected]cbe55d22013-02-14 17:04:334877#if !defined(OS_ANDROID)
4878 // On Android, page zoom isn't used, and in case of WebView, text zoom is used
4879 // for legacy WebView text scaling emulation. Thus, the code that resets
4880 // the zoom level from this map will be effectively resetting text zoom level.
[email protected]9d797f32010-04-23 07:17:544881 host_zoom_levels_[url] = zoom_level;
[email protected]cbe55d22013-02-14 17:04:334882#endif
initial.commit09911bf2008-07-26 23:55:294883}
4884
[email protected]310ebd6302011-10-10 19:06:284885void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274886 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294887}
4888
[email protected]310ebd6302011-10-10 19:06:284889void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274890 WebString no_encoding;
4891 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184892}
4893
[email protected]310ebd6302011-10-10 19:06:284894WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454895 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274896 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454897
4898 // xpath string can represent a frame deep down the tree (across multiple
4899 // frame DOMs).
4900 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4901 // should break into 2 xpaths
4902 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:414903 std::vector<string16> xpaths;
4904 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:454905
[email protected]26aa0482009-09-30 16:55:274906 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:414907 for (std::vector<string16>::const_iterator i = xpaths.begin();
4908 frame && i != xpaths.end(); ++i) {
4909 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294910 }
4911
[email protected]dd7daa82009-08-10 05:46:454912 return frame;
initial.commit09911bf2008-07-26 23:55:294913}
4914
[email protected]310ebd6302011-10-10 19:06:284915void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4916 const string16& jscript,
4917 int id,
4918 bool notify_result) {
[email protected]c76faea2013-03-26 07:42:424919 TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest",
4920 TRACE_EVENT_SCOPE_THREAD);
[email protected]882b7b22010-10-05 03:34:534921 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294922}
4923
[email protected]f546640b2012-05-15 00:03:494924void RenderViewImpl::OnPostMessageEvent(
4925 const ViewMsg_PostMessage_Params& params) {
[email protected]bf4a2312013-04-23 00:32:114926 // TODO(nasko): Support sending to subframes.
[email protected]e12dbe6f2012-10-04 22:11:194927 WebFrame* frame = webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:494928
4929 // Find the source frame if it exists.
[email protected]f546640b2012-05-15 00:03:494930 WebFrame* source_frame = NULL;
4931 if (params.source_routing_id != MSG_ROUTING_NONE) {
4932 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
4933 if (source_view)
[email protected]e12dbe6f2012-10-04 22:11:194934 source_frame = source_view->webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:494935 }
4936
4937 // Create an event with the message. The final parameter to initMessageEvent
4938 // is the last event ID, which is not used with postMessage.
4939 WebDOMEvent event = frame->document().createEvent("MessageEvent");
4940 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
4941 msg_event.initMessageEvent("message",
4942 // |canBubble| and |cancellable| are always false
4943 false, false,
4944 WebSerializedScriptValue::fromString(params.data),
4945 params.source_origin, source_frame, "");
4946
4947 // We must pass in the target_origin to do the security check on this side,
4948 // since it may have changed since the original postMessage call was made.
4949 WebSecurityOrigin target_origin;
4950 if (!params.target_origin.empty()) {
4951 target_origin =
4952 WebSecurityOrigin::createFromString(WebString(params.target_origin));
4953 }
4954 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
4955}
4956
[email protected]310ebd6302011-10-10 19:06:284957void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
4958 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:414959 WebFrame* frame = GetChildFrame(frame_xpath);
4960 if (!frame)
[email protected]216813952011-05-19 22:21:264961 return;
[email protected]ae461542009-06-19 19:03:414962
[email protected]01cf589c2011-07-28 18:04:034963 frame->document().insertUserStyleSheet(
4964 WebString::fromUTF8(css),
4965 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:484966}
4967
[email protected]310ebd6302011-10-10 19:06:284968void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]940ed1d2012-11-27 21:03:214969 if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) &&
4970 !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) {
[email protected]91f05762013-08-21 02:55:094971 // WebUI uses <dialog> which is not yet enabled by default in Chrome.
4972 WebRuntimeFeatures::enableDialogElement(true);
4973
[email protected]dcc72db2013-01-02 00:44:184974 RenderThread::Get()->RegisterExtension(WebUIExtension::Get());
[email protected]940ed1d2012-11-27 21:03:214975 new WebUIExtensionData(this);
4976 }
4977
[email protected]81e63782009-02-27 19:35:094978 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:044979
4980 // Keep track of the total bindings accumulated in this process.
4981 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:294982}
4983
[email protected]dc293a72013-07-01 11:11:224984void RenderViewImpl::OnDragTargetDragEnter(const DropData& drop_data,
[email protected]310ebd6302011-10-10 19:06:284985 const gfx::Point& client_point,
4986 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:424987 WebDragOperationsMask ops,
4988 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:554989 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]dc293a72013-07-01 11:11:224990 DropDataToWebDragData(drop_data),
[email protected]59f4f2fa2011-03-23 01:00:554991 client_point,
4992 screen_point,
[email protected]1f2230b2012-05-17 23:43:424993 ops,
4994 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:554995
4996 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4997}
4998
[email protected]310ebd6302011-10-10 19:06:284999void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
5000 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:425001 WebDragOperationsMask ops,
5002 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:555003 WebDragOperation operation = webview()->dragTargetDragOver(
5004 client_point,
5005 screen_point,
[email protected]1f2230b2012-05-17 23:43:425006 ops,
5007 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555008
5009 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5010}
5011
[email protected]310ebd6302011-10-10 19:06:285012void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:555013 webview()->dragTargetDragLeave();
5014}
5015
[email protected]310ebd6302011-10-10 19:06:285016void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
[email protected]1f2230b2012-05-17 23:43:425017 const gfx::Point& screen_point,
5018 int key_modifiers) {
5019 webview()->dragTargetDrop(client_point, screen_point, key_modifiers);
[email protected]fcad49452011-06-28 17:11:575020
5021 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:555022}
5023
[email protected]310ebd6302011-10-10 19:06:285024void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
5025 const gfx::Point& screen_point,
5026 bool ended,
5027 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:035028 if (ended) {
[email protected]26aa0482009-09-30 16:55:275029 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:205030 } else {
5031 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:035032 }
initial.commit09911bf2008-07-26 23:55:295033}
5034
[email protected]310ebd6302011-10-10 19:06:285035void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:275036 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:295037}
5038
[email protected]310ebd6302011-10-10 19:06:285039void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:595040 webkit_preferences_ = prefs;
[email protected]49a20002013-08-18 12:43:315041 ApplyWebPreferences(webkit_preferences_, webview());
initial.commit09911bf2008-07-26 23:55:295042}
5043
[email protected]38761452012-10-18 16:31:595044void RenderViewImpl::OnUpdateTimezone() {
5045 if (webview())
5046 NotifyTimezoneChange(webview()->mainFrame());
5047}
5048
[email protected]310ebd6302011-10-10 19:06:285049void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:295050 alternate_error_page_url_ = url;
5051}
5052
[email protected]310ebd6302011-10-10 19:06:285053void RenderViewImpl::OnCustomContextMenuAction(
[email protected]e9ff79c2012-10-19 21:31:265054 const CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:085055 unsigned action) {
[email protected]860ee642012-10-13 03:46:255056 if (custom_context.request_id) {
5057 // External context menu request, look in our map.
[email protected]e9ff79c2012-10-19 21:31:265058 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:255059 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:465060 if (client)
5061 client->OnMenuAction(custom_context.request_id, action);
[email protected]860ee642012-10-13 03:46:255062 } else {
5063 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:085064 webview()->performCustomContextMenuAction(action);
[email protected]860ee642012-10-13 03:46:255065 }
[email protected]a0c7153e2009-12-09 14:36:335066}
5067
[email protected]310ebd6302011-10-10 19:06:285068void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:515069 int id,
[email protected]c42de732013-02-16 06:26:315070 const std::vector<base::FilePath>& paths) {
[email protected]600ea402011-04-12 00:01:515071 if (!enumeration_completions_[id])
5072 return;
5073
5074 WebVector<WebString> ws_file_names(paths.size());
5075 for (size_t i = 0; i < paths.size(); ++i)
[email protected]728c2ee2013-06-25 04:01:075076 ws_file_names[i] = paths[i].AsUTF16Unsafe();
[email protected]600ea402011-04-12 00:01:515077
5078 enumeration_completions_[id]->didChooseFile(ws_file_names);
5079 enumeration_completions_.erase(id);
5080}
5081
[email protected]fb11b6a42012-03-14 07:25:125082void RenderViewImpl::OnFileChooserResponse(
[email protected]ddb034b2012-06-26 20:31:395083 const std::vector<ui::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:365084 // This could happen if we navigated to a different page before the user
5085 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:475086 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:365087 return;
5088
[email protected]b5188522012-03-15 00:18:045089 // Convert Chrome's SelectedFileInfo list to WebKit's.
5090 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
5091 files.size());
5092 for (size_t i = 0; i < files.size(); ++i) {
5093 WebFileChooserCompletion::SelectedFileInfo selected_file;
[email protected]728c2ee2013-06-25 04:01:075094 selected_file.path = files[i].local_path.AsUTF16Unsafe();
5095 selected_file.displayName =
5096 base::FilePath(files[i].display_name).AsUTF16Unsafe();
[email protected]b5188522012-03-15 00:18:045097 selected_files[i] = selected_file;
5098 }
[email protected]a1128322009-10-06 18:38:465099
[email protected]cdaf8d02010-03-30 19:52:475100 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:045101 file_chooser_completions_.front()->completion->didChooseFile(
5102 selected_files);
[email protected]cdaf8d02010-03-30 19:52:475103 file_chooser_completions_.pop_front();
5104
5105 // If there are more pending file chooser requests, schedule one now.
5106 if (!file_chooser_completions_.empty()) {
5107 Send(new ViewHostMsg_RunFileChooser(routing_id_,
5108 file_chooser_completions_.front()->params));
5109 }
initial.commit09911bf2008-07-26 23:55:295110}
5111
[email protected]244ac1892011-12-02 17:04:475112void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
5113 const gfx::Size& max_size) {
5114 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5115 if (!webview())
5116 return;
[email protected]97e1bf72013-03-06 14:06:055117 auto_resize_mode_ = true;
[email protected]61e2b3cc2012-03-02 16:13:345118 webview()->enableAutoResizeMode(min_size, max_size);
5119}
5120
5121void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
5122 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5123 if (!webview())
5124 return;
[email protected]97e1bf72013-03-06 14:06:055125 auto_resize_mode_ = false;
[email protected]61e2b3cc2012-03-02 16:13:345126 webview()->disableAutoResizeMode();
5127
[email protected]eac2b362013-05-22 07:01:455128 if (!new_size.IsEmpty()) {
5129 Resize(new_size,
5130 physical_backing_size_,
5131 overdraw_bottom_height_,
5132 resizer_rect_,
5133 is_fullscreen_,
5134 NO_RESIZE_ACK);
5135 }
[email protected]244ac1892011-12-02 17:04:475136}
5137
[email protected]2bf834f2011-11-17 20:02:215138void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:245139 if (send_preferred_size_changes_)
5140 return;
[email protected]9fb325e2010-05-06 18:23:245141 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:395142
[email protected]d812fd12011-05-27 23:05:075143 // Start off with an initial preferred size notification (in case
5144 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:595145 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:085146}
5147
[email protected]310ebd6302011-10-10 19:06:285148void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:105149 const gfx::Size& disable_scrollbar_size_limit) {
5150 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
5151}
5152
[email protected]310ebd6302011-10-10 19:06:285153void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:265154 const RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:505155 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:515156 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:375157 UpdateFontRenderingFromRendererPrefs();
[email protected]38a85712013-01-02 22:45:025158
5159#if defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK)
[email protected]1596efb2013-01-17 22:13:015160 if (renderer_prefs.use_custom_colors) {
5161 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
5162 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
5163 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]38a85712013-01-02 22:45:025164#if defined(TOOLKIT_GTK)
[email protected]1596efb2013-01-17 22:13:015165 ui::NativeTheme::instance()->SetScrollbarColors(
[email protected]93623c5d2009-12-10 21:40:325166 renderer_prefs.thumb_inactive_color,
5167 renderer_prefs.thumb_active_color,
5168 renderer_prefs.track_color);
[email protected]38a85712013-01-02 22:45:025169#endif // defined(TOOLKIT_GTK)
[email protected]1596efb2013-01-17 22:13:015170
5171 if (webview()) {
5172#if defined(TOOLKIT_GTK)
5173 webview()->setScrollbarColors(
5174 renderer_prefs.thumb_inactive_color,
5175 renderer_prefs.thumb_active_color,
5176 renderer_prefs.track_color);
5177#endif // defined(TOOLKIT_GTK)
5178 webview()->setSelectionColors(
5179 renderer_prefs.active_selection_bg_color,
5180 renderer_prefs.active_selection_fg_color,
5181 renderer_prefs.inactive_selection_bg_color,
5182 renderer_prefs.inactive_selection_fg_color);
5183 webview()->themeChanged();
5184 }
[email protected]644d77e2010-01-27 01:03:105185 }
[email protected]38a85712013-01-02 22:45:025186#endif // defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK)
[email protected]d299d972012-03-23 02:26:555187
[email protected]107c0532013-02-06 02:34:095188 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
5189 RenderThreadImpl::current()->SetFlingCurveParameters(
5190 renderer_prefs.touchpad_fling_profile,
5191 renderer_prefs.touchscreen_fling_profile);
5192
[email protected]d051d9a2011-12-10 02:02:505193 // If the zoom level for this page matches the old zoom default, and this
5194 // is not a plugin, update the zoom level to match the new default.
5195 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
[email protected]cbe55d22013-02-14 17:04:335196 !ZoomValuesEqual(old_zoom_level,
5197 renderer_preferences_.default_zoom_level) &&
[email protected]e9ff79c2012-10-19 21:31:265198 ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
[email protected]91219702013-09-18 07:33:515199 webview()->setZoomLevel(renderer_preferences_.default_zoom_level);
[email protected]d051d9a2011-12-10 02:02:505200 zoomLevelChanged();
5201 }
[email protected]80d96fa2009-06-10 22:34:515202}
5203
[email protected]310ebd6302011-10-10 19:06:285204void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
5205 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:285206 if (webview())
5207 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:565208}
5209
[email protected]77829642012-05-15 14:47:175210void RenderViewImpl::OnOrientationChangeEvent(int orientation) {
[email protected]652ad832013-08-16 11:47:045211 FOR_EACH_OBSERVER(RenderViewObserver,
5212 observers_,
5213 OrientationChangeEvent(orientation));
[email protected]77829642012-05-15 14:47:175214 webview()->mainFrame()->sendOrientationChangeEvent(orientation);
5215}
5216
[email protected]81375e872012-01-11 21:40:365217void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
5218 const WebPluginAction& action) {
5219 if (webview())
5220 webview()->performPluginAction(action, location);
5221}
5222
[email protected]310ebd6302011-10-10 19:06:285223void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:195224 const GURL& page_url) {
5225 // Prepare list to storage all savable resource links.
5226 std::vector<GURL> resources_list;
[email protected]c2d986512012-05-12 00:22:465227 std::vector<GURL> referrer_urls_list;
5228 std::vector<WebKit::WebReferrerPolicy> referrer_policies_list;
[email protected]18d5be92011-07-25 18:00:195229 std::vector<GURL> frames_list;
[email protected]12a936d2013-05-15 04:55:495230 SavableResourcesResult result(&resources_list,
5231 &referrer_urls_list,
5232 &referrer_policies_list,
5233 &frames_list);
[email protected]18d5be92011-07-25 18:00:195234
[email protected]e9ff79c2012-10-19 21:31:265235 // webkit/ doesn't know about Referrer.
[email protected]12a936d2013-05-15 04:55:495236 if (!GetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:195237 webview(),
5238 page_url,
5239 &result,
[email protected]e9ff79c2012-10-19 21:31:265240 const_cast<const char**>(GetSavableSchemes()))) {
[email protected]18d5be92011-07-25 18:00:195241 // If something is wrong when collecting all savable resource links,
5242 // send empty list to embedder(browser) to tell it failed.
[email protected]c2d986512012-05-12 00:22:465243 referrer_urls_list.clear();
5244 referrer_policies_list.clear();
[email protected]18d5be92011-07-25 18:00:195245 resources_list.clear();
5246 frames_list.clear();
5247 }
5248
[email protected]e9ff79c2012-10-19 21:31:265249 std::vector<Referrer> referrers_list;
[email protected]c2d986512012-05-12 00:22:465250 CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size());
5251 for (unsigned i = 0; i < referrer_urls_list.size(); ++i) {
5252 referrers_list.push_back(
[email protected]e9ff79c2012-10-19 21:31:265253 Referrer(referrer_urls_list[i], referrer_policies_list[i]));
[email protected]c2d986512012-05-12 00:22:465254 }
5255
[email protected]18d5be92011-07-25 18:00:195256 // Send result of all savable resource links to embedder.
5257 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
5258 resources_list,
5259 referrers_list,
5260 frames_list));
5261}
5262
[email protected]310ebd6302011-10-10 19:06:285263void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:195264 const std::vector<GURL>& links,
[email protected]c42de732013-02-16 06:26:315265 const std::vector<base::FilePath>& local_paths,
5266 const base::FilePath& local_directory_name) {
[email protected]18d5be92011-07-25 18:00:195267
5268 // Convert std::vector of GURLs to WebVector<WebURL>
5269 WebVector<WebURL> weburl_links(links);
5270
[email protected]728c2ee2013-06-25 04:01:075271 // Convert std::vector of base::FilePath to WebVector<WebString>
[email protected]18d5be92011-07-25 18:00:195272 WebVector<WebString> webstring_paths(local_paths.size());
5273 for (size_t i = 0; i < local_paths.size(); i++)
[email protected]728c2ee2013-06-25 04:01:075274 webstring_paths[i] = local_paths[i].AsUTF16Unsafe();
[email protected]18d5be92011-07-25 18:00:195275
5276 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
5277 webstring_paths,
[email protected]728c2ee2013-06-25 04:01:075278 local_directory_name.AsUTF16Unsafe());
[email protected]18d5be92011-07-25 18:00:195279}
5280
[email protected]310ebd6302011-10-10 19:06:285281void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:125282 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:275283 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:125284 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
5285 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
5286 before_unload_start_time,
5287 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:295288}
5289
[email protected]e1986832013-06-14 07:27:285290void RenderViewImpl::OnSwapOut() {
[email protected]73eb2602012-02-09 19:50:555291 // Only run unload if we're not swapped out yet, but send the ack either way.
5292 if (!is_swapped_out_) {
5293 // Swap this RenderView out so the tab can navigate to a page rendered by a
5294 // different process. This involves running the unload handler and clearing
5295 // the page. Once WasSwappedOut is called, we also allow this process to
5296 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:155297
[email protected]73eb2602012-02-09 19:50:555298 // Send an UpdateState message before we get swapped out.
5299 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:155300
[email protected]73eb2602012-02-09 19:50:555301 // Synchronously run the unload handler before sending the ACK.
5302 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:155303
[email protected]73eb2602012-02-09 19:50:555304 // Swap out and stop sending any IPC messages that are not ACKs.
5305 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:155306
[email protected]6169a5772013-05-29 17:41:145307 // Now that we're swapped out and filtering IPC messages, stop loading to
5308 // ensure that no other in-progress navigation continues. We do this here
5309 // to avoid sending a DidStopLoading message to the browser process.
5310 OnStop();
5311
[email protected]285f4bb82012-04-17 15:57:285312 // Replace the page with a blank dummy URL. The unload handler will not be
[email protected]73eb2602012-02-09 19:50:555313 // run a second time, thanks to a check in FrameLoader::stopLoading.
5314 // TODO(creis): Need to add a better way to do this that avoids running the
[email protected]285f4bb82012-04-17 15:57:285315 // beforeunload handler. For now, we just run it a second time silently.
[email protected]0720b532012-08-28 19:23:375316 NavigateToSwappedOutURL(webview()->mainFrame());
[email protected]961541a92012-06-01 21:15:285317
5318 // Let WebKit know that this view is hidden so it can drop resources and
5319 // stop compositing.
5320 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false);
[email protected]73eb2602012-02-09 19:50:555321 }
[email protected]992db4c2011-05-12 15:37:155322
[email protected]e1986832013-06-14 07:27:285323 Send(new ViewHostMsg_SwapOut_ACK(routing_id_));
[email protected]992db4c2011-05-12 15:37:155324}
5325
[email protected]0720b532012-08-28 19:23:375326void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) {
[email protected]14392a52012-05-02 20:28:445327 // We use loadRequest instead of loadHTMLString because the former commits
5328 // synchronously. Otherwise a new navigation can interrupt the navigation
[email protected]e9ff79c2012-10-19 21:31:265329 // to kSwappedOutURL. If that happens to be to the page we had been
[email protected]14392a52012-05-02 20:28:445330 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]890b06ca2012-12-13 21:07:365331 CHECK(is_swapped_out_);
[email protected]e9ff79c2012-10-19 21:31:265332 GURL swappedOutURL(kSwappedOutURL);
[email protected]14392a52012-05-02 20:28:445333 WebURLRequest request(swappedOutURL);
[email protected]0720b532012-08-28 19:23:375334 frame->loadRequest(request);
[email protected]14392a52012-05-02 20:28:445335}
5336
[email protected]310ebd6302011-10-10 19:06:285337void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:375338 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:295339 // TODO(creis): We'd rather use webview()->Close() here, but that currently
5340 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
5341 // in the onunload handler from appearing. For now, we're bypassing that and
5342 // calling the FrameLoader's CloseURL method directly. This should be
5343 // revisited to avoid having two ways to close a page. Having a single way
5344 // to close that can run onunload is also useful for fixing
5345 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:275346 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:295347
[email protected]992db4c2011-05-12 15:37:155348 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:295349}
5350
[email protected]310ebd6302011-10-10 19:06:285351void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:025352#if defined(USE_AURA)
5353 // Aura doesn't care if we switch themes.
5354#elif defined(OS_WIN)
[email protected]f78452f2012-05-15 02:07:525355 ui::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:465356 if (webview())
5357 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:575358#else // defined(OS_WIN)
5359 // TODO(port): we don't support theming on non-Windows platforms yet
5360 NOTIMPLEMENTED();
5361#endif
initial.commit09911bf2008-07-26 23:55:295362}
5363
[email protected]310ebd6302011-10-10 19:06:285364bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
5365 const WebURLError& error,
5366 bool replace) {
[email protected]15d79e12009-08-02 19:23:455367 // We only show alternate error pages in the main frame. They are
5368 // intended to assist the user when navigating, so there is not much
5369 // value in showing them for failed subframes. Ideally, we would be
5370 // able to use the TYPED transition type for this, but that flag is
5371 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455372 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455373 return false;
5374
5375 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375376 // connection failure.
[email protected]15d79e12009-08-02 19:23:455377 int ec = error.reason;
5378 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5379 ec != net::ERR_CONNECTION_FAILED &&
5380 ec != net::ERR_CONNECTION_REFUSED &&
5381 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]82114f52012-03-20 22:53:415382 ec != net::ERR_CONNECTION_TIMED_OUT) {
[email protected]15d79e12009-08-02 19:23:455383 return false;
[email protected]82114f52012-03-20 22:53:415384 }
[email protected]15d79e12009-08-02 19:23:455385
5386 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555387 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455388 if (!error_page_url.is_valid())
5389 return false;
5390
[email protected]11a65772013-04-27 00:36:425391 WebDataSource* ds = frame->provisionalDataSource();
5392 const WebURLRequest& failed_request = ds->request();
5393
[email protected]15d79e12009-08-02 19:23:455394 // Load an empty page first so there is an immediate response to the error,
5395 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455396 frame->loadHTMLString(std::string(),
[email protected]e9ff79c2012-10-19 21:31:265397 GURL(kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455398 error.unreachableURL,
5399 replace);
5400
5401 // Now, create a fetcher for the error page and associate it with the data
5402 // source we just created via the LoadHTMLString call. That way if another
5403 // navigation occurs, the fetcher will get destroyed.
[email protected]e20b88d2013-04-09 15:28:375404 InternalDocumentStateData* internal_data =
5405 InternalDocumentStateData::FromDataSource(frame->provisionalDataSource());
5406 internal_data->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:455407 new AltErrorPageResourceFetcher(
[email protected]11a65772013-04-27 00:36:425408 error_page_url, frame, failed_request, error,
[email protected]6e806822011-11-19 01:51:085409 base::Bind(&RenderViewImpl::AltErrorPageFinished,
5410 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:455411 return true;
5412}
5413
[email protected]310ebd6302011-10-10 19:06:285414void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
[email protected]11a65772013-04-27 00:36:425415 const WebURLRequest& original_request,
[email protected]310ebd6302011-10-10 19:06:285416 const WebURLError& original_error,
5417 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:455418 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:095419 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:555420 // will simply display a default error page.
[email protected]11a65772013-04-27 00:36:425421 LoadNavigationErrorPage(frame, original_request, original_error, html, true);
[email protected]15d79e12009-08-02 19:23:455422}
5423
[email protected]310ebd6302011-10-10 19:06:285424void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:005425 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475426 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005427}
5428
[email protected]0fdd5012013-05-29 08:05:565429void RenderViewImpl::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]cda45c02010-02-25 19:28:105430 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475431 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105432 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205433 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]0fdd5012013-05-29 08:05:565434 ShouldDisplayScrollbars(params.new_size.width(),
5435 params.new_size.height()));
[email protected]cda45c02010-02-25 19:28:105436 }
[email protected]dd6afca2011-08-13 03:44:315437 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:105438 }
5439
[email protected]0fdd5012013-05-29 08:05:565440 RenderWidget::OnResize(params);
[email protected]30f75e62009-02-25 22:01:005441}
[email protected]0aa477bd2009-03-23 22:21:435442
[email protected]29ed96a2012-02-04 18:12:165443void RenderViewImpl::WillInitiatePaint() {
[email protected]ea2fb972013-08-07 05:44:265444#if defined(ENABLE_PLUGINS)
5445 // Notify all of our instances that we started painting. This is used for
5446 // internal bookkeeping only, so we know that the set can not change under
5447 // us.
5448 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
5449 i != active_pepper_instances_.end(); ++i)
5450 (*i)->ViewWillInitiatePaint();
5451#endif
[email protected]29ed96a2012-02-04 18:12:165452}
5453
[email protected]310ebd6302011-10-10 19:06:285454void RenderViewImpl::DidInitiatePaint() {
[email protected]ea2fb972013-08-07 05:44:265455#if defined(ENABLE_PLUGINS)
5456 // Notify all instances that we painted. The same caveats apply as for
5457 // ViewFlushedPaint regarding instances closing themselves, so we take
5458 // similar precautions.
5459 PepperPluginSet plugins = active_pepper_instances_;
5460 for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) {
5461 if (active_pepper_instances_.find(*i) != active_pepper_instances_.end())
5462 (*i)->ViewInitiatedPaint();
5463 }
5464#endif
[email protected]00c39612010-03-06 02:53:285465}
5466
[email protected]310ebd6302011-10-10 19:06:285467void RenderViewImpl::DidFlushPaint() {
[email protected]ea2fb972013-08-07 05:44:265468#if defined(ENABLE_PLUGINS)
5469 // Notify all instances that we flushed. This will call into the plugin, and
5470 // we it may ask to close itself as a result. This will, in turn, modify our
5471 // set, possibly invalidating the iterator. So we iterate on a copy that
[email protected]00c39612010-03-06 02:53:285472 // won't change out from under us.
[email protected]ea2fb972013-08-07 05:44:265473 PepperPluginSet plugins = active_pepper_instances_;
5474 for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) {
5475 // The copy above makes sure our iterator is never invalid if some plugins
5476 // are destroyed. But some plugin may decide to close all of its views in
5477 // response to a paint in one of them, so we need to make sure each one is
5478 // still "current" before using it.
5479 //
5480 // It's possible that a plugin was destroyed, but another one was created
5481 // with the same address. In this case, we'll call ViewFlushedPaint on that
5482 // new plugin. But that's OK for this particular case since we're just
5483 // notifying all of our instances that the view flushed, and the new one is
5484 // one of our instances.
5485 //
5486 // What about the case where a new one is created in a callback at a new
5487 // address and we don't issue the callback? We're still OK since this
5488 // callback is used for flush callbacks and we could not have possibly
5489 // started a new paint (ViewWillInitiatePaint) for the new plugin while
5490 // processing a previous paint for an existing one.
5491 if (active_pepper_instances_.find(*i) != active_pepper_instances_.end())
5492 (*i)->ViewFlushedPaint();
5493 }
5494#endif
[email protected]53900d52010-06-16 04:25:015495
[email protected]5b1dec8c2012-02-07 04:35:385496 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
5497 // See crbug.com/112921.
5498 if (!webview())
5499 return;
5500
[email protected]00c39612010-03-06 02:53:285501 WebFrame* main_frame = webview()->mainFrame();
5502
5503 // If we have a provisional frame we are between the start and commit stages
5504 // of loading and we don't want to save stats.
5505 if (!main_frame->provisionalDataSource()) {
5506 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:075507 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]92d457802013-04-01 19:18:495508 InternalDocumentStateData* data =
[email protected]e20b88d2013-04-09 15:28:375509 InternalDocumentStateData::FromDocumentState(document_state);
[email protected]92d457802013-04-01 19:18:495510 if (data->did_first_visually_non_empty_layout() &&
5511 !data->did_first_visually_non_empty_paint()) {
5512 data->set_did_first_visually_non_empty_paint(true);
5513 Send(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_,
5514 page_id_));
5515 }
5516
[email protected]05c8e502010-08-15 15:13:525517 // TODO(jar): The following code should all be inside a method, probably in
5518 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285519 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:075520 if (document_state->first_paint_time().is_null()) {
5521 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:285522 }
[email protected]007733c2011-11-17 00:34:075523 if (document_state->first_paint_after_load_time().is_null() &&
5524 !document_state->finish_load_time().is_null()) {
5525 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:285526 }
5527 }
5528}
5529
[email protected]adab2332013-07-25 18:04:325530PepperPluginInstanceImpl* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
5531 const gfx::Rect& paint_bounds,
5532 TransportDIB** dib,
5533 gfx::Rect* location,
5534 gfx::Rect* clip,
5535 float* scale_factor) {
[email protected]ea2fb972013-08-07 05:44:265536#if defined(ENABLE_PLUGINS)
5537 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
5538 i != active_pepper_instances_.end(); ++i) {
5539 PepperPluginInstanceImpl* instance = *i;
5540 // In Flash fullscreen , the plugin contents should be painted onto the
5541 // fullscreen widget instead of the web page.
5542 if (!instance->FlashIsFullscreenOrPending() &&
5543 instance->GetBitmapForOptimizedPluginPaint(paint_bounds, dib, location,
5544 clip, scale_factor))
5545 return *i;
5546 }
5547#endif
5548 return NULL;
[email protected]ca4847f2010-09-24 05:39:155549}
5550
[email protected]ceb36f7d2012-10-31 18:33:245551gfx::Vector2d RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:075552 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]ceb36f7d2012-10-31 18:33:245553 return gfx::Vector2d(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:525554}
5555
[email protected]310ebd6302011-10-10 19:06:285556void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:165557 if (webview())
[email protected]26aa0482009-09-30 16:55:275558 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165559}
5560
[email protected]310ebd6302011-10-10 19:06:285561void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:145562 if (webview())
[email protected]b4bb2502009-10-01 22:35:275563 webview()->setIsTransparent(!background.empty());
[email protected]ba91a792013-02-06 09:48:285564 if (compositor_)
5565 compositor_->setHasTransparentBackground(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145566
5567 SetBackground(background);
5568}
5569
[email protected]2a84f9d2012-06-05 21:50:435570void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) {
5571 if (accessibility_mode_ == new_mode)
5572 return;
5573 accessibility_mode_ = new_mode;
5574 if (renderer_accessibility_) {
5575 delete renderer_accessibility_;
5576 renderer_accessibility_ = NULL;
5577 }
5578 if (accessibility_mode_ == AccessibilityModeComplete)
5579 renderer_accessibility_ = new RendererAccessibilityComplete(this);
[email protected]8d3dfee62013-06-19 05:50:335580#if !defined(OS_ANDROID)
[email protected]2a84f9d2012-06-05 21:50:435581 else if (accessibility_mode_ == AccessibilityModeEditableTextOnly)
5582 renderer_accessibility_ = new RendererAccessibilityFocusOnly(this);
[email protected]8d3dfee62013-06-19 05:50:335583#endif
[email protected]2a84f9d2012-06-05 21:50:435584}
5585
[email protected]310ebd6302011-10-10 19:06:285586void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:345587 if (webview())
[email protected]b4bb2502009-10-01 22:35:275588 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265589
[email protected]a80af12e2013-08-07 23:36:135590#if defined(ENABLE_PLUGINS) && defined(OS_MACOSX)
[email protected]d8fd6fa2010-02-01 15:54:265591 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5592 for (plugin_it = plugin_delegates_.begin();
5593 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5594 (*plugin_it)->SetWindowFocus(active);
5595 }
5596#endif
[email protected]8c66c5a2009-07-22 17:26:345597}
5598
[email protected]6ce7abc52010-02-02 18:40:145599#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285600void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]a80af12e2013-08-07 23:36:135601#if defined(ENABLE_PLUGINS)
[email protected]6ce7abc52010-02-02 18:40:145602 // Inform plugins that their container has changed visibility.
5603 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5604 for (plugin_it = plugin_delegates_.begin();
5605 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5606 (*plugin_it)->SetContainerVisibility(visible);
5607 }
[email protected]a80af12e2013-08-07 23:36:135608#endif
[email protected]6ce7abc52010-02-02 18:40:145609}
[email protected]1e6e3c992010-02-08 15:52:135610
[email protected]310ebd6302011-10-10 19:06:285611void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
5612 const gfx::Rect& view_frame) {
[email protected]a80af12e2013-08-07 23:36:135613#if defined(ENABLE_PLUGINS)
[email protected]1e6e3c992010-02-08 15:52:135614 // Inform plugins that their window's frame has changed.
5615 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5616 for (plugin_it = plugin_delegates_.begin();
5617 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5618 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5619 }
[email protected]a80af12e2013-08-07 23:36:135620#endif
[email protected]1e6e3c992010-02-08 15:52:135621}
[email protected]935d63d2010-10-15 23:31:555622
[email protected]310ebd6302011-10-10 19:06:285623void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
5624 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135625 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555626 // applies to it or not, so inform all the delegates.
5627 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5628 for (plugin_it = plugin_delegates_.begin();
5629 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135630 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555631 }
5632}
[email protected]6ce7abc52010-02-02 18:40:145633#endif // OS_MACOSX
5634
[email protected]310ebd6302011-10-10 19:06:285635void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:595636 // We need to grab a pointer to the doomed WebView before we destroy it.
5637 WebView* doomed = webview();
5638 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495639 g_view_map.Get().erase(doomed);
[email protected]058561b2012-12-03 06:48:225640 g_routing_id_view_map.Get().erase(routing_id_);
[email protected]60c42a8c72009-10-09 04:08:595641}
5642
[email protected]310ebd6302011-10-10 19:06:285643void RenderViewImpl::DidHandleKeyEvent() {
[email protected]b2324b092012-11-01 10:34:115644 ClearEditCommands();
[email protected]446705872009-09-10 07:22:485645}
5646
[email protected]310ebd6302011-10-10 19:06:285647bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]a14ddcd2013-06-21 22:53:035648 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]41d86852012-11-07 12:23:245649 possible_drag_event_info_.event_source =
5650 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
5651 possible_drag_event_info_.event_location =
5652 gfx::Point(event.globalX, event.globalY);
[email protected]ea2fb972013-08-07 05:44:265653
5654#if defined(ENABLE_PLUGINS)
5655 // This method is called for every mouse event that the render view receives.
5656 // And then the mouse event is forwarded to WebKit, which dispatches it to the
5657 // event target. Potentially a Pepper plugin will receive the event.
5658 // In order to tell whether a plugin gets the last mouse event and which it
5659 // is, we set |pepper_last_mouse_event_target_| to NULL here. If a plugin gets
5660 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
5661 // |pepper_last_mouse_event_target_|.
5662 pepper_last_mouse_event_target_ = NULL;
5663#endif
[email protected]217690d2012-01-27 07:33:115664
5665 // If the mouse is locked, only the current owner of the mouse lock can
5666 // process mouse events.
5667 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:375668}
5669
[email protected]f56c7872013-06-18 12:31:575670bool RenderViewImpl::WillHandleKeyEvent(const WebKit::WebKeyboardEvent& event) {
[email protected]a14ddcd2013-06-21 22:53:035671 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]f56c7872013-06-18 12:31:575672 return false;
5673}
5674
[email protected]41d86852012-11-07 12:23:245675bool RenderViewImpl::WillHandleGestureEvent(
5676 const WebKit::WebGestureEvent& event) {
[email protected]a14ddcd2013-06-21 22:53:035677 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:245678 possible_drag_event_info_.event_source =
5679 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
5680 possible_drag_event_info_.event_location =
5681 gfx::Point(event.globalX, event.globalY);
5682 return false;
5683}
5684
[email protected]2b942c332012-04-25 16:26:265685void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515686 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065687}
5688
[email protected]310ebd6302011-10-10 19:06:285689void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:245690 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
5691}
5692
[email protected]3d5c243b2012-11-30 00:26:015693bool RenderViewImpl::HasTouchEventHandlersAt(const gfx::Point& point) const {
5694 if (!webview())
5695 return false;
5696 return webview()->hasTouchEventHandlersAt(point);
5697}
5698
[email protected]310ebd6302011-10-10 19:06:285699void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:435700 RenderWidget::OnWasHidden();
5701
[email protected]2d7b82c2012-06-01 05:57:505702#if defined(OS_ANDROID)
[email protected]bc427442013-07-13 02:53:085703 // Inform RendererMediaPlayerManager to release all media player resources.
[email protected]1c36bea2013-07-01 13:43:015704 // unless some audio is playing.
[email protected]263135d2012-11-15 13:01:565705 // If something is in progress the resource will not be freed, it will
5706 // only be freed once the tab is destroyed or if the user navigates away
5707 // via WebMediaPlayerAndroid::Destroy
[email protected]1c36bea2013-07-01 13:43:015708 media_player_manager_->ReleaseMediaResources();
[email protected]6392d982013-04-16 16:59:225709
5710#if defined(ENABLE_WEBRTC)
5711 RenderThreadImpl::current()->video_capture_impl_manager()->
5712 SuspendDevices(true);
5713#endif
[email protected]2d7b82c2012-06-01 05:57:505714#endif
5715
[email protected]8869d392013-05-07 15:34:265716 if (webview())
[email protected]f59203a2011-06-07 10:01:445717 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075718
[email protected]ea2fb972013-08-07 05:44:265719#if defined(ENABLE_PLUGINS)
[email protected]204f1df2012-01-04 20:21:135720 // Inform PPAPI plugins that their page is no longer visible.
[email protected]ea2fb972013-08-07 05:44:265721 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
5722 i != active_pepper_instances_.end(); ++i)
5723 (*i)->PageVisibilityChanged(false);
[email protected]204f1df2012-01-04 20:21:135724
[email protected]a6939ca42011-02-18 17:58:075725#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135726 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:435727 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5728 for (plugin_it = plugin_delegates_.begin();
5729 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5730 (*plugin_it)->SetContainerVisibility(false);
5731 }
[email protected]a6939ca42011-02-18 17:58:075732#endif // OS_MACOSX
[email protected]a80af12e2013-08-07 23:36:135733#endif // ENABLE_PLUGINS
[email protected]941e4552010-02-01 21:23:435734}
5735
[email protected]9e2e4632012-07-27 16:38:415736void RenderViewImpl::OnWasShown(bool needs_repainting) {
5737 RenderWidget::OnWasShown(needs_repainting);
[email protected]941e4552010-02-01 21:23:435738
[email protected]6392d982013-04-16 16:59:225739#if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
5740 RenderThreadImpl::current()->video_capture_impl_manager()->
5741 SuspendDevices(false);
5742#endif
5743
[email protected]8869d392013-05-07 15:34:265744 if (webview())
[email protected]f59203a2011-06-07 10:01:445745 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075746
[email protected]ea2fb972013-08-07 05:44:265747#if defined(ENABLE_PLUGINS)
[email protected]204f1df2012-01-04 20:21:135748 // Inform PPAPI plugins that their page is visible.
[email protected]ea2fb972013-08-07 05:44:265749 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
5750 i != active_pepper_instances_.end(); ++i)
5751 (*i)->PageVisibilityChanged(true);
[email protected]204f1df2012-01-04 20:21:135752
[email protected]a6939ca42011-02-18 17:58:075753#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135754 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:435755 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5756 for (plugin_it = plugin_delegates_.begin();
5757 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5758 (*plugin_it)->SetContainerVisibility(true);
5759 }
[email protected]784ea1ab2010-09-18 00:02:345760#endif // OS_MACOSX
[email protected]a80af12e2013-08-07 23:36:135761#endif // ENABLE_PLUGINS
[email protected]a6939ca42011-02-18 17:58:075762}
[email protected]1e6e3c992010-02-08 15:52:135763
[email protected]ed7defa2013-03-12 21:29:595764GURL RenderViewImpl::GetURLForGraphicsContext3D() {
5765 DCHECK(webview());
5766 if (webview()->mainFrame())
5767 return GURL(webview()->mainFrame()->document().url());
5768 else
5769 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]65225772011-05-12 21:10:245770}
5771
[email protected]479b0172012-10-29 19:27:095772bool RenderViewImpl::ForceCompositingModeEnabled() {
5773 return webkit_preferences_.force_compositing_mode;
5774}
5775
[email protected]310ebd6302011-10-10 19:06:285776void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:135777 RenderWidget::OnSetFocus(enable);
5778
[email protected]a80af12e2013-08-07 23:36:135779#if defined(ENABLE_PLUGINS)
[email protected]7d3c02c2010-05-05 23:10:315780 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075781 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135782 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5783 for (plugin_it = plugin_delegates_.begin();
5784 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345785#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315786 // RenderWidget's call to setFocus can cause the underlying webview's
5787 // activation state to change just like a call to setIsActive.
5788 if (enable)
5789 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345790#endif
[email protected]7d3c02c2010-05-05 23:10:315791 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135792 }
5793 }
[email protected]a01da5682012-06-30 00:37:315794 // Notify all Pepper plugins.
[email protected]ea2fb972013-08-07 05:44:265795 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
5796 i != active_pepper_instances_.end(); ++i)
5797 (*i)->SetContentAreaFocus(enable);
5798#endif
[email protected]321032992012-11-08 01:01:275799 // Notify all BrowserPlugins of the RenderView's focus state.
[email protected]fc72bb12013-06-02 21:13:465800 if (browser_plugin_manager_.get())
[email protected]caaf2482013-05-01 20:33:325801 browser_plugin_manager_->UpdateFocusState();
[email protected]1e6e3c992010-02-08 15:52:135802}
[email protected]941e4552010-02-01 21:23:435803
[email protected]310ebd6302011-10-10 19:06:285804void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:575805 const string16& text,
5806 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5807 int selection_start,
5808 int selection_end) {
[email protected]ea2fb972013-08-07 05:44:265809#if defined(ENABLE_PLUGINS)
5810 if (focused_pepper_plugin_) {
[email protected]73bf95812011-10-12 11:38:325811 // When a PPAPI plugin has focus, we bypass WebKit.
[email protected]ea2fb972013-08-07 05:44:265812 if (!IsPepperAcceptingCompositionEvents()) {
5813 pepper_composition_text_ = text;
5814 } else {
5815 // TODO(kinaba) currently all composition events are sent directly to
5816 // plugins. Use DOM event mechanism after WebKit is made aware about
5817 // plugins that support composition.
5818 // The code below mimics the behavior of WebCore::Editor::setComposition.
5819
5820 // Empty -> nonempty: composition started.
5821 if (pepper_composition_text_.empty() && !text.empty())
5822 focused_pepper_plugin_->HandleCompositionStart(string16());
5823 // Nonempty -> empty: composition canceled.
5824 if (!pepper_composition_text_.empty() && text.empty())
5825 focused_pepper_plugin_->HandleCompositionEnd(string16());
5826 pepper_composition_text_ = text;
5827 // Nonempty: composition is ongoing.
5828 if (!pepper_composition_text_.empty()) {
5829 focused_pepper_plugin_->HandleCompositionUpdate(
5830 pepper_composition_text_, underlines, selection_start,
5831 selection_end);
[email protected]e6ae0f6c2011-10-04 10:39:235832 }
[email protected]e6ae0f6c2011-10-04 10:39:235833 }
[email protected]ea2fb972013-08-07 05:44:265834 return;
[email protected]56ea1a62011-05-30 07:05:575835 }
[email protected]ea2fb972013-08-07 05:44:265836
5837#if defined(OS_WIN)
5838 // When a plug-in has focus, we create platform-specific IME data used by
5839 // our IME emulator and send it directly to the focused plug-in, i.e. we
5840 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
5841 // instance ID is the same one as the specified ID.)
5842 if (focused_plugin_id_ >= 0) {
5843 std::vector<int> clauses;
5844 std::vector<int> target;
5845 for (size_t i = 0; i < underlines.size(); ++i) {
5846 clauses.push_back(underlines[i].startOffset);
5847 clauses.push_back(underlines[i].endOffset);
5848 if (underlines[i].thick) {
5849 target.clear();
5850 target.push_back(underlines[i].startOffset);
5851 target.push_back(underlines[i].endOffset);
5852 }
5853 }
5854 std::set<WebPluginDelegateProxy*>::iterator it;
5855 for (it = plugin_delegates_.begin(); it != plugin_delegates_.end(); ++it) {
5856 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
5857 focused_plugin_id_);
5858 }
5859 return;
5860 }
[email protected]a80af12e2013-08-07 23:36:135861#endif // OS_WIN
5862#endif // ENABLE_PLUGINS
[email protected]ea2fb972013-08-07 05:44:265863 RenderWidget::OnImeSetComposition(text,
5864 underlines,
5865 selection_start,
5866 selection_end);
[email protected]56ea1a62011-05-30 07:05:575867}
5868
[email protected]db4fc1e2013-09-06 20:01:515869void RenderViewImpl::OnImeConfirmComposition(
5870 const string16& text,
5871 const gfx::Range& replacement_range,
5872 bool keep_selection) {
[email protected]ea2fb972013-08-07 05:44:265873#if defined(ENABLE_PLUGINS)
5874 if (focused_pepper_plugin_) {
[email protected]73bf95812011-10-12 11:38:325875 // When a PPAPI plugin has focus, we bypass WebKit.
[email protected]ea2fb972013-08-07 05:44:265876 // Here, text.empty() has a special meaning. It means to commit the last
5877 // update of composition text (see
5878 // RenderWidgetHost::ImeConfirmComposition()).
5879 const string16& last_text = text.empty() ? pepper_composition_text_ : text;
5880
5881 // last_text is empty only when both text and pepper_composition_text_ is.
5882 // Ignore it.
5883 if (last_text.empty())
[email protected]e6ae0f6c2011-10-04 10:39:235884 return;
[email protected]ea2fb972013-08-07 05:44:265885
5886 if (!IsPepperAcceptingCompositionEvents()) {
[email protected]28fccb32013-08-29 22:25:465887 base::i18n::UTF16CharIterator iterator(&last_text);
5888 int32 i = 0;
5889 while (iterator.Advance()) {
[email protected]ea2fb972013-08-07 05:44:265890 WebKit::WebKeyboardEvent char_event;
5891 char_event.type = WebKit::WebInputEvent::Char;
5892 char_event.timeStampSeconds = base::Time::Now().ToDoubleT();
5893 char_event.modifiers = 0;
5894 char_event.windowsKeyCode = last_text[i];
5895 char_event.nativeKeyCode = last_text[i];
[email protected]28fccb32013-08-29 22:25:465896
5897 const int32 char_start = i;
5898 for (; i < iterator.array_pos(); ++i) {
5899 char_event.text[i - char_start] = last_text[i];
5900 char_event.unmodifiedText[i - char_start] = last_text[i];
5901 }
5902
[email protected]ea2fb972013-08-07 05:44:265903 if (webwidget())
5904 webwidget()->handleInputEvent(char_event);
[email protected]ebd28ac2011-10-13 18:49:055905 }
[email protected]ea2fb972013-08-07 05:44:265906 } else {
5907 // Mimics the order of events sent by WebKit.
5908 // See WebCore::Editor::setComposition() for the corresponding code.
5909 focused_pepper_plugin_->HandleCompositionEnd(last_text);
5910 focused_pepper_plugin_->HandleTextInput(last_text);
[email protected]ebd28ac2011-10-13 18:49:055911 }
[email protected]ea2fb972013-08-07 05:44:265912 pepper_composition_text_.clear();
5913 return;
[email protected]56ea1a62011-05-30 07:05:575914 }
[email protected]ea2fb972013-08-07 05:44:265915#if defined(OS_WIN)
5916 // Same as OnImeSetComposition(), we send the text from IMEs directly to
5917 // plug-ins. When we send IME text directly to plug-ins, we should not send
5918 // it to WebKit to prevent WebKit from controlling IMEs.
5919 // TODO(thakis): Honor |replacement_range| for plugins?
5920 if (focused_plugin_id_ >= 0) {
5921 std::set<WebPluginDelegateProxy*>::iterator it;
5922 for (it = plugin_delegates_.begin();
5923 it != plugin_delegates_.end(); ++it) {
5924 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
5925 }
5926 return;
5927 }
[email protected]a80af12e2013-08-07 23:36:135928#endif // OS_WIN
5929#endif // ENABLE_PLUGINS
[email protected]ea2fb972013-08-07 05:44:265930 if (replacement_range.IsValid() && webview()) {
5931 // Select the text in |replacement_range|, it will then be replaced by
5932 // text added by the call to RenderWidget::OnImeConfirmComposition().
5933 if (WebFrame* frame = webview()->focusedFrame()) {
5934 WebRange webrange = WebRange::fromDocumentRange(
5935 frame, replacement_range.start(), replacement_range.length());
5936 if (!webrange.isNull())
5937 frame->selectRange(webrange);
5938 }
5939 }
5940 RenderWidget::OnImeConfirmComposition(text,
5941 replacement_range,
5942 keep_selection);
[email protected]56ea1a62011-05-30 07:05:575943}
5944
[email protected]468ac582012-11-20 00:53:195945void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor) {
5946 RenderWidget::SetDeviceScaleFactor(device_scale_factor);
[email protected]fb854192013-02-06 01:30:045947 if (webview()) {
[email protected]dea5e7682012-06-14 05:21:245948 webview()->setDeviceScaleFactor(device_scale_factor);
[email protected]fb854192013-02-06 01:30:045949 webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled(
5950 ShouldUseFixedPositionCompositing(device_scale_factor_));
[email protected]c162ced82013-06-29 01:24:535951 webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled(
5952 ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_));
[email protected]d8221b22013-05-23 05:35:435953 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
5954 ShouldUseTransitionCompositing(device_scale_factor_));
[email protected]06fc4d3b2013-07-08 21:07:245955 webview()->settings()->
5956 setAcceleratedCompositingForFixedRootBackgroundEnabled(
5957 ShouldUseAcceleratedFixedRootBackground(device_scale_factor_));
[email protected]fb854192013-02-06 01:30:045958 }
[email protected]3a1c8a8032013-03-18 22:35:325959 if (auto_resize_mode_)
5960 AutoResizeCompositor();
[email protected]caaf2482013-05-01 20:33:325961
[email protected]fc72bb12013-06-02 21:13:465962 if (browser_plugin_manager_.get())
[email protected]caaf2482013-05-01 20:33:325963 browser_plugin_manager_->UpdateDeviceScaleFactor(device_scale_factor_);
[email protected]dea5e7682012-06-14 05:21:245964}
5965
[email protected]310ebd6302011-10-10 19:06:285966ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]ea2fb972013-08-07 05:44:265967#if defined(ENABLE_PLUGINS)
5968 if (focused_pepper_plugin_)
5969 return focused_pepper_plugin_->text_input_type();
5970#endif
5971 return RenderWidget::GetTextInputType();
[email protected]73bf95812011-10-12 11:38:325972}
5973
[email protected]3f783362011-10-21 22:40:505974void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
[email protected]ea2fb972013-08-07 05:44:265975#if defined(ENABLE_PLUGINS)
5976 if (focused_pepper_plugin_) {
[email protected]3f783362011-10-21 22:40:505977 // TODO(kinaba) http://crbug.com/101101
5978 // Current Pepper IME API does not handle selection bounds. So we simply
5979 // use the caret position as an empty range for now. It will be updated
5980 // after Pepper API equips features related to surrounding text retrieval.
[email protected]ea2fb972013-08-07 05:44:265981 gfx::Rect caret = focused_pepper_plugin_->GetCaretBounds();
[email protected]3f783362011-10-21 22:40:505982 *start = caret;
5983 *end = caret;
5984 return;
5985 }
[email protected]ea2fb972013-08-07 05:44:265986#endif
[email protected]3f783362011-10-21 22:40:505987 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:455988}
5989
[email protected]501ea13d2013-07-09 17:03:295990#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
[email protected]58b48a0d2012-06-13 07:01:355991void RenderViewImpl::GetCompositionCharacterBounds(
5992 std::vector<gfx::Rect>* bounds) {
5993 DCHECK(bounds);
5994 bounds->clear();
5995
[email protected]ea2fb972013-08-07 05:44:265996#if defined(ENABLE_PLUGINS)
5997 if (focused_pepper_plugin_) {
[email protected]88dbe32f2013-06-20 23:31:365998 return;
5999 }
[email protected]ea2fb972013-08-07 05:44:266000#endif
6001
[email protected]58b48a0d2012-06-13 07:01:356002 if (!webview())
6003 return;
6004 size_t start_offset = 0;
6005 size_t character_count = 0;
6006 if (!webview()->compositionRange(&start_offset, &character_count))
6007 return;
6008 if (character_count == 0)
6009 return;
6010
6011 WebKit::WebFrame* frame = webview()->focusedFrame();
6012 if (!frame)
6013 return;
6014
6015 bounds->reserve(character_count);
6016 WebKit::WebRect webrect;
6017 for (size_t i = 0; i < character_count; ++i) {
6018 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
6019 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
6020 bounds->clear();
6021 return;
6022 }
6023 bounds->push_back(webrect);
6024 }
6025}
6026
[email protected]db4fc1e2013-09-06 20:01:516027void RenderViewImpl::GetCompositionRange(gfx::Range* range) {
[email protected]ea2fb972013-08-07 05:44:266028#if defined(ENABLE_PLUGINS)
6029 if (focused_pepper_plugin_) {
[email protected]88dbe32f2013-06-20 23:31:366030 return;
6031 }
[email protected]ea2fb972013-08-07 05:44:266032#endif
[email protected]88dbe32f2013-06-20 23:31:366033 RenderWidget::GetCompositionRange(range);
6034}
[email protected]501ea13d2013-07-09 17:03:296035#endif
[email protected]88dbe32f2013-06-20 23:31:366036
[email protected]310ebd6302011-10-10 19:06:286037bool RenderViewImpl::CanComposeInline() {
[email protected]ea2fb972013-08-07 05:44:266038#if defined(ENABLE_PLUGINS)
6039 if (focused_pepper_plugin_)
6040 return IsPepperAcceptingCompositionEvents();
6041#endif
6042 return true;
[email protected]56ea1a62011-05-30 07:05:576043}
6044
[email protected]35134e12013-02-22 20:07:406045void RenderViewImpl::InstrumentWillBeginFrame() {
6046 if (!webview())
6047 return;
6048 if (!webview()->devToolsAgent())
6049 return;
6050 webview()->devToolsAgent()->didBeginFrame();
6051}
6052
6053void RenderViewImpl::InstrumentDidBeginFrame() {
6054 if (!webview())
6055 return;
6056 if (!webview()->devToolsAgent())
6057 return;
6058 // TODO(jamesr/caseq): Decide if this needs to be renamed.
6059 webview()->devToolsAgent()->didComposite();
6060}
6061
6062void RenderViewImpl::InstrumentDidCancelFrame() {
6063 if (!webview())
6064 return;
6065 if (!webview()->devToolsAgent())
6066 return;
6067 webview()->devToolsAgent()->didCancelFrame();
6068}
6069
6070void RenderViewImpl::InstrumentWillComposite() {
6071 if (!webview())
6072 return;
6073 if (!webview()->devToolsAgent())
6074 return;
6075 webview()->devToolsAgent()->willComposite();
6076}
6077
[email protected]34bb3ac2013-03-08 02:41:286078bool RenderViewImpl::AllowPartialSwap() const {
6079 return allow_partial_swap_;
6080}
6081
[email protected]310ebd6302011-10-10 19:06:286082bool RenderViewImpl::ScheduleFileChooser(
[email protected]e9ff79c2012-10-19 21:31:266083 const FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:476084 WebFileChooserCompletion* completion) {
6085 static const size_t kMaximumPendingFileChooseRequests = 4;
6086 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
6087 // This sanity check prevents too many file choose requests from getting
6088 // queued which could DoS the user. Getting these is most likely a
6089 // programming error (there are many ways to DoS the user so it's not
6090 // considered a "real" security check), either in JS requesting many file
6091 // choosers to pop up, or in a plugin.
6092 //
6093 // TODO(brettw) we might possibly want to require a user gesture to open
6094 // a file picker, which will address this issue in a better way.
6095 return false;
6096 }
6097
6098 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
6099 new PendingFileChooser(params, completion)));
6100 if (file_chooser_completions_.size() == 1) {
6101 // Actually show the browse dialog when this is the first request.
6102 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
6103 }
6104 return true;
6105}
6106
[email protected]310ebd6302011-10-10 19:06:286107WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:516108 if (!geolocation_dispatcher_)
6109 geolocation_dispatcher_ = new GeolocationDispatcher(this);
6110 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:256111}
[email protected]61c9f032010-03-31 23:04:196112
[email protected]310ebd6302011-10-10 19:06:286113WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:116114 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:226115#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:026116 if (!input_tag_speech_dispatcher_)
6117 input_tag_speech_dispatcher_ =
6118 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:226119#endif
[email protected]c52b2892012-03-07 11:01:026120 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:116121}
6122
[email protected]64d09222012-05-25 10:10:346123WebKit::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
[email protected]64d09222012-05-25 10:10:346124 if (!speech_recognition_dispatcher_)
6125 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
[email protected]64d09222012-05-25 10:10:346126 return speech_recognition_dispatcher_;
6127}
6128
[email protected]310ebd6302011-10-10 19:06:286129WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:516130 if (!device_orientation_dispatcher_)
6131 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
6132 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:536133}
6134
[email protected]310ebd6302011-10-10 19:06:286135void RenderViewImpl::zoomLimitsChanged(double minimum_level,
6136 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:256137 // For now, don't remember plugin zoom values. We don't want to mix them with
6138 // normal web content (i.e. a fixed layout plugin would usually want them
6139 // different).
6140 bool remember = !webview()->mainFrame()->document().isPluginDocument();
6141
[email protected]b75b8292010-10-01 07:28:256142 int minimum_percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:496143 ZoomLevelToZoomFactor(minimum_level) * 100);
[email protected]b75b8292010-10-01 07:28:256144 int maximum_percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:496145 ZoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:256146
6147 Send(new ViewHostMsg_UpdateZoomLimits(
6148 routing_id_, minimum_percent, maximum_percent, remember));
6149}
6150
[email protected]310ebd6302011-10-10 19:06:286151void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:256152 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:086153 float zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:266154
6155 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
6156
[email protected]b75b8292010-10-01 07:28:256157 // Tell the browser which url got zoomed so it can update the menu and the
6158 // saved values if necessary
6159 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:086160 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:416161 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:256162}
6163
[email protected]7940b8e2013-07-25 23:08:496164double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const {
6165 return ZoomLevelToZoomFactor(zoom_level);
6166}
6167
6168double RenderViewImpl::zoomFactorToZoomLevel(double factor) const {
6169 return ZoomFactorToZoomLevel(factor);
6170}
6171
[email protected]310ebd6302011-10-10 19:06:286172void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
6173 const WebString& base_url,
6174 const WebString& url,
6175 const WebString& title) {
[email protected]af15bf22013-03-08 01:18:176176 bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]a6d36cc2011-02-23 00:39:486177 GURL base(base_url);
6178 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
6179 if (base.GetOrigin() != absolute_url.GetOrigin()) {
6180 return;
6181 }
[email protected]f1a29a02011-10-06 23:08:446182 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
6183 UTF16ToUTF8(scheme),
6184 absolute_url,
[email protected]3a3b75a2012-06-01 08:38:366185 title,
6186 user_gesture));
[email protected]a6d36cc2011-02-23 00:39:486187}
6188
[email protected]310ebd6302011-10-10 19:06:286189WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:446190 WebKit::WebPageVisibilityState current_state = is_hidden() ?
6191 WebKit::WebPageVisibilityStateHidden :
6192 WebKit::WebPageVisibilityStateVisible;
6193 WebKit::WebPageVisibilityState override_state = current_state;
[email protected]e9ff79c2012-10-19 21:31:266194 if (GetContentClient()->renderer()->
[email protected]f59203a2011-06-07 10:01:446195 ShouldOverridePageVisibilityState(this,
6196 &override_state))
6197 return override_state;
6198 return current_state;
[email protected]94dec932011-05-26 20:04:216199}
6200
[email protected]273558fb2012-01-12 15:03:516201WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
[email protected]60ee79f2013-09-11 13:49:556202 // This can happen in tests, in which case it's OK to return NULL.
6203 if (!InitializeMediaStreamClient())
6204 return NULL;
6205
[email protected]c3bdce152013-07-10 04:56:346206 return web_user_media_client_;
[email protected]273558fb2012-01-12 15:03:516207}
6208
[email protected]7b77f6cb2013-07-25 16:23:146209WebKit::WebMIDIClient* RenderViewImpl::webMIDIClient() {
6210 if (!midi_dispatcher_)
6211 midi_dispatcher_ = new MIDIDispatcher(this);
6212 return midi_dispatcher_;
6213}
6214
[email protected]a0629af92012-08-08 00:39:376215void RenderViewImpl::draggableRegionsChanged() {
6216 FOR_EACH_OBSERVER(
6217 RenderViewObserver,
6218 observers_,
6219 DraggableRegionsChanged(webview()->mainFrame()));
6220}
6221
[email protected]20657a82012-08-21 20:23:036222#if defined(OS_ANDROID)
6223WebContentDetectionResult RenderViewImpl::detectContentAround(
6224 const WebHitTestResult& touch_hit) {
6225 DCHECK(!touch_hit.isNull());
6226 DCHECK(!touch_hit.node().isNull());
6227 DCHECK(touch_hit.node().isTextNode());
6228
6229 // Process the position with all the registered content detectors until
6230 // a match is found. Priority is provided by their relative order.
6231 for (ContentDetectorList::const_iterator it = content_detectors_.begin();
6232 it != content_detectors_.end(); ++it) {
6233 ContentDetector::Result content = (*it)->FindTappedContent(touch_hit);
6234 if (content.valid) {
6235 return WebContentDetectionResult(content.content_boundaries,
6236 UTF8ToUTF16(content.text), content.intent_url);
6237 }
6238 }
6239 return WebContentDetectionResult();
6240}
6241
6242void RenderViewImpl::scheduleContentIntent(const WebURL& intent) {
6243 // Introduce a short delay so that the user can notice the content.
[email protected]dd32b1272013-05-04 14:17:116244 base::MessageLoop::current()->PostDelayedTask(
[email protected]20657a82012-08-21 20:23:036245 FROM_HERE,
[email protected]dd32b1272013-05-04 14:17:116246 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent,
6247 AsWeakPtr(),
6248 intent,
6249 expected_content_intent_id_),
[email protected]20657a82012-08-21 20:23:036250 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds));
6251}
6252
6253void RenderViewImpl::cancelScheduledContentIntents() {
6254 ++expected_content_intent_id_;
6255}
6256
6257void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent,
6258 size_t request_id) {
6259 if (request_id != expected_content_intent_id_)
6260 return;
6261
6262 // Remove the content highlighting if any.
6263 scheduleComposite();
6264
6265 if (!intent.is_empty())
6266 Send(new ViewHostMsg_StartContentIntent(routing_id_, intent));
6267}
[email protected]b18583c2012-12-18 06:55:276268
6269bool RenderViewImpl::openDateTimeChooser(
6270 const WebKit::WebDateTimeChooserParams& params,
6271 WebKit::WebDateTimeChooserCompletion* completion) {
6272 date_time_picker_client_.reset(
6273 new RendererDateTimePicker(this, params, completion));
6274 return date_time_picker_client_->Open();
6275}
6276
[email protected]6d17f6392012-12-05 05:24:546277#endif // defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:036278
[email protected]caf706f2010-10-26 17:54:086279#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:286280void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:156281 if (external_popup_menu_ == NULL) {
6282 // Crash reports from the field indicate that we can be notified with a
6283 // NULL external popup menu (we probably get notified twice).
6284 // If you hit this please file a bug against jcivelli and include the page
6285 // and steps to repro.
6286 NOTREACHED();
6287 return;
6288 }
[email protected]caf706f2010-10-26 17:54:086289 external_popup_menu_->DidSelectItem(selected_index);
6290 external_popup_menu_.reset();
6291}
6292#endif
[email protected]bb461532010-11-26 21:50:236293
[email protected]24d2b172012-05-26 00:54:126294#if defined(OS_ANDROID)
6295void RenderViewImpl::OnSelectPopupMenuItems(
6296 bool canceled,
6297 const std::vector<int>& selected_indices) {
6298 // It is possible to receive more than one of these calls if the user presses
6299 // a select faster than it takes for the show-select-popup IPC message to make
6300 // it to the browser UI thread. Ignore the extra-messages.
6301 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug.
[email protected]59383c782013-04-17 16:43:276302 if (!external_popup_menu_)
[email protected]24d2b172012-05-26 00:54:126303 return;
6304
6305 external_popup_menu_->DidSelectItems(canceled, selected_indices);
6306 external_popup_menu_.reset();
6307}
6308#endif
6309
[email protected]310ebd6302011-10-10 19:06:286310void RenderViewImpl::OnContextMenuClosed(
[email protected]e9ff79c2012-10-19 21:31:266311 const CustomContextMenuContext& custom_context) {
[email protected]860ee642012-10-13 03:46:256312 if (custom_context.request_id) {
6313 // External request, should be in our map.
[email protected]e9ff79c2012-10-19 21:31:266314 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:256315 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:466316 if (client) {
6317 client->OnMenuClosed(custom_context.request_id);
6318 pending_context_menus_.Remove(custom_context.request_id);
6319 }
[email protected]860ee642012-10-13 03:46:256320 } else {
6321 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:086322 context_menu_node_.reset();
[email protected]860ee642012-10-13 03:46:256323 }
[email protected]521b2482011-01-15 00:10:106324}
[email protected]5a7b15a2011-08-22 22:48:186325
[email protected]f56c7872013-06-18 12:31:576326void RenderViewImpl::OnShowContextMenu(const gfx::Point& location) {
[email protected]a14ddcd2013-06-21 22:53:036327 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH_EDIT_MENU;
[email protected]f56c7872013-06-18 12:31:576328 touch_editing_context_menu_location_ = location;
[email protected]47822262013-04-23 17:22:366329 if (webview())
6330 webview()->showContextMenu();
6331}
6332
[email protected]310ebd6302011-10-10 19:06:286333void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:186334 if (!webview())
6335 return;
6336 WebFrame* main_frame = webview()->mainFrame();
6337 if (!main_frame)
6338 return;
6339 main_frame->enableViewSourceMode(true);
6340}
[email protected]67bfb83f2011-09-22 03:36:376341
[email protected]c7654a232013-06-12 21:04:446342#if defined(OS_ANDROID)
[email protected]64d0e192011-12-09 14:44:206343void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7e9c5bb02012-05-14 13:58:316344 DCHECK(!java_bridge_dispatcher_);
[email protected]7e9c5bb02012-05-14 13:58:316345 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this);
[email protected]7f3c7af2011-10-20 22:52:516346}
[email protected]da816272013-05-15 21:31:176347#endif
[email protected]0720b532012-08-28 19:23:376348
[email protected]7cc78902012-12-06 02:32:266349void RenderViewImpl::OnDisownOpener() {
6350 if (!webview())
6351 return;
6352
6353 WebFrame* main_frame = webview()->mainFrame();
6354 if (main_frame && main_frame->opener())
6355 main_frame->setOpener(NULL);
6356}
6357
[email protected]efd7e47f2012-10-19 20:37:516358#if defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:036359bool RenderViewImpl::didTapMultipleTargets(
6360 const WebKit::WebGestureEvent& event,
6361 const WebVector<WebRect>& target_rects) {
[email protected]8d3dfee62013-06-19 05:50:336362 // Never show a disambiguation popup when accessibility is enabled,
6363 // as this interferes with "touch exploration".
6364 if (accessibility_mode_ == AccessibilityModeComplete)
6365 return false;
6366
[email protected]f9526d12012-10-18 01:55:036367 gfx::Rect finger_rect(
6368 event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2,
6369 event.data.tap.width, event.data.tap.height);
6370 gfx::Rect zoom_rect;
[email protected]70221f02013-01-31 22:17:076371 float new_total_scale =
6372 DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
6373 finger_rect, target_rects, GetSize(),
6374 gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(),
6375 device_scale_factor_ * webview()->pageScaleFactor(), &zoom_rect);
6376 if (!new_total_scale)
[email protected]f9526d12012-10-18 01:55:036377 return false;
6378
[email protected]4ded1dbf2013-08-28 21:11:036379 bool handled = false;
6380 switch (renderer_preferences_.tap_multiple_targets_strategy) {
6381 case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM:
6382 handled = webview()->zoomToMultipleTargetsRect(zoom_rect);
6383 break;
6384 case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: {
[email protected]bc2804d2013-08-06 07:45:496385 gfx::Size canvas_size =
6386 gfx::ToCeiledSize(gfx::ScaleSize(zoom_rect.size(), new_total_scale));
6387 TransportDIB* transport_dib = NULL;
6388 {
6389 scoped_ptr<skia::PlatformCanvas> canvas(
6390 RenderProcess::current()->GetDrawingCanvas(&transport_dib,
6391 gfx::Rect(canvas_size)));
[email protected]4ded1dbf2013-08-28 21:11:036392 if (!canvas) {
6393 handled = false;
6394 break;
6395 }
[email protected]f9526d12012-10-18 01:55:036396
[email protected]bc2804d2013-08-06 07:45:496397 // TODO(trchen): Cleanup the device scale factor mess.
6398 // device scale will be applied in WebKit
6399 // --> zoom_rect doesn't include device scale,
6400 // but WebKit will still draw on zoom_rect * device_scale_factor_
6401 canvas->scale(new_total_scale / device_scale_factor_,
6402 new_total_scale / device_scale_factor_);
6403 canvas->translate(-zoom_rect.x() * device_scale_factor_,
6404 -zoom_rect.y() * device_scale_factor_);
[email protected]f9526d12012-10-18 01:55:036405
[email protected]bc2804d2013-08-06 07:45:496406 webwidget_->paint(
6407 canvas.get(),
6408 zoom_rect,
6409 WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent);
6410 }
6411
6412 gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect(
6413 ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect)));
6414 Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_,
6415 physical_window_zoom_rect,
6416 canvas_size,
6417 transport_dib->id()));
[email protected]4ded1dbf2013-08-28 21:11:036418 handled = true;
6419 break;
6420 }
6421 case TAP_MULTIPLE_TARGETS_STRATEGY_NONE:
6422 // No-op.
6423 break;
[email protected]f9526d12012-10-18 01:55:036424 }
[email protected]70221f02013-01-31 22:17:076425
[email protected]4ded1dbf2013-08-28 21:11:036426 return handled;
[email protected]f9526d12012-10-18 01:55:036427}
[email protected]efd7e47f2012-10-19 20:37:516428#endif
[email protected]f9526d12012-10-18 01:55:036429
[email protected]b283d292013-02-21 08:40:346430unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
6431 return history_list_length_;
6432}
6433
[email protected]cc290f902013-03-04 20:06:026434void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
6435 if (enable) {
6436 if (has_focus())
6437 return;
6438 OnSetActive(true);
6439 OnSetFocus(true);
6440 } else {
6441 if (!has_focus())
6442 return;
6443 OnSetFocus(false);
6444 OnSetActive(false);
6445 }
6446}
6447
[email protected]3a1c8a8032013-03-18 22:35:326448void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) {
[email protected]b54fe452013-06-07 14:01:536449 ViewMsg_Resize_Params params;
6450 params.screen_info = screen_info_;
6451 params.screen_info.deviceScaleFactor = factor;
6452 params.new_size = size();
6453 params.physical_backing_size =
6454 gfx::ToCeiledSize(gfx::ScaleSize(size(), factor));
6455 params.overdraw_bottom_height = 0.f;
6456 params.resizer_rect = WebRect();
6457 params.is_fullscreen = is_fullscreen();
6458 OnResize(params);
[email protected]3a1c8a8032013-03-18 22:35:326459}
6460
[email protected]eac2b362013-05-22 07:01:456461void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size,
6462 const gfx::Size& max_size) {
6463 OnEnableAutoResize(min_size, max_size);
6464}
6465
6466void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) {
6467 OnDisableAutoResize(new_size);
6468}
6469
[email protected]c3bdce152013-07-10 04:56:346470void RenderViewImpl::SetMediaStreamClientForTesting(
[email protected]5e35a8d2013-07-10 19:37:216471 MediaStreamClient* media_stream_client) {
[email protected]c3bdce152013-07-10 04:56:346472 DCHECK(!media_stream_client_);
6473 DCHECK(!web_user_media_client_);
6474 media_stream_client_ = media_stream_client;
6475}
6476
[email protected]f9526d12012-10-18 01:55:036477void RenderViewImpl::OnReleaseDisambiguationPopupDIB(
6478 TransportDIB::Handle dib_handle) {
6479 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle);
6480 RenderProcess::current()->ReleaseTransportDIB(dib);
6481}
[email protected]e9ff79c2012-10-19 21:31:266482
[email protected]6fceb912013-02-15 06:24:156483void RenderViewImpl::DidCommitCompositorFrame() {
6484 RenderWidget::DidCommitCompositorFrame();
6485 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame());
6486}
6487
[email protected]41225fe2013-03-29 05:32:026488void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) {
6489 if (!urls.empty())
6490 Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, page_id_, urls));
6491}
6492
6493void RenderViewImpl::DidStopLoadingIcons() {
6494 int icon_types = WebIconURL::TypeFavicon;
6495 if (TouchEnabled())
6496 icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch;
6497
6498 WebVector<WebIconURL> icon_urls =
6499 webview()->mainFrame()->iconURLs(icon_types);
6500
6501 std::vector<FaviconURL> urls;
6502 for (size_t i = 0; i < icon_urls.size(); i++) {
6503 WebURL url = icon_urls[i].iconURL();
6504 if (!url.isEmpty())
6505 urls.push_back(FaviconURL(url,
6506 ToFaviconType(icon_urls[i].iconType())));
6507 }
6508 SendUpdateFaviconURL(urls);
6509}
6510
[email protected]e9ff79c2012-10-19 21:31:266511} // namespace content