blob: 3a2abf6a951c9c7ebd9431b0e20d55e8a4aba236 [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]7d08a9352013-10-15 08:24:5626#include "base/process/process.h"
[email protected]21aa99682013-06-11 07:17:0127#include "base/strings/string_number_conversions.h"
[email protected]b9e7c479f2013-04-12 04:33:2428#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4929#include "base/strings/string_split.h"
[email protected]21aa99682013-06-11 07:17:0130#include "base/strings/string_util.h"
[email protected]40d11e02013-03-28 17:43:1431#include "base/strings/sys_string_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0032#include "base/strings/utf_string_conversions.h"
[email protected]abb522162013-06-28 01:54:1633#include "base/time/time.h"
[email protected]e3415902013-10-17 15:00:4634#include "cc/base/switches.h"
[email protected]a8cb3b73b2013-08-12 05:50:5035#include "content/child/appcache/appcache_dispatcher.h"
36#include "content/child/appcache/web_application_cache_host_impl.h"
[email protected]10208ea2013-06-06 20:08:0337#include "content/child/child_thread.h"
[email protected]29e2fb42013-07-19 01:13:4738#include "content/child/npapi/webplugin_delegate_impl.h"
[email protected]541b7b02013-06-07 00:59:3439#include "content/child/request_extra_data.h"
[email protected]10208ea2013-06-06 20:08:0340#include "content/child/webmessageportchannel_impl.h"
[email protected]127dd582011-03-16 21:32:1041#include "content/common/clipboard_messages.h"
[email protected]37666cf2011-03-13 21:51:4242#include "content/common/database_messages.h"
[email protected]5f2aa722013-08-07 16:59:4143#include "content/common/dom_storage/dom_storage_types.h"
[email protected]59f4f2fa2011-03-23 01:00:5544#include "content/common/drag_messages.h"
[email protected]c26ad882012-02-07 06:41:2045#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]c084330e02013-04-27 01:08:1546#include "content/common/input_messages.h"
[email protected]7f3c7af2011-10-20 22:52:5147#include "content/common/java_bridge_messages.h"
[email protected]127dd582011-03-16 21:32:1048#include "content/common/pepper_messages.h"
[email protected]5fa3a062012-03-21 15:39:3449#include "content/common/socket_stream_handle_data.h"
[email protected]e4495212012-12-06 03:09:1250#include "content/common/ssl_status_serialization.h"
[email protected]778574e2011-03-21 22:03:5051#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2152#include "content/public/common/bindings_policy.h"
[email protected]744c2a22012-03-15 18:42:0453#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4854#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2955#include "content/public/common/content_switches.h"
[email protected]35be7ec2012-02-12 20:42:5156#include "content/public/common/context_menu_params.h"
[email protected]dc293a72013-07-01 11:11:2257#include "content/public/common/drop_data.h"
[email protected]41225fe2013-03-29 05:32:0258#include "content/public/common/favicon_url.h"
[email protected]8caadeb2011-11-22 02:45:2359#include "content/public/common/file_chooser_params.h"
[email protected]7940b8e2013-07-25 23:08:4960#include "content/public/common/page_zoom.h"
[email protected]e4495212012-12-06 03:09:1261#include "content/public/common/ssl_status.h"
[email protected]818915cd2012-11-20 13:14:1162#include "content/public/common/three_d_api_types.h"
[email protected]a1d29162011-10-14 17:14:0363#include "content/public/common/url_constants.h"
[email protected]3b366ae2013-05-17 21:16:5864#include "content/public/common/url_utils.h"
[email protected]d344114c2011-10-01 01:24:3465#include "content/public/renderer/content_renderer_client.h"
[email protected]97f58132012-11-15 20:41:3266#include "content/public/renderer/context_menu_client.h"
[email protected]007733c2011-11-17 00:34:0767#include "content/public/renderer/document_state.h"
[email protected]691aa2f2013-05-28 22:52:0468#include "content/public/renderer/history_item_serialization.h"
[email protected]82ddba1c2011-10-04 00:15:3269#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4470#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3671#include "content/public/renderer/render_view_visitor.h"
[email protected]49a20002013-08-18 12:43:3172#include "content/public/renderer/web_preferences.h"
[email protected]4e4646a52013-02-08 07:23:4173#include "content/renderer/accessibility/renderer_accessibility.h"
74#include "content/renderer/accessibility/renderer_accessibility_complete.h"
75#include "content/renderer/accessibility/renderer_accessibility_focus_only.h"
[email protected]e6e56752012-08-10 00:46:0676#include "content/renderer/browser_plugin/browser_plugin.h"
77#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]fb325d122012-11-20 23:58:0578#include "content/renderer/browser_plugin/browser_plugin_manager_impl.h"
[email protected]3175fea2013-05-16 10:57:4879#include "content/renderer/context_menu_params_builder.h"
[email protected]70019152012-12-19 11:44:1980#include "content/renderer/devtools/devtools_agent.h"
[email protected]f9526d12012-10-18 01:55:0381#include "content/renderer/disambiguation_popup_helper.h"
[email protected]766a7082012-02-03 23:39:1582#include "content/renderer/dom_automation_controller.h"
[email protected]1910fe82012-05-10 00:04:1083#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]dc293a72013-07-01 11:11:2284#include "content/renderer/drop_data_builder.h"
[email protected]55722152011-03-22 01:33:5385#include "content/renderer/external_popup_menu.h"
[email protected]f8c700ba2013-05-14 08:25:4986#include "content/renderer/fetchers/alt_error_page_resource_fetcher.h"
[email protected]230b7ef2011-03-16 22:30:1987#include "content/renderer/geolocation_dispatcher.h"
[email protected]ea5f70a2013-03-07 12:30:3688#include "content/renderer/gpu/input_handler_manager.h"
[email protected]ba91a792013-02-06 09:48:2889#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]1784b2f2011-11-24 10:53:4890#include "content/renderer/idle_user_detector.h"
[email protected]41225fe2013-03-29 05:32:0291#include "content/renderer/image_loading_helper.h"
[email protected]66fca5bc2013-05-23 06:58:2992#include "content/renderer/ime_event_guard.h"
[email protected]c52b2892012-03-07 11:01:0293#include "content/renderer/input_tag_speech_dispatcher.h"
[email protected]92d457802013-04-01 19:18:4994#include "content/renderer/internal_document_state_data.h"
[email protected]07161902011-11-11 09:57:4295#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0296#include "content/renderer/load_progress_tracker.h"
[email protected]4a914882013-01-10 00:43:4897#include "content/renderer/media/audio_device_factory.h"
98#include "content/renderer/media/audio_renderer_mixer_manager.h"
[email protected]273558fb2012-01-12 15:03:5199#include "content/renderer/media/media_stream_dependency_factory.h"
100#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:40101#include "content/renderer/media/media_stream_impl.h"
[email protected]7b77f6cb2013-07-25 16:23:14102#include "content/renderer/media/midi_dispatcher.h"
[email protected]090f7312011-08-05 23:26:40103#include "content/renderer/media/render_media_log.h"
[email protected]6392d982013-04-16 16:59:22104#include "content/renderer/media/video_capture_impl_manager.h"
[email protected]5e35a8d2013-07-10 19:37:21105#include "content/renderer/media/webmediaplayer_impl.h"
106#include "content/renderer/media/webmediaplayer_ms.h"
107#include "content/renderer/media/webmediaplayer_params.h"
[email protected]4a19be92011-09-22 14:25:02108#include "content/renderer/mhtml_generator.h"
[email protected]230b7ef2011-03-16 22:30:19109#include "content/renderer/notification_provider.h"
[email protected]227692c52013-05-31 22:43:04110#include "content/renderer/render_frame_impl.h"
[email protected]8704f89b2011-04-15 00:30:05111#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:44112#include "content/renderer/render_thread_impl.h"
[email protected]8d41d7612012-11-14 20:32:19113#include "content/renderer/render_view_impl_params.h"
[email protected]89054502012-06-03 10:29:24114#include "content/renderer/render_view_mouse_lock_dispatcher.h"
[email protected]2cff0052011-03-18 16:51:44115#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]b18583c2012-12-18 06:55:27116#include "content/renderer/renderer_date_time_picker.h"
[email protected]663bd9e2011-03-21 01:07:01117#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]da8543762012-03-20 08:52:20118#include "content/renderer/renderer_webcolorchooser_impl.h"
[email protected]5b45ad42013-10-25 00:42:04119#include "content/renderer/resizing_mode_selector.h"
[email protected]12a936d2013-05-15 04:55:49120#include "content/renderer/savable_resources.h"
[email protected]503fa032013-10-27 19:34:40121#include "content/renderer/shared_worker_repository.h"
[email protected]64d09222012-05-25 10:10:34122#include "content/renderer/speech_recognition_dispatcher.h"
[email protected]27c521a2013-05-29 20:44:32123#include "content/renderer/stats_collection_controller.h"
124#include "content/renderer/stats_collection_observer.h"
[email protected]86a7d3c2011-09-12 16:45:32125#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:19126#include "content/renderer/v8_value_converter_impl.h"
[email protected]940ed1d2012-11-27 21:03:21127#include "content/renderer/web_ui_extension.h"
128#include "content/renderer/web_ui_extension_data.h"
[email protected]6f516082011-03-17 19:15:35129#include "content/renderer/websharedworker_proxy.h"
[email protected]f5961142013-04-17 23:09:42130#include "media/audio/audio_output_device.h"
[email protected]4a914882013-01-10 00:43:48131#include "media/base/audio_renderer_mixer_input.h"
[email protected]f8db8132010-12-03 00:27:49132#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41133#include "media/base/media_switches.h"
[email protected]37136d162012-04-09 23:39:19134#include "media/filters/audio_renderer_impl.h"
[email protected]1cad8802013-08-13 16:54:32135#include "media/filters/gpu_video_accelerator_factories.h"
[email protected]d1ef81d2012-07-24 11:39:36136#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29137#include "net/base/escape.h"
138#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09139#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04140#include "net/http/http_util.h"
[email protected]d0fcff72013-07-23 02:45:43141#include "third_party/WebKit/public/platform/WebCString.h"
142#include "third_party/WebKit/public/platform/WebDragData.h"
[email protected]d0fcff72013-07-23 02:45:43143#include "third_party/WebKit/public/platform/WebHTTPBody.h"
144#include "third_party/WebKit/public/platform/WebImage.h"
145#include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
146#include "third_party/WebKit/public/platform/WebPoint.h"
147#include "third_party/WebKit/public/platform/WebRect.h"
148#include "third_party/WebKit/public/platform/WebSize.h"
149#include "third_party/WebKit/public/platform/WebSocketStreamHandle.h"
150#include "third_party/WebKit/public/platform/WebString.h"
151#include "third_party/WebKit/public/platform/WebURL.h"
152#include "third_party/WebKit/public/platform/WebURLError.h"
153#include "third_party/WebKit/public/platform/WebURLRequest.h"
154#include "third_party/WebKit/public/platform/WebURLResponse.h"
155#include "third_party/WebKit/public/platform/WebVector.h"
[email protected]10760e4a2013-09-04 23:32:20156#include "third_party/WebKit/public/web/WebAXObject.h"
[email protected]2255a9332013-06-17 05:12:31157#include "third_party/WebKit/public/web/WebColorName.h"
158#include "third_party/WebKit/public/web/WebDOMEvent.h"
159#include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
160#include "third_party/WebKit/public/web/WebDataSource.h"
161#include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h"
162#include "third_party/WebKit/public/web/WebDateTimeChooserParams.h"
163#include "third_party/WebKit/public/web/WebDevToolsAgent.h"
164#include "third_party/WebKit/public/web/WebDocument.h"
165#include "third_party/WebKit/public/web/WebElement.h"
166#include "third_party/WebKit/public/web/WebFileChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31167#include "third_party/WebKit/public/web/WebFindOptions.h"
168#include "third_party/WebKit/public/web/WebFormControlElement.h"
169#include "third_party/WebKit/public/web/WebFormElement.h"
170#include "third_party/WebKit/public/web/WebFrame.h"
[email protected]6bd867b2013-07-24 22:10:20171#include "third_party/WebKit/public/web/WebGlyphCache.h"
[email protected]2255a9332013-06-17 05:12:31172#include "third_party/WebKit/public/web/WebHelperPlugin.h"
173#include "third_party/WebKit/public/web/WebHistoryItem.h"
174#include "third_party/WebKit/public/web/WebInputElement.h"
175#include "third_party/WebKit/public/web/WebInputEvent.h"
176#include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
177#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
178#include "third_party/WebKit/public/web/WebNodeList.h"
179#include "third_party/WebKit/public/web/WebPageSerializer.h"
180#include "third_party/WebKit/public/web/WebPlugin.h"
181#include "third_party/WebKit/public/web/WebPluginAction.h"
182#include "third_party/WebKit/public/web/WebPluginContainer.h"
183#include "third_party/WebKit/public/web/WebPluginDocument.h"
184#include "third_party/WebKit/public/web/WebPluginParams.h"
185#include "third_party/WebKit/public/web/WebRange.h"
[email protected]91f05762013-08-21 02:55:09186#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
[email protected]2255a9332013-06-17 05:12:31187#include "third_party/WebKit/public/web/WebScriptSource.h"
188#include "third_party/WebKit/public/web/WebSearchableFormData.h"
189#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
190#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
191#include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
192#include "third_party/WebKit/public/web/WebSettings.h"
193#include "third_party/WebKit/public/web/WebStorageQuotaCallbacks.h"
194#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
195#include "third_party/WebKit/public/web/WebUserMediaClient.h"
196#include "third_party/WebKit/public/web/WebView.h"
197#include "third_party/WebKit/public/web/WebWindowFeatures.h"
198#include "third_party/WebKit/public/web/default/WebRenderTheme.h"
[email protected]1400e6dc2013-04-27 02:36:27199#include "ui/base/ui_base_switches_util.h"
[email protected]7d08a9352013-10-15 08:24:56200#include "ui/events/latency_info.h"
[email protected]08397d52011-02-05 01:53:38201#include "ui/gfx/native_widget_types.h"
202#include "ui/gfx/point.h"
203#include "ui/gfx/rect.h"
[email protected]70221f02013-01-31 22:17:07204#include "ui/gfx/rect_conversions.h"
[email protected]f9526d12012-10-18 01:55:03205#include "ui/gfx/size_conversions.h"
[email protected]4344a3c2013-01-17 23:49:20206#include "ui/shell_dialogs/selected_file_info.h"
[email protected]c4a9e932011-03-05 04:05:55207#include "v8/include/v8.h"
[email protected]d0fcff72013-07-23 02:45:43208#include "webkit/child/weburlresponse_extradata_impl.h"
initial.commit09911bf2008-07-26 23:55:29209
[email protected]25fb9b32012-04-27 03:21:55210#if defined(OS_ANDROID)
[email protected]befe54782013-04-23 00:49:25211#include <cpu-features.h>
212
[email protected]276e8a322013-01-24 01:50:11213#include "content/common/android/device_telephony_info.h"
[email protected]a45c46e2013-03-07 01:04:46214#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]20657a82012-08-21 20:23:03215#include "content/renderer/android/address_detector.h"
216#include "content/renderer/android/content_detector.h"
217#include "content/renderer/android/email_detector.h"
218#include "content/renderer/android/phone_number_detector.h"
[email protected]3a59bb92013-08-22 18:54:08219#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]bc427442013-07-13 02:53:08220#include "content/renderer/media/android/renderer_media_player_manager.h"
[email protected]3aaba572013-08-10 15:10:38221#include "content/renderer/media/android/stream_texture_factory_android_impl.h"
[email protected]be580992013-06-22 14:32:44222#include "content/renderer/media/android/webmediaplayer_android.h"
[email protected]c277d3c2013-07-15 21:49:37223#include "skia/ext/platform_canvas.h"
[email protected]5c30b5e02013-05-30 03:46:08224#include "third_party/WebKit/public/platform/WebFloatPoint.h"
225#include "third_party/WebKit/public/platform/WebFloatRect.h"
[email protected]d0fcff72013-07-23 02:45:43226#include "third_party/WebKit/public/web/WebHitTestResult.h"
[email protected]59363fc92012-09-05 03:46:31227#include "ui/gfx/rect_f.h"
[email protected]e69bb062013-06-03 13:05:40228
229#if defined(GOOGLE_TV)
230#include "content/renderer/media/rtc_video_decoder_bridge_tv.h"
231#include "content/renderer/media/rtc_video_decoder_factory_tv.h"
232#endif
233
[email protected]25fb9b32012-04-27 03:21:55234#elif defined(OS_WIN)
[email protected]6c8afae52009-01-22 02:24:57235// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57236// * theming
[email protected]990e6222012-11-16 13:31:18237#include "ui/native_theme/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03238#elif defined(USE_X11)
[email protected]990e6222012-11-16 13:31:18239#include "ui/native_theme/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33240#elif defined(OS_MACOSX)
241#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57242#endif
243
[email protected]ea2fb972013-08-07 05:44:26244#if defined(ENABLE_PLUGINS)
[email protected]a80af12e2013-08-07 23:36:13245#include "content/renderer/npapi/webplugin_delegate_proxy.h"
246#include "content/renderer/npapi/webplugin_impl.h"
[email protected]ea2fb972013-08-07 05:44:26247#include "content/renderer/pepper/pepper_browser_connection.h"
248#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
249#include "content/renderer/pepper/pepper_plugin_registry.h"
250#include "content/renderer/pepper/pepper_webplugin_impl.h"
251#include "content/renderer/pepper/plugin_module.h"
252#endif
253
[email protected]9ac667e2013-09-09 12:49:21254#if defined(ENABLE_WEBRTC)
255#include "content/renderer/media/rtc_peer_connection_handler.h"
256#endif
257
[email protected]180ef242013-11-07 06:50:46258using blink::WebAXObject;
259using blink::WebApplicationCacheHost;
260using blink::WebApplicationCacheHostClient;
261using blink::WebCString;
262using blink::WebColor;
263using blink::WebColorName;
264using blink::WebConsoleMessage;
265using blink::WebContextMenuData;
266using blink::WebCookieJar;
267using blink::WebData;
268using blink::WebDataSource;
269using blink::WebDocument;
270using blink::WebDOMEvent;
271using blink::WebDOMMessageEvent;
272using blink::WebDragData;
273using blink::WebDragOperation;
274using blink::WebDragOperationsMask;
275using blink::WebElement;
276using blink::WebExternalPopupMenu;
277using blink::WebExternalPopupMenuClient;
278using blink::WebFileChooserCompletion;
279using blink::WebFindOptions;
280using blink::WebFormControlElement;
281using blink::WebFormElement;
282using blink::WebFrame;
283using blink::WebGestureEvent;
284using blink::WebHistoryItem;
285using blink::WebHTTPBody;
286using blink::WebIconURL;
287using blink::WebImage;
288using blink::WebInputElement;
289using blink::WebInputEvent;
290using blink::WebMediaPlayer;
291using blink::WebMediaPlayerAction;
292using blink::WebMediaPlayerClient;
293using blink::WebMouseEvent;
294using blink::WebNavigationPolicy;
295using blink::WebNavigationType;
296using blink::WebNode;
297using blink::WebPageSerializer;
298using blink::WebPageSerializerClient;
299using blink::WebPeerConnection00Handler;
300using blink::WebPeerConnection00HandlerClient;
301using blink::WebPeerConnectionHandler;
302using blink::WebPeerConnectionHandlerClient;
303using blink::WebPluginAction;
304using blink::WebPluginContainer;
305using blink::WebPluginDocument;
306using blink::WebPluginParams;
307using blink::WebPoint;
308using blink::WebPopupMenuInfo;
309using blink::WebRange;
310using blink::WebRect;
311using blink::WebReferrerPolicy;
312using blink::WebRuntimeFeatures;
313using blink::WebScriptSource;
314using blink::WebSearchableFormData;
315using blink::WebSecurityOrigin;
316using blink::WebSecurityPolicy;
317using blink::WebSerializedScriptValue;
318using blink::WebSettings;
319using blink::WebSize;
320using blink::WebSocketStreamHandle;
321using blink::WebStorageNamespace;
322using blink::WebStorageQuotaCallbacks;
323using blink::WebStorageQuotaError;
324using blink::WebStorageQuotaType;
325using blink::WebString;
326using blink::WebTextAffinity;
327using blink::WebTextDirection;
328using blink::WebTouchEvent;
329using blink::WebURL;
330using blink::WebURLError;
331using blink::WebURLRequest;
332using blink::WebURLResponse;
333using blink::WebUserGestureIndicator;
334using blink::WebVector;
335using blink::WebView;
336using blink::WebWidget;
337using blink::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26338using base::Time;
339using base::TimeDelta;
[email protected]b9fd01ba2012-02-28 01:50:40340using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33341
[email protected]20657a82012-08-21 20:23:03342#if defined(OS_ANDROID)
[email protected]180ef242013-11-07 06:50:46343using blink::WebContentDetectionResult;
344using blink::WebFloatPoint;
345using blink::WebFloatRect;
346using blink::WebHitTestResult;
[email protected]20657a82012-08-21 20:23:03347#endif
348
[email protected]e9ff79c2012-10-19 21:31:26349namespace content {
350
initial.commit09911bf2008-07-26 23:55:29351//-----------------------------------------------------------------------------
352
[email protected]180ef242013-11-07 06:50:46353typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49354static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]058561b2012-12-03 06:48:22355typedef std::map<int32, RenderViewImpl*> RoutingIDViewMap;
356static base::LazyInstance<RoutingIDViewMap> g_routing_id_view_map =
357 LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02358
[email protected]882daa92009-11-05 16:31:31359// Time, in seconds, we delay before sending content state changes (such as form
360// state and scroll position) to the browser. We delay sending changes to avoid
361// spamming the browser.
362// To avoid having tab/session restore require sending a message to get the
363// current content state during tab closing we use a shorter timeout for the
364// foreground renderer. This means there is a small window of time from which
365// content state is modified and not sent to session restore, but this is
366// better than having to wake up all renderers during shutdown.
[email protected]9afc14e22013-09-25 22:34:14367const int kDelaySecondsForContentStateSyncHidden = 5;
368const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29369
[email protected]9afc14e22013-09-25 22:34:14370const size_t kExtraCharsBeforeAndAfterSelection = 100;
[email protected]e99ef6f2011-10-16 01:13:00371
[email protected]9afc14e22013-09-25 22:34:14372const float kScalingIncrementForGesture = 0.01f;
[email protected]47578fa02011-11-02 19:34:41373
[email protected]20657a82012-08-21 20:23:03374#if defined(OS_ANDROID)
375// Delay between tapping in content and launching the associated android intent.
376// Used to allow users see what has been recognized as content.
[email protected]9afc14e22013-09-25 22:34:14377const size_t kContentIntentDelayMilliseconds = 700;
[email protected]20657a82012-08-21 20:23:03378#endif
379
[email protected]8d41d7612012-11-14 20:32:19380static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) =
381 NULL;
382
[email protected]726985e22009-06-18 21:09:28383static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
[email protected]bf692cd2012-11-14 19:10:02384 // Replace any occurrences of swappedout:// with about:blank.
[email protected]081dc522013-05-15 04:59:20385 const WebURL& blank_url = GURL(kAboutBlankURL);
[email protected]726985e22009-06-18 21:09:28386 WebVector<WebURL> urls;
387 ds->redirectChain(urls);
388 result->reserve(urls.size());
[email protected]bf692cd2012-11-14 19:10:02389 for (size_t i = 0; i < urls.size(); ++i) {
390 if (urls[i] != GURL(kSwappedOutURL))
391 result->push_back(urls[i]);
392 else
393 result->push_back(blank_url);
394 }
[email protected]726985e22009-06-18 21:09:28395}
396
[email protected]e20b88d2013-04-09 15:28:37397// If |data_source| is non-null and has an InternalDocumentStateData associated
398// with it, the AltErrorPageResourceFetcher is reset.
[email protected]6a8f5112011-05-13 16:38:44399static void StopAltErrorPageFetcher(WebDataSource* data_source) {
400 if (data_source) {
[email protected]e20b88d2013-04-09 15:28:37401 InternalDocumentStateData* internal_data =
402 InternalDocumentStateData::FromDataSource(data_source);
403 if (internal_data)
404 internal_data->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44405 }
406}
407
[email protected]007733c2011-11-17 00:34:07408static bool IsReload(const ViewMsg_Navigate_Params& params) {
409 return
410 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
[email protected]7c16976c2012-08-04 02:38:23411 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE ||
412 params.navigation_type ==
413 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]007733c2011-11-17 00:34:07414}
415
[email protected]e507045d2013-07-24 15:23:44416// static
417WebReferrerPolicy RenderViewImpl::GetReferrerPolicyFromRequest(
[email protected]ca662822012-05-11 17:53:59418 WebFrame* frame,
[email protected]445e1042011-12-03 21:03:15419 const WebURLRequest& request) {
420 return request.extraData() ?
421 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
[email protected]ca662822012-05-11 17:53:59422 frame->document().referrerPolicy();
[email protected]445e1042011-12-03 21:03:15423}
424
[email protected]e507045d2013-07-24 15:23:44425// static
426Referrer RenderViewImpl::GetReferrerFromRequest(
[email protected]44e55b012013-07-23 14:21:56427 WebFrame* frame,
428 const WebURLRequest& request) {
429 return Referrer(GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
430 GetReferrerPolicyFromRequest(frame, request));
431}
432
[email protected]e507045d2013-07-24 15:23:44433// static
434WebURLResponseExtraDataImpl* RenderViewImpl::GetExtraDataFromResponse(
[email protected]b9fd01ba2012-02-28 01:50:40435 const WebURLResponse& response) {
436 return static_cast<WebURLResponseExtraDataImpl*>(
437 response.extraData());
438}
439
[email protected]2149cc622012-02-14 01:12:12440NOINLINE static void CrashIntentionally() {
441 // NOTE(shess): Crash directly rather than using NOTREACHED() so
442 // that the signature is easier to triage in crash reports.
443 volatile int* zero = NULL;
444 *zero = 0;
445}
446
[email protected]2132d6b2013-06-05 00:15:43447#if defined(ADDRESS_SANITIZER)
448NOINLINE static void MaybeTriggerAsanError(const GURL& url) {
449 // NOTE(rogerm): We intentionally perform an invalid heap access here in
450 // order to trigger an Address Sanitizer (ASAN) error report.
451 static const char kCrashDomain[] = "crash";
452 static const char kHeapOverflow[] = "/heap-overflow";
453 static const char kHeapUnderflow[] = "/heap-underflow";
454 static const char kUseAfterFree[] = "/use-after-free";
455 static const int kArraySize = 5;
456
457 if (!url.DomainIs(kCrashDomain, sizeof(kCrashDomain) - 1))
458 return;
459
460 if (!url.has_path())
461 return;
462
463 scoped_ptr<int[]> array(new int[kArraySize]);
464 std::string crash_type(url.path());
465 int dummy = 0;
466 if (crash_type == kHeapOverflow) {
467 dummy = array[kArraySize];
468 } else if (crash_type == kHeapUnderflow ) {
469 dummy = array[-1];
470 } else if (crash_type == kUseAfterFree) {
471 int* dangling = array.get();
472 array.reset();
473 dummy = dangling[kArraySize / 2];
474 }
475
476 // Make sure the assignments to the dummy value aren't optimized away.
477 base::debug::Alias(&dummy);
478}
479#endif // ADDRESS_SANITIZER
480
[email protected]8bf1048012012-02-08 01:22:18481static void MaybeHandleDebugURL(const GURL& url) {
482 if (!url.SchemeIs(chrome::kChromeUIScheme))
483 return;
[email protected]f8a6d732013-03-02 22:46:03484 if (url == GURL(kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12485 CrashIntentionally();
[email protected]f8a6d732013-03-02 22:46:03486 } else if (url == GURL(kChromeUIKillURL)) {
[email protected]8bf1048012012-02-08 01:22:18487 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
[email protected]f8a6d732013-03-02 22:46:03488 } else if (url == GURL(kChromeUIHangURL)) {
[email protected]8bf1048012012-02-08 01:22:18489 for (;;) {
490 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
491 }
[email protected]50f86bc2012-11-01 19:59:13492 } else if (url == GURL(kChromeUIShorthangURL)) {
[email protected]8bf1048012012-02-08 01:22:18493 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
494 }
[email protected]2132d6b2013-06-05 00:15:43495
496#if defined(ADDRESS_SANITIZER)
497 MaybeTriggerAsanError(url);
498#endif // ADDRESS_SANITIZER
[email protected]8bf1048012012-02-08 01:22:18499}
500
[email protected]fd3238af2012-05-22 18:55:30501// Returns false unless this is a top-level navigation.
502static bool IsTopLevelNavigation(WebFrame* frame) {
503 return frame->parent() == NULL;
504}
505
506// Returns false unless this is a top-level navigation that crosses origins.
507static bool IsNonLocalTopLevelNavigation(const GURL& url,
508 WebFrame* frame,
[email protected]140a5882013-07-23 19:30:33509 WebNavigationType type,
510 bool is_form_post) {
[email protected]fd3238af2012-05-22 18:55:30511 if (!IsTopLevelNavigation(frame))
512 return false;
513
514 // Navigations initiated within Webkit are not sent out to the external host
515 // in the following cases.
516 // 1. The url scheme is not http/https
517 // 2. The origin of the url and the opener is the same in which case the
518 // opener relationship is maintained.
519 // 3. Reloads/form submits/back forward navigations
[email protected]e9a82042013-09-15 03:38:29520 if (!url.SchemeIs(kHttpScheme) && !url.SchemeIs(kHttpsScheme))
[email protected]fd3238af2012-05-22 18:55:30521 return false;
522
[email protected]180ef242013-11-07 06:50:46523 if (type != blink::WebNavigationTypeReload &&
524 type != blink::WebNavigationTypeBackForward && !is_form_post) {
[email protected]fd3238af2012-05-22 18:55:30525 // The opener relationship between the new window and the parent allows the
526 // new window to script the parent and vice versa. This is not allowed if
527 // the origins of the two domains are different. This can be treated as a
528 // top level navigation and routed back to the host.
[email protected]180ef242013-11-07 06:50:46529 blink::WebFrame* opener = frame->opener();
[email protected]140a5882013-07-23 19:30:33530 if (!opener)
[email protected]fd3238af2012-05-22 18:55:30531 return true;
[email protected]fd3238af2012-05-22 18:55:30532
533 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
534 return true;
535 }
536 return false;
537}
538
[email protected]180ef242013-11-07 06:50:46539static void NotifyTimezoneChange(blink::WebFrame* frame) {
[email protected]e1907b432013-09-04 16:11:14540 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
[email protected]38761452012-10-18 16:31:59541 v8::Context::Scope context_scope(frame->mainWorldScriptContext());
542 v8::Date::DateTimeConfigurationChangeNotification();
[email protected]180ef242013-11-07 06:50:46543 blink::WebFrame* child = frame->firstChild();
[email protected]38761452012-10-18 16:31:59544 for (; child; child = child->nextSibling())
545 NotifyTimezoneChange(child);
546}
547
[email protected]48861e22013-01-09 00:27:32548static WindowOpenDisposition NavigationPolicyToDisposition(
549 WebNavigationPolicy policy) {
550 switch (policy) {
[email protected]180ef242013-11-07 06:50:46551 case blink::WebNavigationPolicyIgnore:
[email protected]48861e22013-01-09 00:27:32552 return IGNORE_ACTION;
[email protected]180ef242013-11-07 06:50:46553 case blink::WebNavigationPolicyDownload:
[email protected]48861e22013-01-09 00:27:32554 return SAVE_TO_DISK;
[email protected]180ef242013-11-07 06:50:46555 case blink::WebNavigationPolicyCurrentTab:
[email protected]48861e22013-01-09 00:27:32556 return CURRENT_TAB;
[email protected]180ef242013-11-07 06:50:46557 case blink::WebNavigationPolicyNewBackgroundTab:
[email protected]48861e22013-01-09 00:27:32558 return NEW_BACKGROUND_TAB;
[email protected]180ef242013-11-07 06:50:46559 case blink::WebNavigationPolicyNewForegroundTab:
[email protected]48861e22013-01-09 00:27:32560 return NEW_FOREGROUND_TAB;
[email protected]180ef242013-11-07 06:50:46561 case blink::WebNavigationPolicyNewWindow:
[email protected]48861e22013-01-09 00:27:32562 return NEW_WINDOW;
[email protected]180ef242013-11-07 06:50:46563 case blink::WebNavigationPolicyNewPopup:
[email protected]48861e22013-01-09 00:27:32564 return NEW_POPUP;
565 default:
566 NOTREACHED() << "Unexpected WebNavigationPolicy";
567 return IGNORE_ACTION;
568 }
569}
570
[email protected]d8221b22013-05-23 05:35:43571// Returns true if the device scale is high enough that losing subpixel
572// antialiasing won't have a noticeable effect on text quality.
573static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
574#if defined(OS_ANDROID)
575 // On Android, we never have subpixel antialiasing.
576 return true;
577#else
578 return device_scale_factor > 1.5f;
579#endif
580
581}
582
[email protected]fb854192013-02-06 01:30:04583static bool ShouldUseFixedPositionCompositing(float device_scale_factor) {
584 // Compositing for fixed-position elements is dependent on
[email protected]d8221b22013-05-23 05:35:43585 // device_scale_factor if no flag is set. http://crbug.com/172738
[email protected]fb854192013-02-06 01:30:04586 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
587
588 if (command_line.HasSwitch(switches::kDisableCompositingForFixedPosition))
589 return false;
590
591 if (command_line.HasSwitch(switches::kEnableCompositingForFixedPosition))
592 return true;
593
[email protected]d8221b22013-05-23 05:35:43594 return DeviceScaleEnsuresTextQuality(device_scale_factor);
595}
596
[email protected]c162ced82013-06-29 01:24:53597static bool ShouldUseAcceleratedCompositingForOverflowScroll(
598 float device_scale_factor) {
599 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
600
[email protected]7d20c7c2013-10-15 13:55:46601 if (command_line.HasSwitch(switches::kDisableAcceleratedOverflowScroll))
602 return false;
603
[email protected]c162ced82013-06-29 01:24:53604 if (command_line.HasSwitch(switches::kEnableAcceleratedOverflowScroll))
605 return true;
606
607 return DeviceScaleEnsuresTextQuality(device_scale_factor);
608}
609
[email protected]e3415902013-10-17 15:00:46610static bool ShouldUseAcceleratedCompositingForScrollableFrames(
611 float device_scale_factor) {
612 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
613
614 if (command_line.HasSwitch(switches::kDisableAcceleratedScrollableFrames))
615 return false;
616
617 if (command_line.HasSwitch(switches::kEnableAcceleratedScrollableFrames))
618 return true;
619
620 if (!cc::switches::IsLCDTextEnabled())
621 return true;
622
623 return DeviceScaleEnsuresTextQuality(device_scale_factor);
624}
625
626static bool ShouldUseCompositedScrollingForFrames(
627 float device_scale_factor) {
628 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
629
630 if (command_line.HasSwitch(switches::kDisableCompositedScrollingForFrames))
631 return false;
632
633 if (command_line.HasSwitch(switches::kEnableCompositedScrollingForFrames))
634 return true;
635
636 if (!cc::switches::IsLCDTextEnabled())
637 return true;
638
639 return DeviceScaleEnsuresTextQuality(device_scale_factor);
640}
641
[email protected]f388a5d2013-11-04 20:19:13642static bool ShouldUseUniversalAcceleratedCompositingForOverflowScroll() {
[email protected]44de7492013-10-18 15:14:59643 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
644
645 if (command_line.HasSwitch(
646 switches::kDisableUniversalAcceleratedOverflowScroll))
647 return false;
648
649 if (command_line.HasSwitch(
650 switches::kEnableUniversalAcceleratedOverflowScroll))
651 return true;
652
[email protected]f388a5d2013-11-04 20:19:13653 return false;
[email protected]44de7492013-10-18 15:14:59654}
655
[email protected]d8221b22013-05-23 05:35:43656static bool ShouldUseTransitionCompositing(float device_scale_factor) {
657 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
658
659 if (command_line.HasSwitch(switches::kDisableCompositingForTransition))
660 return false;
661
662 if (command_line.HasSwitch(switches::kEnableCompositingForTransition))
[email protected]fb854192013-02-06 01:30:04663 return true;
664
[email protected]9a7f6e12013-06-11 07:05:13665 // TODO(ajuma): Re-enable this by default for high-DPI once the problem
666 // of excessive layer promotion caused by overlap has been addressed.
667 // http://crbug.com/178119.
668 return false;
[email protected]fb854192013-02-06 01:30:04669}
670
[email protected]06fc4d3b2013-07-08 21:07:24671static bool ShouldUseAcceleratedFixedRootBackground(float device_scale_factor) {
672 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
673
674 if (command_line.HasSwitch(switches::kDisableAcceleratedFixedRootBackground))
675 return false;
676
677 if (command_line.HasSwitch(switches::kEnableAcceleratedFixedRootBackground))
678 return true;
679
680 return DeviceScaleEnsuresTextQuality(device_scale_factor);
681}
682
[email protected]180ef242013-11-07 06:50:46683static FaviconURL::IconType ToFaviconType(blink::WebIconURL::Type type) {
[email protected]41225fe2013-03-29 05:32:02684 switch (type) {
[email protected]180ef242013-11-07 06:50:46685 case blink::WebIconURL::TypeFavicon:
[email protected]41225fe2013-03-29 05:32:02686 return FaviconURL::FAVICON;
[email protected]180ef242013-11-07 06:50:46687 case blink::WebIconURL::TypeTouch:
[email protected]41225fe2013-03-29 05:32:02688 return FaviconURL::TOUCH_ICON;
[email protected]180ef242013-11-07 06:50:46689 case blink::WebIconURL::TypeTouchPrecomposed:
[email protected]41225fe2013-03-29 05:32:02690 return FaviconURL::TOUCH_PRECOMPOSED_ICON;
[email protected]180ef242013-11-07 06:50:46691 case blink::WebIconURL::TypeInvalid:
[email protected]41225fe2013-03-29 05:32:02692 return FaviconURL::INVALID_ICON;
693 }
694 return FaviconURL::INVALID_ICON;
695}
696
initial.commit09911bf2008-07-26 23:55:29697///////////////////////////////////////////////////////////////////////////////
698
[email protected]310ebd6302011-10-10 19:06:28699struct RenderViewImpl::PendingFileChooser {
[email protected]e9ff79c2012-10-19 21:31:26700 PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c)
[email protected]cdaf8d02010-03-30 19:52:47701 : params(p),
702 completion(c) {
703 }
[email protected]e9ff79c2012-10-19 21:31:26704 FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47705 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
706};
707
[email protected]217690d2012-01-27 07:33:11708namespace {
709
710class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
711 public:
[email protected]180ef242013-11-07 06:50:46712 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
[email protected]217690d2012-01-27 07:33:11713 : webwidget_(webwidget) {}
714
715 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
716 if (succeeded)
717 webwidget_->didAcquirePointerLock();
718 else
719 webwidget_->didNotAcquirePointerLock();
720 }
721
722 virtual void OnMouseLockLost() OVERRIDE {
723 webwidget_->didLosePointerLock();
724 }
725
726 virtual bool HandleMouseLockedInputEvent(
[email protected]180ef242013-11-07 06:50:46727 const blink::WebMouseEvent &event) OVERRIDE {
[email protected]217690d2012-01-27 07:33:11728 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
729 return false;
730 }
731
732 private:
[email protected]180ef242013-11-07 06:50:46733 blink::WebWidget* webwidget_;
[email protected]217690d2012-01-27 07:33:11734};
735
[email protected]86cd9472012-02-03 19:51:05736int64 ExtractPostId(const WebHistoryItem& item) {
737 if (item.isNull())
738 return -1;
739
740 if (item.httpBody().isNull())
741 return -1;
742
743 return item.httpBody().identifier();
744}
745
[email protected]41225fe2013-03-29 05:32:02746bool TouchEnabled() {
747// Based on the definition of chrome::kEnableTouchIcon.
748#if defined(OS_ANDROID)
749 return true;
750#else
751 return false;
752#endif
753}
754
[email protected]dc293a72013-07-01 11:11:22755WebDragData DropDataToWebDragData(const DropData& drop_data) {
[email protected]c10680312013-05-31 15:22:05756 std::vector<WebDragData::Item> item_list;
757
758 // These fields are currently unused when dragging into WebKit.
759 DCHECK(drop_data.download_metadata.empty());
760 DCHECK(drop_data.file_contents.empty());
761 DCHECK(drop_data.file_description_filename.empty());
762
763 if (!drop_data.text.is_null()) {
764 WebDragData::Item item;
765 item.storageType = WebDragData::Item::StorageTypeString;
766 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText);
767 item.stringData = drop_data.text.string();
768 item_list.push_back(item);
769 }
770
771 // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it
772 // meaningful to write an empty URL to the clipboard?
773 if (!drop_data.url.is_empty()) {
774 WebDragData::Item item;
775 item.storageType = WebDragData::Item::StorageTypeString;
776 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList);
777 item.stringData = WebString::fromUTF8(drop_data.url.spec());
778 item.title = drop_data.url_title;
779 item_list.push_back(item);
780 }
781
782 if (!drop_data.html.is_null()) {
783 WebDragData::Item item;
784 item.storageType = WebDragData::Item::StorageTypeString;
785 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML);
786 item.stringData = drop_data.html.string();
787 item.baseURL = drop_data.html_base_url;
788 item_list.push_back(item);
789 }
790
[email protected]dc293a72013-07-01 11:11:22791 for (std::vector<DropData::FileInfo>::const_iterator it =
[email protected]c10680312013-05-31 15:22:05792 drop_data.filenames.begin();
793 it != drop_data.filenames.end();
794 ++it) {
795 WebDragData::Item item;
796 item.storageType = WebDragData::Item::StorageTypeFilename;
[email protected]ef1bbf632013-10-24 22:54:08797 item.filenameData = it->path;
[email protected]c10680312013-05-31 15:22:05798 item.displayNameData = it->display_name;
799 item_list.push_back(item);
800 }
801
802 for (std::map<base::string16, base::string16>::const_iterator it =
803 drop_data.custom_data.begin();
804 it != drop_data.custom_data.end();
805 ++it) {
806 WebDragData::Item item;
807 item.storageType = WebDragData::Item::StorageTypeString;
808 item.stringType = it->first;
809 item.stringData = it->second;
810 item_list.push_back(item);
811 }
812
813 WebDragData result;
814 result.initialize();
815 result.setItems(item_list);
816 result.setFilesystemId(drop_data.filesystem_id);
817 return result;
818}
819
[email protected]217690d2012-01-27 07:33:11820} // namespace
821
[email protected]8d41d7612012-11-14 20:32:19822RenderViewImpl::RenderViewImpl(RenderViewImplParams* params)
[email protected]180ef242013-11-07 06:50:46823 : RenderWidget(blink::WebPopupTypeNone,
[email protected]8d41d7612012-11-14 20:32:19824 params->screen_info,
[email protected]1ac10dca2013-08-20 20:47:04825 params->swapped_out,
826 params->hidden),
[email protected]8d41d7612012-11-14 20:32:19827 webkit_preferences_(params->webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02828 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09829 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02830 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24831 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21832 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02833 opened_by_user_gesture_(true),
834 opener_suppressed_(false),
[email protected]88f10a22013-11-06 21:22:12835 suppress_dialogs_until_swap_out_(false),
[email protected]81a34412009-01-05 19:17:24836 page_id_(-1),
837 last_page_id_sent_to_browser_(-1),
[email protected]8d41d7612012-11-14 20:32:19838 next_page_id_(params->next_page_id),
[email protected]3cc72b12010-03-18 23:03:00839 history_list_offset_(-1),
840 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02841 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55842 selection_text_offset_(0),
[email protected]db4fc1e2013-09-06 20:01:51843 selection_range_(gfx::Range::InvalidRange()),
[email protected]bbc8856d2013-06-14 10:37:04844#if defined(OS_ANDROID)
845 top_controls_constraints_(cc::BOTH),
846#endif
[email protected]dd6afca2011-08-13 03:44:31847 cached_is_main_frame_pinned_to_left_(false),
848 cached_is_main_frame_pinned_to_right_(false),
849 cached_has_main_frame_horizontal_scrollbar_(false),
850 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]69e797f2013-04-30 01:10:22851 cookie_jar_(this),
[email protected]8a67aa352013-02-20 02:58:29852 notification_provider_(NULL),
[email protected]676126f72011-01-15 00:03:51853 geolocation_dispatcher_(NULL),
[email protected]c52b2892012-03-07 11:01:02854 input_tag_speech_dispatcher_(NULL),
[email protected]64d09222012-05-25 10:10:34855 speech_recognition_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51856 media_stream_dispatcher_(NULL),
[email protected]fb325d122012-11-20 23:58:05857 browser_plugin_manager_(NULL),
[email protected]c3bdce152013-07-10 04:56:34858 media_stream_client_(NULL),
859 web_user_media_client_(NULL),
[email protected]f39b9d52013-07-28 08:03:44860 midi_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41861 devtools_agent_(NULL),
[email protected]2a84f9d2012-06-05 21:50:43862 accessibility_mode_(AccessibilityModeOff),
[email protected]063afcb2011-09-29 07:54:32863 renderer_accessibility_(NULL),
[email protected]217690d2012-01-27 07:33:11864 mouse_lock_dispatcher_(NULL),
[email protected]20657a82012-08-21 20:23:03865#if defined(OS_ANDROID)
[email protected]4d0f8182012-10-19 23:14:47866 body_background_color_(SK_ColorWHITE),
[email protected]20657a82012-08-21 20:23:03867 expected_content_intent_id_(0),
[email protected]305ecfc72013-10-31 00:35:48868 media_player_manager_(NULL),
[email protected]a7564272013-04-19 14:24:46869#endif
870#if defined(OS_WIN)
871 focused_plugin_id_(-1),
872#endif
[email protected]ea2fb972013-08-07 05:44:26873#if defined(ENABLE_PLUGINS)
874 focused_pepper_plugin_(NULL),
875 pepper_last_mouse_event_target_(NULL),
876#endif
[email protected]8a67aa352013-02-20 02:58:29877 enumeration_completion_id_(0),
[email protected]69e797f2013-04-30 01:10:22878 load_progress_tracker_(new LoadProgressTracker(this)),
[email protected]8d41d7612012-11-14 20:32:19879 session_storage_namespace_id_(params->session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18880 handling_select_range_(false),
[email protected]c9bc8f12012-12-15 22:20:09881 next_snapshot_id_(0),
[email protected]f56c7872013-06-18 12:31:57882 allow_partial_swap_(params->allow_partial_swap),
[email protected]07fb8d52013-08-07 17:03:51883 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) {
[email protected]075366912013-02-18 07:13:24884}
885
886void RenderViewImpl::Initialize(RenderViewImplParams* params) {
[email protected]8d41d7612012-11-14 20:32:19887 routing_id_ = params->routing_id;
888 surface_id_ = params->surface_id;
889 if (params->opener_id != MSG_ROUTING_NONE && params->is_renderer_created)
890 opener_id_ = params->opener_id;
[email protected]676126f72011-01-15 00:03:51891
[email protected]74ce1ad2011-12-16 21:51:46892 // Ensure we start with a valid next_page_id_ from the browser.
893 DCHECK_GE(next_page_id_, 0);
894
[email protected]21b3a6ae2011-11-30 00:45:29895#if defined(ENABLE_NOTIFICATIONS)
896 notification_provider_ = new NotificationProvider(this);
897#else
898 notification_provider_ = NULL;
899#endif
900
[email protected]11fee2332011-03-29 20:36:35901 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11902 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35903
[email protected]20657a82012-08-21 20:23:03904 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
905
[email protected]27c521a2013-05-29 20:44:32906 if (command_line.HasSwitch(switches::kStatsCollectionController))
907 stats_collection_observer_.reset(new StatsCollectionObserver(this));
908
[email protected]20657a82012-08-21 20:23:03909#if defined(OS_ANDROID)
[email protected]276e8a322013-01-24 01:50:11910 content::DeviceTelephonyInfo device_info;
[email protected]20657a82012-08-21 20:23:03911
912 const std::string region_code =
913 command_line.HasSwitch(switches::kNetworkCountryIso)
914 ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso)
[email protected]276e8a322013-01-24 01:50:11915 : device_info.GetNetworkCountryIso();
[email protected]20657a82012-08-21 20:23:03916 content_detectors_.push_back(linked_ptr<ContentDetector>(
917 new AddressDetector()));
918 content_detectors_.push_back(linked_ptr<ContentDetector>(
919 new PhoneNumberDetector(region_code)));
920 content_detectors_.push_back(linked_ptr<ContentDetector>(
921 new EmailDetector()));
922#endif
923
[email protected]380244092011-10-07 17:26:27924 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51925 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47926 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51927 AddRef();
[email protected]1ac10dca2013-08-20 20:47:04928 if (is_hidden_)
929 RenderThread::Get()->WidgetHidden();
[email protected]676126f72011-01-15 00:03:51930
931 // If this is a popup, we must wait for the CreatingNew_ACK message before
932 // completing initialization. Otherwise, we can finish it now.
[email protected]6cd7c6b2012-10-25 03:26:23933 if (opener_id_ == MSG_ROUTING_NONE) {
[email protected]676126f72011-01-15 00:03:51934 did_show_ = true;
[email protected]fc4404d2012-11-07 19:53:30935 CompleteInit();
[email protected]676126f72011-01-15 00:03:51936 }
937
[email protected]34c61bd52011-05-02 19:38:33938 g_view_map.Get().insert(std::make_pair(webview(), this));
[email protected]058561b2012-12-03 06:48:22939 g_routing_id_view_map.Get().insert(std::make_pair(routing_id_, this));
[email protected]60051ec2012-06-08 22:40:57940 webview()->setDeviceScaleFactor(device_scale_factor_);
[email protected]fb854192013-02-06 01:30:04941 webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled(
942 ShouldUseFixedPositionCompositing(device_scale_factor_));
[email protected]c162ced82013-06-29 01:24:53943 webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled(
944 ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_));
[email protected]44de7492013-10-18 15:14:59945 webview()->settings()->setCompositorDrivenAcceleratedScrollingEnabled(
[email protected]f388a5d2013-11-04 20:19:13946 ShouldUseUniversalAcceleratedCompositingForOverflowScroll());
[email protected]d8221b22013-05-23 05:35:43947 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
948 ShouldUseTransitionCompositing(device_scale_factor_));
[email protected]06fc4d3b2013-07-08 21:07:24949 webview()->settings()->setAcceleratedCompositingForFixedRootBackgroundEnabled(
950 ShouldUseAcceleratedFixedRootBackground(device_scale_factor_));
[email protected]e3415902013-10-17 15:00:46951 webview()->settings()->setAcceleratedCompositingForScrollableFramesEnabled(
952 ShouldUseAcceleratedCompositingForScrollableFrames(device_scale_factor_));
953 webview()->settings()->setCompositedScrollingForFramesEnabled(
954 ShouldUseCompositedScrollingForFrames(device_scale_factor_));
[email protected]fb854192013-02-06 01:30:04955
[email protected]49a20002013-08-18 12:43:31956 ApplyWebPreferences(webkit_preferences_, webview());
[email protected]9b159a52013-10-03 17:24:55957
958 main_render_frame_.reset(
959 RenderFrameImpl::Create(this, params->main_frame_routing_id));
960 // The main frame WebFrame object is closed by
961 // RenderViewImpl::frameDetached().
962 webview()->setMainFrame(WebFrame::create(main_render_frame_.get()));
[email protected]edbea622012-11-28 20:39:38963
[email protected]1400e6dc2013-04-27 02:36:27964 if (switches::IsTouchDragDropEnabled())
[email protected]edbea622012-11-28 20:39:38965 webview()->settings()->setTouchDragDropEnabled(true);
966
[email protected]1400e6dc2013-04-27 02:36:27967 if (switches::IsTouchEditingEnabled())
[email protected]47822262013-04-23 17:22:36968 webview()->settings()->setTouchEditingEnabled(true);
969
[email protected]8d41d7612012-11-14 20:32:19970 if (!params->frame_name.empty())
971 webview()->mainFrame()->setName(params->frame_name);
[email protected]34c61bd52011-05-02 19:38:33972
[email protected]8d41d7612012-11-14 20:32:19973 OnSetRendererPrefs(params->renderer_prefs);
[email protected]34c61bd52011-05-02 19:38:33974
[email protected]4fb0f202012-05-30 22:44:53975#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02976 if (!media_stream_dispatcher_)
977 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32978#endif
[email protected]735873d2012-01-25 23:31:02979
[email protected]8f6a3b852011-07-19 16:48:56980 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32981#if defined(OS_MACOSX)
982 new TextInputClientObserver(this);
983#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56984
[email protected]503fa032013-10-27 19:34:40985 new SharedWorkerRepository(this);
986
[email protected]2d7b82c2012-06-01 05:57:50987#if defined(OS_ANDROID)
[email protected]305ecfc72013-10-31 00:35:48988 media_player_manager_ = new RendererMediaPlayerManager(this);
[email protected]a794f3a2013-10-30 17:00:32989 new JavaBridgeDispatcher(this);
[email protected]2d7b82c2012-06-01 05:57:50990#endif
991
[email protected]217690d2012-01-27 07:33:11992 // The next group of objects all implement RenderViewObserver, so are deleted
993 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41994 devtools_agent_ = new DevToolsAgent(this);
[email protected]6e89eb72013-07-23 13:28:22995 if (RenderWidgetCompositor* rwc = compositor()) {
996 webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId());
997 }
[email protected]89054502012-06-03 10:29:24998 mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
[email protected]41225fe2013-03-29 05:32:02999 new ImageLoadingHelper(this);
[email protected]063afcb2011-09-29 07:54:321000
[email protected]2a84f9d2012-06-05 21:50:431001 // Create renderer_accessibility_ if needed.
[email protected]8d41d7612012-11-14 20:32:191002 OnSetAccessibilityMode(params->accessibility_mode);
[email protected]2a84f9d2012-06-05 21:50:431003
[email protected]1784b2f2011-11-24 10:53:481004 new IdleUserDetector(this);
1005
[email protected]766a7082012-02-03 23:39:151006 if (command_line.HasSwitch(switches::kDomAutomationController))
[email protected]e9ff79c2012-10-19 21:31:261007 enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION;
[email protected]27c521a2013-05-29 20:44:321008 if (command_line.HasSwitch(switches::kStatsCollectionController))
1009 enabled_bindings_ |= BINDINGS_POLICY_STATS_COLLECTION;
[email protected]766a7082012-02-03 23:39:151010
[email protected]5b52cd2f712012-03-28 02:12:481011 ProcessViewLayoutFlags(command_line);
[email protected]7ddea9802012-02-22 23:08:051012
[email protected]b9bad122013-07-29 20:32:331013#if defined(ENABLE_PLUGINS)
[email protected]ea2fb972013-08-07 05:44:261014 new PepperBrowserConnection(this);
[email protected]b9bad122013-07-29 20:32:331015#endif
1016
[email protected]e9ff79c2012-10-19 21:31:261017 GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:441018
1019 // If we have an opener_id but we weren't created by a renderer, then
1020 // it's the browser asking us to set our opener to another RenderView.
[email protected]8d41d7612012-11-14 20:32:191021 if (params->opener_id != MSG_ROUTING_NONE && !params->is_renderer_created) {
1022 RenderViewImpl* opener_view = FromRoutingID(params->opener_id);
[email protected]f546640b2012-05-15 00:03:491023 if (opener_view)
1024 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
[email protected]14392a52012-05-02 20:28:441025 }
1026
1027 // If we are initially swapped out, navigate to kSwappedOutURL.
1028 // This ensures we are in a unique origin that others cannot script.
1029 if (is_swapped_out_)
[email protected]0720b532012-08-28 19:23:371030 NavigateToSwappedOutURL(webview()->mainFrame());
initial.commit09911bf2008-07-26 23:55:291031}
1032
[email protected]310ebd6302011-10-10 19:06:281033RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:031034 history_page_ids_.clear();
1035
[email protected]91a2aea2013-07-08 23:14:391036 base::debug::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_);
1037
[email protected]a1128322009-10-06 18:38:461038 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:471039 while (!file_chooser_completions_.empty()) {
1040 if (file_chooser_completions_.front()->completion) {
1041 file_chooser_completions_.front()->completion->didChooseFile(
1042 WebVector<WebString>());
1043 }
1044 file_chooser_completions_.pop_front();
1045 }
[email protected]a1128322009-10-06 18:38:461046
[email protected]8ed1d3f2013-02-20 11:45:551047#if defined(OS_ANDROID)
1048 // The date/time picker client is both a scoped_ptr member of this class and
1049 // a RenderViewObserver. Reset it to prevent double deletion.
1050 date_time_picker_client_.reset();
1051#endif
1052
[email protected]60c42a8c72009-10-09 04:08:591053#ifndef NDEBUG
[email protected]058561b2012-12-03 06:48:221054 // Make sure we are no longer referenced by the ViewMap or RoutingIDViewMap.
[email protected]625332e02010-12-14 07:48:491055 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:591056 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
1057 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]058561b2012-12-03 06:48:221058 RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
1059 for (RoutingIDViewMap::iterator it = routing_id_views->begin();
1060 it != routing_id_views->end(); ++it)
1061 DCHECK_NE(this, it->second) << "Failed to call Close?";
[email protected]60c42a8c72009-10-09 04:08:591062#endif
[email protected]676126f72011-01-15 00:03:511063
[email protected]310ebd6302011-10-10 19:06:281064 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:511065 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:591066}
1067
1068/*static*/
[email protected]310ebd6302011-10-10 19:06:281069RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:311070 ViewMap* views = g_view_map.Pointer();
1071 ViewMap::iterator it = views->find(webview);
1072 return it == views->end() ? NULL : it->second;
1073}
1074
1075/*static*/
[email protected]180ef242013-11-07 06:50:461076RenderView* RenderView::FromWebView(blink::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:281077 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:311078}
1079
1080/*static*/
[email protected]640e303c2012-12-05 01:36:071081RenderViewImpl* RenderViewImpl::FromRoutingID(int32 routing_id) {
1082 RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
1083 RoutingIDViewMap::iterator it = views->find(routing_id);
1084 return it == views->end() ? NULL : it->second;
1085}
1086
1087/*static*/
1088RenderView* RenderView::FromRoutingID(int routing_id) {
1089 return RenderViewImpl::FromRoutingID(routing_id);
1090}
1091
1092/*static*/
[email protected]e9ff79c2012-10-19 21:31:261093void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:491094 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:591095 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
1096 if (!visitor->Visit(it->second))
1097 return;
1098 }
1099}
1100
1101/*static*/
[email protected]310ebd6302011-10-10 19:06:281102RenderViewImpl* RenderViewImpl::Create(
[email protected]0aa55312008-10-17 21:53:081103 int32 opener_id,
[email protected]e9ff79c2012-10-19 21:31:261104 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:081105 const WebPreferences& webkit_prefs,
[email protected]4e6419c2010-01-15 04:50:341106 int32 routing_id,
[email protected]227692c52013-05-31 22:43:041107 int32 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:561108 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:261109 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461110 const string16& frame_name,
[email protected]14392a52012-05-02 20:28:441111 bool is_renderer_created,
1112 bool swapped_out,
[email protected]1ac10dca2013-08-20 20:47:041113 bool hidden,
[email protected]6fd35b72012-03-01 19:46:411114 int32 next_page_id,
[email protected]180ef242013-11-07 06:50:461115 const blink::WebScreenInfo& screen_info,
[email protected]34bb3ac2013-03-08 02:41:281116 AccessibilityMode accessibility_mode,
1117 bool allow_partial_swap) {
initial.commit09911bf2008-07-26 23:55:291118 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]8d41d7612012-11-14 20:32:191119 RenderViewImplParams params(
[email protected]676126f72011-01-15 00:03:511120 opener_id,
1121 renderer_prefs,
1122 webkit_prefs,
[email protected]676126f72011-01-15 00:03:511123 routing_id,
[email protected]227692c52013-05-31 22:43:041124 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:561125 surface_id,
[email protected]676126f72011-01-15 00:03:511126 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461127 frame_name,
[email protected]14392a52012-05-02 20:28:441128 is_renderer_created,
1129 swapped_out,
[email protected]1ac10dca2013-08-20 20:47:041130 hidden,
[email protected]6fd35b72012-03-01 19:46:411131 next_page_id,
[email protected]842f10652012-06-06 01:54:041132 screen_info,
[email protected]34bb3ac2013-03-08 02:41:281133 accessibility_mode,
1134 allow_partial_swap);
[email protected]075366912013-02-18 07:13:241135 RenderViewImpl* render_view = NULL;
[email protected]8d41d7612012-11-14 20:32:191136 if (g_create_render_view_impl)
[email protected]075366912013-02-18 07:13:241137 render_view = g_create_render_view_impl(&params);
1138 else
1139 render_view = new RenderViewImpl(&params);
1140 render_view->Initialize(&params);
1141 return render_view;
[email protected]8d41d7612012-11-14 20:32:191142}
1143
1144// static
1145void RenderViewImpl::InstallCreateHook(
1146 RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*)) {
1147 CHECK(!g_create_render_view_impl);
1148 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:291149}
1150
[email protected]310ebd6302011-10-10 19:06:281151void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:511152 observers_.AddObserver(observer);
1153}
1154
[email protected]310ebd6302011-10-10 19:06:281155void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
1156 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:511157 observers_.RemoveObserver(observer);
1158}
1159
[email protected]180ef242013-11-07 06:50:461160blink::WebView* RenderViewImpl::webview() const {
1161 return static_cast<blink::WebView*>(webwidget());
[email protected]4d51d5bf2010-07-26 18:48:261162}
1163
[email protected]ea2fb972013-08-07 05:44:261164#if defined(ENABLE_PLUGINS)
1165void RenderViewImpl::PepperInstanceCreated(PepperPluginInstanceImpl* instance) {
1166 active_pepper_instances_.insert(instance);
1167}
1168
1169void RenderViewImpl::PepperInstanceDeleted(PepperPluginInstanceImpl* instance) {
1170 active_pepper_instances_.erase(instance);
1171
1172 if (pepper_last_mouse_event_target_ == instance)
1173 pepper_last_mouse_event_target_ = NULL;
1174 if (focused_pepper_plugin_ == instance)
1175 PepperFocusChanged(instance, false);
1176}
1177
1178void RenderViewImpl::PepperDidChangeCursor(
1179 PepperPluginInstanceImpl* instance,
[email protected]180ef242013-11-07 06:50:461180 const blink::WebCursorInfo& cursor) {
[email protected]ea2fb972013-08-07 05:44:261181 // Update the cursor appearance immediately if the requesting plugin is the
1182 // one which receives the last mouse event. Otherwise, the new cursor won't be
1183 // picked up until the plugin gets the next input event. That is bad if, e.g.,
1184 // the plugin would like to set an invisible cursor when there isn't any user
1185 // input for a while.
1186 if (instance == pepper_last_mouse_event_target_)
1187 didChangeCursor(cursor);
1188}
1189
1190void RenderViewImpl::PepperDidReceiveMouseEvent(
1191 PepperPluginInstanceImpl* instance) {
1192 pepper_last_mouse_event_target_ = instance;
1193}
1194
1195void RenderViewImpl::PepperFocusChanged(PepperPluginInstanceImpl* instance,
1196 bool focused) {
1197 if (focused)
1198 focused_pepper_plugin_ = instance;
1199 else if (focused_pepper_plugin_ == instance)
1200 focused_pepper_plugin_ = NULL;
1201
1202 UpdateTextInputType();
1203 UpdateSelectionBounds();
1204}
1205
1206void RenderViewImpl::PepperTextInputTypeChanged(
1207 PepperPluginInstanceImpl* instance) {
1208 if (instance != focused_pepper_plugin_)
1209 return;
1210
1211 UpdateTextInputType();
1212 if (renderer_accessibility_)
1213 renderer_accessibility_->FocusedNodeChanged(WebNode());
1214}
1215
1216void RenderViewImpl::PepperCaretPositionChanged(
1217 PepperPluginInstanceImpl* instance) {
1218 if (instance != focused_pepper_plugin_)
1219 return;
1220 UpdateSelectionBounds();
1221}
1222
1223void RenderViewImpl::PepperCancelComposition(
1224 PepperPluginInstanceImpl* instance) {
1225 if (instance != focused_pepper_plugin_)
1226 return;
1227 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));;
1228#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
1229 UpdateCompositionInfo(true);
1230#endif
1231}
1232
1233void RenderViewImpl::PepperSelectionChanged(
1234 PepperPluginInstanceImpl* instance) {
1235 if (instance != focused_pepper_plugin_)
1236 return;
1237 SyncSelectionIfRequired();
1238}
1239
1240RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
1241 PepperPluginInstanceImpl* plugin) {
1242 GURL active_url;
1243 if (webview() && webview()->mainFrame())
1244 active_url = GURL(webview()->mainFrame()->document().url());
1245 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
1246 routing_id_, plugin, active_url, screen_info_);
[email protected]180ef242013-11-07 06:50:461247 widget->show(blink::WebNavigationPolicyIgnore);
[email protected]ea2fb972013-08-07 05:44:261248 return widget;
1249}
1250
1251void RenderViewImpl::PepperPluginCreated(RendererPpapiHost* host) {
1252 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
1253 DidCreatePepperPlugin(host));
1254}
1255
1256bool RenderViewImpl::GetPepperCaretBounds(gfx::Rect* rect) {
1257 if (!focused_pepper_plugin_)
1258 return false;
1259 *rect = focused_pepper_plugin_->GetCaretBounds();
1260 return true;
1261}
1262
1263bool RenderViewImpl::IsPepperAcceptingCompositionEvents() const {
1264 if (!focused_pepper_plugin_)
1265 return false;
1266 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
1267}
1268
[email protected]c42de732013-02-16 06:26:311269void RenderViewImpl::PluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:421270 base::ProcessId plugin_pid) {
1271 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path, plugin_pid));
initial.commit09911bf2008-07-26 23:55:291272}
1273
[email protected]310ebd6302011-10-10 19:06:281274void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:261275 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:301276 // If the renderer is visible, set initial visibility and focus state.
1277 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:341278#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:301279 delegate->SetContainerVisibility(true);
1280 if (webview() && webview()->isActive())
1281 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:341282#endif
[email protected]49232292010-09-03 19:07:301283 }
[email protected]784ea1ab2010-09-18 00:02:341284 // Plugins start assuming the content has focus (so that they work in
1285 // environments where RenderView isn't hosting them), so we always have to
1286 // set the initial state. See webplugin_delegate_impl.h for details.
1287 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:261288}
1289
[email protected]310ebd6302011-10-10 19:06:281290void RenderViewImpl::UnregisterPluginDelegate(
1291 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:261292 plugin_delegates_.erase(delegate);
1293}
[email protected]d8fd6fa2010-02-01 15:54:261294
[email protected]310ebd6302011-10-10 19:06:281295bool RenderViewImpl::GetPluginInfo(const GURL& url,
1296 const GURL& page_url,
1297 const std::string& mime_type,
[email protected]d7bd3e52013-07-21 04:29:201298 WebPluginInfo* plugin_info,
[email protected]310ebd6302011-10-10 19:06:281299 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:081300 bool found = false;
1301 Send(new ViewHostMsg_GetPluginInfo(
1302 routing_id_, url, page_url, mime_type, &found, plugin_info,
1303 actual_mime_type));
1304 return found;
1305}
1306
[email protected]a80af12e2013-08-07 23:36:131307void RenderViewImpl::SimulateImeSetComposition(
1308 const string16& text,
[email protected]180ef242013-11-07 06:50:461309 const std::vector<blink::WebCompositionUnderline>& underlines,
[email protected]a80af12e2013-08-07 23:36:131310 int selection_start,
1311 int selection_end) {
1312 OnImeSetComposition(text, underlines, selection_start, selection_end);
1313}
1314
1315void RenderViewImpl::SimulateImeConfirmComposition(
1316 const string16& text,
[email protected]db4fc1e2013-09-06 20:01:511317 const gfx::Range& replacement_range) {
[email protected]a80af12e2013-08-07 23:36:131318 OnImeConfirmComposition(text, replacement_range, false);
1319}
1320
1321#if defined(OS_WIN)
1322void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
1323 if (focused)
1324 focused_plugin_id_ = plugin_id;
1325 else
1326 focused_plugin_id_ = -1;
1327}
1328#endif
1329
1330#if defined(OS_MACOSX)
1331void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
1332 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
1333}
1334
1335void RenderViewImpl::StartPluginIme() {
1336 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
1337 // This message can be sent during event-handling, and needs to be delivered
1338 // within that context.
1339 msg->set_unblock(true);
1340 Send(msg);
1341}
1342#endif // defined(OS_MACOSX)
1343
1344#endif // ENABLE_PLUGINS
1345
[email protected]7a1ec28a2012-03-28 21:10:241346void RenderViewImpl::TransferActiveWheelFlingAnimation(
[email protected]180ef242013-11-07 06:50:461347 const blink::WebActiveWheelFlingParameters& params) {
[email protected]7a1ec28a2012-03-28 21:10:241348 if (webview())
1349 webview()->transferActiveWheelFlingAnimation(params);
1350}
1351
[email protected]8fe8f742012-06-14 00:36:081352bool RenderViewImpl::HasIMETextFocus() {
1353 return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
1354}
1355
[email protected]310ebd6302011-10-10 19:06:281356bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:271357 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:271358 if (main_frame)
[email protected]e9ff79c2012-10-19 21:31:261359 GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:261360
[email protected]676126f72011-01-15 00:03:511361 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
1362 RenderViewObserver* observer;
1363 while ((observer = it.GetNext()) != NULL)
1364 if (observer->OnMessageReceived(message))
1365 return true;
[email protected]b2abac72009-02-26 12:39:281366
[email protected]a95986a82010-12-24 06:19:281367 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:401368 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:281369 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
[email protected]c084330e02013-04-27 01:08:151370 IPC_MESSAGE_HANDLER(InputMsg_Copy, OnCopy)
1371 IPC_MESSAGE_HANDLER(InputMsg_Cut, OnCut)
1372 IPC_MESSAGE_HANDLER(InputMsg_Delete, OnDelete)
1373 IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand)
1374 IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret)
1375 IPC_MESSAGE_HANDLER(InputMsg_Paste, OnPaste)
1376 IPC_MESSAGE_HANDLER(InputMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
1377 IPC_MESSAGE_HANDLER(InputMsg_Redo, OnRedo)
1378 IPC_MESSAGE_HANDLER(InputMsg_Replace, OnReplace)
1379 IPC_MESSAGE_HANDLER(InputMsg_ReplaceMisspelling, OnReplaceMisspelling)
1380 IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect,
1381 OnScrollFocusedEditableNodeIntoRect)
1382 IPC_MESSAGE_HANDLER(InputMsg_SelectAll, OnSelectAll)
1383 IPC_MESSAGE_HANDLER(InputMsg_SelectRange, OnSelectRange)
1384 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
1385 OnSetEditCommandsForNextKeyEvent)
1386 IPC_MESSAGE_HANDLER(InputMsg_Undo, OnUndo)
1387 IPC_MESSAGE_HANDLER(InputMsg_Unselect, OnUnselect)
initial.commit09911bf2008-07-26 23:55:291388 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
1389 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:561390 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
[email protected]25bcc8f2013-01-09 02:49:251391 IPC_MESSAGE_HANDLER(ViewMsg_SetName, OnSetName)
[email protected]45a599062012-09-07 20:09:061392 IPC_MESSAGE_HANDLER(ViewMsg_SetEditableSelectionOffsets,
1393 OnSetEditableSelectionOffsets)
1394 IPC_MESSAGE_HANDLER(ViewMsg_SetCompositionFromExistingText,
1395 OnSetCompositionFromExistingText)
1396 IPC_MESSAGE_HANDLER(ViewMsg_ExtendSelectionAndDelete,
1397 OnExtendSelectionAndDelete)
initial.commit09911bf2008-07-26 23:55:291398 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
1399 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:491400 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
[email protected]630e26b2008-10-14 22:55:171401 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:171402 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:411403 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:541404 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1405 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:291406 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:181407 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1408 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:291409 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]f546640b2012-05-15 00:03:491410 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
[email protected]1810e132009-03-24 23:35:481411 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:551412 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
1413 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
1414 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
1415 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
1416 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
1417 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
1418 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:451419 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:291420 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:291421 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1422 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]38761452012-10-18 16:31:591423 IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone)
initial.commit09911bf2008-07-26 23:55:291424 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:511425 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
1426 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:291427 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:041428 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]88f10a22013-11-06 21:22:121429 IPC_MESSAGE_HANDLER(ViewMsg_SuppressDialogsUntilSwapOut,
1430 OnSuppressDialogsUntilSwapOut)
[email protected]992db4c2011-05-12 15:37:151431 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:291432 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1433 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]30f75e62009-02-25 22:01:001434 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:161435 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:141436 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:251437 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1438 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:471439 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:341440 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:101441 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1442 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511443 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:561444 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]77829642012-05-15 14:47:171445 IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent,
1446 OnOrientationChangeEvent)
[email protected]81375e872012-01-11 21:40:361447 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:341448 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]a0c7153e2009-12-09 14:36:331449 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
1450 OnCustomContextMenuAction)
[email protected]18d5be92011-07-25 18:00:191451 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1452 OnGetAllSavableResourceLinksForCurrentPage)
1453 IPC_MESSAGE_HANDLER(
1454 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1455 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]521b2482011-01-15 00:10:101456 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]47822262013-04-23 17:22:361457 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
[email protected]f0557932011-01-25 20:20:511458 // TODO(viettrungluu): Move to a separate message filter.
[email protected]9e1ad4b2011-08-14 16:49:191459 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
1460 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:181461 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]2a84f9d2012-06-05 21:50:431462 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode)
[email protected]7cc78902012-12-06 02:32:261463 IPC_MESSAGE_HANDLER(ViewMsg_DisownOpener, OnDisownOpener)
[email protected]a794f3a2013-10-30 17:00:321464 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB,
1465 OnReleaseDisambiguationPopupDIB)
1466 IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted,
1467 OnWindowSnapshotCompleted)
[email protected]55750b32012-09-21 14:05:031468#if defined(OS_ANDROID)
[email protected]c084330e02013-04-27 01:08:151469 IPC_MESSAGE_HANDLER(InputMsg_ActivateNearestFindResult,
[email protected]55750b32012-09-21 14:05:031470 OnActivateNearestFindResult)
1471 IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects)
1472 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
[email protected]9b7d11e2012-10-08 19:24:141473 IPC_MESSAGE_HANDLER(ViewMsg_UndoScrollFocusedEditableNodeIntoView,
1474 OnUndoScrollFocusedEditableNodeIntoRect)
[email protected]452b4a92013-03-28 21:24:381475 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState,
1476 OnUpdateTopControlsState)
[email protected]68877c282013-09-20 05:52:421477 IPC_MESSAGE_HANDLER(ViewMsg_PauseVideo, OnPauseVideo)
[email protected]55750b32012-09-21 14:05:031478#elif defined(OS_MACOSX)
[email protected]c084330e02013-04-27 01:08:151479 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]55750b32012-09-21 14:05:031480 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1481 OnPluginImeCompositionCompleted)
1482 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1483 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
1484 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
1485 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
1486#endif
[email protected]a794f3a2013-10-30 17:00:321487 // Adding a new message? Add platform independent ones first, then put the
1488 // platform specific ones at the end.
[email protected]9e1ad4b2011-08-14 16:49:191489
initial.commit09911bf2008-07-26 23:55:291490 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281491 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291492 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401493
1494 if (!msg_is_ok) {
1495 // The message had a handler, but its deserialization failed.
1496 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:281497 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:401498 }
1499
[email protected]a95986a82010-12-24 06:19:281500 return handled;
initial.commit09911bf2008-07-26 23:55:291501}
1502
[email protected]310ebd6302011-10-10 19:06:281503void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]8bf1048012012-02-08 01:22:181504 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:291505 if (!webview())
1506 return;
1507
[email protected]440a0e52011-09-13 17:38:581508 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
1509
[email protected]007733c2011-11-17 00:34:071510 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:031511
1512 // If this is a stale back/forward (due to a recent navigation the browser
1513 // didn't know about), ignore it.
1514 if (IsBackForwardToStaleEntry(params, is_reload))
1515 return;
1516
[email protected]992db4c2011-05-12 15:37:151517 // Swap this renderer back in if necessary.
[email protected]961541a92012-06-01 21:15:281518 if (is_swapped_out_) {
1519 // We marked the view as hidden when swapping the view out, so be sure to
1520 // reset the visibility state before navigating to the new URL.
1521 webview()->setVisibilityState(visibilityState(), false);
[email protected]890b06ca2012-12-13 21:07:361522
1523 // If this is an attempt to reload while we are swapped out, we should not
1524 // reload swappedout://, but the previous page, which is stored in
1525 // params.state. Setting is_reload to false will treat this like a back
1526 // navigation to accomplish that.
1527 is_reload = false;
1528
[email protected]0b059022013-07-03 22:50:091529 // We refresh timezone when a view is swapped in since timezone
1530 // can get out of sync when the system timezone is updated while
1531 // the view is swapped out.
1532 NotifyTimezoneChange(webview()->mainFrame());
1533
[email protected]992db4c2011-05-12 15:37:151534 SetSwappedOut(false);
[email protected]961541a92012-06-01 21:15:281535 }
[email protected]992db4c2011-05-12 15:37:151536
[email protected]60d6cca2013-04-30 08:47:131537 if (params.should_clear_history_list) {
1538 CHECK_EQ(params.pending_history_list_offset, -1);
1539 CHECK_EQ(params.current_history_list_offset, -1);
1540 CHECK_EQ(params.current_history_list_length, 0);
1541 }
[email protected]3cc72b12010-03-18 23:03:001542 history_list_offset_ = params.current_history_list_offset;
1543 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:031544 if (history_list_length_ >= 0)
1545 history_page_ids_.resize(history_list_length_, -1);
1546 if (params.pending_history_list_offset >= 0 &&
1547 params.pending_history_list_offset < history_list_length_)
1548 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:001549
[email protected]e9ff79c2012-10-19 21:31:261550 GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:291551
[email protected]3027cf02013-01-24 08:16:581552 WebFrame* frame = webview()->mainFrame();
1553 if (!params.frame_to_navigate.empty()) {
1554 frame = webview()->findFrameByName(
1555 WebString::fromUTF8(params.frame_to_navigate));
1556 CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate;
1557 }
1558
1559 if (is_reload && frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291560 // We cannot reload if we do not have any history state. This happens, for
1561 // example, when recovering from a crash. Our workaround here is a bit of
1562 // a hack since it means that reload after a crashed tab does not cause an
1563 // end-to-end cache validation.
1564 is_reload = false;
1565 }
1566
[email protected]3d2fd592012-11-30 02:05:501567 pending_navigation_params_.reset(new ViewMsg_Navigate_Params(params));
[email protected]48a5c772011-04-18 23:50:501568
[email protected]04d3c6e2009-05-22 17:00:131569 // If we are reloading, then WebKit will use the history state of the current
1570 // page, so we should just ignore any given history state. Otherwise, if we
1571 // have history state, then we need to navigate to it, which corresponds to a
1572 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551573 if (is_reload) {
[email protected]7c16976c2012-08-04 02:38:231574 bool reload_original_url =
1575 (params.navigation_type ==
1576 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]ecbf10d2010-02-18 13:03:291577 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:021578 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]7c16976c2012-08-04 02:38:231579
1580 if (reload_original_url)
[email protected]3027cf02013-01-24 08:16:581581 frame->reloadWithOverrideURL(params.url, true);
[email protected]7c16976c2012-08-04 02:38:231582 else
[email protected]3027cf02013-01-24 08:16:581583 frame->reload(ignore_cache);
[email protected]691aa2f2013-05-28 22:52:041584 } else if (params.page_state.IsValid()) {
[email protected]04d3c6e2009-05-22 17:00:131585 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581586 DCHECK_NE(params.page_id, -1);
[email protected]691aa2f2013-05-28 22:52:041587 WebHistoryItem item = PageStateToHistoryItem(params.page_state);
[email protected]bf692cd2012-11-14 19:10:021588 if (!item.isNull()) {
1589 // Ensure we didn't save the swapped out URL in UpdateState, since the
1590 // browser should never be telling us to navigate to swappedout://.
1591 CHECK(item.urlString() != WebString::fromUTF8(kSwappedOutURL));
[email protected]3027cf02013-01-24 08:16:581592 frame->loadHistoryItem(item);
[email protected]bf692cd2012-11-14 19:10:021593 }
[email protected]d1ef81d2012-07-24 11:39:361594 } else if (!params.base_url_for_data_url.is_empty()) {
1595 // A loadData request with a specified base URL.
1596 std::string mime_type, charset, data;
1597 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) {
[email protected]3027cf02013-01-24 08:16:581598 frame->loadData(
[email protected]d1ef81d2012-07-24 11:39:361599 WebData(data.c_str(), data.length()),
1600 WebString::fromUTF8(mime_type),
1601 WebString::fromUTF8(charset),
1602 params.base_url_for_data_url,
1603 params.history_url_for_data_url,
1604 false);
1605 } else {
1606 CHECK(false) <<
1607 "Invalid URL passed: " << params.url.possibly_invalid_spec();
1608 }
[email protected]04d3c6e2009-05-22 17:00:131609 } else {
1610 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281611 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291612
[email protected]e6f546c32009-07-01 17:12:551613 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:231614 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131615
[email protected]3027cf02013-01-24 08:16:581616 if (frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551617 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131618
[email protected]445e1042011-12-03 21:03:151619 if (params.referrer.url.is_valid()) {
1620 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
1621 params.referrer.policy,
1622 params.url,
1623 WebString::fromUTF8(params.referrer.url.spec()));
1624 if (!referrer.isEmpty())
1625 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:281626 }
[email protected]04d3c6e2009-05-22 17:00:131627
[email protected]52c68652010-12-07 17:47:041628 if (!params.extra_headers.empty()) {
1629 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1630 params.extra_headers.end(), "\n");
1631 i.GetNext(); ) {
1632 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1633 WebString::fromUTF8(i.values()));
1634 }
1635 }
[email protected]132e281a2012-07-31 18:32:441636
1637 if (params.is_post) {
1638 request.setHTTPMethod(WebString::fromUTF8("POST"));
1639
1640 // Set post data.
1641 WebHTTPBody http_body;
1642 http_body.initialize();
1643 http_body.appendData(WebData(
1644 reinterpret_cast<const char*>(
1645 &params.browser_initiated_post_data.front()),
1646 params.browser_initiated_post_data.size()));
1647 request.setHTTPBody(http_body);
1648 }
1649
[email protected]3027cf02013-01-24 08:16:581650 frame->loadRequest(request);
[email protected]198a95d62013-04-11 00:44:211651
1652 // If this is a cross-process navigation, the browser process will send
1653 // along the proper navigation start value.
1654 if (!params.browser_navigation_start.is_null() &&
1655 frame->provisionalDataSource()) {
1656 // browser_navigation_start is likely before this process existed, so we
1657 // can't use InterProcessTimeTicksConverter. Instead, the best we can do
1658 // is just ensure we don't report a bogus value in the future.
1659 base::TimeTicks navigation_start = std::min(
1660 base::TimeTicks::Now(), params.browser_navigation_start);
1661 double navigation_start_seconds =
1662 (navigation_start - base::TimeTicks()).InSecondsF();
1663 frame->provisionalDataSource()->setNavigationStartTime(
1664 navigation_start_seconds);
1665 }
[email protected]c0588052008-10-27 23:01:501666 }
1667
[email protected]77f17a82009-05-21 04:42:541668 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:071669 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:291670}
1671
[email protected]310ebd6302011-10-10 19:06:281672bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:031673 const ViewMsg_Navigate_Params& params,
1674 bool is_reload) {
1675 // Make sure this isn't a back/forward to an entry we have already cropped
1676 // or replaced from our history, before the browser knew about it. If so,
1677 // a new navigation has committed in the mean time, and we can ignore this.
[email protected]691aa2f2013-05-28 22:52:041678 bool is_back_forward = !is_reload && params.page_state.IsValid();
[email protected]d466b8a2011-07-15 21:48:031679
1680 // Note: if the history_list_length_ is 0 for a back/forward, we must be
1681 // restoring from a previous session. We'll update our state in OnNavigate.
1682 if (!is_back_forward || history_list_length_ <= 0)
1683 return false;
1684
1685 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
1686
1687 // Check for whether the forward history has been cropped due to a recent
1688 // navigation the browser didn't know about.
1689 if (params.pending_history_list_offset >= history_list_length_)
1690 return true;
1691
1692 // Check for whether this entry has been replaced with a new one.
1693 int expected_page_id =
1694 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:441695 if (expected_page_id > 0 && params.page_id != expected_page_id) {
1696 if (params.page_id < expected_page_id)
1697 return true;
1698
1699 // Otherwise we've removed an earlier entry and should have shifted all
1700 // entries left. For now, it's ok to lazily update the list.
1701 // TODO(creis): Notify all live renderers when we remove entries from
1702 // the front of the list, so that we don't hit this case.
1703 history_page_ids_[params.pending_history_list_offset] = params.page_id;
1704 }
[email protected]d466b8a2011-07-15 21:48:031705
1706 return false;
1707}
1708
initial.commit09911bf2008-07-26 23:55:291709// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:281710void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:441711 if (webview()) {
1712 WebFrame* main_frame = webview()->mainFrame();
1713 // Stop the alt error page fetcher. If we let it continue it may complete
1714 // and cause RenderViewHostManager to swap to this RenderView, even though
1715 // it may no longer be active.
1716 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
1717 StopAltErrorPageFetcher(main_frame->dataSource());
1718 main_frame->stopLoading();
1719 }
initial.commit09911bf2008-07-26 23:55:291720}
1721
[email protected]ecbf10d2010-02-18 13:03:291722// Reload current focused frame.
1723// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:281724void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291725 if (webview() && webview()->focusedFrame()) {
1726 // We always obey the cache (ignore_cache=false) here.
1727 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1728 // a cache-ignoring reload of the frame.
1729 webview()->focusedFrame()->reload(false);
1730 }
[email protected]1dda4022010-01-28 18:24:561731}
1732
[email protected]310ebd6302011-10-10 19:06:281733void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271734 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291735}
1736
[email protected]310ebd6302011-10-10 19:06:281737void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291738 // Check if there is a targeturl waiting to be sent.
1739 if (target_url_status_ == TARGET_PENDING) {
1740 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1741 pending_target_url_));
1742 }
1743
1744 target_url_status_ = TARGET_NONE;
1745}
1746
[email protected]310ebd6302011-10-10 19:06:281747void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291748 if (!webview())
1749 return;
1750
[email protected]5d4e36d2013-02-15 15:18:201751 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101752 WebNode current_node = context_menu_node_.isNull() ?
1753 GetFocusedNode() : context_menu_node_;
[email protected]f6b1856b2011-06-29 22:02:531754 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
[email protected]6dd17a8a2013-05-01 05:50:101755 current_node);
initial.commit09911bf2008-07-26 23:55:291756}
1757
[email protected]c084330e02013-04-27 01:08:151758void RenderViewImpl::OnCut() {
[email protected]a954bf72009-09-12 07:30:351759 if (!webview())
1760 return;
1761
[email protected]c084330e02013-04-27 01:08:151762 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101763 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"),
1764 GetFocusedNode());
[email protected]a954bf72009-09-12 07:30:351765}
[email protected]c084330e02013-04-27 01:08:151766
1767void RenderViewImpl::OnDelete() {
1768 if (!webview())
1769 return;
1770
[email protected]6dd17a8a2013-05-01 05:50:101771 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"),
1772 GetFocusedNode());
[email protected]c084330e02013-04-27 01:08:151773}
1774
1775void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
1776 const std::string& value) {
1777 if (!webview() || !webview()->focusedFrame())
1778 return;
1779
1780 webview()->focusedFrame()->executeCommand(
1781 WebString::fromUTF8(name), WebString::fromUTF8(value));
1782}
1783
1784void RenderViewImpl::OnMoveCaret(const gfx::Point& point) {
1785 if (!webview())
1786 return;
1787
1788 Send(new ViewHostMsg_MoveCaret_ACK(routing_id_));
1789
1790 webview()->focusedFrame()->moveCaretSelectionTowardsWindowPoint(point);
1791}
[email protected]a954bf72009-09-12 07:30:351792
[email protected]310ebd6302011-10-10 19:06:281793void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291794 if (!webview())
1795 return;
1796
[email protected]5d4e36d2013-02-15 15:18:201797 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101798 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"),
1799 GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:291800}
1801
[email protected]44bf7002011-10-16 02:46:151802void RenderViewImpl::OnPasteAndMatchStyle() {
1803 if (!webview())
1804 return;
1805
[email protected]5d4e36d2013-02-15 15:18:201806 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]44bf7002011-10-16 02:46:151807 webview()->focusedFrame()->executeCommand(
[email protected]6dd17a8a2013-05-01 05:50:101808 WebString::fromUTF8("PasteAndMatchStyle"), GetFocusedNode());
[email protected]44bf7002011-10-16 02:46:151809}
1810
[email protected]c084330e02013-04-27 01:08:151811void RenderViewImpl::OnRedo() {
1812 if (!webview())
1813 return;
1814
[email protected]6dd17a8a2013-05-01 05:50:101815 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"),
1816 GetFocusedNode());
[email protected]c084330e02013-04-27 01:08:151817}
1818
[email protected]310ebd6302011-10-10 19:06:281819void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291820 if (!webview())
1821 return;
1822
[email protected]1ff7a032010-02-03 02:46:031823 WebFrame* frame = webview()->focusedFrame();
1824 if (!frame->hasSelection())
1825 frame->selectWordAroundCaret();
[email protected]2365c642013-02-12 19:16:471826
[email protected]1ff7a032010-02-03 02:46:031827 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291828}
1829
[email protected]2365c642013-02-12 19:16:471830void RenderViewImpl::OnReplaceMisspelling(const string16& text) {
1831 if (!webview())
1832 return;
1833
1834 WebFrame* frame = webview()->focusedFrame();
1835 if (!frame->hasSelection())
1836 return;
1837
1838 frame->replaceMisspelledRange(text);
1839}
1840
[email protected]c084330e02013-04-27 01:08:151841void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1842 const gfx::Rect& rect) {
[email protected]180ef242013-11-07 06:50:461843 blink::WebNode node = GetFocusedNode();
[email protected]c084330e02013-04-27 01:08:151844 if (!node.isNull()) {
1845 if (IsEditableNode(node)) {
1846 webview()->saveScrollAndScaleState();
1847 webview()->scrollFocusedNodeIntoRect(rect);
1848 }
1849 }
[email protected]25bcc8f2013-01-09 02:49:251850}
1851
[email protected]310ebd6302011-10-10 19:06:281852void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291853 if (!webview())
1854 return;
1855
[email protected]5d4e36d2013-02-15 15:18:201856 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]26aa0482009-09-30 16:55:271857 webview()->focusedFrame()->executeCommand(
[email protected]6dd17a8a2013-05-01 05:50:101858 WebString::fromUTF8("SelectAll"), GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:291859}
1860
[email protected]c084330e02013-04-27 01:08:151861void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1862 const gfx::Point& end) {
1863 if (!webview())
1864 return;
1865
1866 Send(new ViewHostMsg_SelectRange_ACK(routing_id_));
1867
1868 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1869 webview()->focusedFrame()->selectRange(start, end);
1870}
1871
1872void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
1873 const EditCommands& edit_commands) {
1874 edit_commands_ = edit_commands;
1875}
1876
1877void RenderViewImpl::OnUndo() {
1878 if (!webview())
1879 return;
1880
[email protected]6dd17a8a2013-05-01 05:50:101881 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"),
1882 GetFocusedNode());
[email protected]c084330e02013-04-27 01:08:151883}
1884
[email protected]45a599062012-09-07 20:09:061885void RenderViewImpl::OnUnselect() {
1886 if (!webview())
1887 return;
1888
[email protected]5d4e36d2013-02-15 15:18:201889 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101890 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
1891 GetFocusedNode());
[email protected]45a599062012-09-07 20:09:061892}
1893
[email protected]c084330e02013-04-27 01:08:151894#if defined(OS_MACOSX)
1895void RenderViewImpl::OnCopyToFindPboard() {
1896 if (!webview())
1897 return;
1898
1899 // Since the find pasteboard supports only plain text, this can be simpler
1900 // than the |OnCopy()| case.
1901 WebFrame* frame = webview()->focusedFrame();
1902 if (frame->hasSelection()) {
1903 string16 selection = frame->selectionAsText();
1904 RenderThread::Get()->Send(
1905 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
1906 }
1907}
1908#endif
1909
1910void RenderViewImpl::OnSetName(const std::string& name) {
1911 if (!webview())
1912 return;
1913
1914 webview()->mainFrame()->setName(WebString::fromUTF8(name));
1915}
1916
[email protected]45a599062012-09-07 20:09:061917void RenderViewImpl::OnSetEditableSelectionOffsets(int start, int end) {
[email protected]5d4e36d2013-02-15 15:18:201918 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]0d1ebed12013-08-05 22:01:131919 if (!ShouldHandleImeEvent())
1920 return;
[email protected]66fca5bc2013-05-23 06:58:291921 ImeEventGuard guard(this);
[email protected]45a599062012-09-07 20:09:061922 webview()->setEditableSelectionOffsets(start, end);
1923}
1924
1925void RenderViewImpl::OnSetCompositionFromExistingText(
1926 int start, int end,
[email protected]180ef242013-11-07 06:50:461927 const std::vector<blink::WebCompositionUnderline>& underlines) {
[email protected]0d1ebed12013-08-05 22:01:131928 if (!ShouldHandleImeEvent())
[email protected]45a599062012-09-07 20:09:061929 return;
[email protected]66fca5bc2013-05-23 06:58:291930 ImeEventGuard guard(this);
[email protected]45a599062012-09-07 20:09:061931 webview()->setCompositionFromExistingText(start, end, underlines);
1932}
1933
1934void RenderViewImpl::OnExtendSelectionAndDelete(int before, int after) {
[email protected]0d1ebed12013-08-05 22:01:131935 if (!ShouldHandleImeEvent())
[email protected]45a599062012-09-07 20:09:061936 return;
[email protected]66fca5bc2013-05-23 06:58:291937 ImeEventGuard guard(this);
[email protected]45a599062012-09-07 20:09:061938 webview()->extendSelectionAndDelete(before, after);
1939}
1940
[email protected]310ebd6302011-10-10 19:06:281941void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1942 int32 minimum_page_id) {
[email protected]e1ed5a12012-08-08 19:57:441943 DCHECK_GE(history_length, 0);
[email protected]9e1ad4b2011-08-14 16:49:191944 DCHECK(history_list_offset_ == history_list_length_ - 1);
[email protected]e1ed5a12012-08-08 19:57:441945 DCHECK_GE(minimum_page_id, -1);
[email protected]9e1ad4b2011-08-14 16:49:191946
1947 // Generate the new list.
1948 std::vector<int32> new_history_page_ids(history_length, -1);
1949 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1950 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1951 continue;
1952 new_history_page_ids.push_back(history_page_ids_[i]);
1953 }
1954 new_history_page_ids.swap(history_page_ids_);
1955
1956 // Update indexes.
1957 history_list_length_ = history_page_ids_.size();
1958 history_list_offset_ = history_list_length_ - 1;
1959}
1960
1961
[email protected]310ebd6302011-10-10 19:06:281962void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291963 if (!webview())
1964 return;
[email protected]26aa0482009-09-30 16:55:271965 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291966}
1967
[email protected]54ca3ca892011-06-07 21:14:541968#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281969void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331970 if (!webview())
1971 return;
1972 if (in_live_resize)
1973 webview()->willStartLiveResize();
1974 else
1975 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541976}
1977#endif
1978
[email protected]9b7d11e2012-10-08 19:24:141979#if defined(OS_ANDROID)
1980void RenderViewImpl::OnUndoScrollFocusedEditableNodeIntoRect() {
1981 const WebNode node = GetFocusedNode();
1982 if (!node.isNull() && IsEditableNode(node))
1983 webview()->restoreScrollAndScaleState();
1984}
[email protected]68877c282013-09-20 05:52:421985
1986void RenderViewImpl::OnPauseVideo() {
1987 // Inform RendererMediaPlayerManager to release all video player resources.
1988 // If something is in progress the resource will not be freed, it will
1989 // only be freed once the tab is destroyed or if the user navigates away
1990 // via WebMediaPlayerAndroid::Destroy.
1991 media_player_manager_->ReleaseVideoResources();
1992}
[email protected]9b7d11e2012-10-08 19:24:141993#endif
1994
initial.commit09911bf2008-07-26 23:55:291995///////////////////////////////////////////////////////////////////////////////
1996
1997// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281998void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451999 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:292000 DCHECK(ds);
2001
[email protected]726985e22009-06-18 21:09:282002 const WebURLRequest& request = ds->request();
2003 const WebURLRequest& original_request = ds->originalRequest();
2004 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:292005
[email protected]007733c2011-11-17 00:34:072006 DocumentState* document_state = DocumentState::FromDataSource(ds);
2007 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e20b88d2013-04-09 15:28:372008 InternalDocumentStateData* internal_data =
2009 InternalDocumentStateData::FromDocumentState(document_state);
initial.commit09911bf2008-07-26 23:55:292010
2011 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:282012 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:292013 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:052014 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:292015 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:072016 params.frame_id = frame->identifier();
[email protected]2f673064c2013-10-22 04:01:442017 params.frame_unique_name = frame->uniqueName();
[email protected]6d81b482011-02-22 19:47:192018 params.socket_address.set_host(response.remoteIPAddress().utf8());
2019 params.socket_address.set_port(response.remotePort());
[email protected]e07ddafe2013-03-05 21:03:362020 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
2021 if (extra_data) {
2022 params.was_fetched_via_proxy = extra_data->was_fetched_via_proxy();
2023 }
[email protected]af15bed2010-08-25 21:12:092024 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e20b88d2013-04-09 15:28:372025 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:292026
2027 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:312028 params.url = GetLoadingUrl(frame);
[email protected]809be032013-03-19 01:56:562029 DCHECK(!is_swapped_out_ || params.url == GURL(kSwappedOutURL));
initial.commit09911bf2008-07-26 23:55:292030
[email protected]5f9b8712011-11-23 08:55:572031 if (frame->document().baseURL() != params.url)
2032 params.base_url = frame->document().baseURL();
2033
[email protected]726985e22009-06-18 21:09:282034 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:242035 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:042036 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:292037
[email protected]e20b88d2013-04-09 15:28:372038 params.searchable_form_url = internal_data->searchable_form_url();
2039 params.searchable_form_encoding = internal_data->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:292040
initial.commit09911bf2008-07-26 23:55:292041 params.gesture = navigation_gesture_;
2042 navigation_gesture_ = NavigationGestureUnknown;
2043
[email protected]0f38dc4552011-02-25 11:24:002044 // Make navigation state a part of the FrameNavigate message so that commited
2045 // entry had it at all times.
[email protected]691aa2f2013-05-28 22:52:042046 WebHistoryItem item = frame->currentHistoryItem();
2047 if (item.isNull()) {
2048 item.initialize();
2049 item.setURLString(request.url().spec().utf16());
[email protected]0f38dc4552011-02-25 11:24:002050 }
[email protected]691aa2f2013-05-28 22:52:042051 params.page_state = HistoryItemToPageState(item);
[email protected]0f38dc4552011-02-25 11:24:002052
[email protected]dd7daa82009-08-10 05:46:452053 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:292054 // Top-level navigation.
2055
[email protected]d00a7972012-08-07 06:09:582056 // Reset the zoom limits in case a plugin had changed them previously. This
2057 // will also call us back which will cause us to send a message to
2058 // update WebContentsImpl.
[email protected]7940b8e2013-07-25 23:08:492059 webview()->zoomLimitsChanged(ZoomFactorToZoomLevel(kMinimumZoomFactor),
2060 ZoomFactorToZoomLevel(kMaximumZoomFactor));
[email protected]d00a7972012-08-07 06:09:582061
[email protected]b75b8292010-10-01 07:28:252062 // Set zoom level, but don't do it for full-page plugin since they don't use
2063 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:012064 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:542065 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:252066 if (webview()->mainFrame()->document().isPluginDocument()) {
2067 // Reset the zoom levels for plugins.
[email protected]91219702013-09-18 07:33:512068 webview()->setZoomLevel(0);
[email protected]b75b8292010-10-01 07:28:252069 } else {
2070 if (host_zoom != host_zoom_levels_.end())
[email protected]91219702013-09-18 07:33:512071 webview()->setZoomLevel(host_zoom->second);
[email protected]b75b8292010-10-01 07:28:252072 }
2073
[email protected]f85f0702010-01-30 09:31:012074 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:512075 // This zoom level was merely recorded transiently for this load. We can
2076 // erase it now. If at some point we reload this page, the browser will
2077 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:012078 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:512079 }
2080
initial.commit09911bf2008-07-26 23:55:292081 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:552082 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:292083
[email protected]daa8c58e2009-06-15 17:21:102084 params.transition = navigation_state->transition_type();
[email protected]e9ff79c2012-10-19 21:31:262085 if (!PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:292086 // If the main frame does a load, it should not be reported as a subframe
2087 // navigation. This can occur in the following case:
2088 // 1. You're on a site with frames.
2089 // 2. You do a subframe navigation. This is stored with transition type
2090 // MANUAL_SUBFRAME.
2091 // 3. You navigate to some non-frame site, say, google.com.
2092 // 4. You navigate back to the page from step 2. Since it was initially
2093 // MANUAL_SUBFRAME, it will be that same transition type here.
2094 // We don't want that, because any navigation that changes the toplevel
2095 // frame should be tracked as a toplevel navigation (this allows us to
2096 // update the URL bar, etc).
[email protected]e9ff79c2012-10-19 21:31:262097 params.transition = PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:292098 }
2099
[email protected]a00a2e32013-07-31 05:08:332100 // If the page contained a client redirect (meta refresh, document.loc...),
2101 // set the referrer and transition appropriately.
2102 if (ds->isClientRedirect()) {
2103 params.referrer = Referrer(params.redirects[0],
2104 GetReferrerPolicyFromRequest(frame, ds->request()));
[email protected]e9ff79c2012-10-19 21:31:262105 params.transition = static_cast<PageTransition>(
2106 params.transition | PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:292107 } else {
2108 // Bug 654101: the referrer will be empty on https->http transitions. It
2109 // would be nice if we could get the real referrer from somewhere.
[email protected]44e55b012013-07-23 14:21:562110 params.referrer = GetReferrerFromRequest(frame, original_request);
initial.commit09911bf2008-07-26 23:55:292111 }
2112
[email protected]726985e22009-06-18 21:09:282113 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:052114 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:292115 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:052116 params.post_id = ExtractPostId(item);
2117 }
initial.commit09911bf2008-07-26 23:55:292118
[email protected]bf70edce2012-06-20 22:32:222119 // Send the user agent override back.
[email protected]e20b88d2013-04-09 15:28:372120 params.is_overriding_user_agent = internal_data->is_overriding_user_agent();
[email protected]bf70edce2012-06-20 22:32:222121
[email protected]f8872902013-10-30 03:18:572122 // Track the URL of the original request. We use the first entry of the
2123 // redirect chain if it exists because the chain may have started in another
2124 // process.
2125 if (params.redirects.size() > 0)
2126 params.original_request_url = params.redirects.at(0);
2127 else
2128 params.original_request_url = original_request.url();
[email protected]7c16976c2012-08-04 02:38:232129
[email protected]60d6cca2013-04-30 08:47:132130 params.history_list_was_cleared =
2131 navigation_state->history_list_was_cleared();
2132
[email protected]c2a797d2009-09-21 16:46:322133 // Save some histogram data so we can compute the average memory used per
2134 // page load of the glyphs.
2135 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
[email protected]180ef242013-11-07 06:50:462136 blink::WebGlyphCache::pageCount());
[email protected]c2a797d2009-09-21 16:46:322137
[email protected]15cf526b2010-02-12 06:33:492138 // This message needs to be sent before any of allowScripts(),
2139 // allowImages(), allowPlugins() is called for the new page, so that when
2140 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
2141 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:292142 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
2143 } else {
2144 // Subframe navigation: the type depends on whether this navigation
2145 // generated a new session history entry. When they do generate a session
2146 // history entry, it means the user initiated the navigation and we should
2147 // mark it as such. This test checks if this is the first time UpdateURL
2148 // has been called since WillNavigateToURL was called to initiate the load.
2149 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]e9ff79c2012-10-19 21:31:262150 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:292151 else
[email protected]e9ff79c2012-10-19 21:31:262152 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:292153
[email protected]60d6cca2013-04-30 08:47:132154 DCHECK(!navigation_state->history_list_was_cleared());
2155 params.history_list_was_cleared = false;
2156
initial.commit09911bf2008-07-26 23:55:292157 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
2158 }
2159
2160 last_page_id_sent_to_browser_ =
2161 std::max(last_page_id_sent_to_browser_, page_id_);
2162
2163 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:102164 // we don't want the transition type to persist. Just clear it.
[email protected]e9ff79c2012-10-19 21:31:262165 navigation_state->set_transition_type(PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:292166}
2167
2168// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:282169void RenderViewImpl::UpdateTitle(WebFrame* frame,
2170 const string16& title,
2171 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:462172 // Ignore all but top level navigations.
2173 if (frame->parent())
2174 return;
2175
[email protected]91a2aea2013-07-08 23:14:392176 base::debug::TraceLog::GetInstance()->UpdateProcessLabel(
2177 routing_id_, UTF16ToUTF8(title));
2178
[email protected]e9ff79c2012-10-19 21:31:262179 string16 shortened_title = title.substr(0, kMaxTitleChars);
[email protected]a49e10b2011-08-01 23:57:462180 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
2181 title_direction));
initial.commit09911bf2008-07-26 23:55:292182}
2183
[email protected]310ebd6302011-10-10 19:06:282184void RenderViewImpl::UpdateEncoding(WebFrame* frame,
2185 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:292186 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:272187 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:292188 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:302189 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:292190 last_encoding_name_ = encoding_name;
2191
[email protected]e38f40152008-09-12 23:08:302192 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:292193 }
2194}
2195
[email protected]e15f680732010-11-23 22:30:202196// Sends the last committed session history state to the browser so it will be
2197// saved before we navigate to a new page. This must be called *before* the
2198// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:282199void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:292200 // If we have a valid page ID at this point, then it corresponds to the page
2201 // we are navigating away from. Otherwise, this is the first navigation, so
2202 // there is no past session history to record.
2203 if (page_id_ == -1)
2204 return;
2205
[email protected]ca948a22009-06-25 19:36:172206 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:272207 webview()->mainFrame()->previousHistoryItem();
[email protected]6459800a2012-03-27 23:57:052208 SendUpdateState(item);
2209}
2210
2211void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
[email protected]ca948a22009-06-25 19:36:172212 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292213 return;
[email protected]ca948a22009-06-25 19:36:172214
[email protected]e9ff79c2012-10-19 21:31:262215 // Don't send state updates for kSwappedOutURL.
2216 if (item.urlString() == WebString::fromUTF8(kSwappedOutURL))
[email protected]6459800a2012-03-27 23:57:052217 return;
2218
[email protected]ca948a22009-06-25 19:36:172219 Send(new ViewHostMsg_UpdateState(
[email protected]691aa2f2013-05-28 22:52:042220 routing_id_, page_id_, HistoryItemToPageState(item)));
initial.commit09911bf2008-07-26 23:55:292221}
2222
[email protected]310ebd6302011-10-10 19:06:282223void RenderViewImpl::OpenURL(WebFrame* frame,
2224 const GURL& url,
[email protected]445e1042011-12-03 21:03:152225 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:282226 WebNavigationPolicy policy) {
[email protected]e2caa032012-11-15 23:29:182227 ViewHostMsg_OpenURL_Params params;
2228 params.url = url;
2229 params.referrer = referrer;
2230 params.disposition = NavigationPolicyToDisposition(policy);
2231 params.frame_id = frame->identifier();
[email protected]b4c09692012-12-13 19:15:462232 WebDataSource* ds = frame->provisionalDataSource();
2233 if (ds) {
[email protected]866fa2cc2013-07-22 22:19:522234 params.should_replace_current_entry = ds->replacesCurrentHistoryItem();
[email protected]b4c09692012-12-13 19:15:462235 } else {
[email protected]866fa2cc2013-07-22 22:19:522236 params.should_replace_current_entry = false;
[email protected]b4c09692012-12-13 19:15:462237 }
[email protected]e7f2e7c2013-07-15 09:41:302238 params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]00323f02013-07-24 15:47:412239 if (GetContentClient()->renderer()->AllowPopup())
2240 params.user_gesture = true;
[email protected]e7f2e7c2013-07-15 09:41:302241
[email protected]180ef242013-11-07 06:50:462242 if (policy == blink::WebNavigationPolicyNewBackgroundTab ||
2243 policy == blink::WebNavigationPolicyNewForegroundTab ||
2244 policy == blink::WebNavigationPolicyNewWindow ||
2245 policy == blink::WebNavigationPolicyNewPopup) {
[email protected]e7f2e7c2013-07-15 09:41:302246 WebUserGestureIndicator::consumeUserGesture();
2247 }
[email protected]e2caa032012-11-15 23:29:182248
2249 Send(new ViewHostMsg_OpenURL(routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172250}
2251
[email protected]79dbc662009-09-04 05:42:512252// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:292253
[email protected]310ebd6302011-10-10 19:06:282254void RenderViewImpl::LoadNavigationErrorPage(
2255 WebFrame* frame,
2256 const WebURLRequest& failed_request,
2257 const WebURLError& error,
2258 const std::string& html,
2259 bool replace) {
[email protected]d7b175e2011-10-11 15:31:582260 std::string alt_html;
2261 const std::string* error_html;
2262
2263 if (!html.empty()) {
2264 error_html = &html;
2265 } else {
[email protected]e9ff79c2012-10-19 21:31:262266 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]b38806a2013-10-04 16:01:382267 frame, failed_request, error, renderer_preferences_.accept_languages,
2268 &alt_html, NULL);
[email protected]d7b175e2011-10-11 15:31:582269 error_html = &alt_html;
2270 }
2271
2272 frame->loadHTMLString(*error_html,
[email protected]e9ff79c2012-10-19 21:31:262273 GURL(kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:252274 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:552275 replace);
initial.commit09911bf2008-07-26 23:55:292276}
2277
[email protected]e9ff79c2012-10-19 21:31:262278bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:282279 const string16& message,
2280 const string16& default_value,
2281 const GURL& frame_url,
2282 string16* result) {
[email protected]88f10a22013-11-06 21:22:122283 // Don't allow further dialogs if we are waiting to swap out, since the
2284 // PageGroupLoadDeferrer in our stack prevents it.
2285 if (suppress_dialogs_until_swap_out_)
2286 return false;
2287
initial.commit09911bf2008-07-26 23:55:292288 bool success = false;
[email protected]4f5ce842011-05-27 19:34:412289 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:292290 if (!result)
2291 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:292292
[email protected]12636df2009-09-28 22:32:212293 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
[email protected]688e2ee2013-09-12 20:48:142294 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:292295 return success;
2296}
2297
[email protected]310ebd6302011-10-10 19:06:282298bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:572299 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
2300 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
2301 // it is particularly important that we do not call willEnterModalLoop as
2302 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:442303 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2304 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:572305
2306 message->EnableMessagePumping(); // Runs a nested message loop.
2307 return Send(message);
2308}
2309
[email protected]c9bc8f12012-12-15 22:20:092310void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) {
2311 int id = next_snapshot_id_++;
2312 pending_snapshots_.insert(std::make_pair(id, callback));
[email protected]7d08a9352013-10-15 08:24:562313 ui::LatencyInfo latency_info;
2314 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
2315 GetLatencyComponentId(),
2316 id);
2317 if (RenderWidgetCompositor* rwc = compositor()) {
2318 rwc->SetLatencyInfo(latency_info);
2319 } else {
2320 latency_info_.MergeWith(latency_info);
2321 }
2322 ScheduleCompositeWithForcedRedraw();
[email protected]c9bc8f12012-12-15 22:20:092323}
2324
2325void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id,
2326 const gfx::Size& size, const std::vector<unsigned char>& png) {
[email protected]7d08a9352013-10-15 08:24:562327
2328 // Any pending snapshots with a lower ID than the one received are considered
2329 // to be implicitly complete, and returned the same snapshot data.
2330 PendingSnapshotMap::iterator it = pending_snapshots_.begin();
2331 while(it != pending_snapshots_.end()) {
2332 if (it->first <= snapshot_id) {
2333 it->second.Run(size, png);
2334 pending_snapshots_.erase(it++);
2335 } else {
2336 ++it;
2337 }
2338 }
[email protected]c9bc8f12012-12-15 22:20:092339}
2340
[email protected]180ef242013-11-07 06:50:462341// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:522342
[email protected]916dfb62012-03-05 03:39:372343WebView* RenderViewImpl::createView(
2344 WebFrame* creator,
2345 const WebURLRequest& request,
2346 const WebWindowFeatures& features,
2347 const WebString& frame_name,
2348 WebNavigationPolicy policy) {
[email protected]147b2bf2013-11-05 04:00:042349 return createView(creator, request, features, frame_name, policy,
2350 creator->willSuppressOpenerInNewFrame());
2351}
2352
2353WebView* RenderViewImpl::createView(
2354 WebFrame* creator,
2355 const WebURLRequest& request,
2356 const WebWindowFeatures& features,
2357 const WebString& frame_name,
2358 WebNavigationPolicy policy,
2359 bool suppress_opener) {
[email protected]8ab04652010-06-12 02:47:262360 ViewHostMsg_CreateWindow_Params params;
2361 params.opener_id = routing_id_;
[email protected]af15bf22013-03-08 01:18:172362 params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]00323f02013-07-24 15:47:412363 if (GetContentClient()->renderer()->AllowPopup())
2364 params.user_gesture = true;
[email protected]8ab04652010-06-12 02:47:262365 params.window_container_type = WindowFeaturesToContainerType(features);
2366 params.session_storage_namespace_id = session_storage_namespace_id_;
[email protected]5cef23d2013-02-27 13:11:212367 if (frame_name != "_blank")
2368 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:112369 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:412370 params.opener_url = creator->document().url();
[email protected]931bc922013-09-11 21:42:572371 params.opener_top_level_frame_url = creator->top()->document().url();
[email protected]7f48b712013-01-25 01:48:302372 GURL security_url(creator->document().securityOrigin().toString().utf8());
2373 if (!security_url.is_valid())
2374 security_url = GURL();
2375 params.opener_security_origin = security_url;
[email protected]147b2bf2013-11-05 04:00:042376 params.opener_suppressed = suppress_opener;
[email protected]f92ce2b2012-03-06 18:02:592377 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]44e55b012013-07-23 14:21:562378 if (!request.isNull()) {
[email protected]41e65502011-01-21 09:29:112379 params.target_url = request.url();
[email protected]44e55b012013-07-23 14:21:562380 params.referrer = GetReferrerFromRequest(creator, request);
2381 }
[email protected]453c1b22013-07-23 09:31:482382 params.features = features;
[email protected]8ab04652010-06-12 02:47:262383
[email protected]48c9cf2d2009-09-16 16:47:522384 int32 routing_id = MSG_ROUTING_NONE;
[email protected]227692c52013-05-31 22:43:042385 int32 main_frame_routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:562386 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:342387 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:522388
[email protected]380244092011-10-07 17:26:272389 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:262390 new ViewHostMsg_CreateWindow(params,
2391 &routing_id,
[email protected]227692c52013-05-31 22:43:042392 &main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:562393 &surface_id,
[email protected]8ab04652010-06-12 02:47:262394 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:212395 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:522396 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522397
[email protected]af15bf22013-03-08 01:18:172398 WebUserGestureIndicator::consumeUserGesture();
[email protected]c59262422012-11-30 21:20:522399
[email protected]3184f90b2013-05-01 18:17:532400 WebPreferences transferred_preferences = webkit_preferences_;
[email protected]9115d5f2013-03-24 04:37:412401
2402 // Unless accelerated compositing has been explicitly disabled from the
2403 // command line (e.g. via the blacklist or about:flags) re-enable it for
2404 // new views that get spawned by this view. This gets around the issue that
2405 // background extension pages disable accelerated compositing via web prefs
2406 // but can themselves spawn a visible render view which should be allowed
2407 // use gpu acceleration.
2408 if (!webkit_preferences_.accelerated_compositing_enabled) {
2409 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2410 if (!command_line.HasSwitch(switches::kDisableAcceleratedCompositing))
2411 transferred_preferences.accelerated_compositing_enabled = true;
2412 }
2413
[email protected]d6fa88f2013-10-18 16:00:432414 // The initial hidden state for the RenderViewImpl here has to match what the
2415 // browser will eventually decide for the given disposition. Since we have to
2416 // return from this call synchronously, we just have to make our best guess
2417 // and rely on the browser sending a WasHidden / WasShown message if it
2418 // disagrees.
[email protected]310ebd6302011-10-10 19:06:282419 RenderViewImpl* view = RenderViewImpl::Create(
[email protected]310ebd6302011-10-10 19:06:282420 routing_id_,
2421 renderer_preferences_,
[email protected]9115d5f2013-03-24 04:37:412422 transferred_preferences,
[email protected]310ebd6302011-10-10 19:06:282423 routing_id,
[email protected]227692c52013-05-31 22:43:042424 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:562425 surface_id,
[email protected]310ebd6302011-10-10 19:06:282426 cloned_session_storage_namespace_id,
[email protected]5cef23d2013-02-27 13:11:212427 string16(), // WebCore will take care of setting the correct name.
[email protected]1ac10dca2013-08-20 20:47:042428 true, // is_renderer_created
2429 false, // swapped_out
[email protected]d6fa88f2013-10-18 16:00:432430 params.disposition == NEW_BACKGROUND_TAB, // hidden
[email protected]1ac10dca2013-08-20 20:47:042431 1, // next_page_id
[email protected]842f10652012-06-06 01:54:042432 screen_info_,
[email protected]34bb3ac2013-03-08 02:41:282433 accessibility_mode_,
2434 allow_partial_swap_);
[email protected]8ab04652010-06-12 02:47:262435 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:522436
[email protected]007a848b2009-10-26 15:55:462437 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:592438 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:462439
[email protected]48c9cf2d2009-09-16 16:47:522440 // Copy over the alternate error page URL so we can have alt error pages in
2441 // the new render view (we don't need the browser to send the URL back down).
2442 view->alternate_error_page_url_ = alternate_error_page_url_;
2443
2444 return view->webview();
2445}
2446
[email protected]180ef242013-11-07 06:50:462447WebWidget* RenderViewImpl::createPopupMenu(blink::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:412448 RenderWidget* widget =
[email protected]842f10652012-06-06 01:54:042449 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]b2e4c70132013-10-03 02:07:512450 if (screen_metrics_emulator_) {
2451 widget->SetPopupOriginAdjustmentsForEmulation(
2452 screen_metrics_emulator_.get());
2453 }
[email protected]48c9cf2d2009-09-16 16:47:522454 return widget->webwidget();
2455}
2456
[email protected]310ebd6302011-10-10 19:06:282457WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:082458 const WebPopupMenuInfo& popup_menu_info,
2459 WebExternalPopupMenuClient* popup_menu_client) {
[email protected]8de2f882012-05-30 00:32:272460 // An IPC message is sent to the browser to build and display the actual
2461 // popup. The user could have time to click a different select by the time
2462 // the popup is shown. In that case external_popup_menu_ is non NULL.
2463 // By returning NULL in that case, we instruct WebKit to cancel that new
2464 // popup. So from the user perspective, only the first one will show, and
2465 // will have to close the first one before another one can be shown.
[email protected]59383c782013-04-17 16:43:272466 if (external_popup_menu_)
[email protected]8de2f882012-05-30 00:32:272467 return NULL;
[email protected]caf706f2010-10-26 17:54:082468 external_popup_menu_.reset(
2469 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
[email protected]b2e4c70132013-10-03 02:07:512470 if (screen_metrics_emulator_) {
2471 SetExternalPopupOriginAdjustmentsForEmulation(
2472 external_popup_menu_.get(), screen_metrics_emulator_.get());
2473 }
[email protected]caf706f2010-10-26 17:54:082474 return external_popup_menu_.get();
2475}
2476
[email protected]23367482013-06-27 21:06:542477WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() {
[email protected]5f2aa722013-08-07 16:59:412478 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:102479 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:342480}
2481
[email protected]fd8eb742013-08-22 00:42:002482bool RenderViewImpl::shouldReportDetailedMessageForSource(
2483 const WebString& source) {
2484 return GetContentClient()->renderer()->ShouldReportDetailedMessageForSource(
2485 source);
2486}
2487
[email protected]310ebd6302011-10-10 19:06:282488void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:522489 const WebConsoleMessage& message, const WebString& source_name,
[email protected]fd8eb742013-08-22 00:42:002490 unsigned source_line, const WebString& stack_trace) {
[email protected]d09df4b2011-04-11 19:01:082491 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:512492 switch (message.level) {
[email protected]80ac8942013-01-30 22:53:222493 case WebConsoleMessage::LevelDebug:
[email protected]d09df4b2011-04-11 19:01:082494 log_severity = logging::LOG_VERBOSE;
2495 break;
2496 case WebConsoleMessage::LevelLog:
[email protected]69c84d152013-10-25 18:53:092497 case WebConsoleMessage::LevelInfo:
[email protected]d09df4b2011-04-11 19:01:082498 log_severity = logging::LOG_INFO;
2499 break;
2500 case WebConsoleMessage::LevelWarning:
2501 log_severity = logging::LOG_WARNING;
2502 break;
2503 case WebConsoleMessage::LevelError:
2504 log_severity = logging::LOG_ERROR;
2505 break;
2506 default:
2507 NOTREACHED();
2508 }
2509
[email protected]88b50b62013-09-01 23:05:062510 if (shouldReportDetailedMessageForSource(source_name)) {
2511 FOR_EACH_OBSERVER(
2512 RenderViewObserver,
2513 observers_,
2514 DetailedConsoleMessageAdded(message.text,
2515 source_name,
2516 stack_trace,
2517 source_line,
2518 static_cast<int32>(log_severity)));
2519 }
2520
[email protected]07fb8d52013-08-07 17:03:512521 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
2522 static_cast<int32>(log_severity),
2523 message.text,
2524 static_cast<int32>(source_line),
[email protected]88b50b62013-09-01 23:05:062525 source_name));
[email protected]48c9cf2d2009-09-16 16:47:522526}
2527
[email protected]310ebd6302011-10-10 19:06:282528void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]b0553c7e2012-09-19 21:36:112529 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2530 PrintPage(frame, handling_input_event_));
[email protected]48c9cf2d2009-09-16 16:47:522531}
2532
[email protected]180ef242013-11-07 06:50:462533blink::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:512534 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:022535}
2536
[email protected]310ebd6302011-10-10 19:06:282537bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:122538 const WebString& path,
2539 WebFileChooserCompletion* chooser_completion) {
2540 int id = enumeration_completion_id_++;
2541 enumeration_completions_[id] = chooser_completion;
2542 return Send(new ViewHostMsg_EnumerateDirectory(
2543 routing_id_,
2544 id,
[email protected]728c2ee2013-06-25 04:01:072545 base::FilePath::FromUTF16Unsafe(path)));
[email protected]8a58c1c2011-04-19 18:40:122546}
2547
[email protected]4b1146bc2012-07-10 18:46:032548void RenderViewImpl::initializeHelperPluginWebFrame(
[email protected]180ef242013-11-07 06:50:462549 blink::WebHelperPlugin* plugin) {
[email protected]2f61bdd2013-07-02 18:38:472550 plugin->initializeFrame(main_render_frame_.get());
[email protected]4b1146bc2012-07-10 18:46:032551}
2552
[email protected]310ebd6302011-10-10 19:06:282553void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:522554 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:142555 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:522556 return;
2557 }
2558
2559 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:522560
2561 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:312562
2563 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:522564}
2565
[email protected]310ebd6302011-10-10 19:06:282566void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:522567 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:142568 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:522569 return;
2570 }
2571
2572 is_loading_ = false;
2573
2574 // NOTE: For now we're doing the safest thing, and sending out notification
2575 // when done loading. This currently isn't an issue as the favicon is only
2576 // displayed when done loading. Ideally we would send notification when
2577 // finished parsing the head, but webkit doesn't support that yet.
2578 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:522579 Send(new ViewHostMsg_DidStopLoading(routing_id_));
2580
[email protected]90109412010-12-15 17:14:242581 if (load_progress_tracker_ != NULL)
2582 load_progress_tracker_->DidStopLoading();
2583
[email protected]41225fe2013-03-29 05:32:022584 DidStopLoadingIcons();
2585
[email protected]93b9d692011-04-13 00:44:312586 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:522587}
2588
[email protected]310ebd6302011-10-10 19:06:282589void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
2590 double load_progress) {
[email protected]90109412010-12-15 17:14:242591 if (load_progress_tracker_ != NULL)
2592 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
2593}
2594
[email protected]550b0c92013-02-04 05:09:152595void RenderViewImpl::didCancelCompositionOnSelectionChange() {
2596 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
2597}
2598
[email protected]310ebd6302011-10-10 19:06:282599void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:082600 if (!handling_input_event_ && !handling_select_range_)
[email protected]5d4e36d2013-02-15 15:18:202601 return;
[email protected]d4cff272011-05-02 15:46:012602
[email protected]fca52022012-04-03 17:00:502603 if (is_empty_selection)
2604 selection_text_.clear();
2605
[email protected]087edc72013-11-07 01:00:352606 // UpdateTextInputType should be called before SyncSelectionIfRequired.
2607 // UpdateTextInputType may send TextInputTypeChanged to notify the focus
2608 // was changed, and SyncSelectionIfRequired may send SelectionChanged
2609 // to notify the selection was changed. Focus change should be notified
2610 // before selection change.
[email protected]cb9e2632013-06-18 11:26:472611 UpdateTextInputType();
[email protected]087edc72013-11-07 01:00:352612 SyncSelectionIfRequired();
[email protected]cb9e2632013-06-18 11:26:472613#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:132614 UpdateTextInputState(false, true);
[email protected]cb9e2632013-06-18 11:26:472615#endif
[email protected]04fc9482009-09-18 22:13:032616}
2617
[email protected]310ebd6302011-10-10 19:06:282618void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:122619 const std::string& name = UTF16ToUTF8(command_name);
2620 if (StartsWithASCII(name, "Move", true) ||
2621 StartsWithASCII(name, "Insert", true) ||
2622 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:032623 return;
[email protected]f1a29a02011-10-06 23:08:442624 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:032625}
2626
[email protected]310ebd6302011-10-10 19:06:282627bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:102628 if (edit_commands_.empty())
2629 return false;
2630
[email protected]26aa0482009-09-30 16:55:272631 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102632 if (!frame)
2633 return false;
2634
2635 EditCommands::iterator it = edit_commands_.begin();
2636 EditCommands::iterator end = edit_commands_.end();
2637
[email protected]507b33ea2009-09-29 03:56:512638 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102639 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332640 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2641 // key (but it's the exception). Once one edit command is not executed, it
2642 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102643 if (!frame->executeCommand(WebString::fromUTF8(it->name),
[email protected]b77fac52013-06-01 01:03:462644 WebString::fromUTF8(it->value),
2645 GetFocusedNode()))
[email protected]b2528b72009-09-24 06:57:102646 break;
[email protected]507b33ea2009-09-29 03:56:512647 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102648 }
2649
[email protected]507b33ea2009-09-29 03:56:512650 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102651}
2652
[email protected]180ef242013-11-07 06:50:462653blink::WebColorChooser* RenderViewImpl::createColorChooser(
2654 blink::WebColorChooserClient* client,
2655 const blink::WebColor& initial_color) {
[email protected]da8543762012-03-20 08:52:202656 RendererWebColorChooserImpl* color_chooser =
2657 new RendererWebColorChooserImpl(this, client);
2658 color_chooser->Open(static_cast<SkColor>(initial_color));
2659 return color_chooser;
2660}
2661
[email protected]310ebd6302011-10-10 19:06:282662bool RenderViewImpl::runFileChooser(
[email protected]180ef242013-11-07 06:50:462663 const blink::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472664 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352665 // Do not open the file dialog in a hidden RenderView.
2666 if (is_hidden())
2667 return false;
[email protected]e9ff79c2012-10-19 21:31:262668 FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262669 if (params.directory)
[email protected]6bedbef2013-07-31 06:33:492670 ipc_params.mode = FileChooserParams::UploadFolder;
[email protected]b5977a0c2010-08-24 19:46:262671 else if (params.multiSelect)
[email protected]e9ff79c2012-10-19 21:31:262672 ipc_params.mode = FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:502673 else if (params.saveAs)
[email protected]e9ff79c2012-10-19 21:31:262674 ipc_params.mode = FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:262675 else
[email protected]e9ff79c2012-10-19 21:31:262676 ipc_params.mode = FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:472677 ipc_params.title = params.title;
2678 ipc_params.default_file_name =
[email protected]728c2ee2013-06-25 04:01:072679 base::FilePath::FromUTF16Unsafe(params.initialValue);
[email protected]f9a4c41a2012-05-30 00:05:322680 ipc_params.accept_types.reserve(params.acceptTypes.size());
2681 for (size_t i = 0; i < params.acceptTypes.size(); ++i)
2682 ipc_params.accept_types.push_back(params.acceptTypes[i]);
[email protected]2fdf2352012-11-01 19:23:022683#if defined(OS_ANDROID)
[email protected]b7b4beb2013-07-09 14:06:502684 ipc_params.capture = params.useMediaCapture;
[email protected]2fdf2352012-11-01 19:23:022685#endif
[email protected]cdaf8d02010-03-30 19:52:472686
2687 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462688}
2689
[email protected]269f86d2011-12-07 02:43:472690void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
2691 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262692 RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:412693 message,
2694 string16(),
[email protected]b6cb3a842011-06-24 18:28:412695 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522696 NULL);
2697}
2698
[email protected]269f86d2011-12-07 02:43:472699bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
2700 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262701 return RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:412702 message,
2703 string16(),
[email protected]b6cb3a842011-06-24 18:28:412704 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522705 NULL);
2706}
2707
[email protected]269f86d2011-12-07 02:43:472708bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
2709 const WebString& message,
2710 const WebString& default_value,
2711 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:412712 string16 result;
[email protected]e9ff79c2012-10-19 21:31:262713 bool ok = RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:412714 message,
2715 default_value,
[email protected]b6cb3a842011-06-24 18:28:412716 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522717 &result);
2718 if (ok)
[email protected]4f5ce842011-05-27 19:34:412719 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:522720 return ok;
2721}
2722
[email protected]310ebd6302011-10-10 19:06:282723bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:522724 WebFrame* frame, const WebString& message) {
[email protected]ab533826b2013-05-10 23:54:562725 bool is_reload = false;
2726 WebDataSource* ds = frame->provisionalDataSource();
2727 if (ds)
[email protected]180ef242013-11-07 06:50:462728 is_reload = (ds->navigationType() == blink::WebNavigationTypeReload);
[email protected]ab533826b2013-05-10 23:54:562729 return runModalBeforeUnloadDialog(frame, is_reload, message);
2730}
2731
2732bool RenderViewImpl::runModalBeforeUnloadDialog(
2733 WebFrame* frame, bool is_reload, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:152734 // If we are swapping out, we have already run the beforeunload handler.
2735 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
2736 // at all, to avoid running it twice.
2737 if (is_swapped_out_)
2738 return true;
2739
[email protected]88f10a22013-11-06 21:22:122740 // Don't allow further dialogs if we are waiting to swap out, since the
2741 // PageGroupLoadDeferrer in our stack prevents it.
2742 if (suppress_dialogs_until_swap_out_)
2743 return false;
2744
[email protected]48c9cf2d2009-09-16 16:47:522745 bool success = false;
2746 // This is an ignored return value, but is included so we can accept the same
2747 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:412748 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:212749 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:322750 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:412751 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522752 return success;
2753}
2754
[email protected]310ebd6302011-10-10 19:06:282755void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:442756 WebFrame* frame, const WebContextMenuData& data) {
[email protected]3175fea2013-05-16 10:57:482757 ContextMenuParams params = ContextMenuParamsBuilder::Build(data);
[email protected]f56c7872013-06-18 12:31:572758 params.source_type = context_menu_source_type_;
[email protected]a14ddcd2013-06-21 22:53:032759 if (context_menu_source_type_ == ui::MENU_SOURCE_TOUCH_EDIT_MENU) {
[email protected]f56c7872013-06-18 12:31:572760 params.x = touch_editing_context_menu_location_.x();
2761 params.y = touch_editing_context_menu_location_.y();
2762 }
[email protected]b2e4c70132013-10-03 02:07:512763 OnShowHostContextMenu(&params);
[email protected]7fcd9b72011-07-27 16:52:372764
[email protected]329266d2012-09-27 06:20:572765 // Plugins, e.g. PDF, don't currently update the render view when their
2766 // selected text changes, but the context menu params do contain the updated
2767 // selection. If that's the case, update the render view's state just prior
2768 // to showing the context menu.
2769 // TODO(asvitkine): http://crbug.com/152432
[email protected]432c9a72013-02-27 01:51:032770 if (ShouldUpdateSelectionTextFromContextMenuParams(selection_text_,
2771 selection_text_offset_,
2772 selection_range_,
2773 params)) {
[email protected]329266d2012-09-27 06:20:572774 selection_text_ = params.selection_text;
2775 // TODO(asvitkine): Text offset and range is not available in this case.
2776 selection_text_offset_ = 0;
[email protected]db4fc1e2013-09-06 20:01:512777 selection_range_ = gfx::Range(0, selection_text_.length());
[email protected]329266d2012-09-27 06:20:572778 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2779 selection_text_,
2780 selection_text_offset_,
2781 selection_range_));
2782 }
2783
[email protected]7fcd9b72011-07-27 16:52:372784 // frame is NULL if invoked by BlockedPlugin.
2785 if (frame)
2786 params.frame_id = frame->identifier();
2787
[email protected]e9ff79c2012-10-19 21:31:262788 // Serializing a GURL longer than kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:272789 // it. We replace it with an empty GURL so the appropriate items are disabled
2790 // in the context menu.
2791 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2792 // data encoded images. We should have a way to save them.
[email protected]e9ff79c2012-10-19 21:31:262793 if (params.src_url.spec().size() > kMaxURLChars)
[email protected]216932c2010-08-26 21:44:272794 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102795 context_menu_node_ = data.node;
[email protected]44daa3b2012-09-27 19:26:412796
2797#if defined(OS_ANDROID)
2798 gfx::Rect start_rect;
2799 gfx::Rect end_rect;
2800 GetSelectionBounds(&start_rect, &end_rect);
[email protected]326a2342013-02-15 15:47:512801 params.selection_start = gfx::Point(start_rect.x(), start_rect.bottom());
2802 params.selection_end = gfx::Point(end_rect.right(), end_rect.bottom());
[email protected]44daa3b2012-09-27 19:26:412803#endif
2804
[email protected]c27324b2009-11-19 22:44:292805 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]b2324b092012-11-01 10:34:112806
2807 FOR_EACH_OBSERVER(
2808 RenderViewObserver, observers_, DidRequestShowContextMenu(frame, data));
[email protected]79e37442009-10-09 18:17:442809}
2810
[email protected]8b67f78f2013-08-13 12:04:302811void RenderViewImpl::clearContextMenu() {
2812 context_menu_node_.reset();
2813}
2814
[email protected]310ebd6302011-10-10 19:06:282815void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:522816}
2817
[email protected]310ebd6302011-10-10 19:06:282818void RenderViewImpl::UpdateTargetURL(const GURL& url,
2819 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582820 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522821 if (latest_url == target_url_)
2822 return;
[email protected]163f8242009-10-30 20:19:552823
[email protected]48c9cf2d2009-09-16 16:47:522824 // Tell the browser to display a destination link.
2825 if (target_url_status_ == TARGET_INFLIGHT ||
2826 target_url_status_ == TARGET_PENDING) {
2827 // If we have a request in-flight, save the URL to be sent when we
2828 // receive an ACK to the in-flight request. We can happily overwrite
2829 // any existing pending sends.
2830 pending_target_url_ = latest_url;
2831 target_url_status_ = TARGET_PENDING;
2832 } else {
[email protected]e9ff79c2012-10-19 21:31:262833 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:412834 // see |ParamTraits<GURL>|.
[email protected]e9ff79c2012-10-19 21:31:262835 if (latest_url.possibly_invalid_spec().size() > kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:412836 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:522837 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2838 target_url_ = latest_url;
2839 target_url_status_ = TARGET_INFLIGHT;
2840 }
2841}
2842
[email protected]70221f02013-01-31 22:17:072843gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect(
2844 const gfx::RectF& rect) const {
2845 gfx::RectF window_rect = rect;
2846 window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor());
2847 return window_rect;
2848}
2849
[email protected]7d08a9352013-10-15 08:24:562850int64 RenderViewImpl::GetLatencyComponentId() {
2851 // Note: this must match the logic in RenderWidgetHostImpl.
2852 return GetRoutingID() | (static_cast<int64>(
2853 RenderThreadImpl::current()->renderer_process_id()) << 32);
2854}
2855
[email protected]310ebd6302011-10-10 19:06:282856void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]a183fb82012-12-14 04:46:222857 // No need to update state if no page has committed yet.
2858 if (page_id_ == -1)
2859 return;
2860
[email protected]882daa92009-11-05 16:31:312861 int delay;
2862 if (send_content_state_immediately_)
2863 delay = 0;
2864 else if (is_hidden())
2865 delay = kDelaySecondsForContentStateSyncHidden;
2866 else
2867 delay = kDelaySecondsForContentStateSync;
2868
2869 if (nav_state_sync_timer_.IsRunning()) {
2870 // The timer is already running. If the delay of the timer maches the amount
2871 // we want to delay by, then return. Otherwise stop the timer so that it
2872 // gets started with the right delay.
2873 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2874 return;
2875 nav_state_sync_timer_.Stop();
2876 }
2877
[email protected]d323a172011-09-02 18:23:022878 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:282879 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:312880}
2881
[email protected]310ebd6302011-10-10 19:06:282882void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552883 mouse_over_url_ = GURL(url);
2884 UpdateTargetURL(mouse_over_url_, focus_url_);
2885}
2886
[email protected]310ebd6302011-10-10 19:06:282887void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552888 focus_url_ = GURL(url);
2889 UpdateTargetURL(focus_url_, mouse_over_url_);
2890}
2891
[email protected]0407e422012-05-18 19:51:252892void RenderViewImpl::startDragging(WebFrame* frame,
2893 const WebDragData& data,
[email protected]310ebd6302011-10-10 19:06:282894 WebDragOperationsMask mask,
2895 const WebImage& image,
[email protected]ceb36f7d2012-10-31 18:33:242896 const WebPoint& webImageOffset) {
[email protected]dc293a72013-07-01 11:11:222897 DropData drop_data(DropDataBuilder::Build(data));
[email protected]b67151d2012-05-25 23:23:242898 drop_data.referrer_policy = frame->document().referrerPolicy();
[email protected]ceb36f7d2012-10-31 18:33:242899 gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y);
[email protected]59f4f2fa2011-03-23 01:00:552900 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]b67151d2012-05-25 23:23:242901 drop_data,
[email protected]c27ae592010-03-18 15:24:412902 mask,
[email protected]976127072012-05-10 20:08:112903 image.getSkBitmap(),
[email protected]41d86852012-11-07 12:23:242904 imageOffset,
2905 possible_drag_event_info_));
[email protected]48c9cf2d2009-09-16 16:47:522906}
2907
[email protected]310ebd6302011-10-10 19:06:282908bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:452909 return renderer_preferences_.can_accept_load_drops;
2910}
2911
[email protected]310ebd6302011-10-10 19:06:282912void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:522913 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2914}
2915
[email protected]310ebd6302011-10-10 19:06:282916void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:522917 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2918}
2919
[email protected]310ebd6302011-10-10 19:06:282920void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512921 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072922
[email protected]38b592902011-04-16 02:08:422923 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:492924}
2925
[email protected]572a6ca2012-10-11 19:38:012926void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
2927 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
2928}
2929
[email protected]169d4282011-11-30 19:33:592930void RenderViewImpl::didUpdateLayout() {
[email protected]d01b2a62013-09-18 23:21:332931 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidUpdateLayout());
2932
[email protected]169d4282011-11-30 19:33:592933 // We don't always want to set up a timer, only if we've been put in that
2934 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2935 // message.
2936 if (!send_preferred_size_changes_ || !webview())
2937 return;
2938
2939 if (check_preferred_size_timer_.IsRunning())
2940 return;
2941 check_preferred_size_timer_.Start(FROM_HERE,
2942 TimeDelta::FromMilliseconds(0), this,
2943 &RenderViewImpl::CheckPreferredSize);
2944}
2945
[email protected]310ebd6302011-10-10 19:06:282946void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522947 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2948}
2949
[email protected]310ebd6302011-10-10 19:06:282950int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002951 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522952}
2953
[email protected]310ebd6302011-10-10 19:06:282954int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002955 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522956}
2957
[email protected]10760e4a2013-09-04 23:32:202958void RenderViewImpl::postAccessibilityEvent(
[email protected]180ef242013-11-07 06:50:462959 const WebAXObject& obj, blink::WebAXEvent event) {
[email protected]2a84f9d2012-06-05 21:50:432960 if (renderer_accessibility_) {
[email protected]10760e4a2013-09-04 23:32:202961 renderer_accessibility_->HandleWebAccessibilityEvent(obj, event);
[email protected]2a84f9d2012-06-05 21:50:432962 }
[email protected]063afcb2011-09-29 07:54:322963}
2964
[email protected]310ebd6302011-10-10 19:06:282965void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:142966 const WebString& value) {
2967 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2968 key.utf8(),
2969 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262970}
2971
[email protected]180ef242013-11-07 06:50:462972// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:512973
[email protected]310ebd6302011-10-10 19:06:282974void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122975 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2976 // we won't have to test for user gesture anymore and we can
2977 // move that code back to render_widget.cc
[email protected]af15bf22013-03-08 01:18:172978 if (WebUserGestureIndicator::isProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:302979 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]e1176152013-03-06 09:16:442980 Send(new ViewHostMsg_Focus(routing_id_));
[email protected]ea42e7782010-08-23 23:58:122981 }
2982}
2983
[email protected]310ebd6302011-10-10 19:06:282984void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122985 // TODO(jcivelli): see TODO above in didFocus().
[email protected]af15bf22013-03-08 01:18:172986 if (WebUserGestureIndicator::isProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:302987 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]e1176152013-03-06 09:16:442988 Send(new ViewHostMsg_Blur(routing_id_));
[email protected]ea42e7782010-08-23 23:58:122989 }
2990}
2991
initial.commit09911bf2008-07-26 23:55:292992// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282993// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292994// point to dispatch the ShowView message.
2995//
2996// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282997// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292998//
[email protected]310ebd6302011-10-10 19:06:282999void RenderViewImpl::show(WebNavigationPolicy policy) {
[email protected]b2142e962012-10-30 13:59:253000 if (did_show_) {
[email protected]b2142e962012-10-30 13:59:253001 // When supports_multiple_windows is disabled, popups are reusing
3002 // the same view. In some scenarios, this makes WebKit to call show() twice.
[email protected]c9edabd2013-05-23 13:56:243003 if (webkit_preferences_.supports_multiple_windows)
3004 NOTREACHED() << "received extraneous Show call";
initial.commit09911bf2008-07-26 23:55:293005 return;
[email protected]b2142e962012-10-30 13:59:253006 }
initial.commit09911bf2008-07-26 23:55:293007 did_show_ = true;
3008
[email protected]b2142e962012-10-30 13:59:253009 DCHECK(opener_id_ != MSG_ROUTING_NONE);
3010
[email protected]28295ec2009-10-16 05:34:333011 // Force new windows to a popup if they were not opened with a user gesture.
3012 if (!opened_by_user_gesture_) {
3013 // We exempt background tabs for compat with older versions of Chrome.
3014 // TODO(darin): This seems bogus. These should have a user gesture, so
3015 // we probably don't need this check.
[email protected]180ef242013-11-07 06:50:463016 if (policy != blink::WebNavigationPolicyNewBackgroundTab)
3017 policy = blink::WebNavigationPolicyNewPopup;
[email protected]28295ec2009-10-16 05:34:333018 }
3019
initial.commit09911bf2008-07-26 23:55:293020 // NOTE: initial_pos_ may still have its default values at this point, but
3021 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
3022 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:283023 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
3024 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:293025 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:243026 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:293027}
3028
[email protected]310ebd6302011-10-10 19:06:283029void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:293030 DCHECK(did_show_) << "should already have shown the view";
3031
[email protected]88f10a22013-11-06 21:22:123032 // Don't allow further dialogs if we are waiting to swap out, since the
3033 // PageGroupLoadDeferrer in our stack prevents it.
3034 if (suppress_dialogs_until_swap_out_)
3035 return;
3036
[email protected]c1f50aa2010-02-18 03:46:573037 // We must keep WebKit's shared timer running in this case in order to allow
3038 // showModalDialog to function properly.
3039 //
3040 // TODO(darin): WebKit should really be smarter about suppressing events and
3041 // timers so that we do not need to manage the shared timer in such a heavy
3042 // handed manner.
3043 //
[email protected]f1a29a02011-10-06 23:08:443044 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
3045 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:573046
[email protected]08a1c8102012-05-11 23:14:263047 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
3048 routing_id_, opener_id_));
initial.commit09911bf2008-07-26 23:55:293049}
3050
[email protected]2b624c562011-10-27 22:58:263051bool RenderViewImpl::enterFullScreen() {
3052 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
3053 return true;
3054}
3055
3056void RenderViewImpl::exitFullScreen() {
3057 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
3058}
3059
[email protected]217690d2012-01-27 07:33:113060bool RenderViewImpl::requestPointerLock() {
3061 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
3062}
3063
3064void RenderViewImpl::requestPointerUnlock() {
3065 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
3066}
3067
3068bool RenderViewImpl::isPointerLocked() {
3069 return mouse_lock_dispatcher_->IsMouseLockedTo(
3070 webwidget_mouse_lock_target_.get());
3071}
3072
[email protected]7a1ec28a2012-03-28 21:10:243073void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
[email protected]0cd50aa2013-02-12 22:28:013074#if !defined(OS_MACOSX) // many events are unhandled - http://crbug.com/138003
[email protected]ea5f70a2013-03-07 12:30:363075 InputHandlerManager* input_handler_manager =
3076 RenderThreadImpl::current()->input_handler_manager();
[email protected]200a9c062013-05-20 04:34:373077 if (input_handler_manager) {
3078 input_handler_manager->AddInputHandler(
3079 routing_id_,
3080 compositor_->GetInputHandler(),
3081 AsWeakPtr());
3082 }
[email protected]70cff27502013-01-17 09:16:493083#endif
[email protected]7a1ec28a2012-03-28 21:10:243084
3085 RenderWidget::didActivateCompositor(input_handler_identifier);
3086}
3087
[email protected]c68c3e4e2013-01-24 00:36:563088void RenderViewImpl::didHandleGestureEvent(
3089 const WebGestureEvent& event,
3090 bool event_cancelled) {
3091 RenderWidget::didHandleGestureEvent(event, event_cancelled);
3092 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3093 DidHandleGestureEvent(event));
3094}
3095
[email protected]6e89eb72013-07-23 13:28:223096void RenderViewImpl::initializeLayerTreeView() {
3097 RenderWidget::initializeLayerTreeView();
3098 RenderWidgetCompositor* rwc = compositor();
3099 if (!rwc || !webview() || !webview()->devToolsAgent())
3100 return;
3101 webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId());
3102}
3103
[email protected]180ef242013-11-07 06:50:463104// blink::WebFrameClient -----------------------------------------------------
[email protected]3d9689372009-09-10 04:29:173105
[email protected]97b150db2012-08-16 18:26:023106WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]180ef242013-11-07 06:50:463107 WebFrame* frame, const blink::WebURL& url, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:443108 FOR_EACH_OBSERVER(
3109 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:173110
[email protected]40bed812013-11-05 06:59:153111 WebMediaPlayer* player = CreateWebMediaPlayerForMediaStream(frame, url,
3112 client);
3113 if (player)
3114 return player;
[email protected]d05e2162012-11-16 22:21:463115
[email protected]25fb9b32012-04-27 03:21:553116#if defined(OS_ANDROID)
[email protected]40bed812013-11-05 06:59:153117 return CreateAndroidWebMediaPlayer(frame, url, client);
3118#else
[email protected]4a914882013-01-10 00:43:483119 scoped_refptr<media::AudioRendererSink> sink;
[email protected]40bed812013-11-05 06:59:153120 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableAudio)) {
[email protected]17c4ce62f2013-05-03 19:54:023121 sink = RenderThreadImpl::current()->GetAudioRendererMixerManager()->
3122 CreateInput(routing_id_);
[email protected]fc72bb12013-06-02 21:13:463123 DVLOG(1) << "Using AudioRendererMixerManager-provided sink: " << sink.get();
[email protected]3d9689372009-09-10 04:29:173124 }
3125
[email protected]5e35a8d2013-07-10 19:37:213126 WebMediaPlayerParams params(
[email protected]c1330c82013-06-06 02:23:253127 RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy(),
[email protected]d726eddc2013-07-02 22:25:553128 base::Bind(&ContentRendererClient::DeferMediaLoad,
3129 base::Unretained(GetContentClient()->renderer()),
3130 static_cast<RenderView*>(this)),
3131 sink,
[email protected]c50edb962013-10-19 18:05:073132 RenderThreadImpl::current()->GetGpuFactories(),
[email protected]d726eddc2013-07-02 22:25:553133 new RenderMediaLog());
[email protected]5e35a8d2013-07-10 19:37:213134 return new WebMediaPlayerImpl(frame, client, AsWeakPtr(), params);
[email protected]40bed812013-11-05 06:59:153135#endif // defined(OS_ANDROID)
[email protected]3d9689372009-09-10 04:29:173136}
3137
[email protected]310ebd6302011-10-10 19:06:283138WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:383139 return &cookie_jar_;
3140}
3141
[email protected]59167c22013-06-03 18:07:323142void RenderViewImpl::didAccessInitialDocument(WebFrame* frame) {
3143 // Notify the browser process that it is no longer safe to show the pending
3144 // URL of the main frame, since a URL spoof is now possible.
3145 if (!frame->parent() && page_id_ == -1)
3146 Send(new ViewHostMsg_DidAccessInitialDocument(routing_id_));
3147}
3148
[email protected]180ef242013-11-07 06:50:463149void RenderViewImpl::didDisownOpener(blink::WebFrame* frame) {
[email protected]29ece2e2013-04-03 04:53:523150 // We only need to notify the browser if the active, top-level frame clears
3151 // its opener. We can ignore cases where a swapped out frame clears its
3152 // opener after hearing about it from the browser, and the browser does not
3153 // (yet) care about subframe openers.
3154 if (is_swapped_out_ || frame->parent())
[email protected]7cc78902012-12-06 02:32:263155 return;
3156
3157 // Notify WebContents and all its swapped out RenderViews.
3158 Send(new ViewHostMsg_DidDisownOpener(routing_id_));
3159}
3160
[email protected]310ebd6302011-10-10 19:06:283161void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:513162 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:453163}
3164
[email protected]310ebd6302011-10-10 19:06:283165void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:513166 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:173167}
3168
[email protected]f5b6dd1122013-10-04 02:42:503169void RenderViewImpl::didMatchCSS(
3170 WebFrame* frame,
3171 const WebVector<WebString>& newly_matching_selectors,
3172 const WebVector<WebString>& stopped_matching_selectors) {
3173 FOR_EACH_OBSERVER(
3174 RenderViewObserver, observers_,
3175 DidMatchCSS(frame, newly_matching_selectors, stopped_matching_selectors));
3176}
3177
[email protected]5e92282f2012-08-17 08:11:573178void RenderViewImpl::Repaint(const gfx::Size& size) {
[email protected]3d9ec5052013-01-02 22:05:253179 OnRepaint(size);
[email protected]5e92282f2012-08-17 08:11:573180}
3181
[email protected]b2324b092012-11-01 10:34:113182void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
3183 const std::string& value) {
3184 EditCommands edit_commands;
3185 edit_commands.push_back(EditCommand(name, value));
3186 OnSetEditCommandsForNextKeyEvent(edit_commands);
3187}
3188
3189void RenderViewImpl::ClearEditCommands() {
3190 edit_commands_.clear();
3191}
3192
[email protected]180ef242013-11-07 06:50:463193SSLStatus RenderViewImpl::GetSSLStatusOfFrame(blink::WebFrame* frame) const {
[email protected]83c0abca2013-07-23 20:09:423194 std::string security_info;
3195 if (frame && frame->dataSource())
3196 security_info = frame->dataSource()->response().securityInfo();
3197
3198 SSLStatus ssl_status;
3199 DeserializeSecurityInfo(security_info,
3200 &ssl_status.cert_id,
3201 &ssl_status.cert_status,
3202 &ssl_status.security_bits,
3203 &ssl_status.connection_status);
3204 return ssl_status;
[email protected]e4495212012-12-06 03:09:123205}
3206
[email protected]b38806a2013-10-04 16:01:383207const std::string& RenderViewImpl::GetAcceptLanguages() const {
3208 return renderer_preferences_.accept_languages;
3209}
3210
[email protected]310ebd6302011-10-10 19:06:283211WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]0d8f04b2013-04-29 20:05:313212 WebFrame* frame, WebDataSource::ExtraData* extraData,
3213 const WebURLRequest& request, WebNavigationType type,
3214 WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]099df81cf2012-11-14 17:44:043215 if (request.url() != GURL(kSwappedOutURL) &&
3216 GetContentClient()->renderer()->HandleNavigation(frame, request, type,
3217 default_policy,
3218 is_redirect)) {
[email protected]180ef242013-11-07 06:50:463219 return blink::WebNavigationPolicyIgnore;
[email protected]099df81cf2012-11-14 17:44:043220 }
3221
[email protected]44e55b012013-07-23 14:21:563222 Referrer referrer(GetReferrerFromRequest(frame, request));
[email protected]0639c063a2012-03-22 20:55:333223
[email protected]992db4c2011-05-12 15:37:153224 if (is_swapped_out_) {
[email protected]e9ff79c2012-10-19 21:31:263225 if (request.url() != GURL(kSwappedOutURL)) {
[email protected]0639c063a2012-03-22 20:55:333226 // Targeted links may try to navigate a swapped out frame. Allow the
3227 // browser process to navigate the tab instead. Note that it is also
3228 // possible for non-targeted navigations (from this view) to arrive
3229 // here just after we are swapped out. It's ok to send them to the
3230 // browser, as long as they're for the top level frame.
3231 // TODO(creis): Ensure this supports targeted form submissions when
3232 // fixing http://crbug.com/101395.
3233 if (frame->parent() == NULL) {
3234 OpenURL(frame, request.url(), referrer, default_policy);
[email protected]180ef242013-11-07 06:50:463235 return blink::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]0639c063a2012-03-22 20:55:333236 }
3237
3238 // We should otherwise ignore in-process iframe navigations, if they
3239 // arrive just after we are swapped out.
[email protected]180ef242013-11-07 06:50:463240 return blink::WebNavigationPolicyIgnore;
[email protected]0639c063a2012-03-22 20:55:333241 }
[email protected]73eb2602012-02-09 19:50:553242
[email protected]e9ff79c2012-10-19 21:31:263243 // Allow kSwappedOutURL to complete.
[email protected]992db4c2011-05-12 15:37:153244 return default_policy;
3245 }
3246
[email protected]3d9689372009-09-10 04:29:173247 // Webkit is asking whether to navigate to a new URL.
3248 // This is fine normally, except if we're showing UI from one security
3249 // context and they're trying to navigate to a different context.
3250 const GURL& url = request.url();
3251
[email protected]d19ea342011-04-20 20:31:133252 // A content initiated navigation may have originated from a link-click,
3253 // script, drag-n-drop operation, etc.
[email protected]0d8f04b2013-04-29 20:05:313254 bool is_content_initiated = static_cast<DocumentState*>(extraData)->
[email protected]007733c2011-11-17 00:34:073255 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:133256
[email protected]a8c269a2011-10-25 20:17:223257 // Experimental:
[email protected]c6f2e672012-11-15 01:47:023258 // If --enable-strict-site-isolation or --site-per-process is enabled, send
3259 // all top-level navigations to the browser to let it swap processes when
3260 // crossing site boundaries. This is currently expected to break some script
3261 // calls and navigations, such as form submissions.
[email protected]a8c269a2011-10-25 20:17:223262 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]c6f2e672012-11-15 01:47:023263 bool force_swap_due_to_flag =
3264 command_line.HasSwitch(switches::kEnableStrictSiteIsolation) ||
3265 command_line.HasSwitch(switches::kSitePerProcess);
3266 if (force_swap_due_to_flag &&
[email protected]313b80bd2011-11-23 03:49:103267 !frame->parent() && (is_content_initiated || is_redirect)) {
3268 WebString origin_str = frame->document().securityOrigin().toString();
3269 GURL frame_url(origin_str.utf8().data());
[email protected]18fb7a772012-09-20 19:25:093270 // TODO(cevans): revisit whether this site check is still necessary once
[email protected]313b80bd2011-11-23 03:49:103271 // crbug.com/101395 is fixed.
[email protected]ed32c212013-05-14 20:49:293272 bool same_domain_or_host =
3273 net::registry_controlled_domains::SameDomainOrHost(
3274 frame_url,
3275 url,
3276 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
3277 if (!same_domain_or_host || frame_url.scheme() != url.scheme()) {
[email protected]313b80bd2011-11-23 03:49:103278 OpenURL(frame, url, referrer, default_policy);
[email protected]180ef242013-11-07 06:50:463279 return blink::WebNavigationPolicyIgnore;
[email protected]313b80bd2011-11-23 03:49:103280 }
[email protected]a8c269a2011-10-25 20:17:223281 }
3282
[email protected]fd3238af2012-05-22 18:55:303283 // If the browser is interested, then give it a chance to look at the request.
[email protected]5f000f272012-01-19 05:25:083284 if (is_content_initiated) {
[email protected]180ef242013-11-07 06:50:463285 bool is_form_post = ((type == blink::WebNavigationTypeFormSubmitted) ||
3286 (type == blink::WebNavigationTypeFormResubmitted)) &&
[email protected]140a5882013-07-23 19:30:333287 EqualsASCII(request.httpMethod(), "POST");
[email protected]fd3238af2012-05-22 18:55:303288 bool browser_handles_request =
3289 renderer_preferences_.browser_handles_non_local_top_level_requests &&
[email protected]140a5882013-07-23 19:30:333290 IsNonLocalTopLevelNavigation(url, frame, type, is_form_post);
[email protected]fd3238af2012-05-22 18:55:303291 if (!browser_handles_request) {
3292 browser_handles_request =
3293 renderer_preferences_.browser_handles_all_top_level_requests &&
3294 IsTopLevelNavigation(frame);
3295 }
3296
3297 if (browser_handles_request) {
[email protected]5f000f272012-01-19 05:25:083298 // Reset these counters as the RenderView could be reused for the next
3299 // navigation.
3300 page_id_ = -1;
3301 last_page_id_sent_to_browser_ = -1;
3302 OpenURL(frame, url, referrer, default_policy);
[email protected]180ef242013-11-07 06:50:463303 return blink::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]5f000f272012-01-19 05:25:083304 }
[email protected]3d9689372009-09-10 04:29:173305 }
3306
[email protected]dc67e1c32012-06-08 00:10:403307 // Use the frame's original request's URL rather than the document's URL for
3308 // subsequent checks. For a popup, the document's URL may become the opener
3309 // window's URL if the opener has called document.write().
3310 // See http://crbug.com/93517.
3311 GURL old_url(frame->dataSource()->request().url());
3312
[email protected]6101c342010-12-16 22:44:373313 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:553314 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:043315 // top-level navigations (not iframes). But we sometimes navigate to
3316 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:373317 //
[email protected]744c2a22012-03-15 18:42:043318 // Note: this is known to break POST submissions when crossing process
3319 // boundaries until http://crbug.com/101395 is fixed. This is better for
3320 // security than loading a WebUI, extension or app page in the wrong process.
3321 // POST requests don't work because this mechanism does not preserve form
3322 // POST data. We will need to send the request's httpBody data up to the
3323 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:573324 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
3325 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:223326 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:043327 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:373328 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:043329
[email protected]0a57375a2013-03-07 22:18:593330 // All navigations to or from WebUI URLs or within WebUI-enabled
3331 // RenderProcesses must be handled by the browser process so that the
3332 // correct bindings and data sources can be registered.
[email protected]744c2a22012-03-15 18:42:043333 // Similarly, navigations to view-source URLs or within ViewSource mode
[email protected]1c210f692012-11-06 22:31:473334 // must be handled by the browser process (except for reloads - those are
3335 // safe to leave within the renderer).
[email protected]dc67e1c32012-06-08 00:10:403336 // Lastly, access to file:// URLs from non-file:// URL pages must be
3337 // handled by the browser so that ordinary renderer processes don't get
3338 // blessed with file permissions.
3339 int cumulative_bindings = RenderProcess::current()->GetEnabledBindings();
3340 bool is_initial_navigation = page_id_ == -1;
[email protected]0a57375a2013-03-07 22:18:593341 bool should_fork = HasWebUIScheme(url) || HasWebUIScheme(old_url) ||
[email protected]e9ff79c2012-10-19 21:31:263342 (cumulative_bindings & BINDINGS_POLICY_WEB_UI) ||
[email protected]dbdda5402013-05-30 22:13:483343 url.SchemeIs(kViewSourceScheme) ||
[email protected]1c210f692012-11-06 22:31:473344 (frame->isViewSourceModeEnabled() &&
[email protected]180ef242013-11-07 06:50:463345 type != blink::WebNavigationTypeReload);
[email protected]5351dbc2010-08-27 15:22:113346
[email protected]dc67e1c32012-06-08 00:10:403347 if (!should_fork && url.SchemeIs(chrome::kFileScheme)) {
3348 // Fork non-file to file opens. Check the opener URL if this is the
3349 // initial navigation in a newly opened window.
3350 GURL source_url(old_url);
3351 if (is_initial_navigation && source_url.is_empty() && frame->opener())
3352 source_url = frame->opener()->top()->document().url();
3353 DCHECK(!source_url.is_empty());
3354 should_fork = !source_url.SchemeIs(chrome::kFileScheme);
3355 }
3356
[email protected]e48869a2011-04-01 19:56:033357 if (!should_fork) {
3358 // Give the embedder a chance.
[email protected]c5dec6292013-01-25 04:54:523359 should_fork = GetContentClient()->renderer()->ShouldFork(
3360 frame, url, request.httpMethod().utf8(), is_initial_navigation,
[email protected]b0a29f22013-05-30 23:00:093361 is_redirect, &send_referrer);
[email protected]6101c342010-12-16 22:44:373362 }
3363
3364 if (should_fork) {
[email protected]445e1042011-12-03 21:03:153365 OpenURL(
3366 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]180ef242013-11-07 06:50:463367 return blink::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]5351dbc2010-08-27 15:22:113368 }
[email protected]3d9689372009-09-10 04:29:173369 }
3370
3371 // Detect when a page is "forking" a new tab that can be safely rendered in
3372 // its own process. This is done by sites like Gmail that try to open links
3373 // in new windows without script connections back to the original page. We
3374 // treat such cases as browser navigations (in which we will create a new
3375 // renderer for a cross-site navigation), rather than WebKit navigations.
3376 //
3377 // We use the following heuristic to decide whether to fork a new page in its
3378 // own process:
3379 // The parent page must open a new tab to about:blank, set the new tab's
3380 // window.opener to null, and then redirect the tab to a cross-site URL using
3381 // JavaScript.
[email protected]007a848b2009-10-26 15:55:463382 //
3383 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
3384 // (see below).
[email protected]3d9689372009-09-10 04:29:173385 bool is_fork =
3386 // Must start from a tab showing about:blank, which is later redirected.
[email protected]081dc522013-05-15 04:59:203387 old_url == GURL(kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:173388 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:523389 historyBackListCount() < 1 &&
3390 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:173391 // The parent page must have set the child's window.opener to null before
3392 // redirecting to the desired URL.
3393 frame->opener() == NULL &&
3394 // Must be a top-level frame.
3395 frame->parent() == NULL &&
3396 // Must not have issued the request from this page.
3397 is_content_initiated &&
3398 // Must be targeted at the current tab.
[email protected]180ef242013-11-07 06:50:463399 default_policy == blink::WebNavigationPolicyCurrentTab &&
[email protected]3d9689372009-09-10 04:29:173400 // Must be a JavaScript navigation, which appears as "other".
[email protected]180ef242013-11-07 06:50:463401 type == blink::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:463402
[email protected]f92ce2b2012-03-06 18:02:593403 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:173404 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:153405 OpenURL(frame, url, Referrer(), default_policy);
[email protected]180ef242013-11-07 06:50:463406 return blink::WebNavigationPolicyIgnore;
[email protected]3d9689372009-09-10 04:29:173407 }
3408
3409 return default_policy;
3410}
3411
[email protected]f4f40a052013-04-19 15:28:113412WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
3413 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]89bc54c62013-04-24 01:51:333414 WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]0d8f04b2013-04-29 20:05:313415 return decidePolicyForNavigation(frame,
3416 frame->provisionalDataSource()->extraData(),
[email protected]89bc54c62013-04-24 01:51:333417 request, type, default_policy, is_redirect);
[email protected]f4f40a052013-04-19 15:28:113418}
3419
[email protected]180ef242013-11-07 06:50:463420void RenderViewImpl::willSendSubmitEvent(blink::WebFrame* frame,
3421 const blink::WebFormElement& form) {
[email protected]0660a8c2013-08-16 01:09:123422 FOR_EACH_OBSERVER(
3423 RenderViewObserver, observers_, WillSendSubmitEvent(frame, form));
[email protected]90eeddb2010-05-06 21:06:433424}
3425
[email protected]310ebd6302011-10-10 19:06:283426void RenderViewImpl::willSubmitForm(WebFrame* frame,
3427 const WebFormElement& form) {
[email protected]2a5b1732011-04-01 23:55:553428 FOR_EACH_OBSERVER(
3429 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:173430}
3431
[email protected]310ebd6302011-10-10 19:06:283432void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:573433 bool content_initiated = !pending_navigation_params_.get();
3434
[email protected]f8872902013-10-30 03:18:573435 // Make sure any previous redirect URLs end up in our new data source.
3436 if (pending_navigation_params_.get()) {
3437 for (std::vector<GURL>::const_iterator i =
3438 pending_navigation_params_->redirects.begin();
3439 i != pending_navigation_params_->redirects.end(); ++i) {
3440 ds->appendRedirect(*i);
3441 }
3442 }
3443
[email protected]007733c2011-11-17 00:34:073444 DocumentState* document_state = DocumentState::FromDataSource(ds);
3445 if (!document_state) {
3446 document_state = new DocumentState;
3447 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:573448 if (!content_initiated)
3449 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:073450 }
3451
[email protected]bf70edce2012-06-20 22:32:223452 // Carry over the user agent override flag, if it exists.
3453 if (content_initiated && webview() && webview()->mainFrame() &&
3454 webview()->mainFrame()->dataSource()) {
3455 DocumentState* old_document_state =
3456 DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
3457 if (old_document_state) {
[email protected]e20b88d2013-04-09 15:28:373458 InternalDocumentStateData* internal_data =
3459 InternalDocumentStateData::FromDocumentState(document_state);
3460 InternalDocumentStateData* old_internal_data =
3461 InternalDocumentStateData::FromDocumentState(old_document_state);
3462 internal_data->set_is_overriding_user_agent(
3463 old_internal_data->is_overriding_user_agent());
[email protected]bf70edce2012-06-20 22:32:223464 }
3465 }
3466
[email protected]3d9689372009-09-10 04:29:173467 // The rest of RenderView assumes that a WebDataSource will always have a
3468 // non-null NavigationState.
[email protected]e1ed5a12012-08-08 19:57:443469 if (content_initiated) {
[email protected]007733c2011-11-17 00:34:073470 document_state->set_navigation_state(
3471 NavigationState::CreateContentInitiated());
[email protected]e1ed5a12012-08-08 19:57:443472 } else {
[email protected]45d83a12012-04-06 22:57:573473 document_state->set_navigation_state(CreateNavigationStateFromPending());
3474 pending_navigation_params_.reset();
3475 }
[email protected]8a3125a712010-08-09 18:58:513476
[email protected]007733c2011-11-17 00:34:073477 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:513478 // navigating from a page that used prefetching using a link on that
3479 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:073480 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:513481 // this value appropriately.
3482 // TODO(gavinp): catch the important case of navigation in a new
3483 // renderer process.
3484 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303485 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523486 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513487 const GURL referrer(
3488 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3489 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:073490 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:513491 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:413492 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:513493 WebDataSource* old_frame_ds = old_frame->dataSource();
3494 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:073495 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513496 break;
3497 }
3498 }
3499 }
3500 }
3501 }
3502
[email protected]4c1b6f0b2010-02-07 16:38:183503 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523504 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513505 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183506 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:073507 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:183508 break;
3509 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:073510 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:183511 break;
3512 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:073513 document_state->set_load_type(
3514 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:183515 break;
3516 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:073517 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:183518 break;
3519 }
3520 }
[email protected]fa7b6b542009-11-03 05:02:303521
[email protected]946a0032011-03-31 18:42:283522 FOR_EACH_OBSERVER(
3523 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:173524}
3525
[email protected]45d83a12012-04-06 22:57:573526void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:073527 DocumentState* document_state) {
3528 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:573529 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:073530
[email protected]e20b88d2013-04-09 15:28:373531 InternalDocumentStateData* internal_data =
3532 InternalDocumentStateData::FromDocumentState(document_state);
3533
[email protected]44b05812013-08-19 07:59:353534 if (!params.url.SchemeIs(kJavaScriptScheme) &&
[email protected]45d83a12012-04-06 22:57:573535 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
3536 // We're doing a load of a page that was restored from the last session. By
3537 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
3538 // can result in stale data for pages that are set to expire. We explicitly
3539 // override that by setting the policy here so that as necessary we load
3540 // from the network.
[email protected]e20b88d2013-04-09 15:28:373541 internal_data->set_cache_policy_override(
[email protected]45d83a12012-04-06 22:57:573542 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:073543 }
3544
3545 if (IsReload(params))
3546 document_state->set_load_type(DocumentState::RELOAD);
[email protected]691aa2f2013-05-28 22:52:043547 else if (params.page_state.IsValid())
[email protected]007733c2011-11-17 00:34:073548 document_state->set_load_type(DocumentState::HISTORY_LOAD);
3549 else
3550 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]ca662822012-05-11 17:53:593551
[email protected]e20b88d2013-04-09 15:28:373552 internal_data->set_referrer_policy(params.referrer.policy);
3553 internal_data->set_is_overriding_user_agent(params.is_overriding_user_agent);
3554 internal_data->set_must_reset_scroll_and_scale_state(
[email protected]a3a5397d2012-09-12 06:50:343555 params.navigation_type ==
3556 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]951a64832012-10-11 16:26:373557 document_state->set_can_load_local_resources(params.can_load_local_resources);
[email protected]45d83a12012-04-06 22:57:573558}
[email protected]007733c2011-11-17 00:34:073559
[email protected]45d83a12012-04-06 22:57:573560NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
3561 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
3562 NavigationState* navigation_state = NULL;
3563
3564 // A navigation resulting from loading a javascript URL should not be treated
3565 // as a browser initiated event. Instead, we want it to look as if the page
3566 // initiated any load resulting from JS execution.
[email protected]44b05812013-08-19 07:59:353567 if (!params.url.SchemeIs(kJavaScriptScheme)) {
[email protected]45d83a12012-04-06 22:57:573568 navigation_state = NavigationState::CreateBrowserInitiated(
3569 params.page_id,
3570 params.pending_history_list_offset,
[email protected]60d6cca2013-04-30 08:47:133571 params.should_clear_history_list,
[email protected]45d83a12012-04-06 22:57:573572 params.transition);
3573 navigation_state->set_transferred_request_child_id(
3574 params.transferred_request_child_id);
3575 navigation_state->set_transferred_request_request_id(
3576 params.transferred_request_request_id);
[email protected]80744782012-05-04 01:47:003577 navigation_state->set_allow_download(params.allow_download);
[email protected]f050fde2013-03-21 00:40:453578 navigation_state->set_extra_headers(params.extra_headers);
[email protected]45d83a12012-04-06 22:57:573579 } else {
3580 navigation_state = NavigationState::CreateContentInitiated();
3581 }
3582 return navigation_state;
[email protected]007733c2011-11-17 00:34:073583}
3584
[email protected]5b52cd2f712012-03-28 02:12:483585void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
3586 bool enable_viewport =
[email protected]06ea34a2012-05-07 18:52:103587 command_line.HasSwitch(switches::kEnableViewport);
[email protected]5b52cd2f712012-03-28 02:12:483588
[email protected]47e932da2013-03-07 00:11:243589 // If viewport tag is enabled, then the WebKit side will take care
3590 // of setting the fixed layout size and page scale limits.
3591 if (enable_viewport)
3592 return;
3593
[email protected]a02a0c92013-08-12 20:18:583594 // When navigating to a new page, reset the page scale factor to be 1.0.
3595 webview()->setInitialPageScaleOverride(1.f);
3596
[email protected]e4cd82e2013-04-10 15:20:383597 float maxPageScaleFactor =
3598 command_line.HasSwitch(switches::kEnablePinch) ? 4.f : 1.f ;
3599 webview()->setPageScaleFactorLimits(1, maxPageScaleFactor);
[email protected]5b52cd2f712012-03-28 02:12:483600}
3601
[email protected]8672bbf2013-10-22 13:37:083602// TODO(nasko): Remove this method once WebTestProxy in Blink is fixed.
[email protected]310ebd6302011-10-10 19:06:283603void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173604}
3605
[email protected]400992b2012-06-14 00:03:543606void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
3607 WebFrame* frame) {
3608 if (frame->parent())
3609 return;
3610 // Received a redirect on the main frame.
3611 WebDataSource* data_source = frame->provisionalDataSource();
3612 if (!data_source) {
3613 // Should only be invoked when we have a data source.
3614 NOTREACHED();
3615 return;
3616 }
3617 std::vector<GURL> redirects;
3618 GetRedirectChain(data_source, &redirects);
3619 if (redirects.size() >= 2) {
3620 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]434bc9b2012-11-27 21:22:143621 redirects[redirects.size() - 2], redirects.back()));
[email protected]400992b2012-06-14 00:03:543622 }
3623}
3624
[email protected]310ebd6302011-10-10 19:06:283625void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
3626 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173627 // Notify the browser that we failed a provisional load with an error.
3628 //
3629 // Note: It is important this notification occur before DidStopLoading so the
3630 // SSL manager can react to the provisional load failure before being
3631 // notified the load stopped.
3632 //
3633 WebDataSource* ds = frame->provisionalDataSource();
3634 DCHECK(ds);
3635
3636 const WebURLRequest& failed_request = ds->request();
3637
[email protected]28685da92011-02-07 21:49:173638 FOR_EACH_OBSERVER(
3639 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
3640
[email protected]3d9689372009-09-10 04:29:173641 bool show_repost_interstitial =
3642 (error.reason == net::ERR_CACHE_MISS &&
3643 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:583644
3645 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
3646 params.frame_id = frame->identifier();
[email protected]2f673064c2013-10-22 04:01:443647 params.frame_unique_name = frame->uniqueName();
[email protected]d7b175e2011-10-11 15:31:583648 params.is_main_frame = !frame->parent();
3649 params.error_code = error.reason;
[email protected]e9ff79c2012-10-19 21:31:263650 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]8da4d262013-04-23 05:15:533651 frame,
[email protected]d7b175e2011-10-11 15:31:583652 failed_request,
3653 error,
[email protected]b38806a2013-10-04 16:01:383654 renderer_preferences_.accept_languages,
[email protected]d7b175e2011-10-11 15:31:583655 NULL,
3656 &params.error_description);
3657 params.url = error.unreachableURL;
3658 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:173659 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:583660 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:173661
3662 // Don't display an error page if this is simply a cancelled load. Aside
3663 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3664 if (error.reason == net::ERR_ABORTED)
3665 return;
3666
[email protected]f677288e2013-09-18 02:11:003667 // Don't display "client blocked" error page if browser has asked us not to.
3668 if (error.reason == net::ERR_BLOCKED_BY_CLIENT &&
3669 renderer_preferences_.disable_client_blocked_error_page) {
3670 return;
3671 }
3672
[email protected]2309e912013-10-01 01:33:303673 // Allow the embedder to suppress an error page.
3674 if (GetContentClient()->renderer()->ShouldSuppressErrorPage(
3675 error.unreachableURL)) {
[email protected]ac7f5a02013-03-16 16:14:413676 return;
[email protected]2309e912013-10-01 01:33:303677 }
3678
3679 if (RenderThreadImpl::current() &&
3680 RenderThreadImpl::current()->layout_test_mode()) {
3681 return;
3682 }
[email protected]ac7f5a02013-03-16 16:14:413683
[email protected]3d9689372009-09-10 04:29:173684 // Make sure we never show errors in view source mode.
3685 frame->enableViewSourceMode(false);
3686
[email protected]007733c2011-11-17 00:34:073687 DocumentState* document_state = DocumentState::FromDataSource(ds);
3688 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173689
3690 // If this is a failed back/forward/reload navigation, then we need to do a
3691 // 'replace' load. This is necessary to avoid messing up session history.
3692 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3693 // as session history is concerned.
3694 //
3695 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3696 // the page id.
3697 //
3698 bool replace =
3699 navigation_state->pending_page_id() != -1 ||
[email protected]026aac22013-07-10 02:09:113700 PageTransitionCoreTypeIs(navigation_state->transition_type(),
3701 PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:173702
3703 // If we failed on a browser initiated request, then make sure that our error
3704 // page load is regarded as the same browser initiated request.
3705 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:073706 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
3707 pending_navigation_params_->page_id =
3708 navigation_state->pending_page_id();
3709 pending_navigation_params_->pending_history_list_offset =
3710 navigation_state->pending_history_list_offset();
[email protected]60d6cca2013-04-30 08:47:133711 pending_navigation_params_->should_clear_history_list =
3712 navigation_state->history_list_was_cleared();
[email protected]007733c2011-11-17 00:34:073713 pending_navigation_params_->transition =
3714 navigation_state->transition_type();
3715 pending_navigation_params_->request_time =
3716 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:173717 }
3718
3719 // Provide the user with a more helpful error page?
3720 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3721 return;
3722
3723 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083724 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173725}
3726
[email protected]310ebd6302011-10-10 19:06:283727void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
3728 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:073729 DocumentState* document_state =
3730 DocumentState::FromDataSource(frame->dataSource());
3731 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e20b88d2013-04-09 15:28:373732 InternalDocumentStateData* internal_data =
3733 InternalDocumentStateData::FromDocumentState(document_state);
[email protected]3d9689372009-09-10 04:29:173734
[email protected]007733c2011-11-17 00:34:073735 if (document_state->commit_load_time().is_null())
3736 document_state->set_commit_load_time(Time::Now());
3737
[email protected]e20b88d2013-04-09 15:28:373738 if (internal_data->must_reset_scroll_and_scale_state()) {
[email protected]06c7ba022012-12-17 19:24:123739 webview()->resetScrollAndScaleState();
[email protected]e20b88d2013-04-09 15:28:373740 internal_data->set_must_reset_scroll_and_scale_state(false);
[email protected]a3a5397d2012-09-12 06:50:343741 }
[email protected]4b9c9e292013-07-18 19:13:283742 internal_data->set_use_error_page(false);
[email protected]a3a5397d2012-09-12 06:50:343743
[email protected]3d9689372009-09-10 04:29:173744 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203745 // When we perform a new navigation, we need to update the last committed
3746 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173747 UpdateSessionHistory(frame);
3748
3749 // We bump our Page ID to correspond with the new session history entry.
3750 page_id_ = next_page_id_++;
3751
[email protected]e9ff79c2012-10-19 21:31:263752 // Don't update history_page_ids_ (etc) for kSwappedOutURL, since
[email protected]58436a12012-03-21 17:10:263753 // we don't want to forget the entry that was there, and since we will
[email protected]e9ff79c2012-10-19 21:31:263754 // never come back to kSwappedOutURL. Note that we have to call
[email protected]69ddf852012-02-21 23:21:313755 // UpdateSessionHistory and update page_id_ even in this case, so that
3756 // the current entry gets a state update and so that we don't send a
3757 // state update to the wrong entry when we swap back in.
[email protected]e9ff79c2012-10-19 21:31:263758 if (GetLoadingUrl(frame) != GURL(kSwappedOutURL)) {
[email protected]69ddf852012-02-21 23:21:313759 // Advance our offset in session history, applying the length limit.
3760 // There is now no forward history.
3761 history_list_offset_++;
[email protected]e9ff79c2012-10-19 21:31:263762 if (history_list_offset_ >= kMaxSessionHistoryEntries)
3763 history_list_offset_ = kMaxSessionHistoryEntries - 1;
[email protected]69ddf852012-02-21 23:21:313764 history_list_length_ = history_list_offset_ + 1;
3765 history_page_ids_.resize(history_list_length_, -1);
3766 history_page_ids_[history_list_offset_] = page_id_;
3767 }
[email protected]3d9689372009-09-10 04:29:173768 } else {
3769 // Inspect the navigation_state on this frame to see if the navigation
3770 // corresponds to a session history navigation... Note: |frame| may or
3771 // may not be the toplevel frame, but for the case of capturing session
3772 // history, the first committed frame suffices. We keep track of whether
3773 // we've seen this commit before so that only capture session history once
3774 // per navigation.
3775 //
3776 // Note that we need to check if the page ID changed. In the case of a
3777 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3778 // previous URL and the current page ID, which would be wrong.
3779 if (navigation_state->pending_page_id() != -1 &&
3780 navigation_state->pending_page_id() != page_id_ &&
3781 !navigation_state->request_committed()) {
3782 // This is a successful session history navigation!
3783 UpdateSessionHistory(frame);
3784 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003785
3786 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:033787
3788 // If the history list is valid, our list of page IDs should be correct.
3789 DCHECK(history_list_length_ <= 0 ||
3790 history_list_offset_ < 0 ||
3791 history_list_offset_ >= history_list_length_ ||
3792 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:173793 }
3794 }
3795
[email protected]28685da92011-02-07 21:49:173796 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3797 DidCommitProvisionalLoad(frame, is_new_navigation));
3798
[email protected]3d9689372009-09-10 04:29:173799 // Remember that we've already processed this request, so we don't update
3800 // the session history again. We do this regardless of whether this is
3801 // a session history navigation, because if we attempted a session history
3802 // navigation without valid HistoryItem state, WebCore will think it is a
3803 // new navigation.
3804 navigation_state->set_request_committed(true);
3805
3806 UpdateURL(frame);
3807
[email protected]3d9689372009-09-10 04:29:173808 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273809 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]b2d98762012-09-03 17:04:063810
3811 if (!frame->parent()) { // Only for top frames.
3812 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
3813 if (render_thread_impl) { // Can be NULL in tests.
3814 render_thread_impl->histogram_customizer()->
3815 RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(),
3816 g_view_map.Get().size());
3817 }
3818 }
[email protected]3d9689372009-09-10 04:29:173819}
3820
[email protected]310ebd6302011-10-10 19:06:283821void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:103822 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3823 DidClearWindowObject(frame));
3824
[email protected]e9ff79c2012-10-19 21:31:263825 if (enabled_bindings_ & BINDINGS_POLICY_DOM_AUTOMATION) {
[email protected]59383c782013-04-17 16:43:273826 if (!dom_automation_controller_)
[email protected]766a7082012-02-03 23:39:153827 dom_automation_controller_.reset(new DomAutomationController());
3828 dom_automation_controller_->set_message_sender(
[email protected]e9ff79c2012-10-19 21:31:263829 static_cast<RenderView*>(this));
[email protected]766a7082012-02-03 23:39:153830 dom_automation_controller_->set_routing_id(routing_id());
3831 dom_automation_controller_->BindToJavascript(frame,
3832 "domAutomationController");
3833 }
[email protected]27c521a2013-05-29 20:44:323834
3835 if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION) {
3836 if (!stats_collection_controller_.get())
3837 stats_collection_controller_.reset(new StatsCollectionController());
3838 stats_collection_controller_->set_message_sender(
3839 static_cast<RenderView*>(this));
3840 stats_collection_controller_->BindToJavascript(frame,
3841 "statsCollectionController");
3842 }
[email protected]3d9689372009-09-10 04:29:173843}
3844
[email protected]310ebd6302011-10-10 19:06:283845void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:033846 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3847 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:173848}
3849
[email protected]310ebd6302011-10-10 19:06:283850void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
3851 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:463852 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:173853
3854 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273855 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173856}
3857
[email protected]41225fe2013-03-29 05:32:023858void RenderViewImpl::didChangeIcon(WebFrame* frame,
3859 WebIconURL::Type icon_type) {
3860 if (frame->parent())
3861 return;
3862
3863 if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon)
3864 return;
3865
3866 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type);
3867 std::vector<FaviconURL> urls;
3868 for (size_t i = 0; i < icon_urls.size(); i++) {
3869 urls.push_back(FaviconURL(icon_urls[i].iconURL(),
3870 ToFaviconType(icon_urls[i].iconType())));
3871 }
3872 SendUpdateFaviconURL(urls);
[email protected]5019ef12010-04-27 17:26:583873}
3874
[email protected]310ebd6302011-10-10 19:06:283875void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173876 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073877 DocumentState* document_state = DocumentState::FromDataSource(ds);
3878 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:173879
[email protected]622474d2010-11-04 09:21:083880 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173881
[email protected]28685da92011-02-07 21:49:173882 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3883 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173884
3885 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273886 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173887}
3888
[email protected]310ebd6302011-10-10 19:06:283889void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083890 if (webview()->mainFrame() == frame) {
3891 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3892 page_id_));
3893 }
[email protected]3d9689372009-09-10 04:29:173894}
3895
[email protected]310ebd6302011-10-10 19:06:283896void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:313897 WebDataSource* ds = frame->dataSource();
3898 DCHECK(ds);
3899
3900
[email protected]28685da92011-02-07 21:49:173901 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:313902
3903 const WebURLRequest& failed_request = ds->request();
3904 string16 error_description;
[email protected]e9ff79c2012-10-19 21:31:263905 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]8da4d262013-04-23 05:15:533906 frame,
[email protected]1a55c5be2011-11-29 11:36:313907 failed_request,
3908 error,
[email protected]b38806a2013-10-04 16:01:383909 renderer_preferences_.accept_languages,
[email protected]1a55c5be2011-11-29 11:36:313910 NULL,
3911 &error_description);
3912 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
3913 frame->identifier(),
3914 failed_request.url(),
3915 !frame->parent(),
3916 error.reason,
3917 error_description));
[email protected]3d9689372009-09-10 04:29:173918}
3919
[email protected]310ebd6302011-10-10 19:06:283920void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173921 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073922 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]1ac2ff12013-07-16 20:53:533923 if (document_state->finish_load_time().is_null()) {
3924 if (!frame->parent()) {
3925 TRACE_EVENT_INSTANT0("WebCore", "LoadFinished",
3926 TRACE_EVENT_SCOPE_PROCESS);
3927 }
[email protected]007733c2011-11-17 00:34:073928 document_state->set_finish_load_time(Time::Now());
[email protected]1ac2ff12013-07-16 20:53:533929 }
[email protected]4d44a1c2010-04-28 19:20:413930
[email protected]676126f72011-01-15 00:03:513931 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173932
[email protected]1a55c5be2011-11-29 11:36:313933 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
3934 frame->identifier(),
3935 ds->request().url(),
3936 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:173937}
3938
[email protected]310ebd6302011-10-10 19:06:283939void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173940 WebFrame* frame, bool is_new_navigation) {
3941 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:073942 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:173943 // update the ExtraData on the datasource so that others who read the
3944 // ExtraData will get the new NavigationState. Similarly, if we did not
3945 // initiate this navigation, then we need to take care to reset any pre-
3946 // existing navigation state to a content-initiated navigation state.
3947 // DidCreateDataSource conveniently takes care of this for us.
3948 didCreateDataSource(frame, frame->dataSource());
3949
[email protected]007733c2011-11-17 00:34:073950 DocumentState* document_state =
3951 DocumentState::FromDataSource(frame->dataSource());
3952 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:093953 new_state->set_was_within_same_page(true);
3954
[email protected]3d9689372009-09-10 04:29:173955 didCommitProvisionalLoad(frame, is_new_navigation);
[email protected]3d9689372009-09-10 04:29:173956}
3957
[email protected]310ebd6302011-10-10 19:06:283958void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313959 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593960}
3961
[email protected]310ebd6302011-10-10 19:06:283962void RenderViewImpl::willSendRequest(WebFrame* frame,
3963 unsigned identifier,
3964 WebURLRequest& request,
3965 const WebURLResponse& redirect_response) {
[email protected]e507045d2013-07-24 15:23:443966 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:173967}
3968
[email protected]310ebd6302011-10-10 19:06:283969void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173970 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]e507045d2013-07-24 15:23:443971 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:173972}
3973
[email protected]310ebd6302011-10-10 19:06:283974void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173975 WebFrame* frame, unsigned identifier) {
[email protected]e20b88d2013-04-09 15:28:373976 InternalDocumentStateData* internal_data =
3977 InternalDocumentStateData::FromDataSource(frame->dataSource());
3978 if (!internal_data->use_error_page())
[email protected]3d9689372009-09-10 04:29:173979 return;
3980
[email protected]7bfc153f2011-09-23 22:00:203981 // Do not show error page when DevTools is attached.
3982 if (devtools_agent_->IsAttached())
3983 return;
3984
[email protected]06333afe2011-02-24 14:55:093985 // Display error page, if appropriate.
[email protected]e20b88d2013-04-09 15:28:373986 int http_status_code = internal_data->http_status_code();
[email protected]3f853a52010-09-13 19:15:083987 if (http_status_code == 404) {
3988 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413989 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173990
[email protected]b6cb3a842011-06-24 18:28:413991 const GURL& error_page_url =
3992 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093993 if (error_page_url.is_valid()) {
3994 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473995 original_error.domain = "http";
3996 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413997 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173998
[email protected]e20b88d2013-04-09 15:28:373999 internal_data->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:094000 new AltErrorPageResourceFetcher(
[email protected]11a65772013-04-27 00:36:424001 error_page_url, frame, frame->dataSource()->request(),
4002 original_error,
[email protected]6e806822011-11-19 01:51:084003 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4004 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:094005 return;
4006 }
4007 }
[email protected]3d9689372009-09-10 04:29:174008
[email protected]e6a2ce52011-10-08 01:40:134009 std::string error_domain;
[email protected]e9ff79c2012-10-19 21:31:264010 if (GetContentClient()->renderer()->HasErrorPage(
[email protected]e6a2ce52011-10-08 01:40:134011 http_status_code, &error_domain)) {
4012 WebURLError error;
4013 error.unreachableURL = frame->document().url();
4014 error.domain = WebString::fromUTF8(error_domain);
4015 error.reason = http_status_code;
4016
4017 LoadNavigationErrorPage(
4018 frame, frame->dataSource()->request(), error, std::string(), true);
4019 }
[email protected]3d9689372009-09-10 04:29:174020}
4021
[email protected]310ebd6302011-10-10 19:06:284022void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:174023 WebFrame* frame, const WebURLRequest& request,
4024 const WebURLResponse& response) {
[email protected]e507045d2013-07-24 15:23:444025 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:174026}
4027
[email protected]310ebd6302011-10-10 19:06:284028void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e507045d2013-07-24 15:23:444029 NOTREACHED();
[email protected]e3d60e5d2009-09-25 21:08:294030}
4031
[email protected]310ebd6302011-10-10 19:06:284032void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:024033 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e507045d2013-07-24 15:23:444034 NOTREACHED();
[email protected]e3d60e5d2009-09-25 21:08:294035}
4036
[email protected]310ebd6302011-10-10 19:06:284037void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]e507045d2013-07-24 15:23:444038 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:174039}
4040
[email protected]310ebd6302011-10-10 19:06:284041void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
4042 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:584043 int extension_group,
[email protected]310ebd6302011-10-10 19:06:284044 int world_id) {
[email protected]e507045d2013-07-24 15:23:444045 NOTREACHED();
[email protected]a00fe692012-02-27 05:52:584046}
4047
[email protected]310ebd6302011-10-10 19:06:284048void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
4049 v8::Handle<v8::Context> context,
4050 int world_id) {
[email protected]e507045d2013-07-24 15:23:444051 NOTREACHED();
[email protected]0c882b282009-10-07 17:01:284052}
4053
[email protected]310ebd6302011-10-10 19:06:284054void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:074055 // We don't always want to send the change messages over IPC, only if we've
4056 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
4057 // message.
4058 if (!send_preferred_size_changes_ || !webview())
4059 return;
4060
[email protected]e76b7972013-06-06 02:58:484061 gfx::Size size = webview()->contentsPreferredMinimumSize();
[email protected]8205d742010-10-22 23:51:534062
[email protected]7940b8e2013-07-25 23:08:494063 // In the presence of zoom, these sizes are still reported as if unzoomed,
4064 // so we need to adjust.
4065 double zoom_factor = ZoomLevelToZoomFactor(webview()->zoomLevel());
4066 size.set_width(static_cast<int>(size.width() * zoom_factor));
4067 size.set_height(static_cast<int>(size.height() * zoom_factor));
4068
[email protected]705243f2010-05-05 19:58:074069 if (size == preferred_size_)
4070 return;
[email protected]c27324b2009-11-19 22:44:294071
[email protected]705243f2010-05-05 19:58:074072 preferred_size_ = size;
4073 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
4074 preferred_size_));
[email protected]3d9689372009-09-10 04:29:174075}
4076
[email protected]caaf2482013-05-01 20:33:324077BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() {
[email protected]fc72bb12013-06-02 21:13:464078 if (!browser_plugin_manager_.get())
[email protected]fb325d122012-11-20 23:58:054079 browser_plugin_manager_ = BrowserPluginManager::Create(this);
[email protected]fc72bb12013-06-02 21:13:464080 return browser_plugin_manager_.get();
[email protected]fb325d122012-11-20 23:58:054081}
4082
[email protected]60ee79f2013-09-11 13:49:554083bool RenderViewImpl::InitializeMediaStreamClient() {
4084 if (media_stream_client_)
4085 return true;
4086
[email protected]7082fb942012-05-16 23:44:594087 if (!RenderThreadImpl::current()) // Will be NULL during unit tests.
[email protected]60ee79f2013-09-11 13:49:554088 return false;
[email protected]08381562012-05-15 20:55:404089
[email protected]d9da9582013-01-31 04:59:054090#if defined(OS_ANDROID)
[email protected]ce585bf2013-03-14 16:25:164091 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableWebRTC))
[email protected]60ee79f2013-09-11 13:49:554092 return false;
[email protected]d9da9582013-01-31 04:59:054093#endif
4094
[email protected]4fb0f202012-05-30 22:44:534095#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:514096 if (!media_stream_dispatcher_)
4097 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
4098
[email protected]60ee79f2013-09-11 13:49:554099 MediaStreamImpl* media_stream_impl = new MediaStreamImpl(
4100 this,
4101 media_stream_dispatcher_,
4102 RenderThreadImpl::current()->GetMediaStreamDependencyFactory());
4103 media_stream_client_ = media_stream_impl;
4104 web_user_media_client_ = media_stream_impl;
4105 return true;
4106#else
4107 return false;
[email protected]5b87e782012-02-09 18:19:324108#endif
[email protected]273558fb2012-01-12 15:03:514109}
4110
[email protected]310ebd6302011-10-10 19:06:284111void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
4112 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:314113 if (webview()->mainFrame() != frame)
4114 return;
4115 WebView* frameView = frame->view();
4116 if (!frameView)
4117 return;
4118
4119 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
4120 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
4121
4122 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
4123 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
4124 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
4125 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
4126
4127 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
4128 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
4129 }
4130}
4131
[email protected]310ebd6302011-10-10 19:06:284132void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:314133 WebSize offset = frame->scrollOffset();
4134 WebSize minimum_offset = frame->minimumScrollOffset();
4135 WebSize maximum_offset = frame->maximumScrollOffset();
4136
4137 bool is_pinned_to_left = offset.width <= minimum_offset.width;
4138 bool is_pinned_to_right = offset.width >= maximum_offset.width;
4139
4140 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
4141 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
4142 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
4143 routing_id_, is_pinned_to_left, is_pinned_to_right));
4144
4145 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
4146 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
4147 }
[email protected]4e721742013-02-04 21:39:304148
4149 Send(new ViewHostMsg_DidChangeScrollOffset(routing_id_));
[email protected]dd6afca2011-08-13 03:44:314150}
4151
[email protected]310ebd6302011-10-10 19:06:284152void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:494153 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:314154
4155 if (webview()->mainFrame() == frame)
4156 UpdateScrollState(frame);
[email protected]2b942c332012-04-25 16:26:264157
4158 FOR_EACH_OBSERVER(
4159 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]dd6afca2011-08-13 03:44:314160}
4161
[email protected]180ef242013-11-07 06:50:464162void RenderViewImpl::willInsertBody(blink::WebFrame* frame) {
[email protected]e507045d2013-07-24 15:23:444163 NOTREACHED();
[email protected]a9344092d2013-02-27 00:56:454164}
4165
[email protected]4d0f8182012-10-19 23:14:474166void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebFrame* frame) {
4167 if (frame != webview()->mainFrame())
4168 return;
4169
[email protected]92d457802013-04-01 19:18:494170 InternalDocumentStateData* data =
4171 InternalDocumentStateData::FromDataSource(frame->dataSource());
4172 data->set_did_first_visually_non_empty_layout(true);
4173
4174#if defined(OS_ANDROID)
[email protected]4d0f8182012-10-19 23:14:474175 // Update body background color if necessary.
4176 SkColor bg_color = webwidget_->backgroundColor();
4177
4178 // If not initialized, default to white. Note that 0 is different from black
4179 // as black still has alpha 0xFF.
4180 if (!bg_color)
4181 bg_color = SK_ColorWHITE;
4182
4183 if (bg_color != body_background_color_) {
4184 body_background_color_ = bg_color;
[email protected]e507045d2013-07-24 15:23:444185 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(
4186 GetRoutingID(), bg_color));
[email protected]4d0f8182012-10-19 23:14:474187 }
[email protected]4d0f8182012-10-19 23:14:474188#endif
[email protected]92d457802013-04-01 19:18:494189}
[email protected]4d0f8182012-10-19 23:14:474190
[email protected]55750b32012-09-21 14:05:034191void RenderViewImpl::SendFindReply(int request_id,
4192 int match_count,
4193 int ordinal,
4194 const WebRect& selection_rect,
4195 bool final_status_update) {
[email protected]55750b32012-09-21 14:05:034196 Send(new ViewHostMsg_Find_Reply(routing_id_,
4197 request_id,
4198 match_count,
4199 selection_rect,
4200 ordinal,
4201 final_status_update));
4202}
4203
[email protected]432c9a72013-02-27 01:51:034204// static
4205bool RenderViewImpl::ShouldUpdateSelectionTextFromContextMenuParams(
4206 const string16& selection_text,
4207 size_t selection_text_offset,
[email protected]db4fc1e2013-09-06 20:01:514208 const gfx::Range& selection_range,
[email protected]432c9a72013-02-27 01:51:034209 const ContextMenuParams& params) {
4210 string16 trimmed_selection_text;
4211 if (!selection_text.empty() && !selection_range.is_empty()) {
4212 const int start = selection_range.GetMin() - selection_text_offset;
4213 const size_t length = selection_range.length();
4214 if (start >= 0 && start + length <= selection_text.length()) {
4215 TrimWhitespace(selection_text.substr(start, length), TRIM_ALL,
4216 &trimmed_selection_text);
4217 }
4218 }
4219 string16 trimmed_params_text;
4220 TrimWhitespace(params.selection_text, TRIM_ALL, &trimmed_params_text);
4221 return trimmed_params_text != trimmed_selection_text;
4222}
4223
[email protected]55750b32012-09-21 14:05:034224void RenderViewImpl::reportFindInPageMatchCount(int request_id,
4225 int count,
[email protected]310ebd6302011-10-10 19:06:284226 bool final_update) {
[email protected]1f35b45e2013-08-29 17:36:464227 // TODO(jam): switch PepperPluginInstanceImpl to take a RenderFrame
4228 main_render_frame_->reportFindInPageMatchCount(
4229 request_id, count, final_update);
[email protected]8922e1f2009-10-03 05:01:264230}
4231
[email protected]310ebd6302011-10-10 19:06:284232void RenderViewImpl::reportFindInPageSelection(int request_id,
4233 int active_match_ordinal,
4234 const WebRect& selection_rect) {
[email protected]1f35b45e2013-08-29 17:36:464235 // TODO(jam): switch PepperPluginInstanceImpl to take a RenderFrame
4236 main_render_frame_->reportFindInPageSelection(
4237 request_id, active_match_ordinal, selection_rect);
[email protected]8922e1f2009-10-03 05:01:264238}
4239
[email protected]310ebd6302011-10-10 19:06:284240void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:404241 WebFrame* frame,
4242 WebStorageQuotaType type,
4243 unsigned long long requested_size,
4244 WebStorageQuotaCallbacks* callbacks) {
[email protected]e507045d2013-07-24 15:23:444245 NOTREACHED();
[email protected]10e5cf12011-04-13 04:10:404246}
4247
[email protected]f546640b2012-05-15 00:03:494248bool RenderViewImpl::willCheckAndDispatchMessageEvent(
[email protected]180ef242013-11-07 06:50:464249 blink::WebFrame* sourceFrame,
4250 blink::WebFrame* targetFrame,
4251 blink::WebSecurityOrigin target_origin,
4252 blink::WebDOMMessageEvent event) {
[email protected]f546640b2012-05-15 00:03:494253 if (!is_swapped_out_)
4254 return false;
4255
4256 ViewMsg_PostMessage_Params params;
4257 params.data = event.data().toString();
4258 params.source_origin = event.origin();
4259 if (!target_origin.isNull())
4260 params.target_origin = target_origin.toString();
4261
[email protected]180ef242013-11-07 06:50:464262 blink::WebMessagePortChannelArray channels = event.releaseChannels();
[email protected]0bc7f3542013-10-21 15:05:534263 if (!channels.isEmpty()) {
4264 std::vector<int> message_port_ids(channels.size());
4265 // Extract the port IDs from the channel array.
4266 for (size_t i = 0; i < channels.size(); ++i) {
4267 WebMessagePortChannelImpl* webchannel =
4268 static_cast<WebMessagePortChannelImpl*>(channels[i]);
4269 message_port_ids[i] = webchannel->message_port_id();
4270 webchannel->QueueMessages();
4271 DCHECK_NE(message_port_ids[i], MSG_ROUTING_NONE);
4272 }
4273 params.message_port_ids = message_port_ids;
4274 }
4275
[email protected]2bb45f52013-11-02 02:15:084276 // Include the routing ID for the source frame (if one exists), which the
4277 // browser process will translate into the routing ID for the equivalent
4278 // frame in the target process.
[email protected]f546640b2012-05-15 00:03:494279 params.source_routing_id = MSG_ROUTING_NONE;
[email protected]2bb45f52013-11-02 02:15:084280 if (sourceFrame) {
4281 RenderViewImpl* source_view = FromWebView(sourceFrame->view());
4282 if (source_view)
4283 params.source_routing_id = source_view->routing_id();
4284 }
[email protected]f546640b2012-05-15 00:03:494285
4286 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params));
4287 return true;
4288}
4289
[email protected]5fa3a062012-03-21 15:39:344290void RenderViewImpl::willOpenSocketStream(
4291 WebSocketStreamHandle* handle) {
[email protected]e507045d2013-07-24 15:23:444292 NOTREACHED();
[email protected]5fa3a062012-03-21 15:39:344293}
4294
[email protected]ccee4862012-10-03 18:34:264295void RenderViewImpl::willStartUsingPeerConnectionHandler(
[email protected]180ef242013-11-07 06:50:464296 blink::WebFrame* frame, blink::WebRTCPeerConnectionHandler* handler) {
[email protected]e507045d2013-07-24 15:23:444297 NOTREACHED();
[email protected]ccee4862012-10-03 18:34:264298}
4299
[email protected]180ef242013-11-07 06:50:464300blink::WebString RenderViewImpl::acceptLanguages() {
[email protected]9982c802013-06-12 15:22:064301 return WebString::fromUTF8(renderer_preferences_.accept_languages);
4302}
4303
[email protected]180ef242013-11-07 06:50:464304blink::WebString RenderViewImpl::userAgentOverride(
4305 blink::WebFrame* frame,
4306 const blink::WebURL& url) {
[email protected]e507045d2013-07-24 15:23:444307 NOTREACHED();
[email protected]180ef242013-11-07 06:50:464308 return blink::WebString();
[email protected]bf70edce2012-06-20 22:32:224309}
4310
[email protected]a3e217f2013-04-12 22:38:344311WebString RenderViewImpl::doNotTrackValue(WebFrame* frame) {
[email protected]e507045d2013-07-24 15:23:444312 NOTREACHED();
[email protected]180ef242013-11-07 06:50:464313 return blink::WebString();
[email protected]a3e217f2013-04-12 22:38:344314}
4315
[email protected]818915cd2012-11-20 13:14:114316bool RenderViewImpl::allowWebGL(WebFrame* frame, bool default_value) {
[email protected]e507045d2013-07-24 15:23:444317 NOTREACHED();
4318 return false;
[email protected]818915cd2012-11-20 13:14:114319}
4320
4321void RenderViewImpl::didLoseWebGLContext(
[email protected]180ef242013-11-07 06:50:464322 blink::WebFrame* frame,
[email protected]818915cd2012-11-20 13:14:114323 int arb_robustness_status_code) {
[email protected]e507045d2013-07-24 15:23:444324 NOTREACHED();
[email protected]818915cd2012-11-20 13:14:114325}
4326
[email protected]180ef242013-11-07 06:50:464327// blink::WebPageSerializerClient implementation ------------------------------
[email protected]18d5be92011-07-25 18:00:194328
[email protected]310ebd6302011-10-10 19:06:284329void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:194330 const WebURL& frame_url,
4331 const WebCString& data,
4332 WebPageSerializerClient::PageSerializationStatus status) {
4333 Send(new ViewHostMsg_SendSerializedHtmlData(
4334 routing_id(),
4335 frame_url,
4336 data.data(),
4337 static_cast<int32>(status)));
4338}
4339
[email protected]e9ff79c2012-10-19 21:31:264340// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:314341
[email protected]310ebd6302011-10-10 19:06:284342bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:314343 return RenderWidget::Send(message);
4344}
4345
[email protected]82114f52012-03-20 22:53:414346int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:314347 return routing_id_;
4348}
4349
[email protected]82114f52012-03-20 22:53:414350int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:314351 return page_id_;
4352}
4353
[email protected]82114f52012-03-20 22:53:414354gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:314355 return size();
4356}
4357
[email protected]82114f52012-03-20 22:53:414358WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:314359 return webkit_preferences_;
4360}
4361
[email protected]324825d2012-11-30 12:37:154362void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
4363 OnUpdateWebPreferences(preferences);
4364}
4365
[email protected]180ef242013-11-07 06:50:464366blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:314367 return webview();
4368}
4369
[email protected]180ef242013-11-07 06:50:464370blink::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:314371 if (!webview())
4372 return WebNode();
4373 WebFrame* focused_frame = webview()->focusedFrame();
4374 if (focused_frame) {
4375 WebDocument doc = focused_frame->document();
4376 if (!doc.isNull())
4377 return doc.focusedNode();
4378 }
4379
4380 return WebNode();
4381}
4382
[email protected]180ef242013-11-07 06:50:464383blink::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:314384 return context_menu_node_;
4385}
4386
[email protected]2a84f9d2012-06-05 21:50:434387bool RenderViewImpl::IsEditableNode(const WebNode& node) const {
4388 if (node.isNull())
4389 return false;
4390
4391 if (node.isContentEditable())
4392 return true;
4393
4394 if (node.isElementNode()) {
4395 const WebElement& element = node.toConst<WebElement>();
4396 if (element.isTextFormControlElement())
4397 return true;
4398
4399 // Also return true if it has an ARIA role of 'textbox'.
4400 for (unsigned i = 0; i < element.attributeCount(); ++i) {
4401 if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) {
4402 if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox"))
4403 return true;
4404 break;
4405 }
[email protected]a2ef54c2011-10-10 16:20:314406 }
4407 }
[email protected]2a84f9d2012-06-05 21:50:434408
4409 return false;
[email protected]a2ef54c2011-10-10 16:20:314410}
4411
[email protected]180ef242013-11-07 06:50:464412blink::WebPlugin* RenderViewImpl::CreatePlugin(
4413 blink::WebFrame* frame,
[email protected]d7bd3e52013-07-21 04:29:204414 const WebPluginInfo& info,
[email protected]180ef242013-11-07 06:50:464415 const blink::WebPluginParams& params) {
[email protected]ea2fb972013-08-07 05:44:264416#if defined(ENABLE_PLUGINS)
4417 bool pepper_plugin_was_registered = false;
4418 scoped_refptr<PluginModule> pepper_module(PluginModule::Create(
4419 this, info, &pepper_plugin_was_registered));
4420 if (pepper_plugin_was_registered) {
4421 if (pepper_module.get())
4422 return new PepperWebPluginImpl(pepper_module.get(), params, AsWeakPtr());
4423 }
[email protected]a2ef54c2011-10-10 16:20:314424
[email protected]29e2fb42013-07-19 01:13:474425 return new WebPluginImpl(frame, params, info.path, AsWeakPtr());
[email protected]ea2fb972013-08-07 05:44:264426#else
4427 return NULL;
4428#endif
[email protected]a2ef54c2011-10-10 16:20:314429}
4430
[email protected]310ebd6302011-10-10 19:06:284431void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
4432 const string16& jscript,
4433 int id,
4434 bool notify_result) {
[email protected]e1907b432013-09-04 16:11:144435 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
[email protected]a2ef54c2011-10-10 16:20:314436 v8::Handle<v8::Value> result;
4437 WebFrame* web_frame = GetChildFrame(frame_xpath);
4438 if (web_frame)
4439 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
4440 if (notify_result) {
[email protected]0cd50aa2013-02-12 22:28:014441 base::ListValue list;
[email protected]a2ef54c2011-10-10 16:20:314442 if (!result.IsEmpty() && web_frame) {
[email protected]a2ef54c2011-10-10 16:20:314443 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4444 v8::Context::Scope context_scope(context);
4445 V8ValueConverterImpl converter;
[email protected]3de391e82012-05-16 17:50:514446 converter.SetDateAllowed(true);
[email protected]e0658bc2012-09-17 04:05:244447 converter.SetRegExpAllowed(true);
4448 base::Value* result_value = converter.FromV8Value(result, context);
[email protected]0cd50aa2013-02-12 22:28:014449 list.Set(0, result_value ? result_value : base::Value::CreateNullValue());
[email protected]a2ef54c2011-10-10 16:20:314450 } else {
[email protected]0cd50aa2013-02-12 22:28:014451 list.Set(0, base::Value::CreateNullValue());
[email protected]a2ef54c2011-10-10 16:20:314452 }
4453 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
4454 }
4455}
4456
[email protected]310ebd6302011-10-10 19:06:284457bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:314458 return (!send_preferred_size_changes_ ||
4459 (disable_scrollbars_size_limit_.width() <= width ||
4460 disable_scrollbars_size_limit_.height() <= height));
4461}
4462
[email protected]82114f52012-03-20 22:53:414463int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:314464 return enabled_bindings_;
4465}
4466
[email protected]82114f52012-03-20 22:53:414467bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:314468 return send_content_state_immediately_;
4469}
4470
[email protected]82114f52012-03-20 22:53:414471float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:314472 return filtered_time_per_frame();
4473}
4474
[email protected]e9ff79c2012-10-19 21:31:264475int RenderViewImpl::ShowContextMenu(ContextMenuClient* client,
4476 const ContextMenuParams& params) {
[email protected]860ee642012-10-13 03:46:254477 DCHECK(client); // A null client means "internal" when we issue callbacks.
[email protected]e9ff79c2012-10-19 21:31:264478 ContextMenuParams our_params(params);
[email protected]860ee642012-10-13 03:46:254479 our_params.custom_context.request_id = pending_context_menus_.Add(client);
4480 Send(new ViewHostMsg_ContextMenu(routing_id_, our_params));
4481 return our_params.custom_context.request_id;
[email protected]a2ef54c2011-10-10 16:20:314482}
4483
[email protected]e0fd0eb2012-10-17 21:11:464484void RenderViewImpl::CancelContextMenu(int request_id) {
4485 DCHECK(pending_context_menus_.Lookup(request_id));
4486 pending_context_menus_.Remove(request_id);
4487}
4488
[email protected]180ef242013-11-07 06:50:464489blink::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:314490 return visibilityState();
4491}
4492
[email protected]180ef242013-11-07 06:50:464493void RenderViewImpl::RunModalAlertDialog(blink::WebFrame* frame,
4494 const blink::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:314495 return runModalAlertDialog(frame, message);
4496}
4497
[email protected]310ebd6302011-10-10 19:06:284498void RenderViewImpl::LoadURLExternally(
[email protected]180ef242013-11-07 06:50:464499 blink::WebFrame* frame,
4500 const blink::WebURLRequest& request,
4501 blink::WebNavigationPolicy policy) {
[email protected]e507045d2013-07-24 15:23:444502 main_render_frame_->loadURLExternally(frame, request, policy);
[email protected]a2ef54c2011-10-10 16:20:314503}
4504
[email protected]3c71576ce2013-07-23 02:00:014505void RenderViewImpl::DidStartLoading() {
4506 didStartLoading();
4507}
4508
4509void RenderViewImpl::DidStopLoading() {
4510 didStopLoading();
4511}
4512
[email protected]180ef242013-11-07 06:50:464513void RenderViewImpl::DidPlay(blink::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074514 Send(new ViewHostMsg_MediaNotification(routing_id_,
4515 reinterpret_cast<int64>(player),
4516 player->hasVideo(),
4517 player->hasAudio(),
4518 true));
4519}
4520
[email protected]180ef242013-11-07 06:50:464521void RenderViewImpl::DidPause(blink::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074522 Send(new ViewHostMsg_MediaNotification(routing_id_,
4523 reinterpret_cast<int64>(player),
4524 player->hasVideo(),
4525 player->hasAudio(),
4526 false));
4527}
4528
[email protected]180ef242013-11-07 06:50:464529void RenderViewImpl::PlayerGone(blink::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074530 DidPause(player);
4531}
4532
[email protected]310ebd6302011-10-10 19:06:284533void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:294534 if (!webview())
4535 return;
4536
[email protected]26aa0482009-09-30 16:55:274537 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:054538 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:294539}
4540
[email protected]310ebd6302011-10-10 19:06:284541void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:364542 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:004543 if (!frame)
4544 return;
[email protected]b781ff282011-08-20 06:19:364545
[email protected]e99ef6f2011-10-16 01:13:004546 string16 text;
4547 size_t offset;
[email protected]db4fc1e2013-09-06 20:01:514548 gfx::Range range;
[email protected]ea2fb972013-08-07 05:44:264549#if defined(ENABLE_PLUGINS)
4550 if (focused_pepper_plugin_) {
4551 focused_pepper_plugin_->GetSurroundingText(&text, &range);
[email protected]82114f52012-03-20 22:53:414552 offset = 0; // Pepper API does not support offset reporting.
[email protected]3c8c74c2012-03-15 07:34:524553 // TODO(kinaba): cut as needed.
[email protected]ea2fb972013-08-07 05:44:264554 } else
4555#endif
4556 {
[email protected]3c8c74c2012-03-15 07:34:524557 size_t location, length;
4558 if (!webview()->caretOrSelectionRange(&location, &length))
4559 return;
4560
[email protected]db4fc1e2013-09-06 20:01:514561 range = gfx::Range(location, location + length);
[email protected]3c8c74c2012-03-15 07:34:524562
[email protected]180ef242013-11-07 06:50:464563 if (webview()->textInputInfo().type != blink::WebTextInputTypeNone) {
[email protected]3c8c74c2012-03-15 07:34:524564 // If current focused element is editable, we will send 100 more chars
4565 // before and after selection. It is for input method surrounding text
4566 // feature.
4567 if (location > kExtraCharsBeforeAndAfterSelection)
4568 offset = location - kExtraCharsBeforeAndAfterSelection;
4569 else
4570 offset = 0;
4571 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
4572 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
4573 if (!webrange.isNull())
4574 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
4575 } else {
4576 offset = location;
4577 text = frame->selectionAsText();
4578 // http://crbug.com/101435
4579 // In some case, frame->selectionAsText() returned text's length is not
4580 // equal to the length returned from webview()->caretOrSelectionRange().
4581 // So we have to set the range according to text.length().
4582 range.set_end(range.start() + text.length());
4583 }
[email protected]b781ff282011-08-20 06:19:364584 }
4585
[email protected]b781ff282011-08-20 06:19:364586 // Sometimes we get repeated didChangeSelection calls from webkit when
4587 // the selection hasn't actually changed. We don't want to report these
4588 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:004589 if (selection_text_offset_ != offset ||
4590 selection_range_ != range ||
4591 selection_text_ != text) {
4592 selection_text_ = text;
4593 selection_text_offset_ = offset;
4594 selection_range_ = range;
4595 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
4596 }
[email protected]47822262013-04-23 17:22:364597 UpdateSelectionBounds();
[email protected]b781ff282011-08-20 06:19:364598}
4599
[email protected]310ebd6302011-10-10 19:06:284600GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
4601 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554602 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294603 // If the URL that failed was secure, then the embedding web page was not
4604 // expecting a network attacker to be able to manipulate its contents. As
4605 // we fetch alternate error pages over HTTP, we would be allowing a network
4606 // attacker to manipulate the contents of the response if we tried to use
4607 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154608 return GURL();
initial.commit09911bf2008-07-26 23:55:294609 }
4610
4611 // Grab the base URL from the browser process.
4612 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154613 return GURL();
initial.commit09911bf2008-07-26 23:55:294614
4615 // Strip query params from the failed URL.
4616 GURL::Replacements remove_params;
4617 remove_params.ClearUsername();
4618 remove_params.ClearPassword();
4619 remove_params.ClearQuery();
4620 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554621 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]b38806a2013-10-04 16:01:384622 // TODO(yuusuke): change to net::FormatUrl when link doctor
4623 // becomes unicode-capable.
[email protected]6fd28f642010-03-15 17:15:504624 std::string spec_to_send = url_to_send.spec();
4625 // Notify link doctor of the url truncation by sending of "?" at the end.
4626 if (failed_url.has_query())
[email protected]82114f52012-03-20 22:53:414627 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294628
4629 // Construct the query params to send to link doctor.
4630 std::string params(alternate_error_page_url_.query());
4631 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:024632 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294633 params.append("&sourceid=chrome");
4634 params.append("&error=");
4635 switch (error_type) {
4636 case DNS_ERROR:
4637 params.append("dnserror");
4638 break;
4639
4640 case HTTP_404:
4641 params.append("http404");
4642 break;
4643
[email protected]5df266ac2008-10-15 19:50:134644 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334645 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134646 break;
4647
initial.commit09911bf2008-07-26 23:55:294648 default:
4649 NOTREACHED() << "unknown ErrorPageType";
4650 }
4651
4652 // OK, build the final url to return.
4653 GURL::Replacements link_doctor_params;
4654 link_doctor_params.SetQueryStr(params);
4655 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4656 return url;
4657}
4658
[email protected]180ef242013-11-07 06:50:464659GURL RenderViewImpl::GetLoadingUrl(blink::WebFrame* frame) const {
[email protected]69ddf852012-02-21 23:21:314660 WebDataSource* ds = frame->dataSource();
4661 if (ds->hasUnreachableURL())
4662 return ds->unreachableURL();
4663
4664 const WebURLRequest& request = ds->request();
4665 return request.url();
4666}
4667
[email protected]180ef242013-11-07 06:50:464668blink::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:014669 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494670}
4671
[email protected]55750b32012-09-21 14:05:034672void RenderViewImpl::OnFind(int request_id,
4673 const string16& search_text,
[email protected]310ebd6302011-10-10 19:06:284674 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274675 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494676
[email protected]872542532011-06-23 00:43:164677 // Check if the plugin still exists in the document.
4678 if (main_frame->document().isPluginDocument() &&
4679 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494680 if (options.findNext) {
4681 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014682 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494683 } else {
[email protected]55750b32012-09-21 14:05:034684 if (!GetWebPluginFromPluginDocument()->startFind(
[email protected]afdbd142010-07-10 08:01:234685 search_text, options.matchCase, request_id)) {
[email protected]e7c58a32010-08-13 19:47:114686 // Send "no results".
[email protected]55750b32012-09-21 14:05:034687 SendFindReply(request_id, 0, 0, gfx::Rect(), true);
[email protected]24a7f3c2010-03-25 08:26:494688 }
4689 }
4690 return;
4691 }
4692
[email protected]b4bb2502009-10-01 22:35:274693 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274694 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294695 WebFrame* search_frame = focused_frame; // start searching focused frame.
4696
4697 bool multi_frame = (frame_after_main != main_frame);
4698
4699 // If we have multiple frames, we don't want to wrap the search within the
4700 // frame, so we check here if we only have main_frame in the chain.
4701 bool wrap_within_frame = !multi_frame;
4702
[email protected]b3f2b912009-04-09 16:18:524703 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294704 bool result = false;
4705
[email protected]7830da3e2009-11-06 16:27:264706 // If something is selected when we start searching it means we cannot just
4707 // increment the current match ordinal; we need to re-generate it.
4708 WebRange current_selection = focused_frame->selectionRange();
4709
initial.commit09911bf2008-07-26 23:55:294710 do {
[email protected]dd7daa82009-08-10 05:46:454711 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594712 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294713
4714 if (!result) {
4715 // don't leave text selected as you move to the next frame.
[email protected]6dd17a8a2013-05-01 05:50:104716 search_frame->executeCommand(WebString::fromUTF8("Unselect"),
4717 GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:294718
4719 // Find the next frame, but skip the invisible ones.
4720 do {
4721 // What is the next frame to search? (we might be going backwards). Note
4722 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594723 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274724 search_frame->traverseNext(true) :
4725 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454726 } while (!search_frame->hasVisibleContent() &&
4727 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294728
[email protected]884db412008-11-24 23:46:504729 // Make sure selection doesn't affect the search operation in new frame.
[email protected]6dd17a8a2013-05-01 05:50:104730 search_frame->executeCommand(WebString::fromUTF8("Unselect"),
4731 GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:294732
4733 // If we have multiple frames and we have wrapped back around to the
4734 // focused frame, we need to search it once more allowing wrap within
4735 // the frame, otherwise it will report 'no match' if the focused frame has
4736 // reported matches, but no frames after the focused_frame contain a
4737 // match for the search word(s).
4738 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454739 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594740 request_id, search_text, options, true, // Force wrapping.
4741 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294742 }
4743 }
4744
[email protected]26aa0482009-09-30 16:55:274745 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294746 } while (!result && search_frame != focused_frame);
4747
[email protected]7830da3e2009-11-06 16:27:264748 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294749 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454750 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294751 } else {
4752 // If nothing is found, set result to "0 of 0", otherwise, set it to
4753 // "-1 of 1" to indicate that we found at least one item, but we don't know
4754 // yet what is active.
4755 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4756 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294757
[email protected]4f3dc372009-02-24 00:10:294758 // If we find no matches then this will be our last status update.
4759 // Otherwise the scoping effort will send more results.
4760 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294761
[email protected]55750b32012-09-21 14:05:034762 SendFindReply(request_id, match_count, ordinal, selection_rect,
4763 final_status_update);
initial.commit09911bf2008-07-26 23:55:294764
initial.commit09911bf2008-07-26 23:55:294765 // Scoping effort begins, starting with the mainframe.
4766 search_frame = main_frame;
4767
[email protected]dd7daa82009-08-10 05:46:454768 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294769
4770 do {
4771 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454772 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294773
4774 // We don't start another scoping effort unless at least one match has
4775 // been found.
4776 if (result) {
4777 // Start new scoping request. If the scoping function determines that it
4778 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454779 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594780 search_text,
4781 options,
initial.commit09911bf2008-07-26 23:55:294782 true); // reset the tickmarks
4783 }
4784
4785 // Iterate to the next frame. The frame will not necessarily scope, for
4786 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274787 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294788 } while (search_frame != main_frame);
4789 }
4790}
4791
[email protected]e9ff79c2012-10-19 21:31:264792void RenderViewImpl::OnStopFinding(StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:494793 WebView* view = webview();
4794 if (!view)
4795 return;
4796
4797 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:164798 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014799 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494800 return;
4801 }
4802
[email protected]e9ff79c2012-10-19 21:31:264803 bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]6dd17a8a2013-05-01 05:50:104804 if (clear_selection) {
4805 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
4806 GetFocusedNode());
4807 }
[email protected]24a7f3c2010-03-25 08:26:494808
4809 WebFrame* frame = view->mainFrame();
4810 while (frame) {
4811 frame->stopFinding(clear_selection);
4812 frame = frame->traverseNext(false);
4813 }
4814
[email protected]e9ff79c2012-10-19 21:31:264815 if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:494816 WebFrame* focused_frame = view->focusedFrame();
4817 if (focused_frame) {
4818 WebDocument doc = focused_frame->document();
4819 if (!doc.isNull()) {
4820 WebNode node = doc.focusedNode();
4821 if (!node.isNull())
4822 node.simulateClick();
4823 }
4824 }
4825 }
4826}
4827
[email protected]59363fc92012-09-05 03:46:314828#if defined(OS_ANDROID)
4829void RenderViewImpl::OnActivateNearestFindResult(int request_id,
4830 float x, float y) {
4831 if (!webview())
4832 return;
4833
4834 WebFrame* main_frame = webview()->mainFrame();
4835 WebRect selection_rect;
4836 int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y),
4837 &selection_rect);
4838 if (ordinal == -1) {
4839 // Something went wrong, so send a no-op reply (force the main_frame to
4840 // report the current match count) in case the host is waiting for a
4841 // response due to rate-limiting).
4842 main_frame->increaseMatchCount(0, request_id);
4843 return;
4844 }
4845
[email protected]55750b32012-09-21 14:05:034846 SendFindReply(request_id,
4847 -1 /* number_of_matches */,
4848 ordinal,
4849 selection_rect,
4850 true /* final_update */);
[email protected]59363fc92012-09-05 03:46:314851}
4852
4853void RenderViewImpl::OnFindMatchRects(int current_version) {
4854 if (!webview())
4855 return;
4856
4857 WebFrame* main_frame = webview()->mainFrame();
4858 std::vector<gfx::RectF> match_rects;
4859
4860 int rects_version = main_frame->findMatchMarkersVersion();
4861 if (current_version != rects_version) {
4862 WebVector<WebFloatRect> web_match_rects;
4863 main_frame->findMatchRects(web_match_rects);
4864 match_rects.reserve(web_match_rects.size());
4865 for (size_t i = 0; i < web_match_rects.size(); ++i)
4866 match_rects.push_back(gfx::RectF(web_match_rects[i]));
4867 }
4868
4869 gfx::RectF active_rect = main_frame->activeFindMatchRect();
4870 Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_,
4871 rects_version,
4872 match_rects,
4873 active_rect));
4874}
4875#endif
4876
[email protected]e9ff79c2012-10-19 21:31:264877void RenderViewImpl::OnZoom(PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:514878 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4879 return;
4880
[email protected]258d31122010-05-09 10:59:414881 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:104882
[email protected]b75b8292010-10-01 07:28:254883 double old_zoom_level = webview()->zoomLevel();
4884 double zoom_level;
[email protected]e9ff79c2012-10-19 21:31:264885 if (zoom == PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:254886 zoom_level = 0;
4887 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4888 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:484889 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:254890 } else {
4891 // Either the user hit the zoom factor limit and thus the zoom level is now
4892 // not a whole number, or a plugin changed it to a custom value. We want
4893 // to go to the next whole number so that the user can always get back to
4894 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:484895 if ((old_zoom_level > 1 && zoom > 0) ||
4896 (old_zoom_level < 1 && zoom < 0)) {
4897 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:254898 } else {
4899 // We're going towards 100%, so first go to the next whole number.
4900 zoom_level = static_cast<int>(old_zoom_level);
4901 }
4902 }
[email protected]91219702013-09-18 07:33:514903 webview()->setZoomLevel(zoom_level);
[email protected]47578fa02011-11-02 19:34:414904 zoomLevelChanged();
4905}
4906
[email protected]e9ff79c2012-10-19 21:31:264907void RenderViewImpl::OnZoomFactor(PageZoom zoom, int zoom_center_x,
4908 int zoom_center_y) {
[email protected]47578fa02011-11-02 19:34:414909 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
4910 kScalingIncrementForGesture);
4911}
4912
[email protected]e9ff79c2012-10-19 21:31:264913void RenderViewImpl::ZoomFactorHelper(PageZoom zoom,
[email protected]47578fa02011-11-02 19:34:414914 int zoom_center_x,
4915 int zoom_center_y,
4916 float scaling_increment) {
4917 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4918 return;
4919
[email protected]c514d632011-08-16 22:54:444920 double old_page_scale_factor = webview()->pageScaleFactor();
4921 double page_scale_factor;
[email protected]e9ff79c2012-10-19 21:31:264922 if (zoom == PAGE_ZOOM_RESET) {
[email protected]c514d632011-08-16 22:54:444923 page_scale_factor = 1.0;
4924 } else {
4925 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:414926 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d632011-08-16 22:54:444927 }
[email protected]47578fa02011-11-02 19:34:414928 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:094929 webview()->setPageScaleFactor(page_scale_factor,
4930 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:414931 }
[email protected]40bd6582009-12-04 23:49:514932}
4933
[email protected]310ebd6302011-10-10 19:06:284934void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174935 webview()->hidePopups();
[email protected]91219702013-09-18 07:33:514936 webview()->setZoomLevel(zoom_level);
[email protected]d0b8d092010-10-25 04:05:174937 zoomLevelChanged();
4938}
4939
[email protected]310ebd6302011-10-10 19:06:284940void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4941 double zoom_level) {
[email protected]cbe55d22013-02-14 17:04:334942#if !defined(OS_ANDROID)
4943 // On Android, page zoom isn't used, and in case of WebView, text zoom is used
4944 // for legacy WebView text scaling emulation. Thus, the code that resets
4945 // the zoom level from this map will be effectively resetting text zoom level.
[email protected]9d797f32010-04-23 07:17:544946 host_zoom_levels_[url] = zoom_level;
[email protected]cbe55d22013-02-14 17:04:334947#endif
initial.commit09911bf2008-07-26 23:55:294948}
4949
[email protected]310ebd6302011-10-10 19:06:284950void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274951 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294952}
4953
[email protected]310ebd6302011-10-10 19:06:284954void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274955 WebString no_encoding;
4956 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184957}
4958
[email protected]310ebd6302011-10-10 19:06:284959WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454960 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274961 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454962
4963 // xpath string can represent a frame deep down the tree (across multiple
4964 // frame DOMs).
4965 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4966 // should break into 2 xpaths
4967 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:414968 std::vector<string16> xpaths;
4969 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:454970
[email protected]26aa0482009-09-30 16:55:274971 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:414972 for (std::vector<string16>::const_iterator i = xpaths.begin();
4973 frame && i != xpaths.end(); ++i) {
4974 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294975 }
4976
[email protected]dd7daa82009-08-10 05:46:454977 return frame;
initial.commit09911bf2008-07-26 23:55:294978}
4979
[email protected]310ebd6302011-10-10 19:06:284980void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4981 const string16& jscript,
4982 int id,
4983 bool notify_result) {
[email protected]c76faea2013-03-26 07:42:424984 TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest",
4985 TRACE_EVENT_SCOPE_THREAD);
[email protected]882b7b22010-10-05 03:34:534986 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294987}
4988
[email protected]f546640b2012-05-15 00:03:494989void RenderViewImpl::OnPostMessageEvent(
4990 const ViewMsg_PostMessage_Params& params) {
[email protected]bf4a2312013-04-23 00:32:114991 // TODO(nasko): Support sending to subframes.
[email protected]e12dbe6f2012-10-04 22:11:194992 WebFrame* frame = webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:494993
4994 // Find the source frame if it exists.
[email protected]f546640b2012-05-15 00:03:494995 WebFrame* source_frame = NULL;
4996 if (params.source_routing_id != MSG_ROUTING_NONE) {
4997 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
4998 if (source_view)
[email protected]e12dbe6f2012-10-04 22:11:194999 source_frame = source_view->webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:495000 }
5001
[email protected]0bc7f3542013-10-21 15:05:535002 // If the message contained MessagePorts, create the corresponding endpoints.
5003 DCHECK_EQ(params.message_port_ids.size(), params.new_routing_ids.size());
[email protected]180ef242013-11-07 06:50:465004 blink::WebMessagePortChannelArray channels(params.message_port_ids.size());
[email protected]0bc7f3542013-10-21 15:05:535005 for (size_t i = 0;
5006 i < params.message_port_ids.size() && i < params.new_routing_ids.size();
5007 ++i) {
5008 channels[i] =
5009 new WebMessagePortChannelImpl(params.new_routing_ids[i],
5010 params.message_port_ids[i],
5011 base::MessageLoopProxy::current().get());
5012 }
5013
[email protected]f546640b2012-05-15 00:03:495014 // Create an event with the message. The final parameter to initMessageEvent
5015 // is the last event ID, which is not used with postMessage.
5016 WebDOMEvent event = frame->document().createEvent("MessageEvent");
5017 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
5018 msg_event.initMessageEvent("message",
5019 // |canBubble| and |cancellable| are always false
5020 false, false,
5021 WebSerializedScriptValue::fromString(params.data),
[email protected]0bc7f3542013-10-21 15:05:535022 params.source_origin, source_frame, "", channels);
[email protected]f546640b2012-05-15 00:03:495023
5024 // We must pass in the target_origin to do the security check on this side,
5025 // since it may have changed since the original postMessage call was made.
5026 WebSecurityOrigin target_origin;
5027 if (!params.target_origin.empty()) {
5028 target_origin =
5029 WebSecurityOrigin::createFromString(WebString(params.target_origin));
5030 }
5031 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
5032}
5033
[email protected]310ebd6302011-10-10 19:06:285034void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
5035 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:415036 WebFrame* frame = GetChildFrame(frame_xpath);
5037 if (!frame)
[email protected]216813952011-05-19 22:21:265038 return;
[email protected]ae461542009-06-19 19:03:415039
[email protected]01cf589c2011-07-28 18:04:035040 frame->document().insertUserStyleSheet(
5041 WebString::fromUTF8(css),
5042 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:485043}
5044
[email protected]310ebd6302011-10-10 19:06:285045void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]940ed1d2012-11-27 21:03:215046 if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) &&
5047 !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) {
[email protected]91f05762013-08-21 02:55:095048 // WebUI uses <dialog> which is not yet enabled by default in Chrome.
5049 WebRuntimeFeatures::enableDialogElement(true);
5050
[email protected]dcc72db2013-01-02 00:44:185051 RenderThread::Get()->RegisterExtension(WebUIExtension::Get());
[email protected]940ed1d2012-11-27 21:03:215052 new WebUIExtensionData(this);
5053 }
5054
[email protected]81e63782009-02-27 19:35:095055 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:045056
5057 // Keep track of the total bindings accumulated in this process.
5058 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:295059}
5060
[email protected]dc293a72013-07-01 11:11:225061void RenderViewImpl::OnDragTargetDragEnter(const DropData& drop_data,
[email protected]310ebd6302011-10-10 19:06:285062 const gfx::Point& client_point,
5063 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:425064 WebDragOperationsMask ops,
5065 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:555066 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]dc293a72013-07-01 11:11:225067 DropDataToWebDragData(drop_data),
[email protected]59f4f2fa2011-03-23 01:00:555068 client_point,
5069 screen_point,
[email protected]1f2230b2012-05-17 23:43:425070 ops,
5071 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555072
5073 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5074}
5075
[email protected]310ebd6302011-10-10 19:06:285076void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
5077 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:425078 WebDragOperationsMask ops,
5079 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:555080 WebDragOperation operation = webview()->dragTargetDragOver(
5081 client_point,
5082 screen_point,
[email protected]1f2230b2012-05-17 23:43:425083 ops,
5084 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555085
5086 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5087}
5088
[email protected]310ebd6302011-10-10 19:06:285089void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:555090 webview()->dragTargetDragLeave();
5091}
5092
[email protected]310ebd6302011-10-10 19:06:285093void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
[email protected]1f2230b2012-05-17 23:43:425094 const gfx::Point& screen_point,
5095 int key_modifiers) {
5096 webview()->dragTargetDrop(client_point, screen_point, key_modifiers);
[email protected]fcad49452011-06-28 17:11:575097
5098 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:555099}
5100
[email protected]310ebd6302011-10-10 19:06:285101void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
5102 const gfx::Point& screen_point,
5103 bool ended,
5104 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:035105 if (ended) {
[email protected]26aa0482009-09-30 16:55:275106 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:205107 } else {
5108 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:035109 }
initial.commit09911bf2008-07-26 23:55:295110}
5111
[email protected]310ebd6302011-10-10 19:06:285112void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:275113 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:295114}
5115
[email protected]310ebd6302011-10-10 19:06:285116void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:595117 webkit_preferences_ = prefs;
[email protected]49a20002013-08-18 12:43:315118 ApplyWebPreferences(webkit_preferences_, webview());
initial.commit09911bf2008-07-26 23:55:295119}
5120
[email protected]38761452012-10-18 16:31:595121void RenderViewImpl::OnUpdateTimezone() {
5122 if (webview())
5123 NotifyTimezoneChange(webview()->mainFrame());
5124}
5125
[email protected]310ebd6302011-10-10 19:06:285126void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:295127 alternate_error_page_url_ = url;
5128}
5129
[email protected]310ebd6302011-10-10 19:06:285130void RenderViewImpl::OnCustomContextMenuAction(
[email protected]e9ff79c2012-10-19 21:31:265131 const CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:085132 unsigned action) {
[email protected]860ee642012-10-13 03:46:255133 if (custom_context.request_id) {
5134 // External context menu request, look in our map.
[email protected]e9ff79c2012-10-19 21:31:265135 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:255136 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:465137 if (client)
5138 client->OnMenuAction(custom_context.request_id, action);
[email protected]860ee642012-10-13 03:46:255139 } else {
5140 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:085141 webview()->performCustomContextMenuAction(action);
[email protected]860ee642012-10-13 03:46:255142 }
[email protected]a0c7153e2009-12-09 14:36:335143}
5144
[email protected]310ebd6302011-10-10 19:06:285145void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:515146 int id,
[email protected]c42de732013-02-16 06:26:315147 const std::vector<base::FilePath>& paths) {
[email protected]600ea402011-04-12 00:01:515148 if (!enumeration_completions_[id])
5149 return;
5150
5151 WebVector<WebString> ws_file_names(paths.size());
5152 for (size_t i = 0; i < paths.size(); ++i)
[email protected]728c2ee2013-06-25 04:01:075153 ws_file_names[i] = paths[i].AsUTF16Unsafe();
[email protected]600ea402011-04-12 00:01:515154
5155 enumeration_completions_[id]->didChooseFile(ws_file_names);
5156 enumeration_completions_.erase(id);
5157}
5158
[email protected]fb11b6a42012-03-14 07:25:125159void RenderViewImpl::OnFileChooserResponse(
[email protected]ddb034b2012-06-26 20:31:395160 const std::vector<ui::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:365161 // This could happen if we navigated to a different page before the user
5162 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:475163 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:365164 return;
5165
[email protected]b5188522012-03-15 00:18:045166 // Convert Chrome's SelectedFileInfo list to WebKit's.
5167 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
5168 files.size());
5169 for (size_t i = 0; i < files.size(); ++i) {
5170 WebFileChooserCompletion::SelectedFileInfo selected_file;
[email protected]728c2ee2013-06-25 04:01:075171 selected_file.path = files[i].local_path.AsUTF16Unsafe();
5172 selected_file.displayName =
5173 base::FilePath(files[i].display_name).AsUTF16Unsafe();
[email protected]b5188522012-03-15 00:18:045174 selected_files[i] = selected_file;
5175 }
[email protected]a1128322009-10-06 18:38:465176
[email protected]cdaf8d02010-03-30 19:52:475177 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:045178 file_chooser_completions_.front()->completion->didChooseFile(
5179 selected_files);
[email protected]cdaf8d02010-03-30 19:52:475180 file_chooser_completions_.pop_front();
5181
5182 // If there are more pending file chooser requests, schedule one now.
5183 if (!file_chooser_completions_.empty()) {
5184 Send(new ViewHostMsg_RunFileChooser(routing_id_,
5185 file_chooser_completions_.front()->params));
5186 }
initial.commit09911bf2008-07-26 23:55:295187}
5188
[email protected]244ac1892011-12-02 17:04:475189void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
5190 const gfx::Size& max_size) {
5191 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5192 if (!webview())
5193 return;
[email protected]97e1bf72013-03-06 14:06:055194 auto_resize_mode_ = true;
[email protected]61e2b3cc2012-03-02 16:13:345195 webview()->enableAutoResizeMode(min_size, max_size);
5196}
5197
5198void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
5199 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5200 if (!webview())
5201 return;
[email protected]97e1bf72013-03-06 14:06:055202 auto_resize_mode_ = false;
[email protected]61e2b3cc2012-03-02 16:13:345203 webview()->disableAutoResizeMode();
5204
[email protected]eac2b362013-05-22 07:01:455205 if (!new_size.IsEmpty()) {
5206 Resize(new_size,
5207 physical_backing_size_,
5208 overdraw_bottom_height_,
5209 resizer_rect_,
5210 is_fullscreen_,
5211 NO_RESIZE_ACK);
5212 }
[email protected]244ac1892011-12-02 17:04:475213}
5214
[email protected]2bf834f2011-11-17 20:02:215215void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:245216 if (send_preferred_size_changes_)
5217 return;
[email protected]9fb325e2010-05-06 18:23:245218 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:395219
[email protected]d812fd12011-05-27 23:05:075220 // Start off with an initial preferred size notification (in case
5221 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:595222 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:085223}
5224
[email protected]310ebd6302011-10-10 19:06:285225void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:105226 const gfx::Size& disable_scrollbar_size_limit) {
5227 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
5228}
5229
[email protected]310ebd6302011-10-10 19:06:285230void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:265231 const RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:505232 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:515233 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:375234 UpdateFontRenderingFromRendererPrefs();
[email protected]38a85712013-01-02 22:45:025235
5236#if defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK)
[email protected]1596efb2013-01-17 22:13:015237 if (renderer_prefs.use_custom_colors) {
[email protected]180ef242013-11-07 06:50:465238 WebColorName name = blink::WebColorWebkitFocusRingColor;
5239 blink::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
5240 blink::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]38a85712013-01-02 22:45:025241#if defined(TOOLKIT_GTK)
[email protected]1596efb2013-01-17 22:13:015242 ui::NativeTheme::instance()->SetScrollbarColors(
[email protected]93623c5d2009-12-10 21:40:325243 renderer_prefs.thumb_inactive_color,
5244 renderer_prefs.thumb_active_color,
5245 renderer_prefs.track_color);
[email protected]38a85712013-01-02 22:45:025246#endif // defined(TOOLKIT_GTK)
[email protected]1596efb2013-01-17 22:13:015247
5248 if (webview()) {
[email protected]1596efb2013-01-17 22:13:015249 webview()->setSelectionColors(
5250 renderer_prefs.active_selection_bg_color,
5251 renderer_prefs.active_selection_fg_color,
5252 renderer_prefs.inactive_selection_bg_color,
5253 renderer_prefs.inactive_selection_fg_color);
5254 webview()->themeChanged();
5255 }
[email protected]644d77e2010-01-27 01:03:105256 }
[email protected]38a85712013-01-02 22:45:025257#endif // defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK)
[email protected]d299d972012-03-23 02:26:555258
[email protected]107c0532013-02-06 02:34:095259 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
5260 RenderThreadImpl::current()->SetFlingCurveParameters(
5261 renderer_prefs.touchpad_fling_profile,
5262 renderer_prefs.touchscreen_fling_profile);
5263
[email protected]d051d9a2011-12-10 02:02:505264 // If the zoom level for this page matches the old zoom default, and this
5265 // is not a plugin, update the zoom level to match the new default.
5266 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
[email protected]cbe55d22013-02-14 17:04:335267 !ZoomValuesEqual(old_zoom_level,
5268 renderer_preferences_.default_zoom_level) &&
[email protected]e9ff79c2012-10-19 21:31:265269 ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
[email protected]91219702013-09-18 07:33:515270 webview()->setZoomLevel(renderer_preferences_.default_zoom_level);
[email protected]d051d9a2011-12-10 02:02:505271 zoomLevelChanged();
5272 }
[email protected]80d96fa2009-06-10 22:34:515273}
5274
[email protected]310ebd6302011-10-10 19:06:285275void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
5276 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:285277 if (webview())
5278 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:565279}
5280
[email protected]77829642012-05-15 14:47:175281void RenderViewImpl::OnOrientationChangeEvent(int orientation) {
[email protected]a794f3a2013-10-30 17:00:325282 // Screen has rotated. 0 = default (portrait), 90 = one turn right, and so on.
[email protected]652ad832013-08-16 11:47:045283 FOR_EACH_OBSERVER(RenderViewObserver,
5284 observers_,
5285 OrientationChangeEvent(orientation));
[email protected]77829642012-05-15 14:47:175286 webview()->mainFrame()->sendOrientationChangeEvent(orientation);
5287}
5288
[email protected]81375e872012-01-11 21:40:365289void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
5290 const WebPluginAction& action) {
5291 if (webview())
5292 webview()->performPluginAction(action, location);
5293}
5294
[email protected]310ebd6302011-10-10 19:06:285295void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:195296 const GURL& page_url) {
5297 // Prepare list to storage all savable resource links.
5298 std::vector<GURL> resources_list;
[email protected]c2d986512012-05-12 00:22:465299 std::vector<GURL> referrer_urls_list;
[email protected]180ef242013-11-07 06:50:465300 std::vector<blink::WebReferrerPolicy> referrer_policies_list;
[email protected]18d5be92011-07-25 18:00:195301 std::vector<GURL> frames_list;
[email protected]12a936d2013-05-15 04:55:495302 SavableResourcesResult result(&resources_list,
5303 &referrer_urls_list,
5304 &referrer_policies_list,
5305 &frames_list);
[email protected]18d5be92011-07-25 18:00:195306
[email protected]e9ff79c2012-10-19 21:31:265307 // webkit/ doesn't know about Referrer.
[email protected]12a936d2013-05-15 04:55:495308 if (!GetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:195309 webview(),
5310 page_url,
5311 &result,
[email protected]e9ff79c2012-10-19 21:31:265312 const_cast<const char**>(GetSavableSchemes()))) {
[email protected]18d5be92011-07-25 18:00:195313 // If something is wrong when collecting all savable resource links,
5314 // send empty list to embedder(browser) to tell it failed.
[email protected]c2d986512012-05-12 00:22:465315 referrer_urls_list.clear();
5316 referrer_policies_list.clear();
[email protected]18d5be92011-07-25 18:00:195317 resources_list.clear();
5318 frames_list.clear();
5319 }
5320
[email protected]e9ff79c2012-10-19 21:31:265321 std::vector<Referrer> referrers_list;
[email protected]c2d986512012-05-12 00:22:465322 CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size());
5323 for (unsigned i = 0; i < referrer_urls_list.size(); ++i) {
5324 referrers_list.push_back(
[email protected]e9ff79c2012-10-19 21:31:265325 Referrer(referrer_urls_list[i], referrer_policies_list[i]));
[email protected]c2d986512012-05-12 00:22:465326 }
5327
[email protected]18d5be92011-07-25 18:00:195328 // Send result of all savable resource links to embedder.
5329 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
5330 resources_list,
5331 referrers_list,
5332 frames_list));
5333}
5334
[email protected]310ebd6302011-10-10 19:06:285335void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:195336 const std::vector<GURL>& links,
[email protected]c42de732013-02-16 06:26:315337 const std::vector<base::FilePath>& local_paths,
5338 const base::FilePath& local_directory_name) {
[email protected]18d5be92011-07-25 18:00:195339
5340 // Convert std::vector of GURLs to WebVector<WebURL>
5341 WebVector<WebURL> weburl_links(links);
5342
[email protected]728c2ee2013-06-25 04:01:075343 // Convert std::vector of base::FilePath to WebVector<WebString>
[email protected]18d5be92011-07-25 18:00:195344 WebVector<WebString> webstring_paths(local_paths.size());
5345 for (size_t i = 0; i < local_paths.size(); i++)
[email protected]728c2ee2013-06-25 04:01:075346 webstring_paths[i] = local_paths[i].AsUTF16Unsafe();
[email protected]18d5be92011-07-25 18:00:195347
5348 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
5349 webstring_paths,
[email protected]728c2ee2013-06-25 04:01:075350 local_directory_name.AsUTF16Unsafe());
[email protected]18d5be92011-07-25 18:00:195351}
5352
[email protected]310ebd6302011-10-10 19:06:285353void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:125354 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:275355 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:125356 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
5357 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
5358 before_unload_start_time,
5359 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:295360}
5361
[email protected]88f10a22013-11-06 21:22:125362void RenderViewImpl::OnSuppressDialogsUntilSwapOut() {
5363 // Don't show any more dialogs until we finish OnSwapOut.
5364 suppress_dialogs_until_swap_out_ = true;
5365}
5366
[email protected]e1986832013-06-14 07:27:285367void RenderViewImpl::OnSwapOut() {
[email protected]73eb2602012-02-09 19:50:555368 // Only run unload if we're not swapped out yet, but send the ack either way.
5369 if (!is_swapped_out_) {
5370 // Swap this RenderView out so the tab can navigate to a page rendered by a
5371 // different process. This involves running the unload handler and clearing
5372 // the page. Once WasSwappedOut is called, we also allow this process to
5373 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:155374
[email protected]73eb2602012-02-09 19:50:555375 // Send an UpdateState message before we get swapped out.
5376 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:155377
[email protected]73eb2602012-02-09 19:50:555378 // Synchronously run the unload handler before sending the ACK.
5379 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:155380
[email protected]73eb2602012-02-09 19:50:555381 // Swap out and stop sending any IPC messages that are not ACKs.
5382 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:155383
[email protected]6169a5772013-05-29 17:41:145384 // Now that we're swapped out and filtering IPC messages, stop loading to
5385 // ensure that no other in-progress navigation continues. We do this here
5386 // to avoid sending a DidStopLoading message to the browser process.
5387 OnStop();
5388
[email protected]285f4bb82012-04-17 15:57:285389 // Replace the page with a blank dummy URL. The unload handler will not be
[email protected]73eb2602012-02-09 19:50:555390 // run a second time, thanks to a check in FrameLoader::stopLoading.
5391 // TODO(creis): Need to add a better way to do this that avoids running the
[email protected]285f4bb82012-04-17 15:57:285392 // beforeunload handler. For now, we just run it a second time silently.
[email protected]0720b532012-08-28 19:23:375393 NavigateToSwappedOutURL(webview()->mainFrame());
[email protected]961541a92012-06-01 21:15:285394
5395 // Let WebKit know that this view is hidden so it can drop resources and
5396 // stop compositing.
[email protected]180ef242013-11-07 06:50:465397 webview()->setVisibilityState(blink::WebPageVisibilityStateHidden, false);
[email protected]73eb2602012-02-09 19:50:555398 }
[email protected]992db4c2011-05-12 15:37:155399
[email protected]88f10a22013-11-06 21:22:125400 // It is now safe to show modal dialogs again.
5401 suppress_dialogs_until_swap_out_ = false;
5402
[email protected]e1986832013-06-14 07:27:285403 Send(new ViewHostMsg_SwapOut_ACK(routing_id_));
[email protected]992db4c2011-05-12 15:37:155404}
5405
[email protected]180ef242013-11-07 06:50:465406void RenderViewImpl::NavigateToSwappedOutURL(blink::WebFrame* frame) {
[email protected]14392a52012-05-02 20:28:445407 // We use loadRequest instead of loadHTMLString because the former commits
5408 // synchronously. Otherwise a new navigation can interrupt the navigation
[email protected]e9ff79c2012-10-19 21:31:265409 // to kSwappedOutURL. If that happens to be to the page we had been
[email protected]14392a52012-05-02 20:28:445410 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]890b06ca2012-12-13 21:07:365411 CHECK(is_swapped_out_);
[email protected]e9ff79c2012-10-19 21:31:265412 GURL swappedOutURL(kSwappedOutURL);
[email protected]14392a52012-05-02 20:28:445413 WebURLRequest request(swappedOutURL);
[email protected]0720b532012-08-28 19:23:375414 frame->loadRequest(request);
[email protected]14392a52012-05-02 20:28:445415}
5416
[email protected]310ebd6302011-10-10 19:06:285417void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:375418 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:295419 // TODO(creis): We'd rather use webview()->Close() here, but that currently
5420 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
5421 // in the onunload handler from appearing. For now, we're bypassing that and
5422 // calling the FrameLoader's CloseURL method directly. This should be
5423 // revisited to avoid having two ways to close a page. Having a single way
5424 // to close that can run onunload is also useful for fixing
5425 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:275426 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:295427
[email protected]992db4c2011-05-12 15:37:155428 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:295429}
5430
[email protected]310ebd6302011-10-10 19:06:285431void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:025432#if defined(USE_AURA)
5433 // Aura doesn't care if we switch themes.
5434#elif defined(OS_WIN)
[email protected]f78452f2012-05-15 02:07:525435 ui::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:465436 if (webview())
5437 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:575438#else // defined(OS_WIN)
5439 // TODO(port): we don't support theming on non-Windows platforms yet
5440 NOTIMPLEMENTED();
5441#endif
initial.commit09911bf2008-07-26 23:55:295442}
5443
[email protected]310ebd6302011-10-10 19:06:285444bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
5445 const WebURLError& error,
5446 bool replace) {
[email protected]15d79e12009-08-02 19:23:455447 // We only show alternate error pages in the main frame. They are
5448 // intended to assist the user when navigating, so there is not much
5449 // value in showing them for failed subframes. Ideally, we would be
5450 // able to use the TYPED transition type for this, but that flag is
5451 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455452 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455453 return false;
5454
5455 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375456 // connection failure.
[email protected]15d79e12009-08-02 19:23:455457 int ec = error.reason;
5458 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5459 ec != net::ERR_CONNECTION_FAILED &&
5460 ec != net::ERR_CONNECTION_REFUSED &&
5461 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]82114f52012-03-20 22:53:415462 ec != net::ERR_CONNECTION_TIMED_OUT) {
[email protected]15d79e12009-08-02 19:23:455463 return false;
[email protected]82114f52012-03-20 22:53:415464 }
[email protected]15d79e12009-08-02 19:23:455465
5466 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555467 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455468 if (!error_page_url.is_valid())
5469 return false;
5470
[email protected]11a65772013-04-27 00:36:425471 WebDataSource* ds = frame->provisionalDataSource();
5472 const WebURLRequest& failed_request = ds->request();
5473
[email protected]15d79e12009-08-02 19:23:455474 // Load an empty page first so there is an immediate response to the error,
5475 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455476 frame->loadHTMLString(std::string(),
[email protected]e9ff79c2012-10-19 21:31:265477 GURL(kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455478 error.unreachableURL,
5479 replace);
5480
5481 // Now, create a fetcher for the error page and associate it with the data
5482 // source we just created via the LoadHTMLString call. That way if another
5483 // navigation occurs, the fetcher will get destroyed.
[email protected]e20b88d2013-04-09 15:28:375484 InternalDocumentStateData* internal_data =
5485 InternalDocumentStateData::FromDataSource(frame->provisionalDataSource());
5486 internal_data->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:455487 new AltErrorPageResourceFetcher(
[email protected]11a65772013-04-27 00:36:425488 error_page_url, frame, failed_request, error,
[email protected]6e806822011-11-19 01:51:085489 base::Bind(&RenderViewImpl::AltErrorPageFinished,
5490 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:455491 return true;
5492}
5493
[email protected]310ebd6302011-10-10 19:06:285494void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
[email protected]11a65772013-04-27 00:36:425495 const WebURLRequest& original_request,
[email protected]310ebd6302011-10-10 19:06:285496 const WebURLError& original_error,
5497 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:455498 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:095499 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:555500 // will simply display a default error page.
[email protected]11a65772013-04-27 00:36:425501 LoadNavigationErrorPage(frame, original_request, original_error, html, true);
[email protected]15d79e12009-08-02 19:23:455502}
5503
[email protected]310ebd6302011-10-10 19:06:285504void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:005505 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475506 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005507}
5508
[email protected]0fdd5012013-05-29 08:05:565509void RenderViewImpl::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]cda45c02010-02-25 19:28:105510 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475511 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105512 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205513 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]0fdd5012013-05-29 08:05:565514 ShouldDisplayScrollbars(params.new_size.width(),
5515 params.new_size.height()));
[email protected]cda45c02010-02-25 19:28:105516 }
[email protected]dd6afca2011-08-13 03:44:315517 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:105518 }
5519
[email protected]0fdd5012013-05-29 08:05:565520 RenderWidget::OnResize(params);
[email protected]30f75e62009-02-25 22:01:005521}
[email protected]0aa477bd2009-03-23 22:21:435522
[email protected]310ebd6302011-10-10 19:06:285523void RenderViewImpl::DidInitiatePaint() {
[email protected]ea2fb972013-08-07 05:44:265524#if defined(ENABLE_PLUGINS)
5525 // Notify all instances that we painted. The same caveats apply as for
5526 // ViewFlushedPaint regarding instances closing themselves, so we take
5527 // similar precautions.
5528 PepperPluginSet plugins = active_pepper_instances_;
5529 for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) {
5530 if (active_pepper_instances_.find(*i) != active_pepper_instances_.end())
5531 (*i)->ViewInitiatedPaint();
5532 }
5533#endif
[email protected]00c39612010-03-06 02:53:285534}
5535
[email protected]310ebd6302011-10-10 19:06:285536void RenderViewImpl::DidFlushPaint() {
[email protected]ea2fb972013-08-07 05:44:265537#if defined(ENABLE_PLUGINS)
5538 // Notify all instances that we flushed. This will call into the plugin, and
5539 // we it may ask to close itself as a result. This will, in turn, modify our
5540 // set, possibly invalidating the iterator. So we iterate on a copy that
[email protected]00c39612010-03-06 02:53:285541 // won't change out from under us.
[email protected]ea2fb972013-08-07 05:44:265542 PepperPluginSet plugins = active_pepper_instances_;
5543 for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) {
5544 // The copy above makes sure our iterator is never invalid if some plugins
5545 // are destroyed. But some plugin may decide to close all of its views in
5546 // response to a paint in one of them, so we need to make sure each one is
5547 // still "current" before using it.
5548 //
5549 // It's possible that a plugin was destroyed, but another one was created
5550 // with the same address. In this case, we'll call ViewFlushedPaint on that
5551 // new plugin. But that's OK for this particular case since we're just
5552 // notifying all of our instances that the view flushed, and the new one is
5553 // one of our instances.
5554 //
5555 // What about the case where a new one is created in a callback at a new
5556 // address and we don't issue the callback? We're still OK since this
5557 // callback is used for flush callbacks and we could not have possibly
[email protected]0704ac32013-10-03 15:24:225558 // started a new paint for the new plugin while processing a previous paint
5559 // for an existing one.
[email protected]ea2fb972013-08-07 05:44:265560 if (active_pepper_instances_.find(*i) != active_pepper_instances_.end())
5561 (*i)->ViewFlushedPaint();
5562 }
5563#endif
[email protected]53900d52010-06-16 04:25:015564
[email protected]5b1dec8c2012-02-07 04:35:385565 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
5566 // See crbug.com/112921.
5567 if (!webview())
5568 return;
5569
[email protected]00c39612010-03-06 02:53:285570 WebFrame* main_frame = webview()->mainFrame();
5571
5572 // If we have a provisional frame we are between the start and commit stages
5573 // of loading and we don't want to save stats.
5574 if (!main_frame->provisionalDataSource()) {
5575 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:075576 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]92d457802013-04-01 19:18:495577 InternalDocumentStateData* data =
[email protected]e20b88d2013-04-09 15:28:375578 InternalDocumentStateData::FromDocumentState(document_state);
[email protected]92d457802013-04-01 19:18:495579 if (data->did_first_visually_non_empty_layout() &&
5580 !data->did_first_visually_non_empty_paint()) {
5581 data->set_did_first_visually_non_empty_paint(true);
5582 Send(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_,
5583 page_id_));
5584 }
5585
[email protected]05c8e502010-08-15 15:13:525586 // TODO(jar): The following code should all be inside a method, probably in
5587 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285588 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:075589 if (document_state->first_paint_time().is_null()) {
5590 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:285591 }
[email protected]007733c2011-11-17 00:34:075592 if (document_state->first_paint_after_load_time().is_null() &&
5593 !document_state->finish_load_time().is_null()) {
5594 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:285595 }
5596 }
5597}
5598
[email protected]adab2332013-07-25 18:04:325599PepperPluginInstanceImpl* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
5600 const gfx::Rect& paint_bounds,
5601 TransportDIB** dib,
5602 gfx::Rect* location,
5603 gfx::Rect* clip,
5604 float* scale_factor) {
[email protected]ea2fb972013-08-07 05:44:265605#if defined(ENABLE_PLUGINS)
5606 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
5607 i != active_pepper_instances_.end(); ++i) {
5608 PepperPluginInstanceImpl* instance = *i;
5609 // In Flash fullscreen , the plugin contents should be painted onto the
5610 // fullscreen widget instead of the web page.
5611 if (!instance->FlashIsFullscreenOrPending() &&
5612 instance->GetBitmapForOptimizedPluginPaint(paint_bounds, dib, location,
5613 clip, scale_factor))
5614 return *i;
5615 }
5616#endif
5617 return NULL;
[email protected]ca4847f2010-09-24 05:39:155618}
5619
[email protected]ceb36f7d2012-10-31 18:33:245620gfx::Vector2d RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:075621 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]ceb36f7d2012-10-31 18:33:245622 return gfx::Vector2d(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:525623}
5624
[email protected]310ebd6302011-10-10 19:06:285625void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:165626 if (webview())
[email protected]26aa0482009-09-30 16:55:275627 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165628}
5629
[email protected]310ebd6302011-10-10 19:06:285630void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:145631 if (webview())
[email protected]b4bb2502009-10-01 22:35:275632 webview()->setIsTransparent(!background.empty());
[email protected]ba91a792013-02-06 09:48:285633 if (compositor_)
5634 compositor_->setHasTransparentBackground(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145635
5636 SetBackground(background);
5637}
5638
[email protected]2a84f9d2012-06-05 21:50:435639void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) {
5640 if (accessibility_mode_ == new_mode)
5641 return;
5642 accessibility_mode_ = new_mode;
5643 if (renderer_accessibility_) {
5644 delete renderer_accessibility_;
5645 renderer_accessibility_ = NULL;
5646 }
5647 if (accessibility_mode_ == AccessibilityModeComplete)
5648 renderer_accessibility_ = new RendererAccessibilityComplete(this);
[email protected]8d3dfee62013-06-19 05:50:335649#if !defined(OS_ANDROID)
[email protected]2a84f9d2012-06-05 21:50:435650 else if (accessibility_mode_ == AccessibilityModeEditableTextOnly)
5651 renderer_accessibility_ = new RendererAccessibilityFocusOnly(this);
[email protected]8d3dfee62013-06-19 05:50:335652#endif
[email protected]2a84f9d2012-06-05 21:50:435653}
5654
[email protected]310ebd6302011-10-10 19:06:285655void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:345656 if (webview())
[email protected]b4bb2502009-10-01 22:35:275657 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265658
[email protected]a80af12e2013-08-07 23:36:135659#if defined(ENABLE_PLUGINS) && defined(OS_MACOSX)
[email protected]d8fd6fa2010-02-01 15:54:265660 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5661 for (plugin_it = plugin_delegates_.begin();
5662 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5663 (*plugin_it)->SetWindowFocus(active);
5664 }
5665#endif
[email protected]8c66c5a2009-07-22 17:26:345666}
5667
[email protected]6ce7abc52010-02-02 18:40:145668#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285669void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]a80af12e2013-08-07 23:36:135670#if defined(ENABLE_PLUGINS)
[email protected]6ce7abc52010-02-02 18:40:145671 // Inform plugins that their container has changed visibility.
5672 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5673 for (plugin_it = plugin_delegates_.begin();
5674 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5675 (*plugin_it)->SetContainerVisibility(visible);
5676 }
[email protected]a80af12e2013-08-07 23:36:135677#endif
[email protected]6ce7abc52010-02-02 18:40:145678}
[email protected]1e6e3c992010-02-08 15:52:135679
[email protected]310ebd6302011-10-10 19:06:285680void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
5681 const gfx::Rect& view_frame) {
[email protected]a80af12e2013-08-07 23:36:135682#if defined(ENABLE_PLUGINS)
[email protected]1e6e3c992010-02-08 15:52:135683 // Inform plugins that their window's frame has changed.
5684 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5685 for (plugin_it = plugin_delegates_.begin();
5686 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5687 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5688 }
[email protected]a80af12e2013-08-07 23:36:135689#endif
[email protected]1e6e3c992010-02-08 15:52:135690}
[email protected]935d63d2010-10-15 23:31:555691
[email protected]310ebd6302011-10-10 19:06:285692void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
5693 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135694 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555695 // applies to it or not, so inform all the delegates.
5696 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5697 for (plugin_it = plugin_delegates_.begin();
5698 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135699 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555700 }
5701}
[email protected]6ce7abc52010-02-02 18:40:145702#endif // OS_MACOSX
5703
[email protected]310ebd6302011-10-10 19:06:285704void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:595705 // We need to grab a pointer to the doomed WebView before we destroy it.
5706 WebView* doomed = webview();
5707 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495708 g_view_map.Get().erase(doomed);
[email protected]058561b2012-12-03 06:48:225709 g_routing_id_view_map.Get().erase(routing_id_);
[email protected]60c42a8c72009-10-09 04:08:595710}
5711
[email protected]310ebd6302011-10-10 19:06:285712void RenderViewImpl::DidHandleKeyEvent() {
[email protected]b2324b092012-11-01 10:34:115713 ClearEditCommands();
[email protected]446705872009-09-10 07:22:485714}
5715
[email protected]180ef242013-11-07 06:50:465716bool RenderViewImpl::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]a14ddcd2013-06-21 22:53:035717 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]41d86852012-11-07 12:23:245718 possible_drag_event_info_.event_source =
5719 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
5720 possible_drag_event_info_.event_location =
5721 gfx::Point(event.globalX, event.globalY);
[email protected]ea2fb972013-08-07 05:44:265722
5723#if defined(ENABLE_PLUGINS)
5724 // This method is called for every mouse event that the render view receives.
5725 // And then the mouse event is forwarded to WebKit, which dispatches it to the
5726 // event target. Potentially a Pepper plugin will receive the event.
5727 // In order to tell whether a plugin gets the last mouse event and which it
5728 // is, we set |pepper_last_mouse_event_target_| to NULL here. If a plugin gets
5729 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
5730 // |pepper_last_mouse_event_target_|.
5731 pepper_last_mouse_event_target_ = NULL;
5732#endif
[email protected]217690d2012-01-27 07:33:115733
5734 // If the mouse is locked, only the current owner of the mouse lock can
5735 // process mouse events.
5736 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:375737}
5738
[email protected]180ef242013-11-07 06:50:465739bool RenderViewImpl::WillHandleKeyEvent(const blink::WebKeyboardEvent& event) {
[email protected]a14ddcd2013-06-21 22:53:035740 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]f56c7872013-06-18 12:31:575741 return false;
5742}
5743
[email protected]41d86852012-11-07 12:23:245744bool RenderViewImpl::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:465745 const blink::WebGestureEvent& event) {
[email protected]a14ddcd2013-06-21 22:53:035746 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:245747 possible_drag_event_info_.event_source =
5748 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
5749 possible_drag_event_info_.event_location =
5750 gfx::Point(event.globalX, event.globalY);
5751 return false;
5752}
5753
[email protected]2b942c332012-04-25 16:26:265754void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515755 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065756}
5757
[email protected]310ebd6302011-10-10 19:06:285758void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:245759 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
5760}
5761
[email protected]3d5c243b2012-11-30 00:26:015762bool RenderViewImpl::HasTouchEventHandlersAt(const gfx::Point& point) const {
5763 if (!webview())
5764 return false;
5765 return webview()->hasTouchEventHandlersAt(point);
5766}
5767
[email protected]310ebd6302011-10-10 19:06:285768void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:435769 RenderWidget::OnWasHidden();
5770
[email protected]68877c282013-09-20 05:52:425771#if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
[email protected]6392d982013-04-16 16:59:225772 RenderThreadImpl::current()->video_capture_impl_manager()->
5773 SuspendDevices(true);
5774#endif
[email protected]2d7b82c2012-06-01 05:57:505775
[email protected]8869d392013-05-07 15:34:265776 if (webview())
[email protected]f59203a2011-06-07 10:01:445777 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075778
[email protected]ea2fb972013-08-07 05:44:265779#if defined(ENABLE_PLUGINS)
[email protected]204f1df2012-01-04 20:21:135780 // Inform PPAPI plugins that their page is no longer visible.
[email protected]ea2fb972013-08-07 05:44:265781 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
5782 i != active_pepper_instances_.end(); ++i)
5783 (*i)->PageVisibilityChanged(false);
[email protected]204f1df2012-01-04 20:21:135784
[email protected]a6939ca42011-02-18 17:58:075785#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135786 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:435787 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5788 for (plugin_it = plugin_delegates_.begin();
5789 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5790 (*plugin_it)->SetContainerVisibility(false);
5791 }
[email protected]a6939ca42011-02-18 17:58:075792#endif // OS_MACOSX
[email protected]a80af12e2013-08-07 23:36:135793#endif // ENABLE_PLUGINS
[email protected]941e4552010-02-01 21:23:435794}
5795
[email protected]9e2e4632012-07-27 16:38:415796void RenderViewImpl::OnWasShown(bool needs_repainting) {
5797 RenderWidget::OnWasShown(needs_repainting);
[email protected]941e4552010-02-01 21:23:435798
[email protected]6392d982013-04-16 16:59:225799#if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
5800 RenderThreadImpl::current()->video_capture_impl_manager()->
5801 SuspendDevices(false);
5802#endif
5803
[email protected]8869d392013-05-07 15:34:265804 if (webview())
[email protected]f59203a2011-06-07 10:01:445805 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075806
[email protected]ea2fb972013-08-07 05:44:265807#if defined(ENABLE_PLUGINS)
[email protected]204f1df2012-01-04 20:21:135808 // Inform PPAPI plugins that their page is visible.
[email protected]ea2fb972013-08-07 05:44:265809 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
5810 i != active_pepper_instances_.end(); ++i)
5811 (*i)->PageVisibilityChanged(true);
[email protected]204f1df2012-01-04 20:21:135812
[email protected]a6939ca42011-02-18 17:58:075813#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135814 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:435815 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5816 for (plugin_it = plugin_delegates_.begin();
5817 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5818 (*plugin_it)->SetContainerVisibility(true);
5819 }
[email protected]784ea1ab2010-09-18 00:02:345820#endif // OS_MACOSX
[email protected]a80af12e2013-08-07 23:36:135821#endif // ENABLE_PLUGINS
[email protected]a6939ca42011-02-18 17:58:075822}
[email protected]1e6e3c992010-02-08 15:52:135823
[email protected]ed7defa2013-03-12 21:29:595824GURL RenderViewImpl::GetURLForGraphicsContext3D() {
5825 DCHECK(webview());
5826 if (webview()->mainFrame())
5827 return GURL(webview()->mainFrame()->document().url());
5828 else
5829 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]65225772011-05-12 21:10:245830}
5831
[email protected]479b0172012-10-29 19:27:095832bool RenderViewImpl::ForceCompositingModeEnabled() {
5833 return webkit_preferences_.force_compositing_mode;
5834}
5835
[email protected]310ebd6302011-10-10 19:06:285836void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:135837 RenderWidget::OnSetFocus(enable);
5838
[email protected]a80af12e2013-08-07 23:36:135839#if defined(ENABLE_PLUGINS)
[email protected]7d3c02c2010-05-05 23:10:315840 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075841 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135842 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5843 for (plugin_it = plugin_delegates_.begin();
5844 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345845#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315846 // RenderWidget's call to setFocus can cause the underlying webview's
5847 // activation state to change just like a call to setIsActive.
5848 if (enable)
5849 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345850#endif
[email protected]7d3c02c2010-05-05 23:10:315851 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135852 }
5853 }
[email protected]a01da5682012-06-30 00:37:315854 // Notify all Pepper plugins.
[email protected]ea2fb972013-08-07 05:44:265855 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
5856 i != active_pepper_instances_.end(); ++i)
5857 (*i)->SetContentAreaFocus(enable);
5858#endif
[email protected]321032992012-11-08 01:01:275859 // Notify all BrowserPlugins of the RenderView's focus state.
[email protected]fc72bb12013-06-02 21:13:465860 if (browser_plugin_manager_.get())
[email protected]caaf2482013-05-01 20:33:325861 browser_plugin_manager_->UpdateFocusState();
[email protected]1e6e3c992010-02-08 15:52:135862}
[email protected]941e4552010-02-01 21:23:435863
[email protected]310ebd6302011-10-10 19:06:285864void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:575865 const string16& text,
[email protected]180ef242013-11-07 06:50:465866 const std::vector<blink::WebCompositionUnderline>& underlines,
[email protected]56ea1a62011-05-30 07:05:575867 int selection_start,
5868 int selection_end) {
[email protected]ea2fb972013-08-07 05:44:265869#if defined(ENABLE_PLUGINS)
5870 if (focused_pepper_plugin_) {
[email protected]73bf95812011-10-12 11:38:325871 // When a PPAPI plugin has focus, we bypass WebKit.
[email protected]ea2fb972013-08-07 05:44:265872 if (!IsPepperAcceptingCompositionEvents()) {
5873 pepper_composition_text_ = text;
5874 } else {
5875 // TODO(kinaba) currently all composition events are sent directly to
5876 // plugins. Use DOM event mechanism after WebKit is made aware about
5877 // plugins that support composition.
5878 // The code below mimics the behavior of WebCore::Editor::setComposition.
5879
5880 // Empty -> nonempty: composition started.
5881 if (pepper_composition_text_.empty() && !text.empty())
5882 focused_pepper_plugin_->HandleCompositionStart(string16());
5883 // Nonempty -> empty: composition canceled.
5884 if (!pepper_composition_text_.empty() && text.empty())
5885 focused_pepper_plugin_->HandleCompositionEnd(string16());
5886 pepper_composition_text_ = text;
5887 // Nonempty: composition is ongoing.
5888 if (!pepper_composition_text_.empty()) {
5889 focused_pepper_plugin_->HandleCompositionUpdate(
5890 pepper_composition_text_, underlines, selection_start,
5891 selection_end);
[email protected]e6ae0f6c2011-10-04 10:39:235892 }
[email protected]e6ae0f6c2011-10-04 10:39:235893 }
[email protected]ea2fb972013-08-07 05:44:265894 return;
[email protected]56ea1a62011-05-30 07:05:575895 }
[email protected]ea2fb972013-08-07 05:44:265896
5897#if defined(OS_WIN)
5898 // When a plug-in has focus, we create platform-specific IME data used by
5899 // our IME emulator and send it directly to the focused plug-in, i.e. we
5900 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
5901 // instance ID is the same one as the specified ID.)
5902 if (focused_plugin_id_ >= 0) {
5903 std::vector<int> clauses;
5904 std::vector<int> target;
5905 for (size_t i = 0; i < underlines.size(); ++i) {
5906 clauses.push_back(underlines[i].startOffset);
5907 clauses.push_back(underlines[i].endOffset);
5908 if (underlines[i].thick) {
5909 target.clear();
5910 target.push_back(underlines[i].startOffset);
5911 target.push_back(underlines[i].endOffset);
5912 }
5913 }
5914 std::set<WebPluginDelegateProxy*>::iterator it;
5915 for (it = plugin_delegates_.begin(); it != plugin_delegates_.end(); ++it) {
5916 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
5917 focused_plugin_id_);
5918 }
5919 return;
5920 }
[email protected]a80af12e2013-08-07 23:36:135921#endif // OS_WIN
5922#endif // ENABLE_PLUGINS
[email protected]ea2fb972013-08-07 05:44:265923 RenderWidget::OnImeSetComposition(text,
5924 underlines,
5925 selection_start,
5926 selection_end);
[email protected]56ea1a62011-05-30 07:05:575927}
5928
[email protected]db4fc1e2013-09-06 20:01:515929void RenderViewImpl::OnImeConfirmComposition(
5930 const string16& text,
5931 const gfx::Range& replacement_range,
5932 bool keep_selection) {
[email protected]ea2fb972013-08-07 05:44:265933#if defined(ENABLE_PLUGINS)
5934 if (focused_pepper_plugin_) {
[email protected]73bf95812011-10-12 11:38:325935 // When a PPAPI plugin has focus, we bypass WebKit.
[email protected]ea2fb972013-08-07 05:44:265936 // Here, text.empty() has a special meaning. It means to commit the last
5937 // update of composition text (see
5938 // RenderWidgetHost::ImeConfirmComposition()).
5939 const string16& last_text = text.empty() ? pepper_composition_text_ : text;
5940
5941 // last_text is empty only when both text and pepper_composition_text_ is.
5942 // Ignore it.
5943 if (last_text.empty())
[email protected]e6ae0f6c2011-10-04 10:39:235944 return;
[email protected]ea2fb972013-08-07 05:44:265945
5946 if (!IsPepperAcceptingCompositionEvents()) {
[email protected]28fccb32013-08-29 22:25:465947 base::i18n::UTF16CharIterator iterator(&last_text);
5948 int32 i = 0;
5949 while (iterator.Advance()) {
[email protected]180ef242013-11-07 06:50:465950 blink::WebKeyboardEvent char_event;
5951 char_event.type = blink::WebInputEvent::Char;
[email protected]ea2fb972013-08-07 05:44:265952 char_event.timeStampSeconds = base::Time::Now().ToDoubleT();
5953 char_event.modifiers = 0;
5954 char_event.windowsKeyCode = last_text[i];
5955 char_event.nativeKeyCode = last_text[i];
[email protected]28fccb32013-08-29 22:25:465956
5957 const int32 char_start = i;
5958 for (; i < iterator.array_pos(); ++i) {
5959 char_event.text[i - char_start] = last_text[i];
5960 char_event.unmodifiedText[i - char_start] = last_text[i];
5961 }
5962
[email protected]ea2fb972013-08-07 05:44:265963 if (webwidget())
5964 webwidget()->handleInputEvent(char_event);
[email protected]ebd28ac2011-10-13 18:49:055965 }
[email protected]ea2fb972013-08-07 05:44:265966 } else {
5967 // Mimics the order of events sent by WebKit.
5968 // See WebCore::Editor::setComposition() for the corresponding code.
5969 focused_pepper_plugin_->HandleCompositionEnd(last_text);
5970 focused_pepper_plugin_->HandleTextInput(last_text);
[email protected]ebd28ac2011-10-13 18:49:055971 }
[email protected]ea2fb972013-08-07 05:44:265972 pepper_composition_text_.clear();
5973 return;
[email protected]56ea1a62011-05-30 07:05:575974 }
[email protected]ea2fb972013-08-07 05:44:265975#if defined(OS_WIN)
5976 // Same as OnImeSetComposition(), we send the text from IMEs directly to
5977 // plug-ins. When we send IME text directly to plug-ins, we should not send
5978 // it to WebKit to prevent WebKit from controlling IMEs.
5979 // TODO(thakis): Honor |replacement_range| for plugins?
5980 if (focused_plugin_id_ >= 0) {
5981 std::set<WebPluginDelegateProxy*>::iterator it;
5982 for (it = plugin_delegates_.begin();
5983 it != plugin_delegates_.end(); ++it) {
5984 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
5985 }
5986 return;
5987 }
[email protected]a80af12e2013-08-07 23:36:135988#endif // OS_WIN
5989#endif // ENABLE_PLUGINS
[email protected]ea2fb972013-08-07 05:44:265990 if (replacement_range.IsValid() && webview()) {
5991 // Select the text in |replacement_range|, it will then be replaced by
5992 // text added by the call to RenderWidget::OnImeConfirmComposition().
5993 if (WebFrame* frame = webview()->focusedFrame()) {
5994 WebRange webrange = WebRange::fromDocumentRange(
5995 frame, replacement_range.start(), replacement_range.length());
5996 if (!webrange.isNull())
5997 frame->selectRange(webrange);
5998 }
5999 }
6000 RenderWidget::OnImeConfirmComposition(text,
6001 replacement_range,
6002 keep_selection);
[email protected]56ea1a62011-05-30 07:05:576003}
6004
[email protected]468ac582012-11-20 00:53:196005void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor) {
6006 RenderWidget::SetDeviceScaleFactor(device_scale_factor);
[email protected]fb854192013-02-06 01:30:046007 if (webview()) {
[email protected]dea5e7682012-06-14 05:21:246008 webview()->setDeviceScaleFactor(device_scale_factor);
[email protected]fb854192013-02-06 01:30:046009 webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled(
6010 ShouldUseFixedPositionCompositing(device_scale_factor_));
[email protected]c162ced82013-06-29 01:24:536011 webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled(
6012 ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_));
[email protected]d8221b22013-05-23 05:35:436013 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
6014 ShouldUseTransitionCompositing(device_scale_factor_));
[email protected]06fc4d3b2013-07-08 21:07:246015 webview()->settings()->
6016 setAcceleratedCompositingForFixedRootBackgroundEnabled(
6017 ShouldUseAcceleratedFixedRootBackground(device_scale_factor_));
[email protected]e3415902013-10-17 15:00:466018 webview()->settings()->setAcceleratedCompositingForScrollableFramesEnabled(
6019 ShouldUseAcceleratedCompositingForScrollableFrames(
6020 device_scale_factor_));
6021 webview()->settings()->setCompositedScrollingForFramesEnabled(
6022 ShouldUseCompositedScrollingForFrames(device_scale_factor_));
[email protected]fb854192013-02-06 01:30:046023 }
[email protected]3a1c8a8032013-03-18 22:35:326024 if (auto_resize_mode_)
6025 AutoResizeCompositor();
[email protected]caaf2482013-05-01 20:33:326026
[email protected]fc72bb12013-06-02 21:13:466027 if (browser_plugin_manager_.get())
[email protected]caaf2482013-05-01 20:33:326028 browser_plugin_manager_->UpdateDeviceScaleFactor(device_scale_factor_);
[email protected]dea5e7682012-06-14 05:21:246029}
6030
[email protected]310ebd6302011-10-10 19:06:286031ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]ea2fb972013-08-07 05:44:266032#if defined(ENABLE_PLUGINS)
6033 if (focused_pepper_plugin_)
6034 return focused_pepper_plugin_->text_input_type();
6035#endif
6036 return RenderWidget::GetTextInputType();
[email protected]73bf95812011-10-12 11:38:326037}
6038
[email protected]3f783362011-10-21 22:40:506039void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
[email protected]ea2fb972013-08-07 05:44:266040#if defined(ENABLE_PLUGINS)
6041 if (focused_pepper_plugin_) {
[email protected]3f783362011-10-21 22:40:506042 // TODO(kinaba) http://crbug.com/101101
6043 // Current Pepper IME API does not handle selection bounds. So we simply
6044 // use the caret position as an empty range for now. It will be updated
6045 // after Pepper API equips features related to surrounding text retrieval.
[email protected]ea2fb972013-08-07 05:44:266046 gfx::Rect caret = focused_pepper_plugin_->GetCaretBounds();
[email protected]3f783362011-10-21 22:40:506047 *start = caret;
6048 *end = caret;
6049 return;
6050 }
[email protected]ea2fb972013-08-07 05:44:266051#endif
[email protected]3f783362011-10-21 22:40:506052 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:456053}
6054
[email protected]501ea13d2013-07-09 17:03:296055#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
[email protected]58b48a0d2012-06-13 07:01:356056void RenderViewImpl::GetCompositionCharacterBounds(
6057 std::vector<gfx::Rect>* bounds) {
6058 DCHECK(bounds);
6059 bounds->clear();
6060
[email protected]ea2fb972013-08-07 05:44:266061#if defined(ENABLE_PLUGINS)
6062 if (focused_pepper_plugin_) {
[email protected]88dbe32f2013-06-20 23:31:366063 return;
6064 }
[email protected]ea2fb972013-08-07 05:44:266065#endif
6066
[email protected]58b48a0d2012-06-13 07:01:356067 if (!webview())
6068 return;
6069 size_t start_offset = 0;
6070 size_t character_count = 0;
6071 if (!webview()->compositionRange(&start_offset, &character_count))
6072 return;
6073 if (character_count == 0)
6074 return;
6075
[email protected]180ef242013-11-07 06:50:466076 blink::WebFrame* frame = webview()->focusedFrame();
[email protected]58b48a0d2012-06-13 07:01:356077 if (!frame)
6078 return;
6079
6080 bounds->reserve(character_count);
[email protected]180ef242013-11-07 06:50:466081 blink::WebRect webrect;
[email protected]58b48a0d2012-06-13 07:01:356082 for (size_t i = 0; i < character_count; ++i) {
6083 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
6084 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
6085 bounds->clear();
6086 return;
6087 }
6088 bounds->push_back(webrect);
6089 }
6090}
6091
[email protected]db4fc1e2013-09-06 20:01:516092void RenderViewImpl::GetCompositionRange(gfx::Range* range) {
[email protected]ea2fb972013-08-07 05:44:266093#if defined(ENABLE_PLUGINS)
6094 if (focused_pepper_plugin_) {
[email protected]88dbe32f2013-06-20 23:31:366095 return;
6096 }
[email protected]ea2fb972013-08-07 05:44:266097#endif
[email protected]88dbe32f2013-06-20 23:31:366098 RenderWidget::GetCompositionRange(range);
6099}
[email protected]501ea13d2013-07-09 17:03:296100#endif
[email protected]88dbe32f2013-06-20 23:31:366101
[email protected]310ebd6302011-10-10 19:06:286102bool RenderViewImpl::CanComposeInline() {
[email protected]ea2fb972013-08-07 05:44:266103#if defined(ENABLE_PLUGINS)
6104 if (focused_pepper_plugin_)
6105 return IsPepperAcceptingCompositionEvents();
6106#endif
6107 return true;
[email protected]56ea1a62011-05-30 07:05:576108}
6109
[email protected]35134e12013-02-22 20:07:406110void RenderViewImpl::InstrumentWillBeginFrame() {
6111 if (!webview())
6112 return;
6113 if (!webview()->devToolsAgent())
6114 return;
6115 webview()->devToolsAgent()->didBeginFrame();
6116}
6117
6118void RenderViewImpl::InstrumentDidBeginFrame() {
6119 if (!webview())
6120 return;
6121 if (!webview()->devToolsAgent())
6122 return;
6123 // TODO(jamesr/caseq): Decide if this needs to be renamed.
6124 webview()->devToolsAgent()->didComposite();
6125}
6126
6127void RenderViewImpl::InstrumentDidCancelFrame() {
6128 if (!webview())
6129 return;
6130 if (!webview()->devToolsAgent())
6131 return;
6132 webview()->devToolsAgent()->didCancelFrame();
6133}
6134
6135void RenderViewImpl::InstrumentWillComposite() {
6136 if (!webview())
6137 return;
6138 if (!webview()->devToolsAgent())
6139 return;
6140 webview()->devToolsAgent()->willComposite();
6141}
6142
[email protected]34bb3ac2013-03-08 02:41:286143bool RenderViewImpl::AllowPartialSwap() const {
6144 return allow_partial_swap_;
6145}
6146
[email protected]b2e4c70132013-10-03 02:07:516147void RenderViewImpl::SetScreenMetricsEmulationParameters(
6148 float device_scale_factor, float root_layer_scale) {
6149 if (webview()) {
6150 webview()->setCompositorDeviceScaleFactorOverride(device_scale_factor);
6151 webview()->setRootLayerScaleTransform(root_layer_scale);
6152 }
6153}
6154
[email protected]310ebd6302011-10-10 19:06:286155bool RenderViewImpl::ScheduleFileChooser(
[email protected]e9ff79c2012-10-19 21:31:266156 const FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:476157 WebFileChooserCompletion* completion) {
6158 static const size_t kMaximumPendingFileChooseRequests = 4;
6159 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
6160 // This sanity check prevents too many file choose requests from getting
6161 // queued which could DoS the user. Getting these is most likely a
6162 // programming error (there are many ways to DoS the user so it's not
6163 // considered a "real" security check), either in JS requesting many file
6164 // choosers to pop up, or in a plugin.
6165 //
6166 // TODO(brettw) we might possibly want to require a user gesture to open
6167 // a file picker, which will address this issue in a better way.
6168 return false;
6169 }
6170
6171 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
6172 new PendingFileChooser(params, completion)));
6173 if (file_chooser_completions_.size() == 1) {
6174 // Actually show the browse dialog when this is the first request.
6175 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
6176 }
6177 return true;
6178}
6179
[email protected]180ef242013-11-07 06:50:466180blink::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:516181 if (!geolocation_dispatcher_)
6182 geolocation_dispatcher_ = new GeolocationDispatcher(this);
6183 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:256184}
[email protected]61c9f032010-03-31 23:04:196185
[email protected]180ef242013-11-07 06:50:466186blink::WebSpeechInputController* RenderViewImpl::speechInputController(
6187 blink::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:226188#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:026189 if (!input_tag_speech_dispatcher_)
6190 input_tag_speech_dispatcher_ =
6191 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:226192#endif
[email protected]c52b2892012-03-07 11:01:026193 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:116194}
6195
[email protected]180ef242013-11-07 06:50:466196blink::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
[email protected]64d09222012-05-25 10:10:346197 if (!speech_recognition_dispatcher_)
6198 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
[email protected]64d09222012-05-25 10:10:346199 return speech_recognition_dispatcher_;
6200}
6201
[email protected]310ebd6302011-10-10 19:06:286202void RenderViewImpl::zoomLimitsChanged(double minimum_level,
6203 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:256204 // For now, don't remember plugin zoom values. We don't want to mix them with
6205 // normal web content (i.e. a fixed layout plugin would usually want them
6206 // different).
6207 bool remember = !webview()->mainFrame()->document().isPluginDocument();
6208
[email protected]b75b8292010-10-01 07:28:256209 int minimum_percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:496210 ZoomLevelToZoomFactor(minimum_level) * 100);
[email protected]b75b8292010-10-01 07:28:256211 int maximum_percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:496212 ZoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:256213
6214 Send(new ViewHostMsg_UpdateZoomLimits(
6215 routing_id_, minimum_percent, maximum_percent, remember));
6216}
6217
[email protected]310ebd6302011-10-10 19:06:286218void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:256219 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:086220 float zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:266221
6222 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
6223
[email protected]b75b8292010-10-01 07:28:256224 // Tell the browser which url got zoomed so it can update the menu and the
6225 // saved values if necessary
6226 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:086227 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:416228 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:256229}
6230
[email protected]7940b8e2013-07-25 23:08:496231double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const {
6232 return ZoomLevelToZoomFactor(zoom_level);
6233}
6234
6235double RenderViewImpl::zoomFactorToZoomLevel(double factor) const {
6236 return ZoomFactorToZoomLevel(factor);
6237}
6238
[email protected]310ebd6302011-10-10 19:06:286239void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
6240 const WebString& base_url,
6241 const WebString& url,
6242 const WebString& title) {
[email protected]af15bf22013-03-08 01:18:176243 bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]a6d36cc2011-02-23 00:39:486244 GURL base(base_url);
6245 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
6246 if (base.GetOrigin() != absolute_url.GetOrigin()) {
6247 return;
6248 }
[email protected]f1a29a02011-10-06 23:08:446249 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
6250 UTF16ToUTF8(scheme),
6251 absolute_url,
[email protected]3a3b75a2012-06-01 08:38:366252 title,
6253 user_gesture));
[email protected]a6d36cc2011-02-23 00:39:486254}
6255
[email protected]180ef242013-11-07 06:50:466256blink::WebPageVisibilityState RenderViewImpl::visibilityState() const {
6257 blink::WebPageVisibilityState current_state = is_hidden() ?
6258 blink::WebPageVisibilityStateHidden :
6259 blink::WebPageVisibilityStateVisible;
6260 blink::WebPageVisibilityState override_state = current_state;
[email protected]e9ff79c2012-10-19 21:31:266261 if (GetContentClient()->renderer()->
[email protected]f59203a2011-06-07 10:01:446262 ShouldOverridePageVisibilityState(this,
6263 &override_state))
6264 return override_state;
6265 return current_state;
[email protected]94dec932011-05-26 20:04:216266}
6267
[email protected]180ef242013-11-07 06:50:466268blink::WebUserMediaClient* RenderViewImpl::userMediaClient() {
[email protected]60ee79f2013-09-11 13:49:556269 // This can happen in tests, in which case it's OK to return NULL.
6270 if (!InitializeMediaStreamClient())
6271 return NULL;
6272
[email protected]c3bdce152013-07-10 04:56:346273 return web_user_media_client_;
[email protected]273558fb2012-01-12 15:03:516274}
6275
[email protected]180ef242013-11-07 06:50:466276blink::WebMIDIClient* RenderViewImpl::webMIDIClient() {
[email protected]7b77f6cb2013-07-25 16:23:146277 if (!midi_dispatcher_)
6278 midi_dispatcher_ = new MIDIDispatcher(this);
6279 return midi_dispatcher_;
6280}
6281
[email protected]a0629af92012-08-08 00:39:376282void RenderViewImpl::draggableRegionsChanged() {
6283 FOR_EACH_OBSERVER(
6284 RenderViewObserver,
6285 observers_,
6286 DraggableRegionsChanged(webview()->mainFrame()));
6287}
6288
[email protected]40bed812013-11-05 06:59:156289WebMediaPlayer* RenderViewImpl::CreateWebMediaPlayerForMediaStream(
6290 WebFrame* frame,
[email protected]180ef242013-11-07 06:50:466291 const blink::WebURL& url,
[email protected]40bed812013-11-05 06:59:156292 WebMediaPlayerClient* client) {
6293#if defined(ENABLE_WEBRTC)
6294 if (!InitializeMediaStreamClient()) {
6295 LOG(ERROR) << "Failed to initialize MediaStreamClient";
6296 return NULL;
6297 }
6298#if !defined(GOOGLE_TV)
6299 if (media_stream_client_->IsMediaStream(url)) {
6300#if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
6301 bool found_neon =
6302 (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
6303 UMA_HISTOGRAM_BOOLEAN("Platform.WebRtcNEONFound", found_neon);
6304#endif // defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
6305 return new WebMediaPlayerMS(frame, client, AsWeakPtr(),
6306 media_stream_client_, new RenderMediaLog());
6307 }
6308#endif // !defined(GOOGLE_TV)
6309#endif // defined(ENABLE_WEBRTC)
6310 return NULL;
6311}
6312
[email protected]20657a82012-08-21 20:23:036313#if defined(OS_ANDROID)
6314WebContentDetectionResult RenderViewImpl::detectContentAround(
6315 const WebHitTestResult& touch_hit) {
6316 DCHECK(!touch_hit.isNull());
6317 DCHECK(!touch_hit.node().isNull());
6318 DCHECK(touch_hit.node().isTextNode());
6319
6320 // Process the position with all the registered content detectors until
6321 // a match is found. Priority is provided by their relative order.
6322 for (ContentDetectorList::const_iterator it = content_detectors_.begin();
6323 it != content_detectors_.end(); ++it) {
6324 ContentDetector::Result content = (*it)->FindTappedContent(touch_hit);
6325 if (content.valid) {
6326 return WebContentDetectionResult(content.content_boundaries,
6327 UTF8ToUTF16(content.text), content.intent_url);
6328 }
6329 }
6330 return WebContentDetectionResult();
6331}
6332
6333void RenderViewImpl::scheduleContentIntent(const WebURL& intent) {
6334 // Introduce a short delay so that the user can notice the content.
[email protected]dd32b1272013-05-04 14:17:116335 base::MessageLoop::current()->PostDelayedTask(
[email protected]20657a82012-08-21 20:23:036336 FROM_HERE,
[email protected]dd32b1272013-05-04 14:17:116337 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent,
6338 AsWeakPtr(),
6339 intent,
6340 expected_content_intent_id_),
[email protected]20657a82012-08-21 20:23:036341 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds));
6342}
6343
6344void RenderViewImpl::cancelScheduledContentIntents() {
6345 ++expected_content_intent_id_;
6346}
6347
6348void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent,
6349 size_t request_id) {
6350 if (request_id != expected_content_intent_id_)
6351 return;
6352
6353 // Remove the content highlighting if any.
6354 scheduleComposite();
6355
6356 if (!intent.is_empty())
6357 Send(new ViewHostMsg_StartContentIntent(routing_id_, intent));
6358}
[email protected]b18583c2012-12-18 06:55:276359
6360bool RenderViewImpl::openDateTimeChooser(
[email protected]180ef242013-11-07 06:50:466361 const blink::WebDateTimeChooserParams& params,
6362 blink::WebDateTimeChooserCompletion* completion) {
[email protected]b18583c2012-12-18 06:55:276363 date_time_picker_client_.reset(
6364 new RendererDateTimePicker(this, params, completion));
6365 return date_time_picker_client_->Open();
6366}
6367
[email protected]40bed812013-11-05 06:59:156368WebMediaPlayer* RenderViewImpl::CreateAndroidWebMediaPlayer(
6369 WebFrame* frame,
[email protected]180ef242013-11-07 06:50:466370 const blink::WebURL& url,
[email protected]40bed812013-11-05 06:59:156371 WebMediaPlayerClient* client) {
6372 GpuChannelHost* gpu_channel_host =
6373 RenderThreadImpl::current()->EstablishGpuChannelSync(
6374 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
6375 if (!gpu_channel_host) {
6376 LOG(ERROR) << "Failed to establish GPU channel for media player";
6377 return NULL;
6378 }
6379
6380 scoped_ptr<StreamTextureFactory> stream_texture_factory;
6381 if (UsingSynchronousRendererCompositor()) {
6382 SynchronousCompositorFactory* factory =
6383 SynchronousCompositorFactory::GetInstance();
6384 stream_texture_factory = factory->CreateStreamTextureFactory(routing_id_);
6385 } else {
6386 scoped_refptr<cc::ContextProvider> context_provider =
6387 RenderThreadImpl::current()->SharedMainThreadContextProvider();
6388
6389 if (!context_provider.get()) {
6390 LOG(ERROR) << "Failed to get context3d for media player";
6391 return NULL;
6392 }
6393
6394 stream_texture_factory.reset(new StreamTextureFactoryImpl(
6395 context_provider->Context3d(), gpu_channel_host, routing_id_));
6396 }
6397
6398 scoped_ptr<WebMediaPlayerAndroid> web_media_player_android(
6399 new WebMediaPlayerAndroid(
6400 frame,
6401 client,
6402 AsWeakPtr(),
6403 media_player_manager_,
6404 stream_texture_factory.release(),
6405 RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy(),
6406 new RenderMediaLog()));
6407#if defined(ENABLE_WEBRTC) && defined(GOOGLE_TV)
6408 if (media_stream_client_ && media_stream_client_->IsMediaStream(url)) {
6409 RTCVideoDecoderFactoryTv* factory = RenderThreadImpl::current()
6410 ->GetMediaStreamDependencyFactory()->decoder_factory_tv();
6411 // |media_stream_client| and |factory| outlives |web_media_player_android|.
6412 if (!factory->AcquireDemuxer() ||
6413 !web_media_player_android->InjectMediaStream(
6414 media_stream_client_,
6415 factory,
6416 base::Bind(
6417 base::IgnoreResult(&RTCVideoDecoderFactoryTv::ReleaseDemuxer),
6418 base::Unretained(factory)))) {
6419 LOG(ERROR) << "Failed to inject media stream.";
6420 return NULL;
6421 }
6422 }
6423#endif // defined(ENABLE_WEBRTC) && defined(GOOGLE_TV)
6424 return web_media_player_android.release();
6425}
6426
[email protected]6d17f6392012-12-05 05:24:546427#endif // defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:036428
[email protected]caf706f2010-10-26 17:54:086429#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:286430void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:156431 if (external_popup_menu_ == NULL) {
6432 // Crash reports from the field indicate that we can be notified with a
6433 // NULL external popup menu (we probably get notified twice).
6434 // If you hit this please file a bug against jcivelli and include the page
6435 // and steps to repro.
6436 NOTREACHED();
6437 return;
6438 }
[email protected]caf706f2010-10-26 17:54:086439 external_popup_menu_->DidSelectItem(selected_index);
6440 external_popup_menu_.reset();
6441}
6442#endif
[email protected]bb461532010-11-26 21:50:236443
[email protected]24d2b172012-05-26 00:54:126444#if defined(OS_ANDROID)
6445void RenderViewImpl::OnSelectPopupMenuItems(
6446 bool canceled,
6447 const std::vector<int>& selected_indices) {
6448 // It is possible to receive more than one of these calls if the user presses
6449 // a select faster than it takes for the show-select-popup IPC message to make
6450 // it to the browser UI thread. Ignore the extra-messages.
6451 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug.
[email protected]59383c782013-04-17 16:43:276452 if (!external_popup_menu_)
[email protected]24d2b172012-05-26 00:54:126453 return;
6454
6455 external_popup_menu_->DidSelectItems(canceled, selected_indices);
6456 external_popup_menu_.reset();
6457}
6458#endif
6459
[email protected]310ebd6302011-10-10 19:06:286460void RenderViewImpl::OnContextMenuClosed(
[email protected]e9ff79c2012-10-19 21:31:266461 const CustomContextMenuContext& custom_context) {
[email protected]860ee642012-10-13 03:46:256462 if (custom_context.request_id) {
6463 // External request, should be in our map.
[email protected]e9ff79c2012-10-19 21:31:266464 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:256465 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:466466 if (client) {
6467 client->OnMenuClosed(custom_context.request_id);
6468 pending_context_menus_.Remove(custom_context.request_id);
6469 }
[email protected]860ee642012-10-13 03:46:256470 } else {
6471 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:086472 context_menu_node_.reset();
[email protected]860ee642012-10-13 03:46:256473 }
[email protected]521b2482011-01-15 00:10:106474}
[email protected]5a7b15a2011-08-22 22:48:186475
[email protected]f56c7872013-06-18 12:31:576476void RenderViewImpl::OnShowContextMenu(const gfx::Point& location) {
[email protected]a14ddcd2013-06-21 22:53:036477 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH_EDIT_MENU;
[email protected]f56c7872013-06-18 12:31:576478 touch_editing_context_menu_location_ = location;
[email protected]47822262013-04-23 17:22:366479 if (webview())
6480 webview()->showContextMenu();
6481}
6482
[email protected]310ebd6302011-10-10 19:06:286483void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:186484 if (!webview())
6485 return;
6486 WebFrame* main_frame = webview()->mainFrame();
6487 if (!main_frame)
6488 return;
6489 main_frame->enableViewSourceMode(true);
6490}
[email protected]67bfb83f2011-09-22 03:36:376491
[email protected]7cc78902012-12-06 02:32:266492void RenderViewImpl::OnDisownOpener() {
6493 if (!webview())
6494 return;
6495
6496 WebFrame* main_frame = webview()->mainFrame();
6497 if (main_frame && main_frame->opener())
6498 main_frame->setOpener(NULL);
6499}
6500
[email protected]efd7e47f2012-10-19 20:37:516501#if defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:036502bool RenderViewImpl::didTapMultipleTargets(
[email protected]180ef242013-11-07 06:50:466503 const blink::WebGestureEvent& event,
[email protected]f9526d12012-10-18 01:55:036504 const WebVector<WebRect>& target_rects) {
[email protected]8d3dfee62013-06-19 05:50:336505 // Never show a disambiguation popup when accessibility is enabled,
6506 // as this interferes with "touch exploration".
6507 if (accessibility_mode_ == AccessibilityModeComplete)
6508 return false;
6509
[email protected]f9526d12012-10-18 01:55:036510 gfx::Rect finger_rect(
6511 event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2,
6512 event.data.tap.width, event.data.tap.height);
6513 gfx::Rect zoom_rect;
[email protected]70221f02013-01-31 22:17:076514 float new_total_scale =
6515 DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
6516 finger_rect, target_rects, GetSize(),
6517 gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(),
6518 device_scale_factor_ * webview()->pageScaleFactor(), &zoom_rect);
6519 if (!new_total_scale)
[email protected]f9526d12012-10-18 01:55:036520 return false;
6521
[email protected]4ded1dbf2013-08-28 21:11:036522 bool handled = false;
6523 switch (renderer_preferences_.tap_multiple_targets_strategy) {
6524 case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM:
6525 handled = webview()->zoomToMultipleTargetsRect(zoom_rect);
6526 break;
6527 case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: {
[email protected]bc2804d2013-08-06 07:45:496528 gfx::Size canvas_size =
6529 gfx::ToCeiledSize(gfx::ScaleSize(zoom_rect.size(), new_total_scale));
6530 TransportDIB* transport_dib = NULL;
6531 {
6532 scoped_ptr<skia::PlatformCanvas> canvas(
6533 RenderProcess::current()->GetDrawingCanvas(&transport_dib,
6534 gfx::Rect(canvas_size)));
[email protected]4ded1dbf2013-08-28 21:11:036535 if (!canvas) {
6536 handled = false;
6537 break;
6538 }
[email protected]f9526d12012-10-18 01:55:036539
[email protected]bc2804d2013-08-06 07:45:496540 // TODO(trchen): Cleanup the device scale factor mess.
6541 // device scale will be applied in WebKit
6542 // --> zoom_rect doesn't include device scale,
6543 // but WebKit will still draw on zoom_rect * device_scale_factor_
6544 canvas->scale(new_total_scale / device_scale_factor_,
6545 new_total_scale / device_scale_factor_);
6546 canvas->translate(-zoom_rect.x() * device_scale_factor_,
6547 -zoom_rect.y() * device_scale_factor_);
[email protected]f9526d12012-10-18 01:55:036548
[email protected]bc2804d2013-08-06 07:45:496549 webwidget_->paint(
6550 canvas.get(),
6551 zoom_rect,
6552 WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent);
6553 }
6554
6555 gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect(
6556 ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect)));
6557 Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_,
6558 physical_window_zoom_rect,
6559 canvas_size,
6560 transport_dib->id()));
[email protected]4ded1dbf2013-08-28 21:11:036561 handled = true;
6562 break;
6563 }
6564 case TAP_MULTIPLE_TARGETS_STRATEGY_NONE:
6565 // No-op.
6566 break;
[email protected]f9526d12012-10-18 01:55:036567 }
[email protected]70221f02013-01-31 22:17:076568
[email protected]4ded1dbf2013-08-28 21:11:036569 return handled;
[email protected]f9526d12012-10-18 01:55:036570}
[email protected]efd7e47f2012-10-19 20:37:516571#endif
[email protected]f9526d12012-10-18 01:55:036572
[email protected]b283d292013-02-21 08:40:346573unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
6574 return history_list_length_;
6575}
6576
[email protected]cc290f902013-03-04 20:06:026577void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
6578 if (enable) {
6579 if (has_focus())
6580 return;
6581 OnSetActive(true);
6582 OnSetFocus(true);
6583 } else {
6584 if (!has_focus())
6585 return;
6586 OnSetFocus(false);
6587 OnSetActive(false);
6588 }
6589}
6590
[email protected]3a1c8a8032013-03-18 22:35:326591void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) {
[email protected]b54fe452013-06-07 14:01:536592 ViewMsg_Resize_Params params;
6593 params.screen_info = screen_info_;
6594 params.screen_info.deviceScaleFactor = factor;
6595 params.new_size = size();
6596 params.physical_backing_size =
6597 gfx::ToCeiledSize(gfx::ScaleSize(size(), factor));
6598 params.overdraw_bottom_height = 0.f;
6599 params.resizer_rect = WebRect();
6600 params.is_fullscreen = is_fullscreen();
6601 OnResize(params);
[email protected]3a1c8a8032013-03-18 22:35:326602}
6603
[email protected]92650162013-10-30 03:31:026604void RenderViewImpl::ForceResizeForTesting(const gfx::Size& new_size) {
6605 gfx::Rect new_position(rootWindowRect().x,
6606 rootWindowRect().y,
6607 new_size.width(),
6608 new_size.height());
6609 ResizeSynchronously(new_position);
6610}
6611
[email protected]5b45ad42013-10-25 00:42:046612void RenderViewImpl::UseSynchronousResizeModeForTesting(bool enable) {
6613 resizing_mode_selector_->set_is_synchronous_mode(enable);
6614}
6615
[email protected]eac2b362013-05-22 07:01:456616void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size,
6617 const gfx::Size& max_size) {
6618 OnEnableAutoResize(min_size, max_size);
6619}
6620
6621void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) {
6622 OnDisableAutoResize(new_size);
6623}
6624
[email protected]c3bdce152013-07-10 04:56:346625void RenderViewImpl::SetMediaStreamClientForTesting(
[email protected]5e35a8d2013-07-10 19:37:216626 MediaStreamClient* media_stream_client) {
[email protected]c3bdce152013-07-10 04:56:346627 DCHECK(!media_stream_client_);
6628 DCHECK(!web_user_media_client_);
6629 media_stream_client_ = media_stream_client;
6630}
6631
[email protected]0509bc82013-09-20 20:42:596632bool RenderViewImpl::IsPluginFullscreenAllowed() {
6633 return renderer_preferences_.plugin_fullscreen_allowed;
6634}
6635
[email protected]f9526d12012-10-18 01:55:036636void RenderViewImpl::OnReleaseDisambiguationPopupDIB(
6637 TransportDIB::Handle dib_handle) {
6638 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle);
6639 RenderProcess::current()->ReleaseTransportDIB(dib);
6640}
[email protected]e9ff79c2012-10-19 21:31:266641
[email protected]6fceb912013-02-15 06:24:156642void RenderViewImpl::DidCommitCompositorFrame() {
6643 RenderWidget::DidCommitCompositorFrame();
6644 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame());
6645}
6646
[email protected]41225fe2013-03-29 05:32:026647void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) {
6648 if (!urls.empty())
6649 Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, page_id_, urls));
6650}
6651
6652void RenderViewImpl::DidStopLoadingIcons() {
6653 int icon_types = WebIconURL::TypeFavicon;
6654 if (TouchEnabled())
6655 icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch;
6656
6657 WebVector<WebIconURL> icon_urls =
6658 webview()->mainFrame()->iconURLs(icon_types);
6659
6660 std::vector<FaviconURL> urls;
6661 for (size_t i = 0; i < icon_urls.size(); i++) {
6662 WebURL url = icon_urls[i].iconURL();
6663 if (!url.isEmpty())
6664 urls.push_back(FaviconURL(url,
6665 ToFaviconType(icon_urls[i].iconType())));
6666 }
6667 SendUpdateFaviconURL(urls);
6668}
6669
[email protected]e9ff79c2012-10-19 21:31:266670} // namespace content