blob: 97935fd52a467399ad0c1ec14e94f166ac4b1bd8 [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]8d41d7612012-11-14 20:32:1991#include "content/renderer/render_view_impl_params.h"
[email protected]89054502012-06-03 10:29:2492#include "content/renderer/render_view_mouse_lock_dispatcher.h"
[email protected]2cff0052011-03-18 16:51:4493#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3294#include "content/renderer/renderer_accessibility.h"
[email protected]2a84f9d2012-06-05 21:50:4395#include "content/renderer/renderer_accessibility_complete.h"
96#include "content/renderer/renderer_accessibility_focus_only.h"
[email protected]663bd9e2011-03-21 01:07:0197#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]da8543762012-03-20 08:52:2098#include "content/renderer/renderer_webcolorchooser_impl.h"
[email protected]64d09222012-05-25 10:10:3499#include "content/renderer/speech_recognition_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:32100#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:19101#include "content/renderer/v8_value_converter_impl.h"
[email protected]0a35efc2012-03-13 17:28:13102#include "content/renderer/web_intents_host.h"
[email protected]663bd9e2011-03-21 01:07:01103#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:35104#include "content/renderer/webplugin_delegate_proxy.h"
105#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:49106#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41107#include "media/base/media_switches.h"
[email protected]b80322902012-03-06 01:33:50108#include "media/base/message_loop_factory.h"
[email protected]37136d162012-04-09 23:39:19109#include "media/filters/audio_renderer_impl.h"
[email protected]e1d69d762011-12-13 05:12:18110#include "media/filters/gpu_video_decoder.h"
[email protected]d1ef81d2012-07-24 11:39:36111#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29112#include "net/base/escape.h"
113#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09114#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04115#include "net/http/http_util.h"
[email protected]1842fe22012-08-13 23:24:35116#include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutputSurface.h"
[email protected]8bd0fe62011-01-17 06:44:37117#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]97516a02012-10-23 18:19:25118#include "third_party/WebKit/Source/WebKit/chromium/public/WebColorName.h"
[email protected]f546640b2012-05-15 00:03:49119#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEvent.h"
120#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h"
[email protected]be2510c02012-05-28 14:52:14121#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:37123#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:37125#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
129#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]4b1146bc2012-07-10 18:46:03130#include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h"
[email protected]8bd0fe62011-01-17 06:44:37131#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37132#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57133#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58134#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
[email protected]592e20b2012-01-20 05:53:44135#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
[email protected]8b5af492011-11-28 21:50:58136#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14137#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]4e1eb3392012-05-18 00:08:05138#include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannel.h"
[email protected]8bd0fe62011-01-17 06:44:37139#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19140#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37141#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36142#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37143#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
144#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
145#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37146#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37147#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
148#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
149#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17150#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37151#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]10e5cf12011-04-13 04:10:40152#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51153#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08154#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
155#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
156#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
157#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
158#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
[email protected]132e281a2012-07-31 18:32:44159#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPBody.h"
[email protected]9c4bf232011-12-15 02:25:08160#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
161#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
162#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
[email protected]f546640b2012-05-15 00:03:49163#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerializedScriptValue.h"
[email protected]9c4bf232011-12-15 02:25:08164#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]5fa3a062012-03-21 15:39:34165#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSocketStreamHandle.h"
[email protected]e6e90dc2011-12-03 00:01:37166#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
167#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
168#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
169#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
170#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
171#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26172#include "third_party/skia/include/core/SkBitmap.h"
[email protected]ddb034b2012-06-26 20:31:39173#include "ui/base/dialogs/selected_file_info.h"
[email protected]08397d52011-02-05 01:53:38174#include "ui/gfx/native_widget_types.h"
175#include "ui/gfx/point.h"
176#include "ui/gfx/rect.h"
[email protected]f9526d12012-10-18 01:55:03177#include "ui/gfx/size_conversions.h"
[email protected]c4a9e932011-03-05 04:05:55178#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04179#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]bb0e79472012-10-23 04:36:34180#include "webkit/base/file_path_string_conversions.h"
[email protected]b928936b2012-04-13 01:16:16181#include "webkit/dom_storage/dom_storage_types.h"
[email protected]25e18f82010-10-27 16:38:43182#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]18d5be92011-07-25 18:00:19183#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24184#include "webkit/glue/glue_serialize.h"
[email protected]3a3b75a2012-06-01 08:38:36185#include "webkit/glue/web_intent_service_data.h"
[email protected]851334d2012-06-15 22:39:31186#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07187#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29188#include "webkit/glue/webkit_glue.h"
[email protected]b9fd01ba2012-02-28 01:50:40189#include "webkit/glue/weburlresponse_extradata_impl.h"
[email protected]7e8b4d12012-01-20 23:39:51190#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
[email protected]a9288f52011-11-17 05:18:16191#include "webkit/media/webmediaplayer_impl.h"
[email protected]5f04c3532012-09-25 01:28:39192#include "webkit/media/webmediaplayer_ms.h"
[email protected]191eb3f72010-12-21 06:27:50193#include "webkit/plugins/npapi/plugin_list.h"
194#include "webkit/plugins/npapi/webplugin_delegate.h"
195#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
196#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52197#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29198
[email protected]25fb9b32012-04-27 03:21:55199#if defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:03200#include "content/common/android/device_info.h"
201#include "content/renderer/android/address_detector.h"
202#include "content/renderer/android/content_detector.h"
203#include "content/renderer/android/email_detector.h"
204#include "content/renderer/android/phone_number_detector.h"
[email protected]dbd3d212012-07-13 02:17:22205#include "content/renderer/media/stream_texture_factory_impl_android.h"
[email protected]780fc8242012-09-19 20:28:52206#include "content/renderer/media/webmediaplayer_proxy_impl_android.h"
[email protected]20657a82012-08-21 20:23:03207#include "third_party/WebKit/Source/WebKit/chromium/public/WebHitTestResult.h"
[email protected]59363fc92012-09-05 03:46:31208#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoint.h"
209#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatRect.h"
210#include "ui/gfx/rect_f.h"
[email protected]780fc8242012-09-19 20:28:52211#include "webkit/media/android/media_player_bridge_manager_impl.h"
[email protected]25fb9b32012-04-27 03:21:55212#include "webkit/media/android/webmediaplayer_android.h"
[email protected]780fc8242012-09-19 20:28:52213#include "webkit/media/android/webmediaplayer_impl_android.h"
214#include "webkit/media/android/webmediaplayer_in_process_android.h"
[email protected]2d7b82c2012-06-01 05:57:50215#include "webkit/media/android/webmediaplayer_manager_android.h"
[email protected]25fb9b32012-04-27 03:21:55216#elif defined(OS_WIN)
[email protected]6c8afae52009-01-22 02:24:57217// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57218// * theming
[email protected]f78452f2012-05-15 02:07:52219#include "ui/base/native_theme/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03220#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37221#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]f78452f2012-05-15 02:07:52222#include "ui/base/native_theme/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33223#elif defined(OS_MACOSX)
224#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57225#endif
226
[email protected]9892b472010-09-16 00:23:42227using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08228using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21229using WebKit::WebApplicationCacheHost;
230using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26231using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41232using WebKit::WebColor;
233using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59234using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44235using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51236using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55237using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28238using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00239using WebKit::WebDocument;
[email protected]f546640b2012-05-15 00:03:49240using WebKit::WebDOMEvent;
241using WebKit::WebDOMMessageEvent;
[email protected]e80c73b2009-04-07 23:24:58242using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25243using WebKit::WebDragOperation;
244using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51245using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51246using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08247using WebKit::WebExternalPopupMenu;
248using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47249using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22250using WebKit::WebFileSystem;
251using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49252using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59253using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48254using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45255using WebKit::WebFrame;
[email protected]3306f262012-09-21 19:20:42256using WebKit::WebGestureEvent;
[email protected]7e8b4d12012-01-20 23:39:51257using WebKit::WebGraphicsContext3D;
[email protected]ca948a22009-06-25 19:36:17258using WebKit::WebHistoryItem;
[email protected]132e281a2012-07-31 18:32:44259using WebKit::WebHTTPBody;
[email protected]42054a252011-05-17 18:02:13260using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41261using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50262using WebKit::WebInputElement;
[email protected]3306f262012-09-21 19:20:42263using WebKit::WebInputEvent;
[email protected]ffc8bed2012-01-21 01:23:15264using WebKit::WebIntentRequest;
265using WebKit::WebIntentServiceInfo;
[email protected]3d9689372009-09-10 04:29:17266using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28267using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17268using WebKit::WebMediaPlayerClient;
[email protected]2b942c332012-04-25 16:26:26269using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:28270using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28271using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51272using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19273using WebKit::WebPageSerializer;
274using WebKit::WebPageSerializerClient;
[email protected]50da23d02012-04-13 17:47:48275using WebKit::WebPeerConnection00Handler;
276using WebKit::WebPeerConnection00HandlerClient;
277using WebKit::WebPeerConnectionHandler;
278using WebKit::WebPeerConnectionHandlerClient;
[email protected]3d9689372009-09-10 04:29:17279using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36280using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40281using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49282using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09283using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52284using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59285using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51286using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52287using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15288using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40289using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35290using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29291using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17292using WebKit::WebSecurityPolicy;
[email protected]f546640b2012-05-15 00:03:49293using WebKit::WebSerializedScriptValue;
[email protected]2fab253a2009-08-17 23:00:59294using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42295using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02296using WebKit::WebSize;
[email protected]5fa3a062012-03-21 15:39:34297using WebKit::WebSocketStreamHandle;
[email protected]bd92c3a2010-01-13 05:02:34298using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40299using WebKit::WebStorageQuotaCallbacks;
300using WebKit::WebStorageQuotaError;
301using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28302using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51303using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52304using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24305using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28306using WebKit::WebURL;
307using WebKit::WebURLError;
308using WebKit::WebURLRequest;
309using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28310using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03311using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28312using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26313using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26314using appcache::WebApplicationCacheHostImpl;
315using base::Time;
316using base::TimeDelta;
[email protected]e9ff79c2012-10-19 21:31:26317
[email protected]6fdd4182010-10-14 23:59:26318using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23319using webkit_glue::ResourceFetcher;
[email protected]6717bf272012-05-11 23:31:25320using webkit_glue::WebPreferences;
[email protected]b9fd01ba2012-02-28 01:50:40321using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33322
[email protected]20657a82012-08-21 20:23:03323#if defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:03324using WebKit::WebContentDetectionResult;
[email protected]59363fc92012-09-05 03:46:31325using WebKit::WebFloatPoint;
326using WebKit::WebFloatRect;
[email protected]20657a82012-08-21 20:23:03327using WebKit::WebHitTestResult;
328#endif
329
[email protected]e9ff79c2012-10-19 21:31:26330namespace content {
331
initial.commit09911bf2008-07-26 23:55:29332//-----------------------------------------------------------------------------
333
[email protected]310ebd6302011-10-10 19:06:28334typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49335static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02336
[email protected]882daa92009-11-05 16:31:31337// Time, in seconds, we delay before sending content state changes (such as form
338// state and scroll position) to the browser. We delay sending changes to avoid
339// spamming the browser.
340// To avoid having tab/session restore require sending a message to get the
341// current content state during tab closing we use a shorter timeout for the
342// foreground renderer. This means there is a small window of time from which
343// content state is modified and not sent to session restore, but this is
344// better than having to wake up all renderers during shutdown.
345static const int kDelaySecondsForContentStateSyncHidden = 5;
346static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29347
[email protected]e99ef6f2011-10-16 01:13:00348static const size_t kExtraCharsBeforeAndAfterSelection = 100;
349
[email protected]0aa55312008-10-17 21:53:08350// The maximum number of popups that can be spawned from one page.
351static const int kMaximumNumberOfUnacknowledgedPopups = 25;
352
[email protected]c514d6372011-08-16 22:54:44353static const float kScalingIncrement = 0.1f;
354
[email protected]47578fa02011-11-02 19:34:41355static const float kScalingIncrementForGesture = 0.01f;
356
[email protected]20657a82012-08-21 20:23:03357#if defined(OS_ANDROID)
358// Delay between tapping in content and launching the associated android intent.
359// Used to allow users see what has been recognized as content.
360static const size_t kContentIntentDelayMilliseconds = 700;
361#endif
362
[email protected]8d41d7612012-11-14 20:32:19363static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) =
364 NULL;
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) {
[email protected]bf692cd2012-11-14 19:10:02380 // Replace any occurrences of swappedout:// with about:blank.
381 const WebURL& blank_url = GURL(chrome::kAboutBlankURL);
[email protected]726985e22009-06-18 21:09:28382 WebVector<WebURL> urls;
383 ds->redirectChain(urls);
384 result->reserve(urls.size());
[email protected]bf692cd2012-11-14 19:10:02385 for (size_t i = 0; i < urls.size(); ++i) {
386 if (urls[i] != GURL(kSwappedOutURL))
387 result->push_back(urls[i]);
388 else
389 result->push_back(blank_url);
390 }
[email protected]726985e22009-06-18 21:09:28391}
392
[email protected]007733c2011-11-17 00:34:07393// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44394// the AltErrorPageResourceFetcher is reset.
395static void StopAltErrorPageFetcher(WebDataSource* data_source) {
396 if (data_source) {
[email protected]007733c2011-11-17 00:34:07397 DocumentState* document_state = DocumentState::FromDataSource(data_source);
398 if (document_state)
399 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44400 }
401}
402
[email protected]007733c2011-11-17 00:34:07403static bool IsReload(const ViewMsg_Navigate_Params& params) {
404 return
405 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
[email protected]7c16976c2012-08-04 02:38:23406 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE ||
407 params.navigation_type ==
408 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]007733c2011-11-17 00:34:07409}
410
[email protected]b9fd01ba2012-02-28 01:50:40411static WebReferrerPolicy GetReferrerPolicyFromRequest(
[email protected]ca662822012-05-11 17:53:59412 WebFrame* frame,
[email protected]445e1042011-12-03 21:03:15413 const WebURLRequest& request) {
414 return request.extraData() ?
415 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
[email protected]ca662822012-05-11 17:53:59416 frame->document().referrerPolicy();
[email protected]445e1042011-12-03 21:03:15417}
418
[email protected]b9fd01ba2012-02-28 01:50:40419static WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
420 const WebURLResponse& response) {
421 return static_cast<WebURLResponseExtraDataImpl*>(
422 response.extraData());
423}
424
[email protected]2149cc622012-02-14 01:12:12425NOINLINE static void CrashIntentionally() {
426 // NOTE(shess): Crash directly rather than using NOTREACHED() so
427 // that the signature is easier to triage in crash reports.
428 volatile int* zero = NULL;
429 *zero = 0;
430}
431
[email protected]8bf1048012012-02-08 01:22:18432static void MaybeHandleDebugURL(const GURL& url) {
433 if (!url.SchemeIs(chrome::kChromeUIScheme))
434 return;
435 if (url == GURL(chrome::kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12436 CrashIntentionally();
[email protected]8bf1048012012-02-08 01:22:18437 } else if (url == GURL(chrome::kChromeUIKillURL)) {
438 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
439 } else if (url == GURL(chrome::kChromeUIHangURL)) {
440 for (;;) {
441 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
442 }
[email protected]50f86bc2012-11-01 19:59:13443 } else if (url == GURL(kChromeUIShorthangURL)) {
[email protected]8bf1048012012-02-08 01:22:18444 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
445 }
446}
447
[email protected]fd3238af2012-05-22 18:55:30448// Returns false unless this is a top-level navigation.
449static bool IsTopLevelNavigation(WebFrame* frame) {
450 return frame->parent() == NULL;
451}
452
453// Returns false unless this is a top-level navigation that crosses origins.
454static bool IsNonLocalTopLevelNavigation(const GURL& url,
455 WebFrame* frame,
456 WebNavigationType type) {
457 if (!IsTopLevelNavigation(frame))
458 return false;
459
460 // Navigations initiated within Webkit are not sent out to the external host
461 // in the following cases.
462 // 1. The url scheme is not http/https
463 // 2. The origin of the url and the opener is the same in which case the
464 // opener relationship is maintained.
465 // 3. Reloads/form submits/back forward navigations
466 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
467 return false;
468
469 // Not interested in reloads/form submits/resubmits/back forward navigations.
470 if (type != WebKit::WebNavigationTypeReload &&
471 type != WebKit::WebNavigationTypeFormSubmitted &&
472 type != WebKit::WebNavigationTypeFormResubmitted &&
473 type != WebKit::WebNavigationTypeBackForward) {
474 // The opener relationship between the new window and the parent allows the
475 // new window to script the parent and vice versa. This is not allowed if
476 // the origins of the two domains are different. This can be treated as a
477 // top level navigation and routed back to the host.
478 WebKit::WebFrame* opener = frame->opener();
479 if (!opener) {
480 return true;
481 }
482
483 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
484 return true;
485 }
486 return false;
487}
488
[email protected]38761452012-10-18 16:31:59489static void NotifyTimezoneChange(WebKit::WebFrame* frame) {
490 v8::HandleScope handle_scope;
491 v8::Context::Scope context_scope(frame->mainWorldScriptContext());
492 v8::Date::DateTimeConfigurationChangeNotification();
493 WebKit::WebFrame* child = frame->firstChild();
494 for (; child; child = child->nextSibling())
495 NotifyTimezoneChange(child);
496}
497
initial.commit09911bf2008-07-26 23:55:29498///////////////////////////////////////////////////////////////////////////////
499
[email protected]310ebd6302011-10-10 19:06:28500struct RenderViewImpl::PendingFileChooser {
[email protected]e9ff79c2012-10-19 21:31:26501 PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c)
[email protected]cdaf8d02010-03-30 19:52:47502 : params(p),
503 completion(c) {
504 }
[email protected]e9ff79c2012-10-19 21:31:26505 FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47506 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
507};
508
[email protected]217690d2012-01-27 07:33:11509namespace {
510
511class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
512 public:
[email protected]82114f52012-03-20 22:53:41513 explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget)
[email protected]217690d2012-01-27 07:33:11514 : webwidget_(webwidget) {}
515
516 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
517 if (succeeded)
518 webwidget_->didAcquirePointerLock();
519 else
520 webwidget_->didNotAcquirePointerLock();
521 }
522
523 virtual void OnMouseLockLost() OVERRIDE {
524 webwidget_->didLosePointerLock();
525 }
526
527 virtual bool HandleMouseLockedInputEvent(
528 const WebKit::WebMouseEvent &event) OVERRIDE {
529 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
530 return false;
531 }
532
533 private:
534 WebKit::WebWidget* webwidget_;
535};
536
[email protected]86cd9472012-02-03 19:51:05537int64 ExtractPostId(const WebHistoryItem& item) {
538 if (item.isNull())
539 return -1;
540
541 if (item.httpBody().isNull())
542 return -1;
543
544 return item.httpBody().identifier();
545}
546
[email protected]217690d2012-01-27 07:33:11547} // namespace
548
[email protected]8d41d7612012-11-14 20:32:19549RenderViewImpl::RenderViewImpl(RenderViewImplParams* params)
550 : RenderWidget(WebKit::WebPopupTypeNone,
551 params->screen_info,
552 params->swapped_out),
553 webkit_preferences_(params->webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02554 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09555 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02556 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24557 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21558 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02559 opened_by_user_gesture_(true),
560 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24561 page_id_(-1),
562 last_page_id_sent_to_browser_(-1),
[email protected]8d41d7612012-11-14 20:32:19563 next_page_id_(params->next_page_id),
[email protected]3cc72b12010-03-18 23:03:00564 history_list_offset_(-1),
565 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02566 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55567 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31568 cached_is_main_frame_pinned_to_left_(false),
569 cached_is_main_frame_pinned_to_right_(false),
570 cached_has_main_frame_horizontal_scrollbar_(false),
571 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]3354d3e2010-06-10 19:53:02572 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51573 geolocation_dispatcher_(NULL),
[email protected]c52b2892012-03-07 11:01:02574 input_tag_speech_dispatcher_(NULL),
[email protected]64d09222012-05-25 10:10:34575 speech_recognition_dispatcher_(NULL),
[email protected]676126f72011-01-15 00:03:51576 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51577 media_stream_dispatcher_(NULL),
[email protected]1bc65a42012-04-23 09:31:25578 media_stream_impl_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41579 devtools_agent_(NULL),
[email protected]2a84f9d2012-06-05 21:50:43580 accessibility_mode_(AccessibilityModeOff),
[email protected]063afcb2011-09-29 07:54:32581 renderer_accessibility_(NULL),
[email protected]7e9c5bb02012-05-14 13:58:31582 java_bridge_dispatcher_(NULL),
[email protected]217690d2012-01-27 07:33:11583 mouse_lock_dispatcher_(NULL),
[email protected]20657a82012-08-21 20:23:03584#if defined(OS_ANDROID)
[email protected]4d0f8182012-10-19 23:14:47585 body_background_color_(SK_ColorWHITE),
[email protected]198f64122012-11-05 13:09:31586 update_frame_info_scheduled_(false),
[email protected]20657a82012-08-21 20:23:03587 expected_content_intent_id_(0),
[email protected]780fc8242012-09-19 20:28:52588 media_player_proxy_(NULL),
[email protected]55750b32012-09-21 14:05:03589 synchronous_find_active_match_ordinal_(-1),
[email protected]8e603cd92012-10-23 22:29:26590 ALLOW_THIS_IN_INITIALIZER_LIST(
591 load_progress_tracker_(new LoadProgressTracker(this))),
[email protected]20657a82012-08-21 20:23:03592#endif
[email protected]8d41d7612012-11-14 20:32:19593 session_storage_namespace_id_(params->session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18594 handling_select_range_(false),
595#if defined(OS_WIN)
596 focused_plugin_id_(-1),
597#endif
[email protected]0720b532012-08-28 19:23:37598 updating_frame_tree_(false),
599 pending_frame_tree_update_(false),
600 target_process_id_(0),
601 target_routing_id_(0),
[email protected]ef5e98e2011-12-06 09:49:18602 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]8d41d7612012-11-14 20:32:19603 set_throttle_input_events(params->renderer_prefs.throttle_input_events);
604 routing_id_ = params->routing_id;
605 surface_id_ = params->surface_id;
606 if (params->opener_id != MSG_ROUTING_NONE && params->is_renderer_created)
607 opener_id_ = params->opener_id;
[email protected]676126f72011-01-15 00:03:51608
[email protected]74ce1ad2011-12-16 21:51:46609 // Ensure we start with a valid next_page_id_ from the browser.
610 DCHECK_GE(next_page_id_, 0);
611
[email protected]21b3a6ae2011-11-30 00:45:29612#if defined(ENABLE_NOTIFICATIONS)
613 notification_provider_ = new NotificationProvider(this);
614#else
615 notification_provider_ = NULL;
616#endif
617
[email protected]11fee2332011-03-29 20:36:35618 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11619 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35620
[email protected]20657a82012-08-21 20:23:03621 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
622
623#if defined(OS_ANDROID)
[email protected]e9ff79c2012-10-19 21:31:26624 scoped_ptr<DeviceInfo> device_info(new DeviceInfo());
[email protected]20657a82012-08-21 20:23:03625
[email protected]43b06002012-10-11 17:13:26626 webview()->setDeviceScaleFactor(device_info->GetDPIScale());
627
[email protected]20657a82012-08-21 20:23:03628 const std::string region_code =
629 command_line.HasSwitch(switches::kNetworkCountryIso)
630 ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso)
631 : device_info->GetNetworkCountryIso();
632 content_detectors_.push_back(linked_ptr<ContentDetector>(
633 new AddressDetector()));
634 content_detectors_.push_back(linked_ptr<ContentDetector>(
635 new PhoneNumberDetector(region_code)));
636 content_detectors_.push_back(linked_ptr<ContentDetector>(
637 new EmailDetector()));
638#endif
639
[email protected]8d41d7612012-11-14 20:32:19640 if (params->counter) {
641 shared_popup_counter_ = params->counter;
[email protected]14392a52012-05-02 20:28:44642 // Only count this if it isn't swapped out upon creation.
[email protected]8d41d7612012-11-14 20:32:19643 if (!params->swapped_out)
[email protected]14392a52012-05-02 20:28:44644 shared_popup_counter_->data++;
[email protected]676126f72011-01-15 00:03:51645 decrement_shared_popup_at_destruction_ = true;
646 } else {
647 shared_popup_counter_ = new SharedRenderViewCounter(0);
648 decrement_shared_popup_at_destruction_ = false;
649 }
650
[email protected]380244092011-10-07 17:26:27651 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51652 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47653 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51654 AddRef();
655
656 // If this is a popup, we must wait for the CreatingNew_ACK message before
657 // completing initialization. Otherwise, we can finish it now.
[email protected]6cd7c6b2012-10-25 03:26:23658 if (opener_id_ == MSG_ROUTING_NONE) {
[email protected]676126f72011-01-15 00:03:51659 did_show_ = true;
[email protected]fc4404d2012-11-07 19:53:30660 CompleteInit();
[email protected]676126f72011-01-15 00:03:51661 }
662
[email protected]34c61bd52011-05-02 19:38:33663 g_view_map.Get().insert(std::make_pair(webview(), this));
[email protected]60051ec2012-06-08 22:40:57664 webview()->setDeviceScaleFactor(device_scale_factor_);
[email protected]34c61bd52011-05-02 19:38:33665 webkit_preferences_.Apply(webview());
666 webview()->initializeMainFrame(this);
[email protected]8d41d7612012-11-14 20:32:19667 if (!params->frame_name.empty())
668 webview()->mainFrame()->setName(params->frame_name);
[email protected]34c61bd52011-05-02 19:38:33669 webview()->settings()->setMinimumTimerInterval(
670 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
671 webkit_glue::kForegroundTabTimerInterval);
672
[email protected]8d41d7612012-11-14 20:32:19673 OnSetRendererPrefs(params->renderer_prefs);
[email protected]34c61bd52011-05-02 19:38:33674
[email protected]4fb0f202012-05-30 22:44:53675#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02676 if (!media_stream_dispatcher_)
677 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32678#endif
[email protected]735873d2012-01-25 23:31:02679
[email protected]8f6a3b852011-07-19 16:48:56680 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32681#if defined(OS_MACOSX)
682 new TextInputClientObserver(this);
683#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56684
[email protected]2d7b82c2012-06-01 05:57:50685#if defined(OS_ANDROID)
686 media_player_manager_.reset(
687 new webkit_media::WebMediaPlayerManagerAndroid());
688#endif
689
[email protected]217690d2012-01-27 07:33:11690 // The next group of objects all implement RenderViewObserver, so are deleted
691 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41692 devtools_agent_ = new DevToolsAgent(this);
[email protected]89054502012-06-03 10:29:24693 mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
[email protected]0fc7dea72012-02-09 03:47:40694 intents_host_ = new WebIntentsHost(this);
[email protected]063afcb2011-09-29 07:54:32695
[email protected]2a84f9d2012-06-05 21:50:43696 // Create renderer_accessibility_ if needed.
[email protected]8d41d7612012-11-14 20:32:19697 OnSetAccessibilityMode(params->accessibility_mode);
[email protected]2a84f9d2012-06-05 21:50:43698
[email protected]1784b2f2011-11-24 10:53:48699 new IdleUserDetector(this);
700
[email protected]766a7082012-02-03 23:39:15701 if (command_line.HasSwitch(switches::kDomAutomationController))
[email protected]e9ff79c2012-10-19 21:31:26702 enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION;
[email protected]766a7082012-02-03 23:39:15703
[email protected]5b52cd2f712012-03-28 02:12:48704 ProcessViewLayoutFlags(command_line);
[email protected]7ddea9802012-02-22 23:08:05705
[email protected]e9ff79c2012-10-19 21:31:26706 GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44707
708 // If we have an opener_id but we weren't created by a renderer, then
709 // it's the browser asking us to set our opener to another RenderView.
[email protected]8d41d7612012-11-14 20:32:19710 if (params->opener_id != MSG_ROUTING_NONE && !params->is_renderer_created) {
711 RenderViewImpl* opener_view = FromRoutingID(params->opener_id);
[email protected]f546640b2012-05-15 00:03:49712 if (opener_view)
713 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
[email protected]14392a52012-05-02 20:28:44714 }
715
716 // If we are initially swapped out, navigate to kSwappedOutURL.
717 // This ensures we are in a unique origin that others cannot script.
718 if (is_swapped_out_)
[email protected]0720b532012-08-28 19:23:37719 NavigateToSwappedOutURL(webview()->mainFrame());
initial.commit09911bf2008-07-26 23:55:29720}
721
[email protected]310ebd6302011-10-10 19:06:28722RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03723 history_page_ids_.clear();
724
[email protected]0aa55312008-10-17 21:53:08725 if (decrement_shared_popup_at_destruction_)
726 shared_popup_counter_->data--;
727
[email protected]a1128322009-10-06 18:38:46728 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47729 while (!file_chooser_completions_.empty()) {
730 if (file_chooser_completions_.front()->completion) {
731 file_chooser_completions_.front()->completion->didChooseFile(
732 WebVector<WebString>());
733 }
734 file_chooser_completions_.pop_front();
735 }
[email protected]a1128322009-10-06 18:38:46736
[email protected]83dde542009-09-11 20:59:55737#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11738 // Destroy all fake plugin window handles on the browser side.
739 while (!fake_plugin_window_handles_.empty()) {
740 // Make sure no NULL plugin window handles were inserted into this list.
741 DCHECK(*fake_plugin_window_handles_.begin());
742 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
743 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
744 }
[email protected]83dde542009-09-11 20:59:55745#endif
[email protected]98324892009-09-09 21:16:05746
[email protected]60c42a8c72009-10-09 04:08:59747#ifndef NDEBUG
748 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49749 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59750 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
751 DCHECK_NE(this, it->second) << "Failed to call Close?";
752#endif
[email protected]676126f72011-01-15 00:03:51753
[email protected]310ebd6302011-10-10 19:06:28754 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51755 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59756}
757
758/*static*/
[email protected]310ebd6302011-10-10 19:06:28759RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31760 ViewMap* views = g_view_map.Pointer();
761 ViewMap::iterator it = views->find(webview);
762 return it == views->end() ? NULL : it->second;
763}
764
765/*static*/
[email protected]e9ff79c2012-10-19 21:31:26766RenderView* RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28767 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31768}
769
770/*static*/
[email protected]e9ff79c2012-10-19 21:31:26771void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49772 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59773 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
774 if (!visitor->Visit(it->second))
775 return;
776 }
777}
778
779/*static*/
[email protected]310ebd6302011-10-10 19:06:28780RenderViewImpl* RenderViewImpl::Create(
[email protected]0aa55312008-10-17 21:53:08781 int32 opener_id,
[email protected]e9ff79c2012-10-19 21:31:26782 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08783 const WebPreferences& webkit_prefs,
784 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34785 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56786 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26787 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46788 const string16& frame_name,
[email protected]14392a52012-05-02 20:28:44789 bool is_renderer_created,
790 bool swapped_out,
[email protected]6fd35b72012-03-01 19:46:41791 int32 next_page_id,
[email protected]842f10652012-06-06 01:54:04792 const WebKit::WebScreenInfo& screen_info,
[email protected]3e3c4522012-04-13 21:16:29793 AccessibilityMode accessibility_mode) {
initial.commit09911bf2008-07-26 23:55:29794 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]8d41d7612012-11-14 20:32:19795 RenderViewImplParams params(
[email protected]676126f72011-01-15 00:03:51796 opener_id,
797 renderer_prefs,
798 webkit_prefs,
799 counter,
800 routing_id,
[email protected]9f4f3322012-01-18 22:29:56801 surface_id,
[email protected]676126f72011-01-15 00:03:51802 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46803 frame_name,
[email protected]14392a52012-05-02 20:28:44804 is_renderer_created,
805 swapped_out,
[email protected]6fd35b72012-03-01 19:46:41806 next_page_id,
[email protected]842f10652012-06-06 01:54:04807 screen_info,
[email protected]3e3c4522012-04-13 21:16:29808 accessibility_mode);
[email protected]8d41d7612012-11-14 20:32:19809 if (g_create_render_view_impl)
810 return g_create_render_view_impl(&params);
811 return new RenderViewImpl(&params);
812}
813
814// static
815void RenderViewImpl::InstallCreateHook(
816 RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*)) {
817 CHECK(!g_create_render_view_impl);
818 g_create_render_view_impl = create_render_view_impl;
initial.commit09911bf2008-07-26 23:55:29819}
820
[email protected]310ebd6302011-10-10 19:06:28821void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51822 observers_.AddObserver(observer);
823}
824
[email protected]310ebd6302011-10-10 19:06:28825void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
826 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51827 observers_.RemoveObserver(observer);
828}
829
[email protected]310ebd6302011-10-10 19:06:28830WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26831 return static_cast<WebKit::WebView*>(webwidget());
832}
833
[email protected]310ebd6302011-10-10 19:06:28834void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51835 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29836}
837
[email protected]310ebd6302011-10-10 19:06:28838void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26839 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30840 // If the renderer is visible, set initial visibility and focus state.
841 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34842#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30843 delegate->SetContainerVisibility(true);
844 if (webview() && webview()->isActive())
845 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34846#endif
[email protected]49232292010-09-03 19:07:30847 }
[email protected]784ea1ab2010-09-18 00:02:34848 // Plugins start assuming the content has focus (so that they work in
849 // environments where RenderView isn't hosting them), so we always have to
850 // set the initial state. See webplugin_delegate_impl.h for details.
851 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26852}
853
[email protected]310ebd6302011-10-10 19:06:28854void RenderViewImpl::UnregisterPluginDelegate(
855 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26856 plugin_delegates_.erase(delegate);
857}
[email protected]d8fd6fa2010-02-01 15:54:26858
[email protected]310ebd6302011-10-10 19:06:28859bool RenderViewImpl::GetPluginInfo(const GURL& url,
860 const GURL& page_url,
861 const std::string& mime_type,
862 webkit::WebPluginInfo* plugin_info,
863 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08864 bool found = false;
865 Send(new ViewHostMsg_GetPluginInfo(
866 routing_id_, url, page_url, mime_type, &found, plugin_info,
867 actual_mime_type));
868 return found;
869}
870
[email protected]7a1ec28a2012-03-28 21:10:24871void RenderViewImpl::TransferActiveWheelFlingAnimation(
872 const WebKit::WebActiveWheelFlingParameters& params) {
873 if (webview())
874 webview()->transferActiveWheelFlingAnimation(params);
875}
876
[email protected]8fe8f742012-06-14 00:36:08877bool RenderViewImpl::HasIMETextFocus() {
878 return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
879}
880
[email protected]310ebd6302011-10-10 19:06:28881bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27882 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27883 if (main_frame)
[email protected]e9ff79c2012-10-19 21:31:26884 GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26885
[email protected]676126f72011-01-15 00:03:51886 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
887 RenderViewObserver* observer;
888 while ((observer = it.GetNext()) != NULL)
889 if (observer->OnMessageReceived(message))
890 return true;
[email protected]b2abac72009-02-26 12:39:28891
[email protected]a95986a82010-12-24 06:19:28892 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40893 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28894 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29895 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
896 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56897 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29898 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
899 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
900 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
901 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
902 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15903 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29904 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
905 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
906 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]45a599062012-09-07 20:09:06907 IPC_MESSAGE_HANDLER(ViewMsg_ReplaceAll, OnReplaceAll)
908 IPC_MESSAGE_HANDLER(ViewMsg_Unselect, OnUnselect)
909 IPC_MESSAGE_HANDLER(ViewMsg_SetEditableSelectionOffsets,
910 OnSetEditableSelectionOffsets)
911 IPC_MESSAGE_HANDLER(ViewMsg_SetCompositionFromExistingText,
912 OnSetCompositionFromExistingText)
913 IPC_MESSAGE_HANDLER(ViewMsg_ExtendSelectionAndDelete,
914 OnExtendSelectionAndDelete)
[email protected]4fb60142011-08-09 02:22:08915 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29916 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15917 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29918 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49919 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
[email protected]630e26b2008-10-14 22:55:17920 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17921 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41922 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54923 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
924 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29925 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18926 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
927 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29928 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]f546640b2012-05-15 00:03:49929 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
[email protected]1810e132009-03-24 23:35:48930 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55931 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
932 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
933 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
934 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
935 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
936 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
937 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45938 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40939 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29940 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19941 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
942 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29943 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
944 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
[email protected]38761452012-10-18 16:31:59945 IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone)
initial.commit09911bf2008-07-26 23:55:29946 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51947 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
948 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29949 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04950 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15951 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29952 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
953 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08954 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
955 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00956 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16957 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14958 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25959 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
960 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:47961 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:34962 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:10963 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
964 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51965 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56966 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]77829642012-05-15 14:47:17967 IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent,
968 OnOrientationChangeEvent)
[email protected]81375e872012-01-11 21:40:36969 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:34970 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]7a17bac02012-03-07 21:58:12971 IPC_MESSAGE_HANDLER(ViewMsg_SetNavigationStartTime,
972 OnSetNavigationStartTime)
[email protected]446705872009-09-10 07:22:48973 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33974 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33975 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
976 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24977 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42978 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
979 OnPpapiBrokerChannelCreated)
[email protected]d8415ad92012-08-23 14:40:50980 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult,
981 OnPpapiBrokerPermissionResult)
[email protected]18d5be92011-07-25 18:00:19982 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
983 OnGetAllSavableResourceLinksForCurrentPage)
984 IPC_MESSAGE_HANDLER(
985 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
986 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]521b2482011-01-15 00:10:10987 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51988 // TODO(viettrungluu): Move to a separate message filter.
[email protected]9e1ad4b2011-08-14 16:49:19989 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
990 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18991 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]7f3c7af2011-10-20 22:52:51992 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]2a84f9d2012-06-05 21:50:43993 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode)
[email protected]0720b532012-08-28 19:23:37994 IPC_MESSAGE_HANDLER(ViewMsg_UpdateFrameTree, OnUpdatedFrameTree)
[email protected]55750b32012-09-21 14:05:03995#if defined(OS_ANDROID)
996 IPC_MESSAGE_HANDLER(ViewMsg_ActivateNearestFindResult,
997 OnActivateNearestFindResult)
998 IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects)
999 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
1000 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewMsg_SynchronousFind, OnSynchronousFind)
[email protected]9b7d11e2012-10-08 19:24:141001 IPC_MESSAGE_HANDLER(ViewMsg_UndoScrollFocusedEditableNodeIntoView,
1002 OnUndoScrollFocusedEditableNodeIntoRect)
[email protected]55750b32012-09-21 14:05:031003#elif defined(OS_MACOSX)
1004 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
1005 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1006 OnPluginImeCompositionCompleted)
1007 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1008 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
1009 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
1010 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
1011#endif
[email protected]f9526d12012-10-18 01:55:031012 IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB,
1013 OnReleaseDisambiguationPopupDIB)
[email protected]9e1ad4b2011-08-14 16:49:191014
initial.commit09911bf2008-07-26 23:55:291015 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281016 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291017 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401018
1019 if (!msg_is_ok) {
1020 // The message had a handler, but its deserialization failed.
1021 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:281022 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:401023 }
1024
[email protected]a95986a82010-12-24 06:19:281025 return handled;
initial.commit09911bf2008-07-26 23:55:291026}
1027
[email protected]310ebd6302011-10-10 19:06:281028void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]8bf1048012012-02-08 01:22:181029 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:291030 if (!webview())
1031 return;
1032
[email protected]440a0e52011-09-13 17:38:581033 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
1034
[email protected]007733c2011-11-17 00:34:071035 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:031036
1037 // If this is a stale back/forward (due to a recent navigation the browser
1038 // didn't know about), ignore it.
1039 if (IsBackForwardToStaleEntry(params, is_reload))
1040 return;
1041
[email protected]992db4c2011-05-12 15:37:151042 // Swap this renderer back in if necessary.
[email protected]961541a92012-06-01 21:15:281043 if (is_swapped_out_) {
1044 // We marked the view as hidden when swapping the view out, so be sure to
1045 // reset the visibility state before navigating to the new URL.
1046 webview()->setVisibilityState(visibilityState(), false);
[email protected]992db4c2011-05-12 15:37:151047 SetSwappedOut(false);
[email protected]961541a92012-06-01 21:15:281048 }
[email protected]992db4c2011-05-12 15:37:151049
[email protected]3cc72b12010-03-18 23:03:001050 history_list_offset_ = params.current_history_list_offset;
1051 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:031052 if (history_list_length_ >= 0)
1053 history_page_ids_.resize(history_list_length_, -1);
1054 if (params.pending_history_list_offset >= 0 &&
1055 params.pending_history_list_offset < history_list_length_)
1056 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:001057
[email protected]e9ff79c2012-10-19 21:31:261058 GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:291059
[email protected]26aa0482009-09-30 16:55:271060 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451061 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291062 // We cannot reload if we do not have any history state. This happens, for
1063 // example, when recovering from a crash. Our workaround here is a bit of
1064 // a hack since it means that reload after a crashed tab does not cause an
1065 // end-to-end cache validation.
1066 is_reload = false;
1067 }
1068
[email protected]007733c2011-11-17 00:34:071069 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
1070 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:501071
[email protected]04d3c6e2009-05-22 17:00:131072 // If we are reloading, then WebKit will use the history state of the current
1073 // page, so we should just ignore any given history state. Otherwise, if we
1074 // have history state, then we need to navigate to it, which corresponds to a
1075 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551076 if (is_reload) {
[email protected]7c16976c2012-08-04 02:38:231077 bool reload_original_url =
1078 (params.navigation_type ==
1079 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]ecbf10d2010-02-18 13:03:291080 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:021081 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]7c16976c2012-08-04 02:38:231082
1083 if (reload_original_url)
1084 main_frame->reloadWithOverrideURL(params.url, true);
1085 else
1086 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551087 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131088 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581089 DCHECK_NE(params.page_id, -1);
[email protected]f707573e62012-10-18 09:38:071090 WebHistoryItem item = webkit_glue::HistoryItemFromString(params.state);
[email protected]bf692cd2012-11-14 19:10:021091 if (!item.isNull()) {
1092 // Ensure we didn't save the swapped out URL in UpdateState, since the
1093 // browser should never be telling us to navigate to swappedout://.
1094 CHECK(item.urlString() != WebString::fromUTF8(kSwappedOutURL));
[email protected]f707573e62012-10-18 09:38:071095 main_frame->loadHistoryItem(item);
[email protected]bf692cd2012-11-14 19:10:021096 }
[email protected]d1ef81d2012-07-24 11:39:361097 } else if (!params.base_url_for_data_url.is_empty()) {
1098 // A loadData request with a specified base URL.
1099 std::string mime_type, charset, data;
1100 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) {
1101 main_frame->loadData(
1102 WebData(data.c_str(), data.length()),
1103 WebString::fromUTF8(mime_type),
1104 WebString::fromUTF8(charset),
1105 params.base_url_for_data_url,
1106 params.history_url_for_data_url,
1107 false);
1108 } else {
1109 CHECK(false) <<
1110 "Invalid URL passed: " << params.url.possibly_invalid_spec();
1111 }
[email protected]04d3c6e2009-05-22 17:00:131112 } else {
1113 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281114 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291115
[email protected]e6f546c32009-07-01 17:12:551116 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:231117 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131118
[email protected]dd7daa82009-08-10 05:46:451119 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551120 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131121
[email protected]445e1042011-12-03 21:03:151122 if (params.referrer.url.is_valid()) {
1123 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
1124 params.referrer.policy,
1125 params.url,
1126 WebString::fromUTF8(params.referrer.url.spec()));
1127 if (!referrer.isEmpty())
1128 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:281129 }
[email protected]04d3c6e2009-05-22 17:00:131130
[email protected]52c68652010-12-07 17:47:041131 if (!params.extra_headers.empty()) {
1132 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1133 params.extra_headers.end(), "\n");
1134 i.GetNext(); ) {
1135 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1136 WebString::fromUTF8(i.values()));
1137 }
1138 }
[email protected]132e281a2012-07-31 18:32:441139
1140 if (params.is_post) {
1141 request.setHTTPMethod(WebString::fromUTF8("POST"));
1142
1143 // Set post data.
1144 WebHTTPBody http_body;
1145 http_body.initialize();
1146 http_body.appendData(WebData(
1147 reinterpret_cast<const char*>(
1148 &params.browser_initiated_post_data.front()),
1149 params.browser_initiated_post_data.size()));
1150 request.setHTTPBody(http_body);
1151 }
1152
[email protected]dd7daa82009-08-10 05:46:451153 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501154 }
1155
[email protected]77f17a82009-05-21 04:42:541156 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:071157 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:291158}
1159
[email protected]310ebd6302011-10-10 19:06:281160bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:031161 const ViewMsg_Navigate_Params& params,
1162 bool is_reload) {
1163 // Make sure this isn't a back/forward to an entry we have already cropped
1164 // or replaced from our history, before the browser knew about it. If so,
1165 // a new navigation has committed in the mean time, and we can ignore this.
1166 bool is_back_forward = !is_reload && !params.state.empty();
1167
1168 // Note: if the history_list_length_ is 0 for a back/forward, we must be
1169 // restoring from a previous session. We'll update our state in OnNavigate.
1170 if (!is_back_forward || history_list_length_ <= 0)
1171 return false;
1172
1173 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
1174
1175 // Check for whether the forward history has been cropped due to a recent
1176 // navigation the browser didn't know about.
1177 if (params.pending_history_list_offset >= history_list_length_)
1178 return true;
1179
1180 // Check for whether this entry has been replaced with a new one.
1181 int expected_page_id =
1182 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:441183 if (expected_page_id > 0 && params.page_id != expected_page_id) {
1184 if (params.page_id < expected_page_id)
1185 return true;
1186
1187 // Otherwise we've removed an earlier entry and should have shifted all
1188 // entries left. For now, it's ok to lazily update the list.
1189 // TODO(creis): Notify all live renderers when we remove entries from
1190 // the front of the list, so that we don't hit this case.
1191 history_page_ids_[params.pending_history_list_offset] = params.page_id;
1192 }
[email protected]d466b8a2011-07-15 21:48:031193
1194 return false;
1195}
1196
initial.commit09911bf2008-07-26 23:55:291197// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:281198void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:441199 if (webview()) {
1200 WebFrame* main_frame = webview()->mainFrame();
1201 // Stop the alt error page fetcher. If we let it continue it may complete
1202 // and cause RenderViewHostManager to swap to this RenderView, even though
1203 // it may no longer be active.
1204 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
1205 StopAltErrorPageFetcher(main_frame->dataSource());
1206 main_frame->stopLoading();
1207 }
initial.commit09911bf2008-07-26 23:55:291208}
1209
[email protected]ecbf10d2010-02-18 13:03:291210// Reload current focused frame.
1211// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:281212void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291213 if (webview() && webview()->focusedFrame()) {
1214 // We always obey the cache (ignore_cache=false) here.
1215 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1216 // a cache-ignoring reload of the frame.
1217 webview()->focusedFrame()->reload(false);
1218 }
[email protected]1dda4022010-01-28 18:24:561219}
1220
[email protected]310ebd6302011-10-10 19:06:281221void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271222 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291223}
1224
[email protected]310ebd6302011-10-10 19:06:281225void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:251226 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271227 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251228 return;
1229
[email protected]26aa0482009-09-30 16:55:271230 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451231 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251232}
1233
[email protected]310ebd6302011-10-10 19:06:281234void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291235 // Check if there is a targeturl waiting to be sent.
1236 if (target_url_status_ == TARGET_PENDING) {
1237 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1238 pending_target_url_));
1239 }
1240
1241 target_url_status_ = TARGET_NONE;
1242}
1243
[email protected]310ebd6302011-10-10 19:06:281244void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:291245 if (!webview())
1246 return;
1247
[email protected]26aa0482009-09-30 16:55:271248 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:291249}
1250
[email protected]310ebd6302011-10-10 19:06:281251void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:291252 if (!webview())
1253 return;
1254
[email protected]26aa0482009-09-30 16:55:271255 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:291256}
1257
[email protected]310ebd6302011-10-10 19:06:281258void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:291259 if (!webview())
1260 return;
1261
[email protected]26aa0482009-09-30 16:55:271262 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:291263}
1264
[email protected]310ebd6302011-10-10 19:06:281265void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291266 if (!webview())
1267 return;
1268
[email protected]f6b1856b2011-06-29 22:02:531269 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
1270 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:291271}
1272
[email protected]c0cc3092009-09-12 08:27:271273#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281274void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:351275 if (!webview())
1276 return;
1277
1278 // Since the find pasteboard supports only plain text, this can be simpler
1279 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271280 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351281 if (frame->hasSelection()) {
1282 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:271283 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:171284 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:351285 }
[email protected]a954bf72009-09-12 07:30:351286}
[email protected]c0cc3092009-09-12 08:27:271287#endif
[email protected]a954bf72009-09-12 07:30:351288
[email protected]310ebd6302011-10-10 19:06:281289void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291290 if (!webview())
1291 return;
1292
[email protected]26aa0482009-09-30 16:55:271293 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:291294}
1295
[email protected]44bf7002011-10-16 02:46:151296void RenderViewImpl::OnPasteAndMatchStyle() {
1297 if (!webview())
1298 return;
1299
1300 webview()->focusedFrame()->executeCommand(
1301 WebString::fromUTF8("PasteAndMatchStyle"));
1302}
1303
[email protected]310ebd6302011-10-10 19:06:281304void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291305 if (!webview())
1306 return;
1307
[email protected]1ff7a032010-02-03 02:46:031308 WebFrame* frame = webview()->focusedFrame();
1309 if (!frame->hasSelection())
1310 frame->selectWordAroundCaret();
1311 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291312}
1313
[email protected]310ebd6302011-10-10 19:06:281314void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:291315 if (!webview())
1316 return;
1317
[email protected]26aa0482009-09-30 16:55:271318 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:291319}
1320
[email protected]310ebd6302011-10-10 19:06:281321void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291322 if (!webview())
1323 return;
1324
[email protected]26aa0482009-09-30 16:55:271325 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221326 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:291327}
1328
[email protected]45a599062012-09-07 20:09:061329void RenderViewImpl::OnReplaceAll(const string16& text) {
1330 WebNode node = GetFocusedNode();
1331 if (node.isNull() || !IsEditableNode(node))
1332 return;
1333
1334 OnSelectAll();
1335 OnReplace(text);
1336}
1337
1338void RenderViewImpl::OnUnselect() {
1339 if (!webview())
1340 return;
1341
1342 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
1343}
1344
1345void RenderViewImpl::OnSetEditableSelectionOffsets(int start, int end) {
1346 webview()->setEditableSelectionOffsets(start, end);
1347}
1348
1349void RenderViewImpl::OnSetCompositionFromExistingText(
1350 int start, int end,
1351 const std::vector<WebKit::WebCompositionUnderline>& underlines) {
1352 if (!webview())
1353 return;
1354 webview()->setCompositionFromExistingText(start, end, underlines);
1355}
1356
1357void RenderViewImpl::OnExtendSelectionAndDelete(int before, int after) {
1358 if (!webview())
1359 return;
1360 webview()->extendSelectionAndDelete(before, after);
1361}
1362
[email protected]310ebd6302011-10-10 19:06:281363void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1364 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:081365 if (!webview())
1366 return;
1367
[email protected]c95e53ad2012-08-13 17:56:161368 Send(new ViewHostMsg_SelectRange_ACK(routing_id_));
1369
[email protected]4fb60142011-08-09 02:22:081370 handling_select_range_ = true;
1371 webview()->focusedFrame()->selectRange(start, end);
1372 handling_select_range_ = false;
1373}
1374
[email protected]310ebd6302011-10-10 19:06:281375void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1376 int32 minimum_page_id) {
[email protected]e1ed5a12012-08-08 19:57:441377 DCHECK_GE(history_length, 0);
[email protected]9e1ad4b2011-08-14 16:49:191378 DCHECK(history_list_offset_ == history_list_length_ - 1);
[email protected]e1ed5a12012-08-08 19:57:441379 DCHECK_GE(minimum_page_id, -1);
[email protected]9e1ad4b2011-08-14 16:49:191380
1381 // Generate the new list.
1382 std::vector<int32> new_history_page_ids(history_length, -1);
1383 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1384 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1385 continue;
1386 new_history_page_ids.push_back(history_page_ids_[i]);
1387 }
1388 new_history_page_ids.swap(history_page_ids_);
1389
1390 // Update indexes.
1391 history_list_length_ = history_page_ids_.size();
1392 history_list_offset_ = history_list_length_ - 1;
1393}
1394
1395
[email protected]310ebd6302011-10-10 19:06:281396void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291397 if (!webview())
1398 return;
[email protected]26aa0482009-09-30 16:55:271399 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291400}
1401
[email protected]54ca3ca892011-06-07 21:14:541402#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281403void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331404 if (!webview())
1405 return;
1406 if (in_live_resize)
1407 webview()->willStartLiveResize();
1408 else
1409 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541410}
1411#endif
1412
[email protected]310ebd6302011-10-10 19:06:281413void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1414 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091415 WebKit::WebNode node = GetFocusedNode();
1416 if (!node.isNull()) {
[email protected]9b7d11e2012-10-08 19:24:141417 if (IsEditableNode(node)) {
1418 webview()->saveScrollAndScaleState();
[email protected]333ec8d02011-09-16 18:59:191419 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b7d11e2012-10-08 19:24:141420 }
[email protected]9b66f34bf2010-10-27 20:45:511421 }
1422}
1423
[email protected]9b7d11e2012-10-08 19:24:141424#if defined(OS_ANDROID)
1425void RenderViewImpl::OnUndoScrollFocusedEditableNodeIntoRect() {
1426 const WebNode node = GetFocusedNode();
1427 if (!node.isNull() && IsEditableNode(node))
1428 webview()->restoreScrollAndScaleState();
1429}
1430#endif
1431
initial.commit09911bf2008-07-26 23:55:291432///////////////////////////////////////////////////////////////////////////////
1433
1434// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281435void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451436 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291437 DCHECK(ds);
1438
[email protected]726985e22009-06-18 21:09:281439 const WebURLRequest& request = ds->request();
1440 const WebURLRequest& original_request = ds->originalRequest();
1441 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291442
[email protected]007733c2011-11-17 00:34:071443 DocumentState* document_state = DocumentState::FromDataSource(ds);
1444 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291445
1446 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281447 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291448 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051449 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291450 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071451 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191452 params.socket_address.set_host(response.remoteIPAddress().utf8());
1453 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031454 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091455 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071456 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291457 // SSL state specified in the request takes precedence over the one in the
1458 // response.
1459 // So far this is only intended for error pages that are not expected to be
1460 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281461 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071462 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291463 } else {
[email protected]726985e22009-06-18 21:09:281464 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291465 }
1466
1467 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:311468 params.url = GetLoadingUrl(frame);
initial.commit09911bf2008-07-26 23:55:291469
[email protected]5f9b8712011-11-23 08:55:571470 if (frame->document().baseURL() != params.url)
1471 params.base_url = frame->document().baseURL();
1472
[email protected]726985e22009-06-18 21:09:281473 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241474 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041475 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291476
[email protected]007733c2011-11-17 00:34:071477 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351478 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071479 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291480
1481 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071482 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291483 if (password_form_data)
1484 params.password_form = *password_form_data;
1485
1486 params.gesture = navigation_gesture_;
1487 navigation_gesture_ = NavigationGestureUnknown;
1488
[email protected]0f38dc4552011-02-25 11:24:001489 // Make navigation state a part of the FrameNavigate message so that commited
1490 // entry had it at all times.
1491 const WebHistoryItem& item = frame->currentHistoryItem();
1492 if (!item.isNull()) {
1493 params.content_state = webkit_glue::HistoryItemToString(item);
1494 } else {
1495 params.content_state =
1496 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1497 }
1498
[email protected]dd7daa82009-08-10 05:46:451499 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291500 // Top-level navigation.
1501
[email protected]d00a7972012-08-07 06:09:581502 // Reset the zoom limits in case a plugin had changed them previously. This
1503 // will also call us back which will cause us to send a message to
1504 // update WebContentsImpl.
1505 webview()->zoomLimitsChanged(
[email protected]e9ff79c2012-10-19 21:31:261506 WebView::zoomFactorToZoomLevel(kMinimumZoomFactor),
1507 WebView::zoomFactorToZoomLevel(kMaximumZoomFactor));
[email protected]d00a7972012-08-07 06:09:581508
[email protected]b75b8292010-10-01 07:28:251509 // Set zoom level, but don't do it for full-page plugin since they don't use
1510 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011511 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541512 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251513 if (webview()->mainFrame()->document().isPluginDocument()) {
1514 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251515 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251516 } else {
1517 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251518 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251519 }
1520
[email protected]f85f0702010-01-30 09:31:011521 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511522 // This zoom level was merely recorded transiently for this load. We can
1523 // erase it now. If at some point we reload this page, the browser will
1524 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011525 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511526 }
1527
initial.commit09911bf2008-07-26 23:55:291528 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551529 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291530
[email protected]daa8c58e2009-06-15 17:21:101531 params.transition = navigation_state->transition_type();
[email protected]e9ff79c2012-10-19 21:31:261532 if (!PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291533 // If the main frame does a load, it should not be reported as a subframe
1534 // navigation. This can occur in the following case:
1535 // 1. You're on a site with frames.
1536 // 2. You do a subframe navigation. This is stored with transition type
1537 // MANUAL_SUBFRAME.
1538 // 3. You navigate to some non-frame site, say, google.com.
1539 // 4. You navigate back to the page from step 2. Since it was initially
1540 // MANUAL_SUBFRAME, it will be that same transition type here.
1541 // We don't want that, because any navigation that changes the toplevel
1542 // frame should be tracked as a toplevel navigation (this allows us to
1543 // update the URL bar, etc).
[email protected]e9ff79c2012-10-19 21:31:261544 params.transition = PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291545 }
1546
initial.commit09911bf2008-07-26 23:55:291547 // If we have a valid consumed client redirect source,
1548 // the page contained a client redirect (meta refresh, document.loc...),
1549 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151550 if (completed_client_redirect_src_.url.is_valid()) {
1551 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291552 params.referrer = completed_client_redirect_src_;
[email protected]e9ff79c2012-10-19 21:31:261553 params.transition = static_cast<PageTransition>(
1554 params.transition | PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291555 } else {
1556 // Bug 654101: the referrer will be empty on https->http transitions. It
1557 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151558 params.referrer = Referrer(GURL(
1559 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:591560 GetReferrerPolicyFromRequest(frame, original_request));
initial.commit09911bf2008-07-26 23:55:291561 }
1562
[email protected]726985e22009-06-18 21:09:281563 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051564 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291565 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051566 params.post_id = ExtractPostId(item);
1567 }
initial.commit09911bf2008-07-26 23:55:291568
[email protected]bf70edce2012-06-20 22:32:221569 // Send the user agent override back.
1570 params.is_overriding_user_agent =
1571 document_state->is_overriding_user_agent();
1572
[email protected]7c16976c2012-08-04 02:38:231573 // Track the URL of the original request.
1574 params.original_request_url = original_request.url();
1575
[email protected]c2a797d2009-09-21 16:46:321576 // Save some histogram data so we can compute the average memory used per
1577 // page load of the glyphs.
1578 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1579 webkit_glue::GetGlyphPageCount());
1580
[email protected]15cf526b2010-02-12 06:33:491581 // This message needs to be sent before any of allowScripts(),
1582 // allowImages(), allowPlugins() is called for the new page, so that when
1583 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1584 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291585 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1586 } else {
1587 // Subframe navigation: the type depends on whether this navigation
1588 // generated a new session history entry. When they do generate a session
1589 // history entry, it means the user initiated the navigation and we should
1590 // mark it as such. This test checks if this is the first time UpdateURL
1591 // has been called since WillNavigateToURL was called to initiate the load.
1592 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]e9ff79c2012-10-19 21:31:261593 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291594 else
[email protected]e9ff79c2012-10-19 21:31:261595 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291596
initial.commit09911bf2008-07-26 23:55:291597 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1598 }
1599
1600 last_page_id_sent_to_browser_ =
1601 std::max(last_page_id_sent_to_browser_, page_id_);
1602
1603 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101604 // we don't want the transition type to persist. Just clear it.
[email protected]e9ff79c2012-10-19 21:31:261605 navigation_state->set_transition_type(PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291606}
1607
1608// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281609void RenderViewImpl::UpdateTitle(WebFrame* frame,
1610 const string16& title,
1611 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461612 // Ignore all but top level navigations.
1613 if (frame->parent())
1614 return;
1615
[email protected]e9ff79c2012-10-19 21:31:261616 string16 shortened_title = title.substr(0, kMaxTitleChars);
[email protected]a49e10b2011-08-01 23:57:461617 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1618 title_direction));
initial.commit09911bf2008-07-26 23:55:291619}
1620
[email protected]310ebd6302011-10-10 19:06:281621void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1622 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291623 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271624 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291625 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301626 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291627 last_encoding_name_ = encoding_name;
1628
[email protected]e38f40152008-09-12 23:08:301629 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291630 }
1631}
1632
[email protected]e15f680732010-11-23 22:30:201633// Sends the last committed session history state to the browser so it will be
1634// saved before we navigate to a new page. This must be called *before* the
1635// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281636void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291637 // If we have a valid page ID at this point, then it corresponds to the page
1638 // we are navigating away from. Otherwise, this is the first navigation, so
1639 // there is no past session history to record.
1640 if (page_id_ == -1)
1641 return;
1642
[email protected]ca948a22009-06-25 19:36:171643 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271644 webview()->mainFrame()->previousHistoryItem();
[email protected]6459800a2012-03-27 23:57:051645 SendUpdateState(item);
1646}
1647
1648void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
[email protected]ca948a22009-06-25 19:36:171649 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291650 return;
[email protected]ca948a22009-06-25 19:36:171651
[email protected]e9ff79c2012-10-19 21:31:261652 // Don't send state updates for kSwappedOutURL.
1653 if (item.urlString() == WebString::fromUTF8(kSwappedOutURL))
[email protected]6459800a2012-03-27 23:57:051654 return;
1655
[email protected]ca948a22009-06-25 19:36:171656 Send(new ViewHostMsg_UpdateState(
1657 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291658}
1659
[email protected]310ebd6302011-10-10 19:06:281660void RenderViewImpl::OpenURL(WebFrame* frame,
1661 const GURL& url,
[email protected]445e1042011-12-03 21:03:151662 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281663 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171664 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581665 routing_id_,
1666 url,
1667 referrer,
1668 NavigationPolicyToDisposition(policy),
1669 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171670}
1671
[email protected]79dbc662009-09-04 05:42:511672// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291673
[email protected]310ebd6302011-10-10 19:06:281674void RenderViewImpl::LoadNavigationErrorPage(
1675 WebFrame* frame,
1676 const WebURLRequest& failed_request,
1677 const WebURLError& error,
1678 const std::string& html,
1679 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581680 std::string alt_html;
1681 const std::string* error_html;
1682
1683 if (!html.empty()) {
1684 error_html = &html;
1685 } else {
[email protected]e9ff79c2012-10-19 21:31:261686 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]d7b175e2011-10-11 15:31:581687 failed_request, error, &alt_html, NULL);
1688 error_html = &alt_html;
1689 }
1690
1691 frame->loadHTMLString(*error_html,
[email protected]e9ff79c2012-10-19 21:31:261692 GURL(kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251693 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551694 replace);
initial.commit09911bf2008-07-26 23:55:291695}
1696
[email protected]e9ff79c2012-10-19 21:31:261697bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281698 const string16& message,
1699 const string16& default_value,
1700 const GURL& frame_url,
1701 string16* result) {
initial.commit09911bf2008-07-26 23:55:291702 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411703 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291704 if (!result)
1705 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291706
[email protected]12636df2009-09-28 22:32:211707 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1708 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291709 return success;
1710}
1711
[email protected]310ebd6302011-10-10 19:06:281712bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571713 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1714 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1715 // it is particularly important that we do not call willEnterModalLoop as
1716 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441717 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1718 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571719
1720 message->EnableMessagePumping(); // Runs a nested message loop.
1721 return Send(message);
1722}
1723
[email protected]48c9cf2d2009-09-16 16:47:521724// WebKit::WebViewClient ------------------------------------------------------
1725
[email protected]916dfb62012-03-05 03:39:371726WebView* RenderViewImpl::createView(
1727 WebFrame* creator,
1728 const WebURLRequest& request,
1729 const WebWindowFeatures& features,
1730 const WebString& frame_name,
1731 WebNavigationPolicy policy) {
[email protected]48c9cf2d2009-09-16 16:47:521732 // Check to make sure we aren't overloading on popups.
1733 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1734 return NULL;
1735
[email protected]8ab04652010-06-12 02:47:261736 ViewHostMsg_CreateWindow_Params params;
1737 params.opener_id = routing_id_;
1738 params.user_gesture = creator->isProcessingUserGesture();
1739 params.window_container_type = WindowFeaturesToContainerType(features);
1740 params.session_storage_namespace_id = session_storage_namespace_id_;
1741 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111742 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411743 params.opener_url = creator->document().url();
1744 params.opener_security_origin =
1745 creator->document().securityOrigin().toString().utf8();
[email protected]f92ce2b2012-03-06 18:02:591746 params.opener_suppressed = creator->willSuppressOpenerInNewFrame();
1747 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]41e65502011-01-21 09:29:111748 if (!request.isNull())
1749 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261750
[email protected]48c9cf2d2009-09-16 16:47:521751 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561752 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341753 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521754
[email protected]7c962ee32012-08-28 21:12:501755 creator->consumeUserGesture();
[email protected]380244092011-10-07 17:26:271756 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261757 new ViewHostMsg_CreateWindow(params,
1758 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561759 &surface_id,
[email protected]8ab04652010-06-12 02:47:261760 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211761 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521762 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521763
[email protected]310ebd6302011-10-10 19:06:281764 RenderViewImpl* view = RenderViewImpl::Create(
[email protected]310ebd6302011-10-10 19:06:281765 routing_id_,
1766 renderer_preferences_,
1767 webkit_preferences_,
1768 shared_popup_counter_,
1769 routing_id,
[email protected]9f4f3322012-01-18 22:29:561770 surface_id,
[email protected]310ebd6302011-10-10 19:06:281771 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461772 frame_name,
[email protected]14392a52012-05-02 20:28:441773 true,
1774 false,
[email protected]6fd35b72012-03-01 19:46:411775 1,
[email protected]842f10652012-06-06 01:54:041776 screen_info_,
[email protected]3e3c4522012-04-13 21:16:291777 accessibility_mode_);
[email protected]8ab04652010-06-12 02:47:261778 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521779
[email protected]007a848b2009-10-26 15:55:461780 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:591781 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:461782
[email protected]48c9cf2d2009-09-16 16:47:521783 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411784 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521785 if (!creator_url.is_valid() || !creator_url.IsStandard())
1786 creator_url = GURL();
1787 view->creator_url_ = creator_url;
1788
1789 // Copy over the alternate error page URL so we can have alt error pages in
1790 // the new render view (we don't need the browser to send the URL back down).
1791 view->alternate_error_page_url_ = alternate_error_page_url_;
1792
1793 return view->webview();
1794}
1795
[email protected]310ebd6302011-10-10 19:06:281796WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:411797 RenderWidget* widget =
[email protected]842f10652012-06-06 01:54:041798 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]48c9cf2d2009-09-16 16:47:521799 return widget->webwidget();
1800}
1801
[email protected]310ebd6302011-10-10 19:06:281802WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081803 const WebPopupMenuInfo& popup_menu_info,
1804 WebExternalPopupMenuClient* popup_menu_client) {
[email protected]8de2f882012-05-30 00:32:271805 // An IPC message is sent to the browser to build and display the actual
1806 // popup. The user could have time to click a different select by the time
1807 // the popup is shown. In that case external_popup_menu_ is non NULL.
1808 // By returning NULL in that case, we instruct WebKit to cancel that new
1809 // popup. So from the user perspective, only the first one will show, and
1810 // will have to close the first one before another one can be shown.
1811 if (external_popup_menu_.get())
1812 return NULL;
[email protected]caf706f2010-10-26 17:54:081813 external_popup_menu_.reset(
1814 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1815 return external_popup_menu_.get();
1816}
1817
[email protected]310ebd6302011-10-10 19:06:281818RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521819 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531820 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421821 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411822 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531823 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]bee6eb72012-07-26 03:47:321824 routing_id_, plugin, active_url, screen_info_);
[email protected]79c7bed2010-09-14 22:28:391825 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561826 return widget;
[email protected]79c7bed2010-09-14 22:28:391827}
1828
[email protected]310ebd6302011-10-10 19:06:281829WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1830 unsigned quota) {
[email protected]b928936b2012-04-13 01:16:161831 CHECK(session_storage_namespace_id_ !=
1832 dom_storage::kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:101833 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341834}
1835
[email protected]1842fe22012-08-13 23:24:351836WebKit::WebCompositorOutputSurface* RenderViewImpl::createOutputSurface() {
[email protected]1842fe22012-08-13 23:24:351837 // Explicitly disable antialiasing for the compositor. As of the time of
1838 // this writing, the only platform that supported antialiasing for the
1839 // compositor was Mac OS X, because the on-screen OpenGL context creation
1840 // code paths on Windows and Linux didn't yet have multisampling support.
1841 // Mac OS X essentially always behaves as though it's rendering offscreen.
1842 // Multisampling has a heavy cost especially on devices with relatively low
1843 // fill rate like most notebooks, and the Mac implementation would need to
1844 // be optimized to resolve directly into the IOSurface shared between the
1845 // GPU and browser processes. For these reasons and to avoid platform
1846 // disparities we explicitly disable antialiasing.
1847 WebKit::WebGraphicsContext3D::Attributes attributes;
1848 attributes.antialias = false;
1849 attributes.shareResources = true;
[email protected]362e6d602012-10-17 16:55:061850 attributes.noAutomaticFlushes = true;
[email protected]1842fe22012-08-13 23:24:351851 WebGraphicsContext3D* context = CreateGraphicsContext3D(attributes);
1852 if (!context)
[email protected]7e8b4d12012-01-20 23:39:511853 return NULL;
[email protected]468e4902012-05-23 01:49:311854
[email protected]7d4481d12012-09-24 21:26:471855 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1856 if (command_line.HasSwitch(switches::kEnableSoftwareCompositingGLAdapter)) {
1857 // In the absence of a software-based delegating renderer, use this
1858 // stopgap adapter class to present the software renderer output using a
1859 // 3d context.
1860 return new CompositorOutputSurface(routing_id(), NULL,
1861 new CompositorSoftwareOutputDeviceGLAdapter(context));
1862 } else
1863 return new CompositorOutputSurface(routing_id(), context, NULL);
[email protected]7e8b4d12012-01-20 23:39:511864}
1865
[email protected]310ebd6302011-10-10 19:06:281866void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521867 const WebConsoleMessage& message, const WebString& source_name,
1868 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081869 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511870 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081871 case WebConsoleMessage::LevelTip:
1872 log_severity = logging::LOG_VERBOSE;
1873 break;
1874 case WebConsoleMessage::LevelLog:
1875 log_severity = logging::LOG_INFO;
1876 break;
1877 case WebConsoleMessage::LevelWarning:
1878 log_severity = logging::LOG_WARNING;
1879 break;
1880 case WebConsoleMessage::LevelError:
1881 log_severity = logging::LOG_ERROR;
1882 break;
1883 default:
1884 NOTREACHED();
1885 }
1886
[email protected]48c9cf2d2009-09-16 16:47:521887 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081888 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311889 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521890 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311891 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521892}
1893
[email protected]310ebd6302011-10-10 19:06:281894void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]b0553c7e2012-09-19 21:36:111895 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
1896 PrintPage(frame, handling_input_event_));
[email protected]48c9cf2d2009-09-16 16:47:521897}
1898
[email protected]310ebd6302011-10-10 19:06:281899WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511900 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021901}
1902
[email protected]310ebd6302011-10-10 19:06:281903bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121904 const WebString& path,
1905 WebFileChooserCompletion* chooser_completion) {
1906 int id = enumeration_completion_id_++;
1907 enumeration_completions_[id] = chooser_completion;
1908 return Send(new ViewHostMsg_EnumerateDirectory(
1909 routing_id_,
1910 id,
[email protected]bb0e79472012-10-23 04:36:341911 webkit_base::WebStringToFilePath(path)));
[email protected]8a58c1c2011-04-19 18:40:121912}
1913
[email protected]4b1146bc2012-07-10 18:46:031914void RenderViewImpl::initializeHelperPluginWebFrame(
1915 WebKit::WebHelperPlugin* plugin) {
1916 plugin->initializeFrame(this);
1917}
1918
[email protected]310ebd6302011-10-10 19:06:281919void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521920 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:141921 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:521922 return;
1923 }
1924
1925 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521926
1927 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311928
1929 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521930}
1931
[email protected]310ebd6302011-10-10 19:06:281932void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521933 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:141934 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:521935 return;
1936 }
1937
1938 is_loading_ = false;
1939
[email protected]0720b532012-08-28 19:23:371940 if (pending_frame_tree_update_) {
1941 pending_frame_tree_update_ = false;
1942 SendUpdatedFrameTree(NULL);
1943 }
1944
[email protected]48c9cf2d2009-09-16 16:47:521945 // NOTE: For now we're doing the safest thing, and sending out notification
1946 // when done loading. This currently isn't an issue as the favicon is only
1947 // displayed when done loading. Ideally we would send notification when
1948 // finished parsing the head, but webkit doesn't support that yet.
1949 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521950 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1951
[email protected]90109412010-12-15 17:14:241952 if (load_progress_tracker_ != NULL)
1953 load_progress_tracker_->DidStopLoading();
1954
[email protected]93b9d692011-04-13 00:44:311955 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521956}
1957
[email protected]310ebd6302011-10-10 19:06:281958void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1959 double load_progress) {
[email protected]90109412010-12-15 17:14:241960 if (load_progress_tracker_ != NULL)
1961 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1962}
1963
[email protected]310ebd6302011-10-10 19:06:281964bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061965#if defined(OS_MACOSX)
1966 return true;
1967#else
1968 return false;
1969#endif
1970}
1971
[email protected]310ebd6302011-10-10 19:06:281972bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031973#if defined(OS_WIN)
1974 return true;
1975#else
1976 return false;
1977#endif
1978}
1979
[email protected]310ebd6302011-10-10 19:06:281980void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081981 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031982 return;
[email protected]4fb60142011-08-09 02:22:081983 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011984
[email protected]fca52022012-04-03 17:00:501985 if (is_empty_selection)
1986 selection_text_.clear();
1987
[email protected]b781ff282011-08-20 06:19:361988 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031989}
1990
[email protected]310ebd6302011-10-10 19:06:281991void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121992 const std::string& name = UTF16ToUTF8(command_name);
1993 if (StartsWithASCII(name, "Move", true) ||
1994 StartsWithASCII(name, "Insert", true) ||
1995 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031996 return;
[email protected]f1a29a02011-10-06 23:08:441997 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031998}
1999
[email protected]310ebd6302011-10-10 19:06:282000bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:102001 if (edit_commands_.empty())
2002 return false;
2003
[email protected]26aa0482009-09-30 16:55:272004 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102005 if (!frame)
2006 return false;
2007
2008 EditCommands::iterator it = edit_commands_.begin();
2009 EditCommands::iterator end = edit_commands_.end();
2010
[email protected]507b33ea2009-09-29 03:56:512011 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102012 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332013 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2014 // key (but it's the exception). Once one edit command is not executed, it
2015 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102016 if (!frame->executeCommand(WebString::fromUTF8(it->name),
2017 WebString::fromUTF8(it->value)))
2018 break;
[email protected]507b33ea2009-09-29 03:56:512019 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102020 }
2021
[email protected]507b33ea2009-09-29 03:56:512022 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102023}
2024
[email protected]3306f262012-09-21 19:20:422025void RenderViewImpl::didHandleGestureEvent(const WebGestureEvent& event,
2026 bool event_swallowed) {
2027#if defined(OS_ANDROID)
2028 if (event.type == WebInputEvent::GestureTap ||
2029 event.type == WebInputEvent::GestureLongPress) {
2030 UpdateTextInputState(SHOW_IME_IF_NEEDED);
2031 }
2032#endif
2033}
2034
[email protected]da8543762012-03-20 08:52:202035WebKit::WebColorChooser* RenderViewImpl::createColorChooser(
2036 WebKit::WebColorChooserClient* client,
2037 const WebKit::WebColor& initial_color) {
2038 RendererWebColorChooserImpl* color_chooser =
2039 new RendererWebColorChooserImpl(this, client);
2040 color_chooser->Open(static_cast<SkColor>(initial_color));
2041 return color_chooser;
2042}
2043
[email protected]310ebd6302011-10-10 19:06:282044bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:352045 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472046 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352047 // Do not open the file dialog in a hidden RenderView.
2048 if (is_hidden())
2049 return false;
[email protected]e9ff79c2012-10-19 21:31:262050 FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262051 if (params.directory)
[email protected]e9ff79c2012-10-19 21:31:262052 ipc_params.mode = FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:262053 else if (params.multiSelect)
[email protected]e9ff79c2012-10-19 21:31:262054 ipc_params.mode = FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:502055 else if (params.saveAs)
[email protected]e9ff79c2012-10-19 21:31:262056 ipc_params.mode = FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:262057 else
[email protected]e9ff79c2012-10-19 21:31:262058 ipc_params.mode = FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:472059 ipc_params.title = params.title;
2060 ipc_params.default_file_name =
[email protected]bb0e79472012-10-23 04:36:342061 webkit_base::WebStringToFilePath(params.initialValue);
[email protected]f9a4c41a2012-05-30 00:05:322062 ipc_params.accept_types.reserve(params.acceptTypes.size());
2063 for (size_t i = 0; i < params.acceptTypes.size(); ++i)
2064 ipc_params.accept_types.push_back(params.acceptTypes[i]);
[email protected]2fdf2352012-11-01 19:23:022065#if defined(OS_ANDROID)
2066 ipc_params.capture = params.capture;
2067#endif
[email protected]cdaf8d02010-03-30 19:52:472068
2069 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462070}
2071
[email protected]269f86d2011-12-07 02:43:472072void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
2073 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262074 RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:412075 message,
2076 string16(),
[email protected]b6cb3a842011-06-24 18:28:412077 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522078 NULL);
2079}
2080
[email protected]269f86d2011-12-07 02:43:472081bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
2082 const WebString& message) {
[email protected]e9ff79c2012-10-19 21:31:262083 return RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:412084 message,
2085 string16(),
[email protected]b6cb3a842011-06-24 18:28:412086 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522087 NULL);
2088}
2089
[email protected]269f86d2011-12-07 02:43:472090bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
2091 const WebString& message,
2092 const WebString& default_value,
2093 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:412094 string16 result;
[email protected]e9ff79c2012-10-19 21:31:262095 bool ok = RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:412096 message,
2097 default_value,
[email protected]b6cb3a842011-06-24 18:28:412098 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522099 &result);
2100 if (ok)
[email protected]4f5ce842011-05-27 19:34:412101 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:522102 return ok;
2103}
2104
[email protected]310ebd6302011-10-10 19:06:282105bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:522106 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:152107 // If we are swapping out, we have already run the beforeunload handler.
2108 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
2109 // at all, to avoid running it twice.
2110 if (is_swapped_out_)
2111 return true;
2112
[email protected]3b3301f62012-02-29 04:32:322113 bool is_reload = false;
2114 WebDataSource* ds = frame->provisionalDataSource();
2115 if (ds)
2116 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
2117
[email protected]48c9cf2d2009-09-16 16:47:522118 bool success = false;
2119 // This is an ignored return value, but is included so we can accept the same
2120 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:412121 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:212122 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:322123 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:412124 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522125 return success;
2126}
2127
[email protected]310ebd6302011-10-10 19:06:282128void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:442129 WebFrame* frame, const WebContextMenuData& data) {
[email protected]e9ff79c2012-10-19 21:31:262130 ContextMenuParams params(data);
[email protected]7fcd9b72011-07-27 16:52:372131
[email protected]329266d2012-09-27 06:20:572132 // Plugins, e.g. PDF, don't currently update the render view when their
2133 // selected text changes, but the context menu params do contain the updated
2134 // selection. If that's the case, update the render view's state just prior
2135 // to showing the context menu.
2136 // TODO(asvitkine): http://crbug.com/152432
[email protected]f49f7a12012-10-26 19:16:592137 string16 selection_text;
2138 if (!selection_text_.empty() && !selection_range_.is_empty()) {
2139 const int start = selection_range_.GetMin() - selection_text_offset_;
2140 const size_t length = selection_range_.length();
2141 if (start >= 0 && start + length <= selection_text_.length())
2142 selection_text = selection_text_.substr(start, length);
2143 }
[email protected]eff43567da2012-10-25 20:57:482144 if (params.selection_text != selection_text) {
[email protected]329266d2012-09-27 06:20:572145 selection_text_ = params.selection_text;
2146 // TODO(asvitkine): Text offset and range is not available in this case.
2147 selection_text_offset_ = 0;
2148 selection_range_ = ui::Range(0, selection_text_.length());
2149 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2150 selection_text_,
2151 selection_text_offset_,
2152 selection_range_));
2153 }
2154
[email protected]7fcd9b72011-07-27 16:52:372155 // frame is NULL if invoked by BlockedPlugin.
2156 if (frame)
2157 params.frame_id = frame->identifier();
2158
[email protected]e9ff79c2012-10-19 21:31:262159 // Serializing a GURL longer than kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:272160 // it. We replace it with an empty GURL so the appropriate items are disabled
2161 // in the context menu.
2162 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2163 // data encoded images. We should have a way to save them.
[email protected]e9ff79c2012-10-19 21:31:262164 if (params.src_url.spec().size() > kMaxURLChars)
[email protected]216932c2010-08-26 21:44:272165 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102166 context_menu_node_ = data.node;
[email protected]44daa3b2012-09-27 19:26:412167
2168#if defined(OS_ANDROID)
2169 gfx::Rect start_rect;
2170 gfx::Rect end_rect;
2171 GetSelectionBounds(&start_rect, &end_rect);
[email protected]ceb36f7d2012-10-31 18:33:242172 params.selection_start =
2173 gfx::Point(start_rect.x(), start_rect.bottom()) + GetScrollOffset();
2174 params.selection_end =
2175 gfx::Point(end_rect.right(), end_rect.bottom()) + GetScrollOffset();
[email protected]44daa3b2012-09-27 19:26:412176#endif
2177
[email protected]c27324b2009-11-19 22:44:292178 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]b2324b092012-11-01 10:34:112179
2180 FOR_EACH_OBSERVER(
2181 RenderViewObserver, observers_, DidRequestShowContextMenu(frame, data));
[email protected]79e37442009-10-09 18:17:442182}
2183
[email protected]310ebd6302011-10-10 19:06:282184void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:522185}
2186
[email protected]310ebd6302011-10-10 19:06:282187void RenderViewImpl::UpdateTargetURL(const GURL& url,
2188 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582189 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522190 if (latest_url == target_url_)
2191 return;
[email protected]163f8242009-10-30 20:19:552192
[email protected]48c9cf2d2009-09-16 16:47:522193 // Tell the browser to display a destination link.
2194 if (target_url_status_ == TARGET_INFLIGHT ||
2195 target_url_status_ == TARGET_PENDING) {
2196 // If we have a request in-flight, save the URL to be sent when we
2197 // receive an ACK to the in-flight request. We can happily overwrite
2198 // any existing pending sends.
2199 pending_target_url_ = latest_url;
2200 target_url_status_ = TARGET_PENDING;
2201 } else {
[email protected]e9ff79c2012-10-19 21:31:262202 // URLs larger than |kMaxURLChars| cannot be sent through IPC -
[email protected]c85f0212011-11-04 16:54:412203 // see |ParamTraits<GURL>|.
[email protected]e9ff79c2012-10-19 21:31:262204 if (latest_url.possibly_invalid_spec().size() > kMaxURLChars)
[email protected]c85f0212011-11-04 16:54:412205 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:522206 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2207 target_url_ = latest_url;
2208 target_url_status_ = TARGET_INFLIGHT;
2209 }
2210}
2211
[email protected]310ebd6302011-10-10 19:06:282212void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:312213 int delay;
2214 if (send_content_state_immediately_)
2215 delay = 0;
2216 else if (is_hidden())
2217 delay = kDelaySecondsForContentStateSyncHidden;
2218 else
2219 delay = kDelaySecondsForContentStateSync;
2220
2221 if (nav_state_sync_timer_.IsRunning()) {
2222 // The timer is already running. If the delay of the timer maches the amount
2223 // we want to delay by, then return. Otherwise stop the timer so that it
2224 // gets started with the right delay.
2225 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2226 return;
2227 nav_state_sync_timer_.Stop();
2228 }
2229
[email protected]d323a172011-09-02 18:23:022230 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:282231 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:312232}
2233
[email protected]310ebd6302011-10-10 19:06:282234void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552235 mouse_over_url_ = GURL(url);
2236 UpdateTargetURL(mouse_over_url_, focus_url_);
2237}
2238
[email protected]310ebd6302011-10-10 19:06:282239void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552240 focus_url_ = GURL(url);
2241 UpdateTargetURL(focus_url_, mouse_over_url_);
2242}
2243
[email protected]0407e422012-05-18 19:51:252244void RenderViewImpl::startDragging(WebFrame* frame,
2245 const WebDragData& data,
[email protected]310ebd6302011-10-10 19:06:282246 WebDragOperationsMask mask,
2247 const WebImage& image,
[email protected]ceb36f7d2012-10-31 18:33:242248 const WebPoint& webImageOffset) {
[email protected]b67151d2012-05-25 23:23:242249 WebDropData drop_data(data);
2250 drop_data.referrer_policy = frame->document().referrerPolicy();
[email protected]ceb36f7d2012-10-31 18:33:242251 gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y);
[email protected]59f4f2fa2011-03-23 01:00:552252 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]b67151d2012-05-25 23:23:242253 drop_data,
[email protected]c27ae592010-03-18 15:24:412254 mask,
[email protected]976127072012-05-10 20:08:112255 image.getSkBitmap(),
[email protected]41d86852012-11-07 12:23:242256 imageOffset,
2257 possible_drag_event_info_));
[email protected]48c9cf2d2009-09-16 16:47:522258}
2259
[email protected]310ebd6302011-10-10 19:06:282260bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:452261 return renderer_preferences_.can_accept_load_drops;
2262}
2263
[email protected]310ebd6302011-10-10 19:06:282264void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:522265 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2266}
2267
[email protected]310ebd6302011-10-10 19:06:282268void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:522269 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2270}
2271
[email protected]310ebd6302011-10-10 19:06:282272void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512273 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072274
[email protected]38b592902011-04-16 02:08:422275 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:492276}
2277
[email protected]572a6ca2012-10-11 19:38:012278void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
2279 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
2280}
2281
2282void RenderViewImpl::hasTouchEventHandlers(bool has_handlers) {
2283 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2284}
2285
[email protected]169d4282011-11-30 19:33:592286void RenderViewImpl::didUpdateLayout() {
2287 // We don't always want to set up a timer, only if we've been put in that
2288 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2289 // message.
2290 if (!send_preferred_size_changes_ || !webview())
2291 return;
2292
2293 if (check_preferred_size_timer_.IsRunning())
2294 return;
2295 check_preferred_size_timer_.Start(FROM_HERE,
2296 TimeDelta::FromMilliseconds(0), this,
2297 &RenderViewImpl::CheckPreferredSize);
2298}
2299
[email protected]310ebd6302011-10-10 19:06:282300void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522301 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2302}
2303
[email protected]310ebd6302011-10-10 19:06:282304int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002305 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522306}
2307
[email protected]310ebd6302011-10-10 19:06:282308int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002309 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522310}
2311
[email protected]310ebd6302011-10-10 19:06:282312void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:322313 const WebAccessibilityObject& obj,
2314 WebAccessibilityNotification notification) {
[email protected]2a84f9d2012-06-05 21:50:432315 if (renderer_accessibility_) {
2316 renderer_accessibility_->HandleWebAccessibilityNotification(
2317 obj, notification);
2318 }
[email protected]063afcb2011-09-29 07:54:322319}
2320
[email protected]310ebd6302011-10-10 19:06:282321void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:142322 const WebString& value) {
2323 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2324 key.utf8(),
2325 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262326}
2327
[email protected]79dbc662009-09-04 05:42:512328// WebKit::WebWidgetClient ----------------------------------------------------
2329
[email protected]310ebd6302011-10-10 19:06:282330void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122331 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2332 // we won't have to test for user gesture anymore and we can
2333 // move that code back to render_widget.cc
2334 if (webview() && webview()->mainFrame() &&
2335 webview()->mainFrame()->isProcessingUserGesture()) {
2336 Send(new ViewHostMsg_Focus(routing_id_));
2337 }
2338}
2339
[email protected]310ebd6302011-10-10 19:06:282340void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122341 // TODO(jcivelli): see TODO above in didFocus().
2342 if (webview() && webview()->mainFrame() &&
2343 webview()->mainFrame()->isProcessingUserGesture()) {
2344 Send(new ViewHostMsg_Blur(routing_id_));
2345 }
2346}
2347
initial.commit09911bf2008-07-26 23:55:292348// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282349// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292350// point to dispatch the ShowView message.
2351//
2352// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282353// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292354//
[email protected]310ebd6302011-10-10 19:06:282355void RenderViewImpl::show(WebNavigationPolicy policy) {
[email protected]b2142e962012-10-30 13:59:252356 if (did_show_) {
2357#if defined(OS_ANDROID)
2358 // When supports_multiple_windows is disabled, popups are reusing
2359 // the same view. In some scenarios, this makes WebKit to call show() twice.
2360 if (!webkit_preferences_.supports_multiple_windows)
2361 return;
2362#endif
2363 NOTREACHED() << "received extraneous Show call";
initial.commit09911bf2008-07-26 23:55:292364 return;
[email protected]b2142e962012-10-30 13:59:252365 }
initial.commit09911bf2008-07-26 23:55:292366 did_show_ = true;
2367
[email protected]b2142e962012-10-30 13:59:252368 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2369
[email protected]e9ff79c2012-10-19 21:31:262370 if (GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:042371 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:042372
[email protected]28295ec2009-10-16 05:34:332373 // Force new windows to a popup if they were not opened with a user gesture.
2374 if (!opened_by_user_gesture_) {
2375 // We exempt background tabs for compat with older versions of Chrome.
2376 // TODO(darin): This seems bogus. These should have a user gesture, so
2377 // we probably don't need this check.
2378 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2379 policy = WebKit::WebNavigationPolicyNewPopup;
2380 }
2381
initial.commit09911bf2008-07-26 23:55:292382 // NOTE: initial_pos_ may still have its default values at this point, but
2383 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2384 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282385 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2386 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292387 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242388 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292389}
2390
[email protected]310ebd6302011-10-10 19:06:282391void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292392 DCHECK(did_show_) << "should already have shown the view";
2393
[email protected]c1f50aa2010-02-18 03:46:572394 // We must keep WebKit's shared timer running in this case in order to allow
2395 // showModalDialog to function properly.
2396 //
2397 // TODO(darin): WebKit should really be smarter about suppressing events and
2398 // timers so that we do not need to manage the shared timer in such a heavy
2399 // handed manner.
2400 //
[email protected]f1a29a02011-10-06 23:08:442401 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2402 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572403
[email protected]08a1c8102012-05-11 23:14:262404 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
2405 routing_id_, opener_id_));
initial.commit09911bf2008-07-26 23:55:292406}
2407
[email protected]2b624c562011-10-27 22:58:262408bool RenderViewImpl::enterFullScreen() {
2409 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2410 return true;
2411}
2412
2413void RenderViewImpl::exitFullScreen() {
2414 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2415}
2416
[email protected]217690d2012-01-27 07:33:112417bool RenderViewImpl::requestPointerLock() {
2418 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2419}
2420
2421void RenderViewImpl::requestPointerUnlock() {
2422 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2423}
2424
2425bool RenderViewImpl::isPointerLocked() {
2426 return mouse_lock_dispatcher_->IsMouseLockedTo(
2427 webwidget_mouse_lock_target_.get());
2428}
2429
[email protected]7a1ec28a2012-03-28 21:10:242430void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
2431 CompositorThread* compositor_thread =
2432 RenderThreadImpl::current()->compositor_thread();
2433 if (compositor_thread)
2434 compositor_thread->AddInputHandler(
2435 routing_id_, input_handler_identifier, AsWeakPtr());
2436
2437 RenderWidget::didActivateCompositor(input_handler_identifier);
[email protected]1c0c9bc2012-10-08 22:41:482438
2439 ProcessAcceleratedPinchZoomFlags(*CommandLine::ForCurrentProcess());
[email protected]7a1ec28a2012-03-28 21:10:242440}
2441
[email protected]3d9689372009-09-10 04:29:172442// WebKit::WebFrameClient -----------------------------------------------------
2443
[email protected]310ebd6302011-10-10 19:06:282444WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2445 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:552446 WebPlugin* plugin = NULL;
[email protected]e9ff79c2012-10-19 21:31:262447 if (GetContentClient()->renderer()->OverrideCreatePlugin(
[email protected]eaacd1f2011-09-23 02:32:552448 this, frame, params, &plugin)) {
2449 return plugin;
2450 }
2451
[email protected]e9ff79c2012-10-19 21:31:262452 if (UTF16ToASCII(params.mimeType) == kBrowserPluginMimeType) {
[email protected]6cd7c6b2012-10-25 03:26:232453 return BrowserPluginManager::Get()->
2454 CreateBrowserPlugin(this, frame, params);
[email protected]e6e56752012-08-10 00:46:062455 }
2456
[email protected]a813c8e2011-10-08 01:34:112457 webkit::WebPluginInfo info;
2458 std::string mime_type;
2459 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2460 params.mimeType.utf8(), &info, &mime_type);
2461 if (!found)
2462 return NULL;
2463
2464 WebPluginParams params_to_use = params;
2465 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312466 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172467}
2468
[email protected]310ebd6302011-10-10 19:06:282469WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422470 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372471 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422472
[email protected]30447b62009-11-13 01:13:372473 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512474 bool exists = false;
[email protected]30447b62009-11-13 01:13:372475 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512476 ViewHostMsg_CreateWorker_Params params;
2477 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512478 params.name = name;
2479 params.document_id = document_id;
2480 params.render_view_route_id = routing_id_;
2481 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232482 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372483 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512484 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372485 if (url_mismatch) {
2486 return NULL;
2487 } else {
[email protected]f1a29a02011-10-06 23:08:442488 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492489 document_id,
[email protected]6de0bcf2010-02-17 22:00:512490 exists,
[email protected]30447b62009-11-13 01:13:372491 route_id,
2492 routing_id_);
2493 }
[email protected]9c00f002009-11-05 22:37:422494}
2495
[email protected]97b150db2012-08-16 18:26:022496WebMediaPlayer* RenderViewImpl::createMediaPlayer(
2497 WebFrame* frame, const WebKit::WebURL& url, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442498 FOR_EACH_OBSERVER(
2499 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172500
[email protected]780fc8242012-09-19 20:28:522501 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
[email protected]25fb9b32012-04-27 03:21:552502#if defined(OS_ANDROID)
[email protected]855623ed2012-09-24 18:59:552503 WebGraphicsContext3D* resource_context =
2504 GetWebView()->sharedGraphicsContext3D();
2505
2506 GpuChannelHost* gpu_channel_host =
2507 RenderThreadImpl::current()->EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:262508 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
[email protected]855623ed2012-09-24 18:59:552509 if (!gpu_channel_host) {
2510 LOG(ERROR) << "Failed to establish GPU channel for media player";
2511 return NULL;
2512 }
2513
[email protected]780fc8242012-09-19 20:28:522514 if (cmd_line->HasSwitch(switches::kMediaPlayerInRenderProcess)) {
2515 if (!media_bridge_manager_.get()) {
2516 media_bridge_manager_.reset(
2517 new webkit_media::MediaPlayerBridgeManagerImpl(1));
2518 }
2519 return new webkit_media::WebMediaPlayerInProcessAndroid(
2520 frame,
2521 client,
2522 cookieJar(frame),
2523 media_player_manager_.get(),
2524 media_bridge_manager_.get(),
[email protected]e9ff79c2012-10-19 21:31:262525 new StreamTextureFactoryImpl(
[email protected]855623ed2012-09-24 18:59:552526 resource_context, gpu_channel_host, routing_id_),
[email protected]780fc8242012-09-19 20:28:522527 cmd_line->HasSwitch(switches::kDisableMediaHistoryLogging));
2528 }
2529 if (!media_player_proxy_) {
[email protected]e9ff79c2012-10-19 21:31:262530 media_player_proxy_ = new WebMediaPlayerProxyImplAndroid(
[email protected]780fc8242012-09-19 20:28:522531 this, media_player_manager_.get());
2532 }
2533 return new webkit_media::WebMediaPlayerImplAndroid(
2534 frame,
2535 client,
2536 media_player_manager_.get(),
2537 media_player_proxy_,
[email protected]e9ff79c2012-10-19 21:31:262538 new StreamTextureFactoryImpl(
[email protected]855623ed2012-09-24 18:59:552539 resource_context, gpu_channel_host, routing_id_));
[email protected]25fb9b32012-04-27 03:21:552540#endif
2541
[email protected]bb6fd402011-12-09 02:45:442542 media::MessageLoopFactory* message_loop_factory =
[email protected]b80322902012-03-06 01:33:502543 new media::MessageLoopFactory();
[email protected]bb6fd402011-12-09 02:45:442544 media::FilterCollection* collection = new media::FilterCollection();
2545 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372546
[email protected]9e2269d2012-01-07 00:06:212547 RenderAudioSourceProvider* audio_source_provider = NULL;
2548
[email protected]3d9689372009-09-10 04:29:172549 // Add in any custom filter factories first.
[email protected]3d9689372009-09-10 04:29:172550 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212551 // audio_source_provider is a "provider" to WebKit, and a sink
2552 // from the perspective of the audio renderer.
2553 audio_source_provider = new RenderAudioSourceProvider();
2554
2555 // Add the chrome specific audio renderer, using audio_source_provider
2556 // as the sink.
[email protected]37136d162012-04-09 23:39:192557 media::AudioRendererImpl* audio_renderer =
2558 new media::AudioRendererImpl(audio_source_provider);
[email protected]9e2269d2012-01-07 00:06:212559 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172560 }
2561
[email protected]15d206e2012-08-17 22:35:132562 WebGraphicsContext3DCommandBufferImpl* context3d = NULL;
[email protected]5f04c3532012-09-25 01:28:392563 if (!cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode))
[email protected]15d206e2012-08-17 22:35:132564 context3d = RenderThreadImpl::current()->GetGpuVDAContext3D();
[email protected]851334d2012-06-15 22:39:312565 if (context3d) {
[email protected]084c8552012-08-12 22:51:202566 scoped_refptr<base::MessageLoopProxy> factories_loop =
[email protected]84a83e192012-03-09 18:43:402567 RenderThreadImpl::current()->compositor_thread() ?
2568 RenderThreadImpl::current()->compositor_thread()->GetWebThread()
[email protected]084c8552012-08-12 22:51:202569 ->message_loop()->message_loop_proxy() :
2570 base::MessageLoopProxy::current();
[email protected]e1d69d762011-12-13 05:12:182571 GpuChannelHost* gpu_channel_host =
2572 RenderThreadImpl::current()->EstablishGpuChannelSync(
[email protected]e9ff79c2012-10-19 21:31:262573 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
[email protected]873da262012-08-10 22:02:472574 collection->GetVideoDecoders()->push_back(new media::GpuVideoDecoder(
[email protected]084c8552012-08-12 22:51:202575 base::Bind(&media::MessageLoopFactory::GetMessageLoop,
2576 base::Unretained(message_loop_factory),
[email protected]c462c902012-09-06 13:13:422577 media::MessageLoopFactory::kDecoder),
[email protected]84a83e192012-03-09 18:43:402578 factories_loop,
[email protected]8d4359282012-01-14 00:53:312579 new RendererGpuVideoDecoderFactories(
[email protected]84a83e192012-03-09 18:43:402580 gpu_channel_host, factories_loop, context3d)));
[email protected]e1d69d762011-12-13 05:12:182581 }
[email protected]e1d69d762011-12-13 05:12:182582
[email protected]5d65fe92012-06-02 00:48:552583 WebMediaPlayer* media_player =
[email protected]e9ff79c2012-10-19 21:31:262584 GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
[email protected]da952fd2012-01-13 03:49:252585 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1113bfdf2012-07-16 21:46:102586 audio_source_provider, message_loop_factory, media_stream_impl_,
2587 render_media_log);
[email protected]da952fd2012-01-13 03:49:252588 if (!media_player) {
[email protected]ba42ac4f2012-10-11 20:28:142589#if defined(ENABLE_WEBRTC)
[email protected]5f04c3532012-09-25 01:28:392590 // TODO(wjia): when all patches related to WebMediaPlayerMS have been
2591 // landed, remove the switch. Refer to crbug.com/142988.
[email protected]1fba73c12012-10-10 23:36:202592 if (!cmd_line->HasSwitch(switches::kDisableWebMediaPlayerMS) &&
2593 MediaStreamImpl::CheckMediaStream(url)) {
[email protected]5f04c3532012-09-25 01:28:392594 EnsureMediaStreamImpl();
[email protected]1fba73c12012-10-10 23:36:202595 return new webkit_media::WebMediaPlayerMS(
2596 frame, client, AsWeakPtr(), media_stream_impl_, render_media_log);
[email protected]5f04c3532012-09-25 01:28:392597 }
[email protected]ba42ac4f2012-10-11 20:28:142598#endif
[email protected]5f04c3532012-09-25 01:28:392599
[email protected]cec4eb82012-01-12 17:51:562600 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252601 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1113bfdf2012-07-16 21:46:102602 audio_source_provider, message_loop_factory, media_stream_impl_,
2603 render_media_log);
[email protected]bb6fd402011-12-09 02:45:442604 }
[email protected]cec4eb82012-01-12 17:51:562605 return media_player;
[email protected]3d9689372009-09-10 04:29:172606}
2607
[email protected]310ebd6302011-10-10 19:06:282608WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212609 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232610 if (!frame || !frame->view())
2611 return NULL;
[email protected]035545f2010-04-09 13:10:212612 return new RendererWebApplicationCacheHostImpl(
2613 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442614 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212615}
2616
[email protected]310ebd6302011-10-10 19:06:282617WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382618 return &cookie_jar_;
2619}
2620
[email protected]0720b532012-08-28 19:23:372621void RenderViewImpl::didCreateFrame(WebFrame* parent, WebFrame* child) {
[email protected]0720b532012-08-28 19:23:372622 if (!updating_frame_tree_)
2623 SendUpdatedFrameTree(NULL);
2624}
2625
[email protected]310ebd6302011-10-10 19:06:282626void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]0720b532012-08-28 19:23:372627 if (is_loading_) {
2628 pending_frame_tree_update_ = true;
2629 // Make sure observers are notified, even if we return right away.
2630 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
2631 return;
2632 }
2633 if (!updating_frame_tree_)
2634 SendUpdatedFrameTree(frame);
2635
[email protected]676126f72011-01-15 00:03:512636 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452637}
2638
[email protected]310ebd6302011-10-10 19:06:282639void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512640 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172641}
2642
[email protected]310ebd6302011-10-10 19:06:282643void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172644 WebFrame* frame, const WebURLRequest& request,
2645 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342646 loadURLExternally(frame, request, policy, WebString());
2647}
2648
[email protected]5e92282f2012-08-17 08:11:572649void RenderViewImpl::Repaint(const gfx::Size& size) {
2650 OnMsgRepaint(size);
2651}
2652
[email protected]b2324b092012-11-01 10:34:112653void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
2654 const std::string& value) {
2655 EditCommands edit_commands;
2656 edit_commands.push_back(EditCommand(name, value));
2657 OnSetEditCommandsForNextKeyEvent(edit_commands);
2658}
2659
2660void RenderViewImpl::ClearEditCommands() {
2661 edit_commands_.clear();
2662}
2663
[email protected]310ebd6302011-10-10 19:06:282664void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342665 WebFrame* frame, const WebURLRequest& request,
2666 WebNavigationPolicy policy,
2667 const WebString& suggested_name) {
[email protected]56505542012-05-12 00:25:372668 Referrer referrer(
2669 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2670 GetReferrerPolicyFromRequest(frame, request));
[email protected]efce17b2009-09-11 18:04:592671 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342672 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2673 suggested_name));
[email protected]efce17b2009-09-11 18:04:592674 } else {
[email protected]56505542012-05-12 00:25:372675 OpenURL(frame, request.url(), referrer, policy);
[email protected]efce17b2009-09-11 18:04:592676 }
[email protected]3d9689372009-09-10 04:29:172677}
2678
[email protected]310ebd6302011-10-10 19:06:282679WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172680 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222681 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]099df81cf2012-11-14 17:44:042682 if (request.url() != GURL(kSwappedOutURL) &&
2683 GetContentClient()->renderer()->HandleNavigation(frame, request, type,
2684 default_policy,
2685 is_redirect)) {
2686 return WebKit::WebNavigationPolicyIgnore;
2687 }
2688
[email protected]0639c063a2012-03-22 20:55:332689 Referrer referrer(
2690 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:592691 GetReferrerPolicyFromRequest(frame, request));
[email protected]0639c063a2012-03-22 20:55:332692
[email protected]992db4c2011-05-12 15:37:152693 if (is_swapped_out_) {
[email protected]e9ff79c2012-10-19 21:31:262694 if (request.url() != GURL(kSwappedOutURL)) {
[email protected]0639c063a2012-03-22 20:55:332695 // Targeted links may try to navigate a swapped out frame. Allow the
2696 // browser process to navigate the tab instead. Note that it is also
2697 // possible for non-targeted navigations (from this view) to arrive
2698 // here just after we are swapped out. It's ok to send them to the
2699 // browser, as long as they're for the top level frame.
2700 // TODO(creis): Ensure this supports targeted form submissions when
2701 // fixing http://crbug.com/101395.
2702 if (frame->parent() == NULL) {
2703 OpenURL(frame, request.url(), referrer, default_policy);
2704 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2705 }
2706
2707 // We should otherwise ignore in-process iframe navigations, if they
2708 // arrive just after we are swapped out.
[email protected]73eb2602012-02-09 19:50:552709 return WebKit::WebNavigationPolicyIgnore;
[email protected]0639c063a2012-03-22 20:55:332710 }
[email protected]73eb2602012-02-09 19:50:552711
[email protected]e9ff79c2012-10-19 21:31:262712 // Allow kSwappedOutURL to complete.
[email protected]992db4c2011-05-12 15:37:152713 return default_policy;
2714 }
2715
[email protected]3d9689372009-09-10 04:29:172716 // Webkit is asking whether to navigate to a new URL.
2717 // This is fine normally, except if we're showing UI from one security
2718 // context and they're trying to navigate to a different context.
2719 const GURL& url = request.url();
2720
[email protected]d19ea342011-04-20 20:31:132721 // A content initiated navigation may have originated from a link-click,
2722 // script, drag-n-drop operation, etc.
2723 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072724 DocumentState::FromDataSource(frame->provisionalDataSource())->
2725 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132726
[email protected]a8c269a2011-10-25 20:17:222727 // Experimental:
2728 // If --enable-strict-site-isolation is enabled, send all top-level
2729 // navigations to the browser to let it swap processes when crossing site
2730 // boundaries. This is currently expected to break some script calls and
2731 // navigations, such as form submissions.
2732 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102733 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2734 !frame->parent() && (is_content_initiated || is_redirect)) {
2735 WebString origin_str = frame->document().securityOrigin().toString();
2736 GURL frame_url(origin_str.utf8().data());
[email protected]18fb7a772012-09-20 19:25:092737 // TODO(cevans): revisit whether this site check is still necessary once
[email protected]313b80bd2011-11-23 03:49:102738 // crbug.com/101395 is fixed.
[email protected]18fb7a772012-09-20 19:25:092739 if (!net::RegistryControlledDomainService::SameDomainOrHost(frame_url,
2740 url) ||
2741 frame_url.scheme() != url.scheme()) {
[email protected]313b80bd2011-11-23 03:49:102742 OpenURL(frame, url, referrer, default_policy);
2743 return WebKit::WebNavigationPolicyIgnore;
2744 }
[email protected]a8c269a2011-10-25 20:17:222745 }
2746
[email protected]fd3238af2012-05-22 18:55:302747 // If the browser is interested, then give it a chance to look at the request.
[email protected]5f000f272012-01-19 05:25:082748 if (is_content_initiated) {
[email protected]fd3238af2012-05-22 18:55:302749 bool browser_handles_request =
2750 renderer_preferences_.browser_handles_non_local_top_level_requests &&
[email protected]5f000f272012-01-19 05:25:082751 IsNonLocalTopLevelNavigation(url, frame, type);
[email protected]fd3238af2012-05-22 18:55:302752 if (!browser_handles_request) {
2753 browser_handles_request =
2754 renderer_preferences_.browser_handles_all_top_level_requests &&
2755 IsTopLevelNavigation(frame);
2756 }
2757
2758 if (browser_handles_request) {
[email protected]5f000f272012-01-19 05:25:082759 // Reset these counters as the RenderView could be reused for the next
2760 // navigation.
2761 page_id_ = -1;
2762 last_page_id_sent_to_browser_ = -1;
2763 OpenURL(frame, url, referrer, default_policy);
2764 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2765 }
[email protected]3d9689372009-09-10 04:29:172766 }
2767
[email protected]dc67e1c32012-06-08 00:10:402768 // Use the frame's original request's URL rather than the document's URL for
2769 // subsequent checks. For a popup, the document's URL may become the opener
2770 // window's URL if the opener has called document.write().
2771 // See http://crbug.com/93517.
2772 GURL old_url(frame->dataSource()->request().url());
2773
[email protected]6101c342010-12-16 22:44:372774 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552775 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:042776 // top-level navigations (not iframes). But we sometimes navigate to
2777 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:372778 //
[email protected]744c2a22012-03-15 18:42:042779 // Note: this is known to break POST submissions when crossing process
2780 // boundaries until http://crbug.com/101395 is fixed. This is better for
2781 // security than loading a WebUI, extension or app page in the wrong process.
2782 // POST requests don't work because this mechanism does not preserve form
2783 // POST data. We will need to send the request's httpBody data up to the
2784 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:572785 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2786 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222787 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:042788 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:372789 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:042790
2791 // All navigations to WebUI URLs or within WebUI-enabled RenderProcesses
2792 // must be handled by the browser process so that the correct bindings and
2793 // data sources can be registered.
2794 // Similarly, navigations to view-source URLs or within ViewSource mode
[email protected]1c210f692012-11-06 22:31:472795 // must be handled by the browser process (except for reloads - those are
2796 // safe to leave within the renderer).
[email protected]dc67e1c32012-06-08 00:10:402797 // Lastly, access to file:// URLs from non-file:// URL pages must be
2798 // handled by the browser so that ordinary renderer processes don't get
2799 // blessed with file permissions.
2800 int cumulative_bindings = RenderProcess::current()->GetEnabledBindings();
2801 bool is_initial_navigation = page_id_ == -1;
[email protected]6101c342010-12-16 22:44:372802 bool should_fork =
[email protected]e9ff79c2012-10-19 21:31:262803 GetContentClient()->HasWebUIScheme(url) ||
2804 (cumulative_bindings & BINDINGS_POLICY_WEB_UI) ||
[email protected]744c2a22012-03-15 18:42:042805 url.SchemeIs(chrome::kViewSourceScheme) ||
[email protected]1c210f692012-11-06 22:31:472806 (frame->isViewSourceModeEnabled() &&
2807 type != WebKit::WebNavigationTypeReload);
[email protected]5351dbc2010-08-27 15:22:112808
[email protected]dc67e1c32012-06-08 00:10:402809 if (!should_fork && url.SchemeIs(chrome::kFileScheme)) {
2810 // Fork non-file to file opens. Check the opener URL if this is the
2811 // initial navigation in a newly opened window.
2812 GURL source_url(old_url);
2813 if (is_initial_navigation && source_url.is_empty() && frame->opener())
2814 source_url = frame->opener()->top()->document().url();
2815 DCHECK(!source_url.is_empty());
2816 should_fork = !source_url.SchemeIs(chrome::kFileScheme);
2817 }
2818
[email protected]e48869a2011-04-01 19:56:032819 if (!should_fork) {
2820 // Give the embedder a chance.
[email protected]744c2a22012-03-15 18:42:042821 // For now, we skip this for POST submissions. This is because
2822 // http://crbug.com/101395 is more likely to cause compatibility issues
2823 // with hosted apps and extensions than WebUI pages. We will remove this
2824 // check when cross-process POST submissions are supported.
2825 if (request.httpMethod() == "GET") {
[email protected]e9ff79c2012-10-19 21:31:262826 should_fork = GetContentClient()->renderer()->ShouldFork(
[email protected]744c2a22012-03-15 18:42:042827 frame, url, is_initial_navigation, &send_referrer);
2828 }
[email protected]6101c342010-12-16 22:44:372829 }
2830
2831 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152832 OpenURL(
2833 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112834 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2835 }
[email protected]3d9689372009-09-10 04:29:172836 }
2837
2838 // Detect when a page is "forking" a new tab that can be safely rendered in
2839 // its own process. This is done by sites like Gmail that try to open links
2840 // in new windows without script connections back to the original page. We
2841 // treat such cases as browser navigations (in which we will create a new
2842 // renderer for a cross-site navigation), rather than WebKit navigations.
2843 //
2844 // We use the following heuristic to decide whether to fork a new page in its
2845 // own process:
2846 // The parent page must open a new tab to about:blank, set the new tab's
2847 // window.opener to null, and then redirect the tab to a cross-site URL using
2848 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462849 //
2850 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2851 // (see below).
[email protected]3d9689372009-09-10 04:29:172852 bool is_fork =
2853 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582854 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172855 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522856 historyBackListCount() < 1 &&
2857 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172858 // The parent page must have set the child's window.opener to null before
2859 // redirecting to the desired URL.
2860 frame->opener() == NULL &&
2861 // Must be a top-level frame.
2862 frame->parent() == NULL &&
2863 // Must not have issued the request from this page.
2864 is_content_initiated &&
2865 // Must be targeted at the current tab.
2866 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2867 // Must be a JavaScript navigation, which appears as "other".
2868 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462869
[email protected]f92ce2b2012-03-06 18:02:592870 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:172871 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152872 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172873 return WebKit::WebNavigationPolicyIgnore;
2874 }
2875
2876 return default_policy;
2877}
2878
[email protected]310ebd6302011-10-10 19:06:282879bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492880 WebFrame* frame, const WebURLRequest& request) {
2881 // We allow WebKit to think that everything can be handled even though
2882 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342883 return true;
2884}
2885
[email protected]310ebd6302011-10-10 19:06:282886WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492887 WebFrame* frame, const WebURLRequest& request) {
2888 NOTREACHED(); // Since we said we can handle all requests.
2889 return WebURLError();
2890}
2891
[email protected]310ebd6302011-10-10 19:06:282892WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492893 WebFrame* frame, const WebURLRequest& request) {
2894 WebURLError error;
2895 error.domain = WebString::fromUTF8(net::kErrorDomain);
2896 error.reason = net::ERR_ABORTED;
2897 error.unreachableURL = request.url();
2898 return error;
[email protected]7b7a7dc2009-10-19 02:23:342899}
2900
[email protected]310ebd6302011-10-10 19:06:282901void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492902 WebFrame*, const WebURLError&) {
2903 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342904}
2905
[email protected]310ebd6302011-10-10 19:06:282906void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432907 const WebKit::WebFormElement& form) {
2908 // Some login forms have onSubmit handlers that put a hash of the password
2909 // into a hidden field and then clear the password. (Issue 28910.)
2910 // This method gets called before any of those handlers run, so save away
2911 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072912 DocumentState* document_state =
2913 DocumentState::FromDataSource(frame->dataSource());
[email protected]e9ff79c2012-10-19 21:31:262914 document_state->set_password_form_data(CreatePasswordForm(form));
[email protected]90eeddb2010-05-06 21:06:432915}
2916
[email protected]310ebd6302011-10-10 19:06:282917void RenderViewImpl::willSubmitForm(WebFrame* frame,
2918 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072919 DocumentState* document_state =
2920 DocumentState::FromDataSource(frame->provisionalDataSource());
2921 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172922
[email protected]e9ff79c2012-10-19 21:31:262923 if (navigation_state->transition_type() == PAGE_TRANSITION_LINK)
2924 navigation_state->set_transition_type(PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172925
2926 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352927 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072928 document_state->set_searchable_form_url(web_searchable_form_data.url());
2929 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212930 web_searchable_form_data.encoding().utf8());
[email protected]a045f4e32012-08-31 09:36:072931 scoped_ptr<PasswordForm> password_form_data =
[email protected]e9ff79c2012-10-19 21:31:262932 CreatePasswordForm(form);
[email protected]90eeddb2010-05-06 21:06:432933
[email protected]098c95cb2011-04-28 16:49:012934 // In order to save the password that the user actually typed and not one
2935 // that may have gotten transformed by the site prior to submit, recover it
2936 // from the form contents already stored by |willSendSubmitEvent| into the
2937 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2938 // which is what we're storing into now.)
[email protected]a045f4e32012-08-31 09:36:072939 if (password_form_data.get()) {
[email protected]007733c2011-11-17 00:34:072940 DocumentState* old_document_state =
2941 DocumentState::FromDataSource(frame->dataSource());
2942 if (old_document_state) {
2943 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432944 if (old_form_data && old_form_data->action == password_form_data->action)
2945 password_form_data->password_value = old_form_data->password_value;
2946 }
2947 }
[email protected]3d9689372009-09-10 04:29:172948
[email protected]a045f4e32012-08-31 09:36:072949 document_state->set_password_form_data(password_form_data.Pass());
2950
[email protected]2a5b1732011-04-01 23:55:552951 FOR_EACH_OBSERVER(
2952 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172953}
2954
[email protected]310ebd6302011-10-10 19:06:282955void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172956 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2957 double fire_time) {
[email protected]bf692cd2012-11-14 19:10:022958 // Replace any occurrences of swappedout:// with about:blank.
2959 const WebURL& blank_url = GURL(chrome::kAboutBlankURL);
[email protected]eb0bff942011-04-07 22:08:382960 FOR_EACH_OBSERVER(
2961 RenderViewObserver, observers_,
[email protected]bf692cd2012-11-14 19:10:022962 WillPerformClientRedirect(frame,
2963 from == GURL(kSwappedOutURL) ? blank_url : from,
2964 to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172965}
2966
[email protected]310ebd6302011-10-10 19:06:282967void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382968 FOR_EACH_OBSERVER(
2969 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172970}
2971
[email protected]310ebd6302011-10-10 19:06:282972void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172973 WebFrame* frame, const WebURL& from) {
[email protected]bf692cd2012-11-14 19:10:022974 // Replace any occurrences of swappedout:// with about:blank.
2975 const WebURL& blank_url = GURL(chrome::kAboutBlankURL);
[email protected]445e1042011-12-03 21:03:152976 if (!frame->parent()) {
2977 WebDataSource* ds = frame->provisionalDataSource();
2978 // If there's no provisional data source, it's a reference fragment
2979 // navigation.
2980 completed_client_redirect_src_ = Referrer(
[email protected]bf692cd2012-11-14 19:10:022981 from == GURL(kSwappedOutURL) ? blank_url : from,
2982 ds ? GetReferrerPolicyFromRequest(frame, ds->request()) :
[email protected]f36f4092012-05-09 18:31:042983 frame->document().referrerPolicy());
[email protected]445e1042011-12-03 21:03:152984 }
[email protected]eb0bff942011-04-07 22:08:382985 FOR_EACH_OBSERVER(
[email protected]bf692cd2012-11-14 19:10:022986 RenderViewObserver, observers_, DidCompleteClientRedirect(
2987 frame, from == GURL(kSwappedOutURL) ? blank_url : from));
[email protected]3d9689372009-09-10 04:29:172988}
2989
[email protected]310ebd6302011-10-10 19:06:282990void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:572991 bool content_initiated = !pending_navigation_params_.get();
2992
[email protected]007733c2011-11-17 00:34:072993 DocumentState* document_state = DocumentState::FromDataSource(ds);
2994 if (!document_state) {
2995 document_state = new DocumentState;
2996 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:572997 if (!content_initiated)
2998 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:072999 }
3000
[email protected]bf70edce2012-06-20 22:32:223001 // Carry over the user agent override flag, if it exists.
3002 if (content_initiated && webview() && webview()->mainFrame() &&
3003 webview()->mainFrame()->dataSource()) {
3004 DocumentState* old_document_state =
3005 DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
3006 if (old_document_state) {
3007 document_state->set_is_overriding_user_agent(
3008 old_document_state->is_overriding_user_agent());
3009 }
3010 }
3011
[email protected]3d9689372009-09-10 04:29:173012 // The rest of RenderView assumes that a WebDataSource will always have a
3013 // non-null NavigationState.
[email protected]e1ed5a12012-08-08 19:57:443014 if (content_initiated) {
[email protected]007733c2011-11-17 00:34:073015 document_state->set_navigation_state(
3016 NavigationState::CreateContentInitiated());
[email protected]e1ed5a12012-08-08 19:57:443017 } else {
[email protected]45d83a12012-04-06 22:57:573018 document_state->set_navigation_state(CreateNavigationStateFromPending());
3019 pending_navigation_params_.reset();
3020 }
[email protected]8a3125a712010-08-09 18:58:513021
[email protected]007733c2011-11-17 00:34:073022 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:513023 // navigating from a page that used prefetching using a link on that
3024 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:073025 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:513026 // this value appropriately.
3027 // TODO(gavinp): catch the important case of navigation in a new
3028 // renderer process.
3029 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303030 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523031 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513032 const GURL referrer(
3033 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3034 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:073035 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:513036 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:413037 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:513038 WebDataSource* old_frame_ds = old_frame->dataSource();
3039 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:073040 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513041 break;
3042 }
3043 }
3044 }
3045 }
3046 }
3047
[email protected]4c1b6f0b2010-02-07 16:38:183048 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523049 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513050 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183051 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:073052 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:183053 break;
3054 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:073055 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:183056 break;
3057 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:073058 document_state->set_load_type(
3059 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:183060 break;
3061 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:073062 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:183063 break;
3064 }
3065 }
[email protected]fa7b6b542009-11-03 05:02:303066
[email protected]946a0032011-03-31 18:42:283067 FOR_EACH_OBSERVER(
3068 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:173069}
3070
[email protected]45d83a12012-04-06 22:57:573071void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:073072 DocumentState* document_state) {
3073 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:573074 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:073075
[email protected]45d83a12012-04-06 22:57:573076 if (!params.url.SchemeIs(chrome::kJavaScriptScheme) &&
3077 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
3078 // We're doing a load of a page that was restored from the last session. By
3079 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
3080 // can result in stale data for pages that are set to expire. We explicitly
3081 // override that by setting the policy here so that as necessary we load
3082 // from the network.
3083 document_state->set_cache_policy_override(
3084 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:073085 }
3086
3087 if (IsReload(params))
3088 document_state->set_load_type(DocumentState::RELOAD);
3089 else if (!params.state.empty())
3090 document_state->set_load_type(DocumentState::HISTORY_LOAD);
3091 else
3092 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]ca662822012-05-11 17:53:593093
3094 document_state->set_referrer_policy(params.referrer.policy);
[email protected]bf70edce2012-06-20 22:32:223095 document_state->set_is_overriding_user_agent(params.is_overriding_user_agent);
[email protected]a3a5397d2012-09-12 06:50:343096 document_state->set_must_reset_scroll_and_scale_state(
3097 params.navigation_type ==
3098 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]951a64832012-10-11 16:26:373099 document_state->set_can_load_local_resources(params.can_load_local_resources);
[email protected]45d83a12012-04-06 22:57:573100}
[email protected]007733c2011-11-17 00:34:073101
[email protected]45d83a12012-04-06 22:57:573102NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
3103 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
3104 NavigationState* navigation_state = NULL;
3105
3106 // A navigation resulting from loading a javascript URL should not be treated
3107 // as a browser initiated event. Instead, we want it to look as if the page
3108 // initiated any load resulting from JS execution.
3109 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
3110 navigation_state = NavigationState::CreateBrowserInitiated(
3111 params.page_id,
3112 params.pending_history_list_offset,
3113 params.transition);
3114 navigation_state->set_transferred_request_child_id(
3115 params.transferred_request_child_id);
3116 navigation_state->set_transferred_request_request_id(
3117 params.transferred_request_request_id);
[email protected]80744782012-05-04 01:47:003118 navigation_state->set_allow_download(params.allow_download);
[email protected]45d83a12012-04-06 22:57:573119 } else {
3120 navigation_state = NavigationState::CreateContentInitiated();
3121 }
3122 return navigation_state;
[email protected]007733c2011-11-17 00:34:073123}
3124
[email protected]5b52cd2f712012-03-28 02:12:483125void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
3126 bool enable_viewport =
[email protected]06ea34a2012-05-07 18:52:103127 command_line.HasSwitch(switches::kEnableViewport);
[email protected]5b52cd2f712012-03-28 02:12:483128 bool enable_fixed_layout =
3129 command_line.HasSwitch(switches::kEnableFixedLayout);
3130
3131 webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport);
3132 webview()->settings()->setFixedElementsLayoutRelativeToFrame(true);
3133
3134 if (enable_viewport) {
3135 webview()->settings()->setViewportEnabled(true);
3136 } else if (enable_fixed_layout) {
3137 std::string str =
3138 command_line.GetSwitchValueASCII(switches::kEnableFixedLayout);
3139 std::vector<std::string> tokens;
3140 base::SplitString(str, ',', &tokens);
3141 if (tokens.size() == 2) {
3142 int width, height;
3143 if (base::StringToInt(tokens[0], &width) &&
3144 base::StringToInt(tokens[1], &height))
[email protected]e1ed5a12012-08-08 19:57:443145 webview()->setFixedLayoutSize(WebSize(width, height));
[email protected]5b52cd2f712012-03-28 02:12:483146 }
3147 }
[email protected]1c0c9bc2012-10-08 22:41:483148
3149 ProcessAcceleratedPinchZoomFlags(command_line);
3150}
3151
3152void RenderViewImpl::ProcessAcceleratedPinchZoomFlags(
3153 const CommandLine& command_line) {
3154 bool enable_viewport =
3155 command_line.HasSwitch(switches::kEnableViewport);
3156 bool enable_pinch = enable_viewport ||
3157 command_line.HasSwitch(switches::kEnablePinch);
3158 bool enable_pinch_in_compositor =
[email protected]65bfd9972012-10-19 03:39:373159 command_line.HasSwitch(cc::switches::kEnablePinchInCompositor);
[email protected]1c0c9bc2012-10-08 22:41:483160
3161 if (!enable_pinch &&
3162 webview()->isAcceleratedCompositingActive() &&
3163 webkit_preferences_.apply_default_device_scale_factor_in_compositor &&
3164 device_scale_factor_ != 1) {
3165 // Page scaling is disabled by default when applying a scale factor in the
3166 // compositor since they are currently incompatible.
3167 webview()->setPageScaleFactorLimits(1, 1);
3168 }
3169
3170 if (enable_pinch_in_compositor &&
3171 webview()->isAcceleratedCompositingActive())
3172 webview()->setPageScaleFactorLimits(1, 4);
[email protected]5b52cd2f712012-03-28 02:12:483173}
3174
[email protected]310ebd6302011-10-10 19:06:283175void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173176 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:073177 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:173178
[email protected]3d9689372009-09-10 04:29:173179 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:073180 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:173181 double event_time = ds->triggeringEventTime();
3182 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:073183 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:173184 }
3185
[email protected]05c8e502010-08-15 15:13:523186 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:073187 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:523188
[email protected]3d9689372009-09-10 04:29:173189 bool is_top_most = !frame->parent();
3190 if (is_top_most) {
3191 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133192 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173193
3194 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:153195 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173196 } else if (frame->parent()->isLoading()) {
3197 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003198 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:073199 document_state->navigation_state()->set_transition_type(
[email protected]e9ff79c2012-10-19 21:31:263200 PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:173201 }
3202
[email protected]28685da92011-02-07 21:49:173203 FOR_EACH_OBSERVER(
3204 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
3205
[email protected]3d9689372009-09-10 04:29:173206 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]d37c33e2012-10-12 13:35:133207 routing_id_, frame->identifier(),
3208 frame->parent() ? frame->parent()->identifier() : -1,
3209 is_top_most, GetOpenerUrl(), ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173210}
3211
[email protected]400992b2012-06-14 00:03:543212void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
3213 WebFrame* frame) {
3214 if (frame->parent())
3215 return;
3216 // Received a redirect on the main frame.
3217 WebDataSource* data_source = frame->provisionalDataSource();
3218 if (!data_source) {
3219 // Should only be invoked when we have a data source.
3220 NOTREACHED();
3221 return;
3222 }
3223 std::vector<GURL> redirects;
3224 GetRedirectChain(data_source, &redirects);
3225 if (redirects.size() >= 2) {
3226 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
3227 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
3228 }
3229}
3230
[email protected]310ebd6302011-10-10 19:06:283231void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
3232 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173233 // Notify the browser that we failed a provisional load with an error.
3234 //
3235 // Note: It is important this notification occur before DidStopLoading so the
3236 // SSL manager can react to the provisional load failure before being
3237 // notified the load stopped.
3238 //
3239 WebDataSource* ds = frame->provisionalDataSource();
3240 DCHECK(ds);
3241
3242 const WebURLRequest& failed_request = ds->request();
3243
[email protected]28685da92011-02-07 21:49:173244 FOR_EACH_OBSERVER(
3245 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
3246
[email protected]3d9689372009-09-10 04:29:173247 bool show_repost_interstitial =
3248 (error.reason == net::ERR_CACHE_MISS &&
3249 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:583250
3251 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
3252 params.frame_id = frame->identifier();
3253 params.is_main_frame = !frame->parent();
3254 params.error_code = error.reason;
[email protected]e9ff79c2012-10-19 21:31:263255 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]d7b175e2011-10-11 15:31:583256 failed_request,
3257 error,
3258 NULL,
3259 &params.error_description);
3260 params.url = error.unreachableURL;
3261 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:173262 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:583263 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:173264
3265 // Don't display an error page if this is simply a cancelled load. Aside
3266 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3267 if (error.reason == net::ERR_ABORTED)
3268 return;
3269
3270 // Make sure we never show errors in view source mode.
3271 frame->enableViewSourceMode(false);
3272
[email protected]007733c2011-11-17 00:34:073273 DocumentState* document_state = DocumentState::FromDataSource(ds);
3274 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173275
3276 // If this is a failed back/forward/reload navigation, then we need to do a
3277 // 'replace' load. This is necessary to avoid messing up session history.
3278 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3279 // as session history is concerned.
3280 //
3281 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3282 // the page id.
3283 //
3284 bool replace =
3285 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:583286 navigation_state->transition_type() ==
[email protected]e9ff79c2012-10-19 21:31:263287 PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:173288
3289 // If we failed on a browser initiated request, then make sure that our error
3290 // page load is regarded as the same browser initiated request.
3291 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:073292 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
3293 pending_navigation_params_->page_id =
3294 navigation_state->pending_page_id();
3295 pending_navigation_params_->pending_history_list_offset =
3296 navigation_state->pending_history_list_offset();
3297 pending_navigation_params_->transition =
3298 navigation_state->transition_type();
3299 pending_navigation_params_->request_time =
3300 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:173301 }
3302
3303 // Provide the user with a more helpful error page?
3304 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3305 return;
3306
3307 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083308 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173309}
3310
[email protected]310ebd6302011-10-10 19:06:283311void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:173312 WebFrame* frame, const char* data, size_t data_len,
3313 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:073314 DocumentState* document_state =
3315 DocumentState::FromDataSource(frame->dataSource());
3316 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:173317}
3318
[email protected]310ebd6302011-10-10 19:06:283319void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
3320 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:073321 DocumentState* document_state =
3322 DocumentState::FromDataSource(frame->dataSource());
3323 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173324
[email protected]007733c2011-11-17 00:34:073325 if (document_state->commit_load_time().is_null())
3326 document_state->set_commit_load_time(Time::Now());
3327
[email protected]a3a5397d2012-09-12 06:50:343328 if (document_state->must_reset_scroll_and_scale_state()) {
[email protected]c38d49c2012-10-24 21:46:573329#if defined(OS_ANDROID) // crbug.com/153907
[email protected]a3a5397d2012-09-12 06:50:343330 webview()->resetScrollAndScaleState();
[email protected]c38d49c2012-10-24 21:46:573331#endif
[email protected]a3a5397d2012-09-12 06:50:343332 document_state->set_must_reset_scroll_and_scale_state(false);
3333 }
3334
[email protected]3d9689372009-09-10 04:29:173335 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203336 // When we perform a new navigation, we need to update the last committed
3337 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173338 UpdateSessionHistory(frame);
3339
3340 // We bump our Page ID to correspond with the new session history entry.
3341 page_id_ = next_page_id_++;
3342
[email protected]e9ff79c2012-10-19 21:31:263343 // Don't update history_page_ids_ (etc) for kSwappedOutURL, since
[email protected]58436a12012-03-21 17:10:263344 // we don't want to forget the entry that was there, and since we will
[email protected]e9ff79c2012-10-19 21:31:263345 // never come back to kSwappedOutURL. Note that we have to call
[email protected]69ddf852012-02-21 23:21:313346 // UpdateSessionHistory and update page_id_ even in this case, so that
3347 // the current entry gets a state update and so that we don't send a
3348 // state update to the wrong entry when we swap back in.
[email protected]e9ff79c2012-10-19 21:31:263349 if (GetLoadingUrl(frame) != GURL(kSwappedOutURL)) {
[email protected]69ddf852012-02-21 23:21:313350 // Advance our offset in session history, applying the length limit.
3351 // There is now no forward history.
3352 history_list_offset_++;
[email protected]e9ff79c2012-10-19 21:31:263353 if (history_list_offset_ >= kMaxSessionHistoryEntries)
3354 history_list_offset_ = kMaxSessionHistoryEntries - 1;
[email protected]69ddf852012-02-21 23:21:313355 history_list_length_ = history_list_offset_ + 1;
3356 history_page_ids_.resize(history_list_length_, -1);
3357 history_page_ids_[history_list_offset_] = page_id_;
3358 }
[email protected]3d9689372009-09-10 04:29:173359 } else {
3360 // Inspect the navigation_state on this frame to see if the navigation
3361 // corresponds to a session history navigation... Note: |frame| may or
3362 // may not be the toplevel frame, but for the case of capturing session
3363 // history, the first committed frame suffices. We keep track of whether
3364 // we've seen this commit before so that only capture session history once
3365 // per navigation.
3366 //
3367 // Note that we need to check if the page ID changed. In the case of a
3368 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3369 // previous URL and the current page ID, which would be wrong.
3370 if (navigation_state->pending_page_id() != -1 &&
3371 navigation_state->pending_page_id() != page_id_ &&
3372 !navigation_state->request_committed()) {
3373 // This is a successful session history navigation!
3374 UpdateSessionHistory(frame);
3375 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003376
3377 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:033378
3379 // If the history list is valid, our list of page IDs should be correct.
3380 DCHECK(history_list_length_ <= 0 ||
3381 history_list_offset_ < 0 ||
3382 history_list_offset_ >= history_list_length_ ||
3383 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:173384 }
3385 }
3386
[email protected]28685da92011-02-07 21:49:173387 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3388 DidCommitProvisionalLoad(frame, is_new_navigation));
3389
[email protected]3d9689372009-09-10 04:29:173390 // Remember that we've already processed this request, so we don't update
3391 // the session history again. We do this regardless of whether this is
3392 // a session history navigation, because if we attempted a session history
3393 // navigation without valid HistoryItem state, WebCore will think it is a
3394 // new navigation.
3395 navigation_state->set_request_committed(true);
3396
3397 UpdateURL(frame);
3398
3399 // If this committed load was initiated by a client redirect, we're
3400 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:153401 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173402
3403 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273404 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]b2d98762012-09-03 17:04:063405
3406 if (!frame->parent()) { // Only for top frames.
3407 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
3408 if (render_thread_impl) { // Can be NULL in tests.
3409 render_thread_impl->histogram_customizer()->
3410 RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(),
3411 g_view_map.Get().size());
3412 }
3413 }
[email protected]3d9689372009-09-10 04:29:173414}
3415
[email protected]310ebd6302011-10-10 19:06:283416void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:103417 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3418 DidClearWindowObject(frame));
3419
[email protected]b6cb3a842011-06-24 18:28:413420 GURL frame_url = frame->document().url();
[email protected]e9ff79c2012-10-19 21:31:263421 if ((enabled_bindings_ & BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:253422 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
3423 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:273424 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:173425 }
[email protected]766a7082012-02-03 23:39:153426
[email protected]e9ff79c2012-10-19 21:31:263427 if (enabled_bindings_ & BINDINGS_POLICY_DOM_AUTOMATION) {
[email protected]766a7082012-02-03 23:39:153428 if (!dom_automation_controller_.get())
3429 dom_automation_controller_.reset(new DomAutomationController());
3430 dom_automation_controller_->set_message_sender(
[email protected]e9ff79c2012-10-19 21:31:263431 static_cast<RenderView*>(this));
[email protected]766a7082012-02-03 23:39:153432 dom_automation_controller_->set_routing_id(routing_id());
3433 dom_automation_controller_->BindToJavascript(frame,
3434 "domAutomationController");
3435 }
[email protected]498bc512012-09-21 21:50:083436
[email protected]e9ff79c2012-10-19 21:31:263437 InjectDoNotTrackBindings(frame);
[email protected]3d9689372009-09-10 04:29:173438}
3439
[email protected]310ebd6302011-10-10 19:06:283440void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173441 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:413442 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:253443 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]87717d0e2012-04-26 02:58:433444 if (frame == webview()->mainFrame())
3445 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:173446 }
[email protected]e48869a2011-04-01 19:56:033447
3448 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3449 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:173450}
3451
[email protected]310ebd6302011-10-10 19:06:283452void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
3453 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:463454 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:173455
3456 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273457 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173458}
3459
[email protected]310ebd6302011-10-10 19:06:283460void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:133461 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3462 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:583463}
3464
[email protected]310ebd6302011-10-10 19:06:283465void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173466 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073467 DocumentState* document_state = DocumentState::FromDataSource(ds);
3468 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:173469
[email protected]622474d2010-11-04 09:21:083470 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173471
[email protected]28685da92011-02-07 21:49:173472 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3473 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173474
3475 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273476 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173477}
3478
[email protected]310ebd6302011-10-10 19:06:283479void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083480 if (webview()->mainFrame() == frame) {
3481 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3482 page_id_));
3483 }
[email protected]3d9689372009-09-10 04:29:173484}
3485
[email protected]310ebd6302011-10-10 19:06:283486void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:313487 WebDataSource* ds = frame->dataSource();
3488 DCHECK(ds);
3489
3490
[email protected]28685da92011-02-07 21:49:173491 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:313492
3493 const WebURLRequest& failed_request = ds->request();
3494 string16 error_description;
[email protected]e9ff79c2012-10-19 21:31:263495 GetContentClient()->renderer()->GetNavigationErrorStrings(
[email protected]1a55c5be2011-11-29 11:36:313496 failed_request,
3497 error,
3498 NULL,
3499 &error_description);
3500 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
3501 frame->identifier(),
3502 failed_request.url(),
3503 !frame->parent(),
3504 error.reason,
3505 error_description));
[email protected]3d9689372009-09-10 04:29:173506}
3507
[email protected]310ebd6302011-10-10 19:06:283508void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173509 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073510 DocumentState* document_state = DocumentState::FromDataSource(ds);
3511 if (document_state->finish_load_time().is_null())
3512 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:413513
[email protected]676126f72011-01-15 00:03:513514 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173515
[email protected]1a55c5be2011-11-29 11:36:313516 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
3517 frame->identifier(),
3518 ds->request().url(),
3519 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:173520}
3521
[email protected]310ebd6302011-10-10 19:06:283522void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173523 WebFrame* frame, bool is_new_navigation) {
3524 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:073525 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:173526 // update the ExtraData on the datasource so that others who read the
3527 // ExtraData will get the new NavigationState. Similarly, if we did not
3528 // initiate this navigation, then we need to take care to reset any pre-
3529 // existing navigation state to a content-initiated navigation state.
3530 // DidCreateDataSource conveniently takes care of this for us.
3531 didCreateDataSource(frame, frame->dataSource());
3532
[email protected]007733c2011-11-17 00:34:073533 DocumentState* document_state =
3534 DocumentState::FromDataSource(frame->dataSource());
3535 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:093536 new_state->set_was_within_same_page(true);
3537
[email protected]3d9689372009-09-10 04:29:173538 didCommitProvisionalLoad(frame, is_new_navigation);
3539
[email protected]750fcf872011-08-03 23:10:473540 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
3541 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:173542}
3543
[email protected]310ebd6302011-10-10 19:06:283544void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313545 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593546}
3547
[email protected]310ebd6302011-10-10 19:06:283548void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:173549 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3550 // Ignore
3551}
3552
[email protected]310ebd6302011-10-10 19:06:283553void RenderViewImpl::willSendRequest(WebFrame* frame,
3554 unsigned identifier,
3555 WebURLRequest& request,
3556 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303557 WebFrame* top_frame = frame->top();
3558 if (!top_frame)
3559 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513560 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3561 WebDataSource* top_data_source = top_frame->dataSource();
3562 WebDataSource* data_source =
3563 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:223564
[email protected]e9ff79c2012-10-19 21:31:263565 PageTransition transition_type = PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:073566 DocumentState* document_state = DocumentState::FromDataSource(data_source);
[email protected]def55e022012-07-26 01:15:293567 DCHECK(document_state);
[email protected]007733c2011-11-17 00:34:073568 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e1ed5a12012-08-08 19:57:443569 transition_type = navigation_state->transition_type();
3570
3571 GURL request_url(request.url());
3572 GURL new_url;
[email protected]e9ff79c2012-10-19 21:31:263573 if (GetContentClient()->renderer()->WillSendRequest(
[email protected]e1ed5a12012-08-08 19:57:443574 frame, transition_type, request_url, &new_url)) {
3575 request.setURL(WebURL(new_url));
3576 }
3577
[email protected]def55e022012-07-26 01:15:293578 if (document_state->is_cache_policy_override_set())
3579 request.setCachePolicy(document_state->cache_policy_override());
[email protected]8a3125a712010-08-09 18:58:513580
[email protected]ca662822012-05-11 17:53:593581 WebKit::WebReferrerPolicy referrer_policy;
3582 if (document_state && document_state->is_referrer_policy_set()) {
3583 referrer_policy = document_state->referrer_policy();
3584 document_state->clear_referrer_policy();
3585 } else {
3586 referrer_policy = frame->document().referrerPolicy();
3587 }
3588
[email protected]e372f3d2012-07-17 19:16:443589 // The request's extra data may indicate that we should set a custom user
3590 // agent. This needs to be done here, after WebKit is through with setting the
3591 // user agent on its own.
3592 WebString custom_user_agent;
3593 if (request.extraData()) {
3594 webkit_glue::WebURLRequestExtraDataImpl* old_extra_data =
3595 static_cast<webkit_glue::WebURLRequestExtraDataImpl*>(
3596 request.extraData());
3597 custom_user_agent = old_extra_data->custom_user_agent();
3598
3599 if (!custom_user_agent.isNull()) {
3600 if (custom_user_agent.isEmpty())
3601 request.clearHTTPHeaderField("User-Agent");
3602 else
3603 request.setHTTPHeaderField("User-Agent", custom_user_agent);
3604 }
3605 }
3606
[email protected]91043a8232011-11-04 16:41:193607 request.setExtraData(
[email protected]ca662822012-05-11 17:53:593608 new RequestExtraData(referrer_policy,
[email protected]e372f3d2012-07-17 19:16:443609 custom_user_agent,
[email protected]537fbe02011-11-24 00:58:063610 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:193611 frame->identifier(),
3612 frame->parent() == top_frame,
3613 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]80744782012-05-04 01:47:003614 navigation_state->allow_download(),
[email protected]4ad5d77d2011-12-03 02:00:483615 transition_type,
3616 navigation_state->transferred_request_child_id(),
3617 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:573618
[email protected]007733c2011-11-17 00:34:073619 DocumentState* top_document_state =
3620 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:573621 // TODO(gavinp): separate out prefetching and prerender field trials
3622 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:073623 if (top_document_state &&
[email protected]925dec1c2012-05-18 05:09:003624 request.targetType() == WebURLRequest::TargetIsPrefetch)
[email protected]007733c2011-11-17 00:34:073625 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513626
[email protected]3d9689372009-09-10 04:29:173627 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133628 request.setHasUserGesture(frame->isProcessingUserGesture());
3629
[email protected]0a8db0d2011-04-13 15:15:403630 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:133631 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:173632}
3633
[email protected]310ebd6302011-10-10 19:06:283634void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173635 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493636
[email protected]3d9689372009-09-10 04:29:173637 // Only do this for responses that correspond to a provisional data source
3638 // of the top-most frame. If we have a provisional data source, then we
3639 // can't have any sub-resources yet, so we know that this response must
3640 // correspond to a frame load.
3641 if (!frame->provisionalDataSource() || frame->parent())
3642 return;
3643
3644 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083645 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173646 if (frame->isViewSourceModeEnabled())
3647 return;
3648
[email protected]007733c2011-11-17 00:34:073649 DocumentState* document_state =
3650 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083651 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533652
[email protected]972ebdff2010-06-10 22:59:073653 // Record page load flags.
[email protected]007733c2011-11-17 00:34:073654 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3655 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]b9fd01ba2012-02-28 01:50:403656 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
3657 if (extra_data) {
3658 document_state->set_npn_negotiated_protocol(
3659 extra_data->npn_negotiated_protocol());
3660 }
[email protected]007733c2011-11-17 00:34:073661 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:573662 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:073663 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3664 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093665 // Whether or not the http status code actually corresponds to an error is
3666 // only checked when the page is done loading, if |use_error_page| is
3667 // still true.
[email protected]007733c2011-11-17 00:34:073668 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173669}
3670
[email protected]310ebd6302011-10-10 19:06:283671void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173672 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:073673 DocumentState* document_state =
3674 DocumentState::FromDataSource(frame->dataSource());
3675 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173676 return;
3677
[email protected]7bfc153f2011-09-23 22:00:203678 // Do not show error page when DevTools is attached.
3679 if (devtools_agent_->IsAttached())
3680 return;
3681
[email protected]06333afe2011-02-24 14:55:093682 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:073683 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:083684 if (http_status_code == 404) {
3685 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413686 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173687
[email protected]b6cb3a842011-06-24 18:28:413688 const GURL& error_page_url =
3689 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093690 if (error_page_url.is_valid()) {
3691 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473692 original_error.domain = "http";
3693 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413694 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173695
[email protected]007733c2011-11-17 00:34:073696 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093697 new AltErrorPageResourceFetcher(
3698 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:083699 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3700 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093701 return;
3702 }
3703 }
[email protected]3d9689372009-09-10 04:29:173704
[email protected]e6a2ce52011-10-08 01:40:133705 std::string error_domain;
[email protected]e9ff79c2012-10-19 21:31:263706 if (GetContentClient()->renderer()->HasErrorPage(
[email protected]e6a2ce52011-10-08 01:40:133707 http_status_code, &error_domain)) {
3708 WebURLError error;
3709 error.unreachableURL = frame->document().url();
3710 error.domain = WebString::fromUTF8(error_domain);
3711 error.reason = http_status_code;
3712
3713 LoadNavigationErrorPage(
3714 frame, frame->dataSource()->request(), error, std::string(), true);
3715 }
[email protected]3d9689372009-09-10 04:29:173716}
3717
[email protected]310ebd6302011-10-10 19:06:283718void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173719 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3720 // Ignore
3721}
3722
[email protected]310ebd6302011-10-10 19:06:283723void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173724 WebFrame* frame, const WebURLRequest& request,
3725 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003726 // The recipients of this message have no use for data: URLs: they don't
3727 // affect the page's insecure content list and are not in the disk cache. To
3728 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3729 // filter them out here.
3730 GURL url(request.url());
3731 if (url.SchemeIs("data"))
3732 return;
3733
[email protected]3d9689372009-09-10 04:29:173734 // Let the browser know we loaded a resource from the memory cache. This
3735 // message is needed to display the correct SSL indicators.
3736 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3737 routing_id_,
[email protected]84703292011-10-28 20:44:003738 url,
[email protected]70435962011-08-02 20:13:283739 response.securityInfo(),
3740 request.httpMethod().utf8(),
[email protected]6d6cfb3a2012-05-23 22:53:183741 response.mimeType().utf8(),
[email protected]70435962011-08-02 20:13:283742 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173743}
3744
[email protected]310ebd6302011-10-10 19:06:283745void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293746 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3747}
3748
[email protected]310ebd6302011-10-10 19:06:283749void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023750 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293751 Send(new ViewHostMsg_DidRunInsecureContent(
3752 routing_id_,
[email protected]92771112011-01-20 00:13:023753 origin.toString().utf8(),
3754 target));
[email protected]e3d60e5d2009-09-25 21:08:293755}
3756
[email protected]310ebd6302011-10-10 19:06:283757void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173758 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3759}
3760
[email protected]310ebd6302011-10-10 19:06:283761void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3762 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583763 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283764 int world_id) {
[email protected]e9ff79c2012-10-19 21:31:263765 GetContentClient()->renderer()->DidCreateScriptContext(
[email protected]a00fe692012-02-27 05:52:583766 frame, context, extension_group, world_id);
[email protected]7a137c9d2012-10-16 20:41:203767
3768 intents_host_->DidCreateScriptContext(
3769 frame, context, extension_group, world_id);
[email protected]a00fe692012-02-27 05:52:583770}
3771
[email protected]310ebd6302011-10-10 19:06:283772void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3773 v8::Handle<v8::Context> context,
3774 int world_id) {
[email protected]e9ff79c2012-10-19 21:31:263775 GetContentClient()->renderer()->WillReleaseScriptContext(
[email protected]5bc10932011-09-21 21:03:303776 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283777}
3778
[email protected]310ebd6302011-10-10 19:06:283779void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073780 // We don't always want to send the change messages over IPC, only if we've
3781 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3782 // message.
3783 if (!send_preferred_size_changes_ || !webview())
3784 return;
3785
[email protected]705243f2010-05-05 19:58:073786 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3787 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533788
3789 // In the presence of zoom, these sizes are still reported as if unzoomed,
3790 // so we need to adjust.
3791 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3792 size.set_width(static_cast<int>(size.width() * zoom_factor));
3793 size.set_height(static_cast<int>(size.height() * zoom_factor));
3794
[email protected]705243f2010-05-05 19:58:073795 if (size == preferred_size_)
3796 return;
[email protected]c27324b2009-11-19 22:44:293797
[email protected]705243f2010-05-05 19:58:073798 preferred_size_ = size;
3799 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3800 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173801}
3802
[email protected]1842fe22012-08-13 23:24:353803WebGraphicsContext3D* RenderViewImpl::CreateGraphicsContext3D(
3804 const WebGraphicsContext3D::Attributes& attributes) {
3805 if (!webview())
3806 return NULL;
3807
[email protected]1842fe22012-08-13 23:24:353808 // The WebGraphicsContext3DInProcessImpl code path is used for
3809 // layout tests (though not through this code) as well as for
3810 // debugging and bringing up new ports.
3811 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
3812 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
3813 attributes, true);
3814 } else {
3815 GURL url;
3816 if (webview()->mainFrame())
3817 url = GURL(webview()->mainFrame()->document().url());
3818 else
[email protected]f89e173a2012-08-24 01:12:263819 url = GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]1842fe22012-08-13 23:24:353820
3821 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
3822 new WebGraphicsContext3DCommandBufferImpl(
3823 surface_id(),
3824 url,
3825 RenderThreadImpl::current(),
3826 AsWeakPtr()));
3827
3828 if (!context->Initialize(
3829 attributes,
3830 false /* bind generates resources */,
[email protected]e9ff79c2012-10-19 21:31:263831 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
[email protected]1842fe22012-08-13 23:24:353832 return NULL;
3833 return context.release();
3834 }
3835}
3836
[email protected]0720b532012-08-28 19:23:373837// The browser process needs to know the shape of the tree, as well as the names
3838// and ids of all frames. This allows it to properly route JavaScript messages
3839// across processes and frames. The serialization format is described in the
3840// comments of the ViewMsg_FrameTreeUpdated message.
3841// This function sends those updates to the browser and updates the RVH
3842// corresponding to this object. It must be called on any events that modify
3843// the tree structure or the names of any frames.
3844void RenderViewImpl::SendUpdatedFrameTree(
3845 WebKit::WebFrame* exclude_frame_subtree) {
[email protected]e12dbe6f2012-10-04 22:11:193846 // TODO(nasko): Frame tree updates are causing issues with postMessage, as
3847 // described in http://crbug.com/153701. Disable them until a proper fix is
3848 // in place.
[email protected]0720b532012-08-28 19:23:373849}
3850
3851void RenderViewImpl::CreateFrameTree(WebKit::WebFrame* frame,
3852 DictionaryValue* frame_tree) {
[email protected]e12dbe6f2012-10-04 22:11:193853 // TODO(nasko): Remove once http://crbug.com/153701 is fixed.
3854 DCHECK(false);
[email protected]0720b532012-08-28 19:23:373855 NavigateToSwappedOutURL(frame);
3856
3857 string16 name;
[email protected]e9ff79c2012-10-19 21:31:263858 if (frame_tree->GetString(kFrameTreeNodeNameKey, &name) && !name.empty())
[email protected]0720b532012-08-28 19:23:373859 frame->setName(name);
[email protected]0720b532012-08-28 19:23:373860
3861 int remote_id;
[email protected]e9ff79c2012-10-19 21:31:263862 if (frame_tree->GetInteger(kFrameTreeNodeIdKey, &remote_id))
[email protected]0720b532012-08-28 19:23:373863 active_frame_id_map_.insert(std::pair<int, int>(frame->identifier(),
3864 remote_id));
3865
3866 ListValue* children;
[email protected]e9ff79c2012-10-19 21:31:263867 if (!frame_tree->GetList(kFrameTreeNodeSubtreeKey, &children))
[email protected]0720b532012-08-28 19:23:373868 return;
3869
[email protected]5fa9b36b2012-09-21 18:14:273870 // Create an invisible iframe tree in the swapped out page.
[email protected]0720b532012-08-28 19:23:373871 base::DictionaryValue* child;
3872 for (size_t i = 0; i < children->GetSize(); ++i) {
3873 if (!children->GetDictionary(i, &child))
3874 continue;
3875 WebElement element = frame->document().createElement("iframe");
[email protected]5fa9b36b2012-09-21 18:14:273876 element.setAttribute("width", "0");
3877 element.setAttribute("height", "0");
3878 element.setAttribute("frameBorder", "0");
[email protected]0720b532012-08-28 19:23:373879 if (frame->document().body().appendChild(element)) {
3880 WebFrame* subframe = WebFrame::fromFrameOwnerElement(element);
3881 if (subframe)
3882 CreateFrameTree(subframe, child);
3883 } else {
3884 LOG(ERROR) << "Failed to append created iframe element.";
3885 }
3886 }
3887}
3888
[email protected]d1a59e42012-10-03 18:05:353889WebKit::WebFrame* RenderViewImpl::GetFrameByRemoteID(int remote_frame_id) {
3890 std::map<int, int>::const_iterator it = active_frame_id_map_.begin();
3891 for (; it != active_frame_id_map_.end(); ++it) {
3892 if (it->second == remote_frame_id)
3893 return FindFrameByID(webview()->mainFrame(), it->first);
3894 }
3895 return NULL;
[email protected]0720b532012-08-28 19:23:373896}
3897
[email protected]273558fb2012-01-12 15:03:513898void RenderViewImpl::EnsureMediaStreamImpl() {
[email protected]7082fb942012-05-16 23:44:593899 if (!RenderThreadImpl::current()) // Will be NULL during unit tests.
[email protected]08381562012-05-15 20:55:403900 return;
3901
[email protected]4fb0f202012-05-30 22:44:533902#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:513903 if (!media_stream_dispatcher_)
3904 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3905
[email protected]1bc65a42012-04-23 09:31:253906 if (!media_stream_impl_) {
[email protected]273558fb2012-01-12 15:03:513907 media_stream_impl_ = new MediaStreamImpl(
[email protected]1bc65a42012-04-23 09:31:253908 this,
[email protected]273558fb2012-01-12 15:03:513909 media_stream_dispatcher_,
[email protected]273558fb2012-01-12 15:03:513910 RenderThreadImpl::current()->video_capture_impl_manager(),
[email protected]6ee10bd2012-09-13 09:01:533911 RenderThreadImpl::current()->GetMediaStreamDependencyFactory());
[email protected]273558fb2012-01-12 15:03:513912 }
[email protected]5b87e782012-02-09 18:19:323913#endif
[email protected]273558fb2012-01-12 15:03:513914}
3915
[email protected]310ebd6302011-10-10 19:06:283916void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3917 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313918 if (webview()->mainFrame() != frame)
3919 return;
3920 WebView* frameView = frame->view();
3921 if (!frameView)
3922 return;
3923
3924 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3925 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3926
3927 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3928 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3929 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3930 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3931
3932 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3933 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3934 }
[email protected]198f64122012-11-05 13:09:313935
3936#if defined(OS_ANDROID)
3937 ScheduleUpdateFrameInfo();
3938#endif
[email protected]dd6afca2011-08-13 03:44:313939}
3940
[email protected]310ebd6302011-10-10 19:06:283941void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313942 WebSize offset = frame->scrollOffset();
3943 WebSize minimum_offset = frame->minimumScrollOffset();
3944 WebSize maximum_offset = frame->maximumScrollOffset();
3945
3946 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3947 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3948
3949 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3950 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3951 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3952 routing_id_, is_pinned_to_left, is_pinned_to_right));
3953
3954 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3955 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3956 }
3957}
3958
[email protected]310ebd6302011-10-10 19:06:283959void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493960 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313961
3962 if (webview()->mainFrame() == frame)
3963 UpdateScrollState(frame);
[email protected]2b942c332012-04-25 16:26:263964
3965 FOR_EACH_OBSERVER(
3966 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]198f64122012-11-05 13:09:313967
3968#if defined(OS_ANDROID)
3969 if (webview()->mainFrame() == frame)
3970 ScheduleUpdateFrameInfo();
3971#endif
[email protected]dd6afca2011-08-13 03:44:313972}
3973
[email protected]4d0f8182012-10-19 23:14:473974#if defined(OS_ANDROID)
3975void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebFrame* frame) {
3976 if (frame != webview()->mainFrame())
3977 return;
3978
3979 // Update body background color if necessary.
3980 SkColor bg_color = webwidget_->backgroundColor();
3981
3982 // If not initialized, default to white. Note that 0 is different from black
3983 // as black still has alpha 0xFF.
3984 if (!bg_color)
3985 bg_color = SK_ColorWHITE;
3986
3987 if (bg_color != body_background_color_) {
3988 body_background_color_ = bg_color;
3989 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id_, bg_color));
3990 }
3991}
3992#endif
3993
[email protected]55750b32012-09-21 14:05:033994void RenderViewImpl::SendFindReply(int request_id,
3995 int match_count,
3996 int ordinal,
3997 const WebRect& selection_rect,
3998 bool final_status_update) {
3999#if defined(OS_ANDROID)
4000 if (synchronous_find_reply_message_.get()) {
4001 if (final_status_update) {
4002 ViewMsg_SynchronousFind::WriteReplyParams(
4003 synchronous_find_reply_message_.get(),
4004 match_count,
4005 match_count ? synchronous_find_active_match_ordinal_ : 0);
4006 Send(synchronous_find_reply_message_.release());
4007 }
4008 return;
4009 }
4010#endif
4011
4012 Send(new ViewHostMsg_Find_Reply(routing_id_,
4013 request_id,
4014 match_count,
4015 selection_rect,
4016 ordinal,
4017 final_status_update));
4018}
4019
4020void RenderViewImpl::reportFindInPageMatchCount(int request_id,
4021 int count,
[email protected]310ebd6302011-10-10 19:06:284022 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:114023 int active_match_ordinal = -1; // -1 = don't update active match ordinal
4024 if (!count)
4025 active_match_ordinal = 0;
4026
[email protected]55750b32012-09-21 14:05:034027 // Send the search result over to the browser process.
4028 SendFindReply(request_id,
4029 count,
4030 active_match_ordinal,
4031 gfx::Rect(),
4032 final_update);
[email protected]8922e1f2009-10-03 05:01:264033}
4034
[email protected]310ebd6302011-10-10 19:06:284035void RenderViewImpl::reportFindInPageSelection(int request_id,
4036 int active_match_ordinal,
4037 const WebRect& selection_rect) {
[email protected]55750b32012-09-21 14:05:034038#if defined(OS_ANDROID)
4039 // If this was a SynchronousFind request, we need to remember the ordinal
4040 // value here for replying when reportFindInPageMatchCount is called.
4041 if (synchronous_find_reply_message_.get()) {
4042 synchronous_find_active_match_ordinal_ = active_match_ordinal;
4043 return;
4044 }
4045#endif
4046
4047 SendFindReply(request_id,
4048 -1,
4049 active_match_ordinal,
4050 selection_rect,
4051 false);
[email protected]8922e1f2009-10-03 05:01:264052}
4053
[email protected]310ebd6302011-10-10 19:06:284054void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:224055 WebFrame* frame,
4056 WebFileSystem::Type type,
4057 long long size,
[email protected]d275d7a2010-11-03 01:34:494058 bool create,
[email protected]2b06a992010-08-21 05:48:224059 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:084060 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:224061
[email protected]b6cb3a842011-06-24 18:28:414062 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564063 if (origin.isUnique()) {
4064 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:084065 callbacks->didFail(WebKit::WebFileErrorAbort);
4066 return;
4067 }
[email protected]2b06a992010-08-21 05:48:224068
[email protected]c5a272d2010-09-27 18:37:084069 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
4070 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:494071 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:224072}
4073
[email protected]d5e08552012-08-02 21:43:404074void RenderViewImpl::deleteFileSystem(
4075 WebFrame* frame,
4076 WebFileSystem::Type type ,
4077 WebFileSystemCallbacks* callbacks) {
4078 DCHECK(callbacks);
4079
4080 WebSecurityOrigin origin = frame->document().securityOrigin();
4081 if (origin.isUnique()) {
4082 // Unique origins cannot store persistent state.
4083 callbacks->didSucceed();
4084 return;
4085 }
4086
4087 ChildThread::current()->file_system_dispatcher()->DeleteFileSystem(
4088 GURL(origin.toString()),
4089 static_cast<fileapi::FileSystemType>(type),
4090 new WebFileSystemCallbackDispatcher(callbacks));
4091}
4092
[email protected]310ebd6302011-10-10 19:06:284093void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:404094 WebFrame* frame,
4095 WebStorageQuotaType type,
4096 WebStorageQuotaCallbacks* callbacks) {
4097 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:414098 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564099 if (origin.isUnique()) {
4100 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:404101 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
4102 return;
4103 }
4104 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:534105 GURL(origin.toString()),
4106 static_cast<quota::StorageType>(type),
4107 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:404108}
4109
[email protected]310ebd6302011-10-10 19:06:284110void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:404111 WebFrame* frame,
4112 WebStorageQuotaType type,
4113 unsigned long long requested_size,
4114 WebStorageQuotaCallbacks* callbacks) {
4115 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:414116 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564117 if (origin.isUnique()) {
4118 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:404119 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
4120 return;
4121 }
4122 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:534123 routing_id(), GURL(origin.toString()),
4124 static_cast<quota::StorageType>(type), requested_size,
4125 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:404126}
4127
[email protected]8b5af492011-11-28 21:50:584128void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:154129 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]3a3b75a2012-06-01 08:38:364130 webkit_glue::WebIntentServiceData data(service);
4131 if (data.title.empty())
4132 data.title = webview()->mainFrame()->document().title();
4133 bool user_gesture = frame->isProcessingUserGesture();
[email protected]8b5af492011-11-28 21:50:584134 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
[email protected]3a3b75a2012-06-01 08:38:364135 data,
4136 user_gesture));
[email protected]8b5af492011-11-28 21:50:584137}
4138
[email protected]ffc8bed2012-01-21 01:23:154139void RenderViewImpl::dispatchIntent(
4140 WebFrame* frame, const WebIntentRequest& intentRequest) {
4141 webkit_glue::WebIntentData intent_data(intentRequest.intent());
[email protected]4e1eb3392012-05-18 00:08:054142
4143 // See WebMessagePortChannelImpl::postMessage() and ::OnMessagedQueued()
4144 WebKit::WebMessagePortChannelArray* channels =
4145 intentRequest.intent().messagePortChannelsRelease();
4146 if (channels) {
4147 for (size_t i = 0; i < channels->size(); ++i) {
4148 WebMessagePortChannelImpl* webchannel =
4149 static_cast<WebMessagePortChannelImpl*>((*channels)[i]);
4150 intent_data.message_port_ids.push_back(webchannel->message_port_id());
4151 DCHECK(intent_data.message_port_ids[i] != MSG_ROUTING_NONE);
4152 }
4153 delete channels;
4154 }
4155
[email protected]ffc8bed2012-01-21 01:23:154156 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:584157 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:154158 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:584159}
4160
[email protected]f546640b2012-05-15 00:03:494161bool RenderViewImpl::willCheckAndDispatchMessageEvent(
[email protected]0720b532012-08-28 19:23:374162 WebKit::WebFrame* sourceFrame,
4163 WebKit::WebFrame* targetFrame,
[email protected]f546640b2012-05-15 00:03:494164 WebKit::WebSecurityOrigin target_origin,
4165 WebKit::WebDOMMessageEvent event) {
4166 if (!is_swapped_out_)
4167 return false;
4168
4169 ViewMsg_PostMessage_Params params;
4170 params.data = event.data().toString();
4171 params.source_origin = event.origin();
4172 if (!target_origin.isNull())
4173 params.target_origin = target_origin.toString();
4174
4175 // Include the routing ID for the source frame, which the browser process
4176 // will translate into the routing ID for the equivalent frame in the target
4177 // process.
[email protected]f546640b2012-05-15 00:03:494178 params.source_routing_id = MSG_ROUTING_NONE;
[email protected]0720b532012-08-28 19:23:374179 RenderViewImpl* source_view = FromWebView(sourceFrame->view());
[email protected]f546640b2012-05-15 00:03:494180 if (source_view)
4181 params.source_routing_id = source_view->routing_id();
[email protected]0720b532012-08-28 19:23:374182 params.source_frame_id = sourceFrame->identifier();
4183
4184 // Include the process, route, and frame IDs of the target frame. This allows
4185 // the browser to detect races between this message being sent and the target
4186 // frame no longer being valid.
4187 params.target_process_id = target_process_id_;
4188 params.target_routing_id = target_routing_id_;
4189
4190 std::map<int,int>::iterator it = active_frame_id_map_.find(
4191 targetFrame->identifier());
4192 if (it != active_frame_id_map_.end()) {
4193 params.target_frame_id = it->second;
4194 } else {
4195 params.target_frame_id = 0;
4196 }
[email protected]f546640b2012-05-15 00:03:494197
4198 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params));
4199 return true;
4200}
4201
[email protected]5fa3a062012-03-21 15:39:344202void RenderViewImpl::willOpenSocketStream(
4203 WebSocketStreamHandle* handle) {
4204 SocketStreamHandleData::AddToHandle(handle, routing_id_);
4205}
4206
[email protected]ccee4862012-10-03 18:34:264207void RenderViewImpl::willStartUsingPeerConnectionHandler(
4208 WebKit::WebFrame* frame, WebKit::WebRTCPeerConnectionHandler* handler) {
4209#if defined(ENABLE_WEBRTC)
4210 static_cast<RTCPeerConnectionHandler*>(handler)->associateWithFrame(frame);
4211#endif
4212}
4213
[email protected]bf70edce2012-06-20 22:32:224214WebKit::WebString RenderViewImpl::userAgentOverride(
4215 WebKit::WebFrame* frame,
4216 const WebKit::WebURL& url) {
4217 if (!webview() || !webview()->mainFrame() ||
4218 renderer_preferences_.user_agent_override.empty()) {
4219 return WebKit::WebString();
4220 }
4221
4222 // If we're in the middle of committing a load, the data source we need
4223 // will still be provisional.
4224 WebFrame* main_frame = webview()->mainFrame();
4225 WebDataSource* data_source = NULL;
4226 if (main_frame->provisionalDataSource())
4227 data_source = main_frame->provisionalDataSource();
4228 else
4229 data_source = main_frame->dataSource();
4230
4231 DocumentState* document_state =
4232 data_source ? DocumentState::FromDataSource(data_source) : NULL;
4233 if (document_state && document_state->is_overriding_user_agent())
4234 return WebString::fromUTF8(renderer_preferences_.user_agent_override);
4235 else
4236 return WebKit::WebString();
4237}
4238
[email protected]18d5be92011-07-25 18:00:194239// WebKit::WebPageSerializerClient implementation ------------------------------
4240
[email protected]310ebd6302011-10-10 19:06:284241void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:194242 const WebURL& frame_url,
4243 const WebCString& data,
4244 WebPageSerializerClient::PageSerializationStatus status) {
4245 Send(new ViewHostMsg_SendSerializedHtmlData(
4246 routing_id(),
4247 frame_url,
4248 data.data(),
4249 static_cast<int32>(status)));
4250}
4251
[email protected]e9ff79c2012-10-19 21:31:264252// RenderView implementation ---------------------------------------------------
[email protected]a2ef54c2011-10-10 16:20:314253
[email protected]310ebd6302011-10-10 19:06:284254bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:314255 return RenderWidget::Send(message);
4256}
4257
[email protected]82114f52012-03-20 22:53:414258int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:314259 return routing_id_;
4260}
4261
[email protected]82114f52012-03-20 22:53:414262int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:314263 return page_id_;
4264}
4265
[email protected]82114f52012-03-20 22:53:414266gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:314267 return size();
4268}
4269
[email protected]82114f52012-03-20 22:53:414270WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:314271 return webkit_preferences_;
4272}
4273
[email protected]82114f52012-03-20 22:53:414274WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:314275 return webview();
4276}
4277
[email protected]82114f52012-03-20 22:53:414278WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:314279 if (!webview())
4280 return WebNode();
4281 WebFrame* focused_frame = webview()->focusedFrame();
4282 if (focused_frame) {
4283 WebDocument doc = focused_frame->document();
4284 if (!doc.isNull())
4285 return doc.focusedNode();
4286 }
4287
4288 return WebNode();
4289}
4290
[email protected]82114f52012-03-20 22:53:414291WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:314292 return context_menu_node_;
4293}
4294
[email protected]2a84f9d2012-06-05 21:50:434295bool RenderViewImpl::IsEditableNode(const WebNode& node) const {
4296 if (node.isNull())
4297 return false;
4298
4299 if (node.isContentEditable())
4300 return true;
4301
4302 if (node.isElementNode()) {
4303 const WebElement& element = node.toConst<WebElement>();
4304 if (element.isTextFormControlElement())
4305 return true;
4306
4307 // Also return true if it has an ARIA role of 'textbox'.
4308 for (unsigned i = 0; i < element.attributeCount(); ++i) {
4309 if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) {
4310 if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox"))
4311 return true;
4312 break;
4313 }
[email protected]a2ef54c2011-10-10 16:20:314314 }
4315 }
[email protected]2a84f9d2012-06-05 21:50:434316
4317 return false;
[email protected]a2ef54c2011-10-10 16:20:314318}
4319
[email protected]310ebd6302011-10-10 19:06:284320WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:314321 WebKit::WebFrame* frame,
4322 const webkit::WebPluginInfo& info,
[email protected]82114f52012-03-20 22:53:414323 const WebKit::WebPluginParams& params) {
[email protected]a2ef54c2011-10-10 16:20:314324 bool pepper_plugin_was_registered = false;
4325 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
4326 pepper_delegate_.CreatePepperPluginModule(info,
4327 &pepper_plugin_was_registered));
4328 if (pepper_plugin_was_registered) {
4329 if (!pepper_module)
4330 return NULL;
4331 return new webkit::ppapi::WebPluginImpl(
4332 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
4333 }
4334
[email protected]3e076a82012-09-11 19:12:364335#if defined(USE_AURA) && !defined(OS_WIN)
[email protected]34b27e442012-01-20 20:07:414336 return NULL;
4337#else
[email protected]a2ef54c2011-10-10 16:20:314338 return new webkit::npapi::WebPluginImpl(
4339 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:414340#endif
[email protected]a2ef54c2011-10-10 16:20:314341}
4342
[email protected]310ebd6302011-10-10 19:06:284343void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
4344 const string16& jscript,
4345 int id,
4346 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:314347 v8::Handle<v8::Value> result;
4348 WebFrame* web_frame = GetChildFrame(frame_xpath);
4349 if (web_frame)
4350 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
4351 if (notify_result) {
4352 ListValue list;
4353 if (!result.IsEmpty() && web_frame) {
4354 v8::HandleScope handle_scope;
4355 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4356 v8::Context::Scope context_scope(context);
4357 V8ValueConverterImpl converter;
[email protected]3de391e82012-05-16 17:50:514358 converter.SetDateAllowed(true);
[email protected]e0658bc2012-09-17 04:05:244359 converter.SetRegExpAllowed(true);
4360 base::Value* result_value = converter.FromV8Value(result, context);
4361 list.Set(0, result_value ? result_value :
4362 base::Value::CreateNullValue());
[email protected]a2ef54c2011-10-10 16:20:314363 } else {
4364 list.Set(0, Value::CreateNullValue());
4365 }
4366 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
4367 }
4368}
4369
[email protected]310ebd6302011-10-10 19:06:284370bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:314371 return (!send_preferred_size_changes_ ||
4372 (disable_scrollbars_size_limit_.width() <= width ||
4373 disable_scrollbars_size_limit_.height() <= height));
4374}
4375
[email protected]82114f52012-03-20 22:53:414376int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:314377 return enabled_bindings_;
4378}
4379
[email protected]82114f52012-03-20 22:53:414380bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:314381 return send_content_state_immediately_;
4382}
4383
[email protected]82114f52012-03-20 22:53:414384float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:314385 return filtered_time_per_frame();
4386}
4387
[email protected]e9ff79c2012-10-19 21:31:264388int RenderViewImpl::ShowContextMenu(ContextMenuClient* client,
4389 const ContextMenuParams& params) {
[email protected]860ee642012-10-13 03:46:254390 DCHECK(client); // A null client means "internal" when we issue callbacks.
[email protected]e9ff79c2012-10-19 21:31:264391 ContextMenuParams our_params(params);
[email protected]860ee642012-10-13 03:46:254392 our_params.custom_context.request_id = pending_context_menus_.Add(client);
4393 Send(new ViewHostMsg_ContextMenu(routing_id_, our_params));
4394 return our_params.custom_context.request_id;
[email protected]a2ef54c2011-10-10 16:20:314395}
4396
[email protected]e0fd0eb2012-10-17 21:11:464397void RenderViewImpl::CancelContextMenu(int request_id) {
4398 DCHECK(pending_context_menus_.Lookup(request_id));
4399 pending_context_menus_.Remove(request_id);
4400}
4401
[email protected]82114f52012-03-20 22:53:414402WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:314403 return visibilityState();
4404}
4405
[email protected]310ebd6302011-10-10 19:06:284406void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
4407 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:314408 return runModalAlertDialog(frame, message);
4409}
4410
[email protected]310ebd6302011-10-10 19:06:284411void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:314412 WebKit::WebFrame* frame,
4413 const WebKit::WebURLRequest& request,
4414 WebKit::WebNavigationPolicy policy) {
4415 loadURLExternally(frame, request, policy);
4416}
4417
4418// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:514419
[email protected]310ebd6302011-10-10 19:06:284420webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:534421 const FilePath& file_path,
4422 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:204423 if (!PluginChannelHost::IsListening()) {
4424 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:594425 return NULL;
[email protected]94752ee2012-02-10 10:38:204426 }
[email protected]f103ab72009-09-02 17:10:594427
[email protected]00c39612010-03-06 02:53:284428 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:464429 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:324430#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]3b21be92012-11-02 06:00:024431 return webkit::npapi::WebPluginDelegateImpl::Create(file_path, mime_type);
[email protected]6876dff2010-01-15 19:38:094432#else
[email protected]7398dcc2011-09-06 21:40:324433 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:224434 NOTIMPLEMENTED();
4435 return NULL;
[email protected]7b6616f2010-01-14 18:07:554436#endif
[email protected]f103ab72009-09-02 17:10:594437 }
4438
[email protected]4e0616e2010-05-28 14:55:534439 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:594440}
4441
[email protected]6ac77cb2012-05-01 14:49:014442WebKit::WebPlugin* RenderViewImpl::CreatePluginReplacement(
4443 const FilePath& file_path) {
[email protected]e9ff79c2012-10-19 21:31:264444 return GetContentClient()->renderer()->CreatePluginReplacement(
[email protected]6ac77cb2012-05-01 14:49:014445 this, file_path);
4446}
4447
[email protected]310ebd6302011-10-10 19:06:284448void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034449#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:274450 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:594451#endif
4452}
4453
[email protected]310ebd6302011-10-10 19:06:284454void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034455#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:274456 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:594457#endif
4458 CleanupWindowInPluginMoves(window);
4459}
4460
[email protected]310ebd6302011-10-10 19:06:284461void RenderViewImpl::DidMovePlugin(
4462 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:594463 SchedulePluginMove(move);
4464}
4465
[email protected]310ebd6302011-10-10 19:06:284466void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:594467 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524468 didStartLoading();
[email protected]f103ab72009-09-02 17:10:594469}
4470
[email protected]310ebd6302011-10-10 19:06:284471void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:594472 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524473 didStopLoading();
[email protected]f103ab72009-09-02 17:10:594474}
4475
[email protected]310ebd6302011-10-10 19:06:284476WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:514477 return &cookie_jar_;
4478}
4479
[email protected]5d65fe92012-06-02 00:48:554480void RenderViewImpl::DidPlay(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074481 Send(new ViewHostMsg_MediaNotification(routing_id_,
4482 reinterpret_cast<int64>(player),
4483 player->hasVideo(),
4484 player->hasAudio(),
4485 true));
4486}
4487
[email protected]5d65fe92012-06-02 00:48:554488void RenderViewImpl::DidPause(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074489 Send(new ViewHostMsg_MediaNotification(routing_id_,
4490 reinterpret_cast<int64>(player),
4491 player->hasVideo(),
4492 player->hasAudio(),
4493 false));
4494}
4495
[email protected]5d65fe92012-06-02 00:48:554496void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074497 DidPause(player);
4498}
4499
[email protected]310ebd6302011-10-10 19:06:284500void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:294501 if (!webview())
4502 return;
4503
[email protected]26aa0482009-09-30 16:55:274504 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:054505 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:294506}
4507
[email protected]310ebd6302011-10-10 19:06:284508void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:364509 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:004510 if (!frame)
4511 return;
[email protected]b781ff282011-08-20 06:19:364512
[email protected]e99ef6f2011-10-16 01:13:004513 string16 text;
4514 size_t offset;
[email protected]3c8c74c2012-03-15 07:34:524515 ui::Range range;
[email protected]e99ef6f2011-10-16 01:13:004516
[email protected]3c8c74c2012-03-15 07:34:524517 if (pepper_delegate_.IsPluginFocused()) {
4518 pepper_delegate_.GetSurroundingText(&text, &range);
[email protected]82114f52012-03-20 22:53:414519 offset = 0; // Pepper API does not support offset reporting.
[email protected]3c8c74c2012-03-15 07:34:524520 // TODO(kinaba): cut as needed.
[email protected]e99ef6f2011-10-16 01:13:004521 } else {
[email protected]3c8c74c2012-03-15 07:34:524522 size_t location, length;
4523 if (!webview()->caretOrSelectionRange(&location, &length))
4524 return;
4525
4526 range = ui::Range(location, location + length);
4527
4528 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
4529 // If current focused element is editable, we will send 100 more chars
4530 // before and after selection. It is for input method surrounding text
4531 // feature.
4532 if (location > kExtraCharsBeforeAndAfterSelection)
4533 offset = location - kExtraCharsBeforeAndAfterSelection;
4534 else
4535 offset = 0;
4536 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
4537 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
4538 if (!webrange.isNull())
4539 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
4540 } else {
4541 offset = location;
4542 text = frame->selectionAsText();
4543 // http://crbug.com/101435
4544 // In some case, frame->selectionAsText() returned text's length is not
4545 // equal to the length returned from webview()->caretOrSelectionRange().
4546 // So we have to set the range according to text.length().
4547 range.set_end(range.start() + text.length());
4548 }
[email protected]b781ff282011-08-20 06:19:364549 }
4550
[email protected]b781ff282011-08-20 06:19:364551 // Sometimes we get repeated didChangeSelection calls from webkit when
4552 // the selection hasn't actually changed. We don't want to report these
4553 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:004554 if (selection_text_offset_ != offset ||
4555 selection_range_ != range ||
4556 selection_text_ != text) {
4557 selection_text_ = text;
4558 selection_text_offset_ = offset;
4559 selection_range_ = range;
4560 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
4561 }
[email protected]b781ff282011-08-20 06:19:364562}
4563
[email protected]310ebd6302011-10-10 19:06:284564GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
4565 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554566 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294567 // If the URL that failed was secure, then the embedding web page was not
4568 // expecting a network attacker to be able to manipulate its contents. As
4569 // we fetch alternate error pages over HTTP, we would be allowing a network
4570 // attacker to manipulate the contents of the response if we tried to use
4571 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154572 return GURL();
initial.commit09911bf2008-07-26 23:55:294573 }
4574
4575 // Grab the base URL from the browser process.
4576 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154577 return GURL();
initial.commit09911bf2008-07-26 23:55:294578
4579 // Strip query params from the failed URL.
4580 GURL::Replacements remove_params;
4581 remove_params.ClearUsername();
4582 remove_params.ClearPassword();
4583 remove_params.ClearQuery();
4584 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554585 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504586 std::string spec_to_send = url_to_send.spec();
4587 // Notify link doctor of the url truncation by sending of "?" at the end.
4588 if (failed_url.has_query())
[email protected]82114f52012-03-20 22:53:414589 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294590
4591 // Construct the query params to send to link doctor.
4592 std::string params(alternate_error_page_url_.query());
4593 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:024594 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294595 params.append("&sourceid=chrome");
4596 params.append("&error=");
4597 switch (error_type) {
4598 case DNS_ERROR:
4599 params.append("dnserror");
4600 break;
4601
4602 case HTTP_404:
4603 params.append("http404");
4604 break;
4605
[email protected]5df266ac2008-10-15 19:50:134606 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334607 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134608 break;
4609
initial.commit09911bf2008-07-26 23:55:294610 default:
4611 NOTREACHED() << "unknown ErrorPageType";
4612 }
4613
4614 // OK, build the final url to return.
4615 GURL::Replacements link_doctor_params;
4616 link_doctor_params.SetQueryStr(params);
4617 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4618 return url;
4619}
4620
[email protected]310ebd6302011-10-10 19:06:284621GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:594622 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
4623 return GURL();
4624 else
4625 return creator_url_;
4626}
4627
[email protected]69ddf852012-02-21 23:21:314628GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
4629 WebDataSource* ds = frame->dataSource();
4630 if (ds->hasUnreachableURL())
4631 return ds->unreachableURL();
4632
4633 const WebURLRequest& request = ds->request();
4634 return request.url();
4635}
4636
[email protected]310ebd6302011-10-10 19:06:284637WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:274638 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:314639 web_ui_bindings_.reset(new WebUIBindings(
[email protected]e9ff79c2012-10-19 21:31:264640 static_cast<RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:464641 }
[email protected]c50008512011-02-03 01:17:274642 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:464643}
4644
[email protected]310ebd6302011-10-10 19:06:284645WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:014646 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494647}
4648
[email protected]55750b32012-09-21 14:05:034649void RenderViewImpl::OnFind(int request_id,
4650 const string16& search_text,
[email protected]310ebd6302011-10-10 19:06:284651 const WebFindOptions& options) {
[email protected]55750b32012-09-21 14:05:034652#if defined(OS_ANDROID)
4653 // Make sure any asynchronous messages do not disrupt an ongoing synchronous
4654 // find request as it might lead to deadlocks. Also, these should be safe to
4655 // ignore since they would belong to a previous find request.
4656 if (synchronous_find_reply_message_.get())
4657 return;
4658#endif
4659 Find(request_id, search_text, options);
4660}
4661
4662void RenderViewImpl::Find(int request_id,
4663 const string16& search_text,
4664 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274665 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494666
[email protected]872542532011-06-23 00:43:164667 // Check if the plugin still exists in the document.
4668 if (main_frame->document().isPluginDocument() &&
4669 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494670 if (options.findNext) {
4671 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014672 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494673 } else {
[email protected]55750b32012-09-21 14:05:034674 if (!GetWebPluginFromPluginDocument()->startFind(
[email protected]afdbd142010-07-10 08:01:234675 search_text, options.matchCase, request_id)) {
[email protected]e7c58a32010-08-13 19:47:114676 // Send "no results".
[email protected]55750b32012-09-21 14:05:034677 SendFindReply(request_id, 0, 0, gfx::Rect(), true);
[email protected]24a7f3c2010-03-25 08:26:494678 }
4679 }
4680 return;
4681 }
4682
[email protected]b4bb2502009-10-01 22:35:274683 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274684 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294685 WebFrame* search_frame = focused_frame; // start searching focused frame.
4686
4687 bool multi_frame = (frame_after_main != main_frame);
4688
4689 // If we have multiple frames, we don't want to wrap the search within the
4690 // frame, so we check here if we only have main_frame in the chain.
4691 bool wrap_within_frame = !multi_frame;
4692
[email protected]b3f2b912009-04-09 16:18:524693 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294694 bool result = false;
4695
[email protected]7830da3e2009-11-06 16:27:264696 // If something is selected when we start searching it means we cannot just
4697 // increment the current match ordinal; we need to re-generate it.
4698 WebRange current_selection = focused_frame->selectionRange();
4699
initial.commit09911bf2008-07-26 23:55:294700 do {
[email protected]dd7daa82009-08-10 05:46:454701 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594702 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294703
4704 if (!result) {
4705 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:224706 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294707
4708 // Find the next frame, but skip the invisible ones.
4709 do {
4710 // What is the next frame to search? (we might be going backwards). Note
4711 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594712 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274713 search_frame->traverseNext(true) :
4714 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454715 } while (!search_frame->hasVisibleContent() &&
4716 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294717
[email protected]884db412008-11-24 23:46:504718 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:224719 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294720
4721 // If we have multiple frames and we have wrapped back around to the
4722 // focused frame, we need to search it once more allowing wrap within
4723 // the frame, otherwise it will report 'no match' if the focused frame has
4724 // reported matches, but no frames after the focused_frame contain a
4725 // match for the search word(s).
4726 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454727 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594728 request_id, search_text, options, true, // Force wrapping.
4729 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294730 }
4731 }
4732
[email protected]26aa0482009-09-30 16:55:274733 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294734 } while (!result && search_frame != focused_frame);
4735
[email protected]7830da3e2009-11-06 16:27:264736 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294737 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454738 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294739 } else {
4740 // If nothing is found, set result to "0 of 0", otherwise, set it to
4741 // "-1 of 1" to indicate that we found at least one item, but we don't know
4742 // yet what is active.
4743 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4744 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294745
[email protected]4f3dc372009-02-24 00:10:294746 // If we find no matches then this will be our last status update.
4747 // Otherwise the scoping effort will send more results.
4748 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294749
[email protected]55750b32012-09-21 14:05:034750 SendFindReply(request_id, match_count, ordinal, selection_rect,
4751 final_status_update);
initial.commit09911bf2008-07-26 23:55:294752
initial.commit09911bf2008-07-26 23:55:294753 // Scoping effort begins, starting with the mainframe.
4754 search_frame = main_frame;
4755
[email protected]dd7daa82009-08-10 05:46:454756 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294757
4758 do {
4759 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454760 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294761
4762 // We don't start another scoping effort unless at least one match has
4763 // been found.
4764 if (result) {
4765 // Start new scoping request. If the scoping function determines that it
4766 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454767 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594768 search_text,
4769 options,
initial.commit09911bf2008-07-26 23:55:294770 true); // reset the tickmarks
4771 }
4772
4773 // Iterate to the next frame. The frame will not necessarily scope, for
4774 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274775 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294776 } while (search_frame != main_frame);
4777 }
4778}
4779
[email protected]e9ff79c2012-10-19 21:31:264780void RenderViewImpl::OnStopFinding(StopFindAction action) {
[email protected]55750b32012-09-21 14:05:034781#if defined(OS_ANDROID)
4782 // Make sure any asynchronous messages do not disrupt an ongoing synchronous
4783 // find request as it might lead to deadlocks. Also, these should be safe to
4784 // ignore since they would belong to a previous find request.
4785 if (synchronous_find_reply_message_.get())
4786 return;
4787#endif
4788
4789 StopFinding(action);
4790}
4791
[email protected]e9ff79c2012-10-19 21:31:264792void RenderViewImpl::StopFinding(StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:494793 WebView* view = webview();
4794 if (!view)
4795 return;
4796
4797 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:164798 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014799 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494800 return;
4801 }
4802
[email protected]e9ff79c2012-10-19 21:31:264803 bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:494804 if (clear_selection)
4805 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4806
4807 WebFrame* frame = view->mainFrame();
4808 while (frame) {
4809 frame->stopFinding(clear_selection);
4810 frame = frame->traverseNext(false);
4811 }
4812
[email protected]e9ff79c2012-10-19 21:31:264813 if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:494814 WebFrame* focused_frame = view->focusedFrame();
4815 if (focused_frame) {
4816 WebDocument doc = focused_frame->document();
4817 if (!doc.isNull()) {
4818 WebNode node = doc.focusedNode();
4819 if (!node.isNull())
4820 node.simulateClick();
4821 }
4822 }
4823 }
4824}
4825
[email protected]59363fc92012-09-05 03:46:314826#if defined(OS_ANDROID)
[email protected]55750b32012-09-21 14:05:034827void RenderViewImpl::OnSynchronousFind(int request_id,
4828 const string16& search_string,
4829 const WebFindOptions& options,
4830 IPC::Message* reply_msg) {
4831 // It is impossible for simultaneous blocking finds to occur.
4832 CHECK(!synchronous_find_reply_message_.get());
4833 synchronous_find_reply_message_.reset(reply_msg);
4834
4835 // Find next should be asynchronous in order to minimize blocking
4836 // the UI thread as much as possible.
4837 DCHECK(!options.findNext);
[email protected]e9ff79c2012-10-19 21:31:264838 StopFinding(STOP_FIND_ACTION_KEEP_SELECTION);
[email protected]55750b32012-09-21 14:05:034839 synchronous_find_active_match_ordinal_ = -1;
4840
4841 Find(request_id, search_string, options);
4842}
4843
[email protected]59363fc92012-09-05 03:46:314844void RenderViewImpl::OnActivateNearestFindResult(int request_id,
4845 float x, float y) {
4846 if (!webview())
4847 return;
4848
4849 WebFrame* main_frame = webview()->mainFrame();
4850 WebRect selection_rect;
4851 int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y),
4852 &selection_rect);
4853 if (ordinal == -1) {
4854 // Something went wrong, so send a no-op reply (force the main_frame to
4855 // report the current match count) in case the host is waiting for a
4856 // response due to rate-limiting).
4857 main_frame->increaseMatchCount(0, request_id);
4858 return;
4859 }
4860
[email protected]55750b32012-09-21 14:05:034861 SendFindReply(request_id,
4862 -1 /* number_of_matches */,
4863 ordinal,
4864 selection_rect,
4865 true /* final_update */);
[email protected]59363fc92012-09-05 03:46:314866}
4867
4868void RenderViewImpl::OnFindMatchRects(int current_version) {
4869 if (!webview())
4870 return;
4871
4872 WebFrame* main_frame = webview()->mainFrame();
4873 std::vector<gfx::RectF> match_rects;
4874
4875 int rects_version = main_frame->findMatchMarkersVersion();
4876 if (current_version != rects_version) {
4877 WebVector<WebFloatRect> web_match_rects;
4878 main_frame->findMatchRects(web_match_rects);
4879 match_rects.reserve(web_match_rects.size());
4880 for (size_t i = 0; i < web_match_rects.size(); ++i)
4881 match_rects.push_back(gfx::RectF(web_match_rects[i]));
4882 }
4883
4884 gfx::RectF active_rect = main_frame->activeFindMatchRect();
4885 Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_,
4886 rects_version,
4887 match_rects,
4888 active_rect));
4889}
4890#endif
4891
[email protected]e9ff79c2012-10-19 21:31:264892void RenderViewImpl::OnZoom(PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:514893 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4894 return;
4895
[email protected]258d31122010-05-09 10:59:414896 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:104897
[email protected]b75b8292010-10-01 07:28:254898 double old_zoom_level = webview()->zoomLevel();
4899 double zoom_level;
[email protected]e9ff79c2012-10-19 21:31:264900 if (zoom == PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:254901 zoom_level = 0;
4902 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4903 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:484904 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:254905 } else {
4906 // Either the user hit the zoom factor limit and thus the zoom level is now
4907 // not a whole number, or a plugin changed it to a custom value. We want
4908 // to go to the next whole number so that the user can always get back to
4909 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:484910 if ((old_zoom_level > 1 && zoom > 0) ||
4911 (old_zoom_level < 1 && zoom < 0)) {
4912 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:254913 } else {
4914 // We're going towards 100%, so first go to the next whole number.
4915 zoom_level = static_cast<int>(old_zoom_level);
4916 }
4917 }
[email protected]b75b8292010-10-01 07:28:254918 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:414919 zoomLevelChanged();
4920}
4921
[email protected]e9ff79c2012-10-19 21:31:264922void RenderViewImpl::OnZoomFactor(PageZoom zoom, int zoom_center_x,
4923 int zoom_center_y) {
[email protected]47578fa02011-11-02 19:34:414924 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
4925 kScalingIncrementForGesture);
4926}
4927
[email protected]e9ff79c2012-10-19 21:31:264928void RenderViewImpl::ZoomFactorHelper(PageZoom zoom,
[email protected]47578fa02011-11-02 19:34:414929 int zoom_center_x,
4930 int zoom_center_y,
4931 float scaling_increment) {
4932 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4933 return;
4934
[email protected]c514d6372011-08-16 22:54:444935 double old_page_scale_factor = webview()->pageScaleFactor();
4936 double page_scale_factor;
[email protected]e9ff79c2012-10-19 21:31:264937 if (zoom == PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:444938 page_scale_factor = 1.0;
4939 } else {
4940 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:414941 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:444942 }
[email protected]47578fa02011-11-02 19:34:414943 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:094944 webview()->setPageScaleFactor(page_scale_factor,
4945 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:414946 }
[email protected]40bd6582009-12-04 23:49:514947}
4948
[email protected]310ebd6302011-10-10 19:06:284949void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174950 webview()->hidePopups();
4951 webview()->setZoomLevel(false, zoom_level);
4952 zoomLevelChanged();
4953}
4954
[email protected]310ebd6302011-10-10 19:06:284955void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4956 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544957 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294958}
4959
[email protected]310ebd6302011-10-10 19:06:284960void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274961 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294962}
4963
[email protected]310ebd6302011-10-10 19:06:284964void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274965 WebString no_encoding;
4966 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184967}
4968
[email protected]310ebd6302011-10-10 19:06:284969WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454970 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274971 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454972
4973 // xpath string can represent a frame deep down the tree (across multiple
4974 // frame DOMs).
4975 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4976 // should break into 2 xpaths
4977 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:414978 std::vector<string16> xpaths;
4979 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:454980
[email protected]26aa0482009-09-30 16:55:274981 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:414982 for (std::vector<string16>::const_iterator i = xpaths.begin();
4983 frame && i != xpaths.end(); ++i) {
4984 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294985 }
4986
[email protected]dd7daa82009-08-10 05:46:454987 return frame;
initial.commit09911bf2008-07-26 23:55:294988}
4989
[email protected]310ebd6302011-10-10 19:06:284990void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4991 const string16& jscript,
4992 int id,
4993 bool notify_result) {
[email protected]01d43ef92012-09-25 00:54:104994 TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest");
[email protected]882b7b22010-10-05 03:34:534995 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294996}
4997
[email protected]f546640b2012-05-15 00:03:494998void RenderViewImpl::OnPostMessageEvent(
4999 const ViewMsg_PostMessage_Params& params) {
[email protected]0720b532012-08-28 19:23:375000 // Find the target frame of this message. The source tags the message with
5001 // |target_frame_id|, so use it to locate the frame.
[email protected]e12dbe6f2012-10-04 22:11:195002 // TODO(nasko): Lookup based on the frame id, once http://crbug.com/153701
5003 // is fixed and we can rely on having frame tree updates again.
5004 WebFrame* frame = webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:495005
5006 // Find the source frame if it exists.
[email protected]f546640b2012-05-15 00:03:495007 WebFrame* source_frame = NULL;
5008 if (params.source_routing_id != MSG_ROUTING_NONE) {
5009 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
[email protected]e12dbe6f2012-10-04 22:11:195010 // TODO(nasko): Lookup based on the frame id, once http://crbug.com/153701
5011 // is fixed and we can rely on having frame tree updates again.
[email protected]f546640b2012-05-15 00:03:495012 if (source_view)
[email protected]e12dbe6f2012-10-04 22:11:195013 source_frame = source_view->webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:495014 }
5015
5016 // Create an event with the message. The final parameter to initMessageEvent
5017 // is the last event ID, which is not used with postMessage.
5018 WebDOMEvent event = frame->document().createEvent("MessageEvent");
5019 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
5020 msg_event.initMessageEvent("message",
5021 // |canBubble| and |cancellable| are always false
5022 false, false,
5023 WebSerializedScriptValue::fromString(params.data),
5024 params.source_origin, source_frame, "");
5025
5026 // We must pass in the target_origin to do the security check on this side,
5027 // since it may have changed since the original postMessage call was made.
5028 WebSecurityOrigin target_origin;
5029 if (!params.target_origin.empty()) {
5030 target_origin =
5031 WebSecurityOrigin::createFromString(WebString(params.target_origin));
5032 }
5033 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
5034}
5035
[email protected]310ebd6302011-10-10 19:06:285036void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
5037 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:415038 WebFrame* frame = GetChildFrame(frame_xpath);
5039 if (!frame)
[email protected]216813952011-05-19 22:21:265040 return;
[email protected]ae461542009-06-19 19:03:415041
[email protected]01cf589c2011-07-28 18:04:035042 frame->document().insertUserStyleSheet(
5043 WebString::fromUTF8(css),
5044 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:485045}
5046
[email protected]310ebd6302011-10-10 19:06:285047void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:095048 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:045049
5050 // Keep track of the total bindings accumulated in this process.
5051 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:295052}
5053
[email protected]310ebd6302011-10-10 19:06:285054void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
5055 const std::string& value) {
[email protected]e9ff79c2012-10-19 21:31:265056 if (enabled_bindings_ & BINDINGS_POLICY_WEB_UI)
[email protected]808bda52012-03-09 22:43:325057 GetWebUIBindings()->SetProperty(name, value);
5058 else
5059 NOTREACHED() << "WebUI bindings not enabled.";
initial.commit09911bf2008-07-26 23:55:295060}
5061
[email protected]310ebd6302011-10-10 19:06:285062void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
5063 const gfx::Point& client_point,
5064 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:425065 WebDragOperationsMask ops,
5066 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:555067 WebDragOperation operation = webview()->dragTargetDragEnter(
5068 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:555069 client_point,
5070 screen_point,
[email protected]1f2230b2012-05-17 23:43:425071 ops,
5072 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555073
5074 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5075}
5076
[email protected]310ebd6302011-10-10 19:06:285077void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
5078 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:425079 WebDragOperationsMask ops,
5080 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:555081 WebDragOperation operation = webview()->dragTargetDragOver(
5082 client_point,
5083 screen_point,
[email protected]1f2230b2012-05-17 23:43:425084 ops,
5085 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555086
5087 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5088}
5089
[email protected]310ebd6302011-10-10 19:06:285090void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:555091 webview()->dragTargetDragLeave();
5092}
5093
[email protected]310ebd6302011-10-10 19:06:285094void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
[email protected]1f2230b2012-05-17 23:43:425095 const gfx::Point& screen_point,
5096 int key_modifiers) {
5097 webview()->dragTargetDrop(client_point, screen_point, key_modifiers);
[email protected]fcad49452011-06-28 17:11:575098
5099 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:555100}
5101
[email protected]310ebd6302011-10-10 19:06:285102void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
5103 const gfx::Point& screen_point,
5104 bool ended,
5105 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:035106 if (ended) {
[email protected]26aa0482009-09-30 16:55:275107 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:205108 } else {
5109 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:035110 }
initial.commit09911bf2008-07-26 23:55:295111}
5112
[email protected]310ebd6302011-10-10 19:06:285113void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:275114 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:295115}
5116
[email protected]310ebd6302011-10-10 19:06:285117void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:595118 webkit_preferences_ = prefs;
5119 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:295120}
5121
[email protected]38761452012-10-18 16:31:595122void RenderViewImpl::OnUpdateTimezone() {
5123 if (webview())
5124 NotifyTimezoneChange(webview()->mainFrame());
5125}
5126
[email protected]310ebd6302011-10-10 19:06:285127void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:295128 alternate_error_page_url_ = url;
5129}
5130
[email protected]310ebd6302011-10-10 19:06:285131void RenderViewImpl::OnCustomContextMenuAction(
[email protected]e9ff79c2012-10-19 21:31:265132 const CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:085133 unsigned action) {
[email protected]860ee642012-10-13 03:46:255134 if (custom_context.request_id) {
5135 // External context menu request, look in our map.
[email protected]e9ff79c2012-10-19 21:31:265136 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:255137 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:465138 if (client)
5139 client->OnMenuAction(custom_context.request_id, action);
[email protected]860ee642012-10-13 03:46:255140 } else {
5141 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:085142 webview()->performCustomContextMenuAction(action);
[email protected]860ee642012-10-13 03:46:255143 }
[email protected]a0c7153e2009-12-09 14:36:335144}
5145
[email protected]310ebd6302011-10-10 19:06:285146void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:515147 int id,
5148 const std::vector<FilePath>& paths) {
5149 if (!enumeration_completions_[id])
5150 return;
5151
5152 WebVector<WebString> ws_file_names(paths.size());
5153 for (size_t i = 0; i < paths.size(); ++i)
[email protected]bb0e79472012-10-23 04:36:345154 ws_file_names[i] = webkit_base::FilePathToWebString(paths[i]);
[email protected]600ea402011-04-12 00:01:515155
5156 enumeration_completions_[id]->didChooseFile(ws_file_names);
5157 enumeration_completions_.erase(id);
5158}
5159
[email protected]fb11b6a42012-03-14 07:25:125160void RenderViewImpl::OnFileChooserResponse(
[email protected]ddb034b2012-06-26 20:31:395161 const std::vector<ui::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:365162 // This could happen if we navigated to a different page before the user
5163 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:475164 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:365165 return;
5166
[email protected]b5188522012-03-15 00:18:045167 // Convert Chrome's SelectedFileInfo list to WebKit's.
5168 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
5169 files.size());
5170 for (size_t i = 0; i < files.size(); ++i) {
5171 WebFileChooserCompletion::SelectedFileInfo selected_file;
[email protected]bb0e79472012-10-23 04:36:345172 selected_file.path = webkit_base::FilePathToWebString(files[i].local_path);
5173 selected_file.displayName = webkit_base::FilePathStringToWebString(
[email protected]b5188522012-03-15 00:18:045174 files[i].display_name);
5175 selected_files[i] = selected_file;
5176 }
[email protected]a1128322009-10-06 18:38:465177
[email protected]cdaf8d02010-03-30 19:52:475178 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:045179 file_chooser_completions_.front()->completion->didChooseFile(
5180 selected_files);
[email protected]cdaf8d02010-03-30 19:52:475181 file_chooser_completions_.pop_front();
5182
5183 // If there are more pending file chooser requests, schedule one now.
5184 if (!file_chooser_completions_.empty()) {
5185 Send(new ViewHostMsg_RunFileChooser(routing_id_,
5186 file_chooser_completions_.front()->params));
5187 }
initial.commit09911bf2008-07-26 23:55:295188}
5189
[email protected]244ac1892011-12-02 17:04:475190void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
5191 const gfx::Size& max_size) {
5192 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5193 if (!webview())
5194 return;
[email protected]61e2b3cc2012-03-02 16:13:345195 webview()->enableAutoResizeMode(min_size, max_size);
5196}
5197
5198void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
5199 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5200 if (!webview())
5201 return;
5202 webview()->disableAutoResizeMode();
5203
5204 Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK);
[email protected]244ac1892011-12-02 17:04:475205}
5206
[email protected]2bf834f2011-11-17 20:02:215207void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:245208 if (send_preferred_size_changes_)
5209 return;
[email protected]9fb325e2010-05-06 18:23:245210 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:395211
[email protected]d812fd12011-05-27 23:05:075212 // Start off with an initial preferred size notification (in case
5213 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:595214 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:085215}
5216
[email protected]310ebd6302011-10-10 19:06:285217void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:105218 const gfx::Size& disable_scrollbar_size_limit) {
5219 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
5220}
5221
[email protected]310ebd6302011-10-10 19:06:285222void RenderViewImpl::OnSetRendererPrefs(
[email protected]e9ff79c2012-10-19 21:31:265223 const RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:505224 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:515225 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:375226 UpdateFontRenderingFromRendererPrefs();
[email protected]a13283cc2012-04-05 00:21:225227#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:415228 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
5229 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:465230 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]f78452f2012-05-15 02:07:525231 ui::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:345232 renderer_prefs.thumb_inactive_color,
5233 renderer_prefs.thumb_active_color,
5234 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:555235#endif
[email protected]93623c5d2009-12-10 21:40:325236
[email protected]a13283cc2012-04-05 00:21:225237#if defined(USE_ASH) || defined(TOOLKIT_GTK)
[email protected]644d77e2010-01-27 01:03:105238 if (webview()) {
[email protected]a13283cc2012-04-05 00:21:225239#if defined(TOOLKIT_GTK)
[email protected]93623c5d2009-12-10 21:40:325240 webview()->setScrollbarColors(
5241 renderer_prefs.thumb_inactive_color,
5242 renderer_prefs.thumb_active_color,
5243 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:555244#endif
[email protected]644d77e2010-01-27 01:03:105245 webview()->setSelectionColors(
5246 renderer_prefs.active_selection_bg_color,
5247 renderer_prefs.active_selection_fg_color,
5248 renderer_prefs.inactive_selection_bg_color,
5249 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:465250 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:105251 }
[email protected]7a74e102009-09-03 00:16:565252#endif
[email protected]d299d972012-03-23 02:26:555253
[email protected]d051d9a2011-12-10 02:02:505254 // If the zoom level for this page matches the old zoom default, and this
5255 // is not a plugin, update the zoom level to match the new default.
5256 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
[email protected]e9ff79c2012-10-19 21:31:265257 ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
[email protected]d051d9a2011-12-10 02:02:505258 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
5259 zoomLevelChanged();
5260 }
[email protected]80d96fa2009-06-10 22:34:515261}
5262
[email protected]310ebd6302011-10-10 19:06:285263void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
5264 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:285265 if (webview())
5266 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:565267}
5268
[email protected]77829642012-05-15 14:47:175269void RenderViewImpl::OnOrientationChangeEvent(int orientation) {
5270 webview()->mainFrame()->sendOrientationChangeEvent(orientation);
5271}
5272
[email protected]81375e872012-01-11 21:40:365273void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
5274 const WebPluginAction& action) {
5275 if (webview())
5276 webview()->performPluginAction(action, location);
5277}
5278
[email protected]310ebd6302011-10-10 19:06:285279void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:195280 const GURL& page_url) {
5281 // Prepare list to storage all savable resource links.
5282 std::vector<GURL> resources_list;
[email protected]c2d986512012-05-12 00:22:465283 std::vector<GURL> referrer_urls_list;
5284 std::vector<WebKit::WebReferrerPolicy> referrer_policies_list;
[email protected]18d5be92011-07-25 18:00:195285 std::vector<GURL> frames_list;
5286 webkit_glue::SavableResourcesResult result(&resources_list,
[email protected]c2d986512012-05-12 00:22:465287 &referrer_urls_list,
5288 &referrer_policies_list,
[email protected]18d5be92011-07-25 18:00:195289 &frames_list);
5290
[email protected]e9ff79c2012-10-19 21:31:265291 // webkit/ doesn't know about Referrer.
[email protected]18d5be92011-07-25 18:00:195292 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
5293 webview(),
5294 page_url,
5295 &result,
[email protected]e9ff79c2012-10-19 21:31:265296 const_cast<const char**>(GetSavableSchemes()))) {
[email protected]18d5be92011-07-25 18:00:195297 // If something is wrong when collecting all savable resource links,
5298 // send empty list to embedder(browser) to tell it failed.
[email protected]c2d986512012-05-12 00:22:465299 referrer_urls_list.clear();
5300 referrer_policies_list.clear();
[email protected]18d5be92011-07-25 18:00:195301 resources_list.clear();
5302 frames_list.clear();
5303 }
5304
[email protected]e9ff79c2012-10-19 21:31:265305 std::vector<Referrer> referrers_list;
[email protected]c2d986512012-05-12 00:22:465306 CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size());
5307 for (unsigned i = 0; i < referrer_urls_list.size(); ++i) {
5308 referrers_list.push_back(
[email protected]e9ff79c2012-10-19 21:31:265309 Referrer(referrer_urls_list[i], referrer_policies_list[i]));
[email protected]c2d986512012-05-12 00:22:465310 }
5311
[email protected]18d5be92011-07-25 18:00:195312 // Send result of all savable resource links to embedder.
5313 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
5314 resources_list,
5315 referrers_list,
5316 frames_list));
5317}
5318
[email protected]310ebd6302011-10-10 19:06:285319void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:195320 const std::vector<GURL>& links,
5321 const std::vector<FilePath>& local_paths,
5322 const FilePath& local_directory_name) {
5323
5324 // Convert std::vector of GURLs to WebVector<WebURL>
5325 WebVector<WebURL> weburl_links(links);
5326
5327 // Convert std::vector of std::strings to WebVector<WebString>
5328 WebVector<WebString> webstring_paths(local_paths.size());
5329 for (size_t i = 0; i < local_paths.size(); i++)
[email protected]bb0e79472012-10-23 04:36:345330 webstring_paths[i] = webkit_base::FilePathToWebString(local_paths[i]);
[email protected]18d5be92011-07-25 18:00:195331
5332 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
5333 webstring_paths,
[email protected]bb0e79472012-10-23 04:36:345334 webkit_base::FilePathToWebString(
[email protected]18d5be92011-07-25 18:00:195335 local_directory_name));
5336}
5337
[email protected]310ebd6302011-10-10 19:06:285338void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:125339 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:275340 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:125341 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
5342 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
5343 before_unload_start_time,
5344 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:295345}
5346
[email protected]310ebd6302011-10-10 19:06:285347void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]69ddf852012-02-21 23:21:315348 // Ensure that no other in-progress navigation continues.
5349 OnStop();
5350
[email protected]73eb2602012-02-09 19:50:555351 // Only run unload if we're not swapped out yet, but send the ack either way.
5352 if (!is_swapped_out_) {
5353 // Swap this RenderView out so the tab can navigate to a page rendered by a
5354 // different process. This involves running the unload handler and clearing
5355 // the page. Once WasSwappedOut is called, we also allow this process to
5356 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:155357
[email protected]73eb2602012-02-09 19:50:555358 // Send an UpdateState message before we get swapped out.
5359 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:155360
[email protected]73eb2602012-02-09 19:50:555361 // Synchronously run the unload handler before sending the ACK.
5362 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:155363
[email protected]73eb2602012-02-09 19:50:555364 // Swap out and stop sending any IPC messages that are not ACKs.
5365 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:155366
[email protected]285f4bb82012-04-17 15:57:285367 // Replace the page with a blank dummy URL. The unload handler will not be
[email protected]73eb2602012-02-09 19:50:555368 // run a second time, thanks to a check in FrameLoader::stopLoading.
5369 // TODO(creis): Need to add a better way to do this that avoids running the
[email protected]285f4bb82012-04-17 15:57:285370 // beforeunload handler. For now, we just run it a second time silently.
[email protected]0720b532012-08-28 19:23:375371 NavigateToSwappedOutURL(webview()->mainFrame());
[email protected]961541a92012-06-01 21:15:285372
5373 // Let WebKit know that this view is hidden so it can drop resources and
5374 // stop compositing.
5375 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false);
[email protected]73eb2602012-02-09 19:50:555376 }
[email protected]992db4c2011-05-12 15:37:155377
5378 // Just echo back the params in the ACK.
5379 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
5380}
5381
[email protected]0720b532012-08-28 19:23:375382void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) {
[email protected]14392a52012-05-02 20:28:445383 // We use loadRequest instead of loadHTMLString because the former commits
5384 // synchronously. Otherwise a new navigation can interrupt the navigation
[email protected]e9ff79c2012-10-19 21:31:265385 // to kSwappedOutURL. If that happens to be to the page we had been
[email protected]14392a52012-05-02 20:28:445386 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]e9ff79c2012-10-19 21:31:265387 GURL swappedOutURL(kSwappedOutURL);
[email protected]14392a52012-05-02 20:28:445388 WebURLRequest request(swappedOutURL);
[email protected]0720b532012-08-28 19:23:375389 frame->loadRequest(request);
[email protected]14392a52012-05-02 20:28:445390}
5391
[email protected]310ebd6302011-10-10 19:06:285392void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:375393 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:295394 // TODO(creis): We'd rather use webview()->Close() here, but that currently
5395 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
5396 // in the onunload handler from appearing. For now, we're bypassing that and
5397 // calling the FrameLoader's CloseURL method directly. This should be
5398 // revisited to avoid having two ways to close a page. Having a single way
5399 // to close that can run onunload is also useful for fixing
5400 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:275401 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:295402
[email protected]992db4c2011-05-12 15:37:155403 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:295404}
5405
[email protected]310ebd6302011-10-10 19:06:285406void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:025407#if defined(USE_AURA)
5408 // Aura doesn't care if we switch themes.
5409#elif defined(OS_WIN)
[email protected]f78452f2012-05-15 02:07:525410 ui::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:465411 if (webview())
5412 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:575413#else // defined(OS_WIN)
5414 // TODO(port): we don't support theming on non-Windows platforms yet
5415 NOTIMPLEMENTED();
5416#endif
initial.commit09911bf2008-07-26 23:55:295417}
5418
[email protected]310ebd6302011-10-10 19:06:285419void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:085420 if (decrement_shared_popup_at_destruction_)
5421 shared_popup_counter_->data--;
5422 shared_popup_counter_ = new SharedRenderViewCounter(0);
5423 decrement_shared_popup_at_destruction_ = false;
5424}
5425
[email protected]310ebd6302011-10-10 19:06:285426bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
5427 const WebURLError& error,
5428 bool replace) {
[email protected]15d79e12009-08-02 19:23:455429 // We only show alternate error pages in the main frame. They are
5430 // intended to assist the user when navigating, so there is not much
5431 // value in showing them for failed subframes. Ideally, we would be
5432 // able to use the TYPED transition type for this, but that flag is
5433 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455434 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455435 return false;
5436
5437 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375438 // connection failure.
[email protected]15d79e12009-08-02 19:23:455439 int ec = error.reason;
5440 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5441 ec != net::ERR_CONNECTION_FAILED &&
5442 ec != net::ERR_CONNECTION_REFUSED &&
5443 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]82114f52012-03-20 22:53:415444 ec != net::ERR_CONNECTION_TIMED_OUT) {
[email protected]15d79e12009-08-02 19:23:455445 return false;
[email protected]82114f52012-03-20 22:53:415446 }
[email protected]15d79e12009-08-02 19:23:455447
5448 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555449 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455450 if (!error_page_url.is_valid())
5451 return false;
5452
5453 // Load an empty page first so there is an immediate response to the error,
5454 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455455 frame->loadHTMLString(std::string(),
[email protected]e9ff79c2012-10-19 21:31:265456 GURL(kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455457 error.unreachableURL,
5458 replace);
5459
5460 // Now, create a fetcher for the error page and associate it with the data
5461 // source we just created via the LoadHTMLString call. That way if another
5462 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:075463 DocumentState* document_state =
5464 DocumentState::FromDataSource(frame->provisionalDataSource());
5465 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:455466 new AltErrorPageResourceFetcher(
5467 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:085468 base::Bind(&RenderViewImpl::AltErrorPageFinished,
5469 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:455470 return true;
5471}
5472
[email protected]310ebd6302011-10-10 19:06:285473void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
5474 const WebURLError& original_error,
5475 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:455476 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:095477 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:555478 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:095479 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:455480}
5481
[email protected]310ebd6302011-10-10 19:06:285482void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:005483 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475484 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005485}
5486
[email protected]310ebd6302011-10-10 19:06:285487void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:095488 const gfx::Rect& resizer_rect,
5489 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:105490 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475491 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105492 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205493 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:315494 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:105495 }
[email protected]dd6afca2011-08-13 03:44:315496 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:105497 }
5498
[email protected]ee41e7d22011-10-14 19:34:095499 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:005500}
[email protected]0aa477bd2009-03-23 22:21:435501
[email protected]29ed96a2012-02-04 18:12:165502void RenderViewImpl::WillInitiatePaint() {
5503 // Notify the pepper plugins that we're about to paint.
5504 pepper_delegate_.ViewWillInitiatePaint();
5505}
5506
[email protected]310ebd6302011-10-10 19:06:285507void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:165508 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]53900d52010-06-16 04:25:015509 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:285510}
5511
[email protected]310ebd6302011-10-10 19:06:285512void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:285513 // Notify any pepper plugins that we painted. This will call into the plugin,
5514 // and we it may ask to close itself as a result. This will, in turn, modify
5515 // our set, possibly invalidating the iterator. So we iterate on a copy that
5516 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:015517 pepper_delegate_.ViewFlushedPaint();
5518
[email protected]5b1dec8c2012-02-07 04:35:385519 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
5520 // See crbug.com/112921.
5521 if (!webview())
5522 return;
5523
[email protected]00c39612010-03-06 02:53:285524 WebFrame* main_frame = webview()->mainFrame();
5525
5526 // If we have a provisional frame we are between the start and commit stages
5527 // of loading and we don't want to save stats.
5528 if (!main_frame->provisionalDataSource()) {
5529 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:075530 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:285531
[email protected]05c8e502010-08-15 15:13:525532 // TODO(jar): The following code should all be inside a method, probably in
5533 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285534 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:075535 if (document_state->first_paint_time().is_null()) {
5536 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:285537 }
[email protected]007733c2011-11-17 00:34:075538 if (document_state->first_paint_after_load_time().is_null() &&
5539 !document_state->finish_load_time().is_null()) {
5540 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:285541 }
5542 }
5543}
5544
[email protected]310ebd6302011-10-10 19:06:285545void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:085546 RenderWidget::OnSwapBuffersPosted();
5547}
5548
[email protected]310ebd6302011-10-10 19:06:285549void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:245550 RenderWidget::OnSwapBuffersComplete();
5551}
5552
[email protected]310ebd6302011-10-10 19:06:285553void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:245554 RenderWidget::OnSwapBuffersAborted();
5555}
5556
[email protected]310ebd6302011-10-10 19:06:285557webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:155558 const gfx::Rect& paint_bounds,
5559 TransportDIB** dib,
5560 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:205561 gfx::Rect* clip,
5562 float* scale_factor) {
[email protected]ca4847f2010-09-24 05:39:155563 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
[email protected]0f3a2d12012-09-01 03:37:205564 paint_bounds, dib, location, clip, scale_factor);
[email protected]ca4847f2010-09-24 05:39:155565}
5566
[email protected]ceb36f7d2012-10-31 18:33:245567gfx::Vector2d RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:075568 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]ceb36f7d2012-10-31 18:33:245569 return gfx::Vector2d(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:525570}
5571
[email protected]310ebd6302011-10-10 19:06:285572void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:165573 if (webview())
[email protected]26aa0482009-09-30 16:55:275574 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165575}
5576
[email protected]310ebd6302011-10-10 19:06:285577void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:145578 if (webview())
[email protected]b4bb2502009-10-01 22:35:275579 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145580
5581 SetBackground(background);
5582}
5583
[email protected]2a84f9d2012-06-05 21:50:435584void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) {
5585 if (accessibility_mode_ == new_mode)
5586 return;
5587 accessibility_mode_ = new_mode;
5588 if (renderer_accessibility_) {
5589 delete renderer_accessibility_;
5590 renderer_accessibility_ = NULL;
5591 }
5592 if (accessibility_mode_ == AccessibilityModeComplete)
5593 renderer_accessibility_ = new RendererAccessibilityComplete(this);
5594 else if (accessibility_mode_ == AccessibilityModeEditableTextOnly)
5595 renderer_accessibility_ = new RendererAccessibilityFocusOnly(this);
5596}
5597
[email protected]310ebd6302011-10-10 19:06:285598void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:345599 if (webview())
[email protected]b4bb2502009-10-01 22:35:275600 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265601
5602#if defined(OS_MACOSX)
5603 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5604 for (plugin_it = plugin_delegates_.begin();
5605 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5606 (*plugin_it)->SetWindowFocus(active);
5607 }
5608#endif
[email protected]8c66c5a2009-07-22 17:26:345609}
5610
[email protected]7a17bac02012-03-07 21:58:125611void RenderViewImpl::OnSetNavigationStartTime(
5612 const base::TimeTicks& browser_navigation_start) {
5613 if (!webview())
5614 return;
5615
5616 // Only the initial navigation can be a cross-renderer navigation. If we've
5617 // already navigated away from that page, we can ignore this message.
5618 if (page_id_ != -1)
5619 return;
5620
5621 // browser_navigation_start is likely before this process existed, so we can't
5622 // use InterProcessTimeTicksConverter. Instead, the best we can do is just
5623 // ensure we don't report a bogus value in the future.
5624 base::TimeTicks navigation_start = std::min(base::TimeTicks::Now(),
5625 browser_navigation_start);
5626 webview()->mainFrame()->provisionalDataSource()->setNavigationStartTime(
5627 (navigation_start - base::TimeTicks()).InSecondsF());
5628}
5629
[email protected]6ce7abc52010-02-02 18:40:145630#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285631void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:145632 // Inform plugins that their container has changed visibility.
5633 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5634 for (plugin_it = plugin_delegates_.begin();
5635 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5636 (*plugin_it)->SetContainerVisibility(visible);
5637 }
5638}
[email protected]1e6e3c992010-02-08 15:52:135639
[email protected]310ebd6302011-10-10 19:06:285640void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
5641 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:135642 // Inform plugins that their window's frame has changed.
5643 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5644 for (plugin_it = plugin_delegates_.begin();
5645 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5646 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5647 }
5648}
[email protected]935d63d2010-10-15 23:31:555649
[email protected]310ebd6302011-10-10 19:06:285650void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
5651 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135652 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555653 // applies to it or not, so inform all the delegates.
5654 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5655 for (plugin_it = plugin_delegates_.begin();
5656 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135657 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555658 }
5659}
[email protected]6ce7abc52010-02-02 18:40:145660#endif // OS_MACOSX
5661
[email protected]310ebd6302011-10-10 19:06:285662void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:485663 const EditCommands& edit_commands) {
5664 edit_commands_ = edit_commands;
5665}
5666
[email protected]310ebd6302011-10-10 19:06:285667void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:595668 // We need to grab a pointer to the doomed WebView before we destroy it.
5669 WebView* doomed = webview();
5670 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495671 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:595672}
5673
[email protected]310ebd6302011-10-10 19:06:285674void RenderViewImpl::DidHandleKeyEvent() {
[email protected]b2324b092012-11-01 10:34:115675 ClearEditCommands();
[email protected]446705872009-09-10 07:22:485676}
5677
[email protected]310ebd6302011-10-10 19:06:285678bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]41d86852012-11-07 12:23:245679 possible_drag_event_info_.event_source =
5680 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
5681 possible_drag_event_info_.event_location =
5682 gfx::Point(event.globalX, event.globalY);
[email protected]217690d2012-01-27 07:33:115683 pepper_delegate_.WillHandleMouseEvent();
5684
5685 // If the mouse is locked, only the current owner of the mouse lock can
5686 // process mouse events.
5687 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:375688}
5689
[email protected]41d86852012-11-07 12:23:245690bool RenderViewImpl::WillHandleGestureEvent(
5691 const WebKit::WebGestureEvent& event) {
5692 possible_drag_event_info_.event_source =
5693 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
5694 possible_drag_event_info_.event_location =
5695 gfx::Point(event.globalX, event.globalY);
5696 return false;
5697}
5698
[email protected]2b942c332012-04-25 16:26:265699void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515700 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065701}
5702
[email protected]310ebd6302011-10-10 19:06:285703void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:245704 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
5705}
5706
[email protected]310ebd6302011-10-10 19:06:285707void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:435708 RenderWidget::OnWasHidden();
5709
[email protected]2d7b82c2012-06-01 05:57:505710#if defined(OS_ANDROID)
5711 // Inform WebMediaPlayerManagerAndroid to release all media player resources.
5712 media_player_manager_->ReleaseMediaResources();
5713#endif
5714
[email protected]a6939ca42011-02-18 17:58:075715 if (webview()) {
5716 webview()->settings()->setMinimumTimerInterval(
5717 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:445718 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075719 }
5720
[email protected]204f1df2012-01-04 20:21:135721 // Inform PPAPI plugins that their page is no longer visible.
5722 pepper_delegate_.PageVisibilityChanged(false);
5723
[email protected]a6939ca42011-02-18 17:58:075724#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135725 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:435726 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5727 for (plugin_it = plugin_delegates_.begin();
5728 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5729 (*plugin_it)->SetContainerVisibility(false);
5730 }
[email protected]a6939ca42011-02-18 17:58:075731#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:435732}
5733
[email protected]9e2e4632012-07-27 16:38:415734void RenderViewImpl::OnWasShown(bool needs_repainting) {
5735 RenderWidget::OnWasShown(needs_repainting);
[email protected]941e4552010-02-01 21:23:435736
[email protected]a6939ca42011-02-18 17:58:075737 if (webview()) {
5738 webview()->settings()->setMinimumTimerInterval(
5739 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:445740 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075741 }
5742
[email protected]204f1df2012-01-04 20:21:135743 // Inform PPAPI plugins that their page is visible.
5744 pepper_delegate_.PageVisibilityChanged(true);
5745
[email protected]a6939ca42011-02-18 17:58:075746#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135747 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:435748 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5749 for (plugin_it = plugin_delegates_.begin();
5750 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5751 (*plugin_it)->SetContainerVisibility(true);
5752 }
[email protected]784ea1ab2010-09-18 00:02:345753#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:075754}
[email protected]1e6e3c992010-02-08 15:52:135755
[email protected]310ebd6302011-10-10 19:06:285756bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]9caf09bc2012-06-25 21:46:285757 // Contexts using the command buffer support asynchronous swapbuffers.
[email protected]f89e173a2012-08-24 01:12:265758 // See RenderViewImpl::createOutputSurface().
[email protected]9caf09bc2012-06-25 21:46:285759 if (WebWidgetHandlesCompositorScheduling() ||
5760 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL))
[email protected]555e75d2011-10-08 01:23:385761 return false;
5762
[email protected]9caf09bc2012-06-25 21:46:285763 return true;
[email protected]65225772011-05-12 21:10:245764}
5765
[email protected]479b0172012-10-29 19:27:095766bool RenderViewImpl::ForceCompositingModeEnabled() {
5767 return webkit_preferences_.force_compositing_mode;
5768}
5769
[email protected]310ebd6302011-10-10 19:06:285770void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:135771 RenderWidget::OnSetFocus(enable);
5772
[email protected]7d3c02c2010-05-05 23:10:315773 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075774 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135775 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5776 for (plugin_it = plugin_delegates_.begin();
5777 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345778#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315779 // RenderWidget's call to setFocus can cause the underlying webview's
5780 // activation state to change just like a call to setIsActive.
5781 if (enable)
5782 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345783#endif
[email protected]7d3c02c2010-05-05 23:10:315784 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135785 }
5786 }
[email protected]a01da5682012-06-30 00:37:315787 // Notify all Pepper plugins.
5788 pepper_delegate_.OnSetFocus(enable);
[email protected]321032992012-11-08 01:01:275789 // Notify all BrowserPlugins of the RenderView's focus state.
5790 BrowserPluginManager::Get()->SetEmbedderFocus(this, enable);
[email protected]1e6e3c992010-02-08 15:52:135791}
[email protected]941e4552010-02-01 21:23:435792
[email protected]310ebd6302011-10-10 19:06:285793void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]3306f262012-09-21 19:20:425794 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]3f783362011-10-21 22:40:505795 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:575796}
5797
[email protected]73bf95812011-10-12 11:38:325798void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]3306f262012-09-21 19:20:425799 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]8fe8f742012-06-14 00:36:085800 if (renderer_accessibility_)
5801 renderer_accessibility_->FocusedNodeChanged(WebNode());
[email protected]73bf95812011-10-12 11:38:325802}
5803
[email protected]3f783362011-10-21 22:40:505804void RenderViewImpl::PpapiPluginCaretPositionChanged() {
5805 UpdateSelectionBounds();
5806}
5807
[email protected]b25b3ee2012-01-13 05:19:545808bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
5809 if (!pepper_delegate_.IsPluginFocused())
5810 return false;
5811 *rect = pepper_delegate_.GetCaretBounds();
5812 return true;
5813}
5814
[email protected]397c23962012-05-21 07:09:325815void RenderViewImpl::SimulateImeSetComposition(
5816 const string16& text,
5817 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5818 int selection_start,
5819 int selection_end) {
5820 OnImeSetComposition(text, underlines, selection_start, selection_end);
5821}
5822
5823void RenderViewImpl::SimulateImeConfirmComposition(
5824 const string16& text,
5825 const ui::Range& replacement_range) {
5826 OnImeConfirmComposition(text, replacement_range);
5827}
5828
[email protected]73bf95812011-10-12 11:38:325829void RenderViewImpl::PpapiPluginCancelComposition() {
5830 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]58b48a0d2012-06-13 07:01:355831 const ui::Range range(ui::Range::InvalidRange());
5832 const std::vector<gfx::Rect> empty_bounds;
5833 UpdateCompositionInfo(range, empty_bounds);
[email protected]73bf95812011-10-12 11:38:325834}
5835
[email protected]3c8c74c2012-03-15 07:34:525836void RenderViewImpl::PpapiPluginSelectionChanged() {
5837 SyncSelectionIfRequired();
5838}
5839
[email protected]e9ff79c2012-10-19 21:31:265840void RenderViewImpl::PpapiPluginCreated(RendererPpapiHost* host) {
[email protected]236bf852012-07-27 22:49:365841 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
5842 DidCreatePepperPlugin(host));
5843}
5844
[email protected]310ebd6302011-10-10 19:06:285845void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:575846 const string16& text,
5847 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5848 int selection_start,
5849 int selection_end) {
[email protected]73bf95812011-10-12 11:38:325850 if (pepper_delegate_.IsPluginFocused()) {
5851 // When a PPAPI plugin has focus, we bypass WebKit.
5852 pepper_delegate_.OnImeSetComposition(text,
5853 underlines,
5854 selection_start,
5855 selection_end);
5856 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235857#if defined(OS_WIN)
5858 // When a plug-in has focus, we create platform-specific IME data used by
5859 // our IME emulator and send it directly to the focused plug-in, i.e. we
5860 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
5861 // instance ID is the same one as the specified ID.)
5862 if (focused_plugin_id_ >= 0) {
5863 std::vector<int> clauses;
5864 std::vector<int> target;
5865 for (size_t i = 0; i < underlines.size(); ++i) {
5866 clauses.push_back(underlines[i].startOffset);
5867 clauses.push_back(underlines[i].endOffset);
5868 if (underlines[i].thick) {
5869 target.clear();
5870 target.push_back(underlines[i].startOffset);
5871 target.push_back(underlines[i].endOffset);
5872 }
5873 }
5874 std::set<WebPluginDelegateProxy*>::iterator it;
5875 for (it = plugin_delegates_.begin();
5876 it != plugin_delegates_.end(); ++it) {
5877 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
5878 focused_plugin_id_);
5879 }
5880 return;
5881 }
5882#endif
[email protected]56ea1a62011-05-30 07:05:575883 RenderWidget::OnImeSetComposition(text,
5884 underlines,
5885 selection_start,
5886 selection_end);
5887 }
5888}
5889
[email protected]4de6d1692011-10-12 08:45:445890void RenderViewImpl::OnImeConfirmComposition(
5891 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:575892 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:325893 // When a PPAPI plugin has focus, we bypass WebKit.
5894 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:575895 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235896#if defined(OS_WIN)
5897 // Same as OnImeSetComposition(), we send the text from IMEs directly to
5898 // plug-ins. When we send IME text directly to plug-ins, we should not send
5899 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:445900 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:235901 if (focused_plugin_id_ >= 0) {
5902 std::set<WebPluginDelegateProxy*>::iterator it;
5903 for (it = plugin_delegates_.begin();
5904 it != plugin_delegates_.end(); ++it) {
5905 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
5906 }
5907 return;
5908 }
5909#endif
[email protected]ebd28ac2011-10-13 18:49:055910 if (replacement_range.IsValid() && webview()) {
5911 // Select the text in |replacement_range|, it will then be replaced by
5912 // text added by the call to RenderWidget::OnImeConfirmComposition().
5913 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:165914 WebRange webrange = WebRange::fromDocumentRange(
5915 frame, replacement_range.start(), replacement_range.length());
5916 if (!webrange.isNull())
[email protected]884f9002012-08-21 19:33:585917 frame->selectRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:055918 }
5919 }
[email protected]4de6d1692011-10-12 08:45:445920 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:575921 }
5922}
5923
[email protected]dea5e7682012-06-14 05:21:245924void RenderViewImpl::OnSetDeviceScaleFactor(float device_scale_factor) {
5925 RenderWidget::OnSetDeviceScaleFactor(device_scale_factor);
5926 if (webview())
5927 webview()->setDeviceScaleFactor(device_scale_factor);
5928}
5929
[email protected]310ebd6302011-10-10 19:06:285930ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:325931 return pepper_delegate_.IsPluginFocused() ?
5932 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
5933}
5934
[email protected]3f783362011-10-21 22:40:505935void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
5936 if (pepper_delegate_.IsPluginFocused()) {
5937 // TODO(kinaba) http://crbug.com/101101
5938 // Current Pepper IME API does not handle selection bounds. So we simply
5939 // use the caret position as an empty range for now. It will be updated
5940 // after Pepper API equips features related to surrounding text retrieval.
5941 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
5942 *start = caret;
5943 *end = caret;
5944 return;
5945 }
5946 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:455947}
5948
[email protected]58b48a0d2012-06-13 07:01:355949void RenderViewImpl::GetCompositionCharacterBounds(
5950 std::vector<gfx::Rect>* bounds) {
5951 DCHECK(bounds);
5952 bounds->clear();
5953
5954 if (!webview())
5955 return;
5956 size_t start_offset = 0;
5957 size_t character_count = 0;
5958 if (!webview()->compositionRange(&start_offset, &character_count))
5959 return;
5960 if (character_count == 0)
5961 return;
5962
5963 WebKit::WebFrame* frame = webview()->focusedFrame();
5964 if (!frame)
5965 return;
5966
5967 bounds->reserve(character_count);
5968 WebKit::WebRect webrect;
5969 for (size_t i = 0; i < character_count; ++i) {
5970 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
5971 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
5972 bounds->clear();
5973 return;
5974 }
5975 bounds->push_back(webrect);
5976 }
5977}
5978
[email protected]310ebd6302011-10-10 19:06:285979bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:325980 return pepper_delegate_.IsPluginFocused() ?
5981 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:575982}
5983
[email protected]e6ae0f6c2011-10-04 10:39:235984#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:285985void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:235986 if (focused)
5987 focused_plugin_id_ = plugin_id;
5988 else
5989 focused_plugin_id_ = -1;
5990}
5991#endif
5992
[email protected]43f28f832010-02-03 02:28:485993#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285994void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]82114f52012-03-20 22:53:415995 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
[email protected]b7f75862011-01-21 21:15:135996}
5997
[email protected]310ebd6302011-10-10 19:06:285998void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:135999 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:556000 // This message can be sent during event-handling, and needs to be delivered
6001 // within that context.
6002 msg->set_unblock(true);
6003 Send(msg);
6004}
6005
[email protected]310ebd6302011-10-10 19:06:286006gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:236007 bool opaque, bool root) {
[email protected]b2968292012-03-28 01:35:516008 gfx::PluginWindowHandle window = gfx::kNullPluginWindow;
[email protected]43f28f832010-02-03 02:28:486009 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:236010 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:116011 if (window) {
6012 fake_plugin_window_handles_.insert(window);
6013 }
[email protected]43f28f832010-02-03 02:28:486014 return window;
6015}
6016
[email protected]310ebd6302011-10-10 19:06:286017void RenderViewImpl::DestroyFakePluginWindowHandle(
6018 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:116019 if (window && fake_plugin_window_handles_.find(window) !=
6020 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:486021 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:116022 fake_plugin_window_handles_.erase(window);
6023 }
[email protected]43f28f832010-02-03 02:28:486024}
6025
[email protected]310ebd6302011-10-10 19:06:286026void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
6027 gfx::PluginWindowHandle window,
6028 int32 width,
6029 int32 height,
6030 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:336031 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:486032 routing_id(), window, width, height, io_surface_identifier));
6033}
6034
[email protected]310ebd6302011-10-10 19:06:286035void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:336036 gfx::PluginWindowHandle window,
6037 int32 width,
6038 int32 height,
6039 TransportDIB::Handle transport_dib) {
6040 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:076041 routing_id(), window, width, height, transport_dib));
6042}
6043
[email protected]310ebd6302011-10-10 19:06:286044TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:336045 size_t size) {
[email protected]1aef98132010-02-23 18:00:076046 TransportDIB::Handle dib_handle;
6047 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:386048 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:076049 return dib_handle;
6050 // Return an invalid handle if Send() fails.
6051 return TransportDIB::DefaultHandleValue();
6052}
6053
[email protected]310ebd6302011-10-10 19:06:286054void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
6055 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:076056 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
6057}
6058
[email protected]310ebd6302011-10-10 19:06:286059void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:326060 gfx::PluginWindowHandle window, uint64 surface_handle) {
[email protected]f35d6672010-10-28 21:39:146061 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:326062 routing_id(), window, surface_handle));
[email protected]43f28f832010-02-03 02:28:486063}
[email protected]82114f52012-03-20 22:53:416064#endif // defined(OS_MACOSX)
[email protected]58c321d2010-02-19 12:11:286065
[email protected]310ebd6302011-10-10 19:06:286066bool RenderViewImpl::ScheduleFileChooser(
[email protected]e9ff79c2012-10-19 21:31:266067 const FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:476068 WebFileChooserCompletion* completion) {
6069 static const size_t kMaximumPendingFileChooseRequests = 4;
6070 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
6071 // This sanity check prevents too many file choose requests from getting
6072 // queued which could DoS the user. Getting these is most likely a
6073 // programming error (there are many ways to DoS the user so it's not
6074 // considered a "real" security check), either in JS requesting many file
6075 // choosers to pop up, or in a plugin.
6076 //
6077 // TODO(brettw) we might possibly want to require a user gesture to open
6078 // a file picker, which will address this issue in a better way.
6079 return false;
6080 }
6081
6082 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
6083 new PendingFileChooser(params, completion)));
6084 if (file_chooser_completions_.size() == 1) {
6085 // Actually show the browse dialog when this is the first request.
6086 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
6087 }
6088 return true;
6089}
6090
[email protected]310ebd6302011-10-10 19:06:286091WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:516092 if (!geolocation_dispatcher_)
6093 geolocation_dispatcher_ = new GeolocationDispatcher(this);
6094 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:256095}
[email protected]61c9f032010-03-31 23:04:196096
[email protected]310ebd6302011-10-10 19:06:286097WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:116098 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:226099#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:026100 if (!input_tag_speech_dispatcher_)
6101 input_tag_speech_dispatcher_ =
6102 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:226103#endif
[email protected]c52b2892012-03-07 11:01:026104 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:116105}
6106
[email protected]64d09222012-05-25 10:10:346107WebKit::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
6108#if defined(ENABLE_INPUT_SPEECH)
6109 if (!speech_recognition_dispatcher_)
6110 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
6111#endif
6112 return speech_recognition_dispatcher_;
6113}
6114
[email protected]310ebd6302011-10-10 19:06:286115WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:516116 if (!device_orientation_dispatcher_)
6117 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
6118 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:536119}
6120
[email protected]310ebd6302011-10-10 19:06:286121void RenderViewImpl::zoomLimitsChanged(double minimum_level,
6122 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:256123 // For now, don't remember plugin zoom values. We don't want to mix them with
6124 // normal web content (i.e. a fixed layout plugin would usually want them
6125 // different).
6126 bool remember = !webview()->mainFrame()->document().isPluginDocument();
6127
[email protected]b75b8292010-10-01 07:28:256128 int minimum_percent = static_cast<int>(
6129 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
6130 int maximum_percent = static_cast<int>(
6131 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:256132
6133 Send(new ViewHostMsg_UpdateZoomLimits(
6134 routing_id_, minimum_percent, maximum_percent, remember));
6135}
6136
[email protected]310ebd6302011-10-10 19:06:286137void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:256138 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:086139 float zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:266140
6141 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
6142
[email protected]b75b8292010-10-01 07:28:256143 // Tell the browser which url got zoomed so it can update the menu and the
6144 // saved values if necessary
6145 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:086146 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:416147 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:256148}
6149
[email protected]310ebd6302011-10-10 19:06:286150void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
6151 const WebString& base_url,
6152 const WebString& url,
6153 const WebString& title) {
[email protected]3a3b75a2012-06-01 08:38:366154 bool user_gesture = (webview()->focusedFrame() &&
6155 webview()->focusedFrame()->isProcessingUserGesture());
[email protected]a6d36cc2011-02-23 00:39:486156 GURL base(base_url);
6157 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
6158 if (base.GetOrigin() != absolute_url.GetOrigin()) {
6159 return;
6160 }
[email protected]f1a29a02011-10-06 23:08:446161 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
6162 UTF16ToUTF8(scheme),
6163 absolute_url,
[email protected]3a3b75a2012-06-01 08:38:366164 title,
6165 user_gesture));
[email protected]a6d36cc2011-02-23 00:39:486166}
6167
[email protected]310ebd6302011-10-10 19:06:286168WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:446169 WebKit::WebPageVisibilityState current_state = is_hidden() ?
6170 WebKit::WebPageVisibilityStateHidden :
6171 WebKit::WebPageVisibilityStateVisible;
6172 WebKit::WebPageVisibilityState override_state = current_state;
[email protected]e9ff79c2012-10-19 21:31:266173 if (GetContentClient()->renderer()->
[email protected]f59203a2011-06-07 10:01:446174 ShouldOverridePageVisibilityState(this,
6175 &override_state))
6176 return override_state;
6177 return current_state;
[email protected]94dec932011-05-26 20:04:216178}
6179
[email protected]273558fb2012-01-12 15:03:516180WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
[email protected]273558fb2012-01-12 15:03:516181 EnsureMediaStreamImpl();
6182 return media_stream_impl_;
6183}
6184
[email protected]a0629af92012-08-08 00:39:376185void RenderViewImpl::draggableRegionsChanged() {
6186 FOR_EACH_OBSERVER(
6187 RenderViewObserver,
6188 observers_,
6189 DraggableRegionsChanged(webview()->mainFrame()));
6190}
6191
[email protected]20657a82012-08-21 20:23:036192#if defined(OS_ANDROID)
6193WebContentDetectionResult RenderViewImpl::detectContentAround(
6194 const WebHitTestResult& touch_hit) {
6195 DCHECK(!touch_hit.isNull());
6196 DCHECK(!touch_hit.node().isNull());
6197 DCHECK(touch_hit.node().isTextNode());
6198
6199 // Process the position with all the registered content detectors until
6200 // a match is found. Priority is provided by their relative order.
6201 for (ContentDetectorList::const_iterator it = content_detectors_.begin();
6202 it != content_detectors_.end(); ++it) {
6203 ContentDetector::Result content = (*it)->FindTappedContent(touch_hit);
6204 if (content.valid) {
6205 return WebContentDetectionResult(content.content_boundaries,
6206 UTF8ToUTF16(content.text), content.intent_url);
6207 }
6208 }
6209 return WebContentDetectionResult();
6210}
6211
6212void RenderViewImpl::scheduleContentIntent(const WebURL& intent) {
6213 // Introduce a short delay so that the user can notice the content.
6214 MessageLoop::current()->PostDelayedTask(
6215 FROM_HERE,
6216 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, AsWeakPtr(),
6217 intent, expected_content_intent_id_),
6218 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds));
6219}
6220
6221void RenderViewImpl::cancelScheduledContentIntents() {
6222 ++expected_content_intent_id_;
6223}
6224
6225void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent,
6226 size_t request_id) {
6227 if (request_id != expected_content_intent_id_)
6228 return;
6229
6230 // Remove the content highlighting if any.
6231 scheduleComposite();
6232
6233 if (!intent.is_empty())
6234 Send(new ViewHostMsg_StartContentIntent(routing_id_, intent));
6235}
6236#endif
6237
[email protected]310ebd6302011-10-10 19:06:286238void RenderViewImpl::OnAsyncFileOpened(
6239 base::PlatformFileError error_code,
6240 IPC::PlatformFileForTransit file_for_transit,
6241 int message_id) {
[email protected]27a9ef32010-09-10 04:06:246242 pepper_delegate_.OnAsyncFileOpened(
6243 error_code,
6244 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
6245 message_id);
6246}
[email protected]caf706f2010-10-26 17:54:086247
[email protected]310ebd6302011-10-10 19:06:286248void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:476249 int request_id,
[email protected]d54305072011-06-22 20:58:436250 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:476251 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
[email protected]2b657fd2011-04-18 16:00:476252 handle);
[email protected]eb415bf0e2011-04-14 02:45:426253}
6254
[email protected]d8415ad92012-08-23 14:40:506255void RenderViewImpl::OnPpapiBrokerPermissionResult(
6256 int request_id,
6257 bool result) {
6258 pepper_delegate_.OnPpapiBrokerPermissionResult(request_id, result);
6259}
6260
[email protected]caf706f2010-10-26 17:54:086261#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:286262void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:156263 if (external_popup_menu_ == NULL) {
6264 // Crash reports from the field indicate that we can be notified with a
6265 // NULL external popup menu (we probably get notified twice).
6266 // If you hit this please file a bug against jcivelli and include the page
6267 // and steps to repro.
6268 NOTREACHED();
6269 return;
6270 }
[email protected]caf706f2010-10-26 17:54:086271 external_popup_menu_->DidSelectItem(selected_index);
6272 external_popup_menu_.reset();
6273}
6274#endif
[email protected]bb461532010-11-26 21:50:236275
[email protected]24d2b172012-05-26 00:54:126276#if defined(OS_ANDROID)
6277void RenderViewImpl::OnSelectPopupMenuItems(
6278 bool canceled,
6279 const std::vector<int>& selected_indices) {
6280 // It is possible to receive more than one of these calls if the user presses
6281 // a select faster than it takes for the show-select-popup IPC message to make
6282 // it to the browser UI thread. Ignore the extra-messages.
6283 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug.
6284 if (!external_popup_menu_.get())
6285 return;
6286
6287 external_popup_menu_->DidSelectItems(canceled, selected_indices);
6288 external_popup_menu_.reset();
6289}
6290#endif
6291
[email protected]310ebd6302011-10-10 19:06:286292void RenderViewImpl::OnContextMenuClosed(
[email protected]e9ff79c2012-10-19 21:31:266293 const CustomContextMenuContext& custom_context) {
[email protected]860ee642012-10-13 03:46:256294 if (custom_context.request_id) {
6295 // External request, should be in our map.
[email protected]e9ff79c2012-10-19 21:31:266296 ContextMenuClient* client =
[email protected]860ee642012-10-13 03:46:256297 pending_context_menus_.Lookup(custom_context.request_id);
[email protected]e0fd0eb2012-10-17 21:11:466298 if (client) {
6299 client->OnMenuClosed(custom_context.request_id);
6300 pending_context_menus_.Remove(custom_context.request_id);
6301 }
[email protected]860ee642012-10-13 03:46:256302 } else {
6303 // Internal request, forward to WebKit.
[email protected]b29aa74b2011-01-31 21:41:086304 context_menu_node_.reset();
[email protected]860ee642012-10-13 03:46:256305 }
[email protected]521b2482011-01-15 00:10:106306}
[email protected]5a7b15a2011-08-22 22:48:186307
[email protected]310ebd6302011-10-10 19:06:286308void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:186309 if (!webview())
6310 return;
6311 WebFrame* main_frame = webview()->mainFrame();
6312 if (!main_frame)
6313 return;
6314 main_frame->enableViewSourceMode(true);
6315}
[email protected]67bfb83f2011-09-22 03:36:376316
[email protected]310ebd6302011-10-10 19:06:286317bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:086318 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:406319}
[email protected]7f3c7af2011-10-20 22:52:516320
[email protected]64d0e192011-12-09 14:44:206321void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7e9c5bb02012-05-14 13:58:316322 DCHECK(!java_bridge_dispatcher_);
[email protected]464750f2011-10-24 23:16:186323#if defined(ENABLE_JAVA_BRIDGE)
[email protected]7e9c5bb02012-05-14 13:58:316324 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this);
[email protected]464750f2011-10-24 23:16:186325#endif
[email protected]7f3c7af2011-10-20 22:52:516326}
[email protected]0720b532012-08-28 19:23:376327
6328void RenderViewImpl::OnUpdatedFrameTree(
6329 int process_id,
6330 int route_id,
6331 const std::string& frame_tree) {
[email protected]e12dbe6f2012-10-04 22:11:196332 // TODO(nasko): Remove once http://crbug.com/153701 is fixed.
6333 DCHECK(false);
[email protected]5fa9b36b2012-09-21 18:14:276334 // We should only act on this message if we are swapped out. It's possible
6335 // for this to happen due to races.
6336 if (!is_swapped_out_)
6337 return;
6338
[email protected]0720b532012-08-28 19:23:376339 base::DictionaryValue* frames = NULL;
6340 scoped_ptr<base::Value> tree(base::JSONReader::Read(frame_tree));
6341 if (tree.get() && tree->IsType(base::Value::TYPE_DICTIONARY))
6342 tree->GetAsDictionary(&frames);
6343
6344 updating_frame_tree_ = true;
6345 active_frame_id_map_.clear();
6346
6347 target_process_id_ = process_id;
6348 target_routing_id_ = route_id;
6349 CreateFrameTree(webview()->mainFrame(), frames);
6350
6351 updating_frame_tree_ = false;
6352}
[email protected]f9526d12012-10-18 01:55:036353
[email protected]efd7e47f2012-10-19 20:37:516354#if defined(OS_ANDROID)
[email protected]f9526d12012-10-18 01:55:036355bool RenderViewImpl::didTapMultipleTargets(
6356 const WebKit::WebGestureEvent& event,
6357 const WebVector<WebRect>& target_rects) {
[email protected]f9526d12012-10-18 01:55:036358 gfx::Rect finger_rect(
6359 event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2,
6360 event.data.tap.width, event.data.tap.height);
6361 gfx::Rect zoom_rect;
6362 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
6363 finger_rect, target_rects, GetSize(), &zoom_rect);
6364 if (!scale)
6365 return false;
6366
6367 gfx::Size canvas_size = zoom_rect.size();
[email protected]01a15a72012-11-10 09:34:286368 canvas_size = ToCeiledSize(gfx::ScaleSize(canvas_size, scale));
[email protected]f9526d12012-10-18 01:55:036369 TransportDIB* transport_dib = NULL;
6370 {
6371 scoped_ptr<skia::PlatformCanvas> canvas(
6372 RenderProcess::current()->GetDrawingCanvas(&transport_dib,
6373 gfx::Rect(canvas_size)));
6374 if (!canvas.get())
6375 return false;
6376
6377 canvas->scale(scale, scale);
6378
6379 canvas->translate(-zoom_rect.x(), -zoom_rect.y());
6380 webwidget_->paint(webkit_glue::ToWebCanvas(canvas.get()), zoom_rect,
6381 WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent);
6382 }
6383 Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_,
6384 zoom_rect,
6385 canvas_size,
6386 transport_dib->id()));
6387
6388 return true;
6389}
[email protected]efd7e47f2012-10-19 20:37:516390#endif
[email protected]f9526d12012-10-18 01:55:036391
6392void RenderViewImpl::OnReleaseDisambiguationPopupDIB(
6393 TransportDIB::Handle dib_handle) {
6394 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle);
6395 RenderProcess::current()->ReleaseTransportDIB(dib);
6396}
[email protected]e9ff79c2012-10-19 21:31:266397
6398} // namespace content