blob: e7d3d5947b630523917ef20a03ba9902df5521df [file] [log] [blame]
[email protected]b553edd52012-01-10 12:15:231// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]310ebd6302011-10-10 19:06:285#include "content/renderer/render_view_impl.h"
initial.commit09911bf2008-07-26 23:55:296
7#include <algorithm>
[email protected]b75b8292010-10-01 07:28:258#include <cmath>
initial.commit09911bf2008-07-26 23:55:299#include <string>
10#include <vector>
11
[email protected]6e806822011-11-19 01:51:0812#include "base/bind.h"
13#include "base/bind_helpers.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5015#include "base/compiler_specific.h"
[email protected]e7ca2892012-09-01 00:52:1516#include "base/debug/trace_event.h"
[email protected]0720b532012-08-28 19:23:3717#include "base/json/json_reader.h"
[email protected]b1cf3372011-04-20 21:28:1018#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4919#include "base/lazy_instance.h"
[email protected]084c8552012-08-12 22:51:2020#include "base/message_loop_proxy.h"
[email protected]835d7c82010-10-14 04:38:3821#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2822#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5123#include "base/process_util.h"
[email protected]7ddea9802012-02-22 23:08:0524#include "base/string_number_conversions.h"
[email protected]0a35efc2012-03-13 17:28:1325#include "base/string_piece.h"
[email protected]318bf5802011-08-08 17:12:4126#include "base/string_split.h"
initial.commit09911bf2008-07-26 23:55:2927#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2828#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2629#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2230#include "base/utf_string_conversions.h"
[email protected]e93e04e2011-03-14 00:27:1031#include "content/common/appcache/appcache_dispatcher.h"
[email protected]14392a52012-05-02 20:28:4432#include "content/common/child_thread.h"
[email protected]127dd582011-03-16 21:32:1033#include "content/common/clipboard_messages.h"
[email protected]0720b532012-08-28 19:23:3734#include "content/common/content_constants_internal.h"
[email protected]37666cf2011-03-13 21:51:4235#include "content/common/database_messages.h"
[email protected]59f4f2fa2011-03-23 01:00:5536#include "content/common/drag_messages.h"
[email protected]16dd6e22012-03-01 19:08:2037#include "content/common/fileapi/file_system_dispatcher.h"
38#include "content/common/fileapi/webfilesystem_callback_dispatcher.h"
[email protected]c26ad882012-02-07 06:41:2039#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]a2ef54c2011-10-10 16:20:3140#include "content/common/intents_messages.h"
[email protected]7f3c7af2011-10-20 22:52:5141#include "content/common/java_bridge_messages.h"
[email protected]bac466e2012-07-31 02:10:5442#include "content/common/old_browser_plugin_messages.h"
[email protected]127dd582011-03-16 21:32:1043#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0044#include "content/common/pepper_plugin_registry.h"
[email protected]10e5cf12011-04-13 04:10:4045#include "content/common/quota_dispatcher.h"
[email protected]940895b2011-08-20 00:50:0546#include "content/common/request_extra_data.h"
[email protected]5fa3a062012-03-21 15:39:3447#include "content/common/socket_stream_handle_data.h"
[email protected]778574e2011-03-21 22:03:5048#include "content/common/view_messages.h"
[email protected]4e1eb3392012-05-18 00:08:0549#include "content/common/webmessageportchannel_impl.h"
[email protected]e091df82011-10-11 18:13:2150#include "content/public/common/bindings_policy.h"
[email protected]744c2a22012-03-15 18:42:0451#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4852#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2953#include "content/public/common/content_switches.h"
[email protected]35be7ec2012-02-12 20:42:5154#include "content/public/common/context_menu_params.h"
[email protected]8caadeb2011-11-22 02:45:2355#include "content/public/common/file_chooser_params.h"
[email protected]a1d29162011-10-14 17:14:0356#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3457#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0758#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3259#include "content/public/renderer/navigation_state.h"
[email protected]1ecbe862012-10-05 01:29:1460#include "content/public/renderer/password_form_conversion_utils.h"
[email protected]3a034ebb2011-10-03 19:19:4461#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3662#include "content/public/renderer/render_view_visitor.h"
[email protected]e6e56752012-08-10 00:46:0663#include "content/renderer/browser_plugin/browser_plugin.h"
64#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]cc510d7e2012-08-08 04:40:1065#include "content/renderer/browser_plugin/old/old_browser_plugin.h"
[email protected]14cf0f12012-06-18 17:15:5766#include "content/renderer/browser_plugin/old/browser_plugin_channel_manager.h"
67#include "content/renderer/browser_plugin/old/browser_plugin_constants.h"
68#include "content/renderer/browser_plugin/old/guest_to_embedder_channel.h"
[email protected]230b7ef2011-03-16 22:30:1969#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0270#include "content/renderer/devtools_agent.h"
[email protected]766a7082012-02-03 23:39:1571#include "content/renderer/dom_automation_controller.h"
[email protected]1910fe82012-05-10 00:04:1072#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
[email protected]498bc512012-09-21 21:50:0873#include "content/renderer/do_not_track_bindings.h"
[email protected]55722152011-03-22 01:33:5374#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1975#include "content/renderer/geolocation_dispatcher.h"
[email protected]84a83e192012-03-09 18:43:4076#include "content/renderer/gpu/compositor_thread.h"
[email protected]1842fe22012-08-13 23:24:3577#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]7d4481d12012-09-24 21:26:4778#include "content/renderer/gpu/compositor_software_output_device_gl_adapter.h"
[email protected]1784b2f2011-11-24 10:53:4879#include "content/renderer/idle_user_detector.h"
[email protected]c52b2892012-03-07 11:01:0280#include "content/renderer/input_tag_speech_dispatcher.h"
[email protected]07161902011-11-11 09:57:4281#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0282#include "content/renderer/load_progress_tracker.h"
[email protected]273558fb2012-01-12 15:03:5183#include "content/renderer/media/media_stream_dependency_factory.h"
84#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:4085#include "content/renderer/media/media_stream_impl.h"
[email protected]6048d512012-01-28 03:14:4886#include "content/renderer/media/render_audiosourceprovider.h"
[email protected]090f7312011-08-05 23:26:4087#include "content/renderer/media/render_media_log.h"
[email protected]6048d512012-01-28 03:14:4888#include "content/renderer/media/renderer_gpu_video_decoder_factories.h"
[email protected]ccee4862012-10-03 18:34:2689#include "content/renderer/media/rtc_peer_connection_handler.h"
[email protected]4a19be92011-09-22 14:25:0290#include "content/renderer/mhtml_generator.h"
[email protected]230b7ef2011-03-16 22:30:1991#include "content/renderer/notification_provider.h"
[email protected]6f516082011-03-17 19:15:3592#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0593#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4494#include "content/renderer/render_thread_impl.h"
[email protected]89054502012-06-03 10:29:2495#include "content/renderer/render_view_mouse_lock_dispatcher.h"
[email protected]2cff0052011-03-18 16:51:4496#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3297#include "content/renderer/renderer_accessibility.h"
[email protected]2a84f9d2012-06-05 21:50:4398#include "content/renderer/renderer_accessibility_complete.h"
99#include "content/renderer/renderer_accessibility_focus_only.h"
[email protected]663bd9e2011-03-21 01:07:01100#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]da8543762012-03-20 08:52:20101#include "content/renderer/renderer_webcolorchooser_impl.h"
[email protected]64d09222012-05-25 10:10:34102#include "content/renderer/speech_recognition_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:32103#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:19104#include "content/renderer/v8_value_converter_impl.h"
[email protected]0a35efc2012-03-13 17:28:13105#include "content/renderer/web_intents_host.h"
[email protected]663bd9e2011-03-21 01:07:01106#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:35107#include "content/renderer/webplugin_delegate_proxy.h"
108#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:49109#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41110#include "media/base/media_switches.h"
[email protected]b80322902012-03-06 01:33:50111#include "media/base/message_loop_factory.h"
[email protected]37136d162012-04-09 23:39:19112#include "media/filters/audio_renderer_impl.h"
[email protected]e1d69d762011-12-13 05:12:18113#include "media/filters/gpu_video_decoder.h"
[email protected]d1ef81d2012-07-24 11:39:36114#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29115#include "net/base/escape.h"
116#include "net/base/net_errors.h"
[email protected]18fb7a772012-09-20 19:25:09117#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]52c68652010-12-07 17:47:04118#include "net/http/http_util.h"
[email protected]1842fe22012-08-13 23:24:35119#include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutputSurface.h"
[email protected]8bd0fe62011-01-17 06:44:37120#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]f546640b2012-05-15 00:03:49121#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEvent.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h"
[email protected]be2510c02012-05-28 14:52:14123#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:37125#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:37127#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
129#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
130#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
131#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]4b1146bc2012-07-10 18:46:03132#include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h"
[email protected]8bd0fe62011-01-17 06:44:37133#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37134#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57135#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58136#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
[email protected]592e20b2012-01-20 05:53:44137#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
[email protected]8b5af492011-11-28 21:50:58138#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14139#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]4e1eb3392012-05-18 00:08:05140#include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannel.h"
[email protected]8bd0fe62011-01-17 06:44:37141#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19142#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37143#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36144#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37145#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
146#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
147#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37148#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37149#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
150#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
151#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17152#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37153#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]10e5cf12011-04-13 04:10:40154#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51155#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08156#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
157#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
158#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
159#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
160#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
[email protected]132e281a2012-07-31 18:32:44161#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPBody.h"
[email protected]9c4bf232011-12-15 02:25:08162#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
[email protected]50da23d02012-04-13 17:47:48163#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00Handler.h"
164#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00HandlerClient.h"
[email protected]273558fb2012-01-12 15:03:51165#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
166#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
[email protected]9c4bf232011-12-15 02:25:08167#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
168#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
[email protected]f546640b2012-05-15 00:03:49169#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerializedScriptValue.h"
[email protected]9c4bf232011-12-15 02:25:08170#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]5fa3a062012-03-21 15:39:34171#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSocketStreamHandle.h"
[email protected]e6e90dc2011-12-03 00:01:37172#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
173#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
174#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
175#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
176#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
177#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26178#include "third_party/skia/include/core/SkBitmap.h"
[email protected]ddb034b2012-06-26 20:31:39179#include "ui/base/dialogs/selected_file_info.h"
[email protected]08397d52011-02-05 01:53:38180#include "ui/gfx/native_widget_types.h"
181#include "ui/gfx/point.h"
182#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55183#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04184#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]b928936b2012-04-13 01:16:16185#include "webkit/dom_storage/dom_storage_types.h"
[email protected]25e18f82010-10-27 16:38:43186#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]18d5be92011-07-25 18:00:19187#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24188#include "webkit/glue/glue_serialize.h"
[email protected]3a3b75a2012-06-01 08:38:36189#include "webkit/glue/web_intent_service_data.h"
[email protected]851334d2012-06-15 22:39:31190#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07191#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29192#include "webkit/glue/webkit_glue.h"
[email protected]b9fd01ba2012-02-28 01:50:40193#include "webkit/glue/weburlresponse_extradata_impl.h"
[email protected]7e8b4d12012-01-20 23:39:51194#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
[email protected]a9288f52011-11-17 05:18:16195#include "webkit/media/webmediaplayer_impl.h"
[email protected]5f04c3532012-09-25 01:28:39196#include "webkit/media/webmediaplayer_ms.h"
[email protected]191eb3f72010-12-21 06:27:50197#include "webkit/plugins/npapi/plugin_list.h"
198#include "webkit/plugins/npapi/webplugin_delegate.h"
199#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
200#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52201#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29202
[email protected]25fb9b32012-04-27 03:21:55203#if defined(OS_ANDROID)
[email protected]20657a82012-08-21 20:23:03204#include "content/common/android/device_info.h"
205#include "content/renderer/android/address_detector.h"
206#include "content/renderer/android/content_detector.h"
207#include "content/renderer/android/email_detector.h"
208#include "content/renderer/android/phone_number_detector.h"
[email protected]dbd3d212012-07-13 02:17:22209#include "content/renderer/media/stream_texture_factory_impl_android.h"
[email protected]780fc8242012-09-19 20:28:52210#include "content/renderer/media/webmediaplayer_proxy_impl_android.h"
[email protected]20657a82012-08-21 20:23:03211#include "third_party/WebKit/Source/WebKit/chromium/public/WebHitTestResult.h"
[email protected]59363fc92012-09-05 03:46:31212#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoint.h"
213#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatRect.h"
214#include "ui/gfx/rect_f.h"
[email protected]780fc8242012-09-19 20:28:52215#include "webkit/media/android/media_player_bridge_manager_impl.h"
[email protected]25fb9b32012-04-27 03:21:55216#include "webkit/media/android/webmediaplayer_android.h"
[email protected]780fc8242012-09-19 20:28:52217#include "webkit/media/android/webmediaplayer_impl_android.h"
218#include "webkit/media/android/webmediaplayer_in_process_android.h"
[email protected]2d7b82c2012-06-01 05:57:50219#include "webkit/media/android/webmediaplayer_manager_android.h"
[email protected]25fb9b32012-04-27 03:21:55220#elif defined(OS_WIN)
[email protected]6c8afae52009-01-22 02:24:57221// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57222// * theming
[email protected]f78452f2012-05-15 02:07:52223#include "ui/base/native_theme/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03224#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37225#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]f78452f2012-05-15 02:07:52226#include "ui/base/native_theme/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33227#elif defined(OS_MACOSX)
228#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57229#endif
230
[email protected]9892b472010-09-16 00:23:42231using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08232using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21233using WebKit::WebApplicationCacheHost;
234using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26235using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41236using WebKit::WebColor;
237using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59238using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44239using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51240using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55241using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28242using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00243using WebKit::WebDocument;
[email protected]f546640b2012-05-15 00:03:49244using WebKit::WebDOMEvent;
245using WebKit::WebDOMMessageEvent;
[email protected]e80c73b2009-04-07 23:24:58246using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25247using WebKit::WebDragOperation;
248using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51249using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51250using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08251using WebKit::WebExternalPopupMenu;
252using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47253using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22254using WebKit::WebFileSystem;
255using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49256using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59257using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48258using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45259using WebKit::WebFrame;
[email protected]3306f262012-09-21 19:20:42260using WebKit::WebGestureEvent;
[email protected]7e8b4d12012-01-20 23:39:51261using WebKit::WebGraphicsContext3D;
[email protected]ca948a22009-06-25 19:36:17262using WebKit::WebHistoryItem;
[email protected]132e281a2012-07-31 18:32:44263using WebKit::WebHTTPBody;
[email protected]42054a252011-05-17 18:02:13264using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41265using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50266using WebKit::WebInputElement;
[email protected]3306f262012-09-21 19:20:42267using WebKit::WebInputEvent;
[email protected]ffc8bed2012-01-21 01:23:15268using WebKit::WebIntentRequest;
269using WebKit::WebIntentServiceInfo;
[email protected]3d9689372009-09-10 04:29:17270using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28271using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17272using WebKit::WebMediaPlayerClient;
[email protected]2b942c332012-04-25 16:26:26273using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:28274using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28275using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51276using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19277using WebKit::WebPageSerializer;
278using WebKit::WebPageSerializerClient;
[email protected]50da23d02012-04-13 17:47:48279using WebKit::WebPeerConnection00Handler;
280using WebKit::WebPeerConnection00HandlerClient;
281using WebKit::WebPeerConnectionHandler;
282using WebKit::WebPeerConnectionHandlerClient;
[email protected]3d9689372009-09-10 04:29:17283using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36284using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40285using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49286using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09287using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52288using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59289using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51290using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52291using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15292using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40293using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35294using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29295using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17296using WebKit::WebSecurityPolicy;
[email protected]f546640b2012-05-15 00:03:49297using WebKit::WebSerializedScriptValue;
[email protected]2fab253a2009-08-17 23:00:59298using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42299using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02300using WebKit::WebSize;
[email protected]5fa3a062012-03-21 15:39:34301using WebKit::WebSocketStreamHandle;
[email protected]bd92c3a2010-01-13 05:02:34302using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40303using WebKit::WebStorageQuotaCallbacks;
304using WebKit::WebStorageQuotaError;
305using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28306using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51307using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52308using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24309using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28310using WebKit::WebURL;
311using WebKit::WebURLError;
312using WebKit::WebURLRequest;
313using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28314using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03315using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28316using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26317using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26318using appcache::WebApplicationCacheHostImpl;
319using base::Time;
320using base::TimeDelta;
[email protected]007733c2011-11-17 00:34:07321using content::DocumentState;
[email protected]82ddba1c2011-10-04 00:15:32322using content::NavigationState;
[email protected]1ecbe862012-10-05 01:29:14323using content::PasswordForm;
[email protected]2a84f9d2012-06-05 21:50:43324using content::Referrer;
[email protected]380244092011-10-07 17:26:27325using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44326using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36327using content::RenderViewVisitor;
[email protected]2a84f9d2012-06-05 21:50:43328using content::RendererAccessibilityComplete;
329using content::RendererAccessibilityFocusOnly;
[email protected]8d86f13d2011-10-04 17:01:19330using content::V8ValueConverter;
[email protected]6fdd4182010-10-14 23:59:26331using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23332using webkit_glue::ResourceFetcher;
[email protected]6717bf272012-05-11 23:31:25333using webkit_glue::WebPreferences;
[email protected]b9fd01ba2012-02-28 01:50:40334using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33335
[email protected]20657a82012-08-21 20:23:03336#if defined(OS_ANDROID)
337using content::AddressDetector;
338using content::ContentDetector;
339using content::EmailDetector;
340using content::PhoneNumberDetector;
341using WebKit::WebContentDetectionResult;
[email protected]59363fc92012-09-05 03:46:31342using WebKit::WebFloatPoint;
343using WebKit::WebFloatRect;
[email protected]20657a82012-08-21 20:23:03344using WebKit::WebHitTestResult;
345#endif
346
initial.commit09911bf2008-07-26 23:55:29347//-----------------------------------------------------------------------------
348
[email protected]310ebd6302011-10-10 19:06:28349typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49350static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02351
[email protected]882daa92009-11-05 16:31:31352// Time, in seconds, we delay before sending content state changes (such as form
353// state and scroll position) to the browser. We delay sending changes to avoid
354// spamming the browser.
355// To avoid having tab/session restore require sending a message to get the
356// current content state during tab closing we use a shorter timeout for the
357// foreground renderer. This means there is a small window of time from which
358// content state is modified and not sent to session restore, but this is
359// better than having to wake up all renderers during shutdown.
360static const int kDelaySecondsForContentStateSyncHidden = 5;
361static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29362
[email protected]e99ef6f2011-10-16 01:13:00363static const size_t kExtraCharsBeforeAndAfterSelection = 100;
364
[email protected]0aa55312008-10-17 21:53:08365// The maximum number of popups that can be spawned from one page.
366static const int kMaximumNumberOfUnacknowledgedPopups = 25;
367
[email protected]c514d6372011-08-16 22:54:44368static const float kScalingIncrement = 0.1f;
369
[email protected]47578fa02011-11-02 19:34:41370static const float kScalingIncrementForGesture = 0.01f;
371
[email protected]20657a82012-08-21 20:23:03372#if defined(OS_ANDROID)
373// Delay between tapping in content and launching the associated android intent.
374// Used to allow users see what has been recognized as content.
375static const size_t kContentIntentDelayMilliseconds = 700;
376#endif
377
[email protected]f546640b2012-05-15 00:03:49378static RenderViewImpl* FromRoutingID(int32 routing_id) {
379 return static_cast<RenderViewImpl*>(
380 ChildThread::current()->ResolveRoute(routing_id));
381}
382
[email protected]0720b532012-08-28 19:23:37383static WebKit::WebFrame* FindFrameByID(WebKit::WebFrame* root, int frame_id) {
384 for (WebFrame* frame = root; frame; frame = frame->traverseNext(false)) {
385 if (frame->identifier() == frame_id)
386 return frame;
387 }
388 return NULL;
389}
390
[email protected]726985e22009-06-18 21:09:28391static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
392 WebVector<WebURL> urls;
393 ds->redirectChain(urls);
394 result->reserve(urls.size());
395 for (size_t i = 0; i < urls.size(); ++i)
396 result->push_back(urls[i]);
397}
398
[email protected]007733c2011-11-17 00:34:07399// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44400// the AltErrorPageResourceFetcher is reset.
401static void StopAltErrorPageFetcher(WebDataSource* data_source) {
402 if (data_source) {
[email protected]007733c2011-11-17 00:34:07403 DocumentState* document_state = DocumentState::FromDataSource(data_source);
404 if (document_state)
405 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44406 }
407}
408
[email protected]007733c2011-11-17 00:34:07409static bool IsReload(const ViewMsg_Navigate_Params& params) {
410 return
411 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
[email protected]7c16976c2012-08-04 02:38:23412 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE ||
413 params.navigation_type ==
414 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]007733c2011-11-17 00:34:07415}
416
[email protected]b9fd01ba2012-02-28 01:50:40417static WebReferrerPolicy GetReferrerPolicyFromRequest(
[email protected]ca662822012-05-11 17:53:59418 WebFrame* frame,
[email protected]445e1042011-12-03 21:03:15419 const WebURLRequest& request) {
420 return request.extraData() ?
421 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
[email protected]ca662822012-05-11 17:53:59422 frame->document().referrerPolicy();
[email protected]445e1042011-12-03 21:03:15423}
424
[email protected]b9fd01ba2012-02-28 01:50:40425static WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
426 const WebURLResponse& response) {
427 return static_cast<WebURLResponseExtraDataImpl*>(
428 response.extraData());
429}
430
[email protected]2149cc622012-02-14 01:12:12431NOINLINE static void CrashIntentionally() {
432 // NOTE(shess): Crash directly rather than using NOTREACHED() so
433 // that the signature is easier to triage in crash reports.
434 volatile int* zero = NULL;
435 *zero = 0;
436}
437
[email protected]8bf1048012012-02-08 01:22:18438static void MaybeHandleDebugURL(const GURL& url) {
439 if (!url.SchemeIs(chrome::kChromeUIScheme))
440 return;
441 if (url == GURL(chrome::kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12442 CrashIntentionally();
[email protected]8bf1048012012-02-08 01:22:18443 } else if (url == GURL(chrome::kChromeUIKillURL)) {
444 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
445 } else if (url == GURL(chrome::kChromeUIHangURL)) {
446 for (;;) {
447 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
448 }
449 } else if (url == GURL(chrome::kChromeUIShorthangURL)) {
450 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
451 }
452}
453
[email protected]fd3238af2012-05-22 18:55:30454// Returns false unless this is a top-level navigation.
455static bool IsTopLevelNavigation(WebFrame* frame) {
456 return frame->parent() == NULL;
457}
458
459// Returns false unless this is a top-level navigation that crosses origins.
460static bool IsNonLocalTopLevelNavigation(const GURL& url,
461 WebFrame* frame,
462 WebNavigationType type) {
463 if (!IsTopLevelNavigation(frame))
464 return false;
465
466 // Navigations initiated within Webkit are not sent out to the external host
467 // in the following cases.
468 // 1. The url scheme is not http/https
469 // 2. The origin of the url and the opener is the same in which case the
470 // opener relationship is maintained.
471 // 3. Reloads/form submits/back forward navigations
472 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
473 return false;
474
475 // Not interested in reloads/form submits/resubmits/back forward navigations.
476 if (type != WebKit::WebNavigationTypeReload &&
477 type != WebKit::WebNavigationTypeFormSubmitted &&
478 type != WebKit::WebNavigationTypeFormResubmitted &&
479 type != WebKit::WebNavigationTypeBackForward) {
480 // The opener relationship between the new window and the parent allows the
481 // new window to script the parent and vice versa. This is not allowed if
482 // the origins of the two domains are different. This can be treated as a
483 // top level navigation and routed back to the host.
484 WebKit::WebFrame* opener = frame->opener();
485 if (!opener) {
486 return true;
487 }
488
489 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
490 return true;
491 }
492 return false;
493}
494
[email protected]0720b532012-08-28 19:23:37495// Recursively walks the frame tree and serializes it to JSON as described in
496// the comment for ViewMsg_UpdateFrameTree. If |exclude_frame_subtree| is not
497// NULL, the subtree for the frame is not included in the serialized form.
498// This is used when a frame is going to be removed from the tree.
499static void ConstructFrameTree(WebKit::WebFrame* frame,
500 WebKit::WebFrame* exclude_frame_subtree,
501 base::DictionaryValue* dict) {
502 dict->SetString(content::kFrameTreeNodeNameKey,
503 UTF16ToUTF8(frame->assignedName()).c_str());
504 dict->SetInteger(content::kFrameTreeNodeIdKey, frame->identifier());
505
506 WebFrame* child = frame->firstChild();
507 ListValue* children = new ListValue();
508 for (; child; child = child->nextSibling()) {
509 if (child == exclude_frame_subtree)
510 continue;
511
512 base::DictionaryValue* d = new base::DictionaryValue();
513 ConstructFrameTree(child, exclude_frame_subtree, d);
514 children->Append(d);
515 }
516 if (children->GetSize() > 0)
517 dict->Set(content::kFrameTreeNodeSubtreeKey, children);
518}
519
initial.commit09911bf2008-07-26 23:55:29520///////////////////////////////////////////////////////////////////////////////
521
[email protected]310ebd6302011-10-10 19:06:28522struct RenderViewImpl::PendingFileChooser {
[email protected]8caadeb2011-11-22 02:45:23523 PendingFileChooser(const content::FileChooserParams& p,
[email protected]cdaf8d02010-03-30 19:52:47524 WebFileChooserCompletion* c)
525 : params(p),
526 completion(c) {
527 }
[email protected]8caadeb2011-11-22 02:45:23528 content::FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47529 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
530};
531
[email protected]217690d2012-01-27 07:33:11532namespace {
533
534class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
535 public:
[email protected]82114f52012-03-20 22:53:41536 explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget)
[email protected]217690d2012-01-27 07:33:11537 : webwidget_(webwidget) {}
538
539 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
540 if (succeeded)
541 webwidget_->didAcquirePointerLock();
542 else
543 webwidget_->didNotAcquirePointerLock();
544 }
545
546 virtual void OnMouseLockLost() OVERRIDE {
547 webwidget_->didLosePointerLock();
548 }
549
550 virtual bool HandleMouseLockedInputEvent(
551 const WebKit::WebMouseEvent &event) OVERRIDE {
552 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
553 return false;
554 }
555
556 private:
557 WebKit::WebWidget* webwidget_;
558};
559
[email protected]86cd9472012-02-03 19:51:05560int64 ExtractPostId(const WebHistoryItem& item) {
561 if (item.isNull())
562 return -1;
563
564 if (item.httpBody().isNull())
565 return -1;
566
567 return item.httpBody().identifier();
568}
569
[email protected]217690d2012-01-27 07:33:11570} // namespace
571
[email protected]daf82f82011-10-31 22:35:31572RenderViewImpl::RenderViewImpl(
573 gfx::NativeViewId parent_hwnd,
574 int32 opener_id,
575 const content::RendererPreferences& renderer_prefs,
576 const WebPreferences& webkit_prefs,
577 SharedRenderViewCounter* counter,
578 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56579 int32 surface_id,
[email protected]daf82f82011-10-31 22:35:31580 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46581 const string16& frame_name,
[email protected]14392a52012-05-02 20:28:44582 bool is_renderer_created,
583 bool swapped_out,
[email protected]6fd35b72012-03-01 19:46:41584 int32 next_page_id,
[email protected]842f10652012-06-06 01:54:04585 const WebKit::WebScreenInfo& screen_info,
[email protected]cb25aa12012-08-07 19:13:43586 content::old::GuestToEmbedderChannel* guest_to_embedder_channel,
[email protected]3e3c4522012-04-13 21:16:29587 AccessibilityMode accessibility_mode)
[email protected]842f10652012-06-06 01:54:04588 : RenderWidget(WebKit::WebPopupTypeNone, screen_info, swapped_out),
[email protected]676126f72011-01-15 00:03:51589 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02590 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09591 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02592 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24593 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21594 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02595 opened_by_user_gesture_(true),
596 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24597 page_id_(-1),
598 last_page_id_sent_to_browser_(-1),
[email protected]74ce1ad2011-12-16 21:51:46599 next_page_id_(next_page_id),
[email protected]3cc72b12010-03-18 23:03:00600 history_list_offset_(-1),
601 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02602 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55603 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31604 cached_is_main_frame_pinned_to_left_(false),
605 cached_is_main_frame_pinned_to_right_(false),
606 cached_has_main_frame_horizontal_scrollbar_(false),
607 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]3354d3e2010-06-10 19:53:02608 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51609 geolocation_dispatcher_(NULL),
[email protected]c52b2892012-03-07 11:01:02610 input_tag_speech_dispatcher_(NULL),
[email protected]64d09222012-05-25 10:10:34611 speech_recognition_dispatcher_(NULL),
[email protected]676126f72011-01-15 00:03:51612 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51613 media_stream_dispatcher_(NULL),
[email protected]1bc65a42012-04-23 09:31:25614 media_stream_impl_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41615 devtools_agent_(NULL),
[email protected]2a84f9d2012-06-05 21:50:43616 accessibility_mode_(AccessibilityModeOff),
[email protected]063afcb2011-09-29 07:54:32617 renderer_accessibility_(NULL),
[email protected]7e9c5bb02012-05-14 13:58:31618 java_bridge_dispatcher_(NULL),
[email protected]217690d2012-01-27 07:33:11619 mouse_lock_dispatcher_(NULL),
[email protected]20657a82012-08-21 20:23:03620#if defined(OS_ANDROID)
621 expected_content_intent_id_(0),
[email protected]780fc8242012-09-19 20:28:52622 media_player_proxy_(NULL),
[email protected]55750b32012-09-21 14:05:03623 synchronous_find_active_match_ordinal_(-1),
[email protected]20657a82012-08-21 20:23:03624#endif
[email protected]4fb60142011-08-09 02:22:08625 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18626 handling_select_range_(false),
627#if defined(OS_WIN)
628 focused_plugin_id_(-1),
629#endif
[email protected]468e4902012-05-23 01:49:31630 guest_to_embedder_channel_(guest_to_embedder_channel),
631 guest_pp_instance_(0),
632 guest_uninitialized_context_(NULL),
[email protected]0720b532012-08-28 19:23:37633 updating_frame_tree_(false),
634 pending_frame_tree_update_(false),
635 target_process_id_(0),
636 target_routing_id_(0),
[email protected]ef5e98e2011-12-06 09:49:18637 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]ce2b28e2012-08-09 15:53:57638 set_throttle_input_events(renderer_prefs.throttle_input_events);
[email protected]676126f72011-01-15 00:03:51639 routing_id_ = routing_id;
[email protected]9f4f3322012-01-18 22:29:56640 surface_id_ = surface_id;
[email protected]14392a52012-05-02 20:28:44641 if (opener_id != MSG_ROUTING_NONE && is_renderer_created)
[email protected]676126f72011-01-15 00:03:51642 opener_id_ = opener_id;
643
[email protected]74ce1ad2011-12-16 21:51:46644 // Ensure we start with a valid next_page_id_ from the browser.
645 DCHECK_GE(next_page_id_, 0);
646
[email protected]21b3a6ae2011-11-30 00:45:29647#if defined(ENABLE_NOTIFICATIONS)
648 notification_provider_ = new NotificationProvider(this);
649#else
650 notification_provider_ = NULL;
651#endif
652
[email protected]11fee2332011-03-29 20:36:35653 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11654 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35655
[email protected]20657a82012-08-21 20:23:03656 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
657
658#if defined(OS_ANDROID)
659 scoped_ptr<content::DeviceInfo> device_info(new content::DeviceInfo());
660
[email protected]43b06002012-10-11 17:13:26661 webview()->setDeviceScaleFactor(device_info->GetDPIScale());
662
[email protected]20657a82012-08-21 20:23:03663 const std::string region_code =
664 command_line.HasSwitch(switches::kNetworkCountryIso)
665 ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso)
666 : device_info->GetNetworkCountryIso();
667 content_detectors_.push_back(linked_ptr<ContentDetector>(
668 new AddressDetector()));
669 content_detectors_.push_back(linked_ptr<ContentDetector>(
670 new PhoneNumberDetector(region_code)));
671 content_detectors_.push_back(linked_ptr<ContentDetector>(
672 new EmailDetector()));
673#endif
674
[email protected]676126f72011-01-15 00:03:51675 if (counter) {
676 shared_popup_counter_ = counter;
[email protected]14392a52012-05-02 20:28:44677 // Only count this if it isn't swapped out upon creation.
678 if (!swapped_out)
679 shared_popup_counter_->data++;
[email protected]676126f72011-01-15 00:03:51680 decrement_shared_popup_at_destruction_ = true;
681 } else {
682 shared_popup_counter_ = new SharedRenderViewCounter(0);
683 decrement_shared_popup_at_destruction_ = false;
684 }
685
[email protected]380244092011-10-07 17:26:27686 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51687 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47688 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51689 AddRef();
690
691 // If this is a popup, we must wait for the CreatingNew_ACK message before
692 // completing initialization. Otherwise, we can finish it now.
[email protected]468e4902012-05-23 01:49:31693 if (!guest_to_embedder_channel && opener_id_ == MSG_ROUTING_NONE) {
[email protected]676126f72011-01-15 00:03:51694 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55695 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51696 }
697
[email protected]34c61bd52011-05-02 19:38:33698 g_view_map.Get().insert(std::make_pair(webview(), this));
[email protected]60051ec2012-06-08 22:40:57699 webview()->setDeviceScaleFactor(device_scale_factor_);
[email protected]34c61bd52011-05-02 19:38:33700 webkit_preferences_.Apply(webview());
701 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35702 if (!frame_name.empty())
703 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33704 webview()->settings()->setMinimumTimerInterval(
705 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
706 webkit_glue::kForegroundTabTimerInterval);
707
708 OnSetRendererPrefs(renderer_prefs);
709
[email protected]676126f72011-01-15 00:03:51710 host_window_ = parent_hwnd;
711
[email protected]4fb0f202012-05-30 22:44:53712#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02713 if (!media_stream_dispatcher_)
714 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32715#endif
[email protected]735873d2012-01-25 23:31:02716
[email protected]8f6a3b852011-07-19 16:48:56717 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32718#if defined(OS_MACOSX)
719 new TextInputClientObserver(this);
720#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56721
[email protected]2d7b82c2012-06-01 05:57:50722#if defined(OS_ANDROID)
723 media_player_manager_.reset(
724 new webkit_media::WebMediaPlayerManagerAndroid());
725#endif
726
[email protected]217690d2012-01-27 07:33:11727 // The next group of objects all implement RenderViewObserver, so are deleted
728 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41729 devtools_agent_ = new DevToolsAgent(this);
[email protected]89054502012-06-03 10:29:24730 mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
[email protected]0fc7dea72012-02-09 03:47:40731 intents_host_ = new WebIntentsHost(this);
[email protected]063afcb2011-09-29 07:54:32732
[email protected]2a84f9d2012-06-05 21:50:43733 // Create renderer_accessibility_ if needed.
734 OnSetAccessibilityMode(accessibility_mode);
735
[email protected]1784b2f2011-11-24 10:53:48736 new IdleUserDetector(this);
737
[email protected]766a7082012-02-03 23:39:15738 if (command_line.HasSwitch(switches::kDomAutomationController))
739 enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION;
740
[email protected]5b52cd2f712012-03-28 02:12:48741 ProcessViewLayoutFlags(command_line);
[email protected]7ddea9802012-02-22 23:08:05742
[email protected]e48869a2011-04-01 19:56:03743 content::GetContentClient()->renderer()->RenderViewCreated(this);
[email protected]14392a52012-05-02 20:28:44744
745 // If we have an opener_id but we weren't created by a renderer, then
746 // it's the browser asking us to set our opener to another RenderView.
[email protected]14392a52012-05-02 20:28:44747 if (opener_id != MSG_ROUTING_NONE && !is_renderer_created) {
[email protected]f546640b2012-05-15 00:03:49748 RenderViewImpl* opener_view = FromRoutingID(opener_id);
749 if (opener_view)
750 webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
[email protected]14392a52012-05-02 20:28:44751 }
752
753 // If we are initially swapped out, navigate to kSwappedOutURL.
754 // This ensures we are in a unique origin that others cannot script.
755 if (is_swapped_out_)
[email protected]0720b532012-08-28 19:23:37756 NavigateToSwappedOutURL(webview()->mainFrame());
initial.commit09911bf2008-07-26 23:55:29757}
758
[email protected]310ebd6302011-10-10 19:06:28759RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03760 history_page_ids_.clear();
761
[email protected]0aa55312008-10-17 21:53:08762 if (decrement_shared_popup_at_destruction_)
763 shared_popup_counter_->data--;
764
[email protected]a1128322009-10-06 18:38:46765 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47766 while (!file_chooser_completions_.empty()) {
767 if (file_chooser_completions_.front()->completion) {
768 file_chooser_completions_.front()->completion->didChooseFile(
769 WebVector<WebString>());
770 }
771 file_chooser_completions_.pop_front();
772 }
[email protected]a1128322009-10-06 18:38:46773
[email protected]83dde542009-09-11 20:59:55774#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11775 // Destroy all fake plugin window handles on the browser side.
776 while (!fake_plugin_window_handles_.empty()) {
777 // Make sure no NULL plugin window handles were inserted into this list.
778 DCHECK(*fake_plugin_window_handles_.begin());
779 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
780 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
781 }
[email protected]83dde542009-09-11 20:59:55782#endif
[email protected]98324892009-09-09 21:16:05783
[email protected]60c42a8c72009-10-09 04:08:59784#ifndef NDEBUG
785 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49786 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59787 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
788 DCHECK_NE(this, it->second) << "Failed to call Close?";
789#endif
[email protected]676126f72011-01-15 00:03:51790
[email protected]310ebd6302011-10-10 19:06:28791 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51792 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59793}
794
795/*static*/
[email protected]310ebd6302011-10-10 19:06:28796RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31797 ViewMap* views = g_view_map.Pointer();
798 ViewMap::iterator it = views->find(webview);
799 return it == views->end() ? NULL : it->second;
800}
801
802/*static*/
803content::RenderView*
804 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28805 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31806}
807
808/*static*/
809void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49810 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59811 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
812 if (!visitor->Visit(it->second))
813 return;
814 }
815}
816
817/*static*/
[email protected]310ebd6302011-10-10 19:06:28818RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15819 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08820 int32 opener_id,
[email protected]daf82f82011-10-31 22:35:31821 const content::RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08822 const WebPreferences& webkit_prefs,
823 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34824 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56825 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26826 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46827 const string16& frame_name,
[email protected]14392a52012-05-02 20:28:44828 bool is_renderer_created,
829 bool swapped_out,
[email protected]6fd35b72012-03-01 19:46:41830 int32 next_page_id,
[email protected]842f10652012-06-06 01:54:04831 const WebKit::WebScreenInfo& screen_info,
[email protected]cb25aa12012-08-07 19:13:43832 content::old::GuestToEmbedderChannel* guest_to_embedder_channel,
[email protected]3e3c4522012-04-13 21:16:29833 AccessibilityMode accessibility_mode) {
initial.commit09911bf2008-07-26 23:55:29834 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28835 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51836 parent_hwnd,
837 opener_id,
838 renderer_prefs,
839 webkit_prefs,
840 counter,
841 routing_id,
[email protected]9f4f3322012-01-18 22:29:56842 surface_id,
[email protected]676126f72011-01-15 00:03:51843 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46844 frame_name,
[email protected]14392a52012-05-02 20:28:44845 is_renderer_created,
846 swapped_out,
[email protected]6fd35b72012-03-01 19:46:41847 next_page_id,
[email protected]842f10652012-06-06 01:54:04848 screen_info,
[email protected]468e4902012-05-23 01:49:31849 guest_to_embedder_channel,
[email protected]3e3c4522012-04-13 21:16:29850 accessibility_mode);
initial.commit09911bf2008-07-26 23:55:29851}
852
[email protected]310ebd6302011-10-10 19:06:28853void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51854 observers_.AddObserver(observer);
855}
856
[email protected]310ebd6302011-10-10 19:06:28857void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
858 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51859 observers_.RemoveObserver(observer);
860}
861
[email protected]310ebd6302011-10-10 19:06:28862WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26863 return static_cast<WebKit::WebView*>(webwidget());
864}
865
[email protected]310ebd6302011-10-10 19:06:28866void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40867 if (!enabled) {
868 load_progress_tracker_.reset(NULL);
869 return;
870 }
871 if (load_progress_tracker_ == NULL)
872 load_progress_tracker_.reset(new LoadProgressTracker(this));
873}
874
[email protected]cb25aa12012-08-07 19:13:43875content::old::GuestToEmbedderChannel*
[email protected]7900bfdb2012-05-24 19:31:24876 RenderViewImpl::GetGuestToEmbedderChannel() const {
877 return guest_to_embedder_channel_;
878}
879
880void RenderViewImpl::SetGuestToEmbedderChannel(
[email protected]cb25aa12012-08-07 19:13:43881 content::old::GuestToEmbedderChannel* channel) {
[email protected]7900bfdb2012-05-24 19:31:24882 guest_to_embedder_channel_ = channel;
883}
884
[email protected]310ebd6302011-10-10 19:06:28885void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51886 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29887}
888
[email protected]310ebd6302011-10-10 19:06:28889void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26890 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30891 // If the renderer is visible, set initial visibility and focus state.
892 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34893#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30894 delegate->SetContainerVisibility(true);
895 if (webview() && webview()->isActive())
896 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34897#endif
[email protected]49232292010-09-03 19:07:30898 }
[email protected]784ea1ab2010-09-18 00:02:34899 // Plugins start assuming the content has focus (so that they work in
900 // environments where RenderView isn't hosting them), so we always have to
901 // set the initial state. See webplugin_delegate_impl.h for details.
902 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26903}
904
[email protected]310ebd6302011-10-10 19:06:28905void RenderViewImpl::UnregisterPluginDelegate(
906 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26907 plugin_delegates_.erase(delegate);
908}
[email protected]d8fd6fa2010-02-01 15:54:26909
[email protected]310ebd6302011-10-10 19:06:28910bool RenderViewImpl::GetPluginInfo(const GURL& url,
911 const GURL& page_url,
912 const std::string& mime_type,
913 webkit::WebPluginInfo* plugin_info,
914 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08915 bool found = false;
916 Send(new ViewHostMsg_GetPluginInfo(
917 routing_id_, url, page_url, mime_type, &found, plugin_info,
918 actual_mime_type));
919 return found;
920}
921
[email protected]7a1ec28a2012-03-28 21:10:24922void RenderViewImpl::TransferActiveWheelFlingAnimation(
923 const WebKit::WebActiveWheelFlingParameters& params) {
924 if (webview())
925 webview()->transferActiveWheelFlingAnimation(params);
926}
927
[email protected]8fe8f742012-06-14 00:36:08928bool RenderViewImpl::HasIMETextFocus() {
929 return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
930}
931
[email protected]310ebd6302011-10-10 19:06:28932bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27933 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27934 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41935 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26936
[email protected]676126f72011-01-15 00:03:51937 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
938 RenderViewObserver* observer;
939 while ((observer = it.GetNext()) != NULL)
940 if (observer->OnMessageReceived(message))
941 return true;
[email protected]b2abac72009-02-26 12:39:28942
[email protected]a95986a82010-12-24 06:19:28943 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40944 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28945 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29946 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
947 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56948 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29949 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
950 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
951 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
952 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
953 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15954 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29955 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
956 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
957 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]45a599062012-09-07 20:09:06958 IPC_MESSAGE_HANDLER(ViewMsg_ReplaceAll, OnReplaceAll)
959 IPC_MESSAGE_HANDLER(ViewMsg_Unselect, OnUnselect)
960 IPC_MESSAGE_HANDLER(ViewMsg_SetEditableSelectionOffsets,
961 OnSetEditableSelectionOffsets)
962 IPC_MESSAGE_HANDLER(ViewMsg_SetCompositionFromExistingText,
963 OnSetCompositionFromExistingText)
964 IPC_MESSAGE_HANDLER(ViewMsg_ExtendSelectionAndDelete,
965 OnExtendSelectionAndDelete)
[email protected]4fb60142011-08-09 02:22:08966 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29967 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15968 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29969 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49970 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
[email protected]630e26b2008-10-14 22:55:17971 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17972 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41973 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54974 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
975 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29976 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18977 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
978 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29979 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]f546640b2012-05-15 00:03:49980 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
[email protected]1810e132009-03-24 23:35:48981 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55982 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
983 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
984 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
985 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
986 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
987 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
988 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45989 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40990 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29991 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19992 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
993 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29994 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
995 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
996 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51997 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
998 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29999 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:041000 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:151001 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:291002 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1003 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:081004 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
1005 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:001006 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:161007 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:141008 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:251009 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1010 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:471011 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:341012 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:101013 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1014 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511015 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:561016 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]77829642012-05-15 14:47:171017 IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent,
1018 OnOrientationChangeEvent)
[email protected]81375e872012-01-11 21:40:361019 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:341020 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]7a17bac02012-03-07 21:58:121021 IPC_MESSAGE_HANDLER(ViewMsg_SetNavigationStartTime,
1022 OnSetNavigationStartTime)
[email protected]446705872009-09-10 07:22:481023 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:331024 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:331025 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
1026 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:241027 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:421028 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
1029 OnPpapiBrokerChannelCreated)
[email protected]d8415ad92012-08-23 14:40:501030 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerPermissionResult,
1031 OnPpapiBrokerPermissionResult)
[email protected]18d5be92011-07-25 18:00:191032 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1033 OnGetAllSavableResourceLinksForCurrentPage)
1034 IPC_MESSAGE_HANDLER(
1035 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1036 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]521b2482011-01-15 00:10:101037 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:511038 // TODO(viettrungluu): Move to a separate message filter.
[email protected]9e1ad4b2011-08-14 16:49:191039 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
1040 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:181041 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]7f3c7af2011-10-20 22:52:511042 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]2a84f9d2012-06-05 21:50:431043 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode)
[email protected]0720b532012-08-28 19:23:371044 IPC_MESSAGE_HANDLER(ViewMsg_UpdateFrameTree, OnUpdatedFrameTree)
[email protected]55750b32012-09-21 14:05:031045#if defined(OS_ANDROID)
1046 IPC_MESSAGE_HANDLER(ViewMsg_ActivateNearestFindResult,
1047 OnActivateNearestFindResult)
1048 IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects)
1049 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
1050 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewMsg_SynchronousFind, OnSynchronousFind)
[email protected]9b7d11e2012-10-08 19:24:141051 IPC_MESSAGE_HANDLER(ViewMsg_UndoScrollFocusedEditableNodeIntoView,
1052 OnUndoScrollFocusedEditableNodeIntoRect)
[email protected]55750b32012-09-21 14:05:031053#elif defined(OS_MACOSX)
1054 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
1055 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1056 OnPluginImeCompositionCompleted)
1057 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1058 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
1059 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
1060 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
1061#endif
[email protected]9e1ad4b2011-08-14 16:49:191062
initial.commit09911bf2008-07-26 23:55:291063 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281064 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291065 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:401066
1067 if (!msg_is_ok) {
1068 // The message had a handler, but its deserialization failed.
1069 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:281070 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:401071 }
1072
[email protected]a95986a82010-12-24 06:19:281073 return handled;
initial.commit09911bf2008-07-26 23:55:291074}
1075
[email protected]310ebd6302011-10-10 19:06:281076void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]7900bfdb2012-05-24 19:31:241077 // If we don't have guest-to-embedder channel associated with this RenderView
1078 // but we need one, grab one now.
1079 if (!params.embedder_channel_name.empty() && !GetGuestToEmbedderChannel()) {
[email protected]cb25aa12012-08-07 19:13:431080 content::old::GuestToEmbedderChannel* embedder_channel =
[email protected]7900bfdb2012-05-24 19:31:241081 RenderThreadImpl::current()->browser_plugin_channel_manager()->
1082 GetChannelByName(params.embedder_channel_name);
1083 DCHECK(embedder_channel);
1084 SetGuestToEmbedderChannel(embedder_channel);
1085 host_window_set_ = false;
1086 // TODO(fsamuel): This is test code. Need to find a better way to tell
1087 // a WebView to drop its context. This needs to change in
1088 // GuestToEmbedderChannel::OnContextLost.
1089 GetWebView()->loseCompositorContext(1);
1090 RenderThreadImpl::current()->browser_plugin_channel_manager()->
1091 ReportChannelToEmbedder(this,
1092 embedder_channel->embedder_channel_handle(),
1093 params.embedder_channel_name,
1094 params.embedder_container_id);
1095 }
[email protected]8bf1048012012-02-08 01:22:181096 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:291097 if (!webview())
1098 return;
1099
[email protected]440a0e52011-09-13 17:38:581100 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
1101
[email protected]007733c2011-11-17 00:34:071102 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:031103
1104 // If this is a stale back/forward (due to a recent navigation the browser
1105 // didn't know about), ignore it.
1106 if (IsBackForwardToStaleEntry(params, is_reload))
1107 return;
1108
[email protected]992db4c2011-05-12 15:37:151109 // Swap this renderer back in if necessary.
[email protected]961541a92012-06-01 21:15:281110 if (is_swapped_out_) {
1111 // We marked the view as hidden when swapping the view out, so be sure to
1112 // reset the visibility state before navigating to the new URL.
1113 webview()->setVisibilityState(visibilityState(), false);
[email protected]992db4c2011-05-12 15:37:151114 SetSwappedOut(false);
[email protected]961541a92012-06-01 21:15:281115 }
[email protected]992db4c2011-05-12 15:37:151116
[email protected]3cc72b12010-03-18 23:03:001117 history_list_offset_ = params.current_history_list_offset;
1118 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:031119 if (history_list_length_ >= 0)
1120 history_page_ids_.resize(history_list_length_, -1);
1121 if (params.pending_history_list_offset >= 0 &&
1122 params.pending_history_list_offset < history_list_length_)
1123 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:001124
[email protected]38b592902011-04-16 02:08:421125 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:291126
[email protected]26aa0482009-09-30 16:55:271127 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451128 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291129 // We cannot reload if we do not have any history state. This happens, for
1130 // example, when recovering from a crash. Our workaround here is a bit of
1131 // a hack since it means that reload after a crashed tab does not cause an
1132 // end-to-end cache validation.
1133 is_reload = false;
1134 }
1135
[email protected]007733c2011-11-17 00:34:071136 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
1137 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:501138
[email protected]04d3c6e2009-05-22 17:00:131139 // If we are reloading, then WebKit will use the history state of the current
1140 // page, so we should just ignore any given history state. Otherwise, if we
1141 // have history state, then we need to navigate to it, which corresponds to a
1142 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551143 if (is_reload) {
[email protected]7c16976c2012-08-04 02:38:231144 bool reload_original_url =
1145 (params.navigation_type ==
1146 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]ecbf10d2010-02-18 13:03:291147 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:021148 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]7c16976c2012-08-04 02:38:231149
1150 if (reload_original_url)
1151 main_frame->reloadWithOverrideURL(params.url, true);
1152 else
1153 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551154 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131155 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581156 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:451157 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171158 webkit_glue::HistoryItemFromString(params.state));
[email protected]d1ef81d2012-07-24 11:39:361159 } else if (!params.base_url_for_data_url.is_empty()) {
1160 // A loadData request with a specified base URL.
1161 std::string mime_type, charset, data;
1162 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) {
1163 main_frame->loadData(
1164 WebData(data.c_str(), data.length()),
1165 WebString::fromUTF8(mime_type),
1166 WebString::fromUTF8(charset),
1167 params.base_url_for_data_url,
1168 params.history_url_for_data_url,
1169 false);
1170 } else {
1171 CHECK(false) <<
1172 "Invalid URL passed: " << params.url.possibly_invalid_spec();
1173 }
[email protected]04d3c6e2009-05-22 17:00:131174 } else {
1175 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281176 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291177
[email protected]e6f546c32009-07-01 17:12:551178 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:231179 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131180
[email protected]dd7daa82009-08-10 05:46:451181 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551182 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131183
[email protected]445e1042011-12-03 21:03:151184 if (params.referrer.url.is_valid()) {
1185 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
1186 params.referrer.policy,
1187 params.url,
1188 WebString::fromUTF8(params.referrer.url.spec()));
1189 if (!referrer.isEmpty())
1190 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:281191 }
[email protected]04d3c6e2009-05-22 17:00:131192
[email protected]52c68652010-12-07 17:47:041193 if (!params.extra_headers.empty()) {
1194 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1195 params.extra_headers.end(), "\n");
1196 i.GetNext(); ) {
1197 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1198 WebString::fromUTF8(i.values()));
1199 }
1200 }
[email protected]132e281a2012-07-31 18:32:441201
1202 if (params.is_post) {
1203 request.setHTTPMethod(WebString::fromUTF8("POST"));
1204
1205 // Set post data.
1206 WebHTTPBody http_body;
1207 http_body.initialize();
1208 http_body.appendData(WebData(
1209 reinterpret_cast<const char*>(
1210 &params.browser_initiated_post_data.front()),
1211 params.browser_initiated_post_data.size()));
1212 request.setHTTPBody(http_body);
1213 }
1214
[email protected]dd7daa82009-08-10 05:46:451215 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501216 }
1217
[email protected]77f17a82009-05-21 04:42:541218 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:071219 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:291220}
1221
[email protected]310ebd6302011-10-10 19:06:281222bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:031223 const ViewMsg_Navigate_Params& params,
1224 bool is_reload) {
1225 // Make sure this isn't a back/forward to an entry we have already cropped
1226 // or replaced from our history, before the browser knew about it. If so,
1227 // a new navigation has committed in the mean time, and we can ignore this.
1228 bool is_back_forward = !is_reload && !params.state.empty();
1229
1230 // Note: if the history_list_length_ is 0 for a back/forward, we must be
1231 // restoring from a previous session. We'll update our state in OnNavigate.
1232 if (!is_back_forward || history_list_length_ <= 0)
1233 return false;
1234
1235 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
1236
1237 // Check for whether the forward history has been cropped due to a recent
1238 // navigation the browser didn't know about.
1239 if (params.pending_history_list_offset >= history_list_length_)
1240 return true;
1241
1242 // Check for whether this entry has been replaced with a new one.
1243 int expected_page_id =
1244 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:441245 if (expected_page_id > 0 && params.page_id != expected_page_id) {
1246 if (params.page_id < expected_page_id)
1247 return true;
1248
1249 // Otherwise we've removed an earlier entry and should have shifted all
1250 // entries left. For now, it's ok to lazily update the list.
1251 // TODO(creis): Notify all live renderers when we remove entries from
1252 // the front of the list, so that we don't hit this case.
1253 history_page_ids_[params.pending_history_list_offset] = params.page_id;
1254 }
[email protected]d466b8a2011-07-15 21:48:031255
1256 return false;
1257}
1258
initial.commit09911bf2008-07-26 23:55:291259// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:281260void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:441261 if (webview()) {
1262 WebFrame* main_frame = webview()->mainFrame();
1263 // Stop the alt error page fetcher. If we let it continue it may complete
1264 // and cause RenderViewHostManager to swap to this RenderView, even though
1265 // it may no longer be active.
1266 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
1267 StopAltErrorPageFetcher(main_frame->dataSource());
1268 main_frame->stopLoading();
1269 }
initial.commit09911bf2008-07-26 23:55:291270}
1271
[email protected]ecbf10d2010-02-18 13:03:291272// Reload current focused frame.
1273// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:281274void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291275 if (webview() && webview()->focusedFrame()) {
1276 // We always obey the cache (ignore_cache=false) here.
1277 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1278 // a cache-ignoring reload of the frame.
1279 webview()->focusedFrame()->reload(false);
1280 }
[email protected]1dda4022010-01-28 18:24:561281}
1282
[email protected]310ebd6302011-10-10 19:06:281283void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271284 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291285}
1286
[email protected]310ebd6302011-10-10 19:06:281287void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:251288 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271289 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251290 return;
1291
[email protected]26aa0482009-09-30 16:55:271292 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451293 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251294}
1295
[email protected]310ebd6302011-10-10 19:06:281296void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291297 // Check if there is a targeturl waiting to be sent.
1298 if (target_url_status_ == TARGET_PENDING) {
1299 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1300 pending_target_url_));
1301 }
1302
1303 target_url_status_ = TARGET_NONE;
1304}
1305
[email protected]310ebd6302011-10-10 19:06:281306void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:291307 if (!webview())
1308 return;
1309
[email protected]26aa0482009-09-30 16:55:271310 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:291311}
1312
[email protected]310ebd6302011-10-10 19:06:281313void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:291314 if (!webview())
1315 return;
1316
[email protected]26aa0482009-09-30 16:55:271317 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:291318}
1319
[email protected]310ebd6302011-10-10 19:06:281320void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:291321 if (!webview())
1322 return;
1323
[email protected]26aa0482009-09-30 16:55:271324 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:291325}
1326
[email protected]310ebd6302011-10-10 19:06:281327void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291328 if (!webview())
1329 return;
1330
[email protected]f6b1856b2011-06-29 22:02:531331 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
1332 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:291333}
1334
[email protected]c0cc3092009-09-12 08:27:271335#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281336void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:351337 if (!webview())
1338 return;
1339
1340 // Since the find pasteboard supports only plain text, this can be simpler
1341 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271342 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351343 if (frame->hasSelection()) {
1344 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:271345 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:171346 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:351347 }
[email protected]a954bf72009-09-12 07:30:351348}
[email protected]c0cc3092009-09-12 08:27:271349#endif
[email protected]a954bf72009-09-12 07:30:351350
[email protected]310ebd6302011-10-10 19:06:281351void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291352 if (!webview())
1353 return;
1354
[email protected]26aa0482009-09-30 16:55:271355 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:291356}
1357
[email protected]44bf7002011-10-16 02:46:151358void RenderViewImpl::OnPasteAndMatchStyle() {
1359 if (!webview())
1360 return;
1361
1362 webview()->focusedFrame()->executeCommand(
1363 WebString::fromUTF8("PasteAndMatchStyle"));
1364}
1365
[email protected]310ebd6302011-10-10 19:06:281366void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291367 if (!webview())
1368 return;
1369
[email protected]1ff7a032010-02-03 02:46:031370 WebFrame* frame = webview()->focusedFrame();
1371 if (!frame->hasSelection())
1372 frame->selectWordAroundCaret();
1373 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291374}
1375
[email protected]310ebd6302011-10-10 19:06:281376void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:291377 if (!webview())
1378 return;
1379
[email protected]26aa0482009-09-30 16:55:271380 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:291381}
1382
[email protected]310ebd6302011-10-10 19:06:281383void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291384 if (!webview())
1385 return;
1386
[email protected]26aa0482009-09-30 16:55:271387 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221388 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:291389}
1390
[email protected]45a599062012-09-07 20:09:061391void RenderViewImpl::OnReplaceAll(const string16& text) {
1392 WebNode node = GetFocusedNode();
1393 if (node.isNull() || !IsEditableNode(node))
1394 return;
1395
1396 OnSelectAll();
1397 OnReplace(text);
1398}
1399
1400void RenderViewImpl::OnUnselect() {
1401 if (!webview())
1402 return;
1403
1404 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
1405}
1406
1407void RenderViewImpl::OnSetEditableSelectionOffsets(int start, int end) {
1408 webview()->setEditableSelectionOffsets(start, end);
1409}
1410
1411void RenderViewImpl::OnSetCompositionFromExistingText(
1412 int start, int end,
1413 const std::vector<WebKit::WebCompositionUnderline>& underlines) {
1414 if (!webview())
1415 return;
1416 webview()->setCompositionFromExistingText(start, end, underlines);
1417}
1418
1419void RenderViewImpl::OnExtendSelectionAndDelete(int before, int after) {
1420 if (!webview())
1421 return;
1422 webview()->extendSelectionAndDelete(before, after);
1423}
1424
[email protected]310ebd6302011-10-10 19:06:281425void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1426 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:081427 if (!webview())
1428 return;
1429
[email protected]c95e53ad2012-08-13 17:56:161430 Send(new ViewHostMsg_SelectRange_ACK(routing_id_));
1431
[email protected]4fb60142011-08-09 02:22:081432 handling_select_range_ = true;
1433 webview()->focusedFrame()->selectRange(start, end);
1434 handling_select_range_ = false;
1435}
1436
[email protected]310ebd6302011-10-10 19:06:281437void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1438 int32 minimum_page_id) {
[email protected]e1ed5a12012-08-08 19:57:441439 DCHECK_GE(history_length, 0);
[email protected]9e1ad4b2011-08-14 16:49:191440 DCHECK(history_list_offset_ == history_list_length_ - 1);
[email protected]e1ed5a12012-08-08 19:57:441441 DCHECK_GE(minimum_page_id, -1);
[email protected]9e1ad4b2011-08-14 16:49:191442
1443 // Generate the new list.
1444 std::vector<int32> new_history_page_ids(history_length, -1);
1445 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1446 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1447 continue;
1448 new_history_page_ids.push_back(history_page_ids_[i]);
1449 }
1450 new_history_page_ids.swap(history_page_ids_);
1451
1452 // Update indexes.
1453 history_list_length_ = history_page_ids_.size();
1454 history_list_offset_ = history_list_length_ - 1;
1455}
1456
1457
[email protected]310ebd6302011-10-10 19:06:281458void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291459 if (!webview())
1460 return;
[email protected]26aa0482009-09-30 16:55:271461 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291462}
1463
[email protected]54ca3ca892011-06-07 21:14:541464#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281465void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331466 if (!webview())
1467 return;
1468 if (in_live_resize)
1469 webview()->willStartLiveResize();
1470 else
1471 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541472}
1473#endif
1474
[email protected]310ebd6302011-10-10 19:06:281475void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1476 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091477 WebKit::WebNode node = GetFocusedNode();
1478 if (!node.isNull()) {
[email protected]9b7d11e2012-10-08 19:24:141479 if (IsEditableNode(node)) {
1480 webview()->saveScrollAndScaleState();
[email protected]333ec8d02011-09-16 18:59:191481 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b7d11e2012-10-08 19:24:141482 }
[email protected]9b66f34bf2010-10-27 20:45:511483 }
1484}
1485
[email protected]9b7d11e2012-10-08 19:24:141486#if defined(OS_ANDROID)
1487void RenderViewImpl::OnUndoScrollFocusedEditableNodeIntoRect() {
1488 const WebNode node = GetFocusedNode();
1489 if (!node.isNull() && IsEditableNode(node))
1490 webview()->restoreScrollAndScaleState();
1491}
1492#endif
1493
initial.commit09911bf2008-07-26 23:55:291494///////////////////////////////////////////////////////////////////////////////
1495
1496// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281497void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451498 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291499 DCHECK(ds);
1500
[email protected]726985e22009-06-18 21:09:281501 const WebURLRequest& request = ds->request();
1502 const WebURLRequest& original_request = ds->originalRequest();
1503 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291504
[email protected]007733c2011-11-17 00:34:071505 DocumentState* document_state = DocumentState::FromDataSource(ds);
1506 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291507
1508 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281509 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291510 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051511 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291512 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071513 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191514 params.socket_address.set_host(response.remoteIPAddress().utf8());
1515 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031516 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091517 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071518 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291519 // SSL state specified in the request takes precedence over the one in the
1520 // response.
1521 // So far this is only intended for error pages that are not expected to be
1522 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281523 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071524 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291525 } else {
[email protected]726985e22009-06-18 21:09:281526 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291527 }
1528
1529 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:311530 params.url = GetLoadingUrl(frame);
initial.commit09911bf2008-07-26 23:55:291531
[email protected]5f9b8712011-11-23 08:55:571532 if (frame->document().baseURL() != params.url)
1533 params.base_url = frame->document().baseURL();
1534
[email protected]726985e22009-06-18 21:09:281535 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241536 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041537 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291538
[email protected]007733c2011-11-17 00:34:071539 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351540 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071541 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291542
1543 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071544 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291545 if (password_form_data)
1546 params.password_form = *password_form_data;
1547
1548 params.gesture = navigation_gesture_;
1549 navigation_gesture_ = NavigationGestureUnknown;
1550
[email protected]0f38dc4552011-02-25 11:24:001551 // Make navigation state a part of the FrameNavigate message so that commited
1552 // entry had it at all times.
1553 const WebHistoryItem& item = frame->currentHistoryItem();
1554 if (!item.isNull()) {
1555 params.content_state = webkit_glue::HistoryItemToString(item);
1556 } else {
1557 params.content_state =
1558 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1559 }
1560
[email protected]dd7daa82009-08-10 05:46:451561 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291562 // Top-level navigation.
1563
[email protected]d00a7972012-08-07 06:09:581564 // Reset the zoom limits in case a plugin had changed them previously. This
1565 // will also call us back which will cause us to send a message to
1566 // update WebContentsImpl.
1567 webview()->zoomLimitsChanged(
1568 WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
1569 WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
1570
[email protected]b75b8292010-10-01 07:28:251571 // Set zoom level, but don't do it for full-page plugin since they don't use
1572 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011573 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541574 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251575 if (webview()->mainFrame()->document().isPluginDocument()) {
1576 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251577 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251578 } else {
1579 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251580 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251581 }
1582
[email protected]f85f0702010-01-30 09:31:011583 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511584 // This zoom level was merely recorded transiently for this load. We can
1585 // erase it now. If at some point we reload this page, the browser will
1586 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011587 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511588 }
1589
initial.commit09911bf2008-07-26 23:55:291590 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551591 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291592
[email protected]daa8c58e2009-06-15 17:21:101593 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581594 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291595 // If the main frame does a load, it should not be reported as a subframe
1596 // navigation. This can occur in the following case:
1597 // 1. You're on a site with frames.
1598 // 2. You do a subframe navigation. This is stored with transition type
1599 // MANUAL_SUBFRAME.
1600 // 3. You navigate to some non-frame site, say, google.com.
1601 // 4. You navigate back to the page from step 2. Since it was initially
1602 // MANUAL_SUBFRAME, it will be that same transition type here.
1603 // We don't want that, because any navigation that changes the toplevel
1604 // frame should be tracked as a toplevel navigation (this allows us to
1605 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581606 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291607 }
1608
initial.commit09911bf2008-07-26 23:55:291609 // If we have a valid consumed client redirect source,
1610 // the page contained a client redirect (meta refresh, document.loc...),
1611 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151612 if (completed_client_redirect_src_.url.is_valid()) {
1613 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291614 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581615 params.transition = static_cast<content::PageTransition>(
1616 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291617 } else {
1618 // Bug 654101: the referrer will be empty on https->http transitions. It
1619 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151620 params.referrer = Referrer(GURL(
1621 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:591622 GetReferrerPolicyFromRequest(frame, original_request));
initial.commit09911bf2008-07-26 23:55:291623 }
1624
[email protected]726985e22009-06-18 21:09:281625 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051626 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291627 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051628 params.post_id = ExtractPostId(item);
1629 }
initial.commit09911bf2008-07-26 23:55:291630
[email protected]bf70edce2012-06-20 22:32:221631 // Send the user agent override back.
1632 params.is_overriding_user_agent =
1633 document_state->is_overriding_user_agent();
1634
[email protected]7c16976c2012-08-04 02:38:231635 // Track the URL of the original request.
1636 params.original_request_url = original_request.url();
1637
[email protected]c2a797d2009-09-21 16:46:321638 // Save some histogram data so we can compute the average memory used per
1639 // page load of the glyphs.
1640 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1641 webkit_glue::GetGlyphPageCount());
1642
[email protected]15cf526b2010-02-12 06:33:491643 // This message needs to be sent before any of allowScripts(),
1644 // allowImages(), allowPlugins() is called for the new page, so that when
1645 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1646 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291647 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1648 } else {
1649 // Subframe navigation: the type depends on whether this navigation
1650 // generated a new session history entry. When they do generate a session
1651 // history entry, it means the user initiated the navigation and we should
1652 // mark it as such. This test checks if this is the first time UpdateURL
1653 // has been called since WillNavigateToURL was called to initiate the load.
1654 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581655 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291656 else
[email protected]2905f742011-10-13 03:51:581657 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291658
initial.commit09911bf2008-07-26 23:55:291659 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1660 }
1661
1662 last_page_id_sent_to_browser_ =
1663 std::max(last_page_id_sent_to_browser_, page_id_);
1664
1665 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101666 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581667 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291668}
1669
1670// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281671void RenderViewImpl::UpdateTitle(WebFrame* frame,
1672 const string16& title,
1673 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461674 // Ignore all but top level navigations.
1675 if (frame->parent())
1676 return;
1677
1678 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1679 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1680 title_direction));
initial.commit09911bf2008-07-26 23:55:291681}
1682
[email protected]310ebd6302011-10-10 19:06:281683void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1684 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291685 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271686 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291687 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301688 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291689 last_encoding_name_ = encoding_name;
1690
[email protected]e38f40152008-09-12 23:08:301691 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291692 }
1693}
1694
[email protected]e15f680732010-11-23 22:30:201695// Sends the last committed session history state to the browser so it will be
1696// saved before we navigate to a new page. This must be called *before* the
1697// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281698void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291699 // If we have a valid page ID at this point, then it corresponds to the page
1700 // we are navigating away from. Otherwise, this is the first navigation, so
1701 // there is no past session history to record.
1702 if (page_id_ == -1)
1703 return;
1704
[email protected]ca948a22009-06-25 19:36:171705 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271706 webview()->mainFrame()->previousHistoryItem();
[email protected]6459800a2012-03-27 23:57:051707 SendUpdateState(item);
1708}
1709
1710void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
[email protected]ca948a22009-06-25 19:36:171711 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291712 return;
[email protected]ca948a22009-06-25 19:36:171713
[email protected]285f4bb82012-04-17 15:57:281714 // Don't send state updates for content::kSwappedOutURL.
1715 if (item.urlString() == WebString::fromUTF8(content::kSwappedOutURL))
[email protected]6459800a2012-03-27 23:57:051716 return;
1717
[email protected]ca948a22009-06-25 19:36:171718 Send(new ViewHostMsg_UpdateState(
1719 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291720}
1721
[email protected]310ebd6302011-10-10 19:06:281722void RenderViewImpl::OpenURL(WebFrame* frame,
1723 const GURL& url,
[email protected]445e1042011-12-03 21:03:151724 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281725 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171726 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581727 routing_id_,
1728 url,
1729 referrer,
1730 NavigationPolicyToDisposition(policy),
1731 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171732}
1733
[email protected]79dbc662009-09-04 05:42:511734// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291735
[email protected]310ebd6302011-10-10 19:06:281736void RenderViewImpl::LoadNavigationErrorPage(
1737 WebFrame* frame,
1738 const WebURLRequest& failed_request,
1739 const WebURLError& error,
1740 const std::string& html,
1741 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581742 std::string alt_html;
1743 const std::string* error_html;
1744
1745 if (!html.empty()) {
1746 error_html = &html;
1747 } else {
1748 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1749 failed_request, error, &alt_html, NULL);
1750 error_html = &alt_html;
1751 }
1752
1753 frame->loadHTMLString(*error_html,
[email protected]285f4bb82012-04-17 15:57:281754 GURL(content::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251755 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551756 replace);
initial.commit09911bf2008-07-26 23:55:291757}
1758
[email protected]be2510c02012-05-28 14:52:141759bool RenderViewImpl::RunJavaScriptMessage(content::JavaScriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281760 const string16& message,
1761 const string16& default_value,
1762 const GURL& frame_url,
1763 string16* result) {
initial.commit09911bf2008-07-26 23:55:291764 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411765 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291766 if (!result)
1767 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291768
[email protected]12636df2009-09-28 22:32:211769 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1770 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291771 return success;
1772}
1773
[email protected]310ebd6302011-10-10 19:06:281774bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571775 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1776 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1777 // it is particularly important that we do not call willEnterModalLoop as
1778 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441779 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1780 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571781
1782 message->EnableMessagePumping(); // Runs a nested message loop.
1783 return Send(message);
1784}
1785
[email protected]48c9cf2d2009-09-16 16:47:521786// WebKit::WebViewClient ------------------------------------------------------
1787
[email protected]916dfb62012-03-05 03:39:371788WebView* RenderViewImpl::createView(
1789 WebFrame* creator,
1790 const WebURLRequest& request,
1791 const WebWindowFeatures& features,
1792 const WebString& frame_name,
1793 WebNavigationPolicy policy) {
[email protected]48c9cf2d2009-09-16 16:47:521794 // Check to make sure we aren't overloading on popups.
1795 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1796 return NULL;
1797
[email protected]8ab04652010-06-12 02:47:261798 ViewHostMsg_CreateWindow_Params params;
1799 params.opener_id = routing_id_;
1800 params.user_gesture = creator->isProcessingUserGesture();
1801 params.window_container_type = WindowFeaturesToContainerType(features);
1802 params.session_storage_namespace_id = session_storage_namespace_id_;
1803 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111804 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411805 params.opener_url = creator->document().url();
1806 params.opener_security_origin =
1807 creator->document().securityOrigin().toString().utf8();
[email protected]f92ce2b2012-03-06 18:02:591808 params.opener_suppressed = creator->willSuppressOpenerInNewFrame();
1809 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]41e65502011-01-21 09:29:111810 if (!request.isNull())
1811 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261812
[email protected]48c9cf2d2009-09-16 16:47:521813 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561814 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341815 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521816
[email protected]7c962ee32012-08-28 21:12:501817 creator->consumeUserGesture();
[email protected]380244092011-10-07 17:26:271818 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261819 new ViewHostMsg_CreateWindow(params,
1820 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561821 &surface_id,
[email protected]8ab04652010-06-12 02:47:261822 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211823 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521824 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521825
[email protected]8cca3da2012-03-20 08:26:341826 // TODO(fsamuel): The host renderer needs to be able to control whether
1827 // the guest renderer is allowed to do this or not. This current
1828 // behavior is not well defined.
[email protected]310ebd6302011-10-10 19:06:281829 RenderViewImpl* view = RenderViewImpl::Create(
1830 0,
1831 routing_id_,
1832 renderer_preferences_,
1833 webkit_preferences_,
1834 shared_popup_counter_,
1835 routing_id,
[email protected]9f4f3322012-01-18 22:29:561836 surface_id,
[email protected]310ebd6302011-10-10 19:06:281837 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461838 frame_name,
[email protected]14392a52012-05-02 20:28:441839 true,
1840 false,
[email protected]6fd35b72012-03-01 19:46:411841 1,
[email protected]842f10652012-06-06 01:54:041842 screen_info_,
[email protected]468e4902012-05-23 01:49:311843 guest_to_embedder_channel_,
[email protected]3e3c4522012-04-13 21:16:291844 accessibility_mode_);
[email protected]8ab04652010-06-12 02:47:261845 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521846
[email protected]007a848b2009-10-26 15:55:461847 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:591848 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:461849
[email protected]48c9cf2d2009-09-16 16:47:521850 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411851 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521852 if (!creator_url.is_valid() || !creator_url.IsStandard())
1853 creator_url = GURL();
1854 view->creator_url_ = creator_url;
1855
1856 // Copy over the alternate error page URL so we can have alt error pages in
1857 // the new render view (we don't need the browser to send the URL back down).
1858 view->alternate_error_page_url_ = alternate_error_page_url_;
1859
1860 return view->webview();
1861}
1862
[email protected]310ebd6302011-10-10 19:06:281863WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:411864 RenderWidget* widget =
[email protected]842f10652012-06-06 01:54:041865 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]48c9cf2d2009-09-16 16:47:521866 return widget->webwidget();
1867}
1868
[email protected]310ebd6302011-10-10 19:06:281869WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081870 const WebPopupMenuInfo& popup_menu_info,
1871 WebExternalPopupMenuClient* popup_menu_client) {
[email protected]8de2f882012-05-30 00:32:271872 // An IPC message is sent to the browser to build and display the actual
1873 // popup. The user could have time to click a different select by the time
1874 // the popup is shown. In that case external_popup_menu_ is non NULL.
1875 // By returning NULL in that case, we instruct WebKit to cancel that new
1876 // popup. So from the user perspective, only the first one will show, and
1877 // will have to close the first one before another one can be shown.
1878 if (external_popup_menu_.get())
1879 return NULL;
[email protected]caf706f2010-10-26 17:54:081880 external_popup_menu_.reset(
1881 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1882 return external_popup_menu_.get();
1883}
1884
[email protected]310ebd6302011-10-10 19:06:281885RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521886 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531887 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421888 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411889 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531890 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]bee6eb72012-07-26 03:47:321891 routing_id_, plugin, active_url, screen_info_);
[email protected]79c7bed2010-09-14 22:28:391892 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561893 return widget;
[email protected]79c7bed2010-09-14 22:28:391894}
1895
[email protected]310ebd6302011-10-10 19:06:281896WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1897 unsigned quota) {
[email protected]b928936b2012-04-13 01:16:161898 CHECK(session_storage_namespace_id_ !=
1899 dom_storage::kInvalidSessionStorageNamespaceId);
[email protected]1910fe82012-05-10 00:04:101900 return new WebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341901}
1902
[email protected]1842fe22012-08-13 23:24:351903WebKit::WebCompositorOutputSurface* RenderViewImpl::createOutputSurface() {
[email protected]1842fe22012-08-13 23:24:351904 // Explicitly disable antialiasing for the compositor. As of the time of
1905 // this writing, the only platform that supported antialiasing for the
1906 // compositor was Mac OS X, because the on-screen OpenGL context creation
1907 // code paths on Windows and Linux didn't yet have multisampling support.
1908 // Mac OS X essentially always behaves as though it's rendering offscreen.
1909 // Multisampling has a heavy cost especially on devices with relatively low
1910 // fill rate like most notebooks, and the Mac implementation would need to
1911 // be optimized to resolve directly into the IOSurface shared between the
1912 // GPU and browser processes. For these reasons and to avoid platform
1913 // disparities we explicitly disable antialiasing.
1914 WebKit::WebGraphicsContext3D::Attributes attributes;
1915 attributes.antialias = false;
1916 attributes.shareResources = true;
1917 WebGraphicsContext3D* context = CreateGraphicsContext3D(attributes);
1918 if (!context)
[email protected]7e8b4d12012-01-20 23:39:511919 return NULL;
[email protected]468e4902012-05-23 01:49:311920
[email protected]7d4481d12012-09-24 21:26:471921 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1922 if (command_line.HasSwitch(switches::kEnableSoftwareCompositingGLAdapter)) {
1923 // In the absence of a software-based delegating renderer, use this
1924 // stopgap adapter class to present the software renderer output using a
1925 // 3d context.
1926 return new CompositorOutputSurface(routing_id(), NULL,
1927 new CompositorSoftwareOutputDeviceGLAdapter(context));
1928 } else
1929 return new CompositorOutputSurface(routing_id(), context, NULL);
[email protected]7e8b4d12012-01-20 23:39:511930}
1931
[email protected]310ebd6302011-10-10 19:06:281932void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521933 const WebConsoleMessage& message, const WebString& source_name,
1934 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081935 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511936 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081937 case WebConsoleMessage::LevelTip:
1938 log_severity = logging::LOG_VERBOSE;
1939 break;
1940 case WebConsoleMessage::LevelLog:
1941 log_severity = logging::LOG_INFO;
1942 break;
1943 case WebConsoleMessage::LevelWarning:
1944 log_severity = logging::LOG_WARNING;
1945 break;
1946 case WebConsoleMessage::LevelError:
1947 log_severity = logging::LOG_ERROR;
1948 break;
1949 default:
1950 NOTREACHED();
1951 }
1952
[email protected]48c9cf2d2009-09-16 16:47:521953 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081954 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311955 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521956 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311957 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521958}
1959
[email protected]310ebd6302011-10-10 19:06:281960void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]b0553c7e2012-09-19 21:36:111961 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
1962 PrintPage(frame, handling_input_event_));
[email protected]48c9cf2d2009-09-16 16:47:521963}
1964
[email protected]310ebd6302011-10-10 19:06:281965WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511966 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021967}
1968
[email protected]310ebd6302011-10-10 19:06:281969bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121970 const WebString& path,
1971 WebFileChooserCompletion* chooser_completion) {
1972 int id = enumeration_completion_id_++;
1973 enumeration_completions_[id] = chooser_completion;
1974 return Send(new ViewHostMsg_EnumerateDirectory(
1975 routing_id_,
1976 id,
1977 webkit_glue::WebStringToFilePath(path)));
1978}
1979
[email protected]4b1146bc2012-07-10 18:46:031980void RenderViewImpl::initializeHelperPluginWebFrame(
1981 WebKit::WebHelperPlugin* plugin) {
1982 plugin->initializeFrame(this);
1983}
1984
[email protected]310ebd6302011-10-10 19:06:281985void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521986 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:141987 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:521988 return;
1989 }
1990
1991 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521992
1993 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311994
1995 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521996}
1997
[email protected]310ebd6302011-10-10 19:06:281998void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521999 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:142000 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:522001 return;
2002 }
2003
2004 is_loading_ = false;
2005
[email protected]0720b532012-08-28 19:23:372006 if (pending_frame_tree_update_) {
2007 pending_frame_tree_update_ = false;
2008 SendUpdatedFrameTree(NULL);
2009 }
2010
[email protected]48c9cf2d2009-09-16 16:47:522011 // NOTE: For now we're doing the safest thing, and sending out notification
2012 // when done loading. This currently isn't an issue as the favicon is only
2013 // displayed when done loading. Ideally we would send notification when
2014 // finished parsing the head, but webkit doesn't support that yet.
2015 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:522016 Send(new ViewHostMsg_DidStopLoading(routing_id_));
2017
[email protected]90109412010-12-15 17:14:242018 if (load_progress_tracker_ != NULL)
2019 load_progress_tracker_->DidStopLoading();
2020
[email protected]93b9d692011-04-13 00:44:312021 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:522022}
2023
[email protected]310ebd6302011-10-10 19:06:282024void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
2025 double load_progress) {
[email protected]90109412010-12-15 17:14:242026 if (load_progress_tracker_ != NULL)
2027 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
2028}
2029
[email protected]310ebd6302011-10-10 19:06:282030bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:062031#if defined(OS_MACOSX)
2032 return true;
2033#else
2034 return false;
2035#endif
2036}
2037
[email protected]310ebd6302011-10-10 19:06:282038bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:032039#if defined(OS_WIN)
2040 return true;
2041#else
2042 return false;
2043#endif
2044}
2045
[email protected]310ebd6302011-10-10 19:06:282046void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:082047 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:032048 return;
[email protected]4fb60142011-08-09 02:22:082049 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:012050
[email protected]fca52022012-04-03 17:00:502051 if (is_empty_selection)
2052 selection_text_.clear();
2053
[email protected]b781ff282011-08-20 06:19:362054 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:032055}
2056
[email protected]310ebd6302011-10-10 19:06:282057void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:122058 const std::string& name = UTF16ToUTF8(command_name);
2059 if (StartsWithASCII(name, "Move", true) ||
2060 StartsWithASCII(name, "Insert", true) ||
2061 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:032062 return;
[email protected]f1a29a02011-10-06 23:08:442063 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:032064}
2065
[email protected]310ebd6302011-10-10 19:06:282066bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:102067 if (edit_commands_.empty())
2068 return false;
2069
[email protected]26aa0482009-09-30 16:55:272070 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102071 if (!frame)
2072 return false;
2073
2074 EditCommands::iterator it = edit_commands_.begin();
2075 EditCommands::iterator end = edit_commands_.end();
2076
[email protected]507b33ea2009-09-29 03:56:512077 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102078 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332079 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2080 // key (but it's the exception). Once one edit command is not executed, it
2081 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102082 if (!frame->executeCommand(WebString::fromUTF8(it->name),
2083 WebString::fromUTF8(it->value)))
2084 break;
[email protected]507b33ea2009-09-29 03:56:512085 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102086 }
2087
[email protected]507b33ea2009-09-29 03:56:512088 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102089}
2090
[email protected]3306f262012-09-21 19:20:422091void RenderViewImpl::didHandleGestureEvent(const WebGestureEvent& event,
2092 bool event_swallowed) {
2093#if defined(OS_ANDROID)
2094 if (event.type == WebInputEvent::GestureTap ||
2095 event.type == WebInputEvent::GestureLongPress) {
2096 UpdateTextInputState(SHOW_IME_IF_NEEDED);
2097 }
2098#endif
2099}
2100
[email protected]da8543762012-03-20 08:52:202101WebKit::WebColorChooser* RenderViewImpl::createColorChooser(
2102 WebKit::WebColorChooserClient* client,
2103 const WebKit::WebColor& initial_color) {
2104 RendererWebColorChooserImpl* color_chooser =
2105 new RendererWebColorChooserImpl(this, client);
2106 color_chooser->Open(static_cast<SkColor>(initial_color));
2107 return color_chooser;
2108}
2109
[email protected]310ebd6302011-10-10 19:06:282110bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:352111 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472112 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352113 // Do not open the file dialog in a hidden RenderView.
2114 if (is_hidden())
2115 return false;
[email protected]8caadeb2011-11-22 02:45:232116 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262117 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:232118 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:262119 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:232120 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:502121 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:232122 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:262123 else
[email protected]8caadeb2011-11-22 02:45:232124 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:472125 ipc_params.title = params.title;
2126 ipc_params.default_file_name =
2127 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]f9a4c41a2012-05-30 00:05:322128 ipc_params.accept_types.reserve(params.acceptTypes.size());
2129 for (size_t i = 0; i < params.acceptTypes.size(); ++i)
2130 ipc_params.accept_types.push_back(params.acceptTypes[i]);
[email protected]cdaf8d02010-03-30 19:52:472131
2132 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462133}
2134
[email protected]269f86d2011-12-07 02:43:472135void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
2136 const WebString& message) {
[email protected]be2510c02012-05-28 14:52:142137 RunJavaScriptMessage(content::JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:412138 message,
2139 string16(),
[email protected]b6cb3a842011-06-24 18:28:412140 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522141 NULL);
2142}
2143
[email protected]269f86d2011-12-07 02:43:472144bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
2145 const WebString& message) {
[email protected]be2510c02012-05-28 14:52:142146 return RunJavaScriptMessage(content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:412147 message,
2148 string16(),
[email protected]b6cb3a842011-06-24 18:28:412149 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522150 NULL);
2151}
2152
[email protected]269f86d2011-12-07 02:43:472153bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
2154 const WebString& message,
2155 const WebString& default_value,
2156 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:412157 string16 result;
[email protected]be2510c02012-05-28 14:52:142158 bool ok = RunJavaScriptMessage(content::JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:412159 message,
2160 default_value,
[email protected]b6cb3a842011-06-24 18:28:412161 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:522162 &result);
2163 if (ok)
[email protected]4f5ce842011-05-27 19:34:412164 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:522165 return ok;
2166}
2167
[email protected]310ebd6302011-10-10 19:06:282168bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:522169 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:152170 // If we are swapping out, we have already run the beforeunload handler.
2171 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
2172 // at all, to avoid running it twice.
2173 if (is_swapped_out_)
2174 return true;
2175
[email protected]3b3301f62012-02-29 04:32:322176 bool is_reload = false;
2177 WebDataSource* ds = frame->provisionalDataSource();
2178 if (ds)
2179 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
2180
[email protected]48c9cf2d2009-09-16 16:47:522181 bool success = false;
2182 // This is an ignored return value, but is included so we can accept the same
2183 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:412184 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:212185 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:322186 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:412187 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522188 return success;
2189}
2190
[email protected]310ebd6302011-10-10 19:06:282191void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:442192 WebFrame* frame, const WebContextMenuData& data) {
[email protected]8f635f82012-06-22 22:02:442193 // TODO(fsamuel): In the future, we might want the embedder to be able to
2194 // decide whether the guest can show a context menu or not. See
2195 // http://www.crbug.com/134207
2196 if (GetGuestToEmbedderChannel())
2197 return;
2198
[email protected]35be7ec2012-02-12 20:42:512199 content::ContextMenuParams params(data);
[email protected]7fcd9b72011-07-27 16:52:372200
[email protected]329266d2012-09-27 06:20:572201 // Plugins, e.g. PDF, don't currently update the render view when their
2202 // selected text changes, but the context menu params do contain the updated
2203 // selection. If that's the case, update the render view's state just prior
2204 // to showing the context menu.
2205 // TODO(asvitkine): http://crbug.com/152432
2206 if (params.selection_text != selection_text_) {
2207 selection_text_ = params.selection_text;
2208 // TODO(asvitkine): Text offset and range is not available in this case.
2209 selection_text_offset_ = 0;
2210 selection_range_ = ui::Range(0, selection_text_.length());
2211 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2212 selection_text_,
2213 selection_text_offset_,
2214 selection_range_));
2215 }
2216
[email protected]7fcd9b72011-07-27 16:52:372217 // frame is NULL if invoked by BlockedPlugin.
2218 if (frame)
2219 params.frame_id = frame->identifier();
2220
[email protected]db803aae2011-03-05 02:00:422221 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:272222 // it. We replace it with an empty GURL so the appropriate items are disabled
2223 // in the context menu.
2224 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2225 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:422226 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:272227 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102228 context_menu_node_ = data.node;
[email protected]44daa3b2012-09-27 19:26:412229
2230#if defined(OS_ANDROID)
2231 gfx::Rect start_rect;
2232 gfx::Rect end_rect;
2233 GetSelectionBounds(&start_rect, &end_rect);
2234 gfx::Point start_point(start_rect.x(),
2235 start_rect.bottom());
2236 gfx::Point end_point(end_rect.right(),
2237 end_rect.bottom());
2238 params.selection_start = GetScrollOffset().Add(start_point);
2239 params.selection_end = GetScrollOffset().Add(end_point);
2240#endif
2241
[email protected]c27324b2009-11-19 22:44:292242 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442243}
2244
[email protected]310ebd6302011-10-10 19:06:282245void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:522246}
2247
[email protected]310ebd6302011-10-10 19:06:282248void RenderViewImpl::UpdateTargetURL(const GURL& url,
2249 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582250 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522251 if (latest_url == target_url_)
2252 return;
[email protected]163f8242009-10-30 20:19:552253
[email protected]48c9cf2d2009-09-16 16:47:522254 // Tell the browser to display a destination link.
2255 if (target_url_status_ == TARGET_INFLIGHT ||
2256 target_url_status_ == TARGET_PENDING) {
2257 // If we have a request in-flight, save the URL to be sent when we
2258 // receive an ACK to the in-flight request. We can happily overwrite
2259 // any existing pending sends.
2260 pending_target_url_ = latest_url;
2261 target_url_status_ = TARGET_PENDING;
2262 } else {
[email protected]c85f0212011-11-04 16:54:412263 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
2264 // see |ParamTraits<GURL>|.
2265 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
2266 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:522267 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2268 target_url_ = latest_url;
2269 target_url_status_ = TARGET_INFLIGHT;
2270 }
2271}
2272
[email protected]310ebd6302011-10-10 19:06:282273void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:312274 int delay;
2275 if (send_content_state_immediately_)
2276 delay = 0;
2277 else if (is_hidden())
2278 delay = kDelaySecondsForContentStateSyncHidden;
2279 else
2280 delay = kDelaySecondsForContentStateSync;
2281
2282 if (nav_state_sync_timer_.IsRunning()) {
2283 // The timer is already running. If the delay of the timer maches the amount
2284 // we want to delay by, then return. Otherwise stop the timer so that it
2285 // gets started with the right delay.
2286 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2287 return;
2288 nav_state_sync_timer_.Stop();
2289 }
2290
[email protected]d323a172011-09-02 18:23:022291 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:282292 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:312293}
2294
[email protected]310ebd6302011-10-10 19:06:282295void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552296 mouse_over_url_ = GURL(url);
2297 UpdateTargetURL(mouse_over_url_, focus_url_);
2298}
2299
[email protected]310ebd6302011-10-10 19:06:282300void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:552301 focus_url_ = GURL(url);
2302 UpdateTargetURL(focus_url_, mouse_over_url_);
2303}
2304
[email protected]0407e422012-05-18 19:51:252305void RenderViewImpl::startDragging(WebFrame* frame,
2306 const WebDragData& data,
[email protected]310ebd6302011-10-10 19:06:282307 WebDragOperationsMask mask,
2308 const WebImage& image,
2309 const WebPoint& imageOffset) {
[email protected]b67151d2012-05-25 23:23:242310 WebDropData drop_data(data);
2311 drop_data.referrer_policy = frame->document().referrerPolicy();
[email protected]59f4f2fa2011-03-23 01:00:552312 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]b67151d2012-05-25 23:23:242313 drop_data,
[email protected]c27ae592010-03-18 15:24:412314 mask,
[email protected]976127072012-05-10 20:08:112315 image.getSkBitmap(),
[email protected]c27ae592010-03-18 15:24:412316 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522317}
2318
[email protected]310ebd6302011-10-10 19:06:282319bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:452320 return renderer_preferences_.can_accept_load_drops;
2321}
2322
[email protected]310ebd6302011-10-10 19:06:282323void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:522324 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2325}
2326
[email protected]310ebd6302011-10-10 19:06:282327void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:522328 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2329}
2330
[email protected]310ebd6302011-10-10 19:06:282331void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512332 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072333
[email protected]38b592902011-04-16 02:08:422334 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:492335}
2336
[email protected]572a6ca2012-10-11 19:38:012337void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
2338 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
2339}
2340
2341void RenderViewImpl::hasTouchEventHandlers(bool has_handlers) {
2342 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2343}
2344
[email protected]169d4282011-11-30 19:33:592345void RenderViewImpl::didUpdateLayout() {
2346 // We don't always want to set up a timer, only if we've been put in that
2347 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2348 // message.
2349 if (!send_preferred_size_changes_ || !webview())
2350 return;
2351
2352 if (check_preferred_size_timer_.IsRunning())
2353 return;
2354 check_preferred_size_timer_.Start(FROM_HERE,
2355 TimeDelta::FromMilliseconds(0), this,
2356 &RenderViewImpl::CheckPreferredSize);
2357}
2358
[email protected]310ebd6302011-10-10 19:06:282359void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522360 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2361}
2362
[email protected]310ebd6302011-10-10 19:06:282363int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002364 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522365}
2366
[email protected]310ebd6302011-10-10 19:06:282367int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002368 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522369}
2370
[email protected]310ebd6302011-10-10 19:06:282371void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:322372 const WebAccessibilityObject& obj,
2373 WebAccessibilityNotification notification) {
[email protected]2a84f9d2012-06-05 21:50:432374 if (renderer_accessibility_) {
2375 renderer_accessibility_->HandleWebAccessibilityNotification(
2376 obj, notification);
2377 }
[email protected]063afcb2011-09-29 07:54:322378}
2379
[email protected]310ebd6302011-10-10 19:06:282380void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:142381 const WebString& value) {
2382 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2383 key.utf8(),
2384 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262385}
2386
[email protected]79dbc662009-09-04 05:42:512387// WebKit::WebWidgetClient ----------------------------------------------------
2388
[email protected]310ebd6302011-10-10 19:06:282389void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122390 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2391 // we won't have to test for user gesture anymore and we can
2392 // move that code back to render_widget.cc
2393 if (webview() && webview()->mainFrame() &&
2394 webview()->mainFrame()->isProcessingUserGesture()) {
2395 Send(new ViewHostMsg_Focus(routing_id_));
2396 }
2397}
2398
[email protected]310ebd6302011-10-10 19:06:282399void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122400 // TODO(jcivelli): see TODO above in didFocus().
2401 if (webview() && webview()->mainFrame() &&
2402 webview()->mainFrame()->isProcessingUserGesture()) {
2403 Send(new ViewHostMsg_Blur(routing_id_));
2404 }
2405}
2406
initial.commit09911bf2008-07-26 23:55:292407// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282408// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292409// point to dispatch the ShowView message.
2410//
2411// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282412// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292413//
[email protected]310ebd6302011-10-10 19:06:282414void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292415 DCHECK(!did_show_) << "received extraneous Show call";
2416 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2417
2418 if (did_show_)
2419 return;
2420 did_show_ = true;
2421
[email protected]6779aa12011-03-29 17:32:242422 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:042423 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:042424
[email protected]28295ec2009-10-16 05:34:332425 // Force new windows to a popup if they were not opened with a user gesture.
2426 if (!opened_by_user_gesture_) {
2427 // We exempt background tabs for compat with older versions of Chrome.
2428 // TODO(darin): This seems bogus. These should have a user gesture, so
2429 // we probably don't need this check.
2430 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2431 policy = WebKit::WebNavigationPolicyNewPopup;
2432 }
2433
initial.commit09911bf2008-07-26 23:55:292434 // NOTE: initial_pos_ may still have its default values at this point, but
2435 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2436 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282437 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2438 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292439 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242440 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292441}
2442
[email protected]310ebd6302011-10-10 19:06:282443void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292444 DCHECK(did_show_) << "should already have shown the view";
2445
[email protected]c1f50aa2010-02-18 03:46:572446 // We must keep WebKit's shared timer running in this case in order to allow
2447 // showModalDialog to function properly.
2448 //
2449 // TODO(darin): WebKit should really be smarter about suppressing events and
2450 // timers so that we do not need to manage the shared timer in such a heavy
2451 // handed manner.
2452 //
[email protected]f1a29a02011-10-06 23:08:442453 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2454 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572455
[email protected]08a1c8102012-05-11 23:14:262456 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
2457 routing_id_, opener_id_));
initial.commit09911bf2008-07-26 23:55:292458}
2459
[email protected]2b624c562011-10-27 22:58:262460bool RenderViewImpl::enterFullScreen() {
2461 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2462 return true;
2463}
2464
2465void RenderViewImpl::exitFullScreen() {
2466 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2467}
2468
[email protected]217690d2012-01-27 07:33:112469bool RenderViewImpl::requestPointerLock() {
2470 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2471}
2472
2473void RenderViewImpl::requestPointerUnlock() {
2474 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2475}
2476
2477bool RenderViewImpl::isPointerLocked() {
2478 return mouse_lock_dispatcher_->IsMouseLockedTo(
2479 webwidget_mouse_lock_target_.get());
2480}
2481
[email protected]7a1ec28a2012-03-28 21:10:242482void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
2483 CompositorThread* compositor_thread =
2484 RenderThreadImpl::current()->compositor_thread();
2485 if (compositor_thread)
2486 compositor_thread->AddInputHandler(
2487 routing_id_, input_handler_identifier, AsWeakPtr());
2488
2489 RenderWidget::didActivateCompositor(input_handler_identifier);
[email protected]1c0c9bc2012-10-08 22:41:482490
2491 ProcessAcceleratedPinchZoomFlags(*CommandLine::ForCurrentProcess());
[email protected]7a1ec28a2012-03-28 21:10:242492}
2493
[email protected]3d9689372009-09-10 04:29:172494// WebKit::WebFrameClient -----------------------------------------------------
2495
[email protected]310ebd6302011-10-10 19:06:282496WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2497 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:552498 WebPlugin* plugin = NULL;
2499 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
2500 this, frame, params, &plugin)) {
2501 return plugin;
2502 }
2503
[email protected]1eb20dc2012-10-04 21:01:552504 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2505 if (UTF16ToASCII(params.mimeType) == content::kBrowserPluginMimeType) {
2506 if (cmd_line->HasSwitch(switches::kEnableBrowserPluginOldImplementation)) {
2507 // TODO(fsamuel): Remove this once upstreaming of the new browser plugin
2508 // is complete.
2509 return content::old::BrowserPlugin::Create(this, frame, params);
2510 } else {
2511 return content::BrowserPluginManager::Get()->CreateBrowserPlugin(this,
2512 frame,
2513 params);
2514 }
[email protected]e6e56752012-08-10 00:46:062515 }
2516
[email protected]a813c8e2011-10-08 01:34:112517 webkit::WebPluginInfo info;
2518 std::string mime_type;
2519 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2520 params.mimeType.utf8(), &info, &mime_type);
2521 if (!found)
2522 return NULL;
2523
2524 WebPluginParams params_to_use = params;
2525 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312526 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172527}
2528
[email protected]310ebd6302011-10-10 19:06:282529WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422530 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372531 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422532
[email protected]30447b62009-11-13 01:13:372533 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512534 bool exists = false;
[email protected]30447b62009-11-13 01:13:372535 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512536 ViewHostMsg_CreateWorker_Params params;
2537 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512538 params.name = name;
2539 params.document_id = document_id;
2540 params.render_view_route_id = routing_id_;
2541 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232542 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372543 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512544 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372545 if (url_mismatch) {
2546 return NULL;
2547 } else {
[email protected]f1a29a02011-10-06 23:08:442548 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492549 document_id,
[email protected]6de0bcf2010-02-17 22:00:512550 exists,
[email protected]30447b62009-11-13 01:13:372551 route_id,
2552 routing_id_);
2553 }
[email protected]9c00f002009-11-05 22:37:422554}
2555
[email protected]97b150db2012-08-16 18:26:022556WebMediaPlayer* RenderViewImpl::createMediaPlayer(
2557 WebFrame* frame, const WebKit::WebURL& url, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442558 FOR_EACH_OBSERVER(
2559 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172560
[email protected]780fc8242012-09-19 20:28:522561 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
[email protected]25fb9b32012-04-27 03:21:552562#if defined(OS_ANDROID)
[email protected]855623ed2012-09-24 18:59:552563 WebGraphicsContext3D* resource_context =
2564 GetWebView()->sharedGraphicsContext3D();
2565
2566 GpuChannelHost* gpu_channel_host =
2567 RenderThreadImpl::current()->EstablishGpuChannelSync(
2568 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
2569 if (!gpu_channel_host) {
2570 LOG(ERROR) << "Failed to establish GPU channel for media player";
2571 return NULL;
2572 }
2573
[email protected]780fc8242012-09-19 20:28:522574 if (cmd_line->HasSwitch(switches::kMediaPlayerInRenderProcess)) {
2575 if (!media_bridge_manager_.get()) {
2576 media_bridge_manager_.reset(
2577 new webkit_media::MediaPlayerBridgeManagerImpl(1));
2578 }
2579 return new webkit_media::WebMediaPlayerInProcessAndroid(
2580 frame,
2581 client,
2582 cookieJar(frame),
2583 media_player_manager_.get(),
2584 media_bridge_manager_.get(),
2585 new content::StreamTextureFactoryImpl(
[email protected]855623ed2012-09-24 18:59:552586 resource_context, gpu_channel_host, routing_id_),
[email protected]780fc8242012-09-19 20:28:522587 cmd_line->HasSwitch(switches::kDisableMediaHistoryLogging));
2588 }
2589 if (!media_player_proxy_) {
2590 media_player_proxy_ = new content::WebMediaPlayerProxyImplAndroid(
2591 this, media_player_manager_.get());
2592 }
2593 return new webkit_media::WebMediaPlayerImplAndroid(
2594 frame,
2595 client,
2596 media_player_manager_.get(),
2597 media_player_proxy_,
2598 new content::StreamTextureFactoryImpl(
[email protected]855623ed2012-09-24 18:59:552599 resource_context, gpu_channel_host, routing_id_));
[email protected]25fb9b32012-04-27 03:21:552600#endif
2601
[email protected]bb6fd402011-12-09 02:45:442602 media::MessageLoopFactory* message_loop_factory =
[email protected]b80322902012-03-06 01:33:502603 new media::MessageLoopFactory();
[email protected]bb6fd402011-12-09 02:45:442604 media::FilterCollection* collection = new media::FilterCollection();
2605 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372606
[email protected]9e2269d2012-01-07 00:06:212607 RenderAudioSourceProvider* audio_source_provider = NULL;
2608
[email protected]3d9689372009-09-10 04:29:172609 // Add in any custom filter factories first.
[email protected]3d9689372009-09-10 04:29:172610 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212611 // audio_source_provider is a "provider" to WebKit, and a sink
2612 // from the perspective of the audio renderer.
2613 audio_source_provider = new RenderAudioSourceProvider();
2614
2615 // Add the chrome specific audio renderer, using audio_source_provider
2616 // as the sink.
[email protected]37136d162012-04-09 23:39:192617 media::AudioRendererImpl* audio_renderer =
2618 new media::AudioRendererImpl(audio_source_provider);
[email protected]9e2269d2012-01-07 00:06:212619 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172620 }
2621
[email protected]15d206e2012-08-17 22:35:132622 WebGraphicsContext3DCommandBufferImpl* context3d = NULL;
[email protected]5f04c3532012-09-25 01:28:392623 if (!cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode))
[email protected]15d206e2012-08-17 22:35:132624 context3d = RenderThreadImpl::current()->GetGpuVDAContext3D();
[email protected]851334d2012-06-15 22:39:312625 if (context3d) {
[email protected]084c8552012-08-12 22:51:202626 scoped_refptr<base::MessageLoopProxy> factories_loop =
[email protected]84a83e192012-03-09 18:43:402627 RenderThreadImpl::current()->compositor_thread() ?
2628 RenderThreadImpl::current()->compositor_thread()->GetWebThread()
[email protected]084c8552012-08-12 22:51:202629 ->message_loop()->message_loop_proxy() :
2630 base::MessageLoopProxy::current();
[email protected]e1d69d762011-12-13 05:12:182631 GpuChannelHost* gpu_channel_host =
2632 RenderThreadImpl::current()->EstablishGpuChannelSync(
2633 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
[email protected]873da262012-08-10 22:02:472634 collection->GetVideoDecoders()->push_back(new media::GpuVideoDecoder(
[email protected]084c8552012-08-12 22:51:202635 base::Bind(&media::MessageLoopFactory::GetMessageLoop,
2636 base::Unretained(message_loop_factory),
[email protected]c462c902012-09-06 13:13:422637 media::MessageLoopFactory::kDecoder),
[email protected]84a83e192012-03-09 18:43:402638 factories_loop,
[email protected]8d4359282012-01-14 00:53:312639 new RendererGpuVideoDecoderFactories(
[email protected]84a83e192012-03-09 18:43:402640 gpu_channel_host, factories_loop, context3d)));
[email protected]e1d69d762011-12-13 05:12:182641 }
[email protected]e1d69d762011-12-13 05:12:182642
[email protected]5d65fe92012-06-02 00:48:552643 WebMediaPlayer* media_player =
[email protected]da952fd2012-01-13 03:49:252644 content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
2645 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1113bfdf2012-07-16 21:46:102646 audio_source_provider, message_loop_factory, media_stream_impl_,
2647 render_media_log);
[email protected]da952fd2012-01-13 03:49:252648 if (!media_player) {
[email protected]ba42ac4f2012-10-11 20:28:142649#if defined(ENABLE_WEBRTC)
[email protected]5f04c3532012-09-25 01:28:392650 // TODO(wjia): when all patches related to WebMediaPlayerMS have been
2651 // landed, remove the switch. Refer to crbug.com/142988.
[email protected]1fba73c12012-10-10 23:36:202652 if (!cmd_line->HasSwitch(switches::kDisableWebMediaPlayerMS) &&
2653 MediaStreamImpl::CheckMediaStream(url)) {
[email protected]5f04c3532012-09-25 01:28:392654 EnsureMediaStreamImpl();
[email protected]1fba73c12012-10-10 23:36:202655 return new webkit_media::WebMediaPlayerMS(
2656 frame, client, AsWeakPtr(), media_stream_impl_, render_media_log);
[email protected]5f04c3532012-09-25 01:28:392657 }
[email protected]ba42ac4f2012-10-11 20:28:142658#endif
[email protected]5f04c3532012-09-25 01:28:392659
[email protected]cec4eb82012-01-12 17:51:562660 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252661 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1113bfdf2012-07-16 21:46:102662 audio_source_provider, message_loop_factory, media_stream_impl_,
2663 render_media_log);
[email protected]bb6fd402011-12-09 02:45:442664 }
[email protected]cec4eb82012-01-12 17:51:562665 return media_player;
[email protected]3d9689372009-09-10 04:29:172666}
2667
[email protected]310ebd6302011-10-10 19:06:282668WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212669 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232670 if (!frame || !frame->view())
2671 return NULL;
[email protected]035545f2010-04-09 13:10:212672 return new RendererWebApplicationCacheHostImpl(
2673 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442674 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212675}
2676
[email protected]310ebd6302011-10-10 19:06:282677WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382678 return &cookie_jar_;
2679}
2680
[email protected]0720b532012-08-28 19:23:372681void RenderViewImpl::didCreateFrame(WebFrame* parent, WebFrame* child) {
[email protected]0720b532012-08-28 19:23:372682 if (!updating_frame_tree_)
2683 SendUpdatedFrameTree(NULL);
2684}
2685
[email protected]310ebd6302011-10-10 19:06:282686void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]0720b532012-08-28 19:23:372687 if (is_loading_) {
2688 pending_frame_tree_update_ = true;
2689 // Make sure observers are notified, even if we return right away.
2690 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
2691 return;
2692 }
2693 if (!updating_frame_tree_)
2694 SendUpdatedFrameTree(frame);
2695
[email protected]676126f72011-01-15 00:03:512696 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452697}
2698
[email protected]310ebd6302011-10-10 19:06:282699void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512700 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172701}
2702
[email protected]310ebd6302011-10-10 19:06:282703void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172704 WebFrame* frame, const WebURLRequest& request,
2705 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342706 loadURLExternally(frame, request, policy, WebString());
2707}
2708
[email protected]5e92282f2012-08-17 08:11:572709void RenderViewImpl::Repaint(const gfx::Size& size) {
2710 OnMsgRepaint(size);
2711}
2712
[email protected]310ebd6302011-10-10 19:06:282713void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342714 WebFrame* frame, const WebURLRequest& request,
2715 WebNavigationPolicy policy,
2716 const WebString& suggested_name) {
[email protected]56505542012-05-12 00:25:372717 Referrer referrer(
2718 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2719 GetReferrerPolicyFromRequest(frame, request));
[email protected]efce17b2009-09-11 18:04:592720 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342721 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2722 suggested_name));
[email protected]efce17b2009-09-11 18:04:592723 } else {
[email protected]56505542012-05-12 00:25:372724 OpenURL(frame, request.url(), referrer, policy);
[email protected]efce17b2009-09-11 18:04:592725 }
[email protected]3d9689372009-09-10 04:29:172726}
2727
[email protected]310ebd6302011-10-10 19:06:282728WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172729 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222730 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]0639c063a2012-03-22 20:55:332731 Referrer referrer(
2732 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]ca662822012-05-11 17:53:592733 GetReferrerPolicyFromRequest(frame, request));
[email protected]0639c063a2012-03-22 20:55:332734
[email protected]992db4c2011-05-12 15:37:152735 if (is_swapped_out_) {
[email protected]285f4bb82012-04-17 15:57:282736 if (request.url() != GURL(content::kSwappedOutURL)) {
[email protected]0639c063a2012-03-22 20:55:332737 // Targeted links may try to navigate a swapped out frame. Allow the
2738 // browser process to navigate the tab instead. Note that it is also
2739 // possible for non-targeted navigations (from this view) to arrive
2740 // here just after we are swapped out. It's ok to send them to the
2741 // browser, as long as they're for the top level frame.
2742 // TODO(creis): Ensure this supports targeted form submissions when
2743 // fixing http://crbug.com/101395.
2744 if (frame->parent() == NULL) {
2745 OpenURL(frame, request.url(), referrer, default_policy);
2746 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2747 }
2748
2749 // We should otherwise ignore in-process iframe navigations, if they
2750 // arrive just after we are swapped out.
[email protected]73eb2602012-02-09 19:50:552751 return WebKit::WebNavigationPolicyIgnore;
[email protected]0639c063a2012-03-22 20:55:332752 }
[email protected]73eb2602012-02-09 19:50:552753
[email protected]285f4bb82012-04-17 15:57:282754 // Allow content::kSwappedOutURL to complete.
[email protected]992db4c2011-05-12 15:37:152755 return default_policy;
2756 }
2757
[email protected]3d9689372009-09-10 04:29:172758 // Webkit is asking whether to navigate to a new URL.
2759 // This is fine normally, except if we're showing UI from one security
2760 // context and they're trying to navigate to a different context.
2761 const GURL& url = request.url();
2762
[email protected]d19ea342011-04-20 20:31:132763 // A content initiated navigation may have originated from a link-click,
2764 // script, drag-n-drop operation, etc.
2765 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072766 DocumentState::FromDataSource(frame->provisionalDataSource())->
2767 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132768
[email protected]a8c269a2011-10-25 20:17:222769 // Experimental:
2770 // If --enable-strict-site-isolation is enabled, send all top-level
2771 // navigations to the browser to let it swap processes when crossing site
2772 // boundaries. This is currently expected to break some script calls and
2773 // navigations, such as form submissions.
2774 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102775 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2776 !frame->parent() && (is_content_initiated || is_redirect)) {
2777 WebString origin_str = frame->document().securityOrigin().toString();
2778 GURL frame_url(origin_str.utf8().data());
[email protected]18fb7a772012-09-20 19:25:092779 // TODO(cevans): revisit whether this site check is still necessary once
[email protected]313b80bd2011-11-23 03:49:102780 // crbug.com/101395 is fixed.
[email protected]18fb7a772012-09-20 19:25:092781 if (!net::RegistryControlledDomainService::SameDomainOrHost(frame_url,
2782 url) ||
2783 frame_url.scheme() != url.scheme()) {
[email protected]313b80bd2011-11-23 03:49:102784 OpenURL(frame, url, referrer, default_policy);
2785 return WebKit::WebNavigationPolicyIgnore;
2786 }
[email protected]a8c269a2011-10-25 20:17:222787 }
2788
[email protected]fd3238af2012-05-22 18:55:302789 // If the browser is interested, then give it a chance to look at the request.
[email protected]5f000f272012-01-19 05:25:082790 if (is_content_initiated) {
[email protected]fd3238af2012-05-22 18:55:302791 bool browser_handles_request =
2792 renderer_preferences_.browser_handles_non_local_top_level_requests &&
[email protected]5f000f272012-01-19 05:25:082793 IsNonLocalTopLevelNavigation(url, frame, type);
[email protected]fd3238af2012-05-22 18:55:302794 if (!browser_handles_request) {
2795 browser_handles_request =
2796 renderer_preferences_.browser_handles_all_top_level_requests &&
2797 IsTopLevelNavigation(frame);
2798 }
2799
2800 if (browser_handles_request) {
[email protected]5f000f272012-01-19 05:25:082801 // Reset these counters as the RenderView could be reused for the next
2802 // navigation.
2803 page_id_ = -1;
2804 last_page_id_sent_to_browser_ = -1;
2805 OpenURL(frame, url, referrer, default_policy);
2806 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2807 }
[email protected]3d9689372009-09-10 04:29:172808 }
2809
[email protected]dc67e1c32012-06-08 00:10:402810 // Use the frame's original request's URL rather than the document's URL for
2811 // subsequent checks. For a popup, the document's URL may become the opener
2812 // window's URL if the opener has called document.write().
2813 // See http://crbug.com/93517.
2814 GURL old_url(frame->dataSource()->request().url());
2815
[email protected]6101c342010-12-16 22:44:372816 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552817 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:042818 // top-level navigations (not iframes). But we sometimes navigate to
2819 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:372820 //
[email protected]744c2a22012-03-15 18:42:042821 // Note: this is known to break POST submissions when crossing process
2822 // boundaries until http://crbug.com/101395 is fixed. This is better for
2823 // security than loading a WebUI, extension or app page in the wrong process.
2824 // POST requests don't work because this mechanism does not preserve form
2825 // POST data. We will need to send the request's httpBody data up to the
2826 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:572827 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2828 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222829 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:042830 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:372831 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:042832
2833 // All navigations to WebUI URLs or within WebUI-enabled RenderProcesses
2834 // must be handled by the browser process so that the correct bindings and
2835 // data sources can be registered.
2836 // Similarly, navigations to view-source URLs or within ViewSource mode
2837 // must be handled by the browser process.
[email protected]dc67e1c32012-06-08 00:10:402838 // Lastly, access to file:// URLs from non-file:// URL pages must be
2839 // handled by the browser so that ordinary renderer processes don't get
2840 // blessed with file permissions.
2841 int cumulative_bindings = RenderProcess::current()->GetEnabledBindings();
2842 bool is_initial_navigation = page_id_ == -1;
[email protected]6101c342010-12-16 22:44:372843 bool should_fork =
[email protected]744c2a22012-03-15 18:42:042844 content::GetContentClient()->HasWebUIScheme(url) ||
2845 (cumulative_bindings & content::BINDINGS_POLICY_WEB_UI) ||
2846 url.SchemeIs(chrome::kViewSourceScheme) ||
2847 frame->isViewSourceModeEnabled();
[email protected]5351dbc2010-08-27 15:22:112848
[email protected]dc67e1c32012-06-08 00:10:402849 if (!should_fork && url.SchemeIs(chrome::kFileScheme)) {
2850 // Fork non-file to file opens. Check the opener URL if this is the
2851 // initial navigation in a newly opened window.
2852 GURL source_url(old_url);
2853 if (is_initial_navigation && source_url.is_empty() && frame->opener())
2854 source_url = frame->opener()->top()->document().url();
2855 DCHECK(!source_url.is_empty());
2856 should_fork = !source_url.SchemeIs(chrome::kFileScheme);
2857 }
2858
[email protected]e48869a2011-04-01 19:56:032859 if (!should_fork) {
2860 // Give the embedder a chance.
[email protected]744c2a22012-03-15 18:42:042861 // For now, we skip this for POST submissions. This is because
2862 // http://crbug.com/101395 is more likely to cause compatibility issues
2863 // with hosted apps and extensions than WebUI pages. We will remove this
2864 // check when cross-process POST submissions are supported.
2865 if (request.httpMethod() == "GET") {
[email protected]744c2a22012-03-15 18:42:042866 should_fork = content::GetContentClient()->renderer()->ShouldFork(
2867 frame, url, is_initial_navigation, &send_referrer);
2868 }
[email protected]6101c342010-12-16 22:44:372869 }
2870
2871 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152872 OpenURL(
2873 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112874 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2875 }
[email protected]3d9689372009-09-10 04:29:172876 }
2877
2878 // Detect when a page is "forking" a new tab that can be safely rendered in
2879 // its own process. This is done by sites like Gmail that try to open links
2880 // in new windows without script connections back to the original page. We
2881 // treat such cases as browser navigations (in which we will create a new
2882 // renderer for a cross-site navigation), rather than WebKit navigations.
2883 //
2884 // We use the following heuristic to decide whether to fork a new page in its
2885 // own process:
2886 // The parent page must open a new tab to about:blank, set the new tab's
2887 // window.opener to null, and then redirect the tab to a cross-site URL using
2888 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462889 //
2890 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2891 // (see below).
[email protected]3d9689372009-09-10 04:29:172892 bool is_fork =
2893 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582894 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172895 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522896 historyBackListCount() < 1 &&
2897 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172898 // The parent page must have set the child's window.opener to null before
2899 // redirecting to the desired URL.
2900 frame->opener() == NULL &&
2901 // Must be a top-level frame.
2902 frame->parent() == NULL &&
2903 // Must not have issued the request from this page.
2904 is_content_initiated &&
2905 // Must be targeted at the current tab.
2906 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2907 // Must be a JavaScript navigation, which appears as "other".
2908 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462909
[email protected]f92ce2b2012-03-06 18:02:592910 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:172911 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152912 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172913 return WebKit::WebNavigationPolicyIgnore;
2914 }
2915
2916 return default_policy;
2917}
2918
[email protected]310ebd6302011-10-10 19:06:282919bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492920 WebFrame* frame, const WebURLRequest& request) {
2921 // We allow WebKit to think that everything can be handled even though
2922 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342923 return true;
2924}
2925
[email protected]310ebd6302011-10-10 19:06:282926WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492927 WebFrame* frame, const WebURLRequest& request) {
2928 NOTREACHED(); // Since we said we can handle all requests.
2929 return WebURLError();
2930}
2931
[email protected]310ebd6302011-10-10 19:06:282932WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492933 WebFrame* frame, const WebURLRequest& request) {
2934 WebURLError error;
2935 error.domain = WebString::fromUTF8(net::kErrorDomain);
2936 error.reason = net::ERR_ABORTED;
2937 error.unreachableURL = request.url();
2938 return error;
[email protected]7b7a7dc2009-10-19 02:23:342939}
2940
[email protected]310ebd6302011-10-10 19:06:282941void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492942 WebFrame*, const WebURLError&) {
2943 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342944}
2945
[email protected]310ebd6302011-10-10 19:06:282946void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432947 const WebKit::WebFormElement& form) {
2948 // Some login forms have onSubmit handlers that put a hash of the password
2949 // into a hidden field and then clear the password. (Issue 28910.)
2950 // This method gets called before any of those handlers run, so save away
2951 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072952 DocumentState* document_state =
2953 DocumentState::FromDataSource(frame->dataSource());
[email protected]1ecbe862012-10-05 01:29:142954 document_state->set_password_form_data(content::CreatePasswordForm(form));
[email protected]90eeddb2010-05-06 21:06:432955}
2956
[email protected]310ebd6302011-10-10 19:06:282957void RenderViewImpl::willSubmitForm(WebFrame* frame,
2958 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072959 DocumentState* document_state =
2960 DocumentState::FromDataSource(frame->provisionalDataSource());
2961 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172962
[email protected]2905f742011-10-13 03:51:582963 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2964 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172965
2966 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352967 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072968 document_state->set_searchable_form_url(web_searchable_form_data.url());
2969 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212970 web_searchable_form_data.encoding().utf8());
[email protected]a045f4e32012-08-31 09:36:072971 scoped_ptr<PasswordForm> password_form_data =
[email protected]1ecbe862012-10-05 01:29:142972 content::CreatePasswordForm(form);
[email protected]90eeddb2010-05-06 21:06:432973
[email protected]098c95cb2011-04-28 16:49:012974 // In order to save the password that the user actually typed and not one
2975 // that may have gotten transformed by the site prior to submit, recover it
2976 // from the form contents already stored by |willSendSubmitEvent| into the
2977 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2978 // which is what we're storing into now.)
[email protected]a045f4e32012-08-31 09:36:072979 if (password_form_data.get()) {
[email protected]007733c2011-11-17 00:34:072980 DocumentState* old_document_state =
2981 DocumentState::FromDataSource(frame->dataSource());
2982 if (old_document_state) {
2983 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432984 if (old_form_data && old_form_data->action == password_form_data->action)
2985 password_form_data->password_value = old_form_data->password_value;
2986 }
2987 }
[email protected]3d9689372009-09-10 04:29:172988
[email protected]a045f4e32012-08-31 09:36:072989 document_state->set_password_form_data(password_form_data.Pass());
2990
[email protected]2a5b1732011-04-01 23:55:552991 FOR_EACH_OBSERVER(
2992 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172993}
2994
[email protected]310ebd6302011-10-10 19:06:282995void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172996 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2997 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382998 FOR_EACH_OBSERVER(
2999 RenderViewObserver, observers_,
3000 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:173001}
3002
[email protected]310ebd6302011-10-10 19:06:283003void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:383004 FOR_EACH_OBSERVER(
3005 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:173006}
3007
[email protected]310ebd6302011-10-10 19:06:283008void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:173009 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:153010 if (!frame->parent()) {
3011 WebDataSource* ds = frame->provisionalDataSource();
3012 // If there's no provisional data source, it's a reference fragment
3013 // navigation.
3014 completed_client_redirect_src_ = Referrer(
[email protected]ca662822012-05-11 17:53:593015 from, ds ? GetReferrerPolicyFromRequest(frame, ds->request()) :
[email protected]f36f4092012-05-09 18:31:043016 frame->document().referrerPolicy());
[email protected]445e1042011-12-03 21:03:153017 }
[email protected]eb0bff942011-04-07 22:08:383018 FOR_EACH_OBSERVER(
3019 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:173020}
3021
[email protected]310ebd6302011-10-10 19:06:283022void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:573023 bool content_initiated = !pending_navigation_params_.get();
3024
[email protected]007733c2011-11-17 00:34:073025 DocumentState* document_state = DocumentState::FromDataSource(ds);
3026 if (!document_state) {
3027 document_state = new DocumentState;
3028 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:573029 if (!content_initiated)
3030 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:073031 }
3032
[email protected]bf70edce2012-06-20 22:32:223033 // Carry over the user agent override flag, if it exists.
3034 if (content_initiated && webview() && webview()->mainFrame() &&
3035 webview()->mainFrame()->dataSource()) {
3036 DocumentState* old_document_state =
3037 DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
3038 if (old_document_state) {
3039 document_state->set_is_overriding_user_agent(
3040 old_document_state->is_overriding_user_agent());
3041 }
3042 }
3043
[email protected]3d9689372009-09-10 04:29:173044 // The rest of RenderView assumes that a WebDataSource will always have a
3045 // non-null NavigationState.
[email protected]e1ed5a12012-08-08 19:57:443046 if (content_initiated) {
[email protected]007733c2011-11-17 00:34:073047 document_state->set_navigation_state(
3048 NavigationState::CreateContentInitiated());
[email protected]e1ed5a12012-08-08 19:57:443049 } else {
[email protected]45d83a12012-04-06 22:57:573050 document_state->set_navigation_state(CreateNavigationStateFromPending());
3051 pending_navigation_params_.reset();
3052 }
[email protected]8a3125a712010-08-09 18:58:513053
[email protected]007733c2011-11-17 00:34:073054 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:513055 // navigating from a page that used prefetching using a link on that
3056 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:073057 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:513058 // this value appropriately.
3059 // TODO(gavinp): catch the important case of navigation in a new
3060 // renderer process.
3061 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303062 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523063 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513064 const GURL referrer(
3065 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3066 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:073067 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:513068 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:413069 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:513070 WebDataSource* old_frame_ds = old_frame->dataSource();
3071 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:073072 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513073 break;
3074 }
3075 }
3076 }
3077 }
3078 }
3079
[email protected]4c1b6f0b2010-02-07 16:38:183080 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523081 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513082 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183083 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:073084 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:183085 break;
3086 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:073087 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:183088 break;
3089 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:073090 document_state->set_load_type(
3091 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:183092 break;
3093 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:073094 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:183095 break;
3096 }
3097 }
[email protected]fa7b6b542009-11-03 05:02:303098
[email protected]946a0032011-03-31 18:42:283099 FOR_EACH_OBSERVER(
3100 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:173101}
3102
[email protected]45d83a12012-04-06 22:57:573103void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:073104 DocumentState* document_state) {
3105 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:573106 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:073107
[email protected]45d83a12012-04-06 22:57:573108 if (!params.url.SchemeIs(chrome::kJavaScriptScheme) &&
3109 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
3110 // We're doing a load of a page that was restored from the last session. By
3111 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
3112 // can result in stale data for pages that are set to expire. We explicitly
3113 // override that by setting the policy here so that as necessary we load
3114 // from the network.
3115 document_state->set_cache_policy_override(
3116 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:073117 }
3118
3119 if (IsReload(params))
3120 document_state->set_load_type(DocumentState::RELOAD);
3121 else if (!params.state.empty())
3122 document_state->set_load_type(DocumentState::HISTORY_LOAD);
3123 else
3124 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]ca662822012-05-11 17:53:593125
3126 document_state->set_referrer_policy(params.referrer.policy);
[email protected]bf70edce2012-06-20 22:32:223127 document_state->set_is_overriding_user_agent(params.is_overriding_user_agent);
[email protected]a3a5397d2012-09-12 06:50:343128 document_state->set_must_reset_scroll_and_scale_state(
3129 params.navigation_type ==
3130 ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
[email protected]951a64832012-10-11 16:26:373131 document_state->set_can_load_local_resources(params.can_load_local_resources);
[email protected]45d83a12012-04-06 22:57:573132}
[email protected]007733c2011-11-17 00:34:073133
[email protected]45d83a12012-04-06 22:57:573134NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
3135 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
3136 NavigationState* navigation_state = NULL;
3137
3138 // A navigation resulting from loading a javascript URL should not be treated
3139 // as a browser initiated event. Instead, we want it to look as if the page
3140 // initiated any load resulting from JS execution.
3141 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
3142 navigation_state = NavigationState::CreateBrowserInitiated(
3143 params.page_id,
3144 params.pending_history_list_offset,
3145 params.transition);
3146 navigation_state->set_transferred_request_child_id(
3147 params.transferred_request_child_id);
3148 navigation_state->set_transferred_request_request_id(
3149 params.transferred_request_request_id);
[email protected]80744782012-05-04 01:47:003150 navigation_state->set_allow_download(params.allow_download);
[email protected]45d83a12012-04-06 22:57:573151 } else {
3152 navigation_state = NavigationState::CreateContentInitiated();
3153 }
3154 return navigation_state;
[email protected]007733c2011-11-17 00:34:073155}
3156
[email protected]5b52cd2f712012-03-28 02:12:483157void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
3158 bool enable_viewport =
[email protected]06ea34a2012-05-07 18:52:103159 command_line.HasSwitch(switches::kEnableViewport);
[email protected]5b52cd2f712012-03-28 02:12:483160 bool enable_fixed_layout =
3161 command_line.HasSwitch(switches::kEnableFixedLayout);
3162
3163 webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport);
3164 webview()->settings()->setFixedElementsLayoutRelativeToFrame(true);
3165
3166 if (enable_viewport) {
3167 webview()->settings()->setViewportEnabled(true);
3168 } else if (enable_fixed_layout) {
3169 std::string str =
3170 command_line.GetSwitchValueASCII(switches::kEnableFixedLayout);
3171 std::vector<std::string> tokens;
3172 base::SplitString(str, ',', &tokens);
3173 if (tokens.size() == 2) {
3174 int width, height;
3175 if (base::StringToInt(tokens[0], &width) &&
3176 base::StringToInt(tokens[1], &height))
[email protected]e1ed5a12012-08-08 19:57:443177 webview()->setFixedLayoutSize(WebSize(width, height));
[email protected]5b52cd2f712012-03-28 02:12:483178 }
3179 }
[email protected]1c0c9bc2012-10-08 22:41:483180
3181 ProcessAcceleratedPinchZoomFlags(command_line);
3182}
3183
3184void RenderViewImpl::ProcessAcceleratedPinchZoomFlags(
3185 const CommandLine& command_line) {
3186 bool enable_viewport =
3187 command_line.HasSwitch(switches::kEnableViewport);
3188 bool enable_pinch = enable_viewport ||
3189 command_line.HasSwitch(switches::kEnablePinch);
3190 bool enable_pinch_in_compositor =
3191 command_line.HasSwitch(switches::kEnablePinchInCompositor);
3192
3193 if (!enable_pinch &&
3194 webview()->isAcceleratedCompositingActive() &&
3195 webkit_preferences_.apply_default_device_scale_factor_in_compositor &&
3196 device_scale_factor_ != 1) {
3197 // Page scaling is disabled by default when applying a scale factor in the
3198 // compositor since they are currently incompatible.
3199 webview()->setPageScaleFactorLimits(1, 1);
3200 }
3201
3202 if (enable_pinch_in_compositor &&
3203 webview()->isAcceleratedCompositingActive())
3204 webview()->setPageScaleFactorLimits(1, 4);
[email protected]5b52cd2f712012-03-28 02:12:483205}
3206
[email protected]310ebd6302011-10-10 19:06:283207void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173208 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:073209 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:173210
[email protected]3d9689372009-09-10 04:29:173211 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:073212 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:173213 double event_time = ds->triggeringEventTime();
3214 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:073215 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:173216 }
3217
[email protected]05c8e502010-08-15 15:13:523218 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:073219 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:523220
[email protected]3d9689372009-09-10 04:29:173221 bool is_top_most = !frame->parent();
3222 if (is_top_most) {
3223 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133224 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173225
3226 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:153227 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173228 } else if (frame->parent()->isLoading()) {
3229 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003230 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:073231 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:583232 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:173233 }
3234
[email protected]28685da92011-02-07 21:49:173235 FOR_EACH_OBSERVER(
3236 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
3237
[email protected]3d9689372009-09-10 04:29:173238 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:593239 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:263240 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173241}
3242
[email protected]400992b2012-06-14 00:03:543243void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
3244 WebFrame* frame) {
3245 if (frame->parent())
3246 return;
3247 // Received a redirect on the main frame.
3248 WebDataSource* data_source = frame->provisionalDataSource();
3249 if (!data_source) {
3250 // Should only be invoked when we have a data source.
3251 NOTREACHED();
3252 return;
3253 }
3254 std::vector<GURL> redirects;
3255 GetRedirectChain(data_source, &redirects);
3256 if (redirects.size() >= 2) {
3257 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
3258 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
3259 }
3260}
3261
[email protected]310ebd6302011-10-10 19:06:283262void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
3263 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173264 // Notify the browser that we failed a provisional load with an error.
3265 //
3266 // Note: It is important this notification occur before DidStopLoading so the
3267 // SSL manager can react to the provisional load failure before being
3268 // notified the load stopped.
3269 //
3270 WebDataSource* ds = frame->provisionalDataSource();
3271 DCHECK(ds);
3272
3273 const WebURLRequest& failed_request = ds->request();
3274
[email protected]28685da92011-02-07 21:49:173275 FOR_EACH_OBSERVER(
3276 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
3277
[email protected]3d9689372009-09-10 04:29:173278 bool show_repost_interstitial =
3279 (error.reason == net::ERR_CACHE_MISS &&
3280 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:583281
3282 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
3283 params.frame_id = frame->identifier();
3284 params.is_main_frame = !frame->parent();
3285 params.error_code = error.reason;
3286 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
3287 failed_request,
3288 error,
3289 NULL,
3290 &params.error_description);
3291 params.url = error.unreachableURL;
3292 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:173293 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:583294 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:173295
3296 // Don't display an error page if this is simply a cancelled load. Aside
3297 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3298 if (error.reason == net::ERR_ABORTED)
3299 return;
3300
3301 // Make sure we never show errors in view source mode.
3302 frame->enableViewSourceMode(false);
3303
[email protected]007733c2011-11-17 00:34:073304 DocumentState* document_state = DocumentState::FromDataSource(ds);
3305 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173306
3307 // If this is a failed back/forward/reload navigation, then we need to do a
3308 // 'replace' load. This is necessary to avoid messing up session history.
3309 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3310 // as session history is concerned.
3311 //
3312 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3313 // the page id.
3314 //
3315 bool replace =
3316 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:583317 navigation_state->transition_type() ==
3318 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:173319
3320 // If we failed on a browser initiated request, then make sure that our error
3321 // page load is regarded as the same browser initiated request.
3322 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:073323 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
3324 pending_navigation_params_->page_id =
3325 navigation_state->pending_page_id();
3326 pending_navigation_params_->pending_history_list_offset =
3327 navigation_state->pending_history_list_offset();
3328 pending_navigation_params_->transition =
3329 navigation_state->transition_type();
3330 pending_navigation_params_->request_time =
3331 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:173332 }
3333
3334 // Provide the user with a more helpful error page?
3335 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3336 return;
3337
3338 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083339 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173340}
3341
[email protected]310ebd6302011-10-10 19:06:283342void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:173343 WebFrame* frame, const char* data, size_t data_len,
3344 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:073345 DocumentState* document_state =
3346 DocumentState::FromDataSource(frame->dataSource());
3347 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:173348}
3349
[email protected]310ebd6302011-10-10 19:06:283350void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
3351 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:073352 DocumentState* document_state =
3353 DocumentState::FromDataSource(frame->dataSource());
3354 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:173355
[email protected]007733c2011-11-17 00:34:073356 if (document_state->commit_load_time().is_null())
3357 document_state->set_commit_load_time(Time::Now());
3358
[email protected]a3a5397d2012-09-12 06:50:343359 if (document_state->must_reset_scroll_and_scale_state()) {
3360 webview()->resetScrollAndScaleState();
3361 document_state->set_must_reset_scroll_and_scale_state(false);
3362 }
3363
[email protected]3d9689372009-09-10 04:29:173364 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203365 // When we perform a new navigation, we need to update the last committed
3366 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173367 UpdateSessionHistory(frame);
3368
3369 // We bump our Page ID to correspond with the new session history entry.
3370 page_id_ = next_page_id_++;
3371
[email protected]285f4bb82012-04-17 15:57:283372 // Don't update history_page_ids_ (etc) for content::kSwappedOutURL, since
[email protected]58436a12012-03-21 17:10:263373 // we don't want to forget the entry that was there, and since we will
[email protected]285f4bb82012-04-17 15:57:283374 // never come back to content::kSwappedOutURL. Note that we have to call
[email protected]69ddf852012-02-21 23:21:313375 // UpdateSessionHistory and update page_id_ even in this case, so that
3376 // the current entry gets a state update and so that we don't send a
3377 // state update to the wrong entry when we swap back in.
[email protected]285f4bb82012-04-17 15:57:283378 if (GetLoadingUrl(frame) != GURL(content::kSwappedOutURL)) {
[email protected]69ddf852012-02-21 23:21:313379 // Advance our offset in session history, applying the length limit.
3380 // There is now no forward history.
3381 history_list_offset_++;
3382 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
3383 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
3384 history_list_length_ = history_list_offset_ + 1;
3385 history_page_ids_.resize(history_list_length_, -1);
3386 history_page_ids_[history_list_offset_] = page_id_;
3387 }
[email protected]3d9689372009-09-10 04:29:173388 } else {
3389 // Inspect the navigation_state on this frame to see if the navigation
3390 // corresponds to a session history navigation... Note: |frame| may or
3391 // may not be the toplevel frame, but for the case of capturing session
3392 // history, the first committed frame suffices. We keep track of whether
3393 // we've seen this commit before so that only capture session history once
3394 // per navigation.
3395 //
3396 // Note that we need to check if the page ID changed. In the case of a
3397 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3398 // previous URL and the current page ID, which would be wrong.
3399 if (navigation_state->pending_page_id() != -1 &&
3400 navigation_state->pending_page_id() != page_id_ &&
3401 !navigation_state->request_committed()) {
3402 // This is a successful session history navigation!
3403 UpdateSessionHistory(frame);
3404 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003405
3406 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:033407
3408 // If the history list is valid, our list of page IDs should be correct.
3409 DCHECK(history_list_length_ <= 0 ||
3410 history_list_offset_ < 0 ||
3411 history_list_offset_ >= history_list_length_ ||
3412 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:173413 }
3414 }
3415
[email protected]28685da92011-02-07 21:49:173416 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3417 DidCommitProvisionalLoad(frame, is_new_navigation));
3418
[email protected]3d9689372009-09-10 04:29:173419 // Remember that we've already processed this request, so we don't update
3420 // the session history again. We do this regardless of whether this is
3421 // a session history navigation, because if we attempted a session history
3422 // navigation without valid HistoryItem state, WebCore will think it is a
3423 // new navigation.
3424 navigation_state->set_request_committed(true);
3425
3426 UpdateURL(frame);
3427
3428 // If this committed load was initiated by a client redirect, we're
3429 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:153430 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:173431
3432 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273433 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]b2d98762012-09-03 17:04:063434
3435 if (!frame->parent()) { // Only for top frames.
3436 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
3437 if (render_thread_impl) { // Can be NULL in tests.
3438 render_thread_impl->histogram_customizer()->
3439 RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(),
3440 g_view_map.Get().size());
3441 }
3442 }
[email protected]3d9689372009-09-10 04:29:173443}
3444
[email protected]310ebd6302011-10-10 19:06:283445void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:103446 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3447 DidClearWindowObject(frame));
3448
[email protected]b6cb3a842011-06-24 18:28:413449 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:213450 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:253451 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
3452 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:273453 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:173454 }
[email protected]766a7082012-02-03 23:39:153455
3456 if (enabled_bindings_ & content::BINDINGS_POLICY_DOM_AUTOMATION) {
3457 if (!dom_automation_controller_.get())
3458 dom_automation_controller_.reset(new DomAutomationController());
3459 dom_automation_controller_->set_message_sender(
3460 static_cast<content::RenderView*>(this));
3461 dom_automation_controller_->set_routing_id(routing_id());
3462 dom_automation_controller_->BindToJavascript(frame,
3463 "domAutomationController");
3464 }
[email protected]498bc512012-09-21 21:50:083465
3466 content::InjectDoNotTrackBindings(frame);
[email protected]3d9689372009-09-10 04:29:173467}
3468
[email protected]310ebd6302011-10-10 19:06:283469void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173470 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:413471 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:253472 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]87717d0e2012-04-26 02:58:433473 if (frame == webview()->mainFrame())
3474 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:173475 }
[email protected]e48869a2011-04-01 19:56:033476
3477 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3478 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:173479}
3480
[email protected]310ebd6302011-10-10 19:06:283481void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
3482 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:463483 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:173484
3485 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273486 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173487}
3488
[email protected]310ebd6302011-10-10 19:06:283489void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:133490 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3491 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:583492}
3493
[email protected]310ebd6302011-10-10 19:06:283494void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173495 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073496 DocumentState* document_state = DocumentState::FromDataSource(ds);
3497 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:173498
[email protected]622474d2010-11-04 09:21:083499 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173500
[email protected]28685da92011-02-07 21:49:173501 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3502 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173503
3504 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273505 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173506}
3507
[email protected]310ebd6302011-10-10 19:06:283508void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083509 if (webview()->mainFrame() == frame) {
3510 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3511 page_id_));
3512 }
[email protected]3d9689372009-09-10 04:29:173513}
3514
[email protected]310ebd6302011-10-10 19:06:283515void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:313516 WebDataSource* ds = frame->dataSource();
3517 DCHECK(ds);
3518
3519
[email protected]28685da92011-02-07 21:49:173520 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:313521
3522 const WebURLRequest& failed_request = ds->request();
3523 string16 error_description;
3524 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
3525 failed_request,
3526 error,
3527 NULL,
3528 &error_description);
3529 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
3530 frame->identifier(),
3531 failed_request.url(),
3532 !frame->parent(),
3533 error.reason,
3534 error_description));
[email protected]3d9689372009-09-10 04:29:173535}
3536
[email protected]310ebd6302011-10-10 19:06:283537void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173538 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073539 DocumentState* document_state = DocumentState::FromDataSource(ds);
3540 if (document_state->finish_load_time().is_null())
3541 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:413542
[email protected]676126f72011-01-15 00:03:513543 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173544
[email protected]1a55c5be2011-11-29 11:36:313545 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
3546 frame->identifier(),
3547 ds->request().url(),
3548 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:173549}
3550
[email protected]310ebd6302011-10-10 19:06:283551void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173552 WebFrame* frame, bool is_new_navigation) {
3553 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:073554 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:173555 // update the ExtraData on the datasource so that others who read the
3556 // ExtraData will get the new NavigationState. Similarly, if we did not
3557 // initiate this navigation, then we need to take care to reset any pre-
3558 // existing navigation state to a content-initiated navigation state.
3559 // DidCreateDataSource conveniently takes care of this for us.
3560 didCreateDataSource(frame, frame->dataSource());
3561
[email protected]007733c2011-11-17 00:34:073562 DocumentState* document_state =
3563 DocumentState::FromDataSource(frame->dataSource());
3564 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:093565 new_state->set_was_within_same_page(true);
3566
[email protected]3d9689372009-09-10 04:29:173567 didCommitProvisionalLoad(frame, is_new_navigation);
3568
[email protected]750fcf872011-08-03 23:10:473569 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
3570 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:173571}
3572
[email protected]310ebd6302011-10-10 19:06:283573void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313574 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593575}
3576
[email protected]310ebd6302011-10-10 19:06:283577void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:173578 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3579 // Ignore
3580}
3581
[email protected]310ebd6302011-10-10 19:06:283582void RenderViewImpl::willSendRequest(WebFrame* frame,
3583 unsigned identifier,
3584 WebURLRequest& request,
3585 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303586 WebFrame* top_frame = frame->top();
3587 if (!top_frame)
3588 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513589 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3590 WebDataSource* top_data_source = top_frame->dataSource();
3591 WebDataSource* data_source =
3592 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:223593
[email protected]2905f742011-10-13 03:51:583594 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:073595 DocumentState* document_state = DocumentState::FromDataSource(data_source);
[email protected]def55e022012-07-26 01:15:293596 DCHECK(document_state);
[email protected]007733c2011-11-17 00:34:073597 NavigationState* navigation_state = document_state->navigation_state();
[email protected]e1ed5a12012-08-08 19:57:443598 transition_type = navigation_state->transition_type();
3599
3600 GURL request_url(request.url());
3601 GURL new_url;
3602 if (content::GetContentClient()->renderer()->WillSendRequest(
3603 frame, transition_type, request_url, &new_url)) {
3604 request.setURL(WebURL(new_url));
3605 }
3606
[email protected]def55e022012-07-26 01:15:293607 if (document_state->is_cache_policy_override_set())
3608 request.setCachePolicy(document_state->cache_policy_override());
[email protected]8a3125a712010-08-09 18:58:513609
[email protected]ca662822012-05-11 17:53:593610 WebKit::WebReferrerPolicy referrer_policy;
3611 if (document_state && document_state->is_referrer_policy_set()) {
3612 referrer_policy = document_state->referrer_policy();
3613 document_state->clear_referrer_policy();
3614 } else {
3615 referrer_policy = frame->document().referrerPolicy();
3616 }
3617
[email protected]e372f3d2012-07-17 19:16:443618 // The request's extra data may indicate that we should set a custom user
3619 // agent. This needs to be done here, after WebKit is through with setting the
3620 // user agent on its own.
3621 WebString custom_user_agent;
3622 if (request.extraData()) {
3623 webkit_glue::WebURLRequestExtraDataImpl* old_extra_data =
3624 static_cast<webkit_glue::WebURLRequestExtraDataImpl*>(
3625 request.extraData());
3626 custom_user_agent = old_extra_data->custom_user_agent();
3627
3628 if (!custom_user_agent.isNull()) {
3629 if (custom_user_agent.isEmpty())
3630 request.clearHTTPHeaderField("User-Agent");
3631 else
3632 request.setHTTPHeaderField("User-Agent", custom_user_agent);
3633 }
3634 }
3635
[email protected]91043a8232011-11-04 16:41:193636 request.setExtraData(
[email protected]ca662822012-05-11 17:53:593637 new RequestExtraData(referrer_policy,
[email protected]e372f3d2012-07-17 19:16:443638 custom_user_agent,
[email protected]537fbe02011-11-24 00:58:063639 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:193640 frame->identifier(),
3641 frame->parent() == top_frame,
3642 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]80744782012-05-04 01:47:003643 navigation_state->allow_download(),
[email protected]4ad5d77d2011-12-03 02:00:483644 transition_type,
3645 navigation_state->transferred_request_child_id(),
3646 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:573647
[email protected]007733c2011-11-17 00:34:073648 DocumentState* top_document_state =
3649 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:573650 // TODO(gavinp): separate out prefetching and prerender field trials
3651 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:073652 if (top_document_state &&
[email protected]925dec1c2012-05-18 05:09:003653 request.targetType() == WebURLRequest::TargetIsPrefetch)
[email protected]007733c2011-11-17 00:34:073654 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513655
[email protected]3d9689372009-09-10 04:29:173656 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133657 request.setHasUserGesture(frame->isProcessingUserGesture());
3658
[email protected]0a8db0d2011-04-13 15:15:403659 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:133660 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:173661}
3662
[email protected]310ebd6302011-10-10 19:06:283663void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173664 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493665
[email protected]3d9689372009-09-10 04:29:173666 // Only do this for responses that correspond to a provisional data source
3667 // of the top-most frame. If we have a provisional data source, then we
3668 // can't have any sub-resources yet, so we know that this response must
3669 // correspond to a frame load.
3670 if (!frame->provisionalDataSource() || frame->parent())
3671 return;
3672
3673 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083674 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173675 if (frame->isViewSourceModeEnabled())
3676 return;
3677
[email protected]007733c2011-11-17 00:34:073678 DocumentState* document_state =
3679 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083680 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533681
[email protected]972ebdff2010-06-10 22:59:073682 // Record page load flags.
[email protected]007733c2011-11-17 00:34:073683 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3684 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]b9fd01ba2012-02-28 01:50:403685 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
3686 if (extra_data) {
3687 document_state->set_npn_negotiated_protocol(
3688 extra_data->npn_negotiated_protocol());
3689 }
[email protected]007733c2011-11-17 00:34:073690 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:573691 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:073692 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3693 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093694 // Whether or not the http status code actually corresponds to an error is
3695 // only checked when the page is done loading, if |use_error_page| is
3696 // still true.
[email protected]007733c2011-11-17 00:34:073697 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173698}
3699
[email protected]310ebd6302011-10-10 19:06:283700void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173701 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:073702 DocumentState* document_state =
3703 DocumentState::FromDataSource(frame->dataSource());
3704 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173705 return;
3706
[email protected]7bfc153f2011-09-23 22:00:203707 // Do not show error page when DevTools is attached.
3708 if (devtools_agent_->IsAttached())
3709 return;
3710
[email protected]06333afe2011-02-24 14:55:093711 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:073712 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:083713 if (http_status_code == 404) {
3714 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413715 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173716
[email protected]b6cb3a842011-06-24 18:28:413717 const GURL& error_page_url =
3718 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093719 if (error_page_url.is_valid()) {
3720 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473721 original_error.domain = "http";
3722 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413723 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173724
[email protected]007733c2011-11-17 00:34:073725 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093726 new AltErrorPageResourceFetcher(
3727 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:083728 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3729 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093730 return;
3731 }
3732 }
[email protected]3d9689372009-09-10 04:29:173733
[email protected]e6a2ce52011-10-08 01:40:133734 std::string error_domain;
3735 if (content::GetContentClient()->renderer()->HasErrorPage(
3736 http_status_code, &error_domain)) {
3737 WebURLError error;
3738 error.unreachableURL = frame->document().url();
3739 error.domain = WebString::fromUTF8(error_domain);
3740 error.reason = http_status_code;
3741
3742 LoadNavigationErrorPage(
3743 frame, frame->dataSource()->request(), error, std::string(), true);
3744 }
[email protected]3d9689372009-09-10 04:29:173745}
3746
[email protected]310ebd6302011-10-10 19:06:283747void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173748 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3749 // Ignore
3750}
3751
[email protected]310ebd6302011-10-10 19:06:283752void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173753 WebFrame* frame, const WebURLRequest& request,
3754 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003755 // The recipients of this message have no use for data: URLs: they don't
3756 // affect the page's insecure content list and are not in the disk cache. To
3757 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3758 // filter them out here.
3759 GURL url(request.url());
3760 if (url.SchemeIs("data"))
3761 return;
3762
[email protected]3d9689372009-09-10 04:29:173763 // Let the browser know we loaded a resource from the memory cache. This
3764 // message is needed to display the correct SSL indicators.
3765 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3766 routing_id_,
[email protected]84703292011-10-28 20:44:003767 url,
[email protected]70435962011-08-02 20:13:283768 response.securityInfo(),
3769 request.httpMethod().utf8(),
[email protected]6d6cfb3a2012-05-23 22:53:183770 response.mimeType().utf8(),
[email protected]70435962011-08-02 20:13:283771 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173772}
3773
[email protected]310ebd6302011-10-10 19:06:283774void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293775 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3776}
3777
[email protected]310ebd6302011-10-10 19:06:283778void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023779 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293780 Send(new ViewHostMsg_DidRunInsecureContent(
3781 routing_id_,
[email protected]92771112011-01-20 00:13:023782 origin.toString().utf8(),
3783 target));
[email protected]e3d60e5d2009-09-25 21:08:293784}
3785
[email protected]310ebd6302011-10-10 19:06:283786void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173787 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3788}
3789
[email protected]310ebd6302011-10-10 19:06:283790void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3791 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583792 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283793 int world_id) {
[email protected]5bc10932011-09-21 21:03:303794 content::GetContentClient()->renderer()->DidCreateScriptContext(
[email protected]a00fe692012-02-27 05:52:583795 frame, context, extension_group, world_id);
3796}
3797
[email protected]310ebd6302011-10-10 19:06:283798void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3799 v8::Handle<v8::Context> context,
3800 int world_id) {
[email protected]5bc10932011-09-21 21:03:303801 content::GetContentClient()->renderer()->WillReleaseScriptContext(
3802 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283803}
3804
[email protected]310ebd6302011-10-10 19:06:283805void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073806 // We don't always want to send the change messages over IPC, only if we've
3807 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3808 // message.
3809 if (!send_preferred_size_changes_ || !webview())
3810 return;
3811
[email protected]705243f2010-05-05 19:58:073812 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3813 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533814
3815 // In the presence of zoom, these sizes are still reported as if unzoomed,
3816 // so we need to adjust.
3817 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3818 size.set_width(static_cast<int>(size.width() * zoom_factor));
3819 size.set_height(static_cast<int>(size.height() * zoom_factor));
3820
[email protected]705243f2010-05-05 19:58:073821 if (size == preferred_size_)
3822 return;
[email protected]c27324b2009-11-19 22:44:293823
[email protected]705243f2010-05-05 19:58:073824 preferred_size_ = size;
3825 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3826 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173827}
3828
[email protected]1842fe22012-08-13 23:24:353829WebGraphicsContext3D* RenderViewImpl::CreateGraphicsContext3D(
3830 const WebGraphicsContext3D::Attributes& attributes) {
3831 if (!webview())
3832 return NULL;
3833
3834 if (GetGuestToEmbedderChannel()) {
3835 WebGraphicsContext3DCommandBufferImpl* context =
3836 GetGuestToEmbedderChannel()->CreateWebGraphicsContext3D(
3837 this, attributes, false);
3838 if (!guest_pp_instance()) {
3839 guest_uninitialized_context_ = context;
3840 guest_attributes_ = attributes;
3841 }
3842 return context;
3843 }
3844
3845 // The WebGraphicsContext3DInProcessImpl code path is used for
3846 // layout tests (though not through this code) as well as for
3847 // debugging and bringing up new ports.
3848 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
3849 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
3850 attributes, true);
3851 } else {
3852 GURL url;
3853 if (webview()->mainFrame())
3854 url = GURL(webview()->mainFrame()->document().url());
3855 else
[email protected]f89e173a2012-08-24 01:12:263856 url = GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
[email protected]1842fe22012-08-13 23:24:353857
3858 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
3859 new WebGraphicsContext3DCommandBufferImpl(
3860 surface_id(),
3861 url,
3862 RenderThreadImpl::current(),
3863 AsWeakPtr()));
3864
3865 if (!context->Initialize(
3866 attributes,
3867 false /* bind generates resources */,
3868 content::CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
3869 return NULL;
3870 return context.release();
3871 }
3872}
3873
[email protected]0720b532012-08-28 19:23:373874// The browser process needs to know the shape of the tree, as well as the names
3875// and ids of all frames. This allows it to properly route JavaScript messages
3876// across processes and frames. The serialization format is described in the
3877// comments of the ViewMsg_FrameTreeUpdated message.
3878// This function sends those updates to the browser and updates the RVH
3879// corresponding to this object. It must be called on any events that modify
3880// the tree structure or the names of any frames.
3881void RenderViewImpl::SendUpdatedFrameTree(
3882 WebKit::WebFrame* exclude_frame_subtree) {
[email protected]e12dbe6f2012-10-04 22:11:193883 // TODO(nasko): Frame tree updates are causing issues with postMessage, as
3884 // described in http://crbug.com/153701. Disable them until a proper fix is
3885 // in place.
[email protected]0720b532012-08-28 19:23:373886}
3887
3888void RenderViewImpl::CreateFrameTree(WebKit::WebFrame* frame,
3889 DictionaryValue* frame_tree) {
[email protected]e12dbe6f2012-10-04 22:11:193890 // TODO(nasko): Remove once http://crbug.com/153701 is fixed.
3891 DCHECK(false);
[email protected]0720b532012-08-28 19:23:373892 NavigateToSwappedOutURL(frame);
3893
3894 string16 name;
3895 if (frame_tree->GetString(content::kFrameTreeNodeNameKey, &name) &&
[email protected]5604fb5c2012-09-20 03:29:313896 !name.empty()) {
[email protected]0720b532012-08-28 19:23:373897 frame->setName(name);
3898 }
3899
3900 int remote_id;
3901 if (frame_tree->GetInteger(content::kFrameTreeNodeIdKey, &remote_id))
3902 active_frame_id_map_.insert(std::pair<int, int>(frame->identifier(),
3903 remote_id));
3904
3905 ListValue* children;
3906 if (!frame_tree->GetList(content::kFrameTreeNodeSubtreeKey, &children))
3907 return;
3908
[email protected]5fa9b36b2012-09-21 18:14:273909 // Create an invisible iframe tree in the swapped out page.
[email protected]0720b532012-08-28 19:23:373910 base::DictionaryValue* child;
3911 for (size_t i = 0; i < children->GetSize(); ++i) {
3912 if (!children->GetDictionary(i, &child))
3913 continue;
3914 WebElement element = frame->document().createElement("iframe");
[email protected]5fa9b36b2012-09-21 18:14:273915 element.setAttribute("width", "0");
3916 element.setAttribute("height", "0");
3917 element.setAttribute("frameBorder", "0");
[email protected]0720b532012-08-28 19:23:373918 if (frame->document().body().appendChild(element)) {
3919 WebFrame* subframe = WebFrame::fromFrameOwnerElement(element);
3920 if (subframe)
3921 CreateFrameTree(subframe, child);
3922 } else {
3923 LOG(ERROR) << "Failed to append created iframe element.";
3924 }
3925 }
3926}
3927
[email protected]d1a59e42012-10-03 18:05:353928WebKit::WebFrame* RenderViewImpl::GetFrameByRemoteID(int remote_frame_id) {
3929 std::map<int, int>::const_iterator it = active_frame_id_map_.begin();
3930 for (; it != active_frame_id_map_.end(); ++it) {
3931 if (it->second == remote_frame_id)
3932 return FindFrameByID(webview()->mainFrame(), it->first);
3933 }
3934 return NULL;
[email protected]0720b532012-08-28 19:23:373935}
3936
[email protected]273558fb2012-01-12 15:03:513937void RenderViewImpl::EnsureMediaStreamImpl() {
[email protected]7082fb942012-05-16 23:44:593938 if (!RenderThreadImpl::current()) // Will be NULL during unit tests.
[email protected]08381562012-05-15 20:55:403939 return;
3940
[email protected]4fb0f202012-05-30 22:44:533941#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:513942 if (!media_stream_dispatcher_)
3943 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3944
[email protected]1bc65a42012-04-23 09:31:253945 if (!media_stream_impl_) {
[email protected]273558fb2012-01-12 15:03:513946 media_stream_impl_ = new MediaStreamImpl(
[email protected]1bc65a42012-04-23 09:31:253947 this,
[email protected]273558fb2012-01-12 15:03:513948 media_stream_dispatcher_,
[email protected]273558fb2012-01-12 15:03:513949 RenderThreadImpl::current()->video_capture_impl_manager(),
[email protected]6ee10bd2012-09-13 09:01:533950 RenderThreadImpl::current()->GetMediaStreamDependencyFactory());
[email protected]273558fb2012-01-12 15:03:513951 }
[email protected]5b87e782012-02-09 18:19:323952#endif
[email protected]273558fb2012-01-12 15:03:513953}
3954
[email protected]310ebd6302011-10-10 19:06:283955void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3956 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313957 if (webview()->mainFrame() != frame)
3958 return;
3959 WebView* frameView = frame->view();
3960 if (!frameView)
3961 return;
3962
3963 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3964 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3965
3966 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3967 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3968 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3969 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3970
3971 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3972 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3973 }
3974}
3975
[email protected]310ebd6302011-10-10 19:06:283976void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313977 WebSize offset = frame->scrollOffset();
3978 WebSize minimum_offset = frame->minimumScrollOffset();
3979 WebSize maximum_offset = frame->maximumScrollOffset();
3980
3981 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3982 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3983
3984 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3985 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3986 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3987 routing_id_, is_pinned_to_left, is_pinned_to_right));
3988
3989 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3990 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3991 }
3992}
3993
[email protected]310ebd6302011-10-10 19:06:283994void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493995 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313996
3997 if (webview()->mainFrame() == frame)
3998 UpdateScrollState(frame);
[email protected]2b942c332012-04-25 16:26:263999
4000 FOR_EACH_OBSERVER(
4001 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]dd6afca2011-08-13 03:44:314002}
4003
[email protected]55750b32012-09-21 14:05:034004void RenderViewImpl::SendFindReply(int request_id,
4005 int match_count,
4006 int ordinal,
4007 const WebRect& selection_rect,
4008 bool final_status_update) {
4009#if defined(OS_ANDROID)
4010 if (synchronous_find_reply_message_.get()) {
4011 if (final_status_update) {
4012 ViewMsg_SynchronousFind::WriteReplyParams(
4013 synchronous_find_reply_message_.get(),
4014 match_count,
4015 match_count ? synchronous_find_active_match_ordinal_ : 0);
4016 Send(synchronous_find_reply_message_.release());
4017 }
4018 return;
4019 }
4020#endif
4021
4022 Send(new ViewHostMsg_Find_Reply(routing_id_,
4023 request_id,
4024 match_count,
4025 selection_rect,
4026 ordinal,
4027 final_status_update));
4028}
4029
4030void RenderViewImpl::reportFindInPageMatchCount(int request_id,
4031 int count,
[email protected]310ebd6302011-10-10 19:06:284032 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:114033 int active_match_ordinal = -1; // -1 = don't update active match ordinal
4034 if (!count)
4035 active_match_ordinal = 0;
4036
[email protected]55750b32012-09-21 14:05:034037 // Send the search result over to the browser process.
4038 SendFindReply(request_id,
4039 count,
4040 active_match_ordinal,
4041 gfx::Rect(),
4042 final_update);
[email protected]8922e1f2009-10-03 05:01:264043}
4044
[email protected]310ebd6302011-10-10 19:06:284045void RenderViewImpl::reportFindInPageSelection(int request_id,
4046 int active_match_ordinal,
4047 const WebRect& selection_rect) {
[email protected]55750b32012-09-21 14:05:034048#if defined(OS_ANDROID)
4049 // If this was a SynchronousFind request, we need to remember the ordinal
4050 // value here for replying when reportFindInPageMatchCount is called.
4051 if (synchronous_find_reply_message_.get()) {
4052 synchronous_find_active_match_ordinal_ = active_match_ordinal;
4053 return;
4054 }
4055#endif
4056
4057 SendFindReply(request_id,
4058 -1,
4059 active_match_ordinal,
4060 selection_rect,
4061 false);
[email protected]8922e1f2009-10-03 05:01:264062}
4063
[email protected]310ebd6302011-10-10 19:06:284064void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:224065 WebFrame* frame,
4066 WebFileSystem::Type type,
4067 long long size,
[email protected]d275d7a2010-11-03 01:34:494068 bool create,
[email protected]2b06a992010-08-21 05:48:224069 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:084070 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:224071
[email protected]b6cb3a842011-06-24 18:28:414072 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564073 if (origin.isUnique()) {
4074 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:084075 callbacks->didFail(WebKit::WebFileErrorAbort);
4076 return;
4077 }
[email protected]2b06a992010-08-21 05:48:224078
[email protected]c5a272d2010-09-27 18:37:084079 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
4080 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:494081 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:224082}
4083
[email protected]d5e08552012-08-02 21:43:404084void RenderViewImpl::deleteFileSystem(
4085 WebFrame* frame,
4086 WebFileSystem::Type type ,
4087 WebFileSystemCallbacks* callbacks) {
4088 DCHECK(callbacks);
4089
4090 WebSecurityOrigin origin = frame->document().securityOrigin();
4091 if (origin.isUnique()) {
4092 // Unique origins cannot store persistent state.
4093 callbacks->didSucceed();
4094 return;
4095 }
4096
4097 ChildThread::current()->file_system_dispatcher()->DeleteFileSystem(
4098 GURL(origin.toString()),
4099 static_cast<fileapi::FileSystemType>(type),
4100 new WebFileSystemCallbackDispatcher(callbacks));
4101}
4102
[email protected]310ebd6302011-10-10 19:06:284103void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:404104 WebFrame* frame,
4105 WebStorageQuotaType type,
4106 WebStorageQuotaCallbacks* callbacks) {
4107 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:414108 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564109 if (origin.isUnique()) {
4110 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:404111 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
4112 return;
4113 }
4114 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:534115 GURL(origin.toString()),
4116 static_cast<quota::StorageType>(type),
4117 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:404118}
4119
[email protected]310ebd6302011-10-10 19:06:284120void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:404121 WebFrame* frame,
4122 WebStorageQuotaType type,
4123 unsigned long long requested_size,
4124 WebStorageQuotaCallbacks* callbacks) {
4125 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:414126 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:564127 if (origin.isUnique()) {
4128 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:404129 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
4130 return;
4131 }
4132 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:534133 routing_id(), GURL(origin.toString()),
4134 static_cast<quota::StorageType>(type), requested_size,
4135 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:404136}
4137
[email protected]8b5af492011-11-28 21:50:584138void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:154139 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]3a3b75a2012-06-01 08:38:364140 webkit_glue::WebIntentServiceData data(service);
4141 if (data.title.empty())
4142 data.title = webview()->mainFrame()->document().title();
4143 bool user_gesture = frame->isProcessingUserGesture();
[email protected]8b5af492011-11-28 21:50:584144 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
[email protected]3a3b75a2012-06-01 08:38:364145 data,
4146 user_gesture));
[email protected]8b5af492011-11-28 21:50:584147}
4148
[email protected]ffc8bed2012-01-21 01:23:154149void RenderViewImpl::dispatchIntent(
4150 WebFrame* frame, const WebIntentRequest& intentRequest) {
4151 webkit_glue::WebIntentData intent_data(intentRequest.intent());
[email protected]4e1eb3392012-05-18 00:08:054152
4153 // See WebMessagePortChannelImpl::postMessage() and ::OnMessagedQueued()
4154 WebKit::WebMessagePortChannelArray* channels =
4155 intentRequest.intent().messagePortChannelsRelease();
4156 if (channels) {
4157 for (size_t i = 0; i < channels->size(); ++i) {
4158 WebMessagePortChannelImpl* webchannel =
4159 static_cast<WebMessagePortChannelImpl*>((*channels)[i]);
4160 intent_data.message_port_ids.push_back(webchannel->message_port_id());
4161 DCHECK(intent_data.message_port_ids[i] != MSG_ROUTING_NONE);
4162 }
4163 delete channels;
4164 }
4165
[email protected]ffc8bed2012-01-21 01:23:154166 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:584167 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:154168 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:584169}
4170
[email protected]f546640b2012-05-15 00:03:494171bool RenderViewImpl::willCheckAndDispatchMessageEvent(
[email protected]0720b532012-08-28 19:23:374172 WebKit::WebFrame* sourceFrame,
4173 WebKit::WebFrame* targetFrame,
[email protected]f546640b2012-05-15 00:03:494174 WebKit::WebSecurityOrigin target_origin,
4175 WebKit::WebDOMMessageEvent event) {
4176 if (!is_swapped_out_)
4177 return false;
4178
4179 ViewMsg_PostMessage_Params params;
4180 params.data = event.data().toString();
4181 params.source_origin = event.origin();
4182 if (!target_origin.isNull())
4183 params.target_origin = target_origin.toString();
4184
4185 // Include the routing ID for the source frame, which the browser process
4186 // will translate into the routing ID for the equivalent frame in the target
4187 // process.
[email protected]f546640b2012-05-15 00:03:494188 params.source_routing_id = MSG_ROUTING_NONE;
[email protected]0720b532012-08-28 19:23:374189 RenderViewImpl* source_view = FromWebView(sourceFrame->view());
[email protected]f546640b2012-05-15 00:03:494190 if (source_view)
4191 params.source_routing_id = source_view->routing_id();
[email protected]0720b532012-08-28 19:23:374192 params.source_frame_id = sourceFrame->identifier();
4193
4194 // Include the process, route, and frame IDs of the target frame. This allows
4195 // the browser to detect races between this message being sent and the target
4196 // frame no longer being valid.
4197 params.target_process_id = target_process_id_;
4198 params.target_routing_id = target_routing_id_;
4199
4200 std::map<int,int>::iterator it = active_frame_id_map_.find(
4201 targetFrame->identifier());
4202 if (it != active_frame_id_map_.end()) {
4203 params.target_frame_id = it->second;
4204 } else {
4205 params.target_frame_id = 0;
4206 }
[email protected]f546640b2012-05-15 00:03:494207
4208 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params));
4209 return true;
4210}
4211
[email protected]5fa3a062012-03-21 15:39:344212void RenderViewImpl::willOpenSocketStream(
4213 WebSocketStreamHandle* handle) {
4214 SocketStreamHandleData::AddToHandle(handle, routing_id_);
4215}
4216
[email protected]ccee4862012-10-03 18:34:264217void RenderViewImpl::willStartUsingPeerConnectionHandler(
4218 WebKit::WebFrame* frame, WebKit::WebRTCPeerConnectionHandler* handler) {
4219#if defined(ENABLE_WEBRTC)
4220 static_cast<RTCPeerConnectionHandler*>(handler)->associateWithFrame(frame);
4221#endif
4222}
4223
[email protected]bf70edce2012-06-20 22:32:224224WebKit::WebString RenderViewImpl::userAgentOverride(
4225 WebKit::WebFrame* frame,
4226 const WebKit::WebURL& url) {
4227 if (!webview() || !webview()->mainFrame() ||
4228 renderer_preferences_.user_agent_override.empty()) {
4229 return WebKit::WebString();
4230 }
4231
4232 // If we're in the middle of committing a load, the data source we need
4233 // will still be provisional.
4234 WebFrame* main_frame = webview()->mainFrame();
4235 WebDataSource* data_source = NULL;
4236 if (main_frame->provisionalDataSource())
4237 data_source = main_frame->provisionalDataSource();
4238 else
4239 data_source = main_frame->dataSource();
4240
4241 DocumentState* document_state =
4242 data_source ? DocumentState::FromDataSource(data_source) : NULL;
4243 if (document_state && document_state->is_overriding_user_agent())
4244 return WebString::fromUTF8(renderer_preferences_.user_agent_override);
4245 else
4246 return WebKit::WebString();
4247}
4248
[email protected]18d5be92011-07-25 18:00:194249// WebKit::WebPageSerializerClient implementation ------------------------------
4250
[email protected]310ebd6302011-10-10 19:06:284251void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:194252 const WebURL& frame_url,
4253 const WebCString& data,
4254 WebPageSerializerClient::PageSerializationStatus status) {
4255 Send(new ViewHostMsg_SendSerializedHtmlData(
4256 routing_id(),
4257 frame_url,
4258 data.data(),
4259 static_cast<int32>(status)));
4260}
4261
[email protected]a2ef54c2011-10-10 16:20:314262// content::RenderView implementation ------------------------------------------
4263
[email protected]310ebd6302011-10-10 19:06:284264bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:314265 return RenderWidget::Send(message);
4266}
4267
[email protected]82114f52012-03-20 22:53:414268int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:314269 return routing_id_;
4270}
4271
[email protected]82114f52012-03-20 22:53:414272int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:314273 return page_id_;
4274}
4275
[email protected]82114f52012-03-20 22:53:414276gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:314277 return size();
4278}
4279
[email protected]82114f52012-03-20 22:53:414280WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:314281 return webkit_preferences_;
4282}
4283
[email protected]82114f52012-03-20 22:53:414284WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:314285 return webview();
4286}
4287
[email protected]82114f52012-03-20 22:53:414288WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:314289 if (!webview())
4290 return WebNode();
4291 WebFrame* focused_frame = webview()->focusedFrame();
4292 if (focused_frame) {
4293 WebDocument doc = focused_frame->document();
4294 if (!doc.isNull())
4295 return doc.focusedNode();
4296 }
4297
4298 return WebNode();
4299}
4300
[email protected]82114f52012-03-20 22:53:414301WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:314302 return context_menu_node_;
4303}
4304
[email protected]2a84f9d2012-06-05 21:50:434305bool RenderViewImpl::IsEditableNode(const WebNode& node) const {
4306 if (node.isNull())
4307 return false;
4308
4309 if (node.isContentEditable())
4310 return true;
4311
4312 if (node.isElementNode()) {
4313 const WebElement& element = node.toConst<WebElement>();
4314 if (element.isTextFormControlElement())
4315 return true;
4316
4317 // Also return true if it has an ARIA role of 'textbox'.
4318 for (unsigned i = 0; i < element.attributeCount(); ++i) {
4319 if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) {
4320 if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox"))
4321 return true;
4322 break;
4323 }
[email protected]a2ef54c2011-10-10 16:20:314324 }
4325 }
[email protected]2a84f9d2012-06-05 21:50:434326
4327 return false;
[email protected]a2ef54c2011-10-10 16:20:314328}
4329
[email protected]468e4902012-05-23 01:49:314330void RenderViewImpl::GuestReady(PP_Instance instance) {
4331 guest_pp_instance_ = instance;
4332 if (guest_uninitialized_context_) {
[email protected]7900bfdb2012-05-24 19:31:244333 bool success = GetGuestToEmbedderChannel()->CreateGraphicsContext(
[email protected]468e4902012-05-23 01:49:314334 guest_uninitialized_context_,
4335 guest_attributes_,
4336 false,
4337 this);
4338 DCHECK(success);
[email protected]7900bfdb2012-05-24 19:31:244339 CompleteInit(host_window_);
4340 guest_uninitialized_context_ = NULL;
[email protected]468e4902012-05-23 01:49:314341 }
[email protected]468e4902012-05-23 01:49:314342}
4343
4344webkit::ppapi::WebPluginImpl* RenderViewImpl::CreateBrowserPlugin(
4345 const IPC::ChannelHandle& channel_handle,
4346 int guest_process_id,
4347 const WebKit::WebPluginParams& params) {
4348 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
4349 pepper_delegate_.CreateBrowserPluginModule(channel_handle,
4350 guest_process_id));
4351 return new webkit::ppapi::WebPluginImpl(
4352 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
4353}
4354
[email protected]310ebd6302011-10-10 19:06:284355WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:314356 WebKit::WebFrame* frame,
4357 const webkit::WebPluginInfo& info,
[email protected]82114f52012-03-20 22:53:414358 const WebKit::WebPluginParams& params) {
[email protected]a2ef54c2011-10-10 16:20:314359 bool pepper_plugin_was_registered = false;
4360 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
4361 pepper_delegate_.CreatePepperPluginModule(info,
4362 &pepper_plugin_was_registered));
4363 if (pepper_plugin_was_registered) {
4364 if (!pepper_module)
4365 return NULL;
4366 return new webkit::ppapi::WebPluginImpl(
4367 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
4368 }
4369
[email protected]3e076a82012-09-11 19:12:364370#if defined(USE_AURA) && !defined(OS_WIN)
[email protected]34b27e442012-01-20 20:07:414371 return NULL;
4372#else
[email protected]a2ef54c2011-10-10 16:20:314373 return new webkit::npapi::WebPluginImpl(
4374 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:414375#endif
[email protected]a2ef54c2011-10-10 16:20:314376}
4377
[email protected]310ebd6302011-10-10 19:06:284378void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
4379 const string16& jscript,
4380 int id,
4381 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:314382 v8::Handle<v8::Value> result;
4383 WebFrame* web_frame = GetChildFrame(frame_xpath);
4384 if (web_frame)
4385 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
4386 if (notify_result) {
4387 ListValue list;
4388 if (!result.IsEmpty() && web_frame) {
4389 v8::HandleScope handle_scope;
4390 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4391 v8::Context::Scope context_scope(context);
4392 V8ValueConverterImpl converter;
[email protected]3de391e82012-05-16 17:50:514393 converter.SetDateAllowed(true);
[email protected]e0658bc2012-09-17 04:05:244394 converter.SetRegExpAllowed(true);
4395 base::Value* result_value = converter.FromV8Value(result, context);
4396 list.Set(0, result_value ? result_value :
4397 base::Value::CreateNullValue());
[email protected]a2ef54c2011-10-10 16:20:314398 } else {
4399 list.Set(0, Value::CreateNullValue());
4400 }
4401 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
4402 }
4403}
4404
[email protected]310ebd6302011-10-10 19:06:284405bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:314406 return (!send_preferred_size_changes_ ||
4407 (disable_scrollbars_size_limit_.width() <= width ||
4408 disable_scrollbars_size_limit_.height() <= height));
4409}
4410
[email protected]82114f52012-03-20 22:53:414411int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:314412 return enabled_bindings_;
4413}
4414
[email protected]82114f52012-03-20 22:53:414415bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:314416 return send_content_state_immediately_;
4417}
4418
[email protected]82114f52012-03-20 22:53:414419float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:314420 return filtered_time_per_frame();
4421}
4422
[email protected]310ebd6302011-10-10 19:06:284423void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
[email protected]82114f52012-03-20 22:53:414424 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:314425 showContextMenu(frame, data);
4426}
4427
[email protected]82114f52012-03-20 22:53:414428WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:314429 return visibilityState();
4430}
4431
[email protected]310ebd6302011-10-10 19:06:284432void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
4433 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:314434 return runModalAlertDialog(frame, message);
4435}
4436
[email protected]310ebd6302011-10-10 19:06:284437void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:314438 WebKit::WebFrame* frame,
4439 const WebKit::WebURLRequest& request,
4440 WebKit::WebNavigationPolicy policy) {
4441 loadURLExternally(frame, request, policy);
4442}
4443
4444// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:514445
[email protected]310ebd6302011-10-10 19:06:284446webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:534447 const FilePath& file_path,
4448 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:204449 if (!PluginChannelHost::IsListening()) {
4450 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:594451 return NULL;
[email protected]94752ee2012-02-10 10:38:204452 }
[email protected]f103ab72009-09-02 17:10:594453
[email protected]00c39612010-03-06 02:53:284454 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:464455 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:324456#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:224457 return webkit::npapi::WebPluginDelegateImpl::Create(
4458 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:094459#else
[email protected]7398dcc2011-09-06 21:40:324460 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:224461 NOTIMPLEMENTED();
4462 return NULL;
[email protected]7b6616f2010-01-14 18:07:554463#endif
[email protected]f103ab72009-09-02 17:10:594464 }
4465
[email protected]4e0616e2010-05-28 14:55:534466 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:594467}
4468
[email protected]6ac77cb2012-05-01 14:49:014469WebKit::WebPlugin* RenderViewImpl::CreatePluginReplacement(
4470 const FilePath& file_path) {
4471 return content::GetContentClient()->renderer()->CreatePluginReplacement(
4472 this, file_path);
4473}
4474
[email protected]310ebd6302011-10-10 19:06:284475void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034476#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:274477 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:594478#endif
4479}
4480
[email protected]310ebd6302011-10-10 19:06:284481void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034482#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:274483 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:594484#endif
4485 CleanupWindowInPluginMoves(window);
4486}
4487
[email protected]310ebd6302011-10-10 19:06:284488void RenderViewImpl::DidMovePlugin(
4489 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:594490 SchedulePluginMove(move);
4491}
4492
[email protected]310ebd6302011-10-10 19:06:284493void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:594494 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524495 didStartLoading();
[email protected]f103ab72009-09-02 17:10:594496}
4497
[email protected]310ebd6302011-10-10 19:06:284498void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:594499 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524500 didStopLoading();
[email protected]f103ab72009-09-02 17:10:594501}
4502
[email protected]310ebd6302011-10-10 19:06:284503WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:514504 return &cookie_jar_;
4505}
4506
[email protected]5d65fe92012-06-02 00:48:554507void RenderViewImpl::DidPlay(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074508 Send(new ViewHostMsg_MediaNotification(routing_id_,
4509 reinterpret_cast<int64>(player),
4510 player->hasVideo(),
4511 player->hasAudio(),
4512 true));
4513}
4514
[email protected]5d65fe92012-06-02 00:48:554515void RenderViewImpl::DidPause(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074516 Send(new ViewHostMsg_MediaNotification(routing_id_,
4517 reinterpret_cast<int64>(player),
4518 player->hasVideo(),
4519 player->hasAudio(),
4520 false));
4521}
4522
[email protected]5d65fe92012-06-02 00:48:554523void RenderViewImpl::PlayerGone(WebKit::WebMediaPlayer* player) {
[email protected]baff4512011-10-19 18:21:074524 DidPause(player);
4525}
4526
[email protected]310ebd6302011-10-10 19:06:284527void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:294528 if (!webview())
4529 return;
4530
[email protected]26aa0482009-09-30 16:55:274531 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:054532 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:294533}
4534
[email protected]310ebd6302011-10-10 19:06:284535void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:364536 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:004537 if (!frame)
4538 return;
[email protected]b781ff282011-08-20 06:19:364539
[email protected]e99ef6f2011-10-16 01:13:004540 string16 text;
4541 size_t offset;
[email protected]3c8c74c2012-03-15 07:34:524542 ui::Range range;
[email protected]e99ef6f2011-10-16 01:13:004543
[email protected]3c8c74c2012-03-15 07:34:524544 if (pepper_delegate_.IsPluginFocused()) {
4545 pepper_delegate_.GetSurroundingText(&text, &range);
[email protected]82114f52012-03-20 22:53:414546 offset = 0; // Pepper API does not support offset reporting.
[email protected]3c8c74c2012-03-15 07:34:524547 // TODO(kinaba): cut as needed.
[email protected]e99ef6f2011-10-16 01:13:004548 } else {
[email protected]3c8c74c2012-03-15 07:34:524549 size_t location, length;
4550 if (!webview()->caretOrSelectionRange(&location, &length))
4551 return;
4552
4553 range = ui::Range(location, location + length);
4554
4555 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
4556 // If current focused element is editable, we will send 100 more chars
4557 // before and after selection. It is for input method surrounding text
4558 // feature.
4559 if (location > kExtraCharsBeforeAndAfterSelection)
4560 offset = location - kExtraCharsBeforeAndAfterSelection;
4561 else
4562 offset = 0;
4563 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
4564 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
4565 if (!webrange.isNull())
4566 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
4567 } else {
4568 offset = location;
4569 text = frame->selectionAsText();
4570 // http://crbug.com/101435
4571 // In some case, frame->selectionAsText() returned text's length is not
4572 // equal to the length returned from webview()->caretOrSelectionRange().
4573 // So we have to set the range according to text.length().
4574 range.set_end(range.start() + text.length());
4575 }
[email protected]b781ff282011-08-20 06:19:364576 }
4577
[email protected]b781ff282011-08-20 06:19:364578 // Sometimes we get repeated didChangeSelection calls from webkit when
4579 // the selection hasn't actually changed. We don't want to report these
4580 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:004581 if (selection_text_offset_ != offset ||
4582 selection_range_ != range ||
4583 selection_text_ != text) {
4584 selection_text_ = text;
4585 selection_text_offset_ = offset;
4586 selection_range_ = range;
4587 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
4588 }
[email protected]b781ff282011-08-20 06:19:364589}
4590
[email protected]310ebd6302011-10-10 19:06:284591GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
4592 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554593 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294594 // If the URL that failed was secure, then the embedding web page was not
4595 // expecting a network attacker to be able to manipulate its contents. As
4596 // we fetch alternate error pages over HTTP, we would be allowing a network
4597 // attacker to manipulate the contents of the response if we tried to use
4598 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154599 return GURL();
initial.commit09911bf2008-07-26 23:55:294600 }
4601
4602 // Grab the base URL from the browser process.
4603 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154604 return GURL();
initial.commit09911bf2008-07-26 23:55:294605
4606 // Strip query params from the failed URL.
4607 GURL::Replacements remove_params;
4608 remove_params.ClearUsername();
4609 remove_params.ClearPassword();
4610 remove_params.ClearQuery();
4611 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554612 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504613 std::string spec_to_send = url_to_send.spec();
4614 // Notify link doctor of the url truncation by sending of "?" at the end.
4615 if (failed_url.has_query())
[email protected]82114f52012-03-20 22:53:414616 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294617
4618 // Construct the query params to send to link doctor.
4619 std::string params(alternate_error_page_url_.query());
4620 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:024621 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294622 params.append("&sourceid=chrome");
4623 params.append("&error=");
4624 switch (error_type) {
4625 case DNS_ERROR:
4626 params.append("dnserror");
4627 break;
4628
4629 case HTTP_404:
4630 params.append("http404");
4631 break;
4632
[email protected]5df266ac2008-10-15 19:50:134633 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334634 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134635 break;
4636
initial.commit09911bf2008-07-26 23:55:294637 default:
4638 NOTREACHED() << "unknown ErrorPageType";
4639 }
4640
4641 // OK, build the final url to return.
4642 GURL::Replacements link_doctor_params;
4643 link_doctor_params.SetQueryStr(params);
4644 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4645 return url;
4646}
4647
[email protected]310ebd6302011-10-10 19:06:284648GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:594649 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
4650 return GURL();
4651 else
4652 return creator_url_;
4653}
4654
[email protected]69ddf852012-02-21 23:21:314655GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
4656 WebDataSource* ds = frame->dataSource();
4657 if (ds->hasUnreachableURL())
4658 return ds->unreachableURL();
4659
4660 const WebURLRequest& request = ds->request();
4661 return request.url();
4662}
4663
[email protected]310ebd6302011-10-10 19:06:284664WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:274665 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:314666 web_ui_bindings_.reset(new WebUIBindings(
4667 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:464668 }
[email protected]c50008512011-02-03 01:17:274669 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:464670}
4671
[email protected]310ebd6302011-10-10 19:06:284672WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:014673 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494674}
4675
[email protected]55750b32012-09-21 14:05:034676void RenderViewImpl::OnFind(int request_id,
4677 const string16& search_text,
[email protected]310ebd6302011-10-10 19:06:284678 const WebFindOptions& options) {
[email protected]55750b32012-09-21 14:05:034679#if defined(OS_ANDROID)
4680 // Make sure any asynchronous messages do not disrupt an ongoing synchronous
4681 // find request as it might lead to deadlocks. Also, these should be safe to
4682 // ignore since they would belong to a previous find request.
4683 if (synchronous_find_reply_message_.get())
4684 return;
4685#endif
4686 Find(request_id, search_text, options);
4687}
4688
4689void RenderViewImpl::Find(int request_id,
4690 const string16& search_text,
4691 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274692 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494693
[email protected]872542532011-06-23 00:43:164694 // Check if the plugin still exists in the document.
4695 if (main_frame->document().isPluginDocument() &&
4696 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494697 if (options.findNext) {
4698 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014699 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494700 } else {
[email protected]55750b32012-09-21 14:05:034701 if (!GetWebPluginFromPluginDocument()->startFind(
[email protected]afdbd142010-07-10 08:01:234702 search_text, options.matchCase, request_id)) {
[email protected]e7c58a32010-08-13 19:47:114703 // Send "no results".
[email protected]55750b32012-09-21 14:05:034704 SendFindReply(request_id, 0, 0, gfx::Rect(), true);
[email protected]24a7f3c2010-03-25 08:26:494705 }
4706 }
4707 return;
4708 }
4709
[email protected]b4bb2502009-10-01 22:35:274710 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274711 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294712 WebFrame* search_frame = focused_frame; // start searching focused frame.
4713
4714 bool multi_frame = (frame_after_main != main_frame);
4715
4716 // If we have multiple frames, we don't want to wrap the search within the
4717 // frame, so we check here if we only have main_frame in the chain.
4718 bool wrap_within_frame = !multi_frame;
4719
[email protected]b3f2b912009-04-09 16:18:524720 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294721 bool result = false;
4722
[email protected]7830da3e2009-11-06 16:27:264723 // If something is selected when we start searching it means we cannot just
4724 // increment the current match ordinal; we need to re-generate it.
4725 WebRange current_selection = focused_frame->selectionRange();
4726
initial.commit09911bf2008-07-26 23:55:294727 do {
[email protected]dd7daa82009-08-10 05:46:454728 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594729 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294730
4731 if (!result) {
4732 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:224733 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294734
4735 // Find the next frame, but skip the invisible ones.
4736 do {
4737 // What is the next frame to search? (we might be going backwards). Note
4738 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594739 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274740 search_frame->traverseNext(true) :
4741 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454742 } while (!search_frame->hasVisibleContent() &&
4743 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294744
[email protected]884db412008-11-24 23:46:504745 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:224746 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294747
4748 // If we have multiple frames and we have wrapped back around to the
4749 // focused frame, we need to search it once more allowing wrap within
4750 // the frame, otherwise it will report 'no match' if the focused frame has
4751 // reported matches, but no frames after the focused_frame contain a
4752 // match for the search word(s).
4753 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454754 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594755 request_id, search_text, options, true, // Force wrapping.
4756 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294757 }
4758 }
4759
[email protected]26aa0482009-09-30 16:55:274760 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294761 } while (!result && search_frame != focused_frame);
4762
[email protected]7830da3e2009-11-06 16:27:264763 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294764 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454765 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294766 } else {
4767 // If nothing is found, set result to "0 of 0", otherwise, set it to
4768 // "-1 of 1" to indicate that we found at least one item, but we don't know
4769 // yet what is active.
4770 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4771 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294772
[email protected]4f3dc372009-02-24 00:10:294773 // If we find no matches then this will be our last status update.
4774 // Otherwise the scoping effort will send more results.
4775 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294776
[email protected]55750b32012-09-21 14:05:034777 SendFindReply(request_id, match_count, ordinal, selection_rect,
4778 final_status_update);
initial.commit09911bf2008-07-26 23:55:294779
initial.commit09911bf2008-07-26 23:55:294780 // Scoping effort begins, starting with the mainframe.
4781 search_frame = main_frame;
4782
[email protected]dd7daa82009-08-10 05:46:454783 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294784
4785 do {
4786 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454787 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294788
4789 // We don't start another scoping effort unless at least one match has
4790 // been found.
4791 if (result) {
4792 // Start new scoping request. If the scoping function determines that it
4793 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454794 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594795 search_text,
4796 options,
initial.commit09911bf2008-07-26 23:55:294797 true); // reset the tickmarks
4798 }
4799
4800 // Iterate to the next frame. The frame will not necessarily scope, for
4801 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274802 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294803 } while (search_frame != main_frame);
4804 }
4805}
4806
[email protected]815dd9872011-11-23 18:40:304807void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]55750b32012-09-21 14:05:034808#if defined(OS_ANDROID)
4809 // Make sure any asynchronous messages do not disrupt an ongoing synchronous
4810 // find request as it might lead to deadlocks. Also, these should be safe to
4811 // ignore since they would belong to a previous find request.
4812 if (synchronous_find_reply_message_.get())
4813 return;
4814#endif
4815
4816 StopFinding(action);
4817}
4818
4819void RenderViewImpl::StopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:494820 WebView* view = webview();
4821 if (!view)
4822 return;
4823
4824 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:164825 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014826 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494827 return;
4828 }
4829
[email protected]815dd9872011-11-23 18:40:304830 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:494831 if (clear_selection)
4832 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4833
4834 WebFrame* frame = view->mainFrame();
4835 while (frame) {
4836 frame->stopFinding(clear_selection);
4837 frame = frame->traverseNext(false);
4838 }
4839
[email protected]815dd9872011-11-23 18:40:304840 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:494841 WebFrame* focused_frame = view->focusedFrame();
4842 if (focused_frame) {
4843 WebDocument doc = focused_frame->document();
4844 if (!doc.isNull()) {
4845 WebNode node = doc.focusedNode();
4846 if (!node.isNull())
4847 node.simulateClick();
4848 }
4849 }
4850 }
4851}
4852
[email protected]59363fc92012-09-05 03:46:314853#if defined(OS_ANDROID)
[email protected]55750b32012-09-21 14:05:034854void RenderViewImpl::OnSynchronousFind(int request_id,
4855 const string16& search_string,
4856 const WebFindOptions& options,
4857 IPC::Message* reply_msg) {
4858 // It is impossible for simultaneous blocking finds to occur.
4859 CHECK(!synchronous_find_reply_message_.get());
4860 synchronous_find_reply_message_.reset(reply_msg);
4861
4862 // Find next should be asynchronous in order to minimize blocking
4863 // the UI thread as much as possible.
4864 DCHECK(!options.findNext);
4865 StopFinding(content::STOP_FIND_ACTION_KEEP_SELECTION);
4866 synchronous_find_active_match_ordinal_ = -1;
4867
4868 Find(request_id, search_string, options);
4869}
4870
[email protected]59363fc92012-09-05 03:46:314871void RenderViewImpl::OnActivateNearestFindResult(int request_id,
4872 float x, float y) {
4873 if (!webview())
4874 return;
4875
4876 WebFrame* main_frame = webview()->mainFrame();
4877 WebRect selection_rect;
4878 int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y),
4879 &selection_rect);
4880 if (ordinal == -1) {
4881 // Something went wrong, so send a no-op reply (force the main_frame to
4882 // report the current match count) in case the host is waiting for a
4883 // response due to rate-limiting).
4884 main_frame->increaseMatchCount(0, request_id);
4885 return;
4886 }
4887
[email protected]55750b32012-09-21 14:05:034888 SendFindReply(request_id,
4889 -1 /* number_of_matches */,
4890 ordinal,
4891 selection_rect,
4892 true /* final_update */);
[email protected]59363fc92012-09-05 03:46:314893}
4894
4895void RenderViewImpl::OnFindMatchRects(int current_version) {
4896 if (!webview())
4897 return;
4898
4899 WebFrame* main_frame = webview()->mainFrame();
4900 std::vector<gfx::RectF> match_rects;
4901
4902 int rects_version = main_frame->findMatchMarkersVersion();
4903 if (current_version != rects_version) {
4904 WebVector<WebFloatRect> web_match_rects;
4905 main_frame->findMatchRects(web_match_rects);
4906 match_rects.reserve(web_match_rects.size());
4907 for (size_t i = 0; i < web_match_rects.size(); ++i)
4908 match_rects.push_back(gfx::RectF(web_match_rects[i]));
4909 }
4910
4911 gfx::RectF active_rect = main_frame->activeFindMatchRect();
4912 Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_,
4913 rects_version,
4914 match_rects,
4915 active_rect));
4916}
4917#endif
4918
[email protected]54087fe2011-10-28 22:02:484919void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:514920 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4921 return;
4922
[email protected]258d31122010-05-09 10:59:414923 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:104924
[email protected]b75b8292010-10-01 07:28:254925 double old_zoom_level = webview()->zoomLevel();
4926 double zoom_level;
[email protected]54087fe2011-10-28 22:02:484927 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:254928 zoom_level = 0;
4929 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4930 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:484931 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:254932 } else {
4933 // Either the user hit the zoom factor limit and thus the zoom level is now
4934 // not a whole number, or a plugin changed it to a custom value. We want
4935 // to go to the next whole number so that the user can always get back to
4936 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:484937 if ((old_zoom_level > 1 && zoom > 0) ||
4938 (old_zoom_level < 1 && zoom < 0)) {
4939 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:254940 } else {
4941 // We're going towards 100%, so first go to the next whole number.
4942 zoom_level = static_cast<int>(old_zoom_level);
4943 }
4944 }
[email protected]b75b8292010-10-01 07:28:254945 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:414946 zoomLevelChanged();
4947}
4948
4949void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
4950 int zoom_center_x, int zoom_center_y) {
4951 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
4952 kScalingIncrementForGesture);
4953}
4954
4955void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
4956 int zoom_center_x,
4957 int zoom_center_y,
4958 float scaling_increment) {
4959 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4960 return;
4961
[email protected]c514d6372011-08-16 22:54:444962 double old_page_scale_factor = webview()->pageScaleFactor();
4963 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:484964 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:444965 page_scale_factor = 1.0;
4966 } else {
4967 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:414968 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:444969 }
[email protected]47578fa02011-11-02 19:34:414970 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:094971 webview()->setPageScaleFactor(page_scale_factor,
4972 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:414973 }
[email protected]40bd6582009-12-04 23:49:514974}
4975
[email protected]310ebd6302011-10-10 19:06:284976void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174977 webview()->hidePopups();
4978 webview()->setZoomLevel(false, zoom_level);
4979 zoomLevelChanged();
4980}
4981
[email protected]310ebd6302011-10-10 19:06:284982void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4983 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544984 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294985}
4986
[email protected]310ebd6302011-10-10 19:06:284987void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274988 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294989}
4990
[email protected]310ebd6302011-10-10 19:06:284991void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274992 WebString no_encoding;
4993 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184994}
4995
[email protected]310ebd6302011-10-10 19:06:284996WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454997 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274998 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454999
5000 // xpath string can represent a frame deep down the tree (across multiple
5001 // frame DOMs).
5002 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
5003 // should break into 2 xpaths
5004 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:415005 std::vector<string16> xpaths;
5006 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:455007
[email protected]26aa0482009-09-30 16:55:275008 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:415009 for (std::vector<string16>::const_iterator i = xpaths.begin();
5010 frame && i != xpaths.end(); ++i) {
5011 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:295012 }
5013
[email protected]dd7daa82009-08-10 05:46:455014 return frame;
initial.commit09911bf2008-07-26 23:55:295015}
5016
[email protected]310ebd6302011-10-10 19:06:285017void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
5018 const string16& jscript,
5019 int id,
5020 bool notify_result) {
[email protected]01d43ef92012-09-25 00:54:105021 TRACE_EVENT_INSTANT0("test_tracing", "OnScriptEvalRequest");
[email protected]882b7b22010-10-05 03:34:535022 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:295023}
5024
[email protected]f546640b2012-05-15 00:03:495025void RenderViewImpl::OnPostMessageEvent(
5026 const ViewMsg_PostMessage_Params& params) {
[email protected]0720b532012-08-28 19:23:375027 // Find the target frame of this message. The source tags the message with
5028 // |target_frame_id|, so use it to locate the frame.
[email protected]e12dbe6f2012-10-04 22:11:195029 // TODO(nasko): Lookup based on the frame id, once http://crbug.com/153701
5030 // is fixed and we can rely on having frame tree updates again.
5031 WebFrame* frame = webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:495032
5033 // Find the source frame if it exists.
[email protected]f546640b2012-05-15 00:03:495034 WebFrame* source_frame = NULL;
5035 if (params.source_routing_id != MSG_ROUTING_NONE) {
5036 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
[email protected]e12dbe6f2012-10-04 22:11:195037 // TODO(nasko): Lookup based on the frame id, once http://crbug.com/153701
5038 // is fixed and we can rely on having frame tree updates again.
[email protected]f546640b2012-05-15 00:03:495039 if (source_view)
[email protected]e12dbe6f2012-10-04 22:11:195040 source_frame = source_view->webview()->mainFrame();
[email protected]f546640b2012-05-15 00:03:495041 }
5042
5043 // Create an event with the message. The final parameter to initMessageEvent
5044 // is the last event ID, which is not used with postMessage.
5045 WebDOMEvent event = frame->document().createEvent("MessageEvent");
5046 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
5047 msg_event.initMessageEvent("message",
5048 // |canBubble| and |cancellable| are always false
5049 false, false,
5050 WebSerializedScriptValue::fromString(params.data),
5051 params.source_origin, source_frame, "");
5052
5053 // We must pass in the target_origin to do the security check on this side,
5054 // since it may have changed since the original postMessage call was made.
5055 WebSecurityOrigin target_origin;
5056 if (!params.target_origin.empty()) {
5057 target_origin =
5058 WebSecurityOrigin::createFromString(WebString(params.target_origin));
5059 }
5060 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
5061}
5062
[email protected]310ebd6302011-10-10 19:06:285063void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
5064 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:415065 WebFrame* frame = GetChildFrame(frame_xpath);
5066 if (!frame)
[email protected]216813952011-05-19 22:21:265067 return;
[email protected]ae461542009-06-19 19:03:415068
[email protected]01cf589c2011-07-28 18:04:035069 frame->document().insertUserStyleSheet(
5070 WebString::fromUTF8(css),
5071 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:485072}
5073
[email protected]310ebd6302011-10-10 19:06:285074void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:095075 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:045076
5077 // Keep track of the total bindings accumulated in this process.
5078 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:295079}
5080
[email protected]310ebd6302011-10-10 19:06:285081void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
5082 const std::string& value) {
[email protected]808bda52012-03-09 22:43:325083 if (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI)
5084 GetWebUIBindings()->SetProperty(name, value);
5085 else
5086 NOTREACHED() << "WebUI bindings not enabled.";
initial.commit09911bf2008-07-26 23:55:295087}
5088
[email protected]310ebd6302011-10-10 19:06:285089void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
5090 const gfx::Point& client_point,
5091 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:425092 WebDragOperationsMask ops,
5093 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:555094 WebDragOperation operation = webview()->dragTargetDragEnter(
5095 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:555096 client_point,
5097 screen_point,
[email protected]1f2230b2012-05-17 23:43:425098 ops,
5099 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555100
5101 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5102}
5103
[email protected]310ebd6302011-10-10 19:06:285104void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
5105 const gfx::Point& screen_point,
[email protected]1f2230b2012-05-17 23:43:425106 WebDragOperationsMask ops,
5107 int key_modifiers) {
[email protected]59f4f2fa2011-03-23 01:00:555108 WebDragOperation operation = webview()->dragTargetDragOver(
5109 client_point,
5110 screen_point,
[email protected]1f2230b2012-05-17 23:43:425111 ops,
5112 key_modifiers);
[email protected]59f4f2fa2011-03-23 01:00:555113
5114 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
5115}
5116
[email protected]310ebd6302011-10-10 19:06:285117void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:555118 webview()->dragTargetDragLeave();
5119}
5120
[email protected]310ebd6302011-10-10 19:06:285121void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
[email protected]1f2230b2012-05-17 23:43:425122 const gfx::Point& screen_point,
5123 int key_modifiers) {
5124 webview()->dragTargetDrop(client_point, screen_point, key_modifiers);
[email protected]fcad49452011-06-28 17:11:575125
5126 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:555127}
5128
[email protected]310ebd6302011-10-10 19:06:285129void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
5130 const gfx::Point& screen_point,
5131 bool ended,
5132 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:035133 if (ended) {
[email protected]26aa0482009-09-30 16:55:275134 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:205135 } else {
5136 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:035137 }
initial.commit09911bf2008-07-26 23:55:295138}
5139
[email protected]310ebd6302011-10-10 19:06:285140void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:275141 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:295142}
5143
[email protected]310ebd6302011-10-10 19:06:285144void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:595145 webkit_preferences_ = prefs;
5146 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:295147}
5148
[email protected]310ebd6302011-10-10 19:06:285149void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:295150 alternate_error_page_url_ = url;
5151}
5152
[email protected]310ebd6302011-10-10 19:06:285153void RenderViewImpl::OnCustomContextMenuAction(
[email protected]35be7ec2012-02-12 20:42:515154 const content::CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:085155 unsigned action) {
5156 if (custom_context.is_pepper_menu)
5157 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
5158 else
5159 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:585160 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
5161 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:335162}
5163
[email protected]310ebd6302011-10-10 19:06:285164void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:515165 int id,
5166 const std::vector<FilePath>& paths) {
5167 if (!enumeration_completions_[id])
5168 return;
5169
5170 WebVector<WebString> ws_file_names(paths.size());
5171 for (size_t i = 0; i < paths.size(); ++i)
5172 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
5173
5174 enumeration_completions_[id]->didChooseFile(ws_file_names);
5175 enumeration_completions_.erase(id);
5176}
5177
[email protected]fb11b6a42012-03-14 07:25:125178void RenderViewImpl::OnFileChooserResponse(
[email protected]ddb034b2012-06-26 20:31:395179 const std::vector<ui::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:365180 // This could happen if we navigated to a different page before the user
5181 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:475182 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:365183 return;
5184
[email protected]b5188522012-03-15 00:18:045185 // Convert Chrome's SelectedFileInfo list to WebKit's.
5186 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
5187 files.size());
5188 for (size_t i = 0; i < files.size(); ++i) {
5189 WebFileChooserCompletion::SelectedFileInfo selected_file;
[email protected]53f04c82012-07-26 02:31:095190 selected_file.path = webkit_glue::FilePathToWebString(files[i].local_path);
[email protected]b5188522012-03-15 00:18:045191 selected_file.displayName = webkit_glue::FilePathStringToWebString(
5192 files[i].display_name);
5193 selected_files[i] = selected_file;
5194 }
[email protected]a1128322009-10-06 18:38:465195
[email protected]cdaf8d02010-03-30 19:52:475196 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:045197 file_chooser_completions_.front()->completion->didChooseFile(
5198 selected_files);
[email protected]cdaf8d02010-03-30 19:52:475199 file_chooser_completions_.pop_front();
5200
5201 // If there are more pending file chooser requests, schedule one now.
5202 if (!file_chooser_completions_.empty()) {
5203 Send(new ViewHostMsg_RunFileChooser(routing_id_,
5204 file_chooser_completions_.front()->params));
5205 }
initial.commit09911bf2008-07-26 23:55:295206}
5207
[email protected]244ac1892011-12-02 17:04:475208void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
5209 const gfx::Size& max_size) {
5210 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5211 if (!webview())
5212 return;
[email protected]61e2b3cc2012-03-02 16:13:345213 webview()->enableAutoResizeMode(min_size, max_size);
5214}
5215
5216void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
5217 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
5218 if (!webview())
5219 return;
5220 webview()->disableAutoResizeMode();
5221
5222 Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK);
[email protected]244ac1892011-12-02 17:04:475223}
5224
[email protected]2bf834f2011-11-17 20:02:215225void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:245226 if (send_preferred_size_changes_)
5227 return;
[email protected]9fb325e2010-05-06 18:23:245228 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:395229
[email protected]d812fd12011-05-27 23:05:075230 // Start off with an initial preferred size notification (in case
5231 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:595232 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:085233}
5234
[email protected]310ebd6302011-10-10 19:06:285235void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:105236 const gfx::Size& disable_scrollbar_size_limit) {
5237 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
5238}
5239
[email protected]310ebd6302011-10-10 19:06:285240void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:315241 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:505242 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:515243 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:375244 UpdateFontRenderingFromRendererPrefs();
[email protected]a13283cc2012-04-05 00:21:225245#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:415246 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
5247 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:465248 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]f78452f2012-05-15 02:07:525249 ui::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:345250 renderer_prefs.thumb_inactive_color,
5251 renderer_prefs.thumb_active_color,
5252 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:555253#endif
[email protected]93623c5d2009-12-10 21:40:325254
[email protected]a13283cc2012-04-05 00:21:225255#if defined(USE_ASH) || defined(TOOLKIT_GTK)
[email protected]644d77e2010-01-27 01:03:105256 if (webview()) {
[email protected]a13283cc2012-04-05 00:21:225257#if defined(TOOLKIT_GTK)
[email protected]93623c5d2009-12-10 21:40:325258 webview()->setScrollbarColors(
5259 renderer_prefs.thumb_inactive_color,
5260 renderer_prefs.thumb_active_color,
5261 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:555262#endif
[email protected]644d77e2010-01-27 01:03:105263 webview()->setSelectionColors(
5264 renderer_prefs.active_selection_bg_color,
5265 renderer_prefs.active_selection_fg_color,
5266 renderer_prefs.inactive_selection_bg_color,
5267 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:465268 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:105269 }
[email protected]7a74e102009-09-03 00:16:565270#endif
[email protected]d299d972012-03-23 02:26:555271
[email protected]d051d9a2011-12-10 02:02:505272 // If the zoom level for this page matches the old zoom default, and this
5273 // is not a plugin, update the zoom level to match the new default.
5274 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
5275 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
5276 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
5277 zoomLevelChanged();
5278 }
[email protected]80d96fa2009-06-10 22:34:515279}
5280
[email protected]310ebd6302011-10-10 19:06:285281void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
5282 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:285283 if (webview())
5284 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:565285}
5286
[email protected]77829642012-05-15 14:47:175287void RenderViewImpl::OnOrientationChangeEvent(int orientation) {
5288 webview()->mainFrame()->sendOrientationChangeEvent(orientation);
5289}
5290
[email protected]81375e872012-01-11 21:40:365291void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
5292 const WebPluginAction& action) {
5293 if (webview())
5294 webview()->performPluginAction(action, location);
5295}
5296
[email protected]310ebd6302011-10-10 19:06:285297void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:195298 const GURL& page_url) {
5299 // Prepare list to storage all savable resource links.
5300 std::vector<GURL> resources_list;
[email protected]c2d986512012-05-12 00:22:465301 std::vector<GURL> referrer_urls_list;
5302 std::vector<WebKit::WebReferrerPolicy> referrer_policies_list;
[email protected]18d5be92011-07-25 18:00:195303 std::vector<GURL> frames_list;
5304 webkit_glue::SavableResourcesResult result(&resources_list,
[email protected]c2d986512012-05-12 00:22:465305 &referrer_urls_list,
5306 &referrer_policies_list,
[email protected]18d5be92011-07-25 18:00:195307 &frames_list);
5308
[email protected]c2d986512012-05-12 00:22:465309 // webkit/ doesn't know about content::Referrer.
[email protected]18d5be92011-07-25 18:00:195310 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
5311 webview(),
5312 page_url,
5313 &result,
[email protected]1de7a172012-05-28 18:36:435314 const_cast<const char**>(content::GetSavableSchemes()))) {
[email protected]18d5be92011-07-25 18:00:195315 // If something is wrong when collecting all savable resource links,
5316 // send empty list to embedder(browser) to tell it failed.
[email protected]c2d986512012-05-12 00:22:465317 referrer_urls_list.clear();
5318 referrer_policies_list.clear();
[email protected]18d5be92011-07-25 18:00:195319 resources_list.clear();
5320 frames_list.clear();
5321 }
5322
[email protected]c2d986512012-05-12 00:22:465323 std::vector<content::Referrer> referrers_list;
5324 CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size());
5325 for (unsigned i = 0; i < referrer_urls_list.size(); ++i) {
5326 referrers_list.push_back(
5327 content::Referrer(referrer_urls_list[i], referrer_policies_list[i]));
5328 }
5329
[email protected]18d5be92011-07-25 18:00:195330 // Send result of all savable resource links to embedder.
5331 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
5332 resources_list,
5333 referrers_list,
5334 frames_list));
5335}
5336
[email protected]310ebd6302011-10-10 19:06:285337void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:195338 const std::vector<GURL>& links,
5339 const std::vector<FilePath>& local_paths,
5340 const FilePath& local_directory_name) {
5341
5342 // Convert std::vector of GURLs to WebVector<WebURL>
5343 WebVector<WebURL> weburl_links(links);
5344
5345 // Convert std::vector of std::strings to WebVector<WebString>
5346 WebVector<WebString> webstring_paths(local_paths.size());
5347 for (size_t i = 0; i < local_paths.size(); i++)
5348 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
5349
5350 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
5351 webstring_paths,
5352 webkit_glue::FilePathToWebString(
5353 local_directory_name));
5354}
5355
[email protected]310ebd6302011-10-10 19:06:285356void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:125357 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:275358 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:125359 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
5360 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
5361 before_unload_start_time,
5362 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:295363}
5364
[email protected]310ebd6302011-10-10 19:06:285365void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]69ddf852012-02-21 23:21:315366 // Ensure that no other in-progress navigation continues.
5367 OnStop();
5368
[email protected]73eb2602012-02-09 19:50:555369 // Only run unload if we're not swapped out yet, but send the ack either way.
5370 if (!is_swapped_out_) {
5371 // Swap this RenderView out so the tab can navigate to a page rendered by a
5372 // different process. This involves running the unload handler and clearing
5373 // the page. Once WasSwappedOut is called, we also allow this process to
5374 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:155375
[email protected]73eb2602012-02-09 19:50:555376 // Send an UpdateState message before we get swapped out.
5377 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:155378
[email protected]73eb2602012-02-09 19:50:555379 // Synchronously run the unload handler before sending the ACK.
5380 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:155381
[email protected]73eb2602012-02-09 19:50:555382 // Swap out and stop sending any IPC messages that are not ACKs.
5383 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:155384
[email protected]285f4bb82012-04-17 15:57:285385 // Replace the page with a blank dummy URL. The unload handler will not be
[email protected]73eb2602012-02-09 19:50:555386 // run a second time, thanks to a check in FrameLoader::stopLoading.
5387 // TODO(creis): Need to add a better way to do this that avoids running the
[email protected]285f4bb82012-04-17 15:57:285388 // beforeunload handler. For now, we just run it a second time silently.
[email protected]0720b532012-08-28 19:23:375389 NavigateToSwappedOutURL(webview()->mainFrame());
[email protected]961541a92012-06-01 21:15:285390
5391 // Let WebKit know that this view is hidden so it can drop resources and
5392 // stop compositing.
5393 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false);
[email protected]73eb2602012-02-09 19:50:555394 }
[email protected]992db4c2011-05-12 15:37:155395
5396 // Just echo back the params in the ACK.
5397 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
5398}
5399
[email protected]0720b532012-08-28 19:23:375400void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) {
[email protected]14392a52012-05-02 20:28:445401 // We use loadRequest instead of loadHTMLString because the former commits
5402 // synchronously. Otherwise a new navigation can interrupt the navigation
5403 // to content::kSwappedOutURL. If that happens to be to the page we had been
5404 // showing, then WebKit will never send a commit and we'll be left spinning.
5405 GURL swappedOutURL(content::kSwappedOutURL);
5406 WebURLRequest request(swappedOutURL);
[email protected]0720b532012-08-28 19:23:375407 frame->loadRequest(request);
[email protected]14392a52012-05-02 20:28:445408}
5409
[email protected]310ebd6302011-10-10 19:06:285410void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:375411 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:295412 // TODO(creis): We'd rather use webview()->Close() here, but that currently
5413 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
5414 // in the onunload handler from appearing. For now, we're bypassing that and
5415 // calling the FrameLoader's CloseURL method directly. This should be
5416 // revisited to avoid having two ways to close a page. Having a single way
5417 // to close that can run onunload is also useful for fixing
5418 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:275419 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:295420
[email protected]992db4c2011-05-12 15:37:155421 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:295422}
5423
[email protected]310ebd6302011-10-10 19:06:285424void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:025425#if defined(USE_AURA)
5426 // Aura doesn't care if we switch themes.
5427#elif defined(OS_WIN)
[email protected]f78452f2012-05-15 02:07:525428 ui::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:465429 if (webview())
5430 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:575431#else // defined(OS_WIN)
5432 // TODO(port): we don't support theming on non-Windows platforms yet
5433 NOTIMPLEMENTED();
5434#endif
initial.commit09911bf2008-07-26 23:55:295435}
5436
[email protected]310ebd6302011-10-10 19:06:285437void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:085438 if (decrement_shared_popup_at_destruction_)
5439 shared_popup_counter_->data--;
5440 shared_popup_counter_ = new SharedRenderViewCounter(0);
5441 decrement_shared_popup_at_destruction_ = false;
5442}
5443
[email protected]310ebd6302011-10-10 19:06:285444bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
5445 const WebURLError& error,
5446 bool replace) {
[email protected]15d79e12009-08-02 19:23:455447 // We only show alternate error pages in the main frame. They are
5448 // intended to assist the user when navigating, so there is not much
5449 // value in showing them for failed subframes. Ideally, we would be
5450 // able to use the TYPED transition type for this, but that flag is
5451 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455452 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455453 return false;
5454
5455 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375456 // connection failure.
[email protected]15d79e12009-08-02 19:23:455457 int ec = error.reason;
5458 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5459 ec != net::ERR_CONNECTION_FAILED &&
5460 ec != net::ERR_CONNECTION_REFUSED &&
5461 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]82114f52012-03-20 22:53:415462 ec != net::ERR_CONNECTION_TIMED_OUT) {
[email protected]15d79e12009-08-02 19:23:455463 return false;
[email protected]82114f52012-03-20 22:53:415464 }
[email protected]15d79e12009-08-02 19:23:455465
5466 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555467 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455468 if (!error_page_url.is_valid())
5469 return false;
5470
5471 // Load an empty page first so there is an immediate response to the error,
5472 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455473 frame->loadHTMLString(std::string(),
[email protected]285f4bb82012-04-17 15:57:285474 GURL(content::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455475 error.unreachableURL,
5476 replace);
5477
5478 // Now, create a fetcher for the error page and associate it with the data
5479 // source we just created via the LoadHTMLString call. That way if another
5480 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:075481 DocumentState* document_state =
5482 DocumentState::FromDataSource(frame->provisionalDataSource());
5483 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:455484 new AltErrorPageResourceFetcher(
5485 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:085486 base::Bind(&RenderViewImpl::AltErrorPageFinished,
5487 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:455488 return true;
5489}
5490
[email protected]310ebd6302011-10-10 19:06:285491void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
5492 const WebURLError& original_error,
5493 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:455494 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:095495 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:555496 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:095497 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:455498}
5499
[email protected]310ebd6302011-10-10 19:06:285500void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:005501 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475502 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005503}
5504
[email protected]310ebd6302011-10-10 19:06:285505void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:095506 const gfx::Rect& resizer_rect,
5507 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:105508 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475509 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105510 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205511 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:315512 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:105513 }
[email protected]dd6afca2011-08-13 03:44:315514 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:105515 }
5516
[email protected]ee41e7d22011-10-14 19:34:095517 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:005518}
[email protected]0aa477bd2009-03-23 22:21:435519
[email protected]29ed96a2012-02-04 18:12:165520void RenderViewImpl::WillInitiatePaint() {
5521 // Notify the pepper plugins that we're about to paint.
5522 pepper_delegate_.ViewWillInitiatePaint();
5523}
5524
[email protected]310ebd6302011-10-10 19:06:285525void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:165526 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]53900d52010-06-16 04:25:015527 pepper_delegate_.ViewInitiatedPaint();
[email protected]7900bfdb2012-05-24 19:31:245528 if (GetGuestToEmbedderChannel())
5529 GetGuestToEmbedderChannel()->IssueSwapBuffers(guest_graphics_resource());
[email protected]00c39612010-03-06 02:53:285530}
5531
[email protected]310ebd6302011-10-10 19:06:285532void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:285533 // Notify any pepper plugins that we painted. This will call into the plugin,
5534 // and we it may ask to close itself as a result. This will, in turn, modify
5535 // our set, possibly invalidating the iterator. So we iterate on a copy that
5536 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:015537 pepper_delegate_.ViewFlushedPaint();
5538
[email protected]5b1dec8c2012-02-07 04:35:385539 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
5540 // See crbug.com/112921.
5541 if (!webview())
5542 return;
5543
[email protected]00c39612010-03-06 02:53:285544 WebFrame* main_frame = webview()->mainFrame();
5545
5546 // If we have a provisional frame we are between the start and commit stages
5547 // of loading and we don't want to save stats.
5548 if (!main_frame->provisionalDataSource()) {
5549 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:075550 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:285551
[email protected]05c8e502010-08-15 15:13:525552 // TODO(jar): The following code should all be inside a method, probably in
5553 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285554 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:075555 if (document_state->first_paint_time().is_null()) {
5556 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:285557 }
[email protected]007733c2011-11-17 00:34:075558 if (document_state->first_paint_after_load_time().is_null() &&
5559 !document_state->finish_load_time().is_null()) {
5560 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:285561 }
5562 }
5563}
5564
[email protected]310ebd6302011-10-10 19:06:285565void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:085566 RenderWidget::OnSwapBuffersPosted();
5567}
5568
[email protected]310ebd6302011-10-10 19:06:285569void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:245570 RenderWidget::OnSwapBuffersComplete();
5571}
5572
[email protected]310ebd6302011-10-10 19:06:285573void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:245574 RenderWidget::OnSwapBuffersAborted();
5575}
5576
[email protected]310ebd6302011-10-10 19:06:285577webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:155578 const gfx::Rect& paint_bounds,
5579 TransportDIB** dib,
5580 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:205581 gfx::Rect* clip,
5582 float* scale_factor) {
[email protected]ca4847f2010-09-24 05:39:155583 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
[email protected]0f3a2d12012-09-01 03:37:205584 paint_bounds, dib, location, clip, scale_factor);
[email protected]ca4847f2010-09-24 05:39:155585}
5586
[email protected]310ebd6302011-10-10 19:06:285587gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:075588 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:435589 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:525590}
5591
[email protected]310ebd6302011-10-10 19:06:285592void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:165593 if (webview())
[email protected]26aa0482009-09-30 16:55:275594 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165595}
5596
[email protected]310ebd6302011-10-10 19:06:285597void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:145598 if (webview())
[email protected]b4bb2502009-10-01 22:35:275599 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145600
5601 SetBackground(background);
5602}
5603
[email protected]2a84f9d2012-06-05 21:50:435604void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) {
5605 if (accessibility_mode_ == new_mode)
5606 return;
5607 accessibility_mode_ = new_mode;
5608 if (renderer_accessibility_) {
5609 delete renderer_accessibility_;
5610 renderer_accessibility_ = NULL;
5611 }
5612 if (accessibility_mode_ == AccessibilityModeComplete)
5613 renderer_accessibility_ = new RendererAccessibilityComplete(this);
5614 else if (accessibility_mode_ == AccessibilityModeEditableTextOnly)
5615 renderer_accessibility_ = new RendererAccessibilityFocusOnly(this);
5616}
5617
[email protected]310ebd6302011-10-10 19:06:285618void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:345619 if (webview())
[email protected]b4bb2502009-10-01 22:35:275620 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265621
5622#if defined(OS_MACOSX)
5623 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5624 for (plugin_it = plugin_delegates_.begin();
5625 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5626 (*plugin_it)->SetWindowFocus(active);
5627 }
5628#endif
[email protected]8c66c5a2009-07-22 17:26:345629}
5630
[email protected]7a17bac02012-03-07 21:58:125631void RenderViewImpl::OnSetNavigationStartTime(
5632 const base::TimeTicks& browser_navigation_start) {
5633 if (!webview())
5634 return;
5635
5636 // Only the initial navigation can be a cross-renderer navigation. If we've
5637 // already navigated away from that page, we can ignore this message.
5638 if (page_id_ != -1)
5639 return;
5640
5641 // browser_navigation_start is likely before this process existed, so we can't
5642 // use InterProcessTimeTicksConverter. Instead, the best we can do is just
5643 // ensure we don't report a bogus value in the future.
5644 base::TimeTicks navigation_start = std::min(base::TimeTicks::Now(),
5645 browser_navigation_start);
5646 webview()->mainFrame()->provisionalDataSource()->setNavigationStartTime(
5647 (navigation_start - base::TimeTicks()).InSecondsF());
5648}
5649
[email protected]6ce7abc52010-02-02 18:40:145650#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285651void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:145652 // Inform plugins that their container has changed visibility.
5653 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5654 for (plugin_it = plugin_delegates_.begin();
5655 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5656 (*plugin_it)->SetContainerVisibility(visible);
5657 }
5658}
[email protected]1e6e3c992010-02-08 15:52:135659
[email protected]310ebd6302011-10-10 19:06:285660void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
5661 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:135662 // Inform plugins that their window's frame has changed.
5663 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5664 for (plugin_it = plugin_delegates_.begin();
5665 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5666 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5667 }
5668}
[email protected]935d63d2010-10-15 23:31:555669
[email protected]310ebd6302011-10-10 19:06:285670void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
5671 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135672 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555673 // applies to it or not, so inform all the delegates.
5674 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5675 for (plugin_it = plugin_delegates_.begin();
5676 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135677 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555678 }
5679}
[email protected]6ce7abc52010-02-02 18:40:145680#endif // OS_MACOSX
5681
[email protected]310ebd6302011-10-10 19:06:285682void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:485683 const EditCommands& edit_commands) {
5684 edit_commands_ = edit_commands;
5685}
5686
[email protected]310ebd6302011-10-10 19:06:285687void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:595688 // We need to grab a pointer to the doomed WebView before we destroy it.
5689 WebView* doomed = webview();
5690 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495691 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:595692}
5693
[email protected]310ebd6302011-10-10 19:06:285694void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:485695 edit_commands_.clear();
5696}
5697
[email protected]310ebd6302011-10-10 19:06:285698bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]217690d2012-01-27 07:33:115699 pepper_delegate_.WillHandleMouseEvent();
5700
5701 // If the mouse is locked, only the current owner of the mouse lock can
5702 // process mouse events.
5703 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:375704}
5705
[email protected]2b942c332012-04-25 16:26:265706void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515707 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065708}
5709
[email protected]310ebd6302011-10-10 19:06:285710void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:245711 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
5712}
5713
[email protected]310ebd6302011-10-10 19:06:285714void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:435715 RenderWidget::OnWasHidden();
5716
[email protected]2d7b82c2012-06-01 05:57:505717#if defined(OS_ANDROID)
5718 // Inform WebMediaPlayerManagerAndroid to release all media player resources.
5719 media_player_manager_->ReleaseMediaResources();
5720#endif
5721
[email protected]a6939ca42011-02-18 17:58:075722 if (webview()) {
5723 webview()->settings()->setMinimumTimerInterval(
5724 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:445725 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075726 }
5727
[email protected]204f1df2012-01-04 20:21:135728 // Inform PPAPI plugins that their page is no longer visible.
5729 pepper_delegate_.PageVisibilityChanged(false);
5730
[email protected]a6939ca42011-02-18 17:58:075731#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135732 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:435733 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5734 for (plugin_it = plugin_delegates_.begin();
5735 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5736 (*plugin_it)->SetContainerVisibility(false);
5737 }
[email protected]a6939ca42011-02-18 17:58:075738#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:435739}
5740
[email protected]9e2e4632012-07-27 16:38:415741void RenderViewImpl::OnWasShown(bool needs_repainting) {
5742 RenderWidget::OnWasShown(needs_repainting);
[email protected]941e4552010-02-01 21:23:435743
[email protected]a6939ca42011-02-18 17:58:075744 if (webview()) {
5745 webview()->settings()->setMinimumTimerInterval(
5746 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:445747 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:075748 }
5749
[email protected]204f1df2012-01-04 20:21:135750 // Inform PPAPI plugins that their page is visible.
5751 pepper_delegate_.PageVisibilityChanged(true);
5752
[email protected]a6939ca42011-02-18 17:58:075753#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:135754 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:435755 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5756 for (plugin_it = plugin_delegates_.begin();
5757 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5758 (*plugin_it)->SetContainerVisibility(true);
5759 }
[email protected]784ea1ab2010-09-18 00:02:345760#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:075761}
[email protected]1e6e3c992010-02-08 15:52:135762
[email protected]310ebd6302011-10-10 19:06:285763bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]9caf09bc2012-06-25 21:46:285764 // Contexts using the command buffer support asynchronous swapbuffers.
[email protected]f89e173a2012-08-24 01:12:265765 // See RenderViewImpl::createOutputSurface().
[email protected]9caf09bc2012-06-25 21:46:285766 if (WebWidgetHandlesCompositorScheduling() ||
5767 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL))
[email protected]555e75d2011-10-08 01:23:385768 return false;
5769
[email protected]9caf09bc2012-06-25 21:46:285770 return true;
[email protected]65225772011-05-12 21:10:245771}
5772
[email protected]310ebd6302011-10-10 19:06:285773void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:135774 RenderWidget::OnSetFocus(enable);
5775
[email protected]7d3c02c2010-05-05 23:10:315776 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075777 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135778 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5779 for (plugin_it = plugin_delegates_.begin();
5780 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345781#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315782 // RenderWidget's call to setFocus can cause the underlying webview's
5783 // activation state to change just like a call to setIsActive.
5784 if (enable)
5785 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345786#endif
[email protected]7d3c02c2010-05-05 23:10:315787 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135788 }
5789 }
[email protected]a01da5682012-06-30 00:37:315790 // Notify all Pepper plugins.
5791 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135792}
[email protected]941e4552010-02-01 21:23:435793
[email protected]310ebd6302011-10-10 19:06:285794void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]3306f262012-09-21 19:20:425795 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]3f783362011-10-21 22:40:505796 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:575797}
5798
[email protected]73bf95812011-10-12 11:38:325799void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]3306f262012-09-21 19:20:425800 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]8fe8f742012-06-14 00:36:085801 if (renderer_accessibility_)
5802 renderer_accessibility_->FocusedNodeChanged(WebNode());
[email protected]73bf95812011-10-12 11:38:325803}
5804
[email protected]3f783362011-10-21 22:40:505805void RenderViewImpl::PpapiPluginCaretPositionChanged() {
5806 UpdateSelectionBounds();
5807}
5808
[email protected]b25b3ee2012-01-13 05:19:545809bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
5810 if (!pepper_delegate_.IsPluginFocused())
5811 return false;
5812 *rect = pepper_delegate_.GetCaretBounds();
5813 return true;
5814}
5815
[email protected]397c23962012-05-21 07:09:325816void RenderViewImpl::SimulateImeSetComposition(
5817 const string16& text,
5818 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5819 int selection_start,
5820 int selection_end) {
5821 OnImeSetComposition(text, underlines, selection_start, selection_end);
5822}
5823
5824void RenderViewImpl::SimulateImeConfirmComposition(
5825 const string16& text,
5826 const ui::Range& replacement_range) {
5827 OnImeConfirmComposition(text, replacement_range);
5828}
5829
[email protected]73bf95812011-10-12 11:38:325830void RenderViewImpl::PpapiPluginCancelComposition() {
5831 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]58b48a0d2012-06-13 07:01:355832 const ui::Range range(ui::Range::InvalidRange());
5833 const std::vector<gfx::Rect> empty_bounds;
5834 UpdateCompositionInfo(range, empty_bounds);
[email protected]73bf95812011-10-12 11:38:325835}
5836
[email protected]3c8c74c2012-03-15 07:34:525837void RenderViewImpl::PpapiPluginSelectionChanged() {
5838 SyncSelectionIfRequired();
5839}
5840
[email protected]93df81e2012-08-10 22:22:465841void RenderViewImpl::PpapiPluginCreated(content::RendererPpapiHost* host) {
[email protected]236bf852012-07-27 22:49:365842 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
5843 DidCreatePepperPlugin(host));
5844}
5845
[email protected]310ebd6302011-10-10 19:06:285846void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:575847 const string16& text,
5848 const std::vector<WebKit::WebCompositionUnderline>& underlines,
5849 int selection_start,
5850 int selection_end) {
[email protected]73bf95812011-10-12 11:38:325851 if (pepper_delegate_.IsPluginFocused()) {
5852 // When a PPAPI plugin has focus, we bypass WebKit.
5853 pepper_delegate_.OnImeSetComposition(text,
5854 underlines,
5855 selection_start,
5856 selection_end);
5857 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235858#if defined(OS_WIN)
5859 // When a plug-in has focus, we create platform-specific IME data used by
5860 // our IME emulator and send it directly to the focused plug-in, i.e. we
5861 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
5862 // instance ID is the same one as the specified ID.)
5863 if (focused_plugin_id_ >= 0) {
5864 std::vector<int> clauses;
5865 std::vector<int> target;
5866 for (size_t i = 0; i < underlines.size(); ++i) {
5867 clauses.push_back(underlines[i].startOffset);
5868 clauses.push_back(underlines[i].endOffset);
5869 if (underlines[i].thick) {
5870 target.clear();
5871 target.push_back(underlines[i].startOffset);
5872 target.push_back(underlines[i].endOffset);
5873 }
5874 }
5875 std::set<WebPluginDelegateProxy*>::iterator it;
5876 for (it = plugin_delegates_.begin();
5877 it != plugin_delegates_.end(); ++it) {
5878 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
5879 focused_plugin_id_);
5880 }
5881 return;
5882 }
5883#endif
[email protected]56ea1a62011-05-30 07:05:575884 RenderWidget::OnImeSetComposition(text,
5885 underlines,
5886 selection_start,
5887 selection_end);
5888 }
5889}
5890
[email protected]4de6d1692011-10-12 08:45:445891void RenderViewImpl::OnImeConfirmComposition(
5892 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:575893 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:325894 // When a PPAPI plugin has focus, we bypass WebKit.
5895 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:575896 } else {
[email protected]e6ae0f6c2011-10-04 10:39:235897#if defined(OS_WIN)
5898 // Same as OnImeSetComposition(), we send the text from IMEs directly to
5899 // plug-ins. When we send IME text directly to plug-ins, we should not send
5900 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:445901 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:235902 if (focused_plugin_id_ >= 0) {
5903 std::set<WebPluginDelegateProxy*>::iterator it;
5904 for (it = plugin_delegates_.begin();
5905 it != plugin_delegates_.end(); ++it) {
5906 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
5907 }
5908 return;
5909 }
5910#endif
[email protected]ebd28ac2011-10-13 18:49:055911 if (replacement_range.IsValid() && webview()) {
5912 // Select the text in |replacement_range|, it will then be replaced by
5913 // text added by the call to RenderWidget::OnImeConfirmComposition().
5914 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:165915 WebRange webrange = WebRange::fromDocumentRange(
5916 frame, replacement_range.start(), replacement_range.length());
5917 if (!webrange.isNull())
[email protected]884f9002012-08-21 19:33:585918 frame->selectRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:055919 }
5920 }
[email protected]4de6d1692011-10-12 08:45:445921 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:575922 }
5923}
5924
[email protected]dea5e7682012-06-14 05:21:245925void RenderViewImpl::OnSetDeviceScaleFactor(float device_scale_factor) {
5926 RenderWidget::OnSetDeviceScaleFactor(device_scale_factor);
5927 if (webview())
5928 webview()->setDeviceScaleFactor(device_scale_factor);
5929}
5930
[email protected]310ebd6302011-10-10 19:06:285931ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:325932 return pepper_delegate_.IsPluginFocused() ?
5933 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
5934}
5935
[email protected]3f783362011-10-21 22:40:505936void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
5937 if (pepper_delegate_.IsPluginFocused()) {
5938 // TODO(kinaba) http://crbug.com/101101
5939 // Current Pepper IME API does not handle selection bounds. So we simply
5940 // use the caret position as an empty range for now. It will be updated
5941 // after Pepper API equips features related to surrounding text retrieval.
5942 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
5943 *start = caret;
5944 *end = caret;
5945 return;
5946 }
5947 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:455948}
5949
[email protected]58b48a0d2012-06-13 07:01:355950void RenderViewImpl::GetCompositionCharacterBounds(
5951 std::vector<gfx::Rect>* bounds) {
5952 DCHECK(bounds);
5953 bounds->clear();
5954
5955 if (!webview())
5956 return;
5957 size_t start_offset = 0;
5958 size_t character_count = 0;
5959 if (!webview()->compositionRange(&start_offset, &character_count))
5960 return;
5961 if (character_count == 0)
5962 return;
5963
5964 WebKit::WebFrame* frame = webview()->focusedFrame();
5965 if (!frame)
5966 return;
5967
5968 bounds->reserve(character_count);
5969 WebKit::WebRect webrect;
5970 for (size_t i = 0; i < character_count; ++i) {
5971 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
5972 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
5973 bounds->clear();
5974 return;
5975 }
5976 bounds->push_back(webrect);
5977 }
5978}
5979
[email protected]310ebd6302011-10-10 19:06:285980bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:325981 return pepper_delegate_.IsPluginFocused() ?
5982 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:575983}
5984
[email protected]e6ae0f6c2011-10-04 10:39:235985#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:285986void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:235987 if (focused)
5988 focused_plugin_id_ = plugin_id;
5989 else
5990 focused_plugin_id_ = -1;
5991}
5992#endif
5993
[email protected]43f28f832010-02-03 02:28:485994#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285995void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]82114f52012-03-20 22:53:415996 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
[email protected]b7f75862011-01-21 21:15:135997}
5998
[email protected]310ebd6302011-10-10 19:06:285999void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:136000 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:556001 // This message can be sent during event-handling, and needs to be delivered
6002 // within that context.
6003 msg->set_unblock(true);
6004 Send(msg);
6005}
6006
[email protected]310ebd6302011-10-10 19:06:286007gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:236008 bool opaque, bool root) {
[email protected]b2968292012-03-28 01:35:516009 gfx::PluginWindowHandle window = gfx::kNullPluginWindow;
[email protected]43f28f832010-02-03 02:28:486010 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:236011 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:116012 if (window) {
6013 fake_plugin_window_handles_.insert(window);
6014 }
[email protected]43f28f832010-02-03 02:28:486015 return window;
6016}
6017
[email protected]310ebd6302011-10-10 19:06:286018void RenderViewImpl::DestroyFakePluginWindowHandle(
6019 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:116020 if (window && fake_plugin_window_handles_.find(window) !=
6021 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:486022 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:116023 fake_plugin_window_handles_.erase(window);
6024 }
[email protected]43f28f832010-02-03 02:28:486025}
6026
[email protected]310ebd6302011-10-10 19:06:286027void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
6028 gfx::PluginWindowHandle window,
6029 int32 width,
6030 int32 height,
6031 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:336032 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:486033 routing_id(), window, width, height, io_surface_identifier));
6034}
6035
[email protected]310ebd6302011-10-10 19:06:286036void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:336037 gfx::PluginWindowHandle window,
6038 int32 width,
6039 int32 height,
6040 TransportDIB::Handle transport_dib) {
6041 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:076042 routing_id(), window, width, height, transport_dib));
6043}
6044
[email protected]310ebd6302011-10-10 19:06:286045TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:336046 size_t size) {
[email protected]1aef98132010-02-23 18:00:076047 TransportDIB::Handle dib_handle;
6048 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:386049 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:076050 return dib_handle;
6051 // Return an invalid handle if Send() fails.
6052 return TransportDIB::DefaultHandleValue();
6053}
6054
[email protected]310ebd6302011-10-10 19:06:286055void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
6056 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:076057 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
6058}
6059
[email protected]310ebd6302011-10-10 19:06:286060void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:326061 gfx::PluginWindowHandle window, uint64 surface_handle) {
[email protected]f35d6672010-10-28 21:39:146062 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:326063 routing_id(), window, surface_handle));
[email protected]43f28f832010-02-03 02:28:486064}
[email protected]82114f52012-03-20 22:53:416065#endif // defined(OS_MACOSX)
[email protected]58c321d2010-02-19 12:11:286066
[email protected]310ebd6302011-10-10 19:06:286067bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:236068 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:476069 WebFileChooserCompletion* completion) {
6070 static const size_t kMaximumPendingFileChooseRequests = 4;
6071 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
6072 // This sanity check prevents too many file choose requests from getting
6073 // queued which could DoS the user. Getting these is most likely a
6074 // programming error (there are many ways to DoS the user so it's not
6075 // considered a "real" security check), either in JS requesting many file
6076 // choosers to pop up, or in a plugin.
6077 //
6078 // TODO(brettw) we might possibly want to require a user gesture to open
6079 // a file picker, which will address this issue in a better way.
6080 return false;
6081 }
6082
6083 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
6084 new PendingFileChooser(params, completion)));
6085 if (file_chooser_completions_.size() == 1) {
6086 // Actually show the browse dialog when this is the first request.
6087 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
6088 }
6089 return true;
6090}
6091
[email protected]310ebd6302011-10-10 19:06:286092WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:516093 if (!geolocation_dispatcher_)
6094 geolocation_dispatcher_ = new GeolocationDispatcher(this);
6095 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:256096}
[email protected]61c9f032010-03-31 23:04:196097
[email protected]310ebd6302011-10-10 19:06:286098WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:116099 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:226100#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:026101 if (!input_tag_speech_dispatcher_)
6102 input_tag_speech_dispatcher_ =
6103 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:226104#endif
[email protected]c52b2892012-03-07 11:01:026105 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:116106}
6107
[email protected]64d09222012-05-25 10:10:346108WebKit::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
6109#if defined(ENABLE_INPUT_SPEECH)
6110 if (!speech_recognition_dispatcher_)
6111 speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
6112#endif
6113 return speech_recognition_dispatcher_;
6114}
6115
[email protected]310ebd6302011-10-10 19:06:286116WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:516117 if (!device_orientation_dispatcher_)
6118 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
6119 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:536120}
6121
[email protected]310ebd6302011-10-10 19:06:286122void RenderViewImpl::zoomLimitsChanged(double minimum_level,
6123 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:256124 // For now, don't remember plugin zoom values. We don't want to mix them with
6125 // normal web content (i.e. a fixed layout plugin would usually want them
6126 // different).
6127 bool remember = !webview()->mainFrame()->document().isPluginDocument();
6128
[email protected]b75b8292010-10-01 07:28:256129 int minimum_percent = static_cast<int>(
6130 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
6131 int maximum_percent = static_cast<int>(
6132 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:256133
6134 Send(new ViewHostMsg_UpdateZoomLimits(
6135 routing_id_, minimum_percent, maximum_percent, remember));
6136}
6137
[email protected]310ebd6302011-10-10 19:06:286138void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:256139 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:086140 float zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:266141
6142 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
6143
[email protected]b75b8292010-10-01 07:28:256144 // Tell the browser which url got zoomed so it can update the menu and the
6145 // saved values if necessary
6146 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:086147 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:416148 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:256149}
6150
[email protected]310ebd6302011-10-10 19:06:286151void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
6152 const WebString& base_url,
6153 const WebString& url,
6154 const WebString& title) {
[email protected]3a3b75a2012-06-01 08:38:366155 bool user_gesture = (webview()->focusedFrame() &&
6156 webview()->focusedFrame()->isProcessingUserGesture());
[email protected]a6d36cc2011-02-23 00:39:486157 GURL base(base_url);
6158 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
6159 if (base.GetOrigin() != absolute_url.GetOrigin()) {
6160 return;
6161 }
[email protected]f1a29a02011-10-06 23:08:446162 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
6163 UTF16ToUTF8(scheme),
6164 absolute_url,
[email protected]3a3b75a2012-06-01 08:38:366165 title,
6166 user_gesture));
[email protected]a6d36cc2011-02-23 00:39:486167}
6168
[email protected]310ebd6302011-10-10 19:06:286169WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:446170 WebKit::WebPageVisibilityState current_state = is_hidden() ?
6171 WebKit::WebPageVisibilityStateHidden :
6172 WebKit::WebPageVisibilityStateVisible;
6173 WebKit::WebPageVisibilityState override_state = current_state;
6174 if (content::GetContentClient()->renderer()->
6175 ShouldOverridePageVisibilityState(this,
6176 &override_state))
6177 return override_state;
6178 return current_state;
[email protected]94dec932011-05-26 20:04:216179}
6180
[email protected]273558fb2012-01-12 15:03:516181WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
[email protected]273558fb2012-01-12 15:03:516182 EnsureMediaStreamImpl();
6183 return media_stream_impl_;
6184}
6185
[email protected]a0629af92012-08-08 00:39:376186void RenderViewImpl::draggableRegionsChanged() {
6187 FOR_EACH_OBSERVER(
6188 RenderViewObserver,
6189 observers_,
6190 DraggableRegionsChanged(webview()->mainFrame()));
6191}
6192
[email protected]20657a82012-08-21 20:23:036193#if defined(OS_ANDROID)
6194WebContentDetectionResult RenderViewImpl::detectContentAround(
6195 const WebHitTestResult& touch_hit) {
6196 DCHECK(!touch_hit.isNull());
6197 DCHECK(!touch_hit.node().isNull());
6198 DCHECK(touch_hit.node().isTextNode());
6199
6200 // Process the position with all the registered content detectors until
6201 // a match is found. Priority is provided by their relative order.
6202 for (ContentDetectorList::const_iterator it = content_detectors_.begin();
6203 it != content_detectors_.end(); ++it) {
6204 ContentDetector::Result content = (*it)->FindTappedContent(touch_hit);
6205 if (content.valid) {
6206 return WebContentDetectionResult(content.content_boundaries,
6207 UTF8ToUTF16(content.text), content.intent_url);
6208 }
6209 }
6210 return WebContentDetectionResult();
6211}
6212
6213void RenderViewImpl::scheduleContentIntent(const WebURL& intent) {
6214 // Introduce a short delay so that the user can notice the content.
6215 MessageLoop::current()->PostDelayedTask(
6216 FROM_HERE,
6217 base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, AsWeakPtr(),
6218 intent, expected_content_intent_id_),
6219 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds));
6220}
6221
6222void RenderViewImpl::cancelScheduledContentIntents() {
6223 ++expected_content_intent_id_;
6224}
6225
6226void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent,
6227 size_t request_id) {
6228 if (request_id != expected_content_intent_id_)
6229 return;
6230
6231 // Remove the content highlighting if any.
6232 scheduleComposite();
6233
6234 if (!intent.is_empty())
6235 Send(new ViewHostMsg_StartContentIntent(routing_id_, intent));
6236}
6237#endif
6238
[email protected]310ebd6302011-10-10 19:06:286239void RenderViewImpl::OnAsyncFileOpened(
6240 base::PlatformFileError error_code,
6241 IPC::PlatformFileForTransit file_for_transit,
6242 int message_id) {
[email protected]27a9ef32010-09-10 04:06:246243 pepper_delegate_.OnAsyncFileOpened(
6244 error_code,
6245 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
6246 message_id);
6247}
[email protected]caf706f2010-10-26 17:54:086248
[email protected]310ebd6302011-10-10 19:06:286249void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:476250 int request_id,
[email protected]d54305072011-06-22 20:58:436251 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:476252 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
[email protected]2b657fd2011-04-18 16:00:476253 handle);
[email protected]eb415bf0e2011-04-14 02:45:426254}
6255
[email protected]d8415ad92012-08-23 14:40:506256void RenderViewImpl::OnPpapiBrokerPermissionResult(
6257 int request_id,
6258 bool result) {
6259 pepper_delegate_.OnPpapiBrokerPermissionResult(request_id, result);
6260}
6261
[email protected]caf706f2010-10-26 17:54:086262#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:286263void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:156264 if (external_popup_menu_ == NULL) {
6265 // Crash reports from the field indicate that we can be notified with a
6266 // NULL external popup menu (we probably get notified twice).
6267 // If you hit this please file a bug against jcivelli and include the page
6268 // and steps to repro.
6269 NOTREACHED();
6270 return;
6271 }
[email protected]caf706f2010-10-26 17:54:086272 external_popup_menu_->DidSelectItem(selected_index);
6273 external_popup_menu_.reset();
6274}
6275#endif
[email protected]bb461532010-11-26 21:50:236276
[email protected]24d2b172012-05-26 00:54:126277#if defined(OS_ANDROID)
6278void RenderViewImpl::OnSelectPopupMenuItems(
6279 bool canceled,
6280 const std::vector<int>& selected_indices) {
6281 // It is possible to receive more than one of these calls if the user presses
6282 // a select faster than it takes for the show-select-popup IPC message to make
6283 // it to the browser UI thread. Ignore the extra-messages.
6284 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug.
6285 if (!external_popup_menu_.get())
6286 return;
6287
6288 external_popup_menu_->DidSelectItems(canceled, selected_indices);
6289 external_popup_menu_.reset();
6290}
6291#endif
6292
[email protected]310ebd6302011-10-10 19:06:286293void RenderViewImpl::OnContextMenuClosed(
[email protected]35be7ec2012-02-12 20:42:516294 const content::CustomContextMenuContext& custom_context) {
[email protected]b29aa74b2011-01-31 21:41:086295 if (custom_context.is_pepper_menu)
6296 pepper_delegate_.OnContextMenuClosed(custom_context);
6297 else
6298 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:106299}
[email protected]5a7b15a2011-08-22 22:48:186300
[email protected]310ebd6302011-10-10 19:06:286301void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:186302 if (!webview())
6303 return;
6304 WebFrame* main_frame = webview()->mainFrame();
6305 if (!main_frame)
6306 return;
6307 main_frame->enableViewSourceMode(true);
6308}
[email protected]67bfb83f2011-09-22 03:36:376309
[email protected]310ebd6302011-10-10 19:06:286310bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:086311 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:406312}
[email protected]7f3c7af2011-10-20 22:52:516313
[email protected]64d0e192011-12-09 14:44:206314void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7e9c5bb02012-05-14 13:58:316315 DCHECK(!java_bridge_dispatcher_);
[email protected]464750f2011-10-24 23:16:186316#if defined(ENABLE_JAVA_BRIDGE)
[email protected]7e9c5bb02012-05-14 13:58:316317 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this);
[email protected]464750f2011-10-24 23:16:186318#endif
[email protected]7f3c7af2011-10-20 22:52:516319}
[email protected]0720b532012-08-28 19:23:376320
6321void RenderViewImpl::OnUpdatedFrameTree(
6322 int process_id,
6323 int route_id,
6324 const std::string& frame_tree) {
[email protected]e12dbe6f2012-10-04 22:11:196325 // TODO(nasko): Remove once http://crbug.com/153701 is fixed.
6326 DCHECK(false);
[email protected]5fa9b36b2012-09-21 18:14:276327 // We should only act on this message if we are swapped out. It's possible
6328 // for this to happen due to races.
6329 if (!is_swapped_out_)
6330 return;
6331
[email protected]0720b532012-08-28 19:23:376332 base::DictionaryValue* frames = NULL;
6333 scoped_ptr<base::Value> tree(base::JSONReader::Read(frame_tree));
6334 if (tree.get() && tree->IsType(base::Value::TYPE_DICTIONARY))
6335 tree->GetAsDictionary(&frames);
6336
6337 updating_frame_tree_ = true;
6338 active_frame_id_map_.clear();
6339
6340 target_process_id_ = process_id;
6341 target_routing_id_ = route_id;
6342 CreateFrameTree(webview()->mainFrame(), frames);
6343
6344 updating_frame_tree_ = false;
6345}