blob: b1bb19881010df4c0c336b5989971a85fbd9297b [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]778574e2011-03-21 22:03:5041#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2142#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4843#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2944#include "content/public/common/content_switches.h"
[email protected]35be7ec2012-02-12 20:42:5145#include "content/public/common/context_menu_params.h"
[email protected]8caadeb2011-11-22 02:45:2346#include "content/public/common/file_chooser_params.h"
[email protected]fb11b6a42012-03-14 07:25:1247#include "content/public/common/selected_file_info.h"
[email protected]a1d29162011-10-14 17:14:0348#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3449#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0750#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3251#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4452#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3653#include "content/public/renderer/render_view_visitor.h"
[email protected]230b7ef2011-03-16 22:30:1954#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0255#include "content/renderer/devtools_agent.h"
[email protected]766a7082012-02-03 23:39:1556#include "content/renderer/dom_automation_controller.h"
[email protected]55722152011-03-22 01:33:5357#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1958#include "content/renderer/geolocation_dispatcher.h"
[email protected]84a83e192012-03-09 18:43:4059#include "content/renderer/gpu/compositor_thread.h"
[email protected]1784b2f2011-11-24 10:53:4860#include "content/renderer/idle_user_detector.h"
[email protected]c52b2892012-03-07 11:01:0261#include "content/renderer/input_tag_speech_dispatcher.h"
[email protected]07161902011-11-11 09:57:4262#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0263#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0864#include "content/renderer/media/audio_message_filter.h"
[email protected]ccc70d8e2011-03-16 20:40:3765#include "content/renderer/media/audio_renderer_impl.h"
[email protected]273558fb2012-01-12 15:03:5166#include "content/renderer/media/media_stream_dependency_factory.h"
67#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:4068#include "content/renderer/media/media_stream_impl.h"
[email protected]6048d512012-01-28 03:14:4869#include "content/renderer/media/render_audiosourceprovider.h"
[email protected]090f7312011-08-05 23:26:4070#include "content/renderer/media/render_media_log.h"
[email protected]6048d512012-01-28 03:14:4871#include "content/renderer/media/renderer_gpu_video_decoder_factories.h"
[email protected]4a19be92011-09-22 14:25:0272#include "content/renderer/mhtml_generator.h"
[email protected]217690d2012-01-27 07:33:1173#include "content/renderer/mouse_lock_dispatcher.h"
[email protected]230b7ef2011-03-16 22:30:1974#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3775#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3576#include "content/renderer/plugin_channel_host.h"
[email protected]0361b942012-03-14 06:42:5377#include "content/renderer/browser_plugin/browser_plugin_constants.h"
78#include "content/renderer/browser_plugin/browser_plugin_placeholder.h"
[email protected]8704f89b2011-04-15 00:30:0579#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4480#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4481#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3282#include "content/renderer/renderer_accessibility.h"
[email protected]663bd9e2011-03-21 01:07:0183#include "content/renderer/renderer_webapplicationcachehost_impl.h"
84#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]86a7d3c2011-09-12 16:45:3285#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:1986#include "content/renderer/v8_value_converter_impl.h"
[email protected]0a35efc2012-03-13 17:28:1387#include "content/renderer/web_intents_host.h"
[email protected]663bd9e2011-03-21 01:07:0188#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3589#include "content/renderer/webplugin_delegate_proxy.h"
90#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4991#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4192#include "media/base/media_switches.h"
[email protected]b80322902012-03-06 01:33:5093#include "media/base/message_loop_factory.h"
[email protected]e1d69d762011-12-13 05:12:1894#include "media/filters/gpu_video_decoder.h"
initial.commit09911bf2008-07-26 23:55:2995#include "net/base/escape.h"
96#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:0497#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:5798#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:3799#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]8bd0fe62011-01-17 06:44:37100#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:37101#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:37102#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
103#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:37104#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
105#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
106#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
107#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
108#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]8bd0fe62011-01-17 06:44:37109#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37110#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57111#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58112#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
[email protected]592e20b2012-01-20 05:53:44113#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
[email protected]8b5af492011-11-28 21:50:58114#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14115#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:37116#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19117#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37118#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36119#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37120#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37123#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37124#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
125#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17127#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37128#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]8bd0fe62011-01-17 06:44:37129#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40130#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51131#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08132#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
133#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
134#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
135#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
136#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
137#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
[email protected]273558fb2012-01-12 15:03:51138#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
139#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
[email protected]9c4bf232011-12-15 02:25:08140#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
141#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
142#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]e6e90dc2011-12-03 00:01:37143#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
144#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
145#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
146#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
147#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
148#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26149#include "third_party/skia/include/core/SkBitmap.h"
[email protected]269f86d2011-12-07 02:43:47150#include "ui/base/javascript_message_type.h"
[email protected]08397d52011-02-05 01:53:38151#include "ui/gfx/native_widget_types.h"
152#include "ui/gfx/point.h"
153#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55154#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04155#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]9c4bf232011-12-15 02:25:08156#include "webkit/forms/form_data.h"
157#include "webkit/forms/form_field.h"
158#include "webkit/forms/password_form_dom_manager.h"
[email protected]25e18f82010-10-27 16:38:43159#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]18d5be92011-07-25 18:00:19160#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24161#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:29162#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07163#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29164#include "webkit/glue/webkit_glue.h"
[email protected]b00ba702011-08-17 01:41:03165#include "webkit/glue/weburlloader_impl.h"
[email protected]b9fd01ba2012-02-28 01:50:40166#include "webkit/glue/weburlresponse_extradata_impl.h"
[email protected]7e8b4d12012-01-20 23:39:51167#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
[email protected]a9288f52011-11-17 05:18:16168#include "webkit/media/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50169#include "webkit/plugins/npapi/plugin_list.h"
170#include "webkit/plugins/npapi/webplugin_delegate.h"
171#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
172#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52173#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29174
[email protected]6c8afae52009-01-22 02:24:57175#if defined(OS_WIN)
176// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57177// * theming
[email protected]08397d52011-02-05 01:53:38178#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03179#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37180#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51181#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33182#elif defined(OS_MACOSX)
183#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57184#endif
185
[email protected]9892b472010-09-16 00:23:42186using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08187using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21188using WebKit::WebApplicationCacheHost;
189using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26190using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41191using WebKit::WebColor;
192using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59193using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44194using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51195using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55196using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28197using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00198using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58199using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25200using WebKit::WebDragOperation;
201using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51202using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51203using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08204using WebKit::WebExternalPopupMenu;
205using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47206using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22207using WebKit::WebFileSystem;
208using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49209using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59210using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48211using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45212using WebKit::WebFrame;
[email protected]7e8b4d12012-01-20 23:39:51213using WebKit::WebGraphicsContext3D;
[email protected]ca948a22009-06-25 19:36:17214using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13215using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41216using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50217using WebKit::WebInputElement;
[email protected]ffc8bed2012-01-21 01:23:15218using WebKit::WebIntentRequest;
219using WebKit::WebIntentServiceInfo;
[email protected]3d9689372009-09-10 04:29:17220using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28221using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17222using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28223using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28224using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51225using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19226using WebKit::WebPageSerializer;
227using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17228using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36229using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40230using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49231using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09232using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52233using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59234using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51235using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52236using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15237using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40238using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35239using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29240using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17241using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59242using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42243using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02244using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34245using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40246using WebKit::WebStorageQuotaCallbacks;
247using WebKit::WebStorageQuotaError;
248using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28249using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51250using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52251using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24252using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28253using WebKit::WebURL;
254using WebKit::WebURLError;
255using WebKit::WebURLRequest;
256using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28257using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03258using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28259using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26260using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26261using appcache::WebApplicationCacheHostImpl;
262using base::Time;
263using base::TimeDelta;
[email protected]007733c2011-11-17 00:34:07264using content::DocumentState;
[email protected]82ddba1c2011-10-04 00:15:32265using content::NavigationState;
[email protected]380244092011-10-07 17:26:27266using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44267using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36268using content::RenderViewVisitor;
[email protected]445e1042011-12-03 21:03:15269using content::Referrer;
[email protected]8d86f13d2011-10-04 17:01:19270using content::V8ValueConverter;
[email protected]9c4bf232011-12-15 02:25:08271using webkit::forms::FormField;
272using webkit::forms::PasswordForm;
273using webkit::forms::PasswordFormDomManager;
[email protected]6fdd4182010-10-14 23:59:26274using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23275using webkit_glue::ResourceFetcher;
[email protected]b9fd01ba2012-02-28 01:50:40276using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33277
initial.commit09911bf2008-07-26 23:55:29278//-----------------------------------------------------------------------------
279
[email protected]310ebd6302011-10-10 19:06:28280typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49281static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02282
[email protected]882daa92009-11-05 16:31:31283// Time, in seconds, we delay before sending content state changes (such as form
284// state and scroll position) to the browser. We delay sending changes to avoid
285// spamming the browser.
286// To avoid having tab/session restore require sending a message to get the
287// current content state during tab closing we use a shorter timeout for the
288// foreground renderer. This means there is a small window of time from which
289// content state is modified and not sent to session restore, but this is
290// better than having to wake up all renderers during shutdown.
291static const int kDelaySecondsForContentStateSyncHidden = 5;
292static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29293
[email protected]e99ef6f2011-10-16 01:13:00294static const size_t kExtraCharsBeforeAndAfterSelection = 100;
295
[email protected]0aa55312008-10-17 21:53:08296// The maximum number of popups that can be spawned from one page.
297static const int kMaximumNumberOfUnacknowledgedPopups = 25;
298
[email protected]c514d6372011-08-16 22:54:44299static const float kScalingIncrement = 0.1f;
300
[email protected]47578fa02011-11-02 19:34:41301static const float kScalingIncrementForGesture = 0.01f;
302
[email protected]726985e22009-06-18 21:09:28303static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
304 WebVector<WebURL> urls;
305 ds->redirectChain(urls);
306 result->reserve(urls.size());
307 for (size_t i = 0; i < urls.size(); ++i)
308 result->push_back(urls[i]);
309}
310
[email protected]007733c2011-11-17 00:34:07311// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44312// the AltErrorPageResourceFetcher is reset.
313static void StopAltErrorPageFetcher(WebDataSource* data_source) {
314 if (data_source) {
[email protected]007733c2011-11-17 00:34:07315 DocumentState* document_state = DocumentState::FromDataSource(data_source);
316 if (document_state)
317 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44318 }
319}
320
[email protected]007733c2011-11-17 00:34:07321static bool IsReload(const ViewMsg_Navigate_Params& params) {
322 return
323 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
324 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
325}
326
[email protected]b9fd01ba2012-02-28 01:50:40327static WebReferrerPolicy GetReferrerPolicyFromRequest(
[email protected]445e1042011-12-03 21:03:15328 const WebURLRequest& request) {
329 return request.extraData() ?
330 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
331 WebKit::WebReferrerPolicyDefault;
332}
333
[email protected]b9fd01ba2012-02-28 01:50:40334static WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
335 const WebURLResponse& response) {
336 return static_cast<WebURLResponseExtraDataImpl*>(
337 response.extraData());
338}
339
[email protected]2149cc622012-02-14 01:12:12340NOINLINE static void CrashIntentionally() {
341 // NOTE(shess): Crash directly rather than using NOTREACHED() so
342 // that the signature is easier to triage in crash reports.
343 volatile int* zero = NULL;
344 *zero = 0;
345}
346
[email protected]8bf1048012012-02-08 01:22:18347static void MaybeHandleDebugURL(const GURL& url) {
348 if (!url.SchemeIs(chrome::kChromeUIScheme))
349 return;
350 if (url == GURL(chrome::kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12351 CrashIntentionally();
[email protected]8bf1048012012-02-08 01:22:18352 } else if (url == GURL(chrome::kChromeUIKillURL)) {
353 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
354 } else if (url == GURL(chrome::kChromeUIHangURL)) {
355 for (;;) {
356 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
357 }
358 } else if (url == GURL(chrome::kChromeUIShorthangURL)) {
359 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
360 }
361}
362
initial.commit09911bf2008-07-26 23:55:29363///////////////////////////////////////////////////////////////////////////////
364
[email protected]310ebd6302011-10-10 19:06:28365struct RenderViewImpl::PendingFileChooser {
[email protected]8caadeb2011-11-22 02:45:23366 PendingFileChooser(const content::FileChooserParams& p,
[email protected]cdaf8d02010-03-30 19:52:47367 WebFileChooserCompletion* c)
368 : params(p),
369 completion(c) {
370 }
[email protected]8caadeb2011-11-22 02:45:23371 content::FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47372 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
373};
374
[email protected]217690d2012-01-27 07:33:11375namespace {
376
377class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
378 public:
379 WebWidgetLockTarget (WebKit::WebWidget* webwidget)
380 : webwidget_(webwidget) {}
381
382 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
383 if (succeeded)
384 webwidget_->didAcquirePointerLock();
385 else
386 webwidget_->didNotAcquirePointerLock();
387 }
388
389 virtual void OnMouseLockLost() OVERRIDE {
390 webwidget_->didLosePointerLock();
391 }
392
393 virtual bool HandleMouseLockedInputEvent(
394 const WebKit::WebMouseEvent &event) OVERRIDE {
395 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
396 return false;
397 }
398
399 private:
400 WebKit::WebWidget* webwidget_;
401};
402
[email protected]86cd9472012-02-03 19:51:05403int64 ExtractPostId(const WebHistoryItem& item) {
404 if (item.isNull())
405 return -1;
406
407 if (item.httpBody().isNull())
408 return -1;
409
410 return item.httpBody().identifier();
411}
412
[email protected]217690d2012-01-27 07:33:11413} // namespace
414
[email protected]daf82f82011-10-31 22:35:31415RenderViewImpl::RenderViewImpl(
416 gfx::NativeViewId parent_hwnd,
417 int32 opener_id,
418 const content::RendererPreferences& renderer_prefs,
419 const WebPreferences& webkit_prefs,
420 SharedRenderViewCounter* counter,
421 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56422 int32 surface_id,
[email protected]daf82f82011-10-31 22:35:31423 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46424 const string16& frame_name,
[email protected]6fd35b72012-03-01 19:46:41425 int32 next_page_id,
426 const WebKit::WebScreenInfo& screen_info)
427 : RenderWidget(WebKit::WebPopupTypeNone, screen_info),
[email protected]676126f72011-01-15 00:03:51428 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02429 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09430 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02431 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24432 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21433 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02434 opened_by_user_gesture_(true),
435 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24436 page_id_(-1),
437 last_page_id_sent_to_browser_(-1),
[email protected]74ce1ad2011-12-16 21:51:46438 next_page_id_(next_page_id),
[email protected]3cc72b12010-03-18 23:03:00439 history_list_offset_(-1),
440 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02441 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55442 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31443 cached_is_main_frame_pinned_to_left_(false),
444 cached_is_main_frame_pinned_to_right_(false),
445 cached_has_main_frame_horizontal_scrollbar_(false),
446 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]05a980d7a2012-02-07 22:16:42447 context_has_swapbuffers_complete_callback_(false),
448 queried_for_swapbuffers_complete_callback_(false),
[email protected]d0fb8a72012-03-10 18:54:52449 context_is_web_graphics_context_3d_command_buffer_impl_(false),
[email protected]3354d3e2010-06-10 19:53:02450 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51451 geolocation_dispatcher_(NULL),
[email protected]c52b2892012-03-07 11:01:02452 input_tag_speech_dispatcher_(NULL),
[email protected]676126f72011-01-15 00:03:51453 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51454 media_stream_dispatcher_(NULL),
[email protected]cae8c8492011-03-03 11:12:18455 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41456 devtools_agent_(NULL),
[email protected]063afcb2011-09-29 07:54:32457 renderer_accessibility_(NULL),
[email protected]217690d2012-01-27 07:33:11458 mouse_lock_dispatcher_(NULL),
[email protected]4fb60142011-08-09 02:22:08459 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18460 handling_select_range_(false),
461#if defined(OS_WIN)
462 focused_plugin_id_(-1),
463#endif
464 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]676126f72011-01-15 00:03:51465 routing_id_ = routing_id;
[email protected]9f4f3322012-01-18 22:29:56466 surface_id_ = surface_id;
[email protected]676126f72011-01-15 00:03:51467 if (opener_id != MSG_ROUTING_NONE)
468 opener_id_ = opener_id;
469
[email protected]74ce1ad2011-12-16 21:51:46470 // Ensure we start with a valid next_page_id_ from the browser.
471 DCHECK_GE(next_page_id_, 0);
472
[email protected]21b3a6ae2011-11-30 00:45:29473#if defined(ENABLE_NOTIFICATIONS)
474 notification_provider_ = new NotificationProvider(this);
475#else
476 notification_provider_ = NULL;
477#endif
478
[email protected]11fee2332011-03-29 20:36:35479 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11480 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35481
[email protected]676126f72011-01-15 00:03:51482 if (counter) {
483 shared_popup_counter_ = counter;
484 shared_popup_counter_->data++;
485 decrement_shared_popup_at_destruction_ = true;
486 } else {
487 shared_popup_counter_ = new SharedRenderViewCounter(0);
488 decrement_shared_popup_at_destruction_ = false;
489 }
490
[email protected]380244092011-10-07 17:26:27491 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51492 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47493 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51494 AddRef();
495
496 // If this is a popup, we must wait for the CreatingNew_ACK message before
497 // completing initialization. Otherwise, we can finish it now.
498 if (opener_id == MSG_ROUTING_NONE) {
499 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55500 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51501 }
502
[email protected]34c61bd52011-05-02 19:38:33503 g_view_map.Get().insert(std::make_pair(webview(), this));
504 webkit_preferences_.Apply(webview());
505 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35506 if (!frame_name.empty())
507 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33508 webview()->settings()->setMinimumTimerInterval(
509 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
510 webkit_glue::kForegroundTabTimerInterval);
511
512 OnSetRendererPrefs(renderer_prefs);
513
[email protected]676126f72011-01-15 00:03:51514 host_window_ = parent_hwnd;
515
[email protected]a026daa2011-04-20 15:49:51516#if defined(ENABLE_P2P_APIS)
[email protected]273558fb2012-01-12 15:03:51517 if (!p2p_socket_dispatcher_)
518 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51519#endif
[email protected]cae8c8492011-03-03 11:12:18520
[email protected]5b87e782012-02-09 18:19:32521#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02522 if (!media_stream_dispatcher_)
523 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32524#endif
[email protected]735873d2012-01-25 23:31:02525
[email protected]8f6a3b852011-07-19 16:48:56526 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32527#if defined(OS_MACOSX)
528 new TextInputClientObserver(this);
529#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56530
[email protected]217690d2012-01-27 07:33:11531 // The next group of objects all implement RenderViewObserver, so are deleted
532 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41533 devtools_agent_ = new DevToolsAgent(this);
[email protected]063afcb2011-09-29 07:54:32534 renderer_accessibility_ = new RendererAccessibility(this);
[email protected]217690d2012-01-27 07:33:11535 mouse_lock_dispatcher_ = new MouseLockDispatcher(this);
[email protected]0fc7dea72012-02-09 03:47:40536 intents_host_ = new WebIntentsHost(this);
[email protected]063afcb2011-09-29 07:54:32537
[email protected]1784b2f2011-11-24 10:53:48538 new IdleUserDetector(this);
539
[email protected]766a7082012-02-03 23:39:15540 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
541 if (command_line.HasSwitch(switches::kDomAutomationController))
542 enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION;
543
[email protected]7ddea9802012-02-22 23:08:05544 bool enable_fixed_layout =
545 command_line.HasSwitch(switches::kEnableFixedLayout);
546 webview()->enableFixedLayoutMode(enable_fixed_layout);
547 if (enable_fixed_layout)
548 webview()->settings()->setFixedElementsLayoutRelativeToFrame(true);
[email protected]7ddea9802012-02-22 23:08:05549
[email protected]e48869a2011-04-01 19:56:03550 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29551}
552
[email protected]310ebd6302011-10-10 19:06:28553RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03554 history_page_ids_.clear();
555
[email protected]0aa55312008-10-17 21:53:08556 if (decrement_shared_popup_at_destruction_)
557 shared_popup_counter_->data--;
558
[email protected]a1128322009-10-06 18:38:46559 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47560 while (!file_chooser_completions_.empty()) {
561 if (file_chooser_completions_.front()->completion) {
562 file_chooser_completions_.front()->completion->didChooseFile(
563 WebVector<WebString>());
564 }
565 file_chooser_completions_.pop_front();
566 }
[email protected]a1128322009-10-06 18:38:46567
[email protected]83dde542009-09-11 20:59:55568#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11569 // Destroy all fake plugin window handles on the browser side.
570 while (!fake_plugin_window_handles_.empty()) {
571 // Make sure no NULL plugin window handles were inserted into this list.
572 DCHECK(*fake_plugin_window_handles_.begin());
573 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
574 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
575 }
[email protected]83dde542009-09-11 20:59:55576#endif
[email protected]98324892009-09-09 21:16:05577
[email protected]60c42a8c72009-10-09 04:08:59578#ifndef NDEBUG
579 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49580 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59581 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
582 DCHECK_NE(this, it->second) << "Failed to call Close?";
583#endif
[email protected]676126f72011-01-15 00:03:51584
[email protected]273558fb2012-01-12 15:03:51585 // MediaStreamImpl holds weak references to RenderViewObserver objects,
586 // ensure it's deleted before the observers.
587 media_stream_impl_ = NULL;
588
[email protected]310ebd6302011-10-10 19:06:28589 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51590 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59591}
592
593/*static*/
[email protected]310ebd6302011-10-10 19:06:28594RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31595 ViewMap* views = g_view_map.Pointer();
596 ViewMap::iterator it = views->find(webview);
597 return it == views->end() ? NULL : it->second;
598}
599
600/*static*/
601content::RenderView*
602 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28603 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31604}
605
606/*static*/
607void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49608 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59609 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
610 if (!visitor->Visit(it->second))
611 return;
612 }
613}
614
615/*static*/
[email protected]310ebd6302011-10-10 19:06:28616RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15617 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08618 int32 opener_id,
[email protected]daf82f82011-10-31 22:35:31619 const content::RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08620 const WebPreferences& webkit_prefs,
621 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34622 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56623 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26624 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46625 const string16& frame_name,
[email protected]6fd35b72012-03-01 19:46:41626 int32 next_page_id,
627 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29628 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28629 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51630 parent_hwnd,
631 opener_id,
632 renderer_prefs,
633 webkit_prefs,
634 counter,
635 routing_id,
[email protected]9f4f3322012-01-18 22:29:56636 surface_id,
[email protected]676126f72011-01-15 00:03:51637 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46638 frame_name,
[email protected]6fd35b72012-03-01 19:46:41639 next_page_id,
640 screen_info);
initial.commit09911bf2008-07-26 23:55:29641}
642
[email protected]273558fb2012-01-12 15:03:51643WebKit::WebPeerConnectionHandler* RenderViewImpl::CreatePeerConnectionHandler(
644 WebKit::WebPeerConnectionHandlerClient* client) {
645 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
646 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
647 return NULL;
648 EnsureMediaStreamImpl();
[email protected]5b87e782012-02-09 18:19:32649 if (!media_stream_impl_.get())
650 return NULL;
[email protected]273558fb2012-01-12 15:03:51651 return media_stream_impl_->CreatePeerConnectionHandler(client);
652}
653
[email protected]310ebd6302011-10-10 19:06:28654void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51655 observers_.AddObserver(observer);
656}
657
[email protected]310ebd6302011-10-10 19:06:28658void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
659 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51660 observers_.RemoveObserver(observer);
661}
662
[email protected]310ebd6302011-10-10 19:06:28663WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26664 return static_cast<WebKit::WebView*>(webwidget());
665}
666
[email protected]310ebd6302011-10-10 19:06:28667void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40668 if (!enabled) {
669 load_progress_tracker_.reset(NULL);
670 return;
671 }
672 if (load_progress_tracker_ == NULL)
673 load_progress_tracker_.reset(new LoadProgressTracker(this));
674}
675
[email protected]310ebd6302011-10-10 19:06:28676void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51677 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29678}
679
[email protected]310ebd6302011-10-10 19:06:28680void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26681 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30682 // If the renderer is visible, set initial visibility and focus state.
683 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34684#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30685 delegate->SetContainerVisibility(true);
686 if (webview() && webview()->isActive())
687 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34688#endif
[email protected]49232292010-09-03 19:07:30689 }
[email protected]784ea1ab2010-09-18 00:02:34690 // Plugins start assuming the content has focus (so that they work in
691 // environments where RenderView isn't hosting them), so we always have to
692 // set the initial state. See webplugin_delegate_impl.h for details.
693 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26694}
695
[email protected]310ebd6302011-10-10 19:06:28696void RenderViewImpl::UnregisterPluginDelegate(
697 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26698 plugin_delegates_.erase(delegate);
699}
[email protected]d8fd6fa2010-02-01 15:54:26700
[email protected]310ebd6302011-10-10 19:06:28701bool RenderViewImpl::GetPluginInfo(const GURL& url,
702 const GURL& page_url,
703 const std::string& mime_type,
704 webkit::WebPluginInfo* plugin_info,
705 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08706 bool found = false;
707 Send(new ViewHostMsg_GetPluginInfo(
708 routing_id_, url, page_url, mime_type, &found, plugin_info,
709 actual_mime_type));
710 return found;
711}
712
[email protected]310ebd6302011-10-10 19:06:28713bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27714 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27715 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41716 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26717
[email protected]676126f72011-01-15 00:03:51718 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
719 RenderViewObserver* observer;
720 while ((observer = it.GetNext()) != NULL)
721 if (observer->OnMessageReceived(message))
722 return true;
[email protected]b2abac72009-02-26 12:39:28723
[email protected]a95986a82010-12-24 06:19:28724 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40725 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28726 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29727 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
728 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56729 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29730 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
731 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
732 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
733 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27734#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35735 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27736#endif
initial.commit09911bf2008-07-26 23:55:29737 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15738 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29739 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
740 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
741 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08742 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29743 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15744 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29745 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49746 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
747 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17748 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17749 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41750 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54751 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
752 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29753 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18754 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
755 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29756 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48757 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55758 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
759 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
760 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
761 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
762 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
763 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
764 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45765 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40766 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29767 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19768 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
769 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29770 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
771 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
772 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51773 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
774 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29775 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04776 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15777 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29778 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
779 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08780 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
781 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00782 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16783 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14784 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25785 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
786 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:47787 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:34788 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:10789 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
790 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51791 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56792 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:36793 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:34794 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]7a17bac02012-03-07 21:58:12795 IPC_MESSAGE_HANDLER(ViewMsg_SetNavigationStartTime,
796 OnSetNavigationStartTime)
[email protected]6ce7abc52010-02-02 18:40:14797#if defined(OS_MACOSX)
798 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13799 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13800 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
801 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14802#endif
[email protected]446705872009-09-10 07:22:48803 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33804 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33805 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
806 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24807 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42808 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
809 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19810 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
811 OnGetAllSavableResourceLinksForCurrentPage)
812 IPC_MESSAGE_HANDLER(
813 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
814 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08815#if defined(OS_MACOSX)
816 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
817#endif
[email protected]521b2482011-01-15 00:10:10818 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51819 // TODO(viettrungluu): Move to a separate message filter.
820#if defined(ENABLE_FLAPPER_HACKS)
821 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
822#endif
[email protected]54ca3ca892011-06-07 21:14:54823#if defined(OS_MACOSX)
824 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
825#endif
[email protected]9e1ad4b2011-08-14 16:49:19826 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
827 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18828 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]7f3c7af2011-10-20 22:52:51829 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]9e1ad4b2011-08-14 16:49:19830
initial.commit09911bf2008-07-26 23:55:29831 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28832 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29833 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40834
835 if (!msg_is_ok) {
836 // The message had a handler, but its deserialization failed.
837 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:28838 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:40839 }
840
[email protected]a95986a82010-12-24 06:19:28841 return handled;
initial.commit09911bf2008-07-26 23:55:29842}
843
[email protected]310ebd6302011-10-10 19:06:28844void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]6dc7ff62012-03-15 06:16:13845#if defined(OS_CHROMEOS)
846 // crosbug.com/26646.
847 LOG(ERROR) << "OnNavigate: url=" << params.url
848 << ", webview=" << webview()
849 << ", reload=" << IsReload(params)
850 << ", paerams.state.empty=" << params.state.empty();
851#endif
[email protected]8bf1048012012-02-08 01:22:18852 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:29853 if (!webview())
854 return;
855
[email protected]440a0e52011-09-13 17:38:58856 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
857
[email protected]007733c2011-11-17 00:34:07858 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:03859
860 // If this is a stale back/forward (due to a recent navigation the browser
861 // didn't know about), ignore it.
862 if (IsBackForwardToStaleEntry(params, is_reload))
863 return;
864
[email protected]992db4c2011-05-12 15:37:15865 // Swap this renderer back in if necessary.
866 if (is_swapped_out_)
867 SetSwappedOut(false);
868
[email protected]3cc72b12010-03-18 23:03:00869 history_list_offset_ = params.current_history_list_offset;
870 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03871 if (history_list_length_ >= 0)
872 history_page_ids_.resize(history_list_length_, -1);
873 if (params.pending_history_list_offset >= 0 &&
874 params.pending_history_list_offset < history_list_length_)
875 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00876
[email protected]38b592902011-04-16 02:08:42877 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29878
[email protected]26aa0482009-09-30 16:55:27879 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45880 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29881 // We cannot reload if we do not have any history state. This happens, for
882 // example, when recovering from a crash. Our workaround here is a bit of
883 // a hack since it means that reload after a crashed tab does not cause an
884 // end-to-end cache validation.
885 is_reload = false;
886 }
887
[email protected]007733c2011-11-17 00:34:07888 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
889 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:50890
[email protected]04d3c6e2009-05-22 17:00:13891 // If we are reloading, then WebKit will use the history state of the current
892 // page, so we should just ignore any given history state. Otherwise, if we
893 // have history state, then we need to navigate to it, which corresponds to a
894 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55895 if (is_reload) {
[email protected]ecbf10d2010-02-18 13:03:29896 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02897 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29898 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55899 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13900 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58901 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45902 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17903 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13904 } else {
905 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28906 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29907
[email protected]e6f546c32009-07-01 17:12:55908 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:23909 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13910
[email protected]dd7daa82009-08-10 05:46:45911 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55912 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13913
[email protected]445e1042011-12-03 21:03:15914 if (params.referrer.url.is_valid()) {
915 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
916 params.referrer.policy,
917 params.url,
918 WebString::fromUTF8(params.referrer.url.spec()));
919 if (!referrer.isEmpty())
920 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:28921 }
[email protected]04d3c6e2009-05-22 17:00:13922
[email protected]52c68652010-12-07 17:47:04923 if (!params.extra_headers.empty()) {
924 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
925 params.extra_headers.end(), "\n");
926 i.GetNext(); ) {
927 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
928 WebString::fromUTF8(i.values()));
929 }
930 }
[email protected]6dc7ff62012-03-15 06:16:13931#if defined(OS_CHROMEOS)
932 // crosbug.com/26646.
933 LOG(ERROR) << " FrameLoader::loadRequest()";
934#endif
[email protected]dd7daa82009-08-10 05:46:45935 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50936 }
937
[email protected]77f17a82009-05-21 04:42:54938 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:07939 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:29940}
941
[email protected]310ebd6302011-10-10 19:06:28942bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:03943 const ViewMsg_Navigate_Params& params,
944 bool is_reload) {
945 // Make sure this isn't a back/forward to an entry we have already cropped
946 // or replaced from our history, before the browser knew about it. If so,
947 // a new navigation has committed in the mean time, and we can ignore this.
948 bool is_back_forward = !is_reload && !params.state.empty();
949
950 // Note: if the history_list_length_ is 0 for a back/forward, we must be
951 // restoring from a previous session. We'll update our state in OnNavigate.
952 if (!is_back_forward || history_list_length_ <= 0)
953 return false;
954
955 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
956
957 // Check for whether the forward history has been cropped due to a recent
958 // navigation the browser didn't know about.
959 if (params.pending_history_list_offset >= history_list_length_)
960 return true;
961
962 // Check for whether this entry has been replaced with a new one.
963 int expected_page_id =
964 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44965 if (expected_page_id > 0 && params.page_id != expected_page_id) {
966 if (params.page_id < expected_page_id)
967 return true;
968
969 // Otherwise we've removed an earlier entry and should have shifted all
970 // entries left. For now, it's ok to lazily update the list.
971 // TODO(creis): Notify all live renderers when we remove entries from
972 // the front of the list, so that we don't hit this case.
973 history_page_ids_[params.pending_history_list_offset] = params.page_id;
974 }
[email protected]d466b8a2011-07-15 21:48:03975
976 return false;
977}
978
initial.commit09911bf2008-07-26 23:55:29979// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:28980void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44981 if (webview()) {
982 WebFrame* main_frame = webview()->mainFrame();
983 // Stop the alt error page fetcher. If we let it continue it may complete
984 // and cause RenderViewHostManager to swap to this RenderView, even though
985 // it may no longer be active.
986 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
987 StopAltErrorPageFetcher(main_frame->dataSource());
988 main_frame->stopLoading();
989 }
initial.commit09911bf2008-07-26 23:55:29990}
991
[email protected]ecbf10d2010-02-18 13:03:29992// Reload current focused frame.
993// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:28994void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29995 if (webview() && webview()->focusedFrame()) {
996 // We always obey the cache (ignore_cache=false) here.
997 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
998 // a cache-ignoring reload of the frame.
999 webview()->focusedFrame()->reload(false);
1000 }
[email protected]1dda4022010-01-28 18:24:561001}
1002
[email protected]310ebd6302011-10-10 19:06:281003void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271004 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291005}
1006
[email protected]310ebd6302011-10-10 19:06:281007void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:251008 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271009 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251010 return;
1011
[email protected]26aa0482009-09-30 16:55:271012 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451013 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251014}
1015
[email protected]310ebd6302011-10-10 19:06:281016void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291017 // Check if there is a targeturl waiting to be sent.
1018 if (target_url_status_ == TARGET_PENDING) {
1019 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1020 pending_target_url_));
1021 }
1022
1023 target_url_status_ = TARGET_NONE;
1024}
1025
[email protected]310ebd6302011-10-10 19:06:281026void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:291027 if (!webview())
1028 return;
1029
[email protected]26aa0482009-09-30 16:55:271030 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:291031}
1032
[email protected]310ebd6302011-10-10 19:06:281033void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:291034 if (!webview())
1035 return;
1036
[email protected]26aa0482009-09-30 16:55:271037 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:291038}
1039
[email protected]310ebd6302011-10-10 19:06:281040void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:291041 if (!webview())
1042 return;
1043
[email protected]26aa0482009-09-30 16:55:271044 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:291045}
1046
[email protected]310ebd6302011-10-10 19:06:281047void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291048 if (!webview())
1049 return;
1050
[email protected]f6b1856b2011-06-29 22:02:531051 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
1052 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:291053}
1054
[email protected]c0cc3092009-09-12 08:27:271055#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281056void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:351057 if (!webview())
1058 return;
1059
1060 // Since the find pasteboard supports only plain text, this can be simpler
1061 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271062 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351063 if (frame->hasSelection()) {
1064 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:271065 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:171066 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:351067 }
[email protected]a954bf72009-09-12 07:30:351068}
[email protected]c0cc3092009-09-12 08:27:271069#endif
[email protected]a954bf72009-09-12 07:30:351070
[email protected]310ebd6302011-10-10 19:06:281071void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291072 if (!webview())
1073 return;
1074
[email protected]26aa0482009-09-30 16:55:271075 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:291076}
1077
[email protected]44bf7002011-10-16 02:46:151078void RenderViewImpl::OnPasteAndMatchStyle() {
1079 if (!webview())
1080 return;
1081
1082 webview()->focusedFrame()->executeCommand(
1083 WebString::fromUTF8("PasteAndMatchStyle"));
1084}
1085
[email protected]310ebd6302011-10-10 19:06:281086void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291087 if (!webview())
1088 return;
1089
[email protected]1ff7a032010-02-03 02:46:031090 WebFrame* frame = webview()->focusedFrame();
1091 if (!frame->hasSelection())
1092 frame->selectWordAroundCaret();
1093 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291094}
1095
[email protected]310ebd6302011-10-10 19:06:281096void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:291097 if (!webview())
1098 return;
1099
[email protected]26aa0482009-09-30 16:55:271100 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:291101}
1102
[email protected]310ebd6302011-10-10 19:06:281103void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291104 if (!webview())
1105 return;
1106
[email protected]26aa0482009-09-30 16:55:271107 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221108 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:291109}
1110
[email protected]310ebd6302011-10-10 19:06:281111void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1112 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:081113 if (!webview())
1114 return;
1115
1116 handling_select_range_ = true;
1117 webview()->focusedFrame()->selectRange(start, end);
1118 handling_select_range_ = false;
1119}
1120
[email protected]310ebd6302011-10-10 19:06:281121void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1122 int32 minimum_page_id) {
[email protected]9e1ad4b2011-08-14 16:49:191123 DCHECK(history_length >= 0);
1124 DCHECK(history_list_offset_ == history_list_length_ - 1);
1125 DCHECK(minimum_page_id >= -1);
1126
1127 // Generate the new list.
1128 std::vector<int32> new_history_page_ids(history_length, -1);
1129 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1130 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1131 continue;
1132 new_history_page_ids.push_back(history_page_ids_[i]);
1133 }
1134 new_history_page_ids.swap(history_page_ids_);
1135
1136 // Update indexes.
1137 history_list_length_ = history_page_ids_.size();
1138 history_list_offset_ = history_list_length_ - 1;
1139}
1140
1141
[email protected]310ebd6302011-10-10 19:06:281142void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291143 if (!webview())
1144 return;
[email protected]26aa0482009-09-30 16:55:271145 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291146}
1147
[email protected]54ca3ca892011-06-07 21:14:541148#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281149void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331150 if (!webview())
1151 return;
1152 if (in_live_resize)
1153 webview()->willStartLiveResize();
1154 else
1155 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541156}
1157#endif
1158
[email protected]310ebd6302011-10-10 19:06:281159void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1160 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091161 WebKit::WebNode node = GetFocusedNode();
1162 if (!node.isNull()) {
1163 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191164 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511165 }
1166}
1167
initial.commit09911bf2008-07-26 23:55:291168///////////////////////////////////////////////////////////////////////////////
1169
1170// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281171void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451172 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291173 DCHECK(ds);
1174
[email protected]726985e22009-06-18 21:09:281175 const WebURLRequest& request = ds->request();
1176 const WebURLRequest& original_request = ds->originalRequest();
1177 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291178
[email protected]007733c2011-11-17 00:34:071179 DocumentState* document_state = DocumentState::FromDataSource(ds);
1180 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291181
1182 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281183 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291184 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051185 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291186 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071187 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191188 params.socket_address.set_host(response.remoteIPAddress().utf8());
1189 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031190 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091191 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071192 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291193 // SSL state specified in the request takes precedence over the one in the
1194 // response.
1195 // So far this is only intended for error pages that are not expected to be
1196 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281197 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071198 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291199 } else {
[email protected]726985e22009-06-18 21:09:281200 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291201 }
1202
1203 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:311204 params.url = GetLoadingUrl(frame);
initial.commit09911bf2008-07-26 23:55:291205
[email protected]5f9b8712011-11-23 08:55:571206 if (frame->document().baseURL() != params.url)
1207 params.base_url = frame->document().baseURL();
1208
[email protected]726985e22009-06-18 21:09:281209 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241210 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041211 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291212
[email protected]007733c2011-11-17 00:34:071213 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351214 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071215 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291216
1217 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071218 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291219 if (password_form_data)
1220 params.password_form = *password_form_data;
1221
1222 params.gesture = navigation_gesture_;
1223 navigation_gesture_ = NavigationGestureUnknown;
1224
[email protected]0f38dc4552011-02-25 11:24:001225 // Make navigation state a part of the FrameNavigate message so that commited
1226 // entry had it at all times.
1227 const WebHistoryItem& item = frame->currentHistoryItem();
1228 if (!item.isNull()) {
1229 params.content_state = webkit_glue::HistoryItemToString(item);
1230 } else {
1231 params.content_state =
1232 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1233 }
1234
[email protected]dd7daa82009-08-10 05:46:451235 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291236 // Top-level navigation.
1237
[email protected]b75b8292010-10-01 07:28:251238 // Set zoom level, but don't do it for full-page plugin since they don't use
1239 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011240 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541241 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251242 if (webview()->mainFrame()->document().isPluginDocument()) {
1243 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251244 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251245 } else {
1246 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251247 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251248 }
1249
[email protected]f85f0702010-01-30 09:31:011250 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511251 // This zoom level was merely recorded transiently for this load. We can
1252 // erase it now. If at some point we reload this page, the browser will
1253 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011254 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511255 }
1256
[email protected]b75b8292010-10-01 07:28:251257 // Reset the zoom limits in case a plugin had changed them previously. This
1258 // will also call us back which will cause us to send a message to
1259 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251260 webview()->zoomLimitsChanged(
[email protected]0f083402011-11-22 02:59:011261 WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
1262 WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
[email protected]b75b8292010-10-01 07:28:251263
initial.commit09911bf2008-07-26 23:55:291264 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551265 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291266
[email protected]daa8c58e2009-06-15 17:21:101267 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581268 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291269 // If the main frame does a load, it should not be reported as a subframe
1270 // navigation. This can occur in the following case:
1271 // 1. You're on a site with frames.
1272 // 2. You do a subframe navigation. This is stored with transition type
1273 // MANUAL_SUBFRAME.
1274 // 3. You navigate to some non-frame site, say, google.com.
1275 // 4. You navigate back to the page from step 2. Since it was initially
1276 // MANUAL_SUBFRAME, it will be that same transition type here.
1277 // We don't want that, because any navigation that changes the toplevel
1278 // frame should be tracked as a toplevel navigation (this allows us to
1279 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581280 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291281 }
1282
initial.commit09911bf2008-07-26 23:55:291283 // If we have a valid consumed client redirect source,
1284 // the page contained a client redirect (meta refresh, document.loc...),
1285 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151286 if (completed_client_redirect_src_.url.is_valid()) {
1287 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291288 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581289 params.transition = static_cast<content::PageTransition>(
1290 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291291 } else {
1292 // Bug 654101: the referrer will be empty on https->http transitions. It
1293 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151294 params.referrer = Referrer(GURL(
1295 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:401296 GetReferrerPolicyFromRequest(original_request));
initial.commit09911bf2008-07-26 23:55:291297 }
1298
[email protected]726985e22009-06-18 21:09:281299 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051300 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291301 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051302 params.post_id = ExtractPostId(item);
1303 }
initial.commit09911bf2008-07-26 23:55:291304
[email protected]c2a797d2009-09-21 16:46:321305 // Save some histogram data so we can compute the average memory used per
1306 // page load of the glyphs.
1307 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1308 webkit_glue::GetGlyphPageCount());
1309
[email protected]15cf526b2010-02-12 06:33:491310 // This message needs to be sent before any of allowScripts(),
1311 // allowImages(), allowPlugins() is called for the new page, so that when
1312 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1313 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291314 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1315 } else {
1316 // Subframe navigation: the type depends on whether this navigation
1317 // generated a new session history entry. When they do generate a session
1318 // history entry, it means the user initiated the navigation and we should
1319 // mark it as such. This test checks if this is the first time UpdateURL
1320 // has been called since WillNavigateToURL was called to initiate the load.
1321 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581322 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291323 else
[email protected]2905f742011-10-13 03:51:581324 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291325
initial.commit09911bf2008-07-26 23:55:291326 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1327 }
1328
1329 last_page_id_sent_to_browser_ =
1330 std::max(last_page_id_sent_to_browser_, page_id_);
1331
1332 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101333 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581334 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291335}
1336
1337// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281338void RenderViewImpl::UpdateTitle(WebFrame* frame,
1339 const string16& title,
1340 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461341 // Ignore all but top level navigations.
1342 if (frame->parent())
1343 return;
1344
1345 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1346 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1347 title_direction));
initial.commit09911bf2008-07-26 23:55:291348}
1349
[email protected]310ebd6302011-10-10 19:06:281350void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1351 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291352 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271353 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291354 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301355 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291356 last_encoding_name_ = encoding_name;
1357
[email protected]e38f40152008-09-12 23:08:301358 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291359 }
1360}
1361
[email protected]e15f680732010-11-23 22:30:201362// Sends the last committed session history state to the browser so it will be
1363// saved before we navigate to a new page. This must be called *before* the
1364// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281365void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291366 // If we have a valid page ID at this point, then it corresponds to the page
1367 // we are navigating away from. Otherwise, this is the first navigation, so
1368 // there is no past session history to record.
1369 if (page_id_ == -1)
1370 return;
1371
[email protected]ca948a22009-06-25 19:36:171372 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271373 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171374 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291375 return;
[email protected]ca948a22009-06-25 19:36:171376
1377 Send(new ViewHostMsg_UpdateState(
1378 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291379}
1380
[email protected]310ebd6302011-10-10 19:06:281381void RenderViewImpl::OpenURL(WebFrame* frame,
1382 const GURL& url,
[email protected]445e1042011-12-03 21:03:151383 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281384 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171385 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581386 routing_id_,
1387 url,
1388 referrer,
1389 NavigationPolicyToDisposition(policy),
1390 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171391}
1392
[email protected]79dbc662009-09-04 05:42:511393// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291394
[email protected]310ebd6302011-10-10 19:06:281395void RenderViewImpl::LoadNavigationErrorPage(
1396 WebFrame* frame,
1397 const WebURLRequest& failed_request,
1398 const WebURLError& error,
1399 const std::string& html,
1400 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581401 std::string alt_html;
1402 const std::string* error_html;
1403
1404 if (!html.empty()) {
1405 error_html = &html;
1406 } else {
1407 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1408 failed_request, error, &alt_html, NULL);
1409 error_html = &alt_html;
1410 }
1411
1412 frame->loadHTMLString(*error_html,
[email protected]144143c2010-10-28 08:17:361413 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251414 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551415 replace);
initial.commit09911bf2008-07-26 23:55:291416}
1417
[email protected]269f86d2011-12-07 02:43:471418bool RenderViewImpl::RunJavaScriptMessage(ui::JavascriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281419 const string16& message,
1420 const string16& default_value,
1421 const GURL& frame_url,
1422 string16* result) {
initial.commit09911bf2008-07-26 23:55:291423 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411424 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291425 if (!result)
1426 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291427
[email protected]12636df2009-09-28 22:32:211428 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1429 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291430 return success;
1431}
1432
[email protected]310ebd6302011-10-10 19:06:281433bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571434 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1435 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1436 // it is particularly important that we do not call willEnterModalLoop as
1437 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441438 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1439 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571440
1441 message->EnableMessagePumping(); // Runs a nested message loop.
1442 return Send(message);
1443}
1444
[email protected]48c9cf2d2009-09-16 16:47:521445// WebKit::WebViewClient ------------------------------------------------------
1446
[email protected]916dfb62012-03-05 03:39:371447WebView* RenderViewImpl::createView(
1448 WebFrame* creator,
1449 const WebURLRequest& request,
1450 const WebWindowFeatures& features,
1451 const WebString& frame_name,
1452 WebNavigationPolicy policy) {
[email protected]48c9cf2d2009-09-16 16:47:521453 // Check to make sure we aren't overloading on popups.
1454 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1455 return NULL;
1456
[email protected]8ab04652010-06-12 02:47:261457 ViewHostMsg_CreateWindow_Params params;
1458 params.opener_id = routing_id_;
1459 params.user_gesture = creator->isProcessingUserGesture();
1460 params.window_container_type = WindowFeaturesToContainerType(features);
1461 params.session_storage_namespace_id = session_storage_namespace_id_;
1462 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111463 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411464 params.opener_url = creator->document().url();
1465 params.opener_security_origin =
1466 creator->document().securityOrigin().toString().utf8();
[email protected]f92ce2b2012-03-06 18:02:591467 params.opener_suppressed = creator->willSuppressOpenerInNewFrame();
1468 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]41e65502011-01-21 09:29:111469 if (!request.isNull())
1470 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261471
[email protected]48c9cf2d2009-09-16 16:47:521472 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561473 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341474 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521475
[email protected]380244092011-10-07 17:26:271476 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261477 new ViewHostMsg_CreateWindow(params,
1478 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561479 &surface_id,
[email protected]8ab04652010-06-12 02:47:261480 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211481 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521482 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521483
[email protected]310ebd6302011-10-10 19:06:281484 RenderViewImpl* view = RenderViewImpl::Create(
1485 0,
1486 routing_id_,
1487 renderer_preferences_,
1488 webkit_preferences_,
1489 shared_popup_counter_,
1490 routing_id,
[email protected]9f4f3322012-01-18 22:29:561491 surface_id,
[email protected]310ebd6302011-10-10 19:06:281492 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461493 frame_name,
[email protected]6fd35b72012-03-01 19:46:411494 1,
1495 screen_info_);
[email protected]8ab04652010-06-12 02:47:261496 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521497
[email protected]007a848b2009-10-26 15:55:461498 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:591499 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:461500
[email protected]48c9cf2d2009-09-16 16:47:521501 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411502 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521503 if (!creator_url.is_valid() || !creator_url.IsStandard())
1504 creator_url = GURL();
1505 view->creator_url_ = creator_url;
1506
1507 // Copy over the alternate error page URL so we can have alt error pages in
1508 // the new render view (we don't need the browser to send the URL back down).
1509 view->alternate_error_page_url_ = alternate_error_page_url_;
1510
1511 return view->webview();
1512}
1513
[email protected]310ebd6302011-10-10 19:06:281514WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:411515 RenderWidget* widget =
1516 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]48c9cf2d2009-09-16 16:47:521517 return widget->webwidget();
1518}
1519
[email protected]310ebd6302011-10-10 19:06:281520WebWidget* RenderViewImpl::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441521 // TODO(jcivelli): Remove this deprecated method when its been removed from
1522 // the WebViewClient interface. It's been replaced by
1523 // createExternalPopupMenu.
1524 NOTREACHED();
1525 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521526}
1527
[email protected]310ebd6302011-10-10 19:06:281528WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081529 const WebPopupMenuInfo& popup_menu_info,
1530 WebExternalPopupMenuClient* popup_menu_client) {
1531 DCHECK(!external_popup_menu_.get());
1532 external_popup_menu_.reset(
1533 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1534 return external_popup_menu_.get();
1535}
1536
[email protected]310ebd6302011-10-10 19:06:281537RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521538 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531539 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421540 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411541 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531542 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271543 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391544 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561545 return widget;
[email protected]79c7bed2010-09-14 22:28:391546}
1547
[email protected]310ebd6302011-10-10 19:06:281548WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1549 unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341550 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391551 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291552 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1553 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1554 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341555}
1556
[email protected]7e8b4d12012-01-20 23:39:511557WebGraphicsContext3D* RenderViewImpl::createGraphicsContext3D(
[email protected]40ec0c12012-03-08 12:34:401558 const WebGraphicsContext3D::Attributes& attributes) {
1559 return createGraphicsContext3D(attributes, true);
1560}
1561
1562WebGraphicsContext3D* RenderViewImpl::createGraphicsContext3D(
[email protected]01e69032012-01-31 05:39:061563 const WebGraphicsContext3D::Attributes& attributes,
[email protected]7e8b4d12012-01-20 23:39:511564 bool direct) {
1565 if (!webview())
1566 return NULL;
1567 // The WebGraphicsContext3DInProcessImpl code path is used for
1568 // layout tests (though not through this code) as well as for
1569 // debugging and bringing up new ports.
[email protected]7e8b4d12012-01-20 23:39:511570 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
[email protected]56200f012012-02-03 23:13:571571 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
[email protected]33a9c762012-02-23 22:37:241572 attributes, direct);
[email protected]7e8b4d12012-01-20 23:39:511573 } else {
[email protected]b3e83de2012-02-07 03:33:281574 int surface = direct ? surface_id() : 0;
1575
1576 GURL url;
1577 if (webview()->mainFrame())
1578 url = GURL(webview()->mainFrame()->document().url());
1579
1580 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client;
1581 if (direct)
1582 swap_client = AsWeakPtr();
1583
1584 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
1585 new WebGraphicsContext3DCommandBufferImpl(
[email protected]9193034b2012-03-12 19:51:221586 surface, url, RenderThreadImpl::current(), swap_client));
[email protected]b3e83de2012-02-07 03:33:281587
1588 if (!context->Initialize(attributes))
[email protected]56200f012012-02-03 23:13:571589 return NULL;
[email protected]d0fb8a72012-03-10 18:54:521590 context_is_web_graphics_context_3d_command_buffer_impl_ = true;
[email protected]56200f012012-02-03 23:13:571591 return context.release();
[email protected]7e8b4d12012-01-20 23:39:511592 }
[email protected]7e8b4d12012-01-20 23:39:511593}
1594
[email protected]310ebd6302011-10-10 19:06:281595void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521596 const WebConsoleMessage& message, const WebString& source_name,
1597 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081598 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511599 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081600 case WebConsoleMessage::LevelTip:
1601 log_severity = logging::LOG_VERBOSE;
1602 break;
1603 case WebConsoleMessage::LevelLog:
1604 log_severity = logging::LOG_INFO;
1605 break;
1606 case WebConsoleMessage::LevelWarning:
1607 log_severity = logging::LOG_WARNING;
1608 break;
1609 case WebConsoleMessage::LevelError:
1610 log_severity = logging::LOG_ERROR;
1611 break;
1612 default:
1613 NOTREACHED();
1614 }
1615
[email protected]48c9cf2d2009-09-16 16:47:521616 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081617 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311618 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521619 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311620 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521621}
1622
[email protected]310ebd6302011-10-10 19:06:281623void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421624 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521625}
1626
[email protected]310ebd6302011-10-10 19:06:281627WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511628 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021629}
1630
[email protected]310ebd6302011-10-10 19:06:281631bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121632 const WebString& path,
1633 WebFileChooserCompletion* chooser_completion) {
1634 int id = enumeration_completion_id_++;
1635 enumeration_completions_[id] = chooser_completion;
1636 return Send(new ViewHostMsg_EnumerateDirectory(
1637 routing_id_,
1638 id,
1639 webkit_glue::WebStringToFilePath(path)));
1640}
1641
[email protected]310ebd6302011-10-10 19:06:281642void RenderViewImpl::didStartLoading() {
[email protected]6dc7ff62012-03-15 06:16:131643#if defined(OS_CHROMEOS)
1644 // crosbug.com/26646.
1645 LOG(ERROR) << "didStartLoading is_loading=" << is_loading_;
1646#endif
[email protected]48c9cf2d2009-09-16 16:47:521647 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:141648 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:521649 return;
1650 }
1651
1652 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521653
1654 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311655
1656 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521657}
1658
[email protected]310ebd6302011-10-10 19:06:281659void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521660 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:141661 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:521662 return;
1663 }
1664
1665 is_loading_ = false;
1666
1667 // NOTE: For now we're doing the safest thing, and sending out notification
1668 // when done loading. This currently isn't an issue as the favicon is only
1669 // displayed when done loading. Ideally we would send notification when
1670 // finished parsing the head, but webkit doesn't support that yet.
1671 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521672 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1673
[email protected]90109412010-12-15 17:14:241674 if (load_progress_tracker_ != NULL)
1675 load_progress_tracker_->DidStopLoading();
1676
[email protected]93b9d692011-04-13 00:44:311677 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521678}
1679
[email protected]310ebd6302011-10-10 19:06:281680void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1681 double load_progress) {
[email protected]90109412010-12-15 17:14:241682 if (load_progress_tracker_ != NULL)
1683 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1684}
1685
[email protected]310ebd6302011-10-10 19:06:281686bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061687#if defined(OS_MACOSX)
1688 return true;
1689#else
1690 return false;
1691#endif
1692}
1693
[email protected]310ebd6302011-10-10 19:06:281694bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031695#if defined(OS_WIN)
1696 return true;
1697#else
1698 return false;
1699#endif
1700}
1701
[email protected]310ebd6302011-10-10 19:06:281702void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081703 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031704 return;
[email protected]4fb60142011-08-09 02:22:081705 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011706
[email protected]b781ff282011-08-20 06:19:361707 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031708}
1709
[email protected]310ebd6302011-10-10 19:06:281710void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121711 const std::string& name = UTF16ToUTF8(command_name);
1712 if (StartsWithASCII(name, "Move", true) ||
1713 StartsWithASCII(name, "Insert", true) ||
1714 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031715 return;
[email protected]f1a29a02011-10-06 23:08:441716 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031717}
1718
[email protected]310ebd6302011-10-10 19:06:281719bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101720 if (edit_commands_.empty())
1721 return false;
1722
[email protected]26aa0482009-09-30 16:55:271723 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101724 if (!frame)
1725 return false;
1726
1727 EditCommands::iterator it = edit_commands_.begin();
1728 EditCommands::iterator end = edit_commands_.end();
1729
[email protected]507b33ea2009-09-29 03:56:511730 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101731 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331732 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1733 // key (but it's the exception). Once one edit command is not executed, it
1734 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101735 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1736 WebString::fromUTF8(it->value)))
1737 break;
[email protected]507b33ea2009-09-29 03:56:511738 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101739 }
1740
[email protected]507b33ea2009-09-29 03:56:511741 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101742}
1743
[email protected]310ebd6302011-10-10 19:06:281744bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:351745 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471746 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351747 // Do not open the file dialog in a hidden RenderView.
1748 if (is_hidden())
1749 return false;
[email protected]8caadeb2011-11-22 02:45:231750 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261751 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:231752 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261753 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:231754 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501755 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:231756 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261757 else
[email protected]8caadeb2011-11-22 02:45:231758 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471759 ipc_params.title = params.title;
1760 ipc_params.default_file_name =
1761 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]3314c2b12011-11-02 08:05:461762 ipc_params.accept_types.reserve(params.acceptMIMETypes.size());
1763 for (size_t i = 0; i < params.acceptMIMETypes.size(); ++i)
1764 ipc_params.accept_types.push_back(params.acceptMIMETypes[i]);
[email protected]cdaf8d02010-03-30 19:52:471765
1766 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461767}
1768
[email protected]269f86d2011-12-07 02:43:471769void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
1770 const WebString& message) {
1771 RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:411772 message,
1773 string16(),
[email protected]b6cb3a842011-06-24 18:28:411774 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521775 NULL);
1776}
1777
[email protected]269f86d2011-12-07 02:43:471778bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
1779 const WebString& message) {
1780 return RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:411781 message,
1782 string16(),
[email protected]b6cb3a842011-06-24 18:28:411783 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521784 NULL);
1785}
1786
[email protected]269f86d2011-12-07 02:43:471787bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
1788 const WebString& message,
1789 const WebString& default_value,
1790 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411791 string16 result;
[email protected]269f86d2011-12-07 02:43:471792 bool ok = RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:411793 message,
1794 default_value,
[email protected]b6cb3a842011-06-24 18:28:411795 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521796 &result);
1797 if (ok)
[email protected]4f5ce842011-05-27 19:34:411798 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521799 return ok;
1800}
1801
[email protected]310ebd6302011-10-10 19:06:281802bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:521803 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151804 // If we are swapping out, we have already run the beforeunload handler.
1805 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1806 // at all, to avoid running it twice.
1807 if (is_swapped_out_)
1808 return true;
1809
[email protected]3b3301f62012-02-29 04:32:321810 bool is_reload = false;
1811 WebDataSource* ds = frame->provisionalDataSource();
1812 if (ds)
1813 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
1814
[email protected]48c9cf2d2009-09-16 16:47:521815 bool success = false;
1816 // This is an ignored return value, but is included so we can accept the same
1817 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411818 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211819 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:321820 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:411821 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521822 return success;
1823}
1824
[email protected]310ebd6302011-10-10 19:06:281825void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:441826 WebFrame* frame, const WebContextMenuData& data) {
[email protected]35be7ec2012-02-12 20:42:511827 content::ContextMenuParams params(data);
[email protected]7fcd9b72011-07-27 16:52:371828
1829 // frame is NULL if invoked by BlockedPlugin.
1830 if (frame)
1831 params.frame_id = frame->identifier();
1832
[email protected]db803aae2011-03-05 02:00:421833 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271834 // it. We replace it with an empty GURL so the appropriate items are disabled
1835 // in the context menu.
1836 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1837 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421838 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271839 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101840 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291841 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441842}
1843
[email protected]310ebd6302011-10-10 19:06:281844void RenderViewImpl::enterFullscreen() {
[email protected]2b624c562011-10-27 22:58:261845 // TODO(darin): Remove once WebKit roll is complete.
1846 enterFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471847}
1848
[email protected]310ebd6302011-10-10 19:06:281849void RenderViewImpl::exitFullscreen() {
[email protected]2b624c562011-10-27 22:58:261850 // TODO(darin): Remove once WebKit roll is complete.
1851 exitFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471852}
1853
[email protected]310ebd6302011-10-10 19:06:281854void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521855}
1856
[email protected]310ebd6302011-10-10 19:06:281857void RenderViewImpl::UpdateTargetURL(const GURL& url,
1858 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581859 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521860 if (latest_url == target_url_)
1861 return;
[email protected]163f8242009-10-30 20:19:551862
[email protected]48c9cf2d2009-09-16 16:47:521863 // Tell the browser to display a destination link.
1864 if (target_url_status_ == TARGET_INFLIGHT ||
1865 target_url_status_ == TARGET_PENDING) {
1866 // If we have a request in-flight, save the URL to be sent when we
1867 // receive an ACK to the in-flight request. We can happily overwrite
1868 // any existing pending sends.
1869 pending_target_url_ = latest_url;
1870 target_url_status_ = TARGET_PENDING;
1871 } else {
[email protected]c85f0212011-11-04 16:54:411872 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
1873 // see |ParamTraits<GURL>|.
1874 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
1875 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:521876 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1877 target_url_ = latest_url;
1878 target_url_status_ = TARGET_INFLIGHT;
1879 }
1880}
1881
[email protected]310ebd6302011-10-10 19:06:281882void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:311883 int delay;
1884 if (send_content_state_immediately_)
1885 delay = 0;
1886 else if (is_hidden())
1887 delay = kDelaySecondsForContentStateSyncHidden;
1888 else
1889 delay = kDelaySecondsForContentStateSync;
1890
1891 if (nav_state_sync_timer_.IsRunning()) {
1892 // The timer is already running. If the delay of the timer maches the amount
1893 // we want to delay by, then return. Otherwise stop the timer so that it
1894 // gets started with the right delay.
1895 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1896 return;
1897 nav_state_sync_timer_.Stop();
1898 }
1899
[email protected]d323a172011-09-02 18:23:021900 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:281901 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311902}
1903
[email protected]310ebd6302011-10-10 19:06:281904void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551905 mouse_over_url_ = GURL(url);
1906 UpdateTargetURL(mouse_over_url_, focus_url_);
1907}
1908
[email protected]310ebd6302011-10-10 19:06:281909void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551910 focus_url_ = GURL(url);
1911 UpdateTargetURL(focus_url_, mouse_over_url_);
1912}
1913
[email protected]310ebd6302011-10-10 19:06:281914void RenderViewImpl::startDragging(const WebDragData& data,
1915 WebDragOperationsMask mask,
1916 const WebImage& image,
1917 const WebPoint& imageOffset) {
[email protected]c27ae592010-03-18 15:24:411918#if WEBKIT_USING_SKIA
1919 SkBitmap bitmap(image.getSkBitmap());
1920#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331921 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411922#endif
1923
[email protected]59f4f2fa2011-03-23 01:00:551924 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521925 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411926 mask,
1927 bitmap,
1928 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521929}
1930
[email protected]310ebd6302011-10-10 19:06:281931bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451932 return renderer_preferences_.can_accept_load_drops;
1933}
1934
[email protected]310ebd6302011-10-10 19:06:281935void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:521936 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1937}
1938
[email protected]310ebd6302011-10-10 19:06:281939void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:521940 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1941}
1942
[email protected]310ebd6302011-10-10 19:06:281943void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511944 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071945
[email protected]38b592902011-04-16 02:08:421946 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491947}
1948
[email protected]169d4282011-11-30 19:33:591949void RenderViewImpl::didUpdateLayout() {
1950 // We don't always want to set up a timer, only if we've been put in that
1951 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1952 // message.
1953 if (!send_preferred_size_changes_ || !webview())
1954 return;
1955
1956 if (check_preferred_size_timer_.IsRunning())
1957 return;
1958 check_preferred_size_timer_.Start(FROM_HERE,
1959 TimeDelta::FromMilliseconds(0), this,
1960 &RenderViewImpl::CheckPreferredSize);
1961}
1962
[email protected]310ebd6302011-10-10 19:06:281963void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521964 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1965}
1966
[email protected]310ebd6302011-10-10 19:06:281967int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001968 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521969}
1970
[email protected]310ebd6302011-10-10 19:06:281971int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001972 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521973}
1974
[email protected]310ebd6302011-10-10 19:06:281975void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:321976 const WebAccessibilityObject& obj,
1977 WebAccessibilityNotification notification) {
1978 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1979}
1980
[email protected]310ebd6302011-10-10 19:06:281981void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:141982 const WebString& value) {
1983 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1984 key.utf8(),
1985 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261986}
1987
[email protected]79dbc662009-09-04 05:42:511988// WebKit::WebWidgetClient ----------------------------------------------------
1989
[email protected]310ebd6302011-10-10 19:06:281990void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:121991 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1992 // we won't have to test for user gesture anymore and we can
1993 // move that code back to render_widget.cc
1994 if (webview() && webview()->mainFrame() &&
1995 webview()->mainFrame()->isProcessingUserGesture()) {
1996 Send(new ViewHostMsg_Focus(routing_id_));
1997 }
1998}
1999
[email protected]310ebd6302011-10-10 19:06:282000void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:122001 // TODO(jcivelli): see TODO above in didFocus().
2002 if (webview() && webview()->mainFrame() &&
2003 webview()->mainFrame()->isProcessingUserGesture()) {
2004 Send(new ViewHostMsg_Blur(routing_id_));
2005 }
2006}
2007
initial.commit09911bf2008-07-26 23:55:292008// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:282009// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:292010// point to dispatch the ShowView message.
2011//
2012// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:282013// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:292014//
[email protected]310ebd6302011-10-10 19:06:282015void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292016 DCHECK(!did_show_) << "received extraneous Show call";
2017 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2018
2019 if (did_show_)
2020 return;
2021 did_show_ = true;
2022
[email protected]6779aa12011-03-29 17:32:242023 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:042024 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:042025
[email protected]28295ec2009-10-16 05:34:332026 // Force new windows to a popup if they were not opened with a user gesture.
2027 if (!opened_by_user_gesture_) {
2028 // We exempt background tabs for compat with older versions of Chrome.
2029 // TODO(darin): This seems bogus. These should have a user gesture, so
2030 // we probably don't need this check.
2031 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2032 policy = WebKit::WebNavigationPolicyNewPopup;
2033 }
2034
initial.commit09911bf2008-07-26 23:55:292035 // NOTE: initial_pos_ may still have its default values at this point, but
2036 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2037 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282038 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2039 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292040 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242041 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292042}
2043
[email protected]310ebd6302011-10-10 19:06:282044void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292045 DCHECK(did_show_) << "should already have shown the view";
2046
[email protected]c1f50aa2010-02-18 03:46:572047 // We must keep WebKit's shared timer running in this case in order to allow
2048 // showModalDialog to function properly.
2049 //
2050 // TODO(darin): WebKit should really be smarter about suppressing events and
2051 // timers so that we do not need to manage the shared timer in such a heavy
2052 // handed manner.
2053 //
[email protected]f1a29a02011-10-06 23:08:442054 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2055 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572056
[email protected]12636df2009-09-28 22:32:212057 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292058}
2059
[email protected]2b624c562011-10-27 22:58:262060bool RenderViewImpl::enterFullScreen() {
2061 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2062 return true;
2063}
2064
2065void RenderViewImpl::exitFullScreen() {
2066 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2067}
2068
[email protected]217690d2012-01-27 07:33:112069bool RenderViewImpl::requestPointerLock() {
2070 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2071}
2072
2073void RenderViewImpl::requestPointerUnlock() {
2074 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2075}
2076
2077bool RenderViewImpl::isPointerLocked() {
2078 return mouse_lock_dispatcher_->IsMouseLockedTo(
2079 webwidget_mouse_lock_target_.get());
2080}
2081
[email protected]3d9689372009-09-10 04:29:172082// WebKit::WebFrameClient -----------------------------------------------------
2083
[email protected]310ebd6302011-10-10 19:06:282084WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2085 const WebPluginParams& params) {
[email protected]0361b942012-03-14 06:42:532086 // The browser plugin is a special kind of pepper plugin
2087 // that loads asynchronously. We first create a placeholder here.
2088 // When a guest is ready to be displayed, we swap out the placeholder
2089 // with the guest.
2090 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2091 if (command_line.HasSwitch(switches::kEnableBrowserPlugin) &&
2092 UTF16ToASCII(params.mimeType) == kBrowserPluginMimeType)
2093 return BrowserPluginPlaceholder::Create(this, frame, params);
2094
[email protected]eaacd1f2011-09-23 02:32:552095 WebPlugin* plugin = NULL;
2096 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
2097 this, frame, params, &plugin)) {
2098 return plugin;
2099 }
2100
[email protected]a813c8e2011-10-08 01:34:112101 webkit::WebPluginInfo info;
2102 std::string mime_type;
2103 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2104 params.mimeType.utf8(), &info, &mime_type);
2105 if (!found)
2106 return NULL;
2107
2108 WebPluginParams params_to_use = params;
2109 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312110 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172111}
2112
[email protected]310ebd6302011-10-10 19:06:282113WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422114 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372115 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422116
[email protected]30447b62009-11-13 01:13:372117 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512118 bool exists = false;
[email protected]30447b62009-11-13 01:13:372119 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512120 ViewHostMsg_CreateWorker_Params params;
2121 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512122 params.name = name;
2123 params.document_id = document_id;
2124 params.render_view_route_id = routing_id_;
2125 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232126 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372127 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512128 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372129 if (url_mismatch) {
2130 return NULL;
2131 } else {
[email protected]f1a29a02011-10-06 23:08:442132 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492133 document_id,
[email protected]6de0bcf2010-02-17 22:00:512134 exists,
[email protected]30447b62009-11-13 01:13:372135 route_id,
2136 routing_id_);
2137 }
[email protected]9c00f002009-11-05 22:37:422138}
2139
[email protected]310ebd6302011-10-10 19:06:282140WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]3d9689372009-09-10 04:29:172141 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442142 FOR_EACH_OBSERVER(
2143 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172144
[email protected]bb6fd402011-12-09 02:45:442145 media::MessageLoopFactory* message_loop_factory =
[email protected]b80322902012-03-06 01:33:502146 new media::MessageLoopFactory();
[email protected]bb6fd402011-12-09 02:45:442147 media::FilterCollection* collection = new media::FilterCollection();
2148 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372149
[email protected]9e2269d2012-01-07 00:06:212150 RenderAudioSourceProvider* audio_source_provider = NULL;
2151
[email protected]3d9689372009-09-10 04:29:172152 // Add in any custom filter factories first.
2153 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2154 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212155 // audio_source_provider is a "provider" to WebKit, and a sink
2156 // from the perspective of the audio renderer.
2157 audio_source_provider = new RenderAudioSourceProvider();
2158
2159 // Add the chrome specific audio renderer, using audio_source_provider
2160 // as the sink.
2161 AudioRendererImpl* audio_renderer =
2162 new AudioRendererImpl(audio_source_provider);
2163 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172164 }
2165
[email protected]e1d69d762011-12-13 05:12:182166 // Currently only cros/arm has any HW video decode support in
2167 // GpuVideoDecodeAccelerator so we don't even try to use it on other
2168 // platforms. This is a startup-time optimization. When new VDA
2169 // implementations are added, relax the #if above.
[email protected]d0fb8a72012-03-10 18:54:522170#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
2171 // Note we don't actually use the result of this blind down-cast unless it's
2172 // valid (not NULL and of the right type).
[email protected]43567302012-02-16 23:21:392173 WebGraphicsContext3DCommandBufferImpl* context3d =
2174 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2175 webview()->graphicsContext3D());
[email protected]d0fb8a72012-03-10 18:54:522176 if (context_is_web_graphics_context_3d_command_buffer_impl_ && context3d) {
[email protected]84a83e192012-03-09 18:43:402177 MessageLoop* factories_loop =
2178 RenderThreadImpl::current()->compositor_thread() ?
2179 RenderThreadImpl::current()->compositor_thread()->GetWebThread()
2180 ->message_loop() :
2181 MessageLoop::current();
[email protected]e1d69d762011-12-13 05:12:182182 GpuChannelHost* gpu_channel_host =
2183 RenderThreadImpl::current()->EstablishGpuChannelSync(
2184 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
2185 collection->AddVideoDecoder(new media::GpuVideoDecoder(
[email protected]8d4359282012-01-14 00:53:312186 message_loop_factory->GetMessageLoop("GpuVideoDecoder"),
[email protected]84a83e192012-03-09 18:43:402187 factories_loop,
[email protected]8d4359282012-01-14 00:53:312188 new RendererGpuVideoDecoderFactories(
[email protected]84a83e192012-03-09 18:43:402189 gpu_channel_host, factories_loop, context3d)));
[email protected]e1d69d762011-12-13 05:12:182190 }
2191#endif
2192
[email protected]da952fd2012-01-13 03:49:252193 webkit_media::WebMediaPlayerImpl* media_player =
2194 content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
2195 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
2196 message_loop_factory, media_stream_impl_.get(), render_media_log);
[email protected]c4dabe452012-02-08 23:58:122197#if defined(OS_ANDROID)
2198 // TODO(qinmin): Implement for android.
2199 // http://crbug.com/113218
2200#else
[email protected]da952fd2012-01-13 03:49:252201 if (!media_player) {
[email protected]cec4eb82012-01-12 17:51:562202 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252203 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]9e2269d2012-01-07 00:06:212204 message_loop_factory, media_stream_impl_.get(), render_media_log);
[email protected]bb6fd402011-12-09 02:45:442205 }
[email protected]c4dabe452012-02-08 23:58:122206#endif
[email protected]cec4eb82012-01-12 17:51:562207 return media_player;
[email protected]3d9689372009-09-10 04:29:172208}
2209
[email protected]310ebd6302011-10-10 19:06:282210WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212211 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232212 if (!frame || !frame->view())
2213 return NULL;
[email protected]035545f2010-04-09 13:10:212214 return new RendererWebApplicationCacheHostImpl(
2215 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442216 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212217}
2218
[email protected]310ebd6302011-10-10 19:06:282219WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382220 return &cookie_jar_;
2221}
2222
[email protected]310ebd6302011-10-10 19:06:282223void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512224 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452225}
2226
[email protected]310ebd6302011-10-10 19:06:282227void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512228 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172229}
2230
[email protected]310ebd6302011-10-10 19:06:282231void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172232 WebFrame* frame, const WebURLRequest& request,
2233 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342234 loadURLExternally(frame, request, policy, WebString());
2235}
2236
[email protected]310ebd6302011-10-10 19:06:282237void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342238 WebFrame* frame, const WebURLRequest& request,
2239 WebNavigationPolicy policy,
2240 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:592241 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2242 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342243 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2244 suggested_name));
[email protected]efce17b2009-09-11 18:04:592245 } else {
[email protected]445e1042011-12-03 21:03:152246 OpenURL(frame, request.url(),
[email protected]b9fd01ba2012-02-28 01:50:402247 Referrer(referrer, GetReferrerPolicyFromRequest(request)), policy);
[email protected]efce17b2009-09-11 18:04:592248 }
[email protected]3d9689372009-09-10 04:29:172249}
2250
[email protected]310ebd6302011-10-10 19:06:282251WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172252 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222253 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:152254 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
2255 if (is_swapped_out_) {
[email protected]73eb2602012-02-09 19:50:552256 // It is possible for in-progress navigations to arrive here just after we
2257 // are swapped out, including iframes. We should cancel them.
2258 if (request.url() != GURL("about:swappedout"))
2259 return WebKit::WebNavigationPolicyIgnore;
2260
2261 // Allow about:swappedout to complete.
[email protected]992db4c2011-05-12 15:37:152262 return default_policy;
2263 }
2264
[email protected]3d9689372009-09-10 04:29:172265 // Webkit is asking whether to navigate to a new URL.
2266 // This is fine normally, except if we're showing UI from one security
2267 // context and they're trying to navigate to a different context.
2268 const GURL& url = request.url();
2269
[email protected]d19ea342011-04-20 20:31:132270 // A content initiated navigation may have originated from a link-click,
2271 // script, drag-n-drop operation, etc.
2272 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072273 DocumentState::FromDataSource(frame->provisionalDataSource())->
2274 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132275
[email protected]a8c269a2011-10-25 20:17:222276 // Experimental:
2277 // If --enable-strict-site-isolation is enabled, send all top-level
2278 // navigations to the browser to let it swap processes when crossing site
2279 // boundaries. This is currently expected to break some script calls and
2280 // navigations, such as form submissions.
2281 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102282 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2283 !frame->parent() && (is_content_initiated || is_redirect)) {
2284 WebString origin_str = frame->document().securityOrigin().toString();
2285 GURL frame_url(origin_str.utf8().data());
2286 // TODO(cevans): revisit whether this origin check is still necessary once
2287 // crbug.com/101395 is fixed.
2288 if (frame_url.GetOrigin() != url.GetOrigin()) {
[email protected]445e1042011-12-03 21:03:152289 Referrer referrer(
2290 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:402291 GetReferrerPolicyFromRequest(request));
[email protected]313b80bd2011-11-23 03:49:102292 OpenURL(frame, url, referrer, default_policy);
2293 return WebKit::WebNavigationPolicyIgnore;
2294 }
[email protected]a8c269a2011-10-25 20:17:222295 }
2296
[email protected]3d9689372009-09-10 04:29:172297 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302298 // navigations.
[email protected]5f000f272012-01-19 05:25:082299 if (is_content_initiated) {
2300 bool browser_handles_top_level_requests =
2301 renderer_preferences_.browser_handles_top_level_requests &&
2302 IsNonLocalTopLevelNavigation(url, frame, type);
2303 if (browser_handles_top_level_requests ||
2304 renderer_preferences_.browser_handles_all_requests) {
2305 Referrer referrer(
2306 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:402307 GetReferrerPolicyFromRequest(request));
[email protected]5f000f272012-01-19 05:25:082308 // Reset these counters as the RenderView could be reused for the next
2309 // navigation.
2310 page_id_ = -1;
2311 last_page_id_sent_to_browser_ = -1;
2312 OpenURL(frame, url, referrer, default_policy);
2313 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2314 }
[email protected]3d9689372009-09-10 04:29:172315 }
2316
[email protected]6101c342010-12-16 22:44:372317 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552318 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572319 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372320 // opening a new window). But we sometimes navigate to about:blank to clear a
2321 // tab, and we want to still allow that.
2322 //
[email protected]8f4da8c2011-02-09 19:49:572323 // Note: we do this only for GET requests because our mechanism for switching
2324 // processes only issues GET requests. In particular, POST requests don't
2325 // work, because this mechanism does not preserve form POST data. If it
2326 // becomes necessary to support process switching for POST requests, we will
2327 // need to send the request's httpBody data up to the browser process, and
2328 // issue a special POST navigation in WebKit (via
2329 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2330 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222331 if (!frame->parent() && is_content_initiated &&
[email protected]6101c342010-12-16 22:44:372332 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2333 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2334 bool send_referrer = false;
2335 bool should_fork =
[email protected]e091df82011-10-11 18:13:212336 (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]3d9689372009-09-10 04:29:172337 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372338 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112339
[email protected]e48869a2011-04-01 19:56:032340 if (!should_fork) {
2341 // Give the embedder a chance.
[email protected]d55c2382011-08-18 23:10:362342 bool is_initial_navigation = page_id_ == -1;
[email protected]e48869a2011-04-01 19:56:032343 should_fork = content::GetContentClient()->renderer()->ShouldFork(
[email protected]3f105a2f2012-02-25 18:27:362344 frame, url, is_initial_navigation, &send_referrer);
[email protected]6101c342010-12-16 22:44:372345 }
2346
2347 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152348 Referrer referrer(
2349 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:402350 GetReferrerPolicyFromRequest(request));
[email protected]445e1042011-12-03 21:03:152351 OpenURL(
2352 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112353 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2354 }
[email protected]3d9689372009-09-10 04:29:172355 }
2356
[email protected]43763f982011-08-26 18:33:402357 // Use the frame's original request's URL rather than the document's URL for
2358 // this check. For a popup, the document's URL may become the opener window's
2359 // URL if the opener has called document.write. See http://crbug.com/93517.
2360 GURL old_url(frame->dataSource()->request().url());
2361
[email protected]3d9689372009-09-10 04:29:172362 // Detect when a page is "forking" a new tab that can be safely rendered in
2363 // its own process. This is done by sites like Gmail that try to open links
2364 // in new windows without script connections back to the original page. We
2365 // treat such cases as browser navigations (in which we will create a new
2366 // renderer for a cross-site navigation), rather than WebKit navigations.
2367 //
2368 // We use the following heuristic to decide whether to fork a new page in its
2369 // own process:
2370 // The parent page must open a new tab to about:blank, set the new tab's
2371 // window.opener to null, and then redirect the tab to a cross-site URL using
2372 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462373 //
2374 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2375 // (see below).
[email protected]3d9689372009-09-10 04:29:172376 bool is_fork =
2377 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582378 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172379 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522380 historyBackListCount() < 1 &&
2381 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172382 // The parent page must have set the child's window.opener to null before
2383 // redirecting to the desired URL.
2384 frame->opener() == NULL &&
2385 // Must be a top-level frame.
2386 frame->parent() == NULL &&
2387 // Must not have issued the request from this page.
2388 is_content_initiated &&
2389 // Must be targeted at the current tab.
2390 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2391 // Must be a JavaScript navigation, which appears as "other".
2392 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462393
[email protected]f92ce2b2012-03-06 18:02:592394 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:172395 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152396 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172397 return WebKit::WebNavigationPolicyIgnore;
2398 }
2399
2400 return default_policy;
2401}
2402
[email protected]310ebd6302011-10-10 19:06:282403bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492404 WebFrame* frame, const WebURLRequest& request) {
2405 // We allow WebKit to think that everything can be handled even though
2406 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342407 return true;
2408}
2409
[email protected]310ebd6302011-10-10 19:06:282410WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492411 WebFrame* frame, const WebURLRequest& request) {
2412 NOTREACHED(); // Since we said we can handle all requests.
2413 return WebURLError();
2414}
2415
[email protected]310ebd6302011-10-10 19:06:282416WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492417 WebFrame* frame, const WebURLRequest& request) {
2418 WebURLError error;
2419 error.domain = WebString::fromUTF8(net::kErrorDomain);
2420 error.reason = net::ERR_ABORTED;
2421 error.unreachableURL = request.url();
2422 return error;
[email protected]7b7a7dc2009-10-19 02:23:342423}
2424
[email protected]310ebd6302011-10-10 19:06:282425void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492426 WebFrame*, const WebURLError&) {
2427 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342428}
2429
[email protected]310ebd6302011-10-10 19:06:282430void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432431 const WebKit::WebFormElement& form) {
2432 // Some login forms have onSubmit handlers that put a hash of the password
2433 // into a hidden field and then clear the password. (Issue 28910.)
2434 // This method gets called before any of those handlers run, so save away
2435 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072436 DocumentState* document_state =
2437 DocumentState::FromDataSource(frame->dataSource());
2438 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432439 PasswordFormDomManager::CreatePasswordForm(form));
2440}
2441
[email protected]310ebd6302011-10-10 19:06:282442void RenderViewImpl::willSubmitForm(WebFrame* frame,
2443 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072444 DocumentState* document_state =
2445 DocumentState::FromDataSource(frame->provisionalDataSource());
2446 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172447
[email protected]2905f742011-10-13 03:51:582448 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2449 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172450
2451 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352452 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072453 document_state->set_searchable_form_url(web_searchable_form_data.url());
2454 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212455 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432456 PasswordForm* password_form_data =
2457 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]007733c2011-11-17 00:34:072458 document_state->set_password_form_data(password_form_data);
[email protected]90eeddb2010-05-06 21:06:432459
[email protected]098c95cb2011-04-28 16:49:012460 // In order to save the password that the user actually typed and not one
2461 // that may have gotten transformed by the site prior to submit, recover it
2462 // from the form contents already stored by |willSendSubmitEvent| into the
2463 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2464 // which is what we're storing into now.)
2465 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:072466 DocumentState* old_document_state =
2467 DocumentState::FromDataSource(frame->dataSource());
2468 if (old_document_state) {
2469 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432470 if (old_form_data && old_form_data->action == password_form_data->action)
2471 password_form_data->password_value = old_form_data->password_value;
2472 }
2473 }
[email protected]3d9689372009-09-10 04:29:172474
[email protected]2a5b1732011-04-01 23:55:552475 FOR_EACH_OBSERVER(
2476 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172477}
2478
[email protected]310ebd6302011-10-10 19:06:282479void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172480 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2481 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382482 FOR_EACH_OBSERVER(
2483 RenderViewObserver, observers_,
2484 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172485}
2486
[email protected]310ebd6302011-10-10 19:06:282487void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382488 FOR_EACH_OBSERVER(
2489 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172490}
2491
[email protected]310ebd6302011-10-10 19:06:282492void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172493 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152494 if (!frame->parent()) {
2495 WebDataSource* ds = frame->provisionalDataSource();
2496 // If there's no provisional data source, it's a reference fragment
2497 // navigation.
2498 completed_client_redirect_src_ = Referrer(
[email protected]b9fd01ba2012-02-28 01:50:402499 from, ds ? GetReferrerPolicyFromRequest(ds->request()) :
[email protected]445e1042011-12-03 21:03:152500 frame->referrerPolicy());
2501 }
[email protected]eb0bff942011-04-07 22:08:382502 FOR_EACH_OBSERVER(
2503 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172504}
2505
[email protected]310ebd6302011-10-10 19:06:282506void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]007733c2011-11-17 00:34:072507 DocumentState* document_state = DocumentState::FromDataSource(ds);
2508 if (!document_state) {
2509 document_state = new DocumentState;
2510 ds->setExtraData(document_state);
2511 }
2512
[email protected]3d9689372009-09-10 04:29:172513 // The rest of RenderView assumes that a WebDataSource will always have a
2514 // non-null NavigationState.
[email protected]007733c2011-11-17 00:34:072515 bool content_initiated = !pending_navigation_params_.get();
2516 if (content_initiated)
2517 document_state->set_navigation_state(
2518 NavigationState::CreateContentInitiated());
2519 else
2520 PopulateStateFromPendingNavigationParams(document_state);
[email protected]8a3125a712010-08-09 18:58:512521
[email protected]007733c2011-11-17 00:34:072522 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512523 // navigating from a page that used prefetching using a link on that
2524 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072525 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512526 // this value appropriately.
2527 // TODO(gavinp): catch the important case of navigation in a new
2528 // renderer process.
2529 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302530 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522531 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512532 const GURL referrer(
2533 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2534 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072535 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512536 old_frame->dataSource())->was_prefetcher()) {
2537 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2538 WebDataSource* old_frame_ds = old_frame->dataSource();
2539 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072540 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512541 break;
2542 }
2543 }
2544 }
2545 }
2546 }
2547
[email protected]4c1b6f0b2010-02-07 16:38:182548 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522549 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512550 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182551 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072552 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182553 break;
2554 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072555 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182556 break;
2557 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072558 document_state->set_load_type(
2559 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182560 break;
2561 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072562 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182563 break;
2564 }
2565 }
[email protected]fa7b6b542009-11-03 05:02:302566
[email protected]946a0032011-03-31 18:42:282567 FOR_EACH_OBSERVER(
2568 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172569}
2570
[email protected]007733c2011-11-17 00:34:072571void RenderViewImpl::PopulateStateFromPendingNavigationParams(
2572 DocumentState* document_state) {
2573 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
2574
2575 if (document_state->request_time().is_null())
2576 document_state->set_request_time(params.request_time);
2577
2578 // A navigation resulting from loading a javascript URL should not be treated
2579 // as a browser initiated event. Instead, we want it to look as if the page
2580 // initiated any load resulting from JS execution.
2581 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
2582 NavigationState* navigation_state = NavigationState::CreateBrowserInitiated(
2583 params.page_id,
2584 params.pending_history_list_offset,
2585 params.transition);
[email protected]4ad5d77d2011-12-03 02:00:482586 navigation_state->set_transferred_request_child_id(
2587 params.transferred_request_child_id);
2588 navigation_state->set_transferred_request_request_id(
2589 params.transferred_request_request_id);
[email protected]007733c2011-11-17 00:34:072590 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
2591 // We're doing a load of a page that was restored from the last session.
2592 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
2593 // which can result in stale data for pages that are set to expire. We
2594 // explicitly override that by setting the policy here so that as
2595 // necessary we load from the network.
2596 document_state->set_cache_policy_override(
2597 WebURLRequest::UseProtocolCachePolicy);
2598 }
2599 document_state->set_navigation_state(navigation_state);
2600 } else {
2601 document_state->set_navigation_state(
2602 NavigationState::CreateContentInitiated());
2603 }
2604
2605 if (IsReload(params))
2606 document_state->set_load_type(DocumentState::RELOAD);
2607 else if (!params.state.empty())
2608 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2609 else
2610 document_state->set_load_type(DocumentState::NORMAL_LOAD);
2611
2612 pending_navigation_params_.reset();
2613}
2614
[email protected]310ebd6302011-10-10 19:06:282615void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172616 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:072617 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:172618
[email protected]3d9689372009-09-10 04:29:172619 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:072620 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:172621 double event_time = ds->triggeringEventTime();
2622 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:072623 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:172624 }
2625
[email protected]05c8e502010-08-15 15:13:522626 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:072627 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:522628
[email protected]3d9689372009-09-10 04:29:172629 bool is_top_most = !frame->parent();
2630 if (is_top_most) {
2631 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132632 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172633
2634 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:152635 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172636 } else if (frame->parent()->isLoading()) {
2637 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002638 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:072639 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:582640 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172641 }
2642
[email protected]28685da92011-02-07 21:49:172643 FOR_EACH_OBSERVER(
2644 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2645
[email protected]3d9689372009-09-10 04:29:172646 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592647 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262648 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172649}
2650
[email protected]310ebd6302011-10-10 19:06:282651void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2652 WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172653 if (frame->parent())
2654 return;
2655 // Received a redirect on the main frame.
2656 WebDataSource* data_source = frame->provisionalDataSource();
2657 if (!data_source) {
2658 // Should only be invoked when we have a data source.
2659 NOTREACHED();
2660 return;
2661 }
2662 std::vector<GURL> redirects;
2663 GetRedirectChain(data_source, &redirects);
2664 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512665 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592666 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172667 }
2668}
2669
[email protected]310ebd6302011-10-10 19:06:282670void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2671 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172672 // Notify the browser that we failed a provisional load with an error.
2673 //
2674 // Note: It is important this notification occur before DidStopLoading so the
2675 // SSL manager can react to the provisional load failure before being
2676 // notified the load stopped.
2677 //
2678 WebDataSource* ds = frame->provisionalDataSource();
2679 DCHECK(ds);
2680
2681 const WebURLRequest& failed_request = ds->request();
2682
[email protected]28685da92011-02-07 21:49:172683 FOR_EACH_OBSERVER(
2684 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2685
[email protected]3d9689372009-09-10 04:29:172686 bool show_repost_interstitial =
2687 (error.reason == net::ERR_CACHE_MISS &&
2688 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582689
2690 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2691 params.frame_id = frame->identifier();
2692 params.is_main_frame = !frame->parent();
2693 params.error_code = error.reason;
2694 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2695 failed_request,
2696 error,
2697 NULL,
2698 &params.error_description);
2699 params.url = error.unreachableURL;
2700 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172701 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582702 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172703
2704 // Don't display an error page if this is simply a cancelled load. Aside
2705 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2706 if (error.reason == net::ERR_ABORTED)
2707 return;
[email protected]b553edd52012-01-10 12:15:232708 // Don't display an error message if the request was handled by an
2709 // external protocol handler.
2710 if (error.reason == net::ERR_UNKNOWN_URL_SCHEME)
2711 return;
[email protected]3d9689372009-09-10 04:29:172712
2713 // Make sure we never show errors in view source mode.
2714 frame->enableViewSourceMode(false);
2715
[email protected]007733c2011-11-17 00:34:072716 DocumentState* document_state = DocumentState::FromDataSource(ds);
2717 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172718
2719 // If this is a failed back/forward/reload navigation, then we need to do a
2720 // 'replace' load. This is necessary to avoid messing up session history.
2721 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2722 // as session history is concerned.
2723 //
2724 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2725 // the page id.
2726 //
2727 bool replace =
2728 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:582729 navigation_state->transition_type() ==
2730 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:172731
2732 // If we failed on a browser initiated request, then make sure that our error
2733 // page load is regarded as the same browser initiated request.
2734 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:072735 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
2736 pending_navigation_params_->page_id =
2737 navigation_state->pending_page_id();
2738 pending_navigation_params_->pending_history_list_offset =
2739 navigation_state->pending_history_list_offset();
2740 pending_navigation_params_->transition =
2741 navigation_state->transition_type();
2742 pending_navigation_params_->request_time =
2743 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:172744 }
2745
2746 // Provide the user with a more helpful error page?
2747 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2748 return;
2749
2750 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082751 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172752}
2753
[email protected]310ebd6302011-10-10 19:06:282754void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:172755 WebFrame* frame, const char* data, size_t data_len,
2756 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:072757 DocumentState* document_state =
2758 DocumentState::FromDataSource(frame->dataSource());
2759 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172760}
2761
[email protected]310ebd6302011-10-10 19:06:282762void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2763 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:072764 DocumentState* document_state =
2765 DocumentState::FromDataSource(frame->dataSource());
2766 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172767
[email protected]007733c2011-11-17 00:34:072768 if (document_state->commit_load_time().is_null())
2769 document_state->set_commit_load_time(Time::Now());
2770
[email protected]3d9689372009-09-10 04:29:172771 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202772 // When we perform a new navigation, we need to update the last committed
2773 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172774 UpdateSessionHistory(frame);
2775
2776 // We bump our Page ID to correspond with the new session history entry.
2777 page_id_ = next_page_id_++;
2778
[email protected]69ddf852012-02-21 23:21:312779 // Don't update history_page_ids_ (etc) for about:swappedout, since we
2780 // don't want to forget the entry that was there, and since we will
2781 // never come back to about:swappedout. Note that we have to call
2782 // UpdateSessionHistory and update page_id_ even in this case, so that
2783 // the current entry gets a state update and so that we don't send a
2784 // state update to the wrong entry when we swap back in.
2785 if (GetLoadingUrl(frame) != GURL("about:swappedout")) {
2786 // Advance our offset in session history, applying the length limit.
2787 // There is now no forward history.
2788 history_list_offset_++;
2789 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2790 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
2791 history_list_length_ = history_list_offset_ + 1;
2792 history_page_ids_.resize(history_list_length_, -1);
2793 history_page_ids_[history_list_offset_] = page_id_;
2794 }
[email protected]3d9689372009-09-10 04:29:172795 } else {
2796 // Inspect the navigation_state on this frame to see if the navigation
2797 // corresponds to a session history navigation... Note: |frame| may or
2798 // may not be the toplevel frame, but for the case of capturing session
2799 // history, the first committed frame suffices. We keep track of whether
2800 // we've seen this commit before so that only capture session history once
2801 // per navigation.
2802 //
2803 // Note that we need to check if the page ID changed. In the case of a
2804 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2805 // previous URL and the current page ID, which would be wrong.
2806 if (navigation_state->pending_page_id() != -1 &&
2807 navigation_state->pending_page_id() != page_id_ &&
2808 !navigation_state->request_committed()) {
2809 // This is a successful session history navigation!
2810 UpdateSessionHistory(frame);
2811 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002812
2813 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032814
2815 // If the history list is valid, our list of page IDs should be correct.
2816 DCHECK(history_list_length_ <= 0 ||
2817 history_list_offset_ < 0 ||
2818 history_list_offset_ >= history_list_length_ ||
2819 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172820 }
2821 }
2822
[email protected]28685da92011-02-07 21:49:172823 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2824 DidCommitProvisionalLoad(frame, is_new_navigation));
2825
[email protected]3d9689372009-09-10 04:29:172826 // Remember that we've already processed this request, so we don't update
2827 // the session history again. We do this regardless of whether this is
2828 // a session history navigation, because if we attempted a session history
2829 // navigation without valid HistoryItem state, WebCore will think it is a
2830 // new navigation.
2831 navigation_state->set_request_committed(true);
2832
2833 UpdateURL(frame);
2834
2835 // If this committed load was initiated by a client redirect, we're
2836 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:152837 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172838
2839 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272840 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172841}
2842
[email protected]310ebd6302011-10-10 19:06:282843void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102844 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2845 DidClearWindowObject(frame));
2846
[email protected]b6cb3a842011-06-24 18:28:412847 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:212848 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:252849 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2850 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272851 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172852 }
[email protected]766a7082012-02-03 23:39:152853
2854 if (enabled_bindings_ & content::BINDINGS_POLICY_DOM_AUTOMATION) {
2855 if (!dom_automation_controller_.get())
2856 dom_automation_controller_.reset(new DomAutomationController());
2857 dom_automation_controller_->set_message_sender(
2858 static_cast<content::RenderView*>(this));
2859 dom_automation_controller_->set_routing_id(routing_id());
2860 dom_automation_controller_->BindToJavascript(frame,
2861 "domAutomationController");
2862 }
[email protected]3d9689372009-09-10 04:29:172863}
2864
[email protected]310ebd6302011-10-10 19:06:282865void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172866 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412867 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252868 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272869 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172870 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2871 }
[email protected]e48869a2011-04-01 19:56:032872
2873 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2874 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172875}
2876
[email protected]310ebd6302011-10-10 19:06:282877void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
2878 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462879 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172880
2881 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272882 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172883}
2884
[email protected]310ebd6302011-10-10 19:06:282885void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:132886 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2887 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582888}
2889
[email protected]310ebd6302011-10-10 19:06:282890void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172891 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072892 DocumentState* document_state = DocumentState::FromDataSource(ds);
2893 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:172894
[email protected]622474d2010-11-04 09:21:082895 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172896
[email protected]28685da92011-02-07 21:49:172897 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2898 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172899
2900 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272901 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172902}
2903
[email protected]310ebd6302011-10-10 19:06:282904void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082905 if (webview()->mainFrame() == frame) {
2906 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2907 page_id_));
2908 }
[email protected]3d9689372009-09-10 04:29:172909}
2910
[email protected]310ebd6302011-10-10 19:06:282911void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:312912 WebDataSource* ds = frame->dataSource();
2913 DCHECK(ds);
2914
2915
[email protected]28685da92011-02-07 21:49:172916 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:312917
2918 const WebURLRequest& failed_request = ds->request();
2919 string16 error_description;
2920 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2921 failed_request,
2922 error,
2923 NULL,
2924 &error_description);
2925 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
2926 frame->identifier(),
2927 failed_request.url(),
2928 !frame->parent(),
2929 error.reason,
2930 error_description));
[email protected]3d9689372009-09-10 04:29:172931}
2932
[email protected]310ebd6302011-10-10 19:06:282933void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172934 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072935 DocumentState* document_state = DocumentState::FromDataSource(ds);
2936 if (document_state->finish_load_time().is_null())
2937 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412938
[email protected]676126f72011-01-15 00:03:512939 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172940
[email protected]1a55c5be2011-11-29 11:36:312941 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
2942 frame->identifier(),
2943 ds->request().url(),
2944 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:172945}
2946
[email protected]310ebd6302011-10-10 19:06:282947void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172948 WebFrame* frame, bool is_new_navigation) {
2949 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:072950 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:172951 // update the ExtraData on the datasource so that others who read the
2952 // ExtraData will get the new NavigationState. Similarly, if we did not
2953 // initiate this navigation, then we need to take care to reset any pre-
2954 // existing navigation state to a content-initiated navigation state.
2955 // DidCreateDataSource conveniently takes care of this for us.
2956 didCreateDataSource(frame, frame->dataSource());
2957
[email protected]007733c2011-11-17 00:34:072958 DocumentState* document_state =
2959 DocumentState::FromDataSource(frame->dataSource());
2960 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:092961 new_state->set_was_within_same_page(true);
2962
[email protected]3d9689372009-09-10 04:29:172963 didCommitProvisionalLoad(frame, is_new_navigation);
2964
[email protected]750fcf872011-08-03 23:10:472965 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2966 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172967}
2968
[email protected]310ebd6302011-10-10 19:06:282969void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312970 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592971}
2972
[email protected]310ebd6302011-10-10 19:06:282973void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:172974 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2975 // Ignore
2976}
2977
[email protected]310ebd6302011-10-10 19:06:282978void RenderViewImpl::willSendRequest(WebFrame* frame,
2979 unsigned identifier,
2980 WebURLRequest& request,
2981 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302982 WebFrame* top_frame = frame->top();
2983 if (!top_frame)
2984 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512985 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2986 WebDataSource* top_data_source = top_frame->dataSource();
2987 WebDataSource* data_source =
2988 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222989
[email protected]78d5cfe2011-02-04 08:43:222990 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032991 GURL new_url;
2992 if (content::GetContentClient()->renderer()->WillSendRequest(
2993 frame, request_url, &new_url)) {
2994 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222995 }
2996
[email protected]2905f742011-10-13 03:51:582997 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:072998 DocumentState* document_state = DocumentState::FromDataSource(data_source);
2999 NavigationState* navigation_state = document_state->navigation_state();
3000 if (document_state) {
3001 if (document_state->is_cache_policy_override_set())
3002 request.setCachePolicy(document_state->cache_policy_override());
3003 transition_type = navigation_state->transition_type();
[email protected]5e369672009-11-03 23:48:303004 }
[email protected]8a3125a712010-08-09 18:58:513005
[email protected]91043a8232011-11-04 16:41:193006 request.setExtraData(
[email protected]537fbe02011-11-24 00:58:063007 new RequestExtraData(frame->referrerPolicy(),
3008 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:193009 frame->identifier(),
3010 frame->parent() == top_frame,
3011 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]4ad5d77d2011-12-03 02:00:483012 transition_type,
3013 navigation_state->transferred_request_child_id(),
3014 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:573015
[email protected]007733c2011-11-17 00:34:073016 DocumentState* top_document_state =
3017 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:573018 // TODO(gavinp): separate out prefetching and prerender field trials
3019 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:073020 if (top_document_state &&
[email protected]d88bf0a2011-08-30 23:55:573021 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
3022 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]007733c2011-11-17 00:34:073023 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513024
[email protected]3d9689372009-09-10 04:29:173025 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133026 request.setHasUserGesture(frame->isProcessingUserGesture());
3027
[email protected]0a8db0d2011-04-13 15:15:403028 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:133029 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:173030}
3031
[email protected]310ebd6302011-10-10 19:06:283032void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173033 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493034
[email protected]3d9689372009-09-10 04:29:173035 // Only do this for responses that correspond to a provisional data source
3036 // of the top-most frame. If we have a provisional data source, then we
3037 // can't have any sub-resources yet, so we know that this response must
3038 // correspond to a frame load.
3039 if (!frame->provisionalDataSource() || frame->parent())
3040 return;
3041
3042 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083043 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173044 if (frame->isViewSourceModeEnabled())
3045 return;
3046
[email protected]007733c2011-11-17 00:34:073047 DocumentState* document_state =
3048 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083049 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533050
[email protected]972ebdff2010-06-10 22:59:073051 // Record page load flags.
[email protected]007733c2011-11-17 00:34:073052 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3053 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]b9fd01ba2012-02-28 01:50:403054 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
3055 if (extra_data) {
3056 document_state->set_npn_negotiated_protocol(
3057 extra_data->npn_negotiated_protocol());
3058 }
[email protected]007733c2011-11-17 00:34:073059 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:573060 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:073061 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3062 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093063 // Whether or not the http status code actually corresponds to an error is
3064 // only checked when the page is done loading, if |use_error_page| is
3065 // still true.
[email protected]007733c2011-11-17 00:34:073066 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173067}
3068
[email protected]310ebd6302011-10-10 19:06:283069void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173070 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:073071 DocumentState* document_state =
3072 DocumentState::FromDataSource(frame->dataSource());
3073 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173074 return;
3075
[email protected]7bfc153f2011-09-23 22:00:203076 // Do not show error page when DevTools is attached.
3077 if (devtools_agent_->IsAttached())
3078 return;
3079
[email protected]06333afe2011-02-24 14:55:093080 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:073081 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:083082 if (http_status_code == 404) {
3083 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413084 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173085
[email protected]b6cb3a842011-06-24 18:28:413086 const GURL& error_page_url =
3087 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093088 if (error_page_url.is_valid()) {
3089 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473090 original_error.domain = "http";
3091 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413092 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173093
[email protected]007733c2011-11-17 00:34:073094 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093095 new AltErrorPageResourceFetcher(
3096 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:083097 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3098 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093099 return;
3100 }
3101 }
[email protected]3d9689372009-09-10 04:29:173102
[email protected]e6a2ce52011-10-08 01:40:133103 std::string error_domain;
3104 if (content::GetContentClient()->renderer()->HasErrorPage(
3105 http_status_code, &error_domain)) {
3106 WebURLError error;
3107 error.unreachableURL = frame->document().url();
3108 error.domain = WebString::fromUTF8(error_domain);
3109 error.reason = http_status_code;
3110
3111 LoadNavigationErrorPage(
3112 frame, frame->dataSource()->request(), error, std::string(), true);
3113 }
[email protected]3d9689372009-09-10 04:29:173114}
3115
[email protected]310ebd6302011-10-10 19:06:283116void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173117 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3118 // Ignore
3119}
3120
[email protected]310ebd6302011-10-10 19:06:283121void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173122 WebFrame* frame, const WebURLRequest& request,
3123 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003124 // The recipients of this message have no use for data: URLs: they don't
3125 // affect the page's insecure content list and are not in the disk cache. To
3126 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3127 // filter them out here.
3128 GURL url(request.url());
3129 if (url.SchemeIs("data"))
3130 return;
3131
[email protected]3d9689372009-09-10 04:29:173132 // Let the browser know we loaded a resource from the memory cache. This
3133 // message is needed to display the correct SSL indicators.
3134 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3135 routing_id_,
[email protected]84703292011-10-28 20:44:003136 url,
[email protected]70435962011-08-02 20:13:283137 response.securityInfo(),
3138 request.httpMethod().utf8(),
3139 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173140}
3141
[email protected]310ebd6302011-10-10 19:06:283142void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293143 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3144}
3145
[email protected]310ebd6302011-10-10 19:06:283146void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023147 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293148 Send(new ViewHostMsg_DidRunInsecureContent(
3149 routing_id_,
[email protected]92771112011-01-20 00:13:023150 origin.toString().utf8(),
3151 target));
[email protected]e3d60e5d2009-09-25 21:08:293152}
3153
[email protected]310ebd6302011-10-10 19:06:283154void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
[email protected]b00ba702011-08-17 01:41:033155 webkit_glue::WebURLLoaderImpl* loader_impl =
3156 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
3157 loader_impl->UpdateRoutingId(routing_id_);
3158}
3159
[email protected]310ebd6302011-10-10 19:06:283160void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173161 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3162}
3163
[email protected]310ebd6302011-10-10 19:06:283164void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3165 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583166 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283167 int world_id) {
[email protected]5bc10932011-09-21 21:03:303168 content::GetContentClient()->renderer()->DidCreateScriptContext(
[email protected]a00fe692012-02-27 05:52:583169 frame, context, extension_group, world_id);
3170}
3171
3172void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3173 v8::Handle<v8::Context> context,
3174 int world_id) {
3175 content::GetContentClient()->renderer()->DidCreateScriptContext(
3176 frame, context, -1, world_id);
[email protected]0c882b282009-10-07 17:01:283177}
3178
[email protected]310ebd6302011-10-10 19:06:283179void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3180 v8::Handle<v8::Context> context,
3181 int world_id) {
[email protected]5bc10932011-09-21 21:03:303182 content::GetContentClient()->renderer()->WillReleaseScriptContext(
3183 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283184}
3185
[email protected]310ebd6302011-10-10 19:06:283186void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073187 // We don't always want to send the change messages over IPC, only if we've
3188 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3189 // message.
3190 if (!send_preferred_size_changes_ || !webview())
3191 return;
3192
[email protected]705243f2010-05-05 19:58:073193 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3194 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533195
3196 // In the presence of zoom, these sizes are still reported as if unzoomed,
3197 // so we need to adjust.
3198 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3199 size.set_width(static_cast<int>(size.width() * zoom_factor));
3200 size.set_height(static_cast<int>(size.height() * zoom_factor));
3201
[email protected]705243f2010-05-05 19:58:073202 if (size == preferred_size_)
3203 return;
[email protected]c27324b2009-11-19 22:44:293204
[email protected]705243f2010-05-05 19:58:073205 preferred_size_ = size;
3206 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3207 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173208}
3209
[email protected]273558fb2012-01-12 15:03:513210void RenderViewImpl::EnsureMediaStreamImpl() {
3211#if defined(ENABLE_P2P_APIS)
3212 if (!p2p_socket_dispatcher_)
3213 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
3214#endif
3215
[email protected]5b87e782012-02-09 18:19:323216#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:513217 if (!media_stream_dispatcher_)
3218 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3219
3220 if (!media_stream_impl_.get()) {
3221 MediaStreamDependencyFactory* factory = new MediaStreamDependencyFactory();
3222 media_stream_impl_ = new MediaStreamImpl(
3223 media_stream_dispatcher_,
3224 p2p_socket_dispatcher_,
3225 RenderThreadImpl::current()->video_capture_impl_manager(),
3226 factory);
3227 }
[email protected]5b87e782012-02-09 18:19:323228#endif
[email protected]273558fb2012-01-12 15:03:513229}
3230
[email protected]310ebd6302011-10-10 19:06:283231void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3232 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313233 if (webview()->mainFrame() != frame)
3234 return;
3235 WebView* frameView = frame->view();
3236 if (!frameView)
3237 return;
3238
3239 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3240 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3241
3242 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3243 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3244 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3245 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3246
3247 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3248 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3249 }
3250}
3251
[email protected]310ebd6302011-10-10 19:06:283252void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313253 WebSize offset = frame->scrollOffset();
3254 WebSize minimum_offset = frame->minimumScrollOffset();
3255 WebSize maximum_offset = frame->maximumScrollOffset();
3256
3257 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3258 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3259
3260 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3261 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3262 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3263 routing_id_, is_pinned_to_left, is_pinned_to_right));
3264
3265 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3266 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3267 }
3268}
3269
[email protected]310ebd6302011-10-10 19:06:283270void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493271 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313272
3273 if (webview()->mainFrame() == frame)
3274 UpdateScrollState(frame);
3275}
3276
[email protected]310ebd6302011-10-10 19:06:283277void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:313278 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:493279}
3280
[email protected]ea931252012-02-15 22:01:033281void RenderViewImpl::numberOfTouchEventHandlersChanged(unsigned num_handlers) {
3282 Send(new ViewHostMsg_DidChangeNumTouchEvents(routing_id_, num_handlers));
3283}
3284
[email protected]310ebd6302011-10-10 19:06:283285void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
3286 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113287 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3288 if (!count)
3289 active_match_ordinal = 0;
3290
3291 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3292 routing_id_,
3293 request_id,
3294 count,
3295 gfx::Rect(),
3296 active_match_ordinal,
3297 final_update);
3298
[email protected]8922e1f2009-10-03 05:01:263299 // If we have a message that has been queued up, then we should just replace
3300 // it. The ACK from the browser will make sure it gets sent when the browser
3301 // wants it.
3302 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263303 queued_find_reply_message_.reset(msg);
3304 } else {
3305 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113306 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263307 }
3308}
3309
[email protected]310ebd6302011-10-10 19:06:283310void RenderViewImpl::reportFindInPageSelection(int request_id,
3311 int active_match_ordinal,
3312 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:263313 // Send the search result over to the browser process.
3314 Send(new ViewHostMsg_Find_Reply(routing_id_,
3315 request_id,
3316 -1,
3317 selection_rect,
3318 active_match_ordinal,
3319 false));
3320}
3321
[email protected]310ebd6302011-10-10 19:06:283322void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:223323 WebFrame* frame,
3324 WebFileSystem::Type type,
3325 long long size,
[email protected]d275d7a2010-11-03 01:34:493326 bool create,
[email protected]2b06a992010-08-21 05:48:223327 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083328 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223329
[email protected]b6cb3a842011-06-24 18:28:413330 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563331 if (origin.isUnique()) {
3332 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:083333 callbacks->didFail(WebKit::WebFileErrorAbort);
3334 return;
3335 }
[email protected]2b06a992010-08-21 05:48:223336
[email protected]c5a272d2010-09-27 18:37:083337 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3338 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493339 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223340}
3341
[email protected]310ebd6302011-10-10 19:06:283342void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:403343 WebFrame* frame,
3344 WebStorageQuotaType type,
3345 WebStorageQuotaCallbacks* callbacks) {
3346 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413347 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563348 if (origin.isUnique()) {
3349 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403350 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3351 return;
3352 }
3353 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533354 GURL(origin.toString()),
3355 static_cast<quota::StorageType>(type),
3356 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403357}
3358
[email protected]310ebd6302011-10-10 19:06:283359void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:403360 WebFrame* frame,
3361 WebStorageQuotaType type,
3362 unsigned long long requested_size,
3363 WebStorageQuotaCallbacks* callbacks) {
3364 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413365 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563366 if (origin.isUnique()) {
3367 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403368 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3369 return;
3370 }
3371 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533372 routing_id(), GURL(origin.toString()),
3373 static_cast<quota::StorageType>(type), requested_size,
3374 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403375}
3376
[email protected]8b5af492011-11-28 21:50:583377void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:153378 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]e6e35cd2011-12-22 19:37:063379 string16 title = service.title();
3380 if (title.empty())
3381 title = webview()->mainFrame()->document().title();
3382
[email protected]8b5af492011-11-28 21:50:583383 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
3384 service.action(),
3385 service.type(),
3386 service.url().spec().utf16(),
[email protected]e6e35cd2011-12-22 19:37:063387 title,
[email protected]8b5af492011-11-28 21:50:583388 service.disposition()));
3389}
3390
[email protected]ffc8bed2012-01-21 01:23:153391void RenderViewImpl::dispatchIntent(
3392 WebFrame* frame, const WebIntentRequest& intentRequest) {
3393 webkit_glue::WebIntentData intent_data(intentRequest.intent());
3394 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:583395 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:153396 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:583397}
3398
[email protected]18d5be92011-07-25 18:00:193399// WebKit::WebPageSerializerClient implementation ------------------------------
3400
[email protected]310ebd6302011-10-10 19:06:283401void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:193402 const WebURL& frame_url,
3403 const WebCString& data,
3404 WebPageSerializerClient::PageSerializationStatus status) {
3405 Send(new ViewHostMsg_SendSerializedHtmlData(
3406 routing_id(),
3407 frame_url,
3408 data.data(),
3409 static_cast<int32>(status)));
3410}
3411
[email protected]a2ef54c2011-10-10 16:20:313412// content::RenderView implementation ------------------------------------------
3413
[email protected]310ebd6302011-10-10 19:06:283414bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:313415 return RenderWidget::Send(message);
3416}
3417
[email protected]9f76c1e2012-03-05 15:15:583418int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:313419 return routing_id_;
3420}
3421
[email protected]310ebd6302011-10-10 19:06:283422int RenderViewImpl::GetPageId() {
[email protected]a2ef54c2011-10-10 16:20:313423 return page_id_;
3424}
3425
[email protected]310ebd6302011-10-10 19:06:283426gfx::Size RenderViewImpl::GetSize() {
[email protected]a2ef54c2011-10-10 16:20:313427 return size();
3428}
3429
[email protected]310ebd6302011-10-10 19:06:283430gfx::NativeViewId RenderViewImpl::GetHostWindow() {
[email protected]a2ef54c2011-10-10 16:20:313431 return host_window();
3432}
3433
[email protected]310ebd6302011-10-10 19:06:283434WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313435 return webkit_preferences_;
3436}
3437
[email protected]310ebd6302011-10-10 19:06:283438WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313439 return webview();
3440}
3441
[email protected]310ebd6302011-10-10 19:06:283442WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313443 if (!webview())
3444 return WebNode();
3445 WebFrame* focused_frame = webview()->focusedFrame();
3446 if (focused_frame) {
3447 WebDocument doc = focused_frame->document();
3448 if (!doc.isNull())
3449 return doc.focusedNode();
3450 }
3451
3452 return WebNode();
3453}
3454
[email protected]310ebd6302011-10-10 19:06:283455WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313456 return context_menu_node_;
3457}
3458
[email protected]310ebd6302011-10-10 19:06:283459bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) {
[email protected]a2ef54c2011-10-10 16:20:313460 bool is_editable_node = false;
3461 if (!node.isNull()) {
3462 if (node.isContentEditable()) {
3463 is_editable_node = true;
3464 } else if (node.isElementNode()) {
3465 is_editable_node =
3466 node.toConst<WebElement>().isTextFormControlElement();
3467 }
3468 }
3469 return is_editable_node;
3470}
3471
[email protected]310ebd6302011-10-10 19:06:283472WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313473 WebKit::WebFrame* frame,
3474 const webkit::WebPluginInfo& info,
3475 const WebKit::WebPluginParams& params) {
3476 bool pepper_plugin_was_registered = false;
3477 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3478 pepper_delegate_.CreatePepperPluginModule(info,
3479 &pepper_plugin_was_registered));
3480 if (pepper_plugin_was_registered) {
3481 if (!pepper_module)
3482 return NULL;
3483 return new webkit::ppapi::WebPluginImpl(
3484 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3485 }
3486
[email protected]34b27e442012-01-20 20:07:413487#if defined(USE_AURA)
3488 return NULL;
3489#else
[email protected]a2ef54c2011-10-10 16:20:313490 return new webkit::npapi::WebPluginImpl(
3491 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:413492#endif
[email protected]a2ef54c2011-10-10 16:20:313493}
3494
[email protected]310ebd6302011-10-10 19:06:283495void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3496 const string16& jscript,
3497 int id,
3498 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313499 v8::Handle<v8::Value> result;
3500 WebFrame* web_frame = GetChildFrame(frame_xpath);
3501 if (web_frame)
3502 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3503 if (notify_result) {
3504 ListValue list;
3505 if (!result.IsEmpty() && web_frame) {
3506 v8::HandleScope handle_scope;
3507 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3508 v8::Context::Scope context_scope(context);
3509 V8ValueConverterImpl converter;
3510 converter.set_allow_date(true);
3511 converter.set_allow_regexp(true);
3512 list.Set(0, converter.FromV8Value(result, context));
3513 } else {
3514 list.Set(0, Value::CreateNullValue());
3515 }
3516 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3517 }
3518}
3519
[email protected]310ebd6302011-10-10 19:06:283520bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313521 return (!send_preferred_size_changes_ ||
3522 (disable_scrollbars_size_limit_.width() <= width ||
3523 disable_scrollbars_size_limit_.height() <= height));
3524}
3525
[email protected]310ebd6302011-10-10 19:06:283526int RenderViewImpl::GetEnabledBindings() {
[email protected]a2ef54c2011-10-10 16:20:313527 return enabled_bindings_;
3528}
3529
[email protected]310ebd6302011-10-10 19:06:283530bool RenderViewImpl::GetContentStateImmediately() {
[email protected]a2ef54c2011-10-10 16:20:313531 return send_content_state_immediately_;
3532}
3533
[email protected]310ebd6302011-10-10 19:06:283534float RenderViewImpl::GetFilteredTimePerFrame() {
[email protected]a2ef54c2011-10-10 16:20:313535 return filtered_time_per_frame();
3536}
3537
[email protected]310ebd6302011-10-10 19:06:283538void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
3539 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313540 showContextMenu(frame, data);
3541}
3542
[email protected]310ebd6302011-10-10 19:06:283543WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313544 return visibilityState();
3545}
3546
[email protected]310ebd6302011-10-10 19:06:283547void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3548 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313549 return runModalAlertDialog(frame, message);
3550}
3551
[email protected]310ebd6302011-10-10 19:06:283552void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313553 WebKit::WebFrame* frame,
3554 const WebKit::WebURLRequest& request,
3555 WebKit::WebNavigationPolicy policy) {
3556 loadURLExternally(frame, request, policy);
3557}
3558
3559// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513560
[email protected]310ebd6302011-10-10 19:06:283561webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533562 const FilePath& file_path,
3563 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:203564 if (!PluginChannelHost::IsListening()) {
3565 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:593566 return NULL;
[email protected]94752ee2012-02-10 10:38:203567 }
[email protected]f103ab72009-09-02 17:10:593568
[email protected]00c39612010-03-06 02:53:283569 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463570 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323571#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223572 return webkit::npapi::WebPluginDelegateImpl::Create(
3573 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093574#else
[email protected]7398dcc2011-09-06 21:40:323575 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223576 NOTIMPLEMENTED();
3577 return NULL;
[email protected]7b6616f2010-01-14 18:07:553578#endif
[email protected]f103ab72009-09-02 17:10:593579 }
3580
[email protected]4e0616e2010-05-28 14:55:533581 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593582}
3583
[email protected]310ebd6302011-10-10 19:06:283584void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033585#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273586 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593587#endif
3588}
3589
[email protected]310ebd6302011-10-10 19:06:283590void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033591#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273592 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593593#endif
3594 CleanupWindowInPluginMoves(window);
3595}
3596
[email protected]310ebd6302011-10-10 19:06:283597void RenderViewImpl::DidMovePlugin(
3598 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593599 SchedulePluginMove(move);
3600}
3601
[email protected]310ebd6302011-10-10 19:06:283602void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593603 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523604 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593605}
3606
[email protected]310ebd6302011-10-10 19:06:283607void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593608 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523609 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593610}
3611
[email protected]310ebd6302011-10-10 19:06:283612WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513613 return &cookie_jar_;
3614}
3615
[email protected]a9288f52011-11-17 05:18:163616void RenderViewImpl::DidPlay(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073617 Send(new ViewHostMsg_MediaNotification(routing_id_,
3618 reinterpret_cast<int64>(player),
3619 player->hasVideo(),
3620 player->hasAudio(),
3621 true));
3622}
3623
[email protected]a9288f52011-11-17 05:18:163624void RenderViewImpl::DidPause(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073625 Send(new ViewHostMsg_MediaNotification(routing_id_,
3626 reinterpret_cast<int64>(player),
3627 player->hasVideo(),
3628 player->hasAudio(),
3629 false));
3630}
3631
[email protected]a9288f52011-11-17 05:18:163632void RenderViewImpl::PlayerGone(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073633 DidPause(player);
3634}
3635
[email protected]310ebd6302011-10-10 19:06:283636void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:293637 if (!webview())
3638 return;
3639
[email protected]26aa0482009-09-30 16:55:273640 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173641 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293642 return;
[email protected]ca948a22009-06-25 19:36:173643
3644 Send(new ViewHostMsg_UpdateState(
3645 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293646}
3647
[email protected]310ebd6302011-10-10 19:06:283648void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:363649 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:003650 if (!frame)
3651 return;
[email protected]b781ff282011-08-20 06:19:363652
[email protected]e99ef6f2011-10-16 01:13:003653 string16 text;
3654 size_t offset;
[email protected]3c8c74c2012-03-15 07:34:523655 ui::Range range;
[email protected]e99ef6f2011-10-16 01:13:003656
[email protected]3c8c74c2012-03-15 07:34:523657 if (pepper_delegate_.IsPluginFocused()) {
3658 pepper_delegate_.GetSurroundingText(&text, &range);
3659 offset = 0; // Pepper API does not support offset reporting.
3660 // TODO(kinaba): cut as needed.
[email protected]e99ef6f2011-10-16 01:13:003661 } else {
[email protected]3c8c74c2012-03-15 07:34:523662 size_t location, length;
3663 if (!webview()->caretOrSelectionRange(&location, &length))
3664 return;
3665
3666 range = ui::Range(location, location + length);
3667
3668 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
3669 // If current focused element is editable, we will send 100 more chars
3670 // before and after selection. It is for input method surrounding text
3671 // feature.
3672 if (location > kExtraCharsBeforeAndAfterSelection)
3673 offset = location - kExtraCharsBeforeAndAfterSelection;
3674 else
3675 offset = 0;
3676 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
3677 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
3678 if (!webrange.isNull())
3679 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
3680 } else {
3681 offset = location;
3682 text = frame->selectionAsText();
3683 // http://crbug.com/101435
3684 // In some case, frame->selectionAsText() returned text's length is not
3685 // equal to the length returned from webview()->caretOrSelectionRange().
3686 // So we have to set the range according to text.length().
3687 range.set_end(range.start() + text.length());
3688 }
[email protected]b781ff282011-08-20 06:19:363689 }
3690
[email protected]b781ff282011-08-20 06:19:363691 // Sometimes we get repeated didChangeSelection calls from webkit when
3692 // the selection hasn't actually changed. We don't want to report these
3693 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:003694 if (selection_text_offset_ != offset ||
3695 selection_range_ != range ||
3696 selection_text_ != text) {
3697 selection_text_ = text;
3698 selection_text_offset_ = offset;
3699 selection_range_ = range;
3700 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
3701 }
[email protected]b781ff282011-08-20 06:19:363702}
3703
[email protected]310ebd6302011-10-10 19:06:283704GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
3705 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553706 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293707 // If the URL that failed was secure, then the embedding web page was not
3708 // expecting a network attacker to be able to manipulate its contents. As
3709 // we fetch alternate error pages over HTTP, we would be allowing a network
3710 // attacker to manipulate the contents of the response if we tried to use
3711 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153712 return GURL();
initial.commit09911bf2008-07-26 23:55:293713 }
3714
3715 // Grab the base URL from the browser process.
3716 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153717 return GURL();
initial.commit09911bf2008-07-26 23:55:293718
3719 // Strip query params from the failed URL.
3720 GURL::Replacements remove_params;
3721 remove_params.ClearUsername();
3722 remove_params.ClearPassword();
3723 remove_params.ClearQuery();
3724 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553725 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503726 std::string spec_to_send = url_to_send.spec();
3727 // Notify link doctor of the url truncation by sending of "?" at the end.
3728 if (failed_url.has_query())
3729 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293730
3731 // Construct the query params to send to link doctor.
3732 std::string params(alternate_error_page_url_.query());
3733 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023734 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293735 params.append("&sourceid=chrome");
3736 params.append("&error=");
3737 switch (error_type) {
3738 case DNS_ERROR:
3739 params.append("dnserror");
3740 break;
3741
3742 case HTTP_404:
3743 params.append("http404");
3744 break;
3745
[email protected]5df266ac2008-10-15 19:50:133746 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333747 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133748 break;
3749
initial.commit09911bf2008-07-26 23:55:293750 default:
3751 NOTREACHED() << "unknown ErrorPageType";
3752 }
3753
3754 // OK, build the final url to return.
3755 GURL::Replacements link_doctor_params;
3756 link_doctor_params.SetQueryStr(params);
3757 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3758 return url;
3759}
3760
[email protected]310ebd6302011-10-10 19:06:283761GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:593762 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3763 return GURL();
3764 else
3765 return creator_url_;
3766}
3767
[email protected]69ddf852012-02-21 23:21:313768GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
3769 WebDataSource* ds = frame->dataSource();
3770 if (ds->hasUnreachableURL())
3771 return ds->unreachableURL();
3772
3773 const WebURLRequest& request = ds->request();
3774 return request.url();
3775}
3776
[email protected]310ebd6302011-10-10 19:06:283777WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:273778 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:313779 web_ui_bindings_.reset(new WebUIBindings(
3780 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:463781 }
[email protected]c50008512011-02-03 01:17:273782 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463783}
3784
[email protected]310ebd6302011-10-10 19:06:283785WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:013786 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493787}
3788
[email protected]310ebd6302011-10-10 19:06:283789void RenderViewImpl::OnFind(int request_id, const string16& search_text,
3790 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273791 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493792
[email protected]872542532011-06-23 00:43:163793 // Check if the plugin still exists in the document.
3794 if (main_frame->document().isPluginDocument() &&
3795 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493796 if (options.findNext) {
3797 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013798 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493799 } else {
[email protected]afdbd142010-07-10 08:01:233800 if (GetWebPluginFromPluginDocument()->startFind(
3801 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493802 } else {
[email protected]e7c58a32010-08-13 19:47:113803 // Send "no results".
3804 Send(new ViewHostMsg_Find_Reply(routing_id_,
3805 request_id,
3806 0,
3807 gfx::Rect(),
3808 0,
3809 true));
[email protected]24a7f3c2010-03-25 08:26:493810 }
3811 }
3812 return;
3813 }
3814
[email protected]b4bb2502009-10-01 22:35:273815 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273816 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293817 WebFrame* search_frame = focused_frame; // start searching focused frame.
3818
3819 bool multi_frame = (frame_after_main != main_frame);
3820
3821 // If we have multiple frames, we don't want to wrap the search within the
3822 // frame, so we check here if we only have main_frame in the chain.
3823 bool wrap_within_frame = !multi_frame;
3824
[email protected]b3f2b912009-04-09 16:18:523825 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293826 bool result = false;
3827
[email protected]7830da3e2009-11-06 16:27:263828 // If something is selected when we start searching it means we cannot just
3829 // increment the current match ordinal; we need to re-generate it.
3830 WebRange current_selection = focused_frame->selectionRange();
3831
initial.commit09911bf2008-07-26 23:55:293832 do {
[email protected]dd7daa82009-08-10 05:46:453833 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593834 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293835
3836 if (!result) {
3837 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223838 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293839
3840 // Find the next frame, but skip the invisible ones.
3841 do {
3842 // What is the next frame to search? (we might be going backwards). Note
3843 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593844 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273845 search_frame->traverseNext(true) :
3846 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453847 } while (!search_frame->hasVisibleContent() &&
3848 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293849
[email protected]884db412008-11-24 23:46:503850 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223851 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293852
3853 // If we have multiple frames and we have wrapped back around to the
3854 // focused frame, we need to search it once more allowing wrap within
3855 // the frame, otherwise it will report 'no match' if the focused frame has
3856 // reported matches, but no frames after the focused_frame contain a
3857 // match for the search word(s).
3858 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453859 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593860 request_id, search_text, options, true, // Force wrapping.
3861 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293862 }
3863 }
3864
[email protected]26aa0482009-09-30 16:55:273865 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293866 } while (!result && search_frame != focused_frame);
3867
[email protected]7830da3e2009-11-06 16:27:263868 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293869 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453870 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293871 } else {
3872 // If nothing is found, set result to "0 of 0", otherwise, set it to
3873 // "-1 of 1" to indicate that we found at least one item, but we don't know
3874 // yet what is active.
3875 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3876 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293877
[email protected]4f3dc372009-02-24 00:10:293878 // If we find no matches then this will be our last status update.
3879 // Otherwise the scoping effort will send more results.
3880 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293881
[email protected]4f3dc372009-02-24 00:10:293882 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403883 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593884 request_id,
[email protected]4f3dc372009-02-24 00:10:293885 match_count,
3886 selection_rect,
3887 ordinal,
3888 final_status_update));
initial.commit09911bf2008-07-26 23:55:293889
initial.commit09911bf2008-07-26 23:55:293890 // Scoping effort begins, starting with the mainframe.
3891 search_frame = main_frame;
3892
[email protected]dd7daa82009-08-10 05:46:453893 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293894
3895 do {
3896 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453897 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293898
3899 // We don't start another scoping effort unless at least one match has
3900 // been found.
3901 if (result) {
3902 // Start new scoping request. If the scoping function determines that it
3903 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453904 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593905 search_text,
3906 options,
initial.commit09911bf2008-07-26 23:55:293907 true); // reset the tickmarks
3908 }
3909
3910 // Iterate to the next frame. The frame will not necessarily scope, for
3911 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273912 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293913 } while (search_frame != main_frame);
3914 }
3915}
3916
[email protected]815dd9872011-11-23 18:40:303917void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:493918 WebView* view = webview();
3919 if (!view)
3920 return;
3921
3922 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163923 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013924 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493925 return;
3926 }
3927
[email protected]815dd9872011-11-23 18:40:303928 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:493929 if (clear_selection)
3930 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3931
3932 WebFrame* frame = view->mainFrame();
3933 while (frame) {
3934 frame->stopFinding(clear_selection);
3935 frame = frame->traverseNext(false);
3936 }
3937
[email protected]815dd9872011-11-23 18:40:303938 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:493939 WebFrame* focused_frame = view->focusedFrame();
3940 if (focused_frame) {
3941 WebDocument doc = focused_frame->document();
3942 if (!doc.isNull()) {
3943 WebNode node = doc.focusedNode();
3944 if (!node.isNull())
3945 node.simulateClick();
3946 }
3947 }
3948 }
3949}
3950
[email protected]310ebd6302011-10-10 19:06:283951void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:493952 // Check if there is any queued up request waiting to be sent.
3953 if (queued_find_reply_message_.get()) {
3954 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423955 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493956 }
3957}
3958
[email protected]54087fe2011-10-28 22:02:483959void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:513960 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3961 return;
3962
[email protected]258d31122010-05-09 10:59:413963 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:103964
[email protected]b75b8292010-10-01 07:28:253965 double old_zoom_level = webview()->zoomLevel();
3966 double zoom_level;
[email protected]54087fe2011-10-28 22:02:483967 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:253968 zoom_level = 0;
3969 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3970 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:483971 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:253972 } else {
3973 // Either the user hit the zoom factor limit and thus the zoom level is now
3974 // not a whole number, or a plugin changed it to a custom value. We want
3975 // to go to the next whole number so that the user can always get back to
3976 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:483977 if ((old_zoom_level > 1 && zoom > 0) ||
3978 (old_zoom_level < 1 && zoom < 0)) {
3979 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:253980 } else {
3981 // We're going towards 100%, so first go to the next whole number.
3982 zoom_level = static_cast<int>(old_zoom_level);
3983 }
3984 }
[email protected]b75b8292010-10-01 07:28:253985 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:413986 zoomLevelChanged();
3987}
3988
3989void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
3990 int zoom_center_x, int zoom_center_y) {
3991 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
3992 kScalingIncrementForGesture);
3993}
3994
3995void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
3996 int zoom_center_x,
3997 int zoom_center_y,
3998 float scaling_increment) {
3999 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4000 return;
4001
[email protected]c514d6372011-08-16 22:54:444002 double old_page_scale_factor = webview()->pageScaleFactor();
4003 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:484004 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:444005 page_scale_factor = 1.0;
4006 } else {
4007 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:414008 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:444009 }
[email protected]47578fa02011-11-02 19:34:414010 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:094011 webview()->setPageScaleFactor(page_scale_factor,
4012 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:414013 }
[email protected]40bd6582009-12-04 23:49:514014}
4015
[email protected]310ebd6302011-10-10 19:06:284016void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174017 webview()->hidePopups();
4018 webview()->setZoomLevel(false, zoom_level);
4019 zoomLevelChanged();
4020}
4021
[email protected]310ebd6302011-10-10 19:06:284022void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4023 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544024 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294025}
4026
[email protected]310ebd6302011-10-10 19:06:284027void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274028 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294029}
4030
[email protected]310ebd6302011-10-10 19:06:284031void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274032 WebString no_encoding;
4033 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184034}
4035
[email protected]310ebd6302011-10-10 19:06:284036WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454037 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274038 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454039
4040 // xpath string can represent a frame deep down the tree (across multiple
4041 // frame DOMs).
4042 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4043 // should break into 2 xpaths
4044 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:414045 std::vector<string16> xpaths;
4046 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:454047
[email protected]26aa0482009-09-30 16:55:274048 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:414049 for (std::vector<string16>::const_iterator i = xpaths.begin();
4050 frame && i != xpaths.end(); ++i) {
4051 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294052 }
4053
[email protected]dd7daa82009-08-10 05:46:454054 return frame;
initial.commit09911bf2008-07-26 23:55:294055}
4056
[email protected]310ebd6302011-10-10 19:06:284057void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4058 const string16& jscript,
4059 int id,
4060 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:534061 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294062}
4063
[email protected]310ebd6302011-10-10 19:06:284064void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
4065 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:414066 WebFrame* frame = GetChildFrame(frame_xpath);
4067 if (!frame)
[email protected]216813952011-05-19 22:21:264068 return;
[email protected]ae461542009-06-19 19:03:414069
[email protected]01cf589c2011-07-28 18:04:034070 frame->document().insertUserStyleSheet(
4071 WebString::fromUTF8(css),
4072 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:484073}
4074
[email protected]310ebd6302011-10-10 19:06:284075void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:094076 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294077}
4078
[email protected]310ebd6302011-10-10 19:06:284079void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
4080 const std::string& value) {
[email protected]808bda52012-03-09 22:43:324081 if (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI)
4082 GetWebUIBindings()->SetProperty(name, value);
4083 else
4084 NOTREACHED() << "WebUI bindings not enabled.";
initial.commit09911bf2008-07-26 23:55:294085}
4086
[email protected]310ebd6302011-10-10 19:06:284087void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
4088 const gfx::Point& client_point,
4089 const gfx::Point& screen_point,
4090 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:554091 WebDragOperation operation = webview()->dragTargetDragEnter(
4092 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:554093 client_point,
4094 screen_point,
4095 ops);
4096
4097 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4098}
4099
[email protected]310ebd6302011-10-10 19:06:284100void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
4101 const gfx::Point& screen_point,
4102 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:554103 WebDragOperation operation = webview()->dragTargetDragOver(
4104 client_point,
4105 screen_point,
4106 ops);
4107
4108 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4109}
4110
[email protected]310ebd6302011-10-10 19:06:284111void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:554112 webview()->dragTargetDragLeave();
4113}
4114
[email protected]310ebd6302011-10-10 19:06:284115void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
4116 const gfx::Point& screen_point) {
[email protected]59f4f2fa2011-03-23 01:00:554117 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:574118
4119 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:554120}
4121
[email protected]310ebd6302011-10-10 19:06:284122void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4123 const gfx::Point& screen_point,
4124 bool ended,
4125 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034126 if (ended) {
[email protected]26aa0482009-09-30 16:55:274127 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204128 } else {
4129 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034130 }
initial.commit09911bf2008-07-26 23:55:294131}
4132
[email protected]310ebd6302011-10-10 19:06:284133void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274134 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294135}
4136
[email protected]310ebd6302011-10-10 19:06:284137void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594138 webkit_preferences_ = prefs;
4139 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294140}
4141
[email protected]310ebd6302011-10-10 19:06:284142void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:294143 alternate_error_page_url_ = url;
4144}
4145
[email protected]310ebd6302011-10-10 19:06:284146void RenderViewImpl::OnCustomContextMenuAction(
[email protected]35be7ec2012-02-12 20:42:514147 const content::CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:084148 unsigned action) {
4149 if (custom_context.is_pepper_menu)
4150 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
4151 else
4152 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:584153 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
4154 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:334155}
4156
[email protected]310ebd6302011-10-10 19:06:284157void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:514158 int id,
4159 const std::vector<FilePath>& paths) {
4160 if (!enumeration_completions_[id])
4161 return;
4162
4163 WebVector<WebString> ws_file_names(paths.size());
4164 for (size_t i = 0; i < paths.size(); ++i)
4165 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
4166
4167 enumeration_completions_[id]->didChooseFile(ws_file_names);
4168 enumeration_completions_.erase(id);
4169}
4170
[email protected]fb11b6a42012-03-14 07:25:124171void RenderViewImpl::OnFileChooserResponse(
4172 const std::vector<content::SelectedFileInfo>& files) {
[email protected]8029f5672009-03-20 22:33:364173 // This could happen if we navigated to a different page before the user
4174 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474175 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364176 return;
4177
[email protected]b5188522012-03-15 00:18:044178 // Convert Chrome's SelectedFileInfo list to WebKit's.
4179 WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
4180 files.size());
4181 for (size_t i = 0; i < files.size(); ++i) {
4182 WebFileChooserCompletion::SelectedFileInfo selected_file;
4183 selected_file.path = webkit_glue::FilePathToWebString(files[i].path);
4184 selected_file.displayName = webkit_glue::FilePathStringToWebString(
4185 files[i].display_name);
4186 selected_files[i] = selected_file;
4187 }
[email protected]a1128322009-10-06 18:38:464188
[email protected]cdaf8d02010-03-30 19:52:474189 if (file_chooser_completions_.front()->completion)
[email protected]b5188522012-03-15 00:18:044190 file_chooser_completions_.front()->completion->didChooseFile(
4191 selected_files);
[email protected]cdaf8d02010-03-30 19:52:474192 file_chooser_completions_.pop_front();
4193
4194 // If there are more pending file chooser requests, schedule one now.
4195 if (!file_chooser_completions_.empty()) {
4196 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4197 file_chooser_completions_.front()->params));
4198 }
initial.commit09911bf2008-07-26 23:55:294199}
4200
[email protected]244ac1892011-12-02 17:04:474201void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
4202 const gfx::Size& max_size) {
4203 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4204 if (!webview())
4205 return;
[email protected]61e2b3cc2012-03-02 16:13:344206 webview()->enableAutoResizeMode(min_size, max_size);
4207}
4208
4209void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
4210 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4211 if (!webview())
4212 return;
4213 webview()->disableAutoResizeMode();
4214
4215 Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK);
[email protected]244ac1892011-12-02 17:04:474216}
4217
[email protected]2bf834f2011-11-17 20:02:214218void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:244219 if (send_preferred_size_changes_)
4220 return;
[email protected]9fb325e2010-05-06 18:23:244221 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394222
[email protected]d812fd12011-05-27 23:05:074223 // Start off with an initial preferred size notification (in case
4224 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:594225 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:084226}
4227
[email protected]310ebd6302011-10-10 19:06:284228void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:104229 const gfx::Size& disable_scrollbar_size_limit) {
4230 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4231}
4232
[email protected]310ebd6302011-10-10 19:06:284233void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:314234 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:504235 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:514236 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374237 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:134238#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:414239 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4240 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464241 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:514242 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:344243 renderer_prefs.thumb_inactive_color,
4244 renderer_prefs.thumb_active_color,
4245 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:324246
[email protected]644d77e2010-01-27 01:03:104247 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324248 webview()->setScrollbarColors(
4249 renderer_prefs.thumb_inactive_color,
4250 renderer_prefs.thumb_active_color,
4251 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104252 webview()->setSelectionColors(
4253 renderer_prefs.active_selection_bg_color,
4254 renderer_prefs.active_selection_fg_color,
4255 renderer_prefs.inactive_selection_bg_color,
4256 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464257 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104258 }
[email protected]7a74e102009-09-03 00:16:564259#endif
[email protected]d051d9a2011-12-10 02:02:504260 // If the zoom level for this page matches the old zoom default, and this
4261 // is not a plugin, update the zoom level to match the new default.
4262 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
4263 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
4264 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
4265 zoomLevelChanged();
4266 }
[email protected]80d96fa2009-06-10 22:34:514267}
4268
[email protected]310ebd6302011-10-10 19:06:284269void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
4270 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:284271 if (webview())
4272 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564273}
4274
[email protected]81375e872012-01-11 21:40:364275void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
4276 const WebPluginAction& action) {
4277 if (webview())
4278 webview()->performPluginAction(action, location);
4279}
4280
[email protected]310ebd6302011-10-10 19:06:284281void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:194282 const GURL& page_url) {
4283 // Prepare list to storage all savable resource links.
4284 std::vector<GURL> resources_list;
4285 std::vector<GURL> referrers_list;
4286 std::vector<GURL> frames_list;
4287 webkit_glue::SavableResourcesResult result(&resources_list,
4288 &referrers_list,
4289 &frames_list);
4290
[email protected]445e1042011-12-03 21:03:154291 // FIXME(rdsmith): When GetAllSavableResourceLinksForCurrentPage starts to
4292 // return referrers, it should also return the referrer policies.
[email protected]18d5be92011-07-25 18:00:194293 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4294 webview(),
4295 page_url,
4296 &result,
[email protected]0a35efc2012-03-13 17:28:134297 content::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:194298 // If something is wrong when collecting all savable resource links,
4299 // send empty list to embedder(browser) to tell it failed.
4300 referrers_list.clear();
4301 resources_list.clear();
4302 frames_list.clear();
4303 }
4304
4305 // Send result of all savable resource links to embedder.
4306 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
4307 resources_list,
4308 referrers_list,
4309 frames_list));
4310}
4311
[email protected]310ebd6302011-10-10 19:06:284312void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:194313 const std::vector<GURL>& links,
4314 const std::vector<FilePath>& local_paths,
4315 const FilePath& local_directory_name) {
4316
4317 // Convert std::vector of GURLs to WebVector<WebURL>
4318 WebVector<WebURL> weburl_links(links);
4319
4320 // Convert std::vector of std::strings to WebVector<WebString>
4321 WebVector<WebString> webstring_paths(local_paths.size());
4322 for (size_t i = 0; i < local_paths.size(); i++)
4323 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4324
4325 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
4326 webstring_paths,
4327 webkit_glue::FilePathToWebString(
4328 local_directory_name));
4329}
4330
[email protected]310ebd6302011-10-10 19:06:284331void RenderViewImpl::OnShouldClose() {
[email protected]7a17bac02012-03-07 21:58:124332 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
[email protected]26aa0482009-09-30 16:55:274333 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]7a17bac02012-03-07 21:58:124334 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
4335 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
4336 before_unload_start_time,
4337 before_unload_end_time));
initial.commit09911bf2008-07-26 23:55:294338}
4339
[email protected]310ebd6302011-10-10 19:06:284340void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]69ddf852012-02-21 23:21:314341 // Ensure that no other in-progress navigation continues.
4342 OnStop();
4343
[email protected]73eb2602012-02-09 19:50:554344 // Only run unload if we're not swapped out yet, but send the ack either way.
4345 if (!is_swapped_out_) {
4346 // Swap this RenderView out so the tab can navigate to a page rendered by a
4347 // different process. This involves running the unload handler and clearing
4348 // the page. Once WasSwappedOut is called, we also allow this process to
4349 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:154350
[email protected]73eb2602012-02-09 19:50:554351 // Send an UpdateState message before we get swapped out.
4352 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:154353
[email protected]73eb2602012-02-09 19:50:554354 // Synchronously run the unload handler before sending the ACK.
4355 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:154356
[email protected]73eb2602012-02-09 19:50:554357 // Swap out and stop sending any IPC messages that are not ACKs.
4358 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:154359
[email protected]73eb2602012-02-09 19:50:554360 // Replace the page with a blank dummy URL. The unload handler will not be
4361 // run a second time, thanks to a check in FrameLoader::stopLoading.
[email protected]69ddf852012-02-21 23:21:314362 // We use loadRequest instead of loadHTMLString because the former commits
4363 // synchronously. Otherwise a new navigation can interrupt the navigation
4364 // to about:swappedout. If that happens to be to the page we had been
4365 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]73eb2602012-02-09 19:50:554366 // TODO(creis): Need to add a better way to do this that avoids running the
4367 // beforeunload handler. For now, we just run it a second time silently.
[email protected]69ddf852012-02-21 23:21:314368 WebURLRequest request(GURL("about:swappedout"));
4369 webview()->mainFrame()->loadRequest(request);
[email protected]73eb2602012-02-09 19:50:554370 }
[email protected]992db4c2011-05-12 15:37:154371
4372 // Just echo back the params in the ACK.
4373 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
4374}
4375
[email protected]310ebd6302011-10-10 19:06:284376void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:374377 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:294378 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4379 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4380 // in the onunload handler from appearing. For now, we're bypassing that and
4381 // calling the FrameLoader's CloseURL method directly. This should be
4382 // revisited to avoid having two ways to close a page. Having a single way
4383 // to close that can run onunload is also useful for fixing
4384 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274385 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294386
[email protected]992db4c2011-05-12 15:37:154387 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:294388}
4389
[email protected]310ebd6302011-10-10 19:06:284390void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:024391#if defined(USE_AURA)
4392 // Aura doesn't care if we switch themes.
4393#elif defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:164394 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464395 if (webview())
4396 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574397#else // defined(OS_WIN)
4398 // TODO(port): we don't support theming on non-Windows platforms yet
4399 NOTIMPLEMENTED();
4400#endif
initial.commit09911bf2008-07-26 23:55:294401}
4402
[email protected]310ebd6302011-10-10 19:06:284403void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:084404 if (decrement_shared_popup_at_destruction_)
4405 shared_popup_counter_->data--;
4406 shared_popup_counter_ = new SharedRenderViewCounter(0);
4407 decrement_shared_popup_at_destruction_ = false;
4408}
4409
[email protected]310ebd6302011-10-10 19:06:284410bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
4411 const WebURLError& error,
4412 bool replace) {
[email protected]15d79e12009-08-02 19:23:454413 // We only show alternate error pages in the main frame. They are
4414 // intended to assist the user when navigating, so there is not much
4415 // value in showing them for failed subframes. Ideally, we would be
4416 // able to use the TYPED transition type for this, but that flag is
4417 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454418 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454419 return false;
4420
4421 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374422 // connection failure.
[email protected]15d79e12009-08-02 19:23:454423 int ec = error.reason;
4424 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4425 ec != net::ERR_CONNECTION_FAILED &&
4426 ec != net::ERR_CONNECTION_REFUSED &&
4427 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374428 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454429 return false;
4430
4431 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554432 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454433 if (!error_page_url.is_valid())
4434 return false;
4435
4436 // Load an empty page first so there is an immediate response to the error,
4437 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454438 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:364439 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454440 error.unreachableURL,
4441 replace);
4442
4443 // Now, create a fetcher for the error page and associate it with the data
4444 // source we just created via the LoadHTMLString call. That way if another
4445 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:074446 DocumentState* document_state =
4447 DocumentState::FromDataSource(frame->provisionalDataSource());
4448 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:454449 new AltErrorPageResourceFetcher(
4450 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:084451 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4452 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:454453 return true;
4454}
4455
[email protected]310ebd6302011-10-10 19:06:284456void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
4457 const WebURLError& original_error,
4458 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:454459 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094460 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554461 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094462 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454463}
4464
[email protected]310ebd6302011-10-10 19:06:284465void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:004466 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474467 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004468}
4469
[email protected]310ebd6302011-10-10 19:06:284470void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:094471 const gfx::Rect& resizer_rect,
4472 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:104473 if (webview()) {
[email protected]7ddea9802012-02-22 23:08:054474 // This setting has no effect if fixed layout is not enabled.
[email protected]43d9d782012-03-01 15:40:094475 if (webkit_preferences_.default_device_scale_factor)
[email protected]7ddea9802012-02-22 23:08:054476 webview()->settings()->setLayoutFallbackWidth(
[email protected]43d9d782012-03-01 15:40:094477 new_size.width() / webkit_preferences_.default_device_scale_factor);
[email protected]a72a1fa2010-05-03 22:18:474478 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104479 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204480 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:314481 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104482 }
[email protected]dd6afca2011-08-13 03:44:314483 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:104484 }
4485
[email protected]ee41e7d22011-10-14 19:34:094486 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:004487}
[email protected]0aa477bd2009-03-23 22:21:434488
[email protected]29ed96a2012-02-04 18:12:164489void RenderViewImpl::WillInitiatePaint() {
4490 // Notify the pepper plugins that we're about to paint.
4491 pepper_delegate_.ViewWillInitiatePaint();
4492}
4493
[email protected]310ebd6302011-10-10 19:06:284494void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:164495 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]53900d52010-06-16 04:25:014496 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:284497}
4498
[email protected]310ebd6302011-10-10 19:06:284499void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:284500 // Notify any pepper plugins that we painted. This will call into the plugin,
4501 // and we it may ask to close itself as a result. This will, in turn, modify
4502 // our set, possibly invalidating the iterator. So we iterate on a copy that
4503 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014504 pepper_delegate_.ViewFlushedPaint();
4505
[email protected]5b1dec8c2012-02-07 04:35:384506 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
4507 // See crbug.com/112921.
4508 if (!webview())
4509 return;
4510
[email protected]00c39612010-03-06 02:53:284511 WebFrame* main_frame = webview()->mainFrame();
4512
4513 // If we have a provisional frame we are between the start and commit stages
4514 // of loading and we don't want to save stats.
4515 if (!main_frame->provisionalDataSource()) {
4516 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:074517 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:284518
[email protected]05c8e502010-08-15 15:13:524519 // TODO(jar): The following code should all be inside a method, probably in
4520 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284521 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:074522 if (document_state->first_paint_time().is_null()) {
4523 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:284524 }
[email protected]007733c2011-11-17 00:34:074525 if (document_state->first_paint_after_load_time().is_null() &&
4526 !document_state->finish_load_time().is_null()) {
4527 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:284528 }
4529 }
4530}
4531
[email protected]310ebd6302011-10-10 19:06:284532void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084533 RenderWidget::OnSwapBuffersPosted();
4534}
4535
[email protected]310ebd6302011-10-10 19:06:284536void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244537 RenderWidget::OnSwapBuffersComplete();
4538}
4539
[email protected]310ebd6302011-10-10 19:06:284540void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244541 RenderWidget::OnSwapBuffersAborted();
4542}
4543
[email protected]310ebd6302011-10-10 19:06:284544webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154545 const gfx::Rect& paint_bounds,
4546 TransportDIB** dib,
4547 gfx::Rect* location,
4548 gfx::Rect* clip) {
4549 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4550 paint_bounds, dib, location, clip);
4551}
4552
[email protected]310ebd6302011-10-10 19:06:284553gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074554 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434555 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524556}
4557
[email protected]310ebd6302011-10-10 19:06:284558void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164559 if (webview())
[email protected]26aa0482009-09-30 16:55:274560 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164561}
4562
[email protected]310ebd6302011-10-10 19:06:284563void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144564 if (webview())
[email protected]b4bb2502009-10-01 22:35:274565 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144566
4567 SetBackground(background);
4568}
4569
[email protected]310ebd6302011-10-10 19:06:284570void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:344571 if (webview())
[email protected]b4bb2502009-10-01 22:35:274572 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264573
4574#if defined(OS_MACOSX)
4575 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4576 for (plugin_it = plugin_delegates_.begin();
4577 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4578 (*plugin_it)->SetWindowFocus(active);
4579 }
4580#endif
[email protected]8c66c5a2009-07-22 17:26:344581}
4582
[email protected]7a17bac02012-03-07 21:58:124583void RenderViewImpl::OnSetNavigationStartTime(
4584 const base::TimeTicks& browser_navigation_start) {
4585 if (!webview())
4586 return;
4587
4588 // Only the initial navigation can be a cross-renderer navigation. If we've
4589 // already navigated away from that page, we can ignore this message.
4590 if (page_id_ != -1)
4591 return;
4592
4593 // browser_navigation_start is likely before this process existed, so we can't
4594 // use InterProcessTimeTicksConverter. Instead, the best we can do is just
4595 // ensure we don't report a bogus value in the future.
4596 base::TimeTicks navigation_start = std::min(base::TimeTicks::Now(),
4597 browser_navigation_start);
4598 webview()->mainFrame()->provisionalDataSource()->setNavigationStartTime(
4599 (navigation_start - base::TimeTicks()).InSecondsF());
4600}
4601
[email protected]6ce7abc52010-02-02 18:40:144602#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284603void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:144604 // Inform plugins that their container has changed visibility.
4605 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4606 for (plugin_it = plugin_delegates_.begin();
4607 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4608 (*plugin_it)->SetContainerVisibility(visible);
4609 }
4610}
[email protected]1e6e3c992010-02-08 15:52:134611
[email protected]310ebd6302011-10-10 19:06:284612void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
4613 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134614 // Inform plugins that their window's frame has changed.
4615 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4616 for (plugin_it = plugin_delegates_.begin();
4617 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4618 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4619 }
4620}
[email protected]935d63d2010-10-15 23:31:554621
[email protected]310ebd6302011-10-10 19:06:284622void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
4623 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134624 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554625 // applies to it or not, so inform all the delegates.
4626 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4627 for (plugin_it = plugin_delegates_.begin();
4628 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134629 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554630 }
4631}
[email protected]6ce7abc52010-02-02 18:40:144632#endif // OS_MACOSX
4633
[email protected]310ebd6302011-10-10 19:06:284634void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:484635 const EditCommands& edit_commands) {
4636 edit_commands_ = edit_commands;
4637}
4638
[email protected]310ebd6302011-10-10 19:06:284639void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:594640 // We need to grab a pointer to the doomed WebView before we destroy it.
4641 WebView* doomed = webview();
4642 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494643 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594644}
4645
[email protected]310ebd6302011-10-10 19:06:284646void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:484647 edit_commands_.clear();
4648}
4649
[email protected]310ebd6302011-10-10 19:06:284650bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]217690d2012-01-27 07:33:114651 pepper_delegate_.WillHandleMouseEvent();
4652
4653 // If the mouse is locked, only the current owner of the mouse lock can
4654 // process mouse events.
4655 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:374656}
4657
[email protected]310ebd6302011-10-10 19:06:284658void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514659 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064660}
4661
[email protected]310ebd6302011-10-10 19:06:284662void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:244663 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
4664}
4665
[email protected]310ebd6302011-10-10 19:06:284666void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:434667 RenderWidget::OnWasHidden();
4668
[email protected]a6939ca42011-02-18 17:58:074669 if (webview()) {
4670 webview()->settings()->setMinimumTimerInterval(
4671 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444672 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074673 }
4674
[email protected]204f1df2012-01-04 20:21:134675 // Inform PPAPI plugins that their page is no longer visible.
4676 pepper_delegate_.PageVisibilityChanged(false);
4677
[email protected]a6939ca42011-02-18 17:58:074678#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134679 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:434680 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4681 for (plugin_it = plugin_delegates_.begin();
4682 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4683 (*plugin_it)->SetContainerVisibility(false);
4684 }
[email protected]a6939ca42011-02-18 17:58:074685#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434686}
4687
[email protected]310ebd6302011-10-10 19:06:284688void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:434689 RenderWidget::OnWasRestored(needs_repainting);
4690
[email protected]a6939ca42011-02-18 17:58:074691 if (webview()) {
4692 webview()->settings()->setMinimumTimerInterval(
4693 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444694 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074695 }
4696
[email protected]204f1df2012-01-04 20:21:134697 // Inform PPAPI plugins that their page is visible.
4698 pepper_delegate_.PageVisibilityChanged(true);
4699
[email protected]a6939ca42011-02-18 17:58:074700#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134701 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:434702 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4703 for (plugin_it = plugin_delegates_.begin();
4704 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4705 (*plugin_it)->SetContainerVisibility(true);
4706 }
[email protected]784ea1ab2010-09-18 00:02:344707#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074708}
[email protected]1e6e3c992010-02-08 15:52:134709
[email protected]310ebd6302011-10-10 19:06:284710bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:384711 if (WebWidgetHandlesCompositorScheduling())
4712 return false;
4713
[email protected]05a980d7a2012-02-07 22:16:424714 if (queried_for_swapbuffers_complete_callback_)
4715 return context_has_swapbuffers_complete_callback_;
4716
4717 queried_for_swapbuffers_complete_callback_ = true;
4718
[email protected]65225772011-05-12 21:10:244719 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
[email protected]05a980d7a2012-02-07 22:16:424720 if (context && context->makeContextCurrent()) {
4721 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4722 context_has_swapbuffers_complete_callback_ =
4723 extensions.find("GL_CHROMIUM_swapbuffers_complete_callback")
4724 != std::string::npos;
4725 }
4726
4727 return context_has_swapbuffers_complete_callback_;
[email protected]65225772011-05-12 21:10:244728}
4729
[email protected]310ebd6302011-10-10 19:06:284730void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:134731 RenderWidget::OnSetFocus(enable);
4732
[email protected]7d3c02c2010-05-05 23:10:314733 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074734 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134735 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4736 for (plugin_it = plugin_delegates_.begin();
4737 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344738#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314739 // RenderWidget's call to setFocus can cause the underlying webview's
4740 // activation state to change just like a call to setIsActive.
4741 if (enable)
4742 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344743#endif
[email protected]7d3c02c2010-05-05 23:10:314744 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134745 }
[email protected]589621b2010-09-23 22:01:074746
4747 // Notify all Pepper plugins.
4748 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134749 }
4750}
[email protected]941e4552010-02-01 21:23:434751
[email protected]310ebd6302011-10-10 19:06:284752void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:004753 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:504754 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:574755}
4756
[email protected]73bf95812011-10-12 11:38:324757void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:004758 UpdateTextInputState();
[email protected]73bf95812011-10-12 11:38:324759}
4760
[email protected]3f783362011-10-21 22:40:504761void RenderViewImpl::PpapiPluginCaretPositionChanged() {
4762 UpdateSelectionBounds();
4763}
4764
[email protected]b25b3ee2012-01-13 05:19:544765bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
4766 if (!pepper_delegate_.IsPluginFocused())
4767 return false;
4768 *rect = pepper_delegate_.GetCaretBounds();
4769 return true;
4770}
4771
[email protected]73bf95812011-10-12 11:38:324772void RenderViewImpl::PpapiPluginCancelComposition() {
4773 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
4774 ui::Range range(ui::Range::InvalidRange());
4775 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
4776}
4777
[email protected]3c8c74c2012-03-15 07:34:524778void RenderViewImpl::PpapiPluginSelectionChanged() {
4779 SyncSelectionIfRequired();
4780}
4781
[email protected]310ebd6302011-10-10 19:06:284782void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:574783 const string16& text,
4784 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4785 int selection_start,
4786 int selection_end) {
[email protected]73bf95812011-10-12 11:38:324787 if (pepper_delegate_.IsPluginFocused()) {
4788 // When a PPAPI plugin has focus, we bypass WebKit.
4789 pepper_delegate_.OnImeSetComposition(text,
4790 underlines,
4791 selection_start,
4792 selection_end);
4793 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234794#if defined(OS_WIN)
4795 // When a plug-in has focus, we create platform-specific IME data used by
4796 // our IME emulator and send it directly to the focused plug-in, i.e. we
4797 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4798 // instance ID is the same one as the specified ID.)
4799 if (focused_plugin_id_ >= 0) {
4800 std::vector<int> clauses;
4801 std::vector<int> target;
4802 for (size_t i = 0; i < underlines.size(); ++i) {
4803 clauses.push_back(underlines[i].startOffset);
4804 clauses.push_back(underlines[i].endOffset);
4805 if (underlines[i].thick) {
4806 target.clear();
4807 target.push_back(underlines[i].startOffset);
4808 target.push_back(underlines[i].endOffset);
4809 }
4810 }
4811 std::set<WebPluginDelegateProxy*>::iterator it;
4812 for (it = plugin_delegates_.begin();
4813 it != plugin_delegates_.end(); ++it) {
4814 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4815 focused_plugin_id_);
4816 }
4817 return;
4818 }
4819#endif
[email protected]56ea1a62011-05-30 07:05:574820 RenderWidget::OnImeSetComposition(text,
4821 underlines,
4822 selection_start,
4823 selection_end);
4824 }
4825}
4826
[email protected]4de6d1692011-10-12 08:45:444827void RenderViewImpl::OnImeConfirmComposition(
4828 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:574829 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:324830 // When a PPAPI plugin has focus, we bypass WebKit.
4831 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:574832 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234833#if defined(OS_WIN)
4834 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4835 // plug-ins. When we send IME text directly to plug-ins, we should not send
4836 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:444837 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:234838 if (focused_plugin_id_ >= 0) {
4839 std::set<WebPluginDelegateProxy*>::iterator it;
4840 for (it = plugin_delegates_.begin();
4841 it != plugin_delegates_.end(); ++it) {
4842 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4843 }
4844 return;
4845 }
4846#endif
[email protected]ebd28ac2011-10-13 18:49:054847 if (replacement_range.IsValid() && webview()) {
4848 // Select the text in |replacement_range|, it will then be replaced by
4849 // text added by the call to RenderWidget::OnImeConfirmComposition().
4850 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:164851 WebRange webrange = WebRange::fromDocumentRange(
4852 frame, replacement_range.start(), replacement_range.length());
4853 if (!webrange.isNull())
4854 frame->setSelectionToRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:054855 }
4856 }
[email protected]4de6d1692011-10-12 08:45:444857 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:574858 }
4859}
4860
[email protected]310ebd6302011-10-10 19:06:284861ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:324862 return pepper_delegate_.IsPluginFocused() ?
4863 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
4864}
4865
[email protected]3f783362011-10-21 22:40:504866void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
4867 if (pepper_delegate_.IsPluginFocused()) {
4868 // TODO(kinaba) http://crbug.com/101101
4869 // Current Pepper IME API does not handle selection bounds. So we simply
4870 // use the caret position as an empty range for now. It will be updated
4871 // after Pepper API equips features related to surrounding text retrieval.
4872 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
4873 *start = caret;
4874 *end = caret;
4875 return;
4876 }
4877 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:454878}
4879
[email protected]310ebd6302011-10-10 19:06:284880bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:324881 return pepper_delegate_.IsPluginFocused() ?
4882 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:574883}
4884
[email protected]e6ae0f6c2011-10-04 10:39:234885#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:284886void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:234887 if (focused)
4888 focused_plugin_id_ = plugin_id;
4889 else
4890 focused_plugin_id_ = -1;
4891}
4892#endif
4893
[email protected]43f28f832010-02-03 02:28:484894#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284895void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134896 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4897 focused, plugin_id);
4898 Send(msg);
4899}
4900
[email protected]310ebd6302011-10-10 19:06:284901void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:134902 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554903 // This message can be sent during event-handling, and needs to be delivered
4904 // within that context.
4905 msg->set_unblock(true);
4906 Send(msg);
4907}
4908
[email protected]310ebd6302011-10-10 19:06:284909gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234910 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484911 gfx::PluginWindowHandle window = NULL;
4912 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234913 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114914 if (window) {
4915 fake_plugin_window_handles_.insert(window);
4916 }
[email protected]43f28f832010-02-03 02:28:484917 return window;
4918}
4919
[email protected]310ebd6302011-10-10 19:06:284920void RenderViewImpl::DestroyFakePluginWindowHandle(
4921 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114922 if (window && fake_plugin_window_handles_.find(window) !=
4923 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484924 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114925 fake_plugin_window_handles_.erase(window);
4926 }
[email protected]43f28f832010-02-03 02:28:484927}
4928
[email protected]310ebd6302011-10-10 19:06:284929void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
4930 gfx::PluginWindowHandle window,
4931 int32 width,
4932 int32 height,
4933 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:334934 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484935 routing_id(), window, width, height, io_surface_identifier));
4936}
4937
[email protected]310ebd6302011-10-10 19:06:284938void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334939 gfx::PluginWindowHandle window,
4940 int32 width,
4941 int32 height,
4942 TransportDIB::Handle transport_dib) {
4943 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074944 routing_id(), window, width, height, transport_dib));
4945}
4946
[email protected]310ebd6302011-10-10 19:06:284947TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334948 size_t size) {
[email protected]1aef98132010-02-23 18:00:074949 TransportDIB::Handle dib_handle;
4950 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384951 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074952 return dib_handle;
4953 // Return an invalid handle if Send() fails.
4954 return TransportDIB::DefaultHandleValue();
4955}
4956
[email protected]310ebd6302011-10-10 19:06:284957void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
4958 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074959 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4960}
4961
[email protected]310ebd6302011-10-10 19:06:284962void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:324963 gfx::PluginWindowHandle window, uint64 surface_handle) {
[email protected]f35d6672010-10-28 21:39:144964 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
[email protected]7de8fb72012-03-14 04:24:324965 routing_id(), window, surface_handle));
[email protected]43f28f832010-02-03 02:28:484966}
4967#endif
[email protected]58c321d2010-02-19 12:11:284968
[email protected]310ebd6302011-10-10 19:06:284969bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:234970 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:474971 WebFileChooserCompletion* completion) {
4972 static const size_t kMaximumPendingFileChooseRequests = 4;
4973 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4974 // This sanity check prevents too many file choose requests from getting
4975 // queued which could DoS the user. Getting these is most likely a
4976 // programming error (there are many ways to DoS the user so it's not
4977 // considered a "real" security check), either in JS requesting many file
4978 // choosers to pop up, or in a plugin.
4979 //
4980 // TODO(brettw) we might possibly want to require a user gesture to open
4981 // a file picker, which will address this issue in a better way.
4982 return false;
4983 }
4984
4985 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4986 new PendingFileChooser(params, completion)));
4987 if (file_chooser_completions_.size() == 1) {
4988 // Actually show the browse dialog when this is the first request.
4989 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4990 }
4991 return true;
4992}
4993
[email protected]310ebd6302011-10-10 19:06:284994WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514995 if (!geolocation_dispatcher_)
4996 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4997 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254998}
[email protected]61c9f032010-03-31 23:04:194999
[email protected]310ebd6302011-10-10 19:06:285000WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:115001 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:225002#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:025003 if (!input_tag_speech_dispatcher_)
5004 input_tag_speech_dispatcher_ =
5005 new InputTagSpeechDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:225006#endif
[email protected]c52b2892012-03-07 11:01:025007 return input_tag_speech_dispatcher_;
[email protected]638694c2010-08-04 22:24:115008}
5009
[email protected]310ebd6302011-10-10 19:06:285010WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:515011 if (!device_orientation_dispatcher_)
5012 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
5013 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:535014}
5015
[email protected]310ebd6302011-10-10 19:06:285016void RenderViewImpl::zoomLimitsChanged(double minimum_level,
5017 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:255018 // For now, don't remember plugin zoom values. We don't want to mix them with
5019 // normal web content (i.e. a fixed layout plugin would usually want them
5020 // different).
5021 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5022
[email protected]b75b8292010-10-01 07:28:255023 int minimum_percent = static_cast<int>(
5024 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5025 int maximum_percent = static_cast<int>(
5026 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255027
5028 Send(new ViewHostMsg_UpdateZoomLimits(
5029 routing_id_, minimum_percent, maximum_percent, remember));
5030}
5031
[email protected]310ebd6302011-10-10 19:06:285032void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:255033 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:085034 float zoom_level = webview()->zoomLevel();
[email protected]b75b8292010-10-01 07:28:255035 // Tell the browser which url got zoomed so it can update the menu and the
5036 // saved values if necessary
5037 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:085038 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:415039 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:255040}
5041
[email protected]310ebd6302011-10-10 19:06:285042void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
5043 const WebString& base_url,
5044 const WebString& url,
5045 const WebString& title) {
[email protected]a6d36cc2011-02-23 00:39:485046 GURL base(base_url);
5047 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
5048 if (base.GetOrigin() != absolute_url.GetOrigin()) {
5049 return;
5050 }
[email protected]f1a29a02011-10-06 23:08:445051 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
5052 UTF16ToUTF8(scheme),
5053 absolute_url,
5054 title));
[email protected]a6d36cc2011-02-23 00:39:485055}
5056
[email protected]310ebd6302011-10-10 19:06:285057WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:445058 WebKit::WebPageVisibilityState current_state = is_hidden() ?
5059 WebKit::WebPageVisibilityStateHidden :
5060 WebKit::WebPageVisibilityStateVisible;
5061 WebKit::WebPageVisibilityState override_state = current_state;
5062 if (content::GetContentClient()->renderer()->
5063 ShouldOverridePageVisibilityState(this,
5064 &override_state))
5065 return override_state;
5066 return current_state;
[email protected]94dec932011-05-26 20:04:215067}
5068
[email protected]273558fb2012-01-12 15:03:515069WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
5070 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
5071 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
5072 return NULL;
5073 EnsureMediaStreamImpl();
5074 return media_stream_impl_;
5075}
5076
[email protected]310ebd6302011-10-10 19:06:285077bool RenderViewImpl::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195078 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455079 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195080 if (frame->parent() != NULL)
5081 return false;
5082
[email protected]f0a3d0b2010-08-06 22:51:535083 // Navigations initiated within Webkit are not sent out to the external host
5084 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275085 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:135086 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535087 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:135088 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:335089 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:535090 return false;
5091
[email protected]2fc22d12010-12-02 23:08:165092 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:325093 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015094 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:165095 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:015096 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325097 // The opener relationship between the new window and the parent allows the
5098 // new window to script the parent and vice versa. This is not allowed if
5099 // the origins of the two domains are different. This can be treated as a
5100 // top level navigation and routed back to the host.
5101 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275102 if (!opener) {
[email protected]86965362011-04-21 18:42:515103 return true;
[email protected]d19ea342011-04-20 20:31:135104 } else {
[email protected]b6cb3a842011-06-24 18:28:415105 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:325106 return true;
5107 }
5108 }
[email protected]61c9f032010-03-31 23:04:195109 return false;
5110}
[email protected]2b06a992010-08-21 05:48:225111
[email protected]310ebd6302011-10-10 19:06:285112void RenderViewImpl::OnAsyncFileOpened(
5113 base::PlatformFileError error_code,
5114 IPC::PlatformFileForTransit file_for_transit,
5115 int message_id) {
[email protected]27a9ef32010-09-10 04:06:245116 pepper_delegate_.OnAsyncFileOpened(
5117 error_code,
5118 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5119 message_id);
5120}
[email protected]caf706f2010-10-26 17:54:085121
[email protected]310ebd6302011-10-10 19:06:285122void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:475123 int request_id,
5124 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:435125 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:475126 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
5127 broker_process_handle,
5128 handle);
[email protected]eb415bf0e2011-04-14 02:45:425129}
5130
[email protected]caf706f2010-10-26 17:54:085131#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285132void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155133 if (external_popup_menu_ == NULL) {
5134 // Crash reports from the field indicate that we can be notified with a
5135 // NULL external popup menu (we probably get notified twice).
5136 // If you hit this please file a bug against jcivelli and include the page
5137 // and steps to repro.
5138 NOTREACHED();
5139 return;
5140 }
[email protected]caf706f2010-10-26 17:54:085141 external_popup_menu_->DidSelectItem(selected_index);
5142 external_popup_menu_.reset();
5143}
5144#endif
[email protected]bb461532010-11-26 21:50:235145
[email protected]1b4209f2011-01-07 00:25:405146#if defined(ENABLE_FLAPPER_HACKS)
[email protected]310ebd6302011-10-10 19:06:285147void RenderViewImpl::OnConnectTcpACK(
[email protected]1b4209f2011-01-07 00:25:405148 int request_id,
5149 IPC::PlatformFileForTransit socket_for_transit,
[email protected]5a2b68f2011-11-10 00:00:495150 const PP_NetAddress_Private& local_addr,
5151 const PP_NetAddress_Private& remote_addr) {
[email protected]1b4209f2011-01-07 00:25:405152 pepper_delegate_.OnConnectTcpACK(
5153 request_id,
5154 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
5155 local_addr,
5156 remote_addr);
5157}
5158#endif
[email protected]a6097f42011-01-10 08:50:515159
[email protected]310ebd6302011-10-10 19:06:285160void RenderViewImpl::OnContextMenuClosed(
[email protected]35be7ec2012-02-12 20:42:515161 const content::CustomContextMenuContext& custom_context) {
[email protected]b29aa74b2011-01-31 21:41:085162 if (custom_context.is_pepper_menu)
5163 pepper_delegate_.OnContextMenuClosed(custom_context);
5164 else
5165 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:105166}
[email protected]5a7b15a2011-08-22 22:48:185167
[email protected]310ebd6302011-10-10 19:06:285168void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:185169 if (!webview())
5170 return;
5171 WebFrame* main_frame = webview()->mainFrame();
5172 if (!main_frame)
5173 return;
5174 main_frame->enableViewSourceMode(true);
5175}
[email protected]67bfb83f2011-09-22 03:36:375176
[email protected]310ebd6302011-10-10 19:06:285177bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:085178 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:405179}
[email protected]7f3c7af2011-10-20 22:52:515180
[email protected]64d0e192011-12-09 14:44:205181void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7f3c7af2011-10-20 22:52:515182 DCHECK(!java_bridge_dispatcher_.get());
[email protected]464750f2011-10-24 23:16:185183#if defined(ENABLE_JAVA_BRIDGE)
[email protected]64d0e192011-12-09 14:44:205184 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this));
[email protected]464750f2011-10-24 23:16:185185#endif
[email protected]7f3c7af2011-10-20 22:52:515186}