blob: cbd27af2e539ecbf33c08acd6e73720b4b81cdcf [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]cffd7522012-10-23 19:10:5818#include "base/memory/scoped_ptr.h"
[email protected]084c8552012-08-12 22:51:2019#include "base/message_loop_proxy.h"
[email protected]835d7c82010-10-14 04:38:3820#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2821#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5122#include "base/process_util.h"
[email protected]7ddea9802012-02-22 23:08:0523#include "base/string_number_conversions.h"
[email protected]0a35efc2012-03-13 17:28:1324#include "base/string_piece.h"
[email protected]318bf5802011-08-08 17:12:4125#include "base/string_split.h"
initial.commit09911bf2008-07-26 23:55:2926#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2827#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2628#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2229#include "base/utf_string_conversions.h"
[email protected]65bfd9972012-10-19 03:39:3730#include "cc/switches.h"
[email protected]e93e04e2011-03-14 00:27:1031#include "content/common/appcache/appcache_dispatcher.h"
[email protected]14392a52012-05-02 20:28:4432#include "content/common/child_thread.h"
[email protected]127dd582011-03-16 21:32:1033#include "content/common/clipboard_messages.h"
[email protected]0720b532012-08-28 19:23:3734#include "content/common/content_constants_internal.h"
[email protected]37666cf2011-03-13 21:51:4235#include "content/common/database_messages.h"
[email protected]59f4f2fa2011-03-23 01:00:5536#include "content/common/drag_messages.h"
[email protected]16dd6e22012-03-01 19:08:2037#include "content/common/fileapi/file_system_dispatcher.h"
38#include "content/common/fileapi/webfilesystem_callback_dispatcher.h"
[email protected]c26ad882012-02-07 06:41:2039#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]a2ef54c2011-10-10 16:20:3140#include "content/common/intents_messages.h"
[email protected]7f3c7af2011-10-20 22:52:5141#include "content/common/java_bridge_messages.h"
[email protected]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]230b7ef2011-03-16 22:30:1964#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0265#include "content/renderer/devtools_agent.h"
[email protected]f9526d12012-10-18 01:55:0366#include "content/renderer/disambiguation_popup_helper.h"
[email protected]766a7082012-02-03 23:39:1567#include "content/renderer/dom_automation_controller.h"
[email protected]1910fe82012-05-10 00:04:1068#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]498bc512012-09-21 21:50:0869#include "content/renderer/do_not_track_bindings.h"
[email protected]55722152011-03-22 01:33:5370#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1971#include "content/renderer/geolocation_dispatcher.h"
[email protected]84a83e192012-03-09 18:43:4072#include "content/renderer/gpu/compositor_thread.h"
[email protected]1842fe22012-08-13 23:24:3573#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]7d4481d12012-09-24 21:26:4774#include "content/renderer/gpu/compositor_software_output_device_gl_adapter.h"
[email protected]1784b2f2011-11-24 10:53:4875#include "content/renderer/idle_user_detector.h"
[email protected]c52b2892012-03-07 11:01:0276#include "content/renderer/input_tag_speech_dispatcher.h"
[email protected]07161902011-11-11 09:57:4277#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0278#include "content/renderer/load_progress_tracker.h"
[email protected]273558fb2012-01-12 15:03:5179#include "content/renderer/media/media_stream_dependency_factory.h"
80#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:4081#include "content/renderer/media/media_stream_impl.h"
[email protected]6048d512012-01-28 03:14:4882#include "content/renderer/media/render_audiosourceprovider.h"
[email protected]090f7312011-08-05 23:26:4083#include "content/renderer/media/render_media_log.h"
[email protected]6048d512012-01-28 03:14:4884#include "content/renderer/media/renderer_gpu_video_decoder_factories.h"
[email protected]ccee4862012-10-03 18:34:2685#include "content/renderer/media/rtc_peer_connection_handler.h"
[email protected]4a19be92011-09-22 14:25:0286#include "content/renderer/mhtml_generator.h"
[email protected]230b7ef2011-03-16 22:30:1987#include "content/renderer/notification_provider.h"
[email protected]6f516082011-03-17 19:15:3588#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0589#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4490#include "content/renderer/render_thread_impl.h"
[email protected]89054502012-06-03 10:29:2491#include "content/renderer/render_view_mouse_lock_dispatcher.h"
[email protected]2cff0052011-03-18 16:51:4492#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3293#include "content/renderer/renderer_accessibility.h"
[email protected]2a84f9d2012-06-05 21:50:4394#include "content/renderer/renderer_accessibility_complete.h"
95#include "content/renderer/renderer_accessibility_focus_only.h"
[email protected]663bd9e2011-03-21 01:07:0196#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]da8543762012-03-20 08:52:2097#include "content/renderer/renderer_webcolorchooser_impl.h"
[email protected]64d09222012-05-25 10:10:3498#include "content/renderer/speech_recognition_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:3299#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:19100#include "content/renderer/v8_value_converter_impl.h"
[email protected]0a35efc2012-03-13 17:28:13101#include "content/renderer/web_intents_host.h"
[email protected]663bd9e2011-03-21 01:07:01102#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:35103#include "content/renderer/webplugin_delegate_proxy.h"
104#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:49105#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41106#include "media/base/media_switches.h"
[email protected]b80322902012-03-06 01:33:50107#include "media/base/message_loop_factory.h"
[email protected]37136d162012-04-09 23:39:19108#include "media/filters/audio_renderer_impl.h"
[email protected]e1d69d762011-12-13 05:12:18109#include "media/filters/gpu_video_decoder.h"
[email protected]d1ef81d2012-07-24 11:39:36110#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29111#include "net/base/escape.h"
112#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09113#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04114#include "net/http/http_util.h"
[email protected]1842fe22012-08-13 23:24:35115#include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutputSurface.h"
[email protected]8bd0fe62011-01-17 06:44:37116#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]97516a02012-10-23 18:19:25117#include "third_party/WebKit/Source/WebKit/chromium/public/WebColorName.h"
[email protected]f546640b2012-05-15 00:03:49118#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEvent.h"
119#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h"
[email protected]be2510c02012-05-28 14:52:14120#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:37122#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
123#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:37124#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
125#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]4b1146bc2012-07-10 18:46:03129#include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h"
[email protected]8bd0fe62011-01-17 06:44:37130#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37131#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57132#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58133#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
[email protected]592e20b2012-01-20 05:53:44134#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
[email protected]8b5af492011-11-28 21:50:58135#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14136#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]4e1eb3392012-05-18 00:08:05137#include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannel.h"
[email protected]8bd0fe62011-01-17 06:44:37138#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19139#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37140#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36141#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37142#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
143#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
144#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37145#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37146#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
147#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
148#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17149#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37150#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]10e5cf12011-04-13 04:10:40151#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51152#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08153#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
154#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
155#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
156#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
157#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
[email protected]132e281a2012-07-31 18:32:44158#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPBody.h"
[email protected]9c4bf232011-12-15 02:25:08159#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
[email protected]50da23d02012-04-13 17:47:48160#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00Handler.h"
161#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00HandlerClient.h"
[email protected]273558fb2012-01-12 15:03:51162#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
163#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
[email protected]9c4bf232011-12-15 02:25:08164#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
165#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
[email protected]f546640b2012-05-15 00:03:49166#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerializedScriptValue.h"
[email protected]9c4bf232011-12-15 02:25:08167#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]5fa3a062012-03-21 15:39:34168#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSocketStreamHandle.h"
[email protected]e6e90dc2011-12-03 00:01:37169#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
170#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
171#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
172#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
173#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
174#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26175#include "third_party/skia/include/core/SkBitmap.h"
[email protected]ddb034b2012-06-26 20:31:39176#include "ui/base/dialogs/selected_file_info.h"
[email protected]08397d52011-02-05 01:53:38177#include "ui/gfx/native_widget_types.h"
178#include "ui/gfx/point.h"
179#include "ui/gfx/rect.h"
[email protected]f9526d12012-10-18 01:55:03180#include "ui/gfx/size_conversions.h"
[email protected]c4a9e932011-03-05 04:05:55181#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04182#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]bb0e79472012-10-23 04:36:34183#include "webkit/base/file_path_string_conversions.h"
[email protected]b928936b2012-04-13 01:16:16184#include "webkit/dom_storage/dom_storage_types.h"
[email protected]25e18f82010-10-27 16:38:43185#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]18d5be92011-07-25 18:00:19186#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24187#include "webkit/glue/glue_serialize.h"
[email protected]3a3b75a2012-06-01 08:38:36188#include "webkit/glue/web_intent_service_data.h"
[email protected]851334d2012-06-15 22:39:31189#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07190#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29191#include "webkit/glue/webkit_glue.h"
[email protected]b9fd01ba2012-02-28 01:50:40192#include "webkit/glue/weburlresponse_extradata_impl.h"
[email protected]7e8b4d12012-01-20 23:39:51193#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
[email protected]a9288f52011-11-17 05:18:16194#include "webkit/media/webmediaplayer_impl.h"
[email protected]5f04c3532012-09-25 01:28:39195#include "webkit/media/webmediaplayer_ms.h"
[email protected]191eb3f72010-12-21 06:27:50196#include "webkit/plugins/npapi/plugin_list.h"
197#include "webkit/plugins/npapi/webplugin_delegate.h"
198#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
199#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52200#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29201
[email protected]25fb9b32012-04-27 03:21:55202#if defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:03203#include "content/common/android/device_info.h"
204#include "content/renderer/android/address_detector.h"
205#include "content/renderer/android/content_detector.h"
206#include "content/renderer/android/email_detector.h"
207#include "content/renderer/android/phone_number_detector.h"
[email protected]dbd3d212012-07-13 02:17:22208#include "content/renderer/media/stream_texture_factory_impl_android.h"
[email protected]780fc8242012-09-19 20:28:52209#include "content/renderer/media/webmediaplayer_proxy_impl_android.h"
[email protected]20657a82012-08-21 20:23:03210#include "third_party/WebKit/Source/WebKit/chromium/public/WebHitTestResult.h"
[email protected]59363fc92012-09-05 03:46:31211#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoint.h"
212#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatRect.h"
213#include "ui/gfx/rect_f.h"
[email protected]780fc8242012-09-19 20:28:52214#include "webkit/media/android/media_player_bridge_manager_impl.h"
[email protected]25fb9b32012-04-27 03:21:55215#include "webkit/media/android/webmediaplayer_android.h"
[email protected]780fc8242012-09-19 20:28:52216#include "webkit/media/android/webmediaplayer_impl_android.h"
217#include "webkit/media/android/webmediaplayer_in_process_android.h"
[email protected]2d7b82c2012-06-01 05:57:50218#include "webkit/media/android/webmediaplayer_manager_android.h"
[email protected]25fb9b32012-04-27 03:21:55219#elif defined(OS_WIN)
[email protected]6c8afae52009-01-22 02:24:57220// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57221// * theming
[email protected]f78452f2012-05-15 02:07:52222#include "ui/base/native_theme/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03223#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37224#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]f78452f2012-05-15 02:07:52225#include "ui/base/native_theme/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33226#elif defined(OS_MACOSX)
227#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57228#endif
229
[email protected]9892b472010-09-16 00:23:42230using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08231using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21232using WebKit::WebApplicationCacheHost;
233using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26234using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41235using WebKit::WebColor;
236using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59237using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44238using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51239using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55240using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28241using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00242using WebKit::WebDocument;
[email protected]f546640b2012-05-15 00:03:49243using WebKit::WebDOMEvent;
244using WebKit::WebDOMMessageEvent;
[email protected]e80c73b2009-04-07 23:24:58245using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25246using WebKit::WebDragOperation;
247using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51248using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51249using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08250using WebKit::WebExternalPopupMenu;
251using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47252using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22253using WebKit::WebFileSystem;
254using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49255using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59256using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48257using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45258using WebKit::WebFrame;
[email protected]3306f262012-09-21 19:20:42259using WebKit::WebGestureEvent;
[email protected]7e8b4d12012-01-20 23:39:51260using WebKit::WebGraphicsContext3D;
[email protected]ca948a22009-06-25 19:36:17261using WebKit::WebHistoryItem;
[email protected]132e281a2012-07-31 18:32:44262using WebKit::WebHTTPBody;
[email protected]42054a252011-05-17 18:02:13263using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41264using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50265using WebKit::WebInputElement;
[email protected]3306f262012-09-21 19:20:42266using WebKit::WebInputEvent;
[email protected]ffc8bed2012-01-21 01:23:15267using WebKit::WebIntentRequest;
268using WebKit::WebIntentServiceInfo;
[email protected]3d9689372009-09-10 04:29:17269using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28270using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17271using WebKit::WebMediaPlayerClient;
[email protected]2b942c332012-04-25 16:26:26272using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:28273using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28274using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51275using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19276using WebKit::WebPageSerializer;
277using WebKit::WebPageSerializerClient;
[email protected]50da23d02012-04-13 17:47:48278using WebKit::WebPeerConnection00Handler;
279using WebKit::WebPeerConnection00HandlerClient;
280using WebKit::WebPeerConnectionHandler;
281using WebKit::WebPeerConnectionHandlerClient;
[email protected]3d9689372009-09-10 04:29:17282using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36283using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40284using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49285using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09286using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52287using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59288using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51289using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52290using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15291using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40292using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35293using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29294using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17295using WebKit::WebSecurityPolicy;
[email protected]f546640b2012-05-15 00:03:49296using WebKit::WebSerializedScriptValue;
[email protected]2fab253a2009-08-17 23:00:59297using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42298using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02299using WebKit::WebSize;
[email protected]5fa3a062012-03-21 15:39:34300using WebKit::WebSocketStreamHandle;
[email protected]bd92c3a2010-01-13 05:02:34301using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40302using WebKit::WebStorageQuotaCallbacks;
303using WebKit::WebStorageQuotaError;
304using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28305using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51306using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52307using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24308using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28309using WebKit::WebURL;
310using WebKit::WebURLError;
311using WebKit::WebURLRequest;
312using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28313using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03314using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28315using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26316using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26317using appcache::WebApplicationCacheHostImpl;
318using base::Time;
319using base::TimeDelta;
[email protected]e9ff79c2012-10-19 21:31:26320
[email protected]6fdd4182010-10-14 23:59:26321using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23322using webkit_glue::ResourceFetcher;
[email protected]6717bf272012-05-11 23:31:25323using webkit_glue::WebPreferences;
[email protected]b9fd01ba2012-02-28 01:50:40324using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33325
[email protected]20657a82012-08-21 20:23:03326#if defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:03327using WebKit::WebContentDetectionResult;
[email protected]59363fc92012-09-05 03:46:31328using WebKit::WebFloatPoint;
329using WebKit::WebFloatRect;
[email protected]20657a82012-08-21 20:23:03330using WebKit::WebHitTestResult;
331#endif
332
[email protected]e9ff79c2012-10-19 21:31:26333namespace content {
334
initial.commit09911bf2008-07-26 23:55:29335//-----------------------------------------------------------------------------
336
[email protected]310ebd6302011-10-10 19:06:28337typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49338static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02339
[email protected]882daa92009-11-05 16:31:31340// Time, in seconds, we delay before sending content state changes (such as form
341// state and scroll position) to the browser. We delay sending changes to avoid
342// spamming the browser.
343// To avoid having tab/session restore require sending a message to get the
344// current content state during tab closing we use a shorter timeout for the
345// foreground renderer. This means there is a small window of time from which
346// content state is modified and not sent to session restore, but this is
347// better than having to wake up all renderers during shutdown.
348static const int kDelaySecondsForContentStateSyncHidden = 5;
349static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29350
[email protected]e99ef6f2011-10-16 01:13:00351static const size_t kExtraCharsBeforeAndAfterSelection = 100;
352
[email protected]0aa55312008-10-17 21:53:08353// The maximum number of popups that can be spawned from one page.
354static const int kMaximumNumberOfUnacknowledgedPopups = 25;
355
[email protected]c514d6372011-08-16 22:54:44356static const float kScalingIncrement = 0.1f;
357
[email protected]47578fa02011-11-02 19:34:41358static const float kScalingIncrementForGesture = 0.01f;
359
[email protected]20657a82012-08-21 20:23:03360#if defined(OS_ANDROID)
361// Delay between tapping in content and launching the associated android intent.
362// Used to allow users see what has been recognized as content.
363static const size_t kContentIntentDelayMilliseconds = 700;
364#endif
365
[email protected]f546640b2012-05-15 00:03:49366static RenderViewImpl* FromRoutingID(int32 routing_id) {
367 return static_cast<RenderViewImpl*>(
368 ChildThread::current()->ResolveRoute(routing_id));
369}
370
[email protected]0720b532012-08-28 19:23:37371static WebKit::WebFrame* FindFrameByID(WebKit::WebFrame* root, int frame_id) {
372 for (WebFrame* frame = root; frame; frame = frame->traverseNext(false)) {
373 if (frame->identifier() == frame_id)
374 return frame;
375 }
376 return NULL;
377}
378
[email protected]726985e22009-06-18 21:09:28379static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
380 WebVector<WebURL> urls;
381 ds->redirectChain(urls);
382 result->reserve(urls.size());
383 for (size_t i = 0; i < urls.size(); ++i)
384 result->push_back(urls[i]);
385}
386
[email protected]007733c2011-11-17 00:34:07387// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44388// the AltErrorPageResourceFetcher is reset.
389static void StopAltErrorPageFetcher(WebDataSource* data_source) {
390 if (data_source) {
[email protected]007733c2011-11-17 00:34:07391 DocumentState* document_state = DocumentState::FromDataSource(data_source);
392 if (document_state)
393 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44394 }
395}
396
[email protected]007733c2011-11-17 00:34:07397static bool IsReload(const ViewMsg_Navigate_Params& params) {
398 return
399 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
[email protected]7c16976c2012-08-04 02:38:23400 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE ||
401 params.navigation_type ==
402 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]007733c2011-11-17 00:34:07403}
404
[email protected]b9fd01ba2012-02-28 01:50:40405static WebReferrerPolicy GetReferrerPolicyFromRequest(
[email protected]ca662822012-05-11 17:53:59406 WebFrame* frame,
[email protected]445e1042011-12-03 21:03:15407 const WebURLRequest& request) {
408 return request.extraData() ?
409 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
[email protected]ca662822012-05-11 17:53:59410 frame->document().referrerPolicy();
[email protected]445e1042011-12-03 21:03:15411}
412
[email protected]b9fd01ba2012-02-28 01:50:40413static WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
414 const WebURLResponse& response) {
415 return static_cast<WebURLResponseExtraDataImpl*>(
416 response.extraData());
417}
418
[email protected]2149cc622012-02-14 01:12:12419NOINLINE static void CrashIntentionally() {
420 // NOTE(shess): Crash directly rather than using NOTREACHED() so
421 // that the signature is easier to triage in crash reports.
422 volatile int* zero = NULL;
423 *zero = 0;
424}
425
[email protected]8bf1048012012-02-08 01:22:18426static void MaybeHandleDebugURL(const GURL& url) {
427 if (!url.SchemeIs(chrome::kChromeUIScheme))
428 return;
429 if (url == GURL(chrome::kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12430 CrashIntentionally();
[email protected]8bf1048012012-02-08 01:22:18431 } else if (url == GURL(chrome::kChromeUIKillURL)) {
432 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
433 } else if (url == GURL(chrome::kChromeUIHangURL)) {
434 for (;;) {
435 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
436 }
437 } else if (url == GURL(chrome::kChromeUIShorthangURL)) {
438 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
439 }
440}
441
[email protected]fd3238af2012-05-22 18:55:30442// Returns false unless this is a top-level navigation.
443static bool IsTopLevelNavigation(WebFrame* frame) {
444 return frame->parent() == NULL;
445}
446
447// Returns false unless this is a top-level navigation that crosses origins.
448static bool IsNonLocalTopLevelNavigation(const GURL& url,
449 WebFrame* frame,
450 WebNavigationType type) {
451 if (!IsTopLevelNavigation(frame))
452 return false;
453
454 // Navigations initiated within Webkit are not sent out to the external host
455 // in the following cases.
456 // 1. The url scheme is not http/https
457 // 2. The origin of the url and the opener is the same in which case the
458 // opener relationship is maintained.
459 // 3. Reloads/form submits/back forward navigations
460 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
461 return false;
462
463 // Not interested in reloads/form submits/resubmits/back forward navigations.
464 if (type != WebKit::WebNavigationTypeReload &&
465 type != WebKit::WebNavigationTypeFormSubmitted &&
466 type != WebKit::WebNavigationTypeFormResubmitted &&
467 type != WebKit::WebNavigationTypeBackForward) {
468 // The opener relationship between the new window and the parent allows the
469 // new window to script the parent and vice versa. This is not allowed if
470 // the origins of the two domains are different. This can be treated as a
471 // top level navigation and routed back to the host.
472 WebKit::WebFrame* opener = frame->opener();
473 if (!opener) {
474 return true;
475 }
476
477 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
478 return true;
479 }
480 return false;
481}
482
[email protected]38761452012-10-18 16:31:59483static void NotifyTimezoneChange(WebKit::WebFrame* frame) {
484 v8::HandleScope handle_scope;
485 v8::Context::Scope context_scope(frame->mainWorldScriptContext());
486 v8::Date::DateTimeConfigurationChangeNotification();
487 WebKit::WebFrame* child = frame->firstChild();
488 for (; child; child = child->nextSibling())
489 NotifyTimezoneChange(child);
490}
491
initial.commit09911bf2008-07-26 23:55:29492///////////////////////////////////////////////////////////////////////////////
493
[email protected]310ebd6302011-10-10 19:06:28494struct RenderViewImpl::PendingFileChooser {
[email protected]e9ff79c2012-10-19 21:31:26495 PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c)
[email protected]cdaf8d02010-03-30 19:52:47496 : params(p),
497 completion(c) {
498 }
[email protected]e9ff79c2012-10-19 21:31:26499 FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47500 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
501};
502
[email protected]217690d2012-01-27 07:33:11503namespace {
504
505class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
506 public:
[email protected]82114f52012-03-20 22:53:41507 explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget)
[email protected]217690d2012-01-27 07:33:11508 : webwidget_(webwidget) {}
509
510 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
511 if (succeeded)
512 webwidget_->didAcquirePointerLock();
513 else
514 webwidget_->didNotAcquirePointerLock();
515 }
516
517 virtual void OnMouseLockLost() OVERRIDE {
518 webwidget_->didLosePointerLock();
519 }
520
521 virtual bool HandleMouseLockedInputEvent(
522 const WebKit::WebMouseEvent &event) OVERRIDE {
523 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
524 return false;
525 }
526
527 private:
528 WebKit::WebWidget* webwidget_;
529};
530
[email protected]86cd9472012-02-03 19:51:05531int64 ExtractPostId(const WebHistoryItem& item) {
532 if (item.isNull())
533 return -1;
534
535 if (item.httpBody().isNull())
536 return -1;
537
538 return item.httpBody().identifier();
539}
540
[email protected]217690d2012-01-27 07:33:11541} // namespace
542
[email protected]daf82f82011-10-31 22:35:31543RenderViewImpl::RenderViewImpl(
544 gfx::NativeViewId parent_hwnd,
545 int32 opener_id,
[email protected]e9ff79c2012-10-19 21:31:26546 const RendererPreferences& renderer_prefs,
[email protected]daf82f82011-10-31 22:35:31547 const WebPreferences& webkit_prefs,
548 SharedRenderViewCounter* counter,
549 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56550 int32 surface_id,
[email protected]daf82f82011-10-31 22:35:31551 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46552 const string16& frame_name,
[email protected]14392a52012-05-02 20:28:44553 bool is_renderer_created,
554 bool swapped_out,
[email protected]6fd35b72012-03-01 19:46:41555 int32 next_page_id,
[email protected]842f10652012-06-06 01:54:04556 const WebKit::WebScreenInfo& screen_info,
[email protected]3e3c4522012-04-13 21:16:29557 AccessibilityMode accessibility_mode)
[email protected]842f10652012-06-06 01:54:04558 : RenderWidget(WebKit::WebPopupTypeNone, screen_info, swapped_out),
[email protected]676126f72011-01-15 00:03:51559 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02560 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09561 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02562 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24563 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21564 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02565 opened_by_user_gesture_(true),
566 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24567 page_id_(-1),
568 last_page_id_sent_to_browser_(-1),
[email protected]74ce1ad2011-12-16 21:51:46569 next_page_id_(next_page_id),
[email protected]3cc72b12010-03-18 23:03:00570 history_list_offset_(-1),
571 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02572 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55573 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31574 cached_is_main_frame_pinned_to_left_(false),
575 cached_is_main_frame_pinned_to_right_(false),
576 cached_has_main_frame_horizontal_scrollbar_(false),
577 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]3354d3e2010-06-10 19:53:02578 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51579 geolocation_dispatcher_(NULL),
[email protected]c52b2892012-03-07 11:01:02580 input_tag_speech_dispatcher_(NULL),
[email protected]64d09222012-05-25 10:10:34581 speech_recognition_dispatcher_(NULL),
[email protected]676126f72011-01-15 00:03:51582 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51583 media_stream_dispatcher_(NULL),
[email protected]1bc65a42012-04-23 09:31:25584 media_stream_impl_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41585 devtools_agent_(NULL),
[email protected]2a84f9d2012-06-05 21:50:43586 accessibility_mode_(AccessibilityModeOff),
[email protected]063afcb2011-09-29 07:54:32587 renderer_accessibility_(NULL),
[email protected]7e9c5bb02012-05-14 13:58:31588 java_bridge_dispatcher_(NULL),
[email protected]217690d2012-01-27 07:33:11589 mouse_lock_dispatcher_(NULL),
[email protected]20657a82012-08-21 20:23:03590#if defined(OS_ANDROID)
[email protected]4d0f8182012-10-19 23:14:47591 body_background_color_(SK_ColorWHITE),
[email protected]20657a82012-08-21 20:23:03592 expected_content_intent_id_(0),
[email protected]780fc8242012-09-19 20:28:52593 media_player_proxy_(NULL),
[email protected]55750b32012-09-21 14:05:03594 synchronous_find_active_match_ordinal_(-1),
[email protected]8e603cd92012-10-23 22:29:26595 ALLOW_THIS_IN_INITIALIZER_LIST(
596 load_progress_tracker_(new LoadProgressTracker(this))),
[email protected]20657a82012-08-21 20:23:03597#endif
[email protected]4fb60142011-08-09 02:22:08598 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18599 handling_select_range_(false),
600#if defined(OS_WIN)
601 focused_plugin_id_(-1),
602#endif
[email protected]0720b532012-08-28 19:23:37603 updating_frame_tree_(false),
604 pending_frame_tree_update_(false),
605 target_process_id_(0),
606 target_routing_id_(0),
[email protected]ef5e98e2011-12-06 09:49:18607 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]ce2b28e2012-08-09 15:53:57608 set_throttle_input_events(renderer_prefs.throttle_input_events);
[email protected]676126f72011-01-15 00:03:51609 routing_id_ = routing_id;
[email protected]9f4f3322012-01-18 22:29:56610 surface_id_ = surface_id;
[email protected]14392a52012-05-02 20:28:44611 if (opener_id != MSG_ROUTING_NONE && is_renderer_created)
[email protected]676126f72011-01-15 00:03:51612 opener_id_ = opener_id;
613
[email protected]74ce1ad2011-12-16 21:51:46614 // Ensure we start with a valid next_page_id_ from the browser.
615 DCHECK_GE(next_page_id_, 0);
616
[email protected]21b3a6ae2011-11-30 00:45:29617#if defined(ENABLE_NOTIFICATIONS)
618 notification_provider_ = new NotificationProvider(this);
619#else
620 notification_provider_ = NULL;
621#endif
622
[email protected]11fee2332011-03-29 20:36:35623 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11624 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35625
[email protected]20657a82012-08-21 20:23:03626 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
627
628#if defined(OS_ANDROID)
[email protected]e9ff79c2012-10-19 21:31:26629 scoped_ptr<DeviceInfo> device_info(new DeviceInfo());
[email protected]20657a82012-08-21 20:23:03630
[email protected]43b06002012-10-11 17:13:26631 webview()->setDeviceScaleFactor(device_info->GetDPIScale());
632
[email protected]20657a82012-08-21 20:23:03633 const std::string region_code =
634 command_line.HasSwitch(switches::kNetworkCountryIso)
635 ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso)
636 : device_info->GetNetworkCountryIso();
637 content_detectors_.push_back(linked_ptr<ContentDetector>(
638 new AddressDetector()));
639 content_detectors_.push_back(linked_ptr<ContentDetector>(
640 new PhoneNumberDetector(region_code)));
641 content_detectors_.push_back(linked_ptr<ContentDetector>(
642 new EmailDetector()));
643#endif
644
[email protected]676126f72011-01-15 00:03:51645 if (counter) {
646 shared_popup_counter_ = counter;
[email protected]14392a52012-05-02 20:28:44647 // Only count this if it isn't swapped out upon creation.
648 if (!swapped_out)
649 shared_popup_counter_->data++;
[email protected]676126f72011-01-15 00:03:51650 decrement_shared_popup_at_destruction_ = true;
651 } else {
652 shared_popup_counter_ = new SharedRenderViewCounter(0);
653 decrement_shared_popup_at_destruction_ = false;
654 }
655
[email protected]380244092011-10-07 17:26:27656 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51657 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47658 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51659 AddRef();
660
661 // If this is a popup, we must wait for the CreatingNew_ACK message before
662 // completing initialization. Otherwise, we can finish it now.
[email protected]6cd7c6b2012-10-25 03:26:23663 if (opener_id_ == MSG_ROUTING_NONE) {
[email protected]676126f72011-01-15 00:03:51664 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55665 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51666 }
667
[email protected]34c61bd52011-05-02 19:38:33668 g_view_map.Get().insert(std::make_pair(webview(), this));
[email protected]60051ec2012-06-08 22:40:57669 webview()->setDeviceScaleFactor(device_scale_factor_);
[email protected]34c61bd52011-05-02 19:38:33670 webkit_preferences_.Apply(webview());
671 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35672 if (!frame_name.empty())
673 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33674 webview()->settings()->setMinimumTimerInterval(
675 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
676 webkit_glue::kForegroundTabTimerInterval);
677
678 OnSetRendererPrefs(renderer_prefs);
679
[email protected]676126f72011-01-15 00:03:51680 host_window_ = parent_hwnd;
681
[email protected]4fb0f202012-05-30 22:44:53682#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02683 if (!media_stream_dispatcher_)
684 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32685#endif
[email protected]735873d2012-01-25 23:31:02686
[email protected]8f6a3b852011-07-19 16:48:56687 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32688#if defined(OS_MACOSX)
689 new TextInputClientObserver(this);
690#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56691
[email protected]2d7b82c2012-06-01 05:57:50692#if defined(OS_ANDROID)
693 media_player_manager_.reset(
694 new webkit_media::WebMediaPlayerManagerAndroid());
695#endif
696
[email protected]217690d2012-01-27 07:33:11697 // The next group of objects all implement RenderViewObserver, so are deleted
698 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41699 devtools_agent_ = new DevToolsAgent(this);
[email protected]89054502012-06-03 10:29:24700 mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
[email protected]0fc7dea72012-02-09 03:47:40701 intents_host_ = new WebIntentsHost(this);
[email protected]063afcb2011-09-29 07:54:32702
[email protected]2a84f9d2012-06-05 21:50:43703 // Create renderer_accessibility_ if needed.
704 OnSetAccessibilityMode(accessibility_mode);
705
[email protected]1784b2f2011-11-24 10:53:48706 new IdleUserDetector(this);
707
[email protected]766a7082012-02-03 23:39:15708 if (command_line.HasSwitch(switches::kDomAutomationController))
[email protected]e9ff79c2012-10-19 21:31:26709 enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION;
[email protected]766a7082012-02-03 23:39:15710
[email protected]5b52cd2f712012-03-28 02:12:48711 ProcessViewLayoutFlags(command_line);
[email protected]7ddea9802012-02-22 23:08:05712
[email protected]e9ff79c2012-10-19 21:31:26713 GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44714
715 // If we have an opener_id but we weren't created by a renderer, then
716 // it's the browser asking us to set our opener to another RenderView.
[email protected]14392a52012-05-02 20:28:44717 if (opener_id != MSG_ROUTING_NONE && !is_renderer_created) {
[email protected]f546640b2012-05-15 00:03:49718 RenderViewImpl* opener_view = FromRoutingID(opener_id);
719 if (opener_view)
720 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
[email protected]14392a52012-05-02 20:28:44721 }
722
723 // If we are initially swapped out, navigate to kSwappedOutURL.
724 // This ensures we are in a unique origin that others cannot script.
725 if (is_swapped_out_)
[email protected]0720b532012-08-28 19:23:37726 NavigateToSwappedOutURL(webview()->mainFrame());
initial.commit09911bf2008-07-26 23:55:29727}
728
[email protected]310ebd6302011-10-10 19:06:28729RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03730 history_page_ids_.clear();
731
[email protected]0aa55312008-10-17 21:53:08732 if (decrement_shared_popup_at_destruction_)
733 shared_popup_counter_->data--;
734
[email protected]a1128322009-10-06 18:38:46735 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47736 while (!file_chooser_completions_.empty()) {
737 if (file_chooser_completions_.front()->completion) {
738 file_chooser_completions_.front()->completion->didChooseFile(
739 WebVector<WebString>());
740 }
741 file_chooser_completions_.pop_front();
742 }
[email protected]a1128322009-10-06 18:38:46743
[email protected]83dde542009-09-11 20:59:55744#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11745 // Destroy all fake plugin window handles on the browser side.
746 while (!fake_plugin_window_handles_.empty()) {
747 // Make sure no NULL plugin window handles were inserted into this list.
748 DCHECK(*fake_plugin_window_handles_.begin());
749 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
750 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
751 }
[email protected]83dde542009-09-11 20:59:55752#endif
[email protected]98324892009-09-09 21:16:05753
[email protected]60c42a8c72009-10-09 04:08:59754#ifndef NDEBUG
755 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49756 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59757 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
758 DCHECK_NE(this, it->second) << "Failed to call Close?";
759#endif
[email protected]676126f72011-01-15 00:03:51760
[email protected]310ebd6302011-10-10 19:06:28761 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51762 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59763}
764
765/*static*/
[email protected]310ebd6302011-10-10 19:06:28766RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31767 ViewMap* views = g_view_map.Pointer();
768 ViewMap::iterator it = views->find(webview);
769 return it == views->end() ? NULL : it->second;
770}
771
772/*static*/
[email protected]e9ff79c2012-10-19 21:31:26773RenderView* RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28774 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31775}
776
777/*static*/
[email protected]e9ff79c2012-10-19 21:31:26778void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49779 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59780 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
781 if (!visitor->Visit(it->second))
782 return;
783 }
784}
785
786/*static*/
[email protected]310ebd6302011-10-10 19:06:28787RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15788 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08789 int32 opener_id,
[email protected]e9ff79c2012-10-19 21:31:26790 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08791 const WebPreferences& webkit_prefs,
792 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34793 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56794 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26795 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46796 const string16& frame_name,
[email protected]14392a52012-05-02 20:28:44797 bool is_renderer_created,
798 bool swapped_out,
[email protected]6fd35b72012-03-01 19:46:41799 int32 next_page_id,
[email protected]842f10652012-06-06 01:54:04800 const WebKit::WebScreenInfo& screen_info,
[email protected]3e3c4522012-04-13 21:16:29801 AccessibilityMode accessibility_mode) {
initial.commit09911bf2008-07-26 23:55:29802 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28803 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51804 parent_hwnd,
805 opener_id,
806 renderer_prefs,
807 webkit_prefs,
808 counter,
809 routing_id,
[email protected]9f4f3322012-01-18 22:29:56810 surface_id,
[email protected]676126f72011-01-15 00:03:51811 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46812 frame_name,
[email protected]14392a52012-05-02 20:28:44813 is_renderer_created,
814 swapped_out,
[email protected]6fd35b72012-03-01 19:46:41815 next_page_id,
[email protected]842f10652012-06-06 01:54:04816 screen_info,
[email protected]3e3c4522012-04-13 21:16:29817 accessibility_mode);
initial.commit09911bf2008-07-26 23:55:29818}
819
[email protected]310ebd6302011-10-10 19:06:28820void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51821 observers_.AddObserver(observer);
822}
823
[email protected]310ebd6302011-10-10 19:06:28824void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
825 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51826 observers_.RemoveObserver(observer);
827}
828
[email protected]310ebd6302011-10-10 19:06:28829WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26830 return static_cast<WebKit::WebView*>(webwidget());
831}
832
[email protected]310ebd6302011-10-10 19:06:28833void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51834 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29835}
836
[email protected]310ebd6302011-10-10 19:06:28837void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26838 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30839 // If the renderer is visible, set initial visibility and focus state.
840 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34841#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30842 delegate->SetContainerVisibility(true);
843 if (webview() && webview()->isActive())
844 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34845#endif
[email protected]49232292010-09-03 19:07:30846 }
[email protected]784ea1ab2010-09-18 00:02:34847 // Plugins start assuming the content has focus (so that they work in
848 // environments where RenderView isn't hosting them), so we always have to
849 // set the initial state. See webplugin_delegate_impl.h for details.
850 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26851}
852
[email protected]310ebd6302011-10-10 19:06:28853void RenderViewImpl::UnregisterPluginDelegate(
854 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26855 plugin_delegates_.erase(delegate);
856}
[email protected]d8fd6fa2010-02-01 15:54:26857
[email protected]310ebd6302011-10-10 19:06:28858bool RenderViewImpl::GetPluginInfo(const GURL& url,
859 const GURL& page_url,
860 const std::string& mime_type,
861 webkit::WebPluginInfo* plugin_info,
862 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08863 bool found = false;
864 Send(new ViewHostMsg_GetPluginInfo(
865 routing_id_, url, page_url, mime_type, &found, plugin_info,
866 actual_mime_type));
867 return found;
868}
869
[email protected]7a1ec28a2012-03-28 21:10:24870void RenderViewImpl::TransferActiveWheelFlingAnimation(
871 const WebKit::WebActiveWheelFlingParameters& params) {
872 if (webview())
873 webview()->transferActiveWheelFlingAnimation(params);
874}
875
[email protected]8fe8f742012-06-14 00:36:08876bool RenderViewImpl::HasIMETextFocus() {
877 return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
878}
879
[email protected]310ebd6302011-10-10 19:06:28880bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27881 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27882 if (main_frame)
[email protected]e9ff79c2012-10-19 21:31:26883 GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26884
[email protected]676126f72011-01-15 00:03:51885 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
886 RenderViewObserver* observer;
887 while ((observer = it.GetNext()) != NULL)
888 if (observer->OnMessageReceived(message))
889 return true;
[email protected]b2abac72009-02-26 12:39:28890
[email protected]a95986a82010-12-24 06:19:28891 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40892 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28893 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29894 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
895 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56896 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29897 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
898 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
899 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
900 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
901 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15902 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29903 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
904 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
905 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]45a599062012-09-07 20:09:06906 IPC_MESSAGE_HANDLER(ViewMsg_ReplaceAll, OnReplaceAll)
907 IPC_MESSAGE_HANDLER(ViewMsg_Unselect, OnUnselect)
908 IPC_MESSAGE_HANDLER(ViewMsg_SetEditableSelectionOffsets,
909 OnSetEditableSelectionOffsets)
910 IPC_MESSAGE_HANDLER(ViewMsg_SetCompositionFromExistingText,
911 OnSetCompositionFromExistingText)
912 IPC_MESSAGE_HANDLER(ViewMsg_ExtendSelectionAndDelete,
913 OnExtendSelectionAndDelete)
[email protected]4fb60142011-08-09 02:22:08914 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29915 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15916 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29917 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49918 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
[email protected]630e26b2008-10-14 22:55:17919 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17920 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41921 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54922 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
923 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29924 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18925 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
926 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29927 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]f546640b2012-05-15 00:03:49928 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
[email protected]1810e132009-03-24 23:35:48929 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55930 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
931 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
932 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
933 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
934 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
935 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
936 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45937 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40938 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29939 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19940 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
941 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29942 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
943 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]38761452012-10-18 16:31:59944 IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone)
initial.commit09911bf2008-07-26 23:55:29945 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51946 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
947 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29948 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04949 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15950 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29951 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
952 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08953 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
954 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00955 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16956 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14957 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25958 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
959 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:47960 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:34961 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:10962 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
963 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51964 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56965 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]77829642012-05-15 14:47:17966 IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent,
967 OnOrientationChangeEvent)
[email protected]81375e872012-01-11 21:40:36968 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:34969 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]7a17bac02012-03-07 21:58:12970 IPC_MESSAGE_HANDLER(ViewMsg_SetNavigationStartTime,
971 OnSetNavigationStartTime)
[email protected]446705872009-09-10 07:22:48972 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33973 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33974 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
975 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24976 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42977 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
978 OnPpapiBrokerChannelCreated)
[email protected]d8415ad92012-08-23 14:40:50979 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult,
980 OnPpapiBrokerPermissionResult)
[email protected]18d5be92011-07-25 18:00:19981 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
982 OnGetAllSavableResourceLinksForCurrentPage)
983 IPC_MESSAGE_HANDLER(
984 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
985 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]521b2482011-01-15 00:10:10986 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51987 // TODO(viettrungluu): Move to a separate message filter.
[email protected]9e1ad4b2011-08-14 16:49:19988 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
989 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18990 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]7f3c7af2011-10-20 22:52:51991 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]2a84f9d2012-06-05 21:50:43992 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode)
[email protected]0720b532012-08-28 19:23:37993 IPC_MESSAGE_HANDLER(ViewMsg_UpdateFrameTree, OnUpdatedFrameTree)
[email protected]55750b32012-09-21 14:05:03994#if defined(OS_ANDROID)
995 IPC_MESSAGE_HANDLER(ViewMsg_ActivateNearestFindResult,
996 OnActivateNearestFindResult)
997 IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects)
998 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
999 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewMsg_SynchronousFind, OnSynchronousFind)
[email protected]9b7d11e2012-10-08 19:24:141000 IPC_MESSAGE_HANDLER(ViewMsg_UndoScrollFocusedEditableNodeIntoView,
1001 OnUndoScrollFocusedEditableNodeIntoRect)
[email protected]55750b32012-09-21 14:05:031002#elif defined(OS_MACOSX)
1003 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
1004 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1005 OnPluginImeCompositionCompleted)
1006 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1007 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
1008 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
1009 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
1010#endif
[email protected]f9526d12012-10-18 01:55:031011 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB,
1012 OnReleaseDisambiguationPopupDIB)
[email protected]9e1ad4b2011-08-14 16:49:191013
initial.commit09911bf2008-07-26 23:55:291014 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281015 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291016 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401017
1018 if (!msg_is_ok) {
1019 // The message had a handler, but its deserialization failed.
1020 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:281021 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:401022 }
1023
[email protected]a95986a82010-12-24 06:19:281024 return handled;
initial.commit09911bf2008-07-26 23:55:291025}
1026
[email protected]310ebd6302011-10-10 19:06:281027void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]8bf1048012012-02-08 01:22:181028 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:291029 if (!webview())
1030 return;
1031
[email protected]440a0e52011-09-13 17:38:581032 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
1033
[email protected]007733c2011-11-17 00:34:071034 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:031035
1036 // If this is a stale back/forward (due to a recent navigation the browser
1037 // didn't know about), ignore it.
1038 if (IsBackForwardToStaleEntry(params, is_reload))
1039 return;
1040
[email protected]992db4c2011-05-12 15:37:151041 // Swap this renderer back in if necessary.
[email protected]961541a92012-06-01 21:15:281042 if (is_swapped_out_) {
1043 // We marked the view as hidden when swapping the view out, so be sure to
1044 // reset the visibility state before navigating to the new URL.
1045 webview()->setVisibilityState(visibilityState(), false);
[email protected]992db4c2011-05-12 15:37:151046 SetSwappedOut(false);
[email protected]961541a92012-06-01 21:15:281047 }
[email protected]992db4c2011-05-12 15:37:151048
[email protected]3cc72b12010-03-18 23:03:001049 history_list_offset_ = params.current_history_list_offset;
1050 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:031051 if (history_list_length_ >= 0)
1052 history_page_ids_.resize(history_list_length_, -1);
1053 if (params.pending_history_list_offset >= 0 &&
1054 params.pending_history_list_offset < history_list_length_)
1055 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:001056
[email protected]e9ff79c2012-10-19 21:31:261057 GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:291058
[email protected]26aa0482009-09-30 16:55:271059 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451060 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291061 // We cannot reload if we do not have any history state. This happens, for
1062 // example, when recovering from a crash. Our workaround here is a bit of
1063 // a hack since it means that reload after a crashed tab does not cause an
1064 // end-to-end cache validation.
1065 is_reload = false;
1066 }
1067
[email protected]007733c2011-11-17 00:34:071068 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
1069 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:501070
[email protected]04d3c6e2009-05-22 17:00:131071 // If we are reloading, then WebKit will use the history state of the current
1072 // page, so we should just ignore any given history state. Otherwise, if we
1073 // have history state, then we need to navigate to it, which corresponds to a
1074 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551075 if (is_reload) {
[email protected]7c16976c2012-08-04 02:38:231076 bool reload_original_url =
1077 (params.navigation_type ==
1078 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]ecbf10d2010-02-18 13:03:291079 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:021080 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]7c16976c2012-08-04 02:38:231081
1082 if (reload_original_url)
1083 main_frame->reloadWithOverrideURL(params.url, true);
1084 else
1085 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551086 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131087 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581088 DCHECK_NE(params.page_id, -1);
[email protected]f707573e62012-10-18 09:38:071089 WebHistoryItem item = webkit_glue::HistoryItemFromString(params.state);
1090 if (!item.isNull())
1091 main_frame->loadHistoryItem(item);
[email protected]d1ef81d2012-07-24 11:39:361092 } else if (!params.base_url_for_data_url.is_empty()) {
1093 // A loadData request with a specified base URL.
1094 std::string mime_type, charset, data;
1095 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) {
1096 main_frame->loadData(
1097 WebData(data.c_str(), data.length()),
1098 WebString::fromUTF8(mime_type),
1099 WebString::fromUTF8(charset),
1100 params.base_url_for_data_url,
1101 params.history_url_for_data_url,
1102 false);
1103 } else {
1104 CHECK(false) <<
1105 "Invalid URL passed: " << params.url.possibly_invalid_spec();
1106 }
[email protected]04d3c6e2009-05-22 17:00:131107 } else {
1108 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281109 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291110
[email protected]e6f546c32009-07-01 17:12:551111 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:231112 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131113
[email protected]dd7daa82009-08-10 05:46:451114 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551115 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131116
[email protected]445e1042011-12-03 21:03:151117 if (params.referrer.url.is_valid()) {
1118 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
1119 params.referrer.policy,
1120 params.url,
1121 WebString::fromUTF8(params.referrer.url.spec()));
1122 if (!referrer.isEmpty())
1123 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:281124 }
[email protected]04d3c6e2009-05-22 17:00:131125
[email protected]52c68652010-12-07 17:47:041126 if (!params.extra_headers.empty()) {
1127 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1128 params.extra_headers.end(), "\n");
1129 i.GetNext(); ) {
1130 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1131 WebString::fromUTF8(i.values()));
1132 }
1133 }
[email protected]132e281a2012-07-31 18:32:441134
1135 if (params.is_post) {
1136 request.setHTTPMethod(WebString::fromUTF8("POST"));
1137
1138 // Set post data.
1139 WebHTTPBody http_body;
1140 http_body.initialize();
1141 http_body.appendData(WebData(
1142 reinterpret_cast<const char*>(
1143 &params.browser_initiated_post_data.front()),
1144 params.browser_initiated_post_data.size()));
1145 request.setHTTPBody(http_body);
1146 }
1147
[email protected]dd7daa82009-08-10 05:46:451148 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501149 }
1150
[email protected]77f17a82009-05-21 04:42:541151 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:071152 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:291153}
1154
[email protected]310ebd6302011-10-10 19:06:281155bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:031156 const ViewMsg_Navigate_Params& params,
1157 bool is_reload) {
1158 // Make sure this isn't a back/forward to an entry we have already cropped
1159 // or replaced from our history, before the browser knew about it. If so,
1160 // a new navigation has committed in the mean time, and we can ignore this.
1161 bool is_back_forward = !is_reload && !params.state.empty();
1162
1163 // Note: if the history_list_length_ is 0 for a back/forward, we must be
1164 // restoring from a previous session. We'll update our state in OnNavigate.
1165 if (!is_back_forward || history_list_length_ <= 0)
1166 return false;
1167
1168 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
1169
1170 // Check for whether the forward history has been cropped due to a recent
1171 // navigation the browser didn't know about.
1172 if (params.pending_history_list_offset >= history_list_length_)
1173 return true;
1174
1175 // Check for whether this entry has been replaced with a new one.
1176 int expected_page_id =
1177 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:441178 if (expected_page_id > 0 && params.page_id != expected_page_id) {
1179 if (params.page_id < expected_page_id)
1180 return true;
1181
1182 // Otherwise we've removed an earlier entry and should have shifted all
1183 // entries left. For now, it's ok to lazily update the list.
1184 // TODO(creis): Notify all live renderers when we remove entries from
1185 // the front of the list, so that we don't hit this case.
1186 history_page_ids_[params.pending_history_list_offset] = params.page_id;
1187 }
[email protected]d466b8a2011-07-15 21:48:031188
1189 return false;
1190}
1191
initial.commit09911bf2008-07-26 23:55:291192// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:281193void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:441194 if (webview()) {
1195 WebFrame* main_frame = webview()->mainFrame();
1196 // Stop the alt error page fetcher. If we let it continue it may complete
1197 // and cause RenderViewHostManager to swap to this RenderView, even though
1198 // it may no longer be active.
1199 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
1200 StopAltErrorPageFetcher(main_frame->dataSource());
1201 main_frame->stopLoading();
1202 }
initial.commit09911bf2008-07-26 23:55:291203}
1204
[email protected]ecbf10d2010-02-18 13:03:291205// Reload current focused frame.
1206// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:281207void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291208 if (webview() && webview()->focusedFrame()) {
1209 // We always obey the cache (ignore_cache=false) here.
1210 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1211 // a cache-ignoring reload of the frame.
1212 webview()->focusedFrame()->reload(false);
1213 }
[email protected]1dda4022010-01-28 18:24:561214}
1215
[email protected]310ebd6302011-10-10 19:06:281216void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271217 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291218}
1219
[email protected]310ebd6302011-10-10 19:06:281220void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:251221 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271222 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251223 return;
1224
[email protected]26aa0482009-09-30 16:55:271225 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451226 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251227}
1228
[email protected]310ebd6302011-10-10 19:06:281229void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291230 // Check if there is a targeturl waiting to be sent.
1231 if (target_url_status_ == TARGET_PENDING) {
1232 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1233 pending_target_url_));
1234 }
1235
1236 target_url_status_ = TARGET_NONE;
1237}
1238
[email protected]310ebd6302011-10-10 19:06:281239void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:291240 if (!webview())
1241 return;
1242
[email protected]26aa0482009-09-30 16:55:271243 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:291244}
1245
[email protected]310ebd6302011-10-10 19:06:281246void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:291247 if (!webview())
1248 return;
1249
[email protected]26aa0482009-09-30 16:55:271250 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:291251}
1252
[email protected]310ebd6302011-10-10 19:06:281253void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:291254 if (!webview())
1255 return;
1256
[email protected]26aa0482009-09-30 16:55:271257 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:291258}
1259
[email protected]310ebd6302011-10-10 19:06:281260void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291261 if (!webview())
1262 return;
1263
[email protected]f6b1856b2011-06-29 22:02:531264 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
1265 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:291266}
1267
[email protected]c0cc3092009-09-12 08:27:271268#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281269void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:351270 if (!webview())
1271 return;
1272
1273 // Since the find pasteboard supports only plain text, this can be simpler
1274 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271275 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351276 if (frame->hasSelection()) {
1277 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:271278 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:171279 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:351280 }
[email protected]a954bf72009-09-12 07:30:351281}
[email protected]c0cc3092009-09-12 08:27:271282#endif
[email protected]a954bf72009-09-12 07:30:351283
[email protected]310ebd6302011-10-10 19:06:281284void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291285 if (!webview())
1286 return;
1287
[email protected]26aa0482009-09-30 16:55:271288 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:291289}
1290
[email protected]44bf7002011-10-16 02:46:151291void RenderViewImpl::OnPasteAndMatchStyle() {
1292 if (!webview())
1293 return;
1294
1295 webview()->focusedFrame()->executeCommand(
1296 WebString::fromUTF8("PasteAndMatchStyle"));
1297}
1298
[email protected]310ebd6302011-10-10 19:06:281299void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291300 if (!webview())
1301 return;
1302
[email protected]1ff7a032010-02-03 02:46:031303 WebFrame* frame = webview()->focusedFrame();
1304 if (!frame->hasSelection())
1305 frame->selectWordAroundCaret();
1306 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291307}
1308
[email protected]310ebd6302011-10-10 19:06:281309void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:291310 if (!webview())
1311 return;
1312
[email protected]26aa0482009-09-30 16:55:271313 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:291314}
1315
[email protected]310ebd6302011-10-10 19:06:281316void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291317 if (!webview())
1318 return;
1319
[email protected]26aa0482009-09-30 16:55:271320 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221321 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:291322}
1323
[email protected]45a599062012-09-07 20:09:061324void RenderViewImpl::OnReplaceAll(const string16& text) {
1325 WebNode node = GetFocusedNode();
1326 if (node.isNull() || !IsEditableNode(node))
1327 return;
1328
1329 OnSelectAll();
1330 OnReplace(text);
1331}
1332
1333void RenderViewImpl::OnUnselect() {
1334 if (!webview())
1335 return;
1336
1337 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
1338}
1339
1340void RenderViewImpl::OnSetEditableSelectionOffsets(int start, int end) {
1341 webview()->setEditableSelectionOffsets(start, end);
1342}
1343
1344void RenderViewImpl::OnSetCompositionFromExistingText(
1345 int start, int end,
1346 const std::vector<WebKit::WebCompositionUnderline>& underlines) {
1347 if (!webview())
1348 return;
1349 webview()->setCompositionFromExistingText(start, end, underlines);
1350}
1351
1352void RenderViewImpl::OnExtendSelectionAndDelete(int before, int after) {
1353 if (!webview())
1354 return;
1355 webview()->extendSelectionAndDelete(before, after);
1356}
1357
[email protected]310ebd6302011-10-10 19:06:281358void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1359 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:081360 if (!webview())
1361 return;
1362
[email protected]c95e53ad2012-08-13 17:56:161363 Send(new ViewHostMsg_SelectRange_ACK(routing_id_));
1364
[email protected]4fb60142011-08-09 02:22:081365 handling_select_range_ = true;
1366 webview()->focusedFrame()->selectRange(start, end);
1367 handling_select_range_ = false;
1368}
1369
[email protected]310ebd6302011-10-10 19:06:281370void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1371 int32 minimum_page_id) {
[email protected]e1ed5a12012-08-08 19:57:441372 DCHECK_GE(history_length, 0);
[email protected]9e1ad4b2011-08-14 16:49:191373 DCHECK(history_list_offset_ == history_list_length_ - 1);
[email protected]e1ed5a12012-08-08 19:57:441374 DCHECK_GE(minimum_page_id, -1);
[email protected]9e1ad4b2011-08-14 16:49:191375
1376 // Generate the new list.
1377 std::vector<int32> new_history_page_ids(history_length, -1);
1378 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1379 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1380 continue;
1381 new_history_page_ids.push_back(history_page_ids_[i]);
1382 }
1383 new_history_page_ids.swap(history_page_ids_);
1384
1385 // Update indexes.
1386 history_list_length_ = history_page_ids_.size();
1387 history_list_offset_ = history_list_length_ - 1;
1388}
1389
1390
[email protected]310ebd6302011-10-10 19:06:281391void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291392 if (!webview())
1393 return;
[email protected]26aa0482009-09-30 16:55:271394 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291395}
1396
[email protected]54ca3ca892011-06-07 21:14:541397#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281398void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331399 if (!webview())
1400 return;
1401 if (in_live_resize)
1402 webview()->willStartLiveResize();
1403 else
1404 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541405}
1406#endif
1407
[email protected]310ebd6302011-10-10 19:06:281408void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1409 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091410 WebKit::WebNode node = GetFocusedNode();
1411 if (!node.isNull()) {
[email protected]9b7d11e2012-10-08 19:24:141412 if (IsEditableNode(node)) {
1413 webview()->saveScrollAndScaleState();
[email protected]333ec8d02011-09-16 18:59:191414 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b7d11e2012-10-08 19:24:141415 }
[email protected]9b66f34bf2010-10-27 20:45:511416 }
1417}
1418
[email protected]9b7d11e2012-10-08 19:24:141419#if defined(OS_ANDROID)
1420void RenderViewImpl::OnUndoScrollFocusedEditableNodeIntoRect() {
1421 const WebNode node = GetFocusedNode();
1422 if (!node.isNull() && IsEditableNode(node))
1423 webview()->restoreScrollAndScaleState();
1424}
1425#endif
1426
initial.commit09911bf2008-07-26 23:55:291427///////////////////////////////////////////////////////////////////////////////
1428
1429// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281430void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451431 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291432 DCHECK(ds);
1433
[email protected]726985e22009-06-18 21:09:281434 const WebURLRequest& request = ds->request();
1435 const WebURLRequest& original_request = ds->originalRequest();
1436 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291437
[email protected]007733c2011-11-17 00:34:071438 DocumentState* document_state = DocumentState::FromDataSource(ds);
1439 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291440
1441 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281442 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291443 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051444 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291445 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071446 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191447 params.socket_address.set_host(response.remoteIPAddress().utf8());
1448 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031449 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091450 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071451 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291452 // SSL state specified in the request takes precedence over the one in the
1453 // response.
1454 // So far this is only intended for error pages that are not expected to be
1455 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281456 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071457 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291458 } else {
[email protected]726985e22009-06-18 21:09:281459 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291460 }
1461
1462 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:311463 params.url = GetLoadingUrl(frame);
initial.commit09911bf2008-07-26 23:55:291464
[email protected]5f9b8712011-11-23 08:55:571465 if (frame->document().baseURL() != params.url)
1466 params.base_url = frame->document().baseURL();
1467
[email protected]726985e22009-06-18 21:09:281468 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241469 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041470 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291471
[email protected]007733c2011-11-17 00:34:071472 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351473 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071474 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291475
1476 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071477 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291478 if (password_form_data)
1479 params.password_form = *password_form_data;
1480
1481 params.gesture = navigation_gesture_;
1482 navigation_gesture_ = NavigationGestureUnknown;
1483
[email protected]0f38dc4552011-02-25 11:24:001484 // Make navigation state a part of the FrameNavigate message so that commited
1485 // entry had it at all times.
1486 const WebHistoryItem& item = frame->currentHistoryItem();
1487 if (!item.isNull()) {
1488 params.content_state = webkit_glue::HistoryItemToString(item);
1489 } else {
1490 params.content_state =
1491 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1492 }
1493
[email protected]dd7daa82009-08-10 05:46:451494 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291495 // Top-level navigation.
1496
[email protected]d00a7972012-08-07 06:09:581497 // Reset the zoom limits in case a plugin had changed them previously. This
1498 // will also call us back which will cause us to send a message to
1499 // update WebContentsImpl.
1500 webview()->zoomLimitsChanged(
[email protected]e9ff79c2012-10-19 21:31:261501 WebView::zoomFactorToZoomLevel(kMinimumZoomFactor),
1502 WebView::zoomFactorToZoomLevel(kMaximumZoomFactor));
[email protected]d00a7972012-08-07 06:09:581503
[email protected]b75b8292010-10-01 07:28:251504 // Set zoom level, but don't do it for full-page plugin since they don't use
1505 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011506 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541507 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251508 if (webview()->mainFrame()->document().isPluginDocument()) {
1509 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251510 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251511 } else {
1512 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251513 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251514 }
1515
[email protected]f85f0702010-01-30 09:31:011516 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511517 // This zoom level was merely recorded transiently for this load. We can
1518 // erase it now. If at some point we reload this page, the browser will
1519 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011520 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511521 }
1522
initial.commit09911bf2008-07-26 23:55:291523 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551524 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291525
[email protected]daa8c58e2009-06-15 17:21:101526 params.transition = navigation_state->transition_type();
[email protected]e9ff79c2012-10-19 21:31:261527 if (!PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291528 // If the main frame does a load, it should not be reported as a subframe
1529 // navigation. This can occur in the following case:
1530 // 1. You're on a site with frames.
1531 // 2. You do a subframe navigation. This is stored with transition type
1532 // MANUAL_SUBFRAME.
1533 // 3. You navigate to some non-frame site, say, google.com.
1534 // 4. You navigate back to the page from step 2. Since it was initially
1535 // MANUAL_SUBFRAME, it will be that same transition type here.
1536 // We don't want that, because any navigation that changes the toplevel
1537 // frame should be tracked as a toplevel navigation (this allows us to
1538 // update the URL bar, etc).
[email protected]e9ff79c2012-10-19 21:31:261539 params.transition = PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291540 }
1541
initial.commit09911bf2008-07-26 23:55:291542 // If we have a valid consumed client redirect source,
1543 // the page contained a client redirect (meta refresh, document.loc...),
1544 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151545 if (completed_client_redirect_src_.url.is_valid()) {
1546 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291547 params.referrer = completed_client_redirect_src_;
[email protected]e9ff79c2012-10-19 21:31:261548 params.transition = static_cast<PageTransition>(
1549 params.transition | PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291550 } else {
1551 // Bug 654101: the referrer will be empty on https->http transitions. It
1552 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151553 params.referrer = Referrer(GURL(
1554 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:591555 GetReferrerPolicyFromRequest(frame, original_request));
initial.commit09911bf2008-07-26 23:55:291556 }
1557
[email protected]726985e22009-06-18 21:09:281558 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051559 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291560 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051561 params.post_id = ExtractPostId(item);
1562 }
initial.commit09911bf2008-07-26 23:55:291563
[email protected]bf70edce2012-06-20 22:32:221564 // Send the user agent override back.
1565 params.is_overriding_user_agent =
1566 document_state->is_overriding_user_agent();
1567
[email protected]7c16976c2012-08-04 02:38:231568 // Track the URL of the original request.
1569 params.original_request_url = original_request.url();
1570
[email protected]c2a797d2009-09-21 16:46:321571 // Save some histogram data so we can compute the average memory used per
1572 // page load of the glyphs.
1573 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1574 webkit_glue::GetGlyphPageCount());
1575
[email protected]15cf526b2010-02-12 06:33:491576 // This message needs to be sent before any of allowScripts(),
1577 // allowImages(), allowPlugins() is called for the new page, so that when
1578 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1579 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291580 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1581 } else {
1582 // Subframe navigation: the type depends on whether this navigation
1583 // generated a new session history entry. When they do generate a session
1584 // history entry, it means the user initiated the navigation and we should
1585 // mark it as such. This test checks if this is the first time UpdateURL
1586 // has been called since WillNavigateToURL was called to initiate the load.
1587 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]e9ff79c2012-10-19 21:31:261588 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291589 else
[email protected]e9ff79c2012-10-19 21:31:261590 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291591
initial.commit09911bf2008-07-26 23:55:291592 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1593 }
1594
1595 last_page_id_sent_to_browser_ =
1596 std::max(last_page_id_sent_to_browser_, page_id_);
1597
1598 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101599 // we don't want the transition type to persist. Just clear it.
[email protected]e9ff79c2012-10-19 21:31:261600 navigation_state->set_transition_type(PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291601}
1602
1603// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281604void RenderViewImpl::UpdateTitle(WebFrame* frame,
1605 const string16& title,
1606 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461607 // Ignore all but top level navigations.
1608 if (frame->parent())
1609 return;
1610
[email protected]e9ff79c2012-10-19 21:31:261611 string16 shortened_title = title.substr(0, kMaxTitleChars);
[email protected]a49e10b2011-08-01 23:57:461612 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1613 title_direction));
initial.commit09911bf2008-07-26 23:55:291614}
1615
[email protected]310ebd6302011-10-10 19:06:281616void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1617 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291618 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271619 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291620 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301621 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291622 last_encoding_name_ = encoding_name;
1623
[email protected]e38f40152008-09-12 23:08:301624 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291625 }
1626}
1627
[email protected]e15f680732010-11-23 22:30:201628// Sends the last committed session history state to the browser so it will be
1629// saved before we navigate to a new page. This must be called *before* the
1630// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281631void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291632 // If we have a valid page ID at this point, then it corresponds to the page
1633 // we are navigating away from. Otherwise, this is the first navigation, so
1634 // there is no past session history to record.
1635 if (page_id_ == -1)
1636 return;
1637
[email protected]ca948a22009-06-25 19:36:171638 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271639 webview()->mainFrame()->previousHistoryItem();
[email protected]6459800a2012-03-27 23:57:051640 SendUpdateState(item);
1641}
1642
1643void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
[email protected]ca948a22009-06-25 19:36:171644 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291645 return;
[email protected]ca948a22009-06-25 19:36:171646
[email protected]e9ff79c2012-10-19 21:31:261647 // Don't send state updates for kSwappedOutURL.
1648 if (item.urlString() == WebString::fromUTF8(kSwappedOutURL))
[email protected]6459800a2012-03-27 23:57:051649 return;
1650
[email protected]ca948a22009-06-25 19:36:171651 Send(new ViewHostMsg_UpdateState(
1652 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291653}
1654
[email protected]310ebd6302011-10-10 19:06:281655void RenderViewImpl::OpenURL(WebFrame* frame,
1656 const GURL& url,
[email protected]445e1042011-12-03 21:03:151657 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281658 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171659 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581660 routing_id_,
1661 url,
1662 referrer,
1663 NavigationPolicyToDisposition(policy),
1664 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171665}
1666
[email protected]79dbc662009-09-04 05:42:511667// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291668
[email protected]310ebd6302011-10-10 19:06:281669void RenderViewImpl::LoadNavigationErrorPage(
1670 WebFrame* frame,
1671 const WebURLRequest& failed_request,
1672 const WebURLError& error,
1673 const std::string& html,
1674 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581675 std::string alt_html;
1676 const std::string* error_html;
1677
1678 if (!html.empty()) {
1679 error_html = &html;
1680 } else {
[email protected]e9ff79c2012-10-19 21:31:261681 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]d7b175e2011-10-11 15:31:581682 failed_request, error, &alt_html, NULL);
1683 error_html = &alt_html;
1684 }
1685
1686 frame->loadHTMLString(*error_html,
[email protected]e9ff79c2012-10-19 21:31:261687 GURL(kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251688 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551689 replace);
initial.commit09911bf2008-07-26 23:55:291690}
1691
[email protected]e9ff79c2012-10-19 21:31:261692bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281693 const string16& message,
1694 const string16& default_value,
1695 const GURL& frame_url,
1696 string16* result) {
initial.commit09911bf2008-07-26 23:55:291697 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411698 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291699 if (!result)
1700 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291701
[email protected]12636df2009-09-28 22:32:211702 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1703 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291704 return success;
1705}
1706
[email protected]310ebd6302011-10-10 19:06:281707bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571708 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1709 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1710 // it is particularly important that we do not call willEnterModalLoop as
1711 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441712 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1713 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571714
1715 message->EnableMessagePumping(); // Runs a nested message loop.
1716 return Send(message);
1717}
1718
[email protected]48c9cf2d2009-09-16 16:47:521719// WebKit::WebViewClient ------------------------------------------------------
1720
[email protected]916dfb62012-03-05 03:39:371721WebView* RenderViewImpl::createView(
1722 WebFrame* creator,
1723 const WebURLRequest& request,
1724 const WebWindowFeatures& features,
1725 const WebString& frame_name,
1726 WebNavigationPolicy policy) {
[email protected]48c9cf2d2009-09-16 16:47:521727 // Check to make sure we aren't overloading on popups.
1728 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1729 return NULL;
1730
[email protected]8ab04652010-06-12 02:47:261731 ViewHostMsg_CreateWindow_Params params;
1732 params.opener_id = routing_id_;
1733 params.user_gesture = creator->isProcessingUserGesture();
1734 params.window_container_type = WindowFeaturesToContainerType(features);
1735 params.session_storage_namespace_id = session_storage_namespace_id_;
1736 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111737 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411738 params.opener_url = creator->document().url();
1739 params.opener_security_origin =
1740 creator->document().securityOrigin().toString().utf8();
[email protected]f92ce2b2012-03-06 18:02:591741 params.opener_suppressed = creator->willSuppressOpenerInNewFrame();
1742 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]41e65502011-01-21 09:29:111743 if (!request.isNull())
1744 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261745
[email protected]48c9cf2d2009-09-16 16:47:521746 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561747 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341748 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521749
[email protected]7c962ee32012-08-28 21:12:501750 creator->consumeUserGesture();
[email protected]380244092011-10-07 17:26:271751 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261752 new ViewHostMsg_CreateWindow(params,
1753 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561754 &surface_id,
[email protected]8ab04652010-06-12 02:47:261755 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211756 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521757 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521758
[email protected]310ebd6302011-10-10 19:06:281759 RenderViewImpl* view = RenderViewImpl::Create(
1760 0,
1761 routing_id_,
1762 renderer_preferences_,
1763 webkit_preferences_,
1764 shared_popup_counter_,
1765 routing_id,
[email protected]9f4f3322012-01-18 22:29:561766 surface_id,
[email protected]310ebd6302011-10-10 19:06:281767 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461768 frame_name,
[email protected]14392a52012-05-02 20:28:441769 true,
1770 false,
[email protected]6fd35b72012-03-01 19:46:411771 1,
[email protected]842f10652012-06-06 01:54:041772 screen_info_,
[email protected]3e3c4522012-04-13 21:16:291773 accessibility_mode_);
[email protected]8ab04652010-06-12 02:47:261774 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521775
[email protected]007a848b2009-10-26 15:55:461776 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:591777 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:461778
[email protected]48c9cf2d2009-09-16 16:47:521779 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411780 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521781 if (!creator_url.is_valid() || !creator_url.IsStandard())
1782 creator_url = GURL();
1783 view->creator_url_ = creator_url;
1784
1785 // Copy over the alternate error page URL so we can have alt error pages in
1786 // the new render view (we don't need the browser to send the URL back down).
1787 view->alternate_error_page_url_ = alternate_error_page_url_;
1788
1789 return view->webview();
1790}
1791
[email protected]310ebd6302011-10-10 19:06:281792WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:411793 RenderWidget* widget =
[email protected]842f10652012-06-06 01:54:041794 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]48c9cf2d2009-09-16 16:47:521795 return widget->webwidget();
1796}
1797
[email protected]310ebd6302011-10-10 19:06:281798WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081799 const WebPopupMenuInfo& popup_menu_info,
1800 WebExternalPopupMenuClient* popup_menu_client) {
[email protected]8de2f882012-05-30 00:32:271801 // An IPC message is sent to the browser to build and display the actual
1802 // popup. The user could have time to click a different select by the time
1803 // the popup is shown. In that case external_popup_menu_ is non NULL.
1804 // By returning NULL in that case, we instruct WebKit to cancel that new
1805 // popup. So from the user perspective, only the first one will show, and
1806 // will have to close the first one before another one can be shown.
1807 if (external_popup_menu_.get())
1808 return NULL;
[email protected]caf706f2010-10-26 17:54:081809 external_popup_menu_.reset(
1810 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1811 return external_popup_menu_.get();
1812}
1813
[email protected]310ebd6302011-10-10 19:06:281814RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521815 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531816 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421817 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411818 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531819 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]bee6eb72012-07-26 03:47:321820 routing_id_, plugin, active_url, screen_info_);
[email protected]79c7bed2010-09-14 22:28:391821 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561822 return widget;
[email protected]79c7bed2010-09-14 22:28:391823}
1824
[email protected]310ebd6302011-10-10 19:06:281825WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1826 unsigned quota) {
[email protected]b928936b2012-04-13 01:16:161827 CHECK(session_storage_namespace_id_ !=
1828 dom_storage::kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:101829 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341830}
1831
[email protected]1842fe22012-08-13 23:24:351832WebKit::WebCompositorOutputSurface* RenderViewImpl::createOutputSurface() {
[email protected]1842fe22012-08-13 23:24:351833 // Explicitly disable antialiasing for the compositor. As of the time of
1834 // this writing, the only platform that supported antialiasing for the
1835 // compositor was Mac OS X, because the on-screen OpenGL context creation
1836 // code paths on Windows and Linux didn't yet have multisampling support.
1837 // Mac OS X essentially always behaves as though it's rendering offscreen.
1838 // Multisampling has a heavy cost especially on devices with relatively low
1839 // fill rate like most notebooks, and the Mac implementation would need to
1840 // be optimized to resolve directly into the IOSurface shared between the
1841 // GPU and browser processes. For these reasons and to avoid platform
1842 // disparities we explicitly disable antialiasing.
1843 WebKit::WebGraphicsContext3D::Attributes attributes;
1844 attributes.antialias = false;
1845 attributes.shareResources = true;
[email protected]362e6d602012-10-17 16:55:061846 attributes.noAutomaticFlushes = true;
[email protected]1842fe22012-08-13 23:24:351847 WebGraphicsContext3D* context = CreateGraphicsContext3D(attributes);
1848 if (!context)
[email protected]7e8b4d12012-01-20 23:39:511849 return NULL;
[email protected]468e4902012-05-23 01:49:311850
[email protected]7d4481d12012-09-24 21:26:471851 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1852 if (command_line.HasSwitch(switches::kEnableSoftwareCompositingGLAdapter)) {
1853 // In the absence of a software-based delegating renderer, use this
1854 // stopgap adapter class to present the software renderer output using a
1855 // 3d context.
1856 return new CompositorOutputSurface(routing_id(), NULL,
1857 new CompositorSoftwareOutputDeviceGLAdapter(context));
1858 } else
1859 return new CompositorOutputSurface(routing_id(), context, NULL);
[email protected]7e8b4d12012-01-20 23:39:511860}
1861
[email protected]310ebd6302011-10-10 19:06:281862void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521863 const WebConsoleMessage& message, const WebString& source_name,
1864 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081865 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511866 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081867 case WebConsoleMessage::LevelTip:
1868 log_severity = logging::LOG_VERBOSE;
1869 break;
1870 case WebConsoleMessage::LevelLog:
1871 log_severity = logging::LOG_INFO;
1872 break;
1873 case WebConsoleMessage::LevelWarning:
1874 log_severity = logging::LOG_WARNING;
1875 break;
1876 case WebConsoleMessage::LevelError:
1877 log_severity = logging::LOG_ERROR;
1878 break;
1879 default:
1880 NOTREACHED();
1881 }
1882
[email protected]48c9cf2d2009-09-16 16:47:521883 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081884 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311885 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521886 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311887 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521888}
1889
[email protected]310ebd6302011-10-10 19:06:281890void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]b0553c7e2012-09-19 21:36:111891 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
1892 PrintPage(frame, handling_input_event_));
[email protected]48c9cf2d2009-09-16 16:47:521893}
1894
[email protected]310ebd6302011-10-10 19:06:281895WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511896 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021897}
1898
[email protected]310ebd6302011-10-10 19:06:281899bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121900 const WebString& path,
1901 WebFileChooserCompletion* chooser_completion) {
1902 int id = enumeration_completion_id_++;
1903 enumeration_completions_[id] = chooser_completion;
1904 return Send(new ViewHostMsg_EnumerateDirectory(
1905 routing_id_,
1906 id,
[email protected]bb0e79472012-10-23 04:36:341907 webkit_base::WebStringToFilePath(path)));
[email protected]8a58c1c2011-04-19 18:40:121908}
1909
[email protected]4b1146bc2012-07-10 18:46:031910void RenderViewImpl::initializeHelperPluginWebFrame(
1911 WebKit::WebHelperPlugin* plugin) {
1912 plugin->initializeFrame(this);
1913}
1914
[email protected]310ebd6302011-10-10 19:06:281915void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521916 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:141917 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:521918 return;
1919 }
1920
1921 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521922
1923 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311924
1925 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521926}
1927
[email protected]310ebd6302011-10-10 19:06:281928void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521929 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:141930 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:521931 return;
1932 }
1933
1934 is_loading_ = false;
1935
[email protected]0720b532012-08-28 19:23:371936 if (pending_frame_tree_update_) {
1937 pending_frame_tree_update_ = false;
1938 SendUpdatedFrameTree(NULL);
1939 }
1940
[email protected]48c9cf2d2009-09-16 16:47:521941 // NOTE: For now we're doing the safest thing, and sending out notification
1942 // when done loading. This currently isn't an issue as the favicon is only
1943 // displayed when done loading. Ideally we would send notification when
1944 // finished parsing the head, but webkit doesn't support that yet.
1945 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521946 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1947
[email protected]90109412010-12-15 17:14:241948 if (load_progress_tracker_ != NULL)
1949 load_progress_tracker_->DidStopLoading();
1950
[email protected]93b9d692011-04-13 00:44:311951 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521952}
1953
[email protected]310ebd6302011-10-10 19:06:281954void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1955 double load_progress) {
[email protected]90109412010-12-15 17:14:241956 if (load_progress_tracker_ != NULL)
1957 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1958}
1959
[email protected]310ebd6302011-10-10 19:06:281960bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061961#if defined(OS_MACOSX)
1962 return true;
1963#else
1964 return false;
1965#endif
1966}
1967
[email protected]310ebd6302011-10-10 19:06:281968bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031969#if defined(OS_WIN)
1970 return true;
1971#else
1972 return false;
1973#endif
1974}
1975
[email protected]310ebd6302011-10-10 19:06:281976void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081977 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031978 return;
[email protected]4fb60142011-08-09 02:22:081979 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011980
[email protected]fca52022012-04-03 17:00:501981 if (is_empty_selection)
1982 selection_text_.clear();
1983
[email protected]b781ff282011-08-20 06:19:361984 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031985}
1986
[email protected]310ebd6302011-10-10 19:06:281987void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121988 const std::string& name = UTF16ToUTF8(command_name);
1989 if (StartsWithASCII(name, "Move", true) ||
1990 StartsWithASCII(name, "Insert", true) ||
1991 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031992 return;
[email protected]f1a29a02011-10-06 23:08:441993 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031994}
1995
[email protected]310ebd6302011-10-10 19:06:281996bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101997 if (edit_commands_.empty())
1998 return false;
1999
[email protected]26aa0482009-09-30 16:55:272000 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102001 if (!frame)
2002 return false;
2003
2004 EditCommands::iterator it = edit_commands_.begin();
2005 EditCommands::iterator end = edit_commands_.end();
2006
[email protected]507b33ea2009-09-29 03:56:512007 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102008 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332009 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2010 // key (but it's the exception). Once one edit command is not executed, it
2011 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102012 if (!frame->executeCommand(WebString::fromUTF8(it->name),
2013 WebString::fromUTF8(it->value)))
2014 break;
[email protected]507b33ea2009-09-29 03:56:512015 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102016 }
2017
[email protected]507b33ea2009-09-29 03:56:512018 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102019}
2020
[email protected]3306f262012-09-21 19:20:422021void RenderViewImpl::didHandleGestureEvent(const WebGestureEvent& event,
2022 bool event_swallowed) {
2023#if defined(OS_ANDROID)
2024 if (event.type == WebInputEvent::GestureTap ||
2025 event.type == WebInputEvent::GestureLongPress) {
2026 UpdateTextInputState(SHOW_IME_IF_NEEDED);
2027 }
2028#endif
2029}
2030
[email protected]da8543762012-03-20 08:52:202031WebKit::WebColorChooser* RenderViewImpl::createColorChooser(
2032 WebKit::WebColorChooserClient* client,
2033 const WebKit::WebColor& initial_color) {
2034 RendererWebColorChooserImpl* color_chooser =
2035 new RendererWebColorChooserImpl(this, client);
2036 color_chooser->Open(static_cast<SkColor>(initial_color));
2037 return color_chooser;
2038}
2039
[email protected]310ebd6302011-10-10 19:06:282040bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:352041 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472042 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352043 // Do not open the file dialog in a hidden RenderView.
2044 if (is_hidden())
2045 return false;
[email protected]e9ff79c2012-10-19 21:31:262046 FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262047 if (params.directory)
[email protected]e9ff79c2012-10-19 21:31:262048 ipc_params.mode = FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:262049 else if (params.multiSelect)
[email protected]e9ff79c2012-10-19 21:31:262050 ipc_params.mode = FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:502051 else if (params.saveAs)
[email protected]e9ff79c2012-10-19 21:31:262052 ipc_params.mode = FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:262053 else
[email protected]e9ff79c2012-10-19 21:31:262054 ipc_params.mode = FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:472055 ipc_params.title = params.title;
2056 ipc_params.default_file_name =
[email protected]bb0e79472012-10-23 04:36:342057 webkit_base::WebStringToFilePath(params.initialValue);
[email protected]f9a4c41a2012-05-30 00:05:322058 ipc_params.accept_types.reserve(params.acceptTypes.size());
2059 for (size_t i = 0; i < params.acceptTypes.size(); ++i)
2060 ipc_params.accept_types.push_back(params.acceptTypes[i]);
[email protected]cdaf8d02010-03-30 19:52:472061
2062 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462063}
2064
[email protected]269f86d2011-12-07 02:43:472065void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
2066 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262067 RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:412068 message,
2069 string16(),
[email protected]b6cb3a842011-06-24 18:28:412070 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522071 NULL);
2072}
2073
[email protected]269f86d2011-12-07 02:43:472074bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
2075 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262076 return RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:412077 message,
2078 string16(),
[email protected]b6cb3a842011-06-24 18:28:412079 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522080 NULL);
2081}
2082
[email protected]269f86d2011-12-07 02:43:472083bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
2084 const WebString& message,
2085 const WebString& default_value,
2086 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:412087 string16 result;
[email protected]e9ff79c2012-10-19 21:31:262088 bool ok = RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:412089 message,
2090 default_value,
[email protected]b6cb3a842011-06-24 18:28:412091 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522092 &result);
2093 if (ok)
[email protected]4f5ce842011-05-27 19:34:412094 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:522095 return ok;
2096}
2097
[email protected]310ebd6302011-10-10 19:06:282098bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:522099 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:152100 // If we are swapping out, we have already run the beforeunload handler.
2101 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
2102 // at all, to avoid running it twice.
2103 if (is_swapped_out_)
2104 return true;
2105
[email protected]3b3301f62012-02-29 04:32:322106 bool is_reload = false;
2107 WebDataSource* ds = frame->provisionalDataSource();
2108 if (ds)
2109 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
2110
[email protected]48c9cf2d2009-09-16 16:47:522111 bool success = false;
2112 // This is an ignored return value, but is included so we can accept the same
2113 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:412114 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:212115 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:322116 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:412117 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522118 return success;
2119}
2120
[email protected]310ebd6302011-10-10 19:06:282121void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:442122 WebFrame* frame, const WebContextMenuData& data) {
[email protected]e9ff79c2012-10-19 21:31:262123 ContextMenuParams params(data);
[email protected]7fcd9b72011-07-27 16:52:372124
[email protected]329266d2012-09-27 06:20:572125 // Plugins, e.g. PDF, don't currently update the render view when their
2126 // selected text changes, but the context menu params do contain the updated
2127 // selection. If that's the case, update the render view's state just prior
2128 // to showing the context menu.
2129 // TODO(asvitkine): http://crbug.com/152432
[email protected]f49f7a12012-10-26 19:16:592130 string16 selection_text;
2131 if (!selection_text_.empty() && !selection_range_.is_empty()) {
2132 const int start = selection_range_.GetMin() - selection_text_offset_;
2133 const size_t length = selection_range_.length();
2134 if (start >= 0 && start + length <= selection_text_.length())
2135 selection_text = selection_text_.substr(start, length);
2136 }
[email protected]eff43567da2012-10-25 20:57:482137 if (params.selection_text != selection_text) {
[email protected]329266d2012-09-27 06:20:572138 selection_text_ = params.selection_text;
2139 // TODO(asvitkine): Text offset and range is not available in this case.
2140 selection_text_offset_ = 0;
2141 selection_range_ = ui::Range(0, selection_text_.length());
2142 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2143 selection_text_,
2144 selection_text_offset_,
2145 selection_range_));
2146 }
2147
[email protected]7fcd9b72011-07-27 16:52:372148 // frame is NULL if invoked by BlockedPlugin.
2149 if (frame)
2150 params.frame_id = frame->identifier();
2151
[email protected]e9ff79c2012-10-19 21:31:262152 // Serializing a GURL longer than kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:272153 // it. We replace it with an empty GURL so the appropriate items are disabled
2154 // in the context menu.
2155 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2156 // data encoded images. We should have a way to save them.
[email protected]e9ff79c2012-10-19 21:31:262157 if (params.src_url.spec().size() > kMaxURLChars)
[email protected]216932c2010-08-26 21:44:272158 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102159 context_menu_node_ = data.node;
[email protected]44daa3b2012-09-27 19:26:412160
2161#if defined(OS_ANDROID)
2162 gfx::Rect start_rect;
2163 gfx::Rect end_rect;
2164 GetSelectionBounds(&start_rect, &end_rect);
[email protected]ceb36f7d2012-10-31 18:33:242165 params.selection_start =
2166 gfx::Point(start_rect.x(), start_rect.bottom()) + GetScrollOffset();
2167 params.selection_end =
2168 gfx::Point(end_rect.right(), end_rect.bottom()) + GetScrollOffset();
[email protected]44daa3b2012-09-27 19:26:412169#endif
2170
[email protected]c27324b2009-11-19 22:44:292171 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442172}
2173
[email protected]310ebd6302011-10-10 19:06:282174void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:522175}
2176
[email protected]310ebd6302011-10-10 19:06:282177void RenderViewImpl::UpdateTargetURL(const GURL& url,
2178 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582179 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522180 if (latest_url == target_url_)
2181 return;
[email protected]163f8242009-10-30 20:19:552182
[email protected]48c9cf2d2009-09-16 16:47:522183 // Tell the browser to display a destination link.
2184 if (target_url_status_ == TARGET_INFLIGHT ||
2185 target_url_status_ == TARGET_PENDING) {
2186 // If we have a request in-flight, save the URL to be sent when we
2187 // receive an ACK to the in-flight request. We can happily overwrite
2188 // any existing pending sends.
2189 pending_target_url_ = latest_url;
2190 target_url_status_ = TARGET_PENDING;
2191 } else {
[email protected]e9ff79c2012-10-19 21:31:262192 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:412193 // see |ParamTraits<GURL>|.
[email protected]e9ff79c2012-10-19 21:31:262194 if (latest_url.possibly_invalid_spec().size() > kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:412195 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:522196 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2197 target_url_ = latest_url;
2198 target_url_status_ = TARGET_INFLIGHT;
2199 }
2200}
2201
[email protected]310ebd6302011-10-10 19:06:282202void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:312203 int delay;
2204 if (send_content_state_immediately_)
2205 delay = 0;
2206 else if (is_hidden())
2207 delay = kDelaySecondsForContentStateSyncHidden;
2208 else
2209 delay = kDelaySecondsForContentStateSync;
2210
2211 if (nav_state_sync_timer_.IsRunning()) {
2212 // The timer is already running. If the delay of the timer maches the amount
2213 // we want to delay by, then return. Otherwise stop the timer so that it
2214 // gets started with the right delay.
2215 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2216 return;
2217 nav_state_sync_timer_.Stop();
2218 }
2219
[email protected]d323a172011-09-02 18:23:022220 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:282221 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:312222}
2223
[email protected]310ebd6302011-10-10 19:06:282224void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552225 mouse_over_url_ = GURL(url);
2226 UpdateTargetURL(mouse_over_url_, focus_url_);
2227}
2228
[email protected]310ebd6302011-10-10 19:06:282229void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552230 focus_url_ = GURL(url);
2231 UpdateTargetURL(focus_url_, mouse_over_url_);
2232}
2233
[email protected]0407e422012-05-18 19:51:252234void RenderViewImpl::startDragging(WebFrame* frame,
2235 const WebDragData& data,
[email protected]310ebd6302011-10-10 19:06:282236 WebDragOperationsMask mask,
2237 const WebImage& image,
[email protected]ceb36f7d2012-10-31 18:33:242238 const WebPoint& webImageOffset) {
[email protected]b67151d2012-05-25 23:23:242239 WebDropData drop_data(data);
2240 drop_data.referrer_policy = frame->document().referrerPolicy();
[email protected]ceb36f7d2012-10-31 18:33:242241 gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y);
[email protected]59f4f2fa2011-03-23 01:00:552242 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]b67151d2012-05-25 23:23:242243 drop_data,
[email protected]c27ae592010-03-18 15:24:412244 mask,
[email protected]976127072012-05-10 20:08:112245 image.getSkBitmap(),
[email protected]c27ae592010-03-18 15:24:412246 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522247}
2248
[email protected]310ebd6302011-10-10 19:06:282249bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:452250 return renderer_preferences_.can_accept_load_drops;
2251}
2252
[email protected]310ebd6302011-10-10 19:06:282253void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:522254 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2255}
2256
[email protected]310ebd6302011-10-10 19:06:282257void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:522258 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2259}
2260
[email protected]310ebd6302011-10-10 19:06:282261void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512262 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072263
[email protected]38b592902011-04-16 02:08:422264 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:492265}
2266
[email protected]572a6ca2012-10-11 19:38:012267void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
2268 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
2269}
2270
2271void RenderViewImpl::hasTouchEventHandlers(bool has_handlers) {
2272 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2273}
2274
[email protected]169d4282011-11-30 19:33:592275void RenderViewImpl::didUpdateLayout() {
2276 // We don't always want to set up a timer, only if we've been put in that
2277 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2278 // message.
2279 if (!send_preferred_size_changes_ || !webview())
2280 return;
2281
2282 if (check_preferred_size_timer_.IsRunning())
2283 return;
2284 check_preferred_size_timer_.Start(FROM_HERE,
2285 TimeDelta::FromMilliseconds(0), this,
2286 &RenderViewImpl::CheckPreferredSize);
2287}
2288
[email protected]310ebd6302011-10-10 19:06:282289void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522290 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2291}
2292
[email protected]310ebd6302011-10-10 19:06:282293int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002294 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522295}
2296
[email protected]310ebd6302011-10-10 19:06:282297int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002298 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522299}
2300
[email protected]310ebd6302011-10-10 19:06:282301void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:322302 const WebAccessibilityObject& obj,
2303 WebAccessibilityNotification notification) {
[email protected]2a84f9d2012-06-05 21:50:432304 if (renderer_accessibility_) {
2305 renderer_accessibility_->HandleWebAccessibilityNotification(
2306 obj, notification);
2307 }
[email protected]063afcb2011-09-29 07:54:322308}
2309
[email protected]310ebd6302011-10-10 19:06:282310void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:142311 const WebString& value) {
2312 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2313 key.utf8(),
2314 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262315}
2316
[email protected]79dbc662009-09-04 05:42:512317// WebKit::WebWidgetClient ----------------------------------------------------
2318
[email protected]310ebd6302011-10-10 19:06:282319void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122320 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2321 // we won't have to test for user gesture anymore and we can
2322 // move that code back to render_widget.cc
2323 if (webview() && webview()->mainFrame() &&
2324 webview()->mainFrame()->isProcessingUserGesture()) {
2325 Send(new ViewHostMsg_Focus(routing_id_));
2326 }
2327}
2328
[email protected]310ebd6302011-10-10 19:06:282329void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122330 // TODO(jcivelli): see TODO above in didFocus().
2331 if (webview() && webview()->mainFrame() &&
2332 webview()->mainFrame()->isProcessingUserGesture()) {
2333 Send(new ViewHostMsg_Blur(routing_id_));
2334 }
2335}
2336
initial.commit09911bf2008-07-26 23:55:292337// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282338// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292339// point to dispatch the ShowView message.
2340//
2341// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282342// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292343//
[email protected]310ebd6302011-10-10 19:06:282344void RenderViewImpl::show(WebNavigationPolicy policy) {
[email protected]b2142e962012-10-30 13:59:252345 if (did_show_) {
2346#if defined(OS_ANDROID)
2347 // When supports_multiple_windows is disabled, popups are reusing
2348 // the same view. In some scenarios, this makes WebKit to call show() twice.
2349 if (!webkit_preferences_.supports_multiple_windows)
2350 return;
2351#endif
2352 NOTREACHED() << "received extraneous Show call";
initial.commit09911bf2008-07-26 23:55:292353 return;
[email protected]b2142e962012-10-30 13:59:252354 }
initial.commit09911bf2008-07-26 23:55:292355 did_show_ = true;
2356
[email protected]b2142e962012-10-30 13:59:252357 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2358
[email protected]e9ff79c2012-10-19 21:31:262359 if (GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:042360 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:042361
[email protected]28295ec2009-10-16 05:34:332362 // Force new windows to a popup if they were not opened with a user gesture.
2363 if (!opened_by_user_gesture_) {
2364 // We exempt background tabs for compat with older versions of Chrome.
2365 // TODO(darin): This seems bogus. These should have a user gesture, so
2366 // we probably don't need this check.
2367 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2368 policy = WebKit::WebNavigationPolicyNewPopup;
2369 }
2370
initial.commit09911bf2008-07-26 23:55:292371 // NOTE: initial_pos_ may still have its default values at this point, but
2372 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2373 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282374 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2375 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292376 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242377 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292378}
2379
[email protected]310ebd6302011-10-10 19:06:282380void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292381 DCHECK(did_show_) << "should already have shown the view";
2382
[email protected]c1f50aa2010-02-18 03:46:572383 // We must keep WebKit's shared timer running in this case in order to allow
2384 // showModalDialog to function properly.
2385 //
2386 // TODO(darin): WebKit should really be smarter about suppressing events and
2387 // timers so that we do not need to manage the shared timer in such a heavy
2388 // handed manner.
2389 //
[email protected]f1a29a02011-10-06 23:08:442390 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2391 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572392
[email protected]08a1c8102012-05-11 23:14:262393 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
2394 routing_id_, opener_id_));
initial.commit09911bf2008-07-26 23:55:292395}
2396
[email protected]2b624c562011-10-27 22:58:262397bool RenderViewImpl::enterFullScreen() {
2398 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2399 return true;
2400}
2401
2402void RenderViewImpl::exitFullScreen() {
2403 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2404}
2405
[email protected]217690d2012-01-27 07:33:112406bool RenderViewImpl::requestPointerLock() {
2407 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2408}
2409
2410void RenderViewImpl::requestPointerUnlock() {
2411 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2412}
2413
2414bool RenderViewImpl::isPointerLocked() {
2415 return mouse_lock_dispatcher_->IsMouseLockedTo(
2416 webwidget_mouse_lock_target_.get());
2417}
2418
[email protected]7a1ec28a2012-03-28 21:10:242419void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
2420 CompositorThread* compositor_thread =
2421 RenderThreadImpl::current()->compositor_thread();
2422 if (compositor_thread)
2423 compositor_thread->AddInputHandler(
2424 routing_id_, input_handler_identifier, AsWeakPtr());
2425
2426 RenderWidget::didActivateCompositor(input_handler_identifier);
[email protected]1c0c9bc2012-10-08 22:41:482427
2428 ProcessAcceleratedPinchZoomFlags(*CommandLine::ForCurrentProcess());
[email protected]7a1ec28a2012-03-28 21:10:242429}
2430
[email protected]3d9689372009-09-10 04:29:172431// WebKit::WebFrameClient -----------------------------------------------------
2432
[email protected]310ebd6302011-10-10 19:06:282433WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2434 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:552435 WebPlugin* plugin = NULL;
[email protected]e9ff79c2012-10-19 21:31:262436 if (GetContentClient()->renderer()->OverrideCreatePlugin(
[email protected]eaacd1f2011-09-23 02:32:552437 this, frame, params, &plugin)) {
2438 return plugin;
2439 }
2440
[email protected]e9ff79c2012-10-19 21:31:262441 if (UTF16ToASCII(params.mimeType) == kBrowserPluginMimeType) {
[email protected]6cd7c6b2012-10-25 03:26:232442 return BrowserPluginManager::Get()->
2443 CreateBrowserPlugin(this, frame, params);
[email protected]e6e56752012-08-10 00:46:062444 }
2445
[email protected]a813c8e2011-10-08 01:34:112446 webkit::WebPluginInfo info;
2447 std::string mime_type;
2448 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2449 params.mimeType.utf8(), &info, &mime_type);
2450 if (!found)
2451 return NULL;
2452
2453 WebPluginParams params_to_use = params;
2454 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312455 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172456}
2457
[email protected]310ebd6302011-10-10 19:06:282458WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422459 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372460 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422461
[email protected]30447b62009-11-13 01:13:372462 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512463 bool exists = false;
[email protected]30447b62009-11-13 01:13:372464 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512465 ViewHostMsg_CreateWorker_Params params;
2466 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512467 params.name = name;
2468 params.document_id = document_id;
2469 params.render_view_route_id = routing_id_;
2470 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232471 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372472 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512473 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372474 if (url_mismatch) {
2475 return NULL;
2476 } else {
[email protected]f1a29a02011-10-06 23:08:442477 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492478 document_id,
[email protected]6de0bcf2010-02-17 22:00:512479 exists,
[email protected]30447b62009-11-13 01:13:372480 route_id,
2481 routing_id_);
2482 }
[email protected]9c00f002009-11-05 22:37:422483}
2484
[email protected]97b150db2012-08-16 18:26:022485WebMediaPlayer* RenderViewImpl::createMediaPlayer(
2486 WebFrame* frame, const WebKit::WebURL& url, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442487 FOR_EACH_OBSERVER(
2488 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172489
[email protected]780fc8242012-09-19 20:28:522490 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
[email protected]25fb9b32012-04-27 03:21:552491#if defined(OS_ANDROID)
[email protected]855623ed2012-09-24 18:59:552492 WebGraphicsContext3D* resource_context =
2493 GetWebView()->sharedGraphicsContext3D();
2494
2495 GpuChannelHost* gpu_channel_host =
2496 RenderThreadImpl::current()->EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:262497 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
[email protected]855623ed2012-09-24 18:59:552498 if (!gpu_channel_host) {
2499 LOG(ERROR) << "Failed to establish GPU channel for media player";
2500 return NULL;
2501 }
2502
[email protected]780fc8242012-09-19 20:28:522503 if (cmd_line->HasSwitch(switches::kMediaPlayerInRenderProcess)) {
2504 if (!media_bridge_manager_.get()) {
2505 media_bridge_manager_.reset(
2506 new webkit_media::MediaPlayerBridgeManagerImpl(1));
2507 }
2508 return new webkit_media::WebMediaPlayerInProcessAndroid(
2509 frame,
2510 client,
2511 cookieJar(frame),
2512 media_player_manager_.get(),
2513 media_bridge_manager_.get(),
[email protected]e9ff79c2012-10-19 21:31:262514 new StreamTextureFactoryImpl(
[email protected]855623ed2012-09-24 18:59:552515 resource_context, gpu_channel_host, routing_id_),
[email protected]780fc8242012-09-19 20:28:522516 cmd_line->HasSwitch(switches::kDisableMediaHistoryLogging));
2517 }
2518 if (!media_player_proxy_) {
[email protected]e9ff79c2012-10-19 21:31:262519 media_player_proxy_ = new WebMediaPlayerProxyImplAndroid(
[email protected]780fc8242012-09-19 20:28:522520 this, media_player_manager_.get());
2521 }
2522 return new webkit_media::WebMediaPlayerImplAndroid(
2523 frame,
2524 client,
2525 media_player_manager_.get(),
2526 media_player_proxy_,
[email protected]e9ff79c2012-10-19 21:31:262527 new StreamTextureFactoryImpl(
[email protected]855623ed2012-09-24 18:59:552528 resource_context, gpu_channel_host, routing_id_));
[email protected]25fb9b32012-04-27 03:21:552529#endif
2530
[email protected]bb6fd402011-12-09 02:45:442531 media::MessageLoopFactory* message_loop_factory =
[email protected]b80322902012-03-06 01:33:502532 new media::MessageLoopFactory();
[email protected]bb6fd402011-12-09 02:45:442533 media::FilterCollection* collection = new media::FilterCollection();
2534 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372535
[email protected]9e2269d2012-01-07 00:06:212536 RenderAudioSourceProvider* audio_source_provider = NULL;
2537
[email protected]3d9689372009-09-10 04:29:172538 // Add in any custom filter factories first.
[email protected]3d9689372009-09-10 04:29:172539 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212540 // audio_source_provider is a "provider" to WebKit, and a sink
2541 // from the perspective of the audio renderer.
2542 audio_source_provider = new RenderAudioSourceProvider();
2543
2544 // Add the chrome specific audio renderer, using audio_source_provider
2545 // as the sink.
[email protected]37136d162012-04-09 23:39:192546 media::AudioRendererImpl* audio_renderer =
2547 new media::AudioRendererImpl(audio_source_provider);
[email protected]9e2269d2012-01-07 00:06:212548 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172549 }
2550
[email protected]15d206e2012-08-17 22:35:132551 WebGraphicsContext3DCommandBufferImpl* context3d = NULL;
[email protected]5f04c3532012-09-25 01:28:392552 if (!cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode))
[email protected]15d206e2012-08-17 22:35:132553 context3d = RenderThreadImpl::current()->GetGpuVDAContext3D();
[email protected]851334d2012-06-15 22:39:312554 if (context3d) {
[email protected]084c8552012-08-12 22:51:202555 scoped_refptr<base::MessageLoopProxy> factories_loop =
[email protected]84a83e192012-03-09 18:43:402556 RenderThreadImpl::current()->compositor_thread() ?
2557 RenderThreadImpl::current()->compositor_thread()->GetWebThread()
[email protected]084c8552012-08-12 22:51:202558 ->message_loop()->message_loop_proxy() :
2559 base::MessageLoopProxy::current();
[email protected]e1d69d762011-12-13 05:12:182560 GpuChannelHost* gpu_channel_host =
2561 RenderThreadImpl::current()->EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:262562 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
[email protected]873da262012-08-10 22:02:472563 collection->GetVideoDecoders()->push_back(new media::GpuVideoDecoder(
[email protected]084c8552012-08-12 22:51:202564 base::Bind(&media::MessageLoopFactory::GetMessageLoop,
2565 base::Unretained(message_loop_factory),
[email protected]c462c902012-09-06 13:13:422566 media::MessageLoopFactory::kDecoder),
[email protected]84a83e192012-03-09 18:43:402567 factories_loop,
[email protected]8d4359282012-01-14 00:53:312568 new RendererGpuVideoDecoderFactories(
[email protected]84a83e192012-03-09 18:43:402569 gpu_channel_host, factories_loop, context3d)));
[email protected]e1d69d762011-12-13 05:12:182570 }
[email protected]e1d69d762011-12-13 05:12:182571
[email protected]5d65fe92012-06-02 00:48:552572 WebMediaPlayer* media_player =
[email protected]e9ff79c2012-10-19 21:31:262573 GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
[email protected]da952fd2012-01-13 03:49:252574 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1113bfdf2012-07-16 21:46:102575 audio_source_provider, message_loop_factory, media_stream_impl_,
2576 render_media_log);
[email protected]da952fd2012-01-13 03:49:252577 if (!media_player) {
[email protected]ba42ac4f2012-10-11 20:28:142578#if defined(ENABLE_WEBRTC)
[email protected]5f04c3532012-09-25 01:28:392579 // TODO(wjia): when all patches related to WebMediaPlayerMS have been
2580 // landed, remove the switch. Refer to crbug.com/142988.
[email protected]1fba73c12012-10-10 23:36:202581 if (!cmd_line->HasSwitch(switches::kDisableWebMediaPlayerMS) &&
2582 MediaStreamImpl::CheckMediaStream(url)) {
[email protected]5f04c3532012-09-25 01:28:392583 EnsureMediaStreamImpl();
[email protected]1fba73c12012-10-10 23:36:202584 return new webkit_media::WebMediaPlayerMS(
2585 frame, client, AsWeakPtr(), media_stream_impl_, render_media_log);
[email protected]5f04c3532012-09-25 01:28:392586 }
[email protected]ba42ac4f2012-10-11 20:28:142587#endif
[email protected]5f04c3532012-09-25 01:28:392588
[email protected]cec4eb82012-01-12 17:51:562589 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252590 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1113bfdf2012-07-16 21:46:102591 audio_source_provider, message_loop_factory, media_stream_impl_,
2592 render_media_log);
[email protected]bb6fd402011-12-09 02:45:442593 }
[email protected]cec4eb82012-01-12 17:51:562594 return media_player;
[email protected]3d9689372009-09-10 04:29:172595}
2596
[email protected]310ebd6302011-10-10 19:06:282597WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212598 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232599 if (!frame || !frame->view())
2600 return NULL;
[email protected]035545f2010-04-09 13:10:212601 return new RendererWebApplicationCacheHostImpl(
2602 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442603 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212604}
2605
[email protected]310ebd6302011-10-10 19:06:282606WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382607 return &cookie_jar_;
2608}
2609
[email protected]0720b532012-08-28 19:23:372610void RenderViewImpl::didCreateFrame(WebFrame* parent, WebFrame* child) {
[email protected]0720b532012-08-28 19:23:372611 if (!updating_frame_tree_)
2612 SendUpdatedFrameTree(NULL);
2613}
2614
[email protected]310ebd6302011-10-10 19:06:282615void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]0720b532012-08-28 19:23:372616 if (is_loading_) {
2617 pending_frame_tree_update_ = true;
2618 // Make sure observers are notified, even if we return right away.
2619 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
2620 return;
2621 }
2622 if (!updating_frame_tree_)
2623 SendUpdatedFrameTree(frame);
2624
[email protected]676126f72011-01-15 00:03:512625 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452626}
2627
[email protected]310ebd6302011-10-10 19:06:282628void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512629 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172630}
2631
[email protected]310ebd6302011-10-10 19:06:282632void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172633 WebFrame* frame, const WebURLRequest& request,
2634 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342635 loadURLExternally(frame, request, policy, WebString());
2636}
2637
[email protected]5e92282f2012-08-17 08:11:572638void RenderViewImpl::Repaint(const gfx::Size& size) {
2639 OnMsgRepaint(size);
2640}
2641
[email protected]310ebd6302011-10-10 19:06:282642void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342643 WebFrame* frame, const WebURLRequest& request,
2644 WebNavigationPolicy policy,
2645 const WebString& suggested_name) {
[email protected]56505542012-05-12 00:25:372646 Referrer referrer(
2647 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2648 GetReferrerPolicyFromRequest(frame, request));
[email protected]efce17b2009-09-11 18:04:592649 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342650 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2651 suggested_name));
[email protected]efce17b2009-09-11 18:04:592652 } else {
[email protected]56505542012-05-12 00:25:372653 OpenURL(frame, request.url(), referrer, policy);
[email protected]efce17b2009-09-11 18:04:592654 }
[email protected]3d9689372009-09-10 04:29:172655}
2656
[email protected]310ebd6302011-10-10 19:06:282657WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172658 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222659 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]0639c063a2012-03-22 20:55:332660 Referrer referrer(
2661 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:592662 GetReferrerPolicyFromRequest(frame, request));
[email protected]0639c063a2012-03-22 20:55:332663
[email protected]992db4c2011-05-12 15:37:152664 if (is_swapped_out_) {
[email protected]e9ff79c2012-10-19 21:31:262665 if (request.url() != GURL(kSwappedOutURL)) {
[email protected]0639c063a2012-03-22 20:55:332666 // Targeted links may try to navigate a swapped out frame. Allow the
2667 // browser process to navigate the tab instead. Note that it is also
2668 // possible for non-targeted navigations (from this view) to arrive
2669 // here just after we are swapped out. It's ok to send them to the
2670 // browser, as long as they're for the top level frame.
2671 // TODO(creis): Ensure this supports targeted form submissions when
2672 // fixing http://crbug.com/101395.
2673 if (frame->parent() == NULL) {
2674 OpenURL(frame, request.url(), referrer, default_policy);
2675 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2676 }
2677
2678 // We should otherwise ignore in-process iframe navigations, if they
2679 // arrive just after we are swapped out.
[email protected]73eb2602012-02-09 19:50:552680 return WebKit::WebNavigationPolicyIgnore;
[email protected]0639c063a2012-03-22 20:55:332681 }
[email protected]73eb2602012-02-09 19:50:552682
[email protected]e9ff79c2012-10-19 21:31:262683 // Allow kSwappedOutURL to complete.
[email protected]992db4c2011-05-12 15:37:152684 return default_policy;
2685 }
2686
[email protected]3d9689372009-09-10 04:29:172687 // Webkit is asking whether to navigate to a new URL.
2688 // This is fine normally, except if we're showing UI from one security
2689 // context and they're trying to navigate to a different context.
2690 const GURL& url = request.url();
2691
[email protected]d19ea342011-04-20 20:31:132692 // A content initiated navigation may have originated from a link-click,
2693 // script, drag-n-drop operation, etc.
2694 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072695 DocumentState::FromDataSource(frame->provisionalDataSource())->
2696 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132697
[email protected]a8c269a2011-10-25 20:17:222698 // Experimental:
2699 // If --enable-strict-site-isolation is enabled, send all top-level
2700 // navigations to the browser to let it swap processes when crossing site
2701 // boundaries. This is currently expected to break some script calls and
2702 // navigations, such as form submissions.
2703 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102704 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2705 !frame->parent() && (is_content_initiated || is_redirect)) {
2706 WebString origin_str = frame->document().securityOrigin().toString();
2707 GURL frame_url(origin_str.utf8().data());
[email protected]18fb7a772012-09-20 19:25:092708 // TODO(cevans): revisit whether this site check is still necessary once
[email protected]313b80bd2011-11-23 03:49:102709 // crbug.com/101395 is fixed.
[email protected]18fb7a772012-09-20 19:25:092710 if (!net::RegistryControlledDomainService::SameDomainOrHost(frame_url,
2711 url) ||
2712 frame_url.scheme() != url.scheme()) {
[email protected]313b80bd2011-11-23 03:49:102713 OpenURL(frame, url, referrer, default_policy);
2714 return WebKit::WebNavigationPolicyIgnore;
2715 }
[email protected]a8c269a2011-10-25 20:17:222716 }
2717
[email protected]fd3238af2012-05-22 18:55:302718 // If the browser is interested, then give it a chance to look at the request.
[email protected]5f000f272012-01-19 05:25:082719 if (is_content_initiated) {
[email protected]fd3238af2012-05-22 18:55:302720 bool browser_handles_request =
2721 renderer_preferences_.browser_handles_non_local_top_level_requests &&
[email protected]5f000f272012-01-19 05:25:082722 IsNonLocalTopLevelNavigation(url, frame, type);
[email protected]fd3238af2012-05-22 18:55:302723 if (!browser_handles_request) {
2724 browser_handles_request =
2725 renderer_preferences_.browser_handles_all_top_level_requests &&
2726 IsTopLevelNavigation(frame);
2727 }
2728
2729 if (browser_handles_request) {
[email protected]5f000f272012-01-19 05:25:082730 // Reset these counters as the RenderView could be reused for the next
2731 // navigation.
2732 page_id_ = -1;
2733 last_page_id_sent_to_browser_ = -1;
2734 OpenURL(frame, url, referrer, default_policy);
2735 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2736 }
[email protected]3d9689372009-09-10 04:29:172737 }
2738
[email protected]dc67e1c32012-06-08 00:10:402739 // Use the frame's original request's URL rather than the document's URL for
2740 // subsequent checks. For a popup, the document's URL may become the opener
2741 // window's URL if the opener has called document.write().
2742 // See http://crbug.com/93517.
2743 GURL old_url(frame->dataSource()->request().url());
2744
[email protected]6101c342010-12-16 22:44:372745 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552746 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:042747 // top-level navigations (not iframes). But we sometimes navigate to
2748 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:372749 //
[email protected]744c2a22012-03-15 18:42:042750 // Note: this is known to break POST submissions when crossing process
2751 // boundaries until http://crbug.com/101395 is fixed. This is better for
2752 // security than loading a WebUI, extension or app page in the wrong process.
2753 // POST requests don't work because this mechanism does not preserve form
2754 // POST data. We will need to send the request's httpBody data up to the
2755 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:572756 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2757 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222758 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:042759 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:372760 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:042761
2762 // All navigations to WebUI URLs or within WebUI-enabled RenderProcesses
2763 // must be handled by the browser process so that the correct bindings and
2764 // data sources can be registered.
2765 // Similarly, navigations to view-source URLs or within ViewSource mode
2766 // must be handled by the browser process.
[email protected]dc67e1c32012-06-08 00:10:402767 // Lastly, access to file:// URLs from non-file:// URL pages must be
2768 // handled by the browser so that ordinary renderer processes don't get
2769 // blessed with file permissions.
2770 int cumulative_bindings = RenderProcess::current()->GetEnabledBindings();
2771 bool is_initial_navigation = page_id_ == -1;
[email protected]6101c342010-12-16 22:44:372772 bool should_fork =
[email protected]e9ff79c2012-10-19 21:31:262773 GetContentClient()->HasWebUIScheme(url) ||
2774 (cumulative_bindings & BINDINGS_POLICY_WEB_UI) ||
[email protected]744c2a22012-03-15 18:42:042775 url.SchemeIs(chrome::kViewSourceScheme) ||
2776 frame->isViewSourceModeEnabled();
[email protected]5351dbc2010-08-27 15:22:112777
[email protected]dc67e1c32012-06-08 00:10:402778 if (!should_fork && url.SchemeIs(chrome::kFileScheme)) {
2779 // Fork non-file to file opens. Check the opener URL if this is the
2780 // initial navigation in a newly opened window.
2781 GURL source_url(old_url);
2782 if (is_initial_navigation && source_url.is_empty() && frame->opener())
2783 source_url = frame->opener()->top()->document().url();
2784 DCHECK(!source_url.is_empty());
2785 should_fork = !source_url.SchemeIs(chrome::kFileScheme);
2786 }
2787
[email protected]e48869a2011-04-01 19:56:032788 if (!should_fork) {
2789 // Give the embedder a chance.
[email protected]744c2a22012-03-15 18:42:042790 // For now, we skip this for POST submissions. This is because
2791 // http://crbug.com/101395 is more likely to cause compatibility issues
2792 // with hosted apps and extensions than WebUI pages. We will remove this
2793 // check when cross-process POST submissions are supported.
2794 if (request.httpMethod() == "GET") {
[email protected]e9ff79c2012-10-19 21:31:262795 should_fork = GetContentClient()->renderer()->ShouldFork(
[email protected]744c2a22012-03-15 18:42:042796 frame, url, is_initial_navigation, &send_referrer);
2797 }
[email protected]6101c342010-12-16 22:44:372798 }
2799
2800 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152801 OpenURL(
2802 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112803 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2804 }
[email protected]3d9689372009-09-10 04:29:172805 }
2806
2807 // Detect when a page is "forking" a new tab that can be safely rendered in
2808 // its own process. This is done by sites like Gmail that try to open links
2809 // in new windows without script connections back to the original page. We
2810 // treat such cases as browser navigations (in which we will create a new
2811 // renderer for a cross-site navigation), rather than WebKit navigations.
2812 //
2813 // We use the following heuristic to decide whether to fork a new page in its
2814 // own process:
2815 // The parent page must open a new tab to about:blank, set the new tab's
2816 // window.opener to null, and then redirect the tab to a cross-site URL using
2817 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462818 //
2819 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2820 // (see below).
[email protected]3d9689372009-09-10 04:29:172821 bool is_fork =
2822 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582823 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172824 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522825 historyBackListCount() < 1 &&
2826 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172827 // The parent page must have set the child's window.opener to null before
2828 // redirecting to the desired URL.
2829 frame->opener() == NULL &&
2830 // Must be a top-level frame.
2831 frame->parent() == NULL &&
2832 // Must not have issued the request from this page.
2833 is_content_initiated &&
2834 // Must be targeted at the current tab.
2835 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2836 // Must be a JavaScript navigation, which appears as "other".
2837 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462838
[email protected]f92ce2b2012-03-06 18:02:592839 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:172840 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152841 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172842 return WebKit::WebNavigationPolicyIgnore;
2843 }
2844
2845 return default_policy;
2846}
2847
[email protected]310ebd6302011-10-10 19:06:282848bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492849 WebFrame* frame, const WebURLRequest& request) {
2850 // We allow WebKit to think that everything can be handled even though
2851 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342852 return true;
2853}
2854
[email protected]310ebd6302011-10-10 19:06:282855WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492856 WebFrame* frame, const WebURLRequest& request) {
2857 NOTREACHED(); // Since we said we can handle all requests.
2858 return WebURLError();
2859}
2860
[email protected]310ebd6302011-10-10 19:06:282861WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492862 WebFrame* frame, const WebURLRequest& request) {
2863 WebURLError error;
2864 error.domain = WebString::fromUTF8(net::kErrorDomain);
2865 error.reason = net::ERR_ABORTED;
2866 error.unreachableURL = request.url();
2867 return error;
[email protected]7b7a7dc2009-10-19 02:23:342868}
2869
[email protected]310ebd6302011-10-10 19:06:282870void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492871 WebFrame*, const WebURLError&) {
2872 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342873}
2874
[email protected]310ebd6302011-10-10 19:06:282875void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432876 const WebKit::WebFormElement& form) {
2877 // Some login forms have onSubmit handlers that put a hash of the password
2878 // into a hidden field and then clear the password. (Issue 28910.)
2879 // This method gets called before any of those handlers run, so save away
2880 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072881 DocumentState* document_state =
2882 DocumentState::FromDataSource(frame->dataSource());
[email protected]e9ff79c2012-10-19 21:31:262883 document_state->set_password_form_data(CreatePasswordForm(form));
[email protected]90eeddb2010-05-06 21:06:432884}
2885
[email protected]310ebd6302011-10-10 19:06:282886void RenderViewImpl::willSubmitForm(WebFrame* frame,
2887 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072888 DocumentState* document_state =
2889 DocumentState::FromDataSource(frame->provisionalDataSource());
2890 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172891
[email protected]e9ff79c2012-10-19 21:31:262892 if (navigation_state->transition_type() == PAGE_TRANSITION_LINK)
2893 navigation_state->set_transition_type(PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172894
2895 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352896 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072897 document_state->set_searchable_form_url(web_searchable_form_data.url());
2898 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212899 web_searchable_form_data.encoding().utf8());
[email protected]a045f4e32012-08-31 09:36:072900 scoped_ptr<PasswordForm> password_form_data =
[email protected]e9ff79c2012-10-19 21:31:262901 CreatePasswordForm(form);
[email protected]90eeddb2010-05-06 21:06:432902
[email protected]098c95cb2011-04-28 16:49:012903 // In order to save the password that the user actually typed and not one
2904 // that may have gotten transformed by the site prior to submit, recover it
2905 // from the form contents already stored by |willSendSubmitEvent| into the
2906 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2907 // which is what we're storing into now.)
[email protected]a045f4e32012-08-31 09:36:072908 if (password_form_data.get()) {
[email protected]007733c2011-11-17 00:34:072909 DocumentState* old_document_state =
2910 DocumentState::FromDataSource(frame->dataSource());
2911 if (old_document_state) {
2912 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432913 if (old_form_data && old_form_data->action == password_form_data->action)
2914 password_form_data->password_value = old_form_data->password_value;
2915 }
2916 }
[email protected]3d9689372009-09-10 04:29:172917
[email protected]a045f4e32012-08-31 09:36:072918 document_state->set_password_form_data(password_form_data.Pass());
2919
[email protected]2a5b1732011-04-01 23:55:552920 FOR_EACH_OBSERVER(
2921 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172922}
2923
[email protected]310ebd6302011-10-10 19:06:282924void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172925 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2926 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382927 FOR_EACH_OBSERVER(
2928 RenderViewObserver, observers_,
2929 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172930}
2931
[email protected]310ebd6302011-10-10 19:06:282932void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382933 FOR_EACH_OBSERVER(
2934 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172935}
2936
[email protected]310ebd6302011-10-10 19:06:282937void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172938 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152939 if (!frame->parent()) {
2940 WebDataSource* ds = frame->provisionalDataSource();
2941 // If there's no provisional data source, it's a reference fragment
2942 // navigation.
2943 completed_client_redirect_src_ = Referrer(
[email protected]ca662822012-05-11 17:53:592944 from, ds ? GetReferrerPolicyFromRequest(frame, ds->request()) :
[email protected]f36f4092012-05-09 18:31:042945 frame->document().referrerPolicy());
[email protected]445e1042011-12-03 21:03:152946 }
[email protected]eb0bff942011-04-07 22:08:382947 FOR_EACH_OBSERVER(
2948 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172949}
2950
[email protected]310ebd6302011-10-10 19:06:282951void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:572952 bool content_initiated = !pending_navigation_params_.get();
2953
[email protected]007733c2011-11-17 00:34:072954 DocumentState* document_state = DocumentState::FromDataSource(ds);
2955 if (!document_state) {
2956 document_state = new DocumentState;
2957 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:572958 if (!content_initiated)
2959 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:072960 }
2961
[email protected]bf70edce2012-06-20 22:32:222962 // Carry over the user agent override flag, if it exists.
2963 if (content_initiated && webview() && webview()->mainFrame() &&
2964 webview()->mainFrame()->dataSource()) {
2965 DocumentState* old_document_state =
2966 DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
2967 if (old_document_state) {
2968 document_state->set_is_overriding_user_agent(
2969 old_document_state->is_overriding_user_agent());
2970 }
2971 }
2972
[email protected]3d9689372009-09-10 04:29:172973 // The rest of RenderView assumes that a WebDataSource will always have a
2974 // non-null NavigationState.
[email protected]e1ed5a12012-08-08 19:57:442975 if (content_initiated) {
[email protected]007733c2011-11-17 00:34:072976 document_state->set_navigation_state(
2977 NavigationState::CreateContentInitiated());
[email protected]e1ed5a12012-08-08 19:57:442978 } else {
[email protected]45d83a12012-04-06 22:57:572979 document_state->set_navigation_state(CreateNavigationStateFromPending());
2980 pending_navigation_params_.reset();
2981 }
[email protected]8a3125a712010-08-09 18:58:512982
[email protected]007733c2011-11-17 00:34:072983 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512984 // navigating from a page that used prefetching using a link on that
2985 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072986 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512987 // this value appropriately.
2988 // TODO(gavinp): catch the important case of navigation in a new
2989 // renderer process.
2990 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302991 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522992 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512993 const GURL referrer(
2994 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2995 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072996 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512997 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:412998 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:512999 WebDataSource* old_frame_ds = old_frame->dataSource();
3000 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:073001 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513002 break;
3003 }
3004 }
3005 }
3006 }
3007 }
3008
[email protected]4c1b6f0b2010-02-07 16:38:183009 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523010 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513011 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183012 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:073013 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:183014 break;
3015 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:073016 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:183017 break;
3018 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:073019 document_state->set_load_type(
3020 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:183021 break;
3022 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:073023 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:183024 break;
3025 }
3026 }
[email protected]fa7b6b542009-11-03 05:02:303027
[email protected]946a0032011-03-31 18:42:283028 FOR_EACH_OBSERVER(
3029 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:173030}
3031
[email protected]45d83a12012-04-06 22:57:573032void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:073033 DocumentState* document_state) {
3034 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:573035 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:073036
[email protected]45d83a12012-04-06 22:57:573037 if (!params.url.SchemeIs(chrome::kJavaScriptScheme) &&
3038 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
3039 // We're doing a load of a page that was restored from the last session. By
3040 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
3041 // can result in stale data for pages that are set to expire. We explicitly
3042 // override that by setting the policy here so that as necessary we load
3043 // from the network.
3044 document_state->set_cache_policy_override(
3045 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:073046 }
3047
3048 if (IsReload(params))
3049 document_state->set_load_type(DocumentState::RELOAD);
3050 else if (!params.state.empty())
3051 document_state->set_load_type(DocumentState::HISTORY_LOAD);
3052 else
3053 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]ca662822012-05-11 17:53:593054
3055 document_state->set_referrer_policy(params.referrer.policy);
[email protected]bf70edce2012-06-20 22:32:223056 document_state->set_is_overriding_user_agent(params.is_overriding_user_agent);
[email protected]a3a5397d2012-09-12 06:50:343057 document_state->set_must_reset_scroll_and_scale_state(
3058 params.navigation_type ==
3059 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]951a64832012-10-11 16:26:373060 document_state->set_can_load_local_resources(params.can_load_local_resources);
[email protected]45d83a12012-04-06 22:57:573061}
[email protected]007733c2011-11-17 00:34:073062
[email protected]45d83a12012-04-06 22:57:573063NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
3064 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
3065 NavigationState* navigation_state = NULL;
3066
3067 // A navigation resulting from loading a javascript URL should not be treated
3068 // as a browser initiated event. Instead, we want it to look as if the page
3069 // initiated any load resulting from JS execution.
3070 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
3071 navigation_state = NavigationState::CreateBrowserInitiated(
3072 params.page_id,
3073 params.pending_history_list_offset,
3074 params.transition);
3075 navigation_state->set_transferred_request_child_id(
3076 params.transferred_request_child_id);
3077 navigation_state->set_transferred_request_request_id(
3078 params.transferred_request_request_id);
[email protected]80744782012-05-04 01:47:003079 navigation_state->set_allow_download(params.allow_download);
[email protected]45d83a12012-04-06 22:57:573080 } else {
3081 navigation_state = NavigationState::CreateContentInitiated();
3082 }
3083 return navigation_state;
[email protected]007733c2011-11-17 00:34:073084}
3085
[email protected]5b52cd2f712012-03-28 02:12:483086void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
3087 bool enable_viewport =
[email protected]06ea34a2012-05-07 18:52:103088 command_line.HasSwitch(switches::kEnableViewport);
[email protected]5b52cd2f712012-03-28 02:12:483089 bool enable_fixed_layout =
3090 command_line.HasSwitch(switches::kEnableFixedLayout);
3091
3092 webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport);
3093 webview()->settings()->setFixedElementsLayoutRelativeToFrame(true);
3094
3095 if (enable_viewport) {
3096 webview()->settings()->setViewportEnabled(true);
3097 } else if (enable_fixed_layout) {
3098 std::string str =
3099 command_line.GetSwitchValueASCII(switches::kEnableFixedLayout);
3100 std::vector<std::string> tokens;
3101 base::SplitString(str, ',', &tokens);
3102 if (tokens.size() == 2) {
3103 int width, height;
3104 if (base::StringToInt(tokens[0], &width) &&
3105 base::StringToInt(tokens[1], &height))
[email protected]e1ed5a12012-08-08 19:57:443106 webview()->setFixedLayoutSize(WebSize(width, height));
[email protected]5b52cd2f712012-03-28 02:12:483107 }
3108 }
[email protected]1c0c9bc2012-10-08 22:41:483109
3110 ProcessAcceleratedPinchZoomFlags(command_line);
3111}
3112
3113void RenderViewImpl::ProcessAcceleratedPinchZoomFlags(
3114 const CommandLine& command_line) {
3115 bool enable_viewport =
3116 command_line.HasSwitch(switches::kEnableViewport);
3117 bool enable_pinch = enable_viewport ||
3118 command_line.HasSwitch(switches::kEnablePinch);
3119 bool enable_pinch_in_compositor =
[email protected]65bfd9972012-10-19 03:39:373120 command_line.HasSwitch(cc::switches::kEnablePinchInCompositor);
[email protected]1c0c9bc2012-10-08 22:41:483121
3122 if (!enable_pinch &&
3123 webview()->isAcceleratedCompositingActive() &&
3124 webkit_preferences_.apply_default_device_scale_factor_in_compositor &&
3125 device_scale_factor_ != 1) {
3126 // Page scaling is disabled by default when applying a scale factor in the
3127 // compositor since they are currently incompatible.
3128 webview()->setPageScaleFactorLimits(1, 1);
3129 }
3130
3131 if (enable_pinch_in_compositor &&
3132 webview()->isAcceleratedCompositingActive())
3133 webview()->setPageScaleFactorLimits(1, 4);
[email protected]5b52cd2f712012-03-28 02:12:483134}
3135
[email protected]310ebd6302011-10-10 19:06:283136void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173137 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:073138 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:173139
[email protected]3d9689372009-09-10 04:29:173140 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:073141 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:173142 double event_time = ds->triggeringEventTime();
3143 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:073144 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:173145 }
3146
[email protected]05c8e502010-08-15 15:13:523147 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:073148 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:523149
[email protected]3d9689372009-09-10 04:29:173150 bool is_top_most = !frame->parent();
3151 if (is_top_most) {
3152 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133153 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173154
3155 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:153156 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173157 } else if (frame->parent()->isLoading()) {
3158 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003159 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:073160 document_state->navigation_state()->set_transition_type(
[email protected]e9ff79c2012-10-19 21:31:263161 PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:173162 }
3163
[email protected]28685da92011-02-07 21:49:173164 FOR_EACH_OBSERVER(
3165 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
3166
[email protected]3d9689372009-09-10 04:29:173167 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]d37c33e2012-10-12 13:35:133168 routing_id_, frame->identifier(),
3169 frame->parent() ? frame->parent()->identifier() : -1,
3170 is_top_most, GetOpenerUrl(), ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173171}
3172
[email protected]400992b2012-06-14 00:03:543173void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
3174 WebFrame* frame) {
3175 if (frame->parent())
3176 return;
3177 // Received a redirect on the main frame.
3178 WebDataSource* data_source = frame->provisionalDataSource();
3179 if (!data_source) {
3180 // Should only be invoked when we have a data source.
3181 NOTREACHED();
3182 return;
3183 }
3184 std::vector<GURL> redirects;
3185 GetRedirectChain(data_source, &redirects);
3186 if (redirects.size() >= 2) {
3187 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
3188 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
3189 }
3190}
3191
[email protected]310ebd6302011-10-10 19:06:283192void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
3193 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173194 // Notify the browser that we failed a provisional load with an error.
3195 //
3196 // Note: It is important this notification occur before DidStopLoading so the
3197 // SSL manager can react to the provisional load failure before being
3198 // notified the load stopped.
3199 //
3200 WebDataSource* ds = frame->provisionalDataSource();
3201 DCHECK(ds);
3202
3203 const WebURLRequest& failed_request = ds->request();
3204
[email protected]28685da92011-02-07 21:49:173205 FOR_EACH_OBSERVER(
3206 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
3207
[email protected]3d9689372009-09-10 04:29:173208 bool show_repost_interstitial =
3209 (error.reason == net::ERR_CACHE_MISS &&
3210 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:583211
3212 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
3213 params.frame_id = frame->identifier();
3214 params.is_main_frame = !frame->parent();
3215 params.error_code = error.reason;
[email protected]e9ff79c2012-10-19 21:31:263216 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]d7b175e2011-10-11 15:31:583217 failed_request,
3218 error,
3219 NULL,
3220 &params.error_description);
3221 params.url = error.unreachableURL;
3222 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:173223 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:583224 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:173225
3226 // Don't display an error page if this is simply a cancelled load. Aside
3227 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3228 if (error.reason == net::ERR_ABORTED)
3229 return;
3230
3231 // Make sure we never show errors in view source mode.
3232 frame->enableViewSourceMode(false);
3233
[email protected]007733c2011-11-17 00:34:073234 DocumentState* document_state = DocumentState::FromDataSource(ds);
3235 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173236
3237 // If this is a failed back/forward/reload navigation, then we need to do a
3238 // 'replace' load. This is necessary to avoid messing up session history.
3239 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3240 // as session history is concerned.
3241 //
3242 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3243 // the page id.
3244 //
3245 bool replace =
3246 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:583247 navigation_state->transition_type() ==
[email protected]e9ff79c2012-10-19 21:31:263248 PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:173249
3250 // If we failed on a browser initiated request, then make sure that our error
3251 // page load is regarded as the same browser initiated request.
3252 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:073253 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
3254 pending_navigation_params_->page_id =
3255 navigation_state->pending_page_id();
3256 pending_navigation_params_->pending_history_list_offset =
3257 navigation_state->pending_history_list_offset();
3258 pending_navigation_params_->transition =
3259 navigation_state->transition_type();
3260 pending_navigation_params_->request_time =
3261 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:173262 }
3263
3264 // Provide the user with a more helpful error page?
3265 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3266 return;
3267
3268 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083269 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173270}
3271
[email protected]310ebd6302011-10-10 19:06:283272void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:173273 WebFrame* frame, const char* data, size_t data_len,
3274 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:073275 DocumentState* document_state =
3276 DocumentState::FromDataSource(frame->dataSource());
3277 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:173278}
3279
[email protected]310ebd6302011-10-10 19:06:283280void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
3281 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:073282 DocumentState* document_state =
3283 DocumentState::FromDataSource(frame->dataSource());
3284 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173285
[email protected]007733c2011-11-17 00:34:073286 if (document_state->commit_load_time().is_null())
3287 document_state->set_commit_load_time(Time::Now());
3288
[email protected]a3a5397d2012-09-12 06:50:343289 if (document_state->must_reset_scroll_and_scale_state()) {
[email protected]c38d49c2012-10-24 21:46:573290#if defined(OS_ANDROID) // crbug.com/153907
[email protected]a3a5397d2012-09-12 06:50:343291 webview()->resetScrollAndScaleState();
[email protected]c38d49c2012-10-24 21:46:573292#endif
[email protected]a3a5397d2012-09-12 06:50:343293 document_state->set_must_reset_scroll_and_scale_state(false);
3294 }
3295
[email protected]3d9689372009-09-10 04:29:173296 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203297 // When we perform a new navigation, we need to update the last committed
3298 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173299 UpdateSessionHistory(frame);
3300
3301 // We bump our Page ID to correspond with the new session history entry.
3302 page_id_ = next_page_id_++;
3303
[email protected]e9ff79c2012-10-19 21:31:263304 // Don't update history_page_ids_ (etc) for kSwappedOutURL, since
[email protected]58436a12012-03-21 17:10:263305 // we don't want to forget the entry that was there, and since we will
[email protected]e9ff79c2012-10-19 21:31:263306 // never come back to kSwappedOutURL. Note that we have to call
[email protected]69ddf852012-02-21 23:21:313307 // UpdateSessionHistory and update page_id_ even in this case, so that
3308 // the current entry gets a state update and so that we don't send a
3309 // state update to the wrong entry when we swap back in.
[email protected]e9ff79c2012-10-19 21:31:263310 if (GetLoadingUrl(frame) != GURL(kSwappedOutURL)) {
[email protected]69ddf852012-02-21 23:21:313311 // Advance our offset in session history, applying the length limit.
3312 // There is now no forward history.
3313 history_list_offset_++;
[email protected]e9ff79c2012-10-19 21:31:263314 if (history_list_offset_ >= kMaxSessionHistoryEntries)
3315 history_list_offset_ = kMaxSessionHistoryEntries - 1;
[email protected]69ddf852012-02-21 23:21:313316 history_list_length_ = history_list_offset_ + 1;
3317 history_page_ids_.resize(history_list_length_, -1);
3318 history_page_ids_[history_list_offset_] = page_id_;
3319 }
[email protected]3d9689372009-09-10 04:29:173320 } else {
3321 // Inspect the navigation_state on this frame to see if the navigation
3322 // corresponds to a session history navigation... Note: |frame| may or
3323 // may not be the toplevel frame, but for the case of capturing session
3324 // history, the first committed frame suffices. We keep track of whether
3325 // we've seen this commit before so that only capture session history once
3326 // per navigation.
3327 //
3328 // Note that we need to check if the page ID changed. In the case of a
3329 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3330 // previous URL and the current page ID, which would be wrong.
3331 if (navigation_state->pending_page_id() != -1 &&
3332 navigation_state->pending_page_id() != page_id_ &&
3333 !navigation_state->request_committed()) {
3334 // This is a successful session history navigation!
3335 UpdateSessionHistory(frame);
3336 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003337
3338 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:033339
3340 // If the history list is valid, our list of page IDs should be correct.
3341 DCHECK(history_list_length_ <= 0 ||
3342 history_list_offset_ < 0 ||
3343 history_list_offset_ >= history_list_length_ ||
3344 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:173345 }
3346 }
3347
[email protected]28685da92011-02-07 21:49:173348 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3349 DidCommitProvisionalLoad(frame, is_new_navigation));
3350
[email protected]3d9689372009-09-10 04:29:173351 // Remember that we've already processed this request, so we don't update
3352 // the session history again. We do this regardless of whether this is
3353 // a session history navigation, because if we attempted a session history
3354 // navigation without valid HistoryItem state, WebCore will think it is a
3355 // new navigation.
3356 navigation_state->set_request_committed(true);
3357
3358 UpdateURL(frame);
3359
3360 // If this committed load was initiated by a client redirect, we're
3361 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:153362 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173363
3364 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273365 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]b2d98762012-09-03 17:04:063366
3367 if (!frame->parent()) { // Only for top frames.
3368 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
3369 if (render_thread_impl) { // Can be NULL in tests.
3370 render_thread_impl->histogram_customizer()->
3371 RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(),
3372 g_view_map.Get().size());
3373 }
3374 }
[email protected]3d9689372009-09-10 04:29:173375}
3376
[email protected]310ebd6302011-10-10 19:06:283377void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:103378 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3379 DidClearWindowObject(frame));
3380
[email protected]b6cb3a842011-06-24 18:28:413381 GURL frame_url = frame->document().url();
[email protected]e9ff79c2012-10-19 21:31:263382 if ((enabled_bindings_ & BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:253383 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
3384 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:273385 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:173386 }
[email protected]766a7082012-02-03 23:39:153387
[email protected]e9ff79c2012-10-19 21:31:263388 if (enabled_bindings_ & BINDINGS_POLICY_DOM_AUTOMATION) {
[email protected]766a7082012-02-03 23:39:153389 if (!dom_automation_controller_.get())
3390 dom_automation_controller_.reset(new DomAutomationController());
3391 dom_automation_controller_->set_message_sender(
[email protected]e9ff79c2012-10-19 21:31:263392 static_cast<RenderView*>(this));
[email protected]766a7082012-02-03 23:39:153393 dom_automation_controller_->set_routing_id(routing_id());
3394 dom_automation_controller_->BindToJavascript(frame,
3395 "domAutomationController");
3396 }
[email protected]498bc512012-09-21 21:50:083397
[email protected]e9ff79c2012-10-19 21:31:263398 InjectDoNotTrackBindings(frame);
[email protected]3d9689372009-09-10 04:29:173399}
3400
[email protected]310ebd6302011-10-10 19:06:283401void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173402 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:413403 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:253404 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]87717d0e2012-04-26 02:58:433405 if (frame == webview()->mainFrame())
3406 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:173407 }
[email protected]e48869a2011-04-01 19:56:033408
3409 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3410 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:173411}
3412
[email protected]310ebd6302011-10-10 19:06:283413void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
3414 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:463415 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:173416
3417 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273418 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173419}
3420
[email protected]310ebd6302011-10-10 19:06:283421void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:133422 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3423 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:583424}
3425
[email protected]310ebd6302011-10-10 19:06:283426void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173427 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073428 DocumentState* document_state = DocumentState::FromDataSource(ds);
3429 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:173430
[email protected]622474d2010-11-04 09:21:083431 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173432
[email protected]28685da92011-02-07 21:49:173433 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3434 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173435
3436 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273437 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173438}
3439
[email protected]310ebd6302011-10-10 19:06:283440void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083441 if (webview()->mainFrame() == frame) {
3442 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3443 page_id_));
3444 }
[email protected]3d9689372009-09-10 04:29:173445}
3446
[email protected]310ebd6302011-10-10 19:06:283447void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:313448 WebDataSource* ds = frame->dataSource();
3449 DCHECK(ds);
3450
3451
[email protected]28685da92011-02-07 21:49:173452 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:313453
3454 const WebURLRequest& failed_request = ds->request();
3455 string16 error_description;
[email protected]e9ff79c2012-10-19 21:31:263456 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]1a55c5be2011-11-29 11:36:313457 failed_request,
3458 error,
3459 NULL,
3460 &error_description);
3461 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
3462 frame->identifier(),
3463 failed_request.url(),
3464 !frame->parent(),
3465 error.reason,
3466 error_description));
[email protected]3d9689372009-09-10 04:29:173467}
3468
[email protected]310ebd6302011-10-10 19:06:283469void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173470 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073471 DocumentState* document_state = DocumentState::FromDataSource(ds);
3472 if (document_state->finish_load_time().is_null())
3473 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:413474
[email protected]676126f72011-01-15 00:03:513475 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173476
[email protected]1a55c5be2011-11-29 11:36:313477 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
3478 frame->identifier(),
3479 ds->request().url(),
3480 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:173481}
3482
[email protected]310ebd6302011-10-10 19:06:283483void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173484 WebFrame* frame, bool is_new_navigation) {
3485 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:073486 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:173487 // update the ExtraData on the datasource so that others who read the
3488 // ExtraData will get the new NavigationState. Similarly, if we did not
3489 // initiate this navigation, then we need to take care to reset any pre-
3490 // existing navigation state to a content-initiated navigation state.
3491 // DidCreateDataSource conveniently takes care of this for us.
3492 didCreateDataSource(frame, frame->dataSource());
3493
[email protected]007733c2011-11-17 00:34:073494 DocumentState* document_state =
3495 DocumentState::FromDataSource(frame->dataSource());
3496 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:093497 new_state->set_was_within_same_page(true);
3498
[email protected]3d9689372009-09-10 04:29:173499 didCommitProvisionalLoad(frame, is_new_navigation);
3500
[email protected]750fcf872011-08-03 23:10:473501 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
3502 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:173503}
3504
[email protected]310ebd6302011-10-10 19:06:283505void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313506 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593507}
3508
[email protected]310ebd6302011-10-10 19:06:283509void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:173510 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3511 // Ignore
3512}
3513
[email protected]310ebd6302011-10-10 19:06:283514void RenderViewImpl::willSendRequest(WebFrame* frame,
3515 unsigned identifier,
3516 WebURLRequest& request,
3517 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303518 WebFrame* top_frame = frame->top();
3519 if (!top_frame)
3520 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513521 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3522 WebDataSource* top_data_source = top_frame->dataSource();
3523 WebDataSource* data_source =
3524 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:223525
[email protected]e9ff79c2012-10-19 21:31:263526 PageTransition transition_type = PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:073527 DocumentState* document_state = DocumentState::FromDataSource(data_source);
[email protected]def55e022012-07-26 01:15:293528 DCHECK(document_state);
[email protected]007733c2011-11-17 00:34:073529 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e1ed5a12012-08-08 19:57:443530 transition_type = navigation_state->transition_type();
3531
3532 GURL request_url(request.url());
3533 GURL new_url;
[email protected]e9ff79c2012-10-19 21:31:263534 if (GetContentClient()->renderer()->WillSendRequest(
[email protected]e1ed5a12012-08-08 19:57:443535 frame, transition_type, request_url, &new_url)) {
3536 request.setURL(WebURL(new_url));
3537 }
3538
[email protected]def55e022012-07-26 01:15:293539 if (document_state->is_cache_policy_override_set())
3540 request.setCachePolicy(document_state->cache_policy_override());
[email protected]8a3125a712010-08-09 18:58:513541
[email protected]ca662822012-05-11 17:53:593542 WebKit::WebReferrerPolicy referrer_policy;
3543 if (document_state && document_state->is_referrer_policy_set()) {
3544 referrer_policy = document_state->referrer_policy();
3545 document_state->clear_referrer_policy();
3546 } else {
3547 referrer_policy = frame->document().referrerPolicy();
3548 }
3549
[email protected]e372f3d2012-07-17 19:16:443550 // The request's extra data may indicate that we should set a custom user
3551 // agent. This needs to be done here, after WebKit is through with setting the
3552 // user agent on its own.
3553 WebString custom_user_agent;
3554 if (request.extraData()) {
3555 webkit_glue::WebURLRequestExtraDataImpl* old_extra_data =
3556 static_cast<webkit_glue::WebURLRequestExtraDataImpl*>(
3557 request.extraData());
3558 custom_user_agent = old_extra_data->custom_user_agent();
3559
3560 if (!custom_user_agent.isNull()) {
3561 if (custom_user_agent.isEmpty())
3562 request.clearHTTPHeaderField("User-Agent");
3563 else
3564 request.setHTTPHeaderField("User-Agent", custom_user_agent);
3565 }
3566 }
3567
[email protected]91043a8232011-11-04 16:41:193568 request.setExtraData(
[email protected]ca662822012-05-11 17:53:593569 new RequestExtraData(referrer_policy,
[email protected]e372f3d2012-07-17 19:16:443570 custom_user_agent,
[email protected]537fbe02011-11-24 00:58:063571 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:193572 frame->identifier(),
3573 frame->parent() == top_frame,
3574 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]80744782012-05-04 01:47:003575 navigation_state->allow_download(),
[email protected]4ad5d77d2011-12-03 02:00:483576 transition_type,
3577 navigation_state->transferred_request_child_id(),
3578 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:573579
[email protected]007733c2011-11-17 00:34:073580 DocumentState* top_document_state =
3581 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:573582 // TODO(gavinp): separate out prefetching and prerender field trials
3583 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:073584 if (top_document_state &&
[email protected]925dec1c2012-05-18 05:09:003585 request.targetType() == WebURLRequest::TargetIsPrefetch)
[email protected]007733c2011-11-17 00:34:073586 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513587
[email protected]3d9689372009-09-10 04:29:173588 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133589 request.setHasUserGesture(frame->isProcessingUserGesture());
3590
[email protected]0a8db0d2011-04-13 15:15:403591 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:133592 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:173593}
3594
[email protected]310ebd6302011-10-10 19:06:283595void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173596 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493597
[email protected]3d9689372009-09-10 04:29:173598 // Only do this for responses that correspond to a provisional data source
3599 // of the top-most frame. If we have a provisional data source, then we
3600 // can't have any sub-resources yet, so we know that this response must
3601 // correspond to a frame load.
3602 if (!frame->provisionalDataSource() || frame->parent())
3603 return;
3604
3605 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083606 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173607 if (frame->isViewSourceModeEnabled())
3608 return;
3609
[email protected]007733c2011-11-17 00:34:073610 DocumentState* document_state =
3611 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083612 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533613
[email protected]972ebdff2010-06-10 22:59:073614 // Record page load flags.
[email protected]007733c2011-11-17 00:34:073615 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3616 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]b9fd01ba2012-02-28 01:50:403617 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
3618 if (extra_data) {
3619 document_state->set_npn_negotiated_protocol(
3620 extra_data->npn_negotiated_protocol());
3621 }
[email protected]007733c2011-11-17 00:34:073622 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:573623 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:073624 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3625 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093626 // Whether or not the http status code actually corresponds to an error is
3627 // only checked when the page is done loading, if |use_error_page| is
3628 // still true.
[email protected]007733c2011-11-17 00:34:073629 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173630}
3631
[email protected]310ebd6302011-10-10 19:06:283632void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173633 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:073634 DocumentState* document_state =
3635 DocumentState::FromDataSource(frame->dataSource());
3636 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173637 return;
3638
[email protected]7bfc153f2011-09-23 22:00:203639 // Do not show error page when DevTools is attached.
3640 if (devtools_agent_->IsAttached())
3641 return;
3642
[email protected]06333afe2011-02-24 14:55:093643 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:073644 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:083645 if (http_status_code == 404) {
3646 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413647 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173648
[email protected]b6cb3a842011-06-24 18:28:413649 const GURL& error_page_url =
3650 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093651 if (error_page_url.is_valid()) {
3652 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473653 original_error.domain = "http";
3654 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413655 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173656
[email protected]007733c2011-11-17 00:34:073657 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093658 new AltErrorPageResourceFetcher(
3659 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:083660 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3661 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093662 return;
3663 }
3664 }
[email protected]3d9689372009-09-10 04:29:173665
[email protected]e6a2ce52011-10-08 01:40:133666 std::string error_domain;
[email protected]e9ff79c2012-10-19 21:31:263667 if (GetContentClient()->renderer()->HasErrorPage(
[email protected]e6a2ce52011-10-08 01:40:133668 http_status_code, &error_domain)) {
3669 WebURLError error;
3670 error.unreachableURL = frame->document().url();
3671 error.domain = WebString::fromUTF8(error_domain);
3672 error.reason = http_status_code;
3673
3674 LoadNavigationErrorPage(
3675 frame, frame->dataSource()->request(), error, std::string(), true);
3676 }
[email protected]3d9689372009-09-10 04:29:173677}
3678
[email protected]310ebd6302011-10-10 19:06:283679void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173680 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3681 // Ignore
3682}
3683
[email protected]310ebd6302011-10-10 19:06:283684void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173685 WebFrame* frame, const WebURLRequest& request,
3686 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003687 // The recipients of this message have no use for data: URLs: they don't
3688 // affect the page's insecure content list and are not in the disk cache. To
3689 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3690 // filter them out here.
3691 GURL url(request.url());
3692 if (url.SchemeIs("data"))
3693 return;
3694
[email protected]3d9689372009-09-10 04:29:173695 // Let the browser know we loaded a resource from the memory cache. This
3696 // message is needed to display the correct SSL indicators.
3697 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3698 routing_id_,
[email protected]84703292011-10-28 20:44:003699 url,
[email protected]70435962011-08-02 20:13:283700 response.securityInfo(),
3701 request.httpMethod().utf8(),
[email protected]6d6cfb3a2012-05-23 22:53:183702 response.mimeType().utf8(),
[email protected]70435962011-08-02 20:13:283703 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173704}
3705
[email protected]310ebd6302011-10-10 19:06:283706void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293707 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3708}
3709
[email protected]310ebd6302011-10-10 19:06:283710void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023711 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293712 Send(new ViewHostMsg_DidRunInsecureContent(
3713 routing_id_,
[email protected]92771112011-01-20 00:13:023714 origin.toString().utf8(),
3715 target));
[email protected]e3d60e5d2009-09-25 21:08:293716}
3717
[email protected]310ebd6302011-10-10 19:06:283718void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173719 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3720}
3721
[email protected]310ebd6302011-10-10 19:06:283722void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3723 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583724 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283725 int world_id) {
[email protected]e9ff79c2012-10-19 21:31:263726 GetContentClient()->renderer()->DidCreateScriptContext(
[email protected]a00fe692012-02-27 05:52:583727 frame, context, extension_group, world_id);
[email protected]7a137c9d2012-10-16 20:41:203728
3729 intents_host_->DidCreateScriptContext(
3730 frame, context, extension_group, world_id);
[email protected]a00fe692012-02-27 05:52:583731}
3732
[email protected]310ebd6302011-10-10 19:06:283733void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3734 v8::Handle<v8::Context> context,
3735 int world_id) {
[email protected]e9ff79c2012-10-19 21:31:263736 GetContentClient()->renderer()->WillReleaseScriptContext(
[email protected]5bc10932011-09-21 21:03:303737 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283738}
3739
[email protected]310ebd6302011-10-10 19:06:283740void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073741 // We don't always want to send the change messages over IPC, only if we've
3742 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3743 // message.
3744 if (!send_preferred_size_changes_ || !webview())
3745 return;
3746
[email protected]705243f2010-05-05 19:58:073747 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3748 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533749
3750 // In the presence of zoom, these sizes are still reported as if unzoomed,
3751 // so we need to adjust.
3752 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3753 size.set_width(static_cast<int>(size.width() * zoom_factor));
3754 size.set_height(static_cast<int>(size.height() * zoom_factor));
3755
[email protected]705243f2010-05-05 19:58:073756 if (size == preferred_size_)
3757 return;
[email protected]c27324b2009-11-19 22:44:293758
[email protected]705243f2010-05-05 19:58:073759 preferred_size_ = size;
3760 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3761 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173762}
3763
[email protected]1842fe22012-08-13 23:24:353764WebGraphicsContext3D* RenderViewImpl::CreateGraphicsContext3D(
3765 const WebGraphicsContext3D::Attributes& attributes) {
3766 if (!webview())
3767 return NULL;
3768
[email protected]1842fe22012-08-13 23:24:353769 // The WebGraphicsContext3DInProcessImpl code path is used for
3770 // layout tests (though not through this code) as well as for
3771 // debugging and bringing up new ports.
3772 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
3773 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
3774 attributes, true);
3775 } else {
3776 GURL url;
3777 if (webview()->mainFrame())
3778 url = GURL(webview()->mainFrame()->document().url());
3779 else
[email protected]f89e173a2012-08-24 01:12:263780 url = GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]1842fe22012-08-13 23:24:353781
3782 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
3783 new WebGraphicsContext3DCommandBufferImpl(
3784 surface_id(),
3785 url,
3786 RenderThreadImpl::current(),
3787 AsWeakPtr()));
3788
3789 if (!context->Initialize(
3790 attributes,
3791 false /* bind generates resources */,
[email protected]e9ff79c2012-10-19 21:31:263792 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
[email protected]1842fe22012-08-13 23:24:353793 return NULL;
3794 return context.release();
3795 }
3796}
3797
[email protected]0720b532012-08-28 19:23:373798// The browser process needs to know the shape of the tree, as well as the names
3799// and ids of all frames. This allows it to properly route JavaScript messages
3800// across processes and frames. The serialization format is described in the
3801// comments of the ViewMsg_FrameTreeUpdated message.
3802// This function sends those updates to the browser and updates the RVH
3803// corresponding to this object. It must be called on any events that modify
3804// the tree structure or the names of any frames.
3805void RenderViewImpl::SendUpdatedFrameTree(
3806 WebKit::WebFrame* exclude_frame_subtree) {
[email protected]e12dbe6f2012-10-04 22:11:193807 // TODO(nasko): Frame tree updates are causing issues with postMessage, as
3808 // described in http://crbug.com/153701. Disable them until a proper fix is
3809 // in place.
[email protected]0720b532012-08-28 19:23:373810}
3811
3812void RenderViewImpl::CreateFrameTree(WebKit::WebFrame* frame,
3813 DictionaryValue* frame_tree) {
[email protected]e12dbe6f2012-10-04 22:11:193814 // TODO(nasko): Remove once http://crbug.com/153701 is fixed.
3815 DCHECK(false);
[email protected]0720b532012-08-28 19:23:373816 NavigateToSwappedOutURL(frame);
3817
3818 string16 name;
[email protected]e9ff79c2012-10-19 21:31:263819 if (frame_tree->GetString(kFrameTreeNodeNameKey, &name) && !name.empty())
[email protected]0720b532012-08-28 19:23:373820 frame->setName(name);
[email protected]0720b532012-08-28 19:23:373821
3822 int remote_id;
[email protected]e9ff79c2012-10-19 21:31:263823 if (frame_tree->GetInteger(kFrameTreeNodeIdKey, &remote_id))
[email protected]0720b532012-08-28 19:23:373824 active_frame_id_map_.insert(std::pair<int, int>(frame->identifier(),
3825 remote_id));
3826
3827 ListValue* children;
[email protected]e9ff79c2012-10-19 21:31:263828 if (!frame_tree->GetList(kFrameTreeNodeSubtreeKey, &children))
[email protected]0720b532012-08-28 19:23:373829 return;
3830
[email protected]5fa9b36b2012-09-21 18:14:273831 // Create an invisible iframe tree in the swapped out page.
[email protected]0720b532012-08-28 19:23:373832 base::DictionaryValue* child;
3833 for (size_t i = 0; i < children->GetSize(); ++i) {
3834 if (!children->GetDictionary(i, &child))
3835 continue;
3836 WebElement element = frame->document().createElement("iframe");
[email protected]5fa9b36b2012-09-21 18:14:273837 element.setAttribute("width", "0");
3838 element.setAttribute("height", "0");
3839 element.setAttribute("frameBorder", "0");
[email protected]0720b532012-08-28 19:23:373840 if (frame->document().body().appendChild(element)) {
3841 WebFrame* subframe = WebFrame::fromFrameOwnerElement(element);
3842 if (subframe)
3843 CreateFrameTree(subframe, child);
3844 } else {
3845 LOG(ERROR) << "Failed to append created iframe element.";
3846 }
3847 }
3848}
3849
[email protected]d1a59e42012-10-03 18:05:353850WebKit::WebFrame* RenderViewImpl::GetFrameByRemoteID(int remote_frame_id) {
3851 std::map<int, int>::const_iterator it = active_frame_id_map_.begin();
3852 for (; it != active_frame_id_map_.end(); ++it) {
3853 if (it->second == remote_frame_id)
3854 return FindFrameByID(webview()->mainFrame(), it->first);
3855 }
3856 return NULL;
[email protected]0720b532012-08-28 19:23:373857}
3858
[email protected]273558fb2012-01-12 15:03:513859void RenderViewImpl::EnsureMediaStreamImpl() {
[email protected]7082fb942012-05-16 23:44:593860 if (!RenderThreadImpl::current()) // Will be NULL during unit tests.
[email protected]08381562012-05-15 20:55:403861 return;
3862
[email protected]4fb0f202012-05-30 22:44:533863#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:513864 if (!media_stream_dispatcher_)
3865 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3866
[email protected]1bc65a42012-04-23 09:31:253867 if (!media_stream_impl_) {
[email protected]273558fb2012-01-12 15:03:513868 media_stream_impl_ = new MediaStreamImpl(
[email protected]1bc65a42012-04-23 09:31:253869 this,
[email protected]273558fb2012-01-12 15:03:513870 media_stream_dispatcher_,
[email protected]273558fb2012-01-12 15:03:513871 RenderThreadImpl::current()->video_capture_impl_manager(),
[email protected]6ee10bd2012-09-13 09:01:533872 RenderThreadImpl::current()->GetMediaStreamDependencyFactory());
[email protected]273558fb2012-01-12 15:03:513873 }
[email protected]5b87e782012-02-09 18:19:323874#endif
[email protected]273558fb2012-01-12 15:03:513875}
3876
[email protected]310ebd6302011-10-10 19:06:283877void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3878 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313879 if (webview()->mainFrame() != frame)
3880 return;
3881 WebView* frameView = frame->view();
3882 if (!frameView)
3883 return;
3884
3885 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3886 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3887
3888 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3889 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3890 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3891 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3892
3893 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3894 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3895 }
3896}
3897
[email protected]310ebd6302011-10-10 19:06:283898void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313899 WebSize offset = frame->scrollOffset();
3900 WebSize minimum_offset = frame->minimumScrollOffset();
3901 WebSize maximum_offset = frame->maximumScrollOffset();
3902
3903 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3904 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3905
3906 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3907 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3908 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3909 routing_id_, is_pinned_to_left, is_pinned_to_right));
3910
3911 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3912 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3913 }
3914}
3915
[email protected]310ebd6302011-10-10 19:06:283916void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493917 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313918
3919 if (webview()->mainFrame() == frame)
3920 UpdateScrollState(frame);
[email protected]2b942c332012-04-25 16:26:263921
3922 FOR_EACH_OBSERVER(
3923 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]dd6afca2011-08-13 03:44:313924}
3925
[email protected]4d0f8182012-10-19 23:14:473926#if defined(OS_ANDROID)
3927void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebFrame* frame) {
3928 if (frame != webview()->mainFrame())
3929 return;
3930
3931 // Update body background color if necessary.
3932 SkColor bg_color = webwidget_->backgroundColor();
3933
3934 // If not initialized, default to white. Note that 0 is different from black
3935 // as black still has alpha 0xFF.
3936 if (!bg_color)
3937 bg_color = SK_ColorWHITE;
3938
3939 if (bg_color != body_background_color_) {
3940 body_background_color_ = bg_color;
3941 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id_, bg_color));
3942 }
3943}
3944#endif
3945
[email protected]55750b32012-09-21 14:05:033946void RenderViewImpl::SendFindReply(int request_id,
3947 int match_count,
3948 int ordinal,
3949 const WebRect& selection_rect,
3950 bool final_status_update) {
3951#if defined(OS_ANDROID)
3952 if (synchronous_find_reply_message_.get()) {
3953 if (final_status_update) {
3954 ViewMsg_SynchronousFind::WriteReplyParams(
3955 synchronous_find_reply_message_.get(),
3956 match_count,
3957 match_count ? synchronous_find_active_match_ordinal_ : 0);
3958 Send(synchronous_find_reply_message_.release());
3959 }
3960 return;
3961 }
3962#endif
3963
3964 Send(new ViewHostMsg_Find_Reply(routing_id_,
3965 request_id,
3966 match_count,
3967 selection_rect,
3968 ordinal,
3969 final_status_update));
3970}
3971
3972void RenderViewImpl::reportFindInPageMatchCount(int request_id,
3973 int count,
[email protected]310ebd6302011-10-10 19:06:283974 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113975 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3976 if (!count)
3977 active_match_ordinal = 0;
3978
[email protected]55750b32012-09-21 14:05:033979 // Send the search result over to the browser process.
3980 SendFindReply(request_id,
3981 count,
3982 active_match_ordinal,
3983 gfx::Rect(),
3984 final_update);
[email protected]8922e1f2009-10-03 05:01:263985}
3986
[email protected]310ebd6302011-10-10 19:06:283987void RenderViewImpl::reportFindInPageSelection(int request_id,
3988 int active_match_ordinal,
3989 const WebRect& selection_rect) {
[email protected]55750b32012-09-21 14:05:033990#if defined(OS_ANDROID)
3991 // If this was a SynchronousFind request, we need to remember the ordinal
3992 // value here for replying when reportFindInPageMatchCount is called.
3993 if (synchronous_find_reply_message_.get()) {
3994 synchronous_find_active_match_ordinal_ = active_match_ordinal;
3995 return;
3996 }
3997#endif
3998
3999 SendFindReply(request_id,
4000 -1,
4001 active_match_ordinal,
4002 selection_rect,
4003 false);
[email protected]8922e1f2009-10-03 05:01:264004}
4005
[email protected]310ebd6302011-10-10 19:06:284006void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:224007 WebFrame* frame,
4008 WebFileSystem::Type type,
4009 long long size,
[email protected]d275d7a2010-11-03 01:34:494010 bool create,
[email protected]2b06a992010-08-21 05:48:224011 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:084012 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:224013
[email protected]b6cb3a842011-06-24 18:28:414014 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564015 if (origin.isUnique()) {
4016 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:084017 callbacks->didFail(WebKit::WebFileErrorAbort);
4018 return;
4019 }
[email protected]2b06a992010-08-21 05:48:224020
[email protected]c5a272d2010-09-27 18:37:084021 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
4022 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:494023 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:224024}
4025
[email protected]d5e08552012-08-02 21:43:404026void RenderViewImpl::deleteFileSystem(
4027 WebFrame* frame,
4028 WebFileSystem::Type type ,
4029 WebFileSystemCallbacks* callbacks) {
4030 DCHECK(callbacks);
4031
4032 WebSecurityOrigin origin = frame->document().securityOrigin();
4033 if (origin.isUnique()) {
4034 // Unique origins cannot store persistent state.
4035 callbacks->didSucceed();
4036 return;
4037 }
4038
4039 ChildThread::current()->file_system_dispatcher()->DeleteFileSystem(
4040 GURL(origin.toString()),
4041 static_cast<fileapi::FileSystemType>(type),
4042 new WebFileSystemCallbackDispatcher(callbacks));
4043}
4044
[email protected]310ebd6302011-10-10 19:06:284045void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:404046 WebFrame* frame,
4047 WebStorageQuotaType type,
4048 WebStorageQuotaCallbacks* callbacks) {
4049 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:414050 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564051 if (origin.isUnique()) {
4052 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:404053 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
4054 return;
4055 }
4056 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:534057 GURL(origin.toString()),
4058 static_cast<quota::StorageType>(type),
4059 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:404060}
4061
[email protected]310ebd6302011-10-10 19:06:284062void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:404063 WebFrame* frame,
4064 WebStorageQuotaType type,
4065 unsigned long long requested_size,
4066 WebStorageQuotaCallbacks* callbacks) {
4067 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:414068 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564069 if (origin.isUnique()) {
4070 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:404071 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
4072 return;
4073 }
4074 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:534075 routing_id(), GURL(origin.toString()),
4076 static_cast<quota::StorageType>(type), requested_size,
4077 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:404078}
4079
[email protected]8b5af492011-11-28 21:50:584080void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:154081 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]3a3b75a2012-06-01 08:38:364082 webkit_glue::WebIntentServiceData data(service);
4083 if (data.title.empty())
4084 data.title = webview()->mainFrame()->document().title();
4085 bool user_gesture = frame->isProcessingUserGesture();
[email protected]8b5af492011-11-28 21:50:584086 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
[email protected]3a3b75a2012-06-01 08:38:364087 data,
4088 user_gesture));
[email protected]8b5af492011-11-28 21:50:584089}
4090
[email protected]ffc8bed2012-01-21 01:23:154091void RenderViewImpl::dispatchIntent(
4092 WebFrame* frame, const WebIntentRequest& intentRequest) {
4093 webkit_glue::WebIntentData intent_data(intentRequest.intent());
[email protected]4e1eb3392012-05-18 00:08:054094
4095 // See WebMessagePortChannelImpl::postMessage() and ::OnMessagedQueued()
4096 WebKit::WebMessagePortChannelArray* channels =
4097 intentRequest.intent().messagePortChannelsRelease();
4098 if (channels) {
4099 for (size_t i = 0; i < channels->size(); ++i) {
4100 WebMessagePortChannelImpl* webchannel =
4101 static_cast<WebMessagePortChannelImpl*>((*channels)[i]);
4102 intent_data.message_port_ids.push_back(webchannel->message_port_id());
4103 DCHECK(intent_data.message_port_ids[i] != MSG_ROUTING_NONE);
4104 }
4105 delete channels;
4106 }
4107
[email protected]ffc8bed2012-01-21 01:23:154108 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:584109 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:154110 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:584111}
4112
[email protected]f546640b2012-05-15 00:03:494113bool RenderViewImpl::willCheckAndDispatchMessageEvent(
[email protected]0720b532012-08-28 19:23:374114 WebKit::WebFrame* sourceFrame,
4115 WebKit::WebFrame* targetFrame,
[email protected]f546640b2012-05-15 00:03:494116 WebKit::WebSecurityOrigin target_origin,
4117 WebKit::WebDOMMessageEvent event) {
4118 if (!is_swapped_out_)
4119 return false;
4120
4121 ViewMsg_PostMessage_Params params;
4122 params.data = event.data().toString();
4123 params.source_origin = event.origin();
4124 if (!target_origin.isNull())
4125 params.target_origin = target_origin.toString();
4126
4127 // Include the routing ID for the source frame, which the browser process
4128 // will translate into the routing ID for the equivalent frame in the target
4129 // process.
[email protected]f546640b2012-05-15 00:03:494130 params.source_routing_id = MSG_ROUTING_NONE;
[email protected]0720b532012-08-28 19:23:374131 RenderViewImpl* source_view = FromWebView(sourceFrame->view());
[email protected]f546640b2012-05-15 00:03:494132 if (source_view)
4133 params.source_routing_id = source_view->routing_id();
[email protected]0720b532012-08-28 19:23:374134 params.source_frame_id = sourceFrame->identifier();
4135
4136 // Include the process, route, and frame IDs of the target frame. This allows
4137 // the browser to detect races between this message being sent and the target
4138 // frame no longer being valid.
4139 params.target_process_id = target_process_id_;
4140 params.target_routing_id = target_routing_id_;
4141
4142 std::map<int,int>::iterator it = active_frame_id_map_.find(
4143 targetFrame->identifier());
4144 if (it != active_frame_id_map_.end()) {
4145 params.target_frame_id = it->second;
4146 } else {
4147 params.target_frame_id = 0;
4148 }
[email protected]f546640b2012-05-15 00:03:494149
4150 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params));
4151 return true;
4152}
4153
[email protected]5fa3a062012-03-21 15:39:344154void RenderViewImpl::willOpenSocketStream(
4155 WebSocketStreamHandle* handle) {
4156 SocketStreamHandleData::AddToHandle(handle, routing_id_);
4157}
4158
[email protected]ccee4862012-10-03 18:34:264159void RenderViewImpl::willStartUsingPeerConnectionHandler(
4160 WebKit::WebFrame* frame, WebKit::WebRTCPeerConnectionHandler* handler) {
4161#if defined(ENABLE_WEBRTC)
4162 static_cast<RTCPeerConnectionHandler*>(handler)->associateWithFrame(frame);
4163#endif
4164}
4165
[email protected]bf70edce2012-06-20 22:32:224166WebKit::WebString RenderViewImpl::userAgentOverride(
4167 WebKit::WebFrame* frame,
4168 const WebKit::WebURL& url) {
4169 if (!webview() || !webview()->mainFrame() ||
4170 renderer_preferences_.user_agent_override.empty()) {
4171 return WebKit::WebString();
4172 }
4173
4174 // If we're in the middle of committing a load, the data source we need
4175 // will still be provisional.
4176 WebFrame* main_frame = webview()->mainFrame();
4177 WebDataSource* data_source = NULL;
4178 if (main_frame->provisionalDataSource())
4179 data_source = main_frame->provisionalDataSource();
4180 else
4181 data_source = main_frame->dataSource();
4182
4183 DocumentState* document_state =
4184 data_source ? DocumentState::FromDataSource(data_source) : NULL;
4185 if (document_state && document_state->is_overriding_user_agent())
4186 return WebString::fromUTF8(renderer_preferences_.user_agent_override);
4187 else
4188 return WebKit::WebString();
4189}
4190
[email protected]18d5be92011-07-25 18:00:194191// WebKit::WebPageSerializerClient implementation ------------------------------
4192
[email protected]310ebd6302011-10-10 19:06:284193void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:194194 const WebURL& frame_url,
4195 const WebCString& data,
4196 WebPageSerializerClient::PageSerializationStatus status) {
4197 Send(new ViewHostMsg_SendSerializedHtmlData(
4198 routing_id(),
4199 frame_url,
4200 data.data(),
4201 static_cast<int32>(status)));
4202}
4203
[email protected]e9ff79c2012-10-19 21:31:264204// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:314205
[email protected]310ebd6302011-10-10 19:06:284206bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:314207 return RenderWidget::Send(message);
4208}
4209
[email protected]82114f52012-03-20 22:53:414210int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:314211 return routing_id_;
4212}
4213
[email protected]82114f52012-03-20 22:53:414214int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:314215 return page_id_;
4216}
4217
[email protected]82114f52012-03-20 22:53:414218gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:314219 return size();
4220}
4221
[email protected]82114f52012-03-20 22:53:414222WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:314223 return webkit_preferences_;
4224}
4225
[email protected]82114f52012-03-20 22:53:414226WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:314227 return webview();
4228}
4229
[email protected]82114f52012-03-20 22:53:414230WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:314231 if (!webview())
4232 return WebNode();
4233 WebFrame* focused_frame = webview()->focusedFrame();
4234 if (focused_frame) {
4235 WebDocument doc = focused_frame->document();
4236 if (!doc.isNull())
4237 return doc.focusedNode();
4238 }
4239
4240 return WebNode();
4241}
4242
[email protected]82114f52012-03-20 22:53:414243WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:314244 return context_menu_node_;
4245}
4246
[email protected]2a84f9d2012-06-05 21:50:434247bool RenderViewImpl::IsEditableNode(const WebNode& node) const {
4248 if (node.isNull())
4249 return false;
4250
4251 if (node.isContentEditable())
4252 return true;
4253
4254 if (node.isElementNode()) {
4255 const WebElement& element = node.toConst<WebElement>();
4256 if (element.isTextFormControlElement())
4257 return true;
4258
4259 // Also return true if it has an ARIA role of 'textbox'.
4260 for (unsigned i = 0; i < element.attributeCount(); ++i) {
4261 if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) {
4262 if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox"))
4263 return true;
4264 break;
4265 }
[email protected]a2ef54c2011-10-10 16:20:314266 }
4267 }
[email protected]2a84f9d2012-06-05 21:50:434268
4269 return false;
[email protected]a2ef54c2011-10-10 16:20:314270}
4271
[email protected]310ebd6302011-10-10 19:06:284272WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:314273 WebKit::WebFrame* frame,
4274 const webkit::WebPluginInfo& info,
[email protected]82114f52012-03-20 22:53:414275 const WebKit::WebPluginParams& params) {
[email protected]a2ef54c2011-10-10 16:20:314276 bool pepper_plugin_was_registered = false;
4277 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
4278 pepper_delegate_.CreatePepperPluginModule(info,
4279 &pepper_plugin_was_registered));
4280 if (pepper_plugin_was_registered) {
4281 if (!pepper_module)
4282 return NULL;
4283 return new webkit::ppapi::WebPluginImpl(
4284 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
4285 }
4286
[email protected]3e076a82012-09-11 19:12:364287#if defined(USE_AURA) && !defined(OS_WIN)
[email protected]34b27e442012-01-20 20:07:414288 return NULL;
4289#else
[email protected]a2ef54c2011-10-10 16:20:314290 return new webkit::npapi::WebPluginImpl(
4291 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:414292#endif
[email protected]a2ef54c2011-10-10 16:20:314293}
4294
[email protected]310ebd6302011-10-10 19:06:284295void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
4296 const string16& jscript,
4297 int id,
4298 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:314299 v8::Handle<v8::Value> result;
4300 WebFrame* web_frame = GetChildFrame(frame_xpath);
4301 if (web_frame)
4302 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
4303 if (notify_result) {
4304 ListValue list;
4305 if (!result.IsEmpty() && web_frame) {
4306 v8::HandleScope handle_scope;
4307 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4308 v8::Context::Scope context_scope(context);
4309 V8ValueConverterImpl converter;
[email protected]3de391e82012-05-16 17:50:514310 converter.SetDateAllowed(true);
[email protected]e0658bc2012-09-17 04:05:244311 converter.SetRegExpAllowed(true);
4312 base::Value* result_value = converter.FromV8Value(result, context);
4313 list.Set(0, result_value ? result_value :
4314 base::Value::CreateNullValue());
[email protected]a2ef54c2011-10-10 16:20:314315 } else {
4316 list.Set(0, Value::CreateNullValue());
4317 }
4318 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
4319 }
4320}
4321
[email protected]310ebd6302011-10-10 19:06:284322bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:314323 return (!send_preferred_size_changes_ ||
4324 (disable_scrollbars_size_limit_.width() <= width ||
4325 disable_scrollbars_size_limit_.height() <= height));
4326}
4327
[email protected]82114f52012-03-20 22:53:414328int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:314329 return enabled_bindings_;
4330}
4331
[email protected]82114f52012-03-20 22:53:414332bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:314333 return send_content_state_immediately_;
4334}
4335
[email protected]82114f52012-03-20 22:53:414336float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:314337 return filtered_time_per_frame();
4338}
4339
[email protected]e9ff79c2012-10-19 21:31:264340int RenderViewImpl::ShowContextMenu(ContextMenuClient* client,
4341 const ContextMenuParams& params) {
[email protected]860ee642012-10-13 03:46:254342 DCHECK(client); // A null client means "internal" when we issue callbacks.
[email protected]e9ff79c2012-10-19 21:31:264343 ContextMenuParams our_params(params);
[email protected]860ee642012-10-13 03:46:254344 our_params.custom_context.request_id = pending_context_menus_.Add(client);
4345 Send(new ViewHostMsg_ContextMenu(routing_id_, our_params));
4346 return our_params.custom_context.request_id;
[email protected]a2ef54c2011-10-10 16:20:314347}
4348
[email protected]e0fd0eb2012-10-17 21:11:464349void RenderViewImpl::CancelContextMenu(int request_id) {
4350 DCHECK(pending_context_menus_.Lookup(request_id));
4351 pending_context_menus_.Remove(request_id);
4352}
4353
[email protected]82114f52012-03-20 22:53:414354WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:314355 return visibilityState();
4356}
4357
[email protected]310ebd6302011-10-10 19:06:284358void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
4359 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:314360 return runModalAlertDialog(frame, message);
4361}
4362
[email protected]310ebd6302011-10-10 19:06:284363void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:314364 WebKit::WebFrame* frame,
4365 const WebKit::WebURLRequest& request,
4366 WebKit::WebNavigationPolicy policy) {
4367 loadURLExternally(frame, request, policy);
4368}
4369
4370// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:514371
[email protected]310ebd6302011-10-10 19:06:284372webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:534373 const FilePath& file_path,
4374 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:204375 if (!PluginChannelHost::IsListening()) {
4376 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:594377 return NULL;
[email protected]94752ee2012-02-10 10:38:204378 }
[email protected]f103ab72009-09-02 17:10:594379
[email protected]00c39612010-03-06 02:53:284380 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:464381 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:324382#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:224383 return webkit::npapi::WebPluginDelegateImpl::Create(
4384 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:094385#else
[email protected]7398dcc2011-09-06 21:40:324386 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:224387 NOTIMPLEMENTED();
4388 return NULL;
[email protected]7b6616f2010-01-14 18:07:554389#endif
[email protected]f103ab72009-09-02 17:10:594390 }
4391
[email protected]4e0616e2010-05-28 14:55:534392 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:594393}
4394
[email protected]6ac77cb2012-05-01 14:49:014395WebKit::WebPlugin* RenderViewImpl::CreatePluginReplacement(
4396 const FilePath& file_path) {
[email protected]e9ff79c2012-10-19 21:31:264397 return GetContentClient()->renderer()->CreatePluginReplacement(
[email protected]6ac77cb2012-05-01 14:49:014398 this, file_path);
4399}
4400
[email protected]310ebd6302011-10-10 19:06:284401void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034402#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:274403 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:594404#endif
4405}
4406
[email protected]310ebd6302011-10-10 19:06:284407void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034408#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:274409 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:594410#endif
4411 CleanupWindowInPluginMoves(window);
4412}
4413
[email protected]310ebd6302011-10-10 19:06:284414void RenderViewImpl::DidMovePlugin(
4415 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:594416 SchedulePluginMove(move);
4417}
4418
[email protected]310ebd6302011-10-10 19:06:284419void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:594420 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524421 didStartLoading();
[email protected]f103ab72009-09-02 17:10:594422}
4423
[email protected]310ebd6302011-10-10 19:06:284424void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:594425 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524426 didStopLoading();
[email protected]f103ab72009-09-02 17:10:594427}
4428
[email protected]310ebd6302011-10-10 19:06:284429WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:514430 return &cookie_jar_;
4431}
4432
[email protected]5d65fe92012-06-02 00:48:554433void RenderViewImpl::DidPlay(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074434 Send(new ViewHostMsg_MediaNotification(routing_id_,
4435 reinterpret_cast<int64>(player),
4436 player->hasVideo(),
4437 player->hasAudio(),
4438 true));
4439}
4440
[email protected]5d65fe92012-06-02 00:48:554441void RenderViewImpl::DidPause(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074442 Send(new ViewHostMsg_MediaNotification(routing_id_,
4443 reinterpret_cast<int64>(player),
4444 player->hasVideo(),
4445 player->hasAudio(),
4446 false));
4447}
4448
[email protected]5d65fe92012-06-02 00:48:554449void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074450 DidPause(player);
4451}
4452
[email protected]310ebd6302011-10-10 19:06:284453void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:294454 if (!webview())
4455 return;
4456
[email protected]26aa0482009-09-30 16:55:274457 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:054458 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:294459}
4460
[email protected]310ebd6302011-10-10 19:06:284461void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:364462 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:004463 if (!frame)
4464 return;
[email protected]b781ff282011-08-20 06:19:364465
[email protected]e99ef6f2011-10-16 01:13:004466 string16 text;
4467 size_t offset;
[email protected]3c8c74c2012-03-15 07:34:524468 ui::Range range;
[email protected]e99ef6f2011-10-16 01:13:004469
[email protected]3c8c74c2012-03-15 07:34:524470 if (pepper_delegate_.IsPluginFocused()) {
4471 pepper_delegate_.GetSurroundingText(&text, &range);
[email protected]82114f52012-03-20 22:53:414472 offset = 0; // Pepper API does not support offset reporting.
[email protected]3c8c74c2012-03-15 07:34:524473 // TODO(kinaba): cut as needed.
[email protected]e99ef6f2011-10-16 01:13:004474 } else {
[email protected]3c8c74c2012-03-15 07:34:524475 size_t location, length;
4476 if (!webview()->caretOrSelectionRange(&location, &length))
4477 return;
4478
4479 range = ui::Range(location, location + length);
4480
4481 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
4482 // If current focused element is editable, we will send 100 more chars
4483 // before and after selection. It is for input method surrounding text
4484 // feature.
4485 if (location > kExtraCharsBeforeAndAfterSelection)
4486 offset = location - kExtraCharsBeforeAndAfterSelection;
4487 else
4488 offset = 0;
4489 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
4490 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
4491 if (!webrange.isNull())
4492 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
4493 } else {
4494 offset = location;
4495 text = frame->selectionAsText();
4496 // http://crbug.com/101435
4497 // In some case, frame->selectionAsText() returned text's length is not
4498 // equal to the length returned from webview()->caretOrSelectionRange().
4499 // So we have to set the range according to text.length().
4500 range.set_end(range.start() + text.length());
4501 }
[email protected]b781ff282011-08-20 06:19:364502 }
4503
[email protected]b781ff282011-08-20 06:19:364504 // Sometimes we get repeated didChangeSelection calls from webkit when
4505 // the selection hasn't actually changed. We don't want to report these
4506 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:004507 if (selection_text_offset_ != offset ||
4508 selection_range_ != range ||
4509 selection_text_ != text) {
4510 selection_text_ = text;
4511 selection_text_offset_ = offset;
4512 selection_range_ = range;
4513 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
4514 }
[email protected]b781ff282011-08-20 06:19:364515}
4516
[email protected]310ebd6302011-10-10 19:06:284517GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
4518 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554519 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294520 // If the URL that failed was secure, then the embedding web page was not
4521 // expecting a network attacker to be able to manipulate its contents. As
4522 // we fetch alternate error pages over HTTP, we would be allowing a network
4523 // attacker to manipulate the contents of the response if we tried to use
4524 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154525 return GURL();
initial.commit09911bf2008-07-26 23:55:294526 }
4527
4528 // Grab the base URL from the browser process.
4529 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154530 return GURL();
initial.commit09911bf2008-07-26 23:55:294531
4532 // Strip query params from the failed URL.
4533 GURL::Replacements remove_params;
4534 remove_params.ClearUsername();
4535 remove_params.ClearPassword();
4536 remove_params.ClearQuery();
4537 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554538 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504539 std::string spec_to_send = url_to_send.spec();
4540 // Notify link doctor of the url truncation by sending of "?" at the end.
4541 if (failed_url.has_query())
[email protected]82114f52012-03-20 22:53:414542 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294543
4544 // Construct the query params to send to link doctor.
4545 std::string params(alternate_error_page_url_.query());
4546 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:024547 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294548 params.append("&sourceid=chrome");
4549 params.append("&error=");
4550 switch (error_type) {
4551 case DNS_ERROR:
4552 params.append("dnserror");
4553 break;
4554
4555 case HTTP_404:
4556 params.append("http404");
4557 break;
4558
[email protected]5df266ac2008-10-15 19:50:134559 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334560 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134561 break;
4562
initial.commit09911bf2008-07-26 23:55:294563 default:
4564 NOTREACHED() << "unknown ErrorPageType";
4565 }
4566
4567 // OK, build the final url to return.
4568 GURL::Replacements link_doctor_params;
4569 link_doctor_params.SetQueryStr(params);
4570 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4571 return url;
4572}
4573
[email protected]310ebd6302011-10-10 19:06:284574GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:594575 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
4576 return GURL();
4577 else
4578 return creator_url_;
4579}
4580
[email protected]69ddf852012-02-21 23:21:314581GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
4582 WebDataSource* ds = frame->dataSource();
4583 if (ds->hasUnreachableURL())
4584 return ds->unreachableURL();
4585
4586 const WebURLRequest& request = ds->request();
4587 return request.url();
4588}
4589
[email protected]310ebd6302011-10-10 19:06:284590WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:274591 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:314592 web_ui_bindings_.reset(new WebUIBindings(
[email protected]e9ff79c2012-10-19 21:31:264593 static_cast<RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:464594 }
[email protected]c50008512011-02-03 01:17:274595 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:464596}
4597
[email protected]310ebd6302011-10-10 19:06:284598WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:014599 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494600}
4601
[email protected]55750b32012-09-21 14:05:034602void RenderViewImpl::OnFind(int request_id,
4603 const string16& search_text,
[email protected]310ebd6302011-10-10 19:06:284604 const WebFindOptions& options) {
[email protected]55750b32012-09-21 14:05:034605#if defined(OS_ANDROID)
4606 // Make sure any asynchronous messages do not disrupt an ongoing synchronous
4607 // find request as it might lead to deadlocks. Also, these should be safe to
4608 // ignore since they would belong to a previous find request.
4609 if (synchronous_find_reply_message_.get())
4610 return;
4611#endif
4612 Find(request_id, search_text, options);
4613}
4614
4615void RenderViewImpl::Find(int request_id,
4616 const string16& search_text,
4617 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274618 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494619
[email protected]872542532011-06-23 00:43:164620 // Check if the plugin still exists in the document.
4621 if (main_frame->document().isPluginDocument() &&
4622 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494623 if (options.findNext) {
4624 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014625 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494626 } else {
[email protected]55750b32012-09-21 14:05:034627 if (!GetWebPluginFromPluginDocument()->startFind(
[email protected]afdbd142010-07-10 08:01:234628 search_text, options.matchCase, request_id)) {
[email protected]e7c58a32010-08-13 19:47:114629 // Send "no results".
[email protected]55750b32012-09-21 14:05:034630 SendFindReply(request_id, 0, 0, gfx::Rect(), true);
[email protected]24a7f3c2010-03-25 08:26:494631 }
4632 }
4633 return;
4634 }
4635
[email protected]b4bb2502009-10-01 22:35:274636 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274637 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294638 WebFrame* search_frame = focused_frame; // start searching focused frame.
4639
4640 bool multi_frame = (frame_after_main != main_frame);
4641
4642 // If we have multiple frames, we don't want to wrap the search within the
4643 // frame, so we check here if we only have main_frame in the chain.
4644 bool wrap_within_frame = !multi_frame;
4645
[email protected]b3f2b912009-04-09 16:18:524646 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294647 bool result = false;
4648
[email protected]7830da3e2009-11-06 16:27:264649 // If something is selected when we start searching it means we cannot just
4650 // increment the current match ordinal; we need to re-generate it.
4651 WebRange current_selection = focused_frame->selectionRange();
4652
initial.commit09911bf2008-07-26 23:55:294653 do {
[email protected]dd7daa82009-08-10 05:46:454654 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594655 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294656
4657 if (!result) {
4658 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:224659 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294660
4661 // Find the next frame, but skip the invisible ones.
4662 do {
4663 // What is the next frame to search? (we might be going backwards). Note
4664 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594665 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274666 search_frame->traverseNext(true) :
4667 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454668 } while (!search_frame->hasVisibleContent() &&
4669 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294670
[email protected]884db412008-11-24 23:46:504671 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:224672 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294673
4674 // If we have multiple frames and we have wrapped back around to the
4675 // focused frame, we need to search it once more allowing wrap within
4676 // the frame, otherwise it will report 'no match' if the focused frame has
4677 // reported matches, but no frames after the focused_frame contain a
4678 // match for the search word(s).
4679 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454680 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594681 request_id, search_text, options, true, // Force wrapping.
4682 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294683 }
4684 }
4685
[email protected]26aa0482009-09-30 16:55:274686 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294687 } while (!result && search_frame != focused_frame);
4688
[email protected]7830da3e2009-11-06 16:27:264689 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294690 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454691 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294692 } else {
4693 // If nothing is found, set result to "0 of 0", otherwise, set it to
4694 // "-1 of 1" to indicate that we found at least one item, but we don't know
4695 // yet what is active.
4696 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4697 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294698
[email protected]4f3dc372009-02-24 00:10:294699 // If we find no matches then this will be our last status update.
4700 // Otherwise the scoping effort will send more results.
4701 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294702
[email protected]55750b32012-09-21 14:05:034703 SendFindReply(request_id, match_count, ordinal, selection_rect,
4704 final_status_update);
initial.commit09911bf2008-07-26 23:55:294705
initial.commit09911bf2008-07-26 23:55:294706 // Scoping effort begins, starting with the mainframe.
4707 search_frame = main_frame;
4708
[email protected]dd7daa82009-08-10 05:46:454709 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294710
4711 do {
4712 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454713 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294714
4715 // We don't start another scoping effort unless at least one match has
4716 // been found.
4717 if (result) {
4718 // Start new scoping request. If the scoping function determines that it
4719 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454720 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594721 search_text,
4722 options,
initial.commit09911bf2008-07-26 23:55:294723 true); // reset the tickmarks
4724 }
4725
4726 // Iterate to the next frame. The frame will not necessarily scope, for
4727 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274728 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294729 } while (search_frame != main_frame);
4730 }
4731}
4732
[email protected]e9ff79c2012-10-19 21:31:264733void RenderViewImpl::OnStopFinding(StopFindAction action) {
[email protected]55750b32012-09-21 14:05:034734#if defined(OS_ANDROID)
4735 // Make sure any asynchronous messages do not disrupt an ongoing synchronous
4736 // find request as it might lead to deadlocks. Also, these should be safe to
4737 // ignore since they would belong to a previous find request.
4738 if (synchronous_find_reply_message_.get())
4739 return;
4740#endif
4741
4742 StopFinding(action);
4743}
4744
[email protected]e9ff79c2012-10-19 21:31:264745void RenderViewImpl::StopFinding(StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:494746 WebView* view = webview();
4747 if (!view)
4748 return;
4749
4750 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:164751 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014752 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494753 return;
4754 }
4755
[email protected]e9ff79c2012-10-19 21:31:264756 bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:494757 if (clear_selection)
4758 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4759
4760 WebFrame* frame = view->mainFrame();
4761 while (frame) {
4762 frame->stopFinding(clear_selection);
4763 frame = frame->traverseNext(false);
4764 }
4765
[email protected]e9ff79c2012-10-19 21:31:264766 if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:494767 WebFrame* focused_frame = view->focusedFrame();
4768 if (focused_frame) {
4769 WebDocument doc = focused_frame->document();
4770 if (!doc.isNull()) {
4771 WebNode node = doc.focusedNode();
4772 if (!node.isNull())
4773 node.simulateClick();
4774 }
4775 }
4776 }
4777}
4778
[email protected]59363fc92012-09-05 03:46:314779#if defined(OS_ANDROID)
[email protected]55750b32012-09-21 14:05:034780void RenderViewImpl::OnSynchronousFind(int request_id,
4781 const string16& search_string,
4782 const WebFindOptions& options,
4783 IPC::Message* reply_msg) {
4784 // It is impossible for simultaneous blocking finds to occur.
4785 CHECK(!synchronous_find_reply_message_.get());
4786 synchronous_find_reply_message_.reset(reply_msg);
4787
4788 // Find next should be asynchronous in order to minimize blocking
4789 // the UI thread as much as possible.
4790 DCHECK(!options.findNext);
[email protected]e9ff79c2012-10-19 21:31:264791 StopFinding(STOP_FIND_ACTION_KEEP_SELECTION);
[email protected]55750b32012-09-21 14:05:034792 synchronous_find_active_match_ordinal_ = -1;
4793
4794 Find(request_id, search_string, options);
4795}
4796
[email protected]59363fc92012-09-05 03:46:314797void RenderViewImpl::OnActivateNearestFindResult(int request_id,
4798 float x, float y) {
4799 if (!webview())
4800 return;
4801
4802 WebFrame* main_frame = webview()->mainFrame();
4803 WebRect selection_rect;
4804 int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y),
4805 &selection_rect);
4806 if (ordinal == -1) {
4807 // Something went wrong, so send a no-op reply (force the main_frame to
4808 // report the current match count) in case the host is waiting for a
4809 // response due to rate-limiting).
4810 main_frame->increaseMatchCount(0, request_id);
4811 return;
4812 }
4813
[email protected]55750b32012-09-21 14:05:034814 SendFindReply(request_id,
4815 -1 /* number_of_matches */,
4816 ordinal,
4817 selection_rect,
4818 true /* final_update */);
[email protected]59363fc92012-09-05 03:46:314819}
4820
4821void RenderViewImpl::OnFindMatchRects(int current_version) {
4822 if (!webview())
4823 return;
4824
4825 WebFrame* main_frame = webview()->mainFrame();
4826 std::vector<gfx::RectF> match_rects;
4827
4828 int rects_version = main_frame->findMatchMarkersVersion();
4829 if (current_version != rects_version) {
4830 WebVector<WebFloatRect> web_match_rects;
4831 main_frame->findMatchRects(web_match_rects);
4832 match_rects.reserve(web_match_rects.size());
4833 for (size_t i = 0; i < web_match_rects.size(); ++i)
4834 match_rects.push_back(gfx::RectF(web_match_rects[i]));
4835 }
4836
4837 gfx::RectF active_rect = main_frame->activeFindMatchRect();
4838 Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_,
4839 rects_version,
4840 match_rects,
4841 active_rect));
4842}
4843#endif
4844
[email protected]e9ff79c2012-10-19 21:31:264845void RenderViewImpl::OnZoom(PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:514846 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4847 return;
4848
[email protected]258d31122010-05-09 10:59:414849 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:104850
[email protected]b75b8292010-10-01 07:28:254851 double old_zoom_level = webview()->zoomLevel();
4852 double zoom_level;
[email protected]e9ff79c2012-10-19 21:31:264853 if (zoom == PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:254854 zoom_level = 0;
4855 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4856 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:484857 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:254858 } else {
4859 // Either the user hit the zoom factor limit and thus the zoom level is now
4860 // not a whole number, or a plugin changed it to a custom value. We want
4861 // to go to the next whole number so that the user can always get back to
4862 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:484863 if ((old_zoom_level > 1 && zoom > 0) ||
4864 (old_zoom_level < 1 && zoom < 0)) {
4865 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:254866 } else {
4867 // We're going towards 100%, so first go to the next whole number.
4868 zoom_level = static_cast<int>(old_zoom_level);
4869 }
4870 }
[email protected]b75b8292010-10-01 07:28:254871 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:414872 zoomLevelChanged();
4873}
4874
[email protected]e9ff79c2012-10-19 21:31:264875void RenderViewImpl::OnZoomFactor(PageZoom zoom, int zoom_center_x,
4876 int zoom_center_y) {
[email protected]47578fa02011-11-02 19:34:414877 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
4878 kScalingIncrementForGesture);
4879}
4880
[email protected]e9ff79c2012-10-19 21:31:264881void RenderViewImpl::ZoomFactorHelper(PageZoom zoom,
[email protected]47578fa02011-11-02 19:34:414882 int zoom_center_x,
4883 int zoom_center_y,
4884 float scaling_increment) {
4885 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4886 return;
4887
[email protected]c514d6372011-08-16 22:54:444888 double old_page_scale_factor = webview()->pageScaleFactor();
4889 double page_scale_factor;
[email protected]e9ff79c2012-10-19 21:31:264890 if (zoom == PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:444891 page_scale_factor = 1.0;
4892 } else {
4893 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:414894 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:444895 }
[email protected]47578fa02011-11-02 19:34:414896 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:094897 webview()->setPageScaleFactor(page_scale_factor,
4898 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:414899 }
[email protected]40bd6582009-12-04 23:49:514900}
4901
[email protected]310ebd6302011-10-10 19:06:284902void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174903 webview()->hidePopups();
4904 webview()->setZoomLevel(false, zoom_level);
4905 zoomLevelChanged();
4906}
4907
[email protected]310ebd6302011-10-10 19:06:284908void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4909 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544910 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294911}
4912
[email protected]310ebd6302011-10-10 19:06:284913void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274914 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294915}
4916
[email protected]310ebd6302011-10-10 19:06:284917void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274918 WebString no_encoding;
4919 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184920}
4921
[email protected]310ebd6302011-10-10 19:06:284922WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454923 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274924 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454925
4926 // xpath string can represent a frame deep down the tree (across multiple
4927 // frame DOMs).
4928 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4929 // should break into 2 xpaths
4930 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:414931 std::vector<string16> xpaths;
4932 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:454933
[email protected]26aa0482009-09-30 16:55:274934 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:414935 for (std::vector<string16>::const_iterator i = xpaths.begin();
4936 frame && i != xpaths.end(); ++i) {
4937 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294938 }
4939
[email protected]dd7daa82009-08-10 05:46:454940 return frame;
initial.commit09911bf2008-07-26 23:55:294941}
4942
[email protected]310ebd6302011-10-10 19:06:284943void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4944 const string16& jscript,
4945 int id,
4946 bool notify_result) {
[email protected]01d43ef92012-09-25 00:54:104947 TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest");
[email protected]882b7b22010-10-05 03:34:534948 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294949}
4950
[email protected]f546640b2012-05-15 00:03:494951void RenderViewImpl::OnPostMessageEvent(
4952 const ViewMsg_PostMessage_Params& params) {
[email protected]0720b532012-08-28 19:23:374953 // Find the target frame of this message. The source tags the message with
4954 // |target_frame_id|, so use it to locate the frame.
[email protected]e12dbe6f2012-10-04 22:11:194955 // TODO(nasko): Lookup based on the frame id, once http://crbug.com/153701
4956 // is fixed and we can rely on having frame tree updates again.
4957 WebFrame* frame = webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:494958
4959 // Find the source frame if it exists.
[email protected]f546640b2012-05-15 00:03:494960 WebFrame* source_frame = NULL;
4961 if (params.source_routing_id != MSG_ROUTING_NONE) {
4962 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
[email protected]e12dbe6f2012-10-04 22:11:194963 // TODO(nasko): Lookup based on the frame id, once http://crbug.com/153701
4964 // is fixed and we can rely on having frame tree updates again.
[email protected]f546640b2012-05-15 00:03:494965 if (source_view)
[email protected]e12dbe6f2012-10-04 22:11:194966 source_frame = source_view->webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:494967 }
4968
4969 // Create an event with the message. The final parameter to initMessageEvent
4970 // is the last event ID, which is not used with postMessage.
4971 WebDOMEvent event = frame->document().createEvent("MessageEvent");
4972 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
4973 msg_event.initMessageEvent("message",
4974 // |canBubble| and |cancellable| are always false
4975 false, false,
4976 WebSerializedScriptValue::fromString(params.data),
4977 params.source_origin, source_frame, "");
4978
4979 // We must pass in the target_origin to do the security check on this side,
4980 // since it may have changed since the original postMessage call was made.
4981 WebSecurityOrigin target_origin;
4982 if (!params.target_origin.empty()) {
4983 target_origin =
4984 WebSecurityOrigin::createFromString(WebString(params.target_origin));
4985 }
4986 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
4987}
4988
[email protected]310ebd6302011-10-10 19:06:284989void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
4990 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:414991 WebFrame* frame = GetChildFrame(frame_xpath);
4992 if (!frame)
[email protected]216813952011-05-19 22:21:264993 return;
[email protected]ae461542009-06-19 19:03:414994
[email protected]01cf589c2011-07-28 18:04:034995 frame->document().insertUserStyleSheet(
4996 WebString::fromUTF8(css),
4997 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:484998}
4999
[email protected]310ebd6302011-10-10 19:06:285000void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:095001 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:045002
5003 // Keep track of the total bindings accumulated in this process.
5004 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:295005}
5006
[email protected]310ebd6302011-10-10 19:06:285007void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
5008 const std::string& value) {
[email protected]e9ff79c2012-10-19 21:31:265009 if (enabled_bindings_ & BINDINGS_POLICY_WEB_UI)
[email protected]808bda52012-03-09 22:43:325010 GetWebUIBindings()->SetProperty(name, value);
5011 else
5012 NOTREACHED() << "WebUI bindings not enabled.";
initial.commit09911bf2008-07-26 23:55:295013}
5014
[email protected]310ebd6302011-10-10 19:06:285015void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
5016 const gfx::Point& client_point,
5017 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:425018 WebDragOperationsMask ops,
5019 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:555020 WebDragOperation operation = webview()->dragTargetDragEnter(
5021 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:555022 client_point,
5023 screen_point,
[email protected]1f2230b2012-05-17 23:43:425024 ops,
5025 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555026
5027 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5028}
5029
[email protected]310ebd6302011-10-10 19:06:285030void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
5031 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:425032 WebDragOperationsMask ops,
5033 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:555034 WebDragOperation operation = webview()->dragTargetDragOver(
5035 client_point,
5036 screen_point,
[email protected]1f2230b2012-05-17 23:43:425037 ops,
5038 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555039
5040 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5041}
5042
[email protected]310ebd6302011-10-10 19:06:285043void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:555044 webview()->dragTargetDragLeave();
5045}
5046
[email protected]310ebd6302011-10-10 19:06:285047void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
[email protected]1f2230b2012-05-17 23:43:425048 const gfx::Point& screen_point,
5049 int key_modifiers) {
5050 webview()->dragTargetDrop(client_point, screen_point, key_modifiers);
[email protected]fcad49452011-06-28 17:11:575051
5052 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:555053}
5054
[email protected]310ebd6302011-10-10 19:06:285055void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
5056 const gfx::Point& screen_point,
5057 bool ended,
5058 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:035059 if (ended) {
[email protected]26aa0482009-09-30 16:55:275060 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:205061 } else {
5062 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:035063 }
initial.commit09911bf2008-07-26 23:55:295064}
5065
[email protected]310ebd6302011-10-10 19:06:285066void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:275067 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:295068}
5069
[email protected]310ebd6302011-10-10 19:06:285070void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:595071 webkit_preferences_ = prefs;
5072 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:295073}
5074
[email protected]38761452012-10-18 16:31:595075void RenderViewImpl::OnUpdateTimezone() {
5076 if (webview())
5077 NotifyTimezoneChange(webview()->mainFrame());
5078}
5079
[email protected]310ebd6302011-10-10 19:06:285080void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:295081 alternate_error_page_url_ = url;
5082}
5083
[email protected]310ebd6302011-10-10 19:06:285084void RenderViewImpl::OnCustomContextMenuAction(
[email protected]e9ff79c2012-10-19 21:31:265085 const CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:085086 unsigned action) {
[email protected]860ee642012-10-13 03:46:255087 if (custom_context.request_id) {
5088 // External context menu request, look in our map.
[email protected]e9ff79c2012-10-19 21:31:265089 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:255090 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:465091 if (client)
5092 client->OnMenuAction(custom_context.request_id, action);
[email protected]860ee642012-10-13 03:46:255093 } else {
5094 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:085095 webview()->performCustomContextMenuAction(action);
[email protected]860ee642012-10-13 03:46:255096 }
[email protected]a0c7153e2009-12-09 14:36:335097}
5098
[email protected]310ebd6302011-10-10 19:06:285099void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:515100 int id,
5101 const std::vector<FilePath>& paths) {
5102 if (!enumeration_completions_[id])
5103 return;
5104
5105 WebVector<WebString> ws_file_names(paths.size());
5106 for (size_t i = 0; i < paths.size(); ++i)
[email protected]bb0e79472012-10-23 04:36:345107 ws_file_names[i] = webkit_base::FilePathToWebString(paths[i]);
[email protected]600ea402011-04-12 00:01:515108
5109 enumeration_completions_[id]->didChooseFile(ws_file_names);
5110 enumeration_completions_.erase(id);
5111}
5112
[email protected]fb11b6a42012-03-14 07:25:125113void RenderViewImpl::OnFileChooserResponse(
[email protected]ddb034b2012-06-26 20:31:395114 const std::vector<ui::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:365115 // This could happen if we navigated to a different page before the user
5116 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:475117 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:365118 return;
5119
[email protected]b5188522012-03-15 00:18:045120 // Convert Chrome's SelectedFileInfo list to WebKit's.
5121 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
5122 files.size());
5123 for (size_t i = 0; i < files.size(); ++i) {
5124 WebFileChooserCompletion::SelectedFileInfo selected_file;
[email protected]bb0e79472012-10-23 04:36:345125 selected_file.path = webkit_base::FilePathToWebString(files[i].local_path);
5126 selected_file.displayName = webkit_base::FilePathStringToWebString(
[email protected]b5188522012-03-15 00:18:045127 files[i].display_name);
5128 selected_files[i] = selected_file;
5129 }
[email protected]a1128322009-10-06 18:38:465130
[email protected]cdaf8d02010-03-30 19:52:475131 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:045132 file_chooser_completions_.front()->completion->didChooseFile(
5133 selected_files);
[email protected]cdaf8d02010-03-30 19:52:475134 file_chooser_completions_.pop_front();
5135
5136 // If there are more pending file chooser requests, schedule one now.
5137 if (!file_chooser_completions_.empty()) {
5138 Send(new ViewHostMsg_RunFileChooser(routing_id_,
5139 file_chooser_completions_.front()->params));
5140 }
initial.commit09911bf2008-07-26 23:55:295141}
5142
[email protected]244ac1892011-12-02 17:04:475143void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
5144 const gfx::Size& max_size) {
5145 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5146 if (!webview())
5147 return;
[email protected]61e2b3cc2012-03-02 16:13:345148 webview()->enableAutoResizeMode(min_size, max_size);
5149}
5150
5151void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
5152 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5153 if (!webview())
5154 return;
5155 webview()->disableAutoResizeMode();
5156
5157 Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK);
[email protected]244ac1892011-12-02 17:04:475158}
5159
[email protected]2bf834f2011-11-17 20:02:215160void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:245161 if (send_preferred_size_changes_)
5162 return;
[email protected]9fb325e2010-05-06 18:23:245163 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:395164
[email protected]d812fd12011-05-27 23:05:075165 // Start off with an initial preferred size notification (in case
5166 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:595167 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:085168}
5169
[email protected]310ebd6302011-10-10 19:06:285170void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:105171 const gfx::Size& disable_scrollbar_size_limit) {
5172 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
5173}
5174
[email protected]310ebd6302011-10-10 19:06:285175void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:265176 const RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:505177 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:515178 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:375179 UpdateFontRenderingFromRendererPrefs();
[email protected]a13283cc2012-04-05 00:21:225180#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:415181 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
5182 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:465183 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]f78452f2012-05-15 02:07:525184 ui::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:345185 renderer_prefs.thumb_inactive_color,
5186 renderer_prefs.thumb_active_color,
5187 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:555188#endif
[email protected]93623c5d2009-12-10 21:40:325189
[email protected]a13283cc2012-04-05 00:21:225190#if defined(USE_ASH) || defined(TOOLKIT_GTK)
[email protected]644d77e2010-01-27 01:03:105191 if (webview()) {
[email protected]a13283cc2012-04-05 00:21:225192#if defined(TOOLKIT_GTK)
[email protected]93623c5d2009-12-10 21:40:325193 webview()->setScrollbarColors(
5194 renderer_prefs.thumb_inactive_color,
5195 renderer_prefs.thumb_active_color,
5196 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:555197#endif
[email protected]644d77e2010-01-27 01:03:105198 webview()->setSelectionColors(
5199 renderer_prefs.active_selection_bg_color,
5200 renderer_prefs.active_selection_fg_color,
5201 renderer_prefs.inactive_selection_bg_color,
5202 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:465203 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:105204 }
[email protected]7a74e102009-09-03 00:16:565205#endif
[email protected]d299d972012-03-23 02:26:555206
[email protected]d051d9a2011-12-10 02:02:505207 // If the zoom level for this page matches the old zoom default, and this
5208 // is not a plugin, update the zoom level to match the new default.
5209 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
[email protected]e9ff79c2012-10-19 21:31:265210 ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
[email protected]d051d9a2011-12-10 02:02:505211 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
5212 zoomLevelChanged();
5213 }
[email protected]80d96fa2009-06-10 22:34:515214}
5215
[email protected]310ebd6302011-10-10 19:06:285216void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
5217 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:285218 if (webview())
5219 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:565220}
5221
[email protected]77829642012-05-15 14:47:175222void RenderViewImpl::OnOrientationChangeEvent(int orientation) {
5223 webview()->mainFrame()->sendOrientationChangeEvent(orientation);
5224}
5225
[email protected]81375e872012-01-11 21:40:365226void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
5227 const WebPluginAction& action) {
5228 if (webview())
5229 webview()->performPluginAction(action, location);
5230}
5231
[email protected]310ebd6302011-10-10 19:06:285232void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:195233 const GURL& page_url) {
5234 // Prepare list to storage all savable resource links.
5235 std::vector<GURL> resources_list;
[email protected]c2d986512012-05-12 00:22:465236 std::vector<GURL> referrer_urls_list;
5237 std::vector<WebKit::WebReferrerPolicy> referrer_policies_list;
[email protected]18d5be92011-07-25 18:00:195238 std::vector<GURL> frames_list;
5239 webkit_glue::SavableResourcesResult result(&resources_list,
[email protected]c2d986512012-05-12 00:22:465240 &referrer_urls_list,
5241 &referrer_policies_list,
[email protected]18d5be92011-07-25 18:00:195242 &frames_list);
5243
[email protected]e9ff79c2012-10-19 21:31:265244 // webkit/ doesn't know about Referrer.
[email protected]18d5be92011-07-25 18:00:195245 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
5246 webview(),
5247 page_url,
5248 &result,
[email protected]e9ff79c2012-10-19 21:31:265249 const_cast<const char**>(GetSavableSchemes()))) {
[email protected]18d5be92011-07-25 18:00:195250 // If something is wrong when collecting all savable resource links,
5251 // send empty list to embedder(browser) to tell it failed.
[email protected]c2d986512012-05-12 00:22:465252 referrer_urls_list.clear();
5253 referrer_policies_list.clear();
[email protected]18d5be92011-07-25 18:00:195254 resources_list.clear();
5255 frames_list.clear();
5256 }
5257
[email protected]e9ff79c2012-10-19 21:31:265258 std::vector<Referrer> referrers_list;
[email protected]c2d986512012-05-12 00:22:465259 CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size());
5260 for (unsigned i = 0; i < referrer_urls_list.size(); ++i) {
5261 referrers_list.push_back(
[email protected]e9ff79c2012-10-19 21:31:265262 Referrer(referrer_urls_list[i], referrer_policies_list[i]));
[email protected]c2d986512012-05-12 00:22:465263 }
5264
[email protected]18d5be92011-07-25 18:00:195265 // Send result of all savable resource links to embedder.
5266 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
5267 resources_list,
5268 referrers_list,
5269 frames_list));
5270}
5271
[email protected]310ebd6302011-10-10 19:06:285272void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:195273 const std::vector<GURL>& links,
5274 const std::vector<FilePath>& local_paths,
5275 const FilePath& local_directory_name) {
5276
5277 // Convert std::vector of GURLs to WebVector<WebURL>
5278 WebVector<WebURL> weburl_links(links);
5279
5280 // Convert std::vector of std::strings to WebVector<WebString>
5281 WebVector<WebString> webstring_paths(local_paths.size());
5282 for (size_t i = 0; i < local_paths.size(); i++)
[email protected]bb0e79472012-10-23 04:36:345283 webstring_paths[i] = webkit_base::FilePathToWebString(local_paths[i]);
[email protected]18d5be92011-07-25 18:00:195284
5285 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
5286 webstring_paths,
[email protected]bb0e79472012-10-23 04:36:345287 webkit_base::FilePathToWebString(
[email protected]18d5be92011-07-25 18:00:195288 local_directory_name));
5289}
5290
[email protected]310ebd6302011-10-10 19:06:285291void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:125292 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:275293 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:125294 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
5295 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
5296 before_unload_start_time,
5297 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:295298}
5299
[email protected]310ebd6302011-10-10 19:06:285300void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]69ddf852012-02-21 23:21:315301 // Ensure that no other in-progress navigation continues.
5302 OnStop();
5303
[email protected]73eb2602012-02-09 19:50:555304 // Only run unload if we're not swapped out yet, but send the ack either way.
5305 if (!is_swapped_out_) {
5306 // Swap this RenderView out so the tab can navigate to a page rendered by a
5307 // different process. This involves running the unload handler and clearing
5308 // the page. Once WasSwappedOut is called, we also allow this process to
5309 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:155310
[email protected]73eb2602012-02-09 19:50:555311 // Send an UpdateState message before we get swapped out.
5312 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:155313
[email protected]73eb2602012-02-09 19:50:555314 // Synchronously run the unload handler before sending the ACK.
5315 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:155316
[email protected]73eb2602012-02-09 19:50:555317 // Swap out and stop sending any IPC messages that are not ACKs.
5318 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:155319
[email protected]285f4bb82012-04-17 15:57:285320 // Replace the page with a blank dummy URL. The unload handler will not be
[email protected]73eb2602012-02-09 19:50:555321 // run a second time, thanks to a check in FrameLoader::stopLoading.
5322 // TODO(creis): Need to add a better way to do this that avoids running the
[email protected]285f4bb82012-04-17 15:57:285323 // beforeunload handler. For now, we just run it a second time silently.
[email protected]0720b532012-08-28 19:23:375324 NavigateToSwappedOutURL(webview()->mainFrame());
[email protected]961541a92012-06-01 21:15:285325
5326 // Let WebKit know that this view is hidden so it can drop resources and
5327 // stop compositing.
5328 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false);
[email protected]73eb2602012-02-09 19:50:555329 }
[email protected]992db4c2011-05-12 15:37:155330
5331 // Just echo back the params in the ACK.
5332 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
5333}
5334
[email protected]0720b532012-08-28 19:23:375335void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) {
[email protected]14392a52012-05-02 20:28:445336 // We use loadRequest instead of loadHTMLString because the former commits
5337 // synchronously. Otherwise a new navigation can interrupt the navigation
[email protected]e9ff79c2012-10-19 21:31:265338 // to kSwappedOutURL. If that happens to be to the page we had been
[email protected]14392a52012-05-02 20:28:445339 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]e9ff79c2012-10-19 21:31:265340 GURL swappedOutURL(kSwappedOutURL);
[email protected]14392a52012-05-02 20:28:445341 WebURLRequest request(swappedOutURL);
[email protected]0720b532012-08-28 19:23:375342 frame->loadRequest(request);
[email protected]14392a52012-05-02 20:28:445343}
5344
[email protected]310ebd6302011-10-10 19:06:285345void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:375346 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:295347 // TODO(creis): We'd rather use webview()->Close() here, but that currently
5348 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
5349 // in the onunload handler from appearing. For now, we're bypassing that and
5350 // calling the FrameLoader's CloseURL method directly. This should be
5351 // revisited to avoid having two ways to close a page. Having a single way
5352 // to close that can run onunload is also useful for fixing
5353 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:275354 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:295355
[email protected]992db4c2011-05-12 15:37:155356 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:295357}
5358
[email protected]310ebd6302011-10-10 19:06:285359void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:025360#if defined(USE_AURA)
5361 // Aura doesn't care if we switch themes.
5362#elif defined(OS_WIN)
[email protected]f78452f2012-05-15 02:07:525363 ui::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:465364 if (webview())
5365 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:575366#else // defined(OS_WIN)
5367 // TODO(port): we don't support theming on non-Windows platforms yet
5368 NOTIMPLEMENTED();
5369#endif
initial.commit09911bf2008-07-26 23:55:295370}
5371
[email protected]310ebd6302011-10-10 19:06:285372void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:085373 if (decrement_shared_popup_at_destruction_)
5374 shared_popup_counter_->data--;
5375 shared_popup_counter_ = new SharedRenderViewCounter(0);
5376 decrement_shared_popup_at_destruction_ = false;
5377}
5378
[email protected]310ebd6302011-10-10 19:06:285379bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
5380 const WebURLError& error,
5381 bool replace) {
[email protected]15d79e12009-08-02 19:23:455382 // We only show alternate error pages in the main frame. They are
5383 // intended to assist the user when navigating, so there is not much
5384 // value in showing them for failed subframes. Ideally, we would be
5385 // able to use the TYPED transition type for this, but that flag is
5386 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455387 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455388 return false;
5389
5390 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375391 // connection failure.
[email protected]15d79e12009-08-02 19:23:455392 int ec = error.reason;
5393 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5394 ec != net::ERR_CONNECTION_FAILED &&
5395 ec != net::ERR_CONNECTION_REFUSED &&
5396 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]82114f52012-03-20 22:53:415397 ec != net::ERR_CONNECTION_TIMED_OUT) {
[email protected]15d79e12009-08-02 19:23:455398 return false;
[email protected]82114f52012-03-20 22:53:415399 }
[email protected]15d79e12009-08-02 19:23:455400
5401 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555402 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455403 if (!error_page_url.is_valid())
5404 return false;
5405
5406 // Load an empty page first so there is an immediate response to the error,
5407 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455408 frame->loadHTMLString(std::string(),
[email protected]e9ff79c2012-10-19 21:31:265409 GURL(kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455410 error.unreachableURL,
5411 replace);
5412
5413 // Now, create a fetcher for the error page and associate it with the data
5414 // source we just created via the LoadHTMLString call. That way if another
5415 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:075416 DocumentState* document_state =
5417 DocumentState::FromDataSource(frame->provisionalDataSource());
5418 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:455419 new AltErrorPageResourceFetcher(
5420 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:085421 base::Bind(&RenderViewImpl::AltErrorPageFinished,
5422 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:455423 return true;
5424}
5425
[email protected]310ebd6302011-10-10 19:06:285426void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
5427 const WebURLError& original_error,
5428 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:455429 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:095430 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:555431 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:095432 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:455433}
5434
[email protected]310ebd6302011-10-10 19:06:285435void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:005436 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475437 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005438}
5439
[email protected]310ebd6302011-10-10 19:06:285440void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:095441 const gfx::Rect& resizer_rect,
5442 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:105443 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475444 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105445 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205446 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:315447 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:105448 }
[email protected]dd6afca2011-08-13 03:44:315449 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:105450 }
5451
[email protected]ee41e7d22011-10-14 19:34:095452 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:005453}
[email protected]0aa477bd2009-03-23 22:21:435454
[email protected]29ed96a2012-02-04 18:12:165455void RenderViewImpl::WillInitiatePaint() {
5456 // Notify the pepper plugins that we're about to paint.
5457 pepper_delegate_.ViewWillInitiatePaint();
5458}
5459
[email protected]310ebd6302011-10-10 19:06:285460void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:165461 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]53900d52010-06-16 04:25:015462 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:285463}
5464
[email protected]310ebd6302011-10-10 19:06:285465void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:285466 // Notify any pepper plugins that we painted. This will call into the plugin,
5467 // and we it may ask to close itself as a result. This will, in turn, modify
5468 // our set, possibly invalidating the iterator. So we iterate on a copy that
5469 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:015470 pepper_delegate_.ViewFlushedPaint();
5471
[email protected]5b1dec8c2012-02-07 04:35:385472 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
5473 // See crbug.com/112921.
5474 if (!webview())
5475 return;
5476
[email protected]00c39612010-03-06 02:53:285477 WebFrame* main_frame = webview()->mainFrame();
5478
5479 // If we have a provisional frame we are between the start and commit stages
5480 // of loading and we don't want to save stats.
5481 if (!main_frame->provisionalDataSource()) {
5482 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:075483 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:285484
[email protected]05c8e502010-08-15 15:13:525485 // TODO(jar): The following code should all be inside a method, probably in
5486 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285487 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:075488 if (document_state->first_paint_time().is_null()) {
5489 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:285490 }
[email protected]007733c2011-11-17 00:34:075491 if (document_state->first_paint_after_load_time().is_null() &&
5492 !document_state->finish_load_time().is_null()) {
5493 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:285494 }
5495 }
5496}
5497
[email protected]310ebd6302011-10-10 19:06:285498void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:085499 RenderWidget::OnSwapBuffersPosted();
5500}
5501
[email protected]310ebd6302011-10-10 19:06:285502void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:245503 RenderWidget::OnSwapBuffersComplete();
5504}
5505
[email protected]310ebd6302011-10-10 19:06:285506void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:245507 RenderWidget::OnSwapBuffersAborted();
5508}
5509
[email protected]310ebd6302011-10-10 19:06:285510webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:155511 const gfx::Rect& paint_bounds,
5512 TransportDIB** dib,
5513 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:205514 gfx::Rect* clip,
5515 float* scale_factor) {
[email protected]ca4847f2010-09-24 05:39:155516 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
[email protected]0f3a2d12012-09-01 03:37:205517 paint_bounds, dib, location, clip, scale_factor);
[email protected]ca4847f2010-09-24 05:39:155518}
5519
[email protected]ceb36f7d2012-10-31 18:33:245520gfx::Vector2d RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:075521 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]ceb36f7d2012-10-31 18:33:245522 return gfx::Vector2d(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:525523}
5524
[email protected]310ebd6302011-10-10 19:06:285525void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:165526 if (webview())
[email protected]26aa0482009-09-30 16:55:275527 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165528}
5529
[email protected]310ebd6302011-10-10 19:06:285530void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:145531 if (webview())
[email protected]b4bb2502009-10-01 22:35:275532 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145533
5534 SetBackground(background);
5535}
5536
[email protected]2a84f9d2012-06-05 21:50:435537void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) {
5538 if (accessibility_mode_ == new_mode)
5539 return;
5540 accessibility_mode_ = new_mode;
5541 if (renderer_accessibility_) {
5542 delete renderer_accessibility_;
5543 renderer_accessibility_ = NULL;
5544 }
5545 if (accessibility_mode_ == AccessibilityModeComplete)
5546 renderer_accessibility_ = new RendererAccessibilityComplete(this);
5547 else if (accessibility_mode_ == AccessibilityModeEditableTextOnly)
5548 renderer_accessibility_ = new RendererAccessibilityFocusOnly(this);
5549}
5550
[email protected]310ebd6302011-10-10 19:06:285551void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:345552 if (webview())
[email protected]b4bb2502009-10-01 22:35:275553 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265554
5555#if defined(OS_MACOSX)
5556 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5557 for (plugin_it = plugin_delegates_.begin();
5558 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5559 (*plugin_it)->SetWindowFocus(active);
5560 }
5561#endif
[email protected]8c66c5a2009-07-22 17:26:345562}
5563
[email protected]7a17bac02012-03-07 21:58:125564void RenderViewImpl::OnSetNavigationStartTime(
5565 const base::TimeTicks& browser_navigation_start) {
5566 if (!webview())
5567 return;
5568
5569 // Only the initial navigation can be a cross-renderer navigation. If we've
5570 // already navigated away from that page, we can ignore this message.
5571 if (page_id_ != -1)
5572 return;
5573
5574 // browser_navigation_start is likely before this process existed, so we can't
5575 // use InterProcessTimeTicksConverter. Instead, the best we can do is just
5576 // ensure we don't report a bogus value in the future.
5577 base::TimeTicks navigation_start = std::min(base::TimeTicks::Now(),
5578 browser_navigation_start);
5579 webview()->mainFrame()->provisionalDataSource()->setNavigationStartTime(
5580 (navigation_start - base::TimeTicks()).InSecondsF());
5581}
5582
[email protected]6ce7abc52010-02-02 18:40:145583#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285584void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:145585 // Inform plugins that their container has changed visibility.
5586 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5587 for (plugin_it = plugin_delegates_.begin();
5588 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5589 (*plugin_it)->SetContainerVisibility(visible);
5590 }
5591}
[email protected]1e6e3c992010-02-08 15:52:135592
[email protected]310ebd6302011-10-10 19:06:285593void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
5594 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:135595 // Inform plugins that their window's frame has changed.
5596 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5597 for (plugin_it = plugin_delegates_.begin();
5598 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5599 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5600 }
5601}
[email protected]935d63d2010-10-15 23:31:555602
[email protected]310ebd6302011-10-10 19:06:285603void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
5604 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135605 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555606 // applies to it or not, so inform all the delegates.
5607 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5608 for (plugin_it = plugin_delegates_.begin();
5609 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135610 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555611 }
5612}
[email protected]6ce7abc52010-02-02 18:40:145613#endif // OS_MACOSX
5614
[email protected]310ebd6302011-10-10 19:06:285615void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:485616 const EditCommands& edit_commands) {
5617 edit_commands_ = edit_commands;
5618}
5619
[email protected]310ebd6302011-10-10 19:06:285620void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:595621 // We need to grab a pointer to the doomed WebView before we destroy it.
5622 WebView* doomed = webview();
5623 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495624 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:595625}
5626
[email protected]310ebd6302011-10-10 19:06:285627void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:485628 edit_commands_.clear();
5629}
5630
[email protected]310ebd6302011-10-10 19:06:285631bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]217690d2012-01-27 07:33:115632 pepper_delegate_.WillHandleMouseEvent();
5633
5634 // If the mouse is locked, only the current owner of the mouse lock can
5635 // process mouse events.
5636 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:375637}
5638
[email protected]2b942c332012-04-25 16:26:265639void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515640 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065641}
5642
[email protected]310ebd6302011-10-10 19:06:285643void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:245644 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
5645}
5646
[email protected]310ebd6302011-10-10 19:06:285647void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:435648 RenderWidget::OnWasHidden();
5649
[email protected]2d7b82c2012-06-01 05:57:505650#if defined(OS_ANDROID)
5651 // Inform WebMediaPlayerManagerAndroid to release all media player resources.
5652 media_player_manager_->ReleaseMediaResources();
5653#endif
5654
[email protected]a6939ca42011-02-18 17:58:075655 if (webview()) {
5656 webview()->settings()->setMinimumTimerInterval(
5657 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:445658 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075659 }
5660
[email protected]204f1df2012-01-04 20:21:135661 // Inform PPAPI plugins that their page is no longer visible.
5662 pepper_delegate_.PageVisibilityChanged(false);
5663
[email protected]a6939ca42011-02-18 17:58:075664#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135665 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:435666 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5667 for (plugin_it = plugin_delegates_.begin();
5668 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5669 (*plugin_it)->SetContainerVisibility(false);
5670 }
[email protected]a6939ca42011-02-18 17:58:075671#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:435672}
5673
[email protected]9e2e4632012-07-27 16:38:415674void RenderViewImpl::OnWasShown(bool needs_repainting) {
5675 RenderWidget::OnWasShown(needs_repainting);
[email protected]941e4552010-02-01 21:23:435676
[email protected]a6939ca42011-02-18 17:58:075677 if (webview()) {
5678 webview()->settings()->setMinimumTimerInterval(
5679 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:445680 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075681 }
5682
[email protected]204f1df2012-01-04 20:21:135683 // Inform PPAPI plugins that their page is visible.
5684 pepper_delegate_.PageVisibilityChanged(true);
5685
[email protected]a6939ca42011-02-18 17:58:075686#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135687 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:435688 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5689 for (plugin_it = plugin_delegates_.begin();
5690 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5691 (*plugin_it)->SetContainerVisibility(true);
5692 }
[email protected]784ea1ab2010-09-18 00:02:345693#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:075694}
[email protected]1e6e3c992010-02-08 15:52:135695
[email protected]310ebd6302011-10-10 19:06:285696bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]9caf09bc2012-06-25 21:46:285697 // Contexts using the command buffer support asynchronous swapbuffers.
[email protected]f89e173a2012-08-24 01:12:265698 // See RenderViewImpl::createOutputSurface().
[email protected]9caf09bc2012-06-25 21:46:285699 if (WebWidgetHandlesCompositorScheduling() ||
5700 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL))
[email protected]555e75d2011-10-08 01:23:385701 return false;
5702
[email protected]9caf09bc2012-06-25 21:46:285703 return true;
[email protected]65225772011-05-12 21:10:245704}
5705
[email protected]479b0172012-10-29 19:27:095706bool RenderViewImpl::ForceCompositingModeEnabled() {
5707 return webkit_preferences_.force_compositing_mode;
5708}
5709
[email protected]310ebd6302011-10-10 19:06:285710void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:135711 RenderWidget::OnSetFocus(enable);
5712
[email protected]7d3c02c2010-05-05 23:10:315713 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075714 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135715 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5716 for (plugin_it = plugin_delegates_.begin();
5717 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345718#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315719 // RenderWidget's call to setFocus can cause the underlying webview's
5720 // activation state to change just like a call to setIsActive.
5721 if (enable)
5722 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345723#endif
[email protected]7d3c02c2010-05-05 23:10:315724 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135725 }
5726 }
[email protected]a01da5682012-06-30 00:37:315727 // Notify all Pepper plugins.
5728 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135729}
[email protected]941e4552010-02-01 21:23:435730
[email protected]310ebd6302011-10-10 19:06:285731void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]3306f262012-09-21 19:20:425732 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]3f783362011-10-21 22:40:505733 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:575734}
5735
[email protected]73bf95812011-10-12 11:38:325736void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]3306f262012-09-21 19:20:425737 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]8fe8f742012-06-14 00:36:085738 if (renderer_accessibility_)
5739 renderer_accessibility_->FocusedNodeChanged(WebNode());
[email protected]73bf95812011-10-12 11:38:325740}
5741
[email protected]3f783362011-10-21 22:40:505742void RenderViewImpl::PpapiPluginCaretPositionChanged() {
5743 UpdateSelectionBounds();
5744}
5745
[email protected]b25b3ee2012-01-13 05:19:545746bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
5747 if (!pepper_delegate_.IsPluginFocused())
5748 return false;
5749 *rect = pepper_delegate_.GetCaretBounds();
5750 return true;
5751}
5752
[email protected]397c23962012-05-21 07:09:325753void RenderViewImpl::SimulateImeSetComposition(
5754 const string16& text,
5755 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5756 int selection_start,
5757 int selection_end) {
5758 OnImeSetComposition(text, underlines, selection_start, selection_end);
5759}
5760
5761void RenderViewImpl::SimulateImeConfirmComposition(
5762 const string16& text,
5763 const ui::Range& replacement_range) {
5764 OnImeConfirmComposition(text, replacement_range);
5765}
5766
[email protected]73bf95812011-10-12 11:38:325767void RenderViewImpl::PpapiPluginCancelComposition() {
5768 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]58b48a0d2012-06-13 07:01:355769 const ui::Range range(ui::Range::InvalidRange());
5770 const std::vector<gfx::Rect> empty_bounds;
5771 UpdateCompositionInfo(range, empty_bounds);
[email protected]73bf95812011-10-12 11:38:325772}
5773
[email protected]3c8c74c2012-03-15 07:34:525774void RenderViewImpl::PpapiPluginSelectionChanged() {
5775 SyncSelectionIfRequired();
5776}
5777
[email protected]e9ff79c2012-10-19 21:31:265778void RenderViewImpl::PpapiPluginCreated(RendererPpapiHost* host) {
[email protected]236bf852012-07-27 22:49:365779 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
5780 DidCreatePepperPlugin(host));
5781}
5782
[email protected]310ebd6302011-10-10 19:06:285783void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:575784 const string16& text,
5785 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5786 int selection_start,
5787 int selection_end) {
[email protected]73bf95812011-10-12 11:38:325788 if (pepper_delegate_.IsPluginFocused()) {
5789 // When a PPAPI plugin has focus, we bypass WebKit.
5790 pepper_delegate_.OnImeSetComposition(text,
5791 underlines,
5792 selection_start,
5793 selection_end);
5794 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235795#if defined(OS_WIN)
5796 // When a plug-in has focus, we create platform-specific IME data used by
5797 // our IME emulator and send it directly to the focused plug-in, i.e. we
5798 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
5799 // instance ID is the same one as the specified ID.)
5800 if (focused_plugin_id_ >= 0) {
5801 std::vector<int> clauses;
5802 std::vector<int> target;
5803 for (size_t i = 0; i < underlines.size(); ++i) {
5804 clauses.push_back(underlines[i].startOffset);
5805 clauses.push_back(underlines[i].endOffset);
5806 if (underlines[i].thick) {
5807 target.clear();
5808 target.push_back(underlines[i].startOffset);
5809 target.push_back(underlines[i].endOffset);
5810 }
5811 }
5812 std::set<WebPluginDelegateProxy*>::iterator it;
5813 for (it = plugin_delegates_.begin();
5814 it != plugin_delegates_.end(); ++it) {
5815 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
5816 focused_plugin_id_);
5817 }
5818 return;
5819 }
5820#endif
[email protected]56ea1a62011-05-30 07:05:575821 RenderWidget::OnImeSetComposition(text,
5822 underlines,
5823 selection_start,
5824 selection_end);
5825 }
5826}
5827
[email protected]4de6d1692011-10-12 08:45:445828void RenderViewImpl::OnImeConfirmComposition(
5829 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:575830 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:325831 // When a PPAPI plugin has focus, we bypass WebKit.
5832 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:575833 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235834#if defined(OS_WIN)
5835 // Same as OnImeSetComposition(), we send the text from IMEs directly to
5836 // plug-ins. When we send IME text directly to plug-ins, we should not send
5837 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:445838 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:235839 if (focused_plugin_id_ >= 0) {
5840 std::set<WebPluginDelegateProxy*>::iterator it;
5841 for (it = plugin_delegates_.begin();
5842 it != plugin_delegates_.end(); ++it) {
5843 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
5844 }
5845 return;
5846 }
5847#endif
[email protected]ebd28ac2011-10-13 18:49:055848 if (replacement_range.IsValid() && webview()) {
5849 // Select the text in |replacement_range|, it will then be replaced by
5850 // text added by the call to RenderWidget::OnImeConfirmComposition().
5851 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:165852 WebRange webrange = WebRange::fromDocumentRange(
5853 frame, replacement_range.start(), replacement_range.length());
5854 if (!webrange.isNull())
[email protected]884f9002012-08-21 19:33:585855 frame->selectRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:055856 }
5857 }
[email protected]4de6d1692011-10-12 08:45:445858 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:575859 }
5860}
5861
[email protected]dea5e7682012-06-14 05:21:245862void RenderViewImpl::OnSetDeviceScaleFactor(float device_scale_factor) {
5863 RenderWidget::OnSetDeviceScaleFactor(device_scale_factor);
5864 if (webview())
5865 webview()->setDeviceScaleFactor(device_scale_factor);
5866}
5867
[email protected]310ebd6302011-10-10 19:06:285868ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:325869 return pepper_delegate_.IsPluginFocused() ?
5870 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
5871}
5872
[email protected]3f783362011-10-21 22:40:505873void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
5874 if (pepper_delegate_.IsPluginFocused()) {
5875 // TODO(kinaba) http://crbug.com/101101
5876 // Current Pepper IME API does not handle selection bounds. So we simply
5877 // use the caret position as an empty range for now. It will be updated
5878 // after Pepper API equips features related to surrounding text retrieval.
5879 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
5880 *start = caret;
5881 *end = caret;
5882 return;
5883 }
5884 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:455885}
5886
[email protected]58b48a0d2012-06-13 07:01:355887void RenderViewImpl::GetCompositionCharacterBounds(
5888 std::vector<gfx::Rect>* bounds) {
5889 DCHECK(bounds);
5890 bounds->clear();
5891
5892 if (!webview())
5893 return;
5894 size_t start_offset = 0;
5895 size_t character_count = 0;
5896 if (!webview()->compositionRange(&start_offset, &character_count))
5897 return;
5898 if (character_count == 0)
5899 return;
5900
5901 WebKit::WebFrame* frame = webview()->focusedFrame();
5902 if (!frame)
5903 return;
5904
5905 bounds->reserve(character_count);
5906 WebKit::WebRect webrect;
5907 for (size_t i = 0; i < character_count; ++i) {
5908 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
5909 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
5910 bounds->clear();
5911 return;
5912 }
5913 bounds->push_back(webrect);
5914 }
5915}
5916
[email protected]310ebd6302011-10-10 19:06:285917bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:325918 return pepper_delegate_.IsPluginFocused() ?
5919 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:575920}
5921
[email protected]e6ae0f6c2011-10-04 10:39:235922#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:285923void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:235924 if (focused)
5925 focused_plugin_id_ = plugin_id;
5926 else
5927 focused_plugin_id_ = -1;
5928}
5929#endif
5930
[email protected]43f28f832010-02-03 02:28:485931#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285932void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]82114f52012-03-20 22:53:415933 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
[email protected]b7f75862011-01-21 21:15:135934}
5935
[email protected]310ebd6302011-10-10 19:06:285936void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:135937 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:555938 // This message can be sent during event-handling, and needs to be delivered
5939 // within that context.
5940 msg->set_unblock(true);
5941 Send(msg);
5942}
5943
[email protected]310ebd6302011-10-10 19:06:285944gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235945 bool opaque, bool root) {
[email protected]b2968292012-03-28 01:35:515946 gfx::PluginWindowHandle window = gfx::kNullPluginWindow;
[email protected]43f28f832010-02-03 02:28:485947 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235948 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:115949 if (window) {
5950 fake_plugin_window_handles_.insert(window);
5951 }
[email protected]43f28f832010-02-03 02:28:485952 return window;
5953}
5954
[email protected]310ebd6302011-10-10 19:06:285955void RenderViewImpl::DestroyFakePluginWindowHandle(
5956 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:115957 if (window && fake_plugin_window_handles_.find(window) !=
5958 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:485959 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:115960 fake_plugin_window_handles_.erase(window);
5961 }
[email protected]43f28f832010-02-03 02:28:485962}
5963
[email protected]310ebd6302011-10-10 19:06:285964void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
5965 gfx::PluginWindowHandle window,
5966 int32 width,
5967 int32 height,
5968 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:335969 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485970 routing_id(), window, width, height, io_surface_identifier));
5971}
5972
[email protected]310ebd6302011-10-10 19:06:285973void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:335974 gfx::PluginWindowHandle window,
5975 int32 width,
5976 int32 height,
5977 TransportDIB::Handle transport_dib) {
5978 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075979 routing_id(), window, width, height, transport_dib));
5980}
5981
[email protected]310ebd6302011-10-10 19:06:285982TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:335983 size_t size) {
[email protected]1aef98132010-02-23 18:00:075984 TransportDIB::Handle dib_handle;
5985 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385986 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075987 return dib_handle;
5988 // Return an invalid handle if Send() fails.
5989 return TransportDIB::DefaultHandleValue();
5990}
5991
[email protected]310ebd6302011-10-10 19:06:285992void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
5993 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075994 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5995}
5996
[email protected]310ebd6302011-10-10 19:06:285997void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:325998 gfx::PluginWindowHandle window, uint64 surface_handle) {
[email protected]f35d6672010-10-28 21:39:145999 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:326000 routing_id(), window, surface_handle));
[email protected]43f28f832010-02-03 02:28:486001}
[email protected]82114f52012-03-20 22:53:416002#endif // defined(OS_MACOSX)
[email protected]58c321d2010-02-19 12:11:286003
[email protected]310ebd6302011-10-10 19:06:286004bool RenderViewImpl::ScheduleFileChooser(
[email protected]e9ff79c2012-10-19 21:31:266005 const FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:476006 WebFileChooserCompletion* completion) {
6007 static const size_t kMaximumPendingFileChooseRequests = 4;
6008 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
6009 // This sanity check prevents too many file choose requests from getting
6010 // queued which could DoS the user. Getting these is most likely a
6011 // programming error (there are many ways to DoS the user so it's not
6012 // considered a "real" security check), either in JS requesting many file
6013 // choosers to pop up, or in a plugin.
6014 //
6015 // TODO(brettw) we might possibly want to require a user gesture to open
6016 // a file picker, which will address this issue in a better way.
6017 return false;
6018 }
6019
6020 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
6021 new PendingFileChooser(params, completion)));
6022 if (file_chooser_completions_.size() == 1) {
6023 // Actually show the browse dialog when this is the first request.
6024 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
6025 }
6026 return true;
6027}
6028
[email protected]310ebd6302011-10-10 19:06:286029WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:516030 if (!geolocation_dispatcher_)
6031 geolocation_dispatcher_ = new GeolocationDispatcher(this);
6032 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:256033}
[email protected]61c9f032010-03-31 23:04:196034
[email protected]310ebd6302011-10-10 19:06:286035WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:116036 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:226037#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:026038 if (!input_tag_speech_dispatcher_)
6039 input_tag_speech_dispatcher_ =
6040 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:226041#endif
[email protected]c52b2892012-03-07 11:01:026042 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:116043}
6044
[email protected]64d09222012-05-25 10:10:346045WebKit::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
6046#if defined(ENABLE_INPUT_SPEECH)
6047 if (!speech_recognition_dispatcher_)
6048 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
6049#endif
6050 return speech_recognition_dispatcher_;
6051}
6052
[email protected]310ebd6302011-10-10 19:06:286053WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:516054 if (!device_orientation_dispatcher_)
6055 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
6056 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:536057}
6058
[email protected]310ebd6302011-10-10 19:06:286059void RenderViewImpl::zoomLimitsChanged(double minimum_level,
6060 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:256061 // For now, don't remember plugin zoom values. We don't want to mix them with
6062 // normal web content (i.e. a fixed layout plugin would usually want them
6063 // different).
6064 bool remember = !webview()->mainFrame()->document().isPluginDocument();
6065
[email protected]b75b8292010-10-01 07:28:256066 int minimum_percent = static_cast<int>(
6067 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
6068 int maximum_percent = static_cast<int>(
6069 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:256070
6071 Send(new ViewHostMsg_UpdateZoomLimits(
6072 routing_id_, minimum_percent, maximum_percent, remember));
6073}
6074
[email protected]310ebd6302011-10-10 19:06:286075void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:256076 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:086077 float zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:266078
6079 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
6080
[email protected]b75b8292010-10-01 07:28:256081 // Tell the browser which url got zoomed so it can update the menu and the
6082 // saved values if necessary
6083 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:086084 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:416085 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:256086}
6087
[email protected]310ebd6302011-10-10 19:06:286088void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
6089 const WebString& base_url,
6090 const WebString& url,
6091 const WebString& title) {
[email protected]3a3b75a2012-06-01 08:38:366092 bool user_gesture = (webview()->focusedFrame() &&
6093 webview()->focusedFrame()->isProcessingUserGesture());
[email protected]a6d36cc2011-02-23 00:39:486094 GURL base(base_url);
6095 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
6096 if (base.GetOrigin() != absolute_url.GetOrigin()) {
6097 return;
6098 }
[email protected]f1a29a02011-10-06 23:08:446099 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
6100 UTF16ToUTF8(scheme),
6101 absolute_url,
[email protected]3a3b75a2012-06-01 08:38:366102 title,
6103 user_gesture));
[email protected]a6d36cc2011-02-23 00:39:486104}
6105
[email protected]310ebd6302011-10-10 19:06:286106WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:446107 WebKit::WebPageVisibilityState current_state = is_hidden() ?
6108 WebKit::WebPageVisibilityStateHidden :
6109 WebKit::WebPageVisibilityStateVisible;
6110 WebKit::WebPageVisibilityState override_state = current_state;
[email protected]e9ff79c2012-10-19 21:31:266111 if (GetContentClient()->renderer()->
[email protected]f59203a2011-06-07 10:01:446112 ShouldOverridePageVisibilityState(this,
6113 &override_state))
6114 return override_state;
6115 return current_state;
[email protected]94dec932011-05-26 20:04:216116}
6117
[email protected]273558fb2012-01-12 15:03:516118WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
[email protected]273558fb2012-01-12 15:03:516119 EnsureMediaStreamImpl();
6120 return media_stream_impl_;
6121}
6122
[email protected]a0629af92012-08-08 00:39:376123void RenderViewImpl::draggableRegionsChanged() {
6124 FOR_EACH_OBSERVER(
6125 RenderViewObserver,
6126 observers_,
6127 DraggableRegionsChanged(webview()->mainFrame()));
6128}
6129
[email protected]20657a82012-08-21 20:23:036130#if defined(OS_ANDROID)
6131WebContentDetectionResult RenderViewImpl::detectContentAround(
6132 const WebHitTestResult& touch_hit) {
6133 DCHECK(!touch_hit.isNull());
6134 DCHECK(!touch_hit.node().isNull());
6135 DCHECK(touch_hit.node().isTextNode());
6136
6137 // Process the position with all the registered content detectors until
6138 // a match is found. Priority is provided by their relative order.
6139 for (ContentDetectorList::const_iterator it = content_detectors_.begin();
6140 it != content_detectors_.end(); ++it) {
6141 ContentDetector::Result content = (*it)->FindTappedContent(touch_hit);
6142 if (content.valid) {
6143 return WebContentDetectionResult(content.content_boundaries,
6144 UTF8ToUTF16(content.text), content.intent_url);
6145 }
6146 }
6147 return WebContentDetectionResult();
6148}
6149
6150void RenderViewImpl::scheduleContentIntent(const WebURL& intent) {
6151 // Introduce a short delay so that the user can notice the content.
6152 MessageLoop::current()->PostDelayedTask(
6153 FROM_HERE,
6154 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, AsWeakPtr(),
6155 intent, expected_content_intent_id_),
6156 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds));
6157}
6158
6159void RenderViewImpl::cancelScheduledContentIntents() {
6160 ++expected_content_intent_id_;
6161}
6162
6163void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent,
6164 size_t request_id) {
6165 if (request_id != expected_content_intent_id_)
6166 return;
6167
6168 // Remove the content highlighting if any.
6169 scheduleComposite();
6170
6171 if (!intent.is_empty())
6172 Send(new ViewHostMsg_StartContentIntent(routing_id_, intent));
6173}
6174#endif
6175
[email protected]310ebd6302011-10-10 19:06:286176void RenderViewImpl::OnAsyncFileOpened(
6177 base::PlatformFileError error_code,
6178 IPC::PlatformFileForTransit file_for_transit,
6179 int message_id) {
[email protected]27a9ef32010-09-10 04:06:246180 pepper_delegate_.OnAsyncFileOpened(
6181 error_code,
6182 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
6183 message_id);
6184}
[email protected]caf706f2010-10-26 17:54:086185
[email protected]310ebd6302011-10-10 19:06:286186void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:476187 int request_id,
[email protected]d54305072011-06-22 20:58:436188 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:476189 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
[email protected]2b657fd2011-04-18 16:00:476190 handle);
[email protected]eb415bf0e2011-04-14 02:45:426191}
6192
[email protected]d8415ad92012-08-23 14:40:506193void RenderViewImpl::OnPpapiBrokerPermissionResult(
6194 int request_id,
6195 bool result) {
6196 pepper_delegate_.OnPpapiBrokerPermissionResult(request_id, result);
6197}
6198
[email protected]caf706f2010-10-26 17:54:086199#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:286200void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:156201 if (external_popup_menu_ == NULL) {
6202 // Crash reports from the field indicate that we can be notified with a
6203 // NULL external popup menu (we probably get notified twice).
6204 // If you hit this please file a bug against jcivelli and include the page
6205 // and steps to repro.
6206 NOTREACHED();
6207 return;
6208 }
[email protected]caf706f2010-10-26 17:54:086209 external_popup_menu_->DidSelectItem(selected_index);
6210 external_popup_menu_.reset();
6211}
6212#endif
[email protected]bb461532010-11-26 21:50:236213
[email protected]24d2b172012-05-26 00:54:126214#if defined(OS_ANDROID)
6215void RenderViewImpl::OnSelectPopupMenuItems(
6216 bool canceled,
6217 const std::vector<int>& selected_indices) {
6218 // It is possible to receive more than one of these calls if the user presses
6219 // a select faster than it takes for the show-select-popup IPC message to make
6220 // it to the browser UI thread. Ignore the extra-messages.
6221 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug.
6222 if (!external_popup_menu_.get())
6223 return;
6224
6225 external_popup_menu_->DidSelectItems(canceled, selected_indices);
6226 external_popup_menu_.reset();
6227}
6228#endif
6229
[email protected]310ebd6302011-10-10 19:06:286230void RenderViewImpl::OnContextMenuClosed(
[email protected]e9ff79c2012-10-19 21:31:266231 const CustomContextMenuContext& custom_context) {
[email protected]860ee642012-10-13 03:46:256232 if (custom_context.request_id) {
6233 // External request, should be in our map.
[email protected]e9ff79c2012-10-19 21:31:266234 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:256235 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:466236 if (client) {
6237 client->OnMenuClosed(custom_context.request_id);
6238 pending_context_menus_.Remove(custom_context.request_id);
6239 }
[email protected]860ee642012-10-13 03:46:256240 } else {
6241 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:086242 context_menu_node_.reset();
[email protected]860ee642012-10-13 03:46:256243 }
[email protected]521b2482011-01-15 00:10:106244}
[email protected]5a7b15a2011-08-22 22:48:186245
[email protected]310ebd6302011-10-10 19:06:286246void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:186247 if (!webview())
6248 return;
6249 WebFrame* main_frame = webview()->mainFrame();
6250 if (!main_frame)
6251 return;
6252 main_frame->enableViewSourceMode(true);
6253}
[email protected]67bfb83f2011-09-22 03:36:376254
[email protected]310ebd6302011-10-10 19:06:286255bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:086256 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:406257}
[email protected]7f3c7af2011-10-20 22:52:516258
[email protected]64d0e192011-12-09 14:44:206259void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7e9c5bb02012-05-14 13:58:316260 DCHECK(!java_bridge_dispatcher_);
[email protected]464750f2011-10-24 23:16:186261#if defined(ENABLE_JAVA_BRIDGE)
[email protected]7e9c5bb02012-05-14 13:58:316262 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this);
[email protected]464750f2011-10-24 23:16:186263#endif
[email protected]7f3c7af2011-10-20 22:52:516264}
[email protected]0720b532012-08-28 19:23:376265
6266void RenderViewImpl::OnUpdatedFrameTree(
6267 int process_id,
6268 int route_id,
6269 const std::string& frame_tree) {
[email protected]e12dbe6f2012-10-04 22:11:196270 // TODO(nasko): Remove once http://crbug.com/153701 is fixed.
6271 DCHECK(false);
[email protected]5fa9b36b2012-09-21 18:14:276272 // We should only act on this message if we are swapped out. It's possible
6273 // for this to happen due to races.
6274 if (!is_swapped_out_)
6275 return;
6276
[email protected]0720b532012-08-28 19:23:376277 base::DictionaryValue* frames = NULL;
6278 scoped_ptr<base::Value> tree(base::JSONReader::Read(frame_tree));
6279 if (tree.get() && tree->IsType(base::Value::TYPE_DICTIONARY))
6280 tree->GetAsDictionary(&frames);
6281
6282 updating_frame_tree_ = true;
6283 active_frame_id_map_.clear();
6284
6285 target_process_id_ = process_id;
6286 target_routing_id_ = route_id;
6287 CreateFrameTree(webview()->mainFrame(), frames);
6288
6289 updating_frame_tree_ = false;
6290}
[email protected]f9526d12012-10-18 01:55:036291
[email protected]efd7e47f2012-10-19 20:37:516292#if defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:036293bool RenderViewImpl::didTapMultipleTargets(
6294 const WebKit::WebGestureEvent& event,
6295 const WebVector<WebRect>& target_rects) {
[email protected]f9526d12012-10-18 01:55:036296 gfx::Rect finger_rect(
6297 event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2,
6298 event.data.tap.width, event.data.tap.height);
6299 gfx::Rect zoom_rect;
6300 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
6301 finger_rect, target_rects, GetSize(), &zoom_rect);
6302 if (!scale)
6303 return false;
6304
6305 gfx::Size canvas_size = zoom_rect.size();
6306 canvas_size = ToCeiledSize(canvas_size.Scale(scale));
6307 TransportDIB* transport_dib = NULL;
6308 {
6309 scoped_ptr<skia::PlatformCanvas> canvas(
6310 RenderProcess::current()->GetDrawingCanvas(&transport_dib,
6311 gfx::Rect(canvas_size)));
6312 if (!canvas.get())
6313 return false;
6314
6315 canvas->scale(scale, scale);
6316
6317 canvas->translate(-zoom_rect.x(), -zoom_rect.y());
6318 webwidget_->paint(webkit_glue::ToWebCanvas(canvas.get()), zoom_rect,
6319 WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent);
6320 }
6321 Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_,
6322 zoom_rect,
6323 canvas_size,
6324 transport_dib->id()));
6325
6326 return true;
6327}
[email protected]efd7e47f2012-10-19 20:37:516328#endif
[email protected]f9526d12012-10-18 01:55:036329
6330void RenderViewImpl::OnReleaseDisambiguationPopupDIB(
6331 TransportDIB::Handle dib_handle) {
6332 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle);
6333 RenderProcess::current()->ReleaseTransportDIB(dib);
6334}
[email protected]e9ff79c2012-10-19 21:31:266335
6336} // namespace content