blob: f6ddf8a6f8b1fe87b115a019406773c6c8c6199b [file] [log] [blame]
[email protected]b553edd52012-01-10 12:15:231// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]310ebd6302011-10-10 19:06:285#include "content/renderer/render_view_impl.h"
initial.commit09911bf2008-07-26 23:55:296
7#include <algorithm>
[email protected]b75b8292010-10-01 07:28:258#include <cmath>
initial.commit09911bf2008-07-26 23:55:299
[email protected]6e806822011-11-19 01:51:0810#include "base/bind.h"
11#include "base/bind_helpers.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5013#include "base/compiler_specific.h"
[email protected]e7ca2892012-09-01 00:52:1514#include "base/debug/trace_event.h"
[email protected]0720b532012-08-28 19:23:3715#include "base/json/json_reader.h"
[email protected]b1cf3372011-04-20 21:28:1016#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4917#include "base/lazy_instance.h"
[email protected]084c8552012-08-12 22:51:2018#include "base/message_loop_proxy.h"
[email protected]835d7c82010-10-14 04:38:3819#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2820#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5121#include "base/process_util.h"
[email protected]7ddea9802012-02-22 23:08:0522#include "base/string_number_conversions.h"
[email protected]0a35efc2012-03-13 17:28:1323#include "base/string_piece.h"
[email protected]318bf5802011-08-08 17:12:4124#include "base/string_split.h"
initial.commit09911bf2008-07-26 23:55:2925#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2826#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2627#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2228#include "base/utf_string_conversions.h"
[email protected]65bfd9972012-10-19 03:39:3729#include "cc/switches.h"
[email protected]e93e04e2011-03-14 00:27:1030#include "content/common/appcache/appcache_dispatcher.h"
[email protected]14392a52012-05-02 20:28:4431#include "content/common/child_thread.h"
[email protected]127dd582011-03-16 21:32:1032#include "content/common/clipboard_messages.h"
[email protected]0720b532012-08-28 19:23:3733#include "content/common/content_constants_internal.h"
[email protected]37666cf2011-03-13 21:51:4234#include "content/common/database_messages.h"
[email protected]59f4f2fa2011-03-23 01:00:5535#include "content/common/drag_messages.h"
[email protected]16dd6e22012-03-01 19:08:2036#include "content/common/fileapi/file_system_dispatcher.h"
37#include "content/common/fileapi/webfilesystem_callback_dispatcher.h"
[email protected]c26ad882012-02-07 06:41:2038#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]a2ef54c2011-10-10 16:20:3139#include "content/common/intents_messages.h"
[email protected]7f3c7af2011-10-20 22:52:5140#include "content/common/java_bridge_messages.h"
[email protected]bac466e2012-07-31 02:10:5441#include "content/common/old_browser_plugin_messages.h"
[email protected]127dd582011-03-16 21:32:1042#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0043#include "content/common/pepper_plugin_registry.h"
[email protected]10e5cf12011-04-13 04:10:4044#include "content/common/quota_dispatcher.h"
[email protected]940895b2011-08-20 00:50:0545#include "content/common/request_extra_data.h"
[email protected]5fa3a062012-03-21 15:39:3446#include "content/common/socket_stream_handle_data.h"
[email protected]778574e2011-03-21 22:03:5047#include "content/common/view_messages.h"
[email protected]4e1eb3392012-05-18 00:08:0548#include "content/common/webmessageportchannel_impl.h"
[email protected]e091df82011-10-11 18:13:2149#include "content/public/common/bindings_policy.h"
[email protected]744c2a22012-03-15 18:42:0450#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4851#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2952#include "content/public/common/content_switches.h"
[email protected]35be7ec2012-02-12 20:42:5153#include "content/public/common/context_menu_params.h"
[email protected]8caadeb2011-11-22 02:45:2354#include "content/public/common/file_chooser_params.h"
[email protected]a1d29162011-10-14 17:14:0355#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3456#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0757#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3258#include "content/public/renderer/navigation_state.h"
[email protected]1ecbe862012-10-05 01:29:1459#include "content/public/renderer/password_form_conversion_utils.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]f9526d12012-10-18 01:55:0370#include "content/renderer/disambiguation_popup_helper.h"
[email protected]766a7082012-02-03 23:39:1571#include "content/renderer/dom_automation_controller.h"
[email protected]1910fe82012-05-10 00:04:1072#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]498bc512012-09-21 21:50:0873#include "content/renderer/do_not_track_bindings.h"
[email protected]55722152011-03-22 01:33:5374#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1975#include "content/renderer/geolocation_dispatcher.h"
[email protected]84a83e192012-03-09 18:43:4076#include "content/renderer/gpu/compositor_thread.h"
[email protected]1842fe22012-08-13 23:24:3577#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]7d4481d12012-09-24 21:26:4778#include "content/renderer/gpu/compositor_software_output_device_gl_adapter.h"
[email protected]1784b2f2011-11-24 10:53:4879#include "content/renderer/idle_user_detector.h"
[email protected]c52b2892012-03-07 11:01:0280#include "content/renderer/input_tag_speech_dispatcher.h"
[email protected]07161902011-11-11 09:57:4281#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0282#include "content/renderer/load_progress_tracker.h"
[email protected]273558fb2012-01-12 15:03:5183#include "content/renderer/media/media_stream_dependency_factory.h"
84#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:4085#include "content/renderer/media/media_stream_impl.h"
[email protected]6048d512012-01-28 03:14:4886#include "content/renderer/media/render_audiosourceprovider.h"
[email protected]090f7312011-08-05 23:26:4087#include "content/renderer/media/render_media_log.h"
[email protected]6048d512012-01-28 03:14:4888#include "content/renderer/media/renderer_gpu_video_decoder_factories.h"
[email protected]ccee4862012-10-03 18:34:2689#include "content/renderer/media/rtc_peer_connection_handler.h"
[email protected]4a19be92011-09-22 14:25:0290#include "content/renderer/mhtml_generator.h"
[email protected]230b7ef2011-03-16 22:30:1991#include "content/renderer/notification_provider.h"
[email protected]6f516082011-03-17 19:15:3592#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0593#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4494#include "content/renderer/render_thread_impl.h"
[email protected]89054502012-06-03 10:29:2495#include "content/renderer/render_view_mouse_lock_dispatcher.h"
[email protected]2cff0052011-03-18 16:51:4496#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3297#include "content/renderer/renderer_accessibility.h"
[email protected]2a84f9d2012-06-05 21:50:4398#include "content/renderer/renderer_accessibility_complete.h"
99#include "content/renderer/renderer_accessibility_focus_only.h"
[email protected]663bd9e2011-03-21 01:07:01100#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]da8543762012-03-20 08:52:20101#include "content/renderer/renderer_webcolorchooser_impl.h"
[email protected]64d09222012-05-25 10:10:34102#include "content/renderer/speech_recognition_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:32103#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:19104#include "content/renderer/v8_value_converter_impl.h"
[email protected]0a35efc2012-03-13 17:28:13105#include "content/renderer/web_intents_host.h"
[email protected]663bd9e2011-03-21 01:07:01106#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:35107#include "content/renderer/webplugin_delegate_proxy.h"
108#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:49109#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41110#include "media/base/media_switches.h"
[email protected]b80322902012-03-06 01:33:50111#include "media/base/message_loop_factory.h"
[email protected]37136d162012-04-09 23:39:19112#include "media/filters/audio_renderer_impl.h"
[email protected]e1d69d762011-12-13 05:12:18113#include "media/filters/gpu_video_decoder.h"
[email protected]d1ef81d2012-07-24 11:39:36114#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29115#include "net/base/escape.h"
116#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09117#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04118#include "net/http/http_util.h"
[email protected]1842fe22012-08-13 23:24:35119#include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutputSurface.h"
[email protected]8bd0fe62011-01-17 06:44:37120#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]f546640b2012-05-15 00:03:49121#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEvent.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h"
[email protected]be2510c02012-05-28 14:52:14123#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:37125#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:37127#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
129#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
130#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
131#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]4b1146bc2012-07-10 18:46:03132#include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h"
[email protected]8bd0fe62011-01-17 06:44:37133#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37134#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57135#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58136#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
[email protected]592e20b2012-01-20 05:53:44137#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
[email protected]8b5af492011-11-28 21:50:58138#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14139#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]4e1eb3392012-05-18 00:08:05140#include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannel.h"
[email protected]8bd0fe62011-01-17 06:44:37141#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19142#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37143#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36144#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37145#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
146#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
147#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37148#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37149#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
150#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
151#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17152#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37153#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]10e5cf12011-04-13 04:10:40154#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51155#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08156#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
157#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
158#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
159#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
160#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
[email protected]132e281a2012-07-31 18:32:44161#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPBody.h"
[email protected]9c4bf232011-12-15 02:25:08162#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
[email protected]50da23d02012-04-13 17:47:48163#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00Handler.h"
164#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00HandlerClient.h"
[email protected]273558fb2012-01-12 15:03:51165#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
166#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
[email protected]9c4bf232011-12-15 02:25:08167#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
168#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
[email protected]f546640b2012-05-15 00:03:49169#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerializedScriptValue.h"
[email protected]9c4bf232011-12-15 02:25:08170#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]5fa3a062012-03-21 15:39:34171#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSocketStreamHandle.h"
[email protected]e6e90dc2011-12-03 00:01:37172#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
173#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
174#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
175#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
176#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
177#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26178#include "third_party/skia/include/core/SkBitmap.h"
[email protected]ddb034b2012-06-26 20:31:39179#include "ui/base/dialogs/selected_file_info.h"
[email protected]08397d52011-02-05 01:53:38180#include "ui/gfx/native_widget_types.h"
181#include "ui/gfx/point.h"
182#include "ui/gfx/rect.h"
[email protected]f9526d12012-10-18 01:55:03183#include "ui/gfx/size_conversions.h"
[email protected]c4a9e932011-03-05 04:05:55184#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04185#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]b928936b2012-04-13 01:16:16186#include "webkit/dom_storage/dom_storage_types.h"
[email protected]25e18f82010-10-27 16:38:43187#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]18d5be92011-07-25 18:00:19188#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24189#include "webkit/glue/glue_serialize.h"
[email protected]3a3b75a2012-06-01 08:38:36190#include "webkit/glue/web_intent_service_data.h"
[email protected]851334d2012-06-15 22:39:31191#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07192#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29193#include "webkit/glue/webkit_glue.h"
[email protected]b9fd01ba2012-02-28 01:50:40194#include "webkit/glue/weburlresponse_extradata_impl.h"
[email protected]7e8b4d12012-01-20 23:39:51195#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
[email protected]a9288f52011-11-17 05:18:16196#include "webkit/media/webmediaplayer_impl.h"
[email protected]5f04c3532012-09-25 01:28:39197#include "webkit/media/webmediaplayer_ms.h"
[email protected]191eb3f72010-12-21 06:27:50198#include "webkit/plugins/npapi/plugin_list.h"
199#include "webkit/plugins/npapi/webplugin_delegate.h"
200#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
201#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52202#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29203
[email protected]25fb9b32012-04-27 03:21:55204#if defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:03205#include "content/common/android/device_info.h"
206#include "content/renderer/android/address_detector.h"
207#include "content/renderer/android/content_detector.h"
208#include "content/renderer/android/email_detector.h"
209#include "content/renderer/android/phone_number_detector.h"
[email protected]dbd3d212012-07-13 02:17:22210#include "content/renderer/media/stream_texture_factory_impl_android.h"
[email protected]780fc8242012-09-19 20:28:52211#include "content/renderer/media/webmediaplayer_proxy_impl_android.h"
[email protected]20657a82012-08-21 20:23:03212#include "third_party/WebKit/Source/WebKit/chromium/public/WebHitTestResult.h"
[email protected]59363fc92012-09-05 03:46:31213#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoint.h"
214#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatRect.h"
215#include "ui/gfx/rect_f.h"
[email protected]780fc8242012-09-19 20:28:52216#include "webkit/media/android/media_player_bridge_manager_impl.h"
[email protected]25fb9b32012-04-27 03:21:55217#include "webkit/media/android/webmediaplayer_android.h"
[email protected]780fc8242012-09-19 20:28:52218#include "webkit/media/android/webmediaplayer_impl_android.h"
219#include "webkit/media/android/webmediaplayer_in_process_android.h"
[email protected]2d7b82c2012-06-01 05:57:50220#include "webkit/media/android/webmediaplayer_manager_android.h"
[email protected]25fb9b32012-04-27 03:21:55221#elif defined(OS_WIN)
[email protected]6c8afae52009-01-22 02:24:57222// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57223// * theming
[email protected]f78452f2012-05-15 02:07:52224#include "ui/base/native_theme/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03225#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37226#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]f78452f2012-05-15 02:07:52227#include "ui/base/native_theme/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33228#elif defined(OS_MACOSX)
229#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57230#endif
231
[email protected]9892b472010-09-16 00:23:42232using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08233using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21234using WebKit::WebApplicationCacheHost;
235using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26236using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41237using WebKit::WebColor;
238using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59239using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44240using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51241using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55242using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28243using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00244using WebKit::WebDocument;
[email protected]f546640b2012-05-15 00:03:49245using WebKit::WebDOMEvent;
246using WebKit::WebDOMMessageEvent;
[email protected]e80c73b2009-04-07 23:24:58247using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25248using WebKit::WebDragOperation;
249using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51250using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51251using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08252using WebKit::WebExternalPopupMenu;
253using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47254using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22255using WebKit::WebFileSystem;
256using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49257using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59258using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48259using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45260using WebKit::WebFrame;
[email protected]3306f262012-09-21 19:20:42261using WebKit::WebGestureEvent;
[email protected]7e8b4d12012-01-20 23:39:51262using WebKit::WebGraphicsContext3D;
[email protected]ca948a22009-06-25 19:36:17263using WebKit::WebHistoryItem;
[email protected]132e281a2012-07-31 18:32:44264using WebKit::WebHTTPBody;
[email protected]42054a252011-05-17 18:02:13265using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41266using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50267using WebKit::WebInputElement;
[email protected]3306f262012-09-21 19:20:42268using WebKit::WebInputEvent;
[email protected]ffc8bed2012-01-21 01:23:15269using WebKit::WebIntentRequest;
270using WebKit::WebIntentServiceInfo;
[email protected]3d9689372009-09-10 04:29:17271using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28272using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17273using WebKit::WebMediaPlayerClient;
[email protected]2b942c332012-04-25 16:26:26274using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:28275using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28276using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51277using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19278using WebKit::WebPageSerializer;
279using WebKit::WebPageSerializerClient;
[email protected]50da23d02012-04-13 17:47:48280using WebKit::WebPeerConnection00Handler;
281using WebKit::WebPeerConnection00HandlerClient;
282using WebKit::WebPeerConnectionHandler;
283using WebKit::WebPeerConnectionHandlerClient;
[email protected]3d9689372009-09-10 04:29:17284using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36285using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40286using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49287using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09288using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52289using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59290using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51291using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52292using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15293using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40294using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35295using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29296using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17297using WebKit::WebSecurityPolicy;
[email protected]f546640b2012-05-15 00:03:49298using WebKit::WebSerializedScriptValue;
[email protected]2fab253a2009-08-17 23:00:59299using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42300using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02301using WebKit::WebSize;
[email protected]5fa3a062012-03-21 15:39:34302using WebKit::WebSocketStreamHandle;
[email protected]bd92c3a2010-01-13 05:02:34303using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40304using WebKit::WebStorageQuotaCallbacks;
305using WebKit::WebStorageQuotaError;
306using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28307using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51308using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52309using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24310using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28311using WebKit::WebURL;
312using WebKit::WebURLError;
313using WebKit::WebURLRequest;
314using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28315using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03316using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28317using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26318using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26319using appcache::WebApplicationCacheHostImpl;
320using base::Time;
321using base::TimeDelta;
[email protected]e9ff79c2012-10-19 21:31:26322
[email protected]6fdd4182010-10-14 23:59:26323using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23324using webkit_glue::ResourceFetcher;
[email protected]6717bf272012-05-11 23:31:25325using webkit_glue::WebPreferences;
[email protected]b9fd01ba2012-02-28 01:50:40326using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33327
[email protected]20657a82012-08-21 20:23:03328#if defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:03329using WebKit::WebContentDetectionResult;
[email protected]59363fc92012-09-05 03:46:31330using WebKit::WebFloatPoint;
331using WebKit::WebFloatRect;
[email protected]20657a82012-08-21 20:23:03332using WebKit::WebHitTestResult;
333#endif
334
[email protected]e9ff79c2012-10-19 21:31:26335namespace content {
336
initial.commit09911bf2008-07-26 23:55:29337//-----------------------------------------------------------------------------
338
[email protected]310ebd6302011-10-10 19:06:28339typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49340static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02341
[email protected]882daa92009-11-05 16:31:31342// Time, in seconds, we delay before sending content state changes (such as form
343// state and scroll position) to the browser. We delay sending changes to avoid
344// spamming the browser.
345// To avoid having tab/session restore require sending a message to get the
346// current content state during tab closing we use a shorter timeout for the
347// foreground renderer. This means there is a small window of time from which
348// content state is modified and not sent to session restore, but this is
349// better than having to wake up all renderers during shutdown.
350static const int kDelaySecondsForContentStateSyncHidden = 5;
351static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29352
[email protected]e99ef6f2011-10-16 01:13:00353static const size_t kExtraCharsBeforeAndAfterSelection = 100;
354
[email protected]0aa55312008-10-17 21:53:08355// The maximum number of popups that can be spawned from one page.
356static const int kMaximumNumberOfUnacknowledgedPopups = 25;
357
[email protected]c514d6372011-08-16 22:54:44358static const float kScalingIncrement = 0.1f;
359
[email protected]47578fa02011-11-02 19:34:41360static const float kScalingIncrementForGesture = 0.01f;
361
[email protected]20657a82012-08-21 20:23:03362#if defined(OS_ANDROID)
363// Delay between tapping in content and launching the associated android intent.
364// Used to allow users see what has been recognized as content.
365static const size_t kContentIntentDelayMilliseconds = 700;
366#endif
367
[email protected]f546640b2012-05-15 00:03:49368static RenderViewImpl* FromRoutingID(int32 routing_id) {
369 return static_cast<RenderViewImpl*>(
370 ChildThread::current()->ResolveRoute(routing_id));
371}
372
[email protected]0720b532012-08-28 19:23:37373static WebKit::WebFrame* FindFrameByID(WebKit::WebFrame* root, int frame_id) {
374 for (WebFrame* frame = root; frame; frame = frame->traverseNext(false)) {
375 if (frame->identifier() == frame_id)
376 return frame;
377 }
378 return NULL;
379}
380
[email protected]726985e22009-06-18 21:09:28381static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
382 WebVector<WebURL> urls;
383 ds->redirectChain(urls);
384 result->reserve(urls.size());
385 for (size_t i = 0; i < urls.size(); ++i)
386 result->push_back(urls[i]);
387}
388
[email protected]007733c2011-11-17 00:34:07389// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44390// the AltErrorPageResourceFetcher is reset.
391static void StopAltErrorPageFetcher(WebDataSource* data_source) {
392 if (data_source) {
[email protected]007733c2011-11-17 00:34:07393 DocumentState* document_state = DocumentState::FromDataSource(data_source);
394 if (document_state)
395 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44396 }
397}
398
[email protected]007733c2011-11-17 00:34:07399static bool IsReload(const ViewMsg_Navigate_Params& params) {
400 return
401 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
[email protected]7c16976c2012-08-04 02:38:23402 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE ||
403 params.navigation_type ==
404 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]007733c2011-11-17 00:34:07405}
406
[email protected]b9fd01ba2012-02-28 01:50:40407static WebReferrerPolicy GetReferrerPolicyFromRequest(
[email protected]ca662822012-05-11 17:53:59408 WebFrame* frame,
[email protected]445e1042011-12-03 21:03:15409 const WebURLRequest& request) {
410 return request.extraData() ?
411 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
[email protected]ca662822012-05-11 17:53:59412 frame->document().referrerPolicy();
[email protected]445e1042011-12-03 21:03:15413}
414
[email protected]b9fd01ba2012-02-28 01:50:40415static WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
416 const WebURLResponse& response) {
417 return static_cast<WebURLResponseExtraDataImpl*>(
418 response.extraData());
419}
420
[email protected]2149cc622012-02-14 01:12:12421NOINLINE static void CrashIntentionally() {
422 // NOTE(shess): Crash directly rather than using NOTREACHED() so
423 // that the signature is easier to triage in crash reports.
424 volatile int* zero = NULL;
425 *zero = 0;
426}
427
[email protected]8bf1048012012-02-08 01:22:18428static void MaybeHandleDebugURL(const GURL& url) {
429 if (!url.SchemeIs(chrome::kChromeUIScheme))
430 return;
431 if (url == GURL(chrome::kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12432 CrashIntentionally();
[email protected]8bf1048012012-02-08 01:22:18433 } else if (url == GURL(chrome::kChromeUIKillURL)) {
434 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
435 } else if (url == GURL(chrome::kChromeUIHangURL)) {
436 for (;;) {
437 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
438 }
439 } else if (url == GURL(chrome::kChromeUIShorthangURL)) {
440 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
441 }
442}
443
[email protected]fd3238af2012-05-22 18:55:30444// Returns false unless this is a top-level navigation.
445static bool IsTopLevelNavigation(WebFrame* frame) {
446 return frame->parent() == NULL;
447}
448
449// Returns false unless this is a top-level navigation that crosses origins.
450static bool IsNonLocalTopLevelNavigation(const GURL& url,
451 WebFrame* frame,
452 WebNavigationType type) {
453 if (!IsTopLevelNavigation(frame))
454 return false;
455
456 // Navigations initiated within Webkit are not sent out to the external host
457 // in the following cases.
458 // 1. The url scheme is not http/https
459 // 2. The origin of the url and the opener is the same in which case the
460 // opener relationship is maintained.
461 // 3. Reloads/form submits/back forward navigations
462 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
463 return false;
464
465 // Not interested in reloads/form submits/resubmits/back forward navigations.
466 if (type != WebKit::WebNavigationTypeReload &&
467 type != WebKit::WebNavigationTypeFormSubmitted &&
468 type != WebKit::WebNavigationTypeFormResubmitted &&
469 type != WebKit::WebNavigationTypeBackForward) {
470 // The opener relationship between the new window and the parent allows the
471 // new window to script the parent and vice versa. This is not allowed if
472 // the origins of the two domains are different. This can be treated as a
473 // top level navigation and routed back to the host.
474 WebKit::WebFrame* opener = frame->opener();
475 if (!opener) {
476 return true;
477 }
478
479 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
480 return true;
481 }
482 return false;
483}
484
[email protected]38761452012-10-18 16:31:59485static void NotifyTimezoneChange(WebKit::WebFrame* frame) {
486 v8::HandleScope handle_scope;
487 v8::Context::Scope context_scope(frame->mainWorldScriptContext());
488 v8::Date::DateTimeConfigurationChangeNotification();
489 WebKit::WebFrame* child = frame->firstChild();
490 for (; child; child = child->nextSibling())
491 NotifyTimezoneChange(child);
492}
493
[email protected]0720b532012-08-28 19:23:37494// Recursively walks the frame tree and serializes it to JSON as described in
495// the comment for ViewMsg_UpdateFrameTree. If |exclude_frame_subtree| is not
496// NULL, the subtree for the frame is not included in the serialized form.
497// This is used when a frame is going to be removed from the tree.
498static void ConstructFrameTree(WebKit::WebFrame* frame,
499 WebKit::WebFrame* exclude_frame_subtree,
500 base::DictionaryValue* dict) {
[email protected]e9ff79c2012-10-19 21:31:26501 dict->SetString(kFrameTreeNodeNameKey,
[email protected]0720b532012-08-28 19:23:37502 UTF16ToUTF8(frame->assignedName()).c_str());
[email protected]e9ff79c2012-10-19 21:31:26503 dict->SetInteger(kFrameTreeNodeIdKey, frame->identifier());
[email protected]0720b532012-08-28 19:23:37504
505 WebFrame* child = frame->firstChild();
506 ListValue* children = new ListValue();
507 for (; child; child = child->nextSibling()) {
508 if (child == exclude_frame_subtree)
509 continue;
510
511 base::DictionaryValue* d = new base::DictionaryValue();
512 ConstructFrameTree(child, exclude_frame_subtree, d);
513 children->Append(d);
514 }
515 if (children->GetSize() > 0)
[email protected]e9ff79c2012-10-19 21:31:26516 dict->Set(kFrameTreeNodeSubtreeKey, children);
[email protected]0720b532012-08-28 19:23:37517}
518
initial.commit09911bf2008-07-26 23:55:29519///////////////////////////////////////////////////////////////////////////////
520
[email protected]310ebd6302011-10-10 19:06:28521struct RenderViewImpl::PendingFileChooser {
[email protected]e9ff79c2012-10-19 21:31:26522 PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c)
[email protected]cdaf8d02010-03-30 19:52:47523 : params(p),
524 completion(c) {
525 }
[email protected]e9ff79c2012-10-19 21:31:26526 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,
[email protected]e9ff79c2012-10-19 21:31:26573 const RendererPreferences& renderer_prefs,
[email protected]daf82f82011-10-31 22:35:31574 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]e9ff79c2012-10-19 21:31:26584 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)
[email protected]4d0f8182012-10-19 23:14:47619 body_background_color_(SK_ColorWHITE),
[email protected]20657a82012-08-21 20:23:03620 expected_content_intent_id_(0),
[email protected]780fc8242012-09-19 20:28:52621 media_player_proxy_(NULL),
[email protected]55750b32012-09-21 14:05:03622 synchronous_find_active_match_ordinal_(-1),
[email protected]20657a82012-08-21 20:23:03623#endif
[email protected]4fb60142011-08-09 02:22:08624 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18625 handling_select_range_(false),
626#if defined(OS_WIN)
627 focused_plugin_id_(-1),
628#endif
[email protected]468e4902012-05-23 01:49:31629 guest_to_embedder_channel_(guest_to_embedder_channel),
630 guest_pp_instance_(0),
631 guest_uninitialized_context_(NULL),
[email protected]0720b532012-08-28 19:23:37632 updating_frame_tree_(false),
633 pending_frame_tree_update_(false),
634 target_process_id_(0),
635 target_routing_id_(0),
[email protected]ef5e98e2011-12-06 09:49:18636 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]ce2b28e2012-08-09 15:53:57637 set_throttle_input_events(renderer_prefs.throttle_input_events);
[email protected]676126f72011-01-15 00:03:51638 routing_id_ = routing_id;
[email protected]9f4f3322012-01-18 22:29:56639 surface_id_ = surface_id;
[email protected]14392a52012-05-02 20:28:44640 if (opener_id != MSG_ROUTING_NONE && is_renderer_created)
[email protected]676126f72011-01-15 00:03:51641 opener_id_ = opener_id;
642
[email protected]74ce1ad2011-12-16 21:51:46643 // Ensure we start with a valid next_page_id_ from the browser.
644 DCHECK_GE(next_page_id_, 0);
645
[email protected]21b3a6ae2011-11-30 00:45:29646#if defined(ENABLE_NOTIFICATIONS)
647 notification_provider_ = new NotificationProvider(this);
648#else
649 notification_provider_ = NULL;
650#endif
651
[email protected]11fee2332011-03-29 20:36:35652 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11653 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35654
[email protected]20657a82012-08-21 20:23:03655 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
656
657#if defined(OS_ANDROID)
[email protected]e9ff79c2012-10-19 21:31:26658 scoped_ptr<DeviceInfo> device_info(new DeviceInfo());
[email protected]20657a82012-08-21 20:23:03659
[email protected]43b06002012-10-11 17:13:26660 webview()->setDeviceScaleFactor(device_info->GetDPIScale());
661
[email protected]20657a82012-08-21 20:23:03662 const std::string region_code =
663 command_line.HasSwitch(switches::kNetworkCountryIso)
664 ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso)
665 : device_info->GetNetworkCountryIso();
666 content_detectors_.push_back(linked_ptr<ContentDetector>(
667 new AddressDetector()));
668 content_detectors_.push_back(linked_ptr<ContentDetector>(
669 new PhoneNumberDetector(region_code)));
670 content_detectors_.push_back(linked_ptr<ContentDetector>(
671 new EmailDetector()));
672#endif
673
[email protected]676126f72011-01-15 00:03:51674 if (counter) {
675 shared_popup_counter_ = counter;
[email protected]14392a52012-05-02 20:28:44676 // Only count this if it isn't swapped out upon creation.
677 if (!swapped_out)
678 shared_popup_counter_->data++;
[email protected]676126f72011-01-15 00:03:51679 decrement_shared_popup_at_destruction_ = true;
680 } else {
681 shared_popup_counter_ = new SharedRenderViewCounter(0);
682 decrement_shared_popup_at_destruction_ = false;
683 }
684
[email protected]380244092011-10-07 17:26:27685 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51686 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47687 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51688 AddRef();
689
690 // If this is a popup, we must wait for the CreatingNew_ACK message before
691 // completing initialization. Otherwise, we can finish it now.
[email protected]468e4902012-05-23 01:49:31692 if (!guest_to_embedder_channel && opener_id_ == MSG_ROUTING_NONE) {
[email protected]676126f72011-01-15 00:03:51693 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55694 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51695 }
696
[email protected]34c61bd52011-05-02 19:38:33697 g_view_map.Get().insert(std::make_pair(webview(), this));
[email protected]60051ec2012-06-08 22:40:57698 webview()->setDeviceScaleFactor(device_scale_factor_);
[email protected]34c61bd52011-05-02 19:38:33699 webkit_preferences_.Apply(webview());
700 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35701 if (!frame_name.empty())
702 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33703 webview()->settings()->setMinimumTimerInterval(
704 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
705 webkit_glue::kForegroundTabTimerInterval);
706
707 OnSetRendererPrefs(renderer_prefs);
708
[email protected]676126f72011-01-15 00:03:51709 host_window_ = parent_hwnd;
710
[email protected]4fb0f202012-05-30 22:44:53711#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02712 if (!media_stream_dispatcher_)
713 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32714#endif
[email protected]735873d2012-01-25 23:31:02715
[email protected]8f6a3b852011-07-19 16:48:56716 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32717#if defined(OS_MACOSX)
718 new TextInputClientObserver(this);
719#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56720
[email protected]2d7b82c2012-06-01 05:57:50721#if defined(OS_ANDROID)
722 media_player_manager_.reset(
723 new webkit_media::WebMediaPlayerManagerAndroid());
724#endif
725
[email protected]217690d2012-01-27 07:33:11726 // The next group of objects all implement RenderViewObserver, so are deleted
727 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41728 devtools_agent_ = new DevToolsAgent(this);
[email protected]89054502012-06-03 10:29:24729 mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
[email protected]0fc7dea72012-02-09 03:47:40730 intents_host_ = new WebIntentsHost(this);
[email protected]063afcb2011-09-29 07:54:32731
[email protected]2a84f9d2012-06-05 21:50:43732 // Create renderer_accessibility_ if needed.
733 OnSetAccessibilityMode(accessibility_mode);
734
[email protected]1784b2f2011-11-24 10:53:48735 new IdleUserDetector(this);
736
[email protected]766a7082012-02-03 23:39:15737 if (command_line.HasSwitch(switches::kDomAutomationController))
[email protected]e9ff79c2012-10-19 21:31:26738 enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION;
[email protected]766a7082012-02-03 23:39:15739
[email protected]5b52cd2f712012-03-28 02:12:48740 ProcessViewLayoutFlags(command_line);
[email protected]7ddea9802012-02-22 23:08:05741
[email protected]e9ff79c2012-10-19 21:31:26742 GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44743
744 // If we have an opener_id but we weren't created by a renderer, then
745 // it's the browser asking us to set our opener to another RenderView.
[email protected]14392a52012-05-02 20:28:44746 if (opener_id != MSG_ROUTING_NONE && !is_renderer_created) {
[email protected]f546640b2012-05-15 00:03:49747 RenderViewImpl* opener_view = FromRoutingID(opener_id);
748 if (opener_view)
749 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
[email protected]14392a52012-05-02 20:28:44750 }
751
752 // If we are initially swapped out, navigate to kSwappedOutURL.
753 // This ensures we are in a unique origin that others cannot script.
754 if (is_swapped_out_)
[email protected]0720b532012-08-28 19:23:37755 NavigateToSwappedOutURL(webview()->mainFrame());
initial.commit09911bf2008-07-26 23:55:29756}
757
[email protected]310ebd6302011-10-10 19:06:28758RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03759 history_page_ids_.clear();
760
[email protected]0aa55312008-10-17 21:53:08761 if (decrement_shared_popup_at_destruction_)
762 shared_popup_counter_->data--;
763
[email protected]a1128322009-10-06 18:38:46764 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47765 while (!file_chooser_completions_.empty()) {
766 if (file_chooser_completions_.front()->completion) {
767 file_chooser_completions_.front()->completion->didChooseFile(
768 WebVector<WebString>());
769 }
770 file_chooser_completions_.pop_front();
771 }
[email protected]a1128322009-10-06 18:38:46772
[email protected]83dde542009-09-11 20:59:55773#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11774 // Destroy all fake plugin window handles on the browser side.
775 while (!fake_plugin_window_handles_.empty()) {
776 // Make sure no NULL plugin window handles were inserted into this list.
777 DCHECK(*fake_plugin_window_handles_.begin());
778 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
779 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
780 }
[email protected]83dde542009-09-11 20:59:55781#endif
[email protected]98324892009-09-09 21:16:05782
[email protected]60c42a8c72009-10-09 04:08:59783#ifndef NDEBUG
784 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49785 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59786 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
787 DCHECK_NE(this, it->second) << "Failed to call Close?";
788#endif
[email protected]676126f72011-01-15 00:03:51789
[email protected]310ebd6302011-10-10 19:06:28790 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51791 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59792}
793
794/*static*/
[email protected]310ebd6302011-10-10 19:06:28795RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31796 ViewMap* views = g_view_map.Pointer();
797 ViewMap::iterator it = views->find(webview);
798 return it == views->end() ? NULL : it->second;
799}
800
801/*static*/
[email protected]e9ff79c2012-10-19 21:31:26802RenderView* RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28803 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31804}
805
806/*static*/
[email protected]e9ff79c2012-10-19 21:31:26807void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49808 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59809 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
810 if (!visitor->Visit(it->second))
811 return;
812 }
813}
814
815/*static*/
[email protected]310ebd6302011-10-10 19:06:28816RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15817 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08818 int32 opener_id,
[email protected]e9ff79c2012-10-19 21:31:26819 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08820 const WebPreferences& webkit_prefs,
821 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34822 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56823 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26824 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46825 const string16& frame_name,
[email protected]14392a52012-05-02 20:28:44826 bool is_renderer_created,
827 bool swapped_out,
[email protected]6fd35b72012-03-01 19:46:41828 int32 next_page_id,
[email protected]842f10652012-06-06 01:54:04829 const WebKit::WebScreenInfo& screen_info,
[email protected]e9ff79c2012-10-19 21:31:26830 old::GuestToEmbedderChannel* guest_to_embedder_channel,
[email protected]3e3c4522012-04-13 21:16:29831 AccessibilityMode accessibility_mode) {
initial.commit09911bf2008-07-26 23:55:29832 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28833 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51834 parent_hwnd,
835 opener_id,
836 renderer_prefs,
837 webkit_prefs,
838 counter,
839 routing_id,
[email protected]9f4f3322012-01-18 22:29:56840 surface_id,
[email protected]676126f72011-01-15 00:03:51841 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46842 frame_name,
[email protected]14392a52012-05-02 20:28:44843 is_renderer_created,
844 swapped_out,
[email protected]6fd35b72012-03-01 19:46:41845 next_page_id,
[email protected]842f10652012-06-06 01:54:04846 screen_info,
[email protected]468e4902012-05-23 01:49:31847 guest_to_embedder_channel,
[email protected]3e3c4522012-04-13 21:16:29848 accessibility_mode);
initial.commit09911bf2008-07-26 23:55:29849}
850
[email protected]310ebd6302011-10-10 19:06:28851void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51852 observers_.AddObserver(observer);
853}
854
[email protected]310ebd6302011-10-10 19:06:28855void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
856 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51857 observers_.RemoveObserver(observer);
858}
859
[email protected]310ebd6302011-10-10 19:06:28860WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26861 return static_cast<WebKit::WebView*>(webwidget());
862}
863
[email protected]310ebd6302011-10-10 19:06:28864void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40865 if (!enabled) {
866 load_progress_tracker_.reset(NULL);
867 return;
868 }
869 if (load_progress_tracker_ == NULL)
870 load_progress_tracker_.reset(new LoadProgressTracker(this));
871}
872
[email protected]e9ff79c2012-10-19 21:31:26873old::GuestToEmbedderChannel* RenderViewImpl::GetGuestToEmbedderChannel() const {
[email protected]7900bfdb2012-05-24 19:31:24874 return guest_to_embedder_channel_;
875}
876
877void RenderViewImpl::SetGuestToEmbedderChannel(
[email protected]e9ff79c2012-10-19 21:31:26878 old::GuestToEmbedderChannel* channel) {
[email protected]7900bfdb2012-05-24 19:31:24879 guest_to_embedder_channel_ = channel;
880}
881
[email protected]310ebd6302011-10-10 19:06:28882void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51883 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29884}
885
[email protected]310ebd6302011-10-10 19:06:28886void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26887 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30888 // If the renderer is visible, set initial visibility and focus state.
889 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34890#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30891 delegate->SetContainerVisibility(true);
892 if (webview() && webview()->isActive())
893 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34894#endif
[email protected]49232292010-09-03 19:07:30895 }
[email protected]784ea1ab2010-09-18 00:02:34896 // Plugins start assuming the content has focus (so that they work in
897 // environments where RenderView isn't hosting them), so we always have to
898 // set the initial state. See webplugin_delegate_impl.h for details.
899 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26900}
901
[email protected]310ebd6302011-10-10 19:06:28902void RenderViewImpl::UnregisterPluginDelegate(
903 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26904 plugin_delegates_.erase(delegate);
905}
[email protected]d8fd6fa2010-02-01 15:54:26906
[email protected]310ebd6302011-10-10 19:06:28907bool RenderViewImpl::GetPluginInfo(const GURL& url,
908 const GURL& page_url,
909 const std::string& mime_type,
910 webkit::WebPluginInfo* plugin_info,
911 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08912 bool found = false;
913 Send(new ViewHostMsg_GetPluginInfo(
914 routing_id_, url, page_url, mime_type, &found, plugin_info,
915 actual_mime_type));
916 return found;
917}
918
[email protected]7a1ec28a2012-03-28 21:10:24919void RenderViewImpl::TransferActiveWheelFlingAnimation(
920 const WebKit::WebActiveWheelFlingParameters& params) {
921 if (webview())
922 webview()->transferActiveWheelFlingAnimation(params);
923}
924
[email protected]8fe8f742012-06-14 00:36:08925bool RenderViewImpl::HasIMETextFocus() {
926 return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
927}
928
[email protected]310ebd6302011-10-10 19:06:28929bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27930 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27931 if (main_frame)
[email protected]e9ff79c2012-10-19 21:31:26932 GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26933
[email protected]676126f72011-01-15 00:03:51934 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
935 RenderViewObserver* observer;
936 while ((observer = it.GetNext()) != NULL)
937 if (observer->OnMessageReceived(message))
938 return true;
[email protected]b2abac72009-02-26 12:39:28939
[email protected]a95986a82010-12-24 06:19:28940 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40941 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28942 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29943 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
944 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56945 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29946 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
947 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
948 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
949 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
950 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15951 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29952 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
953 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
954 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]45a599062012-09-07 20:09:06955 IPC_MESSAGE_HANDLER(ViewMsg_ReplaceAll, OnReplaceAll)
956 IPC_MESSAGE_HANDLER(ViewMsg_Unselect, OnUnselect)
957 IPC_MESSAGE_HANDLER(ViewMsg_SetEditableSelectionOffsets,
958 OnSetEditableSelectionOffsets)
959 IPC_MESSAGE_HANDLER(ViewMsg_SetCompositionFromExistingText,
960 OnSetCompositionFromExistingText)
961 IPC_MESSAGE_HANDLER(ViewMsg_ExtendSelectionAndDelete,
962 OnExtendSelectionAndDelete)
[email protected]4fb60142011-08-09 02:22:08963 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29964 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15965 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29966 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49967 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
[email protected]630e26b2008-10-14 22:55:17968 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17969 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41970 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54971 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
972 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29973 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18974 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
975 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29976 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]f546640b2012-05-15 00:03:49977 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
[email protected]1810e132009-03-24 23:35:48978 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55979 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
980 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
981 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
982 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
983 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
984 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
985 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45986 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40987 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29988 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19989 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
990 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29991 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
992 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]38761452012-10-18 16:31:59993 IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone)
initial.commit09911bf2008-07-26 23:55:29994 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51995 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
996 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29997 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04998 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15999 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:291000 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1001 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:081002 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
1003 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:001004 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:161005 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:141006 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:251007 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1008 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:471009 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:341010 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:101011 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1012 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511013 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:561014 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]77829642012-05-15 14:47:171015 IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent,
1016 OnOrientationChangeEvent)
[email protected]81375e872012-01-11 21:40:361017 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:341018 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]7a17bac02012-03-07 21:58:121019 IPC_MESSAGE_HANDLER(ViewMsg_SetNavigationStartTime,
1020 OnSetNavigationStartTime)
[email protected]446705872009-09-10 07:22:481021 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:331022 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:331023 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
1024 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:241025 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:421026 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
1027 OnPpapiBrokerChannelCreated)
[email protected]d8415ad92012-08-23 14:40:501028 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult,
1029 OnPpapiBrokerPermissionResult)
[email protected]18d5be92011-07-25 18:00:191030 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1031 OnGetAllSavableResourceLinksForCurrentPage)
1032 IPC_MESSAGE_HANDLER(
1033 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1034 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]521b2482011-01-15 00:10:101035 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:511036 // TODO(viettrungluu): Move to a separate message filter.
[email protected]9e1ad4b2011-08-14 16:49:191037 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
1038 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:181039 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]7f3c7af2011-10-20 22:52:511040 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]2a84f9d2012-06-05 21:50:431041 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode)
[email protected]0720b532012-08-28 19:23:371042 IPC_MESSAGE_HANDLER(ViewMsg_UpdateFrameTree, OnUpdatedFrameTree)
[email protected]55750b32012-09-21 14:05:031043#if defined(OS_ANDROID)
1044 IPC_MESSAGE_HANDLER(ViewMsg_ActivateNearestFindResult,
1045 OnActivateNearestFindResult)
1046 IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects)
1047 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
1048 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewMsg_SynchronousFind, OnSynchronousFind)
[email protected]9b7d11e2012-10-08 19:24:141049 IPC_MESSAGE_HANDLER(ViewMsg_UndoScrollFocusedEditableNodeIntoView,
1050 OnUndoScrollFocusedEditableNodeIntoRect)
[email protected]55750b32012-09-21 14:05:031051#elif defined(OS_MACOSX)
1052 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
1053 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1054 OnPluginImeCompositionCompleted)
1055 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1056 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
1057 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
1058 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
1059#endif
[email protected]f9526d12012-10-18 01:55:031060 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB,
1061 OnReleaseDisambiguationPopupDIB)
[email protected]9e1ad4b2011-08-14 16:49:191062
initial.commit09911bf2008-07-26 23:55:291063 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281064 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291065 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401066
1067 if (!msg_is_ok) {
1068 // The message had a handler, but its deserialization failed.
1069 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:281070 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:401071 }
1072
[email protected]a95986a82010-12-24 06:19:281073 return handled;
initial.commit09911bf2008-07-26 23:55:291074}
1075
[email protected]310ebd6302011-10-10 19:06:281076void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]7900bfdb2012-05-24 19:31:241077 // If we don't have guest-to-embedder channel associated with this RenderView
1078 // but we need one, grab one now.
1079 if (!params.embedder_channel_name.empty() && !GetGuestToEmbedderChannel()) {
[email protected]e9ff79c2012-10-19 21:31:261080 old::GuestToEmbedderChannel* embedder_channel =
[email protected]7900bfdb2012-05-24 19:31:241081 RenderThreadImpl::current()->browser_plugin_channel_manager()->
1082 GetChannelByName(params.embedder_channel_name);
1083 DCHECK(embedder_channel);
1084 SetGuestToEmbedderChannel(embedder_channel);
1085 host_window_set_ = false;
1086 // TODO(fsamuel): This is test code. Need to find a better way to tell
1087 // a WebView to drop its context. This needs to change in
1088 // GuestToEmbedderChannel::OnContextLost.
1089 GetWebView()->loseCompositorContext(1);
1090 RenderThreadImpl::current()->browser_plugin_channel_manager()->
1091 ReportChannelToEmbedder(this,
1092 embedder_channel->embedder_channel_handle(),
1093 params.embedder_channel_name,
1094 params.embedder_container_id);
1095 }
[email protected]8bf1048012012-02-08 01:22:181096 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:291097 if (!webview())
1098 return;
1099
[email protected]440a0e52011-09-13 17:38:581100 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
1101
[email protected]007733c2011-11-17 00:34:071102 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:031103
1104 // If this is a stale back/forward (due to a recent navigation the browser
1105 // didn't know about), ignore it.
1106 if (IsBackForwardToStaleEntry(params, is_reload))
1107 return;
1108
[email protected]992db4c2011-05-12 15:37:151109 // Swap this renderer back in if necessary.
[email protected]961541a92012-06-01 21:15:281110 if (is_swapped_out_) {
1111 // We marked the view as hidden when swapping the view out, so be sure to
1112 // reset the visibility state before navigating to the new URL.
1113 webview()->setVisibilityState(visibilityState(), false);
[email protected]992db4c2011-05-12 15:37:151114 SetSwappedOut(false);
[email protected]961541a92012-06-01 21:15:281115 }
[email protected]992db4c2011-05-12 15:37:151116
[email protected]3cc72b12010-03-18 23:03:001117 history_list_offset_ = params.current_history_list_offset;
1118 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:031119 if (history_list_length_ >= 0)
1120 history_page_ids_.resize(history_list_length_, -1);
1121 if (params.pending_history_list_offset >= 0 &&
1122 params.pending_history_list_offset < history_list_length_)
1123 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:001124
[email protected]e9ff79c2012-10-19 21:31:261125 GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:291126
[email protected]26aa0482009-09-30 16:55:271127 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451128 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291129 // We cannot reload if we do not have any history state. This happens, for
1130 // example, when recovering from a crash. Our workaround here is a bit of
1131 // a hack since it means that reload after a crashed tab does not cause an
1132 // end-to-end cache validation.
1133 is_reload = false;
1134 }
1135
[email protected]007733c2011-11-17 00:34:071136 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
1137 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:501138
[email protected]04d3c6e2009-05-22 17:00:131139 // If we are reloading, then WebKit will use the history state of the current
1140 // page, so we should just ignore any given history state. Otherwise, if we
1141 // have history state, then we need to navigate to it, which corresponds to a
1142 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551143 if (is_reload) {
[email protected]7c16976c2012-08-04 02:38:231144 bool reload_original_url =
1145 (params.navigation_type ==
1146 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]ecbf10d2010-02-18 13:03:291147 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:021148 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]7c16976c2012-08-04 02:38:231149
1150 if (reload_original_url)
1151 main_frame->reloadWithOverrideURL(params.url, true);
1152 else
1153 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551154 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131155 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581156 DCHECK_NE(params.page_id, -1);
[email protected]f707573e62012-10-18 09:38:071157 WebHistoryItem item = webkit_glue::HistoryItemFromString(params.state);
1158 if (!item.isNull())
1159 main_frame->loadHistoryItem(item);
[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()) {
[email protected]9b7d11e2012-10-08 19:24:141480 if (IsEditableNode(node)) {
1481 webview()->saveScrollAndScaleState();
[email protected]333ec8d02011-09-16 18:59:191482 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b7d11e2012-10-08 19:24:141483 }
[email protected]9b66f34bf2010-10-27 20:45:511484 }
1485}
1486
[email protected]9b7d11e2012-10-08 19:24:141487#if defined(OS_ANDROID)
1488void RenderViewImpl::OnUndoScrollFocusedEditableNodeIntoRect() {
1489 const WebNode node = GetFocusedNode();
1490 if (!node.isNull() && IsEditableNode(node))
1491 webview()->restoreScrollAndScaleState();
1492}
1493#endif
1494
initial.commit09911bf2008-07-26 23:55:291495///////////////////////////////////////////////////////////////////////////////
1496
1497// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281498void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451499 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291500 DCHECK(ds);
1501
[email protected]726985e22009-06-18 21:09:281502 const WebURLRequest& request = ds->request();
1503 const WebURLRequest& original_request = ds->originalRequest();
1504 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291505
[email protected]007733c2011-11-17 00:34:071506 DocumentState* document_state = DocumentState::FromDataSource(ds);
1507 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291508
1509 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281510 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291511 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051512 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291513 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071514 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191515 params.socket_address.set_host(response.remoteIPAddress().utf8());
1516 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031517 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091518 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071519 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291520 // SSL state specified in the request takes precedence over the one in the
1521 // response.
1522 // So far this is only intended for error pages that are not expected to be
1523 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281524 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071525 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291526 } else {
[email protected]726985e22009-06-18 21:09:281527 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291528 }
1529
1530 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:311531 params.url = GetLoadingUrl(frame);
initial.commit09911bf2008-07-26 23:55:291532
[email protected]5f9b8712011-11-23 08:55:571533 if (frame->document().baseURL() != params.url)
1534 params.base_url = frame->document().baseURL();
1535
[email protected]726985e22009-06-18 21:09:281536 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241537 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041538 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291539
[email protected]007733c2011-11-17 00:34:071540 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351541 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071542 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291543
1544 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071545 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291546 if (password_form_data)
1547 params.password_form = *password_form_data;
1548
1549 params.gesture = navigation_gesture_;
1550 navigation_gesture_ = NavigationGestureUnknown;
1551
[email protected]0f38dc4552011-02-25 11:24:001552 // Make navigation state a part of the FrameNavigate message so that commited
1553 // entry had it at all times.
1554 const WebHistoryItem& item = frame->currentHistoryItem();
1555 if (!item.isNull()) {
1556 params.content_state = webkit_glue::HistoryItemToString(item);
1557 } else {
1558 params.content_state =
1559 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1560 }
1561
[email protected]dd7daa82009-08-10 05:46:451562 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291563 // Top-level navigation.
1564
[email protected]d00a7972012-08-07 06:09:581565 // Reset the zoom limits in case a plugin had changed them previously. This
1566 // will also call us back which will cause us to send a message to
1567 // update WebContentsImpl.
1568 webview()->zoomLimitsChanged(
[email protected]e9ff79c2012-10-19 21:31:261569 WebView::zoomFactorToZoomLevel(kMinimumZoomFactor),
1570 WebView::zoomFactorToZoomLevel(kMaximumZoomFactor));
[email protected]d00a7972012-08-07 06:09:581571
[email protected]b75b8292010-10-01 07:28:251572 // Set zoom level, but don't do it for full-page plugin since they don't use
1573 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011574 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541575 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251576 if (webview()->mainFrame()->document().isPluginDocument()) {
1577 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251578 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251579 } else {
1580 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251581 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251582 }
1583
[email protected]f85f0702010-01-30 09:31:011584 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511585 // This zoom level was merely recorded transiently for this load. We can
1586 // erase it now. If at some point we reload this page, the browser will
1587 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011588 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511589 }
1590
initial.commit09911bf2008-07-26 23:55:291591 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551592 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291593
[email protected]daa8c58e2009-06-15 17:21:101594 params.transition = navigation_state->transition_type();
[email protected]e9ff79c2012-10-19 21:31:261595 if (!PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291596 // If the main frame does a load, it should not be reported as a subframe
1597 // navigation. This can occur in the following case:
1598 // 1. You're on a site with frames.
1599 // 2. You do a subframe navigation. This is stored with transition type
1600 // MANUAL_SUBFRAME.
1601 // 3. You navigate to some non-frame site, say, google.com.
1602 // 4. You navigate back to the page from step 2. Since it was initially
1603 // MANUAL_SUBFRAME, it will be that same transition type here.
1604 // We don't want that, because any navigation that changes the toplevel
1605 // frame should be tracked as a toplevel navigation (this allows us to
1606 // update the URL bar, etc).
[email protected]e9ff79c2012-10-19 21:31:261607 params.transition = PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291608 }
1609
initial.commit09911bf2008-07-26 23:55:291610 // If we have a valid consumed client redirect source,
1611 // the page contained a client redirect (meta refresh, document.loc...),
1612 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151613 if (completed_client_redirect_src_.url.is_valid()) {
1614 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291615 params.referrer = completed_client_redirect_src_;
[email protected]e9ff79c2012-10-19 21:31:261616 params.transition = static_cast<PageTransition>(
1617 params.transition | PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291618 } else {
1619 // Bug 654101: the referrer will be empty on https->http transitions. It
1620 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151621 params.referrer = Referrer(GURL(
1622 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:591623 GetReferrerPolicyFromRequest(frame, original_request));
initial.commit09911bf2008-07-26 23:55:291624 }
1625
[email protected]726985e22009-06-18 21:09:281626 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051627 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291628 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051629 params.post_id = ExtractPostId(item);
1630 }
initial.commit09911bf2008-07-26 23:55:291631
[email protected]bf70edce2012-06-20 22:32:221632 // Send the user agent override back.
1633 params.is_overriding_user_agent =
1634 document_state->is_overriding_user_agent();
1635
[email protected]7c16976c2012-08-04 02:38:231636 // Track the URL of the original request.
1637 params.original_request_url = original_request.url();
1638
[email protected]c2a797d2009-09-21 16:46:321639 // Save some histogram data so we can compute the average memory used per
1640 // page load of the glyphs.
1641 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1642 webkit_glue::GetGlyphPageCount());
1643
[email protected]15cf526b2010-02-12 06:33:491644 // This message needs to be sent before any of allowScripts(),
1645 // allowImages(), allowPlugins() is called for the new page, so that when
1646 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1647 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291648 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1649 } else {
1650 // Subframe navigation: the type depends on whether this navigation
1651 // generated a new session history entry. When they do generate a session
1652 // history entry, it means the user initiated the navigation and we should
1653 // mark it as such. This test checks if this is the first time UpdateURL
1654 // has been called since WillNavigateToURL was called to initiate the load.
1655 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]e9ff79c2012-10-19 21:31:261656 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291657 else
[email protected]e9ff79c2012-10-19 21:31:261658 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291659
initial.commit09911bf2008-07-26 23:55:291660 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1661 }
1662
1663 last_page_id_sent_to_browser_ =
1664 std::max(last_page_id_sent_to_browser_, page_id_);
1665
1666 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101667 // we don't want the transition type to persist. Just clear it.
[email protected]e9ff79c2012-10-19 21:31:261668 navigation_state->set_transition_type(PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291669}
1670
1671// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281672void RenderViewImpl::UpdateTitle(WebFrame* frame,
1673 const string16& title,
1674 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461675 // Ignore all but top level navigations.
1676 if (frame->parent())
1677 return;
1678
[email protected]e9ff79c2012-10-19 21:31:261679 string16 shortened_title = title.substr(0, kMaxTitleChars);
[email protected]a49e10b2011-08-01 23:57:461680 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1681 title_direction));
initial.commit09911bf2008-07-26 23:55:291682}
1683
[email protected]310ebd6302011-10-10 19:06:281684void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1685 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291686 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271687 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291688 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301689 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291690 last_encoding_name_ = encoding_name;
1691
[email protected]e38f40152008-09-12 23:08:301692 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291693 }
1694}
1695
[email protected]e15f680732010-11-23 22:30:201696// Sends the last committed session history state to the browser so it will be
1697// saved before we navigate to a new page. This must be called *before* the
1698// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281699void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291700 // If we have a valid page ID at this point, then it corresponds to the page
1701 // we are navigating away from. Otherwise, this is the first navigation, so
1702 // there is no past session history to record.
1703 if (page_id_ == -1)
1704 return;
1705
[email protected]ca948a22009-06-25 19:36:171706 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271707 webview()->mainFrame()->previousHistoryItem();
[email protected]6459800a2012-03-27 23:57:051708 SendUpdateState(item);
1709}
1710
1711void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
[email protected]ca948a22009-06-25 19:36:171712 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291713 return;
[email protected]ca948a22009-06-25 19:36:171714
[email protected]e9ff79c2012-10-19 21:31:261715 // Don't send state updates for kSwappedOutURL.
1716 if (item.urlString() == WebString::fromUTF8(kSwappedOutURL))
[email protected]6459800a2012-03-27 23:57:051717 return;
1718
[email protected]ca948a22009-06-25 19:36:171719 Send(new ViewHostMsg_UpdateState(
1720 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291721}
1722
[email protected]310ebd6302011-10-10 19:06:281723void RenderViewImpl::OpenURL(WebFrame* frame,
1724 const GURL& url,
[email protected]445e1042011-12-03 21:03:151725 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281726 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171727 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581728 routing_id_,
1729 url,
1730 referrer,
1731 NavigationPolicyToDisposition(policy),
1732 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171733}
1734
[email protected]79dbc662009-09-04 05:42:511735// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291736
[email protected]310ebd6302011-10-10 19:06:281737void RenderViewImpl::LoadNavigationErrorPage(
1738 WebFrame* frame,
1739 const WebURLRequest& failed_request,
1740 const WebURLError& error,
1741 const std::string& html,
1742 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581743 std::string alt_html;
1744 const std::string* error_html;
1745
1746 if (!html.empty()) {
1747 error_html = &html;
1748 } else {
[email protected]e9ff79c2012-10-19 21:31:261749 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]d7b175e2011-10-11 15:31:581750 failed_request, error, &alt_html, NULL);
1751 error_html = &alt_html;
1752 }
1753
1754 frame->loadHTMLString(*error_html,
[email protected]e9ff79c2012-10-19 21:31:261755 GURL(kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251756 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551757 replace);
initial.commit09911bf2008-07-26 23:55:291758}
1759
[email protected]e9ff79c2012-10-19 21:31:261760bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281761 const string16& message,
1762 const string16& default_value,
1763 const GURL& frame_url,
1764 string16* result) {
initial.commit09911bf2008-07-26 23:55:291765 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411766 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291767 if (!result)
1768 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291769
[email protected]12636df2009-09-28 22:32:211770 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1771 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291772 return success;
1773}
1774
[email protected]310ebd6302011-10-10 19:06:281775bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571776 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1777 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1778 // it is particularly important that we do not call willEnterModalLoop as
1779 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441780 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1781 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571782
1783 message->EnableMessagePumping(); // Runs a nested message loop.
1784 return Send(message);
1785}
1786
[email protected]48c9cf2d2009-09-16 16:47:521787// WebKit::WebViewClient ------------------------------------------------------
1788
[email protected]916dfb62012-03-05 03:39:371789WebView* RenderViewImpl::createView(
1790 WebFrame* creator,
1791 const WebURLRequest& request,
1792 const WebWindowFeatures& features,
1793 const WebString& frame_name,
1794 WebNavigationPolicy policy) {
[email protected]48c9cf2d2009-09-16 16:47:521795 // Check to make sure we aren't overloading on popups.
1796 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1797 return NULL;
1798
[email protected]8ab04652010-06-12 02:47:261799 ViewHostMsg_CreateWindow_Params params;
1800 params.opener_id = routing_id_;
1801 params.user_gesture = creator->isProcessingUserGesture();
1802 params.window_container_type = WindowFeaturesToContainerType(features);
1803 params.session_storage_namespace_id = session_storage_namespace_id_;
1804 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111805 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411806 params.opener_url = creator->document().url();
1807 params.opener_security_origin =
1808 creator->document().securityOrigin().toString().utf8();
[email protected]f92ce2b2012-03-06 18:02:591809 params.opener_suppressed = creator->willSuppressOpenerInNewFrame();
1810 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]41e65502011-01-21 09:29:111811 if (!request.isNull())
1812 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261813
[email protected]48c9cf2d2009-09-16 16:47:521814 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561815 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341816 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521817
[email protected]7c962ee32012-08-28 21:12:501818 creator->consumeUserGesture();
[email protected]380244092011-10-07 17:26:271819 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261820 new ViewHostMsg_CreateWindow(params,
1821 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561822 &surface_id,
[email protected]8ab04652010-06-12 02:47:261823 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211824 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521825 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521826
[email protected]8cca3da2012-03-20 08:26:341827 // TODO(fsamuel): The host renderer needs to be able to control whether
1828 // the guest renderer is allowed to do this or not. This current
1829 // behavior is not well defined.
[email protected]310ebd6302011-10-10 19:06:281830 RenderViewImpl* view = RenderViewImpl::Create(
1831 0,
1832 routing_id_,
1833 renderer_preferences_,
1834 webkit_preferences_,
1835 shared_popup_counter_,
1836 routing_id,
[email protected]9f4f3322012-01-18 22:29:561837 surface_id,
[email protected]310ebd6302011-10-10 19:06:281838 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461839 frame_name,
[email protected]14392a52012-05-02 20:28:441840 true,
1841 false,
[email protected]6fd35b72012-03-01 19:46:411842 1,
[email protected]842f10652012-06-06 01:54:041843 screen_info_,
[email protected]468e4902012-05-23 01:49:311844 guest_to_embedder_channel_,
[email protected]3e3c4522012-04-13 21:16:291845 accessibility_mode_);
[email protected]8ab04652010-06-12 02:47:261846 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521847
[email protected]007a848b2009-10-26 15:55:461848 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:591849 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:461850
[email protected]48c9cf2d2009-09-16 16:47:521851 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411852 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521853 if (!creator_url.is_valid() || !creator_url.IsStandard())
1854 creator_url = GURL();
1855 view->creator_url_ = creator_url;
1856
1857 // Copy over the alternate error page URL so we can have alt error pages in
1858 // the new render view (we don't need the browser to send the URL back down).
1859 view->alternate_error_page_url_ = alternate_error_page_url_;
1860
1861 return view->webview();
1862}
1863
[email protected]310ebd6302011-10-10 19:06:281864WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:411865 RenderWidget* widget =
[email protected]842f10652012-06-06 01:54:041866 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]48c9cf2d2009-09-16 16:47:521867 return widget->webwidget();
1868}
1869
[email protected]310ebd6302011-10-10 19:06:281870WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081871 const WebPopupMenuInfo& popup_menu_info,
1872 WebExternalPopupMenuClient* popup_menu_client) {
[email protected]8de2f882012-05-30 00:32:271873 // An IPC message is sent to the browser to build and display the actual
1874 // popup. The user could have time to click a different select by the time
1875 // the popup is shown. In that case external_popup_menu_ is non NULL.
1876 // By returning NULL in that case, we instruct WebKit to cancel that new
1877 // popup. So from the user perspective, only the first one will show, and
1878 // will have to close the first one before another one can be shown.
1879 if (external_popup_menu_.get())
1880 return NULL;
[email protected]caf706f2010-10-26 17:54:081881 external_popup_menu_.reset(
1882 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1883 return external_popup_menu_.get();
1884}
1885
[email protected]310ebd6302011-10-10 19:06:281886RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521887 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531888 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421889 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411890 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531891 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]bee6eb72012-07-26 03:47:321892 routing_id_, plugin, active_url, screen_info_);
[email protected]79c7bed2010-09-14 22:28:391893 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561894 return widget;
[email protected]79c7bed2010-09-14 22:28:391895}
1896
[email protected]310ebd6302011-10-10 19:06:281897WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1898 unsigned quota) {
[email protected]b928936b2012-04-13 01:16:161899 CHECK(session_storage_namespace_id_ !=
1900 dom_storage::kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:101901 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341902}
1903
[email protected]1842fe22012-08-13 23:24:351904WebKit::WebCompositorOutputSurface* RenderViewImpl::createOutputSurface() {
[email protected]1842fe22012-08-13 23:24:351905 // Explicitly disable antialiasing for the compositor. As of the time of
1906 // this writing, the only platform that supported antialiasing for the
1907 // compositor was Mac OS X, because the on-screen OpenGL context creation
1908 // code paths on Windows and Linux didn't yet have multisampling support.
1909 // Mac OS X essentially always behaves as though it's rendering offscreen.
1910 // Multisampling has a heavy cost especially on devices with relatively low
1911 // fill rate like most notebooks, and the Mac implementation would need to
1912 // be optimized to resolve directly into the IOSurface shared between the
1913 // GPU and browser processes. For these reasons and to avoid platform
1914 // disparities we explicitly disable antialiasing.
1915 WebKit::WebGraphicsContext3D::Attributes attributes;
1916 attributes.antialias = false;
1917 attributes.shareResources = true;
[email protected]362e6d602012-10-17 16:55:061918 attributes.noAutomaticFlushes = true;
[email protected]1842fe22012-08-13 23:24:351919 WebGraphicsContext3D* context = CreateGraphicsContext3D(attributes);
1920 if (!context)
[email protected]7e8b4d12012-01-20 23:39:511921 return NULL;
[email protected]468e4902012-05-23 01:49:311922
[email protected]7d4481d12012-09-24 21:26:471923 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1924 if (command_line.HasSwitch(switches::kEnableSoftwareCompositingGLAdapter)) {
1925 // In the absence of a software-based delegating renderer, use this
1926 // stopgap adapter class to present the software renderer output using a
1927 // 3d context.
1928 return new CompositorOutputSurface(routing_id(), NULL,
1929 new CompositorSoftwareOutputDeviceGLAdapter(context));
1930 } else
1931 return new CompositorOutputSurface(routing_id(), context, NULL);
[email protected]7e8b4d12012-01-20 23:39:511932}
1933
[email protected]310ebd6302011-10-10 19:06:281934void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521935 const WebConsoleMessage& message, const WebString& source_name,
1936 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081937 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511938 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081939 case WebConsoleMessage::LevelTip:
1940 log_severity = logging::LOG_VERBOSE;
1941 break;
1942 case WebConsoleMessage::LevelLog:
1943 log_severity = logging::LOG_INFO;
1944 break;
1945 case WebConsoleMessage::LevelWarning:
1946 log_severity = logging::LOG_WARNING;
1947 break;
1948 case WebConsoleMessage::LevelError:
1949 log_severity = logging::LOG_ERROR;
1950 break;
1951 default:
1952 NOTREACHED();
1953 }
1954
[email protected]48c9cf2d2009-09-16 16:47:521955 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081956 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311957 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521958 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311959 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521960}
1961
[email protected]310ebd6302011-10-10 19:06:281962void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]b0553c7e2012-09-19 21:36:111963 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
1964 PrintPage(frame, handling_input_event_));
[email protected]48c9cf2d2009-09-16 16:47:521965}
1966
[email protected]310ebd6302011-10-10 19:06:281967WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511968 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021969}
1970
[email protected]310ebd6302011-10-10 19:06:281971bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121972 const WebString& path,
1973 WebFileChooserCompletion* chooser_completion) {
1974 int id = enumeration_completion_id_++;
1975 enumeration_completions_[id] = chooser_completion;
1976 return Send(new ViewHostMsg_EnumerateDirectory(
1977 routing_id_,
1978 id,
1979 webkit_glue::WebStringToFilePath(path)));
1980}
1981
[email protected]4b1146bc2012-07-10 18:46:031982void RenderViewImpl::initializeHelperPluginWebFrame(
1983 WebKit::WebHelperPlugin* plugin) {
1984 plugin->initializeFrame(this);
1985}
1986
[email protected]310ebd6302011-10-10 19:06:281987void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521988 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:141989 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:521990 return;
1991 }
1992
1993 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521994
1995 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311996
1997 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521998}
1999
[email protected]310ebd6302011-10-10 19:06:282000void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:522001 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:142002 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:522003 return;
2004 }
2005
2006 is_loading_ = false;
2007
[email protected]0720b532012-08-28 19:23:372008 if (pending_frame_tree_update_) {
2009 pending_frame_tree_update_ = false;
2010 SendUpdatedFrameTree(NULL);
2011 }
2012
[email protected]48c9cf2d2009-09-16 16:47:522013 // NOTE: For now we're doing the safest thing, and sending out notification
2014 // when done loading. This currently isn't an issue as the favicon is only
2015 // displayed when done loading. Ideally we would send notification when
2016 // finished parsing the head, but webkit doesn't support that yet.
2017 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:522018 Send(new ViewHostMsg_DidStopLoading(routing_id_));
2019
[email protected]90109412010-12-15 17:14:242020 if (load_progress_tracker_ != NULL)
2021 load_progress_tracker_->DidStopLoading();
2022
[email protected]93b9d692011-04-13 00:44:312023 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:522024}
2025
[email protected]310ebd6302011-10-10 19:06:282026void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
2027 double load_progress) {
[email protected]90109412010-12-15 17:14:242028 if (load_progress_tracker_ != NULL)
2029 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
2030}
2031
[email protected]310ebd6302011-10-10 19:06:282032bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:062033#if defined(OS_MACOSX)
2034 return true;
2035#else
2036 return false;
2037#endif
2038}
2039
[email protected]310ebd6302011-10-10 19:06:282040bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:032041#if defined(OS_WIN)
2042 return true;
2043#else
2044 return false;
2045#endif
2046}
2047
[email protected]310ebd6302011-10-10 19:06:282048void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:082049 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:032050 return;
[email protected]4fb60142011-08-09 02:22:082051 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:012052
[email protected]fca52022012-04-03 17:00:502053 if (is_empty_selection)
2054 selection_text_.clear();
2055
[email protected]b781ff282011-08-20 06:19:362056 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:032057}
2058
[email protected]310ebd6302011-10-10 19:06:282059void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:122060 const std::string& name = UTF16ToUTF8(command_name);
2061 if (StartsWithASCII(name, "Move", true) ||
2062 StartsWithASCII(name, "Insert", true) ||
2063 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:032064 return;
[email protected]f1a29a02011-10-06 23:08:442065 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:032066}
2067
[email protected]310ebd6302011-10-10 19:06:282068bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:102069 if (edit_commands_.empty())
2070 return false;
2071
[email protected]26aa0482009-09-30 16:55:272072 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102073 if (!frame)
2074 return false;
2075
2076 EditCommands::iterator it = edit_commands_.begin();
2077 EditCommands::iterator end = edit_commands_.end();
2078
[email protected]507b33ea2009-09-29 03:56:512079 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102080 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332081 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2082 // key (but it's the exception). Once one edit command is not executed, it
2083 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102084 if (!frame->executeCommand(WebString::fromUTF8(it->name),
2085 WebString::fromUTF8(it->value)))
2086 break;
[email protected]507b33ea2009-09-29 03:56:512087 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102088 }
2089
[email protected]507b33ea2009-09-29 03:56:512090 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102091}
2092
[email protected]3306f262012-09-21 19:20:422093void RenderViewImpl::didHandleGestureEvent(const WebGestureEvent& event,
2094 bool event_swallowed) {
2095#if defined(OS_ANDROID)
2096 if (event.type == WebInputEvent::GestureTap ||
2097 event.type == WebInputEvent::GestureLongPress) {
2098 UpdateTextInputState(SHOW_IME_IF_NEEDED);
2099 }
2100#endif
2101}
2102
[email protected]da8543762012-03-20 08:52:202103WebKit::WebColorChooser* RenderViewImpl::createColorChooser(
2104 WebKit::WebColorChooserClient* client,
2105 const WebKit::WebColor& initial_color) {
2106 RendererWebColorChooserImpl* color_chooser =
2107 new RendererWebColorChooserImpl(this, client);
2108 color_chooser->Open(static_cast<SkColor>(initial_color));
2109 return color_chooser;
2110}
2111
[email protected]310ebd6302011-10-10 19:06:282112bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:352113 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472114 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352115 // Do not open the file dialog in a hidden RenderView.
2116 if (is_hidden())
2117 return false;
[email protected]e9ff79c2012-10-19 21:31:262118 FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262119 if (params.directory)
[email protected]e9ff79c2012-10-19 21:31:262120 ipc_params.mode = FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:262121 else if (params.multiSelect)
[email protected]e9ff79c2012-10-19 21:31:262122 ipc_params.mode = FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:502123 else if (params.saveAs)
[email protected]e9ff79c2012-10-19 21:31:262124 ipc_params.mode = FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:262125 else
[email protected]e9ff79c2012-10-19 21:31:262126 ipc_params.mode = FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:472127 ipc_params.title = params.title;
2128 ipc_params.default_file_name =
2129 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]f9a4c41a2012-05-30 00:05:322130 ipc_params.accept_types.reserve(params.acceptTypes.size());
2131 for (size_t i = 0; i < params.acceptTypes.size(); ++i)
2132 ipc_params.accept_types.push_back(params.acceptTypes[i]);
[email protected]cdaf8d02010-03-30 19:52:472133
2134 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462135}
2136
[email protected]269f86d2011-12-07 02:43:472137void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
2138 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262139 RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:412140 message,
2141 string16(),
[email protected]b6cb3a842011-06-24 18:28:412142 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522143 NULL);
2144}
2145
[email protected]269f86d2011-12-07 02:43:472146bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
2147 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262148 return RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:412149 message,
2150 string16(),
[email protected]b6cb3a842011-06-24 18:28:412151 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522152 NULL);
2153}
2154
[email protected]269f86d2011-12-07 02:43:472155bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
2156 const WebString& message,
2157 const WebString& default_value,
2158 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:412159 string16 result;
[email protected]e9ff79c2012-10-19 21:31:262160 bool ok = RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:412161 message,
2162 default_value,
[email protected]b6cb3a842011-06-24 18:28:412163 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522164 &result);
2165 if (ok)
[email protected]4f5ce842011-05-27 19:34:412166 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:522167 return ok;
2168}
2169
[email protected]310ebd6302011-10-10 19:06:282170bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:522171 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:152172 // If we are swapping out, we have already run the beforeunload handler.
2173 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
2174 // at all, to avoid running it twice.
2175 if (is_swapped_out_)
2176 return true;
2177
[email protected]3b3301f62012-02-29 04:32:322178 bool is_reload = false;
2179 WebDataSource* ds = frame->provisionalDataSource();
2180 if (ds)
2181 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
2182
[email protected]48c9cf2d2009-09-16 16:47:522183 bool success = false;
2184 // This is an ignored return value, but is included so we can accept the same
2185 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:412186 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:212187 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:322188 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:412189 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522190 return success;
2191}
2192
[email protected]310ebd6302011-10-10 19:06:282193void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:442194 WebFrame* frame, const WebContextMenuData& data) {
[email protected]8f635f82012-06-22 22:02:442195 // TODO(fsamuel): In the future, we might want the embedder to be able to
2196 // decide whether the guest can show a context menu or not. See
2197 // http://www.crbug.com/134207
2198 if (GetGuestToEmbedderChannel())
2199 return;
2200
[email protected]e9ff79c2012-10-19 21:31:262201 ContextMenuParams params(data);
[email protected]7fcd9b72011-07-27 16:52:372202
[email protected]329266d2012-09-27 06:20:572203 // Plugins, e.g. PDF, don't currently update the render view when their
2204 // selected text changes, but the context menu params do contain the updated
2205 // selection. If that's the case, update the render view's state just prior
2206 // to showing the context menu.
2207 // TODO(asvitkine): http://crbug.com/152432
2208 if (params.selection_text != selection_text_) {
2209 selection_text_ = params.selection_text;
2210 // TODO(asvitkine): Text offset and range is not available in this case.
2211 selection_text_offset_ = 0;
2212 selection_range_ = ui::Range(0, selection_text_.length());
2213 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2214 selection_text_,
2215 selection_text_offset_,
2216 selection_range_));
2217 }
2218
[email protected]7fcd9b72011-07-27 16:52:372219 // frame is NULL if invoked by BlockedPlugin.
2220 if (frame)
2221 params.frame_id = frame->identifier();
2222
[email protected]e9ff79c2012-10-19 21:31:262223 // Serializing a GURL longer than kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:272224 // it. We replace it with an empty GURL so the appropriate items are disabled
2225 // in the context menu.
2226 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2227 // data encoded images. We should have a way to save them.
[email protected]e9ff79c2012-10-19 21:31:262228 if (params.src_url.spec().size() > kMaxURLChars)
[email protected]216932c2010-08-26 21:44:272229 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102230 context_menu_node_ = data.node;
[email protected]44daa3b2012-09-27 19:26:412231
2232#if defined(OS_ANDROID)
2233 gfx::Rect start_rect;
2234 gfx::Rect end_rect;
2235 GetSelectionBounds(&start_rect, &end_rect);
2236 gfx::Point start_point(start_rect.x(),
2237 start_rect.bottom());
2238 gfx::Point end_point(end_rect.right(),
2239 end_rect.bottom());
2240 params.selection_start = GetScrollOffset().Add(start_point);
2241 params.selection_end = GetScrollOffset().Add(end_point);
2242#endif
2243
[email protected]c27324b2009-11-19 22:44:292244 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442245}
2246
[email protected]310ebd6302011-10-10 19:06:282247void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:522248}
2249
[email protected]310ebd6302011-10-10 19:06:282250void RenderViewImpl::UpdateTargetURL(const GURL& url,
2251 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582252 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522253 if (latest_url == target_url_)
2254 return;
[email protected]163f8242009-10-30 20:19:552255
[email protected]48c9cf2d2009-09-16 16:47:522256 // Tell the browser to display a destination link.
2257 if (target_url_status_ == TARGET_INFLIGHT ||
2258 target_url_status_ == TARGET_PENDING) {
2259 // If we have a request in-flight, save the URL to be sent when we
2260 // receive an ACK to the in-flight request. We can happily overwrite
2261 // any existing pending sends.
2262 pending_target_url_ = latest_url;
2263 target_url_status_ = TARGET_PENDING;
2264 } else {
[email protected]e9ff79c2012-10-19 21:31:262265 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:412266 // see |ParamTraits<GURL>|.
[email protected]e9ff79c2012-10-19 21:31:262267 if (latest_url.possibly_invalid_spec().size() > kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:412268 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:522269 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2270 target_url_ = latest_url;
2271 target_url_status_ = TARGET_INFLIGHT;
2272 }
2273}
2274
[email protected]310ebd6302011-10-10 19:06:282275void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:312276 int delay;
2277 if (send_content_state_immediately_)
2278 delay = 0;
2279 else if (is_hidden())
2280 delay = kDelaySecondsForContentStateSyncHidden;
2281 else
2282 delay = kDelaySecondsForContentStateSync;
2283
2284 if (nav_state_sync_timer_.IsRunning()) {
2285 // The timer is already running. If the delay of the timer maches the amount
2286 // we want to delay by, then return. Otherwise stop the timer so that it
2287 // gets started with the right delay.
2288 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2289 return;
2290 nav_state_sync_timer_.Stop();
2291 }
2292
[email protected]d323a172011-09-02 18:23:022293 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:282294 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:312295}
2296
[email protected]310ebd6302011-10-10 19:06:282297void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552298 mouse_over_url_ = GURL(url);
2299 UpdateTargetURL(mouse_over_url_, focus_url_);
2300}
2301
[email protected]310ebd6302011-10-10 19:06:282302void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552303 focus_url_ = GURL(url);
2304 UpdateTargetURL(focus_url_, mouse_over_url_);
2305}
2306
[email protected]0407e422012-05-18 19:51:252307void RenderViewImpl::startDragging(WebFrame* frame,
2308 const WebDragData& data,
[email protected]310ebd6302011-10-10 19:06:282309 WebDragOperationsMask mask,
2310 const WebImage& image,
2311 const WebPoint& imageOffset) {
[email protected]b67151d2012-05-25 23:23:242312 WebDropData drop_data(data);
2313 drop_data.referrer_policy = frame->document().referrerPolicy();
[email protected]59f4f2fa2011-03-23 01:00:552314 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]b67151d2012-05-25 23:23:242315 drop_data,
[email protected]c27ae592010-03-18 15:24:412316 mask,
[email protected]976127072012-05-10 20:08:112317 image.getSkBitmap(),
[email protected]c27ae592010-03-18 15:24:412318 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522319}
2320
[email protected]310ebd6302011-10-10 19:06:282321bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:452322 return renderer_preferences_.can_accept_load_drops;
2323}
2324
[email protected]310ebd6302011-10-10 19:06:282325void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:522326 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2327}
2328
[email protected]310ebd6302011-10-10 19:06:282329void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:522330 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2331}
2332
[email protected]310ebd6302011-10-10 19:06:282333void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512334 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072335
[email protected]38b592902011-04-16 02:08:422336 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:492337}
2338
[email protected]572a6ca2012-10-11 19:38:012339void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
2340 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
2341}
2342
2343void RenderViewImpl::hasTouchEventHandlers(bool has_handlers) {
2344 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2345}
2346
[email protected]169d4282011-11-30 19:33:592347void RenderViewImpl::didUpdateLayout() {
2348 // We don't always want to set up a timer, only if we've been put in that
2349 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2350 // message.
2351 if (!send_preferred_size_changes_ || !webview())
2352 return;
2353
2354 if (check_preferred_size_timer_.IsRunning())
2355 return;
2356 check_preferred_size_timer_.Start(FROM_HERE,
2357 TimeDelta::FromMilliseconds(0), this,
2358 &RenderViewImpl::CheckPreferredSize);
2359}
2360
[email protected]310ebd6302011-10-10 19:06:282361void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522362 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2363}
2364
[email protected]310ebd6302011-10-10 19:06:282365int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002366 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522367}
2368
[email protected]310ebd6302011-10-10 19:06:282369int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002370 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522371}
2372
[email protected]310ebd6302011-10-10 19:06:282373void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:322374 const WebAccessibilityObject& obj,
2375 WebAccessibilityNotification notification) {
[email protected]2a84f9d2012-06-05 21:50:432376 if (renderer_accessibility_) {
2377 renderer_accessibility_->HandleWebAccessibilityNotification(
2378 obj, notification);
2379 }
[email protected]063afcb2011-09-29 07:54:322380}
2381
[email protected]310ebd6302011-10-10 19:06:282382void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:142383 const WebString& value) {
2384 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2385 key.utf8(),
2386 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262387}
2388
[email protected]79dbc662009-09-04 05:42:512389// WebKit::WebWidgetClient ----------------------------------------------------
2390
[email protected]310ebd6302011-10-10 19:06:282391void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122392 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2393 // we won't have to test for user gesture anymore and we can
2394 // move that code back to render_widget.cc
2395 if (webview() && webview()->mainFrame() &&
2396 webview()->mainFrame()->isProcessingUserGesture()) {
2397 Send(new ViewHostMsg_Focus(routing_id_));
2398 }
2399}
2400
[email protected]310ebd6302011-10-10 19:06:282401void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122402 // TODO(jcivelli): see TODO above in didFocus().
2403 if (webview() && webview()->mainFrame() &&
2404 webview()->mainFrame()->isProcessingUserGesture()) {
2405 Send(new ViewHostMsg_Blur(routing_id_));
2406 }
2407}
2408
initial.commit09911bf2008-07-26 23:55:292409// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282410// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292411// point to dispatch the ShowView message.
2412//
2413// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282414// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292415//
[email protected]310ebd6302011-10-10 19:06:282416void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292417 DCHECK(!did_show_) << "received extraneous Show call";
2418 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2419
2420 if (did_show_)
2421 return;
2422 did_show_ = true;
2423
[email protected]e9ff79c2012-10-19 21:31:262424 if (GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:042425 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:042426
[email protected]28295ec2009-10-16 05:34:332427 // Force new windows to a popup if they were not opened with a user gesture.
2428 if (!opened_by_user_gesture_) {
2429 // We exempt background tabs for compat with older versions of Chrome.
2430 // TODO(darin): This seems bogus. These should have a user gesture, so
2431 // we probably don't need this check.
2432 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2433 policy = WebKit::WebNavigationPolicyNewPopup;
2434 }
2435
initial.commit09911bf2008-07-26 23:55:292436 // NOTE: initial_pos_ may still have its default values at this point, but
2437 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2438 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282439 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2440 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292441 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242442 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292443}
2444
[email protected]310ebd6302011-10-10 19:06:282445void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292446 DCHECK(did_show_) << "should already have shown the view";
2447
[email protected]c1f50aa2010-02-18 03:46:572448 // We must keep WebKit's shared timer running in this case in order to allow
2449 // showModalDialog to function properly.
2450 //
2451 // TODO(darin): WebKit should really be smarter about suppressing events and
2452 // timers so that we do not need to manage the shared timer in such a heavy
2453 // handed manner.
2454 //
[email protected]f1a29a02011-10-06 23:08:442455 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2456 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572457
[email protected]08a1c8102012-05-11 23:14:262458 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
2459 routing_id_, opener_id_));
initial.commit09911bf2008-07-26 23:55:292460}
2461
[email protected]2b624c562011-10-27 22:58:262462bool RenderViewImpl::enterFullScreen() {
2463 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2464 return true;
2465}
2466
2467void RenderViewImpl::exitFullScreen() {
2468 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2469}
2470
[email protected]217690d2012-01-27 07:33:112471bool RenderViewImpl::requestPointerLock() {
2472 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2473}
2474
2475void RenderViewImpl::requestPointerUnlock() {
2476 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2477}
2478
2479bool RenderViewImpl::isPointerLocked() {
2480 return mouse_lock_dispatcher_->IsMouseLockedTo(
2481 webwidget_mouse_lock_target_.get());
2482}
2483
[email protected]7a1ec28a2012-03-28 21:10:242484void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
2485 CompositorThread* compositor_thread =
2486 RenderThreadImpl::current()->compositor_thread();
2487 if (compositor_thread)
2488 compositor_thread->AddInputHandler(
2489 routing_id_, input_handler_identifier, AsWeakPtr());
2490
2491 RenderWidget::didActivateCompositor(input_handler_identifier);
[email protected]1c0c9bc2012-10-08 22:41:482492
2493 ProcessAcceleratedPinchZoomFlags(*CommandLine::ForCurrentProcess());
[email protected]7a1ec28a2012-03-28 21:10:242494}
2495
[email protected]3d9689372009-09-10 04:29:172496// WebKit::WebFrameClient -----------------------------------------------------
2497
[email protected]310ebd6302011-10-10 19:06:282498WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2499 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:552500 WebPlugin* plugin = NULL;
[email protected]e9ff79c2012-10-19 21:31:262501 if (GetContentClient()->renderer()->OverrideCreatePlugin(
[email protected]eaacd1f2011-09-23 02:32:552502 this, frame, params, &plugin)) {
2503 return plugin;
2504 }
2505
[email protected]1eb20dc2012-10-04 21:01:552506 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
[email protected]e9ff79c2012-10-19 21:31:262507 if (UTF16ToASCII(params.mimeType) == kBrowserPluginMimeType) {
[email protected]1eb20dc2012-10-04 21:01:552508 if (cmd_line->HasSwitch(switches::kEnableBrowserPluginOldImplementation)) {
2509 // TODO(fsamuel): Remove this once upstreaming of the new browser plugin
2510 // is complete.
[email protected]e9ff79c2012-10-19 21:31:262511 return old::BrowserPlugin::Create(this, frame, params);
[email protected]1eb20dc2012-10-04 21:01:552512 } else {
[email protected]e9ff79c2012-10-19 21:31:262513 return BrowserPluginManager::Get()->CreateBrowserPlugin(this, frame,
[email protected]1eb20dc2012-10-04 21:01:552514 params);
2515 }
[email protected]e6e56752012-08-10 00:46:062516 }
2517
[email protected]a813c8e2011-10-08 01:34:112518 webkit::WebPluginInfo info;
2519 std::string mime_type;
2520 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2521 params.mimeType.utf8(), &info, &mime_type);
2522 if (!found)
2523 return NULL;
2524
2525 WebPluginParams params_to_use = params;
2526 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312527 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172528}
2529
[email protected]310ebd6302011-10-10 19:06:282530WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422531 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372532 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422533
[email protected]30447b62009-11-13 01:13:372534 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512535 bool exists = false;
[email protected]30447b62009-11-13 01:13:372536 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512537 ViewHostMsg_CreateWorker_Params params;
2538 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512539 params.name = name;
2540 params.document_id = document_id;
2541 params.render_view_route_id = routing_id_;
2542 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232543 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372544 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512545 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372546 if (url_mismatch) {
2547 return NULL;
2548 } else {
[email protected]f1a29a02011-10-06 23:08:442549 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492550 document_id,
[email protected]6de0bcf2010-02-17 22:00:512551 exists,
[email protected]30447b62009-11-13 01:13:372552 route_id,
2553 routing_id_);
2554 }
[email protected]9c00f002009-11-05 22:37:422555}
2556
[email protected]97b150db2012-08-16 18:26:022557WebMediaPlayer* RenderViewImpl::createMediaPlayer(
2558 WebFrame* frame, const WebKit::WebURL& url, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442559 FOR_EACH_OBSERVER(
2560 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172561
[email protected]780fc8242012-09-19 20:28:522562 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
[email protected]25fb9b32012-04-27 03:21:552563#if defined(OS_ANDROID)
[email protected]855623ed2012-09-24 18:59:552564 WebGraphicsContext3D* resource_context =
2565 GetWebView()->sharedGraphicsContext3D();
2566
2567 GpuChannelHost* gpu_channel_host =
2568 RenderThreadImpl::current()->EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:262569 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
[email protected]855623ed2012-09-24 18:59:552570 if (!gpu_channel_host) {
2571 LOG(ERROR) << "Failed to establish GPU channel for media player";
2572 return NULL;
2573 }
2574
[email protected]780fc8242012-09-19 20:28:522575 if (cmd_line->HasSwitch(switches::kMediaPlayerInRenderProcess)) {
2576 if (!media_bridge_manager_.get()) {
2577 media_bridge_manager_.reset(
2578 new webkit_media::MediaPlayerBridgeManagerImpl(1));
2579 }
2580 return new webkit_media::WebMediaPlayerInProcessAndroid(
2581 frame,
2582 client,
2583 cookieJar(frame),
2584 media_player_manager_.get(),
2585 media_bridge_manager_.get(),
[email protected]e9ff79c2012-10-19 21:31:262586 new StreamTextureFactoryImpl(
[email protected]855623ed2012-09-24 18:59:552587 resource_context, gpu_channel_host, routing_id_),
[email protected]780fc8242012-09-19 20:28:522588 cmd_line->HasSwitch(switches::kDisableMediaHistoryLogging));
2589 }
2590 if (!media_player_proxy_) {
[email protected]e9ff79c2012-10-19 21:31:262591 media_player_proxy_ = new WebMediaPlayerProxyImplAndroid(
[email protected]780fc8242012-09-19 20:28:522592 this, media_player_manager_.get());
2593 }
2594 return new webkit_media::WebMediaPlayerImplAndroid(
2595 frame,
2596 client,
2597 media_player_manager_.get(),
2598 media_player_proxy_,
[email protected]e9ff79c2012-10-19 21:31:262599 new StreamTextureFactoryImpl(
[email protected]855623ed2012-09-24 18:59:552600 resource_context, gpu_channel_host, routing_id_));
[email protected]25fb9b32012-04-27 03:21:552601#endif
2602
[email protected]bb6fd402011-12-09 02:45:442603 media::MessageLoopFactory* message_loop_factory =
[email protected]b80322902012-03-06 01:33:502604 new media::MessageLoopFactory();
[email protected]bb6fd402011-12-09 02:45:442605 media::FilterCollection* collection = new media::FilterCollection();
2606 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372607
[email protected]9e2269d2012-01-07 00:06:212608 RenderAudioSourceProvider* audio_source_provider = NULL;
2609
[email protected]3d9689372009-09-10 04:29:172610 // Add in any custom filter factories first.
[email protected]3d9689372009-09-10 04:29:172611 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212612 // audio_source_provider is a "provider" to WebKit, and a sink
2613 // from the perspective of the audio renderer.
2614 audio_source_provider = new RenderAudioSourceProvider();
2615
2616 // Add the chrome specific audio renderer, using audio_source_provider
2617 // as the sink.
[email protected]37136d162012-04-09 23:39:192618 media::AudioRendererImpl* audio_renderer =
2619 new media::AudioRendererImpl(audio_source_provider);
[email protected]9e2269d2012-01-07 00:06:212620 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172621 }
2622
[email protected]15d206e2012-08-17 22:35:132623 WebGraphicsContext3DCommandBufferImpl* context3d = NULL;
[email protected]5f04c3532012-09-25 01:28:392624 if (!cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode))
[email protected]15d206e2012-08-17 22:35:132625 context3d = RenderThreadImpl::current()->GetGpuVDAContext3D();
[email protected]851334d2012-06-15 22:39:312626 if (context3d) {
[email protected]084c8552012-08-12 22:51:202627 scoped_refptr<base::MessageLoopProxy> factories_loop =
[email protected]84a83e192012-03-09 18:43:402628 RenderThreadImpl::current()->compositor_thread() ?
2629 RenderThreadImpl::current()->compositor_thread()->GetWebThread()
[email protected]084c8552012-08-12 22:51:202630 ->message_loop()->message_loop_proxy() :
2631 base::MessageLoopProxy::current();
[email protected]e1d69d762011-12-13 05:12:182632 GpuChannelHost* gpu_channel_host =
2633 RenderThreadImpl::current()->EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:262634 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
[email protected]873da262012-08-10 22:02:472635 collection->GetVideoDecoders()->push_back(new media::GpuVideoDecoder(
[email protected]084c8552012-08-12 22:51:202636 base::Bind(&media::MessageLoopFactory::GetMessageLoop,
2637 base::Unretained(message_loop_factory),
[email protected]c462c902012-09-06 13:13:422638 media::MessageLoopFactory::kDecoder),
[email protected]84a83e192012-03-09 18:43:402639 factories_loop,
[email protected]8d4359282012-01-14 00:53:312640 new RendererGpuVideoDecoderFactories(
[email protected]84a83e192012-03-09 18:43:402641 gpu_channel_host, factories_loop, context3d)));
[email protected]e1d69d762011-12-13 05:12:182642 }
[email protected]e1d69d762011-12-13 05:12:182643
[email protected]5d65fe92012-06-02 00:48:552644 WebMediaPlayer* media_player =
[email protected]e9ff79c2012-10-19 21:31:262645 GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
[email protected]da952fd2012-01-13 03:49:252646 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1113bfdf2012-07-16 21:46:102647 audio_source_provider, message_loop_factory, media_stream_impl_,
2648 render_media_log);
[email protected]da952fd2012-01-13 03:49:252649 if (!media_player) {
[email protected]ba42ac4f2012-10-11 20:28:142650#if defined(ENABLE_WEBRTC)
[email protected]5f04c3532012-09-25 01:28:392651 // TODO(wjia): when all patches related to WebMediaPlayerMS have been
2652 // landed, remove the switch. Refer to crbug.com/142988.
[email protected]1fba73c12012-10-10 23:36:202653 if (!cmd_line->HasSwitch(switches::kDisableWebMediaPlayerMS) &&
2654 MediaStreamImpl::CheckMediaStream(url)) {
[email protected]5f04c3532012-09-25 01:28:392655 EnsureMediaStreamImpl();
[email protected]1fba73c12012-10-10 23:36:202656 return new webkit_media::WebMediaPlayerMS(
2657 frame, client, AsWeakPtr(), media_stream_impl_, render_media_log);
[email protected]5f04c3532012-09-25 01:28:392658 }
[email protected]ba42ac4f2012-10-11 20:28:142659#endif
[email protected]5f04c3532012-09-25 01:28:392660
[email protected]cec4eb82012-01-12 17:51:562661 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252662 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1113bfdf2012-07-16 21:46:102663 audio_source_provider, message_loop_factory, media_stream_impl_,
2664 render_media_log);
[email protected]bb6fd402011-12-09 02:45:442665 }
[email protected]cec4eb82012-01-12 17:51:562666 return media_player;
[email protected]3d9689372009-09-10 04:29:172667}
2668
[email protected]310ebd6302011-10-10 19:06:282669WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212670 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232671 if (!frame || !frame->view())
2672 return NULL;
[email protected]035545f2010-04-09 13:10:212673 return new RendererWebApplicationCacheHostImpl(
2674 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442675 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212676}
2677
[email protected]310ebd6302011-10-10 19:06:282678WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382679 return &cookie_jar_;
2680}
2681
[email protected]0720b532012-08-28 19:23:372682void RenderViewImpl::didCreateFrame(WebFrame* parent, WebFrame* child) {
[email protected]0720b532012-08-28 19:23:372683 if (!updating_frame_tree_)
2684 SendUpdatedFrameTree(NULL);
2685}
2686
[email protected]310ebd6302011-10-10 19:06:282687void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]0720b532012-08-28 19:23:372688 if (is_loading_) {
2689 pending_frame_tree_update_ = true;
2690 // Make sure observers are notified, even if we return right away.
2691 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
2692 return;
2693 }
2694 if (!updating_frame_tree_)
2695 SendUpdatedFrameTree(frame);
2696
[email protected]676126f72011-01-15 00:03:512697 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452698}
2699
[email protected]310ebd6302011-10-10 19:06:282700void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512701 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172702}
2703
[email protected]310ebd6302011-10-10 19:06:282704void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172705 WebFrame* frame, const WebURLRequest& request,
2706 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342707 loadURLExternally(frame, request, policy, WebString());
2708}
2709
[email protected]5e92282f2012-08-17 08:11:572710void RenderViewImpl::Repaint(const gfx::Size& size) {
2711 OnMsgRepaint(size);
2712}
2713
[email protected]310ebd6302011-10-10 19:06:282714void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342715 WebFrame* frame, const WebURLRequest& request,
2716 WebNavigationPolicy policy,
2717 const WebString& suggested_name) {
[email protected]56505542012-05-12 00:25:372718 Referrer referrer(
2719 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2720 GetReferrerPolicyFromRequest(frame, request));
[email protected]efce17b2009-09-11 18:04:592721 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342722 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2723 suggested_name));
[email protected]efce17b2009-09-11 18:04:592724 } else {
[email protected]56505542012-05-12 00:25:372725 OpenURL(frame, request.url(), referrer, policy);
[email protected]efce17b2009-09-11 18:04:592726 }
[email protected]3d9689372009-09-10 04:29:172727}
2728
[email protected]310ebd6302011-10-10 19:06:282729WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172730 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222731 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]0639c063a2012-03-22 20:55:332732 Referrer referrer(
2733 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:592734 GetReferrerPolicyFromRequest(frame, request));
[email protected]0639c063a2012-03-22 20:55:332735
[email protected]992db4c2011-05-12 15:37:152736 if (is_swapped_out_) {
[email protected]e9ff79c2012-10-19 21:31:262737 if (request.url() != GURL(kSwappedOutURL)) {
[email protected]0639c063a2012-03-22 20:55:332738 // Targeted links may try to navigate a swapped out frame. Allow the
2739 // browser process to navigate the tab instead. Note that it is also
2740 // possible for non-targeted navigations (from this view) to arrive
2741 // here just after we are swapped out. It's ok to send them to the
2742 // browser, as long as they're for the top level frame.
2743 // TODO(creis): Ensure this supports targeted form submissions when
2744 // fixing http://crbug.com/101395.
2745 if (frame->parent() == NULL) {
2746 OpenURL(frame, request.url(), referrer, default_policy);
2747 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2748 }
2749
2750 // We should otherwise ignore in-process iframe navigations, if they
2751 // arrive just after we are swapped out.
[email protected]73eb2602012-02-09 19:50:552752 return WebKit::WebNavigationPolicyIgnore;
[email protected]0639c063a2012-03-22 20:55:332753 }
[email protected]73eb2602012-02-09 19:50:552754
[email protected]e9ff79c2012-10-19 21:31:262755 // Allow kSwappedOutURL to complete.
[email protected]992db4c2011-05-12 15:37:152756 return default_policy;
2757 }
2758
[email protected]3d9689372009-09-10 04:29:172759 // Webkit is asking whether to navigate to a new URL.
2760 // This is fine normally, except if we're showing UI from one security
2761 // context and they're trying to navigate to a different context.
2762 const GURL& url = request.url();
2763
[email protected]d19ea342011-04-20 20:31:132764 // A content initiated navigation may have originated from a link-click,
2765 // script, drag-n-drop operation, etc.
2766 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072767 DocumentState::FromDataSource(frame->provisionalDataSource())->
2768 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132769
[email protected]a8c269a2011-10-25 20:17:222770 // Experimental:
2771 // If --enable-strict-site-isolation is enabled, send all top-level
2772 // navigations to the browser to let it swap processes when crossing site
2773 // boundaries. This is currently expected to break some script calls and
2774 // navigations, such as form submissions.
2775 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102776 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2777 !frame->parent() && (is_content_initiated || is_redirect)) {
2778 WebString origin_str = frame->document().securityOrigin().toString();
2779 GURL frame_url(origin_str.utf8().data());
[email protected]18fb7a772012-09-20 19:25:092780 // TODO(cevans): revisit whether this site check is still necessary once
[email protected]313b80bd2011-11-23 03:49:102781 // crbug.com/101395 is fixed.
[email protected]18fb7a772012-09-20 19:25:092782 if (!net::RegistryControlledDomainService::SameDomainOrHost(frame_url,
2783 url) ||
2784 frame_url.scheme() != url.scheme()) {
[email protected]313b80bd2011-11-23 03:49:102785 OpenURL(frame, url, referrer, default_policy);
2786 return WebKit::WebNavigationPolicyIgnore;
2787 }
[email protected]a8c269a2011-10-25 20:17:222788 }
2789
[email protected]fd3238af2012-05-22 18:55:302790 // If the browser is interested, then give it a chance to look at the request.
[email protected]5f000f272012-01-19 05:25:082791 if (is_content_initiated) {
[email protected]fd3238af2012-05-22 18:55:302792 bool browser_handles_request =
2793 renderer_preferences_.browser_handles_non_local_top_level_requests &&
[email protected]5f000f272012-01-19 05:25:082794 IsNonLocalTopLevelNavigation(url, frame, type);
[email protected]fd3238af2012-05-22 18:55:302795 if (!browser_handles_request) {
2796 browser_handles_request =
2797 renderer_preferences_.browser_handles_all_top_level_requests &&
2798 IsTopLevelNavigation(frame);
2799 }
2800
2801 if (browser_handles_request) {
[email protected]5f000f272012-01-19 05:25:082802 // Reset these counters as the RenderView could be reused for the next
2803 // navigation.
2804 page_id_ = -1;
2805 last_page_id_sent_to_browser_ = -1;
2806 OpenURL(frame, url, referrer, default_policy);
2807 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2808 }
[email protected]3d9689372009-09-10 04:29:172809 }
2810
[email protected]dc67e1c32012-06-08 00:10:402811 // Use the frame's original request's URL rather than the document's URL for
2812 // subsequent checks. For a popup, the document's URL may become the opener
2813 // window's URL if the opener has called document.write().
2814 // See http://crbug.com/93517.
2815 GURL old_url(frame->dataSource()->request().url());
2816
[email protected]6101c342010-12-16 22:44:372817 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552818 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:042819 // top-level navigations (not iframes). But we sometimes navigate to
2820 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:372821 //
[email protected]744c2a22012-03-15 18:42:042822 // Note: this is known to break POST submissions when crossing process
2823 // boundaries until http://crbug.com/101395 is fixed. This is better for
2824 // security than loading a WebUI, extension or app page in the wrong process.
2825 // POST requests don't work because this mechanism does not preserve form
2826 // POST data. We will need to send the request's httpBody data up to the
2827 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:572828 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2829 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222830 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:042831 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:372832 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:042833
2834 // All navigations to WebUI URLs or within WebUI-enabled RenderProcesses
2835 // must be handled by the browser process so that the correct bindings and
2836 // data sources can be registered.
2837 // Similarly, navigations to view-source URLs or within ViewSource mode
2838 // must be handled by the browser process.
[email protected]dc67e1c32012-06-08 00:10:402839 // Lastly, access to file:// URLs from non-file:// URL pages must be
2840 // handled by the browser so that ordinary renderer processes don't get
2841 // blessed with file permissions.
2842 int cumulative_bindings = RenderProcess::current()->GetEnabledBindings();
2843 bool is_initial_navigation = page_id_ == -1;
[email protected]6101c342010-12-16 22:44:372844 bool should_fork =
[email protected]e9ff79c2012-10-19 21:31:262845 GetContentClient()->HasWebUIScheme(url) ||
2846 (cumulative_bindings & BINDINGS_POLICY_WEB_UI) ||
[email protected]744c2a22012-03-15 18:42:042847 url.SchemeIs(chrome::kViewSourceScheme) ||
2848 frame->isViewSourceModeEnabled();
[email protected]5351dbc2010-08-27 15:22:112849
[email protected]dc67e1c32012-06-08 00:10:402850 if (!should_fork && url.SchemeIs(chrome::kFileScheme)) {
2851 // Fork non-file to file opens. Check the opener URL if this is the
2852 // initial navigation in a newly opened window.
2853 GURL source_url(old_url);
2854 if (is_initial_navigation && source_url.is_empty() && frame->opener())
2855 source_url = frame->opener()->top()->document().url();
2856 DCHECK(!source_url.is_empty());
2857 should_fork = !source_url.SchemeIs(chrome::kFileScheme);
2858 }
2859
[email protected]e48869a2011-04-01 19:56:032860 if (!should_fork) {
2861 // Give the embedder a chance.
[email protected]744c2a22012-03-15 18:42:042862 // For now, we skip this for POST submissions. This is because
2863 // http://crbug.com/101395 is more likely to cause compatibility issues
2864 // with hosted apps and extensions than WebUI pages. We will remove this
2865 // check when cross-process POST submissions are supported.
2866 if (request.httpMethod() == "GET") {
[email protected]e9ff79c2012-10-19 21:31:262867 should_fork = GetContentClient()->renderer()->ShouldFork(
[email protected]744c2a22012-03-15 18:42:042868 frame, url, is_initial_navigation, &send_referrer);
2869 }
[email protected]6101c342010-12-16 22:44:372870 }
2871
2872 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152873 OpenURL(
2874 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112875 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2876 }
[email protected]3d9689372009-09-10 04:29:172877 }
2878
2879 // Detect when a page is "forking" a new tab that can be safely rendered in
2880 // its own process. This is done by sites like Gmail that try to open links
2881 // in new windows without script connections back to the original page. We
2882 // treat such cases as browser navigations (in which we will create a new
2883 // renderer for a cross-site navigation), rather than WebKit navigations.
2884 //
2885 // We use the following heuristic to decide whether to fork a new page in its
2886 // own process:
2887 // The parent page must open a new tab to about:blank, set the new tab's
2888 // window.opener to null, and then redirect the tab to a cross-site URL using
2889 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462890 //
2891 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2892 // (see below).
[email protected]3d9689372009-09-10 04:29:172893 bool is_fork =
2894 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582895 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172896 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522897 historyBackListCount() < 1 &&
2898 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172899 // The parent page must have set the child's window.opener to null before
2900 // redirecting to the desired URL.
2901 frame->opener() == NULL &&
2902 // Must be a top-level frame.
2903 frame->parent() == NULL &&
2904 // Must not have issued the request from this page.
2905 is_content_initiated &&
2906 // Must be targeted at the current tab.
2907 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2908 // Must be a JavaScript navigation, which appears as "other".
2909 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462910
[email protected]f92ce2b2012-03-06 18:02:592911 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:172912 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152913 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172914 return WebKit::WebNavigationPolicyIgnore;
2915 }
2916
2917 return default_policy;
2918}
2919
[email protected]310ebd6302011-10-10 19:06:282920bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492921 WebFrame* frame, const WebURLRequest& request) {
2922 // We allow WebKit to think that everything can be handled even though
2923 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342924 return true;
2925}
2926
[email protected]310ebd6302011-10-10 19:06:282927WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492928 WebFrame* frame, const WebURLRequest& request) {
2929 NOTREACHED(); // Since we said we can handle all requests.
2930 return WebURLError();
2931}
2932
[email protected]310ebd6302011-10-10 19:06:282933WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492934 WebFrame* frame, const WebURLRequest& request) {
2935 WebURLError error;
2936 error.domain = WebString::fromUTF8(net::kErrorDomain);
2937 error.reason = net::ERR_ABORTED;
2938 error.unreachableURL = request.url();
2939 return error;
[email protected]7b7a7dc2009-10-19 02:23:342940}
2941
[email protected]310ebd6302011-10-10 19:06:282942void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492943 WebFrame*, const WebURLError&) {
2944 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342945}
2946
[email protected]310ebd6302011-10-10 19:06:282947void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432948 const WebKit::WebFormElement& form) {
2949 // Some login forms have onSubmit handlers that put a hash of the password
2950 // into a hidden field and then clear the password. (Issue 28910.)
2951 // This method gets called before any of those handlers run, so save away
2952 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072953 DocumentState* document_state =
2954 DocumentState::FromDataSource(frame->dataSource());
[email protected]e9ff79c2012-10-19 21:31:262955 document_state->set_password_form_data(CreatePasswordForm(form));
[email protected]90eeddb2010-05-06 21:06:432956}
2957
[email protected]310ebd6302011-10-10 19:06:282958void RenderViewImpl::willSubmitForm(WebFrame* frame,
2959 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072960 DocumentState* document_state =
2961 DocumentState::FromDataSource(frame->provisionalDataSource());
2962 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172963
[email protected]e9ff79c2012-10-19 21:31:262964 if (navigation_state->transition_type() == PAGE_TRANSITION_LINK)
2965 navigation_state->set_transition_type(PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172966
2967 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352968 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072969 document_state->set_searchable_form_url(web_searchable_form_data.url());
2970 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212971 web_searchable_form_data.encoding().utf8());
[email protected]a045f4e32012-08-31 09:36:072972 scoped_ptr<PasswordForm> password_form_data =
[email protected]e9ff79c2012-10-19 21:31:262973 CreatePasswordForm(form);
[email protected]90eeddb2010-05-06 21:06:432974
[email protected]098c95cb2011-04-28 16:49:012975 // In order to save the password that the user actually typed and not one
2976 // that may have gotten transformed by the site prior to submit, recover it
2977 // from the form contents already stored by |willSendSubmitEvent| into the
2978 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2979 // which is what we're storing into now.)
[email protected]a045f4e32012-08-31 09:36:072980 if (password_form_data.get()) {
[email protected]007733c2011-11-17 00:34:072981 DocumentState* old_document_state =
2982 DocumentState::FromDataSource(frame->dataSource());
2983 if (old_document_state) {
2984 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432985 if (old_form_data && old_form_data->action == password_form_data->action)
2986 password_form_data->password_value = old_form_data->password_value;
2987 }
2988 }
[email protected]3d9689372009-09-10 04:29:172989
[email protected]a045f4e32012-08-31 09:36:072990 document_state->set_password_form_data(password_form_data.Pass());
2991
[email protected]2a5b1732011-04-01 23:55:552992 FOR_EACH_OBSERVER(
2993 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172994}
2995
[email protected]310ebd6302011-10-10 19:06:282996void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172997 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2998 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382999 FOR_EACH_OBSERVER(
3000 RenderViewObserver, observers_,
3001 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:173002}
3003
[email protected]310ebd6302011-10-10 19:06:283004void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:383005 FOR_EACH_OBSERVER(
3006 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:173007}
3008
[email protected]310ebd6302011-10-10 19:06:283009void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:173010 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:153011 if (!frame->parent()) {
3012 WebDataSource* ds = frame->provisionalDataSource();
3013 // If there's no provisional data source, it's a reference fragment
3014 // navigation.
3015 completed_client_redirect_src_ = Referrer(
[email protected]ca662822012-05-11 17:53:593016 from, ds ? GetReferrerPolicyFromRequest(frame, ds->request()) :
[email protected]f36f4092012-05-09 18:31:043017 frame->document().referrerPolicy());
[email protected]445e1042011-12-03 21:03:153018 }
[email protected]eb0bff942011-04-07 22:08:383019 FOR_EACH_OBSERVER(
3020 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:173021}
3022
[email protected]310ebd6302011-10-10 19:06:283023void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:573024 bool content_initiated = !pending_navigation_params_.get();
3025
[email protected]007733c2011-11-17 00:34:073026 DocumentState* document_state = DocumentState::FromDataSource(ds);
3027 if (!document_state) {
3028 document_state = new DocumentState;
3029 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:573030 if (!content_initiated)
3031 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:073032 }
3033
[email protected]bf70edce2012-06-20 22:32:223034 // Carry over the user agent override flag, if it exists.
3035 if (content_initiated && webview() && webview()->mainFrame() &&
3036 webview()->mainFrame()->dataSource()) {
3037 DocumentState* old_document_state =
3038 DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
3039 if (old_document_state) {
3040 document_state->set_is_overriding_user_agent(
3041 old_document_state->is_overriding_user_agent());
3042 }
3043 }
3044
[email protected]3d9689372009-09-10 04:29:173045 // The rest of RenderView assumes that a WebDataSource will always have a
3046 // non-null NavigationState.
[email protected]e1ed5a12012-08-08 19:57:443047 if (content_initiated) {
[email protected]007733c2011-11-17 00:34:073048 document_state->set_navigation_state(
3049 NavigationState::CreateContentInitiated());
[email protected]e1ed5a12012-08-08 19:57:443050 } else {
[email protected]45d83a12012-04-06 22:57:573051 document_state->set_navigation_state(CreateNavigationStateFromPending());
3052 pending_navigation_params_.reset();
3053 }
[email protected]8a3125a712010-08-09 18:58:513054
[email protected]007733c2011-11-17 00:34:073055 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:513056 // navigating from a page that used prefetching using a link on that
3057 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:073058 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:513059 // this value appropriately.
3060 // TODO(gavinp): catch the important case of navigation in a new
3061 // renderer process.
3062 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303063 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523064 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513065 const GURL referrer(
3066 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3067 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:073068 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:513069 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:413070 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:513071 WebDataSource* old_frame_ds = old_frame->dataSource();
3072 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:073073 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513074 break;
3075 }
3076 }
3077 }
3078 }
3079 }
3080
[email protected]4c1b6f0b2010-02-07 16:38:183081 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523082 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513083 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183084 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:073085 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:183086 break;
3087 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:073088 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:183089 break;
3090 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:073091 document_state->set_load_type(
3092 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:183093 break;
3094 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:073095 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:183096 break;
3097 }
3098 }
[email protected]fa7b6b542009-11-03 05:02:303099
[email protected]946a0032011-03-31 18:42:283100 FOR_EACH_OBSERVER(
3101 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:173102}
3103
[email protected]45d83a12012-04-06 22:57:573104void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:073105 DocumentState* document_state) {
3106 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:573107 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:073108
[email protected]45d83a12012-04-06 22:57:573109 if (!params.url.SchemeIs(chrome::kJavaScriptScheme) &&
3110 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
3111 // We're doing a load of a page that was restored from the last session. By
3112 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
3113 // can result in stale data for pages that are set to expire. We explicitly
3114 // override that by setting the policy here so that as necessary we load
3115 // from the network.
3116 document_state->set_cache_policy_override(
3117 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:073118 }
3119
3120 if (IsReload(params))
3121 document_state->set_load_type(DocumentState::RELOAD);
3122 else if (!params.state.empty())
3123 document_state->set_load_type(DocumentState::HISTORY_LOAD);
3124 else
3125 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]ca662822012-05-11 17:53:593126
3127 document_state->set_referrer_policy(params.referrer.policy);
[email protected]bf70edce2012-06-20 22:32:223128 document_state->set_is_overriding_user_agent(params.is_overriding_user_agent);
[email protected]a3a5397d2012-09-12 06:50:343129 document_state->set_must_reset_scroll_and_scale_state(
3130 params.navigation_type ==
3131 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]951a64832012-10-11 16:26:373132 document_state->set_can_load_local_resources(params.can_load_local_resources);
[email protected]45d83a12012-04-06 22:57:573133}
[email protected]007733c2011-11-17 00:34:073134
[email protected]45d83a12012-04-06 22:57:573135NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
3136 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
3137 NavigationState* navigation_state = NULL;
3138
3139 // A navigation resulting from loading a javascript URL should not be treated
3140 // as a browser initiated event. Instead, we want it to look as if the page
3141 // initiated any load resulting from JS execution.
3142 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
3143 navigation_state = NavigationState::CreateBrowserInitiated(
3144 params.page_id,
3145 params.pending_history_list_offset,
3146 params.transition);
3147 navigation_state->set_transferred_request_child_id(
3148 params.transferred_request_child_id);
3149 navigation_state->set_transferred_request_request_id(
3150 params.transferred_request_request_id);
[email protected]80744782012-05-04 01:47:003151 navigation_state->set_allow_download(params.allow_download);
[email protected]45d83a12012-04-06 22:57:573152 } else {
3153 navigation_state = NavigationState::CreateContentInitiated();
3154 }
3155 return navigation_state;
[email protected]007733c2011-11-17 00:34:073156}
3157
[email protected]5b52cd2f712012-03-28 02:12:483158void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
3159 bool enable_viewport =
[email protected]06ea34a2012-05-07 18:52:103160 command_line.HasSwitch(switches::kEnableViewport);
[email protected]5b52cd2f712012-03-28 02:12:483161 bool enable_fixed_layout =
3162 command_line.HasSwitch(switches::kEnableFixedLayout);
3163
3164 webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport);
3165 webview()->settings()->setFixedElementsLayoutRelativeToFrame(true);
3166
3167 if (enable_viewport) {
3168 webview()->settings()->setViewportEnabled(true);
3169 } else if (enable_fixed_layout) {
3170 std::string str =
3171 command_line.GetSwitchValueASCII(switches::kEnableFixedLayout);
3172 std::vector<std::string> tokens;
3173 base::SplitString(str, ',', &tokens);
3174 if (tokens.size() == 2) {
3175 int width, height;
3176 if (base::StringToInt(tokens[0], &width) &&
3177 base::StringToInt(tokens[1], &height))
[email protected]e1ed5a12012-08-08 19:57:443178 webview()->setFixedLayoutSize(WebSize(width, height));
[email protected]5b52cd2f712012-03-28 02:12:483179 }
3180 }
[email protected]1c0c9bc2012-10-08 22:41:483181
3182 ProcessAcceleratedPinchZoomFlags(command_line);
3183}
3184
3185void RenderViewImpl::ProcessAcceleratedPinchZoomFlags(
3186 const CommandLine& command_line) {
3187 bool enable_viewport =
3188 command_line.HasSwitch(switches::kEnableViewport);
3189 bool enable_pinch = enable_viewport ||
3190 command_line.HasSwitch(switches::kEnablePinch);
3191 bool enable_pinch_in_compositor =
[email protected]65bfd9972012-10-19 03:39:373192 command_line.HasSwitch(cc::switches::kEnablePinchInCompositor);
[email protected]1c0c9bc2012-10-08 22:41:483193
3194 if (!enable_pinch &&
3195 webview()->isAcceleratedCompositingActive() &&
3196 webkit_preferences_.apply_default_device_scale_factor_in_compositor &&
3197 device_scale_factor_ != 1) {
3198 // Page scaling is disabled by default when applying a scale factor in the
3199 // compositor since they are currently incompatible.
3200 webview()->setPageScaleFactorLimits(1, 1);
3201 }
3202
3203 if (enable_pinch_in_compositor &&
3204 webview()->isAcceleratedCompositingActive())
3205 webview()->setPageScaleFactorLimits(1, 4);
[email protected]5b52cd2f712012-03-28 02:12:483206}
3207
[email protected]310ebd6302011-10-10 19:06:283208void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173209 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:073210 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:173211
[email protected]3d9689372009-09-10 04:29:173212 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:073213 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:173214 double event_time = ds->triggeringEventTime();
3215 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:073216 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:173217 }
3218
[email protected]05c8e502010-08-15 15:13:523219 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:073220 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:523221
[email protected]3d9689372009-09-10 04:29:173222 bool is_top_most = !frame->parent();
3223 if (is_top_most) {
3224 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133225 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173226
3227 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:153228 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173229 } else if (frame->parent()->isLoading()) {
3230 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003231 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:073232 document_state->navigation_state()->set_transition_type(
[email protected]e9ff79c2012-10-19 21:31:263233 PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:173234 }
3235
[email protected]28685da92011-02-07 21:49:173236 FOR_EACH_OBSERVER(
3237 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
3238
[email protected]3d9689372009-09-10 04:29:173239 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]d37c33e2012-10-12 13:35:133240 routing_id_, frame->identifier(),
3241 frame->parent() ? frame->parent()->identifier() : -1,
3242 is_top_most, GetOpenerUrl(), ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173243}
3244
[email protected]400992b2012-06-14 00:03:543245void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
3246 WebFrame* frame) {
3247 if (frame->parent())
3248 return;
3249 // Received a redirect on the main frame.
3250 WebDataSource* data_source = frame->provisionalDataSource();
3251 if (!data_source) {
3252 // Should only be invoked when we have a data source.
3253 NOTREACHED();
3254 return;
3255 }
3256 std::vector<GURL> redirects;
3257 GetRedirectChain(data_source, &redirects);
3258 if (redirects.size() >= 2) {
3259 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
3260 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
3261 }
3262}
3263
[email protected]310ebd6302011-10-10 19:06:283264void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
3265 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173266 // Notify the browser that we failed a provisional load with an error.
3267 //
3268 // Note: It is important this notification occur before DidStopLoading so the
3269 // SSL manager can react to the provisional load failure before being
3270 // notified the load stopped.
3271 //
3272 WebDataSource* ds = frame->provisionalDataSource();
3273 DCHECK(ds);
3274
3275 const WebURLRequest& failed_request = ds->request();
3276
[email protected]28685da92011-02-07 21:49:173277 FOR_EACH_OBSERVER(
3278 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
3279
[email protected]3d9689372009-09-10 04:29:173280 bool show_repost_interstitial =
3281 (error.reason == net::ERR_CACHE_MISS &&
3282 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:583283
3284 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
3285 params.frame_id = frame->identifier();
3286 params.is_main_frame = !frame->parent();
3287 params.error_code = error.reason;
[email protected]e9ff79c2012-10-19 21:31:263288 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]d7b175e2011-10-11 15:31:583289 failed_request,
3290 error,
3291 NULL,
3292 &params.error_description);
3293 params.url = error.unreachableURL;
3294 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:173295 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:583296 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:173297
3298 // Don't display an error page if this is simply a cancelled load. Aside
3299 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3300 if (error.reason == net::ERR_ABORTED)
3301 return;
3302
3303 // Make sure we never show errors in view source mode.
3304 frame->enableViewSourceMode(false);
3305
[email protected]007733c2011-11-17 00:34:073306 DocumentState* document_state = DocumentState::FromDataSource(ds);
3307 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173308
3309 // If this is a failed back/forward/reload navigation, then we need to do a
3310 // 'replace' load. This is necessary to avoid messing up session history.
3311 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3312 // as session history is concerned.
3313 //
3314 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3315 // the page id.
3316 //
3317 bool replace =
3318 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:583319 navigation_state->transition_type() ==
[email protected]e9ff79c2012-10-19 21:31:263320 PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:173321
3322 // If we failed on a browser initiated request, then make sure that our error
3323 // page load is regarded as the same browser initiated request.
3324 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:073325 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
3326 pending_navigation_params_->page_id =
3327 navigation_state->pending_page_id();
3328 pending_navigation_params_->pending_history_list_offset =
3329 navigation_state->pending_history_list_offset();
3330 pending_navigation_params_->transition =
3331 navigation_state->transition_type();
3332 pending_navigation_params_->request_time =
3333 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:173334 }
3335
3336 // Provide the user with a more helpful error page?
3337 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3338 return;
3339
3340 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083341 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173342}
3343
[email protected]310ebd6302011-10-10 19:06:283344void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:173345 WebFrame* frame, const char* data, size_t data_len,
3346 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:073347 DocumentState* document_state =
3348 DocumentState::FromDataSource(frame->dataSource());
3349 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:173350}
3351
[email protected]310ebd6302011-10-10 19:06:283352void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
3353 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:073354 DocumentState* document_state =
3355 DocumentState::FromDataSource(frame->dataSource());
3356 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173357
[email protected]007733c2011-11-17 00:34:073358 if (document_state->commit_load_time().is_null())
3359 document_state->set_commit_load_time(Time::Now());
3360
[email protected]a3a5397d2012-09-12 06:50:343361 if (document_state->must_reset_scroll_and_scale_state()) {
3362 webview()->resetScrollAndScaleState();
3363 document_state->set_must_reset_scroll_and_scale_state(false);
3364 }
3365
[email protected]3d9689372009-09-10 04:29:173366 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203367 // When we perform a new navigation, we need to update the last committed
3368 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173369 UpdateSessionHistory(frame);
3370
3371 // We bump our Page ID to correspond with the new session history entry.
3372 page_id_ = next_page_id_++;
3373
[email protected]e9ff79c2012-10-19 21:31:263374 // Don't update history_page_ids_ (etc) for kSwappedOutURL, since
[email protected]58436a12012-03-21 17:10:263375 // we don't want to forget the entry that was there, and since we will
[email protected]e9ff79c2012-10-19 21:31:263376 // never come back to kSwappedOutURL. Note that we have to call
[email protected]69ddf852012-02-21 23:21:313377 // UpdateSessionHistory and update page_id_ even in this case, so that
3378 // the current entry gets a state update and so that we don't send a
3379 // state update to the wrong entry when we swap back in.
[email protected]e9ff79c2012-10-19 21:31:263380 if (GetLoadingUrl(frame) != GURL(kSwappedOutURL)) {
[email protected]69ddf852012-02-21 23:21:313381 // Advance our offset in session history, applying the length limit.
3382 // There is now no forward history.
3383 history_list_offset_++;
[email protected]e9ff79c2012-10-19 21:31:263384 if (history_list_offset_ >= kMaxSessionHistoryEntries)
3385 history_list_offset_ = kMaxSessionHistoryEntries - 1;
[email protected]69ddf852012-02-21 23:21:313386 history_list_length_ = history_list_offset_ + 1;
3387 history_page_ids_.resize(history_list_length_, -1);
3388 history_page_ids_[history_list_offset_] = page_id_;
3389 }
[email protected]3d9689372009-09-10 04:29:173390 } else {
3391 // Inspect the navigation_state on this frame to see if the navigation
3392 // corresponds to a session history navigation... Note: |frame| may or
3393 // may not be the toplevel frame, but for the case of capturing session
3394 // history, the first committed frame suffices. We keep track of whether
3395 // we've seen this commit before so that only capture session history once
3396 // per navigation.
3397 //
3398 // Note that we need to check if the page ID changed. In the case of a
3399 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3400 // previous URL and the current page ID, which would be wrong.
3401 if (navigation_state->pending_page_id() != -1 &&
3402 navigation_state->pending_page_id() != page_id_ &&
3403 !navigation_state->request_committed()) {
3404 // This is a successful session history navigation!
3405 UpdateSessionHistory(frame);
3406 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003407
3408 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:033409
3410 // If the history list is valid, our list of page IDs should be correct.
3411 DCHECK(history_list_length_ <= 0 ||
3412 history_list_offset_ < 0 ||
3413 history_list_offset_ >= history_list_length_ ||
3414 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:173415 }
3416 }
3417
[email protected]28685da92011-02-07 21:49:173418 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3419 DidCommitProvisionalLoad(frame, is_new_navigation));
3420
[email protected]3d9689372009-09-10 04:29:173421 // Remember that we've already processed this request, so we don't update
3422 // the session history again. We do this regardless of whether this is
3423 // a session history navigation, because if we attempted a session history
3424 // navigation without valid HistoryItem state, WebCore will think it is a
3425 // new navigation.
3426 navigation_state->set_request_committed(true);
3427
3428 UpdateURL(frame);
3429
3430 // If this committed load was initiated by a client redirect, we're
3431 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:153432 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173433
3434 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273435 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]b2d98762012-09-03 17:04:063436
3437 if (!frame->parent()) { // Only for top frames.
3438 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
3439 if (render_thread_impl) { // Can be NULL in tests.
3440 render_thread_impl->histogram_customizer()->
3441 RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(),
3442 g_view_map.Get().size());
3443 }
3444 }
[email protected]3d9689372009-09-10 04:29:173445}
3446
[email protected]310ebd6302011-10-10 19:06:283447void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:103448 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3449 DidClearWindowObject(frame));
3450
[email protected]b6cb3a842011-06-24 18:28:413451 GURL frame_url = frame->document().url();
[email protected]e9ff79c2012-10-19 21:31:263452 if ((enabled_bindings_ & BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:253453 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
3454 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:273455 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:173456 }
[email protected]766a7082012-02-03 23:39:153457
[email protected]e9ff79c2012-10-19 21:31:263458 if (enabled_bindings_ & BINDINGS_POLICY_DOM_AUTOMATION) {
[email protected]766a7082012-02-03 23:39:153459 if (!dom_automation_controller_.get())
3460 dom_automation_controller_.reset(new DomAutomationController());
3461 dom_automation_controller_->set_message_sender(
[email protected]e9ff79c2012-10-19 21:31:263462 static_cast<RenderView*>(this));
[email protected]766a7082012-02-03 23:39:153463 dom_automation_controller_->set_routing_id(routing_id());
3464 dom_automation_controller_->BindToJavascript(frame,
3465 "domAutomationController");
3466 }
[email protected]498bc512012-09-21 21:50:083467
[email protected]e9ff79c2012-10-19 21:31:263468 InjectDoNotTrackBindings(frame);
[email protected]3d9689372009-09-10 04:29:173469}
3470
[email protected]310ebd6302011-10-10 19:06:283471void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173472 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:413473 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:253474 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]87717d0e2012-04-26 02:58:433475 if (frame == webview()->mainFrame())
3476 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:173477 }
[email protected]e48869a2011-04-01 19:56:033478
3479 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3480 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:173481}
3482
[email protected]310ebd6302011-10-10 19:06:283483void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
3484 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:463485 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:173486
3487 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273488 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173489}
3490
[email protected]310ebd6302011-10-10 19:06:283491void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:133492 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3493 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:583494}
3495
[email protected]310ebd6302011-10-10 19:06:283496void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173497 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073498 DocumentState* document_state = DocumentState::FromDataSource(ds);
3499 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:173500
[email protected]622474d2010-11-04 09:21:083501 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173502
[email protected]28685da92011-02-07 21:49:173503 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3504 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173505
3506 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273507 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173508}
3509
[email protected]310ebd6302011-10-10 19:06:283510void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083511 if (webview()->mainFrame() == frame) {
3512 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3513 page_id_));
3514 }
[email protected]3d9689372009-09-10 04:29:173515}
3516
[email protected]310ebd6302011-10-10 19:06:283517void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:313518 WebDataSource* ds = frame->dataSource();
3519 DCHECK(ds);
3520
3521
[email protected]28685da92011-02-07 21:49:173522 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:313523
3524 const WebURLRequest& failed_request = ds->request();
3525 string16 error_description;
[email protected]e9ff79c2012-10-19 21:31:263526 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]1a55c5be2011-11-29 11:36:313527 failed_request,
3528 error,
3529 NULL,
3530 &error_description);
3531 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
3532 frame->identifier(),
3533 failed_request.url(),
3534 !frame->parent(),
3535 error.reason,
3536 error_description));
[email protected]3d9689372009-09-10 04:29:173537}
3538
[email protected]310ebd6302011-10-10 19:06:283539void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173540 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073541 DocumentState* document_state = DocumentState::FromDataSource(ds);
3542 if (document_state->finish_load_time().is_null())
3543 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:413544
[email protected]676126f72011-01-15 00:03:513545 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173546
[email protected]1a55c5be2011-11-29 11:36:313547 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
3548 frame->identifier(),
3549 ds->request().url(),
3550 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:173551}
3552
[email protected]310ebd6302011-10-10 19:06:283553void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173554 WebFrame* frame, bool is_new_navigation) {
3555 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:073556 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:173557 // update the ExtraData on the datasource so that others who read the
3558 // ExtraData will get the new NavigationState. Similarly, if we did not
3559 // initiate this navigation, then we need to take care to reset any pre-
3560 // existing navigation state to a content-initiated navigation state.
3561 // DidCreateDataSource conveniently takes care of this for us.
3562 didCreateDataSource(frame, frame->dataSource());
3563
[email protected]007733c2011-11-17 00:34:073564 DocumentState* document_state =
3565 DocumentState::FromDataSource(frame->dataSource());
3566 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:093567 new_state->set_was_within_same_page(true);
3568
[email protected]3d9689372009-09-10 04:29:173569 didCommitProvisionalLoad(frame, is_new_navigation);
3570
[email protected]750fcf872011-08-03 23:10:473571 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
3572 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:173573}
3574
[email protected]310ebd6302011-10-10 19:06:283575void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313576 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593577}
3578
[email protected]310ebd6302011-10-10 19:06:283579void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:173580 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3581 // Ignore
3582}
3583
[email protected]310ebd6302011-10-10 19:06:283584void RenderViewImpl::willSendRequest(WebFrame* frame,
3585 unsigned identifier,
3586 WebURLRequest& request,
3587 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303588 WebFrame* top_frame = frame->top();
3589 if (!top_frame)
3590 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513591 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3592 WebDataSource* top_data_source = top_frame->dataSource();
3593 WebDataSource* data_source =
3594 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:223595
[email protected]e9ff79c2012-10-19 21:31:263596 PageTransition transition_type = PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:073597 DocumentState* document_state = DocumentState::FromDataSource(data_source);
[email protected]def55e022012-07-26 01:15:293598 DCHECK(document_state);
[email protected]007733c2011-11-17 00:34:073599 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e1ed5a12012-08-08 19:57:443600 transition_type = navigation_state->transition_type();
3601
3602 GURL request_url(request.url());
3603 GURL new_url;
[email protected]e9ff79c2012-10-19 21:31:263604 if (GetContentClient()->renderer()->WillSendRequest(
[email protected]e1ed5a12012-08-08 19:57:443605 frame, transition_type, request_url, &new_url)) {
3606 request.setURL(WebURL(new_url));
3607 }
3608
[email protected]def55e022012-07-26 01:15:293609 if (document_state->is_cache_policy_override_set())
3610 request.setCachePolicy(document_state->cache_policy_override());
[email protected]8a3125a712010-08-09 18:58:513611
[email protected]ca662822012-05-11 17:53:593612 WebKit::WebReferrerPolicy referrer_policy;
3613 if (document_state && document_state->is_referrer_policy_set()) {
3614 referrer_policy = document_state->referrer_policy();
3615 document_state->clear_referrer_policy();
3616 } else {
3617 referrer_policy = frame->document().referrerPolicy();
3618 }
3619
[email protected]e372f3d2012-07-17 19:16:443620 // The request's extra data may indicate that we should set a custom user
3621 // agent. This needs to be done here, after WebKit is through with setting the
3622 // user agent on its own.
3623 WebString custom_user_agent;
3624 if (request.extraData()) {
3625 webkit_glue::WebURLRequestExtraDataImpl* old_extra_data =
3626 static_cast<webkit_glue::WebURLRequestExtraDataImpl*>(
3627 request.extraData());
3628 custom_user_agent = old_extra_data->custom_user_agent();
3629
3630 if (!custom_user_agent.isNull()) {
3631 if (custom_user_agent.isEmpty())
3632 request.clearHTTPHeaderField("User-Agent");
3633 else
3634 request.setHTTPHeaderField("User-Agent", custom_user_agent);
3635 }
3636 }
3637
[email protected]91043a8232011-11-04 16:41:193638 request.setExtraData(
[email protected]ca662822012-05-11 17:53:593639 new RequestExtraData(referrer_policy,
[email protected]e372f3d2012-07-17 19:16:443640 custom_user_agent,
[email protected]537fbe02011-11-24 00:58:063641 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:193642 frame->identifier(),
3643 frame->parent() == top_frame,
3644 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]80744782012-05-04 01:47:003645 navigation_state->allow_download(),
[email protected]4ad5d77d2011-12-03 02:00:483646 transition_type,
3647 navigation_state->transferred_request_child_id(),
3648 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:573649
[email protected]007733c2011-11-17 00:34:073650 DocumentState* top_document_state =
3651 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:573652 // TODO(gavinp): separate out prefetching and prerender field trials
3653 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:073654 if (top_document_state &&
[email protected]925dec1c2012-05-18 05:09:003655 request.targetType() == WebURLRequest::TargetIsPrefetch)
[email protected]007733c2011-11-17 00:34:073656 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513657
[email protected]3d9689372009-09-10 04:29:173658 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133659 request.setHasUserGesture(frame->isProcessingUserGesture());
3660
[email protected]0a8db0d2011-04-13 15:15:403661 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:133662 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:173663}
3664
[email protected]310ebd6302011-10-10 19:06:283665void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173666 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493667
[email protected]3d9689372009-09-10 04:29:173668 // Only do this for responses that correspond to a provisional data source
3669 // of the top-most frame. If we have a provisional data source, then we
3670 // can't have any sub-resources yet, so we know that this response must
3671 // correspond to a frame load.
3672 if (!frame->provisionalDataSource() || frame->parent())
3673 return;
3674
3675 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083676 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173677 if (frame->isViewSourceModeEnabled())
3678 return;
3679
[email protected]007733c2011-11-17 00:34:073680 DocumentState* document_state =
3681 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083682 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533683
[email protected]972ebdff2010-06-10 22:59:073684 // Record page load flags.
[email protected]007733c2011-11-17 00:34:073685 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3686 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]b9fd01ba2012-02-28 01:50:403687 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
3688 if (extra_data) {
3689 document_state->set_npn_negotiated_protocol(
3690 extra_data->npn_negotiated_protocol());
3691 }
[email protected]007733c2011-11-17 00:34:073692 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:573693 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:073694 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3695 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093696 // Whether or not the http status code actually corresponds to an error is
3697 // only checked when the page is done loading, if |use_error_page| is
3698 // still true.
[email protected]007733c2011-11-17 00:34:073699 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173700}
3701
[email protected]310ebd6302011-10-10 19:06:283702void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173703 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:073704 DocumentState* document_state =
3705 DocumentState::FromDataSource(frame->dataSource());
3706 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173707 return;
3708
[email protected]7bfc153f2011-09-23 22:00:203709 // Do not show error page when DevTools is attached.
3710 if (devtools_agent_->IsAttached())
3711 return;
3712
[email protected]06333afe2011-02-24 14:55:093713 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:073714 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:083715 if (http_status_code == 404) {
3716 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413717 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173718
[email protected]b6cb3a842011-06-24 18:28:413719 const GURL& error_page_url =
3720 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093721 if (error_page_url.is_valid()) {
3722 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473723 original_error.domain = "http";
3724 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413725 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173726
[email protected]007733c2011-11-17 00:34:073727 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093728 new AltErrorPageResourceFetcher(
3729 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:083730 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3731 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093732 return;
3733 }
3734 }
[email protected]3d9689372009-09-10 04:29:173735
[email protected]e6a2ce52011-10-08 01:40:133736 std::string error_domain;
[email protected]e9ff79c2012-10-19 21:31:263737 if (GetContentClient()->renderer()->HasErrorPage(
[email protected]e6a2ce52011-10-08 01:40:133738 http_status_code, &error_domain)) {
3739 WebURLError error;
3740 error.unreachableURL = frame->document().url();
3741 error.domain = WebString::fromUTF8(error_domain);
3742 error.reason = http_status_code;
3743
3744 LoadNavigationErrorPage(
3745 frame, frame->dataSource()->request(), error, std::string(), true);
3746 }
[email protected]3d9689372009-09-10 04:29:173747}
3748
[email protected]310ebd6302011-10-10 19:06:283749void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173750 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3751 // Ignore
3752}
3753
[email protected]310ebd6302011-10-10 19:06:283754void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173755 WebFrame* frame, const WebURLRequest& request,
3756 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003757 // The recipients of this message have no use for data: URLs: they don't
3758 // affect the page's insecure content list and are not in the disk cache. To
3759 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3760 // filter them out here.
3761 GURL url(request.url());
3762 if (url.SchemeIs("data"))
3763 return;
3764
[email protected]3d9689372009-09-10 04:29:173765 // Let the browser know we loaded a resource from the memory cache. This
3766 // message is needed to display the correct SSL indicators.
3767 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3768 routing_id_,
[email protected]84703292011-10-28 20:44:003769 url,
[email protected]70435962011-08-02 20:13:283770 response.securityInfo(),
3771 request.httpMethod().utf8(),
[email protected]6d6cfb3a2012-05-23 22:53:183772 response.mimeType().utf8(),
[email protected]70435962011-08-02 20:13:283773 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173774}
3775
[email protected]310ebd6302011-10-10 19:06:283776void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293777 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3778}
3779
[email protected]310ebd6302011-10-10 19:06:283780void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023781 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293782 Send(new ViewHostMsg_DidRunInsecureContent(
3783 routing_id_,
[email protected]92771112011-01-20 00:13:023784 origin.toString().utf8(),
3785 target));
[email protected]e3d60e5d2009-09-25 21:08:293786}
3787
[email protected]310ebd6302011-10-10 19:06:283788void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173789 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3790}
3791
[email protected]310ebd6302011-10-10 19:06:283792void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3793 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583794 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283795 int world_id) {
[email protected]e9ff79c2012-10-19 21:31:263796 GetContentClient()->renderer()->DidCreateScriptContext(
[email protected]a00fe692012-02-27 05:52:583797 frame, context, extension_group, world_id);
[email protected]7a137c9d2012-10-16 20:41:203798
3799 intents_host_->DidCreateScriptContext(
3800 frame, context, extension_group, world_id);
[email protected]a00fe692012-02-27 05:52:583801}
3802
[email protected]310ebd6302011-10-10 19:06:283803void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3804 v8::Handle<v8::Context> context,
3805 int world_id) {
[email protected]e9ff79c2012-10-19 21:31:263806 GetContentClient()->renderer()->WillReleaseScriptContext(
[email protected]5bc10932011-09-21 21:03:303807 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283808}
3809
[email protected]310ebd6302011-10-10 19:06:283810void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073811 // We don't always want to send the change messages over IPC, only if we've
3812 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3813 // message.
3814 if (!send_preferred_size_changes_ || !webview())
3815 return;
3816
[email protected]705243f2010-05-05 19:58:073817 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3818 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533819
3820 // In the presence of zoom, these sizes are still reported as if unzoomed,
3821 // so we need to adjust.
3822 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3823 size.set_width(static_cast<int>(size.width() * zoom_factor));
3824 size.set_height(static_cast<int>(size.height() * zoom_factor));
3825
[email protected]705243f2010-05-05 19:58:073826 if (size == preferred_size_)
3827 return;
[email protected]c27324b2009-11-19 22:44:293828
[email protected]705243f2010-05-05 19:58:073829 preferred_size_ = size;
3830 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3831 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173832}
3833
[email protected]1842fe22012-08-13 23:24:353834WebGraphicsContext3D* RenderViewImpl::CreateGraphicsContext3D(
3835 const WebGraphicsContext3D::Attributes& attributes) {
3836 if (!webview())
3837 return NULL;
3838
3839 if (GetGuestToEmbedderChannel()) {
3840 WebGraphicsContext3DCommandBufferImpl* context =
3841 GetGuestToEmbedderChannel()->CreateWebGraphicsContext3D(
3842 this, attributes, false);
3843 if (!guest_pp_instance()) {
3844 guest_uninitialized_context_ = context;
3845 guest_attributes_ = attributes;
3846 }
3847 return context;
3848 }
3849
3850 // The WebGraphicsContext3DInProcessImpl code path is used for
3851 // layout tests (though not through this code) as well as for
3852 // debugging and bringing up new ports.
3853 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
3854 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
3855 attributes, true);
3856 } else {
3857 GURL url;
3858 if (webview()->mainFrame())
3859 url = GURL(webview()->mainFrame()->document().url());
3860 else
[email protected]f89e173a2012-08-24 01:12:263861 url = GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]1842fe22012-08-13 23:24:353862
3863 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
3864 new WebGraphicsContext3DCommandBufferImpl(
3865 surface_id(),
3866 url,
3867 RenderThreadImpl::current(),
3868 AsWeakPtr()));
3869
3870 if (!context->Initialize(
3871 attributes,
3872 false /* bind generates resources */,
[email protected]e9ff79c2012-10-19 21:31:263873 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
[email protected]1842fe22012-08-13 23:24:353874 return NULL;
3875 return context.release();
3876 }
3877}
3878
[email protected]0720b532012-08-28 19:23:373879// The browser process needs to know the shape of the tree, as well as the names
3880// and ids of all frames. This allows it to properly route JavaScript messages
3881// across processes and frames. The serialization format is described in the
3882// comments of the ViewMsg_FrameTreeUpdated message.
3883// This function sends those updates to the browser and updates the RVH
3884// corresponding to this object. It must be called on any events that modify
3885// the tree structure or the names of any frames.
3886void RenderViewImpl::SendUpdatedFrameTree(
3887 WebKit::WebFrame* exclude_frame_subtree) {
[email protected]e12dbe6f2012-10-04 22:11:193888 // TODO(nasko): Frame tree updates are causing issues with postMessage, as
3889 // described in http://crbug.com/153701. Disable them until a proper fix is
3890 // in place.
[email protected]0720b532012-08-28 19:23:373891}
3892
3893void RenderViewImpl::CreateFrameTree(WebKit::WebFrame* frame,
3894 DictionaryValue* frame_tree) {
[email protected]e12dbe6f2012-10-04 22:11:193895 // TODO(nasko): Remove once http://crbug.com/153701 is fixed.
3896 DCHECK(false);
[email protected]0720b532012-08-28 19:23:373897 NavigateToSwappedOutURL(frame);
3898
3899 string16 name;
[email protected]e9ff79c2012-10-19 21:31:263900 if (frame_tree->GetString(kFrameTreeNodeNameKey, &name) && !name.empty())
[email protected]0720b532012-08-28 19:23:373901 frame->setName(name);
[email protected]0720b532012-08-28 19:23:373902
3903 int remote_id;
[email protected]e9ff79c2012-10-19 21:31:263904 if (frame_tree->GetInteger(kFrameTreeNodeIdKey, &remote_id))
[email protected]0720b532012-08-28 19:23:373905 active_frame_id_map_.insert(std::pair<int, int>(frame->identifier(),
3906 remote_id));
3907
3908 ListValue* children;
[email protected]e9ff79c2012-10-19 21:31:263909 if (!frame_tree->GetList(kFrameTreeNodeSubtreeKey, &children))
[email protected]0720b532012-08-28 19:23:373910 return;
3911
[email protected]5fa9b36b2012-09-21 18:14:273912 // Create an invisible iframe tree in the swapped out page.
[email protected]0720b532012-08-28 19:23:373913 base::DictionaryValue* child;
3914 for (size_t i = 0; i < children->GetSize(); ++i) {
3915 if (!children->GetDictionary(i, &child))
3916 continue;
3917 WebElement element = frame->document().createElement("iframe");
[email protected]5fa9b36b2012-09-21 18:14:273918 element.setAttribute("width", "0");
3919 element.setAttribute("height", "0");
3920 element.setAttribute("frameBorder", "0");
[email protected]0720b532012-08-28 19:23:373921 if (frame->document().body().appendChild(element)) {
3922 WebFrame* subframe = WebFrame::fromFrameOwnerElement(element);
3923 if (subframe)
3924 CreateFrameTree(subframe, child);
3925 } else {
3926 LOG(ERROR) << "Failed to append created iframe element.";
3927 }
3928 }
3929}
3930
[email protected]d1a59e42012-10-03 18:05:353931WebKit::WebFrame* RenderViewImpl::GetFrameByRemoteID(int remote_frame_id) {
3932 std::map<int, int>::const_iterator it = active_frame_id_map_.begin();
3933 for (; it != active_frame_id_map_.end(); ++it) {
3934 if (it->second == remote_frame_id)
3935 return FindFrameByID(webview()->mainFrame(), it->first);
3936 }
3937 return NULL;
[email protected]0720b532012-08-28 19:23:373938}
3939
[email protected]273558fb2012-01-12 15:03:513940void RenderViewImpl::EnsureMediaStreamImpl() {
[email protected]7082fb942012-05-16 23:44:593941 if (!RenderThreadImpl::current()) // Will be NULL during unit tests.
[email protected]08381562012-05-15 20:55:403942 return;
3943
[email protected]4fb0f202012-05-30 22:44:533944#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:513945 if (!media_stream_dispatcher_)
3946 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3947
[email protected]1bc65a42012-04-23 09:31:253948 if (!media_stream_impl_) {
[email protected]273558fb2012-01-12 15:03:513949 media_stream_impl_ = new MediaStreamImpl(
[email protected]1bc65a42012-04-23 09:31:253950 this,
[email protected]273558fb2012-01-12 15:03:513951 media_stream_dispatcher_,
[email protected]273558fb2012-01-12 15:03:513952 RenderThreadImpl::current()->video_capture_impl_manager(),
[email protected]6ee10bd2012-09-13 09:01:533953 RenderThreadImpl::current()->GetMediaStreamDependencyFactory());
[email protected]273558fb2012-01-12 15:03:513954 }
[email protected]5b87e782012-02-09 18:19:323955#endif
[email protected]273558fb2012-01-12 15:03:513956}
3957
[email protected]310ebd6302011-10-10 19:06:283958void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3959 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313960 if (webview()->mainFrame() != frame)
3961 return;
3962 WebView* frameView = frame->view();
3963 if (!frameView)
3964 return;
3965
3966 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3967 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3968
3969 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3970 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3971 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3972 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3973
3974 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3975 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3976 }
3977}
3978
[email protected]310ebd6302011-10-10 19:06:283979void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313980 WebSize offset = frame->scrollOffset();
3981 WebSize minimum_offset = frame->minimumScrollOffset();
3982 WebSize maximum_offset = frame->maximumScrollOffset();
3983
3984 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3985 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3986
3987 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3988 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3989 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3990 routing_id_, is_pinned_to_left, is_pinned_to_right));
3991
3992 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3993 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3994 }
3995}
3996
[email protected]310ebd6302011-10-10 19:06:283997void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493998 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313999
4000 if (webview()->mainFrame() == frame)
4001 UpdateScrollState(frame);
[email protected]2b942c332012-04-25 16:26:264002
4003 FOR_EACH_OBSERVER(
4004 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]dd6afca2011-08-13 03:44:314005}
4006
[email protected]4d0f8182012-10-19 23:14:474007#if defined(OS_ANDROID)
4008void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebFrame* frame) {
4009 if (frame != webview()->mainFrame())
4010 return;
4011
4012 // Update body background color if necessary.
4013 SkColor bg_color = webwidget_->backgroundColor();
4014
4015 // If not initialized, default to white. Note that 0 is different from black
4016 // as black still has alpha 0xFF.
4017 if (!bg_color)
4018 bg_color = SK_ColorWHITE;
4019
4020 if (bg_color != body_background_color_) {
4021 body_background_color_ = bg_color;
4022 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id_, bg_color));
4023 }
4024}
4025#endif
4026
[email protected]55750b32012-09-21 14:05:034027void RenderViewImpl::SendFindReply(int request_id,
4028 int match_count,
4029 int ordinal,
4030 const WebRect& selection_rect,
4031 bool final_status_update) {
4032#if defined(OS_ANDROID)
4033 if (synchronous_find_reply_message_.get()) {
4034 if (final_status_update) {
4035 ViewMsg_SynchronousFind::WriteReplyParams(
4036 synchronous_find_reply_message_.get(),
4037 match_count,
4038 match_count ? synchronous_find_active_match_ordinal_ : 0);
4039 Send(synchronous_find_reply_message_.release());
4040 }
4041 return;
4042 }
4043#endif
4044
4045 Send(new ViewHostMsg_Find_Reply(routing_id_,
4046 request_id,
4047 match_count,
4048 selection_rect,
4049 ordinal,
4050 final_status_update));
4051}
4052
4053void RenderViewImpl::reportFindInPageMatchCount(int request_id,
4054 int count,
[email protected]310ebd6302011-10-10 19:06:284055 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:114056 int active_match_ordinal = -1; // -1 = don't update active match ordinal
4057 if (!count)
4058 active_match_ordinal = 0;
4059
[email protected]55750b32012-09-21 14:05:034060 // Send the search result over to the browser process.
4061 SendFindReply(request_id,
4062 count,
4063 active_match_ordinal,
4064 gfx::Rect(),
4065 final_update);
[email protected]8922e1f2009-10-03 05:01:264066}
4067
[email protected]310ebd6302011-10-10 19:06:284068void RenderViewImpl::reportFindInPageSelection(int request_id,
4069 int active_match_ordinal,
4070 const WebRect& selection_rect) {
[email protected]55750b32012-09-21 14:05:034071#if defined(OS_ANDROID)
4072 // If this was a SynchronousFind request, we need to remember the ordinal
4073 // value here for replying when reportFindInPageMatchCount is called.
4074 if (synchronous_find_reply_message_.get()) {
4075 synchronous_find_active_match_ordinal_ = active_match_ordinal;
4076 return;
4077 }
4078#endif
4079
4080 SendFindReply(request_id,
4081 -1,
4082 active_match_ordinal,
4083 selection_rect,
4084 false);
[email protected]8922e1f2009-10-03 05:01:264085}
4086
[email protected]310ebd6302011-10-10 19:06:284087void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:224088 WebFrame* frame,
4089 WebFileSystem::Type type,
4090 long long size,
[email protected]d275d7a2010-11-03 01:34:494091 bool create,
[email protected]2b06a992010-08-21 05:48:224092 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:084093 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:224094
[email protected]b6cb3a842011-06-24 18:28:414095 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564096 if (origin.isUnique()) {
4097 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:084098 callbacks->didFail(WebKit::WebFileErrorAbort);
4099 return;
4100 }
[email protected]2b06a992010-08-21 05:48:224101
[email protected]c5a272d2010-09-27 18:37:084102 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
4103 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:494104 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:224105}
4106
[email protected]d5e08552012-08-02 21:43:404107void RenderViewImpl::deleteFileSystem(
4108 WebFrame* frame,
4109 WebFileSystem::Type type ,
4110 WebFileSystemCallbacks* callbacks) {
4111 DCHECK(callbacks);
4112
4113 WebSecurityOrigin origin = frame->document().securityOrigin();
4114 if (origin.isUnique()) {
4115 // Unique origins cannot store persistent state.
4116 callbacks->didSucceed();
4117 return;
4118 }
4119
4120 ChildThread::current()->file_system_dispatcher()->DeleteFileSystem(
4121 GURL(origin.toString()),
4122 static_cast<fileapi::FileSystemType>(type),
4123 new WebFileSystemCallbackDispatcher(callbacks));
4124}
4125
[email protected]310ebd6302011-10-10 19:06:284126void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:404127 WebFrame* frame,
4128 WebStorageQuotaType type,
4129 WebStorageQuotaCallbacks* callbacks) {
4130 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:414131 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564132 if (origin.isUnique()) {
4133 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:404134 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
4135 return;
4136 }
4137 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:534138 GURL(origin.toString()),
4139 static_cast<quota::StorageType>(type),
4140 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:404141}
4142
[email protected]310ebd6302011-10-10 19:06:284143void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:404144 WebFrame* frame,
4145 WebStorageQuotaType type,
4146 unsigned long long requested_size,
4147 WebStorageQuotaCallbacks* callbacks) {
4148 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:414149 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564150 if (origin.isUnique()) {
4151 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:404152 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
4153 return;
4154 }
4155 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:534156 routing_id(), GURL(origin.toString()),
4157 static_cast<quota::StorageType>(type), requested_size,
4158 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:404159}
4160
[email protected]8b5af492011-11-28 21:50:584161void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:154162 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]3a3b75a2012-06-01 08:38:364163 webkit_glue::WebIntentServiceData data(service);
4164 if (data.title.empty())
4165 data.title = webview()->mainFrame()->document().title();
4166 bool user_gesture = frame->isProcessingUserGesture();
[email protected]8b5af492011-11-28 21:50:584167 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
[email protected]3a3b75a2012-06-01 08:38:364168 data,
4169 user_gesture));
[email protected]8b5af492011-11-28 21:50:584170}
4171
[email protected]ffc8bed2012-01-21 01:23:154172void RenderViewImpl::dispatchIntent(
4173 WebFrame* frame, const WebIntentRequest& intentRequest) {
4174 webkit_glue::WebIntentData intent_data(intentRequest.intent());
[email protected]4e1eb3392012-05-18 00:08:054175
4176 // See WebMessagePortChannelImpl::postMessage() and ::OnMessagedQueued()
4177 WebKit::WebMessagePortChannelArray* channels =
4178 intentRequest.intent().messagePortChannelsRelease();
4179 if (channels) {
4180 for (size_t i = 0; i < channels->size(); ++i) {
4181 WebMessagePortChannelImpl* webchannel =
4182 static_cast<WebMessagePortChannelImpl*>((*channels)[i]);
4183 intent_data.message_port_ids.push_back(webchannel->message_port_id());
4184 DCHECK(intent_data.message_port_ids[i] != MSG_ROUTING_NONE);
4185 }
4186 delete channels;
4187 }
4188
[email protected]ffc8bed2012-01-21 01:23:154189 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:584190 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:154191 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:584192}
4193
[email protected]f546640b2012-05-15 00:03:494194bool RenderViewImpl::willCheckAndDispatchMessageEvent(
[email protected]0720b532012-08-28 19:23:374195 WebKit::WebFrame* sourceFrame,
4196 WebKit::WebFrame* targetFrame,
[email protected]f546640b2012-05-15 00:03:494197 WebKit::WebSecurityOrigin target_origin,
4198 WebKit::WebDOMMessageEvent event) {
4199 if (!is_swapped_out_)
4200 return false;
4201
4202 ViewMsg_PostMessage_Params params;
4203 params.data = event.data().toString();
4204 params.source_origin = event.origin();
4205 if (!target_origin.isNull())
4206 params.target_origin = target_origin.toString();
4207
4208 // Include the routing ID for the source frame, which the browser process
4209 // will translate into the routing ID for the equivalent frame in the target
4210 // process.
[email protected]f546640b2012-05-15 00:03:494211 params.source_routing_id = MSG_ROUTING_NONE;
[email protected]0720b532012-08-28 19:23:374212 RenderViewImpl* source_view = FromWebView(sourceFrame->view());
[email protected]f546640b2012-05-15 00:03:494213 if (source_view)
4214 params.source_routing_id = source_view->routing_id();
[email protected]0720b532012-08-28 19:23:374215 params.source_frame_id = sourceFrame->identifier();
4216
4217 // Include the process, route, and frame IDs of the target frame. This allows
4218 // the browser to detect races between this message being sent and the target
4219 // frame no longer being valid.
4220 params.target_process_id = target_process_id_;
4221 params.target_routing_id = target_routing_id_;
4222
4223 std::map<int,int>::iterator it = active_frame_id_map_.find(
4224 targetFrame->identifier());
4225 if (it != active_frame_id_map_.end()) {
4226 params.target_frame_id = it->second;
4227 } else {
4228 params.target_frame_id = 0;
4229 }
[email protected]f546640b2012-05-15 00:03:494230
4231 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params));
4232 return true;
4233}
4234
[email protected]5fa3a062012-03-21 15:39:344235void RenderViewImpl::willOpenSocketStream(
4236 WebSocketStreamHandle* handle) {
4237 SocketStreamHandleData::AddToHandle(handle, routing_id_);
4238}
4239
[email protected]ccee4862012-10-03 18:34:264240void RenderViewImpl::willStartUsingPeerConnectionHandler(
4241 WebKit::WebFrame* frame, WebKit::WebRTCPeerConnectionHandler* handler) {
4242#if defined(ENABLE_WEBRTC)
4243 static_cast<RTCPeerConnectionHandler*>(handler)->associateWithFrame(frame);
4244#endif
4245}
4246
[email protected]bf70edce2012-06-20 22:32:224247WebKit::WebString RenderViewImpl::userAgentOverride(
4248 WebKit::WebFrame* frame,
4249 const WebKit::WebURL& url) {
4250 if (!webview() || !webview()->mainFrame() ||
4251 renderer_preferences_.user_agent_override.empty()) {
4252 return WebKit::WebString();
4253 }
4254
4255 // If we're in the middle of committing a load, the data source we need
4256 // will still be provisional.
4257 WebFrame* main_frame = webview()->mainFrame();
4258 WebDataSource* data_source = NULL;
4259 if (main_frame->provisionalDataSource())
4260 data_source = main_frame->provisionalDataSource();
4261 else
4262 data_source = main_frame->dataSource();
4263
4264 DocumentState* document_state =
4265 data_source ? DocumentState::FromDataSource(data_source) : NULL;
4266 if (document_state && document_state->is_overriding_user_agent())
4267 return WebString::fromUTF8(renderer_preferences_.user_agent_override);
4268 else
4269 return WebKit::WebString();
4270}
4271
[email protected]18d5be92011-07-25 18:00:194272// WebKit::WebPageSerializerClient implementation ------------------------------
4273
[email protected]310ebd6302011-10-10 19:06:284274void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:194275 const WebURL& frame_url,
4276 const WebCString& data,
4277 WebPageSerializerClient::PageSerializationStatus status) {
4278 Send(new ViewHostMsg_SendSerializedHtmlData(
4279 routing_id(),
4280 frame_url,
4281 data.data(),
4282 static_cast<int32>(status)));
4283}
4284
[email protected]e9ff79c2012-10-19 21:31:264285// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:314286
[email protected]310ebd6302011-10-10 19:06:284287bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:314288 return RenderWidget::Send(message);
4289}
4290
[email protected]82114f52012-03-20 22:53:414291int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:314292 return routing_id_;
4293}
4294
[email protected]82114f52012-03-20 22:53:414295int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:314296 return page_id_;
4297}
4298
[email protected]82114f52012-03-20 22:53:414299gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:314300 return size();
4301}
4302
[email protected]82114f52012-03-20 22:53:414303WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:314304 return webkit_preferences_;
4305}
4306
[email protected]82114f52012-03-20 22:53:414307WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:314308 return webview();
4309}
4310
[email protected]82114f52012-03-20 22:53:414311WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:314312 if (!webview())
4313 return WebNode();
4314 WebFrame* focused_frame = webview()->focusedFrame();
4315 if (focused_frame) {
4316 WebDocument doc = focused_frame->document();
4317 if (!doc.isNull())
4318 return doc.focusedNode();
4319 }
4320
4321 return WebNode();
4322}
4323
[email protected]82114f52012-03-20 22:53:414324WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:314325 return context_menu_node_;
4326}
4327
[email protected]2a84f9d2012-06-05 21:50:434328bool RenderViewImpl::IsEditableNode(const WebNode& node) const {
4329 if (node.isNull())
4330 return false;
4331
4332 if (node.isContentEditable())
4333 return true;
4334
4335 if (node.isElementNode()) {
4336 const WebElement& element = node.toConst<WebElement>();
4337 if (element.isTextFormControlElement())
4338 return true;
4339
4340 // Also return true if it has an ARIA role of 'textbox'.
4341 for (unsigned i = 0; i < element.attributeCount(); ++i) {
4342 if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) {
4343 if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox"))
4344 return true;
4345 break;
4346 }
[email protected]a2ef54c2011-10-10 16:20:314347 }
4348 }
[email protected]2a84f9d2012-06-05 21:50:434349
4350 return false;
[email protected]a2ef54c2011-10-10 16:20:314351}
4352
[email protected]468e4902012-05-23 01:49:314353void RenderViewImpl::GuestReady(PP_Instance instance) {
4354 guest_pp_instance_ = instance;
4355 if (guest_uninitialized_context_) {
[email protected]7900bfdb2012-05-24 19:31:244356 bool success = GetGuestToEmbedderChannel()->CreateGraphicsContext(
[email protected]468e4902012-05-23 01:49:314357 guest_uninitialized_context_,
4358 guest_attributes_,
4359 false,
4360 this);
4361 DCHECK(success);
[email protected]7900bfdb2012-05-24 19:31:244362 CompleteInit(host_window_);
4363 guest_uninitialized_context_ = NULL;
[email protected]468e4902012-05-23 01:49:314364 }
[email protected]468e4902012-05-23 01:49:314365}
4366
4367webkit::ppapi::WebPluginImpl* RenderViewImpl::CreateBrowserPlugin(
4368 const IPC::ChannelHandle& channel_handle,
4369 int guest_process_id,
4370 const WebKit::WebPluginParams& params) {
4371 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
4372 pepper_delegate_.CreateBrowserPluginModule(channel_handle,
4373 guest_process_id));
4374 return new webkit::ppapi::WebPluginImpl(
4375 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
4376}
4377
[email protected]310ebd6302011-10-10 19:06:284378WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:314379 WebKit::WebFrame* frame,
4380 const webkit::WebPluginInfo& info,
[email protected]82114f52012-03-20 22:53:414381 const WebKit::WebPluginParams& params) {
[email protected]a2ef54c2011-10-10 16:20:314382 bool pepper_plugin_was_registered = false;
4383 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
4384 pepper_delegate_.CreatePepperPluginModule(info,
4385 &pepper_plugin_was_registered));
4386 if (pepper_plugin_was_registered) {
4387 if (!pepper_module)
4388 return NULL;
4389 return new webkit::ppapi::WebPluginImpl(
4390 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
4391 }
4392
[email protected]3e076a82012-09-11 19:12:364393#if defined(USE_AURA) && !defined(OS_WIN)
[email protected]34b27e442012-01-20 20:07:414394 return NULL;
4395#else
[email protected]a2ef54c2011-10-10 16:20:314396 return new webkit::npapi::WebPluginImpl(
4397 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:414398#endif
[email protected]a2ef54c2011-10-10 16:20:314399}
4400
[email protected]310ebd6302011-10-10 19:06:284401void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
4402 const string16& jscript,
4403 int id,
4404 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:314405 v8::Handle<v8::Value> result;
4406 WebFrame* web_frame = GetChildFrame(frame_xpath);
4407 if (web_frame)
4408 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
4409 if (notify_result) {
4410 ListValue list;
4411 if (!result.IsEmpty() && web_frame) {
4412 v8::HandleScope handle_scope;
4413 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4414 v8::Context::Scope context_scope(context);
4415 V8ValueConverterImpl converter;
[email protected]3de391e82012-05-16 17:50:514416 converter.SetDateAllowed(true);
[email protected]e0658bc2012-09-17 04:05:244417 converter.SetRegExpAllowed(true);
4418 base::Value* result_value = converter.FromV8Value(result, context);
4419 list.Set(0, result_value ? result_value :
4420 base::Value::CreateNullValue());
[email protected]a2ef54c2011-10-10 16:20:314421 } else {
4422 list.Set(0, Value::CreateNullValue());
4423 }
4424 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
4425 }
4426}
4427
[email protected]310ebd6302011-10-10 19:06:284428bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:314429 return (!send_preferred_size_changes_ ||
4430 (disable_scrollbars_size_limit_.width() <= width ||
4431 disable_scrollbars_size_limit_.height() <= height));
4432}
4433
[email protected]82114f52012-03-20 22:53:414434int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:314435 return enabled_bindings_;
4436}
4437
[email protected]82114f52012-03-20 22:53:414438bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:314439 return send_content_state_immediately_;
4440}
4441
[email protected]82114f52012-03-20 22:53:414442float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:314443 return filtered_time_per_frame();
4444}
4445
[email protected]e9ff79c2012-10-19 21:31:264446int RenderViewImpl::ShowContextMenu(ContextMenuClient* client,
4447 const ContextMenuParams& params) {
[email protected]860ee642012-10-13 03:46:254448 DCHECK(client); // A null client means "internal" when we issue callbacks.
[email protected]e9ff79c2012-10-19 21:31:264449 ContextMenuParams our_params(params);
[email protected]860ee642012-10-13 03:46:254450 our_params.custom_context.request_id = pending_context_menus_.Add(client);
4451 Send(new ViewHostMsg_ContextMenu(routing_id_, our_params));
4452 return our_params.custom_context.request_id;
[email protected]a2ef54c2011-10-10 16:20:314453}
4454
[email protected]e0fd0eb2012-10-17 21:11:464455void RenderViewImpl::CancelContextMenu(int request_id) {
4456 DCHECK(pending_context_menus_.Lookup(request_id));
4457 pending_context_menus_.Remove(request_id);
4458}
4459
[email protected]82114f52012-03-20 22:53:414460WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:314461 return visibilityState();
4462}
4463
[email protected]310ebd6302011-10-10 19:06:284464void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
4465 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:314466 return runModalAlertDialog(frame, message);
4467}
4468
[email protected]310ebd6302011-10-10 19:06:284469void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:314470 WebKit::WebFrame* frame,
4471 const WebKit::WebURLRequest& request,
4472 WebKit::WebNavigationPolicy policy) {
4473 loadURLExternally(frame, request, policy);
4474}
4475
4476// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:514477
[email protected]310ebd6302011-10-10 19:06:284478webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:534479 const FilePath& file_path,
4480 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:204481 if (!PluginChannelHost::IsListening()) {
4482 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:594483 return NULL;
[email protected]94752ee2012-02-10 10:38:204484 }
[email protected]f103ab72009-09-02 17:10:594485
[email protected]00c39612010-03-06 02:53:284486 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:464487 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:324488#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:224489 return webkit::npapi::WebPluginDelegateImpl::Create(
4490 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:094491#else
[email protected]7398dcc2011-09-06 21:40:324492 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:224493 NOTIMPLEMENTED();
4494 return NULL;
[email protected]7b6616f2010-01-14 18:07:554495#endif
[email protected]f103ab72009-09-02 17:10:594496 }
4497
[email protected]4e0616e2010-05-28 14:55:534498 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:594499}
4500
[email protected]6ac77cb2012-05-01 14:49:014501WebKit::WebPlugin* RenderViewImpl::CreatePluginReplacement(
4502 const FilePath& file_path) {
[email protected]e9ff79c2012-10-19 21:31:264503 return GetContentClient()->renderer()->CreatePluginReplacement(
[email protected]6ac77cb2012-05-01 14:49:014504 this, file_path);
4505}
4506
[email protected]310ebd6302011-10-10 19:06:284507void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034508#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:274509 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:594510#endif
4511}
4512
[email protected]310ebd6302011-10-10 19:06:284513void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034514#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:274515 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:594516#endif
4517 CleanupWindowInPluginMoves(window);
4518}
4519
[email protected]310ebd6302011-10-10 19:06:284520void RenderViewImpl::DidMovePlugin(
4521 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:594522 SchedulePluginMove(move);
4523}
4524
[email protected]310ebd6302011-10-10 19:06:284525void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:594526 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524527 didStartLoading();
[email protected]f103ab72009-09-02 17:10:594528}
4529
[email protected]310ebd6302011-10-10 19:06:284530void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:594531 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524532 didStopLoading();
[email protected]f103ab72009-09-02 17:10:594533}
4534
[email protected]310ebd6302011-10-10 19:06:284535WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:514536 return &cookie_jar_;
4537}
4538
[email protected]5d65fe92012-06-02 00:48:554539void RenderViewImpl::DidPlay(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074540 Send(new ViewHostMsg_MediaNotification(routing_id_,
4541 reinterpret_cast<int64>(player),
4542 player->hasVideo(),
4543 player->hasAudio(),
4544 true));
4545}
4546
[email protected]5d65fe92012-06-02 00:48:554547void RenderViewImpl::DidPause(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074548 Send(new ViewHostMsg_MediaNotification(routing_id_,
4549 reinterpret_cast<int64>(player),
4550 player->hasVideo(),
4551 player->hasAudio(),
4552 false));
4553}
4554
[email protected]5d65fe92012-06-02 00:48:554555void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074556 DidPause(player);
4557}
4558
[email protected]310ebd6302011-10-10 19:06:284559void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:294560 if (!webview())
4561 return;
4562
[email protected]26aa0482009-09-30 16:55:274563 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:054564 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:294565}
4566
[email protected]310ebd6302011-10-10 19:06:284567void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:364568 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:004569 if (!frame)
4570 return;
[email protected]b781ff282011-08-20 06:19:364571
[email protected]e99ef6f2011-10-16 01:13:004572 string16 text;
4573 size_t offset;
[email protected]3c8c74c2012-03-15 07:34:524574 ui::Range range;
[email protected]e99ef6f2011-10-16 01:13:004575
[email protected]3c8c74c2012-03-15 07:34:524576 if (pepper_delegate_.IsPluginFocused()) {
4577 pepper_delegate_.GetSurroundingText(&text, &range);
[email protected]82114f52012-03-20 22:53:414578 offset = 0; // Pepper API does not support offset reporting.
[email protected]3c8c74c2012-03-15 07:34:524579 // TODO(kinaba): cut as needed.
[email protected]e99ef6f2011-10-16 01:13:004580 } else {
[email protected]3c8c74c2012-03-15 07:34:524581 size_t location, length;
4582 if (!webview()->caretOrSelectionRange(&location, &length))
4583 return;
4584
4585 range = ui::Range(location, location + length);
4586
4587 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
4588 // If current focused element is editable, we will send 100 more chars
4589 // before and after selection. It is for input method surrounding text
4590 // feature.
4591 if (location > kExtraCharsBeforeAndAfterSelection)
4592 offset = location - kExtraCharsBeforeAndAfterSelection;
4593 else
4594 offset = 0;
4595 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
4596 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
4597 if (!webrange.isNull())
4598 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
4599 } else {
4600 offset = location;
4601 text = frame->selectionAsText();
4602 // http://crbug.com/101435
4603 // In some case, frame->selectionAsText() returned text's length is not
4604 // equal to the length returned from webview()->caretOrSelectionRange().
4605 // So we have to set the range according to text.length().
4606 range.set_end(range.start() + text.length());
4607 }
[email protected]b781ff282011-08-20 06:19:364608 }
4609
[email protected]b781ff282011-08-20 06:19:364610 // Sometimes we get repeated didChangeSelection calls from webkit when
4611 // the selection hasn't actually changed. We don't want to report these
4612 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:004613 if (selection_text_offset_ != offset ||
4614 selection_range_ != range ||
4615 selection_text_ != text) {
4616 selection_text_ = text;
4617 selection_text_offset_ = offset;
4618 selection_range_ = range;
4619 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
4620 }
[email protected]b781ff282011-08-20 06:19:364621}
4622
[email protected]310ebd6302011-10-10 19:06:284623GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
4624 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554625 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294626 // If the URL that failed was secure, then the embedding web page was not
4627 // expecting a network attacker to be able to manipulate its contents. As
4628 // we fetch alternate error pages over HTTP, we would be allowing a network
4629 // attacker to manipulate the contents of the response if we tried to use
4630 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154631 return GURL();
initial.commit09911bf2008-07-26 23:55:294632 }
4633
4634 // Grab the base URL from the browser process.
4635 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154636 return GURL();
initial.commit09911bf2008-07-26 23:55:294637
4638 // Strip query params from the failed URL.
4639 GURL::Replacements remove_params;
4640 remove_params.ClearUsername();
4641 remove_params.ClearPassword();
4642 remove_params.ClearQuery();
4643 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554644 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504645 std::string spec_to_send = url_to_send.spec();
4646 // Notify link doctor of the url truncation by sending of "?" at the end.
4647 if (failed_url.has_query())
[email protected]82114f52012-03-20 22:53:414648 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294649
4650 // Construct the query params to send to link doctor.
4651 std::string params(alternate_error_page_url_.query());
4652 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:024653 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294654 params.append("&sourceid=chrome");
4655 params.append("&error=");
4656 switch (error_type) {
4657 case DNS_ERROR:
4658 params.append("dnserror");
4659 break;
4660
4661 case HTTP_404:
4662 params.append("http404");
4663 break;
4664
[email protected]5df266ac2008-10-15 19:50:134665 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334666 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134667 break;
4668
initial.commit09911bf2008-07-26 23:55:294669 default:
4670 NOTREACHED() << "unknown ErrorPageType";
4671 }
4672
4673 // OK, build the final url to return.
4674 GURL::Replacements link_doctor_params;
4675 link_doctor_params.SetQueryStr(params);
4676 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4677 return url;
4678}
4679
[email protected]310ebd6302011-10-10 19:06:284680GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:594681 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
4682 return GURL();
4683 else
4684 return creator_url_;
4685}
4686
[email protected]69ddf852012-02-21 23:21:314687GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
4688 WebDataSource* ds = frame->dataSource();
4689 if (ds->hasUnreachableURL())
4690 return ds->unreachableURL();
4691
4692 const WebURLRequest& request = ds->request();
4693 return request.url();
4694}
4695
[email protected]310ebd6302011-10-10 19:06:284696WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:274697 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:314698 web_ui_bindings_.reset(new WebUIBindings(
[email protected]e9ff79c2012-10-19 21:31:264699 static_cast<RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:464700 }
[email protected]c50008512011-02-03 01:17:274701 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:464702}
4703
[email protected]310ebd6302011-10-10 19:06:284704WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:014705 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494706}
4707
[email protected]55750b32012-09-21 14:05:034708void RenderViewImpl::OnFind(int request_id,
4709 const string16& search_text,
[email protected]310ebd6302011-10-10 19:06:284710 const WebFindOptions& options) {
[email protected]55750b32012-09-21 14:05:034711#if defined(OS_ANDROID)
4712 // Make sure any asynchronous messages do not disrupt an ongoing synchronous
4713 // find request as it might lead to deadlocks. Also, these should be safe to
4714 // ignore since they would belong to a previous find request.
4715 if (synchronous_find_reply_message_.get())
4716 return;
4717#endif
4718 Find(request_id, search_text, options);
4719}
4720
4721void RenderViewImpl::Find(int request_id,
4722 const string16& search_text,
4723 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274724 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494725
[email protected]872542532011-06-23 00:43:164726 // Check if the plugin still exists in the document.
4727 if (main_frame->document().isPluginDocument() &&
4728 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494729 if (options.findNext) {
4730 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014731 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494732 } else {
[email protected]55750b32012-09-21 14:05:034733 if (!GetWebPluginFromPluginDocument()->startFind(
[email protected]afdbd142010-07-10 08:01:234734 search_text, options.matchCase, request_id)) {
[email protected]e7c58a32010-08-13 19:47:114735 // Send "no results".
[email protected]55750b32012-09-21 14:05:034736 SendFindReply(request_id, 0, 0, gfx::Rect(), true);
[email protected]24a7f3c2010-03-25 08:26:494737 }
4738 }
4739 return;
4740 }
4741
[email protected]b4bb2502009-10-01 22:35:274742 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274743 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294744 WebFrame* search_frame = focused_frame; // start searching focused frame.
4745
4746 bool multi_frame = (frame_after_main != main_frame);
4747
4748 // If we have multiple frames, we don't want to wrap the search within the
4749 // frame, so we check here if we only have main_frame in the chain.
4750 bool wrap_within_frame = !multi_frame;
4751
[email protected]b3f2b912009-04-09 16:18:524752 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294753 bool result = false;
4754
[email protected]7830da3e2009-11-06 16:27:264755 // If something is selected when we start searching it means we cannot just
4756 // increment the current match ordinal; we need to re-generate it.
4757 WebRange current_selection = focused_frame->selectionRange();
4758
initial.commit09911bf2008-07-26 23:55:294759 do {
[email protected]dd7daa82009-08-10 05:46:454760 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594761 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294762
4763 if (!result) {
4764 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:224765 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294766
4767 // Find the next frame, but skip the invisible ones.
4768 do {
4769 // What is the next frame to search? (we might be going backwards). Note
4770 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594771 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274772 search_frame->traverseNext(true) :
4773 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454774 } while (!search_frame->hasVisibleContent() &&
4775 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294776
[email protected]884db412008-11-24 23:46:504777 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:224778 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294779
4780 // If we have multiple frames and we have wrapped back around to the
4781 // focused frame, we need to search it once more allowing wrap within
4782 // the frame, otherwise it will report 'no match' if the focused frame has
4783 // reported matches, but no frames after the focused_frame contain a
4784 // match for the search word(s).
4785 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454786 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594787 request_id, search_text, options, true, // Force wrapping.
4788 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294789 }
4790 }
4791
[email protected]26aa0482009-09-30 16:55:274792 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294793 } while (!result && search_frame != focused_frame);
4794
[email protected]7830da3e2009-11-06 16:27:264795 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294796 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454797 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294798 } else {
4799 // If nothing is found, set result to "0 of 0", otherwise, set it to
4800 // "-1 of 1" to indicate that we found at least one item, but we don't know
4801 // yet what is active.
4802 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4803 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294804
[email protected]4f3dc372009-02-24 00:10:294805 // If we find no matches then this will be our last status update.
4806 // Otherwise the scoping effort will send more results.
4807 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294808
[email protected]55750b32012-09-21 14:05:034809 SendFindReply(request_id, match_count, ordinal, selection_rect,
4810 final_status_update);
initial.commit09911bf2008-07-26 23:55:294811
initial.commit09911bf2008-07-26 23:55:294812 // Scoping effort begins, starting with the mainframe.
4813 search_frame = main_frame;
4814
[email protected]dd7daa82009-08-10 05:46:454815 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294816
4817 do {
4818 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454819 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294820
4821 // We don't start another scoping effort unless at least one match has
4822 // been found.
4823 if (result) {
4824 // Start new scoping request. If the scoping function determines that it
4825 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454826 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594827 search_text,
4828 options,
initial.commit09911bf2008-07-26 23:55:294829 true); // reset the tickmarks
4830 }
4831
4832 // Iterate to the next frame. The frame will not necessarily scope, for
4833 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274834 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294835 } while (search_frame != main_frame);
4836 }
4837}
4838
[email protected]e9ff79c2012-10-19 21:31:264839void RenderViewImpl::OnStopFinding(StopFindAction action) {
[email protected]55750b32012-09-21 14:05:034840#if defined(OS_ANDROID)
4841 // Make sure any asynchronous messages do not disrupt an ongoing synchronous
4842 // find request as it might lead to deadlocks. Also, these should be safe to
4843 // ignore since they would belong to a previous find request.
4844 if (synchronous_find_reply_message_.get())
4845 return;
4846#endif
4847
4848 StopFinding(action);
4849}
4850
[email protected]e9ff79c2012-10-19 21:31:264851void RenderViewImpl::StopFinding(StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:494852 WebView* view = webview();
4853 if (!view)
4854 return;
4855
4856 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:164857 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014858 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494859 return;
4860 }
4861
[email protected]e9ff79c2012-10-19 21:31:264862 bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:494863 if (clear_selection)
4864 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4865
4866 WebFrame* frame = view->mainFrame();
4867 while (frame) {
4868 frame->stopFinding(clear_selection);
4869 frame = frame->traverseNext(false);
4870 }
4871
[email protected]e9ff79c2012-10-19 21:31:264872 if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:494873 WebFrame* focused_frame = view->focusedFrame();
4874 if (focused_frame) {
4875 WebDocument doc = focused_frame->document();
4876 if (!doc.isNull()) {
4877 WebNode node = doc.focusedNode();
4878 if (!node.isNull())
4879 node.simulateClick();
4880 }
4881 }
4882 }
4883}
4884
[email protected]59363fc92012-09-05 03:46:314885#if defined(OS_ANDROID)
[email protected]55750b32012-09-21 14:05:034886void RenderViewImpl::OnSynchronousFind(int request_id,
4887 const string16& search_string,
4888 const WebFindOptions& options,
4889 IPC::Message* reply_msg) {
4890 // It is impossible for simultaneous blocking finds to occur.
4891 CHECK(!synchronous_find_reply_message_.get());
4892 synchronous_find_reply_message_.reset(reply_msg);
4893
4894 // Find next should be asynchronous in order to minimize blocking
4895 // the UI thread as much as possible.
4896 DCHECK(!options.findNext);
[email protected]e9ff79c2012-10-19 21:31:264897 StopFinding(STOP_FIND_ACTION_KEEP_SELECTION);
[email protected]55750b32012-09-21 14:05:034898 synchronous_find_active_match_ordinal_ = -1;
4899
4900 Find(request_id, search_string, options);
4901}
4902
[email protected]59363fc92012-09-05 03:46:314903void RenderViewImpl::OnActivateNearestFindResult(int request_id,
4904 float x, float y) {
4905 if (!webview())
4906 return;
4907
4908 WebFrame* main_frame = webview()->mainFrame();
4909 WebRect selection_rect;
4910 int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y),
4911 &selection_rect);
4912 if (ordinal == -1) {
4913 // Something went wrong, so send a no-op reply (force the main_frame to
4914 // report the current match count) in case the host is waiting for a
4915 // response due to rate-limiting).
4916 main_frame->increaseMatchCount(0, request_id);
4917 return;
4918 }
4919
[email protected]55750b32012-09-21 14:05:034920 SendFindReply(request_id,
4921 -1 /* number_of_matches */,
4922 ordinal,
4923 selection_rect,
4924 true /* final_update */);
[email protected]59363fc92012-09-05 03:46:314925}
4926
4927void RenderViewImpl::OnFindMatchRects(int current_version) {
4928 if (!webview())
4929 return;
4930
4931 WebFrame* main_frame = webview()->mainFrame();
4932 std::vector<gfx::RectF> match_rects;
4933
4934 int rects_version = main_frame->findMatchMarkersVersion();
4935 if (current_version != rects_version) {
4936 WebVector<WebFloatRect> web_match_rects;
4937 main_frame->findMatchRects(web_match_rects);
4938 match_rects.reserve(web_match_rects.size());
4939 for (size_t i = 0; i < web_match_rects.size(); ++i)
4940 match_rects.push_back(gfx::RectF(web_match_rects[i]));
4941 }
4942
4943 gfx::RectF active_rect = main_frame->activeFindMatchRect();
4944 Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_,
4945 rects_version,
4946 match_rects,
4947 active_rect));
4948}
4949#endif
4950
[email protected]e9ff79c2012-10-19 21:31:264951void RenderViewImpl::OnZoom(PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:514952 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4953 return;
4954
[email protected]258d31122010-05-09 10:59:414955 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:104956
[email protected]b75b8292010-10-01 07:28:254957 double old_zoom_level = webview()->zoomLevel();
4958 double zoom_level;
[email protected]e9ff79c2012-10-19 21:31:264959 if (zoom == PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:254960 zoom_level = 0;
4961 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4962 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:484963 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:254964 } else {
4965 // Either the user hit the zoom factor limit and thus the zoom level is now
4966 // not a whole number, or a plugin changed it to a custom value. We want
4967 // to go to the next whole number so that the user can always get back to
4968 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:484969 if ((old_zoom_level > 1 && zoom > 0) ||
4970 (old_zoom_level < 1 && zoom < 0)) {
4971 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:254972 } else {
4973 // We're going towards 100%, so first go to the next whole number.
4974 zoom_level = static_cast<int>(old_zoom_level);
4975 }
4976 }
[email protected]b75b8292010-10-01 07:28:254977 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:414978 zoomLevelChanged();
4979}
4980
[email protected]e9ff79c2012-10-19 21:31:264981void RenderViewImpl::OnZoomFactor(PageZoom zoom, int zoom_center_x,
4982 int zoom_center_y) {
[email protected]47578fa02011-11-02 19:34:414983 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
4984 kScalingIncrementForGesture);
4985}
4986
[email protected]e9ff79c2012-10-19 21:31:264987void RenderViewImpl::ZoomFactorHelper(PageZoom zoom,
[email protected]47578fa02011-11-02 19:34:414988 int zoom_center_x,
4989 int zoom_center_y,
4990 float scaling_increment) {
4991 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4992 return;
4993
[email protected]c514d6372011-08-16 22:54:444994 double old_page_scale_factor = webview()->pageScaleFactor();
4995 double page_scale_factor;
[email protected]e9ff79c2012-10-19 21:31:264996 if (zoom == PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:444997 page_scale_factor = 1.0;
4998 } else {
4999 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:415000 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:445001 }
[email protected]47578fa02011-11-02 19:34:415002 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:095003 webview()->setPageScaleFactor(page_scale_factor,
5004 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:415005 }
[email protected]40bd6582009-12-04 23:49:515006}
5007
[email protected]310ebd6302011-10-10 19:06:285008void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:175009 webview()->hidePopups();
5010 webview()->setZoomLevel(false, zoom_level);
5011 zoomLevelChanged();
5012}
5013
[email protected]310ebd6302011-10-10 19:06:285014void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
5015 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:545016 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:295017}
5018
[email protected]310ebd6302011-10-10 19:06:285019void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:275020 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:295021}
5022
[email protected]310ebd6302011-10-10 19:06:285023void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:275024 WebString no_encoding;
5025 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:185026}
5027
[email protected]310ebd6302011-10-10 19:06:285028WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:455029 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:275030 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:455031
5032 // xpath string can represent a frame deep down the tree (across multiple
5033 // frame DOMs).
5034 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
5035 // should break into 2 xpaths
5036 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:415037 std::vector<string16> xpaths;
5038 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:455039
[email protected]26aa0482009-09-30 16:55:275040 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:415041 for (std::vector<string16>::const_iterator i = xpaths.begin();
5042 frame && i != xpaths.end(); ++i) {
5043 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:295044 }
5045
[email protected]dd7daa82009-08-10 05:46:455046 return frame;
initial.commit09911bf2008-07-26 23:55:295047}
5048
[email protected]310ebd6302011-10-10 19:06:285049void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
5050 const string16& jscript,
5051 int id,
5052 bool notify_result) {
[email protected]01d43ef92012-09-25 00:54:105053 TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest");
[email protected]882b7b22010-10-05 03:34:535054 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:295055}
5056
[email protected]f546640b2012-05-15 00:03:495057void RenderViewImpl::OnPostMessageEvent(
5058 const ViewMsg_PostMessage_Params& params) {
[email protected]0720b532012-08-28 19:23:375059 // Find the target frame of this message. The source tags the message with
5060 // |target_frame_id|, so use it to locate the frame.
[email protected]e12dbe6f2012-10-04 22:11:195061 // TODO(nasko): Lookup based on the frame id, once http://crbug.com/153701
5062 // is fixed and we can rely on having frame tree updates again.
5063 WebFrame* frame = webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:495064
5065 // Find the source frame if it exists.
[email protected]f546640b2012-05-15 00:03:495066 WebFrame* source_frame = NULL;
5067 if (params.source_routing_id != MSG_ROUTING_NONE) {
5068 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
[email protected]e12dbe6f2012-10-04 22:11:195069 // TODO(nasko): Lookup based on the frame id, once http://crbug.com/153701
5070 // is fixed and we can rely on having frame tree updates again.
[email protected]f546640b2012-05-15 00:03:495071 if (source_view)
[email protected]e12dbe6f2012-10-04 22:11:195072 source_frame = source_view->webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:495073 }
5074
5075 // Create an event with the message. The final parameter to initMessageEvent
5076 // is the last event ID, which is not used with postMessage.
5077 WebDOMEvent event = frame->document().createEvent("MessageEvent");
5078 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
5079 msg_event.initMessageEvent("message",
5080 // |canBubble| and |cancellable| are always false
5081 false, false,
5082 WebSerializedScriptValue::fromString(params.data),
5083 params.source_origin, source_frame, "");
5084
5085 // We must pass in the target_origin to do the security check on this side,
5086 // since it may have changed since the original postMessage call was made.
5087 WebSecurityOrigin target_origin;
5088 if (!params.target_origin.empty()) {
5089 target_origin =
5090 WebSecurityOrigin::createFromString(WebString(params.target_origin));
5091 }
5092 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
5093}
5094
[email protected]310ebd6302011-10-10 19:06:285095void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
5096 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:415097 WebFrame* frame = GetChildFrame(frame_xpath);
5098 if (!frame)
[email protected]216813952011-05-19 22:21:265099 return;
[email protected]ae461542009-06-19 19:03:415100
[email protected]01cf589c2011-07-28 18:04:035101 frame->document().insertUserStyleSheet(
5102 WebString::fromUTF8(css),
5103 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:485104}
5105
[email protected]310ebd6302011-10-10 19:06:285106void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:095107 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:045108
5109 // Keep track of the total bindings accumulated in this process.
5110 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:295111}
5112
[email protected]310ebd6302011-10-10 19:06:285113void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
5114 const std::string& value) {
[email protected]e9ff79c2012-10-19 21:31:265115 if (enabled_bindings_ & BINDINGS_POLICY_WEB_UI)
[email protected]808bda52012-03-09 22:43:325116 GetWebUIBindings()->SetProperty(name, value);
5117 else
5118 NOTREACHED() << "WebUI bindings not enabled.";
initial.commit09911bf2008-07-26 23:55:295119}
5120
[email protected]310ebd6302011-10-10 19:06:285121void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
5122 const gfx::Point& client_point,
5123 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:425124 WebDragOperationsMask ops,
5125 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:555126 WebDragOperation operation = webview()->dragTargetDragEnter(
5127 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:555128 client_point,
5129 screen_point,
[email protected]1f2230b2012-05-17 23:43:425130 ops,
5131 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555132
5133 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5134}
5135
[email protected]310ebd6302011-10-10 19:06:285136void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
5137 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:425138 WebDragOperationsMask ops,
5139 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:555140 WebDragOperation operation = webview()->dragTargetDragOver(
5141 client_point,
5142 screen_point,
[email protected]1f2230b2012-05-17 23:43:425143 ops,
5144 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555145
5146 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5147}
5148
[email protected]310ebd6302011-10-10 19:06:285149void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:555150 webview()->dragTargetDragLeave();
5151}
5152
[email protected]310ebd6302011-10-10 19:06:285153void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
[email protected]1f2230b2012-05-17 23:43:425154 const gfx::Point& screen_point,
5155 int key_modifiers) {
5156 webview()->dragTargetDrop(client_point, screen_point, key_modifiers);
[email protected]fcad49452011-06-28 17:11:575157
5158 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:555159}
5160
[email protected]310ebd6302011-10-10 19:06:285161void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
5162 const gfx::Point& screen_point,
5163 bool ended,
5164 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:035165 if (ended) {
[email protected]26aa0482009-09-30 16:55:275166 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:205167 } else {
5168 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:035169 }
initial.commit09911bf2008-07-26 23:55:295170}
5171
[email protected]310ebd6302011-10-10 19:06:285172void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:275173 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:295174}
5175
[email protected]310ebd6302011-10-10 19:06:285176void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:595177 webkit_preferences_ = prefs;
5178 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:295179}
5180
[email protected]38761452012-10-18 16:31:595181void RenderViewImpl::OnUpdateTimezone() {
5182 if (webview())
5183 NotifyTimezoneChange(webview()->mainFrame());
5184}
5185
[email protected]310ebd6302011-10-10 19:06:285186void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:295187 alternate_error_page_url_ = url;
5188}
5189
[email protected]310ebd6302011-10-10 19:06:285190void RenderViewImpl::OnCustomContextMenuAction(
[email protected]e9ff79c2012-10-19 21:31:265191 const CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:085192 unsigned action) {
[email protected]860ee642012-10-13 03:46:255193 if (custom_context.request_id) {
5194 // External context menu request, look in our map.
[email protected]e9ff79c2012-10-19 21:31:265195 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:255196 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:465197 if (client)
5198 client->OnMenuAction(custom_context.request_id, action);
[email protected]860ee642012-10-13 03:46:255199 } else {
5200 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:085201 webview()->performCustomContextMenuAction(action);
[email protected]860ee642012-10-13 03:46:255202 }
[email protected]a0c7153e2009-12-09 14:36:335203}
5204
[email protected]310ebd6302011-10-10 19:06:285205void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:515206 int id,
5207 const std::vector<FilePath>& paths) {
5208 if (!enumeration_completions_[id])
5209 return;
5210
5211 WebVector<WebString> ws_file_names(paths.size());
5212 for (size_t i = 0; i < paths.size(); ++i)
5213 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
5214
5215 enumeration_completions_[id]->didChooseFile(ws_file_names);
5216 enumeration_completions_.erase(id);
5217}
5218
[email protected]fb11b6a42012-03-14 07:25:125219void RenderViewImpl::OnFileChooserResponse(
[email protected]ddb034b2012-06-26 20:31:395220 const std::vector<ui::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:365221 // This could happen if we navigated to a different page before the user
5222 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:475223 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:365224 return;
5225
[email protected]b5188522012-03-15 00:18:045226 // Convert Chrome's SelectedFileInfo list to WebKit's.
5227 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
5228 files.size());
5229 for (size_t i = 0; i < files.size(); ++i) {
5230 WebFileChooserCompletion::SelectedFileInfo selected_file;
[email protected]53f04c82012-07-26 02:31:095231 selected_file.path = webkit_glue::FilePathToWebString(files[i].local_path);
[email protected]b5188522012-03-15 00:18:045232 selected_file.displayName = webkit_glue::FilePathStringToWebString(
5233 files[i].display_name);
5234 selected_files[i] = selected_file;
5235 }
[email protected]a1128322009-10-06 18:38:465236
[email protected]cdaf8d02010-03-30 19:52:475237 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:045238 file_chooser_completions_.front()->completion->didChooseFile(
5239 selected_files);
[email protected]cdaf8d02010-03-30 19:52:475240 file_chooser_completions_.pop_front();
5241
5242 // If there are more pending file chooser requests, schedule one now.
5243 if (!file_chooser_completions_.empty()) {
5244 Send(new ViewHostMsg_RunFileChooser(routing_id_,
5245 file_chooser_completions_.front()->params));
5246 }
initial.commit09911bf2008-07-26 23:55:295247}
5248
[email protected]244ac1892011-12-02 17:04:475249void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
5250 const gfx::Size& max_size) {
5251 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5252 if (!webview())
5253 return;
[email protected]61e2b3cc2012-03-02 16:13:345254 webview()->enableAutoResizeMode(min_size, max_size);
5255}
5256
5257void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
5258 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5259 if (!webview())
5260 return;
5261 webview()->disableAutoResizeMode();
5262
5263 Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK);
[email protected]244ac1892011-12-02 17:04:475264}
5265
[email protected]2bf834f2011-11-17 20:02:215266void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:245267 if (send_preferred_size_changes_)
5268 return;
[email protected]9fb325e2010-05-06 18:23:245269 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:395270
[email protected]d812fd12011-05-27 23:05:075271 // Start off with an initial preferred size notification (in case
5272 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:595273 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:085274}
5275
[email protected]310ebd6302011-10-10 19:06:285276void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:105277 const gfx::Size& disable_scrollbar_size_limit) {
5278 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
5279}
5280
[email protected]310ebd6302011-10-10 19:06:285281void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:265282 const RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:505283 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:515284 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:375285 UpdateFontRenderingFromRendererPrefs();
[email protected]a13283cc2012-04-05 00:21:225286#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:415287 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
5288 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:465289 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]f78452f2012-05-15 02:07:525290 ui::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:345291 renderer_prefs.thumb_inactive_color,
5292 renderer_prefs.thumb_active_color,
5293 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:555294#endif
[email protected]93623c5d2009-12-10 21:40:325295
[email protected]a13283cc2012-04-05 00:21:225296#if defined(USE_ASH) || defined(TOOLKIT_GTK)
[email protected]644d77e2010-01-27 01:03:105297 if (webview()) {
[email protected]a13283cc2012-04-05 00:21:225298#if defined(TOOLKIT_GTK)
[email protected]93623c5d2009-12-10 21:40:325299 webview()->setScrollbarColors(
5300 renderer_prefs.thumb_inactive_color,
5301 renderer_prefs.thumb_active_color,
5302 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:555303#endif
[email protected]644d77e2010-01-27 01:03:105304 webview()->setSelectionColors(
5305 renderer_prefs.active_selection_bg_color,
5306 renderer_prefs.active_selection_fg_color,
5307 renderer_prefs.inactive_selection_bg_color,
5308 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:465309 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:105310 }
[email protected]7a74e102009-09-03 00:16:565311#endif
[email protected]d299d972012-03-23 02:26:555312
[email protected]d051d9a2011-12-10 02:02:505313 // If the zoom level for this page matches the old zoom default, and this
5314 // is not a plugin, update the zoom level to match the new default.
5315 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
[email protected]e9ff79c2012-10-19 21:31:265316 ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
[email protected]d051d9a2011-12-10 02:02:505317 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
5318 zoomLevelChanged();
5319 }
[email protected]80d96fa2009-06-10 22:34:515320}
5321
[email protected]310ebd6302011-10-10 19:06:285322void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
5323 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:285324 if (webview())
5325 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:565326}
5327
[email protected]77829642012-05-15 14:47:175328void RenderViewImpl::OnOrientationChangeEvent(int orientation) {
5329 webview()->mainFrame()->sendOrientationChangeEvent(orientation);
5330}
5331
[email protected]81375e872012-01-11 21:40:365332void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
5333 const WebPluginAction& action) {
5334 if (webview())
5335 webview()->performPluginAction(action, location);
5336}
5337
[email protected]310ebd6302011-10-10 19:06:285338void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:195339 const GURL& page_url) {
5340 // Prepare list to storage all savable resource links.
5341 std::vector<GURL> resources_list;
[email protected]c2d986512012-05-12 00:22:465342 std::vector<GURL> referrer_urls_list;
5343 std::vector<WebKit::WebReferrerPolicy> referrer_policies_list;
[email protected]18d5be92011-07-25 18:00:195344 std::vector<GURL> frames_list;
5345 webkit_glue::SavableResourcesResult result(&resources_list,
[email protected]c2d986512012-05-12 00:22:465346 &referrer_urls_list,
5347 &referrer_policies_list,
[email protected]18d5be92011-07-25 18:00:195348 &frames_list);
5349
[email protected]e9ff79c2012-10-19 21:31:265350 // webkit/ doesn't know about Referrer.
[email protected]18d5be92011-07-25 18:00:195351 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
5352 webview(),
5353 page_url,
5354 &result,
[email protected]e9ff79c2012-10-19 21:31:265355 const_cast<const char**>(GetSavableSchemes()))) {
[email protected]18d5be92011-07-25 18:00:195356 // If something is wrong when collecting all savable resource links,
5357 // send empty list to embedder(browser) to tell it failed.
[email protected]c2d986512012-05-12 00:22:465358 referrer_urls_list.clear();
5359 referrer_policies_list.clear();
[email protected]18d5be92011-07-25 18:00:195360 resources_list.clear();
5361 frames_list.clear();
5362 }
5363
[email protected]e9ff79c2012-10-19 21:31:265364 std::vector<Referrer> referrers_list;
[email protected]c2d986512012-05-12 00:22:465365 CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size());
5366 for (unsigned i = 0; i < referrer_urls_list.size(); ++i) {
5367 referrers_list.push_back(
[email protected]e9ff79c2012-10-19 21:31:265368 Referrer(referrer_urls_list[i], referrer_policies_list[i]));
[email protected]c2d986512012-05-12 00:22:465369 }
5370
[email protected]18d5be92011-07-25 18:00:195371 // Send result of all savable resource links to embedder.
5372 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
5373 resources_list,
5374 referrers_list,
5375 frames_list));
5376}
5377
[email protected]310ebd6302011-10-10 19:06:285378void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:195379 const std::vector<GURL>& links,
5380 const std::vector<FilePath>& local_paths,
5381 const FilePath& local_directory_name) {
5382
5383 // Convert std::vector of GURLs to WebVector<WebURL>
5384 WebVector<WebURL> weburl_links(links);
5385
5386 // Convert std::vector of std::strings to WebVector<WebString>
5387 WebVector<WebString> webstring_paths(local_paths.size());
5388 for (size_t i = 0; i < local_paths.size(); i++)
5389 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
5390
5391 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
5392 webstring_paths,
5393 webkit_glue::FilePathToWebString(
5394 local_directory_name));
5395}
5396
[email protected]310ebd6302011-10-10 19:06:285397void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:125398 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:275399 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:125400 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
5401 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
5402 before_unload_start_time,
5403 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:295404}
5405
[email protected]310ebd6302011-10-10 19:06:285406void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]69ddf852012-02-21 23:21:315407 // Ensure that no other in-progress navigation continues.
5408 OnStop();
5409
[email protected]73eb2602012-02-09 19:50:555410 // Only run unload if we're not swapped out yet, but send the ack either way.
5411 if (!is_swapped_out_) {
5412 // Swap this RenderView out so the tab can navigate to a page rendered by a
5413 // different process. This involves running the unload handler and clearing
5414 // the page. Once WasSwappedOut is called, we also allow this process to
5415 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:155416
[email protected]73eb2602012-02-09 19:50:555417 // Send an UpdateState message before we get swapped out.
5418 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:155419
[email protected]73eb2602012-02-09 19:50:555420 // Synchronously run the unload handler before sending the ACK.
5421 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:155422
[email protected]73eb2602012-02-09 19:50:555423 // Swap out and stop sending any IPC messages that are not ACKs.
5424 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:155425
[email protected]285f4bb82012-04-17 15:57:285426 // Replace the page with a blank dummy URL. The unload handler will not be
[email protected]73eb2602012-02-09 19:50:555427 // run a second time, thanks to a check in FrameLoader::stopLoading.
5428 // TODO(creis): Need to add a better way to do this that avoids running the
[email protected]285f4bb82012-04-17 15:57:285429 // beforeunload handler. For now, we just run it a second time silently.
[email protected]0720b532012-08-28 19:23:375430 NavigateToSwappedOutURL(webview()->mainFrame());
[email protected]961541a92012-06-01 21:15:285431
5432 // Let WebKit know that this view is hidden so it can drop resources and
5433 // stop compositing.
5434 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false);
[email protected]73eb2602012-02-09 19:50:555435 }
[email protected]992db4c2011-05-12 15:37:155436
5437 // Just echo back the params in the ACK.
5438 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
5439}
5440
[email protected]0720b532012-08-28 19:23:375441void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) {
[email protected]14392a52012-05-02 20:28:445442 // We use loadRequest instead of loadHTMLString because the former commits
5443 // synchronously. Otherwise a new navigation can interrupt the navigation
[email protected]e9ff79c2012-10-19 21:31:265444 // to kSwappedOutURL. If that happens to be to the page we had been
[email protected]14392a52012-05-02 20:28:445445 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]e9ff79c2012-10-19 21:31:265446 GURL swappedOutURL(kSwappedOutURL);
[email protected]14392a52012-05-02 20:28:445447 WebURLRequest request(swappedOutURL);
[email protected]0720b532012-08-28 19:23:375448 frame->loadRequest(request);
[email protected]14392a52012-05-02 20:28:445449}
5450
[email protected]310ebd6302011-10-10 19:06:285451void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:375452 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:295453 // TODO(creis): We'd rather use webview()->Close() here, but that currently
5454 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
5455 // in the onunload handler from appearing. For now, we're bypassing that and
5456 // calling the FrameLoader's CloseURL method directly. This should be
5457 // revisited to avoid having two ways to close a page. Having a single way
5458 // to close that can run onunload is also useful for fixing
5459 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:275460 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:295461
[email protected]992db4c2011-05-12 15:37:155462 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:295463}
5464
[email protected]310ebd6302011-10-10 19:06:285465void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:025466#if defined(USE_AURA)
5467 // Aura doesn't care if we switch themes.
5468#elif defined(OS_WIN)
[email protected]f78452f2012-05-15 02:07:525469 ui::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:465470 if (webview())
5471 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:575472#else // defined(OS_WIN)
5473 // TODO(port): we don't support theming on non-Windows platforms yet
5474 NOTIMPLEMENTED();
5475#endif
initial.commit09911bf2008-07-26 23:55:295476}
5477
[email protected]310ebd6302011-10-10 19:06:285478void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:085479 if (decrement_shared_popup_at_destruction_)
5480 shared_popup_counter_->data--;
5481 shared_popup_counter_ = new SharedRenderViewCounter(0);
5482 decrement_shared_popup_at_destruction_ = false;
5483}
5484
[email protected]310ebd6302011-10-10 19:06:285485bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
5486 const WebURLError& error,
5487 bool replace) {
[email protected]15d79e12009-08-02 19:23:455488 // We only show alternate error pages in the main frame. They are
5489 // intended to assist the user when navigating, so there is not much
5490 // value in showing them for failed subframes. Ideally, we would be
5491 // able to use the TYPED transition type for this, but that flag is
5492 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455493 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455494 return false;
5495
5496 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375497 // connection failure.
[email protected]15d79e12009-08-02 19:23:455498 int ec = error.reason;
5499 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5500 ec != net::ERR_CONNECTION_FAILED &&
5501 ec != net::ERR_CONNECTION_REFUSED &&
5502 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]82114f52012-03-20 22:53:415503 ec != net::ERR_CONNECTION_TIMED_OUT) {
[email protected]15d79e12009-08-02 19:23:455504 return false;
[email protected]82114f52012-03-20 22:53:415505 }
[email protected]15d79e12009-08-02 19:23:455506
5507 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555508 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455509 if (!error_page_url.is_valid())
5510 return false;
5511
5512 // Load an empty page first so there is an immediate response to the error,
5513 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455514 frame->loadHTMLString(std::string(),
[email protected]e9ff79c2012-10-19 21:31:265515 GURL(kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455516 error.unreachableURL,
5517 replace);
5518
5519 // Now, create a fetcher for the error page and associate it with the data
5520 // source we just created via the LoadHTMLString call. That way if another
5521 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:075522 DocumentState* document_state =
5523 DocumentState::FromDataSource(frame->provisionalDataSource());
5524 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:455525 new AltErrorPageResourceFetcher(
5526 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:085527 base::Bind(&RenderViewImpl::AltErrorPageFinished,
5528 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:455529 return true;
5530}
5531
[email protected]310ebd6302011-10-10 19:06:285532void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
5533 const WebURLError& original_error,
5534 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:455535 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:095536 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:555537 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:095538 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:455539}
5540
[email protected]310ebd6302011-10-10 19:06:285541void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:005542 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475543 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005544}
5545
[email protected]310ebd6302011-10-10 19:06:285546void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:095547 const gfx::Rect& resizer_rect,
5548 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:105549 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475550 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105551 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205552 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:315553 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:105554 }
[email protected]dd6afca2011-08-13 03:44:315555 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:105556 }
5557
[email protected]ee41e7d22011-10-14 19:34:095558 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:005559}
[email protected]0aa477bd2009-03-23 22:21:435560
[email protected]29ed96a2012-02-04 18:12:165561void RenderViewImpl::WillInitiatePaint() {
5562 // Notify the pepper plugins that we're about to paint.
5563 pepper_delegate_.ViewWillInitiatePaint();
5564}
5565
[email protected]310ebd6302011-10-10 19:06:285566void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:165567 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]53900d52010-06-16 04:25:015568 pepper_delegate_.ViewInitiatedPaint();
[email protected]7900bfdb2012-05-24 19:31:245569 if (GetGuestToEmbedderChannel())
5570 GetGuestToEmbedderChannel()->IssueSwapBuffers(guest_graphics_resource());
[email protected]00c39612010-03-06 02:53:285571}
5572
[email protected]310ebd6302011-10-10 19:06:285573void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:285574 // Notify any pepper plugins that we painted. This will call into the plugin,
5575 // and we it may ask to close itself as a result. This will, in turn, modify
5576 // our set, possibly invalidating the iterator. So we iterate on a copy that
5577 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:015578 pepper_delegate_.ViewFlushedPaint();
5579
[email protected]5b1dec8c2012-02-07 04:35:385580 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
5581 // See crbug.com/112921.
5582 if (!webview())
5583 return;
5584
[email protected]00c39612010-03-06 02:53:285585 WebFrame* main_frame = webview()->mainFrame();
5586
5587 // If we have a provisional frame we are between the start and commit stages
5588 // of loading and we don't want to save stats.
5589 if (!main_frame->provisionalDataSource()) {
5590 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:075591 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:285592
[email protected]05c8e502010-08-15 15:13:525593 // TODO(jar): The following code should all be inside a method, probably in
5594 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285595 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:075596 if (document_state->first_paint_time().is_null()) {
5597 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:285598 }
[email protected]007733c2011-11-17 00:34:075599 if (document_state->first_paint_after_load_time().is_null() &&
5600 !document_state->finish_load_time().is_null()) {
5601 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:285602 }
5603 }
5604}
5605
[email protected]310ebd6302011-10-10 19:06:285606void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:085607 RenderWidget::OnSwapBuffersPosted();
5608}
5609
[email protected]310ebd6302011-10-10 19:06:285610void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:245611 RenderWidget::OnSwapBuffersComplete();
5612}
5613
[email protected]310ebd6302011-10-10 19:06:285614void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:245615 RenderWidget::OnSwapBuffersAborted();
5616}
5617
[email protected]310ebd6302011-10-10 19:06:285618webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:155619 const gfx::Rect& paint_bounds,
5620 TransportDIB** dib,
5621 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:205622 gfx::Rect* clip,
5623 float* scale_factor) {
[email protected]ca4847f2010-09-24 05:39:155624 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
[email protected]0f3a2d12012-09-01 03:37:205625 paint_bounds, dib, location, clip, scale_factor);
[email protected]ca4847f2010-09-24 05:39:155626}
5627
[email protected]310ebd6302011-10-10 19:06:285628gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:075629 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:435630 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:525631}
5632
[email protected]310ebd6302011-10-10 19:06:285633void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:165634 if (webview())
[email protected]26aa0482009-09-30 16:55:275635 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165636}
5637
[email protected]310ebd6302011-10-10 19:06:285638void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:145639 if (webview())
[email protected]b4bb2502009-10-01 22:35:275640 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145641
5642 SetBackground(background);
5643}
5644
[email protected]2a84f9d2012-06-05 21:50:435645void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) {
5646 if (accessibility_mode_ == new_mode)
5647 return;
5648 accessibility_mode_ = new_mode;
5649 if (renderer_accessibility_) {
5650 delete renderer_accessibility_;
5651 renderer_accessibility_ = NULL;
5652 }
5653 if (accessibility_mode_ == AccessibilityModeComplete)
5654 renderer_accessibility_ = new RendererAccessibilityComplete(this);
5655 else if (accessibility_mode_ == AccessibilityModeEditableTextOnly)
5656 renderer_accessibility_ = new RendererAccessibilityFocusOnly(this);
5657}
5658
[email protected]310ebd6302011-10-10 19:06:285659void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:345660 if (webview())
[email protected]b4bb2502009-10-01 22:35:275661 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265662
5663#if defined(OS_MACOSX)
5664 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5665 for (plugin_it = plugin_delegates_.begin();
5666 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5667 (*plugin_it)->SetWindowFocus(active);
5668 }
5669#endif
[email protected]8c66c5a2009-07-22 17:26:345670}
5671
[email protected]7a17bac02012-03-07 21:58:125672void RenderViewImpl::OnSetNavigationStartTime(
5673 const base::TimeTicks& browser_navigation_start) {
5674 if (!webview())
5675 return;
5676
5677 // Only the initial navigation can be a cross-renderer navigation. If we've
5678 // already navigated away from that page, we can ignore this message.
5679 if (page_id_ != -1)
5680 return;
5681
5682 // browser_navigation_start is likely before this process existed, so we can't
5683 // use InterProcessTimeTicksConverter. Instead, the best we can do is just
5684 // ensure we don't report a bogus value in the future.
5685 base::TimeTicks navigation_start = std::min(base::TimeTicks::Now(),
5686 browser_navigation_start);
5687 webview()->mainFrame()->provisionalDataSource()->setNavigationStartTime(
5688 (navigation_start - base::TimeTicks()).InSecondsF());
5689}
5690
[email protected]6ce7abc52010-02-02 18:40:145691#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285692void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:145693 // Inform plugins that their container has changed visibility.
5694 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5695 for (plugin_it = plugin_delegates_.begin();
5696 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5697 (*plugin_it)->SetContainerVisibility(visible);
5698 }
5699}
[email protected]1e6e3c992010-02-08 15:52:135700
[email protected]310ebd6302011-10-10 19:06:285701void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
5702 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:135703 // Inform plugins that their window's frame has changed.
5704 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5705 for (plugin_it = plugin_delegates_.begin();
5706 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5707 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5708 }
5709}
[email protected]935d63d2010-10-15 23:31:555710
[email protected]310ebd6302011-10-10 19:06:285711void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
5712 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135713 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555714 // applies to it or not, so inform all the delegates.
5715 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5716 for (plugin_it = plugin_delegates_.begin();
5717 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135718 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555719 }
5720}
[email protected]6ce7abc52010-02-02 18:40:145721#endif // OS_MACOSX
5722
[email protected]310ebd6302011-10-10 19:06:285723void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:485724 const EditCommands& edit_commands) {
5725 edit_commands_ = edit_commands;
5726}
5727
[email protected]310ebd6302011-10-10 19:06:285728void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:595729 // We need to grab a pointer to the doomed WebView before we destroy it.
5730 WebView* doomed = webview();
5731 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495732 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:595733}
5734
[email protected]310ebd6302011-10-10 19:06:285735void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:485736 edit_commands_.clear();
5737}
5738
[email protected]310ebd6302011-10-10 19:06:285739bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]217690d2012-01-27 07:33:115740 pepper_delegate_.WillHandleMouseEvent();
5741
5742 // If the mouse is locked, only the current owner of the mouse lock can
5743 // process mouse events.
5744 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:375745}
5746
[email protected]2b942c332012-04-25 16:26:265747void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515748 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065749}
5750
[email protected]310ebd6302011-10-10 19:06:285751void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:245752 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
5753}
5754
[email protected]310ebd6302011-10-10 19:06:285755void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:435756 RenderWidget::OnWasHidden();
5757
[email protected]2d7b82c2012-06-01 05:57:505758#if defined(OS_ANDROID)
5759 // Inform WebMediaPlayerManagerAndroid to release all media player resources.
5760 media_player_manager_->ReleaseMediaResources();
5761#endif
5762
[email protected]a6939ca42011-02-18 17:58:075763 if (webview()) {
5764 webview()->settings()->setMinimumTimerInterval(
5765 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:445766 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075767 }
5768
[email protected]204f1df2012-01-04 20:21:135769 // Inform PPAPI plugins that their page is no longer visible.
5770 pepper_delegate_.PageVisibilityChanged(false);
5771
[email protected]a6939ca42011-02-18 17:58:075772#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135773 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:435774 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5775 for (plugin_it = plugin_delegates_.begin();
5776 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5777 (*plugin_it)->SetContainerVisibility(false);
5778 }
[email protected]a6939ca42011-02-18 17:58:075779#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:435780}
5781
[email protected]9e2e4632012-07-27 16:38:415782void RenderViewImpl::OnWasShown(bool needs_repainting) {
5783 RenderWidget::OnWasShown(needs_repainting);
[email protected]941e4552010-02-01 21:23:435784
[email protected]a6939ca42011-02-18 17:58:075785 if (webview()) {
5786 webview()->settings()->setMinimumTimerInterval(
5787 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:445788 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075789 }
5790
[email protected]204f1df2012-01-04 20:21:135791 // Inform PPAPI plugins that their page is visible.
5792 pepper_delegate_.PageVisibilityChanged(true);
5793
[email protected]a6939ca42011-02-18 17:58:075794#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135795 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:435796 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5797 for (plugin_it = plugin_delegates_.begin();
5798 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5799 (*plugin_it)->SetContainerVisibility(true);
5800 }
[email protected]784ea1ab2010-09-18 00:02:345801#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:075802}
[email protected]1e6e3c992010-02-08 15:52:135803
[email protected]310ebd6302011-10-10 19:06:285804bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]9caf09bc2012-06-25 21:46:285805 // Contexts using the command buffer support asynchronous swapbuffers.
[email protected]f89e173a2012-08-24 01:12:265806 // See RenderViewImpl::createOutputSurface().
[email protected]9caf09bc2012-06-25 21:46:285807 if (WebWidgetHandlesCompositorScheduling() ||
5808 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL))
[email protected]555e75d2011-10-08 01:23:385809 return false;
5810
[email protected]9caf09bc2012-06-25 21:46:285811 return true;
[email protected]65225772011-05-12 21:10:245812}
5813
[email protected]310ebd6302011-10-10 19:06:285814void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:135815 RenderWidget::OnSetFocus(enable);
5816
[email protected]7d3c02c2010-05-05 23:10:315817 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075818 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135819 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5820 for (plugin_it = plugin_delegates_.begin();
5821 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345822#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315823 // RenderWidget's call to setFocus can cause the underlying webview's
5824 // activation state to change just like a call to setIsActive.
5825 if (enable)
5826 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345827#endif
[email protected]7d3c02c2010-05-05 23:10:315828 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135829 }
5830 }
[email protected]a01da5682012-06-30 00:37:315831 // Notify all Pepper plugins.
5832 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135833}
[email protected]941e4552010-02-01 21:23:435834
[email protected]310ebd6302011-10-10 19:06:285835void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]3306f262012-09-21 19:20:425836 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]3f783362011-10-21 22:40:505837 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:575838}
5839
[email protected]73bf95812011-10-12 11:38:325840void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]3306f262012-09-21 19:20:425841 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]8fe8f742012-06-14 00:36:085842 if (renderer_accessibility_)
5843 renderer_accessibility_->FocusedNodeChanged(WebNode());
[email protected]73bf95812011-10-12 11:38:325844}
5845
[email protected]3f783362011-10-21 22:40:505846void RenderViewImpl::PpapiPluginCaretPositionChanged() {
5847 UpdateSelectionBounds();
5848}
5849
[email protected]b25b3ee2012-01-13 05:19:545850bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
5851 if (!pepper_delegate_.IsPluginFocused())
5852 return false;
5853 *rect = pepper_delegate_.GetCaretBounds();
5854 return true;
5855}
5856
[email protected]397c23962012-05-21 07:09:325857void RenderViewImpl::SimulateImeSetComposition(
5858 const string16& text,
5859 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5860 int selection_start,
5861 int selection_end) {
5862 OnImeSetComposition(text, underlines, selection_start, selection_end);
5863}
5864
5865void RenderViewImpl::SimulateImeConfirmComposition(
5866 const string16& text,
5867 const ui::Range& replacement_range) {
5868 OnImeConfirmComposition(text, replacement_range);
5869}
5870
[email protected]73bf95812011-10-12 11:38:325871void RenderViewImpl::PpapiPluginCancelComposition() {
5872 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]58b48a0d2012-06-13 07:01:355873 const ui::Range range(ui::Range::InvalidRange());
5874 const std::vector<gfx::Rect> empty_bounds;
5875 UpdateCompositionInfo(range, empty_bounds);
[email protected]73bf95812011-10-12 11:38:325876}
5877
[email protected]3c8c74c2012-03-15 07:34:525878void RenderViewImpl::PpapiPluginSelectionChanged() {
5879 SyncSelectionIfRequired();
5880}
5881
[email protected]e9ff79c2012-10-19 21:31:265882void RenderViewImpl::PpapiPluginCreated(RendererPpapiHost* host) {
[email protected]236bf852012-07-27 22:49:365883 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
5884 DidCreatePepperPlugin(host));
5885}
5886
[email protected]310ebd6302011-10-10 19:06:285887void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:575888 const string16& text,
5889 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5890 int selection_start,
5891 int selection_end) {
[email protected]73bf95812011-10-12 11:38:325892 if (pepper_delegate_.IsPluginFocused()) {
5893 // When a PPAPI plugin has focus, we bypass WebKit.
5894 pepper_delegate_.OnImeSetComposition(text,
5895 underlines,
5896 selection_start,
5897 selection_end);
5898 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235899#if defined(OS_WIN)
5900 // When a plug-in has focus, we create platform-specific IME data used by
5901 // our IME emulator and send it directly to the focused plug-in, i.e. we
5902 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
5903 // instance ID is the same one as the specified ID.)
5904 if (focused_plugin_id_ >= 0) {
5905 std::vector<int> clauses;
5906 std::vector<int> target;
5907 for (size_t i = 0; i < underlines.size(); ++i) {
5908 clauses.push_back(underlines[i].startOffset);
5909 clauses.push_back(underlines[i].endOffset);
5910 if (underlines[i].thick) {
5911 target.clear();
5912 target.push_back(underlines[i].startOffset);
5913 target.push_back(underlines[i].endOffset);
5914 }
5915 }
5916 std::set<WebPluginDelegateProxy*>::iterator it;
5917 for (it = plugin_delegates_.begin();
5918 it != plugin_delegates_.end(); ++it) {
5919 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
5920 focused_plugin_id_);
5921 }
5922 return;
5923 }
5924#endif
[email protected]56ea1a62011-05-30 07:05:575925 RenderWidget::OnImeSetComposition(text,
5926 underlines,
5927 selection_start,
5928 selection_end);
5929 }
5930}
5931
[email protected]4de6d1692011-10-12 08:45:445932void RenderViewImpl::OnImeConfirmComposition(
5933 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:575934 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:325935 // When a PPAPI plugin has focus, we bypass WebKit.
5936 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:575937 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235938#if defined(OS_WIN)
5939 // Same as OnImeSetComposition(), we send the text from IMEs directly to
5940 // plug-ins. When we send IME text directly to plug-ins, we should not send
5941 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:445942 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:235943 if (focused_plugin_id_ >= 0) {
5944 std::set<WebPluginDelegateProxy*>::iterator it;
5945 for (it = plugin_delegates_.begin();
5946 it != plugin_delegates_.end(); ++it) {
5947 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
5948 }
5949 return;
5950 }
5951#endif
[email protected]ebd28ac2011-10-13 18:49:055952 if (replacement_range.IsValid() && webview()) {
5953 // Select the text in |replacement_range|, it will then be replaced by
5954 // text added by the call to RenderWidget::OnImeConfirmComposition().
5955 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:165956 WebRange webrange = WebRange::fromDocumentRange(
5957 frame, replacement_range.start(), replacement_range.length());
5958 if (!webrange.isNull())
[email protected]884f9002012-08-21 19:33:585959 frame->selectRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:055960 }
5961 }
[email protected]4de6d1692011-10-12 08:45:445962 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:575963 }
5964}
5965
[email protected]dea5e7682012-06-14 05:21:245966void RenderViewImpl::OnSetDeviceScaleFactor(float device_scale_factor) {
5967 RenderWidget::OnSetDeviceScaleFactor(device_scale_factor);
5968 if (webview())
5969 webview()->setDeviceScaleFactor(device_scale_factor);
5970}
5971
[email protected]310ebd6302011-10-10 19:06:285972ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:325973 return pepper_delegate_.IsPluginFocused() ?
5974 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
5975}
5976
[email protected]3f783362011-10-21 22:40:505977void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
5978 if (pepper_delegate_.IsPluginFocused()) {
5979 // TODO(kinaba) http://crbug.com/101101
5980 // Current Pepper IME API does not handle selection bounds. So we simply
5981 // use the caret position as an empty range for now. It will be updated
5982 // after Pepper API equips features related to surrounding text retrieval.
5983 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
5984 *start = caret;
5985 *end = caret;
5986 return;
5987 }
5988 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:455989}
5990
[email protected]58b48a0d2012-06-13 07:01:355991void RenderViewImpl::GetCompositionCharacterBounds(
5992 std::vector<gfx::Rect>* bounds) {
5993 DCHECK(bounds);
5994 bounds->clear();
5995
5996 if (!webview())
5997 return;
5998 size_t start_offset = 0;
5999 size_t character_count = 0;
6000 if (!webview()->compositionRange(&start_offset, &character_count))
6001 return;
6002 if (character_count == 0)
6003 return;
6004
6005 WebKit::WebFrame* frame = webview()->focusedFrame();
6006 if (!frame)
6007 return;
6008
6009 bounds->reserve(character_count);
6010 WebKit::WebRect webrect;
6011 for (size_t i = 0; i < character_count; ++i) {
6012 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
6013 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
6014 bounds->clear();
6015 return;
6016 }
6017 bounds->push_back(webrect);
6018 }
6019}
6020
[email protected]310ebd6302011-10-10 19:06:286021bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:326022 return pepper_delegate_.IsPluginFocused() ?
6023 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:576024}
6025
[email protected]e6ae0f6c2011-10-04 10:39:236026#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:286027void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:236028 if (focused)
6029 focused_plugin_id_ = plugin_id;
6030 else
6031 focused_plugin_id_ = -1;
6032}
6033#endif
6034
[email protected]43f28f832010-02-03 02:28:486035#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:286036void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]82114f52012-03-20 22:53:416037 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
[email protected]b7f75862011-01-21 21:15:136038}
6039
[email protected]310ebd6302011-10-10 19:06:286040void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:136041 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:556042 // This message can be sent during event-handling, and needs to be delivered
6043 // within that context.
6044 msg->set_unblock(true);
6045 Send(msg);
6046}
6047
[email protected]310ebd6302011-10-10 19:06:286048gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:236049 bool opaque, bool root) {
[email protected]b2968292012-03-28 01:35:516050 gfx::PluginWindowHandle window = gfx::kNullPluginWindow;
[email protected]43f28f832010-02-03 02:28:486051 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:236052 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:116053 if (window) {
6054 fake_plugin_window_handles_.insert(window);
6055 }
[email protected]43f28f832010-02-03 02:28:486056 return window;
6057}
6058
[email protected]310ebd6302011-10-10 19:06:286059void RenderViewImpl::DestroyFakePluginWindowHandle(
6060 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:116061 if (window && fake_plugin_window_handles_.find(window) !=
6062 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:486063 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:116064 fake_plugin_window_handles_.erase(window);
6065 }
[email protected]43f28f832010-02-03 02:28:486066}
6067
[email protected]310ebd6302011-10-10 19:06:286068void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
6069 gfx::PluginWindowHandle window,
6070 int32 width,
6071 int32 height,
6072 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:336073 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:486074 routing_id(), window, width, height, io_surface_identifier));
6075}
6076
[email protected]310ebd6302011-10-10 19:06:286077void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:336078 gfx::PluginWindowHandle window,
6079 int32 width,
6080 int32 height,
6081 TransportDIB::Handle transport_dib) {
6082 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:076083 routing_id(), window, width, height, transport_dib));
6084}
6085
[email protected]310ebd6302011-10-10 19:06:286086TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:336087 size_t size) {
[email protected]1aef98132010-02-23 18:00:076088 TransportDIB::Handle dib_handle;
6089 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:386090 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:076091 return dib_handle;
6092 // Return an invalid handle if Send() fails.
6093 return TransportDIB::DefaultHandleValue();
6094}
6095
[email protected]310ebd6302011-10-10 19:06:286096void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
6097 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:076098 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
6099}
6100
[email protected]310ebd6302011-10-10 19:06:286101void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:326102 gfx::PluginWindowHandle window, uint64 surface_handle) {
[email protected]f35d6672010-10-28 21:39:146103 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:326104 routing_id(), window, surface_handle));
[email protected]43f28f832010-02-03 02:28:486105}
[email protected]82114f52012-03-20 22:53:416106#endif // defined(OS_MACOSX)
[email protected]58c321d2010-02-19 12:11:286107
[email protected]310ebd6302011-10-10 19:06:286108bool RenderViewImpl::ScheduleFileChooser(
[email protected]e9ff79c2012-10-19 21:31:266109 const FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:476110 WebFileChooserCompletion* completion) {
6111 static const size_t kMaximumPendingFileChooseRequests = 4;
6112 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
6113 // This sanity check prevents too many file choose requests from getting
6114 // queued which could DoS the user. Getting these is most likely a
6115 // programming error (there are many ways to DoS the user so it's not
6116 // considered a "real" security check), either in JS requesting many file
6117 // choosers to pop up, or in a plugin.
6118 //
6119 // TODO(brettw) we might possibly want to require a user gesture to open
6120 // a file picker, which will address this issue in a better way.
6121 return false;
6122 }
6123
6124 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
6125 new PendingFileChooser(params, completion)));
6126 if (file_chooser_completions_.size() == 1) {
6127 // Actually show the browse dialog when this is the first request.
6128 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
6129 }
6130 return true;
6131}
6132
[email protected]310ebd6302011-10-10 19:06:286133WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:516134 if (!geolocation_dispatcher_)
6135 geolocation_dispatcher_ = new GeolocationDispatcher(this);
6136 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:256137}
[email protected]61c9f032010-03-31 23:04:196138
[email protected]310ebd6302011-10-10 19:06:286139WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:116140 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:226141#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:026142 if (!input_tag_speech_dispatcher_)
6143 input_tag_speech_dispatcher_ =
6144 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:226145#endif
[email protected]c52b2892012-03-07 11:01:026146 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:116147}
6148
[email protected]64d09222012-05-25 10:10:346149WebKit::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
6150#if defined(ENABLE_INPUT_SPEECH)
6151 if (!speech_recognition_dispatcher_)
6152 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
6153#endif
6154 return speech_recognition_dispatcher_;
6155}
6156
[email protected]310ebd6302011-10-10 19:06:286157WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:516158 if (!device_orientation_dispatcher_)
6159 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
6160 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:536161}
6162
[email protected]310ebd6302011-10-10 19:06:286163void RenderViewImpl::zoomLimitsChanged(double minimum_level,
6164 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:256165 // For now, don't remember plugin zoom values. We don't want to mix them with
6166 // normal web content (i.e. a fixed layout plugin would usually want them
6167 // different).
6168 bool remember = !webview()->mainFrame()->document().isPluginDocument();
6169
[email protected]b75b8292010-10-01 07:28:256170 int minimum_percent = static_cast<int>(
6171 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
6172 int maximum_percent = static_cast<int>(
6173 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:256174
6175 Send(new ViewHostMsg_UpdateZoomLimits(
6176 routing_id_, minimum_percent, maximum_percent, remember));
6177}
6178
[email protected]310ebd6302011-10-10 19:06:286179void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:256180 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:086181 float zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:266182
6183 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
6184
[email protected]b75b8292010-10-01 07:28:256185 // Tell the browser which url got zoomed so it can update the menu and the
6186 // saved values if necessary
6187 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:086188 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:416189 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:256190}
6191
[email protected]310ebd6302011-10-10 19:06:286192void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
6193 const WebString& base_url,
6194 const WebString& url,
6195 const WebString& title) {
[email protected]3a3b75a2012-06-01 08:38:366196 bool user_gesture = (webview()->focusedFrame() &&
6197 webview()->focusedFrame()->isProcessingUserGesture());
[email protected]a6d36cc2011-02-23 00:39:486198 GURL base(base_url);
6199 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
6200 if (base.GetOrigin() != absolute_url.GetOrigin()) {
6201 return;
6202 }
[email protected]f1a29a02011-10-06 23:08:446203 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
6204 UTF16ToUTF8(scheme),
6205 absolute_url,
[email protected]3a3b75a2012-06-01 08:38:366206 title,
6207 user_gesture));
[email protected]a6d36cc2011-02-23 00:39:486208}
6209
[email protected]310ebd6302011-10-10 19:06:286210WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:446211 WebKit::WebPageVisibilityState current_state = is_hidden() ?
6212 WebKit::WebPageVisibilityStateHidden :
6213 WebKit::WebPageVisibilityStateVisible;
6214 WebKit::WebPageVisibilityState override_state = current_state;
[email protected]e9ff79c2012-10-19 21:31:266215 if (GetContentClient()->renderer()->
[email protected]f59203a2011-06-07 10:01:446216 ShouldOverridePageVisibilityState(this,
6217 &override_state))
6218 return override_state;
6219 return current_state;
[email protected]94dec932011-05-26 20:04:216220}
6221
[email protected]273558fb2012-01-12 15:03:516222WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
[email protected]273558fb2012-01-12 15:03:516223 EnsureMediaStreamImpl();
6224 return media_stream_impl_;
6225}
6226
[email protected]a0629af92012-08-08 00:39:376227void RenderViewImpl::draggableRegionsChanged() {
6228 FOR_EACH_OBSERVER(
6229 RenderViewObserver,
6230 observers_,
6231 DraggableRegionsChanged(webview()->mainFrame()));
6232}
6233
[email protected]20657a82012-08-21 20:23:036234#if defined(OS_ANDROID)
6235WebContentDetectionResult RenderViewImpl::detectContentAround(
6236 const WebHitTestResult& touch_hit) {
6237 DCHECK(!touch_hit.isNull());
6238 DCHECK(!touch_hit.node().isNull());
6239 DCHECK(touch_hit.node().isTextNode());
6240
6241 // Process the position with all the registered content detectors until
6242 // a match is found. Priority is provided by their relative order.
6243 for (ContentDetectorList::const_iterator it = content_detectors_.begin();
6244 it != content_detectors_.end(); ++it) {
6245 ContentDetector::Result content = (*it)->FindTappedContent(touch_hit);
6246 if (content.valid) {
6247 return WebContentDetectionResult(content.content_boundaries,
6248 UTF8ToUTF16(content.text), content.intent_url);
6249 }
6250 }
6251 return WebContentDetectionResult();
6252}
6253
6254void RenderViewImpl::scheduleContentIntent(const WebURL& intent) {
6255 // Introduce a short delay so that the user can notice the content.
6256 MessageLoop::current()->PostDelayedTask(
6257 FROM_HERE,
6258 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, AsWeakPtr(),
6259 intent, expected_content_intent_id_),
6260 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds));
6261}
6262
6263void RenderViewImpl::cancelScheduledContentIntents() {
6264 ++expected_content_intent_id_;
6265}
6266
6267void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent,
6268 size_t request_id) {
6269 if (request_id != expected_content_intent_id_)
6270 return;
6271
6272 // Remove the content highlighting if any.
6273 scheduleComposite();
6274
6275 if (!intent.is_empty())
6276 Send(new ViewHostMsg_StartContentIntent(routing_id_, intent));
6277}
6278#endif
6279
[email protected]310ebd6302011-10-10 19:06:286280void RenderViewImpl::OnAsyncFileOpened(
6281 base::PlatformFileError error_code,
6282 IPC::PlatformFileForTransit file_for_transit,
6283 int message_id) {
[email protected]27a9ef32010-09-10 04:06:246284 pepper_delegate_.OnAsyncFileOpened(
6285 error_code,
6286 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
6287 message_id);
6288}
[email protected]caf706f2010-10-26 17:54:086289
[email protected]310ebd6302011-10-10 19:06:286290void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:476291 int request_id,
[email protected]d54305072011-06-22 20:58:436292 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:476293 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
[email protected]2b657fd2011-04-18 16:00:476294 handle);
[email protected]eb415bf0e2011-04-14 02:45:426295}
6296
[email protected]d8415ad92012-08-23 14:40:506297void RenderViewImpl::OnPpapiBrokerPermissionResult(
6298 int request_id,
6299 bool result) {
6300 pepper_delegate_.OnPpapiBrokerPermissionResult(request_id, result);
6301}
6302
[email protected]caf706f2010-10-26 17:54:086303#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:286304void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:156305 if (external_popup_menu_ == NULL) {
6306 // Crash reports from the field indicate that we can be notified with a
6307 // NULL external popup menu (we probably get notified twice).
6308 // If you hit this please file a bug against jcivelli and include the page
6309 // and steps to repro.
6310 NOTREACHED();
6311 return;
6312 }
[email protected]caf706f2010-10-26 17:54:086313 external_popup_menu_->DidSelectItem(selected_index);
6314 external_popup_menu_.reset();
6315}
6316#endif
[email protected]bb461532010-11-26 21:50:236317
[email protected]24d2b172012-05-26 00:54:126318#if defined(OS_ANDROID)
6319void RenderViewImpl::OnSelectPopupMenuItems(
6320 bool canceled,
6321 const std::vector<int>& selected_indices) {
6322 // It is possible to receive more than one of these calls if the user presses
6323 // a select faster than it takes for the show-select-popup IPC message to make
6324 // it to the browser UI thread. Ignore the extra-messages.
6325 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug.
6326 if (!external_popup_menu_.get())
6327 return;
6328
6329 external_popup_menu_->DidSelectItems(canceled, selected_indices);
6330 external_popup_menu_.reset();
6331}
6332#endif
6333
[email protected]310ebd6302011-10-10 19:06:286334void RenderViewImpl::OnContextMenuClosed(
[email protected]e9ff79c2012-10-19 21:31:266335 const CustomContextMenuContext& custom_context) {
[email protected]860ee642012-10-13 03:46:256336 if (custom_context.request_id) {
6337 // External request, should be in our map.
[email protected]e9ff79c2012-10-19 21:31:266338 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:256339 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:466340 if (client) {
6341 client->OnMenuClosed(custom_context.request_id);
6342 pending_context_menus_.Remove(custom_context.request_id);
6343 }
[email protected]860ee642012-10-13 03:46:256344 } else {
6345 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:086346 context_menu_node_.reset();
[email protected]860ee642012-10-13 03:46:256347 }
[email protected]521b2482011-01-15 00:10:106348}
[email protected]5a7b15a2011-08-22 22:48:186349
[email protected]310ebd6302011-10-10 19:06:286350void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:186351 if (!webview())
6352 return;
6353 WebFrame* main_frame = webview()->mainFrame();
6354 if (!main_frame)
6355 return;
6356 main_frame->enableViewSourceMode(true);
6357}
[email protected]67bfb83f2011-09-22 03:36:376358
[email protected]310ebd6302011-10-10 19:06:286359bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:086360 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:406361}
[email protected]7f3c7af2011-10-20 22:52:516362
[email protected]64d0e192011-12-09 14:44:206363void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7e9c5bb02012-05-14 13:58:316364 DCHECK(!java_bridge_dispatcher_);
[email protected]464750f2011-10-24 23:16:186365#if defined(ENABLE_JAVA_BRIDGE)
[email protected]7e9c5bb02012-05-14 13:58:316366 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this);
[email protected]464750f2011-10-24 23:16:186367#endif
[email protected]7f3c7af2011-10-20 22:52:516368}
[email protected]0720b532012-08-28 19:23:376369
6370void RenderViewImpl::OnUpdatedFrameTree(
6371 int process_id,
6372 int route_id,
6373 const std::string& frame_tree) {
[email protected]e12dbe6f2012-10-04 22:11:196374 // TODO(nasko): Remove once http://crbug.com/153701 is fixed.
6375 DCHECK(false);
[email protected]5fa9b36b2012-09-21 18:14:276376 // We should only act on this message if we are swapped out. It's possible
6377 // for this to happen due to races.
6378 if (!is_swapped_out_)
6379 return;
6380
[email protected]0720b532012-08-28 19:23:376381 base::DictionaryValue* frames = NULL;
6382 scoped_ptr<base::Value> tree(base::JSONReader::Read(frame_tree));
6383 if (tree.get() && tree->IsType(base::Value::TYPE_DICTIONARY))
6384 tree->GetAsDictionary(&frames);
6385
6386 updating_frame_tree_ = true;
6387 active_frame_id_map_.clear();
6388
6389 target_process_id_ = process_id;
6390 target_routing_id_ = route_id;
6391 CreateFrameTree(webview()->mainFrame(), frames);
6392
6393 updating_frame_tree_ = false;
6394}
[email protected]f9526d12012-10-18 01:55:036395
[email protected]efd7e47f2012-10-19 20:37:516396#if defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:036397bool RenderViewImpl::didTapMultipleTargets(
6398 const WebKit::WebGestureEvent& event,
6399 const WebVector<WebRect>& target_rects) {
[email protected]f9526d12012-10-18 01:55:036400 gfx::Rect finger_rect(
6401 event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2,
6402 event.data.tap.width, event.data.tap.height);
6403 gfx::Rect zoom_rect;
6404 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
6405 finger_rect, target_rects, GetSize(), &zoom_rect);
6406 if (!scale)
6407 return false;
6408
6409 gfx::Size canvas_size = zoom_rect.size();
6410 canvas_size = ToCeiledSize(canvas_size.Scale(scale));
6411 TransportDIB* transport_dib = NULL;
6412 {
6413 scoped_ptr<skia::PlatformCanvas> canvas(
6414 RenderProcess::current()->GetDrawingCanvas(&transport_dib,
6415 gfx::Rect(canvas_size)));
6416 if (!canvas.get())
6417 return false;
6418
6419 canvas->scale(scale, scale);
6420
6421 canvas->translate(-zoom_rect.x(), -zoom_rect.y());
6422 webwidget_->paint(webkit_glue::ToWebCanvas(canvas.get()), zoom_rect,
6423 WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent);
6424 }
6425 Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_,
6426 zoom_rect,
6427 canvas_size,
6428 transport_dib->id()));
6429
6430 return true;
6431}
[email protected]efd7e47f2012-10-19 20:37:516432#endif
[email protected]f9526d12012-10-18 01:55:036433
6434void RenderViewImpl::OnReleaseDisambiguationPopupDIB(
6435 TransportDIB::Handle dib_handle) {
6436 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle);
6437 RenderProcess::current()->ReleaseTransportDIB(dib);
6438}
[email protected]e9ff79c2012-10-19 21:31:266439
6440} // namespace content