blob: b21d9e047b9a4e914326cd43acb012f2db1e9439 [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"
[email protected]ec173b522013-11-14 11:01:18150#include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h"
[email protected]d0fcff72013-07-23 02:45:43151#include "third_party/WebKit/public/platform/WebString.h"
152#include "third_party/WebKit/public/platform/WebURL.h"
153#include "third_party/WebKit/public/platform/WebURLError.h"
154#include "third_party/WebKit/public/platform/WebURLRequest.h"
155#include "third_party/WebKit/public/platform/WebURLResponse.h"
156#include "third_party/WebKit/public/platform/WebVector.h"
[email protected]10760e4a2013-09-04 23:32:20157#include "third_party/WebKit/public/web/WebAXObject.h"
[email protected]2255a9332013-06-17 05:12:31158#include "third_party/WebKit/public/web/WebColorName.h"
159#include "third_party/WebKit/public/web/WebDOMEvent.h"
160#include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
161#include "third_party/WebKit/public/web/WebDataSource.h"
162#include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h"
163#include "third_party/WebKit/public/web/WebDateTimeChooserParams.h"
164#include "third_party/WebKit/public/web/WebDevToolsAgent.h"
165#include "third_party/WebKit/public/web/WebDocument.h"
166#include "third_party/WebKit/public/web/WebElement.h"
167#include "third_party/WebKit/public/web/WebFileChooserParams.h"
[email protected]2255a9332013-06-17 05:12:31168#include "third_party/WebKit/public/web/WebFindOptions.h"
169#include "third_party/WebKit/public/web/WebFormControlElement.h"
170#include "third_party/WebKit/public/web/WebFormElement.h"
171#include "third_party/WebKit/public/web/WebFrame.h"
[email protected]6bd867b2013-07-24 22:10:20172#include "third_party/WebKit/public/web/WebGlyphCache.h"
[email protected]2255a9332013-06-17 05:12:31173#include "third_party/WebKit/public/web/WebHelperPlugin.h"
174#include "third_party/WebKit/public/web/WebHistoryItem.h"
175#include "third_party/WebKit/public/web/WebInputElement.h"
176#include "third_party/WebKit/public/web/WebInputEvent.h"
177#include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
178#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
179#include "third_party/WebKit/public/web/WebNodeList.h"
180#include "third_party/WebKit/public/web/WebPageSerializer.h"
181#include "third_party/WebKit/public/web/WebPlugin.h"
182#include "third_party/WebKit/public/web/WebPluginAction.h"
183#include "third_party/WebKit/public/web/WebPluginContainer.h"
184#include "third_party/WebKit/public/web/WebPluginDocument.h"
185#include "third_party/WebKit/public/web/WebPluginParams.h"
186#include "third_party/WebKit/public/web/WebRange.h"
[email protected]91f05762013-08-21 02:55:09187#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
[email protected]2255a9332013-06-17 05:12:31188#include "third_party/WebKit/public/web/WebScriptSource.h"
189#include "third_party/WebKit/public/web/WebSearchableFormData.h"
190#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
191#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
192#include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
193#include "third_party/WebKit/public/web/WebSettings.h"
[email protected]2255a9332013-06-17 05:12:31194#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();
[email protected]b527ebf2013-11-07 17:38:181643 const char* data = NULL;
1644 if (params.browser_initiated_post_data.size()) {
1645 data = reinterpret_cast<const char*>(
1646 &params.browser_initiated_post_data.front());
1647 }
1648 http_body.appendData(
1649 WebData(data, params.browser_initiated_post_data.size()));
[email protected]132e281a2012-07-31 18:32:441650 request.setHTTPBody(http_body);
1651 }
1652
[email protected]3027cf02013-01-24 08:16:581653 frame->loadRequest(request);
[email protected]198a95d62013-04-11 00:44:211654
1655 // If this is a cross-process navigation, the browser process will send
1656 // along the proper navigation start value.
1657 if (!params.browser_navigation_start.is_null() &&
1658 frame->provisionalDataSource()) {
1659 // browser_navigation_start is likely before this process existed, so we
1660 // can't use InterProcessTimeTicksConverter. Instead, the best we can do
1661 // is just ensure we don't report a bogus value in the future.
1662 base::TimeTicks navigation_start = std::min(
1663 base::TimeTicks::Now(), params.browser_navigation_start);
1664 double navigation_start_seconds =
1665 (navigation_start - base::TimeTicks()).InSecondsF();
1666 frame->provisionalDataSource()->setNavigationStartTime(
1667 navigation_start_seconds);
1668 }
[email protected]c0588052008-10-27 23:01:501669 }
1670
[email protected]77f17a82009-05-21 04:42:541671 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:071672 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:291673}
1674
[email protected]310ebd6302011-10-10 19:06:281675bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:031676 const ViewMsg_Navigate_Params& params,
1677 bool is_reload) {
1678 // Make sure this isn't a back/forward to an entry we have already cropped
1679 // or replaced from our history, before the browser knew about it. If so,
1680 // a new navigation has committed in the mean time, and we can ignore this.
[email protected]691aa2f2013-05-28 22:52:041681 bool is_back_forward = !is_reload && params.page_state.IsValid();
[email protected]d466b8a2011-07-15 21:48:031682
1683 // Note: if the history_list_length_ is 0 for a back/forward, we must be
1684 // restoring from a previous session. We'll update our state in OnNavigate.
1685 if (!is_back_forward || history_list_length_ <= 0)
1686 return false;
1687
1688 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
1689
1690 // Check for whether the forward history has been cropped due to a recent
1691 // navigation the browser didn't know about.
1692 if (params.pending_history_list_offset >= history_list_length_)
1693 return true;
1694
1695 // Check for whether this entry has been replaced with a new one.
1696 int expected_page_id =
1697 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:441698 if (expected_page_id > 0 && params.page_id != expected_page_id) {
1699 if (params.page_id < expected_page_id)
1700 return true;
1701
1702 // Otherwise we've removed an earlier entry and should have shifted all
1703 // entries left. For now, it's ok to lazily update the list.
1704 // TODO(creis): Notify all live renderers when we remove entries from
1705 // the front of the list, so that we don't hit this case.
1706 history_page_ids_[params.pending_history_list_offset] = params.page_id;
1707 }
[email protected]d466b8a2011-07-15 21:48:031708
1709 return false;
1710}
1711
initial.commit09911bf2008-07-26 23:55:291712// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:281713void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:441714 if (webview()) {
1715 WebFrame* main_frame = webview()->mainFrame();
1716 // Stop the alt error page fetcher. If we let it continue it may complete
1717 // and cause RenderViewHostManager to swap to this RenderView, even though
1718 // it may no longer be active.
1719 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
1720 StopAltErrorPageFetcher(main_frame->dataSource());
1721 main_frame->stopLoading();
1722 }
initial.commit09911bf2008-07-26 23:55:291723}
1724
[email protected]ecbf10d2010-02-18 13:03:291725// Reload current focused frame.
1726// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:281727void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291728 if (webview() && webview()->focusedFrame()) {
1729 // We always obey the cache (ignore_cache=false) here.
1730 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1731 // a cache-ignoring reload of the frame.
1732 webview()->focusedFrame()->reload(false);
1733 }
[email protected]1dda4022010-01-28 18:24:561734}
1735
[email protected]310ebd6302011-10-10 19:06:281736void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271737 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291738}
1739
[email protected]310ebd6302011-10-10 19:06:281740void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291741 // Check if there is a targeturl waiting to be sent.
1742 if (target_url_status_ == TARGET_PENDING) {
1743 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1744 pending_target_url_));
1745 }
1746
1747 target_url_status_ = TARGET_NONE;
1748}
1749
[email protected]310ebd6302011-10-10 19:06:281750void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291751 if (!webview())
1752 return;
1753
[email protected]5d4e36d2013-02-15 15:18:201754 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101755 WebNode current_node = context_menu_node_.isNull() ?
1756 GetFocusedNode() : context_menu_node_;
[email protected]f6b1856b2011-06-29 22:02:531757 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
[email protected]6dd17a8a2013-05-01 05:50:101758 current_node);
initial.commit09911bf2008-07-26 23:55:291759}
1760
[email protected]c084330e02013-04-27 01:08:151761void RenderViewImpl::OnCut() {
[email protected]a954bf72009-09-12 07:30:351762 if (!webview())
1763 return;
1764
[email protected]c084330e02013-04-27 01:08:151765 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101766 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"),
1767 GetFocusedNode());
[email protected]a954bf72009-09-12 07:30:351768}
[email protected]c084330e02013-04-27 01:08:151769
1770void RenderViewImpl::OnDelete() {
1771 if (!webview())
1772 return;
1773
[email protected]6dd17a8a2013-05-01 05:50:101774 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"),
1775 GetFocusedNode());
[email protected]c084330e02013-04-27 01:08:151776}
1777
1778void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
1779 const std::string& value) {
1780 if (!webview() || !webview()->focusedFrame())
1781 return;
1782
1783 webview()->focusedFrame()->executeCommand(
1784 WebString::fromUTF8(name), WebString::fromUTF8(value));
1785}
1786
1787void RenderViewImpl::OnMoveCaret(const gfx::Point& point) {
1788 if (!webview())
1789 return;
1790
1791 Send(new ViewHostMsg_MoveCaret_ACK(routing_id_));
1792
1793 webview()->focusedFrame()->moveCaretSelectionTowardsWindowPoint(point);
1794}
[email protected]a954bf72009-09-12 07:30:351795
[email protected]310ebd6302011-10-10 19:06:281796void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291797 if (!webview())
1798 return;
1799
[email protected]5d4e36d2013-02-15 15:18:201800 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101801 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"),
1802 GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:291803}
1804
[email protected]44bf7002011-10-16 02:46:151805void RenderViewImpl::OnPasteAndMatchStyle() {
1806 if (!webview())
1807 return;
1808
[email protected]5d4e36d2013-02-15 15:18:201809 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]44bf7002011-10-16 02:46:151810 webview()->focusedFrame()->executeCommand(
[email protected]6dd17a8a2013-05-01 05:50:101811 WebString::fromUTF8("PasteAndMatchStyle"), GetFocusedNode());
[email protected]44bf7002011-10-16 02:46:151812}
1813
[email protected]c084330e02013-04-27 01:08:151814void RenderViewImpl::OnRedo() {
1815 if (!webview())
1816 return;
1817
[email protected]6dd17a8a2013-05-01 05:50:101818 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"),
1819 GetFocusedNode());
[email protected]c084330e02013-04-27 01:08:151820}
1821
[email protected]310ebd6302011-10-10 19:06:281822void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291823 if (!webview())
1824 return;
1825
[email protected]1ff7a032010-02-03 02:46:031826 WebFrame* frame = webview()->focusedFrame();
1827 if (!frame->hasSelection())
1828 frame->selectWordAroundCaret();
[email protected]2365c642013-02-12 19:16:471829
[email protected]1ff7a032010-02-03 02:46:031830 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291831}
1832
[email protected]2365c642013-02-12 19:16:471833void RenderViewImpl::OnReplaceMisspelling(const string16& text) {
1834 if (!webview())
1835 return;
1836
1837 WebFrame* frame = webview()->focusedFrame();
1838 if (!frame->hasSelection())
1839 return;
1840
1841 frame->replaceMisspelledRange(text);
1842}
1843
[email protected]c084330e02013-04-27 01:08:151844void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1845 const gfx::Rect& rect) {
[email protected]180ef242013-11-07 06:50:461846 blink::WebNode node = GetFocusedNode();
[email protected]c084330e02013-04-27 01:08:151847 if (!node.isNull()) {
1848 if (IsEditableNode(node)) {
1849 webview()->saveScrollAndScaleState();
1850 webview()->scrollFocusedNodeIntoRect(rect);
1851 }
1852 }
[email protected]25bcc8f2013-01-09 02:49:251853}
1854
[email protected]310ebd6302011-10-10 19:06:281855void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291856 if (!webview())
1857 return;
1858
[email protected]5d4e36d2013-02-15 15:18:201859 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]26aa0482009-09-30 16:55:271860 webview()->focusedFrame()->executeCommand(
[email protected]6dd17a8a2013-05-01 05:50:101861 WebString::fromUTF8("SelectAll"), GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:291862}
1863
[email protected]c084330e02013-04-27 01:08:151864void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1865 const gfx::Point& end) {
1866 if (!webview())
1867 return;
1868
1869 Send(new ViewHostMsg_SelectRange_ACK(routing_id_));
1870
1871 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1872 webview()->focusedFrame()->selectRange(start, end);
1873}
1874
1875void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
1876 const EditCommands& edit_commands) {
1877 edit_commands_ = edit_commands;
1878}
1879
1880void RenderViewImpl::OnUndo() {
1881 if (!webview())
1882 return;
1883
[email protected]6dd17a8a2013-05-01 05:50:101884 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"),
1885 GetFocusedNode());
[email protected]c084330e02013-04-27 01:08:151886}
1887
[email protected]45a599062012-09-07 20:09:061888void RenderViewImpl::OnUnselect() {
1889 if (!webview())
1890 return;
1891
[email protected]5d4e36d2013-02-15 15:18:201892 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]6dd17a8a2013-05-01 05:50:101893 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
1894 GetFocusedNode());
[email protected]45a599062012-09-07 20:09:061895}
1896
[email protected]c084330e02013-04-27 01:08:151897#if defined(OS_MACOSX)
1898void RenderViewImpl::OnCopyToFindPboard() {
1899 if (!webview())
1900 return;
1901
1902 // Since the find pasteboard supports only plain text, this can be simpler
1903 // than the |OnCopy()| case.
1904 WebFrame* frame = webview()->focusedFrame();
1905 if (frame->hasSelection()) {
1906 string16 selection = frame->selectionAsText();
1907 RenderThread::Get()->Send(
1908 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
1909 }
1910}
1911#endif
1912
1913void RenderViewImpl::OnSetName(const std::string& name) {
1914 if (!webview())
1915 return;
1916
1917 webview()->mainFrame()->setName(WebString::fromUTF8(name));
1918}
1919
[email protected]45a599062012-09-07 20:09:061920void RenderViewImpl::OnSetEditableSelectionOffsets(int start, int end) {
[email protected]5d4e36d2013-02-15 15:18:201921 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
[email protected]0d1ebed12013-08-05 22:01:131922 if (!ShouldHandleImeEvent())
1923 return;
[email protected]66fca5bc2013-05-23 06:58:291924 ImeEventGuard guard(this);
[email protected]45a599062012-09-07 20:09:061925 webview()->setEditableSelectionOffsets(start, end);
1926}
1927
1928void RenderViewImpl::OnSetCompositionFromExistingText(
1929 int start, int end,
[email protected]180ef242013-11-07 06:50:461930 const std::vector<blink::WebCompositionUnderline>& underlines) {
[email protected]0d1ebed12013-08-05 22:01:131931 if (!ShouldHandleImeEvent())
[email protected]45a599062012-09-07 20:09:061932 return;
[email protected]66fca5bc2013-05-23 06:58:291933 ImeEventGuard guard(this);
[email protected]45a599062012-09-07 20:09:061934 webview()->setCompositionFromExistingText(start, end, underlines);
1935}
1936
1937void RenderViewImpl::OnExtendSelectionAndDelete(int before, int after) {
[email protected]0d1ebed12013-08-05 22:01:131938 if (!ShouldHandleImeEvent())
[email protected]45a599062012-09-07 20:09:061939 return;
[email protected]66fca5bc2013-05-23 06:58:291940 ImeEventGuard guard(this);
[email protected]45a599062012-09-07 20:09:061941 webview()->extendSelectionAndDelete(before, after);
1942}
1943
[email protected]310ebd6302011-10-10 19:06:281944void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1945 int32 minimum_page_id) {
[email protected]e1ed5a12012-08-08 19:57:441946 DCHECK_GE(history_length, 0);
[email protected]9e1ad4b2011-08-14 16:49:191947 DCHECK(history_list_offset_ == history_list_length_ - 1);
[email protected]e1ed5a12012-08-08 19:57:441948 DCHECK_GE(minimum_page_id, -1);
[email protected]9e1ad4b2011-08-14 16:49:191949
1950 // Generate the new list.
1951 std::vector<int32> new_history_page_ids(history_length, -1);
1952 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1953 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1954 continue;
1955 new_history_page_ids.push_back(history_page_ids_[i]);
1956 }
1957 new_history_page_ids.swap(history_page_ids_);
1958
1959 // Update indexes.
1960 history_list_length_ = history_page_ids_.size();
1961 history_list_offset_ = history_list_length_ - 1;
1962}
1963
1964
[email protected]310ebd6302011-10-10 19:06:281965void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291966 if (!webview())
1967 return;
[email protected]26aa0482009-09-30 16:55:271968 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291969}
1970
[email protected]54ca3ca892011-06-07 21:14:541971#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281972void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331973 if (!webview())
1974 return;
1975 if (in_live_resize)
1976 webview()->willStartLiveResize();
1977 else
1978 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541979}
1980#endif
1981
[email protected]9b7d11e2012-10-08 19:24:141982#if defined(OS_ANDROID)
1983void RenderViewImpl::OnUndoScrollFocusedEditableNodeIntoRect() {
1984 const WebNode node = GetFocusedNode();
1985 if (!node.isNull() && IsEditableNode(node))
1986 webview()->restoreScrollAndScaleState();
1987}
[email protected]68877c282013-09-20 05:52:421988
1989void RenderViewImpl::OnPauseVideo() {
1990 // Inform RendererMediaPlayerManager to release all video player resources.
1991 // If something is in progress the resource will not be freed, it will
1992 // only be freed once the tab is destroyed or if the user navigates away
1993 // via WebMediaPlayerAndroid::Destroy.
1994 media_player_manager_->ReleaseVideoResources();
1995}
[email protected]9b7d11e2012-10-08 19:24:141996#endif
1997
initial.commit09911bf2008-07-26 23:55:291998///////////////////////////////////////////////////////////////////////////////
1999
2000// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:282001void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:452002 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:292003 DCHECK(ds);
2004
[email protected]726985e22009-06-18 21:09:282005 const WebURLRequest& request = ds->request();
2006 const WebURLRequest& original_request = ds->originalRequest();
2007 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:292008
[email protected]007733c2011-11-17 00:34:072009 DocumentState* document_state = DocumentState::FromDataSource(ds);
2010 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e20b88d2013-04-09 15:28:372011 InternalDocumentStateData* internal_data =
2012 InternalDocumentStateData::FromDocumentState(document_state);
initial.commit09911bf2008-07-26 23:55:292013
2014 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:282015 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:292016 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:052017 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:292018 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:072019 params.frame_id = frame->identifier();
[email protected]2f673064c2013-10-22 04:01:442020 params.frame_unique_name = frame->uniqueName();
[email protected]6d81b482011-02-22 19:47:192021 params.socket_address.set_host(response.remoteIPAddress().utf8());
2022 params.socket_address.set_port(response.remotePort());
[email protected]e07ddafe2013-03-05 21:03:362023 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
2024 if (extra_data) {
2025 params.was_fetched_via_proxy = extra_data->was_fetched_via_proxy();
2026 }
[email protected]af15bed2010-08-25 21:12:092027 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e20b88d2013-04-09 15:28:372028 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:292029
2030 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:312031 params.url = GetLoadingUrl(frame);
[email protected]809be032013-03-19 01:56:562032 DCHECK(!is_swapped_out_ || params.url == GURL(kSwappedOutURL));
initial.commit09911bf2008-07-26 23:55:292033
[email protected]5f9b8712011-11-23 08:55:572034 if (frame->document().baseURL() != params.url)
2035 params.base_url = frame->document().baseURL();
2036
[email protected]726985e22009-06-18 21:09:282037 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:242038 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:042039 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:292040
[email protected]e20b88d2013-04-09 15:28:372041 params.searchable_form_url = internal_data->searchable_form_url();
2042 params.searchable_form_encoding = internal_data->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:292043
initial.commit09911bf2008-07-26 23:55:292044 params.gesture = navigation_gesture_;
2045 navigation_gesture_ = NavigationGestureUnknown;
2046
[email protected]0f38dc4552011-02-25 11:24:002047 // Make navigation state a part of the FrameNavigate message so that commited
2048 // entry had it at all times.
[email protected]691aa2f2013-05-28 22:52:042049 WebHistoryItem item = frame->currentHistoryItem();
2050 if (item.isNull()) {
2051 item.initialize();
2052 item.setURLString(request.url().spec().utf16());
[email protected]0f38dc4552011-02-25 11:24:002053 }
[email protected]691aa2f2013-05-28 22:52:042054 params.page_state = HistoryItemToPageState(item);
[email protected]0f38dc4552011-02-25 11:24:002055
[email protected]dd7daa82009-08-10 05:46:452056 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:292057 // Top-level navigation.
2058
[email protected]d00a7972012-08-07 06:09:582059 // Reset the zoom limits in case a plugin had changed them previously. This
2060 // will also call us back which will cause us to send a message to
2061 // update WebContentsImpl.
[email protected]7940b8e2013-07-25 23:08:492062 webview()->zoomLimitsChanged(ZoomFactorToZoomLevel(kMinimumZoomFactor),
2063 ZoomFactorToZoomLevel(kMaximumZoomFactor));
[email protected]d00a7972012-08-07 06:09:582064
[email protected]b75b8292010-10-01 07:28:252065 // Set zoom level, but don't do it for full-page plugin since they don't use
2066 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:012067 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:542068 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:252069 if (webview()->mainFrame()->document().isPluginDocument()) {
2070 // Reset the zoom levels for plugins.
[email protected]91219702013-09-18 07:33:512071 webview()->setZoomLevel(0);
[email protected]b75b8292010-10-01 07:28:252072 } else {
2073 if (host_zoom != host_zoom_levels_.end())
[email protected]91219702013-09-18 07:33:512074 webview()->setZoomLevel(host_zoom->second);
[email protected]b75b8292010-10-01 07:28:252075 }
2076
[email protected]f85f0702010-01-30 09:31:012077 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:512078 // This zoom level was merely recorded transiently for this load. We can
2079 // erase it now. If at some point we reload this page, the browser will
2080 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:012081 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:512082 }
2083
initial.commit09911bf2008-07-26 23:55:292084 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:552085 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:292086
[email protected]daa8c58e2009-06-15 17:21:102087 params.transition = navigation_state->transition_type();
[email protected]e9ff79c2012-10-19 21:31:262088 if (!PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:292089 // If the main frame does a load, it should not be reported as a subframe
2090 // navigation. This can occur in the following case:
2091 // 1. You're on a site with frames.
2092 // 2. You do a subframe navigation. This is stored with transition type
2093 // MANUAL_SUBFRAME.
2094 // 3. You navigate to some non-frame site, say, google.com.
2095 // 4. You navigate back to the page from step 2. Since it was initially
2096 // MANUAL_SUBFRAME, it will be that same transition type here.
2097 // We don't want that, because any navigation that changes the toplevel
2098 // frame should be tracked as a toplevel navigation (this allows us to
2099 // update the URL bar, etc).
[email protected]e9ff79c2012-10-19 21:31:262100 params.transition = PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:292101 }
2102
[email protected]a00a2e32013-07-31 05:08:332103 // If the page contained a client redirect (meta refresh, document.loc...),
2104 // set the referrer and transition appropriately.
2105 if (ds->isClientRedirect()) {
2106 params.referrer = Referrer(params.redirects[0],
2107 GetReferrerPolicyFromRequest(frame, ds->request()));
[email protected]e9ff79c2012-10-19 21:31:262108 params.transition = static_cast<PageTransition>(
2109 params.transition | PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:292110 } else {
2111 // Bug 654101: the referrer will be empty on https->http transitions. It
2112 // would be nice if we could get the real referrer from somewhere.
[email protected]44e55b012013-07-23 14:21:562113 params.referrer = GetReferrerFromRequest(frame, original_request);
initial.commit09911bf2008-07-26 23:55:292114 }
2115
[email protected]726985e22009-06-18 21:09:282116 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:052117 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:292118 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:052119 params.post_id = ExtractPostId(item);
2120 }
initial.commit09911bf2008-07-26 23:55:292121
[email protected]bf70edce2012-06-20 22:32:222122 // Send the user agent override back.
[email protected]e20b88d2013-04-09 15:28:372123 params.is_overriding_user_agent = internal_data->is_overriding_user_agent();
[email protected]bf70edce2012-06-20 22:32:222124
[email protected]f8872902013-10-30 03:18:572125 // Track the URL of the original request. We use the first entry of the
2126 // redirect chain if it exists because the chain may have started in another
2127 // process.
2128 if (params.redirects.size() > 0)
2129 params.original_request_url = params.redirects.at(0);
2130 else
2131 params.original_request_url = original_request.url();
[email protected]7c16976c2012-08-04 02:38:232132
[email protected]60d6cca2013-04-30 08:47:132133 params.history_list_was_cleared =
2134 navigation_state->history_list_was_cleared();
2135
[email protected]c2a797d2009-09-21 16:46:322136 // Save some histogram data so we can compute the average memory used per
2137 // page load of the glyphs.
2138 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
[email protected]180ef242013-11-07 06:50:462139 blink::WebGlyphCache::pageCount());
[email protected]c2a797d2009-09-21 16:46:322140
[email protected]15cf526b2010-02-12 06:33:492141 // This message needs to be sent before any of allowScripts(),
2142 // allowImages(), allowPlugins() is called for the new page, so that when
2143 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
2144 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:292145 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
2146 } else {
2147 // Subframe navigation: the type depends on whether this navigation
2148 // generated a new session history entry. When they do generate a session
2149 // history entry, it means the user initiated the navigation and we should
2150 // mark it as such. This test checks if this is the first time UpdateURL
2151 // has been called since WillNavigateToURL was called to initiate the load.
2152 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]e9ff79c2012-10-19 21:31:262153 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:292154 else
[email protected]e9ff79c2012-10-19 21:31:262155 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:292156
[email protected]60d6cca2013-04-30 08:47:132157 DCHECK(!navigation_state->history_list_was_cleared());
2158 params.history_list_was_cleared = false;
2159
initial.commit09911bf2008-07-26 23:55:292160 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
2161 }
2162
2163 last_page_id_sent_to_browser_ =
2164 std::max(last_page_id_sent_to_browser_, page_id_);
2165
2166 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:102167 // we don't want the transition type to persist. Just clear it.
[email protected]e9ff79c2012-10-19 21:31:262168 navigation_state->set_transition_type(PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:292169}
2170
2171// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:282172void RenderViewImpl::UpdateTitle(WebFrame* frame,
2173 const string16& title,
2174 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:462175 // Ignore all but top level navigations.
2176 if (frame->parent())
2177 return;
2178
[email protected]91a2aea2013-07-08 23:14:392179 base::debug::TraceLog::GetInstance()->UpdateProcessLabel(
2180 routing_id_, UTF16ToUTF8(title));
2181
[email protected]e9ff79c2012-10-19 21:31:262182 string16 shortened_title = title.substr(0, kMaxTitleChars);
[email protected]a49e10b2011-08-01 23:57:462183 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
2184 title_direction));
initial.commit09911bf2008-07-26 23:55:292185}
2186
[email protected]310ebd6302011-10-10 19:06:282187void RenderViewImpl::UpdateEncoding(WebFrame* frame,
2188 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:292189 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:272190 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:292191 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:302192 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:292193 last_encoding_name_ = encoding_name;
2194
[email protected]e38f40152008-09-12 23:08:302195 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:292196 }
2197}
2198
[email protected]e15f680732010-11-23 22:30:202199// Sends the last committed session history state to the browser so it will be
2200// saved before we navigate to a new page. This must be called *before* the
2201// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:282202void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:292203 // If we have a valid page ID at this point, then it corresponds to the page
2204 // we are navigating away from. Otherwise, this is the first navigation, so
2205 // there is no past session history to record.
2206 if (page_id_ == -1)
2207 return;
2208
[email protected]ca948a22009-06-25 19:36:172209 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:272210 webview()->mainFrame()->previousHistoryItem();
[email protected]6459800a2012-03-27 23:57:052211 SendUpdateState(item);
2212}
2213
2214void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
[email protected]ca948a22009-06-25 19:36:172215 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292216 return;
[email protected]ca948a22009-06-25 19:36:172217
[email protected]e9ff79c2012-10-19 21:31:262218 // Don't send state updates for kSwappedOutURL.
2219 if (item.urlString() == WebString::fromUTF8(kSwappedOutURL))
[email protected]6459800a2012-03-27 23:57:052220 return;
2221
[email protected]ca948a22009-06-25 19:36:172222 Send(new ViewHostMsg_UpdateState(
[email protected]691aa2f2013-05-28 22:52:042223 routing_id_, page_id_, HistoryItemToPageState(item)));
initial.commit09911bf2008-07-26 23:55:292224}
2225
[email protected]310ebd6302011-10-10 19:06:282226void RenderViewImpl::OpenURL(WebFrame* frame,
2227 const GURL& url,
[email protected]445e1042011-12-03 21:03:152228 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:282229 WebNavigationPolicy policy) {
[email protected]e2caa032012-11-15 23:29:182230 ViewHostMsg_OpenURL_Params params;
2231 params.url = url;
2232 params.referrer = referrer;
2233 params.disposition = NavigationPolicyToDisposition(policy);
2234 params.frame_id = frame->identifier();
[email protected]b4c09692012-12-13 19:15:462235 WebDataSource* ds = frame->provisionalDataSource();
2236 if (ds) {
[email protected]4972fc82013-11-19 04:33:422237 DocumentState* document_state = DocumentState::FromDataSource(ds);
2238 NavigationState* navigation_state = document_state->navigation_state();
2239 if (navigation_state->is_content_initiated()) {
2240 params.should_replace_current_entry = ds->replacesCurrentHistoryItem();
2241 } else {
2242 // This is necessary to preserve the should_replace_current_entry value on
2243 // cross-process redirects, in the event it was set by a previous process.
2244 //
2245 // TODO(davidben): Avoid this awkward duplication of state. See comment on
2246 // NavigationState::should_replace_current_entry().
2247 params.should_replace_current_entry =
2248 navigation_state->should_replace_current_entry();
2249 }
[email protected]b4c09692012-12-13 19:15:462250 } else {
[email protected]866fa2cc2013-07-22 22:19:522251 params.should_replace_current_entry = false;
[email protected]b4c09692012-12-13 19:15:462252 }
[email protected]e7f2e7c2013-07-15 09:41:302253 params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]00323f02013-07-24 15:47:412254 if (GetContentClient()->renderer()->AllowPopup())
2255 params.user_gesture = true;
[email protected]e7f2e7c2013-07-15 09:41:302256
[email protected]180ef242013-11-07 06:50:462257 if (policy == blink::WebNavigationPolicyNewBackgroundTab ||
2258 policy == blink::WebNavigationPolicyNewForegroundTab ||
2259 policy == blink::WebNavigationPolicyNewWindow ||
2260 policy == blink::WebNavigationPolicyNewPopup) {
[email protected]e7f2e7c2013-07-15 09:41:302261 WebUserGestureIndicator::consumeUserGesture();
2262 }
[email protected]e2caa032012-11-15 23:29:182263
2264 Send(new ViewHostMsg_OpenURL(routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172265}
2266
[email protected]79dbc662009-09-04 05:42:512267// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:292268
[email protected]310ebd6302011-10-10 19:06:282269void RenderViewImpl::LoadNavigationErrorPage(
2270 WebFrame* frame,
2271 const WebURLRequest& failed_request,
2272 const WebURLError& error,
2273 const std::string& html,
2274 bool replace) {
[email protected]d7b175e2011-10-11 15:31:582275 std::string alt_html;
2276 const std::string* error_html;
2277
2278 if (!html.empty()) {
2279 error_html = &html;
2280 } else {
[email protected]e9ff79c2012-10-19 21:31:262281 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]b38806a2013-10-04 16:01:382282 frame, failed_request, error, renderer_preferences_.accept_languages,
2283 &alt_html, NULL);
[email protected]d7b175e2011-10-11 15:31:582284 error_html = &alt_html;
2285 }
2286
2287 frame->loadHTMLString(*error_html,
[email protected]e9ff79c2012-10-19 21:31:262288 GURL(kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:252289 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:552290 replace);
initial.commit09911bf2008-07-26 23:55:292291}
2292
[email protected]e9ff79c2012-10-19 21:31:262293bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:282294 const string16& message,
2295 const string16& default_value,
2296 const GURL& frame_url,
2297 string16* result) {
[email protected]88f10a22013-11-06 21:22:122298 // Don't allow further dialogs if we are waiting to swap out, since the
2299 // PageGroupLoadDeferrer in our stack prevents it.
2300 if (suppress_dialogs_until_swap_out_)
2301 return false;
2302
initial.commit09911bf2008-07-26 23:55:292303 bool success = false;
[email protected]4f5ce842011-05-27 19:34:412304 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:292305 if (!result)
2306 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:292307
[email protected]12636df2009-09-28 22:32:212308 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
[email protected]688e2ee2013-09-12 20:48:142309 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:292310 return success;
2311}
2312
[email protected]310ebd6302011-10-10 19:06:282313bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:572314 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
2315 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
2316 // it is particularly important that we do not call willEnterModalLoop as
2317 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:442318 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2319 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:572320
2321 message->EnableMessagePumping(); // Runs a nested message loop.
2322 return Send(message);
2323}
2324
[email protected]c9bc8f12012-12-15 22:20:092325void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) {
2326 int id = next_snapshot_id_++;
2327 pending_snapshots_.insert(std::make_pair(id, callback));
[email protected]7d08a9352013-10-15 08:24:562328 ui::LatencyInfo latency_info;
2329 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
2330 GetLatencyComponentId(),
2331 id);
2332 if (RenderWidgetCompositor* rwc = compositor()) {
2333 rwc->SetLatencyInfo(latency_info);
2334 } else {
2335 latency_info_.MergeWith(latency_info);
2336 }
2337 ScheduleCompositeWithForcedRedraw();
[email protected]c9bc8f12012-12-15 22:20:092338}
2339
2340void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id,
2341 const gfx::Size& size, const std::vector<unsigned char>& png) {
[email protected]7d08a9352013-10-15 08:24:562342
2343 // Any pending snapshots with a lower ID than the one received are considered
2344 // to be implicitly complete, and returned the same snapshot data.
2345 PendingSnapshotMap::iterator it = pending_snapshots_.begin();
2346 while(it != pending_snapshots_.end()) {
2347 if (it->first <= snapshot_id) {
2348 it->second.Run(size, png);
2349 pending_snapshots_.erase(it++);
2350 } else {
2351 ++it;
2352 }
2353 }
[email protected]c9bc8f12012-12-15 22:20:092354}
2355
[email protected]180ef242013-11-07 06:50:462356// blink::WebViewClient ------------------------------------------------------
[email protected]48c9cf2d2009-09-16 16:47:522357
[email protected]916dfb62012-03-05 03:39:372358WebView* RenderViewImpl::createView(
2359 WebFrame* creator,
2360 const WebURLRequest& request,
2361 const WebWindowFeatures& features,
2362 const WebString& frame_name,
[email protected]147b2bf2013-11-05 04:00:042363 WebNavigationPolicy policy,
2364 bool suppress_opener) {
[email protected]8ab04652010-06-12 02:47:262365 ViewHostMsg_CreateWindow_Params params;
2366 params.opener_id = routing_id_;
[email protected]af15bf22013-03-08 01:18:172367 params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]00323f02013-07-24 15:47:412368 if (GetContentClient()->renderer()->AllowPopup())
2369 params.user_gesture = true;
[email protected]8ab04652010-06-12 02:47:262370 params.window_container_type = WindowFeaturesToContainerType(features);
2371 params.session_storage_namespace_id = session_storage_namespace_id_;
[email protected]5cef23d2013-02-27 13:11:212372 if (frame_name != "_blank")
2373 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:112374 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:412375 params.opener_url = creator->document().url();
[email protected]931bc922013-09-11 21:42:572376 params.opener_top_level_frame_url = creator->top()->document().url();
[email protected]7f48b712013-01-25 01:48:302377 GURL security_url(creator->document().securityOrigin().toString().utf8());
2378 if (!security_url.is_valid())
2379 security_url = GURL();
2380 params.opener_security_origin = security_url;
[email protected]147b2bf2013-11-05 04:00:042381 params.opener_suppressed = suppress_opener;
[email protected]f92ce2b2012-03-06 18:02:592382 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]44e55b012013-07-23 14:21:562383 if (!request.isNull()) {
[email protected]41e65502011-01-21 09:29:112384 params.target_url = request.url();
[email protected]44e55b012013-07-23 14:21:562385 params.referrer = GetReferrerFromRequest(creator, request);
2386 }
[email protected]453c1b22013-07-23 09:31:482387 params.features = features;
[email protected]8ab04652010-06-12 02:47:262388
[email protected]22217ed32013-11-18 18:40:232389 for (size_t i = 0; i < features.additionalFeatures.size(); ++i)
2390 params.additional_features.push_back(features.additionalFeatures[i]);
2391
[email protected]48c9cf2d2009-09-16 16:47:522392 int32 routing_id = MSG_ROUTING_NONE;
[email protected]227692c52013-05-31 22:43:042393 int32 main_frame_routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:562394 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:342395 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:522396
[email protected]380244092011-10-07 17:26:272397 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:262398 new ViewHostMsg_CreateWindow(params,
2399 &routing_id,
[email protected]227692c52013-05-31 22:43:042400 &main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:562401 &surface_id,
[email protected]8ab04652010-06-12 02:47:262402 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:212403 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:522404 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522405
[email protected]af15bf22013-03-08 01:18:172406 WebUserGestureIndicator::consumeUserGesture();
[email protected]c59262422012-11-30 21:20:522407
[email protected]3184f90b2013-05-01 18:17:532408 WebPreferences transferred_preferences = webkit_preferences_;
[email protected]9115d5f2013-03-24 04:37:412409
2410 // Unless accelerated compositing has been explicitly disabled from the
2411 // command line (e.g. via the blacklist or about:flags) re-enable it for
2412 // new views that get spawned by this view. This gets around the issue that
2413 // background extension pages disable accelerated compositing via web prefs
2414 // but can themselves spawn a visible render view which should be allowed
2415 // use gpu acceleration.
2416 if (!webkit_preferences_.accelerated_compositing_enabled) {
2417 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2418 if (!command_line.HasSwitch(switches::kDisableAcceleratedCompositing))
2419 transferred_preferences.accelerated_compositing_enabled = true;
2420 }
2421
[email protected]d6fa88f2013-10-18 16:00:432422 // The initial hidden state for the RenderViewImpl here has to match what the
2423 // browser will eventually decide for the given disposition. Since we have to
2424 // return from this call synchronously, we just have to make our best guess
2425 // and rely on the browser sending a WasHidden / WasShown message if it
2426 // disagrees.
[email protected]310ebd6302011-10-10 19:06:282427 RenderViewImpl* view = RenderViewImpl::Create(
[email protected]310ebd6302011-10-10 19:06:282428 routing_id_,
2429 renderer_preferences_,
[email protected]9115d5f2013-03-24 04:37:412430 transferred_preferences,
[email protected]310ebd6302011-10-10 19:06:282431 routing_id,
[email protected]227692c52013-05-31 22:43:042432 main_frame_routing_id,
[email protected]9f4f3322012-01-18 22:29:562433 surface_id,
[email protected]310ebd6302011-10-10 19:06:282434 cloned_session_storage_namespace_id,
[email protected]5cef23d2013-02-27 13:11:212435 string16(), // WebCore will take care of setting the correct name.
[email protected]1ac10dca2013-08-20 20:47:042436 true, // is_renderer_created
2437 false, // swapped_out
[email protected]d6fa88f2013-10-18 16:00:432438 params.disposition == NEW_BACKGROUND_TAB, // hidden
[email protected]1ac10dca2013-08-20 20:47:042439 1, // next_page_id
[email protected]842f10652012-06-06 01:54:042440 screen_info_,
[email protected]34bb3ac2013-03-08 02:41:282441 accessibility_mode_,
2442 allow_partial_swap_);
[email protected]8ab04652010-06-12 02:47:262443 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:522444
[email protected]007a848b2009-10-26 15:55:462445 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:592446 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:462447
[email protected]48c9cf2d2009-09-16 16:47:522448 // Copy over the alternate error page URL so we can have alt error pages in
2449 // the new render view (we don't need the browser to send the URL back down).
2450 view->alternate_error_page_url_ = alternate_error_page_url_;
2451
2452 return view->webview();
2453}
2454
[email protected]180ef242013-11-07 06:50:462455WebWidget* RenderViewImpl::createPopupMenu(blink::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:412456 RenderWidget* widget =
[email protected]842f10652012-06-06 01:54:042457 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]b2e4c70132013-10-03 02:07:512458 if (screen_metrics_emulator_) {
2459 widget->SetPopupOriginAdjustmentsForEmulation(
2460 screen_metrics_emulator_.get());
2461 }
[email protected]48c9cf2d2009-09-16 16:47:522462 return widget->webwidget();
2463}
2464
[email protected]310ebd6302011-10-10 19:06:282465WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:082466 const WebPopupMenuInfo& popup_menu_info,
2467 WebExternalPopupMenuClient* popup_menu_client) {
[email protected]8de2f882012-05-30 00:32:272468 // An IPC message is sent to the browser to build and display the actual
2469 // popup. The user could have time to click a different select by the time
2470 // the popup is shown. In that case external_popup_menu_ is non NULL.
2471 // By returning NULL in that case, we instruct WebKit to cancel that new
2472 // popup. So from the user perspective, only the first one will show, and
2473 // will have to close the first one before another one can be shown.
[email protected]59383c782013-04-17 16:43:272474 if (external_popup_menu_)
[email protected]8de2f882012-05-30 00:32:272475 return NULL;
[email protected]caf706f2010-10-26 17:54:082476 external_popup_menu_.reset(
2477 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
[email protected]b2e4c70132013-10-03 02:07:512478 if (screen_metrics_emulator_) {
2479 SetExternalPopupOriginAdjustmentsForEmulation(
2480 external_popup_menu_.get(), screen_metrics_emulator_.get());
2481 }
[email protected]caf706f2010-10-26 17:54:082482 return external_popup_menu_.get();
2483}
2484
[email protected]23367482013-06-27 21:06:542485WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() {
[email protected]5f2aa722013-08-07 16:59:412486 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:102487 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:342488}
2489
[email protected]fd8eb742013-08-22 00:42:002490bool RenderViewImpl::shouldReportDetailedMessageForSource(
2491 const WebString& source) {
2492 return GetContentClient()->renderer()->ShouldReportDetailedMessageForSource(
2493 source);
2494}
2495
[email protected]310ebd6302011-10-10 19:06:282496void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:522497 const WebConsoleMessage& message, const WebString& source_name,
[email protected]fd8eb742013-08-22 00:42:002498 unsigned source_line, const WebString& stack_trace) {
[email protected]d09df4b2011-04-11 19:01:082499 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:512500 switch (message.level) {
[email protected]80ac8942013-01-30 22:53:222501 case WebConsoleMessage::LevelDebug:
[email protected]d09df4b2011-04-11 19:01:082502 log_severity = logging::LOG_VERBOSE;
2503 break;
2504 case WebConsoleMessage::LevelLog:
[email protected]69c84d152013-10-25 18:53:092505 case WebConsoleMessage::LevelInfo:
[email protected]d09df4b2011-04-11 19:01:082506 log_severity = logging::LOG_INFO;
2507 break;
2508 case WebConsoleMessage::LevelWarning:
2509 log_severity = logging::LOG_WARNING;
2510 break;
2511 case WebConsoleMessage::LevelError:
2512 log_severity = logging::LOG_ERROR;
2513 break;
2514 default:
2515 NOTREACHED();
2516 }
2517
[email protected]88b50b62013-09-01 23:05:062518 if (shouldReportDetailedMessageForSource(source_name)) {
2519 FOR_EACH_OBSERVER(
2520 RenderViewObserver,
2521 observers_,
2522 DetailedConsoleMessageAdded(message.text,
2523 source_name,
2524 stack_trace,
2525 source_line,
2526 static_cast<int32>(log_severity)));
2527 }
2528
[email protected]07fb8d52013-08-07 17:03:512529 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
2530 static_cast<int32>(log_severity),
2531 message.text,
2532 static_cast<int32>(source_line),
[email protected]88b50b62013-09-01 23:05:062533 source_name));
[email protected]48c9cf2d2009-09-16 16:47:522534}
2535
[email protected]310ebd6302011-10-10 19:06:282536void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]b0553c7e2012-09-19 21:36:112537 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2538 PrintPage(frame, handling_input_event_));
[email protected]48c9cf2d2009-09-16 16:47:522539}
2540
[email protected]180ef242013-11-07 06:50:462541blink::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:512542 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:022543}
2544
[email protected]310ebd6302011-10-10 19:06:282545bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:122546 const WebString& path,
2547 WebFileChooserCompletion* chooser_completion) {
2548 int id = enumeration_completion_id_++;
2549 enumeration_completions_[id] = chooser_completion;
2550 return Send(new ViewHostMsg_EnumerateDirectory(
2551 routing_id_,
2552 id,
[email protected]728c2ee2013-06-25 04:01:072553 base::FilePath::FromUTF16Unsafe(path)));
[email protected]8a58c1c2011-04-19 18:40:122554}
2555
[email protected]4b1146bc2012-07-10 18:46:032556void RenderViewImpl::initializeHelperPluginWebFrame(
[email protected]180ef242013-11-07 06:50:462557 blink::WebHelperPlugin* plugin) {
[email protected]2f61bdd2013-07-02 18:38:472558 plugin->initializeFrame(main_render_frame_.get());
[email protected]4b1146bc2012-07-10 18:46:032559}
2560
[email protected]310ebd6302011-10-10 19:06:282561void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:522562 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:142563 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:522564 return;
2565 }
2566
2567 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:522568
2569 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:312570
2571 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:522572}
2573
[email protected]310ebd6302011-10-10 19:06:282574void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:522575 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:142576 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:522577 return;
2578 }
2579
2580 is_loading_ = false;
2581
2582 // NOTE: For now we're doing the safest thing, and sending out notification
2583 // when done loading. This currently isn't an issue as the favicon is only
2584 // displayed when done loading. Ideally we would send notification when
2585 // finished parsing the head, but webkit doesn't support that yet.
2586 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:522587 Send(new ViewHostMsg_DidStopLoading(routing_id_));
2588
[email protected]90109412010-12-15 17:14:242589 if (load_progress_tracker_ != NULL)
2590 load_progress_tracker_->DidStopLoading();
2591
[email protected]41225fe2013-03-29 05:32:022592 DidStopLoadingIcons();
2593
[email protected]93b9d692011-04-13 00:44:312594 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:522595}
2596
[email protected]310ebd6302011-10-10 19:06:282597void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
2598 double load_progress) {
[email protected]90109412010-12-15 17:14:242599 if (load_progress_tracker_ != NULL)
2600 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
2601}
2602
[email protected]550b0c92013-02-04 05:09:152603void RenderViewImpl::didCancelCompositionOnSelectionChange() {
2604 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
2605}
2606
[email protected]310ebd6302011-10-10 19:06:282607void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:082608 if (!handling_input_event_ && !handling_select_range_)
[email protected]5d4e36d2013-02-15 15:18:202609 return;
[email protected]d4cff272011-05-02 15:46:012610
[email protected]fca52022012-04-03 17:00:502611 if (is_empty_selection)
2612 selection_text_.clear();
2613
[email protected]087edc72013-11-07 01:00:352614 // UpdateTextInputType should be called before SyncSelectionIfRequired.
2615 // UpdateTextInputType may send TextInputTypeChanged to notify the focus
2616 // was changed, and SyncSelectionIfRequired may send SelectionChanged
2617 // to notify the selection was changed. Focus change should be notified
2618 // before selection change.
[email protected]cb9e2632013-06-18 11:26:472619 UpdateTextInputType();
[email protected]087edc72013-11-07 01:00:352620 SyncSelectionIfRequired();
[email protected]cb9e2632013-06-18 11:26:472621#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:132622 UpdateTextInputState(false, true);
[email protected]cb9e2632013-06-18 11:26:472623#endif
[email protected]04fc9482009-09-18 22:13:032624}
2625
[email protected]310ebd6302011-10-10 19:06:282626void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:122627 const std::string& name = UTF16ToUTF8(command_name);
2628 if (StartsWithASCII(name, "Move", true) ||
2629 StartsWithASCII(name, "Insert", true) ||
2630 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:032631 return;
[email protected]f1a29a02011-10-06 23:08:442632 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:032633}
2634
[email protected]310ebd6302011-10-10 19:06:282635bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:102636 if (edit_commands_.empty())
2637 return false;
2638
[email protected]26aa0482009-09-30 16:55:272639 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102640 if (!frame)
2641 return false;
2642
2643 EditCommands::iterator it = edit_commands_.begin();
2644 EditCommands::iterator end = edit_commands_.end();
2645
[email protected]507b33ea2009-09-29 03:56:512646 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102647 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332648 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2649 // key (but it's the exception). Once one edit command is not executed, it
2650 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102651 if (!frame->executeCommand(WebString::fromUTF8(it->name),
[email protected]b77fac52013-06-01 01:03:462652 WebString::fromUTF8(it->value),
2653 GetFocusedNode()))
[email protected]b2528b72009-09-24 06:57:102654 break;
[email protected]507b33ea2009-09-29 03:56:512655 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102656 }
2657
[email protected]507b33ea2009-09-29 03:56:512658 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102659}
2660
[email protected]180ef242013-11-07 06:50:462661blink::WebColorChooser* RenderViewImpl::createColorChooser(
2662 blink::WebColorChooserClient* client,
2663 const blink::WebColor& initial_color) {
[email protected]da8543762012-03-20 08:52:202664 RendererWebColorChooserImpl* color_chooser =
2665 new RendererWebColorChooserImpl(this, client);
2666 color_chooser->Open(static_cast<SkColor>(initial_color));
2667 return color_chooser;
2668}
2669
[email protected]310ebd6302011-10-10 19:06:282670bool RenderViewImpl::runFileChooser(
[email protected]180ef242013-11-07 06:50:462671 const blink::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472672 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352673 // Do not open the file dialog in a hidden RenderView.
2674 if (is_hidden())
2675 return false;
[email protected]e9ff79c2012-10-19 21:31:262676 FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262677 if (params.directory)
[email protected]6bedbef2013-07-31 06:33:492678 ipc_params.mode = FileChooserParams::UploadFolder;
[email protected]b5977a0c2010-08-24 19:46:262679 else if (params.multiSelect)
[email protected]e9ff79c2012-10-19 21:31:262680 ipc_params.mode = FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:502681 else if (params.saveAs)
[email protected]e9ff79c2012-10-19 21:31:262682 ipc_params.mode = FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:262683 else
[email protected]e9ff79c2012-10-19 21:31:262684 ipc_params.mode = FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:472685 ipc_params.title = params.title;
2686 ipc_params.default_file_name =
[email protected]728c2ee2013-06-25 04:01:072687 base::FilePath::FromUTF16Unsafe(params.initialValue);
[email protected]f9a4c41a2012-05-30 00:05:322688 ipc_params.accept_types.reserve(params.acceptTypes.size());
2689 for (size_t i = 0; i < params.acceptTypes.size(); ++i)
2690 ipc_params.accept_types.push_back(params.acceptTypes[i]);
[email protected]2fdf2352012-11-01 19:23:022691#if defined(OS_ANDROID)
[email protected]b7b4beb2013-07-09 14:06:502692 ipc_params.capture = params.useMediaCapture;
[email protected]2fdf2352012-11-01 19:23:022693#endif
[email protected]cdaf8d02010-03-30 19:52:472694
2695 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462696}
2697
[email protected]269f86d2011-12-07 02:43:472698void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
2699 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262700 RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:412701 message,
2702 string16(),
[email protected]b6cb3a842011-06-24 18:28:412703 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522704 NULL);
2705}
2706
[email protected]269f86d2011-12-07 02:43:472707bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
2708 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262709 return RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:412710 message,
2711 string16(),
[email protected]b6cb3a842011-06-24 18:28:412712 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522713 NULL);
2714}
2715
[email protected]269f86d2011-12-07 02:43:472716bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
2717 const WebString& message,
2718 const WebString& default_value,
2719 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:412720 string16 result;
[email protected]e9ff79c2012-10-19 21:31:262721 bool ok = RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:412722 message,
2723 default_value,
[email protected]b6cb3a842011-06-24 18:28:412724 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522725 &result);
2726 if (ok)
[email protected]4f5ce842011-05-27 19:34:412727 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:522728 return ok;
2729}
2730
[email protected]310ebd6302011-10-10 19:06:282731bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:522732 WebFrame* frame, const WebString& message) {
[email protected]ab533826b2013-05-10 23:54:562733 bool is_reload = false;
2734 WebDataSource* ds = frame->provisionalDataSource();
2735 if (ds)
[email protected]180ef242013-11-07 06:50:462736 is_reload = (ds->navigationType() == blink::WebNavigationTypeReload);
[email protected]ab533826b2013-05-10 23:54:562737 return runModalBeforeUnloadDialog(frame, is_reload, message);
2738}
2739
2740bool RenderViewImpl::runModalBeforeUnloadDialog(
2741 WebFrame* frame, bool is_reload, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:152742 // If we are swapping out, we have already run the beforeunload handler.
2743 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
2744 // at all, to avoid running it twice.
2745 if (is_swapped_out_)
2746 return true;
2747
[email protected]88f10a22013-11-06 21:22:122748 // Don't allow further dialogs if we are waiting to swap out, since the
2749 // PageGroupLoadDeferrer in our stack prevents it.
2750 if (suppress_dialogs_until_swap_out_)
2751 return false;
2752
[email protected]48c9cf2d2009-09-16 16:47:522753 bool success = false;
2754 // This is an ignored return value, but is included so we can accept the same
2755 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:412756 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:212757 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:322758 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:412759 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522760 return success;
2761}
2762
[email protected]310ebd6302011-10-10 19:06:282763void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:442764 WebFrame* frame, const WebContextMenuData& data) {
[email protected]3175fea2013-05-16 10:57:482765 ContextMenuParams params = ContextMenuParamsBuilder::Build(data);
[email protected]f56c7872013-06-18 12:31:572766 params.source_type = context_menu_source_type_;
[email protected]a14ddcd2013-06-21 22:53:032767 if (context_menu_source_type_ == ui::MENU_SOURCE_TOUCH_EDIT_MENU) {
[email protected]f56c7872013-06-18 12:31:572768 params.x = touch_editing_context_menu_location_.x();
2769 params.y = touch_editing_context_menu_location_.y();
2770 }
[email protected]b2e4c70132013-10-03 02:07:512771 OnShowHostContextMenu(&params);
[email protected]7fcd9b72011-07-27 16:52:372772
[email protected]329266d2012-09-27 06:20:572773 // Plugins, e.g. PDF, don't currently update the render view when their
2774 // selected text changes, but the context menu params do contain the updated
2775 // selection. If that's the case, update the render view's state just prior
2776 // to showing the context menu.
2777 // TODO(asvitkine): http://crbug.com/152432
[email protected]432c9a72013-02-27 01:51:032778 if (ShouldUpdateSelectionTextFromContextMenuParams(selection_text_,
2779 selection_text_offset_,
2780 selection_range_,
2781 params)) {
[email protected]329266d2012-09-27 06:20:572782 selection_text_ = params.selection_text;
2783 // TODO(asvitkine): Text offset and range is not available in this case.
2784 selection_text_offset_ = 0;
[email protected]db4fc1e2013-09-06 20:01:512785 selection_range_ = gfx::Range(0, selection_text_.length());
[email protected]329266d2012-09-27 06:20:572786 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2787 selection_text_,
2788 selection_text_offset_,
2789 selection_range_));
2790 }
2791
[email protected]7fcd9b72011-07-27 16:52:372792 // frame is NULL if invoked by BlockedPlugin.
2793 if (frame)
2794 params.frame_id = frame->identifier();
2795
[email protected]e9ff79c2012-10-19 21:31:262796 // Serializing a GURL longer than kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:272797 // it. We replace it with an empty GURL so the appropriate items are disabled
2798 // in the context menu.
2799 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2800 // data encoded images. We should have a way to save them.
[email protected]e9ff79c2012-10-19 21:31:262801 if (params.src_url.spec().size() > kMaxURLChars)
[email protected]216932c2010-08-26 21:44:272802 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102803 context_menu_node_ = data.node;
[email protected]44daa3b2012-09-27 19:26:412804
2805#if defined(OS_ANDROID)
2806 gfx::Rect start_rect;
2807 gfx::Rect end_rect;
2808 GetSelectionBounds(&start_rect, &end_rect);
[email protected]326a2342013-02-15 15:47:512809 params.selection_start = gfx::Point(start_rect.x(), start_rect.bottom());
2810 params.selection_end = gfx::Point(end_rect.right(), end_rect.bottom());
[email protected]44daa3b2012-09-27 19:26:412811#endif
2812
[email protected]c27324b2009-11-19 22:44:292813 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]b2324b092012-11-01 10:34:112814
2815 FOR_EACH_OBSERVER(
2816 RenderViewObserver, observers_, DidRequestShowContextMenu(frame, data));
[email protected]79e37442009-10-09 18:17:442817}
2818
[email protected]8b67f78f2013-08-13 12:04:302819void RenderViewImpl::clearContextMenu() {
2820 context_menu_node_.reset();
2821}
2822
[email protected]310ebd6302011-10-10 19:06:282823void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:522824}
2825
[email protected]310ebd6302011-10-10 19:06:282826void RenderViewImpl::UpdateTargetURL(const GURL& url,
2827 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582828 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522829 if (latest_url == target_url_)
2830 return;
[email protected]163f8242009-10-30 20:19:552831
[email protected]48c9cf2d2009-09-16 16:47:522832 // Tell the browser to display a destination link.
2833 if (target_url_status_ == TARGET_INFLIGHT ||
2834 target_url_status_ == TARGET_PENDING) {
2835 // If we have a request in-flight, save the URL to be sent when we
2836 // receive an ACK to the in-flight request. We can happily overwrite
2837 // any existing pending sends.
2838 pending_target_url_ = latest_url;
2839 target_url_status_ = TARGET_PENDING;
2840 } else {
[email protected]e9ff79c2012-10-19 21:31:262841 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:412842 // see |ParamTraits<GURL>|.
[email protected]e9ff79c2012-10-19 21:31:262843 if (latest_url.possibly_invalid_spec().size() > kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:412844 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:522845 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2846 target_url_ = latest_url;
2847 target_url_status_ = TARGET_INFLIGHT;
2848 }
2849}
2850
[email protected]70221f02013-01-31 22:17:072851gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect(
2852 const gfx::RectF& rect) const {
2853 gfx::RectF window_rect = rect;
2854 window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor());
2855 return window_rect;
2856}
2857
[email protected]7d08a9352013-10-15 08:24:562858int64 RenderViewImpl::GetLatencyComponentId() {
2859 // Note: this must match the logic in RenderWidgetHostImpl.
2860 return GetRoutingID() | (static_cast<int64>(
2861 RenderThreadImpl::current()->renderer_process_id()) << 32);
2862}
2863
[email protected]310ebd6302011-10-10 19:06:282864void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]a183fb82012-12-14 04:46:222865 // No need to update state if no page has committed yet.
2866 if (page_id_ == -1)
2867 return;
2868
[email protected]882daa92009-11-05 16:31:312869 int delay;
2870 if (send_content_state_immediately_)
2871 delay = 0;
2872 else if (is_hidden())
2873 delay = kDelaySecondsForContentStateSyncHidden;
2874 else
2875 delay = kDelaySecondsForContentStateSync;
2876
2877 if (nav_state_sync_timer_.IsRunning()) {
2878 // The timer is already running. If the delay of the timer maches the amount
2879 // we want to delay by, then return. Otherwise stop the timer so that it
2880 // gets started with the right delay.
2881 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2882 return;
2883 nav_state_sync_timer_.Stop();
2884 }
2885
[email protected]d323a172011-09-02 18:23:022886 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:282887 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:312888}
2889
[email protected]310ebd6302011-10-10 19:06:282890void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552891 mouse_over_url_ = GURL(url);
2892 UpdateTargetURL(mouse_over_url_, focus_url_);
2893}
2894
[email protected]310ebd6302011-10-10 19:06:282895void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552896 focus_url_ = GURL(url);
2897 UpdateTargetURL(focus_url_, mouse_over_url_);
2898}
2899
[email protected]0407e422012-05-18 19:51:252900void RenderViewImpl::startDragging(WebFrame* frame,
2901 const WebDragData& data,
[email protected]310ebd6302011-10-10 19:06:282902 WebDragOperationsMask mask,
2903 const WebImage& image,
[email protected]ceb36f7d2012-10-31 18:33:242904 const WebPoint& webImageOffset) {
[email protected]dc293a72013-07-01 11:11:222905 DropData drop_data(DropDataBuilder::Build(data));
[email protected]b67151d2012-05-25 23:23:242906 drop_data.referrer_policy = frame->document().referrerPolicy();
[email protected]ceb36f7d2012-10-31 18:33:242907 gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y);
[email protected]59f4f2fa2011-03-23 01:00:552908 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]b67151d2012-05-25 23:23:242909 drop_data,
[email protected]c27ae592010-03-18 15:24:412910 mask,
[email protected]976127072012-05-10 20:08:112911 image.getSkBitmap(),
[email protected]41d86852012-11-07 12:23:242912 imageOffset,
2913 possible_drag_event_info_));
[email protected]48c9cf2d2009-09-16 16:47:522914}
2915
[email protected]310ebd6302011-10-10 19:06:282916bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:452917 return renderer_preferences_.can_accept_load_drops;
2918}
2919
[email protected]310ebd6302011-10-10 19:06:282920void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:522921 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2922}
2923
[email protected]310ebd6302011-10-10 19:06:282924void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:522925 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2926}
2927
[email protected]310ebd6302011-10-10 19:06:282928void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512929 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072930
[email protected]38b592902011-04-16 02:08:422931 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:492932}
2933
[email protected]572a6ca2012-10-11 19:38:012934void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
2935 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
2936}
2937
[email protected]169d4282011-11-30 19:33:592938void RenderViewImpl::didUpdateLayout() {
[email protected]d01b2a62013-09-18 23:21:332939 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidUpdateLayout());
2940
[email protected]169d4282011-11-30 19:33:592941 // We don't always want to set up a timer, only if we've been put in that
2942 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2943 // message.
2944 if (!send_preferred_size_changes_ || !webview())
2945 return;
2946
2947 if (check_preferred_size_timer_.IsRunning())
2948 return;
2949 check_preferred_size_timer_.Start(FROM_HERE,
2950 TimeDelta::FromMilliseconds(0), this,
2951 &RenderViewImpl::CheckPreferredSize);
2952}
2953
[email protected]310ebd6302011-10-10 19:06:282954void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522955 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2956}
2957
[email protected]310ebd6302011-10-10 19:06:282958int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002959 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522960}
2961
[email protected]310ebd6302011-10-10 19:06:282962int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002963 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522964}
2965
[email protected]10760e4a2013-09-04 23:32:202966void RenderViewImpl::postAccessibilityEvent(
[email protected]180ef242013-11-07 06:50:462967 const WebAXObject& obj, blink::WebAXEvent event) {
[email protected]2a84f9d2012-06-05 21:50:432968 if (renderer_accessibility_) {
[email protected]10760e4a2013-09-04 23:32:202969 renderer_accessibility_->HandleWebAccessibilityEvent(obj, event);
[email protected]2a84f9d2012-06-05 21:50:432970 }
[email protected]063afcb2011-09-29 07:54:322971}
2972
[email protected]310ebd6302011-10-10 19:06:282973void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:142974 const WebString& value) {
2975 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2976 key.utf8(),
2977 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262978}
2979
[email protected]180ef242013-11-07 06:50:462980// blink::WebWidgetClient ----------------------------------------------------
[email protected]79dbc662009-09-04 05:42:512981
[email protected]310ebd6302011-10-10 19:06:282982void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122983 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2984 // we won't have to test for user gesture anymore and we can
2985 // move that code back to render_widget.cc
[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_Focus(routing_id_));
[email protected]ea42e7782010-08-23 23:58:122989 }
2990}
2991
[email protected]310ebd6302011-10-10 19:06:282992void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122993 // TODO(jcivelli): see TODO above in didFocus().
[email protected]af15bf22013-03-08 01:18:172994 if (WebUserGestureIndicator::isProcessingUserGesture() &&
[email protected]70dee7e2013-05-29 18:28:302995 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]e1176152013-03-06 09:16:442996 Send(new ViewHostMsg_Blur(routing_id_));
[email protected]ea42e7782010-08-23 23:58:122997 }
2998}
2999
initial.commit09911bf2008-07-26 23:55:293000// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:283001// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:293002// point to dispatch the ShowView message.
3003//
3004// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:283005// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:293006//
[email protected]310ebd6302011-10-10 19:06:283007void RenderViewImpl::show(WebNavigationPolicy policy) {
[email protected]b2142e962012-10-30 13:59:253008 if (did_show_) {
[email protected]b2142e962012-10-30 13:59:253009 // When supports_multiple_windows is disabled, popups are reusing
3010 // the same view. In some scenarios, this makes WebKit to call show() twice.
[email protected]c9edabd2013-05-23 13:56:243011 if (webkit_preferences_.supports_multiple_windows)
3012 NOTREACHED() << "received extraneous Show call";
initial.commit09911bf2008-07-26 23:55:293013 return;
[email protected]b2142e962012-10-30 13:59:253014 }
initial.commit09911bf2008-07-26 23:55:293015 did_show_ = true;
3016
[email protected]b2142e962012-10-30 13:59:253017 DCHECK(opener_id_ != MSG_ROUTING_NONE);
3018
[email protected]28295ec2009-10-16 05:34:333019 // Force new windows to a popup if they were not opened with a user gesture.
3020 if (!opened_by_user_gesture_) {
3021 // We exempt background tabs for compat with older versions of Chrome.
3022 // TODO(darin): This seems bogus. These should have a user gesture, so
3023 // we probably don't need this check.
[email protected]180ef242013-11-07 06:50:463024 if (policy != blink::WebNavigationPolicyNewBackgroundTab)
3025 policy = blink::WebNavigationPolicyNewPopup;
[email protected]28295ec2009-10-16 05:34:333026 }
3027
initial.commit09911bf2008-07-26 23:55:293028 // NOTE: initial_pos_ may still have its default values at this point, but
3029 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
3030 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:283031 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
3032 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:293033 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:243034 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:293035}
3036
[email protected]310ebd6302011-10-10 19:06:283037void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:293038 DCHECK(did_show_) << "should already have shown the view";
3039
[email protected]88f10a22013-11-06 21:22:123040 // Don't allow further dialogs if we are waiting to swap out, since the
3041 // PageGroupLoadDeferrer in our stack prevents it.
3042 if (suppress_dialogs_until_swap_out_)
3043 return;
3044
[email protected]c1f50aa2010-02-18 03:46:573045 // We must keep WebKit's shared timer running in this case in order to allow
3046 // showModalDialog to function properly.
3047 //
3048 // TODO(darin): WebKit should really be smarter about suppressing events and
3049 // timers so that we do not need to manage the shared timer in such a heavy
3050 // handed manner.
3051 //
[email protected]f1a29a02011-10-06 23:08:443052 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
3053 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:573054
[email protected]08a1c8102012-05-11 23:14:263055 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
3056 routing_id_, opener_id_));
initial.commit09911bf2008-07-26 23:55:293057}
3058
[email protected]2b624c562011-10-27 22:58:263059bool RenderViewImpl::enterFullScreen() {
3060 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
3061 return true;
3062}
3063
3064void RenderViewImpl::exitFullScreen() {
3065 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
3066}
3067
[email protected]217690d2012-01-27 07:33:113068bool RenderViewImpl::requestPointerLock() {
3069 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
3070}
3071
3072void RenderViewImpl::requestPointerUnlock() {
3073 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
3074}
3075
3076bool RenderViewImpl::isPointerLocked() {
3077 return mouse_lock_dispatcher_->IsMouseLockedTo(
3078 webwidget_mouse_lock_target_.get());
3079}
3080
[email protected]7a1ec28a2012-03-28 21:10:243081void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
[email protected]0cd50aa2013-02-12 22:28:013082#if !defined(OS_MACOSX) // many events are unhandled - http://crbug.com/138003
[email protected]ea5f70a2013-03-07 12:30:363083 InputHandlerManager* input_handler_manager =
3084 RenderThreadImpl::current()->input_handler_manager();
[email protected]200a9c062013-05-20 04:34:373085 if (input_handler_manager) {
3086 input_handler_manager->AddInputHandler(
3087 routing_id_,
3088 compositor_->GetInputHandler(),
3089 AsWeakPtr());
3090 }
[email protected]70cff27502013-01-17 09:16:493091#endif
[email protected]7a1ec28a2012-03-28 21:10:243092
3093 RenderWidget::didActivateCompositor(input_handler_identifier);
3094}
3095
[email protected]c68c3e4e2013-01-24 00:36:563096void RenderViewImpl::didHandleGestureEvent(
3097 const WebGestureEvent& event,
3098 bool event_cancelled) {
3099 RenderWidget::didHandleGestureEvent(event, event_cancelled);
3100 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3101 DidHandleGestureEvent(event));
3102}
3103
[email protected]6e89eb72013-07-23 13:28:223104void RenderViewImpl::initializeLayerTreeView() {
3105 RenderWidget::initializeLayerTreeView();
3106 RenderWidgetCompositor* rwc = compositor();
3107 if (!rwc || !webview() || !webview()->devToolsAgent())
3108 return;
3109 webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId());
3110}
3111
[email protected]180ef242013-11-07 06:50:463112// blink::WebFrameClient -----------------------------------------------------
[email protected]3d9689372009-09-10 04:29:173113
[email protected]97b150db2012-08-16 18:26:023114WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]180ef242013-11-07 06:50:463115 WebFrame* frame, const blink::WebURL& url, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:443116 FOR_EACH_OBSERVER(
3117 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:173118
[email protected]40bed812013-11-05 06:59:153119 WebMediaPlayer* player = CreateWebMediaPlayerForMediaStream(frame, url,
3120 client);
3121 if (player)
3122 return player;
[email protected]d05e2162012-11-16 22:21:463123
[email protected]25fb9b32012-04-27 03:21:553124#if defined(OS_ANDROID)
[email protected]40bed812013-11-05 06:59:153125 return CreateAndroidWebMediaPlayer(frame, url, client);
3126#else
[email protected]4a914882013-01-10 00:43:483127 scoped_refptr<media::AudioRendererSink> sink;
[email protected]40bed812013-11-05 06:59:153128 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableAudio)) {
[email protected]17c4ce62f2013-05-03 19:54:023129 sink = RenderThreadImpl::current()->GetAudioRendererMixerManager()->
3130 CreateInput(routing_id_);
[email protected]fc72bb12013-06-02 21:13:463131 DVLOG(1) << "Using AudioRendererMixerManager-provided sink: " << sink.get();
[email protected]3d9689372009-09-10 04:29:173132 }
3133
[email protected]5e35a8d2013-07-10 19:37:213134 WebMediaPlayerParams params(
[email protected]c1330c82013-06-06 02:23:253135 RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy(),
[email protected]d726eddc2013-07-02 22:25:553136 base::Bind(&ContentRendererClient::DeferMediaLoad,
3137 base::Unretained(GetContentClient()->renderer()),
3138 static_cast<RenderView*>(this)),
3139 sink,
[email protected]c50edb962013-10-19 18:05:073140 RenderThreadImpl::current()->GetGpuFactories(),
[email protected]d726eddc2013-07-02 22:25:553141 new RenderMediaLog());
[email protected]5e35a8d2013-07-10 19:37:213142 return new WebMediaPlayerImpl(frame, client, AsWeakPtr(), params);
[email protected]40bed812013-11-05 06:59:153143#endif // defined(OS_ANDROID)
[email protected]3d9689372009-09-10 04:29:173144}
3145
[email protected]310ebd6302011-10-10 19:06:283146WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:383147 return &cookie_jar_;
3148}
3149
[email protected]59167c22013-06-03 18:07:323150void RenderViewImpl::didAccessInitialDocument(WebFrame* frame) {
3151 // Notify the browser process that it is no longer safe to show the pending
3152 // URL of the main frame, since a URL spoof is now possible.
3153 if (!frame->parent() && page_id_ == -1)
3154 Send(new ViewHostMsg_DidAccessInitialDocument(routing_id_));
3155}
3156
[email protected]180ef242013-11-07 06:50:463157void RenderViewImpl::didDisownOpener(blink::WebFrame* frame) {
[email protected]29ece2e2013-04-03 04:53:523158 // We only need to notify the browser if the active, top-level frame clears
3159 // its opener. We can ignore cases where a swapped out frame clears its
3160 // opener after hearing about it from the browser, and the browser does not
3161 // (yet) care about subframe openers.
3162 if (is_swapped_out_ || frame->parent())
[email protected]7cc78902012-12-06 02:32:263163 return;
3164
3165 // Notify WebContents and all its swapped out RenderViews.
3166 Send(new ViewHostMsg_DidDisownOpener(routing_id_));
3167}
3168
[email protected]310ebd6302011-10-10 19:06:283169void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:513170 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:453171}
3172
[email protected]310ebd6302011-10-10 19:06:283173void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:513174 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:173175}
3176
[email protected]f5b6dd1122013-10-04 02:42:503177void RenderViewImpl::didMatchCSS(
3178 WebFrame* frame,
3179 const WebVector<WebString>& newly_matching_selectors,
3180 const WebVector<WebString>& stopped_matching_selectors) {
3181 FOR_EACH_OBSERVER(
3182 RenderViewObserver, observers_,
3183 DidMatchCSS(frame, newly_matching_selectors, stopped_matching_selectors));
3184}
3185
[email protected]5e92282f2012-08-17 08:11:573186void RenderViewImpl::Repaint(const gfx::Size& size) {
[email protected]3d9ec5052013-01-02 22:05:253187 OnRepaint(size);
[email protected]5e92282f2012-08-17 08:11:573188}
3189
[email protected]b2324b092012-11-01 10:34:113190void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
3191 const std::string& value) {
3192 EditCommands edit_commands;
3193 edit_commands.push_back(EditCommand(name, value));
3194 OnSetEditCommandsForNextKeyEvent(edit_commands);
3195}
3196
3197void RenderViewImpl::ClearEditCommands() {
3198 edit_commands_.clear();
3199}
3200
[email protected]180ef242013-11-07 06:50:463201SSLStatus RenderViewImpl::GetSSLStatusOfFrame(blink::WebFrame* frame) const {
[email protected]83c0abca2013-07-23 20:09:423202 std::string security_info;
3203 if (frame && frame->dataSource())
3204 security_info = frame->dataSource()->response().securityInfo();
3205
3206 SSLStatus ssl_status;
3207 DeserializeSecurityInfo(security_info,
3208 &ssl_status.cert_id,
3209 &ssl_status.cert_status,
3210 &ssl_status.security_bits,
3211 &ssl_status.connection_status);
3212 return ssl_status;
[email protected]e4495212012-12-06 03:09:123213}
3214
[email protected]b38806a2013-10-04 16:01:383215const std::string& RenderViewImpl::GetAcceptLanguages() const {
3216 return renderer_preferences_.accept_languages;
3217}
3218
[email protected]310ebd6302011-10-10 19:06:283219WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]0d8f04b2013-04-29 20:05:313220 WebFrame* frame, WebDataSource::ExtraData* extraData,
3221 const WebURLRequest& request, WebNavigationType type,
3222 WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]099df81cf2012-11-14 17:44:043223 if (request.url() != GURL(kSwappedOutURL) &&
3224 GetContentClient()->renderer()->HandleNavigation(frame, request, type,
3225 default_policy,
3226 is_redirect)) {
[email protected]180ef242013-11-07 06:50:463227 return blink::WebNavigationPolicyIgnore;
[email protected]099df81cf2012-11-14 17:44:043228 }
3229
[email protected]44e55b012013-07-23 14:21:563230 Referrer referrer(GetReferrerFromRequest(frame, request));
[email protected]0639c063a2012-03-22 20:55:333231
[email protected]992db4c2011-05-12 15:37:153232 if (is_swapped_out_) {
[email protected]e9ff79c2012-10-19 21:31:263233 if (request.url() != GURL(kSwappedOutURL)) {
[email protected]0639c063a2012-03-22 20:55:333234 // Targeted links may try to navigate a swapped out frame. Allow the
3235 // browser process to navigate the tab instead. Note that it is also
3236 // possible for non-targeted navigations (from this view) to arrive
3237 // here just after we are swapped out. It's ok to send them to the
3238 // browser, as long as they're for the top level frame.
3239 // TODO(creis): Ensure this supports targeted form submissions when
3240 // fixing http://crbug.com/101395.
3241 if (frame->parent() == NULL) {
3242 OpenURL(frame, request.url(), referrer, default_policy);
[email protected]180ef242013-11-07 06:50:463243 return blink::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]0639c063a2012-03-22 20:55:333244 }
3245
3246 // We should otherwise ignore in-process iframe navigations, if they
3247 // arrive just after we are swapped out.
[email protected]180ef242013-11-07 06:50:463248 return blink::WebNavigationPolicyIgnore;
[email protected]0639c063a2012-03-22 20:55:333249 }
[email protected]73eb2602012-02-09 19:50:553250
[email protected]e9ff79c2012-10-19 21:31:263251 // Allow kSwappedOutURL to complete.
[email protected]992db4c2011-05-12 15:37:153252 return default_policy;
3253 }
3254
[email protected]3d9689372009-09-10 04:29:173255 // Webkit is asking whether to navigate to a new URL.
3256 // This is fine normally, except if we're showing UI from one security
3257 // context and they're trying to navigate to a different context.
3258 const GURL& url = request.url();
3259
[email protected]d19ea342011-04-20 20:31:133260 // A content initiated navigation may have originated from a link-click,
3261 // script, drag-n-drop operation, etc.
[email protected]0d8f04b2013-04-29 20:05:313262 bool is_content_initiated = static_cast<DocumentState*>(extraData)->
[email protected]007733c2011-11-17 00:34:073263 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:133264
[email protected]a8c269a2011-10-25 20:17:223265 // Experimental:
[email protected]c6f2e672012-11-15 01:47:023266 // If --enable-strict-site-isolation or --site-per-process is enabled, send
3267 // all top-level navigations to the browser to let it swap processes when
3268 // crossing site boundaries. This is currently expected to break some script
3269 // calls and navigations, such as form submissions.
[email protected]a8c269a2011-10-25 20:17:223270 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]c6f2e672012-11-15 01:47:023271 bool force_swap_due_to_flag =
3272 command_line.HasSwitch(switches::kEnableStrictSiteIsolation) ||
3273 command_line.HasSwitch(switches::kSitePerProcess);
3274 if (force_swap_due_to_flag &&
[email protected]313b80bd2011-11-23 03:49:103275 !frame->parent() && (is_content_initiated || is_redirect)) {
3276 WebString origin_str = frame->document().securityOrigin().toString();
3277 GURL frame_url(origin_str.utf8().data());
[email protected]18fb7a772012-09-20 19:25:093278 // TODO(cevans): revisit whether this site check is still necessary once
[email protected]313b80bd2011-11-23 03:49:103279 // crbug.com/101395 is fixed.
[email protected]ed32c212013-05-14 20:49:293280 bool same_domain_or_host =
3281 net::registry_controlled_domains::SameDomainOrHost(
3282 frame_url,
3283 url,
3284 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
3285 if (!same_domain_or_host || frame_url.scheme() != url.scheme()) {
[email protected]313b80bd2011-11-23 03:49:103286 OpenURL(frame, url, referrer, default_policy);
[email protected]180ef242013-11-07 06:50:463287 return blink::WebNavigationPolicyIgnore;
[email protected]313b80bd2011-11-23 03:49:103288 }
[email protected]a8c269a2011-10-25 20:17:223289 }
3290
[email protected]fd3238af2012-05-22 18:55:303291 // If the browser is interested, then give it a chance to look at the request.
[email protected]5f000f272012-01-19 05:25:083292 if (is_content_initiated) {
[email protected]180ef242013-11-07 06:50:463293 bool is_form_post = ((type == blink::WebNavigationTypeFormSubmitted) ||
3294 (type == blink::WebNavigationTypeFormResubmitted)) &&
[email protected]140a5882013-07-23 19:30:333295 EqualsASCII(request.httpMethod(), "POST");
[email protected]fd3238af2012-05-22 18:55:303296 bool browser_handles_request =
3297 renderer_preferences_.browser_handles_non_local_top_level_requests &&
[email protected]140a5882013-07-23 19:30:333298 IsNonLocalTopLevelNavigation(url, frame, type, is_form_post);
[email protected]fd3238af2012-05-22 18:55:303299 if (!browser_handles_request) {
3300 browser_handles_request =
3301 renderer_preferences_.browser_handles_all_top_level_requests &&
3302 IsTopLevelNavigation(frame);
3303 }
3304
3305 if (browser_handles_request) {
[email protected]5f000f272012-01-19 05:25:083306 // Reset these counters as the RenderView could be reused for the next
3307 // navigation.
3308 page_id_ = -1;
3309 last_page_id_sent_to_browser_ = -1;
3310 OpenURL(frame, url, referrer, default_policy);
[email protected]180ef242013-11-07 06:50:463311 return blink::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]5f000f272012-01-19 05:25:083312 }
[email protected]3d9689372009-09-10 04:29:173313 }
3314
[email protected]dc67e1c32012-06-08 00:10:403315 // Use the frame's original request's URL rather than the document's URL for
3316 // subsequent checks. For a popup, the document's URL may become the opener
3317 // window's URL if the opener has called document.write().
3318 // See http://crbug.com/93517.
3319 GURL old_url(frame->dataSource()->request().url());
3320
[email protected]6101c342010-12-16 22:44:373321 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:553322 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:043323 // top-level navigations (not iframes). But we sometimes navigate to
3324 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:373325 //
[email protected]744c2a22012-03-15 18:42:043326 // Note: this is known to break POST submissions when crossing process
3327 // boundaries until http://crbug.com/101395 is fixed. This is better for
3328 // security than loading a WebUI, extension or app page in the wrong process.
3329 // POST requests don't work because this mechanism does not preserve form
3330 // POST data. We will need to send the request's httpBody data up to the
3331 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:573332 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
3333 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:223334 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:043335 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:373336 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:043337
[email protected]0a57375a2013-03-07 22:18:593338 // All navigations to or from WebUI URLs or within WebUI-enabled
3339 // RenderProcesses must be handled by the browser process so that the
3340 // correct bindings and data sources can be registered.
[email protected]744c2a22012-03-15 18:42:043341 // Similarly, navigations to view-source URLs or within ViewSource mode
[email protected]1c210f692012-11-06 22:31:473342 // must be handled by the browser process (except for reloads - those are
3343 // safe to leave within the renderer).
[email protected]dc67e1c32012-06-08 00:10:403344 // Lastly, access to file:// URLs from non-file:// URL pages must be
3345 // handled by the browser so that ordinary renderer processes don't get
3346 // blessed with file permissions.
3347 int cumulative_bindings = RenderProcess::current()->GetEnabledBindings();
3348 bool is_initial_navigation = page_id_ == -1;
[email protected]0a57375a2013-03-07 22:18:593349 bool should_fork = HasWebUIScheme(url) || HasWebUIScheme(old_url) ||
[email protected]e9ff79c2012-10-19 21:31:263350 (cumulative_bindings & BINDINGS_POLICY_WEB_UI) ||
[email protected]dbdda5402013-05-30 22:13:483351 url.SchemeIs(kViewSourceScheme) ||
[email protected]1c210f692012-11-06 22:31:473352 (frame->isViewSourceModeEnabled() &&
[email protected]180ef242013-11-07 06:50:463353 type != blink::WebNavigationTypeReload);
[email protected]5351dbc2010-08-27 15:22:113354
[email protected]dc67e1c32012-06-08 00:10:403355 if (!should_fork && url.SchemeIs(chrome::kFileScheme)) {
3356 // Fork non-file to file opens. Check the opener URL if this is the
3357 // initial navigation in a newly opened window.
3358 GURL source_url(old_url);
3359 if (is_initial_navigation && source_url.is_empty() && frame->opener())
3360 source_url = frame->opener()->top()->document().url();
3361 DCHECK(!source_url.is_empty());
3362 should_fork = !source_url.SchemeIs(chrome::kFileScheme);
3363 }
3364
[email protected]e48869a2011-04-01 19:56:033365 if (!should_fork) {
3366 // Give the embedder a chance.
[email protected]c5dec6292013-01-25 04:54:523367 should_fork = GetContentClient()->renderer()->ShouldFork(
3368 frame, url, request.httpMethod().utf8(), is_initial_navigation,
[email protected]b0a29f22013-05-30 23:00:093369 is_redirect, &send_referrer);
[email protected]6101c342010-12-16 22:44:373370 }
3371
3372 if (should_fork) {
[email protected]445e1042011-12-03 21:03:153373 OpenURL(
3374 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]180ef242013-11-07 06:50:463375 return blink::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]5351dbc2010-08-27 15:22:113376 }
[email protected]3d9689372009-09-10 04:29:173377 }
3378
3379 // Detect when a page is "forking" a new tab that can be safely rendered in
3380 // its own process. This is done by sites like Gmail that try to open links
3381 // in new windows without script connections back to the original page. We
3382 // treat such cases as browser navigations (in which we will create a new
3383 // renderer for a cross-site navigation), rather than WebKit navigations.
3384 //
3385 // We use the following heuristic to decide whether to fork a new page in its
3386 // own process:
3387 // The parent page must open a new tab to about:blank, set the new tab's
3388 // window.opener to null, and then redirect the tab to a cross-site URL using
3389 // JavaScript.
[email protected]007a848b2009-10-26 15:55:463390 //
3391 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
3392 // (see below).
[email protected]3d9689372009-09-10 04:29:173393 bool is_fork =
3394 // Must start from a tab showing about:blank, which is later redirected.
[email protected]081dc522013-05-15 04:59:203395 old_url == GURL(kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:173396 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:523397 historyBackListCount() < 1 &&
3398 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:173399 // The parent page must have set the child's window.opener to null before
3400 // redirecting to the desired URL.
3401 frame->opener() == NULL &&
3402 // Must be a top-level frame.
3403 frame->parent() == NULL &&
3404 // Must not have issued the request from this page.
3405 is_content_initiated &&
3406 // Must be targeted at the current tab.
[email protected]180ef242013-11-07 06:50:463407 default_policy == blink::WebNavigationPolicyCurrentTab &&
[email protected]3d9689372009-09-10 04:29:173408 // Must be a JavaScript navigation, which appears as "other".
[email protected]180ef242013-11-07 06:50:463409 type == blink::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:463410
[email protected]f92ce2b2012-03-06 18:02:593411 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:173412 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:153413 OpenURL(frame, url, Referrer(), default_policy);
[email protected]180ef242013-11-07 06:50:463414 return blink::WebNavigationPolicyIgnore;
[email protected]3d9689372009-09-10 04:29:173415 }
3416
3417 return default_policy;
3418}
3419
[email protected]f4f40a052013-04-19 15:28:113420WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
3421 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]89bc54c62013-04-24 01:51:333422 WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]0d8f04b2013-04-29 20:05:313423 return decidePolicyForNavigation(frame,
3424 frame->provisionalDataSource()->extraData(),
[email protected]89bc54c62013-04-24 01:51:333425 request, type, default_policy, is_redirect);
[email protected]f4f40a052013-04-19 15:28:113426}
3427
[email protected]180ef242013-11-07 06:50:463428void RenderViewImpl::willSendSubmitEvent(blink::WebFrame* frame,
3429 const blink::WebFormElement& form) {
[email protected]0660a8c2013-08-16 01:09:123430 FOR_EACH_OBSERVER(
3431 RenderViewObserver, observers_, WillSendSubmitEvent(frame, form));
[email protected]90eeddb2010-05-06 21:06:433432}
3433
[email protected]310ebd6302011-10-10 19:06:283434void RenderViewImpl::willSubmitForm(WebFrame* frame,
3435 const WebFormElement& form) {
[email protected]2a5b1732011-04-01 23:55:553436 FOR_EACH_OBSERVER(
3437 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:173438}
3439
[email protected]310ebd6302011-10-10 19:06:283440void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:573441 bool content_initiated = !pending_navigation_params_.get();
3442
[email protected]f8872902013-10-30 03:18:573443 // Make sure any previous redirect URLs end up in our new data source.
3444 if (pending_navigation_params_.get()) {
3445 for (std::vector<GURL>::const_iterator i =
3446 pending_navigation_params_->redirects.begin();
3447 i != pending_navigation_params_->redirects.end(); ++i) {
3448 ds->appendRedirect(*i);
3449 }
3450 }
3451
[email protected]007733c2011-11-17 00:34:073452 DocumentState* document_state = DocumentState::FromDataSource(ds);
3453 if (!document_state) {
3454 document_state = new DocumentState;
3455 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:573456 if (!content_initiated)
3457 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:073458 }
3459
[email protected]bf70edce2012-06-20 22:32:223460 // Carry over the user agent override flag, if it exists.
3461 if (content_initiated && webview() && webview()->mainFrame() &&
3462 webview()->mainFrame()->dataSource()) {
3463 DocumentState* old_document_state =
3464 DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
3465 if (old_document_state) {
[email protected]e20b88d2013-04-09 15:28:373466 InternalDocumentStateData* internal_data =
3467 InternalDocumentStateData::FromDocumentState(document_state);
3468 InternalDocumentStateData* old_internal_data =
3469 InternalDocumentStateData::FromDocumentState(old_document_state);
3470 internal_data->set_is_overriding_user_agent(
3471 old_internal_data->is_overriding_user_agent());
[email protected]bf70edce2012-06-20 22:32:223472 }
3473 }
3474
[email protected]3d9689372009-09-10 04:29:173475 // The rest of RenderView assumes that a WebDataSource will always have a
3476 // non-null NavigationState.
[email protected]e1ed5a12012-08-08 19:57:443477 if (content_initiated) {
[email protected]007733c2011-11-17 00:34:073478 document_state->set_navigation_state(
3479 NavigationState::CreateContentInitiated());
[email protected]e1ed5a12012-08-08 19:57:443480 } else {
[email protected]45d83a12012-04-06 22:57:573481 document_state->set_navigation_state(CreateNavigationStateFromPending());
3482 pending_navigation_params_.reset();
3483 }
[email protected]8a3125a712010-08-09 18:58:513484
[email protected]007733c2011-11-17 00:34:073485 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:513486 // navigating from a page that used prefetching using a link on that
3487 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:073488 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:513489 // this value appropriately.
3490 // TODO(gavinp): catch the important case of navigation in a new
3491 // renderer process.
3492 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303493 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523494 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513495 const GURL referrer(
3496 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3497 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:073498 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:513499 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:413500 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:513501 WebDataSource* old_frame_ds = old_frame->dataSource();
3502 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:073503 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513504 break;
3505 }
3506 }
3507 }
3508 }
3509 }
3510
[email protected]4c1b6f0b2010-02-07 16:38:183511 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523512 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513513 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183514 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:073515 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:183516 break;
3517 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:073518 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:183519 break;
3520 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:073521 document_state->set_load_type(
3522 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:183523 break;
3524 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:073525 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:183526 break;
3527 }
3528 }
[email protected]fa7b6b542009-11-03 05:02:303529
[email protected]946a0032011-03-31 18:42:283530 FOR_EACH_OBSERVER(
3531 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:173532}
3533
[email protected]45d83a12012-04-06 22:57:573534void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:073535 DocumentState* document_state) {
3536 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:573537 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:073538
[email protected]e20b88d2013-04-09 15:28:373539 InternalDocumentStateData* internal_data =
3540 InternalDocumentStateData::FromDocumentState(document_state);
3541
[email protected]44b05812013-08-19 07:59:353542 if (!params.url.SchemeIs(kJavaScriptScheme) &&
[email protected]45d83a12012-04-06 22:57:573543 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
3544 // We're doing a load of a page that was restored from the last session. By
3545 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
3546 // can result in stale data for pages that are set to expire. We explicitly
3547 // override that by setting the policy here so that as necessary we load
3548 // from the network.
[email protected]e20b88d2013-04-09 15:28:373549 internal_data->set_cache_policy_override(
[email protected]45d83a12012-04-06 22:57:573550 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:073551 }
3552
3553 if (IsReload(params))
3554 document_state->set_load_type(DocumentState::RELOAD);
[email protected]691aa2f2013-05-28 22:52:043555 else if (params.page_state.IsValid())
[email protected]007733c2011-11-17 00:34:073556 document_state->set_load_type(DocumentState::HISTORY_LOAD);
3557 else
3558 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]ca662822012-05-11 17:53:593559
[email protected]e20b88d2013-04-09 15:28:373560 internal_data->set_referrer_policy(params.referrer.policy);
3561 internal_data->set_is_overriding_user_agent(params.is_overriding_user_agent);
3562 internal_data->set_must_reset_scroll_and_scale_state(
[email protected]a3a5397d2012-09-12 06:50:343563 params.navigation_type ==
3564 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]951a64832012-10-11 16:26:373565 document_state->set_can_load_local_resources(params.can_load_local_resources);
[email protected]45d83a12012-04-06 22:57:573566}
[email protected]007733c2011-11-17 00:34:073567
[email protected]45d83a12012-04-06 22:57:573568NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
3569 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
3570 NavigationState* navigation_state = NULL;
3571
3572 // A navigation resulting from loading a javascript URL should not be treated
3573 // as a browser initiated event. Instead, we want it to look as if the page
3574 // initiated any load resulting from JS execution.
[email protected]44b05812013-08-19 07:59:353575 if (!params.url.SchemeIs(kJavaScriptScheme)) {
[email protected]45d83a12012-04-06 22:57:573576 navigation_state = NavigationState::CreateBrowserInitiated(
3577 params.page_id,
3578 params.pending_history_list_offset,
[email protected]60d6cca2013-04-30 08:47:133579 params.should_clear_history_list,
[email protected]45d83a12012-04-06 22:57:573580 params.transition);
[email protected]4972fc82013-11-19 04:33:423581 navigation_state->set_should_replace_current_entry(
3582 params.should_replace_current_entry);
[email protected]45d83a12012-04-06 22:57:573583 navigation_state->set_transferred_request_child_id(
3584 params.transferred_request_child_id);
3585 navigation_state->set_transferred_request_request_id(
3586 params.transferred_request_request_id);
[email protected]80744782012-05-04 01:47:003587 navigation_state->set_allow_download(params.allow_download);
[email protected]f050fde2013-03-21 00:40:453588 navigation_state->set_extra_headers(params.extra_headers);
[email protected]45d83a12012-04-06 22:57:573589 } else {
3590 navigation_state = NavigationState::CreateContentInitiated();
3591 }
3592 return navigation_state;
[email protected]007733c2011-11-17 00:34:073593}
3594
[email protected]5b52cd2f712012-03-28 02:12:483595void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
3596 bool enable_viewport =
[email protected]a41f8f602013-11-12 20:15:283597 command_line.HasSwitch(switches::kEnableViewport) ||
3598 command_line.HasSwitch(switches::kEnableViewportMeta);
[email protected]5b52cd2f712012-03-28 02:12:483599
[email protected]47e932da2013-03-07 00:11:243600 // If viewport tag is enabled, then the WebKit side will take care
3601 // of setting the fixed layout size and page scale limits.
3602 if (enable_viewport)
3603 return;
3604
[email protected]a02a0c92013-08-12 20:18:583605 // When navigating to a new page, reset the page scale factor to be 1.0.
3606 webview()->setInitialPageScaleOverride(1.f);
3607
[email protected]e4cd82e2013-04-10 15:20:383608 float maxPageScaleFactor =
3609 command_line.HasSwitch(switches::kEnablePinch) ? 4.f : 1.f ;
3610 webview()->setPageScaleFactorLimits(1, maxPageScaleFactor);
[email protected]5b52cd2f712012-03-28 02:12:483611}
3612
[email protected]8672bbf2013-10-22 13:37:083613// TODO(nasko): Remove this method once WebTestProxy in Blink is fixed.
[email protected]310ebd6302011-10-10 19:06:283614void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173615}
3616
[email protected]400992b2012-06-14 00:03:543617void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
3618 WebFrame* frame) {
3619 if (frame->parent())
3620 return;
3621 // Received a redirect on the main frame.
3622 WebDataSource* data_source = frame->provisionalDataSource();
3623 if (!data_source) {
3624 // Should only be invoked when we have a data source.
3625 NOTREACHED();
3626 return;
3627 }
3628 std::vector<GURL> redirects;
3629 GetRedirectChain(data_source, &redirects);
3630 if (redirects.size() >= 2) {
3631 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]434bc9b2012-11-27 21:22:143632 redirects[redirects.size() - 2], redirects.back()));
[email protected]400992b2012-06-14 00:03:543633 }
3634}
3635
[email protected]310ebd6302011-10-10 19:06:283636void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
3637 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173638 // Notify the browser that we failed a provisional load with an error.
3639 //
3640 // Note: It is important this notification occur before DidStopLoading so the
3641 // SSL manager can react to the provisional load failure before being
3642 // notified the load stopped.
3643 //
3644 WebDataSource* ds = frame->provisionalDataSource();
3645 DCHECK(ds);
3646
3647 const WebURLRequest& failed_request = ds->request();
3648
[email protected]28685da92011-02-07 21:49:173649 FOR_EACH_OBSERVER(
3650 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
3651
[email protected]3d9689372009-09-10 04:29:173652 bool show_repost_interstitial =
3653 (error.reason == net::ERR_CACHE_MISS &&
3654 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:583655
3656 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
3657 params.frame_id = frame->identifier();
[email protected]2f673064c2013-10-22 04:01:443658 params.frame_unique_name = frame->uniqueName();
[email protected]d7b175e2011-10-11 15:31:583659 params.is_main_frame = !frame->parent();
3660 params.error_code = error.reason;
[email protected]e9ff79c2012-10-19 21:31:263661 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]8da4d262013-04-23 05:15:533662 frame,
[email protected]d7b175e2011-10-11 15:31:583663 failed_request,
3664 error,
[email protected]b38806a2013-10-04 16:01:383665 renderer_preferences_.accept_languages,
[email protected]d7b175e2011-10-11 15:31:583666 NULL,
3667 &params.error_description);
3668 params.url = error.unreachableURL;
3669 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:173670 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:583671 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:173672
3673 // Don't display an error page if this is simply a cancelled load. Aside
3674 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3675 if (error.reason == net::ERR_ABORTED)
3676 return;
3677
[email protected]f677288e2013-09-18 02:11:003678 // Don't display "client blocked" error page if browser has asked us not to.
3679 if (error.reason == net::ERR_BLOCKED_BY_CLIENT &&
3680 renderer_preferences_.disable_client_blocked_error_page) {
3681 return;
3682 }
3683
[email protected]2309e912013-10-01 01:33:303684 // Allow the embedder to suppress an error page.
3685 if (GetContentClient()->renderer()->ShouldSuppressErrorPage(
3686 error.unreachableURL)) {
[email protected]ac7f5a02013-03-16 16:14:413687 return;
[email protected]2309e912013-10-01 01:33:303688 }
3689
3690 if (RenderThreadImpl::current() &&
3691 RenderThreadImpl::current()->layout_test_mode()) {
3692 return;
3693 }
[email protected]ac7f5a02013-03-16 16:14:413694
[email protected]3d9689372009-09-10 04:29:173695 // Make sure we never show errors in view source mode.
3696 frame->enableViewSourceMode(false);
3697
[email protected]007733c2011-11-17 00:34:073698 DocumentState* document_state = DocumentState::FromDataSource(ds);
3699 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173700
3701 // If this is a failed back/forward/reload navigation, then we need to do a
3702 // 'replace' load. This is necessary to avoid messing up session history.
3703 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3704 // as session history is concerned.
3705 //
3706 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3707 // the page id.
3708 //
[email protected]4972fc82013-11-19 04:33:423709 // TODO(davidben): This should also take the failed navigation's replacement
3710 // state into account, if a location.replace() failed.
[email protected]3d9689372009-09-10 04:29:173711 bool replace =
3712 navigation_state->pending_page_id() != -1 ||
[email protected]026aac22013-07-10 02:09:113713 PageTransitionCoreTypeIs(navigation_state->transition_type(),
3714 PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:173715
3716 // If we failed on a browser initiated request, then make sure that our error
3717 // page load is regarded as the same browser initiated request.
3718 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:073719 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
3720 pending_navigation_params_->page_id =
3721 navigation_state->pending_page_id();
3722 pending_navigation_params_->pending_history_list_offset =
3723 navigation_state->pending_history_list_offset();
[email protected]60d6cca2013-04-30 08:47:133724 pending_navigation_params_->should_clear_history_list =
3725 navigation_state->history_list_was_cleared();
[email protected]007733c2011-11-17 00:34:073726 pending_navigation_params_->transition =
3727 navigation_state->transition_type();
3728 pending_navigation_params_->request_time =
3729 document_state->request_time();
[email protected]4972fc82013-11-19 04:33:423730 pending_navigation_params_->should_replace_current_entry = replace;
[email protected]3d9689372009-09-10 04:29:173731 }
3732
3733 // Provide the user with a more helpful error page?
3734 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3735 return;
3736
3737 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083738 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173739}
3740
[email protected]310ebd6302011-10-10 19:06:283741void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
3742 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:073743 DocumentState* document_state =
3744 DocumentState::FromDataSource(frame->dataSource());
3745 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e20b88d2013-04-09 15:28:373746 InternalDocumentStateData* internal_data =
3747 InternalDocumentStateData::FromDocumentState(document_state);
[email protected]3d9689372009-09-10 04:29:173748
[email protected]007733c2011-11-17 00:34:073749 if (document_state->commit_load_time().is_null())
3750 document_state->set_commit_load_time(Time::Now());
3751
[email protected]e20b88d2013-04-09 15:28:373752 if (internal_data->must_reset_scroll_and_scale_state()) {
[email protected]06c7ba022012-12-17 19:24:123753 webview()->resetScrollAndScaleState();
[email protected]e20b88d2013-04-09 15:28:373754 internal_data->set_must_reset_scroll_and_scale_state(false);
[email protected]a3a5397d2012-09-12 06:50:343755 }
[email protected]4b9c9e292013-07-18 19:13:283756 internal_data->set_use_error_page(false);
[email protected]a3a5397d2012-09-12 06:50:343757
[email protected]3d9689372009-09-10 04:29:173758 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203759 // When we perform a new navigation, we need to update the last committed
3760 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173761 UpdateSessionHistory(frame);
3762
3763 // We bump our Page ID to correspond with the new session history entry.
3764 page_id_ = next_page_id_++;
3765
[email protected]e9ff79c2012-10-19 21:31:263766 // Don't update history_page_ids_ (etc) for kSwappedOutURL, since
[email protected]58436a12012-03-21 17:10:263767 // we don't want to forget the entry that was there, and since we will
[email protected]e9ff79c2012-10-19 21:31:263768 // never come back to kSwappedOutURL. Note that we have to call
[email protected]69ddf852012-02-21 23:21:313769 // UpdateSessionHistory and update page_id_ even in this case, so that
3770 // the current entry gets a state update and so that we don't send a
3771 // state update to the wrong entry when we swap back in.
[email protected]e9ff79c2012-10-19 21:31:263772 if (GetLoadingUrl(frame) != GURL(kSwappedOutURL)) {
[email protected]69ddf852012-02-21 23:21:313773 // Advance our offset in session history, applying the length limit.
3774 // There is now no forward history.
3775 history_list_offset_++;
[email protected]e9ff79c2012-10-19 21:31:263776 if (history_list_offset_ >= kMaxSessionHistoryEntries)
3777 history_list_offset_ = kMaxSessionHistoryEntries - 1;
[email protected]69ddf852012-02-21 23:21:313778 history_list_length_ = history_list_offset_ + 1;
3779 history_page_ids_.resize(history_list_length_, -1);
3780 history_page_ids_[history_list_offset_] = page_id_;
3781 }
[email protected]3d9689372009-09-10 04:29:173782 } else {
3783 // Inspect the navigation_state on this frame to see if the navigation
3784 // corresponds to a session history navigation... Note: |frame| may or
3785 // may not be the toplevel frame, but for the case of capturing session
3786 // history, the first committed frame suffices. We keep track of whether
3787 // we've seen this commit before so that only capture session history once
3788 // per navigation.
3789 //
3790 // Note that we need to check if the page ID changed. In the case of a
3791 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3792 // previous URL and the current page ID, which would be wrong.
3793 if (navigation_state->pending_page_id() != -1 &&
3794 navigation_state->pending_page_id() != page_id_ &&
3795 !navigation_state->request_committed()) {
3796 // This is a successful session history navigation!
3797 UpdateSessionHistory(frame);
3798 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003799
3800 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:033801
3802 // If the history list is valid, our list of page IDs should be correct.
3803 DCHECK(history_list_length_ <= 0 ||
3804 history_list_offset_ < 0 ||
3805 history_list_offset_ >= history_list_length_ ||
3806 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:173807 }
3808 }
3809
[email protected]28685da92011-02-07 21:49:173810 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3811 DidCommitProvisionalLoad(frame, is_new_navigation));
3812
[email protected]3d9689372009-09-10 04:29:173813 // Remember that we've already processed this request, so we don't update
3814 // the session history again. We do this regardless of whether this is
3815 // a session history navigation, because if we attempted a session history
3816 // navigation without valid HistoryItem state, WebCore will think it is a
3817 // new navigation.
3818 navigation_state->set_request_committed(true);
3819
3820 UpdateURL(frame);
3821
[email protected]3d9689372009-09-10 04:29:173822 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273823 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]b2d98762012-09-03 17:04:063824
3825 if (!frame->parent()) { // Only for top frames.
3826 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
3827 if (render_thread_impl) { // Can be NULL in tests.
3828 render_thread_impl->histogram_customizer()->
3829 RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(),
3830 g_view_map.Get().size());
3831 }
3832 }
[email protected]3d9689372009-09-10 04:29:173833}
3834
[email protected]310ebd6302011-10-10 19:06:283835void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:103836 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3837 DidClearWindowObject(frame));
3838
[email protected]e9ff79c2012-10-19 21:31:263839 if (enabled_bindings_ & BINDINGS_POLICY_DOM_AUTOMATION) {
[email protected]59383c782013-04-17 16:43:273840 if (!dom_automation_controller_)
[email protected]766a7082012-02-03 23:39:153841 dom_automation_controller_.reset(new DomAutomationController());
3842 dom_automation_controller_->set_message_sender(
[email protected]e9ff79c2012-10-19 21:31:263843 static_cast<RenderView*>(this));
[email protected]766a7082012-02-03 23:39:153844 dom_automation_controller_->set_routing_id(routing_id());
3845 dom_automation_controller_->BindToJavascript(frame,
3846 "domAutomationController");
3847 }
[email protected]27c521a2013-05-29 20:44:323848
3849 if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION) {
3850 if (!stats_collection_controller_.get())
3851 stats_collection_controller_.reset(new StatsCollectionController());
3852 stats_collection_controller_->set_message_sender(
3853 static_cast<RenderView*>(this));
3854 stats_collection_controller_->BindToJavascript(frame,
3855 "statsCollectionController");
3856 }
[email protected]3d9689372009-09-10 04:29:173857}
3858
[email protected]310ebd6302011-10-10 19:06:283859void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:033860 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3861 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:173862}
3863
[email protected]310ebd6302011-10-10 19:06:283864void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
3865 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:463866 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:173867
3868 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273869 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173870}
3871
[email protected]41225fe2013-03-29 05:32:023872void RenderViewImpl::didChangeIcon(WebFrame* frame,
3873 WebIconURL::Type icon_type) {
3874 if (frame->parent())
3875 return;
3876
3877 if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon)
3878 return;
3879
3880 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type);
3881 std::vector<FaviconURL> urls;
3882 for (size_t i = 0; i < icon_urls.size(); i++) {
3883 urls.push_back(FaviconURL(icon_urls[i].iconURL(),
3884 ToFaviconType(icon_urls[i].iconType())));
3885 }
3886 SendUpdateFaviconURL(urls);
[email protected]5019ef12010-04-27 17:26:583887}
3888
[email protected]310ebd6302011-10-10 19:06:283889void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173890 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073891 DocumentState* document_state = DocumentState::FromDataSource(ds);
3892 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:173893
[email protected]622474d2010-11-04 09:21:083894 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173895
[email protected]28685da92011-02-07 21:49:173896 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3897 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173898
3899 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273900 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173901}
3902
[email protected]310ebd6302011-10-10 19:06:283903void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083904 if (webview()->mainFrame() == frame) {
3905 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3906 page_id_));
3907 }
[email protected]3d9689372009-09-10 04:29:173908}
3909
[email protected]310ebd6302011-10-10 19:06:283910void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:313911 WebDataSource* ds = frame->dataSource();
3912 DCHECK(ds);
3913
3914
[email protected]28685da92011-02-07 21:49:173915 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:313916
3917 const WebURLRequest& failed_request = ds->request();
3918 string16 error_description;
[email protected]e9ff79c2012-10-19 21:31:263919 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]8da4d262013-04-23 05:15:533920 frame,
[email protected]1a55c5be2011-11-29 11:36:313921 failed_request,
3922 error,
[email protected]b38806a2013-10-04 16:01:383923 renderer_preferences_.accept_languages,
[email protected]1a55c5be2011-11-29 11:36:313924 NULL,
3925 &error_description);
3926 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
3927 frame->identifier(),
3928 failed_request.url(),
3929 !frame->parent(),
3930 error.reason,
3931 error_description));
[email protected]3d9689372009-09-10 04:29:173932}
3933
[email protected]310ebd6302011-10-10 19:06:283934void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173935 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073936 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]1ac2ff12013-07-16 20:53:533937 if (document_state->finish_load_time().is_null()) {
3938 if (!frame->parent()) {
3939 TRACE_EVENT_INSTANT0("WebCore", "LoadFinished",
3940 TRACE_EVENT_SCOPE_PROCESS);
3941 }
[email protected]007733c2011-11-17 00:34:073942 document_state->set_finish_load_time(Time::Now());
[email protected]1ac2ff12013-07-16 20:53:533943 }
[email protected]4d44a1c2010-04-28 19:20:413944
[email protected]676126f72011-01-15 00:03:513945 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173946
[email protected]1a55c5be2011-11-29 11:36:313947 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
3948 frame->identifier(),
3949 ds->request().url(),
3950 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:173951}
3952
[email protected]310ebd6302011-10-10 19:06:283953void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173954 WebFrame* frame, bool is_new_navigation) {
3955 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:073956 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:173957 // update the ExtraData on the datasource so that others who read the
3958 // ExtraData will get the new NavigationState. Similarly, if we did not
3959 // initiate this navigation, then we need to take care to reset any pre-
3960 // existing navigation state to a content-initiated navigation state.
3961 // DidCreateDataSource conveniently takes care of this for us.
3962 didCreateDataSource(frame, frame->dataSource());
3963
[email protected]007733c2011-11-17 00:34:073964 DocumentState* document_state =
3965 DocumentState::FromDataSource(frame->dataSource());
3966 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:093967 new_state->set_was_within_same_page(true);
3968
[email protected]3d9689372009-09-10 04:29:173969 didCommitProvisionalLoad(frame, is_new_navigation);
[email protected]3d9689372009-09-10 04:29:173970}
3971
[email protected]310ebd6302011-10-10 19:06:283972void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313973 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593974}
3975
[email protected]310ebd6302011-10-10 19:06:283976void RenderViewImpl::willSendRequest(WebFrame* frame,
3977 unsigned identifier,
3978 WebURLRequest& request,
3979 const WebURLResponse& redirect_response) {
[email protected]e507045d2013-07-24 15:23:443980 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:173981}
3982
[email protected]310ebd6302011-10-10 19:06:283983void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173984 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]e507045d2013-07-24 15:23:443985 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:173986}
3987
[email protected]310ebd6302011-10-10 19:06:283988void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173989 WebFrame* frame, unsigned identifier) {
[email protected]e20b88d2013-04-09 15:28:373990 InternalDocumentStateData* internal_data =
3991 InternalDocumentStateData::FromDataSource(frame->dataSource());
3992 if (!internal_data->use_error_page())
[email protected]3d9689372009-09-10 04:29:173993 return;
3994
[email protected]7bfc153f2011-09-23 22:00:203995 // Do not show error page when DevTools is attached.
3996 if (devtools_agent_->IsAttached())
3997 return;
3998
[email protected]06333afe2011-02-24 14:55:093999 // Display error page, if appropriate.
[email protected]e20b88d2013-04-09 15:28:374000 int http_status_code = internal_data->http_status_code();
[email protected]3f853a52010-09-13 19:15:084001 if (http_status_code == 404) {
4002 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:414003 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:174004
[email protected]b6cb3a842011-06-24 18:28:414005 const GURL& error_page_url =
4006 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:094007 if (error_page_url.is_valid()) {
4008 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:474009 original_error.domain = "http";
4010 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:414011 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:174012
[email protected]e20b88d2013-04-09 15:28:374013 internal_data->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:094014 new AltErrorPageResourceFetcher(
[email protected]11a65772013-04-27 00:36:424015 error_page_url, frame, frame->dataSource()->request(),
4016 original_error,
[email protected]6e806822011-11-19 01:51:084017 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4018 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:094019 return;
4020 }
4021 }
[email protected]3d9689372009-09-10 04:29:174022
[email protected]e6a2ce52011-10-08 01:40:134023 std::string error_domain;
[email protected]e9ff79c2012-10-19 21:31:264024 if (GetContentClient()->renderer()->HasErrorPage(
[email protected]e6a2ce52011-10-08 01:40:134025 http_status_code, &error_domain)) {
4026 WebURLError error;
4027 error.unreachableURL = frame->document().url();
4028 error.domain = WebString::fromUTF8(error_domain);
4029 error.reason = http_status_code;
4030
4031 LoadNavigationErrorPage(
4032 frame, frame->dataSource()->request(), error, std::string(), true);
4033 }
[email protected]3d9689372009-09-10 04:29:174034}
4035
[email protected]310ebd6302011-10-10 19:06:284036void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:174037 WebFrame* frame, const WebURLRequest& request,
4038 const WebURLResponse& response) {
[email protected]e507045d2013-07-24 15:23:444039 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:174040}
4041
[email protected]310ebd6302011-10-10 19:06:284042void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e507045d2013-07-24 15:23:444043 NOTREACHED();
[email protected]e3d60e5d2009-09-25 21:08:294044}
4045
[email protected]310ebd6302011-10-10 19:06:284046void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:024047 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e507045d2013-07-24 15:23:444048 NOTREACHED();
[email protected]e3d60e5d2009-09-25 21:08:294049}
4050
[email protected]310ebd6302011-10-10 19:06:284051void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]e507045d2013-07-24 15:23:444052 NOTREACHED();
[email protected]3d9689372009-09-10 04:29:174053}
4054
[email protected]310ebd6302011-10-10 19:06:284055void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
4056 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:584057 int extension_group,
[email protected]310ebd6302011-10-10 19:06:284058 int world_id) {
[email protected]e507045d2013-07-24 15:23:444059 NOTREACHED();
[email protected]a00fe692012-02-27 05:52:584060}
4061
[email protected]310ebd6302011-10-10 19:06:284062void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
4063 v8::Handle<v8::Context> context,
4064 int world_id) {
[email protected]e507045d2013-07-24 15:23:444065 NOTREACHED();
[email protected]0c882b282009-10-07 17:01:284066}
4067
[email protected]310ebd6302011-10-10 19:06:284068void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:074069 // We don't always want to send the change messages over IPC, only if we've
4070 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
4071 // message.
4072 if (!send_preferred_size_changes_ || !webview())
4073 return;
4074
[email protected]e76b7972013-06-06 02:58:484075 gfx::Size size = webview()->contentsPreferredMinimumSize();
[email protected]8205d742010-10-22 23:51:534076
[email protected]7940b8e2013-07-25 23:08:494077 // In the presence of zoom, these sizes are still reported as if unzoomed,
4078 // so we need to adjust.
4079 double zoom_factor = ZoomLevelToZoomFactor(webview()->zoomLevel());
4080 size.set_width(static_cast<int>(size.width() * zoom_factor));
4081 size.set_height(static_cast<int>(size.height() * zoom_factor));
4082
[email protected]705243f2010-05-05 19:58:074083 if (size == preferred_size_)
4084 return;
[email protected]c27324b2009-11-19 22:44:294085
[email protected]705243f2010-05-05 19:58:074086 preferred_size_ = size;
4087 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
4088 preferred_size_));
[email protected]3d9689372009-09-10 04:29:174089}
4090
[email protected]caaf2482013-05-01 20:33:324091BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() {
[email protected]fc72bb12013-06-02 21:13:464092 if (!browser_plugin_manager_.get())
[email protected]fb325d122012-11-20 23:58:054093 browser_plugin_manager_ = BrowserPluginManager::Create(this);
[email protected]fc72bb12013-06-02 21:13:464094 return browser_plugin_manager_.get();
[email protected]fb325d122012-11-20 23:58:054095}
4096
[email protected]60ee79f2013-09-11 13:49:554097bool RenderViewImpl::InitializeMediaStreamClient() {
4098 if (media_stream_client_)
4099 return true;
4100
[email protected]7082fb942012-05-16 23:44:594101 if (!RenderThreadImpl::current()) // Will be NULL during unit tests.
[email protected]60ee79f2013-09-11 13:49:554102 return false;
[email protected]08381562012-05-15 20:55:404103
[email protected]d9da9582013-01-31 04:59:054104#if defined(OS_ANDROID)
[email protected]ce585bf2013-03-14 16:25:164105 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableWebRTC))
[email protected]60ee79f2013-09-11 13:49:554106 return false;
[email protected]d9da9582013-01-31 04:59:054107#endif
4108
[email protected]4fb0f202012-05-30 22:44:534109#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:514110 if (!media_stream_dispatcher_)
4111 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
4112
[email protected]60ee79f2013-09-11 13:49:554113 MediaStreamImpl* media_stream_impl = new MediaStreamImpl(
4114 this,
4115 media_stream_dispatcher_,
4116 RenderThreadImpl::current()->GetMediaStreamDependencyFactory());
4117 media_stream_client_ = media_stream_impl;
4118 web_user_media_client_ = media_stream_impl;
4119 return true;
4120#else
4121 return false;
[email protected]5b87e782012-02-09 18:19:324122#endif
[email protected]273558fb2012-01-12 15:03:514123}
4124
[email protected]310ebd6302011-10-10 19:06:284125void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
4126 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:314127 if (webview()->mainFrame() != frame)
4128 return;
4129 WebView* frameView = frame->view();
4130 if (!frameView)
4131 return;
4132
4133 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
4134 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
4135
4136 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
4137 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
4138 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
4139 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
4140
4141 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
4142 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
4143 }
4144}
4145
[email protected]310ebd6302011-10-10 19:06:284146void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:314147 WebSize offset = frame->scrollOffset();
4148 WebSize minimum_offset = frame->minimumScrollOffset();
4149 WebSize maximum_offset = frame->maximumScrollOffset();
4150
4151 bool is_pinned_to_left = offset.width <= minimum_offset.width;
4152 bool is_pinned_to_right = offset.width >= maximum_offset.width;
4153
4154 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
4155 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
4156 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
4157 routing_id_, is_pinned_to_left, is_pinned_to_right));
4158
4159 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
4160 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
4161 }
[email protected]4e721742013-02-04 21:39:304162
4163 Send(new ViewHostMsg_DidChangeScrollOffset(routing_id_));
[email protected]dd6afca2011-08-13 03:44:314164}
4165
[email protected]310ebd6302011-10-10 19:06:284166void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:494167 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:314168
4169 if (webview()->mainFrame() == frame)
4170 UpdateScrollState(frame);
[email protected]2b942c332012-04-25 16:26:264171
4172 FOR_EACH_OBSERVER(
4173 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]dd6afca2011-08-13 03:44:314174}
4175
[email protected]180ef242013-11-07 06:50:464176void RenderViewImpl::willInsertBody(blink::WebFrame* frame) {
[email protected]e507045d2013-07-24 15:23:444177 NOTREACHED();
[email protected]a9344092d2013-02-27 00:56:454178}
4179
[email protected]4d0f8182012-10-19 23:14:474180void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebFrame* frame) {
4181 if (frame != webview()->mainFrame())
4182 return;
4183
[email protected]92d457802013-04-01 19:18:494184 InternalDocumentStateData* data =
4185 InternalDocumentStateData::FromDataSource(frame->dataSource());
4186 data->set_did_first_visually_non_empty_layout(true);
4187
4188#if defined(OS_ANDROID)
[email protected]4d0f8182012-10-19 23:14:474189 // Update body background color if necessary.
4190 SkColor bg_color = webwidget_->backgroundColor();
4191
4192 // If not initialized, default to white. Note that 0 is different from black
4193 // as black still has alpha 0xFF.
4194 if (!bg_color)
4195 bg_color = SK_ColorWHITE;
4196
4197 if (bg_color != body_background_color_) {
4198 body_background_color_ = bg_color;
[email protected]e507045d2013-07-24 15:23:444199 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(
4200 GetRoutingID(), bg_color));
[email protected]4d0f8182012-10-19 23:14:474201 }
[email protected]4d0f8182012-10-19 23:14:474202#endif
[email protected]92d457802013-04-01 19:18:494203}
[email protected]4d0f8182012-10-19 23:14:474204
[email protected]55750b32012-09-21 14:05:034205void RenderViewImpl::SendFindReply(int request_id,
4206 int match_count,
4207 int ordinal,
4208 const WebRect& selection_rect,
4209 bool final_status_update) {
[email protected]55750b32012-09-21 14:05:034210 Send(new ViewHostMsg_Find_Reply(routing_id_,
4211 request_id,
4212 match_count,
4213 selection_rect,
4214 ordinal,
4215 final_status_update));
4216}
4217
[email protected]432c9a72013-02-27 01:51:034218// static
4219bool RenderViewImpl::ShouldUpdateSelectionTextFromContextMenuParams(
4220 const string16& selection_text,
4221 size_t selection_text_offset,
[email protected]db4fc1e2013-09-06 20:01:514222 const gfx::Range& selection_range,
[email protected]432c9a72013-02-27 01:51:034223 const ContextMenuParams& params) {
4224 string16 trimmed_selection_text;
4225 if (!selection_text.empty() && !selection_range.is_empty()) {
4226 const int start = selection_range.GetMin() - selection_text_offset;
4227 const size_t length = selection_range.length();
4228 if (start >= 0 && start + length <= selection_text.length()) {
4229 TrimWhitespace(selection_text.substr(start, length), TRIM_ALL,
4230 &trimmed_selection_text);
4231 }
4232 }
4233 string16 trimmed_params_text;
4234 TrimWhitespace(params.selection_text, TRIM_ALL, &trimmed_params_text);
4235 return trimmed_params_text != trimmed_selection_text;
4236}
4237
[email protected]55750b32012-09-21 14:05:034238void RenderViewImpl::reportFindInPageMatchCount(int request_id,
4239 int count,
[email protected]310ebd6302011-10-10 19:06:284240 bool final_update) {
[email protected]1f35b45e2013-08-29 17:36:464241 // TODO(jam): switch PepperPluginInstanceImpl to take a RenderFrame
4242 main_render_frame_->reportFindInPageMatchCount(
4243 request_id, count, final_update);
[email protected]8922e1f2009-10-03 05:01:264244}
4245
[email protected]310ebd6302011-10-10 19:06:284246void RenderViewImpl::reportFindInPageSelection(int request_id,
4247 int active_match_ordinal,
4248 const WebRect& selection_rect) {
[email protected]1f35b45e2013-08-29 17:36:464249 // TODO(jam): switch PepperPluginInstanceImpl to take a RenderFrame
4250 main_render_frame_->reportFindInPageSelection(
4251 request_id, active_match_ordinal, selection_rect);
[email protected]8922e1f2009-10-03 05:01:264252}
4253
[email protected]310ebd6302011-10-10 19:06:284254void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:404255 WebFrame* frame,
4256 WebStorageQuotaType type,
4257 unsigned long long requested_size,
4258 WebStorageQuotaCallbacks* callbacks) {
[email protected]e507045d2013-07-24 15:23:444259 NOTREACHED();
[email protected]10e5cf12011-04-13 04:10:404260}
4261
[email protected]f546640b2012-05-15 00:03:494262bool RenderViewImpl::willCheckAndDispatchMessageEvent(
[email protected]180ef242013-11-07 06:50:464263 blink::WebFrame* sourceFrame,
4264 blink::WebFrame* targetFrame,
4265 blink::WebSecurityOrigin target_origin,
4266 blink::WebDOMMessageEvent event) {
[email protected]f546640b2012-05-15 00:03:494267 if (!is_swapped_out_)
4268 return false;
4269
4270 ViewMsg_PostMessage_Params params;
4271 params.data = event.data().toString();
4272 params.source_origin = event.origin();
4273 if (!target_origin.isNull())
4274 params.target_origin = target_origin.toString();
4275
[email protected]180ef242013-11-07 06:50:464276 blink::WebMessagePortChannelArray channels = event.releaseChannels();
[email protected]0bc7f3542013-10-21 15:05:534277 if (!channels.isEmpty()) {
4278 std::vector<int> message_port_ids(channels.size());
4279 // Extract the port IDs from the channel array.
4280 for (size_t i = 0; i < channels.size(); ++i) {
4281 WebMessagePortChannelImpl* webchannel =
4282 static_cast<WebMessagePortChannelImpl*>(channels[i]);
4283 message_port_ids[i] = webchannel->message_port_id();
4284 webchannel->QueueMessages();
4285 DCHECK_NE(message_port_ids[i], MSG_ROUTING_NONE);
4286 }
4287 params.message_port_ids = message_port_ids;
4288 }
4289
[email protected]2bb45f52013-11-02 02:15:084290 // Include the routing ID for the source frame (if one exists), which the
4291 // browser process will translate into the routing ID for the equivalent
4292 // frame in the target process.
[email protected]f546640b2012-05-15 00:03:494293 params.source_routing_id = MSG_ROUTING_NONE;
[email protected]2bb45f52013-11-02 02:15:084294 if (sourceFrame) {
4295 RenderViewImpl* source_view = FromWebView(sourceFrame->view());
4296 if (source_view)
4297 params.source_routing_id = source_view->routing_id();
4298 }
[email protected]f546640b2012-05-15 00:03:494299
4300 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params));
4301 return true;
4302}
4303
[email protected]5fa3a062012-03-21 15:39:344304void RenderViewImpl::willOpenSocketStream(
4305 WebSocketStreamHandle* handle) {
[email protected]e507045d2013-07-24 15:23:444306 NOTREACHED();
[email protected]5fa3a062012-03-21 15:39:344307}
4308
[email protected]ccee4862012-10-03 18:34:264309void RenderViewImpl::willStartUsingPeerConnectionHandler(
[email protected]180ef242013-11-07 06:50:464310 blink::WebFrame* frame, blink::WebRTCPeerConnectionHandler* handler) {
[email protected]e507045d2013-07-24 15:23:444311 NOTREACHED();
[email protected]ccee4862012-10-03 18:34:264312}
4313
[email protected]180ef242013-11-07 06:50:464314blink::WebString RenderViewImpl::acceptLanguages() {
[email protected]9982c802013-06-12 15:22:064315 return WebString::fromUTF8(renderer_preferences_.accept_languages);
4316}
4317
[email protected]180ef242013-11-07 06:50:464318blink::WebString RenderViewImpl::userAgentOverride(
4319 blink::WebFrame* frame,
4320 const blink::WebURL& url) {
[email protected]e507045d2013-07-24 15:23:444321 NOTREACHED();
[email protected]180ef242013-11-07 06:50:464322 return blink::WebString();
[email protected]bf70edce2012-06-20 22:32:224323}
4324
[email protected]a3e217f2013-04-12 22:38:344325WebString RenderViewImpl::doNotTrackValue(WebFrame* frame) {
[email protected]e507045d2013-07-24 15:23:444326 NOTREACHED();
[email protected]180ef242013-11-07 06:50:464327 return blink::WebString();
[email protected]a3e217f2013-04-12 22:38:344328}
4329
[email protected]818915cd2012-11-20 13:14:114330bool RenderViewImpl::allowWebGL(WebFrame* frame, bool default_value) {
[email protected]e507045d2013-07-24 15:23:444331 NOTREACHED();
4332 return false;
[email protected]818915cd2012-11-20 13:14:114333}
4334
4335void RenderViewImpl::didLoseWebGLContext(
[email protected]180ef242013-11-07 06:50:464336 blink::WebFrame* frame,
[email protected]818915cd2012-11-20 13:14:114337 int arb_robustness_status_code) {
[email protected]e507045d2013-07-24 15:23:444338 NOTREACHED();
[email protected]818915cd2012-11-20 13:14:114339}
4340
[email protected]180ef242013-11-07 06:50:464341// blink::WebPageSerializerClient implementation ------------------------------
[email protected]18d5be92011-07-25 18:00:194342
[email protected]310ebd6302011-10-10 19:06:284343void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:194344 const WebURL& frame_url,
4345 const WebCString& data,
4346 WebPageSerializerClient::PageSerializationStatus status) {
4347 Send(new ViewHostMsg_SendSerializedHtmlData(
4348 routing_id(),
4349 frame_url,
4350 data.data(),
4351 static_cast<int32>(status)));
4352}
4353
[email protected]e9ff79c2012-10-19 21:31:264354// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:314355
[email protected]310ebd6302011-10-10 19:06:284356bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:314357 return RenderWidget::Send(message);
4358}
4359
[email protected]82114f52012-03-20 22:53:414360int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:314361 return routing_id_;
4362}
4363
[email protected]82114f52012-03-20 22:53:414364int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:314365 return page_id_;
4366}
4367
[email protected]82114f52012-03-20 22:53:414368gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:314369 return size();
4370}
4371
[email protected]82114f52012-03-20 22:53:414372WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:314373 return webkit_preferences_;
4374}
4375
[email protected]324825d2012-11-30 12:37:154376void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
4377 OnUpdateWebPreferences(preferences);
4378}
4379
[email protected]180ef242013-11-07 06:50:464380blink::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:314381 return webview();
4382}
4383
[email protected]180ef242013-11-07 06:50:464384blink::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:314385 if (!webview())
4386 return WebNode();
4387 WebFrame* focused_frame = webview()->focusedFrame();
4388 if (focused_frame) {
4389 WebDocument doc = focused_frame->document();
4390 if (!doc.isNull())
4391 return doc.focusedNode();
4392 }
4393
4394 return WebNode();
4395}
4396
[email protected]180ef242013-11-07 06:50:464397blink::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:314398 return context_menu_node_;
4399}
4400
[email protected]2a84f9d2012-06-05 21:50:434401bool RenderViewImpl::IsEditableNode(const WebNode& node) const {
4402 if (node.isNull())
4403 return false;
4404
4405 if (node.isContentEditable())
4406 return true;
4407
4408 if (node.isElementNode()) {
4409 const WebElement& element = node.toConst<WebElement>();
4410 if (element.isTextFormControlElement())
4411 return true;
4412
4413 // Also return true if it has an ARIA role of 'textbox'.
4414 for (unsigned i = 0; i < element.attributeCount(); ++i) {
4415 if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) {
4416 if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox"))
4417 return true;
4418 break;
4419 }
[email protected]a2ef54c2011-10-10 16:20:314420 }
4421 }
[email protected]2a84f9d2012-06-05 21:50:434422
4423 return false;
[email protected]a2ef54c2011-10-10 16:20:314424}
4425
[email protected]180ef242013-11-07 06:50:464426blink::WebPlugin* RenderViewImpl::CreatePlugin(
4427 blink::WebFrame* frame,
[email protected]d7bd3e52013-07-21 04:29:204428 const WebPluginInfo& info,
[email protected]180ef242013-11-07 06:50:464429 const blink::WebPluginParams& params) {
[email protected]ea2fb972013-08-07 05:44:264430#if defined(ENABLE_PLUGINS)
4431 bool pepper_plugin_was_registered = false;
4432 scoped_refptr<PluginModule> pepper_module(PluginModule::Create(
4433 this, info, &pepper_plugin_was_registered));
4434 if (pepper_plugin_was_registered) {
4435 if (pepper_module.get())
4436 return new PepperWebPluginImpl(pepper_module.get(), params, AsWeakPtr());
4437 }
[email protected]a2ef54c2011-10-10 16:20:314438
[email protected]29e2fb42013-07-19 01:13:474439 return new WebPluginImpl(frame, params, info.path, AsWeakPtr());
[email protected]ea2fb972013-08-07 05:44:264440#else
4441 return NULL;
4442#endif
[email protected]a2ef54c2011-10-10 16:20:314443}
4444
[email protected]310ebd6302011-10-10 19:06:284445void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
4446 const string16& jscript,
4447 int id,
4448 bool notify_result) {
[email protected]e1907b432013-09-04 16:11:144449 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
[email protected]a2ef54c2011-10-10 16:20:314450 v8::Handle<v8::Value> result;
4451 WebFrame* web_frame = GetChildFrame(frame_xpath);
4452 if (web_frame)
4453 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
4454 if (notify_result) {
[email protected]0cd50aa2013-02-12 22:28:014455 base::ListValue list;
[email protected]a2ef54c2011-10-10 16:20:314456 if (!result.IsEmpty() && web_frame) {
[email protected]a2ef54c2011-10-10 16:20:314457 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4458 v8::Context::Scope context_scope(context);
4459 V8ValueConverterImpl converter;
[email protected]3de391e82012-05-16 17:50:514460 converter.SetDateAllowed(true);
[email protected]e0658bc2012-09-17 04:05:244461 converter.SetRegExpAllowed(true);
4462 base::Value* result_value = converter.FromV8Value(result, context);
[email protected]0cd50aa2013-02-12 22:28:014463 list.Set(0, result_value ? result_value : base::Value::CreateNullValue());
[email protected]a2ef54c2011-10-10 16:20:314464 } else {
[email protected]0cd50aa2013-02-12 22:28:014465 list.Set(0, base::Value::CreateNullValue());
[email protected]a2ef54c2011-10-10 16:20:314466 }
4467 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
4468 }
4469}
4470
[email protected]310ebd6302011-10-10 19:06:284471bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:314472 return (!send_preferred_size_changes_ ||
4473 (disable_scrollbars_size_limit_.width() <= width ||
4474 disable_scrollbars_size_limit_.height() <= height));
4475}
4476
[email protected]82114f52012-03-20 22:53:414477int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:314478 return enabled_bindings_;
4479}
4480
[email protected]82114f52012-03-20 22:53:414481bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:314482 return send_content_state_immediately_;
4483}
4484
[email protected]82114f52012-03-20 22:53:414485float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:314486 return filtered_time_per_frame();
4487}
4488
[email protected]e9ff79c2012-10-19 21:31:264489int RenderViewImpl::ShowContextMenu(ContextMenuClient* client,
4490 const ContextMenuParams& params) {
[email protected]860ee642012-10-13 03:46:254491 DCHECK(client); // A null client means "internal" when we issue callbacks.
[email protected]e9ff79c2012-10-19 21:31:264492 ContextMenuParams our_params(params);
[email protected]860ee642012-10-13 03:46:254493 our_params.custom_context.request_id = pending_context_menus_.Add(client);
4494 Send(new ViewHostMsg_ContextMenu(routing_id_, our_params));
4495 return our_params.custom_context.request_id;
[email protected]a2ef54c2011-10-10 16:20:314496}
4497
[email protected]e0fd0eb2012-10-17 21:11:464498void RenderViewImpl::CancelContextMenu(int request_id) {
4499 DCHECK(pending_context_menus_.Lookup(request_id));
4500 pending_context_menus_.Remove(request_id);
4501}
4502
[email protected]180ef242013-11-07 06:50:464503blink::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:314504 return visibilityState();
4505}
4506
[email protected]180ef242013-11-07 06:50:464507void RenderViewImpl::RunModalAlertDialog(blink::WebFrame* frame,
4508 const blink::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:314509 return runModalAlertDialog(frame, message);
4510}
4511
[email protected]310ebd6302011-10-10 19:06:284512void RenderViewImpl::LoadURLExternally(
[email protected]180ef242013-11-07 06:50:464513 blink::WebFrame* frame,
4514 const blink::WebURLRequest& request,
4515 blink::WebNavigationPolicy policy) {
[email protected]e507045d2013-07-24 15:23:444516 main_render_frame_->loadURLExternally(frame, request, policy);
[email protected]a2ef54c2011-10-10 16:20:314517}
4518
[email protected]3c71576ce2013-07-23 02:00:014519void RenderViewImpl::DidStartLoading() {
4520 didStartLoading();
4521}
4522
4523void RenderViewImpl::DidStopLoading() {
4524 didStopLoading();
4525}
4526
[email protected]180ef242013-11-07 06:50:464527void RenderViewImpl::DidPlay(blink::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074528 Send(new ViewHostMsg_MediaNotification(routing_id_,
4529 reinterpret_cast<int64>(player),
4530 player->hasVideo(),
4531 player->hasAudio(),
4532 true));
4533}
4534
[email protected]180ef242013-11-07 06:50:464535void RenderViewImpl::DidPause(blink::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074536 Send(new ViewHostMsg_MediaNotification(routing_id_,
4537 reinterpret_cast<int64>(player),
4538 player->hasVideo(),
4539 player->hasAudio(),
4540 false));
4541}
4542
[email protected]180ef242013-11-07 06:50:464543void RenderViewImpl::PlayerGone(blink::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074544 DidPause(player);
4545}
4546
[email protected]310ebd6302011-10-10 19:06:284547void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:294548 if (!webview())
4549 return;
4550
[email protected]26aa0482009-09-30 16:55:274551 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:054552 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:294553}
4554
[email protected]310ebd6302011-10-10 19:06:284555void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:364556 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:004557 if (!frame)
4558 return;
[email protected]b781ff282011-08-20 06:19:364559
[email protected]e99ef6f2011-10-16 01:13:004560 string16 text;
4561 size_t offset;
[email protected]db4fc1e2013-09-06 20:01:514562 gfx::Range range;
[email protected]ea2fb972013-08-07 05:44:264563#if defined(ENABLE_PLUGINS)
4564 if (focused_pepper_plugin_) {
4565 focused_pepper_plugin_->GetSurroundingText(&text, &range);
[email protected]82114f52012-03-20 22:53:414566 offset = 0; // Pepper API does not support offset reporting.
[email protected]3c8c74c2012-03-15 07:34:524567 // TODO(kinaba): cut as needed.
[email protected]ea2fb972013-08-07 05:44:264568 } else
4569#endif
4570 {
[email protected]3c8c74c2012-03-15 07:34:524571 size_t location, length;
4572 if (!webview()->caretOrSelectionRange(&location, &length))
4573 return;
4574
[email protected]db4fc1e2013-09-06 20:01:514575 range = gfx::Range(location, location + length);
[email protected]3c8c74c2012-03-15 07:34:524576
[email protected]180ef242013-11-07 06:50:464577 if (webview()->textInputInfo().type != blink::WebTextInputTypeNone) {
[email protected]3c8c74c2012-03-15 07:34:524578 // If current focused element is editable, we will send 100 more chars
4579 // before and after selection. It is for input method surrounding text
4580 // feature.
4581 if (location > kExtraCharsBeforeAndAfterSelection)
4582 offset = location - kExtraCharsBeforeAndAfterSelection;
4583 else
4584 offset = 0;
4585 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
4586 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
4587 if (!webrange.isNull())
4588 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
4589 } else {
4590 offset = location;
4591 text = frame->selectionAsText();
4592 // http://crbug.com/101435
4593 // In some case, frame->selectionAsText() returned text's length is not
4594 // equal to the length returned from webview()->caretOrSelectionRange().
4595 // So we have to set the range according to text.length().
4596 range.set_end(range.start() + text.length());
4597 }
[email protected]b781ff282011-08-20 06:19:364598 }
4599
[email protected]b781ff282011-08-20 06:19:364600 // Sometimes we get repeated didChangeSelection calls from webkit when
4601 // the selection hasn't actually changed. We don't want to report these
4602 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:004603 if (selection_text_offset_ != offset ||
4604 selection_range_ != range ||
4605 selection_text_ != text) {
4606 selection_text_ = text;
4607 selection_text_offset_ = offset;
4608 selection_range_ = range;
4609 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
4610 }
[email protected]47822262013-04-23 17:22:364611 UpdateSelectionBounds();
[email protected]b781ff282011-08-20 06:19:364612}
4613
[email protected]310ebd6302011-10-10 19:06:284614GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
4615 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554616 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294617 // If the URL that failed was secure, then the embedding web page was not
4618 // expecting a network attacker to be able to manipulate its contents. As
4619 // we fetch alternate error pages over HTTP, we would be allowing a network
4620 // attacker to manipulate the contents of the response if we tried to use
4621 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154622 return GURL();
initial.commit09911bf2008-07-26 23:55:294623 }
4624
4625 // Grab the base URL from the browser process.
4626 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154627 return GURL();
initial.commit09911bf2008-07-26 23:55:294628
4629 // Strip query params from the failed URL.
4630 GURL::Replacements remove_params;
4631 remove_params.ClearUsername();
4632 remove_params.ClearPassword();
4633 remove_params.ClearQuery();
4634 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554635 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]b38806a2013-10-04 16:01:384636 // TODO(yuusuke): change to net::FormatUrl when link doctor
4637 // becomes unicode-capable.
[email protected]6fd28f642010-03-15 17:15:504638 std::string spec_to_send = url_to_send.spec();
4639 // Notify link doctor of the url truncation by sending of "?" at the end.
4640 if (failed_url.has_query())
[email protected]82114f52012-03-20 22:53:414641 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294642
4643 // Construct the query params to send to link doctor.
4644 std::string params(alternate_error_page_url_.query());
4645 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:024646 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294647 params.append("&sourceid=chrome");
4648 params.append("&error=");
4649 switch (error_type) {
4650 case DNS_ERROR:
4651 params.append("dnserror");
4652 break;
4653
4654 case HTTP_404:
4655 params.append("http404");
4656 break;
4657
[email protected]5df266ac2008-10-15 19:50:134658 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334659 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134660 break;
4661
initial.commit09911bf2008-07-26 23:55:294662 default:
4663 NOTREACHED() << "unknown ErrorPageType";
4664 }
4665
4666 // OK, build the final url to return.
4667 GURL::Replacements link_doctor_params;
4668 link_doctor_params.SetQueryStr(params);
4669 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4670 return url;
4671}
4672
[email protected]180ef242013-11-07 06:50:464673GURL RenderViewImpl::GetLoadingUrl(blink::WebFrame* frame) const {
[email protected]69ddf852012-02-21 23:21:314674 WebDataSource* ds = frame->dataSource();
4675 if (ds->hasUnreachableURL())
4676 return ds->unreachableURL();
4677
4678 const WebURLRequest& request = ds->request();
4679 return request.url();
4680}
4681
[email protected]180ef242013-11-07 06:50:464682blink::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:014683 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494684}
4685
[email protected]55750b32012-09-21 14:05:034686void RenderViewImpl::OnFind(int request_id,
4687 const string16& search_text,
[email protected]310ebd6302011-10-10 19:06:284688 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274689 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494690
[email protected]872542532011-06-23 00:43:164691 // Check if the plugin still exists in the document.
4692 if (main_frame->document().isPluginDocument() &&
4693 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494694 if (options.findNext) {
4695 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014696 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494697 } else {
[email protected]55750b32012-09-21 14:05:034698 if (!GetWebPluginFromPluginDocument()->startFind(
[email protected]afdbd142010-07-10 08:01:234699 search_text, options.matchCase, request_id)) {
[email protected]e7c58a32010-08-13 19:47:114700 // Send "no results".
[email protected]55750b32012-09-21 14:05:034701 SendFindReply(request_id, 0, 0, gfx::Rect(), true);
[email protected]24a7f3c2010-03-25 08:26:494702 }
4703 }
4704 return;
4705 }
4706
[email protected]b4bb2502009-10-01 22:35:274707 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274708 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294709 WebFrame* search_frame = focused_frame; // start searching focused frame.
4710
4711 bool multi_frame = (frame_after_main != main_frame);
4712
4713 // If we have multiple frames, we don't want to wrap the search within the
4714 // frame, so we check here if we only have main_frame in the chain.
4715 bool wrap_within_frame = !multi_frame;
4716
[email protected]b3f2b912009-04-09 16:18:524717 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294718 bool result = false;
4719
[email protected]7830da3e2009-11-06 16:27:264720 // If something is selected when we start searching it means we cannot just
4721 // increment the current match ordinal; we need to re-generate it.
4722 WebRange current_selection = focused_frame->selectionRange();
4723
initial.commit09911bf2008-07-26 23:55:294724 do {
[email protected]dd7daa82009-08-10 05:46:454725 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594726 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294727
4728 if (!result) {
4729 // don't leave text selected as you move to the next 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 // Find the next frame, but skip the invisible ones.
4734 do {
4735 // What is the next frame to search? (we might be going backwards). Note
4736 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594737 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274738 search_frame->traverseNext(true) :
4739 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454740 } while (!search_frame->hasVisibleContent() &&
4741 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294742
[email protected]884db412008-11-24 23:46:504743 // Make sure selection doesn't affect the search operation in new frame.
[email protected]6dd17a8a2013-05-01 05:50:104744 search_frame->executeCommand(WebString::fromUTF8("Unselect"),
4745 GetFocusedNode());
initial.commit09911bf2008-07-26 23:55:294746
4747 // If we have multiple frames and we have wrapped back around to the
4748 // focused frame, we need to search it once more allowing wrap within
4749 // the frame, otherwise it will report 'no match' if the focused frame has
4750 // reported matches, but no frames after the focused_frame contain a
4751 // match for the search word(s).
4752 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454753 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594754 request_id, search_text, options, true, // Force wrapping.
4755 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294756 }
4757 }
4758
[email protected]26aa0482009-09-30 16:55:274759 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294760 } while (!result && search_frame != focused_frame);
4761
[email protected]7830da3e2009-11-06 16:27:264762 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294763 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454764 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294765 } else {
4766 // If nothing is found, set result to "0 of 0", otherwise, set it to
4767 // "-1 of 1" to indicate that we found at least one item, but we don't know
4768 // yet what is active.
4769 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4770 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294771
[email protected]4f3dc372009-02-24 00:10:294772 // If we find no matches then this will be our last status update.
4773 // Otherwise the scoping effort will send more results.
4774 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294775
[email protected]55750b32012-09-21 14:05:034776 SendFindReply(request_id, match_count, ordinal, selection_rect,
4777 final_status_update);
initial.commit09911bf2008-07-26 23:55:294778
initial.commit09911bf2008-07-26 23:55:294779 // Scoping effort begins, starting with the mainframe.
4780 search_frame = main_frame;
4781
[email protected]dd7daa82009-08-10 05:46:454782 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294783
4784 do {
4785 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454786 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294787
4788 // We don't start another scoping effort unless at least one match has
4789 // been found.
4790 if (result) {
4791 // Start new scoping request. If the scoping function determines that it
4792 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454793 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594794 search_text,
4795 options,
initial.commit09911bf2008-07-26 23:55:294796 true); // reset the tickmarks
4797 }
4798
4799 // Iterate to the next frame. The frame will not necessarily scope, for
4800 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274801 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294802 } while (search_frame != main_frame);
4803 }
4804}
4805
[email protected]e9ff79c2012-10-19 21:31:264806void RenderViewImpl::OnStopFinding(StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:494807 WebView* view = webview();
4808 if (!view)
4809 return;
4810
4811 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:164812 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014813 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494814 return;
4815 }
4816
[email protected]e9ff79c2012-10-19 21:31:264817 bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]6dd17a8a2013-05-01 05:50:104818 if (clear_selection) {
4819 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
4820 GetFocusedNode());
4821 }
[email protected]24a7f3c2010-03-25 08:26:494822
4823 WebFrame* frame = view->mainFrame();
4824 while (frame) {
4825 frame->stopFinding(clear_selection);
4826 frame = frame->traverseNext(false);
4827 }
4828
[email protected]e9ff79c2012-10-19 21:31:264829 if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:494830 WebFrame* focused_frame = view->focusedFrame();
4831 if (focused_frame) {
4832 WebDocument doc = focused_frame->document();
4833 if (!doc.isNull()) {
4834 WebNode node = doc.focusedNode();
4835 if (!node.isNull())
4836 node.simulateClick();
4837 }
4838 }
4839 }
4840}
4841
[email protected]59363fc92012-09-05 03:46:314842#if defined(OS_ANDROID)
4843void RenderViewImpl::OnActivateNearestFindResult(int request_id,
4844 float x, float y) {
4845 if (!webview())
4846 return;
4847
4848 WebFrame* main_frame = webview()->mainFrame();
4849 WebRect selection_rect;
4850 int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y),
4851 &selection_rect);
4852 if (ordinal == -1) {
4853 // Something went wrong, so send a no-op reply (force the main_frame to
4854 // report the current match count) in case the host is waiting for a
4855 // response due to rate-limiting).
4856 main_frame->increaseMatchCount(0, request_id);
4857 return;
4858 }
4859
[email protected]55750b32012-09-21 14:05:034860 SendFindReply(request_id,
4861 -1 /* number_of_matches */,
4862 ordinal,
4863 selection_rect,
4864 true /* final_update */);
[email protected]59363fc92012-09-05 03:46:314865}
4866
4867void RenderViewImpl::OnFindMatchRects(int current_version) {
4868 if (!webview())
4869 return;
4870
4871 WebFrame* main_frame = webview()->mainFrame();
4872 std::vector<gfx::RectF> match_rects;
4873
4874 int rects_version = main_frame->findMatchMarkersVersion();
4875 if (current_version != rects_version) {
4876 WebVector<WebFloatRect> web_match_rects;
4877 main_frame->findMatchRects(web_match_rects);
4878 match_rects.reserve(web_match_rects.size());
4879 for (size_t i = 0; i < web_match_rects.size(); ++i)
4880 match_rects.push_back(gfx::RectF(web_match_rects[i]));
4881 }
4882
4883 gfx::RectF active_rect = main_frame->activeFindMatchRect();
4884 Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_,
4885 rects_version,
4886 match_rects,
4887 active_rect));
4888}
4889#endif
4890
[email protected]e9ff79c2012-10-19 21:31:264891void RenderViewImpl::OnZoom(PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:514892 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4893 return;
4894
[email protected]258d31122010-05-09 10:59:414895 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:104896
[email protected]b75b8292010-10-01 07:28:254897 double old_zoom_level = webview()->zoomLevel();
4898 double zoom_level;
[email protected]e9ff79c2012-10-19 21:31:264899 if (zoom == PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:254900 zoom_level = 0;
4901 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4902 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:484903 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:254904 } else {
4905 // Either the user hit the zoom factor limit and thus the zoom level is now
4906 // not a whole number, or a plugin changed it to a custom value. We want
4907 // to go to the next whole number so that the user can always get back to
4908 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:484909 if ((old_zoom_level > 1 && zoom > 0) ||
4910 (old_zoom_level < 1 && zoom < 0)) {
4911 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:254912 } else {
4913 // We're going towards 100%, so first go to the next whole number.
4914 zoom_level = static_cast<int>(old_zoom_level);
4915 }
4916 }
[email protected]91219702013-09-18 07:33:514917 webview()->setZoomLevel(zoom_level);
[email protected]47578fa02011-11-02 19:34:414918 zoomLevelChanged();
4919}
4920
[email protected]e9ff79c2012-10-19 21:31:264921void RenderViewImpl::OnZoomFactor(PageZoom zoom, int zoom_center_x,
4922 int zoom_center_y) {
[email protected]47578fa02011-11-02 19:34:414923 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
4924 kScalingIncrementForGesture);
4925}
4926
[email protected]e9ff79c2012-10-19 21:31:264927void RenderViewImpl::ZoomFactorHelper(PageZoom zoom,
[email protected]47578fa02011-11-02 19:34:414928 int zoom_center_x,
4929 int zoom_center_y,
4930 float scaling_increment) {
4931 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4932 return;
4933
[email protected]c514d6372011-08-16 22:54:444934 double old_page_scale_factor = webview()->pageScaleFactor();
4935 double page_scale_factor;
[email protected]e9ff79c2012-10-19 21:31:264936 if (zoom == PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:444937 page_scale_factor = 1.0;
4938 } else {
4939 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:414940 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:444941 }
[email protected]47578fa02011-11-02 19:34:414942 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:094943 webview()->setPageScaleFactor(page_scale_factor,
4944 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:414945 }
[email protected]40bd6582009-12-04 23:49:514946}
4947
[email protected]310ebd6302011-10-10 19:06:284948void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174949 webview()->hidePopups();
[email protected]91219702013-09-18 07:33:514950 webview()->setZoomLevel(zoom_level);
[email protected]d0b8d092010-10-25 04:05:174951 zoomLevelChanged();
4952}
4953
[email protected]310ebd6302011-10-10 19:06:284954void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4955 double zoom_level) {
[email protected]cbe55d22013-02-14 17:04:334956#if !defined(OS_ANDROID)
4957 // On Android, page zoom isn't used, and in case of WebView, text zoom is used
4958 // for legacy WebView text scaling emulation. Thus, the code that resets
4959 // the zoom level from this map will be effectively resetting text zoom level.
[email protected]9d797f32010-04-23 07:17:544960 host_zoom_levels_[url] = zoom_level;
[email protected]cbe55d22013-02-14 17:04:334961#endif
initial.commit09911bf2008-07-26 23:55:294962}
4963
[email protected]310ebd6302011-10-10 19:06:284964void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274965 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294966}
4967
[email protected]310ebd6302011-10-10 19:06:284968void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274969 WebString no_encoding;
4970 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184971}
4972
[email protected]310ebd6302011-10-10 19:06:284973WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454974 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274975 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454976
4977 // xpath string can represent a frame deep down the tree (across multiple
4978 // frame DOMs).
4979 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4980 // should break into 2 xpaths
4981 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:414982 std::vector<string16> xpaths;
4983 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:454984
[email protected]26aa0482009-09-30 16:55:274985 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:414986 for (std::vector<string16>::const_iterator i = xpaths.begin();
4987 frame && i != xpaths.end(); ++i) {
4988 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294989 }
4990
[email protected]dd7daa82009-08-10 05:46:454991 return frame;
initial.commit09911bf2008-07-26 23:55:294992}
4993
[email protected]310ebd6302011-10-10 19:06:284994void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4995 const string16& jscript,
4996 int id,
4997 bool notify_result) {
[email protected]c76faea2013-03-26 07:42:424998 TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest",
4999 TRACE_EVENT_SCOPE_THREAD);
[email protected]882b7b22010-10-05 03:34:535000 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:295001}
5002
[email protected]f546640b2012-05-15 00:03:495003void RenderViewImpl::OnPostMessageEvent(
5004 const ViewMsg_PostMessage_Params& params) {
[email protected]bf4a2312013-04-23 00:32:115005 // TODO(nasko): Support sending to subframes.
[email protected]e12dbe6f2012-10-04 22:11:195006 WebFrame* frame = webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:495007
5008 // Find the source frame if it exists.
[email protected]f546640b2012-05-15 00:03:495009 WebFrame* source_frame = NULL;
5010 if (params.source_routing_id != MSG_ROUTING_NONE) {
5011 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
5012 if (source_view)
[email protected]e12dbe6f2012-10-04 22:11:195013 source_frame = source_view->webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:495014 }
5015
[email protected]0bc7f3542013-10-21 15:05:535016 // If the message contained MessagePorts, create the corresponding endpoints.
5017 DCHECK_EQ(params.message_port_ids.size(), params.new_routing_ids.size());
[email protected]180ef242013-11-07 06:50:465018 blink::WebMessagePortChannelArray channels(params.message_port_ids.size());
[email protected]0bc7f3542013-10-21 15:05:535019 for (size_t i = 0;
5020 i < params.message_port_ids.size() && i < params.new_routing_ids.size();
5021 ++i) {
5022 channels[i] =
5023 new WebMessagePortChannelImpl(params.new_routing_ids[i],
5024 params.message_port_ids[i],
5025 base::MessageLoopProxy::current().get());
5026 }
5027
[email protected]f546640b2012-05-15 00:03:495028 // Create an event with the message. The final parameter to initMessageEvent
5029 // is the last event ID, which is not used with postMessage.
5030 WebDOMEvent event = frame->document().createEvent("MessageEvent");
5031 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
5032 msg_event.initMessageEvent("message",
5033 // |canBubble| and |cancellable| are always false
5034 false, false,
5035 WebSerializedScriptValue::fromString(params.data),
[email protected]0bc7f3542013-10-21 15:05:535036 params.source_origin, source_frame, "", channels);
[email protected]f546640b2012-05-15 00:03:495037
5038 // We must pass in the target_origin to do the security check on this side,
5039 // since it may have changed since the original postMessage call was made.
5040 WebSecurityOrigin target_origin;
5041 if (!params.target_origin.empty()) {
5042 target_origin =
5043 WebSecurityOrigin::createFromString(WebString(params.target_origin));
5044 }
5045 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
5046}
5047
[email protected]310ebd6302011-10-10 19:06:285048void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
5049 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:415050 WebFrame* frame = GetChildFrame(frame_xpath);
5051 if (!frame)
[email protected]216813952011-05-19 22:21:265052 return;
[email protected]ae461542009-06-19 19:03:415053
[email protected]01cf589c2011-07-28 18:04:035054 frame->document().insertUserStyleSheet(
5055 WebString::fromUTF8(css),
5056 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:485057}
5058
[email protected]310ebd6302011-10-10 19:06:285059void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]940ed1d2012-11-27 21:03:215060 if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) &&
5061 !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) {
[email protected]91f05762013-08-21 02:55:095062 // WebUI uses <dialog> which is not yet enabled by default in Chrome.
5063 WebRuntimeFeatures::enableDialogElement(true);
5064
[email protected]dcc72db2013-01-02 00:44:185065 RenderThread::Get()->RegisterExtension(WebUIExtension::Get());
[email protected]940ed1d2012-11-27 21:03:215066 new WebUIExtensionData(this);
5067 }
5068
[email protected]81e63782009-02-27 19:35:095069 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:045070
5071 // Keep track of the total bindings accumulated in this process.
5072 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:295073}
5074
[email protected]dc293a72013-07-01 11:11:225075void RenderViewImpl::OnDragTargetDragEnter(const DropData& drop_data,
[email protected]310ebd6302011-10-10 19:06:285076 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()->dragTargetDragEnter(
[email protected]dc293a72013-07-01 11:11:225081 DropDataToWebDragData(drop_data),
[email protected]59f4f2fa2011-03-23 01:00:555082 client_point,
5083 screen_point,
[email protected]1f2230b2012-05-17 23:43:425084 ops,
5085 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555086
5087 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5088}
5089
[email protected]310ebd6302011-10-10 19:06:285090void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
5091 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:425092 WebDragOperationsMask ops,
5093 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:555094 WebDragOperation operation = webview()->dragTargetDragOver(
5095 client_point,
5096 screen_point,
[email protected]1f2230b2012-05-17 23:43:425097 ops,
5098 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555099
5100 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5101}
5102
[email protected]310ebd6302011-10-10 19:06:285103void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:555104 webview()->dragTargetDragLeave();
5105}
5106
[email protected]310ebd6302011-10-10 19:06:285107void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
[email protected]1f2230b2012-05-17 23:43:425108 const gfx::Point& screen_point,
5109 int key_modifiers) {
5110 webview()->dragTargetDrop(client_point, screen_point, key_modifiers);
[email protected]fcad49452011-06-28 17:11:575111
5112 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:555113}
5114
[email protected]310ebd6302011-10-10 19:06:285115void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
5116 const gfx::Point& screen_point,
5117 bool ended,
5118 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:035119 if (ended) {
[email protected]26aa0482009-09-30 16:55:275120 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:205121 } else {
5122 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:035123 }
initial.commit09911bf2008-07-26 23:55:295124}
5125
[email protected]310ebd6302011-10-10 19:06:285126void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:275127 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:295128}
5129
[email protected]310ebd6302011-10-10 19:06:285130void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:595131 webkit_preferences_ = prefs;
[email protected]49a20002013-08-18 12:43:315132 ApplyWebPreferences(webkit_preferences_, webview());
initial.commit09911bf2008-07-26 23:55:295133}
5134
[email protected]38761452012-10-18 16:31:595135void RenderViewImpl::OnUpdateTimezone() {
5136 if (webview())
5137 NotifyTimezoneChange(webview()->mainFrame());
5138}
5139
[email protected]310ebd6302011-10-10 19:06:285140void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:295141 alternate_error_page_url_ = url;
5142}
5143
[email protected]310ebd6302011-10-10 19:06:285144void RenderViewImpl::OnCustomContextMenuAction(
[email protected]e9ff79c2012-10-19 21:31:265145 const CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:085146 unsigned action) {
[email protected]860ee642012-10-13 03:46:255147 if (custom_context.request_id) {
5148 // External context menu request, look in our map.
[email protected]e9ff79c2012-10-19 21:31:265149 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:255150 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:465151 if (client)
5152 client->OnMenuAction(custom_context.request_id, action);
[email protected]860ee642012-10-13 03:46:255153 } else {
5154 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:085155 webview()->performCustomContextMenuAction(action);
[email protected]860ee642012-10-13 03:46:255156 }
[email protected]a0c7153e2009-12-09 14:36:335157}
5158
[email protected]310ebd6302011-10-10 19:06:285159void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:515160 int id,
[email protected]c42de732013-02-16 06:26:315161 const std::vector<base::FilePath>& paths) {
[email protected]600ea402011-04-12 00:01:515162 if (!enumeration_completions_[id])
5163 return;
5164
5165 WebVector<WebString> ws_file_names(paths.size());
5166 for (size_t i = 0; i < paths.size(); ++i)
[email protected]728c2ee2013-06-25 04:01:075167 ws_file_names[i] = paths[i].AsUTF16Unsafe();
[email protected]600ea402011-04-12 00:01:515168
5169 enumeration_completions_[id]->didChooseFile(ws_file_names);
5170 enumeration_completions_.erase(id);
5171}
5172
[email protected]fb11b6a42012-03-14 07:25:125173void RenderViewImpl::OnFileChooserResponse(
[email protected]ddb034b2012-06-26 20:31:395174 const std::vector<ui::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:365175 // This could happen if we navigated to a different page before the user
5176 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:475177 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:365178 return;
5179
[email protected]b5188522012-03-15 00:18:045180 // Convert Chrome's SelectedFileInfo list to WebKit's.
5181 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
5182 files.size());
5183 for (size_t i = 0; i < files.size(); ++i) {
5184 WebFileChooserCompletion::SelectedFileInfo selected_file;
[email protected]728c2ee2013-06-25 04:01:075185 selected_file.path = files[i].local_path.AsUTF16Unsafe();
5186 selected_file.displayName =
5187 base::FilePath(files[i].display_name).AsUTF16Unsafe();
[email protected]b5188522012-03-15 00:18:045188 selected_files[i] = selected_file;
5189 }
[email protected]a1128322009-10-06 18:38:465190
[email protected]cdaf8d02010-03-30 19:52:475191 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:045192 file_chooser_completions_.front()->completion->didChooseFile(
5193 selected_files);
[email protected]cdaf8d02010-03-30 19:52:475194 file_chooser_completions_.pop_front();
5195
5196 // If there are more pending file chooser requests, schedule one now.
5197 if (!file_chooser_completions_.empty()) {
5198 Send(new ViewHostMsg_RunFileChooser(routing_id_,
5199 file_chooser_completions_.front()->params));
5200 }
initial.commit09911bf2008-07-26 23:55:295201}
5202
[email protected]244ac1892011-12-02 17:04:475203void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
5204 const gfx::Size& max_size) {
5205 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5206 if (!webview())
5207 return;
[email protected]97e1bf72013-03-06 14:06:055208 auto_resize_mode_ = true;
[email protected]61e2b3cc2012-03-02 16:13:345209 webview()->enableAutoResizeMode(min_size, max_size);
5210}
5211
5212void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
5213 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5214 if (!webview())
5215 return;
[email protected]97e1bf72013-03-06 14:06:055216 auto_resize_mode_ = false;
[email protected]61e2b3cc2012-03-02 16:13:345217 webview()->disableAutoResizeMode();
5218
[email protected]eac2b362013-05-22 07:01:455219 if (!new_size.IsEmpty()) {
5220 Resize(new_size,
5221 physical_backing_size_,
5222 overdraw_bottom_height_,
5223 resizer_rect_,
5224 is_fullscreen_,
5225 NO_RESIZE_ACK);
5226 }
[email protected]244ac1892011-12-02 17:04:475227}
5228
[email protected]2bf834f2011-11-17 20:02:215229void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:245230 if (send_preferred_size_changes_)
5231 return;
[email protected]9fb325e2010-05-06 18:23:245232 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:395233
[email protected]d812fd12011-05-27 23:05:075234 // Start off with an initial preferred size notification (in case
5235 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:595236 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:085237}
5238
[email protected]310ebd6302011-10-10 19:06:285239void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:105240 const gfx::Size& disable_scrollbar_size_limit) {
5241 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
5242}
5243
[email protected]310ebd6302011-10-10 19:06:285244void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:265245 const RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:505246 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:515247 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:375248 UpdateFontRenderingFromRendererPrefs();
[email protected]38a85712013-01-02 22:45:025249
5250#if defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK)
[email protected]1596efb2013-01-17 22:13:015251 if (renderer_prefs.use_custom_colors) {
[email protected]180ef242013-11-07 06:50:465252 WebColorName name = blink::WebColorWebkitFocusRingColor;
5253 blink::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
5254 blink::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]38a85712013-01-02 22:45:025255#if defined(TOOLKIT_GTK)
[email protected]1596efb2013-01-17 22:13:015256 ui::NativeTheme::instance()->SetScrollbarColors(
[email protected]93623c5d2009-12-10 21:40:325257 renderer_prefs.thumb_inactive_color,
5258 renderer_prefs.thumb_active_color,
5259 renderer_prefs.track_color);
[email protected]38a85712013-01-02 22:45:025260#endif // defined(TOOLKIT_GTK)
[email protected]1596efb2013-01-17 22:13:015261
5262 if (webview()) {
[email protected]1596efb2013-01-17 22:13:015263 webview()->setSelectionColors(
5264 renderer_prefs.active_selection_bg_color,
5265 renderer_prefs.active_selection_fg_color,
5266 renderer_prefs.inactive_selection_bg_color,
5267 renderer_prefs.inactive_selection_fg_color);
5268 webview()->themeChanged();
5269 }
[email protected]644d77e2010-01-27 01:03:105270 }
[email protected]38a85712013-01-02 22:45:025271#endif // defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK)
[email protected]d299d972012-03-23 02:26:555272
[email protected]107c0532013-02-06 02:34:095273 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
5274 RenderThreadImpl::current()->SetFlingCurveParameters(
5275 renderer_prefs.touchpad_fling_profile,
5276 renderer_prefs.touchscreen_fling_profile);
5277
[email protected]d051d9a2011-12-10 02:02:505278 // If the zoom level for this page matches the old zoom default, and this
5279 // is not a plugin, update the zoom level to match the new default.
5280 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
[email protected]cbe55d22013-02-14 17:04:335281 !ZoomValuesEqual(old_zoom_level,
5282 renderer_preferences_.default_zoom_level) &&
[email protected]e9ff79c2012-10-19 21:31:265283 ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
[email protected]91219702013-09-18 07:33:515284 webview()->setZoomLevel(renderer_preferences_.default_zoom_level);
[email protected]d051d9a2011-12-10 02:02:505285 zoomLevelChanged();
5286 }
[email protected]80d96fa2009-06-10 22:34:515287}
5288
[email protected]310ebd6302011-10-10 19:06:285289void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
5290 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:285291 if (webview())
5292 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:565293}
5294
[email protected]77829642012-05-15 14:47:175295void RenderViewImpl::OnOrientationChangeEvent(int orientation) {
[email protected]a794f3a2013-10-30 17:00:325296 // Screen has rotated. 0 = default (portrait), 90 = one turn right, and so on.
[email protected]652ad832013-08-16 11:47:045297 FOR_EACH_OBSERVER(RenderViewObserver,
5298 observers_,
5299 OrientationChangeEvent(orientation));
[email protected]77829642012-05-15 14:47:175300 webview()->mainFrame()->sendOrientationChangeEvent(orientation);
5301}
5302
[email protected]81375e872012-01-11 21:40:365303void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
5304 const WebPluginAction& action) {
5305 if (webview())
5306 webview()->performPluginAction(action, location);
5307}
5308
[email protected]310ebd6302011-10-10 19:06:285309void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:195310 const GURL& page_url) {
5311 // Prepare list to storage all savable resource links.
5312 std::vector<GURL> resources_list;
[email protected]c2d986512012-05-12 00:22:465313 std::vector<GURL> referrer_urls_list;
[email protected]180ef242013-11-07 06:50:465314 std::vector<blink::WebReferrerPolicy> referrer_policies_list;
[email protected]18d5be92011-07-25 18:00:195315 std::vector<GURL> frames_list;
[email protected]12a936d2013-05-15 04:55:495316 SavableResourcesResult result(&resources_list,
5317 &referrer_urls_list,
5318 &referrer_policies_list,
5319 &frames_list);
[email protected]18d5be92011-07-25 18:00:195320
[email protected]e9ff79c2012-10-19 21:31:265321 // webkit/ doesn't know about Referrer.
[email protected]12a936d2013-05-15 04:55:495322 if (!GetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:195323 webview(),
5324 page_url,
5325 &result,
[email protected]e9ff79c2012-10-19 21:31:265326 const_cast<const char**>(GetSavableSchemes()))) {
[email protected]18d5be92011-07-25 18:00:195327 // If something is wrong when collecting all savable resource links,
5328 // send empty list to embedder(browser) to tell it failed.
[email protected]c2d986512012-05-12 00:22:465329 referrer_urls_list.clear();
5330 referrer_policies_list.clear();
[email protected]18d5be92011-07-25 18:00:195331 resources_list.clear();
5332 frames_list.clear();
5333 }
5334
[email protected]e9ff79c2012-10-19 21:31:265335 std::vector<Referrer> referrers_list;
[email protected]c2d986512012-05-12 00:22:465336 CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size());
5337 for (unsigned i = 0; i < referrer_urls_list.size(); ++i) {
5338 referrers_list.push_back(
[email protected]e9ff79c2012-10-19 21:31:265339 Referrer(referrer_urls_list[i], referrer_policies_list[i]));
[email protected]c2d986512012-05-12 00:22:465340 }
5341
[email protected]18d5be92011-07-25 18:00:195342 // Send result of all savable resource links to embedder.
5343 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
5344 resources_list,
5345 referrers_list,
5346 frames_list));
5347}
5348
[email protected]310ebd6302011-10-10 19:06:285349void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:195350 const std::vector<GURL>& links,
[email protected]c42de732013-02-16 06:26:315351 const std::vector<base::FilePath>& local_paths,
5352 const base::FilePath& local_directory_name) {
[email protected]18d5be92011-07-25 18:00:195353
5354 // Convert std::vector of GURLs to WebVector<WebURL>
5355 WebVector<WebURL> weburl_links(links);
5356
[email protected]728c2ee2013-06-25 04:01:075357 // Convert std::vector of base::FilePath to WebVector<WebString>
[email protected]18d5be92011-07-25 18:00:195358 WebVector<WebString> webstring_paths(local_paths.size());
5359 for (size_t i = 0; i < local_paths.size(); i++)
[email protected]728c2ee2013-06-25 04:01:075360 webstring_paths[i] = local_paths[i].AsUTF16Unsafe();
[email protected]18d5be92011-07-25 18:00:195361
5362 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
5363 webstring_paths,
[email protected]728c2ee2013-06-25 04:01:075364 local_directory_name.AsUTF16Unsafe());
[email protected]18d5be92011-07-25 18:00:195365}
5366
[email protected]310ebd6302011-10-10 19:06:285367void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:125368 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:275369 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:125370 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
5371 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
5372 before_unload_start_time,
5373 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:295374}
5375
[email protected]88f10a22013-11-06 21:22:125376void RenderViewImpl::OnSuppressDialogsUntilSwapOut() {
5377 // Don't show any more dialogs until we finish OnSwapOut.
5378 suppress_dialogs_until_swap_out_ = true;
5379}
5380
[email protected]e1986832013-06-14 07:27:285381void RenderViewImpl::OnSwapOut() {
[email protected]73eb2602012-02-09 19:50:555382 // Only run unload if we're not swapped out yet, but send the ack either way.
5383 if (!is_swapped_out_) {
5384 // Swap this RenderView out so the tab can navigate to a page rendered by a
5385 // different process. This involves running the unload handler and clearing
5386 // the page. Once WasSwappedOut is called, we also allow this process to
5387 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:155388
[email protected]73eb2602012-02-09 19:50:555389 // Send an UpdateState message before we get swapped out.
5390 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:155391
[email protected]73eb2602012-02-09 19:50:555392 // Synchronously run the unload handler before sending the ACK.
5393 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:155394
[email protected]73eb2602012-02-09 19:50:555395 // Swap out and stop sending any IPC messages that are not ACKs.
5396 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:155397
[email protected]6169a5772013-05-29 17:41:145398 // Now that we're swapped out and filtering IPC messages, stop loading to
5399 // ensure that no other in-progress navigation continues. We do this here
5400 // to avoid sending a DidStopLoading message to the browser process.
5401 OnStop();
5402
[email protected]285f4bb82012-04-17 15:57:285403 // Replace the page with a blank dummy URL. The unload handler will not be
[email protected]73eb2602012-02-09 19:50:555404 // run a second time, thanks to a check in FrameLoader::stopLoading.
5405 // TODO(creis): Need to add a better way to do this that avoids running the
[email protected]285f4bb82012-04-17 15:57:285406 // beforeunload handler. For now, we just run it a second time silently.
[email protected]0720b532012-08-28 19:23:375407 NavigateToSwappedOutURL(webview()->mainFrame());
[email protected]961541a92012-06-01 21:15:285408
5409 // Let WebKit know that this view is hidden so it can drop resources and
5410 // stop compositing.
[email protected]180ef242013-11-07 06:50:465411 webview()->setVisibilityState(blink::WebPageVisibilityStateHidden, false);
[email protected]73eb2602012-02-09 19:50:555412 }
[email protected]992db4c2011-05-12 15:37:155413
[email protected]88f10a22013-11-06 21:22:125414 // It is now safe to show modal dialogs again.
5415 suppress_dialogs_until_swap_out_ = false;
5416
[email protected]e1986832013-06-14 07:27:285417 Send(new ViewHostMsg_SwapOut_ACK(routing_id_));
[email protected]992db4c2011-05-12 15:37:155418}
5419
[email protected]180ef242013-11-07 06:50:465420void RenderViewImpl::NavigateToSwappedOutURL(blink::WebFrame* frame) {
[email protected]14392a52012-05-02 20:28:445421 // We use loadRequest instead of loadHTMLString because the former commits
5422 // synchronously. Otherwise a new navigation can interrupt the navigation
[email protected]e9ff79c2012-10-19 21:31:265423 // to kSwappedOutURL. If that happens to be to the page we had been
[email protected]14392a52012-05-02 20:28:445424 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]890b06ca2012-12-13 21:07:365425 CHECK(is_swapped_out_);
[email protected]e9ff79c2012-10-19 21:31:265426 GURL swappedOutURL(kSwappedOutURL);
[email protected]14392a52012-05-02 20:28:445427 WebURLRequest request(swappedOutURL);
[email protected]0720b532012-08-28 19:23:375428 frame->loadRequest(request);
[email protected]14392a52012-05-02 20:28:445429}
5430
[email protected]310ebd6302011-10-10 19:06:285431void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:375432 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:295433 // TODO(creis): We'd rather use webview()->Close() here, but that currently
5434 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
5435 // in the onunload handler from appearing. For now, we're bypassing that and
5436 // calling the FrameLoader's CloseURL method directly. This should be
5437 // revisited to avoid having two ways to close a page. Having a single way
5438 // to close that can run onunload is also useful for fixing
5439 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:275440 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:295441
[email protected]992db4c2011-05-12 15:37:155442 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:295443}
5444
[email protected]310ebd6302011-10-10 19:06:285445void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:025446#if defined(USE_AURA)
5447 // Aura doesn't care if we switch themes.
5448#elif defined(OS_WIN)
[email protected]f78452f2012-05-15 02:07:525449 ui::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:465450 if (webview())
5451 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:575452#else // defined(OS_WIN)
5453 // TODO(port): we don't support theming on non-Windows platforms yet
5454 NOTIMPLEMENTED();
5455#endif
initial.commit09911bf2008-07-26 23:55:295456}
5457
[email protected]310ebd6302011-10-10 19:06:285458bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
5459 const WebURLError& error,
5460 bool replace) {
[email protected]15d79e12009-08-02 19:23:455461 // We only show alternate error pages in the main frame. They are
5462 // intended to assist the user when navigating, so there is not much
5463 // value in showing them for failed subframes. Ideally, we would be
5464 // able to use the TYPED transition type for this, but that flag is
5465 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455466 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455467 return false;
5468
5469 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375470 // connection failure.
[email protected]15d79e12009-08-02 19:23:455471 int ec = error.reason;
5472 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5473 ec != net::ERR_CONNECTION_FAILED &&
5474 ec != net::ERR_CONNECTION_REFUSED &&
5475 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]82114f52012-03-20 22:53:415476 ec != net::ERR_CONNECTION_TIMED_OUT) {
[email protected]15d79e12009-08-02 19:23:455477 return false;
[email protected]82114f52012-03-20 22:53:415478 }
[email protected]15d79e12009-08-02 19:23:455479
5480 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555481 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455482 if (!error_page_url.is_valid())
5483 return false;
5484
[email protected]11a65772013-04-27 00:36:425485 WebDataSource* ds = frame->provisionalDataSource();
5486 const WebURLRequest& failed_request = ds->request();
5487
[email protected]15d79e12009-08-02 19:23:455488 // Load an empty page first so there is an immediate response to the error,
5489 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455490 frame->loadHTMLString(std::string(),
[email protected]e9ff79c2012-10-19 21:31:265491 GURL(kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455492 error.unreachableURL,
5493 replace);
5494
5495 // Now, create a fetcher for the error page and associate it with the data
5496 // source we just created via the LoadHTMLString call. That way if another
5497 // navigation occurs, the fetcher will get destroyed.
[email protected]e20b88d2013-04-09 15:28:375498 InternalDocumentStateData* internal_data =
5499 InternalDocumentStateData::FromDataSource(frame->provisionalDataSource());
5500 internal_data->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:455501 new AltErrorPageResourceFetcher(
[email protected]11a65772013-04-27 00:36:425502 error_page_url, frame, failed_request, error,
[email protected]6e806822011-11-19 01:51:085503 base::Bind(&RenderViewImpl::AltErrorPageFinished,
5504 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:455505 return true;
5506}
5507
[email protected]310ebd6302011-10-10 19:06:285508void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
[email protected]11a65772013-04-27 00:36:425509 const WebURLRequest& original_request,
[email protected]310ebd6302011-10-10 19:06:285510 const WebURLError& original_error,
5511 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:455512 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:095513 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:555514 // will simply display a default error page.
[email protected]11a65772013-04-27 00:36:425515 LoadNavigationErrorPage(frame, original_request, original_error, html, true);
[email protected]15d79e12009-08-02 19:23:455516}
5517
[email protected]310ebd6302011-10-10 19:06:285518void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:005519 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475520 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005521}
5522
[email protected]0fdd5012013-05-29 08:05:565523void RenderViewImpl::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]cda45c02010-02-25 19:28:105524 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475525 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105526 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205527 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]0fdd5012013-05-29 08:05:565528 ShouldDisplayScrollbars(params.new_size.width(),
5529 params.new_size.height()));
[email protected]cda45c02010-02-25 19:28:105530 }
[email protected]dd6afca2011-08-13 03:44:315531 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:105532 }
5533
[email protected]0fdd5012013-05-29 08:05:565534 RenderWidget::OnResize(params);
[email protected]30f75e62009-02-25 22:01:005535}
[email protected]0aa477bd2009-03-23 22:21:435536
[email protected]310ebd6302011-10-10 19:06:285537void RenderViewImpl::DidInitiatePaint() {
[email protected]ea2fb972013-08-07 05:44:265538#if defined(ENABLE_PLUGINS)
5539 // Notify all instances that we painted. The same caveats apply as for
5540 // ViewFlushedPaint regarding instances closing themselves, so we take
5541 // similar precautions.
5542 PepperPluginSet plugins = active_pepper_instances_;
5543 for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) {
5544 if (active_pepper_instances_.find(*i) != active_pepper_instances_.end())
5545 (*i)->ViewInitiatedPaint();
5546 }
5547#endif
[email protected]00c39612010-03-06 02:53:285548}
5549
[email protected]310ebd6302011-10-10 19:06:285550void RenderViewImpl::DidFlushPaint() {
[email protected]ea2fb972013-08-07 05:44:265551#if defined(ENABLE_PLUGINS)
5552 // Notify all instances that we flushed. This will call into the plugin, and
5553 // we it may ask to close itself as a result. This will, in turn, modify our
5554 // set, possibly invalidating the iterator. So we iterate on a copy that
[email protected]00c39612010-03-06 02:53:285555 // won't change out from under us.
[email protected]ea2fb972013-08-07 05:44:265556 PepperPluginSet plugins = active_pepper_instances_;
5557 for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) {
5558 // The copy above makes sure our iterator is never invalid if some plugins
5559 // are destroyed. But some plugin may decide to close all of its views in
5560 // response to a paint in one of them, so we need to make sure each one is
5561 // still "current" before using it.
5562 //
5563 // It's possible that a plugin was destroyed, but another one was created
5564 // with the same address. In this case, we'll call ViewFlushedPaint on that
5565 // new plugin. But that's OK for this particular case since we're just
5566 // notifying all of our instances that the view flushed, and the new one is
5567 // one of our instances.
5568 //
5569 // What about the case where a new one is created in a callback at a new
5570 // address and we don't issue the callback? We're still OK since this
5571 // callback is used for flush callbacks and we could not have possibly
[email protected]0704ac32013-10-03 15:24:225572 // started a new paint for the new plugin while processing a previous paint
5573 // for an existing one.
[email protected]ea2fb972013-08-07 05:44:265574 if (active_pepper_instances_.find(*i) != active_pepper_instances_.end())
5575 (*i)->ViewFlushedPaint();
5576 }
5577#endif
[email protected]53900d52010-06-16 04:25:015578
[email protected]5b1dec8c2012-02-07 04:35:385579 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
5580 // See crbug.com/112921.
5581 if (!webview())
5582 return;
5583
[email protected]00c39612010-03-06 02:53:285584 WebFrame* main_frame = webview()->mainFrame();
5585
5586 // If we have a provisional frame we are between the start and commit stages
5587 // of loading and we don't want to save stats.
5588 if (!main_frame->provisionalDataSource()) {
5589 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:075590 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]92d457802013-04-01 19:18:495591 InternalDocumentStateData* data =
[email protected]e20b88d2013-04-09 15:28:375592 InternalDocumentStateData::FromDocumentState(document_state);
[email protected]92d457802013-04-01 19:18:495593 if (data->did_first_visually_non_empty_layout() &&
5594 !data->did_first_visually_non_empty_paint()) {
5595 data->set_did_first_visually_non_empty_paint(true);
5596 Send(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_,
5597 page_id_));
5598 }
5599
[email protected]05c8e502010-08-15 15:13:525600 // TODO(jar): The following code should all be inside a method, probably in
5601 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285602 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:075603 if (document_state->first_paint_time().is_null()) {
5604 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:285605 }
[email protected]007733c2011-11-17 00:34:075606 if (document_state->first_paint_after_load_time().is_null() &&
5607 !document_state->finish_load_time().is_null()) {
5608 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:285609 }
5610 }
5611}
5612
[email protected]adab2332013-07-25 18:04:325613PepperPluginInstanceImpl* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
5614 const gfx::Rect& paint_bounds,
5615 TransportDIB** dib,
5616 gfx::Rect* location,
5617 gfx::Rect* clip,
5618 float* scale_factor) {
[email protected]ea2fb972013-08-07 05:44:265619#if defined(ENABLE_PLUGINS)
5620 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
5621 i != active_pepper_instances_.end(); ++i) {
5622 PepperPluginInstanceImpl* instance = *i;
5623 // In Flash fullscreen , the plugin contents should be painted onto the
5624 // fullscreen widget instead of the web page.
5625 if (!instance->FlashIsFullscreenOrPending() &&
5626 instance->GetBitmapForOptimizedPluginPaint(paint_bounds, dib, location,
5627 clip, scale_factor))
5628 return *i;
5629 }
5630#endif
5631 return NULL;
[email protected]ca4847f2010-09-24 05:39:155632}
5633
[email protected]ceb36f7d2012-10-31 18:33:245634gfx::Vector2d RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:075635 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]ceb36f7d2012-10-31 18:33:245636 return gfx::Vector2d(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:525637}
5638
[email protected]310ebd6302011-10-10 19:06:285639void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:165640 if (webview())
[email protected]26aa0482009-09-30 16:55:275641 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165642}
5643
[email protected]310ebd6302011-10-10 19:06:285644void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:145645 if (webview())
[email protected]b4bb2502009-10-01 22:35:275646 webview()->setIsTransparent(!background.empty());
[email protected]ba91a792013-02-06 09:48:285647 if (compositor_)
5648 compositor_->setHasTransparentBackground(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145649
5650 SetBackground(background);
5651}
5652
[email protected]2a84f9d2012-06-05 21:50:435653void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) {
5654 if (accessibility_mode_ == new_mode)
5655 return;
5656 accessibility_mode_ = new_mode;
5657 if (renderer_accessibility_) {
5658 delete renderer_accessibility_;
5659 renderer_accessibility_ = NULL;
5660 }
5661 if (accessibility_mode_ == AccessibilityModeComplete)
5662 renderer_accessibility_ = new RendererAccessibilityComplete(this);
[email protected]8d3dfee62013-06-19 05:50:335663#if !defined(OS_ANDROID)
[email protected]2a84f9d2012-06-05 21:50:435664 else if (accessibility_mode_ == AccessibilityModeEditableTextOnly)
5665 renderer_accessibility_ = new RendererAccessibilityFocusOnly(this);
[email protected]8d3dfee62013-06-19 05:50:335666#endif
[email protected]2a84f9d2012-06-05 21:50:435667}
5668
[email protected]310ebd6302011-10-10 19:06:285669void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:345670 if (webview())
[email protected]b4bb2502009-10-01 22:35:275671 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265672
[email protected]a80af12e2013-08-07 23:36:135673#if defined(ENABLE_PLUGINS) && defined(OS_MACOSX)
[email protected]d8fd6fa2010-02-01 15:54:265674 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5675 for (plugin_it = plugin_delegates_.begin();
5676 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5677 (*plugin_it)->SetWindowFocus(active);
5678 }
5679#endif
[email protected]8c66c5a2009-07-22 17:26:345680}
5681
[email protected]6ce7abc52010-02-02 18:40:145682#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285683void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]a80af12e2013-08-07 23:36:135684#if defined(ENABLE_PLUGINS)
[email protected]6ce7abc52010-02-02 18:40:145685 // Inform plugins that their container has changed visibility.
5686 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5687 for (plugin_it = plugin_delegates_.begin();
5688 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5689 (*plugin_it)->SetContainerVisibility(visible);
5690 }
[email protected]a80af12e2013-08-07 23:36:135691#endif
[email protected]6ce7abc52010-02-02 18:40:145692}
[email protected]1e6e3c992010-02-08 15:52:135693
[email protected]310ebd6302011-10-10 19:06:285694void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
5695 const gfx::Rect& view_frame) {
[email protected]a80af12e2013-08-07 23:36:135696#if defined(ENABLE_PLUGINS)
[email protected]1e6e3c992010-02-08 15:52:135697 // Inform plugins that their window's frame has changed.
5698 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5699 for (plugin_it = plugin_delegates_.begin();
5700 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5701 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5702 }
[email protected]a80af12e2013-08-07 23:36:135703#endif
[email protected]1e6e3c992010-02-08 15:52:135704}
[email protected]935d63d2010-10-15 23:31:555705
[email protected]310ebd6302011-10-10 19:06:285706void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
5707 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135708 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555709 // applies to it or not, so inform all the delegates.
5710 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5711 for (plugin_it = plugin_delegates_.begin();
5712 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135713 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555714 }
5715}
[email protected]6ce7abc52010-02-02 18:40:145716#endif // OS_MACOSX
5717
[email protected]310ebd6302011-10-10 19:06:285718void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:595719 // We need to grab a pointer to the doomed WebView before we destroy it.
5720 WebView* doomed = webview();
5721 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495722 g_view_map.Get().erase(doomed);
[email protected]058561b2012-12-03 06:48:225723 g_routing_id_view_map.Get().erase(routing_id_);
[email protected]60c42a8c72009-10-09 04:08:595724}
5725
[email protected]310ebd6302011-10-10 19:06:285726void RenderViewImpl::DidHandleKeyEvent() {
[email protected]b2324b092012-11-01 10:34:115727 ClearEditCommands();
[email protected]446705872009-09-10 07:22:485728}
5729
[email protected]180ef242013-11-07 06:50:465730bool RenderViewImpl::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]a14ddcd2013-06-21 22:53:035731 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]41d86852012-11-07 12:23:245732 possible_drag_event_info_.event_source =
5733 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
5734 possible_drag_event_info_.event_location =
5735 gfx::Point(event.globalX, event.globalY);
[email protected]ea2fb972013-08-07 05:44:265736
5737#if defined(ENABLE_PLUGINS)
5738 // This method is called for every mouse event that the render view receives.
5739 // And then the mouse event is forwarded to WebKit, which dispatches it to the
5740 // event target. Potentially a Pepper plugin will receive the event.
5741 // In order to tell whether a plugin gets the last mouse event and which it
5742 // is, we set |pepper_last_mouse_event_target_| to NULL here. If a plugin gets
5743 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
5744 // |pepper_last_mouse_event_target_|.
5745 pepper_last_mouse_event_target_ = NULL;
5746#endif
[email protected]217690d2012-01-27 07:33:115747
5748 // If the mouse is locked, only the current owner of the mouse lock can
5749 // process mouse events.
5750 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:375751}
5752
[email protected]180ef242013-11-07 06:50:465753bool RenderViewImpl::WillHandleKeyEvent(const blink::WebKeyboardEvent& event) {
[email protected]a14ddcd2013-06-21 22:53:035754 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]f56c7872013-06-18 12:31:575755 return false;
5756}
5757
[email protected]41d86852012-11-07 12:23:245758bool RenderViewImpl::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:465759 const blink::WebGestureEvent& event) {
[email protected]a14ddcd2013-06-21 22:53:035760 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:245761 possible_drag_event_info_.event_source =
5762 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
5763 possible_drag_event_info_.event_location =
5764 gfx::Point(event.globalX, event.globalY);
5765 return false;
5766}
5767
[email protected]2b942c332012-04-25 16:26:265768void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515769 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065770}
5771
[email protected]310ebd6302011-10-10 19:06:285772void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:245773 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
5774}
5775
[email protected]3d5c243b2012-11-30 00:26:015776bool RenderViewImpl::HasTouchEventHandlersAt(const gfx::Point& point) const {
5777 if (!webview())
5778 return false;
5779 return webview()->hasTouchEventHandlersAt(point);
5780}
5781
[email protected]310ebd6302011-10-10 19:06:285782void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:435783 RenderWidget::OnWasHidden();
5784
[email protected]68877c282013-09-20 05:52:425785#if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
[email protected]6392d982013-04-16 16:59:225786 RenderThreadImpl::current()->video_capture_impl_manager()->
5787 SuspendDevices(true);
5788#endif
[email protected]2d7b82c2012-06-01 05:57:505789
[email protected]8869d392013-05-07 15:34:265790 if (webview())
[email protected]f59203a2011-06-07 10:01:445791 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075792
[email protected]ea2fb972013-08-07 05:44:265793#if defined(ENABLE_PLUGINS)
[email protected]204f1df2012-01-04 20:21:135794 // Inform PPAPI plugins that their page is no longer visible.
[email protected]ea2fb972013-08-07 05:44:265795 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
5796 i != active_pepper_instances_.end(); ++i)
5797 (*i)->PageVisibilityChanged(false);
[email protected]204f1df2012-01-04 20:21:135798
[email protected]a6939ca42011-02-18 17:58:075799#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135800 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:435801 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5802 for (plugin_it = plugin_delegates_.begin();
5803 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5804 (*plugin_it)->SetContainerVisibility(false);
5805 }
[email protected]a6939ca42011-02-18 17:58:075806#endif // OS_MACOSX
[email protected]a80af12e2013-08-07 23:36:135807#endif // ENABLE_PLUGINS
[email protected]941e4552010-02-01 21:23:435808}
5809
[email protected]9e2e4632012-07-27 16:38:415810void RenderViewImpl::OnWasShown(bool needs_repainting) {
5811 RenderWidget::OnWasShown(needs_repainting);
[email protected]941e4552010-02-01 21:23:435812
[email protected]6392d982013-04-16 16:59:225813#if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
5814 RenderThreadImpl::current()->video_capture_impl_manager()->
5815 SuspendDevices(false);
5816#endif
5817
[email protected]8869d392013-05-07 15:34:265818 if (webview())
[email protected]f59203a2011-06-07 10:01:445819 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075820
[email protected]ea2fb972013-08-07 05:44:265821#if defined(ENABLE_PLUGINS)
[email protected]204f1df2012-01-04 20:21:135822 // Inform PPAPI plugins that their page is visible.
[email protected]ea2fb972013-08-07 05:44:265823 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
5824 i != active_pepper_instances_.end(); ++i)
5825 (*i)->PageVisibilityChanged(true);
[email protected]204f1df2012-01-04 20:21:135826
[email protected]a6939ca42011-02-18 17:58:075827#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135828 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:435829 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5830 for (plugin_it = plugin_delegates_.begin();
5831 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5832 (*plugin_it)->SetContainerVisibility(true);
5833 }
[email protected]784ea1ab2010-09-18 00:02:345834#endif // OS_MACOSX
[email protected]a80af12e2013-08-07 23:36:135835#endif // ENABLE_PLUGINS
[email protected]a6939ca42011-02-18 17:58:075836}
[email protected]1e6e3c992010-02-08 15:52:135837
[email protected]ed7defa2013-03-12 21:29:595838GURL RenderViewImpl::GetURLForGraphicsContext3D() {
5839 DCHECK(webview());
5840 if (webview()->mainFrame())
5841 return GURL(webview()->mainFrame()->document().url());
5842 else
5843 return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]65225772011-05-12 21:10:245844}
5845
[email protected]479b0172012-10-29 19:27:095846bool RenderViewImpl::ForceCompositingModeEnabled() {
5847 return webkit_preferences_.force_compositing_mode;
5848}
5849
[email protected]310ebd6302011-10-10 19:06:285850void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:135851 RenderWidget::OnSetFocus(enable);
5852
[email protected]a80af12e2013-08-07 23:36:135853#if defined(ENABLE_PLUGINS)
[email protected]7d3c02c2010-05-05 23:10:315854 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075855 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135856 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5857 for (plugin_it = plugin_delegates_.begin();
5858 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345859#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315860 // RenderWidget's call to setFocus can cause the underlying webview's
5861 // activation state to change just like a call to setIsActive.
5862 if (enable)
5863 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345864#endif
[email protected]7d3c02c2010-05-05 23:10:315865 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135866 }
5867 }
[email protected]a01da5682012-06-30 00:37:315868 // Notify all Pepper plugins.
[email protected]ea2fb972013-08-07 05:44:265869 for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
5870 i != active_pepper_instances_.end(); ++i)
5871 (*i)->SetContentAreaFocus(enable);
5872#endif
[email protected]321032992012-11-08 01:01:275873 // Notify all BrowserPlugins of the RenderView's focus state.
[email protected]fc72bb12013-06-02 21:13:465874 if (browser_plugin_manager_.get())
[email protected]caaf2482013-05-01 20:33:325875 browser_plugin_manager_->UpdateFocusState();
[email protected]1e6e3c992010-02-08 15:52:135876}
[email protected]941e4552010-02-01 21:23:435877
[email protected]310ebd6302011-10-10 19:06:285878void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:575879 const string16& text,
[email protected]180ef242013-11-07 06:50:465880 const std::vector<blink::WebCompositionUnderline>& underlines,
[email protected]56ea1a62011-05-30 07:05:575881 int selection_start,
5882 int selection_end) {
[email protected]ea2fb972013-08-07 05:44:265883#if defined(ENABLE_PLUGINS)
5884 if (focused_pepper_plugin_) {
[email protected]73bf95812011-10-12 11:38:325885 // When a PPAPI plugin has focus, we bypass WebKit.
[email protected]ea2fb972013-08-07 05:44:265886 if (!IsPepperAcceptingCompositionEvents()) {
5887 pepper_composition_text_ = text;
5888 } else {
5889 // TODO(kinaba) currently all composition events are sent directly to
5890 // plugins. Use DOM event mechanism after WebKit is made aware about
5891 // plugins that support composition.
5892 // The code below mimics the behavior of WebCore::Editor::setComposition.
5893
5894 // Empty -> nonempty: composition started.
5895 if (pepper_composition_text_.empty() && !text.empty())
5896 focused_pepper_plugin_->HandleCompositionStart(string16());
5897 // Nonempty -> empty: composition canceled.
5898 if (!pepper_composition_text_.empty() && text.empty())
5899 focused_pepper_plugin_->HandleCompositionEnd(string16());
5900 pepper_composition_text_ = text;
5901 // Nonempty: composition is ongoing.
5902 if (!pepper_composition_text_.empty()) {
5903 focused_pepper_plugin_->HandleCompositionUpdate(
5904 pepper_composition_text_, underlines, selection_start,
5905 selection_end);
[email protected]e6ae0f6c2011-10-04 10:39:235906 }
[email protected]e6ae0f6c2011-10-04 10:39:235907 }
[email protected]ea2fb972013-08-07 05:44:265908 return;
[email protected]56ea1a62011-05-30 07:05:575909 }
[email protected]ea2fb972013-08-07 05:44:265910
5911#if defined(OS_WIN)
5912 // When a plug-in has focus, we create platform-specific IME data used by
5913 // our IME emulator and send it directly to the focused plug-in, i.e. we
5914 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
5915 // instance ID is the same one as the specified ID.)
5916 if (focused_plugin_id_ >= 0) {
5917 std::vector<int> clauses;
5918 std::vector<int> target;
5919 for (size_t i = 0; i < underlines.size(); ++i) {
5920 clauses.push_back(underlines[i].startOffset);
5921 clauses.push_back(underlines[i].endOffset);
5922 if (underlines[i].thick) {
5923 target.clear();
5924 target.push_back(underlines[i].startOffset);
5925 target.push_back(underlines[i].endOffset);
5926 }
5927 }
5928 std::set<WebPluginDelegateProxy*>::iterator it;
5929 for (it = plugin_delegates_.begin(); it != plugin_delegates_.end(); ++it) {
5930 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
5931 focused_plugin_id_);
5932 }
5933 return;
5934 }
[email protected]a80af12e2013-08-07 23:36:135935#endif // OS_WIN
5936#endif // ENABLE_PLUGINS
[email protected]ea2fb972013-08-07 05:44:265937 RenderWidget::OnImeSetComposition(text,
5938 underlines,
5939 selection_start,
5940 selection_end);
[email protected]56ea1a62011-05-30 07:05:575941}
5942
[email protected]db4fc1e2013-09-06 20:01:515943void RenderViewImpl::OnImeConfirmComposition(
5944 const string16& text,
5945 const gfx::Range& replacement_range,
5946 bool keep_selection) {
[email protected]ea2fb972013-08-07 05:44:265947#if defined(ENABLE_PLUGINS)
5948 if (focused_pepper_plugin_) {
[email protected]73bf95812011-10-12 11:38:325949 // When a PPAPI plugin has focus, we bypass WebKit.
[email protected]ea2fb972013-08-07 05:44:265950 // Here, text.empty() has a special meaning. It means to commit the last
5951 // update of composition text (see
5952 // RenderWidgetHost::ImeConfirmComposition()).
5953 const string16& last_text = text.empty() ? pepper_composition_text_ : text;
5954
5955 // last_text is empty only when both text and pepper_composition_text_ is.
5956 // Ignore it.
5957 if (last_text.empty())
[email protected]e6ae0f6c2011-10-04 10:39:235958 return;
[email protected]ea2fb972013-08-07 05:44:265959
5960 if (!IsPepperAcceptingCompositionEvents()) {
[email protected]28fccb32013-08-29 22:25:465961 base::i18n::UTF16CharIterator iterator(&last_text);
5962 int32 i = 0;
5963 while (iterator.Advance()) {
[email protected]180ef242013-11-07 06:50:465964 blink::WebKeyboardEvent char_event;
5965 char_event.type = blink::WebInputEvent::Char;
[email protected]ea2fb972013-08-07 05:44:265966 char_event.timeStampSeconds = base::Time::Now().ToDoubleT();
5967 char_event.modifiers = 0;
5968 char_event.windowsKeyCode = last_text[i];
5969 char_event.nativeKeyCode = last_text[i];
[email protected]28fccb32013-08-29 22:25:465970
5971 const int32 char_start = i;
5972 for (; i < iterator.array_pos(); ++i) {
5973 char_event.text[i - char_start] = last_text[i];
5974 char_event.unmodifiedText[i - char_start] = last_text[i];
5975 }
5976
[email protected]ea2fb972013-08-07 05:44:265977 if (webwidget())
5978 webwidget()->handleInputEvent(char_event);
[email protected]ebd28ac2011-10-13 18:49:055979 }
[email protected]ea2fb972013-08-07 05:44:265980 } else {
5981 // Mimics the order of events sent by WebKit.
5982 // See WebCore::Editor::setComposition() for the corresponding code.
5983 focused_pepper_plugin_->HandleCompositionEnd(last_text);
5984 focused_pepper_plugin_->HandleTextInput(last_text);
[email protected]ebd28ac2011-10-13 18:49:055985 }
[email protected]ea2fb972013-08-07 05:44:265986 pepper_composition_text_.clear();
5987 return;
[email protected]56ea1a62011-05-30 07:05:575988 }
[email protected]ea2fb972013-08-07 05:44:265989#if defined(OS_WIN)
5990 // Same as OnImeSetComposition(), we send the text from IMEs directly to
5991 // plug-ins. When we send IME text directly to plug-ins, we should not send
5992 // it to WebKit to prevent WebKit from controlling IMEs.
5993 // TODO(thakis): Honor |replacement_range| for plugins?
5994 if (focused_plugin_id_ >= 0) {
5995 std::set<WebPluginDelegateProxy*>::iterator it;
5996 for (it = plugin_delegates_.begin();
5997 it != plugin_delegates_.end(); ++it) {
5998 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
5999 }
6000 return;
6001 }
[email protected]a80af12e2013-08-07 23:36:136002#endif // OS_WIN
6003#endif // ENABLE_PLUGINS
[email protected]ea2fb972013-08-07 05:44:266004 if (replacement_range.IsValid() && webview()) {
6005 // Select the text in |replacement_range|, it will then be replaced by
6006 // text added by the call to RenderWidget::OnImeConfirmComposition().
6007 if (WebFrame* frame = webview()->focusedFrame()) {
6008 WebRange webrange = WebRange::fromDocumentRange(
6009 frame, replacement_range.start(), replacement_range.length());
6010 if (!webrange.isNull())
6011 frame->selectRange(webrange);
6012 }
6013 }
6014 RenderWidget::OnImeConfirmComposition(text,
6015 replacement_range,
6016 keep_selection);
[email protected]56ea1a62011-05-30 07:05:576017}
6018
[email protected]468ac582012-11-20 00:53:196019void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor) {
6020 RenderWidget::SetDeviceScaleFactor(device_scale_factor);
[email protected]fb854192013-02-06 01:30:046021 if (webview()) {
[email protected]dea5e7682012-06-14 05:21:246022 webview()->setDeviceScaleFactor(device_scale_factor);
[email protected]fb854192013-02-06 01:30:046023 webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled(
6024 ShouldUseFixedPositionCompositing(device_scale_factor_));
[email protected]c162ced82013-06-29 01:24:536025 webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled(
6026 ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_));
[email protected]d8221b22013-05-23 05:35:436027 webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
6028 ShouldUseTransitionCompositing(device_scale_factor_));
[email protected]06fc4d3b2013-07-08 21:07:246029 webview()->settings()->
6030 setAcceleratedCompositingForFixedRootBackgroundEnabled(
6031 ShouldUseAcceleratedFixedRootBackground(device_scale_factor_));
[email protected]e3415902013-10-17 15:00:466032 webview()->settings()->setAcceleratedCompositingForScrollableFramesEnabled(
6033 ShouldUseAcceleratedCompositingForScrollableFrames(
6034 device_scale_factor_));
6035 webview()->settings()->setCompositedScrollingForFramesEnabled(
6036 ShouldUseCompositedScrollingForFrames(device_scale_factor_));
[email protected]fb854192013-02-06 01:30:046037 }
[email protected]3a1c8a8032013-03-18 22:35:326038 if (auto_resize_mode_)
6039 AutoResizeCompositor();
[email protected]caaf2482013-05-01 20:33:326040
[email protected]fc72bb12013-06-02 21:13:466041 if (browser_plugin_manager_.get())
[email protected]caaf2482013-05-01 20:33:326042 browser_plugin_manager_->UpdateDeviceScaleFactor(device_scale_factor_);
[email protected]dea5e7682012-06-14 05:21:246043}
6044
[email protected]310ebd6302011-10-10 19:06:286045ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]ea2fb972013-08-07 05:44:266046#if defined(ENABLE_PLUGINS)
6047 if (focused_pepper_plugin_)
6048 return focused_pepper_plugin_->text_input_type();
6049#endif
6050 return RenderWidget::GetTextInputType();
[email protected]73bf95812011-10-12 11:38:326051}
6052
[email protected]3f783362011-10-21 22:40:506053void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
[email protected]ea2fb972013-08-07 05:44:266054#if defined(ENABLE_PLUGINS)
6055 if (focused_pepper_plugin_) {
[email protected]3f783362011-10-21 22:40:506056 // TODO(kinaba) http://crbug.com/101101
6057 // Current Pepper IME API does not handle selection bounds. So we simply
6058 // use the caret position as an empty range for now. It will be updated
6059 // after Pepper API equips features related to surrounding text retrieval.
[email protected]ea2fb972013-08-07 05:44:266060 gfx::Rect caret = focused_pepper_plugin_->GetCaretBounds();
[email protected]3f783362011-10-21 22:40:506061 *start = caret;
6062 *end = caret;
6063 return;
6064 }
[email protected]ea2fb972013-08-07 05:44:266065#endif
[email protected]3f783362011-10-21 22:40:506066 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:456067}
6068
[email protected]501ea13d2013-07-09 17:03:296069#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
[email protected]58b48a0d2012-06-13 07:01:356070void RenderViewImpl::GetCompositionCharacterBounds(
6071 std::vector<gfx::Rect>* bounds) {
6072 DCHECK(bounds);
6073 bounds->clear();
6074
[email protected]ea2fb972013-08-07 05:44:266075#if defined(ENABLE_PLUGINS)
6076 if (focused_pepper_plugin_) {
[email protected]88dbe32f2013-06-20 23:31:366077 return;
6078 }
[email protected]ea2fb972013-08-07 05:44:266079#endif
6080
[email protected]58b48a0d2012-06-13 07:01:356081 if (!webview())
6082 return;
6083 size_t start_offset = 0;
6084 size_t character_count = 0;
6085 if (!webview()->compositionRange(&start_offset, &character_count))
6086 return;
6087 if (character_count == 0)
6088 return;
6089
[email protected]180ef242013-11-07 06:50:466090 blink::WebFrame* frame = webview()->focusedFrame();
[email protected]58b48a0d2012-06-13 07:01:356091 if (!frame)
6092 return;
6093
6094 bounds->reserve(character_count);
[email protected]180ef242013-11-07 06:50:466095 blink::WebRect webrect;
[email protected]58b48a0d2012-06-13 07:01:356096 for (size_t i = 0; i < character_count; ++i) {
6097 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
6098 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
6099 bounds->clear();
6100 return;
6101 }
6102 bounds->push_back(webrect);
6103 }
6104}
6105
[email protected]db4fc1e2013-09-06 20:01:516106void RenderViewImpl::GetCompositionRange(gfx::Range* range) {
[email protected]ea2fb972013-08-07 05:44:266107#if defined(ENABLE_PLUGINS)
6108 if (focused_pepper_plugin_) {
[email protected]88dbe32f2013-06-20 23:31:366109 return;
6110 }
[email protected]ea2fb972013-08-07 05:44:266111#endif
[email protected]88dbe32f2013-06-20 23:31:366112 RenderWidget::GetCompositionRange(range);
6113}
[email protected]501ea13d2013-07-09 17:03:296114#endif
[email protected]88dbe32f2013-06-20 23:31:366115
[email protected]310ebd6302011-10-10 19:06:286116bool RenderViewImpl::CanComposeInline() {
[email protected]ea2fb972013-08-07 05:44:266117#if defined(ENABLE_PLUGINS)
6118 if (focused_pepper_plugin_)
6119 return IsPepperAcceptingCompositionEvents();
6120#endif
6121 return true;
[email protected]56ea1a62011-05-30 07:05:576122}
6123
[email protected]33004772013-11-12 09:49:236124void RenderViewImpl::InstrumentWillBeginFrame(int frame_id) {
[email protected]35134e12013-02-22 20:07:406125 if (!webview())
6126 return;
6127 if (!webview()->devToolsAgent())
6128 return;
[email protected]33004772013-11-12 09:49:236129 webview()->devToolsAgent()->didBeginFrame(frame_id);
[email protected]35134e12013-02-22 20:07:406130}
6131
6132void RenderViewImpl::InstrumentDidBeginFrame() {
6133 if (!webview())
6134 return;
6135 if (!webview()->devToolsAgent())
6136 return;
6137 // TODO(jamesr/caseq): Decide if this needs to be renamed.
6138 webview()->devToolsAgent()->didComposite();
6139}
6140
6141void RenderViewImpl::InstrumentDidCancelFrame() {
6142 if (!webview())
6143 return;
6144 if (!webview()->devToolsAgent())
6145 return;
6146 webview()->devToolsAgent()->didCancelFrame();
6147}
6148
6149void RenderViewImpl::InstrumentWillComposite() {
6150 if (!webview())
6151 return;
6152 if (!webview()->devToolsAgent())
6153 return;
6154 webview()->devToolsAgent()->willComposite();
6155}
6156
[email protected]34bb3ac2013-03-08 02:41:286157bool RenderViewImpl::AllowPartialSwap() const {
6158 return allow_partial_swap_;
6159}
6160
[email protected]b2e4c70132013-10-03 02:07:516161void RenderViewImpl::SetScreenMetricsEmulationParameters(
[email protected]7f99fc22013-11-08 14:05:586162 float device_scale_factor,
6163 const gfx::Point& root_layer_offset,
6164 float root_layer_scale) {
[email protected]b2e4c70132013-10-03 02:07:516165 if (webview()) {
6166 webview()->setCompositorDeviceScaleFactorOverride(device_scale_factor);
[email protected]7f99fc22013-11-08 14:05:586167 webview()->setRootLayerTransform(
6168 blink::WebSize(root_layer_offset.x(), root_layer_offset.y()),
6169 root_layer_scale);
[email protected]b2e4c70132013-10-03 02:07:516170 }
6171}
6172
[email protected]310ebd6302011-10-10 19:06:286173bool RenderViewImpl::ScheduleFileChooser(
[email protected]e9ff79c2012-10-19 21:31:266174 const FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:476175 WebFileChooserCompletion* completion) {
6176 static const size_t kMaximumPendingFileChooseRequests = 4;
6177 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
6178 // This sanity check prevents too many file choose requests from getting
6179 // queued which could DoS the user. Getting these is most likely a
6180 // programming error (there are many ways to DoS the user so it's not
6181 // considered a "real" security check), either in JS requesting many file
6182 // choosers to pop up, or in a plugin.
6183 //
6184 // TODO(brettw) we might possibly want to require a user gesture to open
6185 // a file picker, which will address this issue in a better way.
6186 return false;
6187 }
6188
6189 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
6190 new PendingFileChooser(params, completion)));
6191 if (file_chooser_completions_.size() == 1) {
6192 // Actually show the browse dialog when this is the first request.
6193 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
6194 }
6195 return true;
6196}
6197
[email protected]180ef242013-11-07 06:50:466198blink::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:516199 if (!geolocation_dispatcher_)
6200 geolocation_dispatcher_ = new GeolocationDispatcher(this);
6201 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:256202}
[email protected]61c9f032010-03-31 23:04:196203
[email protected]180ef242013-11-07 06:50:466204blink::WebSpeechInputController* RenderViewImpl::speechInputController(
6205 blink::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:226206#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:026207 if (!input_tag_speech_dispatcher_)
6208 input_tag_speech_dispatcher_ =
6209 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:226210#endif
[email protected]c52b2892012-03-07 11:01:026211 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:116212}
6213
[email protected]180ef242013-11-07 06:50:466214blink::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
[email protected]64d09222012-05-25 10:10:346215 if (!speech_recognition_dispatcher_)
6216 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
[email protected]64d09222012-05-25 10:10:346217 return speech_recognition_dispatcher_;
6218}
6219
[email protected]310ebd6302011-10-10 19:06:286220void RenderViewImpl::zoomLimitsChanged(double minimum_level,
6221 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:256222 // For now, don't remember plugin zoom values. We don't want to mix them with
6223 // normal web content (i.e. a fixed layout plugin would usually want them
6224 // different).
6225 bool remember = !webview()->mainFrame()->document().isPluginDocument();
6226
[email protected]b75b8292010-10-01 07:28:256227 int minimum_percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:496228 ZoomLevelToZoomFactor(minimum_level) * 100);
[email protected]b75b8292010-10-01 07:28:256229 int maximum_percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:496230 ZoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:256231
6232 Send(new ViewHostMsg_UpdateZoomLimits(
6233 routing_id_, minimum_percent, maximum_percent, remember));
6234}
6235
[email protected]310ebd6302011-10-10 19:06:286236void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:256237 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:086238 float zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:266239
6240 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
6241
[email protected]b75b8292010-10-01 07:28:256242 // Tell the browser which url got zoomed so it can update the menu and the
6243 // saved values if necessary
6244 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:086245 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:416246 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:256247}
6248
[email protected]7940b8e2013-07-25 23:08:496249double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const {
6250 return ZoomLevelToZoomFactor(zoom_level);
6251}
6252
6253double RenderViewImpl::zoomFactorToZoomLevel(double factor) const {
6254 return ZoomFactorToZoomLevel(factor);
6255}
6256
[email protected]310ebd6302011-10-10 19:06:286257void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
6258 const WebString& base_url,
6259 const WebString& url,
6260 const WebString& title) {
[email protected]af15bf22013-03-08 01:18:176261 bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
[email protected]a6d36cc2011-02-23 00:39:486262 GURL base(base_url);
6263 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
6264 if (base.GetOrigin() != absolute_url.GetOrigin()) {
6265 return;
6266 }
[email protected]f1a29a02011-10-06 23:08:446267 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
6268 UTF16ToUTF8(scheme),
6269 absolute_url,
[email protected]3a3b75a2012-06-01 08:38:366270 title,
6271 user_gesture));
[email protected]a6d36cc2011-02-23 00:39:486272}
6273
[email protected]180ef242013-11-07 06:50:466274blink::WebPageVisibilityState RenderViewImpl::visibilityState() const {
6275 blink::WebPageVisibilityState current_state = is_hidden() ?
6276 blink::WebPageVisibilityStateHidden :
6277 blink::WebPageVisibilityStateVisible;
6278 blink::WebPageVisibilityState override_state = current_state;
[email protected]e9ff79c2012-10-19 21:31:266279 if (GetContentClient()->renderer()->
[email protected]f59203a2011-06-07 10:01:446280 ShouldOverridePageVisibilityState(this,
6281 &override_state))
6282 return override_state;
6283 return current_state;
[email protected]94dec932011-05-26 20:04:216284}
6285
[email protected]180ef242013-11-07 06:50:466286blink::WebUserMediaClient* RenderViewImpl::userMediaClient() {
[email protected]60ee79f2013-09-11 13:49:556287 // This can happen in tests, in which case it's OK to return NULL.
6288 if (!InitializeMediaStreamClient())
6289 return NULL;
6290
[email protected]c3bdce152013-07-10 04:56:346291 return web_user_media_client_;
[email protected]273558fb2012-01-12 15:03:516292}
6293
[email protected]180ef242013-11-07 06:50:466294blink::WebMIDIClient* RenderViewImpl::webMIDIClient() {
[email protected]7b77f6cb2013-07-25 16:23:146295 if (!midi_dispatcher_)
6296 midi_dispatcher_ = new MIDIDispatcher(this);
6297 return midi_dispatcher_;
6298}
6299
[email protected]a0629af92012-08-08 00:39:376300void RenderViewImpl::draggableRegionsChanged() {
6301 FOR_EACH_OBSERVER(
6302 RenderViewObserver,
6303 observers_,
6304 DraggableRegionsChanged(webview()->mainFrame()));
6305}
6306
[email protected]40bed812013-11-05 06:59:156307WebMediaPlayer* RenderViewImpl::CreateWebMediaPlayerForMediaStream(
6308 WebFrame* frame,
[email protected]180ef242013-11-07 06:50:466309 const blink::WebURL& url,
[email protected]40bed812013-11-05 06:59:156310 WebMediaPlayerClient* client) {
6311#if defined(ENABLE_WEBRTC)
6312 if (!InitializeMediaStreamClient()) {
6313 LOG(ERROR) << "Failed to initialize MediaStreamClient";
6314 return NULL;
6315 }
6316#if !defined(GOOGLE_TV)
6317 if (media_stream_client_->IsMediaStream(url)) {
6318#if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
6319 bool found_neon =
6320 (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
6321 UMA_HISTOGRAM_BOOLEAN("Platform.WebRtcNEONFound", found_neon);
6322#endif // defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
6323 return new WebMediaPlayerMS(frame, client, AsWeakPtr(),
6324 media_stream_client_, new RenderMediaLog());
6325 }
6326#endif // !defined(GOOGLE_TV)
6327#endif // defined(ENABLE_WEBRTC)
6328 return NULL;
6329}
6330
[email protected]20657a82012-08-21 20:23:036331#if defined(OS_ANDROID)
6332WebContentDetectionResult RenderViewImpl::detectContentAround(
6333 const WebHitTestResult& touch_hit) {
6334 DCHECK(!touch_hit.isNull());
6335 DCHECK(!touch_hit.node().isNull());
6336 DCHECK(touch_hit.node().isTextNode());
6337
6338 // Process the position with all the registered content detectors until
6339 // a match is found. Priority is provided by their relative order.
6340 for (ContentDetectorList::const_iterator it = content_detectors_.begin();
6341 it != content_detectors_.end(); ++it) {
6342 ContentDetector::Result content = (*it)->FindTappedContent(touch_hit);
6343 if (content.valid) {
6344 return WebContentDetectionResult(content.content_boundaries,
6345 UTF8ToUTF16(content.text), content.intent_url);
6346 }
6347 }
6348 return WebContentDetectionResult();
6349}
6350
6351void RenderViewImpl::scheduleContentIntent(const WebURL& intent) {
6352 // Introduce a short delay so that the user can notice the content.
[email protected]dd32b1272013-05-04 14:17:116353 base::MessageLoop::current()->PostDelayedTask(
[email protected]20657a82012-08-21 20:23:036354 FROM_HERE,
[email protected]dd32b1272013-05-04 14:17:116355 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent,
6356 AsWeakPtr(),
6357 intent,
6358 expected_content_intent_id_),
[email protected]20657a82012-08-21 20:23:036359 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds));
6360}
6361
6362void RenderViewImpl::cancelScheduledContentIntents() {
6363 ++expected_content_intent_id_;
6364}
6365
6366void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent,
6367 size_t request_id) {
6368 if (request_id != expected_content_intent_id_)
6369 return;
6370
6371 // Remove the content highlighting if any.
6372 scheduleComposite();
6373
6374 if (!intent.is_empty())
6375 Send(new ViewHostMsg_StartContentIntent(routing_id_, intent));
6376}
[email protected]b18583c2012-12-18 06:55:276377
6378bool RenderViewImpl::openDateTimeChooser(
[email protected]180ef242013-11-07 06:50:466379 const blink::WebDateTimeChooserParams& params,
6380 blink::WebDateTimeChooserCompletion* completion) {
[email protected]b18583c2012-12-18 06:55:276381 date_time_picker_client_.reset(
6382 new RendererDateTimePicker(this, params, completion));
6383 return date_time_picker_client_->Open();
6384}
6385
[email protected]40bed812013-11-05 06:59:156386WebMediaPlayer* RenderViewImpl::CreateAndroidWebMediaPlayer(
6387 WebFrame* frame,
[email protected]180ef242013-11-07 06:50:466388 const blink::WebURL& url,
[email protected]40bed812013-11-05 06:59:156389 WebMediaPlayerClient* client) {
6390 GpuChannelHost* gpu_channel_host =
6391 RenderThreadImpl::current()->EstablishGpuChannelSync(
6392 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
6393 if (!gpu_channel_host) {
6394 LOG(ERROR) << "Failed to establish GPU channel for media player";
6395 return NULL;
6396 }
6397
6398 scoped_ptr<StreamTextureFactory> stream_texture_factory;
6399 if (UsingSynchronousRendererCompositor()) {
6400 SynchronousCompositorFactory* factory =
6401 SynchronousCompositorFactory::GetInstance();
6402 stream_texture_factory = factory->CreateStreamTextureFactory(routing_id_);
6403 } else {
6404 scoped_refptr<cc::ContextProvider> context_provider =
6405 RenderThreadImpl::current()->SharedMainThreadContextProvider();
6406
6407 if (!context_provider.get()) {
6408 LOG(ERROR) << "Failed to get context3d for media player";
6409 return NULL;
6410 }
6411
6412 stream_texture_factory.reset(new StreamTextureFactoryImpl(
6413 context_provider->Context3d(), gpu_channel_host, routing_id_));
6414 }
6415
6416 scoped_ptr<WebMediaPlayerAndroid> web_media_player_android(
6417 new WebMediaPlayerAndroid(
6418 frame,
6419 client,
6420 AsWeakPtr(),
6421 media_player_manager_,
6422 stream_texture_factory.release(),
6423 RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy(),
6424 new RenderMediaLog()));
6425#if defined(ENABLE_WEBRTC) && defined(GOOGLE_TV)
6426 if (media_stream_client_ && media_stream_client_->IsMediaStream(url)) {
6427 RTCVideoDecoderFactoryTv* factory = RenderThreadImpl::current()
6428 ->GetMediaStreamDependencyFactory()->decoder_factory_tv();
6429 // |media_stream_client| and |factory| outlives |web_media_player_android|.
6430 if (!factory->AcquireDemuxer() ||
6431 !web_media_player_android->InjectMediaStream(
6432 media_stream_client_,
6433 factory,
6434 base::Bind(
6435 base::IgnoreResult(&RTCVideoDecoderFactoryTv::ReleaseDemuxer),
6436 base::Unretained(factory)))) {
6437 LOG(ERROR) << "Failed to inject media stream.";
6438 return NULL;
6439 }
6440 }
6441#endif // defined(ENABLE_WEBRTC) && defined(GOOGLE_TV)
6442 return web_media_player_android.release();
6443}
6444
[email protected]6d17f6392012-12-05 05:24:546445#endif // defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:036446
[email protected]caf706f2010-10-26 17:54:086447#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:286448void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:156449 if (external_popup_menu_ == NULL) {
6450 // Crash reports from the field indicate that we can be notified with a
6451 // NULL external popup menu (we probably get notified twice).
6452 // If you hit this please file a bug against jcivelli and include the page
6453 // and steps to repro.
6454 NOTREACHED();
6455 return;
6456 }
[email protected]caf706f2010-10-26 17:54:086457 external_popup_menu_->DidSelectItem(selected_index);
6458 external_popup_menu_.reset();
6459}
6460#endif
[email protected]bb461532010-11-26 21:50:236461
[email protected]24d2b172012-05-26 00:54:126462#if defined(OS_ANDROID)
6463void RenderViewImpl::OnSelectPopupMenuItems(
6464 bool canceled,
6465 const std::vector<int>& selected_indices) {
6466 // It is possible to receive more than one of these calls if the user presses
6467 // a select faster than it takes for the show-select-popup IPC message to make
6468 // it to the browser UI thread. Ignore the extra-messages.
6469 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug.
[email protected]59383c782013-04-17 16:43:276470 if (!external_popup_menu_)
[email protected]24d2b172012-05-26 00:54:126471 return;
6472
6473 external_popup_menu_->DidSelectItems(canceled, selected_indices);
6474 external_popup_menu_.reset();
6475}
6476#endif
6477
[email protected]310ebd6302011-10-10 19:06:286478void RenderViewImpl::OnContextMenuClosed(
[email protected]e9ff79c2012-10-19 21:31:266479 const CustomContextMenuContext& custom_context) {
[email protected]860ee642012-10-13 03:46:256480 if (custom_context.request_id) {
6481 // External request, should be in our map.
[email protected]e9ff79c2012-10-19 21:31:266482 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:256483 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:466484 if (client) {
6485 client->OnMenuClosed(custom_context.request_id);
6486 pending_context_menus_.Remove(custom_context.request_id);
6487 }
[email protected]860ee642012-10-13 03:46:256488 } else {
6489 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:086490 context_menu_node_.reset();
[email protected]860ee642012-10-13 03:46:256491 }
[email protected]521b2482011-01-15 00:10:106492}
[email protected]5a7b15a2011-08-22 22:48:186493
[email protected]f56c7872013-06-18 12:31:576494void RenderViewImpl::OnShowContextMenu(const gfx::Point& location) {
[email protected]a14ddcd2013-06-21 22:53:036495 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH_EDIT_MENU;
[email protected]f56c7872013-06-18 12:31:576496 touch_editing_context_menu_location_ = location;
[email protected]47822262013-04-23 17:22:366497 if (webview())
6498 webview()->showContextMenu();
6499}
6500
[email protected]310ebd6302011-10-10 19:06:286501void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:186502 if (!webview())
6503 return;
6504 WebFrame* main_frame = webview()->mainFrame();
6505 if (!main_frame)
6506 return;
6507 main_frame->enableViewSourceMode(true);
6508}
[email protected]67bfb83f2011-09-22 03:36:376509
[email protected]7cc78902012-12-06 02:32:266510void RenderViewImpl::OnDisownOpener() {
6511 if (!webview())
6512 return;
6513
6514 WebFrame* main_frame = webview()->mainFrame();
6515 if (main_frame && main_frame->opener())
6516 main_frame->setOpener(NULL);
6517}
6518
[email protected]efd7e47f2012-10-19 20:37:516519#if defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:036520bool RenderViewImpl::didTapMultipleTargets(
[email protected]180ef242013-11-07 06:50:466521 const blink::WebGestureEvent& event,
[email protected]f9526d12012-10-18 01:55:036522 const WebVector<WebRect>& target_rects) {
[email protected]8d3dfee62013-06-19 05:50:336523 // Never show a disambiguation popup when accessibility is enabled,
6524 // as this interferes with "touch exploration".
6525 if (accessibility_mode_ == AccessibilityModeComplete)
6526 return false;
6527
[email protected]f9526d12012-10-18 01:55:036528 gfx::Rect finger_rect(
6529 event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2,
6530 event.data.tap.width, event.data.tap.height);
6531 gfx::Rect zoom_rect;
[email protected]70221f02013-01-31 22:17:076532 float new_total_scale =
6533 DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
6534 finger_rect, target_rects, GetSize(),
6535 gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(),
6536 device_scale_factor_ * webview()->pageScaleFactor(), &zoom_rect);
6537 if (!new_total_scale)
[email protected]f9526d12012-10-18 01:55:036538 return false;
6539
[email protected]4ded1dbf2013-08-28 21:11:036540 bool handled = false;
6541 switch (renderer_preferences_.tap_multiple_targets_strategy) {
6542 case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM:
6543 handled = webview()->zoomToMultipleTargetsRect(zoom_rect);
6544 break;
6545 case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: {
[email protected]bc2804d2013-08-06 07:45:496546 gfx::Size canvas_size =
6547 gfx::ToCeiledSize(gfx::ScaleSize(zoom_rect.size(), new_total_scale));
6548 TransportDIB* transport_dib = NULL;
6549 {
6550 scoped_ptr<skia::PlatformCanvas> canvas(
6551 RenderProcess::current()->GetDrawingCanvas(&transport_dib,
6552 gfx::Rect(canvas_size)));
[email protected]4ded1dbf2013-08-28 21:11:036553 if (!canvas) {
6554 handled = false;
6555 break;
6556 }
[email protected]f9526d12012-10-18 01:55:036557
[email protected]bc2804d2013-08-06 07:45:496558 // TODO(trchen): Cleanup the device scale factor mess.
6559 // device scale will be applied in WebKit
6560 // --> zoom_rect doesn't include device scale,
6561 // but WebKit will still draw on zoom_rect * device_scale_factor_
6562 canvas->scale(new_total_scale / device_scale_factor_,
6563 new_total_scale / device_scale_factor_);
6564 canvas->translate(-zoom_rect.x() * device_scale_factor_,
6565 -zoom_rect.y() * device_scale_factor_);
[email protected]f9526d12012-10-18 01:55:036566
[email protected]bc2804d2013-08-06 07:45:496567 webwidget_->paint(
6568 canvas.get(),
6569 zoom_rect,
6570 WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent);
6571 }
6572
6573 gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect(
6574 ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect)));
6575 Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_,
6576 physical_window_zoom_rect,
6577 canvas_size,
6578 transport_dib->id()));
[email protected]4ded1dbf2013-08-28 21:11:036579 handled = true;
6580 break;
6581 }
6582 case TAP_MULTIPLE_TARGETS_STRATEGY_NONE:
6583 // No-op.
6584 break;
[email protected]f9526d12012-10-18 01:55:036585 }
[email protected]70221f02013-01-31 22:17:076586
[email protected]4ded1dbf2013-08-28 21:11:036587 return handled;
[email protected]f9526d12012-10-18 01:55:036588}
[email protected]efd7e47f2012-10-19 20:37:516589#endif
[email protected]f9526d12012-10-18 01:55:036590
[email protected]b283d292013-02-21 08:40:346591unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
6592 return history_list_length_;
6593}
6594
[email protected]cc290f902013-03-04 20:06:026595void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
6596 if (enable) {
6597 if (has_focus())
6598 return;
6599 OnSetActive(true);
6600 OnSetFocus(true);
6601 } else {
6602 if (!has_focus())
6603 return;
6604 OnSetFocus(false);
6605 OnSetActive(false);
6606 }
6607}
6608
[email protected]3a1c8a8032013-03-18 22:35:326609void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) {
[email protected]b54fe452013-06-07 14:01:536610 ViewMsg_Resize_Params params;
6611 params.screen_info = screen_info_;
6612 params.screen_info.deviceScaleFactor = factor;
6613 params.new_size = size();
6614 params.physical_backing_size =
6615 gfx::ToCeiledSize(gfx::ScaleSize(size(), factor));
6616 params.overdraw_bottom_height = 0.f;
6617 params.resizer_rect = WebRect();
6618 params.is_fullscreen = is_fullscreen();
6619 OnResize(params);
[email protected]3a1c8a8032013-03-18 22:35:326620}
6621
[email protected]92650162013-10-30 03:31:026622void RenderViewImpl::ForceResizeForTesting(const gfx::Size& new_size) {
6623 gfx::Rect new_position(rootWindowRect().x,
6624 rootWindowRect().y,
6625 new_size.width(),
6626 new_size.height());
6627 ResizeSynchronously(new_position);
6628}
6629
[email protected]5b45ad42013-10-25 00:42:046630void RenderViewImpl::UseSynchronousResizeModeForTesting(bool enable) {
6631 resizing_mode_selector_->set_is_synchronous_mode(enable);
6632}
6633
[email protected]eac2b362013-05-22 07:01:456634void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size,
6635 const gfx::Size& max_size) {
6636 OnEnableAutoResize(min_size, max_size);
6637}
6638
6639void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) {
6640 OnDisableAutoResize(new_size);
6641}
6642
[email protected]c3bdce152013-07-10 04:56:346643void RenderViewImpl::SetMediaStreamClientForTesting(
[email protected]5e35a8d2013-07-10 19:37:216644 MediaStreamClient* media_stream_client) {
[email protected]c3bdce152013-07-10 04:56:346645 DCHECK(!media_stream_client_);
6646 DCHECK(!web_user_media_client_);
6647 media_stream_client_ = media_stream_client;
6648}
6649
[email protected]0509bc82013-09-20 20:42:596650bool RenderViewImpl::IsPluginFullscreenAllowed() {
6651 return renderer_preferences_.plugin_fullscreen_allowed;
6652}
6653
[email protected]f9526d12012-10-18 01:55:036654void RenderViewImpl::OnReleaseDisambiguationPopupDIB(
6655 TransportDIB::Handle dib_handle) {
6656 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle);
6657 RenderProcess::current()->ReleaseTransportDIB(dib);
6658}
[email protected]e9ff79c2012-10-19 21:31:266659
[email protected]6fceb912013-02-15 06:24:156660void RenderViewImpl::DidCommitCompositorFrame() {
6661 RenderWidget::DidCommitCompositorFrame();
6662 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame());
6663}
6664
[email protected]41225fe2013-03-29 05:32:026665void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) {
6666 if (!urls.empty())
6667 Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, page_id_, urls));
6668}
6669
6670void RenderViewImpl::DidStopLoadingIcons() {
6671 int icon_types = WebIconURL::TypeFavicon;
6672 if (TouchEnabled())
6673 icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch;
6674
6675 WebVector<WebIconURL> icon_urls =
6676 webview()->mainFrame()->iconURLs(icon_types);
6677
6678 std::vector<FaviconURL> urls;
6679 for (size_t i = 0; i < icon_urls.size(); i++) {
6680 WebURL url = icon_urls[i].iconURL();
6681 if (!url.isEmpty())
6682 urls.push_back(FaviconURL(url,
6683 ToFaviconType(icon_urls[i].iconType())));
6684 }
6685 SendUpdateFaviconURL(urls);
6686}
6687
[email protected]e9ff79c2012-10-19 21:31:266688} // namespace content