blob: e207b93ed462630faa9656aa4ca2e50b13a2dc63 [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]b1cf3372011-04-20 21:28:1016#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4917#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2819#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5120#include "base/process_util.h"
[email protected]7ddea9802012-02-22 23:08:0521#include "base/string_number_conversions.h"
[email protected]0a35efc2012-03-13 17:28:1322#include "base/string_piece.h"
[email protected]318bf5802011-08-08 17:12:4123#include "base/string_split.h"
initial.commit09911bf2008-07-26 23:55:2924#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2825#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2626#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2227#include "base/utf_string_conversions.h"
[email protected]e93e04e2011-03-14 00:27:1028#include "content/common/appcache/appcache_dispatcher.h"
[email protected]127dd582011-03-16 21:32:1029#include "content/common/clipboard_messages.h"
[email protected]37666cf2011-03-13 21:51:4230#include "content/common/database_messages.h"
[email protected]59f4f2fa2011-03-23 01:00:5531#include "content/common/drag_messages.h"
[email protected]16dd6e22012-03-01 19:08:2032#include "content/common/fileapi/file_system_dispatcher.h"
33#include "content/common/fileapi/webfilesystem_callback_dispatcher.h"
[email protected]c26ad882012-02-07 06:41:2034#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]a2ef54c2011-10-10 16:20:3135#include "content/common/intents_messages.h"
[email protected]7f3c7af2011-10-20 22:52:5136#include "content/common/java_bridge_messages.h"
[email protected]127dd582011-03-16 21:32:1037#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0038#include "content/common/pepper_plugin_registry.h"
[email protected]10e5cf12011-04-13 04:10:4039#include "content/common/quota_dispatcher.h"
[email protected]940895b2011-08-20 00:50:0540#include "content/common/request_extra_data.h"
[email protected]5fa3a062012-03-21 15:39:3441#include "content/common/socket_stream_handle_data.h"
[email protected]778574e2011-03-21 22:03:5042#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2143#include "content/public/common/bindings_policy.h"
[email protected]744c2a22012-03-15 18:42:0444#include "content/public/common/content_client.h"
[email protected]54087fe2011-10-28 22:02:4845#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2946#include "content/public/common/content_switches.h"
[email protected]35be7ec2012-02-12 20:42:5147#include "content/public/common/context_menu_params.h"
[email protected]8caadeb2011-11-22 02:45:2348#include "content/public/common/file_chooser_params.h"
[email protected]fb11b6a42012-03-14 07:25:1249#include "content/public/common/selected_file_info.h"
[email protected]a1d29162011-10-14 17:14:0350#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3451#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0752#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3253#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4454#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3655#include "content/public/renderer/render_view_visitor.h"
[email protected]230b7ef2011-03-16 22:30:1956#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0257#include "content/renderer/devtools_agent.h"
[email protected]766a7082012-02-03 23:39:1558#include "content/renderer/dom_automation_controller.h"
[email protected]55722152011-03-22 01:33:5359#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1960#include "content/renderer/geolocation_dispatcher.h"
[email protected]84a83e192012-03-09 18:43:4061#include "content/renderer/gpu/compositor_thread.h"
[email protected]1784b2f2011-11-24 10:53:4862#include "content/renderer/idle_user_detector.h"
[email protected]c52b2892012-03-07 11:01:0263#include "content/renderer/input_tag_speech_dispatcher.h"
[email protected]07161902011-11-11 09:57:4264#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0265#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0866#include "content/renderer/media/audio_message_filter.h"
[email protected]273558fb2012-01-12 15:03:5167#include "content/renderer/media/media_stream_dependency_factory.h"
68#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:4069#include "content/renderer/media/media_stream_impl.h"
[email protected]6048d512012-01-28 03:14:4870#include "content/renderer/media/render_audiosourceprovider.h"
[email protected]090f7312011-08-05 23:26:4071#include "content/renderer/media/render_media_log.h"
[email protected]6048d512012-01-28 03:14:4872#include "content/renderer/media/renderer_gpu_video_decoder_factories.h"
[email protected]4a19be92011-09-22 14:25:0273#include "content/renderer/mhtml_generator.h"
[email protected]217690d2012-01-27 07:33:1174#include "content/renderer/mouse_lock_dispatcher.h"
[email protected]230b7ef2011-03-16 22:30:1975#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3776#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3577#include "content/renderer/plugin_channel_host.h"
[email protected]0361b942012-03-14 06:42:5378#include "content/renderer/browser_plugin/browser_plugin_constants.h"
79#include "content/renderer/browser_plugin/browser_plugin_placeholder.h"
[email protected]8704f89b2011-04-15 00:30:0580#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4481#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4482#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3283#include "content/renderer/renderer_accessibility.h"
[email protected]663bd9e2011-03-21 01:07:0184#include "content/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]da8543762012-03-20 08:52:2085#include "content/renderer/renderer_webcolorchooser_impl.h"
[email protected]663bd9e2011-03-21 01:07:0186#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]86a7d3c2011-09-12 16:45:3287#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:1988#include "content/renderer/v8_value_converter_impl.h"
[email protected]0a35efc2012-03-13 17:28:1389#include "content/renderer/web_intents_host.h"
[email protected]663bd9e2011-03-21 01:07:0190#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3591#include "content/renderer/webplugin_delegate_proxy.h"
92#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4993#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4194#include "media/base/media_switches.h"
[email protected]b80322902012-03-06 01:33:5095#include "media/base/message_loop_factory.h"
[email protected]37136d162012-04-09 23:39:1996#include "media/filters/audio_renderer_impl.h"
[email protected]e1d69d762011-12-13 05:12:1897#include "media/filters/gpu_video_decoder.h"
initial.commit09911bf2008-07-26 23:55:2998#include "net/base/escape.h"
99#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:04100#include "net/http/http_util.h"
[email protected]8bd0fe62011-01-17 06:44:37101#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]8bd0fe62011-01-17 06:44:37102#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:37103#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:37104#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
105#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:37106#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
107#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
108#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
109#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
110#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]8bd0fe62011-01-17 06:44:37111#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37112#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57113#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58114#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
[email protected]592e20b2012-01-20 05:53:44115#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
[email protected]8b5af492011-11-28 21:50:58116#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14117#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:37118#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19119#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37120#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36121#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37122#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
123#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37125#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37126#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17129#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37130#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]8bd0fe62011-01-17 06:44:37131#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40132#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51133#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08134#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
135#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
136#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
137#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
138#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
139#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
[email protected]50da23d02012-04-13 17:47:48140#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00Handler.h"
141#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnection00HandlerClient.h"
[email protected]273558fb2012-01-12 15:03:51142#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
143#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
[email protected]9c4bf232011-12-15 02:25:08144#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
145#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
146#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]5fa3a062012-03-21 15:39:34147#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSocketStreamHandle.h"
[email protected]e6e90dc2011-12-03 00:01:37148#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
149#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
150#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
151#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
152#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
153#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26154#include "third_party/skia/include/core/SkBitmap.h"
[email protected]269f86d2011-12-07 02:43:47155#include "ui/base/javascript_message_type.h"
[email protected]08397d52011-02-05 01:53:38156#include "ui/gfx/native_widget_types.h"
157#include "ui/gfx/point.h"
158#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55159#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04160#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]b928936b2012-04-13 01:16:16161#include "webkit/dom_storage/dom_storage_types.h"
[email protected]9c4bf232011-12-15 02:25:08162#include "webkit/forms/form_data.h"
163#include "webkit/forms/form_field.h"
164#include "webkit/forms/password_form_dom_manager.h"
[email protected]25e18f82010-10-27 16:38:43165#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]18d5be92011-07-25 18:00:19166#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24167#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:29168#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07169#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29170#include "webkit/glue/webkit_glue.h"
[email protected]b00ba702011-08-17 01:41:03171#include "webkit/glue/weburlloader_impl.h"
[email protected]b9fd01ba2012-02-28 01:50:40172#include "webkit/glue/weburlresponse_extradata_impl.h"
[email protected]7e8b4d12012-01-20 23:39:51173#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
[email protected]a9288f52011-11-17 05:18:16174#include "webkit/media/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50175#include "webkit/plugins/npapi/plugin_list.h"
176#include "webkit/plugins/npapi/webplugin_delegate.h"
177#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
178#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52179#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29180
[email protected]25fb9b32012-04-27 03:21:55181#if defined(OS_ANDROID)
182#include "webkit/media/android/webmediaplayer_android.h"
183#elif defined(OS_WIN)
[email protected]6c8afae52009-01-22 02:24:57184// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57185// * theming
[email protected]08397d52011-02-05 01:53:38186#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03187#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37188#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51189#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33190#elif defined(OS_MACOSX)
191#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57192#endif
193
[email protected]9892b472010-09-16 00:23:42194using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08195using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21196using WebKit::WebApplicationCacheHost;
197using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26198using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41199using WebKit::WebColor;
200using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59201using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44202using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51203using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55204using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28205using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00206using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58207using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25208using WebKit::WebDragOperation;
209using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51210using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51211using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08212using WebKit::WebExternalPopupMenu;
213using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47214using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22215using WebKit::WebFileSystem;
216using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49217using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59218using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48219using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45220using WebKit::WebFrame;
[email protected]7e8b4d12012-01-20 23:39:51221using WebKit::WebGraphicsContext3D;
[email protected]ca948a22009-06-25 19:36:17222using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13223using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41224using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50225using WebKit::WebInputElement;
[email protected]ffc8bed2012-01-21 01:23:15226using WebKit::WebIntentRequest;
227using WebKit::WebIntentServiceInfo;
[email protected]3d9689372009-09-10 04:29:17228using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28229using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17230using WebKit::WebMediaPlayerClient;
[email protected]2b942c332012-04-25 16:26:26231using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:28232using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28233using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51234using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19235using WebKit::WebPageSerializer;
236using WebKit::WebPageSerializerClient;
[email protected]50da23d02012-04-13 17:47:48237using WebKit::WebPeerConnection00Handler;
238using WebKit::WebPeerConnection00HandlerClient;
239using WebKit::WebPeerConnectionHandler;
240using WebKit::WebPeerConnectionHandlerClient;
[email protected]3d9689372009-09-10 04:29:17241using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36242using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40243using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49244using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09245using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52246using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59247using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51248using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52249using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15250using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40251using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35252using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29253using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17254using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59255using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42256using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02257using WebKit::WebSize;
[email protected]5fa3a062012-03-21 15:39:34258using WebKit::WebSocketStreamHandle;
[email protected]bd92c3a2010-01-13 05:02:34259using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40260using WebKit::WebStorageQuotaCallbacks;
261using WebKit::WebStorageQuotaError;
262using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28263using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51264using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52265using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24266using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28267using WebKit::WebURL;
268using WebKit::WebURLError;
269using WebKit::WebURLRequest;
270using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28271using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03272using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28273using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26274using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26275using appcache::WebApplicationCacheHostImpl;
276using base::Time;
277using base::TimeDelta;
[email protected]007733c2011-11-17 00:34:07278using content::DocumentState;
[email protected]82ddba1c2011-10-04 00:15:32279using content::NavigationState;
[email protected]380244092011-10-07 17:26:27280using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44281using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36282using content::RenderViewVisitor;
[email protected]445e1042011-12-03 21:03:15283using content::Referrer;
[email protected]8d86f13d2011-10-04 17:01:19284using content::V8ValueConverter;
[email protected]9c4bf232011-12-15 02:25:08285using webkit::forms::FormField;
286using webkit::forms::PasswordForm;
287using webkit::forms::PasswordFormDomManager;
[email protected]6fdd4182010-10-14 23:59:26288using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23289using webkit_glue::ResourceFetcher;
[email protected]b9fd01ba2012-02-28 01:50:40290using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33291
initial.commit09911bf2008-07-26 23:55:29292//-----------------------------------------------------------------------------
293
[email protected]310ebd6302011-10-10 19:06:28294typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49295static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02296
[email protected]882daa92009-11-05 16:31:31297// Time, in seconds, we delay before sending content state changes (such as form
298// state and scroll position) to the browser. We delay sending changes to avoid
299// spamming the browser.
300// To avoid having tab/session restore require sending a message to get the
301// current content state during tab closing we use a shorter timeout for the
302// foreground renderer. This means there is a small window of time from which
303// content state is modified and not sent to session restore, but this is
304// better than having to wake up all renderers during shutdown.
305static const int kDelaySecondsForContentStateSyncHidden = 5;
306static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29307
[email protected]e99ef6f2011-10-16 01:13:00308static const size_t kExtraCharsBeforeAndAfterSelection = 100;
309
[email protected]0aa55312008-10-17 21:53:08310// The maximum number of popups that can be spawned from one page.
311static const int kMaximumNumberOfUnacknowledgedPopups = 25;
312
[email protected]c514d6372011-08-16 22:54:44313static const float kScalingIncrement = 0.1f;
314
[email protected]47578fa02011-11-02 19:34:41315static const float kScalingIncrementForGesture = 0.01f;
316
[email protected]726985e22009-06-18 21:09:28317static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
318 WebVector<WebURL> urls;
319 ds->redirectChain(urls);
320 result->reserve(urls.size());
321 for (size_t i = 0; i < urls.size(); ++i)
322 result->push_back(urls[i]);
323}
324
[email protected]007733c2011-11-17 00:34:07325// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44326// the AltErrorPageResourceFetcher is reset.
327static void StopAltErrorPageFetcher(WebDataSource* data_source) {
328 if (data_source) {
[email protected]007733c2011-11-17 00:34:07329 DocumentState* document_state = DocumentState::FromDataSource(data_source);
330 if (document_state)
331 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44332 }
333}
334
[email protected]007733c2011-11-17 00:34:07335static bool IsReload(const ViewMsg_Navigate_Params& params) {
336 return
337 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
338 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
339}
340
[email protected]b9fd01ba2012-02-28 01:50:40341static WebReferrerPolicy GetReferrerPolicyFromRequest(
[email protected]445e1042011-12-03 21:03:15342 const WebURLRequest& request) {
343 return request.extraData() ?
344 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
345 WebKit::WebReferrerPolicyDefault;
346}
347
[email protected]b9fd01ba2012-02-28 01:50:40348static WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
349 const WebURLResponse& response) {
350 return static_cast<WebURLResponseExtraDataImpl*>(
351 response.extraData());
352}
353
[email protected]2149cc622012-02-14 01:12:12354NOINLINE static void CrashIntentionally() {
355 // NOTE(shess): Crash directly rather than using NOTREACHED() so
356 // that the signature is easier to triage in crash reports.
357 volatile int* zero = NULL;
358 *zero = 0;
359}
360
[email protected]8bf1048012012-02-08 01:22:18361static void MaybeHandleDebugURL(const GURL& url) {
362 if (!url.SchemeIs(chrome::kChromeUIScheme))
363 return;
364 if (url == GURL(chrome::kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12365 CrashIntentionally();
[email protected]8bf1048012012-02-08 01:22:18366 } else if (url == GURL(chrome::kChromeUIKillURL)) {
367 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
368 } else if (url == GURL(chrome::kChromeUIHangURL)) {
369 for (;;) {
370 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
371 }
372 } else if (url == GURL(chrome::kChromeUIShorthangURL)) {
373 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
374 }
375}
376
initial.commit09911bf2008-07-26 23:55:29377///////////////////////////////////////////////////////////////////////////////
378
[email protected]310ebd6302011-10-10 19:06:28379struct RenderViewImpl::PendingFileChooser {
[email protected]8caadeb2011-11-22 02:45:23380 PendingFileChooser(const content::FileChooserParams& p,
[email protected]cdaf8d02010-03-30 19:52:47381 WebFileChooserCompletion* c)
382 : params(p),
383 completion(c) {
384 }
[email protected]8caadeb2011-11-22 02:45:23385 content::FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47386 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
387};
388
[email protected]217690d2012-01-27 07:33:11389namespace {
390
391class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
392 public:
[email protected]82114f52012-03-20 22:53:41393 explicit WebWidgetLockTarget(WebKit::WebWidget* webwidget)
[email protected]217690d2012-01-27 07:33:11394 : webwidget_(webwidget) {}
395
396 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
397 if (succeeded)
398 webwidget_->didAcquirePointerLock();
399 else
400 webwidget_->didNotAcquirePointerLock();
401 }
402
403 virtual void OnMouseLockLost() OVERRIDE {
404 webwidget_->didLosePointerLock();
405 }
406
407 virtual bool HandleMouseLockedInputEvent(
408 const WebKit::WebMouseEvent &event) OVERRIDE {
409 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
410 return false;
411 }
412
413 private:
414 WebKit::WebWidget* webwidget_;
415};
416
[email protected]86cd9472012-02-03 19:51:05417int64 ExtractPostId(const WebHistoryItem& item) {
418 if (item.isNull())
419 return -1;
420
421 if (item.httpBody().isNull())
422 return -1;
423
424 return item.httpBody().identifier();
425}
426
[email protected]217690d2012-01-27 07:33:11427} // namespace
428
[email protected]daf82f82011-10-31 22:35:31429RenderViewImpl::RenderViewImpl(
430 gfx::NativeViewId parent_hwnd,
431 int32 opener_id,
432 const content::RendererPreferences& renderer_prefs,
433 const WebPreferences& webkit_prefs,
434 SharedRenderViewCounter* counter,
435 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56436 int32 surface_id,
[email protected]daf82f82011-10-31 22:35:31437 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46438 const string16& frame_name,
[email protected]6fd35b72012-03-01 19:46:41439 int32 next_page_id,
[email protected]8cca3da2012-03-20 08:26:34440 const WebKit::WebScreenInfo& screen_info,
[email protected]3e3c4522012-04-13 21:16:29441 bool guest,
442 AccessibilityMode accessibility_mode)
[email protected]6fd35b72012-03-01 19:46:41443 : RenderWidget(WebKit::WebPopupTypeNone, screen_info),
[email protected]676126f72011-01-15 00:03:51444 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02445 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09446 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02447 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24448 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21449 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02450 opened_by_user_gesture_(true),
451 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24452 page_id_(-1),
453 last_page_id_sent_to_browser_(-1),
[email protected]74ce1ad2011-12-16 21:51:46454 next_page_id_(next_page_id),
[email protected]3cc72b12010-03-18 23:03:00455 history_list_offset_(-1),
456 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02457 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55458 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31459 cached_is_main_frame_pinned_to_left_(false),
460 cached_is_main_frame_pinned_to_right_(false),
461 cached_has_main_frame_horizontal_scrollbar_(false),
462 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]05a980d7a2012-02-07 22:16:42463 context_has_swapbuffers_complete_callback_(false),
464 queried_for_swapbuffers_complete_callback_(false),
[email protected]d0fb8a72012-03-10 18:54:52465 context_is_web_graphics_context_3d_command_buffer_impl_(false),
[email protected]3354d3e2010-06-10 19:53:02466 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51467 geolocation_dispatcher_(NULL),
[email protected]c52b2892012-03-07 11:01:02468 input_tag_speech_dispatcher_(NULL),
[email protected]676126f72011-01-15 00:03:51469 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51470 media_stream_dispatcher_(NULL),
[email protected]1bc65a42012-04-23 09:31:25471 media_stream_impl_(NULL),
[email protected]cae8c8492011-03-03 11:12:18472 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41473 devtools_agent_(NULL),
[email protected]063afcb2011-09-29 07:54:32474 renderer_accessibility_(NULL),
[email protected]217690d2012-01-27 07:33:11475 mouse_lock_dispatcher_(NULL),
[email protected]4fb60142011-08-09 02:22:08476 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18477 handling_select_range_(false),
478#if defined(OS_WIN)
479 focused_plugin_id_(-1),
480#endif
[email protected]8cca3da2012-03-20 08:26:34481 guest_(guest),
[email protected]3e3c4522012-04-13 21:16:29482 accessibility_mode_(accessibility_mode),
[email protected]ef5e98e2011-12-06 09:49:18483 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]676126f72011-01-15 00:03:51484 routing_id_ = routing_id;
[email protected]9f4f3322012-01-18 22:29:56485 surface_id_ = surface_id;
[email protected]676126f72011-01-15 00:03:51486 if (opener_id != MSG_ROUTING_NONE)
487 opener_id_ = opener_id;
488
[email protected]74ce1ad2011-12-16 21:51:46489 // Ensure we start with a valid next_page_id_ from the browser.
490 DCHECK_GE(next_page_id_, 0);
491
[email protected]21b3a6ae2011-11-30 00:45:29492#if defined(ENABLE_NOTIFICATIONS)
493 notification_provider_ = new NotificationProvider(this);
494#else
495 notification_provider_ = NULL;
496#endif
497
[email protected]11fee2332011-03-29 20:36:35498 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11499 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35500
[email protected]676126f72011-01-15 00:03:51501 if (counter) {
502 shared_popup_counter_ = counter;
503 shared_popup_counter_->data++;
504 decrement_shared_popup_at_destruction_ = true;
505 } else {
506 shared_popup_counter_ = new SharedRenderViewCounter(0);
507 decrement_shared_popup_at_destruction_ = false;
508 }
509
[email protected]380244092011-10-07 17:26:27510 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51511 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47512 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51513 AddRef();
514
515 // If this is a popup, we must wait for the CreatingNew_ACK message before
516 // completing initialization. Otherwise, we can finish it now.
517 if (opener_id == MSG_ROUTING_NONE) {
518 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55519 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51520 }
521
[email protected]34c61bd52011-05-02 19:38:33522 g_view_map.Get().insert(std::make_pair(webview(), this));
523 webkit_preferences_.Apply(webview());
524 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35525 if (!frame_name.empty())
526 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33527 webview()->settings()->setMinimumTimerInterval(
528 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
529 webkit_glue::kForegroundTabTimerInterval);
530
531 OnSetRendererPrefs(renderer_prefs);
532
[email protected]676126f72011-01-15 00:03:51533 host_window_ = parent_hwnd;
534
[email protected]a026daa2011-04-20 15:49:51535#if defined(ENABLE_P2P_APIS)
[email protected]273558fb2012-01-12 15:03:51536 if (!p2p_socket_dispatcher_)
537 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51538#endif
[email protected]cae8c8492011-03-03 11:12:18539
[email protected]5b87e782012-02-09 18:19:32540#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02541 if (!media_stream_dispatcher_)
542 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32543#endif
[email protected]735873d2012-01-25 23:31:02544
[email protected]8f6a3b852011-07-19 16:48:56545 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32546#if defined(OS_MACOSX)
547 new TextInputClientObserver(this);
548#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56549
[email protected]217690d2012-01-27 07:33:11550 // The next group of objects all implement RenderViewObserver, so are deleted
551 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41552 devtools_agent_ = new DevToolsAgent(this);
[email protected]3e3c4522012-04-13 21:16:29553 renderer_accessibility_ = new RendererAccessibility(this, accessibility_mode);
[email protected]217690d2012-01-27 07:33:11554 mouse_lock_dispatcher_ = new MouseLockDispatcher(this);
[email protected]0fc7dea72012-02-09 03:47:40555 intents_host_ = new WebIntentsHost(this);
[email protected]063afcb2011-09-29 07:54:32556
[email protected]1784b2f2011-11-24 10:53:48557 new IdleUserDetector(this);
558
[email protected]766a7082012-02-03 23:39:15559 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
560 if (command_line.HasSwitch(switches::kDomAutomationController))
561 enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION;
562
[email protected]5b52cd2f712012-03-28 02:12:48563 ProcessViewLayoutFlags(command_line);
[email protected]7ddea9802012-02-22 23:08:05564
[email protected]e48869a2011-04-01 19:56:03565 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29566}
567
[email protected]310ebd6302011-10-10 19:06:28568RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03569 history_page_ids_.clear();
570
[email protected]0aa55312008-10-17 21:53:08571 if (decrement_shared_popup_at_destruction_)
572 shared_popup_counter_->data--;
573
[email protected]a1128322009-10-06 18:38:46574 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47575 while (!file_chooser_completions_.empty()) {
576 if (file_chooser_completions_.front()->completion) {
577 file_chooser_completions_.front()->completion->didChooseFile(
578 WebVector<WebString>());
579 }
580 file_chooser_completions_.pop_front();
581 }
[email protected]a1128322009-10-06 18:38:46582
[email protected]83dde542009-09-11 20:59:55583#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11584 // Destroy all fake plugin window handles on the browser side.
585 while (!fake_plugin_window_handles_.empty()) {
586 // Make sure no NULL plugin window handles were inserted into this list.
587 DCHECK(*fake_plugin_window_handles_.begin());
588 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
589 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
590 }
[email protected]83dde542009-09-11 20:59:55591#endif
[email protected]98324892009-09-09 21:16:05592
[email protected]60c42a8c72009-10-09 04:08:59593#ifndef NDEBUG
594 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49595 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59596 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
597 DCHECK_NE(this, it->second) << "Failed to call Close?";
598#endif
[email protected]676126f72011-01-15 00:03:51599
[email protected]310ebd6302011-10-10 19:06:28600 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51601 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59602}
603
604/*static*/
[email protected]310ebd6302011-10-10 19:06:28605RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31606 ViewMap* views = g_view_map.Pointer();
607 ViewMap::iterator it = views->find(webview);
608 return it == views->end() ? NULL : it->second;
609}
610
611/*static*/
612content::RenderView*
613 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28614 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31615}
616
617/*static*/
618void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49619 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59620 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
621 if (!visitor->Visit(it->second))
622 return;
623 }
624}
625
626/*static*/
[email protected]310ebd6302011-10-10 19:06:28627RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15628 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08629 int32 opener_id,
[email protected]daf82f82011-10-31 22:35:31630 const content::RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08631 const WebPreferences& webkit_prefs,
632 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34633 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56634 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26635 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46636 const string16& frame_name,
[email protected]6fd35b72012-03-01 19:46:41637 int32 next_page_id,
[email protected]8cca3da2012-03-20 08:26:34638 const WebKit::WebScreenInfo& screen_info,
[email protected]3e3c4522012-04-13 21:16:29639 bool guest,
640 AccessibilityMode accessibility_mode) {
initial.commit09911bf2008-07-26 23:55:29641 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28642 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51643 parent_hwnd,
644 opener_id,
645 renderer_prefs,
646 webkit_prefs,
647 counter,
648 routing_id,
[email protected]9f4f3322012-01-18 22:29:56649 surface_id,
[email protected]676126f72011-01-15 00:03:51650 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46651 frame_name,
[email protected]6fd35b72012-03-01 19:46:41652 next_page_id,
[email protected]8cca3da2012-03-20 08:26:34653 screen_info,
[email protected]3e3c4522012-04-13 21:16:29654 guest,
655 accessibility_mode);
initial.commit09911bf2008-07-26 23:55:29656}
657
[email protected]50da23d02012-04-13 17:47:48658WebPeerConnectionHandler* RenderViewImpl::CreatePeerConnectionHandler(
659 WebPeerConnectionHandlerClient* client) {
[email protected]273558fb2012-01-12 15:03:51660 EnsureMediaStreamImpl();
[email protected]1bc65a42012-04-23 09:31:25661 if (!media_stream_impl_)
[email protected]5b87e782012-02-09 18:19:32662 return NULL;
[email protected]273558fb2012-01-12 15:03:51663 return media_stream_impl_->CreatePeerConnectionHandler(client);
664}
665
[email protected]50da23d02012-04-13 17:47:48666WebPeerConnection00Handler* RenderViewImpl::CreatePeerConnectionHandlerJsep(
667 WebPeerConnection00HandlerClient* client) {
668 EnsureMediaStreamImpl();
[email protected]1bc65a42012-04-23 09:31:25669 if (!media_stream_impl_)
[email protected]50da23d02012-04-13 17:47:48670 return NULL;
671 return media_stream_impl_->CreatePeerConnectionHandlerJsep(client);
672}
673
[email protected]310ebd6302011-10-10 19:06:28674void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51675 observers_.AddObserver(observer);
676}
677
[email protected]310ebd6302011-10-10 19:06:28678void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
679 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51680 observers_.RemoveObserver(observer);
681}
682
[email protected]310ebd6302011-10-10 19:06:28683WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26684 return static_cast<WebKit::WebView*>(webwidget());
685}
686
[email protected]310ebd6302011-10-10 19:06:28687void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40688 if (!enabled) {
689 load_progress_tracker_.reset(NULL);
690 return;
691 }
692 if (load_progress_tracker_ == NULL)
693 load_progress_tracker_.reset(new LoadProgressTracker(this));
694}
695
[email protected]310ebd6302011-10-10 19:06:28696void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51697 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29698}
699
[email protected]310ebd6302011-10-10 19:06:28700void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26701 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30702 // If the renderer is visible, set initial visibility and focus state.
703 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34704#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30705 delegate->SetContainerVisibility(true);
706 if (webview() && webview()->isActive())
707 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34708#endif
[email protected]49232292010-09-03 19:07:30709 }
[email protected]784ea1ab2010-09-18 00:02:34710 // Plugins start assuming the content has focus (so that they work in
711 // environments where RenderView isn't hosting them), so we always have to
712 // set the initial state. See webplugin_delegate_impl.h for details.
713 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26714}
715
[email protected]310ebd6302011-10-10 19:06:28716void RenderViewImpl::UnregisterPluginDelegate(
717 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26718 plugin_delegates_.erase(delegate);
719}
[email protected]d8fd6fa2010-02-01 15:54:26720
[email protected]310ebd6302011-10-10 19:06:28721bool RenderViewImpl::GetPluginInfo(const GURL& url,
722 const GURL& page_url,
723 const std::string& mime_type,
724 webkit::WebPluginInfo* plugin_info,
725 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08726 bool found = false;
727 Send(new ViewHostMsg_GetPluginInfo(
728 routing_id_, url, page_url, mime_type, &found, plugin_info,
729 actual_mime_type));
730 return found;
731}
732
[email protected]7a1ec28a2012-03-28 21:10:24733void RenderViewImpl::TransferActiveWheelFlingAnimation(
734 const WebKit::WebActiveWheelFlingParameters& params) {
735 if (webview())
736 webview()->transferActiveWheelFlingAnimation(params);
737}
738
[email protected]310ebd6302011-10-10 19:06:28739bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27740 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27741 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41742 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26743
[email protected]676126f72011-01-15 00:03:51744 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
745 RenderViewObserver* observer;
746 while ((observer = it.GetNext()) != NULL)
747 if (observer->OnMessageReceived(message))
748 return true;
[email protected]b2abac72009-02-26 12:39:28749
[email protected]a95986a82010-12-24 06:19:28750 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40751 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28752 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29753 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
754 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56755 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29756 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
757 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
758 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
759 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27760#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35761 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27762#endif
initial.commit09911bf2008-07-26 23:55:29763 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15764 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29765 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
766 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
767 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08768 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29769 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15770 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29771 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49772 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
773 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17774 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17775 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41776 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54777 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
778 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29779 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18780 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
781 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29782 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48783 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55784 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
785 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
786 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
787 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
788 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
789 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
790 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45791 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40792 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29793 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19794 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
795 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29796 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
797 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
798 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51799 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
800 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29801 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04802 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15803 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29804 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
805 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08806 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
807 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00808 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16809 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14810 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25811 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
812 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:47813 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:34814 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:10815 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
816 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51817 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56818 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:36819 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:34820 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]7a17bac02012-03-07 21:58:12821 IPC_MESSAGE_HANDLER(ViewMsg_SetNavigationStartTime,
822 OnSetNavigationStartTime)
[email protected]6ce7abc52010-02-02 18:40:14823#if defined(OS_MACOSX)
824 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13825 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13826 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
827 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14828#endif
[email protected]446705872009-09-10 07:22:48829 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33830 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33831 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
832 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24833 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42834 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
835 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19836 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
837 OnGetAllSavableResourceLinksForCurrentPage)
838 IPC_MESSAGE_HANDLER(
839 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
840 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08841#if defined(OS_MACOSX)
842 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
843#endif
[email protected]521b2482011-01-15 00:10:10844 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51845 // TODO(viettrungluu): Move to a separate message filter.
[email protected]54ca3ca892011-06-07 21:14:54846#if defined(OS_MACOSX)
847 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
848#endif
[email protected]9e1ad4b2011-08-14 16:49:19849 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
850 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18851 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]7f3c7af2011-10-20 22:52:51852 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]9e1ad4b2011-08-14 16:49:19853
initial.commit09911bf2008-07-26 23:55:29854 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28855 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29856 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40857
858 if (!msg_is_ok) {
859 // The message had a handler, but its deserialization failed.
860 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:28861 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:40862 }
863
[email protected]a95986a82010-12-24 06:19:28864 return handled;
initial.commit09911bf2008-07-26 23:55:29865}
866
[email protected]310ebd6302011-10-10 19:06:28867void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]8bf1048012012-02-08 01:22:18868 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:29869 if (!webview())
870 return;
871
[email protected]440a0e52011-09-13 17:38:58872 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
873
[email protected]007733c2011-11-17 00:34:07874 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:03875
876 // If this is a stale back/forward (due to a recent navigation the browser
877 // didn't know about), ignore it.
878 if (IsBackForwardToStaleEntry(params, is_reload))
879 return;
880
[email protected]992db4c2011-05-12 15:37:15881 // Swap this renderer back in if necessary.
882 if (is_swapped_out_)
883 SetSwappedOut(false);
884
[email protected]3cc72b12010-03-18 23:03:00885 history_list_offset_ = params.current_history_list_offset;
886 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03887 if (history_list_length_ >= 0)
888 history_page_ids_.resize(history_list_length_, -1);
889 if (params.pending_history_list_offset >= 0 &&
890 params.pending_history_list_offset < history_list_length_)
891 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00892
[email protected]38b592902011-04-16 02:08:42893 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29894
[email protected]26aa0482009-09-30 16:55:27895 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45896 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29897 // We cannot reload if we do not have any history state. This happens, for
898 // example, when recovering from a crash. Our workaround here is a bit of
899 // a hack since it means that reload after a crashed tab does not cause an
900 // end-to-end cache validation.
901 is_reload = false;
902 }
903
[email protected]007733c2011-11-17 00:34:07904 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
905 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:50906
[email protected]04d3c6e2009-05-22 17:00:13907 // If we are reloading, then WebKit will use the history state of the current
908 // page, so we should just ignore any given history state. Otherwise, if we
909 // have history state, then we need to navigate to it, which corresponds to a
910 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55911 if (is_reload) {
[email protected]ecbf10d2010-02-18 13:03:29912 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02913 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29914 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55915 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13916 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58917 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45918 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17919 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13920 } else {
921 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28922 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29923
[email protected]e6f546c32009-07-01 17:12:55924 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:23925 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13926
[email protected]dd7daa82009-08-10 05:46:45927 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55928 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13929
[email protected]445e1042011-12-03 21:03:15930 if (params.referrer.url.is_valid()) {
931 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
932 params.referrer.policy,
933 params.url,
934 WebString::fromUTF8(params.referrer.url.spec()));
935 if (!referrer.isEmpty())
936 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:28937 }
[email protected]04d3c6e2009-05-22 17:00:13938
[email protected]52c68652010-12-07 17:47:04939 if (!params.extra_headers.empty()) {
940 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
941 params.extra_headers.end(), "\n");
942 i.GetNext(); ) {
943 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
944 WebString::fromUTF8(i.values()));
945 }
946 }
[email protected]dd7daa82009-08-10 05:46:45947 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50948 }
949
[email protected]77f17a82009-05-21 04:42:54950 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:07951 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:29952}
953
[email protected]310ebd6302011-10-10 19:06:28954bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:03955 const ViewMsg_Navigate_Params& params,
956 bool is_reload) {
957 // Make sure this isn't a back/forward to an entry we have already cropped
958 // or replaced from our history, before the browser knew about it. If so,
959 // a new navigation has committed in the mean time, and we can ignore this.
960 bool is_back_forward = !is_reload && !params.state.empty();
961
962 // Note: if the history_list_length_ is 0 for a back/forward, we must be
963 // restoring from a previous session. We'll update our state in OnNavigate.
964 if (!is_back_forward || history_list_length_ <= 0)
965 return false;
966
967 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
968
969 // Check for whether the forward history has been cropped due to a recent
970 // navigation the browser didn't know about.
971 if (params.pending_history_list_offset >= history_list_length_)
972 return true;
973
974 // Check for whether this entry has been replaced with a new one.
975 int expected_page_id =
976 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44977 if (expected_page_id > 0 && params.page_id != expected_page_id) {
978 if (params.page_id < expected_page_id)
979 return true;
980
981 // Otherwise we've removed an earlier entry and should have shifted all
982 // entries left. For now, it's ok to lazily update the list.
983 // TODO(creis): Notify all live renderers when we remove entries from
984 // the front of the list, so that we don't hit this case.
985 history_page_ids_[params.pending_history_list_offset] = params.page_id;
986 }
[email protected]d466b8a2011-07-15 21:48:03987
988 return false;
989}
990
initial.commit09911bf2008-07-26 23:55:29991// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:28992void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44993 if (webview()) {
994 WebFrame* main_frame = webview()->mainFrame();
995 // Stop the alt error page fetcher. If we let it continue it may complete
996 // and cause RenderViewHostManager to swap to this RenderView, even though
997 // it may no longer be active.
998 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
999 StopAltErrorPageFetcher(main_frame->dataSource());
1000 main_frame->stopLoading();
1001 }
initial.commit09911bf2008-07-26 23:55:291002}
1003
[email protected]ecbf10d2010-02-18 13:03:291004// Reload current focused frame.
1005// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:281006void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291007 if (webview() && webview()->focusedFrame()) {
1008 // We always obey the cache (ignore_cache=false) here.
1009 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1010 // a cache-ignoring reload of the frame.
1011 webview()->focusedFrame()->reload(false);
1012 }
[email protected]1dda4022010-01-28 18:24:561013}
1014
[email protected]310ebd6302011-10-10 19:06:281015void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271016 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291017}
1018
[email protected]310ebd6302011-10-10 19:06:281019void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:251020 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271021 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251022 return;
1023
[email protected]26aa0482009-09-30 16:55:271024 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451025 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251026}
1027
[email protected]310ebd6302011-10-10 19:06:281028void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291029 // Check if there is a targeturl waiting to be sent.
1030 if (target_url_status_ == TARGET_PENDING) {
1031 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1032 pending_target_url_));
1033 }
1034
1035 target_url_status_ = TARGET_NONE;
1036}
1037
[email protected]310ebd6302011-10-10 19:06:281038void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:291039 if (!webview())
1040 return;
1041
[email protected]26aa0482009-09-30 16:55:271042 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:291043}
1044
[email protected]310ebd6302011-10-10 19:06:281045void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:291046 if (!webview())
1047 return;
1048
[email protected]26aa0482009-09-30 16:55:271049 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:291050}
1051
[email protected]310ebd6302011-10-10 19:06:281052void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:291053 if (!webview())
1054 return;
1055
[email protected]26aa0482009-09-30 16:55:271056 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:291057}
1058
[email protected]310ebd6302011-10-10 19:06:281059void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291060 if (!webview())
1061 return;
1062
[email protected]f6b1856b2011-06-29 22:02:531063 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
1064 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:291065}
1066
[email protected]c0cc3092009-09-12 08:27:271067#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281068void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:351069 if (!webview())
1070 return;
1071
1072 // Since the find pasteboard supports only plain text, this can be simpler
1073 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271074 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351075 if (frame->hasSelection()) {
1076 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:271077 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:171078 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:351079 }
[email protected]a954bf72009-09-12 07:30:351080}
[email protected]c0cc3092009-09-12 08:27:271081#endif
[email protected]a954bf72009-09-12 07:30:351082
[email protected]310ebd6302011-10-10 19:06:281083void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291084 if (!webview())
1085 return;
1086
[email protected]26aa0482009-09-30 16:55:271087 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:291088}
1089
[email protected]44bf7002011-10-16 02:46:151090void RenderViewImpl::OnPasteAndMatchStyle() {
1091 if (!webview())
1092 return;
1093
1094 webview()->focusedFrame()->executeCommand(
1095 WebString::fromUTF8("PasteAndMatchStyle"));
1096}
1097
[email protected]310ebd6302011-10-10 19:06:281098void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291099 if (!webview())
1100 return;
1101
[email protected]1ff7a032010-02-03 02:46:031102 WebFrame* frame = webview()->focusedFrame();
1103 if (!frame->hasSelection())
1104 frame->selectWordAroundCaret();
1105 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291106}
1107
[email protected]310ebd6302011-10-10 19:06:281108void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:291109 if (!webview())
1110 return;
1111
[email protected]26aa0482009-09-30 16:55:271112 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:291113}
1114
[email protected]310ebd6302011-10-10 19:06:281115void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291116 if (!webview())
1117 return;
1118
[email protected]26aa0482009-09-30 16:55:271119 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221120 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:291121}
1122
[email protected]310ebd6302011-10-10 19:06:281123void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1124 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:081125 if (!webview())
1126 return;
1127
1128 handling_select_range_ = true;
1129 webview()->focusedFrame()->selectRange(start, end);
1130 handling_select_range_ = false;
1131}
1132
[email protected]310ebd6302011-10-10 19:06:281133void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1134 int32 minimum_page_id) {
[email protected]9e1ad4b2011-08-14 16:49:191135 DCHECK(history_length >= 0);
1136 DCHECK(history_list_offset_ == history_list_length_ - 1);
1137 DCHECK(minimum_page_id >= -1);
1138
1139 // Generate the new list.
1140 std::vector<int32> new_history_page_ids(history_length, -1);
1141 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1142 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1143 continue;
1144 new_history_page_ids.push_back(history_page_ids_[i]);
1145 }
1146 new_history_page_ids.swap(history_page_ids_);
1147
1148 // Update indexes.
1149 history_list_length_ = history_page_ids_.size();
1150 history_list_offset_ = history_list_length_ - 1;
1151}
1152
1153
[email protected]310ebd6302011-10-10 19:06:281154void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291155 if (!webview())
1156 return;
[email protected]26aa0482009-09-30 16:55:271157 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291158}
1159
[email protected]54ca3ca892011-06-07 21:14:541160#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281161void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331162 if (!webview())
1163 return;
1164 if (in_live_resize)
1165 webview()->willStartLiveResize();
1166 else
1167 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541168}
1169#endif
1170
[email protected]310ebd6302011-10-10 19:06:281171void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1172 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091173 WebKit::WebNode node = GetFocusedNode();
1174 if (!node.isNull()) {
1175 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191176 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511177 }
1178}
1179
initial.commit09911bf2008-07-26 23:55:291180///////////////////////////////////////////////////////////////////////////////
1181
1182// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281183void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451184 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291185 DCHECK(ds);
1186
[email protected]726985e22009-06-18 21:09:281187 const WebURLRequest& request = ds->request();
1188 const WebURLRequest& original_request = ds->originalRequest();
1189 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291190
[email protected]007733c2011-11-17 00:34:071191 DocumentState* document_state = DocumentState::FromDataSource(ds);
1192 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291193
1194 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281195 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291196 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051197 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291198 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071199 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191200 params.socket_address.set_host(response.remoteIPAddress().utf8());
1201 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031202 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091203 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071204 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291205 // SSL state specified in the request takes precedence over the one in the
1206 // response.
1207 // So far this is only intended for error pages that are not expected to be
1208 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281209 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071210 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291211 } else {
[email protected]726985e22009-06-18 21:09:281212 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291213 }
1214
1215 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:311216 params.url = GetLoadingUrl(frame);
initial.commit09911bf2008-07-26 23:55:291217
[email protected]5f9b8712011-11-23 08:55:571218 if (frame->document().baseURL() != params.url)
1219 params.base_url = frame->document().baseURL();
1220
[email protected]726985e22009-06-18 21:09:281221 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241222 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041223 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291224
[email protected]007733c2011-11-17 00:34:071225 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351226 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071227 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291228
1229 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071230 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291231 if (password_form_data)
1232 params.password_form = *password_form_data;
1233
1234 params.gesture = navigation_gesture_;
1235 navigation_gesture_ = NavigationGestureUnknown;
1236
[email protected]0f38dc4552011-02-25 11:24:001237 // Make navigation state a part of the FrameNavigate message so that commited
1238 // entry had it at all times.
1239 const WebHistoryItem& item = frame->currentHistoryItem();
1240 if (!item.isNull()) {
1241 params.content_state = webkit_glue::HistoryItemToString(item);
1242 } else {
1243 params.content_state =
1244 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1245 }
1246
[email protected]dd7daa82009-08-10 05:46:451247 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291248 // Top-level navigation.
1249
[email protected]b75b8292010-10-01 07:28:251250 // Set zoom level, but don't do it for full-page plugin since they don't use
1251 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011252 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541253 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251254 if (webview()->mainFrame()->document().isPluginDocument()) {
1255 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251256 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251257 } else {
1258 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251259 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251260 }
1261
[email protected]f85f0702010-01-30 09:31:011262 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511263 // This zoom level was merely recorded transiently for this load. We can
1264 // erase it now. If at some point we reload this page, the browser will
1265 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011266 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511267 }
1268
[email protected]b75b8292010-10-01 07:28:251269 // Reset the zoom limits in case a plugin had changed them previously. This
1270 // will also call us back which will cause us to send a message to
[email protected]770005b2012-04-16 15:58:131271 // update WebContentsImpl.
[email protected]b75b8292010-10-01 07:28:251272 webview()->zoomLimitsChanged(
[email protected]0f083402011-11-22 02:59:011273 WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
1274 WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
[email protected]b75b8292010-10-01 07:28:251275
initial.commit09911bf2008-07-26 23:55:291276 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551277 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291278
[email protected]daa8c58e2009-06-15 17:21:101279 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581280 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291281 // If the main frame does a load, it should not be reported as a subframe
1282 // navigation. This can occur in the following case:
1283 // 1. You're on a site with frames.
1284 // 2. You do a subframe navigation. This is stored with transition type
1285 // MANUAL_SUBFRAME.
1286 // 3. You navigate to some non-frame site, say, google.com.
1287 // 4. You navigate back to the page from step 2. Since it was initially
1288 // MANUAL_SUBFRAME, it will be that same transition type here.
1289 // We don't want that, because any navigation that changes the toplevel
1290 // frame should be tracked as a toplevel navigation (this allows us to
1291 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581292 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291293 }
1294
initial.commit09911bf2008-07-26 23:55:291295 // If we have a valid consumed client redirect source,
1296 // the page contained a client redirect (meta refresh, document.loc...),
1297 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151298 if (completed_client_redirect_src_.url.is_valid()) {
1299 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291300 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581301 params.transition = static_cast<content::PageTransition>(
1302 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291303 } else {
1304 // Bug 654101: the referrer will be empty on https->http transitions. It
1305 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151306 params.referrer = Referrer(GURL(
1307 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:401308 GetReferrerPolicyFromRequest(original_request));
initial.commit09911bf2008-07-26 23:55:291309 }
1310
[email protected]726985e22009-06-18 21:09:281311 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051312 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291313 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051314 params.post_id = ExtractPostId(item);
1315 }
initial.commit09911bf2008-07-26 23:55:291316
[email protected]c2a797d2009-09-21 16:46:321317 // Save some histogram data so we can compute the average memory used per
1318 // page load of the glyphs.
1319 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1320 webkit_glue::GetGlyphPageCount());
1321
[email protected]15cf526b2010-02-12 06:33:491322 // This message needs to be sent before any of allowScripts(),
1323 // allowImages(), allowPlugins() is called for the new page, so that when
1324 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1325 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291326 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1327 } else {
1328 // Subframe navigation: the type depends on whether this navigation
1329 // generated a new session history entry. When they do generate a session
1330 // history entry, it means the user initiated the navigation and we should
1331 // mark it as such. This test checks if this is the first time UpdateURL
1332 // has been called since WillNavigateToURL was called to initiate the load.
1333 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581334 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291335 else
[email protected]2905f742011-10-13 03:51:581336 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291337
initial.commit09911bf2008-07-26 23:55:291338 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1339 }
1340
1341 last_page_id_sent_to_browser_ =
1342 std::max(last_page_id_sent_to_browser_, page_id_);
1343
1344 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101345 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581346 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291347}
1348
1349// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281350void RenderViewImpl::UpdateTitle(WebFrame* frame,
1351 const string16& title,
1352 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461353 // Ignore all but top level navigations.
1354 if (frame->parent())
1355 return;
1356
1357 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1358 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1359 title_direction));
initial.commit09911bf2008-07-26 23:55:291360}
1361
[email protected]310ebd6302011-10-10 19:06:281362void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1363 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291364 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271365 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291366 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301367 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291368 last_encoding_name_ = encoding_name;
1369
[email protected]e38f40152008-09-12 23:08:301370 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291371 }
1372}
1373
[email protected]e15f680732010-11-23 22:30:201374// Sends the last committed session history state to the browser so it will be
1375// saved before we navigate to a new page. This must be called *before* the
1376// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281377void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291378 // If we have a valid page ID at this point, then it corresponds to the page
1379 // we are navigating away from. Otherwise, this is the first navigation, so
1380 // there is no past session history to record.
1381 if (page_id_ == -1)
1382 return;
1383
[email protected]ca948a22009-06-25 19:36:171384 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271385 webview()->mainFrame()->previousHistoryItem();
[email protected]6459800a2012-03-27 23:57:051386 SendUpdateState(item);
1387}
1388
1389void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
[email protected]ca948a22009-06-25 19:36:171390 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291391 return;
[email protected]ca948a22009-06-25 19:36:171392
[email protected]285f4bb82012-04-17 15:57:281393 // Don't send state updates for content::kSwappedOutURL.
1394 if (item.urlString() == WebString::fromUTF8(content::kSwappedOutURL))
[email protected]6459800a2012-03-27 23:57:051395 return;
1396
[email protected]ca948a22009-06-25 19:36:171397 Send(new ViewHostMsg_UpdateState(
1398 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291399}
1400
[email protected]310ebd6302011-10-10 19:06:281401void RenderViewImpl::OpenURL(WebFrame* frame,
1402 const GURL& url,
[email protected]445e1042011-12-03 21:03:151403 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281404 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171405 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581406 routing_id_,
1407 url,
1408 referrer,
1409 NavigationPolicyToDisposition(policy),
1410 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171411}
1412
[email protected]79dbc662009-09-04 05:42:511413// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291414
[email protected]310ebd6302011-10-10 19:06:281415void RenderViewImpl::LoadNavigationErrorPage(
1416 WebFrame* frame,
1417 const WebURLRequest& failed_request,
1418 const WebURLError& error,
1419 const std::string& html,
1420 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581421 std::string alt_html;
1422 const std::string* error_html;
1423
1424 if (!html.empty()) {
1425 error_html = &html;
1426 } else {
1427 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1428 failed_request, error, &alt_html, NULL);
1429 error_html = &alt_html;
1430 }
1431
1432 frame->loadHTMLString(*error_html,
[email protected]285f4bb82012-04-17 15:57:281433 GURL(content::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251434 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551435 replace);
initial.commit09911bf2008-07-26 23:55:291436}
1437
[email protected]269f86d2011-12-07 02:43:471438bool RenderViewImpl::RunJavaScriptMessage(ui::JavascriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281439 const string16& message,
1440 const string16& default_value,
1441 const GURL& frame_url,
1442 string16* result) {
initial.commit09911bf2008-07-26 23:55:291443 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411444 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291445 if (!result)
1446 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291447
[email protected]12636df2009-09-28 22:32:211448 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1449 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291450 return success;
1451}
1452
[email protected]310ebd6302011-10-10 19:06:281453bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571454 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1455 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1456 // it is particularly important that we do not call willEnterModalLoop as
1457 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441458 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1459 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571460
1461 message->EnableMessagePumping(); // Runs a nested message loop.
1462 return Send(message);
1463}
1464
[email protected]48c9cf2d2009-09-16 16:47:521465// WebKit::WebViewClient ------------------------------------------------------
1466
[email protected]916dfb62012-03-05 03:39:371467WebView* RenderViewImpl::createView(
1468 WebFrame* creator,
1469 const WebURLRequest& request,
1470 const WebWindowFeatures& features,
1471 const WebString& frame_name,
1472 WebNavigationPolicy policy) {
[email protected]48c9cf2d2009-09-16 16:47:521473 // Check to make sure we aren't overloading on popups.
1474 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1475 return NULL;
1476
[email protected]8ab04652010-06-12 02:47:261477 ViewHostMsg_CreateWindow_Params params;
1478 params.opener_id = routing_id_;
1479 params.user_gesture = creator->isProcessingUserGesture();
1480 params.window_container_type = WindowFeaturesToContainerType(features);
1481 params.session_storage_namespace_id = session_storage_namespace_id_;
1482 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111483 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411484 params.opener_url = creator->document().url();
1485 params.opener_security_origin =
1486 creator->document().securityOrigin().toString().utf8();
[email protected]f92ce2b2012-03-06 18:02:591487 params.opener_suppressed = creator->willSuppressOpenerInNewFrame();
1488 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]41e65502011-01-21 09:29:111489 if (!request.isNull())
1490 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261491
[email protected]48c9cf2d2009-09-16 16:47:521492 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561493 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341494 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521495
[email protected]380244092011-10-07 17:26:271496 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261497 new ViewHostMsg_CreateWindow(params,
1498 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561499 &surface_id,
[email protected]8ab04652010-06-12 02:47:261500 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211501 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521502 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521503
[email protected]8cca3da2012-03-20 08:26:341504 // TODO(fsamuel): The host renderer needs to be able to control whether
1505 // the guest renderer is allowed to do this or not. This current
1506 // behavior is not well defined.
[email protected]310ebd6302011-10-10 19:06:281507 RenderViewImpl* view = RenderViewImpl::Create(
1508 0,
1509 routing_id_,
1510 renderer_preferences_,
1511 webkit_preferences_,
1512 shared_popup_counter_,
1513 routing_id,
[email protected]9f4f3322012-01-18 22:29:561514 surface_id,
[email protected]310ebd6302011-10-10 19:06:281515 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461516 frame_name,
[email protected]6fd35b72012-03-01 19:46:411517 1,
[email protected]8cca3da2012-03-20 08:26:341518 screen_info_,
[email protected]3e3c4522012-04-13 21:16:291519 guest_,
1520 accessibility_mode_);
[email protected]8ab04652010-06-12 02:47:261521 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521522
[email protected]007a848b2009-10-26 15:55:461523 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:591524 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:461525
[email protected]48c9cf2d2009-09-16 16:47:521526 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411527 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521528 if (!creator_url.is_valid() || !creator_url.IsStandard())
1529 creator_url = GURL();
1530 view->creator_url_ = creator_url;
1531
1532 // Copy over the alternate error page URL so we can have alt error pages in
1533 // the new render view (we don't need the browser to send the URL back down).
1534 view->alternate_error_page_url_ = alternate_error_page_url_;
1535
1536 return view->webview();
1537}
1538
[email protected]310ebd6302011-10-10 19:06:281539WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:411540 RenderWidget* widget =
1541 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]48c9cf2d2009-09-16 16:47:521542 return widget->webwidget();
1543}
1544
[email protected]310ebd6302011-10-10 19:06:281545WebWidget* RenderViewImpl::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441546 // TODO(jcivelli): Remove this deprecated method when its been removed from
1547 // the WebViewClient interface. It's been replaced by
1548 // createExternalPopupMenu.
1549 NOTREACHED();
1550 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521551}
1552
[email protected]310ebd6302011-10-10 19:06:281553WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081554 const WebPopupMenuInfo& popup_menu_info,
1555 WebExternalPopupMenuClient* popup_menu_client) {
1556 DCHECK(!external_popup_menu_.get());
1557 external_popup_menu_.reset(
1558 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1559 return external_popup_menu_.get();
1560}
1561
[email protected]310ebd6302011-10-10 19:06:281562RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521563 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531564 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421565 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411566 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531567 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271568 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391569 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561570 return widget;
[email protected]79c7bed2010-09-14 22:28:391571}
1572
[email protected]310ebd6302011-10-10 19:06:281573WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1574 unsigned quota) {
[email protected]b928936b2012-04-13 01:16:161575 CHECK(session_storage_namespace_id_ !=
1576 dom_storage::kInvalidSessionStorageNamespaceId);
1577 return new RendererWebStorageNamespaceImpl(session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341578}
1579
[email protected]7e8b4d12012-01-20 23:39:511580WebGraphicsContext3D* RenderViewImpl::createGraphicsContext3D(
[email protected]40ec0c12012-03-08 12:34:401581 const WebGraphicsContext3D::Attributes& attributes) {
[email protected]7e8b4d12012-01-20 23:39:511582 if (!webview())
1583 return NULL;
1584 // The WebGraphicsContext3DInProcessImpl code path is used for
1585 // layout tests (though not through this code) as well as for
1586 // debugging and bringing up new ports.
[email protected]7e8b4d12012-01-20 23:39:511587 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
[email protected]56200f012012-02-03 23:13:571588 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
[email protected]29dea0e2012-03-16 01:46:581589 attributes, true);
[email protected]7e8b4d12012-01-20 23:39:511590 } else {
[email protected]b3e83de2012-02-07 03:33:281591 GURL url;
1592 if (webview()->mainFrame())
1593 url = GURL(webview()->mainFrame()->document().url());
1594
[email protected]b3e83de2012-02-07 03:33:281595 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
1596 new WebGraphicsContext3DCommandBufferImpl(
[email protected]8c9e0a02012-04-02 05:13:191597 surface_id(),
1598 url,
1599 RenderThreadImpl::current(),
1600 AsWeakPtr()));
[email protected]b3e83de2012-02-07 03:33:281601
[email protected]8c9e0a02012-04-02 05:13:191602 if (!context->Initialize(
1603 attributes,
1604 false /* bind generates resources */,
1605 content::CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
[email protected]56200f012012-02-03 23:13:571606 return NULL;
[email protected]d0fb8a72012-03-10 18:54:521607 context_is_web_graphics_context_3d_command_buffer_impl_ = true;
[email protected]56200f012012-02-03 23:13:571608 return context.release();
[email protected]7e8b4d12012-01-20 23:39:511609 }
[email protected]7e8b4d12012-01-20 23:39:511610}
1611
[email protected]310ebd6302011-10-10 19:06:281612void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521613 const WebConsoleMessage& message, const WebString& source_name,
1614 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081615 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511616 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081617 case WebConsoleMessage::LevelTip:
1618 log_severity = logging::LOG_VERBOSE;
1619 break;
1620 case WebConsoleMessage::LevelLog:
1621 log_severity = logging::LOG_INFO;
1622 break;
1623 case WebConsoleMessage::LevelWarning:
1624 log_severity = logging::LOG_WARNING;
1625 break;
1626 case WebConsoleMessage::LevelError:
1627 log_severity = logging::LOG_ERROR;
1628 break;
1629 default:
1630 NOTREACHED();
1631 }
1632
[email protected]48c9cf2d2009-09-16 16:47:521633 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081634 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311635 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521636 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311637 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521638}
1639
[email protected]310ebd6302011-10-10 19:06:281640void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421641 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521642}
1643
[email protected]310ebd6302011-10-10 19:06:281644WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511645 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021646}
1647
[email protected]310ebd6302011-10-10 19:06:281648bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121649 const WebString& path,
1650 WebFileChooserCompletion* chooser_completion) {
1651 int id = enumeration_completion_id_++;
1652 enumeration_completions_[id] = chooser_completion;
1653 return Send(new ViewHostMsg_EnumerateDirectory(
1654 routing_id_,
1655 id,
1656 webkit_glue::WebStringToFilePath(path)));
1657}
1658
[email protected]310ebd6302011-10-10 19:06:281659void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521660 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:141661 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:521662 return;
1663 }
1664
1665 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521666
1667 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311668
1669 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521670}
1671
[email protected]310ebd6302011-10-10 19:06:281672void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521673 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:141674 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:521675 return;
1676 }
1677
1678 is_loading_ = false;
1679
1680 // NOTE: For now we're doing the safest thing, and sending out notification
1681 // when done loading. This currently isn't an issue as the favicon is only
1682 // displayed when done loading. Ideally we would send notification when
1683 // finished parsing the head, but webkit doesn't support that yet.
1684 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521685 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1686
[email protected]90109412010-12-15 17:14:241687 if (load_progress_tracker_ != NULL)
1688 load_progress_tracker_->DidStopLoading();
1689
[email protected]93b9d692011-04-13 00:44:311690 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521691}
1692
[email protected]310ebd6302011-10-10 19:06:281693void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1694 double load_progress) {
[email protected]90109412010-12-15 17:14:241695 if (load_progress_tracker_ != NULL)
1696 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1697}
1698
[email protected]310ebd6302011-10-10 19:06:281699bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061700#if defined(OS_MACOSX)
1701 return true;
1702#else
1703 return false;
1704#endif
1705}
1706
[email protected]310ebd6302011-10-10 19:06:281707bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031708#if defined(OS_WIN)
1709 return true;
1710#else
1711 return false;
1712#endif
1713}
1714
[email protected]310ebd6302011-10-10 19:06:281715void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081716 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031717 return;
[email protected]4fb60142011-08-09 02:22:081718 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011719
[email protected]fca52022012-04-03 17:00:501720 if (is_empty_selection)
1721 selection_text_.clear();
1722
[email protected]b781ff282011-08-20 06:19:361723 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031724}
1725
[email protected]310ebd6302011-10-10 19:06:281726void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121727 const std::string& name = UTF16ToUTF8(command_name);
1728 if (StartsWithASCII(name, "Move", true) ||
1729 StartsWithASCII(name, "Insert", true) ||
1730 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031731 return;
[email protected]f1a29a02011-10-06 23:08:441732 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031733}
1734
[email protected]310ebd6302011-10-10 19:06:281735bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101736 if (edit_commands_.empty())
1737 return false;
1738
[email protected]26aa0482009-09-30 16:55:271739 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101740 if (!frame)
1741 return false;
1742
1743 EditCommands::iterator it = edit_commands_.begin();
1744 EditCommands::iterator end = edit_commands_.end();
1745
[email protected]507b33ea2009-09-29 03:56:511746 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101747 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331748 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1749 // key (but it's the exception). Once one edit command is not executed, it
1750 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101751 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1752 WebString::fromUTF8(it->value)))
1753 break;
[email protected]507b33ea2009-09-29 03:56:511754 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101755 }
1756
[email protected]507b33ea2009-09-29 03:56:511757 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101758}
1759
[email protected]da8543762012-03-20 08:52:201760WebKit::WebColorChooser* RenderViewImpl::createColorChooser(
1761 WebKit::WebColorChooserClient* client,
1762 const WebKit::WebColor& initial_color) {
1763 RendererWebColorChooserImpl* color_chooser =
1764 new RendererWebColorChooserImpl(this, client);
1765 color_chooser->Open(static_cast<SkColor>(initial_color));
1766 return color_chooser;
1767}
1768
[email protected]310ebd6302011-10-10 19:06:281769bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:351770 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471771 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351772 // Do not open the file dialog in a hidden RenderView.
1773 if (is_hidden())
1774 return false;
[email protected]8caadeb2011-11-22 02:45:231775 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261776 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:231777 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261778 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:231779 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501780 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:231781 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261782 else
[email protected]8caadeb2011-11-22 02:45:231783 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471784 ipc_params.title = params.title;
1785 ipc_params.default_file_name =
1786 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]3314c2b12011-11-02 08:05:461787 ipc_params.accept_types.reserve(params.acceptMIMETypes.size());
1788 for (size_t i = 0; i < params.acceptMIMETypes.size(); ++i)
1789 ipc_params.accept_types.push_back(params.acceptMIMETypes[i]);
[email protected]cdaf8d02010-03-30 19:52:471790
1791 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461792}
1793
[email protected]269f86d2011-12-07 02:43:471794void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
1795 const WebString& message) {
1796 RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:411797 message,
1798 string16(),
[email protected]b6cb3a842011-06-24 18:28:411799 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521800 NULL);
1801}
1802
[email protected]269f86d2011-12-07 02:43:471803bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
1804 const WebString& message) {
1805 return RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:411806 message,
1807 string16(),
[email protected]b6cb3a842011-06-24 18:28:411808 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521809 NULL);
1810}
1811
[email protected]269f86d2011-12-07 02:43:471812bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
1813 const WebString& message,
1814 const WebString& default_value,
1815 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411816 string16 result;
[email protected]269f86d2011-12-07 02:43:471817 bool ok = RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:411818 message,
1819 default_value,
[email protected]b6cb3a842011-06-24 18:28:411820 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521821 &result);
1822 if (ok)
[email protected]4f5ce842011-05-27 19:34:411823 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521824 return ok;
1825}
1826
[email protected]310ebd6302011-10-10 19:06:281827bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:521828 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151829 // If we are swapping out, we have already run the beforeunload handler.
1830 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1831 // at all, to avoid running it twice.
1832 if (is_swapped_out_)
1833 return true;
1834
[email protected]3b3301f62012-02-29 04:32:321835 bool is_reload = false;
1836 WebDataSource* ds = frame->provisionalDataSource();
1837 if (ds)
1838 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
1839
[email protected]48c9cf2d2009-09-16 16:47:521840 bool success = false;
1841 // This is an ignored return value, but is included so we can accept the same
1842 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411843 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211844 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:321845 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:411846 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521847 return success;
1848}
1849
[email protected]310ebd6302011-10-10 19:06:281850void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:441851 WebFrame* frame, const WebContextMenuData& data) {
[email protected]35be7ec2012-02-12 20:42:511852 content::ContextMenuParams params(data);
[email protected]7fcd9b72011-07-27 16:52:371853
1854 // frame is NULL if invoked by BlockedPlugin.
1855 if (frame)
1856 params.frame_id = frame->identifier();
1857
[email protected]db803aae2011-03-05 02:00:421858 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271859 // it. We replace it with an empty GURL so the appropriate items are disabled
1860 // in the context menu.
1861 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1862 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421863 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271864 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101865 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291866 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441867}
1868
[email protected]310ebd6302011-10-10 19:06:281869void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521870}
1871
[email protected]310ebd6302011-10-10 19:06:281872void RenderViewImpl::UpdateTargetURL(const GURL& url,
1873 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581874 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521875 if (latest_url == target_url_)
1876 return;
[email protected]163f8242009-10-30 20:19:551877
[email protected]48c9cf2d2009-09-16 16:47:521878 // Tell the browser to display a destination link.
1879 if (target_url_status_ == TARGET_INFLIGHT ||
1880 target_url_status_ == TARGET_PENDING) {
1881 // If we have a request in-flight, save the URL to be sent when we
1882 // receive an ACK to the in-flight request. We can happily overwrite
1883 // any existing pending sends.
1884 pending_target_url_ = latest_url;
1885 target_url_status_ = TARGET_PENDING;
1886 } else {
[email protected]c85f0212011-11-04 16:54:411887 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
1888 // see |ParamTraits<GURL>|.
1889 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
1890 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:521891 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1892 target_url_ = latest_url;
1893 target_url_status_ = TARGET_INFLIGHT;
1894 }
1895}
1896
[email protected]310ebd6302011-10-10 19:06:281897void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:311898 int delay;
1899 if (send_content_state_immediately_)
1900 delay = 0;
1901 else if (is_hidden())
1902 delay = kDelaySecondsForContentStateSyncHidden;
1903 else
1904 delay = kDelaySecondsForContentStateSync;
1905
1906 if (nav_state_sync_timer_.IsRunning()) {
1907 // The timer is already running. If the delay of the timer maches the amount
1908 // we want to delay by, then return. Otherwise stop the timer so that it
1909 // gets started with the right delay.
1910 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1911 return;
1912 nav_state_sync_timer_.Stop();
1913 }
1914
[email protected]d323a172011-09-02 18:23:021915 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:281916 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311917}
1918
[email protected]310ebd6302011-10-10 19:06:281919void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551920 mouse_over_url_ = GURL(url);
1921 UpdateTargetURL(mouse_over_url_, focus_url_);
1922}
1923
[email protected]310ebd6302011-10-10 19:06:281924void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551925 focus_url_ = GURL(url);
1926 UpdateTargetURL(focus_url_, mouse_over_url_);
1927}
1928
[email protected]310ebd6302011-10-10 19:06:281929void RenderViewImpl::startDragging(const WebDragData& data,
1930 WebDragOperationsMask mask,
1931 const WebImage& image,
1932 const WebPoint& imageOffset) {
[email protected]c27ae592010-03-18 15:24:411933#if WEBKIT_USING_SKIA
1934 SkBitmap bitmap(image.getSkBitmap());
1935#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331936 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411937#endif
1938
[email protected]59f4f2fa2011-03-23 01:00:551939 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521940 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411941 mask,
1942 bitmap,
1943 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521944}
1945
[email protected]310ebd6302011-10-10 19:06:281946bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451947 return renderer_preferences_.can_accept_load_drops;
1948}
1949
[email protected]310ebd6302011-10-10 19:06:281950void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:521951 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1952}
1953
[email protected]310ebd6302011-10-10 19:06:281954void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:521955 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1956}
1957
[email protected]310ebd6302011-10-10 19:06:281958void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511959 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071960
[email protected]38b592902011-04-16 02:08:421961 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491962}
1963
[email protected]169d4282011-11-30 19:33:591964void RenderViewImpl::didUpdateLayout() {
1965 // We don't always want to set up a timer, only if we've been put in that
1966 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1967 // message.
1968 if (!send_preferred_size_changes_ || !webview())
1969 return;
1970
1971 if (check_preferred_size_timer_.IsRunning())
1972 return;
1973 check_preferred_size_timer_.Start(FROM_HERE,
1974 TimeDelta::FromMilliseconds(0), this,
1975 &RenderViewImpl::CheckPreferredSize);
1976}
1977
[email protected]310ebd6302011-10-10 19:06:281978void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521979 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1980}
1981
[email protected]310ebd6302011-10-10 19:06:281982int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001983 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521984}
1985
[email protected]310ebd6302011-10-10 19:06:281986int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001987 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521988}
1989
[email protected]310ebd6302011-10-10 19:06:281990void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:321991 const WebAccessibilityObject& obj,
1992 WebAccessibilityNotification notification) {
1993 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1994}
1995
[email protected]310ebd6302011-10-10 19:06:281996void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:141997 const WebString& value) {
1998 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1999 key.utf8(),
2000 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262001}
2002
[email protected]79dbc662009-09-04 05:42:512003// WebKit::WebWidgetClient ----------------------------------------------------
2004
[email protected]310ebd6302011-10-10 19:06:282005void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:122006 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2007 // we won't have to test for user gesture anymore and we can
2008 // move that code back to render_widget.cc
2009 if (webview() && webview()->mainFrame() &&
2010 webview()->mainFrame()->isProcessingUserGesture()) {
2011 Send(new ViewHostMsg_Focus(routing_id_));
2012 }
2013}
2014
[email protected]310ebd6302011-10-10 19:06:282015void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122016 // TODO(jcivelli): see TODO above in didFocus().
2017 if (webview() && webview()->mainFrame() &&
2018 webview()->mainFrame()->isProcessingUserGesture()) {
2019 Send(new ViewHostMsg_Blur(routing_id_));
2020 }
2021}
2022
initial.commit09911bf2008-07-26 23:55:292023// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282024// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292025// point to dispatch the ShowView message.
2026//
2027// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282028// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292029//
[email protected]310ebd6302011-10-10 19:06:282030void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292031 DCHECK(!did_show_) << "received extraneous Show call";
2032 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2033
2034 if (did_show_)
2035 return;
2036 did_show_ = true;
2037
[email protected]6779aa12011-03-29 17:32:242038 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:042039 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:042040
[email protected]28295ec2009-10-16 05:34:332041 // Force new windows to a popup if they were not opened with a user gesture.
2042 if (!opened_by_user_gesture_) {
2043 // We exempt background tabs for compat with older versions of Chrome.
2044 // TODO(darin): This seems bogus. These should have a user gesture, so
2045 // we probably don't need this check.
2046 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2047 policy = WebKit::WebNavigationPolicyNewPopup;
2048 }
2049
initial.commit09911bf2008-07-26 23:55:292050 // NOTE: initial_pos_ may still have its default values at this point, but
2051 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2052 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282053 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2054 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292055 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242056 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292057}
2058
[email protected]310ebd6302011-10-10 19:06:282059void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292060 DCHECK(did_show_) << "should already have shown the view";
2061
[email protected]c1f50aa2010-02-18 03:46:572062 // We must keep WebKit's shared timer running in this case in order to allow
2063 // showModalDialog to function properly.
2064 //
2065 // TODO(darin): WebKit should really be smarter about suppressing events and
2066 // timers so that we do not need to manage the shared timer in such a heavy
2067 // handed manner.
2068 //
[email protected]f1a29a02011-10-06 23:08:442069 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2070 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572071
[email protected]12636df2009-09-28 22:32:212072 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292073}
2074
[email protected]2b624c562011-10-27 22:58:262075bool RenderViewImpl::enterFullScreen() {
2076 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2077 return true;
2078}
2079
2080void RenderViewImpl::exitFullScreen() {
2081 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2082}
2083
[email protected]217690d2012-01-27 07:33:112084bool RenderViewImpl::requestPointerLock() {
2085 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2086}
2087
2088void RenderViewImpl::requestPointerUnlock() {
2089 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2090}
2091
2092bool RenderViewImpl::isPointerLocked() {
2093 return mouse_lock_dispatcher_->IsMouseLockedTo(
2094 webwidget_mouse_lock_target_.get());
2095}
2096
[email protected]7a1ec28a2012-03-28 21:10:242097void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
2098 CompositorThread* compositor_thread =
2099 RenderThreadImpl::current()->compositor_thread();
2100 if (compositor_thread)
2101 compositor_thread->AddInputHandler(
2102 routing_id_, input_handler_identifier, AsWeakPtr());
2103
2104 RenderWidget::didActivateCompositor(input_handler_identifier);
2105}
2106
[email protected]3d9689372009-09-10 04:29:172107// WebKit::WebFrameClient -----------------------------------------------------
2108
[email protected]310ebd6302011-10-10 19:06:282109WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2110 const WebPluginParams& params) {
[email protected]0361b942012-03-14 06:42:532111 // The browser plugin is a special kind of pepper plugin
2112 // that loads asynchronously. We first create a placeholder here.
2113 // When a guest is ready to be displayed, we swap out the placeholder
2114 // with the guest.
2115 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2116 if (command_line.HasSwitch(switches::kEnableBrowserPlugin) &&
2117 UTF16ToASCII(params.mimeType) == kBrowserPluginMimeType)
2118 return BrowserPluginPlaceholder::Create(this, frame, params);
2119
[email protected]eaacd1f2011-09-23 02:32:552120 WebPlugin* plugin = NULL;
2121 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
2122 this, frame, params, &plugin)) {
2123 return plugin;
2124 }
2125
[email protected]a813c8e2011-10-08 01:34:112126 webkit::WebPluginInfo info;
2127 std::string mime_type;
2128 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2129 params.mimeType.utf8(), &info, &mime_type);
2130 if (!found)
2131 return NULL;
2132
2133 WebPluginParams params_to_use = params;
2134 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312135 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172136}
2137
[email protected]6ac77cb2012-05-01 14:49:012138WebPlugin* RenderViewImpl::createPluginReplacement(
2139 WebFrame* frame,
2140 const WebPluginParams& params) {
2141 webkit::WebPluginInfo info;
2142 std::string mime_type;
2143 GetPluginInfo(params.url, frame->top()->document().url(),
2144 params.mimeType.utf8(), &info, &mime_type);
2145 return content::GetContentClient()->renderer()->CreatePluginReplacement(
2146 this, info.path);
2147}
2148
[email protected]310ebd6302011-10-10 19:06:282149WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422150 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372151 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422152
[email protected]30447b62009-11-13 01:13:372153 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512154 bool exists = false;
[email protected]30447b62009-11-13 01:13:372155 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512156 ViewHostMsg_CreateWorker_Params params;
2157 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512158 params.name = name;
2159 params.document_id = document_id;
2160 params.render_view_route_id = routing_id_;
2161 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232162 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372163 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512164 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372165 if (url_mismatch) {
2166 return NULL;
2167 } else {
[email protected]f1a29a02011-10-06 23:08:442168 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492169 document_id,
[email protected]6de0bcf2010-02-17 22:00:512170 exists,
[email protected]30447b62009-11-13 01:13:372171 route_id,
2172 routing_id_);
2173 }
[email protected]9c00f002009-11-05 22:37:422174}
2175
[email protected]310ebd6302011-10-10 19:06:282176WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]3d9689372009-09-10 04:29:172177 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442178 FOR_EACH_OBSERVER(
2179 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172180
[email protected]25fb9b32012-04-27 03:21:552181#if defined(OS_ANDROID)
2182 return new webkit_media::WebMediaPlayerAndroid(
2183 client, cookieJar(frame));
2184#endif
2185
[email protected]bb6fd402011-12-09 02:45:442186 media::MessageLoopFactory* message_loop_factory =
[email protected]b80322902012-03-06 01:33:502187 new media::MessageLoopFactory();
[email protected]bb6fd402011-12-09 02:45:442188 media::FilterCollection* collection = new media::FilterCollection();
2189 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372190
[email protected]9e2269d2012-01-07 00:06:212191 RenderAudioSourceProvider* audio_source_provider = NULL;
2192
[email protected]3d9689372009-09-10 04:29:172193 // Add in any custom filter factories first.
2194 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2195 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212196 // audio_source_provider is a "provider" to WebKit, and a sink
2197 // from the perspective of the audio renderer.
2198 audio_source_provider = new RenderAudioSourceProvider();
2199
2200 // Add the chrome specific audio renderer, using audio_source_provider
2201 // as the sink.
[email protected]37136d162012-04-09 23:39:192202 media::AudioRendererImpl* audio_renderer =
2203 new media::AudioRendererImpl(audio_source_provider);
[email protected]9e2269d2012-01-07 00:06:212204 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172205 }
2206
[email protected]e1d69d762011-12-13 05:12:182207 // Currently only cros/arm has any HW video decode support in
2208 // GpuVideoDecodeAccelerator so we don't even try to use it on other
2209 // platforms. This is a startup-time optimization. When new VDA
2210 // implementations are added, relax the #if above.
[email protected]d0fb8a72012-03-10 18:54:522211#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
2212 // Note we don't actually use the result of this blind down-cast unless it's
2213 // valid (not NULL and of the right type).
[email protected]43567302012-02-16 23:21:392214 WebGraphicsContext3DCommandBufferImpl* context3d =
2215 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2216 webview()->graphicsContext3D());
[email protected]d0fb8a72012-03-10 18:54:522217 if (context_is_web_graphics_context_3d_command_buffer_impl_ && context3d) {
[email protected]84a83e192012-03-09 18:43:402218 MessageLoop* factories_loop =
2219 RenderThreadImpl::current()->compositor_thread() ?
2220 RenderThreadImpl::current()->compositor_thread()->GetWebThread()
2221 ->message_loop() :
2222 MessageLoop::current();
[email protected]e1d69d762011-12-13 05:12:182223 GpuChannelHost* gpu_channel_host =
2224 RenderThreadImpl::current()->EstablishGpuChannelSync(
2225 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
2226 collection->AddVideoDecoder(new media::GpuVideoDecoder(
[email protected]8d4359282012-01-14 00:53:312227 message_loop_factory->GetMessageLoop("GpuVideoDecoder"),
[email protected]84a83e192012-03-09 18:43:402228 factories_loop,
[email protected]8d4359282012-01-14 00:53:312229 new RendererGpuVideoDecoderFactories(
[email protected]84a83e192012-03-09 18:43:402230 gpu_channel_host, factories_loop, context3d)));
[email protected]e1d69d762011-12-13 05:12:182231 }
2232#endif
2233
[email protected]da952fd2012-01-13 03:49:252234 webkit_media::WebMediaPlayerImpl* media_player =
2235 content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
2236 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1bc65a42012-04-23 09:31:252237 message_loop_factory, media_stream_impl_, render_media_log);
[email protected]da952fd2012-01-13 03:49:252238 if (!media_player) {
[email protected]cec4eb82012-01-12 17:51:562239 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252240 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]1bc65a42012-04-23 09:31:252241 message_loop_factory, media_stream_impl_, render_media_log);
[email protected]bb6fd402011-12-09 02:45:442242 }
[email protected]cec4eb82012-01-12 17:51:562243 return media_player;
[email protected]3d9689372009-09-10 04:29:172244}
2245
[email protected]310ebd6302011-10-10 19:06:282246WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212247 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232248 if (!frame || !frame->view())
2249 return NULL;
[email protected]035545f2010-04-09 13:10:212250 return new RendererWebApplicationCacheHostImpl(
2251 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442252 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212253}
2254
[email protected]310ebd6302011-10-10 19:06:282255WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382256 return &cookie_jar_;
2257}
2258
[email protected]310ebd6302011-10-10 19:06:282259void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512260 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452261}
2262
[email protected]310ebd6302011-10-10 19:06:282263void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512264 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172265}
2266
[email protected]310ebd6302011-10-10 19:06:282267void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172268 WebFrame* frame, const WebURLRequest& request,
2269 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342270 loadURLExternally(frame, request, policy, WebString());
2271}
2272
[email protected]310ebd6302011-10-10 19:06:282273void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342274 WebFrame* frame, const WebURLRequest& request,
2275 WebNavigationPolicy policy,
2276 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:592277 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2278 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342279 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2280 suggested_name));
[email protected]efce17b2009-09-11 18:04:592281 } else {
[email protected]445e1042011-12-03 21:03:152282 OpenURL(frame, request.url(),
[email protected]b9fd01ba2012-02-28 01:50:402283 Referrer(referrer, GetReferrerPolicyFromRequest(request)), policy);
[email protected]efce17b2009-09-11 18:04:592284 }
[email protected]3d9689372009-09-10 04:29:172285}
2286
[email protected]310ebd6302011-10-10 19:06:282287WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172288 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222289 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]0639c063a2012-03-22 20:55:332290 Referrer referrer(
2291 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2292 GetReferrerPolicyFromRequest(request));
2293
[email protected]992db4c2011-05-12 15:37:152294 if (is_swapped_out_) {
[email protected]285f4bb82012-04-17 15:57:282295 if (request.url() != GURL(content::kSwappedOutURL)) {
[email protected]0639c063a2012-03-22 20:55:332296 // Targeted links may try to navigate a swapped out frame. Allow the
2297 // browser process to navigate the tab instead. Note that it is also
2298 // possible for non-targeted navigations (from this view) to arrive
2299 // here just after we are swapped out. It's ok to send them to the
2300 // browser, as long as they're for the top level frame.
2301 // TODO(creis): Ensure this supports targeted form submissions when
2302 // fixing http://crbug.com/101395.
2303 if (frame->parent() == NULL) {
2304 OpenURL(frame, request.url(), referrer, default_policy);
2305 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2306 }
2307
2308 // We should otherwise ignore in-process iframe navigations, if they
2309 // arrive just after we are swapped out.
[email protected]73eb2602012-02-09 19:50:552310 return WebKit::WebNavigationPolicyIgnore;
[email protected]0639c063a2012-03-22 20:55:332311 }
[email protected]73eb2602012-02-09 19:50:552312
[email protected]285f4bb82012-04-17 15:57:282313 // Allow content::kSwappedOutURL to complete.
[email protected]992db4c2011-05-12 15:37:152314 return default_policy;
2315 }
2316
[email protected]3d9689372009-09-10 04:29:172317 // Webkit is asking whether to navigate to a new URL.
2318 // This is fine normally, except if we're showing UI from one security
2319 // context and they're trying to navigate to a different context.
2320 const GURL& url = request.url();
2321
[email protected]d19ea342011-04-20 20:31:132322 // A content initiated navigation may have originated from a link-click,
2323 // script, drag-n-drop operation, etc.
2324 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072325 DocumentState::FromDataSource(frame->provisionalDataSource())->
2326 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132327
[email protected]a8c269a2011-10-25 20:17:222328 // Experimental:
2329 // If --enable-strict-site-isolation is enabled, send all top-level
2330 // navigations to the browser to let it swap processes when crossing site
2331 // boundaries. This is currently expected to break some script calls and
2332 // navigations, such as form submissions.
2333 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102334 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2335 !frame->parent() && (is_content_initiated || is_redirect)) {
2336 WebString origin_str = frame->document().securityOrigin().toString();
2337 GURL frame_url(origin_str.utf8().data());
2338 // TODO(cevans): revisit whether this origin check is still necessary once
2339 // crbug.com/101395 is fixed.
2340 if (frame_url.GetOrigin() != url.GetOrigin()) {
[email protected]313b80bd2011-11-23 03:49:102341 OpenURL(frame, url, referrer, default_policy);
2342 return WebKit::WebNavigationPolicyIgnore;
2343 }
[email protected]a8c269a2011-10-25 20:17:222344 }
2345
[email protected]3d9689372009-09-10 04:29:172346 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302347 // navigations.
[email protected]5f000f272012-01-19 05:25:082348 if (is_content_initiated) {
2349 bool browser_handles_top_level_requests =
2350 renderer_preferences_.browser_handles_top_level_requests &&
2351 IsNonLocalTopLevelNavigation(url, frame, type);
2352 if (browser_handles_top_level_requests ||
2353 renderer_preferences_.browser_handles_all_requests) {
[email protected]5f000f272012-01-19 05:25:082354 // Reset these counters as the RenderView could be reused for the next
2355 // navigation.
2356 page_id_ = -1;
2357 last_page_id_sent_to_browser_ = -1;
2358 OpenURL(frame, url, referrer, default_policy);
2359 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2360 }
[email protected]3d9689372009-09-10 04:29:172361 }
2362
[email protected]6101c342010-12-16 22:44:372363 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552364 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]744c2a22012-03-15 18:42:042365 // top-level navigations (not iframes). But we sometimes navigate to
2366 // about:blank to clear a tab, and we want to still allow that.
[email protected]6101c342010-12-16 22:44:372367 //
[email protected]744c2a22012-03-15 18:42:042368 // Note: this is known to break POST submissions when crossing process
2369 // boundaries until http://crbug.com/101395 is fixed. This is better for
2370 // security than loading a WebUI, extension or app page in the wrong process.
2371 // POST requests don't work because this mechanism does not preserve form
2372 // POST data. We will need to send the request's httpBody data up to the
2373 // browser process, and issue a special POST navigation in WebKit (via
[email protected]8f4da8c2011-02-09 19:49:572374 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2375 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222376 if (!frame->parent() && is_content_initiated &&
[email protected]744c2a22012-03-15 18:42:042377 !url.SchemeIs(chrome::kAboutScheme)) {
[email protected]6101c342010-12-16 22:44:372378 bool send_referrer = false;
[email protected]744c2a22012-03-15 18:42:042379
2380 // All navigations to WebUI URLs or within WebUI-enabled RenderProcesses
2381 // must be handled by the browser process so that the correct bindings and
2382 // data sources can be registered.
2383 // Similarly, navigations to view-source URLs or within ViewSource mode
2384 // must be handled by the browser process.
2385 int cumulative_bindings =
2386 RenderProcess::current()->GetEnabledBindings();
[email protected]6101c342010-12-16 22:44:372387 bool should_fork =
[email protected]744c2a22012-03-15 18:42:042388 content::GetContentClient()->HasWebUIScheme(url) ||
2389 (cumulative_bindings & content::BINDINGS_POLICY_WEB_UI) ||
2390 url.SchemeIs(chrome::kViewSourceScheme) ||
2391 frame->isViewSourceModeEnabled();
[email protected]5351dbc2010-08-27 15:22:112392
[email protected]e48869a2011-04-01 19:56:032393 if (!should_fork) {
2394 // Give the embedder a chance.
[email protected]744c2a22012-03-15 18:42:042395 // For now, we skip this for POST submissions. This is because
2396 // http://crbug.com/101395 is more likely to cause compatibility issues
2397 // with hosted apps and extensions than WebUI pages. We will remove this
2398 // check when cross-process POST submissions are supported.
2399 if (request.httpMethod() == "GET") {
2400 bool is_initial_navigation = page_id_ == -1;
2401 should_fork = content::GetContentClient()->renderer()->ShouldFork(
2402 frame, url, is_initial_navigation, &send_referrer);
2403 }
[email protected]6101c342010-12-16 22:44:372404 }
2405
2406 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152407 OpenURL(
2408 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112409 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2410 }
[email protected]3d9689372009-09-10 04:29:172411 }
2412
[email protected]43763f982011-08-26 18:33:402413 // Use the frame's original request's URL rather than the document's URL for
2414 // this check. For a popup, the document's URL may become the opener window's
2415 // URL if the opener has called document.write. See http://crbug.com/93517.
2416 GURL old_url(frame->dataSource()->request().url());
2417
[email protected]3d9689372009-09-10 04:29:172418 // Detect when a page is "forking" a new tab that can be safely rendered in
2419 // its own process. This is done by sites like Gmail that try to open links
2420 // in new windows without script connections back to the original page. We
2421 // treat such cases as browser navigations (in which we will create a new
2422 // renderer for a cross-site navigation), rather than WebKit navigations.
2423 //
2424 // We use the following heuristic to decide whether to fork a new page in its
2425 // own process:
2426 // The parent page must open a new tab to about:blank, set the new tab's
2427 // window.opener to null, and then redirect the tab to a cross-site URL using
2428 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462429 //
2430 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2431 // (see below).
[email protected]3d9689372009-09-10 04:29:172432 bool is_fork =
2433 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582434 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172435 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522436 historyBackListCount() < 1 &&
2437 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172438 // The parent page must have set the child's window.opener to null before
2439 // redirecting to the desired URL.
2440 frame->opener() == NULL &&
2441 // Must be a top-level frame.
2442 frame->parent() == NULL &&
2443 // Must not have issued the request from this page.
2444 is_content_initiated &&
2445 // Must be targeted at the current tab.
2446 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2447 // Must be a JavaScript navigation, which appears as "other".
2448 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462449
[email protected]f92ce2b2012-03-06 18:02:592450 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:172451 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152452 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172453 return WebKit::WebNavigationPolicyIgnore;
2454 }
2455
2456 return default_policy;
2457}
2458
[email protected]310ebd6302011-10-10 19:06:282459bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492460 WebFrame* frame, const WebURLRequest& request) {
2461 // We allow WebKit to think that everything can be handled even though
2462 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342463 return true;
2464}
2465
[email protected]310ebd6302011-10-10 19:06:282466WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492467 WebFrame* frame, const WebURLRequest& request) {
2468 NOTREACHED(); // Since we said we can handle all requests.
2469 return WebURLError();
2470}
2471
[email protected]310ebd6302011-10-10 19:06:282472WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492473 WebFrame* frame, const WebURLRequest& request) {
2474 WebURLError error;
2475 error.domain = WebString::fromUTF8(net::kErrorDomain);
2476 error.reason = net::ERR_ABORTED;
2477 error.unreachableURL = request.url();
2478 return error;
[email protected]7b7a7dc2009-10-19 02:23:342479}
2480
[email protected]310ebd6302011-10-10 19:06:282481void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492482 WebFrame*, const WebURLError&) {
2483 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342484}
2485
[email protected]310ebd6302011-10-10 19:06:282486void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432487 const WebKit::WebFormElement& form) {
2488 // Some login forms have onSubmit handlers that put a hash of the password
2489 // into a hidden field and then clear the password. (Issue 28910.)
2490 // This method gets called before any of those handlers run, so save away
2491 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072492 DocumentState* document_state =
2493 DocumentState::FromDataSource(frame->dataSource());
2494 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432495 PasswordFormDomManager::CreatePasswordForm(form));
2496}
2497
[email protected]310ebd6302011-10-10 19:06:282498void RenderViewImpl::willSubmitForm(WebFrame* frame,
2499 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072500 DocumentState* document_state =
2501 DocumentState::FromDataSource(frame->provisionalDataSource());
2502 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172503
[email protected]2905f742011-10-13 03:51:582504 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2505 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172506
2507 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352508 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072509 document_state->set_searchable_form_url(web_searchable_form_data.url());
2510 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212511 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432512 PasswordForm* password_form_data =
2513 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]007733c2011-11-17 00:34:072514 document_state->set_password_form_data(password_form_data);
[email protected]90eeddb2010-05-06 21:06:432515
[email protected]098c95cb2011-04-28 16:49:012516 // In order to save the password that the user actually typed and not one
2517 // that may have gotten transformed by the site prior to submit, recover it
2518 // from the form contents already stored by |willSendSubmitEvent| into the
2519 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2520 // which is what we're storing into now.)
2521 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:072522 DocumentState* old_document_state =
2523 DocumentState::FromDataSource(frame->dataSource());
2524 if (old_document_state) {
2525 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432526 if (old_form_data && old_form_data->action == password_form_data->action)
2527 password_form_data->password_value = old_form_data->password_value;
2528 }
2529 }
[email protected]3d9689372009-09-10 04:29:172530
[email protected]2a5b1732011-04-01 23:55:552531 FOR_EACH_OBSERVER(
2532 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172533}
2534
[email protected]310ebd6302011-10-10 19:06:282535void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172536 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2537 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382538 FOR_EACH_OBSERVER(
2539 RenderViewObserver, observers_,
2540 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172541}
2542
[email protected]310ebd6302011-10-10 19:06:282543void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382544 FOR_EACH_OBSERVER(
2545 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172546}
2547
[email protected]310ebd6302011-10-10 19:06:282548void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172549 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152550 if (!frame->parent()) {
2551 WebDataSource* ds = frame->provisionalDataSource();
2552 // If there's no provisional data source, it's a reference fragment
2553 // navigation.
2554 completed_client_redirect_src_ = Referrer(
[email protected]b9fd01ba2012-02-28 01:50:402555 from, ds ? GetReferrerPolicyFromRequest(ds->request()) :
[email protected]445e1042011-12-03 21:03:152556 frame->referrerPolicy());
2557 }
[email protected]eb0bff942011-04-07 22:08:382558 FOR_EACH_OBSERVER(
2559 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172560}
2561
[email protected]310ebd6302011-10-10 19:06:282562void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]45d83a12012-04-06 22:57:572563 bool content_initiated = !pending_navigation_params_.get();
2564
[email protected]007733c2011-11-17 00:34:072565 DocumentState* document_state = DocumentState::FromDataSource(ds);
2566 if (!document_state) {
2567 document_state = new DocumentState;
2568 ds->setExtraData(document_state);
[email protected]45d83a12012-04-06 22:57:572569 if (!content_initiated)
2570 PopulateDocumentStateFromPending(document_state);
[email protected]007733c2011-11-17 00:34:072571 }
2572
[email protected]3d9689372009-09-10 04:29:172573 // The rest of RenderView assumes that a WebDataSource will always have a
2574 // non-null NavigationState.
[email protected]007733c2011-11-17 00:34:072575 if (content_initiated)
2576 document_state->set_navigation_state(
2577 NavigationState::CreateContentInitiated());
[email protected]45d83a12012-04-06 22:57:572578 else {
2579 document_state->set_navigation_state(CreateNavigationStateFromPending());
2580 pending_navigation_params_.reset();
2581 }
[email protected]8a3125a712010-08-09 18:58:512582
[email protected]007733c2011-11-17 00:34:072583 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512584 // navigating from a page that used prefetching using a link on that
2585 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072586 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512587 // this value appropriately.
2588 // TODO(gavinp): catch the important case of navigation in a new
2589 // renderer process.
2590 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302591 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522592 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512593 const GURL referrer(
2594 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2595 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072596 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512597 old_frame->dataSource())->was_prefetcher()) {
[email protected]82114f52012-03-20 22:53:412598 for (; old_frame; old_frame = old_frame->traverseNext(false)) {
[email protected]8a3125a712010-08-09 18:58:512599 WebDataSource* old_frame_ds = old_frame->dataSource();
2600 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072601 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512602 break;
2603 }
2604 }
2605 }
2606 }
2607 }
2608
[email protected]4c1b6f0b2010-02-07 16:38:182609 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522610 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512611 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182612 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072613 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182614 break;
2615 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072616 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182617 break;
2618 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072619 document_state->set_load_type(
2620 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182621 break;
2622 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072623 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182624 break;
2625 }
2626 }
[email protected]fa7b6b542009-11-03 05:02:302627
[email protected]946a0032011-03-31 18:42:282628 FOR_EACH_OBSERVER(
2629 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172630}
2631
[email protected]45d83a12012-04-06 22:57:572632void RenderViewImpl::PopulateDocumentStateFromPending(
[email protected]007733c2011-11-17 00:34:072633 DocumentState* document_state) {
2634 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
[email protected]45d83a12012-04-06 22:57:572635 document_state->set_request_time(params.request_time);
[email protected]007733c2011-11-17 00:34:072636
[email protected]45d83a12012-04-06 22:57:572637 if (!params.url.SchemeIs(chrome::kJavaScriptScheme) &&
2638 params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
2639 // We're doing a load of a page that was restored from the last session. By
2640 // default this prefers the cache over loading (LOAD_PREFERRING_CACHE) which
2641 // can result in stale data for pages that are set to expire. We explicitly
2642 // override that by setting the policy here so that as necessary we load
2643 // from the network.
2644 document_state->set_cache_policy_override(
2645 WebURLRequest::UseProtocolCachePolicy);
[email protected]007733c2011-11-17 00:34:072646 }
2647
2648 if (IsReload(params))
2649 document_state->set_load_type(DocumentState::RELOAD);
2650 else if (!params.state.empty())
2651 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2652 else
2653 document_state->set_load_type(DocumentState::NORMAL_LOAD);
[email protected]45d83a12012-04-06 22:57:572654}
[email protected]007733c2011-11-17 00:34:072655
[email protected]45d83a12012-04-06 22:57:572656NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
2657 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
2658 NavigationState* navigation_state = NULL;
2659
2660 // A navigation resulting from loading a javascript URL should not be treated
2661 // as a browser initiated event. Instead, we want it to look as if the page
2662 // initiated any load resulting from JS execution.
2663 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
2664 navigation_state = NavigationState::CreateBrowserInitiated(
2665 params.page_id,
2666 params.pending_history_list_offset,
2667 params.transition);
2668 navigation_state->set_transferred_request_child_id(
2669 params.transferred_request_child_id);
2670 navigation_state->set_transferred_request_request_id(
2671 params.transferred_request_request_id);
2672 } else {
2673 navigation_state = NavigationState::CreateContentInitiated();
2674 }
2675 return navigation_state;
[email protected]007733c2011-11-17 00:34:072676}
2677
[email protected]5b52cd2f712012-03-28 02:12:482678void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
2679 bool enable_viewport =
2680 command_line.HasSwitch(switches::kEnableViewport);
2681 bool enable_fixed_layout =
2682 command_line.HasSwitch(switches::kEnableFixedLayout);
2683
2684 webview()->enableFixedLayoutMode(enable_fixed_layout || enable_viewport);
2685 webview()->settings()->setFixedElementsLayoutRelativeToFrame(true);
2686
2687 if (enable_viewport) {
2688 webview()->settings()->setViewportEnabled(true);
2689 } else if (enable_fixed_layout) {
2690 std::string str =
2691 command_line.GetSwitchValueASCII(switches::kEnableFixedLayout);
2692 std::vector<std::string> tokens;
2693 base::SplitString(str, ',', &tokens);
2694 if (tokens.size() == 2) {
2695 int width, height;
2696 if (base::StringToInt(tokens[0], &width) &&
2697 base::StringToInt(tokens[1], &height))
2698 webview()->setFixedLayoutSize(WebSize(width,height));
2699 }
2700 }
2701}
2702
[email protected]310ebd6302011-10-10 19:06:282703void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172704 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:072705 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:172706
[email protected]3d9689372009-09-10 04:29:172707 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:072708 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:172709 double event_time = ds->triggeringEventTime();
2710 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:072711 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:172712 }
2713
[email protected]05c8e502010-08-15 15:13:522714 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:072715 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:522716
[email protected]3d9689372009-09-10 04:29:172717 bool is_top_most = !frame->parent();
2718 if (is_top_most) {
2719 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132720 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172721
2722 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:152723 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172724 } else if (frame->parent()->isLoading()) {
2725 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002726 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:072727 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:582728 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172729 }
2730
[email protected]28685da92011-02-07 21:49:172731 FOR_EACH_OBSERVER(
2732 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2733
[email protected]3d9689372009-09-10 04:29:172734 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592735 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262736 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172737}
2738
[email protected]310ebd6302011-10-10 19:06:282739void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2740 WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172741 if (frame->parent())
2742 return;
2743 // Received a redirect on the main frame.
2744 WebDataSource* data_source = frame->provisionalDataSource();
2745 if (!data_source) {
2746 // Should only be invoked when we have a data source.
2747 NOTREACHED();
2748 return;
2749 }
2750 std::vector<GURL> redirects;
2751 GetRedirectChain(data_source, &redirects);
2752 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512753 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592754 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172755 }
2756}
2757
[email protected]310ebd6302011-10-10 19:06:282758void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2759 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172760 // Notify the browser that we failed a provisional load with an error.
2761 //
2762 // Note: It is important this notification occur before DidStopLoading so the
2763 // SSL manager can react to the provisional load failure before being
2764 // notified the load stopped.
2765 //
2766 WebDataSource* ds = frame->provisionalDataSource();
2767 DCHECK(ds);
2768
2769 const WebURLRequest& failed_request = ds->request();
2770
[email protected]28685da92011-02-07 21:49:172771 FOR_EACH_OBSERVER(
2772 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2773
[email protected]3d9689372009-09-10 04:29:172774 bool show_repost_interstitial =
2775 (error.reason == net::ERR_CACHE_MISS &&
2776 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582777
2778 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2779 params.frame_id = frame->identifier();
2780 params.is_main_frame = !frame->parent();
2781 params.error_code = error.reason;
2782 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2783 failed_request,
2784 error,
2785 NULL,
2786 &params.error_description);
2787 params.url = error.unreachableURL;
2788 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172789 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582790 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172791
2792 // Don't display an error page if this is simply a cancelled load. Aside
2793 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2794 if (error.reason == net::ERR_ABORTED)
2795 return;
[email protected]b553edd52012-01-10 12:15:232796 // Don't display an error message if the request was handled by an
2797 // external protocol handler.
2798 if (error.reason == net::ERR_UNKNOWN_URL_SCHEME)
2799 return;
[email protected]3d9689372009-09-10 04:29:172800
2801 // Make sure we never show errors in view source mode.
2802 frame->enableViewSourceMode(false);
2803
[email protected]007733c2011-11-17 00:34:072804 DocumentState* document_state = DocumentState::FromDataSource(ds);
2805 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172806
2807 // If this is a failed back/forward/reload navigation, then we need to do a
2808 // 'replace' load. This is necessary to avoid messing up session history.
2809 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2810 // as session history is concerned.
2811 //
2812 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2813 // the page id.
2814 //
2815 bool replace =
2816 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:582817 navigation_state->transition_type() ==
2818 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:172819
2820 // If we failed on a browser initiated request, then make sure that our error
2821 // page load is regarded as the same browser initiated request.
2822 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:072823 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
2824 pending_navigation_params_->page_id =
2825 navigation_state->pending_page_id();
2826 pending_navigation_params_->pending_history_list_offset =
2827 navigation_state->pending_history_list_offset();
2828 pending_navigation_params_->transition =
2829 navigation_state->transition_type();
2830 pending_navigation_params_->request_time =
2831 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:172832 }
2833
2834 // Provide the user with a more helpful error page?
2835 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2836 return;
2837
2838 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082839 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172840}
2841
[email protected]310ebd6302011-10-10 19:06:282842void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:172843 WebFrame* frame, const char* data, size_t data_len,
2844 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:072845 DocumentState* document_state =
2846 DocumentState::FromDataSource(frame->dataSource());
2847 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172848}
2849
[email protected]310ebd6302011-10-10 19:06:282850void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2851 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:072852 DocumentState* document_state =
2853 DocumentState::FromDataSource(frame->dataSource());
2854 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172855
[email protected]007733c2011-11-17 00:34:072856 if (document_state->commit_load_time().is_null())
2857 document_state->set_commit_load_time(Time::Now());
2858
[email protected]3d9689372009-09-10 04:29:172859 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202860 // When we perform a new navigation, we need to update the last committed
2861 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172862 UpdateSessionHistory(frame);
2863
2864 // We bump our Page ID to correspond with the new session history entry.
2865 page_id_ = next_page_id_++;
2866
[email protected]285f4bb82012-04-17 15:57:282867 // Don't update history_page_ids_ (etc) for content::kSwappedOutURL, since
[email protected]58436a12012-03-21 17:10:262868 // we don't want to forget the entry that was there, and since we will
[email protected]285f4bb82012-04-17 15:57:282869 // never come back to content::kSwappedOutURL. Note that we have to call
[email protected]69ddf852012-02-21 23:21:312870 // UpdateSessionHistory and update page_id_ even in this case, so that
2871 // the current entry gets a state update and so that we don't send a
2872 // state update to the wrong entry when we swap back in.
[email protected]285f4bb82012-04-17 15:57:282873 if (GetLoadingUrl(frame) != GURL(content::kSwappedOutURL)) {
[email protected]69ddf852012-02-21 23:21:312874 // Advance our offset in session history, applying the length limit.
2875 // There is now no forward history.
2876 history_list_offset_++;
2877 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2878 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
2879 history_list_length_ = history_list_offset_ + 1;
2880 history_page_ids_.resize(history_list_length_, -1);
2881 history_page_ids_[history_list_offset_] = page_id_;
2882 }
[email protected]3d9689372009-09-10 04:29:172883 } else {
2884 // Inspect the navigation_state on this frame to see if the navigation
2885 // corresponds to a session history navigation... Note: |frame| may or
2886 // may not be the toplevel frame, but for the case of capturing session
2887 // history, the first committed frame suffices. We keep track of whether
2888 // we've seen this commit before so that only capture session history once
2889 // per navigation.
2890 //
2891 // Note that we need to check if the page ID changed. In the case of a
2892 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2893 // previous URL and the current page ID, which would be wrong.
2894 if (navigation_state->pending_page_id() != -1 &&
2895 navigation_state->pending_page_id() != page_id_ &&
2896 !navigation_state->request_committed()) {
2897 // This is a successful session history navigation!
2898 UpdateSessionHistory(frame);
2899 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002900
2901 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032902
2903 // If the history list is valid, our list of page IDs should be correct.
2904 DCHECK(history_list_length_ <= 0 ||
2905 history_list_offset_ < 0 ||
2906 history_list_offset_ >= history_list_length_ ||
2907 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172908 }
2909 }
2910
[email protected]28685da92011-02-07 21:49:172911 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2912 DidCommitProvisionalLoad(frame, is_new_navigation));
2913
[email protected]3d9689372009-09-10 04:29:172914 // Remember that we've already processed this request, so we don't update
2915 // the session history again. We do this regardless of whether this is
2916 // a session history navigation, because if we attempted a session history
2917 // navigation without valid HistoryItem state, WebCore will think it is a
2918 // new navigation.
2919 navigation_state->set_request_committed(true);
2920
2921 UpdateURL(frame);
2922
2923 // If this committed load was initiated by a client redirect, we're
2924 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:152925 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172926
2927 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272928 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172929}
2930
[email protected]310ebd6302011-10-10 19:06:282931void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102932 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2933 DidClearWindowObject(frame));
2934
[email protected]b6cb3a842011-06-24 18:28:412935 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:212936 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:252937 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2938 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272939 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172940 }
[email protected]766a7082012-02-03 23:39:152941
2942 if (enabled_bindings_ & content::BINDINGS_POLICY_DOM_AUTOMATION) {
2943 if (!dom_automation_controller_.get())
2944 dom_automation_controller_.reset(new DomAutomationController());
2945 dom_automation_controller_->set_message_sender(
2946 static_cast<content::RenderView*>(this));
2947 dom_automation_controller_->set_routing_id(routing_id());
2948 dom_automation_controller_->BindToJavascript(frame,
2949 "domAutomationController");
2950 }
[email protected]3d9689372009-09-10 04:29:172951}
2952
[email protected]310ebd6302011-10-10 19:06:282953void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172954 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412955 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252956 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]87717d0e2012-04-26 02:58:432957 if (frame == webview()->mainFrame())
2958 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:172959 }
[email protected]e48869a2011-04-01 19:56:032960
2961 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2962 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172963}
2964
[email protected]310ebd6302011-10-10 19:06:282965void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
2966 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462967 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172968
2969 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272970 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172971}
2972
[email protected]310ebd6302011-10-10 19:06:282973void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:132974 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2975 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582976}
2977
[email protected]310ebd6302011-10-10 19:06:282978void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172979 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072980 DocumentState* document_state = DocumentState::FromDataSource(ds);
2981 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:172982
[email protected]622474d2010-11-04 09:21:082983 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172984
[email protected]28685da92011-02-07 21:49:172985 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2986 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172987
2988 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272989 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172990}
2991
[email protected]310ebd6302011-10-10 19:06:282992void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082993 if (webview()->mainFrame() == frame) {
2994 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2995 page_id_));
2996 }
[email protected]3d9689372009-09-10 04:29:172997}
2998
[email protected]310ebd6302011-10-10 19:06:282999void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:313000 WebDataSource* ds = frame->dataSource();
3001 DCHECK(ds);
3002
3003
[email protected]28685da92011-02-07 21:49:173004 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:313005
3006 const WebURLRequest& failed_request = ds->request();
3007 string16 error_description;
3008 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
3009 failed_request,
3010 error,
3011 NULL,
3012 &error_description);
3013 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
3014 frame->identifier(),
3015 failed_request.url(),
3016 !frame->parent(),
3017 error.reason,
3018 error_description));
[email protected]3d9689372009-09-10 04:29:173019}
3020
[email protected]310ebd6302011-10-10 19:06:283021void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173022 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:073023 DocumentState* document_state = DocumentState::FromDataSource(ds);
3024 if (document_state->finish_load_time().is_null())
3025 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:413026
[email protected]676126f72011-01-15 00:03:513027 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173028
[email protected]1a55c5be2011-11-29 11:36:313029 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
3030 frame->identifier(),
3031 ds->request().url(),
3032 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:173033}
3034
[email protected]310ebd6302011-10-10 19:06:283035void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173036 WebFrame* frame, bool is_new_navigation) {
3037 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:073038 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:173039 // update the ExtraData on the datasource so that others who read the
3040 // ExtraData will get the new NavigationState. Similarly, if we did not
3041 // initiate this navigation, then we need to take care to reset any pre-
3042 // existing navigation state to a content-initiated navigation state.
3043 // DidCreateDataSource conveniently takes care of this for us.
3044 didCreateDataSource(frame, frame->dataSource());
3045
[email protected]007733c2011-11-17 00:34:073046 DocumentState* document_state =
3047 DocumentState::FromDataSource(frame->dataSource());
3048 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:093049 new_state->set_was_within_same_page(true);
3050
[email protected]3d9689372009-09-10 04:29:173051 didCommitProvisionalLoad(frame, is_new_navigation);
3052
[email protected]750fcf872011-08-03 23:10:473053 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
3054 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:173055}
3056
[email protected]310ebd6302011-10-10 19:06:283057void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313058 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593059}
3060
[email protected]310ebd6302011-10-10 19:06:283061void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:173062 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3063 // Ignore
3064}
3065
[email protected]310ebd6302011-10-10 19:06:283066void RenderViewImpl::willSendRequest(WebFrame* frame,
3067 unsigned identifier,
3068 WebURLRequest& request,
3069 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303070 WebFrame* top_frame = frame->top();
3071 if (!top_frame)
3072 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513073 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3074 WebDataSource* top_data_source = top_frame->dataSource();
3075 WebDataSource* data_source =
3076 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:223077
[email protected]78d5cfe2011-02-04 08:43:223078 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:033079 GURL new_url;
3080 if (content::GetContentClient()->renderer()->WillSendRequest(
3081 frame, request_url, &new_url)) {
3082 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:223083 }
3084
[email protected]2905f742011-10-13 03:51:583085 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:073086 DocumentState* document_state = DocumentState::FromDataSource(data_source);
3087 NavigationState* navigation_state = document_state->navigation_state();
3088 if (document_state) {
3089 if (document_state->is_cache_policy_override_set())
3090 request.setCachePolicy(document_state->cache_policy_override());
3091 transition_type = navigation_state->transition_type();
[email protected]5e369672009-11-03 23:48:303092 }
[email protected]8a3125a712010-08-09 18:58:513093
[email protected]91043a8232011-11-04 16:41:193094 request.setExtraData(
[email protected]537fbe02011-11-24 00:58:063095 new RequestExtraData(frame->referrerPolicy(),
3096 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:193097 frame->identifier(),
3098 frame->parent() == top_frame,
3099 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]4ad5d77d2011-12-03 02:00:483100 transition_type,
3101 navigation_state->transferred_request_child_id(),
3102 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:573103
[email protected]007733c2011-11-17 00:34:073104 DocumentState* top_document_state =
3105 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:573106 // TODO(gavinp): separate out prefetching and prerender field trials
3107 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:073108 if (top_document_state &&
[email protected]d88bf0a2011-08-30 23:55:573109 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
3110 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]007733c2011-11-17 00:34:073111 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513112
[email protected]3d9689372009-09-10 04:29:173113 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133114 request.setHasUserGesture(frame->isProcessingUserGesture());
3115
[email protected]0a8db0d2011-04-13 15:15:403116 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:133117 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:173118}
3119
[email protected]310ebd6302011-10-10 19:06:283120void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173121 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493122
[email protected]3d9689372009-09-10 04:29:173123 // Only do this for responses that correspond to a provisional data source
3124 // of the top-most frame. If we have a provisional data source, then we
3125 // can't have any sub-resources yet, so we know that this response must
3126 // correspond to a frame load.
3127 if (!frame->provisionalDataSource() || frame->parent())
3128 return;
3129
3130 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083131 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173132 if (frame->isViewSourceModeEnabled())
3133 return;
3134
[email protected]007733c2011-11-17 00:34:073135 DocumentState* document_state =
3136 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083137 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533138
[email protected]972ebdff2010-06-10 22:59:073139 // Record page load flags.
[email protected]007733c2011-11-17 00:34:073140 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3141 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]b9fd01ba2012-02-28 01:50:403142 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
3143 if (extra_data) {
3144 document_state->set_npn_negotiated_protocol(
3145 extra_data->npn_negotiated_protocol());
3146 }
[email protected]007733c2011-11-17 00:34:073147 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:573148 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:073149 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3150 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093151 // Whether or not the http status code actually corresponds to an error is
3152 // only checked when the page is done loading, if |use_error_page| is
3153 // still true.
[email protected]007733c2011-11-17 00:34:073154 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173155}
3156
[email protected]310ebd6302011-10-10 19:06:283157void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173158 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:073159 DocumentState* document_state =
3160 DocumentState::FromDataSource(frame->dataSource());
3161 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173162 return;
3163
[email protected]7bfc153f2011-09-23 22:00:203164 // Do not show error page when DevTools is attached.
3165 if (devtools_agent_->IsAttached())
3166 return;
3167
[email protected]06333afe2011-02-24 14:55:093168 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:073169 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:083170 if (http_status_code == 404) {
3171 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413172 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173173
[email protected]b6cb3a842011-06-24 18:28:413174 const GURL& error_page_url =
3175 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093176 if (error_page_url.is_valid()) {
3177 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473178 original_error.domain = "http";
3179 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413180 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173181
[email protected]007733c2011-11-17 00:34:073182 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093183 new AltErrorPageResourceFetcher(
3184 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:083185 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3186 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093187 return;
3188 }
3189 }
[email protected]3d9689372009-09-10 04:29:173190
[email protected]e6a2ce52011-10-08 01:40:133191 std::string error_domain;
3192 if (content::GetContentClient()->renderer()->HasErrorPage(
3193 http_status_code, &error_domain)) {
3194 WebURLError error;
3195 error.unreachableURL = frame->document().url();
3196 error.domain = WebString::fromUTF8(error_domain);
3197 error.reason = http_status_code;
3198
3199 LoadNavigationErrorPage(
3200 frame, frame->dataSource()->request(), error, std::string(), true);
3201 }
[email protected]3d9689372009-09-10 04:29:173202}
3203
[email protected]310ebd6302011-10-10 19:06:283204void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173205 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3206 // Ignore
3207}
3208
[email protected]310ebd6302011-10-10 19:06:283209void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173210 WebFrame* frame, const WebURLRequest& request,
3211 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003212 // The recipients of this message have no use for data: URLs: they don't
3213 // affect the page's insecure content list and are not in the disk cache. To
3214 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3215 // filter them out here.
3216 GURL url(request.url());
3217 if (url.SchemeIs("data"))
3218 return;
3219
[email protected]3d9689372009-09-10 04:29:173220 // Let the browser know we loaded a resource from the memory cache. This
3221 // message is needed to display the correct SSL indicators.
3222 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3223 routing_id_,
[email protected]84703292011-10-28 20:44:003224 url,
[email protected]70435962011-08-02 20:13:283225 response.securityInfo(),
3226 request.httpMethod().utf8(),
3227 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173228}
3229
[email protected]310ebd6302011-10-10 19:06:283230void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293231 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3232}
3233
[email protected]310ebd6302011-10-10 19:06:283234void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023235 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293236 Send(new ViewHostMsg_DidRunInsecureContent(
3237 routing_id_,
[email protected]92771112011-01-20 00:13:023238 origin.toString().utf8(),
3239 target));
[email protected]e3d60e5d2009-09-25 21:08:293240}
3241
[email protected]310ebd6302011-10-10 19:06:283242void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
[email protected]b00ba702011-08-17 01:41:033243 webkit_glue::WebURLLoaderImpl* loader_impl =
3244 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
3245 loader_impl->UpdateRoutingId(routing_id_);
3246}
3247
[email protected]310ebd6302011-10-10 19:06:283248void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173249 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3250}
3251
[email protected]310ebd6302011-10-10 19:06:283252void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3253 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583254 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283255 int world_id) {
[email protected]5bc10932011-09-21 21:03:303256 content::GetContentClient()->renderer()->DidCreateScriptContext(
[email protected]a00fe692012-02-27 05:52:583257 frame, context, extension_group, world_id);
3258}
3259
3260void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3261 v8::Handle<v8::Context> context,
3262 int world_id) {
3263 content::GetContentClient()->renderer()->DidCreateScriptContext(
3264 frame, context, -1, world_id);
[email protected]0c882b282009-10-07 17:01:283265}
3266
[email protected]310ebd6302011-10-10 19:06:283267void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3268 v8::Handle<v8::Context> context,
3269 int world_id) {
[email protected]5bc10932011-09-21 21:03:303270 content::GetContentClient()->renderer()->WillReleaseScriptContext(
3271 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283272}
3273
[email protected]310ebd6302011-10-10 19:06:283274void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073275 // We don't always want to send the change messages over IPC, only if we've
3276 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3277 // message.
3278 if (!send_preferred_size_changes_ || !webview())
3279 return;
3280
[email protected]705243f2010-05-05 19:58:073281 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3282 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533283
3284 // In the presence of zoom, these sizes are still reported as if unzoomed,
3285 // so we need to adjust.
3286 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3287 size.set_width(static_cast<int>(size.width() * zoom_factor));
3288 size.set_height(static_cast<int>(size.height() * zoom_factor));
3289
[email protected]705243f2010-05-05 19:58:073290 if (size == preferred_size_)
3291 return;
[email protected]c27324b2009-11-19 22:44:293292
[email protected]705243f2010-05-05 19:58:073293 preferred_size_ = size;
3294 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3295 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173296}
3297
[email protected]273558fb2012-01-12 15:03:513298void RenderViewImpl::EnsureMediaStreamImpl() {
[email protected]50da23d02012-04-13 17:47:483299 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
3300 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
3301 return;
3302
[email protected]273558fb2012-01-12 15:03:513303#if defined(ENABLE_P2P_APIS)
3304 if (!p2p_socket_dispatcher_)
3305 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
3306#endif
3307
[email protected]5b87e782012-02-09 18:19:323308#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:513309 if (!media_stream_dispatcher_)
3310 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3311
[email protected]1bc65a42012-04-23 09:31:253312 if (!media_stream_impl_) {
[email protected]273558fb2012-01-12 15:03:513313 MediaStreamDependencyFactory* factory = new MediaStreamDependencyFactory();
3314 media_stream_impl_ = new MediaStreamImpl(
[email protected]1bc65a42012-04-23 09:31:253315 this,
[email protected]273558fb2012-01-12 15:03:513316 media_stream_dispatcher_,
3317 p2p_socket_dispatcher_,
3318 RenderThreadImpl::current()->video_capture_impl_manager(),
3319 factory);
3320 }
[email protected]5b87e782012-02-09 18:19:323321#endif
[email protected]273558fb2012-01-12 15:03:513322}
3323
[email protected]310ebd6302011-10-10 19:06:283324void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3325 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313326 if (webview()->mainFrame() != frame)
3327 return;
3328 WebView* frameView = frame->view();
3329 if (!frameView)
3330 return;
3331
3332 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3333 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3334
3335 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3336 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3337 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3338 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3339
3340 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3341 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3342 }
3343}
3344
[email protected]310ebd6302011-10-10 19:06:283345void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313346 WebSize offset = frame->scrollOffset();
3347 WebSize minimum_offset = frame->minimumScrollOffset();
3348 WebSize maximum_offset = frame->maximumScrollOffset();
3349
3350 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3351 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3352
3353 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3354 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3355 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3356 routing_id_, is_pinned_to_left, is_pinned_to_right));
3357
3358 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3359 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3360 }
3361}
3362
[email protected]310ebd6302011-10-10 19:06:283363void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493364 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313365
3366 if (webview()->mainFrame() == frame)
3367 UpdateScrollState(frame);
[email protected]2b942c332012-04-25 16:26:263368
3369 FOR_EACH_OBSERVER(
3370 RenderViewObserver, observers_, DidChangeScrollOffset(frame));
[email protected]dd6afca2011-08-13 03:44:313371}
3372
[email protected]310ebd6302011-10-10 19:06:283373void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:313374 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:493375}
3376
[email protected]ea931252012-02-15 22:01:033377void RenderViewImpl::numberOfTouchEventHandlersChanged(unsigned num_handlers) {
3378 Send(new ViewHostMsg_DidChangeNumTouchEvents(routing_id_, num_handlers));
3379}
3380
[email protected]310ebd6302011-10-10 19:06:283381void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
3382 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113383 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3384 if (!count)
3385 active_match_ordinal = 0;
3386
3387 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3388 routing_id_,
3389 request_id,
3390 count,
3391 gfx::Rect(),
3392 active_match_ordinal,
3393 final_update);
3394
[email protected]8922e1f2009-10-03 05:01:263395 // If we have a message that has been queued up, then we should just replace
3396 // it. The ACK from the browser will make sure it gets sent when the browser
3397 // wants it.
3398 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263399 queued_find_reply_message_.reset(msg);
3400 } else {
3401 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113402 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263403 }
3404}
3405
[email protected]310ebd6302011-10-10 19:06:283406void RenderViewImpl::reportFindInPageSelection(int request_id,
3407 int active_match_ordinal,
3408 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:263409 // Send the search result over to the browser process.
3410 Send(new ViewHostMsg_Find_Reply(routing_id_,
3411 request_id,
3412 -1,
3413 selection_rect,
3414 active_match_ordinal,
3415 false));
3416}
3417
[email protected]310ebd6302011-10-10 19:06:283418void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:223419 WebFrame* frame,
3420 WebFileSystem::Type type,
3421 long long size,
[email protected]d275d7a2010-11-03 01:34:493422 bool create,
[email protected]2b06a992010-08-21 05:48:223423 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083424 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223425
[email protected]b6cb3a842011-06-24 18:28:413426 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563427 if (origin.isUnique()) {
3428 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:083429 callbacks->didFail(WebKit::WebFileErrorAbort);
3430 return;
3431 }
[email protected]2b06a992010-08-21 05:48:223432
[email protected]c5a272d2010-09-27 18:37:083433 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3434 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493435 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223436}
3437
[email protected]310ebd6302011-10-10 19:06:283438void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:403439 WebFrame* frame,
3440 WebStorageQuotaType type,
3441 WebStorageQuotaCallbacks* callbacks) {
3442 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413443 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563444 if (origin.isUnique()) {
3445 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403446 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3447 return;
3448 }
3449 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533450 GURL(origin.toString()),
3451 static_cast<quota::StorageType>(type),
3452 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403453}
3454
[email protected]310ebd6302011-10-10 19:06:283455void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:403456 WebFrame* frame,
3457 WebStorageQuotaType type,
3458 unsigned long long requested_size,
3459 WebStorageQuotaCallbacks* callbacks) {
3460 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413461 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563462 if (origin.isUnique()) {
3463 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403464 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3465 return;
3466 }
3467 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533468 routing_id(), GURL(origin.toString()),
3469 static_cast<quota::StorageType>(type), requested_size,
3470 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403471}
3472
[email protected]8b5af492011-11-28 21:50:583473void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:153474 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]e6e35cd2011-12-22 19:37:063475 string16 title = service.title();
3476 if (title.empty())
3477 title = webview()->mainFrame()->document().title();
3478
[email protected]8b5af492011-11-28 21:50:583479 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
3480 service.action(),
3481 service.type(),
3482 service.url().spec().utf16(),
[email protected]e6e35cd2011-12-22 19:37:063483 title,
[email protected]8b5af492011-11-28 21:50:583484 service.disposition()));
3485}
3486
[email protected]ffc8bed2012-01-21 01:23:153487void RenderViewImpl::dispatchIntent(
3488 WebFrame* frame, const WebIntentRequest& intentRequest) {
3489 webkit_glue::WebIntentData intent_data(intentRequest.intent());
3490 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:583491 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:153492 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:583493}
3494
[email protected]5fa3a062012-03-21 15:39:343495void RenderViewImpl::willOpenSocketStream(
3496 WebSocketStreamHandle* handle) {
3497 SocketStreamHandleData::AddToHandle(handle, routing_id_);
3498}
3499
[email protected]18d5be92011-07-25 18:00:193500// WebKit::WebPageSerializerClient implementation ------------------------------
3501
[email protected]310ebd6302011-10-10 19:06:283502void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:193503 const WebURL& frame_url,
3504 const WebCString& data,
3505 WebPageSerializerClient::PageSerializationStatus status) {
3506 Send(new ViewHostMsg_SendSerializedHtmlData(
3507 routing_id(),
3508 frame_url,
3509 data.data(),
3510 static_cast<int32>(status)));
3511}
3512
[email protected]a2ef54c2011-10-10 16:20:313513// content::RenderView implementation ------------------------------------------
3514
[email protected]310ebd6302011-10-10 19:06:283515bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:313516 return RenderWidget::Send(message);
3517}
3518
[email protected]82114f52012-03-20 22:53:413519int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:313520 return routing_id_;
3521}
3522
[email protected]82114f52012-03-20 22:53:413523int RenderViewImpl::GetPageId() const {
[email protected]a2ef54c2011-10-10 16:20:313524 return page_id_;
3525}
3526
[email protected]82114f52012-03-20 22:53:413527gfx::Size RenderViewImpl::GetSize() const {
[email protected]a2ef54c2011-10-10 16:20:313528 return size();
3529}
3530
[email protected]82114f52012-03-20 22:53:413531gfx::NativeViewId RenderViewImpl::GetHostWindow() const {
[email protected]a2ef54c2011-10-10 16:20:313532 return host_window();
3533}
3534
[email protected]82114f52012-03-20 22:53:413535WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313536 return webkit_preferences_;
3537}
3538
[email protected]82114f52012-03-20 22:53:413539WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313540 return webview();
3541}
3542
[email protected]82114f52012-03-20 22:53:413543WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313544 if (!webview())
3545 return WebNode();
3546 WebFrame* focused_frame = webview()->focusedFrame();
3547 if (focused_frame) {
3548 WebDocument doc = focused_frame->document();
3549 if (!doc.isNull())
3550 return doc.focusedNode();
3551 }
3552
3553 return WebNode();
3554}
3555
[email protected]82114f52012-03-20 22:53:413556WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313557 return context_menu_node_;
3558}
3559
[email protected]82114f52012-03-20 22:53:413560bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) const {
[email protected]a2ef54c2011-10-10 16:20:313561 bool is_editable_node = false;
3562 if (!node.isNull()) {
3563 if (node.isContentEditable()) {
3564 is_editable_node = true;
3565 } else if (node.isElementNode()) {
3566 is_editable_node =
3567 node.toConst<WebElement>().isTextFormControlElement();
3568 }
3569 }
3570 return is_editable_node;
3571}
3572
[email protected]310ebd6302011-10-10 19:06:283573WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313574 WebKit::WebFrame* frame,
3575 const webkit::WebPluginInfo& info,
[email protected]82114f52012-03-20 22:53:413576 const WebKit::WebPluginParams& params) {
[email protected]a2ef54c2011-10-10 16:20:313577 bool pepper_plugin_was_registered = false;
3578 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3579 pepper_delegate_.CreatePepperPluginModule(info,
3580 &pepper_plugin_was_registered));
3581 if (pepper_plugin_was_registered) {
3582 if (!pepper_module)
3583 return NULL;
3584 return new webkit::ppapi::WebPluginImpl(
3585 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3586 }
3587
[email protected]34b27e442012-01-20 20:07:413588#if defined(USE_AURA)
3589 return NULL;
3590#else
[email protected]a2ef54c2011-10-10 16:20:313591 return new webkit::npapi::WebPluginImpl(
3592 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:413593#endif
[email protected]a2ef54c2011-10-10 16:20:313594}
3595
[email protected]310ebd6302011-10-10 19:06:283596void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3597 const string16& jscript,
3598 int id,
3599 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313600 v8::Handle<v8::Value> result;
3601 WebFrame* web_frame = GetChildFrame(frame_xpath);
3602 if (web_frame)
3603 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3604 if (notify_result) {
3605 ListValue list;
3606 if (!result.IsEmpty() && web_frame) {
3607 v8::HandleScope handle_scope;
3608 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3609 v8::Context::Scope context_scope(context);
3610 V8ValueConverterImpl converter;
3611 converter.set_allow_date(true);
3612 converter.set_allow_regexp(true);
3613 list.Set(0, converter.FromV8Value(result, context));
3614 } else {
3615 list.Set(0, Value::CreateNullValue());
3616 }
3617 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3618 }
3619}
3620
[email protected]310ebd6302011-10-10 19:06:283621bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313622 return (!send_preferred_size_changes_ ||
3623 (disable_scrollbars_size_limit_.width() <= width ||
3624 disable_scrollbars_size_limit_.height() <= height));
3625}
3626
[email protected]82114f52012-03-20 22:53:413627int RenderViewImpl::GetEnabledBindings() const {
[email protected]a2ef54c2011-10-10 16:20:313628 return enabled_bindings_;
3629}
3630
[email protected]82114f52012-03-20 22:53:413631bool RenderViewImpl::GetContentStateImmediately() const {
[email protected]a2ef54c2011-10-10 16:20:313632 return send_content_state_immediately_;
3633}
3634
[email protected]82114f52012-03-20 22:53:413635float RenderViewImpl::GetFilteredTimePerFrame() const {
[email protected]a2ef54c2011-10-10 16:20:313636 return filtered_time_per_frame();
3637}
3638
[email protected]310ebd6302011-10-10 19:06:283639void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
[email protected]82114f52012-03-20 22:53:413640 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313641 showContextMenu(frame, data);
3642}
3643
[email protected]82114f52012-03-20 22:53:413644WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313645 return visibilityState();
3646}
3647
[email protected]310ebd6302011-10-10 19:06:283648void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3649 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313650 return runModalAlertDialog(frame, message);
3651}
3652
[email protected]310ebd6302011-10-10 19:06:283653void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313654 WebKit::WebFrame* frame,
3655 const WebKit::WebURLRequest& request,
3656 WebKit::WebNavigationPolicy policy) {
3657 loadURLExternally(frame, request, policy);
3658}
3659
3660// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513661
[email protected]310ebd6302011-10-10 19:06:283662webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533663 const FilePath& file_path,
3664 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:203665 if (!PluginChannelHost::IsListening()) {
3666 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:593667 return NULL;
[email protected]94752ee2012-02-10 10:38:203668 }
[email protected]f103ab72009-09-02 17:10:593669
[email protected]00c39612010-03-06 02:53:283670 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463671 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323672#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223673 return webkit::npapi::WebPluginDelegateImpl::Create(
3674 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093675#else
[email protected]7398dcc2011-09-06 21:40:323676 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223677 NOTIMPLEMENTED();
3678 return NULL;
[email protected]7b6616f2010-01-14 18:07:553679#endif
[email protected]f103ab72009-09-02 17:10:593680 }
3681
[email protected]4e0616e2010-05-28 14:55:533682 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593683}
3684
[email protected]6ac77cb2012-05-01 14:49:013685WebKit::WebPlugin* RenderViewImpl::CreatePluginReplacement(
3686 const FilePath& file_path) {
3687 return content::GetContentClient()->renderer()->CreatePluginReplacement(
3688 this, file_path);
3689}
3690
[email protected]310ebd6302011-10-10 19:06:283691void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033692#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273693 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593694#endif
3695}
3696
[email protected]310ebd6302011-10-10 19:06:283697void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033698#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273699 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593700#endif
3701 CleanupWindowInPluginMoves(window);
3702}
3703
[email protected]310ebd6302011-10-10 19:06:283704void RenderViewImpl::DidMovePlugin(
3705 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593706 SchedulePluginMove(move);
3707}
3708
[email protected]310ebd6302011-10-10 19:06:283709void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593710 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523711 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593712}
3713
[email protected]310ebd6302011-10-10 19:06:283714void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593715 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523716 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593717}
3718
[email protected]310ebd6302011-10-10 19:06:283719WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513720 return &cookie_jar_;
3721}
3722
[email protected]a9288f52011-11-17 05:18:163723void RenderViewImpl::DidPlay(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073724 Send(new ViewHostMsg_MediaNotification(routing_id_,
3725 reinterpret_cast<int64>(player),
3726 player->hasVideo(),
3727 player->hasAudio(),
3728 true));
3729}
3730
[email protected]a9288f52011-11-17 05:18:163731void RenderViewImpl::DidPause(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073732 Send(new ViewHostMsg_MediaNotification(routing_id_,
3733 reinterpret_cast<int64>(player),
3734 player->hasVideo(),
3735 player->hasAudio(),
3736 false));
3737}
3738
[email protected]a9288f52011-11-17 05:18:163739void RenderViewImpl::PlayerGone(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073740 DidPause(player);
3741}
3742
[email protected]310ebd6302011-10-10 19:06:283743void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:293744 if (!webview())
3745 return;
3746
[email protected]26aa0482009-09-30 16:55:273747 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]6459800a2012-03-27 23:57:053748 SendUpdateState(item);
initial.commit09911bf2008-07-26 23:55:293749}
3750
[email protected]310ebd6302011-10-10 19:06:283751void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:363752 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:003753 if (!frame)
3754 return;
[email protected]b781ff282011-08-20 06:19:363755
[email protected]e99ef6f2011-10-16 01:13:003756 string16 text;
3757 size_t offset;
[email protected]3c8c74c2012-03-15 07:34:523758 ui::Range range;
[email protected]e99ef6f2011-10-16 01:13:003759
[email protected]3c8c74c2012-03-15 07:34:523760 if (pepper_delegate_.IsPluginFocused()) {
3761 pepper_delegate_.GetSurroundingText(&text, &range);
[email protected]82114f52012-03-20 22:53:413762 offset = 0; // Pepper API does not support offset reporting.
[email protected]3c8c74c2012-03-15 07:34:523763 // TODO(kinaba): cut as needed.
[email protected]e99ef6f2011-10-16 01:13:003764 } else {
[email protected]3c8c74c2012-03-15 07:34:523765 size_t location, length;
3766 if (!webview()->caretOrSelectionRange(&location, &length))
3767 return;
3768
3769 range = ui::Range(location, location + length);
3770
3771 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
3772 // If current focused element is editable, we will send 100 more chars
3773 // before and after selection. It is for input method surrounding text
3774 // feature.
3775 if (location > kExtraCharsBeforeAndAfterSelection)
3776 offset = location - kExtraCharsBeforeAndAfterSelection;
3777 else
3778 offset = 0;
3779 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
3780 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
3781 if (!webrange.isNull())
3782 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
3783 } else {
3784 offset = location;
3785 text = frame->selectionAsText();
3786 // http://crbug.com/101435
3787 // In some case, frame->selectionAsText() returned text's length is not
3788 // equal to the length returned from webview()->caretOrSelectionRange().
3789 // So we have to set the range according to text.length().
3790 range.set_end(range.start() + text.length());
3791 }
[email protected]b781ff282011-08-20 06:19:363792 }
3793
[email protected]b781ff282011-08-20 06:19:363794 // Sometimes we get repeated didChangeSelection calls from webkit when
3795 // the selection hasn't actually changed. We don't want to report these
3796 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:003797 if (selection_text_offset_ != offset ||
3798 selection_range_ != range ||
3799 selection_text_ != text) {
3800 selection_text_ = text;
3801 selection_text_offset_ = offset;
3802 selection_range_ = range;
3803 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
3804 }
[email protected]b781ff282011-08-20 06:19:363805}
3806
[email protected]310ebd6302011-10-10 19:06:283807GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
3808 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553809 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293810 // If the URL that failed was secure, then the embedding web page was not
3811 // expecting a network attacker to be able to manipulate its contents. As
3812 // we fetch alternate error pages over HTTP, we would be allowing a network
3813 // attacker to manipulate the contents of the response if we tried to use
3814 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153815 return GURL();
initial.commit09911bf2008-07-26 23:55:293816 }
3817
3818 // Grab the base URL from the browser process.
3819 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153820 return GURL();
initial.commit09911bf2008-07-26 23:55:293821
3822 // Strip query params from the failed URL.
3823 GURL::Replacements remove_params;
3824 remove_params.ClearUsername();
3825 remove_params.ClearPassword();
3826 remove_params.ClearQuery();
3827 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553828 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503829 std::string spec_to_send = url_to_send.spec();
3830 // Notify link doctor of the url truncation by sending of "?" at the end.
3831 if (failed_url.has_query())
[email protected]82114f52012-03-20 22:53:413832 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293833
3834 // Construct the query params to send to link doctor.
3835 std::string params(alternate_error_page_url_.query());
3836 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023837 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293838 params.append("&sourceid=chrome");
3839 params.append("&error=");
3840 switch (error_type) {
3841 case DNS_ERROR:
3842 params.append("dnserror");
3843 break;
3844
3845 case HTTP_404:
3846 params.append("http404");
3847 break;
3848
[email protected]5df266ac2008-10-15 19:50:133849 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333850 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133851 break;
3852
initial.commit09911bf2008-07-26 23:55:293853 default:
3854 NOTREACHED() << "unknown ErrorPageType";
3855 }
3856
3857 // OK, build the final url to return.
3858 GURL::Replacements link_doctor_params;
3859 link_doctor_params.SetQueryStr(params);
3860 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3861 return url;
3862}
3863
[email protected]310ebd6302011-10-10 19:06:283864GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:593865 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3866 return GURL();
3867 else
3868 return creator_url_;
3869}
3870
[email protected]69ddf852012-02-21 23:21:313871GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
3872 WebDataSource* ds = frame->dataSource();
3873 if (ds->hasUnreachableURL())
3874 return ds->unreachableURL();
3875
3876 const WebURLRequest& request = ds->request();
3877 return request.url();
3878}
3879
[email protected]310ebd6302011-10-10 19:06:283880WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:273881 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:313882 web_ui_bindings_.reset(new WebUIBindings(
3883 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:463884 }
[email protected]c50008512011-02-03 01:17:273885 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463886}
3887
[email protected]310ebd6302011-10-10 19:06:283888WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:013889 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493890}
3891
[email protected]310ebd6302011-10-10 19:06:283892void RenderViewImpl::OnFind(int request_id, const string16& search_text,
3893 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273894 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493895
[email protected]872542532011-06-23 00:43:163896 // Check if the plugin still exists in the document.
3897 if (main_frame->document().isPluginDocument() &&
3898 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493899 if (options.findNext) {
3900 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013901 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493902 } else {
[email protected]afdbd142010-07-10 08:01:233903 if (GetWebPluginFromPluginDocument()->startFind(
3904 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493905 } else {
[email protected]e7c58a32010-08-13 19:47:113906 // Send "no results".
3907 Send(new ViewHostMsg_Find_Reply(routing_id_,
3908 request_id,
3909 0,
3910 gfx::Rect(),
3911 0,
3912 true));
[email protected]24a7f3c2010-03-25 08:26:493913 }
3914 }
3915 return;
3916 }
3917
[email protected]b4bb2502009-10-01 22:35:273918 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273919 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293920 WebFrame* search_frame = focused_frame; // start searching focused frame.
3921
3922 bool multi_frame = (frame_after_main != main_frame);
3923
3924 // If we have multiple frames, we don't want to wrap the search within the
3925 // frame, so we check here if we only have main_frame in the chain.
3926 bool wrap_within_frame = !multi_frame;
3927
[email protected]b3f2b912009-04-09 16:18:523928 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293929 bool result = false;
3930
[email protected]7830da3e2009-11-06 16:27:263931 // If something is selected when we start searching it means we cannot just
3932 // increment the current match ordinal; we need to re-generate it.
3933 WebRange current_selection = focused_frame->selectionRange();
3934
initial.commit09911bf2008-07-26 23:55:293935 do {
[email protected]dd7daa82009-08-10 05:46:453936 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593937 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293938
3939 if (!result) {
3940 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223941 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293942
3943 // Find the next frame, but skip the invisible ones.
3944 do {
3945 // What is the next frame to search? (we might be going backwards). Note
3946 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593947 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273948 search_frame->traverseNext(true) :
3949 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453950 } while (!search_frame->hasVisibleContent() &&
3951 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293952
[email protected]884db412008-11-24 23:46:503953 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223954 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293955
3956 // If we have multiple frames and we have wrapped back around to the
3957 // focused frame, we need to search it once more allowing wrap within
3958 // the frame, otherwise it will report 'no match' if the focused frame has
3959 // reported matches, but no frames after the focused_frame contain a
3960 // match for the search word(s).
3961 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453962 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593963 request_id, search_text, options, true, // Force wrapping.
3964 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293965 }
3966 }
3967
[email protected]26aa0482009-09-30 16:55:273968 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293969 } while (!result && search_frame != focused_frame);
3970
[email protected]7830da3e2009-11-06 16:27:263971 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293972 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453973 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293974 } else {
3975 // If nothing is found, set result to "0 of 0", otherwise, set it to
3976 // "-1 of 1" to indicate that we found at least one item, but we don't know
3977 // yet what is active.
3978 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3979 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293980
[email protected]4f3dc372009-02-24 00:10:293981 // If we find no matches then this will be our last status update.
3982 // Otherwise the scoping effort will send more results.
3983 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293984
[email protected]4f3dc372009-02-24 00:10:293985 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403986 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593987 request_id,
[email protected]4f3dc372009-02-24 00:10:293988 match_count,
3989 selection_rect,
3990 ordinal,
3991 final_status_update));
initial.commit09911bf2008-07-26 23:55:293992
initial.commit09911bf2008-07-26 23:55:293993 // Scoping effort begins, starting with the mainframe.
3994 search_frame = main_frame;
3995
[email protected]dd7daa82009-08-10 05:46:453996 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293997
3998 do {
3999 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454000 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294001
4002 // We don't start another scoping effort unless at least one match has
4003 // been found.
4004 if (result) {
4005 // Start new scoping request. If the scoping function determines that it
4006 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454007 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594008 search_text,
4009 options,
initial.commit09911bf2008-07-26 23:55:294010 true); // reset the tickmarks
4011 }
4012
4013 // Iterate to the next frame. The frame will not necessarily scope, for
4014 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274015 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294016 } while (search_frame != main_frame);
4017 }
4018}
4019
[email protected]815dd9872011-11-23 18:40:304020void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:494021 WebView* view = webview();
4022 if (!view)
4023 return;
4024
4025 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:164026 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014027 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494028 return;
4029 }
4030
[email protected]815dd9872011-11-23 18:40:304031 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:494032 if (clear_selection)
4033 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4034
4035 WebFrame* frame = view->mainFrame();
4036 while (frame) {
4037 frame->stopFinding(clear_selection);
4038 frame = frame->traverseNext(false);
4039 }
4040
[email protected]815dd9872011-11-23 18:40:304041 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:494042 WebFrame* focused_frame = view->focusedFrame();
4043 if (focused_frame) {
4044 WebDocument doc = focused_frame->document();
4045 if (!doc.isNull()) {
4046 WebNode node = doc.focusedNode();
4047 if (!node.isNull())
4048 node.simulateClick();
4049 }
4050 }
4051 }
4052}
4053
[email protected]310ebd6302011-10-10 19:06:284054void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:494055 // Check if there is any queued up request waiting to be sent.
4056 if (queued_find_reply_message_.get()) {
4057 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:424058 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:494059 }
4060}
4061
[email protected]54087fe2011-10-28 22:02:484062void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:514063 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4064 return;
4065
[email protected]258d31122010-05-09 10:59:414066 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:104067
[email protected]b75b8292010-10-01 07:28:254068 double old_zoom_level = webview()->zoomLevel();
4069 double zoom_level;
[email protected]54087fe2011-10-28 22:02:484070 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:254071 zoom_level = 0;
4072 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4073 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:484074 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:254075 } else {
4076 // Either the user hit the zoom factor limit and thus the zoom level is now
4077 // not a whole number, or a plugin changed it to a custom value. We want
4078 // to go to the next whole number so that the user can always get back to
4079 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:484080 if ((old_zoom_level > 1 && zoom > 0) ||
4081 (old_zoom_level < 1 && zoom < 0)) {
4082 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:254083 } else {
4084 // We're going towards 100%, so first go to the next whole number.
4085 zoom_level = static_cast<int>(old_zoom_level);
4086 }
4087 }
[email protected]b75b8292010-10-01 07:28:254088 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:414089 zoomLevelChanged();
4090}
4091
4092void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
4093 int zoom_center_x, int zoom_center_y) {
4094 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
4095 kScalingIncrementForGesture);
4096}
4097
4098void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
4099 int zoom_center_x,
4100 int zoom_center_y,
4101 float scaling_increment) {
4102 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4103 return;
4104
[email protected]c514d6372011-08-16 22:54:444105 double old_page_scale_factor = webview()->pageScaleFactor();
4106 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:484107 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:444108 page_scale_factor = 1.0;
4109 } else {
4110 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:414111 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:444112 }
[email protected]47578fa02011-11-02 19:34:414113 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:094114 webview()->setPageScaleFactor(page_scale_factor,
4115 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:414116 }
[email protected]40bd6582009-12-04 23:49:514117}
4118
[email protected]310ebd6302011-10-10 19:06:284119void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174120 webview()->hidePopups();
4121 webview()->setZoomLevel(false, zoom_level);
4122 zoomLevelChanged();
4123}
4124
[email protected]310ebd6302011-10-10 19:06:284125void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4126 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544127 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294128}
4129
[email protected]310ebd6302011-10-10 19:06:284130void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274131 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294132}
4133
[email protected]310ebd6302011-10-10 19:06:284134void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274135 WebString no_encoding;
4136 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184137}
4138
[email protected]310ebd6302011-10-10 19:06:284139WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454140 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274141 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454142
4143 // xpath string can represent a frame deep down the tree (across multiple
4144 // frame DOMs).
4145 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4146 // should break into 2 xpaths
4147 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:414148 std::vector<string16> xpaths;
4149 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:454150
[email protected]26aa0482009-09-30 16:55:274151 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:414152 for (std::vector<string16>::const_iterator i = xpaths.begin();
4153 frame && i != xpaths.end(); ++i) {
4154 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294155 }
4156
[email protected]dd7daa82009-08-10 05:46:454157 return frame;
initial.commit09911bf2008-07-26 23:55:294158}
4159
[email protected]310ebd6302011-10-10 19:06:284160void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4161 const string16& jscript,
4162 int id,
4163 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:534164 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294165}
4166
[email protected]310ebd6302011-10-10 19:06:284167void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
4168 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:414169 WebFrame* frame = GetChildFrame(frame_xpath);
4170 if (!frame)
[email protected]216813952011-05-19 22:21:264171 return;
[email protected]ae461542009-06-19 19:03:414172
[email protected]01cf589c2011-07-28 18:04:034173 frame->document().insertUserStyleSheet(
4174 WebString::fromUTF8(css),
4175 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:484176}
4177
[email protected]310ebd6302011-10-10 19:06:284178void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:094179 enabled_bindings_ |= enabled_bindings_flags;
[email protected]744c2a22012-03-15 18:42:044180
4181 // Keep track of the total bindings accumulated in this process.
4182 RenderProcess::current()->AddBindings(enabled_bindings_flags);
initial.commit09911bf2008-07-26 23:55:294183}
4184
[email protected]310ebd6302011-10-10 19:06:284185void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
4186 const std::string& value) {
[email protected]808bda52012-03-09 22:43:324187 if (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI)
4188 GetWebUIBindings()->SetProperty(name, value);
4189 else
4190 NOTREACHED() << "WebUI bindings not enabled.";
initial.commit09911bf2008-07-26 23:55:294191}
4192
[email protected]310ebd6302011-10-10 19:06:284193void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
4194 const gfx::Point& client_point,
4195 const gfx::Point& screen_point,
4196 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:554197 WebDragOperation operation = webview()->dragTargetDragEnter(
4198 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:554199 client_point,
4200 screen_point,
4201 ops);
4202
4203 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4204}
4205
[email protected]310ebd6302011-10-10 19:06:284206void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
4207 const gfx::Point& screen_point,
4208 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:554209 WebDragOperation operation = webview()->dragTargetDragOver(
4210 client_point,
4211 screen_point,
4212 ops);
4213
4214 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4215}
4216
[email protected]310ebd6302011-10-10 19:06:284217void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:554218 webview()->dragTargetDragLeave();
4219}
4220
[email protected]310ebd6302011-10-10 19:06:284221void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
4222 const gfx::Point& screen_point) {
[email protected]59f4f2fa2011-03-23 01:00:554223 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:574224
4225 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:554226}
4227
[email protected]310ebd6302011-10-10 19:06:284228void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4229 const gfx::Point& screen_point,
4230 bool ended,
4231 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034232 if (ended) {
[email protected]26aa0482009-09-30 16:55:274233 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204234 } else {
4235 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034236 }
initial.commit09911bf2008-07-26 23:55:294237}
4238
[email protected]310ebd6302011-10-10 19:06:284239void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274240 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294241}
4242
[email protected]310ebd6302011-10-10 19:06:284243void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594244 webkit_preferences_ = prefs;
4245 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294246}
4247
[email protected]310ebd6302011-10-10 19:06:284248void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:294249 alternate_error_page_url_ = url;
4250}
4251
[email protected]310ebd6302011-10-10 19:06:284252void RenderViewImpl::OnCustomContextMenuAction(
[email protected]35be7ec2012-02-12 20:42:514253 const content::CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:084254 unsigned action) {
4255 if (custom_context.is_pepper_menu)
4256 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
4257 else
4258 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:584259 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
4260 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:334261}
4262
[email protected]310ebd6302011-10-10 19:06:284263void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:514264 int id,
4265 const std::vector<FilePath>& paths) {
4266 if (!enumeration_completions_[id])
4267 return;
4268
4269 WebVector<WebString> ws_file_names(paths.size());
4270 for (size_t i = 0; i < paths.size(); ++i)
4271 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
4272
4273 enumeration_completions_[id]->didChooseFile(ws_file_names);
4274 enumeration_completions_.erase(id);
4275}
4276
[email protected]fb11b6a42012-03-14 07:25:124277void RenderViewImpl::OnFileChooserResponse(
4278 const std::vector<content::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:364279 // This could happen if we navigated to a different page before the user
4280 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474281 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364282 return;
4283
[email protected]b5188522012-03-15 00:18:044284 // Convert Chrome's SelectedFileInfo list to WebKit's.
4285 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
4286 files.size());
4287 for (size_t i = 0; i < files.size(); ++i) {
4288 WebFileChooserCompletion::SelectedFileInfo selected_file;
4289 selected_file.path = webkit_glue::FilePathToWebString(files[i].path);
4290 selected_file.displayName = webkit_glue::FilePathStringToWebString(
4291 files[i].display_name);
4292 selected_files[i] = selected_file;
4293 }
[email protected]a1128322009-10-06 18:38:464294
[email protected]cdaf8d02010-03-30 19:52:474295 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:044296 file_chooser_completions_.front()->completion->didChooseFile(
4297 selected_files);
[email protected]cdaf8d02010-03-30 19:52:474298 file_chooser_completions_.pop_front();
4299
4300 // If there are more pending file chooser requests, schedule one now.
4301 if (!file_chooser_completions_.empty()) {
4302 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4303 file_chooser_completions_.front()->params));
4304 }
initial.commit09911bf2008-07-26 23:55:294305}
4306
[email protected]244ac1892011-12-02 17:04:474307void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
4308 const gfx::Size& max_size) {
4309 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4310 if (!webview())
4311 return;
[email protected]61e2b3cc2012-03-02 16:13:344312 webview()->enableAutoResizeMode(min_size, max_size);
4313}
4314
4315void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
4316 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4317 if (!webview())
4318 return;
4319 webview()->disableAutoResizeMode();
4320
4321 Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK);
[email protected]244ac1892011-12-02 17:04:474322}
4323
[email protected]2bf834f2011-11-17 20:02:214324void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:244325 if (send_preferred_size_changes_)
4326 return;
[email protected]9fb325e2010-05-06 18:23:244327 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394328
[email protected]d812fd12011-05-27 23:05:074329 // Start off with an initial preferred size notification (in case
4330 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:594331 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:084332}
4333
[email protected]310ebd6302011-10-10 19:06:284334void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:104335 const gfx::Size& disable_scrollbar_size_limit) {
4336 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4337}
4338
[email protected]310ebd6302011-10-10 19:06:284339void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:314340 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:504341 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:514342 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374343 UpdateFontRenderingFromRendererPrefs();
[email protected]a13283cc2012-04-05 00:21:224344#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:414345 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4346 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464347 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:514348 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:344349 renderer_prefs.thumb_inactive_color,
4350 renderer_prefs.thumb_active_color,
4351 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:554352#endif
[email protected]93623c5d2009-12-10 21:40:324353
[email protected]a13283cc2012-04-05 00:21:224354#if defined(USE_ASH) || defined(TOOLKIT_GTK)
[email protected]644d77e2010-01-27 01:03:104355 if (webview()) {
[email protected]a13283cc2012-04-05 00:21:224356#if defined(TOOLKIT_GTK)
[email protected]93623c5d2009-12-10 21:40:324357 webview()->setScrollbarColors(
4358 renderer_prefs.thumb_inactive_color,
4359 renderer_prefs.thumb_active_color,
4360 renderer_prefs.track_color);
[email protected]d299d972012-03-23 02:26:554361#endif
[email protected]644d77e2010-01-27 01:03:104362 webview()->setSelectionColors(
4363 renderer_prefs.active_selection_bg_color,
4364 renderer_prefs.active_selection_fg_color,
4365 renderer_prefs.inactive_selection_bg_color,
4366 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464367 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104368 }
[email protected]7a74e102009-09-03 00:16:564369#endif
[email protected]d299d972012-03-23 02:26:554370
[email protected]d051d9a2011-12-10 02:02:504371 // If the zoom level for this page matches the old zoom default, and this
4372 // is not a plugin, update the zoom level to match the new default.
4373 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
4374 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
4375 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
4376 zoomLevelChanged();
4377 }
[email protected]80d96fa2009-06-10 22:34:514378}
4379
[email protected]310ebd6302011-10-10 19:06:284380void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
4381 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:284382 if (webview())
4383 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564384}
4385
[email protected]81375e872012-01-11 21:40:364386void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
4387 const WebPluginAction& action) {
4388 if (webview())
4389 webview()->performPluginAction(action, location);
4390}
4391
[email protected]310ebd6302011-10-10 19:06:284392void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:194393 const GURL& page_url) {
4394 // Prepare list to storage all savable resource links.
4395 std::vector<GURL> resources_list;
4396 std::vector<GURL> referrers_list;
4397 std::vector<GURL> frames_list;
4398 webkit_glue::SavableResourcesResult result(&resources_list,
4399 &referrers_list,
4400 &frames_list);
4401
[email protected]445e1042011-12-03 21:03:154402 // FIXME(rdsmith): When GetAllSavableResourceLinksForCurrentPage starts to
4403 // return referrers, it should also return the referrer policies.
[email protected]18d5be92011-07-25 18:00:194404 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4405 webview(),
4406 page_url,
4407 &result,
[email protected]0a35efc2012-03-13 17:28:134408 content::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:194409 // If something is wrong when collecting all savable resource links,
4410 // send empty list to embedder(browser) to tell it failed.
4411 referrers_list.clear();
4412 resources_list.clear();
4413 frames_list.clear();
4414 }
4415
4416 // Send result of all savable resource links to embedder.
4417 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
4418 resources_list,
4419 referrers_list,
4420 frames_list));
4421}
4422
[email protected]310ebd6302011-10-10 19:06:284423void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:194424 const std::vector<GURL>& links,
4425 const std::vector<FilePath>& local_paths,
4426 const FilePath& local_directory_name) {
4427
4428 // Convert std::vector of GURLs to WebVector<WebURL>
4429 WebVector<WebURL> weburl_links(links);
4430
4431 // Convert std::vector of std::strings to WebVector<WebString>
4432 WebVector<WebString> webstring_paths(local_paths.size());
4433 for (size_t i = 0; i < local_paths.size(); i++)
4434 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4435
4436 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
4437 webstring_paths,
4438 webkit_glue::FilePathToWebString(
4439 local_directory_name));
4440}
4441
[email protected]310ebd6302011-10-10 19:06:284442void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:124443 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:274444 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:124445 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
4446 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
4447 before_unload_start_time,
4448 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:294449}
4450
[email protected]310ebd6302011-10-10 19:06:284451void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]69ddf852012-02-21 23:21:314452 // Ensure that no other in-progress navigation continues.
4453 OnStop();
4454
[email protected]73eb2602012-02-09 19:50:554455 // Only run unload if we're not swapped out yet, but send the ack either way.
4456 if (!is_swapped_out_) {
4457 // Swap this RenderView out so the tab can navigate to a page rendered by a
4458 // different process. This involves running the unload handler and clearing
4459 // the page. Once WasSwappedOut is called, we also allow this process to
4460 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:154461
[email protected]73eb2602012-02-09 19:50:554462 // Send an UpdateState message before we get swapped out.
4463 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:154464
[email protected]73eb2602012-02-09 19:50:554465 // Synchronously run the unload handler before sending the ACK.
4466 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:154467
[email protected]73eb2602012-02-09 19:50:554468 // Swap out and stop sending any IPC messages that are not ACKs.
4469 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:154470
[email protected]285f4bb82012-04-17 15:57:284471 // Replace the page with a blank dummy URL. The unload handler will not be
[email protected]73eb2602012-02-09 19:50:554472 // run a second time, thanks to a check in FrameLoader::stopLoading.
[email protected]69ddf852012-02-21 23:21:314473 // We use loadRequest instead of loadHTMLString because the former commits
4474 // synchronously. Otherwise a new navigation can interrupt the navigation
[email protected]285f4bb82012-04-17 15:57:284475 // to content::kSwappedOutURL. If that happens to be to the page we had been
[email protected]69ddf852012-02-21 23:21:314476 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]73eb2602012-02-09 19:50:554477 // TODO(creis): Need to add a better way to do this that avoids running the
[email protected]285f4bb82012-04-17 15:57:284478 // beforeunload handler. For now, we just run it a second time silently.
4479 GURL swappedOutURL(content::kSwappedOutURL);
[email protected]58436a12012-03-21 17:10:264480 WebURLRequest request(swappedOutURL);
[email protected]69ddf852012-02-21 23:21:314481 webview()->mainFrame()->loadRequest(request);
[email protected]73eb2602012-02-09 19:50:554482 }
[email protected]992db4c2011-05-12 15:37:154483
4484 // Just echo back the params in the ACK.
4485 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
4486}
4487
[email protected]310ebd6302011-10-10 19:06:284488void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:374489 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:294490 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4491 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4492 // in the onunload handler from appearing. For now, we're bypassing that and
4493 // calling the FrameLoader's CloseURL method directly. This should be
4494 // revisited to avoid having two ways to close a page. Having a single way
4495 // to close that can run onunload is also useful for fixing
4496 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274497 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294498
[email protected]992db4c2011-05-12 15:37:154499 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:294500}
4501
[email protected]310ebd6302011-10-10 19:06:284502void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:024503#if defined(USE_AURA)
4504 // Aura doesn't care if we switch themes.
4505#elif defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:164506 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464507 if (webview())
4508 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574509#else // defined(OS_WIN)
4510 // TODO(port): we don't support theming on non-Windows platforms yet
4511 NOTIMPLEMENTED();
4512#endif
initial.commit09911bf2008-07-26 23:55:294513}
4514
[email protected]310ebd6302011-10-10 19:06:284515void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:084516 if (decrement_shared_popup_at_destruction_)
4517 shared_popup_counter_->data--;
4518 shared_popup_counter_ = new SharedRenderViewCounter(0);
4519 decrement_shared_popup_at_destruction_ = false;
4520}
4521
[email protected]310ebd6302011-10-10 19:06:284522bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
4523 const WebURLError& error,
4524 bool replace) {
[email protected]15d79e12009-08-02 19:23:454525 // We only show alternate error pages in the main frame. They are
4526 // intended to assist the user when navigating, so there is not much
4527 // value in showing them for failed subframes. Ideally, we would be
4528 // able to use the TYPED transition type for this, but that flag is
4529 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454530 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454531 return false;
4532
4533 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374534 // connection failure.
[email protected]15d79e12009-08-02 19:23:454535 int ec = error.reason;
4536 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4537 ec != net::ERR_CONNECTION_FAILED &&
4538 ec != net::ERR_CONNECTION_REFUSED &&
4539 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]82114f52012-03-20 22:53:414540 ec != net::ERR_CONNECTION_TIMED_OUT) {
[email protected]15d79e12009-08-02 19:23:454541 return false;
[email protected]82114f52012-03-20 22:53:414542 }
[email protected]15d79e12009-08-02 19:23:454543
4544 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554545 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454546 if (!error_page_url.is_valid())
4547 return false;
4548
4549 // Load an empty page first so there is an immediate response to the error,
4550 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454551 frame->loadHTMLString(std::string(),
[email protected]285f4bb82012-04-17 15:57:284552 GURL(content::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454553 error.unreachableURL,
4554 replace);
4555
4556 // Now, create a fetcher for the error page and associate it with the data
4557 // source we just created via the LoadHTMLString call. That way if another
4558 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:074559 DocumentState* document_state =
4560 DocumentState::FromDataSource(frame->provisionalDataSource());
4561 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:454562 new AltErrorPageResourceFetcher(
4563 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:084564 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4565 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:454566 return true;
4567}
4568
[email protected]310ebd6302011-10-10 19:06:284569void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
4570 const WebURLError& original_error,
4571 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:454572 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094573 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554574 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094575 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454576}
4577
[email protected]310ebd6302011-10-10 19:06:284578void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:004579 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474580 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004581}
4582
[email protected]310ebd6302011-10-10 19:06:284583void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:094584 const gfx::Rect& resizer_rect,
4585 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:104586 if (webview()) {
[email protected]7ddea9802012-02-22 23:08:054587 // This setting has no effect if fixed layout is not enabled.
[email protected]43d9d782012-03-01 15:40:094588 if (webkit_preferences_.default_device_scale_factor)
[email protected]7ddea9802012-02-22 23:08:054589 webview()->settings()->setLayoutFallbackWidth(
[email protected]43d9d782012-03-01 15:40:094590 new_size.width() / webkit_preferences_.default_device_scale_factor);
[email protected]a72a1fa2010-05-03 22:18:474591 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104592 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204593 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:314594 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104595 }
[email protected]dd6afca2011-08-13 03:44:314596 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:104597 }
4598
[email protected]ee41e7d22011-10-14 19:34:094599 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:004600}
[email protected]0aa477bd2009-03-23 22:21:434601
[email protected]29ed96a2012-02-04 18:12:164602void RenderViewImpl::WillInitiatePaint() {
4603 // Notify the pepper plugins that we're about to paint.
4604 pepper_delegate_.ViewWillInitiatePaint();
4605}
4606
[email protected]310ebd6302011-10-10 19:06:284607void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:164608 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]53900d52010-06-16 04:25:014609 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:284610}
4611
[email protected]310ebd6302011-10-10 19:06:284612void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:284613 // Notify any pepper plugins that we painted. This will call into the plugin,
4614 // and we it may ask to close itself as a result. This will, in turn, modify
4615 // our set, possibly invalidating the iterator. So we iterate on a copy that
4616 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014617 pepper_delegate_.ViewFlushedPaint();
4618
[email protected]5b1dec8c2012-02-07 04:35:384619 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
4620 // See crbug.com/112921.
4621 if (!webview())
4622 return;
4623
[email protected]00c39612010-03-06 02:53:284624 WebFrame* main_frame = webview()->mainFrame();
4625
4626 // If we have a provisional frame we are between the start and commit stages
4627 // of loading and we don't want to save stats.
4628 if (!main_frame->provisionalDataSource()) {
4629 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:074630 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:284631
[email protected]05c8e502010-08-15 15:13:524632 // TODO(jar): The following code should all be inside a method, probably in
4633 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284634 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:074635 if (document_state->first_paint_time().is_null()) {
4636 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:284637 }
[email protected]007733c2011-11-17 00:34:074638 if (document_state->first_paint_after_load_time().is_null() &&
4639 !document_state->finish_load_time().is_null()) {
4640 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:284641 }
4642 }
4643}
4644
[email protected]310ebd6302011-10-10 19:06:284645void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084646 RenderWidget::OnSwapBuffersPosted();
4647}
4648
[email protected]310ebd6302011-10-10 19:06:284649void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244650 RenderWidget::OnSwapBuffersComplete();
4651}
4652
[email protected]310ebd6302011-10-10 19:06:284653void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244654 RenderWidget::OnSwapBuffersAborted();
4655}
4656
[email protected]310ebd6302011-10-10 19:06:284657webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154658 const gfx::Rect& paint_bounds,
4659 TransportDIB** dib,
4660 gfx::Rect* location,
4661 gfx::Rect* clip) {
4662 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4663 paint_bounds, dib, location, clip);
4664}
4665
[email protected]310ebd6302011-10-10 19:06:284666gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074667 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434668 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524669}
4670
[email protected]310ebd6302011-10-10 19:06:284671void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164672 if (webview())
[email protected]26aa0482009-09-30 16:55:274673 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164674}
4675
[email protected]310ebd6302011-10-10 19:06:284676void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144677 if (webview())
[email protected]b4bb2502009-10-01 22:35:274678 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144679
4680 SetBackground(background);
4681}
4682
[email protected]310ebd6302011-10-10 19:06:284683void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:344684 if (webview())
[email protected]b4bb2502009-10-01 22:35:274685 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264686
4687#if defined(OS_MACOSX)
4688 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4689 for (plugin_it = plugin_delegates_.begin();
4690 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4691 (*plugin_it)->SetWindowFocus(active);
4692 }
4693#endif
[email protected]8c66c5a2009-07-22 17:26:344694}
4695
[email protected]7a17bac02012-03-07 21:58:124696void RenderViewImpl::OnSetNavigationStartTime(
4697 const base::TimeTicks& browser_navigation_start) {
4698 if (!webview())
4699 return;
4700
4701 // Only the initial navigation can be a cross-renderer navigation. If we've
4702 // already navigated away from that page, we can ignore this message.
4703 if (page_id_ != -1)
4704 return;
4705
4706 // browser_navigation_start is likely before this process existed, so we can't
4707 // use InterProcessTimeTicksConverter. Instead, the best we can do is just
4708 // ensure we don't report a bogus value in the future.
4709 base::TimeTicks navigation_start = std::min(base::TimeTicks::Now(),
4710 browser_navigation_start);
4711 webview()->mainFrame()->provisionalDataSource()->setNavigationStartTime(
4712 (navigation_start - base::TimeTicks()).InSecondsF());
4713}
4714
[email protected]6ce7abc52010-02-02 18:40:144715#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284716void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:144717 // Inform plugins that their container has changed visibility.
4718 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4719 for (plugin_it = plugin_delegates_.begin();
4720 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4721 (*plugin_it)->SetContainerVisibility(visible);
4722 }
4723}
[email protected]1e6e3c992010-02-08 15:52:134724
[email protected]310ebd6302011-10-10 19:06:284725void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
4726 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134727 // Inform plugins that their window's frame has changed.
4728 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4729 for (plugin_it = plugin_delegates_.begin();
4730 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4731 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4732 }
4733}
[email protected]935d63d2010-10-15 23:31:554734
[email protected]310ebd6302011-10-10 19:06:284735void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
4736 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134737 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554738 // applies to it or not, so inform all the delegates.
4739 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4740 for (plugin_it = plugin_delegates_.begin();
4741 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134742 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554743 }
4744}
[email protected]6ce7abc52010-02-02 18:40:144745#endif // OS_MACOSX
4746
[email protected]310ebd6302011-10-10 19:06:284747void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:484748 const EditCommands& edit_commands) {
4749 edit_commands_ = edit_commands;
4750}
4751
[email protected]310ebd6302011-10-10 19:06:284752void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:594753 // We need to grab a pointer to the doomed WebView before we destroy it.
4754 WebView* doomed = webview();
4755 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494756 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594757}
4758
[email protected]310ebd6302011-10-10 19:06:284759void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:484760 edit_commands_.clear();
4761}
4762
[email protected]310ebd6302011-10-10 19:06:284763bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]217690d2012-01-27 07:33:114764 pepper_delegate_.WillHandleMouseEvent();
4765
4766 // If the mouse is locked, only the current owner of the mouse lock can
4767 // process mouse events.
4768 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:374769}
4770
[email protected]2b942c332012-04-25 16:26:264771void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514772 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064773}
4774
[email protected]310ebd6302011-10-10 19:06:284775void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:244776 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
4777}
4778
[email protected]310ebd6302011-10-10 19:06:284779void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:434780 RenderWidget::OnWasHidden();
4781
[email protected]a6939ca42011-02-18 17:58:074782 if (webview()) {
4783 webview()->settings()->setMinimumTimerInterval(
4784 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444785 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074786 }
4787
[email protected]204f1df2012-01-04 20:21:134788 // Inform PPAPI plugins that their page is no longer visible.
4789 pepper_delegate_.PageVisibilityChanged(false);
4790
[email protected]a6939ca42011-02-18 17:58:074791#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134792 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:434793 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4794 for (plugin_it = plugin_delegates_.begin();
4795 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4796 (*plugin_it)->SetContainerVisibility(false);
4797 }
[email protected]a6939ca42011-02-18 17:58:074798#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434799}
4800
[email protected]310ebd6302011-10-10 19:06:284801void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:434802 RenderWidget::OnWasRestored(needs_repainting);
4803
[email protected]a6939ca42011-02-18 17:58:074804 if (webview()) {
4805 webview()->settings()->setMinimumTimerInterval(
4806 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444807 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074808 }
4809
[email protected]204f1df2012-01-04 20:21:134810 // Inform PPAPI plugins that their page is visible.
4811 pepper_delegate_.PageVisibilityChanged(true);
4812
[email protected]a6939ca42011-02-18 17:58:074813#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134814 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:434815 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4816 for (plugin_it = plugin_delegates_.begin();
4817 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4818 (*plugin_it)->SetContainerVisibility(true);
4819 }
[email protected]784ea1ab2010-09-18 00:02:344820#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074821}
[email protected]1e6e3c992010-02-08 15:52:134822
[email protected]310ebd6302011-10-10 19:06:284823bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:384824 if (WebWidgetHandlesCompositorScheduling())
4825 return false;
4826
[email protected]05a980d7a2012-02-07 22:16:424827 if (queried_for_swapbuffers_complete_callback_)
4828 return context_has_swapbuffers_complete_callback_;
4829
4830 queried_for_swapbuffers_complete_callback_ = true;
4831
[email protected]65225772011-05-12 21:10:244832 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
[email protected]05a980d7a2012-02-07 22:16:424833 if (context && context->makeContextCurrent()) {
4834 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4835 context_has_swapbuffers_complete_callback_ =
4836 extensions.find("GL_CHROMIUM_swapbuffers_complete_callback")
4837 != std::string::npos;
4838 }
4839
4840 return context_has_swapbuffers_complete_callback_;
[email protected]65225772011-05-12 21:10:244841}
4842
[email protected]310ebd6302011-10-10 19:06:284843void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:134844 RenderWidget::OnSetFocus(enable);
4845
[email protected]7d3c02c2010-05-05 23:10:314846 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074847 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134848 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4849 for (plugin_it = plugin_delegates_.begin();
4850 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344851#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314852 // RenderWidget's call to setFocus can cause the underlying webview's
4853 // activation state to change just like a call to setIsActive.
4854 if (enable)
4855 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344856#endif
[email protected]7d3c02c2010-05-05 23:10:314857 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134858 }
[email protected]589621b2010-09-23 22:01:074859
4860 // Notify all Pepper plugins.
4861 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134862 }
4863}
[email protected]941e4552010-02-01 21:23:434864
[email protected]310ebd6302011-10-10 19:06:284865void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:004866 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:504867 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:574868}
4869
[email protected]73bf95812011-10-12 11:38:324870void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:004871 UpdateTextInputState();
[email protected]73bf95812011-10-12 11:38:324872}
4873
[email protected]3f783362011-10-21 22:40:504874void RenderViewImpl::PpapiPluginCaretPositionChanged() {
4875 UpdateSelectionBounds();
4876}
4877
[email protected]b25b3ee2012-01-13 05:19:544878bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
4879 if (!pepper_delegate_.IsPluginFocused())
4880 return false;
4881 *rect = pepper_delegate_.GetCaretBounds();
4882 return true;
4883}
4884
[email protected]73bf95812011-10-12 11:38:324885void RenderViewImpl::PpapiPluginCancelComposition() {
4886 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
4887 ui::Range range(ui::Range::InvalidRange());
4888 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
4889}
4890
[email protected]3c8c74c2012-03-15 07:34:524891void RenderViewImpl::PpapiPluginSelectionChanged() {
4892 SyncSelectionIfRequired();
4893}
4894
[email protected]310ebd6302011-10-10 19:06:284895void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:574896 const string16& text,
4897 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4898 int selection_start,
4899 int selection_end) {
[email protected]73bf95812011-10-12 11:38:324900 if (pepper_delegate_.IsPluginFocused()) {
4901 // When a PPAPI plugin has focus, we bypass WebKit.
4902 pepper_delegate_.OnImeSetComposition(text,
4903 underlines,
4904 selection_start,
4905 selection_end);
4906 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234907#if defined(OS_WIN)
4908 // When a plug-in has focus, we create platform-specific IME data used by
4909 // our IME emulator and send it directly to the focused plug-in, i.e. we
4910 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4911 // instance ID is the same one as the specified ID.)
4912 if (focused_plugin_id_ >= 0) {
4913 std::vector<int> clauses;
4914 std::vector<int> target;
4915 for (size_t i = 0; i < underlines.size(); ++i) {
4916 clauses.push_back(underlines[i].startOffset);
4917 clauses.push_back(underlines[i].endOffset);
4918 if (underlines[i].thick) {
4919 target.clear();
4920 target.push_back(underlines[i].startOffset);
4921 target.push_back(underlines[i].endOffset);
4922 }
4923 }
4924 std::set<WebPluginDelegateProxy*>::iterator it;
4925 for (it = plugin_delegates_.begin();
4926 it != plugin_delegates_.end(); ++it) {
4927 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4928 focused_plugin_id_);
4929 }
4930 return;
4931 }
4932#endif
[email protected]56ea1a62011-05-30 07:05:574933 RenderWidget::OnImeSetComposition(text,
4934 underlines,
4935 selection_start,
4936 selection_end);
4937 }
4938}
4939
[email protected]4de6d1692011-10-12 08:45:444940void RenderViewImpl::OnImeConfirmComposition(
4941 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:574942 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:324943 // When a PPAPI plugin has focus, we bypass WebKit.
4944 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:574945 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234946#if defined(OS_WIN)
4947 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4948 // plug-ins. When we send IME text directly to plug-ins, we should not send
4949 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:444950 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:234951 if (focused_plugin_id_ >= 0) {
4952 std::set<WebPluginDelegateProxy*>::iterator it;
4953 for (it = plugin_delegates_.begin();
4954 it != plugin_delegates_.end(); ++it) {
4955 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4956 }
4957 return;
4958 }
4959#endif
[email protected]ebd28ac2011-10-13 18:49:054960 if (replacement_range.IsValid() && webview()) {
4961 // Select the text in |replacement_range|, it will then be replaced by
4962 // text added by the call to RenderWidget::OnImeConfirmComposition().
4963 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:164964 WebRange webrange = WebRange::fromDocumentRange(
4965 frame, replacement_range.start(), replacement_range.length());
4966 if (!webrange.isNull())
4967 frame->setSelectionToRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:054968 }
4969 }
[email protected]4de6d1692011-10-12 08:45:444970 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:574971 }
4972}
4973
[email protected]310ebd6302011-10-10 19:06:284974ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:324975 return pepper_delegate_.IsPluginFocused() ?
4976 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
4977}
4978
[email protected]3f783362011-10-21 22:40:504979void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
4980 if (pepper_delegate_.IsPluginFocused()) {
4981 // TODO(kinaba) http://crbug.com/101101
4982 // Current Pepper IME API does not handle selection bounds. So we simply
4983 // use the caret position as an empty range for now. It will be updated
4984 // after Pepper API equips features related to surrounding text retrieval.
4985 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
4986 *start = caret;
4987 *end = caret;
4988 return;
4989 }
4990 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:454991}
4992
[email protected]310ebd6302011-10-10 19:06:284993bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:324994 return pepper_delegate_.IsPluginFocused() ?
4995 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:574996}
4997
[email protected]e6ae0f6c2011-10-04 10:39:234998#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:284999void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:235000 if (focused)
5001 focused_plugin_id_ = plugin_id;
5002 else
5003 focused_plugin_id_ = -1;
5004}
5005#endif
5006
[email protected]43f28f832010-02-03 02:28:485007#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285008void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]82114f52012-03-20 22:53:415009 Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
[email protected]b7f75862011-01-21 21:15:135010}
5011
[email protected]310ebd6302011-10-10 19:06:285012void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:135013 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:555014 // This message can be sent during event-handling, and needs to be delivered
5015 // within that context.
5016 msg->set_unblock(true);
5017 Send(msg);
5018}
5019
[email protected]310ebd6302011-10-10 19:06:285020gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235021 bool opaque, bool root) {
[email protected]b2968292012-03-28 01:35:515022 gfx::PluginWindowHandle window = gfx::kNullPluginWindow;
[email protected]43f28f832010-02-03 02:28:485023 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235024 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:115025 if (window) {
5026 fake_plugin_window_handles_.insert(window);
5027 }
[email protected]43f28f832010-02-03 02:28:485028 return window;
5029}
5030
[email protected]310ebd6302011-10-10 19:06:285031void RenderViewImpl::DestroyFakePluginWindowHandle(
5032 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:115033 if (window && fake_plugin_window_handles_.find(window) !=
5034 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:485035 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:115036 fake_plugin_window_handles_.erase(window);
5037 }
[email protected]43f28f832010-02-03 02:28:485038}
5039
[email protected]310ebd6302011-10-10 19:06:285040void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
5041 gfx::PluginWindowHandle window,
5042 int32 width,
5043 int32 height,
5044 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:335045 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485046 routing_id(), window, width, height, io_surface_identifier));
5047}
5048
[email protected]310ebd6302011-10-10 19:06:285049void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:335050 gfx::PluginWindowHandle window,
5051 int32 width,
5052 int32 height,
5053 TransportDIB::Handle transport_dib) {
5054 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075055 routing_id(), window, width, height, transport_dib));
5056}
5057
[email protected]310ebd6302011-10-10 19:06:285058TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:335059 size_t size) {
[email protected]1aef98132010-02-23 18:00:075060 TransportDIB::Handle dib_handle;
5061 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385062 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075063 return dib_handle;
5064 // Return an invalid handle if Send() fails.
5065 return TransportDIB::DefaultHandleValue();
5066}
5067
[email protected]310ebd6302011-10-10 19:06:285068void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
5069 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075070 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5071}
5072
[email protected]310ebd6302011-10-10 19:06:285073void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:325074 gfx::PluginWindowHandle window, uint64 surface_handle) {
[email protected]f35d6672010-10-28 21:39:145075 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:325076 routing_id(), window, surface_handle));
[email protected]43f28f832010-02-03 02:28:485077}
[email protected]82114f52012-03-20 22:53:415078#endif // defined(OS_MACOSX)
[email protected]58c321d2010-02-19 12:11:285079
[email protected]310ebd6302011-10-10 19:06:285080bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:235081 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:475082 WebFileChooserCompletion* completion) {
5083 static const size_t kMaximumPendingFileChooseRequests = 4;
5084 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5085 // This sanity check prevents too many file choose requests from getting
5086 // queued which could DoS the user. Getting these is most likely a
5087 // programming error (there are many ways to DoS the user so it's not
5088 // considered a "real" security check), either in JS requesting many file
5089 // choosers to pop up, or in a plugin.
5090 //
5091 // TODO(brettw) we might possibly want to require a user gesture to open
5092 // a file picker, which will address this issue in a better way.
5093 return false;
5094 }
5095
5096 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5097 new PendingFileChooser(params, completion)));
5098 if (file_chooser_completions_.size() == 1) {
5099 // Actually show the browse dialog when this is the first request.
5100 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5101 }
5102 return true;
5103}
5104
[email protected]310ebd6302011-10-10 19:06:285105WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:515106 if (!geolocation_dispatcher_)
5107 geolocation_dispatcher_ = new GeolocationDispatcher(this);
5108 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:255109}
[email protected]61c9f032010-03-31 23:04:195110
[email protected]310ebd6302011-10-10 19:06:285111WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:115112 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:225113#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:025114 if (!input_tag_speech_dispatcher_)
5115 input_tag_speech_dispatcher_ =
5116 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:225117#endif
[email protected]c52b2892012-03-07 11:01:025118 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:115119}
5120
[email protected]310ebd6302011-10-10 19:06:285121WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:515122 if (!device_orientation_dispatcher_)
5123 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
5124 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:535125}
5126
[email protected]310ebd6302011-10-10 19:06:285127void RenderViewImpl::zoomLimitsChanged(double minimum_level,
5128 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:255129 // For now, don't remember plugin zoom values. We don't want to mix them with
5130 // normal web content (i.e. a fixed layout plugin would usually want them
5131 // different).
5132 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5133
[email protected]b75b8292010-10-01 07:28:255134 int minimum_percent = static_cast<int>(
5135 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5136 int maximum_percent = static_cast<int>(
5137 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255138
5139 Send(new ViewHostMsg_UpdateZoomLimits(
5140 routing_id_, minimum_percent, maximum_percent, remember));
5141}
5142
[email protected]310ebd6302011-10-10 19:06:285143void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:255144 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:085145 float zoom_level = webview()->zoomLevel();
[email protected]2b942c332012-04-25 16:26:265146
5147 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
5148
[email protected]b75b8292010-10-01 07:28:255149 // Tell the browser which url got zoomed so it can update the menu and the
5150 // saved values if necessary
5151 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:085152 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:415153 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:255154}
5155
[email protected]310ebd6302011-10-10 19:06:285156void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
5157 const WebString& base_url,
5158 const WebString& url,
5159 const WebString& title) {
[email protected]a6d36cc2011-02-23 00:39:485160 GURL base(base_url);
5161 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
5162 if (base.GetOrigin() != absolute_url.GetOrigin()) {
5163 return;
5164 }
[email protected]f1a29a02011-10-06 23:08:445165 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
5166 UTF16ToUTF8(scheme),
5167 absolute_url,
5168 title));
[email protected]a6d36cc2011-02-23 00:39:485169}
5170
[email protected]310ebd6302011-10-10 19:06:285171WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:445172 WebKit::WebPageVisibilityState current_state = is_hidden() ?
5173 WebKit::WebPageVisibilityStateHidden :
5174 WebKit::WebPageVisibilityStateVisible;
5175 WebKit::WebPageVisibilityState override_state = current_state;
5176 if (content::GetContentClient()->renderer()->
5177 ShouldOverridePageVisibilityState(this,
5178 &override_state))
5179 return override_state;
5180 return current_state;
[email protected]94dec932011-05-26 20:04:215181}
5182
[email protected]273558fb2012-01-12 15:03:515183WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
[email protected]273558fb2012-01-12 15:03:515184 EnsureMediaStreamImpl();
5185 return media_stream_impl_;
5186}
5187
[email protected]310ebd6302011-10-10 19:06:285188bool RenderViewImpl::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195189 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455190 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195191 if (frame->parent() != NULL)
5192 return false;
5193
[email protected]f0a3d0b2010-08-06 22:51:535194 // Navigations initiated within Webkit are not sent out to the external host
5195 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275196 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:135197 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535198 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:135199 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:335200 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:535201 return false;
5202
[email protected]2fc22d12010-12-02 23:08:165203 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:325204 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015205 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:165206 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:015207 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325208 // The opener relationship between the new window and the parent allows the
5209 // new window to script the parent and vice versa. This is not allowed if
5210 // the origins of the two domains are different. This can be treated as a
5211 // top level navigation and routed back to the host.
5212 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275213 if (!opener) {
[email protected]86965362011-04-21 18:42:515214 return true;
[email protected]d19ea342011-04-20 20:31:135215 } else {
[email protected]b6cb3a842011-06-24 18:28:415216 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:325217 return true;
5218 }
5219 }
[email protected]61c9f032010-03-31 23:04:195220 return false;
5221}
[email protected]2b06a992010-08-21 05:48:225222
[email protected]310ebd6302011-10-10 19:06:285223void RenderViewImpl::OnAsyncFileOpened(
5224 base::PlatformFileError error_code,
5225 IPC::PlatformFileForTransit file_for_transit,
5226 int message_id) {
[email protected]27a9ef32010-09-10 04:06:245227 pepper_delegate_.OnAsyncFileOpened(
5228 error_code,
5229 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5230 message_id);
5231}
[email protected]caf706f2010-10-26 17:54:085232
[email protected]310ebd6302011-10-10 19:06:285233void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:475234 int request_id,
5235 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:435236 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:475237 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
5238 broker_process_handle,
5239 handle);
[email protected]eb415bf0e2011-04-14 02:45:425240}
5241
[email protected]caf706f2010-10-26 17:54:085242#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285243void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155244 if (external_popup_menu_ == NULL) {
5245 // Crash reports from the field indicate that we can be notified with a
5246 // NULL external popup menu (we probably get notified twice).
5247 // If you hit this please file a bug against jcivelli and include the page
5248 // and steps to repro.
5249 NOTREACHED();
5250 return;
5251 }
[email protected]caf706f2010-10-26 17:54:085252 external_popup_menu_->DidSelectItem(selected_index);
5253 external_popup_menu_.reset();
5254}
5255#endif
[email protected]bb461532010-11-26 21:50:235256
[email protected]310ebd6302011-10-10 19:06:285257void RenderViewImpl::OnContextMenuClosed(
[email protected]35be7ec2012-02-12 20:42:515258 const content::CustomContextMenuContext& custom_context) {
[email protected]b29aa74b2011-01-31 21:41:085259 if (custom_context.is_pepper_menu)
5260 pepper_delegate_.OnContextMenuClosed(custom_context);
5261 else
5262 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:105263}
[email protected]5a7b15a2011-08-22 22:48:185264
[email protected]310ebd6302011-10-10 19:06:285265void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:185266 if (!webview())
5267 return;
5268 WebFrame* main_frame = webview()->mainFrame();
5269 if (!main_frame)
5270 return;
5271 main_frame->enableViewSourceMode(true);
5272}
[email protected]67bfb83f2011-09-22 03:36:375273
[email protected]310ebd6302011-10-10 19:06:285274bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:085275 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:405276}
[email protected]7f3c7af2011-10-20 22:52:515277
[email protected]64d0e192011-12-09 14:44:205278void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7f3c7af2011-10-20 22:52:515279 DCHECK(!java_bridge_dispatcher_.get());
[email protected]464750f2011-10-24 23:16:185280#if defined(ENABLE_JAVA_BRIDGE)
[email protected]64d0e192011-12-09 14:44:205281 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this));
[email protected]464750f2011-10-24 23:16:185282#endif
[email protected]7f3c7af2011-10-20 22:52:515283}