blob: 47656382cd878faa2d2d0e146d5c3e8a25f17a09 [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 }
[email protected]50f86bc2012-11-01 19:59:13437 } else if (url == GURL(kChromeUIShorthangURL)) {
[email protected]8bf1048012012-02-08 01:22:18438 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]2fdf2352012-11-01 19:23:022061#if defined(OS_ANDROID)
2062 ipc_params.capture = params.capture;
2063#endif
[email protected]cdaf8d02010-03-30 19:52:472064
2065 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462066}
2067
[email protected]269f86d2011-12-07 02:43:472068void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
2069 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262070 RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:412071 message,
2072 string16(),
[email protected]b6cb3a842011-06-24 18:28:412073 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522074 NULL);
2075}
2076
[email protected]269f86d2011-12-07 02:43:472077bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
2078 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262079 return RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:412080 message,
2081 string16(),
[email protected]b6cb3a842011-06-24 18:28:412082 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522083 NULL);
2084}
2085
[email protected]269f86d2011-12-07 02:43:472086bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
2087 const WebString& message,
2088 const WebString& default_value,
2089 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:412090 string16 result;
[email protected]e9ff79c2012-10-19 21:31:262091 bool ok = RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:412092 message,
2093 default_value,
[email protected]b6cb3a842011-06-24 18:28:412094 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522095 &result);
2096 if (ok)
[email protected]4f5ce842011-05-27 19:34:412097 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:522098 return ok;
2099}
2100
[email protected]310ebd6302011-10-10 19:06:282101bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:522102 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:152103 // If we are swapping out, we have already run the beforeunload handler.
2104 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
2105 // at all, to avoid running it twice.
2106 if (is_swapped_out_)
2107 return true;
2108
[email protected]3b3301f62012-02-29 04:32:322109 bool is_reload = false;
2110 WebDataSource* ds = frame->provisionalDataSource();
2111 if (ds)
2112 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
2113
[email protected]48c9cf2d2009-09-16 16:47:522114 bool success = false;
2115 // This is an ignored return value, but is included so we can accept the same
2116 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:412117 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:212118 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:322119 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:412120 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522121 return success;
2122}
2123
[email protected]310ebd6302011-10-10 19:06:282124void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:442125 WebFrame* frame, const WebContextMenuData& data) {
[email protected]e9ff79c2012-10-19 21:31:262126 ContextMenuParams params(data);
[email protected]7fcd9b72011-07-27 16:52:372127
[email protected]329266d2012-09-27 06:20:572128 // Plugins, e.g. PDF, don't currently update the render view when their
2129 // selected text changes, but the context menu params do contain the updated
2130 // selection. If that's the case, update the render view's state just prior
2131 // to showing the context menu.
2132 // TODO(asvitkine): http://crbug.com/152432
[email protected]f49f7a12012-10-26 19:16:592133 string16 selection_text;
2134 if (!selection_text_.empty() && !selection_range_.is_empty()) {
2135 const int start = selection_range_.GetMin() - selection_text_offset_;
2136 const size_t length = selection_range_.length();
2137 if (start >= 0 && start + length <= selection_text_.length())
2138 selection_text = selection_text_.substr(start, length);
2139 }
[email protected]eff43567da2012-10-25 20:57:482140 if (params.selection_text != selection_text) {
[email protected]329266d2012-09-27 06:20:572141 selection_text_ = params.selection_text;
2142 // TODO(asvitkine): Text offset and range is not available in this case.
2143 selection_text_offset_ = 0;
2144 selection_range_ = ui::Range(0, selection_text_.length());
2145 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2146 selection_text_,
2147 selection_text_offset_,
2148 selection_range_));
2149 }
2150
[email protected]7fcd9b72011-07-27 16:52:372151 // frame is NULL if invoked by BlockedPlugin.
2152 if (frame)
2153 params.frame_id = frame->identifier();
2154
[email protected]e9ff79c2012-10-19 21:31:262155 // Serializing a GURL longer than kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:272156 // it. We replace it with an empty GURL so the appropriate items are disabled
2157 // in the context menu.
2158 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2159 // data encoded images. We should have a way to save them.
[email protected]e9ff79c2012-10-19 21:31:262160 if (params.src_url.spec().size() > kMaxURLChars)
[email protected]216932c2010-08-26 21:44:272161 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102162 context_menu_node_ = data.node;
[email protected]44daa3b2012-09-27 19:26:412163
2164#if defined(OS_ANDROID)
2165 gfx::Rect start_rect;
2166 gfx::Rect end_rect;
2167 GetSelectionBounds(&start_rect, &end_rect);
[email protected]ceb36f7d2012-10-31 18:33:242168 params.selection_start =
2169 gfx::Point(start_rect.x(), start_rect.bottom()) + GetScrollOffset();
2170 params.selection_end =
2171 gfx::Point(end_rect.right(), end_rect.bottom()) + GetScrollOffset();
[email protected]44daa3b2012-09-27 19:26:412172#endif
2173
[email protected]c27324b2009-11-19 22:44:292174 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]b2324b092012-11-01 10:34:112175
2176 FOR_EACH_OBSERVER(
2177 RenderViewObserver, observers_, DidRequestShowContextMenu(frame, data));
[email protected]79e37442009-10-09 18:17:442178}
2179
[email protected]310ebd6302011-10-10 19:06:282180void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:522181}
2182
[email protected]310ebd6302011-10-10 19:06:282183void RenderViewImpl::UpdateTargetURL(const GURL& url,
2184 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582185 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522186 if (latest_url == target_url_)
2187 return;
[email protected]163f8242009-10-30 20:19:552188
[email protected]48c9cf2d2009-09-16 16:47:522189 // Tell the browser to display a destination link.
2190 if (target_url_status_ == TARGET_INFLIGHT ||
2191 target_url_status_ == TARGET_PENDING) {
2192 // If we have a request in-flight, save the URL to be sent when we
2193 // receive an ACK to the in-flight request. We can happily overwrite
2194 // any existing pending sends.
2195 pending_target_url_ = latest_url;
2196 target_url_status_ = TARGET_PENDING;
2197 } else {
[email protected]e9ff79c2012-10-19 21:31:262198 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:412199 // see |ParamTraits<GURL>|.
[email protected]e9ff79c2012-10-19 21:31:262200 if (latest_url.possibly_invalid_spec().size() > kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:412201 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:522202 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2203 target_url_ = latest_url;
2204 target_url_status_ = TARGET_INFLIGHT;
2205 }
2206}
2207
[email protected]310ebd6302011-10-10 19:06:282208void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:312209 int delay;
2210 if (send_content_state_immediately_)
2211 delay = 0;
2212 else if (is_hidden())
2213 delay = kDelaySecondsForContentStateSyncHidden;
2214 else
2215 delay = kDelaySecondsForContentStateSync;
2216
2217 if (nav_state_sync_timer_.IsRunning()) {
2218 // The timer is already running. If the delay of the timer maches the amount
2219 // we want to delay by, then return. Otherwise stop the timer so that it
2220 // gets started with the right delay.
2221 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2222 return;
2223 nav_state_sync_timer_.Stop();
2224 }
2225
[email protected]d323a172011-09-02 18:23:022226 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:282227 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:312228}
2229
[email protected]310ebd6302011-10-10 19:06:282230void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552231 mouse_over_url_ = GURL(url);
2232 UpdateTargetURL(mouse_over_url_, focus_url_);
2233}
2234
[email protected]310ebd6302011-10-10 19:06:282235void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552236 focus_url_ = GURL(url);
2237 UpdateTargetURL(focus_url_, mouse_over_url_);
2238}
2239
[email protected]0407e422012-05-18 19:51:252240void RenderViewImpl::startDragging(WebFrame* frame,
2241 const WebDragData& data,
[email protected]310ebd6302011-10-10 19:06:282242 WebDragOperationsMask mask,
2243 const WebImage& image,
[email protected]ceb36f7d2012-10-31 18:33:242244 const WebPoint& webImageOffset) {
[email protected]b67151d2012-05-25 23:23:242245 WebDropData drop_data(data);
2246 drop_data.referrer_policy = frame->document().referrerPolicy();
[email protected]ceb36f7d2012-10-31 18:33:242247 gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y);
[email protected]59f4f2fa2011-03-23 01:00:552248 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]b67151d2012-05-25 23:23:242249 drop_data,
[email protected]c27ae592010-03-18 15:24:412250 mask,
[email protected]976127072012-05-10 20:08:112251 image.getSkBitmap(),
[email protected]c27ae592010-03-18 15:24:412252 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522253}
2254
[email protected]310ebd6302011-10-10 19:06:282255bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:452256 return renderer_preferences_.can_accept_load_drops;
2257}
2258
[email protected]310ebd6302011-10-10 19:06:282259void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:522260 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2261}
2262
[email protected]310ebd6302011-10-10 19:06:282263void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:522264 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2265}
2266
[email protected]310ebd6302011-10-10 19:06:282267void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512268 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072269
[email protected]38b592902011-04-16 02:08:422270 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:492271}
2272
[email protected]572a6ca2012-10-11 19:38:012273void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
2274 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
2275}
2276
2277void RenderViewImpl::hasTouchEventHandlers(bool has_handlers) {
2278 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2279}
2280
[email protected]169d4282011-11-30 19:33:592281void RenderViewImpl::didUpdateLayout() {
2282 // We don't always want to set up a timer, only if we've been put in that
2283 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2284 // message.
2285 if (!send_preferred_size_changes_ || !webview())
2286 return;
2287
2288 if (check_preferred_size_timer_.IsRunning())
2289 return;
2290 check_preferred_size_timer_.Start(FROM_HERE,
2291 TimeDelta::FromMilliseconds(0), this,
2292 &RenderViewImpl::CheckPreferredSize);
2293}
2294
[email protected]310ebd6302011-10-10 19:06:282295void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522296 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2297}
2298
[email protected]310ebd6302011-10-10 19:06:282299int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002300 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522301}
2302
[email protected]310ebd6302011-10-10 19:06:282303int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002304 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522305}
2306
[email protected]310ebd6302011-10-10 19:06:282307void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:322308 const WebAccessibilityObject& obj,
2309 WebAccessibilityNotification notification) {
[email protected]2a84f9d2012-06-05 21:50:432310 if (renderer_accessibility_) {
2311 renderer_accessibility_->HandleWebAccessibilityNotification(
2312 obj, notification);
2313 }
[email protected]063afcb2011-09-29 07:54:322314}
2315
[email protected]310ebd6302011-10-10 19:06:282316void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:142317 const WebString& value) {
2318 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2319 key.utf8(),
2320 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262321}
2322
[email protected]79dbc662009-09-04 05:42:512323// WebKit::WebWidgetClient ----------------------------------------------------
2324
[email protected]310ebd6302011-10-10 19:06:282325void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122326 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2327 // we won't have to test for user gesture anymore and we can
2328 // move that code back to render_widget.cc
2329 if (webview() && webview()->mainFrame() &&
2330 webview()->mainFrame()->isProcessingUserGesture()) {
2331 Send(new ViewHostMsg_Focus(routing_id_));
2332 }
2333}
2334
[email protected]310ebd6302011-10-10 19:06:282335void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122336 // TODO(jcivelli): see TODO above in didFocus().
2337 if (webview() && webview()->mainFrame() &&
2338 webview()->mainFrame()->isProcessingUserGesture()) {
2339 Send(new ViewHostMsg_Blur(routing_id_));
2340 }
2341}
2342
initial.commit09911bf2008-07-26 23:55:292343// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282344// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292345// point to dispatch the ShowView message.
2346//
2347// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282348// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292349//
[email protected]310ebd6302011-10-10 19:06:282350void RenderViewImpl::show(WebNavigationPolicy policy) {
[email protected]b2142e962012-10-30 13:59:252351 if (did_show_) {
2352#if defined(OS_ANDROID)
2353 // When supports_multiple_windows is disabled, popups are reusing
2354 // the same view. In some scenarios, this makes WebKit to call show() twice.
2355 if (!webkit_preferences_.supports_multiple_windows)
2356 return;
2357#endif
2358 NOTREACHED() << "received extraneous Show call";
initial.commit09911bf2008-07-26 23:55:292359 return;
[email protected]b2142e962012-10-30 13:59:252360 }
initial.commit09911bf2008-07-26 23:55:292361 did_show_ = true;
2362
[email protected]b2142e962012-10-30 13:59:252363 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2364
[email protected]e9ff79c2012-10-19 21:31:262365 if (GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:042366 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:042367
[email protected]28295ec2009-10-16 05:34:332368 // Force new windows to a popup if they were not opened with a user gesture.
2369 if (!opened_by_user_gesture_) {
2370 // We exempt background tabs for compat with older versions of Chrome.
2371 // TODO(darin): This seems bogus. These should have a user gesture, so
2372 // we probably don't need this check.
2373 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2374 policy = WebKit::WebNavigationPolicyNewPopup;
2375 }
2376
initial.commit09911bf2008-07-26 23:55:292377 // NOTE: initial_pos_ may still have its default values at this point, but
2378 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2379 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282380 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2381 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292382 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242383 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292384}
2385
[email protected]310ebd6302011-10-10 19:06:282386void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292387 DCHECK(did_show_) << "should already have shown the view";
2388
[email protected]c1f50aa2010-02-18 03:46:572389 // We must keep WebKit's shared timer running in this case in order to allow
2390 // showModalDialog to function properly.
2391 //
2392 // TODO(darin): WebKit should really be smarter about suppressing events and
2393 // timers so that we do not need to manage the shared timer in such a heavy
2394 // handed manner.
2395 //
[email protected]f1a29a02011-10-06 23:08:442396 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2397 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572398
[email protected]08a1c8102012-05-11 23:14:262399 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
2400 routing_id_, opener_id_));
initial.commit09911bf2008-07-26 23:55:292401}
2402
[email protected]2b624c562011-10-27 22:58:262403bool RenderViewImpl::enterFullScreen() {
2404 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2405 return true;
2406}
2407
2408void RenderViewImpl::exitFullScreen() {
2409 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2410}
2411
[email protected]217690d2012-01-27 07:33:112412bool RenderViewImpl::requestPointerLock() {
2413 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2414}
2415
2416void RenderViewImpl::requestPointerUnlock() {
2417 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2418}
2419
2420bool RenderViewImpl::isPointerLocked() {
2421 return mouse_lock_dispatcher_->IsMouseLockedTo(
2422 webwidget_mouse_lock_target_.get());
2423}
2424
[email protected]7a1ec28a2012-03-28 21:10:242425void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
2426 CompositorThread* compositor_thread =
2427 RenderThreadImpl::current()->compositor_thread();
2428 if (compositor_thread)
2429 compositor_thread->AddInputHandler(
2430 routing_id_, input_handler_identifier, AsWeakPtr());
2431
2432 RenderWidget::didActivateCompositor(input_handler_identifier);
[email protected]1c0c9bc2012-10-08 22:41:482433
2434 ProcessAcceleratedPinchZoomFlags(*CommandLine::ForCurrentProcess());
[email protected]7a1ec28a2012-03-28 21:10:242435}
2436
[email protected]3d9689372009-09-10 04:29:172437// WebKit::WebFrameClient -----------------------------------------------------
2438
[email protected]310ebd6302011-10-10 19:06:282439WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2440 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:552441 WebPlugin* plugin = NULL;
[email protected]e9ff79c2012-10-19 21:31:262442 if (GetContentClient()->renderer()->OverrideCreatePlugin(
[email protected]eaacd1f2011-09-23 02:32:552443 this, frame, params, &plugin)) {
2444 return plugin;
2445 }
2446
[email protected]e9ff79c2012-10-19 21:31:262447 if (UTF16ToASCII(params.mimeType) == kBrowserPluginMimeType) {
[email protected]6cd7c6b2012-10-25 03:26:232448 return BrowserPluginManager::Get()->
2449 CreateBrowserPlugin(this, frame, params);
[email protected]e6e56752012-08-10 00:46:062450 }
2451
[email protected]a813c8e2011-10-08 01:34:112452 webkit::WebPluginInfo info;
2453 std::string mime_type;
2454 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2455 params.mimeType.utf8(), &info, &mime_type);
2456 if (!found)
2457 return NULL;
2458
2459 WebPluginParams params_to_use = params;
2460 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312461 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172462}
2463
[email protected]310ebd6302011-10-10 19:06:282464WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422465 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372466 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422467
[email protected]30447b62009-11-13 01:13:372468 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512469 bool exists = false;
[email protected]30447b62009-11-13 01:13:372470 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512471 ViewHostMsg_CreateWorker_Params params;
2472 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512473 params.name = name;
2474 params.document_id = document_id;
2475 params.render_view_route_id = routing_id_;
2476 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232477 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372478 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512479 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372480 if (url_mismatch) {
2481 return NULL;
2482 } else {
[email protected]f1a29a02011-10-06 23:08:442483 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492484 document_id,
[email protected]6de0bcf2010-02-17 22:00:512485 exists,
[email protected]30447b62009-11-13 01:13:372486 route_id,
2487 routing_id_);
2488 }
[email protected]9c00f002009-11-05 22:37:422489}
2490
[email protected]97b150db2012-08-16 18:26:022491WebMediaPlayer* RenderViewImpl::createMediaPlayer(
2492 WebFrame* frame, const WebKit::WebURL& url, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442493 FOR_EACH_OBSERVER(
2494 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172495
[email protected]780fc8242012-09-19 20:28:522496 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
[email protected]25fb9b32012-04-27 03:21:552497#if defined(OS_ANDROID)
[email protected]855623ed2012-09-24 18:59:552498 WebGraphicsContext3D* resource_context =
2499 GetWebView()->sharedGraphicsContext3D();
2500
2501 GpuChannelHost* gpu_channel_host =
2502 RenderThreadImpl::current()->EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:262503 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
[email protected]855623ed2012-09-24 18:59:552504 if (!gpu_channel_host) {
2505 LOG(ERROR) << "Failed to establish GPU channel for media player";
2506 return NULL;
2507 }
2508
[email protected]780fc8242012-09-19 20:28:522509 if (cmd_line->HasSwitch(switches::kMediaPlayerInRenderProcess)) {
2510 if (!media_bridge_manager_.get()) {
2511 media_bridge_manager_.reset(
2512 new webkit_media::MediaPlayerBridgeManagerImpl(1));
2513 }
2514 return new webkit_media::WebMediaPlayerInProcessAndroid(
2515 frame,
2516 client,
2517 cookieJar(frame),
2518 media_player_manager_.get(),
2519 media_bridge_manager_.get(),
[email protected]e9ff79c2012-10-19 21:31:262520 new StreamTextureFactoryImpl(
[email protected]855623ed2012-09-24 18:59:552521 resource_context, gpu_channel_host, routing_id_),
[email protected]780fc8242012-09-19 20:28:522522 cmd_line->HasSwitch(switches::kDisableMediaHistoryLogging));
2523 }
2524 if (!media_player_proxy_) {
[email protected]e9ff79c2012-10-19 21:31:262525 media_player_proxy_ = new WebMediaPlayerProxyImplAndroid(
[email protected]780fc8242012-09-19 20:28:522526 this, media_player_manager_.get());
2527 }
2528 return new webkit_media::WebMediaPlayerImplAndroid(
2529 frame,
2530 client,
2531 media_player_manager_.get(),
2532 media_player_proxy_,
[email protected]e9ff79c2012-10-19 21:31:262533 new StreamTextureFactoryImpl(
[email protected]855623ed2012-09-24 18:59:552534 resource_context, gpu_channel_host, routing_id_));
[email protected]25fb9b32012-04-27 03:21:552535#endif
2536
[email protected]bb6fd402011-12-09 02:45:442537 media::MessageLoopFactory* message_loop_factory =
[email protected]b80322902012-03-06 01:33:502538 new media::MessageLoopFactory();
[email protected]bb6fd402011-12-09 02:45:442539 media::FilterCollection* collection = new media::FilterCollection();
2540 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372541
[email protected]9e2269d2012-01-07 00:06:212542 RenderAudioSourceProvider* audio_source_provider = NULL;
2543
[email protected]3d9689372009-09-10 04:29:172544 // Add in any custom filter factories first.
[email protected]3d9689372009-09-10 04:29:172545 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212546 // audio_source_provider is a "provider" to WebKit, and a sink
2547 // from the perspective of the audio renderer.
2548 audio_source_provider = new RenderAudioSourceProvider();
2549
2550 // Add the chrome specific audio renderer, using audio_source_provider
2551 // as the sink.
[email protected]37136d162012-04-09 23:39:192552 media::AudioRendererImpl* audio_renderer =
2553 new media::AudioRendererImpl(audio_source_provider);
[email protected]9e2269d2012-01-07 00:06:212554 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172555 }
2556
[email protected]15d206e2012-08-17 22:35:132557 WebGraphicsContext3DCommandBufferImpl* context3d = NULL;
[email protected]5f04c3532012-09-25 01:28:392558 if (!cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode))
[email protected]15d206e2012-08-17 22:35:132559 context3d = RenderThreadImpl::current()->GetGpuVDAContext3D();
[email protected]851334d2012-06-15 22:39:312560 if (context3d) {
[email protected]084c8552012-08-12 22:51:202561 scoped_refptr<base::MessageLoopProxy> factories_loop =
[email protected]84a83e192012-03-09 18:43:402562 RenderThreadImpl::current()->compositor_thread() ?
2563 RenderThreadImpl::current()->compositor_thread()->GetWebThread()
[email protected]084c8552012-08-12 22:51:202564 ->message_loop()->message_loop_proxy() :
2565 base::MessageLoopProxy::current();
[email protected]e1d69d762011-12-13 05:12:182566 GpuChannelHost* gpu_channel_host =
2567 RenderThreadImpl::current()->EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:262568 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
[email protected]873da262012-08-10 22:02:472569 collection->GetVideoDecoders()->push_back(new media::GpuVideoDecoder(
[email protected]084c8552012-08-12 22:51:202570 base::Bind(&media::MessageLoopFactory::GetMessageLoop,
2571 base::Unretained(message_loop_factory),
[email protected]c462c902012-09-06 13:13:422572 media::MessageLoopFactory::kDecoder),
[email protected]84a83e192012-03-09 18:43:402573 factories_loop,
[email protected]8d4359282012-01-14 00:53:312574 new RendererGpuVideoDecoderFactories(
[email protected]84a83e192012-03-09 18:43:402575 gpu_channel_host, factories_loop, context3d)));
[email protected]e1d69d762011-12-13 05:12:182576 }
[email protected]e1d69d762011-12-13 05:12:182577
[email protected]5d65fe92012-06-02 00:48:552578 WebMediaPlayer* media_player =
[email protected]e9ff79c2012-10-19 21:31:262579 GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
[email protected]da952fd2012-01-13 03:49:252580 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1113bfdf2012-07-16 21:46:102581 audio_source_provider, message_loop_factory, media_stream_impl_,
2582 render_media_log);
[email protected]da952fd2012-01-13 03:49:252583 if (!media_player) {
[email protected]ba42ac4f2012-10-11 20:28:142584#if defined(ENABLE_WEBRTC)
[email protected]5f04c3532012-09-25 01:28:392585 // TODO(wjia): when all patches related to WebMediaPlayerMS have been
2586 // landed, remove the switch. Refer to crbug.com/142988.
[email protected]1fba73c12012-10-10 23:36:202587 if (!cmd_line->HasSwitch(switches::kDisableWebMediaPlayerMS) &&
2588 MediaStreamImpl::CheckMediaStream(url)) {
[email protected]5f04c3532012-09-25 01:28:392589 EnsureMediaStreamImpl();
[email protected]1fba73c12012-10-10 23:36:202590 return new webkit_media::WebMediaPlayerMS(
2591 frame, client, AsWeakPtr(), media_stream_impl_, render_media_log);
[email protected]5f04c3532012-09-25 01:28:392592 }
[email protected]ba42ac4f2012-10-11 20:28:142593#endif
[email protected]5f04c3532012-09-25 01:28:392594
[email protected]cec4eb82012-01-12 17:51:562595 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252596 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1113bfdf2012-07-16 21:46:102597 audio_source_provider, message_loop_factory, media_stream_impl_,
2598 render_media_log);
[email protected]bb6fd402011-12-09 02:45:442599 }
[email protected]cec4eb82012-01-12 17:51:562600 return media_player;
[email protected]3d9689372009-09-10 04:29:172601}
2602
[email protected]310ebd6302011-10-10 19:06:282603WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212604 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232605 if (!frame || !frame->view())
2606 return NULL;
[email protected]035545f2010-04-09 13:10:212607 return new RendererWebApplicationCacheHostImpl(
2608 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442609 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212610}
2611
[email protected]310ebd6302011-10-10 19:06:282612WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382613 return &cookie_jar_;
2614}
2615
[email protected]0720b532012-08-28 19:23:372616void RenderViewImpl::didCreateFrame(WebFrame* parent, WebFrame* child) {
[email protected]0720b532012-08-28 19:23:372617 if (!updating_frame_tree_)
2618 SendUpdatedFrameTree(NULL);
2619}
2620
[email protected]310ebd6302011-10-10 19:06:282621void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]0720b532012-08-28 19:23:372622 if (is_loading_) {
2623 pending_frame_tree_update_ = true;
2624 // Make sure observers are notified, even if we return right away.
2625 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
2626 return;
2627 }
2628 if (!updating_frame_tree_)
2629 SendUpdatedFrameTree(frame);
2630
[email protected]676126f72011-01-15 00:03:512631 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452632}
2633
[email protected]310ebd6302011-10-10 19:06:282634void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512635 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172636}
2637
[email protected]310ebd6302011-10-10 19:06:282638void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172639 WebFrame* frame, const WebURLRequest& request,
2640 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342641 loadURLExternally(frame, request, policy, WebString());
2642}
2643
[email protected]5e92282f2012-08-17 08:11:572644void RenderViewImpl::Repaint(const gfx::Size& size) {
2645 OnMsgRepaint(size);
2646}
2647
[email protected]b2324b092012-11-01 10:34:112648void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
2649 const std::string& value) {
2650 EditCommands edit_commands;
2651 edit_commands.push_back(EditCommand(name, value));
2652 OnSetEditCommandsForNextKeyEvent(edit_commands);
2653}
2654
2655void RenderViewImpl::ClearEditCommands() {
2656 edit_commands_.clear();
2657}
2658
[email protected]310ebd6302011-10-10 19:06:282659void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342660 WebFrame* frame, const WebURLRequest& request,
2661 WebNavigationPolicy policy,
2662 const WebString& suggested_name) {
[email protected]56505542012-05-12 00:25:372663 Referrer referrer(
2664 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2665 GetReferrerPolicyFromRequest(frame, request));
[email protected]efce17b2009-09-11 18:04:592666 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342667 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2668 suggested_name));
[email protected]efce17b2009-09-11 18:04:592669 } else {
[email protected]56505542012-05-12 00:25:372670 OpenURL(frame, request.url(), referrer, policy);
[email protected]efce17b2009-09-11 18:04:592671 }
[email protected]3d9689372009-09-10 04:29:172672}
2673
[email protected]310ebd6302011-10-10 19:06:282674WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172675 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222676 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]0639c063a2012-03-22 20:55:332677 Referrer referrer(
2678 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:592679 GetReferrerPolicyFromRequest(frame, request));
[email protected]0639c063a2012-03-22 20:55:332680
[email protected]992db4c2011-05-12 15:37:152681 if (is_swapped_out_) {
[email protected]e9ff79c2012-10-19 21:31:262682 if (request.url() != GURL(kSwappedOutURL)) {
[email protected]0639c063a2012-03-22 20:55:332683 // Targeted links may try to navigate a swapped out frame. Allow the
2684 // browser process to navigate the tab instead. Note that it is also
2685 // possible for non-targeted navigations (from this view) to arrive
2686 // here just after we are swapped out. It's ok to send them to the
2687 // browser, as long as they're for the top level frame.
2688 // TODO(creis): Ensure this supports targeted form submissions when
2689 // fixing http://crbug.com/101395.
2690 if (frame->parent() == NULL) {
2691 OpenURL(frame, request.url(), referrer, default_policy);
2692 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2693 }
2694
2695 // We should otherwise ignore in-process iframe navigations, if they
2696 // arrive just after we are swapped out.
[email protected]73eb2602012-02-09 19:50:552697 return WebKit::WebNavigationPolicyIgnore;
[email protected]0639c063a2012-03-22 20:55:332698 }
[email protected]73eb2602012-02-09 19:50:552699
[email protected]e9ff79c2012-10-19 21:31:262700 // Allow kSwappedOutURL to complete.
[email protected]992db4c2011-05-12 15:37:152701 return default_policy;
2702 }
2703
[email protected]3d9689372009-09-10 04:29:172704 // Webkit is asking whether to navigate to a new URL.
2705 // This is fine normally, except if we're showing UI from one security
2706 // context and they're trying to navigate to a different context.
2707 const GURL& url = request.url();
2708
[email protected]d19ea342011-04-20 20:31:132709 // A content initiated navigation may have originated from a link-click,
2710 // script, drag-n-drop operation, etc.
2711 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072712 DocumentState::FromDataSource(frame->provisionalDataSource())->
2713 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132714
[email protected]a8c269a2011-10-25 20:17:222715 // Experimental:
2716 // If --enable-strict-site-isolation is enabled, send all top-level
2717 // navigations to the browser to let it swap processes when crossing site
2718 // boundaries. This is currently expected to break some script calls and
2719 // navigations, such as form submissions.
2720 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102721 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2722 !frame->parent() && (is_content_initiated || is_redirect)) {
2723 WebString origin_str = frame->document().securityOrigin().toString();
2724 GURL frame_url(origin_str.utf8().data());
[email protected]18fb7a772012-09-20 19:25:092725 // TODO(cevans): revisit whether this site check is still necessary once
[email protected]313b80bd2011-11-23 03:49:102726 // crbug.com/101395 is fixed.
[email protected]18fb7a772012-09-20 19:25:092727 if (!net::RegistryControlledDomainService::SameDomainOrHost(frame_url,
2728 url) ||
2729 frame_url.scheme() != url.scheme()) {
[email protected]313b80bd2011-11-23 03:49:102730 OpenURL(frame, url, referrer, default_policy);
2731 return WebKit::WebNavigationPolicyIgnore;
2732 }
[email protected]a8c269a2011-10-25 20:17:222733 }
2734
[email protected]fd3238af2012-05-22 18:55:302735 // If the browser is interested, then give it a chance to look at the request.
[email protected]5f000f272012-01-19 05:25:082736 if (is_content_initiated) {
[email protected]fd3238af2012-05-22 18:55:302737 bool browser_handles_request =
2738 renderer_preferences_.browser_handles_non_local_top_level_requests &&
[email protected]5f000f272012-01-19 05:25:082739 IsNonLocalTopLevelNavigation(url, frame, type);
[email protected]fd3238af2012-05-22 18:55:302740 if (!browser_handles_request) {
2741 browser_handles_request =
2742 renderer_preferences_.browser_handles_all_top_level_requests &&
2743 IsTopLevelNavigation(frame);
2744 }
2745
2746 if (browser_handles_request) {
[email protected]5f000f272012-01-19 05:25:082747 // Reset these counters as the RenderView could be reused for the next
2748 // navigation.
2749 page_id_ = -1;
2750 last_page_id_sent_to_browser_ = -1;
2751 OpenURL(frame, url, referrer, default_policy);
2752 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2753 }
[email protected]3d9689372009-09-10 04:29:172754 }
2755
[email protected]dc67e1c32012-06-08 00:10:402756 // Use the frame's original request's URL rather than the document's URL for
2757 // subsequent checks. For a popup, the document's URL may become the opener
2758 // window's URL if the opener has called document.write().
2759 // See http://crbug.com/93517.
2760 GURL old_url(frame->dataSource()->request().url());
2761
[email protected]6101c342010-12-16 22:44:372762 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552763 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:042764 // top-level navigations (not iframes). But we sometimes navigate to
2765 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:372766 //
[email protected]744c2a22012-03-15 18:42:042767 // Note: this is known to break POST submissions when crossing process
2768 // boundaries until http://crbug.com/101395 is fixed. This is better for
2769 // security than loading a WebUI, extension or app page in the wrong process.
2770 // POST requests don't work because this mechanism does not preserve form
2771 // POST data. We will need to send the request's httpBody data up to the
2772 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:572773 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2774 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222775 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:042776 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:372777 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:042778
2779 // All navigations to WebUI URLs or within WebUI-enabled RenderProcesses
2780 // must be handled by the browser process so that the correct bindings and
2781 // data sources can be registered.
2782 // Similarly, navigations to view-source URLs or within ViewSource mode
2783 // must be handled by the browser process.
[email protected]dc67e1c32012-06-08 00:10:402784 // Lastly, access to file:// URLs from non-file:// URL pages must be
2785 // handled by the browser so that ordinary renderer processes don't get
2786 // blessed with file permissions.
2787 int cumulative_bindings = RenderProcess::current()->GetEnabledBindings();
2788 bool is_initial_navigation = page_id_ == -1;
[email protected]6101c342010-12-16 22:44:372789 bool should_fork =
[email protected]e9ff79c2012-10-19 21:31:262790 GetContentClient()->HasWebUIScheme(url) ||
2791 (cumulative_bindings & BINDINGS_POLICY_WEB_UI) ||
[email protected]744c2a22012-03-15 18:42:042792 url.SchemeIs(chrome::kViewSourceScheme) ||
2793 frame->isViewSourceModeEnabled();
[email protected]5351dbc2010-08-27 15:22:112794
[email protected]dc67e1c32012-06-08 00:10:402795 if (!should_fork && url.SchemeIs(chrome::kFileScheme)) {
2796 // Fork non-file to file opens. Check the opener URL if this is the
2797 // initial navigation in a newly opened window.
2798 GURL source_url(old_url);
2799 if (is_initial_navigation && source_url.is_empty() && frame->opener())
2800 source_url = frame->opener()->top()->document().url();
2801 DCHECK(!source_url.is_empty());
2802 should_fork = !source_url.SchemeIs(chrome::kFileScheme);
2803 }
2804
[email protected]e48869a2011-04-01 19:56:032805 if (!should_fork) {
2806 // Give the embedder a chance.
[email protected]744c2a22012-03-15 18:42:042807 // For now, we skip this for POST submissions. This is because
2808 // http://crbug.com/101395 is more likely to cause compatibility issues
2809 // with hosted apps and extensions than WebUI pages. We will remove this
2810 // check when cross-process POST submissions are supported.
2811 if (request.httpMethod() == "GET") {
[email protected]e9ff79c2012-10-19 21:31:262812 should_fork = GetContentClient()->renderer()->ShouldFork(
[email protected]744c2a22012-03-15 18:42:042813 frame, url, is_initial_navigation, &send_referrer);
2814 }
[email protected]6101c342010-12-16 22:44:372815 }
2816
2817 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152818 OpenURL(
2819 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112820 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2821 }
[email protected]3d9689372009-09-10 04:29:172822 }
2823
2824 // Detect when a page is "forking" a new tab that can be safely rendered in
2825 // its own process. This is done by sites like Gmail that try to open links
2826 // in new windows without script connections back to the original page. We
2827 // treat such cases as browser navigations (in which we will create a new
2828 // renderer for a cross-site navigation), rather than WebKit navigations.
2829 //
2830 // We use the following heuristic to decide whether to fork a new page in its
2831 // own process:
2832 // The parent page must open a new tab to about:blank, set the new tab's
2833 // window.opener to null, and then redirect the tab to a cross-site URL using
2834 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462835 //
2836 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2837 // (see below).
[email protected]3d9689372009-09-10 04:29:172838 bool is_fork =
2839 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582840 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172841 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522842 historyBackListCount() < 1 &&
2843 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172844 // The parent page must have set the child's window.opener to null before
2845 // redirecting to the desired URL.
2846 frame->opener() == NULL &&
2847 // Must be a top-level frame.
2848 frame->parent() == NULL &&
2849 // Must not have issued the request from this page.
2850 is_content_initiated &&
2851 // Must be targeted at the current tab.
2852 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2853 // Must be a JavaScript navigation, which appears as "other".
2854 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462855
[email protected]f92ce2b2012-03-06 18:02:592856 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:172857 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152858 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172859 return WebKit::WebNavigationPolicyIgnore;
2860 }
2861
2862 return default_policy;
2863}
2864
[email protected]310ebd6302011-10-10 19:06:282865bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492866 WebFrame* frame, const WebURLRequest& request) {
2867 // We allow WebKit to think that everything can be handled even though
2868 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342869 return true;
2870}
2871
[email protected]310ebd6302011-10-10 19:06:282872WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492873 WebFrame* frame, const WebURLRequest& request) {
2874 NOTREACHED(); // Since we said we can handle all requests.
2875 return WebURLError();
2876}
2877
[email protected]310ebd6302011-10-10 19:06:282878WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492879 WebFrame* frame, const WebURLRequest& request) {
2880 WebURLError error;
2881 error.domain = WebString::fromUTF8(net::kErrorDomain);
2882 error.reason = net::ERR_ABORTED;
2883 error.unreachableURL = request.url();
2884 return error;
[email protected]7b7a7dc2009-10-19 02:23:342885}
2886
[email protected]310ebd6302011-10-10 19:06:282887void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492888 WebFrame*, const WebURLError&) {
2889 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342890}
2891
[email protected]310ebd6302011-10-10 19:06:282892void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432893 const WebKit::WebFormElement& form) {
2894 // Some login forms have onSubmit handlers that put a hash of the password
2895 // into a hidden field and then clear the password. (Issue 28910.)
2896 // This method gets called before any of those handlers run, so save away
2897 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072898 DocumentState* document_state =
2899 DocumentState::FromDataSource(frame->dataSource());
[email protected]e9ff79c2012-10-19 21:31:262900 document_state->set_password_form_data(CreatePasswordForm(form));
[email protected]90eeddb2010-05-06 21:06:432901}
2902
[email protected]310ebd6302011-10-10 19:06:282903void RenderViewImpl::willSubmitForm(WebFrame* frame,
2904 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072905 DocumentState* document_state =
2906 DocumentState::FromDataSource(frame->provisionalDataSource());
2907 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172908
[email protected]e9ff79c2012-10-19 21:31:262909 if (navigation_state->transition_type() == PAGE_TRANSITION_LINK)
2910 navigation_state->set_transition_type(PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172911
2912 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352913 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072914 document_state->set_searchable_form_url(web_searchable_form_data.url());
2915 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212916 web_searchable_form_data.encoding().utf8());
[email protected]a045f4e32012-08-31 09:36:072917 scoped_ptr<PasswordForm> password_form_data =
[email protected]e9ff79c2012-10-19 21:31:262918 CreatePasswordForm(form);
[email protected]90eeddb2010-05-06 21:06:432919
[email protected]098c95cb2011-04-28 16:49:012920 // In order to save the password that the user actually typed and not one
2921 // that may have gotten transformed by the site prior to submit, recover it
2922 // from the form contents already stored by |willSendSubmitEvent| into the
2923 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2924 // which is what we're storing into now.)
[email protected]a045f4e32012-08-31 09:36:072925 if (password_form_data.get()) {
[email protected]007733c2011-11-17 00:34:072926 DocumentState* old_document_state =
2927 DocumentState::FromDataSource(frame->dataSource());
2928 if (old_document_state) {
2929 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432930 if (old_form_data && old_form_data->action == password_form_data->action)
2931 password_form_data->password_value = old_form_data->password_value;
2932 }
2933 }
[email protected]3d9689372009-09-10 04:29:172934
[email protected]a045f4e32012-08-31 09:36:072935 document_state->set_password_form_data(password_form_data.Pass());
2936
[email protected]2a5b1732011-04-01 23:55:552937 FOR_EACH_OBSERVER(
2938 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172939}
2940
[email protected]310ebd6302011-10-10 19:06:282941void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172942 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2943 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382944 FOR_EACH_OBSERVER(
2945 RenderViewObserver, observers_,
2946 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172947}
2948
[email protected]310ebd6302011-10-10 19:06:282949void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382950 FOR_EACH_OBSERVER(
2951 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172952}
2953
[email protected]310ebd6302011-10-10 19:06:282954void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172955 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152956 if (!frame->parent()) {
2957 WebDataSource* ds = frame->provisionalDataSource();
2958 // If there's no provisional data source, it's a reference fragment
2959 // navigation.
2960 completed_client_redirect_src_ = Referrer(
[email protected]ca662822012-05-11 17:53:592961 from, ds ? GetReferrerPolicyFromRequest(frame, ds->request()) :
[email protected]f36f4092012-05-09 18:31:042962 frame->document().referrerPolicy());
[email protected]445e1042011-12-03 21:03:152963 }
[email protected]eb0bff942011-04-07 22:08:382964 FOR_EACH_OBSERVER(
2965 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172966}
2967
[email protected]310ebd6302011-10-10 19:06:282968void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:572969 bool content_initiated = !pending_navigation_params_.get();
2970
[email protected]007733c2011-11-17 00:34:072971 DocumentState* document_state = DocumentState::FromDataSource(ds);
2972 if (!document_state) {
2973 document_state = new DocumentState;
2974 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:572975 if (!content_initiated)
2976 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:072977 }
2978
[email protected]bf70edce2012-06-20 22:32:222979 // Carry over the user agent override flag, if it exists.
2980 if (content_initiated && webview() && webview()->mainFrame() &&
2981 webview()->mainFrame()->dataSource()) {
2982 DocumentState* old_document_state =
2983 DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
2984 if (old_document_state) {
2985 document_state->set_is_overriding_user_agent(
2986 old_document_state->is_overriding_user_agent());
2987 }
2988 }
2989
[email protected]3d9689372009-09-10 04:29:172990 // The rest of RenderView assumes that a WebDataSource will always have a
2991 // non-null NavigationState.
[email protected]e1ed5a12012-08-08 19:57:442992 if (content_initiated) {
[email protected]007733c2011-11-17 00:34:072993 document_state->set_navigation_state(
2994 NavigationState::CreateContentInitiated());
[email protected]e1ed5a12012-08-08 19:57:442995 } else {
[email protected]45d83a12012-04-06 22:57:572996 document_state->set_navigation_state(CreateNavigationStateFromPending());
2997 pending_navigation_params_.reset();
2998 }
[email protected]8a3125a712010-08-09 18:58:512999
[email protected]007733c2011-11-17 00:34:073000 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:513001 // navigating from a page that used prefetching using a link on that
3002 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:073003 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:513004 // this value appropriately.
3005 // TODO(gavinp): catch the important case of navigation in a new
3006 // renderer process.
3007 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303008 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523009 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513010 const GURL referrer(
3011 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3012 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:073013 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:513014 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:413015 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:513016 WebDataSource* old_frame_ds = old_frame->dataSource();
3017 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:073018 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513019 break;
3020 }
3021 }
3022 }
3023 }
3024 }
3025
[email protected]4c1b6f0b2010-02-07 16:38:183026 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523027 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513028 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183029 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:073030 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:183031 break;
3032 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:073033 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:183034 break;
3035 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:073036 document_state->set_load_type(
3037 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:183038 break;
3039 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:073040 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:183041 break;
3042 }
3043 }
[email protected]fa7b6b542009-11-03 05:02:303044
[email protected]946a0032011-03-31 18:42:283045 FOR_EACH_OBSERVER(
3046 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:173047}
3048
[email protected]45d83a12012-04-06 22:57:573049void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:073050 DocumentState* document_state) {
3051 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:573052 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:073053
[email protected]45d83a12012-04-06 22:57:573054 if (!params.url.SchemeIs(chrome::kJavaScriptScheme) &&
3055 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
3056 // We're doing a load of a page that was restored from the last session. By
3057 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
3058 // can result in stale data for pages that are set to expire. We explicitly
3059 // override that by setting the policy here so that as necessary we load
3060 // from the network.
3061 document_state->set_cache_policy_override(
3062 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:073063 }
3064
3065 if (IsReload(params))
3066 document_state->set_load_type(DocumentState::RELOAD);
3067 else if (!params.state.empty())
3068 document_state->set_load_type(DocumentState::HISTORY_LOAD);
3069 else
3070 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]ca662822012-05-11 17:53:593071
3072 document_state->set_referrer_policy(params.referrer.policy);
[email protected]bf70edce2012-06-20 22:32:223073 document_state->set_is_overriding_user_agent(params.is_overriding_user_agent);
[email protected]a3a5397d2012-09-12 06:50:343074 document_state->set_must_reset_scroll_and_scale_state(
3075 params.navigation_type ==
3076 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]951a64832012-10-11 16:26:373077 document_state->set_can_load_local_resources(params.can_load_local_resources);
[email protected]45d83a12012-04-06 22:57:573078}
[email protected]007733c2011-11-17 00:34:073079
[email protected]45d83a12012-04-06 22:57:573080NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
3081 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
3082 NavigationState* navigation_state = NULL;
3083
3084 // A navigation resulting from loading a javascript URL should not be treated
3085 // as a browser initiated event. Instead, we want it to look as if the page
3086 // initiated any load resulting from JS execution.
3087 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
3088 navigation_state = NavigationState::CreateBrowserInitiated(
3089 params.page_id,
3090 params.pending_history_list_offset,
3091 params.transition);
3092 navigation_state->set_transferred_request_child_id(
3093 params.transferred_request_child_id);
3094 navigation_state->set_transferred_request_request_id(
3095 params.transferred_request_request_id);
[email protected]80744782012-05-04 01:47:003096 navigation_state->set_allow_download(params.allow_download);
[email protected]45d83a12012-04-06 22:57:573097 } else {
3098 navigation_state = NavigationState::CreateContentInitiated();
3099 }
3100 return navigation_state;
[email protected]007733c2011-11-17 00:34:073101}
3102
[email protected]5b52cd2f712012-03-28 02:12:483103void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
3104 bool enable_viewport =
[email protected]06ea34a2012-05-07 18:52:103105 command_line.HasSwitch(switches::kEnableViewport);
[email protected]5b52cd2f712012-03-28 02:12:483106 bool enable_fixed_layout =
3107 command_line.HasSwitch(switches::kEnableFixedLayout);
3108
3109 webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport);
3110 webview()->settings()->setFixedElementsLayoutRelativeToFrame(true);
3111
3112 if (enable_viewport) {
3113 webview()->settings()->setViewportEnabled(true);
3114 } else if (enable_fixed_layout) {
3115 std::string str =
3116 command_line.GetSwitchValueASCII(switches::kEnableFixedLayout);
3117 std::vector<std::string> tokens;
3118 base::SplitString(str, ',', &tokens);
3119 if (tokens.size() == 2) {
3120 int width, height;
3121 if (base::StringToInt(tokens[0], &width) &&
3122 base::StringToInt(tokens[1], &height))
[email protected]e1ed5a12012-08-08 19:57:443123 webview()->setFixedLayoutSize(WebSize(width, height));
[email protected]5b52cd2f712012-03-28 02:12:483124 }
3125 }
[email protected]1c0c9bc2012-10-08 22:41:483126
3127 ProcessAcceleratedPinchZoomFlags(command_line);
3128}
3129
3130void RenderViewImpl::ProcessAcceleratedPinchZoomFlags(
3131 const CommandLine& command_line) {
3132 bool enable_viewport =
3133 command_line.HasSwitch(switches::kEnableViewport);
3134 bool enable_pinch = enable_viewport ||
3135 command_line.HasSwitch(switches::kEnablePinch);
3136 bool enable_pinch_in_compositor =
[email protected]65bfd9972012-10-19 03:39:373137 command_line.HasSwitch(cc::switches::kEnablePinchInCompositor);
[email protected]1c0c9bc2012-10-08 22:41:483138
3139 if (!enable_pinch &&
3140 webview()->isAcceleratedCompositingActive() &&
3141 webkit_preferences_.apply_default_device_scale_factor_in_compositor &&
3142 device_scale_factor_ != 1) {
3143 // Page scaling is disabled by default when applying a scale factor in the
3144 // compositor since they are currently incompatible.
3145 webview()->setPageScaleFactorLimits(1, 1);
3146 }
3147
3148 if (enable_pinch_in_compositor &&
3149 webview()->isAcceleratedCompositingActive())
3150 webview()->setPageScaleFactorLimits(1, 4);
[email protected]5b52cd2f712012-03-28 02:12:483151}
3152
[email protected]310ebd6302011-10-10 19:06:283153void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173154 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:073155 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:173156
[email protected]3d9689372009-09-10 04:29:173157 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:073158 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:173159 double event_time = ds->triggeringEventTime();
3160 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:073161 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:173162 }
3163
[email protected]05c8e502010-08-15 15:13:523164 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:073165 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:523166
[email protected]3d9689372009-09-10 04:29:173167 bool is_top_most = !frame->parent();
3168 if (is_top_most) {
3169 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133170 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173171
3172 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:153173 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173174 } else if (frame->parent()->isLoading()) {
3175 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003176 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:073177 document_state->navigation_state()->set_transition_type(
[email protected]e9ff79c2012-10-19 21:31:263178 PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:173179 }
3180
[email protected]28685da92011-02-07 21:49:173181 FOR_EACH_OBSERVER(
3182 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
3183
[email protected]3d9689372009-09-10 04:29:173184 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]d37c33e2012-10-12 13:35:133185 routing_id_, frame->identifier(),
3186 frame->parent() ? frame->parent()->identifier() : -1,
3187 is_top_most, GetOpenerUrl(), ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173188}
3189
[email protected]400992b2012-06-14 00:03:543190void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
3191 WebFrame* frame) {
3192 if (frame->parent())
3193 return;
3194 // Received a redirect on the main frame.
3195 WebDataSource* data_source = frame->provisionalDataSource();
3196 if (!data_source) {
3197 // Should only be invoked when we have a data source.
3198 NOTREACHED();
3199 return;
3200 }
3201 std::vector<GURL> redirects;
3202 GetRedirectChain(data_source, &redirects);
3203 if (redirects.size() >= 2) {
3204 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
3205 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
3206 }
3207}
3208
[email protected]310ebd6302011-10-10 19:06:283209void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
3210 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173211 // Notify the browser that we failed a provisional load with an error.
3212 //
3213 // Note: It is important this notification occur before DidStopLoading so the
3214 // SSL manager can react to the provisional load failure before being
3215 // notified the load stopped.
3216 //
3217 WebDataSource* ds = frame->provisionalDataSource();
3218 DCHECK(ds);
3219
3220 const WebURLRequest& failed_request = ds->request();
3221
[email protected]28685da92011-02-07 21:49:173222 FOR_EACH_OBSERVER(
3223 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
3224
[email protected]3d9689372009-09-10 04:29:173225 bool show_repost_interstitial =
3226 (error.reason == net::ERR_CACHE_MISS &&
3227 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:583228
3229 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
3230 params.frame_id = frame->identifier();
3231 params.is_main_frame = !frame->parent();
3232 params.error_code = error.reason;
[email protected]e9ff79c2012-10-19 21:31:263233 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]d7b175e2011-10-11 15:31:583234 failed_request,
3235 error,
3236 NULL,
3237 &params.error_description);
3238 params.url = error.unreachableURL;
3239 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:173240 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:583241 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:173242
3243 // Don't display an error page if this is simply a cancelled load. Aside
3244 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3245 if (error.reason == net::ERR_ABORTED)
3246 return;
3247
3248 // Make sure we never show errors in view source mode.
3249 frame->enableViewSourceMode(false);
3250
[email protected]007733c2011-11-17 00:34:073251 DocumentState* document_state = DocumentState::FromDataSource(ds);
3252 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173253
3254 // If this is a failed back/forward/reload navigation, then we need to do a
3255 // 'replace' load. This is necessary to avoid messing up session history.
3256 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3257 // as session history is concerned.
3258 //
3259 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3260 // the page id.
3261 //
3262 bool replace =
3263 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:583264 navigation_state->transition_type() ==
[email protected]e9ff79c2012-10-19 21:31:263265 PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:173266
3267 // If we failed on a browser initiated request, then make sure that our error
3268 // page load is regarded as the same browser initiated request.
3269 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:073270 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
3271 pending_navigation_params_->page_id =
3272 navigation_state->pending_page_id();
3273 pending_navigation_params_->pending_history_list_offset =
3274 navigation_state->pending_history_list_offset();
3275 pending_navigation_params_->transition =
3276 navigation_state->transition_type();
3277 pending_navigation_params_->request_time =
3278 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:173279 }
3280
3281 // Provide the user with a more helpful error page?
3282 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3283 return;
3284
3285 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083286 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173287}
3288
[email protected]310ebd6302011-10-10 19:06:283289void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:173290 WebFrame* frame, const char* data, size_t data_len,
3291 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:073292 DocumentState* document_state =
3293 DocumentState::FromDataSource(frame->dataSource());
3294 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:173295}
3296
[email protected]310ebd6302011-10-10 19:06:283297void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
3298 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:073299 DocumentState* document_state =
3300 DocumentState::FromDataSource(frame->dataSource());
3301 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173302
[email protected]007733c2011-11-17 00:34:073303 if (document_state->commit_load_time().is_null())
3304 document_state->set_commit_load_time(Time::Now());
3305
[email protected]a3a5397d2012-09-12 06:50:343306 if (document_state->must_reset_scroll_and_scale_state()) {
[email protected]c38d49c2012-10-24 21:46:573307#if defined(OS_ANDROID) // crbug.com/153907
[email protected]a3a5397d2012-09-12 06:50:343308 webview()->resetScrollAndScaleState();
[email protected]c38d49c2012-10-24 21:46:573309#endif
[email protected]a3a5397d2012-09-12 06:50:343310 document_state->set_must_reset_scroll_and_scale_state(false);
3311 }
3312
[email protected]3d9689372009-09-10 04:29:173313 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203314 // When we perform a new navigation, we need to update the last committed
3315 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173316 UpdateSessionHistory(frame);
3317
3318 // We bump our Page ID to correspond with the new session history entry.
3319 page_id_ = next_page_id_++;
3320
[email protected]e9ff79c2012-10-19 21:31:263321 // Don't update history_page_ids_ (etc) for kSwappedOutURL, since
[email protected]58436a12012-03-21 17:10:263322 // we don't want to forget the entry that was there, and since we will
[email protected]e9ff79c2012-10-19 21:31:263323 // never come back to kSwappedOutURL. Note that we have to call
[email protected]69ddf852012-02-21 23:21:313324 // UpdateSessionHistory and update page_id_ even in this case, so that
3325 // the current entry gets a state update and so that we don't send a
3326 // state update to the wrong entry when we swap back in.
[email protected]e9ff79c2012-10-19 21:31:263327 if (GetLoadingUrl(frame) != GURL(kSwappedOutURL)) {
[email protected]69ddf852012-02-21 23:21:313328 // Advance our offset in session history, applying the length limit.
3329 // There is now no forward history.
3330 history_list_offset_++;
[email protected]e9ff79c2012-10-19 21:31:263331 if (history_list_offset_ >= kMaxSessionHistoryEntries)
3332 history_list_offset_ = kMaxSessionHistoryEntries - 1;
[email protected]69ddf852012-02-21 23:21:313333 history_list_length_ = history_list_offset_ + 1;
3334 history_page_ids_.resize(history_list_length_, -1);
3335 history_page_ids_[history_list_offset_] = page_id_;
3336 }
[email protected]3d9689372009-09-10 04:29:173337 } else {
3338 // Inspect the navigation_state on this frame to see if the navigation
3339 // corresponds to a session history navigation... Note: |frame| may or
3340 // may not be the toplevel frame, but for the case of capturing session
3341 // history, the first committed frame suffices. We keep track of whether
3342 // we've seen this commit before so that only capture session history once
3343 // per navigation.
3344 //
3345 // Note that we need to check if the page ID changed. In the case of a
3346 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3347 // previous URL and the current page ID, which would be wrong.
3348 if (navigation_state->pending_page_id() != -1 &&
3349 navigation_state->pending_page_id() != page_id_ &&
3350 !navigation_state->request_committed()) {
3351 // This is a successful session history navigation!
3352 UpdateSessionHistory(frame);
3353 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003354
3355 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:033356
3357 // If the history list is valid, our list of page IDs should be correct.
3358 DCHECK(history_list_length_ <= 0 ||
3359 history_list_offset_ < 0 ||
3360 history_list_offset_ >= history_list_length_ ||
3361 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:173362 }
3363 }
3364
[email protected]28685da92011-02-07 21:49:173365 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3366 DidCommitProvisionalLoad(frame, is_new_navigation));
3367
[email protected]3d9689372009-09-10 04:29:173368 // Remember that we've already processed this request, so we don't update
3369 // the session history again. We do this regardless of whether this is
3370 // a session history navigation, because if we attempted a session history
3371 // navigation without valid HistoryItem state, WebCore will think it is a
3372 // new navigation.
3373 navigation_state->set_request_committed(true);
3374
3375 UpdateURL(frame);
3376
3377 // If this committed load was initiated by a client redirect, we're
3378 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:153379 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173380
3381 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273382 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]b2d98762012-09-03 17:04:063383
3384 if (!frame->parent()) { // Only for top frames.
3385 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
3386 if (render_thread_impl) { // Can be NULL in tests.
3387 render_thread_impl->histogram_customizer()->
3388 RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(),
3389 g_view_map.Get().size());
3390 }
3391 }
[email protected]3d9689372009-09-10 04:29:173392}
3393
[email protected]310ebd6302011-10-10 19:06:283394void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:103395 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3396 DidClearWindowObject(frame));
3397
[email protected]b6cb3a842011-06-24 18:28:413398 GURL frame_url = frame->document().url();
[email protected]e9ff79c2012-10-19 21:31:263399 if ((enabled_bindings_ & BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:253400 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
3401 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:273402 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:173403 }
[email protected]766a7082012-02-03 23:39:153404
[email protected]e9ff79c2012-10-19 21:31:263405 if (enabled_bindings_ & BINDINGS_POLICY_DOM_AUTOMATION) {
[email protected]766a7082012-02-03 23:39:153406 if (!dom_automation_controller_.get())
3407 dom_automation_controller_.reset(new DomAutomationController());
3408 dom_automation_controller_->set_message_sender(
[email protected]e9ff79c2012-10-19 21:31:263409 static_cast<RenderView*>(this));
[email protected]766a7082012-02-03 23:39:153410 dom_automation_controller_->set_routing_id(routing_id());
3411 dom_automation_controller_->BindToJavascript(frame,
3412 "domAutomationController");
3413 }
[email protected]498bc512012-09-21 21:50:083414
[email protected]e9ff79c2012-10-19 21:31:263415 InjectDoNotTrackBindings(frame);
[email protected]3d9689372009-09-10 04:29:173416}
3417
[email protected]310ebd6302011-10-10 19:06:283418void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173419 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:413420 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:253421 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]87717d0e2012-04-26 02:58:433422 if (frame == webview()->mainFrame())
3423 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:173424 }
[email protected]e48869a2011-04-01 19:56:033425
3426 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3427 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:173428}
3429
[email protected]310ebd6302011-10-10 19:06:283430void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
3431 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:463432 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:173433
3434 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273435 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173436}
3437
[email protected]310ebd6302011-10-10 19:06:283438void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:133439 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3440 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:583441}
3442
[email protected]310ebd6302011-10-10 19:06:283443void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173444 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073445 DocumentState* document_state = DocumentState::FromDataSource(ds);
3446 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:173447
[email protected]622474d2010-11-04 09:21:083448 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173449
[email protected]28685da92011-02-07 21:49:173450 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3451 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173452
3453 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273454 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173455}
3456
[email protected]310ebd6302011-10-10 19:06:283457void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083458 if (webview()->mainFrame() == frame) {
3459 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3460 page_id_));
3461 }
[email protected]3d9689372009-09-10 04:29:173462}
3463
[email protected]310ebd6302011-10-10 19:06:283464void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:313465 WebDataSource* ds = frame->dataSource();
3466 DCHECK(ds);
3467
3468
[email protected]28685da92011-02-07 21:49:173469 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:313470
3471 const WebURLRequest& failed_request = ds->request();
3472 string16 error_description;
[email protected]e9ff79c2012-10-19 21:31:263473 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]1a55c5be2011-11-29 11:36:313474 failed_request,
3475 error,
3476 NULL,
3477 &error_description);
3478 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
3479 frame->identifier(),
3480 failed_request.url(),
3481 !frame->parent(),
3482 error.reason,
3483 error_description));
[email protected]3d9689372009-09-10 04:29:173484}
3485
[email protected]310ebd6302011-10-10 19:06:283486void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173487 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073488 DocumentState* document_state = DocumentState::FromDataSource(ds);
3489 if (document_state->finish_load_time().is_null())
3490 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:413491
[email protected]676126f72011-01-15 00:03:513492 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173493
[email protected]1a55c5be2011-11-29 11:36:313494 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
3495 frame->identifier(),
3496 ds->request().url(),
3497 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:173498}
3499
[email protected]310ebd6302011-10-10 19:06:283500void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173501 WebFrame* frame, bool is_new_navigation) {
3502 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:073503 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:173504 // update the ExtraData on the datasource so that others who read the
3505 // ExtraData will get the new NavigationState. Similarly, if we did not
3506 // initiate this navigation, then we need to take care to reset any pre-
3507 // existing navigation state to a content-initiated navigation state.
3508 // DidCreateDataSource conveniently takes care of this for us.
3509 didCreateDataSource(frame, frame->dataSource());
3510
[email protected]007733c2011-11-17 00:34:073511 DocumentState* document_state =
3512 DocumentState::FromDataSource(frame->dataSource());
3513 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:093514 new_state->set_was_within_same_page(true);
3515
[email protected]3d9689372009-09-10 04:29:173516 didCommitProvisionalLoad(frame, is_new_navigation);
3517
[email protected]750fcf872011-08-03 23:10:473518 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
3519 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:173520}
3521
[email protected]310ebd6302011-10-10 19:06:283522void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313523 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593524}
3525
[email protected]310ebd6302011-10-10 19:06:283526void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:173527 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3528 // Ignore
3529}
3530
[email protected]310ebd6302011-10-10 19:06:283531void RenderViewImpl::willSendRequest(WebFrame* frame,
3532 unsigned identifier,
3533 WebURLRequest& request,
3534 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303535 WebFrame* top_frame = frame->top();
3536 if (!top_frame)
3537 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513538 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3539 WebDataSource* top_data_source = top_frame->dataSource();
3540 WebDataSource* data_source =
3541 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:223542
[email protected]e9ff79c2012-10-19 21:31:263543 PageTransition transition_type = PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:073544 DocumentState* document_state = DocumentState::FromDataSource(data_source);
[email protected]def55e022012-07-26 01:15:293545 DCHECK(document_state);
[email protected]007733c2011-11-17 00:34:073546 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e1ed5a12012-08-08 19:57:443547 transition_type = navigation_state->transition_type();
3548
3549 GURL request_url(request.url());
3550 GURL new_url;
[email protected]e9ff79c2012-10-19 21:31:263551 if (GetContentClient()->renderer()->WillSendRequest(
[email protected]e1ed5a12012-08-08 19:57:443552 frame, transition_type, request_url, &new_url)) {
3553 request.setURL(WebURL(new_url));
3554 }
3555
[email protected]def55e022012-07-26 01:15:293556 if (document_state->is_cache_policy_override_set())
3557 request.setCachePolicy(document_state->cache_policy_override());
[email protected]8a3125a712010-08-09 18:58:513558
[email protected]ca662822012-05-11 17:53:593559 WebKit::WebReferrerPolicy referrer_policy;
3560 if (document_state && document_state->is_referrer_policy_set()) {
3561 referrer_policy = document_state->referrer_policy();
3562 document_state->clear_referrer_policy();
3563 } else {
3564 referrer_policy = frame->document().referrerPolicy();
3565 }
3566
[email protected]e372f3d2012-07-17 19:16:443567 // The request's extra data may indicate that we should set a custom user
3568 // agent. This needs to be done here, after WebKit is through with setting the
3569 // user agent on its own.
3570 WebString custom_user_agent;
3571 if (request.extraData()) {
3572 webkit_glue::WebURLRequestExtraDataImpl* old_extra_data =
3573 static_cast<webkit_glue::WebURLRequestExtraDataImpl*>(
3574 request.extraData());
3575 custom_user_agent = old_extra_data->custom_user_agent();
3576
3577 if (!custom_user_agent.isNull()) {
3578 if (custom_user_agent.isEmpty())
3579 request.clearHTTPHeaderField("User-Agent");
3580 else
3581 request.setHTTPHeaderField("User-Agent", custom_user_agent);
3582 }
3583 }
3584
[email protected]91043a8232011-11-04 16:41:193585 request.setExtraData(
[email protected]ca662822012-05-11 17:53:593586 new RequestExtraData(referrer_policy,
[email protected]e372f3d2012-07-17 19:16:443587 custom_user_agent,
[email protected]537fbe02011-11-24 00:58:063588 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:193589 frame->identifier(),
3590 frame->parent() == top_frame,
3591 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]80744782012-05-04 01:47:003592 navigation_state->allow_download(),
[email protected]4ad5d77d2011-12-03 02:00:483593 transition_type,
3594 navigation_state->transferred_request_child_id(),
3595 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:573596
[email protected]007733c2011-11-17 00:34:073597 DocumentState* top_document_state =
3598 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:573599 // TODO(gavinp): separate out prefetching and prerender field trials
3600 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:073601 if (top_document_state &&
[email protected]925dec1c2012-05-18 05:09:003602 request.targetType() == WebURLRequest::TargetIsPrefetch)
[email protected]007733c2011-11-17 00:34:073603 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513604
[email protected]3d9689372009-09-10 04:29:173605 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133606 request.setHasUserGesture(frame->isProcessingUserGesture());
3607
[email protected]0a8db0d2011-04-13 15:15:403608 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:133609 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:173610}
3611
[email protected]310ebd6302011-10-10 19:06:283612void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173613 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493614
[email protected]3d9689372009-09-10 04:29:173615 // Only do this for responses that correspond to a provisional data source
3616 // of the top-most frame. If we have a provisional data source, then we
3617 // can't have any sub-resources yet, so we know that this response must
3618 // correspond to a frame load.
3619 if (!frame->provisionalDataSource() || frame->parent())
3620 return;
3621
3622 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083623 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173624 if (frame->isViewSourceModeEnabled())
3625 return;
3626
[email protected]007733c2011-11-17 00:34:073627 DocumentState* document_state =
3628 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083629 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533630
[email protected]972ebdff2010-06-10 22:59:073631 // Record page load flags.
[email protected]007733c2011-11-17 00:34:073632 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3633 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]b9fd01ba2012-02-28 01:50:403634 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
3635 if (extra_data) {
3636 document_state->set_npn_negotiated_protocol(
3637 extra_data->npn_negotiated_protocol());
3638 }
[email protected]007733c2011-11-17 00:34:073639 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:573640 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:073641 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3642 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093643 // Whether or not the http status code actually corresponds to an error is
3644 // only checked when the page is done loading, if |use_error_page| is
3645 // still true.
[email protected]007733c2011-11-17 00:34:073646 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173647}
3648
[email protected]310ebd6302011-10-10 19:06:283649void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173650 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:073651 DocumentState* document_state =
3652 DocumentState::FromDataSource(frame->dataSource());
3653 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173654 return;
3655
[email protected]7bfc153f2011-09-23 22:00:203656 // Do not show error page when DevTools is attached.
3657 if (devtools_agent_->IsAttached())
3658 return;
3659
[email protected]06333afe2011-02-24 14:55:093660 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:073661 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:083662 if (http_status_code == 404) {
3663 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413664 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173665
[email protected]b6cb3a842011-06-24 18:28:413666 const GURL& error_page_url =
3667 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093668 if (error_page_url.is_valid()) {
3669 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473670 original_error.domain = "http";
3671 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413672 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173673
[email protected]007733c2011-11-17 00:34:073674 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093675 new AltErrorPageResourceFetcher(
3676 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:083677 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3678 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093679 return;
3680 }
3681 }
[email protected]3d9689372009-09-10 04:29:173682
[email protected]e6a2ce52011-10-08 01:40:133683 std::string error_domain;
[email protected]e9ff79c2012-10-19 21:31:263684 if (GetContentClient()->renderer()->HasErrorPage(
[email protected]e6a2ce52011-10-08 01:40:133685 http_status_code, &error_domain)) {
3686 WebURLError error;
3687 error.unreachableURL = frame->document().url();
3688 error.domain = WebString::fromUTF8(error_domain);
3689 error.reason = http_status_code;
3690
3691 LoadNavigationErrorPage(
3692 frame, frame->dataSource()->request(), error, std::string(), true);
3693 }
[email protected]3d9689372009-09-10 04:29:173694}
3695
[email protected]310ebd6302011-10-10 19:06:283696void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173697 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3698 // Ignore
3699}
3700
[email protected]310ebd6302011-10-10 19:06:283701void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173702 WebFrame* frame, const WebURLRequest& request,
3703 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003704 // The recipients of this message have no use for data: URLs: they don't
3705 // affect the page's insecure content list and are not in the disk cache. To
3706 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3707 // filter them out here.
3708 GURL url(request.url());
3709 if (url.SchemeIs("data"))
3710 return;
3711
[email protected]3d9689372009-09-10 04:29:173712 // Let the browser know we loaded a resource from the memory cache. This
3713 // message is needed to display the correct SSL indicators.
3714 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3715 routing_id_,
[email protected]84703292011-10-28 20:44:003716 url,
[email protected]70435962011-08-02 20:13:283717 response.securityInfo(),
3718 request.httpMethod().utf8(),
[email protected]6d6cfb3a2012-05-23 22:53:183719 response.mimeType().utf8(),
[email protected]70435962011-08-02 20:13:283720 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173721}
3722
[email protected]310ebd6302011-10-10 19:06:283723void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293724 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3725}
3726
[email protected]310ebd6302011-10-10 19:06:283727void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023728 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293729 Send(new ViewHostMsg_DidRunInsecureContent(
3730 routing_id_,
[email protected]92771112011-01-20 00:13:023731 origin.toString().utf8(),
3732 target));
[email protected]e3d60e5d2009-09-25 21:08:293733}
3734
[email protected]310ebd6302011-10-10 19:06:283735void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173736 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3737}
3738
[email protected]310ebd6302011-10-10 19:06:283739void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3740 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583741 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283742 int world_id) {
[email protected]e9ff79c2012-10-19 21:31:263743 GetContentClient()->renderer()->DidCreateScriptContext(
[email protected]a00fe692012-02-27 05:52:583744 frame, context, extension_group, world_id);
[email protected]7a137c9d2012-10-16 20:41:203745
3746 intents_host_->DidCreateScriptContext(
3747 frame, context, extension_group, world_id);
[email protected]a00fe692012-02-27 05:52:583748}
3749
[email protected]310ebd6302011-10-10 19:06:283750void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3751 v8::Handle<v8::Context> context,
3752 int world_id) {
[email protected]e9ff79c2012-10-19 21:31:263753 GetContentClient()->renderer()->WillReleaseScriptContext(
[email protected]5bc10932011-09-21 21:03:303754 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283755}
3756
[email protected]310ebd6302011-10-10 19:06:283757void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073758 // We don't always want to send the change messages over IPC, only if we've
3759 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3760 // message.
3761 if (!send_preferred_size_changes_ || !webview())
3762 return;
3763
[email protected]705243f2010-05-05 19:58:073764 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3765 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533766
3767 // In the presence of zoom, these sizes are still reported as if unzoomed,
3768 // so we need to adjust.
3769 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3770 size.set_width(static_cast<int>(size.width() * zoom_factor));
3771 size.set_height(static_cast<int>(size.height() * zoom_factor));
3772
[email protected]705243f2010-05-05 19:58:073773 if (size == preferred_size_)
3774 return;
[email protected]c27324b2009-11-19 22:44:293775
[email protected]705243f2010-05-05 19:58:073776 preferred_size_ = size;
3777 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3778 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173779}
3780
[email protected]1842fe22012-08-13 23:24:353781WebGraphicsContext3D* RenderViewImpl::CreateGraphicsContext3D(
3782 const WebGraphicsContext3D::Attributes& attributes) {
3783 if (!webview())
3784 return NULL;
3785
[email protected]1842fe22012-08-13 23:24:353786 // The WebGraphicsContext3DInProcessImpl code path is used for
3787 // layout tests (though not through this code) as well as for
3788 // debugging and bringing up new ports.
3789 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
3790 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
3791 attributes, true);
3792 } else {
3793 GURL url;
3794 if (webview()->mainFrame())
3795 url = GURL(webview()->mainFrame()->document().url());
3796 else
[email protected]f89e173a2012-08-24 01:12:263797 url = GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]1842fe22012-08-13 23:24:353798
3799 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
3800 new WebGraphicsContext3DCommandBufferImpl(
3801 surface_id(),
3802 url,
3803 RenderThreadImpl::current(),
3804 AsWeakPtr()));
3805
3806 if (!context->Initialize(
3807 attributes,
3808 false /* bind generates resources */,
[email protected]e9ff79c2012-10-19 21:31:263809 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
[email protected]1842fe22012-08-13 23:24:353810 return NULL;
3811 return context.release();
3812 }
3813}
3814
[email protected]0720b532012-08-28 19:23:373815// The browser process needs to know the shape of the tree, as well as the names
3816// and ids of all frames. This allows it to properly route JavaScript messages
3817// across processes and frames. The serialization format is described in the
3818// comments of the ViewMsg_FrameTreeUpdated message.
3819// This function sends those updates to the browser and updates the RVH
3820// corresponding to this object. It must be called on any events that modify
3821// the tree structure or the names of any frames.
3822void RenderViewImpl::SendUpdatedFrameTree(
3823 WebKit::WebFrame* exclude_frame_subtree) {
[email protected]e12dbe6f2012-10-04 22:11:193824 // TODO(nasko): Frame tree updates are causing issues with postMessage, as
3825 // described in http://crbug.com/153701. Disable them until a proper fix is
3826 // in place.
[email protected]0720b532012-08-28 19:23:373827}
3828
3829void RenderViewImpl::CreateFrameTree(WebKit::WebFrame* frame,
3830 DictionaryValue* frame_tree) {
[email protected]e12dbe6f2012-10-04 22:11:193831 // TODO(nasko): Remove once http://crbug.com/153701 is fixed.
3832 DCHECK(false);
[email protected]0720b532012-08-28 19:23:373833 NavigateToSwappedOutURL(frame);
3834
3835 string16 name;
[email protected]e9ff79c2012-10-19 21:31:263836 if (frame_tree->GetString(kFrameTreeNodeNameKey, &name) && !name.empty())
[email protected]0720b532012-08-28 19:23:373837 frame->setName(name);
[email protected]0720b532012-08-28 19:23:373838
3839 int remote_id;
[email protected]e9ff79c2012-10-19 21:31:263840 if (frame_tree->GetInteger(kFrameTreeNodeIdKey, &remote_id))
[email protected]0720b532012-08-28 19:23:373841 active_frame_id_map_.insert(std::pair<int, int>(frame->identifier(),
3842 remote_id));
3843
3844 ListValue* children;
[email protected]e9ff79c2012-10-19 21:31:263845 if (!frame_tree->GetList(kFrameTreeNodeSubtreeKey, &children))
[email protected]0720b532012-08-28 19:23:373846 return;
3847
[email protected]5fa9b36b2012-09-21 18:14:273848 // Create an invisible iframe tree in the swapped out page.
[email protected]0720b532012-08-28 19:23:373849 base::DictionaryValue* child;
3850 for (size_t i = 0; i < children->GetSize(); ++i) {
3851 if (!children->GetDictionary(i, &child))
3852 continue;
3853 WebElement element = frame->document().createElement("iframe");
[email protected]5fa9b36b2012-09-21 18:14:273854 element.setAttribute("width", "0");
3855 element.setAttribute("height", "0");
3856 element.setAttribute("frameBorder", "0");
[email protected]0720b532012-08-28 19:23:373857 if (frame->document().body().appendChild(element)) {
3858 WebFrame* subframe = WebFrame::fromFrameOwnerElement(element);
3859 if (subframe)
3860 CreateFrameTree(subframe, child);
3861 } else {
3862 LOG(ERROR) << "Failed to append created iframe element.";
3863 }
3864 }
3865}
3866
[email protected]d1a59e42012-10-03 18:05:353867WebKit::WebFrame* RenderViewImpl::GetFrameByRemoteID(int remote_frame_id) {
3868 std::map<int, int>::const_iterator it = active_frame_id_map_.begin();
3869 for (; it != active_frame_id_map_.end(); ++it) {
3870 if (it->second == remote_frame_id)
3871 return FindFrameByID(webview()->mainFrame(), it->first);
3872 }
3873 return NULL;
[email protected]0720b532012-08-28 19:23:373874}
3875
[email protected]273558fb2012-01-12 15:03:513876void RenderViewImpl::EnsureMediaStreamImpl() {
[email protected]7082fb942012-05-16 23:44:593877 if (!RenderThreadImpl::current()) // Will be NULL during unit tests.
[email protected]08381562012-05-15 20:55:403878 return;
3879
[email protected]4fb0f202012-05-30 22:44:533880#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:513881 if (!media_stream_dispatcher_)
3882 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3883
[email protected]1bc65a42012-04-23 09:31:253884 if (!media_stream_impl_) {
[email protected]273558fb2012-01-12 15:03:513885 media_stream_impl_ = new MediaStreamImpl(
[email protected]1bc65a42012-04-23 09:31:253886 this,
[email protected]273558fb2012-01-12 15:03:513887 media_stream_dispatcher_,
[email protected]273558fb2012-01-12 15:03:513888 RenderThreadImpl::current()->video_capture_impl_manager(),
[email protected]6ee10bd2012-09-13 09:01:533889 RenderThreadImpl::current()->GetMediaStreamDependencyFactory());
[email protected]273558fb2012-01-12 15:03:513890 }
[email protected]5b87e782012-02-09 18:19:323891#endif
[email protected]273558fb2012-01-12 15:03:513892}
3893
[email protected]310ebd6302011-10-10 19:06:283894void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3895 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313896 if (webview()->mainFrame() != frame)
3897 return;
3898 WebView* frameView = frame->view();
3899 if (!frameView)
3900 return;
3901
3902 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3903 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3904
3905 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3906 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3907 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3908 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3909
3910 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3911 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3912 }
3913}
3914
[email protected]310ebd6302011-10-10 19:06:283915void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313916 WebSize offset = frame->scrollOffset();
3917 WebSize minimum_offset = frame->minimumScrollOffset();
3918 WebSize maximum_offset = frame->maximumScrollOffset();
3919
3920 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3921 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3922
3923 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3924 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3925 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3926 routing_id_, is_pinned_to_left, is_pinned_to_right));
3927
3928 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3929 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3930 }
3931}
3932
[email protected]310ebd6302011-10-10 19:06:283933void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493934 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313935
3936 if (webview()->mainFrame() == frame)
3937 UpdateScrollState(frame);
[email protected]2b942c332012-04-25 16:26:263938
3939 FOR_EACH_OBSERVER(
3940 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]dd6afca2011-08-13 03:44:313941}
3942
[email protected]4d0f8182012-10-19 23:14:473943#if defined(OS_ANDROID)
3944void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebFrame* frame) {
3945 if (frame != webview()->mainFrame())
3946 return;
3947
3948 // Update body background color if necessary.
3949 SkColor bg_color = webwidget_->backgroundColor();
3950
3951 // If not initialized, default to white. Note that 0 is different from black
3952 // as black still has alpha 0xFF.
3953 if (!bg_color)
3954 bg_color = SK_ColorWHITE;
3955
3956 if (bg_color != body_background_color_) {
3957 body_background_color_ = bg_color;
3958 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id_, bg_color));
3959 }
3960}
3961#endif
3962
[email protected]55750b32012-09-21 14:05:033963void RenderViewImpl::SendFindReply(int request_id,
3964 int match_count,
3965 int ordinal,
3966 const WebRect& selection_rect,
3967 bool final_status_update) {
3968#if defined(OS_ANDROID)
3969 if (synchronous_find_reply_message_.get()) {
3970 if (final_status_update) {
3971 ViewMsg_SynchronousFind::WriteReplyParams(
3972 synchronous_find_reply_message_.get(),
3973 match_count,
3974 match_count ? synchronous_find_active_match_ordinal_ : 0);
3975 Send(synchronous_find_reply_message_.release());
3976 }
3977 return;
3978 }
3979#endif
3980
3981 Send(new ViewHostMsg_Find_Reply(routing_id_,
3982 request_id,
3983 match_count,
3984 selection_rect,
3985 ordinal,
3986 final_status_update));
3987}
3988
3989void RenderViewImpl::reportFindInPageMatchCount(int request_id,
3990 int count,
[email protected]310ebd6302011-10-10 19:06:283991 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113992 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3993 if (!count)
3994 active_match_ordinal = 0;
3995
[email protected]55750b32012-09-21 14:05:033996 // Send the search result over to the browser process.
3997 SendFindReply(request_id,
3998 count,
3999 active_match_ordinal,
4000 gfx::Rect(),
4001 final_update);
[email protected]8922e1f2009-10-03 05:01:264002}
4003
[email protected]310ebd6302011-10-10 19:06:284004void RenderViewImpl::reportFindInPageSelection(int request_id,
4005 int active_match_ordinal,
4006 const WebRect& selection_rect) {
[email protected]55750b32012-09-21 14:05:034007#if defined(OS_ANDROID)
4008 // If this was a SynchronousFind request, we need to remember the ordinal
4009 // value here for replying when reportFindInPageMatchCount is called.
4010 if (synchronous_find_reply_message_.get()) {
4011 synchronous_find_active_match_ordinal_ = active_match_ordinal;
4012 return;
4013 }
4014#endif
4015
4016 SendFindReply(request_id,
4017 -1,
4018 active_match_ordinal,
4019 selection_rect,
4020 false);
[email protected]8922e1f2009-10-03 05:01:264021}
4022
[email protected]310ebd6302011-10-10 19:06:284023void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:224024 WebFrame* frame,
4025 WebFileSystem::Type type,
4026 long long size,
[email protected]d275d7a2010-11-03 01:34:494027 bool create,
[email protected]2b06a992010-08-21 05:48:224028 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:084029 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:224030
[email protected]b6cb3a842011-06-24 18:28:414031 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564032 if (origin.isUnique()) {
4033 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:084034 callbacks->didFail(WebKit::WebFileErrorAbort);
4035 return;
4036 }
[email protected]2b06a992010-08-21 05:48:224037
[email protected]c5a272d2010-09-27 18:37:084038 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
4039 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:494040 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:224041}
4042
[email protected]d5e08552012-08-02 21:43:404043void RenderViewImpl::deleteFileSystem(
4044 WebFrame* frame,
4045 WebFileSystem::Type type ,
4046 WebFileSystemCallbacks* callbacks) {
4047 DCHECK(callbacks);
4048
4049 WebSecurityOrigin origin = frame->document().securityOrigin();
4050 if (origin.isUnique()) {
4051 // Unique origins cannot store persistent state.
4052 callbacks->didSucceed();
4053 return;
4054 }
4055
4056 ChildThread::current()->file_system_dispatcher()->DeleteFileSystem(
4057 GURL(origin.toString()),
4058 static_cast<fileapi::FileSystemType>(type),
4059 new WebFileSystemCallbackDispatcher(callbacks));
4060}
4061
[email protected]310ebd6302011-10-10 19:06:284062void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:404063 WebFrame* frame,
4064 WebStorageQuotaType type,
4065 WebStorageQuotaCallbacks* callbacks) {
4066 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:414067 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564068 if (origin.isUnique()) {
4069 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:404070 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
4071 return;
4072 }
4073 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:534074 GURL(origin.toString()),
4075 static_cast<quota::StorageType>(type),
4076 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:404077}
4078
[email protected]310ebd6302011-10-10 19:06:284079void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:404080 WebFrame* frame,
4081 WebStorageQuotaType type,
4082 unsigned long long requested_size,
4083 WebStorageQuotaCallbacks* callbacks) {
4084 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:414085 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564086 if (origin.isUnique()) {
4087 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:404088 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
4089 return;
4090 }
4091 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:534092 routing_id(), GURL(origin.toString()),
4093 static_cast<quota::StorageType>(type), requested_size,
4094 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:404095}
4096
[email protected]8b5af492011-11-28 21:50:584097void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:154098 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]3a3b75a2012-06-01 08:38:364099 webkit_glue::WebIntentServiceData data(service);
4100 if (data.title.empty())
4101 data.title = webview()->mainFrame()->document().title();
4102 bool user_gesture = frame->isProcessingUserGesture();
[email protected]8b5af492011-11-28 21:50:584103 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
[email protected]3a3b75a2012-06-01 08:38:364104 data,
4105 user_gesture));
[email protected]8b5af492011-11-28 21:50:584106}
4107
[email protected]ffc8bed2012-01-21 01:23:154108void RenderViewImpl::dispatchIntent(
4109 WebFrame* frame, const WebIntentRequest& intentRequest) {
4110 webkit_glue::WebIntentData intent_data(intentRequest.intent());
[email protected]4e1eb3392012-05-18 00:08:054111
4112 // See WebMessagePortChannelImpl::postMessage() and ::OnMessagedQueued()
4113 WebKit::WebMessagePortChannelArray* channels =
4114 intentRequest.intent().messagePortChannelsRelease();
4115 if (channels) {
4116 for (size_t i = 0; i < channels->size(); ++i) {
4117 WebMessagePortChannelImpl* webchannel =
4118 static_cast<WebMessagePortChannelImpl*>((*channels)[i]);
4119 intent_data.message_port_ids.push_back(webchannel->message_port_id());
4120 DCHECK(intent_data.message_port_ids[i] != MSG_ROUTING_NONE);
4121 }
4122 delete channels;
4123 }
4124
[email protected]ffc8bed2012-01-21 01:23:154125 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:584126 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:154127 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:584128}
4129
[email protected]f546640b2012-05-15 00:03:494130bool RenderViewImpl::willCheckAndDispatchMessageEvent(
[email protected]0720b532012-08-28 19:23:374131 WebKit::WebFrame* sourceFrame,
4132 WebKit::WebFrame* targetFrame,
[email protected]f546640b2012-05-15 00:03:494133 WebKit::WebSecurityOrigin target_origin,
4134 WebKit::WebDOMMessageEvent event) {
4135 if (!is_swapped_out_)
4136 return false;
4137
4138 ViewMsg_PostMessage_Params params;
4139 params.data = event.data().toString();
4140 params.source_origin = event.origin();
4141 if (!target_origin.isNull())
4142 params.target_origin = target_origin.toString();
4143
4144 // Include the routing ID for the source frame, which the browser process
4145 // will translate into the routing ID for the equivalent frame in the target
4146 // process.
[email protected]f546640b2012-05-15 00:03:494147 params.source_routing_id = MSG_ROUTING_NONE;
[email protected]0720b532012-08-28 19:23:374148 RenderViewImpl* source_view = FromWebView(sourceFrame->view());
[email protected]f546640b2012-05-15 00:03:494149 if (source_view)
4150 params.source_routing_id = source_view->routing_id();
[email protected]0720b532012-08-28 19:23:374151 params.source_frame_id = sourceFrame->identifier();
4152
4153 // Include the process, route, and frame IDs of the target frame. This allows
4154 // the browser to detect races between this message being sent and the target
4155 // frame no longer being valid.
4156 params.target_process_id = target_process_id_;
4157 params.target_routing_id = target_routing_id_;
4158
4159 std::map<int,int>::iterator it = active_frame_id_map_.find(
4160 targetFrame->identifier());
4161 if (it != active_frame_id_map_.end()) {
4162 params.target_frame_id = it->second;
4163 } else {
4164 params.target_frame_id = 0;
4165 }
[email protected]f546640b2012-05-15 00:03:494166
4167 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params));
4168 return true;
4169}
4170
[email protected]5fa3a062012-03-21 15:39:344171void RenderViewImpl::willOpenSocketStream(
4172 WebSocketStreamHandle* handle) {
4173 SocketStreamHandleData::AddToHandle(handle, routing_id_);
4174}
4175
[email protected]ccee4862012-10-03 18:34:264176void RenderViewImpl::willStartUsingPeerConnectionHandler(
4177 WebKit::WebFrame* frame, WebKit::WebRTCPeerConnectionHandler* handler) {
4178#if defined(ENABLE_WEBRTC)
4179 static_cast<RTCPeerConnectionHandler*>(handler)->associateWithFrame(frame);
4180#endif
4181}
4182
[email protected]bf70edce2012-06-20 22:32:224183WebKit::WebString RenderViewImpl::userAgentOverride(
4184 WebKit::WebFrame* frame,
4185 const WebKit::WebURL& url) {
4186 if (!webview() || !webview()->mainFrame() ||
4187 renderer_preferences_.user_agent_override.empty()) {
4188 return WebKit::WebString();
4189 }
4190
4191 // If we're in the middle of committing a load, the data source we need
4192 // will still be provisional.
4193 WebFrame* main_frame = webview()->mainFrame();
4194 WebDataSource* data_source = NULL;
4195 if (main_frame->provisionalDataSource())
4196 data_source = main_frame->provisionalDataSource();
4197 else
4198 data_source = main_frame->dataSource();
4199
4200 DocumentState* document_state =
4201 data_source ? DocumentState::FromDataSource(data_source) : NULL;
4202 if (document_state && document_state->is_overriding_user_agent())
4203 return WebString::fromUTF8(renderer_preferences_.user_agent_override);
4204 else
4205 return WebKit::WebString();
4206}
4207
[email protected]18d5be92011-07-25 18:00:194208// WebKit::WebPageSerializerClient implementation ------------------------------
4209
[email protected]310ebd6302011-10-10 19:06:284210void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:194211 const WebURL& frame_url,
4212 const WebCString& data,
4213 WebPageSerializerClient::PageSerializationStatus status) {
4214 Send(new ViewHostMsg_SendSerializedHtmlData(
4215 routing_id(),
4216 frame_url,
4217 data.data(),
4218 static_cast<int32>(status)));
4219}
4220
[email protected]e9ff79c2012-10-19 21:31:264221// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:314222
[email protected]310ebd6302011-10-10 19:06:284223bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:314224 return RenderWidget::Send(message);
4225}
4226
[email protected]82114f52012-03-20 22:53:414227int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:314228 return routing_id_;
4229}
4230
[email protected]82114f52012-03-20 22:53:414231int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:314232 return page_id_;
4233}
4234
[email protected]82114f52012-03-20 22:53:414235gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:314236 return size();
4237}
4238
[email protected]82114f52012-03-20 22:53:414239WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:314240 return webkit_preferences_;
4241}
4242
[email protected]82114f52012-03-20 22:53:414243WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:314244 return webview();
4245}
4246
[email protected]82114f52012-03-20 22:53:414247WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:314248 if (!webview())
4249 return WebNode();
4250 WebFrame* focused_frame = webview()->focusedFrame();
4251 if (focused_frame) {
4252 WebDocument doc = focused_frame->document();
4253 if (!doc.isNull())
4254 return doc.focusedNode();
4255 }
4256
4257 return WebNode();
4258}
4259
[email protected]82114f52012-03-20 22:53:414260WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:314261 return context_menu_node_;
4262}
4263
[email protected]2a84f9d2012-06-05 21:50:434264bool RenderViewImpl::IsEditableNode(const WebNode& node) const {
4265 if (node.isNull())
4266 return false;
4267
4268 if (node.isContentEditable())
4269 return true;
4270
4271 if (node.isElementNode()) {
4272 const WebElement& element = node.toConst<WebElement>();
4273 if (element.isTextFormControlElement())
4274 return true;
4275
4276 // Also return true if it has an ARIA role of 'textbox'.
4277 for (unsigned i = 0; i < element.attributeCount(); ++i) {
4278 if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) {
4279 if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox"))
4280 return true;
4281 break;
4282 }
[email protected]a2ef54c2011-10-10 16:20:314283 }
4284 }
[email protected]2a84f9d2012-06-05 21:50:434285
4286 return false;
[email protected]a2ef54c2011-10-10 16:20:314287}
4288
[email protected]310ebd6302011-10-10 19:06:284289WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:314290 WebKit::WebFrame* frame,
4291 const webkit::WebPluginInfo& info,
[email protected]82114f52012-03-20 22:53:414292 const WebKit::WebPluginParams& params) {
[email protected]a2ef54c2011-10-10 16:20:314293 bool pepper_plugin_was_registered = false;
4294 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
4295 pepper_delegate_.CreatePepperPluginModule(info,
4296 &pepper_plugin_was_registered));
4297 if (pepper_plugin_was_registered) {
4298 if (!pepper_module)
4299 return NULL;
4300 return new webkit::ppapi::WebPluginImpl(
4301 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
4302 }
4303
[email protected]3e076a82012-09-11 19:12:364304#if defined(USE_AURA) && !defined(OS_WIN)
[email protected]34b27e442012-01-20 20:07:414305 return NULL;
4306#else
[email protected]a2ef54c2011-10-10 16:20:314307 return new webkit::npapi::WebPluginImpl(
4308 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:414309#endif
[email protected]a2ef54c2011-10-10 16:20:314310}
4311
[email protected]310ebd6302011-10-10 19:06:284312void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
4313 const string16& jscript,
4314 int id,
4315 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:314316 v8::Handle<v8::Value> result;
4317 WebFrame* web_frame = GetChildFrame(frame_xpath);
4318 if (web_frame)
4319 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
4320 if (notify_result) {
4321 ListValue list;
4322 if (!result.IsEmpty() && web_frame) {
4323 v8::HandleScope handle_scope;
4324 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4325 v8::Context::Scope context_scope(context);
4326 V8ValueConverterImpl converter;
[email protected]3de391e82012-05-16 17:50:514327 converter.SetDateAllowed(true);
[email protected]e0658bc2012-09-17 04:05:244328 converter.SetRegExpAllowed(true);
4329 base::Value* result_value = converter.FromV8Value(result, context);
4330 list.Set(0, result_value ? result_value :
4331 base::Value::CreateNullValue());
[email protected]a2ef54c2011-10-10 16:20:314332 } else {
4333 list.Set(0, Value::CreateNullValue());
4334 }
4335 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
4336 }
4337}
4338
[email protected]310ebd6302011-10-10 19:06:284339bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:314340 return (!send_preferred_size_changes_ ||
4341 (disable_scrollbars_size_limit_.width() <= width ||
4342 disable_scrollbars_size_limit_.height() <= height));
4343}
4344
[email protected]82114f52012-03-20 22:53:414345int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:314346 return enabled_bindings_;
4347}
4348
[email protected]82114f52012-03-20 22:53:414349bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:314350 return send_content_state_immediately_;
4351}
4352
[email protected]82114f52012-03-20 22:53:414353float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:314354 return filtered_time_per_frame();
4355}
4356
[email protected]e9ff79c2012-10-19 21:31:264357int RenderViewImpl::ShowContextMenu(ContextMenuClient* client,
4358 const ContextMenuParams& params) {
[email protected]860ee642012-10-13 03:46:254359 DCHECK(client); // A null client means "internal" when we issue callbacks.
[email protected]e9ff79c2012-10-19 21:31:264360 ContextMenuParams our_params(params);
[email protected]860ee642012-10-13 03:46:254361 our_params.custom_context.request_id = pending_context_menus_.Add(client);
4362 Send(new ViewHostMsg_ContextMenu(routing_id_, our_params));
4363 return our_params.custom_context.request_id;
[email protected]a2ef54c2011-10-10 16:20:314364}
4365
[email protected]e0fd0eb2012-10-17 21:11:464366void RenderViewImpl::CancelContextMenu(int request_id) {
4367 DCHECK(pending_context_menus_.Lookup(request_id));
4368 pending_context_menus_.Remove(request_id);
4369}
4370
[email protected]82114f52012-03-20 22:53:414371WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:314372 return visibilityState();
4373}
4374
[email protected]310ebd6302011-10-10 19:06:284375void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
4376 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:314377 return runModalAlertDialog(frame, message);
4378}
4379
[email protected]310ebd6302011-10-10 19:06:284380void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:314381 WebKit::WebFrame* frame,
4382 const WebKit::WebURLRequest& request,
4383 WebKit::WebNavigationPolicy policy) {
4384 loadURLExternally(frame, request, policy);
4385}
4386
4387// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:514388
[email protected]310ebd6302011-10-10 19:06:284389webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:534390 const FilePath& file_path,
4391 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:204392 if (!PluginChannelHost::IsListening()) {
4393 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:594394 return NULL;
[email protected]94752ee2012-02-10 10:38:204395 }
[email protected]f103ab72009-09-02 17:10:594396
[email protected]00c39612010-03-06 02:53:284397 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:464398 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:324399#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]3b21be92012-11-02 06:00:024400 return webkit::npapi::WebPluginDelegateImpl::Create(file_path, mime_type);
[email protected]6876dff2010-01-15 19:38:094401#else
[email protected]7398dcc2011-09-06 21:40:324402 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:224403 NOTIMPLEMENTED();
4404 return NULL;
[email protected]7b6616f2010-01-14 18:07:554405#endif
[email protected]f103ab72009-09-02 17:10:594406 }
4407
[email protected]4e0616e2010-05-28 14:55:534408 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:594409}
4410
[email protected]6ac77cb2012-05-01 14:49:014411WebKit::WebPlugin* RenderViewImpl::CreatePluginReplacement(
4412 const FilePath& file_path) {
[email protected]e9ff79c2012-10-19 21:31:264413 return GetContentClient()->renderer()->CreatePluginReplacement(
[email protected]6ac77cb2012-05-01 14:49:014414 this, file_path);
4415}
4416
[email protected]310ebd6302011-10-10 19:06:284417void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034418#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:274419 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:594420#endif
4421}
4422
[email protected]310ebd6302011-10-10 19:06:284423void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034424#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:274425 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:594426#endif
4427 CleanupWindowInPluginMoves(window);
4428}
4429
[email protected]310ebd6302011-10-10 19:06:284430void RenderViewImpl::DidMovePlugin(
4431 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:594432 SchedulePluginMove(move);
4433}
4434
[email protected]310ebd6302011-10-10 19:06:284435void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:594436 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524437 didStartLoading();
[email protected]f103ab72009-09-02 17:10:594438}
4439
[email protected]310ebd6302011-10-10 19:06:284440void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:594441 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524442 didStopLoading();
[email protected]f103ab72009-09-02 17:10:594443}
4444
[email protected]310ebd6302011-10-10 19:06:284445WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:514446 return &cookie_jar_;
4447}
4448
[email protected]5d65fe92012-06-02 00:48:554449void RenderViewImpl::DidPlay(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074450 Send(new ViewHostMsg_MediaNotification(routing_id_,
4451 reinterpret_cast<int64>(player),
4452 player->hasVideo(),
4453 player->hasAudio(),
4454 true));
4455}
4456
[email protected]5d65fe92012-06-02 00:48:554457void RenderViewImpl::DidPause(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074458 Send(new ViewHostMsg_MediaNotification(routing_id_,
4459 reinterpret_cast<int64>(player),
4460 player->hasVideo(),
4461 player->hasAudio(),
4462 false));
4463}
4464
[email protected]5d65fe92012-06-02 00:48:554465void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074466 DidPause(player);
4467}
4468
[email protected]310ebd6302011-10-10 19:06:284469void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:294470 if (!webview())
4471 return;
4472
[email protected]26aa0482009-09-30 16:55:274473 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:054474 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:294475}
4476
[email protected]310ebd6302011-10-10 19:06:284477void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:364478 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:004479 if (!frame)
4480 return;
[email protected]b781ff282011-08-20 06:19:364481
[email protected]e99ef6f2011-10-16 01:13:004482 string16 text;
4483 size_t offset;
[email protected]3c8c74c2012-03-15 07:34:524484 ui::Range range;
[email protected]e99ef6f2011-10-16 01:13:004485
[email protected]3c8c74c2012-03-15 07:34:524486 if (pepper_delegate_.IsPluginFocused()) {
4487 pepper_delegate_.GetSurroundingText(&text, &range);
[email protected]82114f52012-03-20 22:53:414488 offset = 0; // Pepper API does not support offset reporting.
[email protected]3c8c74c2012-03-15 07:34:524489 // TODO(kinaba): cut as needed.
[email protected]e99ef6f2011-10-16 01:13:004490 } else {
[email protected]3c8c74c2012-03-15 07:34:524491 size_t location, length;
4492 if (!webview()->caretOrSelectionRange(&location, &length))
4493 return;
4494
4495 range = ui::Range(location, location + length);
4496
4497 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
4498 // If current focused element is editable, we will send 100 more chars
4499 // before and after selection. It is for input method surrounding text
4500 // feature.
4501 if (location > kExtraCharsBeforeAndAfterSelection)
4502 offset = location - kExtraCharsBeforeAndAfterSelection;
4503 else
4504 offset = 0;
4505 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
4506 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
4507 if (!webrange.isNull())
4508 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
4509 } else {
4510 offset = location;
4511 text = frame->selectionAsText();
4512 // http://crbug.com/101435
4513 // In some case, frame->selectionAsText() returned text's length is not
4514 // equal to the length returned from webview()->caretOrSelectionRange().
4515 // So we have to set the range according to text.length().
4516 range.set_end(range.start() + text.length());
4517 }
[email protected]b781ff282011-08-20 06:19:364518 }
4519
[email protected]b781ff282011-08-20 06:19:364520 // Sometimes we get repeated didChangeSelection calls from webkit when
4521 // the selection hasn't actually changed. We don't want to report these
4522 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:004523 if (selection_text_offset_ != offset ||
4524 selection_range_ != range ||
4525 selection_text_ != text) {
4526 selection_text_ = text;
4527 selection_text_offset_ = offset;
4528 selection_range_ = range;
4529 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
4530 }
[email protected]b781ff282011-08-20 06:19:364531}
4532
[email protected]310ebd6302011-10-10 19:06:284533GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
4534 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554535 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294536 // If the URL that failed was secure, then the embedding web page was not
4537 // expecting a network attacker to be able to manipulate its contents. As
4538 // we fetch alternate error pages over HTTP, we would be allowing a network
4539 // attacker to manipulate the contents of the response if we tried to use
4540 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154541 return GURL();
initial.commit09911bf2008-07-26 23:55:294542 }
4543
4544 // Grab the base URL from the browser process.
4545 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154546 return GURL();
initial.commit09911bf2008-07-26 23:55:294547
4548 // Strip query params from the failed URL.
4549 GURL::Replacements remove_params;
4550 remove_params.ClearUsername();
4551 remove_params.ClearPassword();
4552 remove_params.ClearQuery();
4553 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554554 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504555 std::string spec_to_send = url_to_send.spec();
4556 // Notify link doctor of the url truncation by sending of "?" at the end.
4557 if (failed_url.has_query())
[email protected]82114f52012-03-20 22:53:414558 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294559
4560 // Construct the query params to send to link doctor.
4561 std::string params(alternate_error_page_url_.query());
4562 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:024563 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294564 params.append("&sourceid=chrome");
4565 params.append("&error=");
4566 switch (error_type) {
4567 case DNS_ERROR:
4568 params.append("dnserror");
4569 break;
4570
4571 case HTTP_404:
4572 params.append("http404");
4573 break;
4574
[email protected]5df266ac2008-10-15 19:50:134575 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334576 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134577 break;
4578
initial.commit09911bf2008-07-26 23:55:294579 default:
4580 NOTREACHED() << "unknown ErrorPageType";
4581 }
4582
4583 // OK, build the final url to return.
4584 GURL::Replacements link_doctor_params;
4585 link_doctor_params.SetQueryStr(params);
4586 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4587 return url;
4588}
4589
[email protected]310ebd6302011-10-10 19:06:284590GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:594591 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
4592 return GURL();
4593 else
4594 return creator_url_;
4595}
4596
[email protected]69ddf852012-02-21 23:21:314597GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
4598 WebDataSource* ds = frame->dataSource();
4599 if (ds->hasUnreachableURL())
4600 return ds->unreachableURL();
4601
4602 const WebURLRequest& request = ds->request();
4603 return request.url();
4604}
4605
[email protected]310ebd6302011-10-10 19:06:284606WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:274607 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:314608 web_ui_bindings_.reset(new WebUIBindings(
[email protected]e9ff79c2012-10-19 21:31:264609 static_cast<RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:464610 }
[email protected]c50008512011-02-03 01:17:274611 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:464612}
4613
[email protected]310ebd6302011-10-10 19:06:284614WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:014615 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494616}
4617
[email protected]55750b32012-09-21 14:05:034618void RenderViewImpl::OnFind(int request_id,
4619 const string16& search_text,
[email protected]310ebd6302011-10-10 19:06:284620 const WebFindOptions& options) {
[email protected]55750b32012-09-21 14:05:034621#if defined(OS_ANDROID)
4622 // Make sure any asynchronous messages do not disrupt an ongoing synchronous
4623 // find request as it might lead to deadlocks. Also, these should be safe to
4624 // ignore since they would belong to a previous find request.
4625 if (synchronous_find_reply_message_.get())
4626 return;
4627#endif
4628 Find(request_id, search_text, options);
4629}
4630
4631void RenderViewImpl::Find(int request_id,
4632 const string16& search_text,
4633 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274634 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494635
[email protected]872542532011-06-23 00:43:164636 // Check if the plugin still exists in the document.
4637 if (main_frame->document().isPluginDocument() &&
4638 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494639 if (options.findNext) {
4640 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014641 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494642 } else {
[email protected]55750b32012-09-21 14:05:034643 if (!GetWebPluginFromPluginDocument()->startFind(
[email protected]afdbd142010-07-10 08:01:234644 search_text, options.matchCase, request_id)) {
[email protected]e7c58a32010-08-13 19:47:114645 // Send "no results".
[email protected]55750b32012-09-21 14:05:034646 SendFindReply(request_id, 0, 0, gfx::Rect(), true);
[email protected]24a7f3c2010-03-25 08:26:494647 }
4648 }
4649 return;
4650 }
4651
[email protected]b4bb2502009-10-01 22:35:274652 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274653 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294654 WebFrame* search_frame = focused_frame; // start searching focused frame.
4655
4656 bool multi_frame = (frame_after_main != main_frame);
4657
4658 // If we have multiple frames, we don't want to wrap the search within the
4659 // frame, so we check here if we only have main_frame in the chain.
4660 bool wrap_within_frame = !multi_frame;
4661
[email protected]b3f2b912009-04-09 16:18:524662 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294663 bool result = false;
4664
[email protected]7830da3e2009-11-06 16:27:264665 // If something is selected when we start searching it means we cannot just
4666 // increment the current match ordinal; we need to re-generate it.
4667 WebRange current_selection = focused_frame->selectionRange();
4668
initial.commit09911bf2008-07-26 23:55:294669 do {
[email protected]dd7daa82009-08-10 05:46:454670 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594671 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294672
4673 if (!result) {
4674 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:224675 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294676
4677 // Find the next frame, but skip the invisible ones.
4678 do {
4679 // What is the next frame to search? (we might be going backwards). Note
4680 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594681 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274682 search_frame->traverseNext(true) :
4683 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454684 } while (!search_frame->hasVisibleContent() &&
4685 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294686
[email protected]884db412008-11-24 23:46:504687 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:224688 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294689
4690 // If we have multiple frames and we have wrapped back around to the
4691 // focused frame, we need to search it once more allowing wrap within
4692 // the frame, otherwise it will report 'no match' if the focused frame has
4693 // reported matches, but no frames after the focused_frame contain a
4694 // match for the search word(s).
4695 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454696 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594697 request_id, search_text, options, true, // Force wrapping.
4698 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294699 }
4700 }
4701
[email protected]26aa0482009-09-30 16:55:274702 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294703 } while (!result && search_frame != focused_frame);
4704
[email protected]7830da3e2009-11-06 16:27:264705 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294706 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454707 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294708 } else {
4709 // If nothing is found, set result to "0 of 0", otherwise, set it to
4710 // "-1 of 1" to indicate that we found at least one item, but we don't know
4711 // yet what is active.
4712 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4713 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294714
[email protected]4f3dc372009-02-24 00:10:294715 // If we find no matches then this will be our last status update.
4716 // Otherwise the scoping effort will send more results.
4717 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294718
[email protected]55750b32012-09-21 14:05:034719 SendFindReply(request_id, match_count, ordinal, selection_rect,
4720 final_status_update);
initial.commit09911bf2008-07-26 23:55:294721
initial.commit09911bf2008-07-26 23:55:294722 // Scoping effort begins, starting with the mainframe.
4723 search_frame = main_frame;
4724
[email protected]dd7daa82009-08-10 05:46:454725 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294726
4727 do {
4728 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454729 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294730
4731 // We don't start another scoping effort unless at least one match has
4732 // been found.
4733 if (result) {
4734 // Start new scoping request. If the scoping function determines that it
4735 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454736 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594737 search_text,
4738 options,
initial.commit09911bf2008-07-26 23:55:294739 true); // reset the tickmarks
4740 }
4741
4742 // Iterate to the next frame. The frame will not necessarily scope, for
4743 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274744 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294745 } while (search_frame != main_frame);
4746 }
4747}
4748
[email protected]e9ff79c2012-10-19 21:31:264749void RenderViewImpl::OnStopFinding(StopFindAction action) {
[email protected]55750b32012-09-21 14:05:034750#if defined(OS_ANDROID)
4751 // Make sure any asynchronous messages do not disrupt an ongoing synchronous
4752 // find request as it might lead to deadlocks. Also, these should be safe to
4753 // ignore since they would belong to a previous find request.
4754 if (synchronous_find_reply_message_.get())
4755 return;
4756#endif
4757
4758 StopFinding(action);
4759}
4760
[email protected]e9ff79c2012-10-19 21:31:264761void RenderViewImpl::StopFinding(StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:494762 WebView* view = webview();
4763 if (!view)
4764 return;
4765
4766 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:164767 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014768 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494769 return;
4770 }
4771
[email protected]e9ff79c2012-10-19 21:31:264772 bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:494773 if (clear_selection)
4774 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4775
4776 WebFrame* frame = view->mainFrame();
4777 while (frame) {
4778 frame->stopFinding(clear_selection);
4779 frame = frame->traverseNext(false);
4780 }
4781
[email protected]e9ff79c2012-10-19 21:31:264782 if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:494783 WebFrame* focused_frame = view->focusedFrame();
4784 if (focused_frame) {
4785 WebDocument doc = focused_frame->document();
4786 if (!doc.isNull()) {
4787 WebNode node = doc.focusedNode();
4788 if (!node.isNull())
4789 node.simulateClick();
4790 }
4791 }
4792 }
4793}
4794
[email protected]59363fc92012-09-05 03:46:314795#if defined(OS_ANDROID)
[email protected]55750b32012-09-21 14:05:034796void RenderViewImpl::OnSynchronousFind(int request_id,
4797 const string16& search_string,
4798 const WebFindOptions& options,
4799 IPC::Message* reply_msg) {
4800 // It is impossible for simultaneous blocking finds to occur.
4801 CHECK(!synchronous_find_reply_message_.get());
4802 synchronous_find_reply_message_.reset(reply_msg);
4803
4804 // Find next should be asynchronous in order to minimize blocking
4805 // the UI thread as much as possible.
4806 DCHECK(!options.findNext);
[email protected]e9ff79c2012-10-19 21:31:264807 StopFinding(STOP_FIND_ACTION_KEEP_SELECTION);
[email protected]55750b32012-09-21 14:05:034808 synchronous_find_active_match_ordinal_ = -1;
4809
4810 Find(request_id, search_string, options);
4811}
4812
[email protected]59363fc92012-09-05 03:46:314813void RenderViewImpl::OnActivateNearestFindResult(int request_id,
4814 float x, float y) {
4815 if (!webview())
4816 return;
4817
4818 WebFrame* main_frame = webview()->mainFrame();
4819 WebRect selection_rect;
4820 int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y),
4821 &selection_rect);
4822 if (ordinal == -1) {
4823 // Something went wrong, so send a no-op reply (force the main_frame to
4824 // report the current match count) in case the host is waiting for a
4825 // response due to rate-limiting).
4826 main_frame->increaseMatchCount(0, request_id);
4827 return;
4828 }
4829
[email protected]55750b32012-09-21 14:05:034830 SendFindReply(request_id,
4831 -1 /* number_of_matches */,
4832 ordinal,
4833 selection_rect,
4834 true /* final_update */);
[email protected]59363fc92012-09-05 03:46:314835}
4836
4837void RenderViewImpl::OnFindMatchRects(int current_version) {
4838 if (!webview())
4839 return;
4840
4841 WebFrame* main_frame = webview()->mainFrame();
4842 std::vector<gfx::RectF> match_rects;
4843
4844 int rects_version = main_frame->findMatchMarkersVersion();
4845 if (current_version != rects_version) {
4846 WebVector<WebFloatRect> web_match_rects;
4847 main_frame->findMatchRects(web_match_rects);
4848 match_rects.reserve(web_match_rects.size());
4849 for (size_t i = 0; i < web_match_rects.size(); ++i)
4850 match_rects.push_back(gfx::RectF(web_match_rects[i]));
4851 }
4852
4853 gfx::RectF active_rect = main_frame->activeFindMatchRect();
4854 Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_,
4855 rects_version,
4856 match_rects,
4857 active_rect));
4858}
4859#endif
4860
[email protected]e9ff79c2012-10-19 21:31:264861void RenderViewImpl::OnZoom(PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:514862 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4863 return;
4864
[email protected]258d31122010-05-09 10:59:414865 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:104866
[email protected]b75b8292010-10-01 07:28:254867 double old_zoom_level = webview()->zoomLevel();
4868 double zoom_level;
[email protected]e9ff79c2012-10-19 21:31:264869 if (zoom == PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:254870 zoom_level = 0;
4871 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4872 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:484873 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:254874 } else {
4875 // Either the user hit the zoom factor limit and thus the zoom level is now
4876 // not a whole number, or a plugin changed it to a custom value. We want
4877 // to go to the next whole number so that the user can always get back to
4878 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:484879 if ((old_zoom_level > 1 && zoom > 0) ||
4880 (old_zoom_level < 1 && zoom < 0)) {
4881 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:254882 } else {
4883 // We're going towards 100%, so first go to the next whole number.
4884 zoom_level = static_cast<int>(old_zoom_level);
4885 }
4886 }
[email protected]b75b8292010-10-01 07:28:254887 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:414888 zoomLevelChanged();
4889}
4890
[email protected]e9ff79c2012-10-19 21:31:264891void RenderViewImpl::OnZoomFactor(PageZoom zoom, int zoom_center_x,
4892 int zoom_center_y) {
[email protected]47578fa02011-11-02 19:34:414893 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
4894 kScalingIncrementForGesture);
4895}
4896
[email protected]e9ff79c2012-10-19 21:31:264897void RenderViewImpl::ZoomFactorHelper(PageZoom zoom,
[email protected]47578fa02011-11-02 19:34:414898 int zoom_center_x,
4899 int zoom_center_y,
4900 float scaling_increment) {
4901 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4902 return;
4903
[email protected]c514d6372011-08-16 22:54:444904 double old_page_scale_factor = webview()->pageScaleFactor();
4905 double page_scale_factor;
[email protected]e9ff79c2012-10-19 21:31:264906 if (zoom == PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:444907 page_scale_factor = 1.0;
4908 } else {
4909 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:414910 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:444911 }
[email protected]47578fa02011-11-02 19:34:414912 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:094913 webview()->setPageScaleFactor(page_scale_factor,
4914 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:414915 }
[email protected]40bd6582009-12-04 23:49:514916}
4917
[email protected]310ebd6302011-10-10 19:06:284918void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174919 webview()->hidePopups();
4920 webview()->setZoomLevel(false, zoom_level);
4921 zoomLevelChanged();
4922}
4923
[email protected]310ebd6302011-10-10 19:06:284924void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4925 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544926 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294927}
4928
[email protected]310ebd6302011-10-10 19:06:284929void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274930 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294931}
4932
[email protected]310ebd6302011-10-10 19:06:284933void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274934 WebString no_encoding;
4935 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184936}
4937
[email protected]310ebd6302011-10-10 19:06:284938WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454939 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274940 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454941
4942 // xpath string can represent a frame deep down the tree (across multiple
4943 // frame DOMs).
4944 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4945 // should break into 2 xpaths
4946 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:414947 std::vector<string16> xpaths;
4948 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:454949
[email protected]26aa0482009-09-30 16:55:274950 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:414951 for (std::vector<string16>::const_iterator i = xpaths.begin();
4952 frame && i != xpaths.end(); ++i) {
4953 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294954 }
4955
[email protected]dd7daa82009-08-10 05:46:454956 return frame;
initial.commit09911bf2008-07-26 23:55:294957}
4958
[email protected]310ebd6302011-10-10 19:06:284959void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4960 const string16& jscript,
4961 int id,
4962 bool notify_result) {
[email protected]01d43ef92012-09-25 00:54:104963 TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest");
[email protected]882b7b22010-10-05 03:34:534964 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294965}
4966
[email protected]f546640b2012-05-15 00:03:494967void RenderViewImpl::OnPostMessageEvent(
4968 const ViewMsg_PostMessage_Params& params) {
[email protected]0720b532012-08-28 19:23:374969 // Find the target frame of this message. The source tags the message with
4970 // |target_frame_id|, so use it to locate the frame.
[email protected]e12dbe6f2012-10-04 22:11:194971 // TODO(nasko): Lookup based on the frame id, once http://crbug.com/153701
4972 // is fixed and we can rely on having frame tree updates again.
4973 WebFrame* frame = webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:494974
4975 // Find the source frame if it exists.
[email protected]f546640b2012-05-15 00:03:494976 WebFrame* source_frame = NULL;
4977 if (params.source_routing_id != MSG_ROUTING_NONE) {
4978 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
[email protected]e12dbe6f2012-10-04 22:11:194979 // TODO(nasko): Lookup based on the frame id, once http://crbug.com/153701
4980 // is fixed and we can rely on having frame tree updates again.
[email protected]f546640b2012-05-15 00:03:494981 if (source_view)
[email protected]e12dbe6f2012-10-04 22:11:194982 source_frame = source_view->webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:494983 }
4984
4985 // Create an event with the message. The final parameter to initMessageEvent
4986 // is the last event ID, which is not used with postMessage.
4987 WebDOMEvent event = frame->document().createEvent("MessageEvent");
4988 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
4989 msg_event.initMessageEvent("message",
4990 // |canBubble| and |cancellable| are always false
4991 false, false,
4992 WebSerializedScriptValue::fromString(params.data),
4993 params.source_origin, source_frame, "");
4994
4995 // We must pass in the target_origin to do the security check on this side,
4996 // since it may have changed since the original postMessage call was made.
4997 WebSecurityOrigin target_origin;
4998 if (!params.target_origin.empty()) {
4999 target_origin =
5000 WebSecurityOrigin::createFromString(WebString(params.target_origin));
5001 }
5002 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
5003}
5004
[email protected]310ebd6302011-10-10 19:06:285005void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
5006 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:415007 WebFrame* frame = GetChildFrame(frame_xpath);
5008 if (!frame)
[email protected]216813952011-05-19 22:21:265009 return;
[email protected]ae461542009-06-19 19:03:415010
[email protected]01cf589c2011-07-28 18:04:035011 frame->document().insertUserStyleSheet(
5012 WebString::fromUTF8(css),
5013 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:485014}
5015
[email protected]310ebd6302011-10-10 19:06:285016void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:095017 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:045018
5019 // Keep track of the total bindings accumulated in this process.
5020 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:295021}
5022
[email protected]310ebd6302011-10-10 19:06:285023void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
5024 const std::string& value) {
[email protected]e9ff79c2012-10-19 21:31:265025 if (enabled_bindings_ & BINDINGS_POLICY_WEB_UI)
[email protected]808bda52012-03-09 22:43:325026 GetWebUIBindings()->SetProperty(name, value);
5027 else
5028 NOTREACHED() << "WebUI bindings not enabled.";
initial.commit09911bf2008-07-26 23:55:295029}
5030
[email protected]310ebd6302011-10-10 19:06:285031void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
5032 const gfx::Point& client_point,
5033 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:425034 WebDragOperationsMask ops,
5035 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:555036 WebDragOperation operation = webview()->dragTargetDragEnter(
5037 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:555038 client_point,
5039 screen_point,
[email protected]1f2230b2012-05-17 23:43:425040 ops,
5041 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555042
5043 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5044}
5045
[email protected]310ebd6302011-10-10 19:06:285046void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
5047 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:425048 WebDragOperationsMask ops,
5049 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:555050 WebDragOperation operation = webview()->dragTargetDragOver(
5051 client_point,
5052 screen_point,
[email protected]1f2230b2012-05-17 23:43:425053 ops,
5054 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555055
5056 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5057}
5058
[email protected]310ebd6302011-10-10 19:06:285059void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:555060 webview()->dragTargetDragLeave();
5061}
5062
[email protected]310ebd6302011-10-10 19:06:285063void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
[email protected]1f2230b2012-05-17 23:43:425064 const gfx::Point& screen_point,
5065 int key_modifiers) {
5066 webview()->dragTargetDrop(client_point, screen_point, key_modifiers);
[email protected]fcad49452011-06-28 17:11:575067
5068 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:555069}
5070
[email protected]310ebd6302011-10-10 19:06:285071void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
5072 const gfx::Point& screen_point,
5073 bool ended,
5074 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:035075 if (ended) {
[email protected]26aa0482009-09-30 16:55:275076 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:205077 } else {
5078 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:035079 }
initial.commit09911bf2008-07-26 23:55:295080}
5081
[email protected]310ebd6302011-10-10 19:06:285082void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:275083 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:295084}
5085
[email protected]310ebd6302011-10-10 19:06:285086void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:595087 webkit_preferences_ = prefs;
5088 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:295089}
5090
[email protected]38761452012-10-18 16:31:595091void RenderViewImpl::OnUpdateTimezone() {
5092 if (webview())
5093 NotifyTimezoneChange(webview()->mainFrame());
5094}
5095
[email protected]310ebd6302011-10-10 19:06:285096void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:295097 alternate_error_page_url_ = url;
5098}
5099
[email protected]310ebd6302011-10-10 19:06:285100void RenderViewImpl::OnCustomContextMenuAction(
[email protected]e9ff79c2012-10-19 21:31:265101 const CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:085102 unsigned action) {
[email protected]860ee642012-10-13 03:46:255103 if (custom_context.request_id) {
5104 // External context menu request, look in our map.
[email protected]e9ff79c2012-10-19 21:31:265105 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:255106 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:465107 if (client)
5108 client->OnMenuAction(custom_context.request_id, action);
[email protected]860ee642012-10-13 03:46:255109 } else {
5110 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:085111 webview()->performCustomContextMenuAction(action);
[email protected]860ee642012-10-13 03:46:255112 }
[email protected]a0c7153e2009-12-09 14:36:335113}
5114
[email protected]310ebd6302011-10-10 19:06:285115void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:515116 int id,
5117 const std::vector<FilePath>& paths) {
5118 if (!enumeration_completions_[id])
5119 return;
5120
5121 WebVector<WebString> ws_file_names(paths.size());
5122 for (size_t i = 0; i < paths.size(); ++i)
[email protected]bb0e79472012-10-23 04:36:345123 ws_file_names[i] = webkit_base::FilePathToWebString(paths[i]);
[email protected]600ea402011-04-12 00:01:515124
5125 enumeration_completions_[id]->didChooseFile(ws_file_names);
5126 enumeration_completions_.erase(id);
5127}
5128
[email protected]fb11b6a42012-03-14 07:25:125129void RenderViewImpl::OnFileChooserResponse(
[email protected]ddb034b2012-06-26 20:31:395130 const std::vector<ui::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:365131 // This could happen if we navigated to a different page before the user
5132 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:475133 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:365134 return;
5135
[email protected]b5188522012-03-15 00:18:045136 // Convert Chrome's SelectedFileInfo list to WebKit's.
5137 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
5138 files.size());
5139 for (size_t i = 0; i < files.size(); ++i) {
5140 WebFileChooserCompletion::SelectedFileInfo selected_file;
[email protected]bb0e79472012-10-23 04:36:345141 selected_file.path = webkit_base::FilePathToWebString(files[i].local_path);
5142 selected_file.displayName = webkit_base::FilePathStringToWebString(
[email protected]b5188522012-03-15 00:18:045143 files[i].display_name);
5144 selected_files[i] = selected_file;
5145 }
[email protected]a1128322009-10-06 18:38:465146
[email protected]cdaf8d02010-03-30 19:52:475147 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:045148 file_chooser_completions_.front()->completion->didChooseFile(
5149 selected_files);
[email protected]cdaf8d02010-03-30 19:52:475150 file_chooser_completions_.pop_front();
5151
5152 // If there are more pending file chooser requests, schedule one now.
5153 if (!file_chooser_completions_.empty()) {
5154 Send(new ViewHostMsg_RunFileChooser(routing_id_,
5155 file_chooser_completions_.front()->params));
5156 }
initial.commit09911bf2008-07-26 23:55:295157}
5158
[email protected]244ac1892011-12-02 17:04:475159void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
5160 const gfx::Size& max_size) {
5161 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5162 if (!webview())
5163 return;
[email protected]61e2b3cc2012-03-02 16:13:345164 webview()->enableAutoResizeMode(min_size, max_size);
5165}
5166
5167void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
5168 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5169 if (!webview())
5170 return;
5171 webview()->disableAutoResizeMode();
5172
5173 Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK);
[email protected]244ac1892011-12-02 17:04:475174}
5175
[email protected]2bf834f2011-11-17 20:02:215176void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:245177 if (send_preferred_size_changes_)
5178 return;
[email protected]9fb325e2010-05-06 18:23:245179 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:395180
[email protected]d812fd12011-05-27 23:05:075181 // Start off with an initial preferred size notification (in case
5182 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:595183 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:085184}
5185
[email protected]310ebd6302011-10-10 19:06:285186void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:105187 const gfx::Size& disable_scrollbar_size_limit) {
5188 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
5189}
5190
[email protected]310ebd6302011-10-10 19:06:285191void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:265192 const RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:505193 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:515194 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:375195 UpdateFontRenderingFromRendererPrefs();
[email protected]a13283cc2012-04-05 00:21:225196#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:415197 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
5198 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:465199 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]f78452f2012-05-15 02:07:525200 ui::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:345201 renderer_prefs.thumb_inactive_color,
5202 renderer_prefs.thumb_active_color,
5203 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:555204#endif
[email protected]93623c5d2009-12-10 21:40:325205
[email protected]a13283cc2012-04-05 00:21:225206#if defined(USE_ASH) || defined(TOOLKIT_GTK)
[email protected]644d77e2010-01-27 01:03:105207 if (webview()) {
[email protected]a13283cc2012-04-05 00:21:225208#if defined(TOOLKIT_GTK)
[email protected]93623c5d2009-12-10 21:40:325209 webview()->setScrollbarColors(
5210 renderer_prefs.thumb_inactive_color,
5211 renderer_prefs.thumb_active_color,
5212 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:555213#endif
[email protected]644d77e2010-01-27 01:03:105214 webview()->setSelectionColors(
5215 renderer_prefs.active_selection_bg_color,
5216 renderer_prefs.active_selection_fg_color,
5217 renderer_prefs.inactive_selection_bg_color,
5218 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:465219 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:105220 }
[email protected]7a74e102009-09-03 00:16:565221#endif
[email protected]d299d972012-03-23 02:26:555222
[email protected]d051d9a2011-12-10 02:02:505223 // If the zoom level for this page matches the old zoom default, and this
5224 // is not a plugin, update the zoom level to match the new default.
5225 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
[email protected]e9ff79c2012-10-19 21:31:265226 ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
[email protected]d051d9a2011-12-10 02:02:505227 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
5228 zoomLevelChanged();
5229 }
[email protected]80d96fa2009-06-10 22:34:515230}
5231
[email protected]310ebd6302011-10-10 19:06:285232void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
5233 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:285234 if (webview())
5235 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:565236}
5237
[email protected]77829642012-05-15 14:47:175238void RenderViewImpl::OnOrientationChangeEvent(int orientation) {
5239 webview()->mainFrame()->sendOrientationChangeEvent(orientation);
5240}
5241
[email protected]81375e872012-01-11 21:40:365242void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
5243 const WebPluginAction& action) {
5244 if (webview())
5245 webview()->performPluginAction(action, location);
5246}
5247
[email protected]310ebd6302011-10-10 19:06:285248void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:195249 const GURL& page_url) {
5250 // Prepare list to storage all savable resource links.
5251 std::vector<GURL> resources_list;
[email protected]c2d986512012-05-12 00:22:465252 std::vector<GURL> referrer_urls_list;
5253 std::vector<WebKit::WebReferrerPolicy> referrer_policies_list;
[email protected]18d5be92011-07-25 18:00:195254 std::vector<GURL> frames_list;
5255 webkit_glue::SavableResourcesResult result(&resources_list,
[email protected]c2d986512012-05-12 00:22:465256 &referrer_urls_list,
5257 &referrer_policies_list,
[email protected]18d5be92011-07-25 18:00:195258 &frames_list);
5259
[email protected]e9ff79c2012-10-19 21:31:265260 // webkit/ doesn't know about Referrer.
[email protected]18d5be92011-07-25 18:00:195261 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
5262 webview(),
5263 page_url,
5264 &result,
[email protected]e9ff79c2012-10-19 21:31:265265 const_cast<const char**>(GetSavableSchemes()))) {
[email protected]18d5be92011-07-25 18:00:195266 // If something is wrong when collecting all savable resource links,
5267 // send empty list to embedder(browser) to tell it failed.
[email protected]c2d986512012-05-12 00:22:465268 referrer_urls_list.clear();
5269 referrer_policies_list.clear();
[email protected]18d5be92011-07-25 18:00:195270 resources_list.clear();
5271 frames_list.clear();
5272 }
5273
[email protected]e9ff79c2012-10-19 21:31:265274 std::vector<Referrer> referrers_list;
[email protected]c2d986512012-05-12 00:22:465275 CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size());
5276 for (unsigned i = 0; i < referrer_urls_list.size(); ++i) {
5277 referrers_list.push_back(
[email protected]e9ff79c2012-10-19 21:31:265278 Referrer(referrer_urls_list[i], referrer_policies_list[i]));
[email protected]c2d986512012-05-12 00:22:465279 }
5280
[email protected]18d5be92011-07-25 18:00:195281 // Send result of all savable resource links to embedder.
5282 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
5283 resources_list,
5284 referrers_list,
5285 frames_list));
5286}
5287
[email protected]310ebd6302011-10-10 19:06:285288void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:195289 const std::vector<GURL>& links,
5290 const std::vector<FilePath>& local_paths,
5291 const FilePath& local_directory_name) {
5292
5293 // Convert std::vector of GURLs to WebVector<WebURL>
5294 WebVector<WebURL> weburl_links(links);
5295
5296 // Convert std::vector of std::strings to WebVector<WebString>
5297 WebVector<WebString> webstring_paths(local_paths.size());
5298 for (size_t i = 0; i < local_paths.size(); i++)
[email protected]bb0e79472012-10-23 04:36:345299 webstring_paths[i] = webkit_base::FilePathToWebString(local_paths[i]);
[email protected]18d5be92011-07-25 18:00:195300
5301 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
5302 webstring_paths,
[email protected]bb0e79472012-10-23 04:36:345303 webkit_base::FilePathToWebString(
[email protected]18d5be92011-07-25 18:00:195304 local_directory_name));
5305}
5306
[email protected]310ebd6302011-10-10 19:06:285307void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:125308 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:275309 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:125310 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
5311 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
5312 before_unload_start_time,
5313 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:295314}
5315
[email protected]310ebd6302011-10-10 19:06:285316void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]69ddf852012-02-21 23:21:315317 // Ensure that no other in-progress navigation continues.
5318 OnStop();
5319
[email protected]73eb2602012-02-09 19:50:555320 // Only run unload if we're not swapped out yet, but send the ack either way.
5321 if (!is_swapped_out_) {
5322 // Swap this RenderView out so the tab can navigate to a page rendered by a
5323 // different process. This involves running the unload handler and clearing
5324 // the page. Once WasSwappedOut is called, we also allow this process to
5325 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:155326
[email protected]73eb2602012-02-09 19:50:555327 // Send an UpdateState message before we get swapped out.
5328 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:155329
[email protected]73eb2602012-02-09 19:50:555330 // Synchronously run the unload handler before sending the ACK.
5331 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:155332
[email protected]73eb2602012-02-09 19:50:555333 // Swap out and stop sending any IPC messages that are not ACKs.
5334 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:155335
[email protected]285f4bb82012-04-17 15:57:285336 // Replace the page with a blank dummy URL. The unload handler will not be
[email protected]73eb2602012-02-09 19:50:555337 // run a second time, thanks to a check in FrameLoader::stopLoading.
5338 // TODO(creis): Need to add a better way to do this that avoids running the
[email protected]285f4bb82012-04-17 15:57:285339 // beforeunload handler. For now, we just run it a second time silently.
[email protected]0720b532012-08-28 19:23:375340 NavigateToSwappedOutURL(webview()->mainFrame());
[email protected]961541a92012-06-01 21:15:285341
5342 // Let WebKit know that this view is hidden so it can drop resources and
5343 // stop compositing.
5344 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false);
[email protected]73eb2602012-02-09 19:50:555345 }
[email protected]992db4c2011-05-12 15:37:155346
5347 // Just echo back the params in the ACK.
5348 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
5349}
5350
[email protected]0720b532012-08-28 19:23:375351void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) {
[email protected]14392a52012-05-02 20:28:445352 // We use loadRequest instead of loadHTMLString because the former commits
5353 // synchronously. Otherwise a new navigation can interrupt the navigation
[email protected]e9ff79c2012-10-19 21:31:265354 // to kSwappedOutURL. If that happens to be to the page we had been
[email protected]14392a52012-05-02 20:28:445355 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]e9ff79c2012-10-19 21:31:265356 GURL swappedOutURL(kSwappedOutURL);
[email protected]14392a52012-05-02 20:28:445357 WebURLRequest request(swappedOutURL);
[email protected]0720b532012-08-28 19:23:375358 frame->loadRequest(request);
[email protected]14392a52012-05-02 20:28:445359}
5360
[email protected]310ebd6302011-10-10 19:06:285361void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:375362 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:295363 // TODO(creis): We'd rather use webview()->Close() here, but that currently
5364 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
5365 // in the onunload handler from appearing. For now, we're bypassing that and
5366 // calling the FrameLoader's CloseURL method directly. This should be
5367 // revisited to avoid having two ways to close a page. Having a single way
5368 // to close that can run onunload is also useful for fixing
5369 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:275370 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:295371
[email protected]992db4c2011-05-12 15:37:155372 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:295373}
5374
[email protected]310ebd6302011-10-10 19:06:285375void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:025376#if defined(USE_AURA)
5377 // Aura doesn't care if we switch themes.
5378#elif defined(OS_WIN)
[email protected]f78452f2012-05-15 02:07:525379 ui::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:465380 if (webview())
5381 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:575382#else // defined(OS_WIN)
5383 // TODO(port): we don't support theming on non-Windows platforms yet
5384 NOTIMPLEMENTED();
5385#endif
initial.commit09911bf2008-07-26 23:55:295386}
5387
[email protected]310ebd6302011-10-10 19:06:285388void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:085389 if (decrement_shared_popup_at_destruction_)
5390 shared_popup_counter_->data--;
5391 shared_popup_counter_ = new SharedRenderViewCounter(0);
5392 decrement_shared_popup_at_destruction_ = false;
5393}
5394
[email protected]310ebd6302011-10-10 19:06:285395bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
5396 const WebURLError& error,
5397 bool replace) {
[email protected]15d79e12009-08-02 19:23:455398 // We only show alternate error pages in the main frame. They are
5399 // intended to assist the user when navigating, so there is not much
5400 // value in showing them for failed subframes. Ideally, we would be
5401 // able to use the TYPED transition type for this, but that flag is
5402 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455403 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455404 return false;
5405
5406 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375407 // connection failure.
[email protected]15d79e12009-08-02 19:23:455408 int ec = error.reason;
5409 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5410 ec != net::ERR_CONNECTION_FAILED &&
5411 ec != net::ERR_CONNECTION_REFUSED &&
5412 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]82114f52012-03-20 22:53:415413 ec != net::ERR_CONNECTION_TIMED_OUT) {
[email protected]15d79e12009-08-02 19:23:455414 return false;
[email protected]82114f52012-03-20 22:53:415415 }
[email protected]15d79e12009-08-02 19:23:455416
5417 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555418 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455419 if (!error_page_url.is_valid())
5420 return false;
5421
5422 // Load an empty page first so there is an immediate response to the error,
5423 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455424 frame->loadHTMLString(std::string(),
[email protected]e9ff79c2012-10-19 21:31:265425 GURL(kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455426 error.unreachableURL,
5427 replace);
5428
5429 // Now, create a fetcher for the error page and associate it with the data
5430 // source we just created via the LoadHTMLString call. That way if another
5431 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:075432 DocumentState* document_state =
5433 DocumentState::FromDataSource(frame->provisionalDataSource());
5434 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:455435 new AltErrorPageResourceFetcher(
5436 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:085437 base::Bind(&RenderViewImpl::AltErrorPageFinished,
5438 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:455439 return true;
5440}
5441
[email protected]310ebd6302011-10-10 19:06:285442void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
5443 const WebURLError& original_error,
5444 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:455445 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:095446 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:555447 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:095448 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:455449}
5450
[email protected]310ebd6302011-10-10 19:06:285451void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:005452 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475453 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005454}
5455
[email protected]310ebd6302011-10-10 19:06:285456void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:095457 const gfx::Rect& resizer_rect,
5458 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:105459 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475460 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105461 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205462 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:315463 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:105464 }
[email protected]dd6afca2011-08-13 03:44:315465 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:105466 }
5467
[email protected]ee41e7d22011-10-14 19:34:095468 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:005469}
[email protected]0aa477bd2009-03-23 22:21:435470
[email protected]29ed96a2012-02-04 18:12:165471void RenderViewImpl::WillInitiatePaint() {
5472 // Notify the pepper plugins that we're about to paint.
5473 pepper_delegate_.ViewWillInitiatePaint();
5474}
5475
[email protected]310ebd6302011-10-10 19:06:285476void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:165477 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]53900d52010-06-16 04:25:015478 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:285479}
5480
[email protected]310ebd6302011-10-10 19:06:285481void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:285482 // Notify any pepper plugins that we painted. This will call into the plugin,
5483 // and we it may ask to close itself as a result. This will, in turn, modify
5484 // our set, possibly invalidating the iterator. So we iterate on a copy that
5485 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:015486 pepper_delegate_.ViewFlushedPaint();
5487
[email protected]5b1dec8c2012-02-07 04:35:385488 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
5489 // See crbug.com/112921.
5490 if (!webview())
5491 return;
5492
[email protected]00c39612010-03-06 02:53:285493 WebFrame* main_frame = webview()->mainFrame();
5494
5495 // If we have a provisional frame we are between the start and commit stages
5496 // of loading and we don't want to save stats.
5497 if (!main_frame->provisionalDataSource()) {
5498 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:075499 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:285500
[email protected]05c8e502010-08-15 15:13:525501 // TODO(jar): The following code should all be inside a method, probably in
5502 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285503 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:075504 if (document_state->first_paint_time().is_null()) {
5505 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:285506 }
[email protected]007733c2011-11-17 00:34:075507 if (document_state->first_paint_after_load_time().is_null() &&
5508 !document_state->finish_load_time().is_null()) {
5509 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:285510 }
5511 }
5512}
5513
[email protected]310ebd6302011-10-10 19:06:285514void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:085515 RenderWidget::OnSwapBuffersPosted();
5516}
5517
[email protected]310ebd6302011-10-10 19:06:285518void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:245519 RenderWidget::OnSwapBuffersComplete();
5520}
5521
[email protected]310ebd6302011-10-10 19:06:285522void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:245523 RenderWidget::OnSwapBuffersAborted();
5524}
5525
[email protected]310ebd6302011-10-10 19:06:285526webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:155527 const gfx::Rect& paint_bounds,
5528 TransportDIB** dib,
5529 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:205530 gfx::Rect* clip,
5531 float* scale_factor) {
[email protected]ca4847f2010-09-24 05:39:155532 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
[email protected]0f3a2d12012-09-01 03:37:205533 paint_bounds, dib, location, clip, scale_factor);
[email protected]ca4847f2010-09-24 05:39:155534}
5535
[email protected]ceb36f7d2012-10-31 18:33:245536gfx::Vector2d RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:075537 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]ceb36f7d2012-10-31 18:33:245538 return gfx::Vector2d(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:525539}
5540
[email protected]310ebd6302011-10-10 19:06:285541void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:165542 if (webview())
[email protected]26aa0482009-09-30 16:55:275543 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165544}
5545
[email protected]310ebd6302011-10-10 19:06:285546void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:145547 if (webview())
[email protected]b4bb2502009-10-01 22:35:275548 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145549
5550 SetBackground(background);
5551}
5552
[email protected]2a84f9d2012-06-05 21:50:435553void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) {
5554 if (accessibility_mode_ == new_mode)
5555 return;
5556 accessibility_mode_ = new_mode;
5557 if (renderer_accessibility_) {
5558 delete renderer_accessibility_;
5559 renderer_accessibility_ = NULL;
5560 }
5561 if (accessibility_mode_ == AccessibilityModeComplete)
5562 renderer_accessibility_ = new RendererAccessibilityComplete(this);
5563 else if (accessibility_mode_ == AccessibilityModeEditableTextOnly)
5564 renderer_accessibility_ = new RendererAccessibilityFocusOnly(this);
5565}
5566
[email protected]310ebd6302011-10-10 19:06:285567void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:345568 if (webview())
[email protected]b4bb2502009-10-01 22:35:275569 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265570
5571#if defined(OS_MACOSX)
5572 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5573 for (plugin_it = plugin_delegates_.begin();
5574 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5575 (*plugin_it)->SetWindowFocus(active);
5576 }
5577#endif
[email protected]8c66c5a2009-07-22 17:26:345578}
5579
[email protected]7a17bac02012-03-07 21:58:125580void RenderViewImpl::OnSetNavigationStartTime(
5581 const base::TimeTicks& browser_navigation_start) {
5582 if (!webview())
5583 return;
5584
5585 // Only the initial navigation can be a cross-renderer navigation. If we've
5586 // already navigated away from that page, we can ignore this message.
5587 if (page_id_ != -1)
5588 return;
5589
5590 // browser_navigation_start is likely before this process existed, so we can't
5591 // use InterProcessTimeTicksConverter. Instead, the best we can do is just
5592 // ensure we don't report a bogus value in the future.
5593 base::TimeTicks navigation_start = std::min(base::TimeTicks::Now(),
5594 browser_navigation_start);
5595 webview()->mainFrame()->provisionalDataSource()->setNavigationStartTime(
5596 (navigation_start - base::TimeTicks()).InSecondsF());
5597}
5598
[email protected]6ce7abc52010-02-02 18:40:145599#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285600void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:145601 // Inform plugins that their container has changed visibility.
5602 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5603 for (plugin_it = plugin_delegates_.begin();
5604 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5605 (*plugin_it)->SetContainerVisibility(visible);
5606 }
5607}
[email protected]1e6e3c992010-02-08 15:52:135608
[email protected]310ebd6302011-10-10 19:06:285609void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
5610 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:135611 // Inform plugins that their window's frame has changed.
5612 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5613 for (plugin_it = plugin_delegates_.begin();
5614 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5615 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5616 }
5617}
[email protected]935d63d2010-10-15 23:31:555618
[email protected]310ebd6302011-10-10 19:06:285619void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
5620 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135621 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555622 // applies to it or not, so inform all the delegates.
5623 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5624 for (plugin_it = plugin_delegates_.begin();
5625 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135626 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555627 }
5628}
[email protected]6ce7abc52010-02-02 18:40:145629#endif // OS_MACOSX
5630
[email protected]310ebd6302011-10-10 19:06:285631void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:485632 const EditCommands& edit_commands) {
5633 edit_commands_ = edit_commands;
5634}
5635
[email protected]310ebd6302011-10-10 19:06:285636void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:595637 // We need to grab a pointer to the doomed WebView before we destroy it.
5638 WebView* doomed = webview();
5639 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495640 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:595641}
5642
[email protected]310ebd6302011-10-10 19:06:285643void RenderViewImpl::DidHandleKeyEvent() {
[email protected]b2324b092012-11-01 10:34:115644 ClearEditCommands();
[email protected]446705872009-09-10 07:22:485645}
5646
[email protected]310ebd6302011-10-10 19:06:285647bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]217690d2012-01-27 07:33:115648 pepper_delegate_.WillHandleMouseEvent();
5649
5650 // If the mouse is locked, only the current owner of the mouse lock can
5651 // process mouse events.
5652 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:375653}
5654
[email protected]2b942c332012-04-25 16:26:265655void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515656 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065657}
5658
[email protected]310ebd6302011-10-10 19:06:285659void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:245660 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
5661}
5662
[email protected]310ebd6302011-10-10 19:06:285663void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:435664 RenderWidget::OnWasHidden();
5665
[email protected]2d7b82c2012-06-01 05:57:505666#if defined(OS_ANDROID)
5667 // Inform WebMediaPlayerManagerAndroid to release all media player resources.
5668 media_player_manager_->ReleaseMediaResources();
5669#endif
5670
[email protected]a6939ca42011-02-18 17:58:075671 if (webview()) {
5672 webview()->settings()->setMinimumTimerInterval(
5673 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:445674 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075675 }
5676
[email protected]204f1df2012-01-04 20:21:135677 // Inform PPAPI plugins that their page is no longer visible.
5678 pepper_delegate_.PageVisibilityChanged(false);
5679
[email protected]a6939ca42011-02-18 17:58:075680#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135681 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:435682 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5683 for (plugin_it = plugin_delegates_.begin();
5684 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5685 (*plugin_it)->SetContainerVisibility(false);
5686 }
[email protected]a6939ca42011-02-18 17:58:075687#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:435688}
5689
[email protected]9e2e4632012-07-27 16:38:415690void RenderViewImpl::OnWasShown(bool needs_repainting) {
5691 RenderWidget::OnWasShown(needs_repainting);
[email protected]941e4552010-02-01 21:23:435692
[email protected]a6939ca42011-02-18 17:58:075693 if (webview()) {
5694 webview()->settings()->setMinimumTimerInterval(
5695 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:445696 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075697 }
5698
[email protected]204f1df2012-01-04 20:21:135699 // Inform PPAPI plugins that their page is visible.
5700 pepper_delegate_.PageVisibilityChanged(true);
5701
[email protected]a6939ca42011-02-18 17:58:075702#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135703 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:435704 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5705 for (plugin_it = plugin_delegates_.begin();
5706 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5707 (*plugin_it)->SetContainerVisibility(true);
5708 }
[email protected]784ea1ab2010-09-18 00:02:345709#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:075710}
[email protected]1e6e3c992010-02-08 15:52:135711
[email protected]310ebd6302011-10-10 19:06:285712bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]9caf09bc2012-06-25 21:46:285713 // Contexts using the command buffer support asynchronous swapbuffers.
[email protected]f89e173a2012-08-24 01:12:265714 // See RenderViewImpl::createOutputSurface().
[email protected]9caf09bc2012-06-25 21:46:285715 if (WebWidgetHandlesCompositorScheduling() ||
5716 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL))
[email protected]555e75d2011-10-08 01:23:385717 return false;
5718
[email protected]9caf09bc2012-06-25 21:46:285719 return true;
[email protected]65225772011-05-12 21:10:245720}
5721
[email protected]479b0172012-10-29 19:27:095722bool RenderViewImpl::ForceCompositingModeEnabled() {
5723 return webkit_preferences_.force_compositing_mode;
5724}
5725
[email protected]310ebd6302011-10-10 19:06:285726void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:135727 RenderWidget::OnSetFocus(enable);
5728
[email protected]7d3c02c2010-05-05 23:10:315729 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075730 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135731 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5732 for (plugin_it = plugin_delegates_.begin();
5733 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345734#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315735 // RenderWidget's call to setFocus can cause the underlying webview's
5736 // activation state to change just like a call to setIsActive.
5737 if (enable)
5738 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345739#endif
[email protected]7d3c02c2010-05-05 23:10:315740 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135741 }
5742 }
[email protected]a01da5682012-06-30 00:37:315743 // Notify all Pepper plugins.
5744 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135745}
[email protected]941e4552010-02-01 21:23:435746
[email protected]310ebd6302011-10-10 19:06:285747void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]3306f262012-09-21 19:20:425748 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]3f783362011-10-21 22:40:505749 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:575750}
5751
[email protected]73bf95812011-10-12 11:38:325752void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]3306f262012-09-21 19:20:425753 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]8fe8f742012-06-14 00:36:085754 if (renderer_accessibility_)
5755 renderer_accessibility_->FocusedNodeChanged(WebNode());
[email protected]73bf95812011-10-12 11:38:325756}
5757
[email protected]3f783362011-10-21 22:40:505758void RenderViewImpl::PpapiPluginCaretPositionChanged() {
5759 UpdateSelectionBounds();
5760}
5761
[email protected]b25b3ee2012-01-13 05:19:545762bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
5763 if (!pepper_delegate_.IsPluginFocused())
5764 return false;
5765 *rect = pepper_delegate_.GetCaretBounds();
5766 return true;
5767}
5768
[email protected]397c23962012-05-21 07:09:325769void RenderViewImpl::SimulateImeSetComposition(
5770 const string16& text,
5771 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5772 int selection_start,
5773 int selection_end) {
5774 OnImeSetComposition(text, underlines, selection_start, selection_end);
5775}
5776
5777void RenderViewImpl::SimulateImeConfirmComposition(
5778 const string16& text,
5779 const ui::Range& replacement_range) {
5780 OnImeConfirmComposition(text, replacement_range);
5781}
5782
[email protected]73bf95812011-10-12 11:38:325783void RenderViewImpl::PpapiPluginCancelComposition() {
5784 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]58b48a0d2012-06-13 07:01:355785 const ui::Range range(ui::Range::InvalidRange());
5786 const std::vector<gfx::Rect> empty_bounds;
5787 UpdateCompositionInfo(range, empty_bounds);
[email protected]73bf95812011-10-12 11:38:325788}
5789
[email protected]3c8c74c2012-03-15 07:34:525790void RenderViewImpl::PpapiPluginSelectionChanged() {
5791 SyncSelectionIfRequired();
5792}
5793
[email protected]e9ff79c2012-10-19 21:31:265794void RenderViewImpl::PpapiPluginCreated(RendererPpapiHost* host) {
[email protected]236bf852012-07-27 22:49:365795 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
5796 DidCreatePepperPlugin(host));
5797}
5798
[email protected]310ebd6302011-10-10 19:06:285799void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:575800 const string16& text,
5801 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5802 int selection_start,
5803 int selection_end) {
[email protected]73bf95812011-10-12 11:38:325804 if (pepper_delegate_.IsPluginFocused()) {
5805 // When a PPAPI plugin has focus, we bypass WebKit.
5806 pepper_delegate_.OnImeSetComposition(text,
5807 underlines,
5808 selection_start,
5809 selection_end);
5810 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235811#if defined(OS_WIN)
5812 // When a plug-in has focus, we create platform-specific IME data used by
5813 // our IME emulator and send it directly to the focused plug-in, i.e. we
5814 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
5815 // instance ID is the same one as the specified ID.)
5816 if (focused_plugin_id_ >= 0) {
5817 std::vector<int> clauses;
5818 std::vector<int> target;
5819 for (size_t i = 0; i < underlines.size(); ++i) {
5820 clauses.push_back(underlines[i].startOffset);
5821 clauses.push_back(underlines[i].endOffset);
5822 if (underlines[i].thick) {
5823 target.clear();
5824 target.push_back(underlines[i].startOffset);
5825 target.push_back(underlines[i].endOffset);
5826 }
5827 }
5828 std::set<WebPluginDelegateProxy*>::iterator it;
5829 for (it = plugin_delegates_.begin();
5830 it != plugin_delegates_.end(); ++it) {
5831 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
5832 focused_plugin_id_);
5833 }
5834 return;
5835 }
5836#endif
[email protected]56ea1a62011-05-30 07:05:575837 RenderWidget::OnImeSetComposition(text,
5838 underlines,
5839 selection_start,
5840 selection_end);
5841 }
5842}
5843
[email protected]4de6d1692011-10-12 08:45:445844void RenderViewImpl::OnImeConfirmComposition(
5845 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:575846 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:325847 // When a PPAPI plugin has focus, we bypass WebKit.
5848 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:575849 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235850#if defined(OS_WIN)
5851 // Same as OnImeSetComposition(), we send the text from IMEs directly to
5852 // plug-ins. When we send IME text directly to plug-ins, we should not send
5853 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:445854 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:235855 if (focused_plugin_id_ >= 0) {
5856 std::set<WebPluginDelegateProxy*>::iterator it;
5857 for (it = plugin_delegates_.begin();
5858 it != plugin_delegates_.end(); ++it) {
5859 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
5860 }
5861 return;
5862 }
5863#endif
[email protected]ebd28ac2011-10-13 18:49:055864 if (replacement_range.IsValid() && webview()) {
5865 // Select the text in |replacement_range|, it will then be replaced by
5866 // text added by the call to RenderWidget::OnImeConfirmComposition().
5867 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:165868 WebRange webrange = WebRange::fromDocumentRange(
5869 frame, replacement_range.start(), replacement_range.length());
5870 if (!webrange.isNull())
[email protected]884f9002012-08-21 19:33:585871 frame->selectRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:055872 }
5873 }
[email protected]4de6d1692011-10-12 08:45:445874 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:575875 }
5876}
5877
[email protected]dea5e7682012-06-14 05:21:245878void RenderViewImpl::OnSetDeviceScaleFactor(float device_scale_factor) {
5879 RenderWidget::OnSetDeviceScaleFactor(device_scale_factor);
5880 if (webview())
5881 webview()->setDeviceScaleFactor(device_scale_factor);
5882}
5883
[email protected]310ebd6302011-10-10 19:06:285884ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:325885 return pepper_delegate_.IsPluginFocused() ?
5886 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
5887}
5888
[email protected]3f783362011-10-21 22:40:505889void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
5890 if (pepper_delegate_.IsPluginFocused()) {
5891 // TODO(kinaba) http://crbug.com/101101
5892 // Current Pepper IME API does not handle selection bounds. So we simply
5893 // use the caret position as an empty range for now. It will be updated
5894 // after Pepper API equips features related to surrounding text retrieval.
5895 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
5896 *start = caret;
5897 *end = caret;
5898 return;
5899 }
5900 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:455901}
5902
[email protected]58b48a0d2012-06-13 07:01:355903void RenderViewImpl::GetCompositionCharacterBounds(
5904 std::vector<gfx::Rect>* bounds) {
5905 DCHECK(bounds);
5906 bounds->clear();
5907
5908 if (!webview())
5909 return;
5910 size_t start_offset = 0;
5911 size_t character_count = 0;
5912 if (!webview()->compositionRange(&start_offset, &character_count))
5913 return;
5914 if (character_count == 0)
5915 return;
5916
5917 WebKit::WebFrame* frame = webview()->focusedFrame();
5918 if (!frame)
5919 return;
5920
5921 bounds->reserve(character_count);
5922 WebKit::WebRect webrect;
5923 for (size_t i = 0; i < character_count; ++i) {
5924 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
5925 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
5926 bounds->clear();
5927 return;
5928 }
5929 bounds->push_back(webrect);
5930 }
5931}
5932
[email protected]310ebd6302011-10-10 19:06:285933bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:325934 return pepper_delegate_.IsPluginFocused() ?
5935 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:575936}
5937
[email protected]e6ae0f6c2011-10-04 10:39:235938#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:285939void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:235940 if (focused)
5941 focused_plugin_id_ = plugin_id;
5942 else
5943 focused_plugin_id_ = -1;
5944}
5945#endif
5946
[email protected]43f28f832010-02-03 02:28:485947#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285948void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]82114f52012-03-20 22:53:415949 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
[email protected]b7f75862011-01-21 21:15:135950}
5951
[email protected]310ebd6302011-10-10 19:06:285952void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:135953 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:555954 // This message can be sent during event-handling, and needs to be delivered
5955 // within that context.
5956 msg->set_unblock(true);
5957 Send(msg);
5958}
5959
[email protected]310ebd6302011-10-10 19:06:285960gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235961 bool opaque, bool root) {
[email protected]b2968292012-03-28 01:35:515962 gfx::PluginWindowHandle window = gfx::kNullPluginWindow;
[email protected]43f28f832010-02-03 02:28:485963 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235964 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:115965 if (window) {
5966 fake_plugin_window_handles_.insert(window);
5967 }
[email protected]43f28f832010-02-03 02:28:485968 return window;
5969}
5970
[email protected]310ebd6302011-10-10 19:06:285971void RenderViewImpl::DestroyFakePluginWindowHandle(
5972 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:115973 if (window && fake_plugin_window_handles_.find(window) !=
5974 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:485975 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:115976 fake_plugin_window_handles_.erase(window);
5977 }
[email protected]43f28f832010-02-03 02:28:485978}
5979
[email protected]310ebd6302011-10-10 19:06:285980void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
5981 gfx::PluginWindowHandle window,
5982 int32 width,
5983 int32 height,
5984 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:335985 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485986 routing_id(), window, width, height, io_surface_identifier));
5987}
5988
[email protected]310ebd6302011-10-10 19:06:285989void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:335990 gfx::PluginWindowHandle window,
5991 int32 width,
5992 int32 height,
5993 TransportDIB::Handle transport_dib) {
5994 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075995 routing_id(), window, width, height, transport_dib));
5996}
5997
[email protected]310ebd6302011-10-10 19:06:285998TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:335999 size_t size) {
[email protected]1aef98132010-02-23 18:00:076000 TransportDIB::Handle dib_handle;
6001 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:386002 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:076003 return dib_handle;
6004 // Return an invalid handle if Send() fails.
6005 return TransportDIB::DefaultHandleValue();
6006}
6007
[email protected]310ebd6302011-10-10 19:06:286008void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
6009 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:076010 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
6011}
6012
[email protected]310ebd6302011-10-10 19:06:286013void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:326014 gfx::PluginWindowHandle window, uint64 surface_handle) {
[email protected]f35d6672010-10-28 21:39:146015 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:326016 routing_id(), window, surface_handle));
[email protected]43f28f832010-02-03 02:28:486017}
[email protected]82114f52012-03-20 22:53:416018#endif // defined(OS_MACOSX)
[email protected]58c321d2010-02-19 12:11:286019
[email protected]310ebd6302011-10-10 19:06:286020bool RenderViewImpl::ScheduleFileChooser(
[email protected]e9ff79c2012-10-19 21:31:266021 const FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:476022 WebFileChooserCompletion* completion) {
6023 static const size_t kMaximumPendingFileChooseRequests = 4;
6024 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
6025 // This sanity check prevents too many file choose requests from getting
6026 // queued which could DoS the user. Getting these is most likely a
6027 // programming error (there are many ways to DoS the user so it's not
6028 // considered a "real" security check), either in JS requesting many file
6029 // choosers to pop up, or in a plugin.
6030 //
6031 // TODO(brettw) we might possibly want to require a user gesture to open
6032 // a file picker, which will address this issue in a better way.
6033 return false;
6034 }
6035
6036 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
6037 new PendingFileChooser(params, completion)));
6038 if (file_chooser_completions_.size() == 1) {
6039 // Actually show the browse dialog when this is the first request.
6040 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
6041 }
6042 return true;
6043}
6044
[email protected]310ebd6302011-10-10 19:06:286045WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:516046 if (!geolocation_dispatcher_)
6047 geolocation_dispatcher_ = new GeolocationDispatcher(this);
6048 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:256049}
[email protected]61c9f032010-03-31 23:04:196050
[email protected]310ebd6302011-10-10 19:06:286051WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:116052 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:226053#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:026054 if (!input_tag_speech_dispatcher_)
6055 input_tag_speech_dispatcher_ =
6056 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:226057#endif
[email protected]c52b2892012-03-07 11:01:026058 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:116059}
6060
[email protected]64d09222012-05-25 10:10:346061WebKit::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
6062#if defined(ENABLE_INPUT_SPEECH)
6063 if (!speech_recognition_dispatcher_)
6064 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
6065#endif
6066 return speech_recognition_dispatcher_;
6067}
6068
[email protected]310ebd6302011-10-10 19:06:286069WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:516070 if (!device_orientation_dispatcher_)
6071 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
6072 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:536073}
6074
[email protected]310ebd6302011-10-10 19:06:286075void RenderViewImpl::zoomLimitsChanged(double minimum_level,
6076 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:256077 // For now, don't remember plugin zoom values. We don't want to mix them with
6078 // normal web content (i.e. a fixed layout plugin would usually want them
6079 // different).
6080 bool remember = !webview()->mainFrame()->document().isPluginDocument();
6081
[email protected]b75b8292010-10-01 07:28:256082 int minimum_percent = static_cast<int>(
6083 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
6084 int maximum_percent = static_cast<int>(
6085 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:256086
6087 Send(new ViewHostMsg_UpdateZoomLimits(
6088 routing_id_, minimum_percent, maximum_percent, remember));
6089}
6090
[email protected]310ebd6302011-10-10 19:06:286091void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:256092 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:086093 float zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:266094
6095 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
6096
[email protected]b75b8292010-10-01 07:28:256097 // Tell the browser which url got zoomed so it can update the menu and the
6098 // saved values if necessary
6099 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:086100 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:416101 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:256102}
6103
[email protected]310ebd6302011-10-10 19:06:286104void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
6105 const WebString& base_url,
6106 const WebString& url,
6107 const WebString& title) {
[email protected]3a3b75a2012-06-01 08:38:366108 bool user_gesture = (webview()->focusedFrame() &&
6109 webview()->focusedFrame()->isProcessingUserGesture());
[email protected]a6d36cc2011-02-23 00:39:486110 GURL base(base_url);
6111 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
6112 if (base.GetOrigin() != absolute_url.GetOrigin()) {
6113 return;
6114 }
[email protected]f1a29a02011-10-06 23:08:446115 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
6116 UTF16ToUTF8(scheme),
6117 absolute_url,
[email protected]3a3b75a2012-06-01 08:38:366118 title,
6119 user_gesture));
[email protected]a6d36cc2011-02-23 00:39:486120}
6121
[email protected]310ebd6302011-10-10 19:06:286122WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:446123 WebKit::WebPageVisibilityState current_state = is_hidden() ?
6124 WebKit::WebPageVisibilityStateHidden :
6125 WebKit::WebPageVisibilityStateVisible;
6126 WebKit::WebPageVisibilityState override_state = current_state;
[email protected]e9ff79c2012-10-19 21:31:266127 if (GetContentClient()->renderer()->
[email protected]f59203a2011-06-07 10:01:446128 ShouldOverridePageVisibilityState(this,
6129 &override_state))
6130 return override_state;
6131 return current_state;
[email protected]94dec932011-05-26 20:04:216132}
6133
[email protected]273558fb2012-01-12 15:03:516134WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
[email protected]273558fb2012-01-12 15:03:516135 EnsureMediaStreamImpl();
6136 return media_stream_impl_;
6137}
6138
[email protected]a0629af92012-08-08 00:39:376139void RenderViewImpl::draggableRegionsChanged() {
6140 FOR_EACH_OBSERVER(
6141 RenderViewObserver,
6142 observers_,
6143 DraggableRegionsChanged(webview()->mainFrame()));
6144}
6145
[email protected]20657a82012-08-21 20:23:036146#if defined(OS_ANDROID)
6147WebContentDetectionResult RenderViewImpl::detectContentAround(
6148 const WebHitTestResult& touch_hit) {
6149 DCHECK(!touch_hit.isNull());
6150 DCHECK(!touch_hit.node().isNull());
6151 DCHECK(touch_hit.node().isTextNode());
6152
6153 // Process the position with all the registered content detectors until
6154 // a match is found. Priority is provided by their relative order.
6155 for (ContentDetectorList::const_iterator it = content_detectors_.begin();
6156 it != content_detectors_.end(); ++it) {
6157 ContentDetector::Result content = (*it)->FindTappedContent(touch_hit);
6158 if (content.valid) {
6159 return WebContentDetectionResult(content.content_boundaries,
6160 UTF8ToUTF16(content.text), content.intent_url);
6161 }
6162 }
6163 return WebContentDetectionResult();
6164}
6165
6166void RenderViewImpl::scheduleContentIntent(const WebURL& intent) {
6167 // Introduce a short delay so that the user can notice the content.
6168 MessageLoop::current()->PostDelayedTask(
6169 FROM_HERE,
6170 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, AsWeakPtr(),
6171 intent, expected_content_intent_id_),
6172 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds));
6173}
6174
6175void RenderViewImpl::cancelScheduledContentIntents() {
6176 ++expected_content_intent_id_;
6177}
6178
6179void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent,
6180 size_t request_id) {
6181 if (request_id != expected_content_intent_id_)
6182 return;
6183
6184 // Remove the content highlighting if any.
6185 scheduleComposite();
6186
6187 if (!intent.is_empty())
6188 Send(new ViewHostMsg_StartContentIntent(routing_id_, intent));
6189}
6190#endif
6191
[email protected]310ebd6302011-10-10 19:06:286192void RenderViewImpl::OnAsyncFileOpened(
6193 base::PlatformFileError error_code,
6194 IPC::PlatformFileForTransit file_for_transit,
6195 int message_id) {
[email protected]27a9ef32010-09-10 04:06:246196 pepper_delegate_.OnAsyncFileOpened(
6197 error_code,
6198 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
6199 message_id);
6200}
[email protected]caf706f2010-10-26 17:54:086201
[email protected]310ebd6302011-10-10 19:06:286202void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:476203 int request_id,
[email protected]d54305072011-06-22 20:58:436204 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:476205 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
[email protected]2b657fd2011-04-18 16:00:476206 handle);
[email protected]eb415bf0e2011-04-14 02:45:426207}
6208
[email protected]d8415ad92012-08-23 14:40:506209void RenderViewImpl::OnPpapiBrokerPermissionResult(
6210 int request_id,
6211 bool result) {
6212 pepper_delegate_.OnPpapiBrokerPermissionResult(request_id, result);
6213}
6214
[email protected]caf706f2010-10-26 17:54:086215#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:286216void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:156217 if (external_popup_menu_ == NULL) {
6218 // Crash reports from the field indicate that we can be notified with a
6219 // NULL external popup menu (we probably get notified twice).
6220 // If you hit this please file a bug against jcivelli and include the page
6221 // and steps to repro.
6222 NOTREACHED();
6223 return;
6224 }
[email protected]caf706f2010-10-26 17:54:086225 external_popup_menu_->DidSelectItem(selected_index);
6226 external_popup_menu_.reset();
6227}
6228#endif
[email protected]bb461532010-11-26 21:50:236229
[email protected]24d2b172012-05-26 00:54:126230#if defined(OS_ANDROID)
6231void RenderViewImpl::OnSelectPopupMenuItems(
6232 bool canceled,
6233 const std::vector<int>& selected_indices) {
6234 // It is possible to receive more than one of these calls if the user presses
6235 // a select faster than it takes for the show-select-popup IPC message to make
6236 // it to the browser UI thread. Ignore the extra-messages.
6237 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug.
6238 if (!external_popup_menu_.get())
6239 return;
6240
6241 external_popup_menu_->DidSelectItems(canceled, selected_indices);
6242 external_popup_menu_.reset();
6243}
6244#endif
6245
[email protected]310ebd6302011-10-10 19:06:286246void RenderViewImpl::OnContextMenuClosed(
[email protected]e9ff79c2012-10-19 21:31:266247 const CustomContextMenuContext& custom_context) {
[email protected]860ee642012-10-13 03:46:256248 if (custom_context.request_id) {
6249 // External request, should be in our map.
[email protected]e9ff79c2012-10-19 21:31:266250 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:256251 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:466252 if (client) {
6253 client->OnMenuClosed(custom_context.request_id);
6254 pending_context_menus_.Remove(custom_context.request_id);
6255 }
[email protected]860ee642012-10-13 03:46:256256 } else {
6257 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:086258 context_menu_node_.reset();
[email protected]860ee642012-10-13 03:46:256259 }
[email protected]521b2482011-01-15 00:10:106260}
[email protected]5a7b15a2011-08-22 22:48:186261
[email protected]310ebd6302011-10-10 19:06:286262void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:186263 if (!webview())
6264 return;
6265 WebFrame* main_frame = webview()->mainFrame();
6266 if (!main_frame)
6267 return;
6268 main_frame->enableViewSourceMode(true);
6269}
[email protected]67bfb83f2011-09-22 03:36:376270
[email protected]310ebd6302011-10-10 19:06:286271bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:086272 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:406273}
[email protected]7f3c7af2011-10-20 22:52:516274
[email protected]64d0e192011-12-09 14:44:206275void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7e9c5bb02012-05-14 13:58:316276 DCHECK(!java_bridge_dispatcher_);
[email protected]464750f2011-10-24 23:16:186277#if defined(ENABLE_JAVA_BRIDGE)
[email protected]7e9c5bb02012-05-14 13:58:316278 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this);
[email protected]464750f2011-10-24 23:16:186279#endif
[email protected]7f3c7af2011-10-20 22:52:516280}
[email protected]0720b532012-08-28 19:23:376281
6282void RenderViewImpl::OnUpdatedFrameTree(
6283 int process_id,
6284 int route_id,
6285 const std::string& frame_tree) {
[email protected]e12dbe6f2012-10-04 22:11:196286 // TODO(nasko): Remove once http://crbug.com/153701 is fixed.
6287 DCHECK(false);
[email protected]5fa9b36b2012-09-21 18:14:276288 // We should only act on this message if we are swapped out. It's possible
6289 // for this to happen due to races.
6290 if (!is_swapped_out_)
6291 return;
6292
[email protected]0720b532012-08-28 19:23:376293 base::DictionaryValue* frames = NULL;
6294 scoped_ptr<base::Value> tree(base::JSONReader::Read(frame_tree));
6295 if (tree.get() && tree->IsType(base::Value::TYPE_DICTIONARY))
6296 tree->GetAsDictionary(&frames);
6297
6298 updating_frame_tree_ = true;
6299 active_frame_id_map_.clear();
6300
6301 target_process_id_ = process_id;
6302 target_routing_id_ = route_id;
6303 CreateFrameTree(webview()->mainFrame(), frames);
6304
6305 updating_frame_tree_ = false;
6306}
[email protected]f9526d12012-10-18 01:55:036307
[email protected]efd7e47f2012-10-19 20:37:516308#if defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:036309bool RenderViewImpl::didTapMultipleTargets(
6310 const WebKit::WebGestureEvent& event,
6311 const WebVector<WebRect>& target_rects) {
[email protected]f9526d12012-10-18 01:55:036312 gfx::Rect finger_rect(
6313 event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2,
6314 event.data.tap.width, event.data.tap.height);
6315 gfx::Rect zoom_rect;
6316 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
6317 finger_rect, target_rects, GetSize(), &zoom_rect);
6318 if (!scale)
6319 return false;
6320
6321 gfx::Size canvas_size = zoom_rect.size();
6322 canvas_size = ToCeiledSize(canvas_size.Scale(scale));
6323 TransportDIB* transport_dib = NULL;
6324 {
6325 scoped_ptr<skia::PlatformCanvas> canvas(
6326 RenderProcess::current()->GetDrawingCanvas(&transport_dib,
6327 gfx::Rect(canvas_size)));
6328 if (!canvas.get())
6329 return false;
6330
6331 canvas->scale(scale, scale);
6332
6333 canvas->translate(-zoom_rect.x(), -zoom_rect.y());
6334 webwidget_->paint(webkit_glue::ToWebCanvas(canvas.get()), zoom_rect,
6335 WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent);
6336 }
6337 Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_,
6338 zoom_rect,
6339 canvas_size,
6340 transport_dib->id()));
6341
6342 return true;
6343}
[email protected]efd7e47f2012-10-19 20:37:516344#endif
[email protected]f9526d12012-10-18 01:55:036345
6346void RenderViewImpl::OnReleaseDisambiguationPopupDIB(
6347 TransportDIB::Handle dib_handle) {
6348 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle);
6349 RenderProcess::current()->ReleaseTransportDIB(dib);
6350}
[email protected]e9ff79c2012-10-19 21:31:266351
6352} // namespace content