blob: 33c5b12758630b6962c4594eaf28331cdb6b2eb0 [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#include <string>
10#include <vector>
11
[email protected]6e806822011-11-19 01:51:0812#include "base/bind.h"
13#include "base/bind_helpers.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5015#include "base/compiler_specific.h"
[email protected]e7ca2892012-09-01 00:52:1516#include "base/debug/trace_event.h"
[email protected]0720b532012-08-28 19:23:3717#include "base/json/json_reader.h"
[email protected]b1cf3372011-04-20 21:28:1018#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4919#include "base/lazy_instance.h"
[email protected]084c8552012-08-12 22:51:2020#include "base/message_loop_proxy.h"
[email protected]835d7c82010-10-14 04:38:3821#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2822#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5123#include "base/process_util.h"
[email protected]7ddea9802012-02-22 23:08:0524#include "base/string_number_conversions.h"
[email protected]0a35efc2012-03-13 17:28:1325#include "base/string_piece.h"
[email protected]318bf5802011-08-08 17:12:4126#include "base/string_split.h"
initial.commit09911bf2008-07-26 23:55:2927#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2828#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2629#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2230#include "base/utf_string_conversions.h"
[email protected]e93e04e2011-03-14 00:27:1031#include "content/common/appcache/appcache_dispatcher.h"
[email protected]14392a52012-05-02 20:28:4432#include "content/common/child_thread.h"
[email protected]127dd582011-03-16 21:32:1033#include "content/common/clipboard_messages.h"
[email protected]0720b532012-08-28 19:23:3734#include "content/common/content_constants_internal.h"
[email protected]37666cf2011-03-13 21:51:4235#include "content/common/database_messages.h"
[email protected]59f4f2fa2011-03-23 01:00:5536#include "content/common/drag_messages.h"
[email protected]16dd6e22012-03-01 19:08:2037#include "content/common/fileapi/file_system_dispatcher.h"
38#include "content/common/fileapi/webfilesystem_callback_dispatcher.h"
[email protected]c26ad882012-02-07 06:41:2039#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]a2ef54c2011-10-10 16:20:3140#include "content/common/intents_messages.h"
[email protected]7f3c7af2011-10-20 22:52:5141#include "content/common/java_bridge_messages.h"
[email protected]bac466e2012-07-31 02:10:5442#include "content/common/old_browser_plugin_messages.h"
[email protected]127dd582011-03-16 21:32:1043#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0044#include "content/common/pepper_plugin_registry.h"
[email protected]10e5cf12011-04-13 04:10:4045#include "content/common/quota_dispatcher.h"
[email protected]940895b2011-08-20 00:50:0546#include "content/common/request_extra_data.h"
[email protected]5fa3a062012-03-21 15:39:3447#include "content/common/socket_stream_handle_data.h"
[email protected]778574e2011-03-21 22:03:5048#include "content/common/view_messages.h"
[email protected]4e1eb3392012-05-18 00:08:0549#include "content/common/webmessageportchannel_impl.h"
[email protected]e091df82011-10-11 18:13:2150#include "content/public/common/bindings_policy.h"
[email protected]744c2a22012-03-15 18:42:0451#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4852#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2953#include "content/public/common/content_switches.h"
[email protected]35be7ec2012-02-12 20:42:5154#include "content/public/common/context_menu_params.h"
[email protected]8caadeb2011-11-22 02:45:2355#include "content/public/common/file_chooser_params.h"
[email protected]a1d29162011-10-14 17:14:0356#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3457#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0758#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3259#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4460#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3661#include "content/public/renderer/render_view_visitor.h"
[email protected]e6e56752012-08-10 00:46:0662#include "content/renderer/browser_plugin/browser_plugin.h"
63#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]cc510d7e2012-08-08 04:40:1064#include "content/renderer/browser_plugin/old/old_browser_plugin.h"
[email protected]14cf0f12012-06-18 17:15:5765#include "content/renderer/browser_plugin/old/browser_plugin_channel_manager.h"
66#include "content/renderer/browser_plugin/old/browser_plugin_constants.h"
67#include "content/renderer/browser_plugin/old/guest_to_embedder_channel.h"
[email protected]230b7ef2011-03-16 22:30:1968#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0269#include "content/renderer/devtools_agent.h"
[email protected]766a7082012-02-03 23:39:1570#include "content/renderer/dom_automation_controller.h"
[email protected]1910fe82012-05-10 00:04:1071#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]55722152011-03-22 01:33:5372#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1973#include "content/renderer/geolocation_dispatcher.h"
[email protected]84a83e192012-03-09 18:43:4074#include "content/renderer/gpu/compositor_thread.h"
[email protected]1842fe22012-08-13 23:24:3575#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]1784b2f2011-11-24 10:53:4876#include "content/renderer/idle_user_detector.h"
[email protected]c52b2892012-03-07 11:01:0277#include "content/renderer/input_tag_speech_dispatcher.h"
[email protected]07161902011-11-11 09:57:4278#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0279#include "content/renderer/load_progress_tracker.h"
[email protected]273558fb2012-01-12 15:03:5180#include "content/renderer/media/media_stream_dependency_factory.h"
81#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:4082#include "content/renderer/media/media_stream_impl.h"
[email protected]6048d512012-01-28 03:14:4883#include "content/renderer/media/render_audiosourceprovider.h"
[email protected]090f7312011-08-05 23:26:4084#include "content/renderer/media/render_media_log.h"
[email protected]6048d512012-01-28 03:14:4885#include "content/renderer/media/renderer_gpu_video_decoder_factories.h"
[email protected]4a19be92011-09-22 14:25:0286#include "content/renderer/mhtml_generator.h"
[email protected]230b7ef2011-03-16 22:30:1987#include "content/renderer/notification_provider.h"
[email protected]6f516082011-03-17 19:15:3588#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0589#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4490#include "content/renderer/render_thread_impl.h"
[email protected]89054502012-06-03 10:29:2491#include "content/renderer/render_view_mouse_lock_dispatcher.h"
[email protected]2cff0052011-03-18 16:51:4492#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3293#include "content/renderer/renderer_accessibility.h"
[email protected]2a84f9d2012-06-05 21:50:4394#include "content/renderer/renderer_accessibility_complete.h"
95#include "content/renderer/renderer_accessibility_focus_only.h"
[email protected]663bd9e2011-03-21 01:07:0196#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]da8543762012-03-20 08:52:2097#include "content/renderer/renderer_webcolorchooser_impl.h"
[email protected]64d09222012-05-25 10:10:3498#include "content/renderer/speech_recognition_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:3299#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:19100#include "content/renderer/v8_value_converter_impl.h"
[email protected]0a35efc2012-03-13 17:28:13101#include "content/renderer/web_intents_host.h"
[email protected]663bd9e2011-03-21 01:07:01102#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:35103#include "content/renderer/webplugin_delegate_proxy.h"
104#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:49105#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41106#include "media/base/media_switches.h"
[email protected]b80322902012-03-06 01:33:50107#include "media/base/message_loop_factory.h"
[email protected]37136d162012-04-09 23:39:19108#include "media/filters/audio_renderer_impl.h"
[email protected]e1d69d762011-12-13 05:12:18109#include "media/filters/gpu_video_decoder.h"
[email protected]d1ef81d2012-07-24 11:39:36110#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29111#include "net/base/escape.h"
112#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09113#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04114#include "net/http/http_util.h"
[email protected]1842fe22012-08-13 23:24:35115#include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutputSurface.h"
[email protected]8bd0fe62011-01-17 06:44:37116#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]f546640b2012-05-15 00:03:49117#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEvent.h"
118#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h"
[email protected]be2510c02012-05-28 14:52:14119#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
120#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:37121#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:37123#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
125#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]4b1146bc2012-07-10 18:46:03128#include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h"
[email protected]8bd0fe62011-01-17 06:44:37129#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37130#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57131#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58132#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
[email protected]592e20b2012-01-20 05:53:44133#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
[email protected]8b5af492011-11-28 21:50:58134#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14135#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]4e1eb3392012-05-18 00:08:05136#include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannel.h"
[email protected]8bd0fe62011-01-17 06:44:37137#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19138#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37139#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36140#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37141#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
142#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
143#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37144#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37145#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
146#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
147#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17148#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37149#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]10e5cf12011-04-13 04:10:40150#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51151#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08152#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
153#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
154#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
155#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
156#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
[email protected]132e281a2012-07-31 18:32:44157#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPBody.h"
[email protected]9c4bf232011-12-15 02:25:08158#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
[email protected]50da23d02012-04-13 17:47:48159#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00Handler.h"
160#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00HandlerClient.h"
[email protected]273558fb2012-01-12 15:03:51161#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
162#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
[email protected]9c4bf232011-12-15 02:25:08163#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
164#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
[email protected]f546640b2012-05-15 00:03:49165#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerializedScriptValue.h"
[email protected]9c4bf232011-12-15 02:25:08166#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]5fa3a062012-03-21 15:39:34167#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSocketStreamHandle.h"
[email protected]e6e90dc2011-12-03 00:01:37168#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
169#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
170#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
171#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
172#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
173#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26174#include "third_party/skia/include/core/SkBitmap.h"
[email protected]ddb034b2012-06-26 20:31:39175#include "ui/base/dialogs/selected_file_info.h"
[email protected]08397d52011-02-05 01:53:38176#include "ui/gfx/native_widget_types.h"
177#include "ui/gfx/point.h"
178#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55179#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04180#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]b928936b2012-04-13 01:16:16181#include "webkit/dom_storage/dom_storage_types.h"
[email protected]9c4bf232011-12-15 02:25:08182#include "webkit/forms/form_data.h"
183#include "webkit/forms/form_field.h"
184#include "webkit/forms/password_form_dom_manager.h"
[email protected]25e18f82010-10-27 16:38:43185#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]18d5be92011-07-25 18:00:19186#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24187#include "webkit/glue/glue_serialize.h"
[email protected]3a3b75a2012-06-01 08:38:36188#include "webkit/glue/web_intent_service_data.h"
[email protected]851334d2012-06-15 22:39:31189#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07190#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29191#include "webkit/glue/webkit_glue.h"
[email protected]b9fd01ba2012-02-28 01:50:40192#include "webkit/glue/weburlresponse_extradata_impl.h"
[email protected]7e8b4d12012-01-20 23:39:51193#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
[email protected]a9288f52011-11-17 05:18:16194#include "webkit/media/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50195#include "webkit/plugins/npapi/plugin_list.h"
196#include "webkit/plugins/npapi/webplugin_delegate.h"
197#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
198#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52199#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29200
[email protected]25fb9b32012-04-27 03:21:55201#if defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:03202#include "content/common/android/device_info.h"
203#include "content/renderer/android/address_detector.h"
204#include "content/renderer/android/content_detector.h"
205#include "content/renderer/android/email_detector.h"
206#include "content/renderer/android/phone_number_detector.h"
[email protected]dbd3d212012-07-13 02:17:22207#include "content/renderer/media/stream_texture_factory_impl_android.h"
[email protected]780fc8242012-09-19 20:28:52208#include "content/renderer/media/webmediaplayer_proxy_impl_android.h"
[email protected]20657a82012-08-21 20:23:03209#include "third_party/WebKit/Source/WebKit/chromium/public/WebHitTestResult.h"
[email protected]59363fc92012-09-05 03:46:31210#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoint.h"
211#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatRect.h"
212#include "ui/gfx/rect_f.h"
[email protected]780fc8242012-09-19 20:28:52213#include "webkit/media/android/media_player_bridge_manager_impl.h"
[email protected]25fb9b32012-04-27 03:21:55214#include "webkit/media/android/webmediaplayer_android.h"
[email protected]780fc8242012-09-19 20:28:52215#include "webkit/media/android/webmediaplayer_impl_android.h"
216#include "webkit/media/android/webmediaplayer_in_process_android.h"
[email protected]2d7b82c2012-06-01 05:57:50217#include "webkit/media/android/webmediaplayer_manager_android.h"
[email protected]25fb9b32012-04-27 03:21:55218#elif defined(OS_WIN)
[email protected]6c8afae52009-01-22 02:24:57219// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57220// * theming
[email protected]f78452f2012-05-15 02:07:52221#include "ui/base/native_theme/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03222#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37223#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]f78452f2012-05-15 02:07:52224#include "ui/base/native_theme/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33225#elif defined(OS_MACOSX)
226#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57227#endif
228
[email protected]9892b472010-09-16 00:23:42229using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08230using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21231using WebKit::WebApplicationCacheHost;
232using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26233using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41234using WebKit::WebColor;
235using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59236using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44237using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51238using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55239using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28240using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00241using WebKit::WebDocument;
[email protected]f546640b2012-05-15 00:03:49242using WebKit::WebDOMEvent;
243using WebKit::WebDOMMessageEvent;
[email protected]e80c73b2009-04-07 23:24:58244using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25245using WebKit::WebDragOperation;
246using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51247using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51248using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08249using WebKit::WebExternalPopupMenu;
250using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47251using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22252using WebKit::WebFileSystem;
253using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49254using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59255using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48256using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45257using WebKit::WebFrame;
[email protected]7e8b4d12012-01-20 23:39:51258using WebKit::WebGraphicsContext3D;
[email protected]ca948a22009-06-25 19:36:17259using WebKit::WebHistoryItem;
[email protected]132e281a2012-07-31 18:32:44260using WebKit::WebHTTPBody;
[email protected]42054a252011-05-17 18:02:13261using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41262using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50263using WebKit::WebInputElement;
[email protected]ffc8bed2012-01-21 01:23:15264using WebKit::WebIntentRequest;
265using WebKit::WebIntentServiceInfo;
[email protected]3d9689372009-09-10 04:29:17266using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28267using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17268using WebKit::WebMediaPlayerClient;
[email protected]2b942c332012-04-25 16:26:26269using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:28270using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28271using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51272using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19273using WebKit::WebPageSerializer;
274using WebKit::WebPageSerializerClient;
[email protected]50da23d02012-04-13 17:47:48275using WebKit::WebPeerConnection00Handler;
276using WebKit::WebPeerConnection00HandlerClient;
277using WebKit::WebPeerConnectionHandler;
278using WebKit::WebPeerConnectionHandlerClient;
[email protected]3d9689372009-09-10 04:29:17279using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36280using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40281using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49282using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09283using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52284using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59285using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51286using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52287using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15288using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40289using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35290using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29291using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17292using WebKit::WebSecurityPolicy;
[email protected]f546640b2012-05-15 00:03:49293using WebKit::WebSerializedScriptValue;
[email protected]2fab253a2009-08-17 23:00:59294using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42295using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02296using WebKit::WebSize;
[email protected]5fa3a062012-03-21 15:39:34297using WebKit::WebSocketStreamHandle;
[email protected]bd92c3a2010-01-13 05:02:34298using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40299using WebKit::WebStorageQuotaCallbacks;
300using WebKit::WebStorageQuotaError;
301using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28302using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51303using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52304using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24305using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28306using WebKit::WebURL;
307using WebKit::WebURLError;
308using WebKit::WebURLRequest;
309using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28310using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03311using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28312using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26313using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26314using appcache::WebApplicationCacheHostImpl;
315using base::Time;
316using base::TimeDelta;
[email protected]007733c2011-11-17 00:34:07317using content::DocumentState;
[email protected]82ddba1c2011-10-04 00:15:32318using content::NavigationState;
[email protected]2a84f9d2012-06-05 21:50:43319using content::Referrer;
[email protected]380244092011-10-07 17:26:27320using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44321using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36322using content::RenderViewVisitor;
[email protected]2a84f9d2012-06-05 21:50:43323using content::RendererAccessibilityComplete;
324using content::RendererAccessibilityFocusOnly;
[email protected]8d86f13d2011-10-04 17:01:19325using content::V8ValueConverter;
[email protected]9c4bf232011-12-15 02:25:08326using webkit::forms::FormField;
327using webkit::forms::PasswordForm;
328using webkit::forms::PasswordFormDomManager;
[email protected]6fdd4182010-10-14 23:59:26329using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23330using webkit_glue::ResourceFetcher;
[email protected]6717bf272012-05-11 23:31:25331using webkit_glue::WebPreferences;
[email protected]b9fd01ba2012-02-28 01:50:40332using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33333
[email protected]20657a82012-08-21 20:23:03334#if defined(OS_ANDROID)
335using content::AddressDetector;
336using content::ContentDetector;
337using content::EmailDetector;
338using content::PhoneNumberDetector;
339using WebKit::WebContentDetectionResult;
[email protected]59363fc92012-09-05 03:46:31340using WebKit::WebFloatPoint;
341using WebKit::WebFloatRect;
[email protected]20657a82012-08-21 20:23:03342using WebKit::WebHitTestResult;
343#endif
344
initial.commit09911bf2008-07-26 23:55:29345//-----------------------------------------------------------------------------
346
[email protected]310ebd6302011-10-10 19:06:28347typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49348static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02349
[email protected]882daa92009-11-05 16:31:31350// Time, in seconds, we delay before sending content state changes (such as form
351// state and scroll position) to the browser. We delay sending changes to avoid
352// spamming the browser.
353// To avoid having tab/session restore require sending a message to get the
354// current content state during tab closing we use a shorter timeout for the
355// foreground renderer. This means there is a small window of time from which
356// content state is modified and not sent to session restore, but this is
357// better than having to wake up all renderers during shutdown.
358static const int kDelaySecondsForContentStateSyncHidden = 5;
359static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29360
[email protected]e99ef6f2011-10-16 01:13:00361static const size_t kExtraCharsBeforeAndAfterSelection = 100;
362
[email protected]0aa55312008-10-17 21:53:08363// The maximum number of popups that can be spawned from one page.
364static const int kMaximumNumberOfUnacknowledgedPopups = 25;
365
[email protected]c514d632011-08-16 22:54:44366static const float kScalingIncrement = 0.1f;
367
[email protected]47578fa02011-11-02 19:34:41368static const float kScalingIncrementForGesture = 0.01f;
369
[email protected]20657a82012-08-21 20:23:03370#if defined(OS_ANDROID)
371// Delay between tapping in content and launching the associated android intent.
372// Used to allow users see what has been recognized as content.
373static const size_t kContentIntentDelayMilliseconds = 700;
374#endif
375
[email protected]f546640b2012-05-15 00:03:49376static RenderViewImpl* FromRoutingID(int32 routing_id) {
377 return static_cast<RenderViewImpl*>(
378 ChildThread::current()->ResolveRoute(routing_id));
379}
380
[email protected]0720b532012-08-28 19:23:37381static WebKit::WebFrame* FindFrameByID(WebKit::WebFrame* root, int frame_id) {
382 for (WebFrame* frame = root; frame; frame = frame->traverseNext(false)) {
383 if (frame->identifier() == frame_id)
384 return frame;
385 }
386 return NULL;
387}
388
[email protected]726985e22009-06-18 21:09:28389static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
390 WebVector<WebURL> urls;
391 ds->redirectChain(urls);
392 result->reserve(urls.size());
393 for (size_t i = 0; i < urls.size(); ++i)
394 result->push_back(urls[i]);
395}
396
[email protected]007733c2011-11-17 00:34:07397// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44398// the AltErrorPageResourceFetcher is reset.
399static void StopAltErrorPageFetcher(WebDataSource* data_source) {
400 if (data_source) {
[email protected]007733c2011-11-17 00:34:07401 DocumentState* document_state = DocumentState::FromDataSource(data_source);
402 if (document_state)
403 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44404 }
405}
406
[email protected]007733c2011-11-17 00:34:07407static bool IsReload(const ViewMsg_Navigate_Params& params) {
408 return
409 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
[email protected]7c16976c2012-08-04 02:38:23410 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE ||
411 params.navigation_type ==
412 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]007733c2011-11-17 00:34:07413}
414
[email protected]b9fd01ba2012-02-28 01:50:40415static WebReferrerPolicy GetReferrerPolicyFromRequest(
[email protected]ca662822012-05-11 17:53:59416 WebFrame* frame,
[email protected]445e1042011-12-03 21:03:15417 const WebURLRequest& request) {
418 return request.extraData() ?
419 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
[email protected]ca662822012-05-11 17:53:59420 frame->document().referrerPolicy();
[email protected]445e1042011-12-03 21:03:15421}
422
[email protected]b9fd01ba2012-02-28 01:50:40423static WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
424 const WebURLResponse& response) {
425 return static_cast<WebURLResponseExtraDataImpl*>(
426 response.extraData());
427}
428
[email protected]2149cc622012-02-14 01:12:12429NOINLINE static void CrashIntentionally() {
430 // NOTE(shess): Crash directly rather than using NOTREACHED() so
431 // that the signature is easier to triage in crash reports.
432 volatile int* zero = NULL;
433 *zero = 0;
434}
435
[email protected]8bf1048012012-02-08 01:22:18436static void MaybeHandleDebugURL(const GURL& url) {
437 if (!url.SchemeIs(chrome::kChromeUIScheme))
438 return;
439 if (url == GURL(chrome::kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12440 CrashIntentionally();
[email protected]8bf1048012012-02-08 01:22:18441 } else if (url == GURL(chrome::kChromeUIKillURL)) {
442 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
443 } else if (url == GURL(chrome::kChromeUIHangURL)) {
444 for (;;) {
445 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
446 }
447 } else if (url == GURL(chrome::kChromeUIShorthangURL)) {
448 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
449 }
450}
451
[email protected]fd3238af2012-05-22 18:55:30452// Returns false unless this is a top-level navigation.
453static bool IsTopLevelNavigation(WebFrame* frame) {
454 return frame->parent() == NULL;
455}
456
457// Returns false unless this is a top-level navigation that crosses origins.
458static bool IsNonLocalTopLevelNavigation(const GURL& url,
459 WebFrame* frame,
460 WebNavigationType type) {
461 if (!IsTopLevelNavigation(frame))
462 return false;
463
464 // Navigations initiated within Webkit are not sent out to the external host
465 // in the following cases.
466 // 1. The url scheme is not http/https
467 // 2. The origin of the url and the opener is the same in which case the
468 // opener relationship is maintained.
469 // 3. Reloads/form submits/back forward navigations
470 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
471 return false;
472
473 // Not interested in reloads/form submits/resubmits/back forward navigations.
474 if (type != WebKit::WebNavigationTypeReload &&
475 type != WebKit::WebNavigationTypeFormSubmitted &&
476 type != WebKit::WebNavigationTypeFormResubmitted &&
477 type != WebKit::WebNavigationTypeBackForward) {
478 // The opener relationship between the new window and the parent allows the
479 // new window to script the parent and vice versa. This is not allowed if
480 // the origins of the two domains are different. This can be treated as a
481 // top level navigation and routed back to the host.
482 WebKit::WebFrame* opener = frame->opener();
483 if (!opener) {
484 return true;
485 }
486
487 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
488 return true;
489 }
490 return false;
491}
492
[email protected]0720b532012-08-28 19:23:37493// Recursively walks the frame tree and serializes it to JSON as described in
494// the comment for ViewMsg_UpdateFrameTree. If |exclude_frame_subtree| is not
495// NULL, the subtree for the frame is not included in the serialized form.
496// This is used when a frame is going to be removed from the tree.
497static void ConstructFrameTree(WebKit::WebFrame* frame,
498 WebKit::WebFrame* exclude_frame_subtree,
499 base::DictionaryValue* dict) {
500 dict->SetString(content::kFrameTreeNodeNameKey,
501 UTF16ToUTF8(frame->assignedName()).c_str());
502 dict->SetInteger(content::kFrameTreeNodeIdKey, frame->identifier());
503
504 WebFrame* child = frame->firstChild();
505 ListValue* children = new ListValue();
506 for (; child; child = child->nextSibling()) {
507 if (child == exclude_frame_subtree)
508 continue;
509
510 base::DictionaryValue* d = new base::DictionaryValue();
511 ConstructFrameTree(child, exclude_frame_subtree, d);
512 children->Append(d);
513 }
514 if (children->GetSize() > 0)
515 dict->Set(content::kFrameTreeNodeSubtreeKey, children);
516}
517
initial.commit09911bf2008-07-26 23:55:29518///////////////////////////////////////////////////////////////////////////////
519
[email protected]310ebd6302011-10-10 19:06:28520struct RenderViewImpl::PendingFileChooser {
[email protected]8caadeb2011-11-22 02:45:23521 PendingFileChooser(const content::FileChooserParams& p,
[email protected]cdaf8d02010-03-30 19:52:47522 WebFileChooserCompletion* c)
523 : params(p),
524 completion(c) {
525 }
[email protected]8caadeb2011-11-22 02:45:23526 content::FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47527 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
528};
529
[email protected]217690d2012-01-27 07:33:11530namespace {
531
532class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
533 public:
[email protected]82114f52012-03-20 22:53:41534 explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget)
[email protected]217690d2012-01-27 07:33:11535 : webwidget_(webwidget) {}
536
537 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
538 if (succeeded)
539 webwidget_->didAcquirePointerLock();
540 else
541 webwidget_->didNotAcquirePointerLock();
542 }
543
544 virtual void OnMouseLockLost() OVERRIDE {
545 webwidget_->didLosePointerLock();
546 }
547
548 virtual bool HandleMouseLockedInputEvent(
549 const WebKit::WebMouseEvent &event) OVERRIDE {
550 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
551 return false;
552 }
553
554 private:
555 WebKit::WebWidget* webwidget_;
556};
557
[email protected]86cd9472012-02-03 19:51:05558int64 ExtractPostId(const WebHistoryItem& item) {
559 if (item.isNull())
560 return -1;
561
562 if (item.httpBody().isNull())
563 return -1;
564
565 return item.httpBody().identifier();
566}
567
[email protected]217690d2012-01-27 07:33:11568} // namespace
569
[email protected]daf82f82011-10-31 22:35:31570RenderViewImpl::RenderViewImpl(
571 gfx::NativeViewId parent_hwnd,
572 int32 opener_id,
573 const content::RendererPreferences& renderer_prefs,
574 const WebPreferences& webkit_prefs,
575 SharedRenderViewCounter* counter,
576 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56577 int32 surface_id,
[email protected]daf82f82011-10-31 22:35:31578 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46579 const string16& frame_name,
[email protected]14392a52012-05-02 20:28:44580 bool is_renderer_created,
581 bool swapped_out,
[email protected]6fd35b72012-03-01 19:46:41582 int32 next_page_id,
[email protected]842f10652012-06-06 01:54:04583 const WebKit::WebScreenInfo& screen_info,
[email protected]cb25aa12012-08-07 19:13:43584 content::old::GuestToEmbedderChannel* guest_to_embedder_channel,
[email protected]3e3c4522012-04-13 21:16:29585 AccessibilityMode accessibility_mode)
[email protected]842f10652012-06-06 01:54:04586 : RenderWidget(WebKit::WebPopupTypeNone, screen_info, swapped_out),
[email protected]676126f72011-01-15 00:03:51587 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02588 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09589 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02590 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24591 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21592 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02593 opened_by_user_gesture_(true),
594 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24595 page_id_(-1),
596 last_page_id_sent_to_browser_(-1),
[email protected]74ce1ad2011-12-16 21:51:46597 next_page_id_(next_page_id),
[email protected]3cc72b12010-03-18 23:03:00598 history_list_offset_(-1),
599 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02600 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55601 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31602 cached_is_main_frame_pinned_to_left_(false),
603 cached_is_main_frame_pinned_to_right_(false),
604 cached_has_main_frame_horizontal_scrollbar_(false),
605 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]3354d3e2010-06-10 19:53:02606 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51607 geolocation_dispatcher_(NULL),
[email protected]c52b2892012-03-07 11:01:02608 input_tag_speech_dispatcher_(NULL),
[email protected]64d09222012-05-25 10:10:34609 speech_recognition_dispatcher_(NULL),
[email protected]676126f72011-01-15 00:03:51610 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51611 media_stream_dispatcher_(NULL),
[email protected]1bc65a42012-04-23 09:31:25612 media_stream_impl_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41613 devtools_agent_(NULL),
[email protected]2a84f9d2012-06-05 21:50:43614 accessibility_mode_(AccessibilityModeOff),
[email protected]063afcb2011-09-29 07:54:32615 renderer_accessibility_(NULL),
[email protected]7e9c5bb02012-05-14 13:58:31616 java_bridge_dispatcher_(NULL),
[email protected]217690d2012-01-27 07:33:11617 mouse_lock_dispatcher_(NULL),
[email protected]20657a82012-08-21 20:23:03618#if defined(OS_ANDROID)
619 expected_content_intent_id_(0),
[email protected]780fc8242012-09-19 20:28:52620 media_player_proxy_(NULL),
[email protected]20657a82012-08-21 20:23:03621#endif
[email protected]4fb60142011-08-09 02:22:08622 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18623 handling_select_range_(false),
624#if defined(OS_WIN)
625 focused_plugin_id_(-1),
626#endif
[email protected]468e4902012-05-23 01:49:31627 guest_to_embedder_channel_(guest_to_embedder_channel),
628 guest_pp_instance_(0),
629 guest_uninitialized_context_(NULL),
[email protected]0720b532012-08-28 19:23:37630 updating_frame_tree_(false),
631 pending_frame_tree_update_(false),
632 target_process_id_(0),
633 target_routing_id_(0),
[email protected]ef5e98e2011-12-06 09:49:18634 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]ce2b28e2012-08-09 15:53:57635 set_throttle_input_events(renderer_prefs.throttle_input_events);
[email protected]676126f72011-01-15 00:03:51636 routing_id_ = routing_id;
[email protected]9f4f3322012-01-18 22:29:56637 surface_id_ = surface_id;
[email protected]14392a52012-05-02 20:28:44638 if (opener_id != MSG_ROUTING_NONE && is_renderer_created)
[email protected]676126f72011-01-15 00:03:51639 opener_id_ = opener_id;
640
[email protected]74ce1ad2011-12-16 21:51:46641 // Ensure we start with a valid next_page_id_ from the browser.
642 DCHECK_GE(next_page_id_, 0);
643
[email protected]21b3a6ae2011-11-30 00:45:29644#if defined(ENABLE_NOTIFICATIONS)
645 notification_provider_ = new NotificationProvider(this);
646#else
647 notification_provider_ = NULL;
648#endif
649
[email protected]11fee2332011-03-29 20:36:35650 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11651 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35652
[email protected]20657a82012-08-21 20:23:03653 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
654
655#if defined(OS_ANDROID)
656 scoped_ptr<content::DeviceInfo> device_info(new content::DeviceInfo());
657
658 const std::string region_code =
659 command_line.HasSwitch(switches::kNetworkCountryIso)
660 ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso)
661 : device_info->GetNetworkCountryIso();
662 content_detectors_.push_back(linked_ptr<ContentDetector>(
663 new AddressDetector()));
664 content_detectors_.push_back(linked_ptr<ContentDetector>(
665 new PhoneNumberDetector(region_code)));
666 content_detectors_.push_back(linked_ptr<ContentDetector>(
667 new EmailDetector()));
668#endif
669
[email protected]676126f72011-01-15 00:03:51670 if (counter) {
671 shared_popup_counter_ = counter;
[email protected]14392a52012-05-02 20:28:44672 // Only count this if it isn't swapped out upon creation.
673 if (!swapped_out)
674 shared_popup_counter_->data++;
[email protected]676126f72011-01-15 00:03:51675 decrement_shared_popup_at_destruction_ = true;
676 } else {
677 shared_popup_counter_ = new SharedRenderViewCounter(0);
678 decrement_shared_popup_at_destruction_ = false;
679 }
680
[email protected]380244092011-10-07 17:26:27681 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51682 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47683 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51684 AddRef();
685
686 // If this is a popup, we must wait for the CreatingNew_ACK message before
687 // completing initialization. Otherwise, we can finish it now.
[email protected]468e4902012-05-23 01:49:31688 if (!guest_to_embedder_channel && opener_id_ == MSG_ROUTING_NONE) {
[email protected]676126f72011-01-15 00:03:51689 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55690 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51691 }
692
[email protected]34c61bd52011-05-02 19:38:33693 g_view_map.Get().insert(std::make_pair(webview(), this));
[email protected]60051ec2012-06-08 22:40:57694 webview()->setDeviceScaleFactor(device_scale_factor_);
[email protected]34c61bd52011-05-02 19:38:33695 webkit_preferences_.Apply(webview());
696 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35697 if (!frame_name.empty())
698 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33699 webview()->settings()->setMinimumTimerInterval(
700 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
701 webkit_glue::kForegroundTabTimerInterval);
702
703 OnSetRendererPrefs(renderer_prefs);
704
[email protected]676126f72011-01-15 00:03:51705 host_window_ = parent_hwnd;
706
[email protected]4fb0f202012-05-30 22:44:53707#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02708 if (!media_stream_dispatcher_)
709 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32710#endif
[email protected]735873d2012-01-25 23:31:02711
[email protected]8f6a3b852011-07-19 16:48:56712 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32713#if defined(OS_MACOSX)
714 new TextInputClientObserver(this);
715#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56716
[email protected]2d7b82c2012-06-01 05:57:50717#if defined(OS_ANDROID)
718 media_player_manager_.reset(
719 new webkit_media::WebMediaPlayerManagerAndroid());
720#endif
721
[email protected]217690d2012-01-27 07:33:11722 // The next group of objects all implement RenderViewObserver, so are deleted
723 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41724 devtools_agent_ = new DevToolsAgent(this);
[email protected]89054502012-06-03 10:29:24725 mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
[email protected]0fc7dea72012-02-09 03:47:40726 intents_host_ = new WebIntentsHost(this);
[email protected]063afcb2011-09-29 07:54:32727
[email protected]2a84f9d2012-06-05 21:50:43728 // Create renderer_accessibility_ if needed.
729 OnSetAccessibilityMode(accessibility_mode);
730
[email protected]1784b2f2011-11-24 10:53:48731 new IdleUserDetector(this);
732
[email protected]766a7082012-02-03 23:39:15733 if (command_line.HasSwitch(switches::kDomAutomationController))
734 enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION;
735
[email protected]5b52cd2f712012-03-28 02:12:48736 ProcessViewLayoutFlags(command_line);
[email protected]7ddea9802012-02-22 23:08:05737
[email protected]e48869a2011-04-01 19:56:03738 content::GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44739
740 // If we have an opener_id but we weren't created by a renderer, then
741 // it's the browser asking us to set our opener to another RenderView.
[email protected]14392a52012-05-02 20:28:44742 if (opener_id != MSG_ROUTING_NONE && !is_renderer_created) {
[email protected]f546640b2012-05-15 00:03:49743 RenderViewImpl* opener_view = FromRoutingID(opener_id);
744 if (opener_view)
745 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
[email protected]14392a52012-05-02 20:28:44746 }
747
748 // If we are initially swapped out, navigate to kSwappedOutURL.
749 // This ensures we are in a unique origin that others cannot script.
750 if (is_swapped_out_)
[email protected]0720b532012-08-28 19:23:37751 NavigateToSwappedOutURL(webview()->mainFrame());
initial.commit09911bf2008-07-26 23:55:29752}
753
[email protected]310ebd6302011-10-10 19:06:28754RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03755 history_page_ids_.clear();
756
[email protected]0aa55312008-10-17 21:53:08757 if (decrement_shared_popup_at_destruction_)
758 shared_popup_counter_->data--;
759
[email protected]a1128322009-10-06 18:38:46760 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47761 while (!file_chooser_completions_.empty()) {
762 if (file_chooser_completions_.front()->completion) {
763 file_chooser_completions_.front()->completion->didChooseFile(
764 WebVector<WebString>());
765 }
766 file_chooser_completions_.pop_front();
767 }
[email protected]a1128322009-10-06 18:38:46768
[email protected]83dde542009-09-11 20:59:55769#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11770 // Destroy all fake plugin window handles on the browser side.
771 while (!fake_plugin_window_handles_.empty()) {
772 // Make sure no NULL plugin window handles were inserted into this list.
773 DCHECK(*fake_plugin_window_handles_.begin());
774 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
775 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
776 }
[email protected]83dde542009-09-11 20:59:55777#endif
[email protected]98324892009-09-09 21:16:05778
[email protected]60c42a8c72009-10-09 04:08:59779#ifndef NDEBUG
780 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49781 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59782 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
783 DCHECK_NE(this, it->second) << "Failed to call Close?";
784#endif
[email protected]676126f72011-01-15 00:03:51785
[email protected]310ebd6302011-10-10 19:06:28786 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51787 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59788}
789
790/*static*/
[email protected]310ebd6302011-10-10 19:06:28791RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31792 ViewMap* views = g_view_map.Pointer();
793 ViewMap::iterator it = views->find(webview);
794 return it == views->end() ? NULL : it->second;
795}
796
797/*static*/
798content::RenderView*
799 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28800 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31801}
802
803/*static*/
804void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49805 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59806 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
807 if (!visitor->Visit(it->second))
808 return;
809 }
810}
811
812/*static*/
[email protected]310ebd6302011-10-10 19:06:28813RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15814 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08815 int32 opener_id,
[email protected]daf82f82011-10-31 22:35:31816 const content::RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08817 const WebPreferences& webkit_prefs,
818 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34819 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56820 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26821 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46822 const string16& frame_name,
[email protected]14392a52012-05-02 20:28:44823 bool is_renderer_created,
824 bool swapped_out,
[email protected]6fd35b72012-03-01 19:46:41825 int32 next_page_id,
[email protected]842f10652012-06-06 01:54:04826 const WebKit::WebScreenInfo& screen_info,
[email protected]cb25aa12012-08-07 19:13:43827 content::old::GuestToEmbedderChannel* guest_to_embedder_channel,
[email protected]3e3c4522012-04-13 21:16:29828 AccessibilityMode accessibility_mode) {
initial.commit09911bf2008-07-26 23:55:29829 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28830 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51831 parent_hwnd,
832 opener_id,
833 renderer_prefs,
834 webkit_prefs,
835 counter,
836 routing_id,
[email protected]9f4f3322012-01-18 22:29:56837 surface_id,
[email protected]676126f72011-01-15 00:03:51838 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46839 frame_name,
[email protected]14392a52012-05-02 20:28:44840 is_renderer_created,
841 swapped_out,
[email protected]6fd35b72012-03-01 19:46:41842 next_page_id,
[email protected]842f10652012-06-06 01:54:04843 screen_info,
[email protected]468e4902012-05-23 01:49:31844 guest_to_embedder_channel,
[email protected]3e3c4522012-04-13 21:16:29845 accessibility_mode);
initial.commit09911bf2008-07-26 23:55:29846}
847
[email protected]310ebd6302011-10-10 19:06:28848void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51849 observers_.AddObserver(observer);
850}
851
[email protected]310ebd6302011-10-10 19:06:28852void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
853 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51854 observers_.RemoveObserver(observer);
855}
856
[email protected]310ebd6302011-10-10 19:06:28857WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26858 return static_cast<WebKit::WebView*>(webwidget());
859}
860
[email protected]310ebd6302011-10-10 19:06:28861void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40862 if (!enabled) {
863 load_progress_tracker_.reset(NULL);
864 return;
865 }
866 if (load_progress_tracker_ == NULL)
867 load_progress_tracker_.reset(new LoadProgressTracker(this));
868}
869
[email protected]cb25aa12012-08-07 19:13:43870content::old::GuestToEmbedderChannel*
[email protected]7900bfdb2012-05-24 19:31:24871 RenderViewImpl::GetGuestToEmbedderChannel() const {
872 return guest_to_embedder_channel_;
873}
874
875void RenderViewImpl::SetGuestToEmbedderChannel(
[email protected]cb25aa12012-08-07 19:13:43876 content::old::GuestToEmbedderChannel* channel) {
[email protected]7900bfdb2012-05-24 19:31:24877 guest_to_embedder_channel_ = channel;
878}
879
[email protected]310ebd6302011-10-10 19:06:28880void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51881 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29882}
883
[email protected]310ebd6302011-10-10 19:06:28884void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26885 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30886 // If the renderer is visible, set initial visibility and focus state.
887 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34888#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30889 delegate->SetContainerVisibility(true);
890 if (webview() && webview()->isActive())
891 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34892#endif
[email protected]49232292010-09-03 19:07:30893 }
[email protected]784ea1ab2010-09-18 00:02:34894 // Plugins start assuming the content has focus (so that they work in
895 // environments where RenderView isn't hosting them), so we always have to
896 // set the initial state. See webplugin_delegate_impl.h for details.
897 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26898}
899
[email protected]310ebd6302011-10-10 19:06:28900void RenderViewImpl::UnregisterPluginDelegate(
901 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26902 plugin_delegates_.erase(delegate);
903}
[email protected]d8fd6fa2010-02-01 15:54:26904
[email protected]310ebd6302011-10-10 19:06:28905bool RenderViewImpl::GetPluginInfo(const GURL& url,
906 const GURL& page_url,
907 const std::string& mime_type,
908 webkit::WebPluginInfo* plugin_info,
909 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08910 bool found = false;
911 Send(new ViewHostMsg_GetPluginInfo(
912 routing_id_, url, page_url, mime_type, &found, plugin_info,
913 actual_mime_type));
914 return found;
915}
916
[email protected]7a1ec28a2012-03-28 21:10:24917void RenderViewImpl::TransferActiveWheelFlingAnimation(
918 const WebKit::WebActiveWheelFlingParameters& params) {
919 if (webview())
920 webview()->transferActiveWheelFlingAnimation(params);
921}
922
[email protected]8fe8f742012-06-14 00:36:08923bool RenderViewImpl::HasIMETextFocus() {
924 return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
925}
926
[email protected]310ebd6302011-10-10 19:06:28927bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27928 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27929 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41930 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26931
[email protected]676126f72011-01-15 00:03:51932 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
933 RenderViewObserver* observer;
934 while ((observer = it.GetNext()) != NULL)
935 if (observer->OnMessageReceived(message))
936 return true;
[email protected]b2abac72009-02-26 12:39:28937
[email protected]a95986a82010-12-24 06:19:28938 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40939 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28940 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29941 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
942 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56943 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29944 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
945 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
946 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
947 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27948#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35949 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27950#endif
initial.commit09911bf2008-07-26 23:55:29951 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15952 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29953 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
954 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
955 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]45a599062012-09-07 20:09:06956 IPC_MESSAGE_HANDLER(ViewMsg_ReplaceAll, OnReplaceAll)
957 IPC_MESSAGE_HANDLER(ViewMsg_Unselect, OnUnselect)
958 IPC_MESSAGE_HANDLER(ViewMsg_SetEditableSelectionOffsets,
959 OnSetEditableSelectionOffsets)
960 IPC_MESSAGE_HANDLER(ViewMsg_SetCompositionFromExistingText,
961 OnSetCompositionFromExistingText)
962 IPC_MESSAGE_HANDLER(ViewMsg_ExtendSelectionAndDelete,
963 OnExtendSelectionAndDelete)
[email protected]4fb60142011-08-09 02:22:08964 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29965 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15966 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29967 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49968 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
[email protected]59363fc92012-09-05 03:46:31969#if defined(OS_ANDROID)
970 IPC_MESSAGE_HANDLER(ViewMsg_ActivateNearestFindResult,
971 OnActivateNearestFindResult)
972 IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects,
973 OnFindMatchRects)
974#endif
[email protected]630e26b2008-10-14 22:55:17975 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17976 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41977 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54978 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
979 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29980 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18981 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
982 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29983 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]f546640b2012-05-15 00:03:49984 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
[email protected]1810e132009-03-24 23:35:48985 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55986 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
987 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
988 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
989 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
990 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
991 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
992 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45993 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40994 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29995 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19996 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
997 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29998 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
999 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
1000 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:511001 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
1002 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:291003 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:041004 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:151005 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:291006 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1007 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:081008 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
1009 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:001010 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:161011 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:141012 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:251013 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1014 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:471015 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:341016 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:101017 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1018 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511019 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:561020 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]77829642012-05-15 14:47:171021 IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent,
1022 OnOrientationChangeEvent)
[email protected]81375e872012-01-11 21:40:361023 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:341024 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]7a17bac02012-03-07 21:58:121025 IPC_MESSAGE_HANDLER(ViewMsg_SetNavigationStartTime,
1026 OnSetNavigationStartTime)
[email protected]6ce7abc52010-02-02 18:40:141027#if defined(OS_MACOSX)
1028 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:131029 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:131030 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1031 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:141032#endif
[email protected]446705872009-09-10 07:22:481033 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:331034 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:331035 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
1036 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:241037 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:421038 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
1039 OnPpapiBrokerChannelCreated)
[email protected]d8415ad92012-08-23 14:40:501040 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult,
1041 OnPpapiBrokerPermissionResult)
[email protected]18d5be92011-07-25 18:00:191042 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1043 OnGetAllSavableResourceLinksForCurrentPage)
1044 IPC_MESSAGE_HANDLER(
1045 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1046 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:081047#if defined(OS_MACOSX)
1048 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
[email protected]24d2b172012-05-26 00:54:121049#elif defined(OS_ANDROID)
1050 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
[email protected]caf706f2010-10-26 17:54:081051#endif
[email protected]521b2482011-01-15 00:10:101052 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:511053 // TODO(viettrungluu): Move to a separate message filter.
[email protected]54ca3ca892011-06-07 21:14:541054#if defined(OS_MACOSX)
1055 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
1056#endif
[email protected]9e1ad4b2011-08-14 16:49:191057 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
1058 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:181059 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]7f3c7af2011-10-20 22:52:511060 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]2a84f9d2012-06-05 21:50:431061 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode)
[email protected]0720b532012-08-28 19:23:371062 IPC_MESSAGE_HANDLER(ViewMsg_UpdateFrameTree, OnUpdatedFrameTree)
[email protected]9e1ad4b2011-08-14 16:49:191063
initial.commit09911bf2008-07-26 23:55:291064 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281065 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291066 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401067
1068 if (!msg_is_ok) {
1069 // The message had a handler, but its deserialization failed.
1070 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:281071 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:401072 }
1073
[email protected]a95986a82010-12-24 06:19:281074 return handled;
initial.commit09911bf2008-07-26 23:55:291075}
1076
[email protected]310ebd6302011-10-10 19:06:281077void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]7900bfdb2012-05-24 19:31:241078 // If we don't have guest-to-embedder channel associated with this RenderView
1079 // but we need one, grab one now.
1080 if (!params.embedder_channel_name.empty() && !GetGuestToEmbedderChannel()) {
[email protected]cb25aa12012-08-07 19:13:431081 content::old::GuestToEmbedderChannel* embedder_channel =
[email protected]7900bfdb2012-05-24 19:31:241082 RenderThreadImpl::current()->browser_plugin_channel_manager()->
1083 GetChannelByName(params.embedder_channel_name);
1084 DCHECK(embedder_channel);
1085 SetGuestToEmbedderChannel(embedder_channel);
1086 host_window_set_ = false;
1087 // TODO(fsamuel): This is test code. Need to find a better way to tell
1088 // a WebView to drop its context. This needs to change in
1089 // GuestToEmbedderChannel::OnContextLost.
1090 GetWebView()->loseCompositorContext(1);
1091 RenderThreadImpl::current()->browser_plugin_channel_manager()->
1092 ReportChannelToEmbedder(this,
1093 embedder_channel->embedder_channel_handle(),
1094 params.embedder_channel_name,
1095 params.embedder_container_id);
1096 }
[email protected]8bf1048012012-02-08 01:22:181097 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:291098 if (!webview())
1099 return;
1100
[email protected]440a0e52011-09-13 17:38:581101 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
1102
[email protected]007733c2011-11-17 00:34:071103 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:031104
1105 // If this is a stale back/forward (due to a recent navigation the browser
1106 // didn't know about), ignore it.
1107 if (IsBackForwardToStaleEntry(params, is_reload))
1108 return;
1109
[email protected]992db4c2011-05-12 15:37:151110 // Swap this renderer back in if necessary.
[email protected]961541a92012-06-01 21:15:281111 if (is_swapped_out_) {
1112 // We marked the view as hidden when swapping the view out, so be sure to
1113 // reset the visibility state before navigating to the new URL.
1114 webview()->setVisibilityState(visibilityState(), false);
[email protected]992db4c2011-05-12 15:37:151115 SetSwappedOut(false);
[email protected]961541a92012-06-01 21:15:281116 }
[email protected]992db4c2011-05-12 15:37:151117
[email protected]3cc72b12010-03-18 23:03:001118 history_list_offset_ = params.current_history_list_offset;
1119 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:031120 if (history_list_length_ >= 0)
1121 history_page_ids_.resize(history_list_length_, -1);
1122 if (params.pending_history_list_offset >= 0 &&
1123 params.pending_history_list_offset < history_list_length_)
1124 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:001125
[email protected]38b592902011-04-16 02:08:421126 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:291127
[email protected]26aa0482009-09-30 16:55:271128 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451129 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291130 // We cannot reload if we do not have any history state. This happens, for
1131 // example, when recovering from a crash. Our workaround here is a bit of
1132 // a hack since it means that reload after a crashed tab does not cause an
1133 // end-to-end cache validation.
1134 is_reload = false;
1135 }
1136
[email protected]007733c2011-11-17 00:34:071137 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
1138 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:501139
[email protected]04d3c6e2009-05-22 17:00:131140 // If we are reloading, then WebKit will use the history state of the current
1141 // page, so we should just ignore any given history state. Otherwise, if we
1142 // have history state, then we need to navigate to it, which corresponds to a
1143 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551144 if (is_reload) {
[email protected]7c16976c2012-08-04 02:38:231145 bool reload_original_url =
1146 (params.navigation_type ==
1147 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]ecbf10d2010-02-18 13:03:291148 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:021149 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]7c16976c2012-08-04 02:38:231150
1151 if (reload_original_url)
1152 main_frame->reloadWithOverrideURL(params.url, true);
1153 else
1154 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551155 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131156 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581157 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:451158 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171159 webkit_glue::HistoryItemFromString(params.state));
[email protected]d1ef81d2012-07-24 11:39:361160 } else if (!params.base_url_for_data_url.is_empty()) {
1161 // A loadData request with a specified base URL.
1162 std::string mime_type, charset, data;
1163 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) {
1164 main_frame->loadData(
1165 WebData(data.c_str(), data.length()),
1166 WebString::fromUTF8(mime_type),
1167 WebString::fromUTF8(charset),
1168 params.base_url_for_data_url,
1169 params.history_url_for_data_url,
1170 false);
1171 } else {
1172 CHECK(false) <<
1173 "Invalid URL passed: " << params.url.possibly_invalid_spec();
1174 }
[email protected]04d3c6e2009-05-22 17:00:131175 } else {
1176 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281177 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291178
[email protected]e6f546c32009-07-01 17:12:551179 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:231180 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131181
[email protected]dd7daa82009-08-10 05:46:451182 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551183 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131184
[email protected]445e1042011-12-03 21:03:151185 if (params.referrer.url.is_valid()) {
1186 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
1187 params.referrer.policy,
1188 params.url,
1189 WebString::fromUTF8(params.referrer.url.spec()));
1190 if (!referrer.isEmpty())
1191 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:281192 }
[email protected]04d3c6e2009-05-22 17:00:131193
[email protected]52c68652010-12-07 17:47:041194 if (!params.extra_headers.empty()) {
1195 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1196 params.extra_headers.end(), "\n");
1197 i.GetNext(); ) {
1198 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1199 WebString::fromUTF8(i.values()));
1200 }
1201 }
[email protected]132e281a2012-07-31 18:32:441202
1203 if (params.is_post) {
1204 request.setHTTPMethod(WebString::fromUTF8("POST"));
1205
1206 // Set post data.
1207 WebHTTPBody http_body;
1208 http_body.initialize();
1209 http_body.appendData(WebData(
1210 reinterpret_cast<const char*>(
1211 &params.browser_initiated_post_data.front()),
1212 params.browser_initiated_post_data.size()));
1213 request.setHTTPBody(http_body);
1214 }
1215
[email protected]dd7daa82009-08-10 05:46:451216 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501217 }
1218
[email protected]77f17a82009-05-21 04:42:541219 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:071220 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:291221}
1222
[email protected]310ebd6302011-10-10 19:06:281223bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:031224 const ViewMsg_Navigate_Params& params,
1225 bool is_reload) {
1226 // Make sure this isn't a back/forward to an entry we have already cropped
1227 // or replaced from our history, before the browser knew about it. If so,
1228 // a new navigation has committed in the mean time, and we can ignore this.
1229 bool is_back_forward = !is_reload && !params.state.empty();
1230
1231 // Note: if the history_list_length_ is 0 for a back/forward, we must be
1232 // restoring from a previous session. We'll update our state in OnNavigate.
1233 if (!is_back_forward || history_list_length_ <= 0)
1234 return false;
1235
1236 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
1237
1238 // Check for whether the forward history has been cropped due to a recent
1239 // navigation the browser didn't know about.
1240 if (params.pending_history_list_offset >= history_list_length_)
1241 return true;
1242
1243 // Check for whether this entry has been replaced with a new one.
1244 int expected_page_id =
1245 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:441246 if (expected_page_id > 0 && params.page_id != expected_page_id) {
1247 if (params.page_id < expected_page_id)
1248 return true;
1249
1250 // Otherwise we've removed an earlier entry and should have shifted all
1251 // entries left. For now, it's ok to lazily update the list.
1252 // TODO(creis): Notify all live renderers when we remove entries from
1253 // the front of the list, so that we don't hit this case.
1254 history_page_ids_[params.pending_history_list_offset] = params.page_id;
1255 }
[email protected]d466b8a2011-07-15 21:48:031256
1257 return false;
1258}
1259
initial.commit09911bf2008-07-26 23:55:291260// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:281261void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:441262 if (webview()) {
1263 WebFrame* main_frame = webview()->mainFrame();
1264 // Stop the alt error page fetcher. If we let it continue it may complete
1265 // and cause RenderViewHostManager to swap to this RenderView, even though
1266 // it may no longer be active.
1267 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
1268 StopAltErrorPageFetcher(main_frame->dataSource());
1269 main_frame->stopLoading();
1270 }
initial.commit09911bf2008-07-26 23:55:291271}
1272
[email protected]ecbf10d2010-02-18 13:03:291273// Reload current focused frame.
1274// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:281275void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291276 if (webview() && webview()->focusedFrame()) {
1277 // We always obey the cache (ignore_cache=false) here.
1278 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1279 // a cache-ignoring reload of the frame.
1280 webview()->focusedFrame()->reload(false);
1281 }
[email protected]1dda4022010-01-28 18:24:561282}
1283
[email protected]310ebd6302011-10-10 19:06:281284void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271285 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291286}
1287
[email protected]310ebd6302011-10-10 19:06:281288void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:251289 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271290 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251291 return;
1292
[email protected]26aa0482009-09-30 16:55:271293 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451294 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251295}
1296
[email protected]310ebd6302011-10-10 19:06:281297void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291298 // Check if there is a targeturl waiting to be sent.
1299 if (target_url_status_ == TARGET_PENDING) {
1300 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1301 pending_target_url_));
1302 }
1303
1304 target_url_status_ = TARGET_NONE;
1305}
1306
[email protected]310ebd6302011-10-10 19:06:281307void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:291308 if (!webview())
1309 return;
1310
[email protected]26aa0482009-09-30 16:55:271311 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:291312}
1313
[email protected]310ebd6302011-10-10 19:06:281314void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:291315 if (!webview())
1316 return;
1317
[email protected]26aa0482009-09-30 16:55:271318 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:291319}
1320
[email protected]310ebd6302011-10-10 19:06:281321void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:291322 if (!webview())
1323 return;
1324
[email protected]26aa0482009-09-30 16:55:271325 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:291326}
1327
[email protected]310ebd6302011-10-10 19:06:281328void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291329 if (!webview())
1330 return;
1331
[email protected]f6b1856b2011-06-29 22:02:531332 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
1333 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:291334}
1335
[email protected]c0cc3092009-09-12 08:27:271336#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281337void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:351338 if (!webview())
1339 return;
1340
1341 // Since the find pasteboard supports only plain text, this can be simpler
1342 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271343 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351344 if (frame->hasSelection()) {
1345 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:271346 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:171347 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:351348 }
[email protected]a954bf72009-09-12 07:30:351349}
[email protected]c0cc3092009-09-12 08:27:271350#endif
[email protected]a954bf72009-09-12 07:30:351351
[email protected]310ebd6302011-10-10 19:06:281352void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291353 if (!webview())
1354 return;
1355
[email protected]26aa0482009-09-30 16:55:271356 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:291357}
1358
[email protected]44bf7002011-10-16 02:46:151359void RenderViewImpl::OnPasteAndMatchStyle() {
1360 if (!webview())
1361 return;
1362
1363 webview()->focusedFrame()->executeCommand(
1364 WebString::fromUTF8("PasteAndMatchStyle"));
1365}
1366
[email protected]310ebd6302011-10-10 19:06:281367void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291368 if (!webview())
1369 return;
1370
[email protected]1ff7a032010-02-03 02:46:031371 WebFrame* frame = webview()->focusedFrame();
1372 if (!frame->hasSelection())
1373 frame->selectWordAroundCaret();
1374 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291375}
1376
[email protected]310ebd6302011-10-10 19:06:281377void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:291378 if (!webview())
1379 return;
1380
[email protected]26aa0482009-09-30 16:55:271381 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:291382}
1383
[email protected]310ebd6302011-10-10 19:06:281384void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291385 if (!webview())
1386 return;
1387
[email protected]26aa0482009-09-30 16:55:271388 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221389 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:291390}
1391
[email protected]45a599062012-09-07 20:09:061392void RenderViewImpl::OnReplaceAll(const string16& text) {
1393 WebNode node = GetFocusedNode();
1394 if (node.isNull() || !IsEditableNode(node))
1395 return;
1396
1397 OnSelectAll();
1398 OnReplace(text);
1399}
1400
1401void RenderViewImpl::OnUnselect() {
1402 if (!webview())
1403 return;
1404
1405 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
1406}
1407
1408void RenderViewImpl::OnSetEditableSelectionOffsets(int start, int end) {
1409 webview()->setEditableSelectionOffsets(start, end);
1410}
1411
1412void RenderViewImpl::OnSetCompositionFromExistingText(
1413 int start, int end,
1414 const std::vector<WebKit::WebCompositionUnderline>& underlines) {
1415 if (!webview())
1416 return;
1417 webview()->setCompositionFromExistingText(start, end, underlines);
1418}
1419
1420void RenderViewImpl::OnExtendSelectionAndDelete(int before, int after) {
1421 if (!webview())
1422 return;
1423 webview()->extendSelectionAndDelete(before, after);
1424}
1425
[email protected]310ebd6302011-10-10 19:06:281426void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1427 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:081428 if (!webview())
1429 return;
1430
[email protected]c95e53ad2012-08-13 17:56:161431 Send(new ViewHostMsg_SelectRange_ACK(routing_id_));
1432
[email protected]4fb60142011-08-09 02:22:081433 handling_select_range_ = true;
1434 webview()->focusedFrame()->selectRange(start, end);
1435 handling_select_range_ = false;
1436}
1437
[email protected]310ebd6302011-10-10 19:06:281438void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1439 int32 minimum_page_id) {
[email protected]e1ed5a12012-08-08 19:57:441440 DCHECK_GE(history_length, 0);
[email protected]9e1ad4b2011-08-14 16:49:191441 DCHECK(history_list_offset_ == history_list_length_ - 1);
[email protected]e1ed5a12012-08-08 19:57:441442 DCHECK_GE(minimum_page_id, -1);
[email protected]9e1ad4b2011-08-14 16:49:191443
1444 // Generate the new list.
1445 std::vector<int32> new_history_page_ids(history_length, -1);
1446 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1447 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1448 continue;
1449 new_history_page_ids.push_back(history_page_ids_[i]);
1450 }
1451 new_history_page_ids.swap(history_page_ids_);
1452
1453 // Update indexes.
1454 history_list_length_ = history_page_ids_.size();
1455 history_list_offset_ = history_list_length_ - 1;
1456}
1457
1458
[email protected]310ebd6302011-10-10 19:06:281459void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291460 if (!webview())
1461 return;
[email protected]26aa0482009-09-30 16:55:271462 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291463}
1464
[email protected]54ca3ca892011-06-07 21:14:541465#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281466void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331467 if (!webview())
1468 return;
1469 if (in_live_resize)
1470 webview()->willStartLiveResize();
1471 else
1472 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541473}
1474#endif
1475
[email protected]310ebd6302011-10-10 19:06:281476void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1477 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091478 WebKit::WebNode node = GetFocusedNode();
1479 if (!node.isNull()) {
1480 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191481 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511482 }
1483}
1484
initial.commit09911bf2008-07-26 23:55:291485///////////////////////////////////////////////////////////////////////////////
1486
1487// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281488void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451489 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291490 DCHECK(ds);
1491
[email protected]726985e22009-06-18 21:09:281492 const WebURLRequest& request = ds->request();
1493 const WebURLRequest& original_request = ds->originalRequest();
1494 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291495
[email protected]007733c2011-11-17 00:34:071496 DocumentState* document_state = DocumentState::FromDataSource(ds);
1497 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291498
1499 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281500 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291501 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051502 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291503 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071504 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191505 params.socket_address.set_host(response.remoteIPAddress().utf8());
1506 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031507 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091508 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071509 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291510 // SSL state specified in the request takes precedence over the one in the
1511 // response.
1512 // So far this is only intended for error pages that are not expected to be
1513 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281514 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071515 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291516 } else {
[email protected]726985e22009-06-18 21:09:281517 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291518 }
1519
1520 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:311521 params.url = GetLoadingUrl(frame);
initial.commit09911bf2008-07-26 23:55:291522
[email protected]5f9b8712011-11-23 08:55:571523 if (frame->document().baseURL() != params.url)
1524 params.base_url = frame->document().baseURL();
1525
[email protected]726985e22009-06-18 21:09:281526 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241527 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041528 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291529
[email protected]007733c2011-11-17 00:34:071530 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351531 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071532 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291533
1534 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071535 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291536 if (password_form_data)
1537 params.password_form = *password_form_data;
1538
1539 params.gesture = navigation_gesture_;
1540 navigation_gesture_ = NavigationGestureUnknown;
1541
[email protected]0f38dc4552011-02-25 11:24:001542 // Make navigation state a part of the FrameNavigate message so that commited
1543 // entry had it at all times.
1544 const WebHistoryItem& item = frame->currentHistoryItem();
1545 if (!item.isNull()) {
1546 params.content_state = webkit_glue::HistoryItemToString(item);
1547 } else {
1548 params.content_state =
1549 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1550 }
1551
[email protected]dd7daa82009-08-10 05:46:451552 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291553 // Top-level navigation.
1554
[email protected]d00a7972012-08-07 06:09:581555 // Reset the zoom limits in case a plugin had changed them previously. This
1556 // will also call us back which will cause us to send a message to
1557 // update WebContentsImpl.
1558 webview()->zoomLimitsChanged(
1559 WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
1560 WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
1561
[email protected]b75b8292010-10-01 07:28:251562 // Set zoom level, but don't do it for full-page plugin since they don't use
1563 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011564 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541565 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251566 if (webview()->mainFrame()->document().isPluginDocument()) {
1567 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251568 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251569 } else {
1570 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251571 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251572 }
1573
[email protected]f85f0702010-01-30 09:31:011574 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511575 // This zoom level was merely recorded transiently for this load. We can
1576 // erase it now. If at some point we reload this page, the browser will
1577 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011578 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511579 }
1580
initial.commit09911bf2008-07-26 23:55:291581 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551582 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291583
[email protected]daa8c58e2009-06-15 17:21:101584 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581585 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291586 // If the main frame does a load, it should not be reported as a subframe
1587 // navigation. This can occur in the following case:
1588 // 1. You're on a site with frames.
1589 // 2. You do a subframe navigation. This is stored with transition type
1590 // MANUAL_SUBFRAME.
1591 // 3. You navigate to some non-frame site, say, google.com.
1592 // 4. You navigate back to the page from step 2. Since it was initially
1593 // MANUAL_SUBFRAME, it will be that same transition type here.
1594 // We don't want that, because any navigation that changes the toplevel
1595 // frame should be tracked as a toplevel navigation (this allows us to
1596 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581597 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291598 }
1599
initial.commit09911bf2008-07-26 23:55:291600 // If we have a valid consumed client redirect source,
1601 // the page contained a client redirect (meta refresh, document.loc...),
1602 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151603 if (completed_client_redirect_src_.url.is_valid()) {
1604 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291605 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581606 params.transition = static_cast<content::PageTransition>(
1607 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291608 } else {
1609 // Bug 654101: the referrer will be empty on https->http transitions. It
1610 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151611 params.referrer = Referrer(GURL(
1612 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:591613 GetReferrerPolicyFromRequest(frame, original_request));
initial.commit09911bf2008-07-26 23:55:291614 }
1615
[email protected]726985e22009-06-18 21:09:281616 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051617 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291618 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051619 params.post_id = ExtractPostId(item);
1620 }
initial.commit09911bf2008-07-26 23:55:291621
[email protected]bf70edce2012-06-20 22:32:221622 // Send the user agent override back.
1623 params.is_overriding_user_agent =
1624 document_state->is_overriding_user_agent();
1625
[email protected]7c16976c2012-08-04 02:38:231626 // Track the URL of the original request.
1627 params.original_request_url = original_request.url();
1628
[email protected]c2a797d2009-09-21 16:46:321629 // Save some histogram data so we can compute the average memory used per
1630 // page load of the glyphs.
1631 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1632 webkit_glue::GetGlyphPageCount());
1633
[email protected]15cf526b2010-02-12 06:33:491634 // This message needs to be sent before any of allowScripts(),
1635 // allowImages(), allowPlugins() is called for the new page, so that when
1636 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1637 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291638 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1639 } else {
1640 // Subframe navigation: the type depends on whether this navigation
1641 // generated a new session history entry. When they do generate a session
1642 // history entry, it means the user initiated the navigation and we should
1643 // mark it as such. This test checks if this is the first time UpdateURL
1644 // has been called since WillNavigateToURL was called to initiate the load.
1645 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581646 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291647 else
[email protected]2905f742011-10-13 03:51:581648 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291649
initial.commit09911bf2008-07-26 23:55:291650 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1651 }
1652
1653 last_page_id_sent_to_browser_ =
1654 std::max(last_page_id_sent_to_browser_, page_id_);
1655
1656 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101657 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581658 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291659}
1660
1661// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281662void RenderViewImpl::UpdateTitle(WebFrame* frame,
1663 const string16& title,
1664 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461665 // Ignore all but top level navigations.
1666 if (frame->parent())
1667 return;
1668
1669 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1670 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1671 title_direction));
initial.commit09911bf2008-07-26 23:55:291672}
1673
[email protected]310ebd6302011-10-10 19:06:281674void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1675 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291676 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271677 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291678 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301679 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291680 last_encoding_name_ = encoding_name;
1681
[email protected]e38f40152008-09-12 23:08:301682 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291683 }
1684}
1685
[email protected]e15f680732010-11-23 22:30:201686// Sends the last committed session history state to the browser so it will be
1687// saved before we navigate to a new page. This must be called *before* the
1688// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281689void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291690 // If we have a valid page ID at this point, then it corresponds to the page
1691 // we are navigating away from. Otherwise, this is the first navigation, so
1692 // there is no past session history to record.
1693 if (page_id_ == -1)
1694 return;
1695
[email protected]ca948a22009-06-25 19:36:171696 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271697 webview()->mainFrame()->previousHistoryItem();
[email protected]6459800a2012-03-27 23:57:051698 SendUpdateState(item);
1699}
1700
1701void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
[email protected]ca948a22009-06-25 19:36:171702 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291703 return;
[email protected]ca948a22009-06-25 19:36:171704
[email protected]285f4bb82012-04-17 15:57:281705 // Don't send state updates for content::kSwappedOutURL.
1706 if (item.urlString() == WebString::fromUTF8(content::kSwappedOutURL))
[email protected]6459800a2012-03-27 23:57:051707 return;
1708
[email protected]ca948a22009-06-25 19:36:171709 Send(new ViewHostMsg_UpdateState(
1710 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291711}
1712
[email protected]310ebd6302011-10-10 19:06:281713void RenderViewImpl::OpenURL(WebFrame* frame,
1714 const GURL& url,
[email protected]445e1042011-12-03 21:03:151715 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281716 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171717 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581718 routing_id_,
1719 url,
1720 referrer,
1721 NavigationPolicyToDisposition(policy),
1722 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171723}
1724
[email protected]79dbc662009-09-04 05:42:511725// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291726
[email protected]310ebd6302011-10-10 19:06:281727void RenderViewImpl::LoadNavigationErrorPage(
1728 WebFrame* frame,
1729 const WebURLRequest& failed_request,
1730 const WebURLError& error,
1731 const std::string& html,
1732 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581733 std::string alt_html;
1734 const std::string* error_html;
1735
1736 if (!html.empty()) {
1737 error_html = &html;
1738 } else {
1739 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1740 failed_request, error, &alt_html, NULL);
1741 error_html = &alt_html;
1742 }
1743
1744 frame->loadHTMLString(*error_html,
[email protected]285f4bb82012-04-17 15:57:281745 GURL(content::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251746 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551747 replace);
initial.commit09911bf2008-07-26 23:55:291748}
1749
[email protected]be2510c02012-05-28 14:52:141750bool RenderViewImpl::RunJavaScriptMessage(content::JavaScriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281751 const string16& message,
1752 const string16& default_value,
1753 const GURL& frame_url,
1754 string16* result) {
initial.commit09911bf2008-07-26 23:55:291755 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411756 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291757 if (!result)
1758 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291759
[email protected]12636df2009-09-28 22:32:211760 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1761 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291762 return success;
1763}
1764
[email protected]310ebd6302011-10-10 19:06:281765bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571766 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1767 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1768 // it is particularly important that we do not call willEnterModalLoop as
1769 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441770 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1771 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571772
1773 message->EnableMessagePumping(); // Runs a nested message loop.
1774 return Send(message);
1775}
1776
[email protected]48c9cf2d2009-09-16 16:47:521777// WebKit::WebViewClient ------------------------------------------------------
1778
[email protected]916dfb62012-03-05 03:39:371779WebView* RenderViewImpl::createView(
1780 WebFrame* creator,
1781 const WebURLRequest& request,
1782 const WebWindowFeatures& features,
1783 const WebString& frame_name,
1784 WebNavigationPolicy policy) {
[email protected]48c9cf2d2009-09-16 16:47:521785 // Check to make sure we aren't overloading on popups.
1786 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1787 return NULL;
1788
[email protected]8ab04652010-06-12 02:47:261789 ViewHostMsg_CreateWindow_Params params;
1790 params.opener_id = routing_id_;
1791 params.user_gesture = creator->isProcessingUserGesture();
1792 params.window_container_type = WindowFeaturesToContainerType(features);
1793 params.session_storage_namespace_id = session_storage_namespace_id_;
1794 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111795 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411796 params.opener_url = creator->document().url();
1797 params.opener_security_origin =
1798 creator->document().securityOrigin().toString().utf8();
[email protected]f92ce2b2012-03-06 18:02:591799 params.opener_suppressed = creator->willSuppressOpenerInNewFrame();
1800 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]41e65502011-01-21 09:29:111801 if (!request.isNull())
1802 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261803
[email protected]48c9cf2d2009-09-16 16:47:521804 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561805 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341806 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521807
[email protected]7c962ee32012-08-28 21:12:501808 creator->consumeUserGesture();
[email protected]380244092011-10-07 17:26:271809 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261810 new ViewHostMsg_CreateWindow(params,
1811 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561812 &surface_id,
[email protected]8ab04652010-06-12 02:47:261813 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211814 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521815 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521816
[email protected]8cca3da2012-03-20 08:26:341817 // TODO(fsamuel): The host renderer needs to be able to control whether
1818 // the guest renderer is allowed to do this or not. This current
1819 // behavior is not well defined.
[email protected]310ebd6302011-10-10 19:06:281820 RenderViewImpl* view = RenderViewImpl::Create(
1821 0,
1822 routing_id_,
1823 renderer_preferences_,
1824 webkit_preferences_,
1825 shared_popup_counter_,
1826 routing_id,
[email protected]9f4f3322012-01-18 22:29:561827 surface_id,
[email protected]310ebd6302011-10-10 19:06:281828 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461829 frame_name,
[email protected]14392a52012-05-02 20:28:441830 true,
1831 false,
[email protected]6fd35b72012-03-01 19:46:411832 1,
[email protected]842f10652012-06-06 01:54:041833 screen_info_,
[email protected]468e4902012-05-23 01:49:311834 guest_to_embedder_channel_,
[email protected]3e3c4522012-04-13 21:16:291835 accessibility_mode_);
[email protected]8ab04652010-06-12 02:47:261836 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521837
[email protected]007a848b2009-10-26 15:55:461838 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:591839 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:461840
[email protected]48c9cf2d2009-09-16 16:47:521841 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411842 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521843 if (!creator_url.is_valid() || !creator_url.IsStandard())
1844 creator_url = GURL();
1845 view->creator_url_ = creator_url;
1846
1847 // Copy over the alternate error page URL so we can have alt error pages in
1848 // the new render view (we don't need the browser to send the URL back down).
1849 view->alternate_error_page_url_ = alternate_error_page_url_;
1850
1851 return view->webview();
1852}
1853
[email protected]310ebd6302011-10-10 19:06:281854WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:411855 RenderWidget* widget =
[email protected]842f10652012-06-06 01:54:041856 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]48c9cf2d2009-09-16 16:47:521857 return widget->webwidget();
1858}
1859
[email protected]310ebd6302011-10-10 19:06:281860WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081861 const WebPopupMenuInfo& popup_menu_info,
1862 WebExternalPopupMenuClient* popup_menu_client) {
[email protected]8de2f882012-05-30 00:32:271863 // An IPC message is sent to the browser to build and display the actual
1864 // popup. The user could have time to click a different select by the time
1865 // the popup is shown. In that case external_popup_menu_ is non NULL.
1866 // By returning NULL in that case, we instruct WebKit to cancel that new
1867 // popup. So from the user perspective, only the first one will show, and
1868 // will have to close the first one before another one can be shown.
1869 if (external_popup_menu_.get())
1870 return NULL;
[email protected]caf706f2010-10-26 17:54:081871 external_popup_menu_.reset(
1872 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1873 return external_popup_menu_.get();
1874}
1875
[email protected]310ebd6302011-10-10 19:06:281876RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521877 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531878 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421879 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411880 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531881 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]bee6eb72012-07-26 03:47:321882 routing_id_, plugin, active_url, screen_info_);
[email protected]79c7bed2010-09-14 22:28:391883 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561884 return widget;
[email protected]79c7bed2010-09-14 22:28:391885}
1886
[email protected]310ebd6302011-10-10 19:06:281887WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1888 unsigned quota) {
[email protected]b928936b2012-04-13 01:16:161889 CHECK(session_storage_namespace_id_ !=
1890 dom_storage::kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:101891 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341892}
1893
[email protected]1842fe22012-08-13 23:24:351894WebKit::WebCompositorOutputSurface* RenderViewImpl::createOutputSurface() {
1895 // TODO(aelias): if force-software-mode is on, create an output surface
1896 // without a 3D context.
1897
1898 // Explicitly disable antialiasing for the compositor. As of the time of
1899 // this writing, the only platform that supported antialiasing for the
1900 // compositor was Mac OS X, because the on-screen OpenGL context creation
1901 // code paths on Windows and Linux didn't yet have multisampling support.
1902 // Mac OS X essentially always behaves as though it's rendering offscreen.
1903 // Multisampling has a heavy cost especially on devices with relatively low
1904 // fill rate like most notebooks, and the Mac implementation would need to
1905 // be optimized to resolve directly into the IOSurface shared between the
1906 // GPU and browser processes. For these reasons and to avoid platform
1907 // disparities we explicitly disable antialiasing.
1908 WebKit::WebGraphicsContext3D::Attributes attributes;
1909 attributes.antialias = false;
1910 attributes.shareResources = true;
1911 WebGraphicsContext3D* context = CreateGraphicsContext3D(attributes);
1912 if (!context)
[email protected]7e8b4d12012-01-20 23:39:511913 return NULL;
[email protected]468e4902012-05-23 01:49:311914
[email protected]1842fe22012-08-13 23:24:351915 return new CompositorOutputSurface(routing_id(), context);
[email protected]7e8b4d12012-01-20 23:39:511916}
1917
[email protected]310ebd6302011-10-10 19:06:281918void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521919 const WebConsoleMessage& message, const WebString& source_name,
1920 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081921 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511922 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081923 case WebConsoleMessage::LevelTip:
1924 log_severity = logging::LOG_VERBOSE;
1925 break;
1926 case WebConsoleMessage::LevelLog:
1927 log_severity = logging::LOG_INFO;
1928 break;
1929 case WebConsoleMessage::LevelWarning:
1930 log_severity = logging::LOG_WARNING;
1931 break;
1932 case WebConsoleMessage::LevelError:
1933 log_severity = logging::LOG_ERROR;
1934 break;
1935 default:
1936 NOTREACHED();
1937 }
1938
[email protected]48c9cf2d2009-09-16 16:47:521939 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081940 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311941 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521942 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311943 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521944}
1945
[email protected]310ebd6302011-10-10 19:06:281946void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]b0553c7e2012-09-19 21:36:111947 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
1948 PrintPage(frame, handling_input_event_));
[email protected]48c9cf2d2009-09-16 16:47:521949}
1950
[email protected]310ebd6302011-10-10 19:06:281951WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511952 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021953}
1954
[email protected]310ebd6302011-10-10 19:06:281955bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121956 const WebString& path,
1957 WebFileChooserCompletion* chooser_completion) {
1958 int id = enumeration_completion_id_++;
1959 enumeration_completions_[id] = chooser_completion;
1960 return Send(new ViewHostMsg_EnumerateDirectory(
1961 routing_id_,
1962 id,
1963 webkit_glue::WebStringToFilePath(path)));
1964}
1965
[email protected]4b1146bc2012-07-10 18:46:031966void RenderViewImpl::initializeHelperPluginWebFrame(
1967 WebKit::WebHelperPlugin* plugin) {
1968 plugin->initializeFrame(this);
1969}
1970
[email protected]310ebd6302011-10-10 19:06:281971void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521972 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:141973 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:521974 return;
1975 }
1976
1977 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521978
1979 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311980
1981 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521982}
1983
[email protected]310ebd6302011-10-10 19:06:281984void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521985 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:141986 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:521987 return;
1988 }
1989
1990 is_loading_ = false;
1991
[email protected]0720b532012-08-28 19:23:371992 if (pending_frame_tree_update_) {
1993 pending_frame_tree_update_ = false;
1994 SendUpdatedFrameTree(NULL);
1995 }
1996
[email protected]48c9cf2d2009-09-16 16:47:521997 // NOTE: For now we're doing the safest thing, and sending out notification
1998 // when done loading. This currently isn't an issue as the favicon is only
1999 // displayed when done loading. Ideally we would send notification when
2000 // finished parsing the head, but webkit doesn't support that yet.
2001 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:522002 Send(new ViewHostMsg_DidStopLoading(routing_id_));
2003
[email protected]90109412010-12-15 17:14:242004 if (load_progress_tracker_ != NULL)
2005 load_progress_tracker_->DidStopLoading();
2006
[email protected]93b9d692011-04-13 00:44:312007 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:522008}
2009
[email protected]310ebd6302011-10-10 19:06:282010void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
2011 double load_progress) {
[email protected]90109412010-12-15 17:14:242012 if (load_progress_tracker_ != NULL)
2013 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
2014}
2015
[email protected]310ebd6302011-10-10 19:06:282016bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:062017#if defined(OS_MACOSX)
2018 return true;
2019#else
2020 return false;
2021#endif
2022}
2023
[email protected]310ebd6302011-10-10 19:06:282024bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:032025#if defined(OS_WIN)
2026 return true;
2027#else
2028 return false;
2029#endif
2030}
2031
[email protected]310ebd6302011-10-10 19:06:282032void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:082033 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:032034 return;
[email protected]4fb60142011-08-09 02:22:082035 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:012036
[email protected]fca52022012-04-03 17:00:502037 if (is_empty_selection)
2038 selection_text_.clear();
2039
[email protected]b781ff282011-08-20 06:19:362040 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:032041}
2042
[email protected]310ebd6302011-10-10 19:06:282043void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:122044 const std::string& name = UTF16ToUTF8(command_name);
2045 if (StartsWithASCII(name, "Move", true) ||
2046 StartsWithASCII(name, "Insert", true) ||
2047 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:032048 return;
[email protected]f1a29a02011-10-06 23:08:442049 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:032050}
2051
[email protected]310ebd6302011-10-10 19:06:282052bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:102053 if (edit_commands_.empty())
2054 return false;
2055
[email protected]26aa0482009-09-30 16:55:272056 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102057 if (!frame)
2058 return false;
2059
2060 EditCommands::iterator it = edit_commands_.begin();
2061 EditCommands::iterator end = edit_commands_.end();
2062
[email protected]507b33ea2009-09-29 03:56:512063 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102064 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332065 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2066 // key (but it's the exception). Once one edit command is not executed, it
2067 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102068 if (!frame->executeCommand(WebString::fromUTF8(it->name),
2069 WebString::fromUTF8(it->value)))
2070 break;
[email protected]507b33ea2009-09-29 03:56:512071 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102072 }
2073
[email protected]507b33ea2009-09-29 03:56:512074 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102075}
2076
[email protected]da8543762012-03-20 08:52:202077WebKit::WebColorChooser* RenderViewImpl::createColorChooser(
2078 WebKit::WebColorChooserClient* client,
2079 const WebKit::WebColor& initial_color) {
2080 RendererWebColorChooserImpl* color_chooser =
2081 new RendererWebColorChooserImpl(this, client);
2082 color_chooser->Open(static_cast<SkColor>(initial_color));
2083 return color_chooser;
2084}
2085
[email protected]310ebd6302011-10-10 19:06:282086bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:352087 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472088 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352089 // Do not open the file dialog in a hidden RenderView.
2090 if (is_hidden())
2091 return false;
[email protected]8caadeb2011-11-22 02:45:232092 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262093 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:232094 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:262095 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:232096 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:502097 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:232098 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:262099 else
[email protected]8caadeb2011-11-22 02:45:232100 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:472101 ipc_params.title = params.title;
2102 ipc_params.default_file_name =
2103 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]f9a4c41a2012-05-30 00:05:322104 ipc_params.accept_types.reserve(params.acceptTypes.size());
2105 for (size_t i = 0; i < params.acceptTypes.size(); ++i)
2106 ipc_params.accept_types.push_back(params.acceptTypes[i]);
[email protected]cdaf8d02010-03-30 19:52:472107
2108 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462109}
2110
[email protected]269f86d2011-12-07 02:43:472111void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
2112 const WebString& message) {
[email protected]be2510c02012-05-28 14:52:142113 RunJavaScriptMessage(content::JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:412114 message,
2115 string16(),
[email protected]b6cb3a842011-06-24 18:28:412116 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522117 NULL);
2118}
2119
[email protected]269f86d2011-12-07 02:43:472120bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
2121 const WebString& message) {
[email protected]be2510c02012-05-28 14:52:142122 return RunJavaScriptMessage(content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:412123 message,
2124 string16(),
[email protected]b6cb3a842011-06-24 18:28:412125 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522126 NULL);
2127}
2128
[email protected]269f86d2011-12-07 02:43:472129bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
2130 const WebString& message,
2131 const WebString& default_value,
2132 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:412133 string16 result;
[email protected]be2510c02012-05-28 14:52:142134 bool ok = RunJavaScriptMessage(content::JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:412135 message,
2136 default_value,
[email protected]b6cb3a842011-06-24 18:28:412137 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522138 &result);
2139 if (ok)
[email protected]4f5ce842011-05-27 19:34:412140 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:522141 return ok;
2142}
2143
[email protected]310ebd6302011-10-10 19:06:282144bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:522145 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:152146 // If we are swapping out, we have already run the beforeunload handler.
2147 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
2148 // at all, to avoid running it twice.
2149 if (is_swapped_out_)
2150 return true;
2151
[email protected]3b3301f62012-02-29 04:32:322152 bool is_reload = false;
2153 WebDataSource* ds = frame->provisionalDataSource();
2154 if (ds)
2155 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
2156
[email protected]48c9cf2d2009-09-16 16:47:522157 bool success = false;
2158 // This is an ignored return value, but is included so we can accept the same
2159 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:412160 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:212161 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:322162 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:412163 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522164 return success;
2165}
2166
[email protected]310ebd6302011-10-10 19:06:282167void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:442168 WebFrame* frame, const WebContextMenuData& data) {
[email protected]8f635f82012-06-22 22:02:442169 // TODO(fsamuel): In the future, we might want the embedder to be able to
2170 // decide whether the guest can show a context menu or not. See
2171 // http://www.crbug.com/134207
2172 if (GetGuestToEmbedderChannel())
2173 return;
2174
[email protected]35be7ec2012-02-12 20:42:512175 content::ContextMenuParams params(data);
[email protected]7fcd9b72011-07-27 16:52:372176
2177 // frame is NULL if invoked by BlockedPlugin.
2178 if (frame)
2179 params.frame_id = frame->identifier();
2180
[email protected]db803aae2011-03-05 02:00:422181 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:272182 // it. We replace it with an empty GURL so the appropriate items are disabled
2183 // in the context menu.
2184 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2185 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:422186 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:272187 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102188 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:292189 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442190}
2191
[email protected]310ebd6302011-10-10 19:06:282192void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:522193}
2194
[email protected]310ebd6302011-10-10 19:06:282195void RenderViewImpl::UpdateTargetURL(const GURL& url,
2196 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582197 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522198 if (latest_url == target_url_)
2199 return;
[email protected]163f8242009-10-30 20:19:552200
[email protected]48c9cf2d2009-09-16 16:47:522201 // Tell the browser to display a destination link.
2202 if (target_url_status_ == TARGET_INFLIGHT ||
2203 target_url_status_ == TARGET_PENDING) {
2204 // If we have a request in-flight, save the URL to be sent when we
2205 // receive an ACK to the in-flight request. We can happily overwrite
2206 // any existing pending sends.
2207 pending_target_url_ = latest_url;
2208 target_url_status_ = TARGET_PENDING;
2209 } else {
[email protected]c85f0212011-11-04 16:54:412210 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
2211 // see |ParamTraits<GURL>|.
2212 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
2213 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:522214 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2215 target_url_ = latest_url;
2216 target_url_status_ = TARGET_INFLIGHT;
2217 }
2218}
2219
[email protected]310ebd6302011-10-10 19:06:282220void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:312221 int delay;
2222 if (send_content_state_immediately_)
2223 delay = 0;
2224 else if (is_hidden())
2225 delay = kDelaySecondsForContentStateSyncHidden;
2226 else
2227 delay = kDelaySecondsForContentStateSync;
2228
2229 if (nav_state_sync_timer_.IsRunning()) {
2230 // The timer is already running. If the delay of the timer maches the amount
2231 // we want to delay by, then return. Otherwise stop the timer so that it
2232 // gets started with the right delay.
2233 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2234 return;
2235 nav_state_sync_timer_.Stop();
2236 }
2237
[email protected]d323a172011-09-02 18:23:022238 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:282239 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:312240}
2241
[email protected]310ebd6302011-10-10 19:06:282242void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552243 mouse_over_url_ = GURL(url);
2244 UpdateTargetURL(mouse_over_url_, focus_url_);
2245}
2246
[email protected]310ebd6302011-10-10 19:06:282247void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552248 focus_url_ = GURL(url);
2249 UpdateTargetURL(focus_url_, mouse_over_url_);
2250}
2251
[email protected]0407e422012-05-18 19:51:252252void RenderViewImpl::startDragging(WebFrame* frame,
2253 const WebDragData& data,
[email protected]310ebd6302011-10-10 19:06:282254 WebDragOperationsMask mask,
2255 const WebImage& image,
2256 const WebPoint& imageOffset) {
[email protected]b67151d2012-05-25 23:23:242257 WebDropData drop_data(data);
2258 drop_data.referrer_policy = frame->document().referrerPolicy();
[email protected]59f4f2fa2011-03-23 01:00:552259 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]b67151d2012-05-25 23:23:242260 drop_data,
[email protected]c27ae592010-03-18 15:24:412261 mask,
[email protected]976127072012-05-10 20:08:112262 image.getSkBitmap(),
[email protected]c27ae592010-03-18 15:24:412263 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522264}
2265
[email protected]310ebd6302011-10-10 19:06:282266bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:452267 return renderer_preferences_.can_accept_load_drops;
2268}
2269
[email protected]310ebd6302011-10-10 19:06:282270void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:522271 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2272}
2273
[email protected]310ebd6302011-10-10 19:06:282274void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:522275 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2276}
2277
[email protected]310ebd6302011-10-10 19:06:282278void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512279 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072280
[email protected]38b592902011-04-16 02:08:422281 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:492282}
2283
[email protected]169d4282011-11-30 19:33:592284void RenderViewImpl::didUpdateLayout() {
2285 // We don't always want to set up a timer, only if we've been put in that
2286 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2287 // message.
2288 if (!send_preferred_size_changes_ || !webview())
2289 return;
2290
2291 if (check_preferred_size_timer_.IsRunning())
2292 return;
2293 check_preferred_size_timer_.Start(FROM_HERE,
2294 TimeDelta::FromMilliseconds(0), this,
2295 &RenderViewImpl::CheckPreferredSize);
2296}
2297
[email protected]310ebd6302011-10-10 19:06:282298void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522299 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2300}
2301
[email protected]310ebd6302011-10-10 19:06:282302int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002303 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522304}
2305
[email protected]310ebd6302011-10-10 19:06:282306int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002307 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522308}
2309
[email protected]310ebd6302011-10-10 19:06:282310void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:322311 const WebAccessibilityObject& obj,
2312 WebAccessibilityNotification notification) {
[email protected]2a84f9d2012-06-05 21:50:432313 if (renderer_accessibility_) {
2314 renderer_accessibility_->HandleWebAccessibilityNotification(
2315 obj, notification);
2316 }
[email protected]063afcb2011-09-29 07:54:322317}
2318
[email protected]310ebd6302011-10-10 19:06:282319void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:142320 const WebString& value) {
2321 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2322 key.utf8(),
2323 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262324}
2325
[email protected]79dbc662009-09-04 05:42:512326// WebKit::WebWidgetClient ----------------------------------------------------
2327
[email protected]310ebd6302011-10-10 19:06:282328void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122329 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2330 // we won't have to test for user gesture anymore and we can
2331 // move that code back to render_widget.cc
2332 if (webview() && webview()->mainFrame() &&
2333 webview()->mainFrame()->isProcessingUserGesture()) {
2334 Send(new ViewHostMsg_Focus(routing_id_));
2335 }
2336}
2337
[email protected]310ebd6302011-10-10 19:06:282338void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122339 // TODO(jcivelli): see TODO above in didFocus().
2340 if (webview() && webview()->mainFrame() &&
2341 webview()->mainFrame()->isProcessingUserGesture()) {
2342 Send(new ViewHostMsg_Blur(routing_id_));
2343 }
2344}
2345
initial.commit09911bf2008-07-26 23:55:292346// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282347// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292348// point to dispatch the ShowView message.
2349//
2350// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282351// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292352//
[email protected]310ebd6302011-10-10 19:06:282353void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292354 DCHECK(!did_show_) << "received extraneous Show call";
2355 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2356
2357 if (did_show_)
2358 return;
2359 did_show_ = true;
2360
[email protected]6779aa12011-03-29 17:32:242361 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:042362 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:042363
[email protected]28295ec2009-10-16 05:34:332364 // Force new windows to a popup if they were not opened with a user gesture.
2365 if (!opened_by_user_gesture_) {
2366 // We exempt background tabs for compat with older versions of Chrome.
2367 // TODO(darin): This seems bogus. These should have a user gesture, so
2368 // we probably don't need this check.
2369 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2370 policy = WebKit::WebNavigationPolicyNewPopup;
2371 }
2372
initial.commit09911bf2008-07-26 23:55:292373 // NOTE: initial_pos_ may still have its default values at this point, but
2374 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2375 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282376 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2377 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292378 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242379 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292380}
2381
[email protected]310ebd6302011-10-10 19:06:282382void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292383 DCHECK(did_show_) << "should already have shown the view";
2384
[email protected]c1f50aa2010-02-18 03:46:572385 // We must keep WebKit's shared timer running in this case in order to allow
2386 // showModalDialog to function properly.
2387 //
2388 // TODO(darin): WebKit should really be smarter about suppressing events and
2389 // timers so that we do not need to manage the shared timer in such a heavy
2390 // handed manner.
2391 //
[email protected]f1a29a02011-10-06 23:08:442392 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2393 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572394
[email protected]08a1c8102012-05-11 23:14:262395 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
2396 routing_id_, opener_id_));
initial.commit09911bf2008-07-26 23:55:292397}
2398
[email protected]2b624c562011-10-27 22:58:262399bool RenderViewImpl::enterFullScreen() {
2400 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2401 return true;
2402}
2403
2404void RenderViewImpl::exitFullScreen() {
2405 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2406}
2407
[email protected]217690d2012-01-27 07:33:112408bool RenderViewImpl::requestPointerLock() {
2409 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2410}
2411
2412void RenderViewImpl::requestPointerUnlock() {
2413 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2414}
2415
2416bool RenderViewImpl::isPointerLocked() {
2417 return mouse_lock_dispatcher_->IsMouseLockedTo(
2418 webwidget_mouse_lock_target_.get());
2419}
2420
[email protected]7a1ec28a2012-03-28 21:10:242421void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
2422 CompositorThread* compositor_thread =
2423 RenderThreadImpl::current()->compositor_thread();
2424 if (compositor_thread)
2425 compositor_thread->AddInputHandler(
2426 routing_id_, input_handler_identifier, AsWeakPtr());
2427
2428 RenderWidget::didActivateCompositor(input_handler_identifier);
2429}
2430
[email protected]3d9689372009-09-10 04:29:172431// WebKit::WebFrameClient -----------------------------------------------------
2432
[email protected]310ebd6302011-10-10 19:06:282433WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2434 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:552435 WebPlugin* plugin = NULL;
2436 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
2437 this, frame, params, &plugin)) {
2438 return plugin;
2439 }
2440
[email protected]e6e56752012-08-10 00:46:062441 // TODO(fsamuel): Remove this once upstreaming of the new browser plugin is
2442 // complete.
2443 if (UTF16ToASCII(params.mimeType) == content::kBrowserPluginNewMimeType) {
2444 return content::BrowserPluginManager::Get()->
2445 CreateBrowserPlugin(this, frame, params);
2446 }
2447
[email protected]c64e4d52012-06-20 23:09:062448 if (UTF16ToASCII(params.mimeType) == content::kBrowserPluginMimeType)
[email protected]cb25aa12012-08-07 19:13:432449 return content::old::BrowserPlugin::Create(this, frame, params);
[email protected]b1c4de4c2012-06-08 00:04:562450
[email protected]a813c8e2011-10-08 01:34:112451 webkit::WebPluginInfo info;
2452 std::string mime_type;
2453 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2454 params.mimeType.utf8(), &info, &mime_type);
2455 if (!found)
2456 return NULL;
2457
2458 WebPluginParams params_to_use = params;
2459 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312460 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172461}
2462
[email protected]6ac77cb2012-05-01 14:49:012463WebPlugin* RenderViewImpl::createPluginReplacement(
2464 WebFrame* frame,
2465 const WebPluginParams& params) {
2466 webkit::WebPluginInfo info;
2467 std::string mime_type;
2468 GetPluginInfo(params.url, frame->top()->document().url(),
2469 params.mimeType.utf8(), &info, &mime_type);
2470 return content::GetContentClient()->renderer()->CreatePluginReplacement(
2471 this, info.path);
2472}
2473
[email protected]310ebd6302011-10-10 19:06:282474WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422475 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372476 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422477
[email protected]30447b62009-11-13 01:13:372478 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512479 bool exists = false;
[email protected]30447b62009-11-13 01:13:372480 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512481 ViewHostMsg_CreateWorker_Params params;
2482 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512483 params.name = name;
2484 params.document_id = document_id;
2485 params.render_view_route_id = routing_id_;
2486 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232487 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372488 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512489 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372490 if (url_mismatch) {
2491 return NULL;
2492 } else {
[email protected]f1a29a02011-10-06 23:08:442493 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492494 document_id,
[email protected]6de0bcf2010-02-17 22:00:512495 exists,
[email protected]30447b62009-11-13 01:13:372496 route_id,
2497 routing_id_);
2498 }
[email protected]9c00f002009-11-05 22:37:422499}
2500
[email protected]97b150db2012-08-16 18:26:022501WebMediaPlayer* RenderViewImpl::createMediaPlayer(
2502 WebFrame* frame, const WebKit::WebURL& url, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442503 FOR_EACH_OBSERVER(
2504 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172505
[email protected]780fc8242012-09-19 20:28:522506 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
[email protected]25fb9b32012-04-27 03:21:552507#if defined(OS_ANDROID)
[email protected]dbd3d212012-07-13 02:17:222508 // TODO(qinmin): upstream the implementation of getting WebGraphicsContext3D
2509 // and GpuChannelHost here to replace the NULL params.
[email protected]780fc8242012-09-19 20:28:522510 if (cmd_line->HasSwitch(switches::kMediaPlayerInRenderProcess)) {
2511 if (!media_bridge_manager_.get()) {
2512 media_bridge_manager_.reset(
2513 new webkit_media::MediaPlayerBridgeManagerImpl(1));
2514 }
2515 return new webkit_media::WebMediaPlayerInProcessAndroid(
2516 frame,
2517 client,
2518 cookieJar(frame),
2519 media_player_manager_.get(),
2520 media_bridge_manager_.get(),
2521 new content::StreamTextureFactoryImpl(
2522 NULL, NULL, routing_id_),
2523 cmd_line->HasSwitch(switches::kDisableMediaHistoryLogging));
2524 }
2525 if (!media_player_proxy_) {
2526 media_player_proxy_ = new content::WebMediaPlayerProxyImplAndroid(
2527 this, media_player_manager_.get());
2528 }
2529 return new webkit_media::WebMediaPlayerImplAndroid(
2530 frame,
2531 client,
2532 media_player_manager_.get(),
2533 media_player_proxy_,
2534 new content::StreamTextureFactoryImpl(
2535 NULL, NULL, routing_id_));
[email protected]25fb9b32012-04-27 03:21:552536#endif
2537
[email protected]bb6fd402011-12-09 02:45:442538 media::MessageLoopFactory* message_loop_factory =
[email protected]b80322902012-03-06 01:33:502539 new media::MessageLoopFactory();
[email protected]bb6fd402011-12-09 02:45:442540 media::FilterCollection* collection = new media::FilterCollection();
2541 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372542
[email protected]9e2269d2012-01-07 00:06:212543 RenderAudioSourceProvider* audio_source_provider = NULL;
2544
[email protected]3d9689372009-09-10 04:29:172545 // Add in any custom filter factories first.
[email protected]3d9689372009-09-10 04:29:172546 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212547 // audio_source_provider is a "provider" to WebKit, and a sink
2548 // from the perspective of the audio renderer.
2549 audio_source_provider = new RenderAudioSourceProvider();
2550
2551 // Add the chrome specific audio renderer, using audio_source_provider
2552 // as the sink.
[email protected]37136d162012-04-09 23:39:192553 media::AudioRendererImpl* audio_renderer =
2554 new media::AudioRendererImpl(audio_source_provider);
[email protected]9e2269d2012-01-07 00:06:212555 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172556 }
2557
[email protected]15d206e2012-08-17 22:35:132558 WebGraphicsContext3DCommandBufferImpl* context3d = NULL;
2559 if (!CommandLine::ForCurrentProcess()->HasSwitch(
2560 switches::kDisableAcceleratedVideoDecode))
2561 context3d = RenderThreadImpl::current()->GetGpuVDAContext3D();
[email protected]851334d2012-06-15 22:39:312562 if (context3d) {
[email protected]084c8552012-08-12 22:51:202563 scoped_refptr<base::MessageLoopProxy> factories_loop =
[email protected]84a83e192012-03-09 18:43:402564 RenderThreadImpl::current()->compositor_thread() ?
2565 RenderThreadImpl::current()->compositor_thread()->GetWebThread()
[email protected]084c8552012-08-12 22:51:202566 ->message_loop()->message_loop_proxy() :
2567 base::MessageLoopProxy::current();
[email protected]e1d69d762011-12-13 05:12:182568 GpuChannelHost* gpu_channel_host =
2569 RenderThreadImpl::current()->EstablishGpuChannelSync(
2570 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
[email protected]873da262012-08-10 22:02:472571 collection->GetVideoDecoders()->push_back(new media::GpuVideoDecoder(
[email protected]084c8552012-08-12 22:51:202572 base::Bind(&media::MessageLoopFactory::GetMessageLoop,
2573 base::Unretained(message_loop_factory),
[email protected]c462c902012-09-06 13:13:422574 media::MessageLoopFactory::kDecoder),
[email protected]84a83e192012-03-09 18:43:402575 factories_loop,
[email protected]8d4359282012-01-14 00:53:312576 new RendererGpuVideoDecoderFactories(
[email protected]84a83e192012-03-09 18:43:402577 gpu_channel_host, factories_loop, context3d)));
[email protected]e1d69d762011-12-13 05:12:182578 }
[email protected]e1d69d762011-12-13 05:12:182579
[email protected]5d65fe92012-06-02 00:48:552580 WebMediaPlayer* media_player =
[email protected]da952fd2012-01-13 03:49:252581 content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
2582 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1113bfdf2012-07-16 21:46:102583 audio_source_provider, message_loop_factory, media_stream_impl_,
2584 render_media_log);
[email protected]da952fd2012-01-13 03:49:252585 if (!media_player) {
[email protected]cec4eb82012-01-12 17:51:562586 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252587 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1113bfdf2012-07-16 21:46:102588 audio_source_provider, message_loop_factory, media_stream_impl_,
2589 render_media_log);
[email protected]bb6fd402011-12-09 02:45:442590 }
[email protected]cec4eb82012-01-12 17:51:562591 return media_player;
[email protected]3d9689372009-09-10 04:29:172592}
2593
[email protected]310ebd6302011-10-10 19:06:282594WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212595 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232596 if (!frame || !frame->view())
2597 return NULL;
[email protected]035545f2010-04-09 13:10:212598 return new RendererWebApplicationCacheHostImpl(
2599 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442600 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212601}
2602
[email protected]310ebd6302011-10-10 19:06:282603WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382604 return &cookie_jar_;
2605}
2606
[email protected]0720b532012-08-28 19:23:372607void RenderViewImpl::didCreateFrame(WebFrame* parent, WebFrame* child) {
2608 if (is_loading_) {
2609 pending_frame_tree_update_ = true;
2610 return;
2611 }
2612 if (!updating_frame_tree_)
2613 SendUpdatedFrameTree(NULL);
2614}
2615
[email protected]310ebd6302011-10-10 19:06:282616void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]0720b532012-08-28 19:23:372617 if (is_loading_) {
2618 pending_frame_tree_update_ = true;
2619 // Make sure observers are notified, even if we return right away.
2620 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
2621 return;
2622 }
2623 if (!updating_frame_tree_)
2624 SendUpdatedFrameTree(frame);
2625
[email protected]676126f72011-01-15 00:03:512626 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452627}
2628
[email protected]310ebd6302011-10-10 19:06:282629void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512630 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172631}
2632
[email protected]310ebd6302011-10-10 19:06:282633void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172634 WebFrame* frame, const WebURLRequest& request,
2635 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342636 loadURLExternally(frame, request, policy, WebString());
2637}
2638
[email protected]5e92282f2012-08-17 08:11:572639void RenderViewImpl::Repaint(const gfx::Size& size) {
2640 OnMsgRepaint(size);
2641}
2642
[email protected]310ebd6302011-10-10 19:06:282643void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342644 WebFrame* frame, const WebURLRequest& request,
2645 WebNavigationPolicy policy,
2646 const WebString& suggested_name) {
[email protected]56505542012-05-12 00:25:372647 Referrer referrer(
2648 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2649 GetReferrerPolicyFromRequest(frame, request));
[email protected]efce17b2009-09-11 18:04:592650 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342651 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2652 suggested_name));
[email protected]efce17b2009-09-11 18:04:592653 } else {
[email protected]56505542012-05-12 00:25:372654 OpenURL(frame, request.url(), referrer, policy);
[email protected]efce17b2009-09-11 18:04:592655 }
[email protected]3d9689372009-09-10 04:29:172656}
2657
[email protected]310ebd6302011-10-10 19:06:282658WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172659 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222660 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]0639c063a2012-03-22 20:55:332661 Referrer referrer(
2662 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:592663 GetReferrerPolicyFromRequest(frame, request));
[email protected]0639c063a2012-03-22 20:55:332664
[email protected]992db4c2011-05-12 15:37:152665 if (is_swapped_out_) {
[email protected]285f4bb82012-04-17 15:57:282666 if (request.url() != GURL(content::kSwappedOutURL)) {
[email protected]0639c063a2012-03-22 20:55:332667 // Targeted links may try to navigate a swapped out frame. Allow the
2668 // browser process to navigate the tab instead. Note that it is also
2669 // possible for non-targeted navigations (from this view) to arrive
2670 // here just after we are swapped out. It's ok to send them to the
2671 // browser, as long as they're for the top level frame.
2672 // TODO(creis): Ensure this supports targeted form submissions when
2673 // fixing http://crbug.com/101395.
2674 if (frame->parent() == NULL) {
2675 OpenURL(frame, request.url(), referrer, default_policy);
2676 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2677 }
2678
2679 // We should otherwise ignore in-process iframe navigations, if they
2680 // arrive just after we are swapped out.
[email protected]73eb2602012-02-09 19:50:552681 return WebKit::WebNavigationPolicyIgnore;
[email protected]0639c063a2012-03-22 20:55:332682 }
[email protected]73eb2602012-02-09 19:50:552683
[email protected]285f4bb82012-04-17 15:57:282684 // Allow content::kSwappedOutURL to complete.
[email protected]992db4c2011-05-12 15:37:152685 return default_policy;
2686 }
2687
[email protected]3d9689372009-09-10 04:29:172688 // Webkit is asking whether to navigate to a new URL.
2689 // This is fine normally, except if we're showing UI from one security
2690 // context and they're trying to navigate to a different context.
2691 const GURL& url = request.url();
2692
[email protected]d19ea342011-04-20 20:31:132693 // A content initiated navigation may have originated from a link-click,
2694 // script, drag-n-drop operation, etc.
2695 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072696 DocumentState::FromDataSource(frame->provisionalDataSource())->
2697 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132698
[email protected]a8c269a2011-10-25 20:17:222699 // Experimental:
2700 // If --enable-strict-site-isolation is enabled, send all top-level
2701 // navigations to the browser to let it swap processes when crossing site
2702 // boundaries. This is currently expected to break some script calls and
2703 // navigations, such as form submissions.
2704 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102705 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2706 !frame->parent() && (is_content_initiated || is_redirect)) {
2707 WebString origin_str = frame->document().securityOrigin().toString();
2708 GURL frame_url(origin_str.utf8().data());
[email protected]18fb7a772012-09-20 19:25:092709 // TODO(cevans): revisit whether this site check is still necessary once
[email protected]313b80bd2011-11-23 03:49:102710 // crbug.com/101395 is fixed.
[email protected]18fb7a772012-09-20 19:25:092711 if (!net::RegistryControlledDomainService::SameDomainOrHost(frame_url,
2712 url) ||
2713 frame_url.scheme() != url.scheme()) {
[email protected]313b80bd2011-11-23 03:49:102714 OpenURL(frame, url, referrer, default_policy);
2715 return WebKit::WebNavigationPolicyIgnore;
2716 }
[email protected]a8c269a2011-10-25 20:17:222717 }
2718
[email protected]fd3238af2012-05-22 18:55:302719 // If the browser is interested, then give it a chance to look at the request.
[email protected]5f000f272012-01-19 05:25:082720 if (is_content_initiated) {
[email protected]fd3238af2012-05-22 18:55:302721 bool browser_handles_request =
2722 renderer_preferences_.browser_handles_non_local_top_level_requests &&
[email protected]5f000f272012-01-19 05:25:082723 IsNonLocalTopLevelNavigation(url, frame, type);
[email protected]fd3238af2012-05-22 18:55:302724 if (!browser_handles_request) {
2725 browser_handles_request =
2726 renderer_preferences_.browser_handles_all_top_level_requests &&
2727 IsTopLevelNavigation(frame);
2728 }
2729
2730 if (browser_handles_request) {
[email protected]5f000f272012-01-19 05:25:082731 // Reset these counters as the RenderView could be reused for the next
2732 // navigation.
2733 page_id_ = -1;
2734 last_page_id_sent_to_browser_ = -1;
2735 OpenURL(frame, url, referrer, default_policy);
2736 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2737 }
[email protected]3d9689372009-09-10 04:29:172738 }
2739
[email protected]dc67e1c32012-06-08 00:10:402740 // Use the frame's original request's URL rather than the document's URL for
2741 // subsequent checks. For a popup, the document's URL may become the opener
2742 // window's URL if the opener has called document.write().
2743 // See http://crbug.com/93517.
2744 GURL old_url(frame->dataSource()->request().url());
2745
[email protected]6101c342010-12-16 22:44:372746 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552747 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:042748 // top-level navigations (not iframes). But we sometimes navigate to
2749 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:372750 //
[email protected]744c2a22012-03-15 18:42:042751 // Note: this is known to break POST submissions when crossing process
2752 // boundaries until http://crbug.com/101395 is fixed. This is better for
2753 // security than loading a WebUI, extension or app page in the wrong process.
2754 // POST requests don't work because this mechanism does not preserve form
2755 // POST data. We will need to send the request's httpBody data up to the
2756 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:572757 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2758 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222759 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:042760 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:372761 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:042762
2763 // All navigations to WebUI URLs or within WebUI-enabled RenderProcesses
2764 // must be handled by the browser process so that the correct bindings and
2765 // data sources can be registered.
2766 // Similarly, navigations to view-source URLs or within ViewSource mode
2767 // must be handled by the browser process.
[email protected]dc67e1c32012-06-08 00:10:402768 // Lastly, access to file:// URLs from non-file:// URL pages must be
2769 // handled by the browser so that ordinary renderer processes don't get
2770 // blessed with file permissions.
2771 int cumulative_bindings = RenderProcess::current()->GetEnabledBindings();
2772 bool is_initial_navigation = page_id_ == -1;
[email protected]6101c342010-12-16 22:44:372773 bool should_fork =
[email protected]744c2a22012-03-15 18:42:042774 content::GetContentClient()->HasWebUIScheme(url) ||
2775 (cumulative_bindings & content::BINDINGS_POLICY_WEB_UI) ||
2776 url.SchemeIs(chrome::kViewSourceScheme) ||
2777 frame->isViewSourceModeEnabled();
[email protected]5351dbc2010-08-27 15:22:112778
[email protected]dc67e1c32012-06-08 00:10:402779 if (!should_fork && url.SchemeIs(chrome::kFileScheme)) {
2780 // Fork non-file to file opens. Check the opener URL if this is the
2781 // initial navigation in a newly opened window.
2782 GURL source_url(old_url);
2783 if (is_initial_navigation && source_url.is_empty() && frame->opener())
2784 source_url = frame->opener()->top()->document().url();
2785 DCHECK(!source_url.is_empty());
2786 should_fork = !source_url.SchemeIs(chrome::kFileScheme);
2787 }
2788
[email protected]e48869a2011-04-01 19:56:032789 if (!should_fork) {
2790 // Give the embedder a chance.
[email protected]744c2a22012-03-15 18:42:042791 // For now, we skip this for POST submissions. This is because
2792 // http://crbug.com/101395 is more likely to cause compatibility issues
2793 // with hosted apps and extensions than WebUI pages. We will remove this
2794 // check when cross-process POST submissions are supported.
2795 if (request.httpMethod() == "GET") {
[email protected]744c2a22012-03-15 18:42:042796 should_fork = content::GetContentClient()->renderer()->ShouldFork(
2797 frame, url, is_initial_navigation, &send_referrer);
2798 }
[email protected]6101c342010-12-16 22:44:372799 }
2800
2801 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152802 OpenURL(
2803 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112804 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2805 }
[email protected]3d9689372009-09-10 04:29:172806 }
2807
2808 // Detect when a page is "forking" a new tab that can be safely rendered in
2809 // its own process. This is done by sites like Gmail that try to open links
2810 // in new windows without script connections back to the original page. We
2811 // treat such cases as browser navigations (in which we will create a new
2812 // renderer for a cross-site navigation), rather than WebKit navigations.
2813 //
2814 // We use the following heuristic to decide whether to fork a new page in its
2815 // own process:
2816 // The parent page must open a new tab to about:blank, set the new tab's
2817 // window.opener to null, and then redirect the tab to a cross-site URL using
2818 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462819 //
2820 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2821 // (see below).
[email protected]3d9689372009-09-10 04:29:172822 bool is_fork =
2823 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582824 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172825 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522826 historyBackListCount() < 1 &&
2827 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172828 // The parent page must have set the child's window.opener to null before
2829 // redirecting to the desired URL.
2830 frame->opener() == NULL &&
2831 // Must be a top-level frame.
2832 frame->parent() == NULL &&
2833 // Must not have issued the request from this page.
2834 is_content_initiated &&
2835 // Must be targeted at the current tab.
2836 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2837 // Must be a JavaScript navigation, which appears as "other".
2838 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462839
[email protected]f92ce2b2012-03-06 18:02:592840 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:172841 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152842 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172843 return WebKit::WebNavigationPolicyIgnore;
2844 }
2845
2846 return default_policy;
2847}
2848
[email protected]310ebd6302011-10-10 19:06:282849bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492850 WebFrame* frame, const WebURLRequest& request) {
2851 // We allow WebKit to think that everything can be handled even though
2852 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342853 return true;
2854}
2855
[email protected]310ebd6302011-10-10 19:06:282856WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492857 WebFrame* frame, const WebURLRequest& request) {
2858 NOTREACHED(); // Since we said we can handle all requests.
2859 return WebURLError();
2860}
2861
[email protected]310ebd6302011-10-10 19:06:282862WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492863 WebFrame* frame, const WebURLRequest& request) {
2864 WebURLError error;
2865 error.domain = WebString::fromUTF8(net::kErrorDomain);
2866 error.reason = net::ERR_ABORTED;
2867 error.unreachableURL = request.url();
2868 return error;
[email protected]7b7a7dc2009-10-19 02:23:342869}
2870
[email protected]310ebd6302011-10-10 19:06:282871void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492872 WebFrame*, const WebURLError&) {
2873 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342874}
2875
[email protected]310ebd6302011-10-10 19:06:282876void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432877 const WebKit::WebFormElement& form) {
2878 // Some login forms have onSubmit handlers that put a hash of the password
2879 // into a hidden field and then clear the password. (Issue 28910.)
2880 // This method gets called before any of those handlers run, so save away
2881 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072882 DocumentState* document_state =
2883 DocumentState::FromDataSource(frame->dataSource());
2884 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432885 PasswordFormDomManager::CreatePasswordForm(form));
2886}
2887
[email protected]310ebd6302011-10-10 19:06:282888void RenderViewImpl::willSubmitForm(WebFrame* frame,
2889 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072890 DocumentState* document_state =
2891 DocumentState::FromDataSource(frame->provisionalDataSource());
2892 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172893
[email protected]2905f742011-10-13 03:51:582894 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2895 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172896
2897 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352898 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072899 document_state->set_searchable_form_url(web_searchable_form_data.url());
2900 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212901 web_searchable_form_data.encoding().utf8());
[email protected]a045f4e32012-08-31 09:36:072902 scoped_ptr<PasswordForm> password_form_data =
[email protected]90eeddb2010-05-06 21:06:432903 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]90eeddb2010-05-06 21:06:432904
[email protected]098c95cb2011-04-28 16:49:012905 // In order to save the password that the user actually typed and not one
2906 // that may have gotten transformed by the site prior to submit, recover it
2907 // from the form contents already stored by |willSendSubmitEvent| into the
2908 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2909 // which is what we're storing into now.)
[email protected]a045f4e32012-08-31 09:36:072910 if (password_form_data.get()) {
[email protected]007733c2011-11-17 00:34:072911 DocumentState* old_document_state =
2912 DocumentState::FromDataSource(frame->dataSource());
2913 if (old_document_state) {
2914 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432915 if (old_form_data && old_form_data->action == password_form_data->action)
2916 password_form_data->password_value = old_form_data->password_value;
2917 }
2918 }
[email protected]3d9689372009-09-10 04:29:172919
[email protected]a045f4e32012-08-31 09:36:072920 document_state->set_password_form_data(password_form_data.Pass());
2921
[email protected]2a5b1732011-04-01 23:55:552922 FOR_EACH_OBSERVER(
2923 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172924}
2925
[email protected]310ebd6302011-10-10 19:06:282926void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172927 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2928 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382929 FOR_EACH_OBSERVER(
2930 RenderViewObserver, observers_,
2931 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172932}
2933
[email protected]310ebd6302011-10-10 19:06:282934void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382935 FOR_EACH_OBSERVER(
2936 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172937}
2938
[email protected]310ebd6302011-10-10 19:06:282939void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172940 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152941 if (!frame->parent()) {
2942 WebDataSource* ds = frame->provisionalDataSource();
2943 // If there's no provisional data source, it's a reference fragment
2944 // navigation.
2945 completed_client_redirect_src_ = Referrer(
[email protected]ca662822012-05-11 17:53:592946 from, ds ? GetReferrerPolicyFromRequest(frame, ds->request()) :
[email protected]f36f4092012-05-09 18:31:042947 frame->document().referrerPolicy());
[email protected]445e1042011-12-03 21:03:152948 }
[email protected]eb0bff942011-04-07 22:08:382949 FOR_EACH_OBSERVER(
2950 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172951}
2952
[email protected]310ebd6302011-10-10 19:06:282953void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:572954 bool content_initiated = !pending_navigation_params_.get();
2955
[email protected]007733c2011-11-17 00:34:072956 DocumentState* document_state = DocumentState::FromDataSource(ds);
2957 if (!document_state) {
2958 document_state = new DocumentState;
2959 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:572960 if (!content_initiated)
2961 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:072962 }
2963
[email protected]bf70edce2012-06-20 22:32:222964 // Carry over the user agent override flag, if it exists.
2965 if (content_initiated && webview() && webview()->mainFrame() &&
2966 webview()->mainFrame()->dataSource()) {
2967 DocumentState* old_document_state =
2968 DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
2969 if (old_document_state) {
2970 document_state->set_is_overriding_user_agent(
2971 old_document_state->is_overriding_user_agent());
2972 }
2973 }
2974
[email protected]3d9689372009-09-10 04:29:172975 // The rest of RenderView assumes that a WebDataSource will always have a
2976 // non-null NavigationState.
[email protected]e1ed5a12012-08-08 19:57:442977 if (content_initiated) {
[email protected]007733c2011-11-17 00:34:072978 document_state->set_navigation_state(
2979 NavigationState::CreateContentInitiated());
[email protected]e1ed5a12012-08-08 19:57:442980 } else {
[email protected]45d83a12012-04-06 22:57:572981 document_state->set_navigation_state(CreateNavigationStateFromPending());
2982 pending_navigation_params_.reset();
2983 }
[email protected]8a3125a712010-08-09 18:58:512984
[email protected]007733c2011-11-17 00:34:072985 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512986 // navigating from a page that used prefetching using a link on that
2987 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072988 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512989 // this value appropriately.
2990 // TODO(gavinp): catch the important case of navigation in a new
2991 // renderer process.
2992 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302993 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522994 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512995 const GURL referrer(
2996 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2997 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072998 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512999 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:413000 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:513001 WebDataSource* old_frame_ds = old_frame->dataSource();
3002 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:073003 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513004 break;
3005 }
3006 }
3007 }
3008 }
3009 }
3010
[email protected]4c1b6f0b2010-02-07 16:38:183011 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523012 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513013 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183014 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:073015 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:183016 break;
3017 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:073018 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:183019 break;
3020 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:073021 document_state->set_load_type(
3022 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:183023 break;
3024 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:073025 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:183026 break;
3027 }
3028 }
[email protected]fa7b6b542009-11-03 05:02:303029
[email protected]946a0032011-03-31 18:42:283030 FOR_EACH_OBSERVER(
3031 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:173032}
3033
[email protected]45d83a12012-04-06 22:57:573034void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:073035 DocumentState* document_state) {
3036 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:573037 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:073038
[email protected]45d83a12012-04-06 22:57:573039 if (!params.url.SchemeIs(chrome::kJavaScriptScheme) &&
3040 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
3041 // We're doing a load of a page that was restored from the last session. By
3042 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
3043 // can result in stale data for pages that are set to expire. We explicitly
3044 // override that by setting the policy here so that as necessary we load
3045 // from the network.
3046 document_state->set_cache_policy_override(
3047 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:073048 }
3049
3050 if (IsReload(params))
3051 document_state->set_load_type(DocumentState::RELOAD);
3052 else if (!params.state.empty())
3053 document_state->set_load_type(DocumentState::HISTORY_LOAD);
3054 else
3055 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]ca662822012-05-11 17:53:593056
3057 document_state->set_referrer_policy(params.referrer.policy);
[email protected]bf70edce2012-06-20 22:32:223058 document_state->set_is_overriding_user_agent(params.is_overriding_user_agent);
[email protected]a3a5397d2012-09-12 06:50:343059 document_state->set_must_reset_scroll_and_scale_state(
3060 params.navigation_type ==
3061 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]45d83a12012-04-06 22:57:573062}
[email protected]007733c2011-11-17 00:34:073063
[email protected]45d83a12012-04-06 22:57:573064NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
3065 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
3066 NavigationState* navigation_state = NULL;
3067
3068 // A navigation resulting from loading a javascript URL should not be treated
3069 // as a browser initiated event. Instead, we want it to look as if the page
3070 // initiated any load resulting from JS execution.
3071 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
3072 navigation_state = NavigationState::CreateBrowserInitiated(
3073 params.page_id,
3074 params.pending_history_list_offset,
3075 params.transition);
3076 navigation_state->set_transferred_request_child_id(
3077 params.transferred_request_child_id);
3078 navigation_state->set_transferred_request_request_id(
3079 params.transferred_request_request_id);
[email protected]80744782012-05-04 01:47:003080 navigation_state->set_allow_download(params.allow_download);
[email protected]45d83a12012-04-06 22:57:573081 } else {
3082 navigation_state = NavigationState::CreateContentInitiated();
3083 }
3084 return navigation_state;
[email protected]007733c2011-11-17 00:34:073085}
3086
[email protected]5b52cd2f712012-03-28 02:12:483087void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
3088 bool enable_viewport =
[email protected]06ea34a2012-05-07 18:52:103089 command_line.HasSwitch(switches::kEnableViewport);
[email protected]5b52cd2f712012-03-28 02:12:483090 bool enable_fixed_layout =
3091 command_line.HasSwitch(switches::kEnableFixedLayout);
[email protected]4ef6104a2012-06-06 18:15:323092 bool enable_pinch = enable_viewport ||
3093 command_line.HasSwitch(switches::kEnablePinch);
[email protected]5b52cd2f712012-03-28 02:12:483094
3095 webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport);
3096 webview()->settings()->setFixedElementsLayoutRelativeToFrame(true);
[email protected]4ef6104a2012-06-06 18:15:323097 if (!enable_pinch &&
[email protected]60051ec2012-06-08 22:40:573098 webview()->isAcceleratedCompositingActive() &&
[email protected]4ef6104a2012-06-06 18:15:323099 webkit_preferences_.apply_default_device_scale_factor_in_compositor &&
[email protected]60051ec2012-06-08 22:40:573100 device_scale_factor_ != 1) {
[email protected]4ef6104a2012-06-06 18:15:323101 // Page scaling is disabled by default when applying a scale factor in the
3102 // compositor since they are currently incompatible.
3103 webview()->setPageScaleFactorLimits(1, 1);
3104 }
[email protected]5b52cd2f712012-03-28 02:12:483105
3106 if (enable_viewport) {
3107 webview()->settings()->setViewportEnabled(true);
3108 } else if (enable_fixed_layout) {
3109 std::string str =
3110 command_line.GetSwitchValueASCII(switches::kEnableFixedLayout);
3111 std::vector<std::string> tokens;
3112 base::SplitString(str, ',', &tokens);
3113 if (tokens.size() == 2) {
3114 int width, height;
3115 if (base::StringToInt(tokens[0], &width) &&
3116 base::StringToInt(tokens[1], &height))
[email protected]e1ed5a12012-08-08 19:57:443117 webview()->setFixedLayoutSize(WebSize(width, height));
[email protected]5b52cd2f712012-03-28 02:12:483118 }
3119 }
3120}
3121
[email protected]310ebd6302011-10-10 19:06:283122void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173123 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:073124 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:173125
[email protected]3d9689372009-09-10 04:29:173126 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:073127 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:173128 double event_time = ds->triggeringEventTime();
3129 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:073130 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:173131 }
3132
[email protected]05c8e502010-08-15 15:13:523133 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:073134 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:523135
[email protected]3d9689372009-09-10 04:29:173136 bool is_top_most = !frame->parent();
3137 if (is_top_most) {
3138 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133139 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173140
3141 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:153142 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173143 } else if (frame->parent()->isLoading()) {
3144 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003145 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:073146 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:583147 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:173148 }
3149
[email protected]28685da92011-02-07 21:49:173150 FOR_EACH_OBSERVER(
3151 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
3152
[email protected]3d9689372009-09-10 04:29:173153 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:593154 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:263155 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173156}
3157
[email protected]400992b2012-06-14 00:03:543158void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
3159 WebFrame* frame) {
3160 if (frame->parent())
3161 return;
3162 // Received a redirect on the main frame.
3163 WebDataSource* data_source = frame->provisionalDataSource();
3164 if (!data_source) {
3165 // Should only be invoked when we have a data source.
3166 NOTREACHED();
3167 return;
3168 }
3169 std::vector<GURL> redirects;
3170 GetRedirectChain(data_source, &redirects);
3171 if (redirects.size() >= 2) {
3172 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
3173 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
3174 }
3175}
3176
[email protected]310ebd6302011-10-10 19:06:283177void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
3178 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173179 // Notify the browser that we failed a provisional load with an error.
3180 //
3181 // Note: It is important this notification occur before DidStopLoading so the
3182 // SSL manager can react to the provisional load failure before being
3183 // notified the load stopped.
3184 //
3185 WebDataSource* ds = frame->provisionalDataSource();
3186 DCHECK(ds);
3187
3188 const WebURLRequest& failed_request = ds->request();
3189
[email protected]28685da92011-02-07 21:49:173190 FOR_EACH_OBSERVER(
3191 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
3192
[email protected]3d9689372009-09-10 04:29:173193 bool show_repost_interstitial =
3194 (error.reason == net::ERR_CACHE_MISS &&
3195 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:583196
3197 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
3198 params.frame_id = frame->identifier();
3199 params.is_main_frame = !frame->parent();
3200 params.error_code = error.reason;
3201 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
3202 failed_request,
3203 error,
3204 NULL,
3205 &params.error_description);
3206 params.url = error.unreachableURL;
3207 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:173208 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:583209 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:173210
3211 // Don't display an error page if this is simply a cancelled load. Aside
3212 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3213 if (error.reason == net::ERR_ABORTED)
3214 return;
3215
3216 // Make sure we never show errors in view source mode.
3217 frame->enableViewSourceMode(false);
3218
[email protected]007733c2011-11-17 00:34:073219 DocumentState* document_state = DocumentState::FromDataSource(ds);
3220 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173221
3222 // If this is a failed back/forward/reload navigation, then we need to do a
3223 // 'replace' load. This is necessary to avoid messing up session history.
3224 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3225 // as session history is concerned.
3226 //
3227 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3228 // the page id.
3229 //
3230 bool replace =
3231 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:583232 navigation_state->transition_type() ==
3233 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:173234
3235 // If we failed on a browser initiated request, then make sure that our error
3236 // page load is regarded as the same browser initiated request.
3237 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:073238 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
3239 pending_navigation_params_->page_id =
3240 navigation_state->pending_page_id();
3241 pending_navigation_params_->pending_history_list_offset =
3242 navigation_state->pending_history_list_offset();
3243 pending_navigation_params_->transition =
3244 navigation_state->transition_type();
3245 pending_navigation_params_->request_time =
3246 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:173247 }
3248
3249 // Provide the user with a more helpful error page?
3250 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3251 return;
3252
3253 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083254 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173255}
3256
[email protected]310ebd6302011-10-10 19:06:283257void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:173258 WebFrame* frame, const char* data, size_t data_len,
3259 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:073260 DocumentState* document_state =
3261 DocumentState::FromDataSource(frame->dataSource());
3262 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:173263}
3264
[email protected]310ebd6302011-10-10 19:06:283265void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
3266 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:073267 DocumentState* document_state =
3268 DocumentState::FromDataSource(frame->dataSource());
3269 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173270
[email protected]007733c2011-11-17 00:34:073271 if (document_state->commit_load_time().is_null())
3272 document_state->set_commit_load_time(Time::Now());
3273
[email protected]a3a5397d2012-09-12 06:50:343274 if (document_state->must_reset_scroll_and_scale_state()) {
3275 webview()->resetScrollAndScaleState();
3276 document_state->set_must_reset_scroll_and_scale_state(false);
3277 }
3278
[email protected]3d9689372009-09-10 04:29:173279 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203280 // When we perform a new navigation, we need to update the last committed
3281 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173282 UpdateSessionHistory(frame);
3283
3284 // We bump our Page ID to correspond with the new session history entry.
3285 page_id_ = next_page_id_++;
3286
[email protected]285f4bb82012-04-17 15:57:283287 // Don't update history_page_ids_ (etc) for content::kSwappedOutURL, since
[email protected]58436a12012-03-21 17:10:263288 // we don't want to forget the entry that was there, and since we will
[email protected]285f4bb82012-04-17 15:57:283289 // never come back to content::kSwappedOutURL. Note that we have to call
[email protected]69ddf852012-02-21 23:21:313290 // UpdateSessionHistory and update page_id_ even in this case, so that
3291 // the current entry gets a state update and so that we don't send a
3292 // state update to the wrong entry when we swap back in.
[email protected]285f4bb82012-04-17 15:57:283293 if (GetLoadingUrl(frame) != GURL(content::kSwappedOutURL)) {
[email protected]69ddf852012-02-21 23:21:313294 // Advance our offset in session history, applying the length limit.
3295 // There is now no forward history.
3296 history_list_offset_++;
3297 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
3298 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
3299 history_list_length_ = history_list_offset_ + 1;
3300 history_page_ids_.resize(history_list_length_, -1);
3301 history_page_ids_[history_list_offset_] = page_id_;
3302 }
[email protected]3d9689372009-09-10 04:29:173303 } else {
3304 // Inspect the navigation_state on this frame to see if the navigation
3305 // corresponds to a session history navigation... Note: |frame| may or
3306 // may not be the toplevel frame, but for the case of capturing session
3307 // history, the first committed frame suffices. We keep track of whether
3308 // we've seen this commit before so that only capture session history once
3309 // per navigation.
3310 //
3311 // Note that we need to check if the page ID changed. In the case of a
3312 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3313 // previous URL and the current page ID, which would be wrong.
3314 if (navigation_state->pending_page_id() != -1 &&
3315 navigation_state->pending_page_id() != page_id_ &&
3316 !navigation_state->request_committed()) {
3317 // This is a successful session history navigation!
3318 UpdateSessionHistory(frame);
3319 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003320
3321 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:033322
3323 // If the history list is valid, our list of page IDs should be correct.
3324 DCHECK(history_list_length_ <= 0 ||
3325 history_list_offset_ < 0 ||
3326 history_list_offset_ >= history_list_length_ ||
3327 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:173328 }
3329 }
3330
[email protected]28685da92011-02-07 21:49:173331 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3332 DidCommitProvisionalLoad(frame, is_new_navigation));
3333
[email protected]3d9689372009-09-10 04:29:173334 // Remember that we've already processed this request, so we don't update
3335 // the session history again. We do this regardless of whether this is
3336 // a session history navigation, because if we attempted a session history
3337 // navigation without valid HistoryItem state, WebCore will think it is a
3338 // new navigation.
3339 navigation_state->set_request_committed(true);
3340
3341 UpdateURL(frame);
3342
3343 // If this committed load was initiated by a client redirect, we're
3344 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:153345 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173346
3347 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273348 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]b2d98762012-09-03 17:04:063349
3350 if (!frame->parent()) { // Only for top frames.
3351 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
3352 if (render_thread_impl) { // Can be NULL in tests.
3353 render_thread_impl->histogram_customizer()->
3354 RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(),
3355 g_view_map.Get().size());
3356 }
3357 }
[email protected]3d9689372009-09-10 04:29:173358}
3359
[email protected]310ebd6302011-10-10 19:06:283360void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:103361 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3362 DidClearWindowObject(frame));
3363
[email protected]b6cb3a842011-06-24 18:28:413364 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:213365 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:253366 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
3367 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:273368 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:173369 }
[email protected]766a7082012-02-03 23:39:153370
3371 if (enabled_bindings_ & content::BINDINGS_POLICY_DOM_AUTOMATION) {
3372 if (!dom_automation_controller_.get())
3373 dom_automation_controller_.reset(new DomAutomationController());
3374 dom_automation_controller_->set_message_sender(
3375 static_cast<content::RenderView*>(this));
3376 dom_automation_controller_->set_routing_id(routing_id());
3377 dom_automation_controller_->BindToJavascript(frame,
3378 "domAutomationController");
3379 }
[email protected]3d9689372009-09-10 04:29:173380}
3381
[email protected]310ebd6302011-10-10 19:06:283382void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173383 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:413384 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:253385 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]87717d0e2012-04-26 02:58:433386 if (frame == webview()->mainFrame())
3387 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:173388 }
[email protected]e48869a2011-04-01 19:56:033389
3390 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3391 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:173392}
3393
[email protected]310ebd6302011-10-10 19:06:283394void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
3395 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:463396 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:173397
3398 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273399 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173400}
3401
[email protected]310ebd6302011-10-10 19:06:283402void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:133403 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3404 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:583405}
3406
[email protected]310ebd6302011-10-10 19:06:283407void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173408 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073409 DocumentState* document_state = DocumentState::FromDataSource(ds);
3410 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:173411
[email protected]622474d2010-11-04 09:21:083412 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173413
[email protected]28685da92011-02-07 21:49:173414 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3415 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173416
3417 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273418 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173419}
3420
[email protected]310ebd6302011-10-10 19:06:283421void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083422 if (webview()->mainFrame() == frame) {
3423 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3424 page_id_));
3425 }
[email protected]3d9689372009-09-10 04:29:173426}
3427
[email protected]310ebd6302011-10-10 19:06:283428void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:313429 WebDataSource* ds = frame->dataSource();
3430 DCHECK(ds);
3431
3432
[email protected]28685da92011-02-07 21:49:173433 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:313434
3435 const WebURLRequest& failed_request = ds->request();
3436 string16 error_description;
3437 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
3438 failed_request,
3439 error,
3440 NULL,
3441 &error_description);
3442 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
3443 frame->identifier(),
3444 failed_request.url(),
3445 !frame->parent(),
3446 error.reason,
3447 error_description));
[email protected]3d9689372009-09-10 04:29:173448}
3449
[email protected]310ebd6302011-10-10 19:06:283450void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173451 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073452 DocumentState* document_state = DocumentState::FromDataSource(ds);
3453 if (document_state->finish_load_time().is_null())
3454 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:413455
[email protected]676126f72011-01-15 00:03:513456 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173457
[email protected]1a55c5be2011-11-29 11:36:313458 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
3459 frame->identifier(),
3460 ds->request().url(),
3461 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:173462}
3463
[email protected]310ebd6302011-10-10 19:06:283464void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173465 WebFrame* frame, bool is_new_navigation) {
3466 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:073467 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:173468 // update the ExtraData on the datasource so that others who read the
3469 // ExtraData will get the new NavigationState. Similarly, if we did not
3470 // initiate this navigation, then we need to take care to reset any pre-
3471 // existing navigation state to a content-initiated navigation state.
3472 // DidCreateDataSource conveniently takes care of this for us.
3473 didCreateDataSource(frame, frame->dataSource());
3474
[email protected]007733c2011-11-17 00:34:073475 DocumentState* document_state =
3476 DocumentState::FromDataSource(frame->dataSource());
3477 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:093478 new_state->set_was_within_same_page(true);
3479
[email protected]3d9689372009-09-10 04:29:173480 didCommitProvisionalLoad(frame, is_new_navigation);
3481
[email protected]750fcf872011-08-03 23:10:473482 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
3483 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:173484}
3485
[email protected]310ebd6302011-10-10 19:06:283486void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313487 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593488}
3489
[email protected]310ebd6302011-10-10 19:06:283490void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:173491 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3492 // Ignore
3493}
3494
[email protected]310ebd6302011-10-10 19:06:283495void RenderViewImpl::willSendRequest(WebFrame* frame,
3496 unsigned identifier,
3497 WebURLRequest& request,
3498 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303499 WebFrame* top_frame = frame->top();
3500 if (!top_frame)
3501 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513502 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3503 WebDataSource* top_data_source = top_frame->dataSource();
3504 WebDataSource* data_source =
3505 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:223506
[email protected]2905f742011-10-13 03:51:583507 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:073508 DocumentState* document_state = DocumentState::FromDataSource(data_source);
[email protected]def55e022012-07-26 01:15:293509 DCHECK(document_state);
[email protected]007733c2011-11-17 00:34:073510 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e1ed5a12012-08-08 19:57:443511 transition_type = navigation_state->transition_type();
3512
3513 GURL request_url(request.url());
3514 GURL new_url;
3515 if (content::GetContentClient()->renderer()->WillSendRequest(
3516 frame, transition_type, request_url, &new_url)) {
3517 request.setURL(WebURL(new_url));
3518 }
3519
[email protected]def55e022012-07-26 01:15:293520 if (document_state->is_cache_policy_override_set())
3521 request.setCachePolicy(document_state->cache_policy_override());
[email protected]8a3125a712010-08-09 18:58:513522
[email protected]ca662822012-05-11 17:53:593523 WebKit::WebReferrerPolicy referrer_policy;
3524 if (document_state && document_state->is_referrer_policy_set()) {
3525 referrer_policy = document_state->referrer_policy();
3526 document_state->clear_referrer_policy();
3527 } else {
3528 referrer_policy = frame->document().referrerPolicy();
3529 }
3530
[email protected]e372f3d2012-07-17 19:16:443531 // The request's extra data may indicate that we should set a custom user
3532 // agent. This needs to be done here, after WebKit is through with setting the
3533 // user agent on its own.
3534 WebString custom_user_agent;
3535 if (request.extraData()) {
3536 webkit_glue::WebURLRequestExtraDataImpl* old_extra_data =
3537 static_cast<webkit_glue::WebURLRequestExtraDataImpl*>(
3538 request.extraData());
3539 custom_user_agent = old_extra_data->custom_user_agent();
3540
3541 if (!custom_user_agent.isNull()) {
3542 if (custom_user_agent.isEmpty())
3543 request.clearHTTPHeaderField("User-Agent");
3544 else
3545 request.setHTTPHeaderField("User-Agent", custom_user_agent);
3546 }
3547 }
3548
[email protected]91043a8232011-11-04 16:41:193549 request.setExtraData(
[email protected]ca662822012-05-11 17:53:593550 new RequestExtraData(referrer_policy,
[email protected]e372f3d2012-07-17 19:16:443551 custom_user_agent,
[email protected]537fbe02011-11-24 00:58:063552 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:193553 frame->identifier(),
3554 frame->parent() == top_frame,
3555 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]80744782012-05-04 01:47:003556 navigation_state->allow_download(),
[email protected]4ad5d77d2011-12-03 02:00:483557 transition_type,
3558 navigation_state->transferred_request_child_id(),
3559 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:573560
[email protected]007733c2011-11-17 00:34:073561 DocumentState* top_document_state =
3562 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:573563 // TODO(gavinp): separate out prefetching and prerender field trials
3564 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:073565 if (top_document_state &&
[email protected]925dec1c2012-05-18 05:09:003566 request.targetType() == WebURLRequest::TargetIsPrefetch)
[email protected]007733c2011-11-17 00:34:073567 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513568
[email protected]3d9689372009-09-10 04:29:173569 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133570 request.setHasUserGesture(frame->isProcessingUserGesture());
3571
[email protected]0a8db0d2011-04-13 15:15:403572 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:133573 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:173574}
3575
[email protected]310ebd6302011-10-10 19:06:283576void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173577 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493578
[email protected]3d9689372009-09-10 04:29:173579 // Only do this for responses that correspond to a provisional data source
3580 // of the top-most frame. If we have a provisional data source, then we
3581 // can't have any sub-resources yet, so we know that this response must
3582 // correspond to a frame load.
3583 if (!frame->provisionalDataSource() || frame->parent())
3584 return;
3585
3586 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083587 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173588 if (frame->isViewSourceModeEnabled())
3589 return;
3590
[email protected]007733c2011-11-17 00:34:073591 DocumentState* document_state =
3592 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083593 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533594
[email protected]972ebdff2010-06-10 22:59:073595 // Record page load flags.
[email protected]007733c2011-11-17 00:34:073596 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3597 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]b9fd01ba2012-02-28 01:50:403598 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
3599 if (extra_data) {
3600 document_state->set_npn_negotiated_protocol(
3601 extra_data->npn_negotiated_protocol());
3602 }
[email protected]007733c2011-11-17 00:34:073603 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:573604 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:073605 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3606 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093607 // Whether or not the http status code actually corresponds to an error is
3608 // only checked when the page is done loading, if |use_error_page| is
3609 // still true.
[email protected]007733c2011-11-17 00:34:073610 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173611}
3612
[email protected]310ebd6302011-10-10 19:06:283613void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173614 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:073615 DocumentState* document_state =
3616 DocumentState::FromDataSource(frame->dataSource());
3617 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173618 return;
3619
[email protected]7bfc153f2011-09-23 22:00:203620 // Do not show error page when DevTools is attached.
3621 if (devtools_agent_->IsAttached())
3622 return;
3623
[email protected]06333afe2011-02-24 14:55:093624 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:073625 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:083626 if (http_status_code == 404) {
3627 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413628 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173629
[email protected]b6cb3a842011-06-24 18:28:413630 const GURL& error_page_url =
3631 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093632 if (error_page_url.is_valid()) {
3633 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473634 original_error.domain = "http";
3635 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413636 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173637
[email protected]007733c2011-11-17 00:34:073638 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093639 new AltErrorPageResourceFetcher(
3640 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:083641 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3642 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093643 return;
3644 }
3645 }
[email protected]3d9689372009-09-10 04:29:173646
[email protected]e6a2ce52011-10-08 01:40:133647 std::string error_domain;
3648 if (content::GetContentClient()->renderer()->HasErrorPage(
3649 http_status_code, &error_domain)) {
3650 WebURLError error;
3651 error.unreachableURL = frame->document().url();
3652 error.domain = WebString::fromUTF8(error_domain);
3653 error.reason = http_status_code;
3654
3655 LoadNavigationErrorPage(
3656 frame, frame->dataSource()->request(), error, std::string(), true);
3657 }
[email protected]3d9689372009-09-10 04:29:173658}
3659
[email protected]310ebd6302011-10-10 19:06:283660void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173661 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3662 // Ignore
3663}
3664
[email protected]310ebd6302011-10-10 19:06:283665void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173666 WebFrame* frame, const WebURLRequest& request,
3667 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003668 // The recipients of this message have no use for data: URLs: they don't
3669 // affect the page's insecure content list and are not in the disk cache. To
3670 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3671 // filter them out here.
3672 GURL url(request.url());
3673 if (url.SchemeIs("data"))
3674 return;
3675
[email protected]3d9689372009-09-10 04:29:173676 // Let the browser know we loaded a resource from the memory cache. This
3677 // message is needed to display the correct SSL indicators.
3678 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3679 routing_id_,
[email protected]84703292011-10-28 20:44:003680 url,
[email protected]70435962011-08-02 20:13:283681 response.securityInfo(),
3682 request.httpMethod().utf8(),
[email protected]6d6cfb3a2012-05-23 22:53:183683 response.mimeType().utf8(),
[email protected]70435962011-08-02 20:13:283684 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173685}
3686
[email protected]310ebd6302011-10-10 19:06:283687void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293688 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3689}
3690
[email protected]310ebd6302011-10-10 19:06:283691void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023692 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293693 Send(new ViewHostMsg_DidRunInsecureContent(
3694 routing_id_,
[email protected]92771112011-01-20 00:13:023695 origin.toString().utf8(),
3696 target));
[email protected]e3d60e5d2009-09-25 21:08:293697}
3698
[email protected]310ebd6302011-10-10 19:06:283699void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173700 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3701}
3702
[email protected]310ebd6302011-10-10 19:06:283703void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3704 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583705 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283706 int world_id) {
[email protected]5bc10932011-09-21 21:03:303707 content::GetContentClient()->renderer()->DidCreateScriptContext(
[email protected]a00fe692012-02-27 05:52:583708 frame, context, extension_group, world_id);
3709}
3710
3711void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3712 v8::Handle<v8::Context> context,
3713 int world_id) {
3714 content::GetContentClient()->renderer()->DidCreateScriptContext(
3715 frame, context, -1, world_id);
[email protected]0c882b282009-10-07 17:01:283716}
3717
[email protected]310ebd6302011-10-10 19:06:283718void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3719 v8::Handle<v8::Context> context,
3720 int world_id) {
[email protected]5bc10932011-09-21 21:03:303721 content::GetContentClient()->renderer()->WillReleaseScriptContext(
3722 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283723}
3724
[email protected]310ebd6302011-10-10 19:06:283725void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073726 // We don't always want to send the change messages over IPC, only if we've
3727 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3728 // message.
3729 if (!send_preferred_size_changes_ || !webview())
3730 return;
3731
[email protected]705243f2010-05-05 19:58:073732 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3733 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533734
3735 // In the presence of zoom, these sizes are still reported as if unzoomed,
3736 // so we need to adjust.
3737 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3738 size.set_width(static_cast<int>(size.width() * zoom_factor));
3739 size.set_height(static_cast<int>(size.height() * zoom_factor));
3740
[email protected]705243f2010-05-05 19:58:073741 if (size == preferred_size_)
3742 return;
[email protected]c27324b2009-11-19 22:44:293743
[email protected]705243f2010-05-05 19:58:073744 preferred_size_ = size;
3745 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3746 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173747}
3748
[email protected]1842fe22012-08-13 23:24:353749WebGraphicsContext3D* RenderViewImpl::CreateGraphicsContext3D(
3750 const WebGraphicsContext3D::Attributes& attributes) {
3751 if (!webview())
3752 return NULL;
3753
3754 if (GetGuestToEmbedderChannel()) {
3755 WebGraphicsContext3DCommandBufferImpl* context =
3756 GetGuestToEmbedderChannel()->CreateWebGraphicsContext3D(
3757 this, attributes, false);
3758 if (!guest_pp_instance()) {
3759 guest_uninitialized_context_ = context;
3760 guest_attributes_ = attributes;
3761 }
3762 return context;
3763 }
3764
3765 // The WebGraphicsContext3DInProcessImpl code path is used for
3766 // layout tests (though not through this code) as well as for
3767 // debugging and bringing up new ports.
3768 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
3769 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
3770 attributes, true);
3771 } else {
3772 GURL url;
3773 if (webview()->mainFrame())
3774 url = GURL(webview()->mainFrame()->document().url());
3775 else
[email protected]f89e173a2012-08-24 01:12:263776 url = GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]1842fe22012-08-13 23:24:353777
3778 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
3779 new WebGraphicsContext3DCommandBufferImpl(
3780 surface_id(),
3781 url,
3782 RenderThreadImpl::current(),
3783 AsWeakPtr()));
3784
3785 if (!context->Initialize(
3786 attributes,
3787 false /* bind generates resources */,
3788 content::CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
3789 return NULL;
3790 return context.release();
3791 }
3792}
3793
[email protected]0720b532012-08-28 19:23:373794// The browser process needs to know the shape of the tree, as well as the names
3795// and ids of all frames. This allows it to properly route JavaScript messages
3796// across processes and frames. The serialization format is described in the
3797// comments of the ViewMsg_FrameTreeUpdated message.
3798// This function sends those updates to the browser and updates the RVH
3799// corresponding to this object. It must be called on any events that modify
3800// the tree structure or the names of any frames.
3801void RenderViewImpl::SendUpdatedFrameTree(
3802 WebKit::WebFrame* exclude_frame_subtree) {
3803 std::string json;
3804 base::DictionaryValue tree;
3805
3806 ConstructFrameTree(webview()->mainFrame(), exclude_frame_subtree, &tree);
3807 base::JSONWriter::Write(&tree, &json);
3808
3809 Send(new ViewHostMsg_FrameTreeUpdated(routing_id_, json));
3810}
3811
3812void RenderViewImpl::CreateFrameTree(WebKit::WebFrame* frame,
3813 DictionaryValue* frame_tree) {
3814 NavigateToSwappedOutURL(frame);
3815
3816 string16 name;
3817 if (frame_tree->GetString(content::kFrameTreeNodeNameKey, &name) &&
[email protected]5604fb5c2012-09-20 03:29:313818 !name.empty()) {
[email protected]0720b532012-08-28 19:23:373819 frame->setName(name);
3820 }
3821
3822 int remote_id;
3823 if (frame_tree->GetInteger(content::kFrameTreeNodeIdKey, &remote_id))
3824 active_frame_id_map_.insert(std::pair<int, int>(frame->identifier(),
3825 remote_id));
3826
3827 ListValue* children;
3828 if (!frame_tree->GetList(content::kFrameTreeNodeSubtreeKey, &children))
3829 return;
3830
3831 base::DictionaryValue* child;
3832 for (size_t i = 0; i < children->GetSize(); ++i) {
3833 if (!children->GetDictionary(i, &child))
3834 continue;
3835 WebElement element = frame->document().createElement("iframe");
3836 if (frame->document().body().appendChild(element)) {
3837 WebFrame* subframe = WebFrame::fromFrameOwnerElement(element);
3838 if (subframe)
3839 CreateFrameTree(subframe, child);
3840 } else {
3841 LOG(ERROR) << "Failed to append created iframe element.";
3842 }
3843 }
3844}
3845
3846WebKit::WebFrame* RenderViewImpl::GetFrameByMappedID(int frame_id) {
3847 std::map<int, int>::iterator it = active_frame_id_map_.find(frame_id);
3848 if (it == active_frame_id_map_.end())
3849 return NULL;
3850
3851 return FindFrameByID(webview()->mainFrame(), it->second);
3852}
3853
[email protected]273558fb2012-01-12 15:03:513854void RenderViewImpl::EnsureMediaStreamImpl() {
[email protected]7082fb942012-05-16 23:44:593855 if (!RenderThreadImpl::current()) // Will be NULL during unit tests.
[email protected]08381562012-05-15 20:55:403856 return;
3857
[email protected]4fb0f202012-05-30 22:44:533858#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:513859 if (!media_stream_dispatcher_)
3860 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3861
[email protected]1bc65a42012-04-23 09:31:253862 if (!media_stream_impl_) {
[email protected]273558fb2012-01-12 15:03:513863 media_stream_impl_ = new MediaStreamImpl(
[email protected]1bc65a42012-04-23 09:31:253864 this,
[email protected]273558fb2012-01-12 15:03:513865 media_stream_dispatcher_,
[email protected]273558fb2012-01-12 15:03:513866 RenderThreadImpl::current()->video_capture_impl_manager(),
[email protected]6ee10bd2012-09-13 09:01:533867 RenderThreadImpl::current()->GetMediaStreamDependencyFactory());
[email protected]273558fb2012-01-12 15:03:513868 }
[email protected]5b87e782012-02-09 18:19:323869#endif
[email protected]273558fb2012-01-12 15:03:513870}
3871
[email protected]310ebd6302011-10-10 19:06:283872void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3873 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313874 if (webview()->mainFrame() != frame)
3875 return;
3876 WebView* frameView = frame->view();
3877 if (!frameView)
3878 return;
3879
3880 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3881 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3882
3883 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3884 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3885 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3886 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3887
3888 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3889 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3890 }
3891}
3892
[email protected]310ebd6302011-10-10 19:06:283893void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313894 WebSize offset = frame->scrollOffset();
3895 WebSize minimum_offset = frame->minimumScrollOffset();
3896 WebSize maximum_offset = frame->maximumScrollOffset();
3897
3898 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3899 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3900
3901 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3902 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3903 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3904 routing_id_, is_pinned_to_left, is_pinned_to_right));
3905
3906 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3907 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3908 }
3909}
3910
[email protected]310ebd6302011-10-10 19:06:283911void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493912 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313913
3914 if (webview()->mainFrame() == frame)
3915 UpdateScrollState(frame);
[email protected]2b942c332012-04-25 16:26:263916
3917 FOR_EACH_OBSERVER(
3918 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]dd6afca2011-08-13 03:44:313919}
3920
[email protected]310ebd6302011-10-10 19:06:283921void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:313922 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:493923}
3924
[email protected]c8ac9052012-07-20 21:43:403925void RenderViewImpl::hasTouchEventHandlers(bool has_handlers) {
3926 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
3927}
3928
[email protected]310ebd6302011-10-10 19:06:283929void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
3930 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113931 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3932 if (!count)
3933 active_match_ordinal = 0;
3934
[email protected]733a58f2012-08-11 03:49:013935 Send(new ViewHostMsg_Find_Reply(routing_id_,
3936 request_id,
3937 count,
3938 gfx::Rect(),
3939 active_match_ordinal,
3940 final_update));
[email protected]8922e1f2009-10-03 05:01:263941}
3942
[email protected]310ebd6302011-10-10 19:06:283943void RenderViewImpl::reportFindInPageSelection(int request_id,
3944 int active_match_ordinal,
3945 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:263946 // Send the search result over to the browser process.
3947 Send(new ViewHostMsg_Find_Reply(routing_id_,
3948 request_id,
3949 -1,
3950 selection_rect,
3951 active_match_ordinal,
3952 false));
3953}
3954
[email protected]310ebd6302011-10-10 19:06:283955void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:223956 WebFrame* frame,
3957 WebFileSystem::Type type,
3958 long long size,
[email protected]d275d7a2010-11-03 01:34:493959 bool create,
[email protected]2b06a992010-08-21 05:48:223960 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083961 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223962
[email protected]b6cb3a842011-06-24 18:28:413963 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563964 if (origin.isUnique()) {
3965 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:083966 callbacks->didFail(WebKit::WebFileErrorAbort);
3967 return;
3968 }
[email protected]2b06a992010-08-21 05:48:223969
[email protected]c5a272d2010-09-27 18:37:083970 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3971 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493972 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223973}
3974
[email protected]d5e08552012-08-02 21:43:403975void RenderViewImpl::deleteFileSystem(
3976 WebFrame* frame,
3977 WebFileSystem::Type type ,
3978 WebFileSystemCallbacks* callbacks) {
3979 DCHECK(callbacks);
3980
3981 WebSecurityOrigin origin = frame->document().securityOrigin();
3982 if (origin.isUnique()) {
3983 // Unique origins cannot store persistent state.
3984 callbacks->didSucceed();
3985 return;
3986 }
3987
3988 ChildThread::current()->file_system_dispatcher()->DeleteFileSystem(
3989 GURL(origin.toString()),
3990 static_cast<fileapi::FileSystemType>(type),
3991 new WebFileSystemCallbackDispatcher(callbacks));
3992}
3993
[email protected]310ebd6302011-10-10 19:06:283994void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:403995 WebFrame* frame,
3996 WebStorageQuotaType type,
3997 WebStorageQuotaCallbacks* callbacks) {
3998 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413999 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564000 if (origin.isUnique()) {
4001 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:404002 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
4003 return;
4004 }
4005 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:534006 GURL(origin.toString()),
4007 static_cast<quota::StorageType>(type),
4008 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:404009}
4010
[email protected]310ebd6302011-10-10 19:06:284011void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:404012 WebFrame* frame,
4013 WebStorageQuotaType type,
4014 unsigned long long requested_size,
4015 WebStorageQuotaCallbacks* callbacks) {
4016 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:414017 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564018 if (origin.isUnique()) {
4019 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:404020 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
4021 return;
4022 }
4023 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:534024 routing_id(), GURL(origin.toString()),
4025 static_cast<quota::StorageType>(type), requested_size,
4026 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:404027}
4028
[email protected]8b5af492011-11-28 21:50:584029void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:154030 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]3a3b75a2012-06-01 08:38:364031 webkit_glue::WebIntentServiceData data(service);
4032 if (data.title.empty())
4033 data.title = webview()->mainFrame()->document().title();
4034 bool user_gesture = frame->isProcessingUserGesture();
[email protected]8b5af492011-11-28 21:50:584035 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
[email protected]3a3b75a2012-06-01 08:38:364036 data,
4037 user_gesture));
[email protected]8b5af492011-11-28 21:50:584038}
4039
[email protected]ffc8bed2012-01-21 01:23:154040void RenderViewImpl::dispatchIntent(
4041 WebFrame* frame, const WebIntentRequest& intentRequest) {
4042 webkit_glue::WebIntentData intent_data(intentRequest.intent());
[email protected]4e1eb3392012-05-18 00:08:054043
4044 // See WebMessagePortChannelImpl::postMessage() and ::OnMessagedQueued()
4045 WebKit::WebMessagePortChannelArray* channels =
4046 intentRequest.intent().messagePortChannelsRelease();
4047 if (channels) {
4048 for (size_t i = 0; i < channels->size(); ++i) {
4049 WebMessagePortChannelImpl* webchannel =
4050 static_cast<WebMessagePortChannelImpl*>((*channels)[i]);
4051 intent_data.message_port_ids.push_back(webchannel->message_port_id());
4052 DCHECK(intent_data.message_port_ids[i] != MSG_ROUTING_NONE);
4053 }
4054 delete channels;
4055 }
4056
[email protected]ffc8bed2012-01-21 01:23:154057 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:584058 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:154059 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:584060}
4061
[email protected]f546640b2012-05-15 00:03:494062bool RenderViewImpl::willCheckAndDispatchMessageEvent(
[email protected]0720b532012-08-28 19:23:374063 WebKit::WebFrame* sourceFrame,
4064 WebKit::WebFrame* targetFrame,
[email protected]f546640b2012-05-15 00:03:494065 WebKit::WebSecurityOrigin target_origin,
4066 WebKit::WebDOMMessageEvent event) {
4067 if (!is_swapped_out_)
4068 return false;
4069
4070 ViewMsg_PostMessage_Params params;
4071 params.data = event.data().toString();
4072 params.source_origin = event.origin();
4073 if (!target_origin.isNull())
4074 params.target_origin = target_origin.toString();
4075
4076 // Include the routing ID for the source frame, which the browser process
4077 // will translate into the routing ID for the equivalent frame in the target
4078 // process.
[email protected]f546640b2012-05-15 00:03:494079 params.source_routing_id = MSG_ROUTING_NONE;
[email protected]0720b532012-08-28 19:23:374080 RenderViewImpl* source_view = FromWebView(sourceFrame->view());
[email protected]f546640b2012-05-15 00:03:494081 if (source_view)
4082 params.source_routing_id = source_view->routing_id();
[email protected]0720b532012-08-28 19:23:374083 params.source_frame_id = sourceFrame->identifier();
4084
4085 // Include the process, route, and frame IDs of the target frame. This allows
4086 // the browser to detect races between this message being sent and the target
4087 // frame no longer being valid.
4088 params.target_process_id = target_process_id_;
4089 params.target_routing_id = target_routing_id_;
4090
4091 std::map<int,int>::iterator it = active_frame_id_map_.find(
4092 targetFrame->identifier());
4093 if (it != active_frame_id_map_.end()) {
4094 params.target_frame_id = it->second;
4095 } else {
4096 params.target_frame_id = 0;
4097 }
[email protected]f546640b2012-05-15 00:03:494098
4099 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params));
4100 return true;
4101}
4102
[email protected]5fa3a062012-03-21 15:39:344103void RenderViewImpl::willOpenSocketStream(
4104 WebSocketStreamHandle* handle) {
4105 SocketStreamHandleData::AddToHandle(handle, routing_id_);
4106}
4107
[email protected]bf70edce2012-06-20 22:32:224108WebKit::WebString RenderViewImpl::userAgentOverride(
4109 WebKit::WebFrame* frame,
4110 const WebKit::WebURL& url) {
4111 if (!webview() || !webview()->mainFrame() ||
4112 renderer_preferences_.user_agent_override.empty()) {
4113 return WebKit::WebString();
4114 }
4115
4116 // If we're in the middle of committing a load, the data source we need
4117 // will still be provisional.
4118 WebFrame* main_frame = webview()->mainFrame();
4119 WebDataSource* data_source = NULL;
4120 if (main_frame->provisionalDataSource())
4121 data_source = main_frame->provisionalDataSource();
4122 else
4123 data_source = main_frame->dataSource();
4124
4125 DocumentState* document_state =
4126 data_source ? DocumentState::FromDataSource(data_source) : NULL;
4127 if (document_state && document_state->is_overriding_user_agent())
4128 return WebString::fromUTF8(renderer_preferences_.user_agent_override);
4129 else
4130 return WebKit::WebString();
4131}
4132
[email protected]18d5be92011-07-25 18:00:194133// WebKit::WebPageSerializerClient implementation ------------------------------
4134
[email protected]310ebd6302011-10-10 19:06:284135void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:194136 const WebURL& frame_url,
4137 const WebCString& data,
4138 WebPageSerializerClient::PageSerializationStatus status) {
4139 Send(new ViewHostMsg_SendSerializedHtmlData(
4140 routing_id(),
4141 frame_url,
4142 data.data(),
4143 static_cast<int32>(status)));
4144}
4145
[email protected]a2ef54c2011-10-10 16:20:314146// content::RenderView implementation ------------------------------------------
4147
[email protected]310ebd6302011-10-10 19:06:284148bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:314149 return RenderWidget::Send(message);
4150}
4151
[email protected]82114f52012-03-20 22:53:414152int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:314153 return routing_id_;
4154}
4155
[email protected]82114f52012-03-20 22:53:414156int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:314157 return page_id_;
4158}
4159
[email protected]82114f52012-03-20 22:53:414160gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:314161 return size();
4162}
4163
[email protected]82114f52012-03-20 22:53:414164WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:314165 return webkit_preferences_;
4166}
4167
[email protected]82114f52012-03-20 22:53:414168WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:314169 return webview();
4170}
4171
[email protected]82114f52012-03-20 22:53:414172WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:314173 if (!webview())
4174 return WebNode();
4175 WebFrame* focused_frame = webview()->focusedFrame();
4176 if (focused_frame) {
4177 WebDocument doc = focused_frame->document();
4178 if (!doc.isNull())
4179 return doc.focusedNode();
4180 }
4181
4182 return WebNode();
4183}
4184
[email protected]82114f52012-03-20 22:53:414185WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:314186 return context_menu_node_;
4187}
4188
[email protected]2a84f9d2012-06-05 21:50:434189bool RenderViewImpl::IsEditableNode(const WebNode& node) const {
4190 if (node.isNull())
4191 return false;
4192
4193 if (node.isContentEditable())
4194 return true;
4195
4196 if (node.isElementNode()) {
4197 const WebElement& element = node.toConst<WebElement>();
4198 if (element.isTextFormControlElement())
4199 return true;
4200
4201 // Also return true if it has an ARIA role of 'textbox'.
4202 for (unsigned i = 0; i < element.attributeCount(); ++i) {
4203 if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) {
4204 if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox"))
4205 return true;
4206 break;
4207 }
[email protected]a2ef54c2011-10-10 16:20:314208 }
4209 }
[email protected]2a84f9d2012-06-05 21:50:434210
4211 return false;
[email protected]a2ef54c2011-10-10 16:20:314212}
4213
[email protected]468e4902012-05-23 01:49:314214void RenderViewImpl::GuestReady(PP_Instance instance) {
4215 guest_pp_instance_ = instance;
4216 if (guest_uninitialized_context_) {
[email protected]7900bfdb2012-05-24 19:31:244217 bool success = GetGuestToEmbedderChannel()->CreateGraphicsContext(
[email protected]468e4902012-05-23 01:49:314218 guest_uninitialized_context_,
4219 guest_attributes_,
4220 false,
4221 this);
4222 DCHECK(success);
[email protected]7900bfdb2012-05-24 19:31:244223 CompleteInit(host_window_);
4224 guest_uninitialized_context_ = NULL;
[email protected]468e4902012-05-23 01:49:314225 }
[email protected]468e4902012-05-23 01:49:314226}
4227
4228webkit::ppapi::WebPluginImpl* RenderViewImpl::CreateBrowserPlugin(
4229 const IPC::ChannelHandle& channel_handle,
4230 int guest_process_id,
4231 const WebKit::WebPluginParams& params) {
4232 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
4233 pepper_delegate_.CreateBrowserPluginModule(channel_handle,
4234 guest_process_id));
4235 return new webkit::ppapi::WebPluginImpl(
4236 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
4237}
4238
[email protected]310ebd6302011-10-10 19:06:284239WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:314240 WebKit::WebFrame* frame,
4241 const webkit::WebPluginInfo& info,
[email protected]82114f52012-03-20 22:53:414242 const WebKit::WebPluginParams& params) {
[email protected]a2ef54c2011-10-10 16:20:314243 bool pepper_plugin_was_registered = false;
4244 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
4245 pepper_delegate_.CreatePepperPluginModule(info,
4246 &pepper_plugin_was_registered));
4247 if (pepper_plugin_was_registered) {
4248 if (!pepper_module)
4249 return NULL;
4250 return new webkit::ppapi::WebPluginImpl(
4251 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
4252 }
4253
[email protected]3e076a82012-09-11 19:12:364254#if defined(USE_AURA) && !defined(OS_WIN)
[email protected]34b27e442012-01-20 20:07:414255 return NULL;
4256#else
[email protected]a2ef54c2011-10-10 16:20:314257 return new webkit::npapi::WebPluginImpl(
4258 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:414259#endif
[email protected]a2ef54c2011-10-10 16:20:314260}
4261
[email protected]310ebd6302011-10-10 19:06:284262void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
4263 const string16& jscript,
4264 int id,
4265 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:314266 v8::Handle<v8::Value> result;
4267 WebFrame* web_frame = GetChildFrame(frame_xpath);
4268 if (web_frame)
4269 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
4270 if (notify_result) {
4271 ListValue list;
4272 if (!result.IsEmpty() && web_frame) {
4273 v8::HandleScope handle_scope;
4274 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4275 v8::Context::Scope context_scope(context);
4276 V8ValueConverterImpl converter;
[email protected]3de391e82012-05-16 17:50:514277 converter.SetDateAllowed(true);
[email protected]e0658bc2012-09-17 04:05:244278 converter.SetRegExpAllowed(true);
4279 base::Value* result_value = converter.FromV8Value(result, context);
4280 list.Set(0, result_value ? result_value :
4281 base::Value::CreateNullValue());
[email protected]a2ef54c2011-10-10 16:20:314282 } else {
4283 list.Set(0, Value::CreateNullValue());
4284 }
4285 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
4286 }
4287}
4288
[email protected]310ebd6302011-10-10 19:06:284289bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:314290 return (!send_preferred_size_changes_ ||
4291 (disable_scrollbars_size_limit_.width() <= width ||
4292 disable_scrollbars_size_limit_.height() <= height));
4293}
4294
[email protected]82114f52012-03-20 22:53:414295int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:314296 return enabled_bindings_;
4297}
4298
[email protected]82114f52012-03-20 22:53:414299bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:314300 return send_content_state_immediately_;
4301}
4302
[email protected]82114f52012-03-20 22:53:414303float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:314304 return filtered_time_per_frame();
4305}
4306
[email protected]310ebd6302011-10-10 19:06:284307void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
[email protected]82114f52012-03-20 22:53:414308 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:314309 showContextMenu(frame, data);
4310}
4311
[email protected]82114f52012-03-20 22:53:414312WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:314313 return visibilityState();
4314}
4315
[email protected]310ebd6302011-10-10 19:06:284316void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
4317 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:314318 return runModalAlertDialog(frame, message);
4319}
4320
[email protected]310ebd6302011-10-10 19:06:284321void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:314322 WebKit::WebFrame* frame,
4323 const WebKit::WebURLRequest& request,
4324 WebKit::WebNavigationPolicy policy) {
4325 loadURLExternally(frame, request, policy);
4326}
4327
4328// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:514329
[email protected]310ebd6302011-10-10 19:06:284330webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:534331 const FilePath& file_path,
4332 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:204333 if (!PluginChannelHost::IsListening()) {
4334 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:594335 return NULL;
[email protected]94752ee2012-02-10 10:38:204336 }
[email protected]f103ab72009-09-02 17:10:594337
[email protected]00c39612010-03-06 02:53:284338 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:464339 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:324340#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:224341 return webkit::npapi::WebPluginDelegateImpl::Create(
4342 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:094343#else
[email protected]7398dcc2011-09-06 21:40:324344 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:224345 NOTIMPLEMENTED();
4346 return NULL;
[email protected]7b6616f2010-01-14 18:07:554347#endif
[email protected]f103ab72009-09-02 17:10:594348 }
4349
[email protected]4e0616e2010-05-28 14:55:534350 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:594351}
4352
[email protected]6ac77cb2012-05-01 14:49:014353WebKit::WebPlugin* RenderViewImpl::CreatePluginReplacement(
4354 const FilePath& file_path) {
4355 return content::GetContentClient()->renderer()->CreatePluginReplacement(
4356 this, file_path);
4357}
4358
[email protected]310ebd6302011-10-10 19:06:284359void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034360#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:274361 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:594362#endif
4363}
4364
[email protected]310ebd6302011-10-10 19:06:284365void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034366#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:274367 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:594368#endif
4369 CleanupWindowInPluginMoves(window);
4370}
4371
[email protected]310ebd6302011-10-10 19:06:284372void RenderViewImpl::DidMovePlugin(
4373 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:594374 SchedulePluginMove(move);
4375}
4376
[email protected]310ebd6302011-10-10 19:06:284377void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:594378 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524379 didStartLoading();
[email protected]f103ab72009-09-02 17:10:594380}
4381
[email protected]310ebd6302011-10-10 19:06:284382void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:594383 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524384 didStopLoading();
[email protected]f103ab72009-09-02 17:10:594385}
4386
[email protected]310ebd6302011-10-10 19:06:284387WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:514388 return &cookie_jar_;
4389}
4390
[email protected]5d65fe92012-06-02 00:48:554391void RenderViewImpl::DidPlay(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074392 Send(new ViewHostMsg_MediaNotification(routing_id_,
4393 reinterpret_cast<int64>(player),
4394 player->hasVideo(),
4395 player->hasAudio(),
4396 true));
4397}
4398
[email protected]5d65fe92012-06-02 00:48:554399void RenderViewImpl::DidPause(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074400 Send(new ViewHostMsg_MediaNotification(routing_id_,
4401 reinterpret_cast<int64>(player),
4402 player->hasVideo(),
4403 player->hasAudio(),
4404 false));
4405}
4406
[email protected]5d65fe92012-06-02 00:48:554407void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074408 DidPause(player);
4409}
4410
[email protected]310ebd6302011-10-10 19:06:284411void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:294412 if (!webview())
4413 return;
4414
[email protected]26aa0482009-09-30 16:55:274415 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:054416 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:294417}
4418
[email protected]310ebd6302011-10-10 19:06:284419void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:364420 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:004421 if (!frame)
4422 return;
[email protected]b781ff282011-08-20 06:19:364423
[email protected]e99ef6f2011-10-16 01:13:004424 string16 text;
4425 size_t offset;
[email protected]3c8c74c2012-03-15 07:34:524426 ui::Range range;
[email protected]e99ef6f2011-10-16 01:13:004427
[email protected]3c8c74c2012-03-15 07:34:524428 if (pepper_delegate_.IsPluginFocused()) {
4429 pepper_delegate_.GetSurroundingText(&text, &range);
[email protected]82114f52012-03-20 22:53:414430 offset = 0; // Pepper API does not support offset reporting.
[email protected]3c8c74c2012-03-15 07:34:524431 // TODO(kinaba): cut as needed.
[email protected]e99ef6f2011-10-16 01:13:004432 } else {
[email protected]3c8c74c2012-03-15 07:34:524433 size_t location, length;
4434 if (!webview()->caretOrSelectionRange(&location, &length))
4435 return;
4436
4437 range = ui::Range(location, location + length);
4438
4439 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
4440 // If current focused element is editable, we will send 100 more chars
4441 // before and after selection. It is for input method surrounding text
4442 // feature.
4443 if (location > kExtraCharsBeforeAndAfterSelection)
4444 offset = location - kExtraCharsBeforeAndAfterSelection;
4445 else
4446 offset = 0;
4447 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
4448 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
4449 if (!webrange.isNull())
4450 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
4451 } else {
4452 offset = location;
4453 text = frame->selectionAsText();
4454 // http://crbug.com/101435
4455 // In some case, frame->selectionAsText() returned text's length is not
4456 // equal to the length returned from webview()->caretOrSelectionRange().
4457 // So we have to set the range according to text.length().
4458 range.set_end(range.start() + text.length());
4459 }
[email protected]b781ff282011-08-20 06:19:364460 }
4461
[email protected]b781ff282011-08-20 06:19:364462 // Sometimes we get repeated didChangeSelection calls from webkit when
4463 // the selection hasn't actually changed. We don't want to report these
4464 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:004465 if (selection_text_offset_ != offset ||
4466 selection_range_ != range ||
4467 selection_text_ != text) {
4468 selection_text_ = text;
4469 selection_text_offset_ = offset;
4470 selection_range_ = range;
4471 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
4472 }
[email protected]b781ff282011-08-20 06:19:364473}
4474
[email protected]310ebd6302011-10-10 19:06:284475GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
4476 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554477 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294478 // If the URL that failed was secure, then the embedding web page was not
4479 // expecting a network attacker to be able to manipulate its contents. As
4480 // we fetch alternate error pages over HTTP, we would be allowing a network
4481 // attacker to manipulate the contents of the response if we tried to use
4482 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154483 return GURL();
initial.commit09911bf2008-07-26 23:55:294484 }
4485
4486 // Grab the base URL from the browser process.
4487 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154488 return GURL();
initial.commit09911bf2008-07-26 23:55:294489
4490 // Strip query params from the failed URL.
4491 GURL::Replacements remove_params;
4492 remove_params.ClearUsername();
4493 remove_params.ClearPassword();
4494 remove_params.ClearQuery();
4495 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554496 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504497 std::string spec_to_send = url_to_send.spec();
4498 // Notify link doctor of the url truncation by sending of "?" at the end.
4499 if (failed_url.has_query())
[email protected]82114f52012-03-20 22:53:414500 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294501
4502 // Construct the query params to send to link doctor.
4503 std::string params(alternate_error_page_url_.query());
4504 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:024505 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294506 params.append("&sourceid=chrome");
4507 params.append("&error=");
4508 switch (error_type) {
4509 case DNS_ERROR:
4510 params.append("dnserror");
4511 break;
4512
4513 case HTTP_404:
4514 params.append("http404");
4515 break;
4516
[email protected]5df266ac2008-10-15 19:50:134517 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334518 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134519 break;
4520
initial.commit09911bf2008-07-26 23:55:294521 default:
4522 NOTREACHED() << "unknown ErrorPageType";
4523 }
4524
4525 // OK, build the final url to return.
4526 GURL::Replacements link_doctor_params;
4527 link_doctor_params.SetQueryStr(params);
4528 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4529 return url;
4530}
4531
[email protected]310ebd6302011-10-10 19:06:284532GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:594533 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
4534 return GURL();
4535 else
4536 return creator_url_;
4537}
4538
[email protected]69ddf852012-02-21 23:21:314539GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
4540 WebDataSource* ds = frame->dataSource();
4541 if (ds->hasUnreachableURL())
4542 return ds->unreachableURL();
4543
4544 const WebURLRequest& request = ds->request();
4545 return request.url();
4546}
4547
[email protected]310ebd6302011-10-10 19:06:284548WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:274549 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:314550 web_ui_bindings_.reset(new WebUIBindings(
4551 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:464552 }
[email protected]c50008512011-02-03 01:17:274553 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:464554}
4555
[email protected]310ebd6302011-10-10 19:06:284556WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:014557 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494558}
4559
[email protected]310ebd6302011-10-10 19:06:284560void RenderViewImpl::OnFind(int request_id, const string16& search_text,
4561 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274562 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494563
[email protected]872542532011-06-23 00:43:164564 // Check if the plugin still exists in the document.
4565 if (main_frame->document().isPluginDocument() &&
4566 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494567 if (options.findNext) {
4568 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014569 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494570 } else {
[email protected]afdbd142010-07-10 08:01:234571 if (GetWebPluginFromPluginDocument()->startFind(
4572 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:494573 } else {
[email protected]e7c58a32010-08-13 19:47:114574 // Send "no results".
4575 Send(new ViewHostMsg_Find_Reply(routing_id_,
4576 request_id,
4577 0,
4578 gfx::Rect(),
4579 0,
4580 true));
[email protected]24a7f3c2010-03-25 08:26:494581 }
4582 }
4583 return;
4584 }
4585
[email protected]b4bb2502009-10-01 22:35:274586 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274587 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294588 WebFrame* search_frame = focused_frame; // start searching focused frame.
4589
4590 bool multi_frame = (frame_after_main != main_frame);
4591
4592 // If we have multiple frames, we don't want to wrap the search within the
4593 // frame, so we check here if we only have main_frame in the chain.
4594 bool wrap_within_frame = !multi_frame;
4595
[email protected]b3f2b912009-04-09 16:18:524596 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294597 bool result = false;
4598
[email protected]7830da3e2009-11-06 16:27:264599 // If something is selected when we start searching it means we cannot just
4600 // increment the current match ordinal; we need to re-generate it.
4601 WebRange current_selection = focused_frame->selectionRange();
4602
initial.commit09911bf2008-07-26 23:55:294603 do {
[email protected]dd7daa82009-08-10 05:46:454604 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594605 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294606
4607 if (!result) {
4608 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:224609 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294610
4611 // Find the next frame, but skip the invisible ones.
4612 do {
4613 // What is the next frame to search? (we might be going backwards). Note
4614 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594615 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274616 search_frame->traverseNext(true) :
4617 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454618 } while (!search_frame->hasVisibleContent() &&
4619 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294620
[email protected]884db412008-11-24 23:46:504621 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:224622 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294623
4624 // If we have multiple frames and we have wrapped back around to the
4625 // focused frame, we need to search it once more allowing wrap within
4626 // the frame, otherwise it will report 'no match' if the focused frame has
4627 // reported matches, but no frames after the focused_frame contain a
4628 // match for the search word(s).
4629 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454630 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594631 request_id, search_text, options, true, // Force wrapping.
4632 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294633 }
4634 }
4635
[email protected]26aa0482009-09-30 16:55:274636 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294637 } while (!result && search_frame != focused_frame);
4638
[email protected]7830da3e2009-11-06 16:27:264639 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294640 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454641 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294642 } else {
4643 // If nothing is found, set result to "0 of 0", otherwise, set it to
4644 // "-1 of 1" to indicate that we found at least one item, but we don't know
4645 // yet what is active.
4646 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4647 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294648
[email protected]4f3dc372009-02-24 00:10:294649 // If we find no matches then this will be our last status update.
4650 // Otherwise the scoping effort will send more results.
4651 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294652
[email protected]4f3dc372009-02-24 00:10:294653 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:404654 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:594655 request_id,
[email protected]4f3dc372009-02-24 00:10:294656 match_count,
4657 selection_rect,
4658 ordinal,
4659 final_status_update));
initial.commit09911bf2008-07-26 23:55:294660
initial.commit09911bf2008-07-26 23:55:294661 // Scoping effort begins, starting with the mainframe.
4662 search_frame = main_frame;
4663
[email protected]dd7daa82009-08-10 05:46:454664 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294665
4666 do {
4667 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454668 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294669
4670 // We don't start another scoping effort unless at least one match has
4671 // been found.
4672 if (result) {
4673 // Start new scoping request. If the scoping function determines that it
4674 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454675 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594676 search_text,
4677 options,
initial.commit09911bf2008-07-26 23:55:294678 true); // reset the tickmarks
4679 }
4680
4681 // Iterate to the next frame. The frame will not necessarily scope, for
4682 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274683 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294684 } while (search_frame != main_frame);
4685 }
4686}
4687
[email protected]815dd9872011-11-23 18:40:304688void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:494689 WebView* view = webview();
4690 if (!view)
4691 return;
4692
4693 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:164694 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014695 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494696 return;
4697 }
4698
[email protected]815dd9872011-11-23 18:40:304699 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:494700 if (clear_selection)
4701 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4702
4703 WebFrame* frame = view->mainFrame();
4704 while (frame) {
4705 frame->stopFinding(clear_selection);
4706 frame = frame->traverseNext(false);
4707 }
4708
[email protected]815dd9872011-11-23 18:40:304709 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:494710 WebFrame* focused_frame = view->focusedFrame();
4711 if (focused_frame) {
4712 WebDocument doc = focused_frame->document();
4713 if (!doc.isNull()) {
4714 WebNode node = doc.focusedNode();
4715 if (!node.isNull())
4716 node.simulateClick();
4717 }
4718 }
4719 }
4720}
4721
[email protected]59363fc92012-09-05 03:46:314722#if defined(OS_ANDROID)
4723void RenderViewImpl::OnActivateNearestFindResult(int request_id,
4724 float x, float y) {
4725 if (!webview())
4726 return;
4727
4728 WebFrame* main_frame = webview()->mainFrame();
4729 WebRect selection_rect;
4730 int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y),
4731 &selection_rect);
4732 if (ordinal == -1) {
4733 // Something went wrong, so send a no-op reply (force the main_frame to
4734 // report the current match count) in case the host is waiting for a
4735 // response due to rate-limiting).
4736 main_frame->increaseMatchCount(0, request_id);
4737 return;
4738 }
4739
4740 Send(new ViewHostMsg_Find_Reply(routing_id_,
4741 request_id,
4742 -1 /* number_of_matches */,
4743 selection_rect,
4744 ordinal,
4745 true /* final_update */));
4746}
4747
4748void RenderViewImpl::OnFindMatchRects(int current_version) {
4749 if (!webview())
4750 return;
4751
4752 WebFrame* main_frame = webview()->mainFrame();
4753 std::vector<gfx::RectF> match_rects;
4754
4755 int rects_version = main_frame->findMatchMarkersVersion();
4756 if (current_version != rects_version) {
4757 WebVector<WebFloatRect> web_match_rects;
4758 main_frame->findMatchRects(web_match_rects);
4759 match_rects.reserve(web_match_rects.size());
4760 for (size_t i = 0; i < web_match_rects.size(); ++i)
4761 match_rects.push_back(gfx::RectF(web_match_rects[i]));
4762 }
4763
4764 gfx::RectF active_rect = main_frame->activeFindMatchRect();
4765 Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_,
4766 rects_version,
4767 match_rects,
4768 active_rect));
4769}
4770#endif
4771
[email protected]54087fe2011-10-28 22:02:484772void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:514773 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4774 return;
4775
[email protected]258d31122010-05-09 10:59:414776 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:104777
[email protected]b75b8292010-10-01 07:28:254778 double old_zoom_level = webview()->zoomLevel();
4779 double zoom_level;
[email protected]54087fe2011-10-28 22:02:484780 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:254781 zoom_level = 0;
4782 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4783 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:484784 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:254785 } else {
4786 // Either the user hit the zoom factor limit and thus the zoom level is now
4787 // not a whole number, or a plugin changed it to a custom value. We want
4788 // to go to the next whole number so that the user can always get back to
4789 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:484790 if ((old_zoom_level > 1 && zoom > 0) ||
4791 (old_zoom_level < 1 && zoom < 0)) {
4792 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:254793 } else {
4794 // We're going towards 100%, so first go to the next whole number.
4795 zoom_level = static_cast<int>(old_zoom_level);
4796 }
4797 }
[email protected]b75b8292010-10-01 07:28:254798 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:414799 zoomLevelChanged();
4800}
4801
4802void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
4803 int zoom_center_x, int zoom_center_y) {
4804 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
4805 kScalingIncrementForGesture);
4806}
4807
4808void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
4809 int zoom_center_x,
4810 int zoom_center_y,
4811 float scaling_increment) {
4812 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4813 return;
4814
[email protected]c514d632011-08-16 22:54:444815 double old_page_scale_factor = webview()->pageScaleFactor();
4816 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:484817 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d632011-08-16 22:54:444818 page_scale_factor = 1.0;
4819 } else {
4820 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:414821 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d632011-08-16 22:54:444822 }
[email protected]47578fa02011-11-02 19:34:414823 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:094824 webview()->setPageScaleFactor(page_scale_factor,
4825 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:414826 }
[email protected]40bd6582009-12-04 23:49:514827}
4828
[email protected]310ebd6302011-10-10 19:06:284829void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174830 webview()->hidePopups();
4831 webview()->setZoomLevel(false, zoom_level);
4832 zoomLevelChanged();
4833}
4834
[email protected]310ebd6302011-10-10 19:06:284835void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4836 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544837 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294838}
4839
[email protected]310ebd6302011-10-10 19:06:284840void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274841 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294842}
4843
[email protected]310ebd6302011-10-10 19:06:284844void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274845 WebString no_encoding;
4846 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184847}
4848
[email protected]310ebd6302011-10-10 19:06:284849WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454850 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274851 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454852
4853 // xpath string can represent a frame deep down the tree (across multiple
4854 // frame DOMs).
4855 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4856 // should break into 2 xpaths
4857 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:414858 std::vector<string16> xpaths;
4859 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:454860
[email protected]26aa0482009-09-30 16:55:274861 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:414862 for (std::vector<string16>::const_iterator i = xpaths.begin();
4863 frame && i != xpaths.end(); ++i) {
4864 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294865 }
4866
[email protected]dd7daa82009-08-10 05:46:454867 return frame;
initial.commit09911bf2008-07-26 23:55:294868}
4869
[email protected]310ebd6302011-10-10 19:06:284870void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4871 const string16& jscript,
4872 int id,
4873 bool notify_result) {
[email protected]f0746082012-09-06 00:18:384874 UNSHIPPED_TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest");
[email protected]882b7b22010-10-05 03:34:534875 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294876}
4877
[email protected]f546640b2012-05-15 00:03:494878void RenderViewImpl::OnPostMessageEvent(
4879 const ViewMsg_PostMessage_Params& params) {
[email protected]0720b532012-08-28 19:23:374880 // Find the target frame of this message. The source tags the message with
4881 // |target_frame_id|, so use it to locate the frame.
4882 WebFrame* frame = FindFrameByID(webview()->mainFrame(),
4883 params.target_frame_id);
4884 if (!frame)
4885 return;
[email protected]f546640b2012-05-15 00:03:494886
4887 // Find the source frame if it exists.
[email protected]f546640b2012-05-15 00:03:494888 WebFrame* source_frame = NULL;
4889 if (params.source_routing_id != MSG_ROUTING_NONE) {
4890 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
4891 if (source_view)
[email protected]0720b532012-08-28 19:23:374892 source_frame = source_view->GetFrameByMappedID(params.source_frame_id);
[email protected]f546640b2012-05-15 00:03:494893 }
4894
4895 // Create an event with the message. The final parameter to initMessageEvent
4896 // is the last event ID, which is not used with postMessage.
4897 WebDOMEvent event = frame->document().createEvent("MessageEvent");
4898 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
4899 msg_event.initMessageEvent("message",
4900 // |canBubble| and |cancellable| are always false
4901 false, false,
4902 WebSerializedScriptValue::fromString(params.data),
4903 params.source_origin, source_frame, "");
4904
4905 // We must pass in the target_origin to do the security check on this side,
4906 // since it may have changed since the original postMessage call was made.
4907 WebSecurityOrigin target_origin;
4908 if (!params.target_origin.empty()) {
4909 target_origin =
4910 WebSecurityOrigin::createFromString(WebString(params.target_origin));
4911 }
4912 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
4913}
4914
[email protected]310ebd6302011-10-10 19:06:284915void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
4916 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:414917 WebFrame* frame = GetChildFrame(frame_xpath);
4918 if (!frame)
[email protected]216813952011-05-19 22:21:264919 return;
[email protected]ae461542009-06-19 19:03:414920
[email protected]01cf589c2011-07-28 18:04:034921 frame->document().insertUserStyleSheet(
4922 WebString::fromUTF8(css),
4923 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:484924}
4925
[email protected]310ebd6302011-10-10 19:06:284926void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:094927 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:044928
4929 // Keep track of the total bindings accumulated in this process.
4930 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:294931}
4932
[email protected]310ebd6302011-10-10 19:06:284933void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
4934 const std::string& value) {
[email protected]808bda52012-03-09 22:43:324935 if (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI)
4936 GetWebUIBindings()->SetProperty(name, value);
4937 else
4938 NOTREACHED() << "WebUI bindings not enabled.";
initial.commit09911bf2008-07-26 23:55:294939}
4940
[email protected]310ebd6302011-10-10 19:06:284941void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
4942 const gfx::Point& client_point,
4943 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:424944 WebDragOperationsMask ops,
4945 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:554946 WebDragOperation operation = webview()->dragTargetDragEnter(
4947 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:554948 client_point,
4949 screen_point,
[email protected]1f2230b2012-05-17 23:43:424950 ops,
4951 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:554952
4953 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4954}
4955
[email protected]310ebd6302011-10-10 19:06:284956void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
4957 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:424958 WebDragOperationsMask ops,
4959 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:554960 WebDragOperation operation = webview()->dragTargetDragOver(
4961 client_point,
4962 screen_point,
[email protected]1f2230b2012-05-17 23:43:424963 ops,
4964 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:554965
4966 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4967}
4968
[email protected]310ebd6302011-10-10 19:06:284969void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:554970 webview()->dragTargetDragLeave();
4971}
4972
[email protected]310ebd6302011-10-10 19:06:284973void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
[email protected]1f2230b2012-05-17 23:43:424974 const gfx::Point& screen_point,
4975 int key_modifiers) {
4976 webview()->dragTargetDrop(client_point, screen_point, key_modifiers);
[email protected]fcad49452011-06-28 17:11:574977
4978 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:554979}
4980
[email protected]310ebd6302011-10-10 19:06:284981void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4982 const gfx::Point& screen_point,
4983 bool ended,
4984 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034985 if (ended) {
[email protected]26aa0482009-09-30 16:55:274986 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204987 } else {
4988 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034989 }
initial.commit09911bf2008-07-26 23:55:294990}
4991
[email protected]310ebd6302011-10-10 19:06:284992void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274993 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294994}
4995
[email protected]310ebd6302011-10-10 19:06:284996void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594997 webkit_preferences_ = prefs;
4998 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294999}
5000
[email protected]310ebd6302011-10-10 19:06:285001void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:295002 alternate_error_page_url_ = url;
5003}
5004
[email protected]310ebd6302011-10-10 19:06:285005void RenderViewImpl::OnCustomContextMenuAction(
[email protected]35be7ec2012-02-12 20:42:515006 const content::CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:085007 unsigned action) {
5008 if (custom_context.is_pepper_menu)
5009 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
5010 else
5011 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:585012 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
5013 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:335014}
5015
[email protected]310ebd6302011-10-10 19:06:285016void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:515017 int id,
5018 const std::vector<FilePath>& paths) {
5019 if (!enumeration_completions_[id])
5020 return;
5021
5022 WebVector<WebString> ws_file_names(paths.size());
5023 for (size_t i = 0; i < paths.size(); ++i)
5024 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
5025
5026 enumeration_completions_[id]->didChooseFile(ws_file_names);
5027 enumeration_completions_.erase(id);
5028}
5029
[email protected]fb11b6a42012-03-14 07:25:125030void RenderViewImpl::OnFileChooserResponse(
[email protected]ddb034b2012-06-26 20:31:395031 const std::vector<ui::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:365032 // This could happen if we navigated to a different page before the user
5033 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:475034 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:365035 return;
5036
[email protected]b5188522012-03-15 00:18:045037 // Convert Chrome's SelectedFileInfo list to WebKit's.
5038 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
5039 files.size());
5040 for (size_t i = 0; i < files.size(); ++i) {
5041 WebFileChooserCompletion::SelectedFileInfo selected_file;
[email protected]53f04c82012-07-26 02:31:095042 selected_file.path = webkit_glue::FilePathToWebString(files[i].local_path);
[email protected]b5188522012-03-15 00:18:045043 selected_file.displayName = webkit_glue::FilePathStringToWebString(
5044 files[i].display_name);
5045 selected_files[i] = selected_file;
5046 }
[email protected]a1128322009-10-06 18:38:465047
[email protected]cdaf8d02010-03-30 19:52:475048 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:045049 file_chooser_completions_.front()->completion->didChooseFile(
5050 selected_files);
[email protected]cdaf8d02010-03-30 19:52:475051 file_chooser_completions_.pop_front();
5052
5053 // If there are more pending file chooser requests, schedule one now.
5054 if (!file_chooser_completions_.empty()) {
5055 Send(new ViewHostMsg_RunFileChooser(routing_id_,
5056 file_chooser_completions_.front()->params));
5057 }
initial.commit09911bf2008-07-26 23:55:295058}
5059
[email protected]244ac1892011-12-02 17:04:475060void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
5061 const gfx::Size& max_size) {
5062 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5063 if (!webview())
5064 return;
[email protected]61e2b3cc2012-03-02 16:13:345065 webview()->enableAutoResizeMode(min_size, max_size);
5066}
5067
5068void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
5069 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5070 if (!webview())
5071 return;
5072 webview()->disableAutoResizeMode();
5073
5074 Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK);
[email protected]244ac1892011-12-02 17:04:475075}
5076
[email protected]2bf834f2011-11-17 20:02:215077void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:245078 if (send_preferred_size_changes_)
5079 return;
[email protected]9fb325e2010-05-06 18:23:245080 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:395081
[email protected]d812fd12011-05-27 23:05:075082 // Start off with an initial preferred size notification (in case
5083 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:595084 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:085085}
5086
[email protected]310ebd6302011-10-10 19:06:285087void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:105088 const gfx::Size& disable_scrollbar_size_limit) {
5089 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
5090}
5091
[email protected]310ebd6302011-10-10 19:06:285092void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:315093 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:505094 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:515095 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:375096 UpdateFontRenderingFromRendererPrefs();
[email protected]a13283cc2012-04-05 00:21:225097#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:415098 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
5099 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:465100 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]f78452f2012-05-15 02:07:525101 ui::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:345102 renderer_prefs.thumb_inactive_color,
5103 renderer_prefs.thumb_active_color,
5104 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:555105#endif
[email protected]93623c5d2009-12-10 21:40:325106
[email protected]a13283cc2012-04-05 00:21:225107#if defined(USE_ASH) || defined(TOOLKIT_GTK)
[email protected]644d77e2010-01-27 01:03:105108 if (webview()) {
[email protected]a13283cc2012-04-05 00:21:225109#if defined(TOOLKIT_GTK)
[email protected]93623c5d2009-12-10 21:40:325110 webview()->setScrollbarColors(
5111 renderer_prefs.thumb_inactive_color,
5112 renderer_prefs.thumb_active_color,
5113 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:555114#endif
[email protected]644d77e2010-01-27 01:03:105115 webview()->setSelectionColors(
5116 renderer_prefs.active_selection_bg_color,
5117 renderer_prefs.active_selection_fg_color,
5118 renderer_prefs.inactive_selection_bg_color,
5119 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:465120 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:105121 }
[email protected]7a74e102009-09-03 00:16:565122#endif
[email protected]d299d972012-03-23 02:26:555123
[email protected]d051d9a2011-12-10 02:02:505124 // If the zoom level for this page matches the old zoom default, and this
5125 // is not a plugin, update the zoom level to match the new default.
5126 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
5127 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
5128 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
5129 zoomLevelChanged();
5130 }
[email protected]80d96fa2009-06-10 22:34:515131}
5132
[email protected]310ebd6302011-10-10 19:06:285133void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
5134 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:285135 if (webview())
5136 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:565137}
5138
[email protected]77829642012-05-15 14:47:175139void RenderViewImpl::OnOrientationChangeEvent(int orientation) {
5140 webview()->mainFrame()->sendOrientationChangeEvent(orientation);
5141}
5142
[email protected]81375e872012-01-11 21:40:365143void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
5144 const WebPluginAction& action) {
5145 if (webview())
5146 webview()->performPluginAction(action, location);
5147}
5148
[email protected]310ebd6302011-10-10 19:06:285149void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:195150 const GURL& page_url) {
5151 // Prepare list to storage all savable resource links.
5152 std::vector<GURL> resources_list;
[email protected]c2d986512012-05-12 00:22:465153 std::vector<GURL> referrer_urls_list;
5154 std::vector<WebKit::WebReferrerPolicy> referrer_policies_list;
[email protected]18d5be92011-07-25 18:00:195155 std::vector<GURL> frames_list;
5156 webkit_glue::SavableResourcesResult result(&resources_list,
[email protected]c2d986512012-05-12 00:22:465157 &referrer_urls_list,
5158 &referrer_policies_list,
[email protected]18d5be92011-07-25 18:00:195159 &frames_list);
5160
[email protected]c2d986512012-05-12 00:22:465161 // webkit/ doesn't know about content::Referrer.
[email protected]18d5be92011-07-25 18:00:195162 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
5163 webview(),
5164 page_url,
5165 &result,
[email protected]1de7a172012-05-28 18:36:435166 const_cast<const char**>(content::GetSavableSchemes()))) {
[email protected]18d5be92011-07-25 18:00:195167 // If something is wrong when collecting all savable resource links,
5168 // send empty list to embedder(browser) to tell it failed.
[email protected]c2d986512012-05-12 00:22:465169 referrer_urls_list.clear();
5170 referrer_policies_list.clear();
[email protected]18d5be92011-07-25 18:00:195171 resources_list.clear();
5172 frames_list.clear();
5173 }
5174
[email protected]c2d986512012-05-12 00:22:465175 std::vector<content::Referrer> referrers_list;
5176 CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size());
5177 for (unsigned i = 0; i < referrer_urls_list.size(); ++i) {
5178 referrers_list.push_back(
5179 content::Referrer(referrer_urls_list[i], referrer_policies_list[i]));
5180 }
5181
[email protected]18d5be92011-07-25 18:00:195182 // Send result of all savable resource links to embedder.
5183 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
5184 resources_list,
5185 referrers_list,
5186 frames_list));
5187}
5188
[email protected]310ebd6302011-10-10 19:06:285189void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:195190 const std::vector<GURL>& links,
5191 const std::vector<FilePath>& local_paths,
5192 const FilePath& local_directory_name) {
5193
5194 // Convert std::vector of GURLs to WebVector<WebURL>
5195 WebVector<WebURL> weburl_links(links);
5196
5197 // Convert std::vector of std::strings to WebVector<WebString>
5198 WebVector<WebString> webstring_paths(local_paths.size());
5199 for (size_t i = 0; i < local_paths.size(); i++)
5200 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
5201
5202 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
5203 webstring_paths,
5204 webkit_glue::FilePathToWebString(
5205 local_directory_name));
5206}
5207
[email protected]310ebd6302011-10-10 19:06:285208void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:125209 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:275210 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:125211 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
5212 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
5213 before_unload_start_time,
5214 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:295215}
5216
[email protected]310ebd6302011-10-10 19:06:285217void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]69ddf852012-02-21 23:21:315218 // Ensure that no other in-progress navigation continues.
5219 OnStop();
5220
[email protected]73eb2602012-02-09 19:50:555221 // Only run unload if we're not swapped out yet, but send the ack either way.
5222 if (!is_swapped_out_) {
5223 // Swap this RenderView out so the tab can navigate to a page rendered by a
5224 // different process. This involves running the unload handler and clearing
5225 // the page. Once WasSwappedOut is called, we also allow this process to
5226 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:155227
[email protected]73eb2602012-02-09 19:50:555228 // Send an UpdateState message before we get swapped out.
5229 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:155230
[email protected]73eb2602012-02-09 19:50:555231 // Synchronously run the unload handler before sending the ACK.
5232 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:155233
[email protected]73eb2602012-02-09 19:50:555234 // Swap out and stop sending any IPC messages that are not ACKs.
5235 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:155236
[email protected]285f4bb82012-04-17 15:57:285237 // Replace the page with a blank dummy URL. The unload handler will not be
[email protected]73eb2602012-02-09 19:50:555238 // run a second time, thanks to a check in FrameLoader::stopLoading.
5239 // TODO(creis): Need to add a better way to do this that avoids running the
[email protected]285f4bb82012-04-17 15:57:285240 // beforeunload handler. For now, we just run it a second time silently.
[email protected]0720b532012-08-28 19:23:375241 NavigateToSwappedOutURL(webview()->mainFrame());
[email protected]961541a92012-06-01 21:15:285242
5243 // Let WebKit know that this view is hidden so it can drop resources and
5244 // stop compositing.
5245 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false);
[email protected]73eb2602012-02-09 19:50:555246 }
[email protected]992db4c2011-05-12 15:37:155247
5248 // Just echo back the params in the ACK.
5249 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
5250}
5251
[email protected]0720b532012-08-28 19:23:375252void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) {
[email protected]14392a52012-05-02 20:28:445253 // We use loadRequest instead of loadHTMLString because the former commits
5254 // synchronously. Otherwise a new navigation can interrupt the navigation
5255 // to content::kSwappedOutURL. If that happens to be to the page we had been
5256 // showing, then WebKit will never send a commit and we'll be left spinning.
5257 GURL swappedOutURL(content::kSwappedOutURL);
5258 WebURLRequest request(swappedOutURL);
[email protected]0720b532012-08-28 19:23:375259 frame->loadRequest(request);
[email protected]14392a52012-05-02 20:28:445260}
5261
[email protected]310ebd6302011-10-10 19:06:285262void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:375263 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:295264 // TODO(creis): We'd rather use webview()->Close() here, but that currently
5265 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
5266 // in the onunload handler from appearing. For now, we're bypassing that and
5267 // calling the FrameLoader's CloseURL method directly. This should be
5268 // revisited to avoid having two ways to close a page. Having a single way
5269 // to close that can run onunload is also useful for fixing
5270 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:275271 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:295272
[email protected]992db4c2011-05-12 15:37:155273 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:295274}
5275
[email protected]310ebd6302011-10-10 19:06:285276void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:025277#if defined(USE_AURA)
5278 // Aura doesn't care if we switch themes.
5279#elif defined(OS_WIN)
[email protected]f78452f2012-05-15 02:07:525280 ui::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:465281 if (webview())
5282 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:575283#else // defined(OS_WIN)
5284 // TODO(port): we don't support theming on non-Windows platforms yet
5285 NOTIMPLEMENTED();
5286#endif
initial.commit09911bf2008-07-26 23:55:295287}
5288
[email protected]310ebd6302011-10-10 19:06:285289void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:085290 if (decrement_shared_popup_at_destruction_)
5291 shared_popup_counter_->data--;
5292 shared_popup_counter_ = new SharedRenderViewCounter(0);
5293 decrement_shared_popup_at_destruction_ = false;
5294}
5295
[email protected]310ebd6302011-10-10 19:06:285296bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
5297 const WebURLError& error,
5298 bool replace) {
[email protected]15d79e12009-08-02 19:23:455299 // We only show alternate error pages in the main frame. They are
5300 // intended to assist the user when navigating, so there is not much
5301 // value in showing them for failed subframes. Ideally, we would be
5302 // able to use the TYPED transition type for this, but that flag is
5303 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455304 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455305 return false;
5306
5307 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375308 // connection failure.
[email protected]15d79e12009-08-02 19:23:455309 int ec = error.reason;
5310 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5311 ec != net::ERR_CONNECTION_FAILED &&
5312 ec != net::ERR_CONNECTION_REFUSED &&
5313 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]82114f52012-03-20 22:53:415314 ec != net::ERR_CONNECTION_TIMED_OUT) {
[email protected]15d79e12009-08-02 19:23:455315 return false;
[email protected]82114f52012-03-20 22:53:415316 }
[email protected]15d79e12009-08-02 19:23:455317
5318 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555319 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455320 if (!error_page_url.is_valid())
5321 return false;
5322
5323 // Load an empty page first so there is an immediate response to the error,
5324 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455325 frame->loadHTMLString(std::string(),
[email protected]285f4bb82012-04-17 15:57:285326 GURL(content::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455327 error.unreachableURL,
5328 replace);
5329
5330 // Now, create a fetcher for the error page and associate it with the data
5331 // source we just created via the LoadHTMLString call. That way if another
5332 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:075333 DocumentState* document_state =
5334 DocumentState::FromDataSource(frame->provisionalDataSource());
5335 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:455336 new AltErrorPageResourceFetcher(
5337 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:085338 base::Bind(&RenderViewImpl::AltErrorPageFinished,
5339 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:455340 return true;
5341}
5342
[email protected]310ebd6302011-10-10 19:06:285343void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
5344 const WebURLError& original_error,
5345 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:455346 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:095347 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:555348 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:095349 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:455350}
5351
[email protected]310ebd6302011-10-10 19:06:285352void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:005353 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475354 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005355}
5356
[email protected]310ebd6302011-10-10 19:06:285357void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:095358 const gfx::Rect& resizer_rect,
5359 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:105360 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475361 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105362 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205363 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:315364 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:105365 }
[email protected]dd6afca2011-08-13 03:44:315366 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:105367 }
5368
[email protected]ee41e7d22011-10-14 19:34:095369 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:005370}
[email protected]0aa477bd2009-03-23 22:21:435371
[email protected]29ed96a2012-02-04 18:12:165372void RenderViewImpl::WillInitiatePaint() {
5373 // Notify the pepper plugins that we're about to paint.
5374 pepper_delegate_.ViewWillInitiatePaint();
5375}
5376
[email protected]310ebd6302011-10-10 19:06:285377void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:165378 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]53900d52010-06-16 04:25:015379 pepper_delegate_.ViewInitiatedPaint();
[email protected]7900bfdb2012-05-24 19:31:245380 if (GetGuestToEmbedderChannel())
5381 GetGuestToEmbedderChannel()->IssueSwapBuffers(guest_graphics_resource());
[email protected]00c39612010-03-06 02:53:285382}
5383
[email protected]310ebd6302011-10-10 19:06:285384void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:285385 // Notify any pepper plugins that we painted. This will call into the plugin,
5386 // and we it may ask to close itself as a result. This will, in turn, modify
5387 // our set, possibly invalidating the iterator. So we iterate on a copy that
5388 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:015389 pepper_delegate_.ViewFlushedPaint();
5390
[email protected]5b1dec8c2012-02-07 04:35:385391 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
5392 // See crbug.com/112921.
5393 if (!webview())
5394 return;
5395
[email protected]00c39612010-03-06 02:53:285396 WebFrame* main_frame = webview()->mainFrame();
5397
5398 // If we have a provisional frame we are between the start and commit stages
5399 // of loading and we don't want to save stats.
5400 if (!main_frame->provisionalDataSource()) {
5401 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:075402 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:285403
[email protected]05c8e502010-08-15 15:13:525404 // TODO(jar): The following code should all be inside a method, probably in
5405 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285406 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:075407 if (document_state->first_paint_time().is_null()) {
5408 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:285409 }
[email protected]007733c2011-11-17 00:34:075410 if (document_state->first_paint_after_load_time().is_null() &&
5411 !document_state->finish_load_time().is_null()) {
5412 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:285413 }
5414 }
5415}
5416
[email protected]310ebd6302011-10-10 19:06:285417void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:085418 RenderWidget::OnSwapBuffersPosted();
5419}
5420
[email protected]310ebd6302011-10-10 19:06:285421void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:245422 RenderWidget::OnSwapBuffersComplete();
5423}
5424
[email protected]310ebd6302011-10-10 19:06:285425void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:245426 RenderWidget::OnSwapBuffersAborted();
5427}
5428
[email protected]310ebd6302011-10-10 19:06:285429webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:155430 const gfx::Rect& paint_bounds,
5431 TransportDIB** dib,
5432 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:205433 gfx::Rect* clip,
5434 float* scale_factor) {
[email protected]ca4847f2010-09-24 05:39:155435 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
[email protected]0f3a2d12012-09-01 03:37:205436 paint_bounds, dib, location, clip, scale_factor);
[email protected]ca4847f2010-09-24 05:39:155437}
5438
[email protected]310ebd6302011-10-10 19:06:285439gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:075440 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:435441 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:525442}
5443
[email protected]310ebd6302011-10-10 19:06:285444void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:165445 if (webview())
[email protected]26aa0482009-09-30 16:55:275446 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165447}
5448
[email protected]310ebd6302011-10-10 19:06:285449void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:145450 if (webview())
[email protected]b4bb2502009-10-01 22:35:275451 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145452
5453 SetBackground(background);
5454}
5455
[email protected]2a84f9d2012-06-05 21:50:435456void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) {
5457 if (accessibility_mode_ == new_mode)
5458 return;
5459 accessibility_mode_ = new_mode;
5460 if (renderer_accessibility_) {
5461 delete renderer_accessibility_;
5462 renderer_accessibility_ = NULL;
5463 }
5464 if (accessibility_mode_ == AccessibilityModeComplete)
5465 renderer_accessibility_ = new RendererAccessibilityComplete(this);
5466 else if (accessibility_mode_ == AccessibilityModeEditableTextOnly)
5467 renderer_accessibility_ = new RendererAccessibilityFocusOnly(this);
5468}
5469
[email protected]310ebd6302011-10-10 19:06:285470void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:345471 if (webview())
[email protected]b4bb2502009-10-01 22:35:275472 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265473
5474#if defined(OS_MACOSX)
5475 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5476 for (plugin_it = plugin_delegates_.begin();
5477 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5478 (*plugin_it)->SetWindowFocus(active);
5479 }
5480#endif
[email protected]8c66c5a2009-07-22 17:26:345481}
5482
[email protected]7a17bac02012-03-07 21:58:125483void RenderViewImpl::OnSetNavigationStartTime(
5484 const base::TimeTicks& browser_navigation_start) {
5485 if (!webview())
5486 return;
5487
5488 // Only the initial navigation can be a cross-renderer navigation. If we've
5489 // already navigated away from that page, we can ignore this message.
5490 if (page_id_ != -1)
5491 return;
5492
5493 // browser_navigation_start is likely before this process existed, so we can't
5494 // use InterProcessTimeTicksConverter. Instead, the best we can do is just
5495 // ensure we don't report a bogus value in the future.
5496 base::TimeTicks navigation_start = std::min(base::TimeTicks::Now(),
5497 browser_navigation_start);
5498 webview()->mainFrame()->provisionalDataSource()->setNavigationStartTime(
5499 (navigation_start - base::TimeTicks()).InSecondsF());
5500}
5501
[email protected]6ce7abc52010-02-02 18:40:145502#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285503void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:145504 // Inform plugins that their container has changed visibility.
5505 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5506 for (plugin_it = plugin_delegates_.begin();
5507 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5508 (*plugin_it)->SetContainerVisibility(visible);
5509 }
5510}
[email protected]1e6e3c992010-02-08 15:52:135511
[email protected]310ebd6302011-10-10 19:06:285512void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
5513 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:135514 // Inform plugins that their window's frame has changed.
5515 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5516 for (plugin_it = plugin_delegates_.begin();
5517 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5518 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5519 }
5520}
[email protected]935d63d2010-10-15 23:31:555521
[email protected]310ebd6302011-10-10 19:06:285522void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
5523 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135524 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555525 // applies to it or not, so inform all the delegates.
5526 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5527 for (plugin_it = plugin_delegates_.begin();
5528 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135529 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555530 }
5531}
[email protected]6ce7abc52010-02-02 18:40:145532#endif // OS_MACOSX
5533
[email protected]310ebd6302011-10-10 19:06:285534void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:485535 const EditCommands& edit_commands) {
5536 edit_commands_ = edit_commands;
5537}
5538
[email protected]310ebd6302011-10-10 19:06:285539void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:595540 // We need to grab a pointer to the doomed WebView before we destroy it.
5541 WebView* doomed = webview();
5542 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495543 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:595544}
5545
[email protected]310ebd6302011-10-10 19:06:285546void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:485547 edit_commands_.clear();
5548}
5549
[email protected]310ebd6302011-10-10 19:06:285550bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]217690d2012-01-27 07:33:115551 pepper_delegate_.WillHandleMouseEvent();
5552
5553 // If the mouse is locked, only the current owner of the mouse lock can
5554 // process mouse events.
5555 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:375556}
5557
[email protected]2b942c332012-04-25 16:26:265558void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515559 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065560}
5561
[email protected]310ebd6302011-10-10 19:06:285562void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:245563 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
5564}
5565
[email protected]310ebd6302011-10-10 19:06:285566void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:435567 RenderWidget::OnWasHidden();
5568
[email protected]2d7b82c2012-06-01 05:57:505569#if defined(OS_ANDROID)
5570 // Inform WebMediaPlayerManagerAndroid to release all media player resources.
5571 media_player_manager_->ReleaseMediaResources();
5572#endif
5573
[email protected]a6939ca42011-02-18 17:58:075574 if (webview()) {
5575 webview()->settings()->setMinimumTimerInterval(
5576 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:445577 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075578 }
5579
[email protected]204f1df2012-01-04 20:21:135580 // Inform PPAPI plugins that their page is no longer visible.
5581 pepper_delegate_.PageVisibilityChanged(false);
5582
[email protected]a6939ca42011-02-18 17:58:075583#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135584 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:435585 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5586 for (plugin_it = plugin_delegates_.begin();
5587 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5588 (*plugin_it)->SetContainerVisibility(false);
5589 }
[email protected]a6939ca42011-02-18 17:58:075590#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:435591}
5592
[email protected]9e2e4632012-07-27 16:38:415593void RenderViewImpl::OnWasShown(bool needs_repainting) {
5594 RenderWidget::OnWasShown(needs_repainting);
[email protected]941e4552010-02-01 21:23:435595
[email protected]a6939ca42011-02-18 17:58:075596 if (webview()) {
5597 webview()->settings()->setMinimumTimerInterval(
5598 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:445599 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075600 }
5601
[email protected]204f1df2012-01-04 20:21:135602 // Inform PPAPI plugins that their page is visible.
5603 pepper_delegate_.PageVisibilityChanged(true);
5604
[email protected]a6939ca42011-02-18 17:58:075605#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135606 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:435607 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5608 for (plugin_it = plugin_delegates_.begin();
5609 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5610 (*plugin_it)->SetContainerVisibility(true);
5611 }
[email protected]784ea1ab2010-09-18 00:02:345612#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:075613}
[email protected]1e6e3c992010-02-08 15:52:135614
[email protected]310ebd6302011-10-10 19:06:285615bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]9caf09bc2012-06-25 21:46:285616 // Contexts using the command buffer support asynchronous swapbuffers.
[email protected]f89e173a2012-08-24 01:12:265617 // See RenderViewImpl::createOutputSurface().
[email protected]9caf09bc2012-06-25 21:46:285618 if (WebWidgetHandlesCompositorScheduling() ||
5619 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL))
[email protected]555e75d2011-10-08 01:23:385620 return false;
5621
[email protected]9caf09bc2012-06-25 21:46:285622 return true;
[email protected]65225772011-05-12 21:10:245623}
5624
[email protected]310ebd6302011-10-10 19:06:285625void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:135626 RenderWidget::OnSetFocus(enable);
5627
[email protected]7d3c02c2010-05-05 23:10:315628 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075629 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135630 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5631 for (plugin_it = plugin_delegates_.begin();
5632 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345633#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315634 // RenderWidget's call to setFocus can cause the underlying webview's
5635 // activation state to change just like a call to setIsActive.
5636 if (enable)
5637 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345638#endif
[email protected]7d3c02c2010-05-05 23:10:315639 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135640 }
5641 }
[email protected]a01da5682012-06-30 00:37:315642 // Notify all Pepper plugins.
5643 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135644}
[email protected]941e4552010-02-01 21:23:435645
[email protected]310ebd6302011-10-10 19:06:285646void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:005647 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:505648 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:575649}
5650
[email protected]73bf95812011-10-12 11:38:325651void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:005652 UpdateTextInputState();
[email protected]8fe8f742012-06-14 00:36:085653 if (renderer_accessibility_)
5654 renderer_accessibility_->FocusedNodeChanged(WebNode());
[email protected]73bf95812011-10-12 11:38:325655}
5656
[email protected]3f783362011-10-21 22:40:505657void RenderViewImpl::PpapiPluginCaretPositionChanged() {
5658 UpdateSelectionBounds();
5659}
5660
[email protected]b25b3ee2012-01-13 05:19:545661bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
5662 if (!pepper_delegate_.IsPluginFocused())
5663 return false;
5664 *rect = pepper_delegate_.GetCaretBounds();
5665 return true;
5666}
5667
[email protected]397c23962012-05-21 07:09:325668void RenderViewImpl::SimulateImeSetComposition(
5669 const string16& text,
5670 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5671 int selection_start,
5672 int selection_end) {
5673 OnImeSetComposition(text, underlines, selection_start, selection_end);
5674}
5675
5676void RenderViewImpl::SimulateImeConfirmComposition(
5677 const string16& text,
5678 const ui::Range& replacement_range) {
5679 OnImeConfirmComposition(text, replacement_range);
5680}
5681
[email protected]73bf95812011-10-12 11:38:325682void RenderViewImpl::PpapiPluginCancelComposition() {
5683 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]58b48a0d2012-06-13 07:01:355684 const ui::Range range(ui::Range::InvalidRange());
5685 const std::vector<gfx::Rect> empty_bounds;
5686 UpdateCompositionInfo(range, empty_bounds);
[email protected]73bf95812011-10-12 11:38:325687}
5688
[email protected]3c8c74c2012-03-15 07:34:525689void RenderViewImpl::PpapiPluginSelectionChanged() {
5690 SyncSelectionIfRequired();
5691}
5692
[email protected]93df81e2012-08-10 22:22:465693void RenderViewImpl::PpapiPluginCreated(content::RendererPpapiHost* host) {
[email protected]236bf852012-07-27 22:49:365694 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
5695 DidCreatePepperPlugin(host));
5696}
5697
[email protected]310ebd6302011-10-10 19:06:285698void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:575699 const string16& text,
5700 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5701 int selection_start,
5702 int selection_end) {
[email protected]73bf95812011-10-12 11:38:325703 if (pepper_delegate_.IsPluginFocused()) {
5704 // When a PPAPI plugin has focus, we bypass WebKit.
5705 pepper_delegate_.OnImeSetComposition(text,
5706 underlines,
5707 selection_start,
5708 selection_end);
5709 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235710#if defined(OS_WIN)
5711 // When a plug-in has focus, we create platform-specific IME data used by
5712 // our IME emulator and send it directly to the focused plug-in, i.e. we
5713 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
5714 // instance ID is the same one as the specified ID.)
5715 if (focused_plugin_id_ >= 0) {
5716 std::vector<int> clauses;
5717 std::vector<int> target;
5718 for (size_t i = 0; i < underlines.size(); ++i) {
5719 clauses.push_back(underlines[i].startOffset);
5720 clauses.push_back(underlines[i].endOffset);
5721 if (underlines[i].thick) {
5722 target.clear();
5723 target.push_back(underlines[i].startOffset);
5724 target.push_back(underlines[i].endOffset);
5725 }
5726 }
5727 std::set<WebPluginDelegateProxy*>::iterator it;
5728 for (it = plugin_delegates_.begin();
5729 it != plugin_delegates_.end(); ++it) {
5730 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
5731 focused_plugin_id_);
5732 }
5733 return;
5734 }
5735#endif
[email protected]56ea1a62011-05-30 07:05:575736 RenderWidget::OnImeSetComposition(text,
5737 underlines,
5738 selection_start,
5739 selection_end);
5740 }
5741}
5742
[email protected]4de6d1692011-10-12 08:45:445743void RenderViewImpl::OnImeConfirmComposition(
5744 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:575745 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:325746 // When a PPAPI plugin has focus, we bypass WebKit.
5747 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:575748 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235749#if defined(OS_WIN)
5750 // Same as OnImeSetComposition(), we send the text from IMEs directly to
5751 // plug-ins. When we send IME text directly to plug-ins, we should not send
5752 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:445753 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:235754 if (focused_plugin_id_ >= 0) {
5755 std::set<WebPluginDelegateProxy*>::iterator it;
5756 for (it = plugin_delegates_.begin();
5757 it != plugin_delegates_.end(); ++it) {
5758 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
5759 }
5760 return;
5761 }
5762#endif
[email protected]ebd28ac2011-10-13 18:49:055763 if (replacement_range.IsValid() && webview()) {
5764 // Select the text in |replacement_range|, it will then be replaced by
5765 // text added by the call to RenderWidget::OnImeConfirmComposition().
5766 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:165767 WebRange webrange = WebRange::fromDocumentRange(
5768 frame, replacement_range.start(), replacement_range.length());
5769 if (!webrange.isNull())
[email protected]884f9002012-08-21 19:33:585770 frame->selectRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:055771 }
5772 }
[email protected]4de6d1692011-10-12 08:45:445773 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:575774 }
5775}
5776
[email protected]dea5e7682012-06-14 05:21:245777void RenderViewImpl::OnSetDeviceScaleFactor(float device_scale_factor) {
5778 RenderWidget::OnSetDeviceScaleFactor(device_scale_factor);
5779 if (webview())
5780 webview()->setDeviceScaleFactor(device_scale_factor);
5781}
5782
[email protected]310ebd6302011-10-10 19:06:285783ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:325784 return pepper_delegate_.IsPluginFocused() ?
5785 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
5786}
5787
[email protected]3f783362011-10-21 22:40:505788void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
5789 if (pepper_delegate_.IsPluginFocused()) {
5790 // TODO(kinaba) http://crbug.com/101101
5791 // Current Pepper IME API does not handle selection bounds. So we simply
5792 // use the caret position as an empty range for now. It will be updated
5793 // after Pepper API equips features related to surrounding text retrieval.
5794 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
5795 *start = caret;
5796 *end = caret;
5797 return;
5798 }
5799 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:455800}
5801
[email protected]58b48a0d2012-06-13 07:01:355802void RenderViewImpl::GetCompositionCharacterBounds(
5803 std::vector<gfx::Rect>* bounds) {
5804 DCHECK(bounds);
5805 bounds->clear();
5806
5807 if (!webview())
5808 return;
5809 size_t start_offset = 0;
5810 size_t character_count = 0;
5811 if (!webview()->compositionRange(&start_offset, &character_count))
5812 return;
5813 if (character_count == 0)
5814 return;
5815
5816 WebKit::WebFrame* frame = webview()->focusedFrame();
5817 if (!frame)
5818 return;
5819
5820 bounds->reserve(character_count);
5821 WebKit::WebRect webrect;
5822 for (size_t i = 0; i < character_count; ++i) {
5823 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
5824 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
5825 bounds->clear();
5826 return;
5827 }
5828 bounds->push_back(webrect);
5829 }
5830}
5831
[email protected]310ebd6302011-10-10 19:06:285832bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:325833 return pepper_delegate_.IsPluginFocused() ?
5834 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:575835}
5836
[email protected]e6ae0f6c2011-10-04 10:39:235837#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:285838void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:235839 if (focused)
5840 focused_plugin_id_ = plugin_id;
5841 else
5842 focused_plugin_id_ = -1;
5843}
5844#endif
5845
[email protected]43f28f832010-02-03 02:28:485846#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285847void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]82114f52012-03-20 22:53:415848 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
[email protected]b7f75862011-01-21 21:15:135849}
5850
[email protected]310ebd6302011-10-10 19:06:285851void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:135852 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:555853 // This message can be sent during event-handling, and needs to be delivered
5854 // within that context.
5855 msg->set_unblock(true);
5856 Send(msg);
5857}
5858
[email protected]310ebd6302011-10-10 19:06:285859gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235860 bool opaque, bool root) {
[email protected]b2968292012-03-28 01:35:515861 gfx::PluginWindowHandle window = gfx::kNullPluginWindow;
[email protected]43f28f832010-02-03 02:28:485862 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235863 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:115864 if (window) {
5865 fake_plugin_window_handles_.insert(window);
5866 }
[email protected]43f28f832010-02-03 02:28:485867 return window;
5868}
5869
[email protected]310ebd6302011-10-10 19:06:285870void RenderViewImpl::DestroyFakePluginWindowHandle(
5871 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:115872 if (window && fake_plugin_window_handles_.find(window) !=
5873 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:485874 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:115875 fake_plugin_window_handles_.erase(window);
5876 }
[email protected]43f28f832010-02-03 02:28:485877}
5878
[email protected]310ebd6302011-10-10 19:06:285879void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
5880 gfx::PluginWindowHandle window,
5881 int32 width,
5882 int32 height,
5883 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:335884 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485885 routing_id(), window, width, height, io_surface_identifier));
5886}
5887
[email protected]310ebd6302011-10-10 19:06:285888void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:335889 gfx::PluginWindowHandle window,
5890 int32 width,
5891 int32 height,
5892 TransportDIB::Handle transport_dib) {
5893 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075894 routing_id(), window, width, height, transport_dib));
5895}
5896
[email protected]310ebd6302011-10-10 19:06:285897TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:335898 size_t size) {
[email protected]1aef98132010-02-23 18:00:075899 TransportDIB::Handle dib_handle;
5900 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385901 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075902 return dib_handle;
5903 // Return an invalid handle if Send() fails.
5904 return TransportDIB::DefaultHandleValue();
5905}
5906
[email protected]310ebd6302011-10-10 19:06:285907void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
5908 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075909 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5910}
5911
[email protected]310ebd6302011-10-10 19:06:285912void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:325913 gfx::PluginWindowHandle window, uint64 surface_handle) {
[email protected]f35d6672010-10-28 21:39:145914 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:325915 routing_id(), window, surface_handle));
[email protected]43f28f832010-02-03 02:28:485916}
[email protected]82114f52012-03-20 22:53:415917#endif // defined(OS_MACOSX)
[email protected]58c321d2010-02-19 12:11:285918
[email protected]310ebd6302011-10-10 19:06:285919bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:235920 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:475921 WebFileChooserCompletion* completion) {
5922 static const size_t kMaximumPendingFileChooseRequests = 4;
5923 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5924 // This sanity check prevents too many file choose requests from getting
5925 // queued which could DoS the user. Getting these is most likely a
5926 // programming error (there are many ways to DoS the user so it's not
5927 // considered a "real" security check), either in JS requesting many file
5928 // choosers to pop up, or in a plugin.
5929 //
5930 // TODO(brettw) we might possibly want to require a user gesture to open
5931 // a file picker, which will address this issue in a better way.
5932 return false;
5933 }
5934
5935 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5936 new PendingFileChooser(params, completion)));
5937 if (file_chooser_completions_.size() == 1) {
5938 // Actually show the browse dialog when this is the first request.
5939 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5940 }
5941 return true;
5942}
5943
[email protected]310ebd6302011-10-10 19:06:285944WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:515945 if (!geolocation_dispatcher_)
5946 geolocation_dispatcher_ = new GeolocationDispatcher(this);
5947 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:255948}
[email protected]61c9f032010-03-31 23:04:195949
[email protected]310ebd6302011-10-10 19:06:285950WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:115951 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:225952#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:025953 if (!input_tag_speech_dispatcher_)
5954 input_tag_speech_dispatcher_ =
5955 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:225956#endif
[email protected]c52b2892012-03-07 11:01:025957 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:115958}
5959
[email protected]64d09222012-05-25 10:10:345960WebKit::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
5961#if defined(ENABLE_INPUT_SPEECH)
5962 if (!speech_recognition_dispatcher_)
5963 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
5964#endif
5965 return speech_recognition_dispatcher_;
5966}
5967
[email protected]310ebd6302011-10-10 19:06:285968WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:515969 if (!device_orientation_dispatcher_)
5970 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
5971 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:535972}
5973
[email protected]310ebd6302011-10-10 19:06:285974void RenderViewImpl::zoomLimitsChanged(double minimum_level,
5975 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:255976 // For now, don't remember plugin zoom values. We don't want to mix them with
5977 // normal web content (i.e. a fixed layout plugin would usually want them
5978 // different).
5979 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5980
[email protected]b75b8292010-10-01 07:28:255981 int minimum_percent = static_cast<int>(
5982 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5983 int maximum_percent = static_cast<int>(
5984 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255985
5986 Send(new ViewHostMsg_UpdateZoomLimits(
5987 routing_id_, minimum_percent, maximum_percent, remember));
5988}
5989
[email protected]310ebd6302011-10-10 19:06:285990void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:255991 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:085992 float zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:265993
5994 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
5995
[email protected]b75b8292010-10-01 07:28:255996 // Tell the browser which url got zoomed so it can update the menu and the
5997 // saved values if necessary
5998 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:085999 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:416000 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:256001}
6002
[email protected]310ebd6302011-10-10 19:06:286003void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
6004 const WebString& base_url,
6005 const WebString& url,
6006 const WebString& title) {
[email protected]3a3b75a2012-06-01 08:38:366007 bool user_gesture = (webview()->focusedFrame() &&
6008 webview()->focusedFrame()->isProcessingUserGesture());
[email protected]a6d36cc2011-02-23 00:39:486009 GURL base(base_url);
6010 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
6011 if (base.GetOrigin() != absolute_url.GetOrigin()) {
6012 return;
6013 }
[email protected]f1a29a02011-10-06 23:08:446014 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
6015 UTF16ToUTF8(scheme),
6016 absolute_url,
[email protected]3a3b75a2012-06-01 08:38:366017 title,
6018 user_gesture));
[email protected]a6d36cc2011-02-23 00:39:486019}
6020
[email protected]310ebd6302011-10-10 19:06:286021WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:446022 WebKit::WebPageVisibilityState current_state = is_hidden() ?
6023 WebKit::WebPageVisibilityStateHidden :
6024 WebKit::WebPageVisibilityStateVisible;
6025 WebKit::WebPageVisibilityState override_state = current_state;
6026 if (content::GetContentClient()->renderer()->
6027 ShouldOverridePageVisibilityState(this,
6028 &override_state))
6029 return override_state;
6030 return current_state;
[email protected]94dec932011-05-26 20:04:216031}
6032
[email protected]273558fb2012-01-12 15:03:516033WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
[email protected]273558fb2012-01-12 15:03:516034 EnsureMediaStreamImpl();
6035 return media_stream_impl_;
6036}
6037
[email protected]a0629af92012-08-08 00:39:376038void RenderViewImpl::draggableRegionsChanged() {
6039 FOR_EACH_OBSERVER(
6040 RenderViewObserver,
6041 observers_,
6042 DraggableRegionsChanged(webview()->mainFrame()));
6043}
6044
[email protected]20657a82012-08-21 20:23:036045#if defined(OS_ANDROID)
6046WebContentDetectionResult RenderViewImpl::detectContentAround(
6047 const WebHitTestResult& touch_hit) {
6048 DCHECK(!touch_hit.isNull());
6049 DCHECK(!touch_hit.node().isNull());
6050 DCHECK(touch_hit.node().isTextNode());
6051
6052 // Process the position with all the registered content detectors until
6053 // a match is found. Priority is provided by their relative order.
6054 for (ContentDetectorList::const_iterator it = content_detectors_.begin();
6055 it != content_detectors_.end(); ++it) {
6056 ContentDetector::Result content = (*it)->FindTappedContent(touch_hit);
6057 if (content.valid) {
6058 return WebContentDetectionResult(content.content_boundaries,
6059 UTF8ToUTF16(content.text), content.intent_url);
6060 }
6061 }
6062 return WebContentDetectionResult();
6063}
6064
6065void RenderViewImpl::scheduleContentIntent(const WebURL& intent) {
6066 // Introduce a short delay so that the user can notice the content.
6067 MessageLoop::current()->PostDelayedTask(
6068 FROM_HERE,
6069 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, AsWeakPtr(),
6070 intent, expected_content_intent_id_),
6071 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds));
6072}
6073
6074void RenderViewImpl::cancelScheduledContentIntents() {
6075 ++expected_content_intent_id_;
6076}
6077
6078void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent,
6079 size_t request_id) {
6080 if (request_id != expected_content_intent_id_)
6081 return;
6082
6083 // Remove the content highlighting if any.
6084 scheduleComposite();
6085
6086 if (!intent.is_empty())
6087 Send(new ViewHostMsg_StartContentIntent(routing_id_, intent));
6088}
6089#endif
6090
[email protected]310ebd6302011-10-10 19:06:286091void RenderViewImpl::OnAsyncFileOpened(
6092 base::PlatformFileError error_code,
6093 IPC::PlatformFileForTransit file_for_transit,
6094 int message_id) {
[email protected]27a9ef32010-09-10 04:06:246095 pepper_delegate_.OnAsyncFileOpened(
6096 error_code,
6097 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
6098 message_id);
6099}
[email protected]caf706f2010-10-26 17:54:086100
[email protected]310ebd6302011-10-10 19:06:286101void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:476102 int request_id,
[email protected]d54305072011-06-22 20:58:436103 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:476104 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
[email protected]2b657fd2011-04-18 16:00:476105 handle);
[email protected]eb415bf0e2011-04-14 02:45:426106}
6107
[email protected]d8415ad92012-08-23 14:40:506108void RenderViewImpl::OnPpapiBrokerPermissionResult(
6109 int request_id,
6110 bool result) {
6111 pepper_delegate_.OnPpapiBrokerPermissionResult(request_id, result);
6112}
6113
[email protected]caf706f2010-10-26 17:54:086114#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:286115void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:156116 if (external_popup_menu_ == NULL) {
6117 // Crash reports from the field indicate that we can be notified with a
6118 // NULL external popup menu (we probably get notified twice).
6119 // If you hit this please file a bug against jcivelli and include the page
6120 // and steps to repro.
6121 NOTREACHED();
6122 return;
6123 }
[email protected]caf706f2010-10-26 17:54:086124 external_popup_menu_->DidSelectItem(selected_index);
6125 external_popup_menu_.reset();
6126}
6127#endif
[email protected]bb461532010-11-26 21:50:236128
[email protected]24d2b172012-05-26 00:54:126129#if defined(OS_ANDROID)
6130void RenderViewImpl::OnSelectPopupMenuItems(
6131 bool canceled,
6132 const std::vector<int>& selected_indices) {
6133 // It is possible to receive more than one of these calls if the user presses
6134 // a select faster than it takes for the show-select-popup IPC message to make
6135 // it to the browser UI thread. Ignore the extra-messages.
6136 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug.
6137 if (!external_popup_menu_.get())
6138 return;
6139
6140 external_popup_menu_->DidSelectItems(canceled, selected_indices);
6141 external_popup_menu_.reset();
6142}
6143#endif
6144
[email protected]310ebd6302011-10-10 19:06:286145void RenderViewImpl::OnContextMenuClosed(
[email protected]35be7ec2012-02-12 20:42:516146 const content::CustomContextMenuContext& custom_context) {
[email protected]b29aa74b2011-01-31 21:41:086147 if (custom_context.is_pepper_menu)
6148 pepper_delegate_.OnContextMenuClosed(custom_context);
6149 else
6150 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:106151}
[email protected]5a7b15a2011-08-22 22:48:186152
[email protected]310ebd6302011-10-10 19:06:286153void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:186154 if (!webview())
6155 return;
6156 WebFrame* main_frame = webview()->mainFrame();
6157 if (!main_frame)
6158 return;
6159 main_frame->enableViewSourceMode(true);
6160}
[email protected]67bfb83f2011-09-22 03:36:376161
[email protected]310ebd6302011-10-10 19:06:286162bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:086163 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:406164}
[email protected]7f3c7af2011-10-20 22:52:516165
[email protected]64d0e192011-12-09 14:44:206166void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7e9c5bb02012-05-14 13:58:316167 DCHECK(!java_bridge_dispatcher_);
[email protected]464750f2011-10-24 23:16:186168#if defined(ENABLE_JAVA_BRIDGE)
[email protected]7e9c5bb02012-05-14 13:58:316169 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this);
[email protected]464750f2011-10-24 23:16:186170#endif
[email protected]7f3c7af2011-10-20 22:52:516171}
[email protected]0720b532012-08-28 19:23:376172
6173void RenderViewImpl::OnUpdatedFrameTree(
6174 int process_id,
6175 int route_id,
6176 const std::string& frame_tree) {
6177 base::DictionaryValue* frames = NULL;
6178 scoped_ptr<base::Value> tree(base::JSONReader::Read(frame_tree));
6179 if (tree.get() && tree->IsType(base::Value::TYPE_DICTIONARY))
6180 tree->GetAsDictionary(&frames);
6181
6182 updating_frame_tree_ = true;
6183 active_frame_id_map_.clear();
6184
6185 target_process_id_ = process_id;
6186 target_routing_id_ = route_id;
6187 CreateFrameTree(webview()->mainFrame(), frames);
6188
6189 updating_frame_tree_ = false;
6190}